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
9632f9c171786a15a65023e2f25654f2
train_003.jsonl
1361374200
A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices.A subtree of a tree T is a tree with both vertices and edges as subsets of vertices and edges of T.You're given a tree with n vertices. Consider its vertices numbered with integers from 1 to n. Additionally an integer is written on every vertex of this tree. Initially the integer written on the i-th vertex is equal to vi. In one move you can apply the following operation: Select the subtree of the given tree that includes the vertex with number 1. Increase (or decrease) by one all the integers which are written on the vertices of that subtree. Calculate the minimum number of moves that is required to make all the integers written on the vertices of the given tree equal to zero.
256 megabytes
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; import java.util.*; import java.io.*; public class codeforces { static class Student{ int x,y;//z; Student(int x,int y){ this.x=x; this.y=y; //this.z=z; } } static int prime[]; static void sieveOfEratosthenes(int n) { // Create a boolean array "prime[0..n]" and initialize // all entries it as true. A value in prime[i] will // finally be false if i is Not a prime, else true. int pos=0; prime= new int[n+1]; for(int p = 2; p*p <=n; p++) { // If prime[p] is not changed, then it is a prime if(prime[p] == 0) { // Update all multiples of p prime[p]=p; for(int i = p*p; i <= n; i += p) if(prime[i]==0) prime[i] = p; } } } static class Sortbyroll implements Comparator<Student> { // Used for sorting in ascending order of // roll number public int compare(Student c, Student b) { return c.x-b.x; } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static class Edge{ int a,b; Edge(int a,int b){ this.a=a; this.b=b; } } static class Trie{ HashMap<Character,Trie>map; int c; Trie(){ map=new HashMap<>(); //z=null; //o=null; c=0; } } //static long ans; static int parent[]; static int rank[]; static int b[]; static int bo[][]; static int ho[][]; static int seg[]; //static int pos; static long mod=1000000000+7; //static int dp[][]; static HashMap<Integer,Integer>map; static PriorityQueue<Student>q=new PriorityQueue<>(); //static Stack<Integer>st; // static ArrayList<Character>ans; static ArrayList<ArrayList<Integer>>adj; //static long ans; static int pos; static Trie root; static long fac[]; static int gw,gb; //static long mod=(long)(998244353); static long ans; static void solve()throws IOException{ FastReader sc=new FastReader(); int n,i,x,y; n=sc.nextInt(); adj=new ArrayList<>(); for(i=0;i<n;i++) adj.add(new ArrayList<>()); for(i=0;i<n-1;i++){ x=sc.nextInt()-1; y=sc.nextInt()-1; adj.get(x).add(y); adj.get(y).add(x); } int a[]=new int[n]; for(i=0;i<n;i++) a[i]=sc.nextInt(); long dp[][]=new long[n][2]; dfs(0,0,dp,a); System.out.println(dp[0][0]+dp[0][1]); } static void dfs(int p,int c,long dp[][],int a[]){ for(Integer x:adj.get(c)){ if(x==p) continue; dfs(c,x,dp,a); dp[c][0]=Math.max(dp[c][0],dp[x][0]); dp[c][1]=Math.max(dp[c][1],dp[x][1]); } long y=dp[c][0]-dp[c][1]; y=y+(long)a[c]; if(y>=0) dp[c][1]+=y; else dp[c][0]+=(long)Math.abs(y); } static void check(int x,int y,char ch[][]){ if(x<0||y<0||x>=ch.length||y>=ch[0].length||ch[x][y]!='.') return; ch[x][y]='#'; } static void update(int s,int e,int l,int r,int in,int v){ if(s>e||s>r||l>e) return; if(s>=l&&e<=r){ seg[in]=v; return; } int mid=(s+e)/2; update(s,mid,l,r,2*in+1,v); update(mid+1,e,l,r,2*in+2,v); seg[in]=Math.max(seg[2*in+1],seg[2*in+2]); } static int query(int s,int e,int l,int r,int in){ if(s>e||s>r||l>e) return 0; if(s>=l&&e<=r){ return seg[in]; } int mid=(s+e)/2; return Math.max(query(s,mid,l,r,2*in+1), query(mid+1,e,l,r,2*in+2)); //seg[in]=Math.max(seg[2*in+1],seg[2*in+2]); } static double dist(long x,long y,long z,long w){ return Math.sqrt((x-y)*(x-y)+(z-w)*(z-w)); } static void add(int x,int y,Queue<Integer>q,Queue<Integer>v,int b[][]){ q.add(x); v.add(y); b[x][y]=1; } static long nCr(long n, long r, long p) { return (fac[(int)n]* modInverse(fac[(int)r], p) % p * modInverse(fac[(int)(n-r)], p) % p) % p; } //static int prime[]; //static int dp[]; public static void main(String[] args){ //long sum=0; try { codeforces.solve(); } catch (Exception e) { e.printStackTrace(); } } static long modInverse(long n, long p) { return power(n, p-(long)2,p); } static long power(long x, long y, long p) { long res = 1; // Initialize result x = x % p; // Update x if it is more than or // equal to p while (y > 0) { // If y is odd, multiply x with result if (y %(long)2!=0) res = (res*x) % p; // y must be even now y = y>>1; // y = y/2 x = (x*x) % p; } return res%p; } /*public static long power(long x,long a) { if(a==0) return 1; if(a%2==1)return (x*1L*power(x,a-1))%mod; return (power((int)((x*1L*x)%mod),a/2))%mod; }*/ static int find(int x) { // Finds the representative of the set // that x is an element of while(parent[x]!=x) { // if x is not the parent of itself // Then x is not the representative of // his set, x=parent[x]; // so we recursively call Find on its parent // and move i's node directly under the // representative of this set } return x; } static void union(int x, int y) { // Find representatives of two sets int xRoot = find(x), yRoot = find(y); // Elements are in the same set, no need // to unite anything. if (xRoot == yRoot) return; // If x's rank is less than y's rank if (rank[xRoot] < rank[yRoot]) // Then move x under y so that depth // of tree remains less parent[xRoot] = yRoot; // Else if y's rank is less than x's rank else if (rank[yRoot] < rank[xRoot]) // Then move y under x so that depth of // tree remains less parent[yRoot] = xRoot; else // if ranks are the same { // Then move y under x (doesn't matter // which one goes where) parent[yRoot] = xRoot; // And increment the the result tree's // rank by 1 rank[xRoot] = rank[xRoot] + 1; } } static long gcd(long a, long b) { if (a == 0){ //ans+=b; return b; } return gcd(b % a, a); } }
Java
["3\n1 2\n1 3\n1 -1 1"]
2 seconds
["3"]
null
Java 8
standard input
[ "dp", "dfs and similar", "greedy", "trees" ]
f3c26aa520f6bfa6b181ec40bde7ee1b
The first line of the input contains n (1 ≤ n ≤ 105). Each of the next n - 1 lines contains two integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi) indicating there's an edge between vertices ai and bi. It's guaranteed that the input graph is a tree. The last line of the input contains a list of n space-separated integers v1, v2, ..., vn (|vi| ≤ 109).
1,800
Print the minimum number of operations needed to solve the task. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
standard output
PASSED
0a0c25827984c844192d7794d6f44506
train_003.jsonl
1361374200
A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices.A subtree of a tree T is a tree with both vertices and edges as subsets of vertices and edges of T.You're given a tree with n vertices. Consider its vertices numbered with integers from 1 to n. Additionally an integer is written on every vertex of this tree. Initially the integer written on the i-th vertex is equal to vi. In one move you can apply the following operation: Select the subtree of the given tree that includes the vertex with number 1. Increase (or decrease) by one all the integers which are written on the vertices of that subtree. Calculate the minimum number of moves that is required to make all the integers written on the vertices of the given tree equal to zero.
256 megabytes
import java.util.ArrayList; import java.util.Scanner; public class _28_Zero_trees { static long[][] dp; public static void main(String[] args) { Scanner scn = new Scanner(System.in); int n = scn.nextInt(); dp = new long[n][2]; int[] arr = new int[n]; ArrayList<ArrayList<Integer>> list = new ArrayList<>(); for (int i = 0; i < n; i++) { list.add(new ArrayList<>()); } for (int i = 0; i < n - 1; i++) { int val = scn.nextInt(); int val2 = scn.nextInt(); list.get(val - 1).add(val2 - 1); list.get(val2 - 1).add(val - 1); } for (int i = 0; i < n; i++) { arr[i] = scn.nextInt(); } dfs(-1, 0, list, arr); System.out.println(dp[0][0] + dp[0][1]); } public static void dfs(int par, int vertex, ArrayList<ArrayList<Integer>> graph, int[] arr) { for (int val : graph.get(vertex)) { if (val == par) { continue; } dfs(vertex, val, graph, arr); } long incr = 0; long dec = 0; for (int val : graph.get(vertex)) { incr = Math.max(dp[val][0], incr); dec = Math.max(dp[val][1], dec); } long myval = arr[vertex] + incr - dec; if (myval < 0) { incr += Math.abs(myval); } else { dec += myval; } dp[vertex][0] = incr; dp[vertex][1] = dec; } }
Java
["3\n1 2\n1 3\n1 -1 1"]
2 seconds
["3"]
null
Java 8
standard input
[ "dp", "dfs and similar", "greedy", "trees" ]
f3c26aa520f6bfa6b181ec40bde7ee1b
The first line of the input contains n (1 ≤ n ≤ 105). Each of the next n - 1 lines contains two integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi) indicating there's an edge between vertices ai and bi. It's guaranteed that the input graph is a tree. The last line of the input contains a list of n space-separated integers v1, v2, ..., vn (|vi| ≤ 109).
1,800
Print the minimum number of operations needed to solve the task. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
standard output
PASSED
75b6f00a93aa2c6fd33648be7c649a4c
train_003.jsonl
1361374200
A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices.A subtree of a tree T is a tree with both vertices and edges as subsets of vertices and edges of T.You're given a tree with n vertices. Consider its vertices numbered with integers from 1 to n. Additionally an integer is written on every vertex of this tree. Initially the integer written on the i-th vertex is equal to vi. In one move you can apply the following operation: Select the subtree of the given tree that includes the vertex with number 1. Increase (or decrease) by one all the integers which are written on the vertices of that subtree. Calculate the minimum number of moves that is required to make all the integers written on the vertices of the given tree equal to zero.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; import java.util.*; import java.lang.*; import java.io.*; public class Main { public static ArrayList<Pair>[] arr; public static long[] vals; public static int n; public static boolean[] vist; public static Pair[] arrP; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); n = Integer.parseInt(st.nextToken()); arr = new ArrayList[n]; vist = new boolean[n]; arrP = new Pair[n]; for(int i = 0; i < n; i++) { arrP[i] = new Pair(i, 0, 0); arr[i] = new ArrayList<>(); } for (int i = 0; i < n - 1; i++) { st = new StringTokenizer(br.readLine()); int ind1 = Integer.parseInt(st.nextToken()) - 1; int ind2 = Integer.parseInt(st.nextToken()) - 1; arr[ind1].add(arrP[ind2]); arr[ind2].add(arrP[ind1]); } vals = new long[n]; st = new StringTokenizer(br.readLine()); for (int i = 0; i < n; i++) { long next = Long.parseLong(st.nextToken()); vals[i] = next; } solve(0); System.out.println(arrP[0].p1 + arrP[0].p2); } public static void solve(int ind) { if(vist[ind]) return; vist[ind] = true; if(arr[ind].size() == 1 && vist[arr[ind].get(0).p0]) // then this is a leaf { // then all you do is set your parameters if(vals[ind] < 0) { // we need to decrement arrP[ind].p2 = Math.abs(vals[ind]); } else { arrP[ind].p1 = vals[ind]; } return; } long incr = 0; long dec = 0; for(Pair p : arr[ind]) // for all the children { solve(p.p0); } for(Pair ch : arr[ind]) { incr = Math.max(incr, ch.p1); dec = Math.max(dec, ch.p2); } long value = vals[ind]; value += dec - incr; if(value > 0) { arrP[ind].p1 = incr + value; arrP[ind].p2 = dec; } else { arrP[ind].p1 = incr; arrP[ind].p2 = dec - value; // - value because value is negative } return; } // static class PairComp implements Comparator<Pair1> // { // public int compare(Pair1 c1, Pair1 c2) // { // if(c1.p0 < c2.p0) return -1; // if(c1.p0 > c2.p0) return 1; // if(c1.p1 < c2.p1) return -1; // if(c1.p1 > c2.p1) return 1; // if(c1.p2 < c2.p2) return -1; // if(c1.p2 > c2.p2) return 1; // return 0; // } // } } class Pair { public int p0; // this is the ID of the node public long p1; // this is the number of increments public long p2; // this is the number of decrements public Pair(int pp0, long pp1, long pp2) { p0 = pp0; p1 = pp1; p2 = pp2; } }
Java
["3\n1 2\n1 3\n1 -1 1"]
2 seconds
["3"]
null
Java 8
standard input
[ "dp", "dfs and similar", "greedy", "trees" ]
f3c26aa520f6bfa6b181ec40bde7ee1b
The first line of the input contains n (1 ≤ n ≤ 105). Each of the next n - 1 lines contains two integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi) indicating there's an edge between vertices ai and bi. It's guaranteed that the input graph is a tree. The last line of the input contains a list of n space-separated integers v1, v2, ..., vn (|vi| ≤ 109).
1,800
Print the minimum number of operations needed to solve the task. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
standard output
PASSED
8900c894e740c94ab9c544c74190a2bf
train_003.jsonl
1361374200
A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices.A subtree of a tree T is a tree with both vertices and edges as subsets of vertices and edges of T.You're given a tree with n vertices. Consider its vertices numbered with integers from 1 to n. Additionally an integer is written on every vertex of this tree. Initially the integer written on the i-th vertex is equal to vi. In one move you can apply the following operation: Select the subtree of the given tree that includes the vertex with number 1. Increase (or decrease) by one all the integers which are written on the vertices of that subtree. Calculate the minimum number of moves that is required to make all the integers written on the vertices of the given tree equal to zero.
256 megabytes
// ONE DAY, YOU WILL BE BEYOND THE REACH OF SPACE AND TIME. // // UNTIL THEN, STAY LOW AND CODE HARD. // // Author :- Saurabh// //BIT MESRA, RANCHI// import java.io.*; import java.util.*; import java.util.Queue; import static java.lang.Math.*; public class zeroTree { static ArrayList<Integer> adj[]; static long ar[]; static long ma[];static long ms[]; static void Bolo_Jai_Mata_Di() { n=ni(); adj=new ArrayList[n+5];ar=new long[n+5]; ma=new long [n+5];ms= new long [n+5]; for(int i=0;i<n+5;i++)adj[i]=new ArrayList<>(); for(int i=1;i<n;i++){ int x=ni(),y=ni(); adj[x].add(y); adj[y].add(x); } for(int i=1;i<=n;i++)ar[i]=ni(); dfs(1,0); pl(ma[1]+ms[1]); flush(); } static void dfs(int x, int p){ for(int i: adj[x]){ if(i!=p){dfs(i, x); ms[x]=max(ms[x],ms[i]); ma[x]=max(ma[x],ma[i]); } } ar[x]+= ms[x]-ma[x]; if(ar[x]>0)ma[x]+=ar[x]; else ms[x]-=ar[x]; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //THE DON'T CARE ZONE BEGINS HERE...// static Calendar ts, te; //For time calculation static int mod9 = 1000000007; static int n, m, k, t, mod = 998244353; static Lelo input = new Lelo(System.in); static PrintWriter pw = new PrintWriter(System.out, true); public static void main(String[] args) { //threading has been used to increase the stack size. new Thread(null, null, "BlackRise", 1 << 25) //the last parameter is stack size desired., { public void run() { try { tsc(); Bolo_Jai_Mata_Di(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } }.start(); } static class Lelo { //Lelo class for fast input private InputStream ayega; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public Lelo(InputStream ayega) { this.ayega = ayega; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = ayega.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } // functions to take input// static int ni() { return input.nextInt(); } static long nl() { return input.nextLong(); } static double nd() { return input.nextDouble(); } static String ns() { return input.readString(); } //functions to give output static void pl() { pw.println(); } static void p(Object o) { pw.print(o + " "); } static void pws(Object o) { pw.print(o + ""); } static void pl(Object o) { pw.println(o); } static void tsc() //calculates the starting time of execution { ts = Calendar.getInstance(); ts.setTime(new Date()); } static void tec() //calculates the ending time of execution { te = Calendar.getInstance(); te.setTime(new Date()); } static void pwt() //prints the time taken for execution { pw.printf("\nExecution time was :- %f s\n", (te.getTimeInMillis() - ts.getTimeInMillis()) / 1000.00); } static void sort(int ar[], int n) { for (int i = 0; i < n; i++) { int ran = (int) (Math.random() * n); int temp = ar[i]; ar[i] = ar[ran]; ar[ran] = temp; } Arrays.sort(ar); } static void sort(long ar[], int n) { for (int i = 0; i < n; i++) { int ran = (int) (Math.random() * n); long temp = ar[i]; ar[i] = ar[ran]; ar[ran] = temp; } Arrays.sort(ar); } static void sort(char ar[], int n) { for (int i = 0; i < n; i++) { int ran = (int) (Math.random() * n); char temp = ar[i]; ar[i] = ar[ran]; ar[ran] = temp; } Arrays.sort(ar); } static void flush() { tec(); //ending time of execution //pwt(); //prints the time taken to execute the program pw.flush(); pw.close(); } }
Java
["3\n1 2\n1 3\n1 -1 1"]
2 seconds
["3"]
null
Java 8
standard input
[ "dp", "dfs and similar", "greedy", "trees" ]
f3c26aa520f6bfa6b181ec40bde7ee1b
The first line of the input contains n (1 ≤ n ≤ 105). Each of the next n - 1 lines contains two integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi) indicating there's an edge between vertices ai and bi. It's guaranteed that the input graph is a tree. The last line of the input contains a list of n space-separated integers v1, v2, ..., vn (|vi| ≤ 109).
1,800
Print the minimum number of operations needed to solve the task. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
standard output
PASSED
803ef65bdf28a3034e56d7d90bcfef7a
train_003.jsonl
1361374200
A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices.A subtree of a tree T is a tree with both vertices and edges as subsets of vertices and edges of T.You're given a tree with n vertices. Consider its vertices numbered with integers from 1 to n. Additionally an integer is written on every vertex of this tree. Initially the integer written on the i-th vertex is equal to vi. In one move you can apply the following operation: Select the subtree of the given tree that includes the vertex with number 1. Increase (or decrease) by one all the integers which are written on the vertices of that subtree. Calculate the minimum number of moves that is required to make all the integers written on the vertices of the given tree equal to zero.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.List; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.util.ArrayList; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author prakharjain */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); _274B solver = new _274B(); solver.solve(1, in, out); out.close(); } static class _274B { List[] g; int[] a; long[][] dp; public void solve(int testNumber, InputReader in, OutputWriter out) { int n = in.nextInt(); g = new List[n]; for (int i = 0; i < n; i++) g[i] = new ArrayList(); for (int i = 0; i < n - 1; i++) { int a = in.nextInt() - 1; int b = in.nextInt() - 1; g[a].add(b); g[b].add(a); } a = new int[n]; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); } dp = new long[n][2]; dfs(0, -1); out.println(dp[0][0] + dp[0][1]); } void dfs(int u, int p) { for (int v : (List<Integer>) g[u]) { if (v != p) { dfs(v, u); } } for (int v : (List<Integer>) g[u]) { if (v != p) { dp[u][0] = Math.max(dp[v][0], dp[u][0]); dp[u][1] = Math.max(dp[v][1], dp[u][1]); } } long cv = dp[u][0] - dp[u][1]; if (cv < a[u]) { dp[u][0] += a[u] - cv; } if (cv > a[u]) { dp[u][1] += cv - a[u]; } } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void close() { writer.close(); } public void println(long i) { writer.println(i); } } }
Java
["3\n1 2\n1 3\n1 -1 1"]
2 seconds
["3"]
null
Java 8
standard input
[ "dp", "dfs and similar", "greedy", "trees" ]
f3c26aa520f6bfa6b181ec40bde7ee1b
The first line of the input contains n (1 ≤ n ≤ 105). Each of the next n - 1 lines contains two integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi) indicating there's an edge between vertices ai and bi. It's guaranteed that the input graph is a tree. The last line of the input contains a list of n space-separated integers v1, v2, ..., vn (|vi| ≤ 109).
1,800
Print the minimum number of operations needed to solve the task. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
standard output
PASSED
dfa6ff7e1517e3f3025d79276b4b8221
train_003.jsonl
1361374200
A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices.A subtree of a tree T is a tree with both vertices and edges as subsets of vertices and edges of T.You're given a tree with n vertices. Consider its vertices numbered with integers from 1 to n. Additionally an integer is written on every vertex of this tree. Initially the integer written on the i-th vertex is equal to vi. In one move you can apply the following operation: Select the subtree of the given tree that includes the vertex with number 1. Increase (or decrease) by one all the integers which are written on the vertices of that subtree. Calculate the minimum number of moves that is required to make all the integers written on the vertices of the given tree equal to zero.
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.ObjectInputStream.GetField; import java.io.PrintWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.InputMismatchException; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.PriorityQueue; import java.util.Queue; import java.util.Scanner; import java.util.Stack; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.TreeSet; public class Q1 { static long MOD = 1000000007; static boolean b[], b1[], check; static ArrayList<Integer>[] amp, pa; static ArrayList<Pair>[] amp1; static ArrayList<Pair>[][] damp; static int left[],s[],right[],sum[],dist[],cnt[],start[],color[],parent[],prime[],size[]; static long ans = 0,k; static int p = 0; static FasterScanner sc = new FasterScanner(System.in); static Queue<Pair> queue = new LinkedList<>(); static PriorityQueue<Integer> pq; static BufferedWriter log; static HashSet<Integer>[] hs; static HashMap<String,Integer> hm; static HashMap<Pair,Integer> hmp; static Stack<Integer> st; static boolean boo[][]; static Pair prr[]; static long parent1[],parent2[],size1[],size2[],arr1[],SUM[],MAX[]; static int arr[]; public static void main(String[] args) throws Exception { /*new Thread(null, new Runnable() { public void run() { try { */ soln(); /* } catch (Exception e) { System.out.println(e); } } }, "1", 1 << 26).start(); */} static long dp[][]; static int N,K,T; static int time[][],cost[][]; static boolean b11[]; static HashMap<Pair,Integer> h = new HashMap<>(); static long ans1; static long ans2; public static void soln() throws IOException { //FasterScanner in = new FasterScanner(new FileInputStream("C:\\Users\\Admin\\Desktop\\QCL.txt")); //PrintWriter out = new PrintWriter("C:\\Users\\Admin\\Desktop\\A1.txt"); log = new BufferedWriter(new OutputStreamWriter(System.out)); int n = sc.nextInt(); amp = (ArrayList<Integer>[]) new ArrayList[n]; for(int i =0 ;i < n;i++) amp[i] = new ArrayList<>(); for(int i = 0; i< n-1; i++){ int x = sc.nextInt(), y = sc.nextInt(); amp[x-1].add(y-1); amp[y - 1] .add(x-1); } arr = sc.nextIntArray(n); dp = new long[n][2]; b= new boolean[n]; dfs(0); System.out.println(dp[0][1]+dp[0][0]); log.close(); //out.close(); } static void dfs(int x){ b[x] = true; //System.out.println(x); long max1 = 0, max2 = 0; for(int j:amp[x]){ if(!b[j]){ dfs(j); max1 = Math.max(dp[j][1], max1); max2 = Math.max(dp[j][0], max2); } } long c = arr[x]+max1-max2; dp[x][0] = max2; dp[x][1] = max1; if(c>0){ dp[x][0] += c; } else{ dp[x][1] -=c; } } static long comp(long n, long m){ int l = Math.max(Long.toBinaryString(n).length(),Long.toBinaryString(m).length()); System.out.println((m&(n^MAX[l]))+" "+(((m^MAX[l])&n))); return 2*((m&(n^MAX[l]))+(((m^MAX[l])&n))); } static void recur(int n, int m, int k){ if(n<0 || m<0) return; if(k==0){ p++; return; } recur(n-k,m,k-1); recur(n,m-k,k-1); return; } public static void buildWeightedGraph(int n){ for(int i =0 ;i< n; i++){ int x = sc.nextInt(), y = sc.nextInt(), w = sc.nextInt(); amp1[--x].add(new Pair(--y,w)); amp1[y].add(new Pair(x,w)); } } public static void seive(int n){ b = new boolean[(n+1)]; Arrays.fill(b, true); b[1] = false; for(int i = 2;i*i<=n;i++){ if(b[i]){ for(int p = 2*i;p<=n;p+=i){ b[p] = false; } } } /*for(int i = 2;i<=n;i++){ if(b[i]) prime[i] = i; }*/ } static class Graph{ int vertex; int weight; Graph(int v, int w){ vertex = v; weight = w; } } static class Pair implements Comparable<Pair> { int u; int v; public Pair(){ u = 0; v = 0; } public Pair(int u, int v) { this.u = u; this.v = v; } public int hashCode() { int hu = (int) (u ^ (u >>> 32)); int hv = (int) (v ^ (v >>> 32)); return 31*hu + hv; } public boolean equals(Object o) { Pair other = (Pair) o; return (u == other.u && v == other.v); } public int compareTo(Pair other) { return Long.compare(u, other.u) != 0 ? (Long.compare(u, other.u)) : (Long.compare(v, other.v)); } public String toString() { return "[u=" + u + ", v=" + v + "]"; } } public static void buildGraph(int n){ for(int i =0;i<n;i++){ int x = sc.nextInt()-1, y = sc.nextInt()-1; amp[x].add(y); amp[y].add(x); } } public static int getParent(long x){ while(parent[(int) x]!=x){ parent[ (int) x] = parent[(int) parent[ (int) x]]; x = parent[ (int) x]; } return (int) x; } static long min(long a, long b, long c){ if(a<b && a<c) return a; if(b<c) return b; return c; } /* static class Pair3{ int x, y ,z; Pair3(int x, int y, int z){ this.x = x; this.y = y; this.z = z; } }*/ static int sum(int n){ String str = Integer.toString(n); int cnt = 0; for(int i = 0; i< str.length();i++){ cnt+=(str.charAt(i)-'0'); } return cnt; } static void KMPSearch(String pat, String txt) { int M = pat.length(); int N = txt.length(); // create lps[] that will hold the longest // prefix suffix values for pattern int lps[] = new int[M]; int j = 0; // index for pat[] // Preprocess the pattern (calculate lps[] // array) computeLPSArray(pat,M,lps); int i = 0; // index for txt[] while (i < N) { if (pat.charAt(j) == txt.charAt(i)) { j++; i++; } if (j == M) { // parent.add((i-j)); j = lps[j-1]; } // mismatch after j matches else if (i < N && pat.charAt(j) != txt.charAt(i)) { // Do not match lps[0..lps[j-1]] characters, // they will match anyway if (j != 0) j = lps[j-1]; else i = i+1; } } } static void computeLPSArray(String pat, int M, int lps[]) { // length of the previous longest prefix suffix int len = 0; int i = 1; lps[0] = 0; // lps[0] is always 0 // the loop calculates lps[i] for i = 1 to M-1 while (i < M) { if (pat.charAt(i) == pat.charAt(len)) { len++; lps[i] = len; i++; } else // (pat[i] != pat[len]) { // This is tricky. Consider the example. // AAACAAAA and i = 7. The idea is similar // to search step. if (len != 0) { len = lps[len-1]; // Also, note that we do not increment // i here } else // if (len == 0) { lps[i] = len; i++; } } } } private static void permutation(String prefix, String str) { int n = str.length(); if (n == 0); //hs.add(prefix); else { for (int i = 0; i < n; i++) permutation(prefix + str.charAt(i), str.substring(0, i) + str.substring(i+1, n)); } } public static char give(char c1,char c2){ if(c1!='a' && c2!='a') return 'a'; if(c1!='b' && c2!='b') return 'b'; return 'c'; } public static void buildTree(int n){ int arr[] = sc.nextIntArray(n); for(int i = 0;i<n;i++){ int x = arr[i]-1; amp[i+1].add(x); amp[x].add(i+1); } } static class SegmentTree { boolean st[]; boolean lazy[]; SegmentTree(int n) { int size = 4 * n; st = new boolean[size]; Arrays.fill(st, true); lazy = new boolean[size]; Arrays.fill(lazy, true); //build(0, n - 1, 1); } /*long[] build(int ss, int se, int si) { if (ss == se) { st[si][0] = 1; st[si][1] = 1; st[si][2] = 1; return st[si]; } int mid = (ss + se) / 2; long a1[] = build(ss, mid, si * 2), a2[] = build(mid + 1, se, si * 2 + 1); long ans[] = new long[3]; if (arr[mid] < arr[mid + 1]) { ans[1] = Math.max(a2[1], Math.max(a1[1], a1[2] + a2[0])); if (a1[1] == (mid - ss + 1)) ans[0] = ans[1]; else ans[0] = a1[0]; if (a2[2] == (se - mid)) ans[2] = ans[1]; else ans[2] = a2[2]; } else { ans[1] = Math.max(a1[1], a2[1]); ans[0] = a1[0]; ans[2] = a2[2]; } st[si] = ans; return st[si]; }*/ void update(int si, int ss, int se, int idx, long x) { if (ss == se) { //arr[idx] += val; st[si]=false; } else { int mid = (ss + se) / 2; if(ss <= idx && idx <= mid) { update(2*si, ss, mid, idx, x); } else { update(2*si+1, mid+1, se, idx, x); } st[si] = st[2*si]|st[2*si+1]; } } /*boolean get(int qs, int qe, int ss, int se, int si){ if(qs>se || qe<ss) return 0; if (qs <= ss && qe >= se) { return st[si]; } int mid = (ss+se)/2; return get(qs, qe, ss, mid, si * 2)+get(qs, qe, mid + 1, se, si * 2 + 1); }*/ void updateRange(int node, int start, int end, int l, int r, boolean val) { if(!lazy[node]) { // This node needs to be updated st[node] = lazy[node]; // Update it if(start != end) { lazy[node*2] = lazy[node]; // Mark child as lazy lazy[node*2+1] = lazy[node]; // Mark child as lazy } lazy[node] = true; // Reset it } if(start > end || start > r || end < l) // Current segment is not within range [l, r] return; if(start >= l && end <= r) { // Segment is fully within range st[node] = val; if(start != end) { // Not leaf node lazy[node*2] = val; lazy[node*2+1] = val; } return; } int mid = (start + end) / 2; updateRange(node*2, start, mid, l, r, val); // Updating left child updateRange(node*2 + 1, mid + 1, end, l, r, val); // Updating right child st[node] = st[node*2] | st[node*2+1]; // Updating root with max value } boolean queryRange(int node, int start, int end, int l, int r) { if(start > end || start > r || end < l) return false; // Out of range if(!lazy[node]) { // This node needs to be updated st[node] = lazy[node]; // Update it if(start != end) { lazy[node*2] = lazy[node]; // Mark child as lazy lazy[node*2+1] = lazy[node]; // Mark child as lazy } lazy[node] = true; // Reset it } if(start >= l && end <= r) // Current segment is totally within range [l, r] return st[node]; int mid = (start + end) / 2; boolean p1 = queryRange(node*2, start, mid, l, r); // Query left child boolean b = queryRange(node*2 + 1, mid + 1, end, l, r); // Query right child return (p1 | b); } void print() { for (int i = 0; i < st.length; i++) { System.out.print(st[i]+" "); } System.out.println(); } } static int convert(int x){ int cnt = 0; String str = Integer.toBinaryString(x); //System.out.println(str); for(int i = 0;i<str.length();i++){ if(str.charAt(i)=='1'){ cnt++; } } int ans = (int) Math.pow(3, 6-cnt); return ans; } static class Node2{ Node2 left = null; Node2 right = null; Node2 parent = null; int data; } static class BinarySearchTree{ Node2 root = null; int height = 0; int max = 0; int cnt = 1; ArrayList<Integer> parent = new ArrayList<>(); HashMap<Integer, Integer> hm = new HashMap<>(); public void insert(int x){ Node2 n = new Node2(); n.data = x; if(root==null){ root = n; } else{ Node2 temp = root,temb = null; while(temp!=null){ temb = temp; if(x>temp.data) temp = temp.right; else temp = temp.left; } if(x>temb.data) temb.right = n; else temb.left = n; n.parent = temb; parent.add(temb.data); } } public Node2 getSomething(int x, int y, Node2 n){ if(n.data==x || n.data==y) return n; else if(n.data>x && n.data<y) return n; else if(n.data<x && n.data<y) return getSomething(x,y,n.right); else return getSomething(x,y,n.left); } public Node2 search(int x,Node2 n){ if(x==n.data){ max = Math.max(max, n.data); return n; } if(x>n.data){ max = Math.max(max, n.data); return search(x,n.right); } else{ max = Math.max(max, n.data); return search(x,n.left); } } public int getHeight(Node2 n){ if(n==null) return 0; height = 1+ Math.max(getHeight(n.left), getHeight(n.right)); return height; } } static long findDiff(long[] arr, long[] brr, int m){ int i = 0, j = 0; long fa = 1000000000000L; while(i<m && j<m){ long x = arr[i]-brr[j]; if(x>=0){ if(x<fa) fa = x; j++; } else{ if((-x)<fa) fa = -x; i++; } } return fa; } public static long max(long x, long y, long z){ if(x>=y && x>=z) return x; if(y>=x && y>=z) return y; return z; } static long modInverse(long a, long mOD2){ return power(a, mOD2-2, mOD2); } static long power(long x, long y, long m) { if (y == 0) return 1; long p = power(x, y/2, m) % m; p = (p * p) % m; return (y%2 == 0)? p : (x * p) % m; } static long power2(long x,BigInteger y,long m){ long ans = 1; BigInteger two = new BigInteger("2"); while(y.compareTo(BigInteger.ZERO)>0){ if(y.getLowestSetBit()==y.bitCount()){ x = (x*x)%MOD; y = y.divide(two); } else{ ans = (ans*x)%MOD; y = y.subtract(BigInteger.ONE); } } return ans; } static BigInteger power2(BigInteger x, BigInteger y, BigInteger m){ BigInteger ans = new BigInteger("1"); BigInteger one = new BigInteger("1"); BigInteger two = new BigInteger("2"); BigInteger zero = new BigInteger("0"); while(y.compareTo(zero)>0){ //System.out.println(y); if(y.mod(two).equals(one)){ ans = ans.multiply(x).mod(m); y = y.subtract(one); } else{ x = x.multiply(x).mod(m); y = y.divide(two); } } return ans; } static BigInteger power(BigInteger x, BigInteger y, BigInteger m) { if (y.equals(0)) return (new BigInteger("1")); BigInteger p = power(x, y.divide(new BigInteger("2")), m).mod(m); p = (p.multiply(p)).mod(m); return (y.mod(new BigInteger("2")).equals(0))? p : (p.multiply(x)).mod(m); } static long d,x,y; public static void extendedEuclidian(long a, long b){ if(b == 0) { d = a; x = 1; y = 0; } else { extendedEuclidian(b, a%b); int temp = (int) x; x = y; y = temp - (a/b)*y; } } public static long gcd(long n, long m){ if(m!=0) return gcd(m,n%m); else return n; } static BufferedReader reader; static StringTokenizer tokenizer; static PrintWriter writer; static class FasterScanner { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; private SpaceCharFilter filter; public FasterScanner(InputStream stream) { this.stream = stream; } public int snext() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public long[] nextLongArray(int n) { long a[] = new long[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public String readString() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
Java
["3\n1 2\n1 3\n1 -1 1"]
2 seconds
["3"]
null
Java 8
standard input
[ "dp", "dfs and similar", "greedy", "trees" ]
f3c26aa520f6bfa6b181ec40bde7ee1b
The first line of the input contains n (1 ≤ n ≤ 105). Each of the next n - 1 lines contains two integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi) indicating there's an edge between vertices ai and bi. It's guaranteed that the input graph is a tree. The last line of the input contains a list of n space-separated integers v1, v2, ..., vn (|vi| ≤ 109).
1,800
Print the minimum number of operations needed to solve the task. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
standard output
PASSED
1d1718c1a6384ba9e5e712ddda9bd7b4
train_003.jsonl
1361374200
A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices.A subtree of a tree T is a tree with both vertices and edges as subsets of vertices and edges of T.You're given a tree with n vertices. Consider its vertices numbered with integers from 1 to n. Additionally an integer is written on every vertex of this tree. Initially the integer written on the i-th vertex is equal to vi. In one move you can apply the following operation: Select the subtree of the given tree that includes the vertex with number 1. Increase (or decrease) by one all the integers which are written on the vertices of that subtree. Calculate the minimum number of moves that is required to make all the integers written on the vertices of the given tree equal to zero.
256 megabytes
import java.io.*; import java.util.*; /** * Created by yusuf on 21/03/17. */ public class Main { public static void main(String[] args) { InputReader in = new InputReader(System.in); PrintWriter out = new PrintWriter(System.out); Solver solver = new Solver(); solver.solve(in, out); out.close(); } } class Solver { static class Node { ArrayList<Integer> ch; long pos; long neg; long val; Node() { ch = new ArrayList<Integer>(); pos = 0; neg = 0; val = 0; } }; private Node[] g; void dfs(Integer u, Integer p) { long mxpos = 0, mxneg = 0; for(Integer v : g[u].ch) { if(!v.equals(p)) { dfs(v, u); mxpos = Math.max(mxpos, g[v].pos); mxneg = Math.max(mxneg, g[v].neg); } } g[u].val += mxpos - mxneg; if(g[u].val < 0) { mxpos -= g[u].val; } else { mxneg += g[u].val; } g[u].pos = mxpos; g[u].neg = mxneg; } void solve(InputReader in, PrintWriter out) { int n = in.nextInt(); g = new Node[n + 1]; for(int i = 0; i <= n; ++i) { g[i] = new Node(); } for(int i = 1, u, v; i < n; ++i) { u = in.nextInt(); v = in.nextInt(); g[u].ch.add(v); g[v].ch.add(u); } for(int i = 1; i <= n; ++i) { g[i].val = in.nextInt(); } dfs(1, 0); out.println(g[1].neg + g[1].pos); } } class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } }
Java
["3\n1 2\n1 3\n1 -1 1"]
2 seconds
["3"]
null
Java 8
standard input
[ "dp", "dfs and similar", "greedy", "trees" ]
f3c26aa520f6bfa6b181ec40bde7ee1b
The first line of the input contains n (1 ≤ n ≤ 105). Each of the next n - 1 lines contains two integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi) indicating there's an edge between vertices ai and bi. It's guaranteed that the input graph is a tree. The last line of the input contains a list of n space-separated integers v1, v2, ..., vn (|vi| ≤ 109).
1,800
Print the minimum number of operations needed to solve the task. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
standard output
PASSED
de40f270290ad9b3aca04c5ea1424f6d
train_003.jsonl
1361374200
A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices.A subtree of a tree T is a tree with both vertices and edges as subsets of vertices and edges of T.You're given a tree with n vertices. Consider its vertices numbered with integers from 1 to n. Additionally an integer is written on every vertex of this tree. Initially the integer written on the i-th vertex is equal to vi. In one move you can apply the following operation: Select the subtree of the given tree that includes the vertex with number 1. Increase (or decrease) by one all the integers which are written on the vertices of that subtree. Calculate the minimum number of moves that is required to make all the integers written on the vertices of the given tree equal to zero.
256 megabytes
//package Graphs; import javafx.util.Pair; import java.io.*; import java.util.*; import java.util.StringTokenizer; public class main274B { public static PrintWriter out = new PrintWriter(System.out); public static FastScanner enter = new FastScanner(System.in); public static long[] w; public static void main(String[] args) throws IOException { int n = enter.nextInt(); w = new long[n + 1]; Graph g = new Graph(n); for (int i = 0; i < n - 1; i++) { int a = enter.nextInt(); int b = enter.nextInt(); g.add(a, b); g.add(b, a); } for (int i = 1; i <n+1 ; i++) { w[i]=enter.nextLong(); } g.solve(); } //and others on mccme static class Graph { int n; //vertex int m; //edges LinkedList<Integer>[] vert; //adjacency list //ArrayList<Pair<Integer, Integer>> edge; //edges in graph HashMap<Pair<Integer, Integer>, Long> ed; boolean used[]; //massives for veteces long dp[][]; public Graph(int n) { this.n = n; vert = new LinkedList[n + 1]; //1 ,...., n for (int i = 1; i < n + 1; i++) vert[i] = new LinkedList<>(); used = new boolean[n + 1]; ed = new HashMap<>(); dp=new long[n+1][2]; } public void add(int a, int b) { vert[a].addLast(b); /*if (edge != null) { edge.add(new Pair<>(a, b)); }*/ } public void solve(){ DFS(1); System.out.println(-dp[1][0]+dp[1][1]); /*for (int i = 1; i <n+1 ; i++) { System.out.println(dp[i][0]); System.out.println(dp[i][1]); }*/ } public void BFS(int s) { LinkedList<Integer> queue = new LinkedList<>();//our queue of verteces Arrays.fill(used, false); used[s] = true; queue.add(s); while (queue.size() != 0) { s = queue.poll(); out.print(s + " "); for (Integer n : vert[s]) { if (!used[n]) { used[n] = true; queue.addLast(n); } } } } public void DFS_no_rec(int s) { LinkedList<Integer> queue = new LinkedList<>();//our queue of verteces Arrays.fill(used, false); used[s] = true; queue.add(s); while (queue.size() != 0) { s = queue.poll(); out.print(s + " "); for (Integer n : vert[s]) { if (!used[n]) { used[n] = true; queue.addFirst(n); } } } } void DFSUtil(int v, boolean was[]) { was[v] = true; if(v!=1 && vert[v].size()==1){ dp[v][0]= Math.min(0,w[v]); dp[v][1]=Math.max(0,w[v]); return; } Iterator<Integer> i = vert[v].listIterator(); long n1=0; long n2=0; while (i.hasNext()) { int n = i.next(); if (!was[n]){ DFSUtil(n, was); } n1=Math.min(n1,dp[n][0]); n2=Math.max(n2,dp[n][1]); } dp[v][0]=n1+Math.min(0,w[v]-(n2+n1)); dp[v][1]=n2+Math.max(0,w[v]-(n2+n1)); } void DFS(int v) { boolean was[] = new boolean[n + 1]; DFSUtil(v, was); } public void cout_tree() { for (int i = 1; i < n + 1; i++) { out.println(i + " "); out.println(vert[i]); } } } static class FastScanner { BufferedReader br; StringTokenizer stok; FastScanner(InputStream is) { br = new BufferedReader(new InputStreamReader(is)); } String next() throws IOException { while (stok == null || !stok.hasMoreTokens()) { String s = br.readLine(); if (s == null) { return null; } stok = new StringTokenizer(s); } return stok.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } char nextChar() throws IOException { return (char) (br.read()); } String nextLine() throws IOException { return br.readLine(); } } }
Java
["3\n1 2\n1 3\n1 -1 1"]
2 seconds
["3"]
null
Java 8
standard input
[ "dp", "dfs and similar", "greedy", "trees" ]
f3c26aa520f6bfa6b181ec40bde7ee1b
The first line of the input contains n (1 ≤ n ≤ 105). Each of the next n - 1 lines contains two integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi) indicating there's an edge between vertices ai and bi. It's guaranteed that the input graph is a tree. The last line of the input contains a list of n space-separated integers v1, v2, ..., vn (|vi| ≤ 109).
1,800
Print the minimum number of operations needed to solve the task. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
standard output
PASSED
6929238e5c9ed04dde7a815358c92915
train_003.jsonl
1361374200
A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices.A subtree of a tree T is a tree with both vertices and edges as subsets of vertices and edges of T.You're given a tree with n vertices. Consider its vertices numbered with integers from 1 to n. Additionally an integer is written on every vertex of this tree. Initially the integer written on the i-th vertex is equal to vi. In one move you can apply the following operation: Select the subtree of the given tree that includes the vertex with number 1. Increase (or decrease) by one all the integers which are written on the vertices of that subtree. Calculate the minimum number of moves that is required to make all the integers written on the vertices of the given tree equal to zero.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; /** * Created by birukoudzmitry on 23.07.18. */ public class B274 { public static void main(String[] args) { MyScanner in = new MyScanner(); int n = in.nextInt(); Set<Integer>[] adjList = new Set[n]; for (int i = 0; i < n; ++i) { adjList[i] = new HashSet<>(); } for (int i = 0; i < n - 1; ++i) { int u = in.nextInt() - 1; int v = in.nextInt() - 1; adjList[u].add(v); adjList[v].add(u); } Queue<Vertex> vertexQueue = new ArrayDeque<>(); Vertex[] vArray = new Vertex[n]; for (int i = 0; i < n; ++i) { vArray[i] = new Vertex(); vArray[i].index = i; vArray[i].num = in.nextInt(); if (adjList[i].size() == 1 && i != 0 || (adjList[i].size() == 0 && i == 0)) { vertexQueue.add(vArray[i]); } } long result = 0; while (vertexQueue.size() > 0) { Queue<Vertex> nextQueue = new ArrayDeque<>(); while (!vertexQueue.isEmpty()) { Vertex v = vertexQueue.poll(); // System.out.println("vStat " + v.index + " " + v.sum()); if (v.index == 0) { // System.out.println(v.num + ", " + v.added + ", " + v.subtracted); // added - sub + num + added + sub System.out.println(v.added - v.subtracted + Math.abs(v.num + v.added + v.subtracted)); return; } Integer parentIndex = adjList[v.index].iterator().next(); if (v.sum() >= 0) { v.subtracted -= v.sum(); } else { v.added -= v.sum(); } vArray[parentIndex].subtracted = Math.min(vArray[parentIndex].subtracted, v.subtracted); vArray[parentIndex].added = Math.max(vArray[parentIndex].added, v.added); adjList[parentIndex].remove(Integer.valueOf(v.index)); if ((adjList[parentIndex].size() == 1 && parentIndex != 0) || (adjList[parentIndex].size() == 0 && parentIndex == 0)) { nextQueue.add(vArray[parentIndex]); } } vertexQueue = nextQueue; } System.out.println(result); } public static class Vertex { int index; long num; long added; long subtracted; long sum() { return num + added + subtracted; } } // -----------MyScanner class for faster input---------- public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } // -------------------------------------------------------- }
Java
["3\n1 2\n1 3\n1 -1 1"]
2 seconds
["3"]
null
Java 8
standard input
[ "dp", "dfs and similar", "greedy", "trees" ]
f3c26aa520f6bfa6b181ec40bde7ee1b
The first line of the input contains n (1 ≤ n ≤ 105). Each of the next n - 1 lines contains two integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi) indicating there's an edge between vertices ai and bi. It's guaranteed that the input graph is a tree. The last line of the input contains a list of n space-separated integers v1, v2, ..., vn (|vi| ≤ 109).
1,800
Print the minimum number of operations needed to solve the task. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
standard output
PASSED
e806699acf25a536e3038e01c9dc5e32
train_003.jsonl
1361374200
A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices.A subtree of a tree T is a tree with both vertices and edges as subsets of vertices and edges of T.You're given a tree with n vertices. Consider its vertices numbered with integers from 1 to n. Additionally an integer is written on every vertex of this tree. Initially the integer written on the i-th vertex is equal to vi. In one move you can apply the following operation: Select the subtree of the given tree that includes the vertex with number 1. Increase (or decrease) by one all the integers which are written on the vertices of that subtree. Calculate the minimum number of moves that is required to make all the integers written on the vertices of the given tree equal to zero.
256 megabytes
import java.util.*; import java.lang.*; import java.math.*; import java.io.*; /* spar5h */ public class cf4 implements Runnable{ final static long mod = (long)1e9 + 7; static ArrayList<Integer>[] adj; static long[] inc, dec, val; static int[] vis; static void dfs(int x, int p) { vis[x] = 1; for(int i = 0; i < adj[x].size(); i++) { int y = adj[x].get(i); if(y == p) continue; if(vis[y] == 0) dfs(y, x); inc[x] = Math.max(inc[x], inc[y]); dec[x] = Math.max(dec[x], dec[y]); } val[x] = val[x] + inc[x] - dec[x]; if(val[x] >= 0) dec[x] += val[x]; else inc[x] += -val[x]; } public void run() { InputReader s = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); int n = s.nextInt(); adj = new ArrayList[n + 1]; for(int i = 1; i <= n; i++) adj[i] = new ArrayList<Integer>(); for(int i = 0; i < n - 1; i++) { int u = s.nextInt(), v = s.nextInt(); adj[u].add(v); adj[v].add(u); } val = new long[n + 1]; for(int i = 1; i <= n; i++) val[i] = s.nextLong(); inc = new long[n + 1]; dec = new long[n + 1]; vis = new int[n + 1]; dfs(1, -1); w.println(inc[1] + dec[1]); w.close(); } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars==-1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if(numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int nextInt() { int c = read(); while(isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if(c<'0'||c>'9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } public static void main(String args[]) throws Exception { new Thread(null, new cf4(),"cf4",1<<26).start(); } }
Java
["3\n1 2\n1 3\n1 -1 1"]
2 seconds
["3"]
null
Java 8
standard input
[ "dp", "dfs and similar", "greedy", "trees" ]
f3c26aa520f6bfa6b181ec40bde7ee1b
The first line of the input contains n (1 ≤ n ≤ 105). Each of the next n - 1 lines contains two integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi) indicating there's an edge between vertices ai and bi. It's guaranteed that the input graph is a tree. The last line of the input contains a list of n space-separated integers v1, v2, ..., vn (|vi| ≤ 109).
1,800
Print the minimum number of operations needed to solve the task. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
standard output
PASSED
28130a96eb23f4d6307dae05b25b4e84
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.util.Scanner; public class pr245A { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int aSum, bSum, aPack, bPack; int[] sum = new int[3]; int[] pack = new int[3]; for (int i = 0; i < n; i++) { int a = in.nextInt(); int x = in.nextInt(); int y = in.nextInt(); sum[a] += x+y; pack[a] += x; } for (int i = 1; i < 3; i++) { if(pack[i] >= sum[i]/2) System.out.println("LIVE"); else System.out.println("DEAD"); } } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
994edbcc76abc41da509263ea4e8fabe
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int res = 0; int a = 0, b = 0; int aTotal = 0, bTotal = 0; for (int i = 0; i < n; i++) { int t = scanner.nextInt(), x = scanner.nextInt(), y = scanner.nextInt(); if (t == 1) { aTotal += 10; a += x; } else { bTotal += 10; b += x; } } System.out.println(a >= aTotal / 2 ? "LIVE" : "DEAD"); System.out.println(b >= bTotal / 2 ? "LIVE" : "DEAD"); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
1c52efa842cb11ab9382f7370ff64ae9
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner cv=new Scanner(System.in); int n=cv.nextInt(); int sum1=0,sum2=0; int a,b,c; for (int i = 0; i < n ; i++) { a=cv.nextInt(); b=cv.nextInt(); c=cv.nextInt(); if(a==1) sum1+=b-c; else sum2+=b-c; } System.out.println(sum1>=0? "LIVE":"DEAD"); System.out.println(sum2>=0? "LIVE":"DEAD"); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
c4935bcb73277074f8b2c52b52762565
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
//package Fcis; import java.util.*; import javafx.util.Pair; import java.lang.*; public class Assignment1 { static Scanner in = new Scanner(System.in); public static void main(String[] args) { long n, t, x, y, a = 0, b = 0; n = in.nextLong(); for(int i = 0; i < n; i++) { t = in.nextLong(); x = in.nextLong(); y = in.nextLong(); if (t == 1) { a += (x - y); } else b += (x - y); } if (a >= 0) System.out.println("LIVE"); else System.out.println("DEAD"); if (b >= 0) System.out.println("LIVE"); else System.out.println("DEAD"); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
31d5630fee2d13d963128a176ece46c4
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.util.Scanner; import java.util.stream.Collectors; import java.util.stream.IntStream; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] t = new int[n]; int[] x = new int[n]; int[] y = new int[n]; for (int i = 0; i < n; ++i) { t[i] = sc.nextInt(); x[i] = sc.nextInt(); y[i] = sc.nextInt(); } System.out.println(solve(t, x, y)); sc.close(); } static String solve(int[] t, int[] x, int[] y) { int[] xTotals = new int[3]; int[] yTotals = new int[3]; for (int i = 0; i < t.length; ++i) { xTotals[t[i]] += x[i]; yTotals[t[i]] += y[i]; } return IntStream.rangeClosed(1, 2).mapToObj(i -> (xTotals[i] >= yTotals[i]) ? "LIVE" : "DEAD") .collect(Collectors.joining("\n")); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
af64ea859ef292dc997c4b66e714a4c3
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
/* package whatever; // 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 whatever { public static void main (String[] args) throws java.lang.Exception { Scanner f = new Scanner(System.in); int size=f.nextInt(); int[] server1 = new int[3]; int[] server2 = new int[3]; int xx=0; while(xx < size){ int x,y,z; x= f.nextInt(); y= f.nextInt(); z=f.nextInt(); if(x ==1){ server1[0] += y; server1[1] += z; server1[2]++; }else{ server2[0] += y; server2[1] += z; server2[2]++; } xx++; } if(server1[0] >= server1[2]*5){ System.out.println("LIVE"); }else{ System.out.println("DEAD"); } if(server2[0] >= server2[2]*5){ System.out.println("LIVE"); }else{ System.out.println("DEAD"); } } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
217b817ace28db8da06aa399ffab6895
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.io.*; import java.util.*; public class SystemAdministrator { public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int value1 = 0; int value2 = 0; for(int i = 0; i < n; i++) { StringTokenizer st = new StringTokenizer(br.readLine()); int t = Integer.parseInt(st.nextToken()); if(t == 1) { value1 += Integer.parseInt(st.nextToken()) - Integer.parseInt(st.nextToken()); } else { value2 += Integer.parseInt(st.nextToken()) - Integer.parseInt(st.nextToken()); } } if(value1 >= 0) { System.out.println("LIVE"); } else { System.out.println("DEAD"); } if(value2 >= 0) { System.out.println("LIVE"); } else { System.out.println("DEAD"); } } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
0c2239b2fefe1cb2a41021d7b3d5eb8b
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
//take 3 (with fucking counters) //take 4 bitches //take 5 the counter are no counters anymore import java.util.Scanner; public class foo { static boolean isEven(int n){ if ( n % 2 == 0 ) return true; else return false; } public static void main(String[] args) { Scanner read = new Scanner(System.in); int t = read.nextInt(); int resa = 0 , losta = 0 , resb=0 , lostb = 0; while(true){ if(t==0) break; int server = read.nextInt(); int rx = read.nextInt(); int lx = read.nextInt(); if (server==1){ resa+= rx; losta+= lx; } else if (server==2){ resb+=rx; lostb+=lx; } t--; } System.out.println( (resa >= losta? "LIVE" : "DEAD") ); System.out.println( (resb >= lostb? "LIVE" : "DEAD") ); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
0f134b98cb8eaa718c4fb1b78d1d8fee
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.util.Scanner; public class Ishu { public static void main(String[] args) { Scanner scan=new Scanner(System.in); int n,i,j; int[][] a=new int[1002][3]; n=scan.nextInt(); for(i=0;i<n;++i) { for(j=0;j<3;++j) a[i][j]=scan.nextInt(); if(a[i][0]==1) { a[1000][1]+=a[i][1]; a[1000][2]+=a[i][2]; } else { a[1001][1]+=a[i][1]; a[1001][2]+=a[i][2]; } } if(a[1000][1]>=a[1000][2]) System.out.println("LIVE"); else System.out.println("DEAD"); if(a[1001][1]>=a[1001][2]) System.out.println("LIVE"); else System.out.println("DEAD"); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
19e3b88dd89fcdc4a7b3f57f6bb3eeba
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class SystemAdministrator { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { FastReader scan = new FastReader(); int n = scan.nextInt(); int aSuccess = 0; int aTotal = 0; int bSuccess = 0; int bTotal = 0; while(n-- > 0) { int t = scan.nextInt(); int x = scan.nextInt(); int y = scan.nextInt(); if(t == 1) { aSuccess += x; aTotal += x + y; } else { bSuccess += x; bTotal += x + y; } } System.out.println(((double) aSuccess / aTotal) >= 0.5 ? "LIVE" : "DEAD"); System.out.println(((double) bSuccess / bTotal) >= 0.5 ? "LIVE" : "DEAD"); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
dd2b056028e865a709171ae0450b85ae
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.util.Scanner; public class A245 { public static void main(String args[]){ Scanner sc = new Scanner(System.in); int sum1 = 0; int sum2 = 0; int sum3 = 0; int sum4 = 0; int n = sc.nextInt(); for (int i = 0; i < n; i++){ int ping = sc.nextInt(); int x = sc.nextInt(); int y = sc.nextInt(); if (ping == 1) { sum1 += x; sum2 += y; } else { sum3 += x; sum4 += y; } } if (sum1 >= sum2) System.out.println("LIVE"); else System.out.println("DEAD"); if (sum3 >= sum4) System.out.println("LIVE"); else System.out.println("DEAD"); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
262e62154194b7368d6054152b3bb590
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.util.Scanner; public class Demo { public static void main(String args[]) { Scanner sc = new Scanner(System.in); short n = sc.nextShort(); int server[] = new int[n]; int packet[][] = new int[n][2]; int ping_a = 0, lost_a = 0, ping_b = 0, lost_b = 0; for(int i=0;i<n;i++) { server[i] = sc.nextInt(); packet[i][0] = sc.nextInt(); packet[i][1] = sc.nextInt(); if(server[i] == 1) { ping_a +=10; lost_a += packet[i][1]; } else { ping_b += 10; lost_b += packet[i][1]; } } System.out.println(lost_a <= ping_a/2 ? "LIVE" : "DEAD"); System.out.print(lost_b <= ping_b/2 ? "LIVE" : "DEAD"); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
2d48927ea8c6c857f73b8153a897d6b4
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.util.*; public class A245 { static void printStatus(int up, int down) { System.out.println(up >= down ? "LIVE" : "DEAD"); } public static void main(String[] args) { // TODO Auto-generated method stub Scanner scan = new Scanner(System.in); int tries = scan.nextInt(); int aUp = 0; int aDown = 0; int bUp = 0; int bDown = 0; for (int i = 0; i < tries; i++) { boolean sendA = false; if (scan.nextInt() == 1) { sendA = true; } int upCnt = scan.nextInt(); int downCnt = scan.nextInt(); if (sendA) { aUp += upCnt; aDown += downCnt; } else { bUp += upCnt; bDown += downCnt; } } printStatus(aUp, aDown); printStatus(bUp, bDown); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
68eeaa9e96089924e9fec687becf3375
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.util.*; import java.io.*; public class CROCMBTU_2012A { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int c1 = 0, c2 = 0, w1 = 0, w2 = 0; for(int i = 0; i < n; i++) { if(sc.nextInt() == 1) { c1 += sc.nextInt(); w1 += sc.nextInt(); } else { c2 += sc.nextInt(); w2 += sc.nextInt(); } } if(c1 >= w1) System.out.println("LIVE"); else System.out.println("DEAD"); if(c2 >= w2) System.out.println("LIVE"); else System.out.println("DEAD"); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
1734b26c6031b0095a53ee222747a831
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.util.Scanner; public class A{ public static void main(String[] args){ Scanner s = new Scanner(System.in); int n, aR, aL, bR, bL; n = s.nextInt(); aR = 0; aL = 0; bR = 0; bL = 0; while(n>0){ int t, x, y; t = s.nextInt(); x = s.nextInt(); y = s.nextInt(); if(t==1){ aR += x; aL += y; }else{ bR += x; bL += y; } n--; } System.out.println(aR>=aL?"LIVE":"DEAD"); System.out.println(bR>=bL?"LIVE":"DEAD"); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
e7c99ccd750ebd8ffaf906f0c404825a
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.util.Scanner; public class A245 { public static void main(String q[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int sa=0,la=0,sb=0,lb=0; for (int i=0;i<n;i++){ int type=sc.nextInt(); if(type==1){ sa+=sc.nextInt(); la+=sc.nextInt(); }else { sb+=sc.nextInt(); lb+=sc.nextInt(); } } int ta=sa+la,tb=sb+lb; if(sa>=ta/2) System.out.println("LIVE"); else System.out.println("DEAD"); if(sb>=tb/2) System.out.println("LIVE"); else System.out.println("DEAD"); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
05b5518759fc7e1705491954427a34d1
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.io.*; import java.util.*; public class test { public static void main(String[] args) throws IOException { // BufferedReader br = new BufferedReader(new FileReader(".in")); // PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(".out"))); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); int num_a = 0, num_b = 0, good_a = 0, good_b = 0; while(n-- > 0) { st = new StringTokenizer(br.readLine()); int t = Integer.parseInt(st.nextToken()); int x = Integer.parseInt(st.nextToken()); int y = Integer.parseInt(st.nextToken()); if (t == 1) { num_a += 10; good_a += x; } else { num_b += 10; good_b += x; } } System.out.println(good_a*2 >= num_a ? "LIVE" : "DEAD"); System.out.println(good_b*2 >= num_b ? "LIVE" : "DEAD"); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
ea3b2d4911dccb86fbce939eaa168cb5
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class A245 { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(in.readLine()); int a = 0; int b = 0; int ac = 0; int bc = 0; for(int i = 0;i<n;i++) { String[] p = in.readLine().split(" "); int y = Integer.parseInt(p[0]); int q = Integer.parseInt(p[1]); if(y == 1) { ac++; a+=q; } else { bc++; b+=q; } } if(a >= (ac * 5)) { System.out.println("LIVE"); } else { System.out.println("DEAD"); } if(b >= (bc * 5)) { System.out.println("LIVE"); } else { System.out.println("DEAD"); } } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
83293a51c5c5484f8541ab213d967c70
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.util.Scanner ; public class A_245 { public static void main(String [] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int as = 0, af = 0, bs = 0, bf = 0 ; int t, x, y ; for(int i = 0; i < n; i++) { t = sc.nextInt(); x = sc.nextInt(); y = sc.nextInt(); if(t == 1) { as += x ; af += y ; } else { bs += x ; bf += y ; } } if(as < af) System.out.println("DEAD"); else System.out.println("LIVE"); if(bs < bf) System.out.println("DEAD"); else System.out.println("LIVE"); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
1f2246606194f174f89ff67b86dcb725
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.util.*; public class Server { public static void main(String args[]) throws Exception { Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int[] t=new int[n]; int[] x=new int[n]; int[] y=new int[n]; int a=0,b=0,ax=0,bx=0; for(int i=0;i<n;i++) { t[i]=scan.nextInt(); x[i]=scan.nextInt(); y[i]=scan.nextInt(); } for(int i=0;i<n;i++) { if(t[i]==1) { a=a+x[i]+y[i]; ax=ax+x[i]; } else { b=b+x[i]+y[i]; bx=bx+x[i]; } } if(ax>=(a/2)) System.out.println("LIVE"); else System.out.println("DEAD"); if(bx>=(b/2)) System.out.println("LIVE"); else System.out.println("DEAD"); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
bafaedbbc1db18e7e1d9975ffe7def48
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.util.*; final public class SystemAdministration { public static void main(String args[]) { Scanner s=new Scanner(System.in); int n=s.nextInt(); int a=0,b=0; int lossa=0,lossb=0; int senta=0,sentb=0; for(int i=0;i<n;i++) { int p=s.nextInt(); if(p==1) { senta=senta+s.nextInt(); lossa=lossa+s.nextInt(); } else { sentb=sentb+s.nextInt(); lossb=lossb+s.nextInt(); } } if(lossa>senta) System.out.println("DEAD"); else System.out.println("LIVE"); if(lossb>sentb) System.out.println("DEAD"); else System.out.println("LIVE"); s.close(); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
4e3ea7744b9a4ebd1fc9c1847e38c060
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.util.*; public class Solution { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int pingsA = 0; int pingsB = 0; int liveA = 0; int liveB = 0; for(int i = 0; i < n; i++) { int t = scan.nextInt(); int x = scan.nextInt(); int y = scan.nextInt(); if(t == 1) { pingsA++; liveA += x; } else { pingsB++; liveB += x; } } System.out.println((liveA >= 5*pingsA) ? "LIVE" : "DEAD"); System.out.println((liveB >= 5*pingsB) ? "LIVE" : "DEAD"); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
fe8f53f31a8a44f3395bbff3cb0f0494
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.util.Scanner; public class SystemAdministrator { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int suma=0; int sumb=0; for(int i=0; i<n; i++) { int t=sc.nextInt(); if(t==1) { suma+=sc.nextInt(); suma-=sc.nextInt(); } if(t==2) { sumb+=sc.nextInt(); sumb-=sc.nextInt(); } } System.out.println((suma>=0)?"LIVE":"DEAD"); System.out.println((sumb>=0)?"LIVE":"DEAD"); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
87778259df130d7bd8139fa12f788ebc
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.lang.*; import java.util.*; import java.io.*; public class systemp { int n ; Scanner sc=new Scanner(System.in); PrintWriter pr=new PrintWriter(System.out,true); public static void main(String... args) { systemp c=new systemp(); c.prop(); } public void prop() { int x,y,t1,t2 ; n=sc.nextInt(); x=0 ; y=0 ; t1=0 ; t2=0 ; for (int i=0;i<n ;++i) { int a,b,c ; a=sc.nextInt(); b=sc.nextInt(); c=sc.nextInt(); if (a==1) { t1+=10 ; x+=b ; } if (a==2) { t2+=10 ; y+=b ; } } if(x>=t1/2) pr.println("LIVE"); else pr.println("DEAD"); if(y>=t2/2) pr.println("LIVE"); else pr.println("DEAD"); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
f8f0e39ebd42e1f1974dfff57be6cef8
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); solver.solve(in, out); out.close(); } public static class TaskA { public void solve(InputReader in, PrintWriter out) { int n = in.nextInt(); double successA = 0, successB = 0; int amountA = 0; for (int i = 0; i < n; i++) { int type = in.nextInt(); int success = in.nextInt(); int losed = in.nextInt(); if (type == 1) { amountA++; successA += success; } else successB += success; } out.println(query(amountA * 10, successA)); out.println(query((n - amountA) * 10, successB)); } private String query(double all, double success) { if (success >= all / 2.0) return "LIVE"; else return "DEAD"; } } public static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
d2f6d33fc58b49b7a28e38e9f16334fe
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.util.Scanner; public class SystemAdministrator { public static void main(String[] args ) { Scanner scan = new Scanner(System.in); int n=scan.nextInt(); int c1=0,c2=0,c3=0,c4=0; while(n-->0) { int t=scan.nextInt(); int x=scan.nextInt(); int y=scan.nextInt(); if(t==1) { c1+=x; c2+=y; } else { c3+=x; c4+=y; } } if(c1>=c2) System.out.println("LIVE"); else System.out.println("DEAD"); if(c3>=c4) System.out.println("LIVE"); else System.out.println("DEAD"); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
2c4943d7ad205a29668c375c8ee1df1e
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.util.Scanner; public class Q2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); int a1 = 0, a2=0, b1=0, b2=0; for (int i = 0; i < t; i++) { int s = sc.nextInt(); if (s == 1){ a1 += sc.nextInt(); a2 += sc.nextInt(); } else { b1 += sc.nextInt(); b2 += sc.nextInt(); } } if (a1 >= a2) System.out.println("LIVE"); else System.out.println("DEAD"); if (b1 >= b2) System.out.println("LIVE"); else System.out.println("DEAD"); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
d15ef88220996939d7477c94c36077ee
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.util.*; import java.io.*; public class Solution { public static PrintWriter w = new PrintWriter(System.out); public static void main(String args[] ) throws Exception { Reader in = new Reader(); int n = in.nextInt(); int sa = 0, fa = 0; int sb = 0, fb = 0; while(n-- > 0) { if(in.nextInt() == 1) { sa += in.nextInt(); fa += in.nextInt(); } else { sb += in.nextInt(); fb += in.nextInt(); } } w.println((sa/fa) >= 1 ? "LIVE" : "DEAD"); w.println((sb/fb) >= 1 ? "LIVE" : "DEAD"); w.flush(); return; } } class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String nextLine() throws IOException { int c = read(); while(isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while(!isEndOfLine(c)); return res.toString(); } public String next() throws IOException { int c = read(); while(isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while(!isSpaceChar(c)); return res.toString(); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while(c <= ' ') c = read(); boolean neg = (c == '-'); if(neg) c = read(); do { ret = ret * 10 + c - '0'; } while((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public int[] nextIntArray(int n) throws IOException { int a[] = new int[n]; for(int i = 0; i < n; i++) a[i] = nextInt(); return a; } public int[][] next2dIntArray(int n, int m) throws IOException { int a[][] = new int[n][m]; for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) a[i][j] = nextInt(); return a; } public char nextChar() throws IOException { return next().charAt(0); } public long nextLong() throws IOException { long ret = 0; byte c = read(); while(c <= ' ') c = read(); boolean neg = (c == '-'); if(neg) c = read(); do { ret = ret * 10 + c - '0'; } while((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while(c <= ' ') c = read(); boolean neg = (c == '-'); if(neg) c = read(); do { ret = ret * 10 + c - '0'; } while((c = read()) >= '0' && c <= '9'); if (c == '.') { while((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if(neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if(bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if(bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if(din == null) return; din.close(); } public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
0e64720e0c80469cf57eed706eab7819
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.util.Scanner; public class SystemAdministrator { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(), i, ax = 0, ay = 0, bx = 0, by = 0; for (i = 0; i < n; i++) { int t = in.nextInt(), x = in.nextInt(), y = in.nextInt(); if (t == 1) { ax += x; ay += y; } else { bx += x; by += y; } } if (ax >= ay) { System.out.println("LIVE"); } else { System.out.println("DEAD"); } if (bx >= by) { System.out.println("LIVE"); } else { System.out.println("DEAD"); } in.close(); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
0aecd4a7b43476232f3890bdf1493535
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t1cnt = 0; int t2cnt = 0; int t1s = 0; int t2s = 0; int n = in.nextInt(); for (int i = 0; i < n; i++) { int a = in.nextInt(); int b = in.nextInt(); int c = in.nextInt(); if (a == 1) { t1cnt++; t1s += b; } else { t2cnt++; t2s += b; } } if (t1s >= (t1cnt * 5)) { System.out.println("LIVE"); } else { System.out.println("DEAD"); } if (t2s >= (t2cnt * 5)) { System.out.println("LIVE"); } else { System.out.println("DEAD"); } } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
01518f6e1058bc527d91d7d630ac4704
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class A245 { public static void main(String[] args) throws FileNotFoundException{ Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int ar = 0; int al = 0; int br = 0; int bl = 0; for(int i =0 ; i < n ; i ++) { int server = scan.nextInt(); int received = scan.nextInt(); int left = scan.nextInt(); //System.out.println(server + " " + received + " " + left); if(server == 1) { ar += received; al += left; //System.out.println(ar + " " + al); }else { br += received; bl += left; // System.out.println(br + " " + bl); } } int asum = ar + al; int bsum = br + bl; //System.out.println(ar + " " + asum); //System.out.println(br + " " + bsum); if(ar >= asum/2) { System.out.println("LIVE"); }else { System.out.println("DEAD"); } if(br >= bsum/2) { System.out.println("LIVE"); }else { System.out.println("DEAD"); } } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
dce97a945caf213ea817f5a16b24b404
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.util.Scanner; public class A18 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int array[][] = new int[n][3]; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { array[i][j] = sc.nextInt(); } } int one = 0; int two = 0; int one2 = 0; int two2 = 0; for (int i = 0; i < n; i++) { if (array[i][0] == 1) { one += array[i][1]; one2 += array[i][2]; } if (array[i][0] == 2) { two += array[i][1]; two2 += array[i][2]; } } System.out.println((one >= one2) ? "LIVE" : "DEAD"); System.out.println((two >= two2) ? "LIVE" : "DEAD"); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
80fc8083dab035fd3783c7e787ce394d
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.io.*; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = sc.nextInt(); int[] cntx = new int[2]; int[] cnty = new int[2]; while (n-- > 0) { int server = sc.nextInt() - 1; cntx[server] += sc.nextInt(); cnty[server] += sc.nextInt(); } for (int i = 0 ; i< 2 ; i++) out.println(cntx[i]>=cnty[i]?"LIVE":"DEAD"); out.flush(); out.close(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream system) { br = new BufferedReader(new InputStreamReader(system)); } public Scanner(String s) throws FileNotFoundException { br = new BufferedReader(new FileReader(new File(s))); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public String nextLine() throws IOException { return br.readLine(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public char nextChar() throws IOException { return next().charAt(0); } public Long nextLong() throws IOException { return Long.parseLong(next()); } public boolean ready() throws IOException { return br.ready(); } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public long[] nextLongArray(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public Integer[] nextIntegerArray(int n) throws IOException { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public double[] nextDoubleArray(int n) throws IOException { double[] ans = new double[n]; for (int i = 0; i < n; i++) ans[i] = nextDouble(); return ans; } public short nextShort() throws IOException { return Short.parseShort(next()); } } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
a3645b1508be530bce5e808ea2d9ebc7
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.*; import java.util.*; import java.util.LinkedList; import java.math.*; import java.lang.*; import java.util.PriorityQueue; import static java.lang.Math.*; @SuppressWarnings("unchecked") public class Solution implements Runnable { static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; private BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars==-1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if(numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int nextInt() { int c = read(); while(isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if(c<'0'||c>'9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } public static long min(long a,long b) { if(a>b) { return b; } return a; } public static int min(int a,int b) { if(a>b) { return b; } return a; } public static long max(long a,long b) { if(a>b) { return a; } return b; } public static int max(int a,int b) { if(a>b) { return a; } return b; } static class pair implements Comparable<pair> { int x; int y; pair(int x,int y) { this.x = x; this.y = y; } public int compareTo(pair b) { if(this.x>b.x) { return 1; } else if(this.x<b.x) { return -1; } else { return this.y-b.y; } } } public static int gcd(int a,int b) { if(a==0) return b; if(b==0) return a; while((a%=b)!=0&&(b%=a)!=0); return a^b; } public static long mod(long a) { if(a>0) return a; return -a; } static final int mod = (int)1e9+7;; public static long expo(long exp,long pow) { long ans = 1; while(pow!=0) { if((pow&1)==1) { ans = (ans*exp)%mod; } exp = (exp*exp)%mod; pow = pow>>1; } return ans; } static long start = 0; public static void start() { start = System.currentTimeMillis(); } public static void end() { System.out.println(System.currentTimeMillis()-start); } public static int random(int min,int max) { return (int)((max-min)*Math.random()); } public static String randString(int len) { String s = ""; while(len-->0) { char c = (char)(97+random(0,26)); s+=c; } return s; } public static void main(String args[]) throws Exception { new Thread(null, new Solution(),"Main",1<<26).start(); } public void run() { InputReader sc = new InputReader(System.in); PrintWriter out = new PrintWriter(System.out); int t1 = 1; //start(); while(t1-->0) { int n = sc.nextInt(); int[] alive = new int[2]; int[] dead = new int[2]; for(int i=0;i<n;i++) { int ind = sc.nextInt(); int a = sc.nextInt(); int b = sc.nextInt(); alive[ind-1]+=a; dead[ind-1]+=b; } if(alive[0]>=dead[0]) { out.println("LIVE"); } else { out.println("DEAD"); } if(alive[1]>=dead[1]) { out.println("LIVE"); } else { out.println("DEAD"); } } //end(); out.close(); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
b4b773c8585927440536ea0605be1b2e
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
public class SystemAdministrator{ public static void main(String []args){ java.util.Scanner scan=new java.util.Scanner(System.in); int n=scan.nextInt(); int [][]arr=new int[n][3]; for(int i=1;i<=arr.length;i++){ for(int j=1;j<=3;j++){ arr[i-1][j-1]=scan.nextInt(); } } int totalA=0,totalB=0,sendA=0,sendB=0; for(int i=1;i<=arr.length;i++){ if(arr[i-1][0]==1){ totalA+=10; sendA+=arr[i-1][1]; }else{ totalB+=10; sendB+=arr[i-1][1]; } } if(sendA<totalA/2){ System.out.println("DEAD"); }else{ System.out.println("LIVE"); } if(sendB<totalB/2){ System.out.println("DEAD"); }else{ System.out.println("LIVE"); } } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
7cd988a7099f0eedeaf6f8c90b2e3257
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.util.*; public class solution{ public static void main(String args[]){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int xa = 0, ya = 0, xb = 0, yb = 0; while(n-- != 0){ int t = sc.nextInt(); int x = sc.nextInt(); int y = sc.nextInt(); if(t == 1){ xa += x; ya += y; } else{ xb += x; yb += y; } } System.out.println(xa>=ya ? "LIVE" : "DEAD"); System.out.println(xb >= yb ? "LIVE" : "DEAD"); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
d42ced329b63492f30f20bafcf1c5e67
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner (System.in); int [] [] data = new int [input.nextInt()] [3]; String a = null,b = null; int x = 0,y = 0; int s = 0,t = 0; for (int i = 0; i < data.length; i++) { for (int j = 0; j < data[i].length; j++) { data [i] [j] = input.nextInt(); } if(data [i] [0] == 1){ x = x + data [i] [1]; s = s + data [i] [2]; }else{ y = y + data [i] [1]; t = t + data [i] [2]; } } a = x >= s ? "LIVE" : "DEAD"; b = y >= t ? "LIVE" : "DEAD"; System.out.println(a); System.out.println(b); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
032d03a70431e4f284cea880c60a1cbc
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.util.*; public class check { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int a[]=new int[2]; int b[]=new int[2]; int x=0; int y=0; while(n-->0) { int t=sc.nextInt(); int p=sc.nextInt(); int l=sc.nextInt(); a[t-1]+=p; b[t-1]+=l; b[t-1]+=p; } if((b[0]+1)/2<=a[0]) System.out.println("LIVE"); else System.out.println("DEAD"); if((b[1]+1)/2<=a[1]) System.out.println("LIVE"); else System.out.println("DEAD"); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
9875123895541a18b5cfea6631019a8f
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.util.HashSet; import java.util.Scanner; import java.util.Set; /** * * @author ACM */ public class SystemAdministrator { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt();int count = 0; int sumX=0; int sumY=0; int sumX2=0; int sumY2=0; String ar[] = new String[2]; for (int i = 0; i < n; i++) { int t = in.nextInt(); int x = in . nextInt(); int y = in.nextInt(); if(t==1){ sumX+=x; sumY+=y; if(sumX>=sumY) ar[0]="LIVE"; } else if(sumY>sumX) ar[0]="DEAD"; if(t==2){ sumX2+=x; sumY2+=y; if(sumX2>=sumY2) ar[1]="LIVE"; else if(sumY2>sumX2) ar[1]="DEAD"; }} if(ar[0]!=null) System.out.println(ar[0]); if(ar[1]!=null) System.out.println(ar[1]); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
369d13b833aa68ebb4471fb9b18f24d0
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int xa = 0; int ya = 0; int xb = 0; int yb = 0; for (int i = 1; i <= n; i++) { int ti = sc.nextInt(); int xi = sc.nextInt(); int yi = sc.nextInt(); if (ti == 1) { xa += xi; ya += yi; } else { xb += xi; yb += yi; } } if (xa >= ya) { System.out.println("LIVE"); } else { System.out.println("DEAD"); } if (xb >= yb) { System.out.println("LIVE"); } else { System.out.println("DEAD"); } sc.close(); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
b685245232bdbc0831367f859cd8857a
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.util.*; public class mohammad { public static void main(String[] args) { /* .................................. _oo0oo_ o8888888o 88" . "88 (| ^_^ |) 0\ = /0 ___/`---'\___ .' \\| |// '. / \\||| : ||M// \ / _||||| -:- |||||- \ | | \\\ - /// | | | \_| ''\---/'' |_/ | \ .-\__ '-' ___/-. / ___'. .' /--.--\ `. .'___ ."" '< `.___\_<|>_/___.' >' "". | | : `- \`.;`\ _ /`;.`/ - ` : | | \ \ `_. \_ __\ /__ _/ .-` / / =====`-.____`.___ \_____/___.-`___.-'===== `=---=' /*--------------->Mohammad Abohasan<---------------*/ Scanner sc = new Scanner (System.in); int n = sc.nextInt(); int a, b, c; int s=0, s1=0, s2=0, s3=0; for (int i = 0; i < n; i++){ a = sc.nextInt(); b = sc.nextInt(); c = sc.nextInt(); if(a == 1){ s += b; s1 += c;} else{ s2 += b ; s3 += c;} } if(s >= s1) System.out.println("LIVE"); else System.out.println("DEAD"); if(s2 >= s3) System.out.println("LIVE"); else System.out.println("DEAD"); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
094aa0b94e0b1497b51c0368df552828
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.util.Scanner; public class System_Administrator { public static void main(String[] args) { Scanner t = new Scanner(System.in); int n = t.nextInt(); int a = 0, b = 0, pa = 0, pb = 0; while (n-- > 0) { int p = t.nextInt(); int x = t.nextInt(); int y = t.nextInt(); if (p == 1) { pa += 10; a += x; } else { pb += 10; b += x; } } if (2 * a >= pa) System.out.println("LIVE"); else System.out.println("DEAD"); if (2 * b >= pb) System.out.println("LIVE"); else System.out.println("DEAD"); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
d74c374b1c44ec57e19dcb56eb73890e
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.util.*; public class Solution{ static Scanner scan = new Scanner(System.in); public static void main(String args[]){ int n = scan.nextInt(); int a1 = 0, b1 = 0, a2 = 0, b2 = 0; for(int i = 0; i < n; i++){ int t = scan.nextInt(); int x = scan.nextInt(); int y = scan.nextInt(); if(t == 1){ a1 += x; b1 += y; } else{ a2 += x; b2 += y; } } String a = (a1 >= b1) ? "LIVE" : "DEAD"; String b = (a2 >= b2) ? "LIVE" : "DEAD"; System.out.println(a); System.out.println(b); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
fc814ec2a914cae13b82df55757d5ffa
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.util.*; public class A { public static void main(String[] args) { int n; Scanner s = new Scanner(System.in); n = s.nextInt(); int a[] = new int[3*n]; int suma = 0,sumb = 0; int ca = 0,cb = 0; for(int i = 0; i < n ; i++) { int k = 0; for(int j = 0 ; j < 3 ; j++) { a[j] = s.nextInt(); if(j != 2) { if(j == 0) { if(a[j] == 1) { k = 1; } if(a[j] == 2) { k = 2; } } else { if(k == 1) { suma = suma + a[j]; ca++; } if(k == 2) { sumb = sumb + a[j]; cb++; } } } } } int y = ca*10; int y1 = cb*10; int y3 = y/2; int y4 = y1/2; if(suma >= y3) { System.out.println("LIVE"); } else { System.out.println("DEAD"); } if(sumb >= y4) { System.out.println("LIVE"); } else { System.out.println("DEAD"); } } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
fdb1b4a78154be070757435d8c52785b
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
import java.util.Scanner; public class codePing { public static void main(String[] args) { Scanner jin = new Scanner(System.in); int t = jin.nextInt(); int paket1X = 0; int paket1Y = 0; int paket2X = 0; int paket2Y = 0; boolean t1 = false; boolean t2 = false; for (int i = 0; i < t; i++){ int r = jin.nextInt(); int x = jin.nextInt(); int y = jin.nextInt(); if (r == 1){ paket1X +=x; paket1Y +=y; t1 = true; }else { paket2X +=x; paket2Y +=y; t2 = true; } } if (t1){ if (paket1X >= paket1Y){ System.out.println("LIVE"); }else System.out.println("DEAD"); } if (t2){ if (paket2X >= paket2Y){ System.out.println("LIVE"); }else System.out.println("DEAD"); } } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
4533be0fdf245a002562623f9606c9f7
train_003.jsonl
1353339000
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
256 megabytes
/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; /* Name of the class has to be "Main" only if the class is public. */ public class bbg { public static int result; public static ArrayList<Integer> [] graph; public static int[]cats; public static int vizitat[]; public static int x; //public static HashMap<String, Integer> map2; public static void main (String[] args) throws java.lang.Exception { Scanner input=new Scanner(System.in); HashMap<Integer, Integer> contor1= new HashMap<Integer, Integer>(); HashMap<Integer, Integer> contor2= new HashMap<Integer, Integer>(); HashMap<Integer, Integer> map= new HashMap<Integer, Integer>(); HashMap<String, Integer> curatare= new HashMap<String, Integer>(); HashMap<String, Integer> combinari= new HashMap<String, Integer>(); int n=input.nextInt(); int a=0; int b=0; for (int i=1;i<=n;i++){ int t=input.nextInt(); int x=input.nextInt(); int y=input.nextInt(); if(t==1) a+=x-y; else b+=x-y; } if(a>=0) System.out.println("LIVE"); else System.out.println("DEAD"); if(b>=0) System.out.println("LIVE"); else System.out.println("DEAD"); } }
Java
["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"]
2 seconds
["LIVE\nLIVE", "LIVE\nDEAD"]
NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
Java 8
standard input
[ "implementation" ]
1d8870a705036b9820227309d74dd1e8
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
800
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format.
standard output
PASSED
5a147b2dc609c9d8b9e1b9176314df13
train_003.jsonl
1395502200
Little Chris is participating in a graph cutting contest. He's a pro. The time has come to test his skills to the fullest.Chris is given a simple undirected connected graph with n vertices (numbered from 1 to n) and m edges. The problem is to cut it into edge-distinct paths of length 2. Formally, Chris has to partition all edges of the graph into pairs in such a way that the edges in a single pair are adjacent and each edge must be contained in exactly one pair.For example, the figure shows a way Chris can cut a graph. The first sample test contains the description of this graph. You are given a chance to compete with Chris. Find a way to cut the given graph or determine that it is impossible!
256 megabytes
import java.io.*; import java.util.*; public class Main { int n,m; ArrayList<Edge> list[],in[]; boolean visited[]; private void solve()throws Exception { n=nextInt(); m=nextInt(); list=new ArrayList[n+1]; for(int i=1;i<=n;i++) list[i]=new ArrayList<>(); for(int i=1;i<=m;i++) { int u=nextInt(); int v=nextInt(); Edge e=new Edge(u,v); list[u].add(e); list[v].add(e); } if(m%2!=0) { out.println("No solution"); return; } in=new ArrayList[n+1]; for(int i=1;i<=n;i++) in[i]=new ArrayList<>(); visited=new boolean[n+1]; dfs(1,null); for(int i=1;i<=n;i++) for(int j=0;j+1<in[i].size();j+=2) { Edge first=in[i].get(j); Edge second=in[i].get(j+1); int x=first.src==i?first.dest:first.src; int y=second.src==i?second.dest:second.src; out.println(x+" "+i+" "+y); } } int dfs(int v,Edge p) { visited[v]=true; int deg=0; for(Edge e:list[v]) { int next=v^e.src^e.dest; if(!visited[next]) deg+=dfs(next,e); } for(Edge e:list[v]) if(!e.used && e!=p) { e.used=true; in[v].add(e); deg++; } if(p==null) return 0; p.used=true; int par=v^p.src^p.dest; in[deg%2==0?par:v].add(p); return 1-deg%2; } class Edge { int src,dest; boolean used; Edge(int u,int v) { src=u; dest=v; used=false; } } /////////////////////////////////////////////////////////// public void run()throws Exception { br=new BufferedReader(new InputStreamReader(System.in)); st=null; out=new PrintWriter(System.out); solve(); br.close(); out.close(); } public static void main(String args[])throws Exception{ new Main().run(); } BufferedReader br; StringTokenizer st; PrintWriter out; String nextToken()throws Exception{ while(st==null || !st.hasMoreTokens()) st=new StringTokenizer(br.readLine()); return st.nextToken(); } String nextLine()throws Exception{ return br.readLine(); } int nextInt()throws Exception{ return Integer.parseInt(nextToken()); } long nextLong()throws Exception{ return Long.parseLong(nextToken()); } double nextDouble()throws Exception{ return Double.parseDouble(nextToken()); } }
Java
["8 12\n1 2\n2 3\n3 4\n4 1\n1 3\n2 4\n3 5\n3 6\n5 6\n6 7\n6 8\n7 8", "3 3\n1 2\n2 3\n3 1", "3 2\n1 2\n2 3"]
2 seconds
["1 2 4\n1 3 2\n1 4 3\n5 3 6\n5 6 8\n6 7 8", "No solution", "1 2 3"]
null
Java 11
standard input
[ "constructive algorithms", "dfs and similar", "graphs" ]
ac56745749fc10be925a456925b79ab6
The first line of input contains two space-separated integers n and m (1 ≤ n, m ≤ 105), the number of vertices and the number of edges in the graph. The next m lines contain the description of the graph's edges. The i-th line contains two space-separated integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi), the numbers of the vertices connected by the i-th edge. It is guaranteed that the given graph is simple (without self-loops and multi-edges) and connected. Note: since the size of the input and output could be very large, don't use slow output techniques in your language. For example, do not use input and output streams (cin, cout) in C++.
2,300
If it is possible to cut the given graph into edge-distinct paths of length 2, output lines. In the i-th line print three space-separated integers xi, yi and zi, the description of the i-th path. The graph should contain this path, i.e., the graph should contain edges (xi, yi) and (yi, zi). Each edge should appear in exactly one path of length 2. If there are multiple solutions, output any of them. If it is impossible to cut the given graph, print "No solution" (without quotes).
standard output
PASSED
d870e9a4250b21fcaafb23fea0b4e0f4
train_003.jsonl
1394465400
Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: there wouldn't be a pair of any side-adjacent cards with zeroes in a row; there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way.
256 megabytes
import java.util.Scanner; public class Command { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner scaner = new Scanner(System.in); int n = scaner.nextInt(); int m = scaner.nextInt(); int mMax = n * 2 + 2; int mMin = n - 1; if (m > mMax || m < mMin) { System.out.println(-1); return; } int c0 = 0; int c1 = 0; StringBuilder result = new StringBuilder(); if (m >= mMin && m < mMax - 1) { for (int k = 0; k < n; k++) { if (c0 < n) { c0++; result.append(0); } if (k < m - mMin) { if (c1 < m - 1) { c1 += 2; result.append(11); } else if (c1 < m) { c1++; result.append(1); } } else { if (c1 < m) { c1++; result.append(1); } } } } if (m >= mMin && m >= mMax - 1) { for (int k = 0; k < n; k++) { if (k < m - mMin) { if (c1 < m - 1) { c1 += 2; result.append(11); } } else { if (c1 < m) { c1++; result.append(1); } } if (c0 < n) { c0++; result.append(0); } } if (m - c1 == 2) { result.append(11); } if (m - c1 == 1) { result.append(1); } } System.out.println(result); } }
Java
["1 2", "4 8", "4 10", "1 5"]
1 second
["101", "110110110101", "11011011011011", "-1"]
null
Java 6
standard input
[ "constructive algorithms", "implementation", "greedy" ]
854c561539596722b1dbc8f99cbdca78
The first line contains two integers: n (1 ≤ n ≤ 106) — the number of cards containing number 0; m (1 ≤ m ≤ 106) — the number of cards containing number 1.
1,400
In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1.
standard output
PASSED
1673622a5fe2e4ac252168fef5f8bce6
train_003.jsonl
1394465400
Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: there wouldn't be a pair of any side-adjacent cards with zeroes in a row; there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; public class C { void solve() throws Exception { int n = nextInt(); // zeros int m = nextInt(); // ones int size = n+m; if (m < n-1 || m > 2*(n+1)) { System.out.println(-1); return; } int[] gaps = new int[n+1]; // insert the first ones for (int i=1; i<=n+1 && m>0; i++) { gaps[i%(n+1)]++; m--; } // insert the left over ones for (int i=0; i<n+1 && m>0; i++) { gaps[i]++; m--; } // construct the string char[] ans = new char[size]; for (int i=0; i<size; i++) ans[i] = '0'; int i = 0; for (int gap : gaps) { while(gap>0) { ans[i++] = '1'; gap--; } i++; } System.out.println(ans); } BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String nextLine() throws Exception { String line = stdin.readLine(); st = new StringTokenizer(""); return line; } int[] nextInts(int n) throws Exception { int[] res = new int[n]; for (int i=0; i<n; i++) res[i] = nextInt(); return res; } long[] nextLongs(int n) throws Exception { long[] res = new long[n]; for (int i=0; i<n; i++) res[i] = nextLong(); return res; } double[] nextDoubles(int n) throws Exception { double[] res = new double[n]; for (int i=0; i<n; i++) res[i] = nextDouble(); return res; } String next() throws Exception { while (!st.hasMoreTokens()) st = new StringTokenizer(stdin.readLine()); return st.nextToken(); } int nextInt() throws Exception { return Integer.parseInt(next()); } long nextLong() throws Exception { return Long.parseLong(next()); } double nextDouble() throws Exception { return Double.parseDouble(next()); } public static void main(String[] args) throws Exception { new C().solve(); } }
Java
["1 2", "4 8", "4 10", "1 5"]
1 second
["101", "110110110101", "11011011011011", "-1"]
null
Java 6
standard input
[ "constructive algorithms", "implementation", "greedy" ]
854c561539596722b1dbc8f99cbdca78
The first line contains two integers: n (1 ≤ n ≤ 106) — the number of cards containing number 0; m (1 ≤ m ≤ 106) — the number of cards containing number 1.
1,400
In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1.
standard output
PASSED
bee47922a6cf7107850fd6d29393a27a
train_003.jsonl
1394465400
Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: there wouldn't be a pair of any side-adjacent cards with zeroes in a row; there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way.
256 megabytes
import java.util.*; import java.io.*; public class cartas2{ public static PrintWriter out = new PrintWriter(System.out);//HACER FLUSHHHH public static void main(String args[]) throws IOException{ BufferedReader lector = new BufferedReader(new InputStreamReader(System.in)); String tmp =lector.readLine(); int b = Integer.parseInt(tmp.substring(0,tmp.indexOf(" "))); int a = Integer.parseInt(tmp.substring(tmp.indexOf(" ")+1)); StringBuilder res = new StringBuilder(); int c = 0; boolean puede = true; boolean talpaso = false; while((a>0 || b>0) && puede){ //System.out.println(a+" "+b); if(a==0 && b==1){ talpaso=true; break; }else if(b>1 && a==0 && c==0){ puede = false; break; } if(b==0 && a>2){ puede = false; break; } if(c==0 && ((b==0 && a==2)|| (b!=0 && a>1 && (a-2)/b<3 && a-2>=b))){res=res.append("11"); a-=2; }else if(c==0){res=res.append("1");a--;} if(c==1 && b>0){ res=res.append("0"); b--; } c^=1; } System.out.println((puede?(talpaso?"0"+res:res):-1)); } }
Java
["1 2", "4 8", "4 10", "1 5"]
1 second
["101", "110110110101", "11011011011011", "-1"]
null
Java 6
standard input
[ "constructive algorithms", "implementation", "greedy" ]
854c561539596722b1dbc8f99cbdca78
The first line contains two integers: n (1 ≤ n ≤ 106) — the number of cards containing number 0; m (1 ≤ m ≤ 106) — the number of cards containing number 1.
1,400
In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1.
standard output
PASSED
fa29ff525fbde3ec247cf0d0a800205e
train_003.jsonl
1394465400
Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: there wouldn't be a pair of any side-adjacent cards with zeroes in a row; there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way.
256 megabytes
import java.io.PrintWriter; import java.util.*; public class c { public static void main(String[] args) { Scanner input = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = input.nextInt(), m = input.nextInt(); if(n > m+1 || m > 2*n+2) { out.println(-1); } else { if(n>m) { out.print(0); n--; } while(m>n && n>0) { out.print("110"); m-=2; n--; } while(m>0 && n>0) { out.print("10"); n--; m--; } while(m>0) { out.print(1); m--; } } out.close(); } }
Java
["1 2", "4 8", "4 10", "1 5"]
1 second
["101", "110110110101", "11011011011011", "-1"]
null
Java 6
standard input
[ "constructive algorithms", "implementation", "greedy" ]
854c561539596722b1dbc8f99cbdca78
The first line contains two integers: n (1 ≤ n ≤ 106) — the number of cards containing number 0; m (1 ≤ m ≤ 106) — the number of cards containing number 1.
1,400
In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1.
standard output
PASSED
f84a02587a621fcffe80ac9b03b0b05b
train_003.jsonl
1394465400
Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: there wouldn't be a pair of any side-adjacent cards with zeroes in a row; there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way.
256 megabytes
import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.IOException; import java.io.PrintWriter; import java.util.*; /** * User: anatoly * Date: 25.06.13 * Time: 0:04 * Вот и подошел черед олимпиад. Ваня и Егор решили создать свою команду для участия в олимпиаде по программированию. * Поскольку они с первого класса вместе, есть надежда, что это хоть как-то поможет ребятам в командной работе. На каждую командную олимпиаду Ваня берет свои игровые карточки с числами. Он берет карточки исключительно с числами 1 и 0. Ребята — очень суеверны. Они считают, что олимпиада будет для них успешной, если перед ее началом можно разложить все карточки в ряд таким образом, чтобы: не существовало пары соседних в ряду карточек с нулями; не существовало тройки карточек, лежащих подряд, на которых записаны единицы. Сегодня Ваня принес n карточек с нулями и m карточек с единицами. Карточек оказалось так много, что ребята не знают: можно ли разложить все эти карточки описанным способом или нет. Помогите им найти требуемое расположение карточек, или сообщите ребятам, что это невозможно. Входные данные В первой строке записано два целых числа: n (1 ≤ n ≤ 106) — количество карточек с числом 0; m (1 ≤ m ≤ 106) — количество карточек с числом 1. Выходные данные В единственной строке выведите требуемую последовательность из единичек и нулей без пробелов. Если же такую последовательность получить невозможно, выведите -1. */ public class C401div2C implements Runnable { BufferedInputStream is = new BufferedInputStream(System.in); Scanner s = new Scanner(is); BufferedOutputStream os = new BufferedOutputStream(System.out); PrintWriter out = new PrintWriter(os); public static void main(String[] args) { new Thread(new C401div2C()).start(); } @Override public void run() { try { solve(); out.flush(); os.flush(); } catch (IOException e) { } } public void solve() throws IOException { int zeros = s.nextInt(); int ones = s.nextInt(); if (ones > 2*zeros + 2 || zeros > ones + 1){ out.print(-1); return; } if (zeros == ones){ for (int i = 0; i < zeros; i++) { out.print("01"); } } else if (ones == zeros - 1){ out.print("0"); for (int i = 0; i < ones; i++) { out.print("10"); } } else { //ones > zeros, zeros <= 2n+2 int doubleOnes = ones - zeros - 1; boolean onesFlag = true; while (zeros >0 || ones >0){ if (onesFlag){ if (doubleOnes >0){ out.print("11"); ones-=2; doubleOnes--; } else { out.print("1"); ones--; } } else { out.print("0"); zeros--; } onesFlag = !onesFlag; } } } }
Java
["1 2", "4 8", "4 10", "1 5"]
1 second
["101", "110110110101", "11011011011011", "-1"]
null
Java 6
standard input
[ "constructive algorithms", "implementation", "greedy" ]
854c561539596722b1dbc8f99cbdca78
The first line contains two integers: n (1 ≤ n ≤ 106) — the number of cards containing number 0; m (1 ≤ m ≤ 106) — the number of cards containing number 1.
1,400
In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1.
standard output
PASSED
13f356473837cdf8ef0501d70480249f
train_003.jsonl
1394465400
Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: there wouldn't be a pair of any side-adjacent cards with zeroes in a row; there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way.
256 megabytes
import java.util.*; import java.io.*; import java.lang.*; import java.math.*; import java.math.BigInteger; public class Main { final int INF = 1000000000; final int MAXN = 1111111; Scanner input = new Scanner(System.in); BufferedReader inp = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) throws IOException { new Main().run(); } void run() throws IOException { int n, m; n = input.nextInt(); m = input.nextInt(); if (n > m + 1 || (m + 1) / 2 > n + 1) { out.println(-1); out.close(); return; } int[] rep = new int[MAXN]; for (int i = 0; i < Math.min(n, m); ++i) { rep[i] = 1; } if (n >= m) { for (int i = 0; i < m; ++i) { out.print("01"); } if (n > m) out.println(0); } else { m -= Math.min(n, m); for (int i = 0; i < n && m > 0; ++i) { --m; ++rep[i]; } if (m > 0) { if (m == 1) out.print("1"); else out.print("11"); } for (int i = 0; i < n; ++i) { out.print("0"); for (int k = 0; k < rep[i]; ++k) { out.print("1"); } } } out.close(); } }
Java
["1 2", "4 8", "4 10", "1 5"]
1 second
["101", "110110110101", "11011011011011", "-1"]
null
Java 6
standard input
[ "constructive algorithms", "implementation", "greedy" ]
854c561539596722b1dbc8f99cbdca78
The first line contains two integers: n (1 ≤ n ≤ 106) — the number of cards containing number 0; m (1 ≤ m ≤ 106) — the number of cards containing number 1.
1,400
In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1.
standard output
PASSED
32cc4a401752b95b2cc635ad39368091
train_003.jsonl
1394465400
Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: there wouldn't be a pair of any side-adjacent cards with zeroes in a row; there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way.
256 megabytes
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; public class Solver { public static void main(String[] Args) throws NumberFormatException, IOException { new Solver().Run(); } PrintWriter pw; StringTokenizer Stok; BufferedReader br; public String nextToken() throws IOException { while (Stok == null || !Stok.hasMoreTokens()) { Stok = new StringTokenizer(br.readLine()); } return Stok.nextToken(); } public int nextInt() throws NumberFormatException, IOException { return Integer.parseInt(nextToken()); } public double nextDouble() throws NumberFormatException, IOException { return Double.parseDouble(nextToken()); } public long nextLong() throws NumberFormatException, IOException { return Long.parseLong(nextToken()); } int kol0, kol1; public void Run() throws NumberFormatException, IOException { //br = new BufferedReader(new FileReader("input.txt")); pw = new PrintWriter("output.txt"); br=new BufferedReader(new InputStreamReader(System.in)); pw=new PrintWriter(new OutputStreamWriter(System.out)); kol0=nextInt(); kol1=nextInt(); if ((kol0>kol1+1) || (kol0*2+2<kol1)) { pw.println("-1"); pw.flush(); pw.close(); return; } StringBuilder sb=new StringBuilder(); if (kol1<kol0*2+1) { sb.append('0'); kol0--; } while ((kol1>1) && (kol1<kol0*2+2)) { sb.append("10"); kol0--; kol1--; } if (kol1==1) { sb.append('1'); if (kol0==1) sb.append('0'); } else { sb.append("11"); kol1-=2; while (kol1>0) { sb.append("011"); kol1-=2; kol0--; } } pw.println(sb.toString()); pw.flush(); pw.close(); } }
Java
["1 2", "4 8", "4 10", "1 5"]
1 second
["101", "110110110101", "11011011011011", "-1"]
null
Java 6
standard input
[ "constructive algorithms", "implementation", "greedy" ]
854c561539596722b1dbc8f99cbdca78
The first line contains two integers: n (1 ≤ n ≤ 106) — the number of cards containing number 0; m (1 ≤ m ≤ 106) — the number of cards containing number 1.
1,400
In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1.
standard output
PASSED
52db8e433cc669e3e23c40ba8fa9400f
train_003.jsonl
1394465400
Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: there wouldn't be a pair of any side-adjacent cards with zeroes in a row; there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way.
256 megabytes
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; /** * * * @author pttrung */ public class C { // public static long x, y, gcd; public static int Mod = 1000000007; public static PrintWriter out; public static int[] x = {0, 0, 1, -1}; public static int[] y = {1, -1, 0, 0}; public static void main(String[] args) throws FileNotFoundException { Scanner in = new Scanner(); out = new PrintWriter(System.out); // System.out.println(Integer.MAX_VALUE); // PrintWriter out = new PrintWriter(new FileOutputStream(new File("output.txt"))); int n = in.nextInt(); int m = in.nextInt(); StringBuilder result = new StringBuilder(); while(m > n && n > 0){ result.append("11"); result.append("0"); m -=2; n --; } if(n == 0 && m > 2){ out.println(-1); }else{ while(n > 0 && m > 0){ result.append("1"); result.append("0"); m--; n--; } if(n > 1 && m == 0){ out.println(-1); }else{ if(n > 0){ result = result.reverse().append('0'); }else if( m > 0) { while(m > 0){ result.append('1'); m--; } } out.println(result.toString()); } } out.close(); } public static void cal(int i, int j, boolean[][] map, boolean[][] check) { check[i][j] = true; for (int k = 0; k < 4; k++) { int a = x[k] + i; int b = y[k] + j; if (a >= 0 && b >= 0 && a < map.length && b < map[0].length && !check[a][b] && map[a][b]) { cal(a, b, map, check); } } } public static Point clock(Point p, int n, int m) { Point result = new Point(p.y, n - p.x + 1); return result; } public static Point anti_clock(Point p, int n, int m) { Point result = new Point(m - p.y + 1, p.x); return result; } public static int cross(Point a, Point b) { int val = a.x * b.y - a.y * b.x; return val; } public static long pow(long a, long b) { if (b == 0) { return 1; } if (b == 1) { return a; } long val = pow(a, b / 2); if (b % 2 == 0) { return val * val; } else { return val * val * a; } } public static int gcd(int a, int b) { if (b == 0) { return a; } return gcd(b, a % b); } public static class Point implements Comparable<Point> { int x, y; public Point(int x, int y) { this.x = x; this.y = y; } @Override public int compareTo(Point o) { if (x != o.x) { return x - o.x; } else { return y - o.y; } } } // public static void extendEuclid(long a, long b) { // if (b == 0) { // x = 1; // y = 0; // gcd = a; // return; // } // extendEuclid(b, a % b); // long x1 = y; // long y1 = x - (a / b) * y; // x = x1; // y = y1; // // } public static class FT { int[] data; FT(int n) { data = new int[n]; } public void update(int index, int value) { while (index < data.length) { data[index] += value; index += (index & (-index)); } } public int get(int index) { int result = 0; while (index > 0) { result += data[index]; index -= (index & (-index)); } return result; } } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner() throws FileNotFoundException { // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true)); br = new BufferedReader(new InputStreamReader(System.in)); // br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt")))); } public String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { throw new RuntimeException(); } } return st.nextToken(); } public long nextLong() { return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { st = null; try { return br.readLine(); } catch (Exception e) { throw new RuntimeException(); } } public boolean endLine() { try { String next = br.readLine(); while (next != null && next.trim().isEmpty()) { next = br.readLine(); } if (next == null) { return true; } st = new StringTokenizer(next); return st.hasMoreTokens(); } catch (Exception e) { throw new RuntimeException(); } } } }
Java
["1 2", "4 8", "4 10", "1 5"]
1 second
["101", "110110110101", "11011011011011", "-1"]
null
Java 6
standard input
[ "constructive algorithms", "implementation", "greedy" ]
854c561539596722b1dbc8f99cbdca78
The first line contains two integers: n (1 ≤ n ≤ 106) — the number of cards containing number 0; m (1 ≤ m ≤ 106) — the number of cards containing number 1.
1,400
In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1.
standard output
PASSED
cb3e5e030c0e2f1e71a812b47802fb7a
train_003.jsonl
1394465400
Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: there wouldn't be a pair of any side-adjacent cards with zeroes in a row; there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way.
256 megabytes
import java.util.Scanner; public class C { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int zeros = scan.nextInt(); int ones = scan.nextInt(); if (ones - 2 <= 2 * zeros && ones >= zeros - 1) { char[] sequence = new char[ones + zeros]; int i=0; if(ones == zeros - 1){ sequence[i] = '0'; i++; zeros--; } else if(ones - 2 == 2 * zeros){ sequence[0] = sequence[1] = '1'; ones -=2; i += 2; } else if(ones - 1 == 2 * zeros){ sequence[i] = '1'; ones--; i++; } for (; i < sequence.length; i++) { boolean useOne; if(i > 0 && sequence[i-1] == '0'){ useOne = true; } else if(i > 1 && sequence[i - 1] == '1' && sequence[i - 2] == '1'){ useOne = false; } else { useOne = ones > zeros; } if (useOne && ones > 0) { sequence[i] = '1'; ones--; } else { sequence[i] = '0'; zeros--; } } System.out.println(String.valueOf(sequence)); } else { System.out.println("-1"); } } }
Java
["1 2", "4 8", "4 10", "1 5"]
1 second
["101", "110110110101", "11011011011011", "-1"]
null
Java 6
standard input
[ "constructive algorithms", "implementation", "greedy" ]
854c561539596722b1dbc8f99cbdca78
The first line contains two integers: n (1 ≤ n ≤ 106) — the number of cards containing number 0; m (1 ≤ m ≤ 106) — the number of cards containing number 1.
1,400
In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1.
standard output
PASSED
e57086e59f77ec00f23c05f75ecfd5cf
train_003.jsonl
1394465400
Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: there wouldn't be a pair of any side-adjacent cards with zeroes in a row; there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way.
256 megabytes
import java.util.Scanner; public class C { /** * @param args */ public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); // zeros int m = in.nextInt(); // ones StringBuilder ss = new StringBuilder(); int a = (((int) Math.ceil(m / 2.0)) - 1); if (n < a || m < n - 1) { System.out.println("-1"); } else { int rem = m - n; int mm = m; for (int i = 0; i < n; i++) { ss.append("0"); if (mm-- > 0) ss.append("1"); if (rem > 0) { ss.append("1"); rem--; } } if (rem == 1) System.out.println("1" + ss.toString()); else if (rem == 2) System.out.println("11" + ss.toString()); else System.out.println(ss.toString()); } } }
Java
["1 2", "4 8", "4 10", "1 5"]
1 second
["101", "110110110101", "11011011011011", "-1"]
null
Java 6
standard input
[ "constructive algorithms", "implementation", "greedy" ]
854c561539596722b1dbc8f99cbdca78
The first line contains two integers: n (1 ≤ n ≤ 106) — the number of cards containing number 0; m (1 ≤ m ≤ 106) — the number of cards containing number 1.
1,400
In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1.
standard output
PASSED
17d16b8836d7c3469ac333ad6803234f
train_003.jsonl
1394465400
Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: there wouldn't be a pair of any side-adjacent cards with zeroes in a row; there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way.
256 megabytes
import java.util.*; public class Team401C { public static void main(String[] args) { // Set up scanner Scanner sc = new Scanner(System.in); // System.out.println("Enter n"); int n = sc.nextInt(); // System.out.println("Enter m"); int m = sc.nextInt(); if (m < n-1 || m > 2*n+2) { System.out.println(-1); return; } StringBuilder st = new StringBuilder(); // Special cases where there must be ones on one or both ends if (m == 2*n-1) { st.append("1"); for (int i=0; i<n-1; i++) { st.append("011"); } st.append("0"); System.out.println(st.toString()); return; } if (m == 2*n) { st.append("11"); for (int i=0; i<n-1; i++) { st.append("011"); } st.append("0"); System.out.println(st.toString()); return; } if (m == 2*n + 1) { st.append("11"); for (int i=0; i<n-1; i++) { st.append("011"); } st.append("01"); System.out.println(st.toString()); return; } if (m == 2*n + 2) { st.append("11"); for (int i=0; i<n; i++) { st.append("011"); } System.out.println(st.toString()); return; } // General case--zero on each end int twocount = m-(n-1); st.append("0"); for (int i=1; i<n; i++) { if (twocount > 0) { st.append("110"); } else { st.append("10"); } twocount--; } System.out.println(st.toString()); } }
Java
["1 2", "4 8", "4 10", "1 5"]
1 second
["101", "110110110101", "11011011011011", "-1"]
null
Java 6
standard input
[ "constructive algorithms", "implementation", "greedy" ]
854c561539596722b1dbc8f99cbdca78
The first line contains two integers: n (1 ≤ n ≤ 106) — the number of cards containing number 0; m (1 ≤ m ≤ 106) — the number of cards containing number 1.
1,400
In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1.
standard output
PASSED
3fcc9333c337154d252de20d5a5c43d9
train_003.jsonl
1394465400
Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: there wouldn't be a pair of any side-adjacent cards with zeroes in a row; there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way.
256 megabytes
import java.util.*; import java.io.*; public class TaskC { private FastScanner in; private PrintWriter out; public void solve() throws IOException { int n = in.nextInt(), m = in.nextInt(); if (n > m + 1 || m > 2 * (n + 1)) { out.print(-1); return; } if (n == m + 1) { out.print(0); for (int i = 0; i < n - 1; i++) { out.print("10"); } return; } int rem = m; int intervals = n; for (int i = 0; i < n; i++) { if (rem > intervals) { out.print("110"); rem -= 2; intervals--; } else { out.print("10"); rem--; intervals--; } } if (rem != 0) { for (int i = 0; i < rem; i++) { out.print(1); } } } public void run() { try { in = new FastScanner(); out = new PrintWriter(System.out); solve(); out.close(); } catch (IOException e) { e.printStackTrace(); } } private class FastScanner { private BufferedReader br; private StringTokenizer st; public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } public String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } } public static void main(String[] arg) { new TaskC().run(); } }
Java
["1 2", "4 8", "4 10", "1 5"]
1 second
["101", "110110110101", "11011011011011", "-1"]
null
Java 6
standard input
[ "constructive algorithms", "implementation", "greedy" ]
854c561539596722b1dbc8f99cbdca78
The first line contains two integers: n (1 ≤ n ≤ 106) — the number of cards containing number 0; m (1 ≤ m ≤ 106) — the number of cards containing number 1.
1,400
In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1.
standard output
PASSED
cadd8ad7d8d036856e0b05a0dc2c35b3
train_003.jsonl
1536165300
The Metropolis computer network consists of $$$n$$$ servers, each has an encryption key in the range from $$$0$$$ to $$$2^k - 1$$$ assigned to it. Let $$$c_i$$$ be the encryption key assigned to the $$$i$$$-th server. Additionally, $$$m$$$ pairs of servers are directly connected via a data communication channel. Because of the encryption algorithms specifics, a data communication channel can only be considered safe if the two servers it connects have distinct encryption keys. The initial assignment of encryption keys is guaranteed to keep all data communication channels safe.You have been informed that a new virus is actively spreading across the internet, and it is capable to change the encryption key of any server it infects. More specifically, the virus body contains some unknown number $$$x$$$ in the same aforementioned range, and when server $$$i$$$ is infected, its encryption key changes from $$$c_i$$$ to $$$c_i \oplus x$$$, where $$$\oplus$$$ denotes the bitwise XOR operation.Sadly, you know neither the number $$$x$$$ nor which servers of Metropolis are going to be infected by the dangerous virus, so you have decided to count the number of such situations in which all data communication channels remain safe. Formally speaking, you need to find the number of pairs $$$(A, x)$$$, where $$$A$$$ is some (possibly empty) subset of the set of servers and $$$x$$$ is some number in the range from $$$0$$$ to $$$2^k - 1$$$, such that when all servers from the chosen subset $$$A$$$ and none of the others are infected by a virus containing the number $$$x$$$, all data communication channels remain safe. Since this number can be quite big, you are asked to find its remainder modulo $$$10^9 + 7$$$.
512 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.PrintStream; import java.io.BufferedReader; import java.util.Map; import java.util.Map.Entry; import java.util.HashMap; import java.util.ArrayList; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; /** * Built using CHelper plug-in Actual solution is at the top * * @author dima */ public class Main { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastReader in = new FastReader(); PrintWriter out = new PrintWriter(outputStream); TaskE solver = new TaskE(); solver.solve(1, in, out); out.close(); } static class TaskE { long[] pow2; public void solve(int testNumber, FastReader in, PrintWriter out) { long start = System.nanoTime(); final int n = in.nextInt(); final long pairs = in.nextLong(); final long k = in.nextLong(); long[] C = new long[n]; for (int i = 0; i < n; ++i) { C[i] = in.nextLong(); } pow2 = new long[n + 1]; pow2[0] = 1; final long Mod = 1000000007; for (int i = 1; i < n + 1; ++i) { pow2[i] = (pow2[i - 1] * 2) % Mod; } HashMap<Long, ArrayList<Edge>> X = new HashMap<>(); for (int i = 0; i < pairs; ++i) { int from = in.nextInt() - 1; int to = in.nextInt() - 1; long xor = C[from] ^ C[to]; ArrayList<Edge> currList = X.getOrDefault(xor, new ArrayList<>()); currList.add(new Edge(from, to)); X.put(xor, currList); } long end = System.nanoTime(); System.err.println("Init took: " + Long.toString((end - start) / 1000_000) + " milliseconds seconds"); int[] component = new int[n]; //int[] rank = new int[n]; long res = ((((1L << k) - X.size()) % Mod) * pow(n, Mod)) % Mod; for (Map.Entry<Long, ArrayList<Edge>> entries : X.entrySet()) { int total_components = n; //Arrays.fill(component, -1); for (Edge e : entries.getValue()) { component[e.from] = e.from; component[e.to] = e.to; //rank[e.from] = rank[e.to] = 0; } for (Edge e : entries.getValue()) { int c1 = get_component(component, e.from); int c2 = get_component(component, e.to); if (c1 != c2) { --total_components; merge(component, c1, c2); } } res = (res + pow(total_components, Mod)) % Mod; } long end2 = System.nanoTime(); System.err.println("Solution took: " + Long.toString((end2 - end) / 1000_000) + " milliseconds seconds"); out.println(res); } long pow(int n, long m) { return pow2[n]; } int get_component(int[] set, int v) { if (set[v] != v) { int res = get_component(set, set[v]); set[v] = res; return res; } return v; } void merge(int[] set, int c1, int c2) { set[c1] = c2; } class Edge { public int from; public int to; Edge(int from, int to) { this.from = from; this.to = to; } } } }
Java
["4 4 2\n0 1 0 1\n1 2\n2 3\n3 4\n4 1", "4 5 3\n7 1 7 2\n1 2\n2 3\n3 4\n4 1\n2 4"]
3 seconds
["50", "96"]
NoteConsider the first example.Possible values for the number $$$x$$$ contained by the virus are $$$0$$$, $$$1$$$, $$$2$$$ and $$$3$$$.For values $$$0$$$, $$$2$$$ and $$$3$$$ the virus can infect any subset of the set of servers, which gives us $$$16$$$ pairs for each values. A virus containing the number $$$1$$$ can infect either all of the servers, or none. This gives us $$$16 + 2 + 16 + 16 = 50$$$ pairs in total.
Java 8
standard input
[ "combinatorics", "dfs and similar", "graphs" ]
9319661488d33bd0b43a5ff8b238f694
The first line of input contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \leq n \leq 500\,000$$$, $$$0 \leq m \leq \min(\frac{n(n - 1)}{2}, 500\,000)$$$, $$$0 \leq k \leq 60$$$) — the number of servers, the number of pairs of servers directly connected by a data communication channel, and the parameter $$$k$$$, which defines the range of possible values for encryption keys. The next line contains $$$n$$$ integers $$$c_i$$$ ($$$0 \leq c_i \leq 2^k - 1$$$), the $$$i$$$-th of which is the encryption key used by the $$$i$$$-th server. The next $$$m$$$ lines contain two integers $$$u_i$$$ and $$$v_i$$$ each ($$$1 \leq u_i, v_i \leq n$$$, $$$u_i \ne v_i$$$) denoting that those servers are connected by a data communication channel. It is guaranteed that each pair of servers appears in this list at most once.
2,200
The only output line should contain a single integer — the number of safe infections of some subset of servers by a virus with some parameter, modulo $$$10^9 + 7$$$.
standard output
PASSED
07e6fc332c9830be77d4bf888a0e2fc3
train_003.jsonl
1536165300
The Metropolis computer network consists of $$$n$$$ servers, each has an encryption key in the range from $$$0$$$ to $$$2^k - 1$$$ assigned to it. Let $$$c_i$$$ be the encryption key assigned to the $$$i$$$-th server. Additionally, $$$m$$$ pairs of servers are directly connected via a data communication channel. Because of the encryption algorithms specifics, a data communication channel can only be considered safe if the two servers it connects have distinct encryption keys. The initial assignment of encryption keys is guaranteed to keep all data communication channels safe.You have been informed that a new virus is actively spreading across the internet, and it is capable to change the encryption key of any server it infects. More specifically, the virus body contains some unknown number $$$x$$$ in the same aforementioned range, and when server $$$i$$$ is infected, its encryption key changes from $$$c_i$$$ to $$$c_i \oplus x$$$, where $$$\oplus$$$ denotes the bitwise XOR operation.Sadly, you know neither the number $$$x$$$ nor which servers of Metropolis are going to be infected by the dangerous virus, so you have decided to count the number of such situations in which all data communication channels remain safe. Formally speaking, you need to find the number of pairs $$$(A, x)$$$, where $$$A$$$ is some (possibly empty) subset of the set of servers and $$$x$$$ is some number in the range from $$$0$$$ to $$$2^k - 1$$$, such that when all servers from the chosen subset $$$A$$$ and none of the others are infected by a virus containing the number $$$x$$$, all data communication channels remain safe. Since this number can be quite big, you are asked to find its remainder modulo $$$10^9 + 7$$$.
512 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.PrintStream; import java.io.BufferedReader; import java.util.Map; import java.util.Map.Entry; import java.util.HashMap; import java.util.ArrayList; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; /** * Built using CHelper plug-in Actual solution is at the top * * @author dima */ public class Main { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastReader in = new FastReader(); PrintWriter out = new PrintWriter(outputStream); TaskE solver = new TaskE(); solver.solve(1, in, out); out.close(); } static class TaskE { long[] pow2; public void solve(int testNumber, FastReader in, PrintWriter out) { long start = System.nanoTime(); final int n = in.nextInt(); final long pairs = in.nextLong(); final long k = in.nextLong(); long[] C = new long[n]; for (int i = 0; i < n; ++i) { C[i] = in.nextLong(); } pow2 = new long[n + 1]; pow2[0] = 1; final long Mod = 1000000007; for (int i = 1; i < n + 1; ++i) { pow2[i] = (pow2[i - 1] * 2) % Mod; } HashMap<Long, ArrayList<Edge>> X = new HashMap<>(); for (int i = 0; i < pairs; ++i) { int from = in.nextInt() - 1; int to = in.nextInt() - 1; long xor = C[from] ^ C[to]; ArrayList<Edge> currList = X.getOrDefault(xor, new ArrayList<>()); currList.add(new Edge(from, to)); X.put(xor, currList); } long end = System.nanoTime(); System.err.println("Init took: " + Long.toString((end - start) / 1000_000) + " milliseconds seconds"); int[] component = new int[n]; long res = ((((1L << k) - X.size()) % Mod) * pow(n, Mod)) % Mod; for (Map.Entry<Long, ArrayList<Edge>> entries : X.entrySet()) { int total_components = n; for (Edge e : entries.getValue()) { component[e.from] = e.from; component[e.to] = e.to; } for (Edge e : entries.getValue()) { int c1 = get_component(component, e.from); int c2 = get_component(component, e.to); if (c1 != c2) { --total_components; merge(component, c1, c2); } } res = (res + pow(total_components, Mod)) % Mod; } long end2 = System.nanoTime(); System.err.println("Solution took: " + Long.toString((end2 - end) / 1000_000) + " milliseconds seconds"); out.println(res); } long pow(int n, long m) { if (n == 0) return 1; if ((n & 1) == 0) { long half = pow(n >> 1, m); return (half * half) % m; } else { return (2 * pow(n-1, m)) % m; } } int get_component(int[] set, int v) { if (set[v] != v) { int res = get_component(set, set[v]); set[v] = res; return res; } return v; } void merge(int[] set, int c1, int c2) { set[c1] = c2; } class Edge { public int from; public int to; Edge(int from, int to) { this.from = from; this.to = to; } } } }
Java
["4 4 2\n0 1 0 1\n1 2\n2 3\n3 4\n4 1", "4 5 3\n7 1 7 2\n1 2\n2 3\n3 4\n4 1\n2 4"]
3 seconds
["50", "96"]
NoteConsider the first example.Possible values for the number $$$x$$$ contained by the virus are $$$0$$$, $$$1$$$, $$$2$$$ and $$$3$$$.For values $$$0$$$, $$$2$$$ and $$$3$$$ the virus can infect any subset of the set of servers, which gives us $$$16$$$ pairs for each values. A virus containing the number $$$1$$$ can infect either all of the servers, or none. This gives us $$$16 + 2 + 16 + 16 = 50$$$ pairs in total.
Java 8
standard input
[ "combinatorics", "dfs and similar", "graphs" ]
9319661488d33bd0b43a5ff8b238f694
The first line of input contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \leq n \leq 500\,000$$$, $$$0 \leq m \leq \min(\frac{n(n - 1)}{2}, 500\,000)$$$, $$$0 \leq k \leq 60$$$) — the number of servers, the number of pairs of servers directly connected by a data communication channel, and the parameter $$$k$$$, which defines the range of possible values for encryption keys. The next line contains $$$n$$$ integers $$$c_i$$$ ($$$0 \leq c_i \leq 2^k - 1$$$), the $$$i$$$-th of which is the encryption key used by the $$$i$$$-th server. The next $$$m$$$ lines contain two integers $$$u_i$$$ and $$$v_i$$$ each ($$$1 \leq u_i, v_i \leq n$$$, $$$u_i \ne v_i$$$) denoting that those servers are connected by a data communication channel. It is guaranteed that each pair of servers appears in this list at most once.
2,200
The only output line should contain a single integer — the number of safe infections of some subset of servers by a virus with some parameter, modulo $$$10^9 + 7$$$.
standard output
PASSED
29d767efb26678626a4659adac4e9ce8
train_003.jsonl
1536165300
The Metropolis computer network consists of $$$n$$$ servers, each has an encryption key in the range from $$$0$$$ to $$$2^k - 1$$$ assigned to it. Let $$$c_i$$$ be the encryption key assigned to the $$$i$$$-th server. Additionally, $$$m$$$ pairs of servers are directly connected via a data communication channel. Because of the encryption algorithms specifics, a data communication channel can only be considered safe if the two servers it connects have distinct encryption keys. The initial assignment of encryption keys is guaranteed to keep all data communication channels safe.You have been informed that a new virus is actively spreading across the internet, and it is capable to change the encryption key of any server it infects. More specifically, the virus body contains some unknown number $$$x$$$ in the same aforementioned range, and when server $$$i$$$ is infected, its encryption key changes from $$$c_i$$$ to $$$c_i \oplus x$$$, where $$$\oplus$$$ denotes the bitwise XOR operation.Sadly, you know neither the number $$$x$$$ nor which servers of Metropolis are going to be infected by the dangerous virus, so you have decided to count the number of such situations in which all data communication channels remain safe. Formally speaking, you need to find the number of pairs $$$(A, x)$$$, where $$$A$$$ is some (possibly empty) subset of the set of servers and $$$x$$$ is some number in the range from $$$0$$$ to $$$2^k - 1$$$, such that when all servers from the chosen subset $$$A$$$ and none of the others are infected by a virus containing the number $$$x$$$, all data communication channels remain safe. Since this number can be quite big, you are asked to find its remainder modulo $$$10^9 + 7$$$.
512 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 E { static int mod = 1000000007; static InputReader in = new InputReader(System.in); static PrintWriter out = new PrintWriter(System.out); static long pow(long a,long b) { long ret=1; long mul=a; while(b!=0) { if(b%2==1) { ret*=mul; ret%=mod; } b/=2; mul*=mul; mul%=mod; } return ret; } static int getroot(int u) { while(parent[u]!=u) { parent[u]=parent[parent[u]]; u=parent[u]; } return u; } static boolean union(int l,int r) { int u=getroot(l); int v=getroot(r); if(u==v) { return false; } if(size[v]>size[u]) { return union(v, u); } parent[v]=parent[u]; size[u]+=size[v]; return true; } static class Pair { int a,b; Pair(int a,int b) { this.a=a; this.b=b; } } static int func(long xor) { ArrayList<Pair> list=map.get(xor); int comp=n; for(Pair p : list) { int u=p.a; int v=p.b; if(getroot(u)==getroot(v)) continue; else { comp--; union(u, v); } } for(Pair p : list) { int u=p.a; int v=p.b; size[u]=1; size[v]=1; parent[u]=u; parent[v]=v; } return comp; } static int n,m,k; static long[] a; static ArrayList<Integer>[] adjlist; static int[] size; static int[] parent; static Map<Long, ArrayList<Pair>> map; public static void main(String[] args) { n=in.nextInt(); m=in.nextInt(); k=in.nextInt(); a=new long[n+1]; size=new int[n+1]; parent=new int[n+1]; for(int i=1;i<=n;i++) { parent[i]=i; size[i]=1; } map=new HashMap<>(); for(int i=1;i<=n;i++) { a[i]=in.nextLong(); } adjlist=new ArrayList[n+1]; for(int i=1;i<=n;i++) { adjlist[i]=new ArrayList<>(); } for(int i=1;i<=m;i++) { int u=in.nextInt(); int v=in.nextInt(); adjlist[u].add(v); adjlist[v].add(u); long xor=a[u]^a[v]; if(map.containsKey(xor)) { ArrayList<Pair> temp=map.get(xor); temp.add(new Pair(u, v)); map.put(xor, temp); } else { ArrayList<Pair> temp=new ArrayList<>(); temp.add(new Pair(u, v)); map.put(xor, temp); } } long ans=0; //tr(map.keySet()); for(Long l : map.keySet()) { long comp=func(l); //tr(comp); ans+=pow(2, comp); ans%=mod; } long rem=(pow(2, k)-map.keySet().size())%mod; ans+=(rem*pow(2, n))%mod; ans%=mod; out.println(ans); out.close(); } static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; public InputReader(InputStream st) { this.stream = st; } public int read() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } private static void tr(Object... o) { if (!(System.getProperty("ONLINE_JUDGE") != null)) System.out.println(Arrays.deepToString(o)); } }
Java
["4 4 2\n0 1 0 1\n1 2\n2 3\n3 4\n4 1", "4 5 3\n7 1 7 2\n1 2\n2 3\n3 4\n4 1\n2 4"]
3 seconds
["50", "96"]
NoteConsider the first example.Possible values for the number $$$x$$$ contained by the virus are $$$0$$$, $$$1$$$, $$$2$$$ and $$$3$$$.For values $$$0$$$, $$$2$$$ and $$$3$$$ the virus can infect any subset of the set of servers, which gives us $$$16$$$ pairs for each values. A virus containing the number $$$1$$$ can infect either all of the servers, or none. This gives us $$$16 + 2 + 16 + 16 = 50$$$ pairs in total.
Java 8
standard input
[ "combinatorics", "dfs and similar", "graphs" ]
9319661488d33bd0b43a5ff8b238f694
The first line of input contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \leq n \leq 500\,000$$$, $$$0 \leq m \leq \min(\frac{n(n - 1)}{2}, 500\,000)$$$, $$$0 \leq k \leq 60$$$) — the number of servers, the number of pairs of servers directly connected by a data communication channel, and the parameter $$$k$$$, which defines the range of possible values for encryption keys. The next line contains $$$n$$$ integers $$$c_i$$$ ($$$0 \leq c_i \leq 2^k - 1$$$), the $$$i$$$-th of which is the encryption key used by the $$$i$$$-th server. The next $$$m$$$ lines contain two integers $$$u_i$$$ and $$$v_i$$$ each ($$$1 \leq u_i, v_i \leq n$$$, $$$u_i \ne v_i$$$) denoting that those servers are connected by a data communication channel. It is guaranteed that each pair of servers appears in this list at most once.
2,200
The only output line should contain a single integer — the number of safe infections of some subset of servers by a virus with some parameter, modulo $$$10^9 + 7$$$.
standard output
PASSED
67c64174c9c9152a69aa8e0db481e8c5
train_003.jsonl
1536165300
The Metropolis computer network consists of $$$n$$$ servers, each has an encryption key in the range from $$$0$$$ to $$$2^k - 1$$$ assigned to it. Let $$$c_i$$$ be the encryption key assigned to the $$$i$$$-th server. Additionally, $$$m$$$ pairs of servers are directly connected via a data communication channel. Because of the encryption algorithms specifics, a data communication channel can only be considered safe if the two servers it connects have distinct encryption keys. The initial assignment of encryption keys is guaranteed to keep all data communication channels safe.You have been informed that a new virus is actively spreading across the internet, and it is capable to change the encryption key of any server it infects. More specifically, the virus body contains some unknown number $$$x$$$ in the same aforementioned range, and when server $$$i$$$ is infected, its encryption key changes from $$$c_i$$$ to $$$c_i \oplus x$$$, where $$$\oplus$$$ denotes the bitwise XOR operation.Sadly, you know neither the number $$$x$$$ nor which servers of Metropolis are going to be infected by the dangerous virus, so you have decided to count the number of such situations in which all data communication channels remain safe. Formally speaking, you need to find the number of pairs $$$(A, x)$$$, where $$$A$$$ is some (possibly empty) subset of the set of servers and $$$x$$$ is some number in the range from $$$0$$$ to $$$2^k - 1$$$, such that when all servers from the chosen subset $$$A$$$ and none of the others are infected by a virus containing the number $$$x$$$, all data communication channels remain safe. Since this number can be quite big, you are asked to find its remainder modulo $$$10^9 + 7$$$.
512 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; /** * Runtime O(E * log(V)) * * @author Don Li */ public class NetworkSafety { int N = (int) 5e5 + 10; int MOD = (int) 1e9 + 7; int sz = 0; int[] parent = new int[N]; void solve() { int n = in.nextInt(), m = in.nextInt(), k = in.nextInt(); long[] c = new long[n]; for (int i = 0; i < n; i++) c[i] = in.nextLong(); int[] fr = new int[m], to = new int[m]; for (int i = 0; i < m; i++) { fr[i] = in.nextInt() - 1; to[i] = in.nextInt() - 1; } long[] p2 = new long[N]; p2[0] = 1; for (int i = 1; i < N; i++) p2[i] = 2 * p2[i - 1] % MOD; Map<Long, List<Integer>> x_to_edges = new HashMap<>(); for (int i = 0; i < m; i++) { int u = fr[i], v = to[i]; long x = c[u] ^ c[v]; if (!x_to_edges.containsKey(x)) { List<Integer> edges = new ArrayList<>(); edges.add(i); x_to_edges.put(x, edges); } else { List<Integer> edges = x_to_edges.get(x); edges.add(i); } } long ans = 0; Arrays.fill(parent, -1); for (long x : x_to_edges.keySet()) { sz = n; List<Integer> edges = x_to_edges.get(x); for (int i : edges) { int u = fr[i], v = to[i]; union(u, v); } ans = (ans + p2[sz]) % MOD; for (int i : edges) { int u = fr[i], v = to[i]; parent[u] = -1; parent[v] = -1; } } ans = (ans + ((1L << k) - x_to_edges.size()) % MOD * p2[n] % MOD) % MOD; out.println(ans); } void union(int i, int j) { int u = find(i), v = find(j); if (u == v) return; if (parent[u] > parent[v]) { int tmp = u; u = v; v = tmp; } parent[u] += parent[v]; parent[v] = u; sz--; } int find(int i) { if (parent[i] < 0) return i; return parent[i] = find(parent[i]); } public static void main(String[] args) { in = new FastScanner(new BufferedReader(new InputStreamReader(System.in))); out = new PrintWriter(System.out); new NetworkSafety().solve(); out.close(); } static FastScanner in; static PrintWriter out; static class FastScanner { BufferedReader in; StringTokenizer st; public FastScanner(BufferedReader in) { this.in = in; } public String nextToken() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(in.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(nextToken()); } public long nextLong() { return Long.parseLong(nextToken()); } public double nextDouble() { return Double.parseDouble(nextToken()); } } }
Java
["4 4 2\n0 1 0 1\n1 2\n2 3\n3 4\n4 1", "4 5 3\n7 1 7 2\n1 2\n2 3\n3 4\n4 1\n2 4"]
3 seconds
["50", "96"]
NoteConsider the first example.Possible values for the number $$$x$$$ contained by the virus are $$$0$$$, $$$1$$$, $$$2$$$ and $$$3$$$.For values $$$0$$$, $$$2$$$ and $$$3$$$ the virus can infect any subset of the set of servers, which gives us $$$16$$$ pairs for each values. A virus containing the number $$$1$$$ can infect either all of the servers, or none. This gives us $$$16 + 2 + 16 + 16 = 50$$$ pairs in total.
Java 8
standard input
[ "combinatorics", "dfs and similar", "graphs" ]
9319661488d33bd0b43a5ff8b238f694
The first line of input contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \leq n \leq 500\,000$$$, $$$0 \leq m \leq \min(\frac{n(n - 1)}{2}, 500\,000)$$$, $$$0 \leq k \leq 60$$$) — the number of servers, the number of pairs of servers directly connected by a data communication channel, and the parameter $$$k$$$, which defines the range of possible values for encryption keys. The next line contains $$$n$$$ integers $$$c_i$$$ ($$$0 \leq c_i \leq 2^k - 1$$$), the $$$i$$$-th of which is the encryption key used by the $$$i$$$-th server. The next $$$m$$$ lines contain two integers $$$u_i$$$ and $$$v_i$$$ each ($$$1 \leq u_i, v_i \leq n$$$, $$$u_i \ne v_i$$$) denoting that those servers are connected by a data communication channel. It is guaranteed that each pair of servers appears in this list at most once.
2,200
The only output line should contain a single integer — the number of safe infections of some subset of servers by a virus with some parameter, modulo $$$10^9 + 7$$$.
standard output
PASSED
760d75828dd2ef358d657601793d181b
train_003.jsonl
1536165300
The Metropolis computer network consists of $$$n$$$ servers, each has an encryption key in the range from $$$0$$$ to $$$2^k - 1$$$ assigned to it. Let $$$c_i$$$ be the encryption key assigned to the $$$i$$$-th server. Additionally, $$$m$$$ pairs of servers are directly connected via a data communication channel. Because of the encryption algorithms specifics, a data communication channel can only be considered safe if the two servers it connects have distinct encryption keys. The initial assignment of encryption keys is guaranteed to keep all data communication channels safe.You have been informed that a new virus is actively spreading across the internet, and it is capable to change the encryption key of any server it infects. More specifically, the virus body contains some unknown number $$$x$$$ in the same aforementioned range, and when server $$$i$$$ is infected, its encryption key changes from $$$c_i$$$ to $$$c_i \oplus x$$$, where $$$\oplus$$$ denotes the bitwise XOR operation.Sadly, you know neither the number $$$x$$$ nor which servers of Metropolis are going to be infected by the dangerous virus, so you have decided to count the number of such situations in which all data communication channels remain safe. Formally speaking, you need to find the number of pairs $$$(A, x)$$$, where $$$A$$$ is some (possibly empty) subset of the set of servers and $$$x$$$ is some number in the range from $$$0$$$ to $$$2^k - 1$$$, such that when all servers from the chosen subset $$$A$$$ and none of the others are infected by a virus containing the number $$$x$$$, all data communication channels remain safe. Since this number can be quite big, you are asked to find its remainder modulo $$$10^9 + 7$$$.
512 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; /** * @author Don Li */ public class NetworkSafety { int N = (int) 5e5 + 10; int MOD = (int) 1e9 + 7; int sz = 0; int[] parent = new int[N]; void solve() { int n = in.nextInt(), m = in.nextInt(), k = in.nextInt(); long[] c = new long[n]; for (int i = 0; i < n; i++) c[i] = in.nextLong(); int[] fr = new int[m], to = new int[m]; for (int i = 0; i < m; i++) { fr[i] = in.nextInt() - 1; to[i] = in.nextInt() - 1; } Map<Long, List<Integer>> x_to_edges = new HashMap<>(); for (int i = 0; i < m; i++) { int u = fr[i], v = to[i]; long x = c[u] ^ c[v]; if (!x_to_edges.containsKey(x)) { List<Integer> edges = new ArrayList<>(); edges.add(i); x_to_edges.put(x, edges); } else { List<Integer> edges = x_to_edges.get(x); edges.add(i); } } long ans = 0; Arrays.fill(parent, -1); for (long x : x_to_edges.keySet()) { sz = n; List<Integer> edges = x_to_edges.get(x); for (int i : edges) { int u = fr[i], v = to[i]; union(u, v); } ans = (ans + mpow(2, sz)) % MOD; for (int i : edges) { int u = fr[i], v = to[i]; parent[u] = -1; parent[v] = -1; } } ans = (ans + ((1L << k) - x_to_edges.size()) % MOD * mpow(2, n) % MOD) % MOD; out.println(ans); } void union(int i, int j) { int u = find(i), v = find(j); if (u == v) return; if (parent[u] > parent[v]) { int tmp = u; u = v; v = tmp; } parent[u] += parent[v]; parent[v] = u; sz--; } int find(int i) { if (parent[i] < 0) return i; return parent[i] = find(parent[i]); } long mpow(long a, long n) { long res = 1; while (n > 0) { if ((n & 1) > 0) res = res * a % MOD; a = a * a % MOD; n >>= 1; } return res; } public static void main(String[] args) { in = new FastScanner(new BufferedReader(new InputStreamReader(System.in))); out = new PrintWriter(System.out); new NetworkSafety().solve(); out.close(); } static FastScanner in; static PrintWriter out; static class FastScanner { BufferedReader in; StringTokenizer st; public FastScanner(BufferedReader in) { this.in = in; } public String nextToken() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(in.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(nextToken()); } public long nextLong() { return Long.parseLong(nextToken()); } public double nextDouble() { return Double.parseDouble(nextToken()); } } }
Java
["4 4 2\n0 1 0 1\n1 2\n2 3\n3 4\n4 1", "4 5 3\n7 1 7 2\n1 2\n2 3\n3 4\n4 1\n2 4"]
3 seconds
["50", "96"]
NoteConsider the first example.Possible values for the number $$$x$$$ contained by the virus are $$$0$$$, $$$1$$$, $$$2$$$ and $$$3$$$.For values $$$0$$$, $$$2$$$ and $$$3$$$ the virus can infect any subset of the set of servers, which gives us $$$16$$$ pairs for each values. A virus containing the number $$$1$$$ can infect either all of the servers, or none. This gives us $$$16 + 2 + 16 + 16 = 50$$$ pairs in total.
Java 8
standard input
[ "combinatorics", "dfs and similar", "graphs" ]
9319661488d33bd0b43a5ff8b238f694
The first line of input contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \leq n \leq 500\,000$$$, $$$0 \leq m \leq \min(\frac{n(n - 1)}{2}, 500\,000)$$$, $$$0 \leq k \leq 60$$$) — the number of servers, the number of pairs of servers directly connected by a data communication channel, and the parameter $$$k$$$, which defines the range of possible values for encryption keys. The next line contains $$$n$$$ integers $$$c_i$$$ ($$$0 \leq c_i \leq 2^k - 1$$$), the $$$i$$$-th of which is the encryption key used by the $$$i$$$-th server. The next $$$m$$$ lines contain two integers $$$u_i$$$ and $$$v_i$$$ each ($$$1 \leq u_i, v_i \leq n$$$, $$$u_i \ne v_i$$$) denoting that those servers are connected by a data communication channel. It is guaranteed that each pair of servers appears in this list at most once.
2,200
The only output line should contain a single integer — the number of safe infections of some subset of servers by a virus with some parameter, modulo $$$10^9 + 7$$$.
standard output
PASSED
67f46bd0dcaa474374c9555754c89187
train_003.jsonl
1536165300
The Metropolis computer network consists of $$$n$$$ servers, each has an encryption key in the range from $$$0$$$ to $$$2^k - 1$$$ assigned to it. Let $$$c_i$$$ be the encryption key assigned to the $$$i$$$-th server. Additionally, $$$m$$$ pairs of servers are directly connected via a data communication channel. Because of the encryption algorithms specifics, a data communication channel can only be considered safe if the two servers it connects have distinct encryption keys. The initial assignment of encryption keys is guaranteed to keep all data communication channels safe.You have been informed that a new virus is actively spreading across the internet, and it is capable to change the encryption key of any server it infects. More specifically, the virus body contains some unknown number $$$x$$$ in the same aforementioned range, and when server $$$i$$$ is infected, its encryption key changes from $$$c_i$$$ to $$$c_i \oplus x$$$, where $$$\oplus$$$ denotes the bitwise XOR operation.Sadly, you know neither the number $$$x$$$ nor which servers of Metropolis are going to be infected by the dangerous virus, so you have decided to count the number of such situations in which all data communication channels remain safe. Formally speaking, you need to find the number of pairs $$$(A, x)$$$, where $$$A$$$ is some (possibly empty) subset of the set of servers and $$$x$$$ is some number in the range from $$$0$$$ to $$$2^k - 1$$$, such that when all servers from the chosen subset $$$A$$$ and none of the others are infected by a virus containing the number $$$x$$$, all data communication channels remain safe. Since this number can be quite big, you are asked to find its remainder modulo $$$10^9 + 7$$$.
512 megabytes
import java.io.*; import java.util.*; import java.util.Map.Entry; public class e { static class DisjointSet { int[] s; public DisjointSet(int n) { Arrays.fill(s = new int[n], -1); } public int find(int i) { return s[i] < 0 ? i : (s[i] = find(s[i])); } public boolean union(int a, int b) { if ((a = find(a)) == (b = find(b))) return false; if(s[a] == s[b]) s[a]--; if(s[a] <= s[b]) s[b] = a; else s[a] = b; return true; } } public static void main(String[] args) { JoltyScanner in = new JoltyScanner(System.in); int n = in.nextInt(); int m = in.nextInt(); int k = in.nextInt(); long val[] = new long[n]; for(int i = 0; i < n; i++) val[i] = in.nextLong(); HashMap<Long, Stack<Integer>> adj = new HashMap<>(); for(int i = 0; i < m; i++) { int u = in.nextInt()-1; int v = in.nextInt()-1; long bad = val[u] ^ val[v]; if(!adj.containsKey(bad)) adj.put(bad, new Stack<Integer>()); adj.get(bad).add(u); adj.get(bad).add(v); } long ans = 0; int tot = adj.size(); long tp = fastPow(2, k); tp -= tot; if(tp < 0) tp += MOD; long subsets = fastPow(2, n); ans = (tp * subsets) % MOD; for(Entry<Long, Stack<Integer>> e : adj.entrySet()) { int cmp = n; HashMap<Integer, Integer> hm = new HashMap<>(); int idx =0; Stack<Integer> tmp = new Stack<>(); while(!e.getValue().isEmpty()) { if(!hm.containsKey(e.getValue().peek())) hm.put(e.getValue().peek(), idx++); tmp.add(e.getValue().pop()); } DisjointSet dsu = new DisjointSet(idx); while(!tmp.isEmpty()) { int u = hm.get(tmp.pop()); int v = hm.get(tmp.pop()); if(dsu.find(u) != dsu.find(v)) { cmp--; dsu.union(u, v); } } ans += fastPow(2, cmp); ans %= MOD; } System.out.println(ans); } static long fastPow(long v, long e) { if(e == 0) return 1; if(e % 2 == 0) { long temp = fastPow(v, e/2); return (temp * temp) % MOD; } return (v * fastPow(v, e-1)) % MOD; } static long MOD = (long) 1e9 + 7; static class JoltyScanner { public static final int BUFFER_SIZE = 1 << 16; public static final char NULL_CHAR = (char) -1; byte[] buffer = new byte[BUFFER_SIZE]; boolean EOF_FLAG = false; int bufferIdx = 0, size = 0; char c = NULL_CHAR; BufferedInputStream in; public JoltyScanner(InputStream in) { this.in = new BufferedInputStream(in, BUFFER_SIZE); } public int nextInt() { long x = nextLong(); if (x > Integer.MAX_VALUE || x < Integer.MIN_VALUE) { throw new ArithmeticException("Scanned value overflows integer"); } return (int) x; } public long nextLong() { boolean negative = false; if (c == NULL_CHAR) { c = nextChar(); } for (; !EOF_FLAG && (c < '0' || c > '9'); c = nextChar()) { if (c == '-') { negative = true; } } checkEOF(); long res = 0; for (; c >= '0' && c <= '9'; c = nextChar()) { res = (res << 3) + (res << 1) + c - '0'; } return negative ? -res : res; } public char nextChar() { if (EOF_FLAG) { return NULL_CHAR; } while (bufferIdx == size) { try { size = in.read(buffer); if (size == -1) { throw new Exception(); } } catch (Exception e) { EOF_FLAG = true; return NULL_CHAR; } if (size == -1) { size = BUFFER_SIZE; } bufferIdx = 0; } return (char) buffer[bufferIdx++]; } public void checkEOF() { if (EOF_FLAG) { throw new EndOfFileException(); } } public class EndOfFileException extends RuntimeException { } } }
Java
["4 4 2\n0 1 0 1\n1 2\n2 3\n3 4\n4 1", "4 5 3\n7 1 7 2\n1 2\n2 3\n3 4\n4 1\n2 4"]
3 seconds
["50", "96"]
NoteConsider the first example.Possible values for the number $$$x$$$ contained by the virus are $$$0$$$, $$$1$$$, $$$2$$$ and $$$3$$$.For values $$$0$$$, $$$2$$$ and $$$3$$$ the virus can infect any subset of the set of servers, which gives us $$$16$$$ pairs for each values. A virus containing the number $$$1$$$ can infect either all of the servers, or none. This gives us $$$16 + 2 + 16 + 16 = 50$$$ pairs in total.
Java 8
standard input
[ "combinatorics", "dfs and similar", "graphs" ]
9319661488d33bd0b43a5ff8b238f694
The first line of input contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \leq n \leq 500\,000$$$, $$$0 \leq m \leq \min(\frac{n(n - 1)}{2}, 500\,000)$$$, $$$0 \leq k \leq 60$$$) — the number of servers, the number of pairs of servers directly connected by a data communication channel, and the parameter $$$k$$$, which defines the range of possible values for encryption keys. The next line contains $$$n$$$ integers $$$c_i$$$ ($$$0 \leq c_i \leq 2^k - 1$$$), the $$$i$$$-th of which is the encryption key used by the $$$i$$$-th server. The next $$$m$$$ lines contain two integers $$$u_i$$$ and $$$v_i$$$ each ($$$1 \leq u_i, v_i \leq n$$$, $$$u_i \ne v_i$$$) denoting that those servers are connected by a data communication channel. It is guaranteed that each pair of servers appears in this list at most once.
2,200
The only output line should contain a single integer — the number of safe infections of some subset of servers by a virus with some parameter, modulo $$$10^9 + 7$$$.
standard output
PASSED
7e3ea4ee033aea0fc2bd955bad4e4a94
train_003.jsonl
1536165300
The Metropolis computer network consists of $$$n$$$ servers, each has an encryption key in the range from $$$0$$$ to $$$2^k - 1$$$ assigned to it. Let $$$c_i$$$ be the encryption key assigned to the $$$i$$$-th server. Additionally, $$$m$$$ pairs of servers are directly connected via a data communication channel. Because of the encryption algorithms specifics, a data communication channel can only be considered safe if the two servers it connects have distinct encryption keys. The initial assignment of encryption keys is guaranteed to keep all data communication channels safe.You have been informed that a new virus is actively spreading across the internet, and it is capable to change the encryption key of any server it infects. More specifically, the virus body contains some unknown number $$$x$$$ in the same aforementioned range, and when server $$$i$$$ is infected, its encryption key changes from $$$c_i$$$ to $$$c_i \oplus x$$$, where $$$\oplus$$$ denotes the bitwise XOR operation.Sadly, you know neither the number $$$x$$$ nor which servers of Metropolis are going to be infected by the dangerous virus, so you have decided to count the number of such situations in which all data communication channels remain safe. Formally speaking, you need to find the number of pairs $$$(A, x)$$$, where $$$A$$$ is some (possibly empty) subset of the set of servers and $$$x$$$ is some number in the range from $$$0$$$ to $$$2^k - 1$$$, such that when all servers from the chosen subset $$$A$$$ and none of the others are infected by a virus containing the number $$$x$$$, all data communication channels remain safe. Since this number can be quite big, you are asked to find its remainder modulo $$$10^9 + 7$$$.
512 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.util.Comparator; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Vadim Semenov */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskE solver = new TaskE(); solver.solve(1, in, out); out.close(); } static final class TaskE { private static final int MODULO = 1000_000_000 + 7; public void solve(int __, InputReader in, PrintWriter out) { int vertices = in.nextInt(); int edges = in.nextInt(); int power = in.nextInt(); long[] key = in.nextLongArray(vertices); int[][] edgeList = in.nextIntTable(edges, 2); long[] xor = new long[edges]; Integer[] order = new Integer[edges]; for (int e = 0; e < edges; ++e) { order[e] = e; for (int i = 0; i < 2; ++i) { xor[e] ^= key[--edgeList[e][i]]; } } Arrays.sort(order, Comparator.comparingLong(e -> xor[e])); TaskE.DSU dsu = new TaskE.DSU(vertices); long answer = 0; long numbers = 1L << power; for (int i = 0; i < edges; ) { numbers--; int j = i + 1; while (j < edges && xor[order[i]] == xor[order[j]]) { ++j; } dsu.clear(); int components = vertices; for (int k = i; k < j; ++k) { int e = order[k]; if (dsu.unite(edgeList[e][0], edgeList[e][1])) { --components; } } answer += power(2, components); answer %= MODULO; i = j; } answer += power(2, vertices) * (numbers % MODULO); answer %= MODULO; if (answer < 0) { answer += MODULO; } out.println(answer); } private long power(long base, long power) { long result = 1; while (power > 0) { if ((power & 1) == 1) { result = result * base % MODULO; } base = base * base % MODULO; power >>>= 1; } return result; } private static class DSU { final int[] parents; final int[] time; final int[] rang; int TIME = 1; DSU(int capacity) { parents = new int[capacity]; time = new int[capacity]; rang = new int[capacity]; } boolean unite(int u, int v) { u = get(u); v = get(v); if (u == v) return false; if (rang[u] < rang[v]) { int tmp = u; u = v; v = tmp; } parents[v] = u; if (rang[u] == rang[v]) { rang[u]++; } return true; } int get(int v) { if (TIME != time[v]) { time[v] = TIME; parents[v] = v; rang[v] = 0; } return parents[v] == v ? v : get(parents[v]); } void clear() { TIME++; } } } static class InputReader { private final BufferedReader reader; private StringTokenizer tokenizer; public InputReader(InputStream in) { reader = new BufferedReader(new InputStreamReader(in)); } public long[] nextLongArray(int size) { long[] array = new long[size]; for (int i = 0; i < size; ++i) { array[i] = nextLong(); } return array; } public int[][] nextIntTable(int rows, int columns) { int[][] table = new int[rows][columns]; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { table[i][j] = nextInt(); } } return table; } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(readLine()); } return tokenizer.nextToken(); } public String readLine() { String line; try { line = reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } return line; } } }
Java
["4 4 2\n0 1 0 1\n1 2\n2 3\n3 4\n4 1", "4 5 3\n7 1 7 2\n1 2\n2 3\n3 4\n4 1\n2 4"]
3 seconds
["50", "96"]
NoteConsider the first example.Possible values for the number $$$x$$$ contained by the virus are $$$0$$$, $$$1$$$, $$$2$$$ and $$$3$$$.For values $$$0$$$, $$$2$$$ and $$$3$$$ the virus can infect any subset of the set of servers, which gives us $$$16$$$ pairs for each values. A virus containing the number $$$1$$$ can infect either all of the servers, or none. This gives us $$$16 + 2 + 16 + 16 = 50$$$ pairs in total.
Java 8
standard input
[ "combinatorics", "dfs and similar", "graphs" ]
9319661488d33bd0b43a5ff8b238f694
The first line of input contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \leq n \leq 500\,000$$$, $$$0 \leq m \leq \min(\frac{n(n - 1)}{2}, 500\,000)$$$, $$$0 \leq k \leq 60$$$) — the number of servers, the number of pairs of servers directly connected by a data communication channel, and the parameter $$$k$$$, which defines the range of possible values for encryption keys. The next line contains $$$n$$$ integers $$$c_i$$$ ($$$0 \leq c_i \leq 2^k - 1$$$), the $$$i$$$-th of which is the encryption key used by the $$$i$$$-th server. The next $$$m$$$ lines contain two integers $$$u_i$$$ and $$$v_i$$$ each ($$$1 \leq u_i, v_i \leq n$$$, $$$u_i \ne v_i$$$) denoting that those servers are connected by a data communication channel. It is guaranteed that each pair of servers appears in this list at most once.
2,200
The only output line should contain a single integer — the number of safe infections of some subset of servers by a virus with some parameter, modulo $$$10^9 + 7$$$.
standard output
PASSED
a024f222025f3dd25c363899e4b63eb1
train_003.jsonl
1536165300
The Metropolis computer network consists of $$$n$$$ servers, each has an encryption key in the range from $$$0$$$ to $$$2^k - 1$$$ assigned to it. Let $$$c_i$$$ be the encryption key assigned to the $$$i$$$-th server. Additionally, $$$m$$$ pairs of servers are directly connected via a data communication channel. Because of the encryption algorithms specifics, a data communication channel can only be considered safe if the two servers it connects have distinct encryption keys. The initial assignment of encryption keys is guaranteed to keep all data communication channels safe.You have been informed that a new virus is actively spreading across the internet, and it is capable to change the encryption key of any server it infects. More specifically, the virus body contains some unknown number $$$x$$$ in the same aforementioned range, and when server $$$i$$$ is infected, its encryption key changes from $$$c_i$$$ to $$$c_i \oplus x$$$, where $$$\oplus$$$ denotes the bitwise XOR operation.Sadly, you know neither the number $$$x$$$ nor which servers of Metropolis are going to be infected by the dangerous virus, so you have decided to count the number of such situations in which all data communication channels remain safe. Formally speaking, you need to find the number of pairs $$$(A, x)$$$, where $$$A$$$ is some (possibly empty) subset of the set of servers and $$$x$$$ is some number in the range from $$$0$$$ to $$$2^k - 1$$$, such that when all servers from the chosen subset $$$A$$$ and none of the others are infected by a virus containing the number $$$x$$$, all data communication channels remain safe. Since this number can be quite big, you are asked to find its remainder modulo $$$10^9 + 7$$$.
512 megabytes
import java.util.*; import java.io.*; public class Main { static long mod = 1000000007; static HashMap<Long, ArrayList<Pair>> map = new HashMap<>(); public static void main(String[] args) { FastReader reader = new FastReader(); PrintWriter writer = new PrintWriter(System.out); int n = reader.nextInt(); int m = reader.nextInt(); int k = reader.nextInt(); Dsu set = new Dsu(n); long[] key = new long[n]; for (int i=0; i<n; i++) key[i] = reader.nextLong(); for (int i=0; i<m; i++) { int u = reader.nextInt()-1; int v = reader.nextInt()-1; long temp = key[u]^key[v]; if (!map.containsKey(temp)) map.put(temp, new ArrayList<Pair>()); ArrayList<Pair> got = map.get(temp); got.add(new Pair(u, v)); map.put(temp, got); } long ans = (1L<<k) - map.size(); ans %= mod; ans *= pow(2, n); ans %= mod; for (Map.Entry<Long, ArrayList<Pair>> entry : map.entrySet()) { int count = 0; ArrayList<Pair> temp = entry.getValue(); for (Pair p : temp) count += set.union(p.a, p.b); ans += pow(2, n-count); set.refresh(temp); } ans %= mod; writer.print(ans); writer.close(); } static long pow(long a, long p) { if (p==0) return 1L; else { long got = pow(a, p/2); got *= got; got %= mod; if (p%2 == 1) got *= a; return got%mod; } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } } class Dsu { int[] parent; int[] size; Dsu(int n) { parent = new int[n]; size = new int[n]; for (int i=0; i<n; i++) { parent[i] = i; size[i] = 1; } } int findRoot(int u) { while (u != parent[u]) { parent[u] = parent[parent[u]]; u = parent[u]; } return u; } int union (int u, int v) { int pu = findRoot(u); int pv = findRoot(v); if (pu == pv) return 0; else { if (size[u] > size[v]) { int temp = u; u = v; v = temp; } parent[pu] = parent[pv]; size[pv] += size[pu]; return 1; } } void refresh(ArrayList<Pair> list) { for (Pair p : list) { size[p.a] = 1; size[p.b] = 1; parent[p.a] = p.a; parent[p.b] = p.b; } } } class Pair { int a; int b; Pair(int a, int b) { this.a = a; this.b = b; } }
Java
["4 4 2\n0 1 0 1\n1 2\n2 3\n3 4\n4 1", "4 5 3\n7 1 7 2\n1 2\n2 3\n3 4\n4 1\n2 4"]
3 seconds
["50", "96"]
NoteConsider the first example.Possible values for the number $$$x$$$ contained by the virus are $$$0$$$, $$$1$$$, $$$2$$$ and $$$3$$$.For values $$$0$$$, $$$2$$$ and $$$3$$$ the virus can infect any subset of the set of servers, which gives us $$$16$$$ pairs for each values. A virus containing the number $$$1$$$ can infect either all of the servers, or none. This gives us $$$16 + 2 + 16 + 16 = 50$$$ pairs in total.
Java 8
standard input
[ "combinatorics", "dfs and similar", "graphs" ]
9319661488d33bd0b43a5ff8b238f694
The first line of input contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \leq n \leq 500\,000$$$, $$$0 \leq m \leq \min(\frac{n(n - 1)}{2}, 500\,000)$$$, $$$0 \leq k \leq 60$$$) — the number of servers, the number of pairs of servers directly connected by a data communication channel, and the parameter $$$k$$$, which defines the range of possible values for encryption keys. The next line contains $$$n$$$ integers $$$c_i$$$ ($$$0 \leq c_i \leq 2^k - 1$$$), the $$$i$$$-th of which is the encryption key used by the $$$i$$$-th server. The next $$$m$$$ lines contain two integers $$$u_i$$$ and $$$v_i$$$ each ($$$1 \leq u_i, v_i \leq n$$$, $$$u_i \ne v_i$$$) denoting that those servers are connected by a data communication channel. It is guaranteed that each pair of servers appears in this list at most once.
2,200
The only output line should contain a single integer — the number of safe infections of some subset of servers by a virus with some parameter, modulo $$$10^9 + 7$$$.
standard output
PASSED
30b5b6567f92f84c1c2b85caa2badc9f
train_003.jsonl
1536165300
The Metropolis computer network consists of $$$n$$$ servers, each has an encryption key in the range from $$$0$$$ to $$$2^k - 1$$$ assigned to it. Let $$$c_i$$$ be the encryption key assigned to the $$$i$$$-th server. Additionally, $$$m$$$ pairs of servers are directly connected via a data communication channel. Because of the encryption algorithms specifics, a data communication channel can only be considered safe if the two servers it connects have distinct encryption keys. The initial assignment of encryption keys is guaranteed to keep all data communication channels safe.You have been informed that a new virus is actively spreading across the internet, and it is capable to change the encryption key of any server it infects. More specifically, the virus body contains some unknown number $$$x$$$ in the same aforementioned range, and when server $$$i$$$ is infected, its encryption key changes from $$$c_i$$$ to $$$c_i \oplus x$$$, where $$$\oplus$$$ denotes the bitwise XOR operation.Sadly, you know neither the number $$$x$$$ nor which servers of Metropolis are going to be infected by the dangerous virus, so you have decided to count the number of such situations in which all data communication channels remain safe. Formally speaking, you need to find the number of pairs $$$(A, x)$$$, where $$$A$$$ is some (possibly empty) subset of the set of servers and $$$x$$$ is some number in the range from $$$0$$$ to $$$2^k - 1$$$, such that when all servers from the chosen subset $$$A$$$ and none of the others are infected by a virus containing the number $$$x$$$, all data communication channels remain safe. Since this number can be quite big, you are asked to find its remainder modulo $$$10^9 + 7$$$.
512 megabytes
import java.io.BufferedReader; // import java.io.FileInputStream; // import java.io.FileOutputStream; import java.io.InputStream; import java.io.InputStreamReader; import java.io.IOException; import java.io.PrintWriter; import java.math.BigInteger; import java.util.Arrays; import java.util.ArrayList; import java.util.PriorityQueue; import java.util.Random; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.TreeSet; import static java.lang.Math.abs; import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.round; import static java.lang.Math.sqrt; import static java.util.Arrays.copyOf; import static java.util.Arrays.fill; import static java.util.Arrays.sort; import static java.util.Collections.reverse; import static java.util.Collections.reverseOrder; import static java.util.Collections.sort; import static java.util.Comparator.comparing; import static java.util.Comparator.comparingInt; import static java.util.Comparator.comparingLong; public class Main { FastScanner in; PrintWriter out; int[] parent; long[] value; Random random = new Random(); void dsuInit(int n) { parent = new int[n]; value = new long[n]; for (int i = 0; i < n; i++) parent[i] = i; } int dsuGet(int v) { return v == parent[v] ? v : (parent[v] = dsuGet(parent[v])); } boolean dsuUnite(int a, int b, long v) { if (value[a] != v) { value[a] = v; parent[a] = a; } else a = dsuGet(a); if (value[b] != v) { value[b] = v; parent[b] = b; } else b = dsuGet(b); if (a != b) if (random.nextBoolean()) parent[a] = b; else parent[b] = a; return a != b; } private void solve() throws IOException { int n = in.nextInt(), m = in.nextInt(), k = in.nextInt(); long[] c = new long[n]; for (int i = 0; i < n; i++) c[i] = in.nextLong(); int[][] e = new int[m][2]; for (int i = 0; i < m; i++) for (int j = 0; j < 2; j++) e[i][j] = in.nextInt() - 1; long mod = (long) 1e9 + 7; long[] pow = new long[max(n + 1, 61)]; pow[0] = 1; for (int i = 1; i < max(n + 1, 61); i++) pow[i] = pow[i - 1] * 2 % mod; sort(e, comparingLong(o -> c[o[0]] ^ c[o[1]])); dsuInit(n); int cnt = 0, cmp; long ans = 0; for (int l = 0, r = 0; l < m; l = r) { cmp = n; while (r < m && (c[e[l][0]] ^ c[e[l][1]]) == (c[e[r][0]] ^ c[e[r][1]])) { if (dsuUnite(e[r][0], e[r][1], c[e[r][0]] ^ c[e[r][1]])) cmp--; r++; } ans += pow[cmp]; ans %= mod; cnt++; } ans += (pow[k] + mod - cnt) * pow[n] % mod; out.println(ans % mod); } class FastScanner { StringTokenizer st; BufferedReader br; FastScanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } boolean hasNext() throws IOException { return br.ready() || (st != null && st.hasMoreTokens()); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } String nextLine() throws IOException { return br.readLine(); } boolean hasNextLine() throws IOException { return br.ready(); } } private void run() throws IOException { in = new FastScanner(System.in); // new FastScanner(new FileInputStream(".in")); out = new PrintWriter(System.out); // new PrintWriter(new FileOutputStream(".out")); solve(); out.flush(); out.close(); } public static void main(String[] args) throws IOException { new Main().run(); } }
Java
["4 4 2\n0 1 0 1\n1 2\n2 3\n3 4\n4 1", "4 5 3\n7 1 7 2\n1 2\n2 3\n3 4\n4 1\n2 4"]
3 seconds
["50", "96"]
NoteConsider the first example.Possible values for the number $$$x$$$ contained by the virus are $$$0$$$, $$$1$$$, $$$2$$$ and $$$3$$$.For values $$$0$$$, $$$2$$$ and $$$3$$$ the virus can infect any subset of the set of servers, which gives us $$$16$$$ pairs for each values. A virus containing the number $$$1$$$ can infect either all of the servers, or none. This gives us $$$16 + 2 + 16 + 16 = 50$$$ pairs in total.
Java 8
standard input
[ "combinatorics", "dfs and similar", "graphs" ]
9319661488d33bd0b43a5ff8b238f694
The first line of input contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \leq n \leq 500\,000$$$, $$$0 \leq m \leq \min(\frac{n(n - 1)}{2}, 500\,000)$$$, $$$0 \leq k \leq 60$$$) — the number of servers, the number of pairs of servers directly connected by a data communication channel, and the parameter $$$k$$$, which defines the range of possible values for encryption keys. The next line contains $$$n$$$ integers $$$c_i$$$ ($$$0 \leq c_i \leq 2^k - 1$$$), the $$$i$$$-th of which is the encryption key used by the $$$i$$$-th server. The next $$$m$$$ lines contain two integers $$$u_i$$$ and $$$v_i$$$ each ($$$1 \leq u_i, v_i \leq n$$$, $$$u_i \ne v_i$$$) denoting that those servers are connected by a data communication channel. It is guaranteed that each pair of servers appears in this list at most once.
2,200
The only output line should contain a single integer — the number of safe infections of some subset of servers by a virus with some parameter, modulo $$$10^9 + 7$$$.
standard output
PASSED
bb4a3dffbefa356089413fbb14114397
train_003.jsonl
1536165300
The Metropolis computer network consists of $$$n$$$ servers, each has an encryption key in the range from $$$0$$$ to $$$2^k - 1$$$ assigned to it. Let $$$c_i$$$ be the encryption key assigned to the $$$i$$$-th server. Additionally, $$$m$$$ pairs of servers are directly connected via a data communication channel. Because of the encryption algorithms specifics, a data communication channel can only be considered safe if the two servers it connects have distinct encryption keys. The initial assignment of encryption keys is guaranteed to keep all data communication channels safe.You have been informed that a new virus is actively spreading across the internet, and it is capable to change the encryption key of any server it infects. More specifically, the virus body contains some unknown number $$$x$$$ in the same aforementioned range, and when server $$$i$$$ is infected, its encryption key changes from $$$c_i$$$ to $$$c_i \oplus x$$$, where $$$\oplus$$$ denotes the bitwise XOR operation.Sadly, you know neither the number $$$x$$$ nor which servers of Metropolis are going to be infected by the dangerous virus, so you have decided to count the number of such situations in which all data communication channels remain safe. Formally speaking, you need to find the number of pairs $$$(A, x)$$$, where $$$A$$$ is some (possibly empty) subset of the set of servers and $$$x$$$ is some number in the range from $$$0$$$ to $$$2^k - 1$$$, such that when all servers from the chosen subset $$$A$$$ and none of the others are infected by a virus containing the number $$$x$$$, all data communication channels remain safe. Since this number can be quite big, you are asked to find its remainder modulo $$$10^9 + 7$$$.
512 megabytes
import java.util.*; import java.lang.*; import java.math.*; import java.io.*; import static java.lang.Math.*; /* spar5h */ public class cf3 implements Runnable{ static class pair { int i, j; pair(int i, int j) { this.i = i; this.j = j; } } public void run() { InputReader s = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); int n = s.nextInt(), m = s.nextInt(), k = s.nextInt(); long[] c = new long[n + 1]; for(int i = 1; i <= n; i++) c[i] = s.nextLong(); int mapCount = 0; HashMap<Long, Integer> hm = new HashMap<Long, Integer>(); ArrayList<pair>[] edge = new ArrayList[m]; for(int i = 0; i < m; i++) { int u = s.nextInt(), v = s.nextInt(); if(hm.get(c[u] ^ c[v]) == null) { hm.put(c[u] ^ c[v], mapCount); edge[mapCount] = new ArrayList<pair>(); mapCount++; } edge[hm.get(c[u] ^ c[v])].add(new pair(u, v)); } long mod = (long)1e9 + 7, res = 0; long[] pow2 = new long[1000000 + 1]; pow2[0] = 1; for(int i = 1; i <= 1000000; i++) pow2[i] = (pow2[i - 1] * 2) % mod; ArrayList<Integer>[] adj = new ArrayList[n + 1]; int[] vis = new int[n + 1]; Queue<Integer> q = new LinkedList<Integer>(); for(int i = 0; i < mapCount; i++) { HashSet<Integer> hs = new HashSet<Integer>(); for(int j = 0; j < edge[i].size(); j++) { hs.add(edge[i].get(j).i); hs.add(edge[i].get(j).j); } for(int j : hs) { adj[j] = new ArrayList<Integer>(); vis[j] = 0; } for(int j = 0; j < edge[i].size(); j++) { int u = edge[i].get(j).i, v = edge[i].get(j).j; adj[u].add(v); adj[v].add(u); } long val = 1; int tot = 0; for(int j : hs) { if(vis[j] == 1) continue; q.add(j); vis[j] = 1; while(!q.isEmpty()) { int x = q.poll(); tot++; for(int l = 0; l < adj[x].size(); l++) { int y = adj[x].get(l); if(vis[y] == 0) { q.add(y); vis[y] = 1; } } } val = (val * 2) % mod; } val = (val * pow2[n - tot]) % mod; res = (res + val) % mod; } res = (res + pow2[n] * ((pow2[k] - hm.size()) % mod) % mod) % mod; w.println(res); w.close(); } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars==-1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if(numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int nextInt() { int c = read(); while(isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if(c<'0'||c>'9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } public static void main(String args[]) throws Exception { new Thread(null, new cf3(),"cf3",1<<26).start(); } }
Java
["4 4 2\n0 1 0 1\n1 2\n2 3\n3 4\n4 1", "4 5 3\n7 1 7 2\n1 2\n2 3\n3 4\n4 1\n2 4"]
3 seconds
["50", "96"]
NoteConsider the first example.Possible values for the number $$$x$$$ contained by the virus are $$$0$$$, $$$1$$$, $$$2$$$ and $$$3$$$.For values $$$0$$$, $$$2$$$ and $$$3$$$ the virus can infect any subset of the set of servers, which gives us $$$16$$$ pairs for each values. A virus containing the number $$$1$$$ can infect either all of the servers, or none. This gives us $$$16 + 2 + 16 + 16 = 50$$$ pairs in total.
Java 8
standard input
[ "combinatorics", "dfs and similar", "graphs" ]
9319661488d33bd0b43a5ff8b238f694
The first line of input contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \leq n \leq 500\,000$$$, $$$0 \leq m \leq \min(\frac{n(n - 1)}{2}, 500\,000)$$$, $$$0 \leq k \leq 60$$$) — the number of servers, the number of pairs of servers directly connected by a data communication channel, and the parameter $$$k$$$, which defines the range of possible values for encryption keys. The next line contains $$$n$$$ integers $$$c_i$$$ ($$$0 \leq c_i \leq 2^k - 1$$$), the $$$i$$$-th of which is the encryption key used by the $$$i$$$-th server. The next $$$m$$$ lines contain two integers $$$u_i$$$ and $$$v_i$$$ each ($$$1 \leq u_i, v_i \leq n$$$, $$$u_i \ne v_i$$$) denoting that those servers are connected by a data communication channel. It is guaranteed that each pair of servers appears in this list at most once.
2,200
The only output line should contain a single integer — the number of safe infections of some subset of servers by a virus with some parameter, modulo $$$10^9 + 7$$$.
standard output
PASSED
c7dd8fd317aae852bff2b53c89804f77
train_003.jsonl
1536165300
The Metropolis computer network consists of $$$n$$$ servers, each has an encryption key in the range from $$$0$$$ to $$$2^k - 1$$$ assigned to it. Let $$$c_i$$$ be the encryption key assigned to the $$$i$$$-th server. Additionally, $$$m$$$ pairs of servers are directly connected via a data communication channel. Because of the encryption algorithms specifics, a data communication channel can only be considered safe if the two servers it connects have distinct encryption keys. The initial assignment of encryption keys is guaranteed to keep all data communication channels safe.You have been informed that a new virus is actively spreading across the internet, and it is capable to change the encryption key of any server it infects. More specifically, the virus body contains some unknown number $$$x$$$ in the same aforementioned range, and when server $$$i$$$ is infected, its encryption key changes from $$$c_i$$$ to $$$c_i \oplus x$$$, where $$$\oplus$$$ denotes the bitwise XOR operation.Sadly, you know neither the number $$$x$$$ nor which servers of Metropolis are going to be infected by the dangerous virus, so you have decided to count the number of such situations in which all data communication channels remain safe. Formally speaking, you need to find the number of pairs $$$(A, x)$$$, where $$$A$$$ is some (possibly empty) subset of the set of servers and $$$x$$$ is some number in the range from $$$0$$$ to $$$2^k - 1$$$, such that when all servers from the chosen subset $$$A$$$ and none of the others are infected by a virus containing the number $$$x$$$, all data communication channels remain safe. Since this number can be quite big, you are asked to find its remainder modulo $$$10^9 + 7$$$.
512 megabytes
import java.lang.*; import java.lang.reflect.Array; import java.math.*; import java.util.*; import java.io.*; public class Main { class Node { int id; int x; public Node(int id,int x){ this.id=id; this.x=x; } } void solve() { int n=ni(),m=ni(),k=ni(); int from[]=new int[m+1]; int to[]=new int[m+1]; int sz[]=new int[n+1]; g=new Node[n+1][]; c=new long[n+1]; for(int i=1;i<=n;i++) c[i]=nl(); for(int i=1;i<=m;i++){ int x=ni(),y=ni(); from[i]=x; to[i]=y; sz[x]++; sz[y]++; } for(int i=1;i<=n;i++) g[i]=new Node[sz[i]]; for(int i=1;i<=m;i++){ int x=from[i],y=to[i]; g[x][--sz[x]]=new Node(i,y); g[y][--sz[y]]=new Node(i,x); } vis=new boolean[m+1]; for(int i=1;i<=m;i++){ if(vis[i]) continue; int x=from[i],y=to[i]; hs.clear(); long xr=c[x]^c[y]; dfs(x,xr); int cc=hs.size(); mp.merge(xr,cc,Integer::sum); mp2.merge(xr,1,Integer::sum); } long ans=0; for(Map.Entry<Long,Integer> entry : mp.entrySet()){ long xr=entry.getKey(); long cnt=entry.getValue(); long cc=mp2.get(xr); ans=add(ans,modpow(2,cc+n-cnt,M),M); } ans=add(ans,mul(modpow(2,n,M),sub(modpow(2,k,M),mp.size(),M),M),M); pw.println(ans); } Node g[][]; long c[]; boolean vis[]; HashSet<Integer> hs=new HashSet<>(); HashMap<Long,Integer> mp=new HashMap<>(); HashMap<Long,Integer> mp2=new HashMap<>(); void dfs(int v,long xr){ hs.add(v); for(Node p : g[v]){ int u=p.x; if(!vis[p.id] && (c[v]^c[u])==xr){ vis[p.id]=true; dfs(u,xr); } } } long add(long x,long y,long M){ x+=y; if(x>=M) x-=M; return x; } long sub(long x,long y,long M){ x-=y; if(x<0) x+=M; return x; } long mul(long x,long y,long M){ x*=y; if(x>=M) x%=M; return x; } long modpow(long a, long b,long M) { long r=1; while(b>0) { if((b&1)>0) r=mul(r,a,M); a=mul(a,a,M); b>>=1; } return r; } long modInverse(long A, long M) { return modpow(A,M-2,M); } long M=(long)1e9+7; InputStream is; PrintWriter pw; String INPUT = ""; void run() throws Exception { is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes()); pw = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); pw.flush(); if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms"); } public static void main(String[] args) throws Exception { new Main().run(); } private byte[] inbuf = new byte[1024]; public int lenbuf = 0, ptrbuf = 0; private int readByte() { if(lenbuf == -1)throw new InputMismatchException(); if(ptrbuf >= lenbuf){ ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if(lenbuf <= 0)return -1; } return inbuf[ptrbuf++]; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; } private double nd() { return Double.parseDouble(ns()); } private char nc() { return (char)skip(); } private String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while(p < n && !(isSpaceChar(b))){ buf[p++] = (char)b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private char[][] nm(int n, int m) { char[][] map = new char[n][]; for(int i = 0;i < n;i++)map[i] = ns(m); return map; } private int[] na(int n) { int[] a = new int[n]; for(int i = 0;i < n;i++)a[i] = ni(); return a; } private int ni() { int num = 0, b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private long nl() { long num = 0; int b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private boolean oj = System.getProperty("ONLINE_JUDGE") != null; private void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); } }
Java
["4 4 2\n0 1 0 1\n1 2\n2 3\n3 4\n4 1", "4 5 3\n7 1 7 2\n1 2\n2 3\n3 4\n4 1\n2 4"]
3 seconds
["50", "96"]
NoteConsider the first example.Possible values for the number $$$x$$$ contained by the virus are $$$0$$$, $$$1$$$, $$$2$$$ and $$$3$$$.For values $$$0$$$, $$$2$$$ and $$$3$$$ the virus can infect any subset of the set of servers, which gives us $$$16$$$ pairs for each values. A virus containing the number $$$1$$$ can infect either all of the servers, or none. This gives us $$$16 + 2 + 16 + 16 = 50$$$ pairs in total.
Java 8
standard input
[ "combinatorics", "dfs and similar", "graphs" ]
9319661488d33bd0b43a5ff8b238f694
The first line of input contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \leq n \leq 500\,000$$$, $$$0 \leq m \leq \min(\frac{n(n - 1)}{2}, 500\,000)$$$, $$$0 \leq k \leq 60$$$) — the number of servers, the number of pairs of servers directly connected by a data communication channel, and the parameter $$$k$$$, which defines the range of possible values for encryption keys. The next line contains $$$n$$$ integers $$$c_i$$$ ($$$0 \leq c_i \leq 2^k - 1$$$), the $$$i$$$-th of which is the encryption key used by the $$$i$$$-th server. The next $$$m$$$ lines contain two integers $$$u_i$$$ and $$$v_i$$$ each ($$$1 \leq u_i, v_i \leq n$$$, $$$u_i \ne v_i$$$) denoting that those servers are connected by a data communication channel. It is guaranteed that each pair of servers appears in this list at most once.
2,200
The only output line should contain a single integer — the number of safe infections of some subset of servers by a virus with some parameter, modulo $$$10^9 + 7$$$.
standard output
PASSED
ba692268d99672a2b3fc15945008363d
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 them throughout the years. Unfortunately, when paying something in bitcoin everyone can see how many bitcoins you have in your public address wallet. This worried Alice, so she decided to split her bitcoins among multiple different addresses, so that every address has at most $$$x$$$ satoshi (1 bitcoin = $$$10^8$$$ satoshi). She can create new public address wallets for free and is willing to pay $$$f$$$ fee in satoshi per transaction to ensure acceptable speed of transfer. The fee is deducted from the address the transaction was sent from. Tell Alice how much total fee in satoshi she will need to pay to achieve her goal.
256 megabytes
import java.io.*; import java.util.*; public class Main { private Reader r; private StreamTokenizer tk; public Main() { r = new BufferedReader(new InputStreamReader(System.in)); tk = new StreamTokenizer(r); } public void exit() throws IOException { r.close(); } public String readLine() throws IOException { tk.nextToken(); return tk.sval; } public int nextInt() throws IOException { tk.nextToken(); return (int) tk.nval; } public long nextLong() throws IOException { tk.nextToken(); return (long) tk.nval; } public void run() throws IOException { int n = nextInt(); LinkedList<Long> l = new LinkedList<>(); for(int i = 0; i < n; i++) { l.add(nextLong()); } long maxValue = nextInt(); long cost = nextInt(); l.sort((o1, o2) -> -Long.compare(o1, o2)); long result = 0; while(l.peekFirst() != null) { long current = l.pollFirst(); long canRetrieve = current / (maxValue + cost); long rest = (current - canRetrieve * (maxValue + cost)); long canRetrieveAnother = rest / maxValue; result += cost * canRetrieve; if (rest > maxValue) { result += cost * canRetrieveAnother; } } System.out.println(result); } public static void main(String[] args) throws IOException { Main main = new Main(); main.run(); main.exit(); } }
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 two numbers $$$x$$$, $$$f$$$ ($$$1 \leq f &lt; x \leq 10^9$$$) representing maximum number of satoshies Alice can have in one address, as well as fee in satoshies she is willing to pay per transaction.
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
ae90005c3df70c26eb2f001a3021ff0a
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 them throughout the years. Unfortunately, when paying something in bitcoin everyone can see how many bitcoins you have in your public address wallet. This worried Alice, so she decided to split her bitcoins among multiple different addresses, so that every address has at most $$$x$$$ satoshi (1 bitcoin = $$$10^8$$$ satoshi). She can create new public address wallets for free and is willing to pay $$$f$$$ fee in satoshi per transaction to ensure acceptable speed of transfer. The fee is deducted from the address the transaction was sent from. Tell Alice how much total fee in satoshi she will need to pay to achieve her goal.
256 megabytes
//package math_codet; import java.io.*; import java.util.*; /****************************************** * AUTHOR: AMAN KUMAR SINGH * * INSTITUITION: KALYANI GOVERNMENT ENGINEERING COLLEGE * ******************************************/ public class lets_do { InputReader in; PrintWriter out; Helper_class h; final long mod=1000000007; public static void main(String[] args) throws java.lang.Exception{ new lets_do().run(); } void run() throws Exception{ in=new InputReader(); out = new PrintWriter(System.out); h = new Helper_class(); int t = 1; while(t-->0) solve(); out.flush(); out.close(); } void solve(){ int n = h.ni(); long[] arr = new long[n]; int i = 0; for(i = 0; i < n; i++) arr[i] = h.nl(); long x = h.nl(); long f = h.nl(); long cost = 0; for(i = 0; i < n; i++){ if(arr[i] > x){ arr[i] -= x; long p = arr[i]/(x + f); cost += p * f; arr[i] -= (x + f) * p; if(arr[i] > 0) cost += f; } } h.pn(cost); } /*void add_map(int x){ Integer xx = tmap.get(x); if(xx == null) tmap.put(x, 1); else tmap.put(x, ++x); } void remove_map(int x){ Integer xx = tmap.get(x); if(xx == 1) tmap.remove(x); else tmap.put(x, --xx); }*/ final Comparator<Entity> com=new Comparator<Entity>(){ public int compare(Entity x, Entity y){ int xx=Integer.compare(y.b, x.b); if(xx==0){ int xxx=Integer.compare(x.a,y.a); return xxx; } else return xx; } }; class Entity{ int a; int b; Entity(int p, int q){ a=p; b=q; } } class Helper_class{ long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);} int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);} int bitcount(long n){return (n==0)?0:(1+bitcount(n&(n-1)));} void p(Object o){out.print(o);} void pn(Object o){out.println(o);} void pni(Object o){out.println(o);out.flush();} String n(){return in.next();} String nln(){return in.nextLine();} int ni(){return Integer.parseInt(in.next());} long nl(){return Long.parseLong(in.next());} double nd(){return Double.parseDouble(in.next());} long mul(long a,long b){ if(a>=mod)a%=mod; if(b>=mod)b%=mod; a*=b; if(a>=mod)a%=mod; return a; } long modPow(long a, long p){ long o = 1; while(p>0){ if((p&1)==1)o = mul(o,a); a = mul(a,a); p>>=1; } return o; } long add(long a, long b){ if(a>=mod)a%=mod; if(b>=mod)b%=mod; if(b<0)b+=mod; a+=b; if(a>=mod)a-=mod; return a; } } class InputReader{ BufferedReader br; StringTokenizer st; public InputReader(){ br = new BufferedReader(new InputStreamReader(System.in)); } public InputReader(String s) throws Exception{ br = new BufferedReader(new FileReader(s)); } String next(){ while (st == null || !st.hasMoreElements()){ try{ st = new StringTokenizer(br.readLine()); }catch (IOException e){ e.printStackTrace(); } } return st.nextToken(); } String nextLine(){ String str = ""; try{ str = br.readLine(); }catch (IOException e){ e.printStackTrace(); } return str; } } }
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 two numbers $$$x$$$, $$$f$$$ ($$$1 \leq f &lt; x \leq 10^9$$$) representing maximum number of satoshies Alice can have in one address, as well as fee in satoshies she is willing to pay per transaction.
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
92214811e71100869a92cd9ec9e5ed71
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 them throughout the years. Unfortunately, when paying something in bitcoin everyone can see how many bitcoins you have in your public address wallet. This worried Alice, so she decided to split her bitcoins among multiple different addresses, so that every address has at most $$$x$$$ satoshi (1 bitcoin = $$$10^8$$$ satoshi). She can create new public address wallets for free and is willing to pay $$$f$$$ fee in satoshi per transaction to ensure acceptable speed of transfer. The fee is deducted from the address the transaction was sent from. Tell Alice how much total fee in satoshi she will need to pay to achieve her goal.
256 megabytes
import javafx.util.*; import java.util.*; import java.io.*; import java.math.*; public class Test5 { Random rnd = new Random(); PrintWriter pw = new PrintWriter(System.out); static int[] n; void run(){ long a = ni(),x,k,nk; long o = 0; long[] m = new long[(int)a]; for(int q=0; q<a; q++) m[q] = nl(); x = ni(); k = ni(); for(int q=0; q<a; q++){ nk = m[q]/(x+k)-(m[q]%(x+k)==0 ? 1 : 0); m[q]-=nk*(x+k); if(m[q]>x) nk++; o+=nk*k; } pw.print(o); pw.flush(); } static class PyraSort { private static int heapSize; public static void sort(int[] a) { buildHeap(a); while (heapSize > 1) { swap(a, 0, heapSize - 1); heapSize--; heapify(a, 0); } } private static void buildHeap(int[] a) { heapSize = a.length; for (int i = a.length / 2; i >= 0; i--) { heapify(a, i); } } private static void heapify(int[] a, int i) { int l = 2 * i + 2; int r = 2 * i + 1; int largest = i; if (l < heapSize && a[i]< a[l]) { largest = l; } if (r < heapSize && a[largest] < a[r]) { largest = r; } if (i != largest) { swap(a, i, largest); heapify(a, largest); } } private static void swap(int[] a, int i, int j) { a[i] ^= a[j] ^= a[i]; a[j] ^= a[i]; n[i] ^= n[j] ^= n[i]; n[j] ^= n[i]; } } public static void main(String[] args) { new Test5().run(); } InputStream is = System.in; private byte[] inbuf = new byte[1024]; public int lenbuf = 0, ptrbuf = 0; private int readByte() { if (lenbuf == -1) throw new InputMismatchException(); if (ptrbuf >= lenbuf) { ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) return -1; } return inbuf[ptrbuf++]; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) ; return b; } private double nd() { return Double.parseDouble(ns()); } private char nc() { return (char) skip(); } private String nline(){ int b = readByte(); StringBuilder sb = new StringBuilder(); while (b!=10) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while (p < n && !(isSpaceChar(b))) { buf[p++] = (char) b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private char[][] nm(int n, int m) { char[][] map = new char[n][]; for (int i = 0; i < n; i++) map[i] = ns(m); return map; } private int[] na(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = ni(); return a; } private int ni() { int num = 0, b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } private long nl() { long num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } }
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 two numbers $$$x$$$, $$$f$$$ ($$$1 \leq f &lt; x \leq 10^9$$$) representing maximum number of satoshies Alice can have in one address, as well as fee in satoshies she is willing to pay per transaction.
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
1608ec85e8443fed0bf212174f225d96
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 them throughout the years. Unfortunately, when paying something in bitcoin everyone can see how many bitcoins you have in your public address wallet. This worried Alice, so she decided to split her bitcoins among multiple different addresses, so that every address has at most $$$x$$$ satoshi (1 bitcoin = $$$10^8$$$ satoshi). She can create new public address wallets for free and is willing to pay $$$f$$$ fee in satoshi per transaction to ensure acceptable speed of transfer. The fee is deducted from the address the transaction was sent from. Tell Alice how much total fee in satoshi she will need to pay to achieve her goal.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class SplittingMoney { public static void main(String arg[]) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); Long [] num = new Long[n]; long fee = 0; for (int i = 0; i<n; i++) { Long a = scan.nextLong(); num[i] = a; } Long x = scan.nextLong(); Long f = scan.nextLong(); for (int i = 0; i<n; i++) { if(num[i]<=x) continue; long out=num[i]-x; long takePerTransaction=x+f; long numTransactions=(long)Math.ceil((double)out/takePerTransaction); fee+=numTransactions*f; // if (num[i] > x) { // Long minus = num[i]; // while (minus>x) { // fee = fee + f; // minus = minus - x - f; // } // // } //1 2 2 1 System.out.println(fee); } }
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 two numbers $$$x$$$, $$$f$$$ ($$$1 \leq f &lt; x \leq 10^9$$$) representing maximum number of satoshies Alice can have in one address, as well as fee in satoshies she is willing to pay per transaction.
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
adf9c2d192e9b65c95bbfe45251705ce
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 them throughout the years. Unfortunately, when paying something in bitcoin everyone can see how many bitcoins you have in your public address wallet. This worried Alice, so she decided to split her bitcoins among multiple different addresses, so that every address has at most $$$x$$$ satoshi (1 bitcoin = $$$10^8$$$ satoshi). She can create new public address wallets for free and is willing to pay $$$f$$$ fee in satoshi per transaction to ensure acceptable speed of transfer. The fee is deducted from the address the transaction was sent from. Tell Alice how much total fee in satoshi she will need to pay to achieve her goal.
256 megabytes
import java.util.*; public class BubbleF{ public static void main(String args[]) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long amounts[] = new long[n]; for (int i = 0; i < n;i++) { amounts[i] = sc.nextLong(); } long max = sc.nextLong(); long fee = sc.nextLong(); long sum = 0; for (int i = 0; i<n; i++) { //System.out.println("i: " + amounts[i] + ", " + i); //while (amounts[i]>max) { long temp = amounts[i]/(max+fee); sum += temp; amounts[i] -= (max+fee)*temp; if (amounts[i]>max) { sum++; } //} /*if ((max+fee)>amounts[i]) { int temp = max; while(temp+fee>max) { temp--; } amounts[i] = temp+fee } else { amounts[i] = amounts[i] - (max + fee); } sum += fee;*/ //System.out.println("sum: " + sum); } } System.out.println(sum*fee); sc.close(); } }
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 two numbers $$$x$$$, $$$f$$$ ($$$1 \leq f &lt; x \leq 10^9$$$) representing maximum number of satoshies Alice can have in one address, as well as fee in satoshies she is willing to pay per transaction.
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
296ea02dd2162f863147bfc2ee445e75
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 them throughout the years. Unfortunately, when paying something in bitcoin everyone can see how many bitcoins you have in your public address wallet. This worried Alice, so she decided to split her bitcoins among multiple different addresses, so that every address has at most $$$x$$$ satoshi (1 bitcoin = $$$10^8$$$ satoshi). She can create new public address wallets for free and is willing to pay $$$f$$$ fee in satoshi per transaction to ensure acceptable speed of transfer. The fee is deducted from the address the transaction was sent from. Tell Alice how much total fee in satoshi she will need to pay to achieve her goal.
256 megabytes
import java.util.*; import java.io.*; public class CFB { static int mod = (int) (1e9+7); static InputReader in; static PrintWriter out; public static void main(String[] args) { in = new InputReader(System.in); out = new PrintWriter(System.out); int n = in.nextInt(); int[] arr = in.nextIntArray(n); long res = 0; long x = in.nextInt(); long f = in.nextInt(); for(int i = 0; i < n; i++) { long y = (arr[i]) / (x + f); res += y * f; arr[i] -= (x + f) * y; if(arr[i] > x) { arr[i] -= x + f; res += f; } } out.println(res); out.close(); } static void debug(Object... o) { System.out.println(Arrays.deepToString(o)); } static long pow(long n,long p,long m) { long result = 1; if(p==0){ return 1; } while(p!=0) { if(p%2==1) result *= n; if(result >= m) result %= m; p >>=1; n*=n; if(n >= m) n%=m; } return result; } static long pow(long n,long p) { long result = 1; if(p==0) return 1; while(p!=0) { if(p%2==1) result *= n; p >>=1; n*=n; } return result; } static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int snext() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public long[] nextLongArray(int n) { long a[] = new long[n]; for (int i = 0; i < n; i++) { a[i] = nextLong(); } return a; } public String readString() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
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 two numbers $$$x$$$, $$$f$$$ ($$$1 \leq f &lt; x \leq 10^9$$$) representing maximum number of satoshies Alice can have in one address, as well as fee in satoshies she is willing to pay per transaction.
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
931fa1dfaee03bd6530600933bd9d98e
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 them throughout the years. Unfortunately, when paying something in bitcoin everyone can see how many bitcoins you have in your public address wallet. This worried Alice, so she decided to split her bitcoins among multiple different addresses, so that every address has at most $$$x$$$ satoshi (1 bitcoin = $$$10^8$$$ satoshi). She can create new public address wallets for free and is willing to pay $$$f$$$ fee in satoshi per transaction to ensure acceptable speed of transfer. The fee is deducted from the address the transaction was sent from. Tell Alice how much total fee in satoshi she will need to pay to achieve her goal.
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.util.Scanner; /** * * @author ElchinF */ public class SplittingMoney { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int[] arr = new int[N]; for (int i = 0; i < N; i++) { arr[i] = sc.nextInt(); } long x = sc.nextLong(); long f = sc.nextLong(); long count = 0; for(int i=0; i<N; i++){ count=count+(((arr[i]+f)/(x+f))*f); if((arr[i]+f)%(x+f)==0){ count=count-f; } } System.out.println(count); } }
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 two numbers $$$x$$$, $$$f$$$ ($$$1 \leq f &lt; x \leq 10^9$$$) representing maximum number of satoshies Alice can have in one address, as well as fee in satoshies she is willing to pay per transaction.
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
e715f8aef34d4578a98d3a000a01a5bd
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 them throughout the years. Unfortunately, when paying something in bitcoin everyone can see how many bitcoins you have in your public address wallet. This worried Alice, so she decided to split her bitcoins among multiple different addresses, so that every address has at most $$$x$$$ satoshi (1 bitcoin = $$$10^8$$$ satoshi). She can create new public address wallets for free and is willing to pay $$$f$$$ fee in satoshi per transaction to ensure acceptable speed of transfer. The fee is deducted from the address the transaction was sent from. Tell Alice how much total fee in satoshi she will need to pay to achieve her goal.
256 megabytes
import java.util.Scanner; public class Main { private static Scanner in = new Scanner(System.in); public static void main(String[] args) { int n = in.nextInt(); int[] x = new int[n]; for (int i = 0; i < n; i++) { x[i] = in.nextInt(); } long ans = 0; int m = in.nextInt(); int f = in.nextInt(); for (int i = 0; i < n; i++) { ans += (x[i] - 1L + f) / (m + f) * f; } System.out.println(ans); } }
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 two numbers $$$x$$$, $$$f$$$ ($$$1 \leq f &lt; x \leq 10^9$$$) representing maximum number of satoshies Alice can have in one address, as well as fee in satoshies she is willing to pay per transaction.
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
060c7e3b102ca67c24643d7fa124c069
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 them throughout the years. Unfortunately, when paying something in bitcoin everyone can see how many bitcoins you have in your public address wallet. This worried Alice, so she decided to split her bitcoins among multiple different addresses, so that every address has at most $$$x$$$ satoshi (1 bitcoin = $$$10^8$$$ satoshi). She can create new public address wallets for free and is willing to pay $$$f$$$ fee in satoshi per transaction to ensure acceptable speed of transfer. The fee is deducted from the address the transaction was sent from. Tell Alice how much total fee in satoshi she will need to pay to achieve her goal.
256 megabytes
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map.Entry; import java.util.function.IntPredicate; import java.util.Stack; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.TreeSet; public class Solution { public static void main(String[] args) throws IOException { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int [] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i]= scanner.nextInt(); } int x = scanner.nextInt(); int f = scanner.nextInt(); long counter = 0; int sum = x + f; for (int i = 0; i < n; i++) { int res = arr[i] - ((arr[i]/ sum) * sum); counter += (arr[i] / sum); if (res > x) { counter++; } } System.out.println(counter * f); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream System) throws FileNotFoundException { br = new BufferedReader(new InputStreamReader(System)); // String FILENAME = 'B-large.in'; // br = new BufferedReader(new FileReader(FILENAME)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public String nextLine() throws IOException { return br.readLine(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public char nextChar() throws IOException { return next().charAt(0); } public Long nextLong() throws IOException { return Long.parseLong(next()); } public boolean ready() throws IOException { return br.ready(); } public void waitForInput() { for (long i = 0; i < 3e9; i++) ; } } }
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 two numbers $$$x$$$, $$$f$$$ ($$$1 \leq f &lt; x \leq 10^9$$$) representing maximum number of satoshies Alice can have in one address, as well as fee in satoshies she is willing to pay per transaction.
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
29d1e19ac561554f0882493829a3aa08
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 them throughout the years. Unfortunately, when paying something in bitcoin everyone can see how many bitcoins you have in your public address wallet. This worried Alice, so she decided to split her bitcoins among multiple different addresses, so that every address has at most $$$x$$$ satoshi (1 bitcoin = $$$10^8$$$ satoshi). She can create new public address wallets for free and is willing to pay $$$f$$$ fee in satoshi per transaction to ensure acceptable speed of transfer. The fee is deducted from the address the transaction was sent from. Tell Alice how much total fee in satoshi she will need to pay to achieve her goal.
256 megabytes
//package codeforces.bubble_cup_final_mirror; import java.util.Scanner; public class F_SplittingMoney { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); int[] accounts = new int[N]; for (int i = 0; i < N; i++) { accounts[i] = scanner.nextInt(); } int maxMoney = scanner.nextInt(); int fee = scanner.nextInt(); long totalFee = 0; for (int i = 0; i < N; i++) { int extraAccount = accounts[i] / (maxMoney + fee); totalFee += extraAccount * fee; accounts[i] -= (maxMoney + fee) * extraAccount; if (accounts[i] > maxMoney) { totalFee += fee; } } System.out.println(totalFee); } }
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 two numbers $$$x$$$, $$$f$$$ ($$$1 \leq f &lt; x \leq 10^9$$$) representing maximum number of satoshies Alice can have in one address, as well as fee in satoshies she is willing to pay per transaction.
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
90ec6ed73d420a350978aa50b683141f
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 them throughout the years. Unfortunately, when paying something in bitcoin everyone can see how many bitcoins you have in your public address wallet. This worried Alice, so she decided to split her bitcoins among multiple different addresses, so that every address has at most $$$x$$$ satoshi (1 bitcoin = $$$10^8$$$ satoshi). She can create new public address wallets for free and is willing to pay $$$f$$$ fee in satoshi per transaction to ensure acceptable speed of transfer. The fee is deducted from the address the transaction was sent from. Tell Alice how much total fee in satoshi she will need to pay to achieve her goal.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; /** * */ public class F { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(reader.readLine()); int n = Integer.parseInt(st.nextToken()); st = new StringTokenizer(reader.readLine()); int[]w = new int[n]; for (int i = 0; i < n; i++) { w[i]=Integer.parseInt(st.nextToken()); } st = new StringTokenizer(reader.readLine()); int x = Integer.parseInt(st.nextToken()); int f = Integer.parseInt(st.nextToken()); long ans = 0; for (int i = 0; i < n; i++) { if(w[i] > x){ ans += ((w[i]-x)/(x+f) + ((w[i]-x)%(x+f) == 0?0:1))*f; } } System.out.println(ans); } }
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 two numbers $$$x$$$, $$$f$$$ ($$$1 \leq f &lt; x \leq 10^9$$$) representing maximum number of satoshies Alice can have in one address, as well as fee in satoshies she is willing to pay per transaction.
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
67fdc5cf409f65c264655a69cdd740a9
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 them throughout the years. Unfortunately, when paying something in bitcoin everyone can see how many bitcoins you have in your public address wallet. This worried Alice, so she decided to split her bitcoins among multiple different addresses, so that every address has at most $$$x$$$ satoshi (1 bitcoin = $$$10^8$$$ satoshi). She can create new public address wallets for free and is willing to pay $$$f$$$ fee in satoshi per transaction to ensure acceptable speed of transfer. The fee is deducted from the address the transaction was sent from. Tell Alice how much total fee in satoshi she will need to pay to achieve her goal.
256 megabytes
import java.io.*; import java.math.BigInteger; import java.util.*; public class A { static MyScanner sc; static PrintWriter pw; public static void main(String[] args) throws Throwable { sc = new MyScanner(); pw = new PrintWriter(System.out); int n = sc.nextInt(); long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = sc.nextInt(); long x = sc.nextInt(); long f = sc.nextInt(); long ans=0; for(int i=0;i<n;i++) ans+=(a[i]+f-1)/(x+f); // ceil[(a[i]-x)/(x+f)] <= m pw.println(ans*f); pw.flush(); pw.close(); } static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["3\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 two numbers $$$x$$$, $$$f$$$ ($$$1 \leq f &lt; x \leq 10^9$$$) representing maximum number of satoshies Alice can have in one address, as well as fee in satoshies she is willing to pay per transaction.
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
21beaecdb8b191a16931c3f60b6ed740
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 them throughout the years. Unfortunately, when paying something in bitcoin everyone can see how many bitcoins you have in your public address wallet. This worried Alice, so she decided to split her bitcoins among multiple different addresses, so that every address has at most $$$x$$$ satoshi (1 bitcoin = $$$10^8$$$ satoshi). She can create new public address wallets for free and is willing to pay $$$f$$$ fee in satoshi per transaction to ensure acceptable speed of transfer. The fee is deducted from the address the transaction was sent from. Tell Alice how much total fee in satoshi she will need to pay to achieve her goal.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; import java.util.StringTokenizer; public class vk18 { public static void main(String[] stp) throws Exception { Scanner scan = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()),i; Integer a[]=new Integer[n]; st = new StringTokenizer(br.readLine()); for(i=0;i<n;i++) a[i]=Integer.parseInt(st.nextToken()); st = new StringTokenizer(br.readLine()); int x=Integer.parseInt(st.nextToken()),f=Integer.parseInt(st.nextToken()); long ans=0; for(i=0;i<n;i++) { if(a[i] > x) { double p=(double)(a[i]-x)/(x+f); ans+=Math.ceil(p); } } ans=ans*f; pw.println(ans); pw.flush(); } }
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 two numbers $$$x$$$, $$$f$$$ ($$$1 \leq f &lt; x \leq 10^9$$$) representing maximum number of satoshies Alice can have in one address, as well as fee in satoshies she is willing to pay per transaction.
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
2dbfc2fd6528ab66d9747e9302024e76
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 them throughout the years. Unfortunately, when paying something in bitcoin everyone can see how many bitcoins you have in your public address wallet. This worried Alice, so she decided to split her bitcoins among multiple different addresses, so that every address has at most $$$x$$$ satoshi (1 bitcoin = $$$10^8$$$ satoshi). She can create new public address wallets for free and is willing to pay $$$f$$$ fee in satoshi per transaction to ensure acceptable speed of transfer. The fee is deducted from the address the transaction was sent from. Tell Alice how much total fee in satoshi she will need to pay to achieve her goal.
256 megabytes
// 1046 F import java.util.Scanner; import java.lang.Math; public class SplittingMoney{ public static void main(String [] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long [] a = new long[n]; for(int i = 0; i < n; i++) a[i] = sc.nextInt(); long x = sc.nextInt(); long f = sc.nextInt(); long c = 0; for(int i = 0; i < n; i++){ c += (long)Math.ceil((double)(a[i] + f)/(x+f)) - 1; } System.out.println(c * f); } }
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 two numbers $$$x$$$, $$$f$$$ ($$$1 \leq f &lt; x \leq 10^9$$$) representing maximum number of satoshies Alice can have in one address, as well as fee in satoshies she is willing to pay per transaction.
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
a35fe0c6f6be670e46dd0bd6b65fcf9f
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 them throughout the years. Unfortunately, when paying something in bitcoin everyone can see how many bitcoins you have in your public address wallet. This worried Alice, so she decided to split her bitcoins among multiple different addresses, so that every address has at most $$$x$$$ satoshi (1 bitcoin = $$$10^8$$$ satoshi). She can create new public address wallets for free and is willing to pay $$$f$$$ fee in satoshi per transaction to ensure acceptable speed of transfer. The fee is deducted from the address the transaction was sent from. Tell Alice how much total fee in satoshi she will need to pay to achieve her goal.
256 megabytes
import java.util.Scanner; /** * Created by shnovruzov on 22/10/2018. */ public class Test { public static void main(String args[]) { Scanner in = new Scanner(System.in); int N = in.nextInt(); int a[] = new int[N]; for (int i = 0; i < N; i++) a[i] = in.nextInt(); int x = in.nextInt(); int f = in.nextInt(); long cost = 0; for (int i = 0; i < N; i++) if (a[i] > x) { cost += f; cost += ((a[i] - x - 1) / (x + f)) * f; } System.out.println(cost); } }
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 two numbers $$$x$$$, $$$f$$$ ($$$1 \leq f &lt; x \leq 10^9$$$) representing maximum number of satoshies Alice can have in one address, as well as fee in satoshies she is willing to pay per transaction.
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
c2e841bca5194b243e722e2c1a5dd9c3
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 them throughout the years. Unfortunately, when paying something in bitcoin everyone can see how many bitcoins you have in your public address wallet. This worried Alice, so she decided to split her bitcoins among multiple different addresses, so that every address has at most $$$x$$$ satoshi (1 bitcoin = $$$10^8$$$ satoshi). She can create new public address wallets for free and is willing to pay $$$f$$$ fee in satoshi per transaction to ensure acceptable speed of transfer. The fee is deducted from the address the transaction was sent from. Tell Alice how much total fee in satoshi she will need to pay to achieve her goal.
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 */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskF solver = new TaskF(); solver.solve(1, in, out); out.close(); } static class TaskF { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.ni(); long[] ar = new long[n]; for (int i = 0; i < n; ++i) ar[i] = in.nl(); long x = in.nl(); long f = in.nl(); long ans = 0; for (int i = 0; i < n; ++i) { if (ar[i] <= x) continue; long curr = ar[i] - x; ans += curr / (x + f); if (curr % (x + f) != 0) ans++; } out.print(ans * f); } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int ni() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nl() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
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 two numbers $$$x$$$, $$$f$$$ ($$$1 \leq f &lt; x \leq 10^9$$$) representing maximum number of satoshies Alice can have in one address, as well as fee in satoshies she is willing to pay per transaction.
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
cacb5f356a1aeab9f95cf25781459802
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 them throughout the years. Unfortunately, when paying something in bitcoin everyone can see how many bitcoins you have in your public address wallet. This worried Alice, so she decided to split her bitcoins among multiple different addresses, so that every address has at most $$$x$$$ satoshi (1 bitcoin = $$$10^8$$$ satoshi). She can create new public address wallets for free and is willing to pay $$$f$$$ fee in satoshi per transaction to ensure acceptable speed of transfer. The fee is deducted from the address the transaction was sent from. Tell Alice how much total fee in satoshi she will need to pay to achieve her goal.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner scn = new Scanner(System.in); int n = scn.nextInt(); int arr[] = new int[n]; for(int i=0;i<n;i++){ arr[i]=scn.nextInt(); } int x = scn.nextInt(); int f = scn.nextInt(); long count=0; for(int i=0;i<n;i++){ if(arr[i]>x){ double a = (double)(arr[i]-x)/(x+f); count+=(Math.ceil(a)); } } long ans = count*f; System.out.println(ans); } }
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 two numbers $$$x$$$, $$$f$$$ ($$$1 \leq f &lt; x \leq 10^9$$$) representing maximum number of satoshies Alice can have in one address, as well as fee in satoshies she is willing to pay per transaction.
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
af46ca42ba995b622ce00ce607f167c2
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 them throughout the years. Unfortunately, when paying something in bitcoin everyone can see how many bitcoins you have in your public address wallet. This worried Alice, so she decided to split her bitcoins among multiple different addresses, so that every address has at most $$$x$$$ satoshi (1 bitcoin = $$$10^8$$$ satoshi). She can create new public address wallets for free and is willing to pay $$$f$$$ fee in satoshi per transaction to ensure acceptable speed of transfer. The fee is deducted from the address the transaction was sent from. Tell Alice how much total fee in satoshi she will need to pay to achieve her goal.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class Main{ public static long find_count(long[] a, long max_satoshi,long fees){ long total = 0; for(int i=0;i<a.length;i++){ long div = 0; if(a[(int)i]>max_satoshi){ div = a[(int)i]/(max_satoshi+fees); total = total+div; long h = a[(int)i]-(div*(max_satoshi+fees)); if(h>max_satoshi){ total = total+1; } } } return total*fees; } public static void main(String[] args) { // TODO Auto-generated method stub Scanner inti = new Scanner(System.in); long n = inti.nextLong(); long[] a = new long[(int)n]; for(int i=0;i<n;i++){ a[i] = inti.nextLong(); } long total_fees = 0; long max_satoshi = inti.nextLong(); long fees = inti.nextLong(); total_fees = find_count(a,max_satoshi,fees); System.out.println(total_fees); } }
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 two numbers $$$x$$$, $$$f$$$ ($$$1 \leq f &lt; x \leq 10^9$$$) representing maximum number of satoshies Alice can have in one address, as well as fee in satoshies she is willing to pay per transaction.
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
644dd28e7f84ca876bc64586f184155e
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 them throughout the years. Unfortunately, when paying something in bitcoin everyone can see how many bitcoins you have in your public address wallet. This worried Alice, so she decided to split her bitcoins among multiple different addresses, so that every address has at most $$$x$$$ satoshi (1 bitcoin = $$$10^8$$$ satoshi). She can create new public address wallets for free and is willing to pay $$$f$$$ fee in satoshi per transaction to ensure acceptable speed of transfer. The fee is deducted from the address the transaction was sent from. Tell Alice how much total fee in satoshi she will need to pay to achieve her goal.
256 megabytes
import java.io.*; import java.lang.reflect.Array; import java.math.BigInteger; import java.util.*; import java.util.Random; import java.util.StringTokenizer; public class Main { String fileName = ""; ////////////////////// SOLUTION SOLUTION SOLUTION ////////////////////////////// Long INF = Long.MAX_VALUE; int MODULO = 998244353; long MAX_VALUE = 1000l*1000*1000*100; int[][] steps = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}}; private final static Random rnd = new Random(); double eps = 1e-1; ArrayList<Integer>[] graph; int[] distFromRoot; int[] distFromX; int[] maxDistFromRoot; boolean[] used; int ans = -1; void solve() throws IOException { int n = readInt(); long sum = 0; int[] arr = readIntArray(n); long x = readLong(); long f = readInt(); for (int i=0; i < n; ++i) { long l = -1; long r = arr[i] + 1; while (r - l > 1){ long mid = (r + l) / 2; if (arr[i] > mid * (x + f) + x) l = mid; else r = mid; } sum += r*f; //out.println(r); } out.println(sum); } long binPow(long a, long b, long m) { if (b == 0) { return 1; } if (b % 2 == 1) { return ((a % m) * (binPow(a, b - 1, m) % m)) % m; } else { long c = binPow(a, b / 2, m); return (c * c) % m; } } class Fenwik { int[] t; int n; Fenwik(int n){ t = new int[n]; this.n = n; } void inc(int r, int delta){ for (; r < n; r = r | (r + 1)) t[r] += delta; } int getSum(int r){ int res = 0; for (; r >=0; r = (r & (r + 1) ) - 1) res += t[r]; return res; } } boolean isPrime(int n){ for (int i=2; i*i<=n; ++i){ if (n%i==0) return false; } return true; } class Edge{ int from, to; long dist; public Edge(int to, long dist) { this.to = to; this.dist = dist; } } class Number implements Comparable<Number>{ int x, cost; Number(int x, int cost){ this.x = x; this.cost = cost; } @Override public int compareTo(Number o) { return Integer.compare(this.cost, o.cost); } } /////////////////////////////////////////////////////////////////////////////////////////// class Dsu{ int[] parent; int countSets; Dsu(int n){ parent = new int[n]; countSets = n; for (int i=0; i<n; ++i){ parent[i] = i; } } int findSet(int a){ if (a == parent[a]) return a; parent[a] = findSet(parent[a]); return parent[a]; } void unionSets(int a, int b){ a = findSet(a); b = findSet(b); if (a != b){ parent[a] = b; countSets--; } } } class SparseTable{ int[][] rmq; int[] logTable; int n; SparseTable(int[] a){ n = a.length; logTable = new int[n+1]; for(int i = 2; i <= n; ++i){ logTable[i] = logTable[i >> 1] + 1; } rmq = new int[logTable[n] + 1][n]; for(int i=0; i<n; ++i){ rmq[0][i] = a[i]; } for(int k=1; (1 << k) < n; ++k){ for(int i=0; i + (1 << k) <= n; ++i){ int max1 = rmq[k - 1][i]; int max2 = rmq[k-1][i + (1 << (k-1))]; rmq[k][i] = Math.max(max1, max2); } } } int max(int l, int r){ int k = logTable[r - l]; int max1 = rmq[k][l]; int max2 = rmq[k][r - (1 << k) + 1]; return Math.max(max1, max2); } } long checkBit(long mask, int bit){ return (mask >> bit) & 1; } static int checkBit(int mask, int bit) { return (mask >> bit) & 1; } boolean isLower(char c){ return c >= 'a' && c <= 'z'; } //////////////////////////////////////////////////////////// int gcd(int a, int b){ return b == 0 ? a : gcd(b, a%b); } long gcd(long a, long b){ return b == 0 ? a : gcd(b, a%b); } double binPow(double a, int pow){ if (pow == 0) return 1; if (pow % 2 == 1) { return a * binPow(a, pow - 1); } else { double c = binPow(a, pow / 2); return c * c; } } int minInt(int... values) { int min = Integer.MAX_VALUE; for (int value : values) min = Math.min(min, value); return min; } int maxInt(int... values) { int max = Integer.MIN_VALUE; for (int value : values) max = Math.max(max, value); return max; } public static void main(String[] args) throws NumberFormatException, IOException { // TODO Auto-generated method stub new Main().run(); } void run() throws NumberFormatException, IOException { solve(); out.close(); }; BufferedReader in; PrintWriter out; StringTokenizer tok; String delim = " "; Main() throws FileNotFoundException { try { in = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter("output.txt"); } catch (Exception e) { if (fileName.isEmpty()) { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } else { in = new BufferedReader(new FileReader(fileName + ".in")); out = new PrintWriter(fileName + ".out"); } } tok = new StringTokenizer(""); } String readLine() throws IOException { return in.readLine(); } String readString() throws IOException { while (!tok.hasMoreTokens()) { String nextLine = readLine(); if (null == nextLine) { return null; } tok = new StringTokenizer(nextLine); } return tok.nextToken(); } int readInt() throws NumberFormatException, IOException { return Integer.parseInt(readString()); } byte readByte() throws NumberFormatException, IOException { return Byte.parseByte(readString()); } int[] readIntArray (int n) throws NumberFormatException, IOException { int[] a = new int[n]; for(int i=0; i<n; ++i){ a[i] = readInt(); } return a; } Integer[] readIntegerArray (int n) throws NumberFormatException, IOException { Integer[] a = new Integer[n]; for(int i=0; i<n; ++i){ a[i] = readInt(); } return a; } long readLong() throws NumberFormatException, IOException { return Long.parseLong(readString()); } double readDouble() throws NumberFormatException, IOException { return Double.parseDouble(readString()); } }
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 two numbers $$$x$$$, $$$f$$$ ($$$1 \leq f &lt; x \leq 10^9$$$) representing maximum number of satoshies Alice can have in one address, as well as fee in satoshies she is willing to pay per transaction.
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output
PASSED
b88e093c1e3cb341dc82d904ca80cb32
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 them throughout the years. Unfortunately, when paying something in bitcoin everyone can see how many bitcoins you have in your public address wallet. This worried Alice, so she decided to split her bitcoins among multiple different addresses, so that every address has at most $$$x$$$ satoshi (1 bitcoin = $$$10^8$$$ satoshi). She can create new public address wallets for free and is willing to pay $$$f$$$ fee in satoshi per transaction to ensure acceptable speed of transfer. The fee is deducted from the address the transaction was sent from. Tell Alice how much total fee in satoshi she will need to pay to achieve her goal.
256 megabytes
import java.io.*; import java.util.StringTokenizer; public class F { public static void main(String[] args) throws IOException { init(); int n = nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); long x = nextInt(), f = nextInt(); long trans = 0; for (int bits: a) { trans += (long) bits/(x + f); if (bits % (x + f) > x) trans++; } System.out.println(trans*f); } //Input Reader private static BufferedReader reader; private static StringTokenizer tokenizer; private static void init() { reader = new BufferedReader(new InputStreamReader(System.in)); tokenizer = new StringTokenizer(""); } private static String next() throws IOException { String read; while (!tokenizer.hasMoreTokens()) { read = reader.readLine(); if (read == null || read.equals("")) return "-1"; tokenizer = new StringTokenizer(read); } return tokenizer.nextToken(); } private static int nextInt() throws IOException { return Integer.parseInt(next()); } // private static long nextLong() throws IOException { // return Long.parseLong(next()); // } // // // Get a whole line. // private static String line() throws IOException { // return reader.readLine(); // } // // private static double nextDouble() throws IOException { // return Double.parseDouble(next()); // } }
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 two numbers $$$x$$$, $$$f$$$ ($$$1 \leq f &lt; x \leq 10^9$$$) representing maximum number of satoshies Alice can have in one address, as well as fee in satoshies she is willing to pay per transaction.
1,400
Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.
standard output