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
056777dab7de2e9a4db79cc78229f1ab
train_002.jsonl
1325689200
As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergey's twins help him: they've already made n snowballs with radii equal to r1, r2, ..., rn. To make a snowman, one needs any three snowballs whose radii are pairwise different. For example, the balls with radii 1, 2 and 3 can be used to make a snowman but 2, 2, 3 or 2, 2, 2 cannot. Help Sergey and his twins to determine what maximum number of snowmen they can make from those snowballs.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; public class C implements Runnable{ BufferedReader in; PrintWriter out; StringTokenizer Tokenizer; private boolean CanMake(int value, int[] a, int n) throws IOException{ int m=1; int count = 1; for(int i = 1; i<n; i++){ if (a[i]==a[i-1]) count++; else count=1; if (count<=value) m++; } if (m>=3*value) return true; else return false; } private void Find_Array(int value, int[] a, int n){ int[][] write = new int[value][3]; int[] b = new int[n]; int m=0; int count=1; for(int i= 0; i<n; i++){ if (i<=0 || a[i]!=a[i-1]) count=1; else count++; if (count<=value){ m++; b[m-1] = a[i]; } } int k = 0; for(int i = 0; i<m; i++){ write[k][0] = b[i]; write[k][1] = b[i+value]; write[k][2] = b[i+2*value]; k++; if(k>=value) break; } for(int i = 0; i<value; i++){ Arrays.sort(write[i]); out.println(str(write[i][2])+" "+str(write[i][1])+" "+str(write[i][0])); } } private void BinarySearch(int n, int[] a) throws IOException{ int l=0; int r=(n/3); int res = 0; while(l<=r){ int mid = (l+r)/2; if (CanMake(mid, a, n)){ l = mid+1; res=mid; }else r=mid-1; } out.println(str(res)); Find_Array(res,a,n); } private void solve() throws IOException{ int n = NextInt(); int[] a = new int[n]; for(int i = 0; i<n; i++) a[i] = NextInt(); Arrays.sort(a); BinarySearch(n,a); } public void run(){ try{ in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); in.close(); out.close(); } catch (Exception e){ System.out.println(e.getMessage()); } } int NextInt() throws IOException{ return Integer.parseInt(NextToken()); } long NextLong() throws IOException{ return Long.parseLong(NextToken()); } double NextDouble() throws IOException{ return Double.parseDouble(NextToken()); } String str(int x){ return Integer.toString(x); } String NextToken() throws IOException{ while(Tokenizer == null || !Tokenizer.hasMoreTokens()){ Tokenizer = new StringTokenizer(in.readLine()); } return Tokenizer.nextToken(); } public static void main(String[] args){ new C().run(); } }
Java
["7\n1 2 3 4 5 6 7", "3\n2 2 3"]
2 seconds
["2\n3 2 1\n6 5 4", "0"]
null
Java 6
standard input
[ "data structures", "binary search", "greedy" ]
551e66a4b3da71682652d84313adb8ab
The first line contains integer n (1 ≀ n ≀ 105) β€” the number of snowballs. The next line contains n integers β€” the balls' radii r1, r2, ..., rn (1 ≀ ri ≀ 109). The balls' radii can coincide.
1,800
Print on the first line a single number k β€” the maximum number of the snowmen. Next k lines should contain the snowmen's descriptions. The description of each snowman should consist of three space-separated numbers β€” the big ball's radius, the medium ball's radius and the small ball's radius. It is allowed to print the snowmen in any order. If there are several solutions, print any of them.
standard output
PASSED
ea74863e956735142ac0f358febbdaa1
train_002.jsonl
1325689200
As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergey's twins help him: they've already made n snowballs with radii equal to r1, r2, ..., rn. To make a snowman, one needs any three snowballs whose radii are pairwise different. For example, the balls with radii 1, 2 and 3 can be used to make a snowman but 2, 2, 3 or 2, 2, 2 cannot. Help Sergey and his twins to determine what maximum number of snowmen they can make from those snowballs.
256 megabytes
import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.*; import java.util.regex.*; import java.text.*; import java.math.*; import java.awt.HeadlessException; import java.awt.geom.*; public class C { public static final boolean debug = false; void pln(Object o) {System.out.println(o.toString());} class Pair implements Comparable<Pair> { int n, k; public Pair(int n0, int k0) { n = n0; k = k0; } public int compareTo(Pair o) { return o.k - this.k; } public String toString() { return "(" + n + ", " + k + ")"; } } public void solve() { Scanner sc = null; if (debug) { try { sc = new Scanner(new File("P3.in")); } catch (Exception e) { e.printStackTrace(); } } else { sc = new Scanner(System.in); } int n = sc.nextInt(); int k; Vector<Integer> v = new Vector<Integer>(); for (int i=0; i<n; i++) { k = sc.nextInt(); v.add(k); } Collections.sort(v); Pair p = new Pair(v.get(0), 1); PriorityQueue<Pair> pq = new PriorityQueue<Pair>(); for (int i=1; i<n; i++) { if (p.n == v.get(i)) { p.k++; } else { pq.add(p); p = new Pair(v.get(i), 1); } } pq.add(p); int nr = 0; Vector<Integer> vaux = new Vector<Integer>(3); Vector<Integer> v2 = new Vector<Integer>(); while (true) { Pair f1 = pq.poll(); Pair f2 = pq.poll(); Pair f3 = pq.poll(); if (f3 == null) break; nr++; f1.k--; f2.k--; f3.k--; if (f1.k > 0) pq.add(f1); if (f2.k > 0) pq.add(f2); if (f3.k > 0) pq.add(f3); vaux.removeAllElements(); vaux.add(f1.n); vaux.add(f2.n); vaux.add(f3.n); Collections.sort(vaux); v2.addAll(vaux); } System.out.println(nr); for (int i=0; i<v2.size(); i+=3) System.out.println(v2.get(i+2) + " " + v2.get(i+1) + " " + v2.get(i)); // pw.close(); } public static void main(String[] args) { C t = new C(); t.solve(); } }
Java
["7\n1 2 3 4 5 6 7", "3\n2 2 3"]
2 seconds
["2\n3 2 1\n6 5 4", "0"]
null
Java 6
standard input
[ "data structures", "binary search", "greedy" ]
551e66a4b3da71682652d84313adb8ab
The first line contains integer n (1 ≀ n ≀ 105) β€” the number of snowballs. The next line contains n integers β€” the balls' radii r1, r2, ..., rn (1 ≀ ri ≀ 109). The balls' radii can coincide.
1,800
Print on the first line a single number k β€” the maximum number of the snowmen. Next k lines should contain the snowmen's descriptions. The description of each snowman should consist of three space-separated numbers β€” the big ball's radius, the medium ball's radius and the small ball's radius. It is allowed to print the snowmen in any order. If there are several solutions, print any of them.
standard output
PASSED
a9d2ffcd64281ec3d758d1ff9b70f346
train_002.jsonl
1325689200
As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergey's twins help him: they've already made n snowballs with radii equal to r1, r2, ..., rn. To make a snowman, one needs any three snowballs whose radii are pairwise different. For example, the balls with radii 1, 2 and 3 can be used to make a snowman but 2, 2, 3 or 2, 2, 2 cannot. Help Sergey and his twins to determine what maximum number of snowmen they can make from those snowballs.
256 megabytes
import java.util.Map.Entry; import java.util.*; import java.io.*; import static java.lang.Math.*; public class Main { BufferedReader in; StringTokenizer st; PrintWriter out; static class Pair implements Comparable<Pair> { int cnt, value; public Pair(int cnt, int value) { super(); this.cnt = cnt; this.value = value; } @Override public int compareTo(Pair o) { if (cnt != o.cnt) return cnt - o.cnt; return value - o.value; } } int sz; Pair[] v; Pair getNext() { if (sz < 0) return null; Pair ret = v[sz]; --sz; return ret; } Pair process(Pair p) { p.cnt--; if (p.cnt <= 0) return getNext(); return p; } void solve() throws IOException { int n = ni(); HashMap<Integer, Integer> map = new HashMap<Integer, Integer>(); for (int i = 0; i < n; ++i) { int a = ni(); if (map.containsKey(a) == false) map.put(a, 0); map.put(a, map.get(a) + 1); } TreeSet<Pair> set = new TreeSet<Main.Pair>(); for (Entry<Integer, Integer> e : map.entrySet()) set.add(new Pair(e.getValue(), e.getKey())); StringBuilder ret = new StringBuilder(); int cnt = 0; int[] tSort = new int[3]; while (set.size() >= 3) { Pair p1 = set.pollLast(); Pair p2 = set.pollLast(); Pair p3 = set.pollLast(); ++cnt; tSort[0] = p1.value; tSort[1] = p2.value; tSort[2] = p3.value; Arrays.sort(tSort); ret.append(tSort[2] + " " + tSort[1] + " " + tSort[0] + "\n"); add(p1, set); add(p2, set); add(p3, set); } out.println(cnt); out.println(ret); } void add(Pair p, TreeSet<Pair> set) { --p.cnt; if (p.cnt > 0) set.add(p); } public Main() throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); in.close(); out.close(); } String ns() throws IOException { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(in.readLine()); } return st.nextToken(); } int ni() throws IOException { return Integer.valueOf(ns()); } long nl() throws IOException { return Long.valueOf(ns()); } double nd() throws IOException { return Double.valueOf(ns()); } public static void main(String[] args) throws IOException { new Main(); } }
Java
["7\n1 2 3 4 5 6 7", "3\n2 2 3"]
2 seconds
["2\n3 2 1\n6 5 4", "0"]
null
Java 6
standard input
[ "data structures", "binary search", "greedy" ]
551e66a4b3da71682652d84313adb8ab
The first line contains integer n (1 ≀ n ≀ 105) β€” the number of snowballs. The next line contains n integers β€” the balls' radii r1, r2, ..., rn (1 ≀ ri ≀ 109). The balls' radii can coincide.
1,800
Print on the first line a single number k β€” the maximum number of the snowmen. Next k lines should contain the snowmen's descriptions. The description of each snowman should consist of three space-separated numbers β€” the big ball's radius, the medium ball's radius and the small ball's radius. It is allowed to print the snowmen in any order. If there are several solutions, print any of them.
standard output
PASSED
0507f8a8d0d561eb2640449ac6420104
train_002.jsonl
1325689200
As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergey's twins help him: they've already made n snowballs with radii equal to r1, r2, ..., rn. To make a snowman, one needs any three snowballs whose radii are pairwise different. For example, the balls with radii 1, 2 and 3 can be used to make a snowman but 2, 2, 3 or 2, 2, 2 cannot. Help Sergey and his twins to determine what maximum number of snowmen they can make from those snowballs.
256 megabytes
import java.util.*; import java.io.*; import java.awt.Point; import static java.lang.Math.*; public class P140C { public static void main(String[] args) throws Exception { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] data = new int[n]; for(int i=0; i<n; i++) data[i] = in.nextInt(); Arrays.sort(data); TreeSet<Point> P = new TreeSet<Point>(new Comparator<Point>() { public int compare(Point A, Point B) { if(A.y != B.y) return A.y-B.y; return A.x - B.x; } }); int val = -1; int cnt = 0; for(int i=0; i<n; i++) { if(data[i] != val) { if(val != -1) P.add(new Point(val,cnt)); val = data[i]; cnt = 1; } else { cnt++; } } P.add(new Point(val,cnt)); int ix = 0; int[][] ans = new int[n][3]; while(!P.isEmpty()) { Point p1 = P.pollLast(); if(P.isEmpty()) break; Point p2 = P.pollLast(); if(P.isEmpty()) break; Point p3 = P.pollLast(); int[] arr = new int[]{p1.x,p2.x,p3.x}; if(p1.y > 1) P.add(new Point(p1.x,p1.y-1)); if(p2.y > 1) P.add(new Point(p2.x,p2.y-1)); if(p3.y > 1) P.add(new Point(p3.x,p3.y-1)); Arrays.sort(arr); for(int i=0; i<3; i++) ans[ix][2-i] = arr[i]; ix++; } System.out.println(ix); for(int i=0; i<ix; i++) System.out.println(ans[i][0]+" "+ans[i][1]+" "+ans[i][2]); } }
Java
["7\n1 2 3 4 5 6 7", "3\n2 2 3"]
2 seconds
["2\n3 2 1\n6 5 4", "0"]
null
Java 6
standard input
[ "data structures", "binary search", "greedy" ]
551e66a4b3da71682652d84313adb8ab
The first line contains integer n (1 ≀ n ≀ 105) β€” the number of snowballs. The next line contains n integers β€” the balls' radii r1, r2, ..., rn (1 ≀ ri ≀ 109). The balls' radii can coincide.
1,800
Print on the first line a single number k β€” the maximum number of the snowmen. Next k lines should contain the snowmen's descriptions. The description of each snowman should consist of three space-separated numbers β€” the big ball's radius, the medium ball's radius and the small ball's radius. It is allowed to print the snowmen in any order. If there are several solutions, print any of them.
standard output
PASSED
2a585dae6d3825ff05b2636295c1a013
train_002.jsonl
1325689200
As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergey's twins help him: they've already made n snowballs with radii equal to r1, r2, ..., rn. To make a snowman, one needs any three snowballs whose radii are pairwise different. For example, the balls with radii 1, 2 and 3 can be used to make a snowman but 2, 2, 3 or 2, 2, 2 cannot. Help Sergey and his twins to determine what maximum number of snowmen they can make from those snowballs.
256 megabytes
import java.util.*; public class c { public static void main(String args[]) { Scanner in = new Scanner(System.in); int N = in.nextInt(); ArrayList<Integer> list = new ArrayList<Integer>(); ArrayList<Ball> snowballs = new ArrayList<Ball>(); for(int i = 0; i < N; i++) { list.add(in.nextInt()); } Collections.sort(list); for(int i = 0; i < list.size(); i++) { if(snowballs.size() > 0 && snowballs.get(snowballs.size()-1).size == list.get(i).intValue()) snowballs.get(snowballs.size()-1).count++; else snowballs.add(new Ball(list.get(i).intValue(), 1)); } PriorityQueue<Ball> q = new PriorityQueue<Ball>(); q.addAll(snowballs); Queue<snowMen> ans = new LinkedList<snowMen>(); while(q.size() > 2) { Ball a = q.poll(); Ball b = q.poll(); Ball c = q.poll(); int balls[] = new int[3]; balls[0] = a.size; balls[1] = b.size; balls[2] = c.size; ans.add(new snowMen(balls)); a.count--; b.count--; c.count--; if(a.count > 0) q.add(a); if(b.count > 0) q.add(b); if(c.count > 0) q.add(c); } System.out.println(ans.size()); for(snowMen sm : ans) { for(int i = 0; i < 3; i++) { System.out.print(sm.balls[i] + " "); } System.out.println(); } } public static int findBall(int size, ArrayList<Ball> list) { int lo = 0; int hi = list.size(); boolean finished = false; while(hi > lo && !finished) { int mid = (hi + lo) / 2; if(mid == lo || mid == hi) finished = true; if(list.get(mid).size < size) lo = mid; else if(list.get(mid).size > size) hi = mid; else return mid; } return lo; } static class Ball implements Comparable<Ball> { int size, count; public Ball(int size, int count) { this.size = size; this.count = count; } public int compareTo(Ball that) { if(this.count == that.count) return that.size - this.size; return that.count - this.count; } } static class snowMen { int[] balls; public snowMen(int[] balls) { this.balls = balls; Arrays.sort(balls); int tmp = balls[0]; balls[0] = balls[2]; balls[2] = tmp; } } }
Java
["7\n1 2 3 4 5 6 7", "3\n2 2 3"]
2 seconds
["2\n3 2 1\n6 5 4", "0"]
null
Java 6
standard input
[ "data structures", "binary search", "greedy" ]
551e66a4b3da71682652d84313adb8ab
The first line contains integer n (1 ≀ n ≀ 105) β€” the number of snowballs. The next line contains n integers β€” the balls' radii r1, r2, ..., rn (1 ≀ ri ≀ 109). The balls' radii can coincide.
1,800
Print on the first line a single number k β€” the maximum number of the snowmen. Next k lines should contain the snowmen's descriptions. The description of each snowman should consist of three space-separated numbers β€” the big ball's radius, the medium ball's radius and the small ball's radius. It is allowed to print the snowmen in any order. If there are several solutions, print any of them.
standard output
PASSED
54c5ea50def3cfff4f8a9b7eb1f52b6b
train_002.jsonl
1325689200
As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergey's twins help him: they've already made n snowballs with radii equal to r1, r2, ..., rn. To make a snowman, one needs any three snowballs whose radii are pairwise different. For example, the balls with radii 1, 2 and 3 can be used to make a snowman but 2, 2, 3 or 2, 2, 2 cannot. Help Sergey and his twins to determine what maximum number of snowmen they can make from those snowballs.
256 megabytes
import java.lang.*; import java.awt.geom.Line2D; import java.io.*; import java.util.*; import java.math.*; public class C implements Runnable{ class Val implements Comparable<Val> { int cnt, sz; public Val(int cnt, int sz) { this.cnt = cnt; this.sz = sz; } public int compareTo(Val a) { return (this.cnt==a.cnt)?(this.sz-a.sz):(this.cnt-a.cnt); } } public void run() { TreeSet<Val> k = new TreeSet<Val>(); TreeMap<Integer, Integer> r = new TreeMap<Integer, Integer>(); int n = nextInt(); for (int i = 0; i < n; ++i) { int cur = nextInt(); if (!r.containsKey(cur)) { r.put(cur, 0); } int tmp = r.get(cur); if (tmp > 0) { k.remove(new Val(tmp, cur)); } r.put(cur, tmp+1); k.add(new Val(tmp+1, cur)); } int ans = 0; ArrayList<Integer> list = new ArrayList<Integer>(); int[] szs = new int[3]; while(k.size() >= 3) { Val p1 = k.pollLast(); Val p2 = k.pollLast(); Val p3 = k.pollLast(); ++ans; szs[0] = p1.sz; szs[1] = p2.sz; szs[2] = p3.sz; Arrays.sort(szs); list.add(szs[2]); list.add(szs[1]); list.add(szs[0]); --p1.cnt; --p2.cnt; --p3.cnt; if (p1.cnt > 0) { k.add(p1); } if (p2.cnt > 0) { k.add(p2); } if (p3.cnt > 0) { k.add(p3); } } out.println(ans); for (int i = 0; i < list.size(); ++i) { out.print(list.get(i)); if ((i+1)%3 == 0) { out.println(); } else { out.print(" "); } } out.flush(); } private static BufferedReader br = null; private static PrintWriter out = null; private static StringTokenizer stk = null; public static void main(String[] args) { br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); (new Thread(new C())).start(); } private void loadLine() { try { stk = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } private String nextLine() { try { return br.readLine(); } catch (IOException e) { e.printStackTrace(); } return null; } private Integer nextInt() { while (stk==null||!stk.hasMoreTokens()) loadLine(); return Integer.parseInt(stk.nextToken()); } private Long nextLong() { while (stk==null||!stk.hasMoreTokens()) loadLine(); return Long.parseLong(stk.nextToken()); } private String nextWord() { while (stk==null||!stk.hasMoreTokens()) loadLine(); return (stk.nextToken()); } private Double nextDouble() { while (stk==null||!stk.hasMoreTokens()) loadLine(); return Double.parseDouble(stk.nextToken()); } }
Java
["7\n1 2 3 4 5 6 7", "3\n2 2 3"]
2 seconds
["2\n3 2 1\n6 5 4", "0"]
null
Java 6
standard input
[ "data structures", "binary search", "greedy" ]
551e66a4b3da71682652d84313adb8ab
The first line contains integer n (1 ≀ n ≀ 105) β€” the number of snowballs. The next line contains n integers β€” the balls' radii r1, r2, ..., rn (1 ≀ ri ≀ 109). The balls' radii can coincide.
1,800
Print on the first line a single number k β€” the maximum number of the snowmen. Next k lines should contain the snowmen's descriptions. The description of each snowman should consist of three space-separated numbers β€” the big ball's radius, the medium ball's radius and the small ball's radius. It is allowed to print the snowmen in any order. If there are several solutions, print any of them.
standard output
PASSED
808172288ebd5be364de84642a097f1d
train_002.jsonl
1325689200
As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergey's twins help him: they've already made n snowballs with radii equal to r1, r2, ..., rn. To make a snowman, one needs any three snowballs whose radii are pairwise different. For example, the balls with radii 1, 2 and 3 can be used to make a snowman but 2, 2, 3 or 2, 2, 2 cannot. Help Sergey and his twins to determine what maximum number of snowmen they can make from those snowballs.
256 megabytes
import java.util.List; import java.io.IOException; import java.util.Arrays; import java.util.PriorityQueue; import java.util.InputMismatchException; import java.util.ArrayList; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Writer; import java.math.BigInteger; 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; StreamInputReader in = new StreamInputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskC solver = new TaskC(); solver.solve(1, in, out); out.close(); } } class TaskC { public void solve(int testNumber, StreamInputReader in, OutputWriter out) { int n = in.readInt(); int[] r = IOUtils.readIntArray(in, n); Arrays.sort(r); int z = 0; int[] what = new int[n]; int[] count = new int[n]; what[z] = r[0]; ++count[z]; for (int i = 1; i < n; ++i) { if (r[i] != r[i - 1]) { ++z; what[z] = r[i]; } ++count[z]; } ++z; if (z < 3) { out.printLine(0); return; } PriorityQueue<Pair> pq = new PriorityQueue<Pair>(); for(int i = 0; i < z; ++i) { pq.add(new Pair(count[i], what[i])); } List<int[]> results = new ArrayList<int[]>(); while (pq.size() >= 3) { Pair[] p = new Pair[3]; int[] res = new int[3]; for(int i = 0; i < 3; ++i) { p[i] = pq.poll(); res[i] = p[i].second; --p[i].first; } for(int i = 0; i < 3; ++i) { if (p[i].first > 0) pq.add(p[i]); } Arrays.sort(res); results.add(res); } out.printLine(results.size()); for (int[] res : results) { out.printLine(res[2] + " " + res[1] + " " + res[0]); } } class Pair implements Comparable<Pair> { public int first, second; public Pair(int f, int s) { first = f; second = s; } public int compareTo(Pair o) { return o.first - first; } } } class StreamInputReader extends InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public StreamInputReader(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++]; } } class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(outputStream); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object...objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } public void printLine(Object...objects) { print(objects); writer.println(); } public void close() { writer.close(); } } abstract class InputReader { public abstract int read(); public int readInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } protected boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } } class IOUtils { public static int[] readIntArray(InputReader in, int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) array[i] = in.readInt(); return array; } }
Java
["7\n1 2 3 4 5 6 7", "3\n2 2 3"]
2 seconds
["2\n3 2 1\n6 5 4", "0"]
null
Java 6
standard input
[ "data structures", "binary search", "greedy" ]
551e66a4b3da71682652d84313adb8ab
The first line contains integer n (1 ≀ n ≀ 105) β€” the number of snowballs. The next line contains n integers β€” the balls' radii r1, r2, ..., rn (1 ≀ ri ≀ 109). The balls' radii can coincide.
1,800
Print on the first line a single number k β€” the maximum number of the snowmen. Next k lines should contain the snowmen's descriptions. The description of each snowman should consist of three space-separated numbers β€” the big ball's radius, the medium ball's radius and the small ball's radius. It is allowed to print the snowmen in any order. If there are several solutions, print any of them.
standard output
PASSED
2e944eddc7e66e154c72940980286bc1
train_002.jsonl
1408116600
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones.
256 megabytes
import java.util.Scanner; public class _459A { public static void main(String[] args) { Scanner s = new Scanner(System.in); int x1 = s.nextInt(), y1 = s.nextInt(), x2 = s.nextInt(), y2 = s.nextInt(); int dx = Math.abs(x1 - x2), dy = Math.abs(y1 - y2); if (x1 == x2) System.out.print((x1 + dy) + " " + y1 + " " + (x2 + dy) + " " + y2); else if (y1 == y2) System.out.print(x1 + " " + (y1 + dx) + " " + x2 + " " + (y2 + dx)); else if (dy == dx) System.out.print(x1 + " " + y2 + " " + x2 + " " + y1); else System.out.print(-1); } }
Java
["0 0 0 1", "0 0 1 1", "0 0 1 2"]
1 second
["1 0 1 1", "0 1 1 0", "-1"]
null
Java 8
standard input
[ "implementation" ]
71dea31e1244797f916adf5f526f776e
The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≀ x1, y1, x2, y2 ≀ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct.
1,200
If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≀ x3, y3, x4, y4 ≀ 1000).
standard output
PASSED
75d9024915fcc785d52976ad739e29f7
train_002.jsonl
1408116600
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner leer=new Scanner(System.in); while(leer.hasNext()) { int x1=leer.nextInt(); int y1=leer.nextInt(); int x2=leer.nextInt(); int y2=leer.nextInt(); int l=0; if(y1==y2) { if(x1>0 && x2<0 || x1<0 && x2>0) l=Math.abs(Math.abs(x2)+Math.abs(x1)); else l=Math.abs(Math.abs(x2)-Math.abs(x1)); System.out.println(x1+" "+(y1+l)+" "+x2+" "+(y2+l)); } else if(x1==x2) { if(y1>0 && y2<0 || y1<0 && y2>0) l=Math.abs(Math.abs(y2)+Math.abs(y1)); else l=Math.abs(Math.abs(y2)-Math.abs(y1)); System.out.println((x1+l)+" "+y1+" "+(x2+l)+" "+y2); } else { int a=Math.abs(y1-y2); int b=Math.abs(x1-x2); if(a!=b) System.out.println("-1"); else { if(x1<x2) System.out.println(x1+" "+y2+" "+x2+" "+y1); else System.out.println(x1+" "+y2+" "+x2+" "+y1); } } } } }
Java
["0 0 0 1", "0 0 1 1", "0 0 1 2"]
1 second
["1 0 1 1", "0 1 1 0", "-1"]
null
Java 8
standard input
[ "implementation" ]
71dea31e1244797f916adf5f526f776e
The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≀ x1, y1, x2, y2 ≀ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct.
1,200
If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≀ x3, y3, x4, y4 ≀ 1000).
standard output
PASSED
e46c07c9fa01d805c29cf091eee20b9d
train_002.jsonl
1408116600
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.FilterInputStream; import java.io.BufferedInputStream; import java.util.ArrayList; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Jenish */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; ScanReader in = new ScanReader(inputStream); PrintWriter out = new PrintWriter(outputStream); APashmakAndGarden solver = new APashmakAndGarden(); solver.solve(1, in, out); out.close(); } static class APashmakAndGarden { public void solve(int testNumber, ScanReader in, PrintWriter out) { int x1 = in.scanInt(); int y1 = in.scanInt(); int x2 = in.scanInt(); int y2 = in.scanInt(); int len = 0; if (x1 == x2) { len = Math.abs(y1 - y2); out.println((x1 + len) + " " + y1 + " " + (x2 + len) + " " + y2); } else if (y1 == y2) { len = Math.abs(x1 - x2); out.println(x1 + " " + (y1 + len) + " " + x2 + " " + (y2 + len)); } else { if (Math.abs(x1 - x2) == Math.abs(y1 - y2)) { len = Math.abs(x1 - x2); if (x1 > x2) { int t1 = x1; x1 = x2; x2 = t1; t1 = y1; y1 = y2; y2 = t1; } if (y1 > y2) { out.println((x1 + len) + " " + y1 + " " + (x1) + " " + (y1 - len)); } else { out.println((x1 + len) + " " + y1 + " " + (x1) + " " + (y1 + len)); } } else { out.println(-1); return; } } ArrayList<point> arrayList = new ArrayList<>(); arrayList.add(new point(x1, y1)); arrayList.add(new point(x2, y2)); } class point { int x; int y; public point(int x, int y) { this.x = x; this.y = y; } } } static class ScanReader { private byte[] buf = new byte[4 * 1024]; private int INDEX; private BufferedInputStream in; private int TOTAL; public ScanReader(InputStream inputStream) { in = new BufferedInputStream(inputStream); } private int scan() { if (INDEX >= TOTAL) { INDEX = 0; try { TOTAL = in.read(buf); } catch (Exception e) { e.printStackTrace(); } if (TOTAL <= 0) return -1; } return buf[INDEX++]; } public int scanInt() { int I = 0; int n = scan(); while (isWhiteSpace(n)) n = scan(); int neg = 1; if (n == '-') { neg = -1; n = scan(); } while (!isWhiteSpace(n)) { if (n >= '0' && n <= '9') { I *= 10; I += n - '0'; n = scan(); } } return neg * I; } private boolean isWhiteSpace(int n) { if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true; else return false; } } }
Java
["0 0 0 1", "0 0 1 1", "0 0 1 2"]
1 second
["1 0 1 1", "0 1 1 0", "-1"]
null
Java 8
standard input
[ "implementation" ]
71dea31e1244797f916adf5f526f776e
The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≀ x1, y1, x2, y2 ≀ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct.
1,200
If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≀ x3, y3, x4, y4 ≀ 1000).
standard output
PASSED
fd9955c5cc153ebde3d25b73e1fb8bc9
train_002.jsonl
1408116600
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones.
256 megabytes
import java.io.*; import java.util.*; import java.lang .*; public class Main{ public static void main(String args[]) { Scanner sc= new Scanner(System.in); int x1= sc.nextInt(); int y1= sc.nextInt(); int x2= sc.nextInt(); int y2= sc.nextInt(); int u=Math.abs(x1-y1); int v=Math.abs(x2-y2); int y3,y4,x3,x4; int z=Math.abs(x1-x2); int y=Math.abs(y1-y2); if(z>0 && y==0) { y3=y1+z; y4=y2+z; x3=x1; x4=x2; System.out.print(x3 +" "); System.out.print(y3 +" "); System.out.print(x4 +" "); System.out.print(y4 +" "); } else if(y>0 && z==0) { y3=y1; y4=y2; x3=x1+y; x4=x2+y; System.out.print(x3 +" "); System.out.print(y3 +" "); System.out.print(x4 +" "); System.out.print(y4 +" "); } else if(y==z) { if( y1<y2) { y4=y1+z; y3=y2-z; x3=x2; x4=x1; System.out.print(x3 +" "); System.out.print(y3 +" "); System.out.print(x4 +" "); System.out.print(y4 +" ");} else { y4=y2+z; y3=y1-z; x3=x1; x4=x2; System.out.print(x3 +" "); System.out.print(y3 +" "); System.out.print(x4 +" "); System.out.print(y4 +" "); } } else if(u==v) { if (y1==x2 && y2==x1) { y3=y2; y4=y1; x3=x1; x4=x2; System.out.print(x3 +" "); System.out.print(y3 +" "); System.out.print(x4 +" "); System.out.print(y4 +" "); } else { if( y1<y2) { y4=y2-z; y3=y1+z; x3=x1; x4=x2; System.out.print(x3 +" "); System.out.print(y3 +" "); System.out.print(x4 +" "); System.out.print(y4 +" ");} else { y4=y1-z; y3=y2+z; x3=x2; x4=x1; System.out.print(x3 +" "); System.out.print(y3 +" "); System.out.print(x4 +" "); System.out.print(y4 +" "); } } } else System.out.print("-1 "); }}
Java
["0 0 0 1", "0 0 1 1", "0 0 1 2"]
1 second
["1 0 1 1", "0 1 1 0", "-1"]
null
Java 8
standard input
[ "implementation" ]
71dea31e1244797f916adf5f526f776e
The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≀ x1, y1, x2, y2 ≀ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct.
1,200
If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≀ x3, y3, x4, y4 ≀ 1000).
standard output
PASSED
10d07d7778c03d5635d8af7b7ff3061c
train_002.jsonl
1408116600
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class One1 { public static void main(String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int[] p1 ={Integer.parseInt(st.nextToken()),Integer.parseInt(st.nextToken())}; int[] p2 ={Integer.parseInt(st.nextToken()),Integer.parseInt(st.nextToken())}; if((p1[0] != p2[0]) && (p1[1] != p2[1])) { if((Math.abs(p1[0]-p2[0]) != Math.abs(p1[1] - p2[1]))) { System.out.println(-1); return; } System.out.println(p1[0] +" " + p2[1]+ " " +p2[0] + " " + p1[1] ); return; } if(p1[0] == p2[0]) { int l = Math.abs(p1[1] - p2[1]); if(p1[0] + l > 1000) l*=-1; if(p1[0] + l < -1000) { System.out.println(-1); return; } System.out.println((p1[0] + l) + " " + p1[1] + " " + (p2[0] + l) + " " + p2[1]); } else { int l = Math.abs(p1[0] - p2[0]); if(p1[1]+l>1000) l*=-1; if(p1[1] + l < -1000) { System.out.println(-1); return; } System.out.println(p1[0] + " " + (p1[1]+l) + " " + p2[0] + " " + (p2[1]+l)); } } }
Java
["0 0 0 1", "0 0 1 1", "0 0 1 2"]
1 second
["1 0 1 1", "0 1 1 0", "-1"]
null
Java 8
standard input
[ "implementation" ]
71dea31e1244797f916adf5f526f776e
The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≀ x1, y1, x2, y2 ≀ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct.
1,200
If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≀ x3, y3, x4, y4 ≀ 1000).
standard output
PASSED
5e6a96cc9769ebdea5cdd560abe34611
train_002.jsonl
1408116600
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones.
256 megabytes
import org.omg.CORBA.MARSHAL; import java.util.Scanner; /** * Created by acer on 4/15/2017. */ public class Codeforces_459A { public static void main(String[] args){ Scanner p = new Scanner(System.in); String[] n = p.nextLine().split(" "); double x3 = 0,x4 = 0,y3 = 0,y4 = 0; int x1 = Integer.parseInt(n[0]); int y1 = Integer.parseInt(n[1]); int x2 = Integer.parseInt(n[2]); int y2 = Integer.parseInt(n[3]); double side; double distance = Math.sqrt(Math.pow(x2-x1,2) + Math.pow(y2-y1,2)); int intdistance = (int) Math.round(distance/Math.sqrt(2)); double dada = distance/Math.sqrt(2); if(dada-0.99999999999999 == (int) dada) dada = (int) Math.round(dada); if(dada-0.9999999999999996 == (int)dada){ dada = (int) Math.round(dada); } if(dada ==(int) Math.round(distance/Math.sqrt(2)) ){ side = dada; if(x2>x1){ x3 = x2-side; y3 = y2; x4 = x1+side; y4 = y1; if(Math.abs(x2-x3) != side || Math.abs(y3-y1) != side || Math.abs(x4-x1) != side || Math.abs(y2-y4) != side){ System.out.println(-1); System.exit(0); } }else if(x2<x1){ x3 = x2+side; y3 = y2; x4 = x1-side; y4 = y1; if(Math.abs(x2-x3) != side || Math.abs(y3-y1) != side || Math.abs(x1-x4) != side || Math.abs(y2-y4) != side){ System.out.println(-1); System.exit(0); } } }else if(x1 == x2){ side = y2-y1; x3 = x2+side; y3 = y2; x4 = x1+side; y4 = y1; }else if(y1 == y2){ side = x2-x1; x3 = x2; y3 = y2-side; x4 = x1; y4 = y1-side; }else{ System.out.println(-1); System.exit(0); } System.out.println((int) x3+" "+(int)y3+" "+(int)x4+" "+(int)y4); } }
Java
["0 0 0 1", "0 0 1 1", "0 0 1 2"]
1 second
["1 0 1 1", "0 1 1 0", "-1"]
null
Java 8
standard input
[ "implementation" ]
71dea31e1244797f916adf5f526f776e
The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≀ x1, y1, x2, y2 ≀ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct.
1,200
If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≀ x3, y3, x4, y4 ≀ 1000).
standard output
PASSED
41712ae51751b03530317cd587a45002
train_002.jsonl
1408116600
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class _11PashmakAndGarden { public static void main(String[] args) { FastInput input = new FastInput(); PrintWriter output = new PrintWriter(new PrintWriter(System.out)); int x1 = input.nextInt(), y1 = input.nextInt(), x2 = input.nextInt(), y2 = input.nextInt(); if (x1 - x2 != 0 && y1 == y2) { int distX = Math.max(x1, x2) - Math.min(x1, x2); output.println(x1 + " " + (distX + y1) + " " + x2 + " " + (distX + y2)); } else if (y1 - y2 != 0 && x1 == x2) { int distY = Math.max(y1, y2) - Math.min(y1, y2); output.println((distY + x1) + " " + y1 + " " + (distY + x2) + " " + y2); } else if (Math.abs(y1 - y2) == Math.abs(x1 - x2)) { output.println(x1 + " " + y2 + " " + x2 + " " + y1); } else { output.println(-1); } output.close(); } static class FastInput { BufferedReader br; StringTokenizer st; public FastInput() { 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
["0 0 0 1", "0 0 1 1", "0 0 1 2"]
1 second
["1 0 1 1", "0 1 1 0", "-1"]
null
Java 8
standard input
[ "implementation" ]
71dea31e1244797f916adf5f526f776e
The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≀ x1, y1, x2, y2 ≀ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct.
1,200
If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≀ x3, y3, x4, y4 ≀ 1000).
standard output
PASSED
677fcd87e804e1d0c4834bee311b10f6
train_002.jsonl
1408116600
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class _11PashmakAndGarden { public static void main(String[] args) { FastInput input = new FastInput(); PrintWriter output = new PrintWriter(new PrintWriter(System.out)); int x1 = input.nextInt(), y1 = input.nextInt(), x2 = input.nextInt(), y2 = input.nextInt(), distX = Math.max(x1, x2) - Math.min(x1, x2), distY = Math.max(y1, y2) - Math.min(y1, y2); if ((distX == 0 && distY != 0) || (distX != 0 && distY == 0)) { output.println((distY + x1) + " " + (distX + y1) + " " + (distY + x2) + " " + (distX + y2)); } else if (distX == distY) { output.println(x1 + " " + y2 + " " + x2 + " " + y1); } else { output.println(-1); } output.close(); } static class FastInput { BufferedReader br; StringTokenizer st; public FastInput() { 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()); } } }
Java
["0 0 0 1", "0 0 1 1", "0 0 1 2"]
1 second
["1 0 1 1", "0 1 1 0", "-1"]
null
Java 8
standard input
[ "implementation" ]
71dea31e1244797f916adf5f526f776e
The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≀ x1, y1, x2, y2 ≀ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct.
1,200
If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≀ x3, y3, x4, y4 ≀ 1000).
standard output
PASSED
0f79c3cdfdaa0e2709702e1996a968d5
train_002.jsonl
1408116600
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones.
256 megabytes
import java.util.*; public class CodeForces { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int x1=sc.nextInt(); int y1=sc.nextInt(); int x2=sc.nextInt(); int y2=sc.nextInt(); double distance=Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)); distance=(double)Math.round(distance * 100000d) / 100000d ; double check=Math.abs(x2-x1); double check1=Math.abs(y2-y1); double ans=(double)Math.round(check*Math.sqrt(2) * 100000d) / 100000d ; double ans1=(double)Math.round(check1*Math.sqrt(2) * 100000d) / 100000d ; if(check==distance) { int a=Math.max(x1,x2); int b=y1+(int)distance; int c=Math.min(x1,x2); int d=y1+(int)distance; System.out.print(a+" "+b+" "+c+" "+d); } else if(check1==distance) { int a=x1+(int)distance; int b=Math.max(y1,y2); int c=x1+(int)distance; int d=Math.min(y1,y2); System.out.print(a+" "+b+" "+c+" "+d); } else if(ans==distance&&ans1==distance) { if(x2>x1&&y2>y1) { System.out.print(x1+" "+y2+" "+x2+" "+y1); } else { System.out.print(x2+" "+y1+" "+x1+" "+y2); } } else { System.out.println("-1"); } } }
Java
["0 0 0 1", "0 0 1 1", "0 0 1 2"]
1 second
["1 0 1 1", "0 1 1 0", "-1"]
null
Java 8
standard input
[ "implementation" ]
71dea31e1244797f916adf5f526f776e
The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≀ x1, y1, x2, y2 ≀ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct.
1,200
If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≀ x3, y3, x4, y4 ≀ 1000).
standard output
PASSED
11055ae6dae7b5b097954cea8efa2e7e
train_002.jsonl
1408116600
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones.
256 megabytes
import java.util.*; import java.io.*; public class Codechef { public static void main(String [] args) { Scanner s=new Scanner(System.in); //int T=s.nextInt(); int T=1; while(T-->0) { int x1=s.nextInt(); int y1=s.nextInt(); int x2=s.nextInt(); int y2=s.nextInt(); int a=Math.max(Math.abs(x2-x1),Math.abs(y2-y1)),x4=0,y4=0,x3=0,y3=0; if(x2-x1==0&&Math.abs(y2-y1)==a) { int y=Math.min(y1,y2); x3=x1+a; y3=y; x4=x1+a; y4=y+a; System.out.println(x3+" "+y3+" "+x4+" "+y4); }else if(y2-y1==0&&Math.abs(x2-x1)==a) { int x=Math.min(x1,x2); x3=x; y3=y1+a; x4=x+a; y4=y1+a; System.out.println(x3+" "+y3+" "+x4+" "+y4); }else if(Math.abs(x2-x1)==a&&Math.abs(y2-y1)==a) { if((x2>x1&&y2>y1)||(x2<x1&&y2<y1)) { int x=Math.min(x1,x2); int y=Math.min(y1,y2); x3=x; y3=y+a; x4=x+a; y4=y; System.out.println(x3+" "+y3+" "+x4+" "+y4); }else { int x=Math.min(x1,x2); int y=Math.min(y1,y2); x3=x; y3=y; x4=x3+a; y4=y3+a; System.out.println(x3+" "+y3+" "+x4+" "+y4); } }else System.out.println(-1); } } }
Java
["0 0 0 1", "0 0 1 1", "0 0 1 2"]
1 second
["1 0 1 1", "0 1 1 0", "-1"]
null
Java 8
standard input
[ "implementation" ]
71dea31e1244797f916adf5f526f776e
The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≀ x1, y1, x2, y2 ≀ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct.
1,200
If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≀ x3, y3, x4, y4 ≀ 1000).
standard output
PASSED
c2598b870e250de8693606f99e852928
train_002.jsonl
1408116600
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class Trees { public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); StringTokenizer st = new StringTokenizer(br.readLine()); int x1=Integer.parseInt(st.nextToken()); int y1=Integer.parseInt(st.nextToken()); int x2=Integer.parseInt(st.nextToken()); int y2=Integer.parseInt(st.nextToken()); int x3=0; int x4=0; int y3=0; int y4=0; StringBuilder sb= new StringBuilder(); if (x1==0&&x2==0&&y1==0&&y2==0) {sb.append(x1); sb.append(" "+x2); sb.append(" "+x2); sb.append(" "+x2);} else { int dx=Math.abs(x1-x2); int dy=Math.abs(y1-y2); if(dx!=0&&dy!=0&&dx!=dy) sb.append("-1"); else { int d = Math.max(dx, dy); if(y1==y2) { x3=x1; x4=x2; y3=(y1-d); y4=(y2-d);} else { if (x1==x2) { x3=(x1+d); x4=(x2+d); y3=y1; y4=y2;} else { if(x2>x1 &&y2>y1) {x3=(x2); x4=(x1); y3=y1; y4=y2;} else {x3=x1; x4=(x2); y3=y2; y4=y1;} } } sb.append(x3); sb.append(" "+y3); sb.append(" "+x4); sb.append(" "+y4); } } pw.println(sb); pw.close(); }}
Java
["0 0 0 1", "0 0 1 1", "0 0 1 2"]
1 second
["1 0 1 1", "0 1 1 0", "-1"]
null
Java 8
standard input
[ "implementation" ]
71dea31e1244797f916adf5f526f776e
The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≀ x1, y1, x2, y2 ≀ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct.
1,200
If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≀ x3, y3, x4, y4 ≀ 1000).
standard output
PASSED
ed6e8168b790fd1f706c3a08fa8b9324
train_002.jsonl
1408116600
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones.
256 megabytes
import java.util.Scanner; public class Garden{ public static void main(String arg[]){ Scanner sc=new Scanner(System.in); int x1=sc.nextInt(); int y1=sc.nextInt(); int x2=sc.nextInt(); int y2=sc.nextInt(); if(x1!=x2 && y1!=y2 && Math.abs(x2-x1)!=Math.abs(y2-y1))System.out.println("-1"); else if(x1==x2){ System.out.println(x1+Math.abs(y2-y1)+" "+y1+" "+(x2+Math.abs(y2-y1))+" "+y2); } else if(y1==y2){ System.out.println(x1+" "+(y1+Math.abs(x2-x1))+" "+x2+" "+(y2+Math.abs(x2-x1))); } else System.out.println(x2+" "+y1+" "+x1+" "+y2); } }
Java
["0 0 0 1", "0 0 1 1", "0 0 1 2"]
1 second
["1 0 1 1", "0 1 1 0", "-1"]
null
Java 8
standard input
[ "implementation" ]
71dea31e1244797f916adf5f526f776e
The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≀ x1, y1, x2, y2 ≀ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct.
1,200
If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≀ x3, y3, x4, y4 ≀ 1000).
standard output
PASSED
27e9424a13bcfd9794d0d54062cb82fd
train_002.jsonl
1408116600
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones.
256 megabytes
import java.util.Scanner; public class cheaptravel { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc=new Scanner(System.in); int x1=sc.nextInt(); int y1=sc.nextInt(); int x2=sc.nextInt(); int y2=sc.nextInt(); if(x1==x2) { int l=y2-y1; int x3=l+x1; System.out.println(x3+" "+y2+" "+x3+" "+y1); } else if(y1==y2) { int l=x2-x1; int y3=y1+l; System.out.println(x1+" "+y3+" "+x2+" "+y3); } else { if(Math.abs(x2-x1)==Math.abs(y2-y1)) { System.out.println(x1+" "+y2+" "+x2+" "+y1); } else System.out.println(-1); } } }
Java
["0 0 0 1", "0 0 1 1", "0 0 1 2"]
1 second
["1 0 1 1", "0 1 1 0", "-1"]
null
Java 8
standard input
[ "implementation" ]
71dea31e1244797f916adf5f526f776e
The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≀ x1, y1, x2, y2 ≀ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct.
1,200
If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≀ x3, y3, x4, y4 ≀ 1000).
standard output
PASSED
dd9da580d76190f935fae779ac291d12
train_002.jsonl
1408116600
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones.
256 megabytes
import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; import java.math.BigInteger; /** * * @author T M Mohamad Mabrouk */ public class PashmakAndGarden { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here ArrayList<String> aa = new ArrayList<String>(); ArrayList<Integer> bb = new ArrayList<Integer>(); ArrayList<Integer> T = new ArrayList<Integer>(); ArrayList<Integer> T2 = new ArrayList<Integer>(); Scanner input = new Scanner(System.in); char n = ' '; int count=0; String gg=input.nextLine(); //-------------------------------------------- for(int i=0;i<4;i++){ String h = ""; while (count < gg.length() && gg.charAt(count) != n) { h += gg.charAt(count); //h += gg.charAt(count); count++; } aa.add(h); if (count < gg.length() && gg.charAt(count) == n) { count++; } } for(int i=0;i<aa.size();i++) { bb.add(Integer.parseInt(aa.get(i))); } aa.clear(); //-------------------------------------------------- if(bb.get(0)==bb.get(2)&&bb.get(1)!=bb.get(3)) { String ff=""; ff=(bb.get(0)+(bb.get(3)-bb.get(1)))+" "+bb.get(1)+" "+(bb.get(2)+(bb.get(3)-bb.get(1)))+" "+bb.get(3); aa.add(ff); for(int i=0;i<aa.size();i++){ System.out.println(aa.get(i)); } } //-------------------------------------------------------------------------- if(bb.get(0)!=bb.get(2)&&bb.get(1)==bb.get(3)){ String ff=""; ff=bb.get(0)+" "+(bb.get(1)+(bb.get(2)-bb.get(0)))+" "+bb.get(2)+" "+(bb.get(3)+(bb.get(2)-bb.get(0))); aa.add(ff); for(int i=0;i<aa.size();i++){ System.out.println(aa.get(i)); } } //--------------------------------------------------------------------------- if(bb.get(0)!=bb.get(2)&&bb.get(1)!=bb.get(3)) { if(Math.abs(bb.get(2)-bb.get(0))==Math.abs(bb.get(3)-bb.get(1))){ int b=(bb.get(2)-bb.get(0)); int b2=(bb.get(3)-bb.get(1)); String ff=""; if(bb.get(0)<0&&bb.get(1)>=0){ ff=bb.get(0)+" "+(bb.get(1)+b2)+" "+(bb.get(0)+b)+" "+bb.get(1); } if(bb.get(0)<0&&bb.get(1)<0){ ff=bb.get(0)+" "+(bb.get(1)+b2)+" "+(bb.get(0)+b)+" "+bb.get(1); } if(bb.get(0)>=0&&bb.get(1)<0){ ff=bb.get(0)+" "+(bb.get(1)+b2)+" "+(bb.get(0)+b)+" "+bb.get(1); } if(bb.get(0)>=0&&bb.get(1)>=0){ ff=bb.get(0)+" "+(bb.get(1)+b2)+" "+(bb.get(0)+b)+" "+bb.get(1); } aa.add(ff); for(int i=0;i<aa.size();i++){ System.out.println(aa.get(i)); } } else{ System.out.println("-1"); } } } }
Java
["0 0 0 1", "0 0 1 1", "0 0 1 2"]
1 second
["1 0 1 1", "0 1 1 0", "-1"]
null
Java 8
standard input
[ "implementation" ]
71dea31e1244797f916adf5f526f776e
The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≀ x1, y1, x2, y2 ≀ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct.
1,200
If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≀ x3, y3, x4, y4 ≀ 1000).
standard output
PASSED
13593e8a0b7c4279b5c6a1d8d7e19031
train_002.jsonl
1408116600
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones.
256 megabytes
import java.util.Scanner; public class PashmakandGarden { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int x1 = sc.nextInt(); int y1 = sc.nextInt(); int x2 = sc.nextInt(); int y2 = sc.nextInt(); boolean error = false; int error1 = -1; int x3 = 0; int y3 = 0; int x4 = 0; int y4 = 0; if (x1==x2){ if (y1 == y2) error = true; else if (x1==y1){ x3 = y2; x4 = y2; y3 = x1; y4 = y2; } else if (x2==y2){ x3 = y1; x4 = y1; y3 = x1; y4 = y1; } else{ x3 = y1+x1-y2 ; x4 = x3; y3 = y1; y4 = y2; } } else{ if (x1 ==y1 && x2 == y2){ x3 = x1; y3 = y2; x4 = x2; y4 = y1; } else if (y1==x2 && x2==y2 ){ x3 = y1; y3 = x1; x4 = x1; y4 = x1; } else if (y1==x1 && x1==y2){ x3 = x2; y3 = x2; x4 = y1; y4 = x2; } else if (x1==y2 && x2==y1){ x3 = x1; y3 = x1; x4 = x2; y4 = x2; } else if (y1 == y2){ x3 = x1; x4 = x2; y3 = x2-x1+y1; y4 = y3; } else if (y2-y1==x2-x1 || x1-x2==y2-y1){ x3 =x1; y3 = y2; x4 = x2; y4 = y1; } else error = true; } if (error) System.out.print(error1); else System.out.print(x3 + " " + y3 + " " + x4 + " " + y4 + " "); } }
Java
["0 0 0 1", "0 0 1 1", "0 0 1 2"]
1 second
["1 0 1 1", "0 1 1 0", "-1"]
null
Java 8
standard input
[ "implementation" ]
71dea31e1244797f916adf5f526f776e
The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≀ x1, y1, x2, y2 ≀ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct.
1,200
If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≀ x3, y3, x4, y4 ≀ 1000).
standard output
PASSED
62dd05967c0018621fa9acf400ef237e
train_002.jsonl
1408116600
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class PashmakAndGarden { static class FastReader { BufferedReader reader; StringTokenizer tokenizer; public FastReader() { reader = new BufferedReader(new InputStreamReader(System.in)); } String next() { while(tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch(IOException e) { e.printStackTrace(); } } return tokenizer.nextToken(); } int nextInt() { return Integer.parseInt(next()); } } public static void main(String[] args) { FastReader fr = new FastReader(); int x1 = fr.nextInt(); int y1 = fr.nextInt(); int x2 = fr.nextInt(); int y2 = fr.nextInt(); int side, x3, y3, x4, y4; if(x1==x2) { side = Math.abs(y2-y1); x3 = x1+side; y3 = y1; x4 = x3; y4 = y2; } else if(y1==y2) { side = Math.abs(x2-x1); x3 = x2; y3 = y2+side; x4 = x1; y4 = y3; } else if(x1!=x2 && y1!=y2 && Math.abs(x1-x2)!=Math.abs(y1-y2)){ System.out.println(-1); return; } else { x3 = x2; y3 = y1; x4 = x1; y4 = y2; } System.out.println(x3 + " " + y3 + " " + x4 + " " + y4); } }
Java
["0 0 0 1", "0 0 1 1", "0 0 1 2"]
1 second
["1 0 1 1", "0 1 1 0", "-1"]
null
Java 8
standard input
[ "implementation" ]
71dea31e1244797f916adf5f526f776e
The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≀ x1, y1, x2, y2 ≀ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct.
1,200
If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≀ x3, y3, x4, y4 ≀ 1000).
standard output
PASSED
4ec6f6191c159c95155e11b7c5c6224c
train_002.jsonl
1408116600
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int x1=sc.nextInt(); int y1=sc.nextInt(); int x2=sc.nextInt(); int y2=sc.nextInt(); if((x1)==(x2)||(y1)==(y2)){ if((x1)==(x2)){ System.out.println((x1+(y2-y1))+" "+y1+" "+(x2+(y2-y1))+" "+(y2)); } else if((y1)==(y2)){ System.out.println(x1+" "+(y1+(x2-x1))+" "+(x2)+" "+(y2+(x2-x1))); } } else{if((Math.max((x2),(x1))-Math.min((x2),(x1)))!=(Math.max((y2),(y1))-Math.min((y2),(y1)))){System.out.println("-1");} else{ //y1++ //y2-- System.out.println(x1+" "+y2+" "+x2+" "+y1); } } } }
Java
["0 0 0 1", "0 0 1 1", "0 0 1 2"]
1 second
["1 0 1 1", "0 1 1 0", "-1"]
null
Java 8
standard input
[ "implementation" ]
71dea31e1244797f916adf5f526f776e
The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≀ x1, y1, x2, y2 ≀ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct.
1,200
If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≀ x3, y3, x4, y4 ≀ 1000).
standard output
PASSED
43469230fa3e4bb4addd7ce66aebdc45
train_002.jsonl
1408116600
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones.
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; public class PashmakGarden { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a,a1,b,b1,c,c1,d,d1,dis; a=sc.nextInt(); b=sc.nextInt(); c=sc.nextInt(); d=sc.nextInt(); if(a==c&&b==d) System.out.println(-1); else if(a==c||b==d) { if(a==c) { dis=(int)Math.sqrt((d-b)*(d-b)); if(b>d) {if(a<a+dis) System.out.println((a+dis)+" "+b+" "+" "+(c+dis)+" "+d); else System.out.println((a-dis)+" "+b+" "+" "+(c-dis)+" "+d); } else { if(a<a+dis) System.out.println((a-dis)+" "+b+" "+" "+(c-dis)+" "+d); else System.out.println((a+dis)+" "+b+" "+" "+(c+dis)+" "+d); } } else if(b==d) { dis=(int)Math.sqrt((c-a)*(c-a)); if(a>c) { if(b<b+dis) System.out.println(a+" "+(b+dis)+" "+" "+c+" "+(d+dis)); else System.out.println(a+" "+(b-dis)+" "+" "+c+" "+(d-dis)); } else { if(b<b+dis) System.out.println(a+" "+(b+dis)+" "+" "+c+" "+(d+dis)); else System.out.println(a+" "+(b-dis)+" "+" "+c+" "+(d-dis)); } } } else if((c-a)==(d-b)||(c-a)==-(d-b)) { System.out.println(a+" "+d+" "+c+" "+b); } else System.out.println(-1); } }
Java
["0 0 0 1", "0 0 1 1", "0 0 1 2"]
1 second
["1 0 1 1", "0 1 1 0", "-1"]
null
Java 8
standard input
[ "implementation" ]
71dea31e1244797f916adf5f526f776e
The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≀ x1, y1, x2, y2 ≀ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct.
1,200
If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≀ x3, y3, x4, y4 ≀ 1000).
standard output
PASSED
9125c3faf3cb16e742635748a9b190a2
train_002.jsonl
1408116600
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones.
256 megabytes
/*BY:-PRASANG*/ import java.util.Scanner; public class PashmakAndGarden { public static void main(String[] ar) { int value[]=new int[4]; int c=0,temp=0; Scanner sc=new Scanner(System.in); for(int i=0;i<4;i++) value[i]=sc.nextInt(); if(value[0]==value[2]) { if(value[3]>value[1]) c=value[3]-value[1]; if(value[1]>value[3]) c=value[1]-value[3]; value[0]=value[0]-c; value[2]=value[2]-c; for(int i=0;i<4;i++) System.out.println(value[i]); } else if(value[1]==value[3]) { if(value[0]>value[2]) c=value[0]-value[2]; if(value[0]<value[2]) c=value[2]-value[0]; value[1]=value[1]-c; value[3]=value[3]-c; for(int i=0;i<4;i++) System.out.println(value[i]); } else { if(Math.abs(value[2]-value[0])==Math.abs(value[3]-value[1])) { temp=value[1]; value[1]=value[3]; value[3]=temp; for(int i=0;i<4;i++) System.out.println(value[i]); } else System.out.println(-1); } } }
Java
["0 0 0 1", "0 0 1 1", "0 0 1 2"]
1 second
["1 0 1 1", "0 1 1 0", "-1"]
null
Java 8
standard input
[ "implementation" ]
71dea31e1244797f916adf5f526f776e
The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≀ x1, y1, x2, y2 ≀ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct.
1,200
If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≀ x3, y3, x4, y4 ≀ 1000).
standard output
PASSED
128db73b52b4b61aaa633ca088db6882
train_002.jsonl
1592921100
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
256 megabytes
import java.util.Scanner; public class CF_652_Div2_A { private CF_652_Div2_A() { Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); for (int i = 0; i < t; i++) { long n = scanner.nextLong(); System.out.println((n & 3) == 0 ? "YES" : "NO"); } } public static void main(String[] args) { new CF_652_Div2_A(); } }
Java
["4\n3\n4\n12\n1000000000"]
2 seconds
["NO\nYES\nYES\nYES"]
NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.
Java 8
standard input
[ "geometry", "math" ]
07e56d4031bcb119d2f684203f7ed133
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.
800
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
standard output
PASSED
9792e5ccda83d095789bb6bd65c30ec9
train_002.jsonl
1592921100
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
256 megabytes
import java.util.LinkedList; import java.util.Scanner; public class Exmple { public static void main(String[] args) { //LinkedList<E> Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); if(n%4==0)System.out.println("YES"); else System.out.println("NO"); } } } class Links{ Node head; void add(int data) { Node toAdd=new Node(data); if(isEmpty()) { head.next=toAdd; return;} Node temp=head; while(temp.next!=null) { temp=temp.next; } temp.next=toAdd; } public Links() { head=new Node(); // TODO Auto-generated constructor stub } boolean isEmpty() { if(head==null)return true; return false; } void print() { Node temp=head.next; while(temp!=null) { System.out.print(temp.data+" "); temp=temp.next; } } int get(int pos) {//67 6 7 int i=0; Node temp=head.next; while(i<pos&&temp!=null) { i++; temp=temp.next; } if(i==pos)return temp.data; return -1; } //System.out.println(temp.data+" "); static class Node{ int data; Node next; public Node(int data) { this.data=data; next=null; // TODO Auto-generated constructor stub } public Node() { // TODO Auto-generated constructor stub } } }
Java
["4\n3\n4\n12\n1000000000"]
2 seconds
["NO\nYES\nYES\nYES"]
NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.
Java 8
standard input
[ "geometry", "math" ]
07e56d4031bcb119d2f684203f7ed133
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.
800
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
standard output
PASSED
c77f9fe73b4f185385282ab23338f6d2
train_002.jsonl
1592921100
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
256 megabytes
import java.util.Scanner; public class FashionabLee { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); while (t-- > 0) { System.out.println(in.nextInt() % 4 == 0 ? "YES" : "NO"); } in.close(); } }
Java
["4\n3\n4\n12\n1000000000"]
2 seconds
["NO\nYES\nYES\nYES"]
NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.
Java 8
standard input
[ "geometry", "math" ]
07e56d4031bcb119d2f684203f7ed133
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.
800
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
standard output
PASSED
41a2111f863db3bcafba6d355c3aac04
train_002.jsonl
1592921100
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
256 megabytes
import java.util.Scanner; public class Div2 { public static void main(String[] args) { Scanner in=new Scanner (System.in); int t=in.nextInt(); for (int i = 0; i < t; i++) { int n=in.nextInt(); if(n%2==0){ if((n/2)%2==0) System.out.println("YES"); else System.out.println("NO"); } else System.out.println("NO"); } } }
Java
["4\n3\n4\n12\n1000000000"]
2 seconds
["NO\nYES\nYES\nYES"]
NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.
Java 8
standard input
[ "geometry", "math" ]
07e56d4031bcb119d2f684203f7ed133
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.
800
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
standard output
PASSED
119d505d53d8603f406f79388df03538
train_002.jsonl
1592921100
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
256 megabytes
import java.io.PrintWriter; import java.util.LinkedList; import java.util.List; import java.util.Random; import java.util.Scanner; public class TaskA { static Scanner in = new Scanner(System.in); static PrintWriter w = new PrintWriter(System.out); public static void main(String[] args) { int t = Integer.parseInt(in.nextLine()); outer: while (t-- > 0) { int i = in.nextInt(); w.println(i%4==0 ? "YES" : "NO"); } w.flush(); w.close(); } private static int solve(int n) { for (int i = 3; i <= n / 2; i += 2) { if (n % i == 0) return n / i; } return -1; } private static void shuffleArray(int[] arr) { int n = arr.length; Random rnd = new Random(); for (int i = 0; i < n; ++i) { int tmp = arr[i]; int randomPos = rnd.nextInt(n); arr[i] = arr[randomPos]; arr[randomPos] = tmp; } } private static void shuffleArray(long[] arr) { int n = arr.length; Random rnd = new Random(); for (int i = 0; i < n; ++i) { long tmp = arr[i]; int randomPos = i + rnd.nextInt(n - i); arr[i] = arr[randomPos]; arr[randomPos] = tmp; } } }
Java
["4\n3\n4\n12\n1000000000"]
2 seconds
["NO\nYES\nYES\nYES"]
NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.
Java 8
standard input
[ "geometry", "math" ]
07e56d4031bcb119d2f684203f7ed133
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.
800
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
standard output
PASSED
3bba756bc80c85e1b2dea0219f68a019
train_002.jsonl
1592921100
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
256 megabytes
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.lang.reflect.Array; import java.math.BigInteger; import java.util.*; public class Codeforces{ void pre() throws Exception{} void solve(int TC) throws Exception{ int t=ni(); while(t--!=0) { int n=ni(); if(n%4!=0)pn("NO"); else pn("YES"); } } static boolean isPrime(int n) { // Corner cases if (n <= 1) return false; if (n <= 3) return true; // This is checked so that we can skip // middle five numbers in below loop if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } // class TrieNode{ // TrieNode[] children=new TrieNode[26]; // boolean isEnd; // TrieNode() { // isEnd=false; // for(int i=0;i<26;i++) // children[i]=null; // } // } // // static TrieNode root; // // void insert(String s) { // TrieNode pCrawl=root; // int index=0; // int len=s.length(); // for(int i=0;i<len;i++) { // index=s.charAt(i)-'a'; // if(pCrawl.children[index]!=null) // pCrawl.children[index]=new TrieNode(); // pCrawl = pCrawl.children[index]; // // } // pCrawl.isEnd= true; // // } static boolean multipleTC = false, memory = false; FastReader in;PrintWriter out; void run() throws Exception{ in = new FastReader(); out = new PrintWriter(System.out); int T = (multipleTC)?ni():1; pre();for(int t = 1; t<= T; t++)solve(t); out.flush(); out.close(); } public static void main(String[] args) throws Exception{ if(memory)new Thread(null, new Runnable() {public void run(){try{new Codeforces().run();}catch(Exception e){e.printStackTrace();}}}, "1", 1 << 28).start(); else new Codeforces().run(); } void p(Object o){out.print(o);} void pn(Object o){out.println(o);} void nd(Object o){out.println(o);} void pni(Object o){out.println(o);out.flush();} String n()throws Exception{return in.next();} String nln()throws Exception{return in.nextLine();} int ni()throws Exception{return Integer.parseInt(in.next());} long nl()throws Exception{return Long.parseLong(in.next());} double nd()throws Exception{return Double.parseDouble(in.next());} class FastReader{ BufferedReader br; StringTokenizer st; public FastReader(){ br = new BufferedReader(new InputStreamReader(System.in)); } public FastReader(String s) throws Exception{ br = new BufferedReader(new FileReader(s)); } String next() throws Exception{ while (st == null || !st.hasMoreElements()){ try{ st = new StringTokenizer(br.readLine()); }catch (IOException e){ throw new Exception(e.toString()); } } return st.nextToken(); } String nextLine() throws Exception{ String str = ""; try{ str = br.readLine(); }catch (IOException e){ throw new Exception(e.toString()); } return str; } } }
Java
["4\n3\n4\n12\n1000000000"]
2 seconds
["NO\nYES\nYES\nYES"]
NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.
Java 8
standard input
[ "geometry", "math" ]
07e56d4031bcb119d2f684203f7ed133
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.
800
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
standard output
PASSED
9cb0b26e26a3d80063deb779dd7e49bb
train_002.jsonl
1592921100
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
256 megabytes
import java.io.*; import java.util.*; public class Main { static Scanner scan = new Scanner(System.in); public static void solve() throws Exception { //BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); //StringTokenizer tk = new StringTokenizer(in.readLine()); int n = scan.nextInt(); if(n%4==0) System.out.println("YES"); else System.out.println("NO"); } public static void main(String[] args) throws Exception { if(scan.hasNext()) { int t= scan.nextInt(); //int t= 1; while(t-->0) { solve(); } } } }
Java
["4\n3\n4\n12\n1000000000"]
2 seconds
["NO\nYES\nYES\nYES"]
NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.
Java 8
standard input
[ "geometry", "math" ]
07e56d4031bcb119d2f684203f7ed133
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.
800
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
standard output
PASSED
1e6171153a6834c7aca1df55520817cd
train_002.jsonl
1592921100
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
256 megabytes
import java.util.*; import java.lang.*; import java.math.*; import java.text.*; import java.io.*; public final class Solution { static PrintWriter out = new PrintWriter(System.out); static void flush() { out.flush(); } static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } static boolean isPalindrome(String str1, String str2) { String str3 = str1+str2; int i = 0, j = str3.length()-1; while(i < j) { char a = str3.charAt(i), b = str3.charAt(j); if(a != b) return false; i++;j--; } return true; } static boolean isPalindrome(String str) { int i = 0, j = str.length()-1; while(i < j) { char a = str.charAt(i), b = str.charAt(j); if(a != b) return false; i++;j--; } return true; } 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());} static int fact(int n) { if(n == 1) return 1; return n * fact(n-1); } public int[] readIntArray(int n) { int[] arr = new int[n]; for(int i=0; i<n; ++i) arr[i]=nextInt(); return arr; } public int[][] readIntArray(int m, int n){ int[][] arr = new int[m][n]; for(int i = 0;i<m;i++) for(int j = 0;j<n;j++) arr[i][j] = nextInt(); return arr; } public String[] readStringArray(int n) { String[] arr = new String[n]; for(int i=0; i<n; ++i) arr[i]= nextLine(); return arr; } double nextDouble() {return Double.parseDouble(next());} String nextLine() { String str = ""; try{str = br.readLine();} catch (IOException e) {e.printStackTrace();} return str;} } static int solve(int n) { if(n%2 == 1) { return(n-1)/2; } return n/2; } public static void main(String args[]) throws Exception { FastReader sc = new FastReader(); long start = System.currentTimeMillis(); int t = sc.nextInt(); while(t-- > 0) { int n = sc.nextInt(); int x = n - 4; if(n > 3 && x%4 == 0) { out.println("YES"); } else { out.println("NO"); } } flush(); long end = System.currentTimeMillis(); NumberFormat formatter = new DecimalFormat("#0.00000"); //System.out.print("Execution time is " + formatter.format((end - start) / 1000d) + " seconds"); } }
Java
["4\n3\n4\n12\n1000000000"]
2 seconds
["NO\nYES\nYES\nYES"]
NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.
Java 8
standard input
[ "geometry", "math" ]
07e56d4031bcb119d2f684203f7ed133
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.
800
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
standard output
PASSED
8a38f77cc0b42ace87a5f627fac64e48
train_002.jsonl
1592921100
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { int t,n; Scanner in=new Scanner(System.in); t=in.nextInt(); while(t!=0){ n=in.nextInt(); if(n % 4 == 0){ System.out.println("YES"); } else{ System.out.println("NO"); } t--; } } }
Java
["4\n3\n4\n12\n1000000000"]
2 seconds
["NO\nYES\nYES\nYES"]
NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.
Java 8
standard input
[ "geometry", "math" ]
07e56d4031bcb119d2f684203f7ed133
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.
800
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
standard output
PASSED
db52d013c14802cd13141eae984dad75
train_002.jsonl
1592921100
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { int t,n; Scanner in=new Scanner(System.in); t=in.nextInt(); while(t!=0){ n=in.nextInt(); if(n % 4 == 0){ System.out.println("YES"); } else{ System.out.println("NO"); } t--; } } }
Java
["4\n3\n4\n12\n1000000000"]
2 seconds
["NO\nYES\nYES\nYES"]
NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.
Java 8
standard input
[ "geometry", "math" ]
07e56d4031bcb119d2f684203f7ed133
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.
800
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
standard output
PASSED
c062199719d2eff01d8fab90682bcea6
train_002.jsonl
1592921100
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
256 megabytes
import java.util.Scanner; public class A652 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner obj=new Scanner(System.in); int t=obj.nextInt(); while(t-->0) { long n=obj.nextLong(); if(n%4==0) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["4\n3\n4\n12\n1000000000"]
2 seconds
["NO\nYES\nYES\nYES"]
NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.
Java 8
standard input
[ "geometry", "math" ]
07e56d4031bcb119d2f684203f7ed133
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.
800
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
standard output
PASSED
15a41524821bbaaa05b3b1c038d308bc
train_002.jsonl
1592921100
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
256 megabytes
import java.util.*; import java.io.*; public class Main{ public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { int sides = sc.nextInt(); if(sides%4==0) { System.out.println("YES"); } else { System.out.println("NO"); } } } }
Java
["4\n3\n4\n12\n1000000000"]
2 seconds
["NO\nYES\nYES\nYES"]
NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.
Java 8
standard input
[ "geometry", "math" ]
07e56d4031bcb119d2f684203f7ed133
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.
800
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
standard output
PASSED
c84b7e5505b1cb759eefd6b82a7a1b9e
train_002.jsonl
1592921100
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
256 megabytes
import java.util.*; public class cdf652div2problemA { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); Queue<Integer> q = new LinkedList<Integer>(); for(int i=0;i<t;i++) if(sc.hasNext()) q.add(sc.nextInt()); while(!q.isEmpty()) { int a = q.remove(); if(a%4==0) System.out.println("YES"); else System.out.println("NO"); } sc.close(); } }
Java
["4\n3\n4\n12\n1000000000"]
2 seconds
["NO\nYES\nYES\nYES"]
NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.
Java 8
standard input
[ "geometry", "math" ]
07e56d4031bcb119d2f684203f7ed133
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.
800
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
standard output
PASSED
b1ed47626599c1c5af2ea201cec7388e
train_002.jsonl
1592921100
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
256 megabytes
import java.io.*; import java.math.*; import java.util.*; public class R652Q1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); int T = input.nextInt(); for (int i = 1; i <= T; i++) { int N = input.nextInt(); if (N%2==0) N/=2; System.out.println(N%2==0?"YES":"NO"); } } }
Java
["4\n3\n4\n12\n1000000000"]
2 seconds
["NO\nYES\nYES\nYES"]
NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.
Java 8
standard input
[ "geometry", "math" ]
07e56d4031bcb119d2f684203f7ed133
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.
800
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
standard output
PASSED
5c035f33a1b9858a3b5b2ed85cc23384
train_002.jsonl
1592921100
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Scanner; /** * Built using CHelper plug-in * Actual solution is at the top * * @author booooooo */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); int testCount = Integer.parseInt(in.next()); for (int i = 1; i <= testCount; i++) solver.solve(i, in, out); out.close(); } static class TaskA { public void solve(int testNumber, Scanner in, PrintWriter out) { int n = in.nextInt(); if (n % 4 == 0) out.println("YES"); else out.println("NO"); } } }
Java
["4\n3\n4\n12\n1000000000"]
2 seconds
["NO\nYES\nYES\nYES"]
NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.
Java 8
standard input
[ "geometry", "math" ]
07e56d4031bcb119d2f684203f7ed133
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.
800
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
standard output
PASSED
e7b44c952e61e4ebd35d74767a447566
train_002.jsonl
1592921100
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int T = scanner.nextInt(); while (T-- > 0) { if (scanner.nextInt() % 4 == 0) { System.out.println("YES"); } else { System.out.println("NO"); } } } }
Java
["4\n3\n4\n12\n1000000000"]
2 seconds
["NO\nYES\nYES\nYES"]
NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.
Java 8
standard input
[ "geometry", "math" ]
07e56d4031bcb119d2f684203f7ed133
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.
800
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
standard output
PASSED
2c4652e67b1980d4556b3c633a02962a
train_002.jsonl
1592921100
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int test = in.nextInt(); while(test-- > 0) { long n = in.nextLong(); if(n%4 == 0) { System.out.println("YES"); } else System.out.println("NO"); } } }
Java
["4\n3\n4\n12\n1000000000"]
2 seconds
["NO\nYES\nYES\nYES"]
NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.
Java 8
standard input
[ "geometry", "math" ]
07e56d4031bcb119d2f684203f7ed133
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.
800
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
standard output
PASSED
4c9bb54ad230260e49f20fde89d7977a
train_002.jsonl
1592921100
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
256 megabytes
import java.io.ByteArrayInputStream; import java.io.File; import java.io.PrintWriter; import java.util.Scanner; public class A { public static void main(String[] args) throws Exception { new A().go(); } int use_file = 0; String INPUT = "4\r\n" + "3\r\n" + "4\r\n" + "12\r\n" + "1000000000"; void solve(int caseNr) { int n = in.nextInt(); System.out.println(n%4==0 ? "yes" : "no"); return; } // end of solve2 // ---------------------------------------------------------------------------------------------- // // void testCases() { // solve(1); // out.flush(); // } void testCases() { int t = in.nextInt(); for (int i=1; i<=t; i++) { solve(i); } out.flush(); } // ---------------------------------------------------------------------------------------------- // void go() throws Exception { if (LOCAL && use_file == 0) { System.setIn(new ByteArrayInputStream(INPUT.getBytes())); in = new Scanner(System.in); } if (LOCAL && use_file > 0) { String filename = String.format("in/cf%d.txt", use_file); File inputFile = new File(filename); in = new Scanner(inputFile); out.printf("[%s]\n", filename); out.flush(); } if (!LOCAL) { in = new Scanner(System.in); } long startTime = System.currentTimeMillis(); testCases(); if (LOCAL) { System.out.printf("[%dms]\n", System.currentTimeMillis()-startTime); } in.close(); } static boolean LOCAL = System.getProperty("ONLINE_JUDGE") == null; Scanner in; PrintWriter out = new PrintWriter(System.out); private int inf = Integer.MAX_VALUE; }
Java
["4\n3\n4\n12\n1000000000"]
2 seconds
["NO\nYES\nYES\nYES"]
NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.
Java 8
standard input
[ "geometry", "math" ]
07e56d4031bcb119d2f684203f7ed133
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.
800
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
standard output
PASSED
83ac7d90bce0915cd4cd135557da4a51
train_002.jsonl
1592921100
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
256 megabytes
import java.io.ByteArrayInputStream; import java.io.PrintWriter; import java.util.Scanner; public class A { static boolean LOCAL = System.getProperty("ONLINE_JUDGE") == null; public static void main(String[] args) throws Exception { new A().go(); } Scanner in; PrintWriter out = new PrintWriter(System.out); String INPUT = "4\r\n" + "3\r\n" + "4\r\n" + "12\r\n" + "1000000000"; void go() { if (LOCAL) { System.setIn(new ByteArrayInputStream(INPUT.getBytes())); } in = new Scanner(System.in); long startTime = System.currentTimeMillis(); solve(); if (LOCAL) System.out.printf("[%dms]",System.currentTimeMillis()-startTime); } void solve() { int t = in.nextInt(); while(t-- > 0) { int n = in.nextInt(); out.println(n%4==0 ? "yes" : "no"); } out.flush(); } }
Java
["4\n3\n4\n12\n1000000000"]
2 seconds
["NO\nYES\nYES\nYES"]
NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.
Java 8
standard input
[ "geometry", "math" ]
07e56d4031bcb119d2f684203f7ed133
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.
800
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
standard output
PASSED
71a333ae45fd0c50c73e5fbe5fa65c01
train_002.jsonl
1592921100
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
256 megabytes
import java.io.*; import java.util.*; import java.math.*; import java.lang.*; import static java.lang.Math.*; public class MakingString 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); } } // if modulo is required set value accordingly public static long[][] matrixMultiply2dL(long t[][],long m[][]) { long res[][]= new long[t.length][m[0].length]; for(int i=0;i<t.length;i++) { for(int j=0;j<m[0].length;j++) { res[i][j]=0; for(int k=0;k<t[0].length;k++) { res[i][j]+=t[i][k]+m[k][j]; } } } return res; } static long combination(long n,long r) { long ans=1; for(long i=0;i<r;i++) { ans=(ans*(n-i))/(i+1); } return ans; } static int mat(String a,String b) { int count=0; for(int i=0;i<a.length();i++) { if(a.charAt(i)!=b.charAt(i)) count++; } return count; } static int accumulate(int arr[], int first, int last) { int init = 0; for (int i = first; i< last; i++) { init = init + arr[i]; } return init; } // Returns true if it is possible to divide // array into two halves of same sum. // This function mainly uses combinationUtil() static Boolean isPossible(int arr[], int n) { // If size of array is not even. if (n % 2 != 0) return false; // If sum of array is not even. int sum = accumulate(arr, 0, n); if (sum % 2 != 0) return false; // A temporary array to store all // combination one by one int k=n/2; int half[] = new int[n/2]; // Print all combination using temporary // array 'half[]' return combinationUtil(arr, half, 0, n - 1, 0, n, sum); } /* arr[] ---> Input Array half[] ---> Temporary array to store current combination of size n/2 start & end ---> Staring and Ending indexes in arr[] index ---> Current index in half[] */ static Boolean combinationUtil(int arr[], int half[], int start, int end, int index, int n, int sum) { // Current combination is ready to // be printed, print it if (index == n / 2) { int curr_sum = accumulate(half, 0 , n/2); return (curr_sum + curr_sum == sum); } // replace index with all possible elements. // The condition "end-i+1 >= n/2-index" makes // sure that including one element at index // will make a combination with remaining // elements at remaining positions for (int i = start; i <= end && end - i + 1 >= n/2 - index; i++) { half[index] = arr[i]; if (combinationUtil(arr, half, i + 1, end, index + 1, n, sum)) return true; } return false; } static int gcd(int a, int b) { // Everything divides 0 if (a == 0) return b; if (b == 0) return a; // base case if (a == b) return a; // a is greater if (a > b) return gcd(a-b, b); return gcd(a, b-a); } public static void main(String args[]) throws Exception { new Thread(null, new MakingString(),"MakingString",1<<27).start(); } // **just change the name of class from Main to reuquired** public void run() { InputReader sc = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); int n = sc.nextInt(); for(int j=0;j<n;j++) { int temp=sc.nextInt(); if(temp%4==0) { System.out.println("YES"); } else { System.out.println("NO"); } } System.out.flush(); w.close(); } }
Java
["4\n3\n4\n12\n1000000000"]
2 seconds
["NO\nYES\nYES\nYES"]
NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.
Java 8
standard input
[ "geometry", "math" ]
07e56d4031bcb119d2f684203f7ed133
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.
800
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
standard output
PASSED
658f14f5e98f28a24506997e63284c12
train_002.jsonl
1592921100
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
256 megabytes
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigDecimal; import java.util.StringTokenizer; public class A { public static void main(String[] args) { MyScanner sc = new MyScanner(); PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); int t = sc.nextInt(); while(t-- > 0) { int n = sc.nextInt(); if(n%4== 0) out.println("YES"); else out.println("NO"); } out.close(); } private 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
["4\n3\n4\n12\n1000000000"]
2 seconds
["NO\nYES\nYES\nYES"]
NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.
Java 8
standard input
[ "geometry", "math" ]
07e56d4031bcb119d2f684203f7ed133
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.
800
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
standard output
PASSED
f73ee3b9411488e6ae4b2b48259cf204
train_002.jsonl
1592921100
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
256 megabytes
import java.util.*; public class fashion { public static void main(String args []) { Scanner s = new Scanner(System.in); int t = s.nextInt(); while(t-->0) { int n = s.nextInt(); if(n%4==0) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["4\n3\n4\n12\n1000000000"]
2 seconds
["NO\nYES\nYES\nYES"]
NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.
Java 8
standard input
[ "geometry", "math" ]
07e56d4031bcb119d2f684203f7ed133
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.
800
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
standard output
PASSED
f081efdfc7a0c1b419f467af30b9198d
train_002.jsonl
1592921100
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
256 megabytes
import java.util.*; public class fashion { public static void main(String args []) { Scanner s = new Scanner(System.in); int t = s.nextInt(); while(t-->0) { int side = s.nextInt(); beauti(side); } } static void beauti(int n) { if(n%4==0) System.out.println("YES"); else System.out.println("NO"); } }
Java
["4\n3\n4\n12\n1000000000"]
2 seconds
["NO\nYES\nYES\nYES"]
NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.
Java 8
standard input
[ "geometry", "math" ]
07e56d4031bcb119d2f684203f7ed133
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.
800
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
standard output
PASSED
e7c547abc6cb1f83f62e7679c0b48f16
train_002.jsonl
1592921100
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
256 megabytes
import java.io.*; public class A { public static void main(String [] args)throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); while(t-->0){ int n = Integer.parseInt(br.readLine()); if(n%4==0){ System.out.println("YES"); } else System.out.println("NO"); } } }
Java
["4\n3\n4\n12\n1000000000"]
2 seconds
["NO\nYES\nYES\nYES"]
NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.
Java 8
standard input
[ "geometry", "math" ]
07e56d4031bcb119d2f684203f7ed133
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.
800
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
standard output
PASSED
128ca1a1b3a26d382bb82fb50ff9f339
train_002.jsonl
1592921100
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
256 megabytes
import java.util.Scanner; public class FashionableLee { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int t=sc.nextInt(); long k[]=new long[t]; for(int i=0;i<t;i++) { k[i]=sc.nextLong(); } for(int i=0;i<t;i++) { if(k[i]%4==0 ) { System.out.println("YES"); } else { System.out.println("NO"); } } } }
Java
["4\n3\n4\n12\n1000000000"]
2 seconds
["NO\nYES\nYES\nYES"]
NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.
Java 8
standard input
[ "geometry", "math" ]
07e56d4031bcb119d2f684203f7ed133
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.
800
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
standard output
PASSED
ad292e05221199b193dfb9eefed0073d
train_002.jsonl
1592921100
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
256 megabytes
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int i=0;i<t;i++) { long n = sc.nextLong(); if(n%4 == 0) System.out.println("YES"); else System.out.println("NO"); } sc.close(); } }
Java
["4\n3\n4\n12\n1000000000"]
2 seconds
["NO\nYES\nYES\nYES"]
NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.
Java 8
standard input
[ "geometry", "math" ]
07e56d4031bcb119d2f684203f7ed133
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.
800
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
standard output
PASSED
01b561b8f581b587e02f7e780eb77bba
train_002.jsonl
1592921100
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
256 megabytes
import java.util.Scanner; public class cf652a { public static void main(String[] args) { // TODO Auto-generated method stub Scanner s = new Scanner(System.in); int T,n; T= s.nextInt(); for(int i=0;i<T;i++) { n = s.nextInt(); if(n<=3) { System.out.println("NO"); } else if(n%4==0) { System.out.println("YES"); } else{ System.out.println("NO"); } //System.out.println(n%2); } } }
Java
["4\n3\n4\n12\n1000000000"]
2 seconds
["NO\nYES\nYES\nYES"]
NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.
Java 8
standard input
[ "geometry", "math" ]
07e56d4031bcb119d2f684203f7ed133
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.
800
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
standard output
PASSED
60205c737b1fbd3f2a050952d5dd3c1b
train_002.jsonl
1592921100
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
256 megabytes
import java.util.*; public class Main{ public static void main(String[] args){ Scanner s=new Scanner(System.in); int t=s.nextInt(); for(int j=0;j<t;j++){ int n=s.nextInt(); n=(n-2); if(n%2==0){ if((n/2)%2==1 ){ System.out.println("YES");}else{ System.out.println("NO"); } }else{ System.out.println("NO"); } } } }
Java
["4\n3\n4\n12\n1000000000"]
2 seconds
["NO\nYES\nYES\nYES"]
NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.
Java 8
standard input
[ "geometry", "math" ]
07e56d4031bcb119d2f684203f7ed133
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.
800
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
standard output
PASSED
981fa89f0800748c0477beb020443d8f
train_002.jsonl
1592921100
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
256 megabytes
import java.util.Scanner; import java.util.TreeSet; public class FashionabLee_1369A { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-- > 0) { long n = sc.nextLong(); if(n%4 == 0) { System.out.println("YES"); } else { System.out.println("NO"); } } } }
Java
["4\n3\n4\n12\n1000000000"]
2 seconds
["NO\nYES\nYES\nYES"]
NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.
Java 8
standard input
[ "geometry", "math" ]
07e56d4031bcb119d2f684203f7ed133
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.
800
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
standard output
PASSED
fbc2757dba57bba5303324d5b8266495
train_002.jsonl
1592921100
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
256 megabytes
import java.util.Scanner; public class Fashionablee { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int i = 1;i <= t;i++) { long n = sc.nextLong(); if(n > 3&& n%4 == 0) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["4\n3\n4\n12\n1000000000"]
2 seconds
["NO\nYES\nYES\nYES"]
NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.
Java 8
standard input
[ "geometry", "math" ]
07e56d4031bcb119d2f684203f7ed133
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.
800
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
standard output
PASSED
83261ab275fe616b8b245767aab9a357
train_002.jsonl
1592921100
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
256 megabytes
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 Ideone { public static void main (String[] args) throws java.lang.Exception { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t!=0) { long n=sc.nextLong(); if(n%4==0) System.out.println("YES"); else System.out.println("NO"); t--; } } }
Java
["4\n3\n4\n12\n1000000000"]
2 seconds
["NO\nYES\nYES\nYES"]
NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well.
Java 8
standard input
[ "geometry", "math" ]
07e56d4031bcb119d2f684203f7ed133
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$)Β β€” the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon.
800
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
standard output
PASSED
31d2a751b109cafc41ebd2bd27aea8fe
train_002.jsonl
1568822700
Alex decided to go on a touristic trip over the country.For simplicity let's assume that the country has $$$n$$$ cities and $$$m$$$ bidirectional roads connecting them. Alex lives in city $$$s$$$ and initially located in it. To compare different cities Alex assigned each city a score $$$w_i$$$ which is as high as interesting city seems to Alex.Alex believes that his trip will be interesting only if he will not use any road twice in a row. That is if Alex came to city $$$v$$$ from city $$$u$$$, he may choose as the next city in the trip any city connected with $$$v$$$ by the road, except for the city $$$u$$$.Your task is to help Alex plan his city in a way that maximizes total score over all cities he visited. Note that for each city its score is counted at most once, even if Alex been there several times during his trip.
256 megabytes
import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.InputMismatchException; public class e { static class Solver { int N, M, S; boolean vis[]; long w[], wtot, sum[]; ArrayList<int[]> adj[], trees; long sum(int node, int par) { if(sum[node] != -1) return sum[node]; long cmax = 0; for (int[] e : adj[node]) if (e[1] != par) { cmax = Math.max(cmax, sum(e[1], node)); } return sum[node] = w[node] + cmax; } // we count the number of nodes and edges when seeking down this path int[] precomp(int node) { int nodes = 1, edges = 0, res[]; // me vis[node] = true; for (int[] edge : adj[node]) { int to = edge[1]; if (vis[to]) { // if we've seen this, just count the edge edges++; } else { // if this edge goes to a tree, we want to note it res = precomp(to); edges += ++res[1]; nodes += res[0]; if (res[0] << 1 == res[1]) trees.add(edge); } } return new int[] { nodes, edges }; } @SuppressWarnings("unchecked") void solve(FastScanner s, PrintWriter out) { N = s.nextInt(); M = s.nextInt(); adj = new ArrayList[N]; vis = new boolean[N]; trees = new ArrayList<>(); w = new long[N]; for (int i = 0; i < N; i++) { adj[i] = new ArrayList<>(); wtot += w[i] = s.nextLong(); } for (int i = 0; i < M; i++) { int u = s.nextInt() - 1, v = s.nextInt() - 1; adj[u].add(new int[] { u, v }); adj[v].add(new int[] { v, u }); } S = s.nextInt() - 1; precomp(S); long down = 0, mx = 0; Arrays.fill(sum = new long[N], -1); for (int[] ted : trees) { down = sum(ted[1], ted[0]); wtot -= w[ted[1]]; mx = mx > down ? mx : down; } out.println(wtot + mx); } } public static void main(String[] args) { FastScanner s = new FastScanner(System.in); PrintWriter out = new PrintWriter(System.out); Solver solver = new Solver(); solver.solve(s, out); out.close(); s.close(); } static class FastScanner { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public FastScanner(InputStream stream) { this.stream = stream; } public FastScanner(File f) throws FileNotFoundException { this(new FileInputStream(f)); } public FastScanner(String s) { this.stream = new ByteArrayInputStream(s.getBytes(StandardCharsets.UTF_8)); } void close() { try { stream.close(); } catch (IOException e) { e.printStackTrace(); } } int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } boolean isEndline(int c) { return c == '\n' || c == '\r' || c == -1; } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = read(); while (isEndline(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndline(c)); return res.toString(); } // Jacob Garbage public int[] nextIntArray(int N) { int[] ret = new int[N]; for (int i = 0; i < N; i++) ret[i] = this.nextInt(); return ret; } public int[][] next2DIntArray(int N, int M) { int[][] ret = new int[N][]; for (int i = 0; i < N; i++) ret[i] = this.nextIntArray(M); return ret; } public long[] nextLongArray(int N) { long[] ret = new long[N]; for (int i = 0; i < N; i++) ret[i] = this.nextLong(); return ret; } public long[][] next2DLongArray(int N, int M) { long[][] ret = new long[N][]; for (int i = 0; i < N; i++) ret[i] = nextLongArray(M); return ret; } public double[] nextDoubleArray(int N) { double[] ret = new double[N]; for (int i = 0; i < N; i++) ret[i] = this.nextDouble(); return ret; } public double[][] next2DDoubleArray(int N, int M) { double[][] ret = new double[N][]; for (int i = 0; i < N; i++) ret[i] = this.nextDoubleArray(M); return ret; } } }
Java
["5 7\n2 2 8 6 9\n1 2\n1 3\n2 4\n3 2\n4 5\n2 5\n1 5\n2", "10 12\n1 7 1 9 3 3 6 30 1 10\n1 2\n1 3\n3 5\n5 7\n2 3\n5 4\n6 9\n4 6\n3 7\n6 8\n9 4\n9 10\n6"]
2 seconds
["27", "61"]
null
Java 8
standard input
[ "dp", "greedy", "graphs", "dsu", "dfs and similar", "trees" ]
824c7f11e6c2997c98741d314cdd1970
First line of input contains two integers $$$n$$$ and $$$m$$$, ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le m \le 2 \cdot 10^5$$$) which are numbers of cities and roads in the country. Second line contains $$$n$$$ integers $$$w_1, w_2, \ldots, w_n$$$ ($$$0 \le w_i \le 10^9$$$) which are scores of all cities. The following $$$m$$$ lines contain description of the roads. Each of these $$$m$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$) which are cities connected by this road. It is guaranteed that there is at most one direct road between any two cities, no city is connected to itself by the road and, finally, it is possible to go from any city to any other one using only roads. The last line contains single integer $$$s$$$ ($$$1 \le s \le n$$$), which is the number of the initial city.
2,200
Output single integer which is the maximum possible sum of scores of visited cities.
standard output
PASSED
3af2172b7439bf368e3ca2cd38659619
train_002.jsonl
1568822700
Alex decided to go on a touristic trip over the country.For simplicity let's assume that the country has $$$n$$$ cities and $$$m$$$ bidirectional roads connecting them. Alex lives in city $$$s$$$ and initially located in it. To compare different cities Alex assigned each city a score $$$w_i$$$ which is as high as interesting city seems to Alex.Alex believes that his trip will be interesting only if he will not use any road twice in a row. That is if Alex came to city $$$v$$$ from city $$$u$$$, he may choose as the next city in the trip any city connected with $$$v$$$ by the road, except for the city $$$u$$$.Your task is to help Alex plan his city in a way that maximizes total score over all cities he visited. Note that for each city its score is counted at most once, even if Alex been there several times during his trip.
256 megabytes
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintStream; import java.util.Locale; import java.util.StringTokenizer; public class Solution implements Runnable { private PrintStream out; private BufferedReader in; private StringTokenizer st; public void solve() throws IOException { long time0 = System.currentTimeMillis(); int n = nextInt(); int m = nextInt(); int[] w = new int[n]; for (int i = 0; i < n; i++) { w[i] = nextInt(); } int[] u = new int[m]; int[] v = new int[m]; for (int i = 0; i < m; i++) { u[i] = nextInt() - 1; v[i] = nextInt() - 1; } int s = nextInt() - 1; long answer = solve(n, w, m, u, v, s); out.println(answer); System.err.println("time: " + (System.currentTimeMillis() - time0)); } private long solve(int n, int[] w, int m, int[] u, int[] v, int s) { int[][] g = buildGraph(n, m, u, v); boolean[] used = new boolean[n]; boolean[] cycled = new boolean[n]; goCycles(-1, s, g, used, cycled); long answer = 0; for (int i = 0; i < n; i++) { if (cycled[i]) { answer += w[i]; w[i] = 0; } } used = new boolean[n]; long appendix = findMax(-1, s, g, w, used); answer += appendix; return answer; } private long findMax(int from, int s, int[][] g, int[] w, boolean[] used) { if (used[s]) { return 0; } used[s] = true; long result = 0; for (int e = 0; e < g[s].length; e++) { if (g[s][e] == from) { continue; } result = Math.max(result, findMax(s, g[s][e], g, w, used)); } return result + w[s]; } private boolean goCycles(int from, int s, int[][] g, boolean[] used, boolean[] cycled) { if (used[s]) { return true; } used[s] = true; boolean result = false; for (int e = 0; e < g[s].length; e++) { if (g[s][e] == from) { continue; } if (goCycles(s, g[s][e], g, used, cycled)) { result = true; } } cycled[s] = result; return result; } private int[][] buildGraph(int n, int m, int[] u, int[] v) { int[] cnt = new int[n]; for (int i = 0; i < m; i++) { cnt[u[i]]++; cnt[v[i]]++; } int[][] g = new int[n][]; for (int i = 0; i < n; i++) { g[i] = new int[cnt[i]]; cnt[i] = 0; } for (int i = 0; i < m; i++) { g[u[i]][cnt[u[i]]++] = v[i]; g[v[i]][cnt[v[i]]++] = u[i]; } return g; } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public String next() throws IOException { while (!st.hasMoreTokens()) { String line = in.readLine(); if (line == null) { return null; } st = new StringTokenizer(line); } return st.nextToken(); } @Override public void run() { try { solve(); out.close(); } catch (Throwable e) { throw new RuntimeException(e); } } public Solution(String name) throws IOException { Locale.setDefault(Locale.US); if (name == null) { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintStream(new BufferedOutputStream(System.out)); } else { in = new BufferedReader(new InputStreamReader(new FileInputStream(name + ".in"))); out = new PrintStream(new BufferedOutputStream(new FileOutputStream(name + ".out"))); } st = new StringTokenizer(""); } public static void main(String[] args) throws IOException { new Thread(new Solution(null)).start(); } }
Java
["5 7\n2 2 8 6 9\n1 2\n1 3\n2 4\n3 2\n4 5\n2 5\n1 5\n2", "10 12\n1 7 1 9 3 3 6 30 1 10\n1 2\n1 3\n3 5\n5 7\n2 3\n5 4\n6 9\n4 6\n3 7\n6 8\n9 4\n9 10\n6"]
2 seconds
["27", "61"]
null
Java 8
standard input
[ "dp", "greedy", "graphs", "dsu", "dfs and similar", "trees" ]
824c7f11e6c2997c98741d314cdd1970
First line of input contains two integers $$$n$$$ and $$$m$$$, ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le m \le 2 \cdot 10^5$$$) which are numbers of cities and roads in the country. Second line contains $$$n$$$ integers $$$w_1, w_2, \ldots, w_n$$$ ($$$0 \le w_i \le 10^9$$$) which are scores of all cities. The following $$$m$$$ lines contain description of the roads. Each of these $$$m$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$) which are cities connected by this road. It is guaranteed that there is at most one direct road between any two cities, no city is connected to itself by the road and, finally, it is possible to go from any city to any other one using only roads. The last line contains single integer $$$s$$$ ($$$1 \le s \le n$$$), which is the number of the initial city.
2,200
Output single integer which is the maximum possible sum of scores of visited cities.
standard output
PASSED
ad15e83eac62eecc850b5ad10a499b1a
train_002.jsonl
1568822700
Alex decided to go on a touristic trip over the country.For simplicity let's assume that the country has $$$n$$$ cities and $$$m$$$ bidirectional roads connecting them. Alex lives in city $$$s$$$ and initially located in it. To compare different cities Alex assigned each city a score $$$w_i$$$ which is as high as interesting city seems to Alex.Alex believes that his trip will be interesting only if he will not use any road twice in a row. That is if Alex came to city $$$v$$$ from city $$$u$$$, he may choose as the next city in the trip any city connected with $$$v$$$ by the road, except for the city $$$u$$$.Your task is to help Alex plan his city in a way that maximizes total score over all cities he visited. Note that for each city its score is counted at most once, even if Alex been there several times during his trip.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.util.Collection; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.Queue; import java.io.BufferedReader; import java.util.LinkedList; 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); OutputWriter out = new OutputWriter(outputStream); TaskE solver = new TaskE(); solver.solve(1, in, out); out.close(); } static class TaskE { public void solve(int testNumber, InputReader in, OutputWriter out) { int N = in.nextInt(), M = in.nextInt(); GraphUtils graph = new GraphUtils(); graph.initGraph(N, new String[N]); Integer score[] = in.nextIntArray(N); for (int i = 0; i < M; i++) { graph.addEdge(in.nextInt() - 1, in.nextInt() - 1, false, 1); } int source = in.nextInt() - 1; int degree[] = new int[N]; Queue<GraphUtils.Node> queue = new LinkedList<>(); for (GraphUtils.Node node : graph.nodes) { degree[node.index] = node.edges.size(); if (node.index != source && degree[node.index] == 1) { ((LinkedList<GraphUtils.Node>) queue).add(node); } } long best[] = new long[N]; while (!queue.isEmpty()) { GraphUtils.Node node = queue.poll(); degree[node.index] = -1; for (GraphUtils.Edge edge : node.edges) { GraphUtils.Node v = edge.to; if (degree[v.index] < 0) { continue; } degree[v.index]--; best[v.index] = Math.max(best[v.index], best[node.index] + score[node.index]); if (degree[v.index] == 1 && v.index != source) { ((LinkedList<GraphUtils.Node>) queue).add(v); } } } long total = 0, maxInsert = 0; for (int i = 0; i < N; i++) { if (degree[i] < 0) { continue; } total += score[i]; maxInsert = Math.max(maxInsert, best[i]); } out.printLine(total + maxInsert); } } static class InputReader { BufferedReader in; StringTokenizer tokenizer = null; public InputReader(InputStream inputStream) { in = new BufferedReader(new InputStreamReader(inputStream)); } public String next() { try { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(in.readLine()); } return tokenizer.nextToken(); } catch (IOException e) { return null; } } public int nextInt() { return Integer.parseInt(next()); } public Integer[] nextIntArray(int size) { Integer array[] = new Integer[size]; for (int i = 0; i < size; i++) { array[i] = nextInt(); } return array; } } static class OutputWriter { PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } } public void printLine(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } } static class GraphUtils { GraphUtils.Node[] nodes; public void initGraph(int numberOfNodes, String labels[]) { nodes = new GraphUtils.Node[numberOfNodes]; for (int i = 0; i < numberOfNodes; i++) { nodes[i] = new GraphUtils.Node(); nodes[i].edges = new ArrayList<>(); nodes[i].index = i; if (labels[i] != null) { nodes[i].name = labels[i]; } } } public void addEdge(int u, int v, boolean isDirected, long weight) { GraphUtils.Edge edge = new GraphUtils.Edge(nodes[u], nodes[v], weight); nodes[u].edges.add(edge); if (!isDirected) { GraphUtils.Edge edge1 = new GraphUtils.Edge(nodes[v], nodes[u], weight); nodes[v].edges.add(edge1); } } static class Node { String name; List<GraphUtils.Edge> edges; int index; public Node() { } } static class Edge { long weight; GraphUtils.Node from; GraphUtils.Node to; public Edge(GraphUtils.Node from, GraphUtils.Node to, long weight) { this.from = from; this.to = to; this.weight = weight; } } } }
Java
["5 7\n2 2 8 6 9\n1 2\n1 3\n2 4\n3 2\n4 5\n2 5\n1 5\n2", "10 12\n1 7 1 9 3 3 6 30 1 10\n1 2\n1 3\n3 5\n5 7\n2 3\n5 4\n6 9\n4 6\n3 7\n6 8\n9 4\n9 10\n6"]
2 seconds
["27", "61"]
null
Java 8
standard input
[ "dp", "greedy", "graphs", "dsu", "dfs and similar", "trees" ]
824c7f11e6c2997c98741d314cdd1970
First line of input contains two integers $$$n$$$ and $$$m$$$, ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le m \le 2 \cdot 10^5$$$) which are numbers of cities and roads in the country. Second line contains $$$n$$$ integers $$$w_1, w_2, \ldots, w_n$$$ ($$$0 \le w_i \le 10^9$$$) which are scores of all cities. The following $$$m$$$ lines contain description of the roads. Each of these $$$m$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$) which are cities connected by this road. It is guaranteed that there is at most one direct road between any two cities, no city is connected to itself by the road and, finally, it is possible to go from any city to any other one using only roads. The last line contains single integer $$$s$$$ ($$$1 \le s \le n$$$), which is the number of the initial city.
2,200
Output single integer which is the maximum possible sum of scores of visited cities.
standard output
PASSED
14be850775a2a69be34f50157605588e
train_002.jsonl
1568822700
Alex decided to go on a touristic trip over the country.For simplicity let's assume that the country has $$$n$$$ cities and $$$m$$$ bidirectional roads connecting them. Alex lives in city $$$s$$$ and initially located in it. To compare different cities Alex assigned each city a score $$$w_i$$$ which is as high as interesting city seems to Alex.Alex believes that his trip will be interesting only if he will not use any road twice in a row. That is if Alex came to city $$$v$$$ from city $$$u$$$, he may choose as the next city in the trip any city connected with $$$v$$$ by the road, except for the city $$$u$$$.Your task is to help Alex plan his city in a way that maximizes total score over all cities he visited. Note that for each city its score is counted at most once, even if Alex been there several times during his trip.
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.*; import static java.util.Arrays.sort; import static java.util.Collections.sort; import static java.util.Arrays.fill; import static java.util.Arrays.copyOfRange; import static java.util.Arrays.binarySearch; import static java.lang.Math.min; import static java.lang.Math.max; import static java.lang.Math.sqrt; import static java.lang.Math.ceil; public class Main { public static final int INF = Integer.MAX_VALUE; public static boolean dfs(int curr, int prev, boolean[] done, boolean[] ok, long[] w, long[] sumNotOk, ArrayList <Integer>[] g) { //System.out.println(curr + " " + prev); done[curr] = true; for(int next : g[curr]) { //System.out.println(curr + " -> " + next + " " + done[next]); if(next == prev) continue; ok[curr] |= done[next]; if(done[next]) continue; ok[curr] |= dfs(next, curr, done, ok, w, sumNotOk, g); } if(!ok[curr]) { sumNotOk[curr] = w[curr]; for(int next : g[curr]) if(next != prev) sumNotOk[curr] = max(sumNotOk[curr], w[curr] + sumNotOk[next]); } return ok[curr]; } public static void main(String[] args) throws IOException { int n = in.nextInt(); int m = in.nextInt(); long[] w = in.nextLongArray(n); ArrayList <Integer>[] g = ALArrayI(n); for(int i = 0; i < m; i ++) { int u = in.nextInt() - 1; int v = in.nextInt() - 1; g[u].add(v); g[v].add(u); } int s = in.nextInt() - 1; boolean[] ok = new boolean[n]; boolean[] done = new boolean[n]; long[] sumNotOk = new long[n]; dfs(s, -1, done, ok, w, sumNotOk, g); long ans = 0, maxinc = 0; for(int i = 0; i < n; i ++) { if(ok[i]) ans += w[i]; else maxinc = max(maxinc, sumNotOk[i]); } //for(int i = 0; i < n; i ++) // if(ok[i]) // System.out.println(i); System.out.println(ans + maxinc); } public static FastReader in = new FastReader(); public static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); public static void gcj(int cn, Object ans) throws IOException { System.out.print("Case #" + cn + ": " + ans + "\n"); } public static ArrayList <Integer>[] ALArrayI(int size) { ArrayList <Integer>[] l = new ArrayList[size]; for(int i = 0; i < size; i ++) l[i] = new ArrayList <> (); return l; } public static ArrayList <Long>[] ALArrayL(int size) { ArrayList <Long>[] l = new ArrayList[size]; for(int i = 0; i < size; i ++) l[i] = new ArrayList <> (); return l; } public static Integer[] integerList(int fi, int fo) { Integer[] l = new Integer[fo - fi]; for(int i = 0; i < fo - fi; i ++) l[i] = fi + i; return l; } } class Graph { TreeSet <Integer>[] g; public Graph(int n) { g = new TreeSet[n]; for(int i = 0; i < n; i ++) g[i] = new TreeSet <> (); } public void addEdge(int u, int v) { g[u].add(v); } public TreeSet <Integer> getAdj(int u) { return g[u]; } public int nodes() { return g.length; } } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } public String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public char nextChar() { return next().charAt(0); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int[] nextIntArray(int n) { int[] a = new int[n]; for(int i = 0; i < n; i ++) a[i] = nextInt(); return a; } public Integer[] nextIntegerArray(int n) { Integer[] a = new Integer[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 double[] nextDoubleArray(int n) { double[] a = new double[n]; for(int i = 0; i < n; i ++) a[i] = nextDouble(); return a; } public String[] nextStringArray(int n) { String[] a = new String[n]; for(int i = 0; i < n; i ++) a[i] = next(); return a; } }
Java
["5 7\n2 2 8 6 9\n1 2\n1 3\n2 4\n3 2\n4 5\n2 5\n1 5\n2", "10 12\n1 7 1 9 3 3 6 30 1 10\n1 2\n1 3\n3 5\n5 7\n2 3\n5 4\n6 9\n4 6\n3 7\n6 8\n9 4\n9 10\n6"]
2 seconds
["27", "61"]
null
Java 8
standard input
[ "dp", "greedy", "graphs", "dsu", "dfs and similar", "trees" ]
824c7f11e6c2997c98741d314cdd1970
First line of input contains two integers $$$n$$$ and $$$m$$$, ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le m \le 2 \cdot 10^5$$$) which are numbers of cities and roads in the country. Second line contains $$$n$$$ integers $$$w_1, w_2, \ldots, w_n$$$ ($$$0 \le w_i \le 10^9$$$) which are scores of all cities. The following $$$m$$$ lines contain description of the roads. Each of these $$$m$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$) which are cities connected by this road. It is guaranteed that there is at most one direct road between any two cities, no city is connected to itself by the road and, finally, it is possible to go from any city to any other one using only roads. The last line contains single integer $$$s$$$ ($$$1 \le s \le n$$$), which is the number of the initial city.
2,200
Output single integer which is the maximum possible sum of scores of visited cities.
standard output
PASSED
784fcbcbd228bd705583b82a26388d39
train_002.jsonl
1568822700
Alex decided to go on a touristic trip over the country.For simplicity let's assume that the country has $$$n$$$ cities and $$$m$$$ bidirectional roads connecting them. Alex lives in city $$$s$$$ and initially located in it. To compare different cities Alex assigned each city a score $$$w_i$$$ which is as high as interesting city seems to Alex.Alex believes that his trip will be interesting only if he will not use any road twice in a row. That is if Alex came to city $$$v$$$ from city $$$u$$$, he may choose as the next city in the trip any city connected with $$$v$$$ by the road, except for the city $$$u$$$.Your task is to help Alex plan his city in a way that maximizes total score over all cities he visited. Note that for each city its score is counted at most once, even if Alex been there several times during his trip.
256 megabytes
import java.util.*; import java.io.*; public class Main{ static PrintWriter out; static InputReader in; public static void main(String args[]){ out = new PrintWriter(System.out); in = new InputReader(); new Main(); out.flush(); out.close(); } Main(){ solve(); } class pair{ int F, S; pair(int a, int b){ F = a; S = b; } } final int max = 200010; final long gmax = Long.MAX_VALUE / 100; int n, m; ArrayList<pair> al[] = new ArrayList[max]; int w[] = new int[max]; boolean b[] = new boolean[max]; int low[] = new int[max], visit[] = new int[max], T = 0; int pa[] = new int[max], r[] = new int[max]; int from[] = new int[max], to[] = new int[max], sz[] = new int[max]; long dp[][] = new long[max][2]; void dfs(int u, int pa){ low[u] = visit[u] = ++T; boolean a = true; for(pair e : al[u]){ int v = e.F; if(v == pa)continue; if(visit[v] != 0){ low[u] = Math.min(low[u], visit[v]); }else{ dfs(v, u); low[u] = Math.min(low[u], low[v]); } if(low[v] > visit[u]){ b[e.S] = true; } } } int get(int u){ return pa[u] == u ? u : (pa[u] = get(pa[u])); } void merge(int u, int v){ if(r[u] == r[v])++r[u]; if(r[u] < r[v]){ u ^= v; v ^= u; u ^= v; } pa[v] = u; } boolean cal(int u, int pa){ boolean r = sz[u] > 1; boolean ins = false; for(pair e : al[u]){ int v = e.F; if(v == pa)continue; ins = true; r |= cal(v, u); dp[u][1] += dp[v][1]; } dp[u][0] = gmax; for(pair e : al[u]){ int v = e.F; if(v == pa)continue; dp[u][0] = Math.min(dp[u][0], dp[u][1] - dp[v][1] + dp[v][0]); } if(!r){ dp[u][1] += w[u]; } if(!ins){ dp[u][0] = 0; } // System.out.println(u + " " + dp[u][0] + " " + dp[u][1] + " " + ins); return r; } void solve(){ n = in.nextInt(); m = in.nextInt(); long ans = 0; for(int i = 1; i <= n; i++){ ans += w[i] = in.nextInt(); al[i] = new ArrayList<>(); } for(int i = 0; i < m; i++){ int u = in.nextInt(), v = in.nextInt(); from[i] = u; to[i] = v; al[u].add(new pair(v, i)); al[v].add(new pair(u, i)); } dfs(1, 0); for(int i = 1; i <= n; i++)pa[i] = i; for(int i = 0; i < m; i++){ if(!b[i]){ int u = from[i], v = to[i]; int pu = get(u), pv = get(v); if(pu != pv)merge(pu, pv); } } for(int i = 1; i <= n; i++)al[i].clear(); for(int i = 1; i <= n; i++){ pa[i] = get(i); // System.out.print(pa[i] + " "); if(pa[i] != i)w[pa[i]] += w[i]; sz[pa[i]]++; } for(int i = 0; i < m; i++){ if(b[i]){ int u = from[i], v = to[i]; al[pa[u]].add(new pair(pa[v], -1)); al[pa[v]].add(new pair(pa[u], -1)); } } int x = in.nextInt(); int s = pa[x]; cal(s, 0); ans -= Math.min(dp[s][0], dp[s][1]); out.print(ans); } public static class InputReader{ BufferedReader br; StringTokenizer st; InputReader(){ br = new BufferedReader(new InputStreamReader(System.in)); } public int nextInt(){ return Integer.parseInt(next()); } public long nextLong(){ return Long.parseLong(next()); } public double nextDouble(){ return Double.parseDouble(next()); } public String next(){ while(st == null || !st.hasMoreTokens()){ try{ st = new StringTokenizer(br.readLine()); }catch(IOException e){} } return st.nextToken(); } } }
Java
["5 7\n2 2 8 6 9\n1 2\n1 3\n2 4\n3 2\n4 5\n2 5\n1 5\n2", "10 12\n1 7 1 9 3 3 6 30 1 10\n1 2\n1 3\n3 5\n5 7\n2 3\n5 4\n6 9\n4 6\n3 7\n6 8\n9 4\n9 10\n6"]
2 seconds
["27", "61"]
null
Java 8
standard input
[ "dp", "greedy", "graphs", "dsu", "dfs and similar", "trees" ]
824c7f11e6c2997c98741d314cdd1970
First line of input contains two integers $$$n$$$ and $$$m$$$, ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le m \le 2 \cdot 10^5$$$) which are numbers of cities and roads in the country. Second line contains $$$n$$$ integers $$$w_1, w_2, \ldots, w_n$$$ ($$$0 \le w_i \le 10^9$$$) which are scores of all cities. The following $$$m$$$ lines contain description of the roads. Each of these $$$m$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$) which are cities connected by this road. It is guaranteed that there is at most one direct road between any two cities, no city is connected to itself by the road and, finally, it is possible to go from any city to any other one using only roads. The last line contains single integer $$$s$$$ ($$$1 \le s \le n$$$), which is the number of the initial city.
2,200
Output single integer which is the maximum possible sum of scores of visited cities.
standard output
PASSED
b773a395e6f6a6b36eb47b6ef9e053ae
train_002.jsonl
1568822700
Alex decided to go on a touristic trip over the country.For simplicity let's assume that the country has $$$n$$$ cities and $$$m$$$ bidirectional roads connecting them. Alex lives in city $$$s$$$ and initially located in it. To compare different cities Alex assigned each city a score $$$w_i$$$ which is as high as interesting city seems to Alex.Alex believes that his trip will be interesting only if he will not use any road twice in a row. That is if Alex came to city $$$v$$$ from city $$$u$$$, he may choose as the next city in the trip any city connected with $$$v$$$ by the road, except for the city $$$u$$$.Your task is to help Alex plan his city in a way that maximizes total score over all cities he visited. Note that for each city its score is counted at most once, even if Alex been there several times during his trip.
256 megabytes
import java.util.*; import java.io.*; public class Tourism { static ArrayList<Edge>[] graph; static ArrayList<Integer>[] aux; static int[] pre; static int[] ll; static int cnt; static int curCol; static int[] col; //todo switch this up to include the fact that the subtree can be explored //todo as long as there is a cycle somewhere in the children //todo otherwise the subtrees are mutually exclusive public static void main(String[] args) { FastScanner scanner = new FastScanner(); PrintWriter out = new PrintWriter(System.out, false); int n = scanner.nextInt(), m = scanner.nextInt(); graph = new ArrayList[n]; for(int i = 0; i < n; i++) graph[i] = new ArrayList<>(); int[] scores = new int[n]; for(int i = 0; i < n; i++) scores[i] = scanner.nextInt(); for(int i = 0; i < m; i++) { int u = scanner.nextInt()-1, v = scanner.nextInt()-1; Edge edge= new Edge(u, v); graph[u].add(edge); graph[v].add(edge); } pre = new int[n]; ll = new int[n]; cnt = 0; curCol = 0; col = new int[n]; Arrays.fill(pre, -1); Arrays.fill(col, -1); int s = scanner.nextInt()-1; dfs(s,s); dfsCol(s,curCol++); aux = new ArrayList[curCol]; for(int i = 0; i < curCol; i++) { aux[i] = new ArrayList<>(); } colsz = new int[curCol]; for(int i = 0; i < n; i++) { colsz[col[i]]++; for(Edge edge: graph[i]) { if (col[edge.u] != col[edge.v]) { aux[col[edge.u]].add(col[edge.v]); aux[col[edge.v]].add(col[edge.u]); } } } colSums = new long[curCol]; for(int i = 0; i < n; i++) { colSums[col[i]] += scores[i]; } dp = new long[curCol]; sum = new long[curCol]; hasCycleChild = new boolean[curCol]; dfsAns(col[s], col[s]); out.println((dp[0] +sum[0])); out.flush(); } static long[] dp; static int[] colsz; static long[] colSums; static long[] sum; static boolean[] hasCycleChild; static void dfsAns(int v, int p) { long max = 0; HashSet<Integer> seen = new HashSet<>(); for (int edge:aux[v]) { if (edge == p || seen.contains(edge)) continue; seen.add(edge); dfsAns(edge, v); if (hasCycleChild[edge]) hasCycleChild[v] =true; sum[v] += sum[edge]; max = Math.max(dp[edge], max); } dp[v] = max; if (colsz[v] > 1) { hasCycleChild[v] = true; } else if (!hasCycleChild[v]){ dp[v] +=colSums[v]; } if (hasCycleChild[v]) { sum[v] += colSums[v]; } } static void dfsCol(int v, int c) { col[v] = c; for(Edge edge: graph[v]) { int u = edge.getOther(v); if (col[u] != -1) continue; if (edge.isBridge) dfsCol(u, curCol++); else dfsCol(u, c); } } static void dfs(int cur, int p) { ll[cur] = cnt++; pre[cur] = ll[cur]; for(Edge edge: graph[cur]) { int u = edge.getOther(cur); if (u == p) continue; if (pre[u] == -1) { dfs(u, cur); ll[cur] = Math.min(ll[cur], ll[u]); } else { ll[cur] = Math.min(ll[cur], pre[u]); } if (ll[u] > pre[cur]) edge.isBridge = true; } } static class Edge { int u, v; boolean isBridge; public Edge(int uu, int vv) { u = uu; v = vv; } int getOther(int x) { return u == x ? v : u; } } public static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(Reader in) { br = new BufferedReader(in); } public FastScanner() { this(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 readNextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["5 7\n2 2 8 6 9\n1 2\n1 3\n2 4\n3 2\n4 5\n2 5\n1 5\n2", "10 12\n1 7 1 9 3 3 6 30 1 10\n1 2\n1 3\n3 5\n5 7\n2 3\n5 4\n6 9\n4 6\n3 7\n6 8\n9 4\n9 10\n6"]
2 seconds
["27", "61"]
null
Java 8
standard input
[ "dp", "greedy", "graphs", "dsu", "dfs and similar", "trees" ]
824c7f11e6c2997c98741d314cdd1970
First line of input contains two integers $$$n$$$ and $$$m$$$, ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le m \le 2 \cdot 10^5$$$) which are numbers of cities and roads in the country. Second line contains $$$n$$$ integers $$$w_1, w_2, \ldots, w_n$$$ ($$$0 \le w_i \le 10^9$$$) which are scores of all cities. The following $$$m$$$ lines contain description of the roads. Each of these $$$m$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$) which are cities connected by this road. It is guaranteed that there is at most one direct road between any two cities, no city is connected to itself by the road and, finally, it is possible to go from any city to any other one using only roads. The last line contains single integer $$$s$$$ ($$$1 \le s \le n$$$), which is the number of the initial city.
2,200
Output single integer which is the maximum possible sum of scores of visited cities.
standard output
PASSED
0257667dc44b1b9308a281543d063fb7
train_002.jsonl
1568822700
Alex decided to go on a touristic trip over the country.For simplicity let's assume that the country has $$$n$$$ cities and $$$m$$$ bidirectional roads connecting them. Alex lives in city $$$s$$$ and initially located in it. To compare different cities Alex assigned each city a score $$$w_i$$$ which is as high as interesting city seems to Alex.Alex believes that his trip will be interesting only if he will not use any road twice in a row. That is if Alex came to city $$$v$$$ from city $$$u$$$, he may choose as the next city in the trip any city connected with $$$v$$$ by the road, except for the city $$$u$$$.Your task is to help Alex plan his city in a way that maximizes total score over all cities he visited. Note that for each city its score is counted at most once, even if Alex been there several times during his trip.
256 megabytes
import java.util.*; import java.io.*; public class Solution1{ public static Integer INT(String s){ return Integer.parseInt(s); } public static Long LONG(String s){ return Long.parseLong(s); } //==================================================================================================================== static LinkedList<Integer> adj[]; static long wt[], attach[]; static int n, m; static boolean mark[], visited[]; public static void main(String args[])throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringBuilder out=new StringBuilder(); String line[]=br.readLine().split("\\s"); n=INT(line[0]); m=INT(line[1]); wt=new long[n]; line=br.readLine().split("\\s"); for(int i=0; i<n; i++) wt[i]=LONG(line[i]); adj=new LinkedList[n+1]; for(int i=0; i<=n; i++) adj[i]=new LinkedList<>(); for(int i=0; i<m; i++){ line=br.readLine().split("\\s"); int u=INT(line[0])-1, v=INT(line[1])-1; adj[u].add(v); adj[v].add(u); } int s=INT(br.readLine())-1; mark=new boolean[n]; visited=new boolean[n]; attach=new long[n]; dfs(s, -1); long ans=0, max=0; for(int i=0; i<n; i++) if(mark[i]) ans+=wt[i]; else max=Math.max(max, attach[i]); System.out.println(ans+max); } public static void dfs(int v, int p) { visited[v]=true; for(int item: adj[v]) if(visited[item]) { if(item!=p) mark[v]=true; } else { dfs(item, v); if(mark[item]) mark[v]=mark[v]|mark[item]; else attach[v]=Math.max(attach[v], attach[item]); } if(!mark[v]) attach[v]+=wt[v]; } }
Java
["5 7\n2 2 8 6 9\n1 2\n1 3\n2 4\n3 2\n4 5\n2 5\n1 5\n2", "10 12\n1 7 1 9 3 3 6 30 1 10\n1 2\n1 3\n3 5\n5 7\n2 3\n5 4\n6 9\n4 6\n3 7\n6 8\n9 4\n9 10\n6"]
2 seconds
["27", "61"]
null
Java 8
standard input
[ "dp", "greedy", "graphs", "dsu", "dfs and similar", "trees" ]
824c7f11e6c2997c98741d314cdd1970
First line of input contains two integers $$$n$$$ and $$$m$$$, ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le m \le 2 \cdot 10^5$$$) which are numbers of cities and roads in the country. Second line contains $$$n$$$ integers $$$w_1, w_2, \ldots, w_n$$$ ($$$0 \le w_i \le 10^9$$$) which are scores of all cities. The following $$$m$$$ lines contain description of the roads. Each of these $$$m$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$) which are cities connected by this road. It is guaranteed that there is at most one direct road between any two cities, no city is connected to itself by the road and, finally, it is possible to go from any city to any other one using only roads. The last line contains single integer $$$s$$$ ($$$1 \le s \le n$$$), which is the number of the initial city.
2,200
Output single integer which is the maximum possible sum of scores of visited cities.
standard output
PASSED
e97e0fd5dea115db6bd7f3d45caa28f8
train_002.jsonl
1586788500
You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.*; import java.util.HashSet; import java.util.Set; import java.util.StringTokenizer; public class ProblemD { public static InputStream inputStream = System.in; public static OutputStream outputStream = System.out; public static void main(String[] args) { MyScanner scanner = new MyScanner(inputStream); PrintWriter out = new PrintWriter(outputStream); int t = scanner.nextInt(); for (int p = 0; p < t; p++) { int[][] board = new int[9][9]; for (int i = 0; i < 9; i++) { String s = scanner.next(); for (int j = 0; j < 9; j++) { board[i][j] = s.charAt(j) - '0'; } } for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { if (board[i][j] == 1) { out.print(2); } else { out.print(board[i][j]); } } out.println(); } } out.flush(); } private static class MyScanner { private BufferedReader bufferedReader; private StringTokenizer stringTokenizer; private MyScanner(InputStream inputStream) { bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); } private String next() { while (stringTokenizer == null || !stringTokenizer.hasMoreElements()) { try { stringTokenizer = new StringTokenizer(bufferedReader.readLine()); } catch (IOException e) { e.printStackTrace(); } } return stringTokenizer.nextToken(); } private int nextInt() { return Integer.parseInt(next()); } private long nextLong() { return Long.parseLong(next()); } private double nextDouble() { return Double.parseDouble(next()); } private String nextLine() { String str = ""; try { str = bufferedReader.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } private static class Pair<F, S> { private F first; private S second; public Pair() {} public Pair(F first, S second) { this.first = first; this.second = second; } } private static class Triple<F, S, T> { private F first; private S second; private T third; public Triple() {} public Triple(F first, S second, T third) { this.first = first; this.second = second; this.third = third; } } }
Java
["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"]
2 seconds
["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"]
null
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0e21f1c48c8c0463b2ffa7275eddc633
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β€” the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces β€” the correct solution of the sudoku puzzle.
1,300
For each test case, print the answer β€” the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists.
standard output
PASSED
b6698becda9b61f65620588ec668d63f
train_002.jsonl
1586788500
You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases.
256 megabytes
import javax.management.DynamicMBean; import javax.print.DocFlavor; import javax.print.attribute.HashAttributeSet; import java.awt.*; import java.io.BufferedReader; import java.io.CharConversionException; import java.io.IOException; import java.io.InputStreamReader; import java.nio.file.attribute.FileAttribute; import java.util.List; import java.util.Scanner; import java.util.StringTokenizer; import java.util.*; import java.util.Arrays; import java.util.concurrent.Callable; 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) { FastReader sc = new FastReader(); int t=sc.nextInt(); for(int i=0;i<t;i++){ int[][] arr=new int[10][10]; String[] s=new String[10]; int k=0; for(int j=1;j<=9;j++){ s[j]=sc.next(); if(j==1){ k=1; } else if(j==2){ k=4; } else if(j==3){ k=7; }else if(j==4){ k=2; }else if(j==5){ k=5; }else if(j==6){ k=8; }else if(j==7){ k=3; }else if(j==8){ k=6; }else if(j==9){ k=9; } int num= Character.getNumericValue(s[j].charAt(k-1)); num=num<9?num+1:1; StringBuilder sb=new StringBuilder(s[j]); sb.replace(k-1,k,String.valueOf(num)); s[j]=String.valueOf(sb); } // for(int j=1;j<=9;j++){ //// StringBuilder str=new StringBuilder(sc.next()); // int n=sc.nextInt(); // for(int k=9;k>=1;k--){ // arr[j][k]=n%10; // n/=10; //// arr[j][k]=Character.getNumericValue(str.charAt(k-1)); // if(j==1 && k==1 || j==2 && k==4 || j==3 && k==7 || j==4 && k==2 || j==5 && k==5 || j==6 && k==8 || j==7 && k==3 || j==8 && k==6 || j==9 && k==9) { // arr[j][k] = arr[j][k] < 9 ? arr[j][k] + 1 : 1; // } //// } //// System.out.print(arr[j][k]+""); // } //// System.out.println(" "); // } // int x=1,y=1; // for(int j=1;j<=3;j++){ // x=1;y=1; // if(j==2){ // x+=3;y+=1; // } // if(j==3){ // x+=6;y+=2; // } // for(int k=1;k<=3;k++){ // arr[x][y]=arr[x][y]<9?arr[x][y]+1:1; // x++; // y+=3; // } // } for(int j=1;j<=9;j++){ System.out.println(s[j]+""); } } } }
Java
["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"]
2 seconds
["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"]
null
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0e21f1c48c8c0463b2ffa7275eddc633
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β€” the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces β€” the correct solution of the sudoku puzzle.
1,300
For each test case, print the answer β€” the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists.
standard output
PASSED
33fb2b67e40e424b8ae0b9cf58e27808
train_002.jsonl
1586788500
You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.OutputStream; import java.util.*; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.util.Arrays; import java.util.InputMismatchException; import java.util.LinkedHashSet; import java.io.Writer; import java.math.BigInteger; import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.Period; import java.time.temporal.ChronoUnit; import java.io.OutputStreamWriter; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Egor Kulikov (egor@egork.net) */ public class Solution { public static void main(String[] args) throws FileNotFoundException { InputStream inputStream = System.in; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(System.out); Solutio solver = new Solutio(); int testCount =Integer.parseInt(in.next()); // int sum=in.readInt(),te=0; // if(sum==1) for (int i = 1; i <= testCount; i++) { solver.solve(i, in, out); out.flush(); } } //**********************SOLVE HERE EVERYTHING****************************** //1 2 3 4 5 static class Solutio { public void solve(int testNumber, InputReader in, PrintWriter out) throws FileNotFoundException { // int n=in.readInt(); // String arr[]=new String[n]; // for(int i=0;i<n;i++) // { // arr[i]=in.readString(); // } // Arrays.sort(arr,new StringComparator()); // String k=""; // int st=-1,en=-1; // for(int i=0;i<n;i++) // { // if(arr[i].charAt(0)!='*') // { // st=i; // } // if(arr[i].charAt(arr[i].length()-1)!='*') // { // en=i; // } // // } // if(st!=-1) // { // char ch=arr[st].charAt(0); // for(int i=0;i<n;i++) // { // if(arr[i].charAt(0)!='*' && arr[i].charAt(0)!=ch) // { // System.out.println("Case #"+testNumber+": *"); // return; // } // } // // } // if(en!=-1) // { // char ch=arr[en].charAt(arr[en].length()-1); // for(int i=0;i<n;i++) // { // if(arr[i].charAt(arr[i].length()-1)!='*' && arr[i].charAt(arr[i].length()-1)!=ch) // { // System.out.println("Case #"+testNumber+": *"); // return; // } // } // // } // int n=in.readInt(); // int arr[]=new int[n]; // int ch[]=new int[n+1]; // for(int i=0;i<n;i++) { // arr[i]=in.readInt(); // ch[arr[i]]++; // } // int max=0,ind=-1; // for(int i=1;i<=n;i++) // { // if(ch[i]>max) // { // max=ch[i]; // ind=i; // } // } // int dis=0; // for(int i=1;i<=n;i++) // { // if(ch[i]>0 && i!=ind) // { // dis++; // } // } // if(dis<max) // { // dis++; // max--; // } // if(max<dis) // { // System.out.println(max);return; // } // if(max==dis) // { // System.out.println(max);return; // } // System.out.println(Math.max(max, dis)); // // StringBuffer s; int arr[][]=new int[9][9]; for(int i=0;i<9;i++) { s=new StringBuffer(in.readString()); for(int j=0;j<9;j++) { arr[i][j]=Character.getNumericValue(s.charAt(j)); } } int j=0,k=1; for(int i=0;i<20;i+=3,j++) { if(i>=9) { i=1+i-9;} if(arr[i][j]==1) arr[i][j]=2; else arr[i][j]=1; if(i==8) break; } for(int i=0;i<9;i++) { for(j=0;j<9;j++) out.print(arr[i][j]); out.println(); } } } static class StringComparator implements Comparator<String> { @Override public int compare(String arg0, String arg1) { return arg0.length()-arg1.length(); } } static ArrayList<Integer> primeSieve(int n) { ArrayList<Integer> li=new ArrayList<Integer>(); li.add(1); boolean prime[] = new boolean[n+1]; for(int i=0;i<n;i++) prime[i] = true; for(int p = 2; p*p <=n; p++) { // If prime[p] is not changed, then it is a prime if(prime[p] == true) { // Update all multiples of p for(int i = p*2; i <= n; i += p) prime[i] = false; } } for(int i = 2; i <= n; i++) { if(prime[i] == true) li.add(i); } return li; } static class Tree { } //*********************END HERE EVERYTHING******************************* 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 void readIntArrays(int[]... arrays) { for (int i = 0; i < arrays[0].length; i++) { for (int j = 0; j < arrays.length; j++) { arrays[j][i] = readInt(); } } } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int readInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { if (Character.isValidCodePoint(c)) { res.appendCodePoint(c); } c = read(); } while (!isSpaceChar(c)); return res.toString(); } 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 String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } } public void printLine(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } } }
Java
["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"]
2 seconds
["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"]
null
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0e21f1c48c8c0463b2ffa7275eddc633
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β€” the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces β€” the correct solution of the sudoku puzzle.
1,300
For each test case, print the answer β€” the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists.
standard output
PASSED
7ecf99357d515b9d581c199e53fecd19
train_002.jsonl
1586788500
You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases.
256 megabytes
// Magic. Do not touch. import java.io.*; import java.math.*; import java.util.*; public class Main { static class FastReader { private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public FastReader() { this(System.in); }public FastReader(InputStream is) { mIs = is;} public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];} public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;} public String next(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();} public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;} public int i(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;} public double d() throws IOException {return Double.parseDouble(next()) ;} public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public void scanIntArr(int [] arr){ for(int li=0;li<arr.length;++li){ arr[li]=i();}} public void scanIntIndexArr(int [] arr){ for(int li=0;li<arr.length;++li){ arr[li]=i()-1;}} public void scanLongArr(long [] arr){for (int i=0;i<arr.length;++i){arr[i]=l();}} public void shuffle(int [] arr){ for(int i=arr.length;i>0;--i) { int r=(int)(Math.random()*i); int temp=arr[i-1]; arr[i-1]=arr[r]; arr[r]=temp; } } public int swapIntegers(int a,int b){return a;} //Call it like this: a=swapIntegers(b,b=a) } public static void main(String[] args) throws IOException { FastReader fr = new FastReader(); PrintWriter pw = new PrintWriter(System.out); /* inputCopy 1 154873296 386592714 729641835 863725149 975314628 412968357 631457982 598236471 247189563 outputCopy 154873396 336592714 729645835 863725145 979314628 412958357 631457992 998236471 247789563 */ //Press Ctrl+Win+Alt+L for reformatting indentation int t = fr.i(); for (int ti = 0; ti < t; ++ti) { char[][] arr = new char[9][9]; for (int ni = 0; ni < 9; ++ni) arr[ni] = fr.nextLine().toCharArray(); change(arr, 0, 0); change(arr, 1, 3); change(arr, 2, 6); change(arr, 3, 1); change(arr, 4, 4); change(arr, 5, 7); change(arr, 6, 2); change(arr, 7, 5); change(arr, 8, 8); for (char[] ans : arr) pw.println(String.valueOf(ans)); } pw.flush(); pw.close(); } private static void change(char[][] arr, int i, int j) { if (arr[i][j] != '1') arr[i][j] = '1'; else arr[i][j] = '2'; } }
Java
["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"]
2 seconds
["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"]
null
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0e21f1c48c8c0463b2ffa7275eddc633
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β€” the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces β€” the correct solution of the sudoku puzzle.
1,300
For each test case, print the answer β€” the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists.
standard output
PASSED
a6f30f5f49307e70c7dd3ab88061eb6c
train_002.jsonl
1586788500
You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases.
256 megabytes
// Magic. Do not touch. import java.io.*; import java.math.*; import java.util.*; public class Main { static class FastReader { private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public FastReader() { this(System.in); }public FastReader(InputStream is) { mIs = is;} public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];} public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;} public String next(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();} public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;} public int i(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;} public double d() throws IOException {return Double.parseDouble(next()) ;} public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public void scanIntArr(int [] arr){ for(int li=0;li<arr.length;++li){ arr[li]=i();}} public void scanIntIndexArr(int [] arr){ for(int li=0;li<arr.length;++li){ arr[li]=i()-1;}} public void scanLongArr(long [] arr){for (int i=0;i<arr.length;++i){arr[i]=l();}} public void shuffle(int [] arr){ for(int i=arr.length;i>0;--i) { int r=(int)(Math.random()*i); int temp=arr[i-1]; arr[i-1]=arr[r]; arr[r]=temp; } } public int swapIntegers(int a,int b){return a;} //Call it like this: a=swapIntegers(b,b=a) } static char [][] arr; public static void main(String[] args) throws IOException { FastReader fr = new FastReader(); PrintWriter pw = new PrintWriter(System.out); /* inputCopy 1 154873296 386592714 729641835 863725149 975314628 412968357 631457982 598236471 247189563 outputCopy 154873396 336592714 729645835 863725145 979314628 412958357 631457992 998236471 247789563 */ //Press Ctrl+Win+Alt+L for reformatting indentation int t = fr.i(); for (int ti = 0; ti < t; ++ti) { arr = new char[9][9]; for (int ni = 0; ni < 9; ++ni) arr[ni] = fr.nextLine().toCharArray(); for(int i=0;i<9;++i) for(int j=0;j<9;++j) if(arr[i][j]=='2') arr[i][j]='1'; for (char[] ans : arr) pw.println(String.valueOf(ans)); } pw.flush(); pw.close(); } }
Java
["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"]
2 seconds
["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"]
null
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0e21f1c48c8c0463b2ffa7275eddc633
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β€” the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces β€” the correct solution of the sudoku puzzle.
1,300
For each test case, print the answer β€” the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists.
standard output
PASSED
72716d385bc8f484afbd4790eb9f9249
train_002.jsonl
1586788500
You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases.
256 megabytes
// Magic. Do not touch. import java.io.*; import java.math.*; import java.util.*; public class Main { static class FastReader { private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public FastReader() { this(System.in); }public FastReader(InputStream is) { mIs = is;} public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];} public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;} public String next(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();} public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;} public int i(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;} public double d() throws IOException {return Double.parseDouble(next()) ;} public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public void scanIntArr(int [] arr){ for(int li=0;li<arr.length;++li){ arr[li]=i();}} public void scanIntIndexArr(int [] arr){ for(int li=0;li<arr.length;++li){ arr[li]=i()-1;}} public void scanLongArr(long [] arr){for (int i=0;i<arr.length;++i){arr[i]=l();}} public void shuffle(int [] arr){ for(int i=arr.length;i>0;--i) { int r=(int)(Math.random()*i); int temp=arr[i-1]; arr[i-1]=arr[r]; arr[r]=temp; } } public int swapIntegers(int a,int b){return a;} //Call it like this: a=swapIntegers(b,b=a) } static char [][] arr; public static void main(String[] args) throws IOException { FastReader fr = new FastReader(); PrintWriter pw = new PrintWriter(System.out); /* inputCopy 1 154873296 386592714 729641835 863725149 975314628 412968357 631457982 598236471 247189563 outputCopy 154873396 336592714 729645835 863725145 979314628 412958357 631457992 998236471 247789563 */ //Press Ctrl+Win+Alt+L for reformatting indentation int t = fr.i(); for (int ti = 0; ti < t; ++ti) { arr = new char[9][9]; for (int ni = 0; ni < 9; ++ni) arr[ni] = fr.nextLine().toCharArray(); change(0, 0); change(1, 3); change(2, 6); change(3, 1); change(4, 4); change(5, 7); change(6, 2); change(7, 5); change(8, 8); for (char[] ans : arr) pw.println(String.valueOf(ans)); } pw.flush(); pw.close(); } private static void change(int i, int j) { if (arr[i][j] != '1') arr[i][j] = '1'; else arr[i][j] = '2'; } }
Java
["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"]
2 seconds
["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"]
null
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0e21f1c48c8c0463b2ffa7275eddc633
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β€” the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces β€” the correct solution of the sudoku puzzle.
1,300
For each test case, print the answer β€” the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists.
standard output
PASSED
dab74cdb68d5a503d2845153087a70a3
train_002.jsonl
1586788500
You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases.
256 megabytes
/* Sugoi */ import java.util.*; import java.io.*; import java.math.*; public class D { public static void main(String arima[]) throws Exception { BufferedReader infile = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(infile.readLine()); int T = Integer.parseInt(st.nextToken()); StringBuilder sb = new StringBuilder(); while(T-->0) { int[][] grid = new int[9][9]; int[][] res = new int[9][9]; for(int i=0; i < 9; i++) { String input = infile.readLine(); for(int a=0; a < 9; a++) { grid[i][a] = Integer.parseInt(input.substring(a,a+1)); res[i][a] = grid[i][a]; } } change(grid, res, 0, 0); change(grid, res, 1, 3); change(grid, res, 2, 6); change(grid, res, 3, 1); change(grid, res, 4, 4); change(grid, res, 5, 7); change(grid, res, 6, 2); change(grid, res, 7, 5); change(grid, res, 8, 8); for(int i=0; i < 9; i++) { for(int x: res[i]) sb.append(x); sb.append("\n"); } } System.out.print(sb); } public static void change(int[][] grid, int[][] res, int x, int y) { if(grid[x][y] != 1) res[x][y] = 1; else res[x][y] = 2; } }
Java
["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"]
2 seconds
["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"]
null
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0e21f1c48c8c0463b2ffa7275eddc633
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β€” the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces β€” the correct solution of the sudoku puzzle.
1,300
For each test case, print the answer β€” the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists.
standard output
PASSED
45881a85dd8284fd6b9ce0d246ddbca5
train_002.jsonl
1586788500
You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.*; public class Solution { public static void main(String[] args){ try{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(br.readLine()); for(int i=0;i<t;i++){ int[][] arr=new int[9][9]; for(int j=0;j<9;j++){ String[] ss=br.readLine().split(""); for(int k=0;k<9;k++){ arr[j][k]=Integer.parseInt(ss[k]); } } int u=0; for(int j=0;j<9;j++){ if(arr[j][u]==9){ arr[j][u]=8; }else { arr[j][u] = arr[j][u] + 1; } u=(u+3)%9; if(u==0){ u=1; }else if(u==1){ u=2; } } StringBuilder str; for(int j=0;j<9;j++){ str=new StringBuilder(""); for(int k=0;k<9;k++){ str.append(arr[j][k]); } System.out.println(str); } } }catch(Exception e){ System.out.println("KKKK "+e.getMessage()); } } static void swap(int i,int j,int a,int b,int[][] arr){ int temp=arr[i][j]; arr[i][j]=arr[a][b]; arr[a][b]=temp; } }
Java
["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"]
2 seconds
["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"]
null
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0e21f1c48c8c0463b2ffa7275eddc633
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β€” the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces β€” the correct solution of the sudoku puzzle.
1,300
For each test case, print the answer β€” the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists.
standard output
PASSED
67ef30d6ce34d20211932529a7fcc20a
train_002.jsonl
1586788500
You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; public class D { public static void main(String args[]) { Scanner scn = new Scanner(System.in); int t = scn.nextInt(); scn.nextLine(); while (t-- > 0) { for (int i = 0; i < 9; ++i) { char c[] = scn.nextLine().toCharArray(); for (int j = 0; j < 9; ++j) { if (c[j] == '1') { c[j] = '2'; } } System.out.println(String.valueOf(c)); } } } private static char givechar(int no) { return String.valueOf(no).charAt(0); } }
Java
["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"]
2 seconds
["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"]
null
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0e21f1c48c8c0463b2ffa7275eddc633
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β€” the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces β€” the correct solution of the sudoku puzzle.
1,300
For each test case, print the answer β€” the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists.
standard output
PASSED
8a85fb731fefbf63b54ffd85bf6c5fc9
train_002.jsonl
1586788500
You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; import java.io.*; public class try20 { public static void main(String[] args)throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(br.readLine()); while(t-->0) { int ar[][]=new int[9][9]; for(int i=0;i<9;i++) { String s=br.readLine(); String s1=s.replace('2','3'); System.out.println(s1); } } } }
Java
["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"]
2 seconds
["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"]
null
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0e21f1c48c8c0463b2ffa7275eddc633
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β€” the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces β€” the correct solution of the sudoku puzzle.
1,300
For each test case, print the answer β€” the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists.
standard output
PASSED
1e14255e925173cfa2f9da123a0e8124
train_002.jsonl
1586788500
You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.io.*; public class AntiSudoku { static Integer[] dp; static int INF = (int) 1e9 + 7; public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); int T = Integer.parseInt(in.readLine()); char[][] arr = new char[9][9]; while (T-- > 0) { for (int i = 0; i < 9; i++) { arr[i] = in.readLine().toCharArray(); } for (int i = 0, j = 0; i < 9; i += 3, j = (j + 1) % 3) { for (int x = i; x < i + 3; x++, j += 3) { arr[x][j] = arr[x][j] == '1' ? '2' : '1'; } } for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { out.print(arr[i][j]); } out.println(); } } out.close(); in.close(); } }
Java
["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"]
2 seconds
["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"]
null
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0e21f1c48c8c0463b2ffa7275eddc633
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β€” the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces β€” the correct solution of the sudoku puzzle.
1,300
For each test case, print the answer β€” the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists.
standard output
PASSED
27f90227ea3e683f222b84ebd0efca9f
train_002.jsonl
1586788500
You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which: Any number in this field is in range $$$[1; 9]$$$; each row contains at least two equal elements; each column contains at least two equal elements; each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases.
256 megabytes
import java.util.*; import java.io.*; public class OO7 { public static void main(String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int T=Integer.parseInt(br.readLine()); while(T-->0) { String[] s=new String[9]; for(int i=0;i<9;i++) { s[i]=br.readLine(); s[i]=s[i].replace("1", "2"); System.out.println(s[i]); } } } }
Java
["1\n154873296\n386592714\n729641835\n863725149\n975314628\n412968357\n631457982\n598236471\n247189563"]
2 seconds
["154873396\n336592714\n729645835\n863725145\n979314628\n412958357\n631457992\n998236471\n247789563"]
null
Java 8
standard input
[ "constructive algorithms", "implementation" ]
0e21f1c48c8c0463b2ffa7275eddc633
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) β€” the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces β€” the correct solution of the sudoku puzzle.
1,300
For each test case, print the answer β€” the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists.
standard output
PASSED
60c72c7ff26bef7aec5b83ef8307e2f1
train_002.jsonl
1395502200
This problem has nothing to do with Little Chris. It is about hill climbers instead (and Chris definitely isn't one).There are n hills arranged on a line, each in the form of a vertical line segment with one endpoint on the ground. The hills are numbered with numbers from 1 to n from left to right. The i-th hill stands at position xi with its top at height yi. For every two hills a and b, if the top of hill a can be seen from the top of hill b, their tops are connected by a rope. Formally, the tops of two hills are connected if the segment connecting their top points does not intersect or touch any of the other hill segments. Using these ropes, the hill climbers can move from hill to hill.There are m teams of climbers, each composed of exactly two members. The first and the second climbers of the i-th team are located at the top of the ai-th and bi-th hills, respectively. They want to meet together at the top of some hill. Now, each of two climbers move according to the following process: if a climber is at the top of the hill where the other climber is already located or will come eventually, the former climber stays at this hill; otherwise, the climber picks a hill to the right of his current hill that is reachable by a rope and is the rightmost possible, climbs this hill and continues the process (the climber can also climb a hill whose top is lower than the top of his current hill). For each team of climbers, determine the number of the meeting hill for this pair!
256 megabytes
import java.io.*; import java.util.*; public class HillClimbing { static class Hill{ int x; long y; Hill(int x, long y){ this.x=x; this.y=y; } } static class Climbers{ int a, b; Climbers(int a,int b){ this.a =a; this.b =b; } } public static int [][] hull; public static int [] level; public static int [] depth; public static Hill[] hills; public static Climbers[] climbers; public static int m,n; public static int lca(int a, int b){ if(level[a] > level[b]){ int tmp = a; a=b; b=tmp; } int d = level[b] - level[a]; for(int i = 0; i < 18; i++){ if(((d>>i)&1) != 0) b = hull[i][b]; } if(a==b) return b; for(int i = 17; i >= 0; i--){ if(hull[i][b] != hull[i][a]){ a = hull[i][a]; b = hull[i][b]; } } return hull[0][a]; } public static long cross(int i, int j, int k){ return (hills[j].x-hills[i].x)*(hills[k].y-hills[i].y) - (hills[k].x-hills[i].x)*(hills[j].y-hills[i].y); } public static void convexHull(PrintWriter pw){ int size=1; hull[0][n-1]=n-1; depth = new int[n]; depth[0] = n-1; for(int i = n-2; i >= 0; i--){ while (size >= 2){ int j = depth[size-1]; int k = depth[size-2]; if(cross(i,j,k)<= 0) break; --size; } hull[0][i] = depth[size-1]; depth[size++] = i; } for(int i = 1; i < 18; i++) for(int j = 0; j < n; j++) hull[i][j]= hull[i-1][hull[i-1][j]]; for(int i = n-2; i >= 0; i--) level[i] = level[hull[0][i]] + 1; for(int i=0;i<m;i++){ pw.println(lca(climbers[i].a,climbers[i].b) + 1); } } public static void main(String[] args) { PrintWriter pw = new PrintWriter(System.out); Scanner cin= new Scanner(System.in); n = cin.nextInt(); hull = new int[18][n]; level = new int[n]; hills= new Hill[n]; for(int i = 0; i < n; i++){ int x = cin.nextInt(); long y= cin.nextLong(); hills[i]= new Hill(x,y); } m= cin.nextInt(); climbers= new Climbers[m]; for (int i=0;i<m;i++){ int a=cin.nextInt()-1; int b= cin.nextInt()-1; climbers[i]= new Climbers(a,b); } convexHull(pw); pw.close(); } }
Java
["6\n1 4\n2 1\n3 2\n4 3\n6 4\n7 4\n3\n3 1\n5 6\n2 3"]
1 second
["5 6 3"]
null
Java 11
standard input
[ "geometry", "trees", "dfs and similar" ]
b8438567bb30f91e165502f1dc365546
The first line of input contains a single integer n (1 ≀ n ≀ 105), the number of hills. The next n lines describe the hills. The i-th of them contains two space-separated integers xi, yi (1 ≀ xi ≀ 107; 1 ≀ yi ≀ 1011), the position and the height of the i-th hill. The hills are given in the ascending order of xi, i.e., xi &lt; xj for i &lt; j. The next line of input contains a single integer m (1 ≀ m ≀ 105), the number of teams. The next m lines describe the teams. The i-th of them contains two space-separated integers ai, bi (1 ≀ ai, bi ≀ n), the numbers of the hills where the climbers of the i-th team are located. It is possible that ai = bi.
2,200
In a single line output m space-separated integers, where the i-th integer is the number of the meeting hill for the members of the i-th team.
standard output
PASSED
6c3d026028b211f6d5b238292886063e
train_002.jsonl
1395502200
This problem has nothing to do with Little Chris. It is about hill climbers instead (and Chris definitely isn't one).There are n hills arranged on a line, each in the form of a vertical line segment with one endpoint on the ground. The hills are numbered with numbers from 1 to n from left to right. The i-th hill stands at position xi with its top at height yi. For every two hills a and b, if the top of hill a can be seen from the top of hill b, their tops are connected by a rope. Formally, the tops of two hills are connected if the segment connecting their top points does not intersect or touch any of the other hill segments. Using these ropes, the hill climbers can move from hill to hill.There are m teams of climbers, each composed of exactly two members. The first and the second climbers of the i-th team are located at the top of the ai-th and bi-th hills, respectively. They want to meet together at the top of some hill. Now, each of two climbers move according to the following process: if a climber is at the top of the hill where the other climber is already located or will come eventually, the former climber stays at this hill; otherwise, the climber picks a hill to the right of his current hill that is reachable by a rope and is the rightmost possible, climbs this hill and continues the process (the climber can also climb a hill whose top is lower than the top of his current hill). For each team of climbers, determine the number of the meeting hill for this pair!
256 megabytes
import java.io.*; import java.util.*; public class HillClimbing { static class Hill{ int x; long y; Hill(int x, long y){ this.x=x; this.y=y; } } static class Climbers{ int a, b; Climbers(int a,int b){ this.a =a; this.b =b; } } public static int [][] hull; public static int [] level; public static int [] depth; public static Hill[] hills; public static Climbers[] climbers; public static int m,n; public static int LCA(int a, int b){ if(level[a] > level[b]){ int tmp = a; a=b; b=tmp; } int d = level[b] - level[a]; for(int i = 0; i < 18; i++){ if(((d>>i)&1) != 0) b = hull[i][b]; } if(a==b) return b; for(int i = 17; i >= 0; i--){ if(hull[i][b] != hull[i][a]){ a = hull[i][a]; b = hull[i][b]; } } return hull[0][a]; } public static long cross(int i, int j, int k){ return (hills[j].x-hills[i].x)*(hills[k].y-hills[i].y) - (hills[k].x-hills[i].x)*(hills[j].y-hills[i].y); } public static void convexHull(PrintWriter pw){ depth = new int[n]; depth[0] = n-1; int size=1; hull[0][n-1]=n-1; for(int i = n-2; i >= 0; i--){ while (size >= 2){ int j = depth[size-1]; int k = depth[size-2]; if(cross(i,j,k)<= 0)break; --size; } hull[0][i] = depth[size-1]; depth[size++] = i; } for(int i = 1; i < 18; i++) for(int j = 0; j < n; j++) hull[i][j]= hull[i-1][hull[i-1][j]]; for(int i = n-2; i >= 0; i--) level[i] = level[hull[0][i]] + 1; for(int i=0;i<m;i++){ pw.println(LCA(climbers[i].a,climbers[i].b) + 1); } } public static void main(String[] args) { PrintWriter pw = new PrintWriter(System.out); Scanner cin= new Scanner(System.in); n = cin.nextInt(); hull = new int[18][n]; level = new int[n]; hills= new Hill[n]; for(int i = 0; i < n; i++){ int x = cin.nextInt(); long y= cin.nextLong(); hills[i]= new Hill(x,y); } m= cin.nextInt(); climbers= new Climbers[m]; for (int i=0;i<m;i++){ int a=cin.nextInt()-1; int b= cin.nextInt()-1; climbers[i]= new Climbers(a,b); } convexHull(pw); pw.close(); } }
Java
["6\n1 4\n2 1\n3 2\n4 3\n6 4\n7 4\n3\n3 1\n5 6\n2 3"]
1 second
["5 6 3"]
null
Java 11
standard input
[ "geometry", "trees", "dfs and similar" ]
b8438567bb30f91e165502f1dc365546
The first line of input contains a single integer n (1 ≀ n ≀ 105), the number of hills. The next n lines describe the hills. The i-th of them contains two space-separated integers xi, yi (1 ≀ xi ≀ 107; 1 ≀ yi ≀ 1011), the position and the height of the i-th hill. The hills are given in the ascending order of xi, i.e., xi &lt; xj for i &lt; j. The next line of input contains a single integer m (1 ≀ m ≀ 105), the number of teams. The next m lines describe the teams. The i-th of them contains two space-separated integers ai, bi (1 ≀ ai, bi ≀ n), the numbers of the hills where the climbers of the i-th team are located. It is possible that ai = bi.
2,200
In a single line output m space-separated integers, where the i-th integer is the number of the meeting hill for the members of the i-th team.
standard output
PASSED
cfa5b2326d98b850ddb582dce9f8388e
train_002.jsonl
1361374200
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x &lt; y) from the set, such that y = xΒ·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
256 megabytes
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; import java.util.TreeSet; public class KMultiple_Free_Set_275C { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int[] arr = new int[n]; TreeSet<Long> removed = new TreeSet<>(); for(int i=0;i<n;i++){ arr[i] = sc.nextInt(); } int ans = n; Arrays.sort(arr); for (int i = 0; i < arr.length; i++) { int x = arr[i]; if(removed.contains(1l * x)){ ans--; continue; } removed.add(1l * x * k); } System.out.println(ans); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(String s) throws FileNotFoundException { br = new BufferedReader(new FileReader(new File(s))); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public boolean ready() throws IOException { return br.ready(); } } }
Java
["6 2\n2 3 6 5 4 10"]
2 seconds
["3"]
NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
Java 8
standard input
[ "binary search", "sortings", "greedy" ]
4ea1de740aa131cae632c612e1d582ed
The first line of the input contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). All the numbers in the lines are separated by single spaces.
1,500
On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}.
standard output
PASSED
740b31c3c398b401ebdc2788716be0db
train_002.jsonl
1361374200
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x &lt; y) from the set, such that y = xΒ·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
256 megabytes
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) { FastReader in = new FastReader(); int n = in.nextInt(), k = in.nextInt(); int[] x = new int[n]; Set<Integer> set = new HashSet<Integer>(); for (int i = 0; i < n; i++) { x[i] = in.nextInt(); set.add(x[i]); } if (k == 1) { System.out.println(n); return; } Arrays.sort(x); int count = 0; Set<Integer> removedSet = new HashSet<Integer>(); for (int i = n - 1; i >= 0; i--) { if (!removedSet.contains(x[i])) { int val = x[i]; if (set.contains(val / k) && val % k == 0) { removedSet.add(val / k); } count++; } } System.out.println(count); } } 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; } }
Java
["6 2\n2 3 6 5 4 10"]
2 seconds
["3"]
NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
Java 8
standard input
[ "binary search", "sortings", "greedy" ]
4ea1de740aa131cae632c612e1d582ed
The first line of the input contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). All the numbers in the lines are separated by single spaces.
1,500
On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}.
standard output
PASSED
690e6940e879e7cc878148c9d3b3e1bd
train_002.jsonl
1361374200
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x &lt; y) from the set, such that y = xΒ·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
256 megabytes
//codeforces_275C import java.io.*; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; import static java.lang.Math.*; import java.math.*; public class acm{ static PrintWriter go = new PrintWriter(System.out); public static void main(String args[]) throws IOException,FileNotFoundException { BufferedReader gi = new BufferedReader(new InputStreamReader(System.in)); int[] l = parseArray(gi); int n = l[0]; int m = l[1]; Set<Integer> s = new HashSet<>(); l = parseArray(gi); for ( int k = 0; k < n; k++){ s.add(l[k]); } Arrays.sort(l); for ( int k = 0; k < n; k++){ if ( l[k]%m == 0 && l[k]/m != l[k] && s.contains(l[k]/m) ){ s.remove(l[k]); } } go.println(s.size()); go.close(); } static int[] parseArray(BufferedReader gi) throws IOException{ String[] line = gi.readLine().split(" "); int[] rez = new int[line.length]; for ( int k = 0; k < line.length; k++){ rez[k] = Integer.parseInt(line[k]); } return rez; } }
Java
["6 2\n2 3 6 5 4 10"]
2 seconds
["3"]
NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
Java 8
standard input
[ "binary search", "sortings", "greedy" ]
4ea1de740aa131cae632c612e1d582ed
The first line of the input contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). All the numbers in the lines are separated by single spaces.
1,500
On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}.
standard output
PASSED
29d7cb50dcdc8e7414be049ff51fe573
train_002.jsonl
1361374200
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x &lt; y) from the set, such that y = xΒ·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
256 megabytes
/* / οΎŒοΎŒβ €β €β €β €β €β €β €β €β €β €β €β €γƒ  / )\β €β €β €β €β €β €β €β €β €β €β €β € Y (β €β €| ( Ν‘Β° ΝœΚ– Ν‘Β°οΌ‰β €βŒ’(β € γƒŽ (β € οΎ‰βŒ’ Y βŒ’γƒ½-く __/ | _β €ο½‘γƒŽ| γƒŽο½‘ |/ (β €γƒΌ '_δΊΊ`γƒΌ οΎ‰ β €|\ οΏ£ _δΊΊ'彑ノ β € )\β €β € q⠀⠀ / β €β €(\β € #β € / β €/β €β €β €/α½£====================D- /β €β €β €/β € \ \β €β €\ ( (β €)β €β €β €β € ) ).β €) (β €β €)β €β €β €β €β €( | / |β € /β €β €β €β €β €β € | / [_] β €β €β €β €β €[___] */ // Main Code at the Bottom import java.util.*; import java.lang.*; import java.io.*; import java.math.BigInteger; public class Main { //Fast IO class static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { boolean env=System.getProperty("ONLINE_JUDGE") != null; if(!env) { try { br=new BufferedReader(new FileReader("src\\input.txt")); } catch (FileNotFoundException e) { e.printStackTrace(); } } else 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 long MOD=1000000000+7; //Euclidean Algorithm static long gcd(long A,long B){ return (B==0)?A:gcd(B,A%B); } //Modular Exponentiation static long fastExpo(long x,long n){ if(n==0) return 1; if((n&1)==0) return fastExpo((x*x)%MOD,n/2)%MOD; return ((x%MOD)*fastExpo((x*x)%MOD,(n-1)/2))%MOD; } //Modular Inverse static long inverse(long x) { return fastExpo(x,MOD-2); } //Prime Number Algorithm static boolean isPrime(long n){ if(n<=1) return false; if(n<=3) return true; if(n%2==0 || n%3==0) return false; for(int i=5;i*i<=n;i+=6) if(n%i==0 || n%(i+2)==0) return false; return true; } //Reverse an array static void reverse(char arr[],int l,int r){ while(l<r) { char tmp=arr[l]; arr[l++]=arr[r]; arr[r--]=tmp; } } //Print array static void print1d(int arr[]) { out.println(Arrays.toString(arr)); } static void print2d(int arr[][]) { for(int a[]: arr) out.println(Arrays.toString(a)); } // Pair static class pair{ int x,y; pair(int a,int b){ this.x=a; this.y=b; } public boolean equals(Object obj) { if(obj == null || obj.getClass()!= this.getClass()) return false; pair p = (pair) obj; return (this.x==p.x && this.y==p.y); } public int hashCode() { return Objects.hash(x,y); } } static FastReader sc=new FastReader(); static PrintWriter out=new PrintWriter(System.out); //Main function(The main code starts from here public static void main (String[] args) throws java.lang.Exception { int test=1; //test=sc.nextInt(); while(test-->0){ int n=sc.nextInt(),k=sc.nextInt(); long a[]=new long[n]; TreeSet<Long> set=new TreeSet<>(); for(int i=0;i<n;i++) set.add(a[i]=sc.nextLong()); Arrays.parallelSort(a); HashMap<Long,Integer> map=new HashMap<>(); for(long x: a) map.merge(x, 1, Integer::sum); if(k==1) { out.println(set.size()); continue; } int ans=0; for(Long x: set) { long val=x; int p0=0,p1=0; if(val%k==0 && map.get(val/k)!=null) continue; while(map.get(val)!=null) { int tmp=p1; p1=map.get(val)+p0; p0=Math.max(p0, tmp); val*=k; } ans+=Math.max(p0, p1); } out.println(ans); } out.flush(); out.close(); } }
Java
["6 2\n2 3 6 5 4 10"]
2 seconds
["3"]
NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
Java 8
standard input
[ "binary search", "sortings", "greedy" ]
4ea1de740aa131cae632c612e1d582ed
The first line of the input contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). All the numbers in the lines are separated by single spaces.
1,500
On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}.
standard output
PASSED
583d4f8fc0ffc5de3b8584e5bdf26e7d
train_002.jsonl
1361374200
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x &lt; y) from the set, such that y = xΒ·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
256 megabytes
import java.io.*; import java.math.BigInteger; import java.util.*; public class TaskC { static Integer[][]dp; static int n, m, ans; static String s; static TreeSet<Integer> primes; static void generatePrimes() { primes = new TreeSet<>(); primes.add(2); for (int i = 3 ; i <= (1e6) ; i++,++i) { int j = 2; boolean isPrime = true; while (1l*j*j <= i) { if(i%j == 0) { isPrime = false; break; } j++; } if(isPrime)primes.add(i); } } public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int n = sc.nextInt(); int k = sc.nextInt(); Integer[]arr = new Integer[n]; TreeSet<Long> ans = new TreeSet<>(); HashSet<Long> set = new HashSet<>(); for (int i = 0 ; i < n ; i++) set.add(1l*(arr[i] = sc.nextInt())); Arrays.sort(arr); for (int i = 0 ; i < n ; i++) { // System.out.println(arr[i]/k); if ((arr[i] % k == 0 && !ans.contains(1l*arr[i] / k))) ans.add(1l * arr[i]); else if (arr[i] % k != 0) ans.add(1l * arr[i]); } pw.print(ans.size()); // System.out.println(ans); pw.close(); } private static long gcd(long a, long b) { if( b == 0) return a; return gcd(b , a%b); } static long lcm(int a, int b) { return (a*b)/gcd(a, b); } private static int dis(int xa , int ya , int xb , int yb) { return (xa-xb)*(xa - xb) + (ya- yb)*(ya-yb); } static class Pair implements Comparable<Pair> { double x,y; public Pair(double x, double y) { this.x = x; this.y = y; } public int compareTo(Pair o) { /* if (x == o.x) return y - o.y; return x - o.x;*/ return 0; } public double dis(Pair a){ return (a.x - x)*(a.x - x) + (a.y-y)*(a.y-y); } public String toString() { return x+" "+ y; } public boolean overlap(Pair a) { if((this.x >= a.x && this.x <= a.y) || (a.x >= this.x && a.x <= this.y)) return true; return false; } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(FileReader r) { br = new BufferedReader(r); } public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return st.nextToken(); } public boolean check() { if (!st.hasMoreTokens()) return false; return true; } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public String nextLine() { try { return br.readLine(); } catch (Exception e) { throw new RuntimeException(e); } } public double nextDouble() { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public boolean ready() { try { return br.ready(); } catch (IOException e) { throw new RuntimeException(e); } } } }
Java
["6 2\n2 3 6 5 4 10"]
2 seconds
["3"]
NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
Java 8
standard input
[ "binary search", "sortings", "greedy" ]
4ea1de740aa131cae632c612e1d582ed
The first line of the input contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). All the numbers in the lines are separated by single spaces.
1,500
On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}.
standard output
PASSED
2f5858476f7486ef46ac672d6abe00c2
train_002.jsonl
1361374200
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x &lt; y) from the set, such that y = xΒ·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
256 megabytes
/* * Remember a 7.0 student can know more than a 10.0 student. * Grades don't determine intelligence, they test obedience. * I Never Give Up. */ import java.util.*; import java.util.Map.Entry; import java.io.*; import java.text.*; import static java.lang.System.out; import static java.util.Arrays.*; import static java.lang.Math.*; public class ContestMain { private static Reader in=new Reader(); private static StringBuilder ans=new StringBuilder(); private static long MOD=1000000000+7;//10^9+7 private static final int N=100000+7; //10^5+7 private static final double EPS=1e-9; // private static final int LIM=26; // private static final double PI=3.1415; // private static ArrayList<Integer> v[]=new ArrayList[N]; // private static int color[]=new int[N]; // private static boolean mark[]=new boolean[N]; // private static BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); // private static void dfs(int node){mark[node]=true;for(int x:v[node]){if(!mark[x]){dfs(x);}}} private static long powmod(long x,long n){ if(n==0||x==0)return 1; else if(n%2==0)return(powmod((x*x)%MOD,n/2)); else return (x*(powmod((x*x)%MOD,(n-1)/2)))%MOD; } // private static void shuffle(long [] arr) { // for (int i = arr.length - 1; i >= 2; i--) { // int x = new Random().nextInt(i - 1); // long temp = arr[x]; // arr[x] = arr[i]; // arr[i] = temp; // } // } private static long gcd(long a, long b){ if(b==0)return a; return gcd(b,a%b); } // private static boolean check(int x,int y){ // if((x>=0&&x<n)&&(y>=0&&y<m)&&mat[x][y]!='X'&&!visited[x][y])return true; // return false; // } // static class Node{ // int x,y,c; // Node(int x,int y,int c){ // this.x=x; // this.y=y; // this.c=c; // } // } public static void main(String[] args) throws IOException{ int n=in.nextInt(); long k=in.nextLong(); long ar[]=new long[n]; for(int i=0;i<n;i++) ar[i]=in.nextInt(); HashSet<Long> set=new HashSet(); int cnt=n,ind; sort(ar); for(int i=0;i<n;i++){ ind=binarySearch(ar,k*ar[i]); if(!set.contains(ar[i])&&ind>=0&&ind!=i){ cnt--; set.add(k*ar[i]); } } out.println(cnt); } static class Pair<T> implements Comparable<Pair>{ int l; int r; int ind; Pair(){ l=0; r=0; } Pair(int k,int v,int i){ l=k; r=v; ind=i; } @Override public int compareTo(Pair o) { if(o.l!=l)return (int) (l-o.l); else return (r-o.r); } } static class Reader{ BufferedReader br; StringTokenizer st; public Reader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["6 2\n2 3 6 5 4 10"]
2 seconds
["3"]
NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
Java 8
standard input
[ "binary search", "sortings", "greedy" ]
4ea1de740aa131cae632c612e1d582ed
The first line of the input contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). All the numbers in the lines are separated by single spaces.
1,500
On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}.
standard output
PASSED
e500b5ccca1e9722caeecb77e5a91c15
train_002.jsonl
1361374200
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x &lt; y) from the set, such that y = xΒ·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.HashSet; public class kMultipleFreeSet { public static void main(String[] args) throws IOException { // TODO Auto-generated method stub BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] nm = br.readLine().split(" "); int n = Integer.parseInt(nm[0]); long m = Long.parseLong(nm[1]); String[] ar = br.readLine().split(" "); HashSet <Long> hs = new HashSet<>(); for (int i = 0; i < n; i++) { hs.add(Long.parseLong(ar[i])); } long[] nar = new long[n]; boolean[] vis = new boolean[n]; for (int i = 0; i < n; i++) { nar[i] = Long.parseLong(ar[i])*m; } Arrays.sort(nar); int x = n; if(m > 1) { for (int i = 0; i < n; i++) { if(hs.contains((long)nar[i])) { x--; hs.remove((long)nar[i]*m); } } } System.out.println(x); } }
Java
["6 2\n2 3 6 5 4 10"]
2 seconds
["3"]
NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
Java 8
standard input
[ "binary search", "sortings", "greedy" ]
4ea1de740aa131cae632c612e1d582ed
The first line of the input contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). All the numbers in the lines are separated by single spaces.
1,500
On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}.
standard output
PASSED
b43b567cfa53bfc028948b95f2c664de
train_002.jsonl
1361374200
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x &lt; y) from the set, such that y = xΒ·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
256 megabytes
import java.io.*; import java.util.*; import java.text.*; import java.lang.*; import java.math.BigInteger; import java.util.regex.*; public class Myclass { /* public static ArrayList a[]=new ArrayList[200001]; public static int cat[]=new int [200001]; static int upto[]=new int[200001]; static int maxi[]=new int[200001]; static boolean visited[]=new boolean [200001]; static void dfs(int n,int p) { visited[n]=true; if(cat[n]==1) { upto[n]=upto[p]+1; } maxi[n]=Math.max(maxi[p], upto[n]); for(int i=0;i<a[n].size();i++) { int idx=(int) a[n].get(i); if(!visited[idx]) { dfs(idx,n); } } }*/ /*static boolean visited[]=new boolean [200001]; static PriorityQueue<pair>one =new PriorityQueue<>(); static PriorityQueue<pair>two =new PriorityQueue<>(); static PriorityQueue<pair>three =new PriorityQueue<>(); static long a[]=new long [200001]; public static void f(int x,int j) { if(x==1) one.add(new pair(a[j],j)); else if(x==2) two.add(new pair(a[j],j)); else three.add(new pair(a[j],j)); }*/ public static long dp[][]=new long[5001][5001]; public static void nCr() { dp[0][0]=1; for(int i=1;i<=5000;i++) { for(int j=1;j<i;j++) { dp[i][j]=((dp[i-1][j]%(mod-1))+((dp[i-1][j-1])%(mod-1)))%(mod-1); } dp[i][0]=1; dp[i][i]=1; } } public static void main(String[] args) { InputReader in = new InputReader(System.in); PrintWriter pw = new PrintWriter(System.out); int n=in.nextInt(); long k=in.nextLong(); TreeSet<Long>tr=new TreeSet<>(); long a[]=new long[n]; HashMap<Long,Boolean>hm=new HashMap<>(); for(int i=0;i<n;i++) { a[i]=in.nextLong(); hm.put(a[i], false); tr.add(a[i]); } int ans=0; Arrays.sort(a); for(int i=0;i<n;i++) { if(hm.get(a[i])==true) continue; if(tr.contains(a[i]*k)&& a[i]*k!=a[i]) { int cnt=2; long t=a[i]*k; //pw.println(t); hm.put(t, true); while(tr.contains(t*k)) { cnt++; t=t*k; hm.put(t, true); } ans+=(cnt+1)/2; //pw.println(cnt); } else ans++; //pw.println(hm.toString()); } pw.println(ans); pw.flush(); pw.close(); } 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; } static class tri implements Comparable<tri> { int p, c, l; tri(int p, int c, int l) { this.p = p; this.c = c; this.l = l; } public int compareTo(tri o) { return Integer.compare(l, o.l); } } 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); } } public static long mod = 1000000007; public static int d; public static int p; public static int q; public static int[] suffle(int[] a,Random gen) { int n = a.length; for(int i=0;i<n;i++) { int ind = gen.nextInt(n-i)+i; int temp = a[ind]; a[ind] = a[i]; a[i] = temp; } return a; } public static void swap(int a, int b){ int temp = a; a = b; b = temp; } public static HashSet<Integer> primeFactorization(int n) { HashSet<Integer> a =new HashSet<Integer>(); for(int i=2;i*i<=n;i++) { while(n%i==0) { a.add(i); n/=i; } } if(n!=1) a.add(n); return a; } public static void sieve(boolean[] isPrime,int n) { for(int i=1;i<n;i++) isPrime[i] = true; isPrime[0] = false; isPrime[1] = false; for(int i=2;i*i<n;i++) { if(isPrime[i] == true) { for(int j=(2*i);j<n;j+=i) isPrime[j] = false; } } } public static int GCD(int a,int b) { if(b==0) return a; else return GCD(b,a%b); } public static long GCD(long a,long b) { if(b==0) return a; else return GCD(b,a%b); } public static void extendedEuclid(int A,int B) { if(B==0) { d = A; p = 1 ; q = 0; } else { extendedEuclid(B, A%B); int temp = p; p = q; q = temp - (A/B)*q; } } public static long LCM(long a,long b) { return (a*b)/GCD(a,b); } public static int LCM(int a,int b) { return (a*b)/GCD(a,b); } public static int binaryExponentiation(int x,int n) { int result=1; while(n>0) { if(n % 2 ==1) result=result * x; x=x*x; n=n/2; } return result; } public static long binaryExponentiation(long x,long n) { long result=1; while(n>0) { if(n % 2 ==1) result=result * x; x=x*x; n=n/2; } return result; } public static int modularExponentiation(int x,int n,int M) { int result=1; while(n>0) { if(n % 2 ==1) result=(result * x)%M; x=(x%M*x)%M; n=n/2; } return result; } public static long me(long x,long n,long M) { long result=1; while(n>0) { if(n % 2 ==1) result=(result%M * x%M)%M; x=(x%M * x%M)%M; } return result; } public static long modularExponentiation(long x,long n,long M) { long result=1; while(n>0) { if(n % 2 ==1) result=(result%M * x%M)%M; x=(x%M * x%M)%M; n=n/2; } return result; } public static long modInverse(int A,int M) { return modularExponentiation(A,M-2,M); } public static long modInverse(long A,long M) { return me(A,M-2,M); } public static boolean isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n%2 == 0 || n%3 == 0) return false; for (int i=5; i*i<=n; i=i+6) { if (n%i == 0 || n%(i+2) == 0) return false; } return true; } public static long[] shuffle(long[] a, Random gen){ for(int i = 0, n = a.length;i < n;i++){ int ind = gen.nextInt(n-i)+i; long d = a[i]; a[i] = a[ind]; a[ind] = d; } return a; } static class pair implements Comparable<pair> { Long x; Integer y; pair(long a,int m) { this.x=a; this.y=m; } public boolean isEmpty() { // TODO Auto-generated method stub return false; } public int compareTo(pair o) { int result = x.compareTo(o.x); if(result==0) result = y.compareTo(o.y); return result; } public String toString() { return x+" "+y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair)o; return p.x == x && p.y == y ; } return false; } public int hashCode() { return new Long(x).hashCode()*31 + new Long(y).hashCode(); } } }
Java
["6 2\n2 3 6 5 4 10"]
2 seconds
["3"]
NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
Java 8
standard input
[ "binary search", "sortings", "greedy" ]
4ea1de740aa131cae632c612e1d582ed
The first line of the input contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). All the numbers in the lines are separated by single spaces.
1,500
On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}.
standard output
PASSED
21f759198f6ee03c4891deebb6f05d6b
train_002.jsonl
1361374200
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x &lt; y) from the set, such that y = xΒ·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
256 megabytes
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int n =sc.nextInt() , k = sc.nextInt(); HashSet<Long> set = new HashSet<Long>(); ArrayList<Long> a = new ArrayList<Long>(n); for (int i = 0; i < n; i++) a.add(sc.nextLong()); Collections.sort(a); for (int i = 0; i < n; i++) if(!set.contains(a.get(i))) set.add(1l*a.get(i)*k); System.out.println(set.size()); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));} public Scanner(String s) throws FileNotFoundException {br = new BufferedReader(new FileReader(s));} public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException {return Integer.parseInt(next());} public String nextLine() throws IOException {return br.readLine();} public long nextLong() throws IOException {return Long.parseLong(next());} public double nextDouble() throws IOException {return Double.parseDouble(next());} public char nextChar() throws IOException{return next().charAt(0);} public boolean ready() throws IOException {return br.ready();} public int[] nextIntArr() throws IOException{ st = new StringTokenizer(br.readLine()); int[] res = new int[st.countTokens()]; for (int i = 0; i < res.length; i++) res[i] = nextInt(); return res; } public char[] nextCharArr() throws IOException{ st = new StringTokenizer(br.readLine()); char[] res = new char[st.countTokens()]; for (int i = 0; i < res.length; i++) res[i] = nextChar(); return res; } } }
Java
["6 2\n2 3 6 5 4 10"]
2 seconds
["3"]
NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
Java 8
standard input
[ "binary search", "sortings", "greedy" ]
4ea1de740aa131cae632c612e1d582ed
The first line of the input contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). All the numbers in the lines are separated by single spaces.
1,500
On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}.
standard output
PASSED
54aecbf17f0bd0b75cdd405c8cb02235
train_002.jsonl
1361374200
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x &lt; y) from the set, such that y = xΒ·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
256 megabytes
import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Writer; import java.util.Arrays; import java.util.HashSet; import java.util.InputMismatchException; public class Sticks { public static void main(String[] args) throws Exception { int n = i(); int m = i(); int[] a = new int[n]; for( int i=0 ; i<n ; i++ ) a[i]=i(); Arrays.sort(a); HashSet<Integer> hs = new HashSet<Integer>(); int c=0; for( int i=0 ; i<n ; i++ ) { int t = a[i]/m; if( a[i]%m!=0 ) t=0; if( !hs.contains(t) ) { hs.add(a[i]); c++; } } out.println(c); out.close(); } static InputReader in = new InputReader(System.in); static OutputWriter out = new OutputWriter(System.out); static int i() { return in.readInt(); } static long l() { return in.readLong(); } static double d() { return in.readDouble(); } static String s() { return in.readString(); } static void Iarr( int[] array, int no ) { for( int i=0 ; i<no ; i++ ) { array[i] = i(); } } static void Larr( long[] array, int no ) { for( int i=0 ; i<no ; i++ ) { array[i] = l(); } } static void Darr( double[] array, int no ) { for( int i=0 ; i<no ; i++ ) { array[i] = d(); } } static void Sarr( String[] array, int no ) { for( int i=0 ; i<no ; i++ ) { array[i] = s(); } } private static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int readInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public double readDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, readInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, readInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public long readLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } private static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } public void println(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } public void flush() { writer.flush(); } } }
Java
["6 2\n2 3 6 5 4 10"]
2 seconds
["3"]
NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
Java 8
standard input
[ "binary search", "sortings", "greedy" ]
4ea1de740aa131cae632c612e1d582ed
The first line of the input contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). All the numbers in the lines are separated by single spaces.
1,500
On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}.
standard output
PASSED
fa48bb86c2d02f5a0a0300ec6ad65059
train_002.jsonl
1361374200
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x &lt; y) from the set, such that y = xΒ·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
256 megabytes
/*Talent is something you make bloom , instinct is something you polish*/ import java.io.*; import java.math.*; import java.util.*; public class Main { static long mod=((long)1e9)+7;//toString public static int gcd(int a,int b){if(b==0)return a;else return gcd(b,a%b);} public static long pow_mod(long x,long y){long res=1;x=x%mod;while(y > 0){if((y & 1)==1)res=(res * x)%mod;y=y>>1;x =(x * x)%mod;}return res;} public static int lower_bound(int[]arr,int val){int lo=0;int hi=arr.length-1;while(lo<hi){int mid=lo+((hi-lo+1)/2);if(arr[mid]==val){return mid;}else if(arr[mid]>val){hi=mid-1;}else lo=mid;}if(arr[lo]<=val)return lo;else return -1;} public static int upper_bound(int[]arr,int val){int lo=0;int hi=arr.length-1;while(lo<hi){int mid=lo+((hi-lo)/2);if(arr[mid]==val){return mid;}else if(arr[mid]>val){hi=mid;;}else lo=mid+1;}if(arr[lo]>=val)return lo;else return -1;} public static void main (String[] args) throws java.lang.Exception { Reader sn = new Reader(); Print p = new Print(); int n = sn.nextInt(); int k = sn.nextInt(); if(k != 1){ int[] arr = new int[n]; for(int i = 0; i < n; ++i){ arr[i] = sn.nextInt(); } Arrays.sort(arr); int[] val = new int[n]; HashMap<Integer , Integer> hm = new HashMap<Integer, Integer>(); int[] count = new int[n]; for(int i = 0; i < n; ++i){ hm.put(arr[i] , i); } int x = 0; for(int i = 0; i < n; ++i){ if((arr[i] % k) == 0){ if(hm.get(arr[i]/k) != null){ val[i] = val[hm.get(arr[i]/k)]; count[val[i]]++; } else{ val[i] = x; count[val[i]]++; x++; } } else{ val[i] = x; count[val[i]]++; x++; } } int ans = 0; for(int i = 0; i < n; ++i){ ans += ((count[i] + 1)/2); } /*for(int i = 0; i < 8 ; ++i){ p.printLine(Integer.toString(val[i])); }*/ p.printLine(Integer.toString(ans)); } else{ p.printLine(Integer.toString(n)); } p.close(); } } class Pair implements Comparable<Pair> { int val; int in; Pair(int a, int b){ val=a; in=b; } @Override public int compareTo(Pair o) { if(val==o.val) return Integer.compare(in,o.in); else return Integer.compare(val,o.val); }} class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public String readWord()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 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(); } } class Print { private final BufferedWriter bw; public Print() { bw=new BufferedWriter(new OutputStreamWriter(System.out)); } public void print(String str)throws IOException { bw.append(str); } public void printLine(String str)throws IOException { print(str); bw.append("\n"); } public void close()throws IOException { bw.close(); }}
Java
["6 2\n2 3 6 5 4 10"]
2 seconds
["3"]
NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
Java 8
standard input
[ "binary search", "sortings", "greedy" ]
4ea1de740aa131cae632c612e1d582ed
The first line of the input contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). All the numbers in the lines are separated by single spaces.
1,500
On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}.
standard output
PASSED
973c85ed9c1b3fe9f0975f3a1e1bf642
train_002.jsonl
1361374200
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x &lt; y) from the set, such that y = xΒ·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.nio.Buffer; import java.util.*; public class Watermelon { static long steps = 0; public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); HashMap<Integer,Boolean> map=new HashMap<>(); int n=sc.nextInt(),k=sc.nextInt(); int[] a=new int[n]; for(int i=0;i<n;i++)a[i]=sc.nextInt(); Arrays.sort(a); for(int i=0;i<n;i++){ if(a[i]%k==0){ if(!map.getOrDefault((a[i]/k),false)) map.put(a[i],true); } else map.put(a[i],true); } System.out.print(map.size()); } }
Java
["6 2\n2 3 6 5 4 10"]
2 seconds
["3"]
NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
Java 8
standard input
[ "binary search", "sortings", "greedy" ]
4ea1de740aa131cae632c612e1d582ed
The first line of the input contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). All the numbers in the lines are separated by single spaces.
1,500
On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}.
standard output
PASSED
bafa35392206c75603a35b8818ffefee
train_002.jsonl
1361374200
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x &lt; y) from the set, such that y = xΒ·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
256 megabytes
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.HashSet; import java.util.StringTokenizer; public class Round168C { public static void main(String[] args) { // TODO Auto-generated method stub out=new PrintWriter (new BufferedOutputStream(System.out)); FastReader s=new FastReader(); int n=s.nextInt(); long k=s.nextInt(); Long[] arr=new Long[n]; HashSet<Long> helper=new HashSet<>(); for (int i=0;i<n;i++) { arr[i]=s.nextLong(); helper.add(arr[i]); } Arrays.sort(arr); int ans=0; for(int i=0;i<n;i++) { int count =0; if(helper.contains(arr[i])) { long temp=arr[i]; while(helper.contains(temp)) { helper.remove(temp); count++; if((temp*k)/k!=temp)break; temp*=k; } } ans+=count%2==0?count/2:count/2+1; } out.println(ans); out.close(); } public static PrintWriter out; public static class FastReader { BufferedReader br; StringTokenizer st; //it reads the data about the specified point and divide the data about it ,it is quite fast //than using direct public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); //InputStream reads the data and decodes in character stream //It acts as bridge between byte stream and character stream } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next());//converts string to integer } double nextDouble() { return Double.parseDouble(next()); } long nextLong() { return Long.parseLong(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (Exception e) { e.printStackTrace(); } return str; } } }
Java
["6 2\n2 3 6 5 4 10"]
2 seconds
["3"]
NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
Java 8
standard input
[ "binary search", "sortings", "greedy" ]
4ea1de740aa131cae632c612e1d582ed
The first line of the input contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). All the numbers in the lines are separated by single spaces.
1,500
On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}.
standard output
PASSED
bbfed8d51f05effc846be7a4b46c5ae8
train_002.jsonl
1361374200
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x &lt; y) from the set, such that y = xΒ·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
256 megabytes
/* BY - LAXMIKANT KATRE (laxmikant.katre) */ import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); int n = sc.nextInt(); int k = sc.nextInt(); Set<Integer> hash = new HashSet<>(); int count = 0; int[] arr = new int[n]; for(int i = 0; i < n; ++i) { arr[i] = sc.nextInt(); } Arrays.sort(arr); for(int i = 0; i < n; ++i) { if(arr[i] % k == 0 && hash.contains(arr[i] / k)) continue; hash.add(arr[i]); ++count; } out.println(count); out.close(); /* int n = sc.nextInt(); // read input as integer long k = sc.nextLong(); // read input as long double d = sc.nextDouble(); // read input as double String str = sc.next(); // read input as String String s = sc.nextLine(); // read whole line as String int result = 40*n; out.println(result); // print via PrintWriter */ } //-----------PrintWriter for faster output--------------------------------- public static PrintWriter out; //-----------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
["6 2\n2 3 6 5 4 10"]
2 seconds
["3"]
NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
Java 8
standard input
[ "binary search", "sortings", "greedy" ]
4ea1de740aa131cae632c612e1d582ed
The first line of the input contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). All the numbers in the lines are separated by single spaces.
1,500
On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}.
standard output
PASSED
c0a2fdafe8c150a8e33fa63e04d6c4c6
train_002.jsonl
1361374200
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x &lt; y) from the set, such that y = xΒ·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
256 megabytes
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.math.BigInteger; import java.util.*; import java.lang.Math; public class ACM { private static int gcdThing(long a, long b) { BigInteger b1 = BigInteger.valueOf(a); BigInteger b2 = BigInteger.valueOf(b); BigInteger gcd = b1.gcd(b2); return gcd.intValue(); } public static int binarySearch(long data[],long key) { int count=-1; int low = 0; int high = data.length - 1; while(high >= low) { int middle = (low + high) / 2; if(data[middle] == key) { return middle; } if(data[middle] < key) { low = middle + 1; count=middle; } if(data[middle] > key) { high = middle - 1; } } return count; } /**/ public static int InsertionSort(int[] input){ int count=0; int temp; for (int i = 1; i < input.length; i++) { for(int j = i ; j > 0 ; j--){ if(input[j] < input[j-1]){ temp = input[j]; input[j] = input[j-1]; input[j-1] = temp; count++; } } } return count; } public static void main(String[] args) { FastScanner input = new FastScanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = input.nextInt(); long arr[]= new long[n]; long k=input.nextLong(); //PriorityQueue<Integer> q = new PriorityQueue<>(); TreeSet<Long> a= new TreeSet<>(); for(int i=0;i<n ;i++) a.add(arr[i]=input.nextLong()); Arrays.sort(arr); for(int i=n-1;i>=0;i--){ // System.out.println(arr[i]/k); if(a.contains(arr[i]*k)){ a.remove(arr[i]); // System.out.println("i = "+i); } } // System.out.println("......................"); //for(long x:a) // out.print(x+" "); if(k==1) out.println(n); else out.println(a.size()); out.flush(); out.close(); }// end main method } class FastScanner { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public FastScanner(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 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 String next() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isLineEndChar(c)); return res.toString(); } 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 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 boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public boolean isLineEndChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return c == '\n' || c == '\r' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } }
Java
["6 2\n2 3 6 5 4 10"]
2 seconds
["3"]
NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
Java 8
standard input
[ "binary search", "sortings", "greedy" ]
4ea1de740aa131cae632c612e1d582ed
The first line of the input contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). All the numbers in the lines are separated by single spaces.
1,500
On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}.
standard output
PASSED
f5d355d9c082203cb6ef7be7c12d95ea
train_002.jsonl
1361374200
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x &lt; y) from the set, such that y = xΒ·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class BOOL { private static FastReader in = new FastReader(); public static void main(String[] args) { int n=in.nextInt(),k=in.nextInt(); int a[]=new int[n],ans=0; HashMap<Long,Long>M=new HashMap(); HashMap<Long,Integer>H=new HashMap(); for(int i=0;i<n;i++){ a[i]=in.nextInt(); M.put((long)a[i], (long)k*a[i]); } Sorting.bucketSort(a, n); for(int i=0;i<n;i++){ H.put((long)a[i],i); } for(int i=0;i<n;i++){ if(M.containsKey((long)k*a[i])){ ans++; a[H.get((long)k*a[i])]=0; } } if(k>1) System.out.println(n-ans); else System.out.println(n); //System.out.println(M.keySet().contains(9)); } } 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 Sorting{ public static int[] bucketSort(int[] array, int bucketCount) { if (bucketCount <= 0) throw new IllegalArgumentException("Invalid bucket count"); if (array.length <= 1) return array; //trivially sorted int high = array[0]; int low = array[0]; for (int i = 1; i < array.length; i++) { //find the range of input elements if (array[i] > high) high = array[i]; if (array[i] < low) low = array[i]; } double interval = ((double)(high - low + 1))/bucketCount; //range of one bucket ArrayList<Integer> buckets[] = new ArrayList[bucketCount]; for (int i = 0; i < bucketCount; i++) { //initialize buckets buckets[i] = new ArrayList(); } for (int i = 0; i < array.length; i++) { //partition the input array buckets[(int)((array[i] - low)/interval)].add(array[i]); } int pointer = 0; for (int i = 0; i < buckets.length; i++) { Collections.sort(buckets[i]); //mergeSort for (int j = 0; j < buckets[i].size(); j++) { //merge the buckets array[pointer] = buckets[i].get(j); pointer++; } } return array; } }
Java
["6 2\n2 3 6 5 4 10"]
2 seconds
["3"]
NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
Java 8
standard input
[ "binary search", "sortings", "greedy" ]
4ea1de740aa131cae632c612e1d582ed
The first line of the input contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). All the numbers in the lines are separated by single spaces.
1,500
On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}.
standard output
PASSED
05ac2cddfadb473b64b7b4afc20c1954
train_002.jsonl
1361374200
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x &lt; y) from the set, such that y = xΒ·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main { public static void main(String[] args) throws IOException { Scanner input = new Scanner(System.in); int a = input.nextInt(); long b = input.nextLong(); long[]arr = new long[a]; for(int i=0 ; i<a ; i++){ long x = input.nextLong(); arr[i] = x; } Arrays.sort(arr); Set<Long> set = new HashSet<>(); if(b == 1){ for(int i=0 ; i<a ; i++) set.add(arr[i]); System.out.println(set.size()); return; } for(long element : arr){ if(element % b != 0) set.add(element); else if(!set.contains(element/b)){ set.add(element); } } System.out.println(set.size()); } }
Java
["6 2\n2 3 6 5 4 10"]
2 seconds
["3"]
NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
Java 8
standard input
[ "binary search", "sortings", "greedy" ]
4ea1de740aa131cae632c612e1d582ed
The first line of the input contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). All the numbers in the lines are separated by single spaces.
1,500
On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}.
standard output
PASSED
0c78103cffa4799d3f91885e3190c9d3
train_002.jsonl
1361374200
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x &lt; y) from the set, such that y = xΒ·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
256 megabytes
import java.io.*; import java.math.*; import java.util.*; @SuppressWarnings("Duplicates") // author @mdazmat9 public class Main { static Scanner sc = new Scanner(System.in); static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) throws IOException { int test = 1; // test=sc.nextInt(); for (int ind = 0; ind < test; ind++) { solve(); } out.flush(); } static void solve() { int n=sc.nextInt(); long k=sc.nextLong(); long [] a=longarray(n); if(n==1){ out.println(1); return; } HashMap<Long,Boolean> map=new HashMap<>(); for(long num:a)map.put(num,false); HashSet<Long> set=new HashSet<>(); for(long num :a)set.add(num); sort(a); int ans=0; for(int i=n-1;i>=0;i--){ if(a[i]%k==0 ){ if(map.get(a[i]))continue; ans++; map.put(a[i]/k,true); } else { if(map.get(a[i]))continue; ans++; } } out.println(ans); } static class SegmentTree { int st[]; SegmentTree(int arr[], int n) { int x = (int) (Math.ceil(Math.log(n) / Math.log(2))); int max_size = 2 * (int) Math.pow(2, x) - 1; st = new int[max_size]; // Memory allocation constructSTUtil(arr, 0, n - 1, 0); } int getMid(int s, int e) { return s + (e - s) / 2; } int getSumUtil(int ss, int se, int qs, int qe, int si) { if (qs <= ss && qe >= se) return st[si]; if (se < qs || ss > qe) return 0; int mid = getMid(ss, se); return getSumUtil(ss, mid, qs, qe, 2 * si + 1) + getSumUtil(mid + 1, se, qs, qe, 2 * si + 2); } void updateValueUtil(int ss, int se, int i, int diff, int si) { if (i < ss || i > se) return; st[si] = st[si] + diff; if (se != ss) { int mid = getMid(ss, se); updateValueUtil(ss, mid, i, diff, 2 * si + 1); updateValueUtil(mid + 1, se, i, diff, 2 * si + 2); } } void updateValue( int n, int i, int new_val) { // Check for erroneous input index if (i < 0 || i > n - 1) { System.out.println("Invalid Input"); return; } updateValueUtil(0, n - 1, i, new_val, 0); } int getSum(int n, int qs, int qe) { if (qs < 0 || qe > n - 1 || qs > qe) { System.out.println("Invalid Input"); return -1; } return getSumUtil(0, n - 1, qs, qe, 0); } int constructSTUtil(int arr[], int ss, int se, int si) { if (ss == se) { st[si] = arr[ss]; return arr[ss]; } int mid = getMid(ss, se); st[si] = constructSTUtil(arr, ss, mid, si * 2 + 1) + constructSTUtil(arr, mid + 1, se, si * 2 + 2); return st[si]; } } static int[] intarray(int n){ int [] a=new int[n];for(int i=0;i<n;i++)a[i]=sc.nextInt();return a; } static void sort(int[]a){ shuffle(a);Arrays.sort(a);} static void sort(long[]a){ shuffle(a);Arrays.sort(a);} static long[] longarray(int n){ long [] a=new long[n];for(int i=0;i<n;i++)a[i]=sc.nextLong();return a; } static ArrayList<Integer> intlist(int n){ArrayList<Integer> list=new ArrayList<>();for(int i=0;i<n;i++)list.add(sc.nextInt());return list; } static ArrayList<Long> longlist(int n){ArrayList<Long> list=new ArrayList<>();for(int i=0;i<n;i++)list.add(sc.nextLong());return list; } static int[][] int2darray(int n,int m){ int [][] a=new int[n][m];for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ a[i][j]=sc.nextInt(); } }return a; } static long[][] long2darray(int n,int m){ long [][] a=new long[n][m];for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ a[i][j]=sc.nextLong(); } }return a; } static char[][] char2darray(int n,int m){ char [][] a=new char[n][m];for(int i=0;i<n;i++){ String s=sc.next(); a[i]=s.toCharArray(); }return a; } static double pi=3.14159265358979323846264; public static double logb( double a, double b ) {return Math.log(a) / Math.log(b); } static long fast_pow(long a, long b,long abs) { if(b == 0) return 1L; long val = fast_pow(a, b / 2,abs); if(b % 2 == 0) return val * val % abs; else return val * val % abs * a % abs; } static long abs = (long)1e9 + 7; static void shuffle(int[] a) { int n = a.length;for(int i = 0; i < n; i++) { int r = i + (int) (Math.random() * (n - i));int tmp = a[i];a[i] = a[r];a[r] = tmp; } } static void shuffle(long[] a) { int n = a.length;for(int i = 0; i < n; i++) { int r = i + (int) (Math.random() * (n - i));long tmp = a[i];a[i] = a[r];a[r] = tmp; } } static long gcd(long a , long b) { if(b == 0) return a; return gcd(b , a % b); } } class Scanner { public BufferedReader reader; public StringTokenizer st; public Scanner(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); st = null; } public String next() { while (st == null || !st.hasMoreTokens()) { try { String line = reader.readLine(); if (line == null) return null; st = new StringTokenizer(line); } catch (Exception e) { throw (new RuntimeException()); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } } class DSU { int[] rank, parent; int n; public DSU(int n) { rank = new int[n]; parent = new int[n]; this.n = n; makeSet(); } void makeSet() { for (int i = 0; i < n; i++) parent[i] = i; } int find(int x) { if (parent[x] != x) { return find(parent[x]); } return x; } void union(int x, int y) { int xRoot = find(x); int yRoot = find(y); if (xRoot == yRoot) return; if (rank[xRoot] < rank[yRoot]) parent[xRoot] = yRoot; else if (rank[yRoot] < rank[xRoot]) parent[yRoot] = xRoot; else { parent[yRoot] = xRoot; rank[xRoot] = rank[xRoot] + 1; } } }
Java
["6 2\n2 3 6 5 4 10"]
2 seconds
["3"]
NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
Java 8
standard input
[ "binary search", "sortings", "greedy" ]
4ea1de740aa131cae632c612e1d582ed
The first line of the input contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). All the numbers in the lines are separated by single spaces.
1,500
On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}.
standard output
PASSED
1aea9ebb2480777e7682b4ac8250ca81
train_002.jsonl
1361374200
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x &lt; y) from the set, such that y = xΒ·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class Main { static class Reader { private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public Reader() { this(System.in); }public Reader(InputStream is) { mIs = is;} public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];} public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;} public String s(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();} public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;} public int i(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;} public double d() throws IOException {return Double.parseDouble(s()) ;} public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } /////////////////////////////////////////////////////////////////////////////////////////// // RRRRRRRRR AAA HHH HHH IIIIIIIIIIIII LLL // // RR RRR AAAAA HHH HHH IIIIIIIIIII LLL // // RR RRR AAAAAAA HHH HHH III LLL // // RR RRR AAA AAA HHHHHHHHHHH III LLL // // RRRRRR AAA AAA HHHHHHHHHHH III LLL // // RR RRR AAAAAAAAAAAAA HHH HHH III LLL // // RR RRR AAA AAA HHH HHH IIIIIIIIIII LLLLLLLLLLLL // // RR RRR AAA AAA HHH HHH IIIIIIIIIIIII LLLLLLLLLLLL // /////////////////////////////////////////////////////////////////////////////////////////// static int n; static long store[]; public static void main(String[] args)throws IOException { PrintWriter out= new PrintWriter(System.out); Reader sc=new Reader(); int n=sc.i(); int k=sc.i(); if(k==1) { System.out.println(n); System.exit(0); } int arr[]=new int[n]; TreeSet<Long> ts=new TreeSet<>(); for(int i=0;i<n;i++){arr[i]=sc.i();ts.add((long)arr[i]);} Arrays.sort(arr); for(int i=0;i<n;i++) { if(!ts.contains((long)arr[i])) continue; if(ts.contains((long)k*arr[i])) ts.remove((long)k*arr[i]); } out.println(ts.size()); out.flush(); } }
Java
["6 2\n2 3 6 5 4 10"]
2 seconds
["3"]
NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
Java 8
standard input
[ "binary search", "sortings", "greedy" ]
4ea1de740aa131cae632c612e1d582ed
The first line of the input contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). All the numbers in the lines are separated by single spaces.
1,500
On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}.
standard output
PASSED
14c532b83d5bfb64db1e297165bfba58
train_002.jsonl
1361374200
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x &lt; y) from the set, such that y = xΒ·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
256 megabytes
import java.io.* ; import java.util.* ; public class Solution{ 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 sc = new FastReader(); int n = sc.nextInt(); Long k = sc.nextLong(); Long[] arr = new Long[n]; int count=0; for(int i=0;i<n;i++){ arr[i] = sc.nextLong(); } if(k==1) { System.out.println(n); return ; } Arrays.sort(arr); ArrayList<Long> list = new ArrayList<Long>(Arrays.asList(arr)); /*for(Long a:list) System.out.print(a+" "); System.out.println(""); */ while(list.size()!=0){ Long c = list.get(list.size()-1); //System.out.println("for this c="+c); if(c%k==0){ Long div = c/k; int a = Collections.binarySearch(list, div); //System.out.println("c="+c+" div="+div+" a="+a); if(a>=0){ list.remove(a); } } list.remove(list.size()-1); count++; } System.out.println(count); } }
Java
["6 2\n2 3 6 5 4 10"]
2 seconds
["3"]
NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
Java 8
standard input
[ "binary search", "sortings", "greedy" ]
4ea1de740aa131cae632c612e1d582ed
The first line of the input contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). All the numbers in the lines are separated by single spaces.
1,500
On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}.
standard output
PASSED
0dff02b2734014c9be6d6271c130a9b7
train_002.jsonl
1361374200
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x &lt; y) from the set, such that y = xΒ·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
256 megabytes
import java.io.*; import java.util.*; public class Main { static Scanner sc = new Scanner(System.in); static PrintWriter out = new PrintWriter(System.out); static HashMap<Long,Long> hm = new HashMap<>(); public static void main(String[] args) throws Exception { int n = sc.nextInt(); long k = sc.nextInt(); long arr[] = new long[n]; for(int i=0; i<n ;i++) { arr[i] = sc.nextInt(); hm.put(arr[i],0L); } for(Long x : arr) { if(x%k == 0 && hm.containsKey(x/k)) { hm.put(x/k, hm.get(x/k)+1); } if(hm.containsKey(x*k)) { hm.put(x*k, hm.get(x*k) + 1); } } PriorityQueue<Pair> pq = new PriorityQueue<>(); HashSet<Long> ans = new HashSet<>(); for(Map.Entry<Long,Long> mp : hm.entrySet()) { Pair p = new Pair(mp.getKey(),mp.getValue()); pq.add(p); } while(!pq.isEmpty()) { Long x = pq.poll().key; if(ans.contains(x*k) || (x%k == 0 && ans.contains(x/k))) continue; ans.add(x); } out.println(ans.size()); out.close(); } static class Pair implements Comparable<Pair>{ long key,val; public Pair(long key, long val) { this.key = key; this.val = val; } public int compareTo(Pair o) { if(val == o.val) return (int)(key - o.key); return (int) (val - o.val); } } } class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream system) { br = new BufferedReader(new InputStreamReader(system)); } public Scanner(String file) throws Exception { br = new BufferedReader(new FileReader(file)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public 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 Long nextLong() throws IOException { return Long.parseLong(next()); } }
Java
["6 2\n2 3 6 5 4 10"]
2 seconds
["3"]
NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
Java 8
standard input
[ "binary search", "sortings", "greedy" ]
4ea1de740aa131cae632c612e1d582ed
The first line of the input contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). All the numbers in the lines are separated by single spaces.
1,500
On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}.
standard output
PASSED
4983c9dd47d8feb26c439313cccf8bdd
train_002.jsonl
1361374200
A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x &lt; y) from the set, such that y = xΒ·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.
256 megabytes
import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.BitSet; import java.util.StringTokenizer; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = sc.nextInt(); long k = sc.nextLong(); long a[] = new long[n]; BitSet taken = new BitSet(); BitSet cant_take = new BitSet(); int ans = 0; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } Arrays.sort(a); for (int i = 0; i < n; i++) { if (a[i] % k == 0) { if (!cant_take.get((int) (a[i] / k))) { ans++; taken.set(i,true); cant_take.set((int) (a[i]), true); } cant_take.set((int) (a[i] / k), true); }else { ans++; cant_take.set((int)a[i],true); } } System.out.println(ans); } private static class Scanner { public BufferedReader reader; public StringTokenizer st; public Scanner(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); st = null; } public String next() { while (st == null || !st.hasMoreTokens()) { try { String line = reader.readLine(); if (line == null) return null; st = new StringTokenizer(line); } catch (Exception e) { throw (new RuntimeException()); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } } }
Java
["6 2\n2 3 6 5 4 10"]
2 seconds
["3"]
NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
Java 8
standard input
[ "binary search", "sortings", "greedy" ]
4ea1de740aa131cae632c612e1d582ed
The first line of the input contains two integers n and k (1 ≀ n ≀ 105, 1 ≀ k ≀ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≀ ai ≀ 109). All the numbers in the lines are separated by single spaces.
1,500
On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}.
standard output