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
listlengths
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
9c6b5bb050dddd2b9a6796e3c53e76f1
train_003.jsonl
1537612500
After finding and moving to the new planet that supports human life, discussions started on which currency should be used. After long negotiations, Bitcoin was ultimately chosen as the universal currency.These were the great news for Alice, whose grandfather got into Bitcoin mining in 2013, and accumulated a lot of the...
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main { private FastScanner scanner = new FastScanner(); public static void main(String[] args) { new Main().solve(); } List<List<Integer>> gr = new ArrayList<>(); ...
Java
["3\n13 7 6\n6 2"]
1 second
["4"]
NoteAlice can make two transactions in a following way:0. 13 7 6 (initial state)1. 6 7 6 5 (create new address and transfer from first public address 5 satoshies)2. 6 4 6 5 1 (create new address and transfer from second address 1 satoshi)Since cost per transaction is 2 satoshies, total fee is 4.
Java 8
standard input
[ "implementation" ]
8a3e8a5db6d7d668ffea0f59e2639e87
First line contains number $$$N$$$ ($$$1 \leq N \leq 200\,000$$$) representing total number of public addresses Alice has. Next line contains $$$N$$$ integer numbers $$$a_i$$$ ($$$1 \leq a_i \leq 10^9$$$) separated by a single space, representing how many satoshi Alice has in her public addresses. Last line contains tw...
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
3e628c9394dba249a7d13dccf2bc5d61
train_003.jsonl
1537612500
After finding and moving to the new planet that supports human life, discussions started on which currency should be used. After long negotiations, Bitcoin was ultimately chosen as the universal currency.These were the great news for Alice, whose grandfather got into Bitcoin mining in 2013, and accumulated a lot of the...
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); if(n==1){ int a = sc.nextInt(); int x = sc.nextInt(); int f = sc.nextInt(); ...
Java
["3\n13 7 6\n6 2"]
1 second
["4"]
NoteAlice can make two transactions in a following way:0. 13 7 6 (initial state)1. 6 7 6 5 (create new address and transfer from first public address 5 satoshies)2. 6 4 6 5 1 (create new address and transfer from second address 1 satoshi)Since cost per transaction is 2 satoshies, total fee is 4.
Java 8
standard input
[ "implementation" ]
8a3e8a5db6d7d668ffea0f59e2639e87
First line contains number $$$N$$$ ($$$1 \leq N \leq 200\,000$$$) representing total number of public addresses Alice has. Next line contains $$$N$$$ integer numbers $$$a_i$$$ ($$$1 \leq a_i \leq 10^9$$$) separated by a single space, representing how many satoshi Alice has in her public addresses. Last line contains tw...
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
4feaf130562635d48bb07c22b728b05e
train_003.jsonl
1537612500
After finding and moving to the new planet that supports human life, discussions started on which currency should be used. After long negotiations, Bitcoin was ultimately chosen as the universal currency.These were the great news for Alice, whose grandfather got into Bitcoin mining in 2013, and accumulated a lot of the...
256 megabytes
import java.util.Scanner; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef { public static void main (String[] args) throws java.lang.Exception { try { Scanner sc = new Scanner(System.in); int i,n,x,f; long count=0; n=sc.nextInt(); int a[] = ...
Java
["3\n13 7 6\n6 2"]
1 second
["4"]
NoteAlice can make two transactions in a following way:0. 13 7 6 (initial state)1. 6 7 6 5 (create new address and transfer from first public address 5 satoshies)2. 6 4 6 5 1 (create new address and transfer from second address 1 satoshi)Since cost per transaction is 2 satoshies, total fee is 4.
Java 8
standard input
[ "implementation" ]
8a3e8a5db6d7d668ffea0f59e2639e87
First line contains number $$$N$$$ ($$$1 \leq N \leq 200\,000$$$) representing total number of public addresses Alice has. Next line contains $$$N$$$ integer numbers $$$a_i$$$ ($$$1 \leq a_i \leq 10^9$$$) separated by a single space, representing how many satoshi Alice has in her public addresses. Last line contains tw...
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
1379c4b5701da48d5c76a55cfd25da1e
train_003.jsonl
1537612500
After finding and moving to the new planet that supports human life, discussions started on which currency should be used. After long negotiations, Bitcoin was ultimately chosen as the universal currency.These were the great news for Alice, whose grandfather got into Bitcoin mining in 2013, and accumulated a lot of the...
256 megabytes
/** * Date: 22 Sep, 2018 * Link: * * @author Prasad-Chaudhari * @linkedIn: https://www.linkedin.com/in/prasad-chaudhari-841655a6/ * @git: https://github.com/Prasad-Chaudhari */ import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java...
Java
["3\n13 7 6\n6 2"]
1 second
["4"]
NoteAlice can make two transactions in a following way:0. 13 7 6 (initial state)1. 6 7 6 5 (create new address and transfer from first public address 5 satoshies)2. 6 4 6 5 1 (create new address and transfer from second address 1 satoshi)Since cost per transaction is 2 satoshies, total fee is 4.
Java 8
standard input
[ "implementation" ]
8a3e8a5db6d7d668ffea0f59e2639e87
First line contains number $$$N$$$ ($$$1 \leq N \leq 200\,000$$$) representing total number of public addresses Alice has. Next line contains $$$N$$$ integer numbers $$$a_i$$$ ($$$1 \leq a_i \leq 10^9$$$) separated by a single space, representing how many satoshi Alice has in her public addresses. Last line contains tw...
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
52091d2a621c2a3df2498c84c4a1081a
train_003.jsonl
1537612500
After finding and moving to the new planet that supports human life, discussions started on which currency should be used. After long negotiations, Bitcoin was ultimately chosen as the universal currency.These were the great news for Alice, whose grandfather got into Bitcoin mining in 2013, and accumulated a lot of the...
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.FilterInputStream; import java.io.BufferedInputStream; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Jenish */ public class Ma...
Java
["3\n13 7 6\n6 2"]
1 second
["4"]
NoteAlice can make two transactions in a following way:0. 13 7 6 (initial state)1. 6 7 6 5 (create new address and transfer from first public address 5 satoshies)2. 6 4 6 5 1 (create new address and transfer from second address 1 satoshi)Since cost per transaction is 2 satoshies, total fee is 4.
Java 8
standard input
[ "implementation" ]
8a3e8a5db6d7d668ffea0f59e2639e87
First line contains number $$$N$$$ ($$$1 \leq N \leq 200\,000$$$) representing total number of public addresses Alice has. Next line contains $$$N$$$ integer numbers $$$a_i$$$ ($$$1 \leq a_i \leq 10^9$$$) separated by a single space, representing how many satoshi Alice has in her public addresses. Last line contains tw...
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
6761dbbba71078f09171f3b0384d43cf
train_003.jsonl
1537612500
After finding and moving to the new planet that supports human life, discussions started on which currency should be used. After long negotiations, Bitcoin was ultimately chosen as the universal currency.These were the great news for Alice, whose grandfather got into Bitcoin mining in 2013, and accumulated a lot of the...
256 megabytes
import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.BitS...
Java
["3\n13 7 6\n6 2"]
1 second
["4"]
NoteAlice can make two transactions in a following way:0. 13 7 6 (initial state)1. 6 7 6 5 (create new address and transfer from first public address 5 satoshies)2. 6 4 6 5 1 (create new address and transfer from second address 1 satoshi)Since cost per transaction is 2 satoshies, total fee is 4.
Java 8
standard input
[ "implementation" ]
8a3e8a5db6d7d668ffea0f59e2639e87
First line contains number $$$N$$$ ($$$1 \leq N \leq 200\,000$$$) representing total number of public addresses Alice has. Next line contains $$$N$$$ integer numbers $$$a_i$$$ ($$$1 \leq a_i \leq 10^9$$$) separated by a single space, representing how many satoshi Alice has in her public addresses. Last line contains tw...
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
b79f2577c9ce1bbae9afec0ca11fa99e
train_003.jsonl
1537612500
After finding and moving to the new planet that supports human life, discussions started on which currency should be used. After long negotiations, Bitcoin was ultimately chosen as the universal currency.These were the great news for Alice, whose grandfather got into Bitcoin mining in 2013, and accumulated a lot of the...
256 megabytes
import java.io.BufferedReader; import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class SplittingMoney implements Closeable { private InputReader in = new InputReader(System.in); ...
Java
["3\n13 7 6\n6 2"]
1 second
["4"]
NoteAlice can make two transactions in a following way:0. 13 7 6 (initial state)1. 6 7 6 5 (create new address and transfer from first public address 5 satoshies)2. 6 4 6 5 1 (create new address and transfer from second address 1 satoshi)Since cost per transaction is 2 satoshies, total fee is 4.
Java 8
standard input
[ "implementation" ]
8a3e8a5db6d7d668ffea0f59e2639e87
First line contains number $$$N$$$ ($$$1 \leq N \leq 200\,000$$$) representing total number of public addresses Alice has. Next line contains $$$N$$$ integer numbers $$$a_i$$$ ($$$1 \leq a_i \leq 10^9$$$) separated by a single space, representing how many satoshi Alice has in her public addresses. Last line contains tw...
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
d065e50a5c4a4a90aff11ed6b4a08579
train_003.jsonl
1537612500
After finding and moving to the new planet that supports human life, discussions started on which currency should be used. After long negotiations, Bitcoin was ultimately chosen as the universal currency.These were the great news for Alice, whose grandfather got into Bitcoin mining in 2013, and accumulated a lot of the...
256 megabytes
import java.util.*; public class Q3 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int N = in.nextInt(); long[] arr = new long[N]; for (int j = 0; j < N; j++) arr[j] = in.nextInt(); int f=in.nextInt(),k=in.nextInt(); lo...
Java
["3\n13 7 6\n6 2"]
1 second
["4"]
NoteAlice can make two transactions in a following way:0. 13 7 6 (initial state)1. 6 7 6 5 (create new address and transfer from first public address 5 satoshies)2. 6 4 6 5 1 (create new address and transfer from second address 1 satoshi)Since cost per transaction is 2 satoshies, total fee is 4.
Java 8
standard input
[ "implementation" ]
8a3e8a5db6d7d668ffea0f59e2639e87
First line contains number $$$N$$$ ($$$1 \leq N \leq 200\,000$$$) representing total number of public addresses Alice has. Next line contains $$$N$$$ integer numbers $$$a_i$$$ ($$$1 \leq a_i \leq 10^9$$$) separated by a single space, representing how many satoshi Alice has in her public addresses. Last line contains tw...
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
521e3a5c1783772e207d496f8568b4f8
train_003.jsonl
1537612500
After finding and moving to the new planet that supports human life, discussions started on which currency should be used. After long negotiations, Bitcoin was ultimately chosen as the universal currency.These were the great news for Alice, whose grandfather got into Bitcoin mining in 2013, and accumulated a lot of the...
256 megabytes
import java.util.*; public class algo_102 { public static void main(String args[]) { Scanner ex=new Scanner(System.in); int n=ex.nextInt(); long ans=0; long coin[]=new long[n]; for(int i=0;i<n;i++) coin[i]=ex.nextLong(); long x=ex.nextLong(); long ...
Java
["3\n13 7 6\n6 2"]
1 second
["4"]
NoteAlice can make two transactions in a following way:0. 13 7 6 (initial state)1. 6 7 6 5 (create new address and transfer from first public address 5 satoshies)2. 6 4 6 5 1 (create new address and transfer from second address 1 satoshi)Since cost per transaction is 2 satoshies, total fee is 4.
Java 8
standard input
[ "implementation" ]
8a3e8a5db6d7d668ffea0f59e2639e87
First line contains number $$$N$$$ ($$$1 \leq N \leq 200\,000$$$) representing total number of public addresses Alice has. Next line contains $$$N$$$ integer numbers $$$a_i$$$ ($$$1 \leq a_i \leq 10^9$$$) separated by a single space, representing how many satoshi Alice has in her public addresses. Last line contains tw...
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
206f98a47fb4cc3cca686c81644196ae
train_003.jsonl
1537612500
After finding and moving to the new planet that supports human life, discussions started on which currency should be used. After long negotiations, Bitcoin was ultimately chosen as the universal currency.These were the great news for Alice, whose grandfather got into Bitcoin mining in 2013, and accumulated a lot of the...
256 megabytes
import java.io.*; import java.util.*; public class Main { static int gcd(int a, int b) { return b > 0 ? gcd(b, a % b) : a; } public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] m = new int[n]; ...
Java
["3\n13 7 6\n6 2"]
1 second
["4"]
NoteAlice can make two transactions in a following way:0. 13 7 6 (initial state)1. 6 7 6 5 (create new address and transfer from first public address 5 satoshies)2. 6 4 6 5 1 (create new address and transfer from second address 1 satoshi)Since cost per transaction is 2 satoshies, total fee is 4.
Java 8
standard input
[ "implementation" ]
8a3e8a5db6d7d668ffea0f59e2639e87
First line contains number $$$N$$$ ($$$1 \leq N \leq 200\,000$$$) representing total number of public addresses Alice has. Next line contains $$$N$$$ integer numbers $$$a_i$$$ ($$$1 \leq a_i \leq 10^9$$$) separated by a single space, representing how many satoshi Alice has in her public addresses. Last line contains tw...
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
514619196f3ac597ff09ccc88f901829
train_003.jsonl
1537612500
After finding and moving to the new planet that supports human life, discussions started on which currency should be used. After long negotiations, Bitcoin was ultimately chosen as the universal currency.These were the great news for Alice, whose grandfather got into Bitcoin mining in 2013, and accumulated a lot of the...
256 megabytes
/** * BaZ :D */ import java.util.*; import java.io.*; import static java.lang.Math.*; public class Chu { static Reader scan; static PrintWriter pw; public static void main(String[] args) { new Thread(null,null,"BaZ",1<<25) { public void run() { try ...
Java
["3\n13 7 6\n6 2"]
1 second
["4"]
NoteAlice can make two transactions in a following way:0. 13 7 6 (initial state)1. 6 7 6 5 (create new address and transfer from first public address 5 satoshies)2. 6 4 6 5 1 (create new address and transfer from second address 1 satoshi)Since cost per transaction is 2 satoshies, total fee is 4.
Java 8
standard input
[ "implementation" ]
8a3e8a5db6d7d668ffea0f59e2639e87
First line contains number $$$N$$$ ($$$1 \leq N \leq 200\,000$$$) representing total number of public addresses Alice has. Next line contains $$$N$$$ integer numbers $$$a_i$$$ ($$$1 \leq a_i \leq 10^9$$$) separated by a single space, representing how many satoshi Alice has in her public addresses. Last line contains tw...
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
ff311c6544a163a9a058d46cba1a0326
train_003.jsonl
1537612500
After finding and moving to the new planet that supports human life, discussions started on which currency should be used. After long negotiations, Bitcoin was ultimately chosen as the universal currency.These were the great news for Alice, whose grandfather got into Bitcoin mining in 2013, and accumulated a lot of the...
256 megabytes
import java.util.*; public class Main { public static void main(String[] Args) { Scanner in = new Scanner(System.in); //HashMap<Integer,Integer> hm = new HashMap<Integer,Integer>(); int n = in.nextInt(); long[] a = new long[n]; for(int i=0;i<n;i++) { a[i] = in.nextLong(); } long x = in.n...
Java
["3\n13 7 6\n6 2"]
1 second
["4"]
NoteAlice can make two transactions in a following way:0. 13 7 6 (initial state)1. 6 7 6 5 (create new address and transfer from first public address 5 satoshies)2. 6 4 6 5 1 (create new address and transfer from second address 1 satoshi)Since cost per transaction is 2 satoshies, total fee is 4.
Java 8
standard input
[ "implementation" ]
8a3e8a5db6d7d668ffea0f59e2639e87
First line contains number $$$N$$$ ($$$1 \leq N \leq 200\,000$$$) representing total number of public addresses Alice has. Next line contains $$$N$$$ integer numbers $$$a_i$$$ ($$$1 \leq a_i \leq 10^9$$$) separated by a single space, representing how many satoshi Alice has in her public addresses. Last line contains tw...
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
ecc2c93fc063e325be3e67386f870d13
train_003.jsonl
1537612500
After finding and moving to the new planet that supports human life, discussions started on which currency should be used. After long negotiations, Bitcoin was ultimately chosen as the universal currency.These were the great news for Alice, whose grandfather got into Bitcoin mining in 2013, and accumulated a lot of the...
256 megabytes
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; public InputReader(InputStream ...
Java
["3\n13 7 6\n6 2"]
1 second
["4"]
NoteAlice can make two transactions in a following way:0. 13 7 6 (initial state)1. 6 7 6 5 (create new address and transfer from first public address 5 satoshies)2. 6 4 6 5 1 (create new address and transfer from second address 1 satoshi)Since cost per transaction is 2 satoshies, total fee is 4.
Java 8
standard input
[ "implementation" ]
8a3e8a5db6d7d668ffea0f59e2639e87
First line contains number $$$N$$$ ($$$1 \leq N \leq 200\,000$$$) representing total number of public addresses Alice has. Next line contains $$$N$$$ integer numbers $$$a_i$$$ ($$$1 \leq a_i \leq 10^9$$$) separated by a single space, representing how many satoshi Alice has in her public addresses. Last line contains tw...
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
00db0e96a248c6e7d5053bb1b21627bf
train_003.jsonl
1537612500
After finding and moving to the new planet that supports human life, discussions started on which currency should be used. After long negotiations, Bitcoin was ultimately chosen as the universal currency.These were the great news for Alice, whose grandfather got into Bitcoin mining in 2013, and accumulated a lot of the...
256 megabytes
import java.util.*; import java.io.*; /** * * @author alanl */ public class Main { /** * @param args the command line arguments */ static BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer st; static PrintWriter pr = new PrintWriter(new Buff...
Java
["3\n13 7 6\n6 2"]
1 second
["4"]
NoteAlice can make two transactions in a following way:0. 13 7 6 (initial state)1. 6 7 6 5 (create new address and transfer from first public address 5 satoshies)2. 6 4 6 5 1 (create new address and transfer from second address 1 satoshi)Since cost per transaction is 2 satoshies, total fee is 4.
Java 8
standard input
[ "implementation" ]
8a3e8a5db6d7d668ffea0f59e2639e87
First line contains number $$$N$$$ ($$$1 \leq N \leq 200\,000$$$) representing total number of public addresses Alice has. Next line contains $$$N$$$ integer numbers $$$a_i$$$ ($$$1 \leq a_i \leq 10^9$$$) separated by a single space, representing how many satoshi Alice has in her public addresses. Last line contains tw...
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
4d1456a4e6c667c460893b2de88e6ad2
train_003.jsonl
1537612500
After finding and moving to the new planet that supports human life, discussions started on which currency should be used. After long negotiations, Bitcoin was ultimately chosen as the universal currency.These were the great news for Alice, whose grandfather got into Bitcoin mining in 2013, and accumulated a lot of the...
256 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 * * @author NMouad21 */ public class M...
Java
["3\n13 7 6\n6 2"]
1 second
["4"]
NoteAlice can make two transactions in a following way:0. 13 7 6 (initial state)1. 6 7 6 5 (create new address and transfer from first public address 5 satoshies)2. 6 4 6 5 1 (create new address and transfer from second address 1 satoshi)Since cost per transaction is 2 satoshies, total fee is 4.
Java 8
standard input
[ "implementation" ]
8a3e8a5db6d7d668ffea0f59e2639e87
First line contains number $$$N$$$ ($$$1 \leq N \leq 200\,000$$$) representing total number of public addresses Alice has. Next line contains $$$N$$$ integer numbers $$$a_i$$$ ($$$1 \leq a_i \leq 10^9$$$) separated by a single space, representing how many satoshi Alice has in her public addresses. Last line contains tw...
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
29e9af43c391bddd68753e8a07dd595e
train_003.jsonl
1537612500
After finding and moving to the new planet that supports human life, discussions started on which currency should be used. After long negotiations, Bitcoin was ultimately chosen as the universal currency.These were the great news for Alice, whose grandfather got into Bitcoin mining in 2013, and accumulated a lot of the...
256 megabytes
import java.util.*; import java.io.*; public class Main { static BufferedReader br; static StringTokenizer st; static int n; static int[] vals; static int x; static int f; public static void main(String[] args) throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); st = new Stri...
Java
["3\n13 7 6\n6 2"]
1 second
["4"]
NoteAlice can make two transactions in a following way:0. 13 7 6 (initial state)1. 6 7 6 5 (create new address and transfer from first public address 5 satoshies)2. 6 4 6 5 1 (create new address and transfer from second address 1 satoshi)Since cost per transaction is 2 satoshies, total fee is 4.
Java 8
standard input
[ "implementation" ]
8a3e8a5db6d7d668ffea0f59e2639e87
First line contains number $$$N$$$ ($$$1 \leq N \leq 200\,000$$$) representing total number of public addresses Alice has. Next line contains $$$N$$$ integer numbers $$$a_i$$$ ($$$1 \leq a_i \leq 10^9$$$) separated by a single space, representing how many satoshi Alice has in her public addresses. Last line contains tw...
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
52ab4aef55905bdcf8df3918de9eaccf
train_003.jsonl
1537612500
After finding and moving to the new planet that supports human life, discussions started on which currency should be used. After long negotiations, Bitcoin was ultimately chosen as the universal currency.These were the great news for Alice, whose grandfather got into Bitcoin mining in 2013, and accumulated a lot of the...
256 megabytes
import java.util.Scanner; public class SplittingMoney { private static long splitNum(long i,long x,long f) { return (i+f-1)/(f+x); } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n=scanner.nextInt(); long x,f,ans=0; long[] a ...
Java
["3\n13 7 6\n6 2"]
1 second
["4"]
NoteAlice can make two transactions in a following way:0. 13 7 6 (initial state)1. 6 7 6 5 (create new address and transfer from first public address 5 satoshies)2. 6 4 6 5 1 (create new address and transfer from second address 1 satoshi)Since cost per transaction is 2 satoshies, total fee is 4.
Java 8
standard input
[ "implementation" ]
8a3e8a5db6d7d668ffea0f59e2639e87
First line contains number $$$N$$$ ($$$1 \leq N \leq 200\,000$$$) representing total number of public addresses Alice has. Next line contains $$$N$$$ integer numbers $$$a_i$$$ ($$$1 \leq a_i \leq 10^9$$$) separated by a single space, representing how many satoshi Alice has in her public addresses. Last line contains tw...
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
ec2c5b00b56dbe75f396d2d734504369
train_003.jsonl
1537612500
After finding and moving to the new planet that supports human life, discussions started on which currency should be used. After long negotiations, Bitcoin was ultimately chosen as the universal currency.These were the great news for Alice, whose grandfather got into Bitcoin mining in 2013, and accumulated a lot of the...
256 megabytes
/* Keep solving problems. */ import java.util.*; import java.io.*; public class CFA { BufferedReader br; PrintWriter out; StringTokenizer st; boolean eof; private static final long MOD = 1000L * 1000L * 1000L + 7; private static final int[] dx = {0, -1, 0, 1}; private static final int[] dy...
Java
["3\n13 7 6\n6 2"]
1 second
["4"]
NoteAlice can make two transactions in a following way:0. 13 7 6 (initial state)1. 6 7 6 5 (create new address and transfer from first public address 5 satoshies)2. 6 4 6 5 1 (create new address and transfer from second address 1 satoshi)Since cost per transaction is 2 satoshies, total fee is 4.
Java 8
standard input
[ "implementation" ]
8a3e8a5db6d7d668ffea0f59e2639e87
First line contains number $$$N$$$ ($$$1 \leq N \leq 200\,000$$$) representing total number of public addresses Alice has. Next line contains $$$N$$$ integer numbers $$$a_i$$$ ($$$1 \leq a_i \leq 10^9$$$) separated by a single space, representing how many satoshi Alice has in her public addresses. Last line contains tw...
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
2c4ed0838187698d72c5f08d909be93d
train_003.jsonl
1537612500
After finding and moving to the new planet that supports human life, discussions started on which currency should be used. After long negotiations, Bitcoin was ultimately chosen as the universal currency.These were the great news for Alice, whose grandfather got into Bitcoin mining in 2013, and accumulated a lot of the...
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class Main1 { 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 (n...
Java
["3\n13 7 6\n6 2"]
1 second
["4"]
NoteAlice can make two transactions in a following way:0. 13 7 6 (initial state)1. 6 7 6 5 (create new address and transfer from first public address 5 satoshies)2. 6 4 6 5 1 (create new address and transfer from second address 1 satoshi)Since cost per transaction is 2 satoshies, total fee is 4.
Java 8
standard input
[ "implementation" ]
8a3e8a5db6d7d668ffea0f59e2639e87
First line contains number $$$N$$$ ($$$1 \leq N \leq 200\,000$$$) representing total number of public addresses Alice has. Next line contains $$$N$$$ integer numbers $$$a_i$$$ ($$$1 \leq a_i \leq 10^9$$$) separated by a single space, representing how many satoshi Alice has in her public addresses. Last line contains tw...
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
beb7e41d3d018eedf6553d11a9cfe68a
train_003.jsonl
1537612500
After finding and moving to the new planet that supports human life, discussions started on which currency should be used. After long negotiations, Bitcoin was ultimately chosen as the universal currency.These were the great news for Alice, whose grandfather got into Bitcoin mining in 2013, and accumulated a lot of the...
256 megabytes
//package que_b; import java.io.*; import java.util.*; import java.math.*; public class utkarsh { InputStream is; PrintWriter out; long mod = (long) (1e9 + 7); boolean SHOW_TIME; void solve() { //Enter code here utkarsh //SHOW_TIME = true; int n = ni(); l...
Java
["3\n13 7 6\n6 2"]
1 second
["4"]
NoteAlice can make two transactions in a following way:0. 13 7 6 (initial state)1. 6 7 6 5 (create new address and transfer from first public address 5 satoshies)2. 6 4 6 5 1 (create new address and transfer from second address 1 satoshi)Since cost per transaction is 2 satoshies, total fee is 4.
Java 8
standard input
[ "implementation" ]
8a3e8a5db6d7d668ffea0f59e2639e87
First line contains number $$$N$$$ ($$$1 \leq N \leq 200\,000$$$) representing total number of public addresses Alice has. Next line contains $$$N$$$ integer numbers $$$a_i$$$ ($$$1 \leq a_i \leq 10^9$$$) separated by a single space, representing how many satoshi Alice has in her public addresses. Last line contains tw...
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
7b2fad3b9851b8a74535e1e3bac5ccd7
train_003.jsonl
1537612500
After finding and moving to the new planet that supports human life, discussions started on which currency should be used. After long negotiations, Bitcoin was ultimately chosen as the universal currency.These were the great news for Alice, whose grandfather got into Bitcoin mining in 2013, and accumulated a lot of the...
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); long cnt = 0; long n = scanner.nextLong(); long[] a = new long[200001]; for (int i=1;i<=n;i++) { a[i] = scanner.nextLong(); } long x = scanner.nextLong(); lon...
Java
["3\n13 7 6\n6 2"]
1 second
["4"]
NoteAlice can make two transactions in a following way:0. 13 7 6 (initial state)1. 6 7 6 5 (create new address and transfer from first public address 5 satoshies)2. 6 4 6 5 1 (create new address and transfer from second address 1 satoshi)Since cost per transaction is 2 satoshies, total fee is 4.
Java 8
standard input
[ "implementation" ]
8a3e8a5db6d7d668ffea0f59e2639e87
First line contains number $$$N$$$ ($$$1 \leq N \leq 200\,000$$$) representing total number of public addresses Alice has. Next line contains $$$N$$$ integer numbers $$$a_i$$$ ($$$1 \leq a_i \leq 10^9$$$) separated by a single space, representing how many satoshi Alice has in her public addresses. Last line contains tw...
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
a5468e3ed66d21d79a26523c181ce5e4
train_003.jsonl
1389972600
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills: a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.For example, sequences [1, 5], [10], [5, 4,...
256 megabytes
import java.util.*; import java.io.*; public class jk { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); int num = Integer.parseInt(in.readLine())...
Java
["3\n4 1 7", "1\n10", "4\n1 3 5 9", "4\n4 3 4 5", "2\n2 4"]
1 second
["2\n-2 10", "-1", "1\n7", "0", "3\n0 3 6"]
null
Java 8
standard input
[ "implementation", "sortings" ]
e3ca8338beb8852c201be72650e9aabd
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
1,700
If Arthur can write infinitely many distinct integers on the card, print on a single line -1. Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
standard output
PASSED
432cf00c625348060bbb167119545761
train_003.jsonl
1389972600
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills: a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.For example, sequences [1, 5], [10], [5, 4,...
256 megabytes
import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.util.Arrays; public class ArithmeticProgression { static int mod = 1000000007; static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private in...
Java
["3\n4 1 7", "1\n10", "4\n1 3 5 9", "4\n4 3 4 5", "2\n2 4"]
1 second
["2\n-2 10", "-1", "1\n7", "0", "3\n0 3 6"]
null
Java 8
standard input
[ "implementation", "sortings" ]
e3ca8338beb8852c201be72650e9aabd
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
1,700
If Arthur can write infinitely many distinct integers on the card, print on a single line -1. Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
standard output
PASSED
82a3d2c7167b1253cddfb4351a38b6dd
train_003.jsonl
1389972600
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills: a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.For example, sequences [1, 5], [10], [5, 4,...
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.net.URISyntaxException; import java.util.Arrays; import java.util.StringTokenizer; public class Main { // public static void main(Str...
Java
["3\n4 1 7", "1\n10", "4\n1 3 5 9", "4\n4 3 4 5", "2\n2 4"]
1 second
["2\n-2 10", "-1", "1\n7", "0", "3\n0 3 6"]
null
Java 8
standard input
[ "implementation", "sortings" ]
e3ca8338beb8852c201be72650e9aabd
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
1,700
If Arthur can write infinitely many distinct integers on the card, print on a single line -1. Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
standard output
PASSED
0a0213fa07f7ae91da12aea69ec88aba
train_003.jsonl
1389972600
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills: a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.For example, sequences [1, 5], [10], [5, 4,...
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.net.URISyntaxException; import java.util.Arrays; import java.util.StringTokenizer; public class Main { public static void main(Strin...
Java
["3\n4 1 7", "1\n10", "4\n1 3 5 9", "4\n4 3 4 5", "2\n2 4"]
1 second
["2\n-2 10", "-1", "1\n7", "0", "3\n0 3 6"]
null
Java 8
standard input
[ "implementation", "sortings" ]
e3ca8338beb8852c201be72650e9aabd
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
1,700
If Arthur can write infinitely many distinct integers on the card, print on a single line -1. Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
standard output
PASSED
db5281895b6cf9e162beb31816e26384
train_003.jsonl
1389972600
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills: a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.For example, sequences [1, 5], [10], [5, 4,...
256 megabytes
/** * ******* Created on 10/12/19 12:37 AM******* */ import java.io.*; import java.util.*; public class C382 implements Runnable { private static final int MAX = (int) (1E5 + 5); private static final int MOD = (int) (1E9 + 7); private static final int Inf = (int) (1E9 + 10); List<Integer> res = ne...
Java
["3\n4 1 7", "1\n10", "4\n1 3 5 9", "4\n4 3 4 5", "2\n2 4"]
1 second
["2\n-2 10", "-1", "1\n7", "0", "3\n0 3 6"]
null
Java 8
standard input
[ "implementation", "sortings" ]
e3ca8338beb8852c201be72650e9aabd
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
1,700
If Arthur can write infinitely many distinct integers on the card, print on a single line -1. Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
standard output
PASSED
8ce7c5571eba8090c06daf446356b4f4
train_003.jsonl
1389972600
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills: a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.For example, sequences [1, 5], [10], [5, 4,...
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.StringTokenizer; import java.util.TreeSet; public class C { public static void main(String[] args) throws IOException { FastScanner scan = new FastScann...
Java
["3\n4 1 7", "1\n10", "4\n1 3 5 9", "4\n4 3 4 5", "2\n2 4"]
1 second
["2\n-2 10", "-1", "1\n7", "0", "3\n0 3 6"]
null
Java 8
standard input
[ "implementation", "sortings" ]
e3ca8338beb8852c201be72650e9aabd
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
1,700
If Arthur can write infinitely many distinct integers on the card, print on a single line -1. Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
standard output
PASSED
a02ef1c439498f5b8aa6358320db6480
train_003.jsonl
1389972600
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills: a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.For example, sequences [1, 5], [10], [5, 4,...
256 megabytes
/** * DA-IICT * Author : PARTH PATEL */ import java.io.*; import java.math.*; import java.util.*; import static java.util.Arrays.fill; import static java.lang.Math.*; import static java.util.Arrays.sort; import static java.util.Collections.sort; public class C382 { public static long mod = 1000000007; public ...
Java
["3\n4 1 7", "1\n10", "4\n1 3 5 9", "4\n4 3 4 5", "2\n2 4"]
1 second
["2\n-2 10", "-1", "1\n7", "0", "3\n0 3 6"]
null
Java 8
standard input
[ "implementation", "sortings" ]
e3ca8338beb8852c201be72650e9aabd
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
1,700
If Arthur can write infinitely many distinct integers on the card, print on a single line -1. Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
standard output
PASSED
e63a16d4838f5cb22c84b75c54248590
train_003.jsonl
1389972600
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills: a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.For example, sequences [1, 5], [10], [5, 4,...
256 megabytes
/* *created by Kraken on 08-05-2020 at 10:40 */ //package com.kraken.cf.practice; import java.util.*; import java.io.*; public class C382 { private static final long INF = (long) 1e12; public static void main(String[] args) { FastReader sc = new FastReader(); int n = sc.nextInt(); Long[] x = new Lo...
Java
["3\n4 1 7", "1\n10", "4\n1 3 5 9", "4\n4 3 4 5", "2\n2 4"]
1 second
["2\n-2 10", "-1", "1\n7", "0", "3\n0 3 6"]
null
Java 8
standard input
[ "implementation", "sortings" ]
e3ca8338beb8852c201be72650e9aabd
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
1,700
If Arthur can write infinitely many distinct integers on the card, print on a single line -1. Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
standard output
PASSED
9258fbcde5d138d09399b8ca2a528d25
train_003.jsonl
1389972600
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills: a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.For example, sequences [1, 5], [10], [5, 4,...
256 megabytes
import java.util.*; import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class ArithmeticProgression { public static void main(String[] args) { Scanner inp = new Scanner(System.in); int n = inp.nextInt(); AP arr[] = new AP[n]; List<Integer> pos = n...
Java
["3\n4 1 7", "1\n10", "4\n1 3 5 9", "4\n4 3 4 5", "2\n2 4"]
1 second
["2\n-2 10", "-1", "1\n7", "0", "3\n0 3 6"]
null
Java 8
standard input
[ "implementation", "sortings" ]
e3ca8338beb8852c201be72650e9aabd
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
1,700
If Arthur can write infinitely many distinct integers on the card, print on a single line -1. Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
standard output
PASSED
f5bd89f5f1ef240ccc7383de4c88e008
train_003.jsonl
1389972600
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills: a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.For example, sequences [1, 5], [10], [5, 4,...
256 megabytes
import java.io.*; import java.util.*; public class C1 { 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))); int n = Integer.parseInt(br.rea...
Java
["3\n4 1 7", "1\n10", "4\n1 3 5 9", "4\n4 3 4 5", "2\n2 4"]
1 second
["2\n-2 10", "-1", "1\n7", "0", "3\n0 3 6"]
null
Java 8
standard input
[ "implementation", "sortings" ]
e3ca8338beb8852c201be72650e9aabd
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
1,700
If Arthur can write infinitely many distinct integers on the card, print on a single line -1. Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
standard output
PASSED
bc4822ec01a7171fd01c2e8a57002237
train_003.jsonl
1389972600
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills: a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.For example, sequences [1, 5], [10], [5, 4,...
256 megabytes
import java.io.*; import java.util.*; public class C { static StringBuilder st = new StringBuilder(); public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = sc.nextInt(); if(n == 1) { out.println(-1);...
Java
["3\n4 1 7", "1\n10", "4\n1 3 5 9", "4\n4 3 4 5", "2\n2 4"]
1 second
["2\n-2 10", "-1", "1\n7", "0", "3\n0 3 6"]
null
Java 8
standard input
[ "implementation", "sortings" ]
e3ca8338beb8852c201be72650e9aabd
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
1,700
If Arthur can write infinitely many distinct integers on the card, print on a single line -1. Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
standard output
PASSED
1a2d3bc9de0e2df453af7a78404a2ae0
train_003.jsonl
1389972600
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills: a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.For example, sequences [1, 5], [10], [5, 4,...
256 megabytes
import java.io.*; import java.util.*; public class C { static StringBuilder st = new StringBuilder(); public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = sc.nextInt(); if(n == 1) { out.println(-1); ...
Java
["3\n4 1 7", "1\n10", "4\n1 3 5 9", "4\n4 3 4 5", "2\n2 4"]
1 second
["2\n-2 10", "-1", "1\n7", "0", "3\n0 3 6"]
null
Java 8
standard input
[ "implementation", "sortings" ]
e3ca8338beb8852c201be72650e9aabd
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
1,700
If Arthur can write infinitely many distinct integers on the card, print on a single line -1. Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
standard output
PASSED
8a6fdb194ed444360d29dc4b4cfe3f0b
train_003.jsonl
1389972600
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills: a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.For example, sequences [1, 5], [10], [5, 4,...
256 megabytes
import java.io.*; import java.util.*; public class C { static StringBuilder st = new StringBuilder(); public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = sc.nextInt(); if(n == 1) { out.println(-1); ...
Java
["3\n4 1 7", "1\n10", "4\n1 3 5 9", "4\n4 3 4 5", "2\n2 4"]
1 second
["2\n-2 10", "-1", "1\n7", "0", "3\n0 3 6"]
null
Java 8
standard input
[ "implementation", "sortings" ]
e3ca8338beb8852c201be72650e9aabd
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
1,700
If Arthur can write infinitely many distinct integers on the card, print on a single line -1. Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
standard output
PASSED
0d68f49311d4e2fd165a002544f3f6fb
train_003.jsonl
1389972600
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills: a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.For example, sequences [1, 5], [10], [5, 4,...
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.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import jav...
Java
["3\n4 1 7", "1\n10", "4\n1 3 5 9", "4\n4 3 4 5", "2\n2 4"]
1 second
["2\n-2 10", "-1", "1\n7", "0", "3\n0 3 6"]
null
Java 8
standard input
[ "implementation", "sortings" ]
e3ca8338beb8852c201be72650e9aabd
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
1,700
If Arthur can write infinitely many distinct integers on the card, print on a single line -1. Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
standard output
PASSED
7135fb888256c4e5f7ac1f8570e5ba5b
train_003.jsonl
1389972600
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills: a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.For example, sequences [1, 5], [10], [5, 4,...
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.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; public class B { public static void main(String[] arg...
Java
["3\n4 1 7", "1\n10", "4\n1 3 5 9", "4\n4 3 4 5", "2\n2 4"]
1 second
["2\n-2 10", "-1", "1\n7", "0", "3\n0 3 6"]
null
Java 8
standard input
[ "implementation", "sortings" ]
e3ca8338beb8852c201be72650e9aabd
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
1,700
If Arthur can write infinitely many distinct integers on the card, print on a single line -1. Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
standard output
PASSED
360b46467c13d765519aee4be05f1499
train_003.jsonl
1389972600
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills: a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.For example, sequences [1, 5], [10], [5, 4,...
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNext()) { int n = in.nextInt(); int[] nums = new int[n]; for (int i = 0; i < n; i++) { nums[i] = in.nextInt(); ...
Java
["3\n4 1 7", "1\n10", "4\n1 3 5 9", "4\n4 3 4 5", "2\n2 4"]
1 second
["2\n-2 10", "-1", "1\n7", "0", "3\n0 3 6"]
null
Java 8
standard input
[ "implementation", "sortings" ]
e3ca8338beb8852c201be72650e9aabd
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
1,700
If Arthur can write infinitely many distinct integers on the card, print on a single line -1. Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
standard output
PASSED
68baf1a65e4c4fcdab074e91be10ba08
train_003.jsonl
1389972600
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills: a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.For example, sequences [1, 5], [10], [5, 4,...
256 megabytes
import java.io.*; import java.util.*; /* * Heart beats fast * Colors and promises * How to be brave * How can I love when I am afraid to fall... */ public class Main { public static void main(String[] args) throws IOException { int n=ni(); int a[]=nia(n); Arrays.sort(a); if(n==1) pr(-1); ...
Java
["3\n4 1 7", "1\n10", "4\n1 3 5 9", "4\n4 3 4 5", "2\n2 4"]
1 second
["2\n-2 10", "-1", "1\n7", "0", "3\n0 3 6"]
null
Java 8
standard input
[ "implementation", "sortings" ]
e3ca8338beb8852c201be72650e9aabd
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
1,700
If Arthur can write infinitely many distinct integers on the card, print on a single line -1. Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
standard output
PASSED
203f1797543f5243d7d7f898aecf747b
train_003.jsonl
1479918900
Gosha is hunting. His goal is to catch as many Pokemons as possible. Gosha has a Poke Balls and b Ultra Balls. There are n Pokemons. They are numbered 1 through n. Gosha knows that if he throws a Poke Ball at the i-th Pokemon he catches it with probability pi. If he throws an Ultra Ball at the i-th Pokemon he catches i...
256 megabytes
//package com.company; import java.io.*; import java.util.*; public class Main { public static class Task { int n, a, b; double[] pa, pb, pab; int maxChoice(double[] expect) { int bestC = 0; for (int i = 1; i < expect.length; i++) { if (expect[i] ...
Java
["3 2 2\n1.000 0.000 0.500\n0.000 1.000 0.500", "4 1 3\n0.100 0.500 0.500 0.600\n0.100 0.500 0.900 0.400", "3 2 0\n0.412 0.198 0.599\n0.612 0.987 0.443"]
5 seconds
["2.75", "2.16", "1.011"]
null
Java 11
standard input
[ "dp", "flows", "probabilities", "math", "sortings", "data structures", "brute force" ]
ea7643c3b7ed02d9c41a4b3441e53935
The first line contains three integers n, a and b (2 ≤ n ≤ 2000, 0 ≤ a, b ≤ n) — the number of Pokemons, the number of Poke Balls and the number of Ultra Balls. The second line contains n real values p1, p2, ..., pn (0 ≤ pi ≤ 1), where pi is the probability of catching the i-th Pokemon if Gosha throws a Poke Ball to it...
3,000
Print the maximum possible expected number of Pokemons Gosha can catch. The answer is considered correct if it's absolute or relative error doesn't exceed 10 - 4.
standard output
PASSED
fc631566f006b91c258e00956fadc886
train_003.jsonl
1300809600
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
256 megabytes
import java.util.Scanner; /** * Created by Usandy on 18.03.15. */ public class ACM { public static void main(String[] args){ Scanner scanner=new Scanner(System.in); int n=scanner.nextInt(); long[] mas=new long[3]; long kol=0; for(int i=0;i<n;i++) for(int j=0;j<...
Java
["3\n4 1 7\n-2 4 -1\n1 -5 -3", "3\n3 -1 7\n-5 2 -4\n2 -1 -3"]
2 seconds
["NO", "YES"]
null
Java 7
standard input
[ "implementation", "math" ]
8ea24f3339b2ec67a769243dc68a47b2
The first line contains a positive integer n (1 ≤ n ≤ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 ≤ xi, yi, zi ≤ 100).
1,000
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
standard output
PASSED
6d890d7fe8a996b2f53b29b6d98717fa
train_003.jsonl
1300809600
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
256 megabytes
import java.util.Scanner; public class Area { public static void main(String[] args) { Scanner bucky = new Scanner(System.in); int lines = bucky.nextInt()*3; int[] coords = new int[lines]; for(int i = 0 ; i < lines ; i++){ coords[i] = bucky.nextInt(); } ...
Java
["3\n4 1 7\n-2 4 -1\n1 -5 -3", "3\n3 -1 7\n-5 2 -4\n2 -1 -3"]
2 seconds
["NO", "YES"]
null
Java 7
standard input
[ "implementation", "math" ]
8ea24f3339b2ec67a769243dc68a47b2
The first line contains a positive integer n (1 ≤ n ≤ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 ≤ xi, yi, zi ≤ 100).
1,000
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
standard output
PASSED
fbeca05a3898b4746e61d3d0bd17fa80
train_003.jsonl
1300809600
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
256 megabytes
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ import java.io.*; /** * * @author student */ public class youngphy { public static void main(String args[])throws IOException ...
Java
["3\n4 1 7\n-2 4 -1\n1 -5 -3", "3\n3 -1 7\n-5 2 -4\n2 -1 -3"]
2 seconds
["NO", "YES"]
null
Java 7
standard input
[ "implementation", "math" ]
8ea24f3339b2ec67a769243dc68a47b2
The first line contains a positive integer n (1 ≤ n ≤ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 ≤ xi, yi, zi ≤ 100).
1,000
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
standard output
PASSED
4ca9d290b53f21be97c383c9c1e403a1
train_003.jsonl
1300809600
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
256 megabytes
import java.util.*; public class YoungPhysicist { public static void main(String[] args) { Scanner in=new Scanner(System.in); int n=in.nextInt();int x=0,y=0,z=0; int a[][]=new int[n][3]; for(int row=0;row<a.length;row++) for(int col=0;col<a[row].length;col++) { a[row][col]=in.ne...
Java
["3\n4 1 7\n-2 4 -1\n1 -5 -3", "3\n3 -1 7\n-5 2 -4\n2 -1 -3"]
2 seconds
["NO", "YES"]
null
Java 7
standard input
[ "implementation", "math" ]
8ea24f3339b2ec67a769243dc68a47b2
The first line contains a positive integer n (1 ≤ n ≤ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 ≤ xi, yi, zi ≤ 100).
1,000
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
standard output
PASSED
773b9bff6f4fd3707e298891a999d697
train_003.jsonl
1300809600
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
256 megabytes
import java.io.*; import java.util.*; public class Main { static Scanner in = new Scanner(System.in); static PrintWriter out = new PrintWriter(System.out); //Scanner scanner = new Scanner(new BufferedReader(new FileReader("input.txt"))); //PrintWriter out = new PrintWriter(new FileWriter...
Java
["3\n4 1 7\n-2 4 -1\n1 -5 -3", "3\n3 -1 7\n-5 2 -4\n2 -1 -3"]
2 seconds
["NO", "YES"]
null
Java 7
standard input
[ "implementation", "math" ]
8ea24f3339b2ec67a769243dc68a47b2
The first line contains a positive integer n (1 ≤ n ≤ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 ≤ xi, yi, zi ≤ 100).
1,000
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
standard output
PASSED
169697094f720ca377d2915b706a36dd
train_003.jsonl
1300809600
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
256 megabytes
import java.util.*; public class Phys { public static void main(String[]args){ Scanner sc=new Scanner(System.in); byte vectors=sc.nextByte(); byte x=0; byte y=0; byte z=0; for(byte i=0;i<vectors;i++){ byte inputx=sc.nextByte(); x+=inputx; byte inputy=sc.nextByte(); y+=inpu...
Java
["3\n4 1 7\n-2 4 -1\n1 -5 -3", "3\n3 -1 7\n-5 2 -4\n2 -1 -3"]
2 seconds
["NO", "YES"]
null
Java 7
standard input
[ "implementation", "math" ]
8ea24f3339b2ec67a769243dc68a47b2
The first line contains a positive integer n (1 ≤ n ≤ 100), then follow n lines containing three integers each: the xi coordinate, the yi coordinate and the zi coordinate of the force vector, applied to the body ( - 100 ≤ xi, yi, zi ≤ 100).
1,000
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
standard output
PASSED
a6aec3f62a961b907983afced509d3fe
train_003.jsonl
1421586000
Mr. Kitayuta's garden is planted with n bamboos. (Bamboos are tall, fast-growing tropical plants with hollow stems.) At the moment, the height of the i-th bamboo is hi meters, and it grows ai meters at the end of each day. Actually, Mr. Kitayuta hates these bamboos. He once attempted to cut them down, but failed becaus...
256 megabytes
import java.io.IOException; import java.io.OutputStreamWriter; import java.io.BufferedWriter; import java.util.InputMismatchException; import java.util.ArrayList; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Writer; import java.io.InputStream; /** * Built using CHelper plug-in * Actual sol...
Java
["3 1 2 5\n10 10\n10 10\n15 2", "2 10 10 1000000000\n0 10\n0 10", "5 3 3 10\n9 5\n9 2\n4 7\n9 10\n3 8"]
2 seconds
["17", "10", "14"]
null
Java 8
standard input
[ "binary search", "greedy" ]
608b152c0c15bf0a41465bfa7fa41866
The first line of the input contains four space-separated integers n, m, k and p (1 ≤ n ≤ 105, 1 ≤ m ≤ 5000, 1 ≤ k ≤ 10, 1 ≤ p ≤ 109). They represent the number of the bamboos in Mr. Kitayuta's garden, the duration of Mr. Kitayuta's fight in days, the maximum number of times that Mr. Kitayuta beat the bamboos during ea...
2,900
Print the lowest possible height of the tallest bamboo after m days.
standard output
PASSED
cee1a66946ff935ae842d69f8c406f40
train_003.jsonl
1421586000
Mr. Kitayuta's garden is planted with n bamboos. (Bamboos are tall, fast-growing tropical plants with hollow stems.) At the moment, the height of the i-th bamboo is hi meters, and it grows ai meters at the end of each day. Actually, Mr. Kitayuta hates these bamboos. He once attempted to cut them down, but failed becaus...
256 megabytes
//package round286; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class C { InputStream is; PrintWriter out; String INPUT = ""; void solve() { int n = ni(), m = n...
Java
["3 1 2 5\n10 10\n10 10\n15 2", "2 10 10 1000000000\n0 10\n0 10", "5 3 3 10\n9 5\n9 2\n4 7\n9 10\n3 8"]
2 seconds
["17", "10", "14"]
null
Java 8
standard input
[ "binary search", "greedy" ]
608b152c0c15bf0a41465bfa7fa41866
The first line of the input contains four space-separated integers n, m, k and p (1 ≤ n ≤ 105, 1 ≤ m ≤ 5000, 1 ≤ k ≤ 10, 1 ≤ p ≤ 109). They represent the number of the bamboos in Mr. Kitayuta's garden, the duration of Mr. Kitayuta's fight in days, the maximum number of times that Mr. Kitayuta beat the bamboos during ea...
2,900
Print the lowest possible height of the tallest bamboo after m days.
standard output
PASSED
ec9d25af7d1093cc0c5a88ff209c3282
train_003.jsonl
1564497300
You are given an array of $$$n$$$ integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.The GCD of a group of integers is the largest non-negative integer that divides all the integers i...
256 megabytes
import java.io.BufferedWriter; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.*; public class Test { static PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); int n; int[] a; static int readInt() { ...
Java
["4\n2 3 6 7", "5\n6 15 35 77 22", "5\n6 10 15 1000 75"]
0.5 seconds
["YES\n2 2 1 1", "YES\n2 1 2 1 1", "NO"]
null
Java 11
standard input
[ "greedy", "number theory", "probabilities" ]
973ef4e00b0489261fce852af11aa569
The first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$). The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the elements of the array.
2,900
In the first line print "YES" (without quotes), if it is possible to split the integers into two groups as required, and "NO" (without quotes) otherwise. If it is possible to split the integers, in the second line print $$$n$$$ integers, where the $$$i$$$-th integer is equal to $$$1$$$ if the integer $$$a_i$$$ should b...
standard output
PASSED
e6fd21b22de1882df1867c2e214fe085
train_003.jsonl
1564497300
You are given an array of $$$n$$$ integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.The GCD of a group of integers is the largest non-negative integer that divides all the integers i...
256 megabytes
import java.io.BufferedWriter; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Test { static PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System...
Java
["4\n2 3 6 7", "5\n6 15 35 77 22", "5\n6 10 15 1000 75"]
0.5 seconds
["YES\n2 2 1 1", "YES\n2 1 2 1 1", "NO"]
null
Java 11
standard input
[ "greedy", "number theory", "probabilities" ]
973ef4e00b0489261fce852af11aa569
The first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$). The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the elements of the array.
2,900
In the first line print "YES" (without quotes), if it is possible to split the integers into two groups as required, and "NO" (without quotes) otherwise. If it is possible to split the integers, in the second line print $$$n$$$ integers, where the $$$i$$$-th integer is equal to $$$1$$$ if the integer $$$a_i$$$ should b...
standard output
PASSED
ee70214ac3c47348c46b35e2407d85ff
train_003.jsonl
1564497300
You are given an array of $$$n$$$ integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.The GCD of a group of integers is the largest non-negative integer that divides all the integers i...
256 megabytes
import java.io.BufferedWriter; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.*; public class Test { static PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); int n; int[] a; static int readInt() { ...
Java
["4\n2 3 6 7", "5\n6 15 35 77 22", "5\n6 10 15 1000 75"]
0.5 seconds
["YES\n2 2 1 1", "YES\n2 1 2 1 1", "NO"]
null
Java 11
standard input
[ "greedy", "number theory", "probabilities" ]
973ef4e00b0489261fce852af11aa569
The first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$). The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the elements of the array.
2,900
In the first line print "YES" (without quotes), if it is possible to split the integers into two groups as required, and "NO" (without quotes) otherwise. If it is possible to split the integers, in the second line print $$$n$$$ integers, where the $$$i$$$-th integer is equal to $$$1$$$ if the integer $$$a_i$$$ should b...
standard output
PASSED
3dc33a7fff1455c29831f18f5d8526ea
train_003.jsonl
1383379200
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≤ l ≤ r ≤ n), such that the following conditions hold: there is integer j (l ≤ j ≤ r), such that all integers al, al + 1, ..., ar are divisible by aj; value r - l takes the maximum value amo...
256 megabytes
//package geometry; import java.io.*; import java.util.*; import java.util.Map.Entry; import java.text.*; import java.math.*; import java.util.regex.*; import java.awt.Point; /** * * @author prabhat // use stringbuilder,TreeSet, priorityQueue */ public class point4{ public static long[] BIT; public stati...
Java
["5\n4 6 9 3 6", "5\n1 3 5 7 9", "5\n2 3 5 7 11"]
2 seconds
["1 3\n2", "1 4\n1", "5 0\n1 2 3 4 5"]
NoteIn the first sample the pair of numbers is right, as numbers 6, 9, 3 are divisible by 3.In the second sample all numbers are divisible by number 1.In the third sample all numbers are prime, so conditions 1 and 2 are true only for pairs of numbers (1, 1), (2, 2), (3, 3), (4, 4), (5, 5).
Java 8
standard input
[ "two pointers", "math", "data structures", "binary search", "brute force" ]
da517ae908ba466da8ded87cec12a9fa
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 106).
2,000
Print two integers in the first line — the number of required pairs and the maximum value of r - l. On the following line print all l values from optimal pairs in increasing order.
standard output
PASSED
a1c75405e7c8e26865585e642fe1b07f
train_003.jsonl
1383379200
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≤ l ≤ r ≤ n), such that the following conditions hold: there is integer j (l ≤ j ≤ r), such that all integers al, al + 1, ..., ar are divisible by aj; value r - l takes the maximum value amo...
256 megabytes
// Problem : D. Pair of Numbers // Contest : Codeforces Round #209 (Div. 2) // URL : https://codeforces.com/contest/359/problem/D // Memory Limit : 256 MB // Time Limit : 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) import java.io.*; import java.util.*; public class a { public static void...
Java
["5\n4 6 9 3 6", "5\n1 3 5 7 9", "5\n2 3 5 7 11"]
2 seconds
["1 3\n2", "1 4\n1", "5 0\n1 2 3 4 5"]
NoteIn the first sample the pair of numbers is right, as numbers 6, 9, 3 are divisible by 3.In the second sample all numbers are divisible by number 1.In the third sample all numbers are prime, so conditions 1 and 2 are true only for pairs of numbers (1, 1), (2, 2), (3, 3), (4, 4), (5, 5).
Java 8
standard input
[ "two pointers", "math", "data structures", "binary search", "brute force" ]
da517ae908ba466da8ded87cec12a9fa
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 106).
2,000
Print two integers in the first line — the number of required pairs and the maximum value of r - l. On the following line print all l values from optimal pairs in increasing order.
standard output
PASSED
49bee22671b9947bbb5ded2a41e44a84
train_003.jsonl
1383379200
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≤ l ≤ r ≤ n), such that the following conditions hold: there is integer j (l ≤ j ≤ r), such that all integers al, al + 1, ..., ar are divisible by aj; value r - l takes the maximum value amo...
256 megabytes
import java.util.*; import java.io.*; public class _0359_D_PairOfNumbers { static int org[], tbl[][], N, logN, pow2[]; public static void build() { for(int i = 1; i<=N; i++) tbl[i][0] = org[i]; for(int i = 1; i<=logN; i++) for(int j = 1; j<=N-(1<<i)+1; j++) tbl[j][i] = gcd(tbl[j][i-1], tbl[j+(1<<(i-1))][i-1]...
Java
["5\n4 6 9 3 6", "5\n1 3 5 7 9", "5\n2 3 5 7 11"]
2 seconds
["1 3\n2", "1 4\n1", "5 0\n1 2 3 4 5"]
NoteIn the first sample the pair of numbers is right, as numbers 6, 9, 3 are divisible by 3.In the second sample all numbers are divisible by number 1.In the third sample all numbers are prime, so conditions 1 and 2 are true only for pairs of numbers (1, 1), (2, 2), (3, 3), (4, 4), (5, 5).
Java 8
standard input
[ "two pointers", "math", "data structures", "binary search", "brute force" ]
da517ae908ba466da8ded87cec12a9fa
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 106).
2,000
Print two integers in the first line — the number of required pairs and the maximum value of r - l. On the following line print all l values from optimal pairs in increasing order.
standard output
PASSED
44cc0340f42244e0fcd9c191c9ba37a7
train_003.jsonl
1383379200
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≤ l ≤ r ≤ n), such that the following conditions hold: there is integer j (l ≤ j ≤ r), such that all integers al, al + 1, ..., ar are divisible by aj; value r - l takes the maximum value amo...
256 megabytes
import java.io.*; import java.math.*; import java.util.*; import static java.util.Arrays.fill; import static java.lang.Math.*; import static java.util.Arrays.sort; import static java.util.Collections.sort; public class D359_ST { public static int mod = 1000000007; public static long INF = (1L << 60); static Fa...
Java
["5\n4 6 9 3 6", "5\n1 3 5 7 9", "5\n2 3 5 7 11"]
2 seconds
["1 3\n2", "1 4\n1", "5 0\n1 2 3 4 5"]
NoteIn the first sample the pair of numbers is right, as numbers 6, 9, 3 are divisible by 3.In the second sample all numbers are divisible by number 1.In the third sample all numbers are prime, so conditions 1 and 2 are true only for pairs of numbers (1, 1), (2, 2), (3, 3), (4, 4), (5, 5).
Java 8
standard input
[ "two pointers", "math", "data structures", "binary search", "brute force" ]
da517ae908ba466da8ded87cec12a9fa
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 106).
2,000
Print two integers in the first line — the number of required pairs and the maximum value of r - l. On the following line print all l values from optimal pairs in increasing order.
standard output
PASSED
87c45b906639810d3851ca5008cb4c5b
train_003.jsonl
1383379200
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≤ l ≤ r ≤ n), such that the following conditions hold: there is integer j (l ≤ j ≤ r), such that all integers al, al + 1, ..., ar are divisible by aj; value r - l takes the maximum value amo...
256 megabytes
import java.io.*; import java.math.*; import java.util.*; import static java.util.Arrays.fill; import static java.lang.Math.*; import static java.util.Arrays.sort; import static java.util.Collections.sort; public class D359 { public static int mod = 1000000007; public static long INF = (1L << 60); static FastS...
Java
["5\n4 6 9 3 6", "5\n1 3 5 7 9", "5\n2 3 5 7 11"]
2 seconds
["1 3\n2", "1 4\n1", "5 0\n1 2 3 4 5"]
NoteIn the first sample the pair of numbers is right, as numbers 6, 9, 3 are divisible by 3.In the second sample all numbers are divisible by number 1.In the third sample all numbers are prime, so conditions 1 and 2 are true only for pairs of numbers (1, 1), (2, 2), (3, 3), (4, 4), (5, 5).
Java 8
standard input
[ "two pointers", "math", "data structures", "binary search", "brute force" ]
da517ae908ba466da8ded87cec12a9fa
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 106).
2,000
Print two integers in the first line — the number of required pairs and the maximum value of r - l. On the following line print all l values from optimal pairs in increasing order.
standard output
PASSED
de3f7443a7e7e586a6398f7fbdeb884a
train_003.jsonl
1383379200
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≤ l ≤ r ≤ n), such that the following conditions hold: there is integer j (l ≤ j ≤ r), such that all integers al, al + 1, ..., ar are divisible by aj; value r - l takes the maximum value amo...
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.lang.reflect.Array; import java.math.BigInteger; import java.util.*; import java.util.stream.IntStream; import java.util.stream.Stream; public class CodeChef implements Runnable { ...
Java
["5\n4 6 9 3 6", "5\n1 3 5 7 9", "5\n2 3 5 7 11"]
2 seconds
["1 3\n2", "1 4\n1", "5 0\n1 2 3 4 5"]
NoteIn the first sample the pair of numbers is right, as numbers 6, 9, 3 are divisible by 3.In the second sample all numbers are divisible by number 1.In the third sample all numbers are prime, so conditions 1 and 2 are true only for pairs of numbers (1, 1), (2, 2), (3, 3), (4, 4), (5, 5).
Java 8
standard input
[ "two pointers", "math", "data structures", "binary search", "brute force" ]
da517ae908ba466da8ded87cec12a9fa
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 106).
2,000
Print two integers in the first line — the number of required pairs and the maximum value of r - l. On the following line print all l values from optimal pairs in increasing order.
standard output
PASSED
e50f6f440ff97d33e80a9be2e14241c0
train_003.jsonl
1383379200
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≤ l ≤ r ≤ n), such that the following conditions hold: there is integer j (l ≤ j ≤ r), such that all integers al, al + 1, ..., ar are divisible by aj; value r - l takes the maximum value amo...
256 megabytes
import java.io.*; import java.util.*; public class D { static StringBuilder st = new StringBuilder(); 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] ; St...
Java
["5\n4 6 9 3 6", "5\n1 3 5 7 9", "5\n2 3 5 7 11"]
2 seconds
["1 3\n2", "1 4\n1", "5 0\n1 2 3 4 5"]
NoteIn the first sample the pair of numbers is right, as numbers 6, 9, 3 are divisible by 3.In the second sample all numbers are divisible by number 1.In the third sample all numbers are prime, so conditions 1 and 2 are true only for pairs of numbers (1, 1), (2, 2), (3, 3), (4, 4), (5, 5).
Java 8
standard input
[ "two pointers", "math", "data structures", "binary search", "brute force" ]
da517ae908ba466da8ded87cec12a9fa
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 106).
2,000
Print two integers in the first line — the number of required pairs and the maximum value of r - l. On the following line print all l values from optimal pairs in increasing order.
standard output
PASSED
7b40d41a4bc1bc3013bf382cc5ff6e37
train_003.jsonl
1383379200
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≤ l ≤ r ≤ n), such that the following conditions hold: there is integer j (l ≤ j ≤ r), such that all integers al, al + 1, ..., ar are divisible by aj; value r - l takes the maximum value amo...
256 megabytes
import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Scanner; import java.util.StringTokenizer; public class l073 { public static void main(String[] args) throws Exception { // StringTokenizer stok = new StringToke...
Java
["5\n4 6 9 3 6", "5\n1 3 5 7 9", "5\n2 3 5 7 11"]
2 seconds
["1 3\n2", "1 4\n1", "5 0\n1 2 3 4 5"]
NoteIn the first sample the pair of numbers is right, as numbers 6, 9, 3 are divisible by 3.In the second sample all numbers are divisible by number 1.In the third sample all numbers are prime, so conditions 1 and 2 are true only for pairs of numbers (1, 1), (2, 2), (3, 3), (4, 4), (5, 5).
Java 8
standard input
[ "two pointers", "math", "data structures", "binary search", "brute force" ]
da517ae908ba466da8ded87cec12a9fa
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 106).
2,000
Print two integers in the first line — the number of required pairs and the maximum value of r - l. On the following line print all l values from optimal pairs in increasing order.
standard output
PASSED
8798d36f3e52c7db2b7457a188e9b331
train_003.jsonl
1383379200
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≤ l ≤ r ≤ n), such that the following conditions hold: there is integer j (l ≤ j ≤ r), such that all integers al, al + 1, ..., ar are divisible by aj; value r - l takes the maximum value amo...
256 megabytes
import java.io.*; import java.util.*; public class B { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = sc.nextInt(), a[] = new int[n]; for(int i = 0; i < n; ++i) a[i] = sc.nextInt(); int[] L = new...
Java
["5\n4 6 9 3 6", "5\n1 3 5 7 9", "5\n2 3 5 7 11"]
2 seconds
["1 3\n2", "1 4\n1", "5 0\n1 2 3 4 5"]
NoteIn the first sample the pair of numbers is right, as numbers 6, 9, 3 are divisible by 3.In the second sample all numbers are divisible by number 1.In the third sample all numbers are prime, so conditions 1 and 2 are true only for pairs of numbers (1, 1), (2, 2), (3, 3), (4, 4), (5, 5).
Java 8
standard input
[ "two pointers", "math", "data structures", "binary search", "brute force" ]
da517ae908ba466da8ded87cec12a9fa
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 106).
2,000
Print two integers in the first line — the number of required pairs and the maximum value of r - l. On the following line print all l values from optimal pairs in increasing order.
standard output
PASSED
f3c97fe0eea788e5f9012206928f30a3
train_003.jsonl
1383379200
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≤ l ≤ r ≤ n), such that the following conditions hold: there is integer j (l ≤ j ≤ r), such that all integers al, al + 1, ..., ar are divisible by aj; value r - l takes the maximum value amo...
256 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 D359 { static class Scanner { BufferedReader br; StringTokenizer tk=new StringTokenizer(""); ...
Java
["5\n4 6 9 3 6", "5\n1 3 5 7 9", "5\n2 3 5 7 11"]
2 seconds
["1 3\n2", "1 4\n1", "5 0\n1 2 3 4 5"]
NoteIn the first sample the pair of numbers is right, as numbers 6, 9, 3 are divisible by 3.In the second sample all numbers are divisible by number 1.In the third sample all numbers are prime, so conditions 1 and 2 are true only for pairs of numbers (1, 1), (2, 2), (3, 3), (4, 4), (5, 5).
Java 8
standard input
[ "two pointers", "math", "data structures", "binary search", "brute force" ]
da517ae908ba466da8ded87cec12a9fa
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 106).
2,000
Print two integers in the first line — the number of required pairs and the maximum value of r - l. On the following line print all l values from optimal pairs in increasing order.
standard output
PASSED
3e76fd607eb07eb243216370917682e6
train_003.jsonl
1383379200
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≤ l ≤ r ≤ n), such that the following conditions hold: there is integer j (l ≤ j ≤ r), such that all integers al, al + 1, ..., ar are divisible by aj; value r - l takes the maximum value amo...
256 megabytes
import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.*; public class CODEFORCES_359_D { public static void main (String[] t) throws IOException { INPUT in = new INPUT (System.in); PrintWriter out = new PrintWriter (System.out); ...
Java
["5\n4 6 9 3 6", "5\n1 3 5 7 9", "5\n2 3 5 7 11"]
2 seconds
["1 3\n2", "1 4\n1", "5 0\n1 2 3 4 5"]
NoteIn the first sample the pair of numbers is right, as numbers 6, 9, 3 are divisible by 3.In the second sample all numbers are divisible by number 1.In the third sample all numbers are prime, so conditions 1 and 2 are true only for pairs of numbers (1, 1), (2, 2), (3, 3), (4, 4), (5, 5).
Java 8
standard input
[ "two pointers", "math", "data structures", "binary search", "brute force" ]
da517ae908ba466da8ded87cec12a9fa
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 106).
2,000
Print two integers in the first line — the number of required pairs and the maximum value of r - l. On the following line print all l values from optimal pairs in increasing order.
standard output
PASSED
e47d06e2d29d980530c15cd88a581ea3
train_003.jsonl
1383379200
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≤ l ≤ r ≤ n), such that the following conditions hold: there is integer j (l ≤ j ≤ r), such that all integers al, al + 1, ..., ar are divisible by aj; value r - l takes the maximum value amo...
256 megabytes
import java.io.*; import java.util.*; /* * Heart beats fast * Colors and promises * How to be brave * How can I love when I am afraid to fall... */ //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?) public class Main...
Java
["5\n4 6 9 3 6", "5\n1 3 5 7 9", "5\n2 3 5 7 11"]
2 seconds
["1 3\n2", "1 4\n1", "5 0\n1 2 3 4 5"]
NoteIn the first sample the pair of numbers is right, as numbers 6, 9, 3 are divisible by 3.In the second sample all numbers are divisible by number 1.In the third sample all numbers are prime, so conditions 1 and 2 are true only for pairs of numbers (1, 1), (2, 2), (3, 3), (4, 4), (5, 5).
Java 8
standard input
[ "two pointers", "math", "data structures", "binary search", "brute force" ]
da517ae908ba466da8ded87cec12a9fa
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 106).
2,000
Print two integers in the first line — the number of required pairs and the maximum value of r - l. On the following line print all l values from optimal pairs in increasing order.
standard output
PASSED
6a1e1b2965b8f1de92a1647a572bdfcc
train_003.jsonl
1383379200
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≤ l ≤ r ≤ n), such that the following conditions hold: there is integer j (l ≤ j ≤ r), such that all integers al, al + 1, ..., ar are divisible by aj; value r - l takes the maximum value amo...
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; import java.io.BufferedReader; import java.util.Comparator; ...
Java
["5\n4 6 9 3 6", "5\n1 3 5 7 9", "5\n2 3 5 7 11"]
2 seconds
["1 3\n2", "1 4\n1", "5 0\n1 2 3 4 5"]
NoteIn the first sample the pair of numbers is right, as numbers 6, 9, 3 are divisible by 3.In the second sample all numbers are divisible by number 1.In the third sample all numbers are prime, so conditions 1 and 2 are true only for pairs of numbers (1, 1), (2, 2), (3, 3), (4, 4), (5, 5).
Java 8
standard input
[ "two pointers", "math", "data structures", "binary search", "brute force" ]
da517ae908ba466da8ded87cec12a9fa
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 106).
2,000
Print two integers in the first line — the number of required pairs and the maximum value of r - l. On the following line print all l values from optimal pairs in increasing order.
standard output
PASSED
6c07064b69617dbf09da880fe70ee23e
train_003.jsonl
1383379200
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≤ l ≤ r ≤ n), such that the following conditions hold: there is integer j (l ≤ j ≤ r), such that all integers al, al + 1, ..., ar are divisible by aj; value r - l takes the maximum value amo...
256 megabytes
//package pairofno; import java.util.*; import java.io.*; public class Pairofno { 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 =...
Java
["5\n4 6 9 3 6", "5\n1 3 5 7 9", "5\n2 3 5 7 11"]
2 seconds
["1 3\n2", "1 4\n1", "5 0\n1 2 3 4 5"]
NoteIn the first sample the pair of numbers is right, as numbers 6, 9, 3 are divisible by 3.In the second sample all numbers are divisible by number 1.In the third sample all numbers are prime, so conditions 1 and 2 are true only for pairs of numbers (1, 1), (2, 2), (3, 3), (4, 4), (5, 5).
Java 8
standard input
[ "two pointers", "math", "data structures", "binary search", "brute force" ]
da517ae908ba466da8ded87cec12a9fa
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 106).
2,000
Print two integers in the first line — the number of required pairs and the maximum value of r - l. On the following line print all l values from optimal pairs in increasing order.
standard output
PASSED
7826916b1a97e9a1497e1039dc020307
train_003.jsonl
1383379200
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≤ l ≤ r ≤ n), such that the following conditions hold: there is integer j (l ≤ j ≤ r), such that all integers al, al + 1, ..., ar are divisible by aj; value r - l takes the maximum value amo...
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.Stack; import java.util.StringTokenizer; import java.util.TreeSet; public class A { public static void main(String[] args) throws Except...
Java
["5\n4 6 9 3 6", "5\n1 3 5 7 9", "5\n2 3 5 7 11"]
2 seconds
["1 3\n2", "1 4\n1", "5 0\n1 2 3 4 5"]
NoteIn the first sample the pair of numbers is right, as numbers 6, 9, 3 are divisible by 3.In the second sample all numbers are divisible by number 1.In the third sample all numbers are prime, so conditions 1 and 2 are true only for pairs of numbers (1, 1), (2, 2), (3, 3), (4, 4), (5, 5).
Java 8
standard input
[ "two pointers", "math", "data structures", "binary search", "brute force" ]
da517ae908ba466da8ded87cec12a9fa
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 106).
2,000
Print two integers in the first line — the number of required pairs and the maximum value of r - l. On the following line print all l values from optimal pairs in increasing order.
standard output
PASSED
841e3e4d6a8caa77df5fd3376a2e4188
train_003.jsonl
1383379200
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≤ l ≤ r ≤ n), such that the following conditions hold: there is integer j (l ≤ j ≤ r), such that all integers al, al + 1, ..., ar are divisible by aj; value r - l takes the maximum value amo...
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.Stack; import java.util.StringTokenizer; import java.util.TreeSet; public class A { public static void main(String[] args) throws Except...
Java
["5\n4 6 9 3 6", "5\n1 3 5 7 9", "5\n2 3 5 7 11"]
2 seconds
["1 3\n2", "1 4\n1", "5 0\n1 2 3 4 5"]
NoteIn the first sample the pair of numbers is right, as numbers 6, 9, 3 are divisible by 3.In the second sample all numbers are divisible by number 1.In the third sample all numbers are prime, so conditions 1 and 2 are true only for pairs of numbers (1, 1), (2, 2), (3, 3), (4, 4), (5, 5).
Java 8
standard input
[ "two pointers", "math", "data structures", "binary search", "brute force" ]
da517ae908ba466da8ded87cec12a9fa
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 106).
2,000
Print two integers in the first line — the number of required pairs and the maximum value of r - l. On the following line print all l values from optimal pairs in increasing order.
standard output
PASSED
15db9e1b9f78d10f2cd9eb573c4a761a
train_003.jsonl
1383379200
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≤ l ≤ r ≤ n), such that the following conditions hold: there is integer j (l ≤ j ≤ r), such that all integers al, al + 1, ..., ar are divisible by aj; value r - l takes the maximum value amo...
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.ArrayList; import java.util.InputMismatchException; import java.util.PriorityQueue; import java.util.TreeMap; import jav...
Java
["5\n4 6 9 3 6", "5\n1 3 5 7 9", "5\n2 3 5 7 11"]
2 seconds
["1 3\n2", "1 4\n1", "5 0\n1 2 3 4 5"]
NoteIn the first sample the pair of numbers is right, as numbers 6, 9, 3 are divisible by 3.In the second sample all numbers are divisible by number 1.In the third sample all numbers are prime, so conditions 1 and 2 are true only for pairs of numbers (1, 1), (2, 2), (3, 3), (4, 4), (5, 5).
Java 8
standard input
[ "two pointers", "math", "data structures", "binary search", "brute force" ]
da517ae908ba466da8ded87cec12a9fa
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 106).
2,000
Print two integers in the first line — the number of required pairs and the maximum value of r - l. On the following line print all l values from optimal pairs in increasing order.
standard output
PASSED
5cd3ff2c993dd1e0d5f8d41c8fae6f53
train_003.jsonl
1383379200
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≤ l ≤ r ≤ n), such that the following conditions hold: there is integer j (l ≤ j ≤ r), such that all integers al, al + 1, ..., ar are divisible by aj; value r - l takes the maximum value amo...
256 megabytes
import java.io.*; import java.util.*; public class Main { FastScanner in; PrintWriter out; static final String FILE = ""; int gcd(int a, int b) { int c; while (a != 0) { c = a; a = b % a; b = c; } return b; } public class Rm...
Java
["5\n4 6 9 3 6", "5\n1 3 5 7 9", "5\n2 3 5 7 11"]
2 seconds
["1 3\n2", "1 4\n1", "5 0\n1 2 3 4 5"]
NoteIn the first sample the pair of numbers is right, as numbers 6, 9, 3 are divisible by 3.In the second sample all numbers are divisible by number 1.In the third sample all numbers are prime, so conditions 1 and 2 are true only for pairs of numbers (1, 1), (2, 2), (3, 3), (4, 4), (5, 5).
Java 8
standard input
[ "two pointers", "math", "data structures", "binary search", "brute force" ]
da517ae908ba466da8ded87cec12a9fa
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 106).
2,000
Print two integers in the first line — the number of required pairs and the maximum value of r - l. On the following line print all l values from optimal pairs in increasing order.
standard output
PASSED
5199aae5500c42044ae3108e849a76e9
train_003.jsonl
1383379200
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≤ l ≤ r ≤ n), such that the following conditions hold: there is integer j (l ≤ j ≤ r), such that all integers al, al + 1, ..., ar are divisible by aj; value r - l takes the maximum value amo...
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.TreeSet; public final class _209D_PairofNumbers { public static int left(int arr[], int idx) { int count = 0; for (int i = idx; i >= 0 && arr[i] % arr[idx] == 0; i -= 1)...
Java
["5\n4 6 9 3 6", "5\n1 3 5 7 9", "5\n2 3 5 7 11"]
2 seconds
["1 3\n2", "1 4\n1", "5 0\n1 2 3 4 5"]
NoteIn the first sample the pair of numbers is right, as numbers 6, 9, 3 are divisible by 3.In the second sample all numbers are divisible by number 1.In the third sample all numbers are prime, so conditions 1 and 2 are true only for pairs of numbers (1, 1), (2, 2), (3, 3), (4, 4), (5, 5).
Java 8
standard input
[ "two pointers", "math", "data structures", "binary search", "brute force" ]
da517ae908ba466da8ded87cec12a9fa
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 106).
2,000
Print two integers in the first line — the number of required pairs and the maximum value of r - l. On the following line print all l values from optimal pairs in increasing order.
standard output
PASSED
36cfc1be9d31d56ce1a95efeb6229245
train_003.jsonl
1383379200
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≤ l ≤ r ≤ n), such that the following conditions hold: there is integer j (l ≤ j ≤ r), such that all integers al, al + 1, ..., ar are divisible by aj; value r - l takes the maximum value amo...
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.Input...
Java
["5\n4 6 9 3 6", "5\n1 3 5 7 9", "5\n2 3 5 7 11"]
2 seconds
["1 3\n2", "1 4\n1", "5 0\n1 2 3 4 5"]
NoteIn the first sample the pair of numbers is right, as numbers 6, 9, 3 are divisible by 3.In the second sample all numbers are divisible by number 1.In the third sample all numbers are prime, so conditions 1 and 2 are true only for pairs of numbers (1, 1), (2, 2), (3, 3), (4, 4), (5, 5).
Java 8
standard input
[ "two pointers", "math", "data structures", "binary search", "brute force" ]
da517ae908ba466da8ded87cec12a9fa
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 106).
2,000
Print two integers in the first line — the number of required pairs and the maximum value of r - l. On the following line print all l values from optimal pairs in increasing order.
standard output
PASSED
0d51c0f544546f1bcaabc4fa0f47a2f3
train_003.jsonl
1383379200
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≤ l ≤ r ≤ n), such that the following conditions hold: there is integer j (l ≤ j ≤ r), such that all integers al, al + 1, ..., ar are divisible by aj; value r - l takes the maximum value amo...
256 megabytes
import java.util.*; public class HelloWorld { static class Pair{ int v; int indx; } public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr = new int[n]; int[] ind = new int[n]; HashMap<Integer...
Java
["5\n4 6 9 3 6", "5\n1 3 5 7 9", "5\n2 3 5 7 11"]
2 seconds
["1 3\n2", "1 4\n1", "5 0\n1 2 3 4 5"]
NoteIn the first sample the pair of numbers is right, as numbers 6, 9, 3 are divisible by 3.In the second sample all numbers are divisible by number 1.In the third sample all numbers are prime, so conditions 1 and 2 are true only for pairs of numbers (1, 1), (2, 2), (3, 3), (4, 4), (5, 5).
Java 8
standard input
[ "two pointers", "math", "data structures", "binary search", "brute force" ]
da517ae908ba466da8ded87cec12a9fa
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 106).
2,000
Print two integers in the first line — the number of required pairs and the maximum value of r - l. On the following line print all l values from optimal pairs in increasing order.
standard output
PASSED
fe1c6b081a4408558a99266bab2a98e8
train_003.jsonl
1383379200
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≤ l ≤ r ≤ n), such that the following conditions hold: there is integer j (l ≤ j ≤ r), such that all integers al, al + 1, ..., ar are divisible by aj; value r - l takes the maximum value amo...
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main { static int mod=(int)1e9+7; public static void main(String[] args) throws Exception { FastReader sc = new FastReader(); StringBuilder sb=new StringBuilder(); ...
Java
["5\n4 6 9 3 6", "5\n1 3 5 7 9", "5\n2 3 5 7 11"]
2 seconds
["1 3\n2", "1 4\n1", "5 0\n1 2 3 4 5"]
NoteIn the first sample the pair of numbers is right, as numbers 6, 9, 3 are divisible by 3.In the second sample all numbers are divisible by number 1.In the third sample all numbers are prime, so conditions 1 and 2 are true only for pairs of numbers (1, 1), (2, 2), (3, 3), (4, 4), (5, 5).
Java 8
standard input
[ "two pointers", "math", "data structures", "binary search", "brute force" ]
da517ae908ba466da8ded87cec12a9fa
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 106).
2,000
Print two integers in the first line — the number of required pairs and the maximum value of r - l. On the following line print all l values from optimal pairs in increasing order.
standard output
PASSED
17142690fb274735df60945ffca61791
train_003.jsonl
1383379200
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≤ l ≤ r ≤ n), such that the following conditions hold: there is integer j (l ≤ j ≤ r), such that all integers al, al + 1, ..., ar are divisible by aj; value r - l takes the maximum value amo...
256 megabytes
import java.util.*; import java.io.*; /*NO RESPECT*/ public class Main implements Runnable { static boolean showTime = false; public int gcd(int m, int n){ if(n == 0) return m; else return gcd(n, m % n); } private int getGcd(int...
Java
["5\n4 6 9 3 6", "5\n1 3 5 7 9", "5\n2 3 5 7 11"]
2 seconds
["1 3\n2", "1 4\n1", "5 0\n1 2 3 4 5"]
NoteIn the first sample the pair of numbers is right, as numbers 6, 9, 3 are divisible by 3.In the second sample all numbers are divisible by number 1.In the third sample all numbers are prime, so conditions 1 and 2 are true only for pairs of numbers (1, 1), (2, 2), (3, 3), (4, 4), (5, 5).
Java 8
standard input
[ "two pointers", "math", "data structures", "binary search", "brute force" ]
da517ae908ba466da8ded87cec12a9fa
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 106).
2,000
Print two integers in the first line — the number of required pairs and the maximum value of r - l. On the following line print all l values from optimal pairs in increasing order.
standard output
PASSED
a1c36fd343c659c71318ef76b48ab645
train_003.jsonl
1383379200
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≤ l ≤ r ≤ n), such that the following conditions hold: there is integer j (l ≤ j ≤ r), such that all integers al, al + 1, ..., ar are divisible by aj; value r - l takes the maximum value amo...
256 megabytes
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class main_java { public static void main(String[] args) { InputStream inputStream = System.in; InputReader in = new InputReader(inputStream)...
Java
["5\n4 6 9 3 6", "5\n1 3 5 7 9", "5\n2 3 5 7 11"]
2 seconds
["1 3\n2", "1 4\n1", "5 0\n1 2 3 4 5"]
NoteIn the first sample the pair of numbers is right, as numbers 6, 9, 3 are divisible by 3.In the second sample all numbers are divisible by number 1.In the third sample all numbers are prime, so conditions 1 and 2 are true only for pairs of numbers (1, 1), (2, 2), (3, 3), (4, 4), (5, 5).
Java 8
standard input
[ "two pointers", "math", "data structures", "binary search", "brute force" ]
da517ae908ba466da8ded87cec12a9fa
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 106).
2,000
Print two integers in the first line — the number of required pairs and the maximum value of r - l. On the following line print all l values from optimal pairs in increasing order.
standard output
PASSED
0ed609f64a6b226d0fd341a57f71af0a
train_003.jsonl
1383379200
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≤ l ≤ r ≤ n), such that the following conditions hold: there is integer j (l ≤ j ≤ r), such that all integers al, al + 1, ..., ar are divisible by aj; value r - l takes the maximum value amo...
256 megabytes
import java.io.*; import java.util.*; public class Solution{ InputStream is; static PrintWriter out; String INPUT = ""; static int mod = (int)1e9+7; public void solve(){ int n = ni(); double[] a = new double[n+2]; a[0] = mod + 0.13; a[n+1] = mod+0.13; for(int i = 1; i <= n; i++)a[i] = nd(); //System.o...
Java
["5\n4 6 9 3 6", "5\n1 3 5 7 9", "5\n2 3 5 7 11"]
2 seconds
["1 3\n2", "1 4\n1", "5 0\n1 2 3 4 5"]
NoteIn the first sample the pair of numbers is right, as numbers 6, 9, 3 are divisible by 3.In the second sample all numbers are divisible by number 1.In the third sample all numbers are prime, so conditions 1 and 2 are true only for pairs of numbers (1, 1), (2, 2), (3, 3), (4, 4), (5, 5).
Java 8
standard input
[ "two pointers", "math", "data structures", "binary search", "brute force" ]
da517ae908ba466da8ded87cec12a9fa
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 106).
2,000
Print two integers in the first line — the number of required pairs and the maximum value of r - l. On the following line print all l values from optimal pairs in increasing order.
standard output
PASSED
1f2058b25df8a13c1e5e5b5323fb2dbe
train_003.jsonl
1383379200
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≤ l ≤ r ≤ n), such that the following conditions hold: there is integer j (l ≤ j ≤ r), such that all integers al, al + 1, ..., ar are divisible by aj; value r - l takes the maximum value amo...
256 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.util.ArrayList; import java.io.InputStream; /** * Built using CHel...
Java
["5\n4 6 9 3 6", "5\n1 3 5 7 9", "5\n2 3 5 7 11"]
2 seconds
["1 3\n2", "1 4\n1", "5 0\n1 2 3 4 5"]
NoteIn the first sample the pair of numbers is right, as numbers 6, 9, 3 are divisible by 3.In the second sample all numbers are divisible by number 1.In the third sample all numbers are prime, so conditions 1 and 2 are true only for pairs of numbers (1, 1), (2, 2), (3, 3), (4, 4), (5, 5).
Java 8
standard input
[ "two pointers", "math", "data structures", "binary search", "brute force" ]
da517ae908ba466da8ded87cec12a9fa
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 106).
2,000
Print two integers in the first line — the number of required pairs and the maximum value of r - l. On the following line print all l values from optimal pairs in increasing order.
standard output
PASSED
e99770559eaab3fc6ea058f31cb17060
train_003.jsonl
1383379200
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≤ l ≤ r ≤ n), such that the following conditions hold: there is integer j (l ≤ j ≤ r), such that all integers al, al + 1, ..., ar are divisible by aj; value r - l takes the maximum value amo...
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class code5 { InputStream is; PrintWriter out; static long mod=pow(10,9)+7; void solve() { int n=ni(); int a[]=na(n); Stack<Integer> s=new Stack<Integer>(); int right[]=new int[n]; Arrays.fill(right,-1); for(int i=0;i<n;i++) { if(...
Java
["5\n4 6 9 3 6", "5\n1 3 5 7 9", "5\n2 3 5 7 11"]
2 seconds
["1 3\n2", "1 4\n1", "5 0\n1 2 3 4 5"]
NoteIn the first sample the pair of numbers is right, as numbers 6, 9, 3 are divisible by 3.In the second sample all numbers are divisible by number 1.In the third sample all numbers are prime, so conditions 1 and 2 are true only for pairs of numbers (1, 1), (2, 2), (3, 3), (4, 4), (5, 5).
Java 8
standard input
[ "two pointers", "math", "data structures", "binary search", "brute force" ]
da517ae908ba466da8ded87cec12a9fa
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 106).
2,000
Print two integers in the first line — the number of required pairs and the maximum value of r - l. On the following line print all l values from optimal pairs in increasing order.
standard output
PASSED
6685829a75abaa6f8794e771a4f482be
train_003.jsonl
1383379200
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≤ l ≤ r ≤ n), such that the following conditions hold: there is integer j (l ≤ j ≤ r), such that all integers al, al + 1, ..., ar are divisible by aj; value r - l takes the maximum value amo...
256 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.util.ArrayList; import java.io.InputStream; /** * Built using CHel...
Java
["5\n4 6 9 3 6", "5\n1 3 5 7 9", "5\n2 3 5 7 11"]
2 seconds
["1 3\n2", "1 4\n1", "5 0\n1 2 3 4 5"]
NoteIn the first sample the pair of numbers is right, as numbers 6, 9, 3 are divisible by 3.In the second sample all numbers are divisible by number 1.In the third sample all numbers are prime, so conditions 1 and 2 are true only for pairs of numbers (1, 1), (2, 2), (3, 3), (4, 4), (5, 5).
Java 8
standard input
[ "two pointers", "math", "data structures", "binary search", "brute force" ]
da517ae908ba466da8ded87cec12a9fa
The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 106).
2,000
Print two integers in the first line — the number of required pairs and the maximum value of r - l. On the following line print all l values from optimal pairs in increasing order.
standard output
PASSED
2fc786b32a3aacfff0cfc50776ab6093
train_003.jsonl
1584018300
You are given a tree consisting of $$$n$$$ vertices. A tree is a connected undirected graph with $$$n-1$$$ edges. Each vertex $$$v$$$ of this tree has a color assigned to it ($$$a_v = 1$$$ if the vertex $$$v$$$ is white and $$$0$$$ if the vertex $$$v$$$ is black).You have to solve the following problem for each vertex ...
256 megabytes
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashMap; import java.util.InputMismatchException; public class F { private static int n; private static HashMap<Integer, ArrayList<Integer>> g; private static int[] color; private sta...
Java
["9\n0 1 1 1 0 0 0 0 1\n1 2\n1 3\n3 4\n3 5\n2 6\n4 7\n6 8\n5 9", "4\n0 0 1 0\n1 2\n1 3\n1 4"]
2 seconds
["2 2 2 2 2 1 1 0 2", "0 -1 1 -1"]
NoteThe first example is shown below:The black vertices have bold borders.In the second example, the best subtree for vertices $$$2, 3$$$ and $$$4$$$ are vertices $$$2, 3$$$ and $$$4$$$ correspondingly. And the best subtree for the vertex $$$1$$$ is the subtree consisting of vertices $$$1$$$ and $$$3$$$.
Java 8
standard input
[ "dp", "dfs and similar", "trees", "graphs" ]
cb8895ddd54ffbd898b1bf5e169feb63
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of vertices in the tree. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i$$$ is the color of the $$$i$$$-th vertex. Each of the next $$$n-1$$$ lin...
1,800
Print $$$n$$$ integers $$$res_1, res_2, \dots, res_n$$$, where $$$res_i$$$ is the maximum possible difference between the number of white and black vertices in some subtree that contains the vertex $$$i$$$.
standard output
PASSED
e8230d0ef47594c724e78a957066f4d7
train_003.jsonl
1584018300
You are given a tree consisting of $$$n$$$ vertices. A tree is a connected undirected graph with $$$n-1$$$ edges. Each vertex $$$v$$$ of this tree has a color assigned to it ($$$a_v = 1$$$ if the vertex $$$v$$$ is white and $$$0$$$ if the vertex $$$v$$$ is black).You have to solve the following problem for each vertex ...
256 megabytes
import java.util.*; public class Main { private static final Scanner sc = new Scanner(System.in); static void print(int[] x) { StringBuilder ans = new StringBuilder(); for (int y : x) ans.append(y + " "); System.out.println(ans); } static class Tree { int size; ...
Java
["9\n0 1 1 1 0 0 0 0 1\n1 2\n1 3\n3 4\n3 5\n2 6\n4 7\n6 8\n5 9", "4\n0 0 1 0\n1 2\n1 3\n1 4"]
2 seconds
["2 2 2 2 2 1 1 0 2", "0 -1 1 -1"]
NoteThe first example is shown below:The black vertices have bold borders.In the second example, the best subtree for vertices $$$2, 3$$$ and $$$4$$$ are vertices $$$2, 3$$$ and $$$4$$$ correspondingly. And the best subtree for the vertex $$$1$$$ is the subtree consisting of vertices $$$1$$$ and $$$3$$$.
Java 8
standard input
[ "dp", "dfs and similar", "trees", "graphs" ]
cb8895ddd54ffbd898b1bf5e169feb63
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of vertices in the tree. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i$$$ is the color of the $$$i$$$-th vertex. Each of the next $$$n-1$$$ lin...
1,800
Print $$$n$$$ integers $$$res_1, res_2, \dots, res_n$$$, where $$$res_i$$$ is the maximum possible difference between the number of white and black vertices in some subtree that contains the vertex $$$i$$$.
standard output
PASSED
d8e847acc156008e12ed8fb47f10b066
train_003.jsonl
1584018300
You are given a tree consisting of $$$n$$$ vertices. A tree is a connected undirected graph with $$$n-1$$$ edges. Each vertex $$$v$$$ of this tree has a color assigned to it ($$$a_v = 1$$$ if the vertex $$$v$$$ is white and $$$0$$$ if the vertex $$$v$$$ is black).You have to solve the following problem for each vertex ...
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.StringTokenizer; public class F { static int n; static int[] arr, dp1, dp2; static ArrayList<Integer> adj[]; ...
Java
["9\n0 1 1 1 0 0 0 0 1\n1 2\n1 3\n3 4\n3 5\n2 6\n4 7\n6 8\n5 9", "4\n0 0 1 0\n1 2\n1 3\n1 4"]
2 seconds
["2 2 2 2 2 1 1 0 2", "0 -1 1 -1"]
NoteThe first example is shown below:The black vertices have bold borders.In the second example, the best subtree for vertices $$$2, 3$$$ and $$$4$$$ are vertices $$$2, 3$$$ and $$$4$$$ correspondingly. And the best subtree for the vertex $$$1$$$ is the subtree consisting of vertices $$$1$$$ and $$$3$$$.
Java 8
standard input
[ "dp", "dfs and similar", "trees", "graphs" ]
cb8895ddd54ffbd898b1bf5e169feb63
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of vertices in the tree. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i$$$ is the color of the $$$i$$$-th vertex. Each of the next $$$n-1$$$ lin...
1,800
Print $$$n$$$ integers $$$res_1, res_2, \dots, res_n$$$, where $$$res_i$$$ is the maximum possible difference between the number of white and black vertices in some subtree that contains the vertex $$$i$$$.
standard output
PASSED
a8b51cdcdac91b2815d00370c34aa080
train_003.jsonl
1584018300
You are given a tree consisting of $$$n$$$ vertices. A tree is a connected undirected graph with $$$n-1$$$ edges. Each vertex $$$v$$$ of this tree has a color assigned to it ($$$a_v = 1$$$ if the vertex $$$v$$$ is white and $$$0$$$ if the vertex $$$v$$$ is black).You have to solve the following problem for each vertex ...
256 megabytes
import static java.util.Arrays.* ; import static java.lang.Math.* ; import java.io.*; import java.util.*; public class Main { int ref ; int [] head , next , to ; int [] dp_down , dp_up , a ; void addEdge(int a , int b) { next[++ref] = head[a] ; head[a] = ref ; to[ref] = b ;...
Java
["9\n0 1 1 1 0 0 0 0 1\n1 2\n1 3\n3 4\n3 5\n2 6\n4 7\n6 8\n5 9", "4\n0 0 1 0\n1 2\n1 3\n1 4"]
2 seconds
["2 2 2 2 2 1 1 0 2", "0 -1 1 -1"]
NoteThe first example is shown below:The black vertices have bold borders.In the second example, the best subtree for vertices $$$2, 3$$$ and $$$4$$$ are vertices $$$2, 3$$$ and $$$4$$$ correspondingly. And the best subtree for the vertex $$$1$$$ is the subtree consisting of vertices $$$1$$$ and $$$3$$$.
Java 8
standard input
[ "dp", "dfs and similar", "trees", "graphs" ]
cb8895ddd54ffbd898b1bf5e169feb63
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of vertices in the tree. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i$$$ is the color of the $$$i$$$-th vertex. Each of the next $$$n-1$$$ lin...
1,800
Print $$$n$$$ integers $$$res_1, res_2, \dots, res_n$$$, where $$$res_i$$$ is the maximum possible difference between the number of white and black vertices in some subtree that contains the vertex $$$i$$$.
standard output
PASSED
bd18dacd4b7dd21005d5dbab968fc48b
train_003.jsonl
1584018300
You are given a tree consisting of $$$n$$$ vertices. A tree is a connected undirected graph with $$$n-1$$$ edges. Each vertex $$$v$$$ of this tree has a color assigned to it ($$$a_v = 1$$$ if the vertex $$$v$$$ is white and $$$0$$$ if the vertex $$$v$$$ is black).You have to solve the following problem for each vertex ...
256 megabytes
import java.io.*; import java.io.IOException; import java.util.*; //import javafx.util.Pair; //import java.util.concurrent.LinkedBlockingDeque; //import sun.net.www.content.audio.wav; public class Codeforces { public static long mod = (long)Math.pow(10, 9)+7 ; public static doubl...
Java
["9\n0 1 1 1 0 0 0 0 1\n1 2\n1 3\n3 4\n3 5\n2 6\n4 7\n6 8\n5 9", "4\n0 0 1 0\n1 2\n1 3\n1 4"]
2 seconds
["2 2 2 2 2 1 1 0 2", "0 -1 1 -1"]
NoteThe first example is shown below:The black vertices have bold borders.In the second example, the best subtree for vertices $$$2, 3$$$ and $$$4$$$ are vertices $$$2, 3$$$ and $$$4$$$ correspondingly. And the best subtree for the vertex $$$1$$$ is the subtree consisting of vertices $$$1$$$ and $$$3$$$.
Java 8
standard input
[ "dp", "dfs and similar", "trees", "graphs" ]
cb8895ddd54ffbd898b1bf5e169feb63
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of vertices in the tree. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i$$$ is the color of the $$$i$$$-th vertex. Each of the next $$$n-1$$$ lin...
1,800
Print $$$n$$$ integers $$$res_1, res_2, \dots, res_n$$$, where $$$res_i$$$ is the maximum possible difference between the number of white and black vertices in some subtree that contains the vertex $$$i$$$.
standard output
PASSED
88b43dfe08e482c7686371810d99e30c
train_003.jsonl
1584018300
You are given a tree consisting of $$$n$$$ vertices. A tree is a connected undirected graph with $$$n-1$$$ edges. Each vertex $$$v$$$ of this tree has a color assigned to it ($$$a_v = 1$$$ if the vertex $$$v$$$ is white and $$$0$$$ if the vertex $$$v$$$ is black).You have to solve the following problem for each vertex ...
256 megabytes
import java.io.*; import java.util.*; import java.text.*; public final class isc { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String...
Java
["9\n0 1 1 1 0 0 0 0 1\n1 2\n1 3\n3 4\n3 5\n2 6\n4 7\n6 8\n5 9", "4\n0 0 1 0\n1 2\n1 3\n1 4"]
2 seconds
["2 2 2 2 2 1 1 0 2", "0 -1 1 -1"]
NoteThe first example is shown below:The black vertices have bold borders.In the second example, the best subtree for vertices $$$2, 3$$$ and $$$4$$$ are vertices $$$2, 3$$$ and $$$4$$$ correspondingly. And the best subtree for the vertex $$$1$$$ is the subtree consisting of vertices $$$1$$$ and $$$3$$$.
Java 8
standard input
[ "dp", "dfs and similar", "trees", "graphs" ]
cb8895ddd54ffbd898b1bf5e169feb63
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of vertices in the tree. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i$$$ is the color of the $$$i$$$-th vertex. Each of the next $$$n-1$$$ lin...
1,800
Print $$$n$$$ integers $$$res_1, res_2, \dots, res_n$$$, where $$$res_i$$$ is the maximum possible difference between the number of white and black vertices in some subtree that contains the vertex $$$i$$$.
standard output
PASSED
06e86cc201fae3b514bd58005ed25e61
train_003.jsonl
1584018300
You are given a tree consisting of $$$n$$$ vertices. A tree is a connected undirected graph with $$$n-1$$$ edges. Each vertex $$$v$$$ of this tree has a color assigned to it ($$$a_v = 1$$$ if the vertex $$$v$$$ is white and $$$0$$$ if the vertex $$$v$$$ is black).You have to solve the following problem for each vertex ...
256 megabytes
import java.util.*; import java.io.*; public class F1324 { static int n; static ArrayList<Integer>[] adjList; static ArrayList<Boolean>[] rootCheck; static int[] score; static int[] a; static boolean[] vis; public static int dfs(int u) { vis[u] = true; int sc = a[u]; for(int i = 0; i < adjList[u].size...
Java
["9\n0 1 1 1 0 0 0 0 1\n1 2\n1 3\n3 4\n3 5\n2 6\n4 7\n6 8\n5 9", "4\n0 0 1 0\n1 2\n1 3\n1 4"]
2 seconds
["2 2 2 2 2 1 1 0 2", "0 -1 1 -1"]
NoteThe first example is shown below:The black vertices have bold borders.In the second example, the best subtree for vertices $$$2, 3$$$ and $$$4$$$ are vertices $$$2, 3$$$ and $$$4$$$ correspondingly. And the best subtree for the vertex $$$1$$$ is the subtree consisting of vertices $$$1$$$ and $$$3$$$.
Java 8
standard input
[ "dp", "dfs and similar", "trees", "graphs" ]
cb8895ddd54ffbd898b1bf5e169feb63
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of vertices in the tree. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i$$$ is the color of the $$$i$$$-th vertex. Each of the next $$$n-1$$$ lin...
1,800
Print $$$n$$$ integers $$$res_1, res_2, \dots, res_n$$$, where $$$res_i$$$ is the maximum possible difference between the number of white and black vertices in some subtree that contains the vertex $$$i$$$.
standard output
PASSED
c8a6d48bbc1a92815623b5c4c0d1d1c9
train_003.jsonl
1584018300
You are given a tree consisting of $$$n$$$ vertices. A tree is a connected undirected graph with $$$n-1$$$ edges. Each vertex $$$v$$$ of this tree has a color assigned to it ($$$a_v = 1$$$ if the vertex $$$v$$$ is white and $$$0$$$ if the vertex $$$v$$$ is black).You have to solve the following problem for each vertex ...
256 megabytes
// import java.util.*; // import java.io.*; // public class prob13 { // static int[] val, dp; // static ArrayList<Integer>[] adj; // public static void main(String[] args) throws Exception { // // Scanner in = new Scanner(new File("prob12.in")); // Scanner in = new Scanner(System.in); // // int t = in.nextI...
Java
["9\n0 1 1 1 0 0 0 0 1\n1 2\n1 3\n3 4\n3 5\n2 6\n4 7\n6 8\n5 9", "4\n0 0 1 0\n1 2\n1 3\n1 4"]
2 seconds
["2 2 2 2 2 1 1 0 2", "0 -1 1 -1"]
NoteThe first example is shown below:The black vertices have bold borders.In the second example, the best subtree for vertices $$$2, 3$$$ and $$$4$$$ are vertices $$$2, 3$$$ and $$$4$$$ correspondingly. And the best subtree for the vertex $$$1$$$ is the subtree consisting of vertices $$$1$$$ and $$$3$$$.
Java 8
standard input
[ "dp", "dfs and similar", "trees", "graphs" ]
cb8895ddd54ffbd898b1bf5e169feb63
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of vertices in the tree. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i$$$ is the color of the $$$i$$$-th vertex. Each of the next $$$n-1$$$ lin...
1,800
Print $$$n$$$ integers $$$res_1, res_2, \dots, res_n$$$, where $$$res_i$$$ is the maximum possible difference between the number of white and black vertices in some subtree that contains the vertex $$$i$$$.
standard output
PASSED
bc3135781d3bceac7312e4f9c90786cf
train_003.jsonl
1584018300
You are given a tree consisting of $$$n$$$ vertices. A tree is a connected undirected graph with $$$n-1$$$ edges. Each vertex $$$v$$$ of this tree has a color assigned to it ($$$a_v = 1$$$ if the vertex $$$v$$$ is white and $$$0$$$ if the vertex $$$v$$$ is black).You have to solve the following problem for each vertex ...
256 megabytes
import java.io.*; import java.lang.reflect.Array; import java.math.BigDecimal; import java.math.BigInteger; import java.math.RoundingMode; import java.text.DecimalFormat; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { static long mod=(long)(1e+9 + 7); //...
Java
["9\n0 1 1 1 0 0 0 0 1\n1 2\n1 3\n3 4\n3 5\n2 6\n4 7\n6 8\n5 9", "4\n0 0 1 0\n1 2\n1 3\n1 4"]
2 seconds
["2 2 2 2 2 1 1 0 2", "0 -1 1 -1"]
NoteThe first example is shown below:The black vertices have bold borders.In the second example, the best subtree for vertices $$$2, 3$$$ and $$$4$$$ are vertices $$$2, 3$$$ and $$$4$$$ correspondingly. And the best subtree for the vertex $$$1$$$ is the subtree consisting of vertices $$$1$$$ and $$$3$$$.
Java 8
standard input
[ "dp", "dfs and similar", "trees", "graphs" ]
cb8895ddd54ffbd898b1bf5e169feb63
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of vertices in the tree. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i$$$ is the color of the $$$i$$$-th vertex. Each of the next $$$n-1$$$ lin...
1,800
Print $$$n$$$ integers $$$res_1, res_2, \dots, res_n$$$, where $$$res_i$$$ is the maximum possible difference between the number of white and black vertices in some subtree that contains the vertex $$$i$$$.
standard output
PASSED
370ca507ddab553e4d417109c1ea1c55
train_003.jsonl
1584018300
You are given a tree consisting of $$$n$$$ vertices. A tree is a connected undirected graph with $$$n-1$$$ edges. Each vertex $$$v$$$ of this tree has a color assigned to it ($$$a_v = 1$$$ if the vertex $$$v$$$ is white and $$$0$$$ if the vertex $$$v$$$ is black).You have to solve the following problem for each vertex ...
256 megabytes
import java.io.*; import java.util.*; import java.math.*; /** * Built using CHelper plug-in * Actual solution is at the top */ public class MaximumWhiteSubtree { public static void main(String[] args) throws IOException { InputStream inputStream = System.in; OutputStream outputStream = System.ou...
Java
["9\n0 1 1 1 0 0 0 0 1\n1 2\n1 3\n3 4\n3 5\n2 6\n4 7\n6 8\n5 9", "4\n0 0 1 0\n1 2\n1 3\n1 4"]
2 seconds
["2 2 2 2 2 1 1 0 2", "0 -1 1 -1"]
NoteThe first example is shown below:The black vertices have bold borders.In the second example, the best subtree for vertices $$$2, 3$$$ and $$$4$$$ are vertices $$$2, 3$$$ and $$$4$$$ correspondingly. And the best subtree for the vertex $$$1$$$ is the subtree consisting of vertices $$$1$$$ and $$$3$$$.
Java 8
standard input
[ "dp", "dfs and similar", "trees", "graphs" ]
cb8895ddd54ffbd898b1bf5e169feb63
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of vertices in the tree. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i$$$ is the color of the $$$i$$$-th vertex. Each of the next $$$n-1$$$ lin...
1,800
Print $$$n$$$ integers $$$res_1, res_2, \dots, res_n$$$, where $$$res_i$$$ is the maximum possible difference between the number of white and black vertices in some subtree that contains the vertex $$$i$$$.
standard output
PASSED
a114cf82a86e98197d1c94e0ca59ba85
train_003.jsonl
1584018300
You are given a tree consisting of $$$n$$$ vertices. A tree is a connected undirected graph with $$$n-1$$$ edges. Each vertex $$$v$$$ of this tree has a color assigned to it ($$$a_v = 1$$$ if the vertex $$$v$$$ is white and $$$0$$$ if the vertex $$$v$$$ is black).You have to solve the following problem for each vertex ...
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class p5 { static class Input { private StringTokenizer tokenizer = null; private BufferedReader reader;...
Java
["9\n0 1 1 1 0 0 0 0 1\n1 2\n1 3\n3 4\n3 5\n2 6\n4 7\n6 8\n5 9", "4\n0 0 1 0\n1 2\n1 3\n1 4"]
2 seconds
["2 2 2 2 2 1 1 0 2", "0 -1 1 -1"]
NoteThe first example is shown below:The black vertices have bold borders.In the second example, the best subtree for vertices $$$2, 3$$$ and $$$4$$$ are vertices $$$2, 3$$$ and $$$4$$$ correspondingly. And the best subtree for the vertex $$$1$$$ is the subtree consisting of vertices $$$1$$$ and $$$3$$$.
Java 8
standard input
[ "dp", "dfs and similar", "trees", "graphs" ]
cb8895ddd54ffbd898b1bf5e169feb63
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of vertices in the tree. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i$$$ is the color of the $$$i$$$-th vertex. Each of the next $$$n-1$$$ lin...
1,800
Print $$$n$$$ integers $$$res_1, res_2, \dots, res_n$$$, where $$$res_i$$$ is the maximum possible difference between the number of white and black vertices in some subtree that contains the vertex $$$i$$$.
standard output
PASSED
721386ea5be3c948393c8b364a79f250
train_003.jsonl
1584018300
You are given a tree consisting of $$$n$$$ vertices. A tree is a connected undirected graph with $$$n-1$$$ edges. Each vertex $$$v$$$ of this tree has a color assigned to it ($$$a_v = 1$$$ if the vertex $$$v$$$ is white and $$$0$$$ if the vertex $$$v$$$ is black).You have to solve the following problem for each vertex ...
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class MaximumWhiteSubtree { static int[] color; static List<Integer>[] adj; static int[] dp; public static void main(String[] args) { FastReader scanner = new FastReader(); ...
Java
["9\n0 1 1 1 0 0 0 0 1\n1 2\n1 3\n3 4\n3 5\n2 6\n4 7\n6 8\n5 9", "4\n0 0 1 0\n1 2\n1 3\n1 4"]
2 seconds
["2 2 2 2 2 1 1 0 2", "0 -1 1 -1"]
NoteThe first example is shown below:The black vertices have bold borders.In the second example, the best subtree for vertices $$$2, 3$$$ and $$$4$$$ are vertices $$$2, 3$$$ and $$$4$$$ correspondingly. And the best subtree for the vertex $$$1$$$ is the subtree consisting of vertices $$$1$$$ and $$$3$$$.
Java 8
standard input
[ "dp", "dfs and similar", "trees", "graphs" ]
cb8895ddd54ffbd898b1bf5e169feb63
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of vertices in the tree. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i$$$ is the color of the $$$i$$$-th vertex. Each of the next $$$n-1$$$ lin...
1,800
Print $$$n$$$ integers $$$res_1, res_2, \dots, res_n$$$, where $$$res_i$$$ is the maximum possible difference between the number of white and black vertices in some subtree that contains the vertex $$$i$$$.
standard output
PASSED
9f9849d7a4a9cacb866687c934bc90d7
train_003.jsonl
1584018300
You are given a tree consisting of $$$n$$$ vertices. A tree is a connected undirected graph with $$$n-1$$$ edges. Each vertex $$$v$$$ of this tree has a color assigned to it ($$$a_v = 1$$$ if the vertex $$$v$$$ is white and $$$0$$$ if the vertex $$$v$$$ is black).You have to solve the following problem for each vertex ...
256 megabytes
import java.io.*; import java.util.*; public class Solution { static int[] color; static List<Integer>[] adj; static int[] dp; public static void main(String[] args) { FastReader scanner = new FastReader(); // input int n = scanner.nextInt(); color = new int[n+1]; ...
Java
["9\n0 1 1 1 0 0 0 0 1\n1 2\n1 3\n3 4\n3 5\n2 6\n4 7\n6 8\n5 9", "4\n0 0 1 0\n1 2\n1 3\n1 4"]
2 seconds
["2 2 2 2 2 1 1 0 2", "0 -1 1 -1"]
NoteThe first example is shown below:The black vertices have bold borders.In the second example, the best subtree for vertices $$$2, 3$$$ and $$$4$$$ are vertices $$$2, 3$$$ and $$$4$$$ correspondingly. And the best subtree for the vertex $$$1$$$ is the subtree consisting of vertices $$$1$$$ and $$$3$$$.
Java 8
standard input
[ "dp", "dfs and similar", "trees", "graphs" ]
cb8895ddd54ffbd898b1bf5e169feb63
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of vertices in the tree. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i$$$ is the color of the $$$i$$$-th vertex. Each of the next $$$n-1$$$ lin...
1,800
Print $$$n$$$ integers $$$res_1, res_2, \dots, res_n$$$, where $$$res_i$$$ is the maximum possible difference between the number of white and black vertices in some subtree that contains the vertex $$$i$$$.
standard output
PASSED
be7f49338e61e43b2d7566931b0749c7
train_003.jsonl
1584018300
You are given a tree consisting of $$$n$$$ vertices. A tree is a connected undirected graph with $$$n-1$$$ edges. Each vertex $$$v$$$ of this tree has a color assigned to it ($$$a_v = 1$$$ if the vertex $$$v$$$ is white and $$$0$$$ if the vertex $$$v$$$ is black).You have to solve the following problem for each vertex ...
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.StringTokenizer; public class MaximumWhiteSubtree { /...
Java
["9\n0 1 1 1 0 0 0 0 1\n1 2\n1 3\n3 4\n3 5\n2 6\n4 7\n6 8\n5 9", "4\n0 0 1 0\n1 2\n1 3\n1 4"]
2 seconds
["2 2 2 2 2 1 1 0 2", "0 -1 1 -1"]
NoteThe first example is shown below:The black vertices have bold borders.In the second example, the best subtree for vertices $$$2, 3$$$ and $$$4$$$ are vertices $$$2, 3$$$ and $$$4$$$ correspondingly. And the best subtree for the vertex $$$1$$$ is the subtree consisting of vertices $$$1$$$ and $$$3$$$.
Java 8
standard input
[ "dp", "dfs and similar", "trees", "graphs" ]
cb8895ddd54ffbd898b1bf5e169feb63
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of vertices in the tree. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i$$$ is the color of the $$$i$$$-th vertex. Each of the next $$$n-1$$$ lin...
1,800
Print $$$n$$$ integers $$$res_1, res_2, \dots, res_n$$$, where $$$res_i$$$ is the maximum possible difference between the number of white and black vertices in some subtree that contains the vertex $$$i$$$.
standard output
PASSED
c14c02843e6d76b13315ffe4e53f812e
train_003.jsonl
1584018300
You are given a tree consisting of $$$n$$$ vertices. A tree is a connected undirected graph with $$$n-1$$$ edges. Each vertex $$$v$$$ of this tree has a color assigned to it ($$$a_v = 1$$$ if the vertex $$$v$$$ is white and $$$0$$$ if the vertex $$$v$$$ is black).You have to solve the following problem for each vertex ...
256 megabytes
import java.util.*; public class test2 { static void dfs(int n , LinkedList<Integer> arr[] , boolean visited[] , int dp[] , int a[]) { visited[n] = true; for(Integer i : arr[n]) { if(!visited[i]) { dfs(i , arr, visited, dp,a); dp[n] += Math.max(0, dp[i]); } } dp[n] += a[n]; } static voi...
Java
["9\n0 1 1 1 0 0 0 0 1\n1 2\n1 3\n3 4\n3 5\n2 6\n4 7\n6 8\n5 9", "4\n0 0 1 0\n1 2\n1 3\n1 4"]
2 seconds
["2 2 2 2 2 1 1 0 2", "0 -1 1 -1"]
NoteThe first example is shown below:The black vertices have bold borders.In the second example, the best subtree for vertices $$$2, 3$$$ and $$$4$$$ are vertices $$$2, 3$$$ and $$$4$$$ correspondingly. And the best subtree for the vertex $$$1$$$ is the subtree consisting of vertices $$$1$$$ and $$$3$$$.
Java 8
standard input
[ "dp", "dfs and similar", "trees", "graphs" ]
cb8895ddd54ffbd898b1bf5e169feb63
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of vertices in the tree. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i$$$ is the color of the $$$i$$$-th vertex. Each of the next $$$n-1$$$ lin...
1,800
Print $$$n$$$ integers $$$res_1, res_2, \dots, res_n$$$, where $$$res_i$$$ is the maximum possible difference between the number of white and black vertices in some subtree that contains the vertex $$$i$$$.
standard output
PASSED
141bf02999faa6bc66547c0ae521c9fc
train_003.jsonl
1584018300
You are given a tree consisting of $$$n$$$ vertices. A tree is a connected undirected graph with $$$n-1$$$ edges. Each vertex $$$v$$$ of this tree has a color assigned to it ($$$a_v = 1$$$ if the vertex $$$v$$$ is white and $$$0$$$ if the vertex $$$v$$$ is black).You have to solve the following problem for each vertex ...
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; import java.math.*; import java.text.*; public class Prac{ static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; public InputReader(Inpu...
Java
["9\n0 1 1 1 0 0 0 0 1\n1 2\n1 3\n3 4\n3 5\n2 6\n4 7\n6 8\n5 9", "4\n0 0 1 0\n1 2\n1 3\n1 4"]
2 seconds
["2 2 2 2 2 1 1 0 2", "0 -1 1 -1"]
NoteThe first example is shown below:The black vertices have bold borders.In the second example, the best subtree for vertices $$$2, 3$$$ and $$$4$$$ are vertices $$$2, 3$$$ and $$$4$$$ correspondingly. And the best subtree for the vertex $$$1$$$ is the subtree consisting of vertices $$$1$$$ and $$$3$$$.
Java 8
standard input
[ "dp", "dfs and similar", "trees", "graphs" ]
cb8895ddd54ffbd898b1bf5e169feb63
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of vertices in the tree. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i$$$ is the color of the $$$i$$$-th vertex. Each of the next $$$n-1$$$ lin...
1,800
Print $$$n$$$ integers $$$res_1, res_2, \dots, res_n$$$, where $$$res_i$$$ is the maximum possible difference between the number of white and black vertices in some subtree that contains the vertex $$$i$$$.
standard output
PASSED
77af8af25dac72f10e8a6f159b325ce3
train_003.jsonl
1584018300
You are given a tree consisting of $$$n$$$ vertices. A tree is a connected undirected graph with $$$n-1$$$ edges. Each vertex $$$v$$$ of this tree has a color assigned to it ($$$a_v = 1$$$ if the vertex $$$v$$$ is white and $$$0$$$ if the vertex $$$v$$$ is black).You have to solve the following problem for each vertex ...
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class MaximumWhiteSubtree { private static StringBuffer solve(int n, int[] color, List<List<Integer>> graph) { StringBuffer ans = new StringBuffer(); int[] dp = new int[n]; ...
Java
["9\n0 1 1 1 0 0 0 0 1\n1 2\n1 3\n3 4\n3 5\n2 6\n4 7\n6 8\n5 9", "4\n0 0 1 0\n1 2\n1 3\n1 4"]
2 seconds
["2 2 2 2 2 1 1 0 2", "0 -1 1 -1"]
NoteThe first example is shown below:The black vertices have bold borders.In the second example, the best subtree for vertices $$$2, 3$$$ and $$$4$$$ are vertices $$$2, 3$$$ and $$$4$$$ correspondingly. And the best subtree for the vertex $$$1$$$ is the subtree consisting of vertices $$$1$$$ and $$$3$$$.
Java 8
standard input
[ "dp", "dfs and similar", "trees", "graphs" ]
cb8895ddd54ffbd898b1bf5e169feb63
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of vertices in the tree. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i$$$ is the color of the $$$i$$$-th vertex. Each of the next $$$n-1$$$ lin...
1,800
Print $$$n$$$ integers $$$res_1, res_2, \dots, res_n$$$, where $$$res_i$$$ is the maximum possible difference between the number of white and black vertices in some subtree that contains the vertex $$$i$$$.
standard output
PASSED
e657aca6e9ca8583cd80f239dbf2c666
train_003.jsonl
1584018300
You are given a tree consisting of $$$n$$$ vertices. A tree is a connected undirected graph with $$$n-1$$$ edges. Each vertex $$$v$$$ of this tree has a color assigned to it ($$$a_v = 1$$$ if the vertex $$$v$$$ is white and $$$0$$$ if the vertex $$$v$$$ is black).You have to solve the following problem for each vertex ...
256 megabytes
import java.io.*; import java.util.*; public class R627F { private static int N; private static int[] A, dp, fin; private static List<List<Integer>> neighbors; public static void main(String[] args) throws Exception { BufferedReader in=new BufferedReader(new I...
Java
["9\n0 1 1 1 0 0 0 0 1\n1 2\n1 3\n3 4\n3 5\n2 6\n4 7\n6 8\n5 9", "4\n0 0 1 0\n1 2\n1 3\n1 4"]
2 seconds
["2 2 2 2 2 1 1 0 2", "0 -1 1 -1"]
NoteThe first example is shown below:The black vertices have bold borders.In the second example, the best subtree for vertices $$$2, 3$$$ and $$$4$$$ are vertices $$$2, 3$$$ and $$$4$$$ correspondingly. And the best subtree for the vertex $$$1$$$ is the subtree consisting of vertices $$$1$$$ and $$$3$$$.
Java 8
standard input
[ "dp", "dfs and similar", "trees", "graphs" ]
cb8895ddd54ffbd898b1bf5e169feb63
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of vertices in the tree. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i$$$ is the color of the $$$i$$$-th vertex. Each of the next $$$n-1$$$ lin...
1,800
Print $$$n$$$ integers $$$res_1, res_2, \dots, res_n$$$, where $$$res_i$$$ is the maximum possible difference between the number of white and black vertices in some subtree that contains the vertex $$$i$$$.
standard output
PASSED
cc02a039be8616e9750215385e77ead9
train_003.jsonl
1584018300
You are given a tree consisting of $$$n$$$ vertices. A tree is a connected undirected graph with $$$n-1$$$ edges. Each vertex $$$v$$$ of this tree has a color assigned to it ($$$a_v = 1$$$ if the vertex $$$v$$$ is white and $$$0$$$ if the vertex $$$v$$$ is black).You have to solve the following problem for each vertex ...
256 megabytes
import java.util.*; import java.io.*; import java.text.*; public class F1324 { static int[] clr, p, down, ans; static ArrayList<Integer>[] adjList; public static int down(int u) { int sum = 0; for (int x : adjList[u]) { if (x != p[u]) { p[x] = u; sum += Math.max(down(x), 0); } } return dow...
Java
["9\n0 1 1 1 0 0 0 0 1\n1 2\n1 3\n3 4\n3 5\n2 6\n4 7\n6 8\n5 9", "4\n0 0 1 0\n1 2\n1 3\n1 4"]
2 seconds
["2 2 2 2 2 1 1 0 2", "0 -1 1 -1"]
NoteThe first example is shown below:The black vertices have bold borders.In the second example, the best subtree for vertices $$$2, 3$$$ and $$$4$$$ are vertices $$$2, 3$$$ and $$$4$$$ correspondingly. And the best subtree for the vertex $$$1$$$ is the subtree consisting of vertices $$$1$$$ and $$$3$$$.
Java 8
standard input
[ "dp", "dfs and similar", "trees", "graphs" ]
cb8895ddd54ffbd898b1bf5e169feb63
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of vertices in the tree. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i$$$ is the color of the $$$i$$$-th vertex. Each of the next $$$n-1$$$ lin...
1,800
Print $$$n$$$ integers $$$res_1, res_2, \dots, res_n$$$, where $$$res_i$$$ is the maximum possible difference between the number of white and black vertices in some subtree that contains the vertex $$$i$$$.
standard output
PASSED
e3e887d8f203f2d0dbba244d42166eb9
train_003.jsonl
1584018300
You are given a tree consisting of $$$n$$$ vertices. A tree is a connected undirected graph with $$$n-1$$$ edges. Each vertex $$$v$$$ of this tree has a color assigned to it ($$$a_v = 1$$$ if the vertex $$$v$$$ is white and $$$0$$$ if the vertex $$$v$$$ is black).You have to solve the following problem for each vertex ...
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Graph { static int parent[]; static ArrayList adj[]; static int dp[][]; public Graph(int n) { par...
Java
["9\n0 1 1 1 0 0 0 0 1\n1 2\n1 3\n3 4\n3 5\n2 6\n4 7\n6 8\n5 9", "4\n0 0 1 0\n1 2\n1 3\n1 4"]
2 seconds
["2 2 2 2 2 1 1 0 2", "0 -1 1 -1"]
NoteThe first example is shown below:The black vertices have bold borders.In the second example, the best subtree for vertices $$$2, 3$$$ and $$$4$$$ are vertices $$$2, 3$$$ and $$$4$$$ correspondingly. And the best subtree for the vertex $$$1$$$ is the subtree consisting of vertices $$$1$$$ and $$$3$$$.
Java 8
standard input
[ "dp", "dfs and similar", "trees", "graphs" ]
cb8895ddd54ffbd898b1bf5e169feb63
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of vertices in the tree. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i$$$ is the color of the $$$i$$$-th vertex. Each of the next $$$n-1$$$ lin...
1,800
Print $$$n$$$ integers $$$res_1, res_2, \dots, res_n$$$, where $$$res_i$$$ is the maximum possible difference between the number of white and black vertices in some subtree that contains the vertex $$$i$$$.
standard output
PASSED
35966febb41cbfa05867b30040de28e1
train_003.jsonl
1584018300
You are given a tree consisting of $$$n$$$ vertices. A tree is a connected undirected graph with $$$n-1$$$ edges. Each vertex $$$v$$$ of this tree has a color assigned to it ($$$a_v = 1$$$ if the vertex $$$v$$$ is white and $$$0$$$ if the vertex $$$v$$$ is black).You have to solve the following problem for each vertex ...
256 megabytes
// Don't place your source in a package import java.util.*; import java.lang.*; import java.io.*; import java.math.*; // Please name your class Main public class Main { public static void main (String[] args) throws java.lang.Exception { Scanner in = new Scanner(System.in); //int T =in.nextInt(); PrintWriter...
Java
["9\n0 1 1 1 0 0 0 0 1\n1 2\n1 3\n3 4\n3 5\n2 6\n4 7\n6 8\n5 9", "4\n0 0 1 0\n1 2\n1 3\n1 4"]
2 seconds
["2 2 2 2 2 1 1 0 2", "0 -1 1 -1"]
NoteThe first example is shown below:The black vertices have bold borders.In the second example, the best subtree for vertices $$$2, 3$$$ and $$$4$$$ are vertices $$$2, 3$$$ and $$$4$$$ correspondingly. And the best subtree for the vertex $$$1$$$ is the subtree consisting of vertices $$$1$$$ and $$$3$$$.
Java 8
standard input
[ "dp", "dfs and similar", "trees", "graphs" ]
cb8895ddd54ffbd898b1bf5e169feb63
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of vertices in the tree. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i$$$ is the color of the $$$i$$$-th vertex. Each of the next $$$n-1$$$ lin...
1,800
Print $$$n$$$ integers $$$res_1, res_2, \dots, res_n$$$, where $$$res_i$$$ is the maximum possible difference between the number of white and black vertices in some subtree that contains the vertex $$$i$$$.
standard output
PASSED
f93234b776b6a07d10cbadc4842e9e08
train_003.jsonl
1584018300
You are given a tree consisting of $$$n$$$ vertices. A tree is a connected undirected graph with $$$n-1$$$ edges. Each vertex $$$v$$$ of this tree has a color assigned to it ($$$a_v = 1$$$ if the vertex $$$v$$$ is white and $$$0$$$ if the vertex $$$v$$$ is black).You have to solve the following problem for each vertex ...
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in Actual solution is at the top * * @author MakeM...
Java
["9\n0 1 1 1 0 0 0 0 1\n1 2\n1 3\n3 4\n3 5\n2 6\n4 7\n6 8\n5 9", "4\n0 0 1 0\n1 2\n1 3\n1 4"]
2 seconds
["2 2 2 2 2 1 1 0 2", "0 -1 1 -1"]
NoteThe first example is shown below:The black vertices have bold borders.In the second example, the best subtree for vertices $$$2, 3$$$ and $$$4$$$ are vertices $$$2, 3$$$ and $$$4$$$ correspondingly. And the best subtree for the vertex $$$1$$$ is the subtree consisting of vertices $$$1$$$ and $$$3$$$.
Java 8
standard input
[ "dp", "dfs and similar", "trees", "graphs" ]
cb8895ddd54ffbd898b1bf5e169feb63
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of vertices in the tree. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i$$$ is the color of the $$$i$$$-th vertex. Each of the next $$$n-1$$$ lin...
1,800
Print $$$n$$$ integers $$$res_1, res_2, \dots, res_n$$$, where $$$res_i$$$ is the maximum possible difference between the number of white and black vertices in some subtree that contains the vertex $$$i$$$.
standard output