exec_outcome
stringclasses 1
value | code_uid
stringlengths 32
32
| file_name
stringclasses 111
values | prob_desc_created_at
stringlengths 10
10
| prob_desc_description
stringlengths 63
3.8k
| prob_desc_memory_limit
stringclasses 18
values | source_code
stringlengths 117
65.5k
| lang_cluster
stringclasses 1
value | prob_desc_sample_inputs
stringlengths 2
802
| prob_desc_time_limit
stringclasses 27
values | prob_desc_sample_outputs
stringlengths 2
796
| prob_desc_notes
stringlengths 4
3k
β | lang
stringclasses 5
values | prob_desc_input_from
stringclasses 3
values | tags
sequencelengths 0
11
| src_uid
stringlengths 32
32
| prob_desc_input_spec
stringlengths 28
2.37k
β | difficulty
int64 -1
3.5k
β | prob_desc_output_spec
stringlengths 17
1.47k
β | prob_desc_output_to
stringclasses 3
values | hidden_unit_tests
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PASSED | 8c1b6c6aaecf89f07f540b393002f8bf | train_000.jsonl | 1298908800 | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically:The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last.If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less).For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
public class P063A {
Scanner sc = new Scanner(System.in);
int INF = 1 << 28;
double EPS = 1e-9;
int n;
P[] ps;
void run() {
n = sc.nextInt();
ps = new P[n];
for (int i = 0; i < n; i++) {
String name = sc.next();
String status = sc.next();
ps[i] = new P(name, status, i);
}
solve();
}
HashMap<String, Integer> map;
void solve() {
map = new HashMap<String, Integer>();
map.put("rat", 0);
map.put("woman", 1);
map.put("child", 1);
map.put("man", 2);
map.put("captain", 3);
sort(ps);
for (P p : ps) {
println(p.name);
}
}
class P implements Comparable<P> {
String name, status;
int index;
P(String name, String status, int index) {
this.name = name;
this.status = status;
this.index = index;
}
@Override
public int compareTo(P p) {
if (status.equals(p.status)) {
return index - p.index;
} else {
return map.get(status) - map.get(p.status);
}
}
}
void println(String s) {
System.out.println(s);
}
void print(String s) {
System.out.print(s);
}
void debug(Object... os) {
System.err.println(deepToString(os));
}
public static void main(String[] args) {
Locale.setDefault(Locale.US);
new P063A().run();
}
}
| Java | ["6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman"] | 2 seconds | ["Teddy\nAlice\nBob\nJulia\nCharlie\nJack"] | null | Java 6 | standard input | [
"implementation",
"sortings",
"strings"
] | 753113fa5130a67423f2e205c97f8017 | The first line contains an integer n, which is the number of people in the crew (1ββ€βnββ€β100). Then follow n lines. The i-th of those lines contains two words β the name of the crew member who is i-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain. | 900 | Print n lines. The i-th of them should contain the name of the crew member who must be the i-th one to leave the ship. | standard output | |
PASSED | c84b862d62bef272611a19e257a89b80 | train_000.jsonl | 1298908800 | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically:The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last.If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less).For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
// Sinking Ship
// 2012/11/03
public class P063A{
Scanner sc=new Scanner(System.in);
int n;
P[] ps;
void run(){
n=sc.nextInt();
ps=new P[n];
for(int i=0; i<n; i++){
String name=sc.next();
String status=sc.next();
ps[i]=new P(name, status, i);
}
solve();
}
HashMap<String, Integer> map;
void solve(){
map=new HashMap<String, Integer>();
map.put("rat", 0);
map.put("woman", 1);
map.put("child", 1);
map.put("man", 2);
map.put("captain", 3);
sort(ps);
for(P p : ps){
println(p.name);
}
}
class P implements Comparable<P>{
String name, status;
int index;
P(String name, String status, int index){
this.name=name;
this.status=status;
this.index=index;
}
@Override
public int compareTo(P p){
if(status.equals(p.status)){
return index-p.index;
}else{
return map.get(status)-map.get(p.status);
}
}
}
void println(String s){
System.out.println(s);
}
public static void main(String[] args){
Locale.setDefault(Locale.US);
new P063A().run();
}
}
| Java | ["6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman"] | 2 seconds | ["Teddy\nAlice\nBob\nJulia\nCharlie\nJack"] | null | Java 6 | standard input | [
"implementation",
"sortings",
"strings"
] | 753113fa5130a67423f2e205c97f8017 | The first line contains an integer n, which is the number of people in the crew (1ββ€βnββ€β100). Then follow n lines. The i-th of those lines contains two words β the name of the crew member who is i-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain. | 900 | Print n lines. The i-th of them should contain the name of the crew member who must be the i-th one to leave the ship. | standard output | |
PASSED | 3314a2a9114773ea552ba5d8f06a969c | train_000.jsonl | 1298908800 | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically:The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last.If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less).For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;
public class korablekrushenie implements Runnable {
private BufferedReader br = null;
private PrintWriter pw = null;
private StringTokenizer stk = new StringTokenizer("");
public static void main(String[] lala) {
(new Thread(new korablekrushenie())).run();
}
public void nline() {
try {
while (!stk.hasMoreTokens()) {
stk = new StringTokenizer(br.readLine());
}
} catch (Throwable e) {
throw new RuntimeException("I wanna be cousmonout", e);
}
}
public String nstr() {
nline();
return stk.nextToken();
}
public int ni() {
nline();
return Integer.valueOf(nstr());
}
public double nd() {
nline();
return Double.valueOf(nstr());
}
public BigInteger nbi() {
nline();
return new BigInteger(nstr());
}
public void run() {
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(System.out);
solve();
pw.close();
}
public void solve() {
ArrayList<ArrayList<String>> ar = new ArrayList<ArrayList<String>> (4);
int n= ni();
for (int i=0; i<4; i++){
ArrayList<String> t = new ArrayList<String>();
ar.add(t);
}
for (int i=0; i<n; i++) {
String name= nstr(), rang = nstr();
if (rang.equals("rat")) ar.get(0).add(name);
if (rang.equals("woman") || rang.equals("child")) ar.get(1).add(name);
if (rang.equals("man")) ar.get(2).add(name);
if (rang.equals("captain")) ar.get(3).add(name);
}
for (int i=0; i<ar.size(); i++){
for (int j=0; j<ar.get(i).size(); j++){
System.out.println(ar.get(i).get(j));
}
}
}
public void exit() {
System.exit(0);
}
}
| Java | ["6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman"] | 2 seconds | ["Teddy\nAlice\nBob\nJulia\nCharlie\nJack"] | null | Java 6 | standard input | [
"implementation",
"sortings",
"strings"
] | 753113fa5130a67423f2e205c97f8017 | The first line contains an integer n, which is the number of people in the crew (1ββ€βnββ€β100). Then follow n lines. The i-th of those lines contains two words β the name of the crew member who is i-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain. | 900 | Print n lines. The i-th of them should contain the name of the crew member who must be the i-th one to leave the ship. | standard output | |
PASSED | b2715126ebfd4f34bd94ee77743307ac | train_000.jsonl | 1298908800 | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically:The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last.If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less).For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
String [] str1 = new String [105];
String [] str2 = new String [105];
int n=s.nextInt();
s.nextLine();
for(int i=0;i<n;i++)
{
str1[i] = s.next();
str2[i] = s.next();
}
for(int i=0;i<4;i++)
{
for(int j=0;j<n;j++)
{
if(i==0&&str2[j].equals("rat")==true)
System.out.println(str1[j]);
if(i==1&&(str2[j].equals("woman")==true||str2[j].equals("child")==true))
System.out.println(str1[j]);
if(i==2&&str2[j].equals("man")==true)
System.out.println(str1[j]);
if(i==3&&str2[j].equals("captain")==true)
System.out.println(str1[j]);
}
}
}
}
| Java | ["6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman"] | 2 seconds | ["Teddy\nAlice\nBob\nJulia\nCharlie\nJack"] | null | Java 6 | standard input | [
"implementation",
"sortings",
"strings"
] | 753113fa5130a67423f2e205c97f8017 | The first line contains an integer n, which is the number of people in the crew (1ββ€βnββ€β100). Then follow n lines. The i-th of those lines contains two words β the name of the crew member who is i-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain. | 900 | Print n lines. The i-th of them should contain the name of the crew member who must be the i-th one to leave the ship. | standard output | |
PASSED | 984ca6b32e70454dc00b283617ede0ee | train_000.jsonl | 1298908800 | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically:The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last.If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less).For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew. | 256 megabytes |
import java.util.Scanner;
/**
*
* @author madi
*/
public class Codeforces59C {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.nextLine());
String[][] a = new String[n][2];
for (int i = 0; i < n; i++) {
String[] s = sc.nextLine().split(" ");
a[i][0] = s[0];
a[i][1] = s[1];
}
boolean[] f = new boolean[n];
String[] ss = {"rat", "woman", "man", "captain"};
String k = "child";
for (int i = 0; i < 4; i++) {
for (int j = 0; j < n; j++) {
if (!f[j] && (a[j][1].equalsIgnoreCase(ss[i]) || (ss[i].equalsIgnoreCase("woman") && a[j][1].equalsIgnoreCase(k)))) {
System.out.println(a[j][0]);
f[j] = true;
}
}
}
}
}
| Java | ["6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman"] | 2 seconds | ["Teddy\nAlice\nBob\nJulia\nCharlie\nJack"] | null | Java 6 | standard input | [
"implementation",
"sortings",
"strings"
] | 753113fa5130a67423f2e205c97f8017 | The first line contains an integer n, which is the number of people in the crew (1ββ€βnββ€β100). Then follow n lines. The i-th of those lines contains two words β the name of the crew member who is i-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain. | 900 | Print n lines. The i-th of them should contain the name of the crew member who must be the i-th one to leave the ship. | standard output | |
PASSED | 4a8829469d79ad4f8d9b31ce3f0490bf | train_000.jsonl | 1298908800 | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically:The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last.If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less).For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class one {
public static void main(String[] args) throws IOException {
BufferedReader buf = new BufferedReader(
new InputStreamReader(System.in));
int n = Integer.parseInt(buf.readLine());
String[] names = new String[n];
for (int i = 0; i < n; i++)
names[i] = buf.readLine();
for (int i = 0; i < n; i++) {
String[] in = names[i].split(" ");
if (in[1].equals("rat"))
System.out.println(in[0]);
}
for (int i = 0; i < n; i++) {
String[] in = names[i].split(" ");
if (in[1].equals("woman") || in[1].equals("child"))
System.out.println(in[0]);
}
for (int i = 0; i < n; i++) {
String[] in = names[i].split(" ");
if (in[1].equals("man"))
System.out.println(in[0]);
}
for (int i = 0; i < n; i++) {
String[] in = names[i].split(" ");
if (in[1].equals("captain"))
System.out.println(in[0]);
}
}
}
| Java | ["6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman"] | 2 seconds | ["Teddy\nAlice\nBob\nJulia\nCharlie\nJack"] | null | Java 6 | standard input | [
"implementation",
"sortings",
"strings"
] | 753113fa5130a67423f2e205c97f8017 | The first line contains an integer n, which is the number of people in the crew (1ββ€βnββ€β100). Then follow n lines. The i-th of those lines contains two words β the name of the crew member who is i-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain. | 900 | Print n lines. The i-th of them should contain the name of the crew member who must be the i-th one to leave the ship. | standard output | |
PASSED | 53617cc35c8e7d54a3f61d1b1ec15a16 | train_000.jsonl | 1298908800 | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically:The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last.If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less).For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew. | 256 megabytes | import java.util.Scanner;
public class Prob063A
{
public static void main( String[] Args )
{
Scanner scan = new Scanner( System.in );
int x = scan.nextInt();
String[][] order = new String[4][100];
int[] num = new int[4];
for ( int a = 0; a < x; a++ )
{
String s = scan.next();
String r = scan.next();
int y = 3;
if ( r.equals( "rat" ) )
y = 0;
else if ( r.equals( "woman" ) || r.equals( "child" ) )
y = 1;
else if ( r.equals( "man" ) )
y = 2;
order[y][num[y]++] = s;
}
for (int a = 0; a < 4; a++)
for (int b = 0; b < num[a]; b++)
System.out.println(order[a][b]);
}
}
| Java | ["6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman"] | 2 seconds | ["Teddy\nAlice\nBob\nJulia\nCharlie\nJack"] | null | Java 6 | standard input | [
"implementation",
"sortings",
"strings"
] | 753113fa5130a67423f2e205c97f8017 | The first line contains an integer n, which is the number of people in the crew (1ββ€βnββ€β100). Then follow n lines. The i-th of those lines contains two words β the name of the crew member who is i-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain. | 900 | Print n lines. The i-th of them should contain the name of the crew member who must be the i-th one to leave the ship. | standard output | |
PASSED | 2805f7db02bafce5b6439d7fe386f3e9 | train_000.jsonl | 1298908800 | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically:The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last.If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less).For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew. | 256 megabytes | import java.util.Scanner;
public class A63 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt(), a[] = new int[n];
String s[] = new String[n];
for (int i = 0; i < n; i++) {
s[i] = in.next();
String t = in.next();
if (t.compareTo("rat") == 0)
a[i] = 1;
if (t.compareTo("woman") == 0 || t.compareTo("child") == 0)
a[i] = 2;
if (t.compareTo("man") == 0)
a[i] = 3;
if (t.compareTo("captain") == 0)
a[i] = 4;
}
for (int i = 0; i < n; i++)
for (int j = 0; j < n - 1; j++) {
if (a[j] > a[j + 1]) {
int t = a[j];
a[j] = a[j + 1];
a[j + 1] = t;
String q = s[j];
s[j] = s[j + 1];
s[j + 1] = q;
}
}
for (int i = 0; i < n; i++)
System.out.println(s[i]);
}
} | Java | ["6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman"] | 2 seconds | ["Teddy\nAlice\nBob\nJulia\nCharlie\nJack"] | null | Java 6 | standard input | [
"implementation",
"sortings",
"strings"
] | 753113fa5130a67423f2e205c97f8017 | The first line contains an integer n, which is the number of people in the crew (1ββ€βnββ€β100). Then follow n lines. The i-th of those lines contains two words β the name of the crew member who is i-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain. | 900 | Print n lines. The i-th of them should contain the name of the crew member who must be the i-th one to leave the ship. | standard output | |
PASSED | 839b068d4b42c475e85f1b05aa2678c1 | train_000.jsonl | 1298908800 | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically:The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last.If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less).For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew. | 256 megabytes | import java.util.Scanner;
import java.util.Vector;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
Vector<String> r = new Vector<String>();
Vector<String> w = new Vector<String>();
Vector<String> m = new Vector<String>();
Vector<String> c = new Vector<String>();
for (int i = 0; i < n; ++i) {
String name = in.next();
String type = in.next();
if (type.equals("rat")) {
r.add(name);
} else if (type.equals("man")) {
m.add(name);
} else if (type.equals("captain")) {
c.add(name);
} else {
w.add(name);
}
}
for (String curr: r) {
System.out.println(curr);
}
for (String curr: w) {
System.out.println(curr);
}
for (String curr: m) {
System.out.println(curr);
}
for (String curr: c) {
System.out.println(curr);
}
}
}
| Java | ["6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman"] | 2 seconds | ["Teddy\nAlice\nBob\nJulia\nCharlie\nJack"] | null | Java 6 | standard input | [
"implementation",
"sortings",
"strings"
] | 753113fa5130a67423f2e205c97f8017 | The first line contains an integer n, which is the number of people in the crew (1ββ€βnββ€β100). Then follow n lines. The i-th of those lines contains two words β the name of the crew member who is i-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain. | 900 | Print n lines. The i-th of them should contain the name of the crew member who must be the i-th one to leave the ship. | standard output | |
PASSED | c6d71973ab4b6a3f248727f500e5bc77 | train_000.jsonl | 1298908800 | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically:The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last.If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less).For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew. | 256 megabytes | import java.io.*;
import java.util.*;
public class SinkingShip {
private void solve() throws IOException {
int n = nextInt();
LinkedList<String> Wo_ch = new LinkedList<String>();
LinkedList<String> man = new LinkedList<String>();
String captain = "";
for (int i = 0; i < n; i++) {
String name = nextToken();
String job = nextToken();
if (job.equals("captain"))
captain = name;
else if (job.equals("rat"))
System.out.println(name);
else if (job.equals("woman") || job.equals("child"))
Wo_ch.add(name);
else
man.add(name);
}
for (int i = 0; i < Wo_ch.size(); i++) {
System.out.println(Wo_ch.get(i));
}
for (int i = 0; i < man.size(); i++) {
System.out.println(man.get(i));
}
System.out.println(captain);
}
public static void main(String[] args) {
new SinkingShip().run();
}
BufferedReader reader;
StringTokenizer tokenizer;
PrintWriter writer;
public void run() {
try {
reader = new BufferedReader(new InputStreamReader(System.in));
tokenizer = null;
writer = new PrintWriter(System.out);
solve();
reader.close();
writer.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
String nextToken() throws IOException {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
}
| Java | ["6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman"] | 2 seconds | ["Teddy\nAlice\nBob\nJulia\nCharlie\nJack"] | null | Java 6 | standard input | [
"implementation",
"sortings",
"strings"
] | 753113fa5130a67423f2e205c97f8017 | The first line contains an integer n, which is the number of people in the crew (1ββ€βnββ€β100). Then follow n lines. The i-th of those lines contains two words β the name of the crew member who is i-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain. | 900 | Print n lines. The i-th of them should contain the name of the crew member who must be the i-th one to leave the ship. | standard output | |
PASSED | 5839fb2166d53f60c03bd99904aa2d2f | train_000.jsonl | 1298908800 | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically:The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last.If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less).For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew. | 256 megabytes | import java.io.*;
import java.math.*;
import java.util.*;
import java.util.List;
import java.util.Queue;
import java.awt.*;
public class codefors implements Runnable {
private BufferedReader br = null;
private PrintWriter pw = null;
private StringTokenizer stk = new StringTokenizer("");
public static void main(String[] args) {
new Thread(new codefors()).run();
}
public void run() {
/*
* try { // br = new BufferedReader(new FileReader("input.txt")); pw =
* new PrintWriter("output.txt"); } catch (FileNotFoundException e) {
* e.printStackTrace(); }
*/
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new OutputStreamWriter(System.out));
solver();
pw.close();
}
private void nline() {
try {
if (!stk.hasMoreTokens())
stk = new StringTokenizer(br.readLine());
} catch (IOException e) {
throw new RuntimeException("KaVaBUnGO!!!", e);
}
}
private String nstr() {
while (!stk.hasMoreTokens())
nline();
return stk.nextToken();
}
private int ni() {
return Integer.valueOf(nstr());
}
private double nd() {
return Double.valueOf(nstr());
}
private BigInteger nbi() {
return new BigInteger(nstr());
}
String nextLine() {
try {
return br.readLine();
} catch (IOException e) {
}
return null;
}
private void solver() {
int n = ni();
ArrayList<ArrayList<String>> ar = new ArrayList<ArrayList<String>>();
for (int i = 0; i < 4; i++) {
ArrayList<String> t = new ArrayList<String>();
ar.add(t);
}
for (int i = 0; i < n; i++) {
String name = nstr(), rang = nstr();
if (rang.equals("rat"))
ar.get(0).add(name);
if (rang.equals("woman") || rang.equals("child"))
ar.get(1).add(name);
if (rang.equals("man"))
ar.get(2).add(name);
if (rang.equals("captain"))
ar.get(3).add(name);
}
for (int i = 0; i < ar.size(); i++) {
for (int j = 0; j < ar.get(i).size(); j++) {
System.out.println(ar.get(i).get(j));
}
}
}
void exit() {
System.exit(0);
}
}
| Java | ["6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman"] | 2 seconds | ["Teddy\nAlice\nBob\nJulia\nCharlie\nJack"] | null | Java 6 | standard input | [
"implementation",
"sortings",
"strings"
] | 753113fa5130a67423f2e205c97f8017 | The first line contains an integer n, which is the number of people in the crew (1ββ€βnββ€β100). Then follow n lines. The i-th of those lines contains two words β the name of the crew member who is i-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain. | 900 | Print n lines. The i-th of them should contain the name of the crew member who must be the i-th one to leave the ship. | standard output | |
PASSED | 0a6074c38fb0dc58af860807851fe3e8 | train_000.jsonl | 1298908800 | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically:The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last.If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less).For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew. | 256 megabytes | import java.io.*;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
public class cf2d59a {
//PrintWriter out;
public static void main(String[] args) throws IOException {
//System.setIn(new FileInputStream("input.txt"));
//System.setOut(new PrintStream("output.txt"));
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(r.readLine());
String arr[] = new String[n];
String arr1[] = new String[n];
for(int i = 0; i < n; i++) {
String a = r.readLine();
String b[] = a.split(" ");
arr[i] = b[0];
arr1[i] = b[1];
}
for(int i = 0; i < 6; i++) {
for(int j = 0; j < n; j++) {
if(i == 0 && arr1[j].equals("rat")) {arr1[j] = "";System.out.println(arr[j]);}
else if(i == 1 && arr1[j].equals("woman")||(i == 1 && arr1[j].equals("child"))) {arr1[j] = "";System.out.println(arr[j]);}
else if(i == 3 && arr1[j].equals("man")) {arr1[j] = "";System.out.println(arr[j]);}
else if(i == 4 && arr1[j].equals("captain")) {arr1[j] = "";System.out.println(arr[j]);}
else if(i == 5 && arr1[j].length() > 0) {System.out.println(arr[j]);}
}}
}
}
| Java | ["6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman"] | 2 seconds | ["Teddy\nAlice\nBob\nJulia\nCharlie\nJack"] | null | Java 6 | standard input | [
"implementation",
"sortings",
"strings"
] | 753113fa5130a67423f2e205c97f8017 | The first line contains an integer n, which is the number of people in the crew (1ββ€βnββ€β100). Then follow n lines. The i-th of those lines contains two words β the name of the crew member who is i-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain. | 900 | Print n lines. The i-th of them should contain the name of the crew member who must be the i-th one to leave the ship. | standard output | |
PASSED | 127a96916fdab291ff7b298a9e409b22 | train_000.jsonl | 1298908800 | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically:The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last.If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less).For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew. | 256 megabytes | import java.io.*;
import java.util.*;
public class Test{
public static void main(String[] args) {
Scanner in= new Scanner(System.in);
ArrayList<String> rats = new ArrayList<String>();
ArrayList<String> other = new ArrayList<String>();
ArrayList<String> man = new ArrayList<String>();
String capitan= "";
int n= in.nextInt();
in.nextLine();
for (int i = 0; i < n; i++) {
String[] s= in.nextLine().split(" ");
if(s[1].equals("rat")) rats.add(s[0]);
if(s[1].equals("woman") || s[1].equals("child")) other.add(s[0]);
if(s[1].equals("man")) man.add(s[0]);
if(s[1].equals("captain")) capitan=s[0];
}
for(String s: rats)
System.out.println(s);
for(String s: other)
System.out.println(s);
for(String s: man)
System.out.println(s);
if(capitan.length()!=0)
System.out.println(capitan);
}
}
| Java | ["6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman"] | 2 seconds | ["Teddy\nAlice\nBob\nJulia\nCharlie\nJack"] | null | Java 6 | standard input | [
"implementation",
"sortings",
"strings"
] | 753113fa5130a67423f2e205c97f8017 | The first line contains an integer n, which is the number of people in the crew (1ββ€βnββ€β100). Then follow n lines. The i-th of those lines contains two words β the name of the crew member who is i-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain. | 900 | Print n lines. The i-th of them should contain the name of the crew member who must be the i-th one to leave the ship. | standard output | |
PASSED | 807c4f79c532acb63e883b401619e77e | train_000.jsonl | 1298908800 | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically:The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last.If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less).For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew. | 256 megabytes | //package A;
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {
Scanner sc;
int p(String str) {
if (str.equals("rat")) {
return 0;
}
if (str.equals("child")) {
return 1;
}
if (str.equals("woman")) {
return 1;
}
if (str.equals("man")) {
return 2;
}
return 3;
}
public void run() {
int n = sc.nextInt();
String[] str = new String[n];
int[] pri = new int[n];
for (int i = 0; i < n; i++) {
str[i] = sc.next();
pri[i] = p(sc.next());
}
for (int j = 0; j < 4; j++) {
for (int i = 0; i < n; i++) {
if (pri[i] == j) {
System.out.println(str[i]);
}
}
}
}
public static void main(String[] args) {
Main m = new Main();
m.sc = new Scanner(System.in);
m.run();
}
}
| Java | ["6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman"] | 2 seconds | ["Teddy\nAlice\nBob\nJulia\nCharlie\nJack"] | null | Java 6 | standard input | [
"implementation",
"sortings",
"strings"
] | 753113fa5130a67423f2e205c97f8017 | The first line contains an integer n, which is the number of people in the crew (1ββ€βnββ€β100). Then follow n lines. The i-th of those lines contains two words β the name of the crew member who is i-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain. | 900 | Print n lines. The i-th of them should contain the name of the crew member who must be the i-th one to leave the ship. | standard output | |
PASSED | 15826b92f5fd256dcb64887d4893e83f | train_000.jsonl | 1298908800 | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically:The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last.If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less).For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew. | 256 megabytes | import java.io.BufferedInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
public class _59A
{
public static void main(String[] args)
{
Scanner sc = new Scanner(new BufferedInputStream(System.in));
int n = sc.nextInt();
String[] m1 = new String[n];
String[] m2 = new String[n];
for(int i=0;i<n;i++)
{
m1[i] = sc.next();
m2[i] = sc.next();
}
ArrayList<String> out = new ArrayList<String>();
//get rats
for(int i=0;i<n;i++)
{
if(!out.contains(m1[i]))
{
if(m2[i].compareTo("rat") == 0)
{
System.out.println(m1[i]);
out.add(m1[i]);
}
}
}
for(int i=0;i<n;i++)
{
if(!out.contains(m1[i]))
{
if(m2[i].compareTo("woman") == 0 || m2[i].compareTo("child") == 0)
{
System.out.println(m1[i]);
out.add(m1[i]);
}
}
}
for(int i=0;i<n;i++)
{
if(!out.contains(m1[i]))
{
if(m2[i].compareTo("man") == 0)
{
System.out.println(m1[i]);
out.add(m1[i]);
}
}
}
for(int i=0;i<n;i++)
{
if(!out.contains(m1[i]))
{
if(m2[i].compareTo("captain") == 0)
{
System.out.println(m1[i]);
out.add(m1[i]);
}
}
}
}
}
| Java | ["6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman"] | 2 seconds | ["Teddy\nAlice\nBob\nJulia\nCharlie\nJack"] | null | Java 6 | standard input | [
"implementation",
"sortings",
"strings"
] | 753113fa5130a67423f2e205c97f8017 | The first line contains an integer n, which is the number of people in the crew (1ββ€βnββ€β100). Then follow n lines. The i-th of those lines contains two words β the name of the crew member who is i-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain. | 900 | Print n lines. The i-th of them should contain the name of the crew member who must be the i-th one to leave the ship. | standard output | |
PASSED | 0420c046daf7a91886ad84518633d107 | train_000.jsonl | 1298908800 | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically:The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last.If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less).For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew. | 256 megabytes |
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.StringTokenizer;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Trung Pham
*/
public class A {
public static void main(String[] args) {
Scanner in = new Scanner();
PrintWriter out = new PrintWriter(System.out);
int n = in.nextInt();
Crew [] data = new Crew[n];
for (int i = 0; i < n; i++) {
String name = in.next();
String type = in.next();
int a = type.equals("rat") ? 0 : type.equals("woman") || type.equals("child") ? 1 : type.equals("man") ? 2 : 3;
data[i] = new Crew(name, i, a);
}
Arrays.sort(data);
for(Crew c : data){
out.println(c.name);
}
out.close();
}
public static class Crew implements Comparable<Crew> {
String name;
int index, type;
public Crew(String name, int index, int type) {
this.name = name;
this.index = index;
this.type = type;
}
@Override
public int compareTo(Crew o) {
if(type != o.type ){
return type - o.type;
}else{
return index - o.index;
}
}
}
static class FT {
int[] data;
FT(int n) {
data = new int[n];
}
void update(int index, int val) {
// System.out.println("UPDATE INDEX " + index);
while (index < data.length) {
data[index] += val;
index += index & (-index);
// System.out.println("NEXT " +index);
}
}
int get(int index) {
// System.out.println("GET INDEX " + index);
int result = 0;
while (index > 0) {
result += data[index];
index -= index & (-index);
// System.out.println("BACK " + index);
}
return result;
}
}
static int gcd(int a, int b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
static int pow(int a, int b) {
if (b == 0) {
return 1;
}
if (b == 1) {
return a;
}
int val = pow(a, b / 2);
if (b % 2 == 0) {
return val * val;
} else {
return val * val * a;
}
}
// static Point intersect(Point a, Point b, Point c) {
// double D = cross(a, b);
// if (D != 0) {
// return new Point(cross(c, b) / D, cross(a, c) / D);
// }
// return null;
// }
//
// static Point convert(Point a, double angle) {
// double x = a.x * cos(angle) - a.y * sin(angle);
// double y = a.x * sin(angle) + a.y * cos(angle);
// return new Point(x, y);
// }
static Point minus(Point a, Point b) {
return new Point(a.x - b.x, a.y - b.y);
}
static Point add(Point a, Point b) {
return new Point(a.x + b.x, a.y + b.y);
}
static double cross(Point a, Point b) {
return a.x * b.y - a.y * b.x;
}
static class Point {
int x, y;
Point(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public String toString() {
return "Point: " + x + " " + y;
}
}
static class Scanner {
BufferedReader br;
StringTokenizer st;
public Scanner() {
//System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
br = new BufferedReader(new InputStreamReader(System.in));
}
public String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
throw new RuntimeException();
}
}
return st.nextToken();
}
public long nextLong() {
return Long.parseLong(next());
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() {
st = null;
try {
return br.readLine();
} catch (Exception e) {
throw new RuntimeException();
}
}
public boolean endLine() {
try {
String next = br.readLine();
while (next != null && next.trim().isEmpty()) {
next = br.readLine();
}
if (next == null) {
return true;
}
st = new StringTokenizer(next);
return st.hasMoreTokens();
} catch (Exception e) {
throw new RuntimeException();
}
}
}
}
| Java | ["6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman"] | 2 seconds | ["Teddy\nAlice\nBob\nJulia\nCharlie\nJack"] | null | Java 6 | standard input | [
"implementation",
"sortings",
"strings"
] | 753113fa5130a67423f2e205c97f8017 | The first line contains an integer n, which is the number of people in the crew (1ββ€βnββ€β100). Then follow n lines. The i-th of those lines contains two words β the name of the crew member who is i-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain. | 900 | Print n lines. The i-th of them should contain the name of the crew member who must be the i-th one to leave the ship. | standard output | |
PASSED | c79e2c8d23e07b5ce5402b9b0e19f902 | train_000.jsonl | 1298908800 | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically:The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last.If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less).For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew. | 256 megabytes | import java.util.Scanner;
import java.util.LinkedList;
public class SinkingShip
{
public static class Member
{
String name;
String status;
public Member(String name, String status)
{
this.name = name;
this.status = status;
}
}
public static void main(String[] args)
{
int[] priority = {0, 1, 2, 3};
Scanner input = new Scanner(System.in);
int n = input.nextInt();
input.nextLine();
LinkedList<Member> members = new LinkedList<Member>();
String[] person;
for (int i = 0; i < n; ++i)
{
person = input.nextLine().split(" ");
members.add(new Member(person[0], person[1]));
}
int idx = 0;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < priority.length; ++i)
{
idx = 0;
while (idx < members.size())
{
switch (priority[i])
{
case 0:
if (members.get(idx).status.equals("rat"))
{
sb.append(members.get(idx).name + "\n");
members.remove(idx);
}
else
{
++idx;
}
break;
case 1:
if (members.get(idx).status.equals("child") || members.get(idx).status.equals("woman"))
{
sb.append(members.get(idx).name + "\n");
members.remove(idx);
}
else
{
++idx;
}
break;
case 2:
if (members.get(idx).status.equals("man"))
{
sb.append(members.get(idx).name + "\n");
members.remove(idx);
}
else
{
++idx;
}
break;
case 3:
if (members.get(idx).status.equals("captain"))
{
sb.append(members.get(idx).name + "\n");
members.remove(idx);
}
else
{
++idx;
}
break;
default:
break;
}
}
}
System.out.print(sb.toString());
}
} | Java | ["6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman"] | 2 seconds | ["Teddy\nAlice\nBob\nJulia\nCharlie\nJack"] | null | Java 6 | standard input | [
"implementation",
"sortings",
"strings"
] | 753113fa5130a67423f2e205c97f8017 | The first line contains an integer n, which is the number of people in the crew (1ββ€βnββ€β100). Then follow n lines. The i-th of those lines contains two words β the name of the crew member who is i-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain. | 900 | Print n lines. The i-th of them should contain the name of the crew member who must be the i-th one to leave the ship. | standard output | |
PASSED | e85ccf1d3a83f51964263aff9d06c70f | train_000.jsonl | 1298908800 | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically:The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last.If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less).For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew. | 256 megabytes | import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
/**
* @author manu
*
*/
public class SinkingShip {
/**
* @param args
*/
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String captain = null;
List<String> womanchild= new ArrayList<String>();
List<String> rats= new ArrayList<String>();
List<String> man= new ArrayList<String>();
String name,role;
int N= in.nextInt();
for (int i = 0; i < N; i++) {
name=in.next();
role=in.next();
if(role.equals("rat"))
rats.add(name);
else if(role.equals("woman") || role.equals("child"))
womanchild.add(name);
else if(role.equals("man"))
man.add(name);
else
captain=name;
}
//printing
for (Iterator<String> iterator = rats.iterator(); iterator.hasNext();) {
String string = (String) iterator.next();
System.out.println(string);
}
for (Iterator<String> iterator = womanchild.iterator(); iterator.hasNext();) {
String string = (String) iterator.next();
System.out.println(string);
}
for (Iterator<String> iterator = man.iterator(); iterator.hasNext();) {
String string = (String) iterator.next();
System.out.println(string);
}
System.out.println(captain);
}
} | Java | ["6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman"] | 2 seconds | ["Teddy\nAlice\nBob\nJulia\nCharlie\nJack"] | null | Java 6 | standard input | [
"implementation",
"sortings",
"strings"
] | 753113fa5130a67423f2e205c97f8017 | The first line contains an integer n, which is the number of people in the crew (1ββ€βnββ€β100). Then follow n lines. The i-th of those lines contains two words β the name of the crew member who is i-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain. | 900 | Print n lines. The i-th of them should contain the name of the crew member who must be the i-th one to leave the ship. | standard output | |
PASSED | fa61805c236bdc2edee516e50d1a2f85 | train_000.jsonl | 1298908800 | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All n crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to n) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically:The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last.If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less).For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew. | 256 megabytes | import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
* @author manu
*
*/
public class SinkingShip {
/**
* @param args
*/
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String captain = null;
List<String> womanchild= new ArrayList<String>();
List<String> rats= new ArrayList<String>();
List<String> man= new ArrayList<String>();
String name,role;
int N= in.nextInt();
for (int i = 0; i < N; i++) {
name=in.next();
role=in.next();
if(role.equals("rat"))
rats.add(name);
else if(role.equals("woman") || role.equals("child"))
womanchild.add(name);
else if(role.equals("man"))
man.add(name);
else
captain=name;
}
//printing
for(String str: rats){
System.out.println(str);
}
for(String str: womanchild){
System.out.println(str);
}
for(String str: man){
System.out.println(str);
}
System.out.println(captain);
}
}
| Java | ["6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman"] | 2 seconds | ["Teddy\nAlice\nBob\nJulia\nCharlie\nJack"] | null | Java 6 | standard input | [
"implementation",
"sortings",
"strings"
] | 753113fa5130a67423f2e205c97f8017 | The first line contains an integer n, which is the number of people in the crew (1ββ€βnββ€β100). Then follow n lines. The i-th of those lines contains two words β the name of the crew member who is i-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain. | 900 | Print n lines. The i-th of them should contain the name of the crew member who must be the i-th one to leave the ship. | standard output | |
PASSED | 93d2a84b52dffa7b3c93f87bcf53c883 | train_000.jsonl | 1332860400 | Let's dive into one of the most interesting areas of magic β writing spells. Learning this exciting but challenging science is very troublesome, so now you will not learn the magic words, but only get to know the basic rules of writing spells.Each spell consists of several lines. The line, whose first non-space character is character "#" is an amplifying line and it is responsible for spell power. The remaining lines are common, and determine the effect of the spell.You came across the text of some spell. Spell was too long, so you cannot understand its meaning. So you want to make it as short as possible without changing the meaning.The only way to shorten a spell that you know is the removal of some spaces and line breaks. We know that when it comes to texts of spells, the spaces carry meaning only in the amplifying lines, so we should remove all spaces in other lines. Newlines also do not matter, unless any of the two separated lines is amplifying. Thus, if two consecutive lines are not amplifying, they need to be joined into one (i.e. we should concatenate the second line to the first one). Removing spaces in amplifying lines and concatenating the amplifying lines to anything is forbidden.Note that empty lines must be processed just like all the others: they must be joined to the adjacent non-amplifying lines, or preserved in the output, if they are surrounded with amplifying lines on both sides (i.e. the line above it, if there is one, is amplifying, and the line below it, if there is one, is amplifying too).For now those are the only instructions for removing unnecessary characters that you have to follow (oh yes, a newline is a character, too).The input contains the text of the spell, which should be reduced. Remove the extra characters and print the result to the output. | 256 megabytes | import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Solver {
StringTokenizer st;
BufferedReader in;
PrintWriter out;
public static void main(String[] args) throws NumberFormatException, IOException {
Solver solver = new Solver();
solver.open();
solver.solve();
solver.close();
}
public void open() throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
}
public String nextToken() throws IOException {
while (st == null || !st.hasMoreTokens()) {
String line = in.readLine();
if (line==null) return null;
st = new StringTokenizer(line);
}
return st.nextToken();
}
public int nextInt() throws NumberFormatException, IOException {
return Integer.parseInt(nextToken());
}
public long nextLong() throws NumberFormatException, IOException {
return Long.parseLong(nextToken());
}
public double nextDouble() throws NumberFormatException, IOException {
return Double.parseDouble(nextToken());
}
boolean check(String line){
int i = 0;
for (i=0;i<line.length() && Character.isWhitespace(line.charAt(i));i++){}
return i==line.length() || line.charAt(i)!='#';
}
String process(String line){
StringBuilder sb = new StringBuilder();
for (int i=0;i<line.length();i++){
char c = line.charAt(i);
if(!Character.isWhitespace(c)){
sb.append(c);
}
}
return sb.toString();
}
public void solve() throws NumberFormatException, IOException {
String line = null;
StringBuilder pred = null;
while((line=in.readLine()) != null){
if (!check(line)){
if (pred!=null){
out.println(process(pred.toString()));
}
out.println(line);
pred = null;
}else{
if (pred==null){
pred = new StringBuilder(line);
}else{
pred.append(line);
}
}
}
if (pred!=null){
out.println(process(pred.toString()));
}
}
public void close() {
out.flush();
out.close();
}
} | Java | ["# include <cstdio>\n\nusing namespace std;\n\nint main ( ){\nputs(\"Hello # World\"); #\n#\n}", "#\n\n#"] | 2 seconds | ["# include <cstdio>\nusingnamespacestd;intmain(){puts(\"Hello#World\");#\n#\n}", "#\n\n#"] | NoteIn the first sample the amplifying lines are lines 1 and 7. So, lines 2 to 6 are concatenated to each other, all spaces are deleted from them.In the second sample the amplifying lines are lines 1 and 3. So, no lines are concatenated to each other. | Java 6 | standard input | [
"implementation",
"strings"
] | a16bb696858bc592c33dcf0fd99df197 | The input contains multiple lines. All characters in the lines have codes from 32 to 127 (inclusive). Please note that the lines may begin with or end with one or more spaces. The size of the input does not exceed 1048576 (β=β220) bytes. Newlines are included in this size. In the Windows operating system used on the testing computer, a newline is a sequence of characters with codes #13#10. It is guaranteed that after each line of input there is a newline. In particular, the input ends with a newline. Note that the newline is the end of the line, and not the beginning of the next one. It is guaranteed that the input contains at least one character other than a newline. It is recommended to organize the input-output line by line, in this case the newlines will be processed correctly by the language means. | 1,700 | Print the text of the spell where all extra characters are deleted. Please note that each output line should be followed by a newline. Please be careful: your answers will be validated by comparing them to the jury's answer byte-by-byte. So, all spaces and newlines matter. | standard output | |
PASSED | d6cac5af6f3c8bf3c15dcf5f972efeee | train_000.jsonl | 1332860400 | Let's dive into one of the most interesting areas of magic β writing spells. Learning this exciting but challenging science is very troublesome, so now you will not learn the magic words, but only get to know the basic rules of writing spells.Each spell consists of several lines. The line, whose first non-space character is character "#" is an amplifying line and it is responsible for spell power. The remaining lines are common, and determine the effect of the spell.You came across the text of some spell. Spell was too long, so you cannot understand its meaning. So you want to make it as short as possible without changing the meaning.The only way to shorten a spell that you know is the removal of some spaces and line breaks. We know that when it comes to texts of spells, the spaces carry meaning only in the amplifying lines, so we should remove all spaces in other lines. Newlines also do not matter, unless any of the two separated lines is amplifying. Thus, if two consecutive lines are not amplifying, they need to be joined into one (i.e. we should concatenate the second line to the first one). Removing spaces in amplifying lines and concatenating the amplifying lines to anything is forbidden.Note that empty lines must be processed just like all the others: they must be joined to the adjacent non-amplifying lines, or preserved in the output, if they are surrounded with amplifying lines on both sides (i.e. the line above it, if there is one, is amplifying, and the line below it, if there is one, is amplifying too).For now those are the only instructions for removing unnecessary characters that you have to follow (oh yes, a newline is a character, too).The input contains the text of the spell, which should be reduced. Remove the extra characters and print the result to the output. | 256 megabytes | import java.io.*;
import java.util.*;
public class B {
public void solve() throws IOException {
boolean isOnline = false;
while (true) {
String s = reader.readLine();
if (s == null) {
if (isOnline) writer.println();
break;
}
if (isAmplify(s)) {
if (isOnline) writer.println();
isOnline = false;
writer.println(s);
}
else {
for (int i = 0; i < s.length(); i++)
if (s.charAt(i) != ' ')
writer.print(s.charAt(i));
isOnline = true;
}
}
}
public boolean isAmplify(String s) {
for (int i = 0; i < s.length(); i++)
if (s.charAt(i) != ' ') {
if (s.charAt(i) == '#') return true;
return false;
}
return false;
}
public static void main(String[] args) throws FileNotFoundException {
new B().run();
}
BufferedReader reader;
StringTokenizer tokenizer;
PrintWriter writer;
public void run() {
try {
long tbegin = System.currentTimeMillis();
reader = new BufferedReader(new InputStreamReader(System.in));
//reader = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt")));
tokenizer = null;
writer = new PrintWriter(System.out);
//writer = new PrintWriter(new FileOutputStream("output.txt"));
solve();
//reader.close();
//System.out.println(System.currentTimeMillis() - tbegin + "ms");
writer.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
String nextToken() throws IOException {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
}
| Java | ["# include <cstdio>\n\nusing namespace std;\n\nint main ( ){\nputs(\"Hello # World\"); #\n#\n}", "#\n\n#"] | 2 seconds | ["# include <cstdio>\nusingnamespacestd;intmain(){puts(\"Hello#World\");#\n#\n}", "#\n\n#"] | NoteIn the first sample the amplifying lines are lines 1 and 7. So, lines 2 to 6 are concatenated to each other, all spaces are deleted from them.In the second sample the amplifying lines are lines 1 and 3. So, no lines are concatenated to each other. | Java 6 | standard input | [
"implementation",
"strings"
] | a16bb696858bc592c33dcf0fd99df197 | The input contains multiple lines. All characters in the lines have codes from 32 to 127 (inclusive). Please note that the lines may begin with or end with one or more spaces. The size of the input does not exceed 1048576 (β=β220) bytes. Newlines are included in this size. In the Windows operating system used on the testing computer, a newline is a sequence of characters with codes #13#10. It is guaranteed that after each line of input there is a newline. In particular, the input ends with a newline. Note that the newline is the end of the line, and not the beginning of the next one. It is guaranteed that the input contains at least one character other than a newline. It is recommended to organize the input-output line by line, in this case the newlines will be processed correctly by the language means. | 1,700 | Print the text of the spell where all extra characters are deleted. Please note that each output line should be followed by a newline. Please be careful: your answers will be validated by comparing them to the jury's answer byte-by-byte. So, all spaces and newlines matter. | standard output | |
PASSED | b87b4bd7586905fd49fd23c7d188ea28 | train_000.jsonl | 1332860400 | Let's dive into one of the most interesting areas of magic β writing spells. Learning this exciting but challenging science is very troublesome, so now you will not learn the magic words, but only get to know the basic rules of writing spells.Each spell consists of several lines. The line, whose first non-space character is character "#" is an amplifying line and it is responsible for spell power. The remaining lines are common, and determine the effect of the spell.You came across the text of some spell. Spell was too long, so you cannot understand its meaning. So you want to make it as short as possible without changing the meaning.The only way to shorten a spell that you know is the removal of some spaces and line breaks. We know that when it comes to texts of spells, the spaces carry meaning only in the amplifying lines, so we should remove all spaces in other lines. Newlines also do not matter, unless any of the two separated lines is amplifying. Thus, if two consecutive lines are not amplifying, they need to be joined into one (i.e. we should concatenate the second line to the first one). Removing spaces in amplifying lines and concatenating the amplifying lines to anything is forbidden.Note that empty lines must be processed just like all the others: they must be joined to the adjacent non-amplifying lines, or preserved in the output, if they are surrounded with amplifying lines on both sides (i.e. the line above it, if there is one, is amplifying, and the line below it, if there is one, is amplifying too).For now those are the only instructions for removing unnecessary characters that you have to follow (oh yes, a newline is a character, too).The input contains the text of the spell, which should be reduced. Remove the extra characters and print the result to the output. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class Main {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
PrintWriter out=new PrintWriter(System.out);
boolean check=false;
while(in.ready()){
String cur=in.readLine();
String curTrimed=cur.trim();
if(curTrimed.length()>0 && curTrimed.charAt(0)=='#'){
if(check) {
check=false;
out.println();
}
out.println(cur);
}
else{
out.print(cur.replaceAll(" ", "").replaceAll("\r\n", ""));
check=true;
}
}
if(check) out.println();
out.close();
}
} | Java | ["# include <cstdio>\n\nusing namespace std;\n\nint main ( ){\nputs(\"Hello # World\"); #\n#\n}", "#\n\n#"] | 2 seconds | ["# include <cstdio>\nusingnamespacestd;intmain(){puts(\"Hello#World\");#\n#\n}", "#\n\n#"] | NoteIn the first sample the amplifying lines are lines 1 and 7. So, lines 2 to 6 are concatenated to each other, all spaces are deleted from them.In the second sample the amplifying lines are lines 1 and 3. So, no lines are concatenated to each other. | Java 6 | standard input | [
"implementation",
"strings"
] | a16bb696858bc592c33dcf0fd99df197 | The input contains multiple lines. All characters in the lines have codes from 32 to 127 (inclusive). Please note that the lines may begin with or end with one or more spaces. The size of the input does not exceed 1048576 (β=β220) bytes. Newlines are included in this size. In the Windows operating system used on the testing computer, a newline is a sequence of characters with codes #13#10. It is guaranteed that after each line of input there is a newline. In particular, the input ends with a newline. Note that the newline is the end of the line, and not the beginning of the next one. It is guaranteed that the input contains at least one character other than a newline. It is recommended to organize the input-output line by line, in this case the newlines will be processed correctly by the language means. | 1,700 | Print the text of the spell where all extra characters are deleted. Please note that each output line should be followed by a newline. Please be careful: your answers will be validated by comparing them to the jury's answer byte-by-byte. So, all spaces and newlines matter. | standard output | |
PASSED | be172335b6d42f2b2b8913c674ac6b5a | train_000.jsonl | 1332860400 | Let's dive into one of the most interesting areas of magic β writing spells. Learning this exciting but challenging science is very troublesome, so now you will not learn the magic words, but only get to know the basic rules of writing spells.Each spell consists of several lines. The line, whose first non-space character is character "#" is an amplifying line and it is responsible for spell power. The remaining lines are common, and determine the effect of the spell.You came across the text of some spell. Spell was too long, so you cannot understand its meaning. So you want to make it as short as possible without changing the meaning.The only way to shorten a spell that you know is the removal of some spaces and line breaks. We know that when it comes to texts of spells, the spaces carry meaning only in the amplifying lines, so we should remove all spaces in other lines. Newlines also do not matter, unless any of the two separated lines is amplifying. Thus, if two consecutive lines are not amplifying, they need to be joined into one (i.e. we should concatenate the second line to the first one). Removing spaces in amplifying lines and concatenating the amplifying lines to anything is forbidden.Note that empty lines must be processed just like all the others: they must be joined to the adjacent non-amplifying lines, or preserved in the output, if they are surrounded with amplifying lines on both sides (i.e. the line above it, if there is one, is amplifying, and the line below it, if there is one, is amplifying too).For now those are the only instructions for removing unnecessary characters that you have to follow (oh yes, a newline is a character, too).The input contains the text of the spell, which should be reduced. Remove the extra characters and print the result to the output. | 256 megabytes | import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
/*
br = new BufferedReader(new FileReader("input.txt"));
pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
*/
public class Main {
private static BufferedReader br;
private static StringTokenizer st;
private static PrintWriter pw;
public static void main(String[] args) throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int qq = 1;
//int qq = Integer.MAX_VALUE;
//int qq = readInt();
for(int casenum = 1; casenum <= qq; casenum++) {
ArrayList<String> list = new ArrayList<String>();
while(true) {
String s = br.readLine();
if(s==null) break;
if(!is(s)) {
list.add(clean(s));
}
else {
list.add(s);
}
}
for(int i = 0; i < list.size(); ) {
if(is(list.get(i))) {
pw.println(list.get(i++));
}
else {
StringBuilder sb = new StringBuilder();
int j = i;
for(j = i; j < list.size(); j++) {
if(is(list.get(j))) {
break;
}
sb.append(list.get(j));
}
i=j;
pw.println(sb);
}
}
}
pw.close();
}
public static boolean is(String s) {
for(int i = 0; i < s.length(); i++) {
if(!Character.isWhitespace(s.charAt(i))) {
return s.charAt(i) == '#';
}
}
return false;
}
public static String clean(String s) {
StringBuilder sb = new StringBuilder();
for(int i = 0; i < s.length(); i++) {
if(!Character.isWhitespace(s.charAt(i))) {
sb.append(s.charAt(i));
}
}
return sb.toString();
}
private static void exitImmediately() {
pw.close();
System.exit(0);
}
private static long readLong() throws IOException {
return Long.parseLong(nextToken());
}
private static double readDouble() throws IOException {
return Double.parseDouble(nextToken());
}
private static int readInt() throws IOException {
return Integer.parseInt(nextToken());
}
private static String nextToken() throws IOException {
while(st == null || !st.hasMoreTokens()) {
if(!br.ready()) {
exitImmediately();
}
st = new StringTokenizer(br.readLine().trim());
}
return st.nextToken();
}
}
| Java | ["# include <cstdio>\n\nusing namespace std;\n\nint main ( ){\nputs(\"Hello # World\"); #\n#\n}", "#\n\n#"] | 2 seconds | ["# include <cstdio>\nusingnamespacestd;intmain(){puts(\"Hello#World\");#\n#\n}", "#\n\n#"] | NoteIn the first sample the amplifying lines are lines 1 and 7. So, lines 2 to 6 are concatenated to each other, all spaces are deleted from them.In the second sample the amplifying lines are lines 1 and 3. So, no lines are concatenated to each other. | Java 6 | standard input | [
"implementation",
"strings"
] | a16bb696858bc592c33dcf0fd99df197 | The input contains multiple lines. All characters in the lines have codes from 32 to 127 (inclusive). Please note that the lines may begin with or end with one or more spaces. The size of the input does not exceed 1048576 (β=β220) bytes. Newlines are included in this size. In the Windows operating system used on the testing computer, a newline is a sequence of characters with codes #13#10. It is guaranteed that after each line of input there is a newline. In particular, the input ends with a newline. Note that the newline is the end of the line, and not the beginning of the next one. It is guaranteed that the input contains at least one character other than a newline. It is recommended to organize the input-output line by line, in this case the newlines will be processed correctly by the language means. | 1,700 | Print the text of the spell where all extra characters are deleted. Please note that each output line should be followed by a newline. Please be careful: your answers will be validated by comparing them to the jury's answer byte-by-byte. So, all spaces and newlines matter. | standard output | |
PASSED | 1f2676b9106e4efaff9cad24104497bb | train_000.jsonl | 1332860400 | Let's dive into one of the most interesting areas of magic β writing spells. Learning this exciting but challenging science is very troublesome, so now you will not learn the magic words, but only get to know the basic rules of writing spells.Each spell consists of several lines. The line, whose first non-space character is character "#" is an amplifying line and it is responsible for spell power. The remaining lines are common, and determine the effect of the spell.You came across the text of some spell. Spell was too long, so you cannot understand its meaning. So you want to make it as short as possible without changing the meaning.The only way to shorten a spell that you know is the removal of some spaces and line breaks. We know that when it comes to texts of spells, the spaces carry meaning only in the amplifying lines, so we should remove all spaces in other lines. Newlines also do not matter, unless any of the two separated lines is amplifying. Thus, if two consecutive lines are not amplifying, they need to be joined into one (i.e. we should concatenate the second line to the first one). Removing spaces in amplifying lines and concatenating the amplifying lines to anything is forbidden.Note that empty lines must be processed just like all the others: they must be joined to the adjacent non-amplifying lines, or preserved in the output, if they are surrounded with amplifying lines on both sides (i.e. the line above it, if there is one, is amplifying, and the line below it, if there is one, is amplifying too).For now those are the only instructions for removing unnecessary characters that you have to follow (oh yes, a newline is a character, too).The input contains the text of the spell, which should be reduced. Remove the extra characters and print the result to the output. | 256 megabytes | import java.util.Scanner;
/**
* Created by IntelliJ IDEA.
* User: ΠΠΈΡ
Π°ΠΈΠ»
* Date: 27.03.12
* Time: 5:39
* To change this template use File | Settings | File Templates.
*/
public class Problem2 {
public static void main(String [] args) {
Scanner scanner = new Scanner(System.in);
String buf = "";
boolean isWrite = true;
StringBuilder answerLine = new StringBuilder("");
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
boolean flag = false;
for (int i = 0; i < line.length(); i++) {
if (line.charAt(i) != ' ') {
if (line.charAt(i) != '#') {
line = line.replace(" ", "");
flag = true;
isWrite = false;
answerLine.append(line);
break;
} else {
if (!isWrite) {
isWrite = true;
System.out.println(answerLine);
answerLine = new StringBuilder("");
}
System.out.println(line);
flag = true;
break;
}
}
}
if (!flag) {
isWrite = false;
}
}
if (!isWrite) {
System.out.println(answerLine);
}
}
}
| Java | ["# include <cstdio>\n\nusing namespace std;\n\nint main ( ){\nputs(\"Hello # World\"); #\n#\n}", "#\n\n#"] | 2 seconds | ["# include <cstdio>\nusingnamespacestd;intmain(){puts(\"Hello#World\");#\n#\n}", "#\n\n#"] | NoteIn the first sample the amplifying lines are lines 1 and 7. So, lines 2 to 6 are concatenated to each other, all spaces are deleted from them.In the second sample the amplifying lines are lines 1 and 3. So, no lines are concatenated to each other. | Java 6 | standard input | [
"implementation",
"strings"
] | a16bb696858bc592c33dcf0fd99df197 | The input contains multiple lines. All characters in the lines have codes from 32 to 127 (inclusive). Please note that the lines may begin with or end with one or more spaces. The size of the input does not exceed 1048576 (β=β220) bytes. Newlines are included in this size. In the Windows operating system used on the testing computer, a newline is a sequence of characters with codes #13#10. It is guaranteed that after each line of input there is a newline. In particular, the input ends with a newline. Note that the newline is the end of the line, and not the beginning of the next one. It is guaranteed that the input contains at least one character other than a newline. It is recommended to organize the input-output line by line, in this case the newlines will be processed correctly by the language means. | 1,700 | Print the text of the spell where all extra characters are deleted. Please note that each output line should be followed by a newline. Please be careful: your answers will be validated by comparing them to the jury's answer byte-by-byte. So, all spaces and newlines matter. | standard output | |
PASSED | 2245dcd9cb551691b22c6ef8295ac3d9 | train_000.jsonl | 1332860400 | Let's dive into one of the most interesting areas of magic β writing spells. Learning this exciting but challenging science is very troublesome, so now you will not learn the magic words, but only get to know the basic rules of writing spells.Each spell consists of several lines. The line, whose first non-space character is character "#" is an amplifying line and it is responsible for spell power. The remaining lines are common, and determine the effect of the spell.You came across the text of some spell. Spell was too long, so you cannot understand its meaning. So you want to make it as short as possible without changing the meaning.The only way to shorten a spell that you know is the removal of some spaces and line breaks. We know that when it comes to texts of spells, the spaces carry meaning only in the amplifying lines, so we should remove all spaces in other lines. Newlines also do not matter, unless any of the two separated lines is amplifying. Thus, if two consecutive lines are not amplifying, they need to be joined into one (i.e. we should concatenate the second line to the first one). Removing spaces in amplifying lines and concatenating the amplifying lines to anything is forbidden.Note that empty lines must be processed just like all the others: they must be joined to the adjacent non-amplifying lines, or preserved in the output, if they are surrounded with amplifying lines on both sides (i.e. the line above it, if there is one, is amplifying, and the line below it, if there is one, is amplifying too).For now those are the only instructions for removing unnecessary characters that you have to follow (oh yes, a newline is a character, too).The input contains the text of the spell, which should be reduced. Remove the extra characters and print the result to the output. | 256 megabytes | import java.util.Scanner;
public class Main {
static String linea;
static boolean ok;
public static void main(String[] args) {
Scanner l = new Scanner(System.in);
ok=true;
while (l.hasNextLine()) {
linea=l.nextLine();
if(linea.trim().length()>0){
if(linea.trim().charAt(0)=='#'){
if(!ok){
System.out.println();
}
System.out.println(linea);
ok=true;
}else{
linea=linea.replaceAll(" ", "");
System.out.print(linea);
ok=false;
}
}else{
ok=false;
}
}
if(!ok){
System.out.println();
}
}
}
| Java | ["# include <cstdio>\n\nusing namespace std;\n\nint main ( ){\nputs(\"Hello # World\"); #\n#\n}", "#\n\n#"] | 2 seconds | ["# include <cstdio>\nusingnamespacestd;intmain(){puts(\"Hello#World\");#\n#\n}", "#\n\n#"] | NoteIn the first sample the amplifying lines are lines 1 and 7. So, lines 2 to 6 are concatenated to each other, all spaces are deleted from them.In the second sample the amplifying lines are lines 1 and 3. So, no lines are concatenated to each other. | Java 6 | standard input | [
"implementation",
"strings"
] | a16bb696858bc592c33dcf0fd99df197 | The input contains multiple lines. All characters in the lines have codes from 32 to 127 (inclusive). Please note that the lines may begin with or end with one or more spaces. The size of the input does not exceed 1048576 (β=β220) bytes. Newlines are included in this size. In the Windows operating system used on the testing computer, a newline is a sequence of characters with codes #13#10. It is guaranteed that after each line of input there is a newline. In particular, the input ends with a newline. Note that the newline is the end of the line, and not the beginning of the next one. It is guaranteed that the input contains at least one character other than a newline. It is recommended to organize the input-output line by line, in this case the newlines will be processed correctly by the language means. | 1,700 | Print the text of the spell where all extra characters are deleted. Please note that each output line should be followed by a newline. Please be careful: your answers will be validated by comparing them to the jury's answer byte-by-byte. So, all spaces and newlines matter. | standard output | |
PASSED | cbf35c0ab3502902e62f37d50d14ee17 | train_000.jsonl | 1332860400 | Let's dive into one of the most interesting areas of magic β writing spells. Learning this exciting but challenging science is very troublesome, so now you will not learn the magic words, but only get to know the basic rules of writing spells.Each spell consists of several lines. The line, whose first non-space character is character "#" is an amplifying line and it is responsible for spell power. The remaining lines are common, and determine the effect of the spell.You came across the text of some spell. Spell was too long, so you cannot understand its meaning. So you want to make it as short as possible without changing the meaning.The only way to shorten a spell that you know is the removal of some spaces and line breaks. We know that when it comes to texts of spells, the spaces carry meaning only in the amplifying lines, so we should remove all spaces in other lines. Newlines also do not matter, unless any of the two separated lines is amplifying. Thus, if two consecutive lines are not amplifying, they need to be joined into one (i.e. we should concatenate the second line to the first one). Removing spaces in amplifying lines and concatenating the amplifying lines to anything is forbidden.Note that empty lines must be processed just like all the others: they must be joined to the adjacent non-amplifying lines, or preserved in the output, if they are surrounded with amplifying lines on both sides (i.e. the line above it, if there is one, is amplifying, and the line below it, if there is one, is amplifying too).For now those are the only instructions for removing unnecessary characters that you have to follow (oh yes, a newline is a character, too).The input contains the text of the spell, which should be reduced. Remove the extra characters and print the result to the output. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
static BufferedReader br;
static Scanner sc;
static PrintWriter pw;
static int n, x, y;
static boolean isPower(String s) {
int i = 0;
while(i < s.length() && s.charAt(i) == ' ')
i++;
if(s.indexOf('#') == i)
return true;
else
return false;
}
public static void main(String[] args) throws IOException {
sc = new Scanner(System.in);
pw = new PrintWriter(System.out);
br = new BufferedReader(new InputStreamReader(System.in));
try {
String s1 = null;
String s2 = null;
s1 = br.readLine();
while(br.ready()) {
s2 = br.readLine();
if(isPower(s1)) {
pw.println(s1);
s1 = s2;
continue;
}
if(s2.equals(""))
continue;
for(int i = 0; i < s1.length(); i++)
if(s1.charAt(i) != ' ')
pw.print(s1.charAt(i));
if(isPower(s2))
pw.println();
s1 = s2;
}
if(isPower(s1))
pw.print(s1);
else {
for(int i = 0; i < s1.length(); i++)
if(s1.charAt(i) != ' ')
pw.print(s1.charAt(i));
}
pw.println();
}
finally {
pw.close();
}
}
} | Java | ["# include <cstdio>\n\nusing namespace std;\n\nint main ( ){\nputs(\"Hello # World\"); #\n#\n}", "#\n\n#"] | 2 seconds | ["# include <cstdio>\nusingnamespacestd;intmain(){puts(\"Hello#World\");#\n#\n}", "#\n\n#"] | NoteIn the first sample the amplifying lines are lines 1 and 7. So, lines 2 to 6 are concatenated to each other, all spaces are deleted from them.In the second sample the amplifying lines are lines 1 and 3. So, no lines are concatenated to each other. | Java 6 | standard input | [
"implementation",
"strings"
] | a16bb696858bc592c33dcf0fd99df197 | The input contains multiple lines. All characters in the lines have codes from 32 to 127 (inclusive). Please note that the lines may begin with or end with one or more spaces. The size of the input does not exceed 1048576 (β=β220) bytes. Newlines are included in this size. In the Windows operating system used on the testing computer, a newline is a sequence of characters with codes #13#10. It is guaranteed that after each line of input there is a newline. In particular, the input ends with a newline. Note that the newline is the end of the line, and not the beginning of the next one. It is guaranteed that the input contains at least one character other than a newline. It is recommended to organize the input-output line by line, in this case the newlines will be processed correctly by the language means. | 1,700 | Print the text of the spell where all extra characters are deleted. Please note that each output line should be followed by a newline. Please be careful: your answers will be validated by comparing them to the jury's answer byte-by-byte. So, all spaces and newlines matter. | standard output | |
PASSED | 2d14c25335629e9225d9b3e06eba7319 | train_000.jsonl | 1332860400 | Let's dive into one of the most interesting areas of magic β writing spells. Learning this exciting but challenging science is very troublesome, so now you will not learn the magic words, but only get to know the basic rules of writing spells.Each spell consists of several lines. The line, whose first non-space character is character "#" is an amplifying line and it is responsible for spell power. The remaining lines are common, and determine the effect of the spell.You came across the text of some spell. Spell was too long, so you cannot understand its meaning. So you want to make it as short as possible without changing the meaning.The only way to shorten a spell that you know is the removal of some spaces and line breaks. We know that when it comes to texts of spells, the spaces carry meaning only in the amplifying lines, so we should remove all spaces in other lines. Newlines also do not matter, unless any of the two separated lines is amplifying. Thus, if two consecutive lines are not amplifying, they need to be joined into one (i.e. we should concatenate the second line to the first one). Removing spaces in amplifying lines and concatenating the amplifying lines to anything is forbidden.Note that empty lines must be processed just like all the others: they must be joined to the adjacent non-amplifying lines, or preserved in the output, if they are surrounded with amplifying lines on both sides (i.e. the line above it, if there is one, is amplifying, and the line below it, if there is one, is amplifying too).For now those are the only instructions for removing unnecessary characters that you have to follow (oh yes, a newline is a character, too).The input contains the text of the spell, which should be reduced. Remove the extra characters and print the result to the output. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class CF114B {
private void work() throws IOException {
Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(
System.in)));
boolean first = true;
while (sc.hasNextLine()) {
String line = sc.nextLine();
if (line.trim().length() > 0) {
if (line.trim().charAt(0) == '#') {
if (!first)
System.out.println();
System.out.println(line);
first = true;
} else {
line = line.replaceAll(" ", "");
System.out.print(line);
first = false;
}
} else {
first = false;
}
}
if (!first)
System.out.println();
}
public static void main(String[] args) throws IOException {
new CF114B().work();
}
}
| Java | ["# include <cstdio>\n\nusing namespace std;\n\nint main ( ){\nputs(\"Hello # World\"); #\n#\n}", "#\n\n#"] | 2 seconds | ["# include <cstdio>\nusingnamespacestd;intmain(){puts(\"Hello#World\");#\n#\n}", "#\n\n#"] | NoteIn the first sample the amplifying lines are lines 1 and 7. So, lines 2 to 6 are concatenated to each other, all spaces are deleted from them.In the second sample the amplifying lines are lines 1 and 3. So, no lines are concatenated to each other. | Java 6 | standard input | [
"implementation",
"strings"
] | a16bb696858bc592c33dcf0fd99df197 | The input contains multiple lines. All characters in the lines have codes from 32 to 127 (inclusive). Please note that the lines may begin with or end with one or more spaces. The size of the input does not exceed 1048576 (β=β220) bytes. Newlines are included in this size. In the Windows operating system used on the testing computer, a newline is a sequence of characters with codes #13#10. It is guaranteed that after each line of input there is a newline. In particular, the input ends with a newline. Note that the newline is the end of the line, and not the beginning of the next one. It is guaranteed that the input contains at least one character other than a newline. It is recommended to organize the input-output line by line, in this case the newlines will be processed correctly by the language means. | 1,700 | Print the text of the spell where all extra characters are deleted. Please note that each output line should be followed by a newline. Please be careful: your answers will be validated by comparing them to the jury's answer byte-by-byte. So, all spaces and newlines matter. | standard output | |
PASSED | 9ba9627c8564b8bed4e333f3e83e351b | train_000.jsonl | 1332860400 | Let's dive into one of the most interesting areas of magic β writing spells. Learning this exciting but challenging science is very troublesome, so now you will not learn the magic words, but only get to know the basic rules of writing spells.Each spell consists of several lines. The line, whose first non-space character is character "#" is an amplifying line and it is responsible for spell power. The remaining lines are common, and determine the effect of the spell.You came across the text of some spell. Spell was too long, so you cannot understand its meaning. So you want to make it as short as possible without changing the meaning.The only way to shorten a spell that you know is the removal of some spaces and line breaks. We know that when it comes to texts of spells, the spaces carry meaning only in the amplifying lines, so we should remove all spaces in other lines. Newlines also do not matter, unless any of the two separated lines is amplifying. Thus, if two consecutive lines are not amplifying, they need to be joined into one (i.e. we should concatenate the second line to the first one). Removing spaces in amplifying lines and concatenating the amplifying lines to anything is forbidden.Note that empty lines must be processed just like all the others: they must be joined to the adjacent non-amplifying lines, or preserved in the output, if they are surrounded with amplifying lines on both sides (i.e. the line above it, if there is one, is amplifying, and the line below it, if there is one, is amplifying too).For now those are the only instructions for removing unnecessary characters that you have to follow (oh yes, a newline is a character, too).The input contains the text of the spell, which should be reduced. Remove the extra characters and print the result to the output. | 256 megabytes | import java.util.Scanner;
public class B {
public static void main(String[] args) {
B problem = new B();
problem.solve();
}
private void solve() {
Scanner sc = new Scanner(System.in);
StringBuilder o = new StringBuilder();
String i;
boolean u = false;
while(sc.hasNextLine()){
i = sc.nextLine();
boolean b;
if(b=startsjdv(i)){
if(u) o.append("\n");
o.append(i);
u=false;
}else{
o.append(i.replaceAll(" ",""));
u=true;
}
if(b && sc.hasNextLine()){
o.append("\n");
}
}
System.out.println(o);
}
public boolean startsjdv(String s){
int i = 0;
if(s.length() == 0) return false;
while(i< s.length() && s.charAt(i) == ' '){
i++;
}
if(i==s.length()) return false;
if(s.charAt(i) == '#') return true;
return false;
}
} | Java | ["# include <cstdio>\n\nusing namespace std;\n\nint main ( ){\nputs(\"Hello # World\"); #\n#\n}", "#\n\n#"] | 2 seconds | ["# include <cstdio>\nusingnamespacestd;intmain(){puts(\"Hello#World\");#\n#\n}", "#\n\n#"] | NoteIn the first sample the amplifying lines are lines 1 and 7. So, lines 2 to 6 are concatenated to each other, all spaces are deleted from them.In the second sample the amplifying lines are lines 1 and 3. So, no lines are concatenated to each other. | Java 6 | standard input | [
"implementation",
"strings"
] | a16bb696858bc592c33dcf0fd99df197 | The input contains multiple lines. All characters in the lines have codes from 32 to 127 (inclusive). Please note that the lines may begin with or end with one or more spaces. The size of the input does not exceed 1048576 (β=β220) bytes. Newlines are included in this size. In the Windows operating system used on the testing computer, a newline is a sequence of characters with codes #13#10. It is guaranteed that after each line of input there is a newline. In particular, the input ends with a newline. Note that the newline is the end of the line, and not the beginning of the next one. It is guaranteed that the input contains at least one character other than a newline. It is recommended to organize the input-output line by line, in this case the newlines will be processed correctly by the language means. | 1,700 | Print the text of the spell where all extra characters are deleted. Please note that each output line should be followed by a newline. Please be careful: your answers will be validated by comparing them to the jury's answer byte-by-byte. So, all spaces and newlines matter. | standard output | |
PASSED | 34f1df35342031205a55cfaaef02e68f | train_000.jsonl | 1332860400 | Let's dive into one of the most interesting areas of magic β writing spells. Learning this exciting but challenging science is very troublesome, so now you will not learn the magic words, but only get to know the basic rules of writing spells.Each spell consists of several lines. The line, whose first non-space character is character "#" is an amplifying line and it is responsible for spell power. The remaining lines are common, and determine the effect of the spell.You came across the text of some spell. Spell was too long, so you cannot understand its meaning. So you want to make it as short as possible without changing the meaning.The only way to shorten a spell that you know is the removal of some spaces and line breaks. We know that when it comes to texts of spells, the spaces carry meaning only in the amplifying lines, so we should remove all spaces in other lines. Newlines also do not matter, unless any of the two separated lines is amplifying. Thus, if two consecutive lines are not amplifying, they need to be joined into one (i.e. we should concatenate the second line to the first one). Removing spaces in amplifying lines and concatenating the amplifying lines to anything is forbidden.Note that empty lines must be processed just like all the others: they must be joined to the adjacent non-amplifying lines, or preserved in the output, if they are surrounded with amplifying lines on both sides (i.e. the line above it, if there is one, is amplifying, and the line below it, if there is one, is amplifying too).For now those are the only instructions for removing unnecessary characters that you have to follow (oh yes, a newline is a character, too).The input contains the text of the spell, which should be reduced. Remove the extra characters and print the result to the output. | 256 megabytes | import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.*;
public class B
{
BufferedReader in;
PrintStream out;
StringTokenizer tok;
public B() throws NumberFormatException, IOException
{
in = new BufferedReader(new InputStreamReader(System.in));
//in = new BufferedReader(new FileReader("in.txt"));
out = System.out;
run();
}
void run() throws NumberFormatException, IOException
{
String s = in.readLine();
boolean last = true;
while(s != null)
{
int i = 0;
while(i < s.length() && s.charAt(i)==' ')i++;
char a = (i==s.length())?' ':s.charAt(i);
if(a=='#')
{
if(!last)
out.println();
last = true;
out.println(s);
}
else
{
last = false;
print(s);
}
s = in.readLine();
}
if(!last) out.println();
}
boolean print(String s)
{
boolean empty = true;
for(char i: s.toCharArray())
if(i!= ' ')
{
empty = false;
out.print(i);
}
return empty;
}
public static void main(String[] args) throws NumberFormatException, IOException
{
new B();
}
String nextToken() throws IOException
{
if(tok ==null || !tok.hasMoreTokens()) tok = new StringTokenizer(in.readLine());
return tok.nextToken();
}
int nextInt() throws NumberFormatException, IOException
{
return Integer.parseInt(nextToken());
}
long nextLong() throws NumberFormatException, IOException
{
return Long.parseLong(nextToken());
}
double nextDouble() throws NumberFormatException, IOException
{
return Double.parseDouble(nextToken());
}
}
| Java | ["# include <cstdio>\n\nusing namespace std;\n\nint main ( ){\nputs(\"Hello # World\"); #\n#\n}", "#\n\n#"] | 2 seconds | ["# include <cstdio>\nusingnamespacestd;intmain(){puts(\"Hello#World\");#\n#\n}", "#\n\n#"] | NoteIn the first sample the amplifying lines are lines 1 and 7. So, lines 2 to 6 are concatenated to each other, all spaces are deleted from them.In the second sample the amplifying lines are lines 1 and 3. So, no lines are concatenated to each other. | Java 6 | standard input | [
"implementation",
"strings"
] | a16bb696858bc592c33dcf0fd99df197 | The input contains multiple lines. All characters in the lines have codes from 32 to 127 (inclusive). Please note that the lines may begin with or end with one or more spaces. The size of the input does not exceed 1048576 (β=β220) bytes. Newlines are included in this size. In the Windows operating system used on the testing computer, a newline is a sequence of characters with codes #13#10. It is guaranteed that after each line of input there is a newline. In particular, the input ends with a newline. Note that the newline is the end of the line, and not the beginning of the next one. It is guaranteed that the input contains at least one character other than a newline. It is recommended to organize the input-output line by line, in this case the newlines will be processed correctly by the language means. | 1,700 | Print the text of the spell where all extra characters are deleted. Please note that each output line should be followed by a newline. Please be careful: your answers will be validated by comparing them to the jury's answer byte-by-byte. So, all spaces and newlines matter. | standard output | |
PASSED | 534269cac752ed38c9560844969fd18d | train_000.jsonl | 1332860400 | Let's dive into one of the most interesting areas of magic β writing spells. Learning this exciting but challenging science is very troublesome, so now you will not learn the magic words, but only get to know the basic rules of writing spells.Each spell consists of several lines. The line, whose first non-space character is character "#" is an amplifying line and it is responsible for spell power. The remaining lines are common, and determine the effect of the spell.You came across the text of some spell. Spell was too long, so you cannot understand its meaning. So you want to make it as short as possible without changing the meaning.The only way to shorten a spell that you know is the removal of some spaces and line breaks. We know that when it comes to texts of spells, the spaces carry meaning only in the amplifying lines, so we should remove all spaces in other lines. Newlines also do not matter, unless any of the two separated lines is amplifying. Thus, if two consecutive lines are not amplifying, they need to be joined into one (i.e. we should concatenate the second line to the first one). Removing spaces in amplifying lines and concatenating the amplifying lines to anything is forbidden.Note that empty lines must be processed just like all the others: they must be joined to the adjacent non-amplifying lines, or preserved in the output, if they are surrounded with amplifying lines on both sides (i.e. the line above it, if there is one, is amplifying, and the line below it, if there is one, is amplifying too).For now those are the only instructions for removing unnecessary characters that you have to follow (oh yes, a newline is a character, too).The input contains the text of the spell, which should be reduced. Remove the extra characters and print the result to the output. | 256 megabytes | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
public class B {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
ArrayList<String> list = new ArrayList<String>();
while (true) {
String ss = br.readLine();
if (ss==null)
break;
if (ss.length() != 0) {
int ind = 0;
while (ind < ss.length()-1 && ss.charAt(ind)==' ')
ind++;
if (ss.charAt(ind)=='#') {
if (!list.isEmpty()) {
for (String s : list) {
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i)!=' ' && s.codePointAt(i)!=10 && s.codePointAt(i)!=13)
pw.print(s.charAt(i));
}
}
pw.println();
list.clear();
}
pw.println(ss);
}
else {
list.add(ss);
}
}
else
list.add(ss);
}
if (!list.isEmpty()) {
for (String s : list) {
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i)!=' ' && s.codePointAt(i)!=10 && s.codePointAt(i)!=13)
pw.print(s.charAt(i));
}
}
pw.println();
list.clear();
}
pw.close();
}
}
| Java | ["# include <cstdio>\n\nusing namespace std;\n\nint main ( ){\nputs(\"Hello # World\"); #\n#\n}", "#\n\n#"] | 2 seconds | ["# include <cstdio>\nusingnamespacestd;intmain(){puts(\"Hello#World\");#\n#\n}", "#\n\n#"] | NoteIn the first sample the amplifying lines are lines 1 and 7. So, lines 2 to 6 are concatenated to each other, all spaces are deleted from them.In the second sample the amplifying lines are lines 1 and 3. So, no lines are concatenated to each other. | Java 6 | standard input | [
"implementation",
"strings"
] | a16bb696858bc592c33dcf0fd99df197 | The input contains multiple lines. All characters in the lines have codes from 32 to 127 (inclusive). Please note that the lines may begin with or end with one or more spaces. The size of the input does not exceed 1048576 (β=β220) bytes. Newlines are included in this size. In the Windows operating system used on the testing computer, a newline is a sequence of characters with codes #13#10. It is guaranteed that after each line of input there is a newline. In particular, the input ends with a newline. Note that the newline is the end of the line, and not the beginning of the next one. It is guaranteed that the input contains at least one character other than a newline. It is recommended to organize the input-output line by line, in this case the newlines will be processed correctly by the language means. | 1,700 | Print the text of the spell where all extra characters are deleted. Please note that each output line should be followed by a newline. Please be careful: your answers will be validated by comparing them to the jury's answer byte-by-byte. So, all spaces and newlines matter. | standard output | |
PASSED | 1d50207e6ebac806fbbd3bbfa01bd7ab | train_000.jsonl | 1332860400 | Let's dive into one of the most interesting areas of magic β writing spells. Learning this exciting but challenging science is very troublesome, so now you will not learn the magic words, but only get to know the basic rules of writing spells.Each spell consists of several lines. The line, whose first non-space character is character "#" is an amplifying line and it is responsible for spell power. The remaining lines are common, and determine the effect of the spell.You came across the text of some spell. Spell was too long, so you cannot understand its meaning. So you want to make it as short as possible without changing the meaning.The only way to shorten a spell that you know is the removal of some spaces and line breaks. We know that when it comes to texts of spells, the spaces carry meaning only in the amplifying lines, so we should remove all spaces in other lines. Newlines also do not matter, unless any of the two separated lines is amplifying. Thus, if two consecutive lines are not amplifying, they need to be joined into one (i.e. we should concatenate the second line to the first one). Removing spaces in amplifying lines and concatenating the amplifying lines to anything is forbidden.Note that empty lines must be processed just like all the others: they must be joined to the adjacent non-amplifying lines, or preserved in the output, if they are surrounded with amplifying lines on both sides (i.e. the line above it, if there is one, is amplifying, and the line below it, if there is one, is amplifying too).For now those are the only instructions for removing unnecessary characters that you have to follow (oh yes, a newline is a character, too).The input contains the text of the spell, which should be reduced. Remove the extra characters and print the result to the output. | 256 megabytes | import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;
import java.util.StringTokenizer;
public class Main {
static BufferedReader input;
static StringTokenizer _stk;
static String readln() throws IOException {
String l = input.readLine();
if (l != null)
_stk = new StringTokenizer(l, " ");
return l;
}
static String next() {
return _stk.nextToken();
}
static int nextInt() {
return Integer.parseInt(next());
}
static void dbg(Object... o) {
System.out.println(Arrays.deepToString(o));
}
public static void main(String[] args) throws IOException {
Locale.setDefault(Locale.US);
input=new BufferedReader(new InputStreamReader(System.in));
//input = new BufferedReader(new FileReader("WizardsandMinimalSpell"));
String linea;
boolean antNoEchizo=false;
while (true) {
linea=readln();
if(linea==null)
break;
boolean cont=linea.matches("\\s*#.*");
if (cont) {
if (antNoEchizo) {
System.out.println();
}
System.out.println(linea);
antNoEchizo=false;
}else {
System.out.print(linea.replaceAll("\\s", ""));
antNoEchizo=true;
}
}
if (antNoEchizo) {
System.out.println();
}
}
}
| Java | ["# include <cstdio>\n\nusing namespace std;\n\nint main ( ){\nputs(\"Hello # World\"); #\n#\n}", "#\n\n#"] | 2 seconds | ["# include <cstdio>\nusingnamespacestd;intmain(){puts(\"Hello#World\");#\n#\n}", "#\n\n#"] | NoteIn the first sample the amplifying lines are lines 1 and 7. So, lines 2 to 6 are concatenated to each other, all spaces are deleted from them.In the second sample the amplifying lines are lines 1 and 3. So, no lines are concatenated to each other. | Java 6 | standard input | [
"implementation",
"strings"
] | a16bb696858bc592c33dcf0fd99df197 | The input contains multiple lines. All characters in the lines have codes from 32 to 127 (inclusive). Please note that the lines may begin with or end with one or more spaces. The size of the input does not exceed 1048576 (β=β220) bytes. Newlines are included in this size. In the Windows operating system used on the testing computer, a newline is a sequence of characters with codes #13#10. It is guaranteed that after each line of input there is a newline. In particular, the input ends with a newline. Note that the newline is the end of the line, and not the beginning of the next one. It is guaranteed that the input contains at least one character other than a newline. It is recommended to organize the input-output line by line, in this case the newlines will be processed correctly by the language means. | 1,700 | Print the text of the spell where all extra characters are deleted. Please note that each output line should be followed by a newline. Please be careful: your answers will be validated by comparing them to the jury's answer byte-by-byte. So, all spaces and newlines matter. | standard output | |
PASSED | 97121b45add579d70665925aa36b5173 | train_000.jsonl | 1332860400 | Let's dive into one of the most interesting areas of magic β writing spells. Learning this exciting but challenging science is very troublesome, so now you will not learn the magic words, but only get to know the basic rules of writing spells.Each spell consists of several lines. The line, whose first non-space character is character "#" is an amplifying line and it is responsible for spell power. The remaining lines are common, and determine the effect of the spell.You came across the text of some spell. Spell was too long, so you cannot understand its meaning. So you want to make it as short as possible without changing the meaning.The only way to shorten a spell that you know is the removal of some spaces and line breaks. We know that when it comes to texts of spells, the spaces carry meaning only in the amplifying lines, so we should remove all spaces in other lines. Newlines also do not matter, unless any of the two separated lines is amplifying. Thus, if two consecutive lines are not amplifying, they need to be joined into one (i.e. we should concatenate the second line to the first one). Removing spaces in amplifying lines and concatenating the amplifying lines to anything is forbidden.Note that empty lines must be processed just like all the others: they must be joined to the adjacent non-amplifying lines, or preserved in the output, if they are surrounded with amplifying lines on both sides (i.e. the line above it, if there is one, is amplifying, and the line below it, if there is one, is amplifying too).For now those are the only instructions for removing unnecessary characters that you have to follow (oh yes, a newline is a character, too).The input contains the text of the spell, which should be reduced. Remove the extra characters and print the result to the output. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
public class Main
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer tokenizer=null;
public static void main(String[] args) throws IOException
{
new Main().execute();
}
void debug(Object...os)
{
System.out.println(Arrays.deepToString(os));
}
int ni() throws IOException
{
return Integer.parseInt(ns());
}
long nl() throws IOException
{
return Long.parseLong(ns());
}
double nd() throws IOException
{
return Double.parseDouble(ns());
}
String ns() throws IOException
{
while (tokenizer == null || !tokenizer.hasMoreTokens())
tokenizer = new StringTokenizer(br.readLine());
return tokenizer.nextToken();
}
String nline() throws IOException
{
tokenizer=null;
return br.readLine();
}
//Main Code starts Here
int totalCases, testNum;
int m,n;
void execute() throws IOException
{
totalCases = 1;
for(testNum = 1; testNum <= totalCases; testNum++)
{
input();
solve();
}
}
boolean[] b;
boolean[] amp;
void solve()
{
b = new boolean[ind];
for(int k = 0;k<b.length;k++)
b[k]=true;
amp = new boolean[ind];
for(int i = 0;i<ind;i++)
{
if(line[i].trim().length()>0 && line[i].trim().charAt(0)=='#')
{
amp[i] = true;
continue;
}
else
{
StringBuilder temp = new StringBuilder();
for(int j = 0 ;j<line[i].length();j++)
{
if(line[i].charAt(j)!=' ')
temp.append(line[i].charAt(j));
}
line[i]=temp.toString();
}
}
int i =0;
while(i<ind-1)
{
if(amp[i])
{
i++;
continue;
}
else
{
int j = i+1;
StringBuilder ee = new StringBuilder(line[i]);
while(j<amp.length && !amp[j])
{
ee.append(line[j]);
line[j]="";
b[j]=false;
j++;
}
line[i] = ee.toString();
i=j;
}
}
for(i = 0 ;i<ind;i++)
{
if(b[i])
System.out.println(line[i]);
}
//debug(11);
}
String[] line;
void printarr(int [] a,int b)
{
for(int i = 0;i<=b;i++)
{
if(i==0)
System.out.print(a[i]);
else
System.out.print(" "+a[i]);
}
System.out.println();
}
int ind;
boolean input() throws IOException
{
//n = ni();
//m = ni();
ind= 0;
line = new String[1000000];
String s = nline();
while(s!=null)
{
line[ind++]=s;
s = nline();
}
//debug(line);
return true;
}
} | Java | ["# include <cstdio>\n\nusing namespace std;\n\nint main ( ){\nputs(\"Hello # World\"); #\n#\n}", "#\n\n#"] | 2 seconds | ["# include <cstdio>\nusingnamespacestd;intmain(){puts(\"Hello#World\");#\n#\n}", "#\n\n#"] | NoteIn the first sample the amplifying lines are lines 1 and 7. So, lines 2 to 6 are concatenated to each other, all spaces are deleted from them.In the second sample the amplifying lines are lines 1 and 3. So, no lines are concatenated to each other. | Java 6 | standard input | [
"implementation",
"strings"
] | a16bb696858bc592c33dcf0fd99df197 | The input contains multiple lines. All characters in the lines have codes from 32 to 127 (inclusive). Please note that the lines may begin with or end with one or more spaces. The size of the input does not exceed 1048576 (β=β220) bytes. Newlines are included in this size. In the Windows operating system used on the testing computer, a newline is a sequence of characters with codes #13#10. It is guaranteed that after each line of input there is a newline. In particular, the input ends with a newline. Note that the newline is the end of the line, and not the beginning of the next one. It is guaranteed that the input contains at least one character other than a newline. It is recommended to organize the input-output line by line, in this case the newlines will be processed correctly by the language means. | 1,700 | Print the text of the spell where all extra characters are deleted. Please note that each output line should be followed by a newline. Please be careful: your answers will be validated by comparing them to the jury's answer byte-by-byte. So, all spaces and newlines matter. | standard output | |
PASSED | 89db0dea17aea2f16f53e1200292444d | train_000.jsonl | 1332860400 | Let's dive into one of the most interesting areas of magic β writing spells. Learning this exciting but challenging science is very troublesome, so now you will not learn the magic words, but only get to know the basic rules of writing spells.Each spell consists of several lines. The line, whose first non-space character is character "#" is an amplifying line and it is responsible for spell power. The remaining lines are common, and determine the effect of the spell.You came across the text of some spell. Spell was too long, so you cannot understand its meaning. So you want to make it as short as possible without changing the meaning.The only way to shorten a spell that you know is the removal of some spaces and line breaks. We know that when it comes to texts of spells, the spaces carry meaning only in the amplifying lines, so we should remove all spaces in other lines. Newlines also do not matter, unless any of the two separated lines is amplifying. Thus, if two consecutive lines are not amplifying, they need to be joined into one (i.e. we should concatenate the second line to the first one). Removing spaces in amplifying lines and concatenating the amplifying lines to anything is forbidden.Note that empty lines must be processed just like all the others: they must be joined to the adjacent non-amplifying lines, or preserved in the output, if they are surrounded with amplifying lines on both sides (i.e. the line above it, if there is one, is amplifying, and the line below it, if there is one, is amplifying too).For now those are the only instructions for removing unnecessary characters that you have to follow (oh yes, a newline is a character, too).The input contains the text of the spell, which should be reduced. Remove the extra characters and print the result to the output. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
/**
*
* @author Tarek Gamal
*/
public class A {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
// TODO code application logic here
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Scanner sc= new Scanner(System.in);
// StringTokenizer st;
int n=0 ;
String s="";
boolean flag=true;
do{
s=br.readLine();
if(s.isEmpty())
flag=false;
else if(s.trim().startsWith("#")){
if(!flag)
System.out.println();
System.out.println(s);
flag=true;
}
else{
System.out.print(s.replaceAll(" ", ""));
flag=false;
}
}while(br.ready());
if(!flag)
System.out.println();
}//End of main method
}//End of Main class
| Java | ["# include <cstdio>\n\nusing namespace std;\n\nint main ( ){\nputs(\"Hello # World\"); #\n#\n}", "#\n\n#"] | 2 seconds | ["# include <cstdio>\nusingnamespacestd;intmain(){puts(\"Hello#World\");#\n#\n}", "#\n\n#"] | NoteIn the first sample the amplifying lines are lines 1 and 7. So, lines 2 to 6 are concatenated to each other, all spaces are deleted from them.In the second sample the amplifying lines are lines 1 and 3. So, no lines are concatenated to each other. | Java 6 | standard input | [
"implementation",
"strings"
] | a16bb696858bc592c33dcf0fd99df197 | The input contains multiple lines. All characters in the lines have codes from 32 to 127 (inclusive). Please note that the lines may begin with or end with one or more spaces. The size of the input does not exceed 1048576 (β=β220) bytes. Newlines are included in this size. In the Windows operating system used on the testing computer, a newline is a sequence of characters with codes #13#10. It is guaranteed that after each line of input there is a newline. In particular, the input ends with a newline. Note that the newline is the end of the line, and not the beginning of the next one. It is guaranteed that the input contains at least one character other than a newline. It is recommended to organize the input-output line by line, in this case the newlines will be processed correctly by the language means. | 1,700 | Print the text of the spell where all extra characters are deleted. Please note that each output line should be followed by a newline. Please be careful: your answers will be validated by comparing them to the jury's answer byte-by-byte. So, all spaces and newlines matter. | standard output | |
PASSED | 07eafed7e778efaa5313bbc84966e103 | train_000.jsonl | 1332860400 | Let's dive into one of the most interesting areas of magic β writing spells. Learning this exciting but challenging science is very troublesome, so now you will not learn the magic words, but only get to know the basic rules of writing spells.Each spell consists of several lines. The line, whose first non-space character is character "#" is an amplifying line and it is responsible for spell power. The remaining lines are common, and determine the effect of the spell.You came across the text of some spell. Spell was too long, so you cannot understand its meaning. So you want to make it as short as possible without changing the meaning.The only way to shorten a spell that you know is the removal of some spaces and line breaks. We know that when it comes to texts of spells, the spaces carry meaning only in the amplifying lines, so we should remove all spaces in other lines. Newlines also do not matter, unless any of the two separated lines is amplifying. Thus, if two consecutive lines are not amplifying, they need to be joined into one (i.e. we should concatenate the second line to the first one). Removing spaces in amplifying lines and concatenating the amplifying lines to anything is forbidden.Note that empty lines must be processed just like all the others: they must be joined to the adjacent non-amplifying lines, or preserved in the output, if they are surrounded with amplifying lines on both sides (i.e. the line above it, if there is one, is amplifying, and the line below it, if there is one, is amplifying too).For now those are the only instructions for removing unnecessary characters that you have to follow (oh yes, a newline is a character, too).The input contains the text of the spell, which should be reduced. Remove the extra characters and print the result to the output. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.InputMismatchException;
public class SolA {
private static BufferedReader in;
private static PrintWriter out;
public static void main(String[] args) throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
run();
out.close();
in.close();
}
public static void run() throws IOException {
String s = in.readLine();
boolean needBr = false;
while (s != null) {
String t = s.trim();
if (t.length() > 0 && t.charAt(0) == '#') {
if (needBr) {
out.println();
}
out.print(s);
out.println();
needBr = false;
} else {
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) != ' ' && s.charAt(i) != '\n') {
out.print(s.charAt(i));
}
}
needBr = true;
}
s = in.readLine();
}
if (needBr) {
out.println();
}
}
}
class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuffer res = new StringBuffer();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public static boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return readString();
}
}
| Java | ["# include <cstdio>\n\nusing namespace std;\n\nint main ( ){\nputs(\"Hello # World\"); #\n#\n}", "#\n\n#"] | 2 seconds | ["# include <cstdio>\nusingnamespacestd;intmain(){puts(\"Hello#World\");#\n#\n}", "#\n\n#"] | NoteIn the first sample the amplifying lines are lines 1 and 7. So, lines 2 to 6 are concatenated to each other, all spaces are deleted from them.In the second sample the amplifying lines are lines 1 and 3. So, no lines are concatenated to each other. | Java 6 | standard input | [
"implementation",
"strings"
] | a16bb696858bc592c33dcf0fd99df197 | The input contains multiple lines. All characters in the lines have codes from 32 to 127 (inclusive). Please note that the lines may begin with or end with one or more spaces. The size of the input does not exceed 1048576 (β=β220) bytes. Newlines are included in this size. In the Windows operating system used on the testing computer, a newline is a sequence of characters with codes #13#10. It is guaranteed that after each line of input there is a newline. In particular, the input ends with a newline. Note that the newline is the end of the line, and not the beginning of the next one. It is guaranteed that the input contains at least one character other than a newline. It is recommended to organize the input-output line by line, in this case the newlines will be processed correctly by the language means. | 1,700 | Print the text of the spell where all extra characters are deleted. Please note that each output line should be followed by a newline. Please be careful: your answers will be validated by comparing them to the jury's answer byte-by-byte. So, all spaces and newlines matter. | standard output | |
PASSED | 380cff3ed250f9035762da78a21c10a2 | train_000.jsonl | 1332860400 | Let's dive into one of the most interesting areas of magic β writing spells. Learning this exciting but challenging science is very troublesome, so now you will not learn the magic words, but only get to know the basic rules of writing spells.Each spell consists of several lines. The line, whose first non-space character is character "#" is an amplifying line and it is responsible for spell power. The remaining lines are common, and determine the effect of the spell.You came across the text of some spell. Spell was too long, so you cannot understand its meaning. So you want to make it as short as possible without changing the meaning.The only way to shorten a spell that you know is the removal of some spaces and line breaks. We know that when it comes to texts of spells, the spaces carry meaning only in the amplifying lines, so we should remove all spaces in other lines. Newlines also do not matter, unless any of the two separated lines is amplifying. Thus, if two consecutive lines are not amplifying, they need to be joined into one (i.e. we should concatenate the second line to the first one). Removing spaces in amplifying lines and concatenating the amplifying lines to anything is forbidden.Note that empty lines must be processed just like all the others: they must be joined to the adjacent non-amplifying lines, or preserved in the output, if they are surrounded with amplifying lines on both sides (i.e. the line above it, if there is one, is amplifying, and the line below it, if there is one, is amplifying too).For now those are the only instructions for removing unnecessary characters that you have to follow (oh yes, a newline is a character, too).The input contains the text of the spell, which should be reduced. Remove the extra characters and print the result to the output. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class B114
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
boolean prevamp=true;
while(true)
{
String s=br.readLine();
if(s==null)
break;
boolean amp=false;
for(int i=0;i<s.length();i++)
{if(s.charAt(i)!=' '&&s.charAt(i)=='#')
{
amp=true;
break;
}
else if(s.charAt(i)!=' ')break;
}
if(amp)
{
if(prevamp)
{System.out.println(s);
}
else
{
System.out.println("");
System.out.println(s);
}
prevamp=true;
}
else
{
prevamp=false;
for(int i=0;i<s.length();i++)
{
if(s.charAt(i)!=' '&&s.charAt(i)!='\n')
System.out.print(s.charAt(i)+"");
}
}
}
if(!prevamp)
System.out.println("");
}
} | Java | ["# include <cstdio>\n\nusing namespace std;\n\nint main ( ){\nputs(\"Hello # World\"); #\n#\n}", "#\n\n#"] | 2 seconds | ["# include <cstdio>\nusingnamespacestd;intmain(){puts(\"Hello#World\");#\n#\n}", "#\n\n#"] | NoteIn the first sample the amplifying lines are lines 1 and 7. So, lines 2 to 6 are concatenated to each other, all spaces are deleted from them.In the second sample the amplifying lines are lines 1 and 3. So, no lines are concatenated to each other. | Java 6 | standard input | [
"implementation",
"strings"
] | a16bb696858bc592c33dcf0fd99df197 | The input contains multiple lines. All characters in the lines have codes from 32 to 127 (inclusive). Please note that the lines may begin with or end with one or more spaces. The size of the input does not exceed 1048576 (β=β220) bytes. Newlines are included in this size. In the Windows operating system used on the testing computer, a newline is a sequence of characters with codes #13#10. It is guaranteed that after each line of input there is a newline. In particular, the input ends with a newline. Note that the newline is the end of the line, and not the beginning of the next one. It is guaranteed that the input contains at least one character other than a newline. It is recommended to organize the input-output line by line, in this case the newlines will be processed correctly by the language means. | 1,700 | Print the text of the spell where all extra characters are deleted. Please note that each output line should be followed by a newline. Please be careful: your answers will be validated by comparing them to the jury's answer byte-by-byte. So, all spaces and newlines matter. | standard output | |
PASSED | e3f9782757e487a656b28fff0dfa7f22 | train_000.jsonl | 1332860400 | Let's dive into one of the most interesting areas of magic β writing spells. Learning this exciting but challenging science is very troublesome, so now you will not learn the magic words, but only get to know the basic rules of writing spells.Each spell consists of several lines. The line, whose first non-space character is character "#" is an amplifying line and it is responsible for spell power. The remaining lines are common, and determine the effect of the spell.You came across the text of some spell. Spell was too long, so you cannot understand its meaning. So you want to make it as short as possible without changing the meaning.The only way to shorten a spell that you know is the removal of some spaces and line breaks. We know that when it comes to texts of spells, the spaces carry meaning only in the amplifying lines, so we should remove all spaces in other lines. Newlines also do not matter, unless any of the two separated lines is amplifying. Thus, if two consecutive lines are not amplifying, they need to be joined into one (i.e. we should concatenate the second line to the first one). Removing spaces in amplifying lines and concatenating the amplifying lines to anything is forbidden.Note that empty lines must be processed just like all the others: they must be joined to the adjacent non-amplifying lines, or preserved in the output, if they are surrounded with amplifying lines on both sides (i.e. the line above it, if there is one, is amplifying, and the line below it, if there is one, is amplifying too).For now those are the only instructions for removing unnecessary characters that you have to follow (oh yes, a newline is a character, too).The input contains the text of the spell, which should be reduced. Remove the extra characters and print the result to the output. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.regex.Pattern;
public class CF168B {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Pattern isAmpPtn = Pattern.compile("^\\s*#");
Pattern spacePtn = Pattern.compile(" ");
StringBuilder buf = new StringBuilder();
boolean needsOutput = false;
String str;
while ((str = br.readLine()) != null) {
if (isAmpPtn.matcher(str).find()) {
if (needsOutput) {
System.out.println(buf);
buf.setLength(0);
needsOutput = false;
}
System.out.println(str);
}
else {
needsOutput = true;
buf.append(spacePtn.matcher(str).replaceAll(""));
}
}
if (needsOutput) {
System.out.println(buf);
buf.setLength(0);
}
}
}
| Java | ["# include <cstdio>\n\nusing namespace std;\n\nint main ( ){\nputs(\"Hello # World\"); #\n#\n}", "#\n\n#"] | 2 seconds | ["# include <cstdio>\nusingnamespacestd;intmain(){puts(\"Hello#World\");#\n#\n}", "#\n\n#"] | NoteIn the first sample the amplifying lines are lines 1 and 7. So, lines 2 to 6 are concatenated to each other, all spaces are deleted from them.In the second sample the amplifying lines are lines 1 and 3. So, no lines are concatenated to each other. | Java 6 | standard input | [
"implementation",
"strings"
] | a16bb696858bc592c33dcf0fd99df197 | The input contains multiple lines. All characters in the lines have codes from 32 to 127 (inclusive). Please note that the lines may begin with or end with one or more spaces. The size of the input does not exceed 1048576 (β=β220) bytes. Newlines are included in this size. In the Windows operating system used on the testing computer, a newline is a sequence of characters with codes #13#10. It is guaranteed that after each line of input there is a newline. In particular, the input ends with a newline. Note that the newline is the end of the line, and not the beginning of the next one. It is guaranteed that the input contains at least one character other than a newline. It is recommended to organize the input-output line by line, in this case the newlines will be processed correctly by the language means. | 1,700 | Print the text of the spell where all extra characters are deleted. Please note that each output line should be followed by a newline. Please be careful: your answers will be validated by comparing them to the jury's answer byte-by-byte. So, all spaces and newlines matter. | standard output | |
PASSED | a768e4636940f8bb60aff0c377c9372e | train_000.jsonl | 1332860400 | Let's dive into one of the most interesting areas of magic β writing spells. Learning this exciting but challenging science is very troublesome, so now you will not learn the magic words, but only get to know the basic rules of writing spells.Each spell consists of several lines. The line, whose first non-space character is character "#" is an amplifying line and it is responsible for spell power. The remaining lines are common, and determine the effect of the spell.You came across the text of some spell. Spell was too long, so you cannot understand its meaning. So you want to make it as short as possible without changing the meaning.The only way to shorten a spell that you know is the removal of some spaces and line breaks. We know that when it comes to texts of spells, the spaces carry meaning only in the amplifying lines, so we should remove all spaces in other lines. Newlines also do not matter, unless any of the two separated lines is amplifying. Thus, if two consecutive lines are not amplifying, they need to be joined into one (i.e. we should concatenate the second line to the first one). Removing spaces in amplifying lines and concatenating the amplifying lines to anything is forbidden.Note that empty lines must be processed just like all the others: they must be joined to the adjacent non-amplifying lines, or preserved in the output, if they are surrounded with amplifying lines on both sides (i.e. the line above it, if there is one, is amplifying, and the line below it, if there is one, is amplifying too).For now those are the only instructions for removing unnecessary characters that you have to follow (oh yes, a newline is a character, too).The input contains the text of the spell, which should be reduced. Remove the extra characters and print the result to the output. | 256 megabytes | import java.util.Scanner;
import java.util.regex.Pattern;
public class CF168B {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Pattern isAmpPtn = Pattern.compile("^\\s*#");
Pattern spacePtn = Pattern.compile(" ");
StringBuilder buf = new StringBuilder();
boolean needsOutput = false;
while (sc.hasNextLine()) {
String str = sc.nextLine();
if (isAmpPtn.matcher(str).find()) {
if (needsOutput) {
System.out.println(buf);
buf.setLength(0);
needsOutput = false;
}
System.out.println(str);
}
else {
needsOutput = true;
buf.append(spacePtn.matcher(str).replaceAll(""));
}
}
if (needsOutput) {
System.out.println(buf);
buf.setLength(0);
}
}
}
| Java | ["# include <cstdio>\n\nusing namespace std;\n\nint main ( ){\nputs(\"Hello # World\"); #\n#\n}", "#\n\n#"] | 2 seconds | ["# include <cstdio>\nusingnamespacestd;intmain(){puts(\"Hello#World\");#\n#\n}", "#\n\n#"] | NoteIn the first sample the amplifying lines are lines 1 and 7. So, lines 2 to 6 are concatenated to each other, all spaces are deleted from them.In the second sample the amplifying lines are lines 1 and 3. So, no lines are concatenated to each other. | Java 6 | standard input | [
"implementation",
"strings"
] | a16bb696858bc592c33dcf0fd99df197 | The input contains multiple lines. All characters in the lines have codes from 32 to 127 (inclusive). Please note that the lines may begin with or end with one or more spaces. The size of the input does not exceed 1048576 (β=β220) bytes. Newlines are included in this size. In the Windows operating system used on the testing computer, a newline is a sequence of characters with codes #13#10. It is guaranteed that after each line of input there is a newline. In particular, the input ends with a newline. Note that the newline is the end of the line, and not the beginning of the next one. It is guaranteed that the input contains at least one character other than a newline. It is recommended to organize the input-output line by line, in this case the newlines will be processed correctly by the language means. | 1,700 | Print the text of the spell where all extra characters are deleted. Please note that each output line should be followed by a newline. Please be careful: your answers will be validated by comparing them to the jury's answer byte-by-byte. So, all spaces and newlines matter. | standard output | |
PASSED | 8ff6f369431b6d22e446d4b291243741 | train_000.jsonl | 1332860400 | Let's dive into one of the most interesting areas of magic β writing spells. Learning this exciting but challenging science is very troublesome, so now you will not learn the magic words, but only get to know the basic rules of writing spells.Each spell consists of several lines. The line, whose first non-space character is character "#" is an amplifying line and it is responsible for spell power. The remaining lines are common, and determine the effect of the spell.You came across the text of some spell. Spell was too long, so you cannot understand its meaning. So you want to make it as short as possible without changing the meaning.The only way to shorten a spell that you know is the removal of some spaces and line breaks. We know that when it comes to texts of spells, the spaces carry meaning only in the amplifying lines, so we should remove all spaces in other lines. Newlines also do not matter, unless any of the two separated lines is amplifying. Thus, if two consecutive lines are not amplifying, they need to be joined into one (i.e. we should concatenate the second line to the first one). Removing spaces in amplifying lines and concatenating the amplifying lines to anything is forbidden.Note that empty lines must be processed just like all the others: they must be joined to the adjacent non-amplifying lines, or preserved in the output, if they are surrounded with amplifying lines on both sides (i.e. the line above it, if there is one, is amplifying, and the line below it, if there is one, is amplifying too).For now those are the only instructions for removing unnecessary characters that you have to follow (oh yes, a newline is a character, too).The input contains the text of the spell, which should be reduced. Remove the extra characters and print the result to the output. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.regex.Pattern;
public class CF168B {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Pattern isAmpPtn = Pattern.compile("^\\s*#");
Pattern spacePtn = Pattern.compile(" ");
StringBuilder buf = new StringBuilder();
boolean needsOutput = false;
String str;
while ((str = br.readLine()) != null) {
if (isAmpPtn.matcher(str).find()) {
if (needsOutput) {
System.out.println(buf);
buf.setLength(0);
needsOutput = false;
}
System.out.println(str);
}
else {
needsOutput = true;
buf.append(spacePtn.matcher(str).replaceAll(""));
}
}
if (needsOutput) {
System.out.println(buf);
buf.setLength(0);
}
}
}
| Java | ["# include <cstdio>\n\nusing namespace std;\n\nint main ( ){\nputs(\"Hello # World\"); #\n#\n}", "#\n\n#"] | 2 seconds | ["# include <cstdio>\nusingnamespacestd;intmain(){puts(\"Hello#World\");#\n#\n}", "#\n\n#"] | NoteIn the first sample the amplifying lines are lines 1 and 7. So, lines 2 to 6 are concatenated to each other, all spaces are deleted from them.In the second sample the amplifying lines are lines 1 and 3. So, no lines are concatenated to each other. | Java 6 | standard input | [
"implementation",
"strings"
] | a16bb696858bc592c33dcf0fd99df197 | The input contains multiple lines. All characters in the lines have codes from 32 to 127 (inclusive). Please note that the lines may begin with or end with one or more spaces. The size of the input does not exceed 1048576 (β=β220) bytes. Newlines are included in this size. In the Windows operating system used on the testing computer, a newline is a sequence of characters with codes #13#10. It is guaranteed that after each line of input there is a newline. In particular, the input ends with a newline. Note that the newline is the end of the line, and not the beginning of the next one. It is guaranteed that the input contains at least one character other than a newline. It is recommended to organize the input-output line by line, in this case the newlines will be processed correctly by the language means. | 1,700 | Print the text of the spell where all extra characters are deleted. Please note that each output line should be followed by a newline. Please be careful: your answers will be validated by comparing them to the jury's answer byte-by-byte. So, all spaces and newlines matter. | standard output | |
PASSED | fed3594b50e3d852cb4e544e58ba74fa | train_000.jsonl | 1332860400 | Let's dive into one of the most interesting areas of magic β writing spells. Learning this exciting but challenging science is very troublesome, so now you will not learn the magic words, but only get to know the basic rules of writing spells.Each spell consists of several lines. The line, whose first non-space character is character "#" is an amplifying line and it is responsible for spell power. The remaining lines are common, and determine the effect of the spell.You came across the text of some spell. Spell was too long, so you cannot understand its meaning. So you want to make it as short as possible without changing the meaning.The only way to shorten a spell that you know is the removal of some spaces and line breaks. We know that when it comes to texts of spells, the spaces carry meaning only in the amplifying lines, so we should remove all spaces in other lines. Newlines also do not matter, unless any of the two separated lines is amplifying. Thus, if two consecutive lines are not amplifying, they need to be joined into one (i.e. we should concatenate the second line to the first one). Removing spaces in amplifying lines and concatenating the amplifying lines to anything is forbidden.Note that empty lines must be processed just like all the others: they must be joined to the adjacent non-amplifying lines, or preserved in the output, if they are surrounded with amplifying lines on both sides (i.e. the line above it, if there is one, is amplifying, and the line below it, if there is one, is amplifying too).For now those are the only instructions for removing unnecessary characters that you have to follow (oh yes, a newline is a character, too).The input contains the text of the spell, which should be reduced. Remove the extra characters and print the result to the output. | 256 megabytes | import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Comparator;
import java.util.StringTokenizer;
public class WizardsandMinimalSpell {
static public void main(String args[]) throws IOException {
BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));
String line;
ArrayList<String> lines = new ArrayList<String>();
int nlines = 0;
ArrayList<Integer> ampLines = new ArrayList<Integer>();
while ((line = cin.readLine()) != null) {
lines.add(line);
String ts = line.trim();
if (ts.startsWith("#"))
ampLines.add(nlines);
nlines++;
}
int k = 0, j = 0;
while (k < nlines) {
if (j >= ampLines.size()) {
while (k < nlines) {
String ts = lines.get(k).replaceAll("\\s+", "");
System.out.print(ts);
k++;
}
System.out.println();
} else if (ampLines.get(j) == k) {
System.out.print(lines.get(k));
j++;
boolean qb = true;
while (++k < nlines && j < ampLines.size() && ampLines.get(j) != k) {
if (qb) {
qb = false;
System.out.println();
}
String ts = lines.get(k).replaceAll("\\s+", "");
System.out.print(ts);
}
System.out.println();
} else {
while (k < nlines && j < ampLines.size() && ampLines.get(j) != k) {
String ts = lines.get(k).replaceAll("\\s+", "");
System.out.print(ts);
k++;
}
System.out.println();
}
}
}
} | Java | ["# include <cstdio>\n\nusing namespace std;\n\nint main ( ){\nputs(\"Hello # World\"); #\n#\n}", "#\n\n#"] | 2 seconds | ["# include <cstdio>\nusingnamespacestd;intmain(){puts(\"Hello#World\");#\n#\n}", "#\n\n#"] | NoteIn the first sample the amplifying lines are lines 1 and 7. So, lines 2 to 6 are concatenated to each other, all spaces are deleted from them.In the second sample the amplifying lines are lines 1 and 3. So, no lines are concatenated to each other. | Java 6 | standard input | [
"implementation",
"strings"
] | a16bb696858bc592c33dcf0fd99df197 | The input contains multiple lines. All characters in the lines have codes from 32 to 127 (inclusive). Please note that the lines may begin with or end with one or more spaces. The size of the input does not exceed 1048576 (β=β220) bytes. Newlines are included in this size. In the Windows operating system used on the testing computer, a newline is a sequence of characters with codes #13#10. It is guaranteed that after each line of input there is a newline. In particular, the input ends with a newline. Note that the newline is the end of the line, and not the beginning of the next one. It is guaranteed that the input contains at least one character other than a newline. It is recommended to organize the input-output line by line, in this case the newlines will be processed correctly by the language means. | 1,700 | Print the text of the spell where all extra characters are deleted. Please note that each output line should be followed by a newline. Please be careful: your answers will be validated by comparing them to the jury's answer byte-by-byte. So, all spaces and newlines matter. | standard output | |
PASSED | 8584da38529dfc49b50566414fbdcd47 | train_000.jsonl | 1332860400 | Let's dive into one of the most interesting areas of magic β writing spells. Learning this exciting but challenging science is very troublesome, so now you will not learn the magic words, but only get to know the basic rules of writing spells.Each spell consists of several lines. The line, whose first non-space character is character "#" is an amplifying line and it is responsible for spell power. The remaining lines are common, and determine the effect of the spell.You came across the text of some spell. Spell was too long, so you cannot understand its meaning. So you want to make it as short as possible without changing the meaning.The only way to shorten a spell that you know is the removal of some spaces and line breaks. We know that when it comes to texts of spells, the spaces carry meaning only in the amplifying lines, so we should remove all spaces in other lines. Newlines also do not matter, unless any of the two separated lines is amplifying. Thus, if two consecutive lines are not amplifying, they need to be joined into one (i.e. we should concatenate the second line to the first one). Removing spaces in amplifying lines and concatenating the amplifying lines to anything is forbidden.Note that empty lines must be processed just like all the others: they must be joined to the adjacent non-amplifying lines, or preserved in the output, if they are surrounded with amplifying lines on both sides (i.e. the line above it, if there is one, is amplifying, and the line below it, if there is one, is amplifying too).For now those are the only instructions for removing unnecessary characters that you have to follow (oh yes, a newline is a character, too).The input contains the text of the spell, which should be reduced. Remove the extra characters and print the result to the output. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static class Parser {
private StringTokenizer tokenizer;
public Parser(String input) { tokenizer = new StringTokenizer(input);}
public boolean hasNext() { return tokenizer.hasMoreTokens(); }
public String nextString() { return tokenizer.nextToken(); }
public int nextInteger() { return Integer.parseInt(nextString()); }
public double nextDouble() { return Double.parseDouble(nextString()); }
}
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//Parser p = new Parser(in.readLine());
String out = "";
int i = 0;
do {
String s = in.readLine();
if (s.trim().startsWith("#")) {
if (i > 0) System.out.println();
System.out.println(s);
i = 0;
} else {
i++;
System.out.print(s.replaceAll(" ", "").replaceAll("\n", ""));
}
} while (in.ready());
if (i > 0) System.out.println();
//if (i > 0) System.out.println(out);
// Integer n = p.nextInteger();
// Integer a = p.nextInteger();
// Integer d = p.nextInteger();
//
// int t[] = new int[n];
// int v[] = new int[n];
//
// for (int i = 0; i < n; i++) {
// p = new Parser(in.readLine());
// t[i] = p.nextInteger();
// v[i] = p.nextInteger();
// }
//
// double r[] = new double[n];
//
// r[0] = getT(v[0], a, d) + t[0];
//
// for (int i = 1; i < n; i++) {
// r[i] = getT(v[i], a, d) + t[i];
// if (r[i] < r[i - 1]) r[i] = r[i-1];
// }
//
// for (int i = 0; i < n; i++) {
// System.out.println(r[i]);
// }
}
private static double getT(double vmax, double a, double d) {
double t1 = vmax / a;
double s = a * t1*t1/2;
if (s > d) {
return Math.sqrt(2 * d / a);
} else {
return t1 + (d - s)/vmax;
}
}
}
| Java | ["# include <cstdio>\n\nusing namespace std;\n\nint main ( ){\nputs(\"Hello # World\"); #\n#\n}", "#\n\n#"] | 2 seconds | ["# include <cstdio>\nusingnamespacestd;intmain(){puts(\"Hello#World\");#\n#\n}", "#\n\n#"] | NoteIn the first sample the amplifying lines are lines 1 and 7. So, lines 2 to 6 are concatenated to each other, all spaces are deleted from them.In the second sample the amplifying lines are lines 1 and 3. So, no lines are concatenated to each other. | Java 6 | standard input | [
"implementation",
"strings"
] | a16bb696858bc592c33dcf0fd99df197 | The input contains multiple lines. All characters in the lines have codes from 32 to 127 (inclusive). Please note that the lines may begin with or end with one or more spaces. The size of the input does not exceed 1048576 (β=β220) bytes. Newlines are included in this size. In the Windows operating system used on the testing computer, a newline is a sequence of characters with codes #13#10. It is guaranteed that after each line of input there is a newline. In particular, the input ends with a newline. Note that the newline is the end of the line, and not the beginning of the next one. It is guaranteed that the input contains at least one character other than a newline. It is recommended to organize the input-output line by line, in this case the newlines will be processed correctly by the language means. | 1,700 | Print the text of the spell where all extra characters are deleted. Please note that each output line should be followed by a newline. Please be careful: your answers will be validated by comparing them to the jury's answer byte-by-byte. So, all spaces and newlines matter. | standard output | |
PASSED | 83d56b1df341a2f0fc3741d4c5d953cf | train_000.jsonl | 1332860400 | Let's dive into one of the most interesting areas of magic β writing spells. Learning this exciting but challenging science is very troublesome, so now you will not learn the magic words, but only get to know the basic rules of writing spells.Each spell consists of several lines. The line, whose first non-space character is character "#" is an amplifying line and it is responsible for spell power. The remaining lines are common, and determine the effect of the spell.You came across the text of some spell. Spell was too long, so you cannot understand its meaning. So you want to make it as short as possible without changing the meaning.The only way to shorten a spell that you know is the removal of some spaces and line breaks. We know that when it comes to texts of spells, the spaces carry meaning only in the amplifying lines, so we should remove all spaces in other lines. Newlines also do not matter, unless any of the two separated lines is amplifying. Thus, if two consecutive lines are not amplifying, they need to be joined into one (i.e. we should concatenate the second line to the first one). Removing spaces in amplifying lines and concatenating the amplifying lines to anything is forbidden.Note that empty lines must be processed just like all the others: they must be joined to the adjacent non-amplifying lines, or preserved in the output, if they are surrounded with amplifying lines on both sides (i.e. the line above it, if there is one, is amplifying, and the line below it, if there is one, is amplifying too).For now those are the only instructions for removing unnecessary characters that you have to follow (oh yes, a newline is a character, too).The input contains the text of the spell, which should be reduced. Remove the extra characters and print the result to the output. | 256 megabytes | import java.io.*;
import java.util.*;
public class sp{
public static void main(String args[]) throws IOException{
BufferedReader lector = new BufferedReader(new InputStreamReader(System.in));
StringBuilder res = new StringBuilder("");
String tmp = "";
boolean t = true;
while((tmp = lector.readLine())!=null){
String r = tmp.replaceAll(" ","");
if(t && r.length()>0 && r.charAt(0)=='#'){
res=res.append(tmp+"\n");
}else if(!t && r.length()>0 && r.charAt(0)=='#'){
t = true;
res=res.append("\n"+tmp+"\n");
}
else if(r.length()==0 || (r.length()>0 &&r.charAt(0)!='#')){
t=false;
res=res.append(r);
}
}
if(t)
System.out.println(res.substring(0,res.length()-1));
else
System.out.println(res);
}
}
| Java | ["# include <cstdio>\n\nusing namespace std;\n\nint main ( ){\nputs(\"Hello # World\"); #\n#\n}", "#\n\n#"] | 2 seconds | ["# include <cstdio>\nusingnamespacestd;intmain(){puts(\"Hello#World\");#\n#\n}", "#\n\n#"] | NoteIn the first sample the amplifying lines are lines 1 and 7. So, lines 2 to 6 are concatenated to each other, all spaces are deleted from them.In the second sample the amplifying lines are lines 1 and 3. So, no lines are concatenated to each other. | Java 6 | standard input | [
"implementation",
"strings"
] | a16bb696858bc592c33dcf0fd99df197 | The input contains multiple lines. All characters in the lines have codes from 32 to 127 (inclusive). Please note that the lines may begin with or end with one or more spaces. The size of the input does not exceed 1048576 (β=β220) bytes. Newlines are included in this size. In the Windows operating system used on the testing computer, a newline is a sequence of characters with codes #13#10. It is guaranteed that after each line of input there is a newline. In particular, the input ends with a newline. Note that the newline is the end of the line, and not the beginning of the next one. It is guaranteed that the input contains at least one character other than a newline. It is recommended to organize the input-output line by line, in this case the newlines will be processed correctly by the language means. | 1,700 | Print the text of the spell where all extra characters are deleted. Please note that each output line should be followed by a newline. Please be careful: your answers will be validated by comparing them to the jury's answer byte-by-byte. So, all spaces and newlines matter. | standard output | |
PASSED | 9d739079ffdd5a56e91bcaca6e940362 | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes |
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
public class P349C {
static boolean multipleIndependent = false;
void run() {
int n = in.nextInt();
int[] A = in.nextIntArray(n);
Arrays.sort(A);
long sum = 0;
for (int a : A) {
sum += a;
}
out.println(A[n - 1] + (Math.max(0, sum - (n - 1) * (long) A[n - 1]) + n - 2) / (n - 1));
}
/* -----: Template :----- */
static InputReader in;
static PrintWriter out;
public static void main(String[] args) {
try (PrintWriter o = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)))) {
in = new InputReader(System.in);
out = o;
int q = multipleIndependent ? in.nextInt() : 1;
while (q-- > 0) {
new P349C().run();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
static Integer[] toWrapper(int[] arr) {
Integer[] res = new Integer[arr.length];
for (int i = 0; i < arr.length; i++) {
res[i] = arr[i];
}
return res;
}
static Integer[][] toWrapper(int[][] arr) {
Integer[][] res = new Integer[arr.length][];
for (int i = 0; i < arr.length; i++) {
res[i] = toWrapper(arr[i]);
}
return res;
}
static Long[] toWrapper(long[] arr) {
Long[] res = new Long[arr.length];
for (int i = 0; i < arr.length; i++) {
res[i] = arr[i];
}
return res;
}
static Long[][] toWrapper(long[][] arr) {
Long[][] res = new Long[arr.length][];
for (int i = 0; i < arr.length; i++) {
res[i] = toWrapper(arr[i]);
}
return res;
}
static class InputReader {
private final BufferedReader reader;
private StringTokenizer tokenizer;
public InputReader(InputStream stream) {
int bufferSize = 32 * 1024;
reader = new BufferedReader(new InputStreamReader(stream), bufferSize);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public String nextLine() {
if (true) {
throw new RuntimeException("nextLine: not tested");
}
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
StringBuilder sb = new StringBuilder();
return tokenizer.nextToken("\n");
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public int[] nextIntArray(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
public long[] nextLongArray(int n) {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = nextLong();
}
return arr;
}
public int[][] nextIntMap(int n, int m) {
int[][] map = new int[n][m];
for (int i = 0; i < n; i++) {
map[i] = nextIntArray(m);
}
return map;
}
public long[][] nextLongMap(int n, int m) {
long[][] map = new long[n][m];
for (int i = 0; i < n; i++) {
map[i] = nextLongArray(m);
}
return map;
}
public char[][] nextCharMap(int n) {
char[][] map = new char[n][];
for (int i = 0; i < n; i++) {
map[i] = next().toCharArray();
}
return map;
}
}
}
| Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 8 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | d774366f15d31617cb5d1366d5a3a581 | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class Solution{
public static void main (String[] args)throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
int n = Integer.parseInt(br.readLine());
int[] a = new int[n];
int max = 0;
int pos = -1;
StringTokenizer st = new StringTokenizer(br.readLine());
for(int i=0; i<n; i++){
a[i] = Integer.parseInt(st.nextToken());
if(max < a[i]){
max = a[i];
pos = i;
}
}
int count = 0;
for(int i=0; i<n; i++){
if(i == pos)
continue;
count+=max-a[i];
if(count >= max){
out.println(max);
out.close();
return;
}
}
count = max-count;
out.println(max+(int)Math.ceil((double)count/(n-1)));
out.close();
}
}
| Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 8 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | cd7a713b8a4843d85ef907002bdc2477 | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collection;
import java.util.StringTokenizer;
import java.util.stream.IntStream;
import java.util.stream.Stream;
public class Main implements Runnable {
static final double time = 1e9;
static final int MOD = (int) 1e9 + 7;
static final long mh = Long.MAX_VALUE;
static final Reader in = new Reader();
static final PrintWriter out = new PrintWriter(System.out);
StringBuilder answer = new StringBuilder();
long start = System.nanoTime();
public static void main(String[] args) {
new Thread(null, new Main(), "persefone", 1 << 28).start();
}
@Override
public void run() {
solve();
printf();
long elapsed = System.nanoTime() - start;
// out.println("stamp : " + elapsed / time);
// out.println("stamp : " + TimeUnit.SECONDS.convert(elapsed, TimeUnit.NANOSECONDS));
close();
// out.flush();
}
void solve() {
int n = in.nextInt();
int[] a = in.nextIntArray(n);
long sum = 0;
int max = 0;
for (int i = 0; i < n; i++) {
sum += a[i];
max = Math.max(max, a[i]);
}
int k = (int) (sum / (n - 1) + (sum % (n - 1) == 0 ? 0 : 1));
printf(Math.max(k, max));
}
class Fenwick {
int n;
int[] bit;
Fenwick(int n) {
this.n = n;
bit = new int[n + 1];
}
Fenwick(int[] a) {
this(a.length);
for (int i = 1; i <= n; i++)
update(i, a[i - 1]);
}
void update(int i, int val) {
for (; i <= n; i += i & -i)
bit[i] += val;
}
int get(int i) {
int val = 0;
for (; i > 0; i -= i & -i)
val += bit[i];
return val;
}
int getRange(int be, int en) {
return get(en) - get(be - 1);
}
}
void printf() {
out.print(answer);
}
void close() {
out.close();
}
void printf(Stream<?> str) {
str.forEach(o -> add(o, " "));
add("\n");
}
void printf(Object... obj) {
printf(false, obj);
}
void printfWithDescription(Object... obj) {
printf(true, obj);
}
private void printf(boolean b, Object... obj) {
if (obj.length > 1) {
for (int i = 0; i < obj.length; i++) {
if (b) add(obj[i].getClass().getSimpleName(), " - ");
if (obj[i] instanceof Collection<?>) {
printf((Collection<?>) obj[i]);
} else if (obj[i] instanceof int[][]) {
printf((int[][])obj[i]);
} else if (obj[i] instanceof long[][]) {
printf((long[][])obj[i]);
} else if (obj[i] instanceof double[][]) {
printf((double[][])obj[i]);
} else printf(obj[i]);
}
return;
}
if (b) add(obj[0].getClass().getSimpleName(), " - ");
printf(obj[0]);
}
void printf(Object o) {
if (o instanceof int[])
printf(Arrays.stream((int[]) o).boxed());
else if (o instanceof char[])
printf(new String((char[]) o));
else if (o instanceof long[])
printf(Arrays.stream((long[]) o).boxed());
else if (o instanceof double[])
printf(Arrays.stream((double[]) o).boxed());
else if (o instanceof boolean[]) {
for (boolean b : (boolean[]) o) add(b, " ");
add("\n");
}
else
add(o, "\n");
}
void printf(int[]... obj) {
for (int i = 0; i < obj.length; i++) printf(obj[i]);
}
void printf(long[]... obj) {
for (int i = 0; i < obj.length; i++) printf(obj[i]);
}
void printf(double[]... obj) {
for (int i = 0; i < obj.length; i++) printf(obj[i]);
}
void printf(boolean[]... obj) {
for (int i = 0; i < obj.length; i++) printf(obj[i]);
}
void printf(Collection<?> col) {
printf(col.stream());
}
<T, K> void add(T t, K k) {
if (t instanceof Collection<?>) {
((Collection<?>) t).forEach(i -> add(i, " "));
} else if (t instanceof Object[]) {
Arrays.stream((Object[]) t).forEach(i -> add(i, " "));
} else
add(t);
add(k);
}
<T> void add(T t) {
answer.append(t);
}
@SuppressWarnings("unchecked")
<T extends Comparable<? super T>> T min(T... t) {
if (t.length == 0)
return null;
T m = t[0];
for (int i = 1; i < t.length; i++)
if (t[i].compareTo(m) < 0)
m = t[i];
return m;
}
@SuppressWarnings("unchecked")
<T extends Comparable<? super T>> T max(T... t) {
if (t.length == 0)
return null;
T m = t[0];
for (int i = 1; i < t.length; i++)
if (t[i].compareTo(m) > 0)
m = t[i];
return m;
}
int gcd(int a, int b) {
return (b == 0) ? a : gcd(b, a % b);
}
long gcd(long a, long b) {
return (b == 0) ? a : gcd(b, a % b);
}
// c = gcd(a, b) -> extends gcd method: ax + by = c <----> (b % a)p + q = c;
int[] ext_gcd(int a, int b) {
if (b == 0) return new int[] {a, 1, 0 };
int[] vals = ext_gcd(b, a % b);
int d = vals[0]; // gcd
int p = vals[2]; //
int q = vals[1] - (a / b) * vals[2];
return new int[] { d, p, q };
}
// find any solution of the equation: ax + by = c using extends gcd
boolean find_any_solution(int a, int b, int c, int[] root) {
int[] vals = ext_gcd(Math.abs(a), Math.abs(b));
if (c % vals[0] != 0) return false;
printf(vals);
root[0] = c * vals[1] / vals[0];
root[1] = c * vals[2] / vals[0];
if (a < 0) root[0] *= -1;
if (b < 0) root[1] *= -1;
return true;
}
int mod(int x) { return x % MOD; }
int mod(int x, int y) { return mod(mod(x) + mod(y)); }
long mod(long x) { return x % MOD; }
long mod (long x, long y) { return mod(mod(x) + mod(y)); }
int lw(long[] f, int l, int r, long k) {
int R = r, m = 0;
while (l <= r) {
m = l + r >> 1;
if (m == R) return m;
if (f[m] >= k) r = m - 1; else l = m + 1;
}
return l;
}
int up(long[] f, int l, int r, long k) {
int R = r, m = 0;
while (l <= r) {
m = l + r >> 1;
if (m == R) return m;
if (f[m] > k) r = m - 1; else l = m + 1;
}
return l;
}
int lw(int[] f, int l, int r, int k) {
int R = r, m = 0;
while (l <= r) {
m = l + r >> 1;
if (m == R) return m;
if (f[m] >= k) r = m - 1; else l = m + 1;
}
return l;
}
int up(int[] f, int l, int r, int k) {
int R = r, m = 0;
while (l <= r) {
m = l + r >> 1;
if (m == R) return m;
if (f[m] > k) r = m - 1; else l = m + 1;
}
return l;
}
long calc(int base, int exponent) {
if (exponent == 0) return 1;
if (exponent == 1) return base % MOD;
long m = calc(base, exponent >> 1);
if (exponent % 2 == 0) return m * m % MOD;
return base * m * m % MOD;
}
long calc(int base, long exponent) {
if (exponent == 0) return 1;
if (exponent == 1) return base % MOD;
long m = calc(base, exponent >> 1);
if (exponent % 2 == 0) return m * m % MOD;
return base * m * m % MOD;
}
long calc(long base, long exponent) {
if (exponent == 0) return 1;
if (exponent == 1) return base % MOD;
long m = calc(base, exponent >> 1);
if (exponent % 2 == 0) return m * m % MOD;
return base * m * m % MOD;
}
long power(int base, int exponent) {
if (exponent == 0) return 1;
long m = power(base, exponent >> 1);
if (exponent % 2 == 0) return m * m;
return base * m * m;
}
void swap(int[] a, int i, int j) {
a[i] ^= a[j];
a[j] ^= a[i];
a[i] ^= a[j];
}
void swap(long[] a, int i, int j) {
long tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
static class Pair<K extends Comparable<? super K>, V extends Comparable<? super V>>
implements Comparable<Pair<K, V>> {
private K k;
private V v;
Pair() {}
Pair(K k, V v) {
this.k = k;
this.v = v;
}
K getK() { return k; }
V getV() { return v; }
void setK(K k) { this.k = k; }
void setV(V v) { this.v = v; }
void setKV(K k, V v) {
this.k = k;
this.v = v;
}
@SuppressWarnings("unchecked")
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || !(o instanceof Pair)) return false;
Pair<K, V> p = (Pair<K, V>) o;
return k.compareTo(p.k) == 0 && v.compareTo(p.v) == 0;
}
@Override
public int hashCode() {
int hash = 31;
hash = hash * 89 + k.hashCode();
hash = hash * 89 + v.hashCode();
return hash;
}
@Override
public int compareTo(Pair<K, V> pair) {
return k.compareTo(pair.k) == 0 ? v.compareTo(pair.v) : k.compareTo(pair.k);
}
@Override
public Pair<K, V> clone() {
return new Pair<K, V>(this.k, this.v);
}
@Override
public String toString() {
return String.valueOf(k).concat(" ").concat(String.valueOf(v)).concat("\n");
}
}
static class Reader {
private BufferedReader br;
private StringTokenizer st;
Reader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
try {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] nextIntArray(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++)
arr[i] = nextInt();
return arr;
}
long nextLong() {
return Long.parseLong(next());
}
String nextLine() {
String s = "";
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return s;
}
}
} | Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 8 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | c623a42d45e0ea005b9ce5cbf35eb79f | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes | import java.util.*;
import java.io.*;
public class CF_349_C_MAFIA
{
public static void main (String [] args) throws Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt() - 1 , mx = 0;
long x = 0 ;
for( int i = 0 ; i <= n ; i++ )
{
int xx = sc.nextInt();
x += xx;
mx = Math.max(mx , xx);
}
System.out.println(Math.max((x + n - 1) / n , mx));
}
static class Scanner
{
BufferedReader br ;
StringTokenizer st ;
Scanner (InputStream in) throws Exception { br = new BufferedReader(new InputStreamReader(in));}
String next() throws Exception { while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken() ;}
int nextInt() throws Exception { return Integer.parseInt(next()) ; }
long nextLong () throws Exception { return Long.parseLong(next()) ; }
}
} | Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 8 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | 64623c3898b0844d57130543e1de6b48 | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes |
import java.util.Scanner;
public class Mafia {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n=in.nextInt();
//int[] a=new int[n];
long sum=0,max=0;
for(int i=0;i<n;i++){
int x=in.nextInt();
sum+=x;
max=Math.max(max, x);
}
long ans=0;
if(sum%(n-1)==0){
ans=sum/(n-1);
}else{
ans=sum/(n-1)+1;
}
ans=Math.max(max, ans);
System.out.println(ans);
}
}
| Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 8 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | db4edd89be8bc08962dfcdb8f6d1586e | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static InputReader in = new InputReader(System.in);
static PrintWriter out = new PrintWriter(System.out);
static int oo = (int)1e9;
// static long oo = (long)1e15;
static int mod = 1_000_000_007;
static int[] di = {1, 0, 0, -1};
static int[] dj = {0, -1, 1, 0};
static int M = 40;
static double EPS = 1e-13;
public static void main(String[] args) throws IOException {
int n = in.nextInt();
int m = 0;
int[] a = new int[n];
long sum = 0;
for(int i = 0; i < n; ++i) {
a[i] = in.nextInt();
sum += a[i];
m = Math.max(m, a[i]);
}
long l = m, r = (long)1e10;
long ans = 0;
while(l <= r) {
long mid = (l + r) / 2;
long b = mid * (n-1);
if(b >= sum) {
ans = mid;
r = mid - 1;
}
else
l = mid + 1;
}
System.out.println(ans);
out.close();
}
static int dfs(ArrayList<Integer>[] adj, boolean[] visit, int u, int rem) {
if(u == rem)
return 0;
if(visit[u])
return 0;
visit[u] = true;
int ret = 1;
for(int v : adj[u]) {
if(!visit[v]) {
ret += dfs(adj, visit, v, rem);
}
}
return ret;
}
static int find(int[] g, int x) {
return g[x] = g[x] == x ? x : find(g, g[x]);
}
static void union(int[] g, int[] size, int x, int y) {
x = find(g, x); y = find(g, y);
if(x == y)
return;
if(size[x] < size[y]) {
g[x] = y;
size[y] += size[x];
}
else {
g[y] = x;
size[x] += size[y];
}
}
static class Segment {
Segment left, right;
int size, val;
int time, lazy;
public Segment(int[] a, int l, int r) {
super();
if(l == r) {
return;
}
int mid = (l + r) / 2;
left = new Segment(a, l, mid);
right = new Segment(a, mid+1, r);
}
boolean covered(int ll, int rr, int l, int r) {
return ll <= l && rr >= r;
}
boolean noIntersection(int ll, int rr, int l, int r) {
return ll > r || rr < l;
}
void lazyPropagation() {
if(lazy != 0) {
if(left != null) {
left.setLazy(this.time, this.lazy);
right.setLazy(this.time, this.lazy);
}
else {
val = lazy;
}
}
}
void setLazy(int time, int lazy) {
if(this.time != 0 && this.time <= time)
return;
this.time = time;
this.lazy = lazy;
}
int query(int ll, int rr, int l, int r) {
lazyPropagation();
if(noIntersection(ll, rr, l, r))
return 0;
if(covered(ll, rr, l, r))
return val;
int mid = (l + r) / 2;
int leftSum = left.query(ll, rr, l, mid);
int rightSum = right.query(ll, rr, mid+1, r);
return leftSum + rightSum;
}
int query(int k, int l, int r) {
Segment trace = this;
while(l < r) {
int mid = (l + r) / 2;
if(trace.left.size > k) {
trace = trace.left;
r = mid;
}
else {
k -= trace.left.size;
trace = trace.right;
l = mid + 1;
}
}
return l;
}
void update(int ll, int rr, int time, int knight, int l, int r) {
lazyPropagation();
if(noIntersection(ll, rr, l, r))
return;
if(covered(ll, rr, l, r)) {
setLazy(time, knight);
return;
}
int mid = (l + r) / 2;
left.update(ll, rr, time, knight, l, mid);
right.update(ll, rr, time, knight, mid+1, r);
}
}
static long pow(long a, long n, long mod) {
if(n == 0)
return 1;
if(n % 2 == 1)
return a * pow(a, n-1, mod) % mod;
long x = pow(a, n / 2, mod);
return x * x % mod;
}
static int[] getPi(char[] a) {
int m = a.length;
int j = 0;
int[] pi = new int[m];
for(int i = 1; i < m; ++i) {
while(j > 0 && a[i] != a[j])
j = pi[j-1];
if(a[i] == a[j]) {
pi[i] = j + 1;
j++;
}
}
return pi;
}
static long lcm(long a, long b) {
return a * b / gcd(a, b);
}
static boolean nextPermutation(int[] a) {
for(int i = a.length - 2; i >= 0; --i) {
if(a[i] < a[i+1]) {
for(int j = a.length - 1; ; --j) {
if(a[i] < a[j]) {
int t = a[i];
a[i] = a[j];
a[j] = t;
for(i++, j = a.length - 1; i < j; ++i, --j) {
t = a[i];
a[i] = a[j];
a[j] = t;
}
return true;
}
}
}
}
return false;
}
static void shuffle(Object[] a) {
Random r = new Random();
for(int i = a.length - 1; i > 0; --i) {
int si = r.nextInt(i);
Object t = a[si];
a[si] = a[i];
a[i] = t;
}
}
static void shuffle(int[] a) {
Random r = new Random();
for(int i = a.length - 1; i > 0; --i) {
int si = r.nextInt(i);
int t = a[si];
a[si] = a[i];
a[i] = t;
}
}
static void shuffle(long[] a) {
Random r = new Random();
for(int i = a.length - 1; i > 0; --i) {
int si = r.nextInt(i);
long t = a[si];
a[si] = a[i];
a[i] = t;
}
}
static int lower_bound(int[] a, int n, int k) {
int s = 0;
int e = n;
int m;
while (e - s > 0) {
m = (s + e) / 2;
if (a[m] < k)
s = m + 1;
else
e = m;
}
return e;
}
static int lower_bound(long[] a, int n, long k) {
int s = 0;
int e = n;
int m;
while (e - s > 0) {
m = (s + e) / 2;
if (a[m] < k)
s = m + 1;
else
e = m;
}
return e;
}
static int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
static long gcd(long a, long b) {
return b == 0 ? a : gcd(b, a % b);
}
static class Pair implements Comparable<Pair> {
int first, second;
public Pair(int first, int second) {
super();
this.first = first;
this.second = second;
}
@Override
public int compareTo(Pair o) {
return this.first != o.first ? this.first - o.first : this.second - o.second;
}
// @Override
// public int compareTo(Pair o) {
// return this.first != o.first ? o.first - this.first : o.second - this.second;
// }
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + first;
result = prime * result + second;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Pair other = (Pair) obj;
if (first != other.first)
return false;
if (second != other.second)
return false;
return true;
}
}
}
class InputReader {
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
public InputReader(InputStream st) {
this.stream = st;
}
public int read() {
if (snumChars == -1)
throw new InputMismatchException();
if (curChar >= snumChars) {
curChar = 0;
try {
snumChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (snumChars <= 0)
return -1;
}
return buf[curChar++];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int[] nextIntArray(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
public String readString() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public String nextLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
} | Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 8 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | 96e963cd8d2d9905582ca5918cb280d7 | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes | import java.io.*;
import java.math.*;
import java.util.*;
/**
*
* @author Saju
*
*/
public class Main {
private static int dx[] = { 1, 0, -1, 0 };
private static int dy[] = { 0, -1, 0, 1 };
private static final long INF = (long) Math.pow(10, 16);
private static final int INT_INF = Integer.MAX_VALUE;
private static final long NEG_INF = Long.MIN_VALUE;
private static final int NEG_INT_INF = Integer.MIN_VALUE;
private static final double EPSILON = 1e-10;
private static final long MAX = (long) 1e12;
private static final long MOD = 1000000007;
private static final int MAXN = 200001;
private static final int MAXA = 1000007;
private static final int MAXLOG = 22;
private static final double PI = Math.acos(-1);
public static void main(String[] args) throws IOException {
InputReader in = new InputReader(System.in);
// Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
// InputReader in = new InputReader(new FileInputStream("src/test.in"));
// PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("src/test.out")));
/*
*/
int n = in.nextInt();
List<Integer> list = new ArrayList<>();
long sum = 0;
for(int i = 0; i < n; i++) {
int a = in.nextInt();
list.add(a);
sum += a;
}
Collections.sort(list);
long x = ceil(sum, n - 1);
out.println(max(list.get(n - 1), x));
in.close();
out.flush();
out.close();
System.exit(0);
}
/*
* return the number of elements in list that are less than or equal to the val
*/
private static long upperBound(List<Long> list, long val) {
int start = 0;
int len = list.size();
int end = len - 1;
int mid = 0;
while (true) {
if (start > end) {
break;
}
mid = (start + end) / 2;
long v = list.get(mid);
if (v == val) {
start = mid;
while(start < end) {
mid = (start + end) / 2;
if(list.get(mid) == val) {
if(mid + 1 < len && list.get(mid + 1) == val) {
start = mid + 1;
}
else {
return mid + 1;
}
}
else {
end = mid - 1;
}
}
return start + 1;
}
if (v > val) {
end = mid - 1;
} else {
start = mid + 1;
}
}
if (list.get(mid) < val) {
return mid + 1;
}
return mid;
}
private static boolean isPalindrome(String str) {
StringBuilder sb = new StringBuilder();
sb.append(str);
String str1 = sb.reverse().toString();
return str.equals(str1);
}
private static String getBinaryStr(long n, int j) {
String str = Long.toBinaryString(n);
int k = str.length();
for (int i = 1; i <= j - k; i++) {
str = "0" + str;
}
return str;
}
private static long modInverse(long r) {
return bigMod(r, MOD - 2, MOD);
}
private static long bigMod(long n, long k, long m) {
long ans = 1;
while (k > 0) {
if ((k & 1) == 1) {
ans = (ans * n) % m;
}
n = (n * n) % m;
k >>= 1;
}
return ans;
}
private static long ceil(long n, long x) {
long div = n / x;
if(div * x != n) {
div++;
}
return div;
}
private static int ceil(int n, int x) {
int div = n / x;
if(div * x != n) {
div++;
}
return div;
}
private static int abs(int x) {
if (x < 0) {
return -x;
}
return x;
}
private static double abs(double x) {
if (x < 0) {
return -x;
}
return x;
}
private static long abs(long x) {
if(x < 0) {
return -x;
}
return x;
}
private static long lcm(long a, long b) {
return (a * b) / gcd(a, b);
}
private static int lcm(int a, int b) {
return (a * b) / gcd(a, b);
}
private static int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
private static long gcd(long a, long b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
private static int log(long x, int base) {
return (int) (Math.log(x) / Math.log(base));
}
private static int log(long x, long base) {
return (int) (Math.log(x) / Math.log(base));
}
private static long min(long a, long b) {
if (a < b) {
return a;
}
return b;
}
private static int min(int a, int b) {
if (a < b) {
return a;
}
return b;
}
private static long max(long a, long b) {
if (a < b) {
return b;
}
return a;
}
private static int max(int a, int b) {
if (a < b) {
return b;
}
return a;
}
private static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public String next() {
try {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
} catch (IOException e) {
return null;
}
return tokenizer.nextToken();
}
public String nextLine() {
String line = null;
try {
tokenizer = null;
line = reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
return line;
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public boolean hasNext() {
try {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
} catch (Exception e) {
return false;
}
return true;
}
public int[] nextIntArr(int n) {
int arr[] = new int[n];
for(int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
public long[] nextLongArr(int n) {
long arr[] = new long[n];
for(int i = 0; i < n; i++) {
arr[i] = nextLong();
}
return arr;
}
public int[] nextIntArr1(int n) {
int arr[] = new int[n + 1];
for(int i = 1; i <= n; i++) {
arr[i] = nextInt();
}
return arr;
}
public long[] nextLongArr1(int n) {
long arr[] = new long[n + 1];
for(int i = 1; i <= n; i++) {
arr[i] = nextLong();
}
return arr;
}
public void close() {
try {
if(reader != null) {
reader.close();
}
}
catch(Exception e) {
}
}
}
} | Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 8 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | 0750eab91fd7055d9c88e734980ad8ee | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes | import java.io.*;
import java.util.*;
import java.lang.*;
import java.math.BigInteger;
public class Main {
public static void main(String[] args) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t,ca,i,j;
String[] my;
String line = br.readLine();
my = line.split(" ");
int n,m,k;
n = Integer.parseInt(line);
line = br.readLine();
my = line.split(" ");
int a[] = new int[n];
int hi = -1;
for(i=0;i<n;i++)
{
a[i] = Integer.parseInt(my[i]);
if(a[i] > hi)hi = a[i];
}
// System.out.println(" hi is " + hi);
long ans = hi;
long lo = hi;
long tar = 2*(long)hi;
while(lo<=tar)
{
ans = (lo + tar)/2;
boolean ch = pos(ans,a);
if(ch==false)
{
lo = ans+1;
}
else {
ch = pos(ans-1,a);
if(ch==false)break;
tar = ans-1;
}
}
System.out.println(ans);
}
public static boolean pos(long m,int[] a)
{
int n = a.length;
long sum = 0;
int i;
for(i=0;i<n;i++)
{
sum+=(long)m-a[i];
if(sum>=m)return true;
}
return false;
}
}
class ut implements Comparator<Team>{
public int compare(Team first, Team other)
{
if(first.pr > other.pr)return -1;
if(first.pr < other.pr)return 1;
if(first.ti < other.ti)return -1;
if(first.ti > other.ti)return 1;
if(first.in < other.in)return -1;
if(first.in > other.in)return 1;
return 0;
}
}
class Team implements Comparable{
int pr,ti,in;
public Team(int a, int b, int c)
{
pr = a;
ti = b;
in = c;
}
public String toString()
{
return pr + " " + ti + " " + in+ "\n";
}
public int compareTo(Object obj)
{
Team other = (Team)obj;
if(pr > other.pr)return -1;
if(pr < other.pr)return 1;
if(ti < other.ti)return -1;
if(ti > other.ti)return 1;
if(in < other.in)return -1;
if(in > other.in)return 1;
return 0;
}
}
| Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 8 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | 7bb7daad9762e525855ebe97de1e2cab | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes |
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.lang.*;
public class P349C {
//static long mod=1000000007;
public static void main(String[] args) throws Exception{
InputReader in = new InputReader(System.in);
PrintWriter pw=new PrintWriter(System.out);
//int t=in.readInt();
// while(t-->0)
//{
int n=in.readInt();
//long n=in.readLong();
int a[]=new int[n];
long s=0;
long ans=0;
for(int i=0;i<n;i++)
{
a[i]=in.readInt();
s+=a[i];
ans=max(ans,a[i]);
}
long h=n-1;
//System.out.println(s+" "+h);
long x=(long)Math.ceil((double)s/(double)h);
//System.out.println(x);
ans=max(ans,x);
pw.println(ans);
//}
pw.close();
}
public static long ways(int n, int r, long MOD)
{
// vector<long long> f(n + 1,1);
long f[]=new long[n+1];
Arrays.fill(f,1);
for (int i=2; i<=n;i++)
f[i]= (f[i-1]*i) % MOD;
return (f[n]*((InverseEuler(f[r], MOD) * InverseEuler(f[n-r], MOD)) % MOD)) % MOD;
}
public static long InverseEuler(long n, long MOD)
{
return pow(n,MOD-2,MOD);
}
static boolean isPrime(int number) {
if (number <= 1) {
return false;
}
if (number <= 3) {
return true;
}
if (number % 2 == 0 || number % 3 == 0) {
return false;
}
int i = 5;
while (i * i <= number) {
if (number % i == 0 || number % (i + 2) == 0) {
return false;
}
i += 6;
}
return true;
}
public static long gcd(long x,long y)
{
if(x%y==0)
return y;
else
return gcd(y,x%y);
}
public static int gcd(int x,int y)
{
if(x%y==0)
return y;
else
return gcd(y,x%y);
}
public static int abs(int a,int b)
{
return (int)Math.abs(a-b);
}
public static long abs(long a,long b)
{
return (long)Math.abs(a-b);
}
public static int max(int a,int b)
{
if(a>b)
return a;
else
return b;
}
public static int min(int a,int b)
{
if(a>b)
return b;
else
return a;
}
public static long max(long a,long b)
{
if(a>b)
return a;
else
return b;
}
public static long min(long a,long b)
{
if(a>b)
return b;
else
return a;
}
static boolean isPowerOfTwo (long v) {
return (v & (v - 1)) == 0;
}
public static long pow(long n,long p,long m)
{
long result = 1;
if(p==0)
return 1;
if (p==1)
return n;
while(p!=0)
{
if(p%2==1)
result *= n;
if(result>=m)
result%=m;
p >>=1;
n*=n;
if(n>=m)
n%=m;
}
return result;
}
static class Pair implements Comparable<Pair>
{
int a,b;
Pair (int a,int b)
{
this.a=a;
this.b=b;
}
public int compareTo(Pair o) {
// TODO Auto-generated method stub
if(this.a!=o.a)
return Integer.compare(this.a,o.a);
else
return Integer.compare(this.b, o.b);
//return 0;
}
public boolean equals(Object o) {
if (o instanceof Pair) {
Pair p = (Pair)o;
return p.a == a && p.b == b;
}
return false;
}
public int hashCode() {
return new Integer(a).hashCode() * 31 + new Integer(b).hashCode();
}
}
static long sort(int a[],int n)
{ int b[]=new int[n];
return mergeSort(a,b,0,n-1);}
static long mergeSort(int a[],int b[],long left,long right)
{ long c=0;if(left<right)
{ long mid=left+(right-left)/2;
c= mergeSort(a,b,left,mid);
c+=mergeSort(a,b,mid+1,right);
c+=merge(a,b,left,mid+1,right); }
return c; }
static long merge(int a[],int b[],long left,long mid,long right)
{long c=0;int i=(int)left;int j=(int)mid; int k=(int)left;
while(i<=(int)mid-1&&j<=(int)right)
{ if(a[i]<=a[j]) {b[k++]=a[i++]; }
else { b[k++]=a[j++];c+=mid-i;}}
while (i <= (int)mid - 1) b[k++] = a[i++];
while (j <= (int)right) b[k++] = a[j++];
for (i=(int)left; i <= (int)right; i++)
a[i] = b[i]; return c; }
static class InputReader
{
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream)
{
this.stream = stream;
}
public int read()
{
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars)
{
curChar = 0;
try
{
numChars = stream.read(buf);
} catch (IOException e)
{
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int readInt()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
int res = 0;
do
{
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String readString()
{
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do
{
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public double readDouble() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E')
return res * Math.pow(10, readInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E')
return res * Math.pow(10, readInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public long readLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c)
{
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next()
{
return readString();
}
public interface SpaceCharFilter
{
public boolean isSpaceChar(int ch);
}
}
static class OutputWriter
{
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream)
{
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer)
{
this.writer = new PrintWriter(writer);
}
public void print(Object... objects)
{
for (int i = 0; i < objects.length; i++)
{
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object... objects)
{
print(objects);
writer.println();
}
public void close()
{
writer.close();
}
public void flush()
{
writer.flush();
}
}
/* USAGE
//initialize
InputReader in = new InputReader(System.in);
OutputWriter out = new OutputWriter(System.out);
//read int
int i = in.readInt();
//read string
String s = in.readString();
//read int array of size N
int[] x = IOUtils.readIntArray(in,N);
//printline
out.printLine("X");
//flush output
out.flush();
//remember to close the
//outputstream, at the end
out.close();
*/
static class IOUtils {
public static int[] readIntArray(InputReader in, int size) {
int[] array = new int[size];
for (int i = 0; i < size; i++)
array[i] = in.readInt();
return array;
}
}
//BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
//StringBuilder sb=new StringBuilder("");
//InputReader in = new InputReader(System.in);
// OutputWriter out = new OutputWriter(System.out);
//PrintWriter pw=new PrintWriter(System.out);
//String line=br.readLine().trim();
//int t=Integer.parseInt(br.readLine());
// while(t-->0)
//{
//int n=Integer.parseInt(br.readLine());
//long n=Long.parseLong(br.readLine());
//String l[]=br.readLine().split(" ");
//int m=Integer.parseInt(l[0]);
//int k=Integer.parseInt(l[1]);
//String l[]=br.readLine().split(" ");
//l=br.readLine().split(" ");
/*int a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=Integer.parseInt(l[i]);
}*/
//System.out.println(" ");
//}
} | Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 8 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | 80f7d4906ebdc09ebe003cb7e332d7b3 | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main
{
public static void main(String[] args)
{
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskC solver = new TaskC();
solver.solve(1, in, out);
out.close();
}
static class TaskC
{
public void solve(int testNumber, Scanner in, PrintWriter out)
{
int n = in.nextInt();
int max = 0;
long sum = 0, ans;
for (int i = 0; i < n; i++) {
int minMatch = in.nextInt();
max = Math.max(max, minMatch);
sum += minMatch;
}
ans = Math.max(max, (long) Math.ceil(sum / (double) (n - 1)));
out.println(ans);
}
}
}
| Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 8 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | d323a680f8a8286aca9f9304447ae9fd | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main
{
public static void main(String[] args)
{
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskC solver = new TaskC();
solver.solve(1, in, out);
out.close();
}
static class TaskC
{
public void solve(int testNumber, Scanner in, PrintWriter out)
{
int n = in.nextInt();
int max = 0;
long sum = 0, ans;
for (int i = 0; i < n; i++) {
int minMatch = in.nextInt();
max = Math.max(max, minMatch);
sum += minMatch;
}
ans = Math.max(max, (sum - 1) / (n - 1) + 1); // (long) Math.ceil(sum / (double) (n - 1))
out.println(ans);
}
}
}
| Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 8 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | 25f7271b5b6e7d6aee6b94d5ad93f924 | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes | //package CF;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;
public class B {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = sc.nextInt();
int[] a = new int[n];
int max = 0;
long sum = 0;
for (int i = 0; i < a.length; i++) {
a[i] = sc.nextInt();
max = Math.max(max, a[i]);
sum += a[i];
}
out.println(Math.max(max, (sum+n-2)/(n-1)));
out.flush();
out.close();
}
static class Scanner {
BufferedReader bf;
StringTokenizer st;
public Scanner(InputStream i) {
bf = new BufferedReader(new InputStreamReader(i));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(bf.readLine());
return st.nextToken();
}
public int nextInt() throws NumberFormatException, IOException {
return Integer.parseInt(next());
}
public double nextDouble() throws IOException {
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if (x.charAt(0) == '-') {
neg = true;
start++;
}
for (int i = start; i < x.length(); i++)
if (x.charAt(i) == '.') {
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
} else {
sb.append(x.charAt(i));
if (dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg ? -1 : 1);
}
}
} | Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 8 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | 107aedf30be6396213f144c97ba57feb | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedOutputStream;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Kattio in = new Kattio(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
static class TaskA {
public void solve(int testNumber, Kattio in, PrintWriter out) {
int n = in.nextInt();
long sum = 0;
long max = 0;
for (int i = 0; i < n; ++i) {
long a = in.nextLong();
sum += a;
max = Math.max(max, a);
}
out.println(Math.max(max, (sum / (n - 1)) + (sum % (n - 1) != 0 ? 1 : 0)));
}
}
static class Kattio extends PrintWriter {
private BufferedReader r;
private String line;
private StringTokenizer st;
private String token;
public Kattio(InputStream i) {
super(new BufferedOutputStream(System.out));
r = new BufferedReader(new InputStreamReader(i));
}
public Kattio(InputStream i, OutputStream o) {
super(new BufferedOutputStream(o));
r = new BufferedReader(new InputStreamReader(i));
}
public int nextInt() {
return Integer.parseInt(nextToken());
}
public long nextLong() {
return Long.parseLong(nextToken());
}
private String peekToken() {
if (token == null)
try {
while (st == null || !st.hasMoreTokens()) {
line = r.readLine();
if (line == null) return null;
st = new StringTokenizer(line);
}
token = st.nextToken();
} catch (IOException e) {
}
return token;
}
private String nextToken() {
String ans = peekToken();
token = null;
return ans;
}
}
}
| Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 8 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | 27649817b24c1ce6fc9a715783e0dac0 | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.io.BufferedOutputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Kattio in = new Kattio(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
static class TaskA {
public void solve(int testNumber, Kattio in, PrintWriter out) {
int n = in.nextInt();
long[] arr = new long[n];
long low = 0;
long hi = (long) 1e15;
for (int i = 0; i < n; ++i) {
arr[i] = in.nextInt();
low = Math.max(arr[i], low);
}
while (low < hi) {
long mid = (low + hi) / 2;
if (check(arr, mid)) {
hi = mid;
} else {
low = mid + 1;
}
}
out.println(low);
}
private boolean check(long[] arr, long mid) {
long sum = 0;
for (long a : arr) {
sum += mid - a;
}
return sum < 0 || sum >= mid;
}
}
static class Kattio extends PrintWriter {
private BufferedReader r;
private String line;
private StringTokenizer st;
private String token;
public Kattio(InputStream i) {
super(new BufferedOutputStream(System.out));
r = new BufferedReader(new InputStreamReader(i));
}
public Kattio(InputStream i, OutputStream o) {
super(new BufferedOutputStream(o));
r = new BufferedReader(new InputStreamReader(i));
}
public int nextInt() {
return Integer.parseInt(nextToken());
}
private String peekToken() {
if (token == null)
try {
while (st == null || !st.hasMoreTokens()) {
line = r.readLine();
if (line == null) return null;
st = new StringTokenizer(line);
}
token = st.nextToken();
} catch (IOException e) {
}
return token;
}
private String nextToken() {
String ans = peekToken();
token = null;
return ans;
}
}
}
| Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 8 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | 101e64d7d3729bc901fe84d578530b5d | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes | import java.io.*;
import java.util.*;
public class CF349C {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int[] aa = new int[n];
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 0; i < n; i++)
aa[i] = Integer.parseInt(st.nextToken());
long sum = 0;
long max = 0;
for (int i = 0; i < n; i++) {
sum += aa[i];
if (max < aa[i])
max = aa[i];
}
long r = (sum + n - 2) / (n - 1); // ceiling of sum / (n - 1)
if (r < max)
r = max;
System.out.println(r);
}
}
| Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 8 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | 83491f6d0d68ad2e3f6a9dd10952ecc3 | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes | import java.io.*;
import java.util.*;
public class CodeForce{
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
String[] str=br.readLine().split(" ");
long[] arr=new long[n];
long max=Long.MIN_VALUE;
long sum=0;
for(int i=0;i<n;i++){
arr[i]=Long.parseLong(str[i]);
if(max<arr[i])
max=arr[i];
sum+=arr[i];
}
System.out.println(Math.max(max,(int)Math.ceil((double)sum/(n-1))));
}} | Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 8 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | 18a047b5efb5ff7d6440186d426d4df9 | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes | //import com.sun.org.apache.xpath.internal.operations.String;
//import com.sun.org.apache.xpath.internal.operations.String;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.*;
public class scratch_25 {
// int count=0;
//static long count=0;
static class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/**
* call this method to initialize reader for InputStream
*/
static void init(InputStream input) {
reader = new BufferedReader(
new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
/**
* get next word
*/
static String next() throws IOException {
while (!tokenizer.hasMoreTokens()) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(
reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt(next());
}
static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
static long nextLong() throws IOException {
return Long.parseLong(next());
}
}
public static class Graph{
public static class Vertex{
HashMap<Integer,Integer> nb= new HashMap<>(); // for neighbours of each vertex
}
public static HashMap<Integer,Vertex> vt; // for vertices(all)
public Graph(){
vt= new HashMap<>();
}
public static int numVer(){
return vt.size();
}
public static boolean contVer(int ver){
return vt.containsKey(ver);
}
public static void addVer(int ver){
Vertex v= new Vertex();
vt.put(ver,v);
}
public static int numEdg(){
int count=0;
ArrayList<Integer> vrtc= new ArrayList<>(vt.keySet());
for (int i = 0; i <vrtc.size() ; i++) {
count+=(vt.get(vrtc.get(i))).nb.size();
}
return count/2;
}
public static boolean contEdg(int ver1, int ver2){
if(vt.get(ver1)==null || vt.get(ver2)==null){
return false;
}
Vertex v= vt.get(ver1);
if(v.nb.containsKey(ver2)){
return true;
}
return false;
}
public static void addEdge(int ver1, int ver2, int weight){
if(!vt.containsKey(ver1) || !vt.containsKey(ver2)){
return;
}
Vertex v1= vt.get(ver1);
Vertex v2= vt.get(ver2);
v1.nb.put(ver2,weight); // if previously there is an edge, then this replaces that edge
v2.nb.put(ver1,weight);
}
public static void delEdge(int ver1, int ver2){
if(!vt.containsKey(ver1) || !vt.containsKey(ver2)){
return;
}
vt.get(ver1).nb.remove(ver2);
vt.get(ver2).nb.remove(ver1);
}
public static void delVer(int ver){
if(!vt.containsKey(ver)){
return;
}
Vertex v1= vt.get(ver);
ArrayList<Integer> arr= new ArrayList<>(v1.nb.keySet());
for (int i = 0; i <arr.size() ; i++) {
int s= arr.get(i);
vt.get(s).nb.remove(ver);
}
vt.remove(ver);
}
public class Pair{
int vname;
ArrayList<Integer> psf= new ArrayList<>(); // path so far
int dis;
int col;
}
public HashMap<Integer,Integer> bfs(int src){
HashMap<Integer, Boolean> prcd= new HashMap<>(); // jo jo ho chuke hain unke liye
HashMap<Integer, Integer> ans= new HashMap<>();
LinkedList<Pair> queue= new LinkedList<>(); // for bfs queue
Pair strtp= new Pair();
strtp.vname= src;
ArrayList<Integer> ar= new ArrayList<>();
ar.add(src);
strtp.psf= ar;
strtp.dis=0;
queue.addLast(strtp);
while(!queue.isEmpty()){
Pair rp = queue.removeFirst();
if(prcd.containsKey(rp.vname)){
continue;
}
prcd.put(rp.vname,true);
ans.put(rp.vname,rp.dis);
// if(contEdg(rp.vname,dst)){
// return true;
// }
Vertex a= vt.get(rp.vname);
ArrayList<Integer> arr= new ArrayList<>(a.nb.keySet());
for (int i = 0; i <arr.size() ; i++) {
int s= arr.get(i);
if(!prcd.containsKey(s)){
Pair np = new Pair();
np.vname= s;
np.dis+=rp.dis+a.nb.get(s);
np.psf.addAll(rp.psf);
np.psf.add(s);
// np.psf.add(s);
// np.psf= rp.psf+" "+s;
queue.addLast(np);
}
}
}
return ans;
// return false;
}
public HashMap<Integer,Integer> dfs(int src){
HashMap<Integer, Boolean> prcd= new HashMap<>(); // jo jo ho chuke hain unke liye
HashMap<Integer, Integer> ans= new HashMap<>();
LinkedList<Pair> stack= new LinkedList<>(); // for bfs queue
Pair strtp= new Pair();
strtp.vname= src;
ArrayList<Integer> ar= new ArrayList<>();
ar.add(src);
strtp.psf= ar;
strtp.dis=0;
stack.addFirst(strtp);
while(!stack.isEmpty()){
Pair rp = stack.removeFirst();
if(prcd.containsKey(rp.vname)){
continue;
}
prcd.put(rp.vname,true);
ans.put(rp.vname,rp.dis);
// if(contEdg(rp.vname,dst)){
// return true;
// }
Vertex a= vt.get(rp.vname);
ArrayList<Integer> arr= new ArrayList<>(a.nb.keySet());
for (int i = 0; i <arr.size() ; i++) {
int s= arr.get(i);
if(!prcd.containsKey(s)){
Pair np = new Pair();
np.vname= s;
np.dis+=rp.dis+a.nb.get(s);
np.psf.addAll(rp.psf);
np.psf.add(s);
// np.psf.add(s);
// np.psf= rp.psf+" "+s;
stack.addFirst(np);
}
}
}
return ans;
// return false;
}
public boolean isCycle(){
HashMap<Integer, Boolean> prcd= new HashMap<>(); // jo jo ho chuke hain unke liye
// HashMap<Integer, Integer> ans= new HashMap<>();
LinkedList<Pair> queue= new LinkedList<>(); // for bfs queue
ArrayList<Integer> keys = new ArrayList<>(vt.keySet());
for (int i = 0; i <keys.size(); i++) {
int cur= keys.get(i);
if(prcd.containsKey(cur)){
continue;
}
Pair sp = new Pair();
sp.vname= cur;
ArrayList<Integer> as= new ArrayList<>();
as.add(cur);
sp.psf= as;
queue.addLast(sp);
while(!queue.isEmpty()){
Pair rp= queue.removeFirst();
if(prcd.containsKey(rp.vname)){
return true;
}
prcd.put(rp.vname,true);
Vertex v1= vt.get(rp.vname);
ArrayList<Integer> nbrs= new ArrayList<>(v1.nb.keySet());
for (int j = 0; j <nbrs.size() ; j++) {
int u= nbrs.get(j);
Pair np= new Pair();
np.vname= u;
queue.addLast(np);
}
}
}
return false;
}
public ArrayList<ArrayList<Integer>> genConnctdComp(){
HashMap<Integer, Boolean> prcd= new HashMap<>(); // jo jo ho chuke hain unke liye
ArrayList<ArrayList<Integer>> ans= new ArrayList<>();
// HashMap<Integer, Integer> ans= new HashMap<>();
LinkedList<Pair> queue= new LinkedList<>(); // for bfs queue
// int con=-1;
ArrayList<Integer> keys = new ArrayList<>(vt.keySet());
for (int i = 0; i <keys.size(); i++) {
int cur= keys.get(i);
if(prcd.containsKey(cur)){
//return true;
continue;
}
int count=0;
ArrayList<Integer> fu= new ArrayList<>();
fu.add(cur);
Pair sp = new Pair();
sp.vname= cur;
ArrayList<Integer> as= new ArrayList<>();
as.add(cur);
sp.psf= as;
queue.addLast(sp);
while(!queue.isEmpty()){
Pair rp= queue.removeFirst();
if(prcd.containsKey(rp.vname)){
//return true;
continue;
}
prcd.put(rp.vname,true);
fu.add(rp.vname);
Vertex v1= vt.get(rp.vname);
ArrayList<Integer> nbrs= new ArrayList<>(v1.nb.keySet());
for (int j = 0; j <nbrs.size() ; j++) {
int u= nbrs.get(j);
if(!prcd.containsKey(u)){
count++;
Pair np= new Pair();
np.vname= u;
queue.addLast(np);
}
}}
fu.add(count);
ans.add(fu);
}
//return false;
return ans;
}
public boolean isBip(int src){ // only for connected graph
HashMap<Integer,Integer> clr= new HashMap<>();
// colors are 1 and -1
LinkedList<Integer>q = new LinkedList<Integer>();
clr.put(src,1);
q.add(src);
while(!q.isEmpty()){
int u = q.getFirst();
q.pop();
ArrayList<Integer> arr= new ArrayList<>(vt.keySet());
for (int i = 0; i <arr.size() ; ++i) {
int x= arr.get(i);
if(vt.get(u).nb.containsKey(x) && !clr.containsKey(x)){
if(clr.get(u)==1){
clr.put(x,-1);
}
else{
clr.put(x,1);
}
q.push(x);
}
else if(vt.get(u).nb.containsKey(x) && (clr.get(x)==clr.get(u))){
return false;
}
}
}
return true;
}
public static void printGr() {
ArrayList<Integer> arr= new ArrayList<>(vt.keySet());
for (int i = 0; i <arr.size() ; i++) {
int ver= arr.get(i);
Vertex v1= vt.get(ver);
ArrayList<Integer> arr1= new ArrayList<>(v1.nb.keySet());
for (int j = 0; j <arr1.size() ; j++) {
System.out.println(ver+"-"+arr1.get(j)+":"+v1.nb.get(arr1.get(j)));
}
}
}
}
static class Cus implements Comparable<Cus>{
int size;
int mon;
int num;
public Cus(int size,int mon,int num){
this.size=size;
this.mon=mon;
this.num=num;
}
@Override
public int compareTo(Cus o){
if(this.mon!=o.mon){
return this.mon-o.mon;}
else{
return o.size-this.size;
}
}
}
static class Man implements Comparable<Man>{
long num ;
// int cum;
long size;
public Man(long size,long num){
this.num=num;
// this.cum=cum;
this.size=size;
}
@Override
public int compareTo(Man o){
return (int)this.size-(int)o.size;
}
}
static class Table1 implements Comparable<Table1>{
int go;
//int cum;
int cost;
public Table1(int go,int cost){
this.go=go;
// this.cum=cum;
this.cost=cost;
}
@Override
public int compareTo(Table1 o){
return this.cost-o.cost;
}}
public static class DisjointSet{
HashMap<Integer,Node> mp= new HashMap<>();
public static class Node{
int data;
Node parent;
int rank;
}
public void create(int val){
Node nn= new Node();
nn.data=val;
nn.parent=nn;
nn.rank=0;
mp.put(val,nn);
}
public int find(int val){
return findn(mp.get(val)).data;
}
public Node findn(Node n){
if(n==n.parent){
return n;
}
Node rr= findn(n.parent);
n.parent=rr;
return rr;
}
public void union(int val1, int val2){ // can also be used to check cycles
Node n1= findn(mp.get(val1));
Node n2= findn(mp.get(val2));
if(n1.data==n2.data) {
return;
}
if(n1.rank<n2.rank){
n1.parent=n2;
}
else if(n2.rank<n1.rank){
n2.parent=n1;
}
else {
n2.parent=n1;
n1.rank++;
}
}
}
public static void main(String[] args) throws IOException {
Reader.init(System.in);
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
int n= Reader.nextInt();
long sum=0;
long arr[]= new long[n];
long max=0;
for (int i = 0; i <n ; i++) {
arr[i]= Reader.nextLong();
sum+=arr[i];
max= Math.max(max,arr[i]);
}
long min=max;
long maxi= (long)10000000000000.0;
while(maxi-min>1){
long mid= min+(maxi-min)/2;
// System.out.print("min="+min);
// System.out.print(" mid="+mid);
// System.out.println(" max="+maxi);
if(n*mid-sum>=mid){
maxi=mid;
}
else {
min=mid;
}
}
if(n*min-sum>=min){
System.out.println(min);
}
else{
System.out.println(min+1);
}
}
static long power( long x, long y, long p)
{
// Initialize result
long res = 1;
// Update x if it is more
// than or equal to p
x = x % p;
if (x == 0) return 0; // In case x is divisible by p;
while (y > 0)
{
// If y is odd, multiply x
// with result
if((y & 1)==1)
res = (res * x) % p;
// y must be even now
// y = y / 2
y = y >> 1;
x = (x * x) % p;
}
return res;
}
public static long ceil_div(long a, long b){
return (a+b-1)/b;
}
static int countDivisibles(int A, int B, int M)
{
// Add 1 explicitly as A is divisible by M
if (A % M == 0)
return (B / M) - (A / M) + 1;
// A is not divisible by M
return (B / M) - (A / M);
}
public static void df(int x, int y,int n, int m, char[][]ar, int l){
boolean done[][]= new boolean[n][m];
int count=0;
LinkedList<int[]> stk= new LinkedList<>();
int a[]= {x,y};
stk.addFirst(a);
while(!stk.isEmpty() && count<l){
// count++;
int b[]=stk.removeFirst();
if( done[b[0]][b[1]]){
continue;
}
count++;
done[b[0]][b[1]]=true;
ar[b[0]][b[1]]='@';
int arr[][]={{1,0},{-1,0},{0,1},{0,-1}};
for (int i = 0; i <arr.length ; i++) {
if(!(b[0]+arr[i][0]>=n || b[1]+arr[i][1]>=m || b[0]+arr[i][0]<0 || b[1]+arr[i][1]<0 || ar[b[0]+arr[i][0]][b[1]+arr[i][1]]=='#')){
int r[]= {b[0]+arr[i][0], b[1]+arr[i][1]};
stk.addFirst(r);
// continue;
}
}}
for (int i = 0; i <n ; i++) {
for (int j = 0; j <m ; j++) {
if(ar[i][j]=='.'){
System.out.print('X');
}
else if(ar[i][j]=='@'){
System.out.print('.');
}
else{
System.out.print(ar[i][j]);
}
}
System.out.println();
}
}
static long gcd(long a, long b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
static long gcd1(long a, long b)
{
// Everything divides 0
if (a == 0)
return b;
if (b == 0)
return a;
// base case
if (a == b)
return a;
// a is greater
//count++;
if (a > b){
return gcd(a-b, b);
}
return gcd(a, b-a);
}
// method to return LCM of two numbers
static long lcm(long a, long b)
{
return (a*b)/gcd(a, b);
}
// Driver method
static int partition(long arr[],long arr1[], int low, int high)
{
long pivot = arr[high];
int i = (low-1); // index of smaller element
for (int j=low; j<high; j++)
{
// If current element is smaller than the pivot
if (arr[j] < pivot)
{
i++;
// swap arr[i] and arr[j]
long temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
long temp1=arr1[i];
arr1[i]=arr1[j];
arr1[j]=temp1;
}
}
// swap arr[i+1] and arr[high] (or pivot)
long temp = arr[i+1];
arr[i+1] = arr[high];
arr[high] = temp;
long temp1= arr1[i+1];
arr1[i+1]=arr1[high];
arr1[high]= temp1;
return i+1;
}
/* The main function that implements QuickSort()
arr[] --> Array to be sorted,
low --> Starting index,
high --> Ending index */
static void sort(long arr[],long arr1[], int low, int high)
{
if (low < high)
{
/* pi is partitioning index, arr[pi] is
now at right place */
int pi = partition(arr,arr1, low, high);
// Recursively sort elements before
// partition and after partition
sort(arr,arr1, low, pi-1);
sort(arr,arr1, pi+1, high);
}
}
public static ArrayList<Integer> Sieve(int n) {
boolean arr[]= new boolean [n+1];
Arrays.fill(arr,true);
arr[0]=false;
arr[1]=false;
for (int i = 2; i*i <=n ; i++) {
if(arr[i]){
for (int j = 2; j <=n/i ; j++) {
int u= i*j;
arr[u]=false;
}}
}
ArrayList<Integer> ans= new ArrayList<>();
for (int i = 0; i <n+1 ; i++) {
if(arr[i]){
ans.add(i);
}
}
return ans;
}
} | Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 8 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | 5e7314d4ed52756d430077b1171c02a0 | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes | import java.util.*;
import java.io.*;
public class C
{
Reader in;
PrintWriter out;
int i = 0, j = 0;
void solve()
{
//START//
long n = in.nextInt();
long sum = 0;
long high = 0;
for (i = 0; i < n; i++)
{
long cur = in.nextLong();
high = Math.max(high, cur);
sum += cur;
}
long sol = (long)Math.ceil((double)sum/(n-1));
if (sol < high)
sol = high;
out.println(sol);
//END
}
void runIO()
{
in = new Reader();
out = new PrintWriter(System.out, false);
solve();
out.close();
}
public static void main(String[] args)
{
new C().runIO();
}
// input/output
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public final String next()
{
int c = read();
while (isSpaceChar(c))
{
c = read();
}
StringBuilder res = new StringBuilder();
do
{
res.append((char) c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
private boolean isSpaceChar(int c)
{
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public int nextInt()
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong()
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble()
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.')
while ((c = read()) >= '0' && c <= '9')
ret += (c - '0') / (div *= 10);
if (neg)
return -ret;
return ret;
}
public int[] readIntArray(int size)
{
int[] arr = new int[size];
for (int i = 0; i < size; i++)
arr[i] = nextInt();
return arr;
}
public long[] readLongArray(int size)
{
long[] arr = new long[size];
for (int i = 0; i < size; i++)
arr[i] = nextInt();
return arr;
}
private void fillBuffer()
{
try
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
}
catch (IOException e)
{
}
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read()
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
}
}
| Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 8 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | e46fe22d9d460287703ecb9229d8d873 | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes | import java.util.*;
public class Main{
boolean debug=false;
int INF=1<<28;
long n,max;
long[] a;
void solve(){
Scanner sc=new Scanner(System.in);
n=sc.nextLong();
a=new long[(int)n];
max=-1L;
for(int i=0;i<n;i++){
a[i]=sc.nextLong();
if(a[i]>max)max=a[i];
}
long left=1L;
long right=10000000000L;
long ans=-1L;
while(left<right){
long m=(left+right)/2L;
boolean f1=ok(m);
boolean f2=ok(m-1L);
if(f1 && !f2){
ans=m;break;
}
if(f1 && f2){
right=m;
}else if(!f1 && !f2){
left=m+1;
}else{
int k=1/0;
}
}
System.out.println(ans);
}
boolean ok(long m){
if(m<max)return false;
long count=0;
for(int i=0;i<n;i++){
count+=m-a[i];
}
if(count>=m)return true;
return false;
}
public static void main(String[] args){
new Main().solve();
}
} | Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 8 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | 34237c51c963cd95256d5662828dc454 | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes | /*
* Remember a 7.0 student can know more than a 10.0 student.
* Grades don't determine intelligence, they test obedience.
* I Never Give Up.
*/
import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import com.sun.javafx.collections.MappingChange.Map;
import static java.lang.System.out;
import static java.util.Arrays.*;
import static java.lang.Math.*;
public class ContestMain {
private static Reader in=new Reader();
private static StringBuilder ans=new StringBuilder();
private static long MOD=1000000007;//10^9+7
private static final int N=100000; //10^5
// private static final int LIM=26;
// private static final double PI=3.1415;
// private static ArrayList<Integer> v[]=new ArrayList[N];
// private static int color[]=new int[N]; //For Graph Coloring
// private static boolean mark[]=new boolean[N];
// private static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
// private static void dfs(int node){mark[node]=true;for(int x:v[node]){if(!mark[x]){dfs(x,v);}}}
private static long powmod(long x,long n,long m){
if(n==0)return 1;
else if(n%2==0)return(powmod((x*x)%m,n/2,m));
else return (x*(powmod((x*x)%m,(n-1)/2,m)))%m;
}
// private static void shuffle(long [] arr) {
// for (int i = arr.length - 1; i >= 2; i--) {
// int x = new Random().nextInt(i - 1);
// long temp = arr[x];
// arr[x] = arr[i];
// arr[i] = temp;
// }
// }
// private static void swap(int i,int j,int ar[]){
// int temp=ar[i];
// ar[i]=ar[j];
// ar[j]=temp;
// }
// private static long gcd(long a, long b){
// if(b==0)return a;
// return gcd(b,a%b);
// }
private static Queue<node> queue=new LinkedList();
static class node{
int x,y,cost;
node(int x,int y,int c){
this.x=x;
this.y=y;
cost=c;
}
}
private static boolean check(int x,int y,int n,int m,String ar[]){
if((x>=0&&x<n)&&(y>=0&&y<m))return true;
return false;
}
private static void bfs(int sx,int sy,int dist[][],int n,int m,String ar[]){
node newnode=new node(sx,sy,0);
queue.add(newnode);
node temp;
int x,y;
boolean visited[][]=new boolean[n][m];
while(!queue.isEmpty()){
temp=queue.poll();
x=temp.x;y=temp.y;
if(check(x+1,y,n,m,ar)&&!visited[x+1][y]){
dist[x+1][y]=min(dist[x+1][y],temp.cost+1);
queue.add(new node(x+1,y,temp.cost+1));
visited[x+1][y]=true;
}
if(check(x-1,y,n,m,ar)&&!visited[x-1][y]){
dist[x-1][y]=min(dist[x-1][y],temp.cost+1);
queue.add(new node(x-1,y,temp.cost+1));
visited[x-1][y]=true;
}
if(check(x,y+1,n,m,ar)&&!visited[x][y+1]){
dist[x][y+1]=min(dist[x][y+1],temp.cost+1);
queue.add(new node(x,y+1,temp.cost+1));
visited[x][y-1]=true;
}
if(check(x,y-1,n,m,ar)&&!visited[x][y-1]){
dist[x][y-1]=min(dist[x][y-1],temp.cost+1);
queue.add(new node(x,y-1,temp.cost+1));
}
}
}
private static void init(int n,int m,int dist[][],String ar[]){
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(ar[i].charAt(j)==1)dist[i][j]=0;
else dist[i][j]=Integer.MAX_VALUE;
}
}
}
static void swap(int a[],int index1,int index2){
int temp=a[index1];
a[index1]=a[index2];
a[index2]=temp;
}
static void reverse(int a[],int start,int end){ //Start should be equal to k+1 but end should be less than end
int temp;
int temp_a[]=new int[end-start];
for(int i=0;i<temp_a.length;i++)
temp_a[i]=a[start++];
for(int i=0;i<temp_a.length;i++){
a[--end]=temp_a[i];
}
}
static int next_permutation(int ar[]){
int k=0,l=0;
int index=0;
while(index<ar.length-1){
if(ar[index]<ar[index+1])k=index;
index++;
}
int value=ar[k];
for(int i=k+1;i<ar.length;i++){
if(value<ar[i])l=i;
}
swap(ar,k,l);
if(k!=l){
reverse(ar,k+1,ar.length);
return 1;
}
else return 0;
}
static int pos(int num){
int cnt=0,x=0;
while((num&x)==0){
x=1<<cnt;
cnt++;
}
return cnt;
}
public static void main(String[] args) throws IOException{
int n=in.nextInt();
long sum=0,mx=Long.MIN_VALUE,x;
for(int i=0;i<n;i++){
x=in.nextLong();
sum+=x;
mx=max(mx,x);
}
out.println(max(mx,(long)ceil(((double)sum)/(n-1))));
// int t=in.nextInt();
// int n,cnt=1;
// long sum,mult,temp;
// while(t-->0){
// n=in.nextInt();
// sum=0;
// for(int i=1;i<=n;i++){
// mult=n-i;
// temp=1;
// mult+=i-1;
// for(int j=2;j<=n;j++){
// temp=(temp*mult--)%MOD;
// }
// sum=(sum+temp)%MOD;
// }
// out.println("Case #"+(cnt++)+": "+sum);
// }
// int t=in.nextInt(),n,m,dist[][];
// String ar[];
// while(t-->0){
// n=in.nextInt();
// m=in.nextInt();
// dist=new int[n][m];
// ar=new String[n];
// for(int i=0;i<n;i++)
// ar[i]=in.next();
// for(int i=0;i<n;i++){
// for(int j=0;j<m;j++){
// if(ar[i].charAt(j)=='1'){
// init(n,m,dist,ar);
// bfs(i,j,dist,n,m,ar);
// }
// }
// }
// for(int i=0;i<n;i++){
// for(int j=0;j<m;j++)
// out.print(dist[i][j]+" ");
// out.println();
// }
// }
}
static class Pair<T> implements Comparable<Pair>{
int l;
int r;
Pair(){
l=0;
r=0;
}
Pair(int k,int v){
l=k;
r=v;
}
@Override
public int compareTo(Pair o) {
if(o.l!=l)return (int) (l-o.l);
else return (r-o.r);
}
}
static class Reader{
BufferedReader br;
StringTokenizer st;
public Reader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
} | Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 8 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | 65f18eb0f6d8a01d337450c45939b742 | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes | import java.util.*;
import java.io.*;
//267630EY
public class Main348A
{
static PrintWriter out=new PrintWriter(System.out);
public static void main(String[] args) throws IOException
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int[] a=sc.nextIntArray(n);
long sum=0;
long max=0;
for(int i=0;i<n;i++)
{
max=Math.max(a[i],max);
sum+=(long)a[i];
}
long ans=(long)Math.ceil(sum/(double)(n-1));
ans=Math.max(ans,max);
out.println(ans);
out.flush();
}
static class Scanner
{
BufferedReader br;
StringTokenizer tk=new StringTokenizer("");
public Scanner(InputStream is)
{
br=new BufferedReader(new InputStreamReader(is));
}
public int nextInt() throws IOException
{
if(tk.hasMoreTokens())
return Integer.parseInt(tk.nextToken());
tk=new StringTokenizer(br.readLine());
return nextInt();
}
public long nextLong() throws IOException
{
if(tk.hasMoreTokens())
return Long.parseLong(tk.nextToken());
tk=new StringTokenizer(br.readLine());
return nextLong();
}
public String next() throws IOException
{
if(tk.hasMoreTokens())
return (tk.nextToken());
tk=new StringTokenizer(br.readLine());
return next();
}
public String nextLine() throws IOException
{
tk=new StringTokenizer("");
return br.readLine();
}
public double nextDouble() throws IOException
{
if(tk.hasMoreTokens())
return Double.parseDouble(tk.nextToken());
tk=new StringTokenizer(br.readLine());
return nextDouble();
}
public char nextChar() throws IOException
{
if(tk.hasMoreTokens())
return (tk.nextToken().charAt(0));
tk=new StringTokenizer(br.readLine());
return nextChar();
}
public int[] nextIntArray(int n) throws IOException
{
int a[]=new int[n];
for(int i=0;i<n;i++)
a[i]=nextInt();
return a;
}
public long[] nextLongArray(int n) throws IOException
{
long a[]=new long[n];
for(int i=0;i<n;i++)
a[i]=nextLong();
return a;
}
public int[] nextIntArrayOneBased(int n) throws IOException
{
int a[]=new int[n+1];
for(int i=1;i<=n;i++)
a[i]=nextInt();
return a;
}
public long[] nextLongArrayOneBased(int n) throws IOException
{
long a[]=new long[n+1];
for(int i=1;i<=n;i++)
a[i]=nextLong();
return a;
}
}
}
| Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 8 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | 8528ea7c55d23a796c61af613c453eb8 | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes | import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws Throwable {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] a = sc.nexIntArray();
long sum = 0 , max = a[0];
for (int i = 0; i < a.length; i++) {
sum+=1l*a[i];
max = Math.max(max, a[i]);
}
System.out.println(Math.max(max,(int) Math.ceil(1.0 * sum/(n-1))));
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(String file) throws FileNotFoundException {
br = new BufferedReader(new FileReader(file));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if (x.charAt(0) == '-') {
neg = true;
start++;
}
for (int i = start; i < x.length(); i++)
if (x.charAt(i) == '.') {
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
} else {
sb.append(x.charAt(i));
if (dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg ? -1 : 1);
}
public int[] nexIntArray() throws Throwable {
st = new StringTokenizer(br.readLine());
int[] a = new int[st.countTokens()];
for (int i = 0; i < a.length; i++)
a[i] = nextInt();
return a;
}
public boolean ready() throws IOException {
return br.ready();
}
public boolean hasNext() throws Throwable {
return br.ready() || st.hasMoreTokens();
}
}
}
| Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 8 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | ed12e5168ce1fded5984951a46981b6f | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes | import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Codeforces_BS_C349 {
public static void main(String args[]) throws FileNotFoundException {
InputReader in = new InputReader(System.in);
OutputStream outputStream = System.out;
PrintWriter out = new PrintWriter(outputStream);
StringBuilder sb = new StringBuilder();
// ----------My Code----------
int n=in.nextInt();
int arr[]=in.nextIntArray(n, 0);
long sum=0,max=-1;
for(int i=0;i<n;i++){
sum+=arr[i];
max=max(arr[i],max);
}
System.out.println(max(max,(long)Math.ceil(sum*1d/(n-1))));
// ---------------The End------------------
out.close();
}
// ---------------Extra Methods------------------
public static long pow(long x, long n, long mod) {
long res = 1;
x %= mod;
while (n > 0) {
if (n % 2 == 1) {
res = (res * x) % mod;
}
x = (x * x) % mod;
n /= 2;
}
return res;
}
public static boolean isPal(String s) {
for (int i = 0, j = s.length() - 1; i <= j; i++, j--) {
if (s.charAt(i) != s.charAt(j))
return false;
}
return true;
}
public static String rev(String s) {
StringBuilder sb = new StringBuilder(s);
sb.reverse();
return sb.toString();
}
public static long gcd(long x, long y) {
if (x % y == 0)
return y;
else
return gcd(y, x % y);
}
public static int gcd(int x, int y) {
if (x % y == 0)
return y;
else
return gcd(y, x % y);
}
public static long gcdExtended(long a, long b, long[] x) {
if (a == 0) {
x[0] = 0;
x[1] = 1;
return b;
}
long[] y = new long[2];
long gcd = gcdExtended(b % a, a, y);
x[0] = y[1] - (b / a) * y[0];
x[1] = y[0];
return gcd;
}
public static int abs(int a, int b) {
return (int) Math.abs(a - b);
}
public static long abs(long a, long b) {
return (long) Math.abs(a - b);
}
public static int max(int a, int b) {
if (a > b)
return a;
else
return b;
}
public static int min(int a, int b) {
if (a > b)
return b;
else
return a;
}
public static long max(long a, long b) {
if (a > b)
return a;
else
return b;
}
public static long min(long a, long b) {
if (a > b)
return b;
else
return a;
}
// ---------------Extra Methods------------------
public static void debug(Object... o) {
System.out.println(Arrays.deepToString(o));
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream inputstream) {
reader = new BufferedReader(new InputStreamReader(inputstream));
tokenizer = null;
}
public String nextLine() {
String fullLine = null;
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
fullLine = reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
return fullLine;
}
return fullLine;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public char nextChar() {
return next().charAt(0);
}
public long nextLong() {
return Long.parseLong(next());
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public int[] nextIntArray(int n, int f) {
if (f == 0) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
} else {
int[] arr = new int[n + 1];
for (int i = 1; i < n + 1; i++) {
arr[i] = nextInt();
}
return arr;
}
}
public long[] nextLongArray(int n, int f) {
if (f == 0) {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = nextLong();
}
return arr;
} else {
long[] arr = new long[n + 1];
for (int i = 1; i < n + 1; i++) {
arr[i] = nextLong();
}
return arr;
}
}
public double[] nextDoubleArray(int n, int f) {
if (f == 0) {
double[] arr = new double[n];
for (int i = 0; i < n; i++) {
arr[i] = nextDouble();
}
return arr;
} else {
double[] arr = new double[n + 1];
for (int i = 1; i < n + 1; i++) {
arr[i] = nextDouble();
}
return arr;
}
}
}
static class Pair implements Comparable<Pair> {
int a, b;
Pair(int a, int b) {
this.a = a;
this.b = b;
}
public int compareTo(Pair o) {
// TODO Auto-generated method stub
if (this.a != o.a)
return Integer.compare(this.a, o.a);
else
return Integer.compare(this.b, o.b);
}
public boolean equals(Object o) {
if (o instanceof Pair) {
Pair p = (Pair) o;
return p.a == a && p.b == b;
}
return false;
}
public int hashCode() {
return new Integer(a).hashCode() * 31 + new Integer(b).hashCode();
}
}
}
| Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 8 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | e0f7ed65e8d9d7bb59a031da037ff560 | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes | import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public final class MafiaCF {
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
int arr[]=new int[n];
String st[]=br.readLine().split(" ");
double sum=0;
long max=Integer.MIN_VALUE;
for(int i=0;i<n;i++){
arr[i]=Integer.parseInt(st[i]);
sum+=arr[i];
if(arr[i]>max)
max=arr[i];
}
long left=max,right= (long) (2*1e9);
long ans=0;
while (left<=right){
long mid=left+(right-left)/2;
if(helper(sum,n,mid)){
right=mid-1;
ans=mid;
}else
left=mid+1;
}
System.out.println(ans);
}
private static boolean helper(double sum, long n, long mid) {
if(mid<=n*mid-sum) return true;
return false;
}
}
| Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 8 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | 54d6e2aeb4355eff4af2c0359d618f7e | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class C202 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
int n = Integer.parseInt(br.readLine());
long sum = 0;
long max = 0;
st = new StringTokenizer(br.readLine());
for (int i = 0; i < n; i++) {
long num = Long.parseLong(st.nextToken());
sum += num;
max = Math.max(max, num);
}
System.out.println(Math.max(max, (long) Math.ceil(sum / (n - 1.0))));
}
}
| Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 8 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | 3fe504fef8dd57ae04677d3c1a45ef10 | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes | import java.util.Scanner;
public class hef {
public static boolean check(int a[],int n,long mid) {
long sum = 0;
for(int i=0;i<n;i++) {
if(a[i]>mid) {
return false;
}
sum+=mid-a[i];
}
if(sum>=mid) {
return true;
}
return false;
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int a[] = new int[n];
long sum = 0;
for(int i=0;i<n;i++)
{
a[i] = s.nextInt();
sum+=a[i];
}
long start=2,end=sum,best = 0;
while(start<=end) {
long mid = (start+end)/2;
if(check(a,n,mid)) {
//System.out.println("HEEH");
best = mid;
end = mid-1;
}
else {
start = mid+1;
}
}
System.out.println(best);
}
} | Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 8 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | 0ad58473b1ab310b13656adb128776f4 | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes |
import java.io.*;
import static java.lang.Math.max;
import static java.lang.Math.sin;
import java.util.*;
public class Kaudo {
static Reader in =new Reader();
static StringBuilder Sd=new StringBuilder();
static long ans=0,res;
static boolean B[];
static List<Integer> gr[];
public static void main(String [] args) throws IOException {
int n=in.nextInt();
int a[]=in.arr(n);
Sorting.bucketSort(a, n);
for(int i=0;i<n;i++){
res+=(long)a[i];
}
ans+=max(a[n-1],(res+(n-2))/(n-1));
System.out.println(ans);
}
static boolean prime(int n){
if(n%2==0)return false;
for(int i=3;i*i<=n;i+=2)
if(n%i==0)
return false;
return true;
}
static class Reader
{
private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public Reader() { this(System.in); }public Reader(InputStream is) { mIs = is;}
public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];}
public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;}
public String s(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();}
public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;}
public int nextInt(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;}
public double d() throws IOException {return Double.parseDouble(s()) ;}
public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; }
public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; }
public int[] arr(int n){int[] ret = new int[n];for (int i = 0; i < n; i++) {ret[i] = nextInt();}return ret;}
}
}
class node implements Comparable<node> {
int a,b;
node(int b,int a){
this.a=a;
this.b=b;
}
@Override
public int compareTo(node o) {
return b-o.b;}
}
class Sorting{
public static int[] bucketSort(int[] array, int bucketCount) {
if (bucketCount <= 0) throw new IllegalArgumentException("Invalid bucket count");
if (array.length <= 1) return array; //trivially sorted
int high = array[0];
int low = array[0];
for (int i = 1; i < array.length; i++) { //find the range of input elements
if (array[i] > high) high = array[i];
if (array[i] < low) low = array[i];
}
double interval = ((double)(high - low + 1))/bucketCount; //range of one bucket
ArrayList<Integer> buckets[] = new ArrayList[bucketCount];
for (int i = 0; i < bucketCount; i++) { //initialize buckets
buckets[i] = new ArrayList();
}
for (int i = 0; i < array.length; i++) { //partition the input array
buckets[(int)((array[i] - low)/interval)].add(array[i]);
}
int pointer = 0;
for (int i = 0; i < buckets.length; i++) {
Collections.sort(buckets[i]); //mergeSort
for (int j = 0; j < buckets[i].size(); j++) { //merge the buckets
array[pointer] = buckets[i].get(j);
pointer++;
}
}
return array;
}
}
| Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 8 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | 5a4f649372922a2afebdd8dadc2e3d7d | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes | import java.util.Scanner;
public class Mafiaa {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n=in.nextInt();
//int[] a=new int[n];
long sum=0,max=0;
for(int i=0;i<n;i++){
int x=in.nextInt();
sum+=x;
max=Math.max(max, x);
}
long ans=0;
if(sum%(n-1)==0){
ans=sum/(n-1);
}else{
ans=sum/(n-1)+1;
}
ans=Math.max(max, ans);
System.out.println(ans);
}
} | Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 8 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | 24f7f8e2df55a4eacedccec34e59b7de | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes | import java.util.*;
import java.io.*;
public class cf
{
static int n;
static int arr[];
public static void main(String[] args)
{
PrintWriter out= new PrintWriter(System.out);
Scanner sc = new Scanner(System.in);
n=sc.nextInt();
arr=new int[n];
int max=0;
long sum=0;
for(int i = 0 ;i<n;i++)
{
arr[i]=sc.nextInt();
max=Math.max(max,arr[i]);
sum+=arr[i];
}
System.out.println(Math.max(max,(long)(Math.ceil(sum*1.0/(n-1)))));
}
}
| Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 8 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | 373e08fdbefbf9bbbde88cc129c241fa | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes | import java.io.*;
import java.util.*;
public class ProblemC {
InputReader in; PrintWriter out;
void solve() {
int n = in.nextInt();
long sum = 0;
long max = 0;
for (int i = 0; i < n; i++) {
long cur = in.nextLong();
sum += cur;
if (cur > max) {
max = cur;
}
}
long ans = sum / (n - 1);
if (sum % (n - 1) != 0) {
ans++;
}
if (max > ans) {
ans = max;
}
out.println(ans);
}
class Point {
int cost;
int position;
List<Point> children = new ArrayList<Point>();
}
ProblemC(){
boolean oj = System.getProperty("ONLINE_JUDGE") != null;
try {
if (oj) {
in = new InputReader(System.in);
out = new PrintWriter(System.out);
}
else {
Writer w = new FileWriter("output.txt");
in = new InputReader(new FileReader("input.txt"));
out = new PrintWriter(w);
}
} catch(Exception e) {
throw new RuntimeException(e);
}
solve();
out.close();
}
public static void main(String[] args){
new ProblemC();
}
}
class InputReader {
private BufferedReader reader;
private StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public InputReader(FileReader fr) {
reader = new BufferedReader(fr);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
} | Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 8 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | 42faa5ddf1dc3c3b437a5618597186c4 | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes | import java.io.*;
import java.util.*;
public class Mafia
{
public static void main(String[] args) throws IOException
{
Scanner in = new Scanner(System.in);
//while(in.hasNext())
{
int n = in.nextInt();
int max, temp;
long sum=0;
int count=0;
max=0;
for (int i = 0; i < n; i++)
{
temp=in.nextInt();
max=Math.max(temp, max);
sum += temp;
}
//System.out.println(sum);
count = (int)Math.ceil(sum/((double)n-1));
if(count>=max)
System.out.println(count);
else
System.out.println(max);
}
}
} | Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 6 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | 435349247a90e04a35069ddadb3f8e10 | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
public class C349 {
public static void main(String[] args)throws Exception{
// TODO Auto-generated method stub
new C349().run();
}
int[] getArray(String line){
String[] array=line.split(" ");
int[] res=new int[array.length];
for(int i=0;i<res.length;i++)
res[i]=Integer.parseInt(array[i]);
return res;
}
void run() throws Exception{
BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
reader.readLine();
int[] numbers=getArray(reader.readLine());
System.out.println(getMin(numbers));
System.out.flush();
reader.close();
}
long getMin(int[] numbers){
long max=0;
for(int i:numbers)
max+=i;
long d=0;
long u=max;
while(u-d>1){
long mitte=(u+d)/2;
if(isPos(mitte, numbers))
u=mitte;
else
d=mitte;
}
return u;
}
boolean isPos(long needed, int[] numbers){
long sum=0;
for(int i:numbers){
sum+=(needed-i);
if(needed<i) return false;
}
return sum>=needed;
}
}
| Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 6 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | 9960ea12c7a1f7e8f5203671d59c4b0e | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.StringTokenizer;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author baha
*/
public class ProblemCMafia {
static long a[] = null;
static int n = 0;
public static void main(String[] args) throws IOException {
PrintStream out =
new PrintStream(System.out);
Scanner in = new Scanner();
n = in.nextInt();
long t = n - 1;
a = new long[n];
for (int i = 0; i < a.length; i++) {
a[i] = in.nextInt();
}
Arrays.sort(a);
// long ans1 = a[a.length - 1];
long sum = sum();
long res = 0;
long max = a[a.length - 1];
res = sum % t != 0 ? sum / t + 1 : sum / t;
System.out.println(Math.max(res, max));
}
public static long sum() {
long sum = 0;
for (int i = 0; i < a.length; i++) {
sum += a[i];
}
return sum;
}
private static class Scanner {
BufferedReader in;
StringTokenizer st;
public Scanner(BufferedReader in) {
this.in = in;
}
public Scanner() {
this.in = new BufferedReader(new InputStreamReader(System.in));
}
public String nextToken() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(in.readLine());
}
return st.nextToken();
}
public int nextInt() throws IOException, NumberFormatException {
return Integer.parseInt(nextToken());
}
public long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
public double nextDouble() throws IOException, NumberFormatException {
return Double.parseDouble(nextToken());
}
}
}
| Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 6 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | 9453e53fec065e8d13147597c17707b1 | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes | import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static boolean ok(long n, long[] num) {
long sum = 0;
for (Long x : num) {
if (n > x)
sum += (n - x);
}
if (sum >= n)
return true;
return false;
}
public static void main(String[] args) throws FileNotFoundException {
Scanner in = new Scanner(System.in);
long n = in.nextLong();
long[] nums = new long[(int) n];
for (int i = 0; i < nums.length; i++) {
nums[i] = in.nextLong();
}
// long temp=in.nextLong();
// System.out.println(temp);
// 92233720368547758
// 1000000000000000
// 1000000000000000
// 46116860684273879
// System.out.println(ok(temp, nums));
Arrays.sort(nums);
long min = nums[nums.length - 1], max = Long.MAX_VALUE / 100000;
for (int i = 0; i < 100; i++) {
long mid = (min + max) / 2;
boolean ok = ok(mid, nums);
if (ok)
max = mid;
else
min = mid + 1;
}
System.out.println(max);
}
}
| Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 6 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | 9c4e55bd8c7a03849d59fac55e50089f | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class C {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
long[] a = new long[n];
for (int i = 0; i < a.length; i++) {
a[i] = in.nextLong();
}
//do binary search
long s = 0;
long end = 10000000000l;
long rounds= -1;
while(end>=s){
long mid = (s+end)/2;
boolean c = check(mid,a);
if(c){
rounds = mid;
end = mid -1;
}else{
s = mid + 1;
}
}
System.out.println(rounds);
}
public static boolean check (long rounds, long [] a){
long sum =0;
for (int i = 0; i < a.length; i++) {
if(a[i]>rounds){
return false;
}else{
sum+=(rounds-a[i]);
}
}
if(sum<rounds){
return false;
}
return true;
}
}
| Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 6 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | 936ed3ed24f3d01d68c512feeadcf0c0 | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes | import java.util.*;
import java.io.*;
public class a {
static long mod = 1000000007;
public static void main(String[] args) throws IOException {
// Scanner input = new Scanner(new File("input.txt"));
// PrintWriter out = new PrintWriter(new File("output.txt"));
input.init(System.in);
PrintWriter out = new PrintWriter((System.out));
int n = input.nextInt();
int[] data = new int[n];
for(int i = 0; i<n; i++) data[i] = input.nextInt();
long max = 0, sum = 0;
for(int i = 0; i<n; i++)
{
sum += data[i];
max = Math.max(max, data[i]);
}
out.println(Math.max((sum+n-2)/(n-1), max));
out.close();
}
static long pow(long x, long p) {
if (p == 0)
return 1;
if ((p & 1) > 0) {
return (x * pow(x, p - 1)) % mod;
}
long sqrt = pow(x, p / 2);
return (sqrt * sqrt) % mod;
}
static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
static class input {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while (!tokenizer.hasMoreTokens()) {
// TODO add check for eof if necessary
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt(next());
}
static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
static long nextLong() throws IOException {
return Long.parseLong(next());
}
static String nextLine() throws IOException {
return reader.readLine();
}
}
}
| Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 6 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | 27035690a5935fc96993a3cefa875702 | train_000.jsonl | 1380295800 | One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? | 256 megabytes | import java.util.*;
public class B {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[] = new int[n];
long max = 0, t = 0;
for (int i = 0; i < n; i++) {
max = Math.max(max, a[i] = sc.nextInt());
t += a[i];
}
if (t % (n - 1) == 0)
System.out.println(Math.max(max, t / (n - 1)));
else
System.out.println(Math.max(max, t / (n - 1) + 1));
}
} | Java | ["3\n3 2 2", "4\n2 2 2 2"] | 2 seconds | ["4", "3"] | NoteYou don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | Java 6 | standard input | [
"implementation"
] | 09f5623c3717c9d360334500b198d8e0 | The first line contains integer n (3ββ€βnββ€β105). The second line contains n space-separated integers a1,βa2,β...,βan (1ββ€βaiββ€β109) β the i-th number in the list is the number of rounds the i-th person wants to play. | 1,600 | In a single line print a single integer β the minimum number of game rounds the friends need to let the i-th person play at least ai rounds. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | 2f2ae02d64353e9c929e553d1898bee0 | train_000.jsonl | 1271346300 | Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes P3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into n time periods [l1,βr1],β[l2,βr2],β...,β[ln,βrn]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [l1,βrn]. | 256 megabytes | import java.util.Scanner;
public class A10 {
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
int n =sc.nextInt();
int p1=sc.nextInt();
int p2=sc.nextInt();
int p3=sc.nextInt();
int t1=sc.nextInt();
int t2=sc.nextInt();
int start=0,end=0,type=1;
int l[]=new int[n];
int r[]=new int[n];
for(int i=0;i<n;i++){
l[i]=sc.nextInt();
r[i]=sc.nextInt();
}
start=l[0];
end=r[0];
long power=0;
for(int i=0;i<n;i++){
int time=end-start;
//System.out.println(time);
switch(type){
case 0:
type=1;
if(time>=t1){
time-=t1;
power+=t1*p1;
if(time>=t2){
power+=t2*p2;
time-=t2;
power+=time*p3;
}
else{
power+=time*p2;
}
}
else{
power+=time*p1;
}
start=end;
end=r[i];
i--;
break;
case 1:
type=0;
power+=time*p1;
start=end;
if(i==n-1){
break;
}
else{
i++;
}
end=l[i];
i--;
break;
}
//System.out.println("power "+power);
}
System.out.println(power);
}
} | Java | ["1 3 2 1 5 10\n0 10", "2 8 4 2 5 10\n20 30\n50 100"] | 1 second | ["30", "570"] | null | Java 8 | standard input | [
"implementation"
] | 7ed9265b56ef6244f95a7a663f7860dd | The first line contains 6 integer numbers n, P1, P2, P3, T1, T2 (1ββ€βnββ€β100,β0ββ€βP1,βP2,βP3ββ€β100,β1ββ€βT1,βT2ββ€β60). The following n lines contain description of Tom's work. Each i-th of these lines contains two space-separated integers li and ri (0ββ€βliβ<βriββ€β1440, riβ<βliβ+β1 for iβ<βn), which stand for the start and the end of the i-th period of work. | 900 | Output the answer to the problem. | standard output | |
PASSED | 63b89678628447a213fe57fbde67f6f9 | train_000.jsonl | 1271346300 | Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes P3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into n time periods [l1,βr1],β[l2,βr2],β...,β[ln,βrn]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [l1,βrn]. | 256 megabytes | import java.util.*;
public class Trying
{
public static void main (String[] args)
{
Scanner enter = new Scanner(System.in);
int n = enter.nextInt(), p1 = enter.nextInt(),
p2 = enter.nextInt(), p3 = enter.nextInt(), fornow = 0,
t1 = enter.nextInt(), t2 = enter.nextInt(), total = 0,
intervals[][] = new int [n][2], between [] = new int [n-1];
for(int i = 0 ; i < n ; i++)
{
for(int j = 0 ; j < 2 ; j++)
intervals[i][j] = enter.nextInt();
total += (intervals[i][1] - intervals[i][0])*p1;
}
for(int i = 0 ; i < n-1 ; i++)
{
fornow = intervals[i+1][0] - intervals[i][1];
if(fornow > t1)
{
total += t1*p1;
fornow -= t1;
}
else
{
total += fornow*p1;
continue;
}
if(fornow > t2)
{
total += t2*p2;
fornow -= t2;
}
else
{
total += fornow*p2;
continue;
}
total += fornow * p3;
}
System.out.println(total);
}
} | Java | ["1 3 2 1 5 10\n0 10", "2 8 4 2 5 10\n20 30\n50 100"] | 1 second | ["30", "570"] | null | Java 8 | standard input | [
"implementation"
] | 7ed9265b56ef6244f95a7a663f7860dd | The first line contains 6 integer numbers n, P1, P2, P3, T1, T2 (1ββ€βnββ€β100,β0ββ€βP1,βP2,βP3ββ€β100,β1ββ€βT1,βT2ββ€β60). The following n lines contain description of Tom's work. Each i-th of these lines contains two space-separated integers li and ri (0ββ€βliβ<βriββ€β1440, riβ<βliβ+β1 for iβ<βn), which stand for the start and the end of the i-th period of work. | 900 | Output the answer to the problem. | standard output | |
PASSED | 80348f7a17945366efde342cbde5b9e4 | train_000.jsonl | 1271346300 | Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes P3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into n time periods [l1,βr1],β[l2,βr2],β...,β[ln,βrn]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [l1,βrn]. | 256 megabytes | import java.io.*;
/**
*
* @author SYSTEM
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String ch =br.readLine();
int testCase = Integer.parseInt( ch.substring(0,ch.indexOf(" ")));
ch=ch.substring(ch.indexOf(" ")+1);
int []l=new int[testCase];
int []r=new int[testCase];
int usage = 0;
int diff =0;
int p1,p2,p3,ss,sl;
p1=Integer.parseInt( ch.substring(0,ch.indexOf(" ")));
ch=ch.substring(ch.indexOf(" ")+1);
p2=Integer.parseInt( ch.substring(0,ch.indexOf(" ")));
ch=ch.substring(ch.indexOf(" ")+1);
p3=Integer.parseInt( ch.substring(0,ch.indexOf(" ")));
ch=ch.substring(ch.indexOf(" ")+1);
ss=Integer.parseInt( ch.substring(0,ch.indexOf(" ")));
ch=ch.substring(ch.indexOf(" ")+1);
sl=Integer.parseInt( ch.substring(0));
for (int i=0;i<testCase;i++){
ch=br.readLine();
l[i]=Integer.parseInt( ch.substring(0,ch.indexOf(" ")));
ch=ch.substring(ch.indexOf(" ")+1);
r[i]=Integer.parseInt( ch.substring(0));
usage+=(r[i]-l[i])*p1;
if (i>0 && i<(testCase)){
diff=l[i]-r[i-1];
if( diff >ss )
{
usage+=ss*p1;
diff-=ss;
if(diff>sl){
usage+=sl*p2;
diff-=sl;
if(diff>0){
usage+=diff*p3;
}
}
else {
usage+=diff*p2;
}
}
else{
usage+=diff*p1;
}
}
}
System.out.println(usage);
}catch(Exception ex){
}
}
} | Java | ["1 3 2 1 5 10\n0 10", "2 8 4 2 5 10\n20 30\n50 100"] | 1 second | ["30", "570"] | null | Java 8 | standard input | [
"implementation"
] | 7ed9265b56ef6244f95a7a663f7860dd | The first line contains 6 integer numbers n, P1, P2, P3, T1, T2 (1ββ€βnββ€β100,β0ββ€βP1,βP2,βP3ββ€β100,β1ββ€βT1,βT2ββ€β60). The following n lines contain description of Tom's work. Each i-th of these lines contains two space-separated integers li and ri (0ββ€βliβ<βriββ€β1440, riβ<βliβ+β1 for iβ<βn), which stand for the start and the end of the i-th period of work. | 900 | Output the answer to the problem. | standard output | |
PASSED | 7690fda92abc176e73b133bc028a2992 | train_000.jsonl | 1271346300 | Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes P3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into n time periods [l1,βr1],β[l2,βr2],β...,β[ln,βrn]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [l1,βrn]. | 256 megabytes | import java.util.Scanner;
public class Ishu
{
public static void main(String[] args)
{
Scanner scan=new Scanner(System.in);
int n,P1,P2,P3,T1,T2,i,time,sum=0;
int[][] inter=new int[2][100];
n=scan.nextInt();
P1=scan.nextInt();
P2=scan.nextInt();
P3=scan.nextInt(); //28864
T1=scan.nextInt();
T2=scan.nextInt();
for(i=0;i<n;++i)
{
inter[0][i]=scan.nextInt();
inter[1][i]=scan.nextInt();
sum+=(inter[1][i]-inter[0][i])*P1;
}
for(i=1;i<n;++i)
{
time=inter[0][i]-inter[1][i-1];
if(time<=T1)
sum+=time*P1;
else if(time>T1&&time<=(T1+T2))
{
time-=T1;
sum+=T1*P1;
sum+=time*P2;
}
else if(time>(T1+T2))
{
time-=(T1+T2);
sum+=T1*P1;
sum+=T2*P2;
sum+=time*P3;
}
}
System.out.println(sum);
}
} | Java | ["1 3 2 1 5 10\n0 10", "2 8 4 2 5 10\n20 30\n50 100"] | 1 second | ["30", "570"] | null | Java 8 | standard input | [
"implementation"
] | 7ed9265b56ef6244f95a7a663f7860dd | The first line contains 6 integer numbers n, P1, P2, P3, T1, T2 (1ββ€βnββ€β100,β0ββ€βP1,βP2,βP3ββ€β100,β1ββ€βT1,βT2ββ€β60). The following n lines contain description of Tom's work. Each i-th of these lines contains two space-separated integers li and ri (0ββ€βliβ<βriββ€β1440, riβ<βliβ+β1 for iβ<βn), which stand for the start and the end of the i-th period of work. | 900 | Output the answer to the problem. | standard output | |
PASSED | 27988ea36681841d10d654b8cc64d3fa | train_000.jsonl | 1271346300 | Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes P3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into n time periods [l1,βr1],β[l2,βr2],β...,β[ln,βrn]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [l1,βrn]. | 256 megabytes | import java.io.*;
import java.util.*;
public class A {
public static void solution(BufferedReader reader, PrintWriter out)
throws IOException {
In in = new In(reader);
int n = in.nextInt();
int p1 = in.nextInt(), p2 = in.nextInt(), p3 = in.nextInt();
int t1 = in.nextInt(), t2 = in.nextInt();
int total = 0, pre = 0;
for (int i = 0; i < n; i++) {
int a = in.nextInt(), b = in.nextInt();
total += (b - a) * p1;
if (i > 0) {
int seg = a - pre;
int s1 = Math.min(seg, t1);
total += s1 * p1;
seg -= s1;
int s2 = Math.min(seg, t2);
total += s2 * p2;
seg -= s2;
total += seg * p3;
}
pre = b;
}
out.println(total);
}
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(
new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(
new BufferedWriter(new OutputStreamWriter(System.out)));
solution(reader, out);
out.close();
}
protected static class In {
private BufferedReader reader;
private StringTokenizer tokenizer = new StringTokenizer("");
public In(BufferedReader reader) {
this.reader = reader;
}
public String next() throws IOException {
while (!tokenizer.hasMoreTokens())
tokenizer = new StringTokenizer(reader.readLine());
return tokenizer.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
}
}
| Java | ["1 3 2 1 5 10\n0 10", "2 8 4 2 5 10\n20 30\n50 100"] | 1 second | ["30", "570"] | null | Java 8 | standard input | [
"implementation"
] | 7ed9265b56ef6244f95a7a663f7860dd | The first line contains 6 integer numbers n, P1, P2, P3, T1, T2 (1ββ€βnββ€β100,β0ββ€βP1,βP2,βP3ββ€β100,β1ββ€βT1,βT2ββ€β60). The following n lines contain description of Tom's work. Each i-th of these lines contains two space-separated integers li and ri (0ββ€βliβ<βriββ€β1440, riβ<βliβ+β1 for iβ<βn), which stand for the start and the end of the i-th period of work. | 900 | Output the answer to the problem. | standard output | |
PASSED | 75a418339c8637cd879382ac3651dd87 | train_000.jsonl | 1271346300 | Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes P3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into n time periods [l1,βr1],β[l2,βr2],β...,β[ln,βrn]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [l1,βrn]. | 256 megabytes | import java.util.Scanner;
public class Test {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int p1 = in.nextInt();
int p2 = in.nextInt();
int p3 = in.nextInt();
int t1 = in.nextInt();
int t2 = in.nextInt();
int ans = 0;
int l[] = new int[2*n+1];
l[0] = 0;
for(int i=1;i<=n;i++){
l[2*i-1] = in.nextInt();
l[2*i] = in.nextInt();
}
for(int i=0;i<l.length-1;i+=2){
ans = ans+p1*Math.min(t1,l[i+1]-l[i])+p2*Math.max(0,Math.min(t2,l[i+1]-l[i]-t1))+p3*Math.max(0,l[i+1]-l[i]-t1-t2);
ans = ans+p1*(l[i+2]-l[i+1]);
}
ans = ans-(p1*Math.min(t1,l[1]-l[0])+p2*Math.max(0,Math.min(t2,l[1]-l[0]-t1))+p3*Math.max(0,l[1]-l[0]-t1-t2));
System.out.println(ans);
}
}
| Java | ["1 3 2 1 5 10\n0 10", "2 8 4 2 5 10\n20 30\n50 100"] | 1 second | ["30", "570"] | null | Java 8 | standard input | [
"implementation"
] | 7ed9265b56ef6244f95a7a663f7860dd | The first line contains 6 integer numbers n, P1, P2, P3, T1, T2 (1ββ€βnββ€β100,β0ββ€βP1,βP2,βP3ββ€β100,β1ββ€βT1,βT2ββ€β60). The following n lines contain description of Tom's work. Each i-th of these lines contains two space-separated integers li and ri (0ββ€βliβ<βriββ€β1440, riβ<βliβ+β1 for iβ<βn), which stand for the start and the end of the i-th period of work. | 900 | Output the answer to the problem. | standard output | |
PASSED | 3e6c92c3f92c3e69498adc211691196c | train_000.jsonl | 1271346300 | Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes P3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into n time periods [l1,βr1],β[l2,βr2],β...,β[ln,βrn]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [l1,βrn]. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.Scanner;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author captainTurtle
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
static class TaskA {
public void solve(int testNumber, Scanner in, PrintWriter out) {
int n = in.nextInt();
int p1 = in.nextInt();
int p2 = in.nextInt();
int p3 = in.nextInt();
int t1 = in.nextInt();
int t2 = in.nextInt();
int l[] = new int[n];
int r[] = new int[n];
int value = 0;
for (int i = 0; i < n; i++) {
l[i] = in.nextInt();
r[i] = in.nextInt();
}
for (int i = 0; i < n; i++) {
value += p1 * (r[i] - l[i]);
}
for (int i = 1; i < n; i++) {
int time = l[i] - r[i - 1];
for (int j = 0; j < time; j++) {
if (j < t1) {
value += p1;
} else if (j < t1 + t2) {
value += p2;
} else {
value += p3;
}
}
}
System.out.print(value);
}
}
}
| Java | ["1 3 2 1 5 10\n0 10", "2 8 4 2 5 10\n20 30\n50 100"] | 1 second | ["30", "570"] | null | Java 8 | standard input | [
"implementation"
] | 7ed9265b56ef6244f95a7a663f7860dd | The first line contains 6 integer numbers n, P1, P2, P3, T1, T2 (1ββ€βnββ€β100,β0ββ€βP1,βP2,βP3ββ€β100,β1ββ€βT1,βT2ββ€β60). The following n lines contain description of Tom's work. Each i-th of these lines contains two space-separated integers li and ri (0ββ€βliβ<βriββ€β1440, riβ<βliβ+β1 for iβ<βn), which stand for the start and the end of the i-th period of work. | 900 | Output the answer to the problem. | standard output | |
PASSED | 48ca5273902ec18185980165b39cd0d7 | train_000.jsonl | 1271346300 | Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes P3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into n time periods [l1,βr1],β[l2,βr2],β...,β[ln,βrn]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [l1,βrn]. | 256 megabytes | import java.util.Scanner;
public class A {
private static class Work {
private int l, r;
public Work(int l, int r) {
this.l = l;
this.r = r;
}
public int getL() {
return l;
}
public int getR() {
return r;
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n, p1, p2, p3, t1, t2;
n = in.nextInt();
p1 = in.nextInt();
p2 = in.nextInt();
p3 = in.nextInt();
t1 = in.nextInt();
t2 = in.nextInt();
Work[] works = new Work[n];
int l, r;
for (int i = 0; i < n; i++) {
l = in.nextInt();
r = in.nextInt();
works[i] = new Work(l, r);
}
int last = 0;
int res = 0;
for (int i = 0; i < n; i++) {
if (i == 0) {
last = works[i].getR();
res += (works[i].getR() - works[i].getL()) * p1;
continue;
}
int diff = works[i].getL() - last;
if (diff > t1) {
diff -= t1;
res += p1 * t1;
if (diff > t2) {
diff -= t2;
res += p2 * t2;
res += diff * p3;
} else
res += diff * p2;
} else
res += diff * p1;
res += (works[i].getR() - works[i].getL()) * p1;
last = works[i].getR();
}
System.out.println(res);
}
}
| Java | ["1 3 2 1 5 10\n0 10", "2 8 4 2 5 10\n20 30\n50 100"] | 1 second | ["30", "570"] | null | Java 8 | standard input | [
"implementation"
] | 7ed9265b56ef6244f95a7a663f7860dd | The first line contains 6 integer numbers n, P1, P2, P3, T1, T2 (1ββ€βnββ€β100,β0ββ€βP1,βP2,βP3ββ€β100,β1ββ€βT1,βT2ββ€β60). The following n lines contain description of Tom's work. Each i-th of these lines contains two space-separated integers li and ri (0ββ€βliβ<βriββ€β1440, riβ<βliβ+β1 for iβ<βn), which stand for the start and the end of the i-th period of work. | 900 | Output the answer to the problem. | standard output | |
PASSED | ce5b0ae365636f61997c05dc33af45ba | train_000.jsonl | 1271346300 | Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes P3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into n time periods [l1,βr1],β[l2,βr2],β...,β[ln,βrn]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [l1,βrn]. | 256 megabytes | import java.util.*;
import java.io.*;
public class a {
static long mod = 1000000000l;
public static void main(String[] args) throws IOException
{
input.init(System.in);
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
int n = input.nextInt(), p1 = input.nextInt(), p2 = input.nextInt(), p3 = input.nextInt(), t1 = input.nextInt(), t2 = input.nextInt();
int[] ls = new int[n], rs = new int[n];
for(int i = 0; i<n; i++) {
ls[i] = input.nextInt();
rs[i] = input.nextInt();
}
int i = 0, time = ls[0], res = 0;
while(i<n) {
res += p1*(rs[i]-ls[i]);
if(i<n-1)
{
int dist = ls[i+1] - rs[i];
res += p1*(Math.min(dist, t1));
dist -= Math.min(dist, t1);
res += p2*(Math.min(dist, t2));
dist -= Math.min(dist, t2);
res += dist*p3;
}
i++;
}
out.println(res);
out.close();
}
static void sort(int[] data)
{
Random r = new Random();
int n = data.length;
for(int i = 0; i<2*n; i++)
{
int a = r.nextInt(n), b = r.nextInt(n), temp = data[a];
data[a] = data[b];
data[b] = temp;
}
Arrays.sort(data);
}
static class input {
static BufferedReader reader;
static StringTokenizer tokenizer;
static void init(InputStream input) {
reader = new BufferedReader(
new InputStreamReader(input) );
tokenizer = new StringTokenizer("");
}
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
tokenizer = new StringTokenizer(
reader.readLine() );
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
static String nextLine() throws IOException {
return reader.readLine();
}
}
} | Java | ["1 3 2 1 5 10\n0 10", "2 8 4 2 5 10\n20 30\n50 100"] | 1 second | ["30", "570"] | null | Java 8 | standard input | [
"implementation"
] | 7ed9265b56ef6244f95a7a663f7860dd | The first line contains 6 integer numbers n, P1, P2, P3, T1, T2 (1ββ€βnββ€β100,β0ββ€βP1,βP2,βP3ββ€β100,β1ββ€βT1,βT2ββ€β60). The following n lines contain description of Tom's work. Each i-th of these lines contains two space-separated integers li and ri (0ββ€βliβ<βriββ€β1440, riβ<βliβ+β1 for iβ<βn), which stand for the start and the end of the i-th period of work. | 900 | Output the answer to the problem. | standard output | |
PASSED | 3a9351f68766c167af324f17691706e4 | train_000.jsonl | 1271346300 | Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes P3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into n time periods [l1,βr1],β[l2,βr2],β...,β[ln,βrn]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [l1,βrn]. | 256 megabytes | import java.io.*;
public class CF10A {
static String[] ins;
static int N, s, e;
static long ans = 0;
static int[] p = new int[3];
static int[] t = new int[2];
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
ins = br.readLine().split(" ");
N = Integer.parseInt(ins[0]);
for (int i = 1; i < 6; i++) {
if (i < 4) p[i - 1] = Integer.parseInt(ins[i]);
else t[i - 4] = Integer.parseInt(ins[i]);
}
int pre = -1, term;
for (int i = 0; i < N; i++) {
ins = br.readLine().split(" ");
s = Integer.parseInt(ins[0]);
e = Integer.parseInt(ins[1]);
if (pre < 0) pre = s;
ans += (e - s) * p[0];
term = s - pre;
if (term > t[0] + t[1]) {
ans += (term - (t[0] + t[1])) * p[2];
term = t[0] + t[1];
}
if (term > t[0]) {
ans += (term - t[0]) * p[1];
term = t[0];
}
ans += term * p[0];
pre = e;
}
bw.write(ans + "\n");
bw.flush();bw.close();
}
}
| Java | ["1 3 2 1 5 10\n0 10", "2 8 4 2 5 10\n20 30\n50 100"] | 1 second | ["30", "570"] | null | Java 8 | standard input | [
"implementation"
] | 7ed9265b56ef6244f95a7a663f7860dd | The first line contains 6 integer numbers n, P1, P2, P3, T1, T2 (1ββ€βnββ€β100,β0ββ€βP1,βP2,βP3ββ€β100,β1ββ€βT1,βT2ββ€β60). The following n lines contain description of Tom's work. Each i-th of these lines contains two space-separated integers li and ri (0ββ€βliβ<βriββ€β1440, riβ<βliβ+β1 for iβ<βn), which stand for the start and the end of the i-th period of work. | 900 | Output the answer to the problem. | standard output | |
PASSED | e86f2e308a5145ccb1d822d369e7561d | train_000.jsonl | 1271346300 | Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes P3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into n time periods [l1,βr1],β[l2,βr2],β...,β[ln,βrn]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [l1,βrn]. | 256 megabytes | import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class A {
public static void main(String[] args) throws IOException
{
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = sc.nextInt(), p[] = new int[3], l[] = new int[n], r[] = new int[n];
for(int i = 0; i < 3; ++i)
p[i] = sc.nextInt();
int t1 = sc.nextInt(), t2 = sc.nextInt();
for(int i = 0; i < n; ++i)
{
l[i] = sc.nextInt();
r[i] = sc.nextInt();
}
int mode = 0, time = l[0], end = r[n - 1] - 1, task = 0, inactive = 0, power = 0;
while(time <= end)
{
if(time >= l[task])
{
if(time < r[task])
inactive = 0;
else
{
++inactive;
++task;
}
}
else
++inactive;
if(inactive > t1 + t2)
mode = 2;
else if(inactive > t1)
mode = 1;
else
mode = 0;
power += p[mode];
++time;
}
out.println(power);
out.close();
}
static class Scanner
{
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));}
public Scanner(FileReader r){ br = new BufferedReader(r);}
public String next() throws IOException
{
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {return Integer.parseInt(next());}
public long nextLong() throws IOException {return Long.parseLong(next());}
public String nextLine() throws IOException {return br.readLine();}
public double nextDouble() throws IOException { return Double.parseDouble(next()); }
public boolean ready() throws IOException {return br.ready();}
}
} | Java | ["1 3 2 1 5 10\n0 10", "2 8 4 2 5 10\n20 30\n50 100"] | 1 second | ["30", "570"] | null | Java 8 | standard input | [
"implementation"
] | 7ed9265b56ef6244f95a7a663f7860dd | The first line contains 6 integer numbers n, P1, P2, P3, T1, T2 (1ββ€βnββ€β100,β0ββ€βP1,βP2,βP3ββ€β100,β1ββ€βT1,βT2ββ€β60). The following n lines contain description of Tom's work. Each i-th of these lines contains two space-separated integers li and ri (0ββ€βliβ<βriββ€β1440, riβ<βliβ+β1 for iβ<βn), which stand for the start and the end of the i-th period of work. | 900 | Output the answer to the problem. | standard output | |
PASSED | bb6e7ee9356709434e6dffa624601c81 | train_000.jsonl | 1271346300 | Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes P3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into n time periods [l1,βr1],β[l2,βr2],β...,β[ln,βrn]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [l1,βrn]. | 256 megabytes | import java.io.*;
import java.util.*;
public class CF {
void realSolve() {
int n = in.nextInt();
int p1 = in.nextInt();
int p2 = in.nextInt();
int p3 = in.nextInt();
int t1 = in.nextInt();
int t2 = in.nextInt();
int[] fr = new int[n];
int[] to = new int[n];
long res = 0;
for (int i = 0; i < n; i++) {
fr[i] = in.nextInt();
to[i] = in.nextInt();
res += (to[i] - fr[i]) * p1;
}
for (int i = 0; i < n - 1; i++) {
int len = fr[i + 1] - to[i];
res += p1 * Math.min(len, t1);
len -= Math.min(len, t1);
res += p2 * Math.min(len, t2);
len -= Math.min(len, t2);
res += p3 * len;
}
out.println(res);
}
private class InputReader {
StringTokenizer st;
BufferedReader br;
public InputReader(File f) {
try {
br = new BufferedReader(new FileReader(f));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public InputReader(InputStream f) {
br = new BufferedReader(new InputStreamReader(f));
}
String next() {
while (st == null || !st.hasMoreElements()) {
String s;
try {
s = br.readLine();
} catch (IOException e) {
return null;
}
if (s == null)
return null;
st = new StringTokenizer(s);
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
boolean hasMoreElements() {
while (st == null || !st.hasMoreElements()) {
String s;
try {
s = br.readLine();
} catch (IOException e) {
return false;
}
st = new StringTokenizer(s);
}
return st.hasMoreElements();
}
long nextLong() {
return Long.parseLong(next());
}
}
InputReader in;
PrintWriter out;
void solve() {
in = new InputReader(new File("object.in"));
try {
out = new PrintWriter(new File("object.out"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
realSolve();
out.close();
}
void solveIO() {
in = new InputReader(System.in);
out = new PrintWriter(System.out);
realSolve();
out.close();
}
public static void main(String[] args) {
new CF().solveIO();
}
} | Java | ["1 3 2 1 5 10\n0 10", "2 8 4 2 5 10\n20 30\n50 100"] | 1 second | ["30", "570"] | null | Java 8 | standard input | [
"implementation"
] | 7ed9265b56ef6244f95a7a663f7860dd | The first line contains 6 integer numbers n, P1, P2, P3, T1, T2 (1ββ€βnββ€β100,β0ββ€βP1,βP2,βP3ββ€β100,β1ββ€βT1,βT2ββ€β60). The following n lines contain description of Tom's work. Each i-th of these lines contains two space-separated integers li and ri (0ββ€βliβ<βriββ€β1440, riβ<βliβ+β1 for iβ<βn), which stand for the start and the end of the i-th period of work. | 900 | Output the answer to the problem. | standard output | |
PASSED | 67955f537c03aabaa6cad3d938cac4d0 | train_000.jsonl | 1271346300 | Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes P3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into n time periods [l1,βr1],β[l2,βr2],β...,β[ln,βrn]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [l1,βrn]. | 256 megabytes | //package kitsune;
import java.util.*;
public class powercon {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int p1 = s.nextInt();
int p2 = s.nextInt();
int p3 = s.nextInt();
int t1 = s.nextInt();
int t2 = s.nextInt();
int total = 0;
int[] l = new int[n];
int[] r = new int[n];
for(int i =0;i<n;i++){
l[i] = s.nextInt();
r[i] = s.nextInt();
total += (r[i]-l[i])*p1;
//System.out.printf("%s ", total);
}
int x = 0;
for(int i =0;i<n-1;i++){
x = l[i+1] - r[i];
//System.out.printf("%s ", x);
if(x >= (t2+t1)){
total += t1*p1;
//System.out.printf("%s ", total);
x -= t1;
//System.out.printf("%s ", x);
total += t2*p2;
//System.out.printf("%s ", total);
x -= t2;
//System.out.printf("%s ", x);
total += x*p3;
continue;
}
if(x > t1 && x < (t2+t1)){
total += t1*p1;
//System.out.printf("%s ", total);
//System.out.printf("%s ", x);
x -= t1;
//System.out.printf("%s ", x);
total += x*p2;
//System.out.printf("%s ", total);
continue;
}
if(x <= t1){
total += x*p1;
//System.out.printf("%s ", total);
continue;
}
if(x==0)
continue;
}
System.out.println(total);
}
}
| Java | ["1 3 2 1 5 10\n0 10", "2 8 4 2 5 10\n20 30\n50 100"] | 1 second | ["30", "570"] | null | Java 8 | standard input | [
"implementation"
] | 7ed9265b56ef6244f95a7a663f7860dd | The first line contains 6 integer numbers n, P1, P2, P3, T1, T2 (1ββ€βnββ€β100,β0ββ€βP1,βP2,βP3ββ€β100,β1ββ€βT1,βT2ββ€β60). The following n lines contain description of Tom's work. Each i-th of these lines contains two space-separated integers li and ri (0ββ€βliβ<βriββ€β1440, riβ<βliβ+β1 for iβ<βn), which stand for the start and the end of the i-th period of work. | 900 | Output the answer to the problem. | standard output | |
PASSED | f960e58e19dd83146c1941d7f48ff3b3 | train_000.jsonl | 1396798800 | Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced programmer. Actually he is not a programmer at all. So he wasn't able to solve them. That's why he asked you to help him with these tasks. One of these tasks is the following.You have an array a of length 2n and m queries on it. The i-th query is described by an integer qi. In order to perform the i-th query you must: split the array into 2nβ-βqi parts, where each part is a subarray consisting of 2qi numbers; the j-th subarray (1ββ€βjββ€β2nβ-βqi) should contain the elements a[(jβ-β1)Β·2qiβ+β1],βa[(jβ-β1)Β·2qiβ+β2],β...,βa[(jβ-β1)Β·2qiβ+β2qi]; reverse each of the subarrays; join them into a single array in the same order (this array becomes new array a); output the number of inversions in the new a. Given initial array a and all the queries. Answer all the queries. Please, note that the changes from some query is saved for further queries. | 512 megabytes | import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.InputMismatchException;
public class C414 {
static class Solver {
int N, M, Q, a[];
long inv[][], conv[];
void solve(FastScanner s, PrintWriter out) {
N = s.nextInt();
M = 1 << N;
inv = new long[N + 1][2];
a = s.nextIntArray(M);
sort(0, M - 1, N);
Q = s.nextInt();
for (int q = 1; q <= Q; q++) {
int qi = s.nextInt();
while (qi > 0) {
inv[qi][0] = inv[qi][1] ^ inv[qi][0] ^ (inv[qi][1] = inv[qi][0]);
qi--;
}
long sum = 0;
for (long[] a : inv)
sum += a[0];
out.println(sum);
}
}
void sort(int l, int r, int d) {
if (d == 0)
return;
int m = (l + r) / 2;
sort(l, m, d - 1);
sort(m + 1, r, d - 1);
// regular inversions
int p1 = l, p2 = m + 1;
while (p2 <= r && p1 <= m) {
if (a[p1] <= a[p2]) {
p1++;
continue;
}
inv[d][0] += (m - p1 + 1);
p2++;
}
p1 = l;
p2 = m + 1;
while (p1 <= m && p2 <= r) {
if (a[p2] <= a[p1]) {
p2++;
continue;
}
inv[d][1] += (r - p2 + 1);
p1++;
}
// merge
int[] sub = new int[r - l + 1];
p1 = l;
p2 = m + 1;
int i = 0;
while (p1 <= m || p2 <= r) {
if (p1 > m)
sub[i++] = a[p2++];
else if (p2 > r)
sub[i++] = a[p1++];
else if (a[p1] <= a[p2])
sub[i++] = a[p1++];
else
sub[i++] = a[p2++];
}
for (int x : sub)
a[l++] = x;
}
}
public static void main(String[] args) {
FastScanner s = new FastScanner(System.in);
PrintWriter out = new PrintWriter(System.out);
Solver solver = new Solver();
solver.solve(s, out);
out.close();
}
static int swap(int a, int b) {
return a;
}
static Object swap(Object a, Object b) {
return a;
}
static String ts(Object... o) {
return Arrays.deepToString(o);
}
static class FastScanner {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public FastScanner(InputStream stream) {
this.stream = stream;
}
public FastScanner(File f) throws FileNotFoundException {
this(new FileInputStream(f));
}
public FastScanner(String s) {
this.stream = new ByteArrayInputStream(s.getBytes(StandardCharsets.UTF_8));
}
int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
boolean isEndline(int c) {
return c == '\n' || c == '\r' || c == -1;
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String next() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public String nextLine() {
int c = read();
while (isEndline(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndline(c));
return res.toString();
}
// Jacob Garbage
public int[] nextIntArray(int N) {
int[] ret = new int[N];
for (int i = 0; i < N; i++)
ret[i] = this.nextInt();
return ret;
}
public int[][] next2DIntArray(int N, int M) {
int[][] ret = new int[N][];
for (int i = 0; i < N; i++)
ret[i] = this.nextIntArray(M);
return ret;
}
public long[] nextLongArray(int N) {
long[] ret = new long[N];
for (int i = 0; i < N; i++)
ret[i] = this.nextLong();
return ret;
}
public long[][] next2DLongArray(int N, int M) {
long[][] ret = new long[N][];
for (int i = 0; i < N; i++)
ret[i] = nextLongArray(M);
return ret;
}
public double[] nextDoubleArray(int N) {
double[] ret = new double[N];
for (int i = 0; i < N; i++)
ret[i] = this.nextDouble();
return ret;
}
public double[][] next2DDoubleArray(int N, int M) {
double[][] ret = new double[N][];
for (int i = 0; i < N; i++)
ret[i] = this.nextDoubleArray(M);
return ret;
}
}
}
| Java | ["2\n2 1 4 3\n4\n1 2 0 2", "1\n1 2\n3\n0 1 1"] | 4 seconds | ["0\n6\n6\n0", "0\n1\n0"] | NoteIf we reverse an array x[1],βx[2],β...,βx[n] it becomes new array y[1],βy[2],β...,βy[n], where y[i]β=βx[nβ-βiβ+β1] for each i.The number of inversions of an array x[1],βx[2],β...,βx[n] is the number of pairs of indices i,βj such that: iβ<βj and x[i]β>βx[j]. | Java 8 | standard input | [
"combinatorics",
"divide and conquer"
] | ea7f8bd397f80ba7d3add6f9609dcc4a | The first line of input contains a single integer nΒ (0ββ€βnββ€β20). The second line of input contains 2n space-separated integers a[1],βa[2],β...,βa[2n]Β (1ββ€βa[i]ββ€β109), the initial array. The third line of input contains a single integer mΒ (1ββ€βmββ€β106). The fourth line of input contains m space-separated integers q1,βq2,β...,βqmΒ (0ββ€βqiββ€βn), the queries. Note: since the size of the input and output could be very large, don't use slow output techniques in your language. For example, do not use input and output streams (cin, cout) in C++. | 2,100 | Output m lines. In the i-th line print the answer (the number of inversions) for the i-th query. | standard output | |
PASSED | 108146489e4de80cb3ec4be1358b7386 | train_000.jsonl | 1396798800 | Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced programmer. Actually he is not a programmer at all. So he wasn't able to solve them. That's why he asked you to help him with these tasks. One of these tasks is the following.You have an array a of length 2n and m queries on it. The i-th query is described by an integer qi. In order to perform the i-th query you must: split the array into 2nβ-βqi parts, where each part is a subarray consisting of 2qi numbers; the j-th subarray (1ββ€βjββ€β2nβ-βqi) should contain the elements a[(jβ-β1)Β·2qiβ+β1],βa[(jβ-β1)Β·2qiβ+β2],β...,βa[(jβ-β1)Β·2qiβ+β2qi]; reverse each of the subarrays; join them into a single array in the same order (this array becomes new array a); output the number of inversions in the new a. Given initial array a and all the queries. Answer all the queries. Please, note that the changes from some query is saved for further queries. | 512 megabytes | //package practice.E;
import java.io.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;
public class CF414E {
static long cur[];
static long dupl[];
static int n;
static HashMap<Integer, Integer> log;
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
log = new HashMap<>();
for (int i = 0; i <= 21; i++)
log.put(1<<i, i);
n = sc.nextInt();
int[] arr = new int[1<<n];
for (int i = 0; i < arr.length; i++)
arr[i] = sc.nextInt();
cur = new long[n+1];
dupl = new long[n+1];
mergeSort(arr, 0, arr.length-1);
// System.err.println(Arrays.toString(cur));
int m = sc.nextInt();
for (int i = 0; i < m; i++) {
int x = sc.nextInt();
for (int j = 0; j < x; j++)
cur[j] += c(j);
for (int j = n; j >= x; j--)
cur[j] += c(x);
// System.err.println(Arrays.toString(cur));
pw.println(cur[n]);
}
pw.flush();
pw.close();
}
static final int INF = Integer.MAX_VALUE;
static long mergeSort(int[] a, int b, int e)
{
if(b < e)
{
int q = (b + e) / 2;
long ret = 0;
ret += mergeSort(a, b, q);
ret += mergeSort(a, q + 1, e);
ret += merge(a, b, q, e);
long d = 0;
int cnt = 1;
for (int i = b+1; i <= e; i++) {
if(a[i] == a[i-1])
cnt++;
else {
d += 1l*cnt * (cnt - 1) / 2;
cnt = 1;
}
}
d += 1l*cnt * (cnt - 1) / 2;
dupl[log.get(e-b+1)] += d;
cur[log.get(e-b+1)]+=ret;
return ret;
}
return 0;
}
static long merge(int[] a, int b, int mid, int e)
{
long ret = 0;
int n1 = mid - b + 1;
int n2 = e - mid;
int[] L = new int[n1+1], R = new int[n2+1];
for(int i = 0; i < n1; i++) L[i] = a[b + i];
for(int i = 0; i < n2; i++) R[i] = a[mid + 1 + i];
L[n1] = R[n2] = INF;
for(int k = b, i = 0, j = 0; k <= e; k++)
if(L[i] <= R[j])
a[k] = L[i++];
else {
if(L[i] != Integer.MAX_VALUE)
ret+=(n2-i);
a[k] = R[j++];
}
return ret;
}
static long c(int x){
int p = 1<<x;
int tot = 1<<n;
return 1l*tot/p * (1l*p * (p - 1) / 2) - dupl[x] - 2*cur[x];
}
static class Scanner
{
StringTokenizer st; BufferedReader br;
public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));}
public Scanner(String s) throws FileNotFoundException { br = new BufferedReader(new FileReader(new File(s)));}
public String next() throws IOException {while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());return st.nextToken();}
public int nextInt() throws IOException {return Integer.parseInt(next());}
public long nextLong() throws IOException {return Long.parseLong(next());}
public String nextLine() throws IOException {return br.readLine();}
public boolean ready() throws IOException {return br.ready();}
}
}
| Java | ["2\n2 1 4 3\n4\n1 2 0 2", "1\n1 2\n3\n0 1 1"] | 4 seconds | ["0\n6\n6\n0", "0\n1\n0"] | NoteIf we reverse an array x[1],βx[2],β...,βx[n] it becomes new array y[1],βy[2],β...,βy[n], where y[i]β=βx[nβ-βiβ+β1] for each i.The number of inversions of an array x[1],βx[2],β...,βx[n] is the number of pairs of indices i,βj such that: iβ<βj and x[i]β>βx[j]. | Java 8 | standard input | [
"combinatorics",
"divide and conquer"
] | ea7f8bd397f80ba7d3add6f9609dcc4a | The first line of input contains a single integer nΒ (0ββ€βnββ€β20). The second line of input contains 2n space-separated integers a[1],βa[2],β...,βa[2n]Β (1ββ€βa[i]ββ€β109), the initial array. The third line of input contains a single integer mΒ (1ββ€βmββ€β106). The fourth line of input contains m space-separated integers q1,βq2,β...,βqmΒ (0ββ€βqiββ€βn), the queries. Note: since the size of the input and output could be very large, don't use slow output techniques in your language. For example, do not use input and output streams (cin, cout) in C++. | 2,100 | Output m lines. In the i-th line print the answer (the number of inversions) for the i-th query. | standard output | |
PASSED | 0afb73d708972a921c54796c7598bae2 | train_000.jsonl | 1396798800 | Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced programmer. Actually he is not a programmer at all. So he wasn't able to solve them. That's why he asked you to help him with these tasks. One of these tasks is the following.You have an array a of length 2n and m queries on it. The i-th query is described by an integer qi. In order to perform the i-th query you must: split the array into 2nβ-βqi parts, where each part is a subarray consisting of 2qi numbers; the j-th subarray (1ββ€βjββ€β2nβ-βqi) should contain the elements a[(jβ-β1)Β·2qiβ+β1],βa[(jβ-β1)Β·2qiβ+β2],β...,βa[(jβ-β1)Β·2qiβ+β2qi]; reverse each of the subarrays; join them into a single array in the same order (this array becomes new array a); output the number of inversions in the new a. Given initial array a and all the queries. Answer all the queries. Please, note that the changes from some query is saved for further queries. | 512 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.PrintWriter;
public class C414
{
static class Scanner
{
BufferedReader br;
StringTokenizer tk=new StringTokenizer("");
public Scanner(InputStream is)
{
br=new BufferedReader(new InputStreamReader(is));
}
public int nextInt() throws IOException
{
if(tk.hasMoreTokens())
return Integer.parseInt(tk.nextToken());
tk=new StringTokenizer(br.readLine());
return nextInt();
}
public long nextLong() throws IOException
{
if(tk.hasMoreTokens())
return Long.parseLong(tk.nextToken());
tk=new StringTokenizer(br.readLine());
return nextLong();
}
public String next() throws IOException
{
if(tk.hasMoreTokens())
return (tk.nextToken());
tk=new StringTokenizer(br.readLine());
return next();
}
public String nextLine() throws IOException
{
tk=new StringTokenizer("");
return br.readLine();
}
public double nextDouble() throws IOException
{
if(tk.hasMoreTokens())
return Double.parseDouble(tk.nextToken());
tk=new StringTokenizer(br.readLine());
return nextDouble();
}
public char nextChar() throws IOException
{
if(tk.hasMoreTokens())
return (tk.nextToken().charAt(0));
tk=new StringTokenizer(br.readLine());
return nextChar();
}
public int[] nextIntArray(int n) throws IOException
{
int a[]=new int[n];
for(int i=0;i<n;i++)
a[i]=nextInt();
return a;
}
public long[] nextLongArray(int n) throws IOException
{
long a[]=new long[n];
for(int i=0;i<n;i++)
a[i]=nextLong();
return a;
}
public int[] nextIntArrayOneBased(int n) throws IOException
{
int a[]=new int[n+1];
for(int i=1;i<=n;i++)
a[i]=nextInt();
return a;
}
public long[] nextLongArrayOneBased(int n) throws IOException
{
long a[]=new long[n+1];
for(int i=1;i<=n;i++)
a[i]=nextLong();
return a;
}
}
static long ans[][];
static int c[];
static void solve(int a[],int l,int r,int n)
{
if(l==r)
return;
int mid=(l+r)>>1;
solve(a,l,mid,n-1);
solve(a,mid+1,r,n-1);
int i1=mid+1,i2=l,n1=r,n2=mid,i=0;
while(i1<=n1&&i2<=n2)
{
if(a[i1]<=a[i2])
{
c[i++]=a[i1];
i1++;
}
else
{
ans[n-1][1]+=(n1-i1+1);
c[i++]=a[i2];
i2++;
}
}
i2=mid+1;i1=l;n2=r;n1=mid;i=0;
while(i1<=n1&&i2<=n2)
{
if(a[i1]<=a[i2])
{
c[i++]=a[i1];
i1++;
}
else
{
ans[n-1][0]+=(n1-i1+1);
c[i++]=a[i2];
i2++;
}
}
while(i1<=n1)
{
c[i++]=a[i1];
i1++;
}
while(i2<=n2)
{
c[i++]=a[i2];
i2++;
}
System.arraycopy(c, 0, a, l, i);
}
public static void main(String args[]) throws IOException
{
Scanner in=new Scanner(System.in);
PrintWriter out=new PrintWriter(System.out);
int n=in.nextInt();
int sz=1<<n;
int a[]=in.nextIntArray(sz);
c=new int[sz];
ans=new long[n][2];
solve(a,0,sz-1,n);
int mask=0;
int val[]=new int[n+1];
for(int i=0;i<=n;i++)
{
val[i]=(1<<i)-1;
}
int m=in.nextInt();
for(int i=0;i<m;i++)
{
int x=in.nextInt();
mask^=val[x];
long an=0;
for(int j=0;j<n;j++)
{
if(((mask&(1<<j))>0))
an+=ans[j][1];
else
an+=ans[j][0];
}
out.println(an);
}
out.close();
}
}
| Java | ["2\n2 1 4 3\n4\n1 2 0 2", "1\n1 2\n3\n0 1 1"] | 4 seconds | ["0\n6\n6\n0", "0\n1\n0"] | NoteIf we reverse an array x[1],βx[2],β...,βx[n] it becomes new array y[1],βy[2],β...,βy[n], where y[i]β=βx[nβ-βiβ+β1] for each i.The number of inversions of an array x[1],βx[2],β...,βx[n] is the number of pairs of indices i,βj such that: iβ<βj and x[i]β>βx[j]. | Java 8 | standard input | [
"combinatorics",
"divide and conquer"
] | ea7f8bd397f80ba7d3add6f9609dcc4a | The first line of input contains a single integer nΒ (0ββ€βnββ€β20). The second line of input contains 2n space-separated integers a[1],βa[2],β...,βa[2n]Β (1ββ€βa[i]ββ€β109), the initial array. The third line of input contains a single integer mΒ (1ββ€βmββ€β106). The fourth line of input contains m space-separated integers q1,βq2,β...,βqmΒ (0ββ€βqiββ€βn), the queries. Note: since the size of the input and output could be very large, don't use slow output techniques in your language. For example, do not use input and output streams (cin, cout) in C++. | 2,100 | Output m lines. In the i-th line print the answer (the number of inversions) for the i-th query. | standard output | |
PASSED | 975ad4b3a3f03ad6ac0290004c760e06 | train_000.jsonl | 1396798800 | Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced programmer. Actually he is not a programmer at all. So he wasn't able to solve them. That's why he asked you to help him with these tasks. One of these tasks is the following.You have an array a of length 2n and m queries on it. The i-th query is described by an integer qi. In order to perform the i-th query you must: split the array into 2nβ-βqi parts, where each part is a subarray consisting of 2qi numbers; the j-th subarray (1ββ€βjββ€β2nβ-βqi) should contain the elements a[(jβ-β1)Β·2qiβ+β1],βa[(jβ-β1)Β·2qiβ+β2],β...,βa[(jβ-β1)Β·2qiβ+β2qi]; reverse each of the subarrays; join them into a single array in the same order (this array becomes new array a); output the number of inversions in the new a. Given initial array a and all the queries. Answer all the queries. Please, note that the changes from some query is saved for further queries. | 512 megabytes | import java.io.*;
import java.util.*;
//I am fading.......
//read the question correctly (is y a vowel? what are the exact constraints?)
//look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)
//always declare multidimensional arrays as [2][n] not [n][2]
//it can lead to upto 2-3x diff in runtime
public class Main
{
public static void main(String[] args) throws Exception
{
int n=ni();
int[]a=nia(1<<n);
int[]c=new int[1<<n];
for(int i=0; i<(1<<n); i++)
{
c[i]=a[a.length-1-i];
}
int[]b=new int[1<<n];
long[]invers=new long[n+1];
long[]inversinvers=new long[n+1];
for(int j=1; j<=n; j++)
{
for(int i=0; i<(1<<n); i+=(1<<j))
{
for(int k=i,l=i,m=i+(1<<(j-1)); k<i+(1<<j); k++)
{
if(l==i+(1<<(j-1)))
b[k]=a[m++];
else if(m==i+(1<<j))
b[k]=a[l++];
else if(a[l]<=a[m])
b[k]=a[l++];
else
{
invers[j]+=i+(1<<(j-1))-l;
b[k]=a[m++];
}
}
}
System.arraycopy(b, 0, a, 0, 1<<n);
}
for(int j=1; j<=n; j++)
{
for(int i=0; i<(1<<n); i+=(1<<j))
{
for(int k=i,l=i,m=i+(1<<(j-1)); k<i+(1<<j); k++)
{
if(l==i+(1<<(j-1)))
b[k]=c[m++];
else if(m==i+(1<<j))
b[k]=c[l++];
else if(c[l]<=c[m])
b[k]=c[l++];
else
{
inversinvers[j]+=i+(1<<(j-1))-l;
b[k]=c[m++];
}
}
}
System.arraycopy(b, 0, c, 0, 1<<n);
}
int m=ni();
for(int k=0; k<m; k++)
{
int te=ni();
for(int i=0; i<=te; i++)
{
long tola=invers[i];
invers[i]=inversinvers[i];
inversinvers[i]=tola;
}
long lol=0;
for(long i:invers)
lol+=i;
pr(lol);
}
System.out.print(output);
}
///////////////////////////////////////////
///////////////////////////////////////////
///template from here
static class node
{
vector adj=new vector();
}
static class pair
{
int a, b;
pair(){}
pair(int c,int d){a=c;b=d;}
}
static interface combiner
{
public int combine(int a, int b);
}
static final int mod=1000000007;
static final double eps=1e-9;
static final long inf=100000000000000000L;
static Reader in=new Reader();
static StringBuilder output=new StringBuilder();
static Random rn=new Random();
static void reverse(int[]a){for(int i=0; i<a.length/2; i++){a[i]^=a[a.length-i-1];a[a.length-i-1]^=a[i];a[i]^=a[a.length-i-1];}}
static void sort(int[]a)
{
int te;
for(int i=0; i<a.length; i+=2)
{
te=rn.nextInt(a.length);
if(i!=te)
{
a[i]^=a[te];
a[te]^=a[i];
a[i]^=a[te];
}
}
Arrays.sort(a);
}
static void sort(long[]a)
{
int te;
for(int i=0; i<a.length; i+=2)
{
te=rn.nextInt(a.length);
if(i!=te)
{
a[i]^=a[te];
a[te]^=a[i];
a[i]^=a[te];
}
}
Arrays.sort(a);
}
static void sort(double[]a)
{
int te;
double te1;
for(int i=0; i<a.length; i+=2)
{
te=rn.nextInt(a.length);
if(i!=te)
{
te1=a[te];
a[te]=a[i];
a[i]=te1;
}
}
Arrays.sort(a);
}
static void sort(int[][]a)
{
Arrays.sort(a, new Comparator<int[]>()
{
public int compare(int[]a,int[]b)
{
if(a[0]>b[0])
return -1;
if(b[0]>a[0])
return 1;
return 0;
}
});
}
static void sort(pair[]a)
{
Arrays.sort(a,new Comparator<pair>()
{
@Override
public int compare(pair a,pair b)
{
if(a.a>b.a)
return 1;
if(b.a>a.a)
return -1;
return 0;
}
});
}
static int log2n(long a)
{
int te=0;
while(a>0)
{
a>>=1;
++te;
}
return te;
}
static class vector implements Iterable<Integer>
{
int a[],size;
vector(){a=new int[10];size=0;}
vector(int n){a=new int[n];size=0;}
public void add(int b){if(++size==a.length)a=Arrays.copyOf(a, 2*size);a[size-1]=b;}
public void sort(){Arrays.sort(a, 0, size);}
public void sort(int l, int r){Arrays.sort(a, l, r);}
@Override
public Iterator<Integer> iterator() {
Iterator<Integer> hola=new Iterator<Integer>()
{
int cur=0;
@Override
public boolean hasNext() {
return cur<size;
}
@Override
public Integer next() {
return a[cur++];
}
};
return hola;
}
}
//output functions////////////////
static void pr(Object a){output.append(a+"\n");}
static void pr(){output.append("\n");}
static void p(Object a){output.append(a);}
static void pra(int[]a){for(int i:a)output.append(i+" ");output.append("\n");}
static void pra(long[]a){for(long i:a)output.append(i+" ");output.append("\n");}
static void pra(String[]a){for(String i:a)output.append(i+" ");output.append("\n");}
static void pra(double[]a){for(double i:a)output.append(i+" ");output.append("\n");}
static void sop(Object a){System.out.println(a);}
static void flush(){System.out.println(output);output=new StringBuilder();}
//////////////////////////////////
//input functions/////////////////
static int ni(){return Integer.parseInt(in.next());}
static long nl(){return Long.parseLong(in.next());}
static String ns(){return in.next();}
static double nd(){return Double.parseDouble(in.next());}
static int[] nia(int n){int a[]=new int[n];for(int i=0; i<n; i++)a[i]=ni();return a;}
static int[] pnia(int n){int a[]=new int[n+1];for(int i=1; i<=n; i++)a[i]=ni();return a;}
static long[] nla(int n){long a[]=new long[n];for(int i=0; i<n; i++)a[i]=nl();return a;}
static String[] nsa(int n){String a[]=new String[n];for(int i=0; i<n; i++)a[i]=ns();return a;}
static double[] nda(int n){double a[]=new double[n];for(int i=0; i<n; i++)a[i]=nd();return a;}
//////////////////////////////////
//some utility functions
static void exit(){System.out.print(output);System.exit(0);}
static int min(int... a){int min=a[0];for(int i:a)min=Math.min(min, i);return min;}
static int max(int... a){int max=a[0];for(int i:a)max=Math.max(max, i);return max;}
static int gcd(int... a){int gcd=a[0];for(int i:a)gcd=gcd(gcd, i);return gcd;}
static long min(long... a){long min=a[0];for(long i:a)min=Math.min(min, i);return min;}
static long max(long... a){long max=a[0];for(long i:a)max=Math.max(max, i);return max;}
static long gcd(long... a){long gcd=a[0];for(long i:a)gcd=gcd(gcd, i);return gcd;}
static String pr(String a, long b){String c="";while(b>0){if(b%2==1)c=c.concat(a);a=a.concat(a);b>>=1;}return c;}
static long powm(long a, long b, long m){long an=1;long c=a;while(b>0){if(b%2==1)an=(an*c)%m;c=(c*c)%m;b>>=1;}return an;}
static int gcd(int a, int b){if(b==0)return a;return gcd(b, a%b);}
static long gcd(long a, long b){if(b==0)return a;return gcd(b, a%b);}
static class Reader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public Reader() {
reader = new BufferedReader(new InputStreamReader(System.in), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
}
} | Java | ["2\n2 1 4 3\n4\n1 2 0 2", "1\n1 2\n3\n0 1 1"] | 4 seconds | ["0\n6\n6\n0", "0\n1\n0"] | NoteIf we reverse an array x[1],βx[2],β...,βx[n] it becomes new array y[1],βy[2],β...,βy[n], where y[i]β=βx[nβ-βiβ+β1] for each i.The number of inversions of an array x[1],βx[2],β...,βx[n] is the number of pairs of indices i,βj such that: iβ<βj and x[i]β>βx[j]. | Java 8 | standard input | [
"combinatorics",
"divide and conquer"
] | ea7f8bd397f80ba7d3add6f9609dcc4a | The first line of input contains a single integer nΒ (0ββ€βnββ€β20). The second line of input contains 2n space-separated integers a[1],βa[2],β...,βa[2n]Β (1ββ€βa[i]ββ€β109), the initial array. The third line of input contains a single integer mΒ (1ββ€βmββ€β106). The fourth line of input contains m space-separated integers q1,βq2,β...,βqmΒ (0ββ€βqiββ€βn), the queries. Note: since the size of the input and output could be very large, don't use slow output techniques in your language. For example, do not use input and output streams (cin, cout) in C++. | 2,100 | Output m lines. In the i-th line print the answer (the number of inversions) for the i-th query. | standard output | |
PASSED | 803ee47db4e0ffb3030632b9a492cc73 | train_000.jsonl | 1396798800 | Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced programmer. Actually he is not a programmer at all. So he wasn't able to solve them. That's why he asked you to help him with these tasks. One of these tasks is the following.You have an array a of length 2n and m queries on it. The i-th query is described by an integer qi. In order to perform the i-th query you must: split the array into 2nβ-βqi parts, where each part is a subarray consisting of 2qi numbers; the j-th subarray (1ββ€βjββ€β2nβ-βqi) should contain the elements a[(jβ-β1)Β·2qiβ+β1],βa[(jβ-β1)Β·2qiβ+β2],β...,βa[(jβ-β1)Β·2qiβ+β2qi]; reverse each of the subarrays; join them into a single array in the same order (this array becomes new array a); output the number of inversions in the new a. Given initial array a and all the queries. Answer all the queries. Please, note that the changes from some query is saved for further queries. | 512 megabytes | import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;
public class Main {
int n,a[];
long dp[][],seg[];
void m(ArrayList<Integer> al,ArrayList<Integer> al1,ArrayList<Integer> al2,int l,int node){
int sz1=al1.size(),sz2=al2.size();
int p1=0,p2=0;long v=0,ci=0,common=0;
while(p1!=sz1&&p2!=sz2){
int v1=al1.get(p1),v2=al2.get(p2);
if(v1>v2){
++v;al.add(v2);++p2;
}else if(v1<=v2){
ci+=v;al.add(v1);++p1;
}
}
while(p1!=sz1){
int v1=al1.get(p1);
ci+=v;al.add(v1);++p1;
}
while(p2!=sz2){
int v2=al2.get(p2);
al.add(v2);++p2;
}
seg[node]=seg[2*node+1]+seg[2*node+2]+ci;
int pvt=-1;long c=1;
for(int i=0;i<l;i++){
int e=al.get(i);
if(e==pvt){
c++;
}else{
common+=c*(c-1)/2;c=1;pvt=e;
}
}common+=c*(c-1)/2;
int t=(int)(Math.log(l)/Math.log(2));
dp[t][1]+=seg[node];
dp[t][2]+=common;
}
ArrayList<Integer> make(int n,int l,int r){
ArrayList<Integer> al=new ArrayList<>();
if(l==r){
al.add(a[l]);return al;
}
int m=(l+r)>>1;
ArrayList<Integer> al1=make(2*n+1,l,m);
ArrayList<Integer> al2=make(2*n+2,m+1,r);
m(al,al1,al2,r-l+1,n);
al1.clear();al2.clear();
// System.out.println(al);
return al;
}
void submit() {
n=nextInt();
int sz=1<<n;
a=new int[sz];
for(int i=0;i<sz;i++)a[i]=nextInt();
dp=new long[n+1][3];
long m=1;
for(int i=n;i>0;i--){
long v=(1<<i);
dp[i][0]=m*v*(v-1)/2;
m*=2;
}
seg=new long[4*sz];
make(0,0,sz-1);
long ans=dp[n][1];
// System.out.println(ans);
//for(int i=0;i<=n;i++)System.out.println(dp[i][0]+" "+dp[i][1]+" "+dp[i][2]);
int q=nextInt();
while(q-->0){
int t=nextInt();
long np=dp[t][0]-dp[t][1]-dp[t][2];
ans=ans-dp[t][1]+np;
for(int i=t+1;i<=n;i++){
dp[i][1]=dp[i][1]-dp[t][1]+np;
}
for(int i=t-1;i>=0;i--){
dp[i][1]=dp[i][0]-dp[i][1]-dp[i][2];
}
dp[t][1]=np;
out.println(ans);
}
}
/*
2
1 3 2 4
4
1 2 0 2
*/
void stress() {
for (int tst = 0;; tst++) {
if (false) {
throw new AssertionError();
}
System.err.println(tst);
}
}
Main() throws IOException {
is = System.in;
out = new PrintWriter(System.out);
submit();
// stress();
// test();
out.close();
}
static final Random rng = new Random();
static final int C = 5;
static int rand(int l, int r) {
return l + rng.nextInt(r - l + 1);
}
public static void main(String[] args) throws IOException {
new Main();
}
private InputStream is;
PrintWriter out;
private byte[] buf = new byte[1 << 14];
private int bufSz = 0, bufPtr = 0;
private int readByte() {
if (bufSz == -1)
throw new RuntimeException("Reading past EOF");
if (bufPtr >= bufSz) {
bufPtr = 0;
try {
bufSz = is.read(buf);
} catch (IOException e) {
throw new RuntimeException(e);
}
if (bufSz <= 0)
return -1;
}
return buf[bufPtr++];
}
private boolean isTrash(int c) {
return c < 33 || c > 126;
}
private int skip() {
int b;
while ((b = readByte()) != -1 && isTrash(b))
;
return b;
}
String nextToken() {
int b = skip();
StringBuilder sb = new StringBuilder();
while (!isTrash(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
String nextString() {
int b = readByte();
StringBuilder sb = new StringBuilder();
while (!isTrash(b) || b == ' ') {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
double nextDouble() {
return Double.parseDouble(nextToken());
}
char nextChar() {
return (char) skip();
}
int nextInt() {
int ret = 0;
int b = skip();
if (b != '-' && (b < '0' || b > '9')) {
throw new InputMismatchException();
}
boolean neg = false;
if (b == '-') {
neg = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
ret = ret * 10 + (b - '0');
} else {
if (b != -1 && !isTrash(b)) {
throw new InputMismatchException();
}
return neg ? -ret : ret;
}
b = readByte();
}
}
long nextLong() {
long ret = 0;
int b = skip();
if (b != '-' && (b < '0' || b > '9')) {
throw new InputMismatchException();
}
boolean neg = false;
if (b == '-') {
neg = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
ret = ret * 10 + (b - '0');
} else {
if (b != -1 && !isTrash(b)) {
throw new InputMismatchException();
}
return neg ? -ret : ret;
}
b = readByte();
}
}
} | Java | ["2\n2 1 4 3\n4\n1 2 0 2", "1\n1 2\n3\n0 1 1"] | 4 seconds | ["0\n6\n6\n0", "0\n1\n0"] | NoteIf we reverse an array x[1],βx[2],β...,βx[n] it becomes new array y[1],βy[2],β...,βy[n], where y[i]β=βx[nβ-βiβ+β1] for each i.The number of inversions of an array x[1],βx[2],β...,βx[n] is the number of pairs of indices i,βj such that: iβ<βj and x[i]β>βx[j]. | Java 8 | standard input | [
"combinatorics",
"divide and conquer"
] | ea7f8bd397f80ba7d3add6f9609dcc4a | The first line of input contains a single integer nΒ (0ββ€βnββ€β20). The second line of input contains 2n space-separated integers a[1],βa[2],β...,βa[2n]Β (1ββ€βa[i]ββ€β109), the initial array. The third line of input contains a single integer mΒ (1ββ€βmββ€β106). The fourth line of input contains m space-separated integers q1,βq2,β...,βqmΒ (0ββ€βqiββ€βn), the queries. Note: since the size of the input and output could be very large, don't use slow output techniques in your language. For example, do not use input and output streams (cin, cout) in C++. | 2,100 | Output m lines. In the i-th line print the answer (the number of inversions) for the i-th query. | standard output | |
PASSED | 89e4ca11588e5a147a2aa8752b0fcaf7 | train_000.jsonl | 1396798800 | Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced programmer. Actually he is not a programmer at all. So he wasn't able to solve them. That's why he asked you to help him with these tasks. One of these tasks is the following.You have an array a of length 2n and m queries on it. The i-th query is described by an integer qi. In order to perform the i-th query you must: split the array into 2nβ-βqi parts, where each part is a subarray consisting of 2qi numbers; the j-th subarray (1ββ€βjββ€β2nβ-βqi) should contain the elements a[(jβ-β1)Β·2qiβ+β1],βa[(jβ-β1)Β·2qiβ+β2],β...,βa[(jβ-β1)Β·2qiβ+β2qi]; reverse each of the subarrays; join them into a single array in the same order (this array becomes new array a); output the number of inversions in the new a. Given initial array a and all the queries. Answer all the queries. Please, note that the changes from some query is saved for further queries. | 512 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Iterator;
public class Solution1 implements Runnable
{
static final long MAX = 464897L;
static class InputReader
{
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
private BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public InputReader(InputStream stream)
{
this.stream = stream;
}
public int read()
{
if (numChars==-1)
throw new InputMismatchException();
if (curChar >= numChars)
{
curChar = 0;
try
{
numChars = stream.read(buf);
}
catch (IOException e)
{
throw new InputMismatchException();
}
if(numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
public int nextInt()
{
int c = read();
while(isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
int res = 0;
do
{
if(c<'0'||c>'9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
long res = 0;
do
{
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public double nextDouble()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.')
{
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.')
{
c = read();
double m = 1;
while (!isSpaceChar(c))
{
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public String readString()
{
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do
{
res.appendCodePoint(c);
c = read();
}
while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c)
{
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next()
{
return readString();
}
public interface SpaceCharFilter
{
public boolean isSpaceChar(int ch);
}
}
public static void main(String args[]) throws Exception
{
new Thread(null, new Solution1(),"Solution",1<<26).start();
}
static long gcd(long a, long b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
long MOD = 1000000007;
ArrayList<Integer> adj[];
ArrayList<Pair> adj2[];
public void run()
{
//InputReader sc= new InputReader(new FileInputStream("input.txt"));
//PrintWriter w= new PrintWriter(new FileWriter("output.txt"));
InputReader sc = new InputReader(System.in);
PrintWriter w = new PrintWriter(System.out);
int n = sc.nextInt();
long[] arr = new long[1<<n];
for(int i = 0;i < (1<<n);i++) {
arr[i] = sc.nextLong();
}
int temp = n+1;
segTree = new Node[(1<<temp) - 1];
build(0,(1<<n)-1,0,arr);
int[] state = new int[n+1];
long[][] val = new long[n+1][2];
int curr = 0;
for(int i = 0;i < n+1;i++) {
for(int j = 0;j < (1<<i);j++) {
val[i][0] += segTree[curr].val[0];
val[i][1] += segTree[curr].val[1];
curr++;
}
}
Arrays.fill(state,1);
long ans = 0;
for(int i = 0;i <= n;i++) {
ans += val[i][1];
}
int m = sc.nextInt();
for(int i = 0;i < m;i++) {
int x = sc.nextInt();
for(int j = n-x;j <= n;j++) {
ans -= val[j][state[j]];
state[j] ^= 1;
ans += val[j][state[j]];
}
w.println(ans);
}
w.close();
}
Node segTree[];
void build(int l,int r,int pos,long[] arr) {
if(l == r) {
segTree[pos] = new Node();
segTree[pos].ar.add(arr[l]);
return;
}
int mid = (l + r)/2;
build(l,mid,2*pos+1,arr);
build(mid+1,r,2*pos+2,arr);
segTree[pos] = merge(segTree[2*pos+1],segTree[2*pos+2]);
}
Node merge(Node one,Node two) {
ArrayList<Long> o = one.ar;
ArrayList<Long> s = two.ar;
ArrayList<Long> navu = new ArrayList();
int i = 0;
int j = 0;
long[] nav = new long[2];
while(i < o.size() && j < s.size()) {
if(o.get(i) <= s.get(j)) {
navu.add(o.get(i));
//nav[0] += (s.size() - j);
i++;
}
else {
navu.add(s.get(j));
nav[1] += (o.size() - i);
j++;
}
}
while(i < o.size()) {
navu.add(o.get(i));
i++;
}
while(j < s.size()) {
navu.add(s.get(j));
j++;
}
i = 0;
j = 0;
while(i < o.size() && j < s.size()) {
if(o.get(i) < s.get(j)) {
nav[0] += (s.size() - j);
i++;
}else {
j++;
}
}
return new Node(navu,nav);
}
static class Node{
ArrayList<Long> ar;
long[] val;
Node(){
ar = new ArrayList();
val = new long[2];
}
Node(ArrayList<Long> ar,long[] val) {
this.ar = ar;
this.val = val;
}
}
static long power(long a,long b,long mod) {
long ans = 1;
a = a % mod;
while(b != 0) {
if(b % 2 == 1) {
ans = (ans * a) % mod;
}
a = (a * a) % mod;
b = b/2;
}
return ans;
}
class Pair implements Comparable<Pair>{
long a;
int b;
int c;
//int c;
Pair(long a,int b,int c){
this.b = b;
this.a = a;
this.c = c;
}
public boolean equals(Object o) {
Pair p = (Pair)o;
return this.a == p.a && this.b == p.b;
}
public int hashCode(){
return Long.hashCode(a)*27 + Long.hashCode(b)* 31;
}
public int compareTo(Pair p) {
return Long.compare(this.a,p.a);
}
}
}
| Java | ["2\n2 1 4 3\n4\n1 2 0 2", "1\n1 2\n3\n0 1 1"] | 4 seconds | ["0\n6\n6\n0", "0\n1\n0"] | NoteIf we reverse an array x[1],βx[2],β...,βx[n] it becomes new array y[1],βy[2],β...,βy[n], where y[i]β=βx[nβ-βiβ+β1] for each i.The number of inversions of an array x[1],βx[2],β...,βx[n] is the number of pairs of indices i,βj such that: iβ<βj and x[i]β>βx[j]. | Java 8 | standard input | [
"combinatorics",
"divide and conquer"
] | ea7f8bd397f80ba7d3add6f9609dcc4a | The first line of input contains a single integer nΒ (0ββ€βnββ€β20). The second line of input contains 2n space-separated integers a[1],βa[2],β...,βa[2n]Β (1ββ€βa[i]ββ€β109), the initial array. The third line of input contains a single integer mΒ (1ββ€βmββ€β106). The fourth line of input contains m space-separated integers q1,βq2,β...,βqmΒ (0ββ€βqiββ€βn), the queries. Note: since the size of the input and output could be very large, don't use slow output techniques in your language. For example, do not use input and output streams (cin, cout) in C++. | 2,100 | Output m lines. In the i-th line print the answer (the number of inversions) for the i-th query. | standard output | |
PASSED | 2628104178891576a664e4b92ee1c434 | train_000.jsonl | 1396798800 | Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced programmer. Actually he is not a programmer at all. So he wasn't able to solve them. That's why he asked you to help him with these tasks. One of these tasks is the following.You have an array a of length 2n and m queries on it. The i-th query is described by an integer qi. In order to perform the i-th query you must: split the array into 2nβ-βqi parts, where each part is a subarray consisting of 2qi numbers; the j-th subarray (1ββ€βjββ€β2nβ-βqi) should contain the elements a[(jβ-β1)Β·2qiβ+β1],βa[(jβ-β1)Β·2qiβ+β2],β...,βa[(jβ-β1)Β·2qiβ+β2qi]; reverse each of the subarrays; join them into a single array in the same order (this array becomes new array a); output the number of inversions in the new a. Given initial array a and all the queries. Answer all the queries. Please, note that the changes from some query is saved for further queries. | 512 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastScanner in = new FastScanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
r240C solver = new r240C();
solver.solve(1, in, out);
out.close();
}
static class r240C {
long[] invs;
long[] invsRev;
public long numInversionsInt(int[] src, int[] dest, int low, int high, int N) {
int length = high - low;
if (length == 1) {
return 0;
}
if (length == 2) {
if (dest[low] > dest[high - 1]) {
int t = dest[low];
dest[low] = dest[high - 1];
dest[high - 1] = t;
invs[N]++;
return 1;
}
if (dest[low] < dest[high - 1])
invsRev[N]++;
return 0;
}
int mid = (low + high) / 2;
long c1 = numInversionsInt(dest, src, low, mid, N - 1);
long c2 = numInversionsInt(dest, src, mid, high, N - 1);
long c3 = 0;
long rev = 0;
for (int i = low, p = low, q = mid; i < high; i++) {
if (q >= high || p < mid && src[p] <= src[q]) {
dest[i] = src[p++];
} else {
dest[i] = src[q++];
c3 += mid - p;
}
}
for (int i = low, p = low, q = mid; i < high; i++) {
if (q >= high || p < mid && src[p] < src[q]) {
rev += high - q;
p++;
} else {
q++;
}
}
invs[N] += c3;
invsRev[N] += rev;
return c1 + c2 + c3;
}
public void solve(int testNumber, FastScanner in, PrintWriter out) {
int N = in.ni();
int n = 1 << N;
int[] a = in.na(n);
invs = new long[N + 1];
invsRev = new long[N + 1];
int[] src = a.clone(), dest = a.clone();
numInversionsInt(src, dest, 0, n, N);
int m = in.ni();
int state = 0;
// System.out.println("invs = " + Arrays.toString(invs));
// System.out.println("invsRev = " + Arrays.toString(invsRev));
for (int i = 0; i < m; i++) {
int q = in.ni();
state ^= (1 << q);
long res = 0;
boolean rev = false;
for (int j = N; j > 0; j--) {
rev ^= (state & (1 << j)) != 0;
if (!rev) {
res += invs[j];
} else {
res += invsRev[j];
}
}
out.println(res);
}
}
}
static class FastScanner {
private BufferedReader in;
private StringTokenizer st;
public FastScanner(InputStream stream) {
in = new BufferedReader(new InputStreamReader(stream));
}
public String ns() {
while (st == null || !st.hasMoreTokens()) {
try {
String rl = in.readLine();
if (rl == null) {
return null;
}
st = new StringTokenizer(rl);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return st.nextToken();
}
public int ni() {
return Integer.parseInt(ns());
}
public int[] na(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = ni();
return a;
}
}
}
| Java | ["2\n2 1 4 3\n4\n1 2 0 2", "1\n1 2\n3\n0 1 1"] | 4 seconds | ["0\n6\n6\n0", "0\n1\n0"] | NoteIf we reverse an array x[1],βx[2],β...,βx[n] it becomes new array y[1],βy[2],β...,βy[n], where y[i]β=βx[nβ-βiβ+β1] for each i.The number of inversions of an array x[1],βx[2],β...,βx[n] is the number of pairs of indices i,βj such that: iβ<βj and x[i]β>βx[j]. | Java 8 | standard input | [
"combinatorics",
"divide and conquer"
] | ea7f8bd397f80ba7d3add6f9609dcc4a | The first line of input contains a single integer nΒ (0ββ€βnββ€β20). The second line of input contains 2n space-separated integers a[1],βa[2],β...,βa[2n]Β (1ββ€βa[i]ββ€β109), the initial array. The third line of input contains a single integer mΒ (1ββ€βmββ€β106). The fourth line of input contains m space-separated integers q1,βq2,β...,βqmΒ (0ββ€βqiββ€βn), the queries. Note: since the size of the input and output could be very large, don't use slow output techniques in your language. For example, do not use input and output streams (cin, cout) in C++. | 2,100 | Output m lines. In the i-th line print the answer (the number of inversions) for the i-th query. | standard output | |
PASSED | 1b6ce5fd8d44ffd0661bf0ae5d9a9fb0 | train_000.jsonl | 1396798800 | Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced programmer. Actually he is not a programmer at all. So he wasn't able to solve them. That's why he asked you to help him with these tasks. One of these tasks is the following.You have an array a of length 2n and m queries on it. The i-th query is described by an integer qi. In order to perform the i-th query you must: split the array into 2nβ-βqi parts, where each part is a subarray consisting of 2qi numbers; the j-th subarray (1ββ€βjββ€β2nβ-βqi) should contain the elements a[(jβ-β1)Β·2qiβ+β1],βa[(jβ-β1)Β·2qiβ+β2],β...,βa[(jβ-β1)Β·2qiβ+β2qi]; reverse each of the subarrays; join them into a single array in the same order (this array becomes new array a); output the number of inversions in the new a. Given initial array a and all the queries. Answer all the queries. Please, note that the changes from some query is saved for further queries. | 512 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
CMashmokhAndReverseOperation solver = new CMashmokhAndReverseOperation();
solver.solve(1, in, out);
out.close();
}
static class CMashmokhAndReverseOperation {
long[] bad;
long[] good;
long[] sumBad;
long[] sumGood;
int[] a;
int[] sorted;
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.readInt();
a = in.readIntArray(1 << n);
// a = new int[1 << n];
// for (int i = 0; i < (1 << n); i++) a[i] = (int)(Math.random() * 1000000);
int m = in.readInt();
int[] rev = new int[50];
bad = new long[(1 << n) * 3];
good = new long[(1 << n) * 3];
sorted = new int[1 << n];
sumBad = new long[100];
sumGood = new long[100];
build(1, 0, (1 << n) - 1);
for (int i = 1; i < bad.length; i++) {
int depth = Integer.highestOneBit(i) * 2 - 1;
depth = Integer.bitCount(depth) - 1;
sumBad[depth] += bad[i];
sumGood[depth] += good[i];
}
while (m-- > 0) {
long ans = bad[1];
int q = in.readInt();
rev[n - q] ^= 1;
int parentState = 0;
for (int i = 0; i < 50; i++) {
if (rev[i] == 0) continue;
if (parentState == 0) {
ans += -sumBad[i] + sumGood[i];
} else {
ans += sumBad[i] - sumGood[i];
}
parentState ^= rev[i];
}
out.println(ans);
}
}
void build(int node, int l, int r) {
if (l == r) {
return;
}
build(node * 2, l, (l + r) / 2);
build(node * 2 + 1, (l + r) / 2 + 1, r);
bad[node] = bad[node * 2] + bad[node * 2 + 1];
good[node] = good[node * 2] + good[node * 2 + 1];
int end = (l + r) / 2;
long b = 0, g = 0;
for (int i = l, j = (l + r) / 2 + 1; i <= (l + r) / 2 && j <= r; ) {
if (a[i] > a[j]) {
b += end - i + 1;
j++;
} else i++;
}
for (int i = l, j = (l + r) / 2 + 1; i <= (l + r) / 2 && j <= r; ) {
if (a[i] < a[j]) {
g += r - j + 1;
i++;
} else {
j++;
}
}
int i, j, k;
for (i = l, k = 0, j = (l + r) / 2 + 1; i <= (l + r) / 2 && j <= r; k++) {
if (a[i] < a[j]) {
sorted[k] = a[i++];
} else sorted[k] = a[j++];
}
for (; i <= (l + r) / 2; i++) sorted[k++] = a[i];
for (; j <= r; j++) sorted[k++] = a[j];
for (i = l; i <= r; i++) a[i] = sorted[i - l];
good[node] += g;
bad[node] += b;
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private InputReader.SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public int[] readIntArray(int size) {
int[] ans = new int[size];
for (int i = 0; i < size; i++) ans[i] = readInt();
return ans;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}
| Java | ["2\n2 1 4 3\n4\n1 2 0 2", "1\n1 2\n3\n0 1 1"] | 4 seconds | ["0\n6\n6\n0", "0\n1\n0"] | NoteIf we reverse an array x[1],βx[2],β...,βx[n] it becomes new array y[1],βy[2],β...,βy[n], where y[i]β=βx[nβ-βiβ+β1] for each i.The number of inversions of an array x[1],βx[2],β...,βx[n] is the number of pairs of indices i,βj such that: iβ<βj and x[i]β>βx[j]. | Java 8 | standard input | [
"combinatorics",
"divide and conquer"
] | ea7f8bd397f80ba7d3add6f9609dcc4a | The first line of input contains a single integer nΒ (0ββ€βnββ€β20). The second line of input contains 2n space-separated integers a[1],βa[2],β...,βa[2n]Β (1ββ€βa[i]ββ€β109), the initial array. The third line of input contains a single integer mΒ (1ββ€βmββ€β106). The fourth line of input contains m space-separated integers q1,βq2,β...,βqmΒ (0ββ€βqiββ€βn), the queries. Note: since the size of the input and output could be very large, don't use slow output techniques in your language. For example, do not use input and output streams (cin, cout) in C++. | 2,100 | Output m lines. In the i-th line print the answer (the number of inversions) for the i-th query. | standard output | |
PASSED | bf0dc18483d1da67c029051827784d9a | train_000.jsonl | 1396798800 | Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced programmer. Actually he is not a programmer at all. So he wasn't able to solve them. That's why he asked you to help him with these tasks. One of these tasks is the following.You have an array a of length 2n and m queries on it. The i-th query is described by an integer qi. In order to perform the i-th query you must: split the array into 2nβ-βqi parts, where each part is a subarray consisting of 2qi numbers; the j-th subarray (1ββ€βjββ€β2nβ-βqi) should contain the elements a[(jβ-β1)Β·2qiβ+β1],βa[(jβ-β1)Β·2qiβ+β2],β...,βa[(jβ-β1)Β·2qiβ+β2qi]; reverse each of the subarrays; join them into a single array in the same order (this array becomes new array a); output the number of inversions in the new a. Given initial array a and all the queries. Answer all the queries. Please, note that the changes from some query is saved for further queries. | 512 megabytes | import java.io.*;
import java.util.*;
public class Mn {
FastScanner in;
PrintWriter out;
long[] inv1, inv2;
int[] tmp = new int[1 << 21];
void go(int[] a, int l, int r, int h) {
if (l == r) {
return;
} else {
int m = (l + r) >> 1;
m++;
go(a, l, m - 1, h + 1);
go(a, m, r, h + 1);
{
int it1 = l, it2 = m;
int it = 0;
while (it1 < m && it2 <= r) {
if (a[it1] <= a[it2]) {
tmp[it++] = a[it1++];
inv1[h] += (it2 - m);
} else {
tmp[it++] = a[it2++];
}
}
while (it1 < m) {
tmp[it++] = a[it1++];
inv1[h] += it2 - m;
}
while (it2 <= r) {
tmp[it++] = a[it2++];
}
}
{
int it1 = l, it2 = m;
while (it1 < m && it2 <= r) {
if (a[it1] < a[it2]) {
it1++;
} else {
inv2[h] += (it1 - l);
it2++;
}
}
while (it2 <= r) {
inv2[h] += it1 - l;
it2++;
}
}
for (int i = l; i <= r; i++) {
a[i] = tmp[i - l];
}
}
}
void solve() {
int n = in.nextInt();
inv1 = new long[n];
inv2 = new long[n];
int len = 1 << n;
int[] a = new int[len];
for (int i = 0; i < len; i++)
a[i] = in.nextInt();
go(a, 0, len - 1, 0);
int m = in.nextInt();
boolean[] now = new boolean[n];
long nowInv = 0;
for (int i = 0; i < n; i++)
nowInv += inv1[i];
for (int i = 0; i < m; i++) {
int q = in.nextInt();
for (int j = 0; j < q; j++) {
now[n - 1 - j] = !now[n - 1 - j];
if (now[n - 1 - j]) {
nowInv += inv2[n - 1 - j] - inv1[n - 1 - j];
} else {
nowInv += inv1[n - 1 - j] - inv2[n - 1 - j];
}
}
out.println(nowInv);
}
}
void run() {
try {
in = new FastScanner(new File("test.in"));
out = new PrintWriter(new File("test.out"));
solve();
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
void runIO() {
in = new FastScanner(System.in);
out = new PrintWriter(System.out);
solve();
out.close();
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(File f) {
try {
br = new BufferedReader(new FileReader(f));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public FastScanner(InputStream f) {
br = new BufferedReader(new InputStreamReader(f));
}
String next() {
while (st == null || !st.hasMoreTokens()) {
String s = null;
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (s == null)
return null;
st = new StringTokenizer(s);
}
return st.nextToken();
}
boolean hasMoreTokens() {
while (st == null || !st.hasMoreTokens()) {
String s = null;
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (s == null)
return false;
st = new StringTokenizer(s);
}
return true;
}
int nextInt() {
return Integer.parseInt(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
long nextLong() {
return Long.parseLong(next());
}
}
public static void main(String[] args) {
new Mn().runIO();
}
} | Java | ["2\n2 1 4 3\n4\n1 2 0 2", "1\n1 2\n3\n0 1 1"] | 4 seconds | ["0\n6\n6\n0", "0\n1\n0"] | NoteIf we reverse an array x[1],βx[2],β...,βx[n] it becomes new array y[1],βy[2],β...,βy[n], where y[i]β=βx[nβ-βiβ+β1] for each i.The number of inversions of an array x[1],βx[2],β...,βx[n] is the number of pairs of indices i,βj such that: iβ<βj and x[i]β>βx[j]. | Java 8 | standard input | [
"combinatorics",
"divide and conquer"
] | ea7f8bd397f80ba7d3add6f9609dcc4a | The first line of input contains a single integer nΒ (0ββ€βnββ€β20). The second line of input contains 2n space-separated integers a[1],βa[2],β...,βa[2n]Β (1ββ€βa[i]ββ€β109), the initial array. The third line of input contains a single integer mΒ (1ββ€βmββ€β106). The fourth line of input contains m space-separated integers q1,βq2,β...,βqmΒ (0ββ€βqiββ€βn), the queries. Note: since the size of the input and output could be very large, don't use slow output techniques in your language. For example, do not use input and output streams (cin, cout) in C++. | 2,100 | Output m lines. In the i-th line print the answer (the number of inversions) for the i-th query. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.