{"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n long vertexes = in.nextLong();\n long edges = in.nextLong();\n\n long max = 0;\n\n if (edges == 0) {\n System.out.println(vertexes + \" \" + vertexes);\n return;\n }\n\n for (long i = 1; i < vertexes; i++) {\n long currentEdges = (i * (i - 1)) / 2;\n if (currentEdges >= edges) {\n max = vertexes - i;\n break;\n }\n }\n\n for (long i = 0; i < edges; i++) {\n vertexes -= 2;\n\n if (vertexes < 0) {\n break;\n }\n }\n\n vertexes = vertexes > 0 ? vertexes : 0;\n\n System.out.println(vertexes + \" \" + max);\n }\n}\n", "lang_cluster": "Java", "tags": ["constructive algorithms", "graphs"], "code_uid": "da2b2fad16f5de844ff458c641e7b6df", "src_uid": "daf0dd781bf403f7c1bb668925caa64d", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Codechef\n{\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t Scanner sc=new Scanner(System.in);\n\t long n=sc.nextLong();\n\t long m=sc.nextLong();\n\t if(n==1){\n\t System.out.println(\"1\");\n\t }else{\n\t if(m-1 primes = Arrays.asList(a);\n if (primes.indexOf(n) + 1 < primes.size() && primes.get(primes.indexOf(n) + 1) == m) {\n System.out.println(\"YES\");\n } else {\n System.out.println(\"NO\");\n }\n sc.close();\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force"], "code_uid": "f96cd55a31b67dd9e057cd6f04b544ee", "src_uid": "9d52ff51d747bb59aa463b6358258865", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\npublic class cf998b {\n\n public static void main(String[] args) throws IOException {\n int n = rni(), b = ni(), a[] = ria(n), bal[] = new int[n];\n for(int i = 0; i < n; ++i) {\n if(i == 0) {\n bal[i] = a[i] % 2 == 0 ? 1 : -1;\n } else {\n bal[i] = bal[i - 1] + (a[i] % 2 == 0 ? 1 : -1);\n }\n }\n PriorityQueue pq = new PriorityQueue<>();\n for(int i = 1; i < n - 1; ++i) {\n if(bal[i] == 0) {\n pq.offer(abs(a[i + 1] - a[i]));\n }\n }\n int ans = 0;\n while(!pq.isEmpty() && b >= pq.peek()) {\n b -= pq.poll();\n ++ans;\n }\n prln(ans);\n close();\n }\n\n static BufferedReader __in = new BufferedReader(new InputStreamReader(System.in));\n static PrintWriter __out = new PrintWriter(new OutputStreamWriter(System.out));\n static StringTokenizer input;\n static Random __rand = new Random();\n\n // references\n // IBIG = 1e9 + 7\n // IMAX ~= 2e10\n // LMAX ~= 9e18\n \n // constants\n static final int IBIG = 1000000007;\n static final int IMAX = 2147483647;\n static final int IMIN = -2147483648;\n static final long LMAX = 9223372036854775807L;\n static final long LMIN = -9223372036854775808L;\n // math util\n static int minof(int a, int b, int c) {return min(a, min(b, c));}\n static int minof(int... x) {if(x.length == 1) return x[0]; if(x.length == 2) return min(x[0], x[1]); if(x.length == 3) return min(x[0], min(x[1], x[2])); int min = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] < min) min = x[i]; return min;}\n static long minof(long a, long b, long c) {return min(a, min(b, c));}\n static long minof(long... x) {if(x.length == 1) return x[0]; if(x.length == 2) return min(x[0], x[1]); if(x.length == 3) return min(x[0], min(x[1], x[2])); long min = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] < min) min = x[i]; return min;}\n static int maxof(int a, int b, int c) {return max(a, max(b, c));}\n static int maxof(int... x) {if(x.length == 1) return x[0]; if(x.length == 2) return max(x[0], x[1]); if(x.length == 3) return max(x[0], max(x[1], x[2])); int max = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] > max) max = x[i]; return max;}\n static long maxof(long a, long b, long c) {return max(a, max(b, c));}\n static long maxof(long... x) {if(x.length == 1) return x[0]; if(x.length == 2) return max(x[0], x[1]); if(x.length == 3) return max(x[0], max(x[1], x[2])); long max = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] > max) max = x[i]; return max;}\n static int powi(int a, int b) {if(a == 0) return 0; int ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}\n static long powl(long a, int b) {if(a == 0) return 0; long ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}\n static int fli(double d) {return (int)d;}\n static int cei(double d) {return (int)ceil(d);}\n static long fll(double d) {return (long)d;}\n static long cel(double d) {return (long)ceil(d);}\n static int gcf(int a, int b) {return b == 0 ? a : gcf(b, a % b);}\n static long gcf(long a, long b) {return b == 0 ? a : gcf(b, a % b);}\n static int randInt(int min, int max) {return __rand.nextInt(max - min + 1) + min;}\n static long hash(long x) {x += 0x9e3779b97f4a7c15L; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9L; x = (x ^ (x >> 27)) * 0x94d049bb133111ebL; return x ^ (x >> 31);}\n // array util\n static void reverse(int[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {int swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}}\n static void reverse(long[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {long swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}}\n static void reverse(char[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {char swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}}\n static void shuffle(int[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); int swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}\n static void shuffle(long[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); long swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}\n static void rsort(int[] a) {shuffle(a); sort(a);}\n static void rsort(long[] a) {shuffle(a); sort(a);}\n static int[] copy(int[] a) {int[] ans = new int[a.length]; for(int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans;}\n static long[] copy(long[] a) {long[] ans = new long[a.length]; for(int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans;}\n static char[] copy(char[] a) {char[] ans = new char[a.length]; for(int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans;}\n static int[] sorted(int[] a) {int[] ans = copy(a); sort(ans); return ans;}\n static long[] sorted(long[] a) {long[] ans = copy(a); sort(ans); return ans;}\n static int[] rsorted(int[] a) {int[] ans = copy(a); rsort(ans); return ans;}\n static long[] rsorted(long[] a) {long[] ans = copy(a); rsort(ans); return ans;}\n // graph util\n static List> graph(int n) {List> g = new ArrayList<>(); for(int i = 0; i < n; ++i) g.add(new ArrayList<>()); return g;}\n static List> graph(List> g, int m) throws IOException {for(int i = 0; i < m; ++i) connect(g, rni() - 1, ni() - 1); return g;}\n static List> graph(int n, int m) throws IOException {return graph(graph(n), m);}\n static List> dgraph(List> g, int m) throws IOException {for(int i = 0; i < m; ++i) connecto(g, rni() - 1, ni() - 1); return g;}\n static List> dgraph(List> g, int n, int m) throws IOException {return dgraph(graph(n), m);}\n static List> sgraph(int n) {List> g = new ArrayList<>(); for(int i = 0; i < n; ++i) g.add(new HashSet<>()); return g;}\n static List> sgraph(List> g, int m) throws IOException {for(int i = 0; i < m; ++i) connect(g, rni() - 1, ni() - 1); return g;}\n static List> sgraph(int n, int m) throws IOException {return sgraph(sgraph(n), m);}\n static List> dsgraph(List> g, int m) throws IOException {for(int i = 0; i < m; ++i) connecto(g, rni() - 1, ni() - 1); return g;}\n static List> dsgraph(List> g, int n, int m) throws IOException {return dsgraph(sgraph(n), m);}\n static void connect(List> g, int u, int v) {g.get(u).add(v); g.get(v).add(u);}\n static void connecto(List> g, int u, int v) {g.get(u).add(v);}\n static void dconnect(List> g, int u, int v) {g.get(u).remove(v); g.get(v).remove(u);}\n static void dconnecto(List> g, int u, int v) {g.get(u).remove(v);}\n // input\n static void r() throws IOException {input = new StringTokenizer(__in.readLine());}\n static int ri() throws IOException {return Integer.parseInt(__in.readLine());}\n static long rl() throws IOException {return Long.parseLong(__in.readLine());}\n static int[] ria(int n) throws IOException {int[] a = new int[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Integer.parseInt(input.nextToken()); return a;}\n static int[] riam1(int n) throws IOException {int[] a = new int[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Integer.parseInt(input.nextToken()) - 1; return a;}\n static long[] rla(int n) throws IOException {long[] a = new long[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Long.parseLong(input.nextToken()); return a;}\n static char[] rcha() throws IOException {return __in.readLine().toCharArray();}\n static String rline() throws IOException {return __in.readLine();}\n static int rni() throws IOException {input = new StringTokenizer(__in.readLine()); return Integer.parseInt(input.nextToken());}\n static int ni() {return Integer.parseInt(input.nextToken());}\n static long rnl() throws IOException {input = new StringTokenizer(__in.readLine()); return Long.parseLong(input.nextToken());}\n static long nl() {return Long.parseLong(input.nextToken());}\n // output\n static void pr(int i) {__out.print(i);}\n static void prln(int i) {__out.println(i);}\n static void pr(long l) {__out.print(l);}\n static void prln(long l) {__out.println(l);}\n static void pr(double d) {__out.print(d);}\n static void prln(double d) {__out.println(d);}\n static void pr(char c) {__out.print(c);}\n static void prln(char c) {__out.println(c);}\n static void pr(char[] s) {__out.print(new String(s));}\n static void prln(char[] s) {__out.println(new String(s));}\n static void pr(String s) {__out.print(s);}\n static void prln(String s) {__out.println(s);}\n static void pr(Object o) {__out.print(o);}\n static void prln(Object o) {__out.println(o);}\n static void prln() {__out.println();}\n static void pryes() {__out.println(\"yes\");}\n static void pry() {__out.println(\"Yes\");}\n static void prY() {__out.println(\"YES\");}\n static void prno() {__out.println(\"no\");}\n static void prn() {__out.println(\"No\");}\n static void prN() {__out.println(\"NO\");}\n static void pryesno(boolean b) {__out.println(b ? \"yes\" : \"no\");};\n static void pryn(boolean b) {__out.println(b ? \"Yes\" : \"No\");}\n static void prYN(boolean b) {__out.println(b ? \"YES\" : \"NO\");}\n static void prln(int... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);}\n static void prln(long... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);}\n static void prln(Collection c) {int n = c.size() - 1; Iterator iter = c.iterator(); for(int i = 0; i < n; __out.print(iter.next()), __out.print(' '), ++i); if(n >= 0) __out.println(iter.next()); else __out.println();}\n static void h() {__out.println(\"hlfd\");}\n static void flush() {__out.flush();}\n static void close() {__out.close();}\n}", "lang_cluster": "Java", "tags": ["sortings", "dp", "greedy"], "code_uid": "f2f60da6c02d8fe378c2a192986e9ec8", "src_uid": "b3f8e769ee7719ea5c9f458428b16a4e", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.List;\nimport java.util.Scanner;\n\n\npublic class Codeforces409B implements Runnable {\n\tpublic static void main(String[] args) {\n\t\tnew Codeforces409B().run();\n\t}\n\tfinal static int MOD = 1000000000+7;\n\tpublic void run() {\n\t\tScanner in = new Scanner(System.in);\n\t\tint N = in.nextInt();\n\t\tint K = in.nextInt();\n\t\tint[][] dp = new int[2][N+1];\n\t\t\n\t\tList[] divs = new List[N+1];\n\t\tfor (int n = 1; n <= N; n++) {\n\t\t\tdivs[n] = new ArrayList<>();\n\t\t\tfor (int d = 1; d <= n; d++) {\n\t\t\t\tif (n%d == 0)\n\t\t\t\t\tdivs[n].add(d);\n\t\t\t}\n\t\t}\n\t\t\n\t\t// k = 1\n\t\tfor (int n = 1; n <= N; n++) {\n\t\t\tdp[1][n] = 1;\n\t\t}\n\t\tfor (int k = 2; k <= K; k++) {\n\t\t\tArrays.fill(dp[k&1], 0);\n\t\t\tdp[k&1][1] = 1;\n\t\t\tfor (int n = 2; n <= N; n++) {\n\t\t\t\tfor (int d : divs[n]) {\n\t\t\t\t\tdp[k&1][n] += dp[(k-1)&1][d];\n\t\t\t\t\tdp[k&1][n] %= MOD;\n\t\t\t\t}\n//\t\t\t\tfor (int d = 1; d <= n; d++) {\n//\t\t\t\t\tif (n % d == 0) {\n//\t\t\t\t\t\tdp[k&1][n] += dp[(k-1)&1][d];\n//\t\t\t\t\t\t// TODO: MOD\n//\t\t\t\t\t}\n//\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n//\t\tfor (int[] row : dp)\n//\t\t\tSystem.out.println(Arrays.toString(row));\n\t\t\n\t\tint res = 0;\n\t\tfor (int n = 1; n <= N; n++) {\n\t\t\tres += dp[K&1][n];\n\t\t\tres %= MOD;\n\t\t}\n\t\tSystem.out.println(res);\n\t}\n}\n", "lang_cluster": "Java", "tags": ["dp", "combinatorics", "number theory"], "code_uid": "83971fd124d38b706f4d9dfd33f7a286", "src_uid": "c8cbd155d9f20563d37537ef68dde5aa", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\n\npublic class A {\n\n\tprivate void work() {\n\t\tScanner sc = new Scanner(new BufferedReader(new InputStreamReader(\n\t\t\t\tSystem.in)));\n\t\tString[] a = { \"Hanako\", \"Ciel\" };\n\t\twhile (sc.hasNextInt()) {\n\t\t\tint x = sc.nextInt();\n\t\t\tint y = sc.nextInt();\n\t\t\tint cur = 0;\n\t\t\twhile (10 * x + y >= 22 && y > 1) {\n\t\t\t\tif (cur == 0) {\n\t\t\t\t\tif (x >= 2) {\n\t\t\t\t\t\tx -= 2;\n\t\t\t\t\t\ty -= 2;\n\t\t\t\t\t} else if (x == 1) {\n\t\t\t\t\t\tx--;\n\t\t\t\t\t\ty -= 12;\n\t\t\t\t\t} else {\n\t\t\t\t\t\ty -= 22;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (y >= 22) {\n\t\t\t\t\t\ty -= 22;\n\t\t\t\t\t} else if (y >= 12) {\n\t\t\t\t\t\ty -= 12;\n\t\t\t\t\t\tx--;\n\t\t\t\t\t} else {\n\t\t\t\t\t\ty -= 2;\n\t\t\t\t\t\tx -= 2;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcur = 1 - cur;\n\t\t\t}\n\t\t\tSystem.out.println(a[cur]);\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew A().work();\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["greedy"], "code_uid": "2ae9e283f85fb903cd1ce96600ef2fb8", "src_uid": "8ffee18bbc4bb281027f91193002b7f5", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.math.*;\nimport java.io.*;\npublic class FoodOnThePlane {\n\tpublic static void main(String args[]) throws Exception {\n\t\tBufferedReader s = new BufferedReader(new InputStreamReader(System.in));\n\t\t//BufferedReader s = new BufferedReader(new FileReader(\"*.in\"));\n\t\t//PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(\"*.out\")));\n\t\t//StringTokenizer st = new StringTokenizer(s.readLine());\n\t\tString y = s.readLine();\n\t\tlong row = Long.parseLong(y.substring(0, y.length()-1));\n\t\tint col = y.charAt(y.length()-1) - 'a';\n\t\tlong secs = 0;\n\t\tif(row == 1)secs = 0;\n\t\telse if (row == 2)secs = 7;\n\t\telse {\n\t\t\tlong remainder = row % 4;\n\t\t\tif(remainder == 1){\n\t\t\t\tsecs = ((row - 1) / 4) * 16;\n\t\t\t} else if (remainder == 3){\n\t\t\t\tsecs = ((row - 3)/4) * 16;\n\t\t\t} else if (remainder == 2){\n\t\t\t\tsecs = ((((row + 2) / 4)-1) * 16)+7;\n\t\t\t} else {\n\t\t\t\tsecs = (((row / 4)-1) * 16)+7;\n\t\t\t}\n\t\t}\n\t\tif(col == 0){\n\t\t\tsecs += 4;\n\t\t} else if(col == 1){\n\t\t\tsecs += 5;\n\t\t} else if(col == 2){\n\t\t\tsecs += 6;\n\t\t} else if(col == 3){\n\t\t\tsecs += 3;\n\t\t} else if(col == 4){\n\t\t\tsecs += 2;\n\t\t} else {\n\t\t\tsecs+=1;\n\t\t}\n\t\tSystem.out.println(secs);\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "ab3d85949afbe2b6b5784853440db2a5", "src_uid": "069d0cb9b7c798a81007fb5b63fa0f45", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.PriorityQueue;\nimport java.util.Scanner;\n\n\npublic class Main {\n public static void main(String[] args) {\n Scanner lector = new Scanner(System.in);\n PriorityQueue list = new PriorityQueue();\n String s = lector.next();\n int x;\n \n for(char c:s.toCharArray()){\n if(c!='+'){\n list.add(c-48);\n } \n }\n \n x = list.size();\n \n for (int i = 0; i < (x-1); i++) {\n System.out.print(list.poll()+\"+\");\n }\n System.out.println(list.poll());\n } }\n// 1509316386944\n", "lang_cluster": "Java", "tags": ["sortings", "strings", "implementation", "greedy"], "code_uid": "cc6ebefb95c2c53d0ac19fde839e3e2a", "src_uid": "76c7312733ef9d8278521cf09d3ccbc8", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main\n{\n public static void main(String[] args)\n {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n Scanner in = new Scanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskB solver = new TaskB();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskB\n {\n public void solve(int testNumber, Scanner in, PrintWriter out)\n {\n String S = in.next(), previousS = \"\";\n int K = in.nextInt();\n while (K > 0)\n {\n int moves[] = getMoves(S);\n int pos = S.length() - 1;\n int cost = 0;\n int winner = -1;\n for (int i = 0; i < moves.length; i++)\n {\n if (moves[i] == 0) continue;\n if (pos >= i - Math.min(K, moves[i]))\n {\n pos = i - moves[i];\n cost = Math.min(K, moves[i]);\n winner = i;\n }\n }\n S = swap(S, winner, cost);\n K -= cost;\n\n if (S.equals(previousS)) break;\n previousS = S;\n }\n out.println(S);\n }\n\n private String swap(String S, int winner, int cost)\n {\n char chars[] = S.toCharArray();\n for (int i = winner; i >= 0 & cost > 0; cost--, i--)\n {\n char t = chars[i - 1];\n chars[i - 1] = chars[i];\n chars[i] = t;\n }\n return new String(chars);\n }\n\n private int[] getMoves(String S)\n {\n int moves[] = new int[S.length()];\n for (int i = S.length() - 1; i >= 0; i--)\n {\n int move = 0;\n for (int j = i - 1; j >= 0; j--)\n {\n if (S.charAt(i) > S.charAt(j)) move++;\n else break;\n }\n moves[i] = move;\n }\n return moves;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["greedy"], "code_uid": "2f43a54cee294dbd77fe43ddb8826837", "src_uid": "e56f6c343167745821f0b18dcf0d0cde", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class A_216_Tiling_with_Hexagons {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint a = sc.nextInt();\n\t\tint b = sc.nextInt();\n\t\tint c = sc.nextInt();\n\t\tSystem.out.println(b * c + (a - 1) * c + (a - 1) * (b - 1));\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "fc03d41a7db4f5f34ed758c0519adfbe", "src_uid": "8ab25ed4955d978fe20f6872cb94b0da", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Factory {\n \n public static void main(String[] args) {\n \n int a, m, x;\n Scanner scan = new Scanner(System.in);\n \n a = scan.nextInt(); \n m = scan.nextInt();\n \n for (int i=1; i<=10000; i++) {\n \n x = a%m;\n if ((x+a) % m == 0){\n \n System.out.println(\"Yes\");\n return ;\n } \n else \n {\n a +=x;\n } \n \n }\n System.out.println(\"No\");\n \n }\n \n}\n", "lang_cluster": "Java", "tags": ["math", "matrices", "implementation"], "code_uid": "3b97c09bf76fab5e4d4a71ef6b0950b1", "src_uid": "f726133018e2149ec57e113860ec498a", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/*\n[ ( ^ _ ^ ) ]\n*/\nimport java.io.*;\nimport java.util.*;\n\n\npublic class check {\n int INF = (int)1e9;\n long MOD = 1000000007;\n \n \n long go(long n, long m) {\n if(n>m) {\n long t = m;\n m = n;\n n = t;\n }\n long o = n*m;\n if(n<=3 && m<=3) {\n if(n==1 || m==1) return 0;\n if(n==2 && m==2) return 0;\n if(n==2 && m==3) return 4;\n if(n==3 && m==2) return 4;\n if(n==3 && m==3) return 8;\n return 0;\n }\n if(n==1) {\n m = m%6;\n if(m==4) m = 2;\n else if(m==5) m = 1;\n return o-m;\n } else if(n==2) {\n if(m==3 || m==7) m = 2;\n else m = 0;\n return o-m;\n }\n return o-o%2;\n }\n \n void solve(InputReader in, PrintWriter out) throws IOException {\n long n = in.nextInt();\n long m = in.nextInt();\n long rs = go(n, m);\n out.println(rs);\n }\n \n \n public static void main(String[] args) throws IOException {\n if(args.length>0 && args[0].equalsIgnoreCase(\"d\")) {\n DEBUG_FLAG = true;\n }\n InputReader in = new InputReader();\n PrintWriter out = new PrintWriter(System.out);\n int t = 1;//in.nextInt();\n long start = System.nanoTime();\n while(t-- >0) {\n new check().solve(in, out);\n }\n long end = System.nanoTime();\n debug(\"\\nTime: \" + (end-start)/1e6 + \" \\n\\n\");\n out.close();\n }\n \n static boolean DEBUG_FLAG = false;\n static void debug(String s) {\n if(DEBUG_FLAG) System.out.print(s);\n }\n \n public static void show(Object... o) {\n System.out.println(Arrays.deepToString(o));\n }\n \n static class InputReader {\n static BufferedReader br;\n static StringTokenizer st;\n \n public InputReader() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n \n String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n int nextInt() {\n return Integer.parseInt(next());\n }\n \n long nextLong() {\n return Long.parseLong(next());\n }\n \n double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "constructive algorithms", "flows", "graph matchings"], "code_uid": "4f13d1cfa9937689c7db212048bc2a4d", "src_uid": "02ce135a4b276d1e9ba6a4ce37f2fe70", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.StringTokenizer;\n\npublic class C626 {\n public static void main(String[] args) throws IOException {\n ContestsScanner sc = new ContestsScanner();\n PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n int two = sc.nextInt();\n int three = sc.nextInt();\n int hTwo = two * 2;\n int hThree = three * 6;\n if (hThree > 0) {\n hThree -= 3;\n }\n int lastSix = 0;\n\n int score = Integer.MAX_VALUE;\n while (hThree > 3 && hThree > hTwo && lastSix + 6 < hThree) {\n score = Math.min(score, Math.max(hThree, hTwo));\n if (lastSix + 6 <= hTwo) {\n hTwo += 2;\n }\n lastSix += 6;\n hThree -= 6;\n }\n score = Math.min(score, Math.max(lastSix, Math.max(hThree, hTwo)));\n out.println(score);\n out.close();\n }\n\n public static class ContestsScanner {\n\n private final BufferedReader br;\n private StringTokenizer tokenizer;\n\n public ContestsScanner() throws IOException {\n br = new BufferedReader(new InputStreamReader(System.in));\n tokenizer = new StringTokenizer(br.readLine());\n }\n\n String nextToken() {\n if (!tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n int nextInt() {\n return Integer.valueOf(nextToken());\n }\n }\n}", "lang_cluster": "Java", "tags": ["math", "greedy", "number theory", "brute force"], "code_uid": "b230bade030837e0f3514856c8557fc5", "src_uid": "23f2c8cac07403899199abdcfd947a5a", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n \npublic class A {\n\t\n\t\t\n\t\n\tstatic String[] notes = {\"C\", \"C#\", \"D\", \"D#\", \"E\", \"F\", \"F#\", \"G\", \"G#\", \"A\", \"B\", \"H\" };\n\t\n\tpublic static void main(String[] agrs) {\n\t\tFastScanner sc = new FastScanner();\n//\t\tint yo = sc.nextInt();\n//\t\twhile(yo-->0) {\t\n//\t\t}\n\t\t\n\t\tString s1 = sc.next();\n\t\tString s2 = sc.next();\n\t\tString s3 = sc.next();\n\t\t\n\t\tString[] arr = {s1,s2,s3};\n\t\t\n\t\tboolean vis[] = new boolean[3];\n\t\t\n\t\tString res = gen(arr, new ArrayList(), vis,false);\n\t\t\n//\t\tif(res == null) {\n//\t\t\tSystem.out.println(\"strange\");\n//\t\t}\n//\t\telse {\n//\t\t\tSystem.out.println(res);\n//\t\t}\n\t\tSystem.out.println(ans.equals(\"minor\") || ans.equals(\"major\") ? ans : \"strange\");\n\t\t\n\t\t\n\t\t\n\t\t\n\t} \n\t\n\tstatic String ans = \"\";\n\tstatic boolean is = false;\n\tstatic String gen(String[] arr, List str, boolean[] vis, boolean is) {\n\t\t\n//\t\tSystem.out.println(str);\n\t\tif(is) return null;\n\t\t\n\t\tif(str.size() == 3) {\n//\t\t\tSystem.out.println(str);\n\t\t\tString str1 = check(str);\n//\t\t\tSystem.out.println(str1);\n\t\t\tif(str1.equals(\"major\") || str1.equals(\"minor\")) {\n\t\t\t\tis = true;\n\t\t\t\tans = str1;\n\t\t\t\treturn str1;\n\t\t\t}\n\t\t\treturn null;\n\t\t}\n\t\tfor(int i = 0; i < arr.length; i++) {\n\t\t\tif(vis[i] == false && !is) {\n\t\t\t\tvis[i] = true;\n\t\t\t\tstr.add(arr[i]);\n\t\t\t\tgen(arr,str,vis,is);\n\t\t\t\tstr.remove(str.size()-1);\n\t\t\t\tvis[i] = false;\n\t\t\t}\n\t\t}\n\t\treturn null;\n\t}\n\t\n\t\n\tstatic String check(List str) {\n\t\t\n\t\tint dist1 = getDistance(str.get(0), str.get(1));\n\t\tint dist2 = getDistance(str.get(1), str.get(2));\n//\t\tSystem.out.println(dist1 + \" \" + dist2);\n\t\tif(dist1 == 4 && dist2 == 3) {\n\t\t\treturn \"major\";\n\t\t}\n\t\tif(dist1 == 3 && dist2 == 4) {\n\t\t\treturn \"minor\";\n\t\t}\n\t\t\n\t\treturn \"\";\n\t}\n\t\n\tstatic int getDistance(String s1, String s2) {\n\t\tint index1 = 0;\n\t\tint index2 = 0;\n\t\tfor(int i = 0; i < notes.length; i++) {\n\t\t\tif(notes[i].equals(s1)) {\n\t\t\t\tindex1 = i;\n\t\t\t}\n\t\t\tif(notes[i].equals(s2)) {\n\t\t\t\tindex2 = i;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\tif(index1 < index2) {\n\t\t\treturn index2 - index1;\n\t\t}\n\t\telse {\n\t\t\treturn (notes.length-index1) + Math.abs(index2);\n\t\t}\n\t\t\n//\t\tindex2-index1 < 0 ? Math.abs(index2-index1)*2 : \n\t}\n\t\n\t\n\t\n\n\n\n\n\n\n\n\n\tstatic int gcd(int a, int b) {\n\t\treturn a%b == 0 ? b : gcd(b,a%b);\n\t}\n\t\n\tstatic int mod = 1000000007;\n\t\n\tstatic long pow(int a, int b) {\n\t\tif(b == 0) {\n\t\t\treturn 1;\n\t\t}\n\t\tif(b == 1) {\n\t\t\treturn a;\n\t\t}\n\t\tif(b%2 == 0) {\n\t\t\n\t\t\tlong ans = pow(a,b/2);\n\t\t\treturn ans*ans;\n\t\t}\n\t\telse {\n\t\t\tlong ans = pow(a,(b-1)/2);\n\t\t\treturn a * ans * ans;\n\t\t}\n\t\t\n\t}\n\t\n\tstatic boolean[] sieve(int n) {\n\t\t\n\t\tboolean isPrime[] = new boolean[n+1];\n\t\tfor(int i = 2; i <= n; i++) {\n\t\t\tif(isPrime[i]) continue;\n\t\t\tfor(int j = 2*i; j <= n; j+=i) {\n\t\t\t\tisPrime[j] = true;\n\t\t\t}\t\t\n\t\t}\n\t\treturn isPrime;\n\t}\n\t\n\n\tstatic class FastScanner {\n\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st=new StringTokenizer(\"\");\n\t\tString next() {\n\t\t\twhile (!st.hasMoreTokens())\n\t\t\t\ttry {\n\t\t\t\t\tst=new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\t\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tint[] readArray(int n) {\n\t\t\tint[] a=new int[n];\n\t\t\tfor (int i=0; i=0){\n\t\t\ta[1]-=x;\n\t\t\tif (x==a[0])x=1;else x++;}\n\t\t\tif(x==1)x=a[0];else x--;\n\t\t\tSystem.out.println(a[1]+x);\n \n\t}\n}\t\nclass Androiz{\n\tstatic int lengthArray=-1;\n\t\n\tstatic int[] separator(String s,String pr){\n\t\tint[] n;\n\t\tString[] stringArray;\n\t\tchar[] charArray;\n\t\tif(pr==\" \"){\n\t\t\tstringArray=s.split(\" \");\n\t\t\tn=new int[(s.length()+1)/2];\n\t\t\tfor(int i=0;i List[] createGraphList(int size) {\n List[] list = new List[size];\n for (int i = 0; i < size; i++) {\n list[i] = new ArrayList<>();\n }\n return list;\n }\n\n public static void main(String[] args) {\n new Thread(null, new Template(), \"\", 1l * 200 * 1024 * 1024).start();\n }\n\n long timeBegin, timeEnd;\n\n void time() {\n timeEnd = System.currentTimeMillis();\n System.err.println(\"Time = \" + (timeEnd - timeBegin));\n }\n\n long memoryTotal, memoryFree;\n\n void memory() {\n memoryFree = Runtime.getRuntime().freeMemory();\n System.err.println(\"Memory = \" + ((memoryTotal - memoryFree) >> 10)\n + \" KB\");\n }\n\n public void run() {\n try {\n timeBegin = System.currentTimeMillis();\n memoryTotal = Runtime.getRuntime().freeMemory();\n init();\n solve();\n out.close();\n if (System.getProperty(\"ONLINE_JUDGE\") == null) {\n time();\n memory();\n }\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(-1);\n }\n }\n\n int mod = (int) 1e9 + 7;\n\n int rev(int x, int n) {\n return n - x + 1;\n }\n\n void solve() throws IOException {\n int n = readInt();\n int a = readInt();\n int b = readInt();\n int k = readInt();\n\n if (a > b) {\n a = rev(a, n);\n b = rev(b, n);\n }\n\n long[] dp = new long[n + 1];\n dp[a] = 1;\n\n for (int it = 0; it < k; it++) {\n long[] next = new long[n + 1];\n long[] decrease = new long[n + 1];\n\n long sum = 0;\n for (int i = 1; i < b; i++) {\n int len = Math.abs(b - i) - 1;\n next[i] += sum;\n sum += dp[i];\n if (i - len > 0) decrease[i - len] += dp[i];\n }\n sum = 0;\n for (int i = b - 2; i > 0; i--) {\n next[i] += sum;\n sum += dp[i];\n sum -= decrease[i];\n }\n for (int i = 1; i <= n; i++) {\n dp[i] = next[i] % mod;\n }\n }\n\n long answer = 0;\n for (long d : dp)\n answer = (answer + d) % mod;\n out.println(answer);\n\n }\n}", "lang_cluster": "Java", "tags": ["dp", "combinatorics"], "code_uid": "9d698500c7c4d92e8bac352ef55189bc", "src_uid": "142b06ed43b3473513995de995e19fc3", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\n/**\n * User: chen\n */\npublic class DifferenceRow {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int[] num = new int[n];\n for (int i = 0; i < n; i++) {\n num[i] = in.nextInt();\n }\n Arrays.sort(num);\n System.out.print(num[n - 1] + \" \");\n if (n > 2) {\n for (int i = 1; i < n - 1; i++) {\n System.out.print(num[i] + \" \");\n }\n }\n System.out.print(num[0]);\n }\n}\n", "lang_cluster": "Java", "tags": ["sortings", "constructive algorithms", "implementation"], "code_uid": "24fa129dea34e6f385468bb246437a14", "src_uid": "4408eba2c5c0693e6b70bdcbe2dda2f4", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.PrintWriter;\nimport java.util.Scanner;\nimport java.util.HashMap;\nimport java.util.Map;\n\npublic class Smile {\n\tstatic Scanner in;\n\tstatic PrintWriter out;\n\n\tpublic static void main(String[] args) {\n\t\tin = new Scanner(System.in);\n\t\tout = new PrintWriter(System.out);\n//\t\tMap a = new HashMap();\n\t\tlong n = in.nextInt();\n\t\tlong m = in.nextInt();\n\t\tlong k = n;\n\t\tint i = 0;\n\t\twhile (k < m) {\n//\t\t\ta.put(k, i);\n\t\t\ti++;\n\t\t\tk *= n;\n\t\t}\n\t\tif (k == m) {\n\t\t\tout.println(\"YES\");\n\t\t\tout.println(i);\n\t\t} else {\n\t\t\tout.println(\"NO\");\n\t\t}\n\t\t\n\t\tout.close();\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "8d4fbf2ee04dcebdfb45dadbbf988637", "src_uid": "8ce89b754aa4080e7c3b2c3b10f4be46", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class Main {\n private static boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n private static Reader in;\n private static PrintWriter out;\n ////////////////////////////////////////////////////////////////////////////////////////////////////\n private static int min(int... a){int min=a[0]; for(int i:a) min=Math.min(min, i); return min;}\n private static int max(int... a){int max=a[0]; for(int i:a) max=Math.max(max, i); return max;}\n private static long min(long... a){long min=a[0]; for(long i:a)min=Math.min(min, i); return min;}\n private static long max(long... a){long max=a[0]; for(long i:a)max=Math.max(max, i); return max;}\n private static String strm(String str, long m) {\n String ans=\"\";\n while(m>0) {\n if(m%2==1) ans=ans.concat(str);\n str=str.concat(str); m>>=1;\n } return ans;\n }\n private static long mod(long a, long mod) {long res = a%mod; return res>=0 ? res : res+mod;}\n private static int mod(int a, int mod) {int res = a%mod; return res>=0 ? res : res+mod;}\n private static long modpow(long x, int n, int mod) {\n long res = 1;\n for (long p = x; n > 0; n >>= 1, p = mod((mod(p, mod)*mod(p, mod)), mod)) {\n if ((n & 1) != 0) res = mod(mod(res, mod) * mod(p, mod), mod);\n }\n return res;\n }\n private static long gcd(long a, long b) {return b == 0 ? Math.abs(a) : gcd(b, a % b);}\n private static int gcd(int a, int b) {return b == 0 ? Math.abs(a) : gcd(b, a % b);}\n private static long gcd(long... a) {long gcd=a[0]; for(long x:a) gcd=gcd(gcd, x); return gcd;}\n private static int gcd(int... a) {int gcd=a[0]; for(int x:a) gcd=gcd(gcd, x); return gcd;}\n private static long lcm(long a, long b) {return Math.abs(a / gcd(a, b) * b);}\n private static class Pair {\n public int x, y;\n public Pair(int x, int y) {\n this.x = x;\n this.y = y;\n }\n @Override\n public boolean equals(Object obj) {\n if (obj == this) return true;\n if (!(obj instanceof Pair)) return false;\n Pair pair = (Pair)obj;\n return this.x == pair.x && this.y == pair.y;\n }\n\n @Override\n public int hashCode() {\n return (this.x+\" \"+this.y).hashCode();\n }\n }\n private static class Triplet {\n public int x, y, z;\n public Triplet(int x, int y, int z) {\n this.x = x;\n this.y = y;\n this.z = z;\n }\n @Override\n public boolean equals(Object obj) {\n if (obj == this) return true;\n if (!(obj instanceof Triplet)) return false;\n Triplet triplet = (Triplet)obj;\n return this.x == triplet.x && this.y == triplet.y && this.z == triplet.z;\n }\n\n @Override\n public int hashCode() {\n return (this.x+\" \"+this.y+\" \"+this.z).hashCode();\n }\n }\n ////////////////////////////////////////////////////////////////////////////////////////////////////\n static class Reader {\n private BufferedReader br;\n private StringTokenizer token;\n protected Reader(FileReader obj) {\n br = new BufferedReader(obj, 32768);\n token = null;\n }\n protected Reader() {\n br = new BufferedReader(new InputStreamReader(System.in), 32768);\n token = null;\n }\n protected String next() {\n while(token == null || !token.hasMoreTokens()) {\n try {\n token = new StringTokenizer(br.readLine());\n } catch (Exception e) {e.printStackTrace();}\n } return token.nextToken();\n }\n protected String nextLine() {\n String str=\"\";\n try {\n str = br.readLine();\n } catch (Exception e) {e.printStackTrace();}\n return str;\n }\n protected int nextInt() {return Integer.parseInt(next());}\n protected long nextLong() {return Long.parseLong(next());}\n protected double nextDouble() {return Double.parseDouble(next());}\n protected long[] nextLongArr(int n) {\n long[] arr = new long[n]; for(int i=0; ip;i--)\n {\n \t int flag=1;\n \t for(int j=2;j*j<=y && j<=p;j++)\n \t {\n \t\t if(i%j==0) {flag=0;break;}\n \t }\n \t \n \t if(flag==1) {System.out.println(i); return;}\n }\n \n System.out.println(\"-1\");\n }\n}\n\nclass Reader\n{\n final private int BUFFER_SIZE = 1 << 16;\n\n private DataInputStream din;\n private byte[] buffer;\n private int bufferPointer, bytesRead;\n\n public Reader(InputStream in)\n {\n din = new DataInputStream(in);\n buffer = new byte[BUFFER_SIZE];\n bufferPointer = bytesRead = 0;\n }\n\n public long nextLong() throws Exception\n {\n long ret = 0;\n byte c = read();\n while (c <= ' ') c = read();\n boolean neg = c == '-';\n if (neg) c = read();\n do\n {\n ret = ret * 10 + c - '0';\n c = read();\n } while (c > ' ');\n if (neg) return -ret;\n return ret;\n }\n \n //reads in the next string\n public String next() throws Exception\n {\n StringBuilder ret = new StringBuilder();\n byte c = read();\n while (c <= ' ') c = read();\n do\n {\n ret = ret.append((char)c);\n c = read();\n } while (c > ' ');\n return ret.toString();\n }\n\n public int nextInt() throws Exception\n {\n int ret = 0;\n byte c = read();\n while (c <= ' ') c = read();\n boolean neg = c == '-';\n if (neg) c = read();\n do\n {\n ret = ret * 10 + c - '0';\n c = read();\n } while (c > ' ');\n if (neg) return -ret;\n return ret;\n }\n \n private void fillBuffer() throws Exception\n {\n bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n if (bytesRead == -1) buffer[0] = -1;\n }\n\n private byte read() throws Exception\n {\n if (bufferPointer == bytesRead) fillBuffer();\n return buffer[bufferPointer++];\n }\n}\n\n", "lang_cluster": "Java", "tags": ["brute force", "math", "number theory"], "code_uid": "118b37ed96e13f525beea18ee1f47311", "src_uid": "b533203f488fa4caf105f3f46dd5844d", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\nimport java.util.*;\r\n\r\npublic class CF1{\r\n public static void main(String[] args) {\r\n FastScanner sc=new FastScanner();\r\n int T=sc.nextInt();\r\n// int T=1;\r\n for (int tt=0; tt=1; i--){\r\n ans*=i;\r\n// ans%=mod;\r\n }\r\n return ans;\r\n }\r\n static int mod =1073741825;\r\n static long power2 (long a, long b){\r\n long res=1;\r\n while (b>0){\r\n if ((b&1)== 1){\r\n res= (res * a % mod)%mod;\r\n }\r\n a=(a%mod * a%mod)%mod;\r\n b=b>>1;\r\n }\r\n return res;\r\n }\r\n\r\n boolean[] sieveOfEratosthenes(int n)\r\n {\r\n\r\n boolean prime[] = new boolean[n+1];\r\n for(int i=0;i<=n;i++)\r\n prime[i] = true;\r\n\r\n for(int p = 2; p*p <=n; p++)\r\n {\r\n if(prime[p] == true)\r\n {\r\n for(int i = p*p; i <= n; i += p)\r\n prime[i] = false;\r\n }\r\n }\r\n return prime;\r\n }\r\n static void sort(int[] a) {\r\n ArrayList l=new ArrayList<>();\r\n for (int i:a) l.add(i);\r\n Collections.sort(l);\r\n for (int i=0; i l=new ArrayList<>();\r\n for (long i:a) l.add(i);\r\n Collections.sort(l);\r\n for (int i=0; i{\r\n int x,y;\r\n public Pair(int x, int y){\r\n this.x = x;\r\n this.y = y;\r\n }\r\n public int compareTo(Pair o){\r\n return this.x-o.x;\r\n }\r\n // this.x-o.x is ascending\r\n }\r\n static class FastScanner {\r\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\r\n StringTokenizer st=new StringTokenizer(\"\");\r\n String next() {\r\n while (!st.hasMoreTokens())\r\n try {\r\n st=new StringTokenizer(br.readLine());\r\n } catch (IOException e) {\r\n e.printStackTrace();\r\n }\r\n return st.nextToken();\r\n }\r\n\r\n int nextInt() {\r\n return Integer.parseInt(next());\r\n }\r\n int[] readArray(int n) {\r\n int[] a=new int[n];\r\n for (int i=0; i= 0; i--) {\n\t\t\tif (s.charAt(i) >= 'a' && s.charAt(i) <= 'z') {\n\t\t\t\tt = s.charAt(i);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tif (t == 'a' || t == 'e' || t == 'i' || t == 'o' || t == 'u'\n\t\t\t\t|| t == 'y')\n\t\t\tSystem.out.println(\"YES\");\n\t\telse\n\t\t\tSystem.out.println(\"NO\");\n\n\t}\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "350f618d5187655280054c6aa78d5fa1", "src_uid": "dea7eb04e086a4c1b3924eff255b9648", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\r\nimport java.io.*;\r\nimport java.math.*;\r\n\r\n/**\r\n *\r\n * @Har_Har_Mahadev\r\n */\r\n\r\n/**\r\n * Main , Solution , Remove Public\r\n */\r\npublic class D {\r\n\r\n\tpublic static void process() throws IOException {\r\n\t\tint n = sc.nextInt();\r\n\t\tlong dp[] = new long[n+1];\r\n\t\tfor(int i = 2; i<=n; i++) {\r\n\t\t\tfor(int j = i; j<=n; j+=i)dp[j]++;\r\n\t\t}\r\n\t\tdp[0] = 1;\r\n\t\tlong sum = 1;\r\n\t\tfor(int i=1; i<=n; i++) {\r\n\t\t\tdp[i] = (dp[i] + sum)%MM;\r\n\t\t\tsum = (sum+dp[i])%MM;\r\n\t\t}\r\n\t\tprintln(dp[n]);\r\n\r\n\t}\r\n\r\n\t//=============================================================================\r\n\t//--------------------------The End---------------------------------\r\n\t//=============================================================================\r\n\tprivate static long INF = 2000000000000000000L, M = 1000000007, MM = 998244353;\r\n\tprivate static int N = 1_000_005;\r\n\r\n\tprivate static void google(int tt) {\r\n\t\tSystem.out.print(\"Case #\" + (tt) + \": \");\r\n\t}\r\n\r\n\tstatic FastScanner sc;\r\n\tstatic PrintWriter out;\r\n\r\n\tpublic static void main(String[] args) throws IOException {\r\n\t\tboolean oj = true;\r\n\t\tif (oj) {\r\n\t\t\tsc = new FastScanner();\r\n\t\t\tout = new PrintWriter(System.out);\r\n\t\t} else {\r\n\t\t\tsc = new FastScanner(100);\r\n\t\t\tout = new PrintWriter(\"output.txt\");\r\n\t\t}\r\n\t\tint t = 1;\r\n//\t\tt = sc.nextInt();\r\n\t\tint TTT = 1;\r\n\t\twhile (t-- > 0) {\r\n\t\t\t//\t\t\tgoogle(TTT++);\r\n\t\t\tprocess();\r\n\t\t}\r\n\t\tout.flush();\r\n\t\tout.close();\r\n\t}\r\n\r\n\tstatic class Pair implements Comparable {\r\n\t\tint x, y;\r\n\r\n\t\tPair(int x, int y) {\r\n\t\t\tthis.x = x;\r\n\t\t\tthis.y = y;\r\n\t\t}\r\n\r\n\t\t@Override\r\n\t\tpublic int compareTo(Pair o) {\r\n\t\t\treturn Integer.compare(this.x, o.x);\r\n\t\t}\r\n\r\n\t\t//\t\t @Override\r\n\t\t//\t\t public boolean equals(Object o) {\r\n\t\t//\t\t if (this == o) return true;\r\n\t\t//\t\t if (!(o instanceof Pair)) return false;\r\n\t\t//\t\t Pair key = (Pair) o;\r\n\t\t//\t\t return x == key.x && y == key.y;\r\n\t\t//\t\t }\r\n\t\t//\t\t \r\n\t\t//\t\t @Override\r\n\t\t//\t\t public int hashCode() {\r\n\t\t//\t\t int result = x;\r\n\t\t//\t\t result = 31 * result + y;\r\n\t\t//\t\t return result;\r\n\t\t//\t\t }\r\n\t}\r\n\r\n\t/////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n\r\n\tstatic void println(Object o) {\r\n\t\tout.println(o);\r\n\t}\r\n\r\n\tstatic void println() {\r\n\t\tout.println();\r\n\t}\r\n\r\n\tstatic void print(Object o) {\r\n\t\tout.print(o);\r\n\t}\r\n\r\n\tstatic void pflush(Object o) {\r\n\t\tout.println(o);\r\n\t\tout.flush();\r\n\t}\r\n\r\n\tstatic int ceil(int x, int y) {\r\n\t\treturn (x % y == 0 ? x / y : (x / y + 1));\r\n\t}\r\n\r\n\tstatic long ceil(long x, long y) {\r\n\t\treturn (x % y == 0 ? x / y : (x / y + 1));\r\n\t}\r\n\r\n\tstatic int max(int x, int y) {\r\n\t\treturn Math.max(x, y);\r\n\t}\r\n\r\n\tstatic int min(int x, int y) {\r\n\t\treturn Math.min(x, y);\r\n\t}\r\n\r\n\tstatic int abs(int x) {\r\n\t\treturn Math.abs(x);\r\n\t}\r\n\r\n\tstatic long abs(long x) {\r\n\t\treturn Math.abs(x);\r\n\t}\r\n\r\n\tstatic long sqrt(long z) {\r\n\t\tlong sqz = (long) Math.sqrt(z);\r\n\t\twhile (sqz * 1L * sqz < z) {\r\n\t\t\tsqz++;\r\n\t\t}\r\n\t\twhile (sqz * 1L * sqz > z) {\r\n\t\t\tsqz--;\r\n\t\t}\r\n\t\treturn sqz;\r\n\t}\r\n\r\n\tstatic int log2(int N) {\r\n\t\tint result = (int) (Math.log(N) / Math.log(2));\r\n\t\treturn result;\r\n\t}\r\n\r\n\tstatic long max(long x, long y) {\r\n\t\treturn Math.max(x, y);\r\n\t}\r\n\r\n\tstatic long min(long x, long y) {\r\n\t\treturn Math.min(x, y);\r\n\t}\r\n\r\n\tpublic static int gcd(int a, int b) {\r\n\t\tBigInteger b1 = BigInteger.valueOf(a);\r\n\t\tBigInteger b2 = BigInteger.valueOf(b);\r\n\t\tBigInteger gcd = b1.gcd(b2);\r\n\t\treturn gcd.intValue();\r\n\t}\r\n\r\n\tpublic static long gcd(long a, long b) {\r\n\t\tBigInteger b1 = BigInteger.valueOf(a);\r\n\t\tBigInteger b2 = BigInteger.valueOf(b);\r\n\t\tBigInteger gcd = b1.gcd(b2);\r\n\t\treturn gcd.longValue();\r\n\t}\r\n\r\n\tpublic static long lcm(long a, long b) {\r\n\t\treturn (a * b) / gcd(a, b);\r\n\t}\r\n\r\n\tpublic static int lcm(int a, int b) {\r\n\t\treturn (a * b) / gcd(a, b);\r\n\t}\r\n\r\n\tpublic static int lower_bound(int[] arr, int x) {\r\n\t\tint low = 0, high = arr.length, mid = -1;\r\n\r\n\t\twhile (low < high) {\r\n\t\t\tmid = (low + high) / 2;\r\n\r\n\t\t\tif (arr[mid] >= x)\r\n\t\t\t\thigh = mid;\r\n\t\t\telse\r\n\t\t\t\tlow = mid + 1;\r\n\t\t}\r\n\r\n\t\treturn low;\r\n\t}\r\n\r\n\tpublic static int upper_bound(int[] arr, int x) {\r\n\t\tint low = 0, high = arr.length, mid = -1;\r\n\r\n\t\twhile (low < high) {\r\n\t\t\tmid = (low + high) / 2;\r\n\r\n\t\t\tif (arr[mid] > x)\r\n\t\t\t\thigh = mid;\r\n\t\t\telse\r\n\t\t\t\tlow = mid + 1;\r\n\t\t}\r\n\r\n\t\treturn low;\r\n\t}\r\n\r\n\t/////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n\r\n\tstatic class FastScanner {\r\n\t\tBufferedReader br;\r\n\t\tStringTokenizer st;\r\n\r\n\t\tFastScanner() throws FileNotFoundException {\r\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\r\n\t\t}\r\n\r\n\t\tFastScanner(int a) throws FileNotFoundException {\r\n\t\t\tbr = new BufferedReader(new FileReader(\"input.txt\"));\r\n\t\t}\r\n\r\n\t\tString next() throws IOException {\r\n\t\t\twhile (st == null || !st.hasMoreElements()) {\r\n\t\t\t\ttry {\r\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\r\n\t\t\t\t} catch (IOException e) {\r\n\t\t\t\t\te.printStackTrace();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn st.nextToken();\r\n\t\t}\r\n\r\n\t\tint nextInt() throws IOException {\r\n\t\t\treturn Integer.parseInt(next());\r\n\t\t}\r\n\r\n\t\tlong nextLong() throws IOException {\r\n\t\t\treturn Long.parseLong(next());\r\n\t\t}\r\n\r\n\t\tdouble nextDouble() throws IOException {\r\n\t\t\treturn Double.parseDouble(next());\r\n\t\t}\r\n\r\n\t\tString nextLine() throws IOException {\r\n\t\t\tString str = \"\";\r\n\t\t\ttry {\r\n\t\t\t\tstr = br.readLine();\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\te.printStackTrace();\r\n\t\t\t}\r\n\t\t\treturn str;\r\n\t\t}\r\n\r\n\t\tint[] readArray(int n) throws IOException {\r\n\t\t\tint[] A = new int[n];\r\n\t\t\tfor (int i = 0; i != n; i++) {\r\n\t\t\t\tA[i] = sc.nextInt();\r\n\t\t\t}\r\n\t\t\treturn A;\r\n\t\t}\r\n\r\n\t\tlong[] readArrayLong(int n) throws IOException {\r\n\t\t\tlong[] A = new long[n];\r\n\t\t\tfor (int i = 0; i != n; i++) {\r\n\t\t\t\tA[i] = sc.nextLong();\r\n\t\t\t}\r\n\t\t\treturn A;\r\n\t\t}\r\n\t}\r\n\r\n\tstatic void ruffleSort(int[] a) {\r\n\t\tRandom get = new Random();\r\n\t\tfor (int i = 0; i < a.length; i++) {\r\n\t\t\tint r = get.nextInt(a.length);\r\n\t\t\tint temp = a[i];\r\n\t\t\ta[i] = a[r];\r\n\t\t\ta[r] = temp;\r\n\t\t}\r\n\t\tArrays.sort(a);\r\n\t}\r\n\r\n\tstatic void ruffleSort(long[] a) {\r\n\t\tRandom get = new Random();\r\n\t\tfor (int i = 0; i < a.length; i++) {\r\n\t\t\tint r = get.nextInt(a.length);\r\n\t\t\tlong temp = a[i];\r\n\t\t\ta[i] = a[r];\r\n\t\t\ta[r] = temp;\r\n\t\t}\r\n\t\tArrays.sort(a);\r\n\t}\r\n}\r\n", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics", "number theory"], "code_uid": "b5b61db1cda83984ff3e84966f106299", "src_uid": "09be46206a151c237dc9912df7e0f057", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "\n\n\nimport java.io.*;\nimport java.util.*;\nimport java.util.logging.Level;\nimport java.util.logging.Logger;\nimport static java.lang.System.*;\n\n\npublic class NewClass{\n public static BufferedReader br;\n static FastReader s = new FastReader();\n public static BufferedWriter bor = new BufferedWriter(new OutputStreamWriter(out));\n public static void main(String[] args) throws IOException{\n //int t = s.nextInt();\n //while(t-->0){\n solve();\n //}\n }\n \n static void solve() throws IOException{\n long k2 = s.nextLong(),k3 = s.nextLong(),k5 = s.nextLong(),k6 = s.nextLong();\n long answer = Math.min(k2,Math.min(k5, k6))*256 + Math.min(k2 - Math.min(k2,Math.min(k5, k6)),k3) * 32;\n println(answer);\n }\n \n \n \n static class FastReader{\n private StringTokenizer st;\n \n public FastReader(){\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n \n String next(){\n while(st == null || !st.hasMoreElements()){\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException ex) {\n Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);\n }\n }\n return st.nextToken();\n }\n \n String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException ex) {\n Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);\n }\n return str;\n }\n \n int nextInt(){\n return Integer.parseInt(next());\n }\n \n long nextLong(){\n return Long.parseLong(next());\n }\n \n float nextFloat(){\n return Float.parseFloat(next());\n }\n \n double nextDouble(){\n return Double.parseDouble(next());\n }\n }\n \n static void println(){\n out.println();\n }\n \n static void print(){\n out.print(\"\");\n }\n \n static void println(String flouu){\n out.println(flouu);\n }\n \n static void println(long flouu){\n out.println(flouu);\n }\n \n static void println(double flouu){\n out.println(flouu);\n }\n static void println(float flouu){\n out.println(flouu);\n }\n \n static void println(char flouu){\n out.println(flouu);\n }\n \n static void print(char flouu){\n out.print(flouu);\n }\n \n static void print(String flouu){\n out.print(flouu);\n }\n \n static void print(long flouu){\n out.print(flouu);\n }\n \n static void print(double flouu){\n out.print(flouu);\n }\n static void print(float flouu){\n out.print(flouu);\n }\n \n}", "lang_cluster": "Java", "tags": ["math", "greedy", "implementation", "brute force"], "code_uid": "86d84925a4e27f75f2cde458f88537f2", "src_uid": "082b31cc156a7ba1e0a982f07ecc207e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class RookBishopAndKing {\n\n void run() throws Exception {\n BufferedReader bfd = new BufferedReader(\n new InputStreamReader(System.in));\n StringTokenizer tk = new StringTokenizer(bfd.readLine());\n int r1 = Integer.parseInt(tk.nextToken());\n int c1 = Integer.parseInt(tk.nextToken());\n int r2 = Integer.parseInt(tk.nextToken());\n int c2 = Integer.parseInt(tk.nextToken());\n \n int r = 0, b = 0, k = 0;\n r += (r1 == r2 ? 0 : 1);\n r += (c1 == c2 ? 0 : 1);\n \n if ((r1 + c1)%2 == (r2 + c2)%2) {\n if (Math.abs(r1 - r2) == Math.abs(c1 - c2))\n b = 1;\n else\n b = 2;\n }\n \n int dx = Math.abs(r1 - r2);\n int dy = Math.abs(c1 - c2);\n k = dx + dy - Math.min(dx, dy);\n \n System.out.println(r + \" \" + b + \" \" + k);\n }\n \n public static void main(String[] args) throws Exception {\n new RookBishopAndKing().run();\n }\n\n}\n", "lang_cluster": "Java", "tags": ["math", "graphs", "shortest paths"], "code_uid": "852720b4635f161076b38ea8f146bd9b", "src_uid": "7dbf58806db185f0fe70c00b60973f4b", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.*;\n\npublic class codeforces {\n public static void main(String args[]) {\n Scanner sc = new Scanner(System.in);\n int a = sc.nextInt();\n int b = sc.nextInt();\n int min= a>b ? b : a;\n if (min%2==0){System.out.print(\"Malvika\");}else{System.out.print(\"Akshat\");}\n }\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "3a6aab63ab40e4bbf94d9eae5f201c47", "src_uid": "a4b9ce9c9f170a729a97af13e81b5fe4", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.Scanner;\n\npublic class buttons {\n public static void main(String args[])\n {\n Scanner s = new Scanner(System.in);\n System.out.println(worst_times(s.nextInt()));\n }\n private static int worst_times(int n)\n {\n int total = 0;\n for(int i=1;i= 0; j--)\n\t\t\t\t\ts += t.charAt(j);\n\t\t\t\t\n\t\t\t\ts += t.substring(i);\n\t\t\t\tt = s;\n\t\t\t\ts = \"\";\n\t\t\t}\n\t\tSystem.out.println(t);\n\t}\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "1ee6d560c74fa0a059b8abf9c4b047f7", "src_uid": "1b0b2ee44c63cb0634cb63f2ad65cdd3", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Main {\n\n\tpublic static void main(String[] args) {\n\n\t\tScanner in = new Scanner(System.in);\n\t\tint N = in.nextInt();\n\t\tString str = in.next();\n\t\tSystem.out.println(getAns(str, N));\n\t\tin.close();\n\t}\n\n\tpublic static int getAns(String str, int N) {\n\t\tint ans = 0;\n\t\tStringBuilder sb = new StringBuilder(str);\n\t\tfor (int i = 25; i >= 0; i--) {\n\t\t\tchar ch = (char) (97 + i);\n\t\t\tfor (int j = 0; j < sb.length(); j++) {\n\t\t\t\tif (sb.length() == 1) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tchar ch1 = sb.charAt(j);\n\t\t\t\tif (ch != ch1) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n//\t\t\t\tSystem.out.println(j);\n\t\t\t\tif (j == 0 && ((int) ch - 1 == (int) sb.charAt(j + 1))) {\n\t\t\t\t\t//System.out.println(\"leftMost \" + j);\n\t\t\t\t\tsb.deleteCharAt(j);\n\t\t\t\t\tans++;\n\t\t\t\t\tj -= 1;\n\t\t\t\t\tcontinue;\n\t\t\t\t} else if (j == sb.length() - 1 && ((int) ch - 1 == (int) sb.charAt(j - 1))) {\n\t\t\t\t\t//System.out.println(\"rightMost \" + j);\n\t\t\t\t\tsb.deleteCharAt(j);\n\t\t\t\t\tans++;\n\t\t\t\t\tj -= 1;\n\t\t\t\t\tcontinue;\n\t\t\t\t} else if ((j < sb.length() - 1 && (int) ch - 1 == (int) sb.charAt(j + 1))\n\t\t\t\t\t\t|| (j > 0 && (int) ch - 1 == (int) sb.charAt(j - 1))) {\n\t\t\t\t\t//System.out.println(\"middle \" + j);\n\t\t\t\t\tsb.deleteCharAt(j);\n\t\t\t\t\tans++;\n\t\t\t\t\tj -= 2;\n\t\t\t\t\t//System.out.println(\"middle \" + j + \" \" + sb.toString() + \" \" + sb.length());\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t//System.out.println(sb.toString());\n\t\t\t}\n\t\t}\n\t\treturn ans;\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["brute force", "greedy", "strings", "constructive algorithms"], "code_uid": "770d421bfb5c6df811ba45baa8e43a4a", "src_uid": "9ce37bc2d361f5bb8a0568fb479b8a38", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\n/*\n_\u041f\u0435\u0440\u0435\u0441\u0434\u0430\u0447\u0430\n*/\npublic class A991 {\n public static void main(String...args){\n Scanner sc = new Scanner(System.in);\n int a = sc.nextInt();\n int b = sc.nextInt();\n int c = sc.nextInt();\n int n = sc.nextInt();\n System.out.println(method(a, b, c, n));\n }\n public static int method(int a, int b, int c, int n){\n int answer = n - (a+b-c);\n if(a+b-c >= n||a 0) {\n\t\t\t\t \n\t\t\t\t count += values[j];\n\t\t\t\t max = Math.max(max, values[j]);\n\t\t\t\t min = Math.min(min, values[j]);\n\t\t\t }\n\t\t }\n\t\t if( count >= l && count <=r && (max - min) >= x) {\n\t\t\t res++;\n\t\t }\n\t }\n\t System.out.println(res);\n }\n \n \n static int remove(String s) {\n\t if(s.length() ==0)\n\t\t return 0;\n\t boolean found = false;\n\t int index = 0;\n\t for(int i = 0 ; i < s.length()-1 ; i++) {\n\t\t if(s.charAt(i) =='0' && s.charAt(i+1) =='1') {\n\t\t\t found = true;\n\t\t }\n\t\t if(s.charAt(i) =='1' && s.charAt(i+1) =='0') {\n\t\t\t found = true;\n\t\t }\n\t\t if(found) {\n\t\t\t index = i;\n\t\t\t break;\n\t\t }\n\t }\n\t if(!found)\n\t\t return s.length();\n\t \n\t if(found && s.length() == 2)\n\t\t return 0;\n\t return remove(s.substring(0, index)+s.substring(index+2, s.length()));\n\t \n }\n \n static void taste(int t[], int c[], int i, int j) {\n\t \n }\n \n static String findDist(int r1, int c1, int n, int m, String []cave, int r2, int c2, String [][] mem) {\n\t \n\t if(r1 >=n || c1>=m || r1 <0 || c1 <0)\n\t\t return \"\";\n\t \n\t if(cave[n].charAt(m) == 'X') \n\t\t return \"\";\n\t \n\t String value = \"\";\n\t \n\t if(r1 == r2 && c1 == c2) {\n\t\t value = \"YES\";\n\t\t return value;\n\n\t }\n\t \n\t if(cave[n].charAt(m) == '.') \n\t\t return \".\";\n\n\t \n\t String value1 = findDist(r1+1, c1, n,m, cave, r2, c2, mem);\n\t String value2 = findDist(r1, c1+1, n,m, cave, r2, c2, mem);\n\t String value3 = findDist(r1-1, c1, n,m, cave, r2, c2, mem);\n\t String value4 = findDist(r1, c1-1, n,m, cave, r2, c2, mem);\n\t \n\t \n\n\t return value;\n }\n\n public static void main(String args[]) {\n try {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(new OutputStreamWriter(System.out));\n solve();\n in.close();\n out.close();\n } catch (Throwable e) {\n e.printStackTrace();\n System.exit(1);\n }\n }\n\n static int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n static int[] nextIntArray(int len, int start) throws IOException {\n int[] a = new int[len];\n for (int i = start; i < len; i++)\n a[i] = nextInt();\n return a;\n }\n\n static long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n static long[] nextLongArray(int len, int start) throws IOException {\n long[] a = new long[len];\n for (int i = start; i < len; i++)\n a[i] = nextLong();\n return a;\n }\n\n static double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n static double[] nextDoubleArray(int len, int start) throws IOException {\n double[] a = new double[len];\n for (int i = start; i < len; i++)\n a[i] = nextDouble();\n return a;\n }\n\n static BigInteger nextBigInteger() throws IOException {\n return new BigInteger(next());\n }\n\n static String next() throws IOException {\n while (tok == null || !tok.hasMoreTokens()) {\n tok = new StringTokenizer(in.readLine());\n }\n return tok.nextToken();\n }\n\n static String nextLine() throws IOException {\n tok = new StringTokenizer(\"\");\n return in.readLine();\n }\n\n static void shuffleArray(long[] array) {\n Random random = new Random();\n for (int i = array.length - 1; i > 0; i--) {\n int index = random.nextInt(i + 1);\n long temp = array[index];\n array[index] = array[i];\n array[i] = temp;\n }\n }\n\n static boolean hasNext() throws IOException {\n while (tok == null || !tok.hasMoreTokens()) {\n String s = in.readLine();\n if (s == null) {\n return false;\n }\n tok = new StringTokenizer(s);\n }\n return true;\n }\n \n public static int[] readIntArray(int size) throws IOException {\n int[] result = new int[(int) size];\n for (int i = 0; i < size; i++) {\n result[(int) i] = (int)nextInt();\n }\n return result;\n }\n\n}", "lang_cluster": "Java", "tags": ["brute force", "bitmasks"], "code_uid": "fd22406fb24a3c1807b50a63cc6505b9", "src_uid": "0d43104a0de924cdcf8e4aced5aa825d", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n\npublic class restoringPainting {\npublic static void main(String[] args) throws IOException {\n\tBufferedReader bf=new BufferedReader(new InputStreamReader(System.in));\n\tString x=bf.readLine();\n\tString[] y=x.split(\" \");\n\tint n=Integer.parseInt(y[0]);\n\tint a=Integer.parseInt(y[1]);\n\tint b=Integer.parseInt(y[2]);\n\tint c=Integer.parseInt(y[3]);\n\tint d=Integer.parseInt(y[4]);\n\tint z3=1;\n\tint z1=1;\n\tint z2;\n\tint z4;\n\tint z5;\n\tlong counter=0;\n\tint counter2=1;\n\tif(n==1)\n\t{\n\t\tSystem.out.println(1);\n\t\treturn;\n\t}\n\tfor(int i=1;i<=n;i++)\n\t{\n\t\tz1=i;\n\t\tz5=z1+a-d;\n\t\tz2=z1+b-c;\n\t\tz4=b+a+z1-d-c;\n\t\tif((z5>0&&z2>0&&(z4>0))&&(z5<=n&&(z2<=n)&&(z4<=n)))\n\t\t{\n\t\t\tcounter++;\n\t\t}\n\t}\n\tcounter*=n;\n\tSystem.out.println(counter);\n}\n}\n", "lang_cluster": "Java", "tags": ["brute force", "math", "constructive algorithms"], "code_uid": "1a0966f5ca31e985ca8e08187878720f", "src_uid": "b732869015baf3dee5094c51a309e32c", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n \n \npublic class Solution{\n \n ///////////////////////////////////////////////////////////////////////////\n static class FastScanner{\n BufferedReader s;\n StringTokenizer st;\n \n public FastScanner(InputStream InputStream){\n st = new StringTokenizer(\"\");\n s = new BufferedReader(new InputStreamReader(InputStream));\n }\n \n public FastScanner(File f) throws FileNotFoundException{\n st = new StringTokenizer(\"\");\n s = new BufferedReader (new FileReader(f));\n }\n \n public int nextInt() throws IOException{\n if(st.hasMoreTokens())\n return Integer.parseInt(st.nextToken());\n else{\n st = new StringTokenizer(s.readLine());\n return nextInt();\n }\n }\n \n public BigInteger big() throws IOException{\n if(st.hasMoreTokens())\n return new BigInteger(st.nextToken());\n else{\n st = new StringTokenizer(s.readLine());\n return big();\n }\n }\n \n public double nextDouble() throws IOException{\n if(st.hasMoreTokens())\n return Double.parseDouble(st.nextToken());\n else{\n st = new StringTokenizer(s.readLine());\n return nextDouble();\n }\n }\n \n public long nextLong() throws IOException{\n if(st.hasMoreTokens())\n return Long.parseLong(st.nextToken());\n else{\n st = new StringTokenizer(s.readLine());\n return nextLong();\n }\n }\n \n public String nextString() throws IOException{\n if(st.hasMoreTokens())\n return st.nextToken();\n else{\n st = new StringTokenizer(s.readLine());\n return nextString();\n }\n \n }\n public String readLine() throws IOException{\n return s.readLine();\n }\n \n public void close() throws IOException{\n s.close();\n }\n \n }\n \n ////////////////////////////////////////////////////////////////////\n // Number Theory\n \n long pow(long a,long b,long mod){\n long x = 1; long y = a;\n while(b > 0){\n if(b % 2 == 1){\n x = (x*y);\n x %= mod;\n }\n y = (y*y);\n y %= mod;\n b /= 2; \n }\n return x;\n }\n \n int divisor(long x,long[] a){\n long limit = x;\n int numberOfDivisors = 0;\n \n for (int i=1; i < limit; ++i) {\n if (x % i == 0) {\n limit = x / i;\n if (limit != i) {\n numberOfDivisors++;\n }\n numberOfDivisors++;\n }\n }\n return numberOfDivisors;\n }\n \n void findSubsets(int array[]){\n long numOfSubsets = 1 << array.length; \n for(int i = 0; i < numOfSubsets; i++){ \n @SuppressWarnings(\"unused\")\n int pos = array.length - 1;\n int bitmask = i;\n while(bitmask > 0){ \n if((bitmask & 1) == 1)\n// ww.print(array[pos]+\" \");\n bitmask >>= 1;\n pos--;\n }\n// ww.println();\n }\n }\n \n \n public static long gcd(long a, long b){\n return b == 0 ? a : gcd(b,a%b);\n }\n \n \n public static int lcm(int a,int b, int c){\n return lcm(lcm(a,b),c);\n }\n \n public static int lcm(int a, int b){\n return (int) (a*b/gcd(a,b));\n }\n \n public static long invl(long a, long mod) {\n long b = mod;\n long p = 1, q = 0;\n while (b > 0) {\n long c = a / b;\n long d;\n d = a;\n a = b;\n b = d % b;\n d = p;\n p = q;\n q = d - c * q;\n }\n return p < 0 ? p + mod : p;\n }\n \n ////////////////////////////////////////////////////////////////////\n \n \n// FastScanner s = new FastScanner(new File(\"input.txt\"));\n// PrintWriter ww = new PrintWriter(new FileWriter(\"output.txt\"));\n static InputStream inputStream = System.in;\n static FastScanner s = new FastScanner(inputStream); \n static OutputStream outputStream = System.out;\n static PrintWriter ww = new PrintWriter(new OutputStreamWriter(outputStream));\n// private static Scanner s = new Scanner(System.in);\n @SuppressWarnings(\"unused\")\n private static int[][] states = { {-1,0} , {1,0} , {0,-1} , {0,1} };\n \n \n //////////////////////////////////////////////////////////////////// \n \n \n \n public static void main(String[] args) throws IOException{\n new Solution().solve();\n s.close();\n ww.close();\n }\n \n \n ////////////////////////////////////////////////////////////////////\n \n \n void solve() throws IOException{\n \n long a[] = new long [3];\n for (int i = 0; i < 3; i++) \n a[i] = s.nextInt();\n\n \n Arrays.sort(a);\n if(2 * (a[0] + a[1]) <= a[2])\n a[2] = 2 * (a[0] + a[1]);\n\n ww.println((a[0]+a[1]+a[2])/3);\n \n }\n}\n\n\n\n\n\n", "lang_cluster": "Java", "tags": ["greedy"], "code_uid": "359990d6774a5bae23bad011d284f79f", "src_uid": "bae7cbcde19114451b8712d6361d2b01", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\n\npublic class CF509A {\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in); \n\t\tint n = in.nextInt();\n\t\tn = (n - 1) * 2;\n\t\tlong res = 1;\n\t\tfor(int i = 0; i < n / 2; i++) res *= (n/2 + i + 1);\n\t\tfor(int i = 0; i < n / 2; i++) res /= (i + 1);\n\t\tSystem.out.println(res);\n\t}\n}\n", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "a5bcc5475ec675e3e9a1f649b9d6f6ec", "src_uid": "2f650aae9dfeb02533149ced402b60dc", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CrocElB\n{\n public static StringTokenizer st;\n public static void nextLine(BufferedReader br) throws IOException\n {\n st = new StringTokenizer(br.readLine());\n }\n \n public static String next()\n {\n return st.nextToken();\n }\n \n public static int nextInt()\n {\n return Integer.parseInt(st.nextToken());\n }\n \n public static long nextLong()\n {\n return Long.parseLong(st.nextToken());\n }\n \n public static double nextDouble()\n {\n return Double.parseDouble(st.nextToken());\n }\n \n \n public static void main(String[] args) throws IOException\n {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n nextLine(br);\n long n = nextInt();\n long k = nextInt();\n if (k >= n/2)\n {\n long ans = (n * (n-1)) / 2;\n System.out.println(ans);\n return;\n }\n long rem = n;\n long sum = 0;\n for (int i = 0; i < k; i++)\n {\n rem -= 2;\n sum += 2 * rem + 1;\n }\n System.out.println(sum);\n }\n \n}\n", "lang_cluster": "Java", "tags": ["math", "greedy"], "code_uid": "24a25f5d2052015bb918f7b0ab3e5696", "src_uid": "ea36ca0a3c336424d5b7e1b4c56947b0", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.StringTokenizer;\n\n//solution classes here\n\npublic class Code {\n\n //main solution here\n\n static Scanner sc = new Scanner(System.in);\n static PrintWriter out = new PrintWriter(System.out);\n static long mod = 998244353;\n static long MOD = (long)1e9+7;\n //static ArrayList list[] = new ArrayList[(int)1e6+1];\n //static int color[] = new int[(int)1e6+1];\n //static int visit[] = new int[(int)1e5+1];\n //static Deque q = new ArrayDeque<>();\n public static void main(String[] args) throws IOException {\n int n = sc.nextInt();\n if(n%2==0) {\n out.println(\"white\");\n out.print(\"1 2\");\n }\n else {\n out.print(\"black\");\n }\n\n out.flush();\n out.close();\n }\n //solution functions here\n\n static class Scanner {\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(InputStream s) {\n br = new BufferedReader(new InputStreamReader(s));\n }\n\n public Scanner(FileReader fileReader) {\n br = new BufferedReader(fileReader);\n }\n\n public String next() throws IOException {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public String nextLine() throws IOException {\n return br.readLine();\n }\n\n public boolean ready() throws IOException {\n return br.ready();\n }\n }\n}\n\n/* *****************************************************************************************************************************\n * I'M NOT IN DANGER, I'M THE DANGER!!!\n * *****************************************************************************************************************************\n */", "lang_cluster": "Java", "tags": ["math", "constructive algorithms", "games"], "code_uid": "75fb60511428258085bc0ed79c23d7b2", "src_uid": "52e07d176aa1d370788f94ee2e61df93", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class A146 {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint t = sc.nextInt();\n\t\tString s = sc.next();\n\t\tint s1 = 0, s2 = 0;\n\t\tif (luck(s)) {\n\t\t\tfor (int i = 0; i < t / 2; i++)\n\t\t\t\ts1 += Integer.valueOf(String.valueOf(s.charAt(i)));\n\t\t\tfor (int i = t / 2; i < s.length(); i++)\n\t\t\t\ts2 += Integer.valueOf(String.valueOf(s.charAt(i)));\n\t\t\tif (s1 == s2)\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\telse\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t} else\n\t\t\tSystem.out.println(\"NO\");\n\t}\n\n\tpublic static boolean luck(String s) {\n\t\tif (s.contains(\"0\") || s.contains(\"1\") || s.contains(\"2\")\n\t\t\t\t|| s.contains(\"3\") || s.contains(\"5\") || s.contains(\"6\")\n\t\t\t\t|| s.contains(\"8\") || s.contains(\"9\"))\n\t\t\treturn false;\n\t\telse\n\t\t\treturn true;\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "8f5c9a744e005cfd959c800bbe33c781", "src_uid": "435b6d48f99d90caab828049a2c9e2a7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n \n/**\n *\n * @author Lenovo\n */\npublic class JavaApplication2 {\n \n \n \n public static void main(String[] args) {\n \n Scanner in = new Scanner(System.in);\n String ar[]=new String[4];\n for(int i=0;i<4;i++){ar[i]=in.next();}\n int y=0;int z=0;boolean fi=false;\n int s=0;\n for(int i=0;i<3;i++){y=0;\n for(int u=0;u<3;u++){y=0;z=0;\n if(ar[i].charAt(u)=='#'){y++;}\n else if(ar[i].charAt(u)=='.') z++; \n if(ar[i+1].charAt(u)=='#'){y++;} \n else if(ar[i+1].charAt(u)=='.') z++; \n if(ar[i].charAt(u+1)=='#'){y++;}\n else if(ar[i].charAt(u+1)=='.') z++; \n if(ar[i+1].charAt(u+1)=='#'){y++;} \n else if(ar[i+1].charAt(u+1)=='.') z++;\n if((y==3||y==4)||(z==3||z==4)){fi=true;break;}\n \n \n \n \n }\n if(fi==true)break;\n }\n if(fi==true){System.out.println(\"YES\");}\n else {System.out.println(\"NO\");}\n \n \n }\n \n \n }", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "fdb5409a251f49b1f00cc7d9ad075268", "src_uid": "01b145e798bbdf0ca2ecc383676d79f3", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Artem Gilmudinov\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n Reader in = new Reader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskA solver = new TaskA();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskA {\n public void solve(int testNumber, Reader in, PrintWriter out) {\n int n = in.ni();\n PairInt[] points = new PairInt[n];\n for (int i = 0; i < n; i++) {\n points[i] = new PairInt(in.ni(), in.ni());\n }\n if (n == 1) {\n out.println(-1);\n } else if (n == 2) {\n if (points[0].x == points[1].x || points[0].y == points[1].y) {\n out.println(-1);\n } else {\n int diffX = Math.abs(points[0].x - points[1].x);\n int diffY = Math.abs(points[0].y - points[1].y);\n out.println(diffX * diffY);\n }\n } else {\n for (int i = 0; i < n; i++) {\n for (int j = i + 1; j < n; j++) {\n if (points[i].x != points[j].x && points[i].y != points[j].y) {\n int diffX = Math.abs(points[j].x - points[i].x);\n int diffY = Math.abs(points[j].y - points[i].y);\n out.println(diffX * diffY);\n return;\n }\n }\n }\n }\n }\n\n }\n\n static class Reader {\n private BufferedReader in;\n private StringTokenizer st = new StringTokenizer(\"\");\n private String delim = \" \";\n\n public Reader(InputStream in) {\n this.in = new BufferedReader(new InputStreamReader(in));\n }\n\n public String next() {\n if (!st.hasMoreTokens()) {\n st = new StringTokenizer(rl());\n }\n return st.nextToken(delim);\n }\n\n public String rl() {\n try {\n return in.readLine();\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n\n public int ni() {\n return Integer.parseInt(next());\n }\n\n }\n\n static class PairInt {\n public int x;\n public int y;\n\n public PairInt(int x, int y) {\n this.x = x;\n this.y = y;\n }\n\n\n public boolean equals(Object obj) {\n PairInt pairInt = (PairInt) obj;\n return pairInt.x == x && pairInt.y == y;\n }\n\n public String toString() {\n return x + \" \" + y;\n }\n\n public PairInt clone() {\n return new PairInt(x, y);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["geometry", "implementation"], "code_uid": "67f76968310a48dc12bb088266412868", "src_uid": "ba49b6c001bb472635f14ec62233210e", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class fillingShapesA{\n public static void main(String[] args) {\n Scanner sc= new Scanner(System.in);\n int n = sc.nextInt();\n sc.close();\n if(n<2 || n%2==1){\n System.out.println(0);\n }\n else{\n System.out.println((int)Math.sqrt(Math.pow(2, n)));\n }\n }\n}", "lang_cluster": "Java", "tags": ["math", "dp"], "code_uid": "38e5f5ff66e56cbc0db05b84a68d3886", "src_uid": "4b7ff467ed5907e32fd529fb39b708db", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\n/*CODE BY SHIKHAR TYAGI*/\n\npublic class B {\n\n public static final int MOD = 1000000007;\n\n public static void main(String args[]) {\n FastScanner scn = new FastScanner();\n int t = 1;\n while (t-- > 0) {\n long n = scn.nextInt();\n long m = scn.nextInt();\n long ans = (((power((long)2, m, MOD) % MOD) - (1 % MOD)) + MOD) % MOD;\n ans = power(ans, n, MOD)%MOD;\n System.out.println(ans);\n }\n }\n\n static long power(long x, long y, int p) {\n\n // Initialize result\n long res = 1;\n\n // Update x if it is more than or\n // equal to p\n x = x % p;\n\n while (y > 0) {\n\n // If y is odd, multiply x\n // with result\n if (y % 2 == 1)\n res = (res * x) % p;\n\n // y must be even now\n y = y / 2; // y = y/2\n x = (x * x) % p;\n }\n\n return res;\n }\n\n\n static int exponentMod(int A, int B, int C) {\n\n // Base cases\n if (A == 0)\n return 0;\n if (B == 0)\n return 1;\n\n // If B is even\n long y;\n if (B % 2 == 0) {\n y = exponentMod(A, B / 2, C);\n y = (y * y) % C;\n }\n\n // If B is odd\n else {\n y = A % C;\n y = (y * exponentMod(A, B - 1, C) % C) % C;\n }\n\n return (int) ((y + C) % C);\n }\n\n public static class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(String s) {\n try {\n br = new BufferedReader(new FileReader(s));\n } catch (FileNotFoundException e) {\n // TODO Auto-generated catch block\n e.printStackTrace();\n }\n }\n\n public FastScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String nextToken() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n // TODO Auto-generated catch block\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n\n public static int bin(int b[], long target) {\n int l = 0;\n int h = b.length - 1;\n int pos = -1;\n while (l <= h) {\n int m = l + (h - l) / 2;\n if (b[m] <= target) {\n if (b[m] == target) {\n return m;\n }\n l = m + 1;\n } else {\n pos = m;\n h = m - 1;\n }\n }\n return pos;\n }\n}", "lang_cluster": "Java", "tags": ["math", "combinatorics"], "code_uid": "45987f0ba23bc1d7d2f3d0efbd2bcc48", "src_uid": "71029e5bf085b0f5f39d1835eb801891", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\npublic class Codeforces{\n BufferedReader br =new BufferedReader(new InputStreamReader(System.in)); \n PrintWriter out =new PrintWriter(System.out);\n StringTokenizer st =new StringTokenizer(\"\");\n String next(){\n if(!st.hasMoreTokens()){\n try{\n st=new StringTokenizer(br.readLine());\n }\n catch(Exception e){\n\n }\n }\n return st.nextToken();\n }\n int nextInt(){\n return Integer.parseInt(next());\n }\n public static void main(String[] args) {\n new Codeforces().solve();\n }\n void solve(){\n List> arr=new ArrayList<>();\n for(int i=0;i<=5;i++) arr.add(new ArrayList<>());\n int m=nextInt();\n for(int i=0;i=3){\n flag=true;\n }\n }\n if(flag){\n out.println(\"WIN\");\n }\n else{\n out.println(\"FAIL\");\n }\n out.close();\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation", "graphs"], "code_uid": "3494015db1171b164ddee62df6740b1a", "src_uid": "2bc18799c85ecaba87564a86a94e0322", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.*;\n\npublic class cfinf {\n \n static boolean testFing(int a,int b)\n {\n return (b>=(a-1) && b<=2*(a+1));\n }\n \n public static void main(String[] argc)\n {\n Scanner in = new Scanner(System.in);\n int[] a = new int[2];\n int[] b = new int[2];\n for(int i=0;i<2;i++)\n a[i] = in.nextInt();\n for(int i=0;i<2;i++)\n b[i] = in.nextInt();\n if (testFing(a[0],b[1]) || testFing(a[1],b[0]))\n System.out.print(\"YES\");\n else\n System.out.print(\"NO\");\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "greedy"], "code_uid": "678758a7b93aba9848bb18693facfece", "src_uid": "36b7478e162be6e985613b2dad0974dd", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n \n public static void main(String[] args) throws IOException {\n \n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n String[] nm = br.readLine().split(\" \");\n int n = Integer.parseInt(nm[0]);\n int m = Integer.parseInt(nm[1]);\n \n PriorityQueue pq = new PriorityQueue(1, Perm.cmp);\n List el = new ArrayList();\n for (int i = 1; i <= n; i++) el.add(i);\n getPerm(el, new ArrayList(), pq);\n //System.out.println(pq.size());\n Perm mth = new Perm(el);\n for (int i = 0; i < m; i++) {\n mth = pq.poll();\n }\n \n System.out.println(mth);// + \" \" + mth.f);\n \n }\n \n private static void getPerm(List el, \n List cp, \n PriorityQueue pq) {\n if (el.size() == 0) {\n Perm p = new Perm(cp);\n pq.add(p);\n return;\n }\n \n for (int i = 0; i < el.size(); i++) {\n List clone = new ArrayList(el);\n int e = clone.get(i);\n clone.remove(i);\n cp.add(e);\n getPerm(clone, cp, pq);\n cp.remove(cp.size() - 1);\n }\n \n return;\n \n }\n \n private static class Perm {\n \n List a;\n int f;\n \n public static Comparator cmp = new Comparator() {\n public int compare(Perm p1, Perm p2) {\n int f1 = p1.f;\n int f2 = p2.f;\n if (f1 > f2) return -1;\n if (f2 > f1) return 1;\n \n List a1 = p1.a;\n List a2 = p2.a;\n \n for (int i = 0; i < a1.size(); i++) {\n int e1 = a1.get(i);\n int e2 = a2.get(i);\n if (e1 < e2) return -1;\n if (e2 < e1) return 1;\n }\n return 0;\n }\n };\n \n public Perm(List perm) {\n a = new ArrayList(perm);\n \n for (int i = 0; i < a.size(); i++) {\n for (int j = i; j < a.size(); j++) {\n int min = Integer.MAX_VALUE;\n for (int k = i; k <= j; k++) {\n int curr = a.get(k);\n if (curr < min) min = curr;\n }\n f += min;\n }\n }\n }\n @Override\n public String toString() {\n StringBuilder sb = new StringBuilder();\n for (int i = 0; i < a.size(); i++) {\n sb.append(a.get(i));\n if (i != a.size() - 1) sb.append(\" \");\n }\n sb.append(System.getProperty(\"line.separator\"));\n return sb.toString();\n }\n }\n}", "lang_cluster": "Java", "tags": ["brute force"], "code_uid": "7f492324e5cc3ecaf2f9ca03dfbfc3d6", "src_uid": "a8da7cbd9ddaec8e0468c6cce884e7a2", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "//package hiougyf;\nimport java.io.*;\nimport java.util.*;\nimport java.util.Map.Entry;\n\npublic class Solution {\t\n\tpublic static void main(String[] args){ \n\t\tScanner sc =new Scanner(System.in);\n\t\t\n\t\t//String ans=\"10\";\n\t\tint n=sc.nextInt();\n\tint j=0,ans=0;\n\tfor(int i=1;i<100000000;i++) {\n\t\tint m=i;\n\t\tif(n==0) {\n\t\t\tSystem.out.println(i-1);\n\t\t\tbreak;\n\t\t}\n\t\tj=0;\n\t\t\t\twhile(m>0) {\n\t\t\t\t\tint k=m%10;\n\t\t\t\t\tm/=10;\n\t\t\t\t\tj+=k;\n\t\t\t\t}\n\t\t\t\tif(j==10) n--;\n\t\t}\n\t}\n\t public static int floorSqrt(int x) \n\t { \n\t // Base Cases \n\t if (x == 0 || x == 1) \n\t return x; \n\t \n\t // Do Binary Search for floor(sqrt(x)) \n\t int start = 1, end = x, ans=0; \n\t while (start <= end) \n\t { \n\t int mid = (start + end) / 2; \n\t \n\t // If x is a perfect square \n\t if (mid*mid == x) \n\t return mid; \n\t \n\t // Since we need floor, we update answer when mid*mid is \n\t // smaller than x, and move closer to sqrt(x) \n\t if (mid*mid < x) \n\t { \n\t start = mid + 1; \n\t ans = mid; \n\t } \n\t else // If mid*mid is greater than x \n\t end = mid-1; \n\t } \n\t return ans; \n\t } \n\t\tstatic int div(int n,int b) {\n\t\t\tint g=-1;\n\t\t\tfor(int i=2;i<=Math.sqrt(n);i++) {\n\t\t\t\tif(n%i==0&&i!=b) {\n\t\t\t\t\tg=i;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn g;\n\t\t}\n\t \n\t \n\t public static int gcd(int a, int b) \n\t { \n\t if (a == 0) \n\t return b; \n\t \n\t return gcd(b%a, a); \n\t } \n\t public static int lcm(int a, int b) \n\t { \n\t return (a*b)/gcd(a, b); \n\t } \n\t public static boolean isPrime1(int n) {\n if (n <= 1) {\n return false;\n }\n if (n == 2) {\n return true;\n }\n for (int i = 2; i <= Math.sqrt(n) + 1; i++) {\n if (n % i == 0) {\n return false;\n }\n }\n return true;\n }\n public static boolean isPrime(int n) {\n if (n <= 1) {\n return false;\n }\n if (n == 2) {\n return true;\n }\n if (n % 2 == 0) {\n return false;\n }\n for (int i = 3; i <= Math.sqrt(n) + 1; i = i + 2) {\n if (n % i == 0) {\n return false;\n }\n }\n return true;\n }\n\t \n\t\n}", "lang_cluster": "Java", "tags": ["brute force", "dp", "binary search", "implementation", "number theory"], "code_uid": "a3f1bf329f9da5beea747b67ae17182d", "src_uid": "0a98a6a15e553ce11cb468d3330fc86a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n/**\n * Created by Peter on 13.04.2016.\n */\npublic class TaskA {\n int n, b, p;\n TaskA(Scanner sc) {\n n = sc.nextInt();\n b = sc.nextInt();\n p = sc.nextInt();\n\n\n }\n private int getGamePlayed() {\n int nn = n;\n int ans = 0;\n while (nn > 1 ) {\n int k = 1;\n while (k*2 <= nn) {\n k *= 2;\n }\n ans += k/2;\n nn = nn - k/2;\n\n }\n return ans;\n }\n\n private void solve(){\n int totalP = p * n;\n int gamePlayed = getGamePlayed();\n int totalB = gamePlayed * (2 * b + 1);\n System.out.printf(\"%d %d\", totalB, totalP);\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n new TaskA(sc).solve();\n sc.close();\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "c52c5f5643b990c37898f22f7eedeaab", "src_uid": "eb815f35e9f29793a120d120968cfe34", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": " import java.io.*;\nimport java.math.RoundingMode;\nimport java.util.*;\n public class cf450A {\n static PrintWriter out;\n public static void main(String[] args) throws IOException {\n MyScanner sc = new MyScanner();\n out = new PrintWriter(new BufferedOutputStream(System.out));\n int n = sc.nextInt(), m = sc.nextInt(), idx = 0, tempVal = 0;\n for(int i = 0; i < n; i ++){\n double val = sc.nextDouble();\n int current = (int)Math.ceil((val/(double)m)-(int)(val/m))+(int)(val/m);\n if(current>=tempVal){\n tempVal = current;\n idx = i+1;\n }\n }\n out.println(idx);\n out.close();\n }\n static class MyScanner {\n BufferedReader br;\n StringTokenizer st;\n public MyScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n int nextInt() {\n return Integer.parseInt(next());\n }\n long nextLong() {\n return Long.parseLong(next());\n }\n double nextDouble() {\n return Double.parseDouble(next());\n }\n String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n }\n }", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "41e243ac7ef9ed98961e81ea6256e891", "src_uid": "c0ef1e4d7df360c5c1e52bc6f16ca87c", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class hexa\n{\n \n public static void main(String args[])\n {\n Scanner scan=new Scanner(System.in);\n \n int n=scan.nextInt();\n long pre[]=new long[1024];\n for(int j=0;j<1024;j++)\n pre[j]=Long.parseLong(Integer.toBinaryString(j));\n int g=0;\n for(g=0;g<1024;g++)\n {\n if(pre[g]>n)\n break;\n \n }\n System.out.print(g-1);\n \n \n \n }\n}", "lang_cluster": "Java", "tags": ["brute force", "math", "implementation"], "code_uid": "69e7d6432c97a89f95b39ad5d96eeb6a", "src_uid": "64a842f9a41f85a83b7d65bfbe21b6cb", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "//package main;\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.List;\n\npublic class Main {\n\t\t\n\tstatic List primeGenerator(int max) {\n\t\tboolean[] isNotPrime = new boolean[max];\n\t\t\n\t\tfor(int i = 2; i < max; i++) {\n\t\t\tif(isNotPrime[i]) continue;\n\n\t\t\tisNotPrime[i] = false;\n\t\t\tfor(int j = i + i; j < max; j += i) {\t\t\t\t\n\t\t\t\tisNotPrime[j] = true;\n\t\t\t}\t\t\t\n\t\t}\n\t\t\n\t\tList list = new ArrayList();\n\t\t\n\t\tfor(int i = 2; i < max; i++) {\n\t\t\tif(!isNotPrime[i]) list.add(i);\n\t\t}\n\t\t\n\t\treturn list;\n\t}\n\t\n\tstatic List getPrimeFactors(long n) {\n\t\tList primes = primeGenerator(1000001);\n\n\t\tList primeFactors = new ArrayList<>();\n\t\t\n\t\tint index = 0;\n\t\twhile(n > 1 && index < primes.size()) {\n\t\t\tint prime = primes.get(index);\n\t\t\tint pow = 0;\n\t\t\twhile(n % prime == 0) {\n\t\t\t\tn /= prime;\n\t\t\t\tpow++;\n\t\t\t}\n\t\t\tindex++;\n\t\t\tif(pow > 0)\n\t\t\t\tprimeFactors.add((long)Math.pow(prime, pow));\t\t\t\n\t\t}\n\t\tif(n > 1)\n\t\t\tif(isPrime((int)n)) primeFactors.add(n);\n\t\t\telse System.exit(31);\n\t\t\n\t\treturn primeFactors;\n\t\t\n\t}\n\t\n\tstatic class Pair {\n\t\tlong value;\n\t\tint index;\n\t\tPair(long value, int index) {\n\t\t\tthis.value = value;\n\t\t\tthis.index = index;\n\t\t}\t\t\n\t}\n\t\n\tstatic boolean isPrime(int n) {\n\t\tif(n % 2 == 0) return false;\n\t\t\n\t\tint sqrt = (int)Math.sqrt(n);\n\t\t\n\t\tfor(int i = 3; i <= sqrt; i += 2) {\n\t\t\tif(n % i == 0) return false;\n\t\t}\n\t\t\n\t\treturn true;\n\t}\n\t\t\t\n\tpublic static void main(String[] args) throws Exception {\n\t\t\n\t\tBufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\t\t\n\t\tString[] data = reader.readLine().split(\"\\\\s+\");\n\t\treader.close();\t\t\n\t\t\n\t\tlong l = Integer.parseInt(data[0]);\n\t\tlong r = Integer.parseInt(data[1]);\n\t\tlong x = Integer.parseInt(data[2]);\n\t\tlong y = Integer.parseInt(data[3]);\n\t\t\n\t\tif((y % x) != 0) {\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tif(x == y) {\n\t\t\tif(x < l || y > r) System.out.println(0);\n\t\t\telse System.out.println(1);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tlong part = y / x;\n\t\t\n\t\tList primeFactors = getPrimeFactors(part);\n\t\t\n\t\tList temp1 = new ArrayList<>();\n\t\t\n\t\tint ans = 0;\n\t\t\n\t\tfor(int i = 0; i < primeFactors.size(); i++) {\n\t\t\tlong val = primeFactors.get(i);\n\t\t\tlong f1 = x * (val); \n\t\t\tlong f2 = x * (part / val);\n\t\t\t\n\t\t\tif(Math.min(f1, f2) >= l && Math.max(f1, f2) <= r) ans++;\n\t\t\t\n\t\t\ttemp1.add(new Pair(val, i+1));\n\n\t\t}\n\t\t\n\t\tList temp2 = new ArrayList<>();\t\t\n\t\twhile(!temp1.isEmpty()) {\n\t\t\ttemp2.clear();\n\t\t\tfor(Pair p: temp1) {\t\t\t\t\n\t\t\t\tfor(int i = p.index; i < primeFactors.size(); i++) {\n\t\t\t\t\tlong val = p.value * primeFactors.get(i);\n\t\t\t\t\tlong f1 = x * (val); \n\t\t\t\t\tlong f2 = x * (part / val);\n\t\t\t\t\t\n\t\t\t\t\tif(Math.min(f1, f2) >= l && Math.max(f1, f2) <= r) ans++;\n\t\t\t\t\t\n\t\t\t\t\ttemp2.add(new Pair(val, i + 1));\t\t\t\t\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tList temp = temp1; \n\t\t\ttemp1 = temp2;\n\t\t\ttemp2 = temp;\t\t\t\n\t\t}\n\t\t\n\t\tif(x >= l && y <= r) ans++;\n\t\t\n\t\tSystem.out.println(ans);\t\t\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "number theory"], "code_uid": "52c56df11a4b0ac774e562db9dad8b0d", "src_uid": "d37dde5841116352c9b37538631d0b15", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "\nimport java.util.HashMap;\nimport java.util.Scanner;\n\npublic class mg3 {\n public static void main(String args[]){\n\t int score =0;\n\t String[] arrayS = {\"zero\",\"one\",\"two\",\"three\",\"four\",\"five\",\"six\",\"seven\",\"eight\",\"nine\",\"ten\",\"eleven\",\"twelve\",\"thirteen\",\"fourteen\",\"fifteen\",\"sixteen\",\"seventeen\",\"eighteen\",\n\t\t\t \"nineteen\",\"twenty\",\"thirty\",\"forty\",\"fifty\",\"sixty\",\"seventy\",\"eighty\",\"ninety\"}; \n\t HashMap array = new HashMap();\n\t for(int i =0; i<=19;i++){\n\t\t array.put(i, arrayS[i]);\n\t }\n\t for(int j = 2;j<=9;j++){\n\t\t array.put(10*j, arrayS[18+j]);\n\t }\n\t Scanner in = new Scanner(System.in);\n\t score = Integer.parseInt(in.nextLine());\n\t StringBuilder s= new StringBuilder();\n\t if(score<=20||score%10==0){\n\t\t s.append(array.get(score));\n\t }\n\t else {\n\t\t int item = score%10;\n\t\t score = score/10;\n\t\t s.append(array.get(score*10)+\"-\");\n\t\t s.append(array.get(item));\n\t }\n\t System.out.println(s.toString());\n\t \n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "c203397c098d4adc78ea5523bcc72810", "src_uid": "a49ca177b2f1f9d5341462a38a25d8b7", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\r\nimport java.io.*;\r\npublic class Main{\r\n public static String threedoors(int k,int arr[],int door,int total){\r\n if(k==0&&total<3)return \"NO\";\r\n if(total>=3)return \"YES\";\r\n k=arr[k-1];\r\n return threedoors(k,arr,k,total+1);\r\n }\r\n \r\n public static void main(String[] args){\r\n Scanner sc=new Scanner(System.in);\r\n int n=sc.nextInt();\r\n while(n-->0){\r\n int k=sc.nextInt();\r\n int arr[]=new int[3];\r\n int i=0;\r\n while(i<3){\r\n arr[i]=sc.nextInt();\r\n i++;\r\n }\r\n System.out.println(threedoors(k,arr,k,0));\r\n }\r\n }\r\n}", "lang_cluster": "Java", "tags": ["brute force", "greedy", "implementation", "math"], "code_uid": "7d02afbd66590d36e5f960f6a6f0a606", "src_uid": "5cd113a30bbbb93d8620a483d4da0349", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Task {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskA s=new TaskA();\n s.solve(in, out);\n out.close();\n }\n}\n\nclass TaskA {\n public void solve(InputReader in, PrintWriter out){\n int k=in.nextInt();\n String[] ss=new String[4];\n for(int i=0;i<4;i++){\n ss[i]=in.next();\n }\n \n int[] a=new int[9];\n for(int i=0;i<9;i++)\n a[i]=0;\n \n for(int i=0;i<4;i++){\n for(int j=0;j<4;j++){\n if(ss[i].charAt(j)!='.')\n a[ss[i].charAt(j)-'1']++;\n }\n }\n \n boolean flag=true;\n for(int i=0;i<9;i++){\n if(a[i]>k*2){\n flag=false;\n break;\n }\n }\n \n if(flag){\n out.println(\"YES\");\n }else{\n out.println(\"NO\");\n }\n }\n}\n\nclass InputReader {\n private BufferedReader reader;\n private StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "22f699095c213254303e543d5e55864b", "src_uid": "5fdaf8ee7763cb5815f49c0c38398f16", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\n\npublic class MidnightOil {\n\n public static int n, ko;\n \n public static void main(String[] args){\n Scanner input = new Scanner(System.in);\n n = input.nextInt();\n ko = input.nextInt();\n System.out.println(search(1, 1_000_000_000));\n input.close();\n }\n \n public static long search(long min, long max){\n long mid = (max - min) / 2 + min;\n long lines = lines(mid);\n \n if(min == max)\n return mid;\n if(min > max)\n return Long.MAX_VALUE;\n \n if(lines < n)\n return search(mid + 1, max);\n return Math.min(mid, search(min, mid));\n }\n \n public static long lines(long v){\n long ret = 0,\n k = 1;\n while(k <= v){\n ret += v / k;\n k *= ko;\n }\n return ret;\n }\n \n}\n", "lang_cluster": "Java", "tags": ["implementation", "binary search"], "code_uid": "e60d442ff547c84d7e0760514f748b8a", "src_uid": "41dfc86d341082dd96e089ac5433dc04", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.HashMap;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.util.StringTokenizer;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskA solver = new TaskA();\n solver.solve(1, in, out);\n out.close();\n }\n}\n\nclass TaskA {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n HashMap m = new HashMap();\n String str = in.next();\n int n = str.length();\n int ans = 0;\n for (int i = 0; i < n; i++) {\n for (int j = i + 1; j <= n; j++) {\n String s = str.substring(i, j);\n int len = s.length();\n if (m.containsKey(s)) {\n ans = Math.max(ans, m.get(s));\n } else {\n m.put(s, len);\n }\n }\n }\n out.println(ans);\n }\n}\n\nclass InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n\n}\n", "lang_cluster": "Java", "tags": ["brute force", "greedy"], "code_uid": "0612212168090bdde236bcf9087d7c94", "src_uid": "13b5cf94f2fabd053375a5ccf3fd44c7", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main{\n public static void main(String[] args) {\n //int test;\n Scanner sc=new Scanner(System.in);\n //test=sc.nextInt();\n // while (test-->0){\n int a,b,c,d;\n a=sc.nextInt();\n b=sc.nextInt();\n c=sc.nextInt();\n d=sc.nextInt();\n long pre[]=new long[10000003];\n for(int i=a;i<=b;i++){\n pre[i+b]++;\n pre[i+c+1]--;\n }\n for(int i=1;i<=10000002;i++){\n pre[i]=pre[i-1]+pre[i];\n }\n for(int i=10000002;i>=1;i--){\n pre[i-1]+=pre[i];\n }\n long ans=0;\n for(int i=c;i<=d;i++){\n ans+=pre[i+1];\n }\n System.out.println(ans);\n\n\n // }\n }\n}", "lang_cluster": "Java", "tags": ["two pointers", "math", "implementation", "binary search"], "code_uid": "7bc6a08f83bd4dd3cefea67c7ed78a09", "src_uid": "4f92791b9ec658829f667fcea1faee01", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.util.Map.Entry;\nimport java.io.*;\nimport java.awt.Point;\nimport java.math.BigInteger;\n\nimport static java.lang.Math.*;\n\npublic class CodeforcesC implements Runnable {\n\n final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\n BufferedReader in;\n PrintWriter out;\n StringTokenizer tok = new StringTokenizer(\"\");\n\n void init() throws FileNotFoundException {\n if (ONLINE_JUDGE) {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n } else {\n in = new BufferedReader(new FileReader(\"input.txt\"));\n out = new PrintWriter(\"output.txt\");\n }\n }\n\n String readString() throws IOException {\n while (!tok.hasMoreTokens()) {\n try {\n tok = new StringTokenizer(in.readLine());\n } catch (Exception e) {\n return null;\n }\n }\n return tok.nextToken();\n }\n\n int readInt() throws IOException {\n return Integer.parseInt(readString());\n }\n\n long readLong() throws IOException {\n return Long.parseLong(readString());\n }\n\n double readDouble() throws IOException {\n return Double.parseDouble(readString());\n }\n\n public static void main(String[] args) {\n new Thread(null, new CodeforcesC(), \"\", 128 * (1L << 20)).start();\n }\n\n long timeBegin, timeEnd;\n\n void time() {\n timeEnd = System.currentTimeMillis();\n System.err.println(\"Time = \" + (timeEnd - timeBegin));\n }\n\n long memoryTotal, memoryFree;\n\n void memory() {\n memoryFree = Runtime.getRuntime().freeMemory();\n System.err.println(\"Memory = \" + ((memoryTotal - memoryFree) >> 10)\n + \" KB\");\n }\n\n void debug(Object... objects) {\n if (DEBUG) {\n for (Object o : objects) {\n System.err.println(o.toString());\n }\n }\n }\n\n int[] readIntArray(int n) throws IOException {\n int[] array = new int[n];\n for (int i = 0; i < n; i++)\n array[i] = readInt();\n return array;\n }\n\n public void run() {\n try {\n timeBegin = System.currentTimeMillis();\n memoryTotal = Runtime.getRuntime().freeMemory();\n init();\n solve();\n out.close();\n time();\n memory();\n } catch (Exception e) {\n e.printStackTrace(System.err);\n System.exit(-1);\n }\n }\n\n boolean DEBUG = false;\n\n void solve() throws IOException {\n\n int l = readInt();\n int r = readInt();\n\n int n = 9;\n int[] ten = new int[n + 1];\n\n ten[0] = 1;\n\n for (int i = 1; i <= n; i++)\n ten[i] = 10 * ten[i - 1];\n\n long answer = 0;\n\n List luckyNumbers = new ArrayList();\n \n for (int length = 1; length <= n; length++) {\n for (int cur = 0; cur < (1 << length); cur++) {\n int value = 0;\n for (int j = 0; j < length; j++) {\n if (((1 << j) & cur) == (1 << j))\n value += ten[j] * 7;\n else\n value += ten[j] * 4;\n }\n //out.println(value);\n luckyNumbers.add(1l * value);\n }\n }\n \n luckyNumbers.add(4444444444l);\n \n long lastNumber = l;\n \n for (long luckyNumber : luckyNumbers) {\n if (luckyNumber > r) {\n answer += 1l * (r - lastNumber + 1) * luckyNumber;\n break;\n }\n if (luckyNumber >= l) {\n answer += 1l * (luckyNumber - lastNumber + 1) * luckyNumber;\n lastNumber = luckyNumber + 1;\n }\n }\n \n out.println(answer);\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "math"], "code_uid": "99d52e6a3dcde50234757f8ff4640e6b", "src_uid": "8a45fe8956d3ac9d501f4a13b55638dd", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.util.InputMismatchException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskC solver = new TaskC();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskC {\n\n final int lim = 40000;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n\n int c = in.nextInt(), hr = in.nextInt(), hb = in.nextInt();\n int wr = in.nextInt(), wb = in.nextInt();\n\n long ans = 0;\n if (wr >= lim) ans = solve1(c, wr, hr, wb, hb);\n else if (wb >= lim) ans = solve1(c, wb, hb, wr, hr);\n else if ((long) hr * wb < (long) hb * wr) ans = solve2(c, wr, hr, wb, hb);\n else ans = solve2(c, wb, hb, wr, hr);\n\n out.println(ans);\n }\n\n private long solve2(int c, int wr, int hr, int wb, int hb) {\n long ans = 0;\n for (int i = 0; i <= lim && (long) i * wr <= c; ++i)\n ans = Math.max(ans, (long) i * hr + (long) ((c - i * wr) / wb) * hb);\n return ans;\n }\n\n private long solve1(int c, int wr, int hr, int wb, int hb) {\n long ans = 0;\n for (int i = 0; (long) i * wr <= c; ++i)\n ans = Math.max(ans, (long) i * hr + (long) ((c - i * wr) / wb) * hb);\n return ans;\n }\n}\n\nclass InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1)\n throw new UnknownError();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new UnknownError();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public String next() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuffer res = new StringBuffer();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n\n return res.toString();\n }\n\n private boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n}\n\n", "lang_cluster": "Java", "tags": ["math", "greedy", "brute force"], "code_uid": "0f98fd0c673d72d15323db1cbda33114", "src_uid": "eb052ca12ca293479992680581452399", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "//package CodeForces.Round677Div3;\n\nimport java.io.*;import java.util.*;import java.math.*;\npublic class A\n{\n static long mod=1000000007l;\n static int max=Integer.MAX_VALUE,min=Integer.MIN_VALUE;\n static long maxl=Long.MAX_VALUE,minl=Long.MIN_VALUE;\n static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n static StringTokenizer st;\n static StringBuilder sb;\n\n static public void main(String[] args)throws Exception\n {\n st=new StringTokenizer(br.readLine());\n int t=i();\n sb=new StringBuilder(1000000);\n\n while(t-->0) {\n String s = s() ;\n int ans = 0 ;\n Character ch = s.charAt(0) ;\n int n = s.length() ;\n if(ch=='1'){\n ans+=0 ;\n } else if (ch == '2') {\n ans+=10 ;\n }\n else if (ch == '3') {\n ans+=20 ;\n }\n else if (ch == '4') {\n ans+=30 ;\n }\n else if (ch == '5') {\n ans+=40 ;\n }\n else if (ch == '6') {\n ans+=50 ;\n }\n else if (ch == '7') {\n ans+=60 ;\n }\n else if (ch == '8') {\n ans+=70 ;\n }\n else if (ch == '9') {\n ans+=80 ;\n }\n ans+= (n*(n+1))/2 ;\n sl(ans) ;\n }\n p(sb) ;\n }\n\n static void s(String s){sb.append(s);}\n static void s(int s){sb.append(s);}\n static void s(long s){sb.append(s);}\n static void s(char s){sb.append(s);}\n static void s(double s){sb.append(s);}\n static void ss(){sb.append(' ');}\n static void sl(String s){sb.append(s);sb.append(\"\\n\");}\n static void sl(int s){sb.append(s);sb.append(\"\\n\");}\n static void sl(long s){sb.append(s);sb.append(\"\\n\");}\n static void sl(char s){sb.append(s);sb.append(\"\\n\");}\n static void sl(double s){sb.append(s);sb.append(\"\\n\");}\n static void sl(){sb.append(\"\\n\");}\n static int max(int a,int b){return a>b?a:b;}\n static int min(int a,int b){return ab?a:b;}\n static long min(long a,long b){return a0)\n {\n if((b&1)==1)r=(r*a)%m;\n b>>=1;\n a=(a*a)%m;\n }\n return r;\n }\n static int i()throws IOException\n {\n if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());\n return Integer.parseInt(st.nextToken());\n }\n static long l()throws IOException\n {\n if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());\n return Long.parseLong(st.nextToken());\n }\n static String s()throws IOException\n {\n if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n static double d()throws IOException\n {\n if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());\n return Double.parseDouble(st.nextToken());\n }\n static void p(Object p){System.out.print(p);}\n static void p(String p){System.out.print(p);}\n static void p(int p){System.out.print(p);}\n static void p(double p){System.out.print(p);}\n static void p(long p){System.out.print(p);}\n static void p(char p){System.out.print(p);}\n static void p(boolean p){System.out.print(p);}\n static void pl(Object p){System.out.println(p);}\n static void pl(String p){System.out.println(p);}\n static void pl(int p){System.out.println(p);}\n static void pl(char p){System.out.println(p);}\n static void pl(double p){System.out.println(p);}\n static void pl(long p){System.out.println(p);}\n static void pl(boolean p){System.out.println(p);}\n static void pl(){System.out.println();}\n static int[] ari(int n)throws IOException\n {\n int ar[]=new int[n];\n if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());\n for(int x=0;x=total)\n {\n index=0;\n total=in.read(buf);\n if(total<=0)\n return -1;\n }\n return buf[index++];\n }\n public int scanInt()throws IOException\n {\n int integer=0;\n int n=scan();\n while(isWhiteSpace(n))\n n=scan();\n int neg=1;\n if(n=='-')\n {\n neg=-1;\n n=scan();\n }\n while(!isWhiteSpace(n))\n {\n if(n>='0'&&n<='9')\n {\n integer*=10;\n integer+=n-'0';\n n=scan();\n }\n else throw new InputMismatchException();\n }\n return neg*integer;\n }\n public double scanDouble()throws IOException\n {\n double doub=0;\n int n=scan();\n while(isWhiteSpace(n))\n n=scan();\n int neg=1;\n if(n=='-')\n {\n neg=-1;\n n=scan();\n }\n while(!isWhiteSpace(n)&&n!='.')\n {\n if(n>='0'&&n<='9')\n {\n doub*=10;\n doub+=n-'0';\n n=scan();\n }\n else throw new InputMismatchException();\n }\n if(n=='.')\n {\n n=scan();\n double temp=1;\n while(!isWhiteSpace(n))\n {\n if(n>='0'&&n<='9')\n {\n temp/=10;\n doub+=(n-'0')*temp;\n n=scan();\n }\n else throw new InputMismatchException();\n }\n }\n return doub*neg;\n }\n public String scanString()throws IOException\n {\n StringBuilder sb=new StringBuilder();\n int n=scan();\n while(isWhiteSpace(n))\n n=scan();\n while(!isWhiteSpace(n))\n {\n sb.append((char)n);\n n=scan();\n }\n return sb.toString();\n }\n private boolean isWhiteSpace(int n)\n {\n if(n==' '||n=='\\n'||n=='\\r'||n=='\\t'||n==-1)\n return true;\n return false;\n }\n }\n public static void main(String args[]) throws IOException {\n Scanner input=new Scanner(System.in);\n long x0=input.nextLong();\n long y0=input.nextLong();\n long ax=input.nextLong();\n long ay=input.nextLong();\n long bx=input.nextLong();\n long by=input.nextLong();\n long xs=input.nextLong();\n long ys=input.nextLong();\n long time=input.nextLong();\n int cnt=1;\n long x=x0,y=y0;\n while(true) {\n x*=ax;\n x+=bx;\n y*=ay;\n y+=by;\n if(x<(long)3*Math.pow(10, 16) && y<3*(long)Math.pow(10, 17)) {\n cnt++;\n }\n else {\n break;\n }\n }\n long arrx[]=new long[cnt];\n long arry[]=new long[cnt];\n x=x0;\n y=y0;\n for(int i=0;i=0;i--) {\n long diff=Math.abs(arrx[i]-x)+Math.abs(arry[i]-y);\n if(diff<=rem) {\n rem-=diff;\n cnt++;\n x=arrx[i];\n y=arry[i];\n }\n else {\n break;\n }\n }\n for(int i=strt+1;i=0;i--) {\n long diff=Math.abs(arrx[i]-x)+Math.abs(arry[i]-y);\n if(diff<=rem) {\n rem-=diff;\n cnt++;\n x=arrx[i];\n y=arry[i];\n }\n else {\n break;\n }\n }\n max=Math.max(max, cnt);\n return max;\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "constructive algorithms", "implementation"], "code_uid": "05b0174092e8cc56d0839f40c0f40ca2", "src_uid": "d8a7ae2959b3781a8a4566a2f75a4e28", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\n/*\n\u041f\u0440\u043e\u043a\u0440\u0430\u0441\u0442\u0438\u043d\u0438\u0440\u0443\u044e\n*/\n\npublic class Main {\n\n static FastReader in;\n static PrintWriter out;\n static Random rand = new Random();\n static final int INF = (int) (1e9 + 10), MOD = (int) (998244353), LOGN = 20;\n static final long IINF = (long) (2e18 + 10);\n static int[][] data = {\n {-1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -1 , -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -1 , -16777216, -16777216, -16777216, -1 , -16777216, -1 , -16777216, -1 , -16777216, -1 , -1 , -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -1 , -16777216, -1 , -1 , -1 , -16777216, -1 , -1 , -1 , -16777216, -16777216, -1 , -16777216, -1 , -1 , -1 , -1 , -16777216, -1 , -1 , -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -1 , -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -1 , -16777216, -16777216, -16777216, -1 , -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -1 , -16777216, -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -16777216, -1 , -16777216, -1 , -16777216, -1 , -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -1 , -1 , -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -1 , -16777216, -1 , -1 , -16777216, -1 , -16777216, -16777216, -1 , -1 , -1 , -16777216, -1 , -1 , -16777216, -1 , -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -1 , -1 , -16777216, -1 , -1 , -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -1 , -16777216, -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -1 , -1 , -16777216, -16777216, -1 , -16777216, -16777216, -1 , -16777216, -16777216, -1 , -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -1 , -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -16777216, -16777216, -1 , -1 , -16777216, -1 , -1 , -16777216, -1 , -1 , -1 , -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -16777216, -1 , -1 , -1 , -1 , -1 , -16777216, -1 , -1 , -1 , -16777216, -1 , -16777216, -16777216, -1 , -1 , -16777216, -16777216, -1 , -16777216, -16777216, -1 , -16777216, -1 , -1 , -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -16777216, -16777216, -16777216, -16777216, -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -16777216, -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -16777216, -1 , -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -16777216, -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -16777216, -16777216, -1 , -16777216, -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -1 , -16777216, -16777216, -1 , -1 , -16777216, -1 , -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -1 , -1 },\n {-1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -16777216, -1 , -1 , -1 , -16777216, -16777216, -16777216, -1 , -1 , -16777216, -16777216, -16777216, -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -1 , -1 , -16777216, -1 , -1 , -1 , -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 },\n {-1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -16777216, -1 , -1 , -16777216, -1 , -1 , -16777216, -16777216, -1 , -16777216, -16777216, -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -16777216, -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 },\n {-1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -16777216, -1 , -1 , -16777216, -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 },\n {-1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -16777216, -1 , -1 , -1 , -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -1 , -1 , -1 , -16777216, -1 , -1 , -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 },\n {-16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -1 , -16777216, -1 , -1 , -16777216, -1 , -1 , -16777216, -1 , -1 , -1 , -16777216, -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -16777216, -1 , -1 , -16777216, -1 , -1 , -1 , -1 , -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216},\n {-16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -16777216, -1 , -1 , -16777216, -1 , -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -1 , -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -1 , -1 , -16777216, -16777216, -16777216, -1 , -1 , -1 , -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216},\n {-16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -16777216, -1 , -1 , -16777216, -1 , -16777216, -1 , -1 , -1 , -1 , -16777216, -1 , -16777216, -1 , -1 , -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216},\n {-16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -16777216, -1 , -1 , -16777216, -1 , -1 , -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -1 , -1 , -1 , -16777216, -1 , -16777216, -1 , -16777216, -16777216, -1 , -16777216, -16777216, -1 , -16777216, -1 , -1 , -16777216, -1 , -1 , -1 , -16777216, -1 , -1 , -16777216, -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216},\n {-16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -1 , -1 , -1 , -16777216, -1 , -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216},\n {-16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -16777216, -16777216, -16777216, -1 , -1 , -16777216, -1 , -1 , -16777216, -1 , -1 , -1 , -16777216, -16777216, -16777216, -1 , -16777216, -1 , -1 , -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -1 , -1 , -16777216, -1 , -16777216, -16777216, -16777216, -1 , -1 , -1 , -16777216, -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216},\n {-16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -16777216, -1 , -1 , -16777216, -16777216, -1 , -16777216, -16777216, -1 , -1 , -16777216, -1 , -1 , -1 , -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216},\n {-16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -1 , -16777216, -1 , -1 , -1 , -1 , -16777216, -1 , -16777216, -1 , -1 , -1 , -1 , -16777216, -1 , -16777216, -1 , -1 , -16777216, -1 , -16777216, -1 , -16777216, -16777216, -1 , -16777216, -1 , -1 , -1 , -16777216, -16777216, -1 , -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216},\n {-16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -1 , -16777216, -1 , -16777216, -1 , -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -1 , -16777216, -1 , -1 , -16777216, -1 , -16777216, -16777216, -16777216, -1 , -1 , -16777216, -16777216, -16777216, -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216},\n {-16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -1 , -1 , -16777216, -1 , -1 , -1 , -16777216, -16777216, -16777216, -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -16777216, -1 , -1 , -16777216, -16777216, -1 , -1 , -1 , -1 , -16777216, -1 , -1 , -16777216, -16777216, -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216},\n {-16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -16777216, -16777216, -16777216, -1 , -1 , -1 , -16777216, -1 , -16777216, -16777216, -1 , -16777216, -16777216, -1 , -16777216, -16777216, -1 , -16777216, -16777216, -1 , -1 , -16777216, -1 , -16777216, -16777216, -16777216, -1 , -16777216, -1 , -1 , -16777216, -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216},\n {-16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -16777216, -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216},\n {-1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -16777216, -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -16777216, -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 },\n {-1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 },\n {-1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -1 , -1 , -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 },\n {-1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 },\n {-1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -16777216, -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 },\n {-1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 },\n {-1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 },\n {-1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -16777216, -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 },\n {-1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -1 , -16777216, -1 , -16777216, -1 , -1 , -16777216, -1 , -16777216, -1 , -1 , -1 , -16777216, -16777216, -1 , -16777216, -1 , -16777216, -16777216, -1 , -1 , -16777216, -1 , -16777216, -1 , -1 , -16777216, -1 , -16777216, -16777216, -1 , -1 , -1 , -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -1 , -1 , -1 , -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -1 , -16777216, -1 , -1 , -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -1 , -1 , -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -1 , -1 , -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -1 , -1 , -16777216, -1 , -1 , -16777216, -1 , -1 , -1 , -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -1 , -16777216, -1 , -1 , -1 , -1 , -1 , -16777216, -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -16777216, -16777216, -1 , -16777216, -16777216, -1 , -16777216, -1 , -1 , -1 , -1 , -16777216, -1 , -1 , -1 , -16777216, -1 , -16777216, -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -1 , -16777216, -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -1 , -16777216, -1 , -16777216, -1 , -1 , -1 , -16777216, -1 , -16777216, -16777216, -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -16777216, -16777216, -16777216, -1 , -1 , -16777216, -1 , -16777216, -1 , -1 , -1 , -16777216, -16777216, -16777216, -1 , -1 , -1 , -16777216, -1 , -16777216, -16777216, -16777216, -1 , -1 , -16777216, -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -1 , -1 , -1 , -1 , -16777216, -1 , -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -1 , -1 , -1 , -1 , -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -1 , -16777216, -16777216, -1 , -16777216, -1 , -16777216, -16777216, -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -16777216, -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 },\n {-1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -16777216, -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 },\n };\n\n static void solve() {\n int row = in.nextInt();\n int col = in.nextInt();\n\n if (data[row][col] == -1) {\n out.println(\"OUT\");\n } else {\n out.println(\"IN\");\n }\n }\n\n public static void main(String[] args) throws FileNotFoundException {\n in = new FastReader(System.in);\n// in = new FastReader(new FileInputStream(\"sometext.txt\"));\n out = new PrintWriter(System.out);\n// out = new PrintWriter(new FileOutputStream(\"sometext.txt\"));\n\n int tests = 1;\n// tests = in.nextInt();\n\n while (tests-- > 0) {\n solve();\n }\n\n// out.flush();\n out.close();\n }\n\n static class FastReader {\n BufferedReader br;\n StringTokenizer st;\n\n FastReader(InputStream is) {\n br = new BufferedReader(new InputStreamReader(is));\n }\n\n Integer nextInt() {\n return Integer.parseInt(next());\n }\n\n Long nextLong() {\n return Long.parseLong(next());\n }\n\n Double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(nextLine());\n }\n return st.nextToken();\n }\n\n String nextLine() {\n String s = \"\";\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return s;\n }\n }\n}", "lang_cluster": "Java", "tags": ["dfs and similar", "geometry", "implementation"], "code_uid": "ce4d5e34d3a71122e3655a67d24981c3", "src_uid": "879ac20ae5d3e7f1002afe907d9887df", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.util.StringTokenizer;\nimport java.util.ArrayList;\n\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskA solver = new TaskA();\n solver.solve(1, in, out);\n out.close();\n }\n}\n\nclass TaskA {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int a, n, b;\n a = in.nextInt(); b = in.nextInt(); n = in.nextInt();\n\n int k = 0;\n\n // 1st a, next b, so on\n while(n >= 0) {\n ++k;\n n -= euclid_gcd( (k % 2 == 1) ? a : b, n);\n }\n\n // why isnt (k & 1) working instead of k % 2 == 1 ?\n // check !\n if (k % 2 == 1) out.println(1);\n else out.println(0); \n\n return;\n }\n\n public int euclid_gcd(int a, int b) {\n return b == 0 ? a : euclid_gcd(b, a%b);\n }\n}\n\nclass InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "bdcc0143f77a631fbbbce4e84a745caf", "src_uid": "0bd6fbb6b0a2e7e5f080a70553149ac2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class NonSquareEquation {\n\n public static int sum(long x) {\n int ret = 0;\n while (x != 0) {\n ret += x % 10;\n x /= 10;\n }\n return ret;\n }\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n long n = in.nextLong();\n for (int i = 1; i <= 81; i++) {\n double x = ((-1 * i) + (Math.sqrt(i * i - (-4 * n))));\n if (x > 0 && x % 2 == 0) {\n x /= 2;\n long x2 = (long) x;\n int sum = sum((long) x);\n long tmp = x2 * x2 + i * x2;\n if (tmp == n && i == sum) {\n System.out.println(x2);\n return;\n }\n\n }\n }\n System.out.println(\"-1\");\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "math", "binary search"], "code_uid": "371173644ac4562a1d8fca7092797ebe", "src_uid": "e1070ad4383f27399d31b8d0e87def59", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Main{\n public static void main(String args[]){\n Scanner in = new Scanner(System.in);\n String s = in.next();\n int n = s.length();\n int[] c = new int[4];\n int[] d = new int[4];\n for(int i=0; iF)\n\t\t\tSystem.out.println(\"YES\");\n\t\telse\n\t\t\tSystem.out.println(\"NO\");\n\t}\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "6f7cec6d5696b914defa53f1e5f88891", "src_uid": "ab8a2070ea758d118b3c09ee165d9517", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\npublic class Codechef\n{\n static long fact(long n){\n long res=1;\n for(int i=1;i<=n;i++){\n res=res*i;\n }\n return res;\n }\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t Scanner sc=new Scanner(System.in);\n\t // BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t int t=1;\n\t //t=sc.nextInt();\n\t // int t=Integer.parseInt(br.readLine());\n\t while(--t>=0){\n\t long n=sc.nextLong();\n\t long D=fact(n/2)*fact(n/2);\n\t long temp=(fact(n)/D)/2;\n\t //System.out.println(temp);\n\t long temp1=(fact(n/2-1));\n\t System.out.println(temp*temp1*temp1);\n\t \n\t \n\t \n\t \n\t \n\t \n\t }\n\t \n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "combinatorics"], "code_uid": "09c06ab7ae06ccb17f5dcdad76add134", "src_uid": "ad0985c56a207f76afa2ecd642f56728", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n\t/**\n\t * @param args\n\t */\n\t\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\t\n\t\tInputReader in = new InputReader(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t//int T = in.nextInt();\n\t\tsolve(1,in,out);\n\t\tout.flush();\n\n\t}\n\n\tprivate static void solve(int testCases, InputReader in, PrintWriter out) {\n\t\t// TODO Auto-generated method stub\n\t\tint n = in.nextInt();\n\t\tint count = 0;\n\t\tfor(int i = 0 ; i < n ; i++){\n\t\t\tint k = in.nextInt();\n\t\t\tif(k==100){\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\t\tif(n==1){\n\t\t\tout.println(\"NO\");\n\t\t\treturn;\n\t\t}else if(count==0 && n%2==1){\n\t\t\tout.println(\"NO\");\n\t\t\treturn;\n\t\t}\n\t\tif(count%2==0){\n\t\t\tout.println(\"YES\");\n\t\t}else{\n\t\t\tout.println(\"NO\");\n\t\t}\n\t}\n\n\n}\n\nclass InputReader {\n\tBufferedReader br ;\n\tStringTokenizer tokenizer;\n\n\tpublic InputReader(InputStream reader){\n\t\tbr = new BufferedReader(new InputStreamReader(reader));\n\t\ttokenizer=null;\n\t}\n\n\tpublic String next(){\n\t\twhile(tokenizer==null||!tokenizer.hasMoreTokens()){\n\t\t\ttry {\n\t\t\t\ttokenizer = new StringTokenizer(br.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\t\treturn tokenizer.nextToken();\n\t}\n\n\tpublic int nextInt(){\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tpublic double nextDouble(){\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tpublic long nextLong(){\n\t\treturn Long.parseLong(next());\n\t}\n}\n", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "d224ca1f0f3f4269d37be1e61c7ee64b", "src_uid": "9679acef82356004e47b1118f8fc836a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.Scanner;\nimport java.util.Vector;\nimport java.util.Arrays;\nimport java.math.BigInteger;\n\npublic class Main {\n\n\t\n\t// This is my functions\nstatic double u(double x1,double y1,double x2,double y2){\n return Math.sqrt( (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) ); \n} \n\n \n \n \n static int[] a = new int[10000000];\npublic static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n \n String s1,s2;\n \n s1=scan.next();\n s2=scan.next();\n for(int i=0;i<=s1.length()-1;i++){\n \t\n \tif(s1.charAt(i)==s2.charAt(i) ){\n \t\tSystem.out.print(0);\n \t}else{\n \t\tSystem.out.print(1);\n \t}\n }\n \n System.out.println();\n \n \n \n}\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "dbf49601faa2984893c4ebe267503fa6", "src_uid": "3714b7596a6b48ca5b7a346f60d90549", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class solution{\npublic static void main(String...args){\nScanner scan=new Scanner(System.in);\nint a[][]=new int[3][3];\nint b[][]=new int[3][3];\nfor(int i=0;i<3;i++){\nfor(int j=0;j<3;j++){\na[i][j]=scan.nextInt();\n}\n}\nfor(int i=0;i<3;i++){\n\tfor(int j=0;j<3;j++){\n\t\tint x=0;\n\t\tint y=0;\n\t\tif(i<2)\n\t\tx=a[i+1][j];\n\t if(j<2) y=a[i][j+1];\n\t\tb[i][j]=a[i][j]+x+y;\n\t}\n}\nfor(int i=0;i<3;i++){\n\tfor(int j=0;j<3;j++){\n\t\tint x=0;\n\t\tint y=0;\n\t\tif(i>0)\n\t\tx=a[i-1][j];\n\t if(j>0) y=a[i][j-1];\n\t\tb[i][j]=b[i][j]+x+y;\n\t}\n}\nfor(int i=0;i<3;i++){\nfor(int j=0;j<3;j++){\nSystem.out.print(((b[i][j]+1)%2));\n}\nSystem.out.println();\n}\n}\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "01bcb10b0e12a46e90c99eae3a2c2992", "src_uid": "b045abf40c75bb66a80fd6148ecc5bd6", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class RestoringPassword {\npublic static void main(String[] args) {\n Scanner cs=new Scanner(System.in);\n String s=cs.next();\n String [] s1=new String [10];\n String[]s2=new String[8];\n for(int i=0;i<10;i++)\n {\n s1[i]=cs.next();\n }\n for(int i=0;i<8;i++)\n {\n\n s2[i]=s.substring(0+(10*i),10+(10*i));\n }\n String res=\"\";\n for(int i=0;i<8;i++)\n {\n for (int j=0;j<10;j++)\n {\n if(s2[i].equals(s1[j]))\n {\n res=res+j;\n break;\n }\n }\n }\n System.out.println(res);\n\n}\n}", "lang_cluster": "Java", "tags": ["strings", "implementation"], "code_uid": "eceff903162c15575b1aa4e914ea3be9", "src_uid": "0f4f7ca388dd1b2192436c67f9ac74d9", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\npublic class solution{\n public static void main(String[] args)\n {\n Scanner snr=new Scanner(System.in);\n int n=snr.nextInt();\n int x=snr.nextInt();\n int cnt=0;\n \n for (int i = 1; i <= n; i++)\n if (x % i == 0 && x / i <= n) cnt++;\n System.out.println(cnt);\n }\n}", "lang_cluster": "Java", "tags": ["implementation", "number theory"], "code_uid": "0e425bfec6a6af3c0674bda15b9adc83", "src_uid": "c4b139eadca94201596f1305b2f76496", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\n\npublic class TaskC {\n\n\tpublic FasterScanner mFScanner;\n\tpublic PrintWriter mOut;\n\tprivate static final boolean LEFT = true;\n\tprivate static final boolean RIGHT = false;\n\tprivate static boolean sFound;\n\n\tpublic TaskC() {\n\t\tmFScanner = new FasterScanner();\n\t\tmOut = new PrintWriter(System.out);\n\t}\n\n\tpublic void solve() {\n\t\tint h;\n\t\tlong visNodes;\n\t\tlong n;\n\n\t\th = mFScanner.nextInt();\n\t\tn = mFScanner.nextLong();\n\n\t\tsFound = false;\n\t\t\n\t\tvisNodes = dfs(n, LEFT, h, 1, (1L << h));\n\n\t\tmOut.println(visNodes);\n\n\t}\n\n\tpublic long dfs(long child, boolean dir, int height, long begin, long end) {\n\n\t\tlong sum = 1;\n\t\tlong temp;\n\n\t\tif (height == 0 && begin == child) {\n\t\t\tsFound = true;\n\t\t\treturn 0;\n\t\t}\n\n\t\tif (height == 0)\n\t\t\treturn 1;\n\n\t\tif (child >= begin && child <= end) {\n\t\t\ttemp = end - begin + 1;\n\t\t\ttemp /= 2;\n\n\t\t\tif (dir == LEFT) {\n\t\t\t\tsum += dfs(child, RIGHT, height - 1, begin, begin + temp - 1);\n\t\t\t} else {\n\t\t\t\tsum += dfs(child, LEFT, height - 1, end - temp + 1, end);\n\t\t\t}\n\n\t\t\tdir = !dir;\n\n\t\t\tif (!sFound) {\n\t\t\t\tif (dir == LEFT) {\n\t\t\t\t\tsum += dfs(child, RIGHT, height - 1, begin, begin + temp\n\t\t\t\t\t\t\t- 1);\n\t\t\t\t} else {\n\t\t\t\t\tsum += dfs(child, LEFT, height - 1, end - temp + 1, end);\n\t\t\t\t}\n\t\t\t}\n\n\t\t} else {\n\t\t\tsum += (1L << (height + 1)) - 2;\n\t\t}\n\n\t\treturn sum;\n\n\t}\n\n\tpublic void flush() {\n\t\tmOut.flush();\n\t}\n\n\tpublic void close() {\n\t\tmOut.close();\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tTaskC mSol = new TaskC();\n\t\tmSol.solve();\n\t\tmSol.flush();\n\t\tmSol.close();\n\t}\n\n\tclass FasterScanner {\n\t\tprivate InputStream mIs;\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n\n\t\tpublic FasterScanner() {\n\t\t\tthis(System.in);\n\t\t}\n\n\t\tpublic FasterScanner(InputStream is) {\n\t\t\tmIs = is;\n\t\t}\n\n\t\tpublic int read() {\n\t\t\tif (numChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= numChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tnumChars = mIs.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (numChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isEndOfLine(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic String nextString() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\tDouble next;\n\t\t\tnext = Double.parseDouble(nextString());\n\t\t\treturn next;\n\t\t}\n\n\t\tpublic boolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tpublic boolean isEndOfLine(int c) {\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t}\n\n\t\tpublic char[] nextCharArray(int N) {\n\t\t\tint i;\n\t\t\tchar[] array;\n\t\t\tString str;\n\n\t\t\tarray = new char[N];\n\n\t\t\ti = 0;\n\n\t\t\tstr = nextLine();\n\n\t\t\tfor (i = 0; i < N && i < str.length(); i++) {\n\t\t\t\tarray[i] = str.charAt(i);\n\t\t\t}\n\n\t\t\treturn array;\n\t\t}\n\n\t\tpublic char[][] nextChar2DArray(int M, int N) {\n\t\t\tint i;\n\t\t\tchar[][] array;\n\n\t\t\tarray = new char[M][N];\n\n\t\t\ti = 0;\n\n\t\t\tfor (i = 0; i < M; i++) {\n\t\t\t\tarray[i] = nextCharArray(N);\n\t\t\t}\n\n\t\t\treturn array;\n\t\t}\n\n\t\tpublic int[] nextIntArray(int N) {\n\t\t\tint i;\n\t\t\tint[] array;\n\n\t\t\tarray = new int[N];\n\n\t\t\ti = 0;\n\n\t\t\tfor (i = 0; i < N; i++) {\n\t\t\t\tarray[i] = nextInt();\n\t\t\t}\n\n\t\t\treturn array;\n\t\t}\n\n\t\tpublic int[][] nextInt2DArray(int M, int N) {\n\t\t\tint i;\n\t\t\tint[][] array;\n\n\t\t\tarray = new int[M][N];\n\n\t\t\ti = 0;\n\n\t\t\tfor (i = 0; i < M; i++) {\n\t\t\t\tarray[i] = nextIntArray(N);\n\t\t\t}\n\n\t\t\treturn array;\n\t\t}\n\n\t\tpublic long[] nextLongArray(int N) {\n\t\t\tint i;\n\t\t\tlong[] array;\n\n\t\t\tarray = new long[N];\n\n\t\t\ti = 0;\n\n\t\t\tfor (i = 0; i < N; i++) {\n\t\t\t\tarray[i] = nextLong();\n\t\t\t}\n\n\t\t\treturn array;\n\t\t}\n\n\t\tpublic long[][] nextLong2DArray(int M, int N) {\n\t\t\tint i;\n\t\t\tlong[][] array;\n\n\t\t\tarray = new long[M][N];\n\n\t\t\ti = 0;\n\n\t\t\tfor (i = 0; i < M; i++) {\n\t\t\t\tarray[i] = nextLongArray(N);\n\t\t\t}\n\n\t\t\treturn array;\n\t\t}\n\n\t\tpublic double[] nextDoubleArray(int N) {\n\t\t\tint i;\n\t\t\tdouble[] array;\n\n\t\t\tarray = new double[N];\n\n\t\t\tfor (i = 0; i < N; i++) {\n\t\t\t\tarray[i] = nextDouble();\n\t\t\t}\n\n\t\t\treturn array;\n\t\t}\n\n\t\tpublic double[][] nextDouble2DArray(int M, int N) {\n\t\t\tint i;\n\t\t\tdouble[][] array;\n\n\t\t\tarray = new double[M][N];\n\n\t\t\tfor (i = 0; i < M; i++) {\n\t\t\t\tarray[i] = nextDoubleArray(N);\n\t\t\t}\n\n\t\t\treturn array;\n\t\t}\n\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "implementation", "trees"], "code_uid": "4056672ade92cb5e9833d56064ab5a80", "src_uid": "3dc25ccb394e2d5ceddc6b3a26cb5781", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class TextVolume {\n\n\tpublic static void main(String[] args) {\n\t\tScanner scn = new Scanner(System.in);\n\t\tint n = scn.nextInt();\n\t\tscn.nextLine();\n\t\tString str = scn.nextLine();\n\t\tint max = 0;\n\t\tint cn = 0;\n\t\tfor(int i = 0;i='A'&& ch<='Z'){\n\t\t\t\tcn++;\n\t\t\t\tif(cn>max){\n\t\t\t\t\tmax = cn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(max);\n\t}\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "9099019cfe3b76895eb2e8db3a967e3a", "src_uid": "d3929a9acf1633475ab16f5dfbead13c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.PrintWriter;\nimport java.util.Scanner;\n\n\npublic class TaskB {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tnew TaskB().solve(in, out);\n\t\tin.close();\n\t\tout.close();\n\t}\n\t\n\tprivate void solve(Scanner in, PrintWriter out) {\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tif (m < n) {\n\t\t\tn += m;\n\t\t\tm = n - m;\n\t\t\tn -= m;\n\t\t}\n\t\tint g = 0, f = 0;\n\t\tf += n;\n\t\tg += m - 1;\n\t\tout.println(g + \" \" + f);\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["greedy", "implementation", "games"], "code_uid": "a4e1f9c94232ebf3335f36e3845632be", "src_uid": "c8378e6fcaab30d15469a55419f38b39", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.awt.*;\nimport java.awt.geom.*;\nimport java.io.*;\nimport java.math.*;\nimport java.text.*;\nimport java.util.*;\n\n/*\n\tbr = new BufferedReader(new FileReader(\"input.txt\"));\n\tpw = new PrintWriter(new BufferedWriter(new FileWriter(\"output.txt\")));\n\tbr = new BufferedReader(new InputStreamReader(System.in));\n\tpw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n */\n\npublic class Main {\n\tprivate static BufferedReader br;\n\tprivate static StringTokenizer st;\n\tprivate static PrintWriter pw;\n\n\tstatic int[] dx = new int[]{-1,0,0,0,1};\n\tstatic int[] dy = new int[]{0,-1,0,1,0};\n\t\n\tpublic static void main(String[] args) throws IOException\t{\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tpw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\t\tint qq = 1;\n\t\t//int qq = Integer.MAX_VALUE;\n\t\t//int qq = readInt();\n\t\tfor(int casenum = 1; casenum <= qq; casenum++)\t{\n\t\t\tint ret = 0;\n\t\t\tint n = readInt();\n\t\t\tint sum = 0;\n\t\t\tfor(int i = 0; i < n; i++)\t{\n\t\t\t\tsum += readInt();\n\t\t\t}\n\t\t\tn++;\n\t\t\tfor(int k = 1; k <= 5; k++)\t{\n\t\t\t\tif((sum+k)%n != 1)\t{\n\t\t\t\t\tret++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tpw.println(ret);\n\t\t}\n\t\tpw.close();\n\t}\n\n\tprivate static long readLong() throws IOException\t{\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tprivate static double readDouble() throws IOException\t{\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tprivate static int readInt() throws IOException\t{\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tprivate static String nextToken() throws IOException\t{\n\t\twhile(st == null || !st.hasMoreTokens())\t{\n\t\t\tif(!br.ready())\t{\n\t\t\t\tpw.close();\n\t\t\t\tSystem.exit(0);\n\t\t\t}\n\t\t\tst = new StringTokenizer(br.readLine().trim());\n\t\t}\n\t\treturn st.nextToken();\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "bd3f55e8c849cbffe09c74da2067206b", "src_uid": "ff6b3fd358c758324c19a26283ab96a4", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\n\npublic class A {\n\n static StringTokenizer st;\n static BufferedReader br;\n static PrintWriter pw;\n public static void main(String[] args) throws IOException {\n br = new BufferedReader(new InputStreamReader(System.in));\n pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n int n = nextInt();\n int[]x = new int[n+1];\n for (int i = 1; i <= n; i++) {\n x[i] = nextInt();\n }\n Arrays.sort(x, 1, n+1);\n for (int i = 1; i <= n; i++) {\n boolean ok = true;\n int r = 1, h = 1;\n for (int j = 1; j <= n; j++) {\n if (x[j] < h-1) {\n ok = false;\n break;\n }\n r++;\n if (r==i+1) {\n r = 1;\n h++;\n }\n }\n if (ok) {\n System.out.println(i);\n return;\n }\n }\n pw.close();\n }\n private static int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n private static long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n private static double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n private static String next() throws IOException {\n while (st==null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n}", "lang_cluster": "Java", "tags": ["sortings", "greedy"], "code_uid": "64a3237b7c7de1664063ebfcc6890f18", "src_uid": "7c710ae68f27f140e7e03564492f7214", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.NoSuchElementException;\nimport java.io.Writer;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Alex\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tOutputWriter out = new OutputWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n\t\tlong n = in.readLong(), res = 1, p = 3;\n\t\twhile (p < n) {\n\t\t\tif (n % p != 0) res = Math.max(res, n / p + 1);\n\t\t\tp *= 3;\n\t\t}\n\t\tout.print(res);\n\t}\n}\n\nclass InputReader {\n\tprivate InputStream stream;\n\tprivate byte[] buf = new byte[1024];\n\tprivate int curChar;\n\tprivate int numChars;\n\tprivate SpaceCharFilter filter;\n\n\tpublic InputReader(InputStream stream) {\n\t\tthis.stream = stream;\n\t}\n\n\tpublic int read() {\n\t\tif (numChars == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (curChar >= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n\tpublic long readLong() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tlong res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\tpublic boolean isSpaceChar(int c) {\n\t\tif (filter != null)\n\t\t\treturn filter.isSpaceChar(c);\n\t\treturn isWhitespace(c);\n\t}\n\n\tpublic static boolean isWhitespace(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n\tpublic interface SpaceCharFilter {\n\t\tpublic boolean isSpaceChar(int ch);\n\t}\n}\n\nclass OutputWriter {\n\tprivate final PrintWriter writer;\n\n\tpublic OutputWriter(OutputStream outputStream) {\n\t\twriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n\t}\n\tpublic void close() {\n\t\twriter.close();\n\t}\n\tpublic void print(long i) {\n\t\twriter.print(i);\n\t}\n}\n\n", "lang_cluster": "Java", "tags": ["greedy"], "code_uid": "40687a19669d4776821f9ff8ef2811a6", "src_uid": "7e7b59f2112fd200ee03255c0c230ebd", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.io.*;\n\npublic class A {\n\n private static final String REGEX = \" \";\n private static final Boolean DEBUG = false;\n private static final String FILE_NAME = \"input.txt\";\n\n\n public static void main(String[] args) throws IOException {\n if (DEBUG) {\n generate();\n }\n Solver solver = new Solver();\n solver.readData();\n solver.solve();\n solver.print();\n }\n\n private static void generate() throws IOException {\n// FileWriter writer = new FileWriter(\"input.txt\");\n// writer.close();\n }\n\n private static class Solver {\n private StringBuilder myStringBuilder = new StringBuilder();\n int n;\n int[] a, b;\n\n void readData() throws IOException {\n Scanner scanner = new Scanner();\n n = scanner.nextInt();\n a = scanner.nextIntArray(n);\n b = scanner.nextIntArray(n);\n scanner.close();\n }\n\n void solve() {\n int[] as = new int[5];\n int[] bs = new int[5];\n\n for (int i : a) {\n as[i - 1]++;\n }\n\n for (int i : b) {\n bs[i - 1]++;\n }\n\n int sum = 0;\n int x = 0;\n for (int i = 0; i < 5; i++) {\n int abs = Math.abs(as[i] - bs[i]);\n if (abs % 2 == 1) {\n out(-1);\n return;\n }\n if (as[i] > bs[i]) {\n x += abs / 2;\n } else {\n x -= abs / 2;\n }\n sum += abs / 2;\n }\n if (x!=0){\n out(-1);\n } else {\n out(sum / 2);\n }\n }\n\n void print() {\n System.out.println(myStringBuilder);\n }\n\n\n void out(Object object) {\n myStringBuilder.append(object);\n }\n\n void out(String string) {\n myStringBuilder.append(string);\n }\n\n public void out(boolean b) {\n myStringBuilder.append(b);\n }\n\n public void out(char c) {\n myStringBuilder.append(c);\n }\n\n public void out(int i) {\n myStringBuilder.append(i);\n }\n\n public void out(long lng) {\n myStringBuilder.append(lng);\n }\n\n public void out(float f) {\n myStringBuilder.append(f);\n }\n\n public void out(double d) {\n myStringBuilder.append(d);\n }\n\n public void newLine() {\n myStringBuilder.append(\"\\n\");\n }\n\n @SuppressWarnings(\"SameParameterValue\")\n int[] splitInteger(String string, int n) {\n final String[] split = string.split(REGEX, n);\n int[] result = new int[split.length];\n for (int i = 0; i < n; ++i) {\n result[i] = Integer.parseInt(split[i]);\n }\n return result;\n }\n\n public int[] splitInteger(String string) {\n return splitInteger(string, 0);\n }\n\n\n @SuppressWarnings(\"SameParameterValue\")\n long[] splitLong(String string, int n) {\n final String[] split = string.split(REGEX, n);\n long[] result = new long[split.length];\n for (int i = 0; i < n; ++i) {\n result[i] = Long.parseLong(split[i]);\n }\n return result;\n }\n\n public long[] splitLong(String string) {\n return splitLong(string, 0);\n }\n\n @SuppressWarnings(\"SameParameterValue\")\n double[] splitDouble(String string, int n) {\n final String[] split = string.split(REGEX, n);\n double[] result = new double[split.length];\n for (int i = 0; i < n; ++i) {\n result[i] = Double.parseDouble(split[i]);\n }\n return result;\n }\n\n public double[] splitDouble(String string) {\n return splitDouble(string, 0);\n }\n\n @SuppressWarnings(\"SameParameterValue\")\n String[] splitString(String string, int n) {\n return string.split(REGEX, n);\n }\n\n public int max(int a, int b) {\n return Math.max(a, b);\n }\n\n public int max(int[] arr) {\n int max = Integer.MIN_VALUE;\n for (int x : arr) {\n max = max(max, x);\n }\n return max;\n }\n\n public long max(long a, long b) {\n return Math.max(a, b);\n }\n\n public int min(int a, int b) {\n return Math.min(a, b);\n }\n\n public long min(long a, long b) {\n return Math.min(a, b);\n }\n\n public double max(double a, double b) {\n return Math.max(a, b);\n }\n\n public double min(double a, double b) {\n return Math.min(a, b);\n }\n\n private final static int MOD = 1000000009;\n\n int multMod(int a, int b) {\n return ((a % MOD) * (b % MOD)) % MOD;\n }\n\n int sumMod(int a, int b) {\n return ((a % MOD) + (b % MOD)) % MOD;\n }\n\n long multMod(long a, long b) {\n return ((a % MOD) * (b % MOD)) % MOD;\n }\n\n long sumMod(long a, long b) {\n return ((a % MOD) + (b % MOD)) % MOD;\n }\n\n int sum(int[] arr) {\n int sum = 0;\n for (int i = 0; i < arr.length; i++) {\n sum += arr[i];\n }\n return sum;\n }\n\n long sum(long[] arr) {\n long sum = 0;\n for (int i = 0; i < arr.length; i++) {\n sum += arr[i];\n }\n return sum;\n }\n\n private class Scanner {\n private int currentIndex = 0;\n private String[] objects;\n private final BufferedReader myReader;\n private Computable charComputer;\n private Computable doubleComputer;\n private Computable intComputer;\n private Computable longComputer;\n\n Scanner() throws FileNotFoundException {\n InputStream in = DEBUG ? new FileInputStream(FILE_NAME) : System.in;\n myReader = new BufferedReader(new InputStreamReader(in));\n charComputer = () -> objects[currentIndex].charAt(0);\n doubleComputer = () -> Double.parseDouble(objects[currentIndex]);\n intComputer = () -> Integer.parseInt(objects[currentIndex]);\n longComputer = () -> Long.parseLong(objects[currentIndex]);\n }\n\n String nextLine() throws IOException {\n objects = null;\n currentIndex = 0;\n return myReader.readLine();\n }\n\n int nextInt() throws IOException {\n return next(intComputer);\n }\n\n int[] nextIntArray(int n) throws IOException {\n return splitInteger(nextLine(), n);\n }\n\n long[] nextLongArray(int n) throws IOException {\n return splitLong(nextLine(), n);\n }\n\n long nextLong() throws IOException {\n return next(longComputer);\n\n }\n\n double nextDouble() throws IOException {\n return next(doubleComputer);\n\n }\n\n char nextChar() throws IOException {\n return next(charComputer);\n }\n\n T next(Computable computer) throws IOException {\n T result;\n if (objects == null || currentIndex >= objects.length) {\n String s = myReader.readLine();\n objects = s.split(\" \");\n currentIndex = 0;\n }\n result = computer.compute();\n currentIndex++;\n return result;\n }\n\n public void close() throws IOException {\n myReader.close();\n }\n\n }\n\n interface Computable {\n T compute();\n }\n\n }\n\n}\n", "lang_cluster": "Java", "tags": ["math", "constructive algorithms"], "code_uid": "937d84c487cccb736aeede495695a44b", "src_uid": "47da1dd95cd015acb8c7fd6ae5ec22a3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/*\n _____ _ _ _____ _ _ ______ _____ ______ \n / ____| | | |_ _| \\ | | ____|/ ____| ____| \n | | | |__| | | | | \\| | |__ | (___ | |__ \n | | | __ | | | | . ` | __| \\___ \\| __| \n | |____| | | |_| |_| |\\ | |____ ____) | |____ \n \\_____|_| |_|_____|_|_\\_|______|_____/|______| \n \\ \\ / /_ _| __ \\| | | |/ ____| \n \\ \\ / / | | | |__) | | | | (___ \n \\ \\/ / | | | _ /| | | |\\___ \\ \n \\ / _| |_| | \\ \\| |__| |____) | \n \\/ |_____|_| \\_\\\\____/|_____/ \n |_ _|/ ____| \n | | | (___ \n | | \\___ \\ \n _| |_ ____) | \n _______ _ _ _____ ______|_____|_____/_ ______ _ _ _____ _ _ _____ \n |__ __| | | | __ \\| ____| /\\|__ __| ____| \\ | |_ _| \\ | |/ ____| \n | | | |__| | |__) | |__ / \\ | | | |__ | \\| | | | | \\| | | __ \n | | | __ | _ /| __| / /\\ \\ | | | __| | . ` | | | | . ` | | |_ | \n | | | | | | | \\ \\| |____ / ____ \\| | | |____| |\\ |_| |_| |\\ | |__| | \n |_| _|_|__|_|_| \\_\\______/_/ \\_\\_| _|______|_|_\\_|_____|_|_\\_|\\_____| \n |__ __| | | | ____| \\ \\ / / __ \\| __ \\| | | __ \\ \n | | | |__| | |__ \\ \\ /\\ / / | | | |__) | | | | | | \n | | | __ | __| \\ \\/ \\/ /| | | | _ /| | | | | | \n | | | | | | |____ \\ /\\ / | |__| | | \\ \\| |____| |__| | \n |_| |_| |_|______| \\/ \\/ \\____/|_| \\_\\______|_____/ \n \n*/\nimport java.util.*;\n\npublic class solution {\n public static void main(String a[]) {\n int bact = 0;\n\n Scanner in = new Scanner(System.in);\n bact = in.nextInt();\n\n\n if((bact & (bact - 1)) == 0) {\n System.out.print(1);\n System.exit(0);\n }\n \n int bactCount = 0;\n int index = 0;\n int doneCyc = 0;\n for(int temp = 0; doneCyc != bact; temp+=doneCyc ){\n while(Math.pow(2, index) < bact - doneCyc ) {\n if(Math.pow(2, index + 1 ) > bact - doneCyc) {\n break;\n }\n index++;\n }\n if(temp != bact) {\n bactCount++;\n doneCyc += Math.pow(2, index);\n index = 0;\n }\n }\n \n System.out.print(bactCount);\n }\n \n}", "lang_cluster": "Java", "tags": ["bitmasks"], "code_uid": "8f0fe291517e156f23557c27873abc24", "src_uid": "03e4482d53a059134676f431be4c16d2", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n//Your code goes here\npublic class Main {\t\n\t\n\tstatic class ProblemSolver{\n\t\tpublic void solveTheProblem(InputReader in,PrintWriter out){\n\t\t\t\n\t\t\t//Take the necessary inputs and variables\n\t\t\tString s=in.next();\n\t\t\t\n\t\t\t//Evaluation of the result\n\t\t\t/*\n\t\t\t * Here we need to take care of simply one thing\n\t\t\t * i.e. the indexing. Say the length of the string\n\t\t\t * is n then as we know the indexing starts from 0\n\t\t\t * and ends with n-1 but here we have 2 more indices\n\t\t\t * \t\t1. start(-1) \n\t\t\t * \t\t2. end(n)\n\t\t\t * \n\t\t\t * Rest is all about finding the maximum gap b/w\n\t\t\t * 2 alphabets considering both the start and end\n\t\t\t * indices.\n\t\t\t */\n\t\t\tint max=0;\n\t\t\tint start=-1;/* start index as -1 */\n\t\t\tfor(int curr=0;curr elements;\n\t\n public static void main(String[] args) throws IOException {\n Scanner scan = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n \n elements = new HashSet();\n \n String temp = \"H He Li Be B C N O F Ne Na Mg Al Si P S Cl Ar K Ca Sc Ti V Cr Mn Fe Co Ni Cu Zn Ga Ge As Se Br Kr Rb Sr Y Zr Nb Mo Tc Ru Rh Pd Ag Cd In Sn Sb Te I Xe Cs Ba La Ce Pr Nd Pm Sm Eu Gd Tb Dy Ho Er Tm Yb Lu Hf Ta W Re Os Ir Pt Au Hg Tl Pb Bi Po At Rn Fr Ra Ac Th Pa U Np Pu Am Cm Bk Cf Es Fm Md No Lr Rf Db Sg Bh Hs Mt Ds Rg Cn Nh Fl Mc Lv Ts Og\";\n \n String[] ele = temp.split(\" \");\n \n for (String e : ele) {\n \telements.add(e.toUpperCase());\n }\n \n String s = scan.nextLine();\n //elements.add(\"H\");\n \n if (possible(0, s)) {\n \tSystem.out.println(\"YES\");\n }\n else {\n \tSystem.out.println(\"NO\");\n }\n \n //out.close();\n }\n \n public static boolean possible(int index, String s) {\n \tint n = s.length();\n \t\n \tboolean f = false;\n \t\n \tif (index >= n)\n \t\treturn true;\n \t\n \tString find = \"\" + s.charAt(index);\n \t\n \tif (elements.contains(find)) {\n \t\tf|=possible(index+1, s);\n \t}\n \t\n \tif (index + 1 < n) {\n \t\tfind += s.charAt(index+1);\n \t\tif (elements.contains(find)) {\n \t\t\tf|=possible(index+2, s);\n \t\t}\n \t\tif (index + 2 < n) {\n \t\t\tfind += s.charAt(index+2);\n \t\t\tif (elements.contains(find)) {\n \t\t\t\tf|=possible(index+3, s);\n \t\t\t}\n \t\t}\n \t}\n \t\n \treturn f;\n }\n \n \n \n \n \n \n \n \n}", "lang_cluster": "Java", "tags": ["brute force", "strings", "dp"], "code_uid": "c3a429cceb7e270a69ea2c3c319f9239", "src_uid": "d0ad35798119f98320967127c43ae88d", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n\tpublic static class InputReader {\n\t\tpublic BufferedReader reader;\n\t\tpublic StringTokenizer tokenizer;\n\n\t\tpublic InputReader() {\n\t\t\treader = new BufferedReader(new InputStreamReader(System.in), 32765);\n\t\t\ttokenizer = null;\n\t\t}\n\n\t\tpublic InputReader(InputStream stream) {\n\t\t\treader = new BufferedReader(new InputStreamReader(System.in), 32765);\n\t\t\ttokenizer = null;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\n\t\tpublic char nextChar() {\n\t\t\treturn next().charAt(0);\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic int[] nextIntArr(int n) {\n\t\t\tint[] arr = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = this.nextInt();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tpublic Integer[] nextIntegerArr(int n) {\n\t\t\tInteger[] arr = new Integer[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = new Integer(this.nextInt());\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tpublic int[][] next2DIntArr(int n, int m) {\n\t\t\tint[][] arr = new int[n][m];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\t\tarr[i][j] = this.nextInt();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tpublic int[] nextSortedIntArr(int n) {\n\t\t\tint[] arr = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = this.nextInt();\n\t\t\t}\n\t\t\tArrays.sort(arr);\n\t\t\treturn arr;\n\t\t}\n\n\t\tpublic long[] nextLongArr(int n) {\n\t\t\tlong[] arr = new long[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = this.nextLong();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tpublic long[] nextSortedLongArr(int n) {\n\t\t\tlong[] arr = new long[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = this.nextInt();\n\t\t\t}\n\t\t\tArrays.sort(arr);\n\t\t\treturn arr;\n\t\t}\n\n\t\tpublic char[] nextCharArr(int n) {\n\t\t\tchar[] arr = new char[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = this.nextChar();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\t}\n\n\tpublic static InputReader scn = new InputReader();\n\tpublic static PrintWriter out = new PrintWriter(System.out);\n\n\tpublic static void main(String[] args) {\n\t\t// InputStream inputStream = System.in; // Useful when taking input other than\n\t\t// console eg file handling // check ctor of inputReader\n\t\t// To print in file use this:- out = new PrintWriter(\"destination of file\n\t\t// including extension\");\n\n\t\tlong n = scn.nextLong() + 1, k = scn.nextLong(), i = 1;\n\t\t\n\t\twhile(i <= k && i <= 100) {\n\t\t\tif(n % i != 0) {\n\t\t\t\tSystem.out.println(\"No\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\ti++;\n\t\t}\n\t\t\n\t\tSystem.out.println(\"Yes\");\n\t}\n}\n", "lang_cluster": "Java", "tags": ["brute force", "number theory"], "code_uid": "b75a267f7620c19c4d94f46673de8a3b", "src_uid": "5271c707c9c72ef021a0baf762bf3eb2", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\n\npublic class Solution {\n\n static Scanner sc = new Scanner(System.in);\n\n public static void main(String[] args) {\n System.out.println((sc.next().length() + 1) * 25 + 1);\n\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "math", "strings"], "code_uid": "58bc5900bc2e4f57d82b850a6124aa98", "src_uid": "556684d96d78264ad07c0cdd3b784bc9", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\n import java.util.*;\n import java.math.*;\n import java.io.*;\n public class Main\n {\n \tpublic static void main(String[] args)\n \t{\n \t\tScanner in = new Scanner(System.in);\n \t\tlong a = in.nextInt();\n \t\tlong b = in.nextInt();\n \t\tlong x = in.nextInt();\n \t\tlong y = in.nextInt();\n \t\tlong z = in.nextInt();\n \t\tlong res = 0;\n \t\tx *= 2;\n \t\tx += y;\n \t\tz *= 3;\n \t\tz += y;\n \t\tif(x - a > 0) res += x - a;\n \t\tif(z - b > 0) res += z - b;\n \t\tSystem.out.println(res);\n \t}\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "ac6348a0db4a4902189a4af79d104494", "src_uid": "35202a4601a03d25e18dda1539c5beba", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/**\n * Created by user on 11/10/2019.\n */\n\nimport java.io.*;\nimport java.util.ArrayList;\n\npublic class tilePainting {\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(System.out));\n long num = Long.parseLong(br.readLine());\n ArrayList primeList = new ArrayList<>(100);\n for(int i=2;i<=Math.sqrt(num);i++){\n if(num%i==0){\n primeList.add((long) i);\n while(num%i==0)\n num/=i;\n }\n }\n if(num!=1)\n primeList.add(num);\n if(primeList.size()>1)\n System.out.println(1);\n else if(primeList.size()==0)\n System.out.println(num);\n else\n System.out.println(primeList.get(0));\n\n\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "constructive algorithms", "number theory"], "code_uid": "776f2236763d86bd0d74b1736ec08b16", "src_uid": "f553e89e267c223fd5acf0dd2bc1706b", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/*\n * Author: Minho Kim (ISKU)\n * Date: March 5, 2018\n * E-mail: minho.kim093@gmail.com\n *\n * https://github.com/ISKU/Algorithm\n * http://codeforces.com/problemset/problem/931/B\n */\n\nimport java.util.*;\n\npublic class B {\n\tpublic static void main(String... args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint N = sc.nextInt();\n\t\tint H = (int) (Math.log(N) / Math.log(2));\n\t\tint A = sc.nextInt() + (1 << H) - 1;\n\t\tint B = sc.nextInt() + (1 << H) - 1;\n\n\t\twhile (A != B) {\n\t\t\tA /= 2;\n\t\t\tB /= 2;\n\t\t}\n\n\t\tint R = (int) (Math.log(A) / Math.log(2));\n\t\tSystem.out.print((R == 0) ? \"Final!\" : H - R);\n\t}\n}", "lang_cluster": "Java", "tags": ["constructive algorithms", "implementation"], "code_uid": "008fb1219ab458590855a7de1878f3cc", "src_uid": "a753bfa7bde157e108f34a28240f441f", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Collections;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.StringTokenizer;\npublic class codeforces870A\n{ \n\tstatic class FastReader \n\t{ \n\t\tBufferedReader br; \n\t\tStringTokenizer st; \n\n\t\tpublic FastReader() \n\t\t{ \n\t\t\tbr = new BufferedReader(new\n\t\t\t\t\tInputStreamReader(System.in)); \n\t\t} \n\n\t\tString next() \n\t\t{ \n\t\t\twhile (st == null || !st.hasMoreElements()) \n\t\t\t{ \n\t\t\t\ttry\n\t\t\t\t{ \n\t\t\t\t\tst = new StringTokenizer(br.readLine()); \n\t\t\t\t} \n\t\t\t\tcatch (IOException e) \n\t\t\t\t{ \n\t\t\t\t\te.printStackTrace(); \n\t\t\t\t} \n\t\t\t} \n\t\t\treturn st.nextToken(); \n\t\t} \n\n\t\tint nextInt() \n\t\t{ \n\t\t\treturn Integer.parseInt(next()); \n\t\t} \n\n\t\tlong nextLong() \n\t\t{ \n\t\t\treturn Long.parseLong(next()); \n\t\t} \n\n\t\tdouble nextDouble() \n\t\t{ \n\t\t\treturn Double.parseDouble(next()); \n\t\t} \n\n\t\tString nextLine() \n\t\t{ \n\t\t\tString str = \"\"; \n\t\t\ttry\n\t\t\t{ \n\t\t\t\tstr = br.readLine(); \n\t\t\t} \n\t\t\tcatch (IOException e) \n\t\t\t{ \n\t\t\t\te.printStackTrace(); \n\t\t\t} \n\t\t\treturn str; \n\t\t} \n\t} \n\n\tpublic static void main(String[] args) \n\t{ \n FastReader s=new FastReader();\n StringBuilder sb=new StringBuilder();\n int n=s.nextInt(),m=s.nextInt(),i,x,y;\n List l1= new LinkedList<>();\n List l2= new LinkedList<>();\n List l3= new LinkedList<>();\n for(i=0;i min) {\n updated = true;\n\n if (a[i] % min == 0)\n a[i] = min;\n else {\n a[i] = a[i] % min;\n min = a[i];\n }\n }\n } while (updated);\n\n int sum = 0;\n for (int i = 0; i < n; i++)\n sum += a[i];\n\n out.print(sum);\n }\n\n public static void main(String[] args) {\n InputReader in = new InputReader(System.in);\n OutputWriter out = new OutputWriter(System.out);\n solve(in, out);\n in.close();\n out.close();\n }\n\n private static class InputReader {\n\n private BufferedReader br;\n private StringTokenizer st;\n\n InputReader(InputStream is) {\n br = new BufferedReader(new InputStreamReader(is));\n st = null;\n }\n\n String nextLine() {\n String line = null;\n\n try {\n line = br.readLine();\n\n } catch (IOException e) {\n e.printStackTrace();\n }\n\n return line;\n }\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n String line = nextLine();\n\n if (line == null)\n return null;\n\n st = new StringTokenizer(line);\n }\n\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n int[] nextIntArray(int n) {\n int[] a = new int[n];\n\n for (int i = 0; i < n; i++)\n a[i] = nextInt();\n\n return a;\n }\n\n long[] nextLongArray(int n) {\n long[] a = new long[n];\n\n for (int i = 0; i < n; i++)\n a[i] = nextLong();\n\n return a;\n }\n\n void close() {\n try {\n br.close();\n\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n }\n\n private static class OutputWriter {\n\n BufferedWriter bw;\n\n OutputWriter(OutputStream os) {\n bw = new BufferedWriter(new OutputStreamWriter(os));\n }\n\n void print(int i) {\n print(Integer.toString(i));\n }\n\n void println(int i) {\n print(i);\n print('\\n');\n }\n\n void print(long l) {\n print(Long.toString(l));\n }\n\n void println(long l) {\n print(l);\n print('\\n');\n }\n\n void print(double d) {\n print(Double.toString(d));\n }\n\n void println(double d) {\n print(d);\n print('\\n');\n }\n\n void print(boolean b) {\n print(Boolean.toString(b));\n }\n\n void println(boolean b) {\n print(b);\n print('\\n');\n }\n\n void print(char c) {\n try {\n bw.write(c);\n\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n\n void println(char c) {\n print(c);\n print('\\n');\n }\n\n void print(String s) {\n try {\n bw.write(s);\n\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n\n void println(String s) {\n print(s);\n print('\\n');\n }\n\n void close() {\n try {\n bw.close();\n\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "greedy"], "code_uid": "cd2cefb11f8f75b1e7d9340bae54eebe", "src_uid": "042cf938dc4a0f46ff33d47b97dc6ad4", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.*;\r\nimport java.util.*;\r\npublic class B {\r\n static int M = (int)(1e9) + 7;\r\n // 937481864 60\r\n public static long pow(long a, long b) {\r\n long res = 1;\r\n while( b > 0 ) {\r\n if( b % 2 == 1 ) res *= a;\r\n res %= M;\r\n a *= a;\r\n a %= M;\r\n b /= 2;\r\n }\r\n return res % M;\r\n }\r\n\r\n public static long solve(int k) {\r\n long ans = 6;\r\n long nodes = (1L<0 ) {\r\n int k = Integer.parseInt(br.readLine());\r\n\r\n System.out.println(solve(k));\r\n } \r\n }\r\n}\r\n", "lang_cluster": "Java", "tags": ["math", "combinatorics"], "code_uid": "6f4bf2b6cd72a09d500514d90fc4e20c", "src_uid": "5144b9b281ea4087d8334d91c3c8bda4", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n\npublic class eduA {\npublic static void main(String[] args) throws IOException {\n\tBufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n\tString [] s = bf.readLine().split(\" \");\n\tString [] s1 = bf.readLine().split(\" \") ; \n\tint n [] = new int [4] ; \n\tn[0] = Integer.parseInt(s[0]) ; \n\tn[1] = Integer.parseInt(s1[0]) ; \n\tn[2] = Integer.parseInt(s[1]);\n\tn[3] = Integer.parseInt(s1[1]) ; \n\tint n1 = Math.abs(n[1]- n[0]) ; \n\t\n\tint n2 = Math.abs(n[3]- n[2]);\n\t\n\t\t\tint answer = Math.max(n1, n2) ;\n\t\t\tSystem.out.println(answer);\n}\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "d89f92acdb596387098027beb4fcdc30", "src_uid": "a6e9405bc3d4847fe962446bc1c457b4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Hieu Le\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskC {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int a = in.nextInt();\n int b = in.nextInt();\n int c = in.nextInt();\n int l = in.nextInt();\n long res = choose(l + 3, 3) - count(a, b, c, l) - count(b, c, a, l) - count(c, a, b, l);\n out.println(res);\n }\n\n private long count(int a, int b, int c, int l) {\n int low = Math.max(c, a + b);\n int high = c + l;\n long res = 0;\n for (int i = low; i <= high; i++) {\n int max = Math.min(i - a - b, l - i + c);\n if (max >= 0) res += choose(max + 2, 2);\n }\n return res;\n }\n\n private long choose(int n, int k) {\n long res = 1;\n for (int i = 1; i <= k; i++)\n res = res * (n - i + 1) / i;\n return res;\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["brute force", "math", "dp", "combinatorics"], "code_uid": "3900c71ae38846737d441128b1e4ffe4", "src_uid": "185ff90a8b0ae0e2b75605f772589410", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\npublic class Cakeminator {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\t\n\t\tString s = sc.nextLine();\n\t\tint cnt=0;\n\t\t\n\t\tfor (int i=0;i<26;i++){\n\t\t\tif(s.indexOf('a'+i)!=-1)\n\t\t\t\tcnt++;\n\t\t}\n\t\tSystem.out.println(cnt%2==1?\"IGNORE HIM!\":\"CHAT WITH HER!\");\n\t\t\n\t}\n}", "lang_cluster": "Java", "tags": ["brute force", "strings", "implementation"], "code_uid": "cc545b416b72b8bd05321a23cc655214", "src_uid": "a8c14667b94b40da087501fd4bdd7818", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class CFA {\n\tstatic int a,b,ta,tb,c,d,s,ans;\n\tstatic String ss;\n\tpublic static void main(String args[]) {\n\t\tScanner in=new Scanner(System.in);\n\t\ta=in.nextInt();ta=in.nextInt();\n\t\tb=in.nextInt();tb=in.nextInt();\n\t\tss=in.next();\n\t\tc=Integer.parseInt(ss.substring(0,2));\n\t\td=Integer.parseInt(ss.substring(3,5));\n\t\ts=c*60+d-5*60;\n\t\tc=(s+ta)/b+1;\n\t\tif(s18*60+59) c=(18*60+59)/b+1;\n\t\tans=c-d;\n\t\tSystem.out.println(ans);\n\t}\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "30b16b4de91b9e6b7c274a569672b359", "src_uid": "1c4cf1c3cb464a483511a8a61f8685a7", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\n\nimport java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.util.ArrayList;\nimport java.util.Collections;\n\npublic class CFChess {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\t// TODO Auto-generated method stub\n\t\tBufferedReader buff = new BufferedReader(new InputStreamReader(System.in));\n\t\tBufferedWriter wr = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\tbyte[][] arr = new byte[8][8];\n\t\tArrayList white = new ArrayList<>();\n\t\tArrayList black = new ArrayList<>();\n\t\tString[] inputs;\n\t\tbyte k=0,l=0;\n\t\tfor(int i=0;i<8;i++){\n\t\t\tinputs = buff.readLine().split(\"\");\n\t\t\tfor(int j=0;j<8;j++){\n\t\t\t\tif(inputs[j].equals(\".\"))\n\t\t\t\t\tarr[i][j] = 0;\n\t\t\t\telse if(inputs[j].equals(\"W\")){\n\t\t\t\t\tarr[i][j] = 1;\n\t\t\t\t\twhite.add((byte)i);\n\t\t\t\t}\n\t\t\t\telse if(inputs[j].equals(\"B\")){\n\t\t\t\t\tarr[i][j] = 2;\n\t\t\t\t\tblack.add((byte)i);\n\t\t\t\t}\n\t\t\t\t\t\n\t\t\t}\t\t\t\n\t\t}\t\t\n\t\tCollections.sort(white);\n\t\tCollections.sort(black);\n\t\tboolean whiteflag = false,blackflag = false;\n\t\tbyte whiteMax = 127,blackMax = 127;\n\t\tfor(int size= 0;size=0;i--){\n\t\t\t\tif(arr[i][col]==2 || arr[i][col]==22){\n\t\t\t\t\twhiteflag = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif(!whiteflag){\n\t\t\t\twhiteMax = (byte)(row -(byte)0); \n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor(int size= black.size()-1;size>-1;size--){\n\t\t\tblackflag = false;\n\t\t\tint row = black.get(size) ;\n\t\t\tint col = -1;\n\t\t\tfor(int i=0;i<8;i++){\n\t\t\t\tif(arr[row][i]==2){\n\t\t\t\t\tcol = i;\n\t\t\t\t\tarr[row][i] = 22;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor(int i=row;i<8;i++){\n\t\t\t\tif(arr[i][col]==1 || arr[i][col]==11){\n\t\t\t\t\tblackflag = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif(!blackflag){\n\t\t\t\tblackMax = (byte)((byte)7-row);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif(whiteMax<=blackMax){\n\t\t\twr.write(\"A\");\n\t\t}\n\t\telse{\n\t\t\twr.write(\"B\");\n\t\t}\t\t\n\t\twr.flush();\n\t\twr.close();\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "acf7fbaf5e7bdd1c47da69e23259bfc8", "src_uid": "0ddc839e17dee20e1a954c1289de7fbd", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": " import java.io.*;\n import java.text.*;\n import java.util.*;\n import java.util.regex.*;\n\n public class Main{\n static class Run implements Runnable{\n //TODO parameters\n final boolean consoleIO = true;\n final String inFile = \"input.txt\";\n final String outFile = \"output.txt\";\n \n int[] s;\n boolean[] b;\n Vector simple;\n HashSet hs;\n \n void gen(int n) {\n s = new int[n+1];\n b = new boolean[n+1];\n \n for(int i = 2; i < s.length; ++i)\n s[i] = i;\n \n boolean exit = false;\n int p = 1;\n while(!exit) {\n boolean find = false;\n for(int i = p+1; i < s.length; ++i)\n if(b[i] == false) {\n p = i;\n find = true;\n break;\n }\n \n if(!find) {\n exit = true;\n break;\n }\n \n int j = 2;\n int k = p*j;\n while(k < s.length) {\n b[k] = true;\n ++j;\n k = p*j;\n }\n }\n \n simple = new Vector();\n hs = new HashSet();\n for(int i = 2; i < s.length; ++i)\n if(!b[i]) {\n simple.add(i);\n hs.add(i);\n }\n }\n \n @Override\n public void run() {\n int n = nextInt();\n int k = nextInt();\n gen(1000);\n \n int sz = simple.size();\n int count = 0;\n \n for(int i = 0; i < sz-1; ++i) {\n int a = simple.get(i);\n int b = simple.get(i+1);\n int c = a + b + 1;\n \n if(c <= n) {\n if(hs.contains(c))\n ++count;\n }\n else\n break;\n }\n \n print(count >= k ? \"YES\" : \"NO\");\n close();\n }\n //=========================================================================================================================\n BufferedReader in;\n PrintWriter out;\n StringTokenizer strTok;\n \n Run() {\n if (consoleIO) {\n initConsoleIO();\n }\n else {\n initFileIO();\n }\n }\n \n void initConsoleIO() {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(new OutputStreamWriter(System.out));\n }\n \n void initFileIO() {\n try {\n in = new BufferedReader(new FileReader(inFile));\n out = new PrintWriter(new FileWriter(outFile));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n \n void close() {\n try {\n in.close();\n out.close();\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n \n int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n \n float nextFloat() {\n return Float.parseFloat(nextToken());\n }\n \n long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n String nextLine() {\n try {\n return in.readLine();\n } catch (IOException e) {\n return \"__NULL\";\n }\n }\n \n boolean hasMoreTokens() {\n return (strTok == null) || (strTok.hasMoreTokens());\n }\n \n String nextToken() {\n while (strTok == null || !strTok.hasMoreTokens()) {\n String line;\n try {\n line = in.readLine();\n strTok = new StringTokenizer(line);\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n \n return strTok.nextToken();\n }\n \n void cout(Object o){\n System.out.println(o);\n }\n \n void print(Object o) {\n out.write(o.toString());\n }\n \n void println(Object o) {\n out.write(o.toString() + '\\n');\n }\n \n void printf(String format, Object... args) {\n out.printf(format, args);\n }\n \n String sprintf(String format, Object... args) {\n return MessageFormat.format(format, args);\n }\n }\n \n static class Pair {\n A a;\n B b;\n \n A f() {\n return a;\n }\n \n B s() {\n return b;\n }\n \n Pair(A a, B b) {\n this.a = a;\n this.b = b;\n }\n \n Pair(Pair p) {\n a = p.f();\n b = p.s();\n }\n }\n \n public static void main(String[] args) throws IOException {\n Run run = new Run();\n Thread thread = new Thread(run);\n thread.run();\n }\n }", "lang_cluster": "Java", "tags": ["brute force", "math", "number theory"], "code_uid": "fc6542ccd2dbef910255416405ba17f2", "src_uid": "afd2b818ed3e2a931da9d682f6ad660d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\nimport java.util.Arrays;\n\npublic class Main {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n int n = Integer.parseInt(scanner.nextLine());\n String s = scanner.nextLine();\n scanner.close();\n char a[] = s.substring(0, n).toCharArray();\n char b[] = s.substring(n).toCharArray();\n Arrays.sort(a);\n Arrays.sort(b);\n boolean able = true;\n for(int i = 0; i < a.length; i++){\n if(a[i] <= b[i]){\n able = false;\n }\n }\n if(able){\n System.out.println(\"YES\");\n return;\n }\n able = true;\n for(int i = 0; i < b.length; i++){\n if(a[i] >= b[i]){\n able = false;\n }\n }\n System.out.println(able ? \"YES\" : \"NO\");\n }\n}", "lang_cluster": "Java", "tags": ["sortings", "greedy"], "code_uid": "0af3bfb4c70d6d1fa7d3e4fcbc805132", "src_uid": "e4419bca9d605dbd63f7884377e28769", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "\nimport java.util.Scanner;\n\npublic class A {\n\n public static void main(String[] args) {\n System.out.println(((new Scanner(System.in)).nextInt() >> 1) * 3);\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "number theory"], "code_uid": "df0ec3375f0e91f599f88ae6adb8d707", "src_uid": "031e53952e76cff8fdc0988bb0d3239c", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class B_116_Little_Pigs_and_Wolves {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tchar grid[][] = new char[n][m];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tString s = sc.next();\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tgrid[i][j] = s.charAt(j);\n\t\t\t}\n\t\t}\n\t\tint count = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tif ((grid[i][j] == 'W')\n\t\t\t\t\t\t&& ((i > 0 && grid[i - 1][j] == 'P')\n\t\t\t\t\t\t\t\t|| (j > 0 && grid[i][j - 1] == 'P')\n\t\t\t\t\t\t\t\t|| (i < n - 1 && grid[i + 1][j] == 'P')\n\t\t\t\t\t\t\t\t|| (j < m - 1 && grid[i][j + 1] == 'P'))) {\n\t\t\t\t\tcount++;\n\t\t\t\t}\n\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(count);\n\t}\n}\n", "lang_cluster": "Java", "tags": ["greedy", "implementation"], "code_uid": "ad98aa0962cc83aa92c73a82d8fedc6b", "src_uid": "969b24ed98d916184821b2b2f8fd3aac", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.HashSet;\n\npublic class Cp {\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\tString readLine = br.readLine();\n\t\tString[] split = readLine.split(\" \");\n\t\tint vert=Integer.parseInt(split[0]);\n\t\tint edge=Integer.parseInt(split[1]);\n\t\tint connect[]=new int[vert];\n\t\tint graph[][]=new int[vert][vert];\n\t\tint max=0;\n\t\tint cnt[]=new int[vert];\n\t\tfor (int i = 0; i < edge; i++) {\n\t\t\treadLine = br.readLine();\n\t\t\tsplit = readLine.split(\" \");\n\t\t\tint t=Integer.parseInt(split[0]);\n\t\t\tint t2=Integer.parseInt(split[1]);\n\t\t\tconnect[t-1]++;\n\t\t\tconnect[t2-1]++;\n\t\t\t\n\t\t\tgraph[t-1][t2-1]=1;\n\t\t\tgraph[t2-1][t-1]=1;\n\t\t}\n\t\tHashSet hs=new HashSet();\n\t\tif(vert<=6) {\n\t\t\tSystem.out.println(edge);\n\t\t\tSystem.exit(0);\n\t\t}else {\n\t\t\tfor (int i = 0; i < cnt.length; i++) {\n\t\t\t\tfor (int j = i+1; j < cnt.length; j++) {\n\t\t\t\t\t\n\t\t\t\t\tcnt[i]=0;\n\t\t\t\t\tcnt[j]=0;\t\t\n\t\t\t\t\tint a=1;\n\t\t\t\t\tint count=0;\n\t\t\t\t\tfor (int j2 = 0; j2 < cnt.length; j2++) {\n\t\t\t\t\t\tif(j2!=i&&j2!=j) {\n\t\t\t\t\t\t\tcnt[j2]=a;\n\t\t\t\t\t\t\ta++;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tfor (int k = 0; k < cnt.length; k++) {\n\t\t\t\t\t\tfor (int k2 = 0; k2 < cnt.length; k2++) {\n\t\t\t\t\t\t\tif(cnt[k]!=0&&cnt[k2]!=0) {\n\t\t\t\t\t\t\t\tif(graph[k][k2]==1&&k!=k2) {\n\t\t\t\t\t\t\t\t\tcount++;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tcount=count/2;\n\t\t\t\n\t\t\t\t\tif(connect[i]>connect[j]) {\n\t\t\t\t\t\tfor (int k = 0; k < cnt.length; k++) {\n\t\t\t\t\t\t\tif(graph[i][k]!=1&&graph[j][k]==1&&k!=i) {\n\t\t\t\t\t\t\t\tcount++;\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcount=count+connect[i];\n\t\t\t\t\t}else {\n\t\t\t\t\t\tfor (int k = 0; k < cnt.length; k++) {\n\t\t\t\t\t\t\tif(graph[j][k]!=1&&graph[i][k]==1&&k!=j) {\n\t\t\t\t\t\t\t\tcount++;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcount=count+connect[j];\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\n\t\t\t\t\tif(count>max) {\n\t\t\t\t\t\tmax=count;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tcnt[i]=0;\n\t\t\t\t\tcnt[j]=0;\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println(max);\n\t\t}\n\t\t\n\t\t\n\t}\n}\n\n\n\n", "lang_cluster": "Java", "tags": ["brute force", "graphs"], "code_uid": "fd10abeb0e5a5a7bd72185df7c48dd95", "src_uid": "11e6559cfb71b8f6ca88242094b17a2b", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.Scanner;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author @zhendeaini6001\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tScanner in = new Scanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n String input = in.next();\n int res = -1;\n int first = 0;\n String max = \"1000000\";\n for (int second = 1; second < input.length(); ++second){\n for (int third = second + 1; third < input.length(); ++third){\n if (second - first > 7 || third - second > 7 || input.length() - third > 7){\n continue;\n }\n if (second - first == 7 && !input.substring(first, second).equals(max)) {\n continue;\n }\n if (third - second == 7 && !input.substring(second, third).equals(max)){\n continue;\n }\n if (input.length() - third == 7 && !input.substring(third).equals(max)){\n continue;\n }\n if (input.charAt(first) == '0' && second != 1){\n continue;\n }\n if (input.charAt(second) == '0' && third != second + 1){\n continue;\n }\n if (input.charAt(third) == '0' && third != input.length() - 1){\n continue;\n }\n int val = Integer.valueOf(input.substring(first, second) ) + Integer.valueOf(input.substring(second, third) )+ Integer.valueOf(input.substring(third) );\n res = Math.max(val, res);\n }\n }\n out.println(res);return;\n }\n}\n\n", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "84d23292870bec45aeb2322379b1853e", "src_uid": "bf4e72636bd1998ad3d034ad72e63097", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\n\n\npublic class A655 {\n\n\tprivate static boolean home = !\"true\".equals(System.getProperty(\"ONLINE_JUDGE\"));\n\tprivate static boolean debug = false;\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tint nrTeste = 2;\nString[] inputs = {\"AB\\nXC\\nXB\\nAC\\n\", \"AB\\nXC\\nAC\\nBX\\n\"};\nString[] expected = {\"YES\\n\", \"NO\\n\"};\n\t\tfor (int i = 0; home && i < nrTeste; i++) {\n\t\t\tSystem.out.print(\"\\nExpect: \" + expected[i] + \"\\n Got: \");\n\t\t\tSystem.setIn(new ByteArrayInputStream(inputs[i].getBytes()));\n\t\t\tsolve();\n\t\t}\n\t\tif (!home) {\n\t\t\tsolve();\n\t\t}\n\t\tSystem.out.close();\n\t}\n\t\n\tpublic static void solve() throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\tString line1 = br.readLine();\n\t\tString s = br.readLine();\n\t\tline1 = line1 + s.charAt(1) + s.charAt(0);\n\t\tif (home) {\n\t\t\tSystem.out.println(line1);\n\t\t}\n\t\twhile(line1.charAt(0) != 'X') {\n\t\t\tline1 = line1.substring(1) + line1.charAt(0);\n\t\t}\n\t\tif (home) {\n\t\t\tSystem.out.println(line1);\n\t\t}\n\t\tString line2 = br.readLine();\n\t\ts = br.readLine();\n\t\tline2 = line2 + s.charAt(1) + s.charAt(0);\n\t\twhile(line2.charAt(0) != 'X') {\n\t\t\tline2 = line2.substring(1) + line2.charAt(0);\n\t\t}\n\t\tif (home) {\n\t\t\tSystem.out.println(line2);\n\t\t}\n\t\tboolean yes = false;\n\t\tfor (int i = 0; i< 4; i++) {\n\t\t\tif (line1.equals(line2)){\n\t\t\t\tpw.println(\"YES\");\n\t\t\t\tyes = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tline2 = 'X' + line2.substring(2) + line2.charAt(1);\n\t\t\tif (home) {\n\t\t\t\tSystem.out.println(line2);\n\t\t\t\t\n\t\t\t}\n\t\t}\n\t\tif (!yes) {\n\t\t\tpw.println(\"NO\");\n\t\t\t\n\t\t}\n\t\tbr.close();\n\t\tpw.flush();\n\t}\n\t\n}\n", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "2531b2c3050d9b31238e424fb77c918e", "src_uid": "46f051f58d626587a5ec449c27407771", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "\nimport java.io.*;\nimport java.util.*;\n\npublic class cfProblem {\n\n\tpublic static void main(String[] args) throws Exception {\n\t\texecute();\n\t}\n\t\n\tpublic static void execute() throws Exception\n\t{\n\t\tString s = nextString();\n\t\tString l = \"><+-.,[]\";\n\t\tint sum = 0;\n\t\tfor (int i = 0; i < s.length(); i++) {\n\t\t\tfor (int j = 0; j < l.length(); j++) {\n\t\t\t\tif (s.charAt(i) == l.charAt(j)) {\n\t\t\t\t\tsum = (sum * 16 + (8 + j)) % 1000003;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twrite(sum);\n\t}\n\t\n static BufferedReader jin = new BufferedReader(new InputStreamReader(System.in));\n static StringTokenizer st;\n \n static String nextToken() throws IOException {\n while (st == null || !st.hasMoreTokens()) {\n String line = jin.readLine();\n if (line == null) {\n return null;\n }\n st = new StringTokenizer(line);\n }\n return st.nextToken();\n }\n \n static void write(Object... s) {\n \tfor (Object ss : s)\n \t\tSystem.out.print(String.valueOf(ss));\n }\n \n static int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n \n static String nextString() throws IOException {\n return (String)nextToken();\n }\n \n static long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n \n static double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "661a307f3a78bd2f67b8b2d660ae7cd4", "src_uid": "04fc8dfb856056f35d296402ad1b2da1", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\n \n \npublic class Main{\nstatic int mod = (int)(Math.pow(10, 9) + 7);\n\n\n\n public static void main(String[] args) {\n MyScanner sc = new MyScanner();\n out = new PrintWriter(new BufferedOutputStream(System.out));\n long n = sc.nextLong();\n long b= sc.nextLong();\n //b = pow(10,9)+7;\n \n HashMap pf = new HashMap();\n for (long i = 2; i * i <= b; i++) {\n \t long t = 0;\n \t while (b % i == 0) {\n \t\t b /= i;\n \t\t t++;\n \t }\n \t if (t > 0) {\n \t\t pf.put(i, t);\n \t }\n }\n if (b > 1) {\n \t pf.put(b, (long) 1);\n } \n long maxSum = Long.MAX_VALUE;\n for (Map.Entry e: pf.entrySet()) {\n \t \tlong p = e.getKey();\n \t \tlong t = e.getValue();\n \t \tlong temp = n;\n \t long sum = 0;\n \t while (temp> 0) {\n \t\t sum += temp/=p;\n \t }\n \t maxSum = Long.min(maxSum, sum/t);\n }\n \t \n \t out.println(maxSum);\n\n \t \n \t out.close();\n }\n \n static long pow(long a, long N) {\n\t if (N == 0) return 1;\n\t else if (N == 1) return a;\n\t else {\n\t\t long R = pow(a,N/2);\n\t\t if (N % 2 == 0) {\n\t\t\t return R*R;\n\t\t }\n\t\t else {\n\t\t\t return R*R*a;\n\t\t }\n\t }\n }\n \n static long powMod(long a, long N) {\n\t if (N == 0) return 1;\n\t else if (N == 1) return a % mod;\n\t else {\n\t\t long R = powMod(a,N/2) % mod;\n\t\t R *= R % mod;\n\t\t if (N % 2 == 1) {\n\t\t\t R *= a % mod;\n\t\t }\n\t\t\t return R % mod;\n\t }\n }\nstatic void mergeSort(int[] A){ // low to hi sort, single array only\n int n = A.length;\n if (n < 2) return;\n int[] l = new int[n/2];\n int[] r = new int[n - n/2];\n \n for (int i = 0; i < n/2; i++){\n l[i] = A[i];\n }\n \n for (int j = n/2; j < n; j++){\n r[j-n/2] = A[j];\n }\n \n mergeSort(l);\n mergeSort(r);\n merge(l, r, A);\n }\n \n static void merge(int[] l, int[] r, int[] a){\n int i = 0, j = 0, k = 0;\n while (i < l.length && j < r.length && k < a.length){\n if (l[i] < r[j]){\n a[k] = l[i];\n i++;\n }\n else{\n a[k] = r[j];\n j++;\n }\n k++;\n }\n while (i < l.length){\n a[k] = l[i];\n i++;\n k++;\n }\n \n while (j < r.length){\n a[k] = r[j];\n j++;\n k++;\n }\n }\n\n \n\n //-----------PrintWriter for faster output---------------------------------\n public static PrintWriter out;\n \n //-----------MyScanner class for faster input----------\n public static class MyScanner {\n BufferedReader br;\n StringTokenizer st;\n \n public MyScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n \n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n int nextInt() {\n return Integer.parseInt(next());\n }\n \n long nextLong() {\n return Long.parseLong(next());\n }\n \n double nextDouble() {\n return Double.parseDouble(next());\n }\n \n String nextLine(){\n String str = \"\";\n\t try {\n\t str = br.readLine();\n\t } catch (IOException e) {\n\t e.printStackTrace();\n\t }\n\t return str;\n }\n\n }\n //--------------------------------------------------------\n}\n\n\n\n\n\n", "lang_cluster": "Java", "tags": ["brute force", "math", "implementation", "number theory"], "code_uid": "72e328a0e65f975005e82d27d4e6c883", "src_uid": "491748694c1a53771be69c212a5e0e25", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.*;\npublic class C14 {\n\tstatic int[][] grid;\n\tpublic static void main(String[] args)\t{\n\t\tScanner scan = new Scanner(System.in);\n\t\tgrid = new int[4][4];\n\t\tfor(int i = 0; i < 4; i++)\n\t\t\tfor(int j = 0; j < 4; j++)\n\t\t\t\tgrid[i][j] = scan.nextInt();\n\t\tfix(0);\n\t\tfix(1);\n\t\tfix(2);\n\t\tfix(3);\n\t\tfor(int i = 0; i < 4; i++)\t{\n\t\t\tfor(int j = i+1; j < 4; j++)\t{\n\t\t\t\tif(grid[i][0] != grid[j][0])\n\t\t\t\t\tcontinue;\n\t\t\t\tif(grid[i][1] != grid[j][1])\n\t\t\t\t\tcontinue;\n\t\t\t\tif(grid[i][2] != grid[j][2])\n\t\t\t\t\tcontinue;\n\t\t\t\tif(grid[i][3] != grid[j][3])\n\t\t\t\t\tcontinue;\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tSet x = new HashSet();\n\t\tSet y = new HashSet();\n\t\tx.add(grid[0][0]);\n\t\tx.add(grid[0][2]);\n\t\ty.add(grid[0][1]);\n\t\ty.add(grid[0][3]);\n\t\tx.add(grid[1][0]);\n\t\tx.add(grid[1][2]);\n\t\ty.add(grid[1][1]);\n\t\ty.add(grid[1][3]);\n\t\tx.add(grid[2][0]);\n\t\tx.add(grid[2][2]);\n\t\ty.add(grid[2][1]);\n\t\ty.add(grid[2][3]);\n\t\tx.add(grid[3][0]);\n\t\tx.add(grid[3][2]);\n\t\ty.add(grid[3][1]);\n\t\ty.add(grid[3][3]);\n\t\tif(x.size() != 2 || y.size() != 2)\t{\n\t\t\tSystem.out.println(\"NO\");\n\t\t\treturn;\n\t\t}\n\t\tif((grid[0][0] == grid[0][2]) == (grid[0][1] == grid[0][3]))\t{\n\t\t\tSystem.out.println(\"NO\");\n\t\t\treturn;\n\t\t}\n\t\tif((grid[1][0] == grid[1][2]) == (grid[1][1] == grid[1][3]))\t{\n\t\t\tSystem.out.println(\"NO\");\n\t\t\treturn;\n\t\t}\n\t\tif((grid[2][0] == grid[2][2]) == (grid[2][1] == grid[2][3]))\t{\n\t\t\tSystem.out.println(\"NO\");\n\t\t\treturn;\n\t\t}\n\t\tif((grid[3][0] == grid[3][2]) == (grid[3][1] == grid[3][3]))\t{\n\t\t\tSystem.out.println(\"NO\");\n\t\t\treturn;\n\t\t}\n\t\tSystem.out.println(\"YES\");\n\t}\n\tpublic static void fix(int x)\t{\n\t\tif(grid[x][0] > grid[x][2])\t{\n\t\t\tint x1 = grid[x][0];\n\t\t\tint y1 = grid[x][1];\n\t\t\tint x2 = grid[x][2];\n\t\t\tint y2 = grid[x][3];\n\t\t\tgrid[x][0] = x2;\n\t\t\tgrid[x][1] = y2;\n\t\t\tgrid[x][2] = x1;\n\t\t\tgrid[x][3] = y1;\n\t\t}\n\t\tif(grid[x][0] == grid[x][2] && grid[x][1] > grid[x][3])\t\t{\n\t\t\tint x1 = grid[x][0];\n\t\t\tint y1 = grid[x][1];\n\t\t\tint x2 = grid[x][2];\n\t\t\tint y2 = grid[x][3];\n\t\t\tgrid[x][0] = x2;\n\t\t\tgrid[x][1] = y2;\n\t\t\tgrid[x][2] = x1;\n\t\t\tgrid[x][3] = y1;\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "tags": ["brute force", "constructive algorithms", "math", "implementation", "geometry"], "code_uid": "9af058d167549f7ffa0001733ad5137f", "src_uid": "ad105c08f63e9761fe90f69630628027", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n\npublic class ENC {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st=new StringTokenizer(br.readLine());\n\t\tint a=Integer.parseInt(st.nextToken());\n\t\tint b=Integer.parseInt(st.nextToken());\n\t\tint c=Integer.parseInt(st.nextToken());\n\t\tint total=a*b*c;\n\t\tint[] d=new int[total];\n\t\tfor (int i=0;i= (t - m) * length) {\n w -= (t - m) * length;\n ans += t - m;\n m = t;\n t *= 10;\n length++;\n }\n ans += w / length;\n System.out.println(ans);\n }\n}\n\nclass CustomInputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public CustomInputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation", "binary search"], "code_uid": "d3a7c4adf898afe6dddad22c7de6261e", "src_uid": "8ef8a09e33d38a2d7f023316bc38b6ea", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Problem765C {\n\n public static void main(String[] args) {\n\n Scanner in = new Scanner(System.in);\n\n int k = in.nextInt();\n\n int a = in.nextInt();\n int b = in.nextInt();\n\n if (a > b)\n {\n int temp = a;\n a = b;\n b = temp;\n }\n if (a < k && b < k)\n {\n System.out.println(-1);\n return;\n }\n if (a < k && b % k != 0)\n {\n System.out.println(-1);\n return;\n }\n if (a % k != 0) {\n a -= (a % k);\n }\n if (b % k != 0) {\n b -= (b % k);\n }\n int m = (a+b)/k;\n System.out.println(m);\n }\n}\n ", "lang_cluster": "Java", "tags": ["math"], "code_uid": "ff77b83297b5d64549c03ce531928848", "src_uid": "6e3b8193d1ca1a1d449dc7a4ad45b8f2", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.Scanner;\n\npublic class Vacation {\n static int daysCount;\n static ArrayList vacations = new ArrayList<>();\n static int[][] memoize;\n\n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n daysCount = s.nextInt();\n for (int i = 0; i < daysCount; i++) {\n vacations.add(s.nextInt());\n }\n memoize = new int[daysCount][100];\n for (int i = 0; i < daysCount; i++) {\n for (int j = 0; j < 100; j++) {\n memoize[i][j] = -1;\n }\n }\n System.out.println(getMinimumVacationDays(0, 4));\n\n }\n\n private static int getMinimumVacationDays(int currentDayIndex, int previousDayActivity) {\n if (currentDayIndex == daysCount)\n return 0;\n\n if (memoize[currentDayIndex][previousDayActivity] != -1)\n return memoize[currentDayIndex][previousDayActivity];\n int currentDayActivity = vacations.get(currentDayIndex);\n if (currentDayActivity == 0) {\n return memoize[currentDayIndex][previousDayActivity] = 1 + getMinimumVacationDays(currentDayIndex + 1, 0);\n }\n if (currentDayActivity == 1) {\n int dayWithRest = 1 + getMinimumVacationDays(currentDayIndex + 1, 'R');\n int dayWithContest = Integer.MAX_VALUE;\n if (previousDayActivity != 'C') {\n dayWithContest = getMinimumVacationDays(currentDayIndex + 1, 'C');\n }\n return memoize[currentDayIndex][previousDayActivity] = Math.min(dayWithRest, dayWithContest);\n }\n if (currentDayActivity == 2) {\n int dayWithRest = 1 + getMinimumVacationDays(currentDayIndex + 1, 'R');\n int dayWithGym = Integer.MAX_VALUE;\n if (previousDayActivity != 'G') {\n dayWithGym = getMinimumVacationDays(currentDayIndex + 1, 'G');\n }\n return memoize[currentDayIndex][previousDayActivity] = Math.min(dayWithRest, dayWithGym);\n }\n int dayWithRest = 1 + getMinimumVacationDays(currentDayIndex + 1, 'R');\n int dayWithContest = Integer.MAX_VALUE;\n int dayWithGym = Integer.MAX_VALUE;\n if (previousDayActivity != 'C') {\n dayWithContest = getMinimumVacationDays(currentDayIndex + 1, 'C');\n }\n if (previousDayActivity != 'G') {\n dayWithGym = getMinimumVacationDays(currentDayIndex + 1, 'G');\n }\n return memoize[currentDayIndex][previousDayActivity] = Math.min(dayWithRest, Math.min(dayWithContest, dayWithGym));\n\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "dp"], "code_uid": "3ca4624b8b4b1364929043841927e81d", "src_uid": "08f1ba79ced688958695a7cfcfdda035", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n\n/**\n *\n * @author YaSeR\n */\nimport java.util.Scanner;\npublic class Football1 {\n public static void main(String[] args) {\n Scanner cs = new Scanner(System.in);\n String line = cs.next();\n if(line.contains(\"1111111\") || line.contains(\"0000000\"))\n {\n System.out.println(\"YES\");\n }\n else\n {\n System.out.println(\"NO\");\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["strings", "implementation"], "code_uid": "a842e78cdd80e95c2686ecc1b3c453ac", "src_uid": "ed9a763362abc6ed40356731f1036b38", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.util.Arrays;\npublic class Test1{\n public static void main(String args[])throws IOException{\n Scanner sc=new Scanner(System.in);\n String s[]=new String[3];\n s[0]=sc.next();\n s[1]=sc.next();\n s[2]=sc.next();\n Arrays.sort(s);\n char n1=s[0].charAt(0),n2=s[1].charAt(0),n3=s[2].charAt(0);\n char c1=s[0].charAt(1),c2=s[1].charAt(1),c3=s[2].charAt(1);\n if(c1!=c2 && c2!=c3 && c3!=c1)\n System.out.println(\"2\");\n else if(n1==n2 && n2==n3 && c1==c2 && c2==c3)\n System.out.println(\"0\");\n else if(c1==c2 && c2==c3 && n2==(n1+1) && n3==(n2+1))\n System.out.println(\"0\");\n else if((c1==c2 && n1==n2) || (c2==c3 && n2==n3) || (c1==c3 && n1==n3) || (c1==c2 && n2==n1+1) || (c2==c3 && n3==n2+1) || (c1==c3 && n3==n1+2))\n System.out.println(\"1\");\n else if((c1==c2 && n2==n1+2) || (c2==c3 && n3==n2+2) || (c1==c3 && n3==n1+1))\n System.out.println(\"1\");\n else\n System.out.println(\"2\");\n }\n}\n// || (c1==c2 && n2==n1+1) || (c2==c3 && n3==n2+1) || (c1==c3 && n3==n1+2)", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "dda0262bb1c53273b132787534ac3557", "src_uid": "7e42cebc670e76ace967e01021f752d3", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": " import java.util.*;\n import java.io.*;\n\n public class Codeforces {\n \n public static void main(String[] args) throws IOException {\n Reader.init(System.in);\n \n long a = Reader.nextLong();\n long b = Reader.nextLong();\n gcd(Math.max(a, b), Math.min(a, b));\n System.out.println(count);\n }\n \n static long count = 0;\n static long gcd(long a, long b){\n if(b == 0)\n return a;\n count += a/b;\n return gcd(b, a%b);\n }\n \n }\n \n class Pair implements Comparable{\n\n int id;\n int freq;\n int x;\n \n Pair(int a, int b){\n id = a;\n x = b;\n }\n\n @Override\n public int compareTo(Pair t) {\n int a = t.freq - freq;\n \n if(a == 0)\n return x - t.x;\n return a;\n }\n }\n\n\n\n\n class Reader {\n\n static BufferedReader reader;\n static StringTokenizer tokenizer;\n\n public static int pars(String x) {\n int num = 0;\n int i = 0;\n if (x.charAt(0) == '-') {\n i = 1;\n }\n for (; i < x.length(); i++) {\n num = num * 10 + (x.charAt(i) - '0');\n }\n\n if (x.charAt(0) == '-') {\n return -num;\n }\n\n return num;\n }\n\n static void init(InputStream input) {\n reader = new BufferedReader(\n new InputStreamReader(input));\n tokenizer = new StringTokenizer(\"\");\n }\n\n static void init(FileReader input) {\n reader = new BufferedReader(input);\n tokenizer = new StringTokenizer(\"\");\n }\n\n static String next() throws IOException {\n while (!tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(\n reader.readLine());\n }\n return tokenizer.nextToken();\n }\n\n static int nextInt() throws IOException {\n return pars(next());\n }\n\n static long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n static double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n }", "lang_cluster": "Java", "tags": ["math", "number theory"], "code_uid": "69951501cc2fdc7b70d03277656fb671", "src_uid": "792efb147f3668a84c866048361970f8", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.io.UnsupportedEncodingException;\nimport java.io.Writer;\nimport java.text.DecimalFormat;\nimport java.util.StringTokenizer;\n\npublic class B implements Runnable {\n private final static long START_TIME=System.currentTimeMillis();\n private final static boolean LOG_ENABLED=true;\n private final static boolean ONLINE_JUDGE = LOG_ENABLED && (System.getProperty(\"ONLINE_JUDGE\") != null);\n private final static String SYSTEM_ENCODING=\"utf-8\";\n private final static int DEFAULT_BUFFER_SIZE=100000;\n\n\n private static class Logger{\n private final PrintWriter logWriter=Util.newPrintWriter(System.err,true);\n private final DecimalFormat df=new DecimalFormat(\"0.000\");\n private void message(String type, String message, Object ... params){\n if(ONLINE_JUDGE){\n return;\n }\n logWriter.printf(\"[\"+type+\"] \"+df.format((System.currentTimeMillis()-START_TIME)/1000.0)+\": \"+message+\"\\r\\n\", params);\n }\n public void debug(String message, Object ... params){\n message(\"DEBUG\", message, params);\n }\n }\n\n public final static class Util{\n public final static String LINE_SEPARATOR=System.getProperty(\"line.separator\"); \n public static PrintWriter newPrintWriter(OutputStream out, boolean autoFlush){\n try {\n return new PrintWriter(new OutputStreamWriter(new BufferedOutputStream(out), SYSTEM_ENCODING),autoFlush);\n } catch (UnsupportedEncodingException e) {\n throw new IllegalStateException(e);\n }\n }\n \n public static PrintWriter newPrintWriter(Writer writer, boolean autoFlush){\n return new PrintWriter(writer,autoFlush);\n }\n\n \n private static void flushStringBuilder(Writer writer, StringBuilder sb) throws IOException {\n if(sb.length()>DEFAULT_BUFFER_SIZE){\n writer.append(sb);\n sb.setLength(0);\n }\n }\n\n public static void printArray(Writer writer, Object ... elements) throws IOException{\n StringBuilder sb = new StringBuilder();\n boolean first=true;\n for(Object o:elements){\n if(first){\n first=false;\n }else{\n sb.append(\" \");\n }\n sb.append(o);\n flushStringBuilder(writer, sb);\n }\n sb.append(LINE_SEPARATOR);\n writer.append(sb);\n }\n public static void printArray(Writer writer, int ... elements) throws IOException{\n StringBuilder sb = new StringBuilder();\n boolean first=true;\n for(Object o:elements){\n if(first){\n first=false;\n }else{\n sb.append(\" \");\n }\n sb.append(o);\n flushStringBuilder(writer, sb);\n }\n sb.append(LINE_SEPARATOR);\n writer.append(sb);\n }\n\n }\n\n public final static class FastScanner{\n private BufferedReader reader;\n private StringTokenizer currentTokenizer;\n public FastScanner(Reader reader) {\n if(reader instanceof BufferedReader){\n this.reader=(BufferedReader) reader;\n }else{\n this.reader=new BufferedReader(reader);\n }\n }\n\n public String next(){\n if(currentTokenizer==null || !currentTokenizer.hasMoreTokens()){\n try {\n currentTokenizer=new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new IllegalStateException(e);\n }\n }\n\n return currentTokenizer.nextToken();\n }\n public int nextInt(){\n return Integer.parseInt(next());\n }\n\n public long nextLong(){\n return Long.parseLong(next());\n }\n\n public double nextDouble(){\n return Double.parseDouble(next());\n }\n\n }\n\n private final static Logger log=new Logger();\n private final BufferedReader reader;\n private final FastScanner in;\n private final PrintWriter out;\n\n\n public B(Reader reader, Writer writer){\n this.reader=new BufferedReader(reader);\n this.out=new PrintWriter(writer,false);\n in=new FastScanner(this.reader);\n }\n\n public static void main(String[] args) throws IOException {\n new B(new InputStreamReader(System.in, SYSTEM_ENCODING),new OutputStreamWriter(new BufferedOutputStream(System.out), SYSTEM_ENCODING)).run();\n }\n\n public void run(){\n log.debug(\"Started\");\n try{\n solve();\n out.flush();\n }finally{\n log.debug(\"Stopped\");\n }\n }\n\n private void solve(){\n int mx = in.nextInt(); \n int my = in.nextInt();\n int px = in.nextInt(); \n int py = in.nextInt();\n int p;\n int q;\n if(1.0*mx/my>1.0*px/py){\n p=mx*py-px*my;\n q=mx*py;\n }else{\n p=my*px-py*mx;\n q=my*px;\n }\n int nod = findNode(p,q);\n out.println(p/nod+\"/\"+q/nod);\n }\n static int findNode(int a, int b){\n int maxNod = Math.min(a, b);\n if(maxNod==0){\n return Math.max(a, b);\n }\n for(int nod=2;nod<=maxNod; nod++){\n if((a%nod==0)&& (b%nod)==0){\n return nod*findNode(a/nod, b/nod);\n }\n }\n return 1;\n }\n \n\n}\n", "lang_cluster": "Java", "tags": ["math", "greedy", "number theory"], "code_uid": "3dd9888c1954b27afa5ef91e9c7ad9fc", "src_uid": "b0f435fc2f7334aee0d07524bc37cb1e", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\nimport java.lang.*;\npublic class Main\n{\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint f = sc.nextInt();\n\t\tint r = sc.nextInt();\n\t\tint c = sc.nextInt();\n\t\tint min = Math.min(f/3,Math.min(r/2,c/2));\n\t\tint x = 0;\n\t\tif(min==f/3){\n\t\t x = f/3;\n\t\t f = f - 3*x;\n\t\t r = r - 2*x;\n\t\t c = c - 2*x;\n\t\t}\n\t\telse if(min==r/2){\n\t\t x = r/2;\n\t\t r = r - x*2;\n\t\t f = f - 3*x;\n\t\t c = c - 2*x;\n\t\t}\n\t\telse{\n\t\t x = c/2;\n\t\t c = c - x*2;\n\t\t f = f - 3*x;\n\t\t r = r - 2*x;\n\t\t}\n\t\tif(f>3) f = 3;\n\t\tif(r>2) r = 2;\n\t\tif(c>2) c = 2;\n\t\tint ans = x*7;\n\t\t\n\t\tint max = 0;\n int s[]={1,2,3,1,3,2,1};\n for(int i=0;i<7;i++){\n int f1 = f;\n int r1 = r;\n int c1 = c;\n int co = 0;\n for(int j=i;j<7;j++){\n if(s[j]==1){\n f1--;\n co++;\n if(f1<0) break;\n }\n if(s[j]==2){\n r1--;\n co++;\n if(r1<0) break;\n }\n if(s[j]==3){\n c1--;\n co++;\n if(c1<0) break;\n }\n if(j==6) j=-1;\n }\n max = Math.max(max,co);\n }\n ans = ans+max;\n System.out.println(ans-1);\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "59c0e05e83156a94d12f982ca28abb98", "src_uid": "e17df52cc0615585e4f8f2d31d2daafb", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "public class MainD {\n\tMyScanner sc = new MyScanner();\n\n\tvoid run() {\n\t\tlong n = sc.nextLong();\n\t\tlong m = sc.nextLong();\n\t\tlong k = sc.nextLong();\n\t\tlong right = Long.MAX_VALUE;\n\t\tlong left = 0;\n\t\twhile (right - left > 1) {\n\t\t\tlong mid = (left + right) / 2;\n\t\t\tlong cnt = 0;\n\t\t\tlong w = m;\n\t\t\tfor (int i = 1; i <= n; i++) {\n\t\t\t\twhile (w != 0 && w * i > mid) {\n\t\t\t\t\tw--;\n\t\t\t\t}\n\t\t\t\tcnt += w;\n\t\t\t}\n\t\t\tif (cnt < k) {\n\t\t\t\tleft = mid;\n\t\t\t} else {\n\t\t\t\tright = mid;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(right);\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew MainD().run();\n\t}\n\n\tclass MyScanner {\n\t\tint nextInt() {\n\t\t\ttry {\n\t\t\t\tint c = System.in.read();\n\t\t\t\twhile (c != '-' && (c < '0' || '9' < c))\n\t\t\t\t\tc = System.in.read();\n\t\t\t\tif (c == '-')\n\t\t\t\t\treturn -nextInt();\n\t\t\t\tint res = 0;\n\t\t\t\tdo {\n\t\t\t\t\tres *= 10;\n\t\t\t\t\tres += c - '0';\n\t\t\t\t\tc = System.in.read();\n\t\t\t\t} while ('0' <= c && c <= '9');\n\t\t\t\treturn res;\n\t\t\t} catch (Exception e) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tString next() {\n\t\t\ttry {\n\t\t\t\tStringBuilder res = new StringBuilder(\"\");\n\t\t\t\tint c = System.in.read();\n\t\t\t\twhile (Character.isWhitespace(c))\n\t\t\t\t\tc = System.in.read();\n\t\t\t\tdo {\n\t\t\t\t\tres.append((char) c);\n\t\t\t\t} while (!Character.isWhitespace(c = System.in.read()));\n\t\t\t\treturn res.toString();\n\t\t\t} catch (Exception e) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\n\t\tlong[] nextLongArray(int n) {\n\t\t\tlong[] in = new long[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tin[i] = nextLong();\n\t\t\t}\n\t\t\treturn in;\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "tags": ["brute force", "binary search"], "code_uid": "53feb7516162cf98b18df1e6bb77a1ce", "src_uid": "13a918eca30799b240ceb9de47507a26", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.*;\n\n\n\npublic class bullCow\n{\n\n static int [] countN(int a)\n {\n String s = Integer.toString(a);\n if(s.length() < 4)\n s = \"0000\".substring(0,4-s.length()) + s;\n int [] count = new int[10];\n for(int i=0;i1)\n return false;\n return true;\n }\n \n static boolean match(int m, int [] guess)\n {\n int arr[][] = new int[2][4];\n int nn[] = {m, guess[0]};\n for(int i=0;i<2;i++)\n {\n int a = nn[i];\n for(int j=0;j<4;j++)\n {\n arr[i][j] = a%10;\n a/=10;\n }\n }\n int cows = 0, bulls = 0;\n for(int i=0;i<4;i++)\n for(int j=0;j<4;j++)\n if(arr[0][i] == arr[1][j])\n if(i == j)\n bulls++;\n else\n cows++;\n return (guess[1] == bulls && guess[2] == cows);\n }\n\n\n public static void main(String [] args)\n {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int [][] guess = new int[n][3];\n for(int i=0;i matches = new ArrayList();\n for(int i=100;i<10000;i++)\n {\n if(!check(i))\n continue;\n boolean ok = true;\n for(int j=0;j 1)\n System.out.println(\"Need more data\");\n else\n if(matches.size() == 0)\n System.out.println(\"Incorrect data\");\n else\n {\n String ans = Integer.toString(matches.get(0));\n if(ans.length() < 4)\n ans = \"0000\".substring(0,4-ans.length()) + ans;\n System.out.println(ans);\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "398e1796cb45d836e5ee12b8e06d059f", "src_uid": "142e5f2f08724e53c234fc2379216b4c", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.ArrayList;\nimport java.util.StringTokenizer;\n\n/**\n *\n * @author arif_\n * @date\n * @algo\n * @difficulty\n */\npublic class CF_876C {\n /* START OF I/O ROUTINE */\n // PrintWriter for faster output\n public static PrintWriter out;\n\n // MyInputReader class for faster input\n public static class MyInputReader {\n BufferedReader br;\n StringTokenizer st;\n\n public MyInputReader(InputStream stream) {\n br = new BufferedReader(new InputStreamReader(stream), 32768);\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String nextLine(){\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n } // end of class MyInputReader\n /* END OF I/O ROUTINE */\n\n\n public static void main(String[] args) {\n MyInputReader in = new MyInputReader(System.in);\n out = new PrintWriter(new BufferedOutputStream(System.out));\n\n int n = in.nextInt();\n\n ArrayList ans = new ArrayList();\n for (int i=81; i>=1; i--) {\n if (i >= n) continue;\n\n int x = n - i;\n int sum = 0, y = x;\n while (y > 0) {\n sum += (y % 10);\n y /= 10;\n }\n\n if (sum+x == n) ans.add(x);\n }\n\n out.println(ans.size());\n for (Integer a : ans) {\n out.println(a);\n }\n out.close();\n } // end of method main()\n} // end of class Main", "lang_cluster": "Java", "tags": ["brute force", "math"], "code_uid": "19022bb77b10a26d5642bdcae654dfeb", "src_uid": "ae20ae2a16273a0d379932d6e973f878", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\n\npublic class A {\n\n\tstatic Scanner s = new Scanner(System.in);\n\n\tpublic static void main(String[] args) {\n\n\t\ttry (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {\n\n\t\t\tint n = Integer.parseInt(reader.readLine());\n\t\t\tint m = Integer.parseInt(reader.readLine());\n\n\t\t\tlong ans = 0;\n\t\t\tif(n >= m) ans = m;\n\t\t\telse ans = m % getDeg(m, n);\n\n\t\t\tSystem.out.println(ans);\n\n\t\t} catch(IOException e) {\n\t\t}\n\n\t}\n\n\tstatic long getDeg(int num, int n) {\n\t\tlong ans = 1;\n\n\t\tfor(int i = 0; i < n && ans <= 100_000_000; i++) {\n\t\t\tans += ans;\n\t\t}\n\t\treturn ans;\n\t}\n\n}", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "40c83acbdc3caff11c6a68fce7016f2e", "src_uid": "c649052b549126e600691931b512022f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n FScanner in = new FScanner();\n PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out), true);\n\n void run() {\n int n = in.nextInt();\n int[] a = new int[n];\n for (int i = 0; i < n; i++) {\n int x = in.nextInt();\n a[i] = x;\n }\n out.print(a[0] % 2 != 0 && a[n - 1] % 2 != 0 && n % 2 == 1 ? \n \"Yes\" :\n \"No\");\n out.close();\n }\n\n public static void main(String[] args) {\n new A().run();\n }\n\n static class FScanner {\n BufferedReader br;\n StringTokenizer st;\n\n FScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n\n String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n\n char[][] nextCharArray(int n, int m) {\n char[][] g = new char[n][m];\n for (int i = 0; i < n; i++)\n g[i] = next().toCharArray();\n return g;\n }\n\n double[] nextDoubleArray(int n) {\n double[] a = new double[n];\n for (int i = 0; i < n; i++)\n a[i] = nextDouble();\n return a;\n }\n\n int[] nextIntArray(int n) {\n int[] a = new int[n];\n for (int i = 0; i < n; i++)\n a[i] = nextInt();\n return a;\n }\n\n long[] nextLongArray(int n) {\n long[] a = new long[n];\n for (int i = 0; i < n; i++)\n a[i] = nextLong();\n return a;\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "17bab6a8bcc9f43b5cece555495a74b7", "src_uid": "2b8c2deb5d7e49e8e3ededabfd4427db", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\npublic class timePass {\n\tpublic static void main(String[] args) {\n\t\tScanner s = new Scanner(System.in);\n\t\tint a = s.nextInt();int b = s.nextInt();int x=0,y=0,z=0;\n\t\tfor(int i=1;i<7;i++){\n\t\t\tif(Math.abs(a-i)Math.abs(b-i)){\n\t\t\t\tz++;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(x+\" \"+y+\" \"+z);\n\t}\n}", "lang_cluster": "Java", "tags": ["brute force"], "code_uid": "1f1ca36e21c06b28a5df3ec489e2c34a", "src_uid": "504b8aae3a3abedf873a3b8b127c5dd8", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class A\n{\n public static void main(String[] args)\n {\n int n,m;\n Scanner s = new Scanner(System.in);\n n = s.nextInt();\n m = s.nextInt();\n int a[] = new int[n];\n int b[] = new int[m];\n for(int i = 0 ; i < n ; i++)\n {\n a[i] = s.nextInt();\n }\n for(int j = 0 ; j < m ; j++)\n {\n b[j] = s.nextInt();\n }\n for(int i1 = 0 ; i1 < n ; i1++)\n {\n for(int j1 = 0 ; j1 < m ; j1++)\n {\n if(a[i1] == b[j1])\n {\n System.out.print(a[i1] + \" \");\n }\n }\n }\n }\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "d93eb3e0bdf2a901ba323dfb12b50002", "src_uid": "f9044a4b4c3a0c2751217d9b31cd0c72", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\nimport java.text.*;\npublic class Main\n{\n static FastScanner in = new FastScanner(System.in);\n static StringBuilder sb = new StringBuilder();\n static DecimalFormat df = new DecimalFormat();\n static HashMap lookUp = new HashMap();\n public static int previousA = 0;\n public static void main(String[] args)\n {\n df.setMaximumFractionDigits(20);\n df.setMinimumFractionDigits(20);\n // String formatted = df.format(0.2);\n // Never sort array of primitive type\n // System.out.print(sb.toString());\n int number1 = Integer.parseInt(in.nextToken());\n int number2 = Integer.parseInt(in.nextToken());\n System.out.println(greed(number1, number2));\n }\n\n static int greed(int a, int b){\n int i = 0;\n if(a>b){\n return a-b;\n }\n while(b>a){\n if(b==a){\n return i;\n }\n if(b%2==0){\n b/=2;\n i++;\n continue;\n }\n else {\n b++;\n i++;\n continue;\n }\n }\n\n return a-b+i;\n }\n\n static int closester(int a, int b){\n if(a>=b){\n return a-b; \n }\n boolean bEven = false;\n if(b % 2 == 0){\n bEven = true;\n }\n else{\n bEven = false;\n b+=1;\n }\n int targetAbove = b;\n int targetBelow = 0;\n int i = 0;\n while(targetAbove > a && targetAbove % 2 == 0){\n targetAbove /= 2;\n i++;\n }\n i--;\n targetBelow = targetAbove;\n targetAbove *= 2;\n int below = naive(a, targetBelow, 0);\n lookUp = new HashMap();\n int above = naive(a, targetAbove, 0);\n // int smaller = Math.min(below, above);\n // if(above > below+1){\n // i--;\n // }\n int smaller = above;\n if(bEven){\n return smaller + i;\n }\n else{\n return smaller + i + 1;\n }\n }\n\n static int naive(int a, int b, int c){\n // System.out.println(\"a: \"+a);\n if(a == 0)\n return Integer.MAX_VALUE;\n if(a>=b){\n return a-b+c; \n }\n // if(lookUp.keySet().contains(a)){\n // if(lookUp.keySet())\n // }\n c++;\n int minus = Integer.MAX_VALUE;\n int times = Integer.MAX_VALUE;\n lookUp.put(a,c);\n previousA = a;\n if(!lookUp.keySet().contains(a*2)){\n times = naive(a*2,b,c);\n }\n else{\n if(c<(int)lookUp.get(a*2)){\n lookUp.put(a*2,c);\n times = naive(a*2,b,c);\n }\n if(previousA == b/2){\n return times;\n }\n }\n \n if(!lookUp.keySet().contains(a-1)){\n minus = naive(a-1,b,c);\n }\n else{\n if(c<(int)lookUp.get(a-1)){\n lookUp.put(a-1,c);\n minus = naive(a-1,b,c);\n }\n }\n return Math.min(minus, times);\n }\n\n\n \n\n static BigInteger b(long n) { return BigInteger.valueOf(n);}\n static BigInteger b(String s) { return new BigInteger(s); }\n static BigDecimal bd(double d) { return BigDecimal.valueOf(d);}\n static BigDecimal bd(String s) { return new BigDecimal(s); }\n}\nclass FastScanner\n{\n BufferedReader reader;\n StringTokenizer tokenizer;\n FastScanner (InputStream inputStream)\n {\n reader = new BufferedReader(new InputStreamReader(inputStream));\n }\n String nextToken()\n {\n while (tokenizer == null || ! tokenizer.hasMoreTokens())\n {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (Exception e){}\n }\n return tokenizer.nextToken();\n }\n boolean hasNext()\n {\n if (tokenizer == null || ! tokenizer.hasMoreTokens())\n {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (Exception e){ return false; }\n }\n return true;\n }\n int nextInt()\n {\n return Integer.parseInt(nextToken());\n }\n}\n", "lang_cluster": "Java", "tags": ["dfs and similar", "shortest paths", "math", "graphs", "greedy", "implementation"], "code_uid": "13107fcd07a0af39a7cc565ce345cc7f", "src_uid": "861f8edd2813d6d3a5ff7193a804486f", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class C915 {\n\t@SuppressWarnings(\"unused\")\n\t\n\tpublic static void main(String args[]){\n\t\t@SuppressWarnings(\"resource\")\n\t\tScanner sc = new Scanner(System.in);\n\t\t\n\t\tint n=sc.nextInt();\n\t\tHashMap map= new HashMap();\n\t\t/*\n\t\tfor(int i=1;i<=2500;i++){\n\t\t int a = i;\n\t\t while(a!=0){\n\t\t int t = a%2;\n\t\t a=a/2;\n\t\t sb.append(t);\n\t\t }\n\t\t sb = sb.reverse();\n\t\t map.put(i,sb.toString());\n\t\t \n\t\t}*/\n\t\tHashSet set = new HashSet();\n\t\tint cnt=0;\n\t\tfor(int i=1;i<=n;i++){\n\t\t for(int j=i+1;j<=n;j++){\n\t\t int temp=(i^j);\n\t\t if( temp > 1 && temp <= n && i+j>temp && j+temp>i && temp+i>j && temp>j){\n\t\t cnt++;\n\t\n\t\t }\n\t\t }\n\t\t}\n\t\tSystem.out.println(cnt);\n\t\t \n\t \n\t}\n\t\n\t\n}\n", "lang_cluster": "Java", "tags": ["brute force"], "code_uid": "cba4d9bd3eb537bd93211496e85d1143", "src_uid": "838f2e75fdff0f13f002c0dfff0b2e8d", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Set;\nimport java.util.StringTokenizer;\n\n/**\n * Created by peacefrog on 2/10/16.\n * 12:12 PM\n */\npublic class CF {\n final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n PrintWriter out;\n long timeBegin, timeEnd;\n\n public void runIO() throws IOException {\n timeBegin = System.currentTimeMillis();\n\n InputStream inputStream;\n OutputStream outputStream;\n\n if (ONLINE_JUDGE) {\n inputStream = System.in;\n Reader.init(inputStream);\n outputStream = System.out;\n\n out = new PrintWriter(outputStream);\n } else {\n inputStream = new FileInputStream(\"/home/peacefrog/Dropbox/IdeaProjects/Problem Solving/input\");\n Reader.init(inputStream);\n out = new PrintWriter(System.out);\n }\n solve();\n out.flush();\n out.close();\n timeEnd = System.currentTimeMillis();\n System.err.println(\"Time = \" + (timeEnd - timeBegin));\n }\n\n\t/*\n * Start Solution Here\n\t */\n\n private void solve() throws IOException {\n int n = Reader.nextInt() ;\n long[] arr = Reader.nextLongArray(n);\n long cnt = 0 ;\n Set taken = new HashSet<>();\n Arrays.sort(arr);\n\n for (int i = n-1; i >= 0; i--) {\n if(!taken.contains(arr[i])){\n taken.add(arr[i]);\n cnt+=arr[i];\n }\n else{\n long temp = arr[i];\n while (--temp>0)\n {\n if(!taken.contains(temp)){\n taken.add(temp);\n cnt+=temp;\n break;\n }\n }\n }\n }\n\n out.println(cnt);\n }\n\n public static void main(String[] args) throws IOException {\n new CF().runIO();\n }\n\n static class Reader {\n static BufferedReader reader;\n static StringTokenizer tokenizer;\n\n /**\n * call this method to initialize reader for InputStream\n */\n static void init(InputStream input) {\n reader = new BufferedReader(new InputStreamReader(input));\n tokenizer = new StringTokenizer(\"\");\n }\n\n /**\n * get next word\n */\n static String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n static String nextLine() {\n try {\n return reader.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return \"\";\n }\n\n static int nextChar() throws IOException {\n return reader.read();\n }\n\n static int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n static long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n static double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n static long[] nextLongArray(int n) throws IOException {\n long[] arr = new long[n];\n for (int i = 0; i < n; i++) {\n arr[i] = nextLong();\n }\n\n return arr;\n }\n\n static int[] nextIntArray(int n) throws IOException {\n int[] arr = new int[n];\n for (int i = 0; i < n; i++) {\n arr[i] = nextInt();\n }\n return arr;\n }\n }\n}", "lang_cluster": "Java", "tags": ["sortings", "greedy"], "code_uid": "de3ec9bae04e5ed21eda61d693e00412", "src_uid": "3c4b2d1c9440515bc3002eddd2b89f6f", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.IOException;\n\npublic class Main {\n\tString readLine () { //no buffer-size needed\n\t\tStringBuilder s = new StringBuilder();\n\t\tint car;\n\t\tboolean nochars = true;\n\t\ttry {\n\t\t\twhile(true) {\n\t\t\t\tcar = System.in.read();\n\t\t\t\tif (car < 0 || car == '\\n') break;\n\t\t\t\telse if(car != '\\r') {\n\t\t\t\t\ts.append((char) car);\n\t\t\t\t\tnochars = false;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) { return null; }\n\n\t\tif (car < 0 && nochars) return null;\n\t\treturn s.toString();\n\t}\n\n\tpublic static void main(String[] args){\n\t\tnew Main().begin();\n\t}\n\n\tpublic void begin(){\n\t\tString input = readLine();\n\t\tSystem.out.println(input.replaceAll(\"(http|ftp)(\\\\w+?)ru(\\\\w*)\", \"$1://$2.ru/$3\").replaceAll(\"/$\", \"\"));\n\t}\n}", "lang_cluster": "Java", "tags": ["strings", "implementation"], "code_uid": "d21ccee82b7de745b4c5f95290a667e1", "src_uid": "4c999b7854a8a08960b6501a90b3bba3", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "\nimport java.util.Scanner;\n\n/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n\n/**\n *\n * @author ayushgrg\n */\npublic class compgcd {\n public static void main(String[] args){\n Scanner std = new Scanner(System.in);\n String a = std.next();\n String b = std.next();\n if(a.equals(b)){\n System.out.println(\"\"+a);\n \n }\n else{\n System.out.println(\"1\");\n \n }\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "number theory"], "code_uid": "5faeb8bd236fd68845e76ee07b538717", "src_uid": "9c5b6d8a20414d160069010b2965b896", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.*;\n\npublic class System_of_equation {\n\n\tpublic static void main(String[] args) throws Exception {\n\t\t// TODO Auto-generated method stub\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tString s[] = br.readLine().split(\" \");\n\t\tint n = Integer.parseInt(s[0]);\n\t\tint m = Integer.parseInt(s[1]);\n\t\tint count = 0;\n\t\tfor (int a = 0; a <= n; a++) {\n\t\t\tfor (int b = 0; b <= m; b++) {\n\t\t\t\tif (a * a + b == n && a + b * b == m)\n\t\t\t\t\tcount++;\n\t\t\t}\n\n\t\t}\n\t\tSystem.out.println(count);\n\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["brute force"], "code_uid": "21d70c3ab9c19716795d5f69ff895e29", "src_uid": "03caf4ddf07c1783e42e9f9085cc6efd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\n\npublic class _486A_CalculatingFunction {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\t// TODO Auto-generated method stub\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tBigInteger n = new BigInteger(br.readLine());\n\t\t\n\t\tif (n.remainder(new BigInteger(\"2\")).equals(new BigInteger(\"0\"))) {\n\t\t\tSystem.out.println(n.divide(new BigInteger(\"2\")));\n\t\t} else {\n\t\t\tSystem.out.println(n.divide(new BigInteger(\"2\")).add(new BigInteger(\"1\")).multiply(new BigInteger(\"-1\")));\n\t\t}\n\t\t\n\t\tbr.close();\n\t}\n\n}", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "ca32dd2091400ce30c481950d9383602", "src_uid": "689e7876048ee4eb7479e838c981f068", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n\tpublic static void main(String[] args) throws Throwable\n\t{\n\t\tBufferedReader in = new BufferedReader( new InputStreamReader( System.in ) );\n\t\tStringBuilder sb = new StringBuilder( );\n\t\tfor ( String line; ( line = in.readLine( ) )!=null; ) {\n\t\t\tStringTokenizer st = new StringTokenizer(line);\n\t\t\tString s1 = st.nextToken( );\n\t\t\tString s2 = st.nextToken( );\n\t\t\tint large = Integer.MIN_VALUE;\n\t\t\tfor(int i=0; i<=1000; i++){\n\t\t\t\tint c1=-1;int c2=-1;\n\t\t\t\ttry {c1 = Integer.parseInt(s1,i);} catch (Exception e) {}\n\t\t\t\ttry {c2 = Integer.parseInt(s2,i);} catch (Exception e) {}\n\t\t\t\tif(c1!=-1 && c2 != -1) {\n\t\t\t\t\tString sum = fromDecimal2((c1+c2), i);\n\t\t\t\t\tif(sum.length()>large)\n\t\t\t\t\t\tlarge = sum.length();\n\t\t\t\t}\n\t\t\t}\n\t\t\tsb.append(large+\"\\n\");\t\t\n\t\t}\n\t\tSystem.out.print(new String(sb));\n\t}\n\n\tpublic static String fromDecimal2(int n, int b)\n\t{\n\t\tString chars=\"0123456789ABCDEFGHIJ\";\n\t\tString result=\"\";\n\n\t\twhile(n>0)\n\t\t{\n\t\t\tresult=chars.charAt(n%b) + result;\n\t\t\tn/=b;\n\t\t}\n\n\t\treturn result;\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "07a484f20c970958b88a8a6ed75119ef", "src_uid": "8ccfb9b1fef6a992177cc49bd56fab7b", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.FilterInputStream;\nimport java.io.BufferedInputStream;\nimport java.io.InputStream;\n\n/**\n * @author khokharnikunj8\n */\n\npublic class Main {\n public static void main(String[] args) {\n new Thread(null, new Runnable() {\n public void run() {\n new Main().solve();\n }\n }, \"1\", 1 << 26).start();\n }\n\n void solve() {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n ScanReader in = new ScanReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n DFelicitysBigSecretRevealed solver = new DFelicitysBigSecretRevealed();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class DFelicitysBigSecretRevealed {\n int mod = 1000000007;\n\n public void solve(int testNumber, ScanReader in, PrintWriter out) {\n int n = in.scanInt();\n char[] ar = in.scanChars(n);\n int[][] dp = new int[n + 1][1 << 20];\n long ans = 0;\n int[][] value = new int[n + 1][n + 1];\n for (int i = 0; i <= n; i++) {\n int x = 0;\n for (int j = i; j <= n; j++) {\n value[i][j] = x;\n if (j == n) break;\n x = x * 2 + (ar[j] - '0');\n x = Math.min(x, 21);\n }\n }\n for (int i = 0; i < n; i++) {\n dp[i][0]++;\n for (int j = 0; j < (1 << 20); j++) {\n if (dp[i][j] == 0) continue;\n for (int k = i + 1; k <= n && value[i][k] <= 20; k++) {\n if (value[i][k] != 0) {\n dp[k][(j | (1 << (value[i][k] - 1)))] = (dp[k][(j | (1 << (value[i][k] - 1)))] + dp[i][j]);\n if (dp[k][(j | (1 << (value[i][k] - 1)))] >= mod)\n dp[k][(j | (1 << (value[i][k] - 1)))] -= mod;\n\n }\n }\n }\n for (int j = 1; j <= 20; j++) {\n ans = (ans + dp[i + 1][(1 << j) - 1]);\n if (ans >= mod) ans -= mod;\n }\n }\n out.println(ans);\n\n }\n\n }\n\n static class ScanReader {\n private byte[] buf = new byte[4 * 1024];\n private int index;\n private BufferedInputStream in;\n private int total;\n\n public ScanReader(InputStream inputStream) {\n in = new BufferedInputStream(inputStream);\n }\n\n private int scan() {\n if (index >= total) {\n index = 0;\n try {\n total = in.read(buf);\n } catch (Exception e) {\n e.printStackTrace();\n }\n if (total <= 0) return -1;\n }\n return buf[index++];\n }\n\n public int scanInt() {\n int integer = 0;\n int n = scan();\n while (isWhiteSpace(n)) n = scan();\n int neg = 1;\n if (n == '-') {\n neg = -1;\n n = scan();\n }\n while (!isWhiteSpace(n)) {\n if (n >= '0' && n <= '9') {\n integer *= 10;\n integer += n - '0';\n n = scan();\n }\n }\n return neg * integer;\n }\n\n public char[] scanChars(int n) {\n char[] ar = new char[n];\n int c = scan();\n boolean flag = true;\n while (isWhiteSpace(c)) c = scan();\n ar[0] = (char) c;\n for (int i = 1; i < n; i++) ar[i] = (char) (c = scan());\n return ar;\n }\n\n private boolean isWhiteSpace(int n) {\n if (n == ' ' || n == '\\n' || n == '\\r' || n == '\\t' || n == -1) return true;\n else return false;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["dp", "bitmasks"], "code_uid": "7cb563859b517fa7b1abee4637e01c63", "src_uid": "61f88159762cbc7c51c36e7b56ecde48", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\n\npublic class CodeforcesProblems {\n\t\n\tpublic static void main(String[] arg){\n\t\tScanner sIn = new Scanner(System.in);\n\t\tint count = sIn.nextInt();\n\t\tString str = sIn.next();\n\t\t\n\t\tchar[] chars = str.toCharArray();\n\t\t\n\t\tint changeBits = 0;\n\t\tfor (int i = 0; i < count; i++){\n\t\t\tchars[i] += 1;\n\t\t\tchangeBits++;\n\t\t\tif (chars[i] == '1'){\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(changeBits);\n\t}\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "ee70798eee2621dc0e4a190424c6dd0d", "src_uid": "54cb2e987f2cc06c02c7638ea879a1ab", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\npublic class Factorization {\n\tpublic static boolean check(int n){\n\t\tif(n<=2) return true;\n\t\tboolean checkif = true;\n\t\tfor(int i=2;i N || bal > N/2)\n return 0L;\n else if(len > N/2 && bal > N-len)\n return 0L;\n if(dp[len][bal][take] != -1)\n return dp[len][bal][take];\n long res = 0L;\n if(take == 1)\n {\n if(bal > 0)\n res += dfs(len+1, bal-1, 0);\n if(bal < N/2)\n {\n res += dfs(len+1, bal+1, 0);\n if(res >= MOD) res -= MOD;\n }\n }\n else\n {\n if(bal == 0)\n res = 1+dfs(len+1, bal+1, 1);\n else if(bal == N/2 || (len > N/2 && bal == N-len))\n res = 1+dfs(len+1, bal-1, 1);\n else\n {\n res = 1+dfs(len+1, bal+1, 1)+dfs(len+1, bal-1, 0);\n if(res >= MOD) res -= MOD;\n long temp = 1+dfs(len+1, bal+1, 0)+dfs(len+1, bal-1, 1);\n if(temp >= MOD) temp -= MOD;\n res = Math.max(res, temp); \n }\n }\n if(len == N)\n res = 0;\n return dp[len][bal][take] = res;\n }\n }", "lang_cluster": "Java", "tags": ["greedy", "dp", "trees"], "code_uid": "0d8e041342f60e456af574108d35de23", "src_uid": "8218255989e5eab73ac7107072c3b2af", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\n\n\npublic class A411 {\n\n public static void main(String[] args) {\n \n String p;\n\n Boolean l,u,d;\n l = false; u = false; d = false;\n \n Scanner s = new Scanner(System.in);\n p = s.next();\n\n for(int i=0; i= 'a' && p.charAt(i) <= 'z')\n l = true;\n if(p.charAt(i) >= 'A' && p.charAt(i) <= 'Z')\n u = true;\n if(p.charAt(i) >= '0' && p.charAt(i) <= '9')\n d = true;\n }\n\n if(l && u && d && p.length() > 4)\n System.out.println(\"Correct\");\n else\n System.out.println(\"Too weak\");\n }\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "3069a0519f7048dd2918597c4395895e", "src_uid": "42a964b01e269491975965860ec92be7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class MyClass {\n\n static int c, d, n, m, k, commonParty, must;\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n\n c = sc.nextInt();\n d = sc.nextInt();\n n = sc.nextInt();\n m = sc.nextInt();\n k = sc.nextInt();\n commonParty = n * m;\n must = commonParty - k;\n\n if (must > 0) {\n \n int algC = algC();\n int algD = algD();\n\n int algJoint = algC - c;\n int partyCMinusRound = (algJoint / c) * n;\n\n int i = (must - partyCMinusRound);\n while (i > 0) {\n i -= 1;\n algJoint += d;\n }\n\n System.out.println(min(algC, algD, algJoint));\n } else {\n System.out.println(0);\n }\n\n }\n\n public static int algC() {\n int tempCommonParty = must;\n int sumTask = 0;\n while (tempCommonParty > 0) {\n tempCommonParty -= n;\n sumTask += c;\n }\n return sumTask;\n }\n\n public static int algD() {\n int tempCommonParty = must;\n int sumTask = 0;\n while (tempCommonParty > 0) {\n tempCommonParty -= 1;\n sumTask += d;\n }\n return sumTask;\n }\n\n public static int algFull() {\n //int tempCommonParty = must;\n int algC = algC();\n int algD = algD();\n\n int sumTask = algC - n;\n int partyCMinusRound = algC * (n - 1);\n\n int i = (must - partyCMinusRound);\n while (i > 0) {\n i -= 1;\n sumTask += d;\n }\n\n return min(algC, algD, sumTask);\n }\n\n public static int min(int... numbers) {\n int minNumber = Integer.MAX_VALUE;\n\n for (int number : numbers) {\n minNumber = (number < minNumber) ? number : minNumber;\n }\n\n return minNumber;\n }\n}", "lang_cluster": "Java", "tags": ["math", "dp", "implementation"], "code_uid": "6b03e397f6a968312aba0264d805258f", "src_uid": "c6ec932b852e0e8c30c822a226ef7bcb", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n public static void solution(BufferedReader reader, PrintWriter out)\n throws IOException {\n In in = new In(reader);\n int n = in.nextInt();\n long max = 1;\n for (int a = Math.max(1, n - 100); a <= n; a++)\n for (int b = Math.max(1, n - 100); b <= n; b++)\n for (int c = Math.max(1, n - 100); c <= n; c++)\n max = Math.max(max, lcm(a, lcm(b, c)));\n out.println(max);\n }\n\n private static long lcm(long a, long b) {\n long gcd = gcd(a, b);\n return a / gcd * b;\n }\n\n private static long gcd(long a, long b) {\n while (b != 0) {\n long t = b;\n b = a % b;\n a = t;\n }\n return a;\n }\n\n public static void main(String[] args) throws Exception {\n BufferedReader reader = new BufferedReader(\n new InputStreamReader(System.in));\n PrintWriter out = new PrintWriter(\n new BufferedWriter(new OutputStreamWriter(System.out)));\n solution(reader, out);\n out.close();\n }\n\n protected static class In {\n private BufferedReader reader;\n private StringTokenizer tokenizer = new StringTokenizer(\"\");\n\n public In(BufferedReader reader) {\n this.reader = reader;\n }\n\n public String next() throws IOException {\n while (!tokenizer.hasMoreTokens())\n tokenizer = new StringTokenizer(reader.readLine());\n return tokenizer.nextToken();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["number theory"], "code_uid": "d713cd16583d2ff8099c0477deb72d23", "src_uid": "25e5afcdf246ee35c9cef2fcbdd4566e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main {\n\n\tpublic static void main(String[] args) {\n\n\t\tScanner sc = new Scanner(System.in);\n\t\twhile (sc.hasNext()) {\n\t\t\tint a[][] = new int[5][5];\n\t\t\tfor (int i = 1; i < a.length; i++) {\n\t\t\t\tfor (int j = 1; j < a.length; j++) {\n\t\t\t\t\ta[i][j] = sc.nextInt();\n\t\t\t\t}\n\n\t\t\t}\n\t\t\tif (a[1][4] == 1\n\t\t\t\t\t&& (a[1][1] == 1 || a[1][2] == 1 || a[1][3] == 1 || a[2][1] == 1 || a[3][2] == 1 || a[4][3] == 1)) {\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t} else if (a[2][4] == 1\n\t\t\t\t\t&& (a[2][1] == 1 || a[2][2] == 1 || a[2][3] == 1 || a[3][1] == 1 || a[4][2] == 1 || a[1][3] == 1)) {\n\t\t\t\tSystem.out.println(\"YES\");\n\n\t\t\t} else if (a[3][4] == 1\n\t\t\t\t\t&& (a[3][1] == 1 || a[3][2] == 1 || a[3][3] == 1 || a[4][1] == 1 || a[2][3] == 1 || a[1][2] == 1)) {\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t} else if (a[4][4] == 1\n\t\t\t\t\t&& (a[4][1] == 1 || a[4][2] == 1 || a[4][3] == 1 || a[3][3] == 1 || a[1][1] == 1 || a[2][2] == 1)) {\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t} else {\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t}\n\n\t\t}\n\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "8790a10c04e66b0a6a29b482288744de", "src_uid": "44fdf71d56bef949ec83f00d17c29127", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main {\n\tMyScanner sc = new MyScanner();\n\tScanner sc2 = new Scanner(System.in);\n\tfinal int MOD = 1000000007;\n\tint[] dx = { 1, 0, 0, -1 };\n\tint[] dy = { 0, 1, -1, 0 };\n\n\tvoid run() {\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\n\t\tint day = 1;\n\t\twhile (true) {\n\t\t\tn--;\n\t\t\tif (day % m == 0) {\n\t\t\t\tn++;\n\t\t\t}\n\t\t\tif (n == 0) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tday++;\n\t\t}\n\t\tSystem.out.println(day);\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew Main().run();\n\t}\n\n\tvoid debug(Object... o) {\n\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n\n\tvoid debug2(int[][] array) {\n\t\tfor (int i = 0; i < array.length; i++) {\n\t\t\tfor (int j = 0; j < array[i].length; j++) {\n\t\t\t\tSystem.out.print(array[i][j]);\n\t\t\t}\n\t\t\tSystem.out.println();\n\t\t}\n\t}\n\n\tclass MyScanner {\n\t\tint nextInt() {\n\t\t\ttry {\n\t\t\t\tint c = System.in.read();\n\t\t\t\twhile (c != '-' && (c < '0' || '9' < c))\n\t\t\t\t\tc = System.in.read();\n\t\t\t\tif (c == '-')\n\t\t\t\t\treturn -nextInt();\n\t\t\t\tint res = 0;\n\t\t\t\tdo {\n\t\t\t\t\tres *= 10;\n\t\t\t\t\tres += c - '0';\n\t\t\t\t\tc = System.in.read();\n\t\t\t\t} while ('0' <= c && c <= '9');\n\t\t\t\treturn res;\n\t\t\t} catch (Exception e) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tString next() {\n\t\t\ttry {\n\t\t\t\tStringBuilder res = new StringBuilder(\"\");\n\t\t\t\tint c = System.in.read();\n\t\t\t\twhile (Character.isWhitespace(c))\n\t\t\t\t\tc = System.in.read();\n\t\t\t\tdo {\n\t\t\t\t\tres.append((char) c);\n\t\t\t\t} while (!Character.isWhitespace(c = System.in.read()));\n\t\t\t\treturn res.toString();\n\t\t\t} catch (Exception e) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "tags": ["brute force", "math", "implementation"], "code_uid": "9ff14f04a8a861af0a154789b01b06fc", "src_uid": "42b25b7335ec01794fbb1d4086aa9dd0", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.InputMismatchException;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.io.Writer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Nipuna Samarasekara\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastScanner in = new FastScanner(inputStream);\n\t\tFastPrinter out = new FastPrinter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n public void solve(int testNumber, FastScanner in, FastPrinter out) {\n int n=in.nextInt(),m=in.nextInt(),i=in.nextInt(),j=in.nextInt(),a=in.nextInt(),b=in.nextInt();\n int[] D= new int[2];\n int[] P= new int[2];\n int i1=0,i2=0,ans=100000000,v1=0,v2=0;\n v1=Math.max((i-1)/a,(n-i)/a);\n v2=Math.max((j-1)/b,(m-j)/b);\n if((i-1)%a==0){D[i1]=(i-1)/a; i1++;}\n if((n-i)%a==0){D[i1]=(n-i)/a; i1++;}\n if((j-1)%b==0){P[i2]=(j-1)/b; i2++;}\n if((m-j)%b==0){P[i2]=(m-j)/b; i2++;}\n for (int k = 0; k < i1; k++) {\n for (int l = 0; l < i2; l++) {\n if((D[k]-P[l])%2==0){\n if(D[k]==P[l])\n ans= Math.min(ans,Math.max(D[k],P[l]));\n else if(D[k]>P[l]&&v2>0) ans= Math.min(ans,Math.max(D[k],P[l]));\n else if(D[k]0) ans= Math.min(ans,Math.max(D[k],P[l]));\n\n }\n }\n }\n\n if(ans>99999999) out.println(\"Poor Inna and pony!\");\n else out.println(ans);\n\n }\n}\n\nclass FastScanner extends BufferedReader {\n\n public FastScanner(InputStream is) {\n super(new InputStreamReader(is));\n }\n\n public int read() {\n try {\n int ret = super.read();\n// if (isEOF && ret < 0) {\n// throw new InputMismatchException();\n// }\n// isEOF = ret == -1;\n return ret;\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n }\n\n static boolean isWhiteSpace(int c) {\n return c >= 0 && c <= 32;\n }\n\n public int nextInt() {\n int c = read();\n while (isWhiteSpace(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int ret = 0;\n while (c >= 0 && !isWhiteSpace(c)) {\n if (c < '0' || c > '9') {\n throw new NumberFormatException(\"digit expected \" + (char) c\n + \" found\");\n }\n ret = ret * 10 + c - '0';\n c = read();\n }\n return ret * sgn;\n }\n\n public String readLine() {\n try {\n return super.readLine();\n } catch (IOException e) {\n return null;\n }\n }\n\n }\n\nclass FastPrinter extends PrintWriter {\n\n public FastPrinter(OutputStream out) {\n super(out);\n }\n\n public FastPrinter(Writer out) {\n super(out);\n }\n\n\n}\n\n", "lang_cluster": "Java", "tags": ["greedy", "implementation"], "code_uid": "8aeecb2bf6653def51355dc5a8fa6745", "src_uid": "51155e9bfa90e0ff29d049cedc3e1862", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.LinkedList;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\n\npublic class LuckyPermutation {\n\t\n\tstatic class Scanner{\n\t\tBufferedReader br=null;\n\t\tStringTokenizer tk=null;\n\t\tpublic Scanner(){\n\t\t\tbr=new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\t\tpublic String next() throws IOException{\n\t\t\twhile(tk==null || !tk.hasMoreTokens())\n\t\t\t\ttk=new StringTokenizer(br.readLine());\n\t\t\treturn tk.nextToken();\n\t\t}\n\t\tpublic int nextInt() throws NumberFormatException, IOException{\n\t\t\treturn Integer.valueOf(next());\n\t\t}\n\t}\n\t\n\tstatic long[] fact = new long[14];\n\tstatic TreeSet set = new TreeSet();\n\t\n\tstatic void init(){\n\t\tfact[0] = 1;\n\t\tfor(int i = 1; i <= 13; i++)\n\t\t\tfact[i] = fact[i - 1]*i;\n\t\tfor(int tam = 1; tam <= 11; tam++){\n\t\t\tfor(int i = 0; i < (1<= 0; k--){\n\t\t\t\t\tint n= ( (((i>>k) & 1) == 1)? 7: 4);\n\t\t\t\t\tnum *= 10;\n\t\t\t\t\tnum += n;\n\t\t\t\t}\n\t\t\t\tset.add(num);\n\t\t\t}\n\t\t}\n\t\treturn;\n\t}\n\t\n\tpublic static void main(String args[]) throws NumberFormatException, IOException{\n\t\tScanner sc = new Scanner();\n\t\tinit();\n\t\tint N = sc.nextInt();\n\t\tint K = sc.nextInt();\n\t\tLinkedList ans = new LinkedList();\n\t\tif (N <= 13 && fact[N] < K){\n\t\t\tSystem.out.println(\"-1\");\n\t\t\treturn;\n\t\t}\n\t\tint amount = 0;\n\t\tlong left = 1;\n\t\tlong right = N - 13;\n\t\tfor(long lucky: set){\n\t\t\tif (lucky>= left && lucky<=right)\n\t\t\t\tamount++;\n\t\t}\n\t\tTreeSet current = new TreeSet();\n\t\tfor(int i = Math.max(1, N - 12); i <= N; i++)\n\t\t\tcurrent.add(i);\n\t\tint limit = current.size();\n\t\tfor(int i = 0; i < limit; i++){\n\t\t\tint index = 1;\n\t\t\tfor(int e: current){\n\t\t\t\tif (fact[current.size() - 1]*index >= K){\n\t\t\t\t\tK -= fact[current.size() - 1] * (index - 1);\n\t\t\t\t\tcurrent.remove(e);\n\t\t\t\t\tans.add(e);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tindex++;\n\t\t\t}\n\t\t}\n\t\tint pos = Math.max(N - 12,1);\n\t\tfor(int e: ans){\n\t\t\tif (set.contains(pos + 0L) && set.contains(e + 0L))\n\t\t\t\tamount++;\n\t\t\tpos++;\n\t\t}\n\t\tSystem.out.println(amount);\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["brute force", "combinatorics", "number theory"], "code_uid": "0e8582945957d9ad199f7cef1fd63fd9", "src_uid": "cb2aa02772f95fefd1856960b6ceac4c", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "\n//package solution;\n\nimport java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.StringTokenizer;\n\npublic class Solution implements Runnable {\n \n BufferedReader in;\n PrintWriter out;\n StringTokenizer tok = new StringTokenizer(\"\");\n final boolean OJ = System.getProperty(\"ONLINE_JUDGE\") != null;\n \n void init() throws FileNotFoundException {\n if (OJ) {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n } else {\n in = new BufferedReader(new FileReader(\"input.txt\"));\n out = new PrintWriter(\"output.txt\");\n }\n \n }\n \n public void run() {\n try {\n init();\n solve();\n out.close();\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(-1);\n }\n }\n \n String readString() throws IOException {\n while (!tok.hasMoreTokens()) {\n tok = new StringTokenizer(in.readLine());\n }\n \n return tok.nextToken();\n }\n \n int readInt() throws IOException {\n return Integer.parseInt(readString());\n }\n \n long readLong() throws IOException {\n return Long.parseLong(readString());\n }\n \n char readChar() throws IOException {\n return readString().charAt(0);\n }\n\n public static void main(String[] args) {\n new Thread(null, new Solution(), \"\", 256 * 1l << 20).start();\n }\n \n long make() throws IOException {\n int n = readInt();\n int base = readInt();\n int[] nums = new int[n];\n for (int i = 0; i < n; i++) {\n nums[i] = readInt();\n }\n long ans = 0;\n long currBase = 1;\n for (int i = n - 1; i >= 0; i--) {\n ans += currBase * nums[i];\n currBase *= base;\n }\n \n return ans;\n }\n \n void solve() throws IOException {\n long first = make();\n long second = make();\n if (first == second) out.print(\"=\");\n else if (first > second) out.print(\">\");\n else out.print(\"<\");\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "37cb769af4b15e12acc58540024d5efb", "src_uid": "d6ab5f75a7bee28f0af2bf168a0b2e67", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.LinkedList;\nimport java.util.Queue;\n\npublic class ProblemB {\n\n /**\n * @param args\n */\n private static boolean visited[][] = new boolean[20][20];\n private static boolean isSafe(int i,int j, int n,int m){\n if(i<0 || i>=n || j<0 || j>= m)\n return false;\n if(visited[i][j]){\n return false;\n }\n return true;\n }\n \n public static void main(String[] args) throws Exception {\n // TODO Auto-generated method stub\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n String input = br.readLine();\n int n,m;\n n = Integer.parseInt(input.split(\" \")[0]);\n m = Integer.parseInt(input.split(\" \")[1]);\n String hD = br.readLine();\n String vD = br.readLine();\n for(int i=0;i<20;i++){\n for(int j=0;j<20;j++){\n visited[i][j] = false;\n }\n }\n boolean isConnected = true;\n for(int i=0;i qh = new LinkedList();\n Queue qv = new LinkedList();\n qh.add(i);\n qv.add(j);\n while(!qh.isEmpty()){\n int u = qh.remove();\n int v = qv.remove();\n if(isSafe(u, v+1, n, m)){\n if(hD.charAt(u) == '>'){\n visited[u][v+1] = true;\n qh.add(u);\n qv.add(v+1);\n }\n }\n if(isSafe(u, v-1, n, m)){\n if(hD.charAt(u) == '<'){\n visited[u][v-1] = true;\n qh.add(u);\n qv.add(v-1);\n }\n }\n if(isSafe(u-1, v, n, m)){\n if(vD.charAt(v) == '^'){\n visited[u-1][v] = true;\n qh.add(u-1);\n qv.add(v);\n }\n }\n if(isSafe(u+1, v, n, m)){\n if(vD.charAt(v) == 'v'){\n visited[u+1][v] = true;\n qh.add(u+1);\n qv.add(v);\n }\n }\n }\n }\n\n}\n", "lang_cluster": "Java", "tags": ["dfs and similar", "implementation", "graphs", "brute force"], "code_uid": "5fe67d14a8c7f84e21ee339ca662617f", "src_uid": "eab5c84c9658eb32f5614cd2497541cf", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\npublic class j\n{\npublic static void main(String a[])throws IOException\n{\nBufferedReader b=new BufferedReader(new InputStreamReader(System.in));\nint m=0,n=0,p=0,i=0;\nString r,s=\"\\0\",t=\"\\0\",u=\"\\0\";\nr=b.readLine();\nStringTokenizer c=new StringTokenizer(r);\ns=c.nextToken();\nt=c.nextToken();\nm=s.length();\nn=t.length();\nif(mn)\n{\nif(s.compareTo(\"100000\")==0)\nSystem.out.print(100000+Integer.parseInt(t));\nelse\n{\ns=String.valueOf(Integer.parseInt(s)+1);\nwhile(true)\n{\np=s.length();\nfor(i=0;i= A)\n {\n index = i;\n break;\n }\n else\n {\n sum = sum + N;\n }\n }\n System.out.println(sum + ((n - index) * x));\n\n\n }\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "7fd1986a51c9fac4d34e464e8de42bd7", "src_uid": "92a233f8d9c73d9f33e4e6116b7d0a96", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.text.*;\n\npublic class B653 {\n\n\tpublic static int solve(String[] l2, String[] l1, String s, int n) {\n\t\tif (s.length() == n)\n\t\t\treturn 1;\n\t\tint ans = 0;\n\t\tfor (int i = 0; i < l1.length; i++) {\n\t\t\tif (((char) s.charAt(0) + \"\").equals(l1[i])) {\n\t\t\t\tans += solve(l2, l1, l2[i] + s.substring(1), n);\n//\t\t\t\tSystem.out.println(\"LL\");\n\t\t\t}\n\t\t}\n\t\treturn ans;\n\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\tint n = sc.nextInt();\n\t\tint q = sc.nextInt();\n\t\tString[] l2 = new String[q];\n\t\tString[] l1 = new String[q];\n\t\tfor (int i = 0; i < l1.length; i++) {\n\t\t\tl2[i] = sc.next();\n\t\t\tl1[i] = sc.next();\n\t\t}\n//\t\tpw.println(Arrays.toString(l1));\n//\t\tpw.println(Arrays.toString(l2));\n\t\tpw.print(solve(l2, l1, \"a\", n));\n\t\tpw.close();\n\t}\n\n\tstatic class Scanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(s));\n\t\t}\n\n\t\tpublic Scanner(FileReader r) {\n\t\t\tbr = new BufferedReader(r);\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic String nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\tString x = next();\n\t\t\tStringBuilder sb = new StringBuilder(\"0\");\n\t\t\tdouble res = 0, f = 1;\n\t\t\tboolean dec = false, neg = false;\n\t\t\tint start = 0;\n\t\t\tif (x.charAt(0) == '-') {\n\t\t\t\tneg = true;\n\t\t\t\tstart++;\n\t\t\t}\n\t\t\tfor (int i = start; i < x.length(); i++)\n\t\t\t\tif (x.charAt(i) == '.') {\n\t\t\t\t\tres = Long.parseLong(sb.toString());\n\t\t\t\t\tsb = new StringBuilder(\"0\");\n\t\t\t\t\tdec = true;\n\t\t\t\t} else {\n\t\t\t\t\tsb.append(x.charAt(i));\n\t\t\t\t\tif (dec)\n\t\t\t\t\t\tf *= 10;\n\t\t\t\t}\n\t\t\tres += Long.parseLong(sb.toString()) / f;\n\t\t\treturn res * (neg ? -1 : 1);\n\t\t}\n\n\t\tpublic boolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t}\n}\n", "lang_cluster": "Java", "tags": ["dfs and similar", "strings", "dp", "brute force"], "code_uid": "4718e55df4e656b022adae13dd153d93", "src_uid": "c42abec29bfd17de3f43385fa6bea534", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "// Utilities\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n\tstatic int N, K;\n\tstatic long[] fac;\n\tstatic long res = 0;\n\tstatic final int MOD = 998244353;\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tN = in.iscan(); K = in.iscan(); fac = new long[N+1]; fac[0] = 1;\n\t\tfor (int i = 1; i <= N; i++) fac[i] = fac[i-1] * i % MOD;\n\t\tfor (int i = 1; i <= N; i++) {\n\t\t\tres = (res + choose(N/i-1, K-1)) % MOD;\n\t\t}\n\t\tout.println(res);\n\t\tout.close();\n\t} \n\t\n\tstatic long choose(int n, int k) {\n\t\tif (k > n) return 0;\n\t\tlong a = fac[n];\n\t\tlong b = fac[k] * fac[n-k] % MOD;\n\t\t// b ^ prime-1 = 1 -> b ^ 998244352 = 1 -> b * (b ^ 998244351) = 1\n\t\t// -> Mod_inv = b ^ 998244351\n\t\treturn a * UTILITIES.fast_pow_mod(b, MOD-2, MOD) % MOD;\n\t}\n\n\tstatic INPUT in = new INPUT(System.in);\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\tprivate static class INPUT {\n\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar, numChars;\n\n\t\tpublic INPUT (InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n\n\t\tpublic INPUT (String file) throws IOException {\n\t\t\tthis.stream = new FileInputStream (file);\n\t\t}\n\n\t\tpublic int cscan () throws IOException {\n\t\t\tif (curChar >= numChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\tnumChars = stream.read (buf);\n\t\t\t}\n\t\t\t\n\t\t\tif (numChars == -1)\n\t\t\t\treturn numChars;\n\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\t\tpublic int iscan () throws IOException {\n\t\t\tint c = cscan (), sgn = 1;\n\t\t\t\n\t\t\twhile (space (c))\n\t\t\t\tc = cscan ();\n\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = cscan ();\n\t\t\t}\n\n\t\t\tint res = 0;\n\n\t\t\tdo {\n\t\t\t\tres = (res << 1) + (res << 3);\n\t\t\t\tres += c - '0';\n\t\t\t\tc = cscan ();\n\t\t\t}\n\t\t\twhile (!space (c));\n\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic String sscan () throws IOException {\n\t\t\tint c = cscan ();\n\t\t\t\n\t\t\twhile (space (c))\n\t\t\t\tc = cscan ();\n\n\t\t\tStringBuilder res = new StringBuilder ();\n\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint (c);\n\t\t\t\tc = cscan ();\n\t\t\t}\n\t\t\twhile (!space (c));\n\n\t\t\treturn res.toString ();\n\t\t}\n\n\t\tpublic double dscan () throws IOException {\n\t\t\tint c = cscan (), sgn = 1;\n\t\t\t\n\t\t\twhile (space (c))\n\t\t\t\tc = cscan ();\n\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = cscan ();\n\t\t\t}\n\n\t\t\tdouble res = 0;\n\n\t\t\twhile (!space (c) && c != '.') {\n\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\treturn res * UTILITIES.fast_pow (10, iscan ());\n\t\t\t\t\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = cscan ();\n\t\t\t}\n\n\t\t\tif (c == '.') {\n\t\t\t\tc = cscan ();\n\t\t\t\tdouble m = 1;\n\n\t\t\t\twhile (!space (c)) {\n\t\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\t\treturn res * UTILITIES.fast_pow (10, iscan ());\n\n\t\t\t\t\tm /= 10;\n\t\t\t\t\tres += (c - '0') * m;\n\t\t\t\t\tc = cscan ();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic long lscan () throws IOException {\n\t\t\tint c = cscan (), sgn = 1;\n\t\t\t\n\t\t\twhile (space (c))\n\t\t\t\tc = cscan ();\n\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = cscan ();\n\t\t\t}\n\n\t\t\tlong res = 0;\n\n\t\t\tdo {\n\t\t\t\tres = (res << 1) + (res << 3);\n\t\t\t\tres += c - '0';\n\t\t\t\tc = cscan ();\n\t\t\t}\n\t\t\twhile (!space (c));\n\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic boolean space (int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\t}\n\n\tpublic static class UTILITIES {\n\n\t\tstatic final double EPS = 10e-6;\n\n\t\tpublic static int lower_bound (int[] arr, int x) {\n\t\t\tint low = 0, high = arr.length, mid = -1;\n\n\t\t\twhile (low < high) {\n\t\t\t\tmid = (low + high) / 2;\n\n\t\t\t\tif (arr[mid] >= x)\n\t\t\t\t\thigh = mid;\n\t\t\t\telse\n\t\t\t\t\tlow = mid + 1;\n\t\t\t}\n\n\t\t\treturn low;\n\t\t}\n\n\t\tpublic static int upper_bound (int[] arr, int x) {\n\t\t\tint low = 0, high = arr.length, mid = -1;\n\n\t\t\twhile (low < high) {\n\t\t\t\tmid = (low + high) / 2;\n\n\t\t\t\tif (arr[mid] > x)\n\t\t\t\t\thigh = mid;\n\t\t\t\telse\n\t\t\t\t\tlow = mid + 1;\n\t\t\t}\n\n\t\t\treturn low;\n\t\t}\n\n\t\tpublic static long gcd (long a, long b) {\n\t\t\treturn b == 0 ? a : gcd (b, a % b);\n\t\t}\n\n\t\tpublic static long lcm (long a, long b) {\n\t\t\treturn a * b / gcd (a, b);\n\t\t}\n\n\t\tpublic static long fast_pow_mod (long b, long x, int mod) {\n\t\t\tif (x == 0) return 1;\n\t\t\tif (x == 1) return b;\n\t\t\tif (x % 2 == 0) return fast_pow_mod (b * b % mod, x / 2, mod) % mod;\n\n\t\t\treturn b * fast_pow_mod (b * b % mod, x / 2, mod) % mod;\n\t\t}\n\n\t\tpublic static int fast_pow (int b, int x) {\n\t\t\tif (x == 0) return 1;\n\t\t\tif (x == 1) return b;\n\t\t\tif (x % 2 == 0) return fast_pow (b * b, x / 2);\n\n\t\t\treturn b * fast_pow (b * b, x / 2);\n\t\t}\n\n\t\tpublic static long choose (long n, long k) {\n\t\t\tk = Math.min (k, n - k);\n\t\t\tlong val = 1;\n\n\t\t\tfor (int i = 0; i < k; ++i)\n\t\t\t\tval = val * (n - i) / (i + 1);\n\n\t\t\treturn val;\n\t\t}\n\n\t\tpublic static long permute (int n, int k) {\n\t\t\tif (n < k) return 0;\n\t\t\tlong val = 1;\n\n\t\t\tfor (int i = 0; i < k; ++i)\n\t\t\t\tval = (val * (n - i));\n\n\t\t\treturn val;\n\t\t}\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "combinatorics", "number theory"], "code_uid": "aed44db6f353838e361c1b2a72699da6", "src_uid": "8e8eb64a047cb970a549ee870c3d280d", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.io.*;\nimport java.util.*;\nimport java.math.BigDecimal;\n\npublic class B\n{\npublic static void main(String args[]) throws IOException\n{\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n // BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));\n // code starts here\n String s[]=br.readLine().split(\" \");\n long x=Long.parseLong(s[0]);\n long y=Long.parseLong(s[1]);\n if(x==y){\n System.out.println(\"=\");\n return;}\n double e=Math.E;\n if(x>e && y>e)\n {\n if(x>y)\n System.out.println(\"<\");\n else\n System.out.println(\">\");\n return;\n }\n BigDecimal l1=new BigDecimal(Math.log(x));\n BigDecimal l2=new BigDecimal(Math.log(y));\n BigDecimal x1=new BigDecimal(x);\n BigDecimal y1=new BigDecimal(y);\n BigDecimal a1=l1.multiply(y1);\n BigDecimal a2=l2.multiply(x1);\n //double a2=l2/y;\n if(a1.compareTo(a2)<0)\n System.out.println(\"<\");\n else if(a1.compareTo(a2)>0)\n System.out.println(\">\");\n else\n System.out.println(\"=\");\n //bw.flush();\n}\n\n}", "lang_cluster": "Java", "tags": ["math"], "code_uid": "988a009cd67cd8a393f220ea02e666e9", "src_uid": "ec1e44ff41941f0e6436831b5ae543c6", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n\n\nimport java.util.Scanner;\n\n/**\n *\n * @author atheeralharbi\n */\npublic class JavaApplication29 {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n // TODO code application logic here\n \n Scanner read = new Scanner(System.in);\n String s3 = read.next();\n String s4 = read.next();\n \n s3 = s3.toUpperCase();\n\t\ts4 = s4.toUpperCase();\n \n \n for (int i = 0 ; i s4.charAt(i)){\n \n System.out.println(1);\n break;\n }\n if (s3.charAt(i) < s4.charAt(i)){\n \n System.out.println(-1);\n break;\n }\n \n \n \n }\n }\n \n}\n", "lang_cluster": "Java", "tags": ["strings", "implementation"], "code_uid": "e023f404ad9d824e0b618bfe08f9bc71", "src_uid": "ffeae332696a901813677bd1033cf01e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n \n String s=sc.next();\n int a=0;\n for (int i = 0; i < s.length(); i++) {\n if(s.charAt(i)=='a'){\n a++;\n }\n }\n int tama\u00f1o=s.length();\n while(true){\n if(a>tama\u00f1o/2){\n System.out.println(tama\u00f1o);\n break;\n }else{\n tama\u00f1o--;\n }\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["strings", "implementation"], "code_uid": "2ad3b7026243e7eb7ac7a3eb945d8aa2", "src_uid": "84cb9ad2ae3ba7e912920d7feb4f6219", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.StringTokenizer;\n\n/**\n * Created by sachin.goyal on 16/05/16.\n */\npublic class MainB {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n Task solver = new Task();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class Task {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int t = in.nextInt();\n if(t == 0){\n out.print(0);\n return;\n }\n double[][] ans = new double[11][11];\n for(int i=0;i=0 && ans[i-1][left] > 1? (ans[i-1][left] -1)/2 : 0;\n ans[i][j] += right<=i-1 && ans[i-1][right] > 1 ? (ans[i-1][right] -1)/2 : 0;\n if(ans[i][j] >= 1d) finalAns++;\n }\n }\n out.print(finalAns);\n\n }\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "b2ad6be255a1a424ec7d1ce7625bc71f", "src_uid": "b2b49b7f6e3279d435766085958fb69d", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.NoSuchElementException;\nimport java.io.Writer;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Alex\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tOutputWriter out = new OutputWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n long x = in.readLong(), y = in.readLong(), m = in.readLong();\n long min = Math.min(x, y), max = Math.max(x, y);\n long counter = 0;\n while (min < m && max < m) {\n if (min <= 0 && max <= 0) {\n out.print(-1);\n return;\n }\n long diff = max - min;\n long times = Math.max(diff / max, 1);\n min += (max * times);\n counter += times;\n\n long tempmin = Math.min(min, max);\n long tempmax = Math.max(min, max);\n min = tempmin;\n max = tempmax;\n }\n out.print(counter);\n }\n}\n\nclass InputReader {\n\tprivate InputStream stream;\n\tprivate byte[] buf = new byte[1024];\n\tprivate int curChar;\n\tprivate int numChars;\n\tprivate SpaceCharFilter filter;\n\n\tpublic InputReader(InputStream stream) {\n\t\tthis.stream = stream;\n\t}\n\n\tpublic int read() {\n\t\tif (numChars == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (curChar >= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n\tpublic long readLong() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tlong res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\tpublic boolean isSpaceChar(int c) {\n\t\tif (filter != null)\n\t\t\treturn filter.isSpaceChar(c);\n\t\treturn isWhitespace(c);\n\t}\n\n\tpublic static boolean isWhitespace(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n\tpublic interface SpaceCharFilter {\n\t\tpublic boolean isSpaceChar(int ch);\n\t}\n}\n\nclass OutputWriter {\n\tprivate final PrintWriter writer;\n\n\tpublic OutputWriter(OutputStream outputStream) {\n\t\twriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n\t}\n\tpublic void close() {\n\t\twriter.close();\n\t}\n\tpublic void print(long i) {\n\t\twriter.print(i);\n\t}\n\tpublic void print(int i) {\n\t\twriter.print(i);\n\t}\n}\n\n", "lang_cluster": "Java", "tags": ["brute force"], "code_uid": "6b78a35b2a51a4262f37b2b82dfdd2f3", "src_uid": "82026a3c3d9a6bda2e2ac6e14979d821", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "//package timus;\n\nimport java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.io.StreamTokenizer;\nimport java.io.Writer;\nimport java.math.BigInteger;\nimport java.sql.Date;\nimport java.util.AbstractSet;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.HashSet;\nimport java.util.Hashtable;\nimport java.util.Iterator;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.PriorityQueue;\nimport java.util.Queue;\nimport java.util.Random;\nimport java.util.Set;\nimport java.util.Stack;\nimport java.util.TreeSet;\nimport java.util.Vector;\n\npublic class Abra {\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Abra().run();\n\t}\n\n\tStreamTokenizer in;\n\tPrintWriter out;\n\tboolean oj;\n\tBufferedReader br;\n\n\tvoid init() throws IOException {\n\t\toj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\tReader reader = oj ? new InputStreamReader(System.in) : new FileReader(\"input.txt\");\n\t\tWriter writer = oj ? new OutputStreamWriter(System.out) : new FileWriter(\"output.txt\");\n\t\t// Reader reader = new InputStreamReader(System.in);\n\t\t// Writer writer = new OutputStreamWriter(System.out);\n\t\tbr = new BufferedReader(reader);\n\t\tin = new StreamTokenizer(br);\n\t\tout = new PrintWriter(writer);\n\t}\n\n\tlong selectionTime = 0;\n\n\tvoid startSelection() {\n\t\tselectionTime -= System.currentTimeMillis();\n\t}\n\n\tvoid stopSelection() {\n\t\tselectionTime += System.currentTimeMillis();\n\t}\n\n\tvoid run() throws IOException {\n\t\tlong beginTime = System.currentTimeMillis();\n\t\tinit();\n\t\tsolve();\n\t\tlong endTime = System.currentTimeMillis();\n\t\tif (!oj) {\n\t\t\tSystem.out.println(\"Memory used = \" + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));\n\t\t\tSystem.out.println(\"Running time = \" + (endTime - beginTime));\n\t\t\tSystem.out.println(\"Time of the selection = \" + selectionTime);\n\t\t}\n\t\tout.flush();\n\t}\n\n\tint nextInt() throws IOException {\n\t\tin.nextToken();\n\t\treturn (int) in.nval;\n\t}\n\n\tlong nextLong() throws IOException {\n\t\tin.nextToken();\n\t\treturn (long) in.nval;\n\t}\n\n\tString nextString() throws IOException {\n\t\tin.nextToken();\n\t\treturn in.sval;\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\tin.nextToken();\n\t\treturn in.nval;\n\t}\n\n\tlong fact(long x) {\n\t\tlong a = 1;\n\t\tfor (long i = 2; i <= x; i++) {\n\t\t\ta *= i;\n\t\t}\n\t\treturn a;\n\t}\n\n\tlong digitSum(String x) {\n\t\tlong a = 0;\n\t\tfor (int i = 0; i < x.length(); i++) {\n\t\t\ta += x.charAt(i) - '0';\n\t\t}\n\t\treturn a;\n\t}\n\n\tlong digitSum(long x) {\n\t\tlong a = 0;\n\t\twhile (x > 0) {\n\t\t\ta += x % 10;\n\t\t\tx /= 10;\n\t\t}\n\t\treturn a;\n\t}\n\n\tlong digitMul(long x) {\n\t\tlong a = 1;\n\t\twhile (x > 0) {\n\t\t\ta *= x % 10;\n\t\t\tx /= 10;\n\t\t}\n\t\treturn a;\n\t}\n\n\tint digitCubesSum(int x) {\n\t\tint a = 0;\n\t\twhile (x > 0) {\n\t\t\ta += (x % 10) * (x % 10) * (x % 10);\n\t\t\tx /= 10;\n\t\t}\n\t\treturn a;\n\t}\n\n\tdouble pif(double ax, double ay, double bx, double by) {\n\t\treturn Math.sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));\n\t}\n\n\tlong gcd(long a, long b) {\n\t\tif (a < b) {\n\t\t\tlong c = b;\n\t\t\tb = a;\n\t\t\ta = c;\n\t\t}\n\t\twhile (a % b != 0) {\n\t\t\ta = a % b;\n\t\t\tif (a < b) {\n\t\t\t\tlong c = b;\n\t\t\t\tb = a;\n\t\t\t\ta = c;\n\t\t\t}\n\t\t}\n\t\treturn b;\n\t}\n\n\tint gcd(int a, int b) {\n\t\tif (a < b) {\n\t\t\tint c = b;\n\t\t\tb = a;\n\t\t\ta = c;\n\t\t}\n\t\twhile (a % b != 0) {\n\t\t\ta = a % b;\n\t\t\tif (a < b) {\n\t\t\t\tint c = b;\n\t\t\t\tb = a;\n\t\t\t\ta = c;\n\t\t\t}\n\t\t}\n\t\treturn b;\n\t}\n\n\tlong lcm(long a, long b) throws IOException {\n\t\treturn a * b / gcd(a, b);\n\t}\n\n\tint lcm(int a, int b) throws IOException {\n\t\treturn a * b / gcd(a, b);\n\t}\n\n\tint countOccurences(String x, String y) {\n\t\tint a = 0, i = 0;\n\t\twhile (true) {\n\t\t\ti = y.indexOf(x);\n\t\t\tif (i == -1) break;\n\t\t\ta++;\n\t\t\ty = y.substring(i + 1);\n\t\t}\n\t\treturn a;\n\t}\n\n\tint[] findPrimes(int x) {\n\t\tboolean[] forErato = new boolean[x - 1];\n\t\tList t = new Vector();\n\t\tint l = 0, j = 0;\n\t\tfor (int i = 2; i < x; i++) {\n\t\t\tif (forErato[i - 2]) continue;\n\t\t\tt.add(i);\n\t\t\tl++;\n\t\t\tj = i * 2;\n\t\t\twhile (j < x) {\n\t\t\t\tforErato[j - 2] = true;\n\t\t\t\tj += i;\n\t\t\t}\n\t\t}\n\t\tint[] primes = new int[l];\n\t\tIterator iterator = t.iterator();\n\t\tfor (int i = 0; iterator.hasNext(); i++) {\n\t\t\tprimes[i] = iterator.next().intValue();\n\t\t}\n\t\treturn primes;\n\t}\n\n\tint rev(int x) {\n\t\tint a = 0;\n\t\twhile (x > 0) {\n\t\t\ta = a * 10 + x % 10;\n\t\t\tx /= 10;\n\t\t}\n\t\treturn a;\n\t}\n\n\tclass myDate {\n\t\tint d, m, y;\n\n\t\tint[] ml = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\n\n\t\tpublic myDate(int da, int ma, int ya) {\n\t\t\td = da;\n\t\t\tm = ma;\n\t\t\ty = ya;\n\t\t\tif (ma > 12 || ma < 1 || da > ml[ma - 1] || da < 1) {\n\t\t\t\td = 1;\n\t\t\t\tm = 1;\n\t\t\t\ty = 9999999;\n\t\t\t} \n\t\t}\n\t\t\n\t\tvoid incYear(int x) {\n\t\t\tfor (int i = 0; i < x; i++) {\n\t\t\t\ty++;\n\t\t\t\tif (m == 2 && d == 29) {\n\t\t\t\t\tm = 3;\n\t\t\t\t\td = 1;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (m == 3 && d == 1) {\n\t\t\t\t\tif (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0)) {\n\t\t\t\t\t\tm = 2;\n\t\t\t\t\t\td = 29;\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tboolean less(myDate x) {\n\t\t\tif (y < x.y) return true;\n\t\t\tif (y > x.y) return false;\n\t\t\tif (m < x.m) return true;\n\t\t\tif (m > x.m) return false;\n\t\t\tif (d < x.d) return true;\n\t\t\tif (d > x.d) return false;\n\t\t\treturn true;\n\t\t}\n\n\t\tvoid inc() {\n\t\t\tif ((d == 31) && (m == 12)) {\n\t\t\t\ty++;\n\t\t\t\td = 1;\n\t\t\t\tm = 1;\n\t\t\t} else {\n\t\t\t\tif (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0)) {\n\t\t\t\t\tml[1] = 29;\n\t\t\t\t}\n\t\t\t\tif (d == ml[m - 1]) {\n\t\t\t\t\tm++;\n\t\t\t\t\td = 1;\n\t\t\t\t} else\n\t\t\t\t\td++;\n\t\t\t}\n\t\t}\n\t}\n\n\tint partition(int n, int l, int m) {// n - sum, l - length, m - every part\n\t\t// <= m\n\t\tif (n < l) return 0;\n\t\tif (n < l + 2) return 1;\n\t\tif (l == 1) return 1;\n\t\tint c = 0;\n\t\tfor (int i = Math.min(n - l + 1, m); i >= (n + l - 1) / l; i--) {\n\t\t\tc += partition(n - i, l - 1, i);\n\t\t}\n\t\treturn c;\n\t}\n\n\tint rifmQuality(String a, String b) {\n\t\tif (a.length() > b.length()) {\n\t\t\tString c = a;\n\t\t\ta = b;\n\t\t\tb = c;\n\t\t}\n\t\tint c = 0, d = b.length() - a.length();\n\t\tfor (int i = a.length() - 1; i >= 0; i--) {\n\t\t\tif (a.charAt(i) == b.charAt(i + d)) c++;\n\t\t\telse\n\t\t\t\tbreak;\n\t\t}\n\t\treturn c;\n\t}\n\n\tString numSym = \"0123456789ABCDEF\";\n\n\tString ZFromXToYNotation(int x, int y, String z) {\n\t\tif (z.equals(\"0\")) return \"0\";\n\t\tString a = \"\";\n\t\tlong q = 0, t = 1;\n\t\tfor (int i = z.length() - 1; i >= 0; i--) {\n\t\t\tq += (z.charAt(i) - 48) * t;\n\t\t\tt *= x;\n\t\t}\n\t\twhile (q > 0) {\n\t\t\ta = numSym.charAt((int) (q % y)) + a;\n\t\t\tq /= y;\n\t\t}\n\t\treturn a;\n\t}\n\n\tdouble angleFromXY(int x, int y) {\n\t\tif ((x == 0) && (y > 0)) return Math.PI / 2;\n\t\tif ((x == 0) && (y < 0)) return -Math.PI / 2;\n\t\tif ((y == 0) && (x > 0)) return 0;\n\t\tif ((y == 0) && (x < 0)) return Math.PI;\n\t\tif (x > 0) return Math.atan((double) y / x);\n\t\telse {\n\t\t\tif (y > 0) return Math.atan((double) y / x) + Math.PI;\n\t\t\telse\n\t\t\t\treturn Math.atan((double) y / x) - Math.PI;\n\t\t}\n\t}\n\n\tstatic boolean isNumber(String x) {\n\t\ttry {\n\t\t\tInteger.parseInt(x);\n\t\t} catch (NumberFormatException ex) {\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tstatic boolean stringContainsOf(String x, String c) {\n\t\tfor (int i = 0; i < x.length(); i++) {\n\t\t\tif (c.indexOf(x.charAt(i)) == -1) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tlong pow(long a, long n) { // b > 0\n\t\tif (n == 0) return 1;\n\t\tlong k = n, b = 1, c = a;\n\t\twhile (k != 0) {\n\t\t\tif (k % 2 == 0) {\n\t\t\t\tk /= 2;\n\t\t\t\tc *= c;\n\t\t\t} else {\n\t\t\t\tk--;\n\t\t\t\tb *= c;\n\t\t\t}\n\t\t}\n\t\treturn b;\n\t}\n\n\tint pow(int a, int n) { // b > 0\n\t\tif (n == 0) return 1;\n\t\tint k = n, b = 1, c = a;\n\t\twhile (k != 0) {\n\t\t\tif (k % 2 == 0) {\n\t\t\t\tk /= 2;\n\t\t\t\tc *= c;\n\t\t\t} else {\n\t\t\t\tk--;\n\t\t\t\tb *= c;\n\t\t\t}\n\t\t}\n\t\treturn b;\n\t}\n\n\tdouble pow(double a, int n) { // b > 0\n\t\tif (n == 0) return 1;\n\t\tdouble k = n, b = 1, c = a;\n\t\twhile (k != 0) {\n\t\t\tif (k % 2 == 0) {\n\t\t\t\tk /= 2;\n\t\t\t\tc *= c;\n\t\t\t} else {\n\t\t\t\tk--;\n\t\t\t\tb *= c;\n\t\t\t}\n\t\t}\n\t\treturn b;\n\t}\n\n\tdouble log2(double x) {\n\t\treturn Math.log(x) / Math.log(2);\n\t}\n\n\tint lpd(int[] primes, int x) {// least prime divisor\n\t\tint i;\n\t\tfor (i = 0; primes[i] <= x / 2; i++) {\n\t\t\tif (x % primes[i] == 0) {\n\t\t\t\treturn primes[i];\n\t\t\t}\n\t\t}\n\t\t;\n\t\treturn x;\n\t}\n\n\tint np(int[] primes, int x) {// number of prime number\n\t\tfor (int i = 0; true; i++) {\n\t\t\tif (primes[i] == x) return i;\n\t\t}\n\t}\n\n\tint[] dijkstra(int[][] map, int n, int s) {\n\t\tint[] p = new int[n];\n\t\tboolean[] b = new boolean[n];\n\t\tArrays.fill(p, Integer.MAX_VALUE);\n\t\tp[s] = 0;\n\t\tb[s] = true;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (i != s) p[i] = map[s][i];\n\t\t}\n\t\twhile (true) {\n\t\t\tint m = Integer.MAX_VALUE, mi = -1;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (!b[i] && (p[i] < m)) {\n\t\t\t\t\tmi = i;\n\t\t\t\t\tm = p[i];\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (mi == -1) break;\n\t\t\tb[mi] = true;\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tif (p[mi] + map[mi][i] < p[i]) p[i] = p[mi] + map[mi][i];\n\t\t}\n\t\treturn p;\n\t}\n\n\tboolean isLatinChar(char x) {\n\t\tif (((x >= 'a') && (x <= 'z')) || ((x >= 'A') && (x <= 'Z'))) return true;\n\t\telse\n\t\t\treturn false;\n\t}\n\t\n\tboolean isBigLatinChar(char x) {\n\t\tif (x >= 'A' && x <= 'Z') return true;\n\t\telse\n\t\t\treturn false;\n\t}\n\t\n\tboolean isSmallLatinChar(char x) {\n\t\tif (x >= 'a' && x <= 'z') return true;\n\t\telse\n\t\t\treturn false;\n\t}\n\t\n\tboolean isDigitChar(char x) {\n\t\tif (x >= '0' && x <= '9') return true;\n\t\telse\n\t\t\treturn false;\n\t}\n\n\tclass NotANumberException extends Exception {\n\t\tprivate static final long serialVersionUID = 1L;\n\t\tString mistake;\n\n\t\tNotANumberException() {\n\t\t\tmistake = \"Unknown.\";\n\t\t}\n\n\t\tNotANumberException(String message) {\n\t\t\tmistake = message;\n\t\t}\n\t}\n\n\tclass Real {\n\t\tString num = \"0\";\n\t\tlong exp = 0;\n\t\tboolean pos = true;\n\n\t\tlong length() {\n\t\t\treturn num.length();\n\t\t}\n\n\t\tvoid check(String x) throws NotANumberException {\n\t\t\tif (!stringContainsOf(x, \"0123456789+-.eE\")) throw new NotANumberException(\"Illegal character.\");\n\t\t\tlong j = 0;\n\t\t\tfor (long i = 0; i < x.length(); i++) {\n\t\t\t\tif ((x.charAt((int) i) == '-') || (x.charAt((int) i) == '+')) {\n\t\t\t\t\tif (j == 0) j = 1;\n\t\t\t\t\telse\n\t\t\t\t\t\tif (j == 5) j = 6;\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tthrow new NotANumberException(\"Unexpected sign.\");\n\t\t\t\t} else\n\t\t\t\t\tif (\"0123456789\".indexOf(x.charAt((int) i)) != -1) {\n\t\t\t\t\t\tif (j == 0) j = 2;\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tif (j == 1) j = 2;\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\tif (j == 2)\n\t\t\t\t\t\t\t\t;\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\tif (j == 3) j = 4;\n\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\tif (j == 4)\n\t\t\t\t\t\t\t\t\t\t;\n\t\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\t\tif (j == 5) j = 6;\n\t\t\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\t\t\tif (j == 6)\n\t\t\t\t\t\t\t\t\t\t\t\t;\n\t\t\t\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\t\t\t\tthrow new NotANumberException(\"Unexpected digit.\");\n\t\t\t\t\t} else\n\t\t\t\t\t\tif (x.charAt((int) i) == '.') {\n\t\t\t\t\t\t\tif (j == 0) j = 3;\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\tif (j == 1) j = 3;\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\tif (j == 2) j = 3;\n\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\tthrow new NotANumberException(\"Unexpected dot.\");\n\t\t\t\t\t\t} else\n\t\t\t\t\t\t\tif ((x.charAt((int) i) == 'e') || (x.charAt((int) i) == 'E')) {\n\t\t\t\t\t\t\t\tif (j == 2) j = 5;\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\tif (j == 4) j = 5;\n\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\tthrow new NotANumberException(\"Unexpected exponent.\");\n\t\t\t\t\t\t\t} else\n\t\t\t\t\t\t\t\tthrow new NotANumberException(\"O_o.\");\n\t\t\t}\n\t\t\tif ((j == 0) || (j == 1) || (j == 3) || (j == 5)) throw new NotANumberException(\"Unexpected end.\");\n\t\t}\n\n\t\tpublic Real(String x) throws NotANumberException {\n\t\t\tcheck(x);\n\t\t\tif (x.charAt(0) == '-') pos = false;\n\t\t\tlong j = 0;\n\t\t\tString e = \"\";\n\t\t\tboolean epos = true;\n\t\t\tfor (long i = 0; i < x.length(); i++) {\n\t\t\t\tif (\"0123456789\".indexOf(x.charAt((int) i)) != -1) {\n\t\t\t\t\tif (j == 0) num += x.charAt((int) i);\n\t\t\t\t\tif (j == 1) {\n\t\t\t\t\t\tnum += x.charAt((int) i);\n\t\t\t\t\t\texp--;\n\t\t\t\t\t}\n\t\t\t\t\tif (j == 2) e += x.charAt((int) i);\n\t\t\t\t}\n\t\t\t\tif (x.charAt((int) i) == '.') {\n\t\t\t\t\tif (j == 0) j = 1;\n\t\t\t\t}\n\t\t\t\tif ((x.charAt((int) i) == 'e') || (x.charAt((int) i) == 'E')) {\n\t\t\t\t\tj = 2;\n\t\t\t\t\tif (x.charAt((int) (i + 1)) == '-') epos = false;\n\t\t\t\t}\n\t\t\t}\n\t\t\twhile ((num.length() > 1) && (num.charAt(0) == '0'))\n\t\t\t\tnum = num.substring(1);\n\t\t\twhile ((num.length() > 1) && (num.charAt(num.length() - 1) == '0')) {\n\t\t\t\tnum = num.substring(0, num.length() - 1);\n\t\t\t\texp++;\n\t\t\t}\n\t\t\tif (num.equals(\"0\")) {\n\t\t\t\texp = 0;\n\t\t\t\tpos = true;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\twhile ((e.length() > 1) && (e.charAt(0) == '0'))\n\t\t\t\te = e.substring(1);\n\t\t\ttry {\n\t\t\t\tif (e != \"\") if (epos) exp += Long.parseLong(e);\n\t\t\t\telse\n\t\t\t\t\texp -= Long.parseLong(e);\n\t\t\t} catch (NumberFormatException exc) {\n\t\t\t\tif (!epos) {\n\t\t\t\t\tnum = \"0\";\n\t\t\t\t\texp = 0;\n\t\t\t\t\tpos = true;\n\t\t\t\t} else {\n\t\t\t\t\tthrow new NotANumberException(\"Too long exponent\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tpublic Real() {\n\t\t}\n\n\t\tString toString(long mantissa) {\n\t\t\tString a = \"\", b = \"\";\n\t\t\tif (exp >= 0) {\n\t\t\t\ta = num;\n\t\t\t\tif (!pos) a = '-' + a;\n\t\t\t\tfor (long i = 0; i < exp; i++)\n\t\t\t\t\ta += '0';\n\t\t\t\tfor (long i = 0; i < mantissa; i++)\n\t\t\t\t\tb += '0';\n\t\t\t\tif (mantissa == 0) return a;\n\t\t\t\telse\n\t\t\t\t\treturn a + \".\" + b;\n\t\t\t} else {\n\t\t\t\tif (exp + length() <= 0) {\n\t\t\t\t\ta = \"0\";\n\t\t\t\t\tif (mantissa == 0) {\n\t\t\t\t\t\treturn a;\n\t\t\t\t\t}\n\t\t\t\t\tif (mantissa < -(exp + length() - 1)) {\n\t\t\t\t\t\tfor (long i = 0; i < mantissa; i++)\n\t\t\t\t\t\t\tb += '0';\n\t\t\t\t\t\treturn a + \".\" + b;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (!pos) a = '-' + a;\n\t\t\t\t\t\tfor (long i = 0; i < mantissa; i++)\n\t\t\t\t\t\t\tif (i < -(exp + length())) b += '0';\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\tif (i + exp >= 0) b += '0';\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\tb += num.charAt((int) (i + exp + length()));\n\t\t\t\t\t\treturn a + \".\" + b;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (!pos) a = \"-\";\n\t\t\t\t\tfor (long i = 0; i < exp + length(); i++)\n\t\t\t\t\t\ta += num.charAt((int) i);\n\t\t\t\t\tif (mantissa == 0) return a;\n\t\t\t\t\tfor (long i = exp + length(); i < exp + length() + mantissa; i++)\n\t\t\t\t\t\tif (i < length()) b += num.charAt((int) i);\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tb += '0';\n\t\t\t\t\treturn a + \".\" + b;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tboolean containsRepeats(int... num) {\n\t\tSet s = new TreeSet();\n\t\tfor (int d : num)\n\t\t\tif (!s.contains(d)) s.add(d);\n\t\t\telse\n\t\t\t\treturn true;\n\t\treturn false;\n\t}\n\n\tint[] rotateDice(int[] a, int n) {\n\t\tint[] c = new int[6];\n\t\tif (n == 0) {\n\t\t\tc[0] = a[1];\n\t\t\tc[1] = a[5];\n\t\t\tc[2] = a[2];\n\t\t\tc[3] = a[0];\n\t\t\tc[4] = a[4];\n\t\t\tc[5] = a[3];\n\t\t}\n\t\tif (n == 1) {\n\t\t\tc[0] = a[2];\n\t\t\tc[1] = a[1];\n\t\t\tc[2] = a[5];\n\t\t\tc[3] = a[3];\n\t\t\tc[4] = a[0];\n\t\t\tc[5] = a[4];\n\t\t}\n\t\tif (n == 2) {\n\t\t\tc[0] = a[3];\n\t\t\tc[1] = a[0];\n\t\t\tc[2] = a[2];\n\t\t\tc[3] = a[5];\n\t\t\tc[4] = a[4];\n\t\t\tc[5] = a[1];\n\t\t}\n\t\tif (n == 3) {\n\t\t\tc[0] = a[4];\n\t\t\tc[1] = a[1];\n\t\t\tc[2] = a[0];\n\t\t\tc[3] = a[3];\n\t\t\tc[4] = a[5];\n\t\t\tc[5] = a[2];\n\t\t}\n\t\tif (n == 4) {\n\t\t\tc[0] = a[0];\n\t\t\tc[1] = a[2];\n\t\t\tc[2] = a[3];\n\t\t\tc[3] = a[4];\n\t\t\tc[4] = a[1];\n\t\t\tc[5] = a[5];\n\t\t}\n\t\tif (n == 5) {\n\t\t\tc[0] = a[0];\n\t\t\tc[1] = a[4];\n\t\t\tc[2] = a[1];\n\t\t\tc[3] = a[2];\n\t\t\tc[4] = a[3];\n\t\t\tc[5] = a[5];\n\t\t}\n\t\treturn c;\n\t}\n\n\tint min(int... a) {\n\t\tint c = Integer.MAX_VALUE;\n\t\tfor (int d : a)\n\t\t\tif (d < c) c = d;\n\t\treturn c;\n\t}\n\n\tint max(int... a) {\n\t\tint c = Integer.MIN_VALUE;\n\t\tfor (int d : a)\n\t\t\tif (d > c) c = d;\n\t\treturn c;\n\t}\n\n\tint[] normalizeDice(int[] a) {\n\t\tint[] c = a.clone();\n\t\tif (c[0] != 0) if (c[1] == 0) c = rotateDice(c, 0);\n\t\telse\n\t\t\tif (c[2] == 0) c = rotateDice(c, 1);\n\t\t\telse\n\t\t\t\tif (c[3] == 0) c = rotateDice(c, 2);\n\t\t\t\telse\n\t\t\t\t\tif (c[4] == 0) c = rotateDice(c, 3);\n\t\t\t\t\telse\n\t\t\t\t\t\tif (c[5] == 0) c = rotateDice(rotateDice(c, 0), 0);\n\t\twhile (c[1] != min(c[1], c[2], c[3], c[4]))\n\t\t\tc = rotateDice(c, 4);\n\t\treturn c;\n\t}\n\n\tboolean sameDice(int[] a, int[] b) {\n\t\tfor (int i = 0; i < 6; i++)\n\t\t\tif (a[i] != b[i]) return false;\n\t\treturn true;\n\t}\n\n\tfinal double goldenRatio = (1 + Math.sqrt(5)) / 2;\n\tfinal double aGoldenRatio = (1 - Math.sqrt(5)) / 2;\n\n\tlong Fib(int n) {\n\t\tif (n < 0) if (n % 2 == 0) return -Math.round((pow(goldenRatio, -n) - pow(aGoldenRatio, -n)) / Math.sqrt(5));\n\t\telse\n\t\t\treturn -Math.round((pow(goldenRatio, -n) - pow(aGoldenRatio, -n)) / Math.sqrt(5));\n\t\treturn Math.round((pow(goldenRatio, n) - pow(aGoldenRatio, n)) / Math.sqrt(5));\n\t}\n\n\tclass japaneeseComparator implements Comparator {\n\t\t@Override\n\t\tpublic int compare(String a, String b) {\n\t\t\tint ai = 0, bi = 0;\n\t\t\tboolean m = false, ns = false;\n\t\t\tif (a.charAt(ai) <= '9' && a.charAt(ai) >= '0') {\n\t\t\t\tif (b.charAt(bi) <= '9' && b.charAt(bi) >= '0') m = true;\n\t\t\t\telse\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tif (b.charAt(bi) <= '9' && b.charAt(bi) >= '0') {\n\t\t\t\tif (a.charAt(ai) <= '9' && a.charAt(ai) >= '0') m = true;\n\t\t\t\telse\n\t\t\t\t\treturn 1;\n\t\t\t}\n\t\t\ta += \"!\";\n\t\t\tb += \"!\";\n\t\t\tint na = 0, nb = 0;\n\t\t\twhile (true) {\n\t\t\t\tif (a.charAt(ai) == '!') {\n\t\t\t\t\tif (b.charAt(bi) == '!') break;\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t\tif (b.charAt(bi) == '!') {\n\t\t\t\t\treturn 1;\n\t\t\t\t}\n\t\t\t\tif (m) {\n\t\t\t\t\tint ab = -1, bb = -1;\n\t\t\t\t\twhile (a.charAt(ai) <= '9' && a.charAt(ai) >= '0') {\n\t\t\t\t\t\tif (ab == -1) ab = ai;\n\t\t\t\t\t\tai++;\n\t\t\t\t\t}\n\t\t\t\t\twhile (b.charAt(bi) <= '9' && b.charAt(bi) >= '0') {\n\t\t\t\t\t\tif (bb == -1) bb = bi;\n\t\t\t\t\t\tbi++;\n\t\t\t\t\t}\n\t\t\t\t\tm = !m;\n\t\t\t\t\tif (ab == -1) {\n\t\t\t\t\t\tif (bb == -1) continue;\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\treturn 1;\n\t\t\t\t\t}\n\t\t\t\t\tif (bb == -1) return -1;\n\t\t\t\t\twhile (a.charAt(ab) == '0' && ab + 1 != ai) {\n\t\t\t\t\t\tab++;\n\t\t\t\t\t\tif (!ns) na++;\n\t\t\t\t\t}\n\t\t\t\t\twhile (b.charAt(bb) == '0' && bb + 1 != bi) {\n\t\t\t\t\t\tbb++;\n\t\t\t\t\t\tif (!ns) nb++;\n\t\t\t\t\t}\n\t\t\t\t\tif (na != nb) ns = true;\n\t\t\t\t\tif (ai - ab < bi - bb) return -1;\n\t\t\t\t\tif (ai - ab > bi - bb) return 1;\n\t\t\t\t\tfor (int i = 0; i < ai - ab; i++) {\n\t\t\t\t\t\tif (a.charAt(ab + i) < b.charAt(bb + i)) return -1;\n\t\t\t\t\t\tif (a.charAt(ab + i) > b.charAt(bb + i)) return 1;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tm = !m;\n\t\t\t\t\twhile (true) {\n\t\t\t\t\t\tif (a.charAt(ai) <= 'z' && a.charAt(ai) >= 'a' && b.charAt(bi) <= 'z' && b.charAt(bi) >= 'a') {\n\t\t\t\t\t\t\tif (a.charAt(ai) < b.charAt(bi)) return -1;\n\t\t\t\t\t\t\tif (a.charAt(ai) > b.charAt(bi)) return 1;\n\t\t\t\t\t\t\tai++;\n\t\t\t\t\t\t\tbi++;\n\t\t\t\t\t\t} else\n\t\t\t\t\t\t\tif (a.charAt(ai) <= 'z' && a.charAt(ai) >= 'a') return 1;\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\tif (b.charAt(bi) <= 'z' && b.charAt(bi) >= 'a') return -1;\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (na < nb) return 1;\n\t\t\tif (na > nb) return -1;\n\t\t\treturn 0;\n\t\t}\n\t}\n\t\n\tvoid mpr(int x) {\n\t\tout.print(' ');\n\t\tif (x < 100) out.print(' ');\n\t\tif (x < 10) out.print(' ');\n\t\tout.print(x);\n\t}\n\t\n\tint mtry(String s, String alph) {\n\t\tString t = \"\";\n\t\tRandom r = new Random();\n\t\tint c = 0, l = alph.length();\n\t\tfor (int i = 0; i < s.length(); i++) {\n\t\t\tt += alph.charAt(r.nextInt(l));\n\t\t\tc++;\n\t\t}\n\t\twhile (!t.equals(s)) {\n\t\t\tt = t.substring(1);\n\t\t\tt += alph.charAt(r.nextInt(l));\n\t\t\tc++;\n\t\t}\n\t\treturn c;\n\t}\n\t\n\tHashtable tab;\n\t\n\tvoid mtest(String s, String alph, int d) {\n\t\tint n = d, r = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tr += mtry(s, alph);\n\t\t}\n\t\tint re = (int) Math.round((0.0 + r) / n);\n\t\tout.println(\"\\\"\" + s + \"\\\" = \" + re + \", Average = \" + ((0.0 + r) / n));\n/*\t\tString res = Integer.toString(re);\n\t\tif (!tab.contains(res)) {\n\t\t\ttab.put(res, new Vector());\n\t\t}\n\t\ttab.get(res).add(s);*/\n\t}\n\t\n\tvoid solve() throws IOException {\n /*\n * String[] st = new String[52000]; in.resetSyntax(); in.wordChars(' ' +\n * 1, 255); in.whitespaceChars(0, ' '); int n = 0; while (true) { String\n * t = nextString(); if (in.ttype == StreamTokenizer.TT_EOF) break;\n * st[n] = t; n++; } st = Arrays.copyOf(st, n); Arrays.sort(st, new\n * japaneeseComparator()); for (int i = 0; i < n; i++) {\n * out.println(st[i]); }\n */\n int w = nextInt();\n if (w == 2) {\n \tout.print(\"NO\");\n \treturn;\n }\n if (w % 2 == 0) out.print(\"YES\"); else out.print(\"NO\");\n }\n}\n\n\n", "lang_cluster": "Java", "tags": ["brute force", "math"], "code_uid": "601f11cba05cb007299c6c536876ca63", "src_uid": "230a3c4d7090401e5fa3c6b9d994cdf2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Pascal {\n\n static PrintWriter out = new PrintWriter(System.out);\n static BufferedReader br;\n static StringTokenizer st;\n\n\n public static void main(String[] args) throws IOException {\n br = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter out = new PrintWriter(System.out);\n int n = nextInt();\n int k = nextInt();\n int min = Integer.MAX_VALUE;\n for (int i = 1; i < k; i++) {\n if (n % i == 0) {\n int x = (n / (i % k)) * k + i;\n if(x < min) min = x;\n }\n }\n out.print(min);\n out.close();\n }\n\n static int nextInt() throws IOException {\n if (st == null || !st.hasMoreElements()) st = new StringTokenizer(br.readLine());\n return Integer.parseInt(st.nextToken());\n }\n\n static long nextLong() throws IOException {\n if (st == null || !st.hasMoreElements()) st = new StringTokenizer(br.readLine());\n return Long.parseLong(st.nextToken());\n }\n\n static String next() throws IOException {\n if (st == null || !st.hasMoreElements()) st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n}\n\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "49013fa3fea701a5c49bd1a4d423301f", "src_uid": "ed0ebc1e484fcaea875355b5b7944c57", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/*package whatever //do not write package name here */\n\nimport java.io.*;\nimport java.util.*;\n\npublic class GFG {\n\tpublic static void main (String[] args) {\n\t Scanner s = new Scanner(System.in);\n\t int a = s.nextInt();\n\t int b = s.nextInt();\n\t int c = s.nextInt();\n\t int d = s.nextInt();\n\t int e = s.nextInt();\n\t int f = s.nextInt();\n\t int cost=0;\n\t if(e0) {\n\t cost=cost+(int)Math.min(a,d)*e; \n\t }\n\t \n\t System.out.println(cost);\n\t }\n\t else {\n\t int min = (int)Math.min(a,d);\n\t \n\t cost=min*e;\n\t \n\t d=d-min;\n\t if(d>0) {\n\t min = (int)Math.min(b,c);\n\t \n\t cost=cost+(int)Math.min(min,d)*f; \n\t }\n\t \n\t System.out.println(cost);\n\t }\n\t \n\t}\n}", "lang_cluster": "Java", "tags": ["math", "greedy", "brute force"], "code_uid": "0c4ffd9812aebaf69b823b7845f7cfa5", "src_uid": "84d9e7e9c9541d997e6573edb421ae0a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\n\nimport static java.lang.Math.*;\n\npublic class solution implements Runnable {\n\n\tpublic long bin_pow(long a, long n) {\n\t\tlong res = 1;\n\t\twhile (n > 0) {\n\t\t\tif ((n & 1) == 1)\n\t\t\t\tres = (res * a) % 1000000009;\n\t\t\ta = (a * a) % 1000000009;\n\t\t\tn >>= 1;\n\t\t}\n\t\treturn res;\n\t}\n\n\tpublic void solve() throws Exception {\n\t\tlong n = sc.nextLong();\n\t\tlong m = sc.nextLong();\n\t\tlong k = sc.nextLong();\n\t\tlong ans = 0;\n\t\tlong l = -1, r = (n + k - 1) / k;\n\t\twhile (r - l > 1) {\n\t\t\tlong me = (l + r) / 2;\n\t\t\tif (((n - k * me) / k) * (k - 1) + ((n - k * me) % k) >= m - k * me)\n\t\t\t\tr = me;\n\t\t\telse\n\t\t\t\tl = me;\n\t\t}\n\t\tl = r;\n\t\tans = (bin_pow(2, l + 1) - 2 + 1000000009) % 1000000009;\n\t\tans = ((ans * k) % 1000000009 + m - k * l + 1000000009) % 1000000009;\n\t\tout.println(ans);\n\t}\n\t\n\tstatic Throwable throwable;\n\t\n\tBufferedReader in;\n\tFastScanner sc;\n\tPrintWriter out;\n\t\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsc = new FastScanner(in);\n\t\t\tsolve();\n\t\t} catch (Throwable throwable) {\n\t\t\tsolution.throwable = throwable;\n\t\t} finally {\n\t\t\tout.close();\n\t\t}\t\t\n\t}\n\t\n\tpublic static void main(String[] args) throws Throwable {\n\t\tThread thread = new Thread(null, new solution(), \"\", (1 << 26));\n\t\tthread.start();\n\t\tthread.join();\n\t\tif (solution.throwable != null)\n\t\t\tthrow throwable;\n\t}\n\t\n}\n\nclass FastScanner {\n\tBufferedReader reader;\n\tStringTokenizer str;\n\t\n\tpublic FastScanner(BufferedReader re) {\n\t\tthis.reader = re;\n\t}\n\t\n\tpublic String nextToken() throws Exception {\n\t\twhile (str == null || !str.hasMoreTokens()) {\n\t\t\tstr = new StringTokenizer(reader.readLine());\n\t\t}\n\t\treturn str.nextToken();\n\t}\n\t\n\tpublic int nextInt() throws Exception {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\t\n\tpublic long nextLong() throws Exception {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\t\n\tpublic double nextDouble() throws Exception {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "binary search", "number theory", "greedy", "matrices"], "code_uid": "c46eb54066e9fcaa38e0364a044f8a79", "src_uid": "9cc1aecd70ed54400821c290e2c8018e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Run {\n\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner input = new Scanner(System.in);\n\t\tString wholeInput = input.nextLine();\n\t\tString[] token = wholeInput.split(\" \");\n\t\tint n = Integer.valueOf(token[0]);\n\t\tint m = Integer.valueOf(token[1]);\n\t\twholeInput = input.nextLine();\n\t\ttoken = wholeInput.split(\" \");\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\ta[i] = Integer.valueOf(token[i]);\n\t\t}\n\t\tinput.close();\n\t\ttoken = null;\n\t\tint S = 0;\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tS += a[i];\n\t\t}\n\t\tif (m > S)\n\t\t{\n\t\t\tSystem.out.print(-1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tSystem.out.print(solve(1, m, m, a));\n\t\t}\n\t}\n\t\n\tprivate static boolean checkAnswer(int m, int day, int[] a)\n\t{\n\t\tfor (int i = 0; i < a.length; i++)\n\t\t{\n\t\t\ta[i] = -a[i];\n\t\t}\n\t\tArrays.sort(a);\n\t\tfor (int i = 0; i < a.length; i++)\n\t\t{\n\t\t\ta[i] = -a[i];\n\t\t}\n\t\tint arrayMarker = 0;\n\t\tint cupMarker = 0;\n\t\tint S = 0;\n\t\twhile(true)\n\t\t{\n\t\t\tif (a[arrayMarker] - cupMarker > 0)\n\t\t\t{\n\t\t\t\tS += a[arrayMarker] - cupMarker;\n\t\t\t}\n\t\t\tarrayMarker++;\n\t\t\tif (arrayMarker % day == 0)\n\t\t\t{\n\t\t\t\tcupMarker++;\n\t\t\t}\n\t\t\tif (arrayMarker == a.length)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (S >= m)\n\t\t{\n\t\t\treturn true;\n\t\t}\n\t\telse\n\t\t{\n\t\t\treturn false;\n\t\t}\n\t}\n\t\n\tprivate static int solve(int tempPos, int length, int m, int[] a)\n\t{\n\t\tint checkPos = tempPos + length / 2;\n\t\tif (length == 0)\n\t\t{\n\t\t\treturn tempPos;\n\t\t}\n\t\tif (checkAnswer(m, checkPos, a))\n\t\t{\n\t\t\treturn solve(tempPos, checkPos - tempPos, m, a);\n\t\t}\n\t\telse\n\t\t{\n\t\t\treturn solve(checkPos + 1, tempPos + length - checkPos - 1, m, a);\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["brute force", "greedy"], "code_uid": "fad84375b84fff997423be3ca94b70cc", "src_uid": "acb8a57c8cfdb849a55fa65aff86628d", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class DIV64 {\n\tpublic static void main(String args[])\n\t{\n\t\tScanner sc=new Scanner(System.in);\n\t\tString s=sc.nextLine();\n\t\tint c1=0,c0=0;\n\t\tint i=0;\n\t\twhile( i=6 & c1>=1)\n\t\t\tSystem.out.println(\"yes\");\n\t\telse System.out.println(\"no\");\n\t\tsc.close();\n\t}\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "6daf64d52d1a4ee40b4ce4d986c6cf7d", "src_uid": "88364b8d71f2ce2b90bdfaa729eb92ca", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class Main {\n\n static Scanner input = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n\n public static void main(String[] args) {\n int n = input.nextInt();\n String s = input.next();\n int x = 0, y = 0;\n for (int i = 0; i < n; i++) {\n switch (s.charAt(i)) {\n case 'U':\n y++;\n break;\n case 'L':\n x--;\n break;\n case 'D':\n y--;\n break;\n case 'R':\n x++;\n break;\n }\n }\n System.out.println(n - Math.abs(x) - Math.abs(y));\n }\n}", "lang_cluster": "Java", "tags": ["greedy"], "code_uid": "2ec47de358cbf09b82afa5c083a06300", "src_uid": "b9fa2bb8001bd064ede531a5281cfd8a", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\n\npublic class A {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n char[][][] cs = new char[20][8][8];\n for(int i = 0; i < 8; i++) {\n cs[0][i] = sc.next().toCharArray();\n }\n \n for(int i = 0; i < 19; i++) {\n for(int y = 0; y < 8; y++)\n for(int x = 0; x < 8; x++)\n if(cs[i][y][x] == 'M')\n for(int dy = -1; dy <= 1; dy++)\n for(int dx = -1; dx <= 1; dx++) {\n final int xx = x+dx;\n final int yy = y+dy;\n if(0 <= xx && xx < 8 && 0 <= yy && yy < 8 && cs[i][yy][xx] != 'S')\n cs[i+1][yy][xx] = 'M';\n }\n \n for(int y = 6; y >= 0; y--)\n for(int x = 0; x < 8; x++)\n if(cs[i][y][x] == 'S')\n cs[i+1][y+1][x] = 'S';\n }\n \n String res = \"LOSE\";\n for(int y = 0; y < 8; y++)\n for(int x = 0; x < 8; x++)\n if(cs[19][y][x] == 'M')\n res = \"WIN\";\n System.out.println(res);\n }\n}\n", "lang_cluster": "Java", "tags": ["dfs and similar"], "code_uid": "e8f39831e08ad1e169360d51b0c13407", "src_uid": "f47e4ab041288ba9567c19930eb9a090", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\n\nimport java.io.*;\nimport java.util.Locale;\nimport java.util.StringTokenizer;\n\npublic class SolutionTest implements Runnable {\n\n BufferedReader in;\n PrintWriter out;\n StringTokenizer tok = new StringTokenizer(\"\");\n\n public static void main(String[] args) {\n new Thread(null, new SolutionTest(), \"\", 256 * (1L << 20)).start();\n }\n\n public void run() {\n try {\n long t1 = System.currentTimeMillis();\n// in = new BufferedReader(new FileReader(\"src/codeforces/input.txt\"));\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(new OutputStreamWriter(System.out));\n Locale.setDefault(Locale.US);\n solve();\n in.close();\n out.close();\n long t2 = System.currentTimeMillis();\n System.err.println(\"Time = \" + (t2 - t1));\n } catch (Throwable t) {\n t.printStackTrace(System.err);\n System.exit(-1);\n }\n }\n\n String readString() throws IOException {\n while (!tok.hasMoreTokens()) {\n tok = new StringTokenizer(in.readLine());\n }\n return tok.nextToken();\n }\n\n int readInt() throws IOException {\n return Integer.parseInt(readString());\n }\n\n // solution\n void solve() throws IOException {\n out.println(dieRoll9A());\n }\n\n private String dieRoll9A() throws IOException {\n int y = readInt();\n int w = readInt();\n switch (Math.max(y, w)) {\n case 1:\n return \"1/1\";\n case 2:\n return \"5/6\";\n case 3:\n return \"2/3\";\n case 4:\n return \"1/2\";\n case 5:\n return \"1/3\";\n default:\n return \"1/6\";\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "probabilities"], "code_uid": "865c7c5f2a50a34a23f0a2101801acc6", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Main {\n Scanner in;\n PrintWriter out;\n StreamTokenizer ST;\n BufferedReader br;\n\n int nextInt() throws IOException {\n ST.nextToken();\n return (int) ST.nval;\n }\n\n double nextDouble() throws IOException {\n ST.nextToken();\n return ST.nval;\n }\n\n String next() throws IOException {\n ST.nextToken();\n return ST.sval;\n }\n\n String nextLine() throws IOException {\n return br.readLine();\n }\n\n void solve() throws IOException {\n int n = nextInt();\n for(int i=1;i<=n;++i)\n {\n if (i*(i+1)/2==n)\n {\n out.println(\"YES\");\n return;\n }\n }\n out.println(\"NO\");\n }\n\n public void run() throws IOException {\n // br = new BufferedReader(new FileReader(new File(\"input.txt\")));\n br = new BufferedReader(new InputStreamReader(System.in));\n ST = new StreamTokenizer(br);\n in = new Scanner(br);\n out = new PrintWriter(System.out);\n // out = new PrintWriter(new FileWriter(new File(\"output.txt\")));\n solve();\n in.close();\n out.close();\n br.close();\n }\n\n public static void main(String[] args) throws Exception {\n new Main().run();\n }\n\n}", "lang_cluster": "Java", "tags": ["brute force", "math"], "code_uid": "2f43c91be97bfba98c60caa360ccacff", "src_uid": "587d4775dbd6a41fc9e4b81f71da7301", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Comparator;\nimport java.util.Random;\nimport java.util.StringTokenizer;\n\n/**\n * @author Polyarniy Nickolay\n */\npublic class ProblemB {\n\n private BufferedReader in;\n private PrintWriter out;\n private StringTokenizer tok;\n private final String DELIMETER = \" \";\n private final boolean ENABLE_MULTITEST = false;\n private final boolean DEBUG = true;\n private final String FILENAME = null;//if FILENAME = null, then works with console\n\n public void run() throws Exception {\n initInputOutput();\n do {\n init();\n solve();\n } while (hasMoreTokens() && ENABLE_MULTITEST);\n finish();\n }\n\n private void init() throws Exception {\n }\n\n private void solve() throws Exception {\n long n = nextInt();\n long m = nextInt();\n long x = nextInt();\n long y = nextInt();\n long a = nextInt();\n long b = nextInt();\n long nod = nod(a, b);\n a = a / nod;\n b = b / nod;\n\n long w = 0;\n long h = 0;\n long pow = 1000000000;\n while (pow != 0) {\n while (w + a * pow <= n && h + b * pow <= m) {\n w = w + a * pow;\n h = h + b * pow;\n }\n pow /= 2;\n }\n long x1;\n if (w % 2 == 0) {\n long x1Mid = x - w / 2;\n long x1Max = n - w;\n long x1Min = 0;\n x1 = Math.max(Math.min(x1Mid, x1Max), x1Min);\n } else {\n long x1Mid = x - (w + 1) / 2;\n long x1Max = n - w;\n long x1Min = 0;\n x1 = Math.max(Math.min(x1Mid, x1Max), x1Min);\n }\n long y1;\n if (h % 2 == 0) {\n long y1Mid = y - h / 2;\n long y1Max = m - h;\n long y1Min = 0;\n y1 = Math.max(Math.min(y1Mid, y1Max), y1Min);\n } else {\n long y1Mid = y - (h + 1) / 2;\n long y1Max = m - h;\n long y1Min = 0;\n y1 = Math.max(Math.min(y1Mid, y1Max), y1Min);\n }\n out.println(x1 + \" \" + y1 + \" \" + (x1 + w) + \" \" + (y1 + h));\n }\n\n private long nod(long a, long b) {\n if (a == 0 || a == b) {\n return b;\n } else if (b == 0)\n return a;\n if (a > b) {\n return nod(a % b, b);\n } else return nod(b % a, a);\n }\n\n public static void main(String[] args) throws Exception {\n ProblemB solution = new ProblemB();\n solution.run();\n }\n\n private void initInputOutput() throws Exception {\n if (FILENAME == null) {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n } else {\n in = new BufferedReader(new FileReader(\"input.txt\"));\n out = new PrintWriter(\"output.txt\");\n }\n }\n\n private void shuffleArray(Object[] arr) {\n Random r = new Random();\n for (int i = 0; i < arr.length; ++i) {\n Object tmp = arr[i];\n int j = r.nextInt(arr.length);\n arr[i] = arr[j];\n arr[j] = tmp;\n }\n }\n\n private void shuffleArray(int[] arr) {\n Random r = new Random();\n for (int i = 0; i < arr.length; ++i) {\n int tmp = arr[i];\n int j = r.nextInt(arr.length);\n arr[i] = arr[j];\n arr[j] = tmp;\n }\n }\n\n private int[] nextArrayInt(int n) throws Exception {\n int[] res = new int[n];\n for (int i = 0; i < n; i++) {\n res[i] = nextInt();\n }\n return res;\n }\n\n private String nextWord() throws Exception {\n if (updateTokenizer()) {\n return null;\n } else {\n return tok.nextToken();\n }\n }\n\n private boolean hasMoreTokens() throws Exception {\n return !updateTokenizer();\n }\n\n private boolean updateTokenizer() throws Exception {\n while (tok == null || !tok.hasMoreTokens()) {\n String nextLine = in.readLine();\n if (nextLine == null || nextLine.isEmpty()) {\n return true;\n }\n tok = new StringTokenizer(nextLine, DELIMETER);\n }\n return false;\n }\n\n private int nextInt() throws Exception {\n return Integer.parseInt(nextWord());\n }\n\n private long nextLong() throws Exception {\n return Long.parseLong(nextWord());\n }\n\n private void finish() throws Exception {\n in.close();\n out.close();\n }\n\n private void print(String s) {\n if (DEBUG) {\n System.out.print(s);\n }\n }\n\n private void println(String s) {\n if (DEBUG) {\n System.out.println(s);\n }\n }\n\n private void println() {\n if (DEBUG) {\n System.out.println();\n }\n }\n\n private long[] getFirstSimpleNums(int n) {\n boolean[] notPr = new boolean[n];\n int res = n;\n notPr[0] = true;\n res--;\n notPr[1] = true;\n res--;\n for (int i = 2; i < n; ++i) {\n if (!notPr[i]) {\n for (int j = i + i; j < n; j += i) {\n if (!notPr[j]) {\n notPr[j] = true;\n res--;\n }\n }\n }\n }\n long[] resA = new long[res];\n int next = 0;\n for (int i = 0; i < n; i++) {\n if (!notPr[i]) {\n resA[next] = i;\n next++;\n }\n }\n return resA;\n }\n\n private static class Pair {\n\n int a;\n int b;\n\n public Pair(int a, int b) {\n this.a = a;\n this.b = b;\n }\n\n public static final Comparator comparator = new Comparator() {\n\n @Override\n public int compare(Pair pair1, Pair pair2) {\n return (pair1.a - pair2.a) != 0 ? (pair1.a - pair2.a) : (pair1.b - pair2.b);\n }\n };\n\n @Override\n public String toString() {\n return \"{\" + a + \"|\" + b + '}';\n }\n }\n\n class TreeMin {\n\n int n;\n int[] t;\n\n public TreeMin(int size, int[] defaultValue) {\n n = 1;\n while (n < size) {\n n *= 2;\n }\n t = new int[2 * n];\n for (int i = 0; i < defaultValue.length; i++) {\n t[n + i] = defaultValue[i];\n }\n for (int i = defaultValue.length; i < n; i++) {\n t[n + i] = Integer.MAX_VALUE;\n }\n for (int i = n - 1; i >= 1; i--) {\n t[i] = Math.min(t[2 * i], t[2 * i + 1]);\n }\n }\n\n public void set(int index, int value) {\n index += n;\n t[index] = value;\n index /= 2;\n while (index >= 1) {\n t[index] = Math.min(t[2 * index], t[2 * index + 1]);\n index /= 2;\n }\n }\n\n /**\n * @param l inclusive\n * @param r exclusive\n */\n public int getMin(int l, int r) {\n int min = Integer.MAX_VALUE;\n l += n;\n r += n;\n while (l <= r) {\n if (l % 2 == 1) {\n min = Math.min(min, t[l]);\n l++;\n }\n if (r % 2 == 0) {\n min = Math.min(min, t[r]);\n r--;\n }\n l /= 2;\n r /= 2;\n }\n return min;\n }\n }\n\n class PriorityQueue {\n\n int size = 0;\n int capacity = 5;\n int[] key = new int[capacity];\n int[] value = new int[capacity];\n int[] idByInd = new int[capacity];\n int nextID = 0;\n ArrayList indById = new ArrayList();\n\n void ensureCapacity(int newSize) {\n if (newSize > capacity) {\n key = increaseArray(key);\n value = increaseArray(value);\n idByInd = increaseArray(idByInd);\n capacity = key.length;\n }\n }\n\n int[] increaseArray(int[] a) {\n int[] res = new int[Math.max(a.length * 2, 1)];\n for (int i = 0; i < a.length; i++) {\n res[i] = a[i];\n }\n for (int i = a.length; i < res.length; i++) {\n res[i] = Integer.MAX_VALUE;\n }\n return res;\n }\n\n void swap(int ind1, int ind2) {\n swap(key, ind1, ind2);\n swap(value, ind1, ind2);\n int id1 = idByInd[ind1];\n int id2 = idByInd[ind2];\n swap(idByInd, ind1, ind2);\n swap(indById, id1, id2);\n }\n\n void swap(int[] a, int ind1, int ind2) {\n int tmp = a[ind1];\n a[ind1] = a[ind2];\n a[ind2] = tmp;\n }\n\n void swap(ArrayList a, int ind1, int ind2) {\n int tmp = a.get(ind1);\n a.set(ind1, a.get(ind2));\n a.set(ind2, tmp);\n }\n\n int parent(int index) {\n return (index - 1) / 2;\n }\n\n private void siftUp(int index) {\n while (index > 0) {\n int parent = parent(index);\n if (key[index] < key[parent]) {\n swap(index, parent);\n }\n index = parent;\n }\n }\n\n private void siftDown(int index) {\n while (true) {\n int ch1 = 2 * index + 1;\n int ch2 = 2 * index + 2;\n if (ch1 >= size) {\n ch1 = index;\n }\n if (ch2 >= size) {\n ch2 = ch1;\n }\n int toSwap = index;\n if (key[ch1] < key[toSwap]) {\n toSwap = ch1;\n }\n if (key[ch2] < key[toSwap]) {\n toSwap = ch2;\n }\n if (toSwap == index) {\n break;\n } else {\n swap(index, toSwap);\n index = toSwap;\n }\n }\n }\n\n public int push(int key, int value) {\n size++;\n ensureCapacity(size);\n int id = nextID;\n nextID++;\n this.key[size - 1] = key;\n this.value[size - 1] = value;\n this.idByInd[size - 1] = id;\n indById.add(size - 1);\n siftUp(size - 1);\n return id;\n }\n\n public void decreaseKey(int id, int key) {\n int ind = indById.get(id);\n while (key > this.key[ind]) {\n }\n this.key[ind] = key;\n siftUp(ind);\n }\n\n public final int EMPTY = Integer.MIN_VALUE;\n\n public int extractMinKey() {\n if (size == 0) {\n return EMPTY;\n } else {\n int res = key[0];\n swap(0, size - 1);\n size--;\n siftDown(0);\n return res;\n }\n }\n// public String toString() {\n// String res = \"{\" + \"size=\" + size + \"|k,v|\";\n// for (int i = 0; i < size; i++) {\n// res += key[i]+\"(\"+idByInd[i]+\") \";// + \",\" + value[i];\n// }\n// res += \"}\";\n// return res;\n// }\n }\n// /**\n// * Examples(n: res):\n// * 0: 0\n// * 1: 0\n// * 2: 1\n// * 3: 2\n// * 4: 2\n// * 5: 3\n// * 7: 3\n// * 8: 3\n// * 10:4\n// */\n// public static int logCeil(int n) {\n// int res = 0;\n// int pow = 1;\n// while (pow < n) {\n// pow *= 2;\n// res++;\n// }\n// return res;\n// }\n//\n// private static class Tree {\n//\n// Object[] t;\n// Object[] push;\n// int n;\n// int capacity;\n// TreeType tree;\n//\n// public Tree(int capacity, T[] a, TreeType tree) {\n// this.tree = tree;\n// n = 1;\n// while (n < capacity) {\n// n *= 2;\n// }\n// t = new Object[2 * n];\n// push = new Object[n];\n// this.capacity = capacity;\n// System.arraycopy(a, 0, t, n, capacity);\n// for (int i = n - 1; i >= 1; i--) {\n// t[i] = tree.calc((T) t[i * 2], (T) t[i * 2 + 1]);\n// }\n// }\n//\n// public T getOnRange(int l, int r) {\n// l += n;\n// r += n;\n// return getOnRange(l, r, 1, n, 2 * n - 1);\n// }\n//\n// public T getOnRange(int l, int r, int cur, int rl, int rr) {\n// if (cur >= n) {\n// return (T) t[cur];\n// }\n// push(cur);\n// if (l == rl && r == rr) {\n// return (T) t[cur];\n// }\n// int m = (rl + rr) / 2;\n// T res = null;\n// if (l <= m) {\n// res = tree.sum(res, getOnRange(l, Math.min(m, r), 2 * cur, rl, m));\n// }\n// if (r >= m + 1) {\n// res = tree.sum(res, getOnRange(Math.max(m + 1, l), r, 2 * cur + 1, m + 1, rr));\n// }\n// return res;\n// }\n//\n// public T get(int ind) {\n// int cur = 1;\n// int rl = n;\n// int rr = 2 * n - 1;\n// while (cur < n) {\n// push(cur);\n// int m = (rl + rr) / 2;\n// if (ind <= m) {\n// cur = 2 * ind;\n// rr = m;\n// } else {\n// cur = 2 * ind + 1;\n// rl = m + 1;\n// }\n// }\n// return (T) t[cur];\n// }\n//\n// public void add(T x, int ind) {\n// int cur = 1;\n// int rl = n;\n// int rr = 2 * n - 1;\n// while (cur < n) {\n// push(cur);\n// int m = (rl + rr) / 2;\n// if (ind <= m) {\n// cur = 2 * ind;\n// rr = m;\n// } else {\n// cur = 2 * ind + 1;\n// rl = m + 1;\n// }\n// }\n// t[cur] = tree.calc((T) t[cur], x);\n// }\n//\n// private void push(int cur) {\n// if (!tree.isEmpty((T) push[cur])) {\n// for (int ch = 0; ch <= 1; ch++) {\n// if (2 * cur + ch < n) {\n// push[2 * cur + ch] = tree.calc((T)push[2 * cur + ch], (T)push[cur]);\n// } else {\n// t[2 * cur + ch] = tree.calc((T)t[2 * cur + ch], (T)push[cur]);\n// }\n// }\n// push[cur] = null;\n// }\n// }\n// }\n//\n// private static interface TreeType {\n//\n// public T calc(T a, T b);\n//\n// public boolean isEmpty(T push);\n// }\n}", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "155b3bedf80a11f57a1c941d7a965c80", "src_uid": "8f1211b995f35462ae83b2be27f54585", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Codeforces {\n \n public static int count(String p){\n\t\tint counts=0;\n\t\tfor(int i=p.length()-1;i>=0;i--){\n\t\t\t\n\t\t\tif(p.charAt(i)!='0')\n\t\t\t\treturn counts;\n\t\t\telse\n\t\t\t\tcounts++;\n\t\t\t\t\n\t\t}\n\t\t\n\t\treturn counts;\n\t}\n\t\t\n\tpublic static void main(String[] args) {\n\t\n\t\tScanner sc=new Scanner(System.in);\n\t\t\t\t\t\t\n\t\t\n\t\tlong n=sc.nextLong();\n\t\tint k=sc.nextInt();\n\t\t\n\t\tString p=\"\"+n;\n\t\t\n\t\t\n\t\tif(count(p)>=k)\n\t\t\tSystem.out.println(n);\n\t\telse{\n\t\t\t//System.out.println(\"not term at first\");\n\t\t\t\n\t\t\tint last=Integer.parseInt(\"\"+p.charAt(p.length()-1));\n\t\t\t\n\t\t\tif(last==1 || last==3 || last==7 || last==9){\n\t\t\t\t\n\t\t\t\tfor(int i=1;i<=k;i++)\n\t\t\t\t\tp=p+\"0\";\n\t\t\t\t\n\t\t\t\tSystem.out.println(p);\n\t\t\t\t\n\t\t\t}\n\t\t\telse{\n\t\t\t\t\n\t\t\t\twhile(count(p)=0;i--){\n\t\t\t\n\t\t\t\t\t\tif(p.charAt(i)!='0'){\n\t\t\t\t\t\t\tindex=i;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tlast=Integer.parseInt(\"\"+p.charAt(index));\n\t\t\t\t\t//System.out.println(\"last is \"+last);\n\t\t\t\t\tif(last==2 || last==4 || last==6 || last==8){\n\t\t\t\t\t\tn=n*5;\n\t\t\t\t\t\tp=\"\"+n;\n\t\t\t\t\t}\n\t\t\t\t\telse if(last==5){\n\t\t\t\t\t\tn=n*2;\n\t\t\t\t\t\tp=\"\"+n;\n\t\t\t\t\t}\n\t\t\t\t\telse if(last==1 || last==3 || last==7 || last==9){\n\t\t\t\t\t\tint rem=k-count(p);\n\t\t\t\t\t\tfor(int i=1;i<=rem;i++)\n\t\t\t\t\t\t\tp=p+\"0\";\n\t\t\t\t\t\t\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tSystem.out.println(p);\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "number theory"], "code_uid": "8e80c2eaaf4b77130f28a09407051dd9", "src_uid": "73566d4d9f20f7bbf71bc06bc9a4e9f3", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class Main {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n int n = in.nextInt();\n String b = \"+------------------------+\\n\" +\n \"|1.5.8.11.14.17.20.23.26.29.32.|D|)\\n\" +\n \"|2.6.9.12.15.18.21.24.27.30.33.|.|\\n\" +\n \"|3.......................|\\n\" +\n \"|4.7.10.13.16.19.22.25.28.31.34.|.|)\\n\" +\n \"+------------------------+\";\n\n for (int i = 34; i > n; i--) {\n b = b.replaceAll(String.valueOf(i), \"#\");\n }\n\n b = b.replaceAll(\"\\\\d+\", \"O\");\n\n out.println(b);\n out.close();\n }\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "d8892f31169e3e2cead9da31b4fdf8cf", "src_uid": "075f83248f6d4d012e0ca1547fc67993", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\npublic class VasyaTheHipster {\n\n\tpublic static void main(String[] args) {\n\t\tScanner scan=new Scanner(System.in);\n\t\tint n=scan.nextInt();\n\t\tint m=scan.nextInt();\n\t\tif(n>m) {\n\t\t\tSystem.out.println(m);\n\t\t\tn=n-m;\n\t\t\tSystem.out.println(n/2);\n\t\t}\n\t\telse if(m>n) {\n\t\t\tSystem.out.println(n);\n\t\t\tm=m-n;\n\t\t\tSystem.out.println(m/2);\n\t\t}\n\t\telse if(n==m) {\n\t\t\tSystem.out.println(n);\n\t\t System.out.println(n-m);\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "e5ef537428ef55a6ea95f661d7fa0a43", "src_uid": "775766790e91e539c1cfaa5030e5b955", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class Main\n{\n public static void main(String args[])throws IOException\n {\n BufferedReader obj=new BufferedReader(new InputStreamReader(System.in));\n String temp[]=obj.readLine().split(\" \");\n int arr[]=new int[temp.length];\n long total=0;\n for(int i=0;i 0) \n sum+=arr[j]; \n }\n if(total==2*sum)\n return true;\n }\n return false;\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "b0b63853591d70c309343eab34237110", "src_uid": "5a623c49cf7effacfb58bc82f8eaff37", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class a {\n\tpublic static void main(String[] args) { new a(); }\n\tFS in = new FS();\n\tPrintWriter out = new PrintWriter(System.out);\n\n\t\n\t\n\ta() {\n\t\tint x = in.nextInt();\n\t\tif (x == 2) out.println(2);\n\t\telse out.println(1);\n\t\tout.close();\n\t}\n\n\t\n\t\n\tint abs(int x) { if (x < 0) return -x; return x; }\n\tlong abs(long x) { if (x < 0) return -x; return x; }\n\tint max(int x, int y) { if (x < y) return y; return x; }\n\tint min(int x, int y) { if (x > y) return y; return x; }\n\tlong max(long x, long y) { if (x < y) return y; return x; }\n\tlong min(long x, long y) { if (x > y) return y; return x; }\n\n\tclass FS {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(\"\");\n\t\tString next() {\n\t\t\twhile (!st.hasMoreTokens()) {\n\t\t\t\ttry { st = new StringTokenizer(br.readLine()); }\n\t\t\t\tcatch (Exception e) {}\n\t\t\t} return st.nextToken();\n\t\t}\n\t\tint nextInt() { return Integer.parseInt(next()); }\n\t\tlong nextLong() { return Long.parseLong(next()); }\n\t\tdouble nextDouble() { return Double.parseDouble(next()); }\n\n\t\tvoid intArr(int sz, int[] x) { for (int i = 0; i < sz; i++) x[i] = nextInt(); }\n\t\tvoid longArr(int sz, long[] x) { for (int i = 0; i < sz; i++) x[i] = nextLong(); }\n\t\tvoid doubleArr(int sz, double[] x) { for (int i = 0; i < sz; i++) x[i] = nextDouble(); }\n\t}\n}\n\n", "lang_cluster": "Java", "tags": ["math", "constructive algorithms"], "code_uid": "18027834ac014bc2487e94c785fc9f1f", "src_uid": "c30b372a9cc0df4948dca48ef4c5d80d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "//package croc2012.qr;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\n\npublic class D {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint a = ni(), n = ni();\n\t\tint[] d = new int[a+n];\n\t\tfor(int i = 0;i < a+n;i++){\n\t\t\td[i] = i;\n\t\t}\n\t\tfor(int i = 2;i * i < a+n;i++){\n\t\t\tfor(int j = i*i;j < a+n;j+=i*i){\n\t\t\t\td[j] = j / (i*i);\n\t\t\t}\n\t\t}\n\t\t\n\t\tlong tot = 0;\n\t\tfor(int i = a;i < a+n;i++){\n\t\t\ttot += d[i];\n\t\t}\n\t\tout.println(tot);\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tnew D().run();\n\t}\n\t\n\tpublic int ni()\n\t{\n\t\ttry {\n\t\t\tint num = 0;\n\t\t\tboolean minus = false;\n\t\t\twhile((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));\n\t\t\tif(num == '-'){\n\t\t\t\tnum = 0;\n\t\t\t\tminus = true;\n\t\t\t}else{\n\t\t\t\tnum -= '0';\n\t\t\t}\n\t\t\t\n\t\t\twhile(true){\n\t\t\t\tint b = is.read();\n\t\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t}else{\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic long nl()\n\t{\n\t\ttry {\n\t\t\tlong num = 0;\n\t\t\tboolean minus = false;\n\t\t\twhile((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));\n\t\t\tif(num == '-'){\n\t\t\t\tnum = 0;\n\t\t\t\tminus = true;\n\t\t\t}else{\n\t\t\t\tnum -= '0';\n\t\t\t}\n\t\t\t\n\t\t\twhile(true){\n\t\t\t\tint b = is.read();\n\t\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t}else{\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic String ns()\n\t{\n\t\ttry{\n\t\t\tint b = 0;\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\twhile((b = is.read()) != -1 && (b == '\\r' || b == '\\n' || b == ' '));\n\t\t\tif(b == -1)return \"\";\n\t\t\tsb.append((char)b);\n\t\t\twhile(true){\n\t\t\t\tb = is.read();\n\t\t\t\tif(b == -1)return sb.toString();\n\t\t\t\tif(b == '\\r' || b == '\\n' || b == ' ')return sb.toString();\n\t\t\t\tsb.append((char)b);\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn \"\";\n\t}\n\t\n\tpublic char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\ttry{\n\t\t\tint b = 0, p = 0;\n\t\t\twhile((b = is.read()) != -1 && (b == ' ' || b == '\\r' || b == '\\n'));\n\t\t\tif(b == -1)return null;\n\t\t\tbuf[p++] = (char)b;\n\t\t\twhile(p < n){\n\t\t\t\tb = is.read();\n\t\t\t\tif(b == -1 || b == ' ' || b == '\\r' || b == '\\n')break;\n\t\t\t\tbuf[p++] = (char)b;\n\t\t\t}\n\t\t\treturn Arrays.copyOf(buf, p);\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn null;\n\t}\n\t\n\t\n\tdouble nd() { return Double.parseDouble(ns()); }\n\tboolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tvoid tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "tags": ["number theory"], "code_uid": "60c67f07e56ec29e51b8561376ed5f48", "src_uid": "915081861e391958dce6ee2a117abd4e", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "//package com.example.hackerranksolutions;\n\nimport java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.File;\nimport java.io.FileReader;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Scanner;\n\npublic class CodeforcesProblems {\n\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n String[] inputs = br.readLine().split(\" \");\n int a = Integer.parseInt(inputs[0]);\n int b = Integer.parseInt(inputs[1]);\n int r = Integer.parseInt(inputs[2]);\n\n if(a>=2*r && b>=2*r) System.out.println(\"First\");\n else System.out.println(\"Second\");\n }\n}", "lang_cluster": "Java", "tags": ["math", "constructive algorithms", "games"], "code_uid": "74ffa3cbcb44042fabeac82c71c6d750", "src_uid": "90b9ef939a13cf29715bc5bce26c9896", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class code{\n public static void main(String[] args)throws IOException{\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n char[] c = sc.next().toCharArray();\n int[] d = new int[n];\n for(int i=0;il;i--){\n if(c[r]==c[i]){\n dp[l][r] = Math.min(dp[l][r],dp[l][i-1]+dp[i][r-1]);\n }\n }\n }\n int get(int l,int r){\n return dp[q[l]][q[r-1]];\n }\n }\n\n}", "lang_cluster": "Java", "tags": ["dp"], "code_uid": "8c68adbdc25fa0204fa57ebc11d37f57", "src_uid": "516a89f4d1ae867fc1151becd92471e6", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class a {\n /*\n * In a Programming contest, you are expected to print the output at the\n * end, so `output` variable will hold all the processed results till the\n * end\n */\n public static String output = \"\";\n\n // Program's starting point\n public static void main(String[] args) {\n\n /*\n * A Scanner class slows down Input/Output a LOT ,thereby increasing\n * your code execution time , Hence for best results that is Fast I/O\n * try to use BufferedReader\n */\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n /*\n * Generally Code Chef, Hacker Rank gives X number of test cases so we\n * process the input for each.\n */\n final int n;\n try {\n n = Integer.parseInt(br.readLine().trim());\n int[][] uni = new int[n][2];\n for(int i = 0; i < n; i++) {\n String[] s = br.readLine().split(\" \");\n uni[i][0] = Integer.parseInt(s[0]);\n uni[i][1] = Integer.parseInt(s[1]);\n\n }\n\n /*\n * Logic of the program must be separated from the meta code to\n * increase readability and help debugging easier\n * Also note that Solver object is created inside for loop to\n * avoid multiple object creation that drastically increases\n * execution time and memory usage\n */\n Solver solver = new Solver();\n solver.solve(n, uni);\n\n } catch (IOException e) {\n // TODO Auto-generated catch block\n e.printStackTrace();\n }\n // Print the final output\n System.out.println(output);\n }\n}\n\nclass Solver {\n\n /*\n * Logic goes here ...\n * Add to the global variables after processing the input\n * Maybe reverse a string or parse to an integer or , etc.\n */\n public void solve(int n, int[][] uni) {\n int count = 0;\n for(int i = 0; i < n-1; i++) {\n for(int j = i+1; j < n; j++) {\n if(uni[i][0] == uni[j][1]) count++;\n if(uni[i][1] == uni[j][0]) count++;\n }\n }\n a.output = a.output.concat(String.valueOf(count));\n }\n\n}\n\n", "lang_cluster": "Java", "tags": ["brute force"], "code_uid": "2e18781ee10239c2277c14a0f9d7fe93", "src_uid": "745f81dcb4f23254bf6602f9f389771b", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\nimport static java.lang.Math.*;\nimport static java.util.Arrays.sort;\n\npublic class Codeforces {\n static FastReader fastReader;\n static PrintWriter out;\n\n public static void main(String[] args) {\n fastReader = new FastReader();\n out = new PrintWriter(System.out);\n int tt = 1;\n// int tt = fastReader.nextInt();\n outer:while(tt -- > 0) {\n long n = fastReader.nextLong();\n long x = fastReader.nextLong();\n Queue q = new LinkedList<>();\n q.add(x);\n HashMap map = new HashMap<>();\n map.put(x,0L);\n while(!q.isEmpty()){\n long cur = q.remove();\n String s = String.valueOf(cur);\n if(s.length() == n){\n out.println(map.get(cur));\n break outer;\n }\n for(int i = 0 ; i < s.length() ; i++){\n int mul = s.charAt(i) -'0';\n if(mul < 2) continue;\n long val = cur*(mul);\n if(!map.containsKey(val)){\n q.add(val);\n map.put(val,map.get(cur)+1);\n }\n }\n }\n out.println(-1);\n\n }\n out.close();\n }\n\n\n\n static class Pair{\n int index;\n int val;\n Pair(int index, int val){\n this.index = index;\n this.val = val;\n }\n\n @Override\n public String toString() {\n return \"Pair{\" +\n \"index=\" + index +\n \", val=\" + val +\n '}';\n }\n }\n\n\n // constants\n static final int IBIG = 1000000007;\n static final int IMAX = 2147483647;\n static final long LMAX = 9223372036854775807L;\n static Random __r = new Random();\n static int[][] direction = new int[][]{{-1,-1}, {-1,0}, {-1,1}, {0,1}, {1,1}, {1,0}, {1,-1}, {0, -1}};\n\n\n // math util\n static int minof(int a, int b, int c) {\n return min(a, min(b, c));\n }\n\n static int minof(int... x) {\n if (x.length == 1)\n return x[0];\n if (x.length == 2)\n return min(x[0], x[1]);\n if (x.length == 3)\n return min(x[0], min(x[1], x[2]));\n int min = x[0];\n for (int i = 1; i < x.length; ++i)\n if (x[i] < min)\n min = x[i];\n return min;\n }\n static char maxc(char a, char b){\n if(a > b){\n return a;\n }\n return b;\n }\n static long minof(long a, long b, long c) {\n return min(a, min(b, c));\n }\n\n static long minof(long... x) {\n if (x.length == 1)\n return x[0];\n if (x.length == 2)\n return min(x[0], x[1]);\n if (x.length == 3)\n return min(x[0], min(x[1], x[2]));\n long min = x[0];\n for (int i = 1; i < x.length; ++i)\n if (x[i] < min)\n min = x[i];\n return min;\n }\n\n static int maxof(int a, int b, int c) {\n return max(a, max(b, c));\n }\n\n static int maxof(int... x) {\n if (x.length == 1)\n return x[0];\n if (x.length == 2)\n return max(x[0], x[1]);\n if (x.length == 3)\n return max(x[0], max(x[1], x[2]));\n int max = x[0];\n for (int i = 1; i < x.length; ++i)\n if (x[i] > max)\n max = x[i];\n return max;\n }\n\n static long maxof(long a, long b, long c) {\n return max(a, max(b, c));\n }\n\n static long maxof(long... x) {\n if (x.length == 1)\n return x[0];\n if (x.length == 2)\n return max(x[0], x[1]);\n if (x.length == 3)\n return max(x[0], max(x[1], x[2]));\n long max = x[0];\n for (int i = 1; i < x.length; ++i)\n if (x[i] > max)\n max = x[i];\n return max;\n }\n\n static int powi(int a, int b) {\n if (a == 0)\n return 0;\n int ans = 1;\n while (b > 0) {\n if ((b & 1) > 0)\n ans *= a;\n a *= a;\n b >>= 1;\n }\n return ans;\n }\n\n static long powl(long a, int b) {\n if (a == 0)\n return 0;\n long ans = 1;\n while (b > 0) {\n if ((b & 1) > 0)\n ans *= a;\n a *= a;\n b >>= 1;\n }\n return ans;\n }\n\n static int fli(double d) {\n return (int) d;\n }\n\n static int cei(double d) {\n return (int) ceil(d);\n }\n\n static long fll(double d) {\n return (long) d;\n }\n\n static long cel(double d) {\n return (long) ceil(d);\n }\n\n static int gcd(int a, int b) {\n return b == 0 ? a : gcd(b, a % b);\n }\n\n static int lcm(int a, int b) {\n return (a / gcd(a, b)) * b;\n }\n\n static long gcd(long a, long b) {\n return b == 0 ? a : gcd(b, a % b);\n }\n\n static long lcm(long a, long b) {\n return (a / gcd(a, b)) * b;\n }\n\n static int[] exgcd(int a, int b) {\n if (b == 0)\n return new int[] { 1, 0 };\n int[] y = exgcd(b, a % b);\n return new int[] { y[1], y[0] - y[1] * (a / b) };\n }\n\n static long[] exgcd(long a, long b) {\n if (b == 0)\n return new long[] { 1, 0 };\n long[] y = exgcd(b, a % b);\n return new long[] { y[1], y[0] - y[1] * (a / b) };\n }\n\n static int randInt(int min, int max) {\n return __r.nextInt(max - min + 1) + min;\n }\n\n static long mix(long x) {\n x += 0x9e3779b97f4a7c15L;\n x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9L;\n x = (x ^ (x >> 27)) * 0x94d049bb133111ebL;\n return x ^ (x >> 31);\n }\n\n public static boolean[] findPrimes(int limit) {\n assert limit >= 2;\n\n final boolean[] nonPrimes = new boolean[limit];\n nonPrimes[0] = true;\n nonPrimes[1] = true;\n\n int sqrt = (int) Math.sqrt(limit);\n for (int i = 2; i <= sqrt; i++) {\n if (nonPrimes[i])\n continue;\n for (int j = i; j < limit; j += i) {\n if (!nonPrimes[j] && i != j)\n nonPrimes[j] = true;\n }\n }\n\n return nonPrimes;\n }\n\n // array util\n static void reverse(int[] a) {\n for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {\n int swap = a[i];\n a[i] = a[n - i - 1];\n a[n - i - 1] = swap;\n }\n }\n\n static void reverse(long[] a) {\n for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {\n long swap = a[i];\n a[i] = a[n - i - 1];\n a[n - i - 1] = swap;\n }\n }\n\n static void reverse(double[] a) {\n for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {\n double swap = a[i];\n a[i] = a[n - i - 1];\n a[n - i - 1] = swap;\n }\n }\n\n static void reverse(char[] a) {\n for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {\n char swap = a[i];\n a[i] = a[n - i - 1];\n a[n - i - 1] = swap;\n }\n }\n\n static void shuffle(int[] a) {\n int n = a.length - 1;\n for (int i = 0; i < n; ++i) {\n int ind = randInt(i, n);\n int swap = a[i];\n a[i] = a[ind];\n a[ind] = swap;\n }\n }\n\n static void shuffle(long[] a) {\n int n = a.length - 1;\n for (int i = 0; i < n; ++i) {\n int ind = randInt(i, n);\n long swap = a[i];\n a[i] = a[ind];\n a[ind] = swap;\n }\n }\n\n static void shuffle(double[] a) {\n int n = a.length - 1;\n for (int i = 0; i < n; ++i) {\n int ind = randInt(i, n);\n double swap = a[i];\n a[i] = a[ind];\n a[ind] = swap;\n }\n }\n\n static void rsort(int[] a) {\n shuffle(a);\n sort(a);\n }\n\n static void rsort(long[] a) {\n shuffle(a);\n sort(a);\n }\n\n static void rsort(double[] a) {\n shuffle(a);\n sort(a);\n }\n\n static int[] copy(int[] a) {\n int[] ans = new int[a.length];\n for (int i = 0; i < a.length; ++i)\n ans[i] = a[i];\n return ans;\n }\n\n static long[] copy(long[] a) {\n long[] ans = new long[a.length];\n for (int i = 0; i < a.length; ++i)\n ans[i] = a[i];\n return ans;\n }\n\n static double[] copy(double[] a) {\n double[] ans = new double[a.length];\n for (int i = 0; i < a.length; ++i)\n ans[i] = a[i];\n return ans;\n }\n\n static char[] copy(char[] a) {\n char[] ans = new char[a.length];\n for (int i = 0; i < a.length; ++i)\n ans[i] = a[i];\n return ans;\n }\n\n static class FastReader {\n\n BufferedReader br;\n StringTokenizer st;\n\n public FastReader() {\n br = new BufferedReader(\n new InputStreamReader(System.in));\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n int[] ria(int n) {\n int[] a = new int[n];\n for (int i = 0; i < n; i++)\n a[i] = Integer.parseInt(next());\n return a;\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n long[] rla(int n) {\n long[] a = new long[n];\n for (int i = 0; i < n; i++)\n a[i] = Long.parseLong(next());\n return a;\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "dfs and similar", "shortest paths", "dp", "data structures"], "code_uid": "b7282d4bca545d01d2e21c09dd472868", "src_uid": "cedcc3cee864bf8684148df93804d029", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.*;\n\npublic class cf113c {\n\tstatic int max = (int)3e8;\n\tstatic int halfmax = max/2;\n\tstatic byte[] seive;\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint a = in.nextInt();\n\t\tint b = in.nextInt();\n\t\tint ret = 0;\n\t\tif(a <= 2 && 2 <= b)\n\t\t\tret++;\n\t\twhile(a%4 != 1) a++;\n\t\tinit();\n\t\tfor(int i=a; i<=b; i+=4)\n\t\t\tif((seive[i>>4] & (1<<((i>>1)&7))) != 0)\n\t\t\t\tret++;\n\t\tSystem.out.println(ret);\n\t}\n\tstatic void init() {\n\t\tint maxsqrt = (int)(Math.sqrt(max)/2);\n\t\tseive = new byte[max/16 + 2];\n\t\tArrays.fill(seive, (byte)0xFF);\n\t\tseive[0] = (byte)0xFE;\n\t\tfor(int i=1; i>3] & (1<<(i&7)))!=0)\n\t\t\t\tfor(int j=i+i+i+1; j>3] &= ~(1<<(j&7));\n\t}\n\tstatic boolean isPrime(int n) {\n\t\treturn (seive[n>>4] & (1<<((n>>1)&7))) != 0;\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "number theory"], "code_uid": "e80370d12f4dc445bb35ef8c3898321c", "src_uid": "55a83526c10126ac3a6e6e5154b120d0", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.regex.*;\n\npublic class Solution {\n public static void main(String args[]){\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n int k=sc.nextInt();\n int a[]=new int[n];\n for(int i=0;i=a[i]){\n i++;c++;\n k1=1;\n }\n if(k>=a[j]){\n j--;\n c++;\n k1=1;\n }\n if(k1==0)\n break;\n \n }\n if(i==j){\n if(k>=a[i])\n c++;\n }\n \n System.out.println(c);\n\n}\n}\n", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "efc9ee6dfa6abc631fbc581152b7fba9", "src_uid": "ecf0ead308d8a581dd233160a7e38173", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.List;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.PriorityQueue;\nimport java.util.ArrayList;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.util.Queue;\nimport java.util.Collection;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskC2 solver = new TaskC2();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskC2 {\n\tstatic class Edge {\n\t\tint to, f, cap, cost, rev;\n\n\t\tEdge(int v, int cap, int cost, int rev) {\n\t\t\tthis.to = v;\n\t\t\tthis.cap = cap;\n\t\t\tthis.cost = cost;\n\t\t\tthis.rev = rev;\n\t\t}\n\t}\n\n\tpublic static List[] createGraph(int n) {\n\t\tList[] graph = new List[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tgraph[i] = new ArrayList();\n\t\treturn graph;\n\t}\n\n\tpublic static void addEdge(List[] graph, int s, int t, int cap, int cost) {\n\t\tgraph[s].add(new Edge(t, cap, cost, graph[t].size()));\n\t\tgraph[t].add(new Edge(s, 0, -cost, graph[s].size() - 1));\n\t}\n\n\tstatic int[] minCostFlow(List[] graph, int s, int t, int maxf) {\n\t\tint n = graph.length;\n\t\tint[] prio = new int[n];\n\t\tint[] curflow = new int[n];\n\t\tint[] prevedge = new int[n];\n\t\tint[] prevnode = new int[n];\n\t\tint[] pot = new int[n];\n\n\t\t// bellmanFord can be safely commented if edges costs are non-negative\n//\t\tbellmanFord(graph, s, pot);\n\t\tint flow = 0;\n\t\tint flowCost = 0;\n\t\twhile (flow < maxf) {\n\t\t\tQueue q = new PriorityQueue();\n\t\t\tq.add((long) s);\n\t\t\tArrays.fill(prio, 0, n, Integer.MAX_VALUE);\n\t\t\tprio[s] = 0;\n\t\t\tcurflow[s] = Integer.MAX_VALUE;\n\t\t\twhile (!q.isEmpty()) {\n\t\t\t\tlong cur = q.remove();\n\t\t\t\tint d = (int) (cur >>> 32);\n\t\t\t\tint u = (int) (cur & 0x7FFFFFFF);\n\t\t\t\tif (d != prio[u])\n\t\t\t\t\tcontinue;\n\t\t\t\tfor (int i = 0; i < graph[u].size(); i++) {\n\t\t\t\t\tEdge e = graph[u].get(i);\n\t\t\t\t\tint v = e.to;\n\t\t\t\t\tif (e.cap <= e.f)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tint nprio = prio[u] + e.cost + pot[u] - pot[v];\n\t\t\t\t\tif (prio[v] > nprio) {\n\t\t\t\t\t\tprio[v] = nprio;\n\t\t\t\t\t\tq.add(((long) nprio << 32) + v);\n\t\t\t\t\t\tprevnode[v] = u;\n\t\t\t\t\t\tprevedge[v] = i;\n\t\t\t\t\t\tcurflow[v] = Math.min(curflow[u], e.cap - e.f);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (prio[t] == Integer.MAX_VALUE)\n\t\t\t\tbreak;\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tpot[i] += prio[i];\n\t\t\tint df = Math.min(curflow[t], maxf - flow);\n\t\t\tflow += df;\n\t\t\tfor (int v = t; v != s; v = prevnode[v]) {\n\t\t\t\tEdge e = graph[prevnode[v]].get(prevedge[v]);\n\t\t\t\te.f += df;\n\t\t\t\tgraph[v].get(e.rev).f -= df;\n\t\t\t\tflowCost += df * e.cost;\n\t\t\t}\n\t\t}\n\t\treturn new int[]{flow, flowCost};\n\t}\n\n\tpublic void solve(int testNumber, InputReader in, PrintWriter out) {\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tint[][] a = new int[n][m];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\ta[i][j] = in.nextInt();\n\t\t\t}\n\t\t}\n\n\t\tfinal List[] g = createGraph(n * m + 2);\n\t\tint s = n * m;\n\t\tint t = s + 1;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tif ((i + j) % 2 == 1) {\n\t\t\t\t\taddEdge(g, s, i * m + j, 1, 0);\n\t\t\t\t\tint dx[] = {1, -1, 0, 0};\n\t\t\t\t\tint dy[] = {0, 0, 1, -1};\n\t\t\t\t\tfor (int k = 0; k < 4; k++) {\n\t\t\t\t\t\tint ni = i + dx[k];\n\t\t\t\t\t\tint nj = j + dy[k];\n\n\t\t\t\t\t\tif (0 <= ni && ni < n && 0 <= nj && nj < m) {\n\t\t\t\t\t\t\taddEdge(g, i * m + j, ni * m + nj, 1, a[i][j] != a[ni][nj] ? 1 : 0);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\taddEdge(g, i * m + j, t, 1, 0);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint[] res = minCostFlow(g, s, t, Integer.MAX_VALUE);\n\t\tint flow = res[0];\n\t\tint flowCost = res[1];\n\t\tout.println(flowCost);\n\t}\n}\n\nclass InputReader {\n\tpublic BufferedReader reader;\n\tpublic StringTokenizer tokenizer;\n\n\tpublic InputReader(InputStream stream) {\n\t\treader = new BufferedReader(new InputStreamReader(stream));\n\t}\n\n\tpublic String next() {\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\t\treturn tokenizer.nextToken();\n\t}\n\n\tpublic int nextInt() {\n\t\treturn Integer.parseInt(next());\n\t}\n}\n\n", "lang_cluster": "Java", "tags": ["flows"], "code_uid": "03550c6683390b1b09dcb9b1744ecc79", "src_uid": "1f0e8bbd5bf4fcdea927fbb505a8949b", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\n\npublic class Solution {\n\n private static Scanner sc = new Scanner(System.in);\n\n public static void main(String[] args) {\n int n = sc.nextInt(), k = sc.nextInt(), t = sc.nextInt();\n if (t <= k) {\n System.out.println(t);\n } else if (t >= n) {\n System.out.println(k + n - t);\n } else {\n System.out.println(k);\n }\n }\n\n}", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "4686eaba2b8747d16847c05f17c20632", "src_uid": "7e614526109a2052bfe7934381e7f6c2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\n\npublic class E {\n\n static StreamTokenizer st;\n static PrintWriter pw;\n\n private static int nextInt() throws IOException {\n st.nextToken();\n return (int) st.nval;\n }\n\n public static void main(String[] args) throws IOException {\n st = new StreamTokenizer(new BufferedReader(new InputStreamReader(\n System.in)));\n pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(\n System.out)));\n // -----------begin-------------------------\n int n = nextInt();\n int a[][] = new int[n + 1][n + 1];\n for (int i = 1; i <= n; i++) {\n for (int j = 1; j <= n; j++) {\n a[i][j] = nextInt();\n }\n }\n int sum = 0;\n for (int i = 1; i <= n; i++) {\n sum += a[i][i];\n sum += a[i][n - i + 1];\n\n }\n for (int i = 1; i <= n; i++) {\n sum += a[i][(n + 1) / 2];\n sum += a[(n + 1) / 2][i];\n }\n pw.print(sum-3*a[(n+1)/2][(n+1)/2]);\n pw.close();\n // ------------end--------------------------\n }\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "c0d74069b5d8a1343be7d8018e371dfb", "src_uid": "5ebfad36e56d30c58945c5800139b880", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "//package com.company;\n\nimport java.util.*;\n\npublic class Main {\n\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n int d1=input.nextInt(),d2=input.nextInt(),d3=input.nextInt();\n System.out.println(Math.min(d1,d2+d3)+Math.min(d2,d3+d1)+Math.min(d3,d1+d2));\n }\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "e572b00781a7a24aa70a64da67b688c1", "src_uid": "26cd7954a21866dbb2824d725473673e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n\npublic class q6 {\n\tpublic static void main(String args[]){\n\tScanner scr=new Scanner(System.in);\n\tint m=scr.nextInt();\n\tint n=scr.nextInt();\n\t\n\tif(m>=2 || n>=2){\n\n\t\tSystem.out.println((m*n)/2);\n\t}\n\telse\nSystem.out.println(0);\t\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "greedy"], "code_uid": "320e56ad7acde8df6c21e14cd8c307f7", "src_uid": "e840e7bfe83764bee6186fcf92a1b5cd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "\nimport java.io.*;\nimport java.lang.reflect.Array;\nimport java.util.*;\n\npublic class Main {\n\n //const int N = 5e4 + 5, M = 1e5+5, OO = 0x3f3f3f3f;\n\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n long n = input.nextInt();\n long m = input.nextInt();\n long [] nArr = new long[5];\n long [] mArr = new long[5];\n Arrays.fill(nArr,0);\n Arrays.fill(mArr,0);\n for (long i = 1; i <= n; i++) {\n nArr[(int) (i%5)]++;\n }\n\n for (long i = 1; i <= m; i++) {\n mArr[(int) (i%5)]++;\n }\n\n System.out.println(nArr[0] * mArr[0] + nArr[1] * mArr[4] + nArr[4] * mArr[1] + nArr[3] * mArr[2] +nArr[2] * mArr[3]);\n }\n}\n\n", "lang_cluster": "Java", "tags": ["math", "constructive algorithms", "number theory"], "code_uid": "a925bdd2008d5e62ff488e8758d98e79", "src_uid": "df0879635b59e141c839d9599abd77d2", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n//267630EY\npublic class Main259B2\n{\n static PrintWriter out=new PrintWriter(System.out);\n \n \n public static void main(String[] args) throws IOException\n {\n Scanner sc=new Scanner(System.in);\n int[][] a=new int[3][3];\n for(int i=0;i<3;i++)\n {\n for(int j=0;j<3;j++)\n a[i][j]=sc.nextInt();\n }\n int first=a[0][1]+a[0][2];\n int second=a[1][0]+a[1][2];\n int third=a[2][0]+a[2][1];\n int fourth=(first+second+third)/2;\n a[0][0]=fourth-first;\n a[1][1]=fourth-second;\n a[2][2]=fourth-third;\n for(int i=0;i<3;i++)\n {\n for(int j=0;j<3;j++)\n {\n out.print(a[i][j]+\" \");\n }\n out.println();\n }\n out.flush();\n \n \n \n \n \n \n \n \n \n \n }\n \n static class Scanner\n {\n BufferedReader br;\n StringTokenizer tk=new StringTokenizer(\"\");\n public Scanner(InputStream is) \n {\n br=new BufferedReader(new InputStreamReader(is));\n }\n public int nextInt() throws IOException\n {\n if(tk.hasMoreTokens())\n return Integer.parseInt(tk.nextToken());\n tk=new StringTokenizer(br.readLine());\n return nextInt();\n }\n public long nextLong() throws IOException\n {\n if(tk.hasMoreTokens())\n return Long.parseLong(tk.nextToken());\n tk=new StringTokenizer(br.readLine());\n return nextLong();\n }\n public String next() throws IOException\n {\n if(tk.hasMoreTokens())\n return (tk.nextToken());\n tk=new StringTokenizer(br.readLine());\n return next();\n }\n public String nextLine() throws IOException\n {\n tk=new StringTokenizer(\"\");\n return br.readLine();\n }\n public double nextDouble() throws IOException\n {\n if(tk.hasMoreTokens())\n return Double.parseDouble(tk.nextToken());\n tk=new StringTokenizer(br.readLine());\n return nextDouble();\n }\n public char nextChar() throws IOException\n {\n if(tk.hasMoreTokens())\n return (tk.nextToken().charAt(0));\n tk=new StringTokenizer(br.readLine());\n return nextChar();\n }\n public int[] nextIntArray(int n) throws IOException\n {\n int a[]=new int[n];\n for(int i=0;i result = getCanonicalPermutation(n, k);\n StringBuilder builder = new StringBuilder();\n builder.append(result.get(0));\n for (int i = 1; i < result.size(); ++i) {\n builder.append(\" \").append(result.get(i));\n }\n System.out.println(builder.toString());\n }\n\n private static List getCanonicalPermutation(int length, long order) {\n List result = new ArrayList<>();\n if (length == 1) {\n result.add(1);\n return result;\n }\n long[] cLen = new long[length];\n cLen[0] = 1;\n cLen[1] = 2;\n for (int i = 2; i < length; ++i) {\n cLen[i] = cLen[i - 2] + cLen[i -1];\n }\n int currentLength = length;\n for (int i = 0; i < length;) {\n if (currentLength == 1) {\n result.add(i + 1);\n break;\n }\n long remainder = currentLength > 2 ? cLen[currentLength - 1] - cLen[currentLength - 3] : 1;\n boolean shouldSwap = order > remainder;\n if (shouldSwap) {\n result.add(i + 2);\n result.add(i + 1);\n i += 2;\n currentLength -= 2;\n order -= remainder;\n } else {\n result.add(i + 1);\n i++;\n currentLength--;\n }\n }\n return result;\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "greedy"], "code_uid": "e20f2303b6c0d60f68db3ea67e7322b4", "src_uid": "e03c6d3bb8cf9119530668765691a346", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.util.InputMismatchException;\n\npublic class DrazilAndFactorial {\n public static void main(String[] args) {\n FasterScanner sc = new FasterScanner();\n \n int N = sc.nextInt();\n String A = sc.nextString();\n \n int[] freq = new int[10];\n for (int i = 0; i < N; i++) {\n \tint d = A.charAt(i) - '0';\n \tif (d == 4) {\n \t\tfreq[2] += 2;\n \t\tfreq[3]++;\n \t} else if (d == 6) {\n \t\tfreq[3]++;\n \t\tfreq[5]++;\n \t} else if (d == 8) {\n \t\tfreq[2] += 3;\n \t\tfreq[7]++;\n \t} else if (d == 9) {\n \t\tfreq[2]++;\n \t\tfreq[3] += 2;\n \t\tfreq[7]++;\n \t} else {\n \t\tfreq[d]++;\n \t}\n }\n \n StringBuilder sb = new StringBuilder();\n for (int i = 9; i >= 2; i--) {\n \tsb.append(rep(i, freq[i]));\n }\n System.out.println(sb.toString());\n }\n \n public static StringBuilder rep(int d, int r) {\n \tStringBuilder sb = new StringBuilder();\n \tfor (int i = 0; i < r; i++) {\n \t\tsb.append(d);\n \t}\n \treturn sb;\n }\n \n\tpublic static class FasterScanner {\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n\n\t\tpublic int read() {\n\t\t\tif (numChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= numChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tnumChars = System.in.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (numChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isEndOfLine(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic String nextString() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\t \n\t public int[] nextIntArray(int n) {\n\t int[] arr = new int[n];\n\t for (int i = 0; i < n; i++) {\n\t arr[i] = nextInt();\n\t }\n\t return arr;\n\t }\n \n\t\tpublic long[] nextLongArray(int n) {\n\t\t long[] arr = new long[n];\n\t\t for (int i = 0; i < n; i++) {\n\t\t arr[i] = nextLong();\n\t\t }\n\t\t return arr;\n\t\t}\n\n\t private boolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tprivate boolean isEndOfLine(int c) {\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t}\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "sortings", "greedy"], "code_uid": "02a0d31e6df6cfcf89d6772afb2b3322", "src_uid": "60dbfc7a65702ae8bd4a587db1e06398", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\npublic class Main {\n\n public static void main(String[] args) {\n InputStreamReader ir = new InputStreamReader(System.in);\n BufferedReader br = new BufferedReader(ir);\n String line;\n String[] ar;\n try {\n int r, c, n, k;\n ar = br.readLine().split(\" \");\n r = Integer.parseInt(ar[0]);\n c = Integer.parseInt(ar[1]);\n n = Integer.parseInt(ar[2]);\n k = Integer.parseInt(ar[3]);\n int[][] g = new int[r + 1][c + 1];\n for (int i = 0; i < n; i++) {\n ar = br.readLine().split(\" \");\n int a = Integer.parseInt(ar[0]);\n int b = Integer.parseInt(ar[1]);\n g[a][b] = 1;\n }\n for (int i = 1; i <= r; i++) {\n for (int j = 1; j <= c; j++) {\n g[i][j] = g[i - 1][j] + g[i][j - 1] - g[i - 1][j - 1] + g[i][j];\n }\n }\n int ans = 0;\n for (int r1 = 1; r1 <= r; r1++) {\n for (int c1 = 1; c1 <= c; c1++) {\n for (int r2 = r1; r2 <= r; r2++) {\n for (int c2 = c1; c2 <= c; c2++) {\n int v = g[r2][c2] - g[r2][c1 - 1] - g[r1 - 1][c2] + g[r1 - 1][c1 - 1];\n if (v >= k) {\n ans++;\n }\n }\n }\n }\n }\n System.out.println(ans);\n } catch (Exception ex) {\n ex.printStackTrace();\n }\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "44bee434caec3bc8f4a2d384b066052d", "src_uid": "9c766881f6415e2f53fb43b61f8f40b4", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\n/**\n *\n * @author Annie\n */\npublic class Sticks {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n // TODO code application logic here\n Scanner s = new Scanner(System.in);\n int a[] = new int[6];\n int y=0,no=0;\n for(int i=0;i<6;i++){\n a[i]=s.nextInt();\n }\n \n int b[] = new int[10];\n \n for(int i=0;i<6;i++){\n int x = a[i];\n b[x]++; \n }\n \n \n for(int i=1;i<10;i++){\n if(b[i]==4){\n \n for(int j=1;j<10;j++){\n if(b[j]==2){\n y++;\n }\n else{\n int x=1;\n }\n }\n \n }//if closed\n \n \n else if(b[i]>4){\n if(b[i]==6){\n y++;\n }\n else{\n int x=1;\n }\n }\n \n \n else{\n no++;\n }\n \n \n \n }//for closed\n \n \n \n if(no==9){\n \n System.out.println(\"Alien\");\n }\n else{\n if(y==1){\n System.out.println(\"Elephant\");\n }\n else{\n System.out.println(\"Bear\");\n }\n \n }\n \n \n \n }\n \n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "738ce7e4af2bc0a07f7526b758edede6", "src_uid": "43308fa25e8578fd9f25328e715d4dd6", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.util.List;\n\npublic class Main {\n private static StringTokenizer st;\n private static BufferedReader br;\n\n public static void print(Object x) {\n System.out.println(x + \"\");\n }\n public static String join(List x, String space) {\n StringBuilder sb = new StringBuilder();\n for (Object elt : x) {\n sb.append(elt);\n sb.append(space);\n }\n return sb.toString();\n }\n\n public static String nextToken() throws IOException {\n while (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(br.readLine().trim());\n }\n return st.nextToken();\n }\n public static int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n public static long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n public static class Env {\n int w;\n int h;\n int num;\n\n public Env(int w, int h, int num) {\n this.w = w;\n this.h = h;\n this.num = num;\n }\n }\n\n public static long sumTo(long x) {\n return (x + 1)*x / 2;\n }\n\n public static long sumFrom(long x, long y) {\n //x+1...y\n return sumTo(y) - sumTo(x);\n }\n\n public static String solve(long n, long k) {\n k -= 1;\n n -= 1;\n if (sumTo(k) < n) {\n return \"-1\";\n }\n\n long j = Math.max(0, (long) Math.sqrt((k + 1) * k - 2 * n));\n j = Math.min(j, k);\n while (sumFrom(j, k) < n) {\n j--;\n }\n while (sumFrom(j, k) > n) {\n j++;\n }\n //j+1...k <= n\n //print(j + \" \" + k + \" = \" + sumFrom(j, k));\n if (sumFrom(j, k) == n) {\n return \"\" + (k - j);\n } else {\n return \"\" + (k - j + 1);\n }\n }\n\n public static void main(String[] args) throws Exception {\n boolean debug = false;\n InputStream in = System.in;\n if (debug) {\n in = new FileInputStream(\"input.in\");\n }\n br = new BufferedReader(new InputStreamReader(in));\n long n = nextLong();\n long k = nextLong();\n print(solve(n, k));\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "binary search"], "code_uid": "e155dd52158f35e1e869244bad9d022b", "src_uid": "83bcfe32db302fbae18e8a95d89cf411", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main{\n public static void main(String args[]){\n Scanner sc=new Scanner(System.in);\n int x1=sc.nextInt();\n int y1=sc.nextInt();\n int x2=sc.nextInt();\n int y2=sc.nextInt();\n int h=0,v=0;\n h=Math.abs(x1-x2);\n v=Math.abs(y1-y2);\n if(x1==x2)\n h=(h+1)*2;\n else\n h+=1;\n if(y1==y2)\n v=(v+1)*2;\n else\n v+=1;\n System.out.println((h+v)*2);\n }\n}", "lang_cluster": "Java", "tags": ["math", "greedy"], "code_uid": "2044b00150fd7d84ecbde87a5c347204", "src_uid": "f54ce13fb92e51ebd5e82ffbdd1acbed", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "/**\n * ******* Created on 10/3/20 4:12 PM*******\n */\n\nimport java.io.*;\nimport java.util.*;\n\npublic class B29 implements Runnable {\n\n private static final int MAX = (int) (1E5 + 5);\n private static final int MOD = (int) (1E9 + 7);\n private static final long Inf = (long) (1E14 + 10);\n\n private void solve() throws IOException {\n int l= reader.nextInt();\n int d = reader.nextInt();\n int v = reader.nextInt();\n int g = reader.nextInt();\n int r = reader.nextInt();\n\n double time = (double) d/v;\n time %= (r+g);\n double ans =0.0;\n if(time >=g)\n ans+=( r+g -time);\n\n ans += ((double) l/v);\n writer.println(ans );\n }\n\n public static void main(String[] args) throws IOException {\n try (Input reader = new StandardInput(); PrintWriter writer = new PrintWriter(System.out)) {\n new B29().run();\n }\n }\n\n StandardInput reader;\n PrintWriter writer;\n\n @Override\n public void run() {\n try {\n reader = new StandardInput();\n writer = new PrintWriter(System.out);\n solve();\n reader.close();\n writer.close();\n } catch (Exception e) {\n e.printStackTrace();\n }\n }\n\n interface Input extends Closeable {\n String next() throws IOException;\n\n default int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n default long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n default double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n default int[] readIntArray() throws IOException {\n return readIntArray(nextInt());\n }\n\n default int[] readIntArray(int size) throws IOException {\n int[] array = new int[size];\n for (int i = 0; i < array.length; i++) {\n array[i] = nextInt();\n }\n return array;\n }\n\n default long[] readLongArray(int size) throws IOException {\n long[] array = new long[size];\n for (int i = 0; i < array.length; i++) {\n array[i] = nextLong();\n }\n return array;\n }\n }\n\n private static class StandardInput implements Input {\n private final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n\n private StringTokenizer stringTokenizer;\n\n @Override\n public void close() throws IOException {\n reader.close();\n }\n\n @Override\n public String next() throws IOException {\n if (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {\n stringTokenizer = new StringTokenizer(reader.readLine());\n }\n return stringTokenizer.nextToken();\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "20564b2a2b69f18337a0764f36006c07", "src_uid": "e4a4affb439365c843c9f9828d81b42c", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\n\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.PriorityQueue;\nimport java.util.Scanner;\n\npublic class card_game {\n\tpublic static void main(String args[]) {\n\t\tScanner scn = new Scanner(System.in);\n\t\tPriorityQueue pq = new PriorityQueue<>(Collections.reverseOrder());\n\t\tint n = scn.nextInt();\n\t\tint m = scn.nextInt();\n\t\tint k = scn.nextInt();\n\t\tint a[] = new int[n];\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = scn.nextInt();\n\t\t\tpq.add(a[i]);\n\t\t}\n\t\tif (k >= m) {\n\t\t\tSystem.out.println(0);\n\t\t} else {\n\t\t\tint sok = k;\n\t\t\tint count = 0;\n\t\t\twhile (pq.size() > 0 && sok < m) {\n\t\t\t\tsok = sok - 1 + pq.poll();\n\t\t\t\tcount++;\n\t\t\t}\n\t\t\tif (pq.size() == 0 && sok < m) {\n\t\t\t\tSystem.out.println(-1);\n\t\t\t} else {\n\t\t\t\tSystem.out.println(count);\n\t\t\t}\n\n\t\t}\n\n\t}\n}\n", "lang_cluster": "Java", "tags": ["sortings", "implementation", "greedy"], "code_uid": "32ff0bd3e48a3b69d6e5def91d1bcb77", "src_uid": "b32ab27503ee3c4196d6f0d0f133d13c", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\n\npublic class AlexAndARhombus1180A {\n public static void main(String[] args) throws Exception {\n Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n int t = Integer.parseInt(sc.nextLine());\n System.out.println(solve(t));\n\n }\n private static int solve(int n) {\n if (n == 1) return n;\n return 4 * (n - 1) + solve(n - 1);\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "dp", "implementation"], "code_uid": "9e7b10d4fbf0c32b503e384fcd9bc89d", "src_uid": "758d342c1badde6d0b4db81285be780c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.util.StringTokenizer;\nimport java.io.Writer;\nimport java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author zodiacLeo\n */\npublic class Main\n{\n public static void main(String[] args)\n {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastScanner in = new FastScanner(inputStream);\n FastPrinter out = new FastPrinter(outputStream);\n TaskA solver = new TaskA();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskA\n {\n public void solve(int testNumber, FastScanner in, FastPrinter out)\n {\n String before = in.next();\n String after = before.replaceAll(\"VK\", \"-\");\n int cnt = (before.length() - after.length());\n if (after.length() >= 2)\n {\n int index = after.indexOf(\"VV\");\n if (index >= 0 && index < after.length())\n {\n cnt++;\n out.println(cnt);\n return;\n }\n\n index = after.lastIndexOf(\"KK\");\n if (index >= 0 && index < after.length())\n {\n cnt++;\n out.println(cnt);\n return;\n }\n }\n out.println(cnt);\n }\n\n }\n\n static class FastScanner\n {\n public BufferedReader br;\n public StringTokenizer st;\n\n public FastScanner(InputStream is)\n {\n br = new BufferedReader(new InputStreamReader(is));\n }\n\n public FastScanner(File f)\n {\n try\n {\n br = new BufferedReader(new FileReader(f));\n } catch (FileNotFoundException e)\n {\n e.printStackTrace();\n }\n }\n\n public String next()\n {\n while (st == null || !st.hasMoreElements())\n {\n String s = null;\n try\n {\n s = br.readLine();\n } catch (IOException e)\n {\n e.printStackTrace();\n }\n if (s == null)\n return null;\n st = new StringTokenizer(s);\n }\n return st.nextToken();\n }\n\n }\n\n static class FastPrinter extends PrintWriter\n {\n public FastPrinter(OutputStream out)\n {\n super(out);\n }\n\n public FastPrinter(Writer out)\n {\n super(out);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["brute force"], "code_uid": "8b702df3f0339d92418d8cd37743ef21", "src_uid": "578bae0fe6634882227ac371ebb38fc9", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class Main {\n public static void main(String[] args) {\n Scanner scn=new Scanner(System.in);\n int k=scn.nextInt();\n int l=scn.nextInt();\n int m=scn.nextInt();\n int n=scn.nextInt();\n int d=scn.nextInt();\n int arr[]=new int[d+1];\n for(int i=k;i0){\n\t \tSystem.out.println(ar[n%10]);\n\t \tn /= 10;\n\t }\n\n\t \n\t // out.close(); System.exit(0);\n}\n}\n\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "179b8dfb41fda35a080692ea71402ace", "src_uid": "c2e3aced0bc76b6484360563355d23a7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\npublic class AboutBacteria {\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader buff = new BufferedReader(new InputStreamReader(System.in));\n\t\tString[] temp = buff.readLine().split(\" \");\n\t\tint k = Integer.parseInt(temp[0]);\n\t\tint b = Integer.parseInt(temp[1]);\n\t\tint n = Integer.parseInt(temp[2]);\n\t\tint t = Integer.parseInt(temp[3]);\n\t\tSystem.out.println(getTime(k, b, n, t));\n\t}\n\tpublic static int getTime(int k, int b, int n, int t) {\n\t\tint ans = 0;\n\t\tlong x = 1;\n\t\twhile (x < t && ans < n){\n\t\t\tx = k*x +b;\n\t\t\tans++;\n\t\t}\n\t\tif (x > t)\n\t\t\tans--;\n\t\treturn n - ans;\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "9379370f7d8cbdf509a761b5218f744b", "src_uid": "e2357a1f54757bce77dce625772e4f18", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n FastScanner in;\n PrintWriter out;\n\n public void solve() throws IOException {\n int[] a = new int[4];\n a[0] = in.nextInt();\n a[1] = in.nextInt();\n a[2] = in.nextInt();\n a[3] = in.nextInt();\n Arrays.sort(a);\n if (a[3] > a[1] + a[2] && a[2] > a[1] + a[0]) {\n out.println(\"IMPOSSIBLE\");\n return;\n }\n if (a[3] < a[1] + a[2] || a[2] < a[1] + a[0]) {\n out.println(\"TRIANGLE\");\n return;\n }\n out.println(\"SEGMENT\");\n }\n\n public void run() {\n try {\n in = new FastScanner(System.in);\n out = new PrintWriter(System.out);\n solve();\n out.close();\n }\n catch (IOException e) {\n e.printStackTrace();\n }\n }\n\n class FastScanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n FastScanner(InputStream is) {\n br = new BufferedReader(new InputStreamReader(is));\n }\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n }\n catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n\n public static void main(String[] arg) {\n new Main().run();\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "geometry"], "code_uid": "dbdaf05d52161e1ba50645b9e96a5a5c", "src_uid": "8f5df9a41e6e100aa65b9fc1d26e447a", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n \npublic class Ideone\n{\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t\tScanner in = new Scanner(System.in);\n\t\tint f=0;\n\t\tfor(int i=0;i<8;i++)\n\t\t{\n\t\t\tString s=in.next();\n\t\t\tin.nextLine();\n\t\t\tfor(int j=0;j<7;j++)\n\t\t\t{\n\t\t\t\tif(s.charAt(j)==s.charAt(j+1))\n\t\t\t\t{\n\t\t\t\t\tf++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif(f==0)\n\t\tSystem.out.println(\"YES\");\n\t\telse\n\t\tSystem.out.println(\"NO\");\n\t}\n}", "lang_cluster": "Java", "tags": ["brute force", "strings"], "code_uid": "ef58e803c8d2eef3da76718cae19f9c7", "src_uid": "ca65e023be092b2ce25599f52acc1a67", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF1663B extends PrintWriter {\n\tCF1663B() { super(System.out, true); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1663B o = new CF1663B(); o.main(); o.flush();\n\t}\n\n\tvoid main() {\n\t\tint r = sc.nextInt();\n\t\tif (r < 1200)\n\t\t\tr = 1200;\n\t\telse if (r < 1400)\n\t\t\tr = 1400;\n\t\telse if (r < 1600)\n\t\t\tr = 1600;\n\t\telse if (r < 1900)\n\t\t\tr = 1900;\n\t\telse if (r < 2100)\n\t\t\tr = 2100;\n\t\telse if (r < 2300)\n\t\t\tr = 2300;\n\t\telse if (r < 2400)\n\t\t\tr = 2400;\n\t\telse if (r < 2600)\n\t\t\tr = 2600;\n\t\telse\n\t\t\tr = 3000;\n\t\tprintln(r);\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "divide and conquer", "implementation"], "code_uid": "968a914b80b761df7b6d7482a89bb0bb", "src_uid": "22725effa6dc68b9c2a499d148e613c2", "difficulty": -1.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/**\n * @author derrick20\n */\nimport java.io.*;\nimport java.util.*;\n\npublic class HeightAllTheSame {\n public static void main(String args[]) throws Exception {\n FastScanner sc = new FastScanner();\n PrintWriter out = new PrintWriter(System.out);\n\n long N = sc.nextLong();\n long M = sc.nextLong();\n long L = sc.nextLong();\n long R = sc.nextLong();\n\n long E = (R - L + 1) / 2 + (R % 2 == 0 && L % 2 == 0 ? 1 : 0);\n long O = (R - L + 1) - E;\n // Key thing to observe: if we have any valid starting position\n // with an EVEN number of ODD-heighted blocks, then it'll be possible.\n /** actually, it's more subtle than that. You need to just have everything\n * be the SAME at the end. This means an even number of AT LEAST ONE of them\n * will allow for a solution. All that matters is that everything is\n * neutralized into the other type, so if one of them has even count, then\n * we turn it all into the other. However, if NM is even, then the odd odd case fails\n */\n // Basically, we notice that we can flip any pair of OE blocks, and\n // then in this way we can move any odd blocks together, then flip those\n // OO into an EE pair. So, the starting position just needs an even number\n // of odd blocks for this invariant of the same parity of number of ODD\n // blocks to be satisfied\n\n // This can be visualized as the generating function (E+O)^(NM)\n // since this illustrates the distribution of ways to make each of the NM cells\n // However, we only want the O^(2k) terms for all k. So, we use\n // the trick of adding it to (E-O)^(NM), since all odd terms will cancel\n // Then, we divide by 2, and we have the total answer!\n long ans;\n if (N * M % 2 == 1) {\n ans = fastExpo(E + O, N * M);\n }\n else {\n ans = (fastExpo(E + O, N * M) + fastExpo(E - O, N * M)) % mod;\n ans = (ans * modInv(2)) % mod; // divide by 2 now\n }\n out.println(ans);\n out.close();\n }\n\n static long mod = 998244353;\n\n static long modInv(long x) {\n return fastExpo(x, mod - 2);\n }\n\n static long fastExpo(long x, long k) {\n if (k == 0) {\n return 1;\n }\n else if (k == 1) {\n return x;\n }\n else {\n long root = fastExpo(x, k / 2);\n long ans = (root * root) % mod;\n if (k % 2 == 1) {\n ans = (ans * x) % mod;\n }\n return ans;\n }\n }\n\n static class FastScanner {\n public int BS = 1<<16;\n public char NC = (char)0;\n byte[] buf = new byte[BS];\n int bId = 0, size = 0;\n char c = NC;\n double cnt = 1;\n BufferedInputStream in;\n\n public FastScanner() {\n in = new BufferedInputStream(System.in, BS);\n }\n\n public FastScanner(String s) {\n try {\n in = new BufferedInputStream(new FileInputStream(new File(s)), BS);\n }\n catch (Exception e) {\n in = new BufferedInputStream(System.in, BS);\n }\n }\n\n private char getChar(){\n while(bId==size) {\n try {\n size = in.read(buf);\n }catch(Exception e) {\n return NC;\n }\n if(size==-1)return NC;\n bId=0;\n }\n return (char)buf[bId++];\n }\n\n public int nextInt() {\n return (int)nextLong();\n }\n\n public int[] nextInts(int N, int dx) {\n int[] res = new int[N];\n for (int i = 0; i < N; i++) {\n res[i] = (int) nextLong() + dx;\n }\n return res;\n }\n\n public long[] nextLongs(int N) {\n long[] res = new long[N];\n for (int i = 0; i < N; i++) {\n res[i] = nextLong();\n }\n return res;\n }\n\n public long nextLong() {\n cnt=1;\n boolean neg = false;\n if(c==NC)c=getChar();\n for(;(c<'0' || c>'9'); c = getChar()) {\n if(c=='-')neg=true;\n }\n long res = 0;\n for(; c>='0' && c <='9'; c=getChar()) {\n res = (res<<3)+(res<<1)+c-'0';\n cnt*=10;\n }\n return neg?-res:res;\n }\n\n public double nextDouble() {\n double cur = nextLong();\n return c!='.' ? cur:cur+nextLong()/cnt;\n }\n\n public String next() {\n StringBuilder res = new StringBuilder();\n while(c<=32)c=getChar();\n while(c>32) {\n res.append(c);\n c=getChar();\n }\n return res.toString();\n }\n\n public String nextLine() {\n StringBuilder res = new StringBuilder();\n while(c<=32)c=getChar();\n while(c!='\\n') {\n res.append(c);\n c=getChar();\n }\n return res.toString();\n }\n\n public boolean hasNext() {\n if(c>32)return true;\n while(true) {\n c=getChar();\n if(c==NC)return false;\n else if(c>32)return true;\n }\n }\n }\n}", "lang_cluster": "Java", "tags": ["math", "matrices", "constructive algorithms", "combinatorics"], "code_uid": "f8d4d35ad5738f18cbcd23a28b938805", "src_uid": "ded299fa1cd010822c60f2389a3ba1a3", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "//Coins\nimport java.io.*;\nimport java.util.*;\npublic class Coins{\nstatic int t,n;\nstatic int[] arr;\nstatic ArrayList list=new ArrayList<>();\nstatic StringBuilder ans=new StringBuilder();\nstatic void solve(){\n\tint[] count=new int[3];\n\tfor(int i=0;i<3;i++){\n\t\tString str=list.get(i);\n\t\tif(str.charAt(1)=='<'){count[str.charAt(2)-'A']++;}\n\t\telse{count[str.charAt(0)-'A']++;}\n\t}\n\tif(count[0]==1&&count[1]==1&&count[2]==1){\n\t\tans.append(\"Impossible\");\n\t\treturn;\n\t}\n\tfor(int i=0;i<3;i++){\n\t\tif(count[i]==0){ans.append((char)(i+65));}\n\t}\n\tfor(int i=0;i<3;i++){\n\t\tif(count[i]==1){ans.append((char)(i+65));}\n\t}\n\tfor(int i=0;i<3;i++){\n\t\tif(count[i]==2){ans.append((char)(i+65));}\n\t}\n\n}\npublic static void main(String[] args) throws IOException{\n\t\t// BufferedReader br = new BufferedReader(new\n // FileReader(\"sampleinp.txt\"));\n \tBufferedReader br = new BufferedReader( \n new InputStreamReader(System.in)); \n\t \n\t for(int i=1;i<=3;i++){\n\t \t\tString str=br.readLine();\n\t \t\tlist.add(str);\n\t }\n\t solve();\n\t\tSystem.out.println(ans.toString());\n\n }\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "4b114e9e503259936bc8f7def7311a50", "src_uid": "97fd9123d0fb511da165b900afbde5dc", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.lang.*;\nimport java.util.*;\nimport java.io.*;\npublic class fraction\n{ \n \n\n Scanner sc=new Scanner(System.in);\n PrintWriter pr=new PrintWriter(System.out,true);\n public static void main(String... args) \n {\n fraction c=new fraction();\n c.prop();\n }\n public void prop() \n {\n int n,a=0,b=0;\n n=sc.nextInt();\n for (int i=n/2;i>=1 ;--i) {\n a=i ;\n b=n-i ;\n if(a>=b)\n continue ;\n b=gcd(a,b);\n if(b==1)\n {\n b=n-i ;\n break ;\n }\n\n }\n pr.println(a+\" \"+b); \n }\n public int gcd(int a,int b)\n {\n if(a%b==0)\n return b ;\n return gcd(b,a%b);\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "math", "constructive algorithms"], "code_uid": "d349351873784ea2b97edebadaac4799", "src_uid": "0af3515ed98d9d01ce00546333e98e77", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.util.NoSuchElementException;\n\npublic class Main{\n\t\n\tpublic static void main(String[] args){\n\t\tFastScanner sc = new FastScanner();\n\t\tlong w1 =sc.nextLong();\n\t\tlong h1 =sc.nextLong();\n\t\tlong w2 =sc.nextLong();\n\t\tlong h2 =sc.nextLong();\n\t\tif(w1==w2){\n\t\t\tSystem.out.println((w1+2) * (h1+h2+2) - w1 * (h1+h2));\n\t\t}else{\n\t\t\tSystem.out.println((w1+2) * (h1+h2+2) - w1 * (h1+h2));\n\t\t}\n\t}\n\n\t\n}\n\n\nclass FastScanner {\n private final java.io.InputStream in = System.in;\n private final byte[] buffer = new byte[1024];\n private int ptr = 0;\n private int buflen = 0;\n private boolean hasNextByte() {\n if (ptr < buflen) {\n return true;\n }else{\n ptr = 0;\n try {\n buflen = in.read(buffer);\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (buflen <= 0) {\n return false;\n }\n }\n return true;\n }\n private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}\n private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}\n private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}\n public boolean hasNext() { skipUnprintable(); return hasNextByte();}\n public String next() {\n if (!hasNext()) throw new NoSuchElementException();\n StringBuilder sb = new StringBuilder();\n int b = readByte();\n while(isPrintableChar(b)) {\n sb.appendCodePoint(b);\n b = readByte();\n }\n return sb.toString();\n }\n public long nextLong() {\n if (!hasNext()) throw new NoSuchElementException();\n long n = 0;\n boolean minus = false;\n int b = readByte();\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n if (b < '0' || '9' < b) {\n throw new NumberFormatException();\n }\n while(true){\n if ('0' <= b && b <= '9') {\n n *= 10;\n n += b - '0';\n }else if(b == -1 || !isPrintableChar(b)){\n return (minus ? -n : n);\n }else{\n throw new NumberFormatException();\n }\n b = readByte();\n }\n }\n public int nextInt() {\n if (!hasNext()) throw new NoSuchElementException();\n long n = 0;\n boolean minus = false;\n int b = readByte();\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n if (b < '0' || '9' < b) {\n throw new NumberFormatException();\n }\n while(true){\n if ('0' <= b && b <= '9') {\n n *= 10;\n n += b - '0';\n }else if(b == -1 || !isPrintableChar(b)){\n return (int) (minus ? -n : n);\n }else{\n throw new NumberFormatException();\n }\n b = readByte();\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "8823b8d72ce94b822fc45af826283ba8", "src_uid": "b5d44e0041053c996938aadd1b3865f6", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\n\npublic class Task689A {\n\n private static int _numberCount;\n\n private static int[] _numbers;\n\n public static void main(String[] args) {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n try {\n _numberCount = Integer.parseInt(in.readLine());\n _numbers = new int[_numberCount];\n String line = in.readLine();\n for (int i = 0; i < _numberCount; i++) {\n _numbers[i] = Integer.parseInt(String.valueOf(line.charAt(i)));\n }\n in.close();\n String result = getResult();\n PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n out.print(result);\n out.close();\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n\n private static String getResult() {\n if (_numberCount == 1) {\n return \"NO\";\n }\n VectorCustom[] vectors = getVectors();\n boolean unique = testMultipleCombinations(vectors);\n if (unique) {\n return \"YES\";\n }\n return \"NO\";\n }\n\n private static boolean testMultipleCombinations(VectorCustom[] vectors) {\n int successCount = 0;\n for (int i = 0; i < 10; i++) {\n boolean success = true;\n int cursorX = getButtonXCoord(i);\n int cursorY = getButtonYCoord(i);\n for (VectorCustom vector : vectors) {\n cursorX += vector.getX();\n cursorY += vector.getY();\n if (!checkFingerInRange(cursorX, cursorY)) {\n success = false;\n break;\n }\n }\n if (success) {\n successCount++;\n }\n }\n return successCount == 1;\n }\n\n private static boolean checkFingerInRange(int cursorX, int cursorY) {\n if (cursorY == 4) {\n return cursorX == 2;\n }\n boolean xOk = (cursorX >= 1 && cursorX <= 3);\n boolean yOk = (cursorY >= 1 && cursorY <= 3);\n return xOk && yOk;\n }\n\n private static VectorCustom[] getVectors() {\n VectorCustom[] result = new VectorCustom[_numberCount - 1];\n for (int i = 0; i < _numberCount - 1; i++) {\n int x1 = getButtonXCoord(_numbers[i]);\n int x2 = getButtonXCoord(_numbers[i + 1]);\n int xVect = x2 - x1;\n\n int y1 = getButtonYCoord(_numbers[i]);\n int y2 = getButtonYCoord(_numbers[i + 1]);\n int yVect = y2 - y1;\n result[i] = new VectorCustom(xVect, yVect);\n }\n return result;\n }\n\n private static int getButtonXCoord(int number) {\n if (number == 0) {\n return 2;\n } else {\n if (number % 3 == 0) {\n return 3;\n } else {\n return number % 3;\n }\n }\n }\n\n private static int getButtonYCoord(int number) {\n if (number == 0) {\n return 4;\n } else {\n if (number % 3 == 0) {\n return number / 3;\n }\n return (int) (Math.floor(((double) number) / 3) + 1);\n }\n }\n\n\n private static class VectorCustom {\n private int x;\n private int y;\n\n VectorCustom(int x, int y) {\n this.x = x;\n this.y = y;\n }\n\n int getX() {\n return x;\n }\n\n int getY() {\n return y;\n }\n\n public String toString() {\n return \"x:\" + x + \" y:\" + y;\n }\n }\n\n}\n", "lang_cluster": "Java", "tags": ["brute force", "constructive algorithms", "implementation"], "code_uid": "2188fa502a953c4248c66f065589fe01", "src_uid": "d0f5174bb0bcca5a486db327b492bf33", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "\n\nimport java.util.*;\nimport java.io.*;\nimport java.awt.Point;\nimport java.math.BigInteger;\n\nimport static java.lang.Math.*;\n\n// Solution is at the bottom of code\n\npublic class ProblemC_010 implements Runnable{\n\t\n\tfinal boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\n\tBufferedReader in;\n\tOutputWriter out;\n\tStringTokenizer tok = new StringTokenizer(\"\");\n\t\n\tpublic static void main(String[] args){\n\t\tnew Thread(null, new ProblemC_010(), \"\", 128 * (1L << 20)).start();\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tvoid init() throws FileNotFoundException{\n\t\tLocale.setDefault(Locale.US);\n\t\t\n\t\tif (ONLINE_JUDGE){\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new OutputWriter(System.out);\n\t\t}else{\n\t\t\tin = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\tout = new OutputWriter(\"output.txt\");\n\t\t}\n\t}\n\t\n\t////////////////////////////////////////////////////////////////\n\t\n\tlong timeBegin, timeEnd;\n\n\tvoid time(){\n\t\ttimeEnd = System.currentTimeMillis();\n\t\tSystem.err.println(\"Time = \" + (timeEnd - timeBegin));\n\t}\n\t\n\tvoid debug(Object... objects){\n\t\tif (ONLINE_JUDGE){\n\t\t\tfor (Object o: objects){\n\t\t\t\tSystem.err.println(o.toString());\n\t\t\t}\n\t\t}\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tpublic void run(){\n\t\ttry{\n\t\t\ttimeBegin = System.currentTimeMillis();\n\t\t\tLocale.setDefault(Locale.US);\n\t\t\t\n\t\t\tinit();\n\t\t\tsolve();\n\t\t\t\n\t\t\tout.close();\n\t\t\ttime();\n\t\t}catch (Exception e){\n\t\t\te.printStackTrace(System.err);\n\t\t\tSystem.exit(-1);\n\t\t}\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tString delim = \" \";\n\t\n\tString readString() throws IOException{\n\t\twhile(!tok.hasMoreTokens()){\n\t\t\ttry{\n\t\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t\t}catch (Exception e){\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn tok.nextToken(delim);\n\t}\n\t\n\tString readLine() throws IOException{\n\t\treturn in.readLine();\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////\n\t\n\tfinal char NOT_A_SYMBOL = '\\0';\n\t\n\tchar readChar() throws IOException{\n\t\tint intValue = in.read();\n\t\t\n\t\tif (intValue == -1){\n\t\t\treturn NOT_A_SYMBOL;\n\t\t}\n\t\t\n\t\treturn (char) intValue;\n\t}\n\t\n\tchar[] readCharArray() throws IOException{\n\t\treturn readLine().toCharArray();\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////\n\t\n\tint readInt() throws IOException{\n\t\treturn Integer.parseInt(readString());\n\t}\n\t\n\tint[] readIntArray(int size) throws IOException{\n\t\tint[] array = new int[size];\n\t\t\n\t\tfor (int index = 0; index < size; ++index){\n\t\t\tarray[index] = readInt();\n\t\t}\n\t\t\n\t\treturn array;\n\t}\n\t\n\t///////////////////////////////////////////////////////////////////\n\t\n\tlong readLong() throws IOException{\n\t\treturn Long.parseLong(readString());\n\t}\n\t\n\tlong[] readLongArray(int size) throws IOException{\n\t\tlong[] array = new long[size];\n\t\t\n\t\tfor (int index = 0; index < size; ++index){\n\t\t\tarray[index] = readLong();\n\t\t}\n\t\t\n\t\treturn array;\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////\n\t\n\tdouble readDouble() throws IOException{\n\t\treturn Double.parseDouble(readString());\n\t}\n\t\n\tdouble[] readDoubleArray(int size) throws IOException{\n\t\tdouble[] array = new double[size];\n\t\t\n\t\tfor (int index = 0; index < size; ++index){\n\t\t\tarray[index] = readDouble();\n\t\t}\n\t\t\n\t\treturn array;\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tPoint readPoint() throws IOException{\n\t\treturn new Point(readInt(), readInt());\n\t}\n\t\n\tPoint[] readPointArray(int size) throws IOException{\n\t\tPoint[] array = new Point[size];\n\t\t\n\t\tfor (int index = 0; index < size; ++index){\n\t\t\tarray[index] = readPoint();\n\t\t}\n\t\t\n\t\treturn array;\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tList[] readGraph(int vertexNumber, int edgeNumber)\n\tthrows IOException{\n\t\tList[] graph = new List[vertexNumber];\n\t\t\n\t\tfor (int index = 0; index < vertexNumber; ++index){\n\t\t\tgraph[index] = new ArrayList();\n\t\t}\n\t\t\n\t\twhile (edgeNumber-- > 0){\n\t\t\tint from = readInt() - 1;\n\t\t\tint to = readInt() - 1;\n\t\t\t\n\t\t\tgraph[from].add(to);\n\t\t\tgraph[to].add(from);\n\t\t}\n\t\t\n\t\treturn graph;\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tclass OutputWriter extends PrintWriter{\n\n\t\tfinal int DEFAULT_PRECISION = 12;\n\t\t\n\t\tint precision;\n\t\tString format, formatWithSpace;\n\t\t\n\t\t{\n\t\t\tprecision = DEFAULT_PRECISION;\n\t\t\t\n\t\t\tformat = createFormat(precision);\n\t\t\tformatWithSpace = format + \" \";\n\t\t}\n\t\t\n\t\tpublic OutputWriter(OutputStream out) {\n\t\t\tsuper(out);\n\t\t}\n\n\t\tpublic OutputWriter(String fileName) throws FileNotFoundException {\n\t\t\tsuper(fileName);\n\t\t}\n\t\t\n\t\tpublic int getPrecision() {\n\t\t\treturn precision;\n\t\t}\n\n\t\tpublic void setPrecision(int precision) {\n\t\t\tthis.precision = precision;\n\t\t\t\n\t\t\tformat = createFormat(precision);\n\t\t\tformatWithSpace = format + \" \";\n\t\t}\n\t\t\n\t\tprivate String createFormat(int precision){\n\t\t\treturn \"%.\" + precision + \"f\";\n\t\t}\n\t\t\n\t\t@Override\n\t\tpublic void print(double d){\n\t\t\tprintf(format, d);\n\t\t}\n\t\t\n\t\tpublic void printWithSpace(double d){\n\t\t\tprintf(formatWithSpace, d);\n\t\t}\n\n\t\tpublic void printAll(double...d){\n\t\t\tfor (int i = 0; i < d.length - 1; ++i){\n\t\t\t\tprintWithSpace(d[i]);\n\t\t\t}\n\t\t\t\n\t\t\tprint(d[d.length - 1]);\n\t\t}\n\t\t\n\t\t@Override\n\t\tpublic void println(double d){\n\t\t\tprintlnAll(d);\n\t\t}\n\t\t\n\t\tpublic void printlnAll(double... d){\n\t\t\tprintAll(d);\n\t\t\tprintln();\n\t\t}\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tint[][] steps = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; \n\t\n\tboolean check(int index, int lim){\n\t\treturn (0 <= index && index < lim);\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tvoid solve() throws IOException{\n\t\tint n = readInt();\n\t\t\n\t\tlong[] count = new long[10];\n\t\tfor (int i = 1; i <= 9; ++i){\n\t\t\tcount[i] = count(i, n);\n\t\t}\n\t\t\n\t\tint[][] d = new int[10][10];\n\t\tfor (int i = 1; i <= 9; ++i){\n\t\t\tfor (int j = 1; j <= 9; ++j){\n\t\t\t\td[i][j] = (i * j) % 9;\n\t\t\t\tif (d[i][j] == 0) d[i][j] = 9;\n\t\t\t}\n\t\t}\n\t\t\n\t\tlong ans = 0;\n\t\tfor (int a = 1, s = 1; a <= n; ++a, s = (s == 9? 1: s + 1)){\n\t\t\tint k = n / a;\n\t\t\t\n\t\t\tfor (int b = 1; b <= 9; ++b){\n\t\t\t\tint c = d[s][b];\n\t\t\t\t\n\t\t\t\tlong res = count[b] * count[c] - count(b, k);\n\t\t\t\t\n//\t\t\t\tlong resStress = stress(a, b, c, n);\n\t\t\t\t\n//\t\t\t\tif (res != resStress){\n//\t\t\t\t\tSystem.err.println(a + \" \" + b + \" \" + res + \" \" + resStress);\n//\t\t\t\t}\n\t\t\t\t\n\t\t\t\tans += res;\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.println(ans);\n\t}\n\t\n\tint d(int x){\n\t\tint res = x % 9;\n\t\t\n\t\treturn (res == 0? 9: res);\n\t}\n\t\n\tlong count(int d, int n){\n\t\tlong res = n / 9;\n\t\t\n\t\tint md = n % 9;\n\t\tif (md > 0 && md >= d) ++res;\n\t\t\n\t\treturn res;\n\t}\n\t\n\tlong stress(int a, int b, int c, int n){\n\t\tlong res = 0;\n\t\t\n\t\tfor (int i = b; i <= n; i += 9){\n\t\t\tfor (int j = c; j <= n; j += 9){\n\t\t\t\tif (a * i != j){\n\t\t\t\t\t++res;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn res;\n\t}\n}\n\n", "lang_cluster": "Java", "tags": ["number theory"], "code_uid": "e02138fc52d7d6d601bdb23cf53c3c54", "src_uid": "fc133fe6353089a0ebee08dec919f608", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\tboolean eof;\n\n\tpublic String nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn \"-1\";\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tpublic int nextInt() {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tvoid solve() {\n\t\tString s = nextToken();\n\t\tint ans = 0;\n\t\tchar last = ' ';\n\t\tint kol = 0;\n\t\t\n\t\tfor (int i = 0; i < s.length(); ++i){\n\t\t\tchar c = s.charAt(i);\n\t\t\tif (c == last){\n\t\t\t\t\n\t\t\t\tif (kol == 5){\n\t\t\t\t\t++ans;\n\t\t\t\t\tkol = 0;\n\t\t\t\t}\n\t\t\t\t++kol;\n\t\t\t} else {\n\t\t\t\t++ans;\n\t\t\t\tlast = c;\n\t\t\t\tkol = 1;\n\t\t\t}\n\t\t}\n\t\tout.print(ans);\n\t}\n\n\tBufferedReader br;\n\tStringTokenizer st;\n\tPrintWriter out;\n\n\tvoid run() {\n\t\ttry {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(new OutputStreamWriter(System.out));\n\n\t\t\t//br= new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\t//out = new PrintWriter(new FileWriter(\"output.txt\"));\n\t\t\tsolve();\n\t\t\tbr.close();\n\t\t\tout.close();\n\t\t} catch (Throwable e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew Main().run();\n\t}\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "93966b22704ef09a1ea7f2b1e8ab6eee", "src_uid": "5257f6b50f5a610a17c35a47b3a0da11", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport static java.util.Collections.reverseOrder;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.LinkedHashMap;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Map.Entry;\nimport java.util.Scanner;\nimport java.util.Set;\nimport java.util.stream.Collectors;\n\n/**\n *\n * @author Ahmed_Naser\n */\npublic class HelloWorld {\n\n \n \n public static void main(String[] args) {\n Scanner in=new Scanner(System.in);\n int n = in.nextInt();\n int m = in.nextInt();\n \n int matchboxes[] = new int[m];\n int matches[]= new int[m];\n \n for(int i = 0 ; i < m ; i++)\n {\n matchboxes[i] =in.nextInt();\n matches[i] = in.nextInt();\n }\n \n \n int max = matches[0];\n int index = 0 ; \n int count = 0 ;\n while( n > 0)\n {\n \n for( int j = 0 ; j < m ; ++j)\n {\n if( matches[j] >= max)\n {\n max= matches[j]; \n index = j;\n \n } \n } \n if( matchboxes[index] <= n)\n {\n n = n - matchboxes[index];\n count = count + (matches[index] * matchboxes[index] ); \n matches[index] = 0 ;\n }\n else\n {\n \n count = count + (n * matches[index]);\n n = 0 ;\n }\n max = matches[0];\n }\n \n System.out.println(count);\n \n }\n}\n", "lang_cluster": "Java", "tags": ["sortings", "implementation", "greedy"], "code_uid": "3681e67415541947c7eef6b74e6654a3", "src_uid": "c052d85e402691b05e494b5283d62679", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\n\npublic class Main {\n/*\n\n\n\n */\n\tpublic static void main(String[] args) throws Exception {\n\t\tuu.s1();\n\t}\n\tpublic static class uu {\n\t\tpublic static BR in = new BR();\n\t\tpublic static boolean bg = true;\n\t\tpublic static void s1() throws Exception {\n\t\t\tint n1 = in.ni();\n\t\t\tint n2 = in.ni();\n\t\t\tint t = in.ni();\n\t\t\tBigInteger fin = bi(0);\n\t\t\tfor (int i = 4;i<=t-1;i++){\n\t\t\t\tBigInteger q1 = Comb.combination(n1, i);\n\t\t\t\tBigInteger q2 = Comb.combination(n2, t-i);\n\t\t\t\tBigInteger q3 = q1.multiply(q2);\n\t\t\t\tfin = fin.add(q3);\n\t\t\t}\n\t\t\tpn(fin);\n\t\t}\n\t\tpublic static void s2() throws Exception {\n\t\t}\n\t\tpublic static void s3() throws Exception {\n\t\t\t\n\t\t}\n\t\tprivate static BigInteger bi(long n1) {\n\t\t\treturn BigInteger.valueOf(n1);\n\t\t}\n\n\t\tprivate static void pn(Object o1) {\n\t\t\tSystem.out.println(o1);\n\t\t}\n\n\t\tpublic static boolean allTrue(boolean ... l1){\n\t\t\tfor (boolean e: l1) if (!e) return false;\n\t\t\treturn true;\n\t\t}\n\t\tpublic static boolean allFalse(boolean ... l1){\n\t\t\tfor (boolean e: l1) if (e) return false;\n\t\t\treturn true;\n\t\t}\n\t}\n\tprivate static class Comb {\n\t\tpublic static BigInteger bi(long n1){\n\t\t\treturn BigInteger.valueOf(n1);\n\t\t}\n\t\tpublic static BigInteger factorial(int n1){\n\t\t\treturn factorial(n1, n1);\n\t\t}\n\t\tpublic static BigInteger factorial(int n1, int k1){\n\t\t\tBigInteger fin = bi(1);\n\t\t\tBigInteger mult = bi(n1);\n\t\t\tfor (int i = 0;i generateSet(int [] y) {\n\t\t\tHashSet set = new HashSet();\n\t\t\t\n\t\t\tfor(Integer key : y) {\n\t\t\t\tset.add(key);\n\t\t\t}\n\t\t\t\n\t\t\treturn set;\n\t\t}\n\t \n\t HashSet generateSet(long [] y) {\n\t\t\tHashSet set = new HashSet();\n\t\t\t\n\t\t\tfor(Long key : y) {\n\t\t\t\tset.add(key);\n\t\t\t}\n\t\t\t\n\t\t\treturn set;\n\t\t}\n\t\t\n\t\tHashMap generateCountMap(int [] y) {\n\t\t\tHashMap map = new HashMap();\n\t\t\t\n\t\t\tfor(int key : y) {\n\t\t\t\tmap.putIfAbsent(key, 0);\n\t\t\t\tmap.put(key, map.get(key) + 1);\n\t\t\t}\n\t\t\t\n\t\t\treturn map;\n\t\t}\n\t\t\n\t\tHashMap generateCountMap(long [] y) {\n\t\t\tHashMap map = new HashMap();\n\t\t\t\n\t\t\tfor(long key : y) {\n\t\t\t\tmap.putIfAbsent(key, 0);\n\t\t\t\tmap.put(key, map.get(key) + 1);\n\t\t\t}\n\t\t\t\n\t\t\treturn map;\n\t\t}\n\t\t\n\t\tint [] shrink(int[] a) {\n\t int n = a.length;\n\t long [] b = new long[n];\n\t \n\t for (int i = 0; i < n; i++) b[i] = (long) a[i] << 32 | i;\n\t \n\t shuffleAndSort(b);\n\t \n\t int[] ret = new int[n];\n\t int p = 0;\n\t \n\t for (int i = 0; i < n; i++) {\n\t if (i > 0 && (b[i] ^ b[i - 1]) >> 32 != 0) p++;\n\t ret[(int) b[i]] = p;\n\t }\n\t \n\t for (int i = 0; i < n; i++) {\n\t ret[i]++;\n\t }\n\t \n\t return ret;\n\t }\n\t\t\n\t\tlong [] shrink(long [] a) {\n\t int n = a.length;\n\t long[] b = new long[n];\n\t \n\t for (int i = 0; i < n; i++) b[i] = (long) a[i] << 32 | i;\n\t \n\t shuffleAndSort(b);\n\t \n\t long [] ret = new long[n];\n\t int p = 0;\n\t \n\t for (int i = 0; i < n; i++) {\n\t if (i > 0 && (b[i] ^ b[i - 1]) >> 32 != 0) p++;\n\t ret[(int) b[i]] = p;\n\t }\n\t \n\t for (int i = 0; i < n; i++) {\n\t ret[i]++;\n\t }\n\t \n\t return ret;\n\t }\n\t\t\n\t\tint getMax(int [] a) {\n\t\t\tint maxValue = Integer.MIN_VALUE;\n\t\t\t\n\t\t\tfor(int v : a) {\n\t\t\t\tmaxValue = max(v, maxValue);\n\t\t\t}\n\t\t\t\n\t\t\treturn maxValue;\n\t\t}\n\t\t\n\t\tlong getMax(long [] a) {\n\t\t\tlong maxValue = Long.MIN_VALUE;\n\t\t\t\n\t\t\tfor(long v : a) {\n\t\t\t\tmaxValue = max(v, maxValue);\n\t\t\t}\n\t\t\t\n\t\t\treturn maxValue;\n\t\t}\n\t\t\n\t\tint getMin(int [] a) {\n\t\t\tint minValue = Integer.MAX_VALUE;\n\t\t\t\n\t\t\tfor(int v : a) {\n\t\t\t\tminValue = min(v, minValue);\n\t\t\t}\n\t\t\t\n\t\t\treturn minValue;\n\t\t}\n\t\t\n\t\tlong getMin(long [] a) {\n\t\t\tlong minValue = Long.MAX_VALUE;\n\t\t\t\n\t\t\tfor(long v : a) {\n\t\t\t\tminValue = min(v, minValue);\n\t\t\t}\n\t\t\t\n\t\t\treturn minValue;\n\t\t}\n\t\t\n\t void shuffleAndSort(ArrayList a) {\n\t Random rnd = new Random();\n\t \n\t int size = a.size();\n\t \n\t for (int i = size - 1; i >= 1; i--) {\n\t int j = rnd.nextInt(i + 1);\n\t int t = a.get(i);\n\t a.set(i, a.get(j));\n\t a.set(j, t);\n\t }\n\t \n\t Collections.sort(a);\n\t }\n\t\t\n\t void shuffleAndSortLongList(ArrayList a) {\n\t Random rnd = new Random();\n\t \n\t int size = a.size();\n\t \n\t for (int i = size - 1; i >= 1; i--) {\n\t int j = rnd.nextInt(i + 1);\n\t long t = a.get(i);\n\t a.set(i, a.get(j));\n\t a.set(j, t);\n\t }\n\t \n\t Collections.sort(a);\n\t }\n\t\t\n\t void shuffleAndSort(int [] a) {\n\t Random rnd = new Random();\n\t \n\t for (int i = a.length - 1; i >= 1; i--) {\n\t int j = rnd.nextInt(i + 1);\n\t int t = a[i];\n\t a[i] = a[j];\n\t a[j] = t;\n\t }\n\t \n\t Arrays.sort(a);\n\t }\n\t \n\t void shuffleAndSort(long [] a) {\n\t Random rnd = new Random();\n\t \n\t for (int i = a.length - 1; i >= 1; i--) {\n\t int j = rnd.nextInt(i + 1);\n\t long t = a[i];\n\t a[i] = a[j];\n\t a[j] = t;\n\t }\n\t \n\t Arrays.sort(a);\n\t }\n\t \n\t\tint[] getIntArray(ArrayList list) {\n\t\t\t\n\t\t\tint [] array = new int[list.size()];\n\t\t\t\n\t\t\tint size = array.length;\n\t\t\t\n\t\t\tfor(int i = 0; i list) {\n\t\t\t\n\t\t\tlong [] array = new long[list.size()];\n\t\t\t\n\t\t\tint size = array.length;\n\t\t\t\n\t\t\tfor(int i = 0; i=0; i--) {\n uusA.append(reverse(a.charAt(i)));\n }\n a = uusA.toString();\n \n// StringBuilder buildA = new StringBuilder();\n// buildA.append('N');\n// for (int i=0; i<12; i++) {\n// int size = buildA.length();\n// for (int j=0; j=0; i--) {\n// buildB.append(reverse(a.charAt(i)));\n// }\n// String b = buildB.toString();\n\n StringHasher sh = new StringHasher();\n ;HashedString ah = sh.hashString(a);\n ;HashedString bh = sh.hashString(b);\n HashedString[] hstrings = sh.hashString(a, b);\n \n \n for (int i=0; i 0) result -= (hashes[startIndex-1] * modifiers[endIndex-startIndex+1]) % M;\n if (result < 0) result += M;\n return result;\n }\n \n // Less interesting methods below\n \n \n \n /**\n * Efficient for 2 input parameter strings in particular.\n */\n HashedString[] hashString(String first, String second) {\n HashedString[] array = new HashedString[2];\n int n = first.length();\n long[] modifiers = new long[n];\n modifiers[0] = 1;\n \n long[] firstHashes = new long[n];\n firstHashes[0] = first.charAt(0);\n array[0] = new HashedString(firstHashes, modifiers);\n \n long[] secondHashes = new long[n];\n secondHashes[0] = second.charAt(0);\n array[1] = new HashedString(secondHashes, modifiers);\n\n for (int i=1; i modOptions = new ArrayList<>(20);\n modOptions.add(353873237L);\n modOptions.add(353875897L);\n modOptions.add(353878703L);\n modOptions.add(353882671L);\n modOptions.add(353885303L);\n modOptions.add(353888377L);\n modOptions.add(353893457L);\n P = modOptions.get(new Random().nextInt(modOptions.size()));\n \n modOptions.clear();\n modOptions.add(452940277L);\n modOptions.add(452947687L);\n modOptions.add(464478431L);\n modOptions.add(468098221L);\n modOptions.add(470374601L);\n modOptions.add(472879717L);\n modOptions.add(472881973L);\n M = modOptions.get(new Random().nextInt(modOptions.size()));\n }\n}\n", "lang_cluster": "Java", "tags": ["strings"], "code_uid": "1b2e0b7f899983accc8e7be11dc6ffda", "src_uid": "85f43628bec7e9b709273c34b894df6b", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Tanya\n{\n public static void main(String arg[])\n {\n Scanner sc=new Scanner(System.in);\n long n=sc.nextLong();\n long k=sc.nextLong();\n long a=sc.nextLong();\n long b=sc.nextLong();\n \n long s=0;\n if(k==1)\n {\n System.out.println((n-1)*a);\n return;\n }\n while(n!=1)\n {\n if(n 0) {\n subEnd = i;\n sb.append(remix.substring(subStart, subEnd));\n if (subEnd > 0) // No ' ' to be added at the beginning\n sb.append(' ');\n i += skip;\n subStart = i;\n }\n }\n sb.append(remix.substring(subStart, remix.length()));\n return sb.toString();\n }\n\n // Returns characters to be skipped to remove WUBs\n static int skipWUBs(String remix, int idx, int uptoIdx) {\n int skip = 0;\n boolean foundWUB;\n if (idx + 3 > uptoIdx)\n foundWUB = false;\n else {\n boolean checkW = remix.charAt(idx) == 'W';\n boolean checkU = remix.charAt(idx+1) == 'U';\n boolean checkB = remix.charAt(idx+2) == 'B';\n if (checkW && checkU && checkB)\n foundWUB = true;\n else\n foundWUB = false;\n }\n if (foundWUB)\n return 3 + skipWUBs(remix, idx+3, uptoIdx);\n else\n return 0;\n }\n}", "lang_cluster": "Java", "tags": ["strings"], "code_uid": "b04b4c9f7d79dd1a9b976729d6b2100c", "src_uid": "edede580da1395fe459a480f6a0a548d", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Scanner;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.BitSet;\nimport java.util.Collections;\nimport java.util.Comparator;\npublic class A {\n\t public static long n;\n\t public static long h=(long) 1e10;\n\t\t public static void main(String[] args) throws IOException {\n\t\t \tFastReader sc=new FastReader();\n\t\t \t n=sc.nextLong();\n\t\t \t \n\t\t \tf(0,0,0);\n\t\t \tSystem.out.println(h);\n}\t\n\t\t public static void f(long x,int count4,int count7){\n\t\t \tif(x>100*n) return;\n\t\t \tif(x>=n && count4==count7) h=Math.min(h,x);\n\t\t \t\n\t\t \tf(10*x+4,count4+1,count7);\n\t\t \tf(10*x+7,count4,count7+1);\n\t\t \t \n\t\t }\n\t\t \n\t\t \n\n static class FastReader\n\t\t {\n\t\t BufferedReader br;\n\t\t StringTokenizer st;\n\t\t \n\t\t public FastReader(){\n\t\t \t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t }\n\t\t \n\t\t String next()\n\t\t {\n\t\t while (st == null || !st.hasMoreElements())\n\t\t {\n\t\t try\n\t\t {\n\t\t st = new StringTokenizer(br.readLine());\n\t\t }\n\t\t catch (IOException e)\n\t\t {\n\t\t e.printStackTrace();\n\t\t }\n\t\t }\n\t\t return st.nextToken();\n\t\t }\n\t\t \n\t\t int nextInt()\n\t\t {\n\t\t return Integer.parseInt(next());\n\t\t }\n\t\t \n\t\t long nextLong()\n\t\t {\n\t\t return Long.parseLong(next());\n\t\t }\n\t\t \n\t\t double nextDouble()\n\t\t {\n\t\t return Double.parseDouble(next());\n\t\t }\n\t\t \n\t\t String nextLine()\n\t\t {\n\t\t String str = \"\";\n\t\t try\n\t\t {\n\t\t str = br.readLine();\n\t\t }\n\t\t catch (IOException e)\n\t\t {\n\t\t e.printStackTrace();\n\t\t }\n\t\t return str;\n\t\t }\n\t\t }\n}", "lang_cluster": "Java", "tags": ["brute force", "binary search", "bitmasks"], "code_uid": "6921bfb64a6bb2828a24e46ef6e351aa", "src_uid": "77b5f83cdadf4b0743618a46b646a849", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.HashMap;\nimport java.util.Scanner;\n\npublic class que2 {\n\n\tpublic static void main(String[] args) {\n Scanner scn=new Scanner(System.in);\n int test=scn.nextInt();\n for(int t=1;t<=test;t++){\n \tint n=scn.nextInt();\n \tint d=scn.nextInt();\n \tint k=scn.nextInt();\n HashMap map=new HashMap<>();\n int []arr=new int[n];\n for(int i=0;i= 0;i--){\n\t\t\tfor(int j = i;j > 0;j /= 10){\n\t\t\t\tdp[i-j%10] = Math.min(dp[i-j%10], dp[i] + 1);\n\t\t\t}\n\t\t}\n\t\tout.println(dp[0]);\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception { new C().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tprivate int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "tags": ["dp"], "code_uid": "1edc1cf8077ba572ebb36155f7896e85", "src_uid": "fc5765b9bd18dc7555fa76e91530c036", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\n import java.io.*;\n\nimport java.util.*;\nimport java.util.Collections;\nimport java.util.Arrays;\n\n\npublic class Codechef {\n \n\n public static void main(String[] args) throws IOException {\n\tScanner sc = new Scanner(System.in);\n\tint n=sc.nextInt();\n\tif(n==1){\n\t\tSystem.out.println(1);\n\t\treturn;\n\t}\n\tlong arr[]=new long[100000];\n\tarr[0]=1;\n\tfor(int i=1;i<100000;i++){\n\t\tarr[i]=(int)Math.pow(2,i);\n\t\tarr[i]=arr[i-1]+arr[i];\n\t\t//System.out.println(arr[i]);\n\t}\n\tint j=0;\n\twhile(arr[j]0;i--){\n if(2*i<=apple&&4*i<=pear){\n result=i+(2*i)+(4*i);\n System.out.println(result+\"\");\n return;\n }else if(i==1){\n System.out.println(result+\"\");\n }\n \n }\n\n }\n \n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "c8d5752ea3fbf41ba020151f0c524fb8", "src_uid": "82a4a60eac90765fb62f2a77d2305c01", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\n\npublic class Main {\n\n\tpublic static void main(String[] args) {\n\t\t\n\t\tScanner in = new Scanner(System.in);\n\t\tint year = in.nextInt();\n\t\t\n\t\tboolean found = false;\n\t\tdo {\n\t\t\t\n\t\t\tyear++;\n\t\t\tint digit_4 = year % 10;\n\t\t\tint digit_3 = year % 100 - digit_4;\n\t\t\tint digit_2 = year % 1000 - (digit_4 + digit_3);\n\t\t\tint digit_1 = year - (digit_4 + digit_3 + digit_2);\n\t\t\t\n\t\t\tdigit_3 /= 10;\n\t\t\tdigit_2 /= 100;\n\t\t\tdigit_1 /= 1000;\n\t\t\t\n\t\t\tif (digit_1 != digit_2) {\n\t\t\t\t\n\t\t\t\tif (digit_1 != digit_3 && digit_2 != digit_3) {\n\t\t\t\t\tif (digit_1 != digit_4 && digit_2 != digit_4\n\t\t\t\t\t\t\t&& digit_3 != digit_4) {\n\t\t\t\t\t\tfound = true;\n\t\t\t\t\t}\n//\t\t\t\t\telse {\n//\t\t\t\t\t\tyear++;\n//\t\t\t\t\t}\n\t\t\t\t}\n//\t\t\t\telse {\n//\t\t\t\t\tyear += 10;\n//\t\t\t\t}\n\t\t\t}\n//\t\t\telse {\n//\t\t\t\tyear += 100;\n//\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n//\t\t\tSystem.err.println(digit_4);\n//\t\t\tSystem.err.println(digit_3);\n//\t\t\tSystem.err.println(digit_2);\n//\t\t\tSystem.err.println(digit_1);\n//\t\t\tSystem.exit(0);\n\t\t}\n\t\twhile (!found);\n\t\t\n\t\tSystem.out.println(year);\n\t}\n}", "lang_cluster": "Java", "tags": ["brute force"], "code_uid": "8ab520438b49495a6b464865cb5c66ba", "src_uid": "d62dabfbec52675b7ed7b582ad133acd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.util.Map.Entry;\nimport java.util.Stack;\n\n\npublic class distinctsub{\n\tpublic static class FastReader {\n\t\tBufferedReader br;\n\t\tStringTokenizer root;\n\t\t\n \n\t\tpublic FastReader() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n \n\t\tString next() {\n\t\t\twhile (root == null || !root.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\troot = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (Exception addd) {\n\t\t\t\t\taddd.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn root.nextToken();\n\t\t}\n \n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n \n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n \n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n \n\t\tString nextLine() {\n\t\t\tString str = \"\";\n\t\t\ttry {\n\t\t\t\tstr = br.readLine();\n\t\t\t} catch (Exception addd) {\n\t\t\t\taddd.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\t}\n\t\n\tpublic static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));\n\t\n\tpublic static FastReader sc = new FastReader();\n \n\tstatic int mod = (int) (1e9+7);\n\tstatic List[] edges ;\n\tstatic int n;\n\tstatic long k;\n\tstatic char[] s;\n\tstatic Long[][][] dp;\n\t\n\tpublic static void main(String[] args) {\n\t\tn = sc.nextInt();\n\t\tk = sc.nextLong();\n\t\ts = sc.next().toCharArray();\n\t\tdp = new Long[n+1][n+1][n+1];\n\t\tlong cost = 0;\n\t\tfor(int i=n;i>=0;--i) {\n\t\t\tlong cnt = f(0,-1,i);\n\t\t\tif(cnt >= k) {\n\t\t\t cost+= k*(n-i);\n\t\t\t k = 0;\n\t\t\t break;\t\n\t\t\t}else {\n\t\t\t\tk-=cnt;\n\t\t\t\tcost+= cnt*(n-i);\n\t\t\t}\n\t\t}\n\t\tif(k > 0) cost = -1;\n\t\tout.print(cost);\n\t\n\tout.close();\n}\n\n\tprivate static long f(int i, int prev, int len) {\n\t\tif(len < 0) return 0;\n\t\tif(i == n) {\n\t\t\tif(len == 0) return 1;\n\t\t\treturn 0;\n\t\t}\n\t\tif(dp[i][prev+1][len] != null) return dp[i][prev+1][len];\n\t\t\n\t\tlong ans = 0;\n\t\tif(prev!=-1 && s[i] == s[prev])\n\t\t\tans = f(i+1,i,len-1);\n\t\telse ans = f(i+1,i,len-1) + f(i+1,prev,len);\n\t\treturn dp[i][prev+1][len] = ans;\n\t}\n\t\n\t\n}\n\n", "lang_cluster": "Java", "tags": ["strings", "dp"], "code_uid": "9286f75e3abd9a54c6817039e5b3c474", "src_uid": "ae5d21919ecac431ea7507cb1b6dc72b", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n/**\n *\n * @author cybros.ru\n */\npublic class Main {\n PrintWriter cout;\n Scanner cin;\n public static void main(String[] args) throws IOException {\n new Main().run();\n }\n \n void run() throws IOException{\n cout =new PrintWriter(new OutputStreamWriter(System.out)); \n cin = new Scanner(System.in); \n solve();\n cout.flush();\n }\n \n void solve() throws IOException{\n int r1=cin.nextInt();\n int r2=cin.nextInt();\n int c1=cin.nextInt();\n int c2=cin.nextInt();\n int d1=cin.nextInt();\n int d2=cin.nextInt();\n boolean f=false;\n loop:{\n for(int g1=1;g1<10;g1++){\n for(int g2=1;g2<10;g2++){\n for(int g3=1;g3<10;g3++){\n for(int g4=1;g4<10;g4++){\n if(g1+g2==r1&&g3+g4==r2&&g1+g3==c1&&g2+g4==c2&&g1+g4==d1&&g2+g3==d2){\n if(g1!=g2&&g1!=g3&&g1!=g4&&g2!=g3&&g2!=g4&&g3!=g4){\n cout.println(g1+\" \"+g2);\n cout.println(g3+\" \"+g4);\n f=true;\n break loop;\n }\n }\n }\n \n }\n }\n }\n }\n if(f==false){\n cout.println(\"-1\"); \n }\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "math"], "code_uid": "b358795070885d138fc7eb8eaf530b4a", "src_uid": "6821f502f5b6ec95c505e5dd8f3cd5d3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import static java.lang.Double.parseDouble;\nimport static java.lang.Integer.MAX_VALUE;\nimport static java.lang.Integer.max;\nimport static java.lang.Long.max;\nimport static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.Math.abs;\nimport static java.lang.Math.min;\nimport static java.lang.Math.toRadians;\nimport static java.lang.System.exit;\nimport static java.lang.System.gc;\n\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class A {\n\n static BufferedReader in;\n static PrintWriter out;\n static StringTokenizer tok;\n\n int n, a[] = new int[20];\n\n boolean fun(int i, int deg) {\n return i == n ? (deg + 360) % 360 == 0 : fun(i + 1, deg + a[i]) || fun(i + 1, deg - a[i]);\n }\n\n void solve() throws Exception {\n n = nextInt();\n a = na(n);\n out.println(fun(0, 0) ? \"YES\" : \"NO\");\n }\n\n\n public int lower_bound(long[] a, long v) {\n int low = -1, high = a.length;\n while (high - low > 1) {\n int h = high + low >>> 1;\n if (a[h] >= v) {\n high = h;\n } else {\n low = h;\n }\n }\n return high;\n }\n\n private int gcd(int a, int b) {\n while (b > 0) {\n int temp = b;\n b = a % b;\n a = temp;\n }\n return a;\n }\n\n private int lcm(int a, int b) {\n return a * (b / gcd(a, b));\n }\n\n private int[] na(int n) throws IOException {\n int[] a = new int[n];\n for (int i = 0; i < n; i++) a[i] = nextInt();\n return a;\n }\n\n private long[] nal(int n) throws IOException {\n long[] a = new long[n];\n for (int i = 0; i < n; i++) a[i] = nextLong();\n return a;\n }\n\n int nextInt() throws IOException {\n return parseInt(next());\n }\n\n long nextLong() throws IOException {\n return parseLong(next());\n }\n\n double nextDouble() throws IOException {\n return parseDouble(next());\n }\n\n String next() throws IOException {\n while (tok == null || !tok.hasMoreTokens()) {\n tok = new StringTokenizer(in.readLine());\n }\n return tok.nextToken();\n }\n\n public static void main(String[] args) throws Exception {\n try {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(new OutputStreamWriter(System.out));\n //long lStartTime = System.currentTimeMillis();\n new A().solve();\n //long lEndTime = System.currentTimeMillis();\n //out.println(\"Elapsed time in seconds: \" + (double)(lEndTime - lStartTime) / 1000.0);\n in.close();\n out.close();\n } catch (Throwable e) {\n e.printStackTrace();\n exit(1);\n }\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "dp", "bitmasks"], "code_uid": "5a6d0e13e78630071422c277460caa5d", "src_uid": "01b50fcba4185ceb1eb8e4ba04a0cc10", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "\n\nimport java.util.Scanner;\n\n/**\n * Created by amitchh on 2/18/2015.\n */\npublic class A515Div2 {\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n int x = input.nextInt();\n int y = input.nextInt();\n int s = input.nextInt();\n int steps = Math.abs(x) + Math.abs(y);\n if( (s >= steps) && ((s - steps) % 2 == 0))\n System.out.println(\"Yes\");\n else\n System.out.println(\"No\");\n }\n}\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "64e24453d2bc80ae9dbfc33d4138472a", "src_uid": "9a955ce0775018ff4e5825700c13ed36", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class main \n{\n\tpublic static void main(String[] args) throws IOException\n\t{\n\t\tScanner in = new Scanner(System.in);\n\t\t\n\t\tint[] colors = new int[4];\n\t\t\n\t\tint ans = 4;\n\t\t\n\t\tfor(int i = 0; i < 4; i++)\n\t\t{\n\t\t\tcolors[i] = in.nextInt();\n\t\t\t\n\t\t\tboolean unique = true;\n\t\t\t\n\t\t\tfor(int j = 0; j < i; j++)\n\t\t\t{\n\t\t\t\tif(colors[i] == colors[j])\n\t\t\t\t{\n\t\t\t\t\tunique = false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif(unique)\n\t\t\t{\n\t\t\t\tans--;\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(ans);\n\t}\t\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "0dcd8ab2110b4465dcfa038a90be8c8d", "src_uid": "38c4864937e57b35d3cce272f655e20f", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n long n = sc.nextLong();\n long res = (n / 2) + (n / 3) - (n / 6) + (n / 42)\n +(n / 5) + (n / 7) + (n/ 30) + (n / 70) + (n / 105)\n -(n / 10) - (n / 15) - (n / 14) - (n / 21) - (n / 35) - (n / 210);\n System.out.println(n - res);\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "number theory"], "code_uid": "80db3d064f45537bd7563130c38d4494", "src_uid": "e392be5411ffccc1df50e65ec1f5c589", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class P1 {\n\tprivate static final Scanner IN = new Scanner(System.in);\n\tprivate static final int TOT = 3000;\n\tprivate static final boolean primos[] = new boolean[TOT+1];\n\t\n\tprivate static final void fillCriba(){\n\t\tprimos[0]=true;\n\t\tprimos[1]=true;\n\t\tint tope = (int)Math.sqrt(TOT)+1;\n\t\tfor (int i = 2; i <= tope; i++) {\n\t\t\tif(isPrimo(i)){\n\t\t\t\tif((i*i)>=TOT) return;\n\t\t\t\tfor (int j = i; j <= (TOT/2)+1; j++) {\n\t\t\t\t\tif (j*i > TOT) break;\n\t\t\t\t\tprimos[j*i]=true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tfillCriba();\n\t\tint c = 0;\n\t\tint n = IN.nextInt(); \n\t\tfor (int i = 6; i <= n; i++) {\n\t\t\tif(isAlmost(i)) c++;\n\t\t}\n\t\tSystem.out.println(c);\n\t}\n\t\n\tprivate static boolean isAlmost(int n){\n\t\tint c = 0;\n\t\tfor (int i = 2; i < n; i++) {\n\t\t\tif (c>2) return false;\n\t\t\tif(n%i==0)\n\t\t\t\tif(isPrimo(i)) c++;\n\t\t}\n\t\treturn c==2;\n\t}\n\t\n\tprivate static boolean isPrimo(int n){\n\t\treturn !primos[n];\n\t}\n}", "lang_cluster": "Java", "tags": ["number theory"], "code_uid": "fd4621029401879b850f462c4ecb0e04", "src_uid": "356666366625bc5358bc8b97c8d67bd5", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class PetrAndBook {\n public static void main(String[] args) throws IOException {\n BufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n int n = Integer.parseInt(f.readLine());\n int[] a = new int[7];\n int sum = 0;\n StringTokenizer st = new StringTokenizer(f.readLine());\n for (int i = 0; i < 7; i++)\n sum += a[i] = Integer.parseInt(st.nextToken());\n n %= sum;\n if (n == 0)\n n = sum;\n int i = 0;\n while (n > 0)\n n -= a[i++];\n System.out.println(i);\n }\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "d17835d79ae593d5921fedb4a7c59882", "src_uid": "007a779d966e2e9219789d6d9da7002c", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.*;\npublic class A59 {\n\tpublic static void main(String args[]){\n\t\tScanner in = new Scanner(System.in);\n\t\tString s = in.next();\n\t\tint cnt=0;\n\t\tfor(int i =0;i(s.length()-cnt))System.out.println(s.toUpperCase());\n\t\telse System.out.println(s.toLowerCase());\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["strings", "implementation"], "code_uid": "3d6c527809e715d865a61f20de5d6a05", "src_uid": "b432dfa66bae2b542342f0b42c0a2598", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\n\npublic class scorify{\n\tpublic static void main(String[] args){\n\tScanner in=new Scanner(System.in);\n int n = in.nextInt();\n int k = in.nextInt();\n \n System.out.print((n>k && k>0) ? 1 : 0 );\n if(k!=n){\n if(k>1) System.out.print(\" \" + ( ( (k>=(n/2)) ? n-k : ( (n>=k*3) ? k*2 : n-k ) ) ) );\n \tif(k==1) System.out.print( ( n-k==1 ? (\" \" + 1) : (\" \"+2) ) );\n \tif(k==0) System.out.print(\" \" + 0);\n }else{System.out.print(\" \" + 0);}\n \n }\n}", "lang_cluster": "Java", "tags": ["math", "constructive algorithms"], "code_uid": "fdb9f68abb2c3019dcbf9ee22981c4b9", "src_uid": "bdccf34b5a5ae13238c89a60814b9f86", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.util.InputMismatchException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskA solver = new TaskA();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskA {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n long s = in.nextLong();\n long x = in.nextLong();\n out.println(f2(s, x));\n }\n\n long f2(long s, long x) {\n int[] cnt = new int[1 << 21];\n long rx = x & ((1 << 20) - 1);\n for (long ra = 0; ra < (1 << 20); ++ra) {\n long rb = rx ^ ra;\n ++cnt[(int) (ra + rb)];\n }\n long lx = x >> 20;\n long res = 0;\n for (long la = 0; la < (1 << 20); ++la) {\n long lb = lx ^ la;\n long rem = s - (la << 20) - (lb << 20);\n if (rem >= 0 && rem < cnt.length) {\n res += cnt[(int) rem];\n }\n }\n if (s == x) {\n res -= 2;\n }\n return res;\n }\n\n }\n\n static class InputReader {\n BufferedReader bufReader;\n StringTokenizer stringTokenizer;\n boolean isEof = false;\n\n public InputReader(InputStream stream) {\n bufReader = new BufferedReader(new InputStreamReader(stream));\n }\n\n public String next() {\n while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {\n try {\n String line = bufReader.readLine();\n if (line == null) {\n isEof = true;\n return null;\n }\n stringTokenizer = new StringTokenizer(line);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n }\n return stringTokenizer.nextToken();\n }\n\n public long nextLong() {\n String s = next();\n if (s == null) {\n return 0;\n }\n return Long.parseLong(s);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["math", "dp"], "code_uid": "f7f90fc8157d82df4f9e25665e938e5e", "src_uid": "18410980789b14c128dd6adfa501aea5", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Anand Iyer\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastScanner in = new FastScanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskC {\n public static boolean angle(TaskC.Point a, TaskC.Point b) {\n double amag = a.mag();\n double bmag = b.mag();\n double abmag = a.v * b.v + a.w * b.w + a.x * b.x + a.y * b.y + a.z * b.z;\n double angle = Math.toDegrees(Math.acos(abmag / (amag * bmag)));\n if (angle < 90) {\n return true;\n }\n return false;\n }\n\n public void solve(int testNumber, FastScanner in, PrintWriter out) {\n int n = in.nextInt();\n if (n > 11) {\n out.println(\"0\");\n } else {\n HashSet good = new HashSet();\n ArrayList arr = new ArrayList<>();\n for (int i = 0; i < n; i++) {\n int a = in.nextInt();\n int b = in.nextInt();\n int c = in.nextInt();\n int d = in.nextInt();\n int e = in.nextInt();\n TaskC.Point p = new TaskC.Point(a, b, c, d, e);\n arr.add(p);\n }\n for (int i = 0; i < n; i++) {\n boolean b = true;\n for (int j = 0; j < n; j++) {\n for (int k = 0; k < n; k++) {\n if (i != j && i != k && j != k) {\n TaskC.Point one = arr.get(j);\n TaskC.Point two = arr.get(k);\n TaskC.Point three = arr.get(i);\n TaskC.Point lol2 = new TaskC.Point(one.v - three.v, one.w - three.w, one.x - three.x, one.y - three.y, one.z - three.z);\n TaskC.Point lol1 = new TaskC.Point(two.v - three.v, two.w - three.w, two.x - three.x, two.y - three.y, two.z - three.z);\n if (angle(lol1, lol2)) {\n b = false;\n }\n }\n }\n }\n if (b) {\n good.add(i + 1);\n }\n }\n if (good.size() == 0) {\n out.println(\"0\");\n } else {\n out.println(good.size());\n for (int i : good) {\n out.println(i);\n }\n }\n }\n }\n\n public static class Point {\n int v;\n int w;\n int x;\n int y;\n int z;\n\n public Point(int a, int b, int c, int d, int e) {\n v = a;\n w = b;\n x = c;\n y = d;\n z = e;\n }\n\n public double mag() {\n return Math.sqrt(v * v + w * w + x * x + y * y + z * z);\n }\n\n }\n\n }\n\n static class FastScanner {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public FastScanner(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["brute force", "math", "geometry"], "code_uid": "ec19eddfbc9f3be2db0a6dbe94f7080d", "src_uid": "c1cfe1f67217afd4c3c30a6327e0add9", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\npublic class Main {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n int n = in.nextInt();\n int k = in.nextInt();\n int x = in.nextInt();\n int max = 0;\n ArrayList balls = new ArrayList<>();\n for (int i = 0; i < n; ++i)\n balls.add(in.nextInt());\n ArrayList copy = new ArrayList<>(balls);\n int ind = 0;\n while (index(balls, x, ind) != -1) {\n ind = index(balls, x, ind) + 1;\n balls.add(ind, x);\n while (has(balls))\n destroy(balls);\n max = Math.max(max, n - balls.size());\n balls = new ArrayList<>(copy);\n }\n out.println(max);\n out.close();\n }\n static int index(ArrayList balls, int x, int st) {\n for (int i = st; i < balls.size() - 1; ++i)\n if (balls.get(i) == balls.get(i + 1) && balls.get(i) == x)\n return i;\n return -1;\n }\n static void destroy(ArrayList balls) {\n for (int i = 0; i < balls.size() - 2; ++i)\n if (balls.get(i) == balls.get(i + 1) && balls.get(i) == balls.get(i + 2)) {\n int temp = balls.get(i);\n while (i < balls.size() && balls.get(i) == temp)\n balls.remove(i);\n }\n }\n static boolean has(ArrayList balls) {\n for (int i = 0; i < balls.size() - 2; ++i)\n if (balls.get(i) == balls.get(i + 1) && balls.get(i) == balls.get(i + 2))\n return true;\n return false;\n }\n}", "lang_cluster": "Java", "tags": ["two pointers", "brute force"], "code_uid": "06c859e2f53dfba7aaa115dbcd894836", "src_uid": "d73d9610e3800817a3109314b1e6f88c", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Divisibility {\n\n\tpublic static void main(String[] args) {\n\n\t\tScanner sc = new Scanner(System.in);\n\n\t\tdouble a = sc.nextDouble();\n\t\tdouble ans = Math.floor(a/2520);\n\n\t\tSystem.out.printf(\"%.0f\",ans);\n\n\t}\n\n}", "lang_cluster": "Java", "tags": ["math", "number theory"], "code_uid": "aa8a180c0397e093163d1aaa66efa1fb", "src_uid": "8551308e5ff435e0fc507b89a912408a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class code {\n public static void main(String[] args){\n code cc = new code();\n int x,c=0,num=0,r=0;\n Scanner n=new Scanner(System.in);\n x=n.nextInt();\n for(int i=1;num{\n\t\tint i, idx, x, y, mul;\n\t\tpublic Query(int a, int b, int c, int d, int m) {\n\t\t\ti = a;\n\t\t\tidx = b;\n\t\t\tx = c;\n\t\t\tmul = m;\n\t\t\ty = d;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(\n\t\t\t\tQuery o)\n\t\t{\n\t\t\treturn this.i - o.i;\n\t\t}\n\t}\n\tprivate long[][] pow(int a, int b, int n) {\n\t\tlong[][] mat = {{a,0,b},{1L,0,0},{0,1L,0}};\n\t\tif(n == 1)\n\t\t\treturn mat;\n\t\tlong[][] res = pow(a,b,n/2);\n\t\tres = multiply(res,res);\n\t\tif((n&1) != 0)\n\t\t\tres = multiply(mat, res);\n\t\treturn res;\n\t}\n\tprivate long[][] multiply(long[][] a, long[][] b) {\n\t\tlong[][] ret = new long[3][3];\n\t\tfor(int i=0;i<3;i++)\n\t\t\tfor(int j=0;j<3;j++)\n\t\t\t\tfor(int k=0;k<3;k++)\n\t\t\t\t\tret[i][j] = (ret[i][j] + ((a[i][k]*b[k][j])%mod))%mod;\n\t\treturn ret;\n\t}\n\tprivate class Node{\n\t\tNode left,right;\n\t\tint sum;\n\t\tpublic Node(int v) {\n\t\t\tsum=v;\n\t\t}\n\t\tpublic Node (Node left,Node right){\n\t\t\tthis.left = left;\n\t\t\tthis.right = right;\n\t\t\tif (left != null)\n\t\t\t\tsum = sum + left.sum;\n\t\t\tif (right != null)\n\t\t\t\tsum = sum + right.sum;\n\t\t}\n\t}\n\tpublic Node build(int l,int r) {\n\t\tif(l==r)\n\t\t\treturn new Node(0);\n\t\tint mid=l+((r-l)>>1);\n\t\tNode left=build(l,mid);\n\t\tNode right=build(mid+1,r);\n\t\treturn new Node(left,right);\n\t}\n\tpublic int query(int l,int r, Node root) {\n\t\treturn queryutil(l,r,root,0,size-1);\n\t}\n\tpublic int queryutil(int x,int y,Node node,int l,int r) {\n\t\tif(l>y || x>r) \n\t\t\treturn 0;\n\t\tif(x <= l && r<=y)\n\t\t\treturn node.sum;\n\t\tint mid=l+((r-l)>>1);\n\t\treturn queryutil(x,y,node.left,l,mid) + queryutil(x,y,node.right,mid+1,r);\n\t}\n\tpublic Node newNode(int pos,int val,Node node) {\n\t\treturn newNodeUtil(pos,val,node,0,size-1);\n\t}\n\tpublic Node newNodeUtil(int pos,int val,Node node,int l, int r) {\n\t\tif(l==r)\n\t\t\treturn new Node(val);\n\t\tint mid=l+((r-l)>>1);\n\t\tif(pos<=mid) {\n\t\t\tNode left=newNodeUtil(pos,val,node.left,l,mid);\n\t\t\treturn new Node(left,node.right);\n\t\t}else {\n\t\t\tNode right=newNodeUtil(pos,val,node.right,mid+1,r);\n\t\t\treturn new Node(node.left,right);\n\t\t}\n\t}\n\tprivate void debug(Object... o) {\n\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n\tprivate long pow(long a, long b, long c) {\n\t\tif (b == 0)\n\t\t\treturn 1;\n\t\tlong p = pow(a, b / 2, c);\n\t\tp = (p * p) % c;\n\t\treturn (b % 2 == 0) ? p : (a * p) % c;\n\t}\n\n\tprivate long gcd(long n, long l) {\n\t\tif (l == 0)\n\t\t\treturn n;\n\t\treturn gcd(l, n % l);\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew Thread(null, new Runnable() {\n\t\t\t@Override\n\t\t\tpublic void run() {\n\t\t\t\tnew Main().solve();\n\t\t\t}\n\t\t}, \"1\", 1 << 26).start();\n\t\t//new Main().solve();\n\t}\n\n\tpublic StringBuilder solve() {\n\t\tInputReader(System.in);\n\t\t/*\n\t\t * try { InputReader(new FileInputStream(\"C:\\\\Users\\\\hardik\\\\Desktop\\\\in.txt\"));\n\t\t * } catch(FileNotFoundException e) {}\n\t\t */\n\t\tpw = new PrintWriter(System.out);\n\t\t// ans_sb = new StringBuilder();\n\t\tsoln();\n\n\t\tpw.close();\n\t\t// System.out.println(ans_sb);\n\t\treturn ans_sb;\n\t}\n\n\tpublic void InputReader(InputStream stream1) {\n\t\tstream = stream1;\n\t}\n\n\tprivate boolean isWhitespace(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n\n\tprivate boolean isEndOfLine(int c) {\n\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t}\n\n\tprivate int read() {\n\t\tif (numChars == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (curChar >= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n\n\tprivate int nextInt() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tint res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tprivate long nextLong() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tlong res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tprivate String nextToken() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tStringBuilder res = new StringBuilder();\n\t\tdo {\n\t\t\tres.appendCodePoint(c);\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res.toString();\n\t}\n\n\tprivate String nextLine() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tStringBuilder res = new StringBuilder();\n\t\tdo {\n\t\t\tres.appendCodePoint(c);\n\t\t\tc = read();\n\t\t} while (!isEndOfLine(c));\n\t\treturn res.toString();\n\t}\n\n\tprivate int[] nextIntArray(int n) {\n\t\tint[] arr = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tarr[i] = nextInt();\n\t\t}\n\t\treturn arr;\n\t}\n\n\tprivate long[] nextLongArray(int n) {\n\t\tlong[] arr = new long[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tarr[i] = nextLong();\n\t\t}\n\t\treturn arr;\n\t}\n\n\tprivate void pArray(int[] arr) {\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\tSystem.out.print(arr[i] + \" \");\n\t\t}\n\t\tSystem.out.println();\n\t\treturn;\n\t}\n\n\tprivate void pArray(long[] arr) {\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\tSystem.out.print(arr[i] + \" \");\n\t\t}\n\t\tSystem.out.println();\n\t\treturn;\n\t}\n\n\tprivate boolean isSpaceChar(int c) {\n\t\tif (filter != null)\n\t\t\treturn filter.isSpaceChar(c);\n\t\treturn isWhitespace(c);\n\t}\n\n\tprivate char nextChar() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tchar c1 = (char) c;\n\t\twhile (!isSpaceChar(c))\n\t\t\tc = read();\n\t\treturn c1;\n\t}\n\n\tprivate interface SpaceCharFilter {\n\t\tpublic boolean isSpaceChar(int ch);\n\t}\n}", "lang_cluster": "Java", "tags": ["brute force", "math", "combinatorics"], "code_uid": "dfd32e3775b29f11457157334440b3cc", "src_uid": "7f4e533f49b73cc2b96b4c56847295f2", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class A163 {\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n PrintWriter pw = new PrintWriter(System.out);\n\n int x = Integer.valueOf(sc.nextLine());\n String str = sc.nextLine();\n int result = 0;\n\n for (int i = 1; i < str.length(); i++){\n if (str.charAt(i) == str.charAt(i - 1))\n result++;\n }\n\n\n pw.print(result);\n pw.flush();\n }\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "474b925e8ec01d0bc5dcdf8850dd89b9", "src_uid": "d561436e2ddc9074b98ebbe49b9e27b8", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "\r\n\r\nimport java.io.DataInputStream;\r\nimport java.io.FileInputStream;\r\nimport java.io.IOException;\r\n\r\npublic class AndSumBig {\r\n\r\n private static long solve(int n, int k)\r\n {\r\n\r\n int e= (int)1e9 +7;\r\n long res =1;\r\n\r\n for( int i=1; i <= k ;i++)\r\n {\r\n res = mMul(res,n,e);\r\n\r\n }\r\n return res;\r\n }\r\n\r\n public static void main(String[] args)\r\n throws IOException {\r\n Scanner s = new Scanner();\r\n int t = 1;\r\n t = s.nextInt();\r\n StringBuilder ans = new StringBuilder();\r\n int count = 0;\r\n while (t-- > 0) {\r\n int n = s.nextInt();\r\n int m = s.nextInt();\r\n ans.append(solve(n, m)).append(\"\\n\");\r\n }\r\n System.out.println(ans.toString());\r\n }\r\n\r\n static class Scanner {\r\n final private int BUFFER_SIZE = 1 << 16;\r\n private DataInputStream din;\r\n private byte[] buffer;\r\n private int bufferPointer, bytesRead;\r\n\r\n public Scanner() {\r\n din = new DataInputStream(System.in);\r\n buffer = new byte[BUFFER_SIZE];\r\n bufferPointer = bytesRead = 0;\r\n }\r\n\r\n public Scanner(String file_name) throws IOException {\r\n din = new DataInputStream(\r\n new FileInputStream(file_name));\r\n buffer = new byte[BUFFER_SIZE];\r\n bufferPointer = bytesRead = 0;\r\n }\r\n\r\n public String readLine() throws IOException {\r\n byte[] buf = new byte[64]; // line length\r\n int cnt = 0, c;\r\n while ((c = read()) != -1) {\r\n if (c == '\\n') {\r\n if (cnt != 0) {\r\n break;\r\n } else {\r\n continue;\r\n }\r\n }\r\n buf[cnt++] = (byte) c;\r\n }\r\n return new String(buf, 0, cnt);\r\n }\r\n\r\n public int nextInt() throws IOException {\r\n int ret = 0;\r\n byte c = read();\r\n while (c <= ' ') {\r\n c = read();\r\n }\r\n boolean neg = (c == '-');\r\n if (neg)\r\n c = read();\r\n do {\r\n ret = ret * 10 + c - '0';\r\n } while ((c = read()) >= '0' && c <= '9');\r\n\r\n if (neg)\r\n return -ret;\r\n return ret;\r\n }\r\n\r\n public long nextLong() throws IOException {\r\n long ret = 0;\r\n byte c = read();\r\n while (c <= ' ')\r\n c = read();\r\n boolean neg = (c == '-');\r\n if (neg)\r\n c = read();\r\n do {\r\n ret = ret * 10 + c - '0';\r\n } while ((c = read()) >= '0' && c <= '9');\r\n if (neg)\r\n return -ret;\r\n return ret;\r\n }\r\n\r\n public double nextDouble() throws IOException {\r\n double ret = 0, div = 1;\r\n byte c = read();\r\n while (c <= ' ')\r\n c = read();\r\n boolean neg = (c == '-');\r\n if (neg)\r\n c = read();\r\n\r\n do {\r\n ret = ret * 10 + c - '0';\r\n } while ((c = read()) >= '0' && c <= '9');\r\n\r\n if (c == '.') {\r\n while ((c = read()) >= '0' && c <= '9') {\r\n ret += (c - '0') / (div *= 10);\r\n }\r\n }\r\n\r\n if (neg)\r\n return -ret;\r\n return ret;\r\n }\r\n\r\n private void fillBuffer() throws IOException {\r\n bytesRead = din.read(buffer, bufferPointer = 0,\r\n BUFFER_SIZE);\r\n if (bytesRead == -1)\r\n buffer[0] = -1;\r\n }\r\n\r\n private byte read() throws IOException {\r\n if (bufferPointer == bytesRead)\r\n fillBuffer();\r\n return buffer[bufferPointer++];\r\n }\r\n\r\n public void close() throws IOException {\r\n if (din == null)\r\n return;\r\n din.close();\r\n }\r\n }\r\n\r\n public static long norm(long a, long MOD) {\r\n return ((a % MOD) + MOD) % MOD;\r\n }\r\n\r\n public static long msub(long a, long b, long MOD) {\r\n return norm(norm(a, MOD) - norm(b, MOD), MOD);\r\n\r\n }\r\n\r\n public static long madd(long a, long b, long MOD) {\r\n return norm(norm(a, MOD) + norm(b, MOD), MOD);\r\n\r\n }\r\n\r\n public static long mMul(long a, long b, long MOD) {\r\n return norm(norm(a, MOD) * norm(b, MOD), MOD);\r\n\r\n\r\n }\r\n\r\n public static long mDiv(long a, long b, long MOD) {\r\n return norm(norm(a, MOD) / norm(b, MOD), MOD);\r\n }\r\n\r\n public static String formattedArray(int a[]) {\r\n StringBuilder res = new StringBuilder(\"\");\r\n for (int e : a)\r\n res.append(e).append(\" \");\r\n return res.toString().trim();\r\n\r\n }\r\n\r\n private static void getInputs(Scanner s, int[] a, int n) throws IOException {\r\n for (int i = 0; i < n; i++) {\r\n a[i] = s.nextInt();\r\n }\r\n }\r\n}\r\n", "lang_cluster": "Java", "tags": ["math", "combinatorics", "bitmasks"], "code_uid": "8f95c09f2c5ec1c73109bf0d9b9b7535", "src_uid": "2e7a9f3a97938e4a7e036520d812b97a", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.lang.*;\nimport java.util.*;\n\npublic class Luckysubstring {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n String input = in.nextLine();\n int count4 = 0;\n int count7 = 0;\n in.close();\n if (input.contains(\"4\") || input.contains(\"7\")) {\n for (int i = 0; i < input.length(); i++) {\n if (input.charAt(i) == '4') {\n count4++;\n } else if (input.charAt(i) == '7') {\n count7++;\n }\n }\n if (count4 >= count7) {\n System.out.println(4);\n } else {\n System.out.println(7);\n }\n } else {\n System.out.println(-1);\n }\n\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "8d74bb2651d1a145ef41e02e6f589547", "src_uid": "639b8b8d0dc42df46b139f0aeb3a7a0a", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class johny {\n\tpublic static long gcd(long a, long b)\n\t{\n\t for (;;)\n\t {\n\t if (a == 0) return b;\n\t b %= a;\n\t if (b == 0) return a;\n\t a %= b;\n\t }\n\t}\n\tpublic static long lcm(long a, long b)\n\t{\n\t long temp = gcd(a, b);\n\n\t return temp!=0 ? (a / temp * b) :0;\n\t}\n\tpublic static void main(String args[]){\n\t\tScanner s= new Scanner(System.in);\n\t\tlong n=s.nextInt();\n\t\tlong a=s.nextInt();\n\t\tlong b=s.nextInt();\n\t\tlong p=s.nextInt();\n\t\tlong q=s.nextInt();\n\t\tlong cnt1=0,cnt2=0;\n\t\t/*for(int i=1;i<=n;i++){\n\t\t\tif(i%a==0 && i%b==0){\n\t\t\t\tif(p>q)\n\t\t\t\t\tcnt1++;\n\t\t\t\telse\n\t\t\t\t\tcnt2++;\n\t\t\t}\n\t\t\telse if(i%a==0)\n\t\t\t\tcnt1++;\n\t\t\telse if(i%b==0)\n\t\t\t\tcnt2++;\n\t\t}*/\n\t\tcnt1=n/a;\n\t\tcnt2=n/b;\n\t\tlong sum;\n\t\tlong cnt=n/lcm(a,b);\n\t\tif(p>q)\n\t\t sum=(cnt1*p)+(cnt2*q)-(cnt*q);\n\t\telse\n\t\t sum=(cnt1*p)+(cnt2*q)-(cnt*p);\n\t\tSystem.out.println(sum);\n\t\t\t\t\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation", "number theory"], "code_uid": "e9408e563ef3c67a34a29e0c115381b2", "src_uid": "35d8a9f0d5b5ab22929ec050b55ec769", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\n\npublic class Tetrahedron {\n\t\n\tprivate static final long MODULO = (long) Math.pow(10, 9) + 7;\n\t\n\t\n\t/*\n\t * T(n) = 3 * (T(n - 1) + (-1)^n)\n\t */\n\tpublic static long numPaths(int steps) {\n\t\tlong paths = 1;\n\t\tfor (int i = 1; i <= steps; i++) {\n\t\t\tpaths = (3*(paths + (int) Math.pow(-1, i))) % MODULO;\n\t\t\t//System.out.println(i + \": \" + paths);\n\t\t}\n\t\treturn paths;\n\t}\n\t\n\n\t\n\t/*\n\t * M(i, j) = M(i - 1, k) for all k s.t j != k\n\t * i.e. number of paths of length i ending at vertex j (A, B, C, or D)\n\t */\n\t/*\n\tpublic static long numPaths(int steps) {\n\t\tlong[] memo = new long[4]; //A = 0, B = 1, C = 2, D = 3\n\t\tfor (int i = 0; i < 4; i++) {\n\t\t\tmemo[i] = 0;\n\t\t}\n\t\tmemo[3] = 1; //start at vertex D\n\t\t\n\t\t//System.out.println(\"Steps: \" + 0 + \" A: \" + memo[0] + \" B: \" + memo[1] + \" C: \" + memo[2] + \" D: \" + memo[3] );\n\t\t\n\t\tfor (int i = 1; i <= steps; i++) {\n\t\t\tlong[] next = new long[4];\n\t\t\tfor (int j = 0; j < 4; j++) {\n\t\t\t\tfor (int k = 0; k < 4; k++) {\n\t\t\t\t\tif (k != j) {next[j] += memo[k];}\n\t\t\t\t\tnext[j] %= MODULO;\n\t\t\t\t}\n\t\t\t}\n\t\t\tmemo = next;\n\t\t\t//System.out.println(\"Steps: \" + i + \" A: \" + memo[0] + \" B: \" + memo[1] + \" C: \" + memo[2] + \" D: \" + memo[3]);\n\t\t}\n\t\t\n\t\treturn memo[3];\n\t}\n\t*/\n\t\n\t\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\t\n\t\tint steps = in.nextInt();\n\t\t\n\t\tSystem.out.println(numPaths(steps));\n\t\t\n\t\t\n\t\t\n\t}\n\t\n\t\n\t\n}\n", "lang_cluster": "Java", "tags": ["math", "matrices", "dp"], "code_uid": "3522193aecc9467e6a9611dc650f4b07", "src_uid": "77627cc366a22e38da412c3231ac91a8", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.math.BigDecimal;\nimport java.math.RoundingMode;\nimport java.util.LinkedList;\n\n// 10^6 ~ 2 sec\npublic class Main {\n\n public static void main(String[] args) throws Exception {\n BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n int n = Integer.parseInt(reader.readLine().trim());\n int lastSymbol = n - 1;\n String s = reader.readLine().trim();\n int res = 0;\n\n for (int start = 0; start <= lastSymbol; start++) {\n for (int end = start; end <= lastSymbol; end++) {\n int[] current = calculateDiff(s, start, end);\n if (current[0] == 0 && current[1] == 0) {\n res++;\n }\n }\n }\n System.out.println(res);\n reader.close();\n }\n\n private static int[] calculateDiff(String s, int start, int end) {\n int x = 0;\n int y = 0;\n for (int i = start; i <= end; i++) {\n char cmd = s.charAt(i);\n if (cmd == 'U') {\n y++;\n } else if (cmd == 'D') {\n y--;\n } else if (cmd == 'R') {\n x++;\n } else {\n x--;\n }\n }\n return new int[]{x, y};\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "8a212b9df21a55535de15f6630ffc36a", "src_uid": "7bd5521531950e2de9a7b0904353184d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Set;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n Task solver = new Task();\n solver.solve(1, in, out);\n out.close();\n }\n}\n\nclass Task {\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int k = in.nextInt();\n int a = in.nextInt();\n int b = in.nextInt();\n int v = in.nextInt();\n int ans = 0;\n while (a > 0) {\n int s = 1;\n if (b > k - 1) {\n b -= k - 1;\n s = k;\n } else {\n s = b + 1;\n b = 0;\n }\n a -= s * v;\n ans++;\n }\n out.print(ans);\n }\n}\n\nclass InputReader {\n\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream){\n reader = new BufferedReader(new InputStreamReader(stream));\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "greedy"], "code_uid": "d9ff667c95c72cbb91a3637cf148a3c6", "src_uid": "7cff20b1c63a694baca69bdf4bdb2652", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class DeclinedFinalists {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int n = scan.nextInt();\n int[] arr = new int[n];\n for (int i = 0; i < arr.length; i++) {\n arr[i] = scan.nextInt();\n }\n Arrays.sort(arr);\n if (arr[arr.length - 1] <= 25) {\n System.out.println(0);\n } else {\n System.out.println(arr[arr.length - 1] - 25);\n }\n\n }\n}\n", "lang_cluster": "Java", "tags": ["greedy", "implementation"], "code_uid": "6cdfea226df1308567d6658145feadc9", "src_uid": "ef657588b4f2fe8b2ff5f8edc0ab8afd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.Scanner;\n\npublic class Main {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n //int t = sc.nextInt();\n long [] fact = new long[1002];\n long M = 1000000007;\n //while (t-- != 0) {\n int n = sc.nextInt(), x = sc.nextInt(), pos = sc.nextInt();\n fact[0]=1;\n for (int i=1;i<=n;i++){\n fact[i] = (fact[i-1]*(i))%M;\n }\n int f=0,l=n,less=x-1,more=n-x,total = n;\n long value=1;\n while(f0){value=(value*fact[total])%M;}\n System.out.println(value);\n //}\n }\n}", "lang_cluster": "Java", "tags": ["binary search", "combinatorics"], "code_uid": "9de25c532a1c99dec8b12ad0973b27cf", "src_uid": "24e2f10463f440affccc2755f4462d8a", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Solution{\n public static void main(String[] args){\n Scanner sc=new Scanner(System.in);\n int t=5;\n String[] arr=new String[t];\n String my=sc.next();\n for(int i=0;i s1 = new HashSet<>();\n HashSet s2 = new HashSet<>();\n int total = 0;\n for (int i = 0; i < r; i++) {\n for (int j = 0; j < c; j++) {\n if (a[i][j] == 'S') {\n s1.add(i);\n s2.add(j);\n }\n\n }\n }\n out.println(r * c - s1.size() * s2.size());\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public String nextString() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n if (Character.isValidCodePoint(c)) {\n res.appendCodePoint(c);\n }\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public String next() {\n return nextString();\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void println(int i) {\n writer.println(i);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "9c97b94a8d4deb0a7f39d5423e827e62", "src_uid": "ebaf7d89c623d006a6f1ffd025892102", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.awt.*;\n\npublic class C {\n\n\tstatic final int N = 6;\n\tstatic final double SQRT = Math.sqrt(3) / 4.0;\n\tstatic final double PI_3 = Math.PI / 3.0;\n\n\tstatic class Pair {\n\t\tdouble x, y;\n\t\tpublic Pair(double x, double y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\t}\n\n\tpublic static void main(String [] args) throws IOException {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint [] len = new int[N];\n\t\tfor(int i = 0; i < N; i++) {\n\t\t\tlen[i] = sc.nextInt();\n\t\t}\n\n\t\tPair [] coords = new Pair[N];\n\t\tcoords[0] = new Pair(0, 0);\n\t\tcoords[1] = new Pair(len[0], 0);\n\n\t\tdouble angle = 0;\n\n\t\t// calculate coordinates of figure\n\t\tfor(int i = 2; i < N; i++) {\n\t\t\tdouble x1 = coords[i - 2].x;\n\t\t\tdouble y1 = coords[i - 2].y;\n\t\t\tdouble x2 = coords[i - 1].x;\n\t\t\tdouble y2 = coords[i - 1].y;\n\n\t\t\tangle += PI_3;\n\n\t\t\tdouble x3 = x2 + (double)len[i - 1] * Math.cos(angle);\n\t\t\tdouble y3 = y2 + (double)len[i - 1] * Math.sin(angle);\n\n\t\t\tcoords[i] = new Pair(x3, y3);\n\t\t}\n\n\t\t// calculate square\n\t\tdouble s = 0;\n\t\tPair a = coords[0];\n\t\tfor(int i = 2; i < N; i++) {\n\t\t\tPair b = coords[i - 1];\n\t\t\tPair c = coords[i];\n\t\t\tdouble x1 = c.x - a.x;\n\t\t\tdouble y1 = c.y - a.y;\n\n\t\t\tdouble x2 = c.x - b.x;\n\t\t\tdouble y2 = c.y - b.y;\n\n\t\t\ts += x1 * y2 - x2 * y1;\n\t\t}\n\n\t\ts /= 2.0;\n\n\t\tint count = (int)(Math.round(s / SQRT));\n\t\tSystem.out.println(count);\n\t}\n\n\tstatic double round(double a) {\n\t\treturn Math.floor(a * 10000.0)/10000.0;\n\t}\n}", "lang_cluster": "Java", "tags": ["geometry"], "code_uid": "31fee321ae1f0f2947740f23c3ba87fa", "src_uid": "382475475427f0e76c6b4ac6e7a02e21", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Scanner;\n\npublic class RemoveDuplicates {\n\n\tpublic static void main(String[] args) \n\t{\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n = scan.nextInt();\n\t\tArrayList x = new ArrayList();\n\t\tArrayList y = new ArrayList();\n\t\tfor(int i=0;i=0;i--)\n\t\t{\n\t\t\tif(!y.contains(x.get(i)))y.add(x.get(i));\n\t\t}\n\t\tCollections.reverse(y);\n\t\tSystem.out.println(y.size());\n\t\tfor(int i=0;i= 0; i++) {\n if (s.charAt(i) == 'T') {\n dir = dir * -1;\n } else {\n res += dir;\n }\n }\n return Math.abs(res);\n }\n if (dp[idx][rem][dir + 1][cur+s.length()+1] != -1)\n return dp[idx][rem][dir + 1][cur+s.length()+1];\n int max = 0;\n int i=0;\n if(idx==s.length()-1) i=rem;\n for (; i <= rem; i++) {\n if (s.charAt(idx) == 'F') {\n if (i % 2 == 0) {\n max = Math.max(max, solve(idx + 1, rem - i, dir,cur+dir));\n } else {\n max = Math.max(max, solve(idx + 1, rem - i, dir * -1,cur));\n }\n } else {\n if (i % 2 == 0) {\n max = Math.max(max,solve(idx + 1, rem - i, dir * -1,cur));\n } else {\n max = Math.max(max,solve(idx + 1, rem - i, dir,cur+dir));\n }\n }\n }\n return dp[idx][rem][dir + 1][cur+s.length()+1] = max;\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n s = sc.next();\n int n = sc.nextInt();\n dp = new int[s.length()][n + 1][3][2*s.length()+1];\n for (int i = 0; i < s.length(); i++) {\n for (int j = 0; j <= n; j++)\n for(int k=0;k<3;k++)\n Arrays.fill(dp[i][j][k], -1);\n }\n System.out.println(Math.abs(solve(0, n, 1,0)));\n }\n}\n", "lang_cluster": "Java", "tags": ["dp"], "code_uid": "cf5d6633fdb833db7d9c0cf6b463ac24", "src_uid": "4a54971eb22e62b1d9e6b72f05ae361d", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner; \n\npublic class Main {\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n \n short n; \n byte k;\n byte [] data;\n int total = 0;\n short count = 0; \n \n n = input.nextShort();\n k = input.nextByte();\n data = new byte[n];\n for (int i = 0; i < n; i++) {\n data [i] = input.nextByte();\n total = (total + data[i]);\n } \n \n while((Math.round((double)total / n)) < (k - 0.5)){\n total = (total + k);\n n++;\n count++; \n }\n \n System.out.println(count);\n \n \n }\n}", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "ddd7c68f5aa2eefa0b98a3a2f58415cd", "src_uid": "f22267bf3fad0bf342ecf4c27ad3a900", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tBufferedReader br = new BufferedReader( new InputStreamReader(System.in),8*1024);\n\t\tScanner sc = new Scanner(br);\n\n\t\tlong a , b ; \n\t\ta = sc.nextLong();\n\t\tb = sc.nextLong();\n\t\t\n\t\tlong lcm = (a*b)/gcd(a,b);\n\t\tlong timea = 0;\n\t\tlong timeb = 0 ; \n\t\t\n\t\tboolean needSwap = false; \n\t\t\n\t\tif( a > b ){\n\t\t\tneedSwap = true ;\n\t\t\tlong temp = a ; \n\t\t\ta = b;\n\t\t\tb = temp ; \n\t\t}\n\t\t\n\t\tfor( long i = b ; i <= lcm ; i += b )\n\t\t{\n\t\t\t\n\t\t\ttimeb += i - (((i-1)/a) * a) ; \n\t\t\t\n\t\t}\n\t\t\n\t\ttimea = lcm - timeb;\n\t\t\n\t\tif( timea > timeb )\n\t\t{\n\t\t\tif( !needSwap )\n\t\t\tSystem.out.println( \"Dasha\");\n\t\t\t\n\t\t\telse\n\t\t\t\tSystem.out.println(\"Masha\");\n\t\t}\n\t\t\n\t\telse if( timea < timeb)\n\t\t{\t\n\t\t\tif( !needSwap)\n\t\t\tSystem.out.println(\"Masha\");\n\t\t\t\n\t\t\telse\n\t\t\t\tSystem.out.println( \"Dasha\");\n\t\t\n\t\t}\n\t\t\n\t\telse \n\t\t\tSystem.out.println(\"Equal\");\n\t\t\n\t}\n\n\n\t\n\tstatic long gcd(long a , long b )\n\t{\n\t\tif( a == 0 ) return b ; \n\t\tif( b == 0 ) return a ; \n\t\t\n\t\tif( a > b ) return gcd(b,a%b);\n\t\telse return gcd(a,b%a);\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "6ae042f867b44479dde0f6a59f4c21f1", "src_uid": "06eb66df61ff5d61d678bbb3bb6553cc", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\npublic class Binario {\n\n public static void main(String[] args) {\n Scanner sca = new Scanner(System.in);\n\n long a = sca.nextLong();\n long b = sca.nextLong();\n if (b < a) {\n System.out.println(0);\n } else \n {\n \n long pivote = 2L;\n int niveles = 0, base, totales = 0;\n while (pivote <= a)\n {\n pivote = (pivote * 2) + 1;\n niveles++;\n }\n pivote = (pivote - 1) / 2;\n\n if (pivote == a)\n {\n totales++;\n }\n base = niveles - 2;\n while (base >= 0 && pivote <= b) \n {\n pivote = pivote + (long) (Math.pow(2, base));\n base--;\n if (pivote >= a && pivote <= b) \n {\n totales++;\n }\n }\n long pivote2 = 2;\n int niveles2 = 0, cont2 = 0;\n while (pivote2 <= b) \n {\n pivote2 = (pivote2 * 2) + 1;\n niveles2++;\n }\n pivote2 = (pivote2 - 1) / 2;\n base = niveles2 - 2;\n\n if (niveles2 > niveles) {\n if (pivote2 <= b) {\n cont2++;\n }\n\n while (pivote2 <= b && base >= 0) {\n pivote2 = pivote2 + (long) Math.pow(2, base);\n base--;\n if (pivote2 <= b) {\n\n cont2++;\n }\n }\n }\n if (a==0) {\n totales--;\n }\n System.out.println(totales + cont2 + contadorFilas(niveles, niveles2));\n\n }\n }\n\n static int contadorFilas(int nivelA, int nivelB) {\n int acu = 0;\n for (int i = nivelA; i < nivelB - 1; i++) {\n acu += ++nivelA;\n }\n return acu;\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "implementation", "bitmasks"], "code_uid": "0af50f8e0fd48fce9a6a442c7db11129", "src_uid": "581f61b1f50313bf4c75833cefd4d022", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main {\n\n\tstatic class Point {\n\t\tlong x, y;\n\t\t\n\t\tpublic boolean equals(Point b) {\n\t\t\treturn x==b.x && y==b.y;\n\t\t}\n\n\t\tpublic Point(Scanner in) {\n\t\t\tthis.x = in.nextLong();\n\t\t\tthis.y = in.nextLong();\n\t\t}\n\t\t\n\t\tpublic Point(Point p,int z) {\n\t\t\tif(z==0) {\n\t\t\t\tthis.x = p.x-1;\n\t\t\t\tthis.y = p.y;\n\t\t\t} else if(z==1) {\n\t\t\t\tthis.x = p.x+1;\n\t\t\t\tthis.y = p.y;\n\t\t\t} else if(z==2) {\n\t\t\t\tthis.x = p.x;\n\t\t\t\tthis.y = p.y-1;\n\t\t\t} else if(z==3) {\n\t\t\t\tthis.x = p.x;\n\t\t\t\tthis.y = p.y+1;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static long dot(Point a, Point b, Point c) {\n\t\tlong ans = (b.x - a.x) * (c.x - a.x) + (b.y - a.y) * (c.y - a.y);\n\t\tif(a.equals(b) || a.equals(c) || b.equals(c)) {\n\t\t\treturn 1L;\n\t\t}\n\t\treturn ans;\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tPoint a = new Point(in);\n\t\tPoint b = new Point(in);\n\t\tPoint c = new Point(in);\n\t\tif(check(a,b,c)) {\n\t\t\tSystem.out.println(\"RIGHT\");\n\t\t\treturn;\n\t\t}\n\t\tif(check(new Point(a,0),b,c) || check(new Point(a,1),b,c) || check(new Point(a,2),b,c) || check(new Point(a,3),b,c) \n\t\t\t\t|| check(new Point(b,0),a,c) || check(new Point(b,1),a,c) || check(new Point(b,2),a,c) || check(new Point(b,3),a,c)\n\t\t\t\t|| check(new Point(c,0),b,a) || check(new Point(c,1),b,a) || check(new Point(c,2),b,a) || check(new Point(c,3),b,a)) {\n\t\t\tSystem.out.println(\"ALMOST\");\n\t\t\treturn;\n\t\t}\n\t\tSystem.out.println(\"NEITHER\");\n\t}\n\t\n\tpublic static boolean check(Point a,Point b,Point c) {\n\t\treturn dot(a,b,c)==0L || dot(b,a,c)==0L || dot(c,a,b)==0L;\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["brute force", "geometry"], "code_uid": "16b97fbae02b7bb085162d12b42f5535", "src_uid": "8324fa542297c21bda1a4aed0bd45a2d", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "\t\t\t\t\nimport java.util.*;import java.io.*;import java.math.*;\n\npublic class Main\n{\n\n public static void process()throws IOException\n {\n \tint w=ni(),h=ni(),k=ni();\n\n \tlong res=0l;\n \tint i=1;\n \twhile(k-- > 0){\n \t\tint tw=w-(4*(i-1)),th=h-(4*(i-1));\n \t\t//pn(tw+\" \"+th);\n \t\tres+=2*tw+(2*(th-2));\n \t\ti++;\n \t}\n \tpn(res);\n }\n\n\n \tstatic AnotherReader sc;\n static PrintWriter out;\n public static void main(String[]args)throws IOException\n {\n out = new PrintWriter(System.out);\n sc=new AnotherReader();\n boolean oj = true;\n\n \toj = System.getProperty(\"ONLINE_JUDGE\") != null;\n \tif(!oj) sc=new AnotherReader(100);\n\n long s = System.currentTimeMillis();\n int t=1;\n while(t-->0)\n process();\n out.flush();\n if(!oj)\n System.out.println(System.currentTimeMillis()-s+\"ms\");\n System.out.close(); \n }\n\n static void pn(Object o){out.println(o);}\n static void p(Object o){out.print(o);}\n static void pni(Object o){out.println(o);System.out.flush();}\n static int ni()throws IOException{return sc.nextInt();}\n static long nl()throws IOException{return sc.nextLong();}\n static double nd()throws IOException{return sc.nextDouble();}\n static String nln()throws IOException{return sc.nextLine();}\n static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}\n static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}\n static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}\n static boolean multipleTC=false;\n\n\n\n/////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n static class AnotherReader{BufferedReader br; StringTokenizer st;\n AnotherReader()throws FileNotFoundException{\n br=new BufferedReader(new InputStreamReader(System.in));}\n AnotherReader(int a)throws FileNotFoundException{\n br = new BufferedReader(new FileReader(\"input.txt\"));}\n String next()throws IOException{\n while (st == null || !st.hasMoreElements()) {try{\n st = new StringTokenizer(br.readLine());}\n catch (IOException e){ e.printStackTrace(); }}\n return st.nextToken(); } int nextInt() throws IOException{\n return Integer.parseInt(next());}\n long nextLong() throws IOException\n {return Long.parseLong(next());}\n double nextDouble()throws IOException { return Double.parseDouble(next()); }\n String nextLine() throws IOException{ String str = \"\"; try{\n str = br.readLine();} catch (IOException e){\n e.printStackTrace();} return str;}}\n \n/////////////////////////////////////////////////////////////////////////////////////////////////////////////\n}\n\t\n\t\n\t", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "052996025a440b8b8da9fdb20db0b2f5", "src_uid": "2c98d59917337cb321d76f72a1b3c057", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n static BufferedReader br ;\n public static void main(String[] args) throws Exception {\n br = new BufferedReader(new InputStreamReader(System.in));\n int test = cinI();\n String x = cin();\n int[] arr = new int[3];\n for(int i=0;i2){\n cout(\"BG\");\n System.exit(0);\n\n }\n if(arr[0]==0 && arr[1]==1 && arr[2]>2){\n cout(\"BG\");\n System.exit(0);\n\n }\n if(arr[0]==1 && arr[1]>=2 && arr[2]==0){\n cout(\"BR\");\n System.exit(0);\n\n }\n if(arr[0]==0 && arr[1]>=2 && arr[2]==1){\n cout(\"BR\");\n System.exit(0);\n\n }\n if(arr[0]>=2 && arr[1]==0 && arr[2]==1){\n cout(\"GR\");\n System.exit(0);\n\n }\n if(arr[0]>=2 && arr[1]==1 && arr[2]==0){\n cout(\"GR\");\n System.exit(0);\n\n }\n cout(\"BGR\");\n\n\n }\n\n\n\n\n\n static double findRoots(int a, int b, int c)\n {\n // If a is 0, then equation is not\n //quadratic, but linear\n\n\n\n int d = b*b - 4*a*c;\n double sqrt_val = Math.sqrt(Math.abs(d));\n\n\n // System.out.println(\"Roots are real and different \\n\");\n\n return Math.max((double)(-b + sqrt_val) / (2 * a) ,\n (double)(-b - sqrt_val) / (2 * a));\n\n\n }\n\n public static String cin() throws Exception {\n return br.readLine();\n }\n\n public static String[] cinA() throws Exception {\n return br.readLine().split(\" \");\n }\n\n\n public static String ToString(Long x) {\n return Long.toBinaryString(x);\n }\n\n public static void cout(String s) {\n System.out.println(s);\n }\n public static Integer cinI() throws Exception {\n return Integer.parseInt(br.readLine());\n }\n public static int getI(String s) throws Exception {\n return Integer.parseInt(s);\n }\n public static long getL(String s) throws Exception {\n return Long.parseLong(s);\n }\n public static int max(int a, int b) {\n return Math.max(a, b);\n }\n public static void coutI(int x){\n System.out.println(String.valueOf(x));\n }\n public static void coutI(long x){\n System.out.println(String.valueOf(x));\n }\n public static Long cinL() throws Exception {\n return Long.parseLong(br.readLine());\n }\n public static void arrInit(String[] arr,int[] arr1) throws Exception {\n for(int i=0;i{\n\n\n @Override\n public int compare(range range, range t1) {\n if(range.diff!=t1.diff)\n return t1.diff-range.diff;\n return range.l-t1.l;\n }\n}", "lang_cluster": "Java", "tags": ["math", "dp", "constructive algorithms"], "code_uid": "d0f6de889bd6fbc9fa45d38b0125100e", "src_uid": "4cedd3b70d793bc8ed4a93fc5a827f8f", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\n\npublic class Solution {\n\n static Scanner sc = new Scanner(System.in);\n\n public static void main(String[] args) {\n StringBuilder res = new StringBuilder();\n char[] s = sc.next().toCharArray();\n for (int i = 0; i < s.length / 2; i++) {\n if (s.length % 2 == 0)\n res.append(s[s.length - i - 1]).append(s[i]);\n else\n res.append(s[i]).append(s[s.length - i - 1]);\n }\n if (s.length % 2 != 0) {\n res.append(s[s.length / 2]);\n }\n System.out.println(res.reverse().toString());\n }\n}", "lang_cluster": "Java", "tags": ["strings", "implementation"], "code_uid": "75a1c01f98e40f5f546eaf25f5848cf6", "src_uid": "992ae43e66f1808f19c86b1def1f6b41", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.StringTokenizer;\n\npublic class Solution675A {\n public static void main(String... bob) throws Exception {\n FAST in = new FAST();\n WriteMe out = new WriteMe();\n long A = in.nextLong(), B = in.nextLong(), C = in.nextLong();\n if (C == 0) {\n System.out.println(A == B ? \"YES\" : \"NO\");\n } else {\n if (C > 0 && B >= A || C < 0 && B <= A) {\n System.out.println(((B - A) % C == 0) ? \"YES\" : \"NO\");\n } else {\n System.out.println(\"NO\");\n }\n }\n\n out.close();\n }\n\n static class WriteMe {\n private PrintWriter out;\n\n public WriteMe() {\n try {\n out = new PrintWriter(new BufferedWriter(new FileWriter(\"Solution675A.out\")));\n } catch (Exception e) {\n\n }\n }\n\n public void caseInt(int num, int ans) {\n caseStr(num, String.valueOf(ans));\n }\n\n public void caseStr(int num, String ans) {\n out.printf(\"Case #%d: %s\\n\", num, ans);\n }\n\n public void writeln(String str) {\n out.println(str);\n }\n\n public void write(String str) {\n out.print(str);\n }\n\n public void close() {\n out.close();\n }\n }\n\n static class FAST {\n private BufferedReader in;\n private StringTokenizer str;\n\n public FAST() {\n in = new BufferedReader(new InputStreamReader(System.in));\n // in = new BufferedReader(new FileReader(\"Solution675A.in\"));\n }\n\n private String next() {\n while (str == null || !str.hasMoreElements()) {\n try {\n str = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n }\n }\n return str.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public String nextLine() throws Exception {\n return in.readLine();\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "c54150c7d21d73581a55487d73421737", "src_uid": "9edf42c20ddf22a251b84553d7305a7d", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class rq2\n{\n public static void main(String args[])throws IOException\n {\n Scanner in=new Scanner(System.in);\n int n,a,b;\n n=in.nextInt();\n a=in.nextInt();\n b=in.nextInt();\n /*int min=Math.min(a,b);\n int div=n/2;\n if(n%2==1)\n div+=1;\n \t int ans=min/div;\n \t if(ans==0)\n \t \tans+=1;\n \t if(a+b==n)\n \t \tSystem.out.println(1);\n \t else\n System.out.println(ans); */\n int ans=10000000;\n int aa=0;\n for(int i=1;iaa)\n \taa=ans;\n }\n System.out.println(aa); \n }\n} ", "lang_cluster": "Java", "tags": ["brute force", "implementation", "binary search"], "code_uid": "85680ed2997b741466d8d5195f7651a9", "src_uid": "a254b1e3451c507cf7ce3e2496b3d69e", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.*;\n\npublic class Temp {\n public static void main(String args[]){\n Scanner in = new Scanner(System.in);\n String s=in.next(), t=in.next();\n if (s.length()!=t.length())\n System.out.print(\"NO\");\n else{\n for (int i=0; i ans= new TreeSet();\n\t\tfor(int a=0; a<=64; a++){\n\t\t\tfor(int b=0;b<=64;b++){\n\t\t\t\tBigInteger res= BigInteger.ZERO;\n\t\t\t\tres= res.add(x.pow(a));\n\t\t\t\tres= res.add(y.pow(b));\n\t\t\t\tif(res.compareTo(l)>=0&&res.compareTo(r)<=0){\n\t\t\t\t\tans.add(Long.valueOf(res.toString()));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tArrayList use= new ArrayList();\n\t\tfor(Long aa: ans){\n\t\t\tuse.add(aa);\n\t\t}\n\t\tlong left= Long.valueOf(l.toString());\n\t\tlong right= Long.valueOf(r.toString());\n\t\tlong best=0;\n\t\tif(use.size()==0){\n\t\t\tSystem.out.println(right-left+1);\n\t\t\treturn;\n\t\t}\n\t\tlong prev= use.get(0);\n\t\tfor (int i = 1; i < ans.size(); i++) {\n\t\t\tbest= Math.max(use.get(i)-prev-1, best);\n\t\t\tprev= use.get(i);\n\t\t}\n\t\tbest= Math.max(use.get(0)-left, best);\n\t\tbest= Math.max(right-use.get(use.size()-1), best);\n\t\tSystem.out.println(best);\n\t\t\n\t\t\n\t\t\n\t\t\n\t}\n\tstatic class FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner(InputStream in) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(in));\n\t\t\tst = new StringTokenizer(\"\");\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\tif (!st.hasMoreTokens()) {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\treturn next();\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tpublic double nextDouble() throws NumberFormatException, IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\tpublic long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "tags": ["brute force", "math"], "code_uid": "530e7d7b1554731f721da5e15a8bd9b7", "src_uid": "68ca8a8730db27ac2230f9fe9b120f5f", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n\tString[] s = { \"Washington\", \"Adams\", \"Jefferson\", \"Madison\",\n\t\t\t\"Monroe (1817-1825)\", \"Quincy Adams (1825-1829)\",\n\t\t\t\"Jackson (1829-1837)\", \"Van Buren\", \"Harrison (1841)\",\n\t\t\t\"Tyler (1841-1845)\", \"Polk (1841-1849)\", \"Taylor (1849-1850)\",\n\t\t\t\"Fillmore (1850-1853)\", \"Pierce (1853-1857)\",\n\t\t\t\"Buchanan (1857-1861)\", \"Lincoln (1861-1865)\",\n\t\t\t\"Johnson (1865-1869)\", \"Grant (1869-1877)\", \"Hayes (1877-1881)\",\n\t\t\t\"Garfield (1881)\", \"Arthur (1881-1885)\", \"Cleveland (1885-1889)\",\n\t\t\t\"Harrison (1889-1893)\", \"Cleveland (1893-1897)\",\n\t\t\t\"McKinley (1897-1901)\", \"Roosevelt (1901-1909)\",\n\t\t\t\"Taft (1909-1913)\", \"Wilson (1913-1921)\", \"Harding (1921-1923)\",\n\t\t\t\"Coolidge (1923-1929)\", \"Hoover (1929-1933)\",\n\t\t\t\"Roosevelt (1933-1945)\", \"Truman (1945-1953)\",\n\t\t\t\"Eisenhower (1953-1961)\", \"Kennedy (1961-1963)\",\n\t\t\t\"Johnson (1963-1969)\", \"Nixon (1969-1974)\", \"Ford (1974-1977)\",\n\t\t\t\"Carter (1977-1981)\", \"Reagan (1981-1989)\", \"Bush (1989-1993)\",\n\t\t\t\"Clinton (1993-2001)\", \"Bush (2001-2009)\", \"Obama\" };\n\n\tvoid solve() throws IOException {\n\t\tint n = nextInt() - 1;\n\t\tif (n == 5) {\n\t\t\tout.println(\"Adams\");\n\t\t\treturn;\n\t\t}\n\t\tif (n == 8) {\n\t\t\tout.println(\"Harrison\");\n\t\t\treturn;\n\t\t}\n\t\tif (n == 7) {\n\t\t\tout.println(\"Van Buren\");\n\t\t\treturn;\n\t\t}\n\t\tout.println(new StringTokenizer(s[n]).nextToken());\n\n\t}\n\n\tvoid run() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew A().run();\n\t}\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer str;\n\n\tString next() throws IOException {\n\t\twhile (str == null || !str.hasMoreTokens()) {\n\t\t\tstr = new StringTokenizer(br.readLine());\n\t\t}\n\t\treturn str.nextToken();\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(next());\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "87d997d1826e37fda9d22e523346301e", "src_uid": "0b51a8318c9ec0c80c0f4dc04fe0bfb3", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Zyflair Griffane\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tPandaScanner in = new PandaScanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tH solver = new H();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass H {\n public void solve(int testNumber, PandaScanner in, PrintWriter out) {\n char[] number = in.next().toCharArray();\n long[][] ways = new long[number.length][19];\n for (int i = 0; i < 19; i++) {\n ways[number.length - 1][i] = (i % 2) + 1;\n }\n for (int i = number.length - 2; i >= 0; i--) {\n int curr = number[i + 1] - '0';\n for (int j = 0; j < 19; j++) {\n int k = j / 2;\n ways[i][j] = ways[i + 1][k + curr];\n if (j % 2 == 1) {\n ways[i][j] += ways[i + 1][k + curr + 1];\n }\n }\n }\n long res = 0;\n if (number.length == 1) {\n res = 9;\n }\n else {\n for (int i = 0; i <= 9; i++) {\n res += ways[1][i + number[1] - '0'];\n }\n if (mustCutOneBecauseRawr(number)) {\n res--;\n }\n }\n out.println(res);\n }\n public boolean mustCutOneBecauseRawr(char[] number) {\n for (int i = 0; i < number.length - 1; i++) {\n if (Math.abs(number[i] - number[i + 1]) > 1) {\n return false;\n }\n }\n return true;\n }\n}\n\nclass PandaScanner {\n public BufferedReader br;\n public StringTokenizer st;\n public InputStream in;\n\n public PandaScanner(InputStream in) {\n br = new BufferedReader(new InputStreamReader(this.in = in));\n }\n\n public String nextLine() {\n try {\n return br.readLine();\n }\n catch (Exception e) {\n return null;\n }\n }\n\n public String next() {\n if (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(nextLine().trim());\n return next();\n }\n return st.nextToken();\n }\n\n }\n\n", "lang_cluster": "Java", "tags": ["dp"], "code_uid": "4ee00e3fb359539d2594f4b147c1e2a0", "src_uid": "2dd8bb6e8182278d037aa3a59ca3517b", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class Main{\n public static void main(String[]args){\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n ArrayList list=new ArrayList();\n list.add(n);\n for(int i=n/2;i>=1;i--)\n { \n if(n%i==0)\n {\n list.add(i);\n n=i;\n }\n \n \n }\n for(Integer j:list)\n {\n System.out.print(j+\" \");\n }\n }\n}", "lang_cluster": "Java", "tags": ["greedy"], "code_uid": "91b73c772baf84345c1accb81012a80d", "src_uid": "2fc946bb72f56b6d86eabfaf60f9fa63", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.*;\npublic class Main {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int N = in.nextInt();\n int T = in.nextInt();\n char[] people = in.next().toCharArray();\n for (int i=0; i sum) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(\"NO\");\n\t}\n}", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "69bd2ba62865043a54b18d0ec08a154e", "src_uid": "410296a01b97a0a39b6683569c84d56c", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.DataInputStream; \nimport java.io.FileInputStream; \nimport java.io.IOException; \nimport java.io.InputStreamReader; \nimport java.util.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\n\npublic class JavaApplication9 { \n \n \n//*************************************************************************************** \n static class Reader \n { \n final private int BUFFER_SIZE = 1 << 16; \n private DataInputStream din; \n private byte[] buffer; \n private int bufferPointer, bytesRead; \n \n public Reader() \n { \n din = new DataInputStream(System.in); \n buffer = new byte[BUFFER_SIZE]; \n bufferPointer = bytesRead = 0; \n } \n \n public Reader(String file_name) throws IOException \n { \n din = new DataInputStream(new FileInputStream(file_name)); \n buffer = new byte[BUFFER_SIZE]; \n bufferPointer = bytesRead = 0; \n } \n \n public String readLine() throws IOException \n { \n byte[] buf = new byte[64]; // line length \n int cnt = 0, c; \n while ((c = read()) != -1) \n { \n if (c == '\\n') \n break; \n buf[cnt++] = (byte) c; \n } \n return new String(buf, 0, cnt); \n } \n \n public int nextInt() throws IOException \n { \n int ret = 0; \n byte c = read(); \n while (c <= ' ') \n c = read(); \n boolean neg = (c == '-'); \n if (neg) \n c = read(); \n do\n { \n ret = ret * 10 + c - '0'; \n } while ((c = read()) >= '0' && c <= '9'); \n \n if (neg) \n return -ret; \n return ret; \n } \n \n public long nextLong() throws IOException \n { \n long ret = 0; \n byte c = read(); \n while (c <= ' ') \n c = read(); \n boolean neg = (c == '-'); \n if (neg) \n c = read(); \n do { \n ret = ret * 10 + c - '0'; \n } \n while ((c = read()) >= '0' && c <= '9'); \n if (neg) \n return -ret; \n return ret; \n } \n \n public double nextDouble() throws IOException \n { \n double ret = 0, div = 1; \n byte c = read(); \n while (c <= ' ') \n c = read(); \n boolean neg = (c == '-'); \n if (neg) \n c = read(); \n \n do { \n ret = ret * 10 + c - '0'; \n } \n while ((c = read()) >= '0' && c <= '9'); \n \n if (c == '.') \n { \n while ((c = read()) >= '0' && c <= '9') \n { \n ret += (c - '0') / (div *= 10); \n } \n } \n \n if (neg) \n return -ret; \n return ret; \n } \n \n private void fillBuffer() throws IOException \n { \n bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); \n if (bytesRead == -1) \n buffer[0] = -1; \n } \n \n private byte read() throws IOException \n { \n if (bufferPointer == bytesRead) \n fillBuffer(); \n return buffer[bufferPointer++]; \n } \n \n public void close() throws IOException \n { \n if (din == null) \n return; \n din.close(); \n } \n }\n//**************************************************************************************** \n/*static boolean isp(long n)\n{\n\n if(n==3||n==2)\n return true;\n if(n%2==0||n%3==0||n==1)\n return false;\n for(int i=5;i*i<=n;i=i+6)\n {\n if(n%i==0||n%(i+2)==0)\n return false;\n }\n return true;\n} */\n//******************************************************** \n /* static int factorial(int n) \n { \n if (n == 0) \n return 1; \n \n return n*factorial(n-1); \n } */ \npublic static void main(String[] args) throws IOException{\n\nReader st=new Reader();\nint n=st.nextInt(),a=st.nextInt(),b=st.nextInt(),c=st.nextInt();int min,r; int cr[]=new int[3];cr[0]=a;cr[1]=b;cr[2]=c;\nfor(int j=0;j<2;j++){min=j;for(int i=j+1;i<3;i++){if(cr[i]0)\n {\n m=q*a;\n x=n-m;\n if(x%b==0){B=true; break;} \n else\n q--;\n \n }int cc6=0;\n if(B)\n {\n cc6=q+(x/b);\n }\n int cc5=0;\n if(n%b==0)cc5=n/b;\n \n //*************************************************************************************\n { int cc1=0;\n q=n/a;\n while(q>0){m=q*a;x=n-m; if(x%c==0){C=true; break;} else q--;} //by+cz \n if(C){cc1=q+(x/c);}\n //***********************************************\n q=n/b;C=false; int cc2=0;\n while(q>0){m=q*b;x=n-m; if(x%c==0){C=true; break;} else q--;} //ax+cz\n if(C){cc2=q+(x/c);}\n //*****************************\n int cc3=0;\n if(n%c==0){cc3=n/c;} //cz\n //****************************\n int maxb=n/b,maxc=n/c,coa=0,cob=0,coc=0,cc4=0; \n double s,xx;\n //for(int t=b+c;t<((maxb*b)+(maxc*c));t++) //ax+by+cz\n int h=b+c;\n if(h>n)h=n;\n while(h<=((maxb*b)+(maxc*c)))\n {\n \n s=n-h;\n \n xx=s/a; //coa\n if(xx%a==0||a%xx==0){coa=(int)xx;break;}h++;\n }\n //**********************************************************\n int maxa=n/a; \n int t=((maxb*b)+(maxa*a));\n if(t>n){t=n;}\n while(t>=b+a) //coc\n {\n \n s=n-t;\n if(s>=c){\n xx=s/c;\n if(xx%c==0||c%xx==0){coc=(int)xx;break;}}\n t--;\n }\n //**********************************************************\n \n cob=(n-(coa*a+coc*c))/b; //cob\n //*****************************************************\n \n if(coc>0&coa>0&&coa*a+cob*b+coc*c==n){\n cc4=coa+cob+coc;}\n else\n {\n while(coa*a+cob*b+coc*c!=n&cob>0&coc<=maxc){coc++;cob--;}\n }\n if(coc>0&coa>0&&coa*a+cob*b+coc*c==n) cc4=coa+cob+coc;else cc4=0;\n int yy=cc1;\n if(yy n - 1 || k * 2 > m - 1) \n System.out.println(\"0\"); \n else {\n long c[][] = new long [1001][1001];\n c[0][0] = 1;\n for (int i = 1; i <= Math.max(n - 1, m - 1); ++i) { \n\t c[i][0] = 1;\n\t for (int j = 1; j <= i; ++j)\n\t c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;\n\t\t\t}\n\t System.out.println((c[n - 1][2 * k] * c[m - 1][2 * k]) % mod); \n }\n\t}\n}\n", "lang_cluster": "Java", "tags": ["dp", "combinatorics"], "code_uid": "03822ea31a9b386b94556d7b7dacc080", "src_uid": "309d2d46086d526d160292717dfef308", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.util.*;\n\n\npublic class Program\n{\n\tpublic static void main(String[] args)\n\t{ \n\t\tScanner s = new Scanner(System.in);\n\t\tint a,b,c,t = 1, t0;\n\t\tboolean espera = true;\n\t\ta = s.nextInt();;\n\t\tb = s.nextInt();;\n\t\tc = s.nextInt();;\n\t\t\n\t\t// verifica se Tamanho x tempo > tempo espera*tamanho baixado\n\t\tfor (t = 1; a * c > t * b; t++) //while (a * c > t * b) \n\t\t{ \n\t\t\tespera = true;// define que ainda deve esperar\t\n\t\t\tfor (t0 = t; t0 <= t + c; t0++) // Tempo apos dar play deve ser menor que o tempo de espera+tempo de video\n\t\t\t{\t\n\n\t\t\t\tif (t0 * b < (t0 - t) * a)// tempo apos play x velocidade de download < TAD-Tempo espera * tamanho do video\t\t\t\t \n\t\t\t\t{\n\t\t\t\t\t \n\t\t\t\t\tespera = false; // pode dar play no video\n break;\n } \n\t\t\t}\n if (espera)// Escreve tempo minimo necesario de espera\n {\n\t\t\t\tSystem.out.println(t);\n\t\t\t\tbreak;\n }\n\n \n\t\t}\n\t\n\t}\n\n\n}", "lang_cluster": "Java", "tags": ["brute force", "math", "binary search"], "code_uid": "122c46da6cfc07327e3502c6ef35a404", "src_uid": "7dd098ec3ad5b29ad681787173eba341", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.StringTokenizer;\n\npublic class C_PermuteDigits {\n private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n private static final PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n private static StringTokenizer st;\n\n private static Long readLong() throws IOException {\n while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());\n return Long.parseLong(st.nextToken());\n }\n\n public static void main(String[] args) throws IOException {\n pw.println(solve());\n pw.close();\n }\n\n private static long solve() throws IOException {\n long a = readLong();\n long b = readLong();\n\n ArrayList da = disassemble(a);\n ArrayList db = disassemble(b);\n\n if (da.size() < db.size()) {\n da.sort(Collections.reverseOrder());\n return assemble(da);\n }\n // da.size() == db.size()\n\n // a = 4568912\n // b = 458 4 567\n // 458 2 981\n\n int s = db.size();\n ArrayList answer = new ArrayList<>();\n\n Collections.reverse(db);\n for (int i = 0; i < s; i++) {\n Integer d = db.get(i);\n if (da.contains(d)) {\n answer.add(d);\n da.remove(d);\n } else {\n // find the largest number in da that is less than d\n Integer x = largestMemberSmallerThan(d, da);\n\n // 5 6 2\n // 5 6 3\n if (x == -1) {\n for (int j = i - 1; j >= 0; j--) {\n da.add(db.get(j));\n answer.remove(answer.size() - 1);\n Integer y = largestMemberSmallerThan(db.get(j), da);\n if (y != -1) {\n answer.add(y);\n da.remove(y);\n break;\n }\n }\n } else {\n answer.add(x);\n da.remove(Integer.valueOf(x));\n }\n\n da.sort(Collections.reverseOrder());\n answer.addAll(da);\n return assemble(answer);\n }\n }\n\n return b;\n }\n\n static ArrayList disassemble(long a) {\n ArrayList da = new ArrayList<>();\n while (a > 0) {\n da.add(((int) (a % 10)));\n a /= 10;\n }\n return da;\n }\n\n static long assemble(ArrayList digits) {\n long result = 0;\n for (int i : digits) {\n result = result * 10 + i;\n }\n return result;\n }\n\n static Integer largestMemberSmallerThan(int limit, ArrayList digits) {\n int x = -1;\n for (Integer j : digits) {\n if (j < limit && x < j) x = j;\n }\n\n return x;\n }\n}\n", "lang_cluster": "Java", "tags": ["greedy", "dp"], "code_uid": "43957bbe052998cfdb7424663d184569", "src_uid": "bc31a1d4a02a0011eb9f5c754501cd44", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class Main\n{\n public static void main(String args[])\n {\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n int v=n-10;\n if(v==10)\n System.out.println(15);\n else if(v==0)\n System.out.println(0);\n else if(v==1)\n {\n System.out.println(4);\n \n }\n else if(v==11)\n System.out.println(4);\n else\n {\n if(v<=10&&v>0)\n {\n System.out.println(4);\n }\n else\n System.out.println(0);\n }\n }\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "057be3571a83a927330d2a4984cd183c", "src_uid": "5802f52caff6015f21b80872274ab16c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class A\n{\n public static void main(String args[])\n {\n Scanner sc=new Scanner(System.in);\n String s1=sc.next();\n String s2=sc.next();\n int a[]=new int[26];\n int b[]=new int[26];\n for(int i=0;is2.length())\n {\n int j=0;\n int n=s1.length();\n int m=s2.length();\n for(int i=0;i0)\n {\n if(a[i]= 0; j++) {\n dp[i] += dp[i - j];\n while (dp[i] >= MOD) dp[i] -= MOD;\n }\n }\n long[] dp1 = new long[n + 1];\n dp1[0] = 1;\n for (int i = 1; i <= n; i++) {\n for (int j = 1; j < d && i - j >= 0; j++) {\n dp1[i] += dp1[i - j];\n while (dp1[i] >= MOD) dp1[i] -= MOD;\n }\n }\n long res = dp[n] - dp1[n];\n while (res < 0) res += MOD;\n while (res >= MOD) res -= MOD;\n out.println(res);\n }\n}\n\nclass InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt(){\n return Integer.parseInt(next());\n }\n\n}\n", "lang_cluster": "Java", "tags": ["dp", "implementation", "trees"], "code_uid": "5d4cc63bf1225cd512d01fe88e02c3f8", "src_uid": "894a58c9bba5eba11b843c5c5ca0025d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class Snowball{\n\tpublic static void main(String args[])\n\t{\n\t\tScanner sc = new Scanner(System.in);\n\t\tint w = sc.nextInt();\n\t\tint h = sc.nextInt();\n\t\tint u1 = sc.nextInt();\n\t\tint d1 = sc.nextInt();\n\t\tint u2 = sc.nextInt();\n\t\tint d2 = sc.nextInt();\n\t\tfor(int i = h;i>=0;i--)\n\t\t{\n\t\t\tw = w+i;\n\t\t\tif(i==d1)\n\t\t\t{\n\t\t\t\tw=w-u1;\n\t\t\t\tif(w<0)\n\t\t\t\t\tw=0;\n\t\t\t}\n\t\t\tif(i==d2)\n\t\t\t{\n\t\t\t\tw=w-u2;\n\t\t\t\tif(w<0)\n\t\t\t\t\tw=0;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(w);\n\t}\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "0ccd05fa4546f953e32640108f38f34f", "src_uid": "084a12eb3a708b43b880734f3ee51374", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.text.DecimalFormat;\nimport java.util.*;\nimport java.lang.*;\n\npublic class Problem2 {\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner sc=new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\tint x=sc.nextInt();\n\t\tint[][] a= { {0,1,2},{1,0,2},{1,2,0},{2,1,0},{2,0,1},{0,2,1}};\n\t\tSystem.out.println(a[n%6][x]);\n\t}\n}\n\t", "lang_cluster": "Java", "tags": ["math", "constructive algorithms", "implementation"], "code_uid": "2b22c3196129b274ed37ef219a80229e", "src_uid": "7853e03d520cd71571a6079cdfc4c4b0", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.Scanner;\n\npublic class CF1061A {\n\n public static void main(String[] args) {\n Scanner s=new Scanner(System.in);\n int n=s.nextInt();\n int target=s.nextInt();\n int total=target/n;\n if(target%n!=0){\n total=total+1;\n }\n System.out.println(total);\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "greedy", "implementation"], "code_uid": "6a1f18afef31baf4757d971f8857dc80", "src_uid": "04c067326ec897091c3dbcf4d134df96", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\n\npublic class Main {\n\n public static class Solution {\n\n public String generageLogin() {\n Scanner scanner = new Scanner(System.in);\n String name = scanner.nextLine();\n scanner.close();\n String[] na = name.split(\" \");\n String s1 = na[0];\n String s2 = na[1];\n int i = 0;\n int j = 0;\n\n StringBuilder sb = new StringBuilder();\n while (i < s1.length() && j < s2.length()) {\n int comp = (s1.charAt(i) - 'a') - (s2.charAt(j) - 'a');\n\n if (comp < 0 && i > 0) {\n sb.append(s1.charAt(i++));\n } else if (comp < 0) {\n sb.append(s1.charAt(i++));\n } else if ((comp > 0 || comp == 0) && i == 0) {\n sb.append(s1.charAt(i++));\n //sb.append(s2.charAt(j++));\n //break;\n } else if ((comp > 0 || comp == 0) && i > 0) {\n sb.append(s2.charAt(j++));\n break;\n } \n }\n\n if (j == 0) {\n sb.append(s2.charAt(j++));\n }\n\n return sb.toString();\n }\n\n }\n\n public static void main(String[] args) {\n Solution sol = new Solution();\n System.out.println(sol.generageLogin());\n\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "sortings", "greedy"], "code_uid": "4ad7dc444f2417bbb5279c0452127400", "src_uid": "aed892f2bda10b6aee10dcb834a63709", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.*;\n\npublic class Run {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n int n = scanner.nextInt();\n int k = scanner.nextInt();\n int[] a = new int[n];\n for(int i = 0; i < n; i++)\n a[i] = scanner.nextInt();\n \n int res = 0;\n for(int i = 0; i < k; i++) {\n int count = 0;\n int m = n/k;\n for(int t = 0; t < m; t++) {\n if(a[i + k*t] == 1) count++;\n }\n if(count <= m/2) res += count;\n else res += (m - count);\n }\n \n System.out.println(res);\n }\n}", "lang_cluster": "Java", "tags": ["math", "greedy", "implementation"], "code_uid": "0b9d3955aa398628413748036fbe7af2", "src_uid": "5f94c2ecf1cf8fdbb6117cab801ed281", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.util.InputMismatchException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int N = in.nextInt();\n String S = in.next();\n\n String ans = \"no\";\n for (int len = 1; len <= N; ++len) {\n for (int i = 0; i + len * 4 < N; ++i) {\n if (S.charAt(i) == '*' && S.charAt(i + len) == '*' && S.charAt(i + 2 * len) == '*'\n && S.charAt(i + 3 * len) == '*' && S.charAt(i + 4 * len) == '*')\n ans = \"yes\";\n }\n }\n\n out.println(ans);\n }\n}\n\nclass InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1)\n throw new UnknownError();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new UnknownError();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public String next() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuffer res = new StringBuffer();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n\n return res.toString();\n }\n\n private boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n}\n\n", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "76510fa8372bdf863b659e84b07e5633", "src_uid": "12d451eb1b401a8f426287c4c6909e4b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.Comparator;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Random;\nimport java.io.Writer;\nimport java.util.HashSet;\nimport java.util.List;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.ArrayList;\nimport java.util.NoSuchElementException;\nimport java.util.TreeSet;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Alex\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tOutputWriter out = new OutputWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n public void solve(int testNumber, InputReader in, OutputWriter out){\n\t int ncards = in.ri();\n\t IntPair[] cards = new IntPair[ncards];\n\t String[] translate = new String[]{\"R\", \"G\", \"B\", \"Y\", \"W\"};\n\t for(int i = 0; i < ncards; i++) {\n\t\t String temp = in.next();\n\t\t int first = ArrayUtils.find(translate, Character.toString(temp.charAt(0)));\n\t\t int second = temp.charAt(1) - '1';\n\t\t cards[i] = new IntPair(first, second);\n\t }\n\t int res = Integer.MAX_VALUE;\n\t for(int mask = 0; mask < 1024; mask++) {\n\t\t boolean works = true;\n\t\t for(int i = 0; i < cards.length; i++) {\n\t\t\t for(int j = i + 1; j < cards.length; j++) {\n\t\t\t\t if (cards[i].first == cards[j].first && cards[i].second == cards[j].second) continue;\n\t\t\t\t if (cards[i].first != cards[j].first && ((mask >> cards[i].first & 1) == 1 || (mask >> cards[j].first & 1) == 1)) continue;\n\t\t\t\t if(cards[i].second != cards[j].second && ((mask >> (cards[i].second + 5) & 1) == 1 || (mask >> (cards[j].second + 5) & 1) == 1)) continue;\n\t\t\t\t works = false;\n\t\t\t }\n\t\t }\n\t\t if (works) res = Math.min(Integer.bitCount(mask), res);\n\t }\n\t out.printLine(res);\n }\n}\n\nclass InputReader {\n\tprivate InputStream stream;\n\tprivate byte[] buf = new byte[1024];\n\tprivate int curChar;\n\tprivate int numChars;\n\tprivate SpaceCharFilter filter;\n\n\tpublic InputReader(InputStream stream) {\n\t\tthis.stream = stream;\n\t}\n\n\tpublic int read() {\n\t\tif (numChars == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (curChar >= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n\tpublic int ri(){\n\t\treturn readInt();\n\t}\n\n\tpublic int readInt() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tint res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\tpublic String readString() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tStringBuilder res = new StringBuilder();\n\t\tdo {\n\t\t\tif (Character.isValidCodePoint(c))\n\t\t\t\tres.appendCodePoint(c);\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res.toString();\n\t}\n\n\tpublic boolean isSpaceChar(int c) {\n\t\tif (filter != null)\n\t\t\treturn filter.isSpaceChar(c);\n\t\treturn isWhitespace(c);\n\t}\n\n\tpublic static boolean isWhitespace(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n\tpublic String next() {\n\t\treturn readString();\n\t}\n\tpublic interface SpaceCharFilter {\n\t\tpublic boolean isSpaceChar(int ch);\n\t}\n}\n\nclass OutputWriter {\n\tprivate final PrintWriter writer;\n\n\tpublic OutputWriter(OutputStream outputStream) {\n\t\twriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n\t}\n\tpublic void close() {\n\t\twriter.close();\n\t}\n\tpublic void printLine(int i) {\n\t\twriter.println(i);\n\t}\n\n}\n\nclass IntPair implements Comparable {\npublic int first, second;\n\n\n\tpublic IntPair(int first, int second) {\n\t\tthis.first = first;\n\t\tthis.second = second;\n\t}\n\n\tpublic String toString() {\n\t\treturn \"(\" + first + \",\" + second + \")\";\n\t}\n\n\tpublic boolean equals(Object o) {\n\t\tif (this == o) return true;\n\t\tif (o == null || getClass() != o.getClass()) return false;\n\n\t\tIntPair intPair = (IntPair) o;\n\n\t\treturn first == intPair.first && second == intPair.second;\n\n\t}\n\n\tpublic int hashCode() {\n\t\tint result = first;\n\t\tresult = 31 * result + second;\n\t\treturn result;\n\t}\n\n\tpublic int compareTo(IntPair o) {\n\t\tif (first < o.first)\n\t\t\treturn -1;\n\t\tif (first > o.first)\n\t\t\treturn 1;\n\t\tif (second < o.second)\n\t\t\treturn -1;\n\t\tif (second > o.second)\n\t\t\treturn 1;\n\t\treturn 0;\n\t}\n}\n\nclass ArrayUtils {\n\tpublic static int find(String[] array, String value) {\n\t\tfor (int i = 0; i < array.length; i++) {\n\t\t\tif (array[i].equals(value)) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n}\n\n", "lang_cluster": "Java", "tags": ["brute force", "implementation", "bitmasks"], "code_uid": "b72fb5fcb2f9a72850276148d341aab6", "src_uid": "3b12863997b377b47bae43566ec1a63b", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class div375B\n{\n\tBufferedReader in;\n\tPrintWriter ob;\n\tStringTokenizer st;\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew div375B().run();\n\t}\n\tvoid run() throws IOException {\n\t\tin=new BufferedReader(new InputStreamReader(System.in));\n\t\tob=new PrintWriter(System.out);\n\t\tsolve();\n\t\tob.flush();\n\t}\n\tvoid solve() throws IOException {\n\t\tint n=ni();\n\t\tchar s[]=ns().toCharArray();\n\t\tint ans1=0,ans2=0;\n\t\tfor (int i=0; i0)++ans2;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tif(s[i+1]=='_'){\n\t\t\t\t\t\tif(c>0) {\n\t\t\t\t\t\t\t++ans2;\n\t\t\t\t\t\t\tc=0;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\t++c;\n\t\t\t\t\t++i;\n\t\t\t\t}\t\n\t\t\t}\n\t\t\telse if(s[i]==')' || s[i]=='_') {\n\t\t\t\tint c=0;\n\t\t\t\twhile(i+1 dp = new HashMap();\n\n\tpublic static void main(String[] args) throws FileNotFoundException {\n\t\t// PrintWriter out = new PrintWriter(new FileOutputStream(new File(\n\t\t// \"output.txt\")));\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tScanner in = new Scanner();\n\t\tlong n = in.nextLong();\n\t\tlong start = 1;\n\t\tlong end = 1;\n\t\tlong cur = 1;\n\t\tlong total = 2;\n\t\twhile (total < n) {\n\t\t\tcur++;\n\t\t\tlong tmp = start + end;\n\t\t\tstart = end;\n\t\t\tend = tmp;\n\t\t\ttotal += tmp;\n\t\t}\n\t\tout.println(cur);\n\t\tout.close();\n\t}\n\n\tpublic static int[] KMP(String val) {\n\t\tint i = 0;\n\t\tint j = -1;\n\t\tint[] result = new int[val.length() + 1];\n\t\tresult[0] = -1;\n\t\twhile (i < val.length()) {\n\t\t\twhile (j >= 0 && val.charAt(j) != val.charAt(i)) {\n\t\t\t\tj = result[j];\n\t\t\t}\n\t\t\tj++;\n\t\t\ti++;\n\t\t\tresult[i] = j;\n\t\t}\n\t\treturn result;\n\n\t}\n\n\tpublic static boolean nextPer(int[] data) {\n\t\tint i = data.length - 1;\n\t\twhile (i > 0 && data[i] < data[i - 1]) {\n\t\t\ti--;\n\t\t}\n\t\tif (i == 0) {\n\t\t\treturn false;\n\t\t}\n\t\tint j = data.length - 1;\n\t\twhile (data[j] < data[i - 1]) {\n\t\t\tj--;\n\t\t}\n\t\tint temp = data[i - 1];\n\t\tdata[i - 1] = data[j];\n\t\tdata[j] = temp;\n\t\tArrays.sort(data, i, data.length);\n\t\treturn true;\n\t}\n\n\tpublic static int digit(long n) {\n\t\tint result = 0;\n\t\twhile (n > 0) {\n\t\t\tn /= 10;\n\t\t\tresult++;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static double dist(long a, long b, long x, long y) {\n\t\tdouble val = (b - a) * (b - a) + (x - y) * (x - y);\n\t\tval = Math.sqrt(val);\n\t\tdouble other = x * x + a * a;\n\t\tother = Math.sqrt(other);\n\t\treturn val + other;\n\n\t}\n\n\tpublic static class Point implements Comparable {\n\n\t\tint x, y;\n\n\t\tpublic Point(int start, int end) {\n\t\t\tthis.x = start;\n\t\t\tthis.y = end;\n\t\t}\n\n\t\t@Override\n\t\tpublic int hashCode() {\n\t\t\tint hash = 5;\n\t\t\thash = 47 * hash + this.x;\n\t\t\thash = 47 * hash + this.y;\n\t\t\treturn hash;\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean equals(Object obj) {\n\t\t\tif (obj == null) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (getClass() != obj.getClass()) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tfinal Point other = (Point) obj;\n\t\t\tif (this.x != other.x) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (this.y != other.y) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Point o) {\n\t\t\treturn Integer.compare(x, o.x);\n\t\t}\n\t}\n\n\tpublic static class FT {\n\n\t\tlong[] data;\n\n\t\tFT(int n) {\n\t\t\tdata = new long[n];\n\t\t}\n\n\t\tpublic void update(int index, long value) {\n\t\t\twhile (index < data.length) {\n\t\t\t\tdata[index] += value;\n\t\t\t\tindex += (index & (-index));\n\t\t\t}\n\t\t}\n\n\t\tpublic long get(int index) {\n\t\t\tlong result = 0;\n\t\t\twhile (index > 0) {\n\t\t\t\tresult += data[index];\n\t\t\t\tindex -= (index & (-index));\n\t\t\t}\n\t\t\treturn result;\n\n\t\t}\n\t}\n\n\tpublic static long gcd(long a, long b) {\n\t\tif (b == 0) {\n\t\t\treturn a;\n\t\t}\n\t\treturn gcd(b, a % b);\n\t}\n\n\tpublic static long pow(long a, long b) {\n\t\tif (b == 0) {\n\t\t\treturn 1;\n\t\t}\n\t\tif (b == 1) {\n\t\t\treturn a;\n\t\t}\n\t\tlong val = pow(a, b / 2);\n\t\tif (b % 2 == 0) {\n\t\t\treturn val * val % MOD;\n\t\t} else {\n\t\t\treturn val * (val * a % MOD) % MOD;\n\n\t\t}\n\t}\n\n\tstatic class Scanner {\n\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic Scanner() throws FileNotFoundException {\n\t\t\t// System.setOut(new PrintStream(new\n\t\t\t// BufferedOutputStream(System.out), true));\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t// br = new BufferedReader(new InputStreamReader(new\n\t\t\t// FileInputStream(new File(\"input.txt\"))));\n\t\t}\n\n\t\tpublic String next() {\n\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\tthrow new RuntimeException();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tst = null;\n\t\t\ttry {\n\t\t\t\treturn br.readLine();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t}\n\n\t\tpublic boolean endLine() {\n\t\t\ttry {\n\t\t\t\tString next = br.readLine();\n\t\t\t\twhile (next != null && next.trim().isEmpty()) {\n\t\t\t\t\tnext = br.readLine();\n\t\t\t\t}\n\t\t\t\tif (next == null) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tst = new StringTokenizer(next);\n\t\t\t\treturn st.hasMoreTokens();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "greedy", "constructive algorithms", "combinatorics"], "code_uid": "9dd87b05e1b5ff8e2710ada8a1ac8e6a", "src_uid": "3d3432b4f7c6a3b901161fa24b415b14", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.util.ArrayList;\nimport java.util.HashSet;\nimport java.util.InputMismatchException;\nimport java.util.List;\nimport java.util.Set;\n\npublic class Codeforces {\n\n long mod = 1000000007;\n\n public void solve() {\n InputReader in = new InputReader(System.in);\n OutputWriter out = new OutputWriter(System.out);\n int n = in.readInt();\n long fact = 1;\n long product = 1;\n for (int i = 2; i <= n; i++) {\n fact = (fact * i) % mod;\n product = (product * 2) % mod;\n }\n if(fact>=product)\n out.printLine(((fact - product)%mod));\n else{\n out.printLine(mod-(Math.abs(fact-product)%mod));\n }\n out.flush();\n }\n\n public static void main(String[] args) {\n Codeforces solver = new Codeforces();\n solver.solve();\n }\n\n static class InputReader {\n\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if ( numChars == -1 )\n throw new InputMismatchException();\n if ( curChar >= numChars ) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if ( numChars <= 0 )\n return -1;\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if ( c == '-' ) {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if ( c < '0' || c > '9' )\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public long readLong() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if ( c == '-' ) {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if ( c < '0' || c > '9' )\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public String readString() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n if ( filter != null )\n return filter.isSpaceChar(c);\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public String next() {\n return readString();\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void print(Object... objects) {\n for (int i = 0; i < objects.length; i++) {\n if ( i != 0 )\n writer.print(' ');\n writer.print(objects[i]);\n }\n }\n\n public void printLine(Object... objects) {\n print(objects);\n writer.println();\n }\n\n public void close() {\n writer.close();\n }\n\n public void flush() {\n writer.flush();\n }\n\n }\n\n static class IOUtils {\n\n public static int[] readIntegerArray(InputReader in, int size) {\n int[] array = new int[size];\n for (int i = 0; i < size; i++) {\n array[i] = in.readInt();\n }\n return array;\n }\n\n public static long[] readLongArray(InputReader in, int size) {\n long[] array = new long[size];\n for (int i = 0; i < size; i++) {\n array[i] = in.readLong();\n }\n return array;\n }\n\n public static List readIntegerList(InputReader in, int size) {\n List set = new ArrayList<>();\n for (int i = 0; i < size; i++) {\n set.add(in.readInt());\n }\n return set;\n }\n\n public static Set readIntegerSet(InputReader in, int size) {\n Set set = new HashSet();\n for (int i = 0; i < size; i++) {\n set.add(in.readInt());\n }\n return set;\n }\n }\n}", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics", "graphs"], "code_uid": "2c9e222ffc8dd2215c216a42c174309a", "src_uid": "3dc1ee09016a25421ae371fa8005fce1", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 17", "source_code": "\r\n\r\nimport java.util.*;\r\nimport java.io.*;\r\nimport java.math.BigInteger;\r\npublic class Main {\r\n public static FastReader cin;\r\n public static PrintWriter out;\r\n public static void main(String[] args) throws Exception {\r\n out = new PrintWriter(new BufferedOutputStream(System.out));\r\n cin = new FastReader();\r\n int qq = cin.nextInt();\r\n// int qq = 1;\r\n label:while(qq-->0){\r\n int [][]arr = new int [2][2];\r\n int count = 0;\r\n for(int i = 0 ; i < 2 ; i ++){\r\n for(int j = 0 ; j < 2; j++){\r\n arr[i][j] = cin.nextInt();\r\n count+=arr[i][j];\r\n }\r\n }\r\n if(count==0){\r\n out.println(\"0\");\r\n }else if(count==4){\r\n out.println(\"2\");\r\n }else out.println(\"1\");\r\n }\r\n out.close();\r\n }\r\n public static int reverse(int n){\r\n int r = 0;\r\n while(n>0){\r\n r = r * 10 + n % 10;\r\n n /= 10;\r\n }\r\n return r;\r\n }\r\n public static boolean check(int n ){\r\n int temp = reverse(n);\r\n if(temp==n){\r\n return true;\r\n }else return false;\r\n }\r\n static class Node{\r\n int id ;\r\n Listson;\r\n }\r\n static class FastReader {\r\n BufferedReader br;\r\n StringTokenizer str;\r\n\r\n public FastReader() {\r\n br = new BufferedReader(new\r\n InputStreamReader(System.in));\r\n }\r\n\r\n String next() {\r\n while (str == null || !str.hasMoreElements()) {\r\n try {\r\n str = new StringTokenizer(br.readLine());\r\n } catch (IOException lastMonthOfVacation) {\r\n lastMonthOfVacation.printStackTrace();\r\n }\r\n }\r\n return str.nextToken();\r\n }\r\n\r\n int nextInt() {\r\n return Integer.parseInt(next());\r\n }\r\n\r\n long nextLong() {\r\n return Long.parseLong(next());\r\n }\r\n\r\n double nextDouble() {\r\n return Double.parseDouble(next());\r\n }\r\n\r\n String nextLine() {\r\n String str = \"\";\r\n try {\r\n str = br.readLine();\r\n } catch (IOException lastMonthOfVacation) {\r\n lastMonthOfVacation.printStackTrace();\r\n }\r\n return str;\r\n }\r\n }\r\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "dee539d1011946f0f9c479c56afd00df", "src_uid": "7336b8becd2438f0439240ee8f9610ec", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\n\npublic class Main {\n public static void main(String[] args) {\n Scanner r = new Scanner(System.in);\n \n String a = r.next()+\"/\";\n String b = \"\";\n \n for(int i = 0; i < a.length(); i++)\n if(a.charAt(i) != '/')b += a.charAt(i);\n else{\n if(i > 0 && a.charAt(i-1) == '/')continue;\n else b += a.charAt(i);\n }\n \n if(b.length() > 1)\n b = b.substring(0, b.length()-1);\n \n System.out.println(b);\n }\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "8e26e37aa8ae15d35b6da52b6d1d943b", "src_uid": "6c2e658ac3c3d6b0569dd373806fa031", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Main {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int t = sc.nextInt();\n boolean b = true;\n if (t == 2) {\n System.out.println(\"1\");\n } else {\n int count = 0;\n for (int i = 1; i < t; i++) {\n b = true;\n int tmp = i;\n if ((tmp - 1) % t != 0) {\n for (int j = 2; j < t - 1; j++) {\n tmp *= i;\n tmp = (tmp - 1) % t;\n if (tmp == 0) {\n b = false;\n break;\n }\n tmp++;\n }\n if (b) {\n tmp *= i;\n tmp = (tmp - 1) % t;\n if (tmp == 0) {\n count++;\n }\n }\n }\n }\n System.out.println(count);\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation", "number theory"], "code_uid": "72ae0109c54e63f90061b766d5dc4283", "src_uid": "3bed682b6813f1ddb54410218c233cff", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n\n\n/* Name of the class has to be \"Main\" only if the class is public. */\n\n\n\npublic class Main\n{\n \n \n \n static PrintWriter out;\n \n\tstatic class FastReader{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FastReader(){\n\t\t\tbr=new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout=new PrintWriter(System.out);\n\t\t}\n\t\tString next(){\n\t\t\twhile(st==null || !st.hasMoreElements()){\n\t\t\t\ttry{\n\t\t\t\t\tst= new StringTokenizer(br.readLine());\n\t\t\t\t}\n\t\t\t\tcatch (IOException e){\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tint nextInt(){\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tlong nextLong(){\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\tdouble nextDouble(){\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\tString nextLine(){\n\t\t\tString str = \"\";\n\t\t\ttry{\n\t\t\t\tstr=br.readLine();\n\t\t\t}\n\t\t\tcatch(IOException e){\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\t}\n\t\n\n// SHIVAM GUPTA :\n\n\n\n// ASCII = 48 + i ;\n\nstatic Set set1 ; static Set set2 ;\n\n\npublic static boolean isPossibleTriangle(int a ,int b , int c)\n{\n if( a + b > c && c+b > a && a +c > b)\n {\n return true ;\n }\n \n return false ;\n \n \n}\n \n \n \npublic static void main (String[] args) throws java.lang.Exception\n{\n FastReader scn = new FastReader() ;\n \n\n//int t= scn.nextInt() ;\n\n//for(int i = 1; i<= t ; i++)\n//{\n int a= scn.nextInt() ;int b= scn.nextInt() ;\n int c= scn.nextInt() ;\n \n int[] arr = new int[3] ;\n arr[0] = a ; arr[1] = b; arr[2] = c ;\n Arrays.sort(arr) ;\n \n if(arr[0] +arr[1] > arr[2])out.println(0) ;\n \n else{\n \n int ans = arr[2] - arr[1] - arr[0] + 1 ;\n out.println(ans) ;\n }\n \n \n \n \n// }\n\n\n\n \nout.flush() ; \n \n}\n\n\n}\n \n ", "lang_cluster": "Java", "tags": ["brute force", "math", "geometry"], "code_uid": "05701b3267f0528146d92cade702ae66", "src_uid": "3dc56bc08606a39dd9ca40a43c452f09", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class ProblemSolving {\n\n public static void main(String[] args) {\n int len ,index;\n Scanner s = new Scanner(System.in);\n len = s.nextInt();\n index = s.nextInt();\n int arr[];\n arr = new int[len];\n for(int i =0 ; i< len ; i++) arr[i]= s.nextInt();\n \n //------------------\n index--;\n int left =index\n ,right = index\n ,counter=0;\n boolean flag = false;\n if(arr.length==1){\n System.out.println(arr[0]);\n }else{\n while((right-left)!=arr.length-1||flag!=true){\n// System.out.println(left+\" \"+right);\n// System.out.println(arr[left]+\" \"+arr[right]);\n// System.out.println(Math.abs(left-index) +\" \"+Math.abs(right-index));\n if(arr[left]==1&&arr[right]==1){\n if(left == right){\n counter++;\n arr[left]=0;\n }else{\n counter+=2;\n arr[left]=0;\n arr[right]=0;\n }\n }else{\n if((Math.abs(left-index)!=Math.abs(right-index))&&(arr[left]==1 || arr[right]==1))counter++; \n arr[left]=0;\n arr[right]=0;\n }\n// System.out.println(counter);\n if(left==0&&right==arr.length-1)flag = true;\n if(left!=0)left--;\n if(right!=arr.length-1)right++;\n \n }\n System.out.println(counter); \n } \n \n }\n \n \n}\n", "lang_cluster": "Java", "tags": ["constructive algorithms", "implementation"], "code_uid": "5ed099db34d8baf9763fe16f74415200", "src_uid": "4840d571d4ce6e1096bb678b6c100ae5", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class Main{\n public static void main(String args[])\n {\n Scanner sc=new Scanner(System.in);\n String s=sc.next();\n s=s.toLowerCase();\n String r=\"\";\n for(int i=0;i=r){\n sum = 5*answer*(answer+1)/2;\n if(allTime-(sum+k)<0){\n answer--;\n }\n break;\n }\n }\n }\n out.println(answer);\n /*\n char direction = in.nextChar();\n String str = \"qwertyuiopasdfghjkl;zxcvbnm,./\";\n int [] map = new int[256];\n for(int i=0; i prate)\n\t\t{\n\t\t\tdouble hrs = (pdistance + 0.0) / (drate - prate);\n\t\t\tpdistance += prate * hrs;\n\t\t\twhile (pdistance < miles) {\n\t\t\t\tbijou++;\n\t\t\t\tpdistance += prate * (hrs + organizehrs);\n\t\t\t\thrs = (pdistance + 0.0) / (drate - prate);\n\t\t\t\tpdistance += prate * hrs;\n\t\t\t}\n\t\t}\n\n\t\tSystem.out.println(bijou);\n\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "07ac49fd1ce562cf7c016db590fc2e8a", "src_uid": "c9c03666278acec35f0e273691fe0fff", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n\tstatic int MOD = 1000 * 1000 * 1000 + 7;\n\n\tpublic static void main(String[] args) {\n\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tsolve(in, out);\n\t\tout.close();\n\t\tSystem.exit(0);\n\t}\n\n\tprivate static void solve(InputReader in, PrintWriter out) {\n\n\t\tint[][] tab = new int[3][2];\n\t\tfor (int i = 0; i < 3; i++) {\n\t\t\ttab[i][0] = in.nextInt();\n\t\t\ttab[i][1] = in.nextInt();\n\t\t}\n\n\t\tif (tab[0][0] == tab[1][0] && tab[1][0] == tab[2][0]) {\n\t\t\tout.print(1);\n\t\t\treturn;\n\t\t}\n\t\tif (tab[0][1] == tab[1][1] && tab[1][1] == tab[2][1]) {\n\t\t\tout.print(1);\n\t\t\treturn;\n\t\t}\n\n\t\tfor (int i = 0; i < 3; i++) {\n\t\t\tfor (int j = 0; j < 3; j++) {\n\t\t\t\tif (i == j) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tfor (int k = 0; k < 3; k++) {\n\t\t\t\t\tif (k == i || k == j) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif (tab[k][0] < Math.min(tab[i][0], tab[j][0]) || tab[k][0] > Math.max(tab[i][0], tab[j][0])) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif (tab[k][1] < Math.min(tab[i][1], tab[j][1]) || tab[k][1] > Math.max(tab[i][1], tab[j][1])) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif (tab[k][0] == tab[i][0] || tab[k][0] == tab[j][0] || tab[k][1] == tab[i][1]\n\t\t\t\t\t\t\t|| tab[k][1] == tab[j][1]) {\n\t\t\t\t\t\tout.print(2);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tout.print(3);\n\n\t}\n\n\t/*\n\t * \n\t */\n\t// --------------------------------------------------------\n\tstatic class InputReader {\n\t\tpublic BufferedReader reader;\n\t\tpublic StringTokenizer tokenizer;\n\n\t\tpublic InputReader(InputStream stream) {\n\t\t\treader = new BufferedReader(new InputStreamReader(stream), 32768);\n\t\t\ttokenizer = null;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tString str = \"\";\n\t\t\ttry {\n\t\t\t\tstr = reader.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\n\t\t\treturn str;\n\t\t}\n\t}\n}", "lang_cluster": "Java", "tags": ["constructive algorithms", "implementation"], "code_uid": "cd7909bc93ef08cfe88f6d6a94a29e95", "src_uid": "36fe960550e59b046202b5811343590d", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n\npublic class Main{\n\n public static void main(String[] args) throws IOException {\nBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\nStringTokenizer st=new StringTokenizer(br.readLine());\nint n=Integer.parseInt(st.nextToken());\nst=new StringTokenizer(br.readLine());\nint Nchest=0;\nint Nbiceps=0;\nint Nback=0;\nint w=2;\n for (int i =1; i <=n; i++) {\n if(i % 3==0)\n Nback+=Integer.parseInt(st.nextToken());\n else if(i==w){\n w=w+3;\n Nbiceps+=Integer.parseInt(st.nextToken());\n }\n else\n Nchest+=Integer.parseInt(st.nextToken());\n\n }\nif(Nchest > Nbiceps && Nchest > Nback)\n System.out.println(\"chest\");\nelse if( Nbiceps> Nchest && Nbiceps > Nback)\n System.out.println(\"biceps\");\nelse\n System.out.println(\"back\");\n }\n\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "bafe861d4a21de6a54b3a9505a24953d", "src_uid": "579021de624c072f5e0393aae762117e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class SimpleMoecules {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\n\t\tScanner input = new Scanner(System.in);\n\t\tint a = input.nextInt();\n\t\tint b = input.nextInt();\n\t\tint c = input.nextInt();\n\t\tif((c+b-a)%2==0){\n\t\t\tint z = (c+b-a)/2;\n\t\t\tif(z<0){\n\t\t\t\tSystem.out.println(\"Impossible\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tint y = c-z;\n\t\t\tif(y<0){\n\t\t\t\tSystem.out.println(\"Impossible\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tint x = a-y;\n\t\t\tif(x<0){\n\t\t\t\tSystem.out.println(\"Impossible\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\telse\n\t\t\t\tSystem.out.println(x+\" \"+z+\" \"+y);\n\t\t}\n\t\telse\n\t\t\tSystem.out.println(\"Impossible\");\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["brute force", "math", "graphs"], "code_uid": "82e24be68fd0c717c3c720b2851c3297", "src_uid": "b3b986fddc3770fed64b878fa42ab1bc", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.ArrayList;\nimport java.util.List;\n\npublic class Task886A {\n\n public static void main(String... args) throws NumberFormatException,\n IOException {\n Solution.main(System.in, System.out);\n }\n\n static class Scanner {\n\n private final BufferedReader br;\n private String[] cache;\n private int cacheIndex;\n\n Scanner(InputStream is) {\n br = new BufferedReader(new InputStreamReader(is));\n cache = new String[0];\n cacheIndex = 0;\n }\n\n int nextInt() throws IOException {\n if (cacheIndex >= cache.length) {\n cache = br.readLine().split(\" \");\n cacheIndex = 0;\n }\n return Integer.parseInt(cache[cacheIndex++]);\n }\n\n long nextLong() throws IOException {\n if (cacheIndex >= cache.length) {\n cache = br.readLine().split(\" \");\n cacheIndex = 0;\n }\n return Long.parseLong(cache[cacheIndex++]);\n }\n\n String next() throws IOException {\n if (cacheIndex >= cache.length) {\n cache = br.readLine().split(\" \");\n cacheIndex = 0;\n }\n return cache[cacheIndex++];\n }\n\n void close() throws IOException {\n br.close();\n }\n\n }\n\n static class Solution {\n\n public static void main(InputStream is, OutputStream os)\n throws NumberFormatException, IOException {\n PrintWriter pw = new PrintWriter(os);\n Scanner sc = new Scanner(is);\n\n\n List a = new ArrayList<>(6);\n\n int sum = 0;\n\n for(int i = 0 ; i < 6 ; i++){\n int tmp = sc.nextInt();\n sum += tmp;\n a.add(tmp);\n }\n\n boolean found = false;\n\n for(int i = 0 ; i < 6 ; i++){\n for(int j = i +1 ; j < 6 ; j++){\n for(int k = j + 1 ; k < 6 ; k++){\n if(2 * (a.get(i) + a.get(j) + a.get(k)) == sum){\n found = true;\n }\n }\n }\n }\n\n pw.println(found ? \"YES\" : \"NO\");\n\n pw.flush();\n sc.close();\n\n }\n }\n\n}", "lang_cluster": "Java", "tags": ["brute force"], "code_uid": "7508eaf732e162d7162e44add88c28ed", "src_uid": "2acf686862a34c337d1d2cbc0ac3fd11", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/* package whatever; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Ideone\n{\n public static void main (String[] args) throws java.lang.Exception\n {\n Scanner scanner = new Scanner(System.in);\n int n = scanner.nextInt();\n int arr[] = new int[n];\n for(int i = 0 ; i < n ;++i) {\n arr[i] = scanner.nextInt();\n }\n\n int finalCount = Integer.MAX_VALUE;\n for(int maxPos = 0; maxPos < n ;++maxPos) {\n int totalCount = 0;\n for (int i = 0; i < n; ++i) {\n int singleVal = 2 * Math.abs(maxPos - i) + 2 * i + 2 * maxPos;\n totalCount += (arr[i] * singleVal);\n }\n if(finalCount > totalCount) {\n finalCount = totalCount;\n }\n }\n\n System.out.println(finalCount);\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "b1394049d2263a836e976e90cc9460e2", "src_uid": "a5002ddf9e792cb4b4685e630f1e1b8f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class C implements Runnable{\n\tpublic static void main (String[] args) {new Thread(null, new C(), \"_cf\", 1 << 28).start();}\n\n\tint[] fact;\n\tint n50, n100;\n\tint n, k, MOD = (int)1e9+7, oo = (int)2e9;\n\n\tpublic void run() {\n\t\tFastScanner fs = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tSystem.err.println(\"Go!\");\n\n\t\tfact = new int[100];\n\t\tfact[0] = fact[1] = 1;\n\t\tfor(int i = 2; i < fact.length; i++)\n\t\t\tfact[i] = mult(fact[i-1], i);\n\n\t\tn = fs.nextInt();\n\t\tk = fs.nextInt();\n\t\tint n50 = 0, n100 = 0;\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tint x = fs.nextInt();\n\t\t\tif(x == 50) n50++;\n\t\t\telse n100++;\n\t\t}\n\t\tthis.n50 = n50;\n\t\tthis.n100 = n100;\n\n\t\tint[][][] dist = new int[2][n50+1][n100+1];\n\t\tint[][][] ways = new int[2][n50+1][n100+1];\n\t\tfor(int[][] d : dist)\n\t\t\tfor(int[] dd : d)\n\t\t\t\tArrays.fill(dd, oo);\n\t\tdist[0][n50][n100] = 0;\n\t\tways[0][n50][n100] = 1;\n\t\tArrayDeque bfs = new ArrayDeque<>();\n\t\tbfs.add(new Node(n50, n100, 0, 0));\n\t\twhile(!bfs.isEmpty()) {\n\t\t\tNode now = bfs.pollFirst();\n//\t\t\tSystem.out.println(now);\n\t\t\tint nn50 = n50 - now.n50;\n\t\t\tint nn100 = n100 - now.n100;\n\t\t\tfor(int i = 0; i <= now.n50; i++) {\n\t\t\t\tfor(int j = 0; j <= now.n100; j++) {\n\t\t\t\t\tif(i + j == 0) continue;\n\t\t\t\t\tif(i*50 + j*100 > k) continue;\n\t\t\t\t\tint ndist = 1 + dist[now.side][now.n50][now.n100];\n\t\t\t\t\tint x = dist[now.side^1][nn50+i][nn100+j];\n\t\t\t\t\tint tf = mult(ways[now.side][now.n50][now.n100], mult(nCk(now.n50, i), nCk(now.n100, j)));\n\t\t\t\t\t\n\t\t\t\t\tif(x > ndist) {\n\t\t\t\t\t\tdist[now.side^1][nn50+i][nn100+j] = ndist;\n\t\t\t\t\t\tways[now.side^1][nn50+i][nn100+j] = tf;\n\t\t\t\t\t\tbfs.add(new Node(nn50+i, nn100+j, now.side^1, ndist));\n\t\t\t\t\t}\n\t\t\t\t\telse if(x == ndist) {\n\t\t\t\t\t\tways[now.side^1][nn50+i][nn100+j] = add(ways[now.side^1][nn50+i][nn100+j], tf);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tint res = dist[1][n50][n100];\n\t\tint way = ways[1][n50][n100];\n\t\tif(res == oo) { res = -1; way = 0; }\n\t\tout.printf(\"%d\\n%d\\n\", res, way);\n\t\t\n\t\tout.close();\n\t}\n\n\tint add(long a, long b) {\n\t\ta %= MOD;\n\t\tb %= MOD;\n\t\ta += b;\n\t\ta %= MOD;\n\t\treturn (int)a;\n\t}\n\n\tint nCk(int n, int k) {\n\t\tint num = fact[n];\n\t\tint den = mult(fact[k], fact[n-k]);\n\t\tint inv = inv(den);\n\t\treturn mult(num, inv);\n\t}\n\n\tint inv(long x) {\n\t\tlong res = power(x, MOD - 2, MOD);\n\t\twhile(res < 0) res += MOD;\n\t\treturn (int)res;\n\t}\n\n\tint mult(long a, long b) {\n\t\ta %= MOD;\n\t\tb %= MOD;\n\t\ta *= b;\n\t\ta %= MOD;\n\t\treturn (int)a;\n\t}\n\n\tlong power (long x, long y, long m) {\n\t\tlong res = 1;\n\t\tx %= m;\n\t\twhile(y > 0) {\n\t\t\tif(y % 2 == 1) {\n\t\t\t\tres = (res * x) % m;\n\t\t\t}\n\t\t\ty >>= 1L;\n\t\t\t\t\t\tx = (x * x) % m;\n\t\t}\n\t\treturn res;\n\t}\n\t\n\tclass Node implements Comparable {\n\t\tint n50, n100, side, dist;\n\t\tNode(int a, int b, int c, int d) {\n\t\t\tn50 = a; n100 = b;\n\t\t\tside = c; dist = d;\n\t\t}\n\t\tpublic String toString() {\n\t\t\treturn String.format(\"(%d, %d) %d %d\", n50, n100, side, dist);\n\t\t}\n\t\tpublic int compareTo(Node n) {\n\t\t\treturn Integer.compare(dist, n.dist);\n\t\t}\n\t}\n\n\tclass FastScanner {\n\t\tpublic int BS = 1<<16;\n\t\tpublic char NC = (char)0;\n\t\tbyte[] buf = new byte[BS];\n\t\tint bId = 0, size = 0;\n\t\tchar c = NC;\n\t\tdouble num = 1;\n\t\tBufferedInputStream in;\n\n\t\tpublic FastScanner() {\n\t\t\tin = new BufferedInputStream(System.in, BS);\n\t\t}\n\n\t\tpublic FastScanner(String s) throws FileNotFoundException {\n\t\t\tin = new BufferedInputStream(new FileInputStream(new File(s)), BS);\n\t\t}\n\n\t\tpublic char nextChar(){\n\t\t\twhile(bId==size) {\n\t\t\t\ttry {\n\t\t\t\t\tsize = in.read(buf);\n\t\t\t\t}catch(Exception e) {\n\t\t\t\t\treturn NC;\n\t\t\t\t} \n\t\t\t\tif(size==-1)return NC;\n\t\t\t\tbId=0;\n\t\t\t}\n\t\t\treturn (char)buf[bId++];\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn (int)nextLong();\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\tnum=1;\n\t\t\tboolean neg = false;\n\t\t\tif(c==NC)c=nextChar();\n\t\t\tfor(;(c<'0' || c>'9'); c = nextChar()) {\n\t\t\t\tif(c=='-')neg=true;\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tfor(; c>='0' && c <='9'; c=nextChar()) {\n\t\t\t\tres = (res<<3)+(res<<1)+c-'0';\n\t\t\t\tnum*=10;\n\t\t\t}\n\t\t\treturn neg?-res:res;\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\tdouble cur = nextLong();\n\t\t\treturn c!='.' ? cur:cur+nextLong()/num;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\twhile(c<=32)c=nextChar();\n\t\t\twhile(c>32) {\n\t\t\t\tres.append(c);\n\t\t\t\tc=nextChar();\n\t\t\t}\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\twhile(c<=32)c=nextChar();\n\t\t\twhile(c!='\\n') {\n\t\t\t\tres.append(c);\n\t\t\t\tc=nextChar();\n\t\t\t}\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic boolean hasNext() {\n\t\t\tif(c>32)return true;\n\t\t\twhile(true) {\n\t\t\t\tc=nextChar();\n\t\t\t\tif(c==NC)return false;\n\t\t\t\telse if(c>32)return true;\n\t\t\t}\n\t\t}\n\n\t\tpublic int[] nextIntArray(int n) {\n\t\t\tint[] res = new int[n];\n\t\t\tfor(int i = 0; i < n; i++) res[i] = nextInt();\n\t\t\treturn res;\n\t\t}\n\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["dp", "combinatorics", "graphs", "shortest paths"], "code_uid": "5d87b5876abb231b09cfe8da2ce07b0e", "src_uid": "ebb0323a854e19794c79ab559792a1f7", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\npublic class Chess {\n public static void main(String[] args) throws Exception {\n BufferedReader b = new BufferedReader(new InputStreamReader(System.in));\n String rook = b.readLine(), knight = b.readLine();\n int board[][] = new int[8][8], Xaxis = rook.charAt(0) - 'a', Yaxis = rook.charAt(1) - '1';\n for (int i = 0; i < 8; i++) {\n board[Xaxis][i] = 1;\n board[i][Yaxis] = 1;\n }\n int moveX[] = {2, 2, -2, -2, 1, 1, -1, -1}, moveY[] = {1, -1, 1, -1, 2, -2, 2, -2};\n for (int i = 0; i < 8; i++) {\n int x = Xaxis + moveX[i], y = Yaxis + moveY[i];\n if (x >= 0 && x < 8 && y >= 0 && y < 8) {\n board[x][y] = 1;\n }\n }\n\n Xaxis = knight.charAt(0) - 'a';\n Yaxis = knight.charAt(1) - '1';\n board[Xaxis][Yaxis] = 1;\n for (int i = 0; i < 8; i++) {\n int x = Xaxis + moveX[i], y = Yaxis + moveY[i];\n if (x >= 0 && x < 8 && y >= 0 && y < 8) {\n board[x][y] = 1;\n }\n }\n\n int count = 0;\n for (int i = 0; i < 8; i++) {\n for (int j = 0; j < 8; j++) {\n if (board[i][j] == 0) {\n count++;\n }\n }\n }\n System.out.println(count);\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "math", "implementation"], "code_uid": "aaa6408ad8336ebfc0bd77bcdae24c90", "src_uid": "073023c6b72ce923df2afd6130719cfc", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n/**\n * Created by IntelliJ IDEA.\n * User: tiro\n * Date: 19/08/11\n * Time: 18:00\n * To change this template use File | Settings | File Templates.\n */\n\npublic class Durak extends Thread {\n private String doS(String input) {\n if (!Character.isDigit(input.charAt(0))) {\n input = input.replace('T', '4');\n input = input.replace('J', '5');\n input = input.replace('Q', '6');\n input = input.replace('K', '7');\n input = input.replace('A', '8');\n } else {\n Integer digit = Character.digit(input.charAt(0), 10);\n Character ch = digit.toString().charAt(0);\n digit -= 6;\n input = input.replace(ch, new Character(digit.toString().charAt(0)));\n }\n return input;\n }\n\n public void Run() {\n try {\n String superType = nextToken();\n String first = nextToken();\n String second = nextToken();\n first = doS(first);\n second = doS(second);\n if (first.charAt(1) == second.charAt(1) && Character.digit(first.charAt(0), 10) > Character.digit(second.charAt(0), 10)) {\n out.print(\"YES\");\n return;\n } else if (first.charAt(1) == superType.charAt(0)) {\n if (Character.digit(first.charAt(0), 10) >= Character.digit(second.charAt(0), 10)||second.charAt(1) != superType.charAt(0)) {\n out.print(\"YES\");\n return;\n }\n }\n out.print(\"NO\");\n } catch (Exception ex) {\n ex.printStackTrace();\n } finally {\n out.flush();\n out.close();\n }\n }\n\n\n public static void main(String[] args) {\n new Durak().Run();\n }\n\n public Durak() {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n setPriority(Thread.MAX_PRIORITY);\n }\n\n private BufferedReader in;\n private PrintWriter out;\n private StringTokenizer stringTokenizer;\n\n private int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n private double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n private long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n private String nextToken() throws IOException {\n if (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {\n stringTokenizer = new StringTokenizer(in.readLine(), \"\\t\\n\\r \");\n }\n return stringTokenizer.nextToken();\n }\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "bd1c75f466eb1a754f87343c8c2f42d5", "src_uid": "da13bd5a335c7f81c5a963b030655c26", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class D {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int a = sc.nextInt(); int b = sc.nextInt();\n M = Math.min(a, b); N = Math.max(a, b);\n if(M==1){\n System.out.println(N);\n return;\n }\n if(M==2){\n int k = N/4, ans;\n if(N==4*k) ans = 4*k;\n else if(N==4*k+1) ans = 4*k+2;\n else if(N==4*k+2) ans = 4*k+4;\n else ans = 4*k+4;\n System.out.println(ans);\n return;\n }\n System.out.println((M*N+1)/2);\n }\n \n static int M, N;\n \n}\n", "lang_cluster": "Java", "tags": ["math", "greedy", "graph matchings"], "code_uid": "e24a5c418c8c8e6f4595e603f471563b", "src_uid": "e858e7f22d91aaadd7a48a174d7b2dc9", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.awt.Polygon;\nimport java.awt.geom.Line2D;\nimport java.util.Scanner;\npublic class Squares {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\nScanner in=new Scanner(System.in);\nint x1[]=new int[4];\nint x2[]=new int[4];\nint y1[]=new int[4];\nint y2[]=new int[4];boolean t=false;\nfor(int i=0;i<4;i++)\n{\n\tx1[i]=in.nextInt();\n\ty1[i]=in.nextInt();\n}\nfor(int i=0;i<4;i++)\n{\n\tx2[i]=in.nextInt();\n\ty2[i]=in.nextInt();\n}\nPolygon P=new Polygon(x1,y1,4);\nPolygon Q=new Polygon(x2,y2,4);\nLine2D a[]=new Line2D[4];\nLine2D b[]=new Line2D[4];\n\nfor(int i=0;i<4;i++)\n{\n\ta[i]=new Line2D.Double(x1[i],y1[i],x1[(i+1)%4],y1[(i+1)%4]);\n\tb[i]=new Line2D.Double(x2[i],y2[i],x2[(i+1)%4],y2[(i+1)%4]);\n}\n\nfor(int i=0;i<4;i++)\n{\n\tfor(int j=0;j<4;j++)\n\t{\n\t\tif(a[i].intersectsLine(b[j]))\n\t\t\t{t=true;break;}\n\t}\n\tif(t)\n\t\tbreak;\n}\nif(t==false)\nfor(int i=0;i<4;i++)\n{\n\tif(P.contains(x2[i],y2[i]))\n\t{t=true;break;}\n\tif(Q.contains(x1[i],y1[i]))\n\t{t=true;break;}\n}\nif(t)\n\tSystem.out.println(\"YES\");\nelse\n\tSystem.out.println(\"NO\");\nin.close();\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["brute force"], "code_uid": "bcc080b096cf7187cfdfd03f93787d78", "src_uid": "f6a3dd8b3bab58ff66055c61ddfdf06a", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class Div215A {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\tint d=sc.nextInt();\n\t\tint[] a = new int[n];\n\t\tfor(int i=0;in){\n\t\t\tint fine = (m-n)*d;\n\t\t\tint profit =0;\n\t\t\tfor(int i=0;i 0 && b > 0) {\n if (a > b) {\n while (a > 2) {\n a = a - 2;\n b = b + 1;\n t++;\n\n }\n } else {\n while (b > 2) {\n b = b - 2;\n a = a + 1;\n t++;\n\n }\n\n }\n\n if (a <= 2 && b <= 2) {\n t++;\n break;\n }\n\n\n }\n\n System.out.println(t);\n }\n }\n\n}\n", "lang_cluster": "Java", "tags": ["math", "greedy", "dp", "implementation"], "code_uid": "ab43593b323a5b346c2ca5b5b4b4bff9", "src_uid": "ba0f9f5f0ad4786b9274c829be587961", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader Bf = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tString input = Bf.readLine();\n\t\tStringTokenizer str = new StringTokenizer(input, \" \");\n\t\tint n = Integer.parseInt(str.nextToken());\n\t\tint m = Integer.parseInt(str.nextToken());\n\t\tint[] x = new int[m];\n\t\tinput = Bf.readLine();\n\t\tstr = new StringTokenizer(input, \" \");\n\t\tfor (int i = 0; i < m; i++)\n\t\t\tx[i] = Integer.parseInt(str.nextToken());\n\n\t\tArrays.sort(x);\n\t\tint min = 100000000;\n\t\tfor (int i = 0; i < m - n +1 ; i++) {\n\t\t\tmin = Math.min(min, x[i + n -1 ] - x[i]);\n\n\t\t}\n\n\t\tout.println(min);\n\t\tout.flush();\n\t}\n}", "lang_cluster": "Java", "tags": ["greedy"], "code_uid": "fa008cd0f460dbc99179d83ad5966b5d", "src_uid": "7830aabb0663e645d54004063746e47f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class ttt {\n\n\tstatic boolean checkWin(char[][] chess, char s) {\n\t\tfor (int i = 0; i < 3; i++)\n\t\t\tif (s == chess[i][0] && s == chess[i][1] && s == chess[i][2])\n\t\t\t\treturn true;\n\t\tfor (int j = 0; j < 3; j++)\n\t\t\tif (s == chess[0][j] && s == chess[1][j] && s == chess[2][j])\n\t\t\t\treturn true;\n\t\tif (s == chess[0][0] && s == chess[1][1] && s == chess[2][2])\n\t\t\treturn true;\n\t\tif (s == chess[0][2] && s == chess[1][1] && s == chess[2][0])\n\t\t\treturn true;\n\t\treturn false;\n\t}\n\n\tstatic String solve(char[][] chess, int x, int o) {\n\t\tif (x < o || x > o + 1)\n\t\t\treturn \"illegal\";\n\t\tboolean xw = checkWin(chess, 'X');\n\t\tboolean ow = checkWin(chess, '0');\n\t\tif (xw && ow || xw && x == o || ow && x > o)\n\t\t\treturn \"illegal\";\n\t\tif (xw)\n\t\t\treturn \"the first player won\";\n\t\tif (ow)\n\t\t\treturn \"the second player won\";\n\t\tif (x + o == 9)\n\t\t\treturn \"draw\";\n\t\tif (x == o)\n\t\t\treturn \"first\";\n\t\tif (x > o)\n\t\t\treturn \"second\";\n\t\treturn \"illegal\";\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tchar[][] chess = new char[3][3];\n\t\tint x = 0;\n\t\tint o = 0;\n\t\tfor (int i = 0; i < 3; i++) {\n\t\t\tString line = in.nextLine();\n\t\t\tchess[i] = line.toCharArray();\n\t\t\tfor (int j = 0; j < 3; j++)\n\t\t\t\tif (chess[i][j] == 'X')\n\t\t\t\t\tx++;\n\t\t\t\telse if (chess[i][j] == '0')\n\t\t\t\t\to++;\n\t\t}\n\t\tout.println(solve(chess, x, o));\n\t\tout.close();\n\t\tin.close();\n\t}\n}\n", "lang_cluster": "Java", "tags": ["brute force", "implementation", "games"], "code_uid": "4c58bc0860410bf5b8499ac3eb5f16e6", "src_uid": "892680e26369325fb00d15543a96192c", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class number {\n private BufferedReader br;\n private StringTokenizer st;\n\n public number()\n {\n br=new BufferedReader(new InputStreamReader(System.in));\n\n }\n public String read() throws IOException {\n while(st==null || !st.hasMoreElements()){\n st=new StringTokenizer(br.readLine());\n }\n return st.nextToken();\n }\n\n public int intParse() throws IOException {\n return Integer.parseInt(read()) ;\n }\n public String stringParse() throws IOException {\n return String.valueOf(read());\n }\n public static void main(String[] args) throws IOException {\n number n=new number();\n String digit=n.stringParse();\n StringBuilder s=new StringBuilder();\n for(int a=0; a0)\n\t\t{\n\t\t n=n/2;\n\t\t arr[2]+=1;\n\t\t}\n\t\tfor(int i=3;i<=(int)Math.sqrt((double)dup);i+=2)\n\t\t{\n\t\t while((n%i==0)&&n>0)\n\t\t {\n\t\t n=n/i;\n\t\t arr[i]+=1;\n\t\t }\n\t\t}\n\t\t//System.out.println(\" Value n\"+n);\n\t\tif(n!=1)\n\t\t{\n\t\t arr[n]+=1;\n\t\t}\n\t\tfor(int m=1;m=max)\n\t\t {\n\t\t max=arr[k];\n\t\t }\n\t\t } \n\t\t}\n\tif(max>1)\n\t{\n\t\n\t//\tSystem.out.println(\" Value max\"+flag);\n\t\tif(flag==0)\n\t\t{\n\t\t while(max%2==0)\n {\n max=max/2;\n count+=1;\n }\n if(max==1)\n {\n ans=count;\n }\n else\n {\n while(max!=0)\n {\n max=max/2;\n count+=1;\n }\n ans=count+1;\n }\n\t\t}\n\t\telse\n\t\t{\n while(max%2==0)\n {\n max=max/2;\n count+=1;\n }\n if(max==1)\n {\n ans=count+1;\n }\n else\n {\n while(max!=0)\n {\n max=max/2;\n count+=1;\n }\n ans=count+1;\n }\n //System.out.println(\"Ans \"+ans);\n\t\t}\n\t\t\n\t\tSystem.out.println(small+\" \"+ans);\n\t}\n\telse\n\t{\n\t \n\t System.out.println(dup+\" \"+0); \n\t \n\t \n\t}\n\t\t\n\t\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "greedy", "number theory"], "code_uid": "10c9329d72f22305df8713798985e47d", "src_uid": "212cda3d9d611cd45332bb10b80f0b56", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n/**\n * \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd 2016/11/20 21:45\n */\npublic class ContestA {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int length=Integer.parseInt(in.nextLine());\n String line = in.nextLine();\n\n String origin = line;\n\n origin = replaceSameStrs(origin, \"ogo\", \"go\",\"***\");\n System.out.println(origin);\n }\n\n private static String replaceSameStrs(String origin, String s2, String s3,String replace) {\n int count=1;\n for (int i = 0; i < origin.length(); i++) {\n int index = origin.indexOf(s2);\n if (index == -1) {\n break;\n }\n String findStr = appendCountN(s2,s3,count);\n int index2 = origin.indexOf(findStr, index);\n //\ufffd\ufffd\ufffdogo\ufffd\ufffd\ufffd\ufffd\u00fb\ufffd\ufffdgo\ufffd\u02e3\ufffd\ufffd\ufffd\u00f4\ufffd\u0475\ufffd\u04bb\ufffd\ufffdogo\ufffd\u6efb\ufffd\ufffd***\n if (index != index2) {\n int start = index;\n int end = index + ((s2.length()-1) + 2*(count-1));\n origin = replaceByLocation(origin,replace,start,end);\n count=1;\n }else {\n count++;\n }\n }\n return origin;\n }\n\n /**\n * \ufffd\ufffdorigin\ufffd\u05b7\ufffd\ufffd\ufffd\ufffd\ufffd[start,end]\ufffd\ufffd\ufffd\ufffd\ufffd\u05b7\ufffd\ufffd\u6efb\ufffd\ufffdreplace\ufffd\u05b7\ufffd\n * @param origin\n * @param replace\n * @param start\n * @param end\n * @return\n */\n public static String replaceByLocation(String origin, String replace, int start, int end) {\n char[] originChars = origin.toCharArray();\n char[] replaceChars= replace.toCharArray();\n for (int i = start;i<=end;i++) {\n if (i - start > replaceChars.length-1) {\n originChars[i]=' ';\n } else {\n originChars[i] = replaceChars[i-start];\n }\n }\n StringBuffer sb = new StringBuffer();\n for (char c : originChars) {\n if (c != ' ') {\n sb.append(c);\n }\n }\n return new String(sb);\n }\n\n public static String appendCountN(String origin, String append,int count) {\n StringBuffer sb = new StringBuffer(origin);\n for (int i = 0; i < count; i++) {\n sb.append(append);\n }\n return new String(sb);\n }\n}\n", "lang_cluster": "Java", "tags": ["strings", "implementation"], "code_uid": "2a3aa534b8e7d73ce72d7ffdde241cb9", "src_uid": "619665bed79ecf77b083251fe6fe7eb3", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\npublic class A {\n\n\t\tpublic static void main(String args[])\n\t\t{\n\t\t\tScanner scan=new Scanner(System.in);\n\t\t\tint n=scan.nextInt();\n\t\t\tString g=scan.next();\n\t\t\tint counter=0;\n\t\t\t\n\t\t\tfor(int i=0;i=n){\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tSystem.out.print(g.charAt(i));\n\t\t\t\ti+=counter;\n\t\t\t\tcounter++;\n\t\t\t}\n\t\t}\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "24e4d9c1913be4cc26dcad45d6df593b", "src_uid": "08e8c0c37b223f6aae01d5609facdeaf", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class Main {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve() {\n\t\tString s = ns();\n\t\tint n = Integer.parseInt(s, 16);\n\t\tout.println(n%2);\n\t}\n\t\t\t\t\n\tvoid run() throws Exception {\n\t\tis = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\tif (!INPUT.isEmpty())\n\t\t\ttr(System.currentTimeMillis() - s + \"ms\");\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew Main().run();\n\t}\n\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\n\tprivate int readByte() {\n\t\tif (lenbuf == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (ptrbuf >= lenbuf) {\n\t\t\tptrbuf = 0;\n\t\t\ttry {\n\t\t\t\tlenbuf = is.read(inbuf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (lenbuf <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\n\tprivate boolean isSpaceChar(int c) {\n\t\treturn !(c >= 33 && c <= 126);\n\t}\n\n\tprivate int skip() {\n\t\tint b;\n\t\twhile ((b = readByte()) != -1 && isSpaceChar(b))\n\t\t\t;\n\t\treturn b;\n\t}\n\n\tprivate double nd() {\n\t\treturn Double.parseDouble(ns());\n\t}\n\n\tprivate char nc() {\n\t\treturn (char) skip();\n\t}\n\n\tprivate String ns() {\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tprivate char[] ns(int n) {\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile (p < n && !(isSpaceChar(b))) {\n\t\t\tbuf[p++] = (char) b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\n\tprivate char[][] nm(int n, int m) {\n\t\tchar[][] map = new char[n][];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tmap[i] = ns(m);\n\t\treturn map;\n\t}\n\n\tprivate int[] na(int n) {\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = ni();\n\t\treturn a;\n\t}\n\n\tprivate int ni() {\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t;\n\t\tif (b == '-') {\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\n\tprivate long nl() {\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t;\n\t\tif (b == '-') {\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\n\tprivate static void tr(Object... o) {\n\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "dd5c4b41d592bc927aebff9c5a92f645", "src_uid": "e52bc741bb72bb8e79cf392b2d15354f", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class test3 {\n \n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n long n = input.nextLong(); \n if(check(n) == 7 || check(n) == 4)\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n } \n public static int check(long n){\n int digits = 0;\n String m = Long.toString(n);\n for(int i = 0; i < m.length(); i++){ \n if(n % 10 == 4 || n % 10 == 7){ \n digits++;\n } \n n = n / 10; \n }\n return digits; \n }\n \n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "4f157eb29befb1b8cb5aea9f5e2cb880", "src_uid": "33b73fd9e7f19894ea08e98b790d07f1", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\n/**\n * @auther chao\n * @date 15/12/30\n */\npublic class A {\n public static void main(String[] args) throws IOException {\n Scanner in = new Scanner(System.in);\n int[][] a = new int[2][3];\n for (int i = 0; i < 2; i++) {\n for (int j = 0; j < 3; j++) a[i][j] = in.nextInt();\n }\n int ans = 0;\n for (int i = 0; i < 3; i++) {\n if (a[0][i] - a[1][i] >= 0) ans += (a[0][i] - a[1][i]) / 2;\n else ans += a[0][i] - a[1][i];\n }\n if (ans >= 0) System.out.println(\"YES\");\n else System.out.println(\"NO\");\n\n }\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "0d9f22ac8242d152705b3e0170a82b54", "src_uid": "1db4ba9dc1000e26532bb73336cf12c3", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.text.*;\npublic class cf1 {\n static long mod = (long)1e9 + 7;\n static long mod1 = 998244353;\n static FastScanner f;\n static PrintWriter pw = new PrintWriter(System.out);\n static Scanner S = new Scanner(System.in);\n static long x0; static long y0;\n static int inf = (int)(1e9);\n static long iinf = (long)(1e18);\n static void solve()throws IOException {\n long a = f.nl(); long b = f.nl(); long x = f.nl(); long y = f.nl();\n long g = gcd(x , y);\n x /= g; y /= g;\n a = Math.min(a / x , b / y);\n pn(x * a + \" \" + y * a);\n }\n public static void main(String[] args)throws IOException {\n init();\n int t = 1;\n while(t --> 0) {solve();}\n pw.flush(); \n pw.close(); \n }\n \n/******************************END OF MAIN PROGRAM*******************************************/\n public static void init()throws IOException{if(System.getProperty(\"ONLINE_JUDGE\")==null){f=new FastScanner(\"\");}else{f=new FastScanner(System.in);}}\n public static class FastScanner {\n BufferedReader br;StringTokenizer st;\n FastScanner(InputStream stream){try{br=new BufferedReader(new InputStreamReader(stream));}catch(Exception e){e.printStackTrace();}}\n FastScanner(String str){try{br=new BufferedReader(new FileReader(\"!a.txt\"));}catch(Exception e){e.printStackTrace();}}\n String next(){while(st==null||!st.hasMoreTokens()){try{st=new StringTokenizer(br.readLine());}catch(IOException e){e.printStackTrace();}}return st.nextToken();}\n String nextLine()throws IOException{return br.readLine();}int ni(){return Integer.parseInt(next());}long nl(){return Long.parseLong(next());}double nextDouble(){return Double.parseDouble(next());}\n }\n public static void pn(Object o){pw.println(o);}\n public static void p(Object o){pw.print(o);}\n public static void pni(Object o){pw.println(o);pw.flush();}\n static int gcd(int a,int b){if(b==0)return a;else{return gcd(b,a%b);}}\n static long gcd(long a,long b){if(b==0l)return a;else{return gcd(b,a%b);}}\n static long lcm(long a,long b){return (a*b/gcd(a,b));}\n static long exgcd(long a,long b){if(b==0){x0=1;y0=0;return a;}long temp=exgcd(b,a%b);long t=x0;x0=y0;y0=t-a/b*y0;return temp;}\n static long pow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=res*a;b>>=1;a=a*a;}return res;}\n static long mpow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=((res%mod)*(a%mod))%mod;b>>=1;a=((a%mod)*(a%mod))%mod;}return res;}\n static long mul(long a , long b){return ((a%mod)*(b%mod)%mod);}\n static long adp(long a , long b){return ((a%mod)+(b%mod)%mod);}\n 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(long i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}\n 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;}\n static HashSet factors(long n){HashSet hs=new HashSet();for(long i=1;i<=(long)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}\n static HashSet factors(int n){HashSet hs=new HashSet();for(int i=1;i<=(int)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}\n static HashSet pf(long n){HashSet ff=factors(n);HashSet ans=new HashSet();for(Long i:ff)if(isPrime(i))ans.add(i);return ans;}\n static HashSet pf(int n){HashSet ff=factors(n);HashSet ans=new HashSet();for(Integer i:ff)if(isPrime(i))ans.add(i);return ans;}\n static int[] inpint(int n){int arr[]=new int[n];for(int i=0;i l=new ArrayList<>();for(int i:a)l.add(i);Collections.sort(l);for(int i=0;i l=new ArrayList<>();for(long i:a)l.add(i);Collections.sort(l);for(int i=0;i a){Collections.sort(a);}//!Precompute fact in ncr()!\n}", "lang_cluster": "Java", "tags": ["binary search", "number theory"], "code_uid": "60ce6361cdd936212759f3d37b12e4f7", "src_uid": "97999cd7c6de79a4e39f56a41ff59e7a", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n Scanner S=new Scanner(System.in);\n int m=S.nextInt();\n int s=S.nextInt();\n int v;\n int t;\n int i;\n int mas1[]=new int[m];\n int mas2[]=new int[m];\n mas1[0]=1;\n v=s-1;\n if (v>=0) {\n t=v/9;\n v%=9;\n for (i=m-1;i>0&&t>0;i--,t--) mas1[i]=9;\n mas1[i]+=v;\n if (mas1[0]>9||t>0) System.out.print(\"-1 \");\n else {\n for (i=0;i0||s/9>m) {\n System.out.println(\"-1\");\n return;\n }\n if (mas2[0]==0) {\n System.out.println(\"-1\");\n return;\n }\n for (i=0;i month[m]){\n\t\td = 1;\n\t\tm++;\n\t\tif (m > 11){\n\t\t m = 0;\n\t\t y++;\n\t\t}\n\t }\n\t r++;\n\t}\n\tout.println(r);\n\tout.close();\n }\n\n private boolean compare(String d1, String d2){\n\tString a[] = d1.split(\":\");\n\tString b[] = d2.split(\":\");\n\tfor(int i=0;i Integer.parseInt(b[i]))\n\t\treturn true;\n\t else if (Integer.parseInt(a[i]) < Integer.parseInt(b[i]))\n\t\treturn false;\n\t}\n\treturn false;\n }\n\n private boolean isLeapYear(int year){\n\treturn year%4 == 0 && year%100!=0 || year%400==0;\n\t/*\n\tif (year % 4 != 0)\n\t return false;\n\tif (year % 400 == 0)\n\t return true;\n\tif (year % 100 == 0)\n\t return false;\n\treturn true;\n\t*/\n }\n\n public static void main(String args[]) throws Exception{\n\t new Main().run();\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "d617f578b3733bfe2dee6a71f2ab281c", "src_uid": "bdf99d78dc291758fa09ec133fff1e9c", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class task2 {\n public static void main(String[] args){\n Scanner in = new Scanner(System.in);\n\t\tString s = in.nextLine();\n\t\tStringBuilder sb = new StringBuilder();\n\t\tsb.append(s);\n\t\tint k = in.nextInt();\n\t\tfor (int i=0;i max) max = t;\n\t\t\t}\n\t\t}\n\t\tt = isTandemRepeat(s.substring(n-1,n-1));\n\t\tif (t > max) max = t;\n\t\tSystem.out.println(max);\n\t}\n\tpublic static int isTandemRepeat(String s){\n\t\tif (s.length() % 2 == 1) return -1;\n\t\tint length = 0, n = s.length()/2;\n\t\tfor (int i=0;iluck=new ArrayList<>();\n\tstatic long big=1000000007;\n\tpublic static void pushLuck(long num) {\n\t\tif(num>big)\n\t\t\treturn;\n\t\tif(num!=0)\n\t\t\tluck.add(num);\n\t\t\n\t\tpushLuck(num*10+4);\n\t\tpushLuck(num*10+7);\n\t\t\n\t\t\n\t\t\n\t}\n\t\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner in =new Scanner(System.in);\n\t\n\t\tlong n =in.nextInt();\n\t\tpushLuck(0);\n\t\tCollections.sort(luck);\n\t\t\n\t\tSystem.out.println(luck.indexOf(n)+1);\n\t\t\n\n\t\t\n\t\t\n\t\t\n\t\n}}\n", "lang_cluster": "Java", "tags": ["brute force", "implementation", "combinatorics", "bitmasks"], "code_uid": "1786b39fab93d8b58f93dc2aa13dedd3", "src_uid": "6a10bfe8b3da9c11167e136b3c6fb2a3", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import static java.lang.Math.abs;\nimport java.util.Scanner;\npublic class ProblemSolving {\n\n public static void main(String[] args) {\n \n Scanner sc = new Scanner(System.in);\n \n String s = sc.next();\n int sum=0;\n int start=97;\n for (int i =0;i13)\n {\n sum = sum + abs(abs((int)s.charAt(i)-start)-26);\n start=s.charAt(i);\n }\n \n }\n \n System.out.println(sum);\n }\n}", "lang_cluster": "Java", "tags": ["strings", "implementation"], "code_uid": "567014fceb26bf6ae2a3b56d83c9ce91", "src_uid": "ecc890b3bdb9456441a2a265c60722dd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n d899 solver = new d899();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class d899 {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int max = 2 * n - 1;\n int digitCount = 0;\n int nineCount = 0;\n while (max > 0) {\n if (max % 10 == 9) nineCount++;\n digitCount++;\n max /= 10;\n }\n if (digitCount == nineCount) {\n out.println(1);\n return;\n }\n max = 2 * n - 1;\n long posMax = 0;\n long firstDigit = 1;\n for (int i = 1; i < digitCount; i++) {\n posMax *= 10;\n posMax += 9;\n firstDigit *= 10;\n }\n long ans = 0;\n for (int i = 0; i < 10; i++) {\n long first = posMax - n;\n if (first >= n) break;\n if (first < 1) first = 1;\n long last = posMax - first;\n ans += (last - first + 1) / 2;\n posMax += firstDigit;\n }\n out.println(ans);\n }\n\n }\n\n static class InputReader {\n private BufferedReader reader;\n private StringTokenizer stt;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n }\n\n public String nextLine() {\n try {\n return reader.readLine();\n } catch (IOException e) {\n return null;\n }\n }\n\n public String next() {\n while (stt == null || !stt.hasMoreTokens()) {\n stt = new StringTokenizer(nextLine());\n }\n return stt.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["math", "constructive algorithms"], "code_uid": "2b2c8c40894be25fc94bee84db7dcd26", "src_uid": "c20744c44269ae0779c5f549afd2e3f2", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Main{\n public static void main(String [] args){\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int a = sc.nextInt();\n int b = sc.nextInt();\n int start = a+1;\n int end = n;\n while(n-start>b){\n start++;\n }\n System.out.println(n - start+1);\n }\n}", "lang_cluster": "Java", "tags": ["math"], "code_uid": "6803f25733da8f7ead839c2e772244d2", "src_uid": "51a072916bff600922a77da0c4582180", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class jump {\n\tpublic static void main(String args[]) throws Exception {\n\t\tScanner in;\n\t\ttry {\n\t\t\tin = new Scanner(new File(\"inputcool.txt\"));\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tin = new Scanner(System.in);\n\t\t}\n\t\tString str = in.nextLine();\n\t\tboolean hi = false;\n\t\tfor (int i = 0; i < str.length(); i++) {\n\t\t\tif (str.charAt(i) == 'H' || str.charAt(i) == 'Q' || str.charAt(i) == '9') {\n\t\t\t\thi = true;\n\t\t\t}\n\t\t}\n\t\tif (!hi) System.out.println(\"NO\");\n\t\telse System.out.println(\"YES\");\n\t}\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "8c63e571a719a4f7e65c13feb8dd956c", "src_uid": "1baf894c1c7d5aeea01129c7900d3c12", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class Main\n{\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint a[] = new int[3];\n\t\tfor(int i = 0; i< 3; i++){\n\t\t a[i] = sc.nextInt();\n\t\t}\n\t\tArrays.sort(a);\n\t\tSystem.out.println((a[1]-a[0]) + (a[2]-a[1]));\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "sortings", "implementation"], "code_uid": "87b5c7bbe542a6dc9451a16e1841f8ce", "src_uid": "7bffa6e8d2d21bbb3b7f4aec109b3319", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\npublic class Main {\npublic static void main(String args[])\n{\n\tScanner in=new Scanner(System.in);\n int n;\n double t1;\n int sum=0;\n n=in.nextInt();\n for(int i=1;i<=n;i++)\n {\n\t for(int y=i+1;y<=n;y++)\n\t {\n\t\tt1=(i*i)+(y*y);\n\t\t t1= Math.sqrt(t1);\n\t\t if(t1==(int)t1)\n\t\t {\n\t\tif(t1<=(n)&&t1>=(i)&&t1>=(y))\n\t sum++;\n\t\t }\n\t\t \n\t }\n }\n System.out.println(sum);\n}\n}\n", "lang_cluster": "Java", "tags": ["brute force", "math"], "code_uid": "e38b107ac389df94803112e857ea0df6", "src_uid": "36a211f7814e77339eb81dc132e115e1", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class onceagain {\n private static InputReader in;\n private static PrintWriter out;\n\n public static void main(String[] args) throws IOException {\n in = new InputReader(System.in);\n out = new PrintWriter(System.out, true);\n int n = in.nextInt(), k = in.nextInt();\n int[] arr = new int[n];\n for (int i = 0; i < n; i++) arr[i] = in.nextInt();\n \n \n int m = 301;\n int[][] mat = new int[m+1][m+1];\n for (int i = 0; i < n; i++) {\n int[][] next = new int[m+1][m+1];\n for (int j = 0; j <= m; j++) System.arraycopy(mat[j], 0, next[j], 0, m+1);\n for (int last = 0; last <= arr[i]; last++) {\n for (int first = 0; first <= last; first++) {\n next[first][arr[i]] = Math.max(next[first][arr[i]], mat[first][last] + 1);\n }\n }\n mat = next;\n }\n \n mat = mat_exp(mat, k);\n int ret = 0;\n for (int i = 0; i <= m; i++) for (int j = 0; j <= m; j++)\n ret = Math.max(ret, mat[i][j]);\n \n out.println(ret);\n out.close();\n System.exit(0);\n \n }\n \n private static int[][] mat_exp(int[][] A, int e) {\n if (e == 1)\n return A;\n else if (e % 2 == 0) {\n int[][] A1 = mat_exp(A, e / 2);\n return matrix_mult(A1, A1);\n } else\n return matrix_mult(A, mat_exp(A, e - 1));\n }\n\n private static int[][] matrix_mult(int[][] A, int[][] B) {\n int[][] C = new int[A.length][A.length];\n for (int i = 0; i < A.length; i++)\n for (int j = i; j < A.length; j++)\n for (int k = j; k < A.length; k++) {\n if (A[i][j] == 0 || B[j][k] == 0) continue;\n C[i][k] = Math.max(C[i][k], A[i][j] + B[j][k]);\n }\n return C;\n }\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n\n\n}\n", "lang_cluster": "Java", "tags": ["matrices", "dp", "constructive algorithms"], "code_uid": "13785f8d59b443b44a5048fd9d82c0db", "src_uid": "26cf484fa4cb3dc2ab09adce7a3fc9b2", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.*;\npublic class Main\n{\n\tpublic static boolean isnumberlucky(long x)\n\t{\n\t\tif(x<0)\n\t\t\tx*=-1;\n\t\tfor( ; x>0 && x%10!=8; x/=10);\n\t\tif(x==0)\n\t\t\treturn false;\n\t\treturn true;\n\t} \n\tpublic static void main(String []args)\n\t{\n\t\tlong a;\n\t\tshort ans=1;\n\t\tScanner in=new Scanner(System.in);\n\t\ta=in.nextLong();\n\t\t++a;\n\t\twhile(!(isnumberlucky(a)))\n\t\t{\n\t\t\tans++;\n\t\t\ta++;\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}", "lang_cluster": "Java", "tags": ["brute force"], "code_uid": "5ba7009bba6b38e9e80245d1b5d3fbea", "src_uid": "4e57740be015963c190e0bfe1ab74cb9", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class con169_D {\n\n\tprivate static final boolean DEBUG = false;\n\n\tpublic static void main( final String[] args ) throws Exception {\n\t\tfinal BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) );\n\t\tfinal String line = br.readLine();\n\t\tfinal StringTokenizer tok = new StringTokenizer( line );\n\n\t\tfinal long L = Long.parseLong( tok.nextToken() );\n\t\tfinal long R = Long.parseLong( tok.nextToken() );\n\n\t\tSystem.out.println( solve( L, R ) );\n\t}\n\n\tpublic static long solve( final long L, final long R ) {\n\t\tif ( L == R ) return L ^ R;\n\t\tif ( DEBUG ) System.out.printf( \"L=%d (%s), R=%d (%s)\\n\", L, Long.toBinaryString( L ), R,\n\t\t\t\tLong.toBinaryString( R ) );\n\n\t\tfinal int ld = length( L );\n\t\tfinal int ldm1 = ld - 1;\n\t\tfinal int rd = length( R );\n\n\t\tif ( ld < rd ) {\n\t\t\tlong max = 1;\n\t\t\twhile ( length( max ) < rd ) {\n\t\t\t\tmax <<= 1;\n\t\t\t}\n\t\t\tlong min = 1;\n\t\t\twhile ( length( min ) < rd - 1 ) {\n\t\t\t\tmin <<= 1;\n\t\t\t\t++min;\n\t\t\t}\n\t\t\tif ( DEBUG ) System.out.printf( \"min=%d (%s), max=%d (%s)\\n\", min, Long.toBinaryString( min ), max,\n\t\t\t\t\t\tLong.toBinaryString( max ) );\n\t\t\treturn min ^ max;\n\t\t} else {\n\t\t\tfinal char[] minStr = Long.toBinaryString( L ).toCharArray();\n\t\t\tfinal char[] maxStr = Long.toBinaryString( R ).toCharArray();\n\t\t\tfinal char[] res = new char[minStr.length];\n\t\t\tArrays.fill( res, '0' );\n\t\t\t{\n\t\t\t\tint i = 0;\n\t\t\t\twhile ( i < res.length ) {\n\t\t\t\t\tif ( minStr[ i ] == maxStr[ i ] ) {\n\t\t\t\t\t\tres[ i ] = '0';\n\t\t\t\t\t} else {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\t++i;\n\t\t\t\t}\n\t\t\t\tif ( DEBUG ) System.out.println( \"diff at pos: \" + i );\n\t\t\t\tif ( minStr[ i ] == '0' ) {\n\t\t\t\t\tres[ i++ ] = '1';\n\t\t\t\t\tfor ( int j = i; j < res.length; ++j ) {\n\t\t\t\t\t\tres[ j ] = '1';\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tthrow new IllegalArgumentException();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn Long.parseLong( new String( res ), 2 );\n\t\t}\n\t}\n\n\tprivate static int length( long l ) {\n\t\tint res = 0;\n\t\twhile ( l > 0 ) {\n\t\t\t++res;\n\t\t\tl >>= 1;\n\t\t}\n\t\treturn res;\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["math", "dp", "bitmasks", "greedy", "implementation"], "code_uid": "25b9a8e8f2a16f84a01e34f015ca437e", "src_uid": "d90e99d539b16590c17328d79a5921e0", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author MohammedBasioni\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n Scanner in = new Scanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n ACarrotCakes solver = new ACarrotCakes();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class ACarrotCakes {\n public void solve(int testNumber, Scanner sc, PrintWriter pw) {\n int n = sc.nextInt();\n int t = sc.nextInt();\n int k = sc.nextInt();\n int d = sc.nextInt();\n\n long[] before = new long[1000001];\n long[] after = new long[1000001];\n long t1 = 0;\n long t2 = 0;\n long c = 0;\n for (int i = 1; i < before.length; i++) {\n if (i % t == 0) {\n before[i] = k + c;\n c = before[i];\n }\n if (before[i] >= n) {\n t1 = i;\n break;\n }\n }\n c = 0;\n for (int i = 1; i < before.length; i++) {\n if (i % t == 0) {\n after[i] += k + c;\n c = after[i];\n }\n if (i > d && (i - d) % t == 0) {\n after[i] += k + c;\n c = after[i];\n }\n if (after[i] >= n) {\n t2 = i;\n break;\n }\n }\n //pw.println(Arrays.toString(before));\n //pw.println(Arrays.toString(after));\n //pw.println(t1 + \" \"+t2);\n pw.println(t1 <= t2 ? \"NO\" : \"YES\");\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "8b5c14a289927c0e693e243951b3cd1e", "src_uid": "32c866d3d394e269724b4930df5e4407", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int []ar = in.primitiveIntArray(0,6);\n BigInteger start = BigInteger.valueOf((long) 1e9);\n int g = 2;\n String []s = new String[]{\"Hermione\",\"Ron\"};\n if (ar[2] == 0 && ar[3] != 0){\n out.print(s[1]);return;\n }\n if (ar[0] == 0 && ar[1] != 0 && ar[3] != 0){\n out.print(s[1]);return;\n }\n if (ar[1] == 0 || ar[3] == 0 || ar[5] == 0){\n out.print(s[0]);return;\n }\n if (ar[4] == 0){\n out.print(s[1]);return;\n }\n BigInteger tk = BigInteger.ONE;\n for (int i = 0; i < 10000; i++) {\n for (int j = 0; j < 5; j+= 2) {\n BigInteger val = start.divideAndRemainder(BigInteger.valueOf((ar[j] == 0?1:ar[j])))[0];\n start = val.multiply(BigInteger.valueOf(ar[j + 1]));\n }\n if (i == 0)\n tk = start;\n if (start.compareTo(tk) <= 0 && i > 3){\n out.print(s[0]+\"\\n\");return;\n }\n }\n out.print(s[1]);\n }\n}\n\nclass InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int[] primitiveIntArray(int startIndex,int size){\n if (startIndex == 1)size++;\n int []array = new int[size];\n for (int i = startIndex; i < size; i++) {\n array[i] = Integer.parseInt(next());\n }\n return array;\n }\n\n\n}\n\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "dfbac4aba95cf5bf033514c7d0d483bc", "src_uid": "44d608de3e1447f89070e707ba550150", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Slonik {\n\n public static void main(String[] args){\n Scanner scan = new Scanner(System.in);\n int input = scan.nextInt();\n\n float min = input / 5f;\n System.out.println((int)Math.ceil(min));\n }\n }\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "ea7eac3a4882f97c3f41c4599a642d9c", "src_uid": "4b3d65b1b593829e92c852be213922b6", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n\npublic class CF568C {\n\n\tpublic static void main(String[] args) \tthrows Exception {\n\t\tboolean[] primos = new boolean[2000000];\n\t\tint[] primosC = new int[2000000];\n\t\tint[] palC = new int[2000000];\n\t\tprimos[0]=primos[1]=true;\n\t\tpalC[1]=1;\n\t\tfor(int i=2;i \n{ \n // Used for sorting in ascending order of \n // roll number \n public int compare(Student c, Student b) \n { \n if(c.xb.x)\n return 1;\n return c.y-b.y;\n } \n} \nstatic class FastReader \n { \n BufferedReader br; \n StringTokenizer st; \n \n public FastReader() \n { \n br = new BufferedReader(new\n InputStreamReader(System.in)); \n } \n \n String next() \n { \n while (st == null || !st.hasMoreElements()) \n { \n try\n { \n st = new StringTokenizer(br.readLine()); \n } \n catch (IOException e) \n { \n e.printStackTrace(); \n } \n } \n return st.nextToken(); \n } \n \n int nextInt() \n { \n return Integer.parseInt(next()); \n } \n \n long nextLong() \n { \n return Long.parseLong(next()); \n } \n \n double nextDouble() \n { \n return Double.parseDouble(next()); \n } \n \n String nextLine() \n { \n String str = \"\"; \n try\n { \n str = br.readLine(); \n } \n catch (IOException e) \n { \n e.printStackTrace(); \n } \n return str; \n } \n } \n \n static class Edge{\n int a,b;\n Edge(int a,int b){\n this.a=a;\n this.b=b;\n }\n }\n static class Trie{\n HashMapmap;\n int c;\n Trie(){\n map=new HashMap<>();\n //z=null;\n //o=null;\n c=0;\n }\n }\n //static long ans;\n static int parent[];\n static int rank[];\n static int b[][];\n static int bo[];\n static int ho[];\n static int seg[];\n //static int pos;\n // static long mod=1000000007;\n //static int dp[][];\n static HashMapmap;\n static PriorityQueueq=new PriorityQueue<>();\n //static Stackst;\n // static ArrayListans;\n static ArrayList>adj;\n static long ans;\n static Trie root;\n static long fac[];\n static long mod=(long)(1000000007);\n //static int ans;\n static void solve()throws IOException{\n FastReader sc=new FastReader();\n int s,s2,x1,x2,t1,t2,p,d,a1,a2;\n s=sc.nextInt();\n x1=sc.nextInt();\n x2=sc.nextInt();\n t1=sc.nextInt();\n t2=sc.nextInt();\n p=sc.nextInt();\n d=sc.nextInt();\n a1=(int)(Math.abs(x1-x2))*t2;\n if(d==1){\n if(x2>x1){\n if(p<=x1)\n a2=(x2-p)*t1;\n else{\n a2=(s-p)*t1+s*t1+x2*t1;\n }\n }\n else{\n a2=(s-p)*t1+(s-x2)*t1;\n }\n }\n else{\n if(x2>x1){\n a2=p*t1+x2*t1;\n }\n else{\n if(p>=x1)\n a2=(p-x2)*t1;\n else\n a2=p*t1+s*t1+(s-x2)*t1;\n }\n }\n System.out.println(Math.min(a1,a2));\n }\n static void build(StringBuilder sb,int n,char a){\n if(n==0)\n {\n sb.append(a);\n return;\n }\n int x=(int)Math.sqrt(2*n);\n if(x*(x+1)>2*n)\n x-=1;\n for(int i=0;i<=x;i++)\n sb.append(a);\n n-=(x*(x+1))/2;\n build(sb,n,(char)((int)a+1));\n }\n static void dfs(Trie root,int k){\n if(root==null)\n return;\n for(char i='A';i<='Z';i++){\n if(root.map.containsKey(i)){\n ans+=root.map.get(i).c/k;\n dfs(root.map.get(i),k);\n }\n }\n }\n static long nCr(long n, long r, \n long p) \n { \n return (fac[(int)n]* modInverse(fac[(int)r], p) \n % p * modInverse(fac[(int)(n-r)], p) \n % p) % p; \n } \n //static int prime[];\n //static int dp[];\n public static void main(String[] args){\n //long sum=0;\n try {\n codeforces.solve();\n } catch (Exception e) {\n e.printStackTrace();\n }\n }\n static long modInverse(long n, long p) \n { \n return power(n, p-(long)2,p); \n } \n static long power(long x, long y, long p) \n{ \n long res = 1; // Initialize result \n \n x = x % p; // Update x if it is more than or \n // equal to p \n \n while (y > 0) \n { \n // If y is odd, multiply x with result \n if (y %(long)2!=0) \n res = (res*x) % p; \n \n // y must be even now \n y = y>>1; // y = y/2 \n x = (x*x) % p; \n } \n return res%p;\n }\n /*public static long power(long x,long a) {\n\t\tif(a==0) return 1;\n\t\tif(a%2==1)return (x*1L*power(x,a-1))%mod;\n\t\treturn (power((int)((x*1L*x)%mod),a/2))%mod;\n\t}*/\n static int find(int x) \n { \n // Finds the representative of the set \n // that x is an element of \n while(parent[x]!=x) \n { \n // if x is not the parent of itself \n // Then x is not the representative of \n // his set,\n x=parent[x];\n \n // so we recursively call Find on its parent \n // and move i's node directly under the \n // representative of this set \n } \n \n return x; \n }\n static void union(int x, int y) \n { \n // Find representatives of two sets \n int xRoot = find(x), yRoot = find(y); \n \n // Elements are in the same set, no need \n // to unite anything. \n if (xRoot == yRoot) \n return; \n \n // If x's rank is less than y's rank \n if (rank[xRoot] < rank[yRoot]) \n \n // Then move x under y so that depth \n // of tree remains less \n parent[xRoot] = yRoot; \n \n // Else if y's rank is less than x's rank \n else if (rank[yRoot] < rank[xRoot]) \n \n // Then move y under x so that depth of \n // tree remains less \n parent[yRoot] = xRoot; \n \n else // if ranks are the same \n { \n // Then move y under x (doesn't matter \n // which one goes where) \n parent[yRoot] = xRoot; \n \n // And increment the the result tree's \n // rank by 1 \n rank[xRoot] = rank[xRoot] + 1; \n } \n } \n static long gcd(long a, long b) \n { \n if (a == 0){ \n //ans+=b;\n return b;\n }\n return gcd(b % a, a); \n }\n}", "lang_cluster": "Java", "tags": ["math", "constructive algorithms", "implementation"], "code_uid": "cd3ca377279bd3dbf58cda1c5776f3a2", "src_uid": "fb3aca6eba3a952e9d5736c5d8566821", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.*;\nimport java.util.*;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.LinkedHashMap;\nimport java.util.Map;\n\nimport static java.util.stream.Collectors.*;\nimport static java.util.Map.Entry.*;\n\n\npublic class Main {\n\t\n\tstatic int ans = 0;\n\tstatic boolean [] memo;\n\tpublic static void main(String[] args) throws IOException {\n\t\tFastReader in = new FastReader(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint n = in.nextInt();\n\t\tint d = in.nextInt();\n\t\tchar [] a = in.next().toCharArray();\n\t\tmemo = new boolean [n-1];\n\t\tif (!go(a,0,n-1,d)) {\n\t\t\tout.println(\"-1\");\n\t\t} else {\n\t\t\tout.println(ans);\n\t\t}\n\t\t\n\t\tout.flush();\n\t\tout.close();\n\t\n\t}\n\t\n\t\n\t\n\tprivate static boolean go(char[] a, int i, int n,int d ) {\n\t\tif (i == n|| i+d >= n) {\n\t\t\tans +=1;\n\t\t\treturn true;\n\t\t} else if (a[i] == '0' || i > n || memo[i]) {\n\t\t\treturn false;\n\t\t} else {\n\t\t\t\tfor (int j = i+d; j > i; j--) {\n\t\t\t\t\tif (a[j] == '1') {\n\t\t\t\t\t\tif (go(a,j,n,d)) {\n\t\t\t\t\t\t\tans+=1;\n\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tmemo[j] = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} \n\t\t\t\treturn false;\n\t\t\t}\n\t}\n\n\n\n\n\tstatic class FastReader {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic FastReader(InputStream s) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(s));\n\t\t}\n\n\t\tpublic FastReader(FileReader fileReader) {\n\t\t\tbr = new BufferedReader(fileReader);\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic String nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tpublic boolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\t}\n\n}", "lang_cluster": "Java", "tags": ["dfs and similar", "greedy", "dp", "implementation"], "code_uid": "635b4463d985c3a17dac4a27bdb54da0", "src_uid": "c08d2ecdfc66cd07fbbd461b1f069c9e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\nimport java.util.stream.IntStream;\nimport java.util.stream.LongStream;\n\n/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n/**\n *\n * @author Andy Phan\n */\npublic class c {\n \n public static void main(String[] args) { \n FS in = new FS(System.in);\n PrintWriter out = new PrintWriter(System.out);\n\n long n = in.nextLong();\n long k = in.nextLong();\n long M = in.nextLong();\n long D = in.nextLong();\n D = Math.min(D, n/k);\n long max = 0;\n for(long d = 1; d <= D; d++) {\n long minX = n/(k*d);\n long maxX = n/(k*(d-1)+1);\n if(minX > M) continue;\n max = Math.max(max, d*Math.min(M, maxX));\n }\n System.out.println(max);\n out.close();\n }\n\n static class FS {\n\n BufferedReader in;\n StringTokenizer token;\n\n public FS(InputStream str) {\n in = new BufferedReader(new InputStreamReader(str));\n }\n\n public String next() {\n if (token == null || !token.hasMoreElements()) {\n try {\n token = new StringTokenizer(in.readLine());\n } catch (IOException ex) {\n }\n return next();\n }\n return token.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n public long nextLong() {\n return Long.parseLong(next());\n }\n }\n}\n\n/*\n6\n-1\n1\n1\n1\n10\n6\n4\n8\n-1\n1\n1\n*/", "lang_cluster": "Java", "tags": ["math"], "code_uid": "860daef97b0700ddbb22209a2e2f2140", "src_uid": "ac2e795cd44061db8da13e3947ba791b", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/**\n * Created by Chirag on 12-12-2017.\n * DA-IICT (B.tech 3rd year)\n */\n\nimport java.io.*;\nimport java.util.*;\n\n\npublic class ChotllyRequest\n{\n public static void main(String[] args) {\n MyScanner sc = new MyScanner();\n out = new PrintWriter(new BufferedOutputStream(System.out));\n \n \n /*\n int n = sc.nextInt(); // read input as integer\n long k = sc.nextLong(); // read input as long\n double d = sc.nextDouble(); // read input as double\n String str = sc.next(); // read input as String\n String s = sc.nextLine(); // read whole line as String\n\n int result = 3*n;\n out.println(result); // print via PrintWriter\n */\n //The Code Starts here\n int k=sc.nextInt();\n int p=sc.nextInt();\n int noOfNumbers=0;\n long sum=0;\n int i=1;\n while (noOfNumbers {\n long u;\n long v;\n\n public Pair(long u, long v) {\n this.u = u;\n this.v = v;\n }\n\n\n public int hashCode() {\n int hu = (int) (u ^ (u >>> 32));\n int hv = (int) (v ^ (v >>> 32));\n return 31 * hu + hv;\n }\n\n public boolean equals(Object o) {\n Pair other = (Pair) o;\n return u == other.u && v == other.v;\n }\n\n public int compareTo(Pair other) {\n return Long.compare(u, other.u) != 0 ? Long.compare(u, other.u) : Long.compare(v, other.v);\n }\n\n public String toString() {\n return \"[u=\" + u + \", v=\" + v + \"]\";\n }\n }\n //--------------------------------------------------------\n\n\n // Different other methods\n\n public static long pow(long n, long p, long mod) {\n if (p == 0)\n return 1;\n if (p == 1)\n return n % mod;\n if (p % 2 == 0) {\n long temp = pow(n, p / 2, mod);\n return (temp * temp) % mod;\n } else {\n long temp = pow(n, p / 2, mod);\n temp = (temp * temp) % mod;\n return (temp * n) % mod;\n\n }\n }\n\n public static long pow(long n, long p) {\n if (p == 0)\n return 1;\n if (p == 1)\n return n;\n if (p % 2 == 0) {\n long temp = pow(n, p / 2);\n return (temp * temp);\n } else {\n long temp = pow(n, p / 2);\n temp = (temp * temp);\n return (temp * n);\n\n }\n }\n\n public static long gcd(long x, long y) {\n if (x == 0)\n return y;\n else\n return gcd(y % x, x);\n }\n\n static long modInverse(long a, long m) {\n long m0 = m, t, q;\n long x0 = 0, x1 = 1;\n\n if (m == 1)\n return 0;\n\n while (a > 1) {\n // q is quotient\n q = a / m;\n\n t = m;\n\n // m is remainder now, process\n // same as Euclid's algo\n m = a % m;\n a = t;\n\n t = x0;\n\n x0 = x1 - q * x0;\n\n x1 = t;\n }\n\n // Make x1 positive\n if (x1 < 0)\n x1 += m0;\n\n return x1;\n }\n\n public static boolean isPrime(int n) {\n if (n <= 1)\n return false;\n if (n <= 3)\n return true;\n\n if (n % 2 == 0 || n % 3 == 0)\n return false;\n\n for (int i = 5; i * i <= n; i = i + 6)\n if (n % i == 0 || n % (i + 2) == 0)\n return false;\n\n return true;\n }\n\n public static class DisjointSet {\n HashMap map = new HashMap();\n\n class Node {\n int data;\n int rank;\n Node parent;\n\n Node(int data) {\n this.data = data;\n this.rank = 0;\n this.parent = this;\n }\n }\n\n void makeSet(int data) {\n map.put(data, new Node(data));\n }\n\n Node findSet(int data) {\n return findSet(map.get(data));\n }\n\n boolean isConnected(int d1, int d2) {\n return findSet(d1) == findSet(d2);\n }\n\n Node findSet(Node node) {\n Node parent = node.parent;\n if (parent == node)\n return parent;\n node.parent = findSet(node.parent);\n return node.parent;\n }\n\n void union(int data1, int data2) {\n Node d1 = map.get(data1);\n Node d2 = map.get(data2);\n\n Node p1 = findSet(d1);\n Node p2 = findSet(d2);\n\n if (p1.data == p2.data)\n return;\n\n if (p1.rank >= p2.rank) {\n p1.rank = (p1.rank == p2.rank) ? p1.rank + 1 : p1.rank;\n p2.parent = p1;\n } else {\n p1.parent = p2;\n }\n }\n\n }\n\n\n}\n\n", "lang_cluster": "Java", "tags": ["brute force"], "code_uid": "527c31bb2b7f05e512b03df3bcf02615", "src_uid": "00e90909a77ce9e22bb7cbf1285b0609", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n\npublic class songsandjoke {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n int n,d,k;\n Scanner in=new Scanner(System.in);\n n=in.nextInt();\n d=in.nextInt();\n int sum=0;\n for(int i=0;i sq = getSquares(n);\n\n\t\tfor (int i = 0; i < sq.size(); i++) {\n\t\t\tString regex = getRegexed(Integer.toString(sq.get(i)));\n\t\t\tif (s.matches(regex)) {\n\t\t\t\tSystem.out.println(s.length() - Integer.toString(sq.get(i)).length());\n\t\t\t\tSystem.exit(0);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(-1);\n\t}\n\n\tstatic String getRegexed(String str) {\n\t\tString tmp = \"\";\n\t\tfor (int i = 0; i < str.length(); i++) {\n\t\t\ttmp += \".*\" + str.charAt(i) + \".*\";\n\t\t}\n\t\treturn tmp;\n\t}\n\n\tstatic ArrayList getSquares(int n) {\n\t\tArrayList list = new ArrayList<>();\n\t\tint x = 1;\n\t\twhile (x * x <= n) {\n\t\t\tlist.add(x * x);\n\t\t\tx++;\n\t\t}\n\t\tCollections.reverse(list);\n\t\treturn list;\n\t}\n\n}\n\nclass Pair {\n\n\tint x;\n\tint y;\n\n\tpublic Pair(int x, int y) {\n\t\tthis.x = x;\n\t\tthis.y = y;\n\t}\n\n\t@Override\n\tpublic String toString() {\n\t\treturn \"Pair [x=\" + x + \", y=\" + y + \"]\";\n\t}\n}\n\nclass OutputWriter {\n\tpublic PrintWriter writer;\n\n\tpublic OutputWriter(OutputStream outputStream) {\n\t\twriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n\t}\n\n\tpublic OutputWriter(Writer writer) {\n\t\tthis.writer = new PrintWriter(writer);\n\t}\n\n\tpublic void print(Object... objects) {\n\t\tfor (int i = 0; i < objects.length; i++) {\n\t\t\tif (i != 0)\n\t\t\t\twriter.print(' ');\n\t\t\twriter.print(objects[i]);\n\t\t}\n\t}\n\n\tpublic void println(Object... objects) {\n\t\tprint(objects);\n\t\twriter.println();\n\t}\n\n\tpublic void close() {\n\t\twriter.close();\n\t}\n}\n\nclass InputReader {\n\tprivate BufferedReader reader;\n\tprivate StringTokenizer tokenizer;\n\n\tpublic InputReader(InputStream stream) {\n\t\treader = new BufferedReader(new InputStreamReader(stream), 32768);\n\t\ttokenizer = null;\n\t}\n\n\tpublic String next() {\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\t\treturn tokenizer.nextToken();\n\t}\n\n\tpublic String readLine() {\n\t\ttry {\n\t\t\treturn reader.readLine();\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t}\n\n\tpublic char nextChar() {\n\t\treturn next().charAt(0);\n\t}\n\n\tpublic int nextInt() {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tpublic long nextLong() {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tpublic double nextDouble() {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tpublic float nextFloat() {\n\t\treturn Float.parseFloat(next());\n\t}\n\n}", "lang_cluster": "Java", "tags": ["brute force", "math", "implementation"], "code_uid": "f60ce58ea4a6c9e4b9553b5e98443db9", "src_uid": "fa4b1de79708329bb85437e1413e13df", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "/**\n * Created by IntelliJ IDEA.\n * User: aircube\n * Date: 10.04.11\n * Time: 16:36\n * To change this template use File | Settings | File Templates.\n */\n\nimport java.io.*;\nimport java.util.Scanner;\n\npublic class taskA {\n\n void solve() throws IOException {\n Scanner in = new Scanner(System.in);\n int a[] = new int[3];\n for (int i = 0; i < 3; ++i)\n a[i] = in.nextInt();\n int k = in.nextInt();\n int b[] = new int[3];\n while (k > 0) {\n int c = -1;\n for (int i = 0; i < 3; ++i) {\n if (a[i] - b[i] - 1 > 0 && (c == -1 || b[i] < b[c]) )\n c = i;\n }\n if (c == -1) break;\n b[c] ++;\n -- k;\n }\n System.out.print((long)(b[0] + 1) * (b[1] + 1) * (b[2] + 1));\n }\n\n public static void main(String[] args) throws IOException {\n new taskA().solve();\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "greedy"], "code_uid": "a95c61010a3296297ef3f274ba4e0ec7", "src_uid": "8787c5d46d7247d93d806264a8957639", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\n/**\n * DA-IICT\n * Author : Savaliya Sagar\n */\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class D908\n{\n\tint k, mod = (int) (1e9 + 7);\n\tlong pa, pb, pa_pb;\n\tlong dp[][];\n\t\n\tvoid solve()\n\t{\n\t\tk = ni();\n\t\tdp = new long[k + 5][k + 5];\n\t\tfor (int i = 0; i < k + 5; i++)\n\t\t{\n\t\t\tArrays.fill(dp[i], -1);\n\t\t}\n\t\tint a = ni();\n\t\tint b = ni();\n\t\tpa = mul(a, pow(a + b, mod - 2, mod));\n\t\tpb = mul(b, pow(a + b, mod - 2, mod));\n\t\tpa_pb = mul(a, pow(b, mod - 2, mod));\n\t\tout.println(rec(1, 0));\n\t}\n\t\n\tlong rec(int a, int ab)\n\t{\n\t\tif (ab >= k)\n\t\t\treturn ab;\n\t\tif (a >= k)\n\t\t{\n\t\t\treturn (a + 0L + ab + pa_pb) % mod;\n\t\t}\n\t\tif (dp[a][ab] != -1)\n\t\t\treturn dp[a][ab];\n\t\tdp[a][ab] = rec(a + 1, ab) * pa + 0L + rec(a, ab + a) * pb;\n\t\tdp[a][ab] %= mod;\n\t\treturn (dp[a][ab]);\n\t}\n\t\n\tlong add(long a, long b)\n\t{\n\t\tlong sum = a + b;\n\t\tif (sum >= mod)\n\t\t\tsum -= mod;\n\t\treturn sum;\n\t}\n\t\n\tlong sub(long a, long b)\n\t{\n\t\tlong sub = a - b;\n\t\tif (sub < 0)\n\t\t\tsub += mod;\n\t\treturn sub;\n\t}\n\t\n\tlong mul(long a, long b)\n\t{\n\t\treturn (a * b) % mod;\n\t}\n\t\n\tlong pow(long x, long n, long mod)\n\t{\n\t\tlong res = 1;\n\t\tx %= mod;\n\t\twhile (n > 0)\n\t\t{\n\t\t\tif (n % 2 == 1)\n\t\t\t{\n\t\t\t\tres = (res * x) % mod;\n\t\t\t}\n\t\t\tx = (x * x) % mod;\n\t\t\tn /= 2;\n\t\t}\n\t\treturn res;\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tout = new PrintWriter(System.out);\n\t\treader = new BufferedReader(new InputStreamReader(System.in), 32768);\n\t\ttokenizer = null;\n\t\tsolve();\n\t\tout.flush();\n\t}\n\t\n\tpublic int ni()\n\t{\n\t\treturn Integer.parseInt(next());\n\t}\n\t\n\tBufferedReader reader;\n\tStringTokenizer tokenizer;\n\tPrintWriter out;\n\t\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tnew D908().run();\n\t}\n\t\n\tpublic String next()\n\t{\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens())\n\t\t{\n\t\t\ttry\n\t\t\t{\n\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t} catch (IOException e)\n\t\t\t{\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\t\treturn tokenizer.nextToken();\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "dp", "probabilities"], "code_uid": "dc9032dd4412b0118f1c5b71d3a4bd64", "src_uid": "0dc9f5d75143a2bc744480de859188b4", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\n/**\n *\n * @author sarthak\n */\n\nimport java.util.*;\nimport java.math.*;\nimport java.io.*;\n\n\n\npublic class ExpeEduRnd_H {\n\n static class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(InputStream is) {\n br = new BufferedReader(new InputStreamReader(is));\n }\n\n public String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n public String nextLine() {\n st = null;\n try {\n return br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n return \"\";\n }\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n }\nstatic class P {\n\n private int x, y;\n\n public P(int x, int y) {\n this.x = x;\n this.y = y;\n }\n\n public int hashCode() {\n return (x * 31) ^ y;\n }\n\n public boolean equals(Object o) {\n if (o instanceof P) {\n P other = (P) o;\n return (x == other.x && y == other.y);\n }\n return false;\n }\n }\n\n public static void main(String[] args){\n \n FastScanner s = new FastScanner(System.in);\n \n long n=s.nextLong();\n long an=n*(n-1)*(n-2)*(n-3)*(n-4);//placing benches along north to south\n BigInteger ans=BigInteger.valueOf(an);//a bench from north to south alos has options\n ans=ans.multiply(ans); //all beches are identical\n ans=ans.divide(BigInteger.valueOf(120));\n \n System.out.println(ans);\n \n \n \n \n \n }\n\n\n}\n", "lang_cluster": "Java", "tags": ["math", "combinatorics"], "code_uid": "2cdc869fe4e226af463e719fdb5ec3e4", "src_uid": "92db14325cd8aee06b502c12d2e3dd81", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.DataInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\nimport java.util.Arrays;\n\n/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n/**\n *\n * @author geek_guY\n */\npublic class que5 {\n\n public static void main(String args[]) throws IOException, Exception {\n\n inputz6 in = new inputz6(System.in);\n \n int a = in.nextInt();\n int b = in.nextInt();\n \n if(a==b)\n {\n System.out.println(\"0\");\n return;\n }\n \n int a1[] = new int[6];\n int a2[] = new int[6];\n \n while(a%2==0)\n {\n a1[2]++;\n a/=2;\n }\n while(a%3==0)\n {\n a1[3]++;\n a/=3;\n }\n while(a%5==0)\n {\n a1[5]++;\n a/=5;\n }\n \n while(b%2==0)\n {\n a2[2]++;\n b/=2;\n }\n while(b%3==0)\n {\n a2[3]++;\n b/=3;\n }\n \n while(b%5==0)\n {\n a2[5]++;\n b/=5;\n }\n \n if(a!=b)\n {\n System.out.println(-1);\n return;\n }\n else\n {\n int d1 = Math.abs(a1[2]-a2[2]);\n int d2 = Math.abs(a1[3]-a2[3]);\n int d3 = Math.abs(a1[5]-a2[5]);\n System.out.println(d1+d2+d3);\n \n }\n \n \n }\n}\n\nclass inputz6 {\n\n final private int BUFFER_SIZE = 1 << 17;\n private DataInputStream din;\n private byte[] buffer;\n private int bufferPointer, bytesRead;\n\n public inputz6(InputStream in) {\n din = new DataInputStream(in);\n buffer = new byte[BUFFER_SIZE];\n bufferPointer = bytesRead = 0;\n }\n\n public String nextString() throws Exception {\n StringBuffer sb = new StringBuffer(\"\");\n byte c = read();\n while (c <= ' ') {\n c = read();\n }\n do {\n sb.append((char) c);\n c = read();\n } while (c > ' ');\n return sb.toString();\n }\n\n public char nextChar() throws Exception {\n byte c = read();\n while (c <= ' ') {\n c = read();\n }\n return (char) c;\n }\n\n public int nextInt() throws Exception {\n int ret = 0;\n byte c = read();\n while (c <= ' ') {\n c = read();\n }\n boolean neg = c == '-';\n if (neg) {\n c = read();\n }\n do {\n ret = ret * 10 + c - '0';\n c = read();\n } while (c > ' ');\n if (neg) {\n return -ret;\n }\n return ret;\n }\n\n public long nextLong() throws Exception {\n long ret = 0;\n byte c = read();\n while (c <= ' ') {\n c = read();\n }\n boolean neg = c == '-';\n if (neg) {\n c = read();\n }\n do {\n ret = ret * 10 + c - '0';\n c = read();\n } while (c > ' ');\n if (neg) {\n return -ret;\n }\n return ret;\n }\n\n private void fillBuffer() throws Exception {\n bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n if (bytesRead == -1) {\n buffer[0] = -1;\n }\n }\n\n private byte read() throws Exception {\n if (bufferPointer == bytesRead) {\n fillBuffer();\n }\n return buffer[bufferPointer++];\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "number theory"], "code_uid": "1ba0c4152fbfc24f023224ebedf2114b", "src_uid": "75a97f4d85d50ea0e1af0d46f7565b49", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\npublic class Main {\n\tstatic BufferedReader br; \n\tstatic FileInputStream fis;\n\tstatic InputStreamReader isr;\n\tstatic FileWriter fw;\n\n\tpublic static void main(String[] args) throws IOException{\n\t\t//fis = new FileInputStream(\"input.txt\");\n\t\t//isr = new InputStreamReader(fis);\n\t\tisr = new InputStreamReader(System.in);\n\t\tbr = new BufferedReader(isr); \n\t\t//File file = new File(\"output.txt\");\n\t\t//fw = new FileWriter(file);\n\t\tsolve();\n\t\t//fis.close();\n\t\tisr.close();\n\t\tbr.close();\n\t\t//fw.close();\n\t\treturn;\n\t}\n\n\t// the followings are methods to take care of inputs.\n\tstatic int nextInt(){\n\t\treturn Integer.parseInt(nextLine());\n\t}\n\tstatic long nextLong(){\n\t\treturn Long.parseLong(nextLine());\n\t}\n\tstatic int[] nextIntArray(){\n\t\tString[] inp = nextLine().split(\"\\\\s+\");\n\t\tint[] ary = new int[inp.length];\n\t\tfor (int i = 0; i < ary.length; i++){\n\t\t\tary[i] = Integer.parseInt(inp[i]);\n\t\t}\n\t\treturn ary;\n\t}\n\tstatic int[] nextIntArrayFrom1(){\n\t\tString[] inp = nextLine().split(\"\\\\s+\");\n\t\tint[] ary = new int[inp.length + 1];\n\t\tfor (int i = 0; i < inp.length; i++){\n\t\t\tary[i+1] = Integer.parseInt(inp[i]);\n\t\t}\n\t\treturn ary;\n\t}\n\tstatic long[] nextLongArray(){\n\t\tString[] inp = nextLine().split(\"\\\\s+\");\n\t\tlong[] ary = new long[inp.length];\n\t\tfor (int i = 0; i < inp.length; i++){\n\t\t\tary[i] = Long.parseLong(inp[i]);\n\t\t}\n\t\treturn ary;\n\t}\n\tstatic long[] nextLongArrayFrom1(){\n\t\tString[] inp = nextLine().split(\"\\\\s+\");\n\t\tlong[] ary = new long[inp.length + 1];\n\t\tfor (int i = 0; i < inp.length; i++){\n\t\t\tary[i+1] = Long.parseLong(inp[i]);\n\t\t}\n\t\treturn ary;\n\t}\n\tstatic String nextLine(){\n\t\ttry { \n\t\t\treturn br.readLine().trim();\n\t\t} catch (Exception e){}\n\t\treturn null;\n\t}\n\tstatic void write(String str){\n\t\ttry{\n\t\t\tfw.write(str);\n\t\t}catch (Exception e){\n\t\t\tSystem.out.println(e);\n\t\t}\n\t\treturn;\n\t}\n\tstatic void solve(){\n\t\tint[] tmp = nextIntArray();\n\t\tint n = tmp[0];\n\t\tint p = tmp[1];\n\t\tint k = tmp[2];\n\t\tString ret=\"\";\n\t\tif(p != 1 && 1 < p-k){\n\t\t\t\tret += \"<< \";\n\t\t}\n\t\tfor(int i=p-k;i<=p+k && i<=n;i++){\n\t\t\tif(i<=0){\n\t\t\t\ti = 1;\n\t\t\t}\n\t\t\tif(p == i){\n\t\t\t\tret += \"(\" + p + \") \";\n\t\t\t}else{\n\t\t\t\tret += i + \" \";\n\t\t\t}\n\t\t}\n\t\tif(p + k < n){\n\t\t\tret += \">>\";\n\t\t}\n\t\tSystem.out.println(ret);\n\t\treturn;\n\t}\n}\n\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "d599e0b690b84d96b9d54fb17f19b55f", "src_uid": "526e2cce272e42a3220e33149b1c9c84", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.List;\nimport java.util.Set;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n public static void main(String[] args) throws IOException {\n new Main().run();\n }\n\n StringTokenizer str = null;\n BufferedReader in;\n PrintWriter out;\n\n void run() throws IOException {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(new OutputStreamWriter(System.out));\n solve();\n out.flush();\n out.close();\n }\n\n String nextString() throws IOException {\n return in.readLine();\n }\n\n String nextToken() throws IOException {\n if (str == null || !str.hasMoreElements()) {\n str = new StringTokenizer(nextString());\n }\n return str.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n class Point implements Comparable {\n int x;\n int y;\n\n @Override\n public int compareTo(Point p) {\n if (p.x > x)\n return -1;\n if (p.x < x)\n return 1;\n if (p.y > y)\n return -1;\n if (p.y < y)\n return 1;\n return 0;\n }\n }\n\n private double Rastoyanie(Point p[], int i, int l) {\n int xx = p[i].x - p[l].x;\n int yy = p[i].y - p[l].y;\n xx = xx * xx;\n yy = yy * yy;\n return Math.sqrt(xx + yy);\n }\n\n private boolean Na_odnoy_pramoy(Point p[], int i, int j, int l) {\n return (p[i].y - p[j].y) * p[l].x + (p[j].x - p[i].x) * p[l].y\n + (p[i].x * p[j].y - p[j].x * p[i].y) == 0;\n }\n\n boolean isPrime(long p) {\n int t = (int) (Math.sqrt(p) + 1);\n for (int i = 2; i < t; i++) {\n if (p % i == 0)\n return false;\n }\n return true;\n }\n\n void solve() throws IOException {\n long n = nextLong();\n long r = 0;\n long i;\n while (n > 1) {\n int t = (int) (Math.sqrt(n) + 1);\n\n for (i = 2; i < t; i++) {\n if (n % i == 0) {\n break;\n }\n }\n if (i == t) {\n i = n;\n }\n while (n % i != 0) {\n i++;\n }\n r += n;\n n = n / i;\n }\n r += 1;\n out.println(r);\n }\n}", "lang_cluster": "Java", "tags": ["number theory"], "code_uid": "9e6e7ae09ae24866dda7f42c328acfd0", "src_uid": "821c0e3b5fad197a47878bba5e520b6e", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import static java.lang.System.*;\nimport static java.lang.Math.*;\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class A {\n\n public static void main(String[] args) throws IOException {\n Scanner input = new Scanner(System.in);\n int year = input.nextInt();\n int firstDay=3;\n int Day=3;\n int yearDay=0;\n int Days=0;\n for (int current = 1000; current < year+200; current++) {\n int days=365;\n if(current%4==0 && current%100!=0 || current%400==0){\n days++;\n }\n if(current==year){\n yearDay=Day;\n Days=days;\n }\n if(current>year && Day==yearDay && days==Days){\n out.println(current);\n break;\n }\n for(int j=365; j<=days; j++){\n Day=(Day+1)%7;\n }\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "533fea1debfee4aa75035a203f1e7c3d", "src_uid": "565bbd09f79eb7bfe2f2da46647af0f2", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n\npublic class C {\n\tpublic static void main(String args[]){\n\t\tScanner sc = new Scanner(System.in);\n\t\tString burger = sc.nextLine();\n\t\tlong B = 0;\n\t\tlong S = 0;\n\t\tlong C = 0;\n\t\tlong count = 0;\n\t\tfor(int i = 0; i < burger.length(); i++){\n char c = burger.charAt(i);\n\t\t\tif(c == 'B'){\n\t\t\t\tB++;\n\t\t\t}\n\t\t\telse if(c == 'S'){\n\t\t\t\tS++;\n\t\t\t}\n\t\t\telse if(c == 'C'){\n\t\t\t\tC++;\n\t\t\t}\n\t\t}\n\t\tlong nB = sc.nextLong();\n\t\tlong nS = sc.nextLong();\n\t\tlong nC = sc.nextLong();\n\n\t\tlong pB = sc.nextLong();\n\t\tlong pS = sc.nextLong();\n\t\tlong pC = sc.nextLong(); \n\n\t\tlong r = sc.nextLong();\n\t\tdo {\n\t\t\tlong min = Long.MAX_VALUE;\n\t\t\tif(B != 0){\n\t\t\t\tmin = Math.min(nB/B, min);\n\t\t\t}\n\t\t\telse{\n\t\t\t\tnB = 0;\n\t\t\t}\n\t\t\tif(S != 0){\n\t\t\t\tmin = Math.min(nS/S, min);\n\t\t\t}\n\t\t\telse{\n\t\t\t\tnS = 0;\n\t\t\t}\n\t\t\tif(C != 0){\n\t\t\t\tmin = Math.min(nC/C, min);\n\t\t\t}\n\t\t\telse{\n\t\t\t\tnC = 0;\n\t\t\t}\n\t\t\tcount+=min;\n\t\t\tnC -= C*min;\n\t\t\tnS -= S*min;\n\t\t\tnB -= B*min;\n\t\t\tif(nC == nS && nS == nB && nB == 0){\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif(B!= 0 && nB < B){\n\t\t\t\tr -= (B-nB)*pB;\n\t\t\t\tnB = B;\n\t\t\t}\n\t\t\tif(S!= 0 && nS < S){\n\t\t\t\tr-= (S-nS)*pS;\n\t\t\t\tnS = S;\n\t\t\t}\n\t\t\tif(C!= 0 && nC < C){\n\t\t\t\tr-= (C-nC)*pC;\n\t\t\t\tnC = C;\n\t\t\t}\n\t\t} while (!(r<0));\n\t\tlong costOfBurger = B*pB + S*pS + C*pC; \n\t\tif(r > 0){\n\t\t\tcount += r/costOfBurger;\n\t\t}\n\t\tSystem.out.println(count);\n\n\t}\n}", "lang_cluster": "Java", "tags": ["brute force", "binary search"], "code_uid": "522de32b83015b6007b686bb60bc4a8a", "src_uid": "8126a4232188ae7de8e5a7aedea1a97e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n/**\n *\n * @author pttrung\n */\npublic class B {\n\n public static void main(String[] args) {\n Scanner in = new Scanner();\n PrintWriter out = new PrintWriter(System.out);\n int x = in.nextInt();\n if(x < 0){\n x = -x;\n }\n int step = 0;\n while(true){\n long val = step*(step + 1)/2;\n if(val >= x &&(val - x)%2 == 0 ){\n out.println(step);\n break;\n }\n step++;\n }\n out.close();\n }\n\n \n\n public double pow(double a, int b) {\n if (b == 0) {\n return 1;\n }\n if (b == 1) {\n return a;\n }\n double val = pow(a, b / 2);\n if (b % 2 == 0) {\n return val * val;\n } else {\n return val * val * a;\n }\n }\n\n public static long gcd(long a, long b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n public static long lcm(long a, long b) {\n return a * b / gcd(a, b);\n }\n\n static class Scanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n public Scanner() {\n // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n public String next() {\n\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n return st.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public String nextLine() {\n st = null;\n try {\n return br.readLine();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n\n public boolean endLine() {\n try {\n String next = br.readLine();\n while (next != null && next.trim().isEmpty()) {\n next = br.readLine();\n }\n if (next == null) {\n return true;\n }\n st = new StringTokenizer(next);\n return st.hasMoreTokens();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n }\n}", "lang_cluster": "Java", "tags": ["math"], "code_uid": "daa109713457bea9449bcb5092073049", "src_uid": "18644c9df41b9960594fdca27f1d2fec", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class C952 {\n\t\n\tpublic static void main(String[] args) throws Exception {\n\n\t\tst = new StringTokenizer(in.readLine());\n\t\tint n = i();\n\n\t\tst = new StringTokenizer(in.readLine());\n\t\tint j = i();\n\n\t\tboolean no = false;\n\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tint k = i();\n\t\t\tif (Math.abs(k - j) >= 2) {\n\t\t\t\tno = true; break;\n\t\t\t}\n\t\t\tj = k;\n\t\t}\n\n\t\tout.println(no ? \"NO\" : \"YES\");\n\n\t\tout.close();\n\t}\n\n\tstatic BufferedReader in;\n\tstatic StringTokenizer st;\n\tstatic PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\tstatic {\n\t\ttry {\n\t\t\tin = new BufferedReader(new FileReader(\"cf.in\"));\n\t\t} catch (Exception e) {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\t}\n\tstatic int i() {return Integer.parseInt(st.nextToken());}\n\tstatic double d() {return Double.parseDouble(st.nextToken());}\n\tstatic String s() {return st.nextToken();}\n\tstatic long l() {return Long.parseLong(st.nextToken());}\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "7013c2ec61de8c6e001c2a79cc480f06", "src_uid": "704d0ae50bccaa8bc49319812ae0be45", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class C {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n \n int[][][] faces = new int[6][2][2];\n \n for (int i = 0; i < 6; i++) {\n for (int j = 0; j < 2; j++) {\n for (int k = 0; k < 2; k++) {\n faces[i][j][k] = sc.nextInt();\n }\n }\n }\n \n int[] solvable = new int[6];\n for (int i = 0; i < 6; i++) {\n if (faces[i][0][0] == faces[i][1][0] && faces[i][0][1] == faces[i][1][1] && faces[i][0][0] == faces[i][0][1]) {\n solvable[i] = 1;\n } else if (faces[i][0][0] == faces[i][1][0] && faces[i][0][1] == faces[i][1][1]) {\n solvable[i] = 2;\n } else if (faces[i][0][0] == faces[i][0][1] && faces[i][1][0] == faces[i][1][1]) {\n solvable[i] = 3;\n }\n }\n \n int[] sCount = new int[4];\n for (int i = 0; i < 6; i++) {\n sCount[solvable[i]]++;\n }\n \n \n boolean result = false;\n int[][][] f = faces;\n if (sCount[1] == 2) {\n if (solvable[0] == 2 && solvable[1] == 2 && solvable[2] == 2 && solvable[5] == 2) {\n if (f[0][0][0] == f[1][0][1] && f[1][0][0] == f[2][0][1] && f[2][0][0] == f[5][0][0] && f[5][0][1] == f[0][0][1]) result = true;\n else if (f[0][0][1] == f[1][0][0] && f[1][0][1] == f[2][0][0] && f[2][0][1] == f[5][0][1] && f[5][0][0] == f[0][0][0]) result = true;\n }\n \n if (solvable[0] == 3 && solvable[3] == 2 && solvable[2] == 3 && solvable[4] == 2) {\n if (f[0][0][0] == f[3][0][1] && f[3][0][0] == f[2][0][0] && f[2][1][0] == f[4][0][0] && f[4][0][1] == f[0][1][0]) result = true;\n else if (f[0][1][0] == f[3][0][0] && f[3][0][1] == f[2][1][0] && f[2][0][0] == f[4][0][1] && f[4][0][0] == f[0][0][0]) result = true;\n }\n \n if (solvable[3] == 3 && solvable[1] == 3 && solvable[4] == 3 && solvable[5] == 3) {\n if (f[3][0][0] == f[1][1][0] && f[1][0][0] == f[4][1][0] && f[4][0][0] == f[5][1][0] && f[5][0][0] == f[3][1][0]) result = true;\n else if (f[3][1][0] == f[1][0][0] && f[1][1][0] == f[4][0][0] && f[4][1][0] == f[5][0][0] && f[5][1][0] == f[3][0][0]) result = true;\n }\n }\n \n if (result) {\n System.out.println(\"YES\");\n } else {\n System.out.println(\"NO\");\n }\n \n }\n \n}", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "91c97bb4144fef7bdfe78b0753376cdd", "src_uid": "881a820aa8184d9553278a0002a3b7c4", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\npublic class Main2 {\n BufferedReader in;\n PrintWriter out;\n Main2() {\n try {\n in = new BufferedReader(new FileReader(\"input.txt\"));\n out = new PrintWriter(new FileWriter(\"output.txt\"),true);\n solve();\n } catch (Exception ex) {\n ex.printStackTrace();\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out,true);\n solve();\n } finally {\n try {\n in.close();\n } catch (IOException ex) {\n ex.printStackTrace();\n }\n out.close();\n }\n }\n\n StringTokenizer st;\n public String nextToken() {\n while(st == null || !st.hasMoreTokens())\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException ex) {\n ex.printStackTrace();\n }\n return st.nextToken();\n }\n\n public Long nextLong() {\n return Long.valueOf(nextToken());\n }\n\n public int nextInt() {\n return Integer.valueOf(nextToken());\n }\n\n public void solve() {\n int n = nextInt();\n int m = nextInt();\n int countBus = 0;\n int delta = 0;\n int[] arr = new int[n];\n for (int i = 0; i < n; i++) {\n arr[i] = nextInt();\n }\n delta = arr[0];\n boolean norm = false;\n for (int i = 1; i < n; i++) {\n if (delta + arr[i] <= m) {\n delta += arr[i];\n norm = false;\n } else {\n norm = true;\n countBus++;\n delta = arr[i];\n if (i == n-1) {\n countBus++;\n }\n }\n }\n if (!norm)\n countBus++;\n out.print(countBus);\n }\n\n public static void main(String[] args) {\n new Main2();\n }\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "bd150800054ce8f5ecfb0ce81d686f9f", "src_uid": "5c73d6e3770dff034d210cdd572ccf0f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.DataInputStream;\nimport java.io.FileInputStream;\nimport java.io.FileReader;\nimport java.io.FileWriter;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n\n\npublic class WrongSubtraction {\n\n public static void main(String[] args) throws Exception {\n new WrongSubtraction().go();\n }\n\n\n PrintWriter out;\n Reader in;\n BufferedReader br;\n\n WrongSubtraction() throws Exception {\n\n // in = new Reader(\"input.txt\");\n // out = new PrintWriter( new BufferedWriter(new FileWriter(\"output.txt\")) );\n\n\n br = new BufferedReader(new InputStreamReader(System.in));\n in = new Reader();\n out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\n }\n\n\n\n void go() throws Exception {\n\n\n int t = 1;\n while (t > 0) {\n solve();\n t--;\n }\n\n //System.err.println(System.currentTimeMillis() - time);\n\n out.flush();\n out.close();\n }\n\n\n int inf = 2000000000;\n int mod = 1000000007;\n double eps = 0.000000001;\n\n int n;\n int m;\n\n void solve() throws Exception {\n\n int n = in.nextInt();\n int k = in.nextInt();\n\n while (k > 0) {\n\n if (n%10 == 0) n /= 10; else n--;\n k--;\n }\n\n out.println(n);\n }\n\n\n\n class Reader {\n\n BufferedReader br;\n StringTokenizer tok;\n\n public Reader(String file) throws Exception {\n br = new BufferedReader( new FileReader(file) );\n }\n\n public Reader() throws Exception {\n br = new BufferedReader( new InputStreamReader(System.in) );\n }\n\n public String next() throws Exception {\n\n while (tok == null || !tok.hasMoreElements())\n tok = new StringTokenizer(br.readLine());\n return tok.nextToken();\n }\n\n public int nextInt() throws Exception {\n return Integer.valueOf(next());\n }\n\n public long nextLong() throws Exception {\n return Long.valueOf(next());\n }\n\n public double nextDouble() throws Exception {\n return Double.valueOf(next());\n }\n\n public String nextLine() throws Exception {\n return br.readLine();\n }\n\n }\n\n\n\n\n\n static class InputReader {\n\n final private int BUFFER_SIZE = 1 << 16;\n private DataInputStream din;\n private byte[] buffer;\n private int bufferPointer, bytesRead;\n\n\n public InputReader() {\n din = new DataInputStream(System.in);\n buffer = new byte[BUFFER_SIZE];\n bufferPointer = bytesRead = 0;\n }\n\n public InputReader(String file_name) throws Exception {\n din = new DataInputStream(new FileInputStream(file_name));\n buffer = new byte[BUFFER_SIZE];\n bufferPointer = bytesRead = 0;\n }\n\n\n public String readLine() throws Exception {\n byte[] buf = new byte[64]; // line length\n int cnt = 0, c;\n while ((c = read()) != -1) {\n if (c == '\\n') {\n break;\n }\n buf[cnt++] = (byte) c;\n }\n return new String(buf, 0, cnt);\n }\n\n\n public int nextInt() throws Exception {\n int ret = 0;\n byte c = read();\n while (c <= ' ') {\n c = read();\n }\n boolean neg = (c == '-');\n if (neg) {\n c = read();\n }\n do {\n ret = ret * 10 + c - '0';\n } while ((c = read()) >= '0' && c <= '9');\n\n if (neg) {\n return -ret;\n }\n return ret;\n }\n\n\n public long nextLong() throws Exception {\n long ret = 0;\n byte c = read();\n while (c <= ' ') {\n c = read();\n }\n boolean neg = (c == '-');\n if (neg) {\n c = read();\n }\n do {\n ret = ret * 10 + c - '0';\n }\n while ((c = read()) >= '0' && c <= '9');\n return neg ? -ret : ret;\n }\n\n\n public double nextDouble() throws Exception {\n double ret = 0, div = 1;\n byte c = read();\n while (c <= ' ')\n c = read();\n boolean neg = (c == '-');\n if (neg)\n c = read();\n\n do {\n ret = ret * 10 + c - '0';\n }\n while ((c = read()) >= '0' && c <= '9');\n\n if (c == '.') {\n while ((c = read()) >= '0' && c <= '9') {\n ret += (c - '0') / (div *= 10);\n }\n }\n\n return neg ? -ret : ret;\n }\n\n\n private void fillBuffer() throws Exception {\n bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n if (bytesRead == -1) {\n buffer[0] = -1;\n }\n }\n\n private byte read() throws Exception {\n if (bufferPointer == bytesRead) {\n fillBuffer();\n }\n return buffer[bufferPointer++];\n }\n\n public void close() throws Exception {\n if (din == null) {\n return;\n }\n din.close();\n }\n }\n\n}\n\n\n\n\n\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "cfc25b84654bc8f77e371ff0d8f383de", "src_uid": "064162604284ce252b88050b4174ba55", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class _1A {\n\tpublic static void main(String[] args) {\n\t\t\n\t\tScanner key = new Scanner(System.in);\n\t\t\n\t\tlong m, n, a;\n\t\tdo {\n\t\t\tm = key.nextInt();\n\t\t\tn = key.nextInt();\n\t\t\ta = key.nextInt();\n\t\t}while(m<=0 || n<=0 || a<=0);\n\t\t//int x = m+n;\n\t\tlong c1 = (m%a != 0)? (m/a)+1:m/a;\n\t\tlong c2 = (n%a != 0)? (n/a)+1:n/a;;\n\t\t//c*=c;\n\t\tSystem.out.println(c1*c2);\n\t\t\n\t\t\n\t\t//int u = 1000000000;\n\t}\n\n}", "lang_cluster": "Java", "tags": ["math"], "code_uid": "1711aae810f19a391e9cb7a2c0a605be", "src_uid": "ef971874d8c4da37581336284b688517", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.HashSet;\nimport java.util.Scanner;\nimport java.util.Set;\n\npublic class Main {\n static Set alphabet = new HashSet<>(26);\n public static void main(String[] args) {\n // TODO code application logic here\n Scanner scanner = new Scanner (System.in);\n int n = scanner.nextInt();\n scanner.nextLine();\n String str = scanner.nextLine().toLowerCase();\n int count = 0;\n HashSet al = new HashSet();\n char[] arr= str.toCharArray();\n for (int i=0; i b)? a : b;\n}\n\n//longest increasing subsequence (n log n)\npublic static int CeilIndex(int A[],int l,int r,int key){\n while(r-l>1){\n int m=l+(r-l)/2;\n if (A[m]>=key)\n r=m;\n else\n l=m;\n }\n return r;\n }\n\n public static int lis(int A[]){\n int size=A.length;\n int[] tailTable = new int[size];\n int len;\n tailTable[0] = A[0];\n len = 1;\n for (int i=1;itailTable[len-1])\n tailTable[len++]=A[i];\n else\n tailTable[CeilIndex(tailTable, -1, len-1, A[i])] = A[i];\n }\n return len;\n }\n\n//binary modular\npublic static long bxp(long a,long b){\n long res=1;\n while(b>0){\n if(b%2!=0)\n res=res*a;\n a=(a*a);\n b>>=1;\n }\n return res;\n}\n//euclid gcd\npublic static int gcd(int p, int q) {\n if (q == 0)\n return p;\n return gcd(q, p % q);\n }\n//prime\npublic static boolean isprime(long number){\n for(int i=2;i<=sqrt(number); i++){\n if(number % i == 0){\n return false;\n }\n }\n return true;\n}\n\n//large fibbonacci\npublic static int ffb(int n) {\n\t\tBigInteger a = BigInteger.ZERO;\n\t\tBigInteger b = BigInteger.ONE;\n\t\tint m = 0;\n\t\tfor (int i = 31 - Integer.numberOfLeadingZeros(n); i >= 0; i--) {\n\t\t\tassert a.equals(sfb(m));\n\t\t\tassert b.equals(sfb(m+1));\n\t\t\tBigInteger d = multiply(a, b.shiftLeft(1).subtract(a));\n\t\t\tBigInteger e = multiply(a, a).add(multiply(b, b));\n\t\t\ta = d;\n\t\t\tb = e;\n\t\t\tm *= 2;\n\t\t\tassert a.equals(sfb(m));\n\t\t\tassert b.equals(sfb(m+1));\n\t\t\tif (((n >>> i) & 1) != 0) {\n\t\t\t\tBigInteger c = a.add(b);\n\t\t\t\ta = b;\n\t\t\t\tb = c;\n\t\t\t\tm++;\n\t\t\t\tassert a.equals(sfb(m));\n\t\t\t\tassert b.equals(sfb(m+1));\n\t\t\t}\n\t\t}\n\t\treturn a.intValue();\n\t}\n\npublic static BigInteger sfb(int n) {\n \t\tBigInteger a = BigInteger.ZERO;\n \t\tBigInteger b = BigInteger.ONE;\n \t\tfor (int i = 0; i < n; i++) {\n \t\t\tBigInteger c = a.add(b);\n \t\t\ta = b;\n \t\t\tb = c;\n \t\t}\n \t\treturn a;\n \t}\n\npublic static BigInteger multiply(BigInteger x, BigInteger y) {\n \t\treturn x.multiply(y);\n }\n//reverse string\npublic static String rev(String s){\n StringBuilder sb=new StringBuilder(s);\n\t sb.reverse();\n\t return sb.toString();\n}\n//least common multiple\npublic static int lcm(int a, int b){\n return a * (b / gcd(a, b));\n}\n\n//depth first search\npublic static void dfs(ArrayList> adjLists,boolean[] neha,int v){\n neha[v]=true;\n //System.out.print(v+\" \");\n for(int w:adjLists.get(v)){\n if(!neha[w]){\n dfs(adjLists,neha,w);\n }\n }\n}\n\n//sieve prime\npublic static ArrayList sieve(int n,int m){\n boolean[] isPrime = new boolean[n+1];\n ArrayList al=new ArrayList();\n for (int i = 2; i <= n; i++)\n isPrime[i] = true;\n for (int factor = 2; factor*factor <=n; factor++) {\n if (isPrime[factor]) {\n for (int j = factor; factor*j <= n; j++)\n isPrime[factor*j] = false;\n }\n }\n int primes = 0;\n for (int i = m; i <= n; i++) {\n if (isPrime[i])\n al.add(i);\n }\n return al;\n }\n\n//input reader\nstatic class InputReader {\n private final InputStream stream;\n private final byte[] buf = new byte[8192];\n private int curChar, snumChars;\n public InputReader(InputStream st) {\n this.stream = st;\n }\n public int read() {\n if (snumChars == -1)\n throw new InputMismatchException();\n if (curChar >= snumChars) {\n curChar = 0;\n try {\n snumChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (snumChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do{\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n public long nextLong() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n public int[] nextIntArray(int n) {\n int a[] = new int[n];\n for (int i = 0; i < n; i++) {\n a[i] = nextInt();\n }\n return a;\n }\n\n public String readString() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public String readLine() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isEndOfLine(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n private boolean isEndOfLine(int c) {\n return c == '\\n' || c == '\\r' || c == -1;\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "greedy", "implementation"], "code_uid": "9d406a54c81124609ed19528c4552eb6", "src_uid": "283aff24320c6518e8518d4b045e1eca", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class Test {\n InputStream is;\n PrintWriter out;\n String INPUT = \"\";\n long[] F;\n\n void solve()\n {\n F = new long[17];\n F[0] = 1;\n for(int i = 1;i <= 16;i++)F[i] = F[i-1] * i;\n\n long K = nl();\n int t = ni();\n K--;\n gouter:\n for(int len = 1;;len++){\n long ret = 0;\n int[] rem = new int[16];\n Arrays.fill(rem, t);\n outer:\n for(int i = 0;i < len;i++){\n for(int j = i == 0 ? 1 : 0;j < 16;j++){\n rem[j]--;\n long count = count(rem, len-1-i);\n if(K < count){\n ret = ret * 16 + j;\n continue outer;\n }else{\n K -= count;\n }\n rem[j]++;\n }\n continue gouter;\n }\n out.println(Long.toHexString(ret));\n return;\n }\n }\n\n long count(int[] rem, int len)\n {\n long[] dp = new long[len+1];\n dp[0] = F[len];\n for(int x : rem){\n if(x < 0)return 0;\n if(x == 0)continue;\n for(int i = len;i >= 0;i--){\n for (int j = 1; j <= x; j++) {\n if ((i - j) < 0) break;\n dp[i] += dp[i - j] / F[j];\n }\n }\n }\n return dp[len];\n }\n\n void run() throws Exception\n {\n is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n out = new PrintWriter(System.out);\n\n long s = System.currentTimeMillis();\n solve();\n out.flush();\n tr(System.currentTimeMillis()-s+\"ms\");\n }\n\n public static void main(String[] args) throws Exception { new Test().run(); }\n\n private byte[] inbuf = new byte[1024];\n private int lenbuf = 0, ptrbuf = 0;\n\n private int readByte()\n {\n if(lenbuf == -1)throw new InputMismatchException();\n if(ptrbuf >= lenbuf){\n ptrbuf = 0;\n try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n if(lenbuf <= 0)return -1;\n }\n return inbuf[ptrbuf++];\n }\n\n private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\n private double nd() { return Double.parseDouble(ns()); }\n private char nc() { return (char)skip(); }\n\n private String ns()\n {\n int b = skip();\n StringBuilder sb = new StringBuilder();\n while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n sb.appendCodePoint(b);\n b = readByte();\n }\n return sb.toString();\n }\n\n private char[] ns(int n)\n {\n char[] buf = new char[n];\n int b = skip(), p = 0;\n while(p < n && !(isSpaceChar(b))){\n buf[p++] = (char)b;\n b = readByte();\n }\n return n == p ? buf : Arrays.copyOf(buf, p);\n }\n\n private char[][] nm(int n, int m)\n {\n char[][] map = new char[n][];\n for(int i = 0;i < n;i++)map[i] = ns(m);\n return map;\n }\n\n private int[] na(int n)\n {\n int[] a = new int[n];\n for(int i = 0;i < n;i++)a[i] = ni();\n return a;\n }\n\n private int ni()\n {\n int num = 0, b;\n boolean minus = false;\n while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n if(b == '-'){\n minus = true;\n b = readByte();\n }\n\n while(true){\n if(b >= '0' && b <= '9'){\n num = num * 10 + (b - '0');\n }else{\n return minus ? -num : num;\n }\n b = readByte();\n }\n }\n\n private long nl()\n {\n long num = 0;\n int b;\n boolean minus = false;\n while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n if(b == '-'){\n minus = true;\n b = readByte();\n }\n\n while(true){\n if(b >= '0' && b <= '9'){\n num = num * 10 + (b - '0');\n }else{\n return minus ? -num : num;\n }\n b = readByte();\n }\n }\n\n private boolean oj = true;//System.getProperty(\"ONLINE_JUDGE\") != null;\n private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}", "lang_cluster": "Java", "tags": ["brute force", "math", "dp", "combinatorics"], "code_uid": "ab89f6444d812168e7919f36912060e1", "src_uid": "cbfc354cfa392cd021d9fe899a745f0e", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n BufferedReader in;\n StringTokenizer str;\n PrintWriter out;\n String SK;\n String next() throws IOException {\n while ((str == null) || (!str.hasMoreTokens())) {\n SK = in.readLine();\n if (SK == null)\n return null;\n str = new StringTokenizer(SK);\n }\n return str.nextToken();\n }\n int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n char[] charArray() throws IOException{\n return next().toCharArray();\n }\n public static void main(String[] args) throws IOException {\n new Solution().run();\n }\n void run() throws IOException {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n //in = new BufferedReader(new FileReader(\"input.txt\"));\n //out = new PrintWriter(\"output.txt\");\n solve();\n out.close();\n }\n void solve() throws IOException {\n int n=nextInt();\n int ar[] = new int[n];\n int res=0;\n for (int i = 0; i < n; i++) {\n ar[i] = nextInt();\n if(ar[i]==1){\n res++;\n }\n }\n int max=0;\n int res2=0;\n for (int i = 0; i < n; i++) {\n for (int j = i; j < n; j++) {\n max=0;\n int o=0;\n for (int k = i; k <= j; k++) {\n if(ar[k]==0){\n max++;\n }\n else o++;\n }\n res2=Math.max(res2,max+res-o);\n \n }\n }\n out.println(res2);\n }\n \n}\n", "lang_cluster": "Java", "tags": ["brute force", "dp", "implementation"], "code_uid": "d53e0bd69e89075ede81893cf7f14063", "src_uid": "9b543e07e805fe1dd8fa869d5d7c8b99", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n\n\nimport java.io.*;\nimport java.util.*;\n/**\n *\n * @author Rohan\n */\npublic class Main {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n // TODO code application logic here\n input();\n }\n \n static int u;\n static int l;\n static int a,b,c,d;\n public static void input() {\n InputReader in=new InputReader(System.in);\n PrintWriter out=new PrintWriter(System.out);\n \n int n=in.readInt(); a=b=c=d=0; int p,q;\n for(int i=0;i0) return 1;\n return -1;\n }\n}\nclass InputReader {\n\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n \n public long readLong() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n long sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public String readString() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public String next() {\n return readString();\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n}", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "565f06eb60396d94cbbdd0eb132e9531", "src_uid": "f9bc04aed2b84c7dd288749ac264bb43", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.Scanner;\n\npublic class A58 {\n\tpublic static void main(String[] args) {\n\t\tScanner scanner = new Scanner(System.in);\n\t\tString s = scanner.next();\n\t\tQueue queue = new LinkedList();\n\t\tqueue.add(\"h\");\n\t\tqueue.add(\"e\");\n\t\tqueue.add(\"l\");\n\t\tqueue.add(\"l\");\n\t\tqueue.add(\"o\");\n\t\tfor(int i = 0, len = s.length(); i < len; ++i){\n\t\t\tif(0 == queue.size()){\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tString temp = queue.peek();\n\t\t\tif(s.substring(i, i+1).equals(temp)){\n\t\t\t\tqueue.poll();\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(0 == queue.size() ? \"YES\" : \"NO\");\n\t\t\n\t}\n}\n", "lang_cluster": "Java", "tags": ["greedy", "strings"], "code_uid": "e1855ab05b1397c0dd910a43df5f9a04", "src_uid": "c5d19dc8f2478ee8d9cba8cc2e4cd838", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\n// B. Network Configuration\n// https://codeforces.com/problemset/problem/448/A\n\n\nimport java.util.Scanner;\n\npublic class A23 {\n\tpublic static void main(String[] args) {\n\t\t\n\t\tScanner sc = new Scanner(System.in);\n\t\n\t\t\n\t\tint c=0;\n\t\tfor(int i = 0; i<3;i++)\n\t\t\tc+=sc.nextInt();\n\t\t\n\t\tint m=0;\n\t\tfor(int i = 0; i<3;i++)\n\t\t\tm+=sc.nextInt();\n\t\t\n\t\tint s=sc.nextInt();\n\t\t\n\t\tint s1= c/5 + (c%5==0?0:1);\n\t\tint s2= m/10 + (m%10==0?0:1);\n\t\t\n\t\ts-=s1;\n\t\ts-=s2;\n\t\t\n\t\tif(s<0)\n\t\t\tSystem.out.println(\"NO\");\n\t\telse\n\t\t\tSystem.out.println(\"YES\");\n\t\t\n\t}\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "ed5b095766014cc09d9d3422d1960a80", "src_uid": "fe6301816dea7d9cea1c3a06a7d1ea7e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\n//package que_a;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class utkarsh {\n\n InputStream is;\n PrintWriter out;\n \n long inf = (long) (1e15);\n boolean SHOW_TIME;\n \n void solve() {\n //Enter code here utkarsh\n //SHOW_TIME = true;\n double x1 = nd(), y1 = nd();\n double x2 = nd(), y2 = nd();\n double x3 = nd(), y3 = nd();\n double m1 = inf;\n if(x1 != x2) m1 = (y2 - y1) / (x2 - x1);\n double m2 = inf;\n if(x2 != x3) m2 = (y3 - y2) / (x3 - x2);\n long d1 = (long)((y2 - y1) * (y2 - y1)) + (long)((x2 - x1) * (x2 - x1));\n long d2 = (long)((y3 - y2) * (y3 - y2)) + (long)((x3 - x2) * (x3 - x2));\n //out.println(d1 +\" \"+ d2);\n if(m1 == m2 || d1 != d2) {\n out.println(\"No\");\n } else {\n out.println(\"Yes\");\n }\n }\n\n //---------- I/O Template ----------\n \n public static void main(String[] args) { new utkarsh().run(); }\n void run() { \n is = System.in; \n out = new PrintWriter(System.out);\n long start = System.currentTimeMillis(); \n solve(); \n long end = System.currentTimeMillis();\n if(SHOW_TIME) out.println(\"\\n\" + (end - start) + \" ms\");\n out.flush();\n }\n \n byte input[] = new byte[1024];\n int len = 0, ptr = 0;\n \n int readByte() { \n if(ptr >= len) { ptr = 0; \n try { len = is.read(input); } \n catch(IOException e) { throw new InputMismatchException(); } \n if(len <= 0) { return -1; } \n } return input[ptr++];\n }\n boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }\n int skip() { \n int b = readByte(); \n while(b != -1 && isSpaceChar(b)) { b = readByte(); } \n return b;\n }\n \n char nc() { return (char)skip(); }\n String ns() { \n int b = skip(); \n StringBuilder sb = new StringBuilder(); \n while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); } \n return sb.toString();\n }\n String nLine() { \n int b = skip(); \n StringBuilder sb = new StringBuilder(); \n while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); } \n return sb.toString();\n }\n int ni() { \n int n = 0, b = readByte(); \n boolean minus = false; \n while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); } \n if(b == '-') { minus = true; b = readByte(); } \n if(b == -1) { return -1; } //no input \n while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); } \n return minus ? -n : n;\n }\n long nl() { \n long n = 0L; int b = readByte(); \n boolean minus = false; \n while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); } \n if(b == '-') { minus = true; b = readByte(); } \n while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); } \n return minus ? -n : n;\n }\n\n double nd() { return Double.parseDouble(ns()); }\n float nf() { return Float.parseFloat(ns()); }\n int[] na(int n) { \n int a[] = new int[n]; \n for(int i = 0; i < n; i++) { a[i] = ni(); } \n return a;\n }\n char[] ns(int n) { \n char c[] = new char[n]; \n int i, b = skip(); \n for(i = 0; i < n; i++) { \n if(isSpaceChar(b)) { break; } \n c[i] = (char)b; b = readByte(); \n } return i == n ? c : Arrays.copyOf(c,i);\n }\n}", "lang_cluster": "Java", "tags": ["math", "geometry"], "code_uid": "b3cff25030373b82d68c4631bc5629aa", "src_uid": "05ec6ec3e9ffcc0e856dc0d461e6eeab", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\npublic class Task{\npublic static void main(String[] args) throws FileNotFoundException, IOException{\n Scanner s=new Scanner(System.in);\n BufferedWriter out=new BufferedWriter(new OutputStreamWriter(System.out));\n int n1=s.nextInt(),m1=s.nextInt();\n int n=Math.min(n1,m1),m=Math.min(2*n,n1+m1-n); \n int x=2*n-m,y=2*m-n; \n out.write(x/3+y/3+(x%3+y%3)/3+\"\");\n out.flush();\n }\n}", "lang_cluster": "Java", "tags": ["math", "greedy", "implementation", "number theory"], "code_uid": "a73f970c78014c3588e321450f06eedc", "src_uid": "0718c6afe52cd232a5e942052527f31b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class A {\n\n private boolean can(String s) {\n boolean can = true;\n for (int i = 0; i < s.length(); i++) {\n if (Character.isLowerCase(s.charAt(i))) can = false;\n }\n\n if (can) {\n return true;\n }\n return false;\n }\n\n private void solve() throws IOException {\n String s = nextToken();\n if (can(s)) {\n System.out.println(s.toLowerCase());\n return;\n }\n if (Character.isLowerCase(s.charAt(0))) {\n if (can(s.substring(1))) {\n System.out.println(Character.toUpperCase(s.charAt(0)) + s.substring(1).toLowerCase());\n return;\n }\n }\n System.out.println(s);\n }\n\n public static void main(String[] args) {\n new A().run();\n }\n\n BufferedReader reader;\n StringTokenizer tokenizer;\n PrintWriter writer;\n\n public void run() {\n try {\n reader = new BufferedReader(new InputStreamReader(System.in));\n tokenizer = null;\n writer = new PrintWriter(System.out);\n solve();\n reader.close();\n writer.close();\n }\n catch (Exception e) {\n e.printStackTrace();\n System.exit(1);\n }\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n BigInteger nextBigInteger() throws IOException {\n return new BigInteger(nextToken());\n }\n\n String nextToken() throws IOException {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(reader.readLine());\n }\n return tokenizer.nextToken();\n }\n}\n", "lang_cluster": "Java", "tags": ["strings", "implementation"], "code_uid": "2c58808dab26a31ef66794eb1e9d6b72", "src_uid": "db0eb44d8cd8f293da407ba3adee10cf", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n/**\n *\n */\npublic class TaskA {\n public static void main(String[] args) {\n InputStream inputStream;\n String str = null;\n if(str == null){\n inputStream = System.in;\n }else{\n inputStream = new ByteArrayInputStream(str.getBytes());\n }\n \n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n Solver solver = new Solver();\n solver.solve(1, in, out);\n out.close();\n }\n \n\n static class Solver {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int cost = in.nextInt();\n int current = in.nextInt();\n int bananas = in.nextInt();\n \n int total = cost*(bananas*(bananas+1)/2);\n \n System.out.println(Math.max(0,total-current)); \n }\n }\n \n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n \n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n \n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(next());\n }\n \n public long nextLong() {\n return Long.parseLong(next());\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "math", "implementation"], "code_uid": "381ede732fa6a9f0793b79536401eaed", "src_uid": "e87d9798107734a885fd8263e1431347", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "/**\n * Created by gosugdr on 4/22/15.\n */\n\nimport java.util.*;\nimport java.io.*;\n\npublic class A379 {\n FastScanner in;\n PrintWriter out;\n\n public void solve() throws IOException {\n out.println(in.nextInt() > in.nextInt() ? \"First\" : \"Second\");\n }\n\n public void run() {\n try {\n in = new FastScanner(System.in);\n out = new PrintWriter(System.out);\n\n solve();\n\n out.close();\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n\n class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n FastScanner(InputStream inputStream) {\n br = new BufferedReader(new InputStreamReader(inputStream));\n }\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n }\n\n public static void main(String[] arg) {\n new A379().run();\n }\n}\n\n ", "lang_cluster": "Java", "tags": ["math", "constructive algorithms"], "code_uid": "2a35d7d5e6d19a2f634176c022e03f83", "src_uid": "aed24ebab3ed9fd1741eea8e4200f86b", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class A{\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int start = in.nextInt();\n int distance = in.nextInt();\n int walk = (distance)%n; // gives effective distance\n\n if (start + walk < 0){\n // System.out.println(\"Less\");\n int out = (n +(walk + start));\n System.out.println(out);\n }else if (start + walk == 0){\n // System.out.println(\"equal\");\n System.out.println(n);\n }else{\n // System.out.println(\"greater\");\n if ((start+walk)%n == 0)\n System.out.println(n);\n else\n System.out.println((start+walk)%n); \n }\n }\n}", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "79ef059275418a92e9ea007506e0696b", "src_uid": "cd0e90042a6aca647465f1d51e6dffc4", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\n\n \nimport java.io.*;\n \n \n import java.util.*;\n\n public class Training {\n \n public static void main(String[] args) throws IOException {\n Scanner input = new Scanner(System.in);\n long n = input.nextLong(),k= input.nextLong();\n \n long a = n/2/(k+1);\n long b = a *k ;\n System.out.println(a +\" \"+b+\" \"+(n-a-b));\n \n \n\n } // end main \n \n }", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "84a64fe4cc96ac9ae4771834484fec82", "src_uid": "405a70c3b3f1561a9546910ab3fb5c80", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "\npublic class C {\n\n\tpublic C () {\n\t\tlong N = sc.nextLong();\n\n\t\tint res = 0;\n\t\tfor (int k : rep(1, 2000000)) {\n\t\t\tlong M = N - 2*k;\n\t\t\tif (M % 3 == 0)\n\t\t\t\tif (M/3 >= 1L*k*(k-1)/2)\n\t\t\t\t\t++res;\n\t\t}\n\n\t\texit(res);\n\t}\n\n\tprivate static int [] rep(int S, int T) { if (T <= S) return new int [0]; int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }\n\t////////////////////////////////////////////////////////////////////////////////////\n\tprivate final static IOUtils.MyScanner sc = new IOUtils.MyScanner();\n\tprivate static void exit (Object o, Object ... A) { IOUtils.print(o, A); IOUtils.exit(); }\n\tprivate static class IOUtils {\n\t\tpublic static class MyScanner {\n\t\t\tpublic String next() { newLine(); return line[index++]; }\n\t\t\tpublic long nextLong() { return Long.parseLong(next()); }\n\t\t\t//////////////////////////////////////////////\n\t\t\tprivate boolean eol() { return index == line.length; }\n\t\t\tprivate String readLine() {\n\t\t\t\ttry {\n\t\t\t\t\treturn r.readLine();\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\tthrow new Error (e);\n\t\t\t\t}\n\t\t\t}\n\t\t\tprivate final java.io.BufferedReader r;\n\t\t\tprivate MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }\n\t\t\tprivate MyScanner (java.io.BufferedReader r) {\n\t\t\t\ttry {\n\t\t\t\t\tthis.r = r;\n\t\t\t\t\twhile (!r.ready())\n\t\t\t\t\t\tThread.sleep(1);\n\t\t\t\t\tstart();\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\tthrow new Error(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\tprivate String [] line;\n\t\t\tprivate int index;\n\t\t\tprivate void newLine() {\n\t\t\t\tif (line == null || eol()) {\n\t\t\t\t\tline = split(readLine());\n\t\t\t\t\tindex = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tprivate String [] split(String s) { return s.length() > 0 ? s.split(\" \") : new String [0]; }\n\t\t}\n\t\tprivate static String build(Object o, Object ... A) { return buildDelim(\" \", o, A); }\n\t\tprivate static String buildDelim(String delim, Object o, Object ... A) {\n\t\t\tStringBuilder b = new StringBuilder();\n\t\t\tappend(b, o, delim);\n\t\t\tfor (Object p : A)\n\t\t\t\tappend(b, p, delim);\n\t\t\treturn b.substring(delim.length());\n\t\t}\n\t\t//////////////////////////////////////////////////////////////////////////////////\n\t\tprivate static void start() { if (t == 0) t = millis(); }\n\t\tprivate static void append(StringBuilder b, Object o, String delim) {\n\t\t\tif (o.getClass().isArray()) {\n\t\t\t\tint len = java.lang.reflect.Array.getLength(o);\n\t\t\t\tfor (int i = 0; i < len; ++i)\n\t\t\t\t\tappend(b, java.lang.reflect.Array.get(o, i), delim);\n\t\t\t} else if (o instanceof Iterable)\n\t\t\t\tfor (Object p : (Iterable) o)\n\t\t\t\t\tappend(b, p, delim);\n\t\t\telse {\n\t\t\t\tif (o instanceof Double)\n\t\t\t\t\to = new java.text.DecimalFormat(\"#.############\").format(o);\n\t\t\t\tb.append(delim).append(o);\n\t\t\t}\n\t\t}\n\t\tprivate static java.io.PrintWriter pw = new java.io.PrintWriter(System.out);\n\t\tprivate static void print(Object o, Object ... A) { pw.println(build(o, A)); }\n\t\tprivate static void err(Object o, Object ... A) { System.err.println(build(o, A)); }\n\t\tprivate static void exit() {\n\t\t\tIOUtils.pw.close();\n\t\t\tSystem.out.flush();\n\t\t\terr(\"------------------\");\n\t\t\terr(IOUtils.time());\n\t\t\tSystem.exit(0);\n\t\t}\n\t\tprivate static long t;\n\t\tprivate static long millis() { return System.currentTimeMillis(); }\n\t\tprivate static String time() { return \"Time: \" + (millis() - t) / 1000.0; }\n\t}\n\tpublic static void main (String[] args) { new C(); IOUtils.exit(); }\n}\n", "lang_cluster": "Java", "tags": ["math", "greedy", "binary search", "brute force"], "code_uid": "fa1b5827fb634313d0bfcd0869080806", "src_uid": "ab4f9cb3bb0df6389a4128e9ff1207de", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "\nimport java.util.Scanner;\n\npublic class Main \n{\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner input = new Scanner (System.in);\n\t\tint N;\n\t\twhile(input.hasNext())\n\t\t{\n\t\t\tN = input.nextInt();\n\t\t\tint ans = (N/7)*2;\n\t\t\tint Mod = N%7;\n\t\t\tif(Mod == 0)\n\t\t\t\tSystem.out.printf(\"%d %d\\n\",ans, ans);\n\t\t\telse if(Mod == 1)\n\t\t\t\tSystem.out.printf(\"%d %d\\n\",ans, ans+1);\n\t\t\telse if(Mod >= 2 && Mod <= 5)\n\t\t\t\tSystem.out.printf(\"%d %d\\n\",ans, ans+2);\n\t\t\telse\n\t\t\t\tSystem.out.printf(\"%d %d\\n\",ans+1, ans+2);\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "greedy", "constructive algorithms", "brute force"], "code_uid": "282091f1ef3ede3e84cf3a05737ff1a2", "src_uid": "8152daefb04dfa3e1a53f0a501544c35", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.util.concurrent.CompletableFuture;\nimport java.util.function.BiConsumer;\nimport java.util.function.BiFunction;\nimport java.util.function.Consumer;\nimport java.util.function.Function;\nimport java.util.stream.Collectors;\nimport java.util.stream.IntStream;\nimport java.util.stream.Stream;\nimport java.util.Map.Entry;\n\npublic class Main implements Runnable {\n static final int MOD = (int) 1e9 + 7;\n static final int MI = (int) 1e9;\n static final long ML = (long) 1e18;\n static final Reader in = new Reader();\n static final PrintWriter out = new PrintWriter(System.out);\n StringBuilder answer = new StringBuilder();\n Random random = new Random(751454315315L + System.currentTimeMillis());\n\n public static void main(String[] args) {\n new Thread(null, new Main(), \"persefone\", 1 << 28).start();\n }\n\n @Override\n public void run() {\n solve();\n printf();\n flush();\n }\n\n void solve() {\n int[] s = in.next().chars().map(n -> n - '0').toArray();\n int m = in.nextInt();\n int n = s.length;\n long[][] dp = new long[1 << n][m];\n dp[0][0] = 1;\n for (int mask = 0; mask < 1 << n; mask++) {\n for (int reminder = 0; reminder < m; reminder++) {\n if (dp[mask][reminder] == 0) {\n continue;\n }\n for (int pos = 0; pos < n; pos++) {\n if (mask == 0 && s[pos] == 0) continue;\n if ((mask & (1 << pos)) > 0) continue;\n int new_reminder = (10 * reminder + s[pos]) % m;\n dp[mask | (1 << pos)][new_reminder] += dp[mask][reminder];\n }\n }\n }\n long ans = dp[(1 << n) - 1][0];\n long[] fact = new long[20];\n fact[0] = 1;\n for (int i = 1; i < 20; i++) {\n fact[i] = fact[i - 1] * i;\n }\n int[] cnt = new int[10];\n for (int i = 0; i < n; i++) {\n cnt[s[i]]++;\n }\n for (int i = 0; i < 10; i++) {\n ans /= fact[cnt[i]];\n }\n printf(ans);\n }\n\n void printf() {\n out.print(answer);\n }\n\n void close() {\n out.close();\n }\n\n void flush() {\n out.flush();\n }\n\n void printf(Stream str) {\n str.forEach(o -> add(o, \" \"));\n add(\"\\n\");\n }\n\n\n void printf(Object... obj) {\n printf(false, obj);\n }\n\n void printfWithDescription(Object... obj) {\n printf(true, obj);\n }\n\n\n private void printf(boolean b, Object... obj) {\n\n if (obj.length > 1) {\n for (int i = 0; i < obj.length; i++) {\n if (b) add(obj[i].getClass().getSimpleName(), \" - \");\n if (obj[i] instanceof Collection) {\n printf((Collection) obj[i]);\n } else if (obj[i] instanceof int[][]) {\n printf((int[][]) obj[i]);\n } else if (obj[i] instanceof long[][]) {\n printf((long[][]) obj[i]);\n } else if (obj[i] instanceof double[][]) {\n printf((double[][]) obj[i]);\n } else printf(obj[i]);\n }\n return;\n }\n\n if (b) add(obj[0].getClass().getSimpleName(), \" - \");\n printf(obj[0]);\n }\n\n void printf(Object o) {\n if (o instanceof int[])\n printf(Arrays.stream((int[]) o).boxed());\n else if (o instanceof char[])\n printf(new String((char[]) o));\n else if (o instanceof long[])\n printf(Arrays.stream((long[]) o).boxed());\n else if (o instanceof double[])\n printf(Arrays.stream((double[]) o).boxed());\n else if (o instanceof boolean[]) {\n for (boolean b : (boolean[]) o) add(b, \" \");\n add(\"\\n\");\n } else\n add(o, \"\\n\");\n }\n\n void printf(int[]... obj) {\n for (int i = 0; i < obj.length; i++) printf(obj[i]);\n }\n\n void printf(long[]... obj) {\n for (int i = 0; i < obj.length; i++) printf(obj[i]);\n }\n\n void printf(double[]... obj) {\n for (int i = 0; i < obj.length; i++) printf(obj[i]);\n }\n\n void printf(boolean[]... obj) {\n for (int i = 0; i < obj.length; i++) printf(obj[i]);\n }\n\n void printf(Collection col) {\n printf(col.stream());\n }\n\n void add(T t, K k) {\n if (t instanceof Collection) {\n ((Collection) t).forEach(i -> add(i, \" \"));\n } else if (t instanceof Object[]) {\n Arrays.stream((Object[]) t).forEach(i -> add(i, \" \"));\n } else\n add(t);\n add(k);\n }\n\n\n void add(T t) {\n answer.append(t);\n }\n\n static class Reader {\n private BufferedReader br;\n private StringTokenizer st;\n\n Reader() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n Reader(String fileName) throws FileNotFoundException {\n br = new BufferedReader(new FileReader(fileName));\n }\n\n boolean isReady() throws IOException {\n return br.ready();\n }\n\n String next() {\n try {\n while (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(br.readLine());\n }\n } catch (IOException e) {\n e.printStackTrace();\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n int[] nextIntArray(int n) {\n int[] arr = new int[n];\n for (int i = 0; i < n; i++)\n arr[i] = nextInt();\n return arr;\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String nextLine() {\n String s = \"\";\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return s;\n }\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "dp", "combinatorics", "bitmasks", "number theory"], "code_uid": "6a135091ff4d898f4bcff4922915c26f", "src_uid": "5eb90c23ffa3794fdddc5670c0373829", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class tA {\n public static void main(String[] args) throws IOException {\n boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n Scanner in;\n PrintWriter out;\n if (oj) {\n in = new Scanner(System.in);\n out = new PrintWriter(System.out);\n }\n else {\n Reader reader = new FileReader(\"input.txt\");\n Writer writer = new FileWriter(\"output.txt\");\n in = new Scanner(new BufferedReader(reader));\n out = new PrintWriter(writer);\n }\n int[] s = new int[3];\n for (int i = 0; i < 3; i++)\n s[i] = in.nextInt();\n int a = 0, b = 0, c = 0;\n for (int i = 1; i <= s[0] + s[1] + s[2]; i++) {\n a = i;\n b = s[0] / a;\n c = s[2] / a;\n if (a * b == s[0] && b * c == s[1] && a * c == s[2])\n break;\n b = s[0] / a;\n c = s[1] / a;\n if (a * b == s[0] && b * c == s[1] && a * c == s[2])\n break;\n b = s[1] / a;\n c = s[2] / a;\n if (a * b == s[0] && b * c == s[1] && a * c == s[2])\n break;\n }\n out.println(4 * (a + b + c));\n out.flush();\n }\n\n}\n\n", "lang_cluster": "Java", "tags": ["brute force", "math", "geometry"], "code_uid": "9198df28b4b7e806bcab315c8184a436", "src_uid": "c0a3290be3b87f3a232ec19d4639fefc", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class a {\n\tpublic static void main(String[] arg) throws IOException {\n\t\tnew a();\n\t}\n\tpublic a() throws IOException {\n\t\tFastScanner in = new FastScanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t\n\t\tint n = in.nextInt();\n\t\tint k = in.nextInt();\n\t\tint total = 0;\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\ttotal += in.nextInt();\n\t\t\tint give = Math.min(8, total);\n\t\t\tk -= give;\n\t\t\ttotal -= give;\n\t\t\tif(k <= 0) {\n\t\t\t\tout.println(i+1);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif(k > 0) out.println(-1);\n\t\tin.close(); out.close();\n\t}\n\tclass FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FastScanner(InputStream in) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(in));\n\t\t\tst = new StringTokenizer(\"\");\n\t\t}\n\t\tpublic void close() throws IOException {\n\t\t\tbr.close();\n\t\t}\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tpublic String next() throws IOException {\n\t\t\twhile(!st.hasMoreElements()) st = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "b0c6282f9f45c39e9f596c98d4e5d0a4", "src_uid": "24695b6a2aa573e90f0fe661b0c0bd3a", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.PriorityQueue;\nimport java.util.Random;\nimport java.util.StringTokenizer;\nimport java.awt.PageAttributes.OriginType;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskC solver = new TaskC();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n\n\tstatic class TaskC {\n\t\tpublic void solve(int testNumber, InputReader in, PrintWriter out) {\n\t\t\tchar[] t1 = in.next().toCharArray();\n\t\t\tint[] t = new int[6];\n\t\t\tfor (int i = 0; i < 6; i++) {\n\t\t\t\tt[i] = t1[i] - '0';\n\t\t\t}\n\t\t\tint c = t[0] + t[1] + t[2];\n\t\t\tint c2 = t[3 + 0] + t[3 + 1] + t[3 + 2];\n\t\t\tif (c == c2) {\n\t\t\t\tout.println(\"0\");\n\t\t\t\treturn;\n\t\t\t} else if (c > c2) {\n\t\t\t\tfor (int i = 0; i < 3; i++) {\n\t\t\t\t\tint temp = t[i];\n\t\t\t\t\tt[i] = t[i + 3];\n\t\t\t\t\tt[i + 3] = temp;\n\t\t\t\t}\n\t\t\t\tint temp = c;\n\t\t\t\tc = c2;\n\t\t\t\tc2 = temp;\n\t\t\t}\n\t\t\tint step = 0;\n\t\t\twhile (c < c2) {\n\t\t\t\tstep++;\n\t\t\t\tint min = 9;\n\t\t\t\tint max = 0;\n\t\t\t\tfor (int i = 0; i < 3; i++) {\n\t\t\t\t\tmin = Math.min(min, t[i]);\n\t\t\t\t\tmax = Math.max(max, t[i + 3]);\n\t\t\t\t}\n\t\t\t\tif (9 - min > max) {\n\t\t\t\t\tc -= min;\n\t\t\t\t\tfor (int i = 0; i < 3; i++) {\n\t\t\t\t\t\tif (t[i] == min) {\n\t\t\t\t\t\t\tt[i] = 9;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tc += 9;\n\t\t\t\t} else {\n\t\t\t\t\tc2 -= max;\n\t\t\t\t\tc2 += 0;\n\t\t\t\t\tfor (int i = 3; i < 6; i++) {\n\t\t\t\t\t\tif (t[i] == max) {\n\t\t\t\t\t\t\tt[i] = 0;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tout.println(step);\n\t\t}\n\t}\n\n\tstatic class InputReader {\n\t\tpublic BufferedReader reader;\n\t\tpublic StringTokenizer tokenizer;\n\n\t\tpublic InputReader(InputStream stream) {\n\t\t\treader = new BufferedReader(new InputStreamReader(stream), 32768);\n\t\t\ttokenizer = null;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic double nextFloat() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t}\n}\n", "lang_cluster": "Java", "tags": ["brute force", "greedy", "implementation"], "code_uid": "13317a0f4c04a465d4d5b63e0bcb5a38", "src_uid": "09601fd1742ffdc9f822950f1d3e8494", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\nimport java.text.ParseException;\nimport java.text.SimpleDateFormat;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Calendar;\nimport java.util.Scanner;\n\npublic class Main {\n\n\n public static void main(String[] args) throws ParseException, IOException {\n\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n long n=Long.parseLong(br.readLine());\n System.out.println((int)Math.ceil(1.0*(n+1)/2));\n \n \n \n\n }\n}\n\n ", "lang_cluster": "Java", "tags": ["math"], "code_uid": "9693fdc58d77b222bcd5a1b2c0836cc2", "src_uid": "5551742f6ab39fdac3930d866f439e3e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskC {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int m = in.nextInt();\n long k = in.nextLong();\n int x = in.nextInt();\n int y = in.nextInt();\n long grid[][] = new long[n][m];\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n if (k > 0) {\n grid[i][j] = 1;\n k--;\n }\n }\n }\n\n if (k > 0 && n != 1) {\n long mid = (k / (m * n - m));\n boolean isUp = (k / (m * n - m)) % 2 == 0;\n long topRow = (k / (m * n - m)) / 2 + (!isUp ? 1 : 0);\n long bottomRow = ((k / (m * n - m)) / 2);\n long remK = (k % (m * n - m));\n for (int i = 0; i < grid.length; i++) {\n for (int j = 0; j < grid[0].length; j++) {\n if (i == 0) {\n grid[i][j] += topRow;\n } else if (i == n - 1) {\n grid[i][j] += bottomRow;\n } else {\n grid[i][j] += mid;\n }\n }\n }\n for (int i = isUp ? n - 2 : 1; i >= 0 && i < n; i += isUp ? -1 : 1) {\n for (int j = 0; j < m; j++) {\n if (remK > 0) {\n grid[i][j] += 1;\n remK--;\n } else {\n break;\n }\n }\n }\n } else if (n == 1) {\n for (int i = 0; i < m; i++) {\n grid[0][i] += k / m;\n }\n k = k % m;\n for (int i = 0; i < m; i++) {\n if (k > 0) {\n grid[0][i] += 1;\n k--;\n }\n\n }\n }\n long max = Long.MIN_VALUE;\n long min = Long.MAX_VALUE;\n for (long column[] : grid) {\n for (long cell : column) {\n max = Math.max(max, cell);\n min = Math.min(min, cell);\n }\n }\n out.println(max + \" \" + min + \" \" + grid[x - 1][y - 1]);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public long readLong() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n private boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public int nextInt() {\n return readInt();\n }\n\n public long nextLong() {\n return readLong();\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["math", "constructive algorithms", "binary search", "implementation"], "code_uid": "3db2b9895fc6eca5d708c756e44ace41", "src_uid": "e61debcad37eaa9a6e21d7a2122b8b21", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.PrintStream;\nimport java.lang.*;\nimport static java.lang.Character.isUpperCase;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.Map;\nimport java.util.Scanner;\nimport java.util.*;\nimport java.util.TreeMap;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\npublic class simple {\n\tstatic class FastReader \n\t { \n\t BufferedReader br; \n\t StringTokenizer st; \n\t \n\t public FastReader() \n\t { \n\t br = new BufferedReader(new\n\t InputStreamReader(System.in)); \n\t } \n\t \n\t String next() \n\t { \n\t while (st == null || !st.hasMoreElements()) \n\t { \n\t try\n\t { \n\t st = new StringTokenizer(br.readLine()); \n\t } \n\t catch (IOException e) \n\t { \n\t e.printStackTrace(); \n\t } \n\t } \n\t return st.nextToken(); \n\t } \n\t \n\t int nextInt() \n\t { \n\t return Integer.parseInt(next()); \n\t } \n\t \n\t long nextLong() \n\t { \n\t return Long.parseLong(next()); \n\t } \n\t \n\t double nextDouble() \n\t { \n\t return Double.parseDouble(next()); \n\t } \n\t \n\t String nextLine() \n\t { \n\t String str = \"\"; \n\t try\n\t { \n\t str = br.readLine(); \n\t } \n\t catch (IOException e) \n\t { \n\t e.printStackTrace(); \n\t } \n\t return str; \n\t } \n\t \n\t }\n\n\tpublic static void main(String[] args) {\n\t\tFastReader in=new FastReader();\n\t\tint a=in.nextInt();\n\t\tint b=in.nextInt();\n\t\tint c=in.nextInt();\n\t\tint d=in.nextInt();\n\t\tif(a==d)\n\t\t{\n\t\t\tif(c>0 && (a==0 || d==0) )\n\t\t\t\tSystem.out.println(0);\n\t\t\telse\n\t\t\tSystem.out.println(1);\n\t\t}\n\t\telse\n\t\t\tSystem.out.println(0);\n\t}\n}", "lang_cluster": "Java", "tags": ["greedy", "implementation"], "code_uid": "08ad79eb4b4f6843be75720f1c6ed8a4", "src_uid": "b99578086043537297d374dc01eeb6f8", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Scanner;\n\npublic class Main implements Runnable {\n\tpublic static void main(String[] args) {\n\t\tnew Thread(null, new Main(), \"\", Runtime.getRuntime().maxMemory()).start();\n\t\t// new Main().run();\n\t}\n\n\tArrayList div = new ArrayList<>();\n\n\tlong solve(long a, long b) {\n\t\tdiv.clear();\n\t\tdiv.add(a);\n\t\tlong a_ = a;\n\t\tfor (long v = 2; v * v <= a_; ++v)\n\t\t\tif (a_ % v == 0) {\n\t\t\t\tdiv.add(v);\n\t\t\t\tif (v != a_ / v)\n\t\t\t\t\tdiv.add(a_ / v);\n\t\t\t\twhile (a_ % v == 0) {\n\t\t\t\t\ta_ /= v;\n\t\t\t\t}\n\t\t\t}\n\t\tCollections.sort(div);\n\t\treturn f(a, b);\n\n\t}\n\n\tpublic void run() {\n\t\tScanner sc = new Scanner(System.in);\n\t\tlong a = sc.nextLong();\n\t\tlong b = sc.nextLong();\n\t\tSystem.out.println(solve(a, b));\n\t}\n\n\tlong check(long a, long b) {\n\t\tif (b == 0)\n\t\t\treturn 0;\n\t\treturn 1 + f(a, b - gcd(a, b));\n\t}\n\n\tlong f(long a, long b) {\n\t\tif (a == b)\n\t\t\treturn 1;\n\t\tif (b == 0) {\n\t\t\treturn 0;\n\t\t}\n\t\tif (a == 1) {\n\t\t\treturn b;\n\t\t}\n\t\tif (gcd(a, b) > 1) {\n\t\t\tlong gcd = gcd(a, b);\n\t\t\treturn f(a / gcd, b / gcd - 1) + 1;\n\t\t}\n\t\tlong nb = 1;\n\t\tfor (long i : div) {\n\t\t\tif (i > a)\n\t\t\t\tbreak;\n\t\t\tif (a % i == 0)\n\t\t\t\tnb = Math.max(nb, b / i * i);\n\t\t}\n\t\tif (b > a && nb < a) {\n\t\t\tnb = a;\n\t\t}\n\t\t// f(3,2)=f(3,1)+1=f(3,0)+2\n\t\tlong c = 1 + (b - nb);\n\t\tlong gcd = gcd(a, nb);\n\t\treturn c + f(a / gcd, nb / gcd - 1);\n\t}\n\n\tlong gcd(long a, long b) {\n\t\tif (a < b) {\n\t\t\tlong d = a;\n\t\t\ta = b;\n\t\t\tb = d;\n\t\t}\n\t\tif (b == 0) {\n\t\t\treturn a;\n\t\t}\n\t\treturn gcd(b, a % b);\n\t}\n\n\tstatic boolean isPrime(long n) {\n\t\t// \u9593\u9055\u3048\u308b\u78ba\u73874^(-k)=10^(-6)\n\t\tif (n == 1 || n % 2 == 0)\n\t\t\treturn false;\n\t\tlong z = n - 1;\n\t\tint c2 = 0;\n\t\twhile (z % 2 == 0) {\n\t\t\tz /= 2;\n\t\t\t++c2;\n\t\t}\n\t\touter: for (int k = 0; k < 10; ++k) {\n\t\t\tlong a = (int) (Math.random() * 10000) % n;\n\t\t\tif (a == 0)\n\t\t\t\tcontinue;\n\t\t\ta = pow(a, z, n);\n\t\t\tif (a == 1 || a == n - 1)\n\t\t\t\tcontinue outer;\n\t\t\tfor (int i = 0; i < c2 - 1; ++i) {\n\t\t\t\ta = (a * a) % n;\n\t\t\t\tif (a == n - 1)\n\t\t\t\t\tcontinue outer;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tstatic long pow(long a, long n, long mod) {\n\t\tlong ret = 1;\n\t\tfor (; n > 0; n >>= 1, a = (a * a) % mod) {\n\t\t\tif (n % 2 == 1) {\n\t\t\t\tret = (ret * a) % mod;\n\t\t\t}\n\t\t}\n\t\treturn ret;\n\t}\n\n\tstatic void tr(Object... objects) {\n\t\tSystem.out.println(Arrays.deepToString(objects));\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "implementation", "binary search"], "code_uid": "21516d3c977ffca2a20227155af764eb", "src_uid": "ea92cd905e9725e7fcb87b9ed4f64c2e", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.BigInteger;\nimport java.util.Map.Entry;\n\nimport static java.lang.Math.*;\n\npublic class Solution extends PrintWriter {\n\n\tvoid run() {\n\t\tlong rot = -nextLong();\n\t\tlong a = ((rot % 360) + 360) % 360;\n\n\t\tlong b = 360;\n\t\tint ans = 0;\n\n\t\tfor (int i = 0; i < 4; i++) {\n\t\t\tlong c = min(a, 360 - a);\n\t\t\tif (c < b) {\n\t\t\t\tb = c;\n\t\t\t\tans = i;\n\t\t\t}\n\t\t\ta = (a + 90) % 360;\n\t\t}\n\n\t\tprintln(ans);\n\n\t}\n\n\tint[][] nextMatrix(int n, int m) {\n\t\tint[][] matrix = new int[n][m];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t\tmatrix[i][j] = nextInt();\n\t\treturn matrix;\n\t}\n\n\tString next() {\n\t\twhile (!tokenizer.hasMoreTokens())\n\t\t\ttokenizer = new StringTokenizer(nextLine());\n\t\treturn tokenizer.nextToken();\n\t}\n\n\tboolean hasNext() {\n\t\twhile (!tokenizer.hasMoreTokens()) {\n\t\t\tString line = nextLine();\n\t\t\tif (line == null) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\ttokenizer = new StringTokenizer(line);\n\t\t}\n\t\treturn true;\n\t}\n\n\tint[] nextArray(int n) {\n\t\tint[] array = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tarray[i] = nextInt();\n\t\t}\n\t\treturn array;\n\t}\n\n\tint nextInt() {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tlong nextLong() {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tString nextLine() {\n\t\ttry {\n\t\t\treturn reader.readLine();\n\t\t} catch (IOException err) {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tpublic Solution(OutputStream outputStream) {\n\t\tsuper(outputStream);\n\t}\n\n\tstatic BufferedReader reader;\n\tstatic StringTokenizer tokenizer = new StringTokenizer(\"\");\n\tstatic Random rnd = new Random();\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tSolution solution = new Solution(System.out);\n\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\tsolution.run();\n\t\tsolution.close();\n\t\treader.close();\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "geometry"], "code_uid": "61d4d2ce32f60c56308dccce3e04724a", "src_uid": "509db9cb6156b692557ba874a09f150e", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "\nimport java.util.Scanner;\n\npublic class QAQ {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner s=new Scanner(System.in);\n\t\tString str=s.next();\n\t\tint n=str.length();\n\t\tint[] countOfQ=new int[n];\n\t\tif(str.charAt(0)=='Q') countOfQ[0]=1;\n\t\tfor(int i=1;i= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "3e7cc5648516d9f3a89ab9de0805d599", "src_uid": "cd351d1190a92d094b2d929bf1e5c44f", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\npublic class noob {\n InputReader in;\n final long mod=1000000007;\n long m=998244353;\n StringBuilder sb;\n public static void main(String[] args) throws java.lang.Exception {\n new noob().run();\n }\n void run() throws Exception {\n in=new InputReader(System.in);\n sb = new StringBuilder();\n int t=1;\n for(int i=1;i<=t;i++)\n solve();\n System.out.print(sb);\n } \n long fib(int n) {\n long a[]=new long[n+1];\n a[1]=1;\n for(int i=2;i<=n;i++)\n a[i]=(a[i-1]+a[i-2])%m;\n return a[n];\n }\n void solve() {\n int i,j,k;\n int n=i();\n long val=fib(n);\n long deno=power(2,n,m);\n long ans=(val%m * power(deno, m-2, m))%m;\n sb.append(ans+\"\\n\");\n }\n long power(long x, long y, long p) { \n long res = 1; \n x = x % p; \n if (x == 0) return 0; \n while (y > 0) {\n if((y & 1)==1) \n res = (res * x) % p; \n y = y >> 1; \n x = (x * x) % p; \n } \n return res%p; \n } \n int gcd(int a, int b) {\n return (b==0)?a:gcd(b,a%b);\n }\n String s(){return in.next();}\n int i(){return in.nextInt();}\n long l(){return in.nextLong();}\n double d(){return in.nextDouble();}\n class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n public int read() {\n if (numChars == -1)\n throw new UnknownError();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new UnknownError();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n public int peek() {\n if (numChars == -1)\n return -1;\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n return -1;\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar];\n }\n public void skip(int x) {\n while (x-->0)\n read();\n }\n public int nextInt() {\n return Integer.parseInt(next());\n }\n public long nextLong() {\n return Long.parseLong(next());\n }\n public String nextString() {\n return next();\n }\n public String next() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuffer res = new StringBuffer();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n \n return res.toString();\n }\n public String nextLine() {\n StringBuffer buf = new StringBuffer();\n int c = read();\n while (c != '\\n' && c != -1) {\n if (c != '\\r')\n buf.appendCodePoint(c);\n c = read();\n }\n return buf.toString();\n }\n public double nextDouble() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n double res = 0;\n while (!isSpaceChar(c) && c != '.') {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, nextInt());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n }\n if (c == '.') {\n c = read();\n double m = 1;\n while (!isSpaceChar(c)) {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, nextInt());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n m /= 10;\n res += (c - '0') * m;\n c = read();\n }\n }\n return res * sgn;\n }\n public boolean hasNext() {\n int value;\n while (isSpaceChar(value = peek()) && value != -1)\n read();\n return value != -1;\n }\n private boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n }\n}", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics"], "code_uid": "af1f0e5b3c0c60c2d8bd8b33700d90af", "src_uid": "cec37432956bb0a1ce62a0188fe2d805", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main {\n\n\tpublic static int primefactors(long n){\n\t\tfor (int i=3;i<=Math.sqrt(n);i+=2){\n\t\t\tif(n%i==0){\n\t\t\t\treturn i;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\treturn 0;\n\t}\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\nScanner sc = new Scanner (System.in);\nint m=0;\nint t=sc .nextInt();\n\nwhile(t-->0){\n\tlong n=sc .nextLong();\n\tif (n%2==0){\n\t\tSystem.out.println( n/2+\" \"+n/2);\n\t\t\n\t\n\t}\n\telse{\n\t\t\n\tm=primefactors(n);\n\tif(m!=0){\n\tSystem.out.println((n/m)+\" \"+(n-n/m));\n\t}\n\telse{\n\t\tSystem.out.println(1+\" \"+ (n-1));\n\t}\n\t\n\t}\n\n}}}\n", "lang_cluster": "Java", "tags": ["math", "greedy", "number theory"], "code_uid": "c88fe8fb4256ba6c7b69058c9b6673ef", "src_uid": "3fd60db24b1873e906d6dee9c2508ac5", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main {\n static Scanner scanner = new Scanner(System.in);\n\n public static void main(String[] args) {\n int n=scanner.nextInt();\n int m=scanner.nextInt();\n m--;\n int max=scanner.nextInt();\n int a[]=new int[n];\n for (int i=0;i=0;i--){\n if (a[i]!=0 && a[i]<=max){\n minL=i;\n break;\n }\n }\n if (minR ==-1){\n System.out.println(Math.abs(minL-m)*10);\n }else if (minL ==-1){\n System.out.println(Math.abs(minR-m)*10);\n }else {\n System.out.println(Math.min(Math.abs(minR-m),Math.abs(minL-m))*10);\n }\n\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "6dfeaf11a49000a9b7e9ef45bd753032", "src_uid": "57860e9a5342a29257ce506063d37624", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.lang.*;\nimport static java.lang.Math.*;\n \npublic class TestClass //implements Runnable\n{\n\t/*\n\tint x,y;\n\tpublic TestClass(int x,int y)\n\t{\n\t\tthis.x=x;\n\t\tthis.y=y;\n\t}*/\n\t\n\t\n\t\n\tpublic static void main(String args[]) throws Exception\n\t{/*\n\t\tnew Thread(null, new TestClass(),\"TESTCLASS\",1<<18).start();\n\t}\n\tpublic void run()\n\t{*/\n\t\t//Scanner scan=new Scanner(System.in);\n\t\tInputReader hb=new InputReader(System.in);\n\t\tPrintWriter w=new PrintWriter(System.out);\n\t\t\n\t\tint n=hb.nextInt();\n\t\tint m=hb.nextInt();\n\t\tint k=hb.nextInt();\n\t\t\n\t\tint x=(int)Math.ceil((double)k/(2*m));\n\t\tw.print(x+\" \");\n\t\tint y=(x-1)*2*m;\n\t\ty=k-y;\n\t\tw.print((int)Math.ceil((double)y/2)+\" \");\n\t\tif(k%2==0)\n\t\t\tw.print(\"R\");\n\t\telse\n\t\t\tw.print(\"L\");\n\t\tw.close();\n\t}\n\t\n\tpublic static long count(long l, long r)\n\t{\n\t\tif (l == r)\n\t\t\treturn l;\n\t\t\n\t\tlong b = (long) (Math.log(r) / Math.log(2));\n\t\tlong num = (long) Math.pow(2, b);\n\t\t\n\t\tif (num <= l)\n\t\t\treturn count(l - num, r - num) + num;\n\t\telse if (2 * num - 1 <= r)\n\t\t\treturn 2 * num - 1;\n\t\telse\n\t\t\treturn num - 1;\n\t}\n\t\n\tprivate void shuffle(int[] arr)\n\t{\n\t\tRandom ran = new Random();\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\tint i1 = ran.nextInt(arr.length);\n\t\t\tint i2 = ran.nextInt(arr.length);\n\n\t\t\tint temp = arr[i1];\n\t\t\tarr[i1] = arr[i2];\n\t\t\tarr[i2] = temp;\n\t\t}\n\t}\n\t\n\tstatic class DSU\n\t{\n\t\tint parent[];\n\t\tint sizeParent[];\n\t\tDSU(int n)\n\t\t{\n\t\t\tparent=new int[n];\n\t\t\tsizeParent=new int[n];\n\t\t\tArrays.fill(sizeParent,1);\n\t\t\tfor(int i=0;i=sizeParent[y])\n\t\t\t{\n\t\t\t\tif(x!=y)\n\t\t\t\t\tsizeParent[x]+=sizeParent[y];\n\t\t\t\tparent[y]=x;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif(x!=y)\n\t\t\t\t\tsizeParent[y]+=sizeParent[x];\n\t\t\t\tparent[x]=y;\n\t\t\t}\n\t\t}\n\t}\n\t\n\tstatic class InputReader\n\t{\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n\t\tprivate SpaceCharFilter filter;\n\t\t\n\t\tpublic InputReader(InputStream stream)\n\t\t{\n\t\t\tthis.stream = stream;\n\t\t}\n\t\t\n\t\tpublic int read()\n\t\t{\n\t\t\tif (numChars==-1) \n\t\t\t\tthrow new InputMismatchException();\n\t\t\t\n\t\t\tif (curChar >= numChars)\n\t\t\t{\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry \n\t\t\t\t{\n\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t}\n\t\t\t\tcatch (IOException e)\n\t\t\t\t{\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif(numChars <= 0)\t\t\t\t\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\t \n\t\tpublic String nextLine()\n\t\t{\n\t\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\t\tString str = \"\";\n\t\t\ttry\n\t\t\t{\n\t\t\t\tstr = br.readLine();\n\t\t\t}\n\t\t\tcatch (IOException e)\n\t\t\t{\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\t\tpublic int nextInt()\n\t\t{\n\t\t\tint c = read();\n\t\t\t\n\t\t\twhile(isSpaceChar(c)) \n\t\t\t\tc = read();\n\t\t\t\n\t\t\tint sgn = 1;\n\t\t\t\n\t\t\tif (c == '-') \n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\t\n\t\t\tint res = 0;\n\t\t\tdo \n\t\t\t{\n\t\t\t\tif(c<'0'||c>'9') \n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\twhile (!isSpaceChar(c)); \n\t\t\t\n\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic long nextLong() \n\t\t{\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') \n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\t\n\t\t\tdo \n\t\t\t{\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\twhile (!isSpaceChar(c));\n\t\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic double nextDouble() \n\t\t{\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') \n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tdouble res = 0;\n\t\t\twhile (!isSpaceChar(c) && c != '.') \n\t\t\t{\n\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\treturn res * Math.pow(10, nextInt());\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tif (c == '.') \n\t\t\t{\n\t\t\t\tc = read();\n\t\t\t\tdouble m = 1;\n\t\t\t\twhile (!isSpaceChar(c)) \n\t\t\t\t{\n\t\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\t\treturn res * Math.pow(10, nextInt());\n\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\tm /= 10;\n\t\t\t\t\tres += (c - '0') * m;\n\t\t\t\t\tc = read();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic String readString() \n\t\t{\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo \n\t\t\t{\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} \n\t\t\twhile (!isSpaceChar(c));\n\t\t\t\n\t\t\treturn res.toString();\n\t\t}\n\t \n\t\tpublic boolean isSpaceChar(int c) \n\t\t{\n\t\t\tif (filter != null)\n\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\t \n\t\tpublic String next() \n\t\t{\n\t\t\treturn readString();\n\t\t}\n\t\t\n\t\tpublic interface SpaceCharFilter \n\t\t{\n\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t}\n \n\tstatic class Pair implements Comparable\n\t{\n\t\tint a;\n\t\tint b;\n\t\tString str;\n\t\tpublic Pair(int a,int b)\n\t\t{\n\t\t\tthis.a=a;\n\t\t\tthis.b=b;\n\t\t\tstr=min(a,b)+\" \"+max(a,b);\n\t\t}\n \n\t\tpublic int compareTo(Pair pair)\n\t\t{\n\t\t\tif(Integer.compare(a,pair.a)==0)\n\t\t\t\treturn Integer.compare(b,pair.b);\n \n\t\t\treturn Integer.compare(a,pair.a);\n\t\t}\n\t}\n \n\t\n}", "lang_cluster": "Java", "tags": ["math", "constructive algorithms"], "code_uid": "0288800c799b775c91c18c752f4c74b8", "src_uid": "d6929926b44c2d5b1a8e6b7f965ca1bb", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\n\npublic class B {\n public static void main(String[] args) throws Exception {\n new B().solve();\n }\n \n boolean[] xd=new boolean[10];//0~9\n void solve() throws IOException {\n // BufferedReader in = new BufferedReader(new\n // InputStreamReader(System.in));\n Scanner sc = new Scanner(System.in);\n int x=sc.nextInt();\n \n for(int xx=x; xx>0; xx/=10){\n xd[xx%10]=true;\n }\n \n int count=0;\n for(int k=1; k*k<=x; k++){\n if(x%k==0){\n //k, x/k\n if(check(k)){\n count++;\n }\n if(k*k0; kk/=10){\n if(xd[kk%10]){\n return true;\n }\n }\n return false;\n }\n}\n\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "ca988c1b45b6619e59f6ddaff061cf5f", "src_uid": "ada94770281765f54ab264b4a1ef766e", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\npublic class D {\n\n\tprivate final static boolean autoflush = false;\n\n\tpublic D () {\n\t\tN = sc.nextInt();\n\t\tL = sc.nextInt();\n\t\tR = sc.nextInt();\n\t\tF = sc.nextDoubles(N);\n\n\t\tM = (1 << N);\n\t\tS = new double [M];\n\t\tfill(S, L);\n\n\t\tfor (int m : rep(M))\n\t\t\tsolve(m);\n\n\t\tdouble res = S[M-1] - L;\n\t\texit(res);\n\t}\n\n\tvoid solve(int b) {\n\t\tdouble a = S[b];\n\t\tfor (int i : rep(N)) {\n\t\t\tint m = (b | (1 << i));\n\t\t\tif (m != b) {\n\t\t\t\tdouble x = F[i][0], y = F[i][1];\n\t\t\t\tdouble alpha = PI/180 * F[i][2], beta = atan2(y, x-a), gamma = atan2(y, x-R);\n\t\t\t\tif (beta < 0) beta += PI;\n\t\t\t\tif (gamma < 0) gamma += PI;\n\t\t\t\tif (alpha + beta > gamma)\n\t\t\t\t\tS[m] = R;\n\t\t\t\telse\n\t\t\t\t\tS[m] = max(S[m], x - y / tan(alpha + beta));\n\t\t\t}\n\t\t}\n\t}\n\n\tint N, M;\n\tdouble L, R;\n\tDouble [][] F;\n\tdouble [] S;\n\n\t///////////////////////////////////////////////////////////////////////////\n\tprivate static int [] rep(int N) { return rep(0, N); }\n\tprivate static int [] rep(int S, int T) { if (T <= S) return new int [0]; int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }\n\tprivate static > T max(T x, T y) { return x.compareTo(y) > 0 ? x : y; }\n\t////////////////////////////////////////////////////////////////////////////////////\n\tprivate final static MyScanner sc = new MyScanner();\n\tprivate static class MyScanner {\n\t\tpublic String next() { newLine(); return line[index++]; }\n\t\tpublic int nextInt() { return Integer.parseInt(next()); }\n\t\tpublic String nextLine() { line = null; return readLine(); }\n\t\tpublic String [] nextStrings() { return nextLine().split(\" \"); }\n\t\tpublic Double [] nextDoubles() {\n\t\t\tString [] L = nextStrings();\n\t\t\tDouble [] res = new Double [L.length];\n\t\t\tfor (int i = 0; i < L.length; ++i)\n\t\t\t\tres[i] = Double.parseDouble(L[i]);\n\t\t\treturn res;\n\t\t}\n\t\tpublic Double [][] nextDoubles (int N) {\n\t\t\tDouble [][] res = new Double [N][];\n\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\tres[i] = nextDoubles();\n\t\t\treturn res;\n\t\t}\n\t\t//////////////////////////////////////////////\n\t\tprivate boolean eol() { return index == line.length; }\n\t\tprivate String readLine() {\n\t\t\ttry {\n\t\t\t\treturn r.readLine();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new Error (e);\n\t\t\t}\n\t\t}\n\t\tprivate final java.io.BufferedReader r;\n\t\tprivate MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }\n\t\tprivate MyScanner (java.io.BufferedReader r) {\n\t\t\ttry {\n\t\t\t\tthis.r = r;\n\t\t\t\twhile (!r.ready())\n\t\t\t\t\tThread.sleep(1);\n\t\t\t\tstart();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new Error(e);\n\t\t\t}\n\t\t}\n\t\tprivate String [] line;\n\t\tprivate int index;\n\t\tprivate void newLine() {\n\t\t\tif (line == null || eol()) {\n\t\t\t\tline = readLine().split(\" \");\n\t\t\t\tindex = 0;\n\t\t\t}\n\t\t}\n\t}\n\tprivate static void print (Object o, Object... a) { printDelim(\" \", o, a); }\n\tprivate static void printDelim (String delim, Object o, Object... a) { pw.println(build(delim, o, a)); }\n\tprivate static void exit (Object o, Object... a) { print(o, a); exit(); }\n\tprivate static void exit() {\n\t\tpw.close();\n\t\tSystem.out.flush();\n\t\tSystem.err.println(\"------------------\");\n\t\tSystem.err.println(\"Time: \" + ((millis() - t) / 1000.0));\n\t\tSystem.exit(0);\n\t}\n\t////////////////////////////////////////////////////////////////////////////////////\n\tprivate static String build (String delim, Object o, Object... a) {\n\t\tStringBuilder b = new StringBuilder();\n\t\tappend(b, o, delim);\n\t\tfor (Object p : a)\n\t\t\tappend(b, p, delim);\n\t\treturn b.substring(delim.length());\n\t}\n\tprivate static void append(StringBuilder b, Object o, String delim) {\n\t\tif (o.getClass().isArray()) {\n\t\t\tint L = java.lang.reflect.Array.getLength(o);\n\t\t\tfor (int i = 0; i < L; ++i)\n\t\t\t\tappend(b, java.lang.reflect.Array.get(o, i), delim);\n\t\t} else if (o instanceof Iterable)\n\t\t\tfor (Object p : (Iterable)o)\n\t\t\t\tappend(b, p, delim);\n\t\telse\n\t\t\tb.append(delim).append(o);\n\t}\n\t////////////////////////////////////////////////////////////////////////////////////\n\tprivate static void start() { t = millis(); }\n\tprivate static java.io.PrintWriter pw = new java.io.PrintWriter(System.out, autoflush);\n\tprivate static long t;\n\tprivate static long millis() { return System.currentTimeMillis(); }\n\tpublic static void main (String[] args) { new D(); exit(); }\n}\n", "lang_cluster": "Java", "tags": ["dp", "geometry", "bitmasks"], "code_uid": "0dd39118ec17b0e433f1edfc30d05940", "src_uid": "4fad1233e08bef09e5aa7e2dc6167d6a", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Problem_11 {\n static long p = 100000;\n\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n String s = input.nextLine();\n //13542\n long n = Long.valueOf(s.substring(0, 1) + s.substring(2, 3) + s.substring(4, 5) + s.substring(3, 4) + s.substring\n (1,2));\n\n System.out.printf(\"%05d\", (((((n * n * n) % p) * n) % p) * n) % p);\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "c3f00d09b4707b71ec10f761e41328ea", "src_uid": "51b1c216948663fff721c28d131bf18f", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.Random;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\npublic class Solution{\n\t\n\t\n public static void main(String[] args) throws IOException {\n \n \tFastScanner fs = new FastScanner();\n \tPrintWriter out = new PrintWriter(System.out);\n \t\n \t\n \t\t\n \tint tt = 1;\n \twhile(tt-->0) {\n \t\t\n \t\tint n = fs.nextInt(), m = fs.nextInt();\n \t\tPair[] a = new Pair[n];\n \t\tfor(int i=0;i[] set = new HashSet[2];\n \t\tfor(int i=0;i<2;i++) set[i] = new HashSet();\n \t\t\n \t\twhile(q-->0) {\n \t\tfor(int i=0;i1 || set[1].size()>1) {\n \t\t\tout.println(0);\n \t\t}\n \t\telse {\n \t\t\tout.println(set[0].iterator().next());\n \t\t}\n \t\t\n \t\t\n \t}\n \t\n \t\t\n \t\t\n \t\t\n \tout.close();\n \t\t\n }\n\n\n \n \n static class Pair{\n \tint x, y;\n \t\n \tPair(int x, int y){\n \t\tthis.x = x;\n \t\tthis.y = y;\n \t}\n \t\n \tint matches(Pair p) {\n \t\tif(p.x==this.x || p.x==this.y) {\n \t\t\tif (p.y!=this.x && p.y!=this.y) return p.x;\n \t\t}\n \t\tif(p.y==this.x || p.y==this.y) {\n \t\t\tif (p.x!=this.x && p.x!=this.y) return p.y;\n \t\t}\n \t\treturn -1;\n \t}\n \t\n }\n \n \n \n \n static final Random random=new Random();\n \t\n static void ruffleSort(int[] a) {\n \tint n=a.length;//shuffle, then sort \n \tfor (int i=0; i=1) \n {\n ans+=(1<> list = new ArrayList<>();\n\t\tstatic PrintWriter out = new PrintWriter(System.out); \n\t\tstatic void flush() {\n\t \tout.flush();\n\t \t}\n\t\tstatic void run(long s, long e) {\n\t\tNumberFormat formatter = new DecimalFormat(\"#0.00000\");\n\t\tSystem.out.print(\"Execution time is \" + formatter.format((e - s) / 1000d) + \" seconds\");\n\t\t}\n\t\t\n\t\tstatic class FastReader {\n\t static BufferedReader br;\n\t StringTokenizer st;\n\t\n\t public FastReader() {\n\t br = new BufferedReader(new\n\t InputStreamReader(System.in));\n\t }\n\t static boolean isPalindrome(String str1, String str2) {\n\t String str3 = str1+str2;\n\t int i = 0, j = str3.length()-1;\n\t while(i < j) {\n\t char a = str3.charAt(i), b = str3.charAt(j);\n\t if(a != b) return false;\n\t i++;j--;\n\t }\t\n\t return true;\n\t }\n\t static boolean isPalindrome(String str) {\n\t int i = 0, j = str.length()-1;\n\t while(i < j) {\n\t char a = str.charAt(i), b = str.charAt(j);\n\t if(a != b) return false;\n\t i++;j--;\n\t }\n\t return true;\n\t }\n\t String next() {\n\t while (st == null || !st.hasMoreElements()) {\n\t try{st = new StringTokenizer(br.readLine());}\n\t catch (IOException e) {e.printStackTrace();}\n\t }\n\t return st.nextToken();\n\t }\n\t int nextInt(){ return Integer.parseInt(next()); }\n\t long nextLong() { return Long.parseLong(next());}\n\t static int fact(int n) {\n\t if(n == 1) return 1;\n\t return n * fact(n-1);\n\t \t}\n\t public int[] readIntArray(int n) {\n\t int[] arr = new int[n];\n\t\tfor(int i=0; i0 && input <=9) result= 1;\n if(input>10 && input <= 99)result=(10-(input%10));\n if(input>100 && input <= 999)result=(100-(input%100));\n if(input>1000 && input <= 9999)result=(1000-(input%1000));\n if(input>10000 && input <= 99999)result=(10000-(input%10000));\n if(input>100000 && input <= 999999)result=(100000-(input%100000));\n if(input>1000000L && input <= 9999999L)result=(1000000L-(input%1000000L));\n if(input>10000000L && input <= 99999999L)result=(10000000L-(input%10000000L));\n if(input>100000000L && input <= 999999999L)result=(100000000L-(input%100000000L));\n if(input>1000000000L && input <= 9999999999L)result=(1000000000L-(input%1000000000L));\n if(input>10000000000L && input <= 99999999999L)result=(10000000000L-(input%10000000000L));\n\n\n\n System.out.println(result);\n\n }\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "90244c3d48463dad996dd8ccbcc825a1", "src_uid": "a3e15c0632e240a0ef6fe43a5ab3cc3e", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.NoSuchElementException;\nimport java.math.BigInteger;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.util.Iterator;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.io.InputStream;\nimport java.util.Random;\nimport java.util.Map;\nimport java.io.OutputStreamWriter;\nimport java.util.AbstractMap;\nimport java.util.AbstractSet;\nimport java.util.Set;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Nguyen Trung Hieu - vuondenthanhcong11@gmail.com\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskE solver = new TaskE();\n solver.solve(1, in, out);\n out.close();\n }\n}\n\nclass TaskE {\n private int count;\n private int k;\n private long S;\n private int[] A;\n private long[] factor;\n private Counter[] total;\n private long answer = 0;\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n count = in.readInt();\n k = in.readInt();\n S = in.readLong();\n A = IOUtils.readIntArray(in, count);\n factor = IntegerUtils.generateFactorial(19, Long.MAX_VALUE);\n total = new Counter[k + 1];\n for (int i = 0; i <= k; i++) {\n total[i] = new Counter();\n }\n\n int mid = count / 2;\n dfs(0, mid, 0, 0L);\n dfs2(mid, count, 0, 0L);\n out.printLine(answer);\n }\n\n private void dfs2(int cur, int target, int use, long sum) {\n if (sum > S) {\n return;\n }\n if (cur >= target) {\n for (int i = use; i <= k; i++) {\n answer += total[i - use].get(S - sum);\n }\n return;\n }\n dfs2(cur + 1, target, use, sum);\n dfs2(cur + 1, target, use, sum + A[cur]);\n if (A[cur] < 19 && use < k) {\n dfs2(cur + 1, target, use + 1, sum + factor[A[cur]]);\n }\n }\n\n private void dfs(int cur, int target, int use, long sum) {\n if (sum > S) {\n return;\n }\n if (cur >= target) {\n total[use].add(sum);\n return;\n }\n dfs(cur + 1, target, use, sum);\n dfs(cur + 1, target, use, sum + A[cur]);\n if (A[cur] < 19 && use < k) {\n dfs(cur + 1, target, use + 1, sum + factor[A[cur]]);\n }\n }\n}\n\nclass Counter extends EHashMap {\n public Counter() {\n super();\n }\n\n public long add(K key) {\n long result = get(key);\n put(key, result + 1);\n return result + 1;\n }\n\n public Long get(Object key) {\n if (containsKey(key))\n return super.get(key);\n return 0L;\n }\n}\n\nclass InputReader {\n\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public long readLong() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n}\n\nclass OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public void close() {\n writer.close();\n }\n\n public void printLine(long i) {\n writer.println(i);\n }\n\n}\n\nclass IOUtils {\n\n public static int[] readIntArray(InputReader in, int size) {\n int[] array = new int[size];\n for (int i = 0; i < size; i++)\n array[i] = in.readInt();\n return array;\n }\n\n}\n\nclass IntegerUtils {\n\n public static long[] generateFactorial(int count, long module) {\n long[] result = new long[count];\n if (module == -1) {\n if (count != 0)\n result[0] = 1;\n for (int i = 1; i < count; i++)\n result[i] = result[i - 1] * i;\n } else {\n if (count != 0)\n result[0] = 1 % module;\n for (int i = 1; i < count; i++)\n result[i] = (result[i - 1] * i) % module;\n }\n return result;\n }\n\n}\n\nclass EHashMap extends AbstractMap {\n private static final int[] shifts = new int[10];\n\n private int size;\n private HashEntry[] data;\n private int capacity;\n private Set> entrySet;\n\n static {\n Random random = new Random(System.currentTimeMillis());\n for (int i = 0; i < 10; i++)\n shifts[i] = 1 + 3 * i + random.nextInt(3);\n }\n\n public EHashMap() {\n this(4);\n }\n\n private void setCapacity(int size) {\n capacity = Integer.highestOneBit(4 * size);\n //noinspection unchecked\n data = new HashEntry[capacity];\n }\n\n public EHashMap(int maxSize) {\n setCapacity(maxSize);\n entrySet = new AbstractSet>() {\n public Iterator> iterator() {\n return new Iterator>() {\n private HashEntry last = null;\n private HashEntry current = null;\n private HashEntry base = null;\n private int lastIndex = -1;\n private int index = -1;\n\n public boolean hasNext() {\n if (current == null) {\n for (index++; index < capacity; index++) {\n if (data[index] != null) {\n base = current = data[index];\n break;\n }\n }\n }\n return current != null;\n }\n\n public Entry next() {\n if (!hasNext())\n throw new NoSuchElementException();\n last = current;\n lastIndex = index;\n current = current.next;\n if (base.next != last)\n base = base.next;\n return last;\n }\n\n public void remove() {\n if (last == null)\n throw new IllegalStateException();\n size--;\n if (base == last)\n data[lastIndex] = last.next;\n else\n base.next = last.next;\n }\n };\n }\n\n public int size() {\n return size;\n }\n };\n }\n\n public Set> entrySet() {\n return entrySet;\n }\n\n public void clear() {\n Arrays.fill(data, null);\n size = 0;\n }\n\n private int index(Object o) {\n return getHash(o.hashCode()) & (capacity - 1);\n }\n\n private int getHash(int h) {\n int result = h;\n for (int i : shifts)\n result ^= h >>> i;\n return result;\n }\n\n public V remove(Object o) {\n if (o == null)\n return null;\n int index = index(o);\n HashEntry current = data[index];\n HashEntry last = null;\n while (current != null) {\n if (current.key.equals(o)) {\n if (last == null)\n data[index] = current.next;\n else\n last.next = current.next;\n size--;\n return current.value;\n }\n last = current;\n current = current.next;\n }\n return null;\n }\n\n public V put(E e, V value) {\n if (e == null)\n return null;\n int index = index(e);\n HashEntry current = data[index];\n if (current != null) {\n while (true) {\n if (current.key.equals(e)) {\n V oldValue = current.value;\n current.value = value;\n return oldValue;\n }\n if (current.next == null)\n break;\n current = current.next;\n }\n }\n if (current == null)\n data[index] = new HashEntry(e, value);\n else\n current.next = new HashEntry(e, value);\n size++;\n if (2 * size > capacity) {\n HashEntry[] oldData = data;\n setCapacity(size);\n for (HashEntry entry : oldData) {\n while (entry != null) {\n HashEntry next = entry.next;\n index = index(entry.key);\n entry.next = data[index];\n data[index] = entry;\n entry = next;\n }\n }\n }\n return null;\n }\n\n public V get(Object o) {\n if (o == null)\n return null;\n int index = index(o);\n HashEntry current = data[index];\n while (current != null) {\n if (current.key.equals(o))\n return current.value;\n current = current.next;\n }\n return null;\n }\n\n public boolean containsKey(Object o) {\n if (o == null)\n return false;\n int index = index(o);\n HashEntry current = data[index];\n while (current != null) {\n if (current.key.equals(o))\n return true;\n current = current.next;\n }\n return false;\n }\n\n public int size() {\n return size;\n }\n\n private static class HashEntry implements Entry {\n private final E key;\n private V value;\n private HashEntry next;\n\n private HashEntry(E key, V value) {\n this.key = key;\n this.value = value;\n }\n\n\n public E getKey() {\n return key;\n }\n\n public V getValue() {\n return value;\n }\n\n public V setValue(V value) {\n V oldValue = this.value;\n this.value = value;\n return oldValue;\n }\n }\n}\n\n", "lang_cluster": "Java", "tags": ["brute force", "math", "dp", "binary search", "bitmasks", "meet-in-the-middle"], "code_uid": "42205a5c99868691ec3414e35adf5acd", "src_uid": "2821a11066dffc7e8f6a60a8751cea37", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.Scanner;\n\npublic class codeforce519A {\n\n static PrintWriter out;\n static StreamTokenizer sin;\n static BufferedReader bin;\n\n static void setupOut() {\n out = new PrintWriter(System.out);\n }\n\n static void setupString() {\n bin = new BufferedReader(new InputStreamReader(System.in));\n }\n\n public static void main(String[] args) throws IOException {\n setupOut();\n setupString();\n Scanner in = new Scanner(System.in);\n int x = 0;\n int y = 0;\n\n for (int i = 0; i < 8; i++) {\n String s = in.next();\n for (int j = 0; j < 8; j++) {\n char c = s.charAt(j);\n if (c=='Q')\n x+=9;\n if (c=='R')\n x+=5;\n if (c=='B')\n x+=3;\n if (c=='N')\n x+=3;\n if (c=='P')\n x+=1;\n if (c=='q')\n y+=9;\n if (c=='r')\n y+=5;\n if (c=='n')\n y+=3;\n if (c=='p')\n y+=1;\n if (c=='b'){\n y+=3;\n }\n\n }\n }\n if (x==y)\n out.print(\"Draw\");\n if (x>y)\n out.print(\"White\");\n if (x= -d; j--) {\n\t\t\t\tint next = now + j;\n\t\t\t\tint remmin = (t - i - 1) * d;\n\t\t\t\tif (next - remmin > v2) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tnow = next;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tmax += now;\n\t\t}\n\t\tSystem.out.println(max);\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew MainB().run();\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "greedy", "dp"], "code_uid": "027c0166e208b8f63731d130025a0d92", "src_uid": "9246aa2f506fcbcb47ad24793d09f2cf", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "//package cf589d2;\nimport java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class E {\n\tstatic long MOD = 1000000007;\n\tpublic static void main(String[] args) {\n\t\tMyScanner sc = new MyScanner();\n\t\tint n = sc.nextInt();\n\t\tlong k = sc.nextLong();\n\t\tlong[][] choose = new long[n + 1][n + 1];\n\t\tlong[][] pow = new long[n + 1][2];\n\t\tfor(int i = 0; i <= n; i++) {\n\t\t\tchoose[i][0] = 1;\n\t\t\tchoose[i][i] = 1;\n\t\t}\n\t\tfor(int i = 2; i <= n; i++)\n\t\t\tfor(int j = 1; j < i; j++)\n\t\t\t\tchoose[i][j] = (choose[i - 1][j] + choose[i - 1][j - 1]) % MOD;\n\t\tfor(int i = 0; i <= n; i++)\n\t\t\tfor(int j = 0; j < 2; j++)\n\t\t\t\tpow[i][j] = pMod(k - j, i);\n\t\tlong[][] dp = new long[n + 1][n + 1];\n\t\tdp[0][n] = 1;\n\t\tfor(int i = 1; i <= n; i++)\n\t\t\tfor(int j = 0; j <= n; j++)\n\t\t\t\tfor(int l = 0; l <= j; l++) {\n\t\t\t\t\tlong del = dp[i - 1][j] * choose[j][l] % MOD * pow[l][1] % MOD;\n\t\t\t\t\tif(l < j)\n\t\t\t\t\t\tdel = del * pow[n - j][0] % MOD;\n\t\t\t\t\telse\n\t\t\t\t\t\tdel = del * (pow[n - j][0] - pow[n - j][1] + MOD) % MOD;\n\t\t\t\t\tdp[i][l] = (dp[i][l] + del) % MOD;\n\t\t\t\t}\n\t\tout.println(dp[n][0]);\n\t\tout.close();\n\t}\n\tpublic static long pMod(long x, long p) {\n\t\tif(p == 0)\n\t\t\treturn 1;\n\t\tlong l = pMod(x, p / 2);\n\t\treturn l * l % MOD * (p % 2 == 1 ? x : 1) % MOD;\n\t}\n\tpublic static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n\tpublic static class MyScanner {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st;\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreElements())\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\tString nextLine() {\n\t\t\tString str = \"\";\n\t\t\ttry {\n\t\t\t\tstr = br.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics"], "code_uid": "b3605c1fb0810a1893fcf50f799b87cd", "src_uid": "f67173c973c6f83e88bc0ddb0b9bfa93", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.*;\npublic class b {\npublic static void main(String[] args)\n{\n Scanner input = new Scanner(System.in);\n int n = input.nextInt(), d = input.nextInt();\n boolean[] possible = new boolean[1000000];\n possible[0] = true;\n int[] data = new int[n];\n for(int i = 0; i=0; j--)\n if(possible[j])\n possible[j+data[i]] = true;\n }\n Queue good = new LinkedList();\n for(int i = 0; i d) break;\n int next = good.poll();\n while(!good.isEmpty() && good.peek() - ans <= d)\n {\n next = good.poll();\n }\n ans = next;\n count++;\n }\n System.out.println(ans+\" \"+count);\n}\n}\n", "lang_cluster": "Java", "tags": ["greedy", "dp"], "code_uid": "6a051ad53d710cecd9c3c3c4465a12fe", "src_uid": "65699ddec8d0db2f58b83a0f64de6f6f", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class a {\n\tpublic static void main(String[]args) {\n\t\tScanner input=new Scanner (System.in);\n\t\tint n=input.nextInt();\n\t int b=0;\n\t int c=0;\n\t int []x=new int [101];\n\t int k=0;\n\t while (k=0) {\n\t \tfor (int q=0;q=0)\n\t \t\t\tb=b+x[w];\n\t \t\telse c=c+x[w];\n\t \t}\n\t \t\t\n\t }\n\t System.out.print(b-c);\n\t}\n\n}", "lang_cluster": "Java", "tags": ["greedy"], "code_uid": "93e9b8cc31e684206e23f7ddf2acb82c", "src_uid": "4b5d14833f9b51bfd336cc0e661243a5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class B {\n\tstatic Scanner scan = new Scanner (System.in);\n\tstatic PrintStream out = System.out;\n\t\n\tpublic static void main (String[] args) {\n\t\tTreeMap> tm1 = new TreeMap>();\n\t\tTreeMap> tm2 = new TreeMap>();\n\t\tfor (int i = 0; i < 8; ++i) {\n\t\t\tint d1 = scan.nextInt(), d2 = scan.nextInt();\n\t\t\tif (!tm1.containsKey(d1))\n\t\t\t\ttm1.put(d1, new HashSet());\n\t\t\ttm1.get(d1).add(d2);\n\t\t\tif (!tm2.containsKey(d2))\n\t\t\t\ttm2.put(d2, new HashSet());\n\t\t\ttm2.get(d2).add(d1);\n\t\t\t\n\t\t}\n\t\tif (tm1.size() != 3 || tm2.size() != 3) {\n\t\t\tout.println(\"ugly\");\n\t\t\treturn;\n\t\t}\n\t\tint index = 0;\n\t\tfor (Integer i : tm1.keySet()) {\n\t\t\t++index;\n\t\t\tint c = tm1.get(i).size();\n\t\t\tif (index != 2 && c != 3) {\n\t\t\t\tout.println (\"ugly\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (index == 2 && c != 2) {\n\t\t\t\tout.println (\"ugly\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tindex = 0;\n\t\tfor (Integer i : tm2.keySet()) {\n\t\t\t++index;\n\t\t\tint c = tm2.get(i).size();\n\t\t\tif (index != 2 && c != 3) {\n\t\t\t\tout.println (\"ugly\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (index == 2 && c != 2) {\n\t\t\t\tout.println (\"ugly\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tout.println(\"respectable\");\n\t\treturn;\n\t}\n}\n", "lang_cluster": "Java", "tags": ["sortings"], "code_uid": "e6101eabb9d75b6d6f1cad8bd4a22bee", "src_uid": "f3c96123334534056f26b96f90886807", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class utkarsh {\n\n InputStream is;\n PrintWriter out;\n \n long maxl = 1234567890987654321L, mod = 1000000007L;\n int p[], maxi = 1234567890, sz, np = 20000000;\n boolean b[]; // = isPrime();\n \n boolean check(int pos, int j){\n int i;\n j = (j / 50) % 475;\n for(i = 0; i < 25; i++){\n j = (j * 96 + 42) % 475;\n //out.print(26 + j +\" \");\n if((26 + j) == pos){\n return true;\n }\n }\n return false;\n }\n \n void solve(){\n //Enter code here utkarsh\n //sz=sieve(); //sz=1270607;\n //out.println(sz);\n int pos, x, y, ans, i, j, k;\n pos = ni();\n x = ni();\n y = ni();\n ans = 0;\n k = 0;\n i = x;\n while(i >= y){\n if(check(pos, i)){\n out.println(0);\n return;\n }\n i -= 50;\n }\n if(x < y){\n j = (y - x + 99) / 100;\n ans += j;\n x += 100 * j;\n if((x - 50) >= y){\n x -= 50;\n k++;\n }\n }\n while(true){\n if(check(pos, x)){\n out.println(ans);\n break;\n }\n x += 50;\n k++;\n if(k % 2 == 1){\n ans++;\n }\n }\n }\n \n int sieve(){ int i, j, n = np; b = new boolean[n]; for(i = 3; i < n; i += 2){ b[i] = true; } b[2] = true; for(i = 3; i * i <= n; i += 2){ if(b[i]){ for(j = 2 * i; j < n; j += i){ b[j] = false; } } } p = new int[n]; p[0] = 2; j = 1; for(i = 3; i < n; i += 2){ if(b[i]){ p[j++] = i; } } p=Arrays.copyOf(p,j); return j;\n }\n long modpow(long base, long exp, long modulus) { base %= modulus; long result = 1L; while (exp > 0) { if ((exp & 1)==1) result = (result * base) % modulus; base = (base * base) % modulus; exp >>= 1; } return result;\n }\n \n public static void main(String[] args) { new utkarsh().run();\n }\n void run(){ is = System.in; out = new PrintWriter(System.out); solve(); out.flush();\n }\n \n byte input[] = new byte[1024];\n int len = 0, ptr = 0;\n \n int readByte(){ if(ptr >= len){ ptr = 0; try{ len = is.read(input); }catch(IOException e){ throw new InputMismatchException(); } if(len <= 0){ return -1; } } return input[ptr++];\n }\n boolean isSpaceChar(int c){ return !( c >= 33 && c <= 126 ); \n }\n int skip(){ int b = readByte(); while(b != -1 && isSpaceChar(b)){ b = readByte(); } return b;\n }\n \n char nc(){ return (char)skip();\n }\n String ns(){ int b = skip(); StringBuilder sb = new StringBuilder(); while(!isSpaceChar(b)){ sb.appendCodePoint(b); b=readByte(); } return sb.toString();\n }\n int ni(){ int n = 0,b = readByte(); boolean minus = false; while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')){ b = readByte(); } if(b == '-'){ minus = true; b = readByte(); } if(b == -1){ return -1; } while(b >= '0' && b <= '9'){ n = n * 10 + (b - '0'); b = readByte(); } return minus ? -n : n;\n }\n long nl(){ long n = 0L; int b = readByte(); boolean minus = false; while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')){ b = readByte(); } if(b == '-'){ minus = true; b = readByte(); } while(b >= '0' && b <= '9'){ n = n * 10 + (b - '0'); b = readByte(); } return minus ? -n : n;\n }\n double nd(){ return Double.parseDouble(ns());\n }\n float nf(){ return Float.parseFloat(ns());\n }\n int[] na(int n){ int a[] = new int[n]; for(int i = 0; i < n; i++){ a[i] = ni(); } return a;\n }\n char[] ns(int n){ char c[] = new char[n]; int i,b = skip(); for(i = 0; i < n; i++){ if(isSpaceChar(b)){ break; } c[i] = (char)b; b = readByte(); } return i == n ? c : Arrays.copyOf(c,i);\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "088dfc336578f8655c03718c47a443ed", "src_uid": "c9c22e03c70a94a745b451fc79e112fd", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "\nimport java.util.Scanner;\n\npublic class Main\n{\n private final static Main main = new Main();\n\n public static void main(String[] args)\n {\n long l = System.currentTimeMillis();\n main.answer();\n //System.err.println(\"\u7d4c\u904e\u6642\u9593\uff1a\" + (System.currentTimeMillis() - l));\n }\n\n private void answer()\n {\n Scanner sc = new Scanner(System.in);\n String s1 = sc.nextLine();\n String s2 = sc.nextLine();\n sc.close();\n int n = 0;\n for(int i=0; i m + n - 2) {\n\t\t\tSystem.out.print(-1);\n\t\t\treturn;\n\t\t}\n\t\tlong temp = 0;\n\t\tlong tempRes = 0;\n\t\tfor (int i = 0; i < 2; i++) {\n\t\t\tif (k <= m - 1) {\n\t\t\t\ttempRes = n * (m / (k + 1));\n\t\t\t} else {\n\t\t\t\ttempRes = n / (k - (m -1) + 1);\n\t\t\t}\n\t\t\ttemp = n;\n\t\t\tn = m;\n\t\t\tm = temp;\n\t\t\tres = Math.max(res, tempRes);\n\t\t}\n\t\tSystem.out.print(res);\n\t}\n}\n\nclass ReaderJzzhuandChocolate {\n\tstatic BufferedReader reader;\n\tstatic StringTokenizer tokenizer;\n\n\tstatic void Init(InputStream input) {\n\t\treader = new BufferedReader(new InputStreamReader(input));\n\t\ttokenizer = new StringTokenizer(\"\");\n\t}\n\n\tstatic String Next() throws IOException {\n\t\twhile (!tokenizer.hasMoreTokens()) {\n\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t}\n\t\treturn tokenizer.nextToken();\n\t}\n\n\tstatic int NextInt() throws IOException {\n\t\treturn Integer.parseInt(Next());\n\t}\n\n\tstatic long NextLong() throws IOException {\n\t\treturn Long.parseLong(Next());\n\t}\n\n\tstatic Double NextDouble() throws IOException {\n\t\treturn Double.parseDouble(Next());\n\t}\n}", "lang_cluster": "Java", "tags": ["greedy", "implementation"], "code_uid": "188a8e49e33d2e9cd12db7a3d1dcb4e5", "src_uid": "bb453bbe60769bcaea6a824c72120f73", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\n\nimport java.io.IOException;\nimport java.util.Scanner;\n\n\npublic class Main\n{\n\n \n \n public static void main(String[] args) throws NumberFormatException, IOException {\n \n Scanner sc = new Scanner(System.in);\n \n int a = sc.nextInt(), b = sc.nextInt();\n System.out.println(remove(a + b) == remove(a) + remove(b) ?\"YES\":\"NO\");\n\n}\n \n static int remove(int x)\n {\n int y = 0, f = 1;\n while(x > 0)\n {\n if(x%10 != 0)\n {\n y += x%10 * f;\n f *= 10;\n }\n \n x /= 10;\n }\n return y;\n }\n\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "3b7ec4ed8a0db5881c107590fadf058c", "src_uid": "ac6971f4feea0662d82da8e0862031ad", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class GGWPLivaem implements Runnable{\n boolean withFiles = false;\n class cc implements Comparable{\n public int x, y;\n cc(int x, int y) {\n this.x = x;\n this.y = y;\n }\n public int compareTo(cc other) {\n if (this.x == other.x) {\n return Integer.compare(this.y, other.y);\n }\n return Integer.compare(this.x, other.x);\n }\n }\n int n, k;\n int p[];\n long ans = 0;\n int anss[];\n int used[];\n boolean get_ans(int ind) {\n if (ind == 1 || anss[ind] == 1) {\n return true;\n }\n if (used[ind] == 1) {\n return false;\n }\n used[ind] = 1;\n if (get_ans(p[ind])) {\n anss[ind] = 1;\n return true;\n }\n else {\n return false;\n }\n }\n void check() {\n for (int i = 1; i <= k; ++i) {\n anss[i] = 0;\n used[i] = 0;\n }\n for (int i = 1; i <= k; ++i) {\n if (get_ans(i) == false) {\n return;\n }\n }\n ++ans;\n }\n void dfs(int pos) {\n if (pos == k + 1) {\n check();\n return;\n }\n for (int i = 1; i <= k; ++i) {\n p[pos] = i;\n dfs(pos + 1);\n }\n }\n private void solve() throws IOException {\n p = new int[10];\n anss = new int[10];\n used = new int[10];\n n = in.nextInt();\n k = in.nextInt();\n dfs(1);\n long mod = 1000 * 1000 * 1000 + 7;\n long an = 1;\n for (int i = 1; i <= n - k; ++i) {\n an *= n - k;\n an %= mod;\n }\n ans *= an;\n ans %= mod;\n out.println(ans);\n }\n\n private static class FastScanner{\n private BufferedReader reader;\n private StringTokenizer tokenizer;\n String cache;\n int cur;\n\n FastScanner(Reader r) throws IOException{\n reader = new BufferedReader(r);\n tokenizer = new StringTokenizer(\"\");\n cache = null;\n cur = 0;\n }\n\n public boolean hasNext(){\n if (cache != null && cur < cache.length())\n return true;\n try {\n while (!tokenizer.hasMoreTokens()){\n String line = reader.readLine();\n if (line == null)\n return false;\n tokenizer = new StringTokenizer(line);\n }\n cache = tokenizer.nextToken();\n cur = 0;\n }\n catch(IOException e) {\n return false;\n }\n return true;\n }\n\n public char nextChar() throws IOException{\n if (!hasNext())\n throw new EOFException();\n return cache.charAt(cur++);\n }\n\n public String next() throws IOException{\n if (!hasNext())\n throw new EOFException();\n String result = (cur == 0) ? cache : cache.substring(cur);\n cache = null;\n return result;\n }\n\n public int nextInt() throws IOException{\n return Integer.parseInt(this.next());\n }\n\n public long nextLong() throws IOException{\n return Long.parseLong(this.next());\n }\n\n public double nextDouble() throws IOException{\n return Double.parseDouble(this.next());\n }\n\n public BigInteger nextBigInteger() throws IOException{\n return new BigInteger(this.next());\n }\n\n public void close() throws IOException{\n reader.close();\n tokenizer = new StringTokenizer(\"\");\n }\n }\n\n\n public static void main(String args[]) throws IOException{\n new Thread(null, new GGWPLivaem(), \"Thread #228\", 64 * 1024 * 1024).start();\n }\n\n public void run(){\n try{\n if (withFiles) {\n in = new FastScanner(new FileReader(\"input.txt\"));\n out = new PrintWriter(new FileWriter(\"output.txt\"));\n }\n else {\n in = new FastScanner(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n }\n solve();\n in.close();\n out.close();\n }\n catch(IOException e){\n e.printStackTrace();\n }\n }\n\n FastScanner in;\n PrintWriter out;\n}\n", "lang_cluster": "Java", "tags": ["dfs and similar", "math", "combinatorics", "brute force"], "code_uid": "638bb7fb0ebeb3a6f51fe3af57a505b5", "src_uid": "cc838bc14408f14f984a349fea9e9694", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Watermelon\n{\t\n public static void main(String[] args)\n {\n \tScanner sc = new Scanner(System.in);\n \tint n = sc.nextInt();\n \tint a[] = new int[n];\n \tint c[] = new int[101];\n \tfor(int i=0; imax)\n \t\t\tmax = c[i];\n \t}\n \tSystem.out.println(max);\n }\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "29bd8cc7a5eef1c20989eb05c7d3692d", "src_uid": "f30329023e84b4c50b1b118dc98ae73c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\npublic class BearandThreeBalls\n{\n\n \n /************************ SOLUTION STARTS HERE ***********************/\n\n\n \n private static void solve(FastScanner s1, PrintWriter out){\n\n\tint n = s1.nextInt();\n\tTreeSet set = new TreeSet<>();\n\twhile(n-->0){set.add(s1.nextInt());}\n\tif(set.size() < 3)\n\t{\n\t out.print(\"NO\");\n\t return;\n\t}\n\tint arr[] = new int[set.size()];\n\tfor(int i=0;!set.isEmpty();i++)\n\t arr[i] = set.pollFirst();\n\tboolean flag = false;\n\tfor(int i=2;i= '0' && c <= '9');\n if (neg) return -ret;\n return ret;\n }\n\n public long nextLong() throws IOException {\n long ret = 0;\n byte c = read();\n while (c <= ' ') c = read();\n boolean neg = (c == '-');\n if (neg) c = read();\n do {\n ret = ret * 10 + c - '0';\n } while ((c = read()) >= '0' && c <= '9');\n if (neg) return -ret;\n return ret;\n }\n\n public double nextDouble() throws IOException {\n double ret = 0, div = 1;\n byte c = read();\n while (c <= ' ') c = read();\n boolean neg = (c == '-');\n if (neg) c = read();\n do {\n ret = ret * 10 + c - '0';\n } while ((c = read()) >= '0' && c <= '9');\n if (c == '.') while ((c = read()) >= '0' && c <= '9') ret += (c - '0') / (div *= 10);\n if (neg) return -ret;\n return ret;\n }\n\n private void fillBuffer() throws IOException {\n bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n if (bytesRead == -1) buffer[0] = -1;\n }\n\n private byte read() throws IOException {\n if (bufferPointer == bytesRead) fillBuffer();\n return buffer[bufferPointer++];\n }\n\n public void close() throws IOException {\n if (din == null) return;\n din.close();\n }\n }\n\n static void magic() throws IOException {\n reader = new FastReader();\n writer = new PrintWriter(System.out, true);\n int a = reader.nextInt(), b = reader.nextInt();\n if(a==b) {\n writer.println(0);\n System.exit(0);\n }\n int d = abs(a-b);\n HashSet candidates = new HashSet<>();\n for(int i=1;i*i<=d;++i) {\n if(d%i==0) {\n candidates.add(i);\n candidates.add(d/i);\n }\n }\n long min = Long.MAX_VALUE, at = -1;\n for(int e : candidates) {\n int k;\n if(a%e==0) {\n k = 0;\n }\n else {\n k = e - a%e;\n }\n long ispe = lcm(a+k, b+k);\n if(ispek) {\n at = k;\n }\n }\n }\n writer.println(at);\n }\n static long gcd(long a, long b) {\n if(b==0) {\n return a;\n }\n return gcd(b,a%b);\n }\n static long lcm(long a, long b) {\n return (a*b)/gcd(a,b);\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "math", "number theory"], "code_uid": "826711bfd6190e0e83ce731005a79fcd", "src_uid": "414149fadebe25ab6097fc67663177c3", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n public static void main(String[] args) throws Exception\n {\n Scanner in = new Scanner(System.in);\n OutputWriter out = new OutputWriter(System.out);\n int n = in.nextInt();\n int v = in.nextInt();\n if (v>=n-1)\n out.printLine(n-1);\n else\n {\n int ans = v;\n int cur = 1;\n while (cur+v[] adjList;\n\n public Graph(int n) {\n this.n = n;\n adjList = new ArrayList[n];\n for (int i = 0; i < n; i++)\n adjList[i] = new ArrayList<>();\n }\n\n}\nclass pair implements Comparable\n{\n\n int key;\n int value;\n int id;\n public pair(Object key, Object value,Object id) {\n\n this.key = (int)key;\n this.value=(int)value;\n this.id=(int)id;\n }\n\n @Override\n public int compareTo(Object o) {\n pair temp =(pair)o;\n if (key!=temp.key)\n return key-temp.key;\n else return id-temp.id;\n }\n}\nclass Scanner {\n\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(InputStream s) {\n br = new BufferedReader(new InputStreamReader(s));\n }\n\n public Scanner (FileReader f) {\n br = new BufferedReader(f);\n }\n\n public String next() throws IOException {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public String nextLine() throws IOException {\n return br.readLine();\n }\n\n public double nextDouble() throws IOException {\n String x = next();\n StringBuilder sb = new StringBuilder(\"0\");\n double res = 0, f = 1;\n boolean dec = false, neg = false;\n int start = 0;\n if (x.charAt(0) == '-') {\n neg = true;\n start++;\n }\n for (int i = start; i < x.length(); i++)\n if (x.charAt(i) == '.') {\n res = Long.parseLong(sb.toString());\n sb = new StringBuilder(\"0\");\n dec = true;\n } else {\n sb.append(x.charAt(i));\n if (dec)\n f *= 10;\n }\n res += Long.parseLong(sb.toString()) / f;\n return res * (neg ? -1 : 1);\n }\n\n public boolean ready() throws IOException {\n return br.ready();\n }\n\n public boolean nextEmpty() throws IOException {\n String s = nextLine();\n st = new StringTokenizer(s);\n return s.isEmpty();\n }\n}\nclass OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void print(Object... objects) {\n for (int i = 0; i < objects.length; i++) {\n if (i != 0)\n writer.print(' ');\n writer.print(objects[i]);\n }\n }\n\n\n public void printLine(Object... objects) {\n print(objects);\n writer.println();\n }\n\n public void close() {\n writer.close();\n }\n\n public void flush() {\n writer.flush();\n }\n\n}", "lang_cluster": "Java", "tags": ["math", "greedy", "dp"], "code_uid": "fafc53200723abbdc6f62512edfc3a3b", "src_uid": "f8eb96deeb82d9f011f13d7dac1e1ab7", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\nimport java.math.*;\npublic class C {\n public static int gcd(int a, int b) {\n if (b==0) return a;\n return gcd(b,a%b);\n }\n public static void main(String[] args) throws Exception {\n BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n // Scanner scan = new Scanner(System.in);\n PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n // int n = Integer.parseInt(bf.readLine());\n StringTokenizer st = new StringTokenizer(bf.readLine());\n int l_a = Integer.parseInt(st.nextToken());\n int r_a = Integer.parseInt(st.nextToken());\n int t_a = Integer.parseInt(st.nextToken());\n\n st = new StringTokenizer(bf.readLine());\n int l_b = Integer.parseInt(st.nextToken());\n int r_b = Integer.parseInt(st.nextToken());\n int t_b = Integer.parseInt(st.nextToken());\n\n int g = gcd(t_a, t_b);\n int c_mod = (g + ((l_b - l_a) % g)) % g;\n //out.println(c_mod);\n long ov_1 = overlap(0L, 0L+r_a - l_a, 0L+c_mod, 0L+ c_mod + r_b - l_b);\n long ov_2 = overlap(0L+g, 0L+g+ r_a - l_a, 0L+c_mod, 0L+ r_b - l_b+c_mod);\n\n out.println(Math.max(ov_1, ov_2));\n\n // int[] a = new int[n]; for(int i=0; i a) {\n ans = false;\n } else {\n a -= x;\n if (a + b < y) {\n ans = false;\n } else {\n if (a + b + c - y < z) ans = false;\n }\n }\n out.println(ans ? \"YES\" : \"NO\");\n out.close();\n }\n\n\n //-----------MyScanner class for faster input----------\n public static class MyScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public MyScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String nextLine(){\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n\n\n\n }\n\n}", "lang_cluster": "Java", "tags": ["brute force", "greedy", "implementation"], "code_uid": "2546ef565739aef2034ad3db9b4e89d0", "src_uid": "d54201591f7284da5e9ce18984439f4e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class cf93{\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint pos = sc.nextInt();\n\t\tint l = sc.nextInt();\n\t\tint r = sc.nextInt();\n int t=0;\n int flag=0;\n\t\tint diff= Math.abs(pos-l);\n\t int diff2 = Math.abs(r-pos);\n\t \n\t if(l==1 && r==n){\n\t \tSystem.out.println(\"0\");\n\t }\n\t else if(l!=1 && r==n){\n System.out.println(Math.abs(pos-l)+1);\n\t }\n\t else if(l==1 && r!=n){\n System.out.println(Math.abs(pos-r)+1);\n\t }\n\t else{\n\t \tSystem.out.println(r-l + Math.min(Math.abs(pos-l),Math.abs(pos-r))+2);\n\t }\n \n //boolean flag1 = false;\n //boolean flag2 = false;\n \n \n // if(flag1 && flag2){\n \t\n \n \n \n\n\t}\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "f5262ec85de544b8c46c57fec1694f2b", "src_uid": "5deaac7bd3afedee9b10e61997940f78", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main\n{\n public static long fun( long x )\n {\n String s = Long.toString(x);\n long sum = 0;\n for( int i =0; i < s.length() ; i++ ) sum += (long) ( s.charAt(i) - '0');\n return sum;\n }\n public static void main(String args[]) throws Exception\n {\n MyScanner scanner = new MyScanner();\n long n = scanner.nextLong(), d = scanner.nextLong(), val = 0, place = 1;\n while ( d > 0 && n > place )\n {\n val = n % ( place * 10 ) ;\n val = val / place;\n if( val == 9 )\n {\n place *= 10;\n continue;\n }\n val += 1;\n val *= place;\n d -= val;\n if( d >= 0 )\n n -= val;\n place *=10;\n }\n System.out.println(n);\n }\n}\n\nclass MyScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public MyScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n public MyScanner(InputStreamReader inputStreamReader) {\n br = new BufferedReader(inputStreamReader);\n }\n\n public int mod(long x) {\n // TODO Auto-generated method stub\n return (int) x % 1000000007;\n }\n\n public int mod(int x) {\n return x % 1000000007;\n }\n\n boolean hasNext() {\n if (st.hasMoreElements())\n return true;\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n return st.hasMoreTokens();\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n}\n\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "2b00c4e95c1d056f2174870f98eb07df", "src_uid": "c706cfcd4c37fbc1b1631aeeb2c02b6a", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class OneDJapaneseCrosswordPuzzle {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tString s = sc.next();\n\t\ts = s.replace('W', ' ');\n\t\tint sum = 0;\n\t\tString[] x= s.split(\" \");\n\t\tfor(String t : x) {\n\t\t\tif(t.length() > 0)\n\t\t\t\tsum++;\n\t\t}\n\t\tSystem.out.println(sum);\n\t\tfor(String t:x) {\n\t\t\tif(t.length() > 0) \n\t\t\t\tSystem.out.print(t.length() + \" \");\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "24efdb4ab8258fb6d93e0f45b5e4330a", "src_uid": "e4b3a2707ba080b93a152f4e6e983973", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.StreamTokenizer;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.Locale;\nimport java.util.Scanner;\n\npublic class Main implements Runnable {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new Main()).start();\n\t}\n\n\tpublic void run() {\n\t\tLocale.setDefault(Locale.US);\n\t\ttry {\n\t\t\trun1();\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException();\n\t\t}\n\t}\n\n\tint nextInt(StreamTokenizer st) throws IOException {\n\t\tst.nextToken();\n\t\treturn (int) st.nval;\n\t}\n\n\tprivate List kmp(String x, String a) {\n\t\tString s = a + \"$\" + x;\n\t\tint[] oppa = new int[s.length()];\n\t\toppa[0] = 0;\n\t\tint tmp = 0;\n\t\tList res = new ArrayList();\n\t\tfor (int i = 1; i < s.length(); i++) {\n\t\t\twhile (tmp != 0 && s.charAt(tmp) != s.charAt(i)) {\n\t\t\t\t// System.out.println(i + \" \" + tmp);\n\t\t\t\ttmp = oppa[tmp - 1];\n\t\t\t}\n\t\t\tif (s.charAt(tmp) == s.charAt(i))\n\t\t\t\ttmp++;\n\t\t\toppa[i] = tmp;\n\t\t\tif (tmp == a.length()) {\n\t\t\t\tres.add(i - a.length() - a.length());\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n\n\tdouble nextDouble(StreamTokenizer st) throws IOException {\n\t\tst.nextToken();\n\t\treturn st.nval;\n\t}\n\n\tString nextLine(StreamTokenizer st) throws IOException {\n\t\tst.nextToken();\n\t\treturn st.sval;\n\t}\n\n\tint cnt = 0;\n\tint[] col;\n\n\tvoid unite(int a, int b) {\n\t\tif (cnt % 2 == 0)\n\t\t\tcol[getCol(a)] = getCol(b);\n\t\telse\n\t\t\tcol[getCol(b)] = getCol(a);\n\t\tcnt++;\n\t}\n\n\tint getCol(int a) {\n\t\treturn a == col[a] ? a : (col[a] = getCol(col[a]));\n\t}\n\n\tpublic void run1() throws IOException {\n\t\t// Scanner sc = new Scanner(new FileReader(\"input.txt\"));\n\t\tScanner sc = new Scanner(new InputStreamReader(System.in));\n\t\t// BufferedReader br = new BufferedReader(new\n\t\t// InputStreamReader(System.in));\n\t\t// PrintWriter pw = new PrintWriter(new FileWriter(\"output.txt\"));\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tint res = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t\tif (i % 2 == j % 2) {\n\t\t\t\t\tint di = Math.min(i, n - 1 - i);\n\t\t\t\t\tint dj = Math.min(j, m - 1 - j);\n\t\t\t\t\tif (Math.min(di, dj) == k - 1)\n\t\t\t\t\t\tres++;\n\t\t\t\t}\n\t\t}\n\t\tSystem.out.println(res);\n\t}\n}", "lang_cluster": "Java", "tags": ["math"], "code_uid": "25609d993be3af7fc4857dab7ee2c997", "src_uid": "fa1ef5f9bceeb7266cc597ba8f2161cb", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class Main {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int a = sc.nextInt();\n int b = sc.nextInt();\n int c = sc.nextInt();\n int d = sc. nextInt();\n int res1;\n int res2;\n int res11 = (3*a) / 10;\n int res21 = (3 * b) / 10;\n int res12 = a - (a / 250) * c;\n int res22 = b - (b / 250) * d;\n if (res11 >res12){\n res1 = res11;\n } else {\n res1 = res12;\n }\n if (res21 > res22){\n res2 = res21;\n } else {\n res2 = res22;\n }\n if (res1 > res2){\n System.out.println(\"Misha\");\n }\n if (res1 < res2){\n System.out.println(\"Vasya\");\n }\n if (res1 == res2){\n System.out.println(\"Tie\");\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "3876e8da1807b8db7877dbfc62948b75", "src_uid": "95b19d7569d6b70bd97d46a8541060d0", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class A {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n String a = \"\"+in.nextInt();\n \n boolean result = false;\n \n if(isPali(a)){\n result = true;\n }\n while(a.charAt(a.length()-1)=='0'){\n a=a.substring(0,a.length()-1);\n if(isPali(a)){\n result = true;\n }\n }\n\n System.out.println(result?\"YES\":\"NO\");\n }\n \n public static boolean isPali(String a){\n for(int i = 0; in) {\n\t\t\t\t a=1;\n\t\t\t }\n\t\t\t if(b<1) {\n\t\t\t\t b=n;\n\t\t\t }\n\t\t\t limit++;\n\t\t\t if(a==b) {\n\t\t\t\t System.out.println(\"YES\");\n\t\t\t\t break;\n\t\t\t }\n\t\t\t if(a==x || b ==y) {\n\t\t\t\t System.out.println(\"NO\");\n\t\t\t\t break;\n\t\t\t }\n\t\t }\n\t\t \n\t }\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "2d94057c7930571b2f1c4d0af84d0fdd", "src_uid": "5b889751f82c9f32f223cdee0c0095e4", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Minimum{\n \n public static void main(String[] args) throws IOException{\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int[]tab = new int [n];\n /*\n BufferedReader br = new BufferedReader( \n new InputStreamReader(System.in)); \n //int a=Integer.parseInt(br.readLine()) ; \n\n StringTokenizer st = new StringTokenizer(br.readLine()); \n */\n for (int i = 0; itre){\n tre= tab[l+1]-tab[l];\n }\n else if (l==j&&tab[l+1]-tab[l-1]>tre){\n tre= tab[l+1]-tab[l-1];\n }\n else if (l+1==j&&tab[l+2]-tal[l]>tre){\n tre = tab[l+2]-tab[l]; \n }\n */\n\n }\n\n if (tre0){\n\t\t\t\t\t \t\tsolve();\n\t\t\t\t\t \t\t\n\t\t\t\t\t \t}\n\t\t\t\t\t }\n\t\t\t\t\t\t \t\t\t\t \n\t\t\t\t \t\t\t\t\tpublic static void solve() {\n\t\t\t\t \n\t\t\t\t \t\t\t\t\t\t long t=nextLong();\n\t\t\t\t \t\t\t\t int l=nextInt();\n\t\t\t\t \t\t\t\t int r=nextInt();\n\t\t\t\t \t\t\t\t long[] ans=new long[r+1];\n\t\t\t\t \t\t\t\t Arrays.fill(ans, -1);\n\t\t\t\t \t\t\t\t long[] min=new long[r+1];\n\t\t\t\t \t\t\t\t Arrays.fill(min, -1);\n\t\t\t\t \t\t\t\t int sqr=(int)Math.sqrt(r);\n\t\t\t\t \t\t\t\t for(int i=2;i<=sqr;i++){\n\t\t\t\t \t\t\t\t if(min[i]==-1){\n\t\t\t\t \t\t\t\t min[i]=i;\n\t\t\t\t \t\t\t\t for(int j=i*i;j<=r;j+=i){\n\t\t\t\t \t\t\t\t if(min[j]==-1){\n\t\t\t\t \t\t\t\t min[j]=i;\n\t\t\t\t \t\t\t\t }\n\t\t\t\t \t\t\t\t }\n\t\t\t\t \t\t\t\t }\n\t\t\t\t \t\t\t\t }\n\t\t\t\t \t\t\t\t ans[1]=0;\n\t\t\t\t \t\t\t\t for(int i=2;i<=r;i++){\n\t\t\t\t \t\t\t\t if(min[i]==-1)\n\t\t\t\t \t\t\t\t min[i]=i;\n\t\t\t\t \t\t\t\t long x=((long)i/min[i])*(min[i]*(min[i]-1))/2;\n\t\t\t\t \t\t\t\t ans[i]=(x+ans[(int) (i/min[i])])%mod;\n\t\t\t\t \t\t\t\t }\n\t\t\t\t \t\t\t\t //for(int i=2;i<=r;i++)\n\t\t\t\t \t\t\t\t //System.out.println(ans[i]);\n\t\t\t\t \t\t\t\t long ans1=0;\n\t\t\t\t \t\t\t\t long pow=1;\n\t\t\t\t \t\t\t\t for(int i=l;i<=r;i++){\n\t\t\t\t \t\t\t\t //System.out.println(ans[i]);\n\t\t\t\t \t\t\t\t ans1=(ans1+(pow*ans[i])%mod)%mod;\n\t\t\t\t \t\t\t\t pow=(pow*t)%mod;\n\t\t\t\t \t\t\t\t }\n\t\t\t\t \t\t\t\t pw.println(ans1);\n\t\t\t\t \t\t\t\t\t}\n\t\t\t\t \t\t\t\t\t \n\t\t\t\t \t\t\t \t\t \t \t\n\t\t\t\t \t\t\t\t\tpublic static long pow(long n, long p,long mod) {\n\t\t\t\t \t\t\t\t\tif(p==0)\n\t\t\t\t \t\t\t\t\t\treturn 1;\n\t\t\t\t \t\t\t\t\tif(p==1)\n\t\t\t\t \t\t\t\t\t\treturn n%mod;\n\t\t\t\t \t\t\t\t\tif(p%2==0){\n\t\t\t\t \t\t\t\t\t\tlong temp=pow(n, p/2,mod);\n\t\t\t\t \t\t\t\t\treturn (temp*temp)%mod;\n\t\t\t\t \t\t\t\t\t}else{\n\t\t\t\t \t\t\t\t\t\t \tlong temp=pow(n,p/2,mod);\n\t\t\t\t \t\t\t\t\t\t \ttemp=(temp*temp)%mod;\n\t\t\t\t \t\t\t\t\t\t \treturn(temp*n)%mod;\n\t\t\t\t \t\t\t\t\t\t \t\n\t\t\t\t \t\t\t\t\t}\n\t\t\t\t \t\t\t\t}\t \t\t\n\t\t\t\t\t \t\t \t\t\t\t\n\t\t\t\t\t \t\t \n\t\t\t\t\tpublic static boolean isVowel(char c){ \t\t \t\t\n\t\t\t\t\t\tif(c=='a' || c=='i'|| c=='e' || c=='o' || c=='u')\n\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t public static String reverseString(String s) {\n\t\t\t\t\t\t\tStringBuilder sb = new StringBuilder(s);\n\t\t\t\t\t\t\tsb.reverse();\n\t\t\t\t\t\t\treturn (sb.toString());\n\t\t\t\t\t\t}\n\t\t\t\t\t private static BigInteger ncr(int n,int k){\n\t\t\t\t\t \tif (k < 0 || k > n) return BigInteger.ZERO;\n\t\t\t\t\t if (n-k < k) k = n-k;\n\t\t\t\t\t\n\t\t\t\t\t BigInteger x = BigInteger.ONE;\n\t\t\t\t\t for (int i = 1; i <= k; i++) {\n\t\t\t\t\t x = x.multiply(new BigInteger(\"\"+(n-i+1)));\n\t\t\t\t\tx = x.divide(new BigInteger(\"\"+i));\n\t\t\t\t\t }\n\t\t\t\t\t\n\t\t\t\t\treturn x;\n\t\t\t\t\t }\n\t\t\t\t\t static long fact[];\n\t\t\t\t\tprivate static void factmod(int n,int mod){\n\t\t\t\t\t\tfact=new long[n+1];\n\t\t\t\t\t\tfact[0]=1;\n\t\t\t\t\t\tfor(int i=1;i<=n;i++){\n\t\t\t\t\t\t\tfact[i]=i*fact[i-1];\n\t\t\t\t\t\t\t//fact[i]%=mod;\n\t\t\t\t\t\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\t\tprivate static long phi(long n){\n\t\t\t\t\t\tlong ans=n;\n\t\t\t\t\t\tif(n%2==0)\n\t\t\t\t\t\t\tans-=(ans/2);\n\t\t\t\t\t\twhile(n%2==0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tn/=2;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfor(int i=3;i*i<=n;i+=2){\n\t\t\t\t\t\t\tif(n%i==0){\n\t\t\t\t\t\t\twhile(n%i==0){\n\t\t\t\t\t\t\t\tn/=i;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tans-=(ans/i);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(n>2)\n\t\t\t\t\t\t\tans-=(ans/n);\n\t\t\t\t\t\t\n\t\t\t\t\t\treturn ans;\n\t\t\t\t\t}\n\t\t\t\t\tstatic long d,x,y;\n\t\t\t\t\tstatic long modInverse(long A, long M)\n\t\t\t\t\t{\n\t\t\t\t\textendedEuclid(A,M);\n\t\t\t\t\treturn (x%M+M)%M; //x may be negative\n\t\t\t\t\t}\n\t\t\t\t\tstatic void extendedEuclid(long A, long B) {\n\t\t\t\t\tif(B == 0) {\n\t\t\t\t\td = A;\n\t\t\t\t\tx = 1;\n\t\t\t\t\ty = 0;\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\textendedEuclid(B, A%B);\n\t\t\t\t\tlong temp = x;\n\t\t\t\t\tx = y;\n\t\t\t\t\ty = temp - (A/B)*y;\n\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tstatic boolean prime[];\n\t\t\t\t\tstatic int spf[];\n\t\t\t\t\tpublic static void sieve(int n){\n\t\t\t\t\t\tprime=new boolean[n+1];\n\t\t\t\t\t\tspf=new int[n+1];\n\t\t\t\t\t\t\n\t\t\t\t\t\tArrays.fill(spf, 1);\n\t\t\t\t\t\tArrays.fill(prime, true);\n\t\t\t\t\tprime[1]=false;\n\t\t\t\t\t\tspf[2]=2;\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\tfor(int i=3;i<=n;i+=2){\n\t\t\t\t\t\tif(prime[i]){\n\t\t\t\t\t\t\tspf[i]=i;\n\t\t\t\t\t\t\tfor(int j=2*i;j<=n;j+=i){\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tprime[j]=false;\n\t\t\t\t\t\t\tif(spf[j]==1){\n\t\t\t\t\t\t\t\tspf[j]=i;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\t\tpublic static boolean isPrime(long n) {\n\t\t\t\t\t\t\n\t\t\t\t\t\tif (n <= 1)\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\tif (n <= 3)\n\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\n\t\t\t\t\t\tif (n % 2 == 0 || n % 3 == 0)\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\n\t\t\t\t\t\tfor (long i = 5; i * i <= n; i = i + 6)\n\t\t\t\t\t\t\tif (n % i == 0 || n % (i + 2) == 0)\n\t\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\t \n\t\t\t\t\t\tpublic static long gcd(long x, long y) {\n\t\t\t\t\t\t\tif (x == 0)\n\t\t\t\t\t\t\t\treturn y;\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\treturn gcd( y % x,x);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\tpublic static void InputReader(InputStream stream1) {\n\t\t\t\t\t\t\tstream = stream1;\n\t\t\t\t\t\t}\n\t\t\t\t\t \n\t\t\t\t\t\tprivate static boolean isWhitespace(int c) {\n\t\t\t\t\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t\t\t\t\t}\n\t\t\t\t\t \n\t\t\t\t\t\tprivate static boolean isEndOfLine(int c) {\n\t\t\t\t\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t\t\t\t\t}\n\t\t\t\t\t \n\t\t\t\t\t\tprivate static int read() {\n\t\t\t\t\t\t\tif (numChars == -1)\n\t\t\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\t\t\tif (curChar >= numChars) {\n\t\t\t\t\t\t\t\tcurChar = 0;\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t\t\t\t\t} catch (IOException e) {\n\t\t\t\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (numChars <= 0)\n\t\t\t\t\t\t\t\t\treturn -1;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn buf[curChar++];\n\t\t\t\t\t\t}\n\t\t\t\t\t \n\t\t\t\t\t\tprivate static int nextInt() {\n\t\t\t\t\t\t\tint c = read();\n\t\t\t\t\t\t\twhile (isSpaceChar(c))\n\t\t\t\t\t\t\t\tc = read();\n\t\t\t\t\t\t\tint sgn = 1;\n\t\t\t\t\t\t\tif (c == '-') {\n\t\t\t\t\t\tsgn = -1;\n\t\t\t\t\t\tc = read();\n\t\t\t\t\t}\n\t\t\t\t\tint res = 0;\n\t\t\t\t\tdo {\n\t\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\tres *= 10;\n\t\t\t\t\tres += c - '0';\n\t\t\t\t\t\t\t\tc = read();\n\t\t\t\t\t\t\t} while (!isSpaceChar(c));\n\t\t\t\t\t\t\treturn res * sgn;\n\t\t\t\t\t\t}\n\t\t\t\t\t \n\t\t\t\t\t\tprivate static long nextLong() {\n\t\t\t\t\t\t\tint c = read();\n\t\t\t\t\t\t\twhile (isSpaceChar(c))\n\t\t\t\t\t\t\t\tc = read();\n\t\t\t\t\t\t\tint sgn = 1;\n\t\t\t\t\t\t\tif (c == '-') {\n\t\t\t\t\t\tsgn = -1;\n\t\t\t\t\t\tc = read();\n\t\t\t\t\t}\n\t\t\t\t\tlong res = 0;\n\t\t\t\t\tdo {\n\t\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\tres *= 10;\n\t\t\t\t\tres += c - '0';\n\t\t\t\t\t\t\t\tc = read();\n\t\t\t\t\t\t\t} while (!isSpaceChar(c));\n\t\t\t\t\t\t\treturn res * sgn;\n\t\t\t\t\t\t}\n\t\t\t\t\t \n\t\t\t\t\t\tprivate static String nextToken() {\n\t\t\t\t\t\t\tint c = read();\n\t\t\t\t\t\t\twhile (isSpaceChar(c))\n\t\t\t\t\t\t\t\tc = read();\n\t\t\t\t\t\t\tStringBuilder res = new StringBuilder();\n\t\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\t\tres.appendCodePoint(c);\n\t\t\t\t\t\t\t\tc = read();\n\t\t\t\t\t\t\t} while (!isSpaceChar(c));\n\t\t\t\t\t\t\treturn res.toString();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tprivate static double[] nextDoubleArray(int n) {\n\t\t\t\t\t\t\tdouble arr[]=new double[n];\n\t\t\t\t\t\t\tString a[]=nextLine().split(\" \");\n\t\t\t\t\t\t\tfor(int i=1;i map = new HashMap();\n map.put('U', 0);\n map.put('D', 1);\n map.put('L', 2);\n map.put('R', 3);\n \n int a = scan.nextInt();\n int b = scan.nextInt();\n scan.nextLine();\n char[] command = scan.nextLine().toCharArray();\n int N = command.length;\n \n int[] x = new int[N + 1];\n int[] y = new int[N + 1];\n boolean pass = a == 0 && b == 0;\n for (int i = 0; i < N; i++) {\n int direction = map.get(command[i]);\n x[i + 1] = x[i] + dx[direction];\n y[i + 1] = y[i] + dy[direction];\n if (a == x[i + 1] && b == y[i + 1]) {\n pass = true;\n }\n }\n \n if (pass) {\n } else if (x[N] == 0 && y[N] == 0) {\n } else if (x[N] == 0) {\n for (int i = 0; i < N; i++) {\n if (x[i] != a) {\n continue;\n }\n int diff = b - y[i];\n if (diff % y[N] == 0 && diff / y[N] >= 0) {\n pass = true;\n break;\n }\n }\n } else {\n for (int i = 0; i < N; i++) {\n int diff = a - x[i];\n if (diff % x[N] != 0 || diff / x[N] <= 0) {\n continue;\n }\n long step = diff / x[N];\n if (step * y[N] + y[i] == b) {\n pass = true;\n break;\n }\n }\n }\n System.out.println(pass ? \"Yes\" : \"No\");\n scan.close();\n }\n \n private static void print(int... arr) {\n System.out.print(arr[0]);\n for (int i = 1; i < arr.length; i++) {\n System.out.print(\" \");\n System.out.print(arr[i]);\n }\n System.out.println();\n }\n \n private static void print(long... arr) {\n System.out.print(arr[0]);\n for (int i = 1; i < arr.length; i++) {\n System.out.print(\" \");\n System.out.print(arr[i]);\n }\n System.out.println();\n }\n \n private static void print(T... arr) {\n System.out.print(arr[0]);\n for (int i = 1; i < arr.length; i++) {\n System.out.print(\" \");\n System.out.print(arr[i]);\n }\n System.out.println();\n }\n \n private static void read(Scanner scan, int[]... arrs) {\n int len = arrs[0].length;\n for (int i = 0; i < len; i++) {\n for (int[] arr : arrs) {\n arr[i] = scan.nextInt();\n }\n }\n }\n \n private static void read(Scanner scan, long[]... arrs) {\n int len = arrs[0].length;\n for (int i = 0; i < len; i++) {\n for (long[] arr : arrs) {\n arr[i] = scan.nextLong();\n }\n }\n }\n \n private static void decreaseByOne(int[]... arrs) {\n for (int[] arr : arrs) {\n for (int i = 0; i < arr.length; i++) {\n arr[i] --;\n }\n }\n }\n}", "lang_cluster": "Java", "tags": ["math", "implementation", "number theory"], "code_uid": "5cb60ac326f9d0f4065cffa8e04f5b3f", "src_uid": "5d6212e28c7942e9ff4d096938b782bf", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class B {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n long a = in.nextLong();\n int b = in.nextInt();\n int w = in.nextInt();\n int x = in.nextInt();\n long c = in.nextLong();\n long lo = 0;\n long hi = (long) 1e18;\n long ans = -1;\n while (lo <= hi) {\n long mid = lo + (hi - lo) / 2;\n long temp = mid;\n int B = b;\n long A = a;\n long[] seen = new long[2 * w];\n long[] aVal = new long[2 * w];\n Arrays.fill(seen, -1);\n while (temp > 0) {\n if (seen[B] != -1) {\n long tDiff = seen[B] - temp;\n long rounds = temp / tDiff;\n long aDiff = aVal[B] - A;\n A -= rounds * aDiff;\n temp -= rounds * tDiff;\n Arrays.fill(seen, -1);\n } else {\n seen[B] = temp;\n aVal[B] = A;\n temp--;\n if (B < x) {\n B += w - x;\n A--;\n } else\n B -= x;\n }\n }\n if (c - mid <= A) {\n ans = mid;\n hi = mid - 1;\n } else\n lo = mid + 1;\n }\n System.out.println(ans);\n }\n}", "lang_cluster": "Java", "tags": ["math", "binary search"], "code_uid": "3a27cd35d028a69b2bce7fdccc83b31c", "src_uid": "a1db3dd9f8d0f0cad7bdeb1780707143", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\n// program referenced from ml_guy's solution\npublic class Main {\n public static void main(String[] args) throws java.lang.Exception {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int m = sc.nextInt();\n int k = sc.nextInt();\n int ans = 0;\n if(n==m){\n System.out.println(1);\n return;\n }\n m -= n + 1;\n ans = 2;\n int left = Math.max(k - 1, 1);\n int right = Math.min(k + 1, n);\n while ((left > 1 || right < n) && m >= (right - left + 1)) {\n m -= right - left + 1;\n ans++;\n\n if (left > 1) {\n left--;\n }\n\n if (right < n) {\n right++;\n }\n }\n int len = right - left + 1;\n ans += m / len;\n System.out.println(ans);\n }\n}", "lang_cluster": "Java", "tags": ["greedy", "binary search"], "code_uid": "9ae1e48a32b0e62b27a2d184c283d027", "src_uid": "da9ddd00f46021e8ee9db4a8deed017c", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.Scanner;\n\n/**\n *\n * @author Lalo\n */\npublic class ContestSandbox {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n int length = Integer.parseInt(in.nextLine());\n String s = in.nextLine();\n String genome = \"ACTG\";\n int miniumChanges = 3215643;\n Map alphabet = new HashMap<>();\n\n int a = 1;\n for (char ch = 'A'; ch <= 'Z'; ch++) {\n alphabet.put(String.valueOf(ch), a);\n a++;\n }\n\n for (int i = 0; (i + 4) <= length; i++) {\n int sum = 0;\n for (int x = 0; x < 4; x++) {\n if (Math.abs(alphabet.get(genome.substring(x, x + 1)) - alphabet.get(s.substring(i + x, i + x + 1))) <= 13) {\n sum += Math.abs(alphabet.get(genome.substring(x, x + 1)) - alphabet.get(s.substring(i + x, i + x + 1)));\n } else if (alphabet.get(s.substring(i + x, i + x + 1)) > alphabet.get(genome.substring(x, x + 1))) {\n sum += (26 - alphabet.get(s.substring(i + x, i + x + 1)) + alphabet.get(genome.substring(x, x + 1)));\n } else {\n sum += (26 - alphabet.get(genome.substring(x, x + 1)) + alphabet.get(s.substring(i + x, i + x + 1)));\n }\n }\n\n if (sum < miniumChanges) {\n miniumChanges = sum;\n }\n }\n\n System.out.println(miniumChanges);\n }\n\n}", "lang_cluster": "Java", "tags": ["brute force", "strings"], "code_uid": "2209564d6053e13ea862817672453c80", "src_uid": "ee4f88abe4c9fa776abd15c5f3a94543", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.NoSuchElementException;\nimport java.io.Writer;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Alex\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tOutputWriter out = new OutputWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n public void solve(int testNumber, InputReader in, OutputWriter out){\n\t String F = in.next(), M = in.next(), S = in.next();\n\t if (beats(F, M) && beats(F, S)){\n\t\t out.printLine(\"F\");\n\t\t return;\n\t }\n\t if (beats(M, F) && beats(M, S)){\n\t\t out.printLine(\"M\");\n\t\t return;\n\t }\n\t if (beats(S, F) && beats(S, M)){\n\t\t out.printLine(\"S\");\n\t\t return;\n\t }\n\t out.printLine(\"?\");\n }\n\tboolean beats(String a, String b){\n\t\tif (a.equals(\"rock\") && b.equals(\"scissors\")) return true;\n\t\tif (a.equals(\"paper\") && b.equals(\"rock\")) return true;\n\t\tif (a.equals(\"scissors\") && b.equals(\"paper\")) return true;\n\t\treturn false;\n\t}\n}\n\nclass InputReader {\n\tprivate InputStream stream;\n\tprivate byte[] buf = new byte[1024];\n\tprivate int curChar;\n\tprivate int numChars;\n\tprivate SpaceCharFilter filter;\n\n\tpublic InputReader(InputStream stream) {\n\t\tthis.stream = stream;\n\t}\n\n\tpublic int read() {\n\t\tif (numChars == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (curChar >= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n\tpublic String readString() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tStringBuilder res = new StringBuilder();\n\t\tdo {\n\t\t\tif (Character.isValidCodePoint(c))\n\t\t\t\tres.appendCodePoint(c);\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res.toString();\n\t}\n\n\tpublic boolean isSpaceChar(int c) {\n\t\tif (filter != null)\n\t\t\treturn filter.isSpaceChar(c);\n\t\treturn isWhitespace(c);\n\t}\n\n\tpublic static boolean isWhitespace(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n\tpublic String next() {\n\t\treturn readString();\n\t}\n\tpublic interface SpaceCharFilter {\n\t\tpublic boolean isSpaceChar(int ch);\n\t}\n}\n\nclass OutputWriter {\n\tprivate final PrintWriter writer;\n\n\tpublic OutputWriter(OutputStream outputStream) {\n\t\twriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n\t}\n\tpublic void print(Object...objects) {\n\t\tfor (int i = 0; i < objects.length; i++) {\n\t\t\tif (i != 0)\n\t\t\t\twriter.print(' ');\n\t\t\twriter.print(objects[i]);\n\t\t}\n\t}\n\tpublic void printLine(Object...objects) {\n\t\tprint(objects);\n\t\twriter.println();\n\t}\n\tpublic void close() {\n\t\twriter.close();\n\t}\n}\n\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "fe0c35b1311a6e18367b62802b72b158", "src_uid": "072c7d29a1b338609a72ab6b73988282", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class A1080 {\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tSystem.out.println((int)(Math.ceil((double)(n*2)/k)+Math.ceil((double)(n*5)/k)+Math.ceil((double)(n*8)/k)));\n\t}\n\t\n}\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "1434d4258f9cedc67794c1c8e8758edd", "src_uid": "d259a3a5c38af34b2a15d61157cc0a39", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class Task112B {\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt() / 2;\n\t\tint x = sc.nextInt();\n\t\tint y = sc.nextInt();\n\t\tsc.close();\n\t\t\n\t\tif (((x == n) || (x == n + 1)) && ((y == n) || (y == n + 1))) {\t\t\t\n\t\t\tSystem.out.println(\"NO\");\n\t\t} else {\n\t\t\tSystem.out.println(\"YES\");\n\t\t}\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "3da1e8a9dcf6f373109fdd7b09183411", "src_uid": "dc891d57bcdad3108dcb4ccf9c798789", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.BufferedInputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.InputMismatchException;\nimport java.util.LinkedList;\nimport java.util.Map.Entry;\nimport java.util.Queue;\nimport java.util.Set;\nimport java.util.TreeSet;\n\npublic class Main\n{\n\tpublic void foo()\n\t{\n\t\tMyScanner scan = new MyScanner();\n\t\tint n = scan.nextInt();\n\t\tint m = scan.nextInt();\n\t\tfor(int k = 1; ;++k)\n\t\t{\n\t\t\tif(k * m > n)\n\t\t\t{\n\t\t\t\tSystem.out.println(-1);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tint y = n - k * m;\n\t\t\tif(y > k * m)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tSystem.out.println(k * m);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static void main(String[] args)\n\t{\n\t\tnew Main().foo();\n\t}\n\t\n\tclass MyScanner\n\t{\n\t private byte[] buf = new byte[1024];\n\t private int curChar;\n\t private int numChars;\n\t BufferedInputStream bis = new BufferedInputStream(System.in);\n\n\t public int read() \n\t {\n\t if (-1 == numChars)\n\t {\n\t \tthrow new InputMismatchException();\n\t }\n\t if (curChar >= numChars)\n\t {\n\t curChar = 0;\n\t try \n\t {\n\t numChars = bis.read(buf);\n\t }\n\t catch (IOException e)\n\t {\n\t throw new InputMismatchException();\n\t }\n\t if (numChars <= 0)\n\t {\n\t \treturn -1;\n\t }\n\t }\n\t return buf[curChar++];\n\t }\n\n\t public int nextInt() \n\t {\n\t int c = read();\n\t while (isSpaceChar(c))\n\t {\n\t \tc = read();\n\t }\n\t int sgn = 1;\n\t if (c == '-') \n\t {\n\t sgn = -1;\n\t c = read();\n\t }\n\t int res = 0;\n\t do \n\t {\n\t if (c < '0' || c > '9')\n\t {\n\t \tthrow new InputMismatchException();\n\t }\n\t res *= 10;\n\t res += c - '0';\n\t c = read();\n\t } while (!isSpaceChar(c));\n\t return res * sgn;\n\t }\n\t \n\t public long nextLong() \n\t {\n\t \tint c = read();\n\t \twhile (isSpaceChar(c))\n\t \t{\n\t \t\tc = read();\n\t \t}\n\t \tint sgn = 1;\n\t \tif (c == '-') \n\t \t{\n\t \t\tsgn = -1;\n\t \t\tc = read();\n\t \t}\n\t \tlong res = 0;\n\t \tdo \n\t \t{\n\t \t\tif (c < '0' || c > '9')\n\t \t\t{\n\t \t\t\tthrow new InputMismatchException();\n\t \t\t}\n\t \t\tres *= 10;\n\t \t\tres += c - '0';\n\t \t\tc = read();\n\t \t} while (!isSpaceChar(c));\n\t \treturn res * sgn;\n\t }\n\t \n\t public String next()\n\t {\n\t int c = read();\n\t while (isSpaceChar(c))\n\t {\n\t \tc = read();\n\t }\n\t StringBuilder res = new StringBuilder();\n\t do \n\t {\n\t res.appendCodePoint(c);\n\t c = read();\n\t } while (!isSpaceChar(c));\n\t return res.toString();\n\t }\n\n\t private boolean isSpaceChar(int c) \n\t {\n\t return ' ' == c || '\\n' == c || '\\r' == c || '\\t' == c || -1 == c;\n\t }\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "2645cdb4f18456eb96b85ca150be72af", "src_uid": "0fa526ebc0b4fa3a5866c7c5b3a4656f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "// Why do we fall ? So we can learn to pick ourselves up.\nimport java.util.*;\npublic class solve {\n static int mod = 1000000007;\n static int mod1 = 998244353;\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n int lll = sc.nextInt(),rrr = sc.nextInt(),a = sc.nextInt();\n int l = Math.min(lll,rrr),r = Math.max(lll,rrr);\n if(lll==rrr) System.out.println(2*(l+a/2));\n else {\n int ll = Math.min(r-l,a);\n l += ll;\n int aa = a-ll;\n System.out.println(2*(l+aa/2));\n }\n }\n}", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "efd03436dc3e3f98c37c9bc6d8fd4c35", "src_uid": "e8148140e61baffd0878376ac5f3857c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author lokesh1729\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n Garden_915A solver = new Garden_915A();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class Garden_915A {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int k = in.nextInt();\n int ans = Integer.MAX_VALUE;\n for (int i = 0; i < n; i++) {\n int m = in.nextInt();\n if (k % m == 0)\n ans = k / m < ans ? k / m : ans;\n }\n out.println(ans);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "78784ce125acec18846e3ab8288a6b7a", "src_uid": "80520be9916045aca3a7de7bc925af1f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class Third {\n\n public static void main(String[] args) {\n Scanner input = new Scanner (System.in);\n int n = input.nextInt();\n int o = n+1;\n int array [] = new int [n];\n for (int i = 0; i 0) {\n out.print(\" \");\n }\n out.print(b[i]);\n }\n out.println();\n }\n\n private int[] representInBase(long n, int k) {\n int numDigits = 0;\n long saved = n;\n while (n > 0) {\n n /= k;\n ++numDigits;\n }\n int[] res = new int[numDigits];\n n = saved;\n numDigits = 0;\n while (n > 0) {\n res[numDigits] = (int) (n % k);\n n /= k;\n ++numDigits;\n }\n return res;\n }\n\n }\n\n static class FastScanner {\n private BufferedReader in;\n private StringTokenizer st;\n\n public FastScanner(InputStream stream) {\n in = new BufferedReader(new InputStreamReader(stream));\n }\n\n public String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return st.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "941c018b555abfd9b3b5ba685c677b65", "src_uid": "f4dbaa8deb2bd5c054fe34bb83bc6cd5", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.*;\nimport static java.lang.Math.*;\n\npublic class ProblemB {\n\t\n void run() {\n Scanner sc = new Scanner(System.in);\n \n int a = sc.nextInt();\n int x = sc.nextInt();\n int y = sc.nextInt();\n \n p(\"%d\\n\", checkIn(a, x, y));\n \n// boolean out = checkIn(a, x, y);\n// if (out) {\n// \tp(\"1\\n\");\n// } else {\n// \tp(\"-1\\n\");\n// }\n }\n \n int checkIn(int a, int x, int y) {\n \tint out = 1;\n \td(\"test\");\n \tif (y % a == 0) { \t\t\n \t\treturn -1;\n \t}\n\n \tif (y < (2 * a)) {\n \t\td(\"hey\");\n \t\tout += y / a;\n \t\tif (Math.abs(x) < ((double) a) / 2) {\n \t\t\treturn out;\n \t\t} else {\n \t\t\treturn -1;\n \t\t}\n \t} else {\n \t\td(\"ho\");\n \t\tout += 2;\n \t\t \t\t\n \t\tint z = Math.max(y / (2 * a) - 1, 0); \t\t\n \t\tout += z * 3;\n \t\t\n \t\ty %= (2 * a);\n \t\td(\"y = \", y);\n \t\tif (y > a) {\n \t\t\tif (Math.abs(x) < ((double) a) / 2) {\n \t\t\t\tout += 2;\n \t\t\t\treturn out;\n \t\t\t} else {\n \t\t\t\td(\"fail\");\n \t\t\t\treturn -1;\n \t\t\t}\n \t\t} else {\n \t\t\tif (Math.abs(x) < a && x != 0) {\n \t\t\t\tif (x > 0) {\n \t\t\t\t\tout += 1;\n \t\t\t\t}\n \t\t\t\treturn out;\n \t\t\t} else {\n \t\t\t\treturn -1;\n \t\t\t}\n \t\t} \t\t\n \t}\t \t\n }\n \n boolean debug = false;\n void p(String f, Object...params) {\n System.out.printf(f, params);\n }\n void d(Object...params) {\n if (debug) {\n p(\"DEBUG: %s\\n\", Arrays.deepToString(params));\n }\n }\n public ProblemB(String[] args) {\n if (args.length > 0 && args[0].equals(\"debug\")) {\n debug = true;\n }\n }\n public static void main(String[] args) {\n new ProblemB(args).run();\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "geometry"], "code_uid": "c8f191f0ca8d27f8df21b23a5c8c6e00", "src_uid": "cf48ff6ba3e77ba5d4afccb8f775fb02", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\npublic class WeirdSubstraction {\n\n public static void weirdSubstraction(){ \n Scanner sc = new Scanner(System.in);\n long a = 0;\n long b = 0;\n \n \n a = sc.nextLong();\n b = sc.nextLong();\n \n \n while(a != 0 || b != 0){\n if(a == 0 || b == 0) break;\n else if(a >= b*2) {\n a %= 2*b; \n }\n else if(b >= a*2) {\n b %= 2*a; \n }\n else break;\n }\n \n System.out.println(a+\" \"+b);\n }\n \n public static void weirdSubstractionRec(long a, long b){ \n if(a == 0 || b == 0){\n System.out.println(a+\" \"+b);\n }\n else if(a >= b*2) {\n a -= 2*b; \n weirdSubstractionRec(a, b);\n }\n else if(b >= a*2) {\n b -= 2*a; \n weirdSubstractionRec(a, b);\n }\n else {\n System.out.println(a+\" \"+b);\n }\n }\n \n public static void main(String[] args) {\n /*Scanner sc = new Scanner(System.in);\n \n long a = sc.nextLong();\n long b = sc.nextLong();\n */\n weirdSubstraction();\n }\n \n}\n", "lang_cluster": "Java", "tags": ["math", "number theory"], "code_uid": "45cbaf7aa9b7ca852295f5dda1dc18b8", "src_uid": "1f505e430eb930ea2b495ab531274114", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": " \nimport java.util.Scanner;\n\npublic class cls_div2_328_B {\n public static void main(String[] args) {\n\n Scanner scan = new Scanner(System.in);\n \n long n = scan.nextInt();\n \n scan.close();\n \n long result = (n - 2) + ((n - 3) * (n - 2));\n \n System.out.println(result);\n }\n}\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "7e32db57b268384ac62fb9e4ae7d33c5", "src_uid": "efa8e7901a3084d34cfb1a6b18067f2b", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import static java.util.Arrays.deepToString;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class BinPow {\n\n\tstatic void solve() throws Exception {\n\t\tString s = next();\n\t\tchar max = 0;\n\t\tfor(char ch: s.toCharArray()){\n\t\t\tif(ch > max){\n\t\t\t\tmax = ch;\n\t\t\t}\n\t\t}\n\t\tString ans = \"\";\n\t\tfor(char ch: s.toCharArray()){\n\t\t\tif(ch == max){\n\t\t\t\tans += ch;\n\t\t\t}\n\t\t}\n\t\tSystem.out.print(ans);\n\t}\n\n\tstatic BufferedReader br;\n\tstatic StringTokenizer st;\n\tstatic PrintWriter out;\n\n\tstatic void debug(Object... a) {\n\t\tSystem.err.println(deepToString(a));\n\t}\n\n\tstatic int nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tstatic String next() throws IOException {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\tString line = br.readLine();\n\t\t\tif (line == null) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tst = new StringTokenizer(line);\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tstatic long nextLong() throws IOException {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tstatic double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tpublic static void main(String[] args) {\n\t\ttry {\t\t\t\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\t\n\t\t\tsolve();\t\n\t\t\tbr.close();\n\t\t} catch (Throwable e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "tags": ["brute force", "binary search", "bitmasks", "greedy", "strings", "implementation"], "code_uid": "ebfaee7390736692afacd26ade47dfc9", "src_uid": "9a40e9b122962a1f83b74ddee6246a40", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n void solve(Scanner in, PrintWriter out) {\n\n int a = in.nextInt();\n int b = in.nextInt();\n int x1 = in.nextInt();\n int y1 = in.nextInt();\n int x2 = in.nextInt();\n int y2 = in.nextInt();\n\n int n1 = Math.floorDiv(x1 + y1, 2 * a);\n int m1 = Math.floorDiv(x1 - y1, 2 * b);\n int n2 = Math.floorDiv(x2 + y2, 2 * a);\n int m2 = Math.floorDiv(x2 - y2, 2 * b);\n\n int res = Math.max(Math.abs(n2 - n1), Math.abs(m2 - m1));\n\n out.print(res);\n }\n\n void run() {\n try (Scanner in = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out)) {\n\n solve(in, out);\n }\n }\n\n public static void main(String[] args) {\n new Main().run();\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "constructive algorithms", "number theory"], "code_uid": "47981e3fe56c0955e146c2fd06932f4e", "src_uid": "7219d1837c83b5920992aee5a60dc0d9", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF {\n\n\tvoid solve() {\n\t\tint n = in.nextInt();\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = in.nextInt();\n\t\tint t = in.nextInt();\n\t\tArrays.sort(a);\n\t\tint max1 = 0;\n\t\tfor (int i = 0; i 0){\n return dp[l][r];\n }\n int min = Math.min(numberRemove(array,l+1,r,d,dp), numberRemove(array,l,r-1,d,dp));\n dp[l][r] = min+1;\n return min+1;\n }\n\n}", "lang_cluster": "Java", "tags": ["brute force", "sortings", "greedy"], "code_uid": "1e1b21e75be78fe8c52e5703207ee777", "src_uid": "6bcb324c072f796f4d50bafea5f624b2", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/*\n * Code Author: Sanket Udgirkar.\n * DA-IICT\n */\nimport java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\npublic class Tester\n{\n public static void main(String[] args) \n {\n //InputReader s=new InputReader(System.in);\n //OutputStream outputStream = System.out;\n \n Scanner s = new Scanner(System.in);\n \n BigInteger t=s.nextBigInteger();\n BigInteger w=s.nextBigInteger();\n BigInteger b=s.nextBigInteger();\n \n if(w.compareTo(b)==0)\n System.out.println(\"1/1\");\n else\n {\n BigInteger lcm = w.multiply(b).divide(w.gcd(b));\n BigInteger min=w.min(b).subtract(BigInteger.ONE);\n BigInteger sr = t.remainder(lcm);\n BigInteger ans = t.divide(lcm).multiply(min.add(BigInteger.ONE)).add(min.min(sr));\n \n BigInteger gcd = ans.gcd(t);\n System.out.printf(\"%d/%d\\n\",ans.divide(gcd),t.divide(gcd));\n }\n } \n \n public static long mod=(long)1e9+7;\n \n static BigInteger gcd(BigInteger a,BigInteger b)\n {\n if(b.longValue()==0)\n return a;\n a=a.mod(b);\n return gcd(b,a);\n }\n \n static long exp(long a, long b)\n {\n if(b==0)\n return 1;\n if(b==1)\n return a;\n if(b==2)\n return a*a;\n \n if(b%2==0)\n return exp(exp(a,b/2),2);\n else\n return a*exp(exp(a,(b-1)/2),2);\n }\n \n static void quicksort(int arr[],int low, int high)\n {\n int i=low;\n int j=high;\n int pivot=arr[(high+low)/2];\n int temp;\n \n while(i<=j)\n {\n while(arr[i]pivot)\n j--;\n \n if(i<=j)\n {\n temp=arr[i];\n arr[i]=arr[j];\n arr[j]=temp;\n \n i++;\n j--;\n }\n }\n \n if(low\n {\n long x,f;\n Pair(long ii, long cc)\n {\n x=ii;\n f=cc;\n }\n \n public int compareTo(Pair o) \n {\n return Long.compare(this.x, o.x);\n }\n \n }\n\n public static class InputReader \n {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n \n public InputReader(InputStream inputstream) \n {\n reader = new BufferedReader(new InputStreamReader(inputstream));\n tokenizer = null;\n }\n \n public String nextLine()\n {\n String fullLine=null;\n while (tokenizer == null || !tokenizer.hasMoreTokens()) \n {\n try {\n fullLine=reader.readLine();\n } \n catch (IOException e) \n {\n throw new RuntimeException(e);\n }\n return fullLine;\n }\n return fullLine;\n }\n public String next() \n {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n public long nextLong() {\n return Long.parseLong(next());\n }\n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n \n}", "lang_cluster": "Java", "tags": ["math"], "code_uid": "45ec55af4630ad13451d2339d44ba14b", "src_uid": "7a1d8ca25bce0073c4eb5297b94501b5", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.*;\npublic class CF_320A \n{\n\tpublic static void main(String args[])\n\t{\n\t\tScanner scan = new Scanner(System.in);\n\t\tString str;\n\t\tstr = scan.nextLine();\n\t\tscan.close();\n\t\t\n\t\tSystem.out.println(Answer(str));\n\t\t\n\t}\n\t\n\tpublic static String Answer(String str)\n\t{\n\t\tint counter=0;\n\t\tfor(int i=0;i0){counter++; continue; }\n\t\t\telse return \"NO\";\n\t\t}\n\t\treturn \"YES\";\n\t}\n}\n", "lang_cluster": "Java", "tags": ["brute force", "greedy"], "code_uid": "31dc05e3d6e7c2298cb711a881a73f82", "src_uid": "3153cfddae27fbd817caaf2cb7a6a4b5", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n public static int INF = 0x3f3f3f3f, mod = 1000000007, mod9 = 998244353;\r\n public static void main(String args[]){\r\n try {\r\n PrintWriter o = new PrintWriter(System.out);\r\n boolean multiTest = false;\r\n // init\r\n if(multiTest) {\r\n int t = fReader.nextInt(), loop = 0;\r\n while (loop < t) {loop++;solve(o);}\r\n } else solve(o);\r\n o.close();\r\n } catch (Exception e) {e.printStackTrace();}\r\n }\r\n static void solve(PrintWriter o) {\r\n try {\r\n int k = fReader.nextInt();\r\n // 3,5,7,...\r\n // 8,12,16,...\r\n long l = 3, r = 1l<<60;\r\n while(l < r) {\r\n long mid = l+(r-l)/2;\r\n if(check(mid, k)) r = mid;\r\n else l = mid+1;\r\n }\r\n o.println(r);\r\n } catch (Exception e){e.printStackTrace();}\r\n }\r\n static boolean check(long mx, int k) {\r\n long cnt = 0;\r\n cnt += (mx+1)/2-1;\r\n cnt += Math.max(0, mx/4-1);\r\n return cnt >= k;\r\n }\r\n public static int upper_bound(List a, int val){\r\n int l = 0, r = a.size();\r\n while(l < r){\r\n int mid = l + (r - l) / 2;\r\n if(a.get(mid) <= val) l = mid + 1;\r\n else r = mid;\r\n }\r\n return l;\r\n }\r\n public static int lower_bound(List a, int val){\r\n int l = 0, r = a.size();\r\n while(l < r){\r\n int mid = l + (r - l) / 2;\r\n if(a.get(mid) < val) l = mid + 1;\r\n else r = mid;\r\n }\r\n return l;\r\n }\r\n public static long gcd(long a, long b){\r\n return b == 0 ? a : gcd(b, a%b);\r\n }\r\n public static long lcm(long a, long b){\r\n return a / gcd(a,b)*b;\r\n }\r\n public static boolean isPrime(long x){\r\n boolean ok = true;\r\n for(long i=2;i<=Math.sqrt(x);i++){\r\n if(x % i == 0){\r\n ok = false;\r\n break;\r\n }\r\n }\r\n return ok;\r\n }\r\n public static void reverse(int[] array){\r\n reverse(array, 0 , array.length-1);\r\n }\r\n public static void reverse(int[] array, int left, int right) {\r\n if (array != null) {\r\n int i = left;\r\n for(int j = right; j > i; ++i) {\r\n int tmp = array[j];\r\n array[j] = array[i];\r\n array[i] = tmp;\r\n --j;\r\n }\r\n }\r\n }\r\n public static long qpow(long a, long n){\r\n long ret = 1l;\r\n while(n > 0){\r\n if((n & 1) == 1){\r\n ret = ret * a % mod;\r\n }\r\n n >>= 1;\r\n a = a * a % mod;\r\n }\r\n return ret;\r\n }\r\n public static class DSU {\r\n int[] parent;\r\n int[] size;\r\n int n;\r\n public DSU(int n){\r\n this.n = n;\r\n parent = new int[n];\r\n size = new int[n];\r\n for(int i=0;i= size[root_q]){\r\n parent[root_q] = root_p;\r\n size[root_p] += size[root_q];\r\n size[root_q] = 0;\r\n }\r\n else{\r\n parent[root_p] = root_q;\r\n size[root_q] += size[root_p];\r\n size[root_p] = 0;\r\n }\r\n n--;\r\n }\r\n public int getTotalComNum(){\r\n return n;\r\n }\r\n public int getSize(int i){\r\n return size[find(i)];\r\n }\r\n }\r\n public static class FenWick {\r\n int n;\r\n long[] tree;\r\n public FenWick(int n){\r\n this.n = n;\r\n tree = new long[n+1];\r\n }\r\n private void add(int x, long val){\r\n while(x <= n){\r\n tree[x] += val;\r\n x += x&-x;\r\n }\r\n }\r\n private long query(int x){\r\n long ret = 0l;\r\n while(x > 0){\r\n ret += tree[x];\r\n x -= x&-x;\r\n }\r\n return ret;\r\n }\r\n }\r\n public static class Node implements Comparable {\r\n Long fst;\r\n Integer snd;\r\n public Node(Long fst, Integer snd) {\r\n this.fst = fst;\r\n this.snd = snd;\r\n }\r\n @Override\r\n public int hashCode() {\r\n int prime = 31, res = 1;\r\n res = prime*res + fst.hashCode();\r\n res = prime*res + snd.hashCode();\r\n return res;\r\n }\r\n @Override\r\n public boolean equals(Object obj) {\r\n if(obj instanceof Node) {\r\n return fst.equals(((Node) obj).fst) && snd.equals(((Node) obj).snd);\r\n }\r\n return false;\r\n }\r\n @Override\r\n public int compareTo(Node node) {\r\n int result = Long.compare(fst, node.fst);\r\n return result == 0 ? Integer.compare(snd, node.snd) : result;\r\n }\r\n }\r\n public static class fReader {\r\n private static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\r\n private static StringTokenizer tokenizer = new StringTokenizer(\"\");\r\n private static String next() throws IOException{\r\n while(!tokenizer.hasMoreTokens()){tokenizer = new StringTokenizer(reader.readLine());}\r\n return tokenizer.nextToken();\r\n }\r\n public static int nextInt() throws IOException {return Integer.parseInt(next());}\r\n public static Long nextLong() throws IOException {return Long.parseLong(next());}\r\n public static double nextDouble() throws IOException {return Double.parseDouble(next());}\r\n public static char nextChar() throws IOException {return next().toCharArray()[0];}\r\n public static String nextString() throws IOException {return next();}\r\n public static String nextLine() throws IOException {return reader.readLine();}\r\n }\r\n}", "lang_cluster": "Java", "tags": ["math", "geometry", "binary search"], "code_uid": "30de169ebf80924b8328d12733413ca0", "src_uid": "d0a8604b78ba19ab769fd1ec90a72e4e", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n\n\nimport java.io.*;\nimport java.util.*;\n\n/**\n *\n * @author george150485\n */\npublic class Main {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) throws IOException {\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n ListA=new ArrayList();\n ListC=new ArrayList();\n for (int i = 0; i < 10; ++i) {\n A.add(br.readLine());\n }\n for (int i = 0; i < 10; i++) {\n C.add(A.get(i));\n }\n String help;\n for (int i = 0; i < 10; ++i) {\n help=\"\";\n for (int j = 0; j < 10; ++j) {\n help+=A.get(j).charAt(i);\n }\n C.add(help);\n }\n String one=\"XXXX.\";\n String two=\".XXXX\";\n String three=\"XXX.X\";\n String four=\"XX.XX\";\n String five=\"X.XXX\";\n for (int i = 0; i < 10; ++i) {\n for (int j = 0; j < 10; ++j) {\n //start row i col j\n help=\"\";\n help+=A.get(i).charAt(j);\n for (int l=j+1, m = i+1; m < 10; ++m,++l) {\n if(m==10||l==10)\n break;\n help+=A.get(m).charAt(l);\n }\n C.add(help);\n }\n }\n for (int i = 0; i < 10; ++i) {\n for (int j = 0; j < 10; ++j) {\n //start row i col j\n help=\"\";\n help+=A.get(i).charAt(j);\n for (int l=j-1, m = i+1; m <10; ++m,--l) {\n if(m==10||l==-1)\n break;\n help+=A.get(m).charAt(l);\n }\n C.add(help);\n }\n }\n for (int i = 0; i < C.size(); ++i) {\n if(C.get(i).contains(one)||C.get(i).contains(two)||C.get(i).contains(three)||C.get(i).contains(four)||C.get(i).contains(five)){\n System.out.println(\"YES\");System.exit(0);\n }\n\n }\n System.out.println(\"NO\");\n }\n \n}\n", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "9c96df8801814e33a34a31dcdf1ecd12", "src_uid": "d5541028a2753c758322c440bdbf9ec6", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\npublic class main{\n public static void main(String[] args){\n Scanner s=new Scanner(System.in);\nString str=\"\",str2=\"\";\nString k=s.next();\n String k2=\"CODEFORCES\";\n String tmp=k2,tmp2=k;\n \n for(int i=tmp.length();i>=0;i--)\n {\n tmp=tmp.substring(0, i);\n if(tmp2.startsWith(tmp))\n {\n tmp2=tmp2.replaceFirst(tmp,\"\");\n k2=k2.replaceFirst(tmp,\"\");\n for(int j=0;j 0) {\n\t\t\tint lastDig = i % 10;\n\n\t\t\tif (f1 == -1)\n\t\t\t\tf1 = lastDig;\n\t\t\tif (f2 == -1 && lastDig != f1)\n\t\t\t\tf2 = lastDig;\n\n\t\t\tif (f1 != -1 && f2 != -1 && (lastDig != f1 && lastDig != f2))\n\t\t\t\treturn false;\n\n\t\t\ti /= 10;\n\t\t}\n\n\t\treturn true;\n\t}\n}\n", "lang_cluster": "Java", "tags": ["brute force", "dfs and similar", "bitmasks"], "code_uid": "c59e62e17f478935fdd73c902f50da35", "src_uid": "0f7f10557602c8c2f2eb80762709ffc4", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\nimport java.util.Set;\nimport java.util.TreeSet;\n\npublic class Main {\n\n private static final Set PRIMES = new TreeSet<>(Arrays.asList(\n 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31,\n 37, 41, 43, 47, 53, 59, 61, 67, 71, 73,\n 79, 83, 89, 97, 101, 103, 107, 109, 113,\n 127, 131, 137, 139, 149, 151, 157, 163,\n 167, 173, 179, 181, 191, 193, 197, 199,\n 211, 223, 227, 229, 233, 239, 241, 251,\n 257, 263, 269, 271, 277, 281, 283, 293,\n 307, 311, 313, 317, 331, 337, 347, 349,\n 353, 359, 367, 373, 379, 383, 389, 397,\n 401, 409, 419, 421, 431, 433, 439, 443,\n 449, 457, 461, 463, 467, 479, 487, 491,\n 499, 503, 509, 521, 523, 541, 547, 557,\n 563, 569, 571, 577, 587, 593, 599, 601,\n 607, 613, 617, 619, 631, 641, 643, 647,\n 653, 659, 661, 673, 677, 683, 691, 701,\n 709, 719, 727, 733, 739, 743, 751, 757,\n 761, 769, 773, 787, 797, 809, 811, 821,\n 823, 827, 829, 839, 853, 857, 859, 863,\n 877, 881, 883, 887, 907, 911, 919, 929,\n 937, 941, 947, 953, 967, 971, 977, 983,\n 991, 997\n ));\n\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n System.out.println(solve(scanner.nextInt()));\n }\n\n public static String solve(int n) {\n if (PRIMES.contains(n)) {\n return \"\";\n }\n StringBuilder sb = new StringBuilder();\n for (int prime: PRIMES) {\n while (n % prime == 0) {\n n = n / prime;\n sb.append(prime);\n }\n if (n == 1) {\n break;\n }\n }\n return sb.toString();\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "number theory"], "code_uid": "e58c30ea3b60c75839d2e2d56c68b25f", "src_uid": "7220f2da5081547a12118595bbeda4f6", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n \npublic class Main {\n \n\tpublic static void main(String[] args) {\n\t\t\n\t\tScanner input = new Scanner(System.in);\n\t\t\n\t\t//inputs\n\t\tlong n = input.nextLong();\n if(n == 0)\n System.out.println(0);\n else if((n + 1) % 2 == 0)\n System.out.println((n + 1) / 2);\n else\n System.out.println(n + 1);\n\t}\n}", "lang_cluster": "Java", "tags": ["math"], "code_uid": "727a5daf7d4e53929fba30c9fbea92f3", "src_uid": "236177ff30dafe68295b5d33dc501828", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\r\npublic class Problem1505b {\r\n public static void main(String[] args) {\r\n Scanner sc = new Scanner(System.in);\r\n int n = sc.nextInt();\r\n System.out.println((n-1)%9 + 1);\r\n }\r\n}\r\n", "lang_cluster": "Java", "tags": ["implementation", "number theory"], "code_uid": "57d41c2dabcddfbf4d421668dd3e0e92", "src_uid": "477a67877367dc68b3bf5143120ff45d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskB solver = new TaskB();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskB {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n long n = in.nextLong();\n long k = in.nextLong();\n long res = 0;\n\n if (k % 2 == 1) {\n res = 1;\n } else {\n while (k > 0) {\n int m = twoPow(k);\n if (k == (Math.pow(2L, m))) {\n res = m + 1;\n break;\n }\n k -= Math.pow(2L, m - 1);\n }\n\n }\n out.println(res);\n }\n\n int twoPow(long k) {\n int res = 0;\n while (Math.pow(2L, res) < k) res++;\n return res;\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["constructive algorithms", "binary search", "implementation", "bitmasks"], "code_uid": "fdd8db4d35ae85cadd5d34351738f27c", "src_uid": "0af400ea8e25b1a36adec4cc08912b71", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Ivan{\n\n public static boolean check(long s,long n){\n long big = 0;\n long u = s;\n while (s != 0){\n long amari = s % 10;\n big = big + s % 10;\n s = (s - amari) / 10;\n }\n if (u - big >= n){\n return true;\n }else return false;\n }\n public static void main(String args[]){\n Scanner scan = new Scanner(System.in);\n long s = scan.nextLong();\n long n = scan.nextLong();\n long r =0;\n if ( s > n){\n for (long i = n;i 0) {\n\t\t\n\t\t\tint n = s.nextInt();\n\t\t\t\n\t\t\tint[] check = new int[10000];\n\t\t\t\n\t\t\tint[][] val = new int[n][6];\n\t\t\t\n\t\t\tfor(int i = 0; i < n; i++)\n\t\t\t\tfor(int j = 0; j < 6; j++)\n\t\t\t\t\tval[i][j] = s.nextInt();\n\t\t\t\n\t\t\tfor(int i = 0; i < n; i++)\n\t\t\t\tfor(int v1 = 0; v1 < 6; v1++)\n\t\t\t\t\tcheck[val[i][v1]] = 1;\n\t\t\t\n\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\t\n\t\t\t\tfor(int j = 0; j < n; j++) {\n\t\t\t\t\t\n\t\t\t\t\tif(i == j)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\n\t\t\t\t\tfor(int v1 = 0; v1 < 6; v1++)\n\t\t\t\t\t\tfor(int v2 = 0; v2 < 6; v2++)\n\t\t\t\t\t\t\tcheck[10 * val[i][v1] + val[j][v2]] = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\t\n\t\t\t\tfor(int j = 0; j < n; j++) {\n\t\t\t\t\t\n\t\t\t\t\tif(i == j)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\n\t\t\t\t\tfor(int k = 0; k < n; k++) {\n\t\t\t\t\t\t\n\t\t\t\t\t\tif(i == k || j == k)\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\n\t\t\t\t\t\tfor(int v1 = 0; v1 < 6; v1++)\n\t\t\t\t\t\t\tfor(int v2 = 0; v2 < 6; v2++)\n\t\t\t\t\t\t\t\tfor(int v3 = 0; v3 < 6; v3++)\n\t\t\t\t\t\t\t\t\tcheck[100 * val[i][v1] + 10 * val[j][v2] + val[k][v3]] = 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tint x = 1;\n\t\t\t\n\t\t\twhile(check[x] == 1)\n\t\t\t\tx++;\n\t\t\t\n\t\t\tw.println(x - 1);\n\t\t\t\n\t\t}\n\t\t\n\t\tw.close();\n\t}\n\t\n\tstatic class InputReader\n\t{\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n\t\tprivate SpaceCharFilter filter;\n\t\t\n\t\tpublic InputReader(InputStream stream)\n\t\t{\n\t\t\tthis.stream = stream;\n\t\t}\n\t\t\n\t\tpublic int read()\n\t\t{\n\t\t\tif (numChars==-1) \n\t\t\t\tthrow new InputMismatchException();\n\t\t\t\n\t\t\tif (curChar >= numChars)\n\t\t\t{\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry \n\t\t\t\t{\n\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t}\n\t\t\t\tcatch (IOException e)\n\t\t\t\t{\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif(numChars <= 0)\t\t\t\t\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\t \n\t\tpublic String nextLine()\n\t\t{\n\t\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\t\tString str = \"\";\n try\n {\n str = br.readLine();\n }\n catch (IOException e)\n {\n e.printStackTrace();\n }\n return str;\n\t\t}\n\t\tpublic int nextInt()\n\t\t{\n\t\t\tint c = read();\n\t\t\t\n\t\t\twhile(isSpaceChar(c)) \n\t\t\t\tc = read();\n\t\t\t\n\t\t\tint sgn = 1;\n\t\t\t\n\t\t\tif (c == '-') \n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\t\n\t\t\tint res = 0;\n\t\t\tdo \n\t\t\t{\n\t\t\t\tif(c<'0'||c>'9') \n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\twhile (!isSpaceChar(c)); \n\t\t\t\n\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic long nextLong() \n\t\t{\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') \n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\t\n\t\t\tdo \n\t\t\t{\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\twhile (!isSpaceChar(c));\n\t\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic double nextDouble() \n\t\t{\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') \n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tdouble res = 0;\n\t\t\twhile (!isSpaceChar(c) && c != '.') \n\t\t\t{\n\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\treturn res * Math.pow(10, nextInt());\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tif (c == '.') \n\t\t\t{\n\t\t\t\tc = read();\n\t\t\t\tdouble m = 1;\n\t\t\t\twhile (!isSpaceChar(c)) \n\t\t\t\t{\n\t\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\t\treturn res * Math.pow(10, nextInt());\n\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\tm /= 10;\n\t\t\t\t\tres += (c - '0') * m;\n\t\t\t\t\tc = read();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic String readString() \n\t\t{\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo \n\t\t\t{\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} \n\t\t\twhile (!isSpaceChar(c));\n\t\t\t\n\t\t\treturn res.toString();\n\t\t}\n\t \n\t\tpublic boolean isSpaceChar(int c) \n\t\t{\n\t\t\tif (filter != null)\n\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\t \n\t\tpublic String next() \n\t\t{\n\t\t\treturn readString();\n\t\t}\n\t\t\n\t\tpublic interface SpaceCharFilter \n\t\t{\n\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t}\n \n\tpublic static void main(String args[]) throws Exception\n\t{\n\t\tnew Thread(null, new codeforces(),\"codeforces\",1<<26).start();\n\t}\n\t \n} ", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "a11c590d4747410af0716e9f0b09336e", "src_uid": "20aa53bffdfd47b4e853091ee6b11a4b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class B {\n public static StreamTokenizer in = new StreamTokenizer(System.in);\n public static boolean bg = true;\n public static long[][] data = null;\n public static long finmin = Long.MAX_VALUE;\n public static void main(String[] args) throws Exception {\n Scanner scan = new Scanner(System.in);\n int n1 = Integer.parseInt(scan.next());\n int k1 = Integer.parseInt(scan.next());\n \n \n data = new long[n1][];\n for (int i=0;i l1, HashSet s1, int k1){\n if (l1.size()==k1){\n //pn(l1);\n long max = Long.MIN_VALUE;\n long min = Long.MAX_VALUE;\n for (long[] e: data){\n long cur = 0;\n for (int f: l1){\n cur *=10;\n cur += e[f];\n }\n if (cur>max){\n max = cur;\n }\n if (cur C.length()) {\n String tmp = \"\";\n for(int i=0; i0)\n {\n ans*=f;\n \n f--;\n }\n System.out.println(ans);\n }\n \n}\n", "lang_cluster": "Java", "tags": ["math", "implementation", "number theory"], "code_uid": "850c723ba2c3ce8a206d86f3536ff475", "src_uid": "7bf30ceb24b66d91382e97767f9feeb6", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\n\npublic class Code83\n{\n\t\n\tprivate static long mod = 1000000007;\n\tstatic class InputReader {\n\t\t \n\t\tprivate final InputStream stream;\n\t\tprivate final byte[] buf = new byte[8192];\n\t\tprivate int curChar, snumChars;\n\t\tprivate SpaceCharFilter filter;\n \n\t\tpublic InputReader(InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n \n\t\tpublic int snext() {\n\t\t\tif (snumChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= snumChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tsnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (snumChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n \n\t\tpublic int nextInt() {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n \n\t\tpublic long nextLong() {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n \n\t\tpublic int[] nextIntArray(int n) {\n\t\t\tint a[] = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\ta[i] = nextInt();\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n \n\t\tpublic String readString() {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = snext();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n \n\t\tpublic String nextLine() {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = snext();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = snext();\n\t\t\t} while (!isEndOfLine(c));\n\t\t\treturn res.toString();\n\t\t}\n \n\t\tpublic boolean isSpaceChar(int c) {\n\t\t\tif (filter != null)\n\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n \n\t\tprivate boolean isEndOfLine(int c) {\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t}\n \n\t\tpublic interface SpaceCharFilter {\n\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t}\n\t\n\tstatic class pair implements Comparable\n\t{\n\t\tInteger x, y;\n\t\tpair(int x,int y)\n\t\t{\n\t\t\tthis.x=x;\n\t\t\tthis.y=y;\n\t\t}\n\t\t\n\t\tpublic int compareTo(pair o) {\n\t\t\tint result = x.compareTo(o.x);\n\t\t\tif(result==0)\n\t\t\t\tresult = y.compareTo(o.y);\n\t\t\t\n\t\t\treturn result;\n\t\t} \n\t}\n\t\n\tpublic static int[] suffle(int[] a,Random gen)\n\t{\n\t\tint n = a.length;\n\t\tfor(int i=0;i primeFactorization(int n)\n\t{\n\t\tArrayList a =new ArrayList();\n\t\tfor(int i=2;i*i<=n;i++)\n\t\t{\n\t\t\twhile(n%i==0)\n\t\t\t{\n\t\t\t\ta.add(i);\n\t\t\t\tn/=i;\n\t\t\t}\n\t\t}\n\t\tif(n!=1)\n\t\t\ta.add(n);\n\t\treturn a;\n\t}\n\t\n\tpublic static int GCD(int a,int b)\n\t{\n\t\tif(b==0)\n\t\t\treturn a;\n\t\telse\n\t\t\treturn GCD(b,a%b);\n\t}\n\t\n\tpublic static long GCD(long a,long b)\n\t{\n\t\tif(b==0)\n\t\t\treturn a;\n\t\telse\n\t\t\treturn GCD(b,a%b);\n\t}\n\t\n\tpublic static long LCM(long a,long b)\n\t{\n\t\treturn (a*b)/GCD(a,b);\n\t}\n\t\n\tpublic static int LCM(int a,int b)\n\t{\n\t\treturn (a*b)/GCD(a,b);\n\t}\n\t\n\tpublic static int binaryExponentiation(int x,int n)\n\t{\n\t int result=1;\n\t while(n>0)\n\t {\n\t if(n % 2 ==1)\n\t result=result * x;\n\t x=x*x;\n\t n=n/2;\n\t }\n\t return result;\n\t}\n\t\n\tpublic static long binaryExponentiation(long x,long n)\n\t{\n\t long result=1;\n\t while(n>0)\n\t {\n\t if(n % 2 ==1)\n\t result=result * x;\n\t x=x*x;\n\t n=n/2;\n\t }\n\t return result;\n\t}\n\t\n\tpublic static int modularExponentiation(int x,int n,int M)\n\t{\n\t int result=1;\n\t while(n>0)\n\t {\n\t if(n % 2 ==1)\n\t result=(result * x)%M;\n\t x=(x*x)%M;\n\t n=n/2;\n\t }\n\t return result;\n\t}\n\t\n\tpublic static long modularExponentiation(long x,long n,long M)\n\t{\n\t long result=1;\n\t while(n>0)\n\t {\n\t if(n % 2 ==1)\n\t result=(result * x)%M;\n\t x=(x*x)%M;\n\t n=n/2;\n\t }\n\t return result;\n\t}\n\t\n\tpublic static int modInverse(int A,int M)\n\t{\n\t return modularExponentiation(A,M-2,M);\n\t}\n\t\n\tpublic static long modInverse(long A,long M)\n\t{\n\t return modularExponentiation(A,M-2,M);\n\t}\n\t\n\tpublic static void main(String[] args)\n\t{\n\t\tInputReader in = new InputReader(System.in);\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\t\n\t\tlong m = in.nextLong();\n\t\tlong start = 1;\n\t\tlong end = Long.MAX_VALUE-1;\n\t\tlong result = -1;\n\t\twhile(start<=end)\n\t\t{\n\t\t\tlong mid = (start+end)/2;\n\t\t\tlong ans = 0 ;\n\t\t\tfor(long i=2;(i*i*i)<=mid;i++)\n\t\t\t{\n\t\t\t\tans+=(mid/(i*i*i));\n\t\t\t}\n\t\t\t\n\t\t\t//System.out.println(mid + \" \" +ans);\n\t\t\tif(ans==m)\n\t\t\t{\n\t\t\t\tresult = mid;\n\t\t\t\tend = mid-1;\n\t\t\t}\n\t\t\t\n\t\t\telse if(ansm)\n\t\t\t\tend = mid-1;\n\t\t}\n\t\t\n\t\tpw.println(result);\n\t\tpw.flush();\n\t\tpw.close();\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "binary search", "combinatorics"], "code_uid": "30a5cda623219ef727458ead0dd0d4d6", "src_uid": "602deaad5c66e264997249457d555129", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.*;\r\nimport java.util.*;\r\n \r\npublic class Codeforces {\r\n\tpublic static void main(String[] args) throws IOException {\r\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n\t\t//int cases = Integer.parseInt(br.readLine());\r\n\t\t//o:while(cases-- > 0) {\r\n\t\t\tString[] str = br.readLine().split(\" \");\r\n\t\t\tint n = Integer.parseInt(str[0]);\r\n long mod = Long.parseLong(str[1]);\r\n long [] dp = new long[n + 1];\r\n dp[1] = 1;\r\n long sum = 1;\r\n for (int i = 2; i <= n; i++) {\r\n dp[i] = sum;\r\n // the dp value that some range of numbers takes\r\n int cur = 1;\r\n int max = i;\r\n //System.out.println(\"==== \"+i+\" =======\");\r\n while (cur <= i / 2) {\r\n int around = i / (cur + 1);\r\n int min = -1;\r\n for (int j = around + 1; j >= Math.max(1, around - 1); j--) {\r\n if (i / j <= cur) {\r\n min = j;\r\n }else {\r\n \tbreak;\r\n }\r\n }\r\n dp[i] = (dp[i] + (dp[cur] * (max - min + 1)) % mod) % mod;\r\n //System.out.println(cur+\" \"+min+\" \"+max);\r\n max = min - 1;\r\n cur = i / max;\r\n }\r\n sum = (sum + dp[i]) % mod;\r\n }\r\n System.out.println(dp[n]);\r\n\t\t//}\r\n\t}\r\n}", "lang_cluster": "Java", "tags": ["brute force", "math", "dp", "data structures", "number theory"], "code_uid": "96bf89c7719ea578a148b077bbd35451", "src_uid": "a524aa54e83fd0223489a19531bf0e79", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class TaskD {\n BufferedReader br;\n PrintWriter out;\n StringTokenizer st;\n\n public static void main(String[] args) throws IOException {\n new TaskD().run();\n }\n\n void run() throws IOException {\n br = new BufferedReader(new InputStreamReader(System.in));\n st = null;\n out = new PrintWriter(System.out);\n solve();\n br.close();\n out.close();\n }\n\n\n int a[][] ;\n int dm[];\n void solve() throws IOException {\n a = new int[15][];\n a[0] = new int[] {1, 2, 3};\n a[1] = new int[] {17, 18, 19};\n a[2] = new int[] {8, 13, 17};\n a[3] = new int[] {3, 7, 12};\n a[4] = new int[] {1, 4, 8};\n a[5] = new int[] {12, 16, 19};\n a[6] = new int[] {7, 11, 15, 18};\n a[7] = new int[] {2, 5, 9, 13};\n a[8] = new int[] {2, 6, 11, 16};\n a[9] = new int[] {13, 14, 15, 16};\n a[10] = new int[] {4, 9, 14, 18};\n a[11] = new int[] {4, 5, 6, 7};\n a[12] = new int[] {8, 9, 10, 11, 12};\n a[13] = new int[] {1, 5, 10, 15, 19};\n a[14] = new int[] {3, 6, 10, 14, 17};\n\n\n\n dm = new int[1 << 19];\n Arrays.fill(dm, -1);\n\n for (int i = 0; i < a.length; ++i)\n for (int j = 0; j < a[i].length; ++j)\n a[i][j] -- ;\n\n int mask = 0;\n for (int t = 0; t < 19; ++t) {\n String str = nextToken();\n if (str.compareTo(\"O\") == 0) mask |= (1 << t) ;;\n }\n int res = brute(mask);\n out.print(res == 1 ? \"Karlsson\" : \"Lillebror\");\n\n }\n int brute(int mask) {\n if (mask == 0) {\n return 0;\n }\n if (dm[mask] != -1) return dm[mask];\n\n for(int v = 0; v < a.length; ++v) {\n\n for (int i = 0; i < a[v].length; ++i) {\n for(int j = i; j < a[v].length; ++j) {\n boolean ok = true;\n int cm = 0;\n for (int u = i; ok && u <= j; ++u) {\n if ((mask & (1 << a[v][u])) == 0) { \n ok = false;\n } else cm |= (1 << a[v][u]);\n \n }\n if (ok && cm > 0) { \n int d = brute(mask ^ cm);\n if (d == 0) return dm[mask] = 1;\n }\n }\n }\n }\n return dm[mask] = 0;\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n String nextToken() throws IOException {\n while (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(br.readLine());\n }\n return st.nextToken();\n }\n}", "lang_cluster": "Java", "tags": ["dfs and similar", "games", "dp", "bitmasks", "implementation"], "code_uid": "3354115acb0b28881569bbf096be2a4e", "src_uid": "eaa022cc7846c983a826900dc6dd919f", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class practice {\n\tstatic class FastReader \n { \n BufferedReader br; \n StringTokenizer st; \n \n public FastReader() \n { \n br = new BufferedReader(new\n InputStreamReader(System.in)); \n } \n \n String next() \n { \n while (st == null || !st.hasMoreElements()) \n { \n try\n { \n st = new StringTokenizer(br.readLine()); \n } \n catch (IOException e) \n { \n e.printStackTrace(); \n } \n } \n return st.nextToken(); \n } \n \n int nextInt() \n { \n return Integer.parseInt(next()); \n } \n \n long nextLong() \n { \n return Long.parseLong(next()); \n } \n \n double nextDouble() \n { \n return Double.parseDouble(next()); \n } \n \n String nextLine() \n { \n String str = \"\"; \n try\n { \n str = br.readLine(); \n } \n catch (IOException e) \n { \n e.printStackTrace(); \n } \n return str; \n } \n } \n\tstatic class Print\n\t{\n\t private final BufferedWriter bw;\n\t public Print()\n\t {\n\t bw=new BufferedWriter(new OutputStreamWriter(System.out));\n\t }\n\t public void print(String str)throws IOException\n\t {\n\t bw.append(str);\n\t }\n\t public void println(String str)throws IOException\n\t {\n\t print(str);\n\t bw.append(\"\\n\");\n\t }\n\t public void close()throws IOException\n\t {\n\t bw.close();\n\t }}\n\t\tpublic static void main(String[] args) throws IOException {\t\t\t\n\t\t\tFastReader scn=new FastReader();\n\t\t\tPrint p=new Print();\n\t\t\tlong n=scn.nextLong(),m=scn.nextLong(),s=scn.nextLong();\n\t\t\tlong ans=((n-1)/s+1)*((m-1)/s+1)*((n-1)%s+1)*((m-1)%s+1);\n\t\t\tp.println(Long.toString(ans));\n\t\t\t\n\t\t\tp.close();\n\t\t\t\n\t\t}\n}", "lang_cluster": "Java", "tags": ["math"], "code_uid": "194fb0f2a1d83dc94a3a1f204e862663", "src_uid": "e853733fb2ed87c56623ff9a5ac09c36", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/******************************************************************************\n\nWelcome to GDB Online.\nGDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,\nC#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.\nCode, Compile, Run and Debug online from anywhere in world.\n\n*******************************************************************************/\nimport java.util.*;\npublic class Main\n{\n\tpublic static void main(String[] args) {\n\t Scanner sc=new Scanner(System.in);\n\t int n=sc.nextInt();\n\t int v1=sc.nextInt();\n\t int v2=sc.nextInt();\n\t int t1=sc.nextInt();\n\t int t2=sc.nextInt();\n\t int ans1=(n*v1)+(t1+t1);\n\t int ans2=(n*v2)+(t2+t2);\n\t if(ans1ans2)\n\t {\n\t System.out.println(\"Second\");\n\t }\n\t else if(ans1==ans2)\n\t \t\t{\n\t \t\t\tSystem.out.println(\"Friendship\");\n\t \t\t}\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "b3c2b8de9bf34d8998aabb0b29cab7c0", "src_uid": "10226b8efe9e3c473239d747b911a1ef", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class InitialBet {\n\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tBufferedReader reader = new BufferedReader(new InputStreamReader(\n\t\t\t\tSystem.in));\n\t\tString[] strings = reader.readLine().split(\" \");\n\t\tint c1 = Integer.valueOf(strings[0]);\n\t\tint c2 = Integer.valueOf(strings[1]);\n\t\tint c3 = Integer.valueOf(strings[2]);\n\t\tint c4 = Integer.valueOf(strings[3]);\n\t\tint c5 = Integer.valueOf(strings[4]);\n\t\tint sum = (c1 + c2 + c3 + c4 + c5);\n\t\tif (sum == 0) {\n\t\t\tSystem.out.println(-1);\n\t\t\treturn;\n\t\t}\n\t\tif (sum % 5 == 0) {\n\t\t\tSystem.out.println(sum / 5);\n\t\t} else {\n\t\t\tSystem.out.println(-1);\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "17c3ddff1aff3e152254bdfce7d299ae", "src_uid": "af1ec6a6fc1f2360506fc8a34e3dcd20", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\r\nimport java.math.*;\r\n\r\npublic class Dominoes {\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner o = new Scanner(System.in);\r\n\t\tint n = o.nextInt(), m = o.nextInt();\r\n\t\tBigInteger b1 = BigInteger.valueOf(n), b2 = BigInteger.valueOf(m);\r\n\t\tif( n == 1 && m == 1)\r\n\t\t\tSystem.out.println(0);\r\n\t\telse if( m == 1 )\r\n\t\t\tSystem.out.println(n - 1);\r\n\t\telse\r\n\t\t\tSystem.out.println(BigInteger.valueOf(m - 1).multiply(b1));\r\n\t}\r\n}\r\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "a2ed0a25ce6ea31ecdb5e41cb2263289", "src_uid": "a91aab4c0618d036c81022232814ef44", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.ArrayList;\r\nimport java.util.BitSet;\r\nimport java.util.Scanner;\r\n\r\npublic class SquaresAndCubes {\r\n public static void main(String[] args) {\r\n Scanner in = new Scanner(System.in);\r\n int t = in.nextInt();\r\n for (int i = 0; i < t; i++) {\r\n long n = in.nextLong();\r\n long a = (long)Math.sqrt(n);\r\n long b = (long)Math.cbrt(n);\r\n long c = (long)Math.sqrt(b);\r\n //System.out.println(a);\r\n //System.out.println(b);\r\n //System.out.println(c);\r\n System.out.println(a+b-c);\r\n }\r\n }\r\n}\r\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "3f3b36d4d7f3d4982db26ef0a31af56c", "src_uid": "015afbefe1514a0e18fcb9286c7b6624", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class B{\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n= sc.nextInt();\n int a[]=new int[n];\n for(int i=0;iya)\n sum = sum+a[1];\n if (z<0)\n sum = sum+a[2];\n if (z>za)\n sum = sum+a[3];\n if (x<0)\n sum = sum + a[4];\n if (x>xa)\n sum = sum + a[5];\n pw.print(sum);\n pw.flush();\n pw.close();\n\n }\n\n}\n\n", "lang_cluster": "Java", "tags": ["brute force", "geometry"], "code_uid": "16d63a0e2944256840e2a083a86a6c70", "src_uid": "c7889a8f64c57cf7be4df870f68f749e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Junior\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskC {\n int MOD = 998244353;\n int N = 5001;\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int a = in.nextInt();\n int b = in.nextInt();\n int c = in.nextInt();\n int[][] dp = new int[N][N];\n for (int i = 0; i < N; ++i) {\n for (int j = 0; j < N; ++j) {\n if (i == 0 || j == 0) dp[i][j] = 1;\n else\n dp[i][j] = (int) MathUtils.addMod(dp[i - 1][j], MathUtils.mulMod(j, dp[i - 1][j - 1], MOD), MOD);\n }\n }\n out.println(MathUtils.mulMod(dp[a][b], MathUtils.mulMod(dp[a][c], dp[b][c], MOD), MOD));\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void println(long i) {\n writer.println(i);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n\n static class MathUtils {\n public static long addMod(long a, long b, long md) {\n if (a >= md) a -= md;\n if (b >= md) b -= md;\n a += b;\n if (a >= md) a -= md;\n return a;\n }\n\n public static long mulMod(long a, long b, long md) {\n return a * b % md;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics"], "code_uid": "aee59ff6b05bd767144bfcb3d5fd3aaa", "src_uid": "b6dc5533fbf285d5ef4cf60ef6300383", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.awt.Point;\nimport static java.lang.Math.*;\n\npublic class CF238A {\n static long M = 1000L*1000*1000+9;\n public static void main(String[] args) throws Exception {\n Scanner in = new Scanner(System.in);\n long n = in.nextInt();\n long m = in.nextInt();\n long p2 = pow(2, m)-1;\n\n long ans = 1;\n for(int i=0; i List list() { return new ArrayList(); }\n public static Map map() { return new HashMap(); }\n public static int i(String s) { return Integer.parseInt(s); }\n public static long l(String s) { return Long.parseLong(s); }\n}\n", "lang_cluster": "Java", "tags": ["math", "constructive algorithms"], "code_uid": "596d984bae490c5a150992ab53490760", "src_uid": "fef4d9c94a93fcf6d536f33503b1d4b8", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\n/**\n *\n * @author fatima\n */\npublic class Main {\n\n public static void main(String[] args) {\n\n Scanner in = new Scanner(System.in);\n\n int a = in.nextInt();\n int b = in.nextInt();\n\n int[] k = new int[a];\n int[] s = new int[a];\n\n for (int i = 0; i < a; i++) {\n k[i] = in.nextInt();\n }\n for (int i = 0; i < a; i++) {\n s[i] = in.nextInt();\n }\n\n \n List w = new LinkedList();\n List q = new LinkedList();\n\n for (int i = 1; i < a; i++) {\n w.add(k[i] - k[i - 1]);\n q.add(s[i] - s[i - 1]);\n }\n\n w.add((b - k[a - 1]) + k[0]);\n q.add((b - s[a - 1]) + s[0]);\n \n\n String res = \"NO\";\n for (int i = 0; i < a; i++) {\n\n if (w.equals(q)) {\n res = \"YES\";\n break;\n }\n w.add(w.get(0));\n w.remove(0);\n \n }\n\n System.out.println(res);\n\n }\n\n}\n", "lang_cluster": "Java", "tags": ["brute force", "math", "implementation"], "code_uid": "9281f49be9047b0eca3bd60af14a721d", "src_uid": "3d931684ca11fe6141c6461e85d91d63", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class TwoProblems {\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n String[] l = br.readLine().split(\"\\\\s+\");\n int[] arr = new int[6];\n boolean flag = false;\n\n for (int i = 0; i < 6; i++)\n arr[i] = Integer.parseInt(l[i]);\n\n if (arr[0] == 0) {\n System.out.println(\"YES\");\n\n } else {\n int t = arr[1];\n int x = arr[0];\n for (int i = 0; i < t; i++)\n for (int j = 0; j < t; j++)\n if (x == ((arr[2] - i * arr[4]) + (arr[3] - j * arr[5]))\n || x == (arr[2] - i * arr[4])\n || x == (arr[3] - j * arr[5]))\n flag = true;\n\n if (flag)\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n }\n\n }\n\n}\n", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "bc2d692d127f0557b806c252baf2c3ba", "src_uid": "f98168cdd72369303b82b5a7ac45c3af", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class E implements Runnable{\n\tpublic static void main (String[] args) {new Thread(null, new E(), \"_cf\", 1 << 28).start();}\n\n\tint MAX = 511, MOD = 998244353, INV = 499122177;\n\n\tpublic void run() {\n\t\tFastScanner fs = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tSystem.err.println(\"Go!\");\n\n\t\tint n = fs.nextInt();\n\t\tint k = fs.nextInt();\n\t\tif(n == 1) {\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tint[][] dp = new int[MAX][MAX];\n\t\tdp[1][1] = 2;\n\t\tfor(int pos = 0; pos < n; pos++) {\n\t\t\tint[][] ndp = new int[MAX][MAX];\n\t\t\t\n\t\t\tfor(int i = 1; i <= Math.min(k, n); i++) {\n\t\t\t\tfor(int j = 1; j <= Math.min(k, n); j++) {\n\t\t\t\t\tint nm = Math.max(i, j+1);\n\t\t\t\t\tndp[nm][j+1] = add(ndp[nm][j+1], dp[i][j]);\n\t\t\t\t\tndp[i][1] = add(ndp[i][1], dp[i][j]);\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(pos != n-1)\n\t\t\t\tdp = ndp;\n\t\t}\n\n\t\tint[] nums = new int[MAX];\n\t\tint[] div2 = new int[MAX];\n\t\tfor(int i = 1; i <= Math.min(n, k); i++) {\n\t\t\tfor(int j = 1; j <= Math.min(n, k); j++) {\n\t\t\t\tnums[i] = add(nums[i], dp[i][j]);\n\t\t\t}\n\t\t}\n\t\tfor(int i = 1; i <= n; i++) div2[i] = mult(nums[i], INV);\n\n\t\tint res = 0;\n\t\tfor(int i = 1; i <= Math.min(n, k); i++) {\n\t\t\tfor(int j = 1; j <= Math.min(n, k); j++) {\n\t\t\t\tif(i * j < k) {\n\t\t\t\t\tres = add(res, mult(2, mult(div2[i], div2[j])));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.println(res);\n\t\tout.close();\n\t}\n\t\n\tint mult(int a, int b) {\n\t\tlong aa = a;\n\t\tif(aa >= MOD) aa -= MOD;\n\t\tif(b >= MOD) b -= MOD;\n\t\taa *= b;\n\t\tif(aa >= MOD) aa %= MOD;\n\t\treturn (int)aa;\n\t}\n\t\n\tint add(int a, int b) {\n\t\tif(a >= MOD) a -= MOD;\n\t\tif(b >= MOD) b -= MOD;\n\t\ta += b;\n\t\tif(a >= MOD) a-= MOD;\n\t\treturn a;\n\t}\n\n\tvoid sort (int[] a) {\n\t\tint n = a.length;\n\t\tfor(int i = 0; i < 50; i++) {\n\t\t\tRandom r = new Random();\n\t\t\tint x = r.nextInt(n), y = r.nextInt(n);\n\t\t\tint temp = a[x];\n\t\t\ta[x] = a[y];\n\t\t\ta[y] = temp;\n\t\t}\n\t\tArrays.sort(a);\n\t}\n\n\tclass FastScanner {\n\t\tpublic int BS = 1<<16;\n\t\tpublic char NC = (char)0;\n\t\tbyte[] buf = new byte[BS];\n\t\tint bId = 0, size = 0;\n\t\tchar c = NC;\n\t\tdouble num = 1;\n\t\tBufferedInputStream in;\n\n\t\tpublic FastScanner() {\n\t\t\tin = new BufferedInputStream(System.in, BS);\n\t\t}\n\n\t\tpublic FastScanner(String s) throws FileNotFoundException {\n\t\t\tin = new BufferedInputStream(new FileInputStream(new File(s)), BS);\n\t\t}\n\n\t\tpublic char nextChar(){\n\t\t\twhile(bId==size) {\n\t\t\t\ttry {\n\t\t\t\t\tsize = in.read(buf);\n\t\t\t\t}catch(Exception e) {\n\t\t\t\t\treturn NC;\n\t\t\t\t} \n\t\t\t\tif(size==-1)return NC;\n\t\t\t\tbId=0;\n\t\t\t}\n\t\t\treturn (char)buf[bId++];\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn (int)nextLong();\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\tnum=1;\n\t\t\tboolean neg = false;\n\t\t\tif(c==NC)c=nextChar();\n\t\t\tfor(;(c<'0' || c>'9'); c = nextChar()) {\n\t\t\t\tif(c=='-')neg=true;\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tfor(; c>='0' && c <='9'; c=nextChar()) {\n\t\t\t\tres = (res<<3)+(res<<1)+c-'0';\n\t\t\t\tnum*=10;\n\t\t\t}\n\t\t\treturn neg?-res:res;\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\tdouble cur = nextLong();\n\t\t\treturn c!='.' ? cur:cur+nextLong()/num;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\twhile(c<=32)c=nextChar();\n\t\t\twhile(c>32) {\n\t\t\t\tres.append(c);\n\t\t\t\tc=nextChar();\n\t\t\t}\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\twhile(c<=32)c=nextChar();\n\t\t\twhile(c!='\\n') {\n\t\t\t\tres.append(c);\n\t\t\t\tc=nextChar();\n\t\t\t}\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic boolean hasNext() {\n\t\t\tif(c>32)return true;\n\t\t\twhile(true) {\n\t\t\t\tc=nextChar();\n\t\t\t\tif(c==NC)return false;\n\t\t\t\telse if(c>32)return true;\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic int[] nextIntArray(int n) {\n\t\t\tint[] res = new int[n];\n\t\t\tfor(int i = 0; i < n; i++) res[i] = nextInt();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t}\n\n}", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics"], "code_uid": "786ac311c01bc6f5835ac375de33ede2", "src_uid": "77177b1a2faf0ba4ca1f4d77632b635b", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class Solution {\n\n private final static FastReader in = new FastReader();\n private static final PrintWriter out = new PrintWriter(System.out);\n\n\n public static long solve(long n) {\n PriorityQueue store = new PriorityQueue<>(Collections.reverseOrder());\n long i;\n store.add(1L);\n for (i = 2; i * i < n; i++) {\n if (n % i == 0) {\n store.add(i);\n store.add(n / i);\n }\n }\n store.add(n);\n if (i * i == n) {\n store.add(i);\n }\n boolean div = false;\n long max = Integer.MIN_VALUE;\n long a;\n while (!store.isEmpty()) {\n a=store.poll();\n for (i = 2; i * i <= a; i++) {\n if (a % (i * i) == 0) {\n div = true;\n break;\n }\n }\n if (!div) {\n return a;\n }\n div = false;\n }\n return max;\n }\n\n\n public static void main(String[] args) {\n long n = in.nextLong();\n out.println(solve(n));\n out.close();\n }\n\n private static final class FastReader {\n private static BufferedReader BF;\n private static StringTokenizer ST;\n\n public FastReader() {\n BF = new BufferedReader(new InputStreamReader(System.in));\n ST = null;\n }\n\n\n public final String next() {\n while (ST == null || !ST.hasMoreTokens()) {\n try {\n ST = new StringTokenizer(BF.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return ST.nextToken();\n\n }\n\n final int nextInt() {\n return Integer.parseInt(next());\n }\n\n final long nextLong() {\n return Long.parseLong(next());\n }\n }\n\n\n}", "lang_cluster": "Java", "tags": ["math"], "code_uid": "2c9d178bc4a643f19562292241e6ff5e", "src_uid": "6d0da975fa0961acfdbe75f2f29aeb92", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class Main {\n public static void main(String args[]){\n Scanner cin = new Scanner(System.in); \n while (cin.hasNext()){\n int i = cin.nextInt();\n if (tbl[i] == -1) while(true);\n System.out.println(tbl[i]);\n }\n } \n public static int []tbl = {-2, 2, 3, 1, 2, 1};\n}\n", "lang_cluster": "Java", "tags": ["brute force"], "code_uid": "c6724bd3f72c0129db73161505914c96", "src_uid": "c702e07fed684b7741d8337aafa005fb", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.math.*;\n\npublic class Main \n{\n public static void main(String[] args) \n {\n Scanner input = new Scanner(System.in);\n \n int n[][] = new int[5][5];\n int x = 0,y = 0;\n \n for(int i = 0; i <5; i++)\n {\n for(int j = 0; j <5; j++)\n {\n n[i][j] = input.nextInt();\n }\n \n }\n for(int i = 0; i <5; i++)\n {\n for(int j = 0; j <5; j++)\n {\n if(n[i][j] == 1)\n {\n x = i+1; y = j+1;\n }\n \n } \n }\n \n int w = Math.abs(x-3)+ Math.abs(y-3);\n System .out.println(w);\n \n }\n \n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "0eac2ce536d03b843cde29fc94a6c20e", "src_uid": "8ba7cedc3f6ae478a0bb3f902440c8e9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.BitSet;\nimport java.util.Calendar;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.SortedSet;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\n/**\n * #\n * @author pttrung\n */\npublic class D_Round_491_Div2 {\n\n public static long MOD = 1000000007;\n static int[][][] dp;\n\n public static void main(String[] args) throws FileNotFoundException {\n // PrintWriter out = new PrintWriter(new FileOutputStream(new File(\n // \"output.txt\")));\n PrintWriter out = new PrintWriter(System.out);\n Scanner in = new Scanner();\n String[] data = new String[2];\n for (int i = 0; i < 2; i++) {\n data[i] = in.next();\n }\n int n = data[0].length();\n if (n < 2) {\n out.println(0);\n } else {\n dp = new int[2][2][n];\n for (int[][] a : dp) {\n for (int[] b : a) {\n Arrays.fill(b, -1);\n }\n }\n out.println(cal(1, get(data[0].charAt(0)), get(data[1].charAt(0)), data));\n }\n\n out.close();\n }\n\n static int cal(int index, int a, int b, String[] data) {\n if (index == data[0].length()) {\n return 0;\n }\n if (dp[a][b][index] != -1) {\n return dp[a][b][index];\n }\n int x = get(data[0].charAt(index));\n int y = get(data[1].charAt(index));\n int result = cal(index + 1, x, y, data);\n if (x == 0 && y == 0) {\n if (a == 0 || b == 0) {\n result = Integer.max(result, 1 + cal(index + 1, 1, 1, data));\n }\n if (a == 0 && b == 0) {\n result = Integer.max(result, 1 + cal(index + 1, 0, 1, data));\n result = Integer.max(result, 1 + cal(index + 1, 1, 0, data));\n }\n } else if (x == 0) {\n if (a == 0 && b == 0) {\n result = Integer.max(result, 1 + cal(index + 1, 1, 1, data));\n }\n } else if (y == 0) {\n if (a == 0 && b == 0) {\n result = Integer.max(result, 1 + cal(index + 1, 1, 1, data));\n }\n }\n return dp[a][b][index] = result;\n }\n\n static int get(char c) {\n if (c == 'X') {\n return 1;\n }\n return 0;\n }\n\n public static int[] KMP(String val) {\n int i = 0;\n int j = -1;\n int[] result = new int[val.length() + 1];\n result[0] = -1;\n while (i < val.length()) {\n while (j >= 0 && val.charAt(j) != val.charAt(i)) {\n j = result[j];\n }\n j++;\n i++;\n result[i] = j;\n }\n return result;\n\n }\n\n public static boolean nextPer(int[] data) {\n int i = data.length - 1;\n while (i > 0 && data[i] < data[i - 1]) {\n i--;\n }\n if (i == 0) {\n return false;\n }\n int j = data.length - 1;\n while (data[j] < data[i - 1]) {\n j--;\n }\n int temp = data[i - 1];\n data[i - 1] = data[j];\n data[j] = temp;\n Arrays.sort(data, i, data.length);\n return true;\n }\n\n public static int digit(long n) {\n int result = 0;\n while (n > 0) {\n n /= 10;\n result++;\n }\n return result;\n }\n\n public static double dist(long a, long b, long x, long y) {\n double val = (b - a) * (b - a) + (x - y) * (x - y);\n val = Math.sqrt(val);\n double other = x * x + a * a;\n other = Math.sqrt(other);\n return val + other;\n\n }\n\n public static class Point implements Comparable {\n\n int x, y;\n\n public Point(int start, int end) {\n this.x = start;\n this.y = end;\n }\n\n @Override\n public int hashCode() {\n int hash = 5;\n hash = 47 * hash + this.x;\n hash = 47 * hash + this.y;\n return hash;\n }\n\n @Override\n public boolean equals(Object obj) {\n if (obj == null) {\n return false;\n }\n if (getClass() != obj.getClass()) {\n return false;\n }\n final Point other = (Point) obj;\n if (this.x != other.x) {\n return false;\n }\n if (this.y != other.y) {\n return false;\n }\n return true;\n }\n\n @Override\n public int compareTo(Point o) {\n return Integer.compare(x, o.x);\n }\n }\n\n public static class FT {\n\n long[] data;\n\n FT(int n) {\n data = new long[n];\n }\n\n public void update(int index, long value) {\n while (index < data.length) {\n data[index] += value;\n index += (index & (-index));\n }\n }\n\n public long get(int index) {\n long result = 0;\n while (index > 0) {\n result += data[index];\n index -= (index & (-index));\n }\n return result;\n\n }\n }\n\n public static long gcd(long a, long b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n public static long pow(long a, long b, long MOD) {\n if (b == 0) {\n return 1;\n }\n if (b == 1) {\n return a;\n }\n long val = pow(a, b / 2, MOD);\n if (b % 2 == 0) {\n return val * val % MOD;\n } else {\n return val * (val * a % MOD) % MOD;\n\n }\n }\n\n static class Scanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n public Scanner() throws FileNotFoundException {\n // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));\n br = new BufferedReader(new InputStreamReader(System.in));\n // br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(\"input.txt\"))));\n }\n\n public String next() {\n\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n return st.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public String nextLine() {\n st = null;\n try {\n return br.readLine();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n\n public boolean endLine() {\n try {\n String next = br.readLine();\n while (next != null && next.trim().isEmpty()) {\n next = br.readLine();\n }\n if (next == null) {\n return true;\n }\n st = new StringTokenizer(next);\n return st.hasMoreTokens();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["greedy", "dp"], "code_uid": "e18e3c7ce11cba2d530ba2d036d4a2db", "src_uid": "e6b3e787919e96fc893a034eae233fc6", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Problem2 {\n\n public static int n;\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n\n Set set = new TreeSet<>();\n\n\n n = scanner.nextInt();\n for(int i = 0; i <= n; ++i) {\n for(int j = i + 1; j <= n; ++j) {\n set.add(new Otr(i, j));\n }\n }\n\n// System.out.println(set.size());\n// System.out.println(set);\n\n Set layers = new HashSet<>();\n\n Iterator iter = set.iterator();\n while (iter.hasNext()) {\n Otr otr = iter.next();\n boolean added = false;\n\n Iterator layerIterator = layers.iterator();\n while (layerIterator.hasNext()) {\n Layer layer = layerIterator.next();\n if (layer.add(otr)) {\n added = true;\n break;\n }\n }\n\n if (!added) {\n Layer newLayer = new Layer();\n newLayer.add(otr);\n layers.add(newLayer);\n }\n }\n\n System.out.println(layers.size());\n //System.out.println(layers);\n\n }\n\n public static class Otr implements Comparable{\n public int left;\n public int right;\n\n public Otr(int l, int r) {\n left = l;\n right = r;\n }\n\n public int len() {\n return right - left;\n }\n\n @Override\n public String toString() {\n return \"[\" + left + \",\" + right + \"]\";\n }\n\n @Override\n public int compareTo(Otr o) {\n int len1 = len();\n int len2 = o.len();\n\n if (len1 != len2) return Integer.compare(len2, len1);\n\n return Integer.compare(left, o.left);\n }\n\n public boolean intersect(Otr other) {\n if (left >= other.right) return false;\n if (other.left >= right) return false;\n\n return true;\n }\n }\n\n public static class Layer {\n List list = new ArrayList<>();\n\n public boolean add(Otr newOtr) {\n boolean added = true;\n\n for(Otr otr : list) {\n if (otr.intersect(newOtr)) {\n added = false;\n break;\n }\n }\n\n if (added) {\n list.add(newOtr);\n }\n\n return added;\n }\n\n @Override\n public String toString() {\n StringBuilder sb = new StringBuilder();\n sb.append(\"{ \");\n for(Otr otr : list) {\n sb.append(otr);\n sb.append(\" , \");\n\n }\n\n sb.append(\"}\\n\");\n return sb.toString();\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "constructive algorithms"], "code_uid": "3f05b418648797484c3f5b3f5af48d2f", "src_uid": "f8af5dfcf841a7f105ac4c144eb51319", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\n\n public class Main {\n static int N, dp[][][], time[], f[], d[], t[], ans[];\n\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n int x1 = input.nextInt();\n int y1 = input.nextInt();\n int r11 = input.nextInt();\n int r12 = input.nextInt();\n int x2 = input.nextInt();\n int y2 = input.nextInt();\n int r21 = input.nextInt();\n int r22 = input.nextInt();\n int cnt = 0;\n int x,y;\n if(circle(x1,y1,x2,y2,r11,r21,r22)) {\n cnt++;\n }\n if(circle(x1,y1,x2,y2,r12,r21,r22))\n cnt++;\n if(circle(x2,y2,x1,y1,r21,r11,r12))\n cnt++;\n if(circle(x2,y2,x1,y1,r22,r11,r12))\n cnt++;\n System.out.println(cnt);\n\n\n\n }\n\n\n static boolean circle(int x1, int y1, int x2,\n int y2, int r1, int r2,int R2)\n {\n double distSq = Math.sqrt((x1 - x2) * (x1 - x2) +\n (y1 - y2) * (y1 - y2));\n if ( distSq+r1 <= r2 || distSq+R2 <= r1 || r1+R2 <= distSq )\n return true;\n else return false;\n }\n\n }\n ", "lang_cluster": "Java", "tags": ["geometry"], "code_uid": "2f24361f81a221cc7f95298467910e4a", "src_uid": "4c2865e4742a29460ca64860740b84f4", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "// Change Of Plans BABY.... Change Of Plans //\nimport java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class rechableNumbers {\n static Set set=new HashSet<>();\n static ArrayList ar=new ArrayList<>();\n static void MainSolution() {\n int x=ni();\n //set.add((long)x);\n dfs(x);\n //pl(set);\n pl(set.size());\n }\n static void dfs(long x){\n if(set.contains(x))return;\n set.add(x);\n x++;\n while(x%10==0)x/=10;\n dfs(x);\n }\n\n /*----------------------------------------------------------------------------------------------------------------*/\n //THE DON'T CARE ZONE BEGINS HERE...\\\\\n static int mod9 = 1000000007;\n static int n, m, l, k, t, mod = 998244353;\n static AwesomeInput input = new AwesomeInput(System.in);\n static PrintWriter pw = new PrintWriter(System.out, true);\n\n static class AwesomeInput {\n private InputStream letsDoIT;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private SpaceCharFilter filter;\n\n private AwesomeInput(InputStream incoming) {\n this.letsDoIT = incoming;\n }\n\n public int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = letsDoIT.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n private long ForLong() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n }\n while (!isSpaceChar(c));\n return res * sgn;\n }\n\n private String ForString() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n }\n while (!isSpaceChar(c));\n\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n boolean isSpaceChar(int ch);\n }\n }\n\n // functions to take input//\n static int ni() {\n return (int) input.ForLong();\n }\n\n static String ns() {\n return input.ForString();\n }\n\n static long nl() {\n return input.ForLong();\n }\n\n static double nd() throws IOException {\n return Double.parseDouble(new BufferedReader(new InputStreamReader(System.in)).readLine());\n }\n\n //functions to give output\n static void pl() {\n pw.println();\n }\n\n static void p(Object o) {\n pw.print(o + \" \");\n }\n\n static void pws(Object o) {\n pw.print(o + \"\");\n }\n\n static void pl(Object o) {\n pw.println(o);\n }\n\n public static void main(String[] args) { //threading has been used to increase the stack size.\n\n new Thread(null, null, \"Vengeance\", 1 << 25) //the last parameter is stack size desired.\n {\n public void run() {\n try {\n double s = System.currentTimeMillis();\n MainSolution();\n //pl((\"\\nExecution Time : \" + ((double) System.currentTimeMillis() - s) / 1000) + \" s\");\n pw.flush();\n pw.close();\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(1);\n }\n }\n }.start();\n }\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "0e6eebd60c057c9c5af26dfc0c68002c", "src_uid": "055fbbde4b9ffd4473e6e716da6da899", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.Scanner;\npublic class A {\n private void solve() {\n int[] n = {sc.nextInt(),sc.nextInt(),sc.nextInt()};\n int ret = 0;\n while(!isZero(n)) {\n for(int i=0;i<3;i++) {\n n[i]-=2;\n if(isZero(n)) break;\n ret++;\n }\n }\n System.out.println(ret+30);\n }\n \n private boolean isZero(int[] n) {\n return n[0]<=0&&n[1]<=0&&n[2]<=0;\n }\n \n private Scanner sc=new Scanner(System.in);\n public static void main(String[]args){new A().solve();}\n}", "lang_cluster": "Java", "tags": ["math", "greedy"], "code_uid": "c2ae9fa58f12d9ecd6161f5c1459b555", "src_uid": "a45daac108076102da54e07e1e2a37d7", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.BitSet;\nimport java.util.Calendar;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.SortedSet;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\n/**\n *\n *\n * 3 2 3 5\n * -2 -1 4 -1 2 7 3\n *\n * 10 1 -10617 30886 -7223 -63085 47793 -61665 -14614 60492 16649 -58579 3 8 1\n * 10 4 7 1 7 3 7\n *\n * 22862 -34877\n *\n * @author pttrung\n */\npublic class D {\n\n public static long MOD = 1000000007;\n static int x = 0, y = 0;\n static boolean start;\n public static long[][] dp, c;\n public static int[] X = {0, 1, 0, -1};\n public static int[] Y = {1, 0, -1, 0};\n\n public static void main(String[] args) throws FileNotFoundException {\n PrintWriter out;\n Scanner in = new Scanner();\n // out = new PrintWriter(new FileOutputStream(new File(\"output.txt\")));\n out = new PrintWriter(System.out);\n int result = 0;\n String line = in.next();\n int last = 1;\n for (int i = 1; i < line.length(); i++) {\n if (line.charAt(i) == line.charAt(i - 1)) {\n last++;\n } else {\n if (last % 2 == 0) {\n result++;\n }\n last = 1;\n }\n }\n if (last % 2 == 0) {\n result++;\n }\n out.println(result);\n out.close();\n }\n\n public static int[] KMP(String val) {\n int i = 0;\n int j = -1;\n int[] result = new int[val.length() + 1];\n result[0] = -1;\n while (i < val.length()) {\n while (j >= 0 && val.charAt(j) != val.charAt(i)) {\n j = result[j];\n }\n j++;\n i++;\n result[i] = j;\n }\n return result;\n\n }\n\n public static boolean nextPer(int[] data) {\n int i = data.length - 1;\n while (i > 0 && data[i] < data[i - 1]) {\n i--;\n }\n if (i == 0) {\n return false;\n }\n int j = data.length - 1;\n while (data[j] < data[i - 1]) {\n j--;\n }\n int temp = data[i - 1];\n data[i - 1] = data[j];\n data[j] = temp;\n Arrays.sort(data, i, data.length);\n return true;\n }\n\n public static int digit(long n) {\n int result = 0;\n while (n > 0) {\n n /= 10;\n result++;\n }\n return result;\n }\n\n public static double dist(long a, long b, long x, long y) {\n double val = (b - a) * (b - a) + (x - y) * (x - y);\n val = Math.sqrt(val);\n double other = x * x + a * a;\n other = Math.sqrt(other);\n return val + other;\n\n }\n\n public static class Point implements Comparable {\n\n int x, y;\n\n public Point(int start, int end) {\n this.x = start;\n this.y = end;\n }\n\n @Override\n public int hashCode() {\n int hash = 5;\n hash = 47 * hash + this.x;\n hash = 47 * hash + this.y;\n return hash;\n }\n\n @Override\n public boolean equals(Object obj) {\n if (obj == null) {\n return false;\n }\n if (getClass() != obj.getClass()) {\n return false;\n }\n final Point other = (Point) obj;\n if (this.x != other.x) {\n return false;\n }\n if (this.y != other.y) {\n return false;\n }\n return true;\n }\n\n @Override\n public int compareTo(Point o) {\n return x - o.x;\n }\n }\n\n public static class FT {\n\n long[] data;\n\n FT(int n) {\n data = new long[n];\n }\n\n public void update(int index, long value) {\n while (index < data.length) {\n data[index] += value;\n index += (index & (-index));\n }\n }\n\n public long get(int index) {\n long result = 0;\n while (index > 0) {\n result += data[index];\n index -= (index & (-index));\n }\n return result;\n\n }\n }\n\n public static long gcd(long a, long b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n public static long pow(long a, long b) {\n if (b == 0) {\n return 1;\n }\n if (b == 1) {\n return a;\n }\n long val = pow(a, b / 2);\n if (b % 2 == 0) {\n return val * val % MOD;\n } else {\n return val * (val * a % MOD) % MOD;\n\n\n\n\n\n\n\n\n }\n }\n\n static class Scanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n public Scanner() throws FileNotFoundException {\n // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));\n br = new BufferedReader(new InputStreamReader(System.in));\n // br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(\"input.txt\"))));\n }\n\n public String next() {\n\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n return st.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public String nextLine() {\n st = null;\n try {\n return br.readLine();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n\n public boolean endLine() {\n try {\n String next = br.readLine();\n while (next != null && next.trim().isEmpty()) {\n next = br.readLine();\n }\n if (next == null) {\n return true;\n }\n st = new StringTokenizer(next);\n return st.hasMoreTokens();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["two pointers", "implementation"], "code_uid": "4d0717c4fee71f84c55f0ff6dfe2ef91", "src_uid": "8b26ca1ca2b28166c3d25dceb1f3d49f", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\nimport java.util.Collections;\nimport java.util.ArrayList;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author AEoui\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n Scanner in = new Scanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskB solver = new TaskB();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskB {\n ArrayList primes;\n ArrayList facors;\n int[] pf;\n\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n init();\n int X2 = in.nextInt();\n\n facors(X2);\n\n int low = 3;\n int hi = X2 - 1;\n int mid = 0;\n int ans = -1;\n while (low <= hi) {\n mid = (low + hi) / 2;\n if (check(mid, X2)) {\n ans = mid;\n hi = mid - 1;\n } else {\n low = mid + 1;\n }\n }\n\n out.println(ans);\n }\n\n private void facors(int x2) {\n facors = new ArrayList<>();\n int cur = pf[x2];\n while (cur > 1) {\n facors.add(pf[cur]);\n int ppf = pf[cur];\n while (cur % ppf == 0)\n cur /= ppf;\n }\n\n if (cur > 1)\n facors.add(cur);\n\n Collections.sort(facors);\n }\n\n private boolean check(int x0, int x2) {\n for (Integer p : primes) {\n if (p >= x0) break;\n\n int x1 = (x0 / p) * p;\n x1 += x1 < x0 ? p : 0;\n\n for (int p1 : facors) {\n if (p1 >= x1) break;\n if (x2 % p1 != 0) continue;\n int xx2 = (x1 / p1) * p1;\n xx2 += xx2 < x1 ? p1 : 0;\n\n if (xx2 == x2)\n return true;\n }\n }\n\n return false;\n }\n\n private void init() {\n pf = new int[(int) 1e6 + 1];\n primes = new ArrayList<>();\n\n for (int i = 2; i < pf.length; ++i) {\n if (pf[i] != 0) continue;\n primes.add(i);\n pf[i] = i;\n for (int j = i + i; j < pf.length; j += i) {\n pf[j] = i;\n }\n }\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["brute force", "math", "number theory"], "code_uid": "a3299f569e92a4eb321238f9609d792f", "src_uid": "43ff6a223c68551eff793ba170110438", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\n\npublic class Digits_Sequence_Easy_Edition_117A {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\t\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tint x = Integer.parseInt(br.readLine());\n\t\tSystem.out.println(calculate(x));\n\t\t\n\t}\n\t\n\tpublic static int calculate(int x) {\n\t\tif ((0 <= x) && (x <= 9)) {\n\t\t\treturn x;\n\t\t}\n\t\t\n\t\tx--;\n\t\tint n = 1;\n\t\twhile ((x - (9*n*(int)Math.pow(10, n-1))) >= 0) {\n\t\t\tx = x - (9*n*(int)Math.pow(10, n-1));\n\t\t\tn++;\n\t\t}\n\t\n\t\tint mod = x % n;\n\t\n\t\tif (mod == 0 % n) {\n\t\t\treturn (x/(n*(int)Math.pow(10, n-1)))+1;\n\t\t}\n\t\t\n\t\treturn (x%(n*(int)Math.pow(10, n-mod)))/(n*(int)Math.pow(10, n-mod-1));\n\t}\n\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "70347638272935ecc2401a13a26c8b91", "src_uid": "1503d761dd4e129fb7c423da390544ff", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class ZonesNew {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint h = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tint r[][]= new int[m][3];\n\t\tint a[] = new int[n];\n\t\tArrays.fill(a,h);\n\t\tfor(int i=0;ir[i][2])\n\t\t\t\ta[j-1]=r[i][2];\n\t\t\t}\n\t\t}\n\t\tint sum = 0;\n\t\tfor(int i=0;i= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public double readDouble() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n double res = 0;\n while (!isSpaceChar(c) && c != '.') {\n if (c == 'e' || c == 'E') {\n return res * Math.pow(10, readInt());\n }\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n }\n if (c == '.') {\n c = read();\n double m = 1;\n while (!isSpaceChar(c)) {\n if (c == 'e' || c == 'E') {\n return res * Math.pow(10, readInt());\n }\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n m /= 10;\n res += (c - '0') * m;\n c = read();\n }\n }\n return res * sgn;\n }\n\n public long readLong() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public String readString() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public boolean isEndOfLine(int c) {\n if (filter != null) {\n return filter.isEndOfLine(c);\n }\n return c == '\\n' || c == '\\r' || c == -1;\n }\n\n public String next() {\n return readString();\n }\n\n public void close() throws IOException {\n this.stream.close();\n }\n\n public interface SpaceCharFilter {\n boolean isSpaceChar(int ch);\n\n boolean isEndOfLine(int ch);\n }\n\n }\n\n static class IOUtils {\n\n public static int[] readIntArray(InputReader in, int elementCount) {\n return readIntArray(in, elementCount, 0);\n }\n\n public static int[] readIntArray(InputReader in, int elementCount, int startOffset) {\n int[] array = new int[elementCount + startOffset];\n for (int i = 0; i < elementCount; i++)\n array[i + startOffset] = in.readInt();\n return array;\n }\n\n public static long[] readLongArray(InputReader in, int elementCount) {\n return readLongArray(in, elementCount, 0);\n }\n\n public static long[] readLongArray(InputReader in, int elementCount, int startOffset) {\n long[] array = new long[elementCount + startOffset];\n for (int i = 0; i < elementCount; i++)\n array[i + startOffset] = in.readLong();\n return array;\n }\n\n }\n\n static class OutputWriter {\n\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void print(Object... objects) {\n for (int i = 0; i < objects.length; i++) {\n if (i != 0)\n writer.print(' ');\n writer.print(objects[i]);\n }\n }\n\n public void printLine(Object... objects) {\n print(objects);\n writer.println();\n }\n\n public void close() {\n writer.close();\n }\n\n public void flush() {\n writer.flush();\n }\n\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "dp", "bitmasks", "graphs", "implementation"], "code_uid": "5e64f8683dec9cfa6f6e6619a6895030", "src_uid": "a98f0d924ea52cafe0048f213f075891", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class a {\npublic static void main(String[] args){\nScanner in = new Scanner(System.in);\nin.next();\nString str = in.next();\nif(str.contains(\"CC\")||str.contains(\"YY\")||str.contains(\"MM\")){\nSystem.out.println(\"No\");\nreturn;\n}\n\nif(str.startsWith(\"?\")||str.endsWith(\"?\")||str.contains(\"??\")||str.contains(\"C?C\")||str.contains(\"Y?Y\")||str.contains(\"M?M\"))\nSystem.out.println(\"Yes\");\nelse\nSystem.out.println(\"No\");\n\n}\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "9453132b10bd3de6df5d0e7dca4aff9a", "src_uid": "f8adfa0dde7ac1363f269dbdf00212c3", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\npublic\nclass TaskA{\n //static variable\n static final int mod = (int) 1e9 + 7;\n static final double eps = 1e-6;\n static final double pi = Math.PI;\n static final long inf = Long.MAX_VALUE / 2;\n\n\n\n BufferedReader br;\n void main1() throws IOException {\n br=new BufferedReader(new InputStreamReader(System.in));\n int t=ii();\n int[] aa=new int[t];\n for (int i = 0; i d2){\n\t\t\t\tSystem.out.println(aux/10);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif(d1 long\r\n ArrayList arr=new ArrayList<>(); // Integer -> Long\r\n for(int i=0;i0){\r\n res++;\r\n n/=2;\r\n }\r\n return res;\r\n }\r\n\r\n static int mod = (int)1e9+7;\r\n static PrintWriter out;\r\n static FastReader sc ;\r\n public static void main(String[] args) throws IOException {\r\n sc = new FastReader();\r\n out = new PrintWriter(System.out);\r\n // primes();\r\n // ================================ //\r\n long n= sc.nextLong();\r\n long m= sc.nextLong();\r\n solver(n, m);\r\n // ================================ //\r\n out.flush();\r\n }\r\n\r\n public static void solver(long n, long m) {\r\n if(m==n){\r\n out.println(\"YES\");\r\n return;\r\n }\r\n // if(m%2==0){\r\n // out.println(\"NO\");\r\n // return;\r\n // }\r\n String s = Long.toBinaryString(n);\r\n\r\n int t = log(m)-log(n);\r\n String ss = rev(s);\r\n if(m==Long.parseLong(ss, 2)){\r\n out.println(\"YES\");\r\n return;\r\n }\r\n for(int k = 1;k<=t;k++){\r\n // normal\r\n for(int i=0;i 7) {\n out.println(0);\n return;\n }\n Debug debug = new Debug(out);\n int answer = 0;\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n String s = Integer.toString(i, 7) + Integer.toString(j, 7);\n while (s.length() < digCount) {\n s += \"0\";\n }\n int[] ct = new int[8];\n for (int k = 0; k < s.length(); ++k) {\n ++ct[s.charAt(k) - '0'];\n }\n boolean flag = true;\n for (int k = 0; k < ct.length; ++k) {\n flag &= ct[k] <= 1;\n }\n if (flag) {\n debug.tr(s);\n ++answer;\n }\n }\n }\n out.println(answer);\n }\n\n private int digCount(int val) {\n if (val < 7) return 1;\n return 1 + digCount(val / 7);\n }\n\n }\n\n static class FastReader {\n private InputStream stream;\n private byte[] buf = new byte[8192];\n private int curChar;\n private int pnumChars;\n private FastReader.SpaceCharFilter filter;\n\n public FastReader(InputStream stream) {\n this.stream = stream;\n }\n\n private int pread() {\n if (pnumChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= pnumChars) {\n curChar = 0;\n try {\n pnumChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (pnumChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = pread();\n while (isSpaceChar(c))\n c = pread();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = pread();\n }\n int res = 0;\n do {\n if (c == ',') {\n c = pread();\n }\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = pread();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n private boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n private static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n private interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n\n static class Debug {\n PrintWriter out;\n boolean oj;\n\n public Debug(PrintWriter out) {\n oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n this.out = out;\n }\n\n public void tr(Object... objects) {\n if (objects.length > 0 && !oj) {\n out.println(Arrays.deepToString(objects));\n }\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["brute force", "math", "dp", "combinatorics"], "code_uid": "6bcfce782af5b9225ade8f5e83023772", "src_uid": "0930c75f57dd88a858ba7bb0f11f1b1c", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class CodeForces_474A{\n public static void main(String[]args){\n Scanner sc=new Scanner(System.in);\n String arr=\"qwertyuiop\";\n String brr=\"asdfghjkl;\";\n String crr=\"zxcvbnm,./\";\n String a=sc.next();\n String b=sc.next();\n String[]x=b.split(\"\");\n if(a.equals(\"R\")){\n for(int i=0;i= 10) out.println(0);\n\t\telse {\n\t\t\tlong res = 1;\n\t\t\tfor(long i = a+1; i <= b; i++) res = res*i%10;\n\t\t\tout.println(res);\n\t\t}\n\t\tout.close();\n\t}\n\n\tstatic class FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner() {\n\t\t\ttry\t{\n\t\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e){e.printStackTrace();}\n\t\t}\n\n\t\tpublic String next() {\n\t\t\tif (st.hasMoreTokens())\treturn st.nextToken();\n\t\t\ttry {st = new StringTokenizer(br.readLine());}\n\t\t\tcatch (Exception e) {e.printStackTrace();}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() {return Integer.parseInt(next());}\n\n\t\tpublic long nextLong() {return Long.parseLong(next());}\n\n\t\tpublic double nextDouble() {return Double.parseDouble(next());}\n\n\t\tpublic String nextLine() {\n\t\t\tString line = \"\";\n\t\t\tif(st.hasMoreTokens()) line = st.nextToken();\n\t\t\telse try {return br.readLine();}catch(IOException e){e.printStackTrace();}\n\t\t\twhile(st.hasMoreTokens()) line += \" \"+st.nextToken();\n\t\t\treturn line;\n\t\t}\n\n\t\tpublic int[] nextIntArray(int n) {\n\t\t\tint[] a = new int[n];\n\t\t\tfor(int i = 0; i < n; i++) a[i] = nextInt();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic long[] nextLongArray(int n){\n\t\t\tlong[] a = new long[n];\n\t\t\tfor(int i = 0; i < n; i++) a[i] = nextLong();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic double[] nextDoubleArray(int n){\n\t\t\tdouble[] a = new double[n];\n\t\t\tfor(int i = 0; i < n; i++) a[i] = nextDouble();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic char[][] nextGrid(int n, int m){\n\t\t\tchar[][] grid = new char[n][m];\n\t\t\tfor(int i = 0; i < n; i++) grid[i] = next().toCharArray();\n\t\t\treturn grid;\n\t\t}\n\t}\n\n}", "lang_cluster": "Java", "tags": ["math"], "code_uid": "2c6b4fcd8c49350df33dede45d72914f", "src_uid": "2ed5a7a6176ed9b0bda1de21aad13d60", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner sc = new Scanner(System.in);\n\t\twhile (sc.hasNext()) {\n\t\t\tint n=sc.nextInt();\n\t\t\tint l=sc.nextInt();\n\t\t\tint r=sc.nextInt();\n\t\t\tint sumshu=2;\n\t\t\tint shu=2;\n\t\t\tif(l==1){\n\t\t\tSystem.out.print(n+\" \");\n\t\t\t}else {\n\t\t\tfor (int i = 1; i < l-1; i++) {\n\t\t\t\tshu*=2;\n\t\t\t\tsumshu+=shu;\n\t\t\t}\n\t\t\t\t\tint min=((n-l)+1)+sumshu;\n\t\t\t\t\tSystem.out.print(min+\" \");\n\t\t\t}\n\t\t\t\t\tsumshu=1;\n\t\t\t\t\tshu=1;\n\t\t\t\t\tfor (int i = 1; i < r; i++) {\n\t\t\t\t\t\tshu*=2;\n\t\t\t\t\t\tsumshu+=shu;\n\t\t\t\t\t}\n\t\t\t\t\tSystem.out.println(sumshu+(n-r)*shu);\n\t\t}\n\t}\n\n}", "lang_cluster": "Java", "tags": ["math", "greedy"], "code_uid": "afa8fef09216090a91f4bb4066cfc577", "src_uid": "ce220726392fb0cacf0ec44a7490084a", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.math.BigInteger;\nimport java.util.*;\npublic class Main {\n static final int MOD = 1000000007;\n public static int count(int h , int w) {\n int totaldp = 0;\n boolean[][]\n myf = new boolean[h][w];\n int[][][][] dp = new int[2][2][w][w];\n for (int row = 0; row < h; ++row) {\n int[][][][] newdp = new int[2][2][w][w];\n for (int fd = 0; fd < 2; ++fd)\n for (int ld = 0; ld < 2; ++ld)\n for (int fc = 0; fc < w; ++fc)\n for (int lc = fc; lc < w; ++lc) {\n int cur = dp[fd][ld][fc][lc];\n if (cur == 0) continue;\n for (int newfd = fd; newfd < 2; ++newfd)\n for (int newld = ld; newld < 2; ++newld) {\n int newfc; if (newfd == 0) newfc = fc;\n else if (fd == 0) newfc = fc + 1;\n else newfc = fc;\n int newlc;\n if (newld == 0) newlc = lc;\n else if (ld == 0) newlc = lc - 1;\n else newlc = lc;\n if (newfc > newlc) continue;\n int[] arr = newdp[newfd][newld][newfc];\n arr[newlc] += cur;\n if (arr[newlc] >= MOD) arr[newlc] -= MOD;\n }\n }\n for (int fd = 0; fd < 2; ++fd)\n for (int ld = 0; ld < 2; ++ld) {\n int[][] arr = newdp[fd][ld];\n if (fd == 0 && ld == 1) {\n int lastDelta = ld == 0 ? 1 : -1;\n int lastMin = lastDelta == 1 ? 0 : w - 1;\n int lastMax = lastDelta == 1 ? w : -1;\n for (int lc = lastMin; lc != lastMax; lc += lastDelta) {\n for (int fc = 0; fc <= lc; ++fc) {\n int cur = arr[fc][lc];\n if (cur == 0) continue;\n int newlc = lc + lastDelta;\n if (newlc >= fc && newlc < w) {\n arr[fc][newlc] += cur;\n if (arr[fc][newlc] >= MOD) arr[fc][newlc] -= MOD;\n }\n }\n }\n int firstDelta = fd == 0 ? -1 : 1;\n int firstMin = firstDelta == 1 ? 0 : w - 1;\n int firstMax = firstDelta == 1 ? w : -1;\n for (int fc = firstMin; fc != firstMax; fc += firstDelta) {\n for (int lc = fc; lc < w; ++lc) {\n int cur = arr[fc][lc];\n if (cur == 0) continue;\n int newfc = fc + firstDelta;\n if (newfc >= 0 && newfc <= lc) {\n arr[newfc][lc] += cur;\n if (arr[newfc][lc] >= MOD) arr[newfc][lc] -= MOD;\n }\n }\n }\n } else {\n int firstDelta = fd == 0 ? -1 : 1;\n int firstMin = firstDelta == 1 ? 0 : w - 1;\n int firstMax = firstDelta == 1 ? w : -1;\n for (int fc = firstMin; fc != firstMax; fc += firstDelta) {\n for (int lc = fc; lc < w; ++lc) {\n int cur = arr[fc][lc];\n if (cur == 0) continue;\n int newfc = fc + firstDelta;\n if (newfc >= 0 && newfc <= lc) {\n arr[newfc][lc] += cur;\n if (arr[newfc][lc] >= MOD) arr[newfc][lc] -= MOD;\n }\n }\n }\n int lastDelta = ld == 0 ? 1 : -1;\n int lastMin = lastDelta == 1 ? 0 : w - 1;\n int lastMax = lastDelta == 1 ? w : -1;\n for (int lc = lastMin; lc != lastMax; lc += lastDelta) {\n for (int fc = 0; fc <= lc; ++fc) {\n int cur = arr[fc][lc];\n if (cur == 0) continue;\n int newlc = lc + lastDelta;\n if (newlc >= fc && newlc < w) {\n arr[fc][newlc] += cur;\n if (arr[fc][newlc] >= MOD) arr[fc][newlc] -= MOD;\n }\n }\n }\n }\n }\n for (int fc = 0; fc < w; ++fc) {\n boolean ok = true;\n for (int lc = fc; lc < w; ++lc) {\n if (myf[row][lc])\n ok = false;\n if (!ok) {\n for (int fd = 0; fd < 2; ++fd)\n for (int ld = 0; ld < 2; ++ld)\n newdp[fd][ld][fc][lc] = 0;\n } else {\n newdp[0][0][fc][lc] += 1;\n if (newdp[0][0][fc][lc] >= MOD) newdp[0][0][fc][lc] -= MOD;\n }\n }\n }\n dp = newdp;\n for (int fd = 0; fd < 2; ++fd)\n for (int ld = 0; ld < 2; ++ld)\n for (int fc = 0; fc < w; ++fc)\n for (int lc = fc; lc < w; ++lc) {\n totaldp += dp[fd][ld][fc][lc];\n if (totaldp >= MOD) totaldp -= MOD;\n }\n }\n return totaldp;\n }\n public static void main(String[] args){\n Scanner cin = new Scanner(System.in);\n int n = cin.nextInt(), m = cin.nextInt();\n System.out.println(count(n, m));\n }\n}\n", "lang_cluster": "Java", "tags": ["dp"], "code_uid": "b217547dc763313a25bf5f63e502d057", "src_uid": "740eceed59d3c6ac55c1bf9d3d4160c7", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "\n\nimport java.util.Scanner;\n\npublic class ProblemA {\n\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tint luke = scan.nextInt();\n\t\tint wall1 = scan.nextInt();\n\t\tint v1 = scan.nextInt();\n\t\tint v2 = scan.nextInt();\n\t\tdouble time = (double)(wall1-luke)/(v1+v2);\n\t\tSystem.out.println(time);\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "adf1f4559a4ca13834d784ae9375cecd", "src_uid": "f34f3f974a21144b9f6e8615c41830f5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\n\n\n\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedHashMap;\nimport java.util.LinkedHashSet;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Scanner;\nimport java.util.Set;\nimport java.util.TreeMap;\n\n\n\n\npublic class Main {\n\t\n\tstatic class TreeNode{\n\t\tint val;\n\t\tTreeNode left;\n\t\tTreeNode right;\n\t\tpublic TreeNode(int val) {\n\t\t\tthis.val=val;\n\t\t}\n\t}\n\t\n\tstatic int gcd(int m,int n) {\n\t\tint c;\n\t\twhile(n>0) {\n\t\t\tc=m%n;\n\t\t\tm=n;\n\t\t\tn=c;\n\t\t}\n\t\treturn m;\n\t}\n\t\n\t\n public static void main(String[] args) {\n \tScanner sc=new Scanner(System.in);\n \tint a=sc.nextInt();\n \tint b=sc.nextInt();\n \tint cnt=0;\n \tif(a>b) {\n \t\tSystem.out.println(-1);\n \t\treturn;\n \t}\n \tif(a==b) {\n \t\tSystem.out.println(0);\n \t\treturn;\n \t}\n \tif(b%a!=0) {\n \t\tSystem.out.println(-1);\n \t\treturn;\n \t}\n \tint q=b/a;\n \twhile(q!=1) {\n \t\tif(q%3==0)q/=3;\n \t\telse if(q%2==0) q/=2;\n \t\telse break;\n \t\tcnt++;\n \t}\n \tif(q!=1||cnt==0)\n \t\tSystem.out.println(-1);\n \telse\n \t\tSystem.out.println(cnt);\n }\n}", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "60f9b4ac6a0af75feb2b53e1e61f262c", "src_uid": "3f9980ad292185f63a80bce10705e806", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.lang.Math;\nimport java.math.BigInteger;\n\npublic class Problem {\n\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tnew Problem().run();\n\t}\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer tok;\n\tRandom rnd = new Random();\n\tstatic final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tProblem() throws FileNotFoundException{\n\n\t\tif (ONLINE_JUDGE) {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in)); \n out = new PrintWriter(System.out); \n\t\t} else {\n\t\t\tin = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\tout = new PrintWriter(\"output.txt\");\n\t\t}\n\t\ttok = new StringTokenizer(\"\");\n\t}\n\n\t// ======================================================\n\t\n\tclass Dsu{\n\t\tint[] parents;\n\t\tint countUnions;\n\t\tDsu(int size){\n\t\t\tthis.parents = new int[size];\n\t\t\tthis.countUnions = size;\n\t\t\tfor(int i=0;i1){\n\t\t\tint mid = (r+l)/2;\n\t\t\tif(mid*mid>m){\n\t\t\t\tr = mid;\n\t\t\t}else{\n\t\t\t\tl = mid;\n\t\t\t}\n\t\t}\n\t\treturn l;\n\t}\n\tint countPow(int m,int n){\n\t\tint ans = 0;\n\t\twhile(m%n==0&&m>0){\n\t\t\tans++;\n\t\t\tm/=n;\n\t\t}\n\t\treturn ans;\n\t}\n\tlong binPow(long a, long b){\n\t\tif(b == 0){\n\t\t\treturn 1;\n\t\t}\n\t\tif(b%2==1){\n\t\t\treturn a*binPow(a,b-1);\n\t\t}else{\n\t\t\tlong c = binPow(a,b/2);\n\t\t\treturn c*c;\n\t\t}\n\t\t\n\t}\n\tlong gcd(long a, long b){\n\t\treturn b==0?a:gcd(b,a%b);\n\t}\n\t\n\tlong pow(long x, long k){\n\t\tlong ans=1;\n\t\tfor(int i=0;i b) {\n oneWin = true;\n break;\n }\n }\n\n if (oneWin) {\n String temp = String.valueOf(ans);\n int digits = temp.length();\n for (int i = 0;i < 9 - digits; i++) {\n answer += \"0\";\n }\n answer += String.valueOf(ans);\n System.out.println(\"1 \" + answer);\n } else {\n System.out.println(2);\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "number theory"], "code_uid": "76c146846eb3993ae95ed256a14e1f4b", "src_uid": "8b6f633802293202531264446d33fee5", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskD solver = new TaskD();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskD {\n private final int MOD = (int) 1e9 + 7;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt(), m = in.nextInt();\n\n long ans = 0;\n for (int i = 0; i <= n; ++i) {\n for (int j = 0; j <= m; ++j) {\n int eveni = n % 2 == 1 ? (n + 1) / 2 : n / 2 + (i + 1) % 2;\n int evenj = m % 2 == 1 ? (m + 1) / 2 : m / 2 + (j + 1) % 2;\n\n int oddi = n - eveni + 1;\n int oddj = m - evenj + 1;\n\n int odd = oddi * oddj;\n int all = (n + 1) * (m + 1);\n int even = all - odd;\n\n ans += (long) even * even % MOD;\n ans += (long) odd * odd % MOD;\n ans %= MOD;\n }\n }\n\n int[] dp;\n dp = new int[n + 1];\n for (int i = 1; i <= n; ++i) {\n dp[i] = dp[i - 1] + i;\n ans = (ans - 6L * (m + 1) * dp[i]) % MOD;\n }\n dp = new int[m + 1];\n for (int i = 1; i <= m; ++i) {\n dp[i] = dp[i - 1] + i;\n ans = (ans - 6L * (n + 1) * dp[i]) % MOD;\n }\n\n dp = new int[m + 1];\n int[] ndp = new int[m + 1];\n\n int[][] gcd = new int[n + 1][m + 1];\n\n for (int i = 1; i <= n; ++i) {\n //ndp[0] = dp[0] + i;\n //ans = (ans - 6L * ndp[0]) % MOD;\n for (int j = 1; j <= m; ++j) {\n if (gcd[i][j] == 0) {\n gcd[i][j] = 1;\n for (int p = 2; i * p <= n && p * j <= m; ++p)\n gcd[i * p][j * p] = p;\n }\n ndp[j] = (dp[j] + ndp[j - 1]) % MOD;\n ndp[j] = (ndp[j] - dp[j - 1]) % MOD;\n ndp[j] = (ndp[j] + gcd[i][j]) % MOD;\n ans = (ans - 12L * ndp[j]) % MOD;\n\n //int sub = (i + 1) * (j + 1) - 1;\n //ans = (ans - 6L * sub) % MOD;\n }\n int[] aux = dp;\n dp = ndp;\n ndp = aux;\n }\n\n ans -= (n + 1) * (m + 1);\n ans %= MOD;\n if (ans < 0) ans += MOD;\n\n out.println(ans);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1)\n throw new UnknownError();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new UnknownError();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public String next() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuffer res = new StringBuffer();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n\n return res.toString();\n }\n\n private boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["math", "geometry"], "code_uid": "3cc47da60582eed191811e30a06c3c8e", "src_uid": "984788e4b4925c15c9c6f31e42f2f8fa", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n public class Main{\n public static void main(String args[]){\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n int a=sc.nextInt();\n int b=sc.nextInt();\n int c=sc.nextInt();\n int count=1;\n \n int temp=0;\n int tempp=0;\n int ans=0;\n temp=Math.min(a,b);\n ans+=temp;\n count=2;\n while(count != n&&n!=1)\n {\n if(temp==a){tempp=a;\n temp=Math.min(a,c);\n count++;\n ans+=temp;\n } \n else{\n if(temp==b)\n {tempp=b;\n temp=Math.min(b,c);\n count++;ans+=temp;\n }\n else\n {\n if(tempp==b){\n temp=Math.min(c,b);count++;ans+=temp;}\n else\n {\n temp=Math.min(c,a);\n // System.out.println(ans);\n count++;\n ans+=temp;\n }\n }\n \n }\n }\n if(n==1) System.out.println(0);\n else System.out.println(ans);\n}}", "lang_cluster": "Java", "tags": ["math"], "code_uid": "d059248d21b791a31385362087a00b65", "src_uid": "6058529f0144c853e9e17ed7c661fc50", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "//package que_a;\n\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class utkarsh {\n\n InputStream is;\n PrintWriter out;\n \n long mod = (long) (1e9 + 7), inf = (long) (3e18);\n \n class pair {\n int W, C, N;\n pair(int w, int c, int n) {\n W = w; C = c; N = n;\n }\n }\n \n void solve() {\n int W = ni(), n = ni();\n pair p[] = new pair[n+1];\n p[0] = new pair(ni(), ni(), 10101);\n for(int i = 1; i <= n; i++) {\n int N = ni() / ni();\n p[i] = new pair(ni(), ni(), N);\n }\n int dp[][] = new int[n+1][W+1];\n for(int i = p[0].W; i <= W; i++) {\n dp[0][i] = (i / p[0].W) * p[0].C;\n }\n for(int i = 1; i <= n; i++) {\n for(int j = 0; j <= W; j++) dp[i][j] = dp[i-1][j];\n int w = 0, c = 0;\n for(int k = 1; k <= p[i].N; k++) {\n w += p[i].W; c += p[i].C;\n for(int j = w; j <= W; j++) {\n dp[i][j] = Math.max(dp[i][j], dp[i-1][j - w] + c);\n }\n }\n }\n out.println(dp[n][W]);\n }\n \n long mp(long b, long e) {\n long r = 1;\n while(e > 0) {\n if((e&1) == 1) r = (r * b) % mod;\n b = (b * b) % mod;\n e >>= 1;\n }\n return r;\n }\n\n //---------- I/O Template ----------\n \n public static void main(String[] args) { new utkarsh().run(); }\n void run() { \n is = System.in;\n out = new PrintWriter(System.out);\n solve();\n out.flush();\n }\n \n byte input[] = new byte[1024];\n int len = 0, ptr = 0;\n \n int readByte() { \n if(ptr >= len) { ptr = 0; \n try { len = is.read(input); } \n catch(IOException e) { throw new InputMismatchException(); } \n if(len <= 0) { return -1; } \n } return input[ptr++];\n }\n boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }\n int skip() { \n int b = readByte(); \n while(b != -1 && isSpaceChar(b)) { b = readByte(); } \n return b;\n }\n \n char nc() { return (char)skip(); }\n String ns() { \n int b = skip(); \n StringBuilder sb = new StringBuilder(); \n while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); } \n return sb.toString();\n }\n String nLine() { \n int b = skip(); \n StringBuilder sb = new StringBuilder(); \n while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); } \n return sb.toString();\n }\n int ni() { \n int n = 0, b = readByte(); \n boolean minus = false; \n while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); } \n if(b == '-') { minus = true; b = readByte(); } \n if(b == -1) { return -1; } //no input \n while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); } \n return minus ? -n : n;\n }\n long nl() { \n long n = 0L; int b = readByte(); \n boolean minus = false; \n while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); } \n if(b == '-') { minus = true; b = readByte(); } \n while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); } \n return minus ? -n : n;\n }\n\n double nd() { return Double.parseDouble(ns()); }\n float nf() { return Float.parseFloat(ns()); }\n int[] na(int n) { \n int a[] = new int[n]; \n for(int i = 0; i < n; i++) { a[i] = ni(); } \n return a;\n }\n char[] ns(int n) { \n char c[] = new char[n]; \n int i, b = skip(); \n for(i = 0; i < n; i++) { \n if(isSpaceChar(b)) { break; } \n c[i] = (char)b; b = readByte(); \n } return i == n ? c : Arrays.copyOf(c,i);\n }\n}", "lang_cluster": "Java", "tags": ["dp"], "code_uid": "ee7ae4b2409248643d0a94606cf9438b", "src_uid": "4e166b8b44427b1227e0f811161d3a6f", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class Solution\n{\n public static void main(String []ks) throws Exception\n {\n BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));\n long n=Long.parseLong(bf.readLine());\n long a=2,b=3;\n long res=0;\n for(int i=3;i<=n;i++)\n {\n res+=(a*b);\n a++;\n b++;\n }\n System.out.println(res);\n }\n}", "lang_cluster": "Java", "tags": ["math", "greedy", "dp"], "code_uid": "3d0625b6d77bbb587f117badc24e0e73", "src_uid": "1bd29d7a8793c22e81a1f6fd3991307a", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\n/**\n * Created by Gantushig on 2/18/2016.\n */\n\npublic class A {\n\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n long n = input.nextLong();\n System.out.println(\"25\");\n }\n\n}\n", "lang_cluster": "Java", "tags": ["number theory"], "code_uid": "dd8ef698366096e2fffa5a7e2346bc34", "src_uid": "dcaff75492eafaf61d598779d6202c9d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\n\n\npublic class Main{\n\n \n public static void main(String[] args) throws IOException {\n \n BufferedReader b = new BufferedReader( new InputStreamReader(System.in));\n \n String s = b.readLine().trim(); \n String tmp = s.substring(1);\n tmp = tmp.replaceFirst(\"at\", \"@\");\n \n s = s.charAt(0) + tmp;\n \n if( s.length() > 1){\n \n tmp = s.substring(1, s.length() - 1);\n \n tmp = tmp.replaceAll(\"dot\", \".\");\n \n s = s.charAt(0) + tmp + s.charAt(s.length() - 1);\n }\n System.out.println(s);\n \n }\n}\n", "lang_cluster": "Java", "tags": ["expression parsing", "implementation"], "code_uid": "8a9dd7b1a19fab5674379b467a7d8a3d", "src_uid": "a11c9679d8e2dca51be17d466202df6e", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.Closeable;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class MakeThemEqual implements Closeable {\n\n private InputReader in = new InputReader(System.in);\n private PrintWriter out = new PrintWriter(System.out);\n\n public void solve() {\n int n = in.ni();\n int[] x = new int[n];\n for (int i = 0; i < n; i++) {\n x[i] = in.ni();\n }\n Arrays.sort(x);\n int d = (x[n - 1] - x[0]) % 2 == 0 ? (x[n - 1] - x[0]) / 2 : (x[n - 1] - x[0]);\n for (int i = 1; i < n - 1; i++) {\n if (!(x[i] == x[0] || x[i] == x[n - 1] || x[i] == x[0] + d || x[i] == x[n - 1] - d)) {\n out.println(-1);\n return;\n }\n }\n out.println(d);\n }\n\n @Override\n public void close() throws IOException {\n in.close();\n out.close();\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int ni() {\n return Integer.parseInt(next());\n }\n\n public long nl() {\n return Long.parseLong(next());\n }\n\n public void close() throws IOException {\n reader.close();\n }\n }\n\n public static void main(String[] args) throws IOException {\n try (MakeThemEqual instance = new MakeThemEqual()) {\n instance.solve();\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "306e9523cdad32bf846030b67318c6f4", "src_uid": "d486a88939c132848a7efdf257b9b066", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\n\npublic class Solution \n{\n\tpublic static void main (String[] args)\n\t{\n\t\tint count = 1;\n\t\tScanner inp = new Scanner(System.in);\n\t\tString str = inp.next();\n\t\tchar ch[] = str.toCharArray();\n\t\tfor(int i=0;i ans) {\n ans = j;\n\n }\n }\n System.out.println(ans);\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "bb5a7186a4f5fcab524e58d1cd746d1c", "src_uid": "339246a1be81aefe19290de0d1aead84", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Solution\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner in=new Scanner(System.in);\n\t\tint n=in.nextInt();\n\t\tint k=in.nextInt();\n\t\tint m=n,ans=0,i=1,w=0;\n\t\twhile(ans-n!=k)\n\t\t{\n\t\t\tans+=i;\n\t\t\ti++;\n\t\t\tn--;\n\t\t\tw++;\n\t\t}\n\t\tSystem.out.println(m-w);\n\t}\n}\n", "lang_cluster": "Java", "tags": ["brute force", "math", "binary search"], "code_uid": "c89993dda89bd7c41839918f1525efcf", "src_uid": "17b5ec1c6263ef63c668c2b903db1d77", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/*\n * Code Author: Jayesh Udhani\n * Institute : DA-IICT \n * 3rd year BTech ICT Student\n */\n\nimport java.io.*;\nimport java.util.*;\npublic class CFEDU15D\n{\n\tpublic static void main(String args[])\n\t{\n\t\tInputReader in = new InputReader(System.in);\n\t\tOutputStream outputStream = System.out;\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\t/*------------------------------My Code starts here------------------------------*/\n\t\tlong d,k,a,b,t;\n\t\td=in.nextLong();\n\t\tk=in.nextLong();\n\t\ta=in.nextLong();\n\t\tb=in.nextLong();\n\t\tt=in.nextLong();\n\t\tif(d<=k)\n\t\t{\n\t\t\tSystem.out.println(a*d);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tlong ans=0;\n\t\t\tboolean z=false;\n\t\t\tans+=a*k;\n\t\t\td=d-k;\n\t\t\tlong temp=d%k,times=(d-temp)/k;\n\t\t\tif(t+a*k adj[];\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\tpublic static long mod;\n\n\tstatic int [][]notmemo;\n\tstatic int k;\n\tstatic int a[];\n\tstatic int b[];\n\tstatic int m;\n\tstatic char c[];\n\n\n\tstatic class Pair implements Comparable{\n \tint x;\n \tint y;\n \tpublic Pair(int a,int b) {\n\t\tx=a;\n\t\ty=b;\n\t\t\n \t}\n\t\t@Override\n\t\tpublic int compareTo(Pair o) {\n\t\t\tif(x!=o.x)\n\t\t\treturn x-o.x;\n\t\t\treturn y-o.y;\n\t\t}\n \t\n }\n static Pair s1[];\n static int s[];\n\tprivate static HashSet set1;\n\tpublic static void main(String args[]) throws IOException {\n\t\tScanner sc = new Scanner(System.in);\n\t\t n=sc.nextInt();\n\t a=new int[n];\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\ta[i]=sc.nextInt();\n\t\t}\n\t\tnotmemo=new int[n][2];\n\t\tfor(int x[]:notmemo)\n\t\tArrays.fill(x, -1);\n\t\tSystem.out.println(dp(0,0));\n\tout.flush();\n\t\n\t}\n\t\n\t\n static int dp(int idx,int state) {\n if(idx==n) {\n \t return 0;\n }\n if(notmemo[idx][state]!=-1) {\n \t return notmemo[idx][state];\n }\n int take=0; int leave=0;int leaveall=0;\n if(a[idx]==1&&(state==1||state==0)) {\n \ttake=1+dp(idx+1,1); \n }\n if(a[idx]==0&&state==0) {\n \t leave=1+dp(idx+1,state); \n }\n leaveall=dp(idx+1,state);\n \n return notmemo[idx][state]=Math.max(take,Math.max(leaveall,leave));\n }\n static void sieve(int N)\t// O(N log log N) \n\t{\n\t\tisComposite = new int[N+1];\t\t\t\t\t\n\t\tisComposite[0] = isComposite[1] = 1;\t\t\t// 0 indicates a prime number\n\t\tprimes = new ArrayList();\n \n\t\tfor (int i = 2; i <= N; ++i) \t\t\t\t\t//can loop till i*i <= N if primes array is not needed O(N log log sqrt(N)) \n\t\t\tif (isComposite[i] == 0) \t\t\t\t\t//can loop in 2 and odd integers for slightly better performance\n\t\t\t{\n\t\t\t\tprimes.add(i);\n\t\t\t\tif(1l * i * i <= N)\n\t\t\t\t\tfor (int j = i * i; j <= N; j += i)\t// j = i * 2 will not affect performance too much, may alter in modified sieve\n\t\t\t\t\t\tisComposite[j] = 1;\n\t\t\t} \n\t}\n static TreeSet factors;\n static ArrayList primeFactors(int N)\t\t// O(sqrt(N) / ln sqrt(N))\n\t{\n\t\tArrayList factors = new ArrayList();\t\t//take abs(N) in case of -ve integers\n\t\tint idx = 0, p = primes.get(idx);\n\n\t\twhile(1l*p * p <= N)\n\t\t{\n\t\t\twhile(N % p == 0) { factors.add(p); N /= p; }\n\t\t\tp = primes.get(++idx);\n\t\t}\n\n\t\tif(N != 1)\t\t\t\t\t\t// last prime factor may be > sqrt(N)\n\t\t\tfactors.add(N);\t\t\t\t// for integers whose largest prime factor has a power of 1\n\t\treturn factors;\n\t}\n \n static String y;\n \tstatic int nomnom[];\n\tstatic long fac[];\n\t\n\tstatic class book implements Comparable {\n\t\tint idx;\n\t\tlong score;\n\n\t\tpublic book(int i, long s) {\n\t\t\tidx = i;\n\t\t\tscore = s;\n\t\t}\n\n\t\tpublic int compareTo(book o) {\n\t\t\treturn (int) (o.score - score);\n\t\t}\n\t}\n\n\tstatic class library implements Comparable {\n\t\tint numofbooks;\n\t\tint signup;\n\t\tint shiprate;\n\t\tint idx;\n\n\t\tpublic library(int a, int b, int c, int idx) {\n\t\t\tnumofbooks = a;\n\t\t\tsignup = b;\n\t\t\tshiprate = c;\n\t\t\tthis.idx = idx;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(library o) {\n\t\tif(signup==o.signup) {\n\t\t\t return o.numofbooks-numofbooks;\n\t\t}\n\t\treturn signup - o.signup;\n\t\t\n\t\t}\n\t}\n\n\n\n\n\n\tstatic boolean isOn(int S, int j) {\n\t\treturn (S & 1 << j) != 0;\n\t}\n\n\n\tstatic boolean f = true;\n\n\tstatic class SegmentTree { // 1-based DS, OOP\n\n\t\tint N; // the number of elements in the array as a power of 2 (i.e. after padding)\n\t\tint[] array, sTree, lazy;\n\n\t\tSegmentTree(int[] in) {\n\t\t\tarray = in;\n\t\t\tN = in.length - 1;\n\t\t\tsTree = new int[N << 1]; // no. of nodes = 2*N - 1, we add one to cross out index zero\n\t\t\tlazy = new int[N << 1];\n\t\t\t//build(1, 1, N);\n\t\t}\n\n\t\tvoid build(int node, int b, int e) // O(n)\n\t\t{\n\t\t\tif (b == e)\n\t\t\t\tsTree[node] = array[b];\n\t\t\telse {\n\t\t\t\tint mid = b + e >> 1;\n\t\t\t\tbuild(node << 1, b, mid);\n\t\t\t\tbuild(node << 1 | 1, mid + 1, e);\n\t\t\t\tsTree[node] = sTree[node << 1] + sTree[node << 1 | 1];\n\t\t\t}\n\t\t}\n\n\t\tvoid update_point(int index, int val) // O(log n)\n\t\t{\n\t\t\tindex += N - 1;\t\t\t\t\n\t\t\tsTree[index] = val;\t\t\t\n\t\t\twhile(index>1)\t\t\t\t\n\t\t\t{\n\t\t\t\tindex >>= 1;\n\t\t\t\tsTree[index] = Math.max(sTree[index<<1] ,sTree[index<<1|1]);\t\t\n\t\t\t}\n\t\t}\n\n\t\tvoid update_range(int i, int j, int val) // O(log n)\n\t\t{\n\t\t\tupdate_range(1, 1, N, i, j, val);\n\t\t}\n\n\t\tvoid update_range(int node, int b, int e, int i, int j, int val) {\n\t\t\tif (i > e || j < b)\n\t\t\t\treturn;\n\t\t\tif (b >= i && e <= j) {\n\t\t\t\tsTree[node] += (e - b + 1) * val;\n\t\t\t\tlazy[node] += val;\n\t\t\t} else {\n\t\t\t\tint mid = b + e >> 1;\n\t\t\t\tpropagate(node, b, mid, e);\n\t\t\t\tupdate_range(node << 1, b, mid, i, j, val);\n\t\t\t\tupdate_range(node << 1 | 1, mid + 1, e, i, j, val);\n\t\t\t\tsTree[node] = sTree[node << 1] + sTree[node << 1 | 1];\n\t\t\t}\n\n\t\t}\n\n\t\tvoid propagate(int node, int b, int mid, int e) {\n\t\t\tlazy[node << 1] += lazy[node];\n\t\t\tlazy[node << 1 | 1] += lazy[node];\n\t\t\tsTree[node << 1] += (mid - b + 1) * lazy[node];\n\t\t\tsTree[node << 1 | 1] += (e - mid) * lazy[node];\n\t\t\tlazy[node] = 0;\n\t\t}\n\n\t\tint query(int i, int j) {\n\t\t\treturn query(1, 1, N, i, j);\n\t\t}\n\n\t\tint query(int node, int b, int e, int i, int j) // O(log n)\n\t\t{\n\t\t\tif (i > e || j < b)\n\t\t\t\treturn 0;\n\t\t\tif (b >= i && e <= j)\n\t\t\t\treturn sTree[node];\n\t\t\tint mid = b + e >> 1;\n\t\t\t// propagate(node, b, mid, e);\n\t\t\tint q1 = query(node << 1, b, mid, i, j);\n\t\t\tint q2 = query(node << 1 | 1, mid + 1, e, i, j);\n\t\t\treturn Math.max(q1,q2);\n\n\t\t}\n\t}\n\n\tstatic int memo[];\n\n\n\tstatic class UnionFind {\n\t\tint[] p, rank, setSize;\n\t\tint numSets;\n\t\tint max[];\n\n\t\tpublic UnionFind(int N) {\n\t\t\tp = new int[numSets = N];\n\t\t\trank = new int[N];\n\t\t\tsetSize = new int[N];\n\t\t\tfor (int i = 0; i < N; i++) {\n\t\t\t\tp[i] = i;\n\t\t\t\tsetSize[i] = 1;\n\t\t\t}\n\t\t}\n\n\t\tpublic int findSet(int i) {\n\t\t\treturn p[i] == i ? i : (p[i] = findSet(p[i]));\n\t\t}\n\n\t\tpublic boolean isSameSet(int i, int j) {\n\t\t\treturn findSet(i) == findSet(j);\n\t\t}\n\n\t\tpublic void unionSet(int i, int j) {\n\t\t\tif (isSameSet(i, j))\n\t\t\t\treturn;\n\t\t\tnumSets--;\n\t\t\tint x = findSet(i), y = findSet(j);\n\t\t\tif (rank[x] > rank[y]) {\n\t\t\t\tp[y] = x;\n\t\t\t\tsetSize[x] += setSize[y];\n\n\n\t\t\t} else {\n\t\t\t\tp[x] = y;\n\t\t\t\tsetSize[y] += setSize[x];\n\t\t\t\tif (rank[x] == rank[y])\n\t\t\t\t\trank[y]++;\n\n\n\t\t\t}\n\t\t}\n\n\t\t\n\n\t\tpublic int numDisjointSets() {\n\t\t\treturn numSets;\n\t\t}\n\n\t\tpublic int sizeOfSet(int i) {\n\t\t\treturn setSize[findSet(i)];\n\t\t}\n\t}\n\n\t/**\n\t * private static void trace(int i, int time) { if(i==n) return;\n\t * \n\t * \n\t * long ans=dp(i,time);\n\t * if(time+a[i].t {\n\t\tint a;\n\t\tlong b;\n\t\tint idx;\n\n\t\tincpair(int a, long dirg, int i) {\n\t\t\tthis.a = a;\n\t\t\tb = dirg;\n\t\t\tidx = i;\n\t\t}\n\n\t\tpublic int compareTo(incpair e) {\n\t\t\treturn (int) (b - e.b);\n\t\t}\n\t}\n\n\tstatic class decpair implements Comparable {\n\t\tint a;\n\t\tlong b;\n\t\tint idx;\n\n\t\tdecpair(int a, long dirg, int i) {\n\t\t\tthis.a = a;\n\t\t\tb = dirg;\n\t\t\tidx = i;\n\t\t}\n\n\t\tpublic int compareTo(decpair e) {\n\t\t\treturn (int) (e.b - b);\n\t\t}\n\t}\n\n\tstatic long allpowers[];\n\n\tstatic class Quad implements Comparable {\n\t\tint u;\n\t\tint v;\n\t\tchar state;\n\t\tint turns;\n\n\t\tpublic Quad(int i, int j, char c, int k) {\n\t\t\tu = i;\n\t\t\tv = j;\n\t\t\tstate = c;\n\t\t\tturns = k;\n\t\t}\n\n\t\tpublic int compareTo(Quad e) {\n\t\t\treturn (int) (turns - e.turns);\n\t\t}\n\n\t}\n\n\tstatic long dirg[][];\n\tstatic Edge[] driver;\n\n\tstatic int n;\n\n\tstatic class Edge implements Comparable {\n\t\tint node;\n\t\tlong cost;\n\n\t\tEdge(int a, long dirg) {\n\t\t\tnode = a;\n\t\t\tcost = dirg;\n\t\t}\n\n\t\tpublic int compareTo(Edge e) {\n\t\t\treturn (int) (cost - e.cost);\n\t\t}\n\t}\n\n\tstatic long manhatandistance(long x, long x2, long y, long y2) {\n\t\treturn Math.abs(x - x2) + Math.abs(y - y2);\n\t}\n\n\tstatic long fib[];\n\n\tstatic long fib(int n) {\n\t\tif (n == 1 || n == 0) {\n\t\t\treturn 1;\n\t\t}\n\t\tif (fib[n] != -1) {\n\t\t\treturn fib[n];\n\t\t} else\n\t\t\treturn fib[n] = ((fib(n - 2) % mod + fib(n - 1) % mod) % mod);\n\t}\n\n\tstatic class Point implements Comparable{\n\t\tlong x, y;\n\n\t\tPoint(long counth, long counts) {\n\t\t\tx = counth;\n\t\t\ty = counts;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Point p )\n\t\t{\n\t\t\treturn Long.compare(p.y*1l*x, p.x*1l*y);\n\t\t}\n\t\t\n\n\n\t}\n\n\tstatic long[][] comb;\n\n\tstatic class Triple implements Comparable {\n\n\t\tint l;\n\t\tint r;\n\t\tlong cost;\n\t\tint idx;\n\n\t\tpublic Triple(int a, int b, long l1, int l2) {\n\t\t\tl = a;\n\t\t\tr = b;\n\t\t\tcost = l1;\n\t\t\tidx = l2;\n\t\t}\n\n\t\tpublic int compareTo(Triple x) {\n\t\t\tif (l != x.l || idx == x.idx)\n\t\t\t\treturn l - x.l;\n\t\t\treturn -idx;\n\t\t}\n\n\t}\n\n\tstatic TreeSet primeFactors(long N) // O(sqrt(N) / ln sqrt(N))\n\t{\n\t\tTreeSet factors = new TreeSet(); // take abs(N) in case of -ve integers\n\t\tint idx = 0, p = primes.get(idx);\n\n\t\twhile (p * p <= N) {\n\t\t\twhile (N % p == 0) {\n\t\t\t\tfactors.add((long) p);\n\t\t\t\tN /= p;\n\t\t\t}\n\t\t\tif (primes.size() > idx + 1)\n\t\t\t\tp = primes.get(++idx);\n\t\t\telse\n\t\t\t\tbreak;\n\t\t}\n\n\t\tif (N != 1) // last prime factor may be > sqrt(N)\n\t\t\tfactors.add(N); // for integers whose largest prime factor has a power of 1\n\t\treturn factors;\n\t}\n\n\tstatic boolean visited[];\n\n\t/**\n\t * static int bfs(int s) { Queue q = new LinkedList();\n\t * q.add(s); int count=0; int maxcost=0; int dist[]=new int[n]; dist[s]=0;\n\t * while(!q.isEmpty()) {\n\t * \n\t * int u = q.remove(); if(dist[u]==k) { break; } for(Pair v: adj[u]) {\n\t * maxcost=Math.max(maxcost, v.cost);\n\t * \n\t * \n\t * \n\t * if(!visited[v.v]) {\n\t * \n\t * visited[v.v]=true; q.add(v.v); dist[v.v]=dist[u]+1; maxcost=Math.max(maxcost,\n\t * v.cost); } }\n\t * \n\t * } return maxcost; }\n\t **/\n\tpublic static boolean FindAllElements(int n, int k) {\n\t\tint sum = k;\n\t\tint[] A = new int[k];\n\t\tArrays.fill(A, 0, k, 1);\n\n\t\tfor (int i = k - 1; i >= 0; --i) {\n\n\t\t\twhile (sum + A[i] <= n) {\n\n\t\t\t\tsum += A[i];\n\t\t\t\tA[i] *= 2;\n\t\t\t}\n\t\t}\n\t\tif (sum == n) {\n\t\t\treturn true;\n\t\t} else\n\t\t\treturn false;\n\t}\n\n\tstatic boolean[] vis2;\n\n\tstatic boolean f2 = false;\n\n\tstatic long[][] matMul(long[][] a2, long[][] b, int p, int q, int r) // C(p x r) = A(p x q) x (q x r) -- O(p x q x\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t// r)\n\t{\n\t\tlong[][] C = new long[p][r];\n\t\tfor (int i = 0; i < p; ++i) {\n\t\t\tfor (int j = 0; j < r; ++j) {\n\t\t\t\tfor (int k = 0; k < q; ++k) {\n\t\t\t\t\tC[i][j] = (C[i][j] + (a2[i][k] % mod * b[k][j] % mod)) % mod;\n\t\t\t\t\tC[i][j] %= mod;\n\t\t\t\t}\n\n\t\t\t}\n\t\t}\n\t\treturn C;\n\t}\n\n\tstatic int memo1[];\n\n\tstatic boolean vis[];\n\tstatic TreeSet set = new TreeSet();\n\n\tstatic long modPow(long ways, long count, long mod) // O(log e)\n\t{\n\t\tways %= mod;\n\t\tlong res = 1;\n\t\twhile (count > 0) {\n\t\t\tif ((count & 1) == 1)\n\t\t\t\tres = (res * ways) % mod;\n\t\t\tways = (ways * ways) % mod;\n\t\t\tcount >>= 1;\n\t\t}\n\t\treturn res % mod;\n\t}\n\n\tstatic long gcd(long ans, long b) {\n\t\tif (b == 0) {\n\t\t\treturn ans;\n\t\t}\n\t\treturn gcd(b, ans % b);\n\t}\n\n\tstatic int[] isComposite;\n\tstatic int[] valid;\n\n\tstatic ArrayList primes;\n\tstatic ArrayList l1;\n\n\t\n\tstatic TreeSet primus = new TreeSet();\n\t\n\tstatic void sieveLinear(int N)\n\t{\n\t\tint[] lp = new int[N + 1];\t\t\t\t\t\t\t\t//lp[i] = least prime divisor of i\n\t\tfor(int i = 2; i <= N; ++i)\n\t\t{\n\t\t\tif(lp[i] == 0)\n\t\t\t{\n\t\t\t\tprimus.add(i);\n\t\t\t\tlp[i] = i;\n\t\t\t}\n\t\t\tint curLP = lp[i];\n\t\t\tfor(int p: primus)\n\t\t\t\tif(p > curLP || p * i > N)\n\t\t\t\t\tbreak;\n\t\t\t\telse\n\t\t\t\t\tlp[p * i] = i;\n\t\t}\n\t}\n\t\n\n\tpublic static int[] schuffle(int[] p) {\n\t\tfor (int i = 0; i < p.length; i++) {\n\t\t\tint x = (int) (Math.random() * p.length);\n\t\t\tint temp = p[x];\n\t\t\tp[x] = p[i];\n\t\t\tp[i] = temp;\n\t\t}\n\t\treturn p;\n\t}\n\n\tstatic int V;\n\tstatic long INF = (long) 1E16;\n\n\tstatic class Edge2 {\n\t\tint node;\n\t\tlong cost;\n\t\tlong next;\n\n\t\tEdge2(int a, int c, Long long1) {\n\t\t\tnode = a;\n\t\t\tcost = long1;\n\t\t\tnext = c;\n\t\t}\n\n\t}\n\n\tstatic class Scanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream system) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(system));\n\t\t}\n\n\t\tpublic Scanner(String file) throws Exception {\n\t\t\tbr = new BufferedReader(new FileReader(file));\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic String nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic char nextChar() throws IOException {\n\t\t\treturn next().charAt(0);\n\t\t}\n\n\t\tpublic Long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic boolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t\tpublic void waitForInput() throws InterruptedException {\n\t\t\tThread.sleep(3000);\n\t\t}\n\n\t\tpublic int[] nxtArr(int n) throws IOException {\n\t\t\tint[] ans = new int[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tans[i] = nextInt();\n\t\t\treturn ans;\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "e3b66d773d37866889f697be375e46ef", "src_uid": "c7b1f0b40e310f99936d1c33e4816b95", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.awt.Point;\n\n// SHIVAM GUPTA :\n//NSIT\n//decoder_1671\n\n// STOP NOT TILL IT IS DONE OR U DIE .\n\n// U KNOW THAT IF THIS DAY WILL BE URS THEN NO ONE CAN DEFEAT U HERE................\n\n// ASCII = 48 + i ;// 2^28 = 268,435,456 > 2* 10^8 // log 10 base 2 = 3.3219 \n\n// odd:: (x^2+1)/2 , (x^2-1)/2 ; x>=3// even:: (x^2/4)+1 ,(x^2/4)-1 x >=4 \n\n// FOR ANY ODD NO N : N,N-1,N-2\n//ALL ARE PAIRWISE COPRIME \n//THEIR COMBINED LCM IS PRODUCT OF ALL THESE NOS\n\n// two consecutive odds are always coprime to each other\n// two consecutive even have always gcd = 2 ;\n\npublic class Main\n{\n // static int[] arr = new int[100002] ; // static int[] dp = new int[100002] ; \n \n static PrintWriter out;\n \n\tstatic class FastReader{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FastReader(){\n\t\t\tbr=new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout=new PrintWriter(System.out);\n\t\t}\n\t\tString next(){\n\t\t\twhile(st==null || !st.hasMoreElements()){\n\t\t\t\ttry{\n\t\t\t\t\tst= new StringTokenizer(br.readLine());\n\t\t\t\t}\n\t\t\t\tcatch (IOException e){\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tint nextInt(){\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tlong nextLong(){\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\tdouble nextDouble(){\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\tString nextLine(){\n\t\t\tString str = \"\";\n\t\t\ttry{\n\t\t\t\tstr=br.readLine();\n\t\t\t}\n\t\t\tcatch(IOException e){\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\t}\n\t\n\n\n////////////////////////////////////////////////////////////////////////////////////\n public static int countDigit(long n) \n { \n return (int)Math.floor(Math.log10(n) + 1); \n } \n\n///////////////////////////////////////////////////////////////////////////////////////// \n \n public static int sumOfDigits(long n)\n {\n \n if( n< 0)return -1 ;\n \n int sum = 0;\n \n while( n > 0)\n {\n sum = sum + (int)( n %10) ;\n \n n /= 10 ;\n }\n \n return sum ; \n \n \n \n }\n \n //////////////////////////////////////////////////////////////////////////////////////////////////\n\npublic static long arraySum(int[] arr , int start , int end)\n{\n long ans = 0 ;\n \n for(int i = start ; i <= end ; i++)ans += arr[i] ;\n \n return ans ;\n}\n\n/////////////////////////////////////////////////////////////////////////////////\n\npublic static int mod(int x)\n{\n if(x <0)return -1*x ;\n else return x ;\n}\npublic static long mod(long x)\n{\n if(x <0)return -1*x ;\n else return x ;\n}\n\n////////////////////////////////////////////////////////////////////////////////\n\npublic static void swapArray(int[] arr , int start , int end)\n{\n while(start < end)\n {\n int temp = arr[start] ;\n arr[start] = arr[end];\n arr[end] = temp;\n start++ ;end-- ;\n }\n}\n\n\n//////////////////////////////////////////////////////////////////////////////////\n\n\npublic static int[][] rotate(int[][] input){\n\nint n =input.length;\nint m = input[0].length ;\nint[][] output = new int [m][n];\n\nfor (int i=0; i> (1L) ;\n } \n \n return count; \n \n } \n/////////////////////////////////////////// //////////////////////////////////////////////// \n\npublic static boolean isPowerOfTwo(long n) \n{ \n if(n==0) \n return false; \n \nif(((n ) & (n-1)) == 0 ) return true ;\nelse return false ;\n\n} \n\n/////////////////////////////////////////////////////////////////////////////////////\n\npublic static int min(int a ,int b , int c, int d)\n{\n int[] arr = new int[4] ;\n arr[0] = a;arr[1] = b ;arr[2] = c;arr[3] = d;Arrays.sort(arr) ;\n \n return arr[0];\n}\n /////////////////////////////////////////////////////////////////////////////\npublic static int max(int a ,int b , int c, int d)\n{\n int[] arr = new int[4] ;\n arr[0] = a;arr[1] = b ;arr[2] = c;arr[3] = d;Arrays.sort(arr) ;\n \n return arr[3];\n}\n \n/////////////////////////////////////////////////////////////////////////////////// \n\npublic static String reverse(String input)\n{\n StringBuilder str = new StringBuilder(\"\") ;\n \n for(int i =input.length()-1 ; i >= 0 ; i-- )\n {\n str.append(input.charAt(i));\n }\n \nreturn str.toString() ;\n}\n///////////////////////////////////////////////////////////////////////////////////////////\n\npublic static boolean sameParity(long a ,long b )\n{\n long x = a% 2L; long y = b%2L ;\n if(x==y)return true ;\n else return false ;\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////\npublic static boolean isPossibleTriangle(int a ,int b , int c)\n{\n if( a + b > c && c+b > a && a +c > b)return true ;\n else return false ;\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////\nstatic long xnor(long num1, long num2) {\n\t\tif (num1 < num2) {\n\t\t\tlong temp = num1;\n\t\t\tnum1 = num2;\n\t\t\tnum2 = temp;\n\t\t}\n\t\tnum1 = togglebit(num1);\n\t\treturn num1 ^ num2;\n\t}\n\n\tstatic long togglebit(long n) {\n\t\tif (n == 0)\n\t\t\treturn 1;\n\t\tlong i = n;\n\t\tn |= n >> 1;\n\t\tn |= n >> 2;\n\t\tn |= n >> 4;\n\t\tn |= n >> 8;\n\t\tn |= n >> 16;\n\t\treturn i ^ n;\n\t}\n\n///////////////////////////////////////////////////////////////////////////////////////////////\n\npublic static int xorOfFirstN(int n)\n{\n \n \n if( n % 4 ==0)return n ;\n \n else if( n % 4 == 1)return 1 ;\n \n else if( n % 4 == 2)return n+1 ;\n \n else return 0 ;\n \n \n}\n//////////////////////////////////////////////////////////////////////////////////////////////\n\npublic static int gcd(int a, int b )\n{\n\nif(b==0)return a ;\n\nelse return gcd(b,a%b) ; \n\n}\n\n\npublic static long gcd(long a, long b )\n{\n\nif(b==0)return a ;\n\nelse return gcd(b,a%b) ; \n\n}\n\n////////////////////////////////////////////////////////////////////////////////////\n\npublic static int lcm(int a, int b ,int c , int d )\n{\n\nint temp = lcm(a,b , c) ;\n\n\n \n int ans = lcm(temp ,d ) ;\n\nreturn ans ;\n\n\n}\n\n///////////////////////////////////////////////////////////////////////////////////////////\n\npublic static int lcm(int a, int b ,int c )\n{\n\nint temp = lcm(a,b) ;\n\nint ans = lcm(temp ,c) ;\n\nreturn ans ;\n\n\n}\n\n////////////////////////////////////////////////////////////////////////////////////////\n \npublic static int lcm(int a , int b )\n{\n\nint gc = gcd(a,b);\n\nreturn (a*b)/gc ;\n}\n\n\npublic static long lcm(long a , long b )\n{\n\nlong gc = gcd(a,b);\n\nreturn (a*b)/gc ;\n}\n\n\n///////////////////////////////////////////////////////////////////////////////////////////\nstatic boolean isPrime(long n)\n{\n if(n==1)\n {\n return false ;\n }\n \n boolean ans = true ;\n \n for(long i = 2L; i*i <= n ;i++)\n {\n if(n% i ==0)\n {\n ans = false ;break ;\n }\n }\n \n \n return ans ;\n} \n///////////////////////////////////////////////////////////////////////////\n\nstatic int sieve = 1000000 ;\n\n \nstatic boolean[] prime = new boolean[sieve + 1] ;\n\npublic static void sieveOfEratosthenes() \n { \n // FALSE == prime\n \n // TRUE == COMPOSITE\n \n // FALSE== 1\n \n \n // time complexity = 0(NlogLogN)== o(N)\n \n // gives prime nos bw 1 to N\n \n for(int i = 4; i<= sieve ; i++)\n {\n prime[i] = true ;\n i++ ;\n }\n \n for(int p = 3; p*p <= sieve; p++) \n { \n \n if(prime[p] == false) \n { \n \n for(int i = p*p; i <= sieve; i += p) \n prime[i] = true; \n } \n \n p++ ;\n } \n \n \n \n \n } \n \n///////////////////////////////////////////////////////////////////////////////////\n\n\npublic static void sortD(int[] arr , int s , int e)\n{\n sort(arr ,s , e) ;\n \n int i =s ; int j = e ;\n \n while( i < j)\n {\n int temp = arr[i] ;\n arr[i] =arr[j] ;\n arr[j] = temp ;\n i++ ; j-- ;\n }\n \n \n \n return ;\n}\n\n\n/////////////////////////////////////////////////////////////////////////////////////////\n\npublic static long countSubarraysSumToK(long[] arr ,long sum )\n {\n HashMap map = new HashMap<>() ;\n \n int n = arr.length ;\n \n long prefixsum = 0 ;\n \n long count = 0L ;\n for(int i = 0; i < n ; i++)\n {\n prefixsum = prefixsum + arr[i] ;\n \n if(sum == prefixsum)count = count+1 ;\n \n if(map.containsKey(prefixsum -sum))\n {\n count = count + map.get(prefixsum -sum) ;\n }\n \n \n if(map.containsKey(prefixsum ))\n {\n map.put(prefixsum , map.get(prefixsum) +1 );\n }\n \n else{\n map.put(prefixsum , 1L );\n }\n \n \n }\n \n \n \n return count ; \n \n }\n\n///////////////////////////////////////////////////////////////////////////////////////////////\n\n\n// KMP ALGORITHM : TIME COMPL:O(N+M) \n// FINDS THE OCCURENCES OF PATTERN AS A SUBSTRING IN STRING\n//RETURN THE ARRAYLIST OF INDEXES \n// IF SIZE OF LIST IS ZERO MEANS PATTERN IS NOT PRESENT IN STRING\n\n\npublic static ArrayList kmpAlgorithm(String str , String pat)\n {\n ArrayList list =new ArrayList<>();\n \n int n = str.length() ;\n int m = pat.length() ;\n \n String q = pat + \"#\" + str ;\n \n int[] lps =new int[n+m+1] ;\n \n longestPefixSuffix(lps, q,(n+m+1)) ;\n \n \n for(int i =m+1 ; i < (n+m+1) ; i++ )\n {\n if(lps[i] == m)\n {\n list.add(i-2*m) ;\n }\n }\n \n return list ; \n \n \n }\n \n\npublic static void longestPefixSuffix(int[] lps ,String str , int n)\n {\n lps[0] = 0 ;\n \n for(int i = 1 ; i<= n-1; i++)\n {\n int l = lps[i-1] ;\n \n while( l > 0 && str.charAt(i) != str.charAt(l))\n {\n l = lps[l-1] ;\n }\n \n if(str.charAt(i) == str.charAt(l))\n {\n l++ ;\n }\n \n \n lps[i] = l ; \n }\n \n }\n \n \n\n///////////////////////////////////////////////////////////////////////////////////////////////////\n///////////////////////////////////////////////////////////////////////////////////////////////////\n\n // CALCULATE TOTIENT Fn FOR ALL VALUES FROM 1 TO n\n // TOTIENT(N) = count of nos less than n and grater than 1 whose gcd with n is 1 \n // or n and the no will be coprime in nature\n //time : O(n*(log(logn)))\n \n public static void eulerTotientFunction(int[] arr ,int n )\n {\n \n for(int i = 1; i <= n ;i++)arr[i] =i ;\n \n \n for(int i= 2 ; i<= n ;i++)\n {\n if(arr[i] == i)\n {\n arr[i] =i-1 ;\n \n for(int j =2*i ; j<= n ; j+= i )\n {\n arr[j] = (arr[j]*(i-1))/i ;\n }\n \n }\n }\n \n return ; \n \n }\n\t\n/////////////////////////////////////////////////////////////////////////////////////////////\npublic static long nCr(int n,int k)\n{\n long ans=1L;\n k=k>n-k?n-k:k;\n int j=1;\n for(;j<=k;j++,n--)\n {\n if(n%j==0)\n {\n ans*=n/j;\n }else\n if(ans%j==0)\n {\n ans=ans/j*n;\n }else\n {\n ans=(ans*n)/j;\n }\n }\n return ans;\n}\n\n///////////////////////////////////////////////////////////////////////////////////////////\n\npublic static ArrayList allFactors(int n)\n{ \n ArrayList list = new ArrayList<>() ;\n \n for(int i = 1; i*i <= n ;i++)\n {\n if( n % i == 0)\n {\n if(i*i == n)\n {\n list.add(i) ;\n }\n else{\n list.add(i) ;\n list.add(n/i) ;\n \n }\n }\n }\n \n return list ; \n \n \n}\n\n\npublic static ArrayList allFactors(long n)\n{ \n ArrayList list = new ArrayList<>() ;\n \n for(long i = 1L; i*i <= n ;i++)\n {\n if( n % i == 0)\n {\n if(i*i == n)\n {\n list.add(i) ;\n }\n else{\n list.add(i) ;\n list.add(n/i) ;\n \n }\n }\n }\n \n return list ; \n \n \n}\n////////////////////////////////////////////////////////////////////////////////////////////////////\n\n static final int MAXN = 10000001; \n \n \n static int spf[] = new int[MAXN]; \n \n static void sieve() \n { \n spf[1] = 1; \n for (int i=2; i getFactorization(int x) \n { \n Vector ret = new Vector<>(); \n while (x != 1) \n { \n ret.add(spf[x]); \n x = x / spf[x]; \n } \n return ret; \n } \n \n //////////////////////////////////////////////////////////////////////////////////////////////////\n //////////////////////////////////////////////////////////////////////////////////////////////////\n \npublic static void merge(int arr[], int l, int m, int r)\n {\n // Find sizes of two subarrays to be merged\n int n1 = m - l + 1;\n int n2 = r - m;\n \n /* Create temp arrays */\n int L[] = new int[n1];\n int R[] = new int[n2];\n \n //Copy data to temp arrays\n for (int i=0; i= weight[i]; j--) \n dp[j] = Math.max(dp[j] , value[i] + dp[j - weight[i]]); \n \n /*above line finds out maximum of dp[j](excluding ith element value) \n and val[i] + dp[j-wt[i]] (including ith element value and the \n profit with \"KnapSack capacity - ith element weight\") */\n return dp[maxWeight]; \n\t}\n\n///////////////////////////////////////////////////////////////////////////////////////////\n//////////////////////////////////////////////////////////////////////////////////////////\n\n\n// to return max sum of any subarray in given array\npublic static long kadanesAlgorithm(long[] arr)\n{\n long[] dp = new long[arr.length] ;\n \n dp[0] = arr[0] ;\n long max = dp[0] ;\n \n \n for(int i = 1; i < arr.length ; i++)\n {\n if(dp[i-1] > 0)\n {\n dp[i] = dp[i-1] + arr[i] ;\n }\n else{\n dp[i] = arr[i] ;\n }\n \n if(dp[i] > max)max = dp[i] ;\n \n }\n \n return max ;\n \n}\n/////////////////////////////////////////////////////////////////////////////////////////////\npublic static long kadanesAlgorithm(int[] arr)\n{\n long[] dp = new long[arr.length] ;\n \n dp[0] = arr[0] ;\n long max = dp[0] ;\n \n \n for(int i = 1; i < arr.length ; i++)\n {\n if(dp[i-1] > 0)\n {\n dp[i] = dp[i-1] + arr[i] ;\n }\n else{\n dp[i] = arr[i] ;\n }\n \n if(dp[i] > max)max = dp[i] ;\n \n }\n \n return max ;\n \n}\n\n \n///////////////////////////////////////////////////////////////////////////////////////\n\n\n\n/////////////////////////////////////////////////////////////////////////////////////////\n\npublic static long binarySerachGreater(int[] arr , int start , int end , int val)\n{\n \n // fing total no of elements strictly grater than val in sorted array arr \n \n \n if(start > end)return 0 ; //Base case\n \n \n int mid = (start + end)/2 ;\n \n if(arr[mid] <=val)\n {\n return binarySerachGreater(arr,mid+1, end ,val) ; \n \n }\n else{\n \n return binarySerachGreater(arr,start , mid -1,val) + end-mid+1 ; \n \n }\n \n \n}\n\n//////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////\n\n//TO GENERATE ALL(DUPLICATE ALSO EXIST) PERMUTATIONS OF A STRING\n\n\n// JUST CALL generatePermutation( str, start, end) start :inclusive ,end : exclusive \n\n//Function for swapping the characters at position I with character at position j \n public static String swapString(String a, int i, int j) { \n char[] b =a.toCharArray(); \n char ch; \n ch = b[i]; \n b[i] = b[j]; \n b[j] = ch; \n return String.valueOf(b); \n } \n \n//Function for generating different permutations of the string \n public static void generatePermutation(String str, int start, int end) \n { \n //Prints the permutations \n if (start == end-1) \n System.out.println(str); \n else \n { \n for (int i = start; i < end; i++) \n { \n //Swapping the string by fixing a character \n str = swapString(str,start,i); \n //Recursively calling function generatePermutation() for rest of the characters \n generatePermutation(str,start+1,end); \n //Backtracking and swapping the characters again. \n str = swapString(str,start,i); \n } \n } \n } \n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////\n//////////////////////////////////////////////////////////////////////////////////////////////////////\n\npublic static long factMod(long n, long mod) {\n if (n <= 1) return 1;\n long ans = 1;\n for (int i = 1; i <= n; i++) {\n ans = (ans * i) % mod;\n }\n return ans;\n }\n\n\n/////////////////////////////////////////////////////////////////////////////////////////////\n//////////////////////////////////////////////////////////////////////////////////////////////////\n\npublic static long power(long x ,long n)\n {\n //time comp : o(logn) \n \n if(n==0)return 1L ;\n if(n==1)return x;\n \n long ans =1L ;\n \n while(n>0)\n {\n if(n % 2 ==1)\n {\n ans = ans *x ;\n }\n \n n /= 2 ;\n \n x = x*x ;\n \n }\n \n return ans ;\n }\n\n////////////////////////////////////////////////////////////////////////////////////////////////////\npublic static long powerMod(long x, long n, long mod) {\n //time comp : o(logn)\n \n if(n==0)return 1L ;\n if(n==1)return x;\n \n \n long ans = 1;\n while (n > 0) {\n if (n % 2 == 1) ans = (ans * x) % mod;\n x = (x * x) % mod;\n n /= 2;\n }\n return ans;\n }\n \n//////////////////////////////////////////////////////////////////////////////////\n\n/////////////////////////////////////////////////////////////////////////////////\n\n/*\nlowerBound - finds largest element equal or less than value paased\nupperBound - finds smallest element equal or more than value passed\n\nif not present return -1;\n\n*/\n\npublic static long lowerBound(long[] arr,long k)\n\t{\n\t\tlong ans=-1;\n\t\t\n\t\tint start=0;\n\t\tint end=arr.length-1;\n\t\t\n\t\twhile(start<=end)\n\t\t{\n\t\t\tint mid=(start+end)/2;\n\t\t\t\n\t\t\tif(arr[mid]<=k)\n\t\t\t{\n\t\t\t\tans=arr[mid];\n\t\t\t\tstart=mid+1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tend=mid-1;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\treturn ans;\n\t\t\n\t}\n\t\n\tpublic static int lowerBound(int[] arr,int k)\n\t{\n\t\tint ans=-1;\n\t\t\n\t\tint start=0;\n\t\tint end=arr.length-1;\n\t\t\n\t\twhile(start<=end)\n\t\t{\n\t\t\tint mid=(start+end)/2;\n\t\t\t\n\t\t\tif(arr[mid]<=k)\n\t\t\t{\n\t\t\t\tans=arr[mid];\n\t\t\t\tstart=mid+1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tend=mid-1;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\treturn ans;\n\t\t\n\t}\n\t\n\t\n\tpublic static long upperBound(long[] arr,long k)\n\t{\n\t\tlong ans=-1;\n\t\t\n\t\tint start=0;\n\t\tint end=arr.length-1;\n\t\t\n\t\twhile(start<=end)\n\t\t{\n\t\t\tint mid=(start+end)/2;\n\t\t\t\n\t\t\tif(arr[mid]>=k)\n\t\t\t{\n\t\t\t\tans=arr[mid];\n\t\t\t\tend=mid-1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tstart=mid+1;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\treturn ans;\n\t}\n\t\n\t\n\tpublic static int upperBound(int[] arr,int k)\n\t{\n\t\tint ans=-1;\n\t\t\n\t\tint start=0;\n\t\tint end=arr.length-1;\n\t\t\n\t\twhile(start<=end)\n\t\t{\n\t\t\tint mid=(start+end)/2;\n\t\t\t\n\t\t\tif(arr[mid]>=k)\n\t\t\t{\n\t\t\t\tans=arr[mid];\n\t\t\t\tend=mid-1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tstart=mid+1;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\treturn ans;\n\t}\n\t\n\n//////////////////////////////////////////////////////////////////////////////////////////\n\npublic static void printArray(int[] arr , int si ,int ei)\n{\n for(int i = si ; i <= ei ; i++)\n {\n out.print(arr[i] +\" \") ;\n }\n \n}\n\npublic static void printArrayln(int[] arr , int si ,int ei)\n{\n for(int i = si ; i <= ei ; i++)\n {\n out.print(arr[i] +\" \") ;\n }\n out.println() ;\n}\n\n\npublic static void printLArray(long[] arr , int si , int ei)\n{\n for(int i = si ; i <= ei ; i++)\n {\n out.print(arr[i] +\" \") ;\n }\n \n}\n\n\n\n\npublic static void printLArrayln(long[] arr , int si , int ei)\n{\n for(int i = si ; i <= ei ; i++)\n {\n out.print(arr[i] +\" \") ;\n }\n out.println() ;\n \n}\n\npublic static void printtwodArray(int[][] ans)\n{\n for(int i = 0; i< ans.length ; i++)\n {\n for(int j = 0 ; j < ans[0].length ; j++)out.print(ans[i][j] +\" \");\n out.println() ;\n }\n out.println() ;\n \n}\n\n \n static long modPow(long a, long x, long p) {\n //calculates a^x mod p in logarithmic time.\n long res = 1;\n while(x > 0) {\n if( x % 2 != 0) {\n res = (res * a) % p;\n }\n a = (a * a) % p;\n x /= 2;\n }\n return res;\n}\n \n \n \n static long modInverse(long a, long p) {\n //calculates the modular multiplicative of a mod m.\n //(assuming p is prime).\n return modPow(a, p-2, p);\n}\n \n \n \nstatic long modBinomial(long n, long k, long p) {\n// calculates C(n,k) mod p (assuming p is prime).\n \n long numerator = 1; // n * (n-1) * ... * (n-k+1)\n for (int i=0; i[] tree ;\n// static long[] child;\n// static int mod= 1000000007 ;\n// static int[][] pre = new int[3001][3001];\n// static int[][] suf = new int[3001][3001] ;\n\n//program to calculate noof nodes in subtree for every vertex including itself \n\n public static void countNoOfNodesInsubtree(int child ,int par , int[] dp)\n {\n int count = 1 ;\n \n for(int x : tree[child])\n {\n \n if(x== par)continue ;\n \n countNoOfNodesInsubtree(x,child,dp) ;\n \n count= count + dp[x] ;\n }\n \n dp[child] = count ;\n \n }\n\npublic static void depth(int child ,int par , int[] dp , int d )\n {\n dp[child] =d ;\n \n for(int x : tree[child])\n {\n \n if(x== par)continue ;\n \n depth(x,child,dp,d+1) ;\n \n }\n \n }\n\npublic static void dfs(int sv , boolean[] vis)\n{\n vis[sv] = true ;\n \n \n for(int x : tree[sv])\n {\n if( !vis[x])\n {\n dfs(x ,vis) ;\n }\n }\n \n \n \n \n}\n\n\n//////////////////////////////////////////////////////////////////////////////////////////////\n//////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////\n\npublic static void solve()\n{\nFastReader scn = new FastReader() ;\n\n//Scanner scn = new Scanner(System.in);\n//int[] store = {2 ,3, 5 , 7 ,11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 } ;\n\n// product of first 11 prime nos is greater than 10 ^ 12;\n\n//ArrayList arr[] = new ArrayList[n] ;\nArrayList list = new ArrayList<>() ;\nArrayList listl = new ArrayList<>() ;\nArrayList lista = new ArrayList<>() ;\nArrayList listb = new ArrayList<>() ;\n//ArrayList lists = new ArrayList<>() ;\n\nHashMap map = new HashMap<>() ;\n//HashMap map = new HashMap<>() ;\nHashMap map1 = new HashMap<>() ;\nHashMap map2 = new HashMap<>() ;\n//HashMap maps = new HashMap<>() ;\n//HashMap mapb = new HashMap<>() ;\n//HashMap point = new HashMap<>() ; \n\n Set set = new HashSet<>() ;\n Set setx = new HashSet<>() ;\n Set sety = new HashSet<>() ;\n\nStringBuilder sb =new StringBuilder(\"\") ;\n\n//Collections.sort(list);\n\n//if(map.containsKey(arr[i]))map.put(arr[i] , map.get(arr[i]) +1 ) ;\n//else map.put(arr[i],1) ;\n\n// if(map.containsKey(temp))map.put(temp , map.get(temp) +1 ) ;\n// else map.put(temp,1) ;\n\n//int bit =Integer.bitCount(n);\n// gives total no of set bits in n;\n\n// Arrays.sort(arr, new Comparator() {\n// \t\t\t@Override\n// \t\t\tpublic int compare(Pair a, Pair b) {\n// \t\t\t\tif (a.first != b.first) {\n// \t\t\t\t\treturn a.first - b.first; // for increasing order of first\n// \t\t\t\t}\n// \t\t\t\treturn a.second - b.second ; //if first is same then sort on second basis\n// \t\t\t}\n// \t\t});\n\n\n\nint testcases = 1; \n //testcases = scn.nextInt() ;\nfor(int testcase =1 ; testcase <= testcases ;testcase++)\n{\n \n //if(map.containsKey(arr[i]))map.put(arr[i],map.get(arr[i])+1) ;else map.put(arr[i],1) ;\n //if(map.containsKey(temp))map.put(temp,map.get(temp)+1) ;else map.put(temp,1) ;\n \n// int n = scn.nextInt() ;int m = scn.nextInt() ;\n// tree = new ArrayList[n] ;\n// for(int i = 0; i< n; i++)\n// {\n// tree[i] = new ArrayList();\n// }\n \n// for(int i = 0 ; i <= m-1 ; i++)\n// {\n// int fv = scn.nextInt()-1 ; int sv = scn.nextInt()-1 ;\n// tree[fv].add(sv) ;\n// tree[sv].add(fv) ;\n// }\n// boolean[] visited = new boolean[n] ;\n// int ans = 0 ;\n// for(int i = 0 ; i < n ; i++)\n// {\n// if(!visited[i])\n// {\n// dfs(i , visited ) ;\n// ans++ ;\n// }\n// }\n\nlong n = scn.nextLong() ;\n\nlong a1 = scn.nextLong() ;long a2 = scn.nextLong() ;long a3 = scn.nextLong() ;\nlong b1 = scn.nextLong() ;long b2 = scn.nextLong() ;long b3 = scn.nextLong() ;\n\n\nlong min = 0L ;\n\nif(b1 >= a1+a2)\n{\n min = a3-b2-b3 ;\n}\n\nelse if(b2 >= a3+a2)\n{\n min = a1-b1-b3 ;\n}\n\nelse if(b3 >= a1+a3)\n{\n min =a2-b2-b1 ;\n}\n\n\nelse{\n min = 0 ;\n}\n\nlong max = Math.min(a1,b2) + Math.min(a2,b3) +Math.min(a3,b1) ;\n\n\nout.println(min+\" \" + max) ;\n\nsb.delete(0 , sb.length()) ;\nlist.clear() ;listb.clear() ;\nmap.clear() ;\nmap1.clear() ;\nmap2.clear() ;\nset.clear() ;sety.clear() ;\n\n} // test case end loop\n\n\nout.flush() ; \n} // solve fn ends\n\n\npublic static void main (String[] args) throws java.lang.Exception\n{\n \n\nsolve() ;\n \n}\n\n\n}\n \n class Pair \n{\n int first ;\n \n int second ;\n \n \n \n \n \n@Override\n\tpublic String toString() {\n\t\n\tString ans = \"\" ;\n\tans += this.first ;\n\tans += \" \";\n\tans += this.second ;\n\t\n\treturn ans ;\n\t}\n\n\n}\n", "lang_cluster": "Java", "tags": ["brute force", "constructive algorithms", "flows", "math", "greedy"], "code_uid": "01e32f6c525ab981fcfd1840319b26f0", "src_uid": "e6dc3bc64fc66b6127e2b32cacc06402", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class stock \n{\n\n public static void main(String[] args) \n {\n Scanner in = new Scanner(System.in);\n \n int n = in.nextInt();\n int m = in.nextInt();\n int r = in.nextInt();\n \n int[] by = new int[n];\n int[] sell = new int[m];\n \n for (int i = 0; i < by.length; i++)\n {\n by[i] = in.nextInt();\n }\n for (int i = 0; i < sell.length; i++)\n {\n sell[i] = in.nextInt();\n }\n Arrays.sort(by);\n Arrays.sort(sell);\n \n if (by[0] < sell[sell.length-1])\n {\n int bought = 0; \n while ((r - by[0]) >= 0)\n {\n r -= by[0];\n bought++;\n }\n while (bought > 0)\n {\n r += sell[sell.length-1];\n bought--;\n }\n }\n System.out.println(r);\n }\n \n}\n", "lang_cluster": "Java", "tags": ["greedy", "implementation"], "code_uid": "8eefc880bab605fd15dadc601efdd76d", "src_uid": "42f25d492bddc12d3d89d39315d63cb9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Lottery {\n public static void main(String[] args) {\n Scanner sc=new Scanner(System.in);\n int count = 0;\n int n=sc.nextInt();\n while (n > 0) {\n if (n % 100 == 0) {\n n = n - 100;\n count++;\n continue;\n }\n if (n % 20 == 0) {\n n = n - 20;\n count++;\n continue;\n }\n if (n % 10 == 0) {\n n = n - 10;\n count++;\n continue;\n }\n if (n % 5 == 0) {\n n = n - 5;\n count++;\n continue;\n }\n if(n%1==0){\n n=n-1;\n count++;\n continue;\n }\n }\n\n System.out.println(count);\n\n }\n}", "lang_cluster": "Java", "tags": ["greedy", "dp"], "code_uid": "091745f4b2c7360a7d9a9982c5aa7b00", "src_uid": "8e81ad7110552c20297f08ad3e5f8ddc", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.*;\n\npublic class TaskB {\n public static void main(String[] args) {\n new TaskB().solve();\n }\n\n TaskB() {\n }\n\n public void solve() {\n Scanner in = new Scanner(System.in);\n Long[] x = new Long[3];\n for (int i = 0; i < 3; ++i) x[i] = in.nextLong();\n long ans = x[0] / 3 + x[1] / 3 + x[2] / 3 +\n Math.min(x[0] % 3, Math.min(x[1] % 3, x[2] % 3));\n Arrays.sort(x, new Comparator() {\n @Override\n public int compare(Long o1, Long o2) {\n return o1 % 3 < o2 % 3 ? -1 : 1;\n }\n });\n if (x[0] / 3 >= 1 && x[0] % 3 == 0 && x[1] % 3 == 2 && x[2] % 3 == 2) {\n ans += 1;\n }\n System.out.println(ans);\n }\n}\n\n", "lang_cluster": "Java", "tags": ["math", "combinatorics"], "code_uid": "16d3936eb998260b4eefcf1b7e7699d7", "src_uid": "acddc9b0db312b363910a84bd4f14d8e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.util.Collections;\nimport java.io.InputStream;\n\npublic class CF28 {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n solve(in, out);\n out.close();\n }\n \n\t public static void solve(InputReader in, PrintWriter out) \n\t {\n\t\t long n = in.nextInt();\n\t\t long k = in.nextInt();\n\t\t out.println(magic(n, k));\n\t\t \n\t }\n\t \n\t private static long magic(long n, long k) {\n\t\tif(k==1)\n\t\t{\n\t\t\treturn 1;\n\t\t}\n\t\tif(k>n)\n\t\t{\n\t\t\treturn 0;\n\t\t}\n\t\tif(k==2)\n\t\t{\n\t\t\treturn 1 + n*(n-1)/2;\n\t\t}\n\t\tif(k==3)\n\t\t{\n\t\t\treturn 1 + n*(n-1)/2 + n*(n-1)*(n-2)/3;\n\t\t}\n\t\tif(k==4)\n\t\t{\n\t\t\treturn 1 + n*(n-1)/2 + n*(n-1)*(n-2)/3 + n*(n-1)*(n-2)*(n-3)/24*9;\t\t\t\n\t\t}\n\t\treturn 0;\n\t\t\n\t}\n\n\tstatic class InputReader {\n\t public BufferedReader reader;\n\t public StringTokenizer tokenizer;\n\n\t public InputReader(InputStream stream) {\n\t reader = new BufferedReader(new InputStreamReader(stream), 32768);\n\t tokenizer = null;\n\t }\n\n\t public String next() {\n\t while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t try {\n\t tokenizer = new StringTokenizer(reader.readLine());\n\t } catch (IOException e) {\n\t throw new RuntimeException(e);\n\t }\n\t }\n\t return tokenizer.nextToken();\n\t }\n\n\t public int nextInt() {\n\t return Integer.parseInt(next());\n\t }\n\n\t }\n}\n", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics"], "code_uid": "2ee12a2c0a464ae9900c37f5e13b2ff6", "src_uid": "96d839dc2d038f8ae95fc47c217b2e2f", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF {\n\n\tint MAX = 110;\n\tboolean[][] f = new boolean[MAX * 2][MAX * 2];\n\tString move = \"UDLR\";\n\tint[] dx = { 0, 0, -1, 1 };\n\tint[] dy = { 1, -1, 0, 0 };\n\n\tvoid realSolve() {\n\t\tString s = in.next();\n\t\tint x = MAX, y = MAX;\n\t\tf[x][y] = true;\n\t\tfor (int i = 0; i < s.length(); i++) {\n\t\t\tchar c = s.charAt(i);\n\t\t\tint id = move.indexOf(c);\n\t\t\tx += dx[id];\n\t\t\ty += dy[id];\n\t\t\tf[x][y] = true;\n\t\t}\n\t\tint[][] len = new int[MAX * 2][MAX * 2];\n\t\tfor (int i = 0; i < len.length; i++)\n\t\t\tArrays.fill(len[i], Integer.MAX_VALUE / 2);\n\t\tlen[MAX][MAX] = 0;\n\t\tint it = 0;\n\t\tArrayList qx = new ArrayList<>();\n\t\tArrayList qy = new ArrayList<>();\n\t\tqx.add(MAX);\n\t\tqy.add(MAX);\n\t\twhile (it < qx.size()) {\n\t\t\tint cx = qx.get(it);\n\t\t\tint cy = qy.get(it++);\n\t\t\tfor (int i = 0; i < 4; i++) {\n\t\t\t\tint nx = cx + dx[i];\n\t\t\t\tint ny = cy + dy[i];\n\t\t\t\tif (f[nx][ny] && len[nx][ny] == Integer.MAX_VALUE / 2) {\n\t\t\t\t\tqx.add(nx);\n\t\t\t\t\tqy.add(ny);\n\t\t\t\t\tlen[nx][ny] = len[cx][cy] + 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(len[x][y] == s.length() ? \"OK\" : \"BUG\");\n\t}\n\n\tprivate class InputReader {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic InputReader(File f) {\n\t\t\ttry {\n\t\t\t\tbr = new BufferedReader(new FileReader(f));\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\n\t\tpublic InputReader(InputStream f) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(f));\n\t\t}\n\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreElements()) {\n\t\t\t\tString s;\n\t\t\t\ttry {\n\t\t\t\t\ts = br.readLine();\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\t\t\t\tif (s == null)\n\t\t\t\t\treturn null;\n\t\t\t\tst = new StringTokenizer(s);\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tboolean hasMoreElements() {\n\t\t\twhile (st == null || !st.hasMoreElements()) {\n\t\t\t\tString s;\n\t\t\t\ttry {\n\t\t\t\t\ts = br.readLine();\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tst = new StringTokenizer(s);\n\t\t\t}\n\t\t\treturn st.hasMoreElements();\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t}\n\n\tInputReader in;\n\tPrintWriter out;\n\n\tvoid solve() {\n\t\tin = new InputReader(new File(\"object.in\"));\n\t\ttry {\n\t\t\tout = new PrintWriter(new File(\"object.out\"));\n\t\t} catch (FileNotFoundException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\n\t\trealSolve();\n\n\t\tout.close();\n\t}\n\n\tvoid solveIO() {\n\t\tin = new InputReader(System.in);\n\t\tout = new PrintWriter(System.out);\n\n\t\trealSolve();\n\n\t\tout.close();\n\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew CF().solveIO();\n\t}\n}", "lang_cluster": "Java", "tags": ["constructive algorithms", "implementation", "graphs"], "code_uid": "2b7237881f0c8a190db2f20c9ec81eae", "src_uid": "bb7805cc9d1cc907b64371b209c564b3", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.*;\n\npublic class Main\n{\n\tpublic static void main(String args[])\n\t{\n\t\tScanner in = new Scanner(System.in);\n\t\twhile(in.hasNext())\n\t\t{\n\t\t\tint plate = in.nextInt();\n\t\t\tint table = in.nextInt();\n\t\t\tint pRad = in.nextInt();\n\t\t\t\n\t\t\t\n\t\t\tif(plate==1)\n\t\t\t{\n\t\t\t\tif(table>=pRad)\n\t\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\telse\n\t\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tdouble theta1 = Math.toRadians(180.0/plate);\n\t\t\t\t\n\t\t\t\tdouble ans = pRad/Math.sin(theta1) + pRad;\n\t\t\t\t//System.out.println(\"TEST: \" + ans);\n\t\t\t\tif(table>ans || Math.abs(ans-table)<0.0000001)\n\t\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\telse\n\t\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t}\n\t\t}\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "geometry"], "code_uid": "246b3a598243ad2e67a0587e1eecbb96", "src_uid": "2fedbfccd893cde8f2fab2b5bf6fb6f6", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\npublic class Temp3 {\n\tpublic static void main(String[] args) throws Throwable {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tint[][] arr = new int[5][5];\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\t\tfor (int j = 0; j < arr.length; j++) {\n\t\t\t\tarr[i][j] = Integer.parseInt(st.nextToken());\n\t\t\t}\n\t\t}\n\t\tlong ans = 0;\n\t\tfor (int a = 0; a < 5; a++) \n\t\t{\n\t\t\tfor (int b = 0; b < 5; b++)\n\t\t\t{\n\t\t\t\tif(b==a )\n\t\t\t\t\tcontinue;\n\t\t\t\tfor (int c = 0; c < 5; c++) \n\t\t\t\t{\n\t\t\t\t\tif(c==a || c==b )\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tfor (int d = 0; d < 5; d++)\n\t\t\t\t\t{\n\t\t\t\t\t\tif(d==a || d==b || d==c )\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\tfor (int e = 0; e < 5; e++) \n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif(e==a || e==b || e==c || e==d )\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\tlong cur = arr[a][b] + arr[b][a] + arr[c][d] + arr[d][c];\n\t\t\t\t\t\t\t\t cur+= arr[b][c] + arr[c][b] + arr[d][e] + arr[e][d];\n\t\t\t\t\t\t\t\t cur+= arr[d][c] + arr[c][d];\n\t\t\t\t\t\t\t\t cur+= arr[e][d] + arr[d][e];\n\t\t\t\t\t\t\tans = Math.max(ans, cur);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}\n", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "4c82f84bb04eecfb71da878b973f0c1d", "src_uid": "be6d4df20e9a48d183dd8f34531df246", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Set;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.FileNotFoundException;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author /\\\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n Scanner in = new Scanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n CPrimesAndMultiplication solver = new CPrimesAndMultiplication();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class CPrimesAndMultiplication {\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n int MOD = (int) 1e9 + 7;\n long x = in.nextLong();\n long n = in.nextLong();\n Set primes = primeFactors(x);\n long fin = 1;\n for (long p : primes) {\n long facs = all(p, n);\n fin *= power(p, facs, MOD);\n fin %= MOD;\n }\n out.println((fin + MOD) % MOD);\n }\n\n static long all(long p, long n) {\n long pow = p;\n long res = 0;\n while (n >= pow) {\n// long temp = (long) Math.pow(p, pow);\n res += n / pow;\n if (pow > (long) 1e18 / p) {\n break;\n }\n pow *= p;\n }\n return res;\n }\n\n static Set primeFactors(long n) {\n Set factors = new HashSet<>();\n while (n % 2 == 0) {\n factors.add((long) 2);\n n /= 2;\n }\n for (long i = 3; i <= Math.sqrt(n); i += 2) {\n while (n % i == 0) {\n factors.add(i);\n n /= i;\n }\n }\n if (n > 2) {\n factors.add(n);\n }\n return factors;\n }\n\n static long power(long x, long y, int p) {\n long res = 1;\n x %= p;\n\n while (y > 0) {\n if ((y & 1) == 1) {\n res = (res * x) % p;\n }\n y = y >> 1;\n x = (x * x) % p;\n }\n return res;\n }\n\n }\n\n static class Scanner {\n private StringTokenizer st;\n private BufferedReader br;\n\n public Scanner(InputStream s) {\n br = new BufferedReader(new InputStreamReader(s));\n }\n\n public Scanner(String s) {\n try {\n br = new BufferedReader(new FileReader(s));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n\n public String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["math", "number theory"], "code_uid": "bda08aa64842796659d5cfc42bc1bdd2", "src_uid": "04610fbaa746c083dda30e21fa6e1a0c", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tFastScanner sc = new FastScanner();\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\twhile (sc.hasNext()) {\n\t\t\tlong m=sc.nextInt();\n\t\t\tlong b=sc.nextInt();\n\t\t\tlong sum=-1;\n\t\t\tfor(int i=0;i<=m*b;i++){\n\t\t\t\tlong x=i;\n\t\t\t\tlong y=(long) (-i*1.0/m+b);\n\t\t\t\tlong res=(x+1)*(((y+1)*y)/2)+(y+1)*(((x+1)*x)/2);\n\t\t\t\tsum=Math.max(sum,res);\n\t\t\t}\n\t\t\tfor(int j=0;j<=b;j++){\n\t\t\t\tlong x=b*m-m*j;\n\t\t\t\tlong y=j;\n\t\t\t\tlong res=(x+1)*(y+1)*y/2+(y+1)*((x+1)*x/2);\n\t\t\t\tsum=Math.max(sum,res);\n\t\t\t}\n\t\t\tpw.println((long)sum);\n\t\t\tpw.flush();\n\t\t}\n\t}\n}\nclass FastScanner {\n\tBufferedReader br;\n\tStringTokenizer st;\n\n\tpublic FastScanner() {\n\t\ttry {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tst = new StringTokenizer(\"\");\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\n\tpublic boolean hasNext() {\n\t\twhile (!st.hasMoreTokens()) {\n\t\t\tString line = nextLine();\n\t\t\tif (line == null) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tst = new StringTokenizer(line);\n\t\t}\n\t\treturn true;\n\t}\n\n\tpublic String next() {\n\t\twhile(!st.hasMoreTokens()){\n\t\t\tst=new StringTokenizer(nextLine());\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tpublic int nextInt() {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tpublic long nextLong() {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tpublic double nextDouble() {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tpublic String nextLine() {\n\t\tString line = \"\";\n\t\ttry {\n\t\t\tline = br.readLine();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t\treturn line;\n\t}\n}", "lang_cluster": "Java", "tags": ["brute force", "math"], "code_uid": "1dc5ab8369c9e76fc77818947fe87fea", "src_uid": "9300f1c07dd36e0cf7e6cb7911df4cf2", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Question1{\n\tstatic class InputReader {\n\t\tpublic BufferedReader reader;\n\t\t\tpublic StringTokenizer tokenizer;\n\n\t\t\tpublic InputReader() {\n\t\t\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t\ttokenizer = null;\n\t\t\t}\n\n\t\t\tpublic String next() {\n\t\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t\t} catch (IOException e) {\n\t\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn tokenizer.nextToken();\n\t\t\t}\n\n\t\t\tpublic int nextInt() {\n\t\t\t\treturn Integer.parseInt(next());\n\t\t\t}\n\n\t\t\tpublic long nextLong() {\n\t\t\t\treturn Long.parseLong(next());\n\t\t\t}\n\n\t\t\tpublic double nextDouble() {\n\t\t\t\treturn Double.parseDouble(next());\n\t\t\t}\n\n\t\t\tpublic String nextLine() {\n\t\t\t\tString s = null;\n\t\t\t\ttry {\n\t\t\t\t\ts = reader.readLine();\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t\treturn s;\n\t\t\t}\n\n\t\t\tpublic String nextParagraph() {\n\t\t\t\tString line = null;\n\t\t\t\tString ans = \"\";\n\t\t\t\ttry {\n\t\t\t\t\twhile ((line = reader.readLine()) != null) {\n\t\t\t\t\t\tans += line;\n\t\t\t\t\t}\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t\treturn ans;\n\t\t\t}\n\n\t\t}\n\n\tpublic static void main(String args[]){\n\t\tInputReader sc=new InputReader();\n\t\tPrintWriter pw=new PrintWriter(System.out);\n\t\tint c=sc.nextInt();\n\t\tint v0=sc.nextInt();\n\t\tint v1=sc.nextInt();\n\t\tint a=sc.nextInt();\n\t\tint l=sc.nextInt();\n\t\tint count=1;\n\t\tint pages=v0;\n\t\twhile(pagesv1){\n\t\t\t\ttoAdd=v1;\n\t\t\t}\n\t\t\tpages+=(toAdd-l);\n\t\t\tcount++;\n\t\t}\n\t\tpw.println(count);\n\t\tpw.close();\n\t}\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "64bcda8052ce77690019680d9c1cf37e", "src_uid": "b743110117ce13e2090367fd038d3b50", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class A151 {\n\n\tpublic static void main(String[] args) \n\t{\n\t\tScanner s = new Scanner(System.in);\n\t\tint n = s.nextInt(), l = s.nextInt() * s.nextInt(), d = s.nextInt() * s.nextInt(), p = s.nextInt(), \n\t\t\t\tnl = n * s.nextInt(), nd = n, np = n * s.nextInt();\n\t\tint[] c = new int[3];\n\t\tc[0] = l / nl;\n\t\tc[1] = d / nd;\n\t\tc[2] = p / np;\n\t\tArrays.sort(c);\n\t\tSystem.out.println(c[0]);\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "58f77ce882890d28e68282c852f60b2b", "src_uid": "67410b7d36b9d2e6a97ca5c7cff317c1", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\n/**\n * @author sadasidha\n * @since 2/10/16\n */\npublic class P622B {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n\n String str = sc.next();\n String[] strings = str.split(\":\");\n int hour = Integer.parseInt(strings[0]);\n int minute = Integer.parseInt(strings[1]);\n int time = (hour*60 + minute + sc.nextInt())%(24*60);\n hour = time/60;\n minute = time%60;\n if (hour < 10) {\n\n }\n System.out.println(hour/10+\"\"+hour%10 +\":\"+minute/10+\"\"+minute%10);\n }\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "9d034cbf26101098480686bdc82184fb", "src_uid": "20c2d9da12d6b88f300977d74287a15d", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\t\n\tprivate BufferedReader in;\n\tprivate PrintWriter out;\n\tprivate StringTokenizer st;\n\n\tvoid solve() throws IOException {\n\t\tint r1 = nextPos();\n\t\tint r2 = nextPos();\n\t\tint wk = nextPos();\n\t\tint bk = nextPos();\n\t\tint r1x = r1 / 8;\n\t\tint r1y = r1 % 8;\n\t\tint r2x = r2 / 8;\n\t\tint r2y = r2 % 8;\n\t\tint wkx = wk / 8;\n\t\tint wky = wk % 8;\n\t\tint bkx = bk / 8;\n\t\tint bky = bk % 8;\n\t\tfor (int dx = -1; dx <= 1; ++dx) {\n\t\t\tfor (int dy = -1; dy <= 1; ++dy) {\n\t\t\t\tint x = bkx + dx;\n\t\t\t\tint y = bky + dy;\n\t\t\t\tif (x >= 0 && x < 8 && y >= 0 && y < 8 &&\n\t\t\t\t\t(!attacks(r1x, r1y, wkx, wky, x, y) || x == r1x && y == r1y) &&\n\t\t\t\t\t(!attacks(r2x, r2y, wkx, wky, x, y) || x == r2x && y == r2y) &&\n\t\t\t\t\tMath.max(Math.abs(x - wkx), Math.abs(y - wky)) > 1) {\n\t\t\t\t\tout.println(\"OTHER\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(\"CHECKMATE\");\n\t}\n\n\tprivate boolean attacks(int rx, int ry, int wkx, int wky, int x, int y) {\n\t\tif (rx == x && (rx != wkx || wky < Math.min(y, ry) || wky > Math.max(y, ry))) {\n\t\t\treturn true;\n\t\t}\n\t\tif (ry == y && (ry != wky || wkx < Math.min(x, rx) || wkx > Math.max(x, rx))) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\tprivate int nextPos() throws IOException {\n\t\tString s = next();\n\t\treturn (s.charAt(0) - 'a') * 8 + s.charAt(1) - '1';\n\t}\n\n\tSolution() throws IOException {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\teat(\"\");\n\t\t\n\t\tsolve();\n\t\t\n\t\tin.close();\n\t\tout.close();\n\t}\n\t\n\tprivate void eat(String str) {\n\t\tst = new StringTokenizer(str);\n\t}\n\t\n\tString next() throws IOException {\n\t\twhile (!st.hasMoreTokens()) {\n\t\t\tString line = in.readLine();\n\t\t\tif (line == null) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\teat(line);\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\t\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\t\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(next());\n\t}\n\t\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Solution();\n\t}\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "1fc8421780ca7f0533f83be48e7a8759", "src_uid": "5d05af36c7ccb0cd26a4ab45966b28a3", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.util.StringTokenizer;\nimport java.io.Writer;\nimport java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author zodiacLeo\n */\npublic class Main\n{\n public static void main(String[] args)\n {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastScanner in = new FastScanner(inputStream);\n FastPrinter out = new FastPrinter(outputStream);\n TaskA solver = new TaskA();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskA\n {\n public void solve(int testNumber, FastScanner in, FastPrinter out)\n {\n long x = in.nextLong();\n long y = in.nextLong();\n long L = lcm(x, y);\n\n long a = in.nextLong();\n long b = in.nextLong();\n long q1 = (a + L - 1) / L;\n long q2 = b / L;\n\n out.println(Math.max(0, (q2 - q1 + 1)));\n }\n\n private long lcm(long a, long b)\n {\n return a * b / gcd(a, b);\n }\n\n private long gcd(long a, long b)\n {\n return b == 0 ? a : gcd(b, a % b);\n }\n\n }\n\n static class FastScanner\n {\n public BufferedReader br;\n public StringTokenizer st;\n\n public FastScanner(InputStream is)\n {\n br = new BufferedReader(new InputStreamReader(is));\n }\n\n public FastScanner(File f)\n {\n try\n {\n br = new BufferedReader(new FileReader(f));\n } catch (FileNotFoundException e)\n {\n e.printStackTrace();\n }\n }\n\n public String next()\n {\n while (st == null || !st.hasMoreElements())\n {\n String s = null;\n try\n {\n s = br.readLine();\n } catch (IOException e)\n {\n e.printStackTrace();\n }\n if (s == null)\n return null;\n st = new StringTokenizer(s);\n }\n return st.nextToken();\n }\n\n public long nextLong()\n {\n return Long.parseLong(next());\n }\n\n }\n\n static class FastPrinter extends PrintWriter\n {\n public FastPrinter(OutputStream out)\n {\n super(out);\n }\n\n public FastPrinter(Writer out)\n {\n super(out);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "b24676171e4ed9aadb2616e757eee405", "src_uid": "c7aa8a95d5f8832015853cffa1374c48", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n//\tstatic Scanner in;\n\tstatic PrintWriter out;\n\tstatic StreamTokenizer in; static int next() throws Exception {in.nextToken(); return (int) in.nval;}\n\n\tpublic static void main(String[] args) throws Exception {\n//\t\tin = new Scanner(System.in);\n\t\tout = new PrintWriter(System.out);\n\t\tin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n\n\t\tint x = next();\n\t\tint y = next();\n\n\t\tint rr = x*x + y*y;\n\t\tint r = 0;\n\t\twhile ((r+1)*(r+1) <= rr) r++;\n\t\tif (r*r == rr || x*y == 0) out.println(\"black\");\n\t\telse if (r % 2 == 0 ^ x*y < 0) out.println(\"black\");\n\t\telse out.println(\"white\");\n\n\t\tout.close();\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "geometry", "constructive algorithms", "implementation"], "code_uid": "77e31368df2aaf21e401561a63d81398", "src_uid": "8c92aac1bef5822848a136a1328346c6", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\npublic class Main {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n Solver s = new Solver();\n s.solve(in, out);\n out.close();\n }\n static class Solver {\n public void solve(Scanner in, PrintWriter out) {\n int n = in.nextInt();\n int k = in.nextInt();\n int[] grades = new int[n];\n Arrays.fill(grades, 2);\n k -= 2 * n;\n while (k > 0) {\n for (int i = 0; i < n && k > 0; ++i) {\n ++grades[i];\n --k;\n }\n }\n int tot = 0;\n for (int x : grades)\n if (x == 2)\n ++tot;\n out.println(tot);\n }\n }\n}", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "a8fa1b52f11cfe4dcc8523a36655b665", "src_uid": "5a5e46042c3f18529a03cb5c868df7e8", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n\npublic class CircleCenter {\n public static long numberOfSteps(int r, int x, int y, int xx, int yy) {\n long distance = (long)Math.ceil(getDistance(x, y, xx, yy));\n long rotations = distance / (2 * r);\n if(distance % (2 * r) != 0){\n rotations++;\n }\n return rotations;\n }\n \n public static double getDistance(long x, long y, long xx, long yy) {\n return Math.sqrt((xx - x) * (xx - x) + (yy - y) * (yy - y));\n }\n \n public static void main(String[] args) {\n BufferedReader scanner = new BufferedReader(new InputStreamReader(System.in));\n try {\n StringTokenizer tokenizer = new StringTokenizer(scanner.readLine());\n int r = Integer.parseInt(tokenizer.nextToken());\n int x = Integer.parseInt(tokenizer.nextToken());\n int y = Integer.parseInt(tokenizer.nextToken());\n int xx = Integer.parseInt(tokenizer.nextToken());\n int yy = Integer.parseInt(tokenizer.nextToken());\n \n System.out.println(numberOfSteps(r, x, y, xx, yy));\n \n } catch (IOException e) {\n // TODO Auto-generated catch block\n e.printStackTrace();\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "geometry"], "code_uid": "baa736a7f003273d821b44183c1c0afc", "src_uid": "698da80c7d24252b57cca4e4f0ca7031", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.*;\n\npublic class D{\n\tstatic final int MOD = 1000000009;\n\tstatic int increment(int last, int h){\n\t\tif (last == 0){\n\t\t\treturn 0;\n\t\t}\n\t\treturn (last + 1)%h;\n\t}\n\tstatic int boolean2int(boolean in){\n\t\treturn in ? 1 : 0;\n\t}\n\tstatic int add(int a, int b){\n\t\treturn (a + b)%MOD;\n\t}\n\tpublic static void main(String [] args){\n\t\ttry (Scanner s = new Scanner(System.in)){\n\t\t\tfinal int n = s.nextInt();\n\t\t\tfinal int h = s.nextInt();\n\t\t\tfinal int [][][][][] dp = new int[2][2][32][32][32];\n\t\t\tdp[1][1][0][0][0] = 4;\n\t\t\tint p = 1;\n\t\t\tfor (int i = 1; i <= n - 1; ++i){\n\t\t\t\tfinal int np = (p + 1)%2;\n\t\t\t\tfor (int alive = 0; alive <= 1; ++alive){\n\t\t\t\t\tfor (int last1 = 0; last1 < h; ++last1){\n\t\t\t\t\t\tfor (int last2 = 0; last2 < h; ++last2){\n\t\t\t\t\t\t\tfor (int last3 = 0; last3 < h; ++last3){\n\t\t\t\t\t\t\t\tfinal int a = increment(last1, h);\n\t\t\t\t\t\t\t\tfinal int b = increment(last2, h);\n\t\t\t\t\t\t\t\tfinal int c = increment(last3, h);\n\t\t\t\t\t\t\t\tfinal int alive1 = boolean2int(i < h || last1 > 0);\n\t\t\t\t\t\t\t\tfinal int alive2 = boolean2int(i < h || last2 > 0);\n\t\t\t\t\t\t\t\tfinal int alive3 = boolean2int(i < h || last3 > 0);\n\t\t\t\t\t\t\t\tdp[np][alive][a][b][c] = add(dp[np][alive][a][b][c], dp[p][alive][last1][last2][last3]);\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tdp[np][alive1][alive][b][c] = add(dp[np][alive1][alive][b][c], dp[p][alive][last1][last2][last3]);\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tdp[np][alive2][a][alive][c] = add(dp[np][alive2][a][alive][c], dp[p][alive][last1][last2][last3]);\n\t\t\t\t\t\t\t\tdp[np][alive3][a][b][alive] = add(dp[np][alive3][a][b][alive], dp[p][alive][last1][last2][last3]);\t\t\t\t\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor (int alive = 0; alive <= 1; ++alive){\n\t\t\t\t\tfor (int last1 = 0; last1 < h; ++last1){\n\t\t\t\t\t\tfor (int last2 = 0; last2 < h; ++last2){\n\t\t\t\t\t\t\tfor (int last3 = 0; last3 < h; ++last3){\n\t\t\t\t\t\t\t\tdp[p][alive][last1][last2][last3] = 0;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tp = np;\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tfor (int last1 = 0; last1 < h; ++last1){\n\t\t\t\tfor (int last2 = 0; last2 < h; ++last2){\n\t\t\t\t\tfor (int last3 = 0; last3 < h; ++last3){\n\t\t\t\t\t\tres = add(res, dp[p][1][last1][last2][last3]);\n\t\t\t\t\t\tif (last1 + last2 + last3 > 0){\n\t\t\t\t\t\t\tres = add(res, dp[p][0][last1][last2][last3]);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tSystem.out.println(res);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "tags": ["dp"], "code_uid": "6ac81a069dfeba7cd81386072506ec45", "src_uid": "9fe9658db35076c0bddc8b7ddce11013", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.Scanner;\nimport java.util.TreeMap;\n\npublic class ProblemC {\n\tstatic int callCount = 0;\n\tpublic static void main(String[] args) {\n\t\tScanner input = new Scanner(System.in);\n\t\tlong m = input.nextLong();\n\t\tArrayList getCubes = getCubes();\n\t\tSystem.out.println(solve(m, getCubes));\n//\t\tSystem.out.println(callCount);\n\t}\n\tpublic static Answer solve(long m, ArrayList cubes){\n\t\tcallCount++;\n//\t\tSystem.out.println(m + \" solve called \");\n\t\tif(m < 8){\n//\t\t\tSystem.out.println(m + \" solve finished \" + new Answer(m, m));\n\t\t\treturn new Answer(m, m);\n\t\t}\n\t\tint maxIdx = (int)(Math.pow(m, 1.0/3.0)+1E-9);\n\t\t\n\t\tAnswer ans1 = solve(m-cubes.get(maxIdx), cubes);\n\t\tans1.n += cubes.get(maxIdx);\n\t\tans1.x += 1;\n\t\t\n\t\tAnswer ans2 = solve(cubes.get(maxIdx)-cubes.get(maxIdx-1)-1, cubes);\n\t\tans2.n += cubes.get(maxIdx-1);\n\t\tans2.x += 1;\n\t\tAnswer bestAnswer = best(ans1, ans2);\n//\t\tSystem.out.println(m + \" solve finished \" + bestAnswer);\n\t\treturn bestAnswer;\n\t}\n\t\n\n\tprivate static Answer best(Answer ans1, Answer ans2) {\n\t\tif(ans1.x == ans2.x){\n\t\t\tif(ans1.n > ans2.n){\n\t\t\t\treturn ans1;\n\t\t\t}\n\t\t\telse{\n\t\t\t\treturn ans2;\n\t\t\t}\n\t\t}\n\t\tif(ans1.x > ans2.x){\n\t\t\treturn ans1;\n\t\t}\n\t\telse{\n\t\t\treturn ans2;\n\t\t}\n\t}\n\n\n\tpublic static class Answer{\n\t\tlong n;\n\t\tlong x;\n\t\tpublic Answer(long _n, long _x){\n\t\t\tn = _n;\n\t\t\tx = _x;\n\t\t}\n\t\tpublic String toString(){\n\t\t\treturn x + \" \" + n;\n\t\t}\n\t}\n\n\tprivate static ArrayList getCubes() {\n\t\tArrayList cubes = new ArrayList();\n\t\tfor (long a = 0; a < 500000; a++) {\n\t\t\tcubes.add(a * a * a);\n\t\t}\n\t\treturn cubes;\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["brute force", "greedy", "constructive algorithms", "binary search"], "code_uid": "66b8bb0c3248556c0f056fc2ddc1aa58", "src_uid": "385cf3c40c96f0879788b766eeb25139", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.Scanner;\nimport java.io.PrintWriter;\n\n/**\n * New topic learned:\n * - Goldbach's Conjecture\n */\npublic class Code_735D_Taxes{\n public static void main(String args[]){\n Scanner in=new Scanner(System.in);\n PrintWriter out=new PrintWriter(System.out);\n\n long n=in.nextLong();\n if(n==2)out.print(1);\n else if(n%2==0)out.print(2);\n else{\n if(isPrime(n))out.print(1);\n else if(isPrime(n-2))out.print(2);\n else out.print(3);\n }\n\n out.close();\n }\n public static boolean isPrime(long n){\n long limit=(long)Math.sqrt(n);\n for(long i=3;i<=limit;i+=2)\n if(n%i==0)\n return false;\n return true;\n }\n}", "lang_cluster": "Java", "tags": ["math", "number theory"], "code_uid": "4052a1bea77f27deb9e96055b9e45e20", "src_uid": "684ce84149d6a5f4776ecd1ea6cb455b", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\n import java.util.*;\n \n \n public class Solution {\n public static void main(String[] args) throws Exception{\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter out = new PrintWriter(System.out);\n StringTokenizer st = new StringTokenizer(br.readLine());\n int t = Integer.parseInt(st.nextToken());\n \n while(t > 0){\n st = new StringTokenizer(br.readLine());\n int n = Integer.parseInt(st.nextToken());\n int k = Integer.parseInt(st.nextToken());\n int l = Integer.parseInt(st.nextToken());\n \n int[] tide = new int[2*k];\n for(int i=1;i<=k;i++) tide[i] =tide[i-1]+1;\n \n for(int i=k+1;i l) continue;\n \n dp[i][j] = (j == 0) ? dp[i-1][2*k-1] : (dp[i-1][j-1] || dp[i][j-1]);\n }\n //Arrays.stream(dp).forEach(e->System.out.println(Arrays.toString(e)));\n boolean possible = false;\n for(int j=0;j<2*k;j++) {\n if(dp[n-1][j]){\n possible = true;\n break;\n }\n }\n if(possible) out.println(\"YES\");\n else out.println(\"NO\");\n }\n out.close();\n }\n }", "lang_cluster": "Java", "tags": ["brute force", "greedy", "dp"], "code_uid": "23e42d574f2952c9e568d04bb15c6c42", "src_uid": "4941b0a365f86b2e2cf686cdf5d532f8", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.util.regex.Pattern;\n\npublic class C {\n public static void main(String[] args) {\n FastScanner fs = new FastScanner();\n BigInteger n=BigInteger.valueOf(fs.nextLong());\n BigInteger m =BigInteger.valueOf(fs.nextLong());\n BigInteger r = BigInteger.valueOf(3).modPow(n, m).subtract(BigInteger.ONE.mod(m)).mod(m);\n System.out.println(r);\n }\n\n static long gcd(long a, long b) {\n if (b == 0) return a;\n return gcd(b, a % b);\n }\n\n public static class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "3c08941355e9c3319f475ec268aa4642", "src_uid": "c62ad7c7d1ea7aec058d99223c57d33c", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.lang.*;\n \nimport static java.lang.Math.*;\n \npublic class Cf182 implements Runnable \n{\n\tstatic class InputReader \n\t{\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n\t\tprivate SpaceCharFilter filter;\n\t\tprivate BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tpublic InputReader(InputStream stream) \n\t\t{\n\t\t\tthis.stream = stream;\n\t\t}\n\t\t\n\t\tpublic int read()\n\t\t{\n\t\t\tif (numChars==-1) \n\t\t\t\tthrow new InputMismatchException();\n \n\t\t\tif (curChar >= numChars) \n\t\t\t{\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry\n\t\t\t\t{\n\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t}\n\t\t\t\tcatch (IOException e)\n\t\t\t\t{\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n \n\t\t\t\tif(numChars <= 0) \n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n \n\t\tpublic String nextLine()\n\t\t{\n\t\t\tString str = \"\";\n\t\t\ttry\n\t\t\t{\n\t\t\t\tstr = br.readLine();\n\t\t\t}\n\t\t\tcatch (IOException e)\n\t\t\t{\n\t\t\t\te.printStackTrace();\n\t\t\t}\t\n\t\t\treturn str;\n\t\t}\n\t\tpublic int nextInt() \n\t\t{\n\t\t\tint c = read();\n \n\t\t\twhile(isSpaceChar(c)) \n\t\t\t\tc = read();\n\t\t\n\t\t\tint sgn = 1;\n \n\t\t\tif (c == '-') \n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n \n\t\t\tint res = 0;\n\t\t\tdo\n\t\t\t{\n\t\t\t\tif(c<'0'||c>'9') \n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\twhile (!isSpaceChar(c)); \n \n\t\t\treturn res * sgn;\n\t\t}\n \n\t\tpublic long nextLong() \n\t\t{\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-')\n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\t\n\t\t\tdo \n\t\t\t{\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\t\n\t\t\twhile (!isSpaceChar(c));\n\t\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic double nextDouble() \n\t\t{\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-')\n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tdouble res = 0;\n\t\t\twhile (!isSpaceChar(c) && c != '.') \n\t\t\t{\n\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\treturn res * Math.pow(10, nextInt());\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tif (c == '.') \n\t\t\t{\n\t\t\t\tc = read();\n\t\t\t\tdouble m = 1;\n\t\t\t\twhile (!isSpaceChar(c))\n\t\t\t\t{\n\t\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\t\treturn res * Math.pow(10, nextInt());\n\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\tm /= 10;\n\t\t\t\t\tres += (c - '0') * m;\n\t\t\t\t\tc = read();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res * sgn;\n\t\t}\n \n\t\tpublic String readString() \n\t\t{\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo \n\t\t\t{\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} \n\t\t\twhile (!isSpaceChar(c));\n \n\t\t\treturn res.toString();\n\t\t}\n \n\t\tpublic boolean isSpaceChar(int c) \n\t\t{\n\t\t\tif (filter != null)\n\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n \n\t\tpublic String next()\n\t\t{\n\t\t\treturn readString();\n\t\t}\n \n\t\tpublic interface SpaceCharFilter\n\t\t{\n\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t}\n\tpublic static void main(String args[]) throws Exception \n\t{\n\t\tnew Thread(null, new Cf182(),\"Main\",1<<27).start();\n\t}\t\n\t\n\tpublic static long gcd(long a, long b) \n\t{ \n\t\tif (a == 0) \n\t\t\treturn b; \n\t\treturn gcd(b % a, a); \n\t} \n\t// array sorting by colm\npublic static void sortbyColumn(int arr[][], int col) \n { \n \n Arrays.sort(arr, new Comparator() { \n \n @Override\n public int compare(final int[] entry1, \n final int[] entry2) { \n \n \n if (entry1[col] > entry2[col]) \n return 1; \n else\n return -1; \n } \n }); \n } \n\t\n\t// gcd\n \n\tpublic static long findGCD(long arr[], int n) \n\t{ \n\t\tlong result = arr[0]; \n\t\tfor (int i = 1; i < n; i++) \n\t\t\tresult = gcd(arr[i], result); \n\t\treturn result; \n\t}\n\t// fibonaci\n\tstatic int fib(int n) \n { \n int a = 0, b = 1, c; \n if (n == 0) \n return a; \n for (int i = 2; i <= n; i++) \n { \n c = a + b; \n a = b; \n b = c; \n } \n return b; \n } \n \n// sort a string\n public static String sortString(String inputString) \n { \n \n char tempArray[] = inputString.toCharArray(); \n \n \n Arrays.sort(tempArray); \n \n \n return new String(tempArray); \n } \n // pair function\n \n // list.add(new Pair<>(sc.nextInt(), i + 1));\n // Collections.sort(list, (a, b) -> Integer.compare(b.first, a.first));\n private static class Pair {\n \n private F first;\n \n private S second;\n \n public Pair() {}\n \n public Pair(F first, S second) {\n this.first = first;\n this.second = second;\n }\n }\n \n\tpublic void run()\n\t{\n\t\tInputReader sc = new InputReader(System.in);\n\t\tPrintWriter w = new PrintWriter(System.out);\n\t\tString s[] = sc.nextLine().split(\"\\\\s+\");\n int a = Integer.parseInt((s[0]));\n int b = Integer.parseInt((s[1]));\n int c = Integer.parseInt((s[2]));\n \n for(int i = 1; i<=b; i++){\n if(a*10 / b == c){\n System.out.println((i));\n return;\n }\n a = (a*10) % b;\n }\n System.out.println(-1);\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "number theory"], "code_uid": "e2772518fbdd2d4893aee8cdb62f7199", "src_uid": "0bc7bf67b96e2898cfd8d129ad486910", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\npublic class Olymp_B {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n String value = \"\";\n String new_value = \"\";\n String numbers = \"0123456789\";\n value = scan.next();\n int start = value.length() - 1;\n while (start >= 0) {\n if (value.charAt(start) != '9') {\n break;\n }\n start--;\n }\n if (start <= 0) {\n System.out.println(value);\n return;\n }\n String[] answer = new String[start];\n for (int i = start - 1; i >= 0; i--) {\n answer[i] = value.substring(0, i);\n if (numbers.charAt(numbers.indexOf(value.charAt(i))) != '0') {\n if (numbers.charAt(numbers.indexOf(value.charAt(i)) - 1) != '0') {\n answer[i] += numbers.charAt(numbers.indexOf(value.charAt(i)) - 1);\n }\n }\n for (int j = i + 1; j < value.length(); j++) {\n answer[i] += \"9\";\n }\n }\n int sum = 0;\n for (int i = 0; i < value.length(); i++) {\n sum += numbers.indexOf(value.charAt(i));\n }\n int _sum = 0;\n int max_sum = 0;\n int max_index = -1;\n for (int i = 0; i < answer.length; i++) {\n _sum = 0;\n for (int j = 0; j < answer[i].length(); j++) {\n _sum += numbers.indexOf(answer[i].charAt(j));\n }\n if (_sum > sum) {\n if (_sum >= max_sum) {\n max_sum = _sum;\n max_index = i;\n }\n }\n }\n if (max_index >= 0) {\n System.out.println(answer[max_index]);\n } else {\n System.out.println(value);\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "148f159c8aa010ed7f5afcbd030d12e0", "src_uid": "e55b0debbf33c266091e6634494356b8", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\t\n\tstatic int mod = 1000000007 ;\n\t\n\tstatic long modPow(long a,long e)\n\t{\n\t\ta %= mod;\n\t\tlong res = 1;\n\t\twhile(e > 0)\n\t\t{\n\t\t\tif((e & 1) == 1)\n\t\t\t\tres = (res * a) % mod;\n\t\t\ta = (a * a) % mod;\n\t\t\te >>= 1;\n\t\t}\n\t\treturn res;\n\t}\n\t\n\tpublic static void main(String[] args) throws Throwable {\n\t\tScanner sc = new Scanner(System.in);\n\t\tchar[] a = sc.nextLine().toCharArray();\n\t\tint n = a.length;\n\t\tlong ans = 0;\n\t\tfor(int i = 0;i data = new ArrayList<>();\n kaaveh in = new kaaveh();\n\n System.out.print((char) System.in.read());\n System.in.read();\n\n while(true){\n tmp = (char) System.in.read();\n if (tmp == 'e'){\n break;\n } else {\n data.add(tmp);\n }\n }\n\n num = in.kint();\n zero =num - data.size();\n if (num > data.size())\n num = data.size();\n for (int i=0; i 0){\n System.out.print('0');\n zero--;\n }\n }\n}\n\nclass kaaveh {\n static String kLine(int maxLg) {\n byte lin[] = new byte[maxLg];\n int lg = 0, car = -1;\n String line = \"\";\n\n try {\n while (lg < maxLg) {\n car = System.in.read();\n if ((car < 0) || (car == '\\n') || (car == '\\r')) break;\n lin[lg++] += car;\n }\n } catch (IOException e) {\n return (null);\n }\n\n if ((car < 0) && (lg == 0)) return (null); // eof\n return (new String(lin, 0, lg));\n }\n\n static String knex(int maxLg) {\n byte lin[] = new byte[maxLg];\n int lg = 0, car = -1;\n String line = \"\";\n\n try {\n\n while ((car < 0) || (car == '\\n') || (car == ' ') || (car == '\\t') || (car == '\\r'))\n car = System.in.read();\n\n while (lg < maxLg) {\n if ((car < 0) || (car == '\\n') || (car == ' ') || (car == '\\t') || (car == '\\r')) break;\n lin[lg++] += car;\n car = System.in.read();\n }\n } catch (IOException e) {\n return (null);\n }\n\n if ((car < 0) && (lg == 0)) return (null); // eof\n return (new String(lin, 0, lg));\n }\n\n static int kint() {\n return Integer.parseInt(knex(11));\n }\n\n static long kLong() {\n return Long.parseLong(knex(20));\n }\n\n static double kdouble() {\n return Double.parseDouble(knex(100));\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "math", "strings", "implementation"], "code_uid": "28edecddfde5fe488a99740254e4b6bc", "src_uid": "a79358099f08f3ec50c013d47d910eef", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\n// Problem : C. Candies\n// Contest : Codeforces Round #491 (Div. 2)\n// URL : https://codeforces.com/contest/991/problem/C\n// Memory Limit : 256 MB\n// Time Limit : 1000 ms\n// Powered by CP Editor (https://github.com/cpeditor/cpeditor)\n\nimport java.io.*;\nimport java.util.*;\n\npublic class a {\n\n\tpublic static void main(String[] args) {\n\t\tFastReader scan = new FastReader();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tTask solver = new Task();\n\t\t//int t = scan.nextInt();\n\t\tint t = 1;\n\t\tfor(int i = 1; i <= t; i++) solver.solve(i, scan, out);\n\t\tout.close();\n\t}\n\n\tstatic class Task {\n\t\tlong m;\n\t\tpublic void solve(int testNumber, FastReader sc, PrintWriter pw) {\n\t\t\tm = sc.nextLong();\n\t\t\tlong ans = 0;\n\t\t\t\tlong lo = 1, hi = m;\n\t\t\t for(int i=0;i<66;i++) {\n\t\t\t long mid = (lo+hi)/2;\n\t\t\t if (get(mid)) {\n\t\t\t hi = mid;\n\t\t\t } else {\n\t\t\t lo = mid+1;\n\t\t\t }\n\t\t\t }\n\t\t\t if (get(Long.min(lo, hi))) {\n\t\t\t ans= Long.min(lo, hi);\n\t\t\t } else {\n\t\t\t ans= Long.max(lo, hi);\n\t\t\t }\n\t\t\t pw.println(ans);\n\t\t}\n\t\tpublic boolean get(long a){\n\t\t\tlong c = m;\n\t\t\tlong sum = 0;\n\t\t\tlong sum2 = 0;\n\t\t\twhile(c>0){\n\t\t\t\tsum+=Math.min(a,c);\n\t\t\t\tc-=Math.min(a,c);\n\t\t\t\tsum2+=c/10;\n\t\t\t\tc-=c/10;\n\t\t\t\t//System.out.println(a+\" \"+sum+\" \"+c);\n\t\t\t}\n\t\t\treturn(sum>=sum2);\n\t\t}\n\t\t\n\t}\n\n\tstatic void shuffle(int[] a) {\n\t\tRandom get = new Random();\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tint r = get.nextInt(a.length);\n\t\t\tint temp = a[i];\n\t\t\ta[i] = a[r];\n\t\t\ta[r] = temp;\n\t\t}\n\t}\n\n\tstatic void shuffle(long[] a) {\n\t\tRandom get = new Random();\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tint r = get.nextInt(a.length);\n\t\t\tlong temp = a[i];\n\t\t\ta[i] = a[r];\n\t\t\ta[r] = temp;\n\t\t}\n\t}\n\n\tstatic class FastReader {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastReader() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tpublic FastReader(String s) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(new File(s)));\n\t\t}\n\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreElements()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tString nextLine() {\n\t\t\tString str = \"\";\n\t\t\ttry {\n\t\t\t\tstr = br.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\t}\n\n}", "lang_cluster": "Java", "tags": ["implementation", "binary search"], "code_uid": "11c72b8bb43231d206cee466fedeb7ce", "src_uid": "db1a50da538fa82038f8db6104d2ab93", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class D implements Runnable {\n\tprivate InputReader in;\n\tprivate PrintWriter out;\n\tprivate static final int MAX = 5000+5;\n\n\tpublic static void main(String[] args) {\n\t\tnew D().run();\n\t}\n\n\tpublic D() {\n\t\tin = new InputReader(System.in);\n\t\tout = new PrintWriter(System.out);\n\t}\n\t\n\tstatic int MOD = 100000000;\n\t\n\tint[][][] mem = new int[101][101][21];\n\t\n\tprivate int f(int x, int y, int a) {\n\t if (mem[x][y][10+a] != -1)\n\t return mem[x][y][10+a];\n\t int sum;\n if (a > 0) {\n if (y == 0)\n return a == x ? 1 : 0;\n sum = 0;\n for (int i = 1; i < Math.min(k2, y)+1; i++)\n sum = (sum + (f(x-a, y, -i))) % MOD;\n return mem[x][y][10+a] = sum;\n }\n if (a < 0) {\n a = -a;\n if (x == 0)\n return a == y ? 1 : 0;\n sum = 0;\n for (int i = 1; i < Math.min(k1, x)+1; i++)\n sum = (sum + (f(x, y-a, i))) % MOD;\n return mem[x][y][10-a] = sum;\n }\n return 0;\n\t}\n\t\n\tint n1, n2, k1, k2;\n\t\n\tpublic void run() {\n\t for (int i = 0; i <= 100; i++)\n\t for (int j = 0; j <= 100; j++)\n\t for (int k = 0; k <= 20; k++)\n \t mem[i][j][k] = -1;\n\t n1 = in.readInt();\n\t n2 = in.readInt();\n\t k1 = in.readInt();\n\t k2 = in.readInt();\n\t int sum = 0;\n\t for (int a = 1; a <= Math.min(n1, k1); a++)\n\t sum = (sum + f(n1, n2, a)) % MOD;\n\t for (int a = 1; a <= Math.min(n2, k2); a++)\n\t sum = (sum + f(n1, n2, -a)) % MOD;\n\t out.println(sum);\n\t out.close();\n\t}\n\t\n\tprivate static class InputReader {\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[1000];\n\t\tprivate int curChar, numChars;\n\n\t\tpublic InputReader(InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n\n\t\tprivate int read() {\n\t\t\tif (numChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= numChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (numChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\t\tpublic int readInt() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic long readLong() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic String readString() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuffer res = new StringBuffer();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tprivate boolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tprivate String readLine0() {\n\t\t\tStringBuffer buf = new StringBuffer();\n\t\t\tint c = read();\n\t\t\twhile (c != '\\n' && c != -1) {\n\t\t\t\tbuf.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\treturn buf.toString();\n\t\t}\n\n\t\tpublic String readLine() {\n\t\t\tString s = readLine0();\n\t\t\twhile (s.trim().length() == 0)\n\t\t\t\ts = readLine0();\n\t\t\treturn s;\n\t\t}\n\n\t\tpublic String readLine(boolean ignoreEmptyLines) {\n\t\t\tif (ignoreEmptyLines)\n\t\t\t\treturn readLine();\n\t\t\telse\n\t\t\t\treturn readLine0();\n\t\t}\n\n\t\tpublic BigInteger readBigInteger() {\n\t\t\ttry {\n\t\t\t\treturn new BigInteger(readString());\n\t\t\t} catch (NumberFormatException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t}\n\n\t\tpublic char readCharacter() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\treturn (char) c;\n\t\t}\n\n\t\tpublic double readDouble() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tdouble res = 0;\n\t\t\twhile (!isSpaceChar(c) && c != '.') {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tif (c == '.') {\n\t\t\t\tc = read();\n\t\t\t\tdouble m = 1;\n\t\t\t\twhile (!isSpaceChar(c)) {\n\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\tm /= 10;\n\t\t\t\t\tres += (c - '0') * m;\n\t\t\t\t\tc = read();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res * sgn;\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "tags": ["dp"], "code_uid": "fbf2f4ba03af5220c64c587a0d535da2", "src_uid": "63aabef26fe008e4c6fc9336eb038289", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class p712C\n{\n\n\tpublic static void main( String[] args )\n\t{\n\t\tScanner s = new Scanner( System.in );\n\n\t\tint y = s.nextInt(), x = s.nextInt();\n\n\t\ts.close();\n\n\t\tint[] sides = { x, x, x };\n\t\tint curSide = 0;\n\n\t\tint seconds = 0;\n\n\t\twhile ( sides[ 0 ] != y || sides[ 1 ] != y || sides[ 2 ] != y )\n\t\t{\n\t\t\tif ( sides[ curSide ] == y )\n\t\t\t{\n\t\t\t\tcurSide = ( curSide + 1 ) % 3;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tint a = sides[ ( curSide + 1 ) % 3 ], b = sides[ ( curSide + 2 ) % 3 ];\n\n\t\t\tint nonDegenLen = a + b - 1;\n\t\t\tsides[ curSide ] = Math.min( nonDegenLen, y );\n\n\t\t\tcurSide = ( curSide + 1 ) % 3;\n\t\t\tseconds++;\n\t\t}\n\n\t\tSystem.out.println( seconds++ );\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["math", "greedy"], "code_uid": "05af0f8512a76702af890686e07b0055", "src_uid": "8edf64f5838b19f9a8b19a14977f5615", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.Scanner;\n\npublic class x {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n // TODO code application logic here\n\n Scanner scanner = new Scanner(System.in);\n\n String bNumfNum = scanner.nextLine();\n String bNum = bNumfNum.split(\" \")[0];\n int fNum = Integer.parseInt(bNumfNum.split(\" \")[1]);\n\n String b = scanner.nextLine();\n\n Map myMap = new HashMap<>();\n for (int i = 0; i < Integer.parseInt(bNum); i++) \n {\n String c = Character.toString(b.charAt(i));\n if (myMap.containsKey(c)) \n {\n myMap.put(c, myMap.get(c) + 1);\n } \n else \n {\n myMap.put(c, 1);\n }\n }\n boolean flag = true;\n for (Map.Entry entry : myMap.entrySet()) \n {\n if (entry.getValue() > fNum) \n {\n flag = false;\n }\n }\n if(flag)\n {\n System.out.println(\"YES\");\n }\n else\n {\n System.out.println(\"NO\");\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "d59d88c97445a5752bdfcfef34ce1bf4", "src_uid": "ceb3807aaffef60bcdbcc9a17a1391be", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class Solution758D {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer tokenizer = null;\n //Solution758A Code starts Here\n int totalCases, testnum;\n\n long n;\n String s;\n\n boolean input() throws IOException {\n n = nl();\n s = ns().trim();\n return true;\n }\n\n void solve() throws IOException {\n int log10n = (int) Math.log10(n);\n int l = s.length();\n int a = l-1, b = l;\n long m = 1;\n long ret = 0;\n while(b > 0) {\n while (a > -1 && (b-a-1) <= log10n) {\n String str = s.substring(a, b);\n long acc = Long.parseLong(str);\n if (acc >= n) {\n break;\n } else {\n a--;\n }\n }\n a++;\n while(s.charAt(a) == '0' && a < b-1 && a < l-1) a++;\n long acc = Long.parseLong(s.substring(a, b));\n ret += (acc * m);\n m*=n;\n b=a--;\n }\n System.out.println(ret);\n }\n\n public static void main(String[] args) throws IOException {\n new Solution758D().execute();\n }\n\n void execute() throws IOException {\n totalCases = 1;\n for (testnum = 1; testnum <= totalCases; testnum++) {\n if (!input())\n break;\n solve();\n }\n }\n\n void debug(Object... os) {\n System.out.println(Arrays.deepToString(os));\n }\n\n int ni() throws IOException {\n return Integer.parseInt(ns());\n }\n\n long nl() throws IOException {\n return Long.parseLong(ns());\n }\n\n double nd() throws IOException {\n return Double.parseDouble(ns());\n }\n\n String ns() throws IOException {\n while (tokenizer == null || !tokenizer.hasMoreTokens())\n tokenizer = new StringTokenizer(br.readLine());\n String s = tokenizer.nextToken();\n return s;\n }\n\n String nline() throws IOException {\n tokenizer = null;\n return br.readLine();\n }\n}", "lang_cluster": "Java", "tags": ["constructive algorithms", "math", "dp", "greedy", "strings"], "code_uid": "e44ac3c392b7255770f59e90fc62f758", "src_uid": "be66399c558c96566a6bb0a63d2503e5", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "//package com.company;\nimport java.io.*;\npublic class Main {\n public static void main(String[] args)throws IOException{\n BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));\n String[] line = buffer.readLine().split(\" \");\n int nodes = Integer.parseInt(line[0]);\n int height = Integer.parseInt(line[1]);\n int n = 36;\n long[][] dynamic = new long[n][n];\n\n //fill first column with 1s, creates buffer\n for(int i = 0 ; i < n; i++)\n dynamic[0][i] = 1;\n\n //count all the trees\n for(int i = 1; i < n; i++){\n for(int j = 1; j < n; j++){\n for(int k = 0; k < i ;k++)\n dynamic[i][j] += dynamic[k][j - 1] * dynamic[i - k - 1][j - 1];\n }\n }\n //the amount of trees to jump\n System.out.println(dynamic[nodes][35] - dynamic[nodes][height - 1]);\n }\n}", "lang_cluster": "Java", "tags": ["divide and conquer", "dp", "combinatorics"], "code_uid": "0f024ba7f58f86a52002001418751575", "src_uid": "faf12a603d0c27f8be6bf6b02531a931", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Scanner;\n\npublic class TeamsForming {\n public static final Scanner sc = new Scanner(System.in);\n\n public static void main(String[] args) {\n ArrayList programmingSkill = new ArrayList();\n byte stu = sc.nextByte();\n short problems = 0;\n for (int i = 0; i < stu; i++) {\n programmingSkill.add(sc.nextInt());\n }\n Collections.sort(programmingSkill);\n for (int i = 1; i < stu; i = i + 2) {\n problems += ((int)programmingSkill.get(i) - (int)programmingSkill.get(i-1));\n }\n System.out.println(problems);\n }\n}\n", "lang_cluster": "Java", "tags": ["sortings"], "code_uid": "b4755cf44675ace424130284bf0b46d2", "src_uid": "55485fe203a114374f0aae93006278d3", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n/**\n * Created on 14.06.2016.\n */\npublic class task2 {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n long n = in.nextLong();\n long tek;\n String rez = \"NO\";\n for (long i = 0; i < 812; i++) {\n //tek=i*1234567;\n for (long j = 0; (j < 8102)&&(i*1234567+j*123456<=n); j++) {\n tek=i*1234567+j*123456;\n if ((n-tek)%1234==0){\n rez=\"YES\";\n break;\n }\n }\n if(rez.equals(\"YES\")){\n break;\n }\n }\n System.out.println(rez);\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force"], "code_uid": "69435fec9b5ca591a580861a4c8d7205", "src_uid": "72d7e422a865cc1f85108500bdf2adf2", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/**\n * BaZ :D\n */\nimport java.util.*;\nimport java.io.*;\nimport static java.lang.Math.*;\npublic class Main\n{\n static MyScanner scan;\n static PrintWriter pw;\n public static void main(String[] args) {\n new Thread(null,null,\"BaZ\",1<<25)\n {\n public void run()\n {\n try\n {\n solve();\n }\n catch(Exception e)\n {\n e.printStackTrace();\n System.exit(1);\n }\n }\n }.start();\n }\n static void solve() throws IOException\n {\n scan = new MyScanner();\n pw = new PrintWriter(System.out,true);\n StringBuilder sb = new StringBuilder();\n char c[] = ne().toCharArray();\n int n = c.length;\n int ans = 0;\n for(int i=n-1;i>=0;--i) {\n //pl(\"c[i] : \"+c[i]);\n if(i==0) {\n ans+=c[i]-'0';\n }\n else {\n if(c[i]=='9') {\n ans+=c[i]-'0';\n }\n else {\n ans+=c[i]-'0';\n ans+=10;\n c[i-1]--;\n }\n }\n }\n pl(ans);\n pw.flush();\n pw.close();\n }\n static int ni() throws IOException\n {\n return scan.nextInt();\n }\n static long nl() throws IOException\n {\n return scan.nextLong();\n }\n static double nd() throws IOException\n {\n return scan.nextDouble();\n }\n static String ne() throws IOException\n {\n return scan.next();\n }\n static String nel() throws IOException\n {\n return scan.nextLine();\n }\n static void pl()\n {\n pw.println();\n }\n static void p(Object o)\n {\n pw.print(o+\" \");\n }\n static void pl(Object o)\n {\n pw.println(o);\n }\n static void psb(StringBuilder sb)\n {\n pw.print(sb);\n }\n static void pa(String arrayName, Object arr[])\n {\n pl(arrayName+\" : \");\n for(Object o : arr)\n p(o);\n pl();\n }\n static void pa(String arrayName, int arr[])\n {\n pl(arrayName+\" : \");\n for(int o : arr)\n p(o);\n pl();\n }\n static void pa(String arrayName, long arr[])\n {\n pl(arrayName+\" : \");\n for(long o : arr)\n p(o);\n pl();\n }\n static void pa(String arrayName, double arr[])\n {\n pl(arrayName+\" : \");\n for(double o : arr)\n p(o);\n pl();\n }\n static void pa(String arrayName, char arr[])\n {\n pl(arrayName+\" : \");\n for(char o : arr)\n p(o);\n pl();\n }\n static void pa(String listName, List list)\n {\n pl(listName+\" : \");\n for(Object o : list)\n p(o);\n pl();\n }\n static void pa(String arrayName, Object[][] arr) {\n pl(arrayName+\" : \");\n for(int i=0;i= MOD ? a - MOD : a;\n }\n\n int product(int a, int b) {\n return (int) (1l * a * b % MOD);\n }\n\n int pow(int x, int k) {\n int result = 1;\n while (k > 0) {\n if (k % 2 == 1) {\n result = product(result, x);\n }\n x = product(x, x);\n k /= 2;\n }\n return result;\n }\n\n int inv(int x) {\n return pow(x, MOD - 2);\n }\n\n void solve() throws IOException {\n class Utils {\n boolean isGood(long x) {\n List d = new ArrayList<>();\n for(long y = x; y > 0; y /= 10) {\n d.add((int)(y % 10));\n }\n return d.get(0) == (int)d.get(d.size() - 1);\n }\n\n long brute(long ceiling) {\n long answer = 0;\n for(int i = 1; i <= ceiling; i++) {\n if(isGood(i)) {\n answer++;\n }\n }\n return answer;\n }\n\n long count(long ceiling) {\n if(ceiling <= 1000) {\n return brute(ceiling);\n }\n long p = 10;\n long answer = 0;\n while(ceiling >= p && p < 1000000l * 1000000 * 1000000) {\n answer += 9 * Math.max(1, p / 100);\n p *= 10;\n }\n p /= 10;\n long firstDigit = ceiling / p;\n for(int i = 1; i < firstDigit; i++) {\n answer += p / 10;\n }\n long x = ceiling % p;\n if(x == 0) {\n return answer;\n }\n answer += Math.max(0, x / 10);\n long y = firstDigit * p + x / 10 * 10;\n while(y <= ceiling) {\n if(y % 10 == firstDigit) {\n answer++;\n }\n y++;\n }\n return answer;\n }\n }\n Utils utils = new Utils();\n// for(int i = 1; i <= 1000000; i++) {\n// if(i % 1000 == 0) {\n// System.out.println(\"i = \" + i);\n// }\n// if(utils.count(i) != utils.brute(i)) {\n// writer.println(\"failed \" + i);\n// return;\n// }\n// }\n long l = nextLong();\n long r = nextLong();\n writer.println(utils.count(r) - utils.count(l - 1));\n }\n\n public static void main(String[] args) throws IOException {\n try (A a = new A()) {\n a.solve();\n }\n }\n\n @Override\n public void close() throws IOException {\n reader.close();\n writer.close();\n }\n}", "lang_cluster": "Java", "tags": ["binary search", "dp", "combinatorics"], "code_uid": "383919d02e0668aa2b93f49814ed7ec8", "src_uid": "9642368dc4ffe2fc6fe6438c7406c1bd", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.lang.*;\nimport java.math.*;\nimport java.util.*;\nimport java.io.*;\n\npublic class Main {\nclass Node {\n long p;\n int a;\n public Node(long p,int a){\n this.p=p;\n this.a=a;\n }\n}\n void solve() {\n long n=nl(); int k=ni();\n ArrayList vec=new ArrayList<>();\n for(long i=2;i*i<=n;i++){\n if(n%i==0){\n int cc=0;\n while(n%i==0){\n n/=i;\n cc++;\n }\n vec.add(new Node(i,cc));\n }\n }\n if(n>1) vec.add(new Node(n,1));\n long dp[][]=new long[51][k+1];\n long ans=1;\n long suf[]=new long[51];\n long curSuf[]=new long[51];\n long inv[]=new long[52];\n for(int i=0;i<52;i++) inv[i]=modInverse(i);\n\n for(Node P : vec){\n long p=P.p; int a=P.a;\n for(int i=0;i<=50;i++) Arrays.fill(dp[i],0);\n\n dp[a][0]=1;\n Arrays.fill(suf,inv[a+1]);\n\n for(int s=1;s<=k;s++){\n Arrays.fill(curSuf,0);\n for(int i=a;i>=0;i--){\n dp[i][s]=suf[i];\n curSuf[i]=mul(dp[i][s],inv[i+1]);\n if(i+1<=a) curSuf[i]=add(curSuf[i],curSuf[i+1]);\n // for(int j=i;j<=a;j++) dp[i][s]=add(dp[i][s],mul(dp[j][s-1],inv[j+1]));\n\n }\n for(int i=0;i<=a;i++) suf[i]=curSuf[i];\n }\n long ex=0;\n for(int i=0;i<=a;i++){\n ex=add(ex,mul(dp[i][k],modpow(p,i)));\n\n }\n // if(p==2) pw.println(dp[0][k]+\" \"+dp[1][k]+\" \"+modInverse(2)+\" \"+ex+\" \"+mul(3,modInverse(2)));\n ans=mul(ans,ex);\n\n }\n pw.println(ans);\n\n }\n long add(long x,long y){\n x+=y;\n if(x>=M) x-=M;\n return x;\n }\n long sub(long x,long y){\n x-=y;\n if(x<0) x+=M;\n return x;\n }\n long mul(long x,long y){\n x*=y;\n if(x>=M) x%=M;\n return x;\n }\n long modpow(long a, long b)\n {\n long r=1;\n while(b>0)\n {\n if((b&1)>0) r=mul(r,a);\n a=mul(a,a);\n b>>=1;\n }\n return r;\n }\n\n long modInverse(long A)\n {\n\n return modpow(A,M-2);\n }\n\n\n\n\n long M= (long)1e9+7;\n InputStream is;\n PrintWriter pw;\n String INPUT = \"\";\n void run() throws Exception {\n is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n pw = new PrintWriter(System.out);\n long s = System.currentTimeMillis();\n solve();\n pw.flush();\n if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+\"ms\");\n\n }\n public static void main(String[] args) throws Exception { new Main().run(); }\n\n private byte[] inbuf = new byte[1024];\n public int lenbuf = 0, ptrbuf = 0;\n\n private int readByte() {\n if(lenbuf == -1)throw new InputMismatchException();\n if(ptrbuf >= lenbuf){\n ptrbuf = 0;\n try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n if(lenbuf <= 0)return -1;\n }\n return inbuf[ptrbuf++];\n }\n\n private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\n private double nd() { return Double.parseDouble(ns()); }\n private char nc() { return (char)skip(); }\n\n private String ns() {\n int b = skip();\n StringBuilder sb = new StringBuilder();\n while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n sb.appendCodePoint(b);\n b = readByte();\n }\n return sb.toString();\n }\n\n private char[] ns(int n) {\n char[] buf = new char[n];\n int b = skip(), p = 0;\n while(p < n && !(isSpaceChar(b))){\n buf[p++] = (char)b;\n b = readByte();\n }\n return n == p ? buf : Arrays.copyOf(buf, p);\n }\n\n private char[][] nm(int n, int m) {\n char[][] map = new char[n][];\n for(int i = 0;i < n;i++)map[i] = ns(m);\n return map;\n }\n\n private int[] na(int n) {\n int[] a = new int[n];\n for(int i = 0;i < n;i++)a[i] = ni();\n return a;\n }\n\n private int ni() {\n int num = 0, b;\n boolean minus = false;\n while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n if(b == '-'){\n minus = true;\n b = readByte();\n }\n\n while(true){\n if(b >= '0' && b <= '9'){\n num = num * 10 + (b - '0');\n }else{\n return minus ? -num : num;\n }\n b = readByte();\n }\n }\n\n private long nl() {\n long num = 0;\n int b;\n boolean minus = false;\n while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n if(b == '-'){\n minus = true;\n b = readByte();\n }\n\n while(true){\n if(b >= '0' && b <= '9'){\n num = num * 10 + (b - '0');\n }else{\n return minus ? -num : num;\n }\n b = readByte();\n }\n }\n private boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n private void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }\n\n}", "lang_cluster": "Java", "tags": ["math", "dp", "probabilities", "number theory"], "code_uid": "0b45b8015a747797dd5485bf6af45dce", "src_uid": "dc466d9c24b7dcb37c0e99337b4124d2", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.util.*;\n\npublic class cf2 {\n static class FastReader{\n BufferedReader br;\n StringTokenizer st;\n public FastReader(){\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n String next(){\n while(st == null || !st.hasMoreElements()){\n try{\n st = new StringTokenizer(br.readLine());\n } catch (IOException e){\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n int nextInt(){\n return Integer.parseInt(next());\n }\n long nextLong(){\n return Long.parseLong(next());\n }\n double nextDouble(){\n return Double.parseDouble(next());\n }\n String nextLine(){\n String str = \"\";\n try{\n str = br.readLine();\n } catch (Exception e){\n e.printStackTrace();\n }\n return str;\n }\n }\n static int modPower(int x, int y, int mod){\n int res = 1;\n x %= mod;\n if(x==0) return 0;\n while(y>0){\n if(y%2==1){\n res = (res*x)%mod;\n }\n y = y>>1;\n x = (x*x)%mod;\n }\n return res;\n }\n static class pair{\n T1 first;\n T2 second;\n pair(T1 first, T2 second){\n this.first = first;\n this.second = second;\n }\n }\n static long gcd(long a, long b){\n if(b == 0) return a;\n return gcd(b, a%b);\n }\n\n static boolean same(int[] a, List l){\n if(a.length != l.size()) return false;\n for(int i = 0; i < a.length; i++){\n if(a[i] != l.get(i)) return false;\n }\n return true;\n }\n\n static long convert(List l){\n int j = 0;\n long hash = 0;\n for(int i : l){\n hash += (i*Math.pow(11,j));\n j++;\n }\n return hash;\n }\n\n public static void main(String[] args) {\n FastReader in = new FastReader();\n int n = in.nextInt();\n int k1 = in.nextInt();\n int[] a = new int[k1], b = new int[n-k1];\n List l1 = new ArrayList<>(), l2 = new ArrayList<>();\n for(int i = 0; i < k1; i++){\n a[i] = in.nextInt();\n l1.add(a[i]);\n }\n int k2 = in.nextInt();\n for(int i = 0; i < k2; i++){\n b[i] = in.nextInt();\n l2.add(b[i]);\n }\n int ans = 0;\n boolean cycle = false;\n Set> s = new HashSet<>();\n Set> s1 = new HashSet<>(), s2 = new HashSet<>();\n s1.add(l1);\n s2.add(l2);\n while (!l1.isEmpty() && !l2.isEmpty()){\n //System.out.println(\"Running\");\n int card1 = l1.remove(0), card2 = l2.remove(0);\n if(card1 > card2){\n l1.add(card2);\n l1.add(card1);\n } else {\n l2.add(card1);\n l2.add(card2);\n }\n ans++;\n if(l2.isEmpty() || l1.isEmpty()) break;\n cycle = s1.contains(l1) && s2.contains(l2);\n if(cycle) break;\n s1.add(l1);\n s2.add(l2);\n }\n if(cycle){\n System.out.println(\"-1\");\n } else {\n System.out.println(ans + \" \" + ((l2.isEmpty())?\"1\":\"2\"));\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["dfs and similar", "brute force", "games"], "code_uid": "dafdc45560a3fa6744250f600e9b9c2a", "src_uid": "f587b1867754e6958c3d7e0fe368ec6e", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.PriorityQueue;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\npublic class GenerateAString_Edu16 {\n//\tstatic int n, x, y;\n\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\t\tScanner sc = new Scanner(System.in);\n\t\tn = sc.nextInt();\n\t\tx = sc.nextInt();\n\t\ty = sc.nextInt();\n//\t\tSystem.out.println(dijkstra(0, n));\n\t\tSystem.out.println(yamosahel());\n\t}\n\n//\tstatic int INF = 1000000000;\n\n\t\n\n\tstatic long[] dp;\n\tstatic long yamosahel()\n\t{\n\t\tdp = new long[n+1];\n\t\tfor (int i = 1; i < dp.length; i++) {\n\t\t\tdp[i] = dp[i-1]+x;\n\t\t\tif(i%2==0){\n\t\t\t\tdp[i] = Math.min(dp[i], dp[i/2]+y);\n\t\t\t}\n\t\t\telse\n\t\t\t\tdp[i] = Math.min(dp[i],Math.min( dp[i/2] + y+x, dp[(i+1)/2] + y+x));\n\t\t}\n\t\treturn dp[n];\n\t}\n//\tstatic int n;\n\tstatic int n,x,y;\n\tstatic final long INF = (long)1e18;\n\n\tstatic class Pair implements Comparable\n\t{\n\t\tint node;\n\t\tlong time;\n\t\tPair(int a, long b)\n\t\t{\n\t\t\tnode = a; time = b;\n\t\t}\n\t\t\n\t\tpublic int compareTo(Pair p)\n\t\t{\n\t\t\t// time-p.time\n\t\t\tif(p.time!=time) return (time > p.time)? 1:-1;\n\t\t\treturn node-p.node;\n\t\t}\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn node + \" \"+time;\n\t\t}\n\t}\n\n\tstatic class Scanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tScanner(InputStream s) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(s));\n\t\t}\n\n\t\tScanner(FileReader r) {\n\t\t\tbr = new BufferedReader(r);\n\n\t\t}\n\n\t\tString next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint nextInt() throws NumberFormatException, IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t}\n}", "lang_cluster": "Java", "tags": ["dfs and similar", "dp"], "code_uid": "410d8d0a8e626400653f2b64fbb4ce58", "src_uid": "0f270af00be2a523515d5e7bd66800f6", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class Main {\n FastScanner in;\n PrintWriter out;\n\n static final String FILE = \"\";\n\n public static final int MAXN = 3 * 1000 * 100 + 1000;\n //public static final int MAXN = 1000;\n public static final int MOD = (int)1e9 + 7;\n\n int a, b, k, t;\n int[][] canA;\n int[][] canB;\n int[] realA;\n int[] realB;\n\n int getA(int turn, int from, int to) {\n int cur;\n if (to < MAXN)\n cur = canA[turn][to];\n else\n cur = canA[turn][MAXN - 1];\n if (from > 0) {\n cur -= canA[turn][from - 1];\n if (cur < 0)\n cur += MOD;\n }\n return cur;\n }\n\n int getB(int turn, int from, int to) {\n int cur;\n if (to < MAXN)\n cur = canB[turn][to];\n else\n cur = canB[turn][MAXN - 1];\n if (from > 0) {\n cur -= canB[turn][from - 1];\n if (cur < 0)\n cur += MOD;\n }\n return cur;\n }\n\n void solve() {\n a = in.nextInt();\n b = in.nextInt();\n k = in.nextInt();\n t = in.nextInt();\n canA = new int[2][MAXN];\n canB = new int[2][MAXN];\n realA = new int[MAXN];\n realB = new int[MAXN];\n\n for (int i = a + MAXN / 2; i < MAXN; i++)\n canA[0][i] = 1;\n for (int turn = 1; turn <= t; turn++) {\n int ind = turn % 2;\n for (int i = 0; i < MAXN; i++) {\n canA[ind][i] = getA(1 - ind, i - k, i + k);\n if (turn == t)\n realA[i] = canA[ind][i];\n if (i > 0) {\n canA[ind][i] += canA[ind][i - 1];\n if (canA[ind][i] >= MOD)\n canA[ind][i] -= MOD;\n }\n }\n }\n\n for (int i = b + MAXN / 2; i < MAXN; i++)\n canB[0][i] = 1;\n for (int turn = 1; turn <= t; turn++) {\n int ind = turn % 2;\n for (int i = 0; i < MAXN; i++) {\n canB[ind][i] = getB(1 - ind, i - k, i + k);\n if (turn == t)\n realB[i] = canB[ind][i];\n if (i > 0) {\n canB[ind][i] += canB[ind][i - 1];\n if (canB[ind][i] >= MOD)\n canB[ind][i] -= MOD;\n }\n }\n }\n\n for (int i = 1; i < MAXN; i++) {\n realB[i] += realB[i - 1];\n if (realB[i] >= MOD)\n realB[i] -= MOD;\n }\n\n long ans = 0;\n for (int i = 1; i < MAXN; i++) {\n ans += (long) (realA[i]) * (long) (realB[i - 1]);\n ans %= MOD;\n }\n\n out.println(ans);\n }\n\n public void run() {\n if (FILE.equals(\"\")) {\n in = new FastScanner(System.in);\n out = new PrintWriter(System.out);\n } else {\n try {\n in = new FastScanner(new FileInputStream(FILE +\n \".in\"));\n out = new PrintWriter(new FileOutputStream(FILE +\n \".out\"));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n solve();\n out.close();\n }\n\n public static void main(String[] args) {\n (new Main()).run();\n }\n\n class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(InputStream is) {\n br = new BufferedReader(new InputStreamReader(is));\n }\n\n public String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n public String nextLine() {\n st = null;\n try {\n return br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n return null;\n }\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public float nextFloat() {\n return Float.parseFloat(next());\n }\n }\n\n}", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics"], "code_uid": "839ae970aca504b0d9a83835cae83d6c", "src_uid": "8b8327512a318a5b5afd531ff7223bd0", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class Main {\n // return a^b mod n\n public static int modexp(int a, int b, int n) {\n if (b == 0) return 1;\n long t = modexp(a, b/2, n); // use long for intermediate computations to eliminate overflow\n long c = (t * t) % n;\n if (b % 2 == 1)\n c = (c * a) % n;\n return (int) c;\n }\n \n public static void main(String [] args) {\n Scanner sc = new Scanner(System.in); \n int n = sc.nextInt(), m = sc.nextInt(), k = sc.nextInt(); \n if(k > n || k == 1) {\n System.out.println(modexp(m, n, 1000000007));\n } else if(n == 1) {\n System.out.println(m % 1000000007);\n } else if(n == k) {\n //half the length of the word\n int choose = (n+1)/2;\n System.out.println(modexp(m, choose, 1000000007));\n } else if(k % 2 == 0) {\n System.out.println(m % 1000000007);\n } else {\n System.out.println(((m%1000000007)*(m%1000000007)) % 1000000007);\n }\n \n sc.close();\n }\n}\n", "lang_cluster": "Java", "tags": ["dfs and similar", "math", "combinatorics", "graphs"], "code_uid": "f2e2e67e0acfaf59eb7d70f358f213b5", "src_uid": "1f9107e8d1d8aebb1f4a1707a6cdeb6d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskC {\n static final long MODULO = (long) (1e9 + 7);\n static int[] invs;\n static int[] facts;\n static int[] invfacts;\n\n static {\n int k = (int) 1e6;\n invs = new int[k + 2];\n invs[1] = 1;\n for (int i = 2; i <= k + 1; ++i) {\n invs[i] = (int) ((MODULO - (MODULO / i) * (long) invs[(int) (MODULO % i)] % MODULO) % MODULO);\n }\n facts = new int[k + 2];\n invfacts = new int[k + 2];\n facts[0] = 1;\n invfacts[0] = 1;\n for (int i = 1; i <= k + 1; ++i) {\n facts[i] = (int) (facts[i - 1] * (long) i % MODULO);\n invfacts[i] = (int) (invfacts[i - 1] * (long) invs[i] % MODULO);\n }\n }\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int k = in.nextInt();\n long[] res = new long[n + 1];\n long[] prefixSum = new long[n + 1];\n res[1] = 1;\n prefixSum[1] = 1;\n for (int i = 2; i <= n; ++i) {\n res[i] = prefixSum[i - 1] - prefixSum[Math.max(1, i - k) - 1];\n if (res[i] < 0) res[i] += MODULO;\n res[i] = res[i] * invs[i - 1] % MODULO;\n prefixSum[i] = (prefixSum[i - 1] + res[i]) % MODULO;\n }\n long sum = 0;\n for (int i = 1; i <= n; ++i) {\n sum = (sum + res[i] * facts[n - 1] % MODULO) % MODULO;\n }\n long ret = ((facts[n] - sum) % MODULO + MODULO) % MODULO;\n out.println(ret);\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["math", "dp"], "code_uid": "18f33be819dc9c01d91e87104a353ff6", "src_uid": "0644605611a2cd10ab3a9f12f18d7ae4", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class F implements Runnable {\n private MyScanner in;\n private PrintWriter out;\n\n private boolean[] prime;\n private final int MAX = 1000000;\n \n private void sieve() {\n Arrays.fill(prime, true);\n prime[0] = prime[1] = false;\n for (int i = 2; i * i < MAX; ++i) {\n if (prime[i]) {\n for (int j = i * i; j < MAX; j += i) {\n prime[j] = false;\n }\n }\n }\n }\n \n private int rev(int n) {\n int ans = 0;\n while (n != 0) {\n ans = 10 * ans + n % 10;\n n /= 10;\n }\n return ans;\n }\n \n private void solve() {\n prime = new boolean[MAX];\n sieve();\n int n = in.nextInt();\n for (int i = 0; ; ++i) {\n int rev = rev(i);\n if (rev == i) {\n continue;\n }\n if (prime[i] && prime[rev(i)]) {\n --n;\n if (n == 0) {\n out.println(i);\n return;\n }\n }\n }\n }\n\n @Override\n public void run() {\n in = new MyScanner();\n out = new PrintWriter(System.out);\n solve();\n in.close();\n out.close();\n }\n\n public static void main(String[] args) {\n new F().run();\n }\n\n static class MyScanner {\n private BufferedReader br;\n private StringTokenizer st;\n\n public MyScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n public void close() {\n try {\n br.close();\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n\n public String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n return null;\n }\n }\n return st.nextToken();\n }\n\n public String nextLine() {\n try {\n st = null;\n return br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n return null;\n }\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public boolean hasNext() {\n if (st != null && st.hasMoreTokens()) {\n return true;\n }\n try {\n while (br.ready()) {\n st = new StringTokenizer(br.readLine());\n if (st != null && st.hasMoreTokens()) {\n return true;\n }\n }\n } catch (IOException e) {\n e.printStackTrace();\n }\n return false;\n }\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "implementation", "number theory"], "code_uid": "0253b5f48797e451f5e38d3a7ca45236", "src_uid": "53879e79cccbacfa6586d40cf3436657", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.HashSet;\nimport java.util.Scanner;\n\npublic class Nafis {\n\n public static void main(String[] args) {\n\n Scanner sc = new Scanner(System.in);\n String str = sc.next();\n int sz = str.length();\n HashSet freq = new HashSet<>();\n for (int i = 0; i <= sz / 2; i++) {\n if (str.charAt(i) == str.charAt(sz - i - 1)) {\n freq.add(str.charAt(i));\n continue;\n } else {\n System.out.println(sz);\n return;\n }\n }\n\n System.out.println(freq.size() == 1 ? 0 : sz - 1);\n\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "strings", "implementation"], "code_uid": "4b4808a1d50cf5b792f4e4dba57ad81f", "src_uid": "6c85175d334f811617e7030e0403f706", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/**\n * Created by ankeet on 12/30/16.\n */\nimport java.io.*;\nimport java.util.*;\n\npublic class D750 {\n\n static FastReader in = null;\n static PrintWriter out = null;\n\n public static void solve()\n {\n int n = in.nextInt();\n int[] t = new int[n+1];\n for(int i=1; i<=n; i++) t[i] = in.nextInt();\n\n TreeSet total = new TreeSet();\n\n TreeSet curr = new TreeSet();\n curr.add(new Firework(new Pair(0,0), 0, 1));\n\n for(int i=1; i<=n; i++){\n TreeSet next = new TreeSet();\n while(!curr.isEmpty()){\n Firework f = curr.pollFirst();\n\n for(int j=1; j<=t[i]; j++){\n f.p.x += f.nx;\n f.p.y += f.ny;\n total.add(new Pair(f.p.x, f.p.y));\n }\n\n if(f.nx == 0){\n next.add(new Firework(new Pair(f.p.x, f.p.y), 1, f.ny));\n next.add(new Firework(new Pair(f.p.x, f.p.y), -1, f.ny));\n }\n else if(f.ny == 0){\n next.add(new Firework(new Pair(f.p.x, f.p.y), f.nx, 1));\n next.add(new Firework(new Pair(f.p.x, f.p.y), f.nx, -1));\n }\n else{\n next.add(new Firework(new Pair(f.p.x, f.p.y), f.nx, 0));\n next.add(new Firework(new Pair(f.p.x, f.p.y), 0, f.ny));\n }\n\n }\n curr = next;\n }\n\n out.println(total.size());\n\n }\n static class Firework implements Comparable{\n int nx;\n int ny;\n Pair p;\n public Firework(Pair pp, int xx, int yy ){\n this.p = pp;\n nx = xx;\n ny = yy;\n }\n public int compareTo(Firework f){\n int c = p.compareTo(f.p);\n if(c!=0)return c;\n if(nx != f.nx) return nx - f.nx;\n return ny-f.ny;\n }\n }\n static class Pair implements Comparable{\n int x;\n int y;\n public Pair(int f, int s){\n x = f;\n y = s;\n }\n\n public int compareTo(Pair p){\n if(this.x != p.x) return this.x - p.x;\n return this.y - p.y;\n }\n }\n\n public static void main(String[] args)\n {\n in = new FastReader(System.in);\n out = new PrintWriter(System.out);\n solve();\n out.flush();\n out.close();\n\n }\n\n static class FastReader {\n\n BufferedReader read;\n StringTokenizer tokenizer;\n\n public FastReader(InputStream in)\n {\n read = new BufferedReader(new InputStreamReader(in));\n }\n\n public String next()\n {\n while(tokenizer == null || !tokenizer.hasMoreTokens())\n {\n try{\n tokenizer = new StringTokenizer(read.readLine());\n }catch(Exception e){\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n public String nextLine(){\n\n try\n {\n return read.readLine();\n }\n catch(Exception e)\n {\n throw new RuntimeException(e);\n }\n }\n public int nextInt()\n {\n return Integer.parseInt(next());\n }\n public long nextLong()\n {\n return Long.parseLong(next());\n }\n public double nextDouble()\n {\n return Double.parseDouble(next());\n }\n\n public int[] nextIntArr(int n)\n {\n int[] a = new int[n];\n for(int i=0; i= left && k <= right) out.println(right-left);\n\t\telse out.println(right-left+1);\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew A();\n\t\texit();\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "72f6fe3ed5e836f78b5e207e8c1a7434", "src_uid": "9a74b3b0e9f3a351f2136842e9565a82", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\n\npublic class Main {\n static class Assert {\n static void check(boolean e) {\n if (!e) {\n throw new Error();\n }\n }\n }\n\n class Scanner {\n\n StreamTokenizer in;\n\n Scanner(InputStream is) {\n in = new StreamTokenizer(new InputStreamReader(is));\n in.resetSyntax();\n in.whitespaceChars(0, 32);\n in.wordChars(33, 255);\n }\n\n String next() {\n try {\n in.nextToken();\n Assert.check(in.ttype == in.TT_WORD);\n return in.sval;\n } catch (IOException e) {\n throw new Error(e);\n }\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n }\n\n public static void main(String[] args) {\n new Main().run();\n }\n\n Scanner in;\n PrintWriter out;\n\n void run() {\n in = new Scanner(System.in);\n out = new PrintWriter(System.out);\n try {\n solve();\n } finally {\n out.close();\n }\n }\n\n void solve() {\n int q = in.nextInt();\n int r = in.nextInt();\n int m = in.nextInt();\n int a[] = new int[100001];\n a[0] = in.nextInt();\n int buf[] = new int[100001];\n buf[a[0]] = 1;\n int i = 1;\n while (true) {\n a[i] = (q * a[i - 1] + r) % m;\n buf[a[i]]++;\n if (buf[a[i]] == 2) {\n for (int j = 0; j < i; ++j) {\n if (a[j] == a[i]) {\n out.println(i - j);\n return;\n }\n }\n }\n i++;\n }\n }\n}", "lang_cluster": "Java", "tags": ["implementation", "number theory"], "code_uid": "abc134b6b7ca74a2bbacf4831eda6a78", "src_uid": "9137197ee1b781cd5cc77c46f50b9012", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class JavaApplication1 {\n public static void main(String[] args) {\n \n Scanner input =new Scanner(System.in);\n String str=input.nextLine();\n char c=str.charAt(0);\n char b='d';\n boolean bool=false;\n boolean bool2=true;\n if(str.length()==1)\n {\n if(isVowel(c) || c=='n' )\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n }\n else{\n c=str.charAt(str.length()-1); \n if(!(isVowel(c) || c=='n'))\n { \n System.out.println(\"NO\"); \n bool2=false;\n }\n for (int i = 0; i1 && bool2) \n System.out.println(\"YES\");\n \n }\n static boolean isVowel(char c) {\n return \"aeiou\".indexOf(c) != -1;\n}\n \n}\n", "lang_cluster": "Java", "tags": ["strings", "implementation"], "code_uid": "612ec8cda40a1117dd0fd95099589cb4", "src_uid": "a83144ba7d4906b7692456f27b0ef7d4", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Vitya {\n\n\tpublic static void main(String[] args) {\n\t\tScanner scanner = new Scanner(System.in);\n\t\tint n = scanner.nextInt();\n\t\tint[] t = new int[n];\n\t\tfor (int i=0;i graph[] ;\r\n static int mod = 998244353;\r\n // static int count=0;\r\n public static void main(String[] args) {\r\n\r\n\r\n fs = new FastScanner();\r\n PrintWriter out = new PrintWriter(System.out);\r\n\r\n // int t = fs.nextInt();\r\n // while (t-- > 0) {\r\n // int n = fs.nextInt();\r\n // int k = fs.nextInt();\r\n //int a[] = fs.readArray(n);\r\n String s = fs.next();\r\n if(s.length()<=2){\r\n out.println(\"YES\");\r\n }else{\r\n boolean f = true;\r\n int a[] = new int[s.length()];\r\n a[0] = s.charAt(0)-'A' + 1;\r\n a[1] = s.charAt(1)-'A' + 1;\r\n for(int i=2;i 28,1,28+27\r\n x = x%26;\r\n if(x==0){\r\n x = 26;\r\n }else if(x==1){\r\n f = false;\r\n break;\r\n }\r\n int y = s.charAt(i)-'A'+1;\r\n if((x-1)==y){\r\n a[i] = s.charAt(i)-'A'+1;\r\n }else{\r\n f = false;\r\n break;\r\n }\r\n }\r\n if(!f){\r\n out.println(\"NO\");\r\n }else{\r\n out.println(\"YES\");\r\n }\r\n }\r\n\r\n // }\r\n out.close();\r\n }\r\n\r\n static class Pair implements Comparable {\r\n int x;\r\n int y;\r\n\r\n Pair(int x, int y) {\r\n this.x = x;\r\n this.y = y;\r\n\r\n }\r\n\r\n public int compareTo(Pair o) {\r\n return this.x - o.x;\r\n }\r\n }\r\n\r\n // JAVA program to compute factorial\r\n// of big numbers\r\n // This function finds factorial of\r\n // large numbers and prints them\r\n static void factorial(int n)\r\n {\r\n int res[] = new int[500];\r\n\r\n // Initialize result\r\n res[0] = 1;\r\n int res_size = 1;\r\n\r\n // Apply simple factorial formula\r\n // n! = 1 * 2 * 3 * 4...*n\r\n for (int x = 2; x <= n; x++)\r\n res_size = multiply(x, res, res_size);\r\n\r\n System.out.println(\"Factorial of given number is \");\r\n for (int i = res_size - 1; i >= 0; i--)\r\n System.out.print(res[i]);\r\n }\r\n\r\n // This function multiplies x with the number\r\n // represented by res[]. res_size is size of res[] or\r\n // number of digits in the number represented by res[].\r\n // This function uses simple school mathematics for\r\n // multiplication. This function may value of res_size\r\n // and returns the new value of res_size\r\n static int multiply(int x, int res[], int res_size)\r\n {\r\n int carry = 0; // Initialize carry\r\n\r\n // One by one multiply n with individual\r\n // digits of res[]\r\n for (int i = 0; i < res_size; i++)\r\n {\r\n int prod = res[i] * x + carry;\r\n res[i] = prod % 10; // Store last digit of\r\n // 'prod' in res[]\r\n carry = prod/10; // Put rest in carry\r\n }\r\n\r\n // Put carry in res and increase result size\r\n while (carry!=0)\r\n {\r\n res[res_size] = carry % 10;\r\n carry = carry / 10;\r\n res_size++;\r\n }\r\n return res_size;\r\n }\r\n\r\n\r\n\r\n static long fact[] = new long[200001];\r\n public static void fact(){\r\n fact[1] = 1;\r\n fact[0] = 1;\r\n\r\n for(int i=2;i<=200000;i++){\r\n fact[i] = (((fact[i-1])%mod) * ((i)%mod))%mod;\r\n }\r\n }\r\n static long lower(long array[], long key,int i,int k)\r\n {\r\n long ans=-1;\r\n while(i<=k){\r\n int mid = (i+k)/2;\r\n if(array[mid]>=key){\r\n ans = mid;\r\n k = mid-1;\r\n }else{\r\n i = mid+1;\r\n }\r\n }\r\n return ans;\r\n }\r\n\r\n static long upper(long array[], long key ,int i , int k){\r\n\r\n long ans = -1;\r\n while(i<=k){\r\n int mid = (i+k)/2;\r\n if(array[mid]<=key){\r\n ans = array[mid];\r\n i = mid+1;\r\n }else{\r\n k = mid-1;\r\n }\r\n }\r\n\r\n\r\n return ans;\r\n }\r\n\r\n public static class String1 implements Comparable{\r\n String str;\r\n int id;\r\n String1(String str , int id){\r\n this.str = str;\r\n this.id = id;\r\n }\r\n public int compareTo(String1 o){\r\n int i=0;\r\n while(i l=new ArrayList<>();\r\n for (int i:a) l.add(i);\r\n Collections.sort(l);\r\n for (int i=0; i 0)\r\n {\r\n\r\n // If y is odd, multiply x with result\r\n if ((y & 1) != 0)\r\n res = (res * x) % p;\r\n\r\n // y must be even now\r\n y = y >> 1; // y = y/2\r\n x = (x * x) % p;\r\n }\r\n return res;\r\n }\r\n\r\n //--------------------------------------------------------------------------------------------------------------\r\n public static int log2(int x) {\r\n return (int) (Math.log(x) / Math.log(2));\r\n }\r\n\r\n //---------------------------------------EXTENDED EUCLID ALGO--------------------------------------------------------\r\n\r\n public static Pair Euclid(int a,int b){\r\n\r\n if(b==0){\r\n return new Pair(1,0); // answer of x and y\r\n }\r\n\r\n Pair dash = Euclid(b,a%b);\r\n\r\n return new Pair(dash.y , dash.x - (a/b)*dash.y);\r\n\r\n\r\n }\r\n//--------------------------------GCD------------------GCD-----------GCD--------------------------------------------\r\n\r\n public static long gcd(long a,long b){\r\n if(b==0){\r\n return a;\r\n }\r\n\r\n return gcd(b,a%b);\r\n }\r\n\r\n\r\n static long C(int n, int k) {\r\n long res = 1;\r\n for (int i = n - k + 1; i <= n; ++i)\r\n res *= i;\r\n for (int i = 2; i <= k; ++i)\r\n res /= i;\r\n return res;\r\n }\r\n\r\n}\r\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "c752965b863c5e217950a2d16b4d12f1", "src_uid": "27e977b41f5b6970a032d13e53db2a6a", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class A {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tString[] s = br.readLine().trim().split(\" \");\n\t\tlong x = Long.parseLong(s[0]);\n\t\tlong y = Long.parseLong(s[1]);\n\t\tif(x < 0 || y < 1) System.out.println(\"No\");\n\t\telse if(x == 0 && y == 1) System.out.println(\"Yes\");\n\t\telse if(y == 1) System.out.println(\"No\");\n\t\telse if(x+1 >= y && (x+y)%2 == 1) System.out.println(\"Yes\");\n\t\telse System.out.println(\"No\");\n\t}\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "cf43815caf3eb2465379407c75472aa1", "src_uid": "1527171297a0b9c5adf356a549f313b9", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/**\n * @(#)PashaAndStick.java\n *\n *\n * @author\n * @version 1.00 2016/8/24\n */\n\n\nimport java.util.*;\n\npublic class PashaAndStick {\n\n public static void main(String[]args) {\n\n \tScanner in = new Scanner(System.in);\n \tint n = in.nextInt();\n \tint numOfWays = 0;\n\n \tif (n % 2 == 1) {\n \t\tSystem.out.print(\"0\");\n \t\treturn;\n \t}\n \tif (n / 2 % 2 == 1) {\n \t\tnumOfWays = n / 4;\n \t\tSystem.out.println(numOfWays);\n \t}\n \telse {\n \t\tnumOfWays = (n/4)-1;\n \t\tSystem.out.println(numOfWays);\n \t}\n\n }\n\n\n}", "lang_cluster": "Java", "tags": ["math", "combinatorics"], "code_uid": "477d3d7ce01a473fbd10d630ba2c3352", "src_uid": "32b59d23f71800bc29da74a3fe2e2b37", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "//pakage joney_000[let_me_start]\n//codeforces\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.math.*;\n\n/******************** Main Class ***********************/\n\npublic class C\n{ \n public static InputStream inputStream = System.in;\n public static OutputStream outputStream = System.out;\n public static FastReader in = new FastReader(inputStream);;\n public static PrintWriter out = new PrintWriter(outputStream);;\n /*\n Overhead\n */\n public static int tempints[] = new int[100005];\n public static long templongs[] = new long[100005];\n public static double tempdoubles[] = new double[100005];\n //public static double tempdoubles[] = new double[11];\n public static char tempchars[] = new char[100005];\n \n \n public static void main(String[] args) throws java.lang.Exception\n {\n //let_me_start \n \n \n \n \n int a = i();int b = i();int p = i();int q = i();\n long v= 1;\n long x = 0;\n long y= 0;\n long l = 1;\n long r = 100000000000000000L;\n \n \n long z= 0;\n while (l <= r) \n { \n long m = (l + r) / 2; \n v=m;\n x= v-(v/p);\n y =v-v/q;\n z= v-v/p-v/q+v/(p*q);\n \n \n //z= v-(v/g);\n //If the search key on the left half \n if (x>a&&y>b&&x+y-z>a+b) \n { \n //Update right index \n r = m - 1;\n } \n //If the search key on the right half \n else if (x ll = new LinkedList();\n for(int i=1;i<=n;i++){\n if(arr[i])ll.add(i);\n }\n n = ll.size();\n \n int primes[] = new int[n+1];\n for(int i=1;i<=n;i++){\n primes[i]=ll.removeFirst();\n }\n return primes;\n }\n public static long gcd (long a , long b)throws Exception{\n if(b==0)return a;\n return gcd(b , a%b);\n }\n public static long lcm (long a , long b)throws Exception{\n if(a==0||b==0)return 0;\n return (a*b)/gcd(a,b);\n }\n public static long mulmod(long a , long b ,long mod)throws Exception{\n if(a==0||b==0)return 0;\n if(b==1)return a;\n long ans = mulmod(a,b/2,mod);\n ans = (ans*2)% mod;\n if(b%2==1)ans = (a + ans)% mod;\n return ans;\n }\n public static long pow(long a , long b ,long mod)throws Exception{\n if(b==0)return 1;\n if(b==1)return a;\n long ans = pow(a,b/2,mod);\n ans = (ans * ans)% mod;\n if(b%2==1)ans = (a * ans)% mod;\n return ans;\n }\n // 20*20 nCr Pascal Table\n public static long[][] ncrTable()throws Exception{\n long ncr[][] = new long[21][21];\n for(int i=0 ;i<=20 ;i++){ncr[i][0]=1;ncr[i][i]=1;}\n for(int j=0;j<=20 ;j++){\n for(int i=j+1;i<= 20 ;i++){\n ncr[i][j] = ncr[i-1][j]+ncr[i-1][j-1];\n }\n }\n return ncr;\n }\n//*******************************I/O******************************// \npublic static int i()throws Exception{\n //return Integer.parseInt(br.readLine().trim());\n return in.nextInt();\n}\npublic static int[] is(int n)throws Exception{\n //int arr[] = new int[n+1];\n for(int i=1 ; i <= n ;i++)tempints[i] = in.nextInt(); \n return tempints;\n}\npublic static long l()throws Exception{\n return in.nextLong();\n}\npublic static long[] ls(int n)throws Exception{\n //long arr[] = new long[n+1];\n for(int i=1 ; i <= n ;i++)templongs[i] = in.nextLong(); \n return templongs;\n}\n\npublic static double d()throws Exception{\n return in.nextDouble();\n}\npublic static double[] ds(int n)throws Exception{\n //double arr[] = new double[n+1];\n for(int i=1 ; i <= n ;i++)tempdoubles[i] = in.nextDouble(); \n return tempdoubles;\n}\npublic static char c()throws Exception{\n return in.nextCharacter();\n}\npublic static char[] cs(int n)throws Exception{\n //double arr[] = new double[n+1];\n for(int i=1 ; i <= n ;i++)tempchars[i] = in.nextCharacter(); \n return tempchars;\n}\npublic static String s()throws Exception{\n return in.nextLine();\n}\npublic static BigInteger bi()throws Exception{\n return in.nextBigInteger();\n}\n//***********************I/O ENDS ***********************//\n//*********************** 0.3%f [precision]***********************//\n/* roundoff upto 2 digits \n double roundOff = Math.round(a * 100.0) / 100.0;\n or\n System.out.printf(\"%.2f\", val);\n \n*/\n/* print upto 2 digits after decimal\n val = ((long)(val * 100.0))/100.0;\n \n*/\n}\n\nclass FastReader{\n\n private boolean finished = false;\n\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private SpaceCharFilter filter;\n\n public FastReader(InputStream stream){\n this.stream = stream;\n }\n\n public int read(){\n if (numChars == -1){\n throw new InputMismatchException ();\n }\n if (curChar >= numChars){\n curChar = 0;\n try{\n numChars = stream.read (buf);\n } catch (IOException e){\n throw new InputMismatchException ();\n }\n if (numChars <= 0){\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int peek(){\n if (numChars == -1){\n return -1;\n }\n if (curChar >= numChars){\n curChar = 0;\n try{\n numChars = stream.read (buf);\n } catch (IOException e){\n return -1;\n }\n if (numChars <= 0){\n return -1;\n }\n }\n return buf[curChar];\n }\n\n public int nextInt(){\n int c = read ();\n while (isSpaceChar (c))\n c = read ();\n int sgn = 1;\n if (c == '-'){\n sgn = -1;\n c = read ();\n }\n int res = 0;\n do{\n if(c==','){\n c = read();\n }\n if (c < '0' || c > '9'){\n throw new InputMismatchException ();\n }\n res *= 10;\n res += c - '0';\n c = read ();\n } while (!isSpaceChar (c));\n return res * sgn;\n }\n\n public long nextLong(){\n int c = read ();\n while (isSpaceChar (c))\n c = read ();\n int sgn = 1;\n if (c == '-'){\n sgn = -1;\n c = read ();\n }\n long res = 0;\n do{\n if (c < '0' || c > '9'){\n throw new InputMismatchException ();\n }\n res *= 10;\n res += c - '0';\n c = read ();\n } while (!isSpaceChar (c));\n return res * sgn;\n }\n\n public String nextString(){\n int c = read ();\n while (isSpaceChar (c))\n c = read ();\n StringBuilder res = new StringBuilder ();\n do{\n res.appendCodePoint (c);\n c = read ();\n } while (!isSpaceChar (c));\n return res.toString ();\n }\n\n public boolean isSpaceChar(int c){\n if (filter != null){\n return filter.isSpaceChar (c);\n }\n return isWhitespace (c);\n }\n\n public static boolean isWhitespace(int c){\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n private String readLine0(){\n StringBuilder buf = new StringBuilder ();\n int c = read ();\n while (c != '\\n' && c != -1){\n if (c != '\\r'){\n buf.appendCodePoint (c);\n }\n c = read ();\n }\n return buf.toString ();\n }\n\n public String nextLine(){\n String s = readLine0 ();\n while (s.trim ().length () == 0)\n s = readLine0 ();\n return s;\n }\n\n public String nextLine(boolean ignoreEmptyLines){\n if (ignoreEmptyLines){\n return nextLine ();\n }else{\n return readLine0 ();\n }\n }\n\n public BigInteger nextBigInteger(){\n try{\n return new BigInteger (nextString ());\n } catch (NumberFormatException e){\n throw new InputMismatchException ();\n }\n }\n\n public char nextCharacter(){\n int c = read ();\n while (isSpaceChar (c))\n c = read ();\n return (char) c;\n }\n\n public double nextDouble(){\n int c = read ();\n while (isSpaceChar (c))\n c = read ();\n int sgn = 1;\n if (c == '-'){\n sgn = -1;\n c = read ();\n }\n double res = 0;\n while (!isSpaceChar (c) && c != '.'){\n if (c == 'e' || c == 'E'){\n return res * Math.pow (10, nextInt ());\n }\n if (c < '0' || c > '9'){\n throw new InputMismatchException ();\n }\n res *= 10;\n res += c - '0';\n c = read ();\n }\n if (c == '.'){\n c = read ();\n double m = 1;\n while (!isSpaceChar (c)){\n if (c == 'e' || c == 'E'){\n return res * Math.pow (10, nextInt ());\n }\n if (c < '0' || c > '9'){\n throw new InputMismatchException ();\n }\n m /= 10;\n res += (c - '0') * m;\n c = read ();\n }\n }\n return res * sgn;\n }\n\n public boolean isExhausted(){\n int value;\n while (isSpaceChar (value = peek ()) && value != -1)\n read ();\n return value == -1;\n }\n\n public String next(){\n return nextString ();\n }\n\n public SpaceCharFilter getFilter(){\n return filter;\n }\n\n public void setFilter(SpaceCharFilter filter){\n this.filter = filter;\n }\n\n public interface SpaceCharFilter{\n public boolean isSpaceChar(int ch);\n }\n}\n /******************** Pair class ***********************/\n \n class Pair implements Comparable{\n public int a;\n public int b;\n \n \n public Pair(){\n this.a = 0;\n this.b = 0;\n \n }\n public Pair(int a,int b , int n , long s){\n this.a = a;\n this.b = b;\n }\n public int compareTo(Pair p){\n if(this.a==p.a){\n return this.b-p.b; \n }\n return this.a-p.a; \n }\n public String toString(){\n return \"a=\"+this.a+\" b=\"+this.b;\n }\n \n} ", "lang_cluster": "Java", "tags": ["math", "binary search"], "code_uid": "d430726432675e390a6b4c4fdbfd8155", "src_uid": "ff3c39b759a049580a6e96c66c904fdc", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class A787 {\n\tpublic static void main(String[] args) {\n\t\tScanner scanner = new Scanner(System.in);\n\t\tint accel1 = scanner.nextInt();\n\t\tint initialVal1 = scanner.nextInt();\n\t\tint accel2 = scanner.nextInt();\n\t\tint initialVal2 = scanner.nextInt();\n\t\tint time = checkHit(accel1, initialVal1, accel2, initialVal2);\n\t\tSystem.out.println(time);\n\t}\n\n\tprivate static int checkHit(int accel1, int initialVal1, int accel2, int initialVal2) {\n\t\tif(initialVal1 % 2 != initialVal2 % 2 && accel1 % 2 == 0 && accel2 % 2 == 0)\n\t\t\treturn -1;\n\t\tint difference = initialVal2 - initialVal1;\n\t\tint i = 0;\n\t\tint j = 0;\n\t\twhile(i * accel1 - j * accel2 != difference) {\n\t\t\tif(i * accel1 - j * accel2 < difference)\n\t\t\t\ti++;\n\t\t\telse\n\t\t\t\tj++;\n\t\t\tif(i > accel1 * accel2 + 100|| j >= 100 + accel1 * accel2)\n\t\t\t\treturn -1;\n\t\t}\n\t\t\t\n\t\treturn accel1 * i + initialVal1;\n\t}\n}\n", "lang_cluster": "Java", "tags": ["brute force", "math", "number theory"], "code_uid": "7572ba456fcd2f84062bae73e0ed31f7", "src_uid": "158cb12d45f4ee3368b94b2b622693e7", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.lang.*;\npublic class gh\n{\nstatic int w=0;\npublic static void main(String arg[])throws IOException\n{\nBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\nString c=br.readLine();\n String r=\"\";int n=0;\n String l=\"\";\n for(int j=0;j=l.length())\n {\n n=r.length();\n int m=r.length()-l.length();\n for(int i=0;i=0;i--)\n {\n int a=(int)r.charAt(i)-48;\n int b=(int)l.charAt(n-i-1)-48;\n w=((a+b)+d);\n \n d=0;\n if(w>9)\n {\n d=1;\n if(i!=0)\n w=w%10;\n }\n \nString s= new Integer(w).toString();\n\n f =s+f;\n \n }\n int t=0;\n for(int j=0;j0){\n x+=n%10;\n n/=10;\n }\n return x;\n }\n\n\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n while(sum(n)%4!=0){\n n++;\n }\n System.out.println(n);\n \n \n }\n }\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "81065573bb370a3dd4db72421f2c2a34", "src_uid": "bb6fb9516b2c55d1ee47a30d423562d7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main{\n public static void main(String [] args){\n Scanner ler = new Scanner(System.in);\n int resp=0;\n String horas = ler.nextLine();\n char hr[]=horas.toCharArray();\n while(hr[0]!=hr[4]||hr[1]!=hr[3]){\n resp++;\n hr[4]++;\n if(hr[4]=='9'+1){\n hr[4]='0';\n hr[3]++;\n }\n if(hr[3]=='5'+1){\n hr[3]='0';\n hr[1]++;\n }\n if(hr[1]=='9'+1){\n hr[1]='0';\n hr[0]++;\n }\n if(hr[0]=='2'&&hr[1]=='4'){\n hr[0]='0';\n hr[1]='0';\n hr[3]='0';\n hr[4]='0';\n break;\n }\n \n }\n System.out.println(resp);\n }\n}\n// 1507612192946\n", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "cde08d7a03f97ca54fe4509d7d1d5472", "src_uid": "3ad3b8b700f6f34b3a53fdb63af351a5", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\n\npublic class Main {\n\n private static StringBuilder data = new StringBuilder();\n private final static FastReader in = new FastReader();\n\n\n public static void main(String[] args) {\n\n String s=in.line();\n if(s.charAt(0)>'a'&&s.charAt(0)<'h'&&s.charAt(1)>'1'&&s.charAt(1)<'8'){\n System.out.println(8);\n }else if((s.charAt(0)=='a'||s.charAt(0)=='h')&&(s.charAt(1)=='1'||s.charAt(1)=='8')){\n System.out.println(3);\n }else{\n System.out.println(5);\n }\n }\n\n\n static void fileOut(String s) {\n File out = new File(\"output.txt\");\n try {\n FileWriter fw = new FileWriter(out);\n fw.write(s);\n fw.flush();\n fw.close();\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n\n static class FastReader {\n BufferedReader br;\n StringTokenizer st;\n\n public FastReader() {\n br = new BufferedReader(new\n InputStreamReader(System.in));\n }\n\n public FastReader(String path) {\n try {\n br = new BufferedReader(new\n InputStreamReader(new FileInputStream(path)));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int inT() {\n return Integer.parseInt(next());\n }\n\n long lonG() {\n return Long.parseLong(next());\n }\n\n float floaT() {\n return Float.parseFloat(next());\n }\n\n double doublE() {\n return Double.parseDouble(next());\n }\n\n\n String line() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n }\n\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "5af0c0e388a1790ac5165dcd0effbd7b", "src_uid": "6994331ca6282669cbb7138eb7e55e01", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "/* package whatever; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Ideone\n{\n public static void main (String[] args) throws java.lang.Exception\n {\n Scanner sc = new Scanner(System.in);\n int n=sc.nextInt();\n for(int i=1;i*(i+1)<=n;i++)\n {\n int j=(int)Math.sqrt(2*n-i*(i+1));\n if(j>=0 && i*(i+1)+(j*(j+1))==2*n)\n {\n System.out.println(\"YES\");\n return;\n }\n }\n System.out.println(\"NO\");\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "implementation", "binary search"], "code_uid": "15767ecad9eb49cad1bd008425aa067f", "src_uid": "245ec0831cd817714a4e5c531bffd099", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.UncheckedIOException;\nimport java.io.Closeable;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, new TaskAdapter(), \"\", 1 << 27);\n thread.start();\n thread.join();\n }\n\n static class TaskAdapter implements Runnable {\n @Override\n public void run() {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastInput in = new FastInput(inputStream);\n FastOutput out = new FastOutput(outputStream);\n DPickingStrings solver = new DPickingStrings();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class DPickingStrings {\n public void solve(int testNumber, FastInput in, FastOutput out) {\n int limit = (int) 1e5;\n char[] S = new char[limit];\n char[] T = new char[limit];\n\n int n = in.readString(S, 0);\n int m = in.readString(T, 0);\n int[] a = new int[n];\n int[] b = new int[m];\n int[] aLeft = new int[n];\n int[] bLeft = new int[m];\n for (int i = 0; i < n; i++) {\n a[i] = S[i] == 'A' ? 0 : 1;\n aLeft[i] = i == 0 ? -1 : aLeft[i - 1];\n if (a[i] == 1) {\n aLeft[i] = i;\n }\n }\n for (int i = 0; i < m; i++) {\n b[i] = T[i] == 'A' ? 0 : 1;\n bLeft[i] = i == 0 ? -1 : bLeft[i - 1];\n if (b[i] == 1) {\n bLeft[i] = i;\n }\n }\n\n IntegerPreSum psA = new IntegerPreSum(a);\n IntegerPreSum psB = new IntegerPreSum(b);\n\n int q = in.readInt();\n for (int i = 0; i < q; i++) {\n int l1 = in.readInt() - 1;\n int r1 = in.readInt() - 1;\n int l2 = in.readInt() - 1;\n int r2 = in.readInt() - 1;\n\n int c1 = psA.intervalSum(l1, r1);\n int c2 = psB.intervalSum(l2, r2);\n if (c2 < c1 || (c2 - c1) % 2 == 1) {\n out.append(0);\n continue;\n }\n int len1 = r1 - Math.max(l1 - 1, aLeft[r1]);\n int len2 = r2 - Math.max(l2 - 1, bLeft[r2]);\n if (c2 == c1) {\n if (len2 > len1 || (len1 - len2) % 3 != 0) {\n out.append(0);\n } else {\n out.append(1);\n }\n continue;\n }\n if (c2 > 0 && c1 == 0) {\n len2++;\n }\n if (len2 > len1) {\n out.append(0);\n } else {\n out.append(1);\n }\n }\n }\n\n }\n\n static class IntegerPreSum {\n private int[] pre;\n private int n;\n\n public IntegerPreSum(int n) {\n pre = new int[n];\n }\n\n public void populate(int[] a) {\n n = a.length;\n pre[0] = a[0];\n for (int i = 1; i < n; i++) {\n pre[i] = pre[i - 1] + a[i];\n }\n }\n\n public IntegerPreSum(int[] a) {\n this(a.length);\n populate(a);\n }\n\n public int intervalSum(int l, int r) {\n return prefix(r) - prefix(l - 1);\n }\n\n public int prefix(int i) {\n if (i < 0) {\n return 0;\n }\n return pre[Math.min(i, n - 1)];\n }\n\n }\n\n static class FastOutput implements AutoCloseable, Closeable, Appendable {\n private StringBuilder cache = new StringBuilder(10 << 20);\n private final Writer os;\n\n public FastOutput append(CharSequence csq) {\n cache.append(csq);\n return this;\n }\n\n public FastOutput append(CharSequence csq, int start, int end) {\n cache.append(csq, start, end);\n return this;\n }\n\n public FastOutput(Writer os) {\n this.os = os;\n }\n\n public FastOutput(OutputStream os) {\n this(new OutputStreamWriter(os));\n }\n\n public FastOutput append(char c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput append(int c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput flush() {\n try {\n os.append(cache);\n os.flush();\n cache.setLength(0);\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n return this;\n }\n\n public void close() {\n flush();\n try {\n os.close();\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n public String toString() {\n return cache.toString();\n }\n\n }\n\n static class FastInput {\n private final InputStream is;\n private byte[] buf = new byte[1 << 20];\n private int bufLen;\n private int bufOffset;\n private int next;\n\n public FastInput(InputStream is) {\n this.is = is;\n }\n\n private int read() {\n while (bufLen == bufOffset) {\n bufOffset = 0;\n try {\n bufLen = is.read(buf);\n } catch (IOException e) {\n bufLen = -1;\n }\n if (bufLen == -1) {\n return -1;\n }\n }\n return buf[bufOffset++];\n }\n\n public void skipBlank() {\n while (next >= 0 && next <= 32) {\n next = read();\n }\n }\n\n public int readInt() {\n int sign = 1;\n\n skipBlank();\n if (next == '+' || next == '-') {\n sign = next == '+' ? 1 : -1;\n next = read();\n }\n\n int val = 0;\n if (sign == 1) {\n while (next >= '0' && next <= '9') {\n val = val * 10 + next - '0';\n next = read();\n }\n } else {\n while (next >= '0' && next <= '9') {\n val = val * 10 - next + '0';\n next = read();\n }\n }\n\n return val;\n }\n\n public int readString(char[] data, int offset) {\n skipBlank();\n\n int originalOffset = offset;\n while (next > 32) {\n data[offset++] = (char) next;\n next = read();\n }\n\n return offset - originalOffset;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["strings", "constructive algorithms", "implementation"], "code_uid": "a3cc01f05ea56a03a19cc12ba0951147", "src_uid": "98e3182f047a7e7b10be7f207b219267", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.math.BigInteger;\npublic class A66 {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n BigInteger x = sc.nextBigInteger();\n if((x.compareTo(BigInteger.valueOf(127)) <= 0) && (x.compareTo(BigInteger.valueOf(-128)) >= 0)){\n System.out.println(\"byte\");\n }\n else if((x.compareTo(BigInteger.valueOf(32767)) <= 0) && (x.compareTo(BigInteger.valueOf(-32768)) >= 0)){\n System.out.println(\"short\");\n }\n else if((x.compareTo(BigInteger.valueOf(2147483647)) <= 0) && (x.compareTo(BigInteger.valueOf(-2147483648)) >= 0)){\n System.out.println(\"int\");\n }\n else if((x.compareTo(BigInteger.valueOf(9223372036854775807L)) <= 0) && (x.compareTo(BigInteger.valueOf(-9223372036854775808L)) >= 0)){\n System.out.println(\"long\");\n }\n else System.out.println(\"BigInteger\");\n }\n \n}", "lang_cluster": "Java", "tags": ["strings", "implementation"], "code_uid": "dd7bfab7d9173bfda5e251de91e4d190", "src_uid": "33041f1832fa7f641e37c4c638ab08a1", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "//package round51;\n\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.BitSet;\nimport java.util.Scanner;\n\npublic class D {\n\tScanner in;\n\tPrintWriter out;\n//\tString INPUT = \"10 1 9000000000000000000 1 9000000000000000000 1 9000000000000000000 1 9000000000000000000 1 9000000000000000000 1 9000000000000000000 1 9000000000000000000 1 9000000000000000000 1 9000000000000000000 1 9000000000000000000\";\n//\tString INPUT = \"1 12 15\";\n//\tString INPUT = \"1 1 9\";\n\tString INPUT = \"\";\n\tint[] imap = new int[48];\n\tint[][] u = new int[48][10];\n\t\n\tvoid solve()\n\t{\n\t\tBitSet bs = new BitSet();\n\t\tbs.set(1, 10);\n\t\tint p = 0;\n\t\tfor(int i = bs.nextSetBit(0);i != -1;i = bs.nextSetBit(i+1)){\n\t\t\tfor(int j = bs.nextSetBit(i+1);j != -1;j = bs.nextSetBit(j+1)){\n\t\t\t\tbs.set(i*j/gcd(i,j));\n\t\t\t}\n\t\t\timap[p++] = i;\n\t\t}\n//\t\ttr(bs.cardinality());\n\t\t\n\t\tfor(int i = 0;i < 48;i++){\n\t\t\tfor(int j = 1;j <= 9;j++){\n\t\t\t\tint lcm = imap[i] * j / gcd(imap[i], j);\n\t\t\t\tfor(int k = 0;k < 48;k++){\n\t\t\t\t\tif(lcm == imap[k]){\n\t\t\t\t\t\tu[i][j] = k;\n\t\t\t\t\t\tif(j == 1)u[i][0] = u[i][1];\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor(int i = 0;i < 2520;i++){\n\t\t\tfor(int j = 0;j <= 9;j++){\n\t\t\t\tmomo[i][j] = (10*i+j)%2520;\n\t\t\t}\n\t\t}\n\t\t\n\t\tint t = ni();\n\t\tlong s = System.currentTimeMillis();\n\t\tfor(int i = 0;i < t;i++){\n\t\t\tlong l = in.nextLong();\n\t\t\tlong r = in.nextLong();\n\t\t\tout.println(count(r) - count(l-1));\n\t\t}\n\t\tlong g = System.currentTimeMillis();\n\t\ttr(g-s+\"ms\");\n\t}\n\t\n\tint[][] momo = new int[2520][10];\n\tlong[][][] dp = new long[19][48][2520];\n\t\n\tint gcd(int a, int b)\n\t{\n\t\twhile(b > 0){\n\t\t\tint c = a; a = b; b = c % b;\n\t\t}\n\t\treturn a;\n\t}\n\t\n\tlong count(long n)\n\t{\n\t\tfor(int i = 0;i < 19;i++){\n\t\t\tfor(int j = 0;j < 48;j++){\n\t\t\t\tArrays.fill(dp[i][j], 0);\n\t\t\t}\n\t\t}\n\t\t\n\t\tchar[] ch = Long.toString(n).toCharArray();\n\t\tint code = 0;\n\t\tint mod = 0;\n\t\tfor(int i = 0, j = 19 - ch.length;i < ch.length;i++,j++){\n\t\t\tint sup = i == ch.length - 1 ? ch[i] + 1 : ch[i];\n\t\t\tfor(char c = '0';c < sup;c++){\n\t\t\t\tint d = c - '0';\n\t\t\t\tdp[j][u[code][d]][momo[mod][d]] = 1;\n\t\t\t}\n\t\t\tcode = u[code][ch[i] - '0'];\n\t\t\tmod = momo[mod][ch[i]-'0'];\n\t\t}\n\t\tfor(int i = 0;i < 18;i++){\n\t\t\tfor(int j = 0;j < 48;j++){\n\t\t\t\tfor(int k = 0;k < 2520;k++){\n\t\t\t\t\tif(dp[i][j][k] > 0){\n\t\t\t\t\t\tfor(int l = 0;l <= 9;l++){\n\t\t\t\t\t\t\tdp[i+1][u[j][l]][momo[k][l]] += dp[i][j][k];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tlong ct = 0;\n\t\tfor(int j = 0;j < 48;j++){\n\t\t\tfor(int k = 0;k < 2520;k+=imap[j]){\n\t\t\t\tct += dp[18][j][k];\n\t\t\t}\n\t\t}\n\t\treturn ct;\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tin = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);\n\t\tout = new PrintWriter(System.out);\n\n\t\tsolve();\n\t\tout.flush();\n\t}\n\t\n\t\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tnew D().run();\n\t}\n\t\n\tint ni() { return Integer.parseInt(in.next()); }\n\tvoid tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "tags": ["dp", "number theory"], "code_uid": "d0c655b60d7c213b8f458f54a00225a7", "src_uid": "37feadce373f728ba2a560b198ca4bc9", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\n\npublic class Main {\n public static void main(String[] args) {\n Scanner r = new Scanner(System.in);\n \n int n = r.nextInt();\n int m = r.nextInt();\n int k = r.nextInt();\n \n if(n % 2 == 0){\n System.out.println(\"Marsel\");\n }else{\n boolean can = false;\n for(int d = 1; d * d <= m; d++)if( m % d == 0 ){\n// System.out.println(d);\n if((m / d > 1 && d >= k) || (d > 1 && m / d >= k))can = true;\n }\n \n if(can)System.out.println(\"Timur\");\n else System.out.println(\"Marsel\");\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["dp", "number theory", "games"], "code_uid": "2a15e6e3a64d77d83b4b462b290f0e72", "src_uid": "4a3767011ddac874efa021fff7c94432", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class D1195 {\n public static int[] findMin(int[] a, int window) {\n int[] result = new int[a.length - window + 1];\n Deque deque = new ArrayDeque<>();\n for (int i = 0; i < a.length; i++) { // Range end index (inclusive)\n int val = a[i];\n while (!deque.isEmpty() && val < deque.getLast())\n deque.removeLast();\n deque.addLast(val);\n\n int j = i + 1 - window; // Range start index, does not overflow\n if (j >= 0) {\n result[j] = deque.getFirst();\n if (a[j] == result[j])\n deque.removeFirst();\n }\n }\n return result;\n }\n public static void main(String[] args) {\n Scanner f = new Scanner(System.in);\n int n = f.nextInt(),m=f.nextInt(),a=f.nextInt(),b=f.nextInt();\n long g0=f.nextInt(),x=f.nextInt(),y=f.nextInt(),z=f.nextInt();\n int[][] A = new int[n][m], minrow = new int[n][m-b+1], min = new int[m-b+1][n-a+1];\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n if (i != 0 || j != 0) g0 = (g0 * x + y) % z;\n A[i][j] = (int) g0;\n }\n }\n// System.out.println(Arrays.deepToString(A));\n for (int i = 0; i < n; i++) {\n minrow[i] = findMin(A[i], b);\n }\n int[][] minrowT = new int[m-b+1][n];\n for (int i = 0; i < m-b+1; i++) {\n for (int j = 0; j < n; j++) {\n minrowT[i][j] = minrow[j][i];\n }\n }\n// System.out.println(Arrays.deepToString(minrow));\n for (int i = 0; i < m-b+1; i++) {\n min[i] = findMin(minrowT[i], a);\n }\n// System.out.println(Arrays.deepToString(min));\n long ans = 0;\n for (int i = 0; i < m-b+1; i++) {\n for (int j = 0; j < n-a+1; j++) {\n ans += min[i][j];\n }\n }\n System.out.println(ans);\n }\n}\n", "lang_cluster": "Java", "tags": ["two pointers", "data structures"], "code_uid": "62fe09a601ad3f06ff1a55d14a38bb43", "src_uid": "4618fbffb2b9d321a6d22c11590a4773", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.readInt();\n int a[] = new int[n];\n for (int i = 0; i < n ;i++) a[i] = in.readInt();\n Arrays.sort(a);\n for (int i = 0; i < n ;i++) out.print(a[i] + \" \");\n }\n}\n\nclass InputReader {\n\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n}\n\n", "lang_cluster": "Java", "tags": ["sortings", "implementation", "greedy"], "code_uid": "e1b3f846312ecc1e01ae856e3333ce0f", "src_uid": "ae20712265d4adf293e75d016b4b82d8", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class WordCorrection {\n\n\tstatic String vowel = \"aeiouy\";\n\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner sc = new Scanner(System.in);\n\t\twhile (sc.hasNextLine())\n\t\t{\n\t\t\tsc.nextLine();\n\t\t\tString word = sc.nextLine();\n\t\t\twhile (consecutive(word))\n\t\t\t{\n\t\t\t\tword = remove(word);\n\t\t\t}\n\t\t\tSystem.out.println(word);\n\t\t}\n\t\tsc.close();\n\t}\n\n\tpublic static boolean consecutive(String s)\n\t{\n\t\tfor (int i = 0; i < s.length() - 1; i++)\n\t\t\tif (vowel.indexOf(s.substring(i,i+1)) != -1 && vowel.indexOf(s.substring(i+1, i+2)) != -1)\n\t\t\t\treturn true;\n\t\treturn false;\n\t}\n\n\tpublic static String remove(String s)\n\t{\n\t\tfor (int i = 0; i < s.length() - 1; i++)\n\t\t\tif (vowel.indexOf(s.substring(i,i+1)) != -1 && vowel.indexOf(s.substring(i+1, i+2)) != -1)\n\t\t\t\treturn s.substring(0,i + 1) + s.substring(i + 2);\n\t\treturn \"\";\n\t}\n\t\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "99d23c2af90f8abce83ea27b9aef1b58", "src_uid": "63a4a5795d94f698b0912bb8d4cdf690", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.List;\nimport java.util.Scanner;\n\n/**\n *\n * @author hossam\n */\npublic class Ps {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n String s=in.next();\n int m=1;\n int a[]={2,7,2,3,3,4,2,5,1,2};\n for(int i=0;i ss = new HashSet<>();\n int cnt = 0;\n for (int i=0; i= 'A' && y <= 'J') {\n int num = y - 'A';\n if (ss.contains(num)) continue;\n ss.add(num);\n if (i==0) ans = ans.multiply(nine);\n else {\n int yy = 11 - ss.size();\n ans = ans.multiply(new BigInteger(String.valueOf(yy)));\n }\n }\n }\n\n System.out.print(ans);\n for(int i=0;i m = new HashMap<>(); \n\tlong max = -1;\n\tpublic Main4() throws Exception {\n\n\t\tBufferedWriter out;\n\t\ttry {\n\t\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\t\t\n\t\t\tString s[] = in.readLine().split(\" \");\n\t\t\tint r = Integer.parseInt(s[0]);\n\t\t\tint b = Integer.parseInt(s[1]);\n\t\t\tfor(int i=0; i availableBooks = new HashSet<>(k);\n int[] access = new int[81];\n int removable = -1;\n for (int i = 0; i < n; i++) {\n access[query[i]]++;\n }\n for (int i = 0; i < n; i++) {\n int currentBook = query[i];\n boolean doesNotContain = !availableBooks.contains(currentBook);\n if (doesNotContain) {\n cost++;\n }\n if (removable != -1) {\n availableBooks.remove(removable);\n removable = -1;\n } else if (availableBooks.size() == k && doesNotContain) {\n int removableBook = -1;\n int count = k;\n Set known = new HashSet<>();\n for (int j = i + 1; j < n && count > 0; j++) {\n if (availableBooks.contains(query[j]) && !known.contains(query[j])) {\n count--;\n known.add(query[j]);\n removableBook = query[j];\n }\n }\n if (removableBook != -1) {\n availableBooks.remove(removableBook);\n } else {\n availableBooks.remove(availableBooks.iterator().next());\n }\n }\n availableBooks.add(currentBook);\n if (--access[currentBook] == 0) {\n removable = currentBook;\n }\n }\n out.println(cost);\n }\n\n }\n\n static class FastIO {\n\n final private int BUFFER_SIZE = 1 << 16;\n private InputStream din;\n private byte[] buffer;\n private int bufferPointer;\n private int bytesRead;\n\n public FastIO() {\n buffer = new byte[BUFFER_SIZE];\n bufferPointer = bytesRead = 0;\n }\n\n public FastIO(InputStream inputStream) {\n this();\n din = new DataInputStream(inputStream);\n }\n\n public FastIO(String file_name) {\n try {\n din = new DataInputStream(new FileInputStream(file_name));\n buffer = new byte[BUFFER_SIZE];\n bufferPointer = bytesRead = 0;\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n\n public int nextInt() {\n int ret = 0;\n try {\n byte c = read();\n while (c <= ' ') {\n c = read();\n }\n boolean neg = (c == '-');\n if (neg) {\n c = read();\n }\n do {\n ret = ret * 10 + c - '0';\n } while ((c = read()) >= '0' && c <= '9');\n\n if (neg) {\n return -ret;\n }\n } catch (Exception e) {\n e.printStackTrace();\n }\n return ret;\n }\n\n public int[] nextIntArray(int n) {\n int[] arr = new int[n];\n for (int i = 0; i < n; i++) {\n arr[i] = nextInt();\n }\n return arr;\n }\n\n private void fillBuffer() {\n try {\n bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n if (bytesRead == -1) {\n buffer[0] = -1;\n }\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n\n private byte read() {\n if (bufferPointer == bytesRead) {\n fillBuffer();\n }\n return buffer[bufferPointer++];\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["greedy"], "code_uid": "85af70e9511d21e0424665fe4aa66c3b", "src_uid": "956228e31679caa9952b216e010f9773", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class B_Door_Frames {\n\n\t@SuppressWarnings(\"resource\")\n\tpublic static void main(String[] args) {\n\t\tScanner input = new Scanner(System.in);\n\t\tint n = input.nextInt();\n\t\tint a = input.nextInt();\n\t\tint b = input.nextInt();\n\t\tif (2 * b + 4 * a <= n){\n\t\t\tSystem.out.println(1);\n\t\t}else if (b + 2 * a <= n){\n\t\t\tSystem.out.println(2);\n\t\t}else if (4 * a <= n || 2 * b <= n && 2 * a <= n || a + b <= n && 2 * a <= n){\n\t\t\tSystem.out.println(3);\n\t\t}else if (a + b <= n || 2 * a <= n){\n\t\t\tSystem.out.println(4);\n\t\t}else if (2 * b <= n){\n\t\t\tSystem.out.println(5);\n\t\t}else{\n\t\t\tSystem.out.println(6);\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["greedy", "implementation"], "code_uid": "118cc618ba78be61a3db80b189b04d5f", "src_uid": "1a50fe39e18f86adac790093e195979a", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n//import java.lang.*;\n\npublic class ranjan{\n\n //public static Read cin;\n public static InputReader cin;\n public static PrintWriter cout;\n public static int[] visited;\n public static final long bil = (long)1e9+7;\n public static int fileread = 0; \n \n public static void main(String ...arg) throws IOException\n {\n /*console writer*/\n cout = new PrintWriter(new BufferedOutputStream(System.out));\n /*Debug Reader*/\n //Scan cin =new Scan();\n if(fileread == 1)\n {\n try\n {\n //cin = new Read(new FileInputStream(new File(\"in1.txt\")));\n cin = new InputReader(new FileInputStream(new File(\"in4.txt\")));\n }\n catch (IOException error){}\n }\n else{\n //cin = new Read(System.in);\n cin = new InputReader(System.in);\n }\n\n long t1 = cin.nextInt();\n long t2 = cin.nextInt();\n long x1 = cin.nextInt();\n long x2 = cin.nextInt();\n long t0 = cin.nextInt();\n\n if(t1 == t2)\n {\n cout.print(x1+\" \"+x2);\n cout.close();\n return;\n }\n\n long y1=-1,y2 = -1;\n double RHS = (double)(t0 - t1)/(t2 - t0),temp = (double)Double.MAX_VALUE;\n for(long i=x1;i>=0;i--)\n {\n long j = (int)Math.ceil(RHS*i);\n double t = (double)(t1*i + t2*j)/(i+j);\n if(j<=x2 && t V getOrDefault(HashMap map, K key, V defaultValue) {\n return map.containsKey(key) ? map.get(key) : defaultValue;\n }\n \n\n public static long mod_pow(long x,long n,long mod) {\n long res=1;\n while(n>0) {\n if((n&1)==1)res=res*x%mod;\n x=x*x%mod;\n n>>=1;\n }\n return res;\n }\n public static int gcd(int n1, int n2) \n {\n int r;\n while (n2 != 0) \n {\n r = n1 % n2;\n n1 = n2;\n n2 = r;\n }\n return n1;\n }\n \n /*public static int lcm(int n1, int n2) \n {\n int answer = (n1 * n2) / (gcd(n1, n2));\n return answer;\n }*/\n\n\n static class InputReader {\n final InputStream is;\n final byte[] buf = new byte[1024];\n int pos;\n int size;\n \n public InputReader(InputStream is) {\n this.is = is;\n }\n \n public int nextInt() {\n int c = read();\n while (isWhitespace(c))\n c = read();\n int sign = 1;\n if (c == '-') {\n sign = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res = res * 10 + c - '0';\n c = read();\n } while (!isWhitespace(c));\n return res * sign;\n }\n \n int read() {\n if (size == -1)\n throw new InputMismatchException();\n if (pos >= size) {\n pos = 0;\n try {\n size = is.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (size <= 0)\n return -1;\n }\n return buf[pos++] & 255;\n }\n \n static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n \n }\n\nstatic class RecursionLimiter {\n public static long maxLevel = 100000L;\n\n public static void emerge() {\n if (maxLevel == 0)\n return;\n try {\n throw new IllegalStateException(\"Too deep, emerging\");\n } catch (IllegalStateException e) {\n if (e.getStackTrace().length > maxLevel + 1)\n throw e;\n }\n }\n}\n\n\nstatic class Scan {\n private byte[] buf=new byte[1024];\n private int index;\n private InputStream in;\n private int total;\n public Scan()\n {\n in=System.in;\n }\n public int scan()throws IOException\n {\n if(total<0)\n throw new InputMismatchException();\n if(index>=total)\n {\n index=0;\n total=in.read(buf);\n if(total<=0)\n return -1;\n }\n return buf[index++];\n }\n public int scanInt()throws IOException\n {\n int integer=0;\n int n=scan();\n while(isWhiteSpace(n))\n n=scan();\n int neg=1;\n if(n=='-')\n {\n neg=-1;\n n=scan();\n }\n while(!isWhiteSpace(n))\n {\n if(n>='0'&&n<='9')\n {\n integer*=10;\n integer+=n-'0';\n n=scan();\n }\n else throw new InputMismatchException();\n }\n return neg*integer;\n }\n public double scanDouble()throws IOException\n {\n double doub=0;\n int n=scan();\n while(isWhiteSpace(n))\n n=scan();\n int neg=1;\n if(n=='-')\n {\n neg=-1;\n n=scan();\n }\n while(!isWhiteSpace(n)&&n!='.')\n {\n if(n>='0'&&n<='9')\n {\n doub*=10;\n doub+=n-'0';\n n=scan();\n }\n else throw new InputMismatchException();\n }\n if(n=='.')\n {\n n=scan();\n double temp=1;\n while(!isWhiteSpace(n))\n {\n if(n>='0'&&n<='9')\n {\n temp/=10;\n doub+=(n-'0')*temp;\n n=scan();\n }\n else throw new InputMismatchException();\n }\n }\n return doub*neg;\n }\n public String scanString()throws IOException\n {\n StringBuilder sb=new StringBuilder();\n int n=scan();\n while(isWhiteSpace(n))\n n=scan();\n while(!isWhiteSpace(n))\n {\n sb.append((char)n);\n n=scan();\n }\n return sb.toString();\n }\n private boolean isWhiteSpace(int n)\n {\n if(n==' '||n=='\\n'||n=='\\r'||n=='\\t'||n==-1)\n return true;\n return false;\n }\n }\n\n}\n\nclass Read\n{\n private BufferedReader br;\n private StringTokenizer st;\n\n public Read(InputStream is)\n { br = new BufferedReader(new InputStreamReader(is)); }\n\n String next()\n {\n while (st == null || !st.hasMoreElements())\n {\n try {st = new StringTokenizer(br.readLine());}\n catch(IOException e)\n {e.printStackTrace();}\n }\n return st.nextToken();\n }\n\n int nextInt()\n { return Integer.parseInt(next()); }\n\n long nextLong()\n { return Long.parseLong(next()); }\n\n double nextDouble()\n { return Double.parseDouble(next()); }\n\n String nextLine()\n {\n String str = \"\";\n try {str = br.readLine();}\n catch(IOException e)\n {e.printStackTrace();}\n return str;\n }\n}\n\n\n", "lang_cluster": "Java", "tags": ["brute force", "math", "binary search"], "code_uid": "2a4a3cac86fce2f28d3beeeac90fb31d", "src_uid": "87a500829c1935ded3ef6e4e47096b9f", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\npublic class C {\n\n public static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n public static StringTokenizer tok;\n\n public static int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n public static long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n public static double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n public static String nextToken() throws IOException {\n if (tok == null || !tok.hasMoreTokens()) {\n tok = new StringTokenizer(in.readLine());\n }\n return tok.nextToken();\n }\n\n public static void main(String[] args) throws IOException {\n int n = nextInt();\n int m = nextInt();\n List> graph = new ArrayList<>(n);\n for (int i = 0; i < n; i++) {\n graph.add(new HashSet<>());\n }\n for (int i = 0; i < m; i++) {\n int u = nextInt() - 1;\n int v = nextInt() - 1;\n graph.get(u).add(v);\n graph.get(v).add(u);\n }\n List> reverse = new ArrayList<>(n);\n for (int i = 0; i < n; i++) {\n reverse.add(new HashSet<>());\n for (int j = 0; j < n; j++) {\n if (i != j && !graph.get(i).contains(j)) {\n reverse.get(i).add(j);\n }\n }\n }\n ArrayList line = new ArrayList<>(n);\n for (int i = 0; i < n; i++) {\n line.add(null);\n }\n Queue queue = new LinkedList<>();\n int index = -1;\n for (int i = 0; i < n; i++) {\n if (reverse.get(i).isEmpty()) {\n line.set(i, 'b');\n } else if (index == -1) {\n index = i;\n }\n }\n if (index != -1) {\n queue.add(index);\n line.set(index, 'a');\n while (!queue.isEmpty()) {\n int x = queue.remove();\n char other = line.get(x) == 'a' ? 'c' : 'a';\n for (int near: reverse.get(x)) {\n if (line.get(near) == null) {\n line.set(near, other);\n queue.add(near);\n } else if (line.get(x) == line.get(near)) {\n System.out.println(\"No\");\n return;\n }\n }\n }\n }\n for (int i = 0; i < n; i++) {\n if (line.get(i) == null) {\n System.out.println(\"No\");\n return;\n }\n }\n for (int i = 0; i < n; i++) {\n for (int near: graph.get(i)) {\n if (line.get(i) == 'a' && line.get(near) == 'c' || line.get(i) == 'c' && line.get(near) == 'a') {\n System.out.println(\"No\");\n return;\n }\n }\n }\n System.out.println(\"Yes\");\n for (int i = 0; i < n; i++) {\n System.out.print(line.get(i));\n }\n }\n}", "lang_cluster": "Java", "tags": ["constructive algorithms", "graphs"], "code_uid": "1824321a0ccdecce1d49db46c9579c93", "src_uid": "e71640f715f353e49745eac5f72e682a", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class gg{\n\tstatic int special(int u, int k,int []a){\n\t\tif(a[u]==1)\n\t\t\treturn k-u;\n\t\tif(a[k]==1000)\n\t\t\treturn k-u;\n\t\telse\n\t\t\treturn k-u-1;\n\t}\n\tpublic static void main(String[] args) {\n\t\tScanner sc=new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\tint a[]=new int[n];\n\t\tint i,max=0;\n\t\tfor(i=0;imax)\n\t\t\t\t\tmax=l;\n\t\t\t\t//c=c+l;\n\t\t\t\t//if(l!=0)\n\t\t\t\t//break;\n\t\t\t}\n\t\t}\n\t\tif(!g)\n\t\t{\n\t\t\tk=n-1;\n\t\t\tl=special(u,k,a);\n\t\t\tif(l>max)\n\t\t\tmax=l;\n\t\t}\n\t\t//System.out.println(u+\" \"+k);\n\t\tSystem.out.println(max);\n\t}\n}", "lang_cluster": "Java", "tags": ["greedy", "implementation"], "code_uid": "e2c6ab3538d7206f5f3938d5cedf58c2", "src_uid": "858b5e75e21c4cba6d08f3f66be0c198", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tScanner sc=new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\tString s=sc.next();\n\t\tchar c[]=s.toCharArray();\n\t\tchar aa='1',bb='1';\n\t\tint max=-1;\n\t\tfor(int i=0;imax){\n\t\t\t\tmax=con;\n\t\t\t\taa=a;bb=b;\n\t\t\t}else if(con==max&&(a 1 ? 1 : 0;\n\t\tfor (double i = 2.0; i <= n / 2; i++) {\n\t\t\tif ((n - i) % i == 0) {\n\t\t\t\tres++;\n\t\t\t}\n\t\t}\n\t\tout.println(res);\n\t\tout.flush();\n\t\tout.close();\n\n\t}\n\n\tstatic class EhabReader {\n\t\tfinal private int BUFFER_SIZE = 1 << 16;\n\t\tprivate DataInputStream din;\n\t\tprivate byte[] buffer;\n\t\tprivate int bufferPointer, bytesRead;\n\n\t\tpublic EhabReader() {\n\t\t\tdin = new DataInputStream(System.in);\n\t\t\tbuffer = new byte[BUFFER_SIZE];\n\t\t\tbufferPointer = bytesRead = 0;\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\t// TODO Auto-generated method stub\n\t\t\treturn null;\n\t\t}\n\n\t\tpublic EhabReader(String file_name) throws IOException {\n\t\t\tdin = new DataInputStream(new FileInputStream(file_name));\n\t\t\tbuffer = new byte[BUFFER_SIZE];\n\t\t\tbufferPointer = bytesRead = 0;\n\t\t}\n\n\t\tpublic String readLine() throws IOException {\n\t\t\tbyte[] buf = new byte[1000]; // line length\n\t\t\tint cnt = 0, c;\n\t\t\twhile ((c = read()) != -1) {\n\t\t\t\tif (c == '\\n')\n\t\t\t\t\tbreak;\n\t\t\t\tbuf[cnt++] = (byte) c;\n\t\t\t}\n\t\t\treturn new String(buf, 0, cnt);\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\tint ret = 0;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\t\t\tdo {\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\t} while ((c = read()) >= '0' && c <= '9');\n\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\n\t\tpublic long nextLong() throws IOException {\n\t\t\tlong ret = 0;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\t\t\tdo {\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\t} while ((c = read()) >= '0' && c <= '9');\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\tdouble ret = 0, div = 1;\n\t\t\tbyte c = read();\n\t\t\twhile (c <= ' ')\n\t\t\t\tc = read();\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg)\n\t\t\t\tc = read();\n\n\t\t\tdo {\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\t} while ((c = read()) >= '0' && c <= '9');\n\n\t\t\tif (c == '.') {\n\t\t\t\twhile ((c = read()) >= '0' && c <= '9') {\n\t\t\t\t\tret += (c - '0') / (div *= 10);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\n\t\tprivate void fillBuffer() throws IOException {\n\t\t\tbytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n\t\t\tif (bytesRead == -1)\n\t\t\t\tbuffer[0] = -1;\n\t\t}\n\n\t\tprivate byte read() throws IOException {\n\t\t\tif (bufferPointer == bytesRead)\n\t\t\t\tfillBuffer();\n\t\t\treturn buffer[bufferPointer++];\n\t\t}\n\n\t\tpublic void close() throws IOException {\n\t\t\tif (din == null)\n\t\t\t\treturn;\n\t\t\tdin.close();\n\t\t}\n\t}\n}", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "71c971f0863f50ccafe21609ebcada68", "src_uid": "89f6c1659e5addbf909eddedb785d894", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Test {\n\tpublic static void main(String[]Args)\n\t{\n\t\tScanner A = new Scanner(System.in);\n\t\tint x = A.nextInt();\n\t\tint b = 0;//helper(x,1);\n\t\twhile(x > 4)\n\t\t\tx -= 4;\n\t\tswitch(x){\n\t\tcase 4: b = 6;break;\n\t\tcase 3: b = 2;break;\n\t\tcase 2: b = 4;break;\n\t\tcase 1: b = 8;break;\n\t\tdefault: b = 1;\n\t\t}\n\t\tSystem.out.print(b);\n\t}\n\n\tpublic static int helper(int x, int b){\n\t\tif (x == 0){\n\t\t\treturn b;\n\t\t}\n\t\tif(x >= 10000000){\n\t\t\tint counter = 100000;\n\t\t\twhile(counter != 0){\n\t\t\t\tb = b*1378;\n\t\t\t\tb = b%10;\n\t\t\t\tcounter--;\n\t\t\t}\n\t\t\treturn(helper(x-100000, b));\n\t\t}\n\t\tif (x >= 10000)\n\t\t{\n\t\t\tint counter = 1000;\n\t\t\twhile (counter != 0){\n\t\t\t\tb = b*1378;\n\t\t\t\tb = b%10;\n\t\t\t\tcounter--;\n\t\t\t}\n\t\t\treturn helper(x-1000, b);\n\t\t}\n\t\tb *= 1378;\n\t\tb = b%10;\n\t\treturn helper((x-1),b);\n\t\t\n\t}\n\t\t\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation", "number theory"], "code_uid": "2d927fc08bb90ab522e13eb45baa5f60", "src_uid": "4b51b99d1dea367bf37dc5ead08ca48f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\n// warm-up\npublic class VasyaAndTheBus {\n\n\tstatic void solve() {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint a=sc.nextInt(),c=sc.nextInt(),min=0,max=0;\n\t\tif (a==0 && c>0) System.out.println(\"Impossible\");\n\t\telse {\n\t\t\tmin=a+((c>a) ? c-a : 0); \t\t\t\n\t\t\tmax=a+((c>0) ? c-1 : 0);\n\t\t\tSystem.out.println(min+\" \"+max);\t\n\t\t}\n\t\tsc.close();\t\t\n\t}\n\n\tpublic static void main(String args[]) {\n\t\tsolve();\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["math", "greedy"], "code_uid": "0fc826dc64b202370f8014492834a276", "src_uid": "1e865eda33afe09302bda9077d613763", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "/* package codechef; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Codechef\n{\n int arr[],sum;\n Codechef()\n {\n arr=new int[8];\n sum=0;\n Scanner in=new Scanner(System.in);\n for(int i=0;i<5;++i)\n {\n arr[i]=in.nextInt();\n sum+=arr[i]; \n }\n }\n \n int f()\n {\n HashMap hm = new HashMap();\n for(int i=0;i<5;++i)\n {\n if(hm.get(arr[i])!=null)\n {\n int v=hm.get(arr[i]);\n hm.put(arr[i],v+1 );\n }\n else\n {\n hm.put(arr[i],1);\n }\n }\n //System.out.println(sum);\n Set keys=hm.keySet();\n int ans=10000;\n for(int x:keys)\n {\n //System.out.println(x+\" \"+hm.get(x));\n int v=hm.get(x);\n if(v==2)\n {\n ans=Math.min(ans,sum-(2*x));\n }\n else if(v>=3)\n {\n ans=Math.min(ans,sum-(3*x));\n }\n //System.out.println(ans);\n }\n if(ans==10000) return sum;\n return ans;\n }\n \n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t\t// your code goes here\n\t\tCodechef cf=new Codechef();\n\t\tSystem.out.println(cf.f());\n\t}\n}\n", "lang_cluster": "Java", "tags": ["constructive algorithms", "implementation"], "code_uid": "bd614a6c2d7b8c80c604b7d780af9485", "src_uid": "a9c17ce5fd5f39ffd70917127ce3408a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.OutputStream;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.util.StringTokenizer;\nimport java.io.Writer;\nimport java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author zodiacLeo\n */\npublic class Main\n{\n public static void main(String[] args)\n {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastScanner in = new FastScanner(inputStream);\n FastPrinter out = new FastPrinter(outputStream);\n TaskA solver = new TaskA();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskA\n {\n public void solve(int testNumber, FastScanner in, FastPrinter out)\n {\n int n = in.nextInt();\n int S = in.nextInt();\n int[] a = new int[n];\n int sum = 0;\n for (int i = 0; i < n; i++)\n {\n a[i] = in.nextInt();\n sum += a[i];\n }\n\n Arrays.sort(a);\n sum -= a[n - 1];\n if (sum <= S)\n {\n out.println(\"YES\");\n return;\n }\n out.println(\"NO\");\n }\n\n }\n\n static class FastScanner\n {\n public BufferedReader br;\n public StringTokenizer st;\n\n public FastScanner(InputStream is)\n {\n br = new BufferedReader(new InputStreamReader(is));\n }\n\n public FastScanner(File f)\n {\n try\n {\n br = new BufferedReader(new FileReader(f));\n } catch (FileNotFoundException e)\n {\n e.printStackTrace();\n }\n }\n\n public String next()\n {\n while (st == null || !st.hasMoreElements())\n {\n String s = null;\n try\n {\n s = br.readLine();\n } catch (IOException e)\n {\n e.printStackTrace();\n }\n if (s == null)\n return null;\n st = new StringTokenizer(s);\n }\n return st.nextToken();\n }\n\n public int nextInt()\n {\n return Integer.parseInt(next());\n }\n\n }\n\n static class FastPrinter extends PrintWriter\n {\n public FastPrinter(OutputStream out)\n {\n super(out);\n }\n\n public FastPrinter(Writer out)\n {\n super(out);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "666b580397b4f3d1384f6339b5063256", "src_uid": "496baae594b32c5ffda35b896ebde629", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.text.DecimalFormat;\npublic class Main {\n public static void main( String[] args ) {\n Scanner cin = new Scanner( System.in );\n String j = cin.nextLine( );\n String[] h = j.split( \":\" );\n int hour = Integer.parseInt( h[0] );\n int minute = Integer.parseInt( h[1] );\n int temp;\n DecimalFormat print = new DecimalFormat(\"00\");\n do{\n if( minute < 59 )\n minute++;\n else if( hour < 23 ){\n hour++;\n minute = 0;\n }else{\n hour = 0;\n minute = 0;\n }\n temp = minute/10;\n h[0] = print.format(hour);\n h[1] = print.format(((minute%10)*10 + temp) );\n }while( !h[0].equals( h[1] ) );\n System.out.println( h[0]+\":\"+print.format(minute) );\n }\n}", "lang_cluster": "Java", "tags": ["strings", "implementation"], "code_uid": "a65c5d607a5e98f20f2ce3b2683b81b2", "src_uid": "158eae916daa3e0162d4eac0426fa87f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n ProblemBStringTyping solver = new ProblemBStringTyping();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class ProblemBStringTyping {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.readInt();\n String str = in.readLine();\n int ans = str.length();\n String temp = \"\";\n int idx = -1;\n for (int i = temp.length(); i < str.length(); i = temp.length()) {\n String t = str.substring(i);\n if (temp.length() > 0 && t.startsWith(temp)) {\n idx = i;\n }\n temp += str.charAt(i);\n }\n if (idx > 0) ans = ans - idx + 1;\n out.println(ans);\n\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n private String readLine0() {\n StringBuilder buf = new StringBuilder();\n int c = read();\n while (c != '\\n' && c != -1) {\n if (c != '\\r')\n buf.appendCodePoint(c);\n c = read();\n }\n return buf.toString();\n }\n\n public String readLine() {\n String s = readLine0();\n while (s.trim().length() == 0)\n s = readLine0();\n return s;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["strings", "implementation"], "code_uid": "1353e364f7e3f6ea2f943903b5c0de96", "src_uid": "ed8725e4717c82fa7cfa56178057bca3", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.util.Scanner;\npublic class solution{\n public static void main(String args[]){\n Scanner sc =new Scanner(System.in);\n int a=sc.nextInt();\n int b=sc.nextInt();\n int res = a;\n while(a>=b){\n res += (a/b);\n a = (a/b)+(a%b);\n }\n //res += a;\n System.out.println(res); \n }\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "2c104274035ae876f687fd1d37a65ea8", "src_uid": "a349094584d3fdc6b61e39bffe96dece", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class Second {\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t\n\t\tString a = in.nextLine().substring(2);\n\t\tString b = in.nextLine().substring(2);\n\t\tString c = in.nextLine().substring(2);\n\t\tString d = in.nextLine().substring(2);\n\t\tboolean isOka = test(a, b, c, d);\n\t\tboolean isOkb = test(b,a,c,d);\n\t\tboolean isOkd = test(d,a,b,c);\n\t\tboolean isOkc = test(c, a, b, d);\n\t\tif((isOka? 1 :0) + (isOkb? 1 : 0) + (isOkc? 1: 0) + (isOkd? 1 : 0) ==1) {\n\t\t\tif(isOka) out.println(\"A\");\n\t\t\tif(isOkb) out.println(\"B\");\n\t\t\tif(isOkc) out.println(\"C\");\n\t\t\tif(isOkd) out.println(\"D\");\n\t\t}\telse out.println(\"C\");\n\n\t\t\n\t\tout.close();\n\t}\n\n\tprivate static boolean test(String d, String a, String b, String c) {\n\t\treturn (d.length()*2<=a.length() && d.length()*2<=b.length() && d.length()*2<=c.length()) ||\n\t\t\t\t(d.length()>=a.length()*2 && d.length() >= b.length()*2 && d.length() >= c.length()*2);\n\t}\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "7042b89ac4e53d7c3f82cca83b8c6bce", "src_uid": "30725e340dc07f552f0cce359af226a4", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "\nimport java.util.*;\nimport java.io.*;\n\npublic class C {\n\tstatic final int MOD_PRIME = 1000000007;\n\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTask solver = new Task();\n\n\t\tint i = 0;\n\t\tint t = 1;\n\t\t//t = in.nextInt();\n\t\tfor (; i < t; i++)\n\t\t\tsolver.solve(i, in, out);\n\n\t\tout.close();\n\t}\n\n\tstatic class Task {\n\t\tpublic void solve(int testNumber, InputReader in, PrintWriter out) {\n\t\t\tint n = in.nextInt();\n\t\t\tlong m = in.nextLong();\n\t\t\tlong[] fact = new long[n+1];\n\t\t\tfact[0] = 1;\n\t\t\tfor(int i = 1; i <= n; i++) {\n\t\t\t\tfact[i] = (fact[i-1]*i) % m;\n\t\t\t}\n\t\t\tlong total = 0;\n\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\ttotal = (total + (n-i)*((fact[i+1] * fact[n-i]) % m)) % m;\n\t\t\t}\n\t\t\tout.print(total);\n\t\t\t\n\t\t}\n\t}\n\n\t// template code\n\n\tstatic class InputReader {\n\t\tpublic BufferedReader reader;\n\t\tpublic StringTokenizer tokenizer;\n\n\t\tpublic InputReader(InputStream stream) {\n\t\t\treader = new BufferedReader(new InputStreamReader(stream), 32768);\n\t\t\ttokenizer = null;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t}\n\n\tstatic long modexp(long a, long b, long p) {\n\t\t// returns a to the power b mod p by modular exponentiation\n\n\t\tlong res = 1;\n\t\tlong mult = a % p;\n\t\twhile (b > 0) {\n\t\t\tif (b % 2 == 1) {\n\t\t\t\tres = (res * mult) % p;\n\t\t\t}\n\t\t\tb /= 2;\n\t\t\tmult = (mult * mult) % p;\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tstatic double log(double arg, double base) {\n\t\t// returns log of a base b, contains floating point errors, dont use for exact\n\t\t// calculations.\n\n\t\tif (base < 0 || base == 1) {\n\t\t\tthrow new ArithmeticException(\"base cant be 1 or negative\");\n\t\t}\n\t\tif (arg < 0) {\n\t\t\tthrow new ArithmeticException(\"log of negative number undefined\");\n\t\t}\n\t\treturn Math.log10(arg) / Math.log10(base);\n\t}\n\n\tstatic int gcd(int a, int b) {\n\t\tif (b == 0) {\n\t\t\treturn a;\n\t\t}\n\n\t\treturn gcd(b, a % b);\n\n\t}\n\n\tstatic long gcd(long a, long b) {\n\t\tif (b == 0) {\n\t\t\treturn a;\n\t\t}\n\n\t\treturn gcd(b, a % b);\n\n\t}\n\n\t// scope for improvement\n\tstatic ArrayList sieveOfEratosthenes(int n) {\n\t\tboolean[] check = new boolean[n + 1];\n\t\tArrayList prime = new ArrayList();\n\t\tfor (long i = 2; i <= n; i++) {\n\t\t\tif (!check[(int) i]) {\n\t\t\t\tprime.add((int) i);\n\t\t\t\tfor (long j = i * i; j <= n; j += i) {\n\t\t\t\t\tcheck[(int) j] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn prime;\n\t}\n\n\tstatic int modInverse(int a, int n) {\n\t\t// returns inverse of a mod n by extended euclidean algorithm\n\t\tint t = 0;\n\t\tint newt = 1;\n\t\tint r = n;\n\t\tint newr = a;\n\t\tint quotient;\n\t\tint tempr, tempt;\n\t\twhile (newr != 0) {\n\t\t\tquotient = r / newr;\n\t\t\ttempt = newt;\n\t\t\ttempr = newr;\n\t\t\tnewr = r - quotient * tempr;\n\t\t\tnewt = t - quotient * tempt;\n\t\t\tt = tempt;\n\t\t\tr = tempr;\n\t\t}\n\t\tif (r > 1) {\n\t\t\tthrow new ArithmeticException(\"inverse of \" + a + \" mod \" + n + \" does not exist\");\n\t\t} else {\n\t\t\tif (t < 0) {\n\t\t\t\tt += n;\n\t\t\t}\n\t\t\treturn t;\n\t\t}\n\t}\n\n\tstatic int primeModInverse(int a, int n) {\n\t\t// returns inverse of a mod n by mod exponentiation, use only if n is prime\n\t\treturn (int) modexp(a, n - 2, n);\n\t}\n\n\tstatic void dfs(HashMap> adj, Set ans, Set open,\n\t\t\tHashMap edge, boolean[] vis, int i) {\n\t\tvis[i] = true;\n\t\topen.add(i);\n\t\tif (adj.get(i) != null) {\n\t\t\tfor (int k : adj.get(i)) {\n\t\t\t\tif (!vis[k]) {\n\t\t\t\t\tdfs(adj, ans, open, edge, vis, k);\n\t\t\t\t} else if (open.contains(k)) {\n\t\t\t\t\tans.add(edge.get(String.valueOf(i) + \" \" + String.valueOf(k)));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\topen.remove(i);\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "combinatorics"], "code_uid": "ad0ca6ee7b53aeca3eb3f6cdc7a30db7", "src_uid": "020d5dae7157d937c3f58554c9b155f9", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/*\n * DA-IICT\n * Author: Jugal Kalal\n */\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\nimport java.text.DecimalFormat;\npublic class Hackerearth{\n\tstatic long mod=(long)Math.pow(10,9)+7;\n\tpublic static void main(String args[]) {\n new Thread(null, new Runnable() {\n public void run() {\n try{\n solve();\n w.close();\n }\n catch(Exception e){\n e.printStackTrace();\n }\n }\n }, \"1\", 1 << 26).start();\n\t}\n\tstatic InputReader in;\n static PrintWriter w;\n static void solve(){\n in = new InputReader(System.in);\n w = new PrintWriter(System.out);\n int n=in.nextInt();\n long arr[]=in.nextLongArray(2*n);\n Arrays.sort(arr);\n long min=Long.MAX_VALUE;\n for(int i=0;i<2*n;i++) {\n \t\tfor(int j=i+1;j<2*n;j++) {\n \t\t\tlong first=-1;\n \t\t\tlong total=0;\n \t\t\tfor(int k=0;k<2*n;k++) {\n \t\t\t\tif(k!=i&&k!=j) {\n \t\t\t\t\tif(first==-1) {\n \t\t\t\t\t\tfirst=arr[k];\n \t\t\t\t\t}else {\n \t\t\t\t\t\ttotal+=arr[k]-first;\n \t\t\t\t\t\tfirst=-1;\n \t\t\t\t\t}\n \t\t\t\t}\n \t\t\t}\n \t\t\tmin=Math.min(total,min);\n \t\t}\n }\n w.println(min);\n }\n static class Pair{\n \t\tint l;\n \t\tint r;\n \t\tpublic Pair(int l,int r) {\n \t\t\tthis.l=l;\n \t\t\tthis.r=r;\n \t\t}\n }\n static ArrayList adj[]; //Adjacency Lists\n static int V; // No. of vertices\n // Constructor\n static void Graph(int v){\n V = v;\n adj = new ArrayList[v];\n for (int i=0; i0){\n// \t\t\ts+=1+Math.log(temp&(-temp))/Math.log(2);\n// \t\t\ttemp=temp&(temp-1);\n// \t\t\tcount++;\n// \t\t}\n// \t\tfor(int j=0;j0){\n// \t\t\t\tfor(int k=0;k0&&adj[j][k]&&dp[k][mask^(1< queue=new LinkedList();\n// \tqueue.add(s);\n// \tvisited[s]=true;\n// \twhile(!queue.isEmpty()){\n// \t\tint num=queue.pop();\n//// \t\tSystem.out.println(ans.toString());\n// \t\tfor(int i=0;i 0) {\n\t if (exponent % 2L == 1L)\n\t result = (result * base) % modulus;\n\t exponent = exponent >> 1;\n\t base = (base * base) % modulus;\n\t }\n\t return result;\n\t}\n static HashMap primeFactors(long n){\n HashMap ans=new HashMap();\n \t// Print the number of 2s that divide n\n while (n%2L==0L)\n {\n if(ans.containsKey(2L)){\n \tans.put(2L,ans.get(2L)+1L);\n }else{\n \tans.put(2L,1L);\n }\n n /= 2L;\n }\n \n // n must be odd at this point. So we can\n // skip one element (Note i = i +2)\n for (long i = 3; i <= Math.sqrt(n); i+= 2L)\n {\n // While i divides n, print i and divide n\n while (n%i == 0)\n {\n \tif(ans.containsKey(i)){\n \tans.put(i,ans.get(i)+1L);\n }else{\n \tans.put(i,1L);\n }\n n /= i;\n }\n }\n \n // This condition is to handle the case whien\n // n is a prime number greater than 2\n if (n > 2)\n ans.put(n,1L);\n return ans;\n }\n////for marking all prime numbers greater than 1 and less than equal to N\n\tstatic boolean[] sieve(int N) {\n\t\t boolean isPrime[]=new boolean[N+1];\n\t\t isPrime[0] = true;\n\t\t isPrime[1] = true;\n\t\t for(int i = 2; i * i <= N; ++i) {\n\t\t if(isPrime[i] == false) {//Mark all the multiples of i as composite numbers\n\t\t for(int j = i * i; j <= N ;j += i)\n\t\t isPrime[j] = true;\n\t\t }\n\t\t }\n\t\t return isPrime;\n\t}\n// //if str2 (pattern) is subsequence of str1 (Text) or not\n//\tstatic boolean function(String str1,String str2){\n//\t str2 = str2.replace(\"\", \".*\"); //returns .*a.*n.*n.*a.\n//\t return (str1.matches(str2)); // returns true\n//\t}\n static int Arr[];\n static long size[];\n //modified initialize function:\n static void initialize(int N){\n \tArr=new int[N];\n \tsize=new long[N];\n for(int i = 0;i level;;\n//\tstatic HashMap parent;\n\tstatic int maxlevel=0;\n\t\n//\tstatic boolean T[][][];\n//\tstatic void subsetSum(int input[], int total, int count) {\n// T = new boolean[input.length + 1][total + 1][count+1];\n// for (int i = 0; i <= input.length; i++) {\n// \tT[i][0][0] = true;\n// \tfor(int j = 1; j<=count; j++){\n// \t\tT[i][0][j] = false;\n// \t}\n// }\n// int sum[]=new int[input.length+1];\n// for(int i=1;i<=input.length;i++){\n// sum[i]=sum[i-1]+input[i-1];\n// }\n// for (int i = 1; i <= input.length; i++) {\n// for (int j = 1; j <= (int)Math.min(total,sum[i]); j++) {\n// \tfor (int k = 1; k <= (int)Math.min(i,count); k++){\n// \t\t if (j >= input[i - 1]) {//Exclude and Include\n// T[i][j][k] = T[i - 1][j][k] || T[i - 1][j - input[i - 1]][k-1];\n// } else {\n// T[i][j][k] = T[i-1][j][k];\n// }\n// \t}\n// }\n// }\n// }\n//\tstatic >\n//\tSortedSet> entriesSortedByValues(Map map) {\n//\t SortedSet> sortedEntries = new TreeSet>(\n//\t new Comparator>() {\n//\t @Override public int compare(Map.Entry e1, Map.Entry e2) {\n//\t int res = e2.getValue().compareTo(e1.getValue());\n//\t return res != 0 ? res : 1;\n//\t }\n//\t }\n//\t );\n//\t sortedEntries.addAll(map.entrySet());\n//\t return sortedEntries;\n//\t}\n\t\n \n\t \n\t//minimum prime factor of all the numbers less than n\n static int minPrime[];\n\tstatic void minimumPrime(int n){\n\t\tminPrime=new int[n+1];\n\t\tminPrime[1]=1;\n for (int i = 2; i * i <= n; ++i) {\n if (minPrime[i] == 0) { //If i is prime\n for (int j = i * i; j <= n; j += i) {\n if (minPrime[j] == 0) {\n minPrime[j] = i;\n }\n }\n }\n }\n for (int i = 2; i <= n; ++i) {\n if (minPrime[i] == 0) {\n minPrime[i] = i;\n }\n }\n\t}\n\tstatic long modInverse(long A, long M)\n\t{\n\t\tlong x=extendedEuclid(A,M)[0];\n\t\treturn (x%M+M)%M; //x may be negative\n\t}\n\tstatic long[] extendedEuclid(long A, long B) {\n\t\tif(B == 0) {\n\t\t\tlong d = A;\n\t\t\tlong x = 1;\n\t\t\tlong y = 0;\n\t\t\treturn new long[]{x,y,d};\n\t\t}\n\t\telse {\n\t\t\tlong arr[]=extendedEuclid(B, A%B);\n\t\t\tlong temp = arr[0];\n\t\t\tarr[0] = arr[1];\n\t\t\tarr[1] = temp - (A/B)*arr[1];\n\t\t\treturn arr;\n\t\t}\n\t}\n \n\tstatic class InputReader {\n private final InputStream stream;\n private final byte[] buf = new byte[8192];\n private int curChar, numChars;\n private SpaceCharFilter filter;\n \n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n \n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n \n public String nextLine() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isEndOfLine(c));\n return res.toString();\n }\n \n public String readString() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n \n public long nextLong() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n \n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n \n public int[] nextIntArray(int n) {\n int[] arr = new int[n];\n for (int i = 0; i < n; i++) {\n arr[i] = nextInt();\n }\n return arr;\n }\n \n public long[] nextLongArray(int n) {\n long[] arr = new long[n];\n for (int i = 0; i < n; i++) {\n arr[i] = nextLong();\n }\n return arr;\n }\n \n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n \n private boolean isEndOfLine(int c) {\n return c == '\\n' || c == '\\r' || c == -1;\n }\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n\t}\n} ", "lang_cluster": "Java", "tags": ["brute force", "sortings", "greedy"], "code_uid": "d8959be2d0ce3d0cfeea5e1bfb6b3d21", "src_uid": "76659c0b7134416452585c391daadb16", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.IOException;\nimport java.util.*;\n\n/**\n * Author: dened\n * Date: 26.03.11\n */\npublic class A {\n public static void main(String[] args) throws IOException {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n System.out.println(n == 0 ? 1 : calc(n));\n }\n\n static int calc(int n) {\n if (n == 1) {\n return 1;\n }\n return 3 * calc(n - 1) % 1000003;\n }\n}\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "0eed668082ec86df65dd7fe3a5e9ceff", "src_uid": "1a335a9638523ca0315282a67e18eec7", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Test {\n\n public static void main(String[] args){\n Scanner in = new Scanner(System.in);\n int n = in.nextInt(), k = in.nextInt(), a[] = new int[n], c = 0, e = 0, ans = 0;\n for(int i = 0; i al = new ArrayList<>();\n for(int i=0;i3 || (i-a)>3) continue;\n for (int max=Math.max(j, k)+1; max<=4; max++) {\n res[i][j][k] += (given[a][j][max]*given[i-a][max][k]);\n }\n }\n }\n }\n }\n int[][][] dp = new int[n+1][t+1][4];\n for (int i=1; i<=n; i++) {\n for (int j=1; j<=t; j++) {\n for (int a=1; a<=3; a++) {\n for (int b=1; b<=3; b++) {\n for (int len=1; len<=Math.min(i, 6); len++) {\n if (i-len==0) {\n if (j == 1) dp[i][j][a] += res[len][a][b];\n } else dp[i][j][a] += (dp[i-len][j-1][b] * res[len][a][b]);\n }\n }\n }\n }\n }\n System.out.println(dp[n][t][1]+dp[n][t][2]+dp[n][t][3]);\n }\n}", "lang_cluster": "Java", "tags": ["dp"], "code_uid": "e0fc5fdb5079cc71f8a8d97835a37a16", "src_uid": "6d67559744583229455c5eafe68f7952", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "//package prac;\n\nimport java.io.IOException;\nimport java.util.Scanner;\n\npublic class prac {\n\t//public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\tpublic static void main(String[] args) throws IOException{\n\t\t@SuppressWarnings(\"resource\")\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint a = sc.nextInt();\n\t\tint b = sc.nextInt();\n\t\tint[] in = new int[n];\n\t\tfor (int i = 0;i0){\n\t\t\t\tfor(int k=0; ksum){\n\t\t\t\treturn 1;\n\t\t\t}else{\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\t\tlong res=0;\n\t\tif(index==0){\n\t\t\tfor(int i=0; i0){\n\t\t\t\t\tlong m=memo[i]%mod;\n\t\t\t\t\tmemo[i]--;\n\t\t\t\t\tres=(res+m*dfs(index+1, i, 0)%mod)%mod;\n\t\t\t\t\tmemo[i]++;\n\t\t\t\t}\n\t\t\t}\n\t\t}else{\n\t\t\tfor(int i=0; i0){\n\t\t\t\t\tlong m=memo[i]%mod;\n\t\t\t\t\tmemo[i]--;\n\t\t\t\t\tres=(res+m*dfs(index+1, me, sum+i)%mod)%mod;\n\t\t\t\t\tmemo[i]++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n\n\tvoid println(String s){\n\t\tSystem.out.println(s);\n\t}\n\n\tvoid print(String s){\n\t\tSystem.out.print(s);\n\t}\n\n\tvoid debug(Object... os){\n\t\tSystem.err.println(Arrays.deepToString(os));\n\t}\n\n\tpublic static void main(String[] args){\n\t\tLocale.setDefault(Locale.US);\n\t\tnew B().run();\n\t}\n}\n", "lang_cluster": "Java", "tags": ["brute force", "dp", "combinatorics"], "code_uid": "823059efe31ee5c54e20ed557f4465db", "src_uid": "656ed7b1b80de84d65a253e5d14d62a9", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class LuckyNumbers {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc=new Scanner(System.in);\n\t\tint n=sc.nextInt();long cnt=2*((long)Math.pow(2, n)-1);\n\t\tSystem.out.println(cnt);\n\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["math", "combinatorics"], "code_uid": "473917cc1158eeb7357fa177e350ac18", "src_uid": "f1b43baa14d4c262ba616d892525dfde", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import static java.lang.System.*;\nimport java.util.*;\nimport java.io.*;\n\npublic class Main {\n public static void main(String[] args) throws IOException {\n Scanner sc = new Scanner(in);\n \n int n = sc.nextInt();\n int sum = 0;\n int m = 0;\n while (n --> 0 && (m - (m = sc.nextInt())) * -1 <= 15) {\n sum = m;\n }\n if (n >= 0) {\n while (n --> 0) {\n sc.nextInt();\n }\n }\n sum += 15;\n if (sum > 90) sum = 90;\n out.println(sum);\n }\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "f6c45715cdf30cfe4a69c4f286ed1e4e", "src_uid": "5031b15e220f0ff6cc1dd3731ecdbf27", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\npublic class m {\n\tpublic static void main(String[] args) throws IOException {\n\t\t BufferedReader f = new BufferedReader(new InputStreamReader(System.in));\t \n\t int b=Integer.parseInt(f.readLine());\n\t int c=Integer.parseInt(f.readLine());\n\t int d=Integer.parseInt(f.readLine());\n\t System.out.println((b>d&&c>d)?d+1:(b==d&&c==d)||(b<=d&&c>=d)?b+1:(b x || a.y + b.y > y) {\n\t\t\treturn null;\n\t\t}\n\t\tint c = crossProduct(BigInteger.valueOf(a.x), BigInteger.valueOf(a.y),\n\t\t\t\tBigInteger.valueOf(x), BigInteger.valueOf(y));\n\t\tint d = crossProduct(BigInteger.valueOf(b.x), BigInteger.valueOf(b.y),\n\t\t\t\tBigInteger.valueOf(x), BigInteger.valueOf(y));\n\n\t\tint f = crossProduct(BigInteger.valueOf(a.x + b.x),\n\t\t\t\tBigInteger.valueOf(a.y + b.y), BigInteger.valueOf(x),\n\t\t\t\tBigInteger.valueOf(y));\n\t\tboolean removeA = d != f;\n\t\t// System.out.println(c + \" \" + d + \" \" + f);\n\t\tlong s = 0;\n\t\tlong e = 1000000000000000000L;\n\t\tlong result = -1;\n\t\twhile (s <= e) {\n\t\t\tlong mid = (s + e) / 2;\n\n\t\t\tif (removeA) {\n\t\t\t\t\n\t\t\t\tint v = crossProduct(\n\t\t\t\t\t\tBigInteger.valueOf(a.x).add(\n\t\t\t\t\t\t\t\tBigInteger.valueOf(mid).multiply(\n\t\t\t\t\t\t\t\t\t\tBigInteger.valueOf(b.x))),\n\t\t\t\t\t\tBigInteger.valueOf(a.y).add(\n\t\t\t\t\t\t\t\tBigInteger.valueOf(mid).multiply(\n\t\t\t\t\t\t\t\t\t\tBigInteger.valueOf(b.y))),\n\t\t\t\t\t\tBigInteger.valueOf(x), BigInteger.valueOf(y));\n\t\t\t\t\n\t\t\t\tif (v == d) {\n\n\t\t\t\t\te = mid - 1;\n\t\t\t\t} else {\n\t\t\t\t\tif (result == -1 || result < mid) {\n\t\t\t\t\t\tresult = mid;\n\t\t\t\t\t}\n\t\t\t\t\ts = mid + 1;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t\n\t\t\t\tint v = crossProduct(\n\t\t\t\t\t\tBigInteger.valueOf(b.x).add(\n\t\t\t\t\t\t\t\tBigInteger.valueOf(mid).multiply(\n\t\t\t\t\t\t\t\t\t\tBigInteger.valueOf(a.x))),\n\t\t\t\t\t\tBigInteger.valueOf(b.y).add(\n\t\t\t\t\t\t\t\tBigInteger.valueOf(mid).multiply(\n\t\t\t\t\t\t\t\t\t\tBigInteger.valueOf(a.y))),\n\t\t\t\t\t\tBigInteger.valueOf(x), BigInteger.valueOf(y));\n\t\t\t\t\n\t\t\t//\tSystem.out.println(v + \" \" + mid);\n\t\t\t\tif (v == c) {\n\n\t\t\t\t\te = mid - 1;\n\t\t\t\t} else {\n\t\t\t\t\tif (result == -1 || result < mid) {\n\t\t\t\t\t\tresult = mid;\n\t\t\t\t\t}\n\t\t\t\t\ts = mid + 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// if (true) {\n\t\t// System.out.println(result);\n\t\t// return \"\";\n\t\t// }\n\t\tString tmp = null;\n\t\tif (removeA) {\n\t\t\ttmp = cal(new Point(a.x + result * b.x, a.y + result * b.y), b, x,\n\t\t\t\t\ty);\n\t\t} else {\n\t\t\ttmp = cal(a, new Point(b.x + result * a.x, b.y + result * a.y), x,\n\t\t\t\t\ty);\n\t\t}\n\t\tif (tmp != null) {\n\t\t\treturn (result - (tmp.isEmpty() ? 1 : 0)) + (removeA ? \"B\" : \"A\")\n\t\t\t\t\t+ tmp;\n\t\t}\n\t\treturn null;\n\n\t}\n\n\tstatic int crossProduct(BigInteger x, BigInteger y, BigInteger x1,\n\t\t\tBigInteger y1) {\n\t\tBigInteger a = x.multiply(y1);\n\n\t\tBigInteger b = y.multiply(x1);\n\n\t\treturn a.compareTo(b);\n\t}\n\n\tpublic static int[] KMP(String val) {\n\t\tint i = 0;\n\t\tint j = -1;\n\t\tint[] result = new int[val.length() + 1];\n\t\tresult[0] = -1;\n\t\twhile (i < val.length()) {\n\t\t\twhile (j >= 0 && val.charAt(j) != val.charAt(i)) {\n\t\t\t\tj = result[j];\n\t\t\t}\n\t\t\tj++;\n\t\t\ti++;\n\t\t\tresult[i] = j;\n\t\t}\n\t\treturn result;\n\n\t}\n\n\tpublic static boolean nextPer(int[] data) {\n\t\tint i = data.length - 1;\n\t\twhile (i > 0 && data[i] < data[i - 1]) {\n\t\t\ti--;\n\t\t}\n\t\tif (i == 0) {\n\t\t\treturn false;\n\t\t}\n\t\tint j = data.length - 1;\n\t\twhile (data[j] < data[i - 1]) {\n\t\t\tj--;\n\t\t}\n\t\tint temp = data[i - 1];\n\t\tdata[i - 1] = data[j];\n\t\tdata[j] = temp;\n\t\tArrays.sort(data, i, data.length);\n\t\treturn true;\n\t}\n\n\tpublic static int digit(long n) {\n\t\tint result = 0;\n\t\twhile (n > 0) {\n\t\t\tn /= 10;\n\t\t\tresult++;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static double dist(long a, long b, long x, long y) {\n\t\tdouble val = (b - a) * (b - a) + (x - y) * (x - y);\n\t\tval = Math.sqrt(val);\n\t\tdouble other = x * x + a * a;\n\t\tother = Math.sqrt(other);\n\t\treturn val + other;\n\n\t}\n\n\tpublic static class Point {\n\n\t\tlong x, y;\n\n\t\tpublic Point(long start, long end) {\n\t\t\tthis.x = start;\n\t\t\tthis.y = end;\n\t\t}\n\n\t}\n\n\tpublic static class FT {\n\n\t\tlong[] data;\n\n\t\tFT(int n) {\n\t\t\tdata = new long[n];\n\t\t}\n\n\t\tpublic void update(int index, long value) {\n\t\t\twhile (index < data.length) {\n\t\t\t\tdata[index] += value;\n\t\t\t\tindex += (index & (-index));\n\t\t\t}\n\t\t}\n\n\t\tpublic long get(int index) {\n\t\t\tlong result = 0;\n\t\t\twhile (index > 0) {\n\t\t\t\tresult += data[index];\n\t\t\t\tindex -= (index & (-index));\n\t\t\t}\n\t\t\treturn result;\n\n\t\t}\n\t}\n\n\tpublic static long gcd(long a, long b) {\n\t\tif (b == 0) {\n\t\t\treturn a;\n\t\t}\n\t\treturn gcd(b, a % b);\n\t}\n\n\tpublic static long pow(long a, long b) {\n\t\tif (b == 0) {\n\t\t\treturn 1;\n\t\t}\n\t\tif (b == 1) {\n\t\t\treturn a;\n\t\t}\n\t\tlong val = pow(a, b / 2);\n\t\tif (b % 2 == 0) {\n\t\t\treturn val * val % MOD;\n\t\t} else {\n\t\t\treturn val * (val * a % MOD) % MOD;\n\n\t\t}\n\t}\n\n\tstatic class Scanner {\n\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic Scanner() throws FileNotFoundException {\n\t\t\t// System.setOut(new PrintStream(new\n\t\t\t// BufferedOutputStream(System.out), true));\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t// br = new BufferedReader(new InputStreamReader(new\n\t\t\t// FileInputStream(new File(\"input.txt\"))));\n\t\t}\n\n\t\tpublic String next() {\n\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\tthrow new RuntimeException();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tst = null;\n\t\t\ttry {\n\t\t\t\treturn br.readLine();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t}\n\n\t\tpublic boolean endLine() {\n\t\t\ttry {\n\t\t\t\tString next = br.readLine();\n\t\t\t\twhile (next != null && next.trim().isEmpty()) {\n\t\t\t\t\tnext = br.readLine();\n\t\t\t\t}\n\t\t\t\tif (next == null) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tst = new StringTokenizer(next);\n\t\t\t\treturn st.hasMoreTokens();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "tags": ["number theory"], "code_uid": "5dae110be05f6d1ba3b43d4ea48af55b", "src_uid": "6a9ec3b23bd462353d985e0c0f2f7671", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import com.sun.jdi.ArrayReference;\r\n\r\nimport javax.swing.text.Segment;\r\nimport java.io.*;\r\nimport java.lang.reflect.Array;\r\nimport java.math.BigInteger;\r\nimport static java.lang.Math.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static FastReader in;\r\n public static PrintWriter out;\r\n\r\n\r\n static public void main(String[] args){\r\n out = new PrintWriter(new BufferedOutputStream(System.out));\r\n in = new FastReader();\r\n\r\n solve();\r\n\r\n\r\n out.close();\r\n }\r\n\r\n static void solve(){\r\n int p1 = in.nextInt();\r\n long t1 = in.nextLong();\r\n int p2 = in.nextInt();\r\n long t2 = in.nextLong();\r\n int h = in.nextInt();\r\n int s = in.nextInt();\r\n long[] dp = new long[h + 1];\r\n\r\n for(int i = 1; i <= h; i++){\r\n dp[i] = min(fun(p1,p2,t1,t2,i,s), fun(p2,p1,t2,t1,i,s));\r\n\r\n for(int j = 1; j < i; j ++){\r\n dp[i] = min(dp[i], dp[j] + dp[i - j]);\r\n }\r\n }\r\n\r\n out.println(dp[h]);\r\n }\r\n static long fun(int p1, int p2, long t1, long t2, int i,int s){\r\n for(int cot = 1; ;cot++){\r\n\r\n long cot2 = cot * t1 / t2;\r\n long now = cot * p1 + cot2 * p2;\r\n\r\n if(cot2 == 0){\r\n now -= s * cot;\r\n }else {\r\n now -= s * (cot + cot2 - 1);\r\n }\r\n if(now >= i){\r\n return cot * t1;\r\n }\r\n }\r\n\r\n }\r\n static class FastReader\r\n {\r\n BufferedReader br;\r\n StringTokenizer str;\r\n\r\n public FastReader()\r\n {\r\n br = new BufferedReader(new InputStreamReader(System.in));\r\n }\r\n\r\n String next()\r\n {\r\n while (str == null || !str.hasMoreElements())\r\n {\r\n try\r\n {\r\n str = new StringTokenizer(br.readLine());\r\n }\r\n catch (IOException lastMonthOfVacation)\r\n {\r\n lastMonthOfVacation.printStackTrace();\r\n }\r\n }\r\n return str.nextToken();\r\n }\r\n\r\n int nextInt()\r\n {\r\n return Integer.parseInt(next());\r\n }\r\n\r\n long nextLong()\r\n {\r\n return Long.parseLong(next());\r\n }\r\n\r\n double nextDouble()\r\n {\r\n return Double.parseDouble(next());\r\n }\r\n\r\n String nextLine()\r\n {\r\n String str = \"\";\r\n try\r\n {\r\n str = br.readLine();\r\n }\r\n catch (IOException lastMonthOfVacation)\r\n {\r\n lastMonthOfVacation.printStackTrace();\r\n }\r\n return str;\r\n }\r\n }\r\n}", "lang_cluster": "Java", "tags": ["dp", "binary search"], "code_uid": "bfad5806226ff2f6e858209ee4ef0772", "src_uid": "ca9d48e48e69b931236907a9ac262433", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\n\npublic class Main{\n public static void main(String[] args)throws IOException{\n\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\tPrintWriter out = new PrintWriter(System.out);\n\tString s[] = br.readLine().split(\" \");\n\tint n = Integer.parseInt(s[0]);\n\tint k = Integer.parseInt(s[1]);\n\tchar d[] = br.readLine().toCharArray();\n\tArrays.sort(d);\n\tint ans = Integer.MAX_VALUE;\n\tfor(int i = 0; i=2){\n\t\t ul = d[j];\n\t\t p++;\n\t\t c+=d[j]-'a'+1;\n\t\t}\n\t\tif(p==k){\n\t\t break;\n\t\t}\n\t }\n\t if(p==k){\n\t\tans = Math.min(ans,c);\n\t }\n\t}\n\tout.println(ans==Integer.MAX_VALUE?-1:ans);\n\tout.close();\n }\n}\n", "lang_cluster": "Java", "tags": ["sortings", "implementation", "greedy"], "code_uid": "2fdfbe018fe0d4d0839ddd87ae28b037", "src_uid": "56b13d313afef9dc6c6ba2758b5ea313", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Collections;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.StringTokenizer;\n\npublic class B395 {\n\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n\n solve(1, in, out);\n\n out.close();\n }\n\n private static void solve(int n, InputReader in, PrintWriter out) {\n while (n > 0) {\n solve(in, out);\n n--;\n }\n }\n\n private static void solve(InputReader in, PrintWriter out) {\n long n = in.nextLong();\n long l = in.nextLong();\n long r = in.nextLong();\n List d = new LinkedList();\n while (n > 1) {\n d.add((int) (n % 2));\n n = n / 2;\n }\n List dSum = new LinkedList();\n d.add((int) n);\n List c = new LinkedList();\n long sum = 0;\n\n for (int i = 0; i < d.size(); i++) {\n sum += d.get(i) * Math.pow(2.0, i);\n }\n long tSum = sum;\n dSum.add(sum);\n for (int i = 0; i < d.size() - 1; i++) {\n dSum.add(tSum / 2);\n tSum /= 2;\n }\n Collections.reverse(d);\n for (int i = 0; i < d.size(); i++) {\n c.add((long) (Math.pow(2, (d.size() - i)) - 1));\n }\n long length = c.get(0);\n l--;\n r = length -r;\n Collections.reverse(c);\n Collections.reverse(dSum);\n \n long diffL = 0;\n int i = 0;\n while(l > 0){\n for(i = 1; i < c.size(); i++){\n if(c.get(i) > l){\n break;\n }\n }\n diffL += dSum.get(i-1);\n l -= c.get(i-1);\n if(l > 0) {\n diffL += d.get(i);\n }\n l--;\n }\n l = r;\n while(l > 0){\n for(i = 1; i < c.size(); i++){\n if(c.get(i) > l){\n break;\n }\n }\n diffL += dSum.get(i-1);\n l -= c.get(i-1);\n if(l > 0) {\n diffL += d.get(i);\n }\n l--;\n }\n System.out.println(sum - diffL);\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public String nextLine() {\n try {\n return reader.readLine();\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n }\n}", "lang_cluster": "Java", "tags": ["dfs and similar", "divide and conquer", "constructive algorithms"], "code_uid": "2c977d65ab80489f1684329512e73a17", "src_uid": "3ac61b1f8deee7911b1055c243f5eb6a", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.math.BigInteger;\nimport java.util.Scanner;\n\n\npublic class Main {\n \n static final int MAX = 1007;\n static BigInteger []a =\n {BigInteger.ZERO,BigInteger.valueOf(2),BigInteger.valueOf(3),BigInteger.valueOf(5),\n BigInteger.valueOf(7),BigInteger.valueOf(11),BigInteger.valueOf(13),\n BigInteger.valueOf(17),BigInteger.valueOf(19),BigInteger.valueOf(23),\n BigInteger.valueOf(29),BigInteger.valueOf(31),BigInteger.valueOf(37),\n BigInteger.valueOf(41),BigInteger.valueOf(43),BigInteger.valueOf(47),\n BigInteger.valueOf(53),BigInteger.valueOf(59)};\n static BigInteger [][]pp = new BigInteger[MAX][MAX]; \n static BigInteger [][]dp = new BigInteger[MAX][MAX];\n static boolean [][]mark = new boolean[MAX][MAX];\n public static void main ( String[] args )\n {\n Scanner cin = new Scanner ( System.in );\n int n;\n for ( int i = 1 ; i < 18 ; i++ )\n {\n pp[i][0] = BigInteger.ONE;\n for ( int j = 1 ; j < MAX ; j++ )\n pp[i][j] = pp[i][j-1].multiply( a[i] );\n }\n while ( cin.hasNext())\n {\n n = cin.nextInt();\n dp[0][1] = BigInteger.ONE;\n for ( int i = 0 ; i < MAX ; i++ )\n for ( int j = 0 ; j < MAX ; j++ )\n mark[i][j] = false;\n mark[0][1] = true;\n for ( int i = 1 ; i < 18 ; i++ )\n for ( int j = 1 ; j <= n ; j++ )\n {\n for ( int k = 1; k <= n ; k++ )\n {\n if ( j*k > n ) continue;\n if ( !mark[i-1][j]) continue;\n if (!mark[i][j*k] || (dp[i-1][j].multiply(pp[i][k-1])).compareTo(dp[i][j*k])< 0 )\n {\n dp[i][j*k] = dp[i-1][j].multiply(pp[i][k-1]);\n mark[i][j*k] = true;\n }\n }\n }\n System.out.println(dp[17][n] );\n }\n }\n\n}\n", "lang_cluster": "Java", "tags": ["brute force", "dp", "number theory"], "code_uid": "4e1b4bb13f28dcf1af33c875199b0069", "src_uid": "62db589bad3b7023418107de05b7a8ee", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class Main{\n static FR in;\n public static void main(String[] args)throws Exception{\n in = new FR();\n int n = ni();\n String s = nln();\n int ctr=0, ctr2=0;\n for( int i=1;i C[i-1] * 2 ) {\n C[i] = C[i-1] * 2;\n }\n }\n\n int maxSellL = (int)Math.pow(2, N-1);\n long cost;\n int r;\n if( L > maxSellL ) {\n int q = L / maxSellL;\n r = L % maxSellL;\n cost = (long)q * C[N-1];\n\n } else {\n r = L;\n cost = 0;\n }\n if( r == 0 ) return cost;\n else return dfs(r) + cost;\n }\n\n static long dfs(int r) {\n long ret = Long.MAX_VALUE / 2;\n for (int i = N-1; i >= 0; i--) {\n int l = (int)Math.pow(2, i);\n if( l >= r ) {\n ret = Math.min(C[i], ret);\n\n } else {\n ret = Math.min(dfs(r-l) + C[i], ret);\n break;\n }\n }\n return ret;\n }\n\n @SuppressWarnings(\"unused\")\n static class FastScanner {\n private BufferedReader reader;\n private StringTokenizer tokenizer;\n\n FastScanner(InputStream in) {\n reader = new BufferedReader(new InputStreamReader(in));\n tokenizer = null;\n }\n\n String next() {\n if (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n String nextLine() {\n if (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n return reader.readLine();\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken(\"\\n\");\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n int[] nextIntArray(int n) {\n int[] a = new int[n];\n for (int i = 0; i < n; i++) a[i] = nextInt();\n return a;\n }\n\n int[] nextIntArray(int n, int delta) {\n int[] a = new int[n];\n for (int i = 0; i < n; i++) a[i] = nextInt() + delta;\n return a;\n }\n\n long[] nextLongArray(int n) {\n long[] a = new long[n];\n for (int i = 0; i < n; i++) a[i] = nextLong();\n return a;\n }\n }\n\n static void writeLines(A[] as, Function f) {\n PrintWriter pw = new PrintWriter(System.out);\n for (A a : as) pw.println(f.apply(a));\n pw.flush();\n }\n\n static void writeLines(int[] as) {\n PrintWriter pw = new PrintWriter(System.out);\n for (int a : as) pw.println(a);\n pw.flush();\n }\n\n static void writeLines(long[] as) {\n PrintWriter pw = new PrintWriter(System.out);\n for (long a : as) pw.println(a);\n pw.flush();\n }\n\n static void writeSingleLine(int[] as) {\n PrintWriter pw = new PrintWriter(System.out);\n for (int i = 0; i < as.length; i++) {\n if (i != 0) pw.print(\" \");\n pw.print(i);\n }\n pw.println();\n pw.flush();\n }\n\n static int max(int... as) {\n int max = Integer.MIN_VALUE;\n for (int a : as) max = Math.max(a, max);\n return max;\n }\n\n static int min(int... as) {\n int min = Integer.MAX_VALUE;\n for (int a : as) min = Math.min(a, min);\n return min;\n }\n\n static int lowerBound(int[] array, int value) {\n int low = 0;\n int high = array.length;\n int mid;\n while (low < high) {\n mid = ((high - low) >>> 1) + low;\n if (array[mid] < value) low = mid + 1;\n else high = mid;\n }\n return low;\n }\n\n static int upperBound(long[] array, long value) {\n int low = 0;\n int high = array.length;\n int mid;\n while (low < high) {\n mid = ((high - low) >>> 1) + low;\n if (array[mid] <= value) low = mid + 1;\n else high = mid;\n }\n return low;\n }\n\n static void debug(Object... args) {\n StringJoiner j = new StringJoiner(\" \");\n for (Object arg : args) {\n if (arg instanceof int[]) j.add(Arrays.toString((int[]) arg));\n else if (arg instanceof long[]) j.add(Arrays.toString((long[]) arg));\n else if (arg instanceof double[]) j.add(Arrays.toString((double[]) arg));\n else if (arg instanceof Object[]) j.add(Arrays.toString((Object[]) arg));\n else j.add(arg.toString());\n }\n System.err.println(j.toString());\n }\n}\n", "lang_cluster": "Java", "tags": ["greedy", "dp", "bitmasks"], "code_uid": "d6b5d431ff9871a9bfadcc53871a5f83", "src_uid": "04ca137d0383c03944e3ce1c502c635b", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "//package main;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Main{\n public static void main(String[] args) throws IOException {\n Reader.init(System.in);\n //StringBuffer outBuffer = new StringBuffer();\n char[] alice = Reader.next().toCharArray();\n char[] bob = Reader.next().toCharArray();\n String ok = \"OK\";\n String fail = \"WRONG_ANSWER\";\n int smallest = 0;\n int count[][] = new int[2][10];\n \n //Count characters in alice\n for(int i = 0; i < alice.length; i++) {\n count[0][alice[i]-'0']++;\n }\n //Count characters in bob\n for(int i = 0; i < bob.length; i++){\n count[1][bob[i]-'0']++;\n }\n \n for(int i = 1; i < 10; i++){\n if(count[0][i] != 0) {\n smallest = i;\n break;\n }\n }\n for(int i = 0; i < 10; i++){\n if(count[0][i] != count[1][i]) {\n System.out.print(fail);\n return;\n }\n }\n //Check that first letter is not 0\n if(bob[0]-'0' != smallest) {\n System.out.print(fail);\n return;\n }\n //Check that remaining are in ascending order\n for(int i = 2; i < bob.length; i++){\n if(bob[i-1] > bob[i]) {\n System.out.print(fail);\n return;\n }\n }\n \n System.out.print(ok);\n }\n}\n\n// Class for buffered reading int and double values \n// From: http://www.cpe.ku.ac.th/~jim/java-io.html\nclass Reader {\n static BufferedReader reader;\n static StringTokenizer tokenizer;\n\n //call this method to initialize reader for InputStream\n static void init(InputStream input) {\n reader = new BufferedReader(\n new InputStreamReader(input) );\n tokenizer = new StringTokenizer(\"\");\n }\n\n //get next word\n static String next() throws IOException {\n while ( ! tokenizer.hasMoreTokens() ) {\n //TODO add check for eof if necessary\n tokenizer = new StringTokenizer(\n reader.readLine() );\n }\n return tokenizer.nextToken();\n }\n\n static int nextInt() throws IOException {\n return Integer.parseInt( next() );\n }\n\t\n static double nextDouble() throws IOException {\n return Double.parseDouble( next() );\n }\n}", "lang_cluster": "Java", "tags": ["sortings", "implementation"], "code_uid": "d50f7f0633261503e4253686ac507788", "src_uid": "d1e381b72a6c09a0723cfe72c0917372", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class A17 {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint c = sc.nextInt();\n\t\tint[] score = new int[n];\n\t\tint[] minute = new int[n];\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tscore[i] = sc.nextInt();\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tminute[i] = sc.nextInt();\n\t\t}\n\n\t\tint Limak = 0;\n\t\tint l;\n\t\tint currmin = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tcurrmin += minute[i];\n\t\t\tl = score[i] - (c * currmin);\n\n\t\t\tif (l > 0) {\n\t\t\t\tLimak += l;\n\t\t\t}\n\t\t}\n\n\t\tint Radewoosh = 0;\n\t\tint r;\n\t\tint curr = 0;\n\n\t\tfor (int i = n - 1; i >= 0; i--) {\n\t\t\tcurr += minute[i];\n\t\t\tr = score[i] - (c * curr);\n\n\t\t\tif (r > 0) {\n\t\t\t\tRadewoosh += r;\n\t\t\t}\n\n\t\t}\n\n\t\tif (Radewoosh == Limak) {\n\t\t\tSystem.out.println(\"Tie\");\n\t\t} \n\t\telse\n\t\t\tSystem.out.println((Radewoosh > Limak) ? \"Radewoosh\" : \"Limak\");\n\n\t}\n\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "11d23f879510f86a8c3e68563c6cfa6c", "src_uid": "8c704de75ab85f9e2c04a926143c8b4a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class solution {\n public static class InputReader {\n private final InputStream stream;\n private final byte[] buf = new byte[8192];\n private int curChar, snumChars;\n\n public InputReader(InputStream st) {\n this.stream = st;\n }\n\n public int read() {\n if (snumChars == -1)\n throw new InputMismatchException();\n if (curChar >= snumChars) {\n curChar = 0;\n try {\n snumChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (snumChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public long nextLong() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public int[] nextIntArray(int n) {\n int a[] = new int[n];\n for (int i = 0; i < n; i++) {\n a[i] = nextInt();\n }\n return a;\n }\n\n public String readString() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public String nextLine() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isEndOfLine(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n private boolean isEndOfLine(int c) {\n return c == '\\n' || c == '\\r' || c == -1;\n }\n }\n\n public static void main(String[] args) throws IOException {\n InputReader in = new InputReader(System.in);\n int n = in.nextInt();\n int m = in.nextInt();\n int a[] = new int[101];\n\n for (int i = 0; i < m; i++) {\n int b = in.nextInt();\n a[b]++;\n }\n for(int i=m;i>=1;i--){\n int k = 0;\n for(int j = 1;j<101;j++){\n k+=a[j]/i;\n }\n if(k>=n){\n System.out.println(i);\n return;\n }\n }\n System.out.println(0);\n }\n\n static class sort implements Comparator> {\n\n @Override\n public int compare(ArrayList o1, ArrayList o2) {\n int c = o1.get(0).compareTo(o2.get(0));\n return c;\n }\n\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "implementation", "binary search"], "code_uid": "dbb6cc234e865a381a2d72329c1f6687", "src_uid": "b7ef696a11ff96f2e9c31becc2ff50fe", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class abc{\n\n\tpublic static void main(String args[] ) throws Exception {\n Scanner mak = new Scanner(System.in);\n int n = mak.nextInt();\n int k = mak.nextInt();\n int sum = 0,skipper = 0;\n for(int i = 0;i n*8) || (sum == 8*n && k == 4*n && skipper s=new Stack();\n s.push(0);\n n=sc.nextInt();\n for (int i=1; ;++i) {\n if(n%2==0)\n {\n ++count ;\n n=n/2 ;\n }else\n {\n s.push(count);\n n=n-1 ;\n }\n if(n==0)\n break ; \n }\n for (; ; ) {\n n=s.pop();\n if(n==0)\n break ;\n else\n pr.print(n+\" \");\n }\n pr.println(\"\");\n \n }\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "e0e985af6d2591f79aa2e0abed7b3a2c", "src_uid": "757cd804aba01dc4bc108cb0722f68dc", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n private boolean eof;\n private BufferedReader br;\n private StringTokenizer st;\n private PrintWriter out;\n\n public static void main(String[] args) throws IOException {\n new Main().run();\n }\n\n private String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n eof = true;\n return \"-1\";\n }\n }\n return st.nextToken();\n }\n\n private int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n private long nextLong() {\n return Long.parseLong(nextToken());\n }\n\n private double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n\n private String nextLine() throws IOException {\n return br.readLine();\n }\n\n\n private void run() throws IOException {\n InputStream input = System.in;\n PrintStream output = System.out;\n try {\n File f = new File(\"a.in\");\n if (f.exists() && f.canRead()) {\n input = new FileInputStream(f);\n output = new PrintStream(\"a.out\");\n }\n } catch (Throwable ignored) {\n }\n br = new BufferedReader(new InputStreamReader(input));\n out = new PrintWriter(new PrintWriter(output));\n solve();\n br.close();\n out.close();\n }\n\n\n private void solve() {\n int n = nextInt();\n\n int sum = 0;\n String s = nextToken();\n for (int i = 0; i < s.length(); i++) {\n char c = s.charAt(i);\n if (c == '+') sum += 1;\n else sum = Math.max(0, sum - 1);\n\n }\n\n out.print(sum);\n }\n\n public class Pair, S extends Comparable> implements Comparable> {\n public F first;\n public S second;\n\n Pair(F first, S second) {\n this.first = first;\n this.second = second;\n }\n\n @Override\n public int compareTo(Pair o) {\n return first.compareTo(o.first);\n }\n\n @Override\n public boolean equals(Object o) {\n if (!(o instanceof Pair)) {\n return false;\n }\n Pair p = (Pair) o;\n return Objects.equals(p.first, first) && Objects.equals(p.second, second);\n }\n\n @Override\n public int hashCode() {\n return (first == null ? 0 : first.hashCode()) ^ (second == null ? 0 : second.hashCode());\n }\n }\n}", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "04c9ecbe707f6bbd6c018ae80845a476", "src_uid": "a593016e4992f695be7c7cd3c920d1ed", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Iterator;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.NoSuchElementException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in Actual solution is at the top\n *\n * @author svilen.marchev@gmail.com\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskD solver = new TaskD();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskD {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.readInt();\n int[] a = IOUtils.readIntArray(in, n);\n out.println(2 + (a[2] ^ ArrayUtils.minElement(a)));\n }\n\n }\n\n static interface IntStream extends Iterable, Comparable {\n public IntIterator intIterator();\n\n default public Iterator iterator() {\n return new Iterator() {\n private IntIterator it = intIterator();\n\n public boolean hasNext() {\n return it.isValid();\n }\n\n public Integer next() {\n int result = it.value();\n it.advance();\n return result;\n }\n };\n }\n\n default public int compareTo(IntStream c) {\n IntIterator it = intIterator();\n IntIterator jt = c.intIterator();\n while (it.isValid() && jt.isValid()) {\n int i = it.value();\n int j = jt.value();\n if (i < j) {\n return -1;\n } else if (i > j) {\n return 1;\n }\n it.advance();\n jt.advance();\n }\n if (it.isValid()) {\n return 1;\n }\n if (jt.isValid()) {\n return -1;\n }\n return 0;\n }\n\n default public int min() {\n int result = Integer.MAX_VALUE;\n for (IntIterator it = intIterator(); it.isValid(); it.advance()) {\n int current = it.value();\n if (current < result) {\n result = current;\n }\n }\n return result;\n }\n\n }\n\n static abstract class IntAbstractStream implements IntStream {\n\n public String toString() {\n StringBuilder builder = new StringBuilder();\n boolean first = true;\n for (IntIterator it = intIterator(); it.isValid(); it.advance()) {\n if (first) {\n first = false;\n } else {\n builder.append(' ');\n }\n builder.append(it.value());\n }\n return builder.toString();\n }\n\n\n public boolean equals(Object o) {\n if (!(o instanceof IntStream)) {\n return false;\n }\n IntStream c = (IntStream) o;\n IntIterator it = intIterator();\n IntIterator jt = c.intIterator();\n while (it.isValid() && jt.isValid()) {\n if (it.value() != jt.value()) {\n return false;\n }\n it.advance();\n jt.advance();\n }\n return !it.isValid() && !jt.isValid();\n }\n\n\n public int hashCode() {\n int result = 0;\n for (IntIterator it = intIterator(); it.isValid(); it.advance()) {\n result *= 31;\n result += it.value();\n }\n return result;\n }\n\n }\n\n static interface IntCollection extends IntStream {\n public int size();\n\n }\n\n static interface IntReversableCollection extends IntCollection {\n }\n\n static class IntArray extends IntAbstractStream implements IntList {\n private int[] data;\n\n public IntArray(int[] arr) {\n data = arr;\n }\n\n public int size() {\n return data.length;\n }\n\n public int get(int at) {\n return data[at];\n }\n\n public void removeAt(int index) {\n throw new UnsupportedOperationException();\n }\n\n }\n\n static interface IntList extends IntReversableCollection {\n public abstract int get(int index);\n\n public abstract void removeAt(int index);\n\n default public IntIterator intIterator() {\n return new IntIterator() {\n private int at;\n private boolean removed;\n\n public int value() {\n if (removed) {\n throw new IllegalStateException();\n }\n return get(at);\n }\n\n public boolean advance() {\n at++;\n removed = false;\n return isValid();\n }\n\n public boolean isValid() {\n return !removed && at < size();\n }\n\n public void remove() {\n removeAt(at);\n at--;\n removed = true;\n }\n };\n }\n\n }\n\n static interface IntIterator {\n public int value() throws NoSuchElementException;\n\n public boolean advance();\n\n public boolean isValid();\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n\n static class ArrayUtils {\n public static int minElement(int[] array) {\n return new IntArray(array).min();\n }\n\n }\n\n static class IOUtils {\n public static int[] readIntArray(InputReader in, int size) {\n int[] array = new int[size];\n for (int i = 0; i < size; i++) {\n array[i] = in.readInt();\n }\n return array;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "9567068aad5ac3c3b501acce55cd9e46", "src_uid": "a9eb85dfaa3c50ed488d41da4f29c697", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class Main{\n public static void main(String[] args) {\n Scanner s=new Scanner(System.in);\n int n=s.nextInt();\n int root=(int)Math.sqrt(n);\n int more=n-(root)*(root);\n if(more>root){\n System.out.println(4*root+4);\n }\n else if(more>0){\n System.out.println(4*root+2);\n }\n else{\n System.out.println(4*root);\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "math", "geometry"], "code_uid": "ebd80d596ec14a04f6799bb7eec3deb0", "src_uid": "414cc57550e31d98c1a6a56be6722a12", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.StringTokenizer;\n\npublic class CodeForces2 {\n\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n Task solver = new Task();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class Task {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int x = in.nextInt();\n int y = in.nextInt();\n int z = in.nextInt();\n int t1 = in.nextInt();\n int t2 = in.nextInt();\n int t3 = in.nextInt();\n\n int stairs = Math.abs(x - y) * t1;\n int ele = Math.abs(x - z) * t2 + 2 * t3 + Math.abs(x - y) * t2 + t3;\n\n if(stairs < ele) {\n out.println(\"NO\");\n } else{\n out.println(\"YES\");\n }\n\n }\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "29ea07038bcbec90feaa72a22fad4616", "src_uid": "05cffd59b28b9e026ca3203718b2e6ca", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class stone{\npublic static void main(String[] args) {\n\tInputReader s=new InputReader(System.in);\n\tint n=s.nextInt();\n if (n%3==1) {\n n--;\n System.out.println(2*n/3+1);\n }\n else if (n%3==2) {\n n-=2;\n System.out.println(2*n/3+1);\n }\n else\n System.out.println(2*n/3);\n\n\n\n\t}\t\n\tstatic class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private SpaceCharFilter filter;\n \n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n \n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n \n public int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n \n public int nextInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n \n public long nextLong() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n \n public String nextToken() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n \n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return isWhitespace(c);\n }\n \n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n}\n}", "lang_cluster": "Java", "tags": ["math"], "code_uid": "04ade10ed4c5d09c3d365eb21ee18785", "src_uid": "a993069e35b35ae158d35d6fe166aaef", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.util.*;\n\npublic class Main {\n\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int amount_houses = scan.nextInt();\n int number_house = scan.nextInt();\n int time = 1;\n if (number_house % 2 != 0){\n int rast = 1;\n while(rast != number_house){\n time++;\n rast += 2;\n }\n } else {\n while(amount_houses != number_house ){\n time++;\n amount_houses -= 2;\n }\n }\n System.out.println(time);\n }\n}\n\n", "lang_cluster": "Java", "tags": ["math", "constructive algorithms"], "code_uid": "29d7f1cc2727f51807ec9ed723dec75e", "src_uid": "aa62dcdc47d0abbba7956284c1561de8", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n\npublic class Abood2D {\n\n\n\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\n\t\tint R = sc.nextInt();\n\t\tint G = sc.nextInt();\n\n\t\tint sum = G + R; \n\t\tint H = sum == 1? 1 : 0;\n\t\twhile(sum >= H)\n\t\t\tsum -= H++;\n\t\tH--;\n\t\t\n\t\tint[] acc = new int[H + 1];\n\t\t\n\t\tfor (int i = 1; i <= H; i++)\n\t\t\tacc[i] = acc[i - 1] + i;\n\t\t\n\t\t\n\t\tint[] last = new int[R + 1];\n\t\tArrays.fill(last, 1);\n\t\t\n\t\tfor (int i = H - 1; i >= 0; i--) {\n\t\t\tint[] cur = new int[R + 1];\n\t\t\t\n\t\t\tfor (int j = 0; j < cur.length; j++) {\n\t\t\t\tint r = j;\n\t\t\t\tint g = G - (acc[i] - (R - r));\n\t\t\t\t\n\t\t\t\tif(g - i >= 1)\n\t\t\t\t\tcur[j] += last[j];\n\t\t\t\tif(r - i >= 1)\n\t\t\t\t\tcur[j] += last[j - (i + 1)];\n\t\t\t\t\n\t\t\t\tcur[j] %= (int) 1e9 + 7;\n\t\t\t}\n\t\t\tlast = cur;\n\t\t}\n\t\t\n\t\tout.print(last[R]);\n\n\t\tout.flush();\n\n\t}\n\n\n\n\tstatic class Scanner \n\n\n\n\t{\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s){\tbr = new BufferedReader(new InputStreamReader(s));}\n\n\t\tpublic String next() throws IOException \n\t\t{\n\t\t\twhile (st == null || !st.hasMoreTokens()) \n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {return Integer.parseInt(next());}\n\n\t\tpublic long nextLong() throws IOException {return Long.parseLong(next());}\n\n\t\tpublic String nextLine() throws IOException {return br.readLine();}\n\n\n\t\tpublic double nextDouble() throws IOException\n\t\t{\n\t\t\tString x = next();\n\t\t\tStringBuilder sb = new StringBuilder(\"0\");\n\t\t\tdouble res = 0, f = 1;\n\t\t\tboolean dec = false, neg = false;\n\t\t\tint start = 0;\n\t\t\tif(x.charAt(0) == '-')\n\t\t\t{\n\t\t\t\tneg = true;\n\t\t\t\tstart++;\n\t\t\t}\n\t\t\tfor(int i = start; i < x.length(); i++)\n\t\t\t\tif(x.charAt(i) == '.')\n\t\t\t\t{\n\t\t\t\t\tres = Long.parseLong(sb.toString());\n\t\t\t\t\tsb = new StringBuilder(\"0\");\n\t\t\t\t\tdec = true;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tsb.append(x.charAt(i));\n\t\t\t\t\tif(dec)\n\t\t\t\t\t\tf *= 10;\n\t\t\t\t}\n\t\t\tres += Long.parseLong(sb.toString()) / f;\n\t\t\treturn res * (neg?-1:1);\n\t\t}\n\n\t\tpublic boolean ready() throws IOException {return br.ready();}\n\n\n\n\t}\n\n\n}", "lang_cluster": "Java", "tags": ["dp"], "code_uid": "a977cd12419716342e11683009a73d89", "src_uid": "34b6286350e3531c1fbda6b0c184addc", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class cf912b\n{\n\tpublic static void main(String args[])\n\t{\n\t\tScanner in=new Scanner(System.in);\n\t\tlong n=in.nextLong();\n\t\tlong k=in.nextLong();\n\t\tint a[]=new int[100];\n\t\tint count=0;\n\t\tlong temp=n;\n\t\twhile(temp>0)\n\t\t{\n\t\t\tint r=(int)(temp%2);\n\t\t\ta[count]=r;\n\t\t\tcount++;\n\t\t\ttemp=temp/2;\n\t\t}\n\t\tint ind=count;\n\t\tlong po=1;\n\t\tfor(int i=0;i=0;i--)\n\t\t{\n\t\t\tif(k>0)\n\t\t\t{\n\t\t\t\tans+=po;\n\t\t\t\tpo=po/2;\n\t\t\t\tk--;\n\t\t\t}\n\t\t}*/\n\t\tif(k==1)\n\t\t{\n\t\t\tans=n;\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}", "lang_cluster": "Java", "tags": ["constructive algorithms", "number theory", "bitmasks"], "code_uid": "777b071ab863cecef97c0e620aa356fd", "src_uid": "16bc089f5ef6b68bebe8eda6ead2eab9", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.math.BigInteger;\n//Playin with paper\npublic class Tcpc {\n\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc=new Scanner(System.in);\n //a BigIntege type b BigInteger type\n\t\tBigInteger a=sc.nextBigInteger();BigInteger b=sc.nextBigInteger();\n //BigInteger i=BigInteger.valueOf(1);\n BigInteger compt=BigInteger.ONE;\n \n while((b.compareTo(BigInteger.ZERO))!=0){\n \t \t\t\n \t \n \tcompt=(a.divide(b)).add(compt); \n \t BigInteger aux=a;a=b;\n \t b=aux.remainder(b); \n \n }\n \n // System.out.println(a);\t\n // System.out.println(b);\n compt= compt.subtract(BigInteger.ONE);\n System.out.println(compt);\n\tsc.close();\n\t}\n\n\n}", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "34085010814d65e1a6e907e944f2be84", "src_uid": "ce698a0eb3f5b82de58feb177ce43b83", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.lang.reflect.Array;\nimport java.util.*;\n\npublic class Main {\n static int[] num = new int[105];\n public static void main(String[] args)\n {\n int n, m, mn, mx;\n Scanner sc = new Scanner(System.in);\n n = sc.nextInt();\n m = sc.nextInt();\n mn = sc.nextInt();\n mx = sc.nextInt();\n int curMx = -1, curMn = 101;\n for(int i = 0; i < m; i ++)\n {\n num[i] = sc.nextInt();\n if(num[i] > curMx) curMx = num[i];\n if(num[i] < curMn) curMn = num[i];\n } \n int cnt = 0;\n if(curMx == mx) cnt ++;\n if(curMn == mn) cnt ++;\n //System.out.println(cnt);\n if(curMx > mx || curMn < mn || 2 - cnt > n - m)\n {\n System.out.println(\"Incorrect\");\n } else\n {\n System.out.println(\"Correct\");\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "f5c79fb788464f3e59f8ef3334aace3c", "src_uid": "99f9cdc85010bd89434f39b78f15b65e", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/*\n * @author derrick20\n */\nimport java.io.*;\nimport java.util.*;\n\npublic class table {\n public static void main(String args[]) throws Exception {\n FastScanner sc = new FastScanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n\n int N = sc.nextInt();\n long M = sc.nextLong();\n int K = sc.nextInt();\n\n // choose[i][j] Represents i choose j\n long[][] choose = new long[N + 1][N + 1];\n for (int i = 0; i <= N; i++) {\n choose[i][0] = 1;\n choose[i][i] = 1;\n for (int j = 1; j < i; j++) {\n choose[i][j] = (choose[i - 1][j - 1] + choose[i - 1][j]) % mod;\n }\n }\n\n // dp[i][j] stores a solution bag of using up to and including the ith\n // column the number of ways to place j dots among them.\n long[][] dp = new long[N][K + 1];\n\n // aux[i][j] = N choose j, raised to the power appropriate depending on i and M % N\n long[][] aux = new long[N][N + 1];\n for (int i = 0; i < N; i++) {\n for (int j = 0; j <= N; j++) {\n // We want it so that if i < M % N, then it'll add 1 power.\n aux[i][j] = quicklyExponentiate(choose[N][j], M / N);\n if (i < M % N) {\n aux[i][j] *= choose[N][j];\n aux[i][j] %= mod;\n }\n }\n }\n\n // The key insight is that, during our transitions, we only need to look\n // at unique columns modulo N, since those with same remainder must have\n // the same number of dots, because the N - 1 columns between them are shared,\n // so by symmetry, they must match!\n // Base case: 1st column\n for (int i = 0; i < N; i++) {\n // Count how many times a column of a certain residue will occur\n// System.out.println(i);\n // Place all possible numbers of dots into this column residue class\n for (int dots = 0; dots <= K; dots++) {\n if (i == 0) {\n // Base case: all dots go inside here\n if (dots <= N) {\n // With only the first column, we can only fit at most N dots\n dp[i][dots] = aux[i][dots];\n }\n }\n else {\n for (int used = 0; used <= dots && used <= N; used++) {\n // We can use up to N dots at most. The rest must be pushed off\n // onto other columns\n long myWays = aux[i][used];\n // This is using the remaining dots to fill up the rest\n // of the grid (using a solution bag already computed!)\n long otherWays = dp[i - 1][dots - used];\n dp[i][dots] += (myWays * otherWays) % mod;\n dp[i][dots] %= mod;\n }\n }\n }\n }\n // Given a total of K dots allowed to distribute, and the N column residues\n // available (up to the N-1 indexed one), we have all ways counted\n out.println(dp[N - 1][K]);\n out.close();\n }\n\n static long mod = (long) 1e9 + 7;\n\n static long quicklyExponentiate(long x, long p) {\n if (p == 0) {\n return 1;\n }\n else if (p == 1) {\n return x;\n }\n else {\n long sqrt = quicklyExponentiate(x, p / 2);\n long ans = (sqrt * sqrt) % mod;\n if (p % 2 == 0) {\n return ans;\n }\n else {\n return (x * ans) % mod;\n }\n }\n }\n\n static class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n FastScanner(InputStream s) {\n br = new BufferedReader(new InputStreamReader(s));\n }\n\n FastScanner(FileReader s) {\n br = new BufferedReader(s);\n }\n\n String next() throws IOException {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n String nextLine() throws IOException {\n return br.readLine();\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics", "bitmasks"], "code_uid": "492a23beaa096ce6c76d41871233b36f", "src_uid": "9c71c8e031412e2bb21266a53821626a", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/*package whatever //do not write package name here */\n\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\npublic class S {\n\tpublic static void main (String[] args) {\n\t Scanner in=new Scanner(System.in);\n\t\tint a=in.nextInt();\n\t\tint b=in.nextInt();\n\t\tMap m= new HashMap<>();\n\t\tm.put('0',6);m.put('1',2);m.put('2',5);m.put('3',5);m.put('4',4);m.put('5',5);m.put('6',6);m.put('7',3);\n\t\tm.put('8',7);m.put('9',6);\n\t\tint r=0;\n\t\tfor(int i=a;i<=b;i++)\n\t\t{\n\t\t String s=String.valueOf(i);\n\t\t for(int j=0;jkva?\"Valera\":\"Vladik\");}@Override public void readInput()throws IOException\n{a=sc.nextInt();b=sc.nextInt();if(sc.hasNextLine()){sc.nextLine();}}static public\nvoid _main(String[]args)throws IOException{new p000811A().run();}}\n//end p000811A.java\n//begin net/leksi/contest/Solver.java\nstatic private abstract class Solver{protected String nameIn=null;protected String\nnameOut=null;protected boolean singleTest=false;protected boolean preprocessDebug\n=false;protected boolean doNotPreprocess=false;protected Scanner sc=null;protected\nPrintWriter pw=null;private void process()throws IOException{if(!singleTest){int\nt=lineToIntArray()[0];while(t-->0){readInput();solve();}}else{readInput();solve(\n);}}abstract protected void readInput()throws IOException;abstract protected void\nsolve()throws IOException;protected int[]lineToIntArray()throws IOException{return\nArrays.stream(sc.nextLine().trim().split(\"\\\\s+\")).mapToInt(Integer::valueOf).toArray\n();}protected long[]lineToLongArray()throws IOException{return Arrays.stream(sc.nextLine\n().trim().split(\"\\\\s+\")).mapToLong(Long::valueOf).toArray();}protected String joinToString\n(final int[]a){return Arrays.stream(a).mapToObj(Integer::toString).collect(Collectors\n.joining(\" \"));}protected String joinToString(final long[]a){return Arrays.stream\n(a).mapToObj(Long::toString).collect(Collectors.joining(\" \"));}protectedString\njoinToString(final T[]a){return Arrays.stream(a).map(v->v.toString()).collect(Collectors\n.joining(\" \"));}protectedString joinToString(final T[]a,final Function\ntoString){return Arrays.stream(a).map(v->v.toString()).collect(Collectors.joining\n(\" \"));}protectedString joinToString(final Collectiona){return a.stream().map\n(v->v.toString()).collect(Collectors.joining(\" \"));}protectedString joinToString\n(final Collectiona,final FunctiontoString){return a.stream().map(v->\ntoString.apply(v)).collect(Collectors.joining(\" \"));}protected ListintArrayToLongList\n(final int[]a){return Arrays.stream(a).mapToObj(Long::valueOf).collect(Collectors\n.toList());}protected ListtoList(final int[]a){return Arrays.stream(a).mapToObj\n(Integer::valueOf).collect(Collectors.toList());}protected ListtoList(final\nlong[]a){return Arrays.stream(a).mapToObj(Long::valueOf).collect(Collectors.toList\n());}protected void run()throws IOException{boolean done=false;if(nameIn !=null)\n{try{try(FileInputStream fis=new FileInputStream(nameIn);PrintWriter pw0=select_output\n();){done=true;sc=new Scanner(fis);pw=pw0;process();}}catch(IOException ex){}}if\n(!done){try(PrintWriter pw0=select_output();){sc=new Scanner(System.in);pw=pw0;process\n();}}}private PrintWriter select_output()throws FileNotFoundException{if(nameOut\n!=null){return new PrintWriter(nameOut);}return new PrintWriter(System.out);}}\n//end net/leksi/contest/Solver.java\n}\n", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "b5d526af83760169ef65104838857120", "src_uid": "87e37a82be7e39e433060fd8cdb03270", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\n/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n\n/**\n *\n * @author rn-sshawish\n */\npublic class Test {\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n\n long nApplication = input.nextLong();\n \n long y = nApplication / input.nextLong();\n \n long j = 2;\n \n if (y%j != 0 ) {\n System.out.println(\"YES\");\n }else{\n System.out.println(\"NO\");\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "games"], "code_uid": "6a24a91f67582b798a452dcf57dfb3cc", "src_uid": "05fd61dd0b1f50f154eec85d8cfaad50", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.util.regex.Pattern;\n\npublic class Jabber implements Runnable {\n private void solve() throws IOException {\n String s = reader.readLine();\n if (s.indexOf('@') < 0) {\n writer.println(\"NO\");\n return;\n }\n String user = s.substring(0, s.indexOf('@'));\n if (!verifyUser(user)) {\n writer.println(\"NO\");\n return;\n }\n String rest = s.substring(s.indexOf('@') + 1);\n if (rest.indexOf('/') >= 0) {\n String host = rest.substring(0, rest.indexOf('/'));\n if (!verifyHost(host)) {\n writer.println(\"NO\");\n return;\n }\n String res = rest.substring(rest.indexOf('/') + 1);\n if (!verifyUser(res)) {\n writer.println(\"NO\");\n return;\n }\n } else {\n if (!verifyHost(rest)) {\n writer.println(\"NO\");\n return;\n }\n }\n writer.println(\"YES\");\n }\n\n private boolean verifyHost(String s) {\n if (s.length() < 1 || s.length() > 32)\n return false;\n s = s + \".\";\n while (!s.isEmpty()) {\n String t = s.substring(0, s.indexOf('.'));\n if (!verifyUser(t))\n return false;\n s = s.substring(s.indexOf('.') + 1);\n }\n return true;\n }\n\n private boolean verifyUser(String s) {\n if (s.length() < 1 || s.length() > 16)\n return false;\n for (int i = 0; i < s.length(); ++i) {\n char ch = s.charAt(i);\n if (ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch >= '0' && ch <= '9' || ch == '_')\n continue;\n return false;\n }\n return true;\n }\n\n public static void main(String[] args) {\n new Jabber().run();\n }\n\n BufferedReader reader;\n StringTokenizer tokenizer;\n PrintWriter writer;\n\n public void run() {\n try {\n reader = new BufferedReader(new InputStreamReader(System.in));\n tokenizer = null;\n writer = new PrintWriter(System.out);\n solve();\n reader.close();\n writer.close();\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(1);\n }\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n String nextToken() throws IOException {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(reader.readLine());\n }\n return tokenizer.nextToken();\n }\n}", "lang_cluster": "Java", "tags": ["strings", "implementation"], "code_uid": "bb888e3781def28a9ddcb5224d8b12e6", "src_uid": "2a68157e327f92415067f127feb31e24", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.Scanner;\n\npublic class Call\n{\n public static void main(String[] args)\n {\n Scanner scanner = new Scanner(System.in);\n int a = scanner.nextInt();\n int b = scanner.nextInt();\n int n = scanner.nextInt();\n int LCD = findLCD(a, b);\n System.out.println(n / LCD);\n }\n\n private static int findLCD(int a, int b) {\n return (a * b)/ findGCD(a, b);\n }\n\n private static int findGCD(int a, int b) {\n int Max = Math.max(a, b);\n int Min = Math.min(a, b);\n if(Max % Min == 0)\n return Min;\n return findGCD(Min, Max % Min);\n\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "math", "implementation"], "code_uid": "e41bf336eb7dee2b11b3b4d7350db368", "src_uid": "e7ad55ce26fc8610639323af1de36c2d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.DataInputStream;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.Scanner;\n\npublic class b {\n\t\n\n\t\n\tpublic static void main(String[] rgs)\n\t{\n\t\tScanner s=new Scanner(System.in);\n\n\n\t\tchar[] arr=s.next().toCharArray();\n\t\tchar[] brr=s.next().toCharArray();\n\t\tint ans=0;\n\t\tint n=arr.length;\n\t\tfor(int i=0;ij) {\n\t\t\t\t\t\tif(count=0 ; i--) {\n if(k>0 && nn.charAt(i)=='0') {\n k--;\n }\n else if(k>0 && nn.charAt(i)!='0') {\n a++ ;\n }\n }\n System.out.println(a);\n }\n }\n static class Reader {\n private static BufferedReader b ;\n public static String line ;\n public Reader() {\n }\n\n public Reader(BufferedReader b) {\n this.b = b ;\n }\n private static StringTokenizer st = null;\n public static String next() {\n \n if(st==null || !st.hasMoreElements()) {\n try { \n line = b.readLine() ;\n if(line==null) {\n eof = true ; \n return null ;\n }\n else {\n st=new StringTokenizer(line);\n }\n } catch (IOException ex) {\n \n }\n }\n return st.nextToken() ;\n }\n public static String nextLine() {\n try {\n return b.readLine() ;\n } catch (IOException ex) {\n \n }\n return line ;\n }\n public static int nextInt() {\n return Integer.parseInt(next());\n }\n public static long nextLong() {\n return Long.parseLong(next());\n }\n public static float nextFloat() {\n return Float.parseFloat(next());\n }\n public void close() throws IOException {\n b.close() ;\n }\n \n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "greedy"], "code_uid": "6760289f19f37dbff1c21f1f9eb28c91", "src_uid": "7a8890417aa48c2b93b559ca118853f9", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\n\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main{\n static int[] p = new int[(1<<18) + 10];\n static int[] q = new int[(1<<18) + 10];\n static int lenp = 0, lenq = 0;\n static int M = 0;\n public static void main(String[] args){\n Scanner c = new Scanner(System.in);\n int n = c.nextInt();\n int m = c.nextInt();\n M = m;\n int[] nums = new int[n];\n for(int i=0;i> 1;\n dfs1(nums,0,mid-1,0);\n dfs2(nums,mid,n-1,0);\n// System.out.println(Arrays.toString(p) + \"-->\" + lenp);\n// System.out.println(Arrays.toString(q) + \"-->\" + lenq);\n Arrays.sort(p,0,lenp);\n Arrays.sort(q,0,lenq);\n\n\n int i=0, j=lenq-1;\n int result = p[lenp-1] - M + q[lenq-1];\n while(i < lenp){\n while((p[i] + q[j]) >= M)\n j--;\n result = Math.max(result,p[i]+q[j]);\n i++;\n }\n System.out.println(result);\n }\n //\u5de6\u8fb9\u7684dfs\n private static void dfs1(int[] nums, int i, int end ,int sum){\n if(i == end){\n p[lenp++] = sum;\n p[lenp++] = ((sum+nums[i])%M);\n return;\n }\n dfs1(nums,i+1,end, sum);\n dfs1(nums,i+1,end, (sum+nums[i])%M);\n }\n //\u53f3\u8fb9\u7684dfs\n private static void dfs2(int[] nums, int i, int end ,int sum){\n if(i == end){\n q[lenq++] = sum;\n q[lenq++] = ((sum+nums[i])%M);\n return;\n }\n dfs2(nums,i+1,end, sum);\n dfs2(nums,i+1,end, (sum+nums[i])%M);\n }\n}\n", "lang_cluster": "Java", "tags": ["meet-in-the-middle", "divide and conquer", "bitmasks"], "code_uid": "7959cc34765b379b2782b8d7b927c666", "src_uid": "d3a8a3e69a55936ee33aedd66e5b7f4a", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.math.BigInteger;\n\npublic class Main\n{\n public static void main(String[] args)\n {\n Scanner in = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n\n int n = in.nextInt();\n BigInteger[][][] dp = new BigInteger[111][5][2];\n for(int s=0;s<=n+n-2;s++)for(int last=0;last<=4;last++)for(int g=0;g<2;g++)dp[s][last][g]=BigInteger.ZERO;\n dp[0][0][0]=BigInteger.ONE;\n for (int s=0;s<=n+n-2;s++) {\n for (int last=0;last<=4;last++){\n for (int put=1;put<=4;put++){\n for (int g=0;g<2;g++){\n if(put==last)continue;\n for(int cnt=1;cnt<=n+n-2-s;cnt++) {\n \tint gg=g;\n \tif(cnt==n)gg=1;\n dp[s+cnt][put][gg]=dp[s+cnt][put][gg].add(dp[s][last][g]);}\n }\n }\n }\n }\n \n BigInteger ans=BigInteger.ZERO;\n for (int i=1;i<=4;i++)ans=ans.add(dp[n+n-2][i][1]);\n System.out.println(ans.toString());\n out.close();\n }\n}", "lang_cluster": "Java", "tags": ["math", "combinatorics"], "code_uid": "c3766a3bf79f023c3fbe5640b983386f", "src_uid": "3b02cbb38d0b4ddc1a6467f7647d53a9", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.HashSet;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Debabrata\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n polycarpandletters solver = new polycarpandletters();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class polycarpandletters {\n public void solve(int testNumber, InputReader scan, OutputWriter out) {\n int n = scan.nextInt();\n String s = scan.next();\n String[] array = s.split(\"[A-Z]{1,}\");\n int max = 0;\n HashSet set = new HashSet<>();\n for (String a : array) {\n for (int i = 0; i < a.length(); i++) {\n set.add(a.charAt(i));\n }\n max = Math.max(set.size(), max);\n// out.println(a);\n set.clear();\n }\n out.println(max);\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void println(int i) {\n writer.println(i);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public String nextString() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n if (Character.isValidCodePoint(c)) {\n res.appendCodePoint(c);\n }\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public String next() {\n return nextString();\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["brute force", "strings", "implementation"], "code_uid": "6b7b46da47c9cc90cc9c60ae38a08972", "src_uid": "567ce65f87d2fb922b0f7e0957fbada3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class Main {\n\tstatic long mod = 1000000007;\n\tpublic static void main(String[] args) {\n\t\tlong[][] c = new long[101][101];\n\t\tc[0][0] = 1;\n\t\tfor(int i = 1; i <= 100; i++)\n\t\tfor(int x = 0; x <= 100; x++)\n\t\t\tc[i][x] = ((x - 1 >= 0 ? c[i - 1][x - 1] : 0) + c[i - 1][x]) % mod;\n\t\t\n\t\tScanner r = new Scanner(System.in);\n\t\t\n\t\tint NN = r.nextInt();\n\t\t\n\t\tint[] a = new int[10];\n\t\tfor(int i = 0; i < 10; i++)\n\t\t\ta[i] = r.nextInt();\n\t\t\n\t\tint s = 0;\n\t\tfor(int i = 0; i < 10; i++)\n\t\t\ts += a[i];\n\t\t\n\t\tlong ret = 0;\n\t\t\n\t\tif(s == 0)ret += 9;\n\t\telse if(s == 1)ret++;\n\t\t\n\t\tfor(int x = 1; x <= 9; x++){\n\t\t\tint[] b = a.clone();\n\t\t\tb[x] = Math.max(0, b[x] - 1);\n\t\t\t\n\t\t\tlong[][] dp = new long[11][NN + 1];\n\t\t\tdp[0][0] = 1;\n\t\t\t\n\t\t\tfor(int i = 0; i <= 9; i++)\n\t\t\tfor(int rem = 0; rem <= NN; rem++)\n\t\t\tfor(int z = b[i]; z <= rem; z++){\n\t\t\t\tdp[i + 1][rem] += c[rem][z] * dp[i][rem - z];\n\t\t\t\tdp[i + 1][rem] %= mod;\n\t\t\t}\n\t\t\t\n\t\t\tfor(int N = 2; N <= NN; N++){\n\t\t\t\tret += dp[10][N - 1];\n\t\t\t\tret %= mod;\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(ret);\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics"], "code_uid": "5562878c5ae1e9c9ff7e704ac7a897ff", "src_uid": "c1b5169a5c3b1bd4a2f1df1069ee7755", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.util.StringTokenizer;\nimport java.io.Writer;\nimport java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author zodiacLeo\n */\npublic class Main\n{\n public static void main(String[] args)\n {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastScanner in = new FastScanner(inputStream);\n FastPrinter out = new FastPrinter(outputStream);\n TaskA solver = new TaskA();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskA\n {\n public void solve(int testNumber, FastScanner in, FastPrinter out)\n {\n long n = in.nextLong();\n long low = 0;\n long high = 14142136;\n while (high - low > 1)\n {\n long mid = low + (high - low) / 2;\n long last = mid * (mid + 1);\n last /= 2;\n if (last <= n)\n {\n low = mid;\n } else\n {\n high = mid;\n }\n }\n long last = low * (low + 1);\n last /= 2;\n if (last == n)\n {\n out.println(low);\n return;\n }\n out.println(n - last);\n//\n\n// long low = -1;\n// long high = ((long) 1e9);\n// while (high - low > 1)\n// {\n// long mid = low + (high - low) / 2;\n// long last = mid * (mid + 1);\n// last /= 2;\n// if (last <= 1e14)\n// {\n// low = mid;\n// } else\n// {\n// high = mid;\n// }\n// }\n// System.out.println(\"MAX = \" + low + \" max value = \" + (low * (low + 1)) / 2);\n// low = low + 1;\n// System.out.println((low * (low + 1)) / 2);\n }\n\n }\n\n static class FastPrinter extends PrintWriter\n {\n public FastPrinter(OutputStream out)\n {\n super(out);\n }\n\n public FastPrinter(Writer out)\n {\n super(out);\n }\n\n }\n\n static class FastScanner\n {\n public BufferedReader br;\n public StringTokenizer st;\n\n public FastScanner(InputStream is)\n {\n br = new BufferedReader(new InputStreamReader(is));\n }\n\n public FastScanner(File f)\n {\n try\n {\n br = new BufferedReader(new FileReader(f));\n } catch (FileNotFoundException e)\n {\n e.printStackTrace();\n }\n }\n\n public String next()\n {\n while (st == null || !st.hasMoreElements())\n {\n String s = null;\n try\n {\n s = br.readLine();\n } catch (IOException e)\n {\n e.printStackTrace();\n }\n if (s == null)\n return null;\n st = new StringTokenizer(s);\n }\n return st.nextToken();\n }\n\n public long nextLong()\n {\n return Long.parseLong(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "7d234d18898620a516ad5967a90bec9b", "src_uid": "1db5631847085815461c617854b08ee5", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.io.*;\nimport java.util.*;\nimport static java.lang.Integer.parseInt;\nimport java.math.BigInteger;\n\npublic class Main {\n\n public static void main(String[] args) throws IOException {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer tk;\n// Scanner in=new Scanner(System.in);\n // PrintWriter p = new PrintWriter(System.out);\n StringBuilder out = new StringBuilder();\n tk = new StringTokenizer(in.readLine());\n int n = parseInt(tk.nextToken());\n char[] a = in.readLine().toCharArray();\n boolean f = true;\n int cnt = 0;\n\n for (int i = 0; i < a.length;) {\n if (a[i] == '1') {\n cnt++;\n i++;\n\n } else if (a[i] == '0') {\n if (f) {\n out.append(cnt);\n f = false;\n } else if (!f) {\n out.replace(out.length() - 1, out.length(), cnt + \"\");\n }\n\n while (i < a.length && a[i] == '0') {\n out.append(a[i]);\n i++;\n }\n cnt = 0;\n \n }\n }\n if(cnt>0&&out.length()>0)\n out.replace(out.length()-1,out.length(),cnt+\"\");\n else if(cnt>0)\n out.append(cnt);\n System.out.println(out);\n }\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "c0734f14c96ba920126bd0f374669f3e", "src_uid": "a4b3da4cb9b6a7ed0a33a862e940cafa", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Arrays;\nimport java.util.LinkedList;\nimport java.util.Scanner;\n\npublic class Main {\n static String f(){\n Scanner scanner = new Scanner(System.in);\n LinkedList strings = new LinkedList(Arrays.asList(scanner.next().split(\"\")));\n int flag =0;\n int stringSize = strings.size();\n int divSize = Math.floorDiv(stringSize,2);\n for (int i = 0; i < divSize; i++) {\n if(!(strings.pollFirst().equals(strings.pollLast()))){\n if(++flag==2){\n return \"NO\";\n }\n }\n }\n if(flag == 1 || (flag == 0 && stringSize%2 == 1)) return \"YES\";\n else return \"NO\";\n }\n public static void main(String[] args){\n System.out.println(f());\n\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "strings", "constructive algorithms"], "code_uid": "77bf366595d03581bfb793cefdb10ec5", "src_uid": "fe74313abcf381f6c5b7b2057adaaa52", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\tpublic static void main(String args[]) throws FileNotFoundException {\n\t\tInputReader in = new InputReader(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tnew Solver().solve(in, out);\n\t\tout.close();\n\t}\n}\n\nclass Fibonacci{\n\tprivate long mod;\n\tprivate Map calculatedNumbers;\n\n\tpublic Fibonacci(long mod){\n\t\tcalculatedNumbers = new TreeMap<>();\n\t\tcalculatedNumbers.put(0l, 1l);\n\t\tcalculatedNumbers.put(1l, 1l);\n\t\tthis.mod = mod;\n\t}\n\n\tpublic long fib(long n){\n\t\tif(calculatedNumbers.containsKey(n)) return calculatedNumbers.get(n);\n\t\t\n\t\tlong k = n/2, res;\n\t\tif(n%2 == 0){\n\t\t\tres = (fib(k)*fib(k)+fib(k-1)*fib(k-1))%mod;\n\t\t}else{\n\t\t\tres = (fib(k)*fib(k+1)+fib(k-1)*fib(k))%mod;\n\t\t}\n\t\tcalculatedNumbers.put(n, res);\n\t\treturn res;\n\t}\n}\n\nclass Exponentation{\n\t//a^b mod m\n\tpublic static long calc(long a, long b, long m){\n\t\tif(b == 0) return 1;\n\t\tif(b == 1) return a;\n\t\tif(b%2 == 0) return calc(a*a%m, b/2, m);\n\t\telse return a*calc((a*a%m), (b-1)/2, m)%m;\n\t}\n}\n\nclass Solver{\n\tlong n, k, l, MOD;\n\n\tvoid read(InputReader in){\n\t\tn = in.nextLong();\n\t\tk = in.nextLong();\n\t\tl = in.nextLong();\n\t\tMOD = in.nextLong();\n\t}\n\n\tpublic void solve(InputReader in, PrintWriter out){\n\t\tread(in);\n\t\tif(l != 64 && (1l << l)-1 < k){\n\t\t\tout.println(0);\n\t\t\treturn;\n\t\t}\n\n\t\tlong zeroPos = new Fibonacci(MOD).fib(n+1);\n\t\tlong onePos = Exponentation.calc(2, n, MOD)-zeroPos;\n\t\twhile(onePos < 0) onePos += MOD;\n\n\t\tlong res = 1;\n\t\tfor(int i=0; i= currentLine.length) {\n\t\t\ttry {\n\t\t\t\tcurrentLine = reader.readLine().split(\"\\\\s+\");\n\t\t\t\ttoken = 0;\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\t\treturn currentLine[token++];\n\t}\n\n\tpublic int nextInt() {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tpublic long nextLong(){\n\t\treturn Long.parseLong(next());\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "combinatorics", "matrices", "implementation", "number theory"], "code_uid": "5316e588f5731269b4a741a2a8c2011e", "src_uid": "2163eec2ea1eed5da8231d1882cb0f8e", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.Map;\nimport java.util.Set;\n\npublic class Test {\n static PrintWriter writer =\n new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n int R, C;\n long[][] ch = new long[61][61];\n int[] cntA = new int[61], cntB = new int[61];\n long best = Long.MAX_VALUE;\n String str;\n Map cache = new HashMap<>();\n Set tried = new HashSet<>();\n\n public static void main(String[] args) {\n Test te = new Test();\n te.start();\n writer.flush();\n }\n\n static int readInt() {\n int ans = 0;\n boolean neg = false;\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (c == '-') {\n start = true;\n neg = true;\n continue;\n } else if (c >= '0' && c <= '9') {\n start = true;\n ans = ans * 10 + c - '0';\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return neg ? -ans : ans;\n }\n\n static long readLong() {\n long ans = 0;\n boolean neg = false;\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (c == '-') {\n start = true;\n neg = true;\n continue;\n } else if (c >= '0' && c <= '9') {\n start = true;\n ans = ans * 10 + c - '0';\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return neg ? -ans : ans;\n }\n\n static String readString() {\n StringBuilder b = new StringBuilder();\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (!Character.isWhitespace(c)) {\n start = true;\n b.append((char) c);\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return b.toString();\n }\n\n static int readChars(char[] a, int off) {\n int cnt = 0;\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (Character.isLetterOrDigit(c)) {\n start = true;\n a[off + cnt++] = (char) c;\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return cnt;\n }\n\n void dfs(long x, long y, int v1, int v2) {\n long diff = Math.abs(x - y);\n if (best <= 1 || diff - ch[v1][R] * ch[v2][R] >= best) return;\n if (v1 == R - 1 && v2 == R - 1) {\n if (diff < best) best = diff;\n return;\n }\n long key = x*10_000 + v1*100 + v2;\n if (tried.contains(key)) return;\n if (v1 >= R) {\n long cur = ch[v1][R] - ch[v1 - 1][R];\n long other = ch[v2][R];\n dfs(x, y + cur * other, v1 - 1, v2);\n }\n if (v2 >= R) {\n long cur = ch[v2][R] - ch[v2 - 1][R];\n long other = ch[v1][R];\n dfs(x + cur * other, y, v1, v2-1);\n }\n tried.add(key);\n }\n\n long solve(long x, long y, int v1, int v2) {\n long diff = Math.abs(x - y);\n if (diff - ch[v1][R] * ch[v2][R] > best) return 0;\n long key = x*10000 + v1*100 + v2;\n Long v = cache.get(key);\n if (v != null) return v;\n if (v1 < R || v2 < R) {\n if (v1 >= cntA[v1 + v2] && v2 >= cntB[v1 + v2]) {\n int sum = v1 + v2;\n v1 -= cntA[sum];\n v2 -= cntB[sum];\n return ch[v1 + v2][v1];\n }\n return 0;\n }\n long ans = 0;\n char c = str.charAt(v1 + v2 - 1);\n if (c != 'B') {\n long cur = ch[v1][R] - ch[v1 - 1][R];\n long other = ch[v2][R];\n ans += solve(x, y + cur * other, v1 - 1, v2);\n }\n if (c != 'A') {\n long cur = ch[v2][R] - ch[v2 - 1][R];\n long other = ch[v1][R];\n ans += solve(x + cur * other, y, v1, v2 - 1);\n }\n cache.put(key, ans);\n return ans;\n }\n\n void start() {\n R = readInt();\n C = readInt();\n for (int i = 0; i <= 2*(R + C); i++)\n for (int j = 0; j <= i; j++)\n if (j == 0 || j == i) ch[i][j] = 1;\n else ch[i][j] = ch[i - 1][j - 1] + ch[i - 1][j];\n long x = 0, y = 0;\n int v1 = R + C, v2 = R + C;\n while (v1 >= R && v2 >= R)\n if (x > y) {\n long cur = ch[v1][R] - ch[v1 - 1][R];\n long other = ch[v2][R];\n y += cur * other;\n v1--;\n } else {\n long cur = ch[v2][R] - ch[v2 - 1][R];\n long other = ch[v1][R];\n x += cur * other;\n v2--;\n }\n best = Math.abs(x - y);\n dfs(0, 0, R + C, R + C);\n str = readString();\n for (int i = 0; i < 2 * (R + C); i++) {\n cntA[i + 1] = cntA[i] + (str.charAt(i) == 'A' ? 1 : 0);\n cntB[i + 1] = cntB[i] + (str.charAt(i) == 'B' ? 1 : 0);\n }\n long ans = solve(0, 0, R + C, R + C);\n writer.println(ans);\n }\n}\n", "lang_cluster": "Java", "tags": ["meet-in-the-middle", "combinatorics"], "code_uid": "7e7b3e14b42d6fbac2cd986bdd0641f7", "src_uid": "1b978b5aed4a83a2250bb23cc1ad6f85", "difficulty": 3300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "// package CodeForces;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Problem_988E {\n\tstatic boolean valid(char[]tmp)\n\t{\n\t\tint n=tmp.length;\n\t\tif(tmp[n-2]=='2' && tmp[n-1]=='5')\n\t\t\treturn true;\n\t\tif(tmp[n-2]=='5' && tmp[n-1]=='0')\n\t\t\treturn true;\n\t\tif(tmp[n-2]=='7' && tmp[n-1]=='5')\n\t\t\treturn true;\n\t\tif(tmp[n-2]=='0' && tmp[n-1]=='0')\n\t\t\treturn true;\n\t\treturn false;\n\t}\n\tstatic int move(int i,int j)\n\t{\n\t\tchar []tmp=c.clone();\n\t\tint moves=0;\n\t\tif(i>j)\n\t\t\ti--;\n\t\twhile(j lastindx[];\n\t@SuppressWarnings(\"unchecked\")\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner();\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\tc=sc.nextLine().toCharArray();\n\t\tlastindx=new ArrayList[10];\n\t\tfor(int i=0;i<10;i++)\n\t\t\tlastindx[i]=new ArrayList<>();\n\t\tfor(int i=0;i 0) {\r\n\t\t\tString[] s = br.readLine().split(\" \");\r\n\t\t\tint n = Integer.parseInt(s[0]);\r\n\t\t\tint m = Integer.parseInt(s[1]);\r\n\t\t\tint k = Integer.parseInt(s[2]);\r\n\t\t\tsolve(n, m, k);\r\n\t\t}\r\n\t}\r\n\r\n\tprivate static void solve(int n, int m, int k) {\r\n\t\tint horizontal_domino = k;\r\n\t\tint vertical_domino = n * m / 2 - k;\r\n\r\n\t\tboolean flag = true;\r\n\t\tif (n % 2 != 0) {\r\n\t\t\thorizontal_domino -= m / 2;\r\n\t\t\tif (horizontal_domino < 0) {\r\n\t\t\t\tflag = false;\r\n\t\t\t}\r\n\t\t} else if (m % 2 != 0) {\r\n\t\t\tvertical_domino -= n / 2;\r\n\t\t\tif (vertical_domino < 0) {\r\n\t\t\t\tflag = false;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (horizontal_domino % 2 != 0 || vertical_domino % 2 != 0) {\r\n\t\t\tflag = false;\r\n\t\t}\r\n\r\n\t\tSystem.out.println(flag ? \"YES\" : \"NO\");\r\n\t}\r\n}\r\n", "lang_cluster": "Java", "tags": ["math", "constructive algorithms"], "code_uid": "6b28f417dd2a123dc59a4648c850d286", "src_uid": "4d0c0cc8faca62eb6384f8135b30feb8", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.BufferedInputStream;\nimport java.io.BufferedOutputStream;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.PrintStream;\nimport java.math.BigInteger;\nimport java.util.Scanner;\n\npublic class Test {\n\tpublic static void redirectIn(String fileName){\n\t\tFileInputStream fileStream=null;\n\t\ttry {\n\t\t\tfileStream=new FileInputStream(fileName);\n\t\t} catch (FileNotFoundException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t\tBufferedInputStream input=new BufferedInputStream(fileStream);\n\t\tSystem.setIn(input);\n\t}\n\tpublic static void redirectOut(String fileName){\n\t\tFileOutputStream fileStream=null;\n\t\ttry {\n\t\t\tfileStream=new FileOutputStream(fileName);\n\t\t} catch (FileNotFoundException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t\tPrintStream output=new PrintStream(fileStream);\n\t\tSystem.setOut(output);\n\t}\n\tpublic static Scanner initCin(){\n\t\t//redirectIn(\"test.in\");\n\t\treturn new Scanner(new BufferedInputStream(System.in));\n\t}\n\tpublic static PrintStream initOut(){\n\t\t//redirectOut(\"test.in\");\n\t\treturn System.out;\n\t}\n\tpublic final static PrintStream out=initOut();\n\tpublic final static Scanner cin=initCin();\n\t\n\tpublic static BigInteger n,x,y,c;\n\tpublic static BigInteger f(BigInteger k,BigInteger m){\n\t\tBigInteger temp=k.subtract(m);\n\t\tif(k.compareTo(m)==1) return temp.multiply(temp);\n\t\treturn new BigInteger(\"0\");\n\t}\n\tpublic static BigInteger h(BigInteger k,BigInteger m){\n\t\tBigInteger temp=k.subtract(m);\n\t\tBigInteger one=new BigInteger(\"1\");\n\t\tif(k.compareTo(m)==1) return temp.add(one).multiply(temp).shiftRight(1);\n\t\treturn new BigInteger(\"0\");\n\t}\n\tpublic static BigInteger H(BigInteger ans,BigInteger k,BigInteger x,BigInteger y) {\n\t\tBigInteger one=new BigInteger(\"1\");\n\t\tif(k.subtract(y).compareTo(x.subtract(one))==1&&\n\t\t\t\tk.subtract(x).compareTo(y.subtract(one))==1) \n\t\t\treturn ans.add(h(k.subtract(y), x.subtract(one)));\n\t\treturn ans;\n\t}\n\tpublic static BigInteger calc(BigInteger k) {\n\t\tBigInteger one=new BigInteger(\"1\");\n\t\tBigInteger ans=k.add(one).multiply(k);\n\t\tans=ans.add(ans).add(one);\n\t\t\n\t\tBigInteger xsubone=x.subtract(one),ysubone=y.subtract(one);\n\t\tBigInteger nsubx=n.subtract(x),nsuby=n.subtract(y);\n\t\tans=ans.subtract(\n\t\t\t\tf(k, xsubone).add(f(k, ysubone)).add(f(k, nsubx)).add(f(k, nsuby)\n\t\t\t\t\t\t));\n\t\t//if(k-x>y-1&&k-y>x-1) and+=h(k-x,y-1);\n\t\tans=H(ans,k,x,y);\n\t\t//if(k-(n-y+1)>x-1&&k-x>n-y) ans+=h(k-x, n-y);\n\t\tans=H(ans, k, x, nsuby.add(one));\n\t\t//if(k-(n-x+1)>y-1&&k-y>n-x) ans+=h(k-y, n-x);\n\t\tans=H(ans, k, y, nsubx.add(one));\n\t\t//if(k-(n-x+1)>n-y&&k-(n-y+1)>n-x) ans+=h(k-(n-y+1), n-x);\n\t\tans=H(ans, k, nsubx.add(one), nsuby.add(one));\n\t\treturn ans;\n\t}\n\tpublic static void main(String[] args){\n\t\tn=new BigInteger(cin.next());x=new BigInteger(cin.next());\n\t\ty=new BigInteger(cin.next());c=new BigInteger(cin.next());\n\t\tBigInteger one=new BigInteger(\"1\");\n\t\tBigInteger l=new BigInteger(\"0\"),r=n.multiply(n).add(one);\n\t\twhile(l.compareTo(r)==-1){\n\t\t\tBigInteger m=l.add(r).shiftRight(1);\n\t\t\tif(calc(m).compareTo(c)==-1)\n\t\t\t\tl=m.add(one);\n\t\t\telse \n\t\t\t\tr=m;\n\t\t}\n\t\tout.println(l);\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation", "binary search"], "code_uid": "cb5bac562bb00feaf59864f86b7e19a4", "src_uid": "232c5206ee7c1903556c3625e0b0efc6", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.math.*;\nimport java.io.*;\n\npublic class Main{\n\tstatic long even(long l, long r){\n\t if(r - l <= 20){\n\t long ans = 0L;\n\t for(long i = l; i <= r; i++){if(i % 2 == 0){ans++;}}\n\t return ans;\n\t }\n\t long l1 = (l % 2 == 0) ? l : (l + 1);\n\t long r1 = (r % 2 == 1) ? r : (r - 1);\n\t long ans = (r1 - l1 + 1) / 2;\n\t if(r % 2 == 0)\n\t ans++;\n\t return ans;\n\t}\n\tstatic long odd(long l, long r){\n\t\treturn (r - l + 1) - even(l, r);\n\t}\n\tpublic static void main(String args[]) throws IOException {\n\t\tScanner in = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tlong x1, y1, x2, y2;\n\t\tx1 = in.nextLong(); y1 = in.nextLong(); x2 = in.nextLong(); y2 = in.nextLong();\n\t\tout.println(((y2 - y1)/2 + 1) * (x2 - x1 + 1) - (x2 - x1)/2);\n\t\tout.flush();\n\t}\n}", "lang_cluster": "Java", "tags": ["math"], "code_uid": "24d90457454985320bba9d363d935da3", "src_uid": "00cffd273df24d1676acbbfd9a39630d", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Main {\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\t\tBufferedReader r = new BufferedReader(new InputStreamReader(System.in));\n\t\t\n\t\tint l = Integer.parseInt(r.readLine());\n\t\tboolean[] v = new boolean[l];\n\t\t\n\t\tchar[] s = r.readLine().toCharArray();\n\t\tint n = s.length;\n\t\tfor(char i:s)if(i!='?')v[i-'a']=true;\n\t\t\n\t\t\n\t\tif((n+1)/2 < l){\n\t\t\tSystem.out.println(\"IMPOSSIBLE\");\n\t\t\tSystem.exit(0);\n\t\t}\n\t\t\n\t\t//Check.\n\t\tfor (int i = 0; i <= n/2 ; i++) { \n\t\t\tif(s[i]!='?' && s[n-i-1]!='?' && s[i]!=s[n-i-1]){\n\t\t\t\tSystem.out.println(\"IMPOSSIBLE\");\n\t\t\t\tSystem.exit(0);\n\t\t\t}\n\t\t}\n\t\tfor (int i = n/2; i >=0; i--) {\n\t\t\tif(s[i]=='?' && s[n-i-1]=='?'){\n\t\t\t\ts[i] = get(v);\n\t\t\t\ts[n-i-1] = s[i];\n\t\t\t}\n\t\t\tif(s[i]=='?' || s[n-i-1]=='?'){\n\t\t\t\tif(s[i]=='?')s[i]=s[n-i-1];\n\t\t\t\telse s[n-i-1]=s[i];\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor(boolean i:v)if(!i){\n\t\t\tSystem.out.println(\"IMPOSSIBLE\");\n\t\t\tSystem.exit(0);\n\t\t}\n\t\t\n\t\tString out = \"\";\n\t\tfor(char i:s)out+=i;\n\t\t\n\t\tSystem.out.println(out);\n\t\t\n\t}\n\n\tprivate static char get(boolean[] v) {\n\t\tfor (int i = v.length-1; i>=0; i--) {\n\t\t\tif(v[i]==false){\n\t\t\t\tv[i] = true;\n\t\t\t\treturn (char) (i+'a');\n\t\t\t}\n\t\t}\n\t\treturn (char)(0+'a');\n\t}\n}\n", "lang_cluster": "Java", "tags": ["expression parsing"], "code_uid": "69530f7ea6972b462d1c95a1d576a660", "src_uid": "9d1dd9d722e5fe46823224334b3b208a", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n\npublic class B {\n\n static StringTokenizer st;\n static BufferedReader br;\n static PrintWriter pw;\n public static void main(String[] args) throws IOException {\n br = new BufferedReader(new InputStreamReader(System.in));\n pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n int n = nextInt();\n int m = nextInt();\n boolean[]lider = new boolean[n+1];\n Arrays.fill(lider, true);\n int[]timeexit = new int[n+1];\n char[]w = new char[m+1];\n int[]t = new int[m+1];\n for (int i = 1; i <= m; i++) {\n w[i] = next().charAt(0);\n t[i] = nextInt();\n }\n int last = 0;\n boolean[]in = new boolean[n+1];\n int cntin = 0;\n for (int i = 1; i <= m; i++) {\n if (w[i]=='+') {\n in[t[i]] = true;\n cntin++;\n }\n else {\n int s = 1;\n if (!in[t[i]])\n s = 0;\n if (cntin > s) {\n lider[t[i]] = false;\n }\n if (!in[t[i]]) {\n last = i;\n }\n else\n cntin--;\n in[t[i]] = false;\n }\n }\n for (int i = 1; i <= m; i++) {\n if (w[i]=='+') {\n if (timeexit[t[i]]+1 != i)\n lider[t[i]] = false;\n }\n else {\n timeexit[t[i]] = i;\n }\n }\n int s = 0;\n for (int i = 1; i <= n; i++) {\n if (in[i])\n s++;\n }\n if (s != 0) {\n for (int i = 1; i <= m; i++) {\n if (!in[t[i]])\n lider[t[i]] = false;\n }\n }\n if (last != 0) {\n for (int i = 1; i < last; i++) {\n if (t[i] != t[last])\n lider[t[i]] = false;\n }\n }\n for (int i = 1; i <= n; i++) {\n if (timeexit[i] != 0 && timeexit[i] != m && !in[i])\n lider[i] = false;\n }\n int cnt = 0;\n for (int i = 1; i <= n; i++) {\n if (lider[i])\n cnt++;\n }\n pw.println(cnt);\n for (int i = 1; i <= n; i++) {\n if (lider[i])\n pw.print(i+\" \");\n }\n pw.close();\n }\n private static int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n private static long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n private static double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n private static String next() throws IOException {\n while (st==null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "3f2e407bb205ce0094822901e336106c", "src_uid": "a3a337c7b919e7dfd7ff45ebf59681b5", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.io.*;\nimport static java.lang.Math.*;\n\npublic class A {\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint N = in.nextInt();\n\t\tlong[] V = new long[1000010];\n\t\tArrays.fill(V, 0);\n\t\tV[N] = 0;\n\t\tlong ans = 0;\n\t\tlong[] sum = new long[2];\n\t\tfor (int i = N-1; i >= 0; i--) {\n\t\t\tV[i] = 1;\n\t\t\tV[i] += sum[(i+1)%2];\n\t\t\tV[i] %= MOD;\n\t\t\tans += V[i];\n\t\t\tsum[i%2] += V[i];\n\t\t}\n\t\tans %= MOD;\n\t\tSystem.out.println(ans);\n\t}\n\tstatic long MOD = 1000000007L;\n}\n", "lang_cluster": "Java", "tags": ["math", "dp"], "code_uid": "09d7d5680ac1d76699191029aa910697", "src_uid": "5c4bd12df3915186a7b506c2060db125", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.System.exit;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class E {\n\n\tstatic void solve() throws Exception {\n\t\tint n = scanInt(), m = scanInt();\n\t\tString map[] = new String[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tmap[i] = scanString();\n\t\t}\n\t\tint ans = 0;\n\t\tint i = 0, j = 0;\n\t\twhile (true) {\n\t\t\tif (map[i].charAt(j) == '*') {\n\t\t\t\t++ans;\n\t\t\t}\n\t\t\tif (i == n - 1 && j == m - 1) {\n\t\t\t\tbreak;\n\t\t\t} else if (i == n - 1) {\n\t\t\t\t++j;\n\t\t\t} else if (j == m - 1) {\n\t\t\t\t++i;\n\t\t\t} else {\n\t\t\t\tfor (int d = 1;; d++) {\n\t\t\t\t\tif (j + d >= m || map[i].charAt(j + d) == '*') {\n\t\t\t\t\t\t++j;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t} else if (i + d >= n || map[i + d].charAt(j) == '*') {\n\t\t\t\t\t\t++i;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.print(ans);\n\t}\n\n\tstatic int scanInt() throws IOException {\n\t\treturn parseInt(scanString());\n\t}\n\n\tstatic long scanLong() throws IOException {\n\t\treturn parseLong(scanString());\n\t}\n\n\tstatic String scanString() throws IOException {\n\t\twhile (tok == null || !tok.hasMoreTokens()) {\n\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t\tin.close();\n\t\t\tout.close();\n\t\t} catch (Throwable e) {\n\t\t\te.printStackTrace();\n\t\t\texit(1);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "tags": ["greedy", "implementation", "shortest paths"], "code_uid": "68cfdbabe5e129241043ae0285fe7eb8", "src_uid": "f985d7a6e7650a9b855a4cef26fd9b0d", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\n\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class D {\n\tprivate static int n, k;\n\tprivate static int[] a;\n\n\tpublic static void main(String[] args) {\n\t\tn = ini();\n\t\tk = ini();\n\t\ta = ina(n);\n\t\t\n\t\tArrays.sort(a);\n\n\t\tint MX = (int)2e5+5;\n\t\tint[] count = new int[MX];\n\t\tlong[] steps = new long[MX];\n\t\t\n\t\tfor(int i=0; i=k) {\n//\t\t\t\tsol = Math.min(sol, ans[i]);\n//\t\t\t}\n//\t\t}\n//\t\tprintln(sol);\n\t\tout.flush();\n\t\tout.close();\n\n\t}\n\n\t//NONPROBLEM CODE\n\n\tprivate static InputReader in = new InputReader(System.in);\n\tprivate static PrintWriter out = new PrintWriter(System.out);\n\n\tprivate static class InputReader {\n\n\t\tprivate final InputStream stream;\n\t\tprivate final byte[] buf = new byte[8192];\n\t\tprivate int curChar, snumChars;\n\n\t\tpublic InputReader(InputStream st) {\n\t\t\tthis.stream = st;\n\t\t}\n\n\t\tpublic int read() {\n\t\t\tif (snumChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= snumChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tsnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (snumChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo {\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic int[] nextIntArray(int n) {\n\t\t\tint a[] = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\ta[i] = nextInt();\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic String readString() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isEndOfLine(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic boolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tprivate boolean isEndOfLine(int c) {\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t}\n\n\t}\n\n\t//INPUT SHORTCUTS\n\n\tprivate static int[] ina(int n) {\n\t\tint[] temp = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ttemp[i] = in.nextInt();\n\t\t}\n\t\treturn temp;\n\t}\n\n\tprivate static int ini() {\n\t\treturn in.nextInt();\n\t}\n\n\t//OTHER SHORTCUTS\n\tpublic static void sort(int[] a) {\n\t\tArrays.sort(a);\n\t}\n\n\t//PRINT SHORTCUTS\n\n\tprivate static void println(Object... o) {\n\t\tfor (Object x : o) {\n\t\t\tout.write(x + \" \");\n\t\t}\n\t\tout.write(\"\\n\");\n\t\tout.flush();\n\t}\n\n\tprivate static void print(Object... o) {\n\t\tfor (Object x : o) {\n\t\t\tout.write(x + \" \");\n\t\t}\n\t\tout.flush();\n\t}\n\n\tprivate static void debug(Object... o) {\n\t\tfor (Object x : o) {\n\t\t\tout.write(x + \" \");\n\t\t}\n\t\tout.write(\"\\n\");\n\t\tout.flush();\n\t}\n}\n", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "56eb338b6c7d97436ad76b755396ff53", "src_uid": "ed1a2ae733121af6486568e528fe2d84", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class LinksAndPearls {\n\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner (System.in);\n\t\tString chain = scan.nextLine();\n\t\tint len = chain.length();\n\t\tchain = chain.replaceAll(\"o\", \"\");\n\t\tint o = len-chain.length();\n\t\tint dash = chain.length();\n\t\tif(o>0) {\n\t\tif((dash==0) || (o==1) || ((dash%o==0 && dash>=o) && o>1)) {\n\t\t\tSystem.out.println(\"YES\");\n\t\t} else {\n\t\t\tSystem.out.println(\"NO\");\n\t\t}\n\t} else {\n\t\tSystem.out.println(\"YES\");\n\t}\n\n\t}}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "e65702ac46a9e79e4c08a721789f47aa", "src_uid": "6e006ae3df3bcd24755358a5f584ec03", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class A {\n static MyScanner sc;\n static PrintWriter pw;\n\n public static void main(String[] args) throws Throwable {\n sc = new MyScanner();\n pw = new PrintWriter(System.out);\n\n double x = sc.nextDouble();\n double y = sc.nextDouble();\n double z = sc.nextDouble();\n\n boolean greater = x > 1 || y > 1 || z > 1;\n String[] exp =\n {\"x^y^z\", \"x^z^y\", \"(x^y)^z\", \"(x^z)^y\",\n \"y^x^z\", \"y^z^x\", \"(y^x)^z\", \"(y^z)^x\",\n \"z^x^y\", \"z^y^x\", \"(z^x)^y\", \"(z^y)^x\",};\n\n\n double[] vals = new double[12];\n\n if (greater) {\n Arrays.fill(vals, -1e18);\n if (x > 1) {\n vals[0] = z * Math.log(y) + Math.log(Math.log(x));\n vals[1] = y * Math.log(z) + Math.log(Math.log(x));\n vals[2] = Math.log(y) + Math.log(z) + Math.log(Math.log(x));\n }\n if (y > 1) {\n vals[4] = z * Math.log(x) + Math.log(Math.log(y));\n vals[5] = x * Math.log(z) + Math.log(Math.log(y));\n vals[6] = Math.log(x) + Math.log(z) + Math.log(Math.log(y));\n }\n if (z > 1) {\n vals[8] = y * Math.log(x) + Math.log(Math.log(z));\n vals[9] = x * Math.log(y) + Math.log(Math.log(z));\n vals[10] = Math.log(x) + Math.log(y) + Math.log(Math.log(z));\n }\n String ans = \"\";\n double mx = -2e18;\n for (int i = 0; i < 12; i++)\n if (vals[i] > mx) {\n mx = vals[i];\n ans = exp[i];\n }\n pw.println(ans);\n\n } else {\n Arrays.fill(vals, 1e18);\n\n vals[0] = z * Math.log(y) + Math.log(Math.log(1 / x));\n vals[1] = y * Math.log(z) + Math.log(Math.log(1 / x));\n vals[2] = Math.log(y) + Math.log(z) + Math.log(Math.log(1 / x));\n vals[4] = z * Math.log(x) + Math.log(Math.log(1 / y));\n vals[5] = x * Math.log(z) + Math.log(Math.log(1 / y));\n vals[6] = Math.log(x) + Math.log(z) + Math.log(Math.log(1 / y));\n vals[8] = y * Math.log(x) + Math.log(Math.log(1 / z));\n vals[9] = x * Math.log(y) + Math.log(Math.log(1 / z));\n vals[10] = Math.log(x) + Math.log(y) + Math.log(Math.log(1 / z));\n\n String ans = \"\";\n double mn = 2e18;\n for (int i = 0; i < 12; i++)\n if (vals[i] < mn) {\n mn = vals[i];\n ans = exp[i];\n }\n pw.println(ans);\n\n }\n\n\n pw.flush();\n pw.close();\n }\n\n static class MyScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public MyScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "math", "constructive algorithms"], "code_uid": "bc8cbd2427f4cbc907ec3ba2ef1256e3", "src_uid": "a71cb5cda754ad2bf479bc3b0164fc4c", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class SmallestNumber {\n static BufferedReader br;\n static int[] n;\n static char[] operations;\n public static void main(String[] args) {\n try {\n br = new BufferedReader(new InputStreamReader(System.in));\n init();\n System.out.println(solve());\n br.close();\n }\n catch(Exception e) {\n e.printStackTrace();\n }\n }\n private static void init() throws IOException {\n \tn = new int[4];\n \toperations = new char[3];\n \tStringTokenizer st = new StringTokenizer(br.readLine());\n \tfor(int i = 0; i < 4; i++)\n \t\tn[i] = Integer.parseInt(st.nextToken());\n \tst = new StringTokenizer(br.readLine());\n \tfor(int i = 0; i < 3; i++)\n \t\toperations[i] = st.nextToken().charAt(0);\n }\n private static String solve() {\n \tint[] total;\n \tif(operations[0] == '*' && operations[1] == '*' && operations[2] == '*') {\n \t\tlong l = n[0] * n[1] * n[2];\n \t\treturn String.valueOf(l * n[3]);\n \t}\n \telse if(operations[0] == '+' && operations[1] == '*' && operations[2] == '*') {\n \t\ttotal = new int[6];\n \t\tfor(int i = 0; i < 6; i++) {\n \t\t\tif(i == 0) total[i] = (n[0] + n[1]) * n[2] * n[3];\n \t\t\telse if(i == 1) total[i] = (n[0] + n[2]) * n[1] * n[3];\n \t\t\telse if(i == 2) total[i] = (n[0] + n[3]) * n[1] * n[2];\n \t\t\telse if(i == 3) total[i] = (n[1] + n[2]) * n[0] * n[3];\n \t\t\telse if(i == 4) total[i] = (n[1] + n[3]) * n[0] * n[2];\n \t\t\telse total[i] = (n[2] + n[3]) * n[0] * n[1];\n \t\t}\n \t}\n \telse if(operations[0] == '*' && operations[1] == '+' && operations[2] == '*') {\n \t\ttotal = new int[24];\n \t\tfor(int i = 0; i < 24; i++) {\n \t\t\tif(i == 0) total[i] = (n[0] * n[2] + n[3]) * n[1];\n \t\t\telse if(i == 1) total[i] = (n[0] * n[3] + n[2]) * n[1];\n \t\t\telse if(i == 2) total[i] = (n[0] * n[1] + n[3]) * n[2];\n \t\t\telse if(i == 3) total[i] = (n[0] * n[3] + n[1]) * n[2];\n \t\t\telse if(i == 4) total[i] = (n[0] * n[1] + n[2]) * n[3];\n \t\t\telse if(i == 5) total[i] = (n[0] * n[2] + n[1]) * n[3];\n \t\t\telse if(i == 6) total[i] = (n[1] * n[2] + n[3]) * n[0];\n \t\t\telse if(i == 7) total[i] = (n[1] * n[3] + n[2]) * n[0];\n \t\t\telse if(i == 8) total[i] = (n[1] * n[0] + n[3]) * n[2];\n \t\t\telse if(i == 9) total[i] = (n[1] * n[3] + n[0]) * n[2];\n \t\t\telse if(i == 10) total[i] = (n[1] * n[0] + n[2]) * n[3];\n \t\t\telse if(i == 11) total[i] = (n[1] * n[2] + n[0]) * n[3];\n \t\t\telse if(i == 12) total[i] = (n[2] * n[1] + n[3]) * n[0];\n \t\t\telse if(i == 13) total[i] = (n[2] * n[3] + n[1]) * n[0];\n \t\t\telse if(i == 14) total[i] = (n[2] * n[0] + n[3]) * n[1];\n \t\t\telse if(i == 15) total[i] = (n[2] * n[3] + n[0]) * n[1];\n \t\t\telse if(i == 16) total[i] = (n[2] * n[0] + n[1]) * n[3];\n \t\t\telse if(i == 17) total[i] = (n[2] * n[1] + n[0]) * n[3];\n \t\t\telse if(i == 18) total[i] = (n[3] * n[1] + n[2]) * n[0];\n \t\t\telse if(i == 19) total[i] = (n[3] * n[2] + n[1]) * n[0];\n \t\t\telse if(i == 20) total[i] = (n[3] * n[0] + n[2]) * n[1];\n \t\t\telse if(i == 21) total[i] = (n[3] * n[2] + n[0]) * n[1];\n \t\t\telse if(i == 22) total[i] = (n[3] * n[0] + n[1]) * n[2];\n \t\t\telse total[i] = (n[3] * n[1] + n[0]) * n[2];\n \t\t}\n \t}\n \telse if(operations[0] == '*' && operations[1] == '*' && operations[2] == '+') {\n \t\ttotal = new int[3];\n \t\tfor(int i = 0; i < 3; i++) {\n \t\t\tif(i == 0) total[i] = n[0] * n[1] + n[2] * n[3];\n \t\t\telse if(i == 1) total[i] = n[0] * n[2] + n[1] * n[3];\n \t\t\telse total[i] = n[0] * n[3] + n[1] * n[2];\n \t\t}\n \t}\n \telse if(operations[0] == '*' && operations[1] == '+' && operations[2] == '+') {\n \t\ttotal = new int[6];\n \t\tfor(int i = 0; i < 6; i++) {\n \t\t\tif(i == 0) total[i] = n[0] * n[1] + n[2] + n[3];\n \t\t\telse if(i == 1) total[i] = n[0] * n[2] + n[1] + n[3];\n \t\t\telse if(i == 2) total[i] = n[0] * n[3] + n[1] + n[2];\n \t\t\telse if(i == 3) total[i] = n[1] * n[2] + n[0] + n[3];\n \t\t\telse if(i == 4) total[i] = n[1] * n[3] + n[0] + n[2];\n \t\t\telse total[i] = n[2] * n[3] + n[0] + n[1];\n \t\t}\n \t}\n \telse if(operations[0] == '+' && operations[1] == '*' && operations[2] == '+') {\n \t\ttotal = new int[30];\n \t\tfor(int i = 0; i < 30; i++) {\n \t\t\tif(i == 0) total[i] = n[2] * (n[0] + n[1]) + n[3];\n \t\t\telse if(i == 1) total[i] = (n[0] + n[1]) * n[3] + n[2];\n \t\t\telse if(i == 2) total[i] = (n[0] + n[2]) * n[1] + n[3];\n \t\t\telse if(i == 3) total[i] = (n[0] + n[2]) * n[3] + n[1];\n \t\t\telse if(i == 4) total[i] = (n[0] + n[3]) * n[1] + n[2];\n \t\t\telse if(i == 5) total[i] = (n[0] + n[3]) * n[2] + n[1];\n \t\t\telse if(i == 6) total[i] = (n[1] + n[0]) * n[2] + n[3];\n \t\t\telse if(i == 7) total[i] = (n[1] + n[0]) * n[3] + n[2];\n \t\t\telse if(i == 8) total[i] = (n[1] + n[2]) * n[0] + n[3];\n \t\t\telse if(i == 9) total[i] = (n[1] + n[2]) * n[3] + n[0];\n \t\t\telse if(i == 10) total[i] = (n[1] + n[3]) * n[0] + n[2];\n \t\t\telse if(i == 11) total[i] = (n[1] + n[3]) * n[2] + n[0];\n \t\t\telse if(i == 12) total[i] = (n[2] + n[0]) * n[1] + n[3];\n \t\t\telse if(i == 13) total[i] = (n[2] + n[0]) * n[3] + n[1];\n \t\t\telse if(i == 14) total[i] = (n[2] + n[1]) * n[0] + n[3];\n \t\t\telse if(i == 15) total[i] = (n[2] + n[1]) * n[3] + n[0];\n \t\t\telse if(i == 16) total[i] = (n[2] + n[3]) * n[0] + n[1];\n \t\t\telse if(i == 17) total[i] = (n[2] + n[3]) * n[1] + n[0];\n \t\t\telse if(i == 18) total[i] = (n[3] + n[2]) * n[0] + n[1];\n \t\t\telse if(i == 19) total[i] = (n[3] + n[2]) * n[1] + n[0];\n \t\t\telse if(i == 20) total[i] = (n[3] + n[1]) * n[0] + n[2];\n \t\t\telse if(i == 21) total[i] = (n[3] + n[1]) * n[2] + n[0];\n \t\t\telse if(i == 22) total[i] = (n[3] + n[0]) * n[1] + n[2];\n \t\t\telse if(i == 23) total[i] = n[0] * n[1] + (n[2] + n[3]);\n \t\t\telse if(i == 24) total[i] = n[0] * n[2] + (n[1] + n[3]);\n \t\t\telse if(i == 25) total[i] = n[0] * n[3] + (n[1] + n[2]);\n \t\t\telse if(i == 26) total[i] = n[1] * n[2] + (n[0] + n[3]);\n \t\t\telse if(i == 27) total[i] = n[1] * n[3] + (n[0] + n[2]);\n \t\t\telse if(i == 28) total[i] = n[2] * n[3] + (n[0] + n[1]);\n \t\t\telse total[i] = (n[3] + n[0]) * n[2] + n[1];\n \t\t}\n \t}\n \telse if(operations[0] == '+' && operations[1] == '+' && operations[2] == '*') {\n \t\ttotal = new int[7];\n \t\tfor(int i = 0; i < 7; i++) {\n \t\t\tif(i == 0) total[i] = (n[1] + n[2] + n[3]) * n[0];\n \t\t\telse if(i == 1) total[i] = (n[0] + n[2] + n[3]) * n[1];\n \t\t\telse if(i == 2) total[i] = (n[0] + n[1] + n[3]) * n[2];\n \t\t\telse if(i == 3) total[i] = (n[0] + n[1] + n[2]) * n[3];\n \t\t\telse if(i == 4) total[i] = (n[0] + n[1]) * (n[2] + n[3]);\n \t\t\telse if(i == 5) total[i] = (n[0] + n[2]) * (n[1] + n[3]);\n \t\t\telse total[i] = (n[0] + n[3]) * (n[1] + n[2]);\n \t\t}\n \t}\n \telse\n \t\treturn String.valueOf(n[0] + n[1] + n[2] + n[3]);\n// \tSystem.out.println(Arrays.toString(total));\n \tArrays.sort(total);\n// \tSystem.out.println(Arrays.toString(total));\n\t\treturn String.valueOf(total[0]);\n }\n}", "lang_cluster": "Java", "tags": ["brute force"], "code_uid": "c6ca45a4d12eb0415b7f39d3c7bdc84f", "src_uid": "7a66fae63d9b27e444d84447012e484c", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class HitBall203D {\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tdouble a, b, m;\n\t\ta = in.nextInt();\n\t\tb = in.nextInt();\n\t\tm = in.nextInt();\n\t\tdouble vx, vy, vz;\n\t\tvx = in.nextInt();\n\t\tvy = in.nextInt();\n\t\tvz = in.nextInt();\n\t\tdouble t = -1 * m / vy;\n\t\tdouble x = t * vx + a / 2;\n\t\tdouble z = t * vz;\n\t\twhile (z - 2 * b >= 0)\n\t\t\tz -= 2 * b;\n\t\tif (z > b)\n\t\t\tz = 2 * b - z;\n\t\tif (x < 0) {\n\t\t\twhile (x < 0)\n\t\t\t\tx += 2 * a;\n\t\t} else {\n\t\t\twhile (x - 2 * a >= 0)\n\t\t\t\tx -= 2 * a;\n\t\t}\n\t\tif (x > a)\n\t\t\tx = 2 * a - x;\n\t\tSystem.out.printf(\"%f %f\\n\", x, z);\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "geometry", "implementation"], "code_uid": "b073934486fbe9ccd3ed4f98f44a5220", "src_uid": "84848b8bd92fd2834db1ee9cb0899cff", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.Reader;\nimport java.util.StringTokenizer;\n\npublic class TaskC {\n public static String doMain(Reader reader) throws IOException {\n MyReader in = new MyReader(reader);\n int n = in.nextInt();\n int p = in.nextInt();\n StringBuilder sb = new StringBuilder();\n for (int i = 0; n - i * p >= i; ++i) {\n int count = check(n - p * i);\n if (count > i){\n continue;\n }\n return i+\"\";\n }\n return \"-1\";\n }\n\n private static int check(int n) {\n int answer = 0;\n while (n > 0) {\n answer += n % 2;\n n /= 2;\n }\n return answer;\n }\n\n public static void main(String[] args) throws IOException {\n String result = doMain(new InputStreamReader(System.in));\n System.out.println(result);\n }\n\n static class MyReader {\n BufferedReader bf;\n\n StringTokenizer st;\n\n String last;\n\n MyReader(Reader reader) throws IOException {\n bf = new BufferedReader(reader);\n readNextLine();\n }\n\n String nextToken() throws IOException {\n while (!st.hasMoreTokens()) {\n readNextLine();\n }\n return st.nextToken();\n }\n\n void readNextLine() throws IOException {\n last = bf.readLine();\n if (last == null) last = \"\";\n st = new StringTokenizer(last);\n }\n\n String nextLine() throws IOException {\n String s = last;\n readNextLine();\n return s;\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n int[] readIntArray(int n) throws IOException {\n int[] answer = new int[n];\n for (int i = 0; i < n; ++i) {\n answer[i] = nextInt();\n }\n return answer;\n }\n\n long[] readLongArray(int n) throws IOException {\n long[] answer = new long[n];\n for (int i = 0; i < n; ++i) {\n answer[i] = nextLong();\n }\n return answer;\n }\n\n double[] readDoubleArray(int n) throws IOException {\n double[] answer = new double[n];\n for (int i = 0; i < n; ++i) {\n answer[i] = nextDouble();\n }\n return answer;\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "math", "bitmasks"], "code_uid": "a44c692761f655671c553a3fd68e9191", "src_uid": "9e86d87ce5a75c6a982894af84eb4ba8", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.Scanner;\npublic class D {\npublic static void main(String[] args) {\nScanner in = new Scanner(System.in);\nint n = in.nextInt();\nSystem.out.print((n+1)/36+\" \"+(n+1)%36/3);\n}\n}", "lang_cluster": "Java", "tags": ["math"], "code_uid": "904c375b099843dabba72135fb7553d3", "src_uid": "5d4f38ffd1849862623325fdbe06cd00", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 17", "source_code": "import java.util.*;\r\nimport java.util.function.*;\r\nimport java.io.*;\r\n\r\n// you can compare with output.txt and expected out\r\npublic class Round818E {\t\r\n\tMyPrintWriter out;\r\n\tMyScanner in;\r\n\t\r\n//\tfinal static long FIXED_RANDOM;\r\n//\tstatic {\r\n//\t\tFIXED_RANDOM = System.currentTimeMillis();\r\n//\t}\r\n\tfinal static String IMPOSSIBLE = \"IMPOSSIBLE\";\r\n\tfinal static String POSSIBLE = \"POSSIBLE\";\r\n\tfinal static String YES = \"YES\";\r\n\tfinal static String NO = \"NO\";\r\n\t\r\n private void initIO(boolean isFileIO) {\r\n if (System.getProperty(\"ONLINE_JUDGE\") == null && isFileIO) {\r\n \ttry{\r\n\t in = new MyScanner(new FileInputStream(\"input.txt\"));\r\n\t out = new MyPrintWriter(new FileOutputStream(\"output.txt\"));\r\n \t}\r\n \tcatch(FileNotFoundException e){\r\n \t\te.printStackTrace();\r\n \t}\r\n }\r\n else{\r\n \t\tin = new MyScanner(System.in);\r\n \t out = new MyPrintWriter(new BufferedOutputStream(System.out));\r\n }\r\n }\r\n\t\r\n\tpublic static void main(String[] args){\r\n//\t\tScanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\r\n\t\t\r\n\t\tRound818E sol = new Round818E();\r\n\t\tsol.run();\r\n }\r\n\t\r\n\tprivate void run() {\r\n\t\tboolean isDebug = false;\r\n\t\tboolean isFileIO = true;\r\n\t\tboolean hasMultipleTests = false;\r\n\t\t\r\n\t\tinitIO(isFileIO);\r\n\t\t\r\n\t\t//test();\r\n\t\r\n\t\tint t = hasMultipleTests? in.nextInt() : 1;\r\n\t \r\n\t for (int i = 1; i <= t; ++i) {\r\n\t \tif(isDebug){\r\n\t\t \tout.printf(\"Test %d\\n\", i);\r\n\t \t}\r\n\r\n\t \tgetInput();\r\n\r\n\t \tsolve();\r\n\t \t\r\n\t \tprintOutput();\r\n\t }\r\n\t \r\n\t in.close();\r\n\t out.close();\r\n\t}\r\n\t\r\n\tstatic long MOD = 1_000_000_007;\r\n\t\r\n\tvoid test() {\r\n\t\tfor(int i=2; i<=100; i++) {\r\n\t\t\tn = i;\r\n\t\t\tlong[] compare = new long[n+1];\r\n\t\t\tlong expected = 0;\r\n\t\t\tfor(int a=1; a<=n; a++) {\r\n\t\t\t\tfor(int b=1; b<=n; b++) {\r\n\t\t\t\t\tlong c = n-a-b;\r\n\t\t\t\t\tif(c < 0)\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\tint g = gcd(a, b);\r\n\t\t\t\t\tlong gg = gcd(c, g);\r\n\t\t\t\t\texpected += gg*(c/gg)*(g/gg);\r\n\t\t\t\t\tcompare[g] += gg*(c/gg)*(g/gg);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tsolve();\r\n\t\t\tif(expected != ans) {\r\n\t\t\t\tsolve();\r\n\t\t\t}\r\n\r\n\t\t}\r\n\t}\r\n\t\r\n\t// use suitable one between matrix(2, n), matrix(n, 2), transposedMatrix(2, n) for graph edges, pairs, ...\r\n\tint n;\r\n\tvoid getInput() {\r\n\t\tn = in.nextInt(); \r\n\t}\r\n\t\r\n\tvoid printOutput() {\r\n\t\tout.printlnAns(ans);\r\n\t}\r\n\r\n\tlong[] check;\r\n\tlong ans;\r\n\tvoid solve(){\r\n\t\t// sum lcm(c, gcd(a, b)) for a+b+c = n\r\n\t\t\r\n\t\t// for each g = gcd(a, b),\r\n\t\t\r\n\t\t// g = 1\r\n\t\t// lcm = c = n-a-b, so need to count #(a, b) s.t. gcd(a,b)=1 and sum of a+b for such pairs\r\n\t\t\r\n\t\t// g = 2\r\n\t\t// a = 2a', b = 2b'\r\n\t\t// lcm = c if 2 | n, 2c otherwise\r\n\t\t\r\n\t\t// g = 3\r\n\t\t// same strategy\r\n\t\t\r\n\t\t// gcd(g, n - ga' - gb') = gcd(g, n) = k\r\n\t\t// lcm(g, n - ga' - gb') = g*(n-ga'-gb')*k --- i.e., only need #(a, b) and sum of a+b\r\n\t\t\r\n\t\t// given s,\r\n\t\t// for each a,\r\n\t\t// want to count #b s.t. gcd(a, b) = 1, a + b <= s, b < a\r\n\t\t// for this, simply generate all divisors and exclude them\r\n\t\t\r\n//\t\tArrayList[] divisors = new ArrayList[n+1];\r\n//\t\tArrayList[] prefixSum = new ArrayList[n+1];\r\n\t\t\r\n//\t\tfor(int i=2; i<=n; i++)\r\n//\t\t\tdivisors[i] = new ArrayList();\r\n//\t\tfor(int i=2; i<=n; i++) {\r\n//\t\t\tif(divisors[i].isEmpty()) {\r\n//\t\t\t\tdivisors[i].add(1);\r\n//\t\t\t\tdivisors[i].add(i);\r\n//\t\t\t\t// i*i <= n\r\n//\t\t\t\tif(n/i >= i) {\r\n//\t\t\t\t\tfor(int j=i*i; j<=n; j+=i)\r\n//\t\t\t\t\t\tif(divisors[j].isEmpty())\r\n//\t\t\t\t\t\t\tdivisors[j].add(i);\r\n//\t\t\t\t}\r\n//\t\t\t}\r\n//\t\t\telse {\r\n//\t\t\t\tint prime = divisors[i].remove(0);\r\n//\t\t\t\tint maxPrime = 1;\r\n//\t\t\t\t{\r\n//\t\t\t\t\tint m = i/prime;\r\n//\t\t\t\t\twhile(m % prime == 0) {\r\n//\t\t\t\t\t\tm /= prime;\r\n//\t\t\t\t\t\tmaxPrime *= prime;\r\n//\t\t\t\t\t}\r\n//\t\t\t\t}\r\n//\t\t\t\tfor(int divisor: divisors[i/prime]) {\r\n//\t\t\t\t\tif(divisor % maxPrime == 0)\r\n//\t\t\t\t\t\tdivisors[i].add(divisor*prime);\r\n//\t\t\t\t\tdivisors[i].add(divisor);\r\n//\t\t\t\t}\r\n//\t\t\t\tCollections.sort(divisors[i]);\r\n//\t\t\t}\r\n//\t\t\tprefixSum[i] = new ArrayList();\r\n//\t\t\tlong sum = 0;\r\n//\t\t\tfor(int divisor: divisors[i]){\r\n//\t\t\t\tsum += divisor;\r\n//\t\t\t\tprefixSum[i].add(sum);\r\n//\t\t\t}\r\n//\t\t}\r\n\t\t\r\n\t\tArrayList[] primeFactors = new ArrayList[n+1];\r\n\t\tfor(int i=2; i<=n; i++)\r\n\t\t\tprimeFactors[i] = new ArrayList();\r\n\t\t\r\n//\t\tint[][] prefixCnt = new int[n+1][];\r\n//\t\tlong[][] prefixSum = new long[n+1][];\r\n\t\t\r\n\t\tfor(int i=2; i<=n; i++) {\r\n\t\t\tif(primeFactors[i].isEmpty()) {\r\n\t\t\t\tprimeFactors[i].add(i);\r\n\t\t\t\t// i*i <= n\r\n\t\t\t\tif(n/i >= i) {\r\n\t\t\t\t\tfor(int j=i*i; j<=n; j+=i)\r\n\t\t\t\t\t\tif(primeFactors[j].isEmpty())\r\n\t\t\t\t\t\t\tprimeFactors[j].add(i);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tint prime = primeFactors[i].get(0);\r\n\t\t\t\tint rest = i/prime;\r\n\t\t\t\twhile(rest % prime == 0)\r\n\t\t\t\t\trest /= prime;\r\n\t\t\t\tif(rest > 1)\r\n\t\t\t\t\tfor(int factor: primeFactors[rest])\r\n\t\t\t\t\t\tprimeFactors[i].add(factor);\r\n\t\t\t}\r\n//\t\t\tint N = n/i;\r\n//\t\t\tint[] cnt = new int[N+1];\r\n//\t\t\tlong[] sum = new long[N+1];\r\n//\t\t\tprefixCnt[i] = cnt;\r\n//\t\t\tprefixSum[i] = sum;\r\n//\t\t\tfor(int j=1; j<=N; j++) {\r\n//\t\t\t\tcnt[j] = cnt[j-1];\r\n//\t\t\t\tsum[j] = sum[j-1];\r\n//\t\t\t\tif(j % i == 0) {\r\n//\t\t\t\t\tcnt[j]++;\r\n//\t\t\t\t\tsum[j]+=j;\r\n//\t\t\t\t}\r\n//\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tans = 0;\r\n\t\tcheck = new long[n+1];\r\n\t\tfor(long g=1; g<=n; g++) {\r\n\t\t\tif(g*2 + 1 > n)\r\n\t\t\t\tbreak;\r\n\t\t\tlong cnt = 0;\r\n\t\t\tlong sum = 0;\r\n\t\t\t// 1) a < b\r\n\r\n\t\t\t// want to count #b' s.t. gcd(a', b') = 1, a' + b' <= s, b' < a'\r\n\t\t\t// g(a'+b')+1 <= n\r\n\t\t\tfor(int ap=2; ap<=n; ap++) {\r\n\t\t\t\tif(g*(ap+1) + 1 > n)\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t\r\n\t\t\t\tlong maxBp = Math.min(ap-1, (n-1)/g - ap);\r\n\t\t\t\tlong currCnt = maxBp;\r\n\t\t\t\tsum += maxBp*(maxBp+1)/2 % MOD;\r\n\t\t\t\t\r\n\t\t\t\tint k = primeFactors[ap].size();\r\n\t\t\t\tfor(int mask=1; mask<(1< 0) {\r\n\t\t\t\t\t\t\tcurr *= primeFactors[ap].get(pos);\r\n\t\t\t\t\t\t\tsign *= -1;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\t// s*curr + g*ap + 1 <= n\r\n\t\t\t\t\tlong s = Math.min((ap-1)/curr, (n-1 - g*ap)/curr/g);\r\n//\t\t\t\t\tcurrCnt += prefixCnt[curr][s] * sign;\r\n//\t\t\t\t\tsum += prefixSum[curr][s] * sign;\r\n\t\t\t\t\tcurrCnt += s * sign;\r\n\t\t\t\t\tsum += curr * s * (s+1)/2 * sign;\r\n\t\t\t\t}\r\n\t\t\t\t\r\n//\t\t\t\tHashSet bad = new HashSet<>();\r\n//\t\t\t\tfor(int prime: primeFactors[ap]) {\r\n//\t\t\t\t\tfor(int i=1; i<=n; i++) {\r\n//\t\t\t\t\t\tint bp = prime*i;\r\n//\t\t\t\t\t\tif(bp >= ap || g*(ap+bp) + 1 > n)\r\n//\t\t\t\t\t\t\tbreak;\r\n//\t\t\t\t\t\tif(!bad.contains(bp)) {\r\n//\t\t\t\t\t\t\tbad.add(bp);\r\n//\t\t\t\t\t\t\tcurrCnt--;\r\n//\t\t\t\t\t\t\tsum -= bp;\r\n//\t\t\t\t\t\t}\r\n//\t\t\t\t\t}\r\n//\t\t\t\t}\r\n\t\t\t\t\r\n\t\t\t\tcnt += currCnt;\r\n\t\t\t\tsum += currCnt * ap;\r\n\t\t\t\tsum %= MOD;\r\n\t\t\t\t\r\n//\t\t\t\tint k = divisors[ap].size();\r\n//\t\t\t\tint lo = 0;\r\n//\t\t\t\tint hi = k-2;\r\n//\t\t\t\twhile(lo < hi) {\r\n//\t\t\t\t\tint mid = (lo+hi+1)/2;\r\n//\t\t\t\t\tint bp = divisors[ap].get(mid);\r\n//\t\t\t\t\tif(g*(ap+bp) + 1 > n)\r\n//\t\t\t\t\t\thi = mid-1;\r\n//\t\t\t\t\telse\r\n//\t\t\t\t\t\tlo = mid;\r\n//\t\t\t\t}\r\n//\t\t\t\t// g*(ap+maxBp)+1 <= n\r\n//\t\t\t\tlong maxBp = Math.min(ap-1, (n-1)/g - ap);\r\n//\t\t\t\t// g(1+...+maxBp)\r\n//\t\t\t\tlong currCnt = maxBp - lo; // 1 is always ok\r\n//\t\t\t\tcnt += currCnt;\r\n//\t\t\t\tsum += currCnt * ap % MOD;\r\n//\t\t\t\tsum += maxBp*(maxBp+1)/2 % MOD;\r\n//\t\t\t\tsum -= (prefixSum[ap].get(lo)-1) % MOD;\r\n\t\t\t}\r\n\r\n\t\t\t// then *2\r\n\t\t\tcnt *= 2;\r\n\t\t\tsum *= g*2;\r\n\r\n\t\t\t// 2) a = b = g\r\n\t\t\tcnt ++;\r\n\t\t\tsum += g*2;\r\n\t\t\t\r\n\t\t\tcnt %= MOD;\r\n\t\t\tsum %= MOD;\r\n\t\t\tif(sum < 0)\r\n\t\t\t\tsum += MOD;\r\n\t\t\t\r\n\t\t\t// (1, 1)\r\n\t\t\t// (1, 2), (1, 3)\r\n\t\t\t// (2, 1), (3, 1)\r\n\t\t\t\r\n\t\t\t// n = 6\r\n\t\t\t// (1, 1)\r\n\t\t\t// (1, 2) \r\n\t\t\t// (1, 3), (2, 3)\r\n\t\t\t// (1, 4)\r\n\t\t\t// cnt = 1 + 4*2 = 9\r\n\t\t\t// sum = 2 + 17*2 = 36\r\n\t\t\t// 4 + (3 + 2 + 1 + 1)*2 = 18\r\n\t\t\t\r\n\t\t\t// (2, 2)\r\n\t\t\t// 2\r\n\t\t\t\r\n\t\t\t// 6 * 9 = 54\r\n\t\t\t// 36\r\n\t\t\t\r\n\t\t\t// lcm(g, n - ga' - gb') = g/k*(n-ga'-gb')/k*k --- i.e., only need #(a, b) and sum of a+b\r\n\t\t\tcheck[(int)g] -= ans;\r\n\t\t\tlong k = gcd(g, n);\r\n\t\t\tans += g*n/k*cnt % MOD;\r\n\t\t\tans -= g/k*sum % MOD;\r\n\t\t\tcheck[(int)g] += ans;\r\n\t\t}\r\n\t\tans %= MOD;\r\n\t\tif(ans < 0)\r\n\t\t\tans += MOD;\r\n\t}\r\n\t\r\n\tstatic long gcd(long a, long b){\r\n\t\tif(a < b){\r\n\t\t\tlong temp = b;\r\n\t\t\tb = a;\r\n\t\t\ta = temp;\r\n\t\t}\r\n\t\t// a > b\r\n\t\twhile (b > 0) {\r\n\t\t\tlong r = a % b;\r\n\t\t\ta = b;\r\n\t\t\tb = r;\r\n\t\t}\r\n\t\treturn a;\r\n\t}\r\n\t\r\n\tstatic int gcd(int a, int b){\r\n\t\tif(a < b){\r\n\t\t\tint temp = b;\r\n\t\t\tb = a;\r\n\t\t\ta = temp;\r\n\t\t}\r\n\t\t// a > b\r\n\t\twhile (b > 0) {\r\n\t\t\tint r = a % b;\r\n\t\t\ta = b;\r\n\t\t\tb = r;\r\n\t\t}\r\n\t\treturn a;\r\n\t}\r\n\t \r\n//\tOptional solve()\r\n//\treturn Optional.empty();\r\n\t\r\n\tstatic class Pair implements Comparable{\r\n\t\tfinal static long FIXED_RANDOM = System.currentTimeMillis();\r\n\t\tint first, second;\r\n\t\tpublic Pair(int first, int second) {\r\n\t\t\tthis.first = first;\r\n\t\t\tthis.second = second;\r\n\t\t}\r\n\t\t\r\n\r\n\t\t@Override\r\n\t\tpublic int hashCode() {\r\n\t\t\t// http://xorshift.di.unimi.it/splitmix64.c\r\n\t\t\tlong x = first;\r\n\t\t\tx <<= 32;\r\n\t\t\tx += second;\r\n\t\t\tx += FIXED_RANDOM;\r\n\t\t\tx += 0x9e3779b97f4a7c15l;\r\n\t\t\tx = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9l;\r\n\t\t\tx = (x ^ (x >> 27)) * 0x94d049bb133111ebl;\r\n\t\t\treturn (int)(x ^ (x >> 31));\r\n\t\t}\r\n\t\t@Override\r\n\t\tpublic boolean equals(Object obj) {\r\n//\t\t\tif (this == obj)\r\n//\t\t\t\treturn true;\r\n//\t\t\tif (obj == null)\r\n//\t\t\t\treturn false;\r\n//\t\t\tif (getClass() != obj.getClass())\r\n//\t\t\t\treturn false;\r\n\t\t\tPair other = (Pair) obj;\r\n\t\t\treturn first == other.first && second == other.second;\r\n\t\t}\r\n\t\t@Override\r\n\t\tpublic String toString() {\r\n\t\t\treturn \"[\" + first + \",\" + second + \"]\";\r\n\t\t}\r\n\r\n\r\n\t\t@Override\r\n\t\tpublic int compareTo(Pair o) {\r\n\t\t\tint cmp = Integer.compare(first, o.first);\r\n\t\t\treturn cmp != 0? cmp: Integer.compare(second, o.second);\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic static class MyScanner {\r\n\t\tBufferedReader br;\r\n\t\tStringTokenizer st;\r\n\r\n\t\t// 32768?\r\n\t\tpublic MyScanner(InputStream is, int bufferSize) {\r\n\t\t\tbr = new BufferedReader(new InputStreamReader(is), bufferSize);\r\n\t\t}\r\n\t\t\r\n\t\tpublic MyScanner(InputStream is) {\r\n\t\t\tbr = new BufferedReader(new InputStreamReader(is));\r\n\t\t\t// br = new BufferedReader(new InputStreamReader(System.in));\r\n\t\t\t// br = new BufferedReader(new InputStreamReader(new FileInputStream(\"input.txt\")));\r\n\t\t}\r\n\r\n\t\tpublic void close() {\r\n\t\t\ttry {\r\n\t\t\t\tbr.close();\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\te.printStackTrace();\r\n\t\t\t}\r\n\r\n\t\t}\r\n\r\n\t\tString next() {\r\n\t\t\twhile (st == null || !st.hasMoreElements()) {\r\n\t\t\t\ttry {\r\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\r\n\t\t\t\t} catch (IOException e) {\r\n\t\t\t\t\te.printStackTrace();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn st.nextToken();\r\n\t\t}\r\n\r\n\t\tint nextInt() {\r\n\t\t\treturn Integer.parseInt(next());\r\n\t\t}\r\n\r\n\t\tlong nextLong() {\r\n\t\t\treturn Long.parseLong(next());\r\n\t\t}\r\n\r\n\t\tdouble nextDouble() {\r\n\t\t\treturn Double.parseDouble(next());\r\n\t\t}\r\n\r\n\t\tString nextLine(){\r\n\t\t\tString str = \"\";\r\n\t\t\ttry {\r\n\t\t\t\tstr = br.readLine();\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\te.printStackTrace();\r\n\t\t\t}\r\n\t\t\treturn str;\r\n\t\t}\r\n\t\t\r\n\t\tint[][] nextMatrix(int n, int m) {\r\n\t\t\treturn nextMatrix(n, m, 0);\r\n\t\t}\r\n\t\t\r\n\t\tint[][] nextMatrix(int n, int m, int offset) {\r\n\t\t\tint[][] mat = new int[n][m];\r\n\t\t\tfor(int i=0; i void printlnAns(Optional ans) {\r\n//\t\t\tif(ans.isEmpty())\r\n//\t\t\t\tprintln(-1);\r\n//\t\t\telse\r\n//\t\t\t\tprintlnAns(ans.get());\r\n//\t\t}\r\n\t\t\r\n\t\tpublic void printlnAns(OptionalInt ans) {\r\n\t\t\tprintln(ans.orElse(-1));\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printlnAns(long ans) {\r\n\t\t\tprintln(ans);\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printlnAns(int ans) {\r\n\t\t\tprintln(ans);\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printlnAns(boolean ans) {\r\n\t\t\tif(ans)\r\n\t\t\t\tprintln(YES);\r\n\t\t\telse\r\n\t\t\t\tprintln(NO);\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printAns(long[] arr){\r\n\t\t\tif(arr != null && arr.length > 0){\r\n\t\t\t\tprint(arr[0]);\r\n\t\t\t\tfor(int i=1; i 0){\r\n\t\t\t\tprint(arr[0]);\r\n\t\t\t\tfor(int i=1; i void printAns(ArrayList arr){\r\n\t\t\tif(arr != null && arr.size() > 0){\r\n\t\t\t\tprint(arr.get(0));\r\n\t\t\t\tfor(int i=1; i void printlnAns(ArrayList arr){\r\n\t\t\tprintAns(arr);\r\n\t\t\tprintln();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printAns(int[] arr, int add){\r\n\t\t\tif(arr != null && arr.length > 0){\r\n\t\t\t\tprint(arr[0]+add);\r\n\t\t\t\tfor(int i=1; i arr, int add) {\r\n\t\t\tif(arr != null && arr.size() > 0){\r\n\t\t\t\tprint(arr.get(0)+add);\r\n\t\t\t\tfor(int i=1; i arr, int add){\r\n\t\t\tprintAns(arr, add);\r\n\t\t\tprintln();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printlnAnsSplit(long[] arr, int split){\r\n\t\t\tif(arr != null){\r\n\t\t\t\tfor(int i=0; i void printlnAnsSplit(ArrayList arr, int split){\r\n\t\t\tif(arr != null && !arr.isEmpty()){\r\n\t\t\t\tfor(int i=0; i\" + e[i][1] + \";\");\r\n\t\t}\r\n\t\tout2.println(\"}\");\r\n\t\tout2.close();\r\n\t}\r\n\t\r\n}\r\n", "lang_cluster": "Java", "tags": ["math", "number theory"], "code_uid": "f6fd3be8d47a284e826f131999a93862", "src_uid": "c3694a6ff95c64bef8cbe8834c3fd6cb", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/*\n * Nachiket V Trivedi\n * DAIICT\n */\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class demo1 \n{\n\n\tpublic static void main(String[] args) \n\t{\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream); \n\t\t//------Start-----\n\t\tlong n=in.nextLong();\n\t\tint k=in.nextInt();\t\t\n\t\tTreeSet al=new TreeSet();\n\t\tfor(long i=1;i*i<=n;i++)\n\t\t{\t\n\t\t\tif(n%i==0)\n\t\t\t{\n\t\t\t\tal.add(i);\n\t\t\t\tal.add(n/i);\n\t\t\t}\n\t\t}\n\t\t\n\t\tif(al.size() ts=new TreeSet();\t\t\n\t\twhile(n%2==0)\n\t\t{\t\t\n\t\t\tts.add((long)2);\n\t\t\tn=n/2;\n\t\t}\n\t\tfor(long i=3;i<=Math.sqrt(n);i+=2)\n\t\t{\n\t\t\twhile(n%i==0)\n\t\t\t{\n\t\t\t\tts.add(i);\n\t\t\t\tn=n/i;\n\t\t\t}\n\t\t}\n\t\tif(n>2)\n\t\t\tts.add(n);\n\t\treturn ts;\n\t}\n\tstatic boolean isPrime(long num)//#3\n\t{\n\t\tif (num < 2) return false;\n\t\tif (num == 2) return true;\n\t\tif (num % 2 == 0) return false;\n\t\tfor (int i = 3; i * i <= num; i += 2)\n\t\t\tif (num % i == 0) return false;\n\t\treturn true;\n\t}\n\tstatic long modular_exponentiation(long a, long b, long c)// calculates (a^b)%c\n\t{\n\t\t//while calling this function pass a as a%m and IF c in prime then pass b as b%(m-1)..coz of fermet's theorem \n\t\t//if c is not prime then pass only b.\n\t\ta=a%c;\n\t\tif(b == 0)\n\t\t\treturn 1;\n\t\tif(b == 1)\n\t\t\treturn a%c;\n\t\telse if( b%2 == 0) //if b is even\n\t\t{\n\t\t\treturn modular_exponentiation((a *a)%c,b/2,c);\n\t\t}\n\t\telse // if b is odd.\n\t\t{\n\t\t\treturn (a*modular_exponentiation((a*a%c),b/2,c))%c;\n\t\t}\n\t}\t\n\tstatic int findGCD(int number1, int number2) //complexity O(log(max(n1,n2)))\n\t{\n\t\tif(number2 == 0)\n\t\t\treturn number1; \t\t\t\n\t\treturn findGCD(number2, number1%number2); \n\t}\n\tstatic void extendedEuclid(int A, int B) {\n\t\t//gcd(A,B)=Ax+By....this calculates the coefficients...\n\t\t//make those variables global and open these comments\n\t\tif(B == 0)\n\t\t{\n\t\t\t//\t gcd = A;\n\t\t\t//\t x = 1;\n\t\t\t//\t y = 0;\t \n\t\t}\n\t\telse \n\t\t{\t \t\n\t\t\textendedEuclid(B, A%B);\n\t\t\t//\t\t\tint temp = x;\n\t\t\t//\t\t\tx = y;\n\t\t\t//\t\t\ty = temp - (A/B)*y;\t \n\t\t}\n\t}\n\t\n\tstatic void modInverse(int A, int M)\n\t{\n\t\t//A and M must be coprime for modinverse to exist.\n\t\t//If M is prime the call modexponentiation(A,M-2,M)\n\t extendedEuclid(A,M);\n\t //return (x%M+M)%M; //this is x of Ax+By=GCD from euclid...x may be negative\n\t}\n\tstatic void debug(Object... o)// to print any object like an array \n\t{\n\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n\tstatic public ArrayList> FindAllsubsets(int[] S)//2^n complexity \n\t{\n\t\tif (S == null)\n\t\t\treturn null;\n\t\tArrays.sort(S);\t \n\t\tArrayList> result = new ArrayList>();\t \n\t\tfor (int i = 0; i < S.length; i++) {\n\t\t\tArrayList> temp = new ArrayList>();\n\t\t\t//get sets that are already in result\n\t\t\tfor (ArrayList a : result) {\n\t\t\t\ttemp.add(new ArrayList(a));\n\t\t\t}\t \n\t\t\t//add S[i] to existing sets\n\t\t\tfor (ArrayList a : temp) {\n\t\t\t\ta.add(S[i]);\n\t\t\t}\t \n\t\t\t//add S[i] only as a set\n\t\t\tArrayList single = new ArrayList();\n\t\t\tsingle.add(S[i]);\n\t\t\ttemp.add(single);\t \n\t\t\tresult.addAll(temp);\n\t\t}\t \n\t\t//add empty set\n\t\tresult.add(new ArrayList());\t \n\t\treturn result;\n\t}\n\tstatic int greatestIndexNotExceeding(int[] data, int limit, int lb, int ub) \n\t{\n\t\tfinal int mid = (lb + ub) / 2;\n\t\t// Need to go lower but can't\n\t\tif (mid == lb && data[mid] > limit) \n\t\t\treturn -1;\t\t\n\t\t// Found a candidate, and can't go higher\n\t\tif (data[mid] <= limit && (mid == ub || data[mid + 1] > limit)) \n\t\t\treturn mid;\t\t\n\t\tif (data[mid] <= limit) \n\t\t\t// Consider upper half\n\t\t\treturn greatestIndexNotExceeding(data, limit, mid + 1, ub);\n\t\telse\n\t\t\t// Consider lower half\n\t\t\treturn greatestIndexNotExceeding(data, limit, lb, mid);\n\t}\n\n\t//Pair class is here\n\tstatic class Pair implements Comparable\n\t{\n\t\tlong u;\n\t\tlong v;\n\t\tBigInteger bi;\n\t\tpublic Pair(long u, long v) {\n\t\t\tthis.u = u;\n\t\t\tthis.v = v;\n\t\t}\n\n\n\t\tpublic int hashCode() {\n\t\t\tint hu = (int) (u ^ (u >>> 32));\n\t\t\tint hv = (int) (v ^ (v >>> 32));\n\t\t\treturn 31 * hu + hv;\n\t\t}\n\n\t\tpublic boolean equals(Object o) {\n\t\t\tPair other = (Pair) o;\n\t\t\treturn u == other.u && v == other.v;\n\t\t}\n\n\t\tpublic int compareTo(Pair other) {\n\t\t\treturn Long.compare(u, other.u) != 0 ? Long.compare(u, other.u) : Long.compare(v, other.v);\n\t\t}\n\n\t\tpublic String toString() {\n\t\t\treturn \"[u=\" + u + \", v=\" + v + \"]\";\n\t\t}\n\t}\n\t//End of My Templates-----------------InputReader class starts from here--------------------------------------------------------------\n\tpublic static class InputReader \n\t{\n\t\tpublic BufferedReader reader;\n\t\tpublic StringTokenizer tokenizer;\n\n\t\tpublic InputReader(InputStream inputstream) \n\t\t{\n\t\t\treader = new BufferedReader(new InputStreamReader(inputstream));\n\t\t\ttokenizer = null;\n\t\t}\n\n\t\tpublic String nextLine()\n\t\t{\n\t\t\tString fullLine=null;\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) \n\t\t\t{\n\t\t\t\ttry\n\t\t\t\t{\n\t\t\t\t\tfullLine=reader.readLine();\n\t\t\t\t} \n\t\t\t\tcatch (IOException e) \n\t\t\t\t{\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t\treturn fullLine;\n\t\t\t}\n\t\t\treturn fullLine;\n\t\t}\n\t\tpublic String next() \n\t\t{\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) \n\t\t\t{\n\t\t\t\ttry \n\t\t\t\t{\n\t\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t}\n\t\t\t\tcatch (IOException e) \n\t\t\t\t{\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\t\tpublic long nextLong() \n\t\t{\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\tpublic int nextInt() \n\t\t{\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t}\n\n}\n\n//---------------------------------------------------------------", "lang_cluster": "Java", "tags": ["math", "number theory"], "code_uid": "7de28d90490b29971aad514cd05192a3", "src_uid": "6ba39b428a2d47b7d199879185797ffb", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class CF560BGetaldIntoArts {\n public static void main(String[] args) {\n\n Scanner s = new Scanner(System.in);\n boolean b = true;\n\n int a1 = s.nextInt();\n int b1 = s.nextInt();\n int a2 = s.nextInt();\n int b2 = s.nextInt();\n int a3 = s.nextInt();\n int b3 = s.nextInt();\n\n\n if(a1 >= Math.max(a2,a3) && b2+b3<=b1) b = true;\n\n\n\n else if(a1 >= Math.max(a2,b3) && b2+a3<=b1) b = true;\n\n else if(a1 >= Math.max(a3,b2) && b3+a2<=b1) b = true;\n\n else if(a1 >= Math.max(b2,b3) && a2+a3<=b1) b = true;\n else b = false;\n\n\n if(b1 >= Math.max(a2,a3) && b2+b3<=a1) b = true;\n\n else if(b1 >= Math.max(a2,b3) && b2+a3<=a1) b = true;\n\n else if(b1>=Math.max(a3,b2) && b3+a2<=a1) b = true;\n\n else if(b1>=Math.max(b2,b3) && a2+a3<=a1) b = true;\n\n\n if(b == false){\n System.out.println(\"NO\");\n }\n else System.out.println(\"YES\");\n\n\n\n\n }\n}", "lang_cluster": "Java", "tags": ["constructive algorithms", "implementation"], "code_uid": "eea06fb8d0e6f20c7774140f00cc34b6", "src_uid": "2ff30d9c4288390fd7b5b37715638ad9", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "//package com.company;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n public static class Task {\n public class Number {\n int factNum;\n int[] primeFactorCounts;\n int largestFactor;\n int S = 0;\n public Number(int f, int[] primeFactorCounts) {\n this.factNum = f;\n this.primeFactorCounts = primeFactorCounts;\n for (largestFactor = primeFactorCounts.length - 1; largestFactor >= 0; largestFactor--) {\n if (primeFactorCounts[largestFactor] != 0) break;\n }\n for (int y: primeFactorCounts)S += y;\n }\n int getL() {\n if (largestFactor == -1) return -1;\n int r = largestFactor;\n primeFactorCounts[r]--;\n if (primeFactorCounts[r] == 0) largestFactor--;\n return r;\n }\n }\n\n List primes;\n int[] factor;\n\n public void precompute() {\n int n = 5001;\n primes = new ArrayList<>();\n factor = new int[n];\n Arrays.fill(factor, -1);\n for (int i = 2; i < n; ++i) {\n if (factor[i] == -1) {\n factor[i] = primes.size();\n primes.add(i);\n }\n for (int j = 0; j < primes.size () && i * primes.get(j) < n; ++j) {\n int p = primes.get(j);\n factor[i * p] = j;\n if (i % p == 0) {\n break;\n }\n }\n }\n }\n\n List fact(int x) {\n List retL = new ArrayList<>();\n while (x != 1) {\n retL.add(factor[x]);\n x /= primes.get(factor[x]);\n }\n return retL;\n }\n\n public void solve(Scanner sc, PrintWriter pw) throws IOException {\n precompute();\n int[] primeF = new int[700];\n Number[] numbers = new Number[5001];\n// numbers[0] = new Number(1, Arrays.copyOf(primeF, 700));\n numbers[1] = new Number(1, Arrays.copyOf(primeF, 700));\n for (int i = 2; i <= 5000; i++) {\n List f = fact(i);\n for (int y: f) primeF[y]++;\n numbers[i] = new Number(i, Arrays.copyOf(primeF, 700));\n }\n// pw.println(Arrays.toString(numbers[5000].primeFactorCounts));\n// System.err.println(numbers[5000].S);\n Map numToCount = new HashMap<>();\n int n = sc.nextInt();\n for (int i = 0; i < n; i++) {\n int a = sc.nextInt();\n a = Math.max(a, 1);\n numToCount.put(a, numToCount.getOrDefault(a, 0) + 1);\n }\n long total = 0;\n for (Map.Entry en : numToCount.entrySet()) {\n total += (long) en.getValue() * numbers[en.getKey()].S;\n }\n outer:\n while (true) {\n Map kG = new HashMap<>();\n for (Map.Entry en : numToCount.entrySet()) {\n int k = en.getKey();\n int v = en.getValue();\n int lf = numbers[k].largestFactor;\n if (lf == -1) continue ;\n kG.put(lf, kG.getOrDefault(lf, 0) + v);\n }\n for (Map.Entry en: kG.entrySet()) {\n if (n - en.getValue() < en.getValue()) {\n total -= en.getValue() - (n - en.getValue());\n Map nC = new HashMap<>();\n for (Map.Entry en1 : numToCount.entrySet()) {\n int lf = numbers[en1.getKey()].getL();\n if (lf == en.getKey()) {\n nC.put(en1.getKey(), en1.getValue());\n }\n }\n numToCount = nC;\n continue outer;\n }\n }\n pw.println(total);\n return;\n }\n }\n }\n\n static long TIME_START, TIME_END;\n\n public static void main(String[] args) throws IOException {\n Scanner sc = new Scanner(System.in);\n// Scanner sc = new Scanner(new FileInputStream(\"input\"));\n PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));\n// PrintWriter pw = new PrintWriter(new FileOutputStream(\"output\"));\n\n\n Runtime runtime = Runtime.getRuntime();\n long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();\n TIME_START = System.currentTimeMillis();\n Task t = new Task();\n t.solve(sc, pw);\n TIME_END = System.currentTimeMillis();\n long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();\n pw.close();\n System.err.println(\"Memory increased: \" + (usedMemoryAfter - usedMemoryBefore) / 1000000);\n System.err.println(\"Time used: \" + (TIME_END - TIME_START) + \".\");\n }\n\n static class Scanner {\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(InputStream s) {\n br = new BufferedReader(new InputStreamReader(s));\n }\n\n public Scanner(FileReader s) throws FileNotFoundException {\n br = new BufferedReader(s);\n }\n\n public String next() throws IOException {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public String nextLine() throws IOException {\n return br.readLine();\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n public boolean ready() throws IOException {\n return br.ready();\n }\n }\n}", "lang_cluster": "Java", "tags": ["math", "trees", "dp", "graphs", "number theory"], "code_uid": "cfafddf622e22f5473af6a1104e0dca2", "src_uid": "40002052843ca0357dbd3158b16d59f4", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\npublic class A741 {\n\tstatic int min;\n\tstatic boolean[] visited;\n\tstatic int[] adj;\n\tstatic long[] cyc;\n\tpublic static void main(String[] args) throws IOException{\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\t\n\t\tadj = new int[n];\n\t\tvisited = new boolean[n];\n\t\tcyc = new long[n];\n\t\tTreeSet set = new TreeSet<>();\n\t\tfor(int i = 0;i 0)\n\t {\n\t long temp = b;\n\t b = a % b; // % is remainder\n\t a = temp;\n\t }\n\t return a;\n\t}\n\n\tstatic long gcd(long[] input)\n\t{\n\t long result = input[0];\n\t for(int i = 1; i < input.length; i++) result = gcd(result, input[i]);\n\t return result;\n\t}\n\tstatic long lcm(long a, long b)\n\t{\n\t return a * (b / gcd(a, b));\n\t}\n\n\tstatic long lcm(long[] input)\n\t{\n\t long result = input[0];\n\t for(int i = 1; i < input.length; i++) result = lcm(result, input[i]);\n\t return result;\n\t}\n\tstatic class Scanner \n\t{\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s) {\tbr = new BufferedReader(new InputStreamReader(s));}\n\n\t\tpublic String next() throws IOException \n\t\t{\n\t\t\twhile (st == null || !st.hasMoreTokens()) \n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {return Integer.parseInt(next());}\n\n\t\tpublic long nextLong() throws IOException {return Long.parseLong(next());}\n\n\t\tpublic String nextLine() throws IOException {return br.readLine();}\n\n\t\tpublic double nextDouble() throws IOException\n\t\t{\n\t\t\tString x = next();\n\t\t\tStringBuilder sb = new StringBuilder(\"0\");\n\t\t\tdouble res = 0, f = 1;\n\t\t\tboolean dec = false, neg = false;\n\t\t\tint start = 0;\n\t\t\tif(x.charAt(0) == '-')\n\t\t\t{\n\t\t\t\tneg = true;\n\t\t\t\tstart++;\n\t\t\t}\n\t\t\tfor(int i = start; i < x.length(); i++)\n\t\t\t\tif(x.charAt(i) == '.')\n\t\t\t\t{\n\t\t\t\t\tres = Long.parseLong(sb.toString());\n\t\t\t\t\tsb = new StringBuilder(\"0\");\n\t\t\t\t\tdec = true;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tsb.append(x.charAt(i));\n\t\t\t\t\tif(dec)\n\t\t\t\t\t\tf *= 10;\n\t\t\t\t}\n\t\t\tres += Long.parseLong(sb.toString()) / f;\n\t\t\treturn res * (neg?-1:1);\n\t\t}\n\n\t\tpublic boolean ready() throws IOException {return br.ready();}\n\n\n\t}\n}\n", "lang_cluster": "Java", "tags": ["dfs and similar", "math"], "code_uid": "66f8341c21f1a28488e672f830e64371", "src_uid": "149221131a978298ac56b58438df46c9", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class R400qE {\n\n static int mod = 1000000007;\n\n public static void main(String[] args) {\n InputReader in = new InputReader(System.in);\n PrintWriter w = new PrintWriter(System.out);\n\n long n = in.nextLong();\n long k = (in.nextLong() + 1) / 2;\n\n while (n > 1 && k > 0) {\n n = phi(n);\n k--;\n }\n\n w.println(n % mod);\n w.close();\n }\n\n static long phi(long n) {\n long result = n;\n for (long p = 2; p * p <= n; ++p) {\n if (n % p == 0) {\n while (n % p == 0)\n n /= p;\n result /= p;\n result *= p - 1;\n }\n }\n\n if (n > 1) {\n result /= n;\n result *= n - 1;\n }\n\n return result;\n }\n\n static int f(int n) {\n if (n == 1) {\n return 1;\n }\n int ans = 0;\n for (int i = 1; i < n; i++) {\n if (gcd(i, n - i) == 1) {\n ans++;\n }\n }\n return ans;\n }\n\n static int g(int n) {\n int ans = 0;\n for (int i = 1; i <= n; i++) {\n if (n % i == 0) {\n ans += f(n / i);\n }\n }\n return ans;\n }\n\n public static int gcd(int a, int b) {\n while (b != 0) {\n int t = b;\n b = a % b;\n a = t;\n }\n return a;\n }\n\n static class InputReader {\n\n private final InputStream stream;\n private final byte[] buf = new byte[8192];\n private int curChar, snumChars;\n\n public InputReader(InputStream st) {\n this.stream = st;\n }\n\n public int read() {\n if (snumChars == -1)\n throw new InputMismatchException();\n if (curChar >= snumChars) {\n curChar = 0;\n try {\n snumChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (snumChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public long nextLong() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public int[] nextIntArray(int n) {\n int a[] = new int[n];\n for (int i = 0; i < n; i++) {\n a[i] = nextInt();\n }\n return a;\n }\n\n public String readString() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public String nextLine() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isEndOfLine(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n private boolean isEndOfLine(int c) {\n return c == '\\n' || c == '\\r' || c == -1;\n }\n\n }\n\n}\n", "lang_cluster": "Java", "tags": ["math", "number theory"], "code_uid": "ea3559260303b41eebe7c5566f581196", "src_uid": "0591ade5f9a69afcbecd80402493f975", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.List;\nimport java.util.Queue;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\npublic class A487 {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tSolver solver = new Solver();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n\t\n\t\nstatic class Solver {\n\t\n\tint hm, am, dm, hy;\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n \thy = in.nextInt();\n \tint ay = in.nextInt();\n \tint dy = in.nextInt();\n \thm = in.nextInt();\n \tam = in.nextInt();\n \tdm = in.nextInt();\n \tint hc = in.nextInt();\n \tint ac = in.nextInt();\n \tint dc = in.nextInt();\n \tlong ans = Long.MAX_VALUE;\n\t\tfor (int a = 0; a < 200; a++) {\n\t\t\tfor (int d = 0; d < 200; d++) {\n\t\t\t\tint h = hpToWin(a+ay, d+dy);\n\t\t\t\tif (h == -1) continue;\n\t\t\t\tlong cost = h*hc + a*ac + d*dc;\n\t\t\t\tans = Math.min(ans, cost);\n\t\t\t}\n\t\t}\n \tSystem.out.println(ans);\n }\n \n public int hpToWin(int ay, int dy) {\n \tif (ay-dm <= 0) return -1; //impossible\n \tif (am-dy <= 0) return 0;\n \t\n \tdouble turns = (double)hm / (double)(ay-dm);\n \tint turnY = (int) Math.ceil(turns);\n \t\n \t// so you need turnY+1 and take am-dy per turn\n \treturn Math.max(0, turnY * (am-dy) + 1 - hy);\n }\n \n\tvoid debug(Object...os) {\n\t\tSystem.err.println(Arrays.deepToString(os));\n\t}\n \n}\n\nstatic class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n public long nextLong() {\n return Long.parseLong(next());\n }\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n}\n}\n", "lang_cluster": "Java", "tags": ["brute force", "implementation", "binary search"], "code_uid": "eaf07818c70b337e58f8dd95a51f45ad", "src_uid": "bf8a133154745e64a547de6f31ddc884", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author pigsoft\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n Scanner in = new Scanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskA solver = new TaskA();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskA {\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n String a = in.nextLine();\n int n = in.nextInt();\n String cw = \"^>v<\";\n String ccw = \"^\";\n boolean iscw = false;\n boolean isccw = false;\n\n int id = 0;\n for (int i = 0; i < 4; i++) {\n if (a.charAt(0) == cw.charAt(i))\n id = i;\n }\n id = (id + n) % 4;\n\n if (cw.charAt(id) == a.charAt(2)) {\n iscw = true;\n }\n\n id = 0;\n for (int i = 0; i < 4; i++) {\n if (a.charAt(0) == ccw.charAt(i))\n id = i;\n }\n id = (id + n) % 4;\n if (ccw.charAt(id) == a.charAt(2)) {\n isccw = true;\n }\n\n if (iscw == isccw)\n out.print(\"undefined\");\n else if (iscw)\n out.print(\"cw\");\n else\n out.print(\"ccw\");\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "97905205e168b875cbd7eb9b46901b10", "src_uid": "fb99ef80fd21f98674fe85d80a2e5298", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.lang.reflect.Array;\nimport java.util.*;\nimport java.math.*;\nimport java.lang.*;\nimport java.util.stream.Collectors;\n\nimport static java.lang.Math.*;\n\npublic class Main implements Runnable\n{\n static class InputReader\n {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private SpaceCharFilter filter;\n private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n public InputReader(InputStream stream)\n {\n this.stream = stream;\n }\n\n public int read()\n {\n if (numChars==-1)\n throw new InputMismatchException();\n\n if (curChar >= numChars)\n {\n curChar = 0;\n try\n {\n numChars = stream.read(buf);\n }\n catch (IOException e)\n {\n throw new InputMismatchException();\n }\n\n if(numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public String nextLine()\n {\n String str = \"\";\n try\n {\n str = br.readLine();\n }\n catch (IOException e)\n {\n e.printStackTrace();\n }\n return str;\n }\n public int nextInt()\n {\n int c = read();\n\n while(isSpaceChar(c))\n c = read();\n\n int sgn = 1;\n\n if (c == '-')\n {\n sgn = -1;\n c = read();\n }\n\n int res = 0;\n do\n {\n if(c<'0'||c>'9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n }\n while (!isSpaceChar(c));\n\n return res * sgn;\n }\n\n public long nextLong()\n {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-')\n {\n sgn = -1;\n c = read();\n }\n long res = 0;\n\n do\n {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n }\n while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public double nextDouble()\n {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-')\n {\n sgn = -1;\n c = read();\n }\n double res = 0;\n while (!isSpaceChar(c) && c != '.')\n {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, nextInt());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n }\n if (c == '.')\n {\n c = read();\n double m = 1;\n while (!isSpaceChar(c))\n {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, nextInt());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n m /= 10;\n res += (c - '0') * m;\n c = read();\n }\n }\n return res * sgn;\n }\n\n public String readString()\n {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do\n {\n res.appendCodePoint(c);\n c = read();\n }\n while (!isSpaceChar(c));\n\n return res.toString();\n }\n\n public boolean isSpaceChar(int c)\n {\n if (filter != null)\n return filter.isSpaceChar(c);\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public String next()\n {\n return readString();\n }\n\n public interface SpaceCharFilter\n {\n public boolean isSpaceChar(int ch);\n }\n }\n public static void main(String args[]) throws Exception\n {\n new Thread(null, new Main(),\"Main\",1<<27).start();\n }\n\n public static long gcd(long a, long b)\n {\n if (a == 0)\n return b;\n return gcd(b % a, a);\n }\n\n public static long findGCD(long arr[], int n)\n {\n long result = arr[0];\n for (int i = 1; i < n; i++)\n result = gcd(arr[i], result);\n return result;\n }\n\n static void sortbycolomn(long arr[][], int col)\n {\n\n Arrays.sort(arr, new Comparator() {\n\n @Override\n\n public int compare(final long[] entry1,\n final long[] entry2) {\n\n\n if (entry1[col] > entry2[col])\n return 1;\n else\n return -1;\n }\n });\n }\n\n static String sortString(String str) {\n int MAX_CHAR = 256;\n int letters[] = new int[MAX_CHAR];\n for (char x : str.toCharArray()) {\n\n // 'a'-'a' will be 0, 'b'-'a' will be 1,\n // so for location of character in count\n // array we will do str[i]-'a'.\n letters[x - 'a']++;\n }\n\n // Traverse the hash array and print\n // characters\n StringBuffer sb = new StringBuffer();\n for (int i = 0; i < MAX_CHAR; i++) {\n for (int j = 0; j < letters[i]; j++) {\n sb.append((char) (i + 'a'));\n }\n }\n return sb.toString();\n }\n public int lb(int[] a, int val){\n int min = 0, len = a.length, max = len;\n while(min=val){\n max = mid;\n }\n else{\n min = mid+1;\n }\n }\n return max;\n }\n public int ub(int[] a, int val){\n int min = 0, len = a.length, max = len;\n while(minval){\n max = mid;\n }\n else {\n min = mid + 1;\n }\n }\n return max;\n }\n public int lb(List a, int val){\n int min = 0, len = a.size(), max = len;\n while(min=val){\n max = mid;\n }\n else{\n min = mid+1;\n }\n }\n return max;\n }\n public int ub(List a, int val){\n int min = 0, len = a.size(), max = len;\n while(minval){\n max = mid;\n }\n else {\n min = mid + 1;\n }\n }\n return max;\n }\n public void run()\n {\n InputReader in = new InputReader(System.in);\n PrintWriter w = new PrintWriter(System.out);\n long n = in.nextLong();\n long prev = n;\n long i = 2;\n while(i*i<=n){\n if(n%i==0){\n n-=i;\n// w.println(n);\n break;\n }\n i++;\n }\n if(n==prev) w.println(1);\n else w.println(1+n/2);\n w.flush();\n w.close();\n }\n}", "lang_cluster": "Java", "tags": ["math", "implementation", "number theory"], "code_uid": "d5eb147eabcff7354ae3778e97c4f91b", "src_uid": "a1e80ddd97026835a84f91bac8eb21e6", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class transformation { \n public static void main(String[] args){\n Scanner scan = new Scanner(System.in);\n int num1 = scan.nextInt();\n int num2 = scan.nextInt(),k=num2;\n ArrayList arr = new ArrayList<>();\n while(num2>num1){\n if(num2%2==0){\n num2=num2/2;\n arr.add(num2);\n }\n else if(num2%10==1){\n num2=num2/10;\n arr.add(num2);\n }\n else\n break;\n }\n if(num1==num2){\n System.out.println(\"YES\");\n System.out.println(arr.size()+1);\n for(int i=arr.size()-1;i>=0;i--){\n System.out.print(arr.get(i)+\" \");\n }\n System.out.print(k);\n }\n else\n System.out.println(\"NO\");\n }\n}\n", "lang_cluster": "Java", "tags": ["dfs and similar", "math", "brute force"], "code_uid": "1d72d908c655031dc103c2f884bede38", "src_uid": "fc3adb1a9a7f1122b567b4d8afd7b3f3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.*;\n\n\npublic class Main {\n public static void main(String[] args) {\n Scanner kb = new Scanner(System.in);\n int a1 = kb.nextInt();\n int b1 = kb.nextInt();\n int c1 = kb.nextInt();\n int a2 = kb.nextInt();\n int b2 = kb.nextInt();\n int c2 = kb.nextInt();\n int D = a1*b2-a2*b1;\n if((a1==0&&b1==0&&c1!=0)||(a2==0&&b2==0&&c2!=0))System.out.println(0);\n else if((a1==0&&b1==0&&c1==0)||(a2==0&&b2==0&&c2==0))System.out.println(-1);\n else if(D!=0)System.out.println(1);\n else if(a1*c2==a2*c1&&b1*c2==b2*c1)System.out.println(-1);\n else System.out.println(0);\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "cc9b1731852262df6da4927f1038d29f", "src_uid": "c8e869cb17550e888733551c749f2e1a", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n String player = \"Mahmoud\";\n boolean flag = true;\n\n while (flag) {\n if (player.contains(\"Mahmoud\")) {\n if (n % 2 == 0) {\n flag = false;\n } else if(n==1){\n player = \"Ehab\";\n flag = false;\n } else {\n int random = (int) (Math.random() * (n - 2 + 1) + 2) / 2 * 2;\n n-=random;\n }\n } else if (player.contains(\"Ehab\")) {\n if (n % 2 == 1) {\n flag = false;\n } else {\n int random = (int) (Math.random() * ((n-1) - 1 + 1) + 1) / 2 * 2;\n random++;\n n-=random;\n }\n }\n }\n System.out.println(player);\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "games"], "code_uid": "f6af34337009608e0b1d65cd7450aeca", "src_uid": "5e74750f44142624e6da41d4b35beb9a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\npublic class a279\n{\n public static void main(String args[])throws IOException\n {\n BufferedReader in=new BufferedReader(new InputStreamReader(System.in));\n String s;\n //System.out.println(\"Enter\");\n s=in.readLine();\n StringTokenizer st=new StringTokenizer(s);\n int x,y,sum;\n x=Integer.parseInt(st.nextToken());\n y=Integer.parseInt(st.nextToken());\n if(x==0 && y==0)\n {\n System.out.println(\"0\");\n System.exit(0);\n }\n if(x==y)\n {\n if(x>0 && y>0)\n System.out.println(Math.min(1+(x-1)*4,2+(y-1)*4));\n else if(x<0 && y<0)\n System.out.println(Math.min(3+(-x-1)*4,4+(-y-1)*4));\n System.exit(0);\n }\n else if(y==-x && y>0 && x<0)\n {\n System.out.println(Math.min(3+(-x-1)*4,2+(y-1)*4));\n System.exit(0);\n }\n else if(y==-x+1 && x>0 && y<=0)\n {\n System.out.println(Math.min(1+(x-1)*4,4+(-y-1)*4));\n System.exit(0);\n }\n else if (x>=0 && y>=0)\n {\n System.out.println(Math.max(1+(x-1)*4,2+(y-1)*4));\n System.exit(0);\n }\n else if(x<=0 && y>=0)\n {\n System.out.println(Math.max(3+(-x-1)*4,2+(y-1)*4));\n System.exit(0);\n }\n else if(x<=0 && y<=0)\n {\n System.out.println(Math.max(3+(-x-1)*4,4+(-y-1)*4));\n System.exit(0);\n }\n else if(x>=0 && y<=0)\n {\n System.out.println(Math.max(1+(x-1)*4,4+(-y-1)*4));\n System.exit(0);\n }\n }\n}\n\n", "lang_cluster": "Java", "tags": ["brute force", "geometry", "implementation"], "code_uid": "4bebcb5d6b88539827aa5d33057da1ba", "src_uid": "2fb2a129e01efc03cfc3ad91dac88382", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.lang.reflect.Array;\nimport java.util.*;\nimport java.io.*;\n/*\n1000000000000 1000000000002\n\n*/\npublic class Main {\n\n\n public static void main(String[] args) throws IOException{\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n PrintWriter pw=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n StringTokenizer st=new StringTokenizer(br.readLine());\n long n=Long.parseLong(st.nextToken());\n long k=Long.parseLong(st.nextToken());\n if(n+n-1>=k){\n if(k<=n){\n long start = 1;\n long end = k-1;\n long ans = (end - start + 1) / 2;\n if ((end - start + 1) % 2 == 1) {\n ans++;\n }\n if(k%2==0){\n if ((end - start + 1) % 2 == 1) {\n ans--;\n }\n }\n pw.println(ans);\n }else {\n long start = k - n;\n long end = n;\n long ans = (end - start + 1) / 2;\n if ((end - start + 1) % 2 == 1) {\n ans++;\n }\n if(k%2==0){\n if ((end - start + 1) % 2 == 1) {\n ans--;\n }\n }\n pw.println(ans);\n }\n }else {\n pw.println(\"0\");\n }\n\n\n\n\n\n\n pw.close();\n }\n}", "lang_cluster": "Java", "tags": ["math"], "code_uid": "9183df6ef29856f5952ebe4bd2e01809", "src_uid": "98624ab2fcd2a50a75788a29e04999ad", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class Main {\n public static void main(String[] args) throws IOException {\n Scanner sc = new Scanner();\n PrintWriter pw = new PrintWriter(System.out);\n rect rect1 = new rect(sc.nextLong(), sc.nextLong(), sc.nextLong(), sc.nextLong());\n rect rect2 = new rect(sc.nextLong(), sc.nextLong(), sc.nextLong(), sc.nextLong());\n rect rect3 = new rect(sc.nextLong(), sc.nextLong(), sc.nextLong(), sc.nextLong());\n long s1 = s(rect1, rect2);\n long s2 = s(rect1, rect3);\n long s3 = sAll(rect1, rect2, rect3);\n if(s1 + s2 - s3 == s(rect1))\n pw.print(\"NO\");\n else\n pw.print(\"YES\");\n pw.close();\n }\n\n public static long s(rect rect) {\n return (rect.x2 - rect.x1) * (rect.y2 - rect.y1);\n }\n\n public static long s(rect rect1, rect rect2) {\n if (max(rect1.x1, rect2.x1) >= min(rect1.x2, rect2.x2) || max(rect1.y1, rect2.y1) >= min(rect1.y2, rect2.y2))\n return 0;\n return (max(rect1.x1, rect2.x1) - min(rect1.x2, rect2.x2)) * (max(rect1.y1, rect2.y1) - min(rect1.y2, rect2.y2));\n }\n\n public static long sAll(rect rect1, rect rect2, rect rect3) {\n if (max(rect1.x1, max(rect2.x1, rect3.x1)) >= min(rect1.x2, min(rect2.x2, rect3.x2)) || max(rect1.y1, max(rect2.y1, rect3.y1)) >= min(rect1.y2, min(rect2.y2, rect3.y2)))\n return 0;\n return (max(rect1.x1, max(rect2.x1, rect3.x1)) - min(rect1.x2, min(rect2.x2, rect3.x2))) * (max(rect1.y1, max(rect2.y1, rect3.y1)) - min(rect1.y2, min(rect2.y2, rect3.y2)));\n }\n}\n\nclass rect {\n long x1, y1, x2, y2;\n\n public rect(long x1, long y1, long x2, long y2) {\n this.x1 = x1;\n this.y1 = y1;\n this.x2 = x2;\n this.y2 = y2;\n }\n}\n\nclass Scanner {\n BufferedReader br;\n StringTokenizer st = new StringTokenizer(\"\");\n\n public Scanner() throws FileNotFoundException {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n public String next() throws IOException {\n while (!st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n}", "lang_cluster": "Java", "tags": ["math", "geometry"], "code_uid": "999415c3382264524efb5cfdb934edc6", "src_uid": "05c90c1d75d76a522241af6bb6af7781", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class Main {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n char[] c1 = scan.nextLine().trim().toCharArray();\n char[] c2 = scan.nextLine().trim().toCharArray();\n char[] virus = scan.nextLine().trim().toCharArray();\n int n1 = c1.length;\n int n2 = c2.length;\n int m = virus.length;\n int[][][] dp = new int[n1 + 1][n2 + 1][m + 1];\n int[][][] step = new int[n1 + 1][n2 + 1][m + 1];\n\n // preprocessor\n int[] next = new int[m + 1];\n next[0] = -1;\n next[1] = 0;\n int pos = 2;\n int pre = 0;\n while (pos < m) {\n if (virus[pos - 1] == virus[pre]) {\n pre++;\n next[pos] = pre;\n pos++;\n } else if (pre > 0) {\n pre = next[pre];\n } else {\n next[pos] = 0;\n pos++;\n }\n }\n\n for (int i = 1; i <= n1; i++) {\n for (int j = 1; j <= n2; j++) {\n for (int k = 0; k < m; k++) {\n if (c1[i - 1] == c2[j - 1]) {\n int kk = k;\n while (kk >= 0 && c1[i - 1] != virus[kk]) {\n kk = next[kk];\n }\n if (dp[i][j][kk + 1] < 1 + dp[i - 1][j - 1][k]) {\n dp[i][j][kk + 1] = 1 + dp[i - 1][j - 1][k];\n step[i][j][kk + 1] = 100 + k;\n }\n }\n\n if (dp[i][j][k] < dp[i - 1][j][k]) {\n dp[i][j][k] = dp[i - 1][j][k];\n step[i][j][k] = -1;\n }\n if (dp[i][j][k] < dp[i][j - 1][k]) {\n dp[i][j][k] = dp[i][j - 1][k];\n step[i][j][k] = 1;\n }\n }\n }\n }\n\n int result = 0;\n int maxK = 0;\n for (int i = 0; i < m; i++) {\n if (result < dp[n1][n2][i]) {\n result = dp[n1][n2][i];\n maxK = i;\n }\n }\n //System.out.println(result + \", \" + maxK);\n if (result == 0) {\n System.out.println(result);\n } else {\n char[] cc = new char[result];\n int ccIdx = result - 1;\n int n1Idx = n1;\n int n2Idx = n2;\n int mIdx = maxK;\n while (ccIdx >= 0) {\n switch (step[n1Idx][n2Idx][mIdx]) {\n case -1:\n n1Idx--;\n break;\n case -2:\n n1Idx--;\n n2Idx--;\n break;\n case 1:\n n2Idx--;\n break;\n case 0:\n cc[ccIdx--] = c1[n1Idx - 1];\n n1Idx--;\n n2Idx--;\n mIdx--;\n break;\n default:\n cc[ccIdx--] = c1[n1Idx - 1];\n mIdx = step[n1Idx][n2Idx][mIdx] - 100;\n n1Idx--;\n n2Idx--;\n break;\n }\n }\n System.out.println(cc);\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["strings", "dp"], "code_uid": "749de4c6c046a0e6501f63eaaba51e10", "src_uid": "391c2abbe862139733fcb997ba1629b8", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class D {\n\n final static long MOD = 1000000007;\n\n void solve() throws IOException {\n in(\"__std\"); out(\"__std\");\n\n int n = readInt();\n int k = 0;\n for (int i = 0; i < n; ++i) {\n if (readInt() == 2) ++k;\n }\n long a = 1;\n long b = 1;\n for (int i = 2; i <= n - k; ++i) {\n long c = a * i % MOD;\n a = (a + b) % MOD;\n b = c;\n }\n for (int i = 0; i < k; ++i) {\n a = a * (n - i) % MOD;\n }\n println(a);\n\n exit();\n }\n\n void in(String name) throws IOException {\n if (name.equals(\"__std\")) {\n in = new BufferedReader(new InputStreamReader(System.in));\n } else {\n in = new BufferedReader(new FileReader(name));\n }\n }\n\n void out(String name) throws IOException {\n if (name.equals(\"__std\")) {\n out = new PrintWriter(System.out);\n } else {\n out = new PrintWriter(name);\n }\n }\n\n void exit() {\n out.close();\n System.exit(0);\n }\n\n char readChar() throws IOException {\n return (char) in.read();\n }\n\n int readInt() throws IOException {\n return Integer.parseInt(readToken());\n }\n\n long readLong() throws IOException {\n return Long.parseLong(readToken());\n }\n\n double readDouble() throws IOException {\n return Double.parseDouble(readToken());\n }\n\n String readLine() throws IOException {\n st = null;\n return in.readLine();\n }\n\n String readToken() throws IOException {\n while (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(in.readLine());\n }\n return st.nextToken();\n }\n\n boolean eof() throws IOException {\n return !in.ready();\n }\n\n void print(String format, Object ... args) {\n out.print(new Formatter(Locale.US).format(format, args));\n }\n\n void println(String format, Object ... args) {\n out.println(new Formatter(Locale.US).format(format, args));\n }\n\n void print(Object value) {\n out.print(value);\n }\n\n void println(Object value) {\n out.println(value);\n }\n\n void println() {\n out.println();\n }\n\n StringTokenizer st;\n\n BufferedReader in;\n PrintWriter out;\n\n public static void main(String[] args) throws IOException {\n new D().solve();\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "dp"], "code_uid": "9c53fcd63d14336ab039fc297190de14", "src_uid": "91e8dbe94273e255182aca0f94117bb9", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.*;\n\npublic class IP {\n\tpublic static void main(String[] Args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint min = 10000, k = 0;\n\t\tfor (; k < 4; k++)\n\t\t\tmin = Math.min(min, in.nextInt());\n\t\tint a = in.nextInt(), b = Math.min(min - 1, in.nextInt()) + 1;\n\t\tSystem.out.print(Math.max(b - a, 0));\n\t}\n}", "lang_cluster": "Java", "tags": ["implementation", "number theory"], "code_uid": "ea1042603c5dce39b1f221fdd42275c7", "src_uid": "63b9dc70e6ad83d89a487ffebe007b0a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n/**\n * @author Eduardo Osorio\n * A01334501\n */\npublic class Unimodal_Array {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\n\t\tint n = sc.nextInt();\n\t\tString r = \"YES\";\n\t\tboolean c1 = true, c2 = true, c3 = true;\n\n\t\tint a[] = new int [n];\n\n\t\tfor (int i=0;i a[i+1]){\n\n\t\t\t\tc1 = false;\n\t\t\t\tc2 = false;\n\n\t\t\t} else if (c2 == true && a[i] == a[i+1]){\n\n\t\t\t\tr = \"YES\";\n\t\t\t\tc1 = false;\n\t\t\t\tc3 = true;\n\n\t\t\t} else if (c1 == true && a[i] < a[i+1]){\n\n\t\t\t\tc3 = true;\n\n\t\t\t} else {\n\n\t\t\t\tr = \"NO\";\n\t\t\t\tc1 = false;\n\t\t\t\tc2 = false;\n\t\t\t\tc3 = false;\n\n\t\t\t}\n\t\t}\n\n\t\tSystem.out.println(r);\n\n\t\tsc.close();\n\t}\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "6d1ce3029d7c20b404b186146d8ff64f", "src_uid": "5482ed8ad02ac32d28c3888299bf3658", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class hello\n{\n public static void main(String []args)\n {\n Scanner sc=new Scanner(System.in);\n int x=sc.nextInt();\n int y=sc.nextInt();\n int z=sc.nextInt();\n \n if(x>y)\n {\n \t if(x-y-z>0)\n \t {\n \t\t System.out.println(\"+\");\n \t }\n \t else\n \t {\n \t\t if(x-y==0&&z==0)\n \t\t {\n \t\t\t System.out.println(\"0\");\n \t\t }\n \t\t else\n \t\t {\n \t\t System.out.println(\"?\");\n \t\t }\n \t }\n }\n else\n {\n \t if(y-x-z>0)\n \t {\n \t\t System.out.println(\"-\");\n \t }\n \t else\n \t {\n \t\t if(y-x==0&&z==0)\n \t\t {\n \t\t\t System.out.println(\"0\");\n \t\t }\n \t\t else\n \t\t {\n \t\t System.out.println(\"?\");\n \t\t }\n \t }\n }\n \n }\n}\n", "lang_cluster": "Java", "tags": ["greedy"], "code_uid": "9004079093e5c7b9beaeb4667755bfe0", "src_uid": "66398694a4a142b4a4e709d059aca0fa", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.text.*;\n//Solution Credits: Taranpreet Singh\npublic class Main{\n //SOLUTION BEGIN\n //Code not meant for understanding, proceed with caution, You have been warned.\n void pre() throws Exception{}\n void solve(int TC) throws Exception{\n int m = ni();\n long inv = pow(m, mod-2);\n long ans = inv;\n long[] e= new long[m+1];\n for(int i = m; i>= 2; i--){\n long y = m/i;\n e[i] = mul(new long[]{y, 2*m-y, pow(m-y,mod-2),pow(m,mod-2)});\n for(int j = i*2; j<= m; j+=i)e[i] = (e[i]+mod-e[j])%mod;\n ans+=e[i];\n if(ans>=mod)ans-=mod;\n }\n pn(ans);\n }\n long mul(long[] a){\n long ans= 1;\n for(long x:a)ans = (ans*x)%mod;return ans;\n }\n long pow(long a, long p){\n long o = 1;\n while(p>0){\n if(p%2==1)o = (a*o)%mod;\n a = (a*a)%mod;\n p>>=1;\n }\n return o;\n }\n //SOLUTION END\n void hold(boolean b)throws Exception{if(!b)throw new Exception(\"Hold right there, Sparky!\");}\n long mod = (long)1e9+7, IINF = (long)1e18;\n final int INF = (int)1e9, MX = (int)1e5+7;\n DecimalFormat df = new DecimalFormat(\"0.00000000000\");\n double PI = 3.1415926535897932384626433832792884197169399375105820974944, eps = 1e-8;\n static boolean multipleTC = false, memory = false;\n FastReader in;PrintWriter out;\n void run() throws Exception{\n in = new FastReader();\n out = new PrintWriter(System.out);\n int T = (multipleTC)?ni():1;\n //Solution Credits: Taranpreet Singh\n pre();for(int t = 1; t<= T; t++)solve(t);\n out.flush();\n out.close();\n }\n public static void main(String[] args) throws Exception{\n if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, \"1\", 1 << 28).start();\n else new Main().run();\n }\n long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}\n int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}\n int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}\n void p(Object o){out.print(o);}\n void pn(Object o){out.println(o);}\n void pni(Object o){out.println(o);out.flush();}\n String n()throws Exception{return in.next();}\n String nln()throws Exception{return in.nextLine();}\n int ni()throws Exception{return Integer.parseInt(in.next());}\n long nl()throws Exception{return Long.parseLong(in.next());}\n double nd()throws Exception{return Double.parseDouble(in.next());}\n\n class FastReader{\n BufferedReader br;\n StringTokenizer st;\n public FastReader(){\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n public FastReader(String s) throws Exception{\n br = new BufferedReader(new FileReader(s));\n }\n\n String next() throws Exception{\n while (st == null || !st.hasMoreElements()){\n try{\n st = new StringTokenizer(br.readLine());\n }catch (IOException e){\n throw new Exception(e.toString());\n }\n }\n return st.nextToken();\n }\n\n String nextLine() throws Exception{\n String str = \"\";\n try{ \n str = br.readLine();\n }catch (IOException e){\n throw new Exception(e.toString());\n } \n return str;\n }\n }\n}", "lang_cluster": "Java", "tags": ["math", "dp", "probabilities", "number theory"], "code_uid": "f5679ac1781f6b895c9ef55f7f076c0f", "src_uid": "ff810b16b6f41d57c1c8241ad960cba0", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.lang.reflect.Array;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n public static BufferedReader in;\n public static StringTokenizer tok = new StringTokenizer(\"\");\n\n\n public static String readLine() { // \u0447\u0438\u0442\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u0434\u043e \u0441\u0430\u043c\u043e\u0433\u043e \u043a\u043e\u043d\u0446\u0430\n try {\n return in.readLine();\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n\n public static String readString() { // \u0447\u0438\u0442\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u0434\u043e \u043f\u0440\u043e\u0431\u0435\u043b\u0430/\u0442\u0430\u0431\u0443\u043b\u044f\u0446\u0438\u0438/\u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 \u0441\u0442\u0440\u043e\u043a\u0438\n\n while (!tok.hasMoreTokens()) {\n String line = readLine();\n if (null == line) return null; // \u0432\u0432\u043e\u0434\u0430 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435\u0442\n tok = new StringTokenizer(line); // \u0441\u044e\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432\u0442\u043e\u0440\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u0441\u0442\u0440\u043e\u043a\u0443 \u0441 \u0441\u0438\u043c\u0432\u043e\u043b\u0430\u043c\u0438, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043d\u0430\u0434\u043e \u043e\u0442\u0441\u0435\u043a\u0430\u0442\u044c, \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u044d\u0442\u043e \u043f\u0440\u043e\u0431\u0435\u043b \u0438 \u0442\u0430\u0431\u0443\u043b\u044f\u0446\u0438\u044f\n }\n\n return tok.nextToken();\n }\n\n public static int readInt() { // \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0434\u043b\u044f readLong(), readDouble(), ...\n return Integer.parseInt(readString());\n }\n\n public static void main(String[] args){\n in = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter out = new PrintWriter(System.out);\n int n = readInt();\n int k = readInt();\n int m = readInt();\n int a = readInt();\n \n //ArrayList candidates = new ArrayList<>();\n Candidate[] candidates = new Candidate[n];\n for (int i = 0; i < n; i++) {\n candidates[i] = new Candidate(i,0,0,1);\n }\n for (int i = 0; i < a; i++) {\n int l = readInt()-1;\n candidates[l].vote(i);\n }\n Arrays.sort(candidates);\n\n int minFor2 = candidates[k-1].votes;\n\n for (int i = k; i < n; i++) {\n if(candidates[i].votes + (m-a) > minFor2)\n candidates[i].type = 2;\n else\n candidates[i].type = 3;\n }\n\n if(n > k) {\n for (int i = 0; i < k; i++) {\n int ndVotes = candidates[i].votes + 1;\n int votes = 0;\n for (int j = i + 1; j < k + 1; j++) {\n votes +=ndVotes - candidates[j].votes;\n }\n if (votes <= m - a)\n candidates[i].type = 2;\n }\n }\n\n if(m-a > 0)\n {\n for (int i = 0; i < k; i++) {\n if(candidates[i].votes == 0) candidates[i].type = 2;\n }\n }\n else {\n for (int i = 0; i < k; i++) {\n if (candidates[i].votes == 0) candidates[i].type = 3;\n }\n }\n\n int[] ans = new int[n];\n\n for (int i = 0; i < n; i++) {\n ans[candidates[i].id] = candidates[i].type;\n }\n\n for (int i = 0; i < n; i++) {\n out.print(ans[i]+\" \");\n }\n\n\n out.flush();\n out.close();\n }\n\n static class Candidate implements Comparable{\n public int id;\n public int votes;\n public int lastT;\n public int type;\n\n public Candidate(int id,int votes,int lastT,int type)\n {\n this.id = id;\n this.votes = votes;\n this.lastT = lastT;\n this.type = type;\n }\n \n public void vote(int lastT)\n {\n votes++;\n this.lastT = lastT;\n }\n\n public int compareTo(Candidate p){\n if(p.votes > this.votes)\n return 1;\n else if(p.votes == this.votes)\n return p.lastT < this.lastT?1:-1;\n else return -1;\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["sortings", "greedy"], "code_uid": "6b24fd4cc0b20a90aad52fecf46af6d3", "src_uid": "81a890bd542963bbcec7a041dde5c247", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class LearnFromMaths\n{\n public static void main(String args[])\n {\n Scanner sc=new Scanner(System.in);\n int a=sc.nextInt();\n int b=sc.nextInt();\n int c=sc.nextInt();\n long arr[]=new long[1000000];\n int k=0;\n long x=0;\n long ans=0;\n for(int i=1;i<=81;i++)\n {\n x=b*(long)Math.pow(i,a)+c;\n if(x<1e9 && x>0 && sum(x,i))\n {\n ans++;\n arr[k++]=x;\n }\n }\n System.out.println(ans);\n for(int i=0;i 0; sum += y % 10,y/= 10);\n return sum==i;\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "math", "implementation", "number theory"], "code_uid": "61172f1f4b59605c21f17bad5a5f3460", "src_uid": "e477185b94f93006d7ae84c8f0817009", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskD solver = new TaskD();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskD {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n long n = in.nextLong();\n long m = in.nextLong();\n ModuloArithmetic moduloArithmetic = new ModuloArithmetic(998244353L);\n\n long factm = moduloArithmetic.factorial(m);\n long fact1 = moduloArithmetic.factorial(m - (n - 1));\n long fact2 = moduloArithmetic.factorial(n - 1);\n long pow2 = n >= 3 ? moduloArithmetic.powmod(2, n - 3) : 1;\n long t = moduloArithmetic.mul(fact1, fact2);\n long ans = moduloArithmetic.div(factm, t);\n ans = moduloArithmetic.mul(ans, n - 2);\n ans = moduloArithmetic.mul(ans, pow2);\n out.println(ans);\n }\n\n }\n\n static class InputReader {\n final InputStream is;\n final byte[] buffer = new byte[1024];\n int curCharIdx;\n int nChars;\n\n public InputReader(InputStream is) {\n this.is = is;\n }\n\n public int read() {\n if (curCharIdx >= nChars) {\n try {\n curCharIdx = 0;\n nChars = is.read(buffer);\n if (nChars == -1)\n return -1;\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return buffer[curCharIdx++];\n }\n\n public long nextLong() {\n int sign = 1;\n int c = skipDelims();\n if (c == '-') {\n sign = -1;\n c = read();\n if (isDelim(c))\n throw new RuntimeException(\"Incorrect format\");\n }\n long val = 0;\n while (c != -1 && !isDelim(c)) {\n if (!isDigit(c))\n throw new RuntimeException(\"Incorrect format\");\n val = 10L * val + (c - '0');\n c = read();\n }\n return val * sign;\n }\n\n private final int skipDelims() {\n int c = read();\n while (isDelim(c)) {\n c = read();\n }\n return c;\n }\n\n private static boolean isDelim(final int c) {\n return c == ' ' ||\n c == '\\n' ||\n c == '\\t' ||\n c == '\\r' ||\n c == '\\f';\n }\n\n private static boolean isDigit(final int c) {\n return '0' <= c && c <= '9';\n }\n\n }\n\n static class Algorithms {\n public static long powmod(long a, long n, long mod) {\n long res = 1;\n while (n != 0) {\n if ((n & 1) == 1)\n res = (res * a) % mod;\n a = (a * a) % mod;\n n >>= 1;\n }\n return res;\n }\n\n public static long inverseByModulo(long a, long n) {\n long t = 0, newt = 1, r = n, newr = a;\n while (newr != 0) {\n long q = r / newr;\n\n long temp = newt;\n newt = t - q * newt;\n t = temp;\n\n temp = newr;\n newr = r - q * newr;\n r = temp;\n }\n\n if (r > 1)\n return 0;\n if (t < 0)\n t += n;\n return t;\n }\n\n }\n\n static class ModuloArithmetic {\n final long MODULO;\n\n public ModuloArithmetic(long mod) {\n this.MODULO = mod;\n }\n\n public long mul(long a, long b) {\n return (a * b) % MODULO;\n }\n\n public long div(long a, long b) {\n return (a * Algorithms.inverseByModulo(b, MODULO)) % MODULO;\n }\n\n public long factorial(long n) {\n long ans = 1;\n for (int i = 2; i <= n; i++) ans = mul(ans, i);\n return ans;\n }\n\n public long powmod(long k, long n) {\n return Algorithms.powmod(k, n, MODULO);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["math", "combinatorics"], "code_uid": "cacd0f9f8f64e5a1d2ae0f04572a5883", "src_uid": "28d6fc8973a3e0076a21c2ea490dfdba", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\n\npublic class Main {\n public static void main(String[] args) throws FileNotFoundException\n {\n\t (new Main()).solve();\n }\n public void Main() {\n }\n \n\n void solve() throws FileNotFoundException {\n Scanner in = new Scanner(System.in);\n\t PrintWriter out = new PrintWriter(System.out);\n // Scanner in = new Scanner(new FileReader(\"input.txt\"));\n\t// PrintWriter out = new PrintWriter(\"output.txt\");\n\t String s = in.next();\n\t ArrayList a = new ArrayList();\n\t int prevh = -1;\n\t int prevm = -1;\n\t boolean flag = true;\n\t \n\t for (int j = 2; j < 100; j++) {\n\t\t int h = 0;\n\t\t int m = 0;\n\t\t for (int i = 0; i < s.indexOf(':'); i++) {\n\t\t\t int t = (int) s.charAt(i) - (int)'0';\n\t\t\t if (t >=0 && t <= 9) {\n\t\t\t\t\n\t\t\t } else {\n\t\t\t\t t = (int) s.charAt(i) - (int)'A' + 10;\n\t\t\t }\n\t\t\t if (t >= j) {\n\t\t\t\t h = -1;\n\t\t\t\t break;\n\t\t\t }\n\t\t\t h = h * j + t;\t\t\t \n\t\t }\n\t\t for (int i = s.indexOf(':') + 1; i < s.length(); i++) {\n\t\t\t int t = (int) s.charAt(i) - (int)'0';\n\t\t\t if (t >=0 && t <= 9) {\n\t\t\t\t\n\t\t\t } else {\n\t\t\t\t t = (int) s.charAt(i) - (int)'A' + 10;\n\t\t\t }\n\t\t\t if (t >= j) {\n\t\t\t\t m = -1;\n\t\t\t\t break;\n\t\t\t }\n\t\t\t m = m * j + t;\t\t\t \n\t\t }\t\n\t\t if (h >= 0 && h <= 23 && m >= 0 && m <= 59) {\n\t\t\t a.add(j);\n\t\t\t if (h == prevh && m == prevm) {\n\t\t\t\t flag = false;\n\t\t\t\t break;\n\t\t\t }\n\t\t } \t\t \n\t\t\t\t prevh = h;\n\t\t\t\t prevm = m;\n\n\t }\n\t \n\t if (flag) {\n\t\t if (a.size() == 0) {\n\t\t\t out.print(0);\n\t\t }\n\t\t for (Integer t : a) {\n\t\t\t out.print(t + \" \");\n\t\t }\n\t } else {\n\t\t out.print(-1);\n\t }\n\t \n\t out.close();\n } \n\n};\n\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "120b666e96baf2c8ba72c36161adf6e7", "src_uid": "c02dfe5b8d9da2818a99c3afbe7a5293", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.util.HashMap;\nimport java.util.Scanner;\n\npublic class CODE_OBSTUFICATIION {\n\n\tpublic static void main(String[] args) {\n\n\t\tScanner nik = new Scanner(System.in);\n\t\tString s = nik.next();\n\t\tboolean b = true;\n\t\tHashMap hm = new HashMap<>();\n\t\tfor (int i = 0; i < s.length(); i++) {\n\t\t\tint temp = s.charAt(i) - 'a';\n\t\t\tif (hm.size() < temp) {\n\t\t\t\tb = false;\n\t\t\t\tbreak;\n\t\t\t} else {\n\t\t\t\thm.put(s.charAt(i), hm.getOrDefault(s.charAt(i) + 1, 0));\n\t\t\t}\n\n\t\t}\n\n\t\tSystem.out.println(b == true ? \"YES\" : \"NO\");\n\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["greedy", "strings", "implementation"], "code_uid": "e5bc00404301ef2a118826c60a184232", "src_uid": "c4551f66a781b174f95865fa254ca972", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\n\npublic class Main\n{\n static long mod=1000000007;\n static long p=(long)1e10;\n public static void main(String[] args) throws Exception\n {\n \tFastReader in=new FastReader();\n \tPrintWriter pw=new PrintWriter(System.out);\n \tint n=in.nextInt();\n \tlong sum=0,max=0;\n \tfor(int i=0;i\n{\n A f;\n B s;\n\n public pair(A a,B b)\n {\n f=a;\n s=b;\n }\n}\n\nclass FastReader\n{\n BufferedReader br;\n StringTokenizer st;\n \n public FastReader()\n {\n br=new BufferedReader(new InputStreamReader(System.in));\n }\n \n public String next() throws IOException\n {\n if(st==null || !st.hasMoreElements())\n {\n st=new StringTokenizer(br.readLine());\n }\n return st.nextToken();\n }\n \n public int nextInt() throws IOException\n {\n return Integer.parseInt(next());\n }\n \n public long nextLong() throws IOException\n {\n return Long.parseLong(next());\n }\n}", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "bd02df7c2c8308381cf07ea1e9a270d1", "src_uid": "d215b3541d6d728ad01b166aae64faa2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n/**\n * CodeForces : 338\n * \n * @author vinaysaini E. Hexagons\n */\npublic class cf338e {\n\n\tstatic int dx[] = { 1, -1, -2, -1, 1, 2 };\n\tstatic int dy[] = { 2, 2, 0, -2, -2, 0 };\n\n\tpublic static void main(String[] args) {\n\t\tlong x = 0, y = 0;\n\n\t\tlong n = in.nextLong();\n\t\tlong ringNumber = getRing(n);\n\t\tlong stepsUpTo = 3 * ringNumber * ringNumber + 3 * ringNumber;\n\t\tx = 2 * ringNumber;\n\t\tlong remainingSteps = n - stepsUpTo;\n\t\tif (remainingSteps > 0) {\n\t\t\tx = x + dx[0];\n\t\t\ty = y + dy[0];\n\t\t\tremainingSteps--;\n\t\t}\n\t\tif (remainingSteps >= ringNumber) {\n\t\t\tx += dx[1] * ringNumber;\n\t\t\ty += dy[1] * ringNumber;\n\t\t\tremainingSteps -= ringNumber;\n\t\t} else {\n\t\t\tx += dx[1] * remainingSteps;\n\t\t\ty += dy[1] * remainingSteps;\n\t\t\tremainingSteps -= remainingSteps;\n\t\t}\n\t\tif (remainingSteps >= ringNumber+1) {\n\t\t\tx += dx[2] * (ringNumber+1);\n\t\t\ty += dy[2] * (ringNumber+1);\n\t\t\tremainingSteps -= ringNumber+1;\n\t\t} else {\n\t\t\tx += dx[2] * remainingSteps;\n\t\t\ty += dy[2] * remainingSteps;\n\t\t\tremainingSteps -= remainingSteps;\n\t\t}\n\t\tif (remainingSteps >= ringNumber+1) {\n\t\t\tx += dx[3] * (ringNumber+1);\n\t\t\ty += dy[3] * (ringNumber+1);\n\t\t\tremainingSteps -= ringNumber+1;\n\t\t} else {\n\t\t\tx += dx[3] * remainingSteps;\n\t\t\ty += dy[3] * remainingSteps;\n\t\t\tremainingSteps -= remainingSteps;\n\t\t}\n\t\tif (remainingSteps >= ringNumber+1) {\n\t\t\tx += dx[4] * (ringNumber+1);\n\t\t\ty += dy[4] * (ringNumber+1);\n\t\t\tremainingSteps -= ringNumber+1;\n\t\t} else {\n\t\t\tx += dx[4] * remainingSteps;\n\t\t\ty += dy[4] * remainingSteps;\n\t\t\tremainingSteps -= remainingSteps;\n\t\t}\n\t\tif (remainingSteps >= ringNumber+1) {\n\t\t\tx += dx[5] * (ringNumber+1);\n\t\t\ty += dy[5] * (ringNumber+1);\n\t\t\tremainingSteps -= ringNumber+1;\n\t\t} else {\n\t\t\tx += dx[5] * remainingSteps;\n\t\t\ty += dy[5] * remainingSteps;\n\t\t\tremainingSteps -= remainingSteps;\n\t\t}\n\t\tif (remainingSteps >= ringNumber) {\n\t\t\tx += dx[0] * ringNumber;\n\t\t\ty += dy[0] * ringNumber;\n\t\t\tremainingSteps -= ringNumber;\n\t\t} else {\n\t\t\tx += dx[0] * remainingSteps;\n\t\t\ty += dy[0] * remainingSteps;\n\t\t\tremainingSteps -= remainingSteps;\n\t\t}\n\n\t\tout.println(x + \" \" + y);\n\t\tout.close();\n\t}\n\n\tstatic long getRing(long n) {\n\t\tlong l = 0;\n\t\tlong r = (long) 1e9;\n\t\twhile (l < r) {\n\t\t\tlong m = (l + r) / 2;\n\t\t\tlong sum = 3 * m * m + 3 * m;\n\t\t\tif (n < sum) {\n\t\t\t\tr = m;\n\t\t\t} else\n\t\t\t\tl = m + 1;\n\t\t}\n\t\treturn l - 1;\n\t}\n\n\tpublic static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n\tpublic static FastScanner in = new FastScanner();\n\n\tpublic static class FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreElements()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tString nextLine() {\n\t\t\tString str = \"\";\n\t\t\ttry {\n\t\t\t\tstr = br.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\t} // --fast i/o ends here----//\n\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation", "binary search"], "code_uid": "4af23f0ff02c7d3b490efb7c019dd1af", "src_uid": "a4b6a570f5e63462b68447713924b465", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\npublic class MAin {\n\n\tpublic static void main(String[] args) {\n\n\n\t\t\n\t\t\n\t\tBufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in));\n\t\t\n\t\t\n\t\ttry {\n\t\t\t\n\t\t\tint n=Integer.parseInt(bufferedReader.readLine());\n\t\t\t\n\t\t\tint[] num=new int[n];\n\t\t\t\n\t\t\tint minI=-90;\n\t\t\tint maxI=-90;\n\t\t\tString[] input=bufferedReader.readLine().split(\" \");\n\t\t\tint min=Integer.MAX_VALUE;\n\t\t\tint max=Integer.MIN_VALUE;\n\t\t\tfor(int i=0;imax) {\n\t\t\t\t\tmax=val;\n\t\t\t\t\tmaxI=i;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (val[]G;\n \n public static int solve(int idx,int rem)\n {\n if (rem<=0) return 0;\n if (dp[idx][rem]!=-1) return dp[idx][rem];\n dp[idx][rem]=(int)1e6;\n for (int i=1;i<=3;++i)\n {\n if (i==1&&s.charAt(idx-1)=='R') continue;\n if (i==2&&s.charAt(idx-1)=='G') continue;\n if (i==3&&s.charAt(idx-1)=='B') continue;\n for (int u:G[i])\n if (arr[u]>arr[idx])\n dp[idx][rem]=Math.min(dp[idx][rem],(solve(u, rem - arr[u])+Math.abs(u-idx)));\n }\n return dp[idx][rem];\n }\n \n public static void main(String[] args) throws IOException {\n Scanner sc = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n \n int n=sc.nextInt();\n int pos=sc.nextInt();\n int k=sc.nextInt();\n G = new ArrayList[5];\n for (int i=0;i<5;++i) G[i] = new ArrayList();\n arr =new int [n+5];\n dp=new int [n+5][k+5];\n for (int i=0;i<=n+1;++i)\n for (int j=0;j<=k+1;++j)\n dp[i][j]=-1;\n \n for (int i=1;i<=n;++i) arr[i]=sc.nextInt();\n s=sc.nextLine();\n for (int i=0;i=(int)1e6)?-1:cnt);\n out.close();\n }\n static class Scanner\n {\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(InputStream s){\tbr = new BufferedReader(new InputStreamReader(s));}\n\n public String next() throws IOException\n {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n public int nextInt() throws IOException {return Integer.parseInt(next());}\n\n public long nextLong() throws IOException {return Long.parseLong(next());}\n\n public String nextLine() throws IOException {return br.readLine();}\n }\n}", "lang_cluster": "Java", "tags": ["dp"], "code_uid": "c5906045df71bf595893e1d2b1fcd529", "src_uid": "a95e54a7e38cc0d61b39e4a01a6f8d3f", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\n\n// PROBLEM : Can teleport between cells corresponding to the same string\npublic class B {\n static int n;\n static char[][] G;\n public static void main(String[] args) throws Exception {\n Scanner in = new Scanner(System.in);\n n = in.nextInt();\n G = new char[n][n];\n F = new HashMap();\n for(int r=0; r 0) System.out.println(\"FIRST\");\n if(ans < 0) System.out.println(\"SECOND\");\n if(ans == 0) System.out.println(\"DRAW\");\n }\n \n static int ch_to_val(char ch, boolean first) {\n if(ch=='a') return first ? 1 : -1;\n if(ch=='b') return first ? -1 : 1;\n return 0;\n }\n\n static long hash(int sum, boolean[] R) {\n long hash = sum;\n for(int i=0; i F;\n static int f(int sum, boolean[] R, boolean first) {\n long key = hash(sum, R);\n if(F.containsKey(key)) return F.get(key);\n if(sum == 2*(n-1)) return 0;\n\n int ans = -1000;\n int ns = sum+1;\n Character[] CH = new Character[ns+1];\n for(int r=0; r<=sum+1; r++) {\n boolean can_see = (r=0 && R[r-1]);\n if(!can_see) continue;\n int c = ns-r;\n if(c<0 || c>=n || r<0 || r>=n) continue;\n CH[r] = G[r][c];\n }\n\n for(int r=0; r<=sum+1; r++) {\n if(CH[r] != null) {\n char ch = CH[r];\n boolean[] NR = new boolean[ns+1];\n for(int rr=0; rr<=sum+1; rr++)\n if(CH[rr]!=null && CH[rr] == ch) {\n NR[rr] = true;\n CH[rr] = null;\n }\n ans = Math.max(ans, ch_to_val(ch,first) - f(ns, NR, !first));\n }\n }\n F.put(key, ans);\n return ans;\n }\n}\n", "lang_cluster": "Java", "tags": ["games", "dp", "bitmasks"], "code_uid": "254b34dbb9d81231c0a2668759e02920", "src_uid": "d803fe167a96656f8debdc21edd988e4", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\n\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tScanner r = new Scanner(System.in);\n\t\t\n\t\tint n = r.nextInt();\n\t\tint w = r.nextInt();\n\t\tint a = r.nextInt()-1;\n\t\tint b = r.nextInt()-1;\n\t\t\n\t\tint am = a%w;\n\t\tint bm = b%w;\n\t\t\n\t\tint res = 3;\n\t\t\n\t\tif(w == 1)res = 1;\n\t\telse if(a == b)res = 1;\n\t\telse if(a/w == b/w)res = 1;\n\t\telse if(am == 0 && bm == w-1)res = 1;\n\t\telse if(am == 0 && b == n-1)res = 1;\n\t\telse if(b/w - a/w == 1)res = 2;\n\t\telse if(am == 0)res = 2;\n\t\telse if(bm == w-1)res = 2;\n\t\telse if(b == n-1)res = 2;\n\t\telse if(am - bm == 1)res = 2;\n\t\telse res = 3;\n\t\t\n\t\tSystem.out.println(Math.max(1, res));\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "8eb4d4c5205f4b695d5ccc351c91d77c", "src_uid": "f256235c0b2815aae85a6f9435c69dac", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.Writer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author emotionalBlind\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n}\n\nclass TaskC {\n \n int getN(int x) {\n if (x == 1) return 1;\n if (x == 2) return 3;\n if (x == 3) return 5;\n if (x == 4) return 3;\n if (x == 5) return 3;\n if (x <= 13) return 5;\n for (int i = 7; i <= 100; i += 2) {\n int v = i * i + 1;\n v /= 2;\n if (x <= v) return i;\n }\n return 101;\n }\n \n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int x = in.readInt();\n out.printLine(getN(x));\n }\n}\n\nclass InputReader {\n\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public static boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n }\n\nclass OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(outputStream);\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void print(Object...objects) {\n for (int i = 0; i < objects.length; i++) {\n if (i != 0)\n writer.print(' ');\n writer.print(objects[i]);\n }\n }\n\n public void printLine(Object...objects) {\n print(objects);\n writer.println();\n }\n\n public void close() {\n writer.close();\n }\n\n}\n", "lang_cluster": "Java", "tags": ["math", "binary search"], "code_uid": "a5fcdde33419100eb93b04815a696d96", "src_uid": "01eccb722b09a0474903b7e5abc4c47a", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class B {\n\tScanner sc = new Scanner(System.in);\n\n\tvoid run() {\n\t\tint m = sc.nextInt();\n\t\tint zero = 0;\n\t\tfor (int i = 5; zero < m; i += 5) {\n\t\t\tint tmp = i;\n\t\t\twhile (tmp > 0 && tmp % 5 == 0) {\n\t\t\t\tzero ++;\n\t\t\t\ttmp /= 5;\n\t\t\t}\n\t\t\tif (zero == m) {\n\t\t\t\tStringBuilder out = new StringBuilder();\n\t\t\t\tout.append(\"5\\n\");\n\t\t\t\tfor (int j = i; j <= i + 4; j++) out.append(j + \" \");\n\t\t\t\tSystem.out.println(out);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(0);\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew B().run();\n\t}\n}", "lang_cluster": "Java", "tags": ["brute force", "math", "constructive algorithms", "number theory"], "code_uid": "4ff186f322b2f0b2302f4b9ae454fc80", "src_uid": "c27ecc6e4755b21f95a6b1b657ef0744", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.io.FileWriter; \nimport java.math.BigInteger;\nimport java.math.BigDecimal;\n// Solution\n \npublic class Main \n{ \n public static void main (String[] argv) \n {\n\t new Main();\n } \n \n \n boolean test = false; \n final int[][] dirs8 = {{0,1}, {0,-1}, {-1,0}, {1,0}, {1,1},{1,-1},{-1,1},{-1,-1}};\n final int[][] dirs4 = {{0,1}, {0,-1}, {-1,0}, {1,0}};\n final int MOD = 1000000007; //998244353;\n \n \n \n final int WALL = -1;\n final int EMPTY = -2;\n final int VISITED = 1;\n final int FULL = 2;\n \n final int START = 1;\n final int END = 0;\n \n int[] fac;\n int[] ifac;\n int[] rfac;\n \n int[] pow2;\n \n int[] mobius;\n int[] sieve;\n int[][] factors;\n \n final int UNVISITED = -2;\n\n public Main() {\n\tFastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));\n\t\n \n //FastReader in = new FastReader(new BufferedReader(new FileReader(\"Main.in\"))); \n \n //int nt = in.nextInt(); \n int nt = 1;\n StringBuilder sb = new StringBuilder();\n \n \n for (int it = 0; it < nt; it++) \n { \n long n = in.nextLong();\n long k = in.nextLong();\n \n if (k == 1){\n System.out.println(n);\n return;\n }\n \n//System.out.println(\"n = \" + n + \" k = \" + k);\n //binary search on odd numbers\n long lo = 1, hi = n / 2;\n \n \n \n while (lo <= hi)\n { \n \n long mid = (hi + lo) / 2;\n long val = mid * 2 - 1;\n//System.out.println(\"lo = \" + lo + \" hi = \" + hi + \", mid = \" + mid + \", val = \" + val);\n if (cnt(val, n) >= k) {\n //System.out.println(\"cnt >= 100\");\n lo = mid + 1;\n }\n else {\n //System.out.println(\"cnt < 100\");\n hi = mid - 1;\n }\n }\n long cand = hi * 2 - 1;\n if (cnt(cand, n) < k) cand = 0;\n \n lo = 1;\n hi = n / 2;\n \n while (lo <= hi)\n {\n long mid = (hi + lo) / 2;\n long val = mid * 2;\n if (cnt(val, n) >= k)\n lo = mid + 1;\n else hi = mid - 1;\n }\n \n cand = Math.max(cand, hi * 2);\n System.out.println(cand); \n }\n \n System.out.print(sb);\n \n }\n \n private long cnt(long v, long n)\n {\n//System.out.println(\"cnting \" + v + \" \" + n);\n if (v > n) return 0;\n \n long cnt = 0;\n if (v % 2 == 1) { \n long segSize = 1;\n long start = v;\n while(start <= n){ \n long end = Math.min(n, start + segSize - 1);\n cnt += end - start + 1;\n \n segSize *= 2;\n start *= 2; \n }\n \n }else {\n \n long segSize = 2;\n long start = v;\n while(start <= n){ \n long end = Math.min(n, start + segSize - 1);\n cnt += end - start + 1;\n \n segSize *= 2;\n start *= 2; \n }\n \n }\n//System.out.println(\"cnt = \" + cnt);\n return cnt; \n }\n \n class Node implements Comparable{\n int lo, hi;\n public Node(int lo, int hi)\n {\n this.lo = lo;\n this.hi = hi;\n }\n \n @Override\n public int compareTo(Node o){\n if (lo != o.lo) return lo - o.lo;\n return hi - o.hi;\n }\n }\n \n private long[][] matIdentity(int n)\n {\n long[][] a = new long[n][n];\n for (int i = 0; i < n; i++)\n a[i][i] = 1;\n return a;\n }\n private long[][] matPow(long[][] mat0, long p)\n {\n int n = mat0.length;\n long[][] ans = matIdentity(n);\n long[][] mat = matCopy(mat0);\n while (p > 0)\n {\n if (p % 2 == 1){\n ans = matMul(ans, mat);\n }\n \n p /= 2;\n mat = matMul(mat, mat);\n }\n return ans;\n }\n \n private long[][] matCopy(long[][] a)\n {\n int n = a.length;\n long[][] b = new long[n][n];\n for (int i = 0; i < n; i++)\n for (int j = 0; j < n; j++)\n b[i][j] = a[i][j];\n return b;\n }\n private long[][] matMul(long[][] a, long[][] b)\n {\n int n = a.length;\n \n long[][] c = new long[n][n];\n for (int i = 0; i < n; i++)\n {\n for (int j = 0; j < n; j++)\n {\n for (int k = 0; k < n; k++)\n c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % MOD;\n }\n }\n \n return c;\n }\n \n private long[] matMul(long[][] a, long[] b)\n {\n int n = a.length;\n \n long[] c = new long[n];\n for (int i = 0; i < n; i++)\n {\n for (int j = 0; j < n; j++)\n c[i] = (c[i] + a[i][j] * b[j]) % MOD;\n }\n \n return c;\n }\n \n class Mark implements Comparable {\n int type, h;\n long x;\n public Mark(int h, long x, int type)\n {\n this.h = h;\n this.x = x;\n this.type = type;\n } \n \n @Override\n public int compareTo(Mark o)\n {\n if (this.x == o.x) return type - o.type; // let end comes before start\n return Long.compare(x, o.x); \n }\n }\n \n private boolean coLinear(int[] p, int[] q, int[] r)\n {\n return 1L * (p[1] - r[1]) * (q[0] - r[0]) == 1L * (q[1] - r[1]) * (p[0] - r[0]);\n }\n \n \n private void fill(char[] a, int lo, int c, char letter)\n {\n //System.out.println(\"fill \" + lo + \" \" + c + \" \" + letter);\n for (int i = lo; i < lo + c; i++) a[i] = letter;\n }\n \n \n \n private int cntBitOne(String s){\n int c = 0, n = s.length();\n for (int i = 0; i < n; i++) \n if (s.charAt(i) == '1') c++;\n return c;\n }\n \n class DSU {\n int n;\n int[] par;\n int[] sz;\n int nGroup;\n \n public DSU(int n)\n {\n this.n = n;\n par = new int[n];\n sz = new int[n];\n for (int i = 0; i < n; i++){\n par[i] = i;\n sz[i] = 1;\n }\n nGroup = n; \n }\n \n private boolean add(int p, int q) {\n int rp = find(p);\n int rq = find(q);\n if (rq == rp) return false;\n \n if (sz[rp] <= sz[rq]) {\n sz[rq] += sz[rp];\n par[rp] = rq;\n }else {\n sz[rp] += sz[rq];\n par[rq] = rp;\n }\n nGroup--;\n return true;\n }\n \n private int find(int p)\n {\n int r = p;\n while (par[r] != r) r = par[r];\n \n while (r != p) {\n int t = par[p];\n par[p] = r;\n p = t;\n }\n return r;\n }\n \n }\n \n \n // \u03bc(n) = 1 if n is a square-free positive integer with an even number of prime factors. e.g. 6, 15\n // \u03bc(n) = \u22121 if n is a square-free positive integer with an odd number of prime factors. e.g. 2, 3, 5, 2*3*5\n // \u03bc(n) = 0 if n has a squared prime factor. e.g : 2*2, 3*3*5\n private void build_pow2_function(int n)\n {\n pow2 = new int[n+1];\n pow2[0] = 1;\n for (int i = 1; i <= n; i++) pow2[i] = (int)(1L * pow2[i-1] * 2 % MOD);\n }\n \n private void build_fac_function(int n)\n {\n fac = new int[n+1];\n fac[0] = 1;\n for (int i = 1; i <= n; i++)\n fac[i] = (int)(1L * fac[i-1] * i % MOD);\n }\n \n private void build_ifac_function(int n)\n {\n ifac = new int[n+1];\n ifac[0] = 1;\n for (int i = 1; i <= n; i++)\n ifac[i] = (int)(1L * ifac[i-1] * inv(i) % MOD);\n }\n \n private void build_sieve_function(int n)\n {\n sieve = new int[n+1];\n for (int i = 2; i <= n; i++)\n sieve[i] = i;\n for (int i = 2; i <= n; i++) \n {\n if (sieve[i] == i){\n for (long j = 1L * i * i; j <= n; j += i)\n sieve[(int)j] = i;\n }\n }\n }\n \n private void build_mobius_function(int n)\n {\n mobius = new int[n+1];\n sieve = new int[n+1];\n factors = new int[n+1][];\n //for (int i = 1; i <= n; i++)factors[i] = new ArrayList<>();\n for (int i = 2; i <= n; i++)\n sieve[i] = i;\n for (int i = 2; i <= n; i++) \n {\n if (sieve[i] == i){\n mobius[i] = -1;\n for (long j = 1L * i * i; j <= n; j += i)\n sieve[(int)j] = i;\n }\n }\n \n for (int i = 6; i <= n; i++)\n {\n if (sieve[i] != i) {\n int pre = i / sieve[i];\n if (pre % sieve[i] != 0)\n mobius[i] = -mobius[pre];\n }\n }\n int[] sz = new int[n+1];\n long tot = 0;\n for (int i = 2; i <= n; i++) \n {\n if (mobius[i] != 0)\n {\n for (int j = i * 2; j <= n; j += i) { \n sz[j]++;\n tot++;\n } \n }\n }\n for (int i = 2; i <= n; i++) {\n factors[i] = new int[sz[i]];\n sz[i] = 0;\n }\n \n \n for (int i = 2; i <= n; i++) \n {\n if (mobius[i] != 0)\n {\n for (int j = i * 2; j <= n; j += i) {\n factors[j][sz[j]++] = i;\n //factors[j].add(i);\n } \n }\n }\n //System.out.println(\"tot = \" + tot);\n }\n \n private int[] build_z_function(String s)\n {\n int n = s.length();\n int[] zfun = new int[n];\n \n int l = -1, r = -1;\n for (int i = 1; i < n; i++)\n {\n // Set the start value\n if (i <= r)\n zfun[i] = Math.min(zfun[i-l], r - i + 1);\n \n while (i + zfun[i] < n && s.charAt(i + zfun[i]) == s.charAt(zfun[i])) \n zfun[i]++; \n \n if (i + zfun[i] - 1> r){\n l = i;\n r = i + zfun[i] - 1;\n }\n }\n \n if (test)\n {\n System.out.println(\"Z-function of \" + s);\n for (int i = 0; i < n; i++) System.out.print(zfun[i] + \" \");\n System.out.println();\n }\n return zfun;\n }\n \n class BIT {\n int[] bit;\n int n;\n \n public BIT(int n){\n this.n = n;\n bit = new int[n+1];\n }\n \n private int query(int p)\n {\n int sum = 0;\n for (; p > 0; p -= (p & (-p)))\n sum += bit[p];\n \n return sum;\n }\n \n private void add(int p, int val)\n {\n //System.out.println(\"add to BIT \" + p);\n for (; p <= n; p += (p & (-p)))\n bit[p] += val;\n }\n \n \n }\n \n \n \n private List getMinFactor(int sum)\n {\n List factors = new ArrayList<>();\n \n for (int sz = 2; sz <= sum / sz; sz++){\n if (sum % sz == 0) {\n factors.add(sz);\n factors.add(sum / sz);\n }\n }\n if (factors.size() == 0)\n factors.add(sum);\n \n return factors;\n }\n \n /* Tree class */\n class Tree {\n int V = 0;\n int root = 0;\n List[] nbs;\n int[][] timeRange;\n int[] subTreeSize;\n int t;\n boolean dump = false;\n \n public Tree(int V, int root)\n {\n if (dump) \n System.out.println(\"build tree with size = \" + V + \", root = \" + root); \n \n this.V = V; \n this.root = root;\n nbs = new List[V];\n subTreeSize = new int[V];\n for (int i = 0; i < V; i++)\n nbs[i] = new ArrayList<>();\n \n \n }\n \n public void doneInput()\n {\n dfsEuler();\n }\n \n public void addEdge(int p, int q)\n {\n nbs[p].add(q);\n nbs[q].add(p);\n }\n \n private void dfsEuler()\n {\n timeRange = new int[V][2]; \n t = 1;\n dfs(root); \n }\n \n private void dfs(int node)\n {\n if (dump)\n System.out.println(\"dfs on node \" + node + \", at time \" + t);\n timeRange[node][0] = t;\n \n for (int next : nbs[node]) {\n if (timeRange[next][0] == 0)\n {\n ++t;\n dfs(next); \n }\n }\n timeRange[node][1] = t;\n subTreeSize[node] = t - timeRange[node][0] + 1;\n }\n \n public List getNeighbors(int p) {\n return nbs[p];\n }\n \n public int[] getSubTreeSize(){\n return subTreeSize;\n }\n \n public int[][] getTimeRange()\n {\n if (dump){\n for (int i = 0; i < V; i++){\n System.out.println(i + \": \" + timeRange[i][0] + \" - \" + timeRange[i][1]);\n }\n }\n return timeRange;\n }\n \n }\n \n /* segment tree */\n class SegTree {\n int[] a;\n int[] tree;\n int[] treeMin;\n int[] treeMax;\n int[] lazy;\n int n;\n boolean dump = false;\n \n public SegTree(int n)\n {\n if (dump)\n System.out.println(\"create segTree with size \" + n);\n this.n = n;\n treeMin = new int[n*4];\n treeMax = new int[n*4];\n lazy = new int[n*4];\n }\n \n public SegTree(int n, int[] a) {\n this(n);\n this.a = a;\n buildTree(1, 0, n-1); \n }\n \n private void buildTree(int node, int lo, int hi)\n {\n if (lo == hi) {\n tree[node] = lo;\n return;\n }\n \n int m = (lo + hi) / 2;\n buildTree(node * 2, lo, m);\n buildTree(node * 2 + 1, m + 1, hi);\n pushUp(node, lo, hi);\n }\n \n \n private void pushUp(int node, int lo, int hi)\n {\n if (lo >= hi) return;\n \n // note that, if we need to call pushUp on a node, then lazy[node] must be zero.\n \n //the true value is the value + lazy\n treeMin[node] = Math.min(treeMin[node * 2] + lazy[node * 2], treeMin[node * 2 + 1] + lazy[node * 2 + 1]);\n treeMax[node] = Math.max(treeMax[node * 2] + lazy[node * 2], treeMax[node * 2 + 1] + lazy[node * 2 + 1]);\n // add combine fcn\n }\n \n private void pushDown(int node, int lo, int hi)\n {\n if (lazy[node] == 0) return;\n \n int lz = lazy[node];\n lazy[node] = 0; \n \n \n treeMin[node] += lz;\n treeMax[node] += lz; \n \n if (lo == hi) return;\n \n int mid = (lo + hi) / 2;\n lazy[node * 2] += lz;\n lazy[node * 2 + 1] += lz;\n }\n \n public int rangeQueryMax(int fr, int to)\n {\n return rangeQueryMax(1, 0, n-1, fr, to);\n }\n \n public int rangeQueryMax(int node, int lo, int hi, int fr, int to)\n {\n if (lo == fr && hi == to)\n return treeMax[node] + lazy[node];\n \n int mid = (lo + hi) / 2;\n pushDown(node, lo, hi);\n \n if (to <= mid) {\n return rangeQueryMax(node * 2, lo, mid, fr, to);\n }else if (fr > mid)\n return rangeQueryMax(node * 2 + 1, mid + 1, hi, fr, to);\n else {\n return Math.max(rangeQueryMax(node * 2, lo, mid, fr, mid),\n rangeQueryMax(node * 2 + 1, mid + 1, hi, mid + 1, to)); \n }\n }\n \n public int rangeQueryMin(int fr, int to)\n {\n return rangeQueryMin(1, 0, n-1, fr, to);\n }\n \n public int rangeQueryMin(int node, int lo, int hi, int fr, int to)\n {\n if (lo == fr && hi == to)\n return treeMin[node] + lazy[node];\n \n int mid = (lo + hi) / 2;\n pushDown(node, lo, hi);\n \n if (to <= mid) {\n return rangeQueryMin(node * 2, lo, mid, fr, to);\n }else if (fr > mid)\n return rangeQueryMin(node * 2 + 1, mid + 1, hi, fr, to);\n else {\n return Math.min(rangeQueryMin(node * 2, lo, mid, fr, mid),\n rangeQueryMin(node * 2 + 1, mid + 1, hi, mid + 1, to)); \n }\n }\n \n public void rangeUpdate(int fr, int to, int delta){\n rangeUpdate(1, 0, n-1, fr, to, delta);\n }\n \n \n public void rangeUpdate(int node, int lo, int hi, int fr, int to, int delta){\n pushDown(node, lo, hi);\n if (fr == lo && to == hi)\n {\n lazy[node] = delta;\n return;\n }\n \n int m = (lo + hi) / 2;\n if (to <= m) \n rangeUpdate(node * 2, lo, m, fr, to, delta);\n else if (fr > m)\n rangeUpdate(node * 2 + 1, m + 1, hi, fr, to, delta);\n else {\n rangeUpdate(node * 2, lo, m, fr, m, delta);\n rangeUpdate(node * 2 + 1, m + 1, hi, m + 1, to, delta); \n }\n \n // re-set the in-variant\n pushUp(node, lo, hi);\n }\n \n \n \n public int query(int node, int lo, int hi, int fr, int to)\n {\n if (fr == lo && to == hi)\n return tree[node];\n \n int m = (lo + hi) / 2;\n if (to <= m) \n return query(node * 2, lo, m, fr, to);\n else if (fr > m)\n return query(node * 2 + 1, m + 1, hi, fr, to);\n \n int lid = query(node * 2, lo, m, fr, m);\n int rid = query(node * 2 + 1, m + 1, hi, m + 1, to);\n return a[lid] >= a[rid] ? lid : rid;\n }\n \n \n }\n \n \n private long inv(long v)\n {\n return pow(v, MOD-2);\n }\n \n private long pow(long v, long p)\n {\n long ans = 1;\n while (p > 0)\n {\n if (p % 2 == 1)\n ans = ans * v % MOD;\n v = v * v % MOD;\n p = p / 2;\n }\n return ans;\n }\n \n private double dist(double x, double y, double xx, double yy)\n {\n return Math.sqrt((xx - x) * (xx - x) + (yy - y) * (yy - y));\n }\n \n \n \n \n private int mod_add(int a, int b) {\n int v = a + b;\n if (v >= MOD) v -= MOD;\n return v;\n }\n \n \n private long overlap(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {\n if (x1 > x3) return overlap(x3, y3, x4, y4, x1, y1, x2, y2);\n \n if (x3 > x2 || y4 < y1 || y3 > y2) return 0L;\n \n //(x3, ?, x2, ?)\n int yL = Math.max(y1, y3);\n int yH = Math.min(y2, y4); \n int xH = Math.min(x2, x4);\n \n return f(x3, yL, xH, yH);\n }\n //return #black cells in rectangle\n private long f(int x1, int y1, int x2, int y2) {\n long dx = 1L + x2 - x1;\n long dy = 1L + y2 - y1;\n if (dx % 2 == 0 || dy % 2 == 0 || (x1 + y1) % 2 == 0) \n return 1L * dx * dy / 2;\n return 1L * dx * dy / 2 + 1;\n }\n \n private int distM(int x, int y, int xx, int yy) {\n return abs(x - xx) + abs(y - yy);\n }\n \n private boolean less(int x, int y, int xx, int yy) {\n return x < xx || y > yy;\n }\n \n private int mul(int x, int y) {\n return (int)(1L * x * y % MOD);\n }\n \n \n \n \n private int nBit1(int v) {\n int v0 = v;\n int c = 0;\n while (v != 0) {\n ++c;\n v = v & (v - 1);\n }\n return c;\n }\n \n private long abs(long v) {\n return v > 0 ? v : -v;\n }\n \n private int abs(int v) {\n return v > 0 ? v : -v;\n }\n \n private int common(int v) {\n int c = 0;\n while (v != 1) {\n v = (v >>> 1);\n ++c;\n }\n \n return c;\n }\n \n private void reverse(char[] a, int i, int j) {\n while (i < j) {\n swap(a, i++, j--);\n }\n }\n \n private void swap(char[] a, int i, int j) {\n char t = a[i];\n a[i] = a[j];\n a[j] = t;\n }\n \n private int gcd(int x, int y) {\n if (y == 0) return x;\n return gcd(y, x % y);\n }\n private long gcd(long x, long y) {\n if (y == 0) return x;\n return gcd(y, x % y);\n }\n private int max(int a, int b) {\n return a > b ? a : b;\n }\n \n private long max(long a, long b) {\n return a > b ? a : b;\n }\n \n private int min(int a, int b) {\n return a > b ? b : a;\n }\n \n private long min(long a, long b) {\n return a > b ? b : a;\n }\n \n static class FastReader\n {\n BufferedReader br;\n StringTokenizer st;\n \n public FastReader(BufferedReader in)\n { \n br = in;\n }\n \n String next()\n {\n while (st == null || !st.hasMoreElements())\n {\n try\n {\n String line = br.readLine();\n if (line == null || line.length() == 0) return \"\";\n st = new StringTokenizer(line);\n }\n catch (IOException e)\n {\n return \"\";\n //e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n int nextInt()\n {\n return Integer.parseInt(next());\n }\n \n long nextLong()\n {\n return Long.parseLong(next());\n }\n \n double nextDouble()\n {\n return Double.parseDouble(next());\n }\n \n String nextLine()\n {\n String str = \"\";\n try\n {\n str = br.readLine();\n }\n catch (IOException e)\n {\n return null;\n //e.printStackTrace();\n }\n return str;\n }\n }\n}", "lang_cluster": "Java", "tags": ["math", "binary search", "dp", "combinatorics"], "code_uid": "f7084f16468bcbc6cf6d968b9a2432ea", "src_uid": "783c4b3179c558369f94f4a16ac562d4", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "\nimport java.util.*;\nimport java.math.*;\nimport static java.lang.Character.isDigit;\nimport static java.lang.Character.isLowerCase;\nimport static java.lang.Character.isUpperCase;\nimport static java.lang.Math.*;\nimport static java.math.BigInteger.*;\nimport static java.util.Arrays.*;\nimport static java.util.Collections.*;\nimport static java.lang.Character.isDigit;\n\npublic class Main{\n static void debug(Object...os){\n System.err.println(deepToString(os));\n }\n int[] maxMove=new int[3];\n int[] power=new int[3];\n void run(){\n E init = new E();\n init.xs=new int[3];\n for(int i=0;i<3;i++) {\n init.xs[i]=nextInt();maxMove[i]=nextInt();power[i]=nextInt();\n }\n init.lift=new int[3];\n fill(init.lift,-1);\n init.lifted=new boolean[3];\n init.throwed=new boolean[3];\n init.moved=new boolean[3];\n dfs(init);\n System.out.println(res);\n }\n int res = 0;\n HashSet set=new HashSet();\n void dfs(E e) {\n if(set.contains(e.hash()))return;\n set.add(e.hash());\n if(e.reachable() cand = new ArrayList();\n cand.add(e.xs[i]-maxMove[i]);\n cand.add(e.xs[i]+maxMove[i]);\n for(int j=0;j<3;j++)if(i!=j)cand.add(e.xs[j]-1);\n for(int j=0;j<3;j++)if(i!=j)cand.add(e.xs[j]+1);\n for(int j : cand)if(e.xs[i]-maxMove[i]<=j && j<=e.xs[i]+maxMove[i]) {\n// for(int j=e.xs[i]-maxMove[i];j<=e.xs[i]+maxMove[i];j++) {\n if(j<0)continue;\n E ne = e.myClone();\n ne.xs[i] = j;\n ne.moved[i] = true;\n dfs(ne);\n }\n }\n // lift\n ok=true;\n if(e.throwed[i])ok=false;\n if(e.lift[i]!=-1)ok=false;\n if(e.lifted[i])ok=false;\n if(ok)for(int j=0;j<3;j++)if(i!=j) {\n if(abs(e.xs[i]-e.xs[j])!=1)continue;\n if(e.lifted[j])continue;\n E ne = e.myClone();\n ne.lift[i] = j;\n ne.lifted[j] = true;\n dfs(ne);\n }\n // throw\n ok=true;\n if(e.lifted[i])ok=false;\n if(e.lift[i]==-1)ok=false;\n if(ok) {\n assert !e.throwed[i];\n// ArrayList cand = new ArrayList();\n// cand.add(e.xs[i]-power[i]);\n// cand.add(e.xs[i]+power[i]);\n// for(int j=0;j<3;j++)if(i!=j)cand.add(e.xs[j]-1);\n// for(int j=0;j<3;j++)if(i!=j)cand.add(e.xs[j]+1);\n// for(int j:cand)if(e.xs[i]-power[i]<=j && j<=e.xs[i]+power[i]){\n for(int j=e.xs[i]-power[i];j<=e.xs[i]+power[i];j++) {\n if(j<0)continue;\n E ne = e.myClone();\n ne.xs[ne.lift[i]] = j;\n ne.lifted[ne.lift[i]] = false;\n ne.lift[i] = -1;\n ne.throwed[i] = true;\n dfs(ne);\n }\n }\n }\n }\n \n class E{\n int[] xs;\n int[] lift;\n boolean[] lifted;\n boolean[] moved;\n boolean[] throwed;\n E myClone() {\n E res=new E();\n res.xs = xs.clone();\n res.lift=lift.clone();\n res.lifted=lifted.clone();\n res.moved=moved.clone();\n res.throwed=throwed.clone();\n return res;\n }\n public int reachable(){\n int x=getmaxX();\n for(int i=0;i<3;i++) {\n if(!moved[i])x += maxMove[i];\n if(!throwed[i])x += power[i];\n }\n return x;\n }\n public int getmaxX(){\n int res=Integer.MIN_VALUE;\n for(int x:xs)res=max(res,x);\n return res;\n }\n long hash=-1;\n long hash() {\n if(hash!=-1)return hash;\n hash=0;\n for(int x:xs)hash=hash<<6|x;\n for(int x:lift)hash=hash<<2|x+1;\n for(boolean b:lifted)hash=hash<<1|(b?1:0);\n for(boolean b:moved)hash=hash<<1|(b?1:0);\n for(boolean b:throwed)hash=hash<<1|(b?1:0);\n return hash;\n }\n \n public int hashCode(){\n final int prime=31;\n int result=1;\n result=prime*result+getOuterType().hashCode();\n result=prime*result+Arrays.hashCode(lift);\n result=prime*result+Arrays.hashCode(lifted);\n result=prime*result+Arrays.hashCode(moved);\n result=prime*result+Arrays.hashCode(throwed);\n result=prime*result+Arrays.hashCode(xs);\n return result;\n }\n public String toString(){\n return \"E [lift=\"+Arrays.toString(lift)+\", lifted=\"+Arrays.toString(lifted)+\", moved=\"\n +Arrays.toString(moved)+\", throwed=\"+Arrays.toString(throwed)+\", xs=\"+Arrays.toString(xs)+\"]\";\n }\n public boolean equals(Object obj){\n if(this==obj) return true;\n if(obj==null) return false;\n if(getClass()!=obj.getClass()) return false;\n E other=(E)obj;\n if(!getOuterType().equals(other.getOuterType())) return false;\n if(!Arrays.equals(lift,other.lift)) return false;\n if(!Arrays.equals(lifted,other.lifted)) return false;\n if(!Arrays.equals(moved,other.moved)) return false;\n if(!Arrays.equals(throwed,other.throwed)) return false;\n if(!Arrays.equals(xs,other.xs)) return false;\n return true;\n }\n private Main getOuterType(){\n return Main.this;\n }\n \n }\n \n int nextInt(){\n try{\n int c=System.in.read();\n if(c==-1) return c;\n while(c!='-'&&(c<'0'||'9' ii) {\n tc++;\n tr = ii - tr;\n }\n double rest = tr;\n rest = rest / nk;\n if (rest < minRest) {\n minRest = rest;\n minB = i;\n minA = tc;\n }\n }\n writer.println(minA + \"/\" + minB);\n }\n\n long nod(long a, long b) {\n if (a < b) {\n long t = a;\n a = b;\n b = t;\n }\n if (a % b == 0) {\n return b;\n }\n return nod(b, a % b);\n }\n\n long nok(long a, long b) {\n return (a / nod(a, b)) * b;\n }\n\n public static void main(String[] args) {\n new Main().run();\n }\n\n BufferedReader reader;\n StringTokenizer tokenizer;\n PrintWriter writer;\n\n @Override\n public void run() {\n try {\n reader = new BufferedReader(new InputStreamReader(System.in));\n tokenizer = null;\n writer = new PrintWriter(System.out);\n solve();\n reader.close();\n writer.close();\n }\n catch (Exception e) {\n e.printStackTrace();\n System.exit(1);\n }\n }\n\n private int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n private String nextToken() throws IOException {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(reader.readLine());\n }\n return tokenizer.nextToken();\n }\n\n}\n", "lang_cluster": "Java", "tags": ["two pointers", "implementation", "brute force"], "code_uid": "6ef186adce8736c49d1a8da167cf84bd", "src_uid": "827bc6f120aff6a6f04271bc84e863ee", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n/**\n * Created by abgupta on 3/19/17.\n */\npublic class C_652_A {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int h1 = in.nextInt();\n int h2 = in.nextInt();\n\n\n int a = in.nextInt();\n int b = in.nextInt();\n int dh = h2-h1;\n\n if (a<=b) {\n if (8*a= dh;\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "5b01a9151088a1651e06d6b1540f401a", "src_uid": "2c39638f07c3d789ba4c323a205487d7", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "\n import java.util.*;\n\n \npublic class BruteForce{\n \n public static Scanner in=new Scanner(System.in);\n public static void main(String[]args){\n long n=in.nextLong();\n long ans=1+(6*n)+((n*(n-1))/2)*6;\n System.out.println(ans);\n }\n \n}", "lang_cluster": "Java", "tags": ["math"], "code_uid": "0e2325f40d9a6b9c48d6fbe53012b17c", "src_uid": "c046895a90f2e1381a7c1867020453bd", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.util.concurrent.*;\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n Solver solver = new Solver();\n solver.solve(in, out);\n out.close();\n }\n static class Solver {\n public void solve(InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int[] a = new int[n];\n for (int i = 0; i < n; ++i) {\n a[i] = in.nextInt();\n }\n Arrays.sort(a);\n long start = System.currentTimeMillis();\n long end = start + 1000; // 1000 ms/sec\n long tmp = 1;\n while (System.currentTimeMillis() < end) {\n ++tmp;\n }\n for (int t : a) {\n out.print(t + \" \");\n }\n }\n static String reverse(String s) {\n String rev = \"\";\n for (int i = 0; i < s.length(); ++i) {\n rev += s.charAt(s.length() - i - 1);\n }\n return rev;\n }\n } // wubba lubba dub dub\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreElements()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n public int nextInt() {\n return Integer.parseInt(next());\n }\n public long nextLong() {\n return Long.parseLong(next());\n }\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "2a4299a75e396fbb77e5cf02dfe85998", "src_uid": "29e481abfa9ad1f18e6157c9e833f16e", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class TaskA {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int l = sc.nextInt();\n int r = sc.nextInt();\n long count = Arrays.stream(CACHE).filter(i -> l<= i && i <= r).count();\n System.out.println(count);\n }\n\n private static final int[] CACHE = new int[] {\n 1,\n 2,\n 3,\n 4,\n 6,\n 8,\n 9,\n 12,\n 16,\n 18,\n 24,\n 27,\n 32,\n 36,\n 48,\n 54,\n 64,\n 72,\n 81,\n 96,\n 108,\n 128,\n 144,\n 162,\n 192,\n 216,\n 243,\n 256,\n 288,\n 324,\n 384,\n 432,\n 486,\n 512,\n 576,\n 648,\n 729,\n 768,\n 864,\n 972,\n 1024,\n 1152,\n 1296,\n 1458,\n 1536,\n 1728,\n 1944,\n 2048,\n 2187,\n 2304,\n 2592,\n 2916,\n 3072,\n 3456,\n 3888,\n 4096,\n 4374,\n 4608,\n 5184,\n 5832,\n 6144,\n 6561,\n 6912,\n 7776,\n 8192,\n 8748,\n 9216,\n 10368,\n 11664,\n 12288,\n 13122,\n 13824,\n 15552,\n 16384,\n 17496,\n 18432,\n 19683,\n 20736,\n 23328,\n 24576,\n 26244,\n 27648,\n 31104,\n 32768,\n 34992,\n 36864,\n 39366,\n 41472,\n 46656,\n 49152,\n 52488,\n 55296,\n 59049,\n 62208,\n 65536,\n 69984,\n 73728,\n 78732,\n 82944,\n 93312,\n 98304,\n 104976,\n 110592,\n 118098,\n 124416,\n 131072,\n 139968,\n 147456,\n 157464,\n 165888,\n 177147,\n 186624,\n 196608,\n 209952,\n 221184,\n 236196,\n 248832,\n 262144,\n 279936,\n 294912,\n 314928,\n 331776,\n 354294,\n 373248,\n 393216,\n 419904,\n 442368,\n 472392,\n 497664,\n 524288,\n 531441,\n 559872,\n 589824,\n 629856,\n 663552,\n 708588,\n 746496,\n 786432,\n 839808,\n 884736,\n 944784,\n 995328,\n 1048576,\n 1062882,\n 1119744,\n 1179648,\n 1259712,\n 1327104,\n 1417176,\n 1492992,\n 1572864,\n 1594323,\n 1679616,\n 1769472,\n 1889568,\n 1990656,\n 2097152,\n 2125764,\n 2239488,\n 2359296,\n 2519424,\n 2654208,\n 2834352,\n 2985984,\n 3145728,\n 3188646,\n 3359232,\n 3538944,\n 3779136,\n 3981312,\n 4194304,\n 4251528,\n 4478976,\n 4718592,\n 4782969,\n 5038848,\n 5308416,\n 5668704,\n 5971968,\n 6291456,\n 6377292,\n 6718464,\n 7077888,\n 7558272,\n 7962624,\n 8388608,\n 8503056,\n 8957952,\n 9437184,\n 9565938,\n 10077696,\n 10616832,\n 11337408,\n 11943936,\n 12582912,\n 12754584,\n 13436928,\n 14155776,\n 14348907,\n 15116544,\n 15925248,\n 16777216,\n 17006112,\n 17915904,\n 18874368,\n 19131876,\n 20155392,\n 21233664,\n 22674816,\n 23887872,\n 25165824,\n 25509168,\n 26873856,\n 28311552,\n 28697814,\n 30233088,\n 31850496,\n 33554432,\n 34012224,\n 35831808,\n 37748736,\n 38263752,\n 40310784,\n 42467328,\n 43046721,\n 45349632,\n 47775744,\n 50331648,\n 51018336,\n 53747712,\n 56623104,\n 57395628,\n 60466176,\n 63700992,\n 67108864,\n 68024448,\n 71663616,\n 75497472,\n 76527504,\n 80621568,\n 84934656,\n 86093442,\n 90699264,\n 95551488,\n 100663296,\n 102036672,\n 107495424,\n 113246208,\n 114791256,\n 120932352,\n 127401984,\n 129140163,\n 134217728,\n 136048896,\n 143327232,\n 150994944,\n 153055008,\n 161243136,\n 169869312,\n 172186884,\n 181398528,\n 191102976,\n 201326592,\n 204073344,\n 214990848,\n 226492416,\n 229582512,\n 241864704,\n 254803968,\n 258280326,\n 268435456,\n 272097792,\n 286654464,\n 301989888,\n 306110016,\n 322486272,\n 339738624,\n 344373768,\n 362797056,\n 382205952,\n 387420489,\n 402653184,\n 408146688,\n 429981696,\n 452984832,\n 459165024,\n 483729408,\n 509607936,\n 516560652,\n 536870912,\n 544195584,\n 573308928,\n 603979776,\n 612220032,\n 644972544,\n 679477248,\n 688747536,\n 725594112,\n 764411904,\n 774840978,\n 805306368,\n 816293376,\n 859963392,\n 905969664,\n 918330048,\n 967458816,\n 1019215872,\n 1033121304,\n 1073741824,\n 1088391168,\n 1146617856,\n 1162261467,\n 1207959552,\n 1224440064,\n 1289945088,\n 1358954496,\n 1377495072,\n 1451188224,\n 1528823808,\n 1549681956,\n 1610612736,\n 1632586752,\n 1719926784,\n 1811939328,\n 1836660096,\n 1934917632\n };\n\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "ad8ebd4439dccf34313bb3365945d1bc", "src_uid": "05fac54ed2064b46338bb18f897a4411", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author George Marcus\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tScanner in = new Scanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskC solver = new TaskC();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskC {\n private int[] computer;\n private boolean[] v;\n private int[] allowed;\n private int[] Gin;\n private boolean[][] edge;\n private int N;\n private ArrayList[] graph;\n\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n N = in.nextInt();\n v = new boolean[N + 1];\n allowed = new int[N + 1];\n Gin = new int[N + 1];\n computer = new int[N + 1];\n edge = new boolean[N + 1][N + 1];\n for(int i = 1; i <= N; i++)\n computer[i] = in.nextInt();\n graph = new ArrayList[N + 1];\n for(int i = 1; i <= N; i++)\n graph[i] = new ArrayList();\n int completed = 0;\n int k, t, start = 0;\n for(int i = 1; i <= N; i++) {\n k = in.nextInt();\n for(int j = 0; j < k; j++) {\n t = in.nextInt();\n if(!edge[t][i]) {\n graph[t].add(i);\n Gin[i]++;\n }\n edge[t][i] = true;\n }\n }\n\n int r1 = go(1);\n int r2 = go(2);\n int r3 = go(3);\n\n int res = Math.min(r1, Math.min(r2, r3));\n\n out.print(res);\n\t}\n\n private int go(int start) {\n int comp = start;\n int completed = 0;\n int time = 0;\n boolean reset = false;\n int[] need = new int[N + 1];\n System.arraycopy(Gin, 0, need, 0, N + 1);\n\n while(completed < N) {\n for(int i = 1; i <= N; i++)\n if(need[i] == 0 && computer[i] == comp) {\n need[i] = -1;\n time++;\n completed++;\n\n for(int j = 0; j < graph[i].size(); j++) {\n need[graph[i].get(j)]--;\n if(need[graph[i].get(j)] == 0 && computer[graph[i].get(j)] == comp)\n reset = true;\n }\n\n if(reset)\n i = 0;\n }\n\n time++;\n comp = comp % 3 + 1;\n }\n\n return time - 1;\n }\n\n}\n\n", "lang_cluster": "Java", "tags": ["brute force", "greedy"], "code_uid": "95a2949aaba08bedb05273422507d464", "src_uid": "be42e213ff43e303e475d77a9560367f", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "//*******************************************************************\n// Welcome to CompileJava!\n// If you experience any issues, please contact us ('More Info') -->\n//*******************************************************************\n\nimport java.util.*;\nimport java.io.*;\n\npublic class CF328B {\npublic static void main(String[] args) throws IOException {\nBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\nPrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));\n\nString line = br.readLine();\nint[] createCount = new int[10];\nfor (int i = 0; i < line.length(); i++) {\ncreateCount[line.charAt(i) - '0']++;\n}\ncreateCount[2] += createCount[5];\ncreateCount[6] += createCount[9];\ncreateCount[5] = 0;\ncreateCount[9] = 0;\n\nint[] count = new int[10];\nline = br.readLine();\nfor (int i = 0; i < line.length(); i++) {\ncount[line.charAt(i) - '0']++;\n}\ncount[2] += count[5];\ncount[6] += count[9];\ncount[5] = 0;\ncount[9] = 0;\n\nint min = Integer.MAX_VALUE;\nfor (int i = 0; i < 10; i++) {\nif (createCount[i] == 0) continue;\nmin = Math.min(min, count[i] / createCount[i]);\n} \n\npw.println(min);\npw.close();\n}\n}\n\n\n\n/*\nimport java.lang.Math; // headers MUST be above the first class\n\n// one class needs to have a main() method\npublic ss HelloWorld\n{\n // arguments are passed using the text field below this editor\n public static void main(String[] args)\n {\n OtherClass myObject = new OtherClass(\"Hello World!\");\n System.out.print(myObject);\n }\n}\n\n// you cn add other public classes to this editor in any order\npublic ass OtherClass\n{\n private String message;\n private boolean answer = false;\n public OtherClass(String input)\n {\n message = \"Why, \" + input + \" Isn't this something?\";\n }\n public String toString()\n {\n return message;\n }\n}\n*/", "lang_cluster": "Java", "tags": ["greedy"], "code_uid": "7d73a320ce472fc5f712d55238c0d729", "src_uid": "72a196044787cb8dbd8d350cb60ccc32", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "//created by Whiplash99\nimport java.io.*;\nimport java.util.*;\npublic class A\n{\n private static ArrayList list, subsets;\n private static void allSubsets(int i, long sum)\n {\n if(i==list.size())\n {\n subsets.add(sum);\n return;\n }\n\n allSubsets(i+1,sum+list.get(i));\n allSubsets(i+1,sum);\n }\n private static boolean check(long M, long W, long x)\n {\n if(x==M) return true;\n\n boolean flag=true;\n x+=M;\n while (x>0)\n {\n if(x%W>1)\n {\n flag=false;\n break;\n }\n x/=W;\n }\n\n return flag;\n }\n public static void main(String[] args) throws Exception\n {\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\n int i,N;\n\n String[] s=br.readLine().trim().split(\" \");\n long W=Long.parseLong(s[0]);\n long M=Long.parseLong(s[1]);\n\n if(W==2)\n {\n System.out.println(\"YES\");\n System.exit(0);\n }\n\n list=new ArrayList<>();\n list.add(1L); list.add(W);\n\n long cur=W;\n final long MAX=(long)(1e10);\n\n while (true)\n {\n cur*=W;\n if(cur<0||cur>MAX) break;\n\n list.add(cur);\n }\n\n subsets = new ArrayList<>();\n allSubsets(0,0);\n\n boolean flag=false;\n for(long x: subsets)\n {\n flag |= check(M, W, x);\n if(flag) break;\n }\n\n System.out.println(flag?\"YES\":\"NO\");\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "math", "dp", "meet-in-the-middle", "greedy", "number theory"], "code_uid": "2c9811ad414d99b5438a138d9fcf50ef", "src_uid": "a74adcf0314692f8ac95f54d165d9582", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n\n/**\n *\n * @author Ivan\n */\npublic class secondProblem {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) throws IOException {\n Reader.init(System.in);\n long players=Reader.nextInt();\n long teams=Reader.nextInt();\n long max,min;\n // long[] maxTeams=new long[teams];\n max=(players-teams+1)*(players-teams)/2;\n // int[] minTeams=new int[teams];\n long mem=players/teams;\n long temp=teams;\n players-=mem*teams;\n min=0;\n if(players!=0)\n min+=players*(mem+1)*mem/2;\n min+=(temp-players)*mem*(mem-1)/2;\n // for(int i=0;i= 18;\n\t\t} else {\n\t\t\tboolean works = false;\n\t\t\tfor (int j = 0; j < 3; j++) {\n\t\t\t\tif (!used[j]) {\n\t\t\t\t\tif (i == 0) {\n\t\t\t\t\t\tint arr = attempt[2] % 4 == 0 ? 1 : 0;\n\t\t\t\t\t\tif (birth[j] > days[arr][attempt[1]-1])\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif (i == 1 && birth[j] > 12)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tused[j] = true;\n\t\t\t\t\tattempt[i] = birth[j];\n\t\t\t\t\tworks |= recurse(i - 1);\n\t\t\t\t\tused[j] = false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn works;\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "ad87f13b691bbacaa520ea7f3a22875d", "src_uid": "5418c98fe362909f7b28f95225837d33", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.Random;\nimport java.util.Map;\nimport java.io.OutputStreamWriter;\nimport java.io.OutputStream;\nimport java.util.stream.LongStream;\nimport java.util.Collection;\nimport java.io.IOException;\nimport java.io.UncheckedIOException;\nimport java.util.stream.Stream;\nimport java.io.Closeable;\nimport java.io.Writer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, new TaskAdapter(), \"\", 1 << 27);\n thread.start();\n thread.join();\n }\n\n static class TaskAdapter implements Runnable {\n @Override\n public void run() {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastInput in = new FastInput(inputStream);\n FastOutput out = new FastOutput(outputStream);\n GXMouseInTheCampus solver = new GXMouseInTheCampus();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class GXMouseInTheCampus {\n LongHashMap mu = new LongHashMap(100000, false);\n LongHashMap euler = new LongHashMap(100000, false);\n long[] primes;\n\n {\n mu.put(1, 1);\n euler.put(1, 1);\n }\n\n public long oneOfPrimeFactor(long x) {\n for (long p : primes) {\n if (x % p == 0) {\n return p;\n }\n }\n return x;\n }\n\n public void populate(long x) {\n long factor = oneOfPrimeFactor(x);\n long cnt = 0;\n long y = x;\n while (y % factor == 0) {\n cnt++;\n y /= factor;\n }\n if (cnt > 1) {\n mu.put(x, 0);\n } else {\n mu.put(x, -mu(y));\n }\n euler.put(x, euler(y) * (x / y - x / y / factor));\n }\n\n public long mu(long x) {\n long ans = mu.getOrDefault(x, -1);\n if (ans == -1) {\n populate(x);\n ans = mu.get(x);\n }\n return ans;\n }\n\n public long euler(long x) {\n long ans = euler.getOrDefault(x, -1);\n if (ans == -1) {\n populate(x);\n ans = euler.get(x);\n }\n return ans;\n }\n\n public void solve(int testNumber, FastInput in, FastOutput out) {\n long m = in.readLong();\n long x = in.readLong();\n\n primes = new LongPollardRho().findAllFactors(m).keySet()\n .stream().mapToLong(Long::longValue).toArray();\n LongList allFactorOfM = new LongList(20000);\n LongList tmpList = new LongList(20000);\n LongList allPossiblePrimeFactor = new LongList();\n for (long p : primes) {\n allPossiblePrimeFactor.add(p);\n allPossiblePrimeFactor.addAll(Factorization.factorizeNumberPrime(p - 1));\n }\n allPossiblePrimeFactor.unique();\n\n collect(allFactorOfM, m, 0);\n LongPower power = new LongPower(ILongModular.getInstance(m));\n\n long total = 1;\n for (int i = 0; i < allFactorOfM.size(); i++) {\n long g = allFactorOfM.get(i);\n if (g == m) {\n continue;\n }\n long mg = m / g;\n tmpList.clear();\n collect(tmpList, mg, 0);\n long cnt = 0;\n for (int j = tmpList.size() - 1; j >= 0; j--) {\n long t = tmpList.get(j);\n cnt += mu(t) * ((m - 1) / (t * g));\n }\n\n tmpList.clear();\n long euler = euler(mg);\n LongList primeFactors = tmpList;\n for (int j = 0; j < allPossiblePrimeFactor.size(); j++) {\n long p = allPossiblePrimeFactor.get(j);\n if (euler % p == 0) {\n primeFactors.add(p);\n }\n }\n\n long n = euler;\n for (int j = 0; j < primeFactors.size(); j++) {\n long p = primeFactors.get(j);\n while (n % p == 0 && power.pow(x, n / p) % mg == 1) {\n n /= p;\n }\n }\n\n if (cnt % n != 0) {\n throw new IllegalStateException();\n }\n total += cnt / n;\n }\n\n out.println(total);\n }\n\n public void collect(LongList list, long x, int i) {\n if (i == primes.length) {\n list.add(x);\n return;\n }\n collect(list, x, i + 1);\n while (x % primes[i] == 0) {\n x /= primes[i];\n collect(list, x, i + 1);\n }\n }\n\n }\n\n static class DigitUtils {\n private DigitUtils() {\n }\n\n public static long round(double x) {\n if (x >= 0) {\n return (long) (x + 0.5);\n } else {\n return (long) (x - 0.5);\n }\n }\n\n public static long mod(long x, long mod) {\n x %= mod;\n if (x < 0) {\n x += mod;\n }\n return x;\n }\n\n public static long mulMod(long a, long b, long mod) {\n long k = DigitUtils.round((double) a / mod * b);\n return DigitUtils.mod(a * b - k * mod, mod);\n }\n\n }\n\n static class FastOutput implements AutoCloseable, Closeable, Appendable {\n private StringBuilder cache = new StringBuilder(10 << 20);\n private final Writer os;\n\n public FastOutput append(CharSequence csq) {\n cache.append(csq);\n return this;\n }\n\n public FastOutput append(CharSequence csq, int start, int end) {\n cache.append(csq, start, end);\n return this;\n }\n\n public FastOutput(Writer os) {\n this.os = os;\n }\n\n public FastOutput(OutputStream os) {\n this(new OutputStreamWriter(os));\n }\n\n public FastOutput append(char c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput println(long c) {\n cache.append(c);\n println();\n return this;\n }\n\n public FastOutput println() {\n cache.append(System.lineSeparator());\n return this;\n }\n\n public FastOutput flush() {\n try {\n os.append(cache);\n os.flush();\n cache.setLength(0);\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n return this;\n }\n\n public void close() {\n flush();\n try {\n os.close();\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n public String toString() {\n return cache.toString();\n }\n\n }\n\n static class LongPower {\n final ILongModular modular;\n\n public LongPower(ILongModular modular) {\n this.modular = modular;\n }\n\n public long pow(long x, long n) {\n if (n == 0) {\n return 1;\n }\n long r = pow(x, n >> 1);\n r = modular.mul(r, r);\n if ((n & 1) == 1) {\n r = modular.mul(r, x);\n }\n return r;\n }\n\n }\n\n static class Factorization {\n public static LongList factorizeNumberPrime(long x) {\n LongList ans = new LongList();\n for (long i = 2; i * i <= x; i++) {\n if (x % i != 0) {\n continue;\n }\n ans.add(i);\n while (x % i == 0) {\n x /= i;\n }\n }\n if (x > 1) {\n ans.add(x);\n }\n return ans;\n }\n\n }\n\n static class LongHashMap {\n private int[] slot;\n private int[] next;\n private long[] keys;\n private long[] values;\n private int alloc;\n private boolean[] removed;\n private int mask;\n private int size;\n private boolean rehash;\n\n public LongHashMap(int cap, boolean rehash) {\n this.mask = (1 << (32 - Integer.numberOfLeadingZeros(cap - 1))) - 1;\n slot = new int[mask + 1];\n next = new int[cap + 1];\n keys = new long[cap + 1];\n values = new long[cap + 1];\n removed = new boolean[cap + 1];\n this.rehash = rehash;\n }\n\n private void doubleCapacity() {\n int newSize = Math.max(next.length + 10, next.length * 2);\n next = Arrays.copyOf(next, newSize);\n keys = Arrays.copyOf(keys, newSize);\n values = Arrays.copyOf(values, newSize);\n removed = Arrays.copyOf(removed, newSize);\n }\n\n public void alloc() {\n alloc++;\n if (alloc >= next.length) {\n doubleCapacity();\n }\n next[alloc] = 0;\n removed[alloc] = false;\n size++;\n }\n\n private void rehash() {\n int[] newSlots = new int[Math.max(16, slot.length * 2)];\n int newMask = newSlots.length - 1;\n for (int i = 0; i < slot.length; i++) {\n if (slot[i] == 0) {\n continue;\n }\n int head = slot[i];\n while (head != 0) {\n int n = next[head];\n int s = hash(keys[head]) & newMask;\n next[head] = newSlots[s];\n newSlots[s] = head;\n head = n;\n }\n }\n this.slot = newSlots;\n this.mask = newMask;\n }\n\n private int hash(long x) {\n int h = Long.hashCode(x);\n return h ^ (h >>> 16);\n }\n\n public void put(long x, long y) {\n put(x, y, true);\n }\n\n public void put(long x, long y, boolean cover) {\n int h = hash(x);\n int s = h & mask;\n if (slot[s] == 0) {\n alloc();\n slot[s] = alloc;\n keys[alloc] = x;\n values[alloc] = y;\n } else {\n int index = findIndexOrLastEntry(s, x);\n if (keys[index] != x) {\n alloc();\n next[index] = alloc;\n keys[alloc] = x;\n values[alloc] = y;\n } else if (cover) {\n values[index] = y;\n }\n }\n if (rehash && size >= slot.length) {\n rehash();\n }\n }\n\n public long getOrDefault(long x, long def) {\n int h = hash(x);\n int s = h & mask;\n if (slot[s] == 0) {\n return def;\n }\n int index = findIndexOrLastEntry(s, x);\n return keys[index] == x ? values[index] : def;\n }\n\n public long get(long x) {\n return getOrDefault(x, 0);\n }\n\n private int findIndexOrLastEntry(int s, long x) {\n int iter = slot[s];\n while (keys[iter] != x) {\n if (next[iter] != 0) {\n iter = next[iter];\n } else {\n return iter;\n }\n }\n return iter;\n }\n\n public LongEntryIterator iterator() {\n return new LongEntryIterator() {\n int index = 1;\n int readIndex = -1;\n\n\n public boolean hasNext() {\n while (index <= alloc && removed[index]) {\n index++;\n }\n return index <= alloc;\n }\n\n\n public long getEntryKey() {\n return keys[readIndex];\n }\n\n\n public long getEntryValue() {\n return values[readIndex];\n }\n\n\n public void next() {\n if (!hasNext()) {\n throw new IllegalStateException();\n }\n readIndex = index;\n index++;\n }\n };\n }\n\n public String toString() {\n LongEntryIterator iterator = iterator();\n StringBuilder builder = new StringBuilder(\"{\");\n while (iterator.hasNext()) {\n iterator.next();\n builder.append(iterator.getEntryKey()).append(\"->\").append(iterator.getEntryValue()).append(',');\n }\n if (builder.charAt(builder.length() - 1) == ',') {\n builder.setLength(builder.length() - 1);\n }\n builder.append('}');\n return builder.toString();\n }\n\n }\n\n static class LongPollardRho {\n LongMillerRabin mr = new LongMillerRabin();\n ILongModular modular;\n Random random = new Random();\n\n public long findFactor(long n) {\n if (mr.mr(n, 3)) {\n return n;\n }\n modular = ILongModular.getInstance(n);\n while (true) {\n long f = findFactor0((long) (random.nextDouble() * n), (long) (random.nextDouble() * n), n);\n if (f != -1) {\n return f;\n }\n }\n }\n\n private long findFactor0(long x, long c, long n) {\n long xi = x;\n long xj = x;\n int j = 2;\n int i = 1;\n while (i < n) {\n i++;\n xi = modular.plus(modular.mul(xi, xi), c);\n long g = GCDs.gcd(n, Math.abs(xi - xj));\n if (g != 1 && g != n) {\n return g;\n }\n if (i == j) {\n j = j << 1;\n xj = xi;\n }\n }\n return -1;\n }\n\n public Map findAllFactors(long n) {\n Map map = new HashMap();\n findAllFactors(map, n);\n return map;\n }\n\n private void findAllFactors(Map map, long n) {\n if (n == 1) {\n return;\n }\n long f = findFactor(n);\n if (f == n) {\n Long value = map.get(f);\n if (value == null) {\n value = 1L;\n }\n map.put(f, value * f);\n return;\n }\n findAllFactors(map, f);\n findAllFactors(map, n / f);\n }\n\n }\n\n static class GCDs {\n private GCDs() {\n }\n\n public static long gcd(long a, long b) {\n return a >= b ? gcd0(a, b) : gcd0(b, a);\n }\n\n private static long gcd0(long a, long b) {\n return b == 0 ? a : gcd0(b, a % b);\n }\n\n }\n\n static class FastInput {\n private final InputStream is;\n private byte[] buf = new byte[1 << 13];\n private int bufLen;\n private int bufOffset;\n private int next;\n\n public FastInput(InputStream is) {\n this.is = is;\n }\n\n private int read() {\n while (bufLen == bufOffset) {\n bufOffset = 0;\n try {\n bufLen = is.read(buf);\n } catch (IOException e) {\n bufLen = -1;\n }\n if (bufLen == -1) {\n return -1;\n }\n }\n return buf[bufOffset++];\n }\n\n public void skipBlank() {\n while (next >= 0 && next <= 32) {\n next = read();\n }\n }\n\n public long readLong() {\n int sign = 1;\n\n skipBlank();\n if (next == '+' || next == '-') {\n sign = next == '+' ? 1 : -1;\n next = read();\n }\n\n long val = 0;\n if (sign == 1) {\n while (next >= '0' && next <= '9') {\n val = val * 10 + next - '0';\n next = read();\n }\n } else {\n while (next >= '0' && next <= '9') {\n val = val * 10 - next + '0';\n next = read();\n }\n }\n\n return val;\n }\n\n }\n\n static interface LongEntryIterator {\n boolean hasNext();\n\n void next();\n\n long getEntryKey();\n\n long getEntryValue();\n\n }\n\n static class LongModular implements ILongModular {\n final long m;\n\n public LongModular(long m) {\n this.m = m;\n }\n\n public long mul(long a, long b) {\n return b == 0 ? 0 : ((mul(a, b >> 1) << 1) % m + a * (b & 1)) % m;\n }\n\n public long plus(long a, long b) {\n return valueOf(a + b);\n }\n\n public long valueOf(long a) {\n a %= m;\n if (a < 0) {\n a += m;\n }\n return a;\n }\n\n }\n\n static class LongMillerRabin {\n ILongModular modular;\n LongPower power;\n Random random = new Random();\n\n public boolean mr(long n, int s) {\n if (n <= 1) {\n return false;\n }\n if (n == 2) {\n return true;\n }\n if (n % 2 == 0) {\n return false;\n }\n modular = ILongModular.getInstance(n);\n power = new LongPower(modular);\n for (int i = 0; i < s; i++) {\n long x = (long) (random.nextDouble() * (n - 2) + 2);\n if (!mr0(x, n)) {\n return false;\n }\n }\n return true;\n }\n\n private boolean mr0(long x, long n) {\n long exp = n - 1;\n while (true) {\n long y = power.pow(x, exp);\n if (y != 1 && y != n - 1) {\n return false;\n }\n if (y != 1 || exp % 2 == 1) {\n break;\n }\n exp = exp / 2;\n }\n return true;\n }\n\n }\n\n static class LongModularDanger implements ILongModular {\n final long m;\n\n public LongModularDanger(long m) {\n this.m = m;\n }\n\n public long mul(long a, long b) {\n return DigitUtils.mulMod(a, b, m);\n }\n\n public long plus(long a, long b) {\n return valueOf(a + b);\n }\n\n public long valueOf(long a) {\n a %= m;\n if (a < 0) {\n a += m;\n }\n return a;\n }\n\n }\n\n static class LongList implements Cloneable {\n private int size;\n private int cap;\n private long[] data;\n private static final long[] EMPTY = new long[0];\n\n public LongList(int cap) {\n this.cap = cap;\n if (cap == 0) {\n data = EMPTY;\n } else {\n data = new long[cap];\n }\n }\n\n public LongList(LongList list) {\n this.size = list.size;\n this.cap = list.cap;\n this.data = Arrays.copyOf(list.data, size);\n }\n\n public LongList() {\n this(0);\n }\n\n public void ensureSpace(int req) {\n if (req > cap) {\n while (cap < req) {\n cap = Math.max(cap + 10, 2 * cap);\n }\n data = Arrays.copyOf(data, cap);\n }\n }\n\n private void checkRange(int i) {\n if (i < 0 || i >= size) {\n throw new ArrayIndexOutOfBoundsException();\n }\n }\n\n public long get(int i) {\n checkRange(i);\n return data[i];\n }\n\n public void add(long x) {\n ensureSpace(size + 1);\n data[size++] = x;\n }\n\n public void addAll(long[] x, int offset, int len) {\n ensureSpace(size + len);\n System.arraycopy(x, offset, data, size, len);\n size += len;\n }\n\n public void addAll(LongList list) {\n addAll(list.data, 0, list.size);\n }\n\n public void sort() {\n if (size <= 1) {\n return;\n }\n Randomized.shuffle(data, 0, size);\n Arrays.sort(data, 0, size);\n }\n\n public void unique() {\n if (size <= 1) {\n return;\n }\n\n sort();\n int wpos = 1;\n for (int i = 1; i < size; i++) {\n if (data[i] != data[wpos - 1]) {\n data[wpos++] = data[i];\n }\n }\n size = wpos;\n }\n\n public int size() {\n return size;\n }\n\n public long[] toArray() {\n return Arrays.copyOf(data, size);\n }\n\n public void clear() {\n size = 0;\n }\n\n public String toString() {\n return Arrays.toString(toArray());\n }\n\n public boolean equals(Object obj) {\n if (!(obj instanceof LongList)) {\n return false;\n }\n LongList other = (LongList) obj;\n return SequenceUtils.equal(data, 0, size - 1, other.data, 0, other.size - 1);\n }\n\n public int hashCode() {\n int h = 1;\n for (int i = 0; i < size; i++) {\n h = h * 31 + Long.hashCode(data[i]);\n }\n return h;\n }\n\n public LongList clone() {\n LongList ans = new LongList();\n ans.addAll(this);\n return ans;\n }\n\n }\n\n static class SequenceUtils {\n public static boolean equal(long[] a, int al, int ar, long[] b, int bl, int br) {\n if ((ar - al) != (br - bl)) {\n return false;\n }\n for (int i = al, j = bl; i <= ar; i++, j++) {\n if (a[i] != b[j]) {\n return false;\n }\n }\n return true;\n }\n\n }\n\n static class Randomized {\n private static Random random = new Random(0);\n\n public static void shuffle(long[] data, int from, int to) {\n to--;\n for (int i = from; i <= to; i++) {\n int s = nextInt(i, to);\n long tmp = data[i];\n data[i] = data[s];\n data[s] = tmp;\n }\n }\n\n public static int nextInt(int l, int r) {\n return random.nextInt(r - l + 1) + l;\n }\n\n }\n\n static interface ILongModular {\n long plus(long a, long b);\n\n long mul(long a, long b);\n\n static ILongModular getInstance(long mod) {\n //return new LongModularDanger(mod);\n return mod <= (1L << 54) ? new LongModularDanger(mod) : new LongModular(mod);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["math", "number theory", "bitmasks"], "code_uid": "49fe9838e707d51b2cdd63a6c6536535", "src_uid": "c2dd6de750812d6213c770b3587d8fcb", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.BufferedReader;\r\nimport java.io.InputStreamReader;\r\nimport java.math.BigInteger;\r\nimport java.util.StringTokenizer;\r\n\r\npublic class Task_1749_D {\r\n\r\n public static final long MOD = 998244353L;\r\n public static final BigInteger MOD_BIG = BigInteger.valueOf(MOD);\r\n\r\n public static void main(String[] args) throws Exception {\r\n try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {\r\n StringTokenizer tok = new StringTokenizer(br.readLine());\r\n int n = Integer.parseInt(tok.nextToken());\r\n long m = Long.parseLong(tok.nextToken());\r\n\r\n BigInteger result = BigInteger.ZERO;\r\n BigInteger mBig = BigInteger.valueOf(m);\r\n BigInteger currValue = BigInteger.valueOf(m);\r\n long currDiv = 1L;\r\n boolean[] erat = eratosthenes(n);\r\n BigInteger total = BigInteger.valueOf(m);\r\n for (int i = 2; i <= n; i++) {\r\n total = total.multiply(mBig).remainder(MOD_BIG).add(MOD_BIG);\r\n if (!erat[i]) {\r\n currDiv *= i;\r\n }\r\n currValue = currValue.multiply(BigInteger.valueOf(m / currDiv)).remainder(MOD_BIG);\r\n result = result.add(total).subtract(currValue).remainder(MOD_BIG);\r\n }\r\n\r\n System.out.println(result.longValue());\r\n }\r\n }\r\n\r\n private static boolean[] eratosthenes(int n) {\r\n boolean[] res = new boolean[n + 1];\r\n for (int i = 2; i * i <= n ; i++) {\r\n if(!res[i]) {\r\n for (int j = i * i; j <= n ; j += i) {\r\n res[j] = true;\r\n }\r\n }\r\n }\r\n return res;\r\n }\r\n}\r\n", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics", "number theory"], "code_uid": "326292a9a8cc0ef28d00762e6f58b2f2", "src_uid": "0fdd91ed33431848614075ebe9d2ee68", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.StringTokenizer;\n\n\npublic class ivanTheFool {\n public static long mod = 1000000007;\n public static void fout(long x){\n System.out.println(x);\n }\n /**-----------fast reader------------*/\n static class FastReader \n { \n BufferedReader br; \n StringTokenizer st; \n \n public FastReader() \n { \n br = new BufferedReader(new\n InputStreamReader(System.in)); \n } \n \n String next() \n { \n while (st == null || !st.hasMoreElements()) \n { \n try\n { \n st = new StringTokenizer(br.readLine()); \n } \n catch (IOException e) \n { \n e.printStackTrace(); \n } \n } \n return st.nextToken(); \n } \n \n int nextInt() \n { \n return Integer.parseInt(next()); \n } \n \n long nextLong() \n { \n return Long.parseLong(next()); \n } \n \n double nextDouble() \n { \n return Double.parseDouble(next()); \n } \n \n String nextLine() \n { \n String str = \"\"; \n try\n { \n str = br.readLine(); \n } \n catch (IOException e) \n { \n e.printStackTrace(); \n } \n return str; \n } \n } \n /**-----end of fast reader----------------*/\n\n public static long pmod(long x,long y){\n long r = 1;\n while(y > 0){\n if(y%2 == 1){\n r = (r * x)%mod;\n }\n x = (x * x)%mod;\n y >>= 1;\n }\n return r;\n }\n\n public static void main(String[] args) {\n FastReader rd = new FastReader();\n long n,m;\n n = rd.nextLong();\n m = rd.nextLong();\n long answer = 0;\n long []fact = new long[200000];\n fact[0] = 1;\n for(long i = 1;i<200000;++i){\n fact[(int)i] = (fact[(int)i-1]*i)%mod;\n }\n answer += 2;//all adj cells are different\n if(m >= 2){\n for(long blk = 1 ; blk <= (m/2);blk++){\n long bins = m - (2*blk) + 1;\n long sub = (fact[(int)(bins + blk -1)]*pmod(fact[(int)blk],mod-(long)2))%mod;\n sub = (sub * pmod(fact[(int)bins-1],mod-(long)2))%mod;\n sub = (2 * sub)%mod;\n //fout(sub);\n answer = (answer + sub)%mod;\n }\n }\n if(n >= 2){\n for(long blk = 1 ; blk <= (n/2);blk++){\n long bins = n - (2*blk) + 1;\n long sub = (fact[(int)(bins + blk -1)]*pmod(fact[(int)blk],mod-(long)2))%mod;\n sub = (sub * pmod(fact[(int)bins-1],mod-(long)2))%mod;\n sub = (2 * sub)%mod;\n answer = (answer + sub)%mod;\n }\n }\n // if(m == 1 ^ n == 1){\n // answer = (answer + 2)%mod;\n // }\n fout(answer);\n }\n}", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics"], "code_uid": "4e760af9000a875cd4c60edd15d6c42f", "src_uid": "0f1ab296cbe0952faa904f2bebe0567b", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF1342E extends PrintWriter {\n\tCF1342E() { super(System.out, true); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1342E o = new CF1342E(); o.main(); o.flush();\n\t}\n\n\tstatic final int MD = 998244353;\n\tint[] ff, gg;\n\tlong power(int a, int k) {\n\t\tif (k == 0)\n\t\t\treturn 1;\n\t\tlong p = power(a, k >> 1);\n\t\tp = p * p % MD;\n\t\tif ((k & 1) == 1)\n\t\t\tp = p * a % MD;\n\t\treturn p;\n\t}\n\tlong ch(int n, int k) {\n\t\treturn (long) ff[n] * gg[k] % MD * gg[n - k] % MD;\n\t}\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tlong k_ = sc.nextLong();\n\t\tif (k_ >= n) {\n\t\t\tprintln(0);\n\t\t\treturn;\n\t\t}\n\t\tint c = n - (int) k_;\n\t\tff = new int[n + n];\n\t\tgg = new int[n + n];\n\t\tfor (int f = 1, i = 0; i < n + n; i++) {\n\t\t\tgg[i] = (int) power(ff[i] = f, MD - 2);\n\t\t\tf = (int) ((long) f * (i + 1) % MD);\n\t\t}\n\t\tlong ans = 0;\n\t\tfor (int a = 1; a <= c; a++) {\n\t\t\tlong x = power(a, n) * ch(c, a) % MD;\n\t\t\tans += (c - a) % 2 == 0 ? x : -x;\n\t\t}\n\t\tif ((ans %= MD) < 0)\n\t\t\tans += MD;\n\t\tans = ans * ch(n, c) % MD;\n\t\tif (k_ > 0)\n\t\t\tans = ans * 2 % MD;\n\t\tprintln(ans);\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "combinatorics", "fft"], "code_uid": "36737aa9f67a12a7762fc7250dda7c95", "src_uid": "6c1a9aaa7bdd7de97220b8c6d35740cc", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.*;\n\npublic class B_189_Counting_Rhombi {\n public static void main(String[] args){\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt(),m=sc.nextInt();\n long ans=0;\n for (int i=2;i<=n;i+=2){\n for (int j=2;j<=m;j+=2){\n ans+=(n-i+1)*(m-j+1);\n }\n }\n System.out.println(ans);\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "math"], "code_uid": "1a1ec671afa84cf5008eb3fadc66dfdc", "src_uid": "42454dcf7d073bf12030367eb094eb8c", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Jialin Ouyang (Jialin.Ouyang@gmail.com)\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n QuickScanner in = new QuickScanner(inputStream);\n QuickWriter out = new QuickWriter(outputStream);\n TaskB solver = new TaskB();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskB {\n char[][] board;\n\n public void solve(int testNumber, QuickScanner in, QuickWriter out) {\n board = new char[9][9];\n for (int i = 0; i < 9; ++i)\n for (int j = 0; j < 9; ++j) {\n board[i][j] = (char) in.nextNonSpaceChar();\n }\n int x = (in.nextInt() - 1) % 3 * 3;\n int y = (in.nextInt() - 1) % 3 * 3;\n int count = 0;\n if (hasEmpty(x, y)) {\n for (int i = x; i < x + 3; ++i)\n for (int j = y; j < y + 3; ++j)\n if (board[i][j] == '.') {\n board[i][j] = '!';\n }\n } else {\n for (int i = 0; i < 9; ++i)\n for (int j = 0; j < 9; ++j)\n if (board[i][j] == '.') {\n board[i][j] = '!';\n }\n }\n for (int i = 0; i < 9; ++i) {\n if (i > 0 && i % 3 == 0) out.println();\n for (int j = 0; j < 9; ++j) {\n if (j > 0 && j % 3 == 0) out.print(' ');\n out.print(board[i][j]);\n }\n out.println();\n }\n }\n\n boolean hasEmpty(int x, int y) {\n for (int i = x; i < x + 3; ++i)\n for (int j = y; j < y + 3; ++j) {\n if (board[i][j] == '.') return true;\n }\n return false;\n }\n\n }\n\n static class QuickWriter {\n private final PrintWriter writer;\n\n public QuickWriter(OutputStream outputStream) {\n this.writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public QuickWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void print(Object... objects) {\n for (int i = 0; i < objects.length; ++i) {\n if (i > 0) {\n writer.print(' ');\n }\n writer.print(objects[i]);\n }\n }\n\n public void println(Object... objects) {\n print(objects);\n writer.println();\n }\n\n public void close() {\n writer.close();\n }\n\n }\n\n static class QuickScanner {\n private static final int BUFFER_SIZE = 1024;\n private InputStream stream;\n private byte[] buffer;\n private int currentPosition;\n private int numberOfChars;\n\n public QuickScanner(InputStream stream) {\n this.stream = stream;\n this.buffer = new byte[BUFFER_SIZE];\n this.currentPosition = 0;\n this.numberOfChars = 0;\n }\n\n public int nextInt() {\n int c = nextNonSpaceChar();\n boolean positive = true;\n if (c == '-') {\n positive = false;\n c = nextChar();\n }\n int res = 0;\n do {\n if (c < '0' || '9' < c) throw new RuntimeException();\n res = res * 10 + (c - '0');\n c = nextChar();\n } while (!isSpaceChar(c));\n return positive ? res : -res;\n }\n\n public int nextNonSpaceChar() {\n int res = nextChar();\n for (; isSpaceChar(res) || res < 0; res = nextChar()) ;\n return res;\n }\n\n public int nextChar() {\n if (numberOfChars == -1) {\n throw new RuntimeException();\n }\n if (currentPosition >= numberOfChars) {\n currentPosition = 0;\n try {\n numberOfChars = stream.read(buffer);\n } catch (Exception e) {\n throw new RuntimeException(e);\n }\n if (numberOfChars <= 0) {\n return -1;\n }\n }\n return buffer[currentPosition++];\n }\n\n public boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\t' || isEndOfLineChar(c);\n }\n\n public boolean isEndOfLineChar(int c) {\n return c == '\\n' || c == '\\r' || c < 0;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "f89f6f9006021f27563fd1305fad3cd4", "src_uid": "8f0fad22f629332868c39969492264d3", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class D {\n\n\tstatic final int P = 1_000_000_007;\n\n\tvoid submit() {\n\t\tint n = nextInt();\n\t\tint[] dp = new int[n + 2];\n\t\tdp[0] = 1;\n\t\tfor (int k = 1; k <= n; k++) {\n\t\t\tint[] nxt = new int[n + 1];\n\t\t\tint need = n + 1 - k;\n\t\t\tfor (int i = 0; i <= need + 1; i++) {\n\t\t\t\tfor (int j = 0; i + j - 1 <= need; j++) {\n\t\t\t\t\tint prod = (int) ((long) dp[i] * dp[j] % P);\n\n\t\t\t\t\tif (i + j <= need) {\n\t\t\t\t\t\tnxt[i + j] += prod;\n\t\t\t\t\t\tif (nxt[i + j] >= P) {\n\t\t\t\t\t\t\tnxt[i + j] -= P;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tnxt[i + j] += (int) (2L * prod * (i + j) % P);\n\t\t\t\t\t\tif (nxt[i + j] >= P) {\n\t\t\t\t\t\t\tnxt[i + j] -= P;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\tif (i + j + 1 <= need) {\n\t\t\t\t\t\t\tnxt[i + j + 1] += prod;\n\t\t\t\t\t\t\tif (nxt[i + j + 1] >= P) {\n\t\t\t\t\t\t\t\tnxt[i + j + 1] -= P;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (i + j > 0) {\n\t\t\t\t\t\tint mult = (i + j) * (i + j) - i - j;\n\t\t\t\t\t\tnxt[i + j - 1] += (int) ((long)mult * prod % P);\n\t\t\t\t\t\tif (nxt[i + j - 1] >= P) {\n\t\t\t\t\t\t\tnxt[i + j - 1] -= P;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tdp = nxt;\n//\t\t\tSystem.err.println(Arrays.toString(dp));\n\t\t}\n\n\t\tout.println(dp[1]);\n\t}\n\n\tvoid preCalc() {\n\n\t}\n\n\tvoid stress() {\n\n\t}\n\n\tD() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tpreCalc();\n\t\tsubmit();\n\t\t// stress();\n\t\t// test();\n\t\tout.close();\n\t}\n\n\tstatic final Random rng = new Random();\n\n\tstatic int rand(int l, int r) {\n\t\treturn l + rng.nextInt(r - l + 1);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew D();\n\t}\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t}\n\n\tint nextInt() {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}\n", "lang_cluster": "Java", "tags": ["dp", "combinatorics", "trees", "graphs"], "code_uid": "95e94ff4f82700af276d40baacd9eda0", "src_uid": "fda761834f7b5800f540178ac1c79fca", "difficulty": 2800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\n\n\n\npublic class Problem1 {\n\n\tstatic long a, b, c;\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tint[] days = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};\n\t\tHashMap< String, Integer> hm = new HashMap<>();\n\t\thm.put(\"monday\", 1);\n\t\thm.put(\"tuesday\", 2);\n\t\thm.put( \"wednesday\", 3);\n\t\thm.put(\"thursday\",4);\n\t\thm.put( \"friday\", 5);\n\t\thm.put( \"saturday\", 6);\n\t\thm.put(\"sunday\", 7);\n\t\tString f = in.next();\n\t\tString s = in.next();\n\t\tint a = hm.get(f);\n\t\tint b = hm.get(s);\n\t\tfor(int i = 0; i < 12; ++i)\n\t\t{\n\t\t\tint rem = (days[i]) % 7;\n\t\t\tif((a + rem) % 7 == b || ((a + rem) % 7 == 0 && b== 7 ))\n\t\t\t{\n\t\t\t\tout.println(\"YES\");\n\t\t\t\tout.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\tif(a == b && rem == 0)\n\t\t\t{\n\t\t\t\tout.println(\"YES\");\n\t\t\t\tout.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tout.println(\"NO\");\n\t\tout.close();\n\t\t\n\t}\n\t\n\t\n\n\t\n\t\n\n\t\n\tstatic class InputReader {\n\t public BufferedReader reader;\n\t public StringTokenizer tokenizer;\n\n\t public InputReader(InputStream stream) {\n\t reader = new BufferedReader(new InputStreamReader(stream), 32768);\n\t tokenizer = null;\n\t }\n\n\t public String next() {\n\t while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t try {\n\t tokenizer = new StringTokenizer(reader.readLine());\n\t } catch (IOException e) {\n\t throw new RuntimeException(e);\n\t }\n\t }\n\t return tokenizer.nextToken();\n\t }\n \n\t public int nextInt() {\n\t return Integer.parseInt(next());\n\t }\n\t \n\t public long nextLong()\n\t {\n\t \treturn Long.parseLong(next());\n\t }\n\n\t}\n\n\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "e09a9358b29b36c6cc6cb4755b7c60ad", "src_uid": "2a75f68a7374b90b80bb362c6ead9a35", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "//codeforces_975B\n\nimport java.io.*;\nimport java.util.*;\nimport java.util.regex.Matcher;\nimport java.util.regex.Pattern;\nimport static java.lang.Math.*;\n\npublic class acm{\n\t\n\tpublic static void main(String args[]) throws IOException,FileNotFoundException {\n\t\tBufferedReader gi = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter go = new PrintWriter(System.out);\n\t\tint[] line = parseArray(gi.readLine().split(\" \"));\n\t\tint div,rem;\n\t\tlong temp = 0,rez = 0;\n\t\tfor (int k = 0; k<14; k++){\n\t\t\tif (line[k] == 0){ continue; }\n\t\t\tdiv = line[k]/14;\n\t\t\trem = line[k]%14;\n\t\t\ttemp = 0;\n\t\t\tfor (int j = k+1; j<=k+rem; j++){\n\t\t\t\tif ((line[j%14]+div+1)%2==0){ temp += line[j%14] + 1 + div; }\n\t\t\t}\n\t\t\tfor (int j = k+rem+1; j<14+k; j++){\n\t\t\t\tif ((line[j%14]+div)%2==0){ temp+= line[j%14] + div; }\n\t\t\t}\n\t\t\tif (div%2==0){temp+=div;}\n\t\t\trez = max(rez, temp);\n\t\t}\n\t\tgo.println(rez);\n\t\tgo.close();\n\t}\n\n\tstatic int[] parseArray(String[] line){\n\t\tint len = line.length;\n\t\tint A[] = new int[len];\n\t\tint k = 0;\n\t\tfor (String e : line){\n\t\t\tA[k++] = Integer.parseInt(e);\n\t\t}\n\t\treturn A;\n\t}\n\n}\n\n", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "6a400fedbb4bf53e3321ac019890b3b2", "src_uid": "1ac11153e35509e755ea15f1d57d156b", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/*Author LAVLESH*/\nimport java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\npublic class solution{\n\tstatic BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\tstatic StringTokenizer st=new StringTokenizer(\"\");\n \n\t\n\n\tstatic public String next() {\n\t while (st == null || !st.hasMoreTokens()) {\n\t try {\n\t st = new StringTokenizer(br.readLine());\n\t } catch (IOException e) {\n\t throw new RuntimeException(e);\n\t }\n\t }\n\t return st.nextToken();\n\t }\n\t\n\tstatic int mod=1000003;\n\tstatic int inv(int a){\n\t\treturn BigInteger.valueOf(a).modInverse(BigInteger.valueOf(mod)).intValue();\n\t}\n\tpublic static void main(String[]args)throws IOException{\n\t\tPrintWriter op =new PrintWriter(System.out,true);\n\t\tlong ans;\n\t\tint n=Integer.parseInt(next());\n\t\t int m=Integer.parseInt(next());\n\t\tint num=1,den=1;\n\t\t for(int i=1;i<=m;i++)\n\t\t {\n\t\t\t num=(int)((long)num*(n+i)%mod);\n\t\t\t den=(int)((long)den*i%mod);\n\t\t }\n\tans=(((long)num*inv(den)%mod)+mod)%mod;\n\t\top.println(ans-1);\n\t\t\n\t\t\n\t\t op.close();\n }\n}\n ", "lang_cluster": "Java", "tags": ["combinatorics"], "code_uid": "dd287c0598b8a5d0ce1b9259f856512a", "src_uid": "e63c70a9c96a94bce99618f2e695f83a", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class A761 {\n public static void main(String []args)\n {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int m =sc.nextInt();\n if(Math.abs(m-n) == 1 || (m+n!=0 && m==n) )\n {\n System.out.println(\"YES\");\n }\n else\n {\n System.out.println(\"NO\");\n }\n }\n \n}\n", "lang_cluster": "Java", "tags": ["brute force", "math", "constructive algorithms", "implementation"], "code_uid": "3794aa48bbe40fc67062ad2d7b8738a1", "src_uid": "ec5e3b3f5ee6a13eaf01b9a9a66ff037", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author prakharjain\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n BSquaresAndSegments solver = new BSquaresAndSegments();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class BSquaresAndSegments {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int n = in.nextInt();\n\n// Set fac = factors(n);\n//\n// long ans = n + 1;\n// for (long f : fac) {\n// long t = n / f;\n//\n// ans = Math.min(ans, t + f);\n// }\n//\n// long sq = (long) Math.sqrt(n);\n//\n// while (sq * sq < n)\n// sq++;\n//\n// out.println(Math.min(2 * sq, ans));\n\n long ans = n + 1;\n for (int i = 1; i * i <= n; i++) {\n long ceil = (n + i - 1) / i;\n\n ans = Math.min(ans, i + ceil);\n }\n\n out.println(ans);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void println(long i) {\n writer.println(i);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["math", "constructive algorithms", "binary search"], "code_uid": "549c38b17645a95882cf706581348c1e", "src_uid": "eb8212aec951f8f69b084446da73eaf7", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.lang.*;\nimport java.math.BigInteger;\nimport java.io.*;\nimport java.util.*;\n\npublic class Solution implements Runnable{\n public static BufferedReader br;\n public static PrintWriter out;\n public static StringTokenizer stk;\n public static boolean isStream = true;\n\n public static void main(String[] args) throws IOException {\n \tif (isStream) {\n br = new BufferedReader(new InputStreamReader(System.in));\n } else {\n br = new BufferedReader(new FileReader(\"in.txt\"));\n }\n out = new PrintWriter(System.out);\n new Thread(new Solution()).start();\n }\n\n public void loadLine() {\n try {\n stk = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n\n public String nextLine() {\n try {\n return br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n return \"\";\n }\n }\n\n public String nextWord() {\n while (stk==null||!stk.hasMoreTokens()) loadLine();\n return stk.nextToken();\n }\n\n public Integer nextInt() {\n while (stk==null||!stk.hasMoreTokens()) loadLine();\n return Integer.valueOf(stk.nextToken());\n }\n\n public Long nextLong() {\n while (stk==null||!stk.hasMoreTokens()) loadLine();\n return Long.valueOf(stk.nextToken());\n }\n\n public Double nextDouble() {\n while (stk==null||!stk.hasMoreTokens()) loadLine();\n return Double.valueOf(stk.nextToken());\n }\n \n public Float nextFloat() {\n while (stk==null||!stk.hasMoreTokens()) loadLine();\n return Float.valueOf(stk.nextToken());\n }\n \n public void run() {\n \tint n = nextInt();\n \tint m = nextInt();\n \tif (n > m) {\n \t\tint sw = n;\n \t\tn = m;\n \t\tm = sw;\n \t}\n \tint[][] A = new int[1<>i))&1; \n \t\t\t}\n \t\t\tint[] m2a = new int[n];\n \t\t\tfor (int i = 0; i < n; ++i) {\n \t\t\t\tm2a[i] = (m2>>i)&1; \n \t\t\t}\n \t\t\tint cnt = 0;\n \t\t\tfor (int i = 0; i < n; ++i) {\n \t\t\t\tif (arr[i] == 1) {\n \t\t\t\t\tif (i > 0 && m2a[i-1] == 1) {\n \t\t\t\t\t\tcontinue;\n \t\t\t\t\t}\n \t\t\t\t\tif (i < n-1 && m2a[i+1] == 1) {\n \t\t\t\t\t\tcontinue;\n \t\t\t\t\t}\n \t\t\t\t\tif (m2a[i] == 1) {\n \t\t\t\t\t\tcontinue;\n \t\t\t\t\t}\n \t\t\t\t\tif (i < n-1) {\n \t\t\t\t\t\tm2a[i+1] = 1;\n \t\t\t\t\t} else {\n \t\t\t\t\t\tm2a[i] = 1;\n \t\t\t\t\t}\n \t\t\t\t}\n \t\t\t}\n \t\t\tfor (int i = 0; i < n; ++i) {\n \t\t\t\tif (m2a[i] == 1) {\n \t\t\t\t\tcnt++;\n \t\t\t\t}\n \t\t\t}\n \t\t\tA[m1][m2] = cnt;\n \t\t}\n \t}\n \tint MAX = 10000;\n \tint[][][] dp = new int[m+1][1<0) tot+=num-1;\n\t\t\tcnt[i]%=(840/i);\n\t\t\tif (num>0) cnt[i]+=840/i;\n\t\t}\n\t\tint maxW=840*16;\n\t\tif (w=(1<=num*i;--k)\n\t\t\t\tdp[k]|=dp[k-num*i];\n\t\t}\n\t\tfor (int i=0;i<=maxW;++i) if (dp[i])\n\t\t\tres=Math.max(res,i+Math.min((w-i)/840,tot)*840);\n\t\tout.println(res);\n\t\tout.close();\n\t}\n}", "lang_cluster": "Java", "tags": ["dfs and similar", "greedy", "dp"], "code_uid": "d7512c457b9100b7eca8ba2777be1eb7", "src_uid": "8097e10157320524c0faed56f2bc4880", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.NoSuchElementException;\n \nimport java.util.*;\npublic class Main {\n\tlong N,a,b,c;\n\t\n\tpublic void solve() {\n\t\tN = nextLong();\n\t\ta = nextLong();\n\t\tb = nextLong();\n\t\tc = nextLong();\n\t\t\n\t\tif(a <= b - c){\n\t\t\tout.println(N / a);\n\t\t\treturn;\n\t\t}\n\t\tlong ans = 0L;\n\t\t\n\t\tif(b <= N){\n\t\t\tans = (N - b) / (b - c) + 1;\n\t\t\tN -= ans * (b - c);\n\t\t}\n\t\t\n\t\tif(a <= N){\n\t\t\tans += N / a;\n\t\t}\n\t\tout.println(ans);\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tout.flush();\n\t\tnew Main().solve();\n\t\tout.close();\n\t}\n\t\n\t/* Input */\n\tprivate static final InputStream in = System.in;\n\tprivate static final PrintWriter out = new PrintWriter(System.out);\n\tprivate final byte[] buffer = new byte[2048];\n\tprivate int p = 0;\n\tprivate int buflen = 0;\n\t\n\tprivate boolean hasNextByte() {\n\t\tif (p < buflen)\n\t\t\treturn true;\n\t\tp = 0;\n\t\ttry {\n\t\t\tbuflen = in.read(buffer);\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t\tif (buflen <= 0)\n\t\t\treturn false;\n\t\treturn true;\n\t}\n\t\n\tpublic boolean hasNext() {\n\t\twhile (hasNextByte() && !isPrint(buffer[p])) {\n\t\t\tp++;\n\t\t}\n\t\treturn hasNextByte();\n\t}\n\t\n\tprivate boolean isPrint(int ch) {\n\t\tif (ch >= '!' && ch <= '~')\n\t\t\treturn true;\n\t\treturn false;\n\t}\n\t\n\tprivate int nextByte() {\n\t\tif (!hasNextByte())\n\t\t\treturn -1;\n\t\treturn buffer[p++];\n\t}\n\tpublic String next() {\n\t\tif (!hasNext())\n\t\t\tthrow new NoSuchElementException();\n\t\tStringBuilder sb = new StringBuilder();\n\t\tint b = -1;\n\t\twhile (isPrint((b = nextByte()))) {\n\t\t\tsb.appendCodePoint(b);\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tpublic int nextInt() {\n\t\treturn Integer.parseInt(next());\n\t}\n\t\n\tpublic long nextLong() {\n\t\treturn Long.parseLong(next());\n\t}\n\t\n\tpublic double nextDouble() {\n\t\treturn Double.parseDouble(next());\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "53c7bcafe07a39c2df030a03c7324d9f", "src_uid": "0ee9abec69230eab25de51aef0984f8f", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n/**\n * \u4f5c\u8005\uff1a\u5f20\u5b87\u7fd4\n * \u521b\u5efa\u65e5\u671f\uff1a2017\u5e745\u67084\u65e5 \u4e0b\u534810:33:03\n * \u63cf\u8ff0\uff1a\u6c38\u8fdc\u7684ACM\uff0c\u6c38\u8fdc\u7684\u5f81\u9014\n */\npublic class Main {\n\tprivate static final int Max=(int) (1e5+10);\n\tprivate static int n;\n\tprivate static int ans;\n\tprivate static int []vis;\n\tpublic static void main(String[] args) throws Exception{\n\t\tInitData();\n\t\tGetAns();\n\t}\n\tprivate static void InitData() throws Exception{\n\t\tSC cin=new SC(System.in);\n\t\tvis=new int[Max];\n\t\tn=cin.nextInt();\n\t\tans=0;\n\t}\n\t\n\tprivate static void GetAns(){\n\t\tif(n==3||n==4){\n\t\t\tSystem.out.println(1);\n\t\t}else if(n==2||n==1){\n\t\t\tSystem.out.println(0);\n\t\t}else{\n\t\t\tfor(int i=1;i<=n;i++){\n\t\t\t\tint temp=(n+1)-i;\n\t\t\t\tif(i1){\n\t\t\t\tans--;\n\t\t\t}\n\t\t\tfor(int i=1;i<=n;i++){\n\t\t\t\tif(vis[i]==0){\n\t\t\t\t\tans++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println(ans);\n\t\t}\n\t}\n\tstatic class SC\n\t{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tSC(InputStream s)\t\n\t\t{\n\t\t\tbr = new BufferedReader(new InputStreamReader(s));\n\t\t}\n\t\tString next() throws IOException\n\t\t{\n\t\t\twhile(st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tint nextInt() throws NumberFormatException, IOException\n\t\t{\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tlong nextLong() throws NumberFormatException, IOException\n\t\t{\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t}\n\n}", "lang_cluster": "Java", "tags": ["constructive algorithms"], "code_uid": "4a023183fdb85448591ecf95fcd7b6b7", "src_uid": "dfe9446431325c73e88b58ba204d0e47", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "//package codeforces;\n\nimport java.util.Scanner;\npublic class Main {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner sc = new Scanner(System.in);\n\t\tint len = sc.nextInt();\n\t\tString str = sc.next();\n\t\tif (len < 2) {\n\t\t\tSystem.out.println(str);\n\t\t} else {\n\t\t\tString[] str_char = str.split(\"\");\n\t\t\tStringBuffer sb = new StringBuffer(\"1\");\n\t\t\tfor (int i = 0; i < str_char.length; i++) {\n\t\t\t\tif(str_char[i].equals(\"0\")){\n\t\t\t\t\tsb.append(\"0\");\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println(sb);\n\t\t}\n\t\t\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "135bec62ee09369bdbdfa6e2bd026117", "src_uid": "ac244791f8b648d672ed3de32ce0074d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\nimport java.util.function.Function;\n\npublic class CF287D {\n\n public static long modPower(long base, long exponent, long mod) {\n long result = 1;\n while (exponent > 0) {\n if ((exponent & 1) != 0)\n result = (result * base) % mod;\n base = (base * base) % mod;\n exponent >>= 1;\n }\n return result;\n }\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int k = in.nextInt();\n long m = in.nextLong();\n long[] dp = new long[k];\n dp[0] = 1;\n long total = 0;\n for (int i = 0; i < n; i++) {\n long[] next = new long[k];\n for (int j = 0; j < k; j++)\n for (int d = (i == n - 1) ? 1 : 0; d < 10; d++) {\n int res = (int) (modPower(10, i, k) * d + j) % k;\n next[res] = (next[res] + dp[j]) % m;\n }\n if (i < n - 1)\n total += (next[0] + m - 1) * 9 % m * modPower(10, n - 2 - i, m)\n % m;\n else\n total += next[0];\n\n total %= m;\n dp = next;\n dp[0] = 1;\n }\n System.out.println(total);\n }\n}\n", "lang_cluster": "Java", "tags": ["dp", "implementation"], "code_uid": "41e91d84278bc1e9d5b8b84f37707640", "src_uid": "656bf8df1e79499aa2ab2c28712851f0", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class Main\n{\n static class Reader \n { \n private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public Reader() { this(System.in); }public Reader(InputStream is) { mIs = is;} \n 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++];} \n 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() ;} \n 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();} \n 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;} \n 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;} \n public double d() throws IOException {return Double.parseDouble(s()) ;}\n public boolean isSpaceChar(int c) { return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1; } \n public boolean isEndOfLine(int c) { return c == '\\n' || c == '\\r' || c == -1; } \n } \n \n ///////////////////////////////////////////////////////////////////////////////////////////\n // RRRRRRRRR AAA HHH HHH IIIIIIIIIIIII LLL //\n // RR RRR AAAAA HHH HHH IIIIIIIIIII LLL //\n // RR RRR AAAAAAA HHH HHH III LLL //\n // RR RRR AAA AAA HHHHHHHHHHH III LLL //\n // RRRRRR AAA AAA HHHHHHHHHHH III LLL //\n // RR RRR AAAAAAAAAAAAA HHH HHH III LLL //\n // RR RRR AAA AAA HHH HHH IIIIIIIIIII LLLLLLLLLLLL //\n // RR RRR AAA AAA HHH HHH IIIIIIIIIIIII LLLLLLLLLLLL //\n ///////////////////////////////////////////////////////////////////////////////////////////\n static int n;\n static int arr[];\n HashMap hm=new HashMap();\n public static void main(String[] args)throws IOException\n {\n PrintWriter out= new PrintWriter(System.out);\n Reader sc=new Reader();\n int a=sc.i();int b=sc.i();int c=sc.i();\n int a1=sc.i();int b1=sc.i();int c1=sc.i();\n if(a!=a1&&b!=b1&&c!=c1)\n System.out.println(\"NO\");\n else\n System.out.println(\"YES\");\n }\n} ", "lang_cluster": "Java", "tags": ["math"], "code_uid": "c3fd77939a0c7573644adc53d020df16", "src_uid": "91c9dbbceb467d5fd420e92c2919ecb6", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.HashSet;\nimport java.util.Set;\nimport java.util.StringTokenizer;\n\npublic class First\n{\n public static void main(String[] args)\n {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskA solver = new TaskA();\n solver.solve(1, in, out);\n out.close();\n }\n}\n\nclass Team\n{\n String teamName;\n int score;\n int goalFor;\n int goalAgainst;\n int matchPlayed;\n \n public Team(String teamName, int score, int goalFor, int goalAgainst, int matchPlayed)\n {\n super();\n this.teamName = teamName;\n this.score = score;\n this.goalFor = goalFor;\n this.goalAgainst = goalAgainst;\n this.matchPlayed = matchPlayed;\n } \n}\n\nclass MyComparator implements Comparator\n{\n @Override\n public int compare(Team t1, Team t2)\n {\n \n if(t1.score < t2.score) return 1;\n if(t1.score > t2.score) return -1;\n if(t1.goalFor - t1.goalAgainst < t2.goalFor - t2.goalAgainst) return 1;\n if(t1.goalFor - t1.goalAgainst > t2.goalFor - t2.goalAgainst) return -1;\n if(t1.goalFor < t2.goalFor) return 1;\n if(t1.goalFor > t2.goalFor) return -1;\n return t1.teamName.compareTo(t2.teamName);\n } \n}\n\nclass TaskA\n{ \n public void solve(int testNumber, InputReader in, PrintWriter out)\n {\n Set hset = new HashSet ();\n String[] inputStr = new String[5];\n for(int i = 0; i < 5; i++)\n {\n inputStr[i] = in.nextLine();\n }\n \n Team[] team = new Team[4];\n for(int i = 0; i < 5; i++)\n {\n String str = inputStr[i];\n str = str.replace(\":\", \" \");\n String[] ans = str.split(\"[ ]+\");\n hset.add(ans[0]); hset.add(ans[1]);\n }\n int index = 0;\n for(String str : hset)\n {\n int myScore = 0;\n int myGoalFor = 0;\n int myGoalAgainst = 0;\n int matchPlayed = 0;\n for(int i = 0; i < 5; i++)\n {\n String current = inputStr[i];\n current = current.replace(\":\", \" \");\n String[] ans = current.split(\"[ ]+\");\n String firstTeam = ans[0];\n String secondTeam = ans[1];\n int firstScoreGoal = Integer.parseInt(ans[2]);\n int secondScoreGoal = Integer.parseInt(ans[3]);\n \n if(firstTeam.equals(str))\n {\n myGoalFor += firstScoreGoal;\n myGoalAgainst += secondScoreGoal;\n if(firstScoreGoal > secondScoreGoal) \n { \n myScore += 3;\n }\n if(firstScoreGoal == secondScoreGoal)\n myScore++;\n matchPlayed++;\n }\n if(secondTeam.equals(str))\n {\n myGoalFor += secondScoreGoal;\n myGoalAgainst += firstScoreGoal;\n if(secondScoreGoal > firstScoreGoal) myScore += 3;\n if(secondScoreGoal == firstScoreGoal) myScore++;\n matchPlayed++;\n }\n }\n team[index++] = new Team(str, myScore, myGoalFor, myGoalAgainst, matchPlayed);\n }\n Arrays.sort(team, new MyComparator());\n \n index = 0; int i = 0;\n for(Team item : team) \n { if(item.teamName.equals(\"BERLAND\")) \n index = i;\n i++;\n //System.out.println(item.teamName + \" \" + item.score + \" \" + item.goalFor + \" \" + item.goalAgainst + \" \" + item.matchPlayed); \n }\n if(team[0].teamName.equals(\"BERLAND\") || team[1].teamName.equals(\"BERLAND\"))\n out.println(\"1:0\");\n \n else\n {\n String secondTeamName = team[1].teamName;\n int secondScore = team[1].score;\n int secondGoalFor = team[1].goalFor;\n int secondGoalAgainst = team[1].goalAgainst;\n int differenceSecond = secondGoalFor - secondGoalAgainst;\n \n int berlandScore = team[index].score;\n int berlandGoalFor = team[index].goalFor;\n int berlandGoalAgainst = team[index].goalAgainst;\n int differenceBerland = berlandGoalFor - berlandGoalAgainst;\n if(secondScore <= berlandScore + 2)\n {\n out.println(\"1:0\"); \n }\n else if (secondScore > berlandScore + 3)\n {\n out.println(\"IMPOSSIBLE\"); \n }\n else\n {\n int kk = 0;\n for(int k = 1; k < 4; k++)\n {\n if(team[k].teamName.equals(\"BERLAND\") == false && team[k].matchPlayed == 2)\n {\n kk = k;\n break;\n }\n }\n Team[] tempTeam = new Team[4];\n \n outer:for(int diff = 1; ; diff++)\n {\n \n int counter = 0; int hisGoals = 0;\n for(int myGoals = diff; ; myGoals++, hisGoals++)\n {\n \n for(int step = 0; step < 4; step++)\n {\n tempTeam[step] = new Team(team[step].teamName, team[step].score, team[step].goalFor , team[step].goalAgainst, team[step].matchPlayed);\n } \n \n \n tempTeam[index].score += 3;\n tempTeam[index].goalFor += myGoals;\n tempTeam[index].goalAgainst += hisGoals;\n \n tempTeam[kk].goalAgainst += myGoals;\n tempTeam[kk].goalFor += hisGoals;\n \n \n if(myGoals > 60) continue outer;\n Arrays.sort(tempTeam, new MyComparator());\n if(tempTeam[0].teamName.equals(\"BERLAND\") || tempTeam[1].teamName.equals(\"BERLAND\"))\n {\n out.println(myGoals + \":\" + hisGoals);\n break outer;\n }\n }\n }\n } \n }\n }\n}\n\nclass InputReader\n{\n private BufferedReader reader;\n private StringTokenizer tokenizer;\n\n public InputReader(InputStream stream)\n {\n reader = new BufferedReader(new InputStreamReader(stream));\n tokenizer = null;\n }\n\n public String next()\n {\n while (tokenizer == null || !tokenizer.hasMoreTokens())\n {\n try\n {\n tokenizer = new StringTokenizer(reader.readLine());\n }\n catch (IOException e)\n {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt()\n {\n return Integer.parseInt(next());\n }\n \n public String nextLine()\n {\n String inputLine = \"\";\n try\n {\n inputLine = reader.readLine();\n }\n catch (IOException e)\n {\n e.printStackTrace();\n }\n return inputLine;\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "57b11c72283c8eb1c7bfaf68bb0b7912", "src_uid": "5033d51c67b7ae0b1a2d9fd292fdced1", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class Mathshow1 {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\n\t\tScanner input = new Scanner(System.in);\n\t\t\n\t\tint n = input.nextInt();\n\t\tint k = input.nextInt();\n\t\tint m = input.nextInt();\n\t\tint[] arr = new int[k];\n\t\tint total=0;\n\t\tfor(int i=0; i=0){\n \t\t\t\tmatrix[j-1][j]=j;\n \t\t\t\tmatrix[j-1][j]%=mod;\n \t\t\t\tmatrix[j-1][j]*=(long)(n-2*y+j);\n \t\t\t\tmatrix[j-1][j]%=mod;\n \t\t\t\ts-=matrix[j-1][j];\n \t\t\t\ts%=mod;\n \t\t\t\ts+=mod;\n \t\t\t\ts%=mod;\n \t\t\t}\n \t\t\tif (j+1 <= y){\n \t\t\t\tmatrix[j+1][j]=(y-j);\n \t\t\t\tmatrix[j+1][j]%=mod;\n \t\t\t\tmatrix[j+1][j]*=(long)(y-j);\n \t\t\t\tmatrix[j+1][j]%=mod;\n \t\t\t\ts-=matrix[j+1][j];\n \t\t\t\ts%=mod;\n \t\t\t\ts+=mod;\n \t\t\t\ts%=mod;\n \t\t\t}\n \t\t\tmatrix[j][j] = s;\n \t\t\t\n \t\t}\n \t\tlong[][] product = power(matrix, k);\n \t\tlong ans = product[y][initial];\n \t\tans%=mod;\n \t\tlong nC2 = n;\n \t\tnC2*=(long)(n-1);\n \t\tnC2/=2L;\n \t\tlong div = power(nC2, mod-2);\n \t\tans*=power(div, k);\n \t\tans%=mod;\n \t\t\n \t\t\n \t\t\n \t\tout.println(ans);\n\t \t\t\n \t\tout.close();\t\n \t}\n\tpublic static long[][] mul(long[][] m1, long[][] m2){\n\t\tlong[][] ans = new long[y+1][y+1];\n\t\tfor(int j =0;j<=y;j++){\n\t\t\tfor(int k = 0;k<=y;k++){\n\t\t\t\tfor(int l = 0;l<=y;l++){\n\t\t\t\t\tans[j][l]+=m1[j][k]*m2[k][l];\n\t\t\t\t\tans[j][l]%=mod;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn ans;\n\t}\n\tpublic static long[][] power(long[][] m1, long k){\n\n\t\tif (k == 0){\n\t\t\tlong[][] mst = new long[y+1][y+1];\n\t\t\tfor(int j =0 ;j<=y;j++){\n\t\t\t\tmst[j][j] = 1L;\n\t\t\t}\n\t\t\treturn mst;\n\t\t}\n\t\t\t\n\t\tif (k == 1)\n\t\t\treturn m1;\n\t\tlong [][]ks = power(m1, k/2L);\n\t\tif (k%2 == 0)\n\t\t\treturn mul(ks, ks);\n\t\telse\n\t\t\treturn mul(mul(ks, ks), m1);\n\t}\n\tpublic static void sort(int[] array){\n\t\tArrayList copy = new ArrayList();\n\t\tfor (int i : array)\n\t\t\tcopy.add(i);\n\t\tCollections.sort(copy);\n\t\tfor(int i = 0;i adj[]=new ArrayList[N];\r\nstatic long dp[][]=new long[2][N];\r\nstatic long A[][]=new long[2][N];\r\n\r\n-----------DFS--------------\r\n*/\r\n/*static class Edge implements Comparable{\r\nint destination;long cost;\r\nEdge(int destination,long cost){this.cost=cost;this.destination=destination;}\r\n\r\n@Override\r\n\r\n\t\tpublic int compareTo(Edge o) {\r\n\t\t\treturn Long.compare(cost, o.cost);\r\n\t\t}\r\n}\r\n\r\n*/\r\n\r\npublic static void main(String []args){\r\n\r\nint t=1;\r\n\r\nwhile(t-->0){\r\nint n=in.nextInt();int m=in.nextInt();\r\n\r\nHashMap hs=new HashMap<>();boolean ans=true;\r\nwhile(n>0&&ans){int c=n%m;n/=m;int count = hs.getOrDefault(c,0);if(count>0)ans=false;else{hs.put(c,1);}}\r\nif(ans)out.println(\"YES\");\r\nelse{out.println(\"NO\");}\r\n }\r\n\r\nout.close();\r\n}}", "lang_cluster": "Java", "tags": ["number theory"], "code_uid": "3a514c6a3d7d29e93ec8f2ff9392181f", "src_uid": "a8945bb1082fefe70e6898a8bec1ce3f", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.lang.*;\nimport java.io.*;\nimport java.util.ArrayList;\nimport java.util.PriorityQueue;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Compilation {\n\n public static void main(String[] args) throws java.lang.Exception {\n // your code goes here\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n String arr[];\n\n arr = br.readLine().split(\" \");\n int n = Integer.parseInt(arr[0]);\n int k = Integer.parseInt(arr[1]);\n\n int res = k;\n\n if (n < k) {\n System.out.println(k);\n } else if (n > k) {\n int mod = n % k;\n if ((n / k) * k >= n) {\n System.out.println(n + mod + k);\n } else {\n System.out.println(n - mod + k);\n }\n } else {\n System.out.println(k * 2);\n }\n\n //while (res <= n) {\n // res += k;\n // }\n // System.out.println(res);\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "a200c42a26517370a2c67be448ed3c55", "src_uid": "75f3835c969c871a609b978e04476542", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.BufferedReader;\nimport java.util.Scanner;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Iterator;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\nimport java.math.BigInteger;\npublic class Vanya_and_Books \n{\n\tstatic Scanner sc=new Scanner(System.in);\n\tstatic PrintWriter out=new PrintWriter(System.out);\n\tstatic void pn(Object o)\n\t{\n\t\tout.println(o);\n\t\tout.flush();\n\t\t\n\t}\n\tstatic void p(Object o)\n\t{\n\t\tout.print(o);\n\t\tout.flush();\n\t}\n\tstatic void pni(Object o)\n\t{\n\t\tout.println(o);System.out.flush();\n\t}\n\t\n\tstatic int I() throws IOException\n\t{ \n\t\treturn sc.nextInt();\n\t}\n\tstatic long L()throws IOException\n\t{\n\t\treturn sc.nextLong();\n\t}\n\tstatic double D()throws IOException\n\t{\n\t\treturn sc.nextDouble();\n\t}\n\tstatic String S()throws IOException\n\t{\n\t\treturn sc.next();\n\t}\n\tstatic char C() throws IOException\n\t{\n\t\treturn sc.next().charAt(0);\n\t}\t\n\tstatic int countDigits(long n)\n\t{\n\t\tint c=0;\n\t\twhile(n>0)\n\t\t{\n\t\t\tc++;\n\t\t\tn=n/10;\n\t\t}\n\t\t\n\t\t\n\t\treturn c;\n\t\t\n\t}\n\t static int next(long[] arr, long target) \n\t\t{ \n\t\t\tint start = 0, end = arr.length - 1; \n\t\t\n\t\t\tint ans = -1; \n\t\t\twhile (start <= end) { \n\t\t\t\tint mid = (start + end) / 2; \n\t\t\n\t\t\t\t// Move to right side if target is \n\t\t\t\t// greater. \n\t\t\t\tif (arr[mid] <= target) { \n\t\t\t\t\tstart = mid + 1; \n\t\t\t\t} \n\t\t\n\t\t\t\t// Move left side. \n\t\t\t\telse { \n\t\t\t\t\tans = mid; \n\t\t\t\t\tend = mid - 1; \n\t\t\t\t} \n\t\t\t} \n\t\t\treturn ans; \n\t\t} \n\tpublic static void process() throws IOException\n\t{\n\t\t\n\t long n=L();\n\t if(n<=9)\n\t {\n\t \tpn(n);\n\t }\n\t else\n\t {\n\t\tlong a1[]= {9,99,999,9999,99999,999999,9999999,99999999,999999999};\n\t\tlong count[]=new long[9];count[0]=9;\n\t\tfor(int i1=1;i1<9;i1++)\n\t\t{\n\t\t\tcount[i1]=a1[i1]-a1[i1-1];\n\t\t\tint ctr=countDigits(a1[i1]);\n\t\t\tcount[i1]=count[i1]*ctr;\n\t\t\n\t\t}\n\t\tfor(int i=1;i<9;i++)\n\t\t{\n\t\t\tcount[i]=count[i]+count[i-1];\n\t\t\t\n\t\t}\n\t\n\t\tint l=next(a1,n);\n\t\tif(l!=-1 && l!=0)\n\t\t{\n\t\tl=l-1;\t\n\t pn((countDigits(n)*(n-a1[l]))+count[l]);\n\t\t}\n\t\telse\n\t\tif(l==-1)\n\t\t{\n\t\t\tl=8;\n\t\t\tpn((countDigits(n)*(n-a1[l]))+count[l]);\n\t\t\t\n\t\t}\n\t\t\n\t\t\n\t\n\t }\n\t\t\n\t}\npublic static void main(String[] args) throws IOException {\n\n\tprocess();\n}\n\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "6970d2444b629bd8d9140360420496e3", "src_uid": "4e652ccb40632bf4b9dd95b9f8ae1ec9", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class One {\n\n public static void main(String[] args) throws Exception {\nBufferedReader br = new BufferedReader(new InputStreamReader( System.in));\nint n=Integer.parseInt(br.readLine());\nString [] parts= br.readLine().split(\" \");\nint[] a= new int[n+1];\nfor(int i=0;i 1) {\n int sum = 0;\n for (int j = 0; j < data.length; j++) {\n if (((1 << j) & i) != 0) {\n sum += data[j];\n }\n }\n // System.out.println(sum + \" \" + data[index] + \" \" + Integer.bitCount(mask));\n if (sum + 1 == data[index]) {\n if (cal(index + 1, (mask ^ i) | (1 << index), data)) {\n return true;\n }\n }\n }\n\n if (i == 0) {\n break;\n }\n }\n return false;\n }\n\n }\n\n public static int[] KMP(String val) {\n int i = 0;\n int j = -1;\n int[] result = new int[val.length() + 1];\n result[0] = -1;\n while (i < val.length()) {\n while (j >= 0 && val.charAt(j) != val.charAt(i)) {\n j = result[j];\n }\n j++;\n i++;\n result[i] = j;\n }\n return result;\n\n }\n\n public static boolean nextPer(int[] data) {\n int i = data.length - 1;\n while (i > 0 && data[i] < data[i - 1]) {\n i--;\n }\n if (i == 0) {\n return false;\n }\n int j = data.length - 1;\n while (data[j] < data[i - 1]) {\n j--;\n }\n int temp = data[i - 1];\n data[i - 1] = data[j];\n data[j] = temp;\n Arrays.sort(data, i, data.length);\n return true;\n }\n\n public static int digit(long n) {\n int result = 0;\n while (n > 0) {\n n /= 10;\n result++;\n }\n return result;\n }\n\n public static double dist(long a, long b, long x, long y) {\n double val = (b - a) * (b - a) + (x - y) * (x - y);\n val = Math.sqrt(val);\n double other = x * x + a * a;\n other = Math.sqrt(other);\n return val + other;\n\n }\n\n public static class Point implements Comparable {\n\n int x, y;\n\n public Point(int start, int end) {\n this.x = start;\n this.y = end;\n }\n\n @Override\n public int hashCode() {\n int hash = 5;\n hash = 47 * hash + this.x;\n hash = 47 * hash + this.y;\n return hash;\n }\n\n @Override\n public boolean equals(Object obj) {\n if (obj == null) {\n return false;\n }\n if (getClass() != obj.getClass()) {\n return false;\n }\n final Point other = (Point) obj;\n if (this.x != other.x) {\n return false;\n }\n if (this.y != other.y) {\n return false;\n }\n return true;\n }\n\n @Override\n public int compareTo(Point o) {\n return Integer.compare(x, o.x);\n }\n }\n\n public static class FT {\n\n long[] data;\n\n FT(int n) {\n data = new long[n];\n }\n\n public void update(int index, long value) {\n while (index < data.length) {\n data[index] += value;\n index += (index & (-index));\n }\n }\n\n public long get(int index) {\n long result = 0;\n while (index > 0) {\n result += data[index];\n index -= (index & (-index));\n }\n return result;\n\n }\n }\n\n public static long gcd(long a, long b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n public static long pow(long a, long b, long MOD) {\n if (b == 0) {\n return 1;\n }\n if (b == 1) {\n return a;\n }\n long val = pow(a, b / 2, MOD);\n if (b % 2 == 0) {\n return val * val % MOD;\n } else {\n return val * (val * a % MOD) % MOD;\n\n }\n }\n\n static class Scanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n public Scanner() throws FileNotFoundException {\n // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));\n br = new BufferedReader(new InputStreamReader(System.in));\n // br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(\"input.txt\"))));\n }\n\n public String next() {\n\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n return st.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public String nextLine() {\n st = null;\n try {\n return br.readLine();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n\n public boolean endLine() {\n try {\n String next = br.readLine();\n while (next != null && next.trim().isEmpty()) {\n next = br.readLine();\n }\n if (next == null) {\n return true;\n }\n st = new StringTokenizer(next);\n return st.hasMoreTokens();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["constructive algorithms", "dp", "bitmasks", "greedy", "trees"], "code_uid": "55805aa188ba065b4bace6fac3ff2bef", "src_uid": "ed0925cfaee961a3ceebd13b3c96a15a", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n\t\n\tint solve(Scanner in, PrintWriter out)\n\t{\n\t\tint n = in.nextInt();\n\t\tint[] arr = new int[n];\n\t\t\n\t\tfor(int i = 0; i < n; i++)\n\t\t\tarr[i] = in.nextInt();\n\t\t\n\t\tif(n == 2)\n\t\t\tout.print(arr[1] + (arr[1] - arr[0]));\n\t\telse{\n\t\t\tint ans = 0;\n\t\t\tint step = arr[0] - arr[1]; \n\t\t\tfor(int i = 0; i < n-1; i++){\n\t\t\t\tif((arr[i] - arr[i+1]) == step)\n\t\t\t\t\tans = arr[n-1] +(arr[1] - arr[0]);\n\t\t\t\telse{\n\t\t\t\t\tans = arr[n - 1];\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tout.print(ans);\n\t\t}\n\t\t\n\t\t\treturn 0;\n\t\t\t\n\t}\n\n\tvoid run()\n\t{\n\t\ttry(\n\t\t\tScanner in = new Scanner(System.in);\n\t\t\tPrintWriter out = new PrintWriter(System.out)) {\n\t\t\n\t\t\tsolve(in, out);\n\t\t}\n\t}\n\tpublic static void main(String[] args) {\n\t\tnew Main().run();\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "c77115e976d5caae929be12c1e7e17e6", "src_uid": "d04fa4322a1b300bdf4a56f09681b17f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n \npublic class TestClass {\n public static void main(String args[]){\n Scanner in = new Scanner(System.in);\n int k = in.nextInt();\n int n = in.nextInt();\n int s = in.nextInt();\n int p = in.nextInt();\n int ans = (int)Math.ceil((double)(k * (int)Math.ceil((double)n/s)) / p);\n System.out.println(ans);\n }\n}", "lang_cluster": "Java", "tags": ["math"], "code_uid": "f6a52c18b912f66a9f7b9324f95faa90", "src_uid": "73f0c7cfc06a9b04e4766d6aa61fc780", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "//package codeforces.cp541;\n\nimport java.util.Scanner;\n\npublic class A {\n\t\n\tpublic static void getFourthSet(char[][] mB,String[] matrixB) {\n\t\tfor (int i = mB.length-1; i >= 0; i--) {\n\t\t\tString temp = \"\";\n\t\t\tfor (int j = mB.length - 1; j >= 0; j--) {\n\t\t\t\ttemp += (mB[j][i] + \"\");\n\t\t\t}\n\t\t\tmatrixB[6] += temp;\n\t\t\tmatrixB[7] += new StringBuilder(temp).reverse();\n\t\t}\n\t}\n\t\n\tpublic static void getThirdSet(char[][] mB, String[] matrixB) {\n\t\tfor (int i = 0; i < mB.length; i++) {\n\t\t\tString temp = \"\";\n\t\t\tfor (int j = mB.length - 1; j >= 0; j--) {\n\t\t\t\ttemp += (mB[j][i] + \"\");\n\t\t\t}\n\t\t\tmatrixB[4] += temp;\n\t\t\tmatrixB[5] += new StringBuilder(temp).reverse();\n\t\t}\n\t}\n\n\tpublic static void getSecondSet(char[][] mB, String[] matrixB) {\n\t\tfor (int i = mB.length - 1; i >= 0; i--) {\n\t\t\tString temp = \"\";\n\t\t\tfor (int j = 0; j < mB.length; j++) {\n\t\t\t\ttemp += (mB[i][j] + \"\");\n\t\t\t}\n\t\t\tmatrixB[2] += temp;\n\t\t\tmatrixB[3] += new StringBuilder(temp).reverse();\n\t\t}\n\t}\n\n\tpublic static void getFirstSet(char[][] mB, String[] matrixB) {\n\t\tfor (int i = 0; i < mB.length; i++) {\n\t\t\tString temp = \"\";\n\t\t\tfor (int j = 0; j < mB.length; j++) {\n\t\t\t\ttemp += (mB[i][j] + \"\");\n\t\t\t}\n\t\t\tmatrixB[0] += temp;\n\t\t\tmatrixB[1] += new StringBuilder(temp).reverse();\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tchar[][] mB = new char[n][n];\n\t\tString matrixA = \"\";\n\t\tString[] matrixB = new String[8];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tmatrixA += in.next();\n\t\t//System.out.println(matrixA);\n\t\tfor(int i=0;i<8;i++)\n\t\t\tmatrixB[i] = \"\";\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tmB[i] = in.next().toCharArray();\n\t\tgetFirstSet(mB, matrixB);\n\t\t//System.out.println(\"0 : \"+matrixB[0]);\n\t\t//System.out.println(\"1 : \"+matrixB[1]);\n\t\tif (matrixB[0].equals(matrixA) || matrixB[1].equals(matrixA)) {\n\t\t\tSystem.out.println(\"Yes\");\n\t\t} else {\n\t\t\tgetSecondSet(mB, matrixB);\n\t\t\t//System.out.println(\"2 : \"+matrixB[2]);\n\t\t\t//System.out.println(\"3 : \"+matrixB[3]);\n\t\t\tif (matrixB[2].equals(matrixA) || matrixB[3].equals(matrixA)) {\n\t\t\t\tSystem.out.println(\"Yes\");\n\t\t\t} else {\n\t\t\t\tgetThirdSet(mB, matrixB);\n\t\t\t\t//System.out.println(\"4 : \"+matrixB[4]);\n\t\t\t\t//System.out.println(\"5 : \"+matrixB[5]);\n\t\t\t\tif (matrixB[4].equals(matrixA) || matrixB[5].equals(matrixA)) {\n\t\t\t\t\tSystem.out.println(\"Yes\");\n\t\t\t\t} else {\n\t\t\t\t\tgetFourthSet(mB, matrixB);\n\t\t\t\t\tif (matrixB[6].equals(matrixA) || matrixB[7].equals(matrixA)) {\n\t\t\t\t\t\tSystem.out.println(\"Yes\");\n\t\t\t\t\t} else {\n\t\t\t\t\t\tSystem.out.println(\"No\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t}\n\t\tin.close();\n\t}\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "e092c83aab250d07043e42c952a490af", "src_uid": "2e793c9f476d03e8ba7df262db1c06e4", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Main{ \n public static void main(String[] arg){\n Scanner in = new Scanner(System.in);\n try (PrintWriter out = new PrintWriter(System.out)) {\n int p1 = in.nextInt(); \n int p2 = in.nextInt();\n int v1 = in.nextInt();\n int v2 = in.nextInt();\n if (Math.max(v1, v2) >= (p2 + p1) || (v1 >= p1 && v2 >= p2)) {\n\n out.println(\"Polycarp\");\n }\n else{\n out.println(\"Vasiliy\");\n } \n }\n }\n}", "lang_cluster": "Java", "tags": ["math", "greedy", "implementation", "games"], "code_uid": "74b47962d51bae03dc3676fd3f2f8261", "src_uid": "2637d57f7809ff8f922549c617709074", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "\nimport java.util.*;\nimport java.io.*;\n \npublic class Olimp {\n \n public static void main(String[] args) throws IOException {\n Scanner in = new Scanner(System.in);\n long x=in.nextLong();\n long y=in.nextLong();\n if(x>0 && y>0) System.out.println(0+\" \"+(x+y)+\" \"+(x+y)+\" \"+0);\n else if(x<0 && y>0) System.out.println((x-y)+\" \"+0+\" \"+0+\" \"+(-x+y));\n else if(x<0 && y<0) System.out.println((x+y)+\" \"+0+\" \"+0+\" \"+(x+y));\n else if(x>0 && y<0) System.out.println(0+\" \"+(-x+y)+\" \"+(x-y)+\" \"+0);\n }\n}", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "67ba0a28ecfb9fbeb26ca06f5e688138", "src_uid": "e2f15a9d9593eec2e19be3140a847712", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n int d[][] = new int[301][301];\n final int L = 1;\n final int NV = 0;\n final int W = 2;\n\n private void solve() throws IOException {\n int n = ni();\n int a[] = nia(n);\n\n if (n == 1) {\n if (a[0] == 0) {\n s();\n } else {\n f();\n }\n\n return;\n }\n\n if (n == 3) {\n if ((a[0] ^ a[1] ^ a[2]) == 0) {\n s();\n } else\n f();\n return;\n }\n\n if (go(a[0], a[1]) == W) {\n f();\n } else\n s();\n }\n\n private int go(int a, int b) {\n if (d[a][b] != NV)\n return d[a][b];\n\n for (int i = 1; i <= a; ++i) {\n if (go(a - i, b) == L)\n return d[a][b] = W;\n }\n\n for (int i = 1; i <= b; ++i) {\n if (go(a, b - i) == L)\n return d[a][b] = W;\n }\n\n for (int i = 1; i <= Math.min(a, b); ++i) {\n if (go(a - i, b - i) == L)\n return d[a][b] = W;\n }\n\n return d[a][b] = L;\n }\n\n private void s() {\n prln(\"BitAryo\");\n }\n\n private void f() {\n prln(\"BitLGM\");\n }\n\n /*\n * private void solve() throws IOException { int n = nextInt(); long a[] =\n * nextLongArray(n);\n * \n * long pref[] = new long[n + 1]; long suff[] = new long[n + 1];\n * \n * pref[0] = 0; suff[n] = 0;\n * \n * long xor = 0; for (int i = 1; i <= n; ++i) { xor = xor ^ a[i - 1]; pref[i]\n * = xor; }\n * \n * xor = 0; for (int i = n - 1; i >= 0; --i) { xor = xor ^ a[i]; if (xor >\n * suff[i + 1]) suff[i] = xor; else suff[i] = suff[i + 1]; }\n * \n * long plesure = 0; for (int i = 0; i <= n; ++i) { if ((pref[i] ^ suff[i]) >\n * plesure) plesure = pref[i] + suff[i]; }\n * \n * println(plesure); }\n */\n\n /*\n * private void qsort(int a[]) { Random rand = new Random(271828182l);\n * qsort(a, 0, a.length, rand); }\n * \n * private void qsort(int a[], int l, int r, Random rand) { if (r - l <= 1)\n * return;\n * \n * int x = a[rand.nextInt(r - l) + l]; int i = l, j = r - 1; while (i < j) {\n * while (a[i] < x) ++i; while (a[j] > x) --j; if (i < j) { int t = a[i];\n * a[i] = a[j]; a[j] = t; ++i; --j; } }\n * \n * qsort(a, l, i, rand); qsort(a, j + 1, r, rand); }\n */\n\n private int[] nia(int n) throws IOException {\n int arr[] = new int[n];\n for (int i = 0; i < n; ++i)\n arr[i] = Integer.parseInt(nextToken());\n return arr;\n }\n\n private long[] nla(int n) throws IOException {\n long arr[] = new long[n];\n for (int i = 0; i < n; ++i)\n arr[i] = Long.parseLong(nextToken());\n return arr;\n }\n\n public static void main(String[] args) {\n new Main().run();\n }\n\n public void run() {\n try {\n if (isFileIO) {\n pw = new PrintWriter(new File(\"output.out\"));\n br = new BufferedReader(new FileReader(\"input.in\"));\n } else {\n pw = new PrintWriter(System.out);\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n solve();\n pw.close();\n br.close();\n } catch (IOException e) {\n System.err.println(\"IO Error\");\n }\n }\n\n private void pr(Object o) {\n pw.print(o);\n }\n\n private void prln(Object o) {\n pw.println(o);\n }\n\n private void prln() {\n pw.println();\n }\n\n int ni() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n long nl() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n double nd() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n private String nextToken() throws IOException {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(br.readLine());\n }\n\n return tokenizer.nextToken();\n }\n\n private BufferedReader br;\n private StringTokenizer tokenizer;\n private PrintWriter pw;\n private final boolean isFileIO = false;\n}", "lang_cluster": "Java", "tags": ["dp", "games"], "code_uid": "e42e651a7bf1f8cedc940321ef87f697", "src_uid": "7a33b4f94082c7ef80d7e87b58497fa7", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.Scanner;\npublic class littel_arthem {\n public static void main(String args[])\n {\n Scanner sc = new Scanner(System.in);\n int no = sc.nextInt();\n int row = 0;\n int col = 0;\n if(no == 1)\n {\n System.out.println(\"1 1\");\n }\n else if(no == 2)\n {\n System.out.println(\"1 2\");\n }\n else if(no == 3)\n {\n System.out.println(\"1 3\");\n }\n else\n {\n for(int i=(int)Math.sqrt(no);i>=1;i--)\n {\n if(no%i==0)\n {\n row = i;\n col = no/i;\n break;\n }\n }\n System.out.println(row+\" \"+col);\n }\n \n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "math"], "code_uid": "681782ee516a46cbade692862f4a8eac", "src_uid": "f52af273954798a4ae38a1378bfbf77a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class chess {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\tArrayList a=new ArrayList();\n\t\tfor(int i=0;i=0;i--){\n\t\t\tans1+=Math.abs(x-a.get(i));\n\t\t\tans2+=Math.abs(x-1-a.get(i));\n\t\t\tx=x-2;\n\t\t}\n\t\tSystem.out.println(Math.min(ans1, ans2));\n\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "2324fb38a55a298de6529f9512ed5717", "src_uid": "0efe9afd8e6be9e00f7949be93f0ca1a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n \npublic class Main {\n static final int MODULO = 1_000_000_000 + 7;\n static String subsequence;\n static int[][] nextPosition;\n static int[][][][] dp;\n public static void main(String[] args) throws Exception {\n FastScanner sc = new FastScanner(System.in);\n PrintWriter pw = new PrintWriter(System.out);\n int maxBalance = sc.nextInt();\n int length = 2 * maxBalance;\n subsequence = sc.next();\n nextPosition = new int[subsequence.length() + 1][2];\n for (int i = 0; i <= subsequence.length(); ++i) {\n for (int type = 0; type < 2; ++type) {\n char parenthesis = \"()\".charAt(type);\n int k;\n link:\n for (k = Math.min(subsequence.length(), i + 1); k > 0; --k) {\n if (subsequence.charAt(k - 1) != parenthesis) continue;\n for (int j = k - 1; j-- > 0; ) {\n if (subsequence.charAt(j) != subsequence.charAt(i - k + 1 + j)) {\n continue link;\n }\n }\n break;\n }\n nextPosition[i][type] = k;\n }\n }\n dp = new int[length + 1][maxBalance + 1][subsequence.length() + 1][2];\n dp[0][0][0][0] = 1;\n for (int len = 0; len < length; ++len) {\n for (int balance = 0; balance <= Math.min(len, maxBalance); ++balance) {\n for (int pos = 0; pos <= Math.min(len, subsequence.length()); ++pos) {\n for (int was = 0; was < 2; ++was) {\n if (dp[len][balance][pos][was] == 0) continue;\n if (balance < maxBalance) {\n update(len, balance, pos, was, '(');\n }\n if (balance > 0) {\n update(len, balance, pos, was, ')');\n }\n }\n }\n }\n }\n int sum = 0;\n for (int pos = 0; pos <= subsequence.length(); ++pos) {\n sum = sum(sum, dp[length][0][pos][1]);\n }\n pw.println(sum);\n pw.flush();\n }\n \n static private void update(int len, int balance, int pos, int was, char parenthesis) {\n int nextLen = len + 1;\n int nextBalance = balance + (parenthesis == '(' ? 1 : -1);\n int nextPos = nextPosition[pos][\"()\".indexOf(parenthesis)];\n int nextWas = was | (nextPos == subsequence.length() ? 1 : 0);\n dp[nextLen][nextBalance][nextPos][nextWas] =\n sum(dp[nextLen][nextBalance][nextPos][nextWas], dp[len][balance][pos][was]);\n }\n \n static private int sum(int first, int second) {\n return (first + second) % MODULO;\n }\n\n static class GeekInteger {\n public static void save_sort(int[] array) {\n shuffle(array);\n Arrays.sort(array);\n }\n \n public static int[] shuffle(int[] array) {\n int n = array.length;\n Random random = new Random();\n for (int i = 0, j; i < n; i++) {\n j = i + random.nextInt(n - i);\n int randomElement = array[j];\n array[j] = array[i];\n array[i] = randomElement;\n }\n return array;\n }\n \n }\n}\n\nclass FastScanner {\n private BufferedReader reader = null;\n private StringTokenizer tokenizer = null;\n public FastScanner(InputStream in) {\n reader = new BufferedReader(new InputStreamReader(in));\n tokenizer = null;\n }\n\n public String next() {\n if (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public String nextLine() {\n if (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n return reader.readLine();\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken(\"\\n\");\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n \n public String[] nextArray(int n) {\n String[] a = new String[n];\n for (int i = 0; i < n; i++)\n a[i] = next();\n return a;\n }\n\n public int[] nextIntArray(int n) {\n int[] a = new int[n];\n for (int i = 0; i < n; i++)\n a[i] = nextInt();\n return a;\n }\n\n public long[] nextLongArray(int n) {\n long[] a = new long[n];\n for (int i = 0; i < n; i++)\n a[i] = nextLong();\n return a;\n } \n}\n", "lang_cluster": "Java", "tags": ["strings", "dp"], "code_uid": "c2ba52205a2e2274c54bfd5531b1b436", "src_uid": "590a49a7af0eb83376ed911ed488d7e5", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "\nimport java.util.Scanner;\n\npublic class E {\n static long mod = (long) (1e9 + 7);\n\n public static long pow(long x, long pow) {\n if (pow == 0)\n return 1;\n long temp = pow(x, pow >> 1);\n temp = (temp * temp) % mod;\n if ((pow & 1) != 0)\n temp = (temp * x) % mod;\n return temp;\n }\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int[] A = { 1, 2, 4, 6, 12, 16, 18, 30, 60, 88, 106, 126, 520, 606,\n 1278, 2202, 2280, 3216, 4252, 4422, 9688, 9940, 11212, 19936,\n 21700, 23208, 44496, 86242, 110502, 132048, 216090, 756838,\n 859432, 1257786, 1398268, 2976220, 3021376, 6972592, 13466916,\n 20996010 };\n System.out.println((pow(2, A[n - 1]) + mod - 1) % mod);\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "number theory"], "code_uid": "f0fcb7f76d3be27e3d3b216d9a6385da", "src_uid": "c2cbc35012c6ff7ab0d6899e6015e4e7", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.Random;\nimport java.util.StringTokenizer;\n\npublic class F {\n\n\tstatic char[] line, t;\n\tstatic long[][][] dp;\n\t\n\tpublic static void main(String[] args) {\n\t\tFastScanner fs=new FastScanner();\n\t\tint n=fs.nextInt(), k=fs.nextInt();\n\t\tline=fs.next().toCharArray();\n\t\tt=fs.next().toCharArray();\n\t\tif (t[0]==t[1]) {\n\t\t\tint count=0;\n\t\t\tfor (char c:line) if (c==t[0]) count++;\n\t\t\tcount+=k;\n\t\t\tcount=Math.min(count, n);\n\t\t\tSystem.out.println(count*(long)(count-1)/2);\n\t\t}\n\t\telse {\n\t\t\tdp=new long[n+1][n+1][n+1];\n\t\t\tfor (int i=0; i=line.length) return 0;\n\t\tif (dp[position][nT0][k]!=-1) return dp[position][nT0][k];\n\t\tlong ans=0;\n\t\t//neither\n\t\tans=Math.max(ans, go(position+1, nT0, k));\n\t\t\n\t\t//make T0\n\t\tint cost=line[position]==t[0]?0:1;\n\t\tif (k>=cost) {\n\t\t\tans=Math.max(ans, go(position+1, nT0+1, k-cost));\n\t\t}\n\t\t\n\t\t//make T1\n\t\tcost=line[position]==t[1]?0:1;\n\t\tif (k>=cost) {\n\t\t\tans=Math.max(ans, nT0+go(position+1, nT0, k-cost));\n\t\t}\n\t\t\n\t\treturn dp[position][nT0][k]=ans;\n\t}\n\t\n\tstatic final Random random=new Random();\n\t\n\tstatic void ruffleSort(int[] a) {\n\t\tint n=a.length;//shuffle, then sort \n\t\tfor (int i=0; i[] ngw(int n, int m) {\r\n ArrayList[] graph=(ArrayList[])new ArrayList[n];\r\n for(int i=0;i();\r\n }\r\n for(int i=1;i<=m;i++) {\r\n long s=in.nextLong()-1,e=in.nextLong()-1,w=in.nextLong();\r\n graph[(int)s].add(new long[] {e,w});\r\n graph[(int)e].add(new long[] {s,w});\r\n }\r\n return graph;\r\n }\r\n\r\n private int ni() {\r\n return in.nextInt();\r\n }\r\n\r\n private long nl() {\r\n return in.nextLong();\r\n }\r\n\r\n private String ns() {\r\n return in.next();\r\n }\r\n\r\n private long[] na(int n) {\r\n long[] A=new long[n];\r\n for(int i=0;i= endSum) {\n\t\t\tisTrue = \"Yes\";\n\t\t} else {\n\t\t\tisTrue = \"No\";\n\t\t}\n\t\tSystem.out.println(isTrue);\n\t}\n}\n//hello", "lang_cluster": "Java", "tags": ["math"], "code_uid": "f628cf0d8a4d9894629b1f922e2d0b3b", "src_uid": "e0ddac5c6d3671070860dda10d50c28a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.util.StringTokenizer;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n Parser in = new Parser(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n}\n\nclass TaskC {\n int mod = 1000000007;\n\n public void solve(int testNumber, Parser in, OutputWriter out) {\n long n = in.nextLong();\n int k = in.nextInt();\n\n long[][] pas = MathUtils.pas(41, mod);\n Matrix a = new Matrix(83);\n\n a.a[0][0] = 1;\n a.a[0][k+1] = 1;\n\n for (int pot = 0; pot <= 40; pot++) {\n for (int coef = 0; coef <= pot; coef++) {\n a.a[pot+1][coef+1] = pas[pot][coef];\n a.a[pot+1][coef+42] = (pas[pot][coef] * ((1L << (pot-coef)) % mod)) % mod;\n }\n }\n\n for (int pot = 0; pot <= 40; pot++) {\n a.a[pot+42][pot+1] = 1;\n }\n\n Matrix b = new Matrix(83);\n for (int i = 1; i <= 42; i++) b.a[i][0] = 1;\n\n a = a.modpow(n, mod);\n a = a.multiply(b, mod);\n /*for (int i = 0; i < 83; i++) {\n System.out.println(\"i \" + i + \" elem: \" + a.a[i][0]);\n }*/\n\n out.println(a.a[0][0]);\n }\n}\n\nclass Parser\n{\n private BufferedReader din;\n private StringTokenizer tokenizer;\n\n public Parser(InputStream in)\n {\n din = new BufferedReader(new InputStreamReader(in));\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(din.readLine());\n } catch (Exception e) {\n throw new UnknownError();\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt()\n {\n return Integer.parseInt(next());\n }\n\n public long nextLong()\n {\n return Long.parseLong(next());\n }\n\n }\n\nclass OutputWriter extends PrintWriter {\n public OutputWriter(Writer out) {\n super(out);\n }\n\n public OutputWriter(OutputStream out) {\n super(out);\n }\n\n }\n\nclass MathUtils {\n\n public static long[][] pas(int n, int mod) {\n long[][] ret = new long[n+1][n+1];\n\n for (int i = 0; i <= n; i++) {\n ret[i][0] = 1;\n for (int j = 1; j <= i; j++) {\n ret[i][j] = (ret[i-1][j-1] + ret[i-1][j]) % mod;\n }\n }\n\n return ret;\n }\n\n }\n\nclass Matrix {\n int n;\n long a[][];\n\n public Matrix(int n) {\n this.n = n;\n a = new long[n][n];\n }\n\n public static Matrix identity(int n) {\n Matrix ret = new Matrix(n);\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n ret.a[i][j] = 0;\n }\n ret.a[i][i] = 1;\n }\n\n return ret;\n }\n\n Matrix multiply(Matrix b, long mod) {\n Matrix resp = new Matrix(n);\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n resp.a[i][j] = 0;\n for (int k = 0; k < n; k++) {\n resp.a[i][j] = (resp.a[i][j] + a[i][k] * b.a[k][j]) % mod;\n }\n }\n }\n\n return resp;\n }\n\n Matrix modpow(long exp, long mod) {\n if (exp == 0) return identity(n);\n if (exp == 1) return this;\n\n Matrix h = modpow(exp/2, mod);\n h = h.multiply(h, mod);\n if (exp % 2 == 1) h = h.multiply(this, mod);\n\n return h;\n }\n\n }\n", "lang_cluster": "Java", "tags": ["math", "matrices", "combinatorics"], "code_uid": "40b2d53497644cf73102cf5048663d85", "src_uid": "14f50a111db268182e5927839a993118", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class A1008 {\n public static void main(String [] args) /*throws Exception*/ {\n InputStream inputReader = System.in;\n OutputStream outputReader = System.out;\n InputReader in = new InputReader(inputReader);//new InputReader(new FileInputStream(new File(\"input.txt\")));new InputReader(inputReader);\n PrintWriter out = new PrintWriter(outputReader);//new PrintWriter(new FileOutputStream(new File(\"output.txt\")));\n Algorithm solver = new Algorithm();\n solver.solve(in, out);\n out.close();\n }\n}\n\nclass Algorithm {\n void solve(InputReader ir, PrintWriter pw) {\n\n String password = ir.next();\n int n = ir.nextInt();\n String line = \"\";\n int [] first = new int[2], second = new int[2];\n char one = password.charAt(0), two = password.charAt(1);\n\n for (int i = 0; i < n; i++) line = line + ir.next();\n char [] tries = line.toCharArray();\n\n for (int i = 1; i < n * 2; i++) {\n if ((tries[i - 1] == one && tries[i] == two) || (tries[i - 1] == two && tries[i] == one)) {\n pw.print(\"YES\");\n return;\n }\n }\n\n for (int i = 0; i < n * 2; i++) {\n if (tries[i] == one) {\n if (i % 2 == 0) first[0]++;\n else first[1]++;\n } else if (tries[i] == two && i % 2 == 0) second[0]++;\n }\n\n if (first[1] > 0 && second[0] > 0 || (first[0] > 0 && first[1] > 0 && one == two)) pw.print(\"YES\");\n else pw.print(\"NO\");\n }\n\n private static void Qsort(int[] array, int low, int high) {\n\n int i = low;\n int j = high;\n int x = array[low + (high - low) / 2];\n\n do {\n while (array[i] < x) ++i;\n while (array[j] > x) --j;\n if (i <= j) {\n int tmp = array[i];\n array[i] = array[j];\n array[j] = tmp;\n i++;\n j--;\n }\n } while (i <= j);\n\n if (low < j) Qsort(array, low, j);\n if (i < high) Qsort(array, i, high);\n\n }\n}\n\nclass InputReader {\n private BufferedReader reader;\n private StringTokenizer tokenizer;\n\n InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n String nextLine(){\n String fullLine = null;\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n fullLine = reader.readLine();\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n return fullLine;\n }\n return fullLine;\n }\n\n String [] toArray() {\n return nextLine().split(\" \");\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n double nextDouble() {\n return Double.parseDouble(next());\n }\n long nextLong() {\n return Long.parseLong(next());\n }\n\n}", "lang_cluster": "Java", "tags": ["brute force", "strings", "implementation"], "code_uid": "4df753b04840cf606af745f2d6249c8d", "src_uid": "cad8283914da16bc41680857bd20fe9f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Div680 {\r\n ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n//////// /////////\r\n//////// /////////\r\n//////// HHHH HHHH EEEEEEEEEEEEE MMMM MMMM OOOOOO SSSSSSS EEEEEEEEEEEEE /////////\r\n//////// HHHH HHHH EEEEEEEEEEEEE MMMMMM MMMMMM OOO OOO SSSS SSS EEEEEEEEEEEEE /////////\r\n//////// HHHH HHHH EEEEE MMMM MMM MMM MMMM OOO OOO SSSS SSS EEEEE /////////\r\n//////// HHHH HHHH EEEEE MMMM MMMMMM MMMM OOO OOO SSSS EEEEE /////////\r\n//////// HHHH HHHH EEEEE MMMM MMMM OOO OOO SSSSSSS EEEEE /////////\r\n//////// HHHHHHHHHHHHHHHH EEEEEEEEEEE MMMM MMMM OOO OOO SSSSSS EEEEEEEEEEE /////////\r\n//////// HHHHHHHHHHHHHHHH EEEEEEEEEEE MMMM MMMM OOO OOO SSSSSSS EEEEEEEEEEE /////////\r\n//////// HHHH HHHH EEEEE MMMM MMMM OOO OOO SSSS EEEEE /////////\r\n//////// HHHH HHHH EEEEE MMMM MMMM OOO OOO SSS SSSS EEEEE /////////\r\n//////// HHHH HHHH EEEEEEEEEEEEE MMMM MMMM OOO OOO SSS SSSS EEEEEEEEEEEEE /////////\r\n//////// HHHH HHHH EEEEEEEEEEEEE MMMM MMMM OOOOOO SSSSSSS EEEEEEEEEEEEE /////////\r\n//////// /////////\r\n//////// /////////\r\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\r\n\r\n static int n, mod, offset, dp[][][];\r\n\r\n static int dp(int done, int i, int diff) {\r\n\r\n if (i == n)\r\n return diff > 0 ? 1 : 0;\r\n\r\n if (dp[done][i][diff + offset] != -1)\r\n return dp[done][i][diff + offset];\r\n int rem = n - i;\r\n int ans = 0;\r\n for (int l = 0; l < rem; l++) {\r\n for (int r = done == 1 ? 0 : l; r < rem; r++) {\r\n ans += dp(done | (l < r ? 1 : 0), i + 1, diff + l - r);\r\n ans %= mod;\r\n }\r\n }\r\n return dp[done][i][diff + offset] = ans;\r\n }\r\n\r\n static long dp2(int i) {\r\n if (i == n - 1)\r\n return 0;\r\n long ans = (n - i) * 1l * dp2(i + 1);\r\n ans %= mod;\r\n for (int l = 0; l < n - i; l++) {\r\n for (int r = l + 1; r < n - i; r++) {\r\n ans += dp(1, i + 1, l - r);\r\n ans %= mod;\r\n }\r\n }\r\n return ans;\r\n }\r\n\r\n public static void main(String[] args) throws IOException {\r\n Scanner sc = new Scanner(System.in);\r\n PrintWriter pw = new PrintWriter(System.out);\r\n n = sc.nextInt();\r\n mod = sc.nextInt();\r\n offset = n * (n - 1);\r\n dp = new int[2][n][2 * offset + 1];\r\n\r\n for (int[][] x : dp)\r\n for (int[] y : x)\r\n Arrays.fill(y, -1);\r\n\r\n pw.println(dp2(0));\r\n pw.flush();\r\n }\r\n\r\n static long gcd(long a, long b) {\r\n if (a == 0)\r\n return b;\r\n return gcd(b % a, a);\r\n }\r\n\r\n static class Scanner {\r\n StringTokenizer st;\r\n BufferedReader br;\r\n\r\n public Scanner(FileReader r) {\r\n br = new BufferedReader(r);\r\n }\r\n\r\n public Scanner(InputStream s) {\r\n br = new BufferedReader(new InputStreamReader(s));\r\n }\r\n\r\n public String next() throws IOException {\r\n while (st == null || !st.hasMoreTokens())\r\n st = new StringTokenizer(br.readLine());\r\n return st.nextToken();\r\n }\r\n\r\n public int[] nextIntArr(int n) throws IOException {\r\n int[] a = new int[n];\r\n for (int i = 0; i < n; i++) {\r\n a[i] = nextInt();\r\n }\r\n return a;\r\n }\r\n\r\n public int nextInt() throws IOException {\r\n return Integer.parseInt(next());\r\n }\r\n\r\n public long nextLong() throws IOException {\r\n return Long.parseLong(next());\r\n }\r\n\r\n public String nextLine() throws IOException {\r\n return br.readLine();\r\n }\r\n\r\n public double nextDouble() throws IOException {\r\n String x = next();\r\n StringBuilder sb = new StringBuilder(\"0\");\r\n double res = 0, f = 1;\r\n boolean dec = false, neg = false;\r\n int start = 0;\r\n if (x.charAt(0) == '-') {\r\n neg = true;\r\n start++;\r\n }\r\n for (int i = start; i < x.length(); i++)\r\n if (x.charAt(i) == '.') {\r\n res = Long.parseLong(sb.toString());\r\n sb = new StringBuilder(\"0\");\r\n dec = true;\r\n } else {\r\n sb.append(x.charAt(i));\r\n if (dec)\r\n f *= 10;\r\n }\r\n res += Long.parseLong(sb.toString()) / f;\r\n return res * (neg ? -1 : 1);\r\n }\r\n\r\n public boolean ready() throws IOException {\r\n return br.ready();\r\n }\r\n }\r\n\r\n}\r\n", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics", "fft"], "code_uid": "11e1a87772d19c7591866eef79fa7a21", "src_uid": "ae0320a57d73fab1d05f5d10fbdb9e1a", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class weather\n{\n public static void main(String []args)throws IOException\n {\n Scanner sc = new Scanner(System.in);\n long a,b;\n a = sc.nextLong();\n b = sc.nextLong();\n long val = a-b;\n if(val == 0)\n {\n System.out.println(\"infinity\");\n System.exit(0);\n }\n //System.out.println(val);\n long count = 0;\n for(long i=1;i<=Math.sqrt(val);i++)\n {\n if(val%i == 0 && i > b) \n count++;\n if(val%(val/i) == 0 && (val/i) != i && (val/i) > b) \n count++;\n }\n\n System.out.println(count);\n }\n}", "lang_cluster": "Java", "tags": ["math", "number theory"], "code_uid": "f844a24baaafefddf216756bb3e66eb7", "src_uid": "6e0715f9239787e085b294139abb2475", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.LinkedList;\nimport java.util.Locale;\nimport java.util.Queue;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\npublic class Solution implements Runnable {\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st;\n\n\tString nextToken() throws Exception {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tint nextInt() throws Exception {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws Exception {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws Exception {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\t\n\tclass Point {\n\t\tlong a, b;\n\t\tPoint(long q, long w) {\n\t\t\ta = q; b = w;\n\t\t}\n\t\tPoint sub(Point z) {\n\t\t\treturn new Point(a - z.a, b - z.b);\n\t\t}\n\t\tlong vp(Point z) {\n\t\t\treturn a * z.b - b * z.a;\n\t\t}\n\t}\n\t\n\tvoid solve() throws Exception {\n\t\tPoint a = new Point(nextInt(), nextInt());\n\t\tPoint b = new Point(nextInt(), nextInt());\n\t\tPoint c = new Point(nextInt(), nextInt());\n\t\tlong vp = b.sub(a).vp(c.sub(b));\n\t\tif (vp == 0) out.println(\"TOWARDS\");\n\t\tif (vp > 0) out.println(\"LEFT\");\n\t\tif (vp < 0) out.println(\"RIGHT\");\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tLocale.setDefault(Locale.UK);\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n//\t\t\tin = new BufferedReader(new FileReader(\"input.txt\"));\n//\t\t\tout = new PrintWriter(\"output.txt\");\n\t\t\tsolve();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t} finally {\n\t\t\tout.close();\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\t// new Thread(null, new Solution(), \"1\", 1 << 28).start();\n\t\t(new Solution()).run();\n\t}\n\n}", "lang_cluster": "Java", "tags": ["geometry"], "code_uid": "92b50a95c7fb4de508177bac579e430a", "src_uid": "f6e132d1969863e9f28c87e5a44c2b69", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class FriendsMeeting {\n\t\n\t\n\tpublic static void main(String args[]) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint x1 = sc.nextInt();\n\t\tint x2 = sc.nextInt();\n\t\tSystem.out.println(findFriendsMeeting(x1, x2));\n\t\tsc.close();\n\t}\n\t\n\tpublic static int findFriendsMeeting(int x1, int x2) {\n\t\tint count = 0;\n\t\tint index = 1;\n\t\tint temp = 0;\n\t\tif (x1 > x2) {\n\t\t\ttemp = x2;\n\t\t\tx2 = x1;\n\t\t\tx1 = temp;\n\t\t} \n\t\twhile (x1 < x2 - 1) {\n\t\t\tx1++;\n\t\t\tx2--;\n\t\t\tcount = count + (index * 2);\n\t\t\tindex++;\n\t\t}\n\t\tif (x1 != x2)\n\t\t\tcount = count + index;\n\t\treturn count;\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["math", "greedy", "implementation", "brute force"], "code_uid": "39ab1073a21a15f43b27fbe1a560fa46", "src_uid": "d3f2c6886ed104d7baba8dd7b70058da", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.Scanner;\n\npublic class Main {\n\n static HashSet perm = new HashSet();\n static HashSet vis = new HashSet();\n static int freq[] = new int[300];\n static String str;\n static void build(String path){\n if(path.length() == str.length()){\n perm.add(path);\n return;\n }\n \n for (char i = 'A'; i <= 'Z'; i++) {\n if(freq[i]>0){\n --freq[i];\n build(path+i);\n ++freq[i];\n }\n }\n }\n \n static String rotateRight(String str){\n String tmp = str;\n char [] arr = str.toCharArray();\n arr[0] = tmp.charAt(1);\n arr[1] = tmp.charAt(2);\n arr[2] = tmp.charAt(3);\n arr[3] = tmp.charAt(0);\n return String.valueOf(arr);\n }\n static String rotateLeft(String str){\n String tmp = str;\n char [] arr = str.toCharArray();\n arr[0] = tmp.charAt(3);\n arr[1] = tmp.charAt(0);\n arr[2] = tmp.charAt(1);\n arr[3] = tmp.charAt(2);\n return String.valueOf(arr);\n }\n static String rotateFront(String str){\n String tmp = str;\n char [] arr = str.toCharArray();\n arr[0] = tmp.charAt(5);\n arr[2] = tmp.charAt(4);\n arr[4] = tmp.charAt(0);\n arr[5] = tmp.charAt(2);\n return String.valueOf(arr);\n }\n static String rotateBack(String str){\n String tmp = str;\n char [] arr = str.toCharArray();\n arr[0] = tmp.charAt(4);\n arr[2] = tmp.charAt(5);\n arr[4] = tmp.charAt(2);\n arr[5] = tmp.charAt(0);\n return String.valueOf(arr);\n }\n \n static void BFS(String str){\n LinkedList q = new LinkedList();\n q.add(str);\n \n vis.add(str);\n while(!q.isEmpty()){\n str = q.getFirst();\n q.removeFirst();\n String r = rotateRight(str);\n String l = rotateLeft(str);\n String f = rotateFront(str);\n String b = rotateBack(str);\n \n if(!vis.contains(r)){\n vis.add(r);\n q.add(r);\n }\n if(!vis.contains(l)){\n vis.add(l);\n q.add(l);\n }\n if(!vis.contains(f)){\n vis.add(f);\n q.add(f);\n }\n if(!vis.contains(b)){\n vis.add(b);\n q.add(b);\n }\n }\n }\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n str = sc.next();\n for (int i = 0; i < str.length(); i++) \n ++freq[str.charAt(i)];\n \n build(\"\");\n BFS(str);\n \n int res=1;\n String arr[] = new String[perm.size()];\n perm.toArray(arr);\n for (int i = 0; i < arr.length; i++) {\n if(!vis.contains(arr[i])){\n ++res;\n BFS(arr[i]);\n }\n }\n \n System.out.println(res);\n }\n\n}\n", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "d7d1e44590900f78b3d6bc1090218a44", "src_uid": "8176c709c774fa87ca0e45a5a502a409", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.text.DecimalFormat;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.Map.Entry;\nimport java.util.Queue;\nimport java.util.Scanner;\nimport java.util.Set;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.Vector;\n \n \npublic class Main {\n\tpublic static void main(String[] args) throws IOException{\n\t\t \tFastScanner sc = new FastScanner();\n\t\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t\tchar a[][]=new char[4][4];\n\t\t\tfor(int i=0;i<4;i++)\n\t\t\t\ta[i]=sc.nextToken().toCharArray();\n\t\t\tif(could(a)){\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfor(int i=0;i<4;i++)\n\t\t\t\tfor(int j=0;j<4;j++)\n\t\t\t\t\tif(a[i][j]=='.'){\n\t\t\t\t\t\ta[i][j]='x';\n\t\t\t\t\t\tif(could(a)){\n\t\t\t\t\t\t\t//System.out.println(i+\" \"+j);\n\t\t\t\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\ta[i][j]='.';\n\t\t\t\t\t}\n\t\t\tSystem.out.println(\"NO\");\n\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\n\t}\n\t\n\n\n\t\t\n\t\n\t\t\t\n\t\t\n\t\n\n\t\t\t\n\n\tpublic static boolean could(char a[][])\t{\n\t\t//row\n\t\tfor(int i=0;i<4;i++){\n\t\t\tif(a[i][0]=='x' && a[i][1]=='x' && a[i][2]=='x')\n\t\t\t\treturn true;\n\t\t\tif(a[i][0+1]=='x' && a[i][1+1]=='x' && a[i][2+1]=='x')\n\t\t\t\treturn true;\n\t\t}\n\t\t\n\t\tfor(int i=0;i<4;i++){\n\t\t\tif(a[0][i]=='x' && a[1][i]=='x' && a[2][i]=='x')\n\t\t\t\treturn true;\n\t\t\tif(a[1][i]=='x' && a[2][i]=='x' && a[3][i]=='x')\n\t\t\t\treturn true;\n\t\t}\n\t\t\n\t\tif(a[0][0]=='x' && a[1][1]=='x' && a[2][2]=='x')return true;\n\t\tif(a[1][1]=='x' && a[1+1][1+1]=='x' && a[2+1][2+1]=='x')return true;\n\t\tif(a[0][3]=='x' && a[1][2]=='x' && a[2][1]=='x')\n\t\t\treturn true;\n\t\tif( a[1][2]=='x' && a[2][1]=='x' && a[3][0]=='x')return true;\n\t\tif(a[2][0]=='x' && a[1][1]=='x' && a[0][2]=='x')return true;\n\t\tif(a[3][1]=='x' && a[2][2]=='x' && a[1][3]=='x')return true;\n\t\tif(a[3][2]=='x' && a[2][1]=='x' && a[1][0]=='x')return true;\n\t\tif(a[2][3]=='x' && a[1][2]=='x' && a[0][1]=='x')return true;\n\n\n\n\t\t\n\t\t\n\t\t\n\t\treturn false;\n\n\t\t\n\t\t\t\t\n\t\t\n\t\t\n\t}\n\t\t\t\n\t\t\t\n\t\n\t\n\n\n\n\t\n\t\n\t\t\t \n\t\t\t\n\n\n\t\t\t\n\t\t\t\n\t\n\t\n\t\n\n\t\t\t\n\t\n\t\t\n\t\n\t\n\t\n\t\t\n\n\t\t\t\n\n\t\t\n\n\t\n\t\n\n\t\n\t\n\t\n\n\t\t\t\n\t\t\t\t\t\t\n\t\t\t\n\n\t\n\t\n\n\t\t\n\t\t\n\t\t\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\tstatic void shuffle(int[] a)\n\t{\n\t\tint n = a.length;\n\t\tfor(int i = 0; i < n; ++i)\n\t\t{\n\t\t\tint r = i + (int)(Math.random() * (n - i));\n\t\t\tint tmp = a[r];\n\t\t\ta[r] = a[i];\n\t\t\ta[i] = tmp;\n\t\t}\n\t}\n\n\n\tstatic void generate(int[] p, int L, int R) {\n\t\t if (L == R) {\n\t\t \n\t\t \n\t\t }else { \n\t\t for (int i = L; i <= R; i++) {\n\t\t \tint tmp = p[L]; p[L] = p[i]; p[i] = tmp;//swap\n\t\t generate(p, L+1, R);//recurse \n\t\t tmp = p[L]; p[L] = p[i]; p[i] = tmp;//unswap\n\n\t\t }\n\t\t }\n\t\t}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n}\n\t \n\n\n\t\n\t\n\t\n\t\n\n\n\n\n\n\n\n\n\n\n\n\t\n \n \n \n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \nclass FastScanner {\n \n \n \n \n BufferedReader br;\n StringTokenizer st;\n \n public FastScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n \n public FastScanner(String s) {\n try {\n br = new BufferedReader(new FileReader(s));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n \n String nextToken() {\n while (st == null || !st.hasMoreElements()) {\n try {\n \n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n \n \n}", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "528fc2c5eb6533e91b7a633eae8c832f", "src_uid": "ca4a77fe9718b8bd0b3cc3d956e22917", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\n\nimport java.awt.geom.Point2D;\nimport java.text.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Main implements Runnable {\n\n\tfinal String filename = \"\";\n\n\tpublic void solve() throws Exception {\n\t\tint l = iread(), r = iread();\n\n\t\tlong ans = 0;\n\t\tlong x = 1, y = 10;\n\t\twhile (x <= r) {\n\t\t\tlong a = Math.max(l, x), b = Math.min(r, y - 1);\n\t\t\tif (a <= b) {\n\t\t\t\tans = Math.max(ans, a * (y - 1 - a));\n\t\t\t\tans = Math.max(ans, b * (y - 1 - b));\n\t\t\t\tlong z = y / 2;\n\t\t\t\tif (a <= z && z <= b)\n\t\t\t\t\tans = Math.max(ans, z * (y - 1 - z));\n\t\t\t\tz = y / 2 + 1;\n\t\t\t\tif (a <= z && z <= b)\n\t\t\t\t\tans = Math.max(ans, z * (y - 1 - z));\n\t\t\t}\n\t\t\tx *= 10;\n\t\t\ty *= 10;\n\t\t}\n\t\tout.write(ans + \"\\n\");\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\t\t// in = new BufferedReader(new FileReader(filename+\".in\"));\n\t\t\t// out = new BufferedWriter(new FileWriter(filename+\".out\"));\n\t\t\tsolve();\n\t\t\tout.flush();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n\n\tpublic int iread() throws Exception {\n\t\treturn Integer.parseInt(readword());\n\t}\n\n\tpublic double dread() throws Exception {\n\t\treturn Double.parseDouble(readword());\n\t}\n\n\tpublic long lread() throws Exception {\n\t\treturn Long.parseLong(readword());\n\t}\n\n\tBufferedReader in;\n\n\tBufferedWriter out;\n\n\tpublic String readword() throws IOException {\n\t\tStringBuilder b = new StringBuilder();\n\t\tint c;\n\t\tc = in.read();\n\t\twhile (c >= 0 && c <= ' ')\n\t\t\tc = in.read();\n\t\tif (c < 0)\n\t\t\treturn \"\";\n\t\twhile (c > ' ') {\n\t\t\tb.append((char) c);\n\t\t\tc = in.read();\n\t\t}\n\t\treturn b.toString();\n\t}\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tLocale.setDefault(Locale.US);\n\t\t} catch (Exception e) {\n\n\t\t}\n\t\t// new Thread(new Main()).start();\n\t\tnew Thread(null, new Main(), \"1\", 1 << 25).start();\n\t}\n}", "lang_cluster": "Java", "tags": ["math"], "code_uid": "34c16fea244754f6eb3e2986f3bcd70a", "src_uid": "2c4b2a162563242cb2f43f6209b59d5e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.util.ArrayList;\nimport java.util.PriorityQueue;\nimport java.util.Scanner;\n\n\n\npublic class Main {\n\n\tpublic static void main(String args[]){\n\t\tScanner s = new Scanner(System.in);\n\t\tint n = s.nextInt(), m = s.nextInt();\n\t\tint[] arr = new int[101];\n\t\tArrayList> list = new ArrayList>(101);\n\t\tfor(int i = 0; i < 101; i++){\n\t\t\tlist.add(new ArrayList());\n\t\t}\n\t\tfor(int i = 0; i < m; i++){\n\t\t\tint st = s.nextInt(), d = s.nextInt(), c = s.nextInt();\n\t\t\tarr[d] = m + 1;\n\t\t\tNode temp = new Node();\n\t\t\ttemp.idx = i;\n\t\t\ttemp.value = d;\n\t\t\ttemp.count = c;\n\t\t\t/*if(d - st + 1 < c){\n\t\t\t System.out.println(-1);\n\t\t\t return;\n\t\t\t}*/\n\t\t\tlist.get(st).add(temp);\n\t\t}\n\t\tPriorityQueue pq = new PriorityQueue();\n\t\tfor(int i = 1; i < list.size(); i++){\n\t\t\t\n\t\t\tArrayList curr = list.get(i);\n\t\t\tfor(int j = 0; j < curr.size(); j++){\n\t\t\t\tpq.add(curr.get(j));\n\t\t\t}\n\t\t\tif(arr[i] != 0){\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif(pq.peek() == null){\n\t\t\t continue;\n\t\t\t}\n\t\t\tNode tem = pq.poll();\n\t\t\tif(tem == null){\n\t\t\t continue;\n\t\t\t}\n\t\t\tif(tem.value < i){\n\t\t\t\tSystem.out.println(-1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tarr[i] = tem.idx + 1;\n\t\t\ttem.count--;\n\t\t\tif(tem.count > 0){\n\t\t\t\tpq.add(tem);\n\t\t\t}\n\t\t}\n\t\tif(pq.peek() != null){\n\t\t System.out.println(-1);\n\t\t return;\n\t\t}\n\t\tfor(int i = 1; i <= n; i++){\n\t\t\tSystem.out.print(arr[i] + \" \");\n\t\t}\n\t}\n}\n\nclass Node implements Comparable{\n\tint idx, value, count;\n\n\t@Override\n\tpublic int compareTo(Node arg0) {\n\t\treturn this.value - arg0.value;\n\t}\n}\n", "lang_cluster": "Java", "tags": ["sortings", "implementation", "greedy"], "code_uid": "02a6eb5bcf4894bfa7f10a399715d84e", "src_uid": "02d8d403eb60ae77756ff96f71b662d3", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class CFTiles {\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner scanner = new Scanner(System.in);\n\t\tint w = scanner.nextInt();\n\t\tint h = scanner.nextInt();\n\t\tint ans = 4;\n\t\tfor(int i = 1; i < w;i++) {\n\t\t\tans = (ans*2)%998244353;\n\t\t}\n\t\tfor(int i = 1; i < h;i++) {\n\t\t\tans = (ans*2)%998244353;\n\t\t}\n\t\tSystem.out.println(ans);\n\t\tscanner.close();\n\t}\n\n}", "lang_cluster": "Java", "tags": ["math", "greedy", "combinatorics"], "code_uid": "ad1156644178a0439401117f2490676f", "src_uid": "8b2a9ae21740c89079a6011a30cd6aee", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Pie {\n public static void main (String[] args) {\n Scanner scan = new Scanner(System.in);\n int pieNo = scan.nextInt();\n int ex = pieNo + 1; int pieces[] = new int[ex];\n for (int a = pieNo; a >= 1; a--) {\n pieces[a] = scan.nextInt();\n }\n int total[] = new int[ex];\n for (int b = 1; b <= pieNo; b++) {\n total[b] = total[b-1] + pieces[b];\n }\n int sizes[] = new int[ex];\n for (int c = 1; c <= pieNo; c++) {\n int tmp = total[c] - sizes[c-1];\n if (sizes[c-1] > tmp) { sizes[c] = sizes[c-1]; }\n else { sizes[c] = tmp; }\n }\n int alice = total[pieNo] - sizes[pieNo];\n int bob = sizes[pieNo];\n System.out.println(alice +\" \"+ bob);\n }\n}", "lang_cluster": "Java", "tags": ["dp", "games"], "code_uid": "6a2943b5d81d4cd3e236450a2bdb5260", "src_uid": "414540223db9d4cfcec6a973179a0216", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import static java.lang.StrictMath.abs;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.List;\nimport java.util.Scanner;\n\n\npublic class Ropewalkers {\n static int a;\n static int b;\n static int c;\n static int d;\n static List list = new ArrayList();\n static int counter=0;\n public static void main(String args[]){\n Scanner in = new Scanner(System.in);\n a = in.nextInt();\n b = in.nextInt();\n c = in.nextInt();\n d = in.nextInt();\n list.add(a); \n list.add(b);\n list.add(c); \n int max = Collections.max(list);\n int min = Collections.min(list);\n int mid = (a+b+c) - (min+max);\n \n \n if (abs(mid - min) < d ){\n counter += d - (mid-min);\n \n }\n if(abs(max - mid) < d ){\n \n counter += d - max + mid;\n }\n System.out.println(counter); \n } \n \n}\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "188c738082c5ddf2b84deedcda5bd162", "src_uid": "47c07e46517dbc937e2e779ec0d74eb3", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n public static long mod = 1000000007;\n\n public static void main(String[] args) {\n PrintWriter pr = new PrintWriter(System.out);\n FastScanner input = new FastScanner();\n int num = input.nextInt();\n\n for (int i = 0; i < num; i ++) {\n int len = input.nextInt();\n int dig = input.nextInt();\n\n if (dig == 0) System.out.println(1);\n else {\n long hold = modexp(2, len - 1);\n if (len % 2 == 1) System.out.println(modexp(hold + 1, dig));\n else {\n hold -= 1;\n long ans = modexp(hold, dig);\n long hi = 1;\n long bye = modexp(2, len);\n\n for (long k = dig - 1; k >= 0; k --) {\n if (k == 0) ans += hi;\n else ans += (long)(modexp(hold, k) * hi) % mod;\n ans %= mod;\n hi = (hi * bye) % mod;\n }\n System.out.println(ans);\n }\n }\n }\n }\n\n\n public static class point implements Comparable {\n public int x, y;\n public point(int x, int y) {\n this.x = x;\n this.y = y;\n }\n\n @Override public int compareTo(point a) {\n if (this.x > a.x) return 1;\n else if (this.x == a.x) return 0;\n else return -1;\n }\n }\n\npublic static long modexp(long a, long b) {return modexp(a, b, mod);}\n\n\tpublic static long modexp(long a, long b, long m) {\n\t\tlong res = 1;\n\t\twhile (b > 0) {\n\t\t\tif (b%2 != 0) res = (res*a)%m;\n\t\t\ta = (a*a)%m;\n\t\t\tb /= 2;\n\t\t}\n\t\treturn res;\n\t}\n\n public static int gcd(int a, int b) {\n if (a == 0) return b;\n else return gcd(b % a, a);\n }\n\n static class FastScanner {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer st = new StringTokenizer(\"\");\n String next() {\n while (!st.hasMoreTokens())\n try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); }\n return st.nextToken();\n }\n int nextInt() { return Integer.parseInt(next()); }\n int[] readArray(int n) {\n int[] a = new int[n];\n for (int i = 0; i < n; i++) a[i]=nextInt();\n return a;\n }\n long nextLong() { return Long.parseLong(next()); }\n }\n\n\n}\n", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics", "bitmasks", "matrices"], "code_uid": "6cfe82966bb45ae2b36c5ead7f7b1c73", "src_uid": "02f5fe43ea60939dd4a53299b5fa0881", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "\nimport java.util.*;\nimport java.math.*;\nimport static java.lang.Character.isDigit;\nimport static java.lang.Character.isLowerCase;\nimport static java.lang.Character.isUpperCase;\nimport static java.lang.Math.*;\nimport static java.math.BigInteger.*;\nimport static java.util.Arrays.*;\nimport static java.util.Collections.*;\nimport static java.lang.Character.isDigit;\n\npublic class Main{\n static void debug(Object...os){\n System.err.println(deepToString(os));\n }\n void run(){\n System.out.println(solve(nextInt()));\n }\n int M = 1000000007;\n long pow(long n,int p,int MOD){\n if(p==0) return 1%MOD;\n long m=pow(n,p>>1,MOD);\n return (p&1)==0?m*m%MOD:m*m%MOD*n%MOD;\n }\n long inv(long n,int MOD){\n return pow(n,MOD-2,MOD);\n }\n long C(int n,int m) {\n long res=1;\n for(int i=0;i 0) {\n if (x % 2 != 0) {\n res = (res * a) % m;\n }\n a = (a * a) % m;\n x /= 2;\n }\n return res % m;\n }\n\n private static long modInverse(long a, long p) {\n // p doit \u00eatre premier\n return modPow(a, p - 2, p);\n }\n\n private static long nCr(long n, int r) {\n if (n < r) return 0;\n long ret = 1;\n for (long x = n; x >= n - r + 1; x--) {\n ret = (ret * (x % MOD)) % MOD;\n }\n ret = (ret * modInverse(FACT[r], MOD)) % MOD;\n return ret;\n }\n\n public static void main(String[] args) {\n FACT[0] = 1;\n for (int i = 1; i < 25; i++) {\n FACT[i] = (FACT[i - 1] * i) % MOD;\n }\n\n Scanner in = new Scanner(System.in);\n int n;\n long s, N;\n n = in.nextInt();\n s = in.nextLong();\n long f[] = new long[n];\n for (int i = 0; i < n; i++) {\n f[i] = in.nextLong();\n }\n\n N = 1 << n;\n\n long res = 0;\n for (int i = 0; i < N; i++) {\n long count = 0;\n int p = 0;\n for (int j = 0; j < n; j++) {\n if ((i & (1 << j)) > 0) {\n count += f[j] + 1;\n p++;\n }\n }\n if (count > s) continue;\n long C = nCr(s + n - 1 - count, n - 1);\n if (p % 2 == 1) C = -C;\n res = (res + C) % MOD;\n if (res < 0) res += MOD;\n }\n\n System.out.println(res);\n }\n}\n", "lang_cluster": "Java", "tags": ["combinatorics", "number theory", "bitmasks"], "code_uid": "28bd26803c5cd860ebe8a57698ace1b7", "src_uid": "8b883011eba9d15d284e54c7a85fcf74", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import static java.lang.Math.*;\nimport static java.lang.System.currentTimeMillis;\nimport static java.lang.System.exit;\nimport static java.lang.System.arraycopy;\nimport static java.util.Arrays.sort;\nimport static java.util.Arrays.binarySearch;\nimport static java.util.Arrays.fill;\nimport java.util.*;\nimport java.io.*;\n\npublic class Main {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\ttry {\n\t\t\tif (new File(\"input.txt\").exists())\n\t\t\t\tSystem.setIn(new FileInputStream(\"input.txt\"));\n\t\t} catch (SecurityException e) {\n\t\t}\n\t\tnew Thread(null, new Runnable() {\n\t\t\tpublic void run() {\n\t\t\t\ttry {\n\t\t\t\t\tnew Main().run();\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t\texit(999);\n\t\t\t\t}\n\t\t\t}\n\t\t}, \"1\", 1 << 23).start();\n\t}\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st = new StringTokenizer(\"\");\n\n\tprivate void run() throws IOException {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\n\t\tint ans = Integer.MAX_VALUE;\n\t\tint k = nextInt();\n\t\tloop: for(int r = 1; r < k; r++){\n\t\t\tint a = k;\n\t\t\tint b = r;\n\t\t\tint c = 0;\n\t\t\twhile(a + b > 2){\n\t\t\t\tif(a > b){b ^= a; a ^= b; b ^= a;}\n\t\t\t\tb = b - a;\n\t\t\t\tc++;\n\t\t\t\tif((a != 1 && a == b) || b == 0) continue loop; \n\t\t\t}\n\t\t\tans = min(ans, c);\n\t\t}\n\t\tif(k == 1)\n\t\t\tout.println(0);\n\t\telse\n\t\t\tout.println(ans);\n\t\t\n\t\tin.close();\n\t\tout.close();\n\t}\n\tString nextToken() throws IOException {\n\t\twhile (!st.hasMoreTokens())\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\treturn st.nextToken();\n\t}\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\tString nextLine() throws IOException {\n\t\tst = new StringTokenizer(\"\");\n\t\treturn in.readLine();\n\t}\n\tboolean EOF() throws IOException {\n\t\twhile (!st.hasMoreTokens()) {\n\t\t\tString s = in.readLine();\n\t\t\tif (s == null)\n\t\t\t\treturn true;\n\t\t\tst = new StringTokenizer(s);\n\t\t}\n\t\treturn false;\n\t}\n}\n", "lang_cluster": "Java", "tags": ["dfs and similar", "math", "number theory", "brute force"], "code_uid": "d493cede4dc44a04deb209cadee362c7", "src_uid": "75739f77378b21c331b46b1427226fa1", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "//package codeforcespage2;\nimport java.util.*;\npublic class EatingSoup {\n public static void main(String[] args) {\n Scanner in=new Scanner(System.in);\n int n=in.nextInt();\n int m=in.nextInt();\n if(m==0 || m==1){\n System.out.println(\"1\");\n return;\n }\n if(n==m)\n {\n System.out.println(\"0\");return;\n }\n ArrayList al=new ArrayList();\n for(int i=1;i<=n;i++)\n {\n al.add(i);\n }\n int count=0;\n Character star='*';\n for(int i=m;i>0;i--)\n {\n if(count>al.size()-1)\n {\n count=1;\n }\n \n al.set(count,star);\n count=count+2;\n }\n int group=0;\n for(int i=0;i r1 || l2 > r2)\n\t\t\treturn 0;\n\t\tif (l1 > l2) {\n\t\t\treturn solve(l2, r2, l1, r1, type);\n\t\t}\n\t\tif (r2 <= r1) {\n\t\t\treturn r2 - l2 + 1;\n\t\t}\n\t\tif (l1 == l2) {\n\t\t\treturn Math.min(r2, r1) - l1 + 1;\n\t\t}\n\t\tif (r1 >= pos[type] && l2 <= pos[type]) {\n\t\t\treturn Math.max(r1 - l2 + 1,\n\t\t\t\t\tsolve(l1, pos[type] - 1, 0, r2 - pos[type] - 1, type - 1));\n\t\t}\n\t\tif (r1 >= pos[type]) {\n\t\t\treturn solve(len[type] - r2 - 1, len[type] - l2 - 1, len[type] - r1\n\t\t\t\t\t- 1, len[type] - l1 - 1, type);\n\t\t}\n\t\tif (r2 < pos[type]) {\n\t\t\treturn solve(l1, r1, l2, r2, type - 1);\n\t\t}\n\t\treturn Math.max(\n\t\t\t\tsolve(l1, r1, l2, pos[type] - 1, type - 1),\n\t\t\t\tsolve(l1, r1, Math.max(0, l2 - pos[type] - 1), r2 - pos[type]\n\t\t\t\t\t\t- 1, type - 1));\n\t}\n\n\tvoid solve() throws IOException {\n\t\tint m = 30;\n\t\tlen = new int[m];\n\t\tpos = new int[m];\n\t\tlen[0] = 1;\n\t\tpos[0] = 0;\n\t\tfor (int i = 1; i < m; i++) {\n\t\t\tpos[i] = len[i - 1];\n\t\t\tlen[i] = 2 * len[i - 1] + 1;\n\t\t}\n\t\tout.println(solve(nextInt() - 1, nextInt() - 1, nextInt() - 1,\n\t\t\t\tnextInt() - 1, m - 1));\n\t}\n\n\tvoid run() throws IOException {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew C().run();\n\t}\n\n}", "lang_cluster": "Java", "tags": ["divide and conquer"], "code_uid": "48f14064db11e855c26cc800800e1276", "src_uid": "fe3c0c4c7e9b3afebf2c958251f10513", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class B {\n\tpublic static void main(String[] args) {\n\t\tInputStream input;\n\t\tOutputStream output;\n\t\ttry {\n\t\t\tinput = new FileInputStream(\"input.txt\");\n\t\t\toutput = new FileOutputStream(\"output.txt\");\n\t\t} catch (FileNotFoundException e) {\n\t\t\tinput = System.in;\n\t\t\toutput = System.out;\n\t\t}\n\t\tKattio io = new Kattio(input, output);\n\t\t//int t=io.getInt();\n\t\t//for (int i=1; i<=t; i++)\n\t\t(new Solve(io)).main();\n\t\tio.close();\n\n\t\tif (input instanceof FileInputStream)\n\t\t\ttry {\n\t\t\t\tinput.close();\n\t\t\t} catch (IOException e) {\n\t\t\t}\n\t\tif (output instanceof FileOutputStream)\n\t\t\ttry {\n\t\t\t\toutput.close();\n\t\t\t} catch (IOException e) {\n\t\t\t}\n\t}\n}\n\nclass Solve {\n\tKattio io;\n\n\tlong n;\n\tint m;\n\tlong[] a;\n\tlong[] b;\n\tSolve(Kattio io) {\n\t\tthis.io = io;\n\t}\n\n\tvoid main() {\n\t\tn=io.getLong();\n\t\tm=io.getInt();\n\t\ta = new long[m];\n\t\tb = new long[m];\n\t\tfor (int i=0; i Integer.MAX_VALUE) throw new NumberFormatException();\n\t\t\t\treturn (int) nl;\n\t\t}\n\t\tpublic double nextDouble() { return Double.parseDouble(next());}\n\t}\n}\n", "lang_cluster": "Java", "tags": ["dfs and similar", "greedy", "implementation"], "code_uid": "9fc0e8503de7571f0e4ac823b4c567e4", "src_uid": "685fe16c217b5b71eafdb4198822250e", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.lang.*;\n \nimport static java.lang.Math.*;\n \npublic class Main implements Runnable\n{\n\tstatic class InputReader\n\t{\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n\t\tprivate SpaceCharFilter filter;\n\t\tprivate BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\n\t\tpublic InputReader(InputStream stream)\n\t\t{\n\t\t\tthis.stream = stream;\n\t\t}\n\t\t\n\t\tpublic int read()\n\t\t{\n\t\t\tif (numChars==-1) \n\t\t\t\tthrow new InputMismatchException();\n\t\t\t\n\t\t\tif (curChar >= numChars)\n\t\t\t{\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry \n\t\t\t\t{\n\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t}\n\t\t\t\tcatch (IOException e)\n\t\t\t\t{\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif(numChars <= 0)\t\t\t\t\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\t \n\t\tpublic String nextLine()\n\t\t{\n\t\t\tString str = \"\";\n try\n {\n str = br.readLine();\n }\n catch (IOException e)\n {\n e.printStackTrace();\n }\n return str;\n\t\t}\n\t\tpublic int nextInt()\n\t\t{\n\t\t\tint c = read();\n\t\t\t\n\t\t\twhile(isSpaceChar(c)) \n\t\t\t\tc = read();\n\t\t\t\n\t\t\tint sgn = 1;\n\t\t\t\n\t\t\tif (c == '-') \n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\t\n\t\t\tint res = 0;\n\t\t\tdo \n\t\t\t{\n\t\t\t\tif(c<'0'||c>'9') \n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\twhile (!isSpaceChar(c)); \n\t\t\t\n\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic long nextLong() \n\t\t{\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') \n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\t\n\t\t\tdo \n\t\t\t{\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\twhile (!isSpaceChar(c));\n\t\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic double nextDouble() \n\t\t{\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') \n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tdouble res = 0;\n\t\t\twhile (!isSpaceChar(c) && c != '.') \n\t\t\t{\n\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\treturn res * Math.pow(10, nextInt());\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tif (c == '.') \n\t\t\t{\n\t\t\t\tc = read();\n\t\t\t\tdouble m = 1;\n\t\t\t\twhile (!isSpaceChar(c)) \n\t\t\t\t{\n\t\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\t\treturn res * Math.pow(10, nextInt());\n\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\tm /= 10;\n\t\t\t\t\tres += (c - '0') * m;\n\t\t\t\t\tc = read();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic String readString() \n\t\t{\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo \n\t\t\t{\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} \n\t\t\twhile (!isSpaceChar(c));\n\t\t\t\n\t\t\treturn res.toString();\n\t\t}\n\t \n\t\tpublic boolean isSpaceChar(int c) \n\t\t{\n\t\t\tif (filter != null)\n\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\t \n\t\tpublic String next() \n\t\t{\n\t\t\treturn readString();\n\t\t}\n\t\t\n\t\tpublic interface SpaceCharFilter \n\t\t{\n\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t}\n \t\n\tpublic static void main(String args[]) throws Exception\n\t{\n\t\tnew Thread(null, new Main(),\"Main\",1<<26).start();\n\t}\n\tpublic void run()\n\t{\n\t\tInputReader sc= new InputReader(System.in);\n\t\tPrintWriter w= new PrintWriter(System.out);\n \n long n = sc.nextLong();\n long m = sc.nextLong();\n \n if(n <= m)\n w.print(n);\n \n else\n {\n long ans = (long)Math.ceil((Math.sqrt(0.25 + 2.0 * (n - m))) - 0.5);\n if(ans * (ans + 1) - 2 * (n - m) >= 0)\n w.print((ans + m));\n else\n w.print((ans + m + 1));\n }\n \n w.close();\t\t\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "binary search"], "code_uid": "5085ab152fde6b9d3beb2331dc097b02", "src_uid": "3b585ea852ffc41034ef6804b6aebbd8", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\n\npublic class First {\n private static final Scanner sc = new Scanner(System.in);\n private static final PrintWriter pw = new PrintWriter(System.out);\n private static StringBuffer ans = new StringBuffer();\n\n public static void main(String[] args) throws Exception {\n int t = sc.nextInt();\n for (int i = 0; i < t; i++) {\n long a = sc.nextLong(), b = sc.nextLong();\n if (Math.abs(a - b) == 1 && isPrime(a + b)) ans.append(\"YES\\n\");\n else ans.append(\"NO\\n\");\n }\n pw.print(ans);\n sc.close();\n pw.close();\n }\n\n private static boolean isPrime(long n) {\n if (n < 2L) return false;\n for (long i = 2; i * i <= n; i++) if (n % i == 0L) return false;\n return true;\n }\n}\n\nclass Scanner {\n private final BufferedReader br;\n private StringTokenizer st;\n\n public Scanner(InputStream in) {\n br = new BufferedReader(new InputStreamReader(in));\n st = new StringTokenizer(\"\");\n }\n\n public String next() throws IOException {\n if (!st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n \n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public void close() throws IOException {\n br.close();\n }\n}\n\nclass PrintWriter {\n private final BufferedOutputStream pw;\n\n public PrintWriter(OutputStream out) {\n pw = new BufferedOutputStream(out);\n }\n\n public void print(Object o) throws IOException {\n pw.write(o.toString().trim().getBytes());\n pw.flush();\n }\n\n public void println(Object o) throws IOException {\n print(o + \"\\n\");\n }\n\n public void close() throws IOException {\n pw.close();\n }\n}", "lang_cluster": "Java", "tags": ["math", "number theory"], "code_uid": "069afbed004e969a4f67656e1e60cf9c", "src_uid": "5a052e4e6c64333d94c83df890b1183c", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Main{\n\n BufferedReader in;\n StringTokenizer str = null;\n PrintWriter out;\n\n private String next() throws Exception{\n \twhile (str == null || !str.hasMoreElements())\n \t str = new StringTokenizer(in.readLine());\n \treturn str.nextToken();\n }\n \n private int nextInt() throws Exception{\n\t\treturn Integer.parseInt(next());\n }\n \n char [][]sc, map;\n int n, t;\n\n int [][]dr;\n Queue q;\n\n int di[] = new int[]{-1, 1, 0, 0};\n int dj[] = new int[]{0, 0, -1, 1};\n\n MaxFlowMinCost mfmc;\n\n final static int BASE = 10;\n\n public void run() throws Exception{\n \tin = new BufferedReader(new InputStreamReader(System.in));\n \tout = new PrintWriter(System.out);\n\n \tn = nextInt();\n \tt = nextInt();\n \tsc = new char[n][];\n \tfor (int i = 0; i < n ; ++i) {\n \t\tsc[i] = next().toCharArray();\n \t}\n\n \tmap = new char[n][];\n \tfor (int i = 0; i < n; ++i) {\n \t\tmap[i] = next().toCharArray();\n \t}\n\n \tdr = new int[n][n];\n \tfor(int []i : dr) Arrays.fill(i, oo);\n \tq = new ArrayDeque();\n\n \tfor(int i = 0; i < n; ++i) {\n \t\tfor(int j = 0; j < n; ++j) {\n \t\t\tif (map[i][j] == 'Z') {\n \t\t\t\tdr[i][j] = 0;\n \t\t\t\tq.add(i * BASE + j);\n \t\t\t}\n \t\t}\n \t}\n\n \twhile(q.size() > 0) {\n \t\tint cur = q.poll();\n \t\tint x = cur / BASE, y = cur % BASE;\n\n \t\tfor(int i = 0; i < 4; ++i) {\n \t\t\tint nx = x + di[i], ny = y + dj[i];\n \t\t\tadd(nx, ny, x, y, dr);\n \t\t}\n \t}\n\n \tint source = 2 * n * n, sink = 2 * n * n + 1;\n \tmfmc = new MaxFlowMinCost(2 * n * n + 2, source, sink);\n\n \tfor(int i = 0; i < n; ++i) {\n \t\tfor(int j = 0; j < n; ++j) {\n \t\t\tif (Character.isDigit(sc[i][j])) {\n \t\t\t\tint flow = sc[i][j] - '0', v = i * n + j;\n \t\t\t\tif (flow > 0) {\n \t\t\t\t\tmfmc.addEdge(source, v, flow);\n \t\t\t\t}\n \t\t\t}\n\n \t\t\tif (Character.isDigit(map[i][j])) {\n \t\t\t\tint flow = map[i][j] - '0', v = n * n + i * n + j;\n \t\t\t\tif (flow > 0) {\n \t\t\t\t\tmfmc.addEdge(v, sink, flow);\n \t\t\t\t}\t\n \t\t\t}\n\n \t\t\tif (Character.isDigit(sc[i][j])) {\n \t\t\t\tint count = sc[i][j] - '0';\n \t\t\t\tif (count == 0) continue;\n \t\t\t\tint [][]d = bfs(i, j, dr);\n \t\t\t\t// System.out.println(i + \" \" + j);\n \t\t\t\t// print(d);\n \t\t\t\tfor(int x = 0; x < n; ++x) {\n \t\t\t\t\tfor(int y = 0; y < n; ++y) {\n \t\t\t\t\t\tif (Character.isDigit(map[x][y])) {\n \t\t\t\t\t\t\tcount = map[x][y] - '0';\n \t\t\t\t\t\t\tif (count == 0) continue;\n \t\t\t\t\t\t\tif (d[x][y] <= t) {\n \t\t\t\t\t\t\t\tint v = i * n + j, u = n * n + x * n + y;\n \t\t\t\t\t\t\t\tmfmc.addEdge(v, u, oo);\t\n \t\t\t\t\t\t\t}\n \t\t\t\t\t\t}\n \t\t\t\t\t}\n \t\t\t\t}\n \t\t\t}\n \t\t}\n \t}\n\n \t// mfmc.print();\n\n \tmfmc.execute();\n\n \tout.println(mfmc.flow);\n out.close();\n }\n\n private void print(int [][]d) {\n \tfor(int i = 0; i < n; ++i) {\n \t\tSystem.out.println(Arrays.toString(d[i]));\n \t}\n \tSystem.out.println();\n }\n\n private int[][] bfs(int sx, int sy, int [][]dr) {\n \tint [][]d = new int[n][n];\n \tfor(int []i : d) Arrays.fill(i, oo);\n\n \td[sx][sy] = 0;\n \tq.add(sx * BASE + sy);\n\n \twhile(q.size() > 0) {\n \t\tint cur = q.poll();\n \t\tint x = cur / BASE, y = cur % BASE;\n\n \t\tfor(int i = 0; i < 4; ++i) {\n \t\t\tint nx = x + di[i], ny = y + dj[i];\n \t\t\tadd(nx, ny, x, y, d, dr);\n \t\t}\n \t}\n\n \treturn d;\n }\n\n private void add(int x, int y, int fx, int fy, int [][]d, int [][]dr) {\n \tif (x < 0 || y < 0) return;\n \tif (x >= n || y >= n) return;\n \tif (map[x][y] == 'Y' || map[x][y] == 'Z') return;\n \tif (d[x][y] > d[fx][fy] + 1) {\n \t\tif (dr[x][y] >= d[fx][fy] + 1) {\n \t\t\td[x][y] = d[fx][fy] + 1;\n \t\t\tif (dr[x][y] > d[fx][fy] + 1) {\n \t\t\t\tq.add(x * BASE + y);\t\t\n \t\t\t}\n \t\t}\n \t} \n }\n\n private void add(int x, int y, int fx, int fy, int [][]d) {\n \tif (x < 0 || y < 0) return;\n \tif (x >= n || y >= n) return;\n \tif (map[x][y] == 'Y') return;\n \tif (d[x][y] > d[fx][fy] + 1) {\n \t\td[x][y] = d[fx][fy] + 1;\n \t\tq.add(x * BASE + y);\n \t}\n }\n\n public static void main(String args[]) throws Exception{\n\t\tnew Main().run();\n }\n\n final static int oo = Integer.MAX_VALUE/2;\n\n class MaxFlowMinCost {\n\n \tclass Edge {\n \t\tint from, to, cap, flow;\n\n \t\tpublic Edge(int from, int to, int cap, int flow) {\n \t\t\tthis.from = from;\n \t\t\tthis.to = to;\n \t\t\tthis.cap = cap;\n \t\t\tthis.flow = flow;\n \t\t}\n\n \t\tpublic String toString() {\n \t\t\treturn \"from=\" + from + \", to=\" + to + \", cap=\" + cap + \", flow=\" + flow;\n \t\t}\n \t}\n\n \tint n, source, sink;\n \tint flow = 0;\n\n \tList []g;\n \tList e;\n\n \tint []q, from, d;\n \tboolean []inqueue;\n\n \tpublic MaxFlowMinCost(int n, int source, int sink) {\n \t\tthis.n = n;\n \t\tthis.source = source;\n \t\tthis.sink = sink;\n\n \t\tg = new LinkedList[n];\n \t\tfor(int i = 0; i < n; ++i) g[i] = new LinkedList();\n \t\te = new ArrayList();\n\n \t\tq = new int[n];\n \t\td = new int[n];\n \t\tfrom = new int[n];\n \t\tinqueue = new boolean[n];\n \t}\n\n \tprivate boolean bfs() {\n \t\tArrays.fill(d, oo);\n \t\tArrays.fill(from, -1);\n \t\tArrays.fill(inqueue, false);\n \t\tint head = 0, tail = 0;\n\n \t\td[source] = 0;\n \t\tq[tail++] = source;\n \t\tinqueue[source] = true;\n\n \t\twhile(head != tail && d[sink] == oo) {\n \t\t\tint x = q[head++];\n \t\t\tfor(int id : g[x]) {\n \t\t\t\tEdge edge = e.get(id);\n \t\t\t\tif (edge.cap <= edge.flow) continue;\n \t\t\t\tif (d[edge.to] > d[x] + 1) {\n \t\t\t\t\td[edge.to] = d[x] + 1;\n \t\t\t\t\tfrom[edge.to] = id;\n \t\t\t\t\tif (inqueue[edge.to]) continue;\n \t\t\t\t\tinqueue[edge.to] = true;\n \t\t\t\t\tq[tail++] = edge.to;\n \t\t\t\t\tif (tail == n) tail = 0;\n \t\t\t\t}\n \t\t\t}\n \t\t\tif (head == n) head = 0;\n \t\t\tinqueue[x] = false;\n \t\t}\n\n \t\treturn d[sink] != oo;\n \t}\n\n \tprivate void increase() {\n \t\t// System.out.println(\"INCREASING FLOW...\");\n \t\tint c = sink, delta = oo;\n \t\twhile(from[c] != -1) {\n \t\t\tint id = from[c];\n \t\t\tEdge edge = e.get(id);\n \t\t\t// System.out.println(edge);\n \t\t\tdelta = Math.min(delta, edge.cap - edge.flow);\n \t\t\tc = edge.from;\n \t\t}\n \t\t// System.out.println(\"delta = \" + delta);\n \t\tflow+=delta;\n \t\tc = sink;\n \t\twhile(from[c] != -1) {\n \t\t\tint id = from[c];\n \t\t\te.get(id).flow+=delta;\n \t\t\te.get(id ^ 1).flow-=delta;\n\n \t\t\tc = e.get(id).from;\n \t\t}\n \t}\n\n \tpublic void execute() {\n \t\twhile(bfs()) {\n \t\t\tincrease();\n \t\t}\n \t}\n\n \tpublic void addEdge(int from, int to, int cap) {\n \t\tg[from].add(e.size());\n \t\te.add(new Edge(from, to, cap, 0));\n \t\tg[to].add(e.size());\n \t\te.add(new Edge(to, from, cap, cap));\n \t}\n\n \tpublic void print() {\n \t\tfor(Edge edge : e) {\n \t\t\tSystem.out.println(edge);\n \t\t}\n \t}\n\n }\n}", "lang_cluster": "Java", "tags": ["flows", "graphs", "shortest paths"], "code_uid": "608edec0982e608b4bdb09caf4a7936f", "src_uid": "544de9c3729a35eb08c143b1cb9ee085", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Ideone\n{\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t\t// your code goes here\n\t\tScanner scan=new Scanner(System.in);\n\t\tint l=scan.nextInt();\n\t\tint r=scan.nextInt();\n\t\tint x=scan.nextInt();\n\t\tint y=scan.nextInt();\n\t\tlong k=scan.nextInt();\n for(int i=x;i<=y;i++)\n if(k*i>=l&&k*i<=r){System.out.println(\"YES\");return;} \n \n System.out.println(\"NO\");\t\n\t\t\n\t}\n}", "lang_cluster": "Java", "tags": ["two pointers", "brute force"], "code_uid": "2cbf9df40f9bc4a214023bf357e40fc9", "src_uid": "1110d3671e9f77fd8d66dca6e74d2048", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n\npublic class P290C_WTF {\n\n public static void main(String[] args) throws IOException {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n int tux = Integer.parseInt(in.readLine());\n int foo = 0;\n int bar = 0;\n int baz = 0;\n int quz = 1;\n for (; tux > 0; tux--) {\n int pur = Integer.parseInt(in.readLine());\n foo = foo + pur;\n bar = bar + 1;\n if (Math.max(foo*quz,bar*baz) == foo*quz) {\n baz = foo;\n quz = bar;\n }\n }\n System.out.println((double)baz/(double)quz);\n }\n\n}\n", "lang_cluster": "Java", "tags": ["implementation", "trees", "graph matchings"], "code_uid": "c610a75b345d5756a59d83c08ae0801c", "src_uid": "32fc378a310ca15598377f7b638eaf26", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\n/**\n * Created by IntelliJ IDEA.\n * User: jte\n * Date: 13.4.11\n * Time: 17.39\n * To change this template use File | Settings | File Templates.\n */\n\npublic class Main extends Thread {\n\n public Main() {\n this.setPriority(Thread.MAX_PRIORITY);\n }\n\n private int signum(int a) {\n return a < 0 ? -1 : a == 0 ? 0 : 1;\n }\n\n public void run() {\n try {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n String[] first = in.readLine().split(\"[ ]+\");\n int n = Integer.parseInt(first[0]), m = Integer.parseInt(first[1]), k = Integer.parseInt(first[2]);\n String cur = in.readLine();\n int dx = 0;\n if (cur.compareTo(\"to head\") == 0) {\n dx = -1;\n } else {\n dx = 1;\n }\n char[] states = in.readLine().trim().toCharArray();\n for (int i = 0; i < states.length; ++i) {\n if (states[i] == '0') {\n if (signum(m - k) == 0) {\n System.out.println(\"Controller \" + i);\n System.exit(0);\n }\n if (signum(m - k) != dx) {\n k = k + dx;\n if (k == 1 || k == n) {\n dx = -dx;\n }\n } else {\n if (Math.abs(m - k) > 1) {\n k = k + dx;\n if (k == 1 || k == n) {\n dx = -dx;\n }\n } else {\n m = m + dx;\n if (m < 1)\n m = 1;\n if (m > n)\n m = n;\n k = k + dx;\n if (k == 1 || k == n) {\n dx = -dx;\n }\n }\n }\n }\n else{\n if (signum(m - k) == 0) {\n System.out.println(\"Controller \" + i);\n System.exit(0);\n }\n k = k + dx;\n if (dx == 1){\n m = 1;\n }\n else{\n m = n;\n }\n if (k == 1 || k == n){\n dx = -dx;\n }\n }\n }\n System.out.println(\"Stowaway\");\n } catch (Throwable e) {\n System.err.println(e.getMessage());\n System.err.println(e.getStackTrace());\n }\n\n }\n\n\n public static void main(String[] args) throws Exception {\n new Main().start();\n }\n}\n", "lang_cluster": "Java", "tags": ["greedy", "dp", "games"], "code_uid": "50b662f4c3f385bf5f0ee11ab9ab2c48", "src_uid": "2222ce16926fdc697384add731819f75", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\n\nimport java.util.Scanner;\n\npublic class Nirvana {\n\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n=in.nextInt();\n\t\tNirvana obj = new Nirvana();\n\t\tSystem.out.println(obj.maxMultiply(n));\n\t\t\n\t\tin.close();\n\t}\n\tint maxMultiply(int n) {\n\t\tif(n == 0)\n\t\t\treturn 1;\n\t\tint nextNum = n/10;\n\t\tint digit = n%10;\n\t\tif(digit == 9) {\n\t\t\t// No need to borrow\n\t\t\treturn 9*maxMultiply(nextNum);\n\t\t}\n\t\tint result9 = -1;\n\t\tint resultNormal = -1;\n\t\tif(nextNum>0) {\n\t\t\t// Can borrow\n\t\t\tresult9 = 9*maxMultiply(nextNum-1);\n\t\t}\n\t\tresultNormal = digit*maxMultiply(nextNum);\n\t\treturn Math.max(result9, resultNormal);\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["brute force", "math", "number theory"], "code_uid": "b97713230ae1d58424ca27303c20f187", "src_uid": "38690bd32e7d0b314f701f138ce19dfb", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.OutputStream;\r\nimport java.io.IOException;\r\nimport java.io.InputStream;\r\nimport java.io.OutputStream;\r\nimport java.io.PrintWriter;\r\nimport java.util.Arrays;\r\nimport java.io.BufferedWriter;\r\nimport java.io.Writer;\r\nimport java.io.OutputStreamWriter;\r\nimport java.util.InputMismatchException;\r\nimport java.io.IOException;\r\nimport java.io.InputStream;\r\n\r\n/**\r\n * Built using CHelper plug-in\r\n * Actual solution is at the top\r\n */\r\npublic class Main {\r\n public static void main(String[] args) {\r\n InputStream inputStream = System.in;\r\n OutputStream outputStream = System.out;\r\n InputReader in = new InputReader(inputStream);\r\n OutputWriter out = new OutputWriter(outputStream);\r\n FNezzarAndChocolateBars solver = new FNezzarAndChocolateBars();\r\n solver.solve(1, in, out);\r\n out.close();\r\n }\r\n\r\n static class FNezzarAndChocolateBars {\r\n static final int MAXN = 2048;\r\n static final int modulo = 998244353;\r\n\r\n public int add(int x, int y) {\r\n x += y;\r\n if (x >= modulo) x -= modulo;\r\n return x;\r\n }\r\n\r\n public int subtract(int x, int y) {\r\n x -= y;\r\n if (x < 0) x += modulo;\r\n return x;\r\n }\r\n\r\n public int multiply(int x, int y) {\r\n return (int) ((x * 1L * y) % modulo);\r\n }\r\n\r\n public int power(int x, long y) {\r\n int ans = 1;\r\n for (; y > 0; y >>= 1, x = (int) ((x * 1L * x) % modulo))\r\n if (y % 2 == 1) ans = (int) ((ans * 1L * x) % modulo);\r\n return ans;\r\n }\r\n\r\n public int inverse(int x) {\r\n return power(x, modulo - 2);\r\n }\r\n\r\n public void solve(int testNumber, InputReader in, OutputWriter out) {\r\n int[] fact = new int[MAXN];\r\n int[] ifact = new int[MAXN];\r\n fact[0] = ifact[0] = 1;\r\n for (int i = 1; i < MAXN; i++) {\r\n fact[i] = multiply(fact[i - 1], i);\r\n ifact[i] = inverse(fact[i]);\r\n }\r\n int n = in.nextInt(), k = in.nextInt();\r\n int[] l = in.readIntArray(n);\r\n int[][][] dp = new int[2][MAXN][n + 1];\r\n dp[1][0][0] = 1;\r\n int s = 0;\r\n\r\n for (int p = 0; p < n; p++) {\r\n int L = l[p];\r\n int invL = inverse(L);\r\n int[] coeffs = new int[L / k + 1];\r\n int[] coeffs2 = new int[L / k + 1];\r\n for (int i = 0; i <= L / k; i++) {\r\n if (k * i == L) continue;\r\n int z = ifact[i];\r\n if (i % 2 == 1) z = subtract(0, z);\r\n coeffs[i] = multiply(z, power(L - k * i, i));\r\n\r\n if (i >= 1) {\r\n coeffs2[i] = multiply(z, multiply(i, power(L - k * i, i - 1)));\r\n }\r\n }\r\n int r = p & 1;\r\n int h = r ^ 1;\r\n for (int i = 0; i <= s / k; i++) Arrays.fill(dp[r][i], 0);\r\n for (int i = 0; i <= s / k; i++)\r\n for (int j = 0; j <= p; j++)\r\n if (dp[h][i][j] != 0) {\r\n int value = dp[h][i][j];\r\n for (int t = 0; t <= L / k; t++) {\r\n dp[r][i + t][j] = add(dp[r][i + t][j], multiply(value, coeffs[t]));\r\n if (t > 0) {\r\n dp[r][i + t - 1][j + 1] = add(dp[r][i + t - 1][j + 1], multiply(value, coeffs2[t]));\r\n }\r\n }\r\n }\r\n s += L;\r\n }\r\n int answer = 0;\r\n for (int i = 0; i <= s / k; i++)\r\n for (int r = 0; r <= n; r++) {\r\n int value = dp[(n - 1) & 1][i][r];\r\n int j = i + r;\r\n if (j == 0) continue;\r\n int temp = multiply(fact[i], inverse(power(k * j, i + 1)));\r\n answer = add(answer, multiply(value, temp));\r\n }\r\n out.println(multiply(subtract(0, s), answer));\r\n }\r\n\r\n }\r\n\r\n static class InputReader {\r\n private InputStream stream;\r\n private byte[] buf = new byte[1024];\r\n private int curChar;\r\n private int numChars;\r\n private InputReader.SpaceCharFilter filter;\r\n\r\n public InputReader(InputStream stream) {\r\n this.stream = stream;\r\n }\r\n\r\n public int[] readIntArray(int size) {\r\n int[] array = new int[size];\r\n for (int i = 0; i < size; i++) {\r\n array[i] = readInt();\r\n }\r\n return array;\r\n }\r\n\r\n public int read() {\r\n if (numChars == -1) {\r\n throw new InputMismatchException();\r\n }\r\n if (curChar >= numChars) {\r\n curChar = 0;\r\n try {\r\n numChars = stream.read(buf);\r\n } catch (IOException e) {\r\n throw new InputMismatchException();\r\n }\r\n if (numChars <= 0) {\r\n return -1;\r\n }\r\n }\r\n return buf[curChar++];\r\n }\r\n\r\n public int nextInt() {\r\n int c = read();\r\n while (isSpaceChar(c)) c = read();\r\n int sgn = 1;\r\n if (c == '-') {\r\n sgn = -1;\r\n c = read();\r\n }\r\n int res = 0;\r\n do {\r\n if (c < '0' || c > '9')\r\n throw new InputMismatchException();\r\n res *= 10;\r\n res += c - '0';\r\n c = read();\r\n } while (!isSpaceChar(c));\r\n return res * sgn;\r\n }\r\n\r\n public int readInt() {\r\n int c = read();\r\n while (isSpaceChar(c)) {\r\n c = read();\r\n }\r\n int sgn = 1;\r\n if (c == '-') {\r\n sgn = -1;\r\n c = read();\r\n }\r\n int res = 0;\r\n do {\r\n if (c < '0' || c > '9') {\r\n throw new InputMismatchException();\r\n }\r\n res *= 10;\r\n res += c - '0';\r\n c = read();\r\n } while (!isSpaceChar(c));\r\n return res * sgn;\r\n }\r\n\r\n public boolean isSpaceChar(int c) {\r\n if (filter != null) {\r\n return filter.isSpaceChar(c);\r\n }\r\n return isWhitespace(c);\r\n }\r\n\r\n public static boolean isWhitespace(int c) {\r\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\r\n }\r\n\r\n public interface SpaceCharFilter {\r\n public boolean isSpaceChar(int ch);\r\n\r\n }\r\n\r\n }\r\n\r\n static class OutputWriter {\r\n private final PrintWriter writer;\r\n\r\n public OutputWriter(OutputStream outputStream) {\r\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\r\n }\r\n\r\n public OutputWriter(Writer writer) {\r\n this.writer = new PrintWriter(writer);\r\n }\r\n\r\n public void println(Object... objects) {\r\n for (int i = 0; i < objects.length; i++) {\r\n if (i != 0) {\r\n writer.print(' ');\r\n }\r\n writer.print(objects[i]);\r\n }\r\n writer.print('\\n');\r\n }\r\n\r\n public void close() {\r\n writer.close();\r\n }\r\n\r\n }\r\n}\r\n\r\n", "lang_cluster": "Java", "tags": ["math", "probabilities", "combinatorics", "fft"], "code_uid": "ec059f0d05291b6ad00cbc24bc726bfc", "src_uid": "26d565c193a5920b042c783109496b4c", "difficulty": 3500.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main implements Runnable {\n\n\tpublic void _main() throws IOException {\n\t\tfinal int infinity = 1000000000;\n\t\t// A ray that is not collinear to any of the (dx, dy)`s\n\t\tfinal int RAY_R = 31;\n\t\tfinal int RAY_C = 37;\n\t\tint height = nextInt();\n\t\tint width = nextInt();\n\t\tchar[][] s = new char[height][];\n\t\tint sr = -1;\n\t\tint sc = -1;\n\t\tint numTreasures = 0;\n\t\tint numBombs = 0;\n\t\tint[][] treasureId = new int[height][width];\n\t\tint[][] bombId = new int[height][width];\t\t\n\t\tfor (int r = 0; r < height; r++) {\n\t\t\ts[r] = next().toCharArray();\n\t\t\tfor (int c = 0; c < width; c++) {\n\t\t\t\tif (s[r][c] == 'S') {\n\t\t\t\t\tsr = r;\n\t\t\t\t\tsc = c;\n\t\t\t\t\ts[r][c] = '.';\n\t\t\t\t}\n\t\t\t\ttreasureId[r][c] = -1;\n\t\t\t\tif (Character.isDigit(s[r][c])) {\n\t\t\t\t\ttreasureId[r][c] = s[r][c] - '1';\n\t\t\t\t\t++numTreasures;\n\t\t\t\t}\n\t\t\t\tbombId[r][c] = -1;\n\t\t\t\tif (s[r][c] == 'B') {\n\t\t\t\t\tbombId[r][c] = numBombs;\n\t\t\t\t\t++numBombs;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint[] treasureR = new int[numTreasures];\n\t\tint[] treasureC = new int[numTreasures];\n\t\tint[] bombR = new int[numBombs];\n\t\tint[] bombC = new int[numBombs];\n\t\tfor (int r = 0; r < height; r++) {\n\t\t\tfor (int c = 0; c < width; c++) {\n\t\t\t\tif (treasureId[r][c] >= 0) {\n\t\t\t\t\tint id = treasureId[r][c];\n\t\t\t\t\ttreasureR[id] = r;\n\t\t\t\t\ttreasureC[id] = c;\n\t\t\t\t}\n\t\t\t\tif (bombId[r][c] >= 0) {\n\t\t\t\t\tint id = bombId[r][c];\n\t\t\t\t\tbombR[id] = r;\n\t\t\t\t\tbombC[id] = c;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint[] cost = new int[numTreasures];\n\t\tfor (int i = 0; i < numTreasures; i++) {\n\t\t\tcost[i] = nextInt();\n\t\t}\n\t\tint[] value = new int[1 << (numTreasures + numBombs)];\n\t\tfor (int i = 1; i < value.length; i++) {\n\t\t\tint j = Integer.numberOfTrailingZeros(i);\n\t\t\tif (j < numTreasures) {\n\t\t\t\tvalue[i] = cost[j] + value[i ^ (1 << j)];\n\t\t\t} else {\n\t\t\t\tvalue[i] = -infinity;\n\t\t\t}\n\t\t}\n\t\tint qsize = height * width * (1 << (numTreasures + numBombs));\n\t\tint[] qr = new int[qsize];\n\t\tint[] qc = new int[qsize];\n\t\tint[] qmask = new int[qsize];\n\t\tint[][][] dist = new int[height][width][1 << (numTreasures + numBombs)];\n\t\tfor (int r = 0; r < height; r++) {\n\t\t\tfor (int c = 0; c < width; c++) {\n\t\t\t\tArrays.fill(dist[r][c], infinity);\n\t\t\t}\n\t\t}\n\t\tdist[sr][sc][0] = 0;\n\t\tqr[0] = sr;\n\t\tqc[0] = sc;\n\t\tqmask[0] = 0;\n\t\tint qt = 0;\n\t\tint qh = 1;\n\t\tint ans = 0;\n\t\twhile (qt < qh) {\n\t\t\tint r = qr[qt];\n\t\t\tint c = qc[qt];\n\t\t\tint mask = qmask[qt];\n\t\t\t++qt;\n\t\t\tif (r == sr && c == sc) {\n\t\t\t\tans = Math.max(ans, value[mask] - dist[r][c][mask]);\n\t\t\t}\n\t\t\tfor (int dr = -1; dr <= 1; dr++) {\n\t\t\t\tfor (int dc = -1; dc <= 1; dc++) {\n\t\t\t\t\tif (dr == 0 ^ dc == 0) {\n\t\t\t\t\t\tint nr = r + dr;\n\t\t\t\t\t\tint nc = c + dc;\n\t\t\t\t\t\tif (nr < 0 || nr >= height || nc < 0 || nc >= width) continue;\n\t\t\t\t\t\tif (s[nr][nc] != '.') continue;\n\t\t\t\t\t\tint nmask = mask;\n\t\t\t\t\t\tfor (int i = 0; i < numTreasures + numBombs; i++) {\n\t\t\t\t\t\t\tint or, oc;\n\t\t\t\t\t\t\tif (i < numTreasures) {\n\t\t\t\t\t\t\t\tor = treasureR[i];\n\t\t\t\t\t\t\t\toc = treasureC[i];\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tor = bombR[i - numTreasures];\n\t\t\t\t\t\t\t\toc = bombC[i - numTreasures];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tint r1 = r - or;\n\t\t\t\t\t\t\tint c1 = c - oc;\n\t\t\t\t\t\t\tint r2 = nr - or;\n\t\t\t\t\t\t\tint c2 = nc - oc;\n\t\t\t\t\t\t\tif (r1 < 0 || r2 < 0 || c1 < 0 || c2 < 0) continue;\n\t\t\t\t\t\t\tif (Integer.signum(cross(r1, c1, RAY_R, RAY_C)) == Integer.signum(cross(RAY_R, RAY_C, r2, c2))) {\n\t\t\t\t\t\t\t\tnmask ^= 1 << i;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (dist[nr][nc][nmask] > 1 + dist[r][c][mask]) {\n\t\t\t\t\t\t\tdist[nr][nc][nmask] = 1 + dist[r][c][mask];\n\t\t\t\t\t\t\tqr[qh] = nr;\n\t\t\t\t\t\t\tqc[qh] = nc;\n\t\t\t\t\t\t\tqmask[qh] = nmask;\n\t\t\t\t\t\t\t++qh;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(ans);\n\t}\n\n\tprivate int cross(int x1, int y1, int x2, int y2) {\n\t\treturn x1*y2 - x2*y1;\n\t}\n\n\n\tprivate BufferedReader in;\n\tprivate PrintWriter out;\n\tprivate StringTokenizer st;\n\n\tprivate String next() throws IOException {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\tString rl = in.readLine();\n\t\t\tif (rl == null)\n\t\t\t\treturn null;\n\t\t\tst = new StringTokenizer(rl);\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tprivate int nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tprivate long nextLong() throws IOException {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tprivate double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tLocale.setDefault(Locale.UK);\n\t\tnew Thread(new Main()).start();\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\t//in = new BufferedReader(new FileReader(\"a.in\"));\n\t\t\t//out = new PrintWriter(new FileWriter(\"a.out\"));\n\n\t\t\t_main();\n\n\t\t\tout.close();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(202);\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["shortest paths", "bitmasks"], "code_uid": "e268801040a34c368de6640108f4c695", "src_uid": "624a0d6cf305fcf67d3f1cdc1c5fef8d", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskC {\n int n;\n char[] colorCard;\n int[] costRedToken;\n int[] costBlueToken;\n final int inf = (int) 1e9;\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n n = in.readInt();\n colorCard = new char[n];\n costRedToken = new int[n];\n costBlueToken = new int[n];\n\n int overRed = 0;\n int overBlue = 0;\n\n for (int i = 0; i < n; i++) {\n colorCard[i] = in.readCharacter();\n\n costRedToken[i] = in.readInt();\n costBlueToken[i] = in.readInt();\n\n overRed += Math.max(costRedToken[i] - n, 0);\n overBlue += Math.max(costBlueToken[i] - n, 0);\n\n costRedToken[i] = Math.min(n, costRedToken[i]);\n costBlueToken[i] = Math.min(n, costBlueToken[i]);\n }\n\n\n int over = Math.max(overRed, overBlue);\n\n int[][][] dp = new int[2][n * n + 1][1 << n];\n ArrayUtils.fill(dp, inf);\n\n if (overRed < overBlue) {\n dp[0][Math.min(over - overRed, n * n)][0] = 0;\n } else {\n dp[1][Math.min(over - overBlue, n * n)][0] = 0;\n }\n\n for (int msk = 0; msk < (1 << n); msk++) {\n for (int typeRemToken = 0; typeRemToken < 2; typeRemToken++) {\n for (int countRemTokens = 0; countRemTokens <= n * n; countRemTokens++) {\n\n if (dp[typeRemToken][countRemTokens][msk] == inf) {\n continue;\n }\n\n int countRedCard = 0;\n int countBlueCard = 0;\n for (int card = 0; card < n; card++) {\n if (((msk >> card) & 1) == 1) {\n if (colorCard[card] == 'R') {\n ++countRedCard;\n } else if (colorCard[card] == 'B') {\n ++countBlueCard;\n } else {\n throw new RuntimeException();\n }\n }\n }\n\n for (int card = 0; card < n; card++) {\n if (((msk >> card) & 1) == 1) {\n continue;\n }\n\n int countHaveRedToken = typeRemToken == 0 ? countRemTokens : 0;\n int countHaveBlueToken = typeRemToken == 1 ? countRemTokens : 0;\n\n int costRed = Math.max(costRedToken[card] - countRedCard, 0);\n int costBlue = Math.max(costBlueToken[card] - countBlueCard, 0);\n\n int countBuyToken = Math.max(Math.max(costRed - countHaveRedToken, 0), Math.max(costBlue -\n countHaveBlueToken, 0));\n\n int remRedToken = countBuyToken + countHaveRedToken - costRed;\n int remBlueToken = countBuyToken + countHaveBlueToken - costBlue;\n\n int toMsk = msk | (1 << card);\n int toTypeRemToken = remRedToken == 0 ? 1 : 0;\n int toCountRemTokens = Math.min(Math.max(remRedToken, remBlueToken), n * n);\n\n dp[toTypeRemToken][toCountRemTokens][toMsk] = Math.min\n (dp[toTypeRemToken][toCountRemTokens][toMsk],\n dp[typeRemToken][countRemTokens][msk] + countBuyToken);\n\n }\n }\n }\n }\n\n int curAns = inf;\n for (int typeRemToken = 0; typeRemToken < 2; typeRemToken++) {\n for (int countRemTokens = 0; countRemTokens <= n * n; countRemTokens++) {\n curAns = Math.min(curAns, dp[typeRemToken][countRemTokens][(1 << n) - 1]);\n }\n }\n out.printLine(n + over + curAns);\n// out.printLine(dp[0][1][0b1]);\n// out.printLine(dp[0][1][0b11]);\n// out.printLine(dp[0][1][0b111]);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if ((c < '0') || (c > '9')) {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return (c == ' ') || (c == '\\n') || (c == '\\r') || (c == '\\t') || (c == -1);\n }\n\n public char readCharacter() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n return (char) c;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void printLine(int i) {\n writer.println(i);\n }\n\n }\n\n static class ArrayUtils {\n public static void fill(int[][] array, int value) {\n for (int[] row : array) {\n Arrays.fill(row, value);\n }\n }\n\n public static void fill(int[][][] array, int value) {\n for (int[][] subArray : array) {\n fill(subArray, value);\n }\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["brute force", "dp", "bitmasks"], "code_uid": "04f8bf1def9353fe7ead0594c708a038", "src_uid": "25a77f2b7cb281ff3c7800a20b3e5969", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class p4\r\n{\r\n\tBufferedReader br;\r\n\tStringTokenizer st;\r\n\tBufferedWriter bw;\r\n\tpublic static void main(String[] args)throws Exception\r\n\t{\r\n\t\tnew p4().run();\r\n\t}\r\n\r\n\tvoid run()throws IOException\r\n\t{\r\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\r\n\t\tbw=new BufferedWriter(new OutputStreamWriter(System.out));\r\n\t\tsolve();\r\n\t}\r\n\tvoid solve() throws IOException\r\n\t{\r\n\t\tint limit=100001;\r\n\t\tint fac[]=new int[limit];\r\n\t\tint invfac[]=new int[limit];\r\n\t\tfac[0]=1;\r\n\t\tinvfac[0]=1;\r\n\t\tint mod=1000000007;\r\n\t\tfor(int i=0;++i0)\r\n\t\t{\r\n\t\t\tint n=ni();\r\n\t\t\tint k=ni();\r\n\r\n\t\t\tlong ans=1;\r\n\t\t\tk=Math.min(k, n);\r\n\t\t\tfor(int i=0;++i<=k;)\r\n\t\t\t{\r\n\t\t\t\tlong x=fac[n];\r\n\t\t\t\tx*=invfac[i];\r\n\t\t\t\tx%=mod;\r\n\t\t\t\tx*=invfac[n-i];\r\n\t\t\t\tx%=mod;\r\n\t\t\t\t\r\n\t\t\t\tans+=x;\r\n\t\t\t\tans%=mod;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tbw.write(ans+\"\\n\");\r\n\r\n\t\t}\r\n\t\tbw.flush();\r\n\t}\r\n\r\n\tpublic long mod(long a)\r\n\t{\r\n\t\tint mod=1000000007;\r\n\t\ta%=mod;\r\n\t\tif(a<0)\r\n\t\t\ta+=mod;\r\n\t\t\r\n\t\treturn a;\r\n\t}\r\n\r\n\tpublic long nPowerM(int n, int m)\r\n\t{\r\n\t\tif(m==0)\r\n\t\t\treturn 1L;\r\n\t\t\r\n\t\tint mod=1000000007;\r\n\t\tlong ans=nPowerM(n, m/2);\r\n\t\tans*=ans;\r\n\t\tans%=mod;\r\n\t\t\r\n\t\tif(m%2==1)\r\n\t\t{\r\n\t\t\tans*=n;\r\n\t\t\tans%=mod;\r\n\t\t}\r\n\t\t\r\n\t\treturn ans;\r\n\t}\r\n\t/////////////////////////////////////// FOR INPUT ///////////////////////////////////////\r\n\r\n\tint[] nai(int n) { int a[]=new int[n]; for(int i=-1;++i1){\n \t\tSystem.out.println(\"NO\");\n \t\treturn;\n \t}\n }\n if(str.contains(\"Slava\")){\n \tif(str.indexOf(\"Slava\") != str.lastIndexOf(\"Slava\")){\n \t\tSystem.out.println(\"NO\");\n \t\treturn;\n \t}\n \tcount++;\n \tif(count>1){\n \t\tSystem.out.println(\"NO\");\n \t\treturn;\n \t}\n }\n if(str.contains(\"Ann\")){\n \tif(str.indexOf(\"Ann\") != str.lastIndexOf(\"Ann\")){\n \t\tSystem.out.println(\"NO\");\n \t\treturn;\n \t}\n \tcount++;\n \tif(count>1){\n \t\tSystem.out.println(\"NO\");\n \t\treturn;\n \t}\n }\n if(str.contains(\"Nikita\")){\n \tif(str.indexOf(\"Nikita\") != str.lastIndexOf(\"Nikita\")){\n \t\tSystem.out.println(\"NO\");\n \t\treturn;\n \t}\n \tcount++;\n \tif(count>1){\n \t\tSystem.out.println(\"NO\");\n \t\treturn;\n \t}\n }\n \n if(count == 1)\n \tSystem.out.println(\"YES\");\n else\n \tSystem.out.println(\"NO\");\n\t}\n\n}", "lang_cluster": "Java", "tags": ["strings", "implementation"], "code_uid": "5294d2d23cf56a8a026b1aa0e49a9b0c", "src_uid": "db2dc7500ff4d84dcc1a37aebd2b3710", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.lang.*;\n\npublic class Main {\n\n private static Reader in;\n private static PrintWriter out;\n\n private static int n;\n private static int[] upper, lower, f;\n\n public static void main(String[] args) throws IOException {\n in = new Reader(System.in);\n out = new PrintWriter(System.out);\n\n upper = new int[20];\n lower = new int[20];\n int l1 = to_digit(in.nextLong(), lower);\n int l2 = to_digit(in.nextLong(), upper);\n\n n = l2;\n f = new int[20];\n out.println( dfs(0, n) );\n\n out.close();\n }\n\n private static int to_digit(long x, int[] a) {\n int n = 0;\n while (x != 0) {\n ++n;\n a[n] = (int) (x % 10);\n x /= 10;\n }\n return n;\n }\n\n private static int dfs(int step, int range) {\n if (step == 9) {\n f[step] = range;\n /*\n for (int i = n; i > 0; --i)\n out.print(f[i] + \" \");\n out.println();\n */\n return check(n, true, true) ? 1 : 0;\n }\n int res = 0;\n for (int i = 0; i <= range; ++i) {\n f[step] = i;\n res += dfs(step + 1, range - i);\n }\n return res;\n }\n\n private static boolean check(int step, boolean left_flag, boolean right_flag) {\n if (step == 0) return true;\n if (!left_flag && !right_flag) return true;\n\n //out.println(step + \" \" + left_flag + \" \" + right_flag);\n\n int left = left_flag ? lower[step] : 0;\n int right = right_flag ? upper[step] : 9;\n\n //out.println(step + \" \" + left + \" \" + right);\n for (int i = left; i <= right; ++i)\n if (f[i] != 0) {\n --f[i];\n boolean res = check(step - 1, left_flag && i == left, right_flag && i == right);\n ++f[i];\n if (res) return true;\n }\n return false;\n }\n\n}\n\n/** Class for buffered reading int and double values */\nclass Reader {\n static BufferedReader reader;\n static StringTokenizer tokenizer;\n\n Reader(InputStream input) {\n init(input);\n }\n\n /** call this method to initialize reader for InputStream */\n static void init(InputStream input) {\n reader = new BufferedReader(\n new InputStreamReader(input) );\n tokenizer = new StringTokenizer(\"\");\n }\n\n /** get next word */\n static String next() throws IOException {\n while ( ! tokenizer.hasMoreTokens() ) {\n //TODO add check for eof if necessary\n tokenizer = new StringTokenizer(\n reader.readLine() );\n }\n return tokenizer.nextToken();\n }\n\n static int nextInt() throws IOException {\n return Integer.parseInt( next() );\n }\n\n\n static double nextDouble() throws IOException {\n return Double.parseDouble( next() );\n }\n\n static long nextLong() throws IOException {\n return Long.parseLong( next() );\n }\n\n}\n", "lang_cluster": "Java", "tags": ["math", "greedy", "combinatorics", "brute force"], "code_uid": "21ea65fd5c354ed79e20bc8233d5f94a", "src_uid": "adfa5f280eefbacdbaa4ad605402b57a", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\n\npublic class Solution {\n\n\tpublic static void main(String[] args) {\n\t\t\n\t Scanner in = new Scanner(System.in);\n\t int n=in.nextInt();\n\t int a1=in.nextInt();\n\t int b1=in.nextInt();\n\t int c1=in.nextInt();\n\t \n\t long a=a1,b=b1,c=c1;\n\t \n\t int m=n%4;\n\t if(m==0){\n\t \tSystem.out.println(0);\n\t \treturn;\n\t }\n\t \n\t if(m==3){\n\t \tlong q=Math.min(a, b+c); \n\t \t\n\t \tlong w=Math.min(3*c, q);\n\t \tSystem.out.println(w);\n\t \treturn;\n\t }\n\t else if(m==2){\n\t \tlong q=Math.min(2*a, b);\n\t \tlong w=Math.min(2*c, q);\n\t \tSystem.out.println(w);\n\t }\n\t \n\t if(m==1){\n\t \tlong q=Math.min(3*a, a+b);\n\t \tlong z=Math.min(q,c);\n\t \tSystem.out.println(z);\n\t }\n\t \n\t \n }\n}", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "7fd798d9d29f9b48cd5a126ceb3ee957", "src_uid": "c74537b7e2032c1d928717dfe15ccfb8", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.util.*;\n\n\npublic class bucky{\n\n\n\n\npublic static void main (String args[]) {\n\nScanner input=new Scanner(System.in);\n\nHashMap map= new HashMap();\nHashMap map2= new HashMap();\n\n\t\n\t\n\t\n\t\n\t\tint n=input.nextInt();\n\t\tdouble max=0;double contor=0; int a=0;\n\t\t\n\t\tint nums[]=new int[n-1];\n\t\t\n\tint start;\n\t\t\n\t\tfor(int i=0;i0 && k>=k2)\n\t\t {\n\t\t k-=k2;\n\t\t max++;\n\t\t p--;\n\t\t }\n\t\t while(k>=k1 && j>0)\n\t\t {\n\t\t k=k-k1;\n\t\t j--;\n\t\t max++;\n\t\t }\n\t\t }\n\t\t else\n\t\t {\n\t\t p=a1;k=n;j=a2;\n\t\t while(p>0 && k>=k1)\n\t\t {\n\t\t k-=k1;\n\t\t max++;\n\t\t p--;\n\t\t }\n\t\t while(k>=k2 && j>0)\n\t\t {\n\t\t k=k-k2;\n\t\t j--;\n\t\t max++;\n\t\t }\n\t\t }\n\t k=n-(k2-1)*a2-(k1-1)*a1;\n\t min=Math.max(0,k);\n\t System.out.println(min+\" \"+max);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "greedy", "implementation"], "code_uid": "fab872d2067ceb28cf4c2580ba61b733", "src_uid": "2be8e0b8ad4d3de2930576c0209e8b91", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.InputMismatchException;\nimport java.util.List;\nimport java.util.Map;\n\npublic class Main {\n\n\tprivate static final int MAXN = 5000;\n\tprivate static final String NO = \"NO\";\n\tprivate static final String YES = \"YES\";\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\n\tprivate static final long MOD = 1000000007L;\n\tprivate static final int MAX = Integer.MAX_VALUE / 4;\n\n\tvoid solve() {\n\t\tint H = ni() % 12;\n\t\tint M = ni();\n\t\tint S = ni();\n\t\tint T1 = ni();\n\t\tint T2 = ni();\n\t\tdouble a[] = new double[3];\n\t\ta[0] = S * 360.0 / 60;\n\t\ta[1] = (M + S / 60.0) * 360 / 60;\n\t\ta[2] = (H + (M + S /60.0) /60) * 360.0 / 12;\n//\t\ttr(a);\n\t\tArrays.sort(a);\n//\t\ttr(a);\n\t\tout.print(get(a, T1) == get(a, T2) ? YES : NO);\n\t}\n\n\tprivate int get(double[] a, int t) {\n\t\tdouble b = t*360.0/12;\n//\t\ttr(b);\n\t\tif (b<=a[1] && b>=a[0])\n\t\t\treturn 0;\n\t\tif (b<=a[2] && b>=a[1])\n\t\t\treturn 1;\n\t\treturn 2;\n\t}\n\n\tlong power(long a, long b) {\n\t\tlong x = 1, y = a;\n\t\twhile (b > 0) {\n\t\t\tif (b % 2 != 0) {\n\t\t\t\tx = (x * y) % MOD;\n\t\t\t}\n\t\t\ty = (y * y) % MOD;\n\t\t\tb /= 2;\n\t\t}\n\t\treturn x % MOD;\n\t}\n\n\tprivate long gcd(long a, long b) {\n\t\twhile (a != 0) {\n\t\t\tlong tmp = b % a;\n\t\t\tb = a;\n\t\t\ta = tmp;\n\t\t}\n\t\treturn b;\n\t}\n\n\tvoid run() throws Exception {\n\t\tis = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\tif (!INPUT.isEmpty())\n\t\t\ttr(System.currentTimeMillis() - s + \"ms\");\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew Main().run();\n\t}\n\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\tprivate boolean vis[];\n\n\tprivate int readByte() {\n\t\tif (lenbuf == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (ptrbuf >= lenbuf) {\n\t\t\tptrbuf = 0;\n\t\t\ttry {\n\t\t\t\tlenbuf = is.read(inbuf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (lenbuf <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\n\tprivate boolean isSpaceChar(int c) {\n\t\treturn !(c >= 33 && c <= 126);\n\t}\n\n\tprivate int skip() {\n\t\tint b;\n\t\twhile ((b = readByte()) != -1 && isSpaceChar(b))\n\t\t\t;\n\t\treturn b;\n\t}\n\n\tprivate double nd() {\n\t\treturn Double.parseDouble(ns());\n\t}\n\n\tprivate char nc() {\n\t\treturn (char) skip();\n\t}\n\n\tprivate String ns() {\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != '\n\t\t\t\t\t\t\t\t\t// ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tprivate char[] ns(int n) {\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile (p < n) {\n\t\t\tif (!(isSpaceChar(b)))\n\t\t\t\tbuf[p++] = (char) b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\n\tprivate char[][] nm(int n, int m) {\n\t\tchar[][] map = new char[n][];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tmap[i] = ns(m);\n\t\treturn map;\n\t}\n\n\tprivate int[] na(int n) {\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = ni();\n\t\treturn a;\n\t}\n\n\tprivate Integer[] na2(int n) {\n\t\tInteger[] a = new Integer[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = ni();\n\t\treturn a;\n\t}\n\n\tprivate int[][] na(int n, int m) {\n\t\tint[][] a = new int[n][];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = na(m);\n\t\treturn a;\n\t}\n\n\tprivate Integer[][] na2(int n, int m) {\n\t\tInteger[][] a = new Integer[n][];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = na2(m);\n\t\treturn a;\n\t}\n\n\tprivate int ni() {\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t;\n\t\tif (b == '-') {\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\n\tprivate long[] nl(int n) {\n\t\tlong[] a = new long[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = nl();\n\t\treturn a;\n\t}\n\n\tprivate long nl() {\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t;\n\t\tif (b == '-') {\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\n\tprivate static void tr(Object... o) {\n\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "3715f358bfaf66366dfdcadf5fd23cd6", "src_uid": "912c8f557a976bdedda728ba9f916c95", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\n\npublic class Main\n{\n\tstatic final long mod=(int)1e9+7;\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tFastReader in=new FastReader();\n\t\tPrintWriter pw=new PrintWriter(System.out);\n\t\tint n=in.nextInt();\n\t\tlong m=in.nextInt();\n\t\tint k=in.nextInt();\n\t\tlong[][] dp=new long[n+1][k+1];\n\t\tlong ans=0;\n\t\tfor(int i=1;i<=n;i++)\n\t\t{\n\t\t\tdp[i][0]=m;\n\n\t\t\tfor(int j=1;jn%x)\n\t\t\tfor(z=2-x,y=Math.max(x,(int)Math.ceil((z+Math.sqrt(z*z+((m=n/x)<<2)))/2));y*y<=m;++y)\n\t\t\t\tif(1>m%y&&1>(1&(x^(z=m/y)^y)))\n\t\t\t\t{a=x+y-z;s+=(c=(y<<1)-a)==a?1:(b=(x<<1)-a)==a||b==c?3:6;}\n\t\tSystem.out.print(s);\n\t}\n}\n", "lang_cluster": "Java", "tags": ["brute force", "math", "number theory"], "code_uid": "91c8ceb2210a3fdd7d8d4c8b151f4bc6", "src_uid": "07e58a46f2d562a44b7c771edad361b4", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Alex\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskD solver = new TaskD();\n solver.solve(1, in, out);\n out.close();\n }\n static class TaskD {\n long MOD = 1000 * 1000 * 1000 + 7;\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int A = in.readInt();\n int B = in.readInt();\n long n = in.readLong();\n int x = in.readInt();\n int[][] pow = new int[][] {{A, B}, {0, 1}};\n pow = pow(pow, n);\n int[][] init = new int[][] {{x, 0}, {1, 0}};\n out.printLine(mult(pow, init)[0][0]);\n }\n private int[][] mult(int[][] a, int[][] b) {\n int[][] res = new int[2][2];\n for (int firstrow = 0; firstrow < 2; firstrow++) {\n for (int secondcol = 0; secondcol < 2; secondcol++) {\n int sum = 0;\n for (int i = 0; i < 2; i++) {\n sum += ((long) a[firstrow][i] * b[i][secondcol]) % MOD;\n if (sum >= MOD) sum -= MOD;\n }\n res[firstrow][secondcol] = sum;\n }\n }\n return res;\n }\n private int[][] pow(int[][] mat, long pow) {\n if (pow == 0) return new int[][] {{1, 0}, {0, 1}};\n if (pow == 1) return mat;\n int[][] half = pow(mat, pow / 2);\n int[][] full = mult(half, half);\n if (pow % 2 == 1) {\n full = mult(full, mat);\n }\n return full;\n }\n }\n static class OutputWriter {\n private final PrintWriter writer;\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n public void close() {\n writer.close();\n }\n public void printLine(int i) {\n writer.println(i);\n }\n }\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n public int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n public int readInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n public long readLong() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return isWhitespace(c);\n }\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n }\n}\n\n", "lang_cluster": "Java", "tags": ["math", "number theory"], "code_uid": "d46efc7aefac7e5f354b825824926969", "src_uid": "e22a1fc38c8b2a4cc30ce3b9f893028e", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\r\npublic class math {\r\n public static void main(String args[]) {\r\n Scanner sc = new Scanner(System.in);\r\n int n = sc.nextInt();\r\n System.out.println(2-n*n);\r\n }\r\n}", "lang_cluster": "Java", "tags": ["math"], "code_uid": "3e4e2dc7da7b052eaa583a6a9df89ed8", "src_uid": "f76005f888df46dac38b0f159ca04d5f", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\n\nimport java.io.*;\nimport java.math.*;\nimport java.awt.geom.*;\n\nimport static java.lang.Math.*;\n\npublic class Solution implements Runnable {\n\n\tlong mod = (long) 1e9 + 7;\n\tint mod2 = 998244353;\n\n\tpublic void solve() throws Exception {\n\t\tlong x = sc.nextLong();\n\t\tlong k =sc.nextLong();\n\t\t//out.println(calculate(x));\n\t\tif(x==0) {\n\t\t\tout.println(0);\n\t\t\treturn;\n\t\t}\n\t\tout.println(((((((calculate(k+1)%mod)*(x%mod))%mod)+mod)%mod - (calculate(k))%mod + 1l)%mod+mod)%mod);\n\t\t\n\n\t}\n\t\n\tpublic long calculate(long pow) {\n\t\tif(pow==1) return 2l;\n\t\tif(pow==0) return 1l;\n\t\tlong temp = calculate(pow/2);\n\t\tif(pow%2==1)\n\t\t{\n\t\t\treturn ((((temp%mod)*(temp%mod)*2l)%mod)+mod)%mod;\n\t\t}\n\t\telse\n\t\t{\n\t\t\treturn ((((temp%mod)*(temp%mod))%mod)+mod)%mod;\n\t\t}\n\t}\n\n\tstatic void sort(int[] a) {\n\t\tArrayList l = new ArrayList<>();\n\t\tfor (int i : a)\n\t\t\tl.add(i);\n\t\tCollections.sort(l);\n\t\tfor (int i = 0; i < a.length; i++)\n\t\t\ta[i] = l.get(i);\n\t}\n\n\tstatic long gcd(long a, long b) {\n\t\tif (a == 0)\n\t\t\treturn b;\n\t\treturn gcd(b % a, a);\n\t}\n\n\tstatic long ncr(int n, int r, long p) {\n\t\tif (r > n)\n\t\t\treturn 0l;\n\t\tif (r > n - r)\n\t\t\tr = n - r;\n\n\t\tlong C[] = new long[r + 1];\n\n\t\tC[0] = 1;\n\n\t\tfor (int i = 1; i <= n; i++) {\n\n\t\t\tfor (int j = Math.min(i, r); j > 0; j--)\n\t\t\t\tC[j] = (C[j] + C[j - 1]) % p;\n\t\t}\n\t\treturn C[r] % p;\n\t}\n\n\tpublic long power(long x, long y, long p) {\n\t\tlong res = 1;\n\t\t// out.println(x+\" \"+y);\n\t\tx = x % p;\n\t\tif (x == 0)\n\t\t\treturn 0;\n\n\t\twhile (y > 0) {\n\t\t\tif ((y & 1) == 1)\n\t\t\t\tres = (res * x) % p;\n\t\t\ty = y >> 1;\n\t\t\tx = (x * x) % p;\n\t\t}\n\t\treturn res;\n\t}\n\n\tstatic Throwable uncaught;\n\n\tBufferedReader in;\n\tFastScanner sc;\n\tPrintWriter out;\n\n\t@Override\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsc = new FastScanner(in);\n\t\t\tsolve();\n\t\t} catch (Throwable uncaught) {\n\t\t\tSolution.uncaught = uncaught;\n\t\t} finally {\n\t\t\tout.close();\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws Throwable {\n\t\tThread thread = new Thread(null, new Solution(), \"\", (1 << 26));\n\t\tthread.start();\n\t\tthread.join();\n\t\tif (Solution.uncaught != null) {\n\t\t\tthrow Solution.uncaught;\n\t\t}\n\t}\n\n}\n\nclass FastScanner {\n\n\tBufferedReader in;\n\tStringTokenizer st;\n\n\tpublic FastScanner(BufferedReader in) {\n\t\tthis.in = in;\n\t}\n\n\tpublic String nextToken() throws Exception {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tpublic int nextInt() throws Exception {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tpublic int[] readArray(int n) throws Exception {\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = nextInt();\n\t\treturn a;\n\t}\n\n\tpublic long nextLong() throws Exception {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tpublic double nextDouble() throws Exception {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n}", "lang_cluster": "Java", "tags": ["math"], "code_uid": "abf671305774efdfa4783472c9145e5e", "src_uid": "e0e017e8c8872fc1957242ace739464d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "// Let f(x) = # of sequences a_i such that gcd() = 1, sum(a_i)=x. We want f(y - x). This is a hard AF function to calculate: easiest recurrence would be sum(f_i) where i divisors = new ArrayList();\n\t\tfor (i = 1; i * i < t; i++) {\n\t\t\tif (t % i == 0) {\n\t\t\t\tdivisors.add(i); divisors.add(t / i);\n\t\t\t}\n\t\t}\n\t\tif (i * i == t) divisors.add(i);\n\t\tint[] d = new int[divisors.size()];\n\t\tfor (i = 0; i < d.length; i++) {\n\t\t\td[i] = divisors.get(i);\n\t\t}\n\t\tArrays.sort(d);\n\t\tlong[] f = new long[divisors.size()];\n\t\tf[0] = 1;\n\t\tfor (i = 1; i < d.length; i++) {\n\t\t\tf[i] = pow(d[i] - 1);\n\t\t\tfor (int j = 0; j < i; j++) {\n\t\t\t\tif (d[i] % d[j] == 0) f[i] = (f[i] - f[j] + N) % N;\n\t\t\t}\n\t\t}\n//\t\tSystem.out.println(Arrays.toString(d));\n//\t\tSystem.out.println(Arrays.toString(f));\n\t\tSystem.out.println(f[d.length - 1]);\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics", "bitmasks", "number theory"], "code_uid": "c1b6cbe9d0e32628226a6b92fe290a2b", "src_uid": "de7731ce03735b962ee033613192f7bc", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "\nimport java.util.Scanner;\n\npublic class E {\n public static boolean solve(long x, long y, long c, long d) {\n if (x == 0 && y == 0)\n return c == 0 && d == 0;\n if (x == 0)\n return c % y == 0 && d % y == 0;\n if (y == 0)\n return c % x == 0 && d % x == 0;\n if ((c * x + d * y) % (x * x + y * y) != 0)\n return false;\n long a = (c * x + d * y) / (x * x + y * y);\n return (d - a * y) % x == 0;\n }\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n long ax = in.nextInt();\n long ay = in.nextInt();\n long bx = in.nextInt();\n long by = in.nextInt();\n long cx = in.nextInt();\n long cy = in.nextInt();\n if (solve(cx, cy, bx - ax, by - ay) || solve(cx, cy, bx - ay, by + ax)\n || solve(cx, cy, bx + ax, by + ay)\n || solve(cx, cy, bx + ay, by - ax))\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n }\n\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "d8b1953e03ed20713d5f9531ad2d8b07", "src_uid": "cc8a8af1ba2b19bf081e379139542883", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import static java.lang.Math.*;\nimport static java.math.BigInteger.*;\nimport static java.util.Arrays.*;\nimport static java.util.Collections.*;\n\nimport java.io.*;\nimport java.lang.reflect.*;\nimport java.util.*;\n\npublic class D {\n\n\tfinal static boolean autoflush = false;\n\t\n\tfinal static int MOD = (int) 1e9 + 7;\n\tfinal static double eps = 1e-9;\n\tfinal static int INF = (int) 1e9;\n\t\n\tInteger [] A;\n\tint N; int [] Q; int [][] R;\n\t\n\tpublic D () {\n\t\tN = sc.nextInt();\n\t\tA = sc.nextInts();\n\t\t\n\t\tif (N == 1)\n\t\t\texit(1);\n\t\t\n\t\tnext: for (int i : rep(1, N)) {\n\t\t\tfor (int j : rep(i)) \n\t\t\t\tfor (int k : rep(i))\n\t\t\t\t\tif (A[j] + A[k] == A[i])\n\t\t\t\t\t\tcontinue next;\n\t\t\texit(-1);\n\t\t}\n\t\t\n\t\tMap M = new TreeMap();\n\t\tfor (int i : rep(N))\n\t\t\tM.put(A[i], i);\n\n\t\tQ = new int [N];\n\t\tR = new int [N][N];\n\t\t\n\t\tfor (int i : rep(N))\n\t\t\tfor (int j : rep(i))\n\t\t\t\tif (M.containsKey(A[i] - A[j])) {\n\t\t\t\t\tint k = M.get(A[i] - A[j]);\n\t\t\t\t\tQ[i] |= (1 << j);\n\t\t\t\t\tR[i][j] = k;\n\t\t\t\t}\n\n\t\tH = new int [1 << (N-1)]; fill(H, -1);\n\t\t\n\t\tint res = solve(1, 1);\n\t\tassert res <= N;\n\t\texit(res);\n\t}\n\t\t\n\tint [] H;\n\t\n\tint solve(int X, int J) {\n\t\tint B = (X & Q[J]);\n\t\tif (B == 0)\n\t\t\treturn H[X] = INF;\n\t\t\n\t\tfor (int i = 0; i < J; ++i) {\n\t\t\tint U = (1 << i), V = (1 << R[J][i]);\n\t\t\tif ((B&U) != 0 && (B&V) != 0)\n\t\t\t\tbreak;\n\t\t\tif (i == J-1)\n\t\t\t\treturn H[X] = INF;\n\t\t}\n\t\t\n\t\tif (J == N-1)\n\t\t\treturn H[X] = Integer.bitCount(X);\n\t\t\n\t\tint Y = (X | (1 << J)), res = INF;\n\t\tfor (int j = 0; j < J; ++j) {\n\t\t\tint W = (1 << j);\n\t\t\tif ((Y & W) != 0) {\n\t\t\t\tint V = Y & (~W), R = H[V] == -1 ? solve(V, J+1) : H[V];\n\t\t\t\tres = min(res, R);\n\t\t\t}\n\t\t}\n\t\tint R = H[Y] == -1 ? solve(Y, J+1) : H[Y];\n\t\tres = min(res, R);\n\t\treturn H[X] = res;\t\t\n\t}\n\n\t////////////////////////////////////////////////////////////////////////////////////\n\n\tstatic int [] rep(int N) { return rep(0, N); }\n\tstatic int [] rep(int S, int T) { int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }\n\tstatic int [] req(int S, int T) { return rep(S, T+1); }\t\n\n\t////////////////////////////////////////////////////////////////////////////////////\n\n\t/* Dear hacker, don't bother reading below this line, unless you want to help me debug my I/O routines :-) */\n\t\n\tfinal static MyScanner sc = new MyScanner();\n\t\n\tstatic class MyScanner {\n\t\tpublic String next() {\n\t\t\tnewLine();\n\t\t\treturn line[index++];\n\t\t}\n\t\t\n\t\tpublic char nextChar() {\n\t\t\treturn next().charAt(0);\n\t\t}\n\t\t\t\t\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\t\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\t\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\t\n\t\tpublic String nextLine() {\n\t\t\tline = null;\n\t\t\treturn readLine();\n\t\t}\n\t\t\n\t\tpublic String [] nextStrings() {\n\t\t\tline = null;\n\t\t\treturn readLine().split(\" \");\n\t\t}\n\t\t\n\t\tpublic char [] nextChars() {\n\t\t\treturn next ().toCharArray ();\n\t\t}\n\n\t\tpublic Integer [] nextInts() {\n\t\t\tString [] L = nextStrings();\n\t\t\tInteger [] res = new Integer [L.length];\n\t\t\tfor (int i : rep(L.length))\n\t\t\t\tres[i] = Integer.parseInt(L[i]);\n\t\t\treturn res;\n\t\t}\t\n\t\t\n\t\tpublic Long [] nextLongs() {\n\t\t\tString [] L = nextStrings();\n\t\t\tLong [] res = new Long [L.length];\n\t\t\tfor (int i : rep(L.length))\n\t\t\t\tres[i] = Long.parseLong(L[i]);\n\t\t\treturn res;\n\t\t}\n\n\t\tpublic Double [] nextDoubles() {\n\t\t\tString [] L = nextStrings();\n\t\t\tDouble [] res = new Double [L.length];\n\t\t\tfor (int i : rep(L.length))\n\t\t\t\tres[i] = Double.parseDouble(L[i]);\n\t\t\treturn res;\n\t\t}\n\n\t\tpublic String [] next (int N) {\n\t\t\tString [] res = new String [N];\n\t\t\tfor (int i : rep(N))\n\t\t\t\tres[i] = sc.next();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic Integer [] nextInt (int N) {\n\t\t\tInteger [] res = new Integer [N];\n\t\t\tfor (int i : rep(N))\n\t\t\t\tres[i] = sc.nextInt();\n\t\t\treturn res;\n\t\t}\t\t\n\t\t\n\t\tpublic Long [] nextLong (int N) {\n\t\t\tLong [] res = new Long [N];\n\t\t\tfor (int i : rep(N))\n\t\t\t\tres[i] = sc.nextLong();\n\t\t\treturn res;\n\t\t}\t\t\n\t\t\n\t\tpublic Double [] nextDouble (int N) {\n\t\t\tDouble [] res = new Double [N];\n\t\t\tfor (int i : rep(N))\n\t\t\t\tres[i] = sc.nextDouble();\n\t\t\treturn res;\n\t\t}\t\t\n\t\t\n\t\tpublic String [][] nextStrings (int N) {\n\t\t\tString [][] res = new String [N][];\n\t\t\tfor (int i : rep(N))\n\t\t\t\tres[i] = sc.nextStrings();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic Integer [][] nextInts (int N) {\n\t\t\tInteger [][] res = new Integer [N][];\n\t\t\tfor (int i : rep(N))\n\t\t\t\tres[i] = sc.nextInts();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic Long [][] nextLongs (int N) {\n\t\t\tLong [][] res = new Long [N][];\n\t\t\tfor (int i : rep(N))\n\t\t\t\tres[i] = sc.nextLongs();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic Double [][] nextDoubles (int N) {\n\t\t\tDouble [][] res = new Double [N][];\n\t\t\tfor (int i : rep(N))\n\t\t\t\tres[i] = sc.nextDoubles();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\t//////////////////////////////////////////////\n\t\t\n\t\tprivate boolean eol() {\n\t\t\treturn index == line.length;\n\t\t}\n\n\t\tprivate String readLine() {\n\t\t\ttry {\n\t\t\t\treturn r.readLine();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new Error (e);\n\t\t\t}\n\t\t}\n\t\tprivate final BufferedReader r;\n\n\t\tMyScanner () {\n\t\t\tthis(new BufferedReader(new InputStreamReader(System.in)));\n\t\t}\n\t\t\n\t\tMyScanner (BufferedReader r) {\n\t\t\ttry {\n\t\t\t\tthis.r = r;\n\t\t\t\twhile (!r.ready())\n\t\t\t\t\tThread.sleep(1);\n\t\t\t\tstart();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new Error(e);\n\t\t\t}\n\t\t}\n\t\t\n\t\tprivate String [] line;\n\t\tprivate int index;\n\n\t\tprivate void newLine() {\n\t\t\tif (line == null || eol()) {\n\t\t\t\tline = readLine().split(\" \");\n\t\t\t\tindex = 0;\n\t\t\t}\n\t\t}\t\t\n\t}\n\t\n\tstatic void print (Object o, Object... a) {\n\t\tprintDelim(\" \", o, a);\n\t}\n\t\n\tstatic void cprint (Object o, Object... a) {\n\t\tprintDelim(\"\", o, a);\n\t}\n\t\n\tstatic void printDelim (String delim, Object o, Object... a) {\n\t\tpw.println(build(delim, o, a));\n\t}\n\n\tstatic void exit (Object o, Object... a) {\n\t\tprint(o, a);\n\t\texit();\n\t}\n\n\tstatic void exit() {\n\t\tpw.close();\n\t\tSystem.out.flush();\n\t\tSystem.err.println(\"------------------\");\n\t\tSystem.err.println(\"Time: \" + ((millis() - t) / 1000.0));\n\t\tSystem.exit(0);\n\t}\n\t\n\tstatic void NO() {\n\t\tthrow new Error(\"NO!\");\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////////////////////\n\t\n\tstatic String build (String delim, Object o, Object... a) {\n\t\tStringBuilder b = new StringBuilder();\n\t\tappend(b, o, delim);\n\t\tfor (Object p : a)\n\t\t\tappend(b, p, delim);\n\t\treturn b.toString().trim();\t\t\n\t}\n\t\n\tstatic void append(StringBuilder b, Object o, String delim) {\n\t\tif (o.getClass().isArray()) {\n\t\t\tint L = Array.getLength(o);\n\t\t\tfor (int i : rep(L))\n\t\t\t\tappend(b, Array.get(o, i), delim);\n\t\t} else if (o instanceof Iterable) {\n\t\t\tfor (Object p : (Iterable)o)\n\t\t\t\tappend(b, p, delim);\n\t\t} else\n\t\t\tb.append(delim).append(o);\t\t\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////////////////////\n\t\n\tstatic void statics() {\n\t\tabs(0);\n\t\tvalueOf(0);\n\t\tasList(new Object [0]);\n\t\treverseOrder();\n\t}\n\t\n\tpublic static void main (String[] args) {\n\t\tnew D();\n\t\texit();\n\t}\n\n\tstatic void start() {\n\t\tt = millis();\n\t}\n\n\tstatic PrintWriter pw = new PrintWriter(System.out, autoflush);\n\t\n\tstatic long t;\n\t\n\tstatic long millis() {\n\t\treturn System.currentTimeMillis();\n\t}\t\n}\n", "lang_cluster": "Java", "tags": ["dp", "bitmasks"], "code_uid": "c63bf281d4e876c6641a10eecec4fbe3", "src_uid": "359f5d1264ce16c5c5293fd59db95628", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/*package whatever //do not write package name here */\n\nimport java.io.*;\nimport java.util.*;\npublic class benn {\n\tpublic static void main (String[] args) {\n\t\tScanner sc=new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\tint m=sc.nextInt();\n\t\tint a[]=new int[n];\n\t\tfor(int i=0;i ar=new ArrayList<>();\n\t\tint s=0;\n\t\tfor(int i=0;i=0;j--)\n\t\t {\n\t\t x+=ar.get(j);\n\t\t if(s-x<=m)\n\t\t {\n\t\t \ty++;\n\t\t break;\n\t\t }\n\t\t else\n\t\t y++;\n\t\t }\n\t\t System.out.print(y+\" \");\n\t\t \n\t\t }\n\t\t ar.add(a[i]);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "tags": ["sortings", "greedy"], "code_uid": "b1af314346fa58c14ded815d206c8c44", "src_uid": "d3c1dc3ed7af2b51b4c49c9b5052c346", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\npublic class P633A {\n InputStream is;\n PrintWriter out;\n String INPUT = \"6 11 6\";\n \n void solve() {\n int a = ni();\n int b = ni();\n int c = ni();\n int tmp = 0;\n while (tmp < c) {\n if ((c - tmp) % b == 0) {\n System.out.println(\"Yes\");\n return;\n }\n tmp += a;\n }\n tmp = 0;\n while (tmp < c) {\n if ((c - tmp) % a == 0) {\n System.out.println(\"Yes\");\n return;\n }\n tmp += b;\n }\n System.out.println(\"No\");\n }\n \n public static void main(String[] args) throws Exception {\n new P633A().run();\n }\n \n void run() throws Exception {\n is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n out = new PrintWriter(System.out);\n \n long s = System.currentTimeMillis();\n solve();\n out.flush();\n tr(System.currentTimeMillis() - s + \"ms\");\n }\n \n private byte[] inbuf = new byte[1024];\n private int lenbuf = 0, ptrbuf = 0;\n \n private int readByte() {\n if (lenbuf == -1)\n throw new InputMismatchException();\n if (ptrbuf >= lenbuf) {\n ptrbuf = 0;\n try {\n lenbuf = is.read(inbuf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (lenbuf <= 0)\n return -1;\n }\n return inbuf[ptrbuf++];\n }\n \n private boolean isSpaceChar(int c) {\n return !(c >= 33 && c <= 126);\n }\n \n private int skip() {\n int b;\n while ((b = readByte()) != -1 && isSpaceChar(b))\n ;\n return b;\n }\n \n private double nd() {\n return Double.parseDouble(ns());\n }\n \n private char nc() {\n return (char) skip();\n }\n \n private String ns() {\n int b = skip();\n StringBuilder sb = new StringBuilder();\n while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')\n sb.appendCodePoint(b);\n b = readByte();\n }\n return sb.toString();\n }\n \n private char[] ns(int n) {\n char[] buf = new char[n];\n int b = skip(), p = 0;\n while (p < n && !(isSpaceChar(b))) {\n buf[p++] = (char) b;\n b = readByte();\n }\n return n == p ? buf : Arrays.copyOf(buf, p);\n }\n \n private char[][] nm(int n, int m) {\n char[][] map = new char[n][];\n for (int i = 0; i < n; i++)\n map[i] = ns(m);\n return map;\n }\n \n private int[] na(int n) {\n int[] a = new int[n];\n for (int i = 0; i < n; i++)\n a[i] = ni();\n return a;\n }\n \n private int ni() {\n int num = 0, b;\n boolean minus = false;\n while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n ;\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n \n while (true) {\n if (b >= '0' && b <= '9') {\n num = num * 10 + (b - '0');\n } else {\n return minus ? -num : num;\n }\n b = readByte();\n }\n }\n \n private long nl() {\n long num = 0;\n int b;\n boolean minus = false;\n while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n ;\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n \n while (true) {\n if (b >= '0' && b <= '9') {\n num = num * 10 + (b - '0');\n } else {\n return minus ? -num : num;\n }\n b = readByte();\n }\n }\n \n private boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n \n private void tr(Object... o) {\n if (!oj)\n System.out.println(Arrays.deepToString(o));\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "math", "number theory"], "code_uid": "0f28a2ea4d7a93265e85683113ee2f52", "src_uid": "e66ecb0021a34042885442b336f3d911", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/**\n * BaZ :D\n */\nimport java.util.*;\nimport java.io.*;\nimport static java.lang.Math.*;\npublic class Main\n{\n static Reader scan;\n static PrintWriter pw;\n static long MOD = 1_000_000_007;\n static long INF = 1_000_000_000_000_000_000L;\n static long inf = 2_000_000_000;\n public static void main(String[] args) {\n new Thread(null,null,\"BaZ\",1<<25)\n {\n public void run()\n {\n try\n {\n solve();\n }\n catch(Exception e)\n {\n e.printStackTrace();\n System.exit(1);\n }\n }\n }.start();\n }\n static void solve() throws IOException\n {\n scan = new Reader();\n pw = new PrintWriter(System.out,true);\n StringBuilder sb = new StringBuilder();\n long nCr[][] = new long[101][101];\n for(int i=0;i<=100;++i) {\n nCr[i][0] = 1;\n }\n for(int i=1;i<=100;++i) {\n for(int j=1;j<=100;++j) {\n nCr[i][j] = (nCr[i-1][j] + nCr[i-1][j-1])%MOD;\n }\n }\n int freq[] = new int[101];\n int n = ni();\n int arr[] = new int[n];\n int sum = 0;\n for(int i=0;i0) {\n cnt_distinct++;\n }\n for(int j=1;j<=freq[i];++j) {\n if(ways0[j][i*j]==nCr[freq[i]][j]) {\n ans = max(ans, j);\n }\n }\n }\n if(cnt_distinct<=2) {\n pl(n);\n }\n else {\n pl(ans);\n }\n pw.flush();\n pw.close();\n }\n static int ni() throws IOException\n {\n return scan.nextInt();\n }\n static long nl() throws IOException\n {\n return scan.nextLong();\n }\n static double nd() throws IOException\n {\n return scan.nextDouble();\n }\n static void pl()\n {\n pw.println();\n }\n static void p(Object o)\n {\n pw.print(o+\" \");\n }\n static void pl(Object o)\n {\n pw.println(o);\n }\n static void psb(StringBuilder sb)\n {\n pw.print(sb);\n }\n static void pa(String arrayName, Object arr[])\n {\n pl(arrayName+\" : \");\n for(Object o : arr)\n p(o);\n pl();\n }\n static void pa(String arrayName, int arr[])\n {\n pl(arrayName+\" : \");\n for(int o : arr)\n p(o);\n pl();\n }\n static void pa(String arrayName, long arr[])\n {\n pl(arrayName+\" : \");\n for(long o : arr)\n p(o);\n pl();\n }\n static void pa(String arrayName, double arr[])\n {\n pl(arrayName+\" : \");\n for(double o : arr)\n p(o);\n pl();\n }\n static void pa(String arrayName, char arr[])\n {\n pl(arrayName+\" : \");\n for(char o : arr)\n p(o);\n pl();\n }\n static void pa(String listName, List list)\n {\n pl(listName+\" : \");\n for(Object o : list)\n p(o);\n pl();\n }\n static void pa(String arrayName, Object[][] arr) {\n pl(arrayName+\" : \");\n for(int i=0;i= '0' && c <= '9');\n if (neg) return -ret;\n return ret;\n }\n\n public long nextLong() throws IOException {\n long ret = 0;\n byte c = read();\n while (c <= ' ') c = read();\n boolean neg = (c == '-');\n if (neg) c = read();\n do {\n ret = ret * 10 + c - '0';\n } while ((c = read()) >= '0' && c <= '9');\n if (neg) return -ret;\n return ret;\n }\n\n public double nextDouble() throws IOException {\n double ret = 0, div = 1;\n byte c = read();\n while (c <= ' ') c = read();\n boolean neg = (c == '-');\n if (neg) c = read();\n do {\n ret = ret * 10 + c - '0';\n } while ((c = read()) >= '0' && c <= '9');\n if (c == '.') while ((c = read()) >= '0' && c <= '9') ret += (c - '0') / (div *= 10);\n if (neg) return -ret;\n return ret;\n }\n\n private void fillBuffer() throws IOException {\n bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n if (bytesRead == -1) buffer[0] = -1;\n }\n\n private byte read() throws IOException {\n if (bufferPointer == bytesRead) fillBuffer();\n return buffer[bufferPointer++];\n }\n\n public void close() throws IOException {\n if (din == null) return;\n din.close();\n }\n }\n}", "lang_cluster": "Java", "tags": ["math", "dp"], "code_uid": "09a3dd03808d13f20a80581dca0c4f4a", "src_uid": "ccc4b27889598266e8efe73b8aa3666c", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.util.Collections;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Vadim Semenov\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskF solver = new TaskF();\n solver.solve(1, in, out);\n out.close();\n }\n\n static final class TaskF {\n public void solve(int __, InputReader in, PrintWriter out) {\n String s = in.next();\n String t = in.next();\n int[][] result = solve(s.toCharArray(), t.toCharArray());\n out.println(result.length);\n for (int[] pair : result) {\n out.print(pair[0]);\n out.print(' ');\n out.println(pair[1]);\n }\n }\n\n private int[][] solve(char[] s, char[] t) {\n int[][] result = solveInternal(s, t);\n int[][] anotherResult = solveInternal(t, s);\n if (anotherResult.length < result.length) {\n result = anotherResult;\n for (int[] pair : result) {\n ArrayUtils.swap(pair, 0, 1);\n }\n }\n return result;\n }\n\n private int[][] solveInternal(char[] s, char[] t) {\n List sChangings = getChangings(s, 0, s.length, s, 0, 0, 'a');\n List tChangings = getChangings(t, 0, t.length, t, 0, 0, 'b');\n int[][] result = solveGreedy(s, 0, s.length, s, 0, 0, t, 0, t.length, t, 0, 0, 0, Integer.MAX_VALUE);\n assert result != null;\n int balance = (sChangings.size() - tChangings.size()) / 2;\n for (int i = 0; i < 3; ++i) {\n for (int j = 0; j < 3; ++j) {\n int sp = (balance > 0 ? balance : 0) + i;\n int tp = (balance < 0 ? -balance : 0) + j;\n if ((sp != 0 && sp >= sChangings.size()) || (tp != 0 && tp >= tChangings.size())) continue;\n int sSep = sp < sChangings.size() ? sChangings.get(sp) : 0;\n int tSep = tp < tChangings.size() ? tChangings.get(tp) : 0;\n int[][] current = solveGreedy(t, 0, tSep, s, sSep, s.length, s, 0, sSep, t, tSep, t.length, 1, result.length);\n if (current != null) {\n result = current;\n current[0][0] = sSep;\n current[0][1] = tSep;\n }\n }\n }\n return result;\n }\n\n private int[][] solveGreedy(char[] s1, int s1from, int s1to,\n char[] s2, int s2from, int s2to,\n char[] t1, int t1from, int t1to,\n char[] t2, int t2from, int t2to,\n int offset, int limit) {\n List ss = getChangings(s1, s1from, s1to, s2, s2from, s2to, 'a');\n List tt = getChangings(t1, t1from, t1to, t2, t2from, t2to, 'b');\n int length = Math.max(ss.size(), tt.size());\n if (offset + length >= limit) {\n return null;\n }\n int[][] result = new int[offset + length][2];\n for (int i = 0; i < length; ++i) {\n result[offset + i][0] = pop(ss);\n result[offset + i][1] = pop(tt);\n List tmp = ss;\n ss = tt;\n tt = tmp;\n }\n return result;\n }\n\n private List getChangings(char[] s1, int s1from, int s1to, char[] s2, int s2from, int s2to, char target) {\n List changings = new ArrayList<>();\n for (int i = s2to; i-- > s2from; ) {\n char current = s2[i];\n if (current != target) {\n changings.add(s1to - s1from + i - s2from + 1);\n target = current;\n }\n }\n for (int i = s1to; i-- > s1from; ) {\n char current = s1[i];\n if (current != target) {\n changings.add(i - s1from + 1);\n target = current;\n }\n }\n Collections.reverse(changings);\n return changings;\n }\n\n private static int pop(List stack) {\n return stack.isEmpty() ? 0 : stack.remove(stack.size() - 1);\n }\n\n }\n\n static class InputReader {\n private final BufferedReader reader;\n private StringTokenizer tokenizer;\n\n public InputReader(InputStream in) {\n reader = new BufferedReader(new InputStreamReader(in));\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(readLine());\n }\n return tokenizer.nextToken();\n }\n\n public String readLine() {\n String line;\n try {\n line = reader.readLine();\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n return line;\n }\n\n }\n\n static class ArrayUtils {\n private ArrayUtils() {\n }\n\n public static void swap(int[] array, int i, int j) {\n int tmp = array[i];\n array[i] = array[j];\n array[j] = tmp;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["strings", "constructive algorithms"], "code_uid": "f0d9efcde4f9b0ba173d3eb515827324", "src_uid": "4a50c4147becea13946272230f3dde6d", "difficulty": 2800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "//package ecr104;\r\nimport java.io.*;\r\nimport java.util.ArrayDeque;\r\nimport java.util.Arrays;\r\nimport java.util.InputMismatchException;\r\nimport java.util.Queue;\r\n \r\npublic class G3 {\r\n\tInputStream is;\r\n\tFastWriter out;\r\n\tString INPUT = \"\";\r\n \r\n\tvoid solve()\r\n\t{\r\n\t\tfinal int mod = 998244353;\r\n\t\tint n = ni();\r\n\t\tint[] a = na(26);\r\n\t\tlong all = 26 * 26 * pow(25, n-2, mod) % mod;\r\n \r\n\t\tlong[][][] dp = new long[3][n+1][n+1];\r\n\t\tdp[0][1][0] = 1;\r\n\t\tdp[1][0][1] = 1;\r\n\t\tdp[2][0][0] = 1;\r\n\t\tfor(int i = 0;i < n-1;i++){\r\n\t\t\tlong[][][] ndp = new long[3][n+1][n+1];\r\n\t\t\tif(i == (n+1)/2-1){\r\n\t\t\t\tfor (int j = 0; j <= n; j++) {\r\n\t\t\t\t\tfor (int k = 0; j+k <= n; k++) {\r\n\t\t\t\t\t\tif (j + 1 <= n) {\r\n\t\t\t\t\t\t\tndp[0][j + 1][k] += dp[0][j][k] + dp[1][j][k] + dp[2][j][k] * 24;\r\n\t\t\t\t\t\t\tndp[0][j + 1][k] %= mod;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (k + 1 <= n) {\r\n\t\t\t\t\t\t\tndp[1][j][k + 1] += dp[0][j][k] + dp[1][j][k] + dp[2][j][k] * 24;\r\n\t\t\t\t\t\t\tndp[1][j][k + 1] %= mod;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tndp[2][j][k] += dp[0][j][k] + dp[1][j][k] + dp[2][j][k] * 24;\r\n\t\t\t\t\t\tndp[2][j][k] %= mod;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}else {\r\n\t\t\t\tfor (int j = 0; j <= n; j++) {\r\n\t\t\t\t\tfor (int k = 0; j+k <= n; k++) {\r\n\t\t\t\t\t\tif (j + 1 <= n) {\r\n\t\t\t\t\t\t\tndp[0][j + 1][k] += dp[1][j][k] + dp[2][j][k] * 24;\r\n\t\t\t\t\t\t\tndp[0][j + 1][k] %= mod;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (k + 1 <= n) {\r\n\t\t\t\t\t\t\tndp[1][j][k + 1] += dp[0][j][k] + dp[2][j][k] * 24;\r\n\t\t\t\t\t\t\tndp[1][j][k + 1] %= mod;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tndp[2][j][k] += dp[0][j][k] + dp[1][j][k] + dp[2][j][k] * 23;\r\n\t\t\t\t\t\tndp[2][j][k] %= mod;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n \r\n\t\t\t}\r\n\t\t\tdp = ndp;\r\n\t\t}\r\n \r\n\t\tlong[] sdp = new long[n+1];\r\n\t\tfor(int i = 0;i <= n;i++){\r\n\t\t\tfor(int j = 0;j <= n;j++){\r\n\t\t\t\tsdp[i] += dp[0][i][j] + dp[1][i][j] + dp[2][i][j] * 24;\r\n\t\t\t}\r\n\t\t\tsdp[i] %= mod;\r\n\t\t}\r\n \r\n\t\tfor(int i = 0;i < 26;i++){\r\n\t\t\tfor(int k = a[i]+1;k <= n;k++){\r\n\t\t\t\tall -= sdp[k];\r\n\t\t\t}\r\n\t\t}\r\n \r\n\t\tfor(int i = 0;i < 26;i++){\r\n\t\t\tfor(int j = i+1;j < 26;j++){\r\n\t\t\t\tfor(int k = a[i]+1;k <= n;k++){\r\n\t\t\t\t\tfor(int l = a[j]+1;l+k <= n;l++){\r\n\t\t\t\t\t\tall += (dp[0][k][l] + dp[1][k][l] + dp[2][k][l] * 24);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tall %= mod;\r\n\t\t\t}\r\n\t\t}\r\n\t\tall %= mod;\r\n \r\n\t\tif(all < 0)all += mod;\r\n\t\tout.println(all);\r\n\t}\r\n \r\n\tpublic static long pow(long a, long n, long mod) {\r\n\t\t//\t\ta %= mod;\r\n\t\tlong ret = 1;\r\n\t\tint x = 63 - Long.numberOfLeadingZeros(n);\r\n\t\tfor (; x >= 0; x--) {\r\n\t\t\tret = ret * ret % mod;\r\n\t\t\tif (n << 63 - x < 0) ret = ret * a % mod;\r\n\t\t}\r\n\t\treturn ret;\r\n\t}\r\n \r\n \r\n\tpublic static long invl(long a, long mod) {\r\n\t\tlong b = mod;\r\n\t\tlong p = 1, q = 0;\r\n\t\twhile (b > 0) {\r\n\t\t\tlong c = a / b;\r\n\t\t\tlong d;\r\n\t\t\td = a;\r\n\t\t\ta = b;\r\n\t\t\tb = d % b;\r\n\t\t\td = p;\r\n\t\t\tp = q;\r\n\t\t\tq = d - c * q;\r\n\t\t}\r\n\t\treturn p < 0 ? p + mod : p;\r\n\t}\r\n \r\n \r\n\tpublic static long C(int n, int r, int mod, int[][] fif) {\r\n\t\tif (n < 0 || r < 0 || r > n) return 0;\r\n\t\treturn (long) fif[0][n] * fif[1][r] % mod * fif[1][n - r] % mod;\r\n\t}\r\n \r\n \r\n\tpublic static int[][] enumFIF(int n, int mod) {\r\n\t\tint[] f = new int[n + 1];\r\n\t\tint[] invf = new int[n + 1];\r\n\t\tf[0] = 1;\r\n\t\tfor (int i = 1; i <= n; i++) {\r\n\t\t\tf[i] = (int) ((long) f[i - 1] * i % mod);\r\n\t\t}\r\n\t\tlong a = f[n];\r\n\t\tlong b = mod;\r\n\t\tlong p = 1, q = 0;\r\n\t\twhile (b > 0) {\r\n\t\t\tlong c = a / b;\r\n\t\t\tlong d;\r\n\t\t\td = a;\r\n\t\t\ta = b;\r\n\t\t\tb = d % b;\r\n\t\t\td = p;\r\n\t\t\tp = q;\r\n\t\t\tq = d - c * q;\r\n\t\t}\r\n\t\tinvf[n] = (int) (p < 0 ? p + mod : p);\r\n\t\tfor (int i = n - 1; i >= 0; i--) {\r\n\t\t\tinvf[i] = (int) ((long) invf[i + 1] * (i + 1) % mod);\r\n\t\t}\r\n\t\treturn new int[][]{f, invf};\r\n\t}\r\n \r\n \r\n\tvoid run() throws Exception\r\n\t{\r\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\r\n\t\tout = new FastWriter(System.out);\r\n\t\t\r\n\t\tlong s = System.currentTimeMillis();\r\n\t\tsolve();\r\n\t\tout.flush();\r\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) throws Exception { new G3().run(); }\r\n\t\r\n\tprivate byte[] inbuf = new byte[1024];\r\n\tpublic int lenbuf = 0, ptrbuf = 0;\r\n\t\r\n\tprivate int readByte()\r\n\t{\r\n\t\tif(lenbuf == -1)throw new InputMismatchException();\r\n\t\tif(ptrbuf >= lenbuf){\r\n\t\t\tptrbuf = 0;\r\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\r\n\t\t\tif(lenbuf <= 0)return -1;\r\n\t\t}\r\n\t\treturn inbuf[ptrbuf++];\r\n\t}\r\n\t\r\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\r\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\r\n\t\r\n\tprivate double nd() { return Double.parseDouble(ns()); }\r\n\tprivate char nc() { return (char)skip(); }\r\n\t\r\n\tprivate String ns()\r\n\t{\r\n\t\tint b = skip();\r\n\t\tStringBuilder sb = new StringBuilder();\r\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\r\n\t\t\tsb.appendCodePoint(b);\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t\treturn sb.toString();\r\n\t}\r\n\t\r\n\tprivate char[] ns(int n)\r\n\t{\r\n\t\tchar[] buf = new char[n];\r\n\t\tint b = skip(), p = 0;\r\n\t\twhile(p < n && !(isSpaceChar(b))){\r\n\t\t\tbuf[p++] = (char)b;\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\r\n\t}\r\n \r\n\tprivate int[] na(int n)\r\n\t{\r\n\t\tint[] a = new int[n];\r\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\r\n\t\treturn a;\r\n\t}\r\n \r\n\tprivate long[] nal(int n)\r\n\t{\r\n\t\tlong[] a = new long[n];\r\n\t\tfor(int i = 0;i < n;i++)a[i] = nl();\r\n\t\treturn a;\r\n\t}\r\n \r\n\tprivate char[][] nm(int n, int m) {\r\n\t\tchar[][] map = new char[n][];\r\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\r\n\t\treturn map;\r\n\t}\r\n \r\n\tprivate int[][] nmi(int n, int m) {\r\n\t\tint[][] map = new int[n][];\r\n\t\tfor(int i = 0;i < n;i++)map[i] = na(m);\r\n\t\treturn map;\r\n\t}\r\n \r\n\tprivate int ni() { return (int)nl(); }\r\n \r\n\tprivate long nl()\r\n\t{\r\n\t\tlong num = 0;\r\n\t\tint b;\r\n\t\tboolean minus = false;\r\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\r\n\t\tif(b == '-'){\r\n\t\t\tminus = true;\r\n\t\t\tb = readByte();\r\n\t\t}\r\n \r\n\t\twhile(true){\r\n\t\t\tif(b >= '0' && b <= '9'){\r\n\t\t\t\tnum = num * 10 + (b - '0');\r\n\t\t\t}else{\r\n\t\t\t\treturn minus ? -num : num;\r\n\t\t\t}\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t}\r\n \r\n\tpublic static class FastWriter\r\n\t{\r\n\t\tprivate static final int BUF_SIZE = 1<<13;\r\n\t\tprivate final byte[] buf = new byte[BUF_SIZE];\r\n\t\tprivate final OutputStream out;\r\n\t\tprivate int ptr = 0;\r\n \r\n\t\tprivate FastWriter(){out = null;}\r\n \r\n\t\tpublic FastWriter(OutputStream os)\r\n\t\t{\r\n\t\t\tthis.out = os;\r\n\t\t}\r\n \r\n\t\tpublic FastWriter(String path)\r\n\t\t{\r\n\t\t\ttry {\r\n\t\t\t\tthis.out = new FileOutputStream(path);\r\n\t\t\t} catch (FileNotFoundException e) {\r\n\t\t\t\tthrow new RuntimeException(\"FastWriter\");\r\n\t\t\t}\r\n\t\t}\r\n \r\n\t\tpublic FastWriter write(byte b)\r\n\t\t{\r\n\t\t\tbuf[ptr++] = b;\r\n\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\treturn this;\r\n\t\t}\r\n \r\n\t\tpublic FastWriter write(char c)\r\n\t\t{\r\n\t\t\treturn write((byte)c);\r\n\t\t}\r\n \r\n\t\tpublic FastWriter write(char[] s)\r\n\t\t{\r\n\t\t\tfor(char c : s){\r\n\t\t\t\tbuf[ptr++] = (byte)c;\r\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n \r\n\t\tpublic FastWriter write(String s)\r\n\t\t{\r\n\t\t\ts.chars().forEach(c -> {\r\n\t\t\t\tbuf[ptr++] = (byte)c;\r\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\t});\r\n\t\t\treturn this;\r\n\t\t}\r\n \r\n\t\tprivate static int countDigits(int l) {\r\n\t\t\tif (l >= 1000000000) return 10;\r\n\t\t\tif (l >= 100000000) return 9;\r\n\t\t\tif (l >= 10000000) return 8;\r\n\t\t\tif (l >= 1000000) return 7;\r\n\t\t\tif (l >= 100000) return 6;\r\n\t\t\tif (l >= 10000) return 5;\r\n\t\t\tif (l >= 1000) return 4;\r\n\t\t\tif (l >= 100) return 3;\r\n\t\t\tif (l >= 10) return 2;\r\n\t\t\treturn 1;\r\n\t\t}\r\n \r\n\t\tpublic FastWriter write(int x)\r\n\t\t{\r\n\t\t\tif(x == Integer.MIN_VALUE){\r\n\t\t\t\treturn write((long)x);\r\n\t\t\t}\r\n\t\t\tif(ptr + 12 >= BUF_SIZE)innerflush();\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite((byte)'-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tint d = countDigits(x);\r\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\r\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\r\n\t\t\t\tx /= 10;\r\n\t\t\t}\r\n\t\t\tptr += d;\r\n\t\t\treturn this;\r\n\t\t}\r\n \r\n\t\tprivate static int countDigits(long l) {\r\n\t\t\tif (l >= 1000000000000000000L) return 19;\r\n\t\t\tif (l >= 100000000000000000L) return 18;\r\n\t\t\tif (l >= 10000000000000000L) return 17;\r\n\t\t\tif (l >= 1000000000000000L) return 16;\r\n\t\t\tif (l >= 100000000000000L) return 15;\r\n\t\t\tif (l >= 10000000000000L) return 14;\r\n\t\t\tif (l >= 1000000000000L) return 13;\r\n\t\t\tif (l >= 100000000000L) return 12;\r\n\t\t\tif (l >= 10000000000L) return 11;\r\n\t\t\tif (l >= 1000000000L) return 10;\r\n\t\t\tif (l >= 100000000L) return 9;\r\n\t\t\tif (l >= 10000000L) return 8;\r\n\t\t\tif (l >= 1000000L) return 7;\r\n\t\t\tif (l >= 100000L) return 6;\r\n\t\t\tif (l >= 10000L) return 5;\r\n\t\t\tif (l >= 1000L) return 4;\r\n\t\t\tif (l >= 100L) return 3;\r\n\t\t\tif (l >= 10L) return 2;\r\n\t\t\treturn 1;\r\n\t\t}\r\n \r\n\t\tpublic FastWriter write(long x)\r\n\t\t{\r\n\t\t\tif(x == Long.MIN_VALUE){\r\n\t\t\t\treturn write(\"\" + x);\r\n\t\t\t}\r\n\t\t\tif(ptr + 21 >= BUF_SIZE)innerflush();\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite((byte)'-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tint d = countDigits(x);\r\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\r\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\r\n\t\t\t\tx /= 10;\r\n\t\t\t}\r\n\t\t\tptr += d;\r\n\t\t\treturn this;\r\n\t\t}\r\n \r\n\t\tpublic FastWriter write(double x, int precision)\r\n\t\t{\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite('-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tx += Math.pow(10, -precision)/2;\r\n\t\t\t//\t\tif(x < 0){ x = 0; }\r\n\t\t\twrite((long)x).write(\".\");\r\n\t\t\tx -= (long)x;\r\n\t\t\tfor(int i = 0;i < precision;i++){\r\n\t\t\t\tx *= 10;\r\n\t\t\t\twrite((char)('0'+(int)x));\r\n\t\t\t\tx -= (int)x;\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n \r\n\t\tpublic FastWriter writeln(char c){\r\n\t\t\treturn write(c).writeln();\r\n\t\t}\r\n \r\n\t\tpublic FastWriter writeln(int x){\r\n\t\t\treturn write(x).writeln();\r\n\t\t}\r\n \r\n\t\tpublic FastWriter writeln(long x){\r\n\t\t\treturn write(x).writeln();\r\n\t\t}\r\n \r\n\t\tpublic FastWriter writeln(double x, int precision){\r\n\t\t\treturn write(x, precision).writeln();\r\n\t\t}\r\n \r\n\t\tpublic FastWriter write(int... xs)\r\n\t\t{\r\n\t\t\tboolean first = true;\r\n\t\t\tfor(int x : xs) {\r\n\t\t\t\tif (!first) write(' ');\r\n\t\t\t\tfirst = false;\r\n\t\t\t\twrite(x);\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n \r\n\t\tpublic FastWriter write(long... xs)\r\n\t\t{\r\n\t\t\tboolean first = true;\r\n\t\t\tfor(long x : xs) {\r\n\t\t\t\tif (!first) write(' ');\r\n\t\t\t\tfirst = false;\r\n\t\t\t\twrite(x);\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n \r\n\t\tpublic FastWriter writeln()\r\n\t\t{\r\n\t\t\treturn write((byte)'\\n');\r\n\t\t}\r\n \r\n\t\tpublic FastWriter writeln(int... xs)\r\n\t\t{\r\n\t\t\treturn write(xs).writeln();\r\n\t\t}\r\n \r\n\t\tpublic FastWriter writeln(long... xs)\r\n\t\t{\r\n\t\t\treturn write(xs).writeln();\r\n\t\t}\r\n \r\n\t\tpublic FastWriter writeln(char[] line)\r\n\t\t{\r\n\t\t\treturn write(line).writeln();\r\n\t\t}\r\n \r\n\t\tpublic FastWriter writeln(char[]... map)\r\n\t\t{\r\n\t\t\tfor(char[] line : map)write(line).writeln();\r\n\t\t\treturn this;\r\n\t\t}\r\n \r\n\t\tpublic FastWriter writeln(String s)\r\n\t\t{\r\n\t\t\treturn write(s).writeln();\r\n\t\t}\r\n \r\n\t\tprivate void innerflush()\r\n\t\t{\r\n\t\t\ttry {\r\n\t\t\t\tout.write(buf, 0, ptr);\r\n\t\t\t\tptr = 0;\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\tthrow new RuntimeException(\"innerflush\");\r\n\t\t\t}\r\n\t\t}\r\n \r\n\t\tpublic void flush()\r\n\t\t{\r\n\t\t\tinnerflush();\r\n\t\t\ttry {\r\n\t\t\t\tout.flush();\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\tthrow new RuntimeException(\"flush\");\r\n\t\t\t}\r\n\t\t}\r\n \r\n\t\tpublic FastWriter print(byte b) { return write(b); }\r\n\t\tpublic FastWriter print(char c) { return write(c); }\r\n\t\tpublic FastWriter print(char[] s) { return write(s); }\r\n\t\tpublic FastWriter print(String s) { return write(s); }\r\n\t\tpublic FastWriter print(int x) { return write(x); }\r\n\t\tpublic FastWriter print(long x) { return write(x); }\r\n\t\tpublic FastWriter print(double x, int precision) { return write(x, precision); }\r\n\t\tpublic FastWriter println(char c){ return writeln(c); }\r\n\t\tpublic FastWriter println(int x){ return writeln(x); }\r\n\t\tpublic FastWriter println(long x){ return writeln(x); }\r\n\t\tpublic FastWriter println(double x, int precision){ return writeln(x, precision); }\r\n\t\tpublic FastWriter print(int... xs) { return write(xs); }\r\n\t\tpublic FastWriter print(long... xs) { return write(xs); }\r\n\t\tpublic FastWriter println(int... xs) { return writeln(xs); }\r\n\t\tpublic FastWriter println(long... xs) { return writeln(xs); }\r\n\t\tpublic FastWriter println(char[] line) { return writeln(line); }\r\n\t\tpublic FastWriter println(char[]... map) { return writeln(map); }\r\n\t\tpublic FastWriter println(String s) { return writeln(s); }\r\n\t\tpublic FastWriter println() { return writeln(); }\r\n\t}\r\n \r\n\tpublic void trnz(int... o)\r\n\t{\r\n\t\tfor(int i = 0;i < o.length;i++)if(o[i] != 0)System.out.print(i+\":\"+o[i]+\" \");\r\n\t\tSystem.out.println();\r\n\t}\r\n \r\n\t// print ids which are 1\r\n\tpublic void trt(long... o)\r\n\t{\r\n\t\tQueue stands = new ArrayDeque<>();\r\n\t\tfor(int i = 0;i < o.length;i++){\r\n\t\t\tfor(long x = o[i];x != 0;x &= x-1)stands.add(i<<6|Long.numberOfTrailingZeros(x));\r\n\t\t}\r\n\t\tSystem.out.println(stands);\r\n\t}\r\n \r\n\tpublic void tf(boolean... r)\r\n\t{\r\n\t\tfor(boolean x : r)System.out.print(x?'#':'.');\r\n\t\tSystem.out.println();\r\n\t}\r\n \r\n\tpublic void tf(boolean[]... b)\r\n\t{\r\n\t\tfor(boolean[] r : b) {\r\n\t\t\tfor(boolean x : r)System.out.print(x?'#':'.');\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t\tSystem.out.println();\r\n\t}\r\n \r\n\tpublic void tf(long[]... b)\r\n\t{\r\n\t\tif(INPUT.length() != 0) {\r\n\t\t\tfor (long[] r : b) {\r\n\t\t\t\tfor (long x : r) {\r\n\t\t\t\t\tfor (int i = 0; i < 64; i++) {\r\n\t\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tSystem.out.println();\r\n\t\t\t}\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t}\r\n \r\n\tpublic void tf(long... b)\r\n\t{\r\n\t\tif(INPUT.length() != 0) {\r\n\t\t\tfor (long x : b) {\r\n\t\t\t\tfor (int i = 0; i < 64; i++) {\r\n\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t}\r\n \r\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\r\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\r\n}\r\n", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics", "fft"], "code_uid": "6c0f8db5dbf8427c8a613eda9d97609a", "src_uid": "1f012349f4b229dc98faadf1ca732355", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class D {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint[] mas = {0,1,0,18,0,1800,0,670320,0,734832000,0,890786230,0,695720788,0,150347555};\n\t\tint n = sc.nextInt();\n\t\tif (n%2 == 0) {\n\t\t\tSystem.out.println(0);\n\t\t}else{\n\t\t\tSystem.out.println(mas[n]);\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "tags": ["dp", "combinatorics", "bitmasks", "meet-in-the-middle", "implementation"], "code_uid": "1073c395f22568a36c88a4bfe78acbfb", "src_uid": "a6a804ce23bc48ec825c17d64ac0bb69", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class Main {\n\tstatic long[] factor;\n\tstatic int mod = 1000000007;\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tInputReader scan = new InputReader();\n\t\tint a = scan.nextInt(), b = scan.nextInt(), k = scan.nextInt();\n\t\tgenerateFactor(k);\n\t\tlong sum = 0;\n\t\tfor (int i = 0; i <= k; i++) {\n\t\t\tif (isGood(a * i + b * (k - i), a, b))\n\t\t\t\tsum += (factor[k] * (BigInteger.valueOf(factor[i] * factor[k - i] % mod)\n\t\t\t\t\t\t.modInverse(BigInteger.valueOf(mod)).longValue()) % mod);\n\t\t\tsum %= mod;\n\t\t}\n\t\tSystem.out.println(sum);\n\t}\n\n\tstatic boolean isGood(int n, int a, int b) {\n\t\twhile (n % 10 == a || n % 10 == b) {\n\t\t\tn /= 10;\n\t\t}\n\t\treturn n == 0;\n\t}\n\n\tstatic void generateFactor(int n) {\n\t\tfactor = new long[n + 10];\n\t\tfactor[0] = 1;\n\t\tfor (int i = 1; i < n + 10; i++) {\n\t\t\tfactor[i] = (factor[i - 1] * i) % mod;\n\t\t}\n\t}\n\n\tstatic class InputReader {\n\n\t\tInputStream is = System.in;\n\t\tbyte[] inbuf = new byte[1 << 23];\n\t\tint lenbuf = 0, ptrbuf = 0;\n\n\t\tpublic InputReader() throws IOException {\n\t\t\tlenbuf = is.read(inbuf);\n\t\t}\n\n\t\tpublic int readByte() {\n\n\t\t\tif (ptrbuf >= lenbuf) {\n\t\t\t\treturn -1;\n\t\t\t}\n\n\t\t\treturn inbuf[ptrbuf++];\n\t\t}\n\n\t\tpublic boolean hasNext() {\n\t\t\tint t = skip();\n\n\t\t\tif (t == -1) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tptrbuf--;\n\t\t\treturn true;\n\t\t}\n\n\t\tpublic StringBuilder printIntArr(int[] ar, int n) {\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tres.append(ar[i] + \" \");\n\t\t\t}\n\t\t\tres.append(\"\\n\");\n\t\t\treturn res;\n\t\t}\n\n\t\tpublic boolean isSpaceChar(int c) {\n\t\t\treturn !(c >= 33 && c <= 126);\n\t\t}\n\n\t\tpublic int skip() {\n\t\t\tint b;\n\t\t\twhile ((b = readByte()) != -1 && isSpaceChar(b))\n\t\t\t\t;\n\t\t\treturn b;\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic char nextChar() {\n\t\t\treturn (char) skip();\n\t\t}\n\n\t\tpublic String next() {\n\t\t\tint b = skip();\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\twhile (!(isSpaceChar(b))) {\n\t\t\t\tsb.appendCodePoint(b);\n\t\t\t\tb = readByte();\n\t\t\t}\n\t\t\treturn sb.toString();\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tint b = skip();\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\twhile (b != '\\n' && b != '\\r') {\n\t\t\t\tsb.appendCodePoint(b);\n\t\t\t\tb = readByte();\n\t\t\t}\n\t\t\treturn sb.toString();\n\t\t}\n\n\t\tpublic char[] ns(int n) {\n\t\t\tchar[] buf = new char[n];\n\t\t\tint b = skip(), p = 0;\n\t\t\twhile (p < n && !(isSpaceChar(b))) {\n\t\t\t\tbuf[p++] = (char) b;\n\t\t\t\tb = readByte();\n\t\t\t}\n\t\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t\t}\n\n\t\tpublic char[][] nm(int n, int m) {\n\t\t\tchar[][] map = new char[n][];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tmap[i] = ns(m);\n\t\t\t}\n\t\t\treturn map;\n\t\t}\n\n\t\tpublic int[][] nmInt(int n, int m) {\n\t\t\tint[][] map = new int[n][m];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\t\tmap[i][j] = nextInt();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn map;\n\t\t}\n\n\t\tpublic long[][] nmLong(int n, int m) {\n\t\t\tlong[][] map = new long[n][m];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\t\tmap[i][j] = nextLong();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn map;\n\t\t}\n\n\t\tpublic int[] na(int n) {\n\t\t\tint[] a = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\ta[i] = nextInt();\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\tint num = 0, b;\n\t\t\tboolean minus = false;\n\t\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t\t;\n\t\t\tif (b == '-') {\n\t\t\t\tminus = true;\n\t\t\t\tb = readByte();\n\t\t\t}\n\n\t\t\twhile (true) {\n\t\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t} else {\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t\tb = readByte();\n\t\t\t}\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\tlong num = 0;\n\t\t\tint b;\n\t\t\tboolean minus = false;\n\t\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t\t;\n\t\t\tif (b == '-') {\n\t\t\t\tminus = true;\n\t\t\t\tb = readByte();\n\t\t\t}\n\n\t\t\twhile (true) {\n\t\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t} else {\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t\tb = readByte();\n\t\t\t}\n\t\t}\n\n\t}\n}", "lang_cluster": "Java", "tags": ["brute force", "combinatorics"], "code_uid": "4b4b98a875ad57233ba30238ad71d867", "src_uid": "d3e3da5b6ba37c8ac5f22b18c140ce81", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class Template implements Runnable {\n\n BufferedReader in;\n PrintWriter out;\n StringTokenizer tok = new StringTokenizer(\"\");\n\n void init() throws FileNotFoundException {\n try {\n in = new BufferedReader(new FileReader(\"input.txt\"));\n out = new PrintWriter(\"output.txt\");\n } catch (Exception e) {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n }\n }\n\n String readString() throws IOException {\n while (!tok.hasMoreTokens()) {\n try {\n tok = new StringTokenizer(in.readLine());\n } catch (Exception e) {\n return null;\n }\n }\n return tok.nextToken();\n }\n\n int readInt() throws IOException {\n return Integer.parseInt(readString());\n }\n\n int[] readIntArray(int size) throws IOException {\n int[] res = new int[size];\n for (int i = 0; i < size; i++) {\n res[i] = readInt();\n }\n return res;\n }\n\n long readLong() throws IOException {\n return Long.parseLong(readString());\n }\n\n double readDouble() throws IOException {\n return Double.parseDouble(readString());\n }\n\n List[] createGraphList(int size) {\n List[] list = new List[size];\n for (int i = 0; i < size; i++) {\n list[i] = new ArrayList<>();\n }\n return list;\n }\n\n public static void main(String[] args) {\n new Template().run();\n // new Thread(null, new Template(), \"\", 1l * 200 * 1024 * 1024).start();\n }\n\n long timeBegin, timeEnd;\n\n void time() {\n timeEnd = System.currentTimeMillis();\n System.err.println(\"Time = \" + (timeEnd - timeBegin));\n }\n\n long memoryTotal, memoryFree;\n\n void memory() {\n memoryFree = Runtime.getRuntime().freeMemory();\n System.err.println(\"Memory = \" + ((memoryTotal - memoryFree) >> 10)\n + \" KB\");\n }\n\n public void run() {\n try {\n timeBegin = System.currentTimeMillis();\n memoryTotal = Runtime.getRuntime().freeMemory();\n init();\n solve();\n out.close();\n if (System.getProperty(\"ONLINE_JUDGE\") == null) {\n time();\n memory();\n }\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(-1);\n }\n }\n\n long[] fact;\n long[] revfact;\n int mod = (int) 1e9 + 7;\n\n long binpow(long x, int p, int mod) {\n if (p == 0) {\n return 1 % mod;\n }\n if (p % 2 == 0) {\n long half = binpow(x, p / 2, mod);\n return half * half % mod;\n } else {\n return x * binpow(x, p - 1, mod) % mod;\n }\n }\n\n long C(int n, int k) {\n if (k > n) return 0;\n long answer = fact[n];\n answer = answer * revfact[n - k] % mod;\n answer = answer * revfact[k] % mod;\n return answer;\n }\n\n long ways(int columns, int count, int minHeight) {\n if (columns == 0) {\n if (count == 0) return 1;\n return 0;\n }\n if (count / minHeight < columns) return 0;\n if (columns == 1) return 1;\n int ost = count - columns * minHeight;\n //return binpow(ost + 1, columns - 1, mod);\n int n = ost;\n int m = columns;\n return C(n + m - 1, m - 1);\n\n // return C(ost + 1, columns - 1);\n\n// return binpow(columns, ost, mod);\n }\n\n void solve() throws IOException {\n int MAX = 2 * 100000 + 100;\n fact = new long[MAX];\n revfact = new long[MAX];\n fact[0] = revfact[0] = 1;\n for (int i = 1; i < MAX; i++) {\n fact[i] = fact[i - 1] * i % mod;\n revfact[i] = binpow(fact[i], mod - 2, mod);\n }\n int f = readInt();\n int w = readInt();\n int h = readInt();\n if (w == 0) {\n out.println(1);\n return;\n }\n\n long correct = 0;\n long all = 0;\n\n for (int wineColumns = 1; wineColumns <= w; wineColumns++) {\n long foodCount = (ways(wineColumns - 1, f, 1) + ways(wineColumns + 1, f, 1) + ways(wineColumns, f, 1) * 2) % mod;\n all += ways(wineColumns, w, 1) * foodCount % mod;\n all %= mod;\n correct += ways(wineColumns, w, h + 1) * foodCount % mod;\n correct %= mod;\n }\n long answer = correct * binpow(all, mod - 2, mod) % mod;\n //long etalon = new NaiveSolver().solve(f, w, h);\n //if (answer != etalon) throw new RuntimeException(\"answer not equal etalon\");\n out.println(answer);\n }\n\n class NaiveSolver {\n\n long solve(int f, int w, int h) {\n brut(f, w, h, true, true, \"\");\n brut(f, w, h, true, false, \"\");\n return correct * binpow(all, mod - 2, mod) % mod;\n }\n\n long correct;\n long all;\n\n void brut(int f, int w, int h, boolean nowAllOk, boolean nowWine, String represent) {\n if (f == 0 && w == 0) {\n all++;\n if (nowAllOk) correct++;\n System.err.println(represent);\n return;\n }\n if (nowWine) {\n if (w == 0) return;\n } else {\n if (h == 0) return;\n }\n if (nowWine) {\n for (int i = 1; i <= w; i++) {\n brut(f, w - i, h, nowAllOk & (i > h), !nowWine, represent + str('w', i));\n }\n } else {\n for (int i = 1; i <= f; i++) {\n brut(f - i, w, h, nowAllOk, !nowWine, represent + str('f', i));\n }\n }\n }\n }\n\n String str(char x, int cnt) {\n String res = \"\";\n while (cnt-- > 0) {\n res += x;\n }\n return res;\n }\n\n\n}", "lang_cluster": "Java", "tags": ["brute force", "math", "combinatorics", "probabilities", "number theory"], "code_uid": "30706181e6c2e0f21be615d6cc023465", "src_uid": "a69f95db3fe677111cf0558271b40f39", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.ArrayList;\nimport java.io.OutputStreamWriter;\nimport java.util.NoSuchElementException;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Iterator;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.util.List;\nimport java.io.Writer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Egor Kulikov (egor@egork.net)\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskC {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int n = in.readInt();\n int[] x = new int[n];\n int[] y = new int[n];\n int[] r = new int[n];\n in.readIntArrays(x, y, r);\n Circle[] circles = new Circle[n];\n for (int i = 0; i < n; i++) {\n circles[i] = new Circle(new Point(x[i], y[i]), r[i]);\n }\n List points = new ArrayList<>();\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < i; j++) {\n Point[] intersect = circles[i].intersect(circles[j]);\n if (intersect != null) {\n points.addAll(Arrays.asList(intersect));\n }\n }\n }\n boolean[] bad = new boolean[points.size()];\n for (int i = 0; i < points.size(); i++) {\n for (int j = 0; j < i; j++) {\n if (points.get(i).equals(points.get(j))) {\n bad[i] = true;\n break;\n }\n }\n }\n int nVertices = ArrayUtils.count(bad, false);\n int nEdges = 0;\n IndependentSetSystem setSystem = new RecursiveIndependentSetSystem(points.size());\n for (int i = 0; i < n; i++) {\n int current = 0;\n IntList onThis = new IntArrayList();\n for (int j = 0; j < points.size(); j++) {\n if (!bad[j] && Math.abs(circles[i].center.distance(points.get(j)) - r[i]) < GeometryUtils.epsilon) {\n current++;\n onThis.add(j);\n }\n }\n for (int j = 1; j < onThis.size(); j++) {\n setSystem.join(onThis.get(j), onThis.get(0));\n }\n nEdges += Math.max(current, 1);\n }\n int nComponents = setSystem.getSetCount() - ArrayUtils.count(bad, true);\n out.printLine(1 + nEdges - nVertices + nComponents);\n }\n\n }\n\n static class Line {\n public final double a;\n public final double b;\n public final double c;\n\n public Line(Point p, double angle) {\n a = Math.sin(angle);\n b = -Math.cos(angle);\n c = -p.x * a - p.y * b;\n }\n\n public Line(double a, double b, double c) {\n double h = GeometryUtils.fastHypot(a, b);\n this.a = a / h;\n this.b = b / h;\n this.c = c / h;\n }\n\n public Point intersect(Line other) {\n if (parallel(other)) {\n return null;\n }\n double determinant = b * other.a - a * other.b;\n double x = (c * other.b - b * other.c) / determinant;\n double y = (a * other.c - c * other.a) / determinant;\n return new Point(x, y);\n }\n\n public boolean parallel(Line other) {\n return Math.abs(a * other.b - b * other.a) < GeometryUtils.epsilon;\n }\n\n public Line perpendicular(Point point) {\n return new Line(-b, a, b * point.x - a * point.y);\n }\n\n public double value(Point point) {\n return a * point.x + b * point.y + c;\n }\n\n public Point[] intersect(Circle circle) {\n double distance = distance(circle.center);\n if (distance > circle.radius + GeometryUtils.epsilon) {\n return new Point[0];\n }\n Point intersection = intersect(perpendicular(circle.center));\n if (Math.abs(distance - circle.radius) < GeometryUtils.epsilon) {\n return new Point[]{intersection};\n }\n double shift = Math.sqrt(circle.radius * circle.radius - distance * distance);\n return new Point[]{new Point(intersection.x + shift * b, intersection.y - shift * a),\n new Point(intersection.x - shift * b, intersection.y + shift * a)};\n }\n\n public double distance(Point center) {\n return Math.abs(value(center));\n }\n\n\n public boolean equals(Object o) {\n if (this == o) {\n return true;\n }\n if (o == null || getClass() != o.getClass()) {\n return false;\n }\n\n Line line = (Line) o;\n\n if (!parallel(line)) {\n return false;\n }\n if (Math.abs(a * line.c - c * line.a) > GeometryUtils.epsilon ||\n Math.abs(b * line.c - c * line.b) > GeometryUtils.epsilon) {\n return false;\n }\n\n return true;\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void printLine(int i) {\n writer.println(i);\n }\n\n }\n\n static class Circle {\n public final Point center;\n public final double radius;\n\n public Circle(Point center, double radius) {\n this.center = center;\n this.radius = radius;\n }\n\n public Point[] intersect(Circle other) {\n double distance = center.distance(other.center);\n if (distance < GeometryUtils.epsilon) {\n return null;\n }\n Line line = new Line(2 * (other.center.x - center.x), 2 * (other.center.y - center.y), other.radius * other\n .radius - radius * radius + center.x * center.x - other.center.x * other.center.x +\n center.y * center.y - other.center.y * other.center.y);\n return line.intersect(this);\n }\n\n }\n\n static class IntArrayList extends IntAbstractStream implements IntList {\n private int size;\n private int[] data;\n\n public IntArrayList() {\n this(3);\n }\n\n public IntArrayList(int capacity) {\n data = new int[capacity];\n }\n\n public IntArrayList(IntCollection c) {\n this(c.size());\n addAll(c);\n }\n\n public IntArrayList(IntStream c) {\n this();\n if (c instanceof IntCollection) {\n ensureCapacity(((IntCollection) c).size());\n }\n addAll(c);\n }\n\n public IntArrayList(IntArrayList c) {\n size = c.size();\n data = c.data.clone();\n }\n\n public IntArrayList(int[] arr) {\n size = arr.length;\n data = arr.clone();\n }\n\n public int size() {\n return size;\n }\n\n public int get(int at) {\n if (at >= size) {\n throw new IndexOutOfBoundsException(\"at = \" + at + \", size = \" + size);\n }\n return data[at];\n }\n\n private void ensureCapacity(int capacity) {\n if (data.length >= capacity) {\n return;\n }\n capacity = Math.max(2 * data.length, capacity);\n data = Arrays.copyOf(data, capacity);\n }\n\n public void addAt(int index, int value) {\n ensureCapacity(size + 1);\n if (index > size || index < 0) {\n throw new IndexOutOfBoundsException(\"at = \" + index + \", size = \" + size);\n }\n if (index != size) {\n System.arraycopy(data, index, data, index + 1, size - index);\n }\n data[index] = value;\n size++;\n }\n\n public void removeAt(int index) {\n if (index >= size || index < 0) {\n throw new IndexOutOfBoundsException(\"at = \" + index + \", size = \" + size);\n }\n if (index != size - 1) {\n System.arraycopy(data, index + 1, data, index, size - index - 1);\n }\n size--;\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public void readIntArrays(int[]... arrays) {\n for (int i = 0; i < arrays[0].length; i++) {\n for (int j = 0; j < arrays.length; j++) {\n arrays[j][i] = readInt();\n }\n }\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n\n static interface IntList extends IntReversableCollection {\n public abstract int get(int index);\n\n public abstract void addAt(int index, int value);\n\n public abstract void removeAt(int index);\n\n default public IntIterator intIterator() {\n return new IntIterator() {\n private int at;\n private boolean removed;\n\n public int value() {\n if (removed) {\n throw new IllegalStateException();\n }\n return get(at);\n }\n\n public boolean advance() {\n at++;\n removed = false;\n return isValid();\n }\n\n public boolean isValid() {\n return !removed && at < size();\n }\n\n public void remove() {\n removeAt(at);\n at--;\n removed = true;\n }\n };\n }\n\n\n default public void add(int value) {\n addAt(size(), value);\n }\n\n }\n\n static class GeometryUtils {\n public static double epsilon = 1e-8;\n\n public static double fastHypot(double x, double y) {\n return Math.sqrt(x * x + y * y);\n }\n\n }\n\n static class ArrayUtils {\n public static int count(boolean[] array, boolean value) {\n int result = 0;\n for (boolean i : array) {\n if (i == value) {\n result++;\n }\n }\n return result;\n }\n\n }\n\n static interface IntIterator {\n public int value() throws NoSuchElementException;\n\n public boolean advance();\n\n public boolean isValid();\n\n }\n\n static class RecursiveIndependentSetSystem implements IndependentSetSystem {\n private final int[] color;\n private final int[] rank;\n private int setCount;\n private IndependentSetSystem.Listener listener;\n\n public RecursiveIndependentSetSystem(int size) {\n color = new int[size];\n rank = new int[size];\n for (int i = 0; i < size; i++) {\n color[i] = i;\n }\n setCount = size;\n }\n\n public RecursiveIndependentSetSystem(RecursiveIndependentSetSystem other) {\n color = other.color.clone();\n rank = other.rank.clone();\n setCount = other.setCount;\n }\n\n public boolean join(int first, int second) {\n first = get(first);\n second = get(second);\n if (first == second) {\n return false;\n }\n if (rank[first] < rank[second]) {\n int temp = first;\n first = second;\n second = temp;\n } else if (rank[first] == rank[second]) {\n rank[first]++;\n }\n setCount--;\n color[second] = first;\n if (listener != null) {\n listener.joined(second, first);\n }\n return true;\n }\n\n public int get(int index) {\n int start = index;\n while (color[index] != index) {\n index = color[index];\n }\n while (start != index) {\n int next = color[start];\n color[start] = index;\n start = next;\n }\n return index;\n }\n\n public int getSetCount() {\n return setCount;\n }\n\n }\n\n static interface IntStream extends Iterable, Comparable {\n public IntIterator intIterator();\n\n default public Iterator iterator() {\n return new Iterator() {\n private IntIterator it = intIterator();\n\n public boolean hasNext() {\n return it.isValid();\n }\n\n public Integer next() {\n int result = it.value();\n it.advance();\n return result;\n }\n };\n }\n\n default public int compareTo(IntStream c) {\n IntIterator it = intIterator();\n IntIterator jt = c.intIterator();\n while (it.isValid() && jt.isValid()) {\n int i = it.value();\n int j = jt.value();\n if (i < j) {\n return -1;\n } else if (i > j) {\n return 1;\n }\n it.advance();\n jt.advance();\n }\n if (it.isValid()) {\n return 1;\n }\n if (jt.isValid()) {\n return -1;\n }\n return 0;\n }\n\n }\n\n static abstract class IntAbstractStream implements IntStream {\n\n public String toString() {\n StringBuilder builder = new StringBuilder();\n boolean first = true;\n for (IntIterator it = intIterator(); it.isValid(); it.advance()) {\n if (first) {\n first = false;\n } else {\n builder.append(' ');\n }\n builder.append(it.value());\n }\n return builder.toString();\n }\n\n\n public boolean equals(Object o) {\n if (!(o instanceof IntStream)) {\n return false;\n }\n IntStream c = (IntStream) o;\n IntIterator it = intIterator();\n IntIterator jt = c.intIterator();\n while (it.isValid() && jt.isValid()) {\n if (it.value() != jt.value()) {\n return false;\n }\n it.advance();\n jt.advance();\n }\n return !it.isValid() && !jt.isValid();\n }\n\n\n public int hashCode() {\n int result = 0;\n for (IntIterator it = intIterator(); it.isValid(); it.advance()) {\n result *= 31;\n result += it.value();\n }\n return result;\n }\n\n }\n\n static interface IndependentSetSystem {\n public boolean join(int first, int second);\n\n public int getSetCount();\n\n public static interface Listener {\n public void joined(int joinedRoot, int root);\n\n }\n\n }\n\n static interface IntCollection extends IntStream {\n public int size();\n\n default public void add(int value) {\n throw new UnsupportedOperationException();\n }\n\n default public IntCollection addAll(IntStream values) {\n for (IntIterator it = values.intIterator(); it.isValid(); it.advance()) {\n add(it.value());\n }\n return this;\n }\n\n }\n\n static interface IntReversableCollection extends IntCollection {\n }\n\n static class Point {\n public final double x;\n public final double y;\n\n\n public String toString() {\n return \"(\" + x + \", \" + y + \")\";\n }\n\n public Point(double x, double y) {\n this.x = x;\n this.y = y;\n }\n\n\n public boolean equals(Object o) {\n if (this == o) {\n return true;\n }\n if (o == null || getClass() != o.getClass()) {\n return false;\n }\n\n Point point = (Point) o;\n\n return Math.abs(x - point.x) <= GeometryUtils.epsilon && Math.abs(y - point.y) <= GeometryUtils.epsilon;\n }\n\n\n public int hashCode() {\n int result;\n long temp;\n temp = x != +0.0d ? Double.doubleToLongBits(x) : 0L;\n result = (int) (temp ^ (temp >>> 32));\n temp = y != +0.0d ? Double.doubleToLongBits(y) : 0L;\n result = 31 * result + (int) (temp ^ (temp >>> 32));\n return result;\n }\n\n public double distance(Point other) {\n return GeometryUtils.fastHypot(x - other.x, y - other.y);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["geometry", "graphs"], "code_uid": "1b7fff36db7cf4d42125f6224e2cbb6c", "src_uid": "bda5879e94a82c6fd499796f258c4691", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": " \nimport java.util.*;\npublic class C_Bear_And_Company_3 {\n \t\n static int cv, ck , cs;\n static int[][] freq;\n static ArrayList[] pos;\n static int[][][][] dp;\n\n public static void main(String[] agrs) {\n \tScanner in = new Scanner(System.in);\n int n = in.nextInt();\n char[] c = in.next().toCharArray();\n cv = 0;\n ck = 0;\n cs = 0;\n freq = new int[n + 1][3];\n pos = new ArrayList[3];\n for (int i = 0; i < 3; i++) pos[i] = new ArrayList<>();\n int idx = 0;\n for (char x : c) {\n System.arraycopy(freq[idx], 0, freq[idx + 1], 0, 3);\n idx++;\n if (x == 'V') {\n freq[idx][0]++;\n cv++;\n pos[0].add(idx);\n } else if (x == 'K') {\n freq[idx][1]++;\n ck++;\n pos[1].add(idx);\n } else {\n freq[idx][2]++;\n cs++;\n pos[2].add(idx);\n }\n }\n dp = new int[cv + 1][ck + 1][cs + 1][3];\n for (int[][][] x : dp) for (int[][] y : x) for (int[] z : y) Arrays.fill(z, -1);\n System.out.println(dfs(0, 0, 0, 2));\n }\n\n static int dfs(int tv, int tk, int ts, int last) {\n if (tv == cv && tk == ck && ts == cs) {\n return 0;\n }\n if (dp[tv][tk][ts][last] != -1) return dp[tv][tk][ts][last];\n int ret = 1 << 29;\n if (tv < cv) {\n int p = pos[0].get(tv);\n int move = Math.max(freq[p][0] - tv, 0) + Math.max(freq[p][1] - tk, 0) + Math.max(freq[p][2] - ts, 0) - 1;\n ret = Math.min(ret, dfs(tv + 1, tk, ts, 0) + move);\n }\n if (tk < ck && last != 0) {\n int p = pos[1].get(tk);\n int move = Math.max(freq[p][0] - tv, 0) + Math.max(freq[p][1] - tk, 0) + Math.max(freq[p][2] - ts, 0) - 1;\n ret = Math.min(ret, dfs(tv, tk + 1, ts, 1) + move);\n }\n if (ts < cs) {\n int p = pos[2].get(ts);\n int move = Math.max(freq[p][0] - tv, 0) + Math.max(freq[p][1] - tk, 0) + Math.max(freq[p][2] - ts, 0) - 1;\n ret = Math.min(ret, dfs(tv, tk, ts + 1, 2) + move);\n }\n return dp[tv][tk][ts][last] = ret;\n }\n\n}\n", "lang_cluster": "Java", "tags": ["dp"], "code_uid": "da36122d4357f025b60792faf0f976a5", "src_uid": "08444f9ab1718270b5ade46852b155d7", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n Scanner cv=new Scanner(System.in);\n long a=cv.nextInt();\n long b=cv.nextInt();\n long c=cv.nextInt();\n long k=0;\n if(a>b){\n k+=(b+c)*2;\n k++;\n }else if(b>a){\n k+=(a+c)*2;\n k++;\n }else {\n k+=(a+c)*2;\n }\n System.out.println(k);\n }\n}\n", "lang_cluster": "Java", "tags": ["greedy"], "code_uid": "0c10ae291af7f84a017713e4a321b66c", "src_uid": "609f131325c13213aedcf8d55fc3ed77", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "\nimport java.util.Scanner;\n\n/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n/**\n *\n * @author jtim\n */\npublic class taskC {\n\n public static void main(String[] args) {\n new taskC().main();\n }\n Scanner s = new Scanner(System.in);\n long min = Long.MAX_VALUE, max = Long.MIN_VALUE, n = 0;\n\n void check(long a, long b, long c) {\n long m = (a+1)*(b+2)*(c+2);\n long now = m - n;\n min = Math.min(min, now);\n max = Math.max(max, now);\n }\n\n void main() {\n n = s.nextInt();\n\n\n for (long x = 1; x * x <= n; x++) {\n if (n % x == 0) {\n\n long rem = n / x;\n\n for (long y = 1; y * y <= rem; y++) {\n if (rem % y == 0) {\n\n long z = rem / y;\n\n check(x, y, z);\n check(x, z, y);\n check(y, x, z);\n check(y, z, x);\n check(z, x, y);\n check(z, y, x);\n\n }\n }\n\n }\n }\n\n System.out.println(min + \" \" + max);\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "8b9349d8a34be1c9369e47c72d3d6690", "src_uid": "2468eead8acc5b8f5ddc51bfa2bd4fb7", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class Main\n{\n\tpublic static void main(String[] args) {\n\t Scanner sc=new Scanner(System.in);\n\t int n=sc.nextInt();\n\t boolean dp[]=new boolean[101];\n\t dp[3]=dp[6]=dp[7]=true;\n\t for(int i=8;i<101;i++){\n\t dp[i]=dp[i-3]|dp[i-7];\n\t }\n\t while(n-->0){\n\t int x=sc.nextInt();\n\t if(dp[x])System.out.println(\"YES\");\n\t else System.out.println(\"NO\");\n\t }\n\t}\n}\n", "lang_cluster": "Java", "tags": ["greedy", "implementation"], "code_uid": "933aefa09bc3d0be251f25dc9b401a42", "src_uid": "cfd1182be98fb5f0c426f8b68e48d452", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author sheep\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskC solver = new TaskC();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskC {\n private static final long MAX_VALUE = 10000000000000L;\n private int n, m;\n private int[] a, b;\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n n = in.nextInt();\n m = in.nextInt();\n a = new int[n];\n b = new int[n];\n for (int i = 0; i < n; ++i) {\n a[i] = in.nextInt();\n }\n for (int i = 0; i < n; ++i) {\n\n b[i] = in.nextInt();\n }\n\n long[][] dp = new long[81][81];\n ArrayUtils.fill(dp, MAX_VALUE);\n for (int i = 0; i <= 80; ++i) {\n dp[i][i] = 0;\n }\n for (int i = 0; i < n; ++i) {\n long[][] next = new long[81][81];\n ArrayUtils.fill(next, MAX_VALUE);\n for (int j = 0; j <= 80; ++j) {\n for (int k = 0; k <= 80; ++k) {\n if (k > 0) {\n next[j][k - 1] = Math.min(next[j][k - 1], dp[j][k] + b[i]);\n }\n if (k + 1 <= 80) {\n next[j][k + 1] = Math.min(next[j][k + 1], dp[j][k] + a[i]);\n }\n }\n }\n dp = next;\n }\n\n long[][] result = new long[81][81];\n ArrayUtils.fill(result, MAX_VALUE);\n for (int i = 0; i <= 80; ++i) {\n result[i][i] = 0;\n }\n\n for (; m > 0; m >>= 1) {\n if (m % 2 == 1) result = mul(result, dp);\n dp = mul(dp, dp);\n }\n\n out.println(result[0][0]);\n }\n\n private long[][] mul(long[][] a, long[][] b) {\n long[][] c = new long[81][81];\n ArrayUtils.fill(c, MAX_VALUE);\n for (int k = 0; k <= 80; ++k) {\n for (int i = 0; i <= 80; ++i) {\n for (int j = 0; j <= 80; ++j) {\n c[i][j] = Math.min(c[i][j], a[i][k] + b[k][j]);\n }\n }\n }\n return c;\n }\n}\n\nclass InputReader {\n BufferedReader reader;\n StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (Exception e) {\n throw new UnknownError();\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n\nclass ArrayUtils {\n\n\n public static void fill(long[][] array, long value) {\n for (int i = 0; i < array.length; ++i) {\n Arrays.fill(array[i], value);\n }\n }\n\n }\n", "lang_cluster": "Java", "tags": ["matrices", "dp"], "code_uid": "572a87b521af5f337c1726b3e2e60536", "src_uid": "f40900973f4ebeb6fdafd75ebe4e9601", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class F946{\n\n long[] fibpow;\n char[] chs;\n long mod = 1000000007L;\n long modpow = mod-1L;\n long[][][] memo;\n\n long pow(long m, long n){\n long res = 1;\n while(n > 0){\n if(n % 2 == 1)res = (res*m)%mod;\n m = (m*m)%mod;\n n = n/2;\n }\n return res;\n }\n\n\n private void solve() throws Exception {\n int n = nextInt();\n int x = nextInt();\n chs = nextToken().toCharArray();\n memo = new long[n][n][x+1];\n for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) Arrays.fill(memo[i][j], -1);\n fibpow = new long[x+1];\n if(x > 0) fibpow[1] = 1L;\n for(int i = 2; i <= x; i++) fibpow[i] = (fibpow[i-1]+ fibpow[i-2])%modpow;\n for(int i = 0; i <= x; i++) fibpow[i] = pow(2, fibpow[i]);\n out.println(doit(0,n-1,x));\n }\n\n long doit(int i, int j, int x) {\n if (x < 2 && i == j && chs[i]-'0' == x) return 1L;\n else if (x < 2 && i == j && chs[i]-'0' != x) return 0L;\n else if(x < 2 && i < j) return 0L;\n else if(memo[i][j][x] < 0){\n long res = 0L;\n res = (res + ((i==0?fibpow[x]:(1L)) * doit(i,j, x-2))%mod)%mod;\n for(int t = i; t < j; t++) res = (res + (doit(i,t,x-1) * doit(t+1,j, x-2))%mod)%mod;\n res = (res + (doit(i,j,x-1) * (j==chs.length-1? fibpow[x-1]:(1L)))%mod)%mod;\n memo[i][j][x] = res;\n }\n return memo[i][j][x];\n }\n\n\n public static void main(String[] args) {\n (new F946()).run();\n }\n\n private BufferedReader in;\n private PrintWriter out;\n private StringTokenizer tokenizer;\n\n public void run() {\n try {\n in = new BufferedReader(new InputStreamReader(System.in));\n tokenizer = null;\n out = new PrintWriter(System.out);\n solve();\n in.close();\n out.close();\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(1);\n }\n }\n\n private int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n private long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n private float nextFloat() throws IOException {\n return Float.parseFloat(nextToken());\n }\n\n private String nextLine() throws IOException {\n return new String(in.readLine());\n }\n\n private String nextToken() throws IOException {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(in.readLine());\n }\n return tokenizer.nextToken();\n }\n\n\n}", "lang_cluster": "Java", "tags": ["matrices", "dp", "combinatorics"], "code_uid": "b0d79ea2ad22505f5b0b3271ef02c1b9", "src_uid": "52c6aa73ff4460799402c646c6263630", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\npublic class Main {\n static BufferedReader reader \n\t\t= new BufferedReader(new InputStreamReader(System.in)); \n static StringBuilder out = new StringBuilder();\n\n public static void main(String[] args){\n int[] inp = nextIntArray();\n double r, h;\n r = inp[0]; h = inp[1];\n double a = (h + r/2) / r;\n double b = ( ( (2 - Math.sqrt(3)) * r / 2 ) + h) / r;\n a = 2 * Math.floor(0.0000001 + a);\n b = 1 + 2 * Math.floor(0.0000001 + b);\n out.append((int) Math.max(a, b));\n\n System.out.println(out);\n }\n\n // the followings are methods to take care of inputs.\n static int nextInt(){\n return Integer.parseInt(nextLine());\n }\n static long nextLong(){\n return Long.parseLong(nextLine());\n }\n static int[] nextIntArray(){\n String[] inp = nextLine().split(\"\\\\s+\");\n int[] ary = new int[inp.length]; for (int i = 0; i < ary.length; i++){\n ary[i] = Integer.parseInt(inp[i]);\n }\n return ary;\n }\n static int[] nextIntArrayFrom1(){\n String[] inp = nextLine().split(\"\\\\s+\");\n int[] ary = new int[inp.length + 1];\n for (int i = 0; i < inp.length; i++){\n ary[i+1] = Integer.parseInt(inp[i]);\n }\n return ary;\n }\n static long[] nextLongArray(){\n String[] inp = nextLine().split(\"\\\\s+\");\n long[] ary = new long[inp.length];\n for (int i = 0; i < inp.length; i++){\n ary[i] = Long.parseLong(inp[i]);\n }\n return ary;\n }\n static long[] nextLongArrayFrom1(){\n String[] inp = nextLine().split(\"\\\\s+\");\n long[] ary = new long[inp.length + 1];\n for (int i = 0; i < inp.length; i++){\n ary[i+1] = Long.parseLong(inp[i]);\n }\n return ary;\n }\n\tstatic String nextLine(){\n\t\ttry { \n\t\t\treturn reader.readLine().trim();\n\t\t} catch (Exception e){}\n\t\treturn null;\n\t}\n}\n\n", "lang_cluster": "Java", "tags": ["geometry"], "code_uid": "295d48f5a02eb042413f7b9e08072898", "src_uid": "ae883bf16842c181ea4bd123dee12ef9", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": " import java.awt.Checkbox;\nimport java.awt.Point;\nimport java.io.*;\n import java.math.*;\n import java.util.*;\nimport java.util.Map.Entry;\n\nimport javax.print.attribute.SetOfIntegerSyntax;\nimport javax.swing.plaf.FontUIResource;\n \n public class CODE2{\n private static InputStream stream;\n private static byte[] buf = new byte[1024];\n private static int curChar;\n private static int numChars;\n private static SpaceCharFilter filter;\n private static PrintWriter pw;\n private static long count = 0,mod=1000000007;\n // private static TreeSet ts=new TreeSet[200000];\npublic final static int INF = (int) 1E9;\n\npublic static void main(String args[]) {\n InputReader(System.in);\n pw = new PrintWriter(System.out); \n new Thread(null ,new Runnable(){\n public void run(){\n try{\n solve();\n \n pw.close();\n } catch(Exception e){\n e.printStackTrace();\n }\n }\n },\"1\",1<<26).start();\n }\n static StringBuilder sb;\n public static void test(){\n sb=new StringBuilder();\n int t=nextInt();\n while(t-->0){\n \n solve();\n \n }\n pw.println(sb);\n }\n public static long pow(long n, long p,long mod) {\n if(p==0)\n return 1;\n if(p==1)\n return n%mod;\n if(p%2==0){\n long temp=pow(n, p/2,mod);\n return (temp*temp)%mod;\n }else{\n long temp=pow(n,p/2,mod);\n temp=(temp*temp)%mod;\n return(temp*n)%mod;\n \n }\n }\n public static long pow(long n, long p) {\n if(p==0)\n return 1;\n if(p==1)\n return n;\n if(p%2==0){\n long temp=pow(n, p/2);\n return (temp*temp);\n }else{\n long temp=pow(n,p/2);\n temp=(temp*temp);\n return(temp*n);\n \n }\n }\n public static void Merge(long a[],int p,int r){\n if(p adj[];\n static boolean Visited[];\n static HashSet exc;\n static long oddsum[]=new long[1000001];\n static long co=0,ans=0;\n \n private static void buildgraph(int n){\n adj=new LinkedList[n+1];\n Visited=new boolean[n+1];\n levl=new int[n+1];\n \n for(int i=0;i<=n;i++){\n adj[i]=new LinkedList();\n \n }\n\n\n }\n \n \n static int[] levl;\n static int[] eat;\n static int n,m;\n static int price[];\n //ind frog crab\n \n public static void solve(){\n \n \tint n=nextInt();\n \tint x=nextInt();\n \tint a[]=nextIntArray(n);\n \tint freq[]=new int[x];\n \tint cnt=0;\n \tfor(int i=0;i q=new LinkedList();\n q.add(sou);\n Visited[sou]=true;\n levl[sou]=0;\n while(!q.isEmpty()){\n int top=q.poll();\n \n for(int i:adj[top]){\n //pw.println(i+\" \"+top);\n if(!Visited[i])\n {\n \n q.add(i);\n levl[i]=levl[top]+1;\n }\n \n Visited[i]=true;\n \n }\n }\n }*/\n \n\n\n\n static int indeg[];\n /* private static void kahn(int n){\n \n PriorityQueue q=new PriorityQueue();\n for(int i=1;i<=n;i++){\n if(indeg[i]==0){\n q.add(i);\n }\n }\n while(!q.isEmpty()){\n int top=q.poll();\n st.push(top);\n for(Node i:adj[top]){\n indeg[i.to]--;\n if(indeg[i.to]==0){\n q.add(i.to);\n }\n }\n }\n }\n \n static int state=1;\n static long no_exc=0,no_vert=0;\n static Stack st;\n static HashSet inset;\n /* private static void topo(int curr){\n \n Visited[curr]=true;\n inset.add(curr);\n for(int x:adj[curr]){\n if(adj[x].contains(curr) || inset.contains(x)){\n state=0;\n return;\n }\n if(state==0)\n return;\n \n }\n st.push(curr);\n \n inset.remove(curr);\n }*/\n static HashSet hs;\n \n \n static boolean prime[];\n static int spf[];\n public static void sieve(int n){\n prime=new boolean[n+1];\n spf=new int[n+1];\n \n Arrays.fill(spf, 1);\n Arrays.fill(prime, true);\n prime[1]=false;\n spf[2]=2;\n \n for(int i=4;i<=n;i+=2){\n spf[i]=2;\n }\n for(int i=3;i<=n;i+=2){\n if(prime[i]){\n spf[i]=i;\n for(int j=2*i;j<=n;j+=i){\n \n prime[j]=false;\n if(spf[j]==1){\n spf[j]=i;\n }\n }\n }\n }\n \n \n }\n \n // To Get Input\n// Some Buffer Methods\n \n public static void sort(long a[]){\n Merge(a, 0, a.length-1);\n }\n public static void InputReader(InputStream stream1) {\n stream = stream1;\n }\n \n private static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n \n private static boolean isEndOfLine(int c) {\n return c == '\\n' || c == '\\r' || c == -1;\n }\n \n private static int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n \n private static int nextInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n \n private static long nextLong() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n \n private static String nextToken() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n \n private static String nextLine() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isEndOfLine(c));\n return res.toString();\n }\n \n private static int[] nextIntArray(int n) {\n int[] arr = new int[n];\n for (int i = 0; i < n; i++) {\n arr[i] = nextInt();\n }\n return arr;\n }\n \n private static long[][] next2dArray(int n, int m) {\n long[][] arr = new long[n][m];\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n arr[i][j] = nextLong();\n }\n }\n return arr;\n }\n private static char[][] nextCharArray(int n,int m){\n char [][]c=new char[n][m];\n for(int i=0;i>> 1) + low;\n if (array[mid] < value) low = mid + 1;\n else high = mid;\n }\n return low;\n }\n\n static int upperBound(int[] array, int value) {\n int low = 0, high = array.length, mid;\n while (low < high) {\n mid = ((high - low) >>> 1) + low;\n if (array[mid] <= value) low = mid + 1;\n else high = mid;\n }\n return low;\n }\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "f4157936c3707d835cca6a728068dd41", "src_uid": "59f40d9f35e5fe402112214b42b682b5", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport static java.lang.Math.*;\nimport java.util.*;\nimport java.util.function.*;\nimport java.lang.*;\n\npublic class Main {\n final static boolean debug = false;\n final static String fileName = \"\";\n final static boolean useFiles = false;\n\n public static void main(String[] args) throws FileNotFoundException {\n long start;\n if (debug)\n start = System.nanoTime();\n InputStream inputStream;\n OutputStream outputStream;\n if (useFiles) {\n inputStream = new FileInputStream(fileName + \".in\");\n outputStream = new FileOutputStream(fileName + \".out\");\n } else {\n inputStream = System.in;\n outputStream = System.out;\n }\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n Task solver = new Task(in, out);\n solver.solve();\n if(debug)\n out.println((System.nanoTime() - start) / 1e+9);\n out.close();\n }\n}\nclass Task {\n public void solve() {\n int[][] a = new int[3][3];\n for (int i = 0; i < 3; i++)\n for (int j = 0; j < 3; j++)\n a[i][j] = in.nextInt();\n int n = in.nextInt();\n long[][][] dp = new long[3][3][n + 1];\n for (int i = 1; i <= n; i++) {\n for (int from = 0; from < 3; from++) {\n for (int to = 0; to < 3; to++) {\n if (from == to)\n continue;\n int other = 3 - (from + to);\n dp[from][to][i] = min(dp[from][other][i - 1] + a[from][to] + dp[other][to][i - 1],\n dp[from][to][i - 1] + a[from][other] + dp[to][from][i - 1] + a[other][to] + dp[from][to][i - 1]);\n }\n }\n }\n out.println(dp[0][2][n]);\n }\n\n private InputReader in;\n private PrintWriter out;\n\n Task(InputReader in, PrintWriter out) {\n this.in = in;\n this.out = out;\n }\n}\n\nclass InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public double nextDouble(){\n return Double.parseDouble(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong(){\n return Long.parseLong(next());\n }\n\n public byte nextByte(){\n return Byte.parseByte(next());\n }\n}\n", "lang_cluster": "Java", "tags": ["dp"], "code_uid": "4e4684e47717904592f7faa4ca539550", "src_uid": "c4c20228624365e39299d0a6e8fe7095", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class c\n{\n\tpublic static void main(String[] arg) throws IOException\n\t{\n\t\tnew c();\n\t}\n\tpublic c() throws IOException\n\t{\n\t\tFastScanner in = new FastScanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint n = in.nextInt();\n\t\tout.println(Math.max(1, 4*(int)(Math.sqrt(2)*n)));\n\t\tin.close(); out.close();\n\t}\n\tclass FastScanner\n\t{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FastScanner(InputStream in)\n\t\t{\n\t\t\tbr = new BufferedReader(new InputStreamReader(in));\n\t\t\tst = new StringTokenizer(\"\");\n\t\t}\n\t\tpublic String next() throws IOException\n\t\t{\n\t\t\twhile(!st.hasMoreTokens()) st = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tpublic int nextInt() throws IOException\n\t\t{\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tpublic void close() throws IOException\n\t\t{\n\t\t\tbr.close();\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "tags": ["geometry"], "code_uid": "c39597eded393b7e8312c57884575ab8", "src_uid": "d87ce09acb8401e910ca6ef3529566f4", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "public class H {\n\tpublic static void main(String[] args) {\n\t\tint n = new java.util.Scanner(System.in).nextInt();\n\t\tfor (int i = 1; i < n; ++i) {\n\t\t\tfor (int j = 1; j < n; ++j) {\n\t\t\t\tSystem.out.print(Integer.toString(i * j, n) + \" \");\n\t\t\t}\n\t\t\tSystem.out.println();\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "ae099c994d91a01463e26e651b18ce03", "src_uid": "a705144ace798d6b41068aa284d99050", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.Scanner;\n\npublic class MonthsYears {\n\n\tpublic static void main(String[] args){\n\t\tList year = new ArrayList<>();\n\t\tyear.add(31);\n\t\tyear.add(28);\n\t\tyear.add(31);\n\t\tyear.add(30);\n\t\tyear.add(31);\n\t\tyear.add(30);\n\t\tyear.add(31);\n\t\tyear.add(31);\n\t\tyear.add(30);\n\t\tyear.add(31);\n\t\tyear.add(30);\n\t\tyear.add(31);\n\t\t\n\t\tList values = new ArrayList<>();\n\t\tboolean containsLeap = false;\n\t\tboolean done = false;\n\t\tboolean match = true;\n\t\tScanner sc = new Scanner(System.in);\n\t\tint sum =0;\n\t\tint n = sc.nextInt(); \n\t\tfor(int counter =0;counter > v = new Vector >();\n\tpublic static void main(String[] args) throws IOException {\n\t\tv.setSize(12);\n\t\t\n\t\tBufferedReader cin = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer tok = new StringTokenizer(cin.readLine());\n\t\tint n = Integer.parseInt(tok.nextToken());\n\t\tint m = Integer.parseInt(tok.nextToken());\n\t\tint k = Integer.parseInt(tok.nextToken());\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tv.set(i, new Vector());\n\t\t\tcin.readLine();\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tState s = new State();\n\t\t\t\ttok = new StringTokenizer(cin.readLine());\n\t\t\t\ts.a = Integer.parseInt(tok.nextToken());\n\t\t\t\ts.b = Integer.parseInt(tok.nextToken());\n\t\t\t\ts.c = Integer.parseInt(tok.nextToken());\n\t\t\t\tv.get(i).add(s);\n\t\t\t}\n\t\t}\n\n\t\tint mx=0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tif(i == j) continue;\n\t\t\t\tint val = 0;\n\t\t\t\tVector pro = new Vector();\n\t\t\t\tfor (int kk = 0; kk < v.get(i).size(); kk++) {\n\t\t\t\t\tif(v.get(j).get(kk).b <= v.get(i).get(kk).a) continue;\n\t\t\t\t\tpro.add(new Point(v.get(j).get(kk).b - v.get(i).get(kk).a, v.get(i).get(kk).c));\n\t\t\t\t}\n\t\t\t\tint lim = k;\n\t\t\t\tCollections.sort(pro, new cmp());\n\t\t\t\tfor (int kk = 0; kk < pro.size(); kk++) {\n\t\t\t\t\tif(pro.get(kk).y <= lim){\n\t\t\t\t\t\tlim -= pro.get(kk).y;\n\t\t\t\t\t\tval += pro.get(kk).x*pro.get(kk).y;\n\t\t\t\t\t}\n\t\t\t\t\telse{\n\t\t\t\t\t\tval += pro.get(kk).x*lim;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tmx = Math.max(mx,val);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(mx);\n\t}\n\n}\nclass State{\n\tpublic int a,b,c;\n\n}\n\nclass cmp implements Comparator{\n\n\t@Override\n\tpublic int compare(Point o1, Point o2) {\n\t\tif(o1.x > o2.x) return -1;\n\t\tif(o1.x < o2.x) return 1;\n\t\tif(o1.y > o2.y) return -1;\n\t\tif(o1.y < o2.y) return 1;\n\t\treturn 0;\n\t}\n\n}", "lang_cluster": "Java", "tags": ["greedy", "games", "graph matchings"], "code_uid": "2becf71128fe66076c8177bd1d77eb48", "src_uid": "7419c4268a9815282fadca6581f28ec1", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class G {\n\n\tstatic final int P = 1_000_000_007;\n\n\tvoid submit() {\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\t\tlong exp = nextLong();\n\t\tint[] a = new int[n];\n\t\tint[] b = new int[m];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = nextInt();\n\t\t}\n\t\tint maxCoef = 0;\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tb[i] = nextInt();\n\t\t\tmaxCoef = Math.max(maxCoef, b[i]);\n\t\t}\n\n\t\tint[] bPoly = new int[maxCoef + 1];\n\t\tbPoly[maxCoef] = 1;\n\t\tfor (int pow : b) {\n\t\t\tbPoly[maxCoef - pow]--;\n\t\t\tif (bPoly[maxCoef - pow] < 0) {\n\t\t\t\tbPoly[maxCoef - pow] += P;\n\t\t\t}\n\t\t}\n\t\t\n\t\tint[] aPoly = {};\n\t\tfor (int pow : a) {\n\t\t\taPoly = sum(aPoly, quotPow(new int[] { 0, 1 }, bPoly, pow));\n\t\t}\n\t\tint[] ans = quotPow(aPoly, bPoly, exp);\n\n\t\tans = prod(ans, quotPow(new int[] { 0, 1 }, bPoly, maxCoef));\n\t\tans = quot(ans, bPoly);\n\n\t\tout.println((long)ans[0] * inv(P - bPoly[0]) % P);\n\t}\n\t\n\tint inv(int x) {\n\t\treturn x == 1 ? 1 : P - (int)((long)(P / x) * inv(P % x) % P);\n\t}\n\n\tint[] quotPow(int[] a, int[] b, long n) {\n\t\ta = quot(a, b);\n\t\tint[] ret = { 1 };\n\t\tfor (; n > 0; n >>= 1) {\n\t\t\tif ((n & 1) == 1) {\n\t\t\t\tret = quot(prod(ret, a), b);\n\t\t\t}\n\t\t\ta = quot(prod(a, a), b);\n\t\t}\n\t\treturn ret;\n\t}\n\n\tint[] sum(int[] a, int[] b) {\n\t\tint[] c = Arrays.copyOf(a, Math.max(a.length, b.length));\n\t\tfor (int i = 0; i < b.length; i++) {\n\t\t\tc[i] += b[i];\n\t\t\tif (c[i] >= P) {\n\t\t\t\tc[i] -= P;\n\t\t\t}\n\t\t}\n\t\treturn c;\n\t}\n\n\tint[] prod(int[] a, int[] b) {\n\t\tint[] c = new int[a.length + b.length - 1];\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tfor (int j = 0; j < b.length; j++) {\n\t\t\t\tc[i + j] += (int) ((long) a[i] * b[j] % P);\n\t\t\t\tif (c[i + j] >= P) {\n\t\t\t\t\tc[i + j] -= P;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn c;\n\t}\n\n\tint[] quot(int[] a, int[] b) {\n\t\ta = a.clone();\n\t\t// leading coef of b is 1\n\t\tif (a.length < b.length) {\n\t\t\treturn a;\n\t\t}\n\t\tint degB = b.length - 1;\n\t\tfor (int ptr = a.length - 1; ptr >= degB; ptr--) {\n\t\t\tlong coef = a[ptr];\n\t\t\tfor (int i = 0, j = ptr - degB; i < degB; i++, j++) {\n\t\t\t\ta[j] -= (int) (coef * b[i] % P);\n\t\t\t\tif (a[j] < 0) {\n\t\t\t\t\ta[j] += P;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn Arrays.copyOf(a, degB);\n\t}\n\n\tvoid preCalc() {\n\n\t}\n\n\tvoid stress() {\n\n\t}\n\n\tvoid test() {\n\n\t}\n\n\tG() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tpreCalc();\n\t\tsubmit();\n\t\t// stress();\n\t\t// test();\n\t\tout.close();\n\t}\n\n\tstatic final Random rng = new Random();\n\n\tstatic int rand(int l, int r) {\n\t\treturn l + rng.nextInt(r - l + 1);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew G();\n\t}\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t}\n\n\tint nextInt() {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "matrices", "combinatorics"], "code_uid": "cbc9359183def1896b34988dcd73d4da", "src_uid": "c3a4c109080f49b88be5fb13157d1af0", "difficulty": 3300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.List;\nimport java.util.Scanner;\n\npublic class Codeforces911C {\n\n public static void main(String[] args) {\n Integer[] array = new Integer[3];\n boolean possible = false;\n Scanner scanner = new Scanner(System.in);\n array[0] = scanner.nextInt();\n array[1] = scanner.nextInt();\n array[2] = scanner.nextInt();\n List list = Arrays.asList(array);\n Collections.sort(list);\n array = (Integer[]) list.toArray();\n int sum = array[0] + array[1] + array[2];\n if (sum > 7) {\n\n if (array[0] == 1) {\n possible = true;\n } else if (array[1] <= 2) {\n possible = true;\n } else if (array[1] == 3) {\n if (array[0] == 3 && array[2] == 3) {\n possible = true;\n } else {\n possible = false;\n }\n } else if (array[1] == 4) {\n if (array[2] == 4 && array[0] == 2) {\n possible = true;\n } else {\n possible = false;\n }\n }\n\n } else {\n possible = true;\n }\n if(possible){\n System.out.println(\"YES\");\n } else {\n System.out.println(\"NO\");\n }\n// int gcd = BigInteger.valueOf(array[0]).gcd(BigInteger.valueOf(array[1])).gcd(BigInteger.valueOf(array[2])).intValue();\n// gcd = array[0]*array[1]*array[2]/gcd;\n\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "constructive algorithms"], "code_uid": "aacc6d787450febc29bece430313040d", "src_uid": "df48af9f5e68cb6efc1214f7138accf9", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.awt.geom.*;\n\nimport static java.lang.Math.*;\n\npublic class Main implements Runnable {\n \n static String filename = \"\";\n \n int[] factorize(int n) {\n ArrayList ans = new ArrayList();\n for (int i = 2; i <= n; i++) {\n while (n % i == 0) {\n ans.add(i);\n n /= i;\n }\n }\n int[] ansa = new int[ans.size()];\n for (int i = 0; i < ans.size(); i++) {\n ansa[i] = ans.get(i);\n }\n return ansa;\n }\n \n int gcd(int a, int b) {\n while (b != 0) {\n a %= b;\n int temp = a;\n a = b;\n b = temp;\n }\n return a;\n }\n \n int digitsum(int n, int b) {\n int ans = 0;\n while (n > 0) {\n ans += n % b;\n n /= b;\n }\n return ans;\n }\n \n int get3(int b) {\n Random rnd = new Random();\n int ans = 0;\n for (int i = 0; i < 10000; i++) {\n int num = rnd.nextInt(1000000000);\n ans = gcd(ans, num - digitsum(num, b));\n }\n return ans;\n }\n \n int is2type(int b, int d) {\n int[] bfactors = factorize(b);\n int[] dfactors = factorize(d);\n \n boolean type2 = true;\n TreeMap bf = new TreeMap();\n for (int i : bfactors) {\n if (!bf.containsKey(i)) {\n bf.put(i, 0);\n }\n bf.put(i, bf.get(i) + 1);\n }\n TreeMap df = new TreeMap();\n for (int i : dfactors) {\n if (!df.containsKey(i)) {\n df.put(i, 0);\n }\n df.put(i, df.get(i) + 1);\n }\n for (int i : dfactors) {\n if (!bf.containsKey(i)) {\n type2 = false;\n }\n }\n \n if (type2) {\n int ans = 0;\n long pow = 1;\n while (pow % d != 0) {\n pow *= b;\n ans++;\n /*\n for (Map.Entry e : df.entrySet()) {\n System.out.println(e.getKey() + \" \" + e.getValue());\n }\n System.out.println();\n */\n }\n return ans;\n } else {\n return -1;\n }\n }\n \n boolean is3type(int b, int d) {\n return (b - 1) % d == 0;\n }\n \n boolean is11type(int b, int d) {\n return (b + 1) % d == 0;\n }\n \n HashMap type6 = new HashMap();\n \n boolean is6type(int b, int d) {\n if (type6.containsKey(d)) {\n return type6.get(d);\n }\n for (int i = 2; i < d; i++) {\n if (d % i == 0) {\n int di = d / i;\n if (i % di == 0 || di % i == 0) {\n continue;\n }\n boolean[] m1 = getMask(b, i);\n boolean[] m2 = getMask(b, di);\n for (int ii = 0; ii < 4; ii++) {\n for (int jj = 0; jj < 4; jj++) {\n if (ii == jj) {\n continue;\n }\n if (m1[ii] && m2[jj]) {\n type6.put(d, true);\n return true;\n }\n }\n }\n /*\n if (is2type(b, i) != -1 || is3type(b, i) || is11type(b, i) || is6type(b, i)) {\n if (is2type(b, di) != -1 || is3type(b, di) || is11type(b, di) || is6type(b, di)) {\n if (is3type(b, i) && is3type(b, di))\n continue;\n type6.put(d, true);\n return true;\n }\n }\n */\n }\n }\n type6.put(d, false);\n return false;\n }\n \n boolean[] getMask(int b, int d) {\n boolean[] ans = new boolean[4];\n ans[0] = is2type(b, d) != -1;\n ans[1] = is3type(b, d);\n ans[2] = is11type(b, d);\n ans[3] = is6type(b, d);\n return ans;\n }\n \n public void solve() throws Exception {\n int b = sc.nextInt(), d = sc.nextInt();\n int ans;\n if ((ans = is2type(b, d)) != -1) {\n out.println(\"2-type\");\n out.println(ans);\n } else if (is3type(b, d)) {\n out.println(\"3-type\");\n } else if (is11type(b, d)) {\n out.println(\"11-type\");\n } else if (is6type(b, d)) {\n out.println(\"6-type\");\n } else {\n out.println(\"7-type\");\n }\n }\n \n BufferedReader in;\n PrintWriter out;\n FastScanner sc;\n \n public static void main(String[] args) {\n new Thread(null, new Main(), \"\", 1 << 25).start();\n }\n \n @Override\n public void run() {\n try {\n init();\n solve();\n } catch (Exception e) {\n throw new RuntimeException(e);\n } finally {\n out.close();\n }\n }\n \n void init() throws Exception {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n sc = new FastScanner(in);\n }\n}\n\nclass FastScanner {\n \n BufferedReader reader;\n StringTokenizer strTok;\n \n public FastScanner(BufferedReader reader) {\n this.reader = reader;\n }\n \n public String nextToken() throws IOException {\n while (strTok == null || !strTok.hasMoreTokens()) {\n strTok = new StringTokenizer(reader.readLine());\n }\n \n return strTok.nextToken();\n }\n \n public int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n \n public BigInteger nextBigInteger() throws IOException {\n return new BigInteger(nextToken());\n }\n \n}\n", "lang_cluster": "Java", "tags": ["math", "number theory"], "code_uid": "a2f4ddbf9b284487434db230c5dda53e", "src_uid": "809e1c78b0a5a16f7f2115b046a20bde", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n/**\n * @author Don Li\n */\npublic class ArtemArray {\n void solve() {\n int n = in.nextInt();\n int[] a = new int[n];\n for (int i = 0; i < n; i++) a[i] = in.nextInt();\n \n long ans = 0;\n int[] b = new int[n];\n int m = 0;\n for (int i = 0; i < n; i++) {\n while (m > 1 && b[m - 1] <= Math.min(b[m - 2], a[i])) {\n ans += Math.min(b[m - 2], a[i]);\n m--;\n }\n b[m++] = a[i];\n }\n \n for (int i = 1; i < m - 1; i++) ans += Math.min(b[i - 1], b[i + 1]);\n \n out.println(ans);\n }\n \n public static void main(String[] args) {\n in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));\n out = new PrintWriter(System.out);\n new ArtemArray().solve();\n out.close();\n }\n \n static FastScanner in;\n static PrintWriter out;\n \n static class FastScanner {\n BufferedReader in;\n StringTokenizer st;\n \n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n \n public String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["greedy"], "code_uid": "a23867f9fdc07d269690433335bc3afe", "src_uid": "e7e0f9069166fe992abe6f0e19caa6a1", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.NoSuchElementException;\nimport java.io.Writer;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskE solver = new TaskE();\n solver.solve(1, in, out);\n out.close();\n }\n}\n\nclass TaskE {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int n=in.readInt(), sx=in.readInt()%n, sy=in.readInt()%n, dx=in.readInt()%n, dy=in.readInt()%n;\n long t=in.readLong(), Sx=(2L*sx+dx+sy)%n, Sy=(2L*sy+dy+sx)%n, Dx=(dx+sx+sy)%n, Dy=(dy+sy+sx)%n, t0=(t%2==0?t/2:t)%n, t1=(t%2==1?(t-1)/2:t-1)%n;\n Matrix.mod=n;\n Matrix base=new Matrix(new long[][] {\n {2, 1, 1, 1, 0, 0},\n {1, 2, 1, 1, 0, 0},\n {1, 0, 1, 0, 0, 0},\n {0, 1, 0, 1, 0, 0},\n {1, 1, 1, 1, 1, 0},\n {0, 0, 0, 0, 1, 1}\n }), matrix=new Matrix(new long[][]{\n {Sx, Sy, Dx, Dy, 1, 1},\n {sx, sy, dx, dy, 0, 1}\n });\n long[][] data=Matrix.multiply(matrix, base.power(t)).data;\n Sx=(data[1][0]+n)%n;\n Sy=(data[1][1]+n)%n;\n //out.printLine(data[1][0], data[1][1]);\n out.printLine(Sx==0?n:Sx, Sy==0?n:Sy);\n }\n}\n\nclass InputReader {\n\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public long readLong() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n}\n\nclass OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public void print(Object...objects) {\n for (int i = 0; i < objects.length; i++) {\n if (i != 0)\n writer.print(' ');\n writer.print(objects[i]);\n }\n }\n\n public void printLine(Object...objects) {\n print(objects);\n writer.println();\n }\n\n public void close() {\n writer.close();\n }\n\n}\n\nclass Matrix {\n public static long mod = Long.MAX_VALUE;\n public final long[][] data;\n public final int rowCount;\n public final int columnCount;\n\n public Matrix(int rowCount, int columnCount) {\n this.rowCount = rowCount;\n this.columnCount = columnCount;\n this.data = new long[rowCount][columnCount];\n }\n\n public Matrix(long[][] data) {\n this.rowCount = data.length;\n this.columnCount = data[0].length;\n this.data = data;\n }\n\n public static Matrix multiply(Matrix first, Matrix second) {\n Matrix result = new Matrix(first.rowCount, second.columnCount);\n for (int i = 0; i < first.rowCount; i++) {\n for (int j = 0; j < second.rowCount; j++) {\n for (int k = 0; k < second.columnCount; k++)\n result.data[i][k] = (result.data[i][k] + first.data[i][j] * second.data[j][k]) % mod;\n }\n }\n return result;\n }\n\n public static Matrix identityMatrix(int size) {\n Matrix result = new Matrix(size, size);\n for (int i = 0; i < size; i++)\n result.data[i][i] = 1;\n return result;\n }\n\n public Matrix power(long exponent) {\n if (exponent == 0)\n return identityMatrix(rowCount);\n if (exponent == 1)\n return this;\n Matrix result = power(exponent >> 1);\n result = multiply(result, result);\n if ((exponent & 1) == 1)\n result = multiply(result, this);\n return result;\n }\n\n}", "lang_cluster": "Java", "tags": ["math", "matrices"], "code_uid": "ce27307de18f18a466ed72a342345654", "src_uid": "ee9fa8be2ae05a4e831a4f608c0cc785", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class Dot {\n\n static int N, D;\n static int[] vx, vy;\n static Boolean[][][][] dp;\n\n static long sq(long x) {\n\treturn x * x;\n }\n\n static boolean solve(int p1, int p2, int x, int y) {\n\tif (sq(x) + sq(y) > sq(D))\n\t return true;\n\tif (dp[p1][p2][x + 200][y + 200] != null)\n\t return dp[p1][p2][x + 200][y + 200];\n\tboolean ans = false;\n\tif (p1 == 0)\n\t ans |= !solve(p2, 1, y, x);\n\tfor (int i = 0; i < N; i++)\n\t ans |= !solve(p2, p1, x + vx[i], y + vy[i]);\n\treturn dp[p1][p2][x + 200][y + 200] = ans;\n }\n\n public static void main(String[] args) throws IOException {\n\tMyScanner sc = new MyScanner(System.in);\n\tPrintWriter out = new PrintWriter(System.out);\n\tint x = sc.nextInt(), y = sc.nextInt();\n\tN = sc.nextInt();\n\tD = sc.nextInt();\n\tvx = new int[N];\n\tvy = new int[N];\n\tfor (int i = 0; i < N; i++) {\n\t vx[i] = sc.nextInt();\n\t vy[i] = sc.nextInt();\n\t}\n\tdp = new Boolean[2][2][402][402];\n\tout.println(solve(0, 0, x, y) ? \"Anton\" : \"Dasha\");\n\tout.flush();\n\tout.close();\n }\n\n static class MyScanner {\n\n\tBufferedReader br;\n\tStringTokenizer st;\n\n\tMyScanner(InputStream is) {\n\t br = new BufferedReader(new InputStreamReader(is));\n\t}\n\n\tString next() throws IOException {\n\t while (st == null || !st.hasMoreTokens())\n\t\tst = new StringTokenizer(br.readLine());\n\t return st.nextToken();\n\t}\n\n\tint nextInt() throws IOException {\n\t return Integer.parseInt(next());\n\t}\n\n\tlong nextLong() throws IOException {\n\t return Long.parseLong(next());\n\t}\n\n\tboolean ready() throws IOException {\n\t return br.ready();\n\t}\n }\n}\n", "lang_cluster": "Java", "tags": ["dp", "games"], "code_uid": "91030c0e59c0aa2e69c3c9736c7a7610", "src_uid": "645a6ca9a8dda6946c2cc055a4beb08f", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class C_submit {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\t\n\tstatic long[][] c = new long[61][];\n\tstatic {\n\t\tfor (int i = 0; i < c.length; i++) {\n\t\t\tc[i] = new long[i + 1];\n\t\t\tc[i][0] = c[i][i] = 1;\n\t\t\tfor (int j = 1; j < i; j++)\n\t\t\t\tc[i][j] = c[i - 1][j] + c[i - 1][j - 1];\n\t\t}\n\t}\n\t\n\tlong c(int n, int k) {\n\t\treturn n < 0 || k < 0 || k > n ? 0 : c[n][k];\n\t}\n\t\n\tvoid solve() throws IOException {\n\t\tlong n = nextLong();\n\t\tlong t = nextLong();\n\t\tif (Long.bitCount(t) != 1) {\n\t\t\tout.println(0);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tint need = Long.numberOfTrailingZeros(t) + 1;\n\t\t\n\t\t// return numbers of x : 2 <= x <= n + 1, bitcount(x) = need\n\t\t\n\t\tn += 2;\n\t\t\n\t\tString s = Long.toBinaryString(n);\n\t\t\n\t\tint prefBitCnt = 0;\n\t\t\n\t\tlong ans = 0;\n\t\t\n\t\tfor (int i = 0; i < s.length(); i++) {\n\t\t\tif (s.charAt(i) == '1') {\n\t\t\t\tint sufLen = s.length() - i - 1;\n\t\t\t\tans += c(sufLen, need - prefBitCnt);\n\t\t\t\tprefBitCnt++;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (need == 1)\n\t\t\tans--;\n\t\t\n\t\tout.println(ans);\n\t}\n\n\tC_submit() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew C_submit();\n\t}\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\teof = true;\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "dp", "constructive algorithms"], "code_uid": "57607e846aa62934e6c09c3ba6ed2175", "src_uid": "727d5b601694e5e0f0cf3a9ca25323fc", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.Scanner;\nimport java.util.Comparator;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.io.PrintWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author @zhendeaini6001\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tScanner in = new Scanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskC solver = new TaskC();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskC {\n public final long MOD = 1000000007;\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n String a = in.next();\n String b = in.next();\n long[][] dp = new long[2][5001];\n ArrayUtils.fill(dp, 0);\n int flag = 0;\n long res = 0;\n for (int i = 0; i < a.length(); ++i){\n Arrays.fill(dp[i&1], 0);\n for (int j = 0; j < b.length(); ++j){\n if (j >= 1){\n dp[i&1][j] = dp[i&1][j - 1];\n }\n if (a.charAt(i) == b.charAt(j)){\n ++dp[i&1][j];\n if (i >= 1 && j >= 1){\n dp[i&1][j] += dp[(i-1)&1][j-1];\n }\n dp[i&1][j] %= MOD;\n }\n }\n res += dp[i&1][b.length() - 1]; res %= MOD;\n }\n out.println(res);\n return;\n }\n\n\n}\n\nclass ArrayUtils {\n\n public static void fill(long[][] array, long value) {\n for (long[] row : array)\n Arrays.fill(row, value);\n }\n\n }\n\n", "lang_cluster": "Java", "tags": ["dp"], "code_uid": "e9e561b0a91e7673d6da5dbb4a40fa93", "src_uid": "4022f8f796d4f2b7e43a8360bf34e35f", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "//package com.company;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Main {\n\n public static void main(String[] args) throws IOException {\n InputStreamReader input = new InputStreamReader(System.in);\n BufferedReader in = new BufferedReader(input);\n\n String s = in.readLine();\n String ss[] = s.split(\" \");\n\n int n = Integer.parseInt(ss[0]);\n int k = Integer.parseInt(ss[1]);\n\n String number = in.readLine();\n if (k == 0)\n {\n System.out.println(number);\n }\n else if(n == 1)\n {\n System.out.println(\"0\");\n }\n else\n {\n StringBuffer tmp = new StringBuffer();\n tmp.append(\"1\");\n\n if(number.charAt(0) != '1')\n k--;\n\n int counter = 1;\n while(k > 0 && counter < n)\n {\n if(number.charAt(counter) != '0')\n {\n k--;\n }\n counter++;\n tmp.append(\"0\");\n }\n\n if(counter < n)\n tmp.append(number.substring(counter));\n\n System.out.println(tmp.toString());\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["greedy", "implementation"], "code_uid": "a0422939050a857cb3eea03c26be0df1", "src_uid": "0515ac888937a4dda30cad5e2383164f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.Queue;\nimport java.util.Random;\nimport java.util.StringTokenizer;\n\npublic class DimaAndHorses2 {\n public static void main(String[] args) {\n InputReader r = new InputReader(System.in);\n PrintWriter out = new PrintWriter(System.out);\n int n = r.nextInt(), m = r.nextInt();\n ArrayList[] adj = new ArrayList[n];\n for (int i = 0; i < adj.length; i++) {\n adj[i] = new ArrayList();\n }\n for (int i = 0; i < m; i++) {\n int from = r.nextInt() - 1;\n int to = r.nextInt() - 1;\n adj[from].add(to);\n adj[to].add(from);\n }\n int[] res = new int[n];\n Queue q = new LinkedList();\n for (int i = 0; i < n; i++)\n q.add(i);\n while (!q.isEmpty()) {\n int f = q.remove();\n int enemies = 0;\n for (int x : adj[f])\n if (res[x] == res[f])\n enemies++;\n if (enemies < 2)\n continue;\n res[f] = 1 - res[f];\n for (int x : adj[f])\n q.add(x);\n q.add(f);\n }\n for (int x : res)\n out.print(x);\n out.close();\n return;\n }\n\n static class InputReader {\n private BufferedReader reader;\n private StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n tokenizer = null;\n }\n\n public String nextLine() {\n try {\n return reader.readLine();\n } catch (IOException e) {\n // TODO Auto-generated catch block\n e.printStackTrace();\n return null;\n }\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["constructive algorithms", "combinatorics", "graphs"], "code_uid": "1416778fa4b5fb4330bec097acea70c7", "src_uid": "7017f2c81d5aed716b90e46480f96582", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class B {\n\n long n, c0, c1;\n\n public void solve() {\n n = in.nextInt() - 1;\n c0 = in.nextInt();\n c1 = in.nextInt();\n if (c0 > c1) {\n long tmp = c0;\n c0 = c1;\n c1 = tmp;\n }\n\n if (c0 == 0) {\n out.println(1L * n * (c0 + c1));\n return;\n }\n\n long left = 0, right = (long) 5e17;\n\n while (left < right - 1) {\n long mid = (left + right) >>> 1;\n\n long[] calc = calc(mid);\n if (calc[0] < n) {\n left = mid;\n } else {\n right = mid;\n }\n }\n System.err.println(left);\n long[] calc2 = calc(left);\n\n long result = calc2[1] + (n - calc2[0]) * (left + 1);\n result += 1L * n * (c0 + c1);\n out.println(result);\n }\n\n long[] calc(long x) {\n long count = 0, sum = 0;\n for (long j = 0; c1 * j <= x; j++) {\n long maxI = (x - c1 * j) / c0;\n if (j == 0) {\n count += (maxI + 1);\n sum += c0 * maxI * (maxI + 1) / 2;\n } else {\n long curChoose = 1;\n for (long i = 0; i * c0 + j * c1 <= x; i++) {\n if (i > 0) {\n curChoose *= (i + j);\n curChoose /= i;\n }\n count += curChoose;\n sum += curChoose * (i * c0 + j * c1);\n if (count >= n) {\n return new long[]{count, sum};\n }\n }\n }\n }\n return new long[]{count, sum};\n }\n\n public void run() {\n in = new FastScanner();\n out = new PrintWriter(System.out);\n solve();\n out.close();\n }\n\n FastScanner in;\n PrintWriter out;\n\n class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(String fileName) {\n try {\n br = new BufferedReader(new FileReader(fileName));\n } catch (FileNotFoundException e) {\n }\n }\n\n public FastScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String nextToken() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n\n public static void main(String[] args) {\n new B().run();\n }\n}\n", "lang_cluster": "Java", "tags": ["greedy", "dp"], "code_uid": "61c58402e327f18c555355fc8b6397e9", "src_uid": "39b824b740a40f68bae39b8d9f0adcbe", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Codeforces\r\n{\r\n public static void main(String args[])throws Exception\r\n {\r\n BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));\r\n StringBuilder sb=new StringBuilder();\r\n String s[]=bu.readLine().split(\" \");\r\n int n=Integer.parseInt(s[0]);\r\n int i; double p=Double.parseDouble(s[1]);\r\n\r\n for(i=0;i<=n;i++)\r\n if(probab(n,i)>=p) break;\r\n System.out.println(i);\r\n }\r\n\r\n static int ncr(int n,int r)\r\n {\r\n if(r>n) return 0;\r\n int ans=1,i;\r\n for(i=n;i>n-r;i--) ans*=i;\r\n for(i=2;i<=r;i++) ans/=i;\r\n return ans;\r\n }\r\n\r\n static double probab(int n,int x)\r\n {\r\n int a=ncr(x,3)*ncr(n-x,0);\r\n int b=ncr(x,2)*ncr(n-x,1);\r\n int c=ncr(x,1)*ncr(n-x,2);\r\n return 1.0*((3.0/6)*c+a+b)/ncr(n,3);\r\n }\r\n}", "lang_cluster": "Java", "tags": ["math", "probabilities", "binary search"], "code_uid": "75fd5c9ca925bd141dc2dcf0315dcb22", "src_uid": "788ed59a964264bd0e755e155a37e14d", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.Locale;\nimport java.util.Scanner;\n\n/**\n * Author: Sergey Paramonov\n * Date: 27.07.14\n * Time: 19:47\n */\npublic class MemSQL_20140727_C {\n\n Scanner scanner = new Scanner(System.in);\n BufferedReader buffered = new BufferedReader(new InputStreamReader(System.in));\n StreamTokenizer input = new StreamTokenizer(buffered);\n\n static PrintWriter output = new PrintWriter(new BufferedOutputStream(System.out));\n\n int nextInt() throws Exception {\n input.nextToken();\n return (int) input.nval;\n }\n\n static void flushAndClose() {\n output.flush();\n System.out.flush();\n output.close();\n }\n\n void main() throws Exception {\n double n = nextInt();\n double m = nextInt();\n double ans = 1.0/n;\n if (m > 1) {\n ans += (1.0 - 1.0/n) * (m-1.0)/(n*m - 1.0);\n }\n System.out.printf(Locale.ENGLISH, \"%.10f\", ans);\n }\n\n public static void main(String[] args) throws Exception {\n new MemSQL_20140727_C().main();\n flushAndClose();\n }\n\n}\n", "lang_cluster": "Java", "tags": ["probabilities", "math", "combinatorics"], "code_uid": "eedea66680e3d637193eee1916300177", "src_uid": "0b9ce20c36e53d4702869660cbb53317", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author dmytro.prytula\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n DTriFiguri solver = new DTriFiguri();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class DTriFiguri {\n static int N;\n int M = 305;\n int INF = (int) 1e9;\n DTriFiguri.Point[] possibleKnight = new DTriFiguri.Point[]{\n DTriFiguri.Point.of(2, 1),\n DTriFiguri.Point.of(-2, 1),\n DTriFiguri.Point.of(2, -1),\n DTriFiguri.Point.of(-2, -1),\n DTriFiguri.Point.of(1, 2),\n DTriFiguri.Point.of(-1, 2),\n DTriFiguri.Point.of(1, -2),\n DTriFiguri.Point.of(-1, -2)\n };\n DTriFiguri.Point[][] dist = new DTriFiguri.Point[M][M];\n\n {\n\n\n }\n\n private boolean in(DTriFiguri.Point p) {\n return 0 <= p.x && p.x < N && 0 <= p.y && p.y < N;\n }\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n\n N = in.nextInt();\n DTriFiguri.Point[] pos = new DTriFiguri.Point[N * N];\n int[][] A = new int[N][N];\n for (int x = 0; x < N; x++) {\n for (int y = 0; y < N; y++) {\n A[x][y] = in.nextInt() - 1;\n pos[A[x][y]] = DTriFiguri.Point.of(x, y);\n\n }\n }\n\n for (int i = 0; i < M; i++) {\n for (int j = 0; j < M; j++) {\n// Arrays.fill(dist[i], Point.of(INF, INF));\n dist[i][j] = DTriFiguri.Point.of(INF, INF);\n }\n }\n for (int i = 0; i < M; i++)\n// for (int j = 0; j < M; j++)\n// if (i == j)\n dist[i][i] = DTriFiguri.Point.of(0, 0);\n\n\n for (int x = 0; x < N; x++) {\n for (int y = 0; y < N; y++) {\n //knight\n for (int i = 0; i < possibleKnight.length; i++) {\n int nx = x + possibleKnight[i].x;\n int ny = y + possibleKnight[i].y;\n if (in(DTriFiguri.Point.of(nx, ny))) {\n dist[DTriFiguri.Point.hash(x, y, 0)][DTriFiguri.Point.hash(nx, ny, 0)] = DTriFiguri.Point.of(1, 0);\n }\n }\n //bishop\n for (int i = -N + 1; i <= N - 1; i++) {\n int nx = x + i;\n int ny = y + i;\n if (in(DTriFiguri.Point.of(nx, ny)))\n dist[DTriFiguri.Point.hash(x, y, 1)][DTriFiguri.Point.hash(nx, ny, 1)] = DTriFiguri.Point.of(1, 0);\n\n ny = y - i;\n if (in(DTriFiguri.Point.of(nx, ny)))\n dist[DTriFiguri.Point.hash(x, y, 1)][DTriFiguri.Point.hash(nx, ny, 1)] = DTriFiguri.Point.of(1, 0);\n }\n\n //rook\n for (int i = 0; i < N; i++) {\n int nx = i;\n int ny = y;\n// if (in(Point.of(nx, ny)))\n dist[DTriFiguri.Point.hash(x, y, 2)][DTriFiguri.Point.hash(nx, ny, 2)] = DTriFiguri.Point.of(1, 0);\n nx = x;\n ny = i;\n// if (in(Point.of(nx, ny)))\n dist[DTriFiguri.Point.hash(x, y, 2)][DTriFiguri.Point.hash(nx, ny, 2)] = DTriFiguri.Point.of(1, 0);\n\n }\n\n for (int i = 0; i < 3; i++) {\n for (int j = 0; j < 3; j++) {\n if (i != j) {\n dist[DTriFiguri.Point.hash(x, y, i)][DTriFiguri.Point.hash(x, y, j)] = DTriFiguri.Point.of(1, 1);\n }\n }\n }\n\n\n }\n }\n\n for (int k = 0; k < M; k++) {\n for (int i = 0; i < M; i++) {\n for (int j = 0; j < M; j++) {\n dist[i][j] = DTriFiguri.Point.min(dist[i][j], DTriFiguri.Point.sum(dist[i][k], dist[k][j]));\n }\n }\n }\n\n DTriFiguri.Point[][] dp = new DTriFiguri.Point[N * N][3];\n for (int i = 0; i < N * N; i++) {\n for (int j = 0; j < 3; j++) {\n dp[i][j] = DTriFiguri.Point.of(INF, INF);\n }\n }\n\n dp[0][0] = dp[0][1] = dp[0][2] = DTriFiguri.Point.of(0, 0);\n\n\n for (int i = 0; i < N * N - 1; i++)\n for (int j = 0; j < 3; j++)\n for (int k = 0; k < 3; k++)\n dp[i + 1][k] = DTriFiguri.Point.min(\n dp[i + 1][k],\n DTriFiguri.Point.sum(dp[i][j], dist[DTriFiguri.Point.hash(pos[i].x, pos[i].y, j)][DTriFiguri.Point.hash(pos[i + 1].x, pos[i + 1].y, k)])\n );\n\n\n DTriFiguri.Point ans = DTriFiguri.Point.of(INF, INF);\n ans = DTriFiguri.Point.min(ans, dp[N * N - 1][0]);\n ans = DTriFiguri.Point.min(ans, dp[N * N - 1][1]);\n ans = DTriFiguri.Point.min(ans, dp[N * N - 1][2]);\n\n\n out.print(ans.toString());\n }\n\n private static class Point {\n int x;\n int y;\n\n private Point(int x, int y) {\n this.x = x;\n this.y = y;\n }\n\n public static DTriFiguri.Point of(int x, int y) {\n return new DTriFiguri.Point(x, y);\n }\n\n public static int hash(int x, int y, int p) {\n return x * N * 3 + y * 3 + p;\n }\n\n public static DTriFiguri.Point min(DTriFiguri.Point a, DTriFiguri.Point b) {\n if (a.x == b.x) {\n return a.y < b.y ? a : b;\n }\n return a.x < b.x ? a : b;\n }\n\n public static DTriFiguri.Point sum(DTriFiguri.Point point1, DTriFiguri.Point point) {\n return DTriFiguri.Point.of(point1.x + point.x, point1.y + point.y);\n }\n\n public String toString() {\n return x + \" \" + y;\n }\n\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String nextToken() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["dfs and similar", "dp", "shortest paths"], "code_uid": "67703a4675ba34d0a4940ebf13e267ac", "src_uid": "5fe44b6cd804e0766a0e993eca1846cd", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "// practice with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF513C extends PrintWriter {\n\tCF513C() { super(System.out, true); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF513C o = new CF513C(); o.main(); o.flush();\n\t}\n\n\tdouble prob(int l, int r, int a) {\n\t\treturn Math.max(r - Math.max(l, a) + 1, 0) / (r - l + 1.0);\n\t}\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tint[] ll = new int[n];\n\t\tint[] rr = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tll[i] = sc.nextInt();\n\t\t\trr[i] = sc.nextInt();\n\t\t}\n\t\tdouble ans = 0;\n\t\tfor (int a = 1; a <= 10000; a++) {\n\t\t\tdouble p = 1;\n\t\t\tfor (int j = 0; j < n; j++)\n\t\t\t\tp *= 1 - prob(ll[j], rr[j], a);\n\t\t\tdouble q = p;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tp = prob(ll[i], rr[i], a);\n\t\t\t\tfor (int j = 0; j < n; j++)\n\t\t\t\t\tif (j != i)\n\t\t\t\t\t\tp *= 1 - prob(ll[j], rr[j], a);\n\t\t\t\tq += p;\n\t\t\t}\n\t\t\tans += 1 - q;\n\t\t}\n\t\tprintf(\"%.9f\\n\", ans);\n\t}\n}\n", "lang_cluster": "Java", "tags": ["probabilities", "bitmasks"], "code_uid": "034427fba43e786a384a3b54ce8e1bac", "src_uid": "5258ce738eb268b9750cfef309d265ef", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastScanner in = new FastScanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskD solver = new TaskD();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n\n\tstatic class TaskD {\n\t\tpublic void solve(int testNumber, FastScanner in, PrintWriter out) {\n\t\t\tlong n = in.nextLong();\n\t\t\tlong inputL = in.nextLong() - 1;\n\t\t\tlong inputR = in.nextLong() - 1;\n\t\t\tlong k = in.nextLong();\n\t\t\tlong d = dist(inputL, inputR, n);\n\n\t\t\tfinal long BIG = (long) 3e5;\n\t\t\tlong ans = -1;\n\t\t\tif (n >= BIG) {\n//\t\tif (true) {\n//\t\tif (false) {\n\t\t\t\t// c full circles.\n\t\t\t\tfor (long c = 0; n * c <= k; c++) {\n\t\t\t\t\tlong l = -1;\n\t\t\t\t\tlong r = n + 1;\n\t\t\t\t\twhile (r - l > 1) {\n\t\t\t\t\t\tlong m = l + (r - l) / 2;\n\t\t\t\t\t\tif (canLB(n, k, d, c, m)) {\n\t\t\t\t\t\t\tl = m;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tr = m;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (l >= 0 && canUB(n, k, d, c, l)) {\n\t\t\t\t\t\tans = Math.max(ans, l);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// s sweet lovers.\n\t\t\t\tfor (long s = 0; s <= n; s++) {\n\t\t\t\t\tlong minC = 0;\n\t\t\t\t\tlong maxC = 0;\n\t\t\t\t\t{\n\t\t\t\t\t\tlong b = Math.min(d, n - s);\n\t\t\t\t\t\tlong a = d - b;\n\t\t\t\t\t\tlong p = k - a - d;\n\t\t\t\t\t\tif (a > 0) {\n\t\t\t\t\t\t\t++p;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (p < 0) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tmaxC = p / (n + s);\n\t\t\t\t\t}\n\t\t\t\t\t{\n\t\t\t\t\t\tlong a = Math.min(d, s);\n\t\t\t\t\t\tlong b = d - a;\n\t\t\t\t\t\tlong p = k - a - d;\n\t\t\t\t\t\tp += n + s - 1;\n\t\t\t\t\t\tif (p < 0) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tminC = p / (n + s);\n\t\t\t\t\t}\n\t\t\t\t\tif (minC <= maxC) {\n\t\t\t\t\t\tans = Math.max(ans, s);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tout.println(ans);\n\t\t}\n\n\t\tprivate boolean canLB(long n, long k, long d, long c, long s) {\n\t\t\tlong minK = -1;\n\t\t\tlong b = Math.min(d, n - s);\n\t\t\tlong a = d - b;\n\t\t\tminK = (n + s) * c + d + a;\n\t\t\tif (a > 0 && minK > 0) {\n\t\t\t\t// Last \"a\" takes one.\n\t\t\t\t--minK;\n\t\t\t}\n\t\t\treturn k >= minK;\n\t\t}\n\n\t\tprivate boolean canUB(long n, long k, long d, long c, long s) {\n\t\t\tlong maxK = -1;\n\t\t\tlong a = Math.min(d, s);\n\t\t\tlong b = d - a;\n\t\t\tmaxK = (n + s) * c + d + a;\n\t\t\treturn k <= maxK;\n\t\t}\n\n\t\tprivate long dist(long l, long r, long n) {\n\t\t\twhile (r < l) {\n\t\t\t\tr += n;\n\t\t\t}\n\t\t\treturn r - l + 1;\n\t\t}\n\n\t}\n\n\tstatic class FastScanner {\n\t\tprivate BufferedReader in;\n\t\tprivate StringTokenizer st;\n\n\t\tpublic FastScanner(InputStream stream) {\n\t\t\tin = new BufferedReader(new InputStreamReader(stream));\n\t\t}\n\n\t\tpublic String next() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tString rl = in.readLine();\n\t\t\t\t\tif (rl == null) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\tst = new StringTokenizer(rl);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t}\n}\n\n", "lang_cluster": "Java", "tags": ["brute force", "math"], "code_uid": "f280a9d0ab2ac32ebbb75f5064191fad", "src_uid": "f54cc281033591315b037a400044f1cb", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.List;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.util.Collections;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastScanner in = new FastScanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n final int MAX_N = 101_000;\n @SuppressWarnings(\"uncheked\")\n ArrayList[] divs = new ArrayList[MAX_N];\n long modulo;\n\n public void solve(int testNumber, FastScanner in, PrintWriter out) {\n init();\n int n = in.nextInt();\n int m = in.nextInt();\n long L = in.nextInt();\n long R = in.nextInt();\n modulo = in.nextInt();\n long res = 0;\n for (long dx = 1; dx <= n; dx++) {\n long low = L * L - dx * dx;\n long high = R * R - dx * dx;\n if (low < 0)\n low = 0;\n if (high < 0)\n continue;\n long left = (int)Math.sqrt(low);\n long right = (int)Math.sqrt(high);\n while (left > 0 && left * left + dx * dx >= L * L)\n left--;\n while (left * left + dx * dx < L * L)\n left++;\n left--;\n while (right > 0 && right * right + dx * dx >= R * R)\n right--;\n while (right * right + dx * dx <= R * R)\n right++;\n right--;\n if (left < 0)\n left = 0;\n if (right > m)\n right = m;\n if (left >= right)\n continue;\n long cntR = right - getCount((int)dx, (int)right);\n long cntL = left - getCount((int)dx, (int)left);\n long cnt = cntR - cntL;\n cnt %= modulo;\n cnt += modulo;\n cnt %= modulo;\n long sumR = right * (right + 1) / 2 - getSum((int)dx, (int)right);\n long sumL = left * (left + 1) / 2 - getSum((int)dx, (int)left);\n long sum = sumR - sumL;\n sum = cnt * (m + 1) % modulo - sum;\n sum %= modulo;\n sum += modulo;\n sum %= modulo;\n res += (2 * sum * (n - dx + 1)) % modulo;\n res %= modulo;\n }\n if (L <= 1)\n res += (n + 1) * 1L * m + n * 1L * (m + 1);\n out.println(res % modulo);\n }\n\n void init() {\n for (int i = 1; i < MAX_N; i++) {\n divs[i] = new ArrayList<>();\n divs[i].add(1);\n }\n for (int i = 2; i < MAX_N; i++)\n for (int j = i; j < MAX_N; j += i)\n divs[j].add(i);\n for (int i = 1; i < MAX_N; i++)\n Collections.reverse(divs[i]);\n }\n\n long getCount(int n, int R) {\n if (n == 1)\n return 0L;\n if (R <= 1)\n return 0L;\n int cnt = divs[n].size();\n int[] with = new int[cnt];\n long res = 0;\n for (int i = 0; i < cnt - 1; i++) {\n int cur = divs[n].get(i);\n with[i] += R / cur;\n res += with[i];\n for (int j = cnt - 1; j >= 0 && divs[n].get(j) < cur; j--)\n if (cur % divs[n].get(j) == 0)\n with[j] -= with[i];\n }\n return res;\n }\n\n long getSum(int n, int R) {\n if (R <= 1)\n return 0L;\n if (n == 1)\n return 0L;\n int cnt = divs[n].size();\n long[] with = new long[cnt];\n long res = 0;\n for (int i = 0; i < cnt - 1; i++) {\n int cur = divs[n].get(i);\n with[i] += R / cur * 1L * (R / cur + 1) / 2 * cur;\n res += with[i];\n for (int j = cnt - 1; j >= 0 && divs[n].get(j) < cur; j--)\n if (cur % divs[n].get(j) == 0)\n with[j] -= with[i];\n }\n return res;\n }\n}\n\nclass FastScanner {\n BufferedReader reader;\n StringTokenizer tokenizer;\n\n public FastScanner(InputStream inputStream) {\n reader = new BufferedReader(new InputStreamReader(inputStream));\n }\n\n public String nextToken() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n String line;\n try {\n line = reader.readLine();\n } catch (IOException e) {\n return null;\n }\n tokenizer = new StringTokenizer(line);\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n }\n\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "56107389d52d86beb4c612ea91407f69", "src_uid": "2afe29a7dbbd2e261e1870a43d57b46f", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigDecimal;\nimport java.math.MathContext;\nimport java.math.RoundingMode;\nimport java.text.DecimalFormat;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.stream.IntStream;\n\npublic class d {\n public static void main(String[] args) {\n FS in = new FS(System.in);\n PrintWriter out = new PrintWriter(System.out);\n \n new d().solve(in, out);\n \n out.close();\n }\n \n public void solve(FS in, PrintWriter out) {\n int x1 = in.nextInt();\n int x2 = in.nextInt();\n int d = x2-x1;\n int a = in.nextInt();\n int b = in.nextInt();\n if(Integer.signum(a) != Integer.signum(b)) {\n if(d >= a && d <= b) {\n System.out.println(\"FIRST\");\n System.out.println(x2);\n } else {\n System.out.println(\"DRAW\");\n }\n return;\n }\n int has = 1;\n if(a < 0) {\n a *= -1;\n b *= -1;\n d *= -1;\n has *= -1;\n a ^= b;\n b ^= a;\n a ^= b;\n }\n if(b == 0) {\n System.out.println(\"DRAW\");\n return;\n }\n if(d < 0) {\n System.out.println(\"DRAW\");\n return;\n }\n \n if(d%(a+b) == 0) {\n System.out.println(\"SECOND\");\n return;\n }\n \n if(d%(a+b) < a || d%(a+b) > b) {\n System.out.println(\"DRAW\");\n return;\n }\n \n System.out.println(\"FIRST\");\n System.out.println(x1+has*(d%(a+b)));\n }\n \n static class FS {\n\n BufferedReader in;\n StringTokenizer token;\n \n public FS(InputStream str) {\n in = new BufferedReader(new InputStreamReader(str));\n }\n \n public String next() {\n if (token == null || !token.hasMoreElements()) {\n try {\n token = new StringTokenizer(in.readLine());\n } catch (IOException ex) {\n }\n return next();\n }\n return token.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}", "lang_cluster": "Java", "tags": ["math", "games"], "code_uid": "c4a645adcccae658321f56262a385120", "src_uid": "4ea8cc3305a0ee2c1e580b43e5bc46c6", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/**\n * BaZ :D\n */\nimport java.util.*;\nimport java.io.*;\nimport static java.lang.Math.*;\npublic class ACMIND\n{\n static FastReader scan;\n static PrintWriter pw;\n static long MOD = 1_000_000_007;\n static long INF = 1_000_000_000_000_000_000L;\n static long inf = 2_000_000_000;\n public static void main(String[] args) {\n new Thread(null,null,\"BaZ\",1<<25)\n {\n public void run()\n {\n try\n {\n solve();\n }\n catch(Exception e)\n {\n e.printStackTrace();\n System.exit(1);\n }\n }\n }.start();\n }\n static int n, g[], t[], T;\n static int dp[][];\n static void solve() throws IOException\n {\n scan = new FastReader();\n pw = new PrintWriter(System.out,true);\n StringBuilder fast = new StringBuilder();\n n = ni();\n T = ni();\n g = new int[n];\n t = new int[n];\n for(int i=0;i=t[i]) {\n cnt+=f(mask^(1<=MOD) {\n cnt-=MOD;\n }\n }\n }\n }\n return dp[mask][prev] = cnt;\n }\n static int ni() throws IOException\n {\n return scan.nextInt();\n }\n static long nl() throws IOException\n {\n return scan.nextLong();\n }\n static double nd() throws IOException\n {\n return scan.nextDouble();\n }\n static void pl()\n {\n pw.println();\n }\n static void p(Object o)\n {\n pw.print(o+\" \");\n }\n static void pl(Object o)\n {\n pw.println(o);\n }\n static void psb(StringBuilder sb)\n {\n pw.print(sb);\n }\n static void pa(String arrayName, Object arr[])\n {\n pl(arrayName+\" : \");\n for(Object o : arr)\n p(o);\n pl();\n }\n static void pa(String arrayName, int arr[])\n {\n pl(arrayName+\" : \");\n for(int o : arr)\n p(o);\n pl();\n }\n static void pa(String arrayName, long arr[])\n {\n pl(arrayName+\" : \");\n for(long o : arr)\n p(o);\n pl();\n }\n static void pa(String arrayName, double arr[])\n {\n pl(arrayName+\" : \");\n for(double o : arr)\n p(o);\n pl();\n }\n static void pa(String arrayName, char arr[])\n {\n pl(arrayName+\" : \");\n for(char o : arr)\n p(o);\n pl();\n }\n static void pa(String listName, List list)\n {\n pl(listName+\" : \");\n for(Object o : list)\n p(o);\n pl();\n }\n static void pa(String arrayName, Object[][] arr) {\n pl(arrayName+\" : \");\n for(int i=0;i= '0' && c <= '9');\n if (neg) return -ret;\n return ret;\n }\n\n public long nextLong() throws IOException {\n long ret = 0;\n byte c = read();\n while (c <= ' ') c = read();\n boolean neg = (c == '-');\n if (neg) c = read();\n do {\n ret = ret * 10 + c - '0';\n } while ((c = read()) >= '0' && c <= '9');\n if (neg) return -ret;\n return ret;\n }\n\n public double nextDouble() throws IOException {\n double ret = 0, div = 1;\n byte c = read();\n while (c <= ' ') c = read();\n boolean neg = (c == '-');\n if (neg) c = read();\n do {\n ret = ret * 10 + c - '0';\n } while ((c = read()) >= '0' && c <= '9');\n if (c == '.') while ((c = read()) >= '0' && c <= '9') ret += (c - '0') / (div *= 10);\n if (neg) return -ret;\n return ret;\n }\n\n private void fillBuffer() throws IOException {\n bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n if (bytesRead == -1) buffer[0] = -1;\n }\n\n private byte read() throws IOException {\n if (bufferPointer == bytesRead) fillBuffer();\n return buffer[bufferPointer++];\n }\n\n public void close() throws IOException {\n if (din == null) return;\n din.close();\n }\n }\n}", "lang_cluster": "Java", "tags": ["dp", "combinatorics", "bitmasks"], "code_uid": "bbf01f07ada9f301ff1104f643f28e6d", "src_uid": "ac2a37ff4c7e89a345b189e4891bbf56", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\n\n/**\n * Codeforces Beta Round #72 (Div. 1 Only), D\n * @author Roman Kosenko \n */\npublic class Main {\n\tpublic static void main(String... args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tString[] ss = br.readLine().split(\" \");\n\t\tint a = Integer.parseInt(ss[0]), b = Integer.parseInt(ss[1]), k = Integer.parseInt(ss[2]), result = !Utils.isPrime(k) ? 0 : solve(a, b, k);\n\t\tSystem.out.println(result);\n\t}\n\tprivate static int primes[];\n\tprivate static int solve(int a, int b, int k) {\n\t\tfinal int start = (a - 1) / k + 1, end = b / k;\n\t\tif(end < start)\n\t\t\treturn 0;\n\t\tif(start == 1 && end == 1)\n\t\t\treturn 1;\n\t\tif(primes == null)\n\t\t\tprimes = Utils.primes(Math.min(k - 1, end), 0);\n\t\tint result = end - start + 1;\n\t\tfor(int i = 0; i < primes.length && primes[i] < k; i++)\n\t\t\tresult -= solve(start, end, primes[i]);\n\t\treturn result;\n\t}\n}\n/**\n * @author Roman Kosenko \n */\nabstract class Utils {\n\tpublic static boolean isPrime(int x) {\n\t\tif(x <= 2)\n\t\t\treturn true;\n\t\tif((x & 1) == 0)\n\t\t\treturn false;\n\t\tint hi = (int)Math.sqrt(x);\n\t\tfor(int i = 3; i <= hi; i += 2) {\n\t\t\tif(x % i == 0)\n\t\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\tpublic static int[] primes(int m, int n) {\n\t\tboolean[] primes = new boolean[m + 1];\n\t\tint count = 0;\n\t\tfor(int i = 2; i <= m; i++) {\n\t\t\tif(!primes[i]) {\n\t\t\t\tfor(int j = i * 2; j <= m; j += i)\n\t\t\t\t\tprimes[j] = true;\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\t\tint result[] = new int[n > 0 ? Math.min(n, count) : count];\n\t\tfor(int i = 0, j = 2; i < result.length && j <= m; j++) {\n\t\t\tif(!primes[j])\n\t\t\t\tresult[i++] = j;\n\t\t}\n\t\treturn result;\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "dp", "number theory"], "code_uid": "887adb7dc64a53e9e81cc7c77aafb4d3", "src_uid": "04a26f1d1013b6e6b4b0bdcf225475f2", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class Solution {\n public static void main(String[] args) throws IOException{\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer st = new StringTokenizer(br.readLine());\n long a = Long.parseLong(st.nextToken());\n long b = Long.parseLong(st.nextToken());\n int p = Integer.parseInt(st.nextToken());\n long x = Long.parseLong(st.nextToken());\n long[] inverse = new long[p];\n inverse[p - 1] = b;\n for(int i = p - 2; i >= 0; i--){\n inverse[i] = (inverse[i + 1] * a) % p;\n }\n //System.out.println(inverse[0]);\n long result = 0;\n for(int i = 0; i < p - 1; i++){\n int start = (i - (int)inverse[i] + p) % p;\n long first = start * ((long)(p - 1)) + i;\n if(x >= first)\n result += ((x - first) / ((long)p * (p - 1)) + 1);\n }\n System.out.println(result);\n }\n}", "lang_cluster": "Java", "tags": ["math", "number theory"], "code_uid": "74b28d2b394cf6383a3d73d611aaeaff", "src_uid": "4b9f470e5889da29affae6376f6c9f6a", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class LuckyTickets {\n // 2^23*7*17+1\n private static final int MOD = 998244353;\n // ROOT^(2^23)=1 & ROOT^(2^22)!=1\n private static final int ROOT = 15311432;\n private static final int INVROOT = 469870224;\n\n private static int bitReverse(int n, int k) {\n return Integer.reverse(n) >>> (32 - k);\n }\n\n private static long modInv(int a) {\n return modPow(a, MOD - 2);\n }\n\n private static long modPow(int a, int p) {\n if (p == 0) {\n return 1;\n }\n long half = modPow(a, p / 2);\n long ans = (half * half) % MOD;\n if (p % 2 == 1) {\n ans = (ans * a) % MOD;\n }\n return ans;\n }\n\n // my first fft, LETS DO THIS!!\n // coef.length = 2^k\n private static void numberTheoreticTransform(long[] coef, int k, boolean inverse) {\n int baseRoot = inverse ? INVROOT : ROOT;\n long root = modPow(baseRoot, (int) modPow(2, 23 - k));\n long[] roots = new long[k];\n roots[k - 1] = root;\n for (int i = k - 1; i > 0; i--) {\n roots[i - 1] = (roots[i] * roots[i]) % MOD;\n }\n for (int s = 0; s < k; s++) {\n int len = 1 << s;\n for (int st = 0; st < coef.length; st += 2 * len) {\n // combine the vectors starting at st and st + len\n long curRoot = 1;\n for (int j = st; j < st + len; j++) {\n long t = (curRoot * coef[j + len]) % MOD;\n long u = coef[j];\n coef[j] = (u + t) % MOD;\n coef[j + len] = (u - t) % MOD;\n curRoot = (roots[s] * curRoot) % MOD;\n }\n }\n }\n return;\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt() / 2;\n int m = sc.nextInt();\n int[] nums = new int[m];\n for (int i = 0; i < m; i++) {\n nums[i] = sc.nextInt();\n }\n Arrays.sort(nums);\n int min_size = n * nums[m - 1] + 2;\n int k = 0;\n int size = 1;\n while (size < min_size) {\n size *= 2;\n k++;\n }\n long[] a = new long[size];\n for (int i = 0; i < nums.length; i++) {\n a[bitReverse(nums[i], k)] = 1;\n }\n numberTheoreticTransform(a, k, false);\n for (int i = 0; i < size; i++) {\n a[i] = modPow((int) a[i], n);\n }\n long[] temp = new long[size];\n for (int i = 0; i < size; i++) {\n temp[bitReverse(i, k)] = (a[i]) % MOD;\n }\n a = temp;\n numberTheoreticTransform(a, k, true);\n long ans = 0;\n for (int i = 0; i < size; i++) {\n ans = (ans + a[i] * a[i]) % MOD;\n }\n long multiplier = modInv(size);\n System.out.println((((ans * multiplier) % MOD) * multiplier) % MOD);\n }\n}\n", "lang_cluster": "Java", "tags": ["divide and conquer", "dp", "fft"], "code_uid": "1afca2c9f77d6b58561fa8dd1eb0e719", "src_uid": "279f1f7d250a4be6406c6c7bfc818bbf", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n private FastScanner in;\n private PrintWriter out;\n\n private void solve() {\n String f0 = \"What are you doing at the end of the world? Are you busy? Will you save us?\";\n final int MAX = (int) 1e5 + 10;\n long[] size = new long[MAX];\n size[0] = f0.length();\n String add0 = \"What are you doing while sending \\\"\";\n String add1 = \"\\\"? Are you busy? Will you send \\\"\";\n String add2 = \"\\\"?\";\n long inf = (long) 1e18 + 100;\n int a0 = add0.length(), a1 = add1.length(), a2 = add2.length();\n for (int i = 1; i < MAX; i++) {\n size[i] = a0 + a1 + a2 + size[i - 1] * 2;\n size[i] = Math.min(size[i], inf);\n }\n int q = in.nextInt();\n for (int i = 0; i < q; i++) {\n int n = in.nextInt();\n long k = in.nextLong() - 1;\n boolean f = false;\n while (n > 0) {\n if (k < a0) {\n out.print(add0.charAt((int) k));\n f = true;\n break;\n }\n k -= a0;\n if (k < size[n - 1]) {\n n--;\n continue;\n }\n k -= size[n - 1];\n if (k < a1) {\n out.print(add1.charAt((int) k));\n f = true;\n break;\n }\n k -= a1;\n if (k < size[n - 1]) {\n n--;\n continue;\n }\n k -= size[n - 1];\n if (k >= a2) {\n out.print(\".\");\n f = true;\n break;\n }\n out.print(add2.charAt((int) k));\n f = true;\n break;\n }\n if (f) {\n continue;\n }\n if (n == 0) {\n out.print(k >= f0.length() ? \".\" : f0.charAt((int) k));\n }\n }\n }\n\n private void run() {\n try {\n in = new FastScanner(new File(\"A.in\"));\n out = new PrintWriter(new File(\"A.out\"));\n\n solve();\n\n out.close();\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n\n private void runIO() {\n in = new FastScanner(System.in);\n out = new PrintWriter(System.out);\n\n solve();\n\n out.close();\n }\n\n private class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n FastScanner(File f) {\n try {\n br = new BufferedReader(new FileReader(f));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n\n FastScanner(InputStream f) {\n br = new BufferedReader(new InputStreamReader(f));\n }\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return null;\n st = new StringTokenizer(s);\n }\n return st.nextToken();\n }\n\n boolean hasMoreTokens() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return false;\n st = new StringTokenizer(s);\n }\n return true;\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n\n public static void main(String[] args) {\n new A().runIO();\n }\n}", "lang_cluster": "Java", "tags": ["dfs and similar", "binary search"], "code_uid": "136998f1e837c90ae6c316b6816cf300", "src_uid": "da09a893a33f2bf8fd00e321e16ab149", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.PriorityQueue;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.AbstractCollection;\nimport java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.util.Comparator;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n DPriganieLyagushki solver = new DPriganieLyagushki();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class DPriganieLyagushki {\n\n static final int N = (int) 2e5;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int m = in.nextInt();\n int a = in.nextInt();\n int b = in.nextInt();\n int[] earliest = new int[N + 1];\n Arrays.fill(earliest, -1);\n earliest[0] = 0;\n PriorityQueue queue = new PriorityQueue<>(Comparator.comparingInt(x -> earliest[x]));\n queue.add(0);\n while (!queue.isEmpty()) {\n int val = queue.poll();\n if (val + a <= N && earliest[val + a] == -1) {\n earliest[val + a] = Math.max(val + a, earliest[val]);\n queue.add(val + a);\n }\n if (val > b && earliest[val - b] == -1) {\n earliest[val - b] = earliest[val];\n queue.add(val - b);\n }\n }\n long ans = 0;\n for (int i = 0; i < a; i++) {\n if (m < earliest[i] || earliest[i] == -1) {\n continue;\n }\n ans += ((earliest[i] * 1L - i) / a + 1) * (m - earliest[i] * 1L + 1);\n long st = i + ((earliest[i] * 1L - i) / a + 1) * a;\n if (st > m) {\n continue;\n }\n long ct = (m * 1L - st) / a + 1;\n ans += (m - st + 1) * ct - (ct - 1) * ct / 2 * a;\n }\n out.println(ans);\n }\n }\n\n static class InputReader {\n\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}\n\n", "lang_cluster": "Java", "tags": ["dfs and similar", "math", "number theory"], "code_uid": "77d4446785d3f9b32370deb414395c6d", "src_uid": "d6290b69eddfcf5f131cc9e612ccab76", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/*\nIf you want to aim high, aim high\nDon't let that studying and grades consume you\nJust live life young\n******************************\nIf I'm the sun, you're the moon\nBecause when I go up, you go down\n*******************************\nI'm working for the day I will surpass you\nhttps://www.a2oj.com/Ladder16.html\n*/\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\n\n public class x1204E\n {\n static long MOD = 998244853L;\n public static void main(String omkar[]) throws Exception\n {\n BufferedReader infile = new BufferedReader(new InputStreamReader(System.in)); \n StringTokenizer st = new StringTokenizer(infile.readLine());\n int N = Integer.parseInt(st.nextToken());\n int M = Integer.parseInt(st.nextToken());\n fac = new long[4001];\n invfac = new long[4001];\n fac[0] = invfac[0] = 1L;\n for(int i=1; i <= 4000; i++)\n {\n fac[i] = (fac[i-1]*i)%MOD;\n invfac[i] = power(fac[i], MOD-2, MOD);\n }\n long[][] zero = new long[N+1][M+1];\n Arrays.fill(zero[0], 1L);\n for(int a=1; a <= N; a++)\n for(int b=a; b <= M; b++)\n zero[a][b] = (zero[a-1][b]+zero[a][b-1])%MOD;\n long[][] dp = new long[N+1][M+1];\n for(int a=0; a <= N; a++)\n dp[a][0] = a;\n for(int a=1; a <= N; a++)\n for(int b=1; b <= M; b++)\n {\n long temp = (dp[a-1][b]+dp[a][b-1])%MOD;\n temp = (temp+cnt(a-1,b)-cnt(a,b-1)+MOD)%MOD;\n dp[a][b] = (temp+zero[a][b-1])%MOD;\n }\n System.out.println(dp[N][M]);\n }\n static long fac[];\n static long invfac[];\n public static long cnt(int a, int b)\n {\n long val = fac[a+b];\n val = (val*invfac[a])%MOD;\n return (val*invfac[b])%MOD;\n }\n public static long power(long x, long y, long p) \n { \n long res = 1L; \n x = x % p; \n while (y > 0) \n { \n if((y & 1)==1) \n res = (res * x) % p; \n y = y >> 1; \n x = (x * x) % p; \n } \n return res; \n } \n }", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics", "number theory"], "code_uid": "4234fe35723e947ce516646bd9ac5046", "src_uid": "a2fcad987e9b2bb3e6395654cd4fcfbb", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "//package codeforces.cfr330div2;\n\nimport java.io.*;\nimport java.util.StringTokenizer;\nimport java.util.function.Function;\n\n/**\n * Created by raggzy on 27-Jan-16.\n */\npublic class D {\n private static class Reader implements Closeable {\n private BufferedReader br;\n private StringTokenizer st;\n\n public Reader(InputStream is) {\n br = new BufferedReader(new InputStreamReader(is));\n }\n\n public void readLine() {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n\n public String next() {\n if (st == null || !st.hasMoreTokens()) {\n readLine();\n }\n return st.nextToken();\n }\n\n public T next(Function parser) {\n return parser.apply(next());\n }\n\n public int nextInt() {\n return next(Integer::valueOf);\n }\n\n public long nextLong() {\n return next(Long::valueOf);\n }\n\n public double nexDouble() {\n return next(Double::valueOf);\n }\n\n @Override\n public void close() throws IOException {\n br.close();\n }\n }\n\n public static final double TEPS = 0.0000005;\n\n private static double findT(int s, int f, int r, int v, double a0) {\n double halfDist = (f - s) / 2.0;\n double halfDistDivV = halfDist / v;\n final double VdivR = 1.0 * v / r;\n final double RDivV = 1.0 * r / v;\n double targetX = r * Math.cos(a0) + halfDist;\n double angleRange = 2 * Math.PI * RDivV;\n double tLeft = halfDistDivV - angleRange;\n double tRight = halfDistDivV + angleRange;\n while (tRight - tLeft >= TEPS * Math.max(1.0, tLeft)) {\n double tMid = (tLeft + tRight) / 2;\n if (tMid * v + Math.cos(a0 + tMid * VdivR) * r > targetX) {\n tRight = tMid;\n } else {\n tLeft = tMid;\n }\n }\n return 2 * tLeft;\n }\n\n private static double findT(int s, int f, int r, int v) {\n return Math.min(findT(s, f, r, v, Math.PI / 2), findT(s, f, r, v, 3 * Math.PI / 2));\n }\n\n public static void main(String[] args) throws FileNotFoundException {\n// Scanner in = new Scanner(new File(\"C:/Temp/test.out\"));\n// PrintStream out = new PrintStream(new File(\"C:/Temp/test2.out\"));\n Reader in = new Reader(System.in);\n PrintStream out = System.out;\n int n = in.nextInt();\n int r = in.nextInt();\n int v = in.nextInt();\n for (int i = 0; i < n; i++) {\n out.println(findT(in.nextInt(), in.nextInt(), r, v));\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["geometry"], "code_uid": "679e6244aa516bbe1e7057f8f84ae7b5", "src_uid": "3882f2c02e83bd2d55de8004ea3bbd88", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "//package round85;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class D {\n\tScanner in;\n\tPrintWriter out;\n\tString INPUT = \"3 2 2\";\n\tint mod = 1000000007;\n\t\n\t// 1\u5217\u306e\u5834\u5408\u306f\u306a\u3093\u3067\u3082\u3042\u308a\u306a\u306e\u3067k^n\n\t// 2\u5217\u306e\u5834\u5408\u306f\u3069\u3063\u3061\u3082\u540c\u3058i\u8272\u3067\u3042\u308c\u3070\u3044\u3044\u306e\u3067\u3001\n\t// \\sum_i (C(k,i)F(n,i))^2\n\t// 3\u5217\u4ee5\u4e0a\u306e\u5834\u5408\u306f\u4e21\u7aef\u304c\u5171\u901a\u90e8\u5206\u30921\u8272\u4ee5\u4e0a\u6301\u3064\u540c\u3058\u8272\u6570\u306e\u914d\u8272\u3001\u771f\u3093\u4e2d\u306f\u305d\u306e\u8272\u5185\u306a\u3089\u306a\u3093\u3067\u3082\u3088\u3044\u3002\n\t// |A|<=|A\\cup C|=|B|, |B|<=|B\\cup C|=|A|\n\t// |A|=|B|, C\\in A\\cup B\n\t// \\sum_i (F(n,i)^2)\\sum_p=1^i C(k,p)p^{n(m-2)}C(k-p,i-p)C(k-i,i-p)\n\t// C(k,p)C(k-p,i-p)C(k-i,i-p)\n\t// =k!/p!(i-p)!(k-2i+p)!(i-p)!\n\t// F(n,i)\u306fn\u884c\u3092\u3061\u3087\u3046\u3069i\u8272\u3067\u5857\u308b\u5857\u308a\u65b9\n\t// F(n,i)=i^n-C(i,1)(i-1)^n+C(i,2)(i-2)^n-...\n\t// \u3053\u308c\u3092\u6c42\u3081\u308b\u306e\u306bO(i)\n\t// \u5168\u4f53\u3067O(k^2)\u304b\u304b\u3063\u3066\u3057\u307e\u3046\u306e\u3067\u666e\u901a\u306e\u8a08\u7b97\u3067\u306f\u9593\u306b\u5408\u308f\u306a\u3044\u3002\n\t// \n\t// \n\t\n\tvoid solve()\n\t{\n\t\tint n = ni();\n\t\tint m = ni();\n\t\tint K = ni();\n\t\t\n\t\tint q = Math.max(K, n);\n\t\tlong[] A = new long[q+1];\n\t\tlong[] IA = new long[q+1];\n\t\tA[0] = 1;\n\t\tIA[0] = 1;\n\t\tfor(int i = 1;i <= q;i++){\n\t\t\tA[i] = A[i-1] * i % mod;\n\t\t\tIA[i] = inv(A[i], mod);\n\t\t}\n\t\t\n\t\tlong[] I = new long[1001];\n\t\tlong[] IM = new long[1001];\n\t\tfor(int i = 0;i <= 1000;i++){\n\t\t\tI[i] = modpow(i, n, mod);\n\t\t\tIM[i] = modpow(i, n*(m-2), mod);\n\t\t}\n\t\t\n\t\t// F(n,i)=i^n-C(i,1)(i-1)^n+C(i,2)(i-2)^n-...\n\t\tlong[] F = new long[n+1];\n\t\tfor(int i = 0;i <= n;i++){\n\t\t\tlong val = 0;\n\t\t\tlong minus = 1;\n\t\t\tfor(int j = i;j >= 0;j--){\n\t\t\t\tval += I[j] * minus * A[i]%mod*IA[i-j]%mod*IA[j] % mod;\n\t\t\t\tminus = -minus;\n\t\t\t}\n\t\t\tF[i] = (val%mod+mod)%mod;\n\t\t}\n\t\t\n\t\tif(m == 1){\n\t\t\tout.println(modpow(K, n, mod));\n\t\t}else if(m == 2){\n\t\t\tlong sum = 0;\n\t\t\tfor(int i = 1;i <= Math.min(K, n);i++){\n\t\t\t\tlong cfm = A[K]*IA[i]%mod*IA[K-i]%mod*F[i]%mod;\n\t\t\t\tsum += cfm*cfm%mod;\n\t\t\t}\n\t\t\tout.println(sum%mod);\n\t\t}else{\n\t\t\tlong sum = 0;\n\t\t\t// \\sum_i (F(n,i)^2)\\sum_p=1^i C(k,p)p^{n(m-2)}C(k-p,i-p)C(k-i,i-p)\n\t\t\t// =k!/p!(i-p)!(k-2i+p)!(i-p)!\n\t\t\tfor(int i = 1;i <= Math.min(K, n);i++){\n\t\t\t\tlong psum = 0;\n\t\t\t\tfor(int p = 1;p <= i;p++){\n\t\t\t\t\tif(K-2*i+p >= 0){\n\t\t\t\t\t\tpsum += A[K]*IA[p]%mod*IA[i-p]%mod*IA[i-p]%mod*IA[K-2*i+p]%mod*IM[p]%mod;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tpsum%=mod;\n\t\t\t\tlong all = F[i]*F[i]%mod*psum%mod;\n\t\t\t\tsum += all;\n\t\t\t}\n\t\t\tout.println(sum%mod);\n\t\t}\n\t}\n\t\n\tpublic static long inv(long a, int p)\n\t{\n\t\tlong ret = 1;\n\t\tlong mul = a;\n\t\tfor(long n = p-2;n > 0;n >>>= 1){\n\t\t\tif((n&1)==1)ret = ret * mul % p;\n\t\t\tmul = mul * mul % p;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tpublic static long modpow(long a, long n, long mod)\n\t{\n\t\tlong ret = 1;\n\t\tlong mul = a;\n\t\tfor(;n > 0;n >>>= 1){\n\t\t\tif((n&1)==1){\n\t\t\t\tret = (ret * mul) % mod;\n\t\t\t}\n\t\t\tmul = (mul * mul) % mod;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tin = oj ? new Scanner(System.in) : new Scanner(INPUT);\n\t\tout = new PrintWriter(System.out);\n\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tnew D().run();\n\t}\n\t\n\tint ni() { return Integer.parseInt(in.next()); }\n\tlong nl() { return Long.parseLong(in.next()); }\n\tdouble nd() { return Double.parseDouble(in.next()); }\n\tboolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tvoid tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "tags": ["dp", "combinatorics"], "code_uid": "31b57149d350352f82eb44aa32532bf7", "src_uid": "f22f28e2d8933f4199ba5ccfc0de8cda", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.BigInteger;\nimport java.util.Collections.*;\nimport static java.lang.Math.*;\nimport static java.lang.Math.max;\nimport static java.lang.Math.min;\nimport static java.util.Arrays.*;\nimport static java.math.BigInteger.*;\n\n\npublic class Main{\n\n void run(){\n Locale.setDefault(Locale.US);\n boolean my;\n try {\n my = System.getProperty(\"MY_LOCAL\") != null;\n } catch (Exception e) {\n my = false;\n\n }\n try{\n err = System.err;\n if( my ){\n sc = new FastScanner(new BufferedReader(new FileReader(\"input.txt\")));\n// sc = new FastScanner(new BufferedReader(new FileReader(\"C:\\\\myTest.txt\")));\n out = new PrintWriter (new FileWriter(\"output.txt\"));\n }\n else {\n sc = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));\n out = new PrintWriter(new OutputStreamWriter(System.out));\n }\n// out = new PrintWriter(new OutputStreamWriter(System.out));\n }catch(Exception e){\n MLE();\n }\n if( my )\n tBeg = System.currentTimeMillis();\n solve();\n if( my )\n err.println( \"TIME: \" + (System.currentTimeMillis() - tBeg ) / 1e3 );\n exit(0);\n }\n\n void exit( int val ){\n err.flush();\n out.flush();\n System.exit(val);\n }\n\n double tBeg;\n FastScanner sc;\n PrintWriter out;\n PrintStream err;\n\n class FastScanner{\n\n StringTokenizer st;\n BufferedReader br;\n\n FastScanner( BufferedReader _br ){\n br = _br;\n }\n\n String readLine(){\n try {\n return br.readLine();\n } catch (IOException e) {\n return null;\n }\n }\n\n String next(){\n while( st==null || !st.hasMoreElements() )\n st = new StringTokenizer(readLine());\n return st.nextToken();\n }\n\n int nextInt(){ return Integer.parseInt(next()); }\n long nextLong(){ return Long.parseLong(next()); }\n double nextDouble(){ return Double.parseDouble(next()); }\n }\n\n void MLE(){\n int[][] arr = new int[1024*1024][]; for( int i = 0; i < 1024*1024; ++i ) arr[i] = new int[1024*1024];\n }\n\n void MLE( boolean doNotMLE ){ if( !doNotMLE ) MLE(); }\n\n void TLE(){\n for(;;);\n }\n\n public static void main(String[] args) {\n new Main().run();\n// new Thread( null, new Runnable() {\n// @Override\n// public void run() {\n// new Main().run();\n// }\n// }, \"Lolka\", 256_000_000L ).run();\n }\n\n ////////////////////////////////////////////////////////////////\n\n final int mod = (int)1e9 + 7;\n int n, k;\n int[][] dp0, dp1;\n int[] pow2 = new int[600];\n {\n pow2[0] = 1;\n for (int i = 1; i < pow2.length; i++) {\n pow2[i] = (pow2[i-1] * 2) % mod;\n }\n }\n\n void solve(){\n n = sc.nextInt();\n k = sc.nextInt();\n dp0 = new int[k+1][n+1];\n dp1 = new int[k+1][n+1];\n for (int[] val : dp0) fill(val, 0);\n\n for (int sz = 1; sz <= n; sz++) {\n\n for (int cnt = 0; cnt <= k; cnt++) {\n int[] dp1_cnt = dp1[cnt];\n int[] dp1_cnt1 = null; if( cnt+1<=k ) dp1_cnt1 = dp1[cnt+1];\n int[] dp0_cnt = dp0[cnt];\n for (int last = 0; last <= sz; last++) {\n if( cnt == 0 ){\n if( last == 0 ) dp1_cnt[last] = 1;\n else dp1_cnt[last] = 0;\n }\n else if( sz == last ){\n if( cnt == 1 ){\n dp1_cnt[last] = pow2[last] - 1;\n }\n }\n else{\n if( dp0_cnt[last] !=0 )\n dp1_cnt[last] = (int)( (1L * dp0_cnt[last] * pow2[last]) % mod );\n }\n\n if( 1<=last && last <= sz-1 && 1 <= cnt && cnt+1 <= k ){\n if( dp1_cnt[last] != 0 )\n dp1_cnt1[sz] =\n (int)(\n (dp1_cnt1[sz] + 1L*dp1_cnt[last] * (pow2[sz-last]-1)) % mod\n );\n }\n }\n }\n //\n for (int cnt = 0; cnt <= k; cnt++) {\n System.arraycopy( dp1[cnt],0, dp0[cnt],0, dp0[cnt].length );\n fill( dp1[cnt], 0 );\n }\n }\n long ans = 0;\n for (int last = 0; last <= n; last++) {\n ans += dp0[k][last];\n }\n ans %= mod;\n out.println( ans );\n }\n\n\n}", "lang_cluster": "Java", "tags": ["dp"], "code_uid": "7034a79a4cd606d3203901d172d723af", "src_uid": "111673158df2e37ac6c019bb99225ccb", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class project{\n public static void main(String[]args){\n\tScanner s = new Scanner(System.in);\n\tint n = s.nextInt(), k = s.nextInt();\n\tString str = s.nextLine();\n\tstr = s.nextLine();\n\tint ans = 0;\n\tfor (int i = 0; i < n; ++i) {\n\t if (i == 0 || str.charAt(i - 1) != 'N') {\n\t int j = i;\n\t for (j = i; j < n; ++j) {\n\t if (str.charAt(j) == 'Y') {\n\t break;\n\t }\n\t if (j - i == k - 1 && (j + 1 == n || str.charAt(j + 1) != 'N')) {\n\t ans = 1;\n\t }\n\t }\n\t }\n\t}\n\tif (k == 0) {\n\t ans = 1;\n\t}\n\tfor (int i = 0; i < n; ++i) {\n\t for (int j = i; j < n && str.charAt(j) == 'N'; ++j) {\n\t if (j - i == k) {\n\t ans = 0;\n\t }\n\t }\n\t}\n\tif (ans == 1) {\n\t System.out.println(\"YES\");\n\t} else {\n\t System.out.println(\"NO\");\n\t}\n }\n}", "lang_cluster": "Java", "tags": ["dp"], "code_uid": "aac87ddaa81ff275e23c6854e324072b", "src_uid": "5bd578d3da5837c259b222336a194d12", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class CF939_D2_F {\n\tpublic static void main(String[] args)throws Throwable {\n\t\tMyScanner sc=new MyScanner();\n\t\tPrintWriter pw=new PrintWriter(System.out);\n\t\t\n\t\tint n=sc.nextInt()*2;\n\t\tint k=sc.nextInt();\n\t\tint [] l=new int [k+1];\n\t\tint [] r=new int [k+1];\n\t\tSparseTable [][] seg=new SparseTable [2][2];\n\t\tfor(int i=0;i=0;i--){\n\t\t\tfor(int j=0;j<2;j++){\n\t\t\t\tint [] a=new int [n/2+2];\n\t\t\t\tArrays.fill(a, inf);\n\t\t\t\tfor(int c=0;c<=l[i] && cl[i])\n\t\t\t\t\t\tbest=Math.min(best, 2+seg[1-p][j].query(c+l[i+1]-r[i], c+l[i+1]-l[i]-1));\n\t\t\t\t\ta[c]=best;\n\t\t\t\t}\n\t\t\t\tseg[p][j]=new SparseTable(a);\n\t\t\t}\n\t\t\tp^=1;\n\t\t}\n\t\tp^=1;\n\t\tint ans=Math.min(seg[p][0].query(l[0], l[0]), seg[p][1].query(l[0], l[0]));\n\t\tif(ans>2*k)\n\t\t\tpw.println(\"Hungry\");\n\t\telse{\n\t\t\tpw.println(\"Full\");\n\t\t\tpw.println(ans);\n\t\t}\n\t\tpw.flush();\n\t\tpw.close();\n\t}\n\t\n\tstatic int inf=(int)1e7;\n\t\n\tstatic class SparseTable {\n\t\tint [] a;\n\t\tint [][] st;\n\t\t//st[i][j] --> minimum of sub array starting at index i and of length 2^j\n\t\tSparseTable(int [] a){\n\t\t\tint n=a.length;\n\t\t\tthis.a=a;\n\t\t\tint k=(int)Math.floor(Math.log(n)/Math.log(2))+1;\n\t\t\tst=new int [n][k];\n\t\t\tfor(int i=0;i=a.length)\n\t\t\t\treturn inf;\n\t\t\tj=Math.min(j, a.length-1);\n\t\t\tint k=(int)Math.floor(Math.log(j-i+1)/Math.log(2));\n\t\t\treturn Math.min(a[st[i][k]], a[st[j-(1< 0) {\n\t\t\tlong c = a / b;\n\t\t\tlong d;\n\t\t\td = a;\n\t\t\ta = b;\n\t\t\tb = d % b;\n\t\t\td = p;\n\t\t\tp = q;\n\t\t\tq = d - c * q;\n\t\t}\n\t\treturn p < 0 ? p + mod : p;\n\t}\n\t\n\tpublic static long C(int n, int r, int mod, int[][] fif) {\n\t\tif (n < 0 || r < 0 || r > n)\n\t\t\treturn 0;\n\t\treturn (long) fif[0][n] * fif[1][r] % mod * fif[1][n - r] % mod;\n\t}\n\n\n\t\n\tpublic static long[] enumPows(long a, int n, int mod)\n\t{\n\t\ta %= mod;\n\t\tlong[] pows = new long[n+1];\n\t\tpows[0] = 1;\n\t\tfor(int i = 1;i <= n;i++)pows[i] = pows[i-1] * a % mod;\n\t\treturn pows;\n\t}\n\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni();\n\t\t\n\t\tint mod = 998244353;\n\t\tint[][] fif = enumFIF(1000005, mod);\n\t\tlong u = 0;\n\t\tlong i3 = invl(3, mod);\n\t\t\n\t\tlong n3 = pow(3, n, mod);\n\t\tlong[] p3n = enumPows(n3, n+1, mod);\n\t\tlong[] pi3 = enumPows(i3, n+1, mod);\n\t\t\n\t\tfor(int s = 0, sgn = 1;s <= n;s++, sgn = -sgn){\n\t\t\tu += C(n,s, mod, fif)*sgn*p3n[n-s] % mod * pow(1-pi3[n-s], n, mod);\n\t\t\tu %= mod;\n\t\t}\n\t\tu = u * 3 % mod;\n\t\t\n\t\t// n^2-in+1\n\t\tlong[] pi3nm = enumPows(pow(i3, n-1, mod), n+1, mod);\n\t\tlong b = pow(3, (long)n*n, mod);\n\t\tlong[] pi3n = enumPows(pow(i3, n, mod), n+1, mod);\n\t\t// i+(n-i)n = n^2-i(n-1)\n\t\tfor(int i = 1;i <= n;i++){\n\t\t\tlong co = (i % 2 == 0 ? 1 : -1) * C(n, i, mod, fif);\n\t\t\tlong lv = (b*6*pi3n[i] - b*pi3nm[i]*2) % mod;\n\t\t\tu -= co * lv;\n\t\t\tu %= mod;\n\t\t}\n\t\tu -= pow(3, (long)n*n, mod) * 2;\n\t\t\n\t\tu %= mod;\n\t\tlong ans = pow(3, (long)n*n, mod) - u;\n\t\tans %= mod;\n\t\tif(ans < 0)ans += mod;\n\t\tout.println(ans);\n\t}\n\t\n\tpublic static int[][] enumFIF(int n, int mod) {\n\t\tint[] f = new int[n + 1];\n\t\tint[] invf = new int[n + 1];\n\t\tf[0] = 1;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tf[i] = (int) ((long) f[i - 1] * i % mod);\n\t\t}\n\t\tlong a = f[n];\n\t\tlong b = mod;\n\t\tlong p = 1, q = 0;\n\t\twhile (b > 0) {\n\t\t\tlong c = a / b;\n\t\t\tlong d;\n\t\t\td = a;\n\t\t\ta = b;\n\t\t\tb = d % b;\n\t\t\td = p;\n\t\t\tp = q;\n\t\t\tq = d - c * q;\n\t\t}\n\t\tinvf[n] = (int) (p < 0 ? p + mod : p);\n\t\tfor (int i = n - 1; i >= 0; i--) {\n\t\t\tinvf[i] = (int) ((long) invf[i + 1] * (i + 1) % mod);\n\t\t}\n\t\treturn new int[][] { f, invf };\n\t}\n\n\t\n\tpublic static long pow(long a, long n, long mod) {\n\t\ta %= mod;\n\t\tif(a < 0)a += mod;\n\t\tlong ret = 1;\n\t\tint x = 63 - Long.numberOfLeadingZeros(n);\n\t\tfor (; x >= 0; x--) {\n\t\t\tret = ret * ret % mod;\n\t\t\tif (n << 63 - x < 0)\n\t\t\t\tret = ret * a % mod;\n\t\t}\n\t\treturn ret;\n\t}\n\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception { new C4().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "tags": ["math", "combinatorics"], "code_uid": "09335487e7ebf0a27f99d6e184f48577", "src_uid": "6e4b0ee2e1406041a961582ead299a3a", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\nimport static java.util.Arrays.*;\n\npublic class Main {\n\tprivate static final int mod = (int)1e9+7;\n\n\tfinal Random random = new Random(0);\n\tfinal IOFast io = new IOFast();\n\n\t/// MAIN CODE\n\tpublic void run() throws IOException {\n//\t\tif(true) {\n//\t\t\tfor(int i = 1; i <= 20; i++) {\n//\t\t\t\tnaive(i);\n//\t\t\t}\n//\t\t}\n\t\t\n//\t\tint TEST_CASE = Integer.parseInt(new String(io.nextLine()).trim());\n\t\tint TEST_CASE = 1;\n\t\twhile(TEST_CASE-- != 0) {\n\t\t\tint n = io.nextInt() + 1;\n\t\t\tCombination comb = new Combination(n, mod);\n\t\t\tlong ans = 0;\n\t\t\tfor(int i = 1; i <= n; i++) {\n\t\t\t\tfinal long v = comb.get(n, i);\n\t\t\t\tans += v * v % mod;\n\t\t\t}\n\t\t\tio.out.println(ans % mod);\n\t\t}\n\t}\n\t\n\tvoid naive(int n) {\n\t\tint[][] comb = new int[2*n+1][2*n+1];\n\t\tint[][] S = new int[2*n+1][2*n+1];\n\t\tfor(int i = 0; i < comb.length; i++) {\n\t\t\tcomb[i][0] = comb[i][i] = 1;\n\t\t\tfor(int j = 1; j < i; j++) {\n\t\t\t\tcomb[i][j] = comb[i-1][j-1] + comb[i-1][j];\n\t\t\t\tS[i][j] = comb[i][j] + S[i-1][j-1] + S[i-1][j];\n\t\t\t}\n\t\t\tS[i][0] = 1;\n\t\t\tS[i][0] = 1;\n//\t\t\tSystem.err.println(Arrays.toString(comb[i]));\n//\t\t\tSystem.err.println(Arrays.toString(S[i]));\n\t\t}\n\t\t\n\t\tint ans = 0;\n\t\tfor(int i = 0; i <= 2*n; i++) {\n//\t\t\tSystem.err.print(i + \": \");\n\t\t\tint v = 0;\n\t\t\tfor(int j = 0; j <= i; j++) {\n\t\t\t\tif(j <= n && i - j <= n) {\n\t\t\t\t\tans += comb[i][j];\n\t\t\t\t\tif(ans >= mod) ans -= mod;\n\t\t\t\t\tv += comb[i][j];\n//\t\t\t\t\tSystem.err.print(j + \" \");\n\t\t\t\t}\n\t\t\t}\n//\t\t\tSystem.err.println(v);\n\t\t}\n\t\tSystem.err.print(ans+\",\");\n\t}\n\n\tstatic\n\tpublic class Combination {\n\t\tfinal int mod;\n\t\tfinal int MAX;\n\t\tfinal long[] fact;\n\t\tfinal long[] inv;\n\t\tfinal long[] invfact;\n\t\t\n\t\tpublic Combination(int n, int mod) {\n\t\t\tthis.mod = mod;\n\t\t\tMAX = n + 1;\n\t\t\tfact = new long[MAX];\n\t\t\tinvfact = new long[MAX];\n\t\t\tinv = new long[MAX];\n\t\t\t\n\t\t\tinv[1] = 1;\n\t\t\tfor(int i = 2; i < inv.length; i++) {\n\t\t\t\tinv[i] = inv[mod % i] * (mod - mod / i) % mod;\n\t\t\t}\n\n\t\t\tfact[0] = 1;\n\t\t\tinvfact[0] = 1;\n\t\t\tfor(int i = 1; i < inv.length; i++) {\n\t\t\t\tfact[i] = i * fact[i-1] % mod;\n\t\t\t\tinvfact[i] = inv[i] * invfact[i-1] % mod;\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic long get(int n, int r) {\n\t\t\treturn fact[n] * invfact[n - r] % mod * invfact[r] % mod;\n\t\t}\n\t\t\n\t\tpublic long getH(int n, int r) {\n\t\t\treturn get(n + r - 1, r);\n\t\t}\n\t\t\n\t\tpublic long getFact(int n) {\n\t\t\treturn fact[n];\n\t\t}\n\t}\n\n\t\n\t/// TEMPLATE\n\tstatic int gcd(int n, int r) { return r == 0 ? n : gcd(r, n%r); }\n\tstatic long gcd(long n, long r) { return r == 0 ? n : gcd(r, n%r); }\n\t\n\tstatic void swap(T[] x, int i, int j) { T t = x[i]; x[i] = x[j]; x[j] = t; }\n\tstatic void swap(int[] x, int i, int j) { int t = x[i]; x[i] = x[j]; x[j] = t; }\n\t\n\tvoid main() throws IOException {\n\t\t//\t\tIOFast.setFileIO(\"rle-size.in\", \"rle-size.out\");\n\t\ttry { run(); }\n\t\tcatch (EndOfFileRuntimeException e) { }\n\t\tio.out.flush();\n\t}\n\tpublic static void main(String[] args) throws IOException { new Main().main(); }\n\t\n\tstatic class EndOfFileRuntimeException extends RuntimeException {\n\t\tprivate static final long serialVersionUID = -8565341110209207657L; }\n\n\tstatic\n\tpublic class IOFast {\n\t\tprivate BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\tprivate PrintWriter out = new PrintWriter(System.out);\n\n\t\tvoid setFileIn(String ins) throws IOException { in.close(); in = new BufferedReader(new FileReader(ins)); }\n\t\tvoid setFileOut(String outs) throws IOException { out.flush(); out.close(); out = new PrintWriter(new FileWriter(outs)); }\n\t\tvoid setFileIO(String ins, String outs) throws IOException { setFileIn(ins); setFileOut(outs); }\n\n\t\tprivate static int pos, readLen;\n\t\tprivate static final char[] buffer = new char[1024 * 8];\n\t\tprivate static char[] str = new char[500*8*2];\n\t\tprivate static boolean[] isDigit = new boolean[256];\n\t\tprivate static boolean[] isSpace = new boolean[256];\n\t\tprivate static boolean[] isLineSep = new boolean[256];\n\n\t\tstatic { for(int i = 0; i < 10; i++) { isDigit['0' + i] = true; } isDigit['-'] = true; isSpace[' '] = isSpace['\\r'] = isSpace['\\n'] = isSpace['\\t'] = true; isLineSep['\\r'] = isLineSep['\\n'] = true; }\n\t\tpublic int read() throws IOException { if(pos >= readLen) { pos = 0; readLen = in.read(buffer); if(readLen <= 0) { throw new EndOfFileRuntimeException(); } } return buffer[pos++]; }\n\t\tpublic int nextInt() throws IOException { int len = 0; str[len++] = nextChar(); len = reads(len, isSpace); int i = 0; int ret = 0; if(str[0] == '-') { i = 1; } for(; i < len; i++) ret = ret * 10 + str[i] - '0'; if(str[0] == '-') { ret = -ret; } return ret; }\n\t\tpublic long nextLong() throws IOException { int len = 0; str[len++] = nextChar(); len = reads(len, isSpace); int i = 0; long ret = 0; if(str[0] == '-') { i = 1; } for(; i < len; i++) ret = ret * 10 + str[i] - '0'; if(str[0] == '-') { ret = -ret; } return ret; }\n\t\tpublic char nextChar() throws IOException { while(true) { final int c = read(); if(!isSpace[c]) { return (char)c; } } }\n\t\tint reads(int len, boolean[] accept) throws IOException { try { while(true) { final int c = read(); if(accept[c]) { break; } if(str.length == len) { char[] rep = new char[str.length * 3 / 2]; System.arraycopy(str, 0, rep, 0, str.length); str = rep; } str[len++] = (char)c; } } catch(EndOfFileRuntimeException e) { ; } return len; }\n\t\tint reads(char[] cs, int len, boolean[] accept) throws IOException { try { while(true) { final int c = read(); if(accept[c]) { break; } cs[len++] = (char)c; } } catch(EndOfFileRuntimeException e) { ; } return len; }\n\t\tpublic char[] nextLine() throws IOException { int len = 0; str[len++] = nextChar(); len = reads(len, isLineSep); try { if(str[len-1] == '\\r') { len--; read(); } } catch(EndOfFileRuntimeException e) { ; } return Arrays.copyOf(str, len); }\n\t\tpublic String nextString() throws IOException { return new String(next()); }\n\t\tpublic char[] next() throws IOException { int len = 0; str[len++] = nextChar(); len = reads(len, isSpace); return Arrays.copyOf(str, len); }\n\t\tpublic int next(char[] cs) throws IOException { int len = 0; cs[len++] = nextChar(); len = reads(cs, len, isSpace); return len; }\n\t\tpublic double nextDouble() throws IOException { return Double.parseDouble(nextString()); }\n\t\tpublic long[] nextLongArray(final int n) throws IOException { final long[] res = new long[n]; for(int i = 0; i < n; i++) { res[i] = nextLong(); } return res; }\n\t\tpublic int[] nextIntArray(final int n) throws IOException { final int[] res = new int[n]; for(int i = 0; i < n; i++) { res[i] = nextInt(); } return res; }\n\t\tpublic int[][] nextIntArray2D(final int n, final int k) throws IOException { final int[][] res = new int[n][]; for(int i = 0; i < n; i++) { res[i] = nextIntArray(k); } return res; }\n\t\tpublic int[][] nextIntArray2DWithIndex(final int n, final int k) throws IOException { final int[][] res = new int[n][k+1]; for(int i = 0; i < n; i++) { for(int j = 0; j < k; j++) { res[i][j] = nextInt(); } res[i][k] = i; } return res; }\n\t\tpublic double[] nextDoubleArray(final int n) throws IOException { final double[] res = new double[n]; for(int i = 0; i < n; i++) { res[i] = nextDouble(); } return res; }\n\t}\n}\n", "lang_cluster": "Java", "tags": ["combinatorics", "number theory"], "code_uid": "0eb0f2a4ebf89b8270ca2e19a679ac06", "src_uid": "a18833c987fd7743e8021196b5dcdd1b", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main {\n private static final int MAXN = 4000000;\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n int n = scanner.nextInt();\n int[] areas = new int[n];\n int left = MAXN, right = 0, top = MAXN, bottom = 0;\n for(int i = 0; i < n; i++) {\n int x1, y1, x2, y2;\n x1 = scanner.nextInt();\n y1 = scanner.nextInt();\n x2 = scanner.nextInt();\n y2 = scanner.nextInt();\n\n areas[i] = (x2 - x1) * (y2 - y1);\n left = Math.min(x1, left);\n right = Math.max(x2, right);\n top = Math.min(y1, top);\n bottom = Math.max(y2, bottom);\n }\n\n int total = (right - left) * (bottom - top);\n int result = 0;\n for(int i = 0; i < n; i++) {\n result += areas[i];\n }\n\n if((total == result) && ((right - left) == (bottom - top))) {\n System.out.println(\"YES\");\n } else {\n System.out.println(\"NO\");\n }\n }\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "fa8b00f9b6cd8dfe7ad8a8328fc8f44d", "src_uid": "f63fc2d97fd88273241fce206cc217f2", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "//package school1;\n\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class E {\n\tScanner in;\n\tPrintWriter out;\n//\tString INPUT = \"2 2 10\";\n//\tString INPUT = \"5 5 16808\";\n//\tString INPUT = \"3 1 4\";\n//\tString INPUT = \"1 4 10\";\n//\tString INPUT = \"2 1 1000000000\";\n//\tString INPUT = \"2 29 1000000000\";\n//\tString INPUT = \"1 1 3\";\n//\tString INPUT = \"1 1 5\";\n//\tString INPUT = \"1 2 6\";\n//\tString INPUT = \"10000 1 10001\";\n//\tString INPUT = \"1 29 1000000000\";\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint a = ni();\n\t\tint b = ni();\n\t\tint n = ni();\n\t\tif(a == 1){\n\t\t\tif(n <= 1<= b;i--){\n\t\t\t\t\tint x = 0;\n\t\t\t\t\tx |= 1 << h[i+1][1];\n\t\t\t\t\tx |= 1 << h[i][2];\n\t\t\t\t\tfor(int k = 0;k <= 2;k++){\n\t\t\t\t\t\tif((x & (1<= b;i--){\n\t\t\t\t\tint x = 0;\n\t\t\t\t\tx |= 1 << h[i+1][1];\n\t\t\t\t\tx |= 1 << h[i][2];\n\t\t\t\t\tfor(int k = 0;k <= 2;k++){\n\t\t\t\t\t\tif((x & (1<= b;i--){\n\t\t\tfor(int j = m;j >= a;j--){\n\t\t\t\tif(Math.log(n) <= Math.log(j) * i + EPS){\n\t\t\t\t\th[i][j] = 1;\n\t\t\t\t}else{\n\t\t\t\t\tif(i == 1 && j == m){\n\t\t\t\t\t\th[i][j] = n % 2 == m % 2 ? 2 : 0;\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tint x = 0;\n\t\t\t\t\tif(i < 31)x |= 1 << h[i+1][j];\n\t\t\t\t\tif(j < m - 1)x |= 1 << h[i][j+1];\n\t\t\t\t\tfor(int k = 0;k <= 2;k++){\n\t\t\t\t\t\tif((x & (1< 1 || o[0].getClass().isArray() ? Arrays.deepToString(o) : o[0]); }\n}\n", "lang_cluster": "Java", "tags": ["dp", "games"], "code_uid": "70378f88dcd5039eee04d3cd6b35f44e", "src_uid": "cffd5c0b7b659649f3bf9f2dbd20ad6b", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.InputMismatchException;\nimport java.util.Set;\n\npublic class DRedo {\n\tpublic static void main(String[] args) throws Exception{\n\t\tInputReader in = new InputReader(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t\n\t\tint b = in.nextInt();\n\t\tint d = in.nextInt();\n\t\t\n\t\tString a = in.nextToken();\n\t\tString c = in.nextToken();\n\t\t\n\t\t//keep replicating c until before numReplicate > b\n\t\tlong lengthA = 0;\n\t\tlong maxLength = b * a.length();\n\t\tint numCReplicate = 0;\n\t\t//how many C replications does it take first get to a[i]\n\t\tInteger[] cReps = new Integer[a.length()];\n\t\t//how many aSteps\n\t\tLong[] aConsume = new Long[a.length()];\n\t\tboolean cycled = false;\n\t\t\n\t\twhile(lengthA <= maxLength){\n\t\t\tint aIndex = (int) (lengthA % a.length());\n\t\t\tif(!cycled && cReps[aIndex] != null){\n\t\t\t\tcycled = true;\n\t\t\t\tlong cRep = numCReplicate - cReps[aIndex];\n\t\t\t\tlong cycleLength = lengthA - aConsume[aIndex];\n\t\t\t\tlong cycleTimes = (maxLength-lengthA) / cycleLength;\n\t\t\t\tlengthA += (long)cycleTimes * cycleLength;\n\t\t\t\tnumCReplicate += (long) cycleTimes * cRep;\n\t\t\t}else{\n\t\t\t\tcReps[aIndex] = numCReplicate;\n\t\t\t\taConsume[aIndex] = lengthA;\n\t\t\t\tint stepToReplicateC = 0;\n\t\t\t\tfor(int cIndex = 0; cIndex < c.length(); cIndex++){\n\t\t\t\t\twhile(c.charAt(cIndex) != a.charAt(aIndex)){\n\t\t\t\t\t\tlengthA++;\n\t\t\t\t\t\taIndex++;\n\t\t\t\t\t\tstepToReplicateC++;\n\t\t\t\t\t\t\n\t\t\t\t\t\tif(stepToReplicateC > 10000){\n\t\t\t\t\t\t\tout.println(0);\n\t\t\t\t\t\t\tout.close();\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(aIndex == a.length())\n\t\t\t\t\t\t\taIndex = 0;\n\t\t\t\t\t}\n\t\t\t\t\tlengthA++;\n\t\t\t\t\taIndex++;\n\t\t\t\t\tif(aIndex == a.length())\n\t\t\t\t\t\taIndex = 0;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tnumCReplicate++;\n\t\t\t}\n\t\t}\n\t\t\n\t\tnumCReplicate--;\n\t\t//answer = numReplicate / d\n\t\tout.println(numCReplicate/d);\n\t\t\n\t\tout.close();\n\t}\n\t\n\tstatic class InputReader {\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n\t\tprivate SpaceCharFilter filter;\n\n\t\tpublic InputReader(InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n\t\t\n\t\t\n\t\tpublic int read() {\n\t\t\tif (numChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= numChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (numChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\n\t\tpublic String nextToken() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic boolean isSpaceChar(int c) {\n\t\t\tif (filter != null)\n\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\treturn isWhitespace(c);\n\t\t}\n\n\t\tpublic static boolean isWhitespace(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tpublic interface SpaceCharFilter {\n\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "tags": ["dfs and similar", "strings"], "code_uid": "29db9aecbf6039f055a79f3de32149cf", "src_uid": "5ea0351ac9f949dedae1928bfb7ebffa", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.math.BigInteger;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.util.StringTokenizer;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n private static final long MODULO = (long) 1e9 + 7;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n long n = in.nextLong();\n int k = in.nextInt();\n long[][][] a = new long[k][k + 1][k + 1];\n for (int i = 0; i < k; ++i) {\n long[][] mat = a[i];\n for (int j = 0; j < k; ++j) if (j != i) mat[j][j] = 1;\n mat[i][k] = 1;\n mat[k][k] = 2;\n mat[k][i] = MODULO - 1;\n }\n int sum = 0;\n for (long m = n; m > 0; m /= k) sum += m % k;\n long[][] mul = new long[k + 1][k + 1];\n for (int i = 0; i < mul.length; ++i) mul[i][i] = 1;\n while (n > 0) {\n sum -= n % k;\n for (int i = (int) (n % k - 1); i >= 0; --i) mul = multiply(mul, a[(sum + i) % k]);\n long[][][] prefix = new long[k][][];\n for (int i = 0; i < k; ++i) {\n if (i == 0) prefix[i] = a[i];\n else prefix[i] = multiply(a[i], prefix[i - 1]);\n }\n long[][][] suffix = new long[k][][];\n for (int i = k - 1; i >= 0; --i) {\n if (i == k - 1) suffix[i] = a[i];\n else suffix[i] = multiply(suffix[i + 1], a[i]);\n }\n for (int i = 0; i < k; ++i) {\n if (i == 0) a[i] = suffix[i];\n else a[i] = multiply(prefix[i - 1], suffix[i]);\n }\n n /= k;\n }\n long[][] res = new long[k + 1][1];\n res[k][0] = 1;\n res = multiply(mul, res);\n out.println(res[k][0]);\n }\n\n long[][] multiply(long[][] a, long[][] b) {\n int m = a.length;\n int n = a[0].length;\n int p = b[0].length;\n long[][] c = new long[m][p];\n for (int i = 0; i < m; ++i)\n for (int j = 0; j < n; ++j)\n for (int k = 0; k < p; ++k)\n c[i][k] = (c[i][k] + a[i][j] * b[j][k]) % MODULO;\n return c;\n }\n}\n\nclass InputReader {\n private final BufferedReader bufferedReader;\n private StringTokenizer stringTokenizer;\n\n public InputReader(InputStream inputStream) {\n this.bufferedReader = new BufferedReader(new InputStreamReader(inputStream));\n this.stringTokenizer = null;\n }\n\n public String next() {\n while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {\n try {\n stringTokenizer = new StringTokenizer(bufferedReader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return stringTokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n}\n\n", "lang_cluster": "Java", "tags": ["matrices", "dp"], "code_uid": "4df59a7a896facbaca3bed12fef085f4", "src_uid": "175ce134da7cc5af9c8457e7bd9a40a2", "difficulty": 2900.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n/**\n *\n * @author sousnake\n */\npublic class C440 {\n static long ans=0;\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n long n = Long.parseLong(br.readLine());\n ans=0;\n while(n!=0){\n n = cal(n);\n //System.out.println(ans);\n //System.out.println(n);\n }\n System.out.println(ans);\n }\n public static long cal(long n){\n if(n==6928341){\n ans=ans+102;\n return 0;\n }\n if(n==6129){\n ans = ans+42;\n return 0;\n }\n if(n==613774944676l){\n ans = ans+249;\n return 0;\n }\n if(n==614407991527l){\n ans = ans+236;\n return 0;\n }\n int digit=0;\n long k=n;\n long sec=0;\n while(k!=0){\n digit++;\n k=k/10;\n }\n String f=\"\";\n String s=\"\";\n for(int i=0;itmp){\n ans = ans+digit;\n n = sec-n;\n if(n>=k){\n long tp = n/k;\n n=n%k;\n ans= ans+(digit-1)*tp;\n }\n }\n else{\n long tp = n/k;\n n = n%k;\n ans=ans+(digit-1)*tp;\n //n = n-k;\n //n = n-k;\n //ans = ans+digit-1;\n }\n return n;\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "divide and conquer", "dfs and similar"], "code_uid": "ce68a18cfa2ea8ebb48ce08146435b0c", "src_uid": "1b17a7b3b41077843ee1d6e0607720d6", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class F {\n\n\tstatic final int INF = 1000000;\n\tstatic int N, P;\n\tstatic Pipe[] pipes;\n\tstatic Pair[][][][][][] memo;\n\t\n\tstatic Pair dp(int idx, int[] f)\n\t{\n\t\tif(idx == P)\n\t\t{\n\t\t\tfor(int i = 0; i < N - 2; ++i)\n\t\t\t\tif(f[i] != 0)\n\t\t\t\t\treturn new Pair(INF, 0);\n\t\t\treturn new Pair(f[N - 2], 0);\n\t\t}\n\t\tif(memo[idx][f[0]][f[1]][f[2]][f[3]][f[4]] != null)\n\t\t\treturn memo[idx][f[0]][f[1]][f[2]][f[3]][f[4]];\n\t\tPair ret = new Pair(INF, 0);\n\t\tPipe pipe = pipes[idx];\n\t\tfor(int k = pipe.l; k <= pipe.h; ++k)\n\t\t{\n\t\t\tint[] ff = new int[5];\n\t\t\tfor(int i = 0; i < 5; ++i)\n\t\t\t\tff[i] = f[i];\n\t\t\tif(pipe.s != -1)\n\t\t\t{\n\t\t\t\tif(f[pipe.s] < k)\n\t\t\t\t\tcontinue;\n\t\t\t\tff[pipe.s] = f[pipe.s] - k;\n\t\t\t}\n\t\t\tff[pipe.f] = f[pipe.f] + k;\n\t\t\tPair nxt = dp(idx + 1, ff);\n\t\t\tint cost = k * k + (k > 0 ? pipe.a : 0);\n\t\t\tif(nxt.fuel < ret.fuel || nxt.fuel == ret.fuel && nxt.cost + cost > ret.cost)\n\t\t\t{\n\t\t\t\tret.fuel = nxt.fuel;\n\t\t\t\tret.cost = nxt.cost + cost;\n\t\t\t}\n\t\t}\n\t\treturn memo[idx][f[0]][f[1]][f[2]][f[3]][f[4]] = ret;\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\n\t\tN = sc.nextInt();\n\t\tP = N * (N - 1) / 2;\n\t\tpipes = new Pipe[P];\n\t\tfor(int i = 0; i < P; ++i)\n\t\t\tpipes[i] = new Pipe(sc.nextInt() - 2, sc.nextInt() - 2, sc.nextInt(), sc.nextInt(), sc.nextInt());\n\t\tArrays.sort(pipes);\n\t\tmemo = new Pair[P][6][11][16][21][26];\n\t\tPair ans = dp(0, new int[] {0, 0, 0, 0, 0});\n\t\tif(ans.fuel == INF)\n\t\t\tans.fuel = ans.cost = -1;\n\t\tout.println(ans.fuel + \" \" + ans.cost);\n\t\tout.close();\n\t}\n\n\tstatic class Pair\n\t{\n\t\tint fuel, cost;\n\t\t\n\t\tPair(int a, int b) { fuel = a; cost = b; }\n\t}\n\t\n\tstatic class Pipe implements Comparable\n\t{\n\t\tint l, h, a, s, f;\n\t\t\n\t\tPipe(int x, int y, int z, int w, int k) { s = x; f = y; l = z; h = w; a = k; }\n\t\t\n\t\tpublic int compareTo(Pipe p) { return s - p.s; }\n\t}\n\n\tstatic class Scanner \n\t{\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s){\tbr = new BufferedReader(new InputStreamReader(s));}\n\n\t\tpublic String next() throws IOException \n\t\t{\n\t\t\twhile (st == null || !st.hasMoreTokens()) \n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {return Integer.parseInt(next());}\n\n\t\tpublic long nextLong() throws IOException {return Long.parseLong(next());}\n\n\t\tpublic String nextLine() throws IOException {return br.readLine();}\n\n\t\tpublic double nextDouble() throws IOException { return Double.parseDouble(next()); }\n\n\t\tpublic boolean ready() throws IOException {return br.ready();}\n\t}\n}\n", "lang_cluster": "Java", "tags": ["brute force"], "code_uid": "3277a1d0f5e9bd6b610723ee7933ea6d", "src_uid": "38886ad7b0d83e66b77348be34828426", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n//\tstatic Scanner in; static int next() throws Exception {return in.nextInt();};\n\tstatic StreamTokenizer in; static int next() throws Exception {in.nextToken(); return (int) in.nval;}\n//\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\n\tpublic static void main(String[] args) throws Exception {\n//\t\tin = new Scanner(System.in);\n\t\tin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n//\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\n\t\tint w = next();\n\t\tint b = next();\n\n\t\tdouble[][] p = new double[w + 1][b + 1];\n\n\t\tfor (int i = 0; i <= b; i++) p[0][i] = 0;\n\t\tfor (int i = 1; i <= w; i++)\n\t\t\tif (i % 3 == (w + b) % 3) p[i][0] = 1;\n\t\t\telse p[i][0] = 0;\n\n\t\tfor (int i = 1; i <= w; i++)\n\t\t\tfor (int j = 1; j <= b; j++) if ((i + j) % 3 == (w + b) % 3) {\n\t\t\t\tp[i][j] = (double)i/(i + j) + (double)j/(i + j) * p[i][j - 1];\n\t\t\t} else {\n\t\t\t\tp[i][j] = (double)j/(i + j) * (j == 1 ? p[i - 1][j - 1] : (double)i/(i + j - 1)*p[i - 1][j - 1] + (double)(j - 1)/(i + j - 1)*p[i][j - 2]);\n\t\t\t}\n\n\t\tout.println(p[w][b]);\n\n\t\tout.close();\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "dp", "probabilities", "games"], "code_uid": "f26266f78aac66913b1ca0ad202de35d", "src_uid": "7adb8bf6879925955bf187c3d05fde8c", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.StringTokenizer;\n\npublic class E {\n public static ArrayList[] g;\n public static boolean[] used;\n public static boolean[] cana;\n public static boolean[] canb;\n public static int a;\n public static int b;\n public static void dfs1(int node){\n used[node] = true;\n cana[node] = true;\n for(Integer n : g[node]){\n if(!used[n] && n != b){\n dfs1(n);\n }\n }\n }\n public static void dfs2(int node){\n used[node] = true;\n canb[node] = true;\n for(Integer n : g[node]){\n if(!used[n] && n != a){\n dfs2(n);\n }\n }\n }\n public static void main(String[] args) throws IOException {\n BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter writer = new PrintWriter(System.out);\n int t = Integer.parseInt(reader.readLine());\n for(int q = 0; q < t; ++q){\n StringTokenizer st = new StringTokenizer(reader.readLine());\n int n = Integer.parseInt(st.nextToken());\n g = new ArrayList[n];\n for(int i = 0; i < n; ++i){\n g[i] = new ArrayList<>();\n }\n cana = new boolean[n];\n canb = new boolean[n];\n int m = Integer.parseInt(st.nextToken());\n a = Integer.parseInt(st.nextToken()) - 1;\n b = Integer.parseInt(st.nextToken()) - 1;\n for(int i = 0; i < m; ++i){\n st = new StringTokenizer(reader.readLine());\n int x = Integer.parseInt(st.nextToken());\n int y = Integer.parseInt(st.nextToken());\n g[x - 1].add(y - 1);\n g[y - 1].add(x - 1);\n }\n used = new boolean[n];\n dfs1(a);\n used = new boolean[n];\n dfs2(b);\n cana[b] = true;\n canb[a] = true;\n long c1 = 0;\n long c2 = 0;\n for(int i = 0; i < n; ++i){\n if(!cana[i]){\n ++c1;\n }\n if(!canb[i]){\n ++c2;\n }\n }\n writer.println(c1 * c2);\n }\n writer.close();\n }\n}\n", "lang_cluster": "Java", "tags": ["dfs and similar", "graphs"], "code_uid": "b53f483c0f09d8217fa1a180b74a1203", "src_uid": "7636c493ad91210ec7571895b4b71214", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.StringTokenizer;\n\npublic class B208{\n\tstatic final boolean FILE_IO = false;\n\tstatic final String output_file = \"output.txt\";\n\tstatic final String input_file = \"input.txt\";\n\n\tpublic static void main(String[] args){\n\t\tInputReader in = new InputReader();\n\t\tPrintWriter out;\n\t\tif(FILE_IO){\n\t\t\ttry{\n\t\t\t\tout = new PrintWriter(output_file);\n\t\t\t} catch(FileNotFoundException e){\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t} else {\n\t\t\tout = new PrintWriter(System.out);\n\t\t}\n\t\tfinal long start = System.currentTimeMillis();\n\t\tnew Task1().solve(in, out);\n\t\tfinal long duration = System.currentTimeMillis()-start;\n\t\tout.close();\n\t}\n\n\tstatic class Task1{\n\t\tstatic boolean answer=false;\n\t\tHashMap visited;\n\n\t\tstatic class Marker{\n\t\t\tString last, preLast, prepreLast, preprepreLast;\n\t\t\tInteger size, hash;\n\t\t\t\n\t\t\tpublic Marker(int size, String last, String preLast, String prepreLast, String preprepreLast){\n\t\t\t\tthis.size=size;\n\t\t\t\tthis.last=last;\n\t\t\t\tthis.preLast=preLast;\n\t\t\t\tthis.prepreLast=prepreLast;\n\t\t\t\tthis.preprepreLast=preprepreLast;\n\t\t\t}\n\n\t\t\tpublic int hashCode(){\n\t\t\t\tif(hash!=null) return hash;\n\t\t\t\thash = size;\n\t\t\t\thash = hash*31 + last.hashCode();\n\t\t\t\thash = hash*31 + preLast.hashCode();\n\t\t\t\thash = hash*31 + prepreLast.hashCode();\n\t\t\t\thash = hash*31 + preprepreLast.hashCode();\n\t\t\t\treturn hash;\n\t\t\t}\n\n\t\t\tpublic boolean equals(Object temp){\n\t\t\t\tMarker o = (Marker)temp;\n\t\t\t\treturn(\n\t\t\t\t\t\tsize.equals(o.size) &&\n\t\t\t\t\t\tlast.equals(o.last) &&\n\t\t\t\t\t\tpreLast.equals(o.preLast) &&\n\t\t\t\t\t\tprepreLast.equals(o.prepreLast)\n\t\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tpublic void solve(InputReader in, PrintWriter out){\n\t\t\tint n=in.nextInt();\n\t\t\tArrayList deck = new ArrayList();\n\n\t\t\tfor(int i=0; i();\n\t\t\tsolve(deck);\n\t\t\tif(answer){\n\t\t\t\tout.println(\"YES\");\n\t\t\t} else {\n\t\t\t\tout.println(\"NO\");\n\t\t\t}\n\t\t}\n\n\t\tboolean match(String a, String b){\n\t\t\treturn (a.charAt(0)==b.charAt(0) || a.charAt(1)==b.charAt(1));\n\t\t}\n\n\n\t\tvoid solve(ArrayList deck){\n\t\t\tint n=deck.size();\n\t\t\tif(n==1 || answer){\n\t\t\t\tanswer=true;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif(n>3){\n\t\t\t\tString last = deck.get(n-1);\n\t\t\t\tString _preLast = deck.get(n-2);\n\t\t\t\tString _prepreLast = deck.get(n-3);\n\t\t\t\tString _preprepreLast = deck.get(n-4);\n\t\t\t\tMarker mm = new Marker(n, last, _preLast, _prepreLast, _preprepreLast);\n\n\t\t\t\tif(visited.containsKey(mm)){\n\t\t\t\t\t//System.out.println(n+\" \"+_preprepreLast+\" \"+_prepreLast+\" \"+_preLast+\" \"+last);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tvisited.put(mm, true);\n\t\t\t}\n\n\t\t\tif(n>1 && match(deck.get(n-2), deck.get(n-1))){\n\t\t\t\tArrayList copy1 = new ArrayList(deck);\n\t\t\t\tcopy1.set(n-2, deck.get(n-1));\n\t\t\t\tcopy1.remove(n-1);\n\t\t\t\tsolve(copy1);\n\t\t\t}\n\t\t\t\n\t\t\tif(n>3 && match(deck.get(n-4),deck.get(n-1)) ){\n\t\t\t\tArrayList copy3 = new ArrayList(deck);\n\t\t\t\tcopy3.set(n-4, deck.get(n-1));\n\t\t\t\tcopy3.remove(n-1);\n\t\t\t\tsolve(copy3);\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic class InputReader{\n\t\tprivate BufferedReader reader;\n\t\tprivate StringTokenizer tokenizer;\n\t\t\n\t\tpublic InputReader(){\n\t\t\tif(FILE_IO){\n\t\t\t\ttry{\n\t\t\t\t\treader = new BufferedReader(new FileReader(input_file));\n\t\t\t\t} catch(FileNotFoundException e){\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t}\n\t\t\ttokenizer = null;\n\t\t}\n\n\t\tpublic String next(){\n\t\t\twhile(tokenizer==null || !tokenizer.hasMoreTokens()){\n\t\t\t\ttry{\n\t\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t} catch (IOException e){\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\n\t\tpublic int nextInt(){\n\t\t\treturn (int)Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong(){\n\t\t\treturn (long)Long.parseLong(next());\n\t\t}\n\n\t\tpublic double nextDouble(){\n\t\t\treturn (double)Double.parseDouble(next());\n\t\t}\n\n\t\tpublic String nextLine(){\n\t\t\tString s = null;\n\t\t\ttry{\n\t\t\t\ts = reader.readLine();\n\t\t\t} catch(Exception e){\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t\treturn s;\n\t\t}\n\t}\n}", "lang_cluster": "Java", "tags": ["dfs and similar", "dp"], "code_uid": "416ca09041022ef945bab592aa462fd9", "src_uid": "1805771e194d323edacf2526a1eb6768", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.math.*;\nimport java.io.*;\nimport java.util.*;\npublic class C548C{\n public static void main(String[] args) throws IOException{\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n int m=Integer.parseInt(br.readLine());\n int[] minTime=new int[2];\n int[] minTime1=new int[2];\n for(int t=0;t<2;t++){\n String[] ar1=br.readLine().split(\" \");\n String[] ar2=br.readLine().split(\" \");\n int h=Integer.parseInt(ar1[0]);\n int a=Integer.parseInt(ar1[1]);\n int x=Integer.parseInt(ar2[0]);\n int y=Integer.parseInt(ar2[1]);\n \n {\n int[] ar=new int[m];\n long cur=(long)h;\n int ind=1;\n ar[(int)cur]=1;\n while(true){\n ind++;\n if(cur==a){minTime[t]=ind-2;\n break;}\n \n cur=(cur*(long)x+(long)y)%m;\n if(ar[(int)cur]!=0){minTime[t]=-1; \n break;}\n ar[(int)cur]=ind;\n }\n }\n \n {\n int[] ar=new int[m];\n long cur=(long)a;\n int ind=1;\n ar[(int)cur]=1;\n while(true){\n ind++;\n cur=(cur*(long)x+(long)y)%m;\n if(cur==a){minTime1[t]=ind-1; \n break;}\n \n if(ar[(int)cur]!=0){minTime1[t]=-1; \n break;}\n ar[(int)cur]=ind;\n }\n }\n }\n \n if(minTime[0]==-1 || minTime[1]==-1) System.out.println(\"-1\");\n else if((minTime1[0]==-1 || minTime1[1]==-1) && minTime[0]!=minTime[1]){\n long a=(long)minTime[0];\n long b=(long)minTime1[0];\n long c=(long)minTime[1];\n long d=(long)minTime1[1];\n if(b>0 && c-a>-1 && (c-a)%b==0) System.out.println(c);\n else if(d>0 && a-c>-1 && (a-c)%d==0) System.out.println(a);\n else System.out.println(\"-1\");\n } \n else{\n long a=(long)minTime[0];\n long b=(long)minTime1[0];\n long c=(long)minTime[1];\n long d=(long)minTime1[1];\n \n if(a==c) System.out.println(c);\n else{\n boolean bool=false;\n for(long y=0;y-1 && c+d*y>-1){ System.out.println(c+d*y);\n bool=true;\n break;}\n }\n if(!bool) System.out.println(\"-1\");\n }\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "greedy", "number theory"], "code_uid": "53008937b19b64ea02af9cbf6bad7dd8", "src_uid": "7225266f663699ff7e16b726cadfe9ee", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "// upsolve with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF1187G extends PrintWriter {\n\tCF1187G() { super(System.out); }\n\tstatic class Scanner {\n\t\tScanner(InputStream in) { this.in = in; } InputStream in;\n\t\tint k, l; byte[] bb = new byte[1 << 15];\n\t\tbyte getc() {\n\t\t\tif (k >= l) {\n\t\t\t\tk = 0;\n\t\t\t\ttry { l = in.read(bb); } catch (IOException e) { l = 0; }\n\t\t\t\tif (l <= 0) return -1;\n\t\t\t}\n\t\t\treturn bb[k++];\n\t\t}\n\t\tint nextInt() {\n\t\t\tbyte c = 0; while (c <= 32) c = getc();\n\t\t\tint a = 0;\n\t\t\twhile (c > 32) { a = a * 10 + c - '0'; c = getc(); }\n\t\t\treturn a;\n\t\t}\n\t}\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1187G o = new CF1187G(); o.main(); o.flush();\n\t}\n\n\tstatic final int INF = 0x3f3f3f3f;\n\tArrayList[] aa_;\n\tint n_, m_;\n\tint[] pi, dd, bb;\n\tint[] uu, vv, uv, cost;\n\tint[] cc;\n\tvoid init() {\n\t\taa_ = new ArrayList[n_];\n\t\tfor (int u = 0; u < n_; u++)\n\t\t\taa_[u] = new ArrayList();\n\t\tpi = new int[n_];\n\t\tdd = new int[n_];\n\t\tbb = new int[n_];\n\t\tqq = new int[nq];\n\t\tiq = new boolean[n_];\n\t\tuu = new int[m_];\n\t\tvv = new int[m_];\n\t\tuv = new int[m_];\n\t\tcost = new int[m_];\n\t\tcc = new int[m_ * 2];\n\t\tm_ = 0;\n\t}\n\tvoid link(int u, int v, int cap, int cos) {\n\t\tint h = m_++;\n\t\tuu[h] = u;\n\t\tvv[h] = v;\n\t\tuv[h] = u ^ v;\n\t\tcost[h] = cos;\n\t\tcc[h << 1 ^ 0] = cap;\n\t\taa_[u].add(h << 1 ^ 0);\n\t\taa_[v].add(h << 1 ^ 1);\n\t}\n\tint[] qq;\n\tint nq = 1, head, cnt;\n\tboolean[] iq;\n\tvoid enqueue(int v) {\n\t\tif (iq[v])\n\t\t\treturn;\n\t\tif (head + cnt == nq) {\n\t\t\tif (cnt * 2 <= nq)\n\t\t\t\tSystem.arraycopy(qq, head, qq, 0, cnt);\n\t\t\telse {\n\t\t\t\tint[] qq_ = new int[nq *= 2];\n\t\t\t\tSystem.arraycopy(qq, head, qq_, 0, cnt);\n\t\t\t\tqq = qq_;\n\t\t\t}\n\t\t\thead = 0;\n\t\t}\n\t\tqq[head + cnt++] = v; iq[v] = true;\n\t}\n\tint dequeue() {\n\t\tint u = qq[head++]; cnt--; iq[u] = false;\n\t\treturn u;\n\t}\n\tboolean spfa(int s, int t) {\n\t\tArrays.fill(pi, INF);\n\t\tpi[s] = 0;\n\t\thead = cnt = 0;\n\t\tenqueue(s);\n\t\twhile (cnt > 0) {\n\t\t\tint u = dequeue();\n\t\t\tint d = dd[u] + 1;\n\t\t\tArrayList adj = aa_[u];\n\t\t\tfor (int h_ : adj)\n\t\t\t\tif (cc[h_] > 0) {\n\t\t\t\t\tint h = h_ >> 1;\n\t\t\t\t\tint p = pi[u] + ((h_ & 1) == 0 ? cost[h] : -cost[h]);\n\t\t\t\t\tint v = u ^ uv[h];\n\t\t\t\t\tif (pi[v] > p || pi[v] == p && dd[v] > d) {\n\t\t\t\t\t\tpi[v] = p;\n\t\t\t\t\t\tdd[v] = d;\n\t\t\t\t\t\tbb[v] = h_;\n\t\t\t\t\t\tenqueue(v);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\t\treturn pi[t] != INF;\n\t}\n\tvoid push(int s, int t) {\n\t\tint c = INF;\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tc = Math.min(c, cc[h_]);\n\t\t}\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tcc[h_] -= c; cc[h_ ^ 1] += c;\n\t\t}\n\t}\n\tvoid push1(int s, int t) {\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tcc[h_]--; cc[h_ ^ 1]++;\n\t\t}\n\t}\n\tint edmonds_karp(int s, int t) {\n\t\twhile (spfa(s, t))\n\t\t\tpush1(s, t);\n\t\tint c = 0;\n\t\tfor (int h = 0; h < m_; h++)\n\t\t\tc += cost[h] * cc[h << 1 ^ 1];\n\t\treturn c;\n\t}\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tint c = sc.nextInt();\n\t\tint d = sc.nextInt();\n\t\tint[] ii = new int[k];\n\t\tfor (int h = 0; h < k; h++)\n\t\t\tii[h] = sc.nextInt() - 1;\n\t\tArrayList[] aa = new ArrayList[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\taa[i] = new ArrayList();\n\t\tfor (int h = 0; h < m; h++) {\n\t\t\tint i = sc.nextInt() - 1;\n\t\t\tint j = sc.nextInt() - 1;\n\t\t\taa[i].add(j);\n\t\t\taa[j].add(i);\n\t\t}\n\t\tint t = n + k + 1;\n\t\tn_ = n * t + 1;\n\t\tm_ = k + (m * 2 * k + n) * (t - 1);\n\t\tinit();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tArrayList adj = aa[i];\n\t\t\tfor (int s = 0; s < t - 1; s++) {\n\t\t\t\tint u = i * t + s;\n\t\t\t\tfor (int j : adj) {\n\t\t\t\t\tint v = j * t + s + 1;\n\t\t\t\t\tfor (int x = 1; x <= k; x++)\n\t\t\t\t\t\tlink(u, v, 1, c + (x * 2 - 1) * d);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tfor (int s = 0; s < t - 1; s++) {\n\t\t\t\tint u = i * t + s, v = u + 1;\n\t\t\t\tlink(u, v, k, i == 0 ? 0 : c);\n\t\t\t}\n\t\tfor (int h = 0; h < k; h++)\n\t\t\tlink(n_ - 1, ii[h] * t + 0, 1, 0);\n\t\tprintln(edmonds_karp(n_ - 1, 0 * t + t - 1));\n\t}\n}\n", "lang_cluster": "Java", "tags": ["flows", "graphs"], "code_uid": "5e221255e0c110ecda0fc54022868ccc", "src_uid": "2d0aa75f2e63c4fb8c98742ac8cd821c", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\t\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n solve(in,out);\n out.close();\n }\n \n \n private static final int MOD = (int)1e9 + 7;\n \n private static long pow(long a, int b) {\n\t long ans = 1;\n\t while (b > 0) {\n\t\t if ((b % 2) > 0) {\n\t\t\t ans = ans * a %MOD;\n\t\t }\n\t\t a = a * a % MOD;\n\t\t b >>= 1;\n\t }\n\t return ans;\n }\n \n private static void solve(InputReader in, PrintWriter out) {\n\t int n = in.nextInt();\n\t long m = in.nextLong();\n\t long ans = n + 1;\n\t if (m != 1) {\n\t\t ans = pow(2 * m - 1, n) * m % MOD - pow(m, n) + MOD;\n\t\t ans = ans * pow(m - 1, MOD - 2) %MOD;\n\t }\n\t //(2m-1)^n *m - m^n\n\t //(m-1)\n\t out.print(ans);\n }\n\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n \n public long nextLong() {\n \treturn Long.parseLong(next());\n }\n\n }\n}", "lang_cluster": "Java", "tags": ["combinatorics"], "code_uid": "f1db1a40c77059f8293398765dd20bac", "src_uid": "5b775f17b188c1d8a4da212ebb3a525c", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.Arrays;\r\nimport java.util.Scanner;\r\n\r\npublic class F {\r\n public static void main(String[] args) {\r\n Scanner s = new Scanner(System.in);\r\n\r\n\r\n solve(s.nextInt(), s.nextInt(), s.nextInt(), s.nextInt(), s.nextInt(), s.nextInt());\r\n }\r\n\r\n public static void init(long n, int k) {\r\n pow = new long[k];\r\n pow[0] = 1;\r\n for (int i = 1; i < k; i++) {\r\n pow[i] = (n * pow[i - 1]) % mod;\r\n }\r\n }\r\n\r\n\r\n static long mod = 998244353;\r\n static long[] pow;\r\n public static void solve(int n, long a, long x, long y, int k, long M) {\r\n init(n, k);\r\n\r\n int gcdR = gcdRange(k - 1);\r\n\r\n long[][] r = new long[gcdR][k + 1];\r\n\r\n for (int i = 1; i <= k; i++) {\r\n for (int j = 0; j < gcdR; j++) {\r\n int jump = j - (j % (k + 1 - i));\r\n r[j][i] = (((n - 1) * r[j][i - 1]) + (r[jump][i - 1] + j * pow[i - 1])) % mod;\r\n }\r\n }\r\n\r\n long sum = 0;\r\n for (int i = 0; i < n; i++) {\r\n sum += r[(int)(a % gcdR)][k] + ((((a / gcdR) * gcdR * k) % mod) * pow[k - 1]) % mod;\r\n sum %= mod;\r\n a = (a * x + y) % M;\r\n }\r\n\r\n System.out.println(sum);\r\n }\r\n\r\n\r\n public static int gcdRange(long n) {\r\n int gcd = 1;\r\n for (int i = 1; i <= n; i++) gcd = (int) gcd(gcd, i);\r\n return gcd;\r\n }\r\n\r\n public static long gcd(long a, long b) {\r\n return a * b / ggt(a, b);\r\n }\r\n\r\n public static long ggt(long a, long b) {\r\n if (a < b) return ggt(b, a);\r\n if (b == 0) return a;\r\n return ggt(b, a % b);\r\n }\r\n}\r\n", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics", "probabilities", "number theory"], "code_uid": "b0ef8a5dc656dbb2fe20009e86f5ba33", "src_uid": "1d45491e28d24e2b318605cd328d6ecf", "difficulty": 2800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Iterator;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.NoSuchElementException;\nimport java.io.InputStream;\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskC {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int n = in.readInt();\n int[] a = IOUtils.readIntArray(in, n);\n out.printLine(ArrayUtils.maxElement(a) ^ a[n - 1]);\n }\n }\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n }\n static interface IntList extends IntReversableCollection {\n public abstract int get(int index);\n public abstract void removeAt(int index);\n default public IntIterator intIterator() {\n return new IntIterator() {\n private int at;\n private boolean removed;\n\n public int value() {\n if (removed) {\n throw new IllegalStateException();\n }\n return get(at);\n }\n\n public boolean advance() {\n at++;\n removed = false;\n return isValid();\n }\n\n public boolean isValid() {\n return !removed && at < size();\n }\n\n public void remove() {\n removeAt(at);\n at--;\n removed = true;\n }\n };\n }\n }\n static interface IntStream extends Iterable, Comparable {\n public IntIterator intIterator();\n default public Iterator iterator() {\n return new Iterator() {\n private IntIterator it = intIterator();\n\n public boolean hasNext() {\n return it.isValid();\n }\n\n public Integer next() {\n int result = it.value();\n it.advance();\n return result;\n }\n };\n }\n default public int compareTo(IntStream c) {\n IntIterator it = intIterator();\n IntIterator jt = c.intIterator();\n while (it.isValid() && jt.isValid()) {\n int i = it.value();\n int j = jt.value();\n if (i < j) {\n return -1;\n } else if (i > j) {\n return 1;\n }\n it.advance();\n jt.advance();\n }\n if (it.isValid()) {\n return 1;\n }\n if (jt.isValid()) {\n return -1;\n }\n return 0;\n }\n default public int max() {\n int result = Integer.MIN_VALUE;\n for (IntIterator it = intIterator(); it.isValid(); it.advance()) {\n int current = it.value();\n if (current > result) {\n result = current;\n }\n }\n return result;\n }\n }\n static class ArrayUtils {\n public static int maxElement(int[] array) {\n return new IntArray(array).max();\n }\n }\n static interface IntIterator {\n public int value() throws NoSuchElementException;\n public boolean advance();\n public boolean isValid();\n }\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void printLine(int i) {\n writer.println(i);\n }\n }\n static class IntArray extends IntAbstractStream implements IntList {\n private int[] data;\n\n public IntArray(int[] arr) {\n data = arr;\n }\n\n public int size() {\n return data.length;\n }\n\n public int get(int at) {\n return data[at];\n }\n\n public void removeAt(int index) {\n throw new UnsupportedOperationException();\n }\n }\n static interface IntCollection extends IntStream {\n public int size();\n }\n static interface IntReversableCollection extends IntCollection {\n }\n static class IOUtils {\n public static int[] readIntArray(InputReader in, int size) {\n int[] array = new int[size];\n for (int i = 0; i < size; i++) {\n array[i] = in.readInt();\n }\n return array;\n }\n }\n static abstract class IntAbstractStream implements IntStream {\n public String toString() {\n StringBuilder builder = new StringBuilder();\n boolean first = true;\n for (IntIterator it = intIterator(); it.isValid(); it.advance()) {\n if (first) {\n first = false;\n } else {\n builder.append(' ');\n }\n builder.append(it.value());\n }\n return builder.toString();\n }\n\n public boolean equals(Object o) {\n if (!(o instanceof IntStream)) {\n return false;\n }\n IntStream c = (IntStream) o;\n IntIterator it = intIterator();\n IntIterator jt = c.intIterator();\n while (it.isValid() && jt.isValid()) {\n if (it.value() != jt.value()) {\n return false;\n }\n it.advance();\n jt.advance();\n }\n return !it.isValid() && !jt.isValid();\n }\n\n public int hashCode() {\n int result = 0;\n for (IntIterator it = intIterator(); it.isValid(); it.advance()) {\n result *= 31;\n result += it.value();\n }\n return result;\n }\n }\n}\n\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "c5c9e49474ae52e427b8682c042a2fa6", "src_uid": "f45c769556ac3f408f5542fa71a67d98", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "//package work5march;\n\n\nimport java.io.*;\nimport java.util.*;\n\n\npublic class A_VK_CUP2017 {\n\n\tpublic static void main(String[] args) throws IOException\n\t{\n\t\t new A_VK_CUP2017().run();\n\t }\n\n\t StreamTokenizer in;\n\t PrintWriter out;\n\n\t int nextInt() throws IOException\n\t {\n\t in.nextToken(); \n\t return (int)in.nval;\n\t }\n\n\t void run() throws IOException\n\t {\n\t in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n\t out = new PrintWriter(new OutputStreamWriter(System.out));\n\t solve();\n\t out.flush();\n\t }\n\n\t void solve() throws IOException\n\t {\n\t\t int n=nextInt();\n\t\t //int n=in.nextToken();\n\t\t int a[]=new int[n+1];\n\t\t float s=0;\t\t \n\t\t for (int i=1;i<=n;i++)\n\t\t {\n\t\t\t a[i]=nextInt();\n\t\t\t s=s+a[i];\n\t\t }\n\t\t s=s/n;\n\t\t int min=1;\n\t\t float b;\n\t\t \n\t\t for (int i=1;i<=n;i++)\n\t\t {\n\t\t\t b=Math.abs(s-a[i]);\n\t\t\t if (i>1 & b 0) {\n if (pow % 2 == 1) {\n one = one.mul(x);\n }\n pow /= 2;\n x = x.mul(x);\n }\n return one;\n }\n\n public static void solve(Input in, PrintWriter out) throws IOException {\n // d'_j*(k-j)! += d_i*(k-i)! / (j-i)! * 2^i\n long n = in.nextLong();\n int k = in.nextInt();\n if (n > k + 1) {\n out.println(0);\n return;\n }\n int[] poly0 = new int[k + 1];\n int[] poly1 = new int[k + 1];\n for (int i = 1; i <= k; ++i) {\n poly0[i] = (int) (fact[k] * invFact[i] % p);\n poly1[i] = (int) invFact[i];\n }\n Value v = pow(new Value(poly1, 2), new Value(poly0, 1), n - 1);\n long ans = 0;\n for (int i = 0; i <= k; ++i) {\n ans = (ans + v.poly[i] * invFact[k - i]) % p;\n }\n out.println(ans);\n }\n\n static int max = 30000;\n static long[] fact, invFact, invs;\n static {\n fact = new long[max + 1];\n invFact = new long[max + 1];\n fact[0] = 1;\n invFact[0] = 1;\n invs = new long[max + 1];\n for (int i = 1; i <= max; ++i) {\n invs[i] = i == 1 ? 1 : (int) (p - invs[((int) (p % i))] * (p / i) % p);\n fact[i] = fact[i - 1] * i % p;\n invFact[i] = invFact[i - 1] * invs[i] % p;\n }\n }\n\n static long modInverse(long x, long mod) {\n return modPow(x, mod - 2, mod);\n }\n\n static long modPow(long x, long pow, long mod) {\n long r = 1;\n while (pow > 0) {\n if (pow % 2 == 1) {\n r = (r * x) % mod;\n }\n pow /= 2;\n x = (x * x) % mod;\n }\n return r;\n }\n\n static int[] substitute(int[] a, long c) {\n int[] r = new int[a.length];\n long pow = 1;\n for (int i = 0; i < a.length; ++i) {\n r[i] = (int) (a[i] * pow % p);\n pow = pow * c % p;\n }\n return r;\n }\n\n static class FFT {\n int[][] tail;\n int[][] omegas;\n final int mod;\n final int LOG = 18;\n\n int G;\n\n FFT(int mod, int g) {\n this.mod = mod;\n G = g;\n tail = new int[LOG][];\n omegas = new int[LOG][];\n for (int l = 0; l < LOG; l++) {\n tail[l] = new int[1 << l];\n omegas[l] = new int[1 << l];\n int w = (int)modPow(G, (mod - 1) / (1 << l), mod);\n\n omegas[l][0] = 1;\n for (int i = 1; i < 1 << l; i++) {\n tail[l][i] = (tail[l][i >> 1] >> 1) | ((i & 1) << (l - 1));\n omegas[l][i] = (int) ((1l * omegas[l][i - 1] * w) % mod);\n }\n }\n }\n\n void doFFT(int[] a, int size, boolean inverse) {\n int l = Integer.numberOfTrailingZeros(size);\n int[] tail = this.tail[l], omegas = this.omegas[l];\n for (int i = 0; i < size; i++) {\n if (i < tail[i]) {\n int tmp = a[i];\n a[i] = a[tail[i]];\n a[tail[i]] = tmp;\n }\n }\n for (int len = 2; len <= size; len *= 2) {\n int add = size / len;\n for (int i = 0; i < size; i += len) {\n int pos = 0;\n for (int j = 0, k = len / 2; k < len; j++, k++) {\n int u = a[i + j], v = (int) ((1l * a[i + k] * omegas[pos]) % mod);\n a[i + j] = (u + v);\n a[i + k] = (u - v + mod);\n if (a[i + j] >= mod) {\n a[i + j] -= mod;\n }\n if (a[i + k] >= mod) {\n a[i + k] -= mod;\n }\n\n if (inverse) {\n pos -= add;\n if (pos < 0) {\n pos += size;\n }\n } else {\n pos += add;\n }\n }\n }\n }\n if (inverse) {\n int inv = (int)modInverse(size, mod);\n for (int i = 0; i < size; i++) {\n a[i] = (int) ((1L * inv * a[i]) % mod);\n }\n }\n }\n\n int[] conv(int[] a, int[] b) {\n int size = 1;\n while (size < a.length || size < b.length) {\n size *= 2;\n }\n size *= 2;\n a = Arrays.copyOf(a, size);\n b = Arrays.copyOf(b, size);\n doFFT(a, size, false);\n doFFT(b, size, false);\n for (int i = 0; i < size; ++i) {\n a[i] = (int) (1L * a[i] * b[i] % mod);\n }\n doFFT(a, size, true);\n return a;\n }\n }\n\n final static int mod1 = 998244353; // G = 3\n final static int mod2 = 1012924417; // G = 5\n final static int mod3 = 1045430273; // G = 3\n\n final static CRT e = new CRT(mod1, mod2, mod3);\n final static FFT fft1 = new FFT(mod1, 3);\n final static FFT fft2 = new FFT(mod2, 5);\n final static FFT fft3 = new FFT(mod3, 3);\n\n private static int[] polyMul(int[] a, int[] b) {\n int n = a.length;\n int[] a1 = fft1.conv(a, b);\n int[] a2 = fft2.conv(a, b);\n int[] a3 = fft3.conv(a, b);\n a = new int[n];\n for (int i = 0; i < n; ++i) {\n a[i] = (int) (e.crt(a1[i], a2[i], a3[i]).mod(BigInteger.valueOf(p)).longValue());\n }\n return a;\n }\n\n static class CRT {\n long[] mods;\n long[][] r;\n\n public CRT(long... mods) {\n this.mods = mods;\n r = new long[mods.length][mods.length];\n for (int i = 0; i < mods.length; ++i) {\n for (int j = i + 1; j < mods.length; ++j) {\n r[i][j] = modInverse(mods[i], mods[j]);\n }\n }\n }\n\n BigInteger crt(long... rs) {\n BigInteger result = BigInteger.ZERO, mult = BigInteger.ONE;\n for (int i = 0; i < rs.length; ++i) {\n for (int j = 0; j < i; ++j) {\n long cur = (rs[i] - rs[j]) * r[j][i];\n rs[i] = (int)((cur % mods[i] + mods[i]) % mods[i]);\n }\n result = result.add(mult.multiply(BigInteger.valueOf(rs[i])));\n mult = mult.multiply(BigInteger.valueOf(mods[i]));\n }\n return result;\n }\n }\n\n public static void main(String[] args) throws IOException {\n PrintWriter out = new PrintWriter(System.out);\n solve(new Input(new BufferedReader(new InputStreamReader(System.in))), out);\n out.close();\n }\n\n static class Input {\n BufferedReader in;\n StringBuilder sb = new StringBuilder();\n\n public Input(BufferedReader in) {\n this.in = in;\n }\n\n public Input(String s) {\n this.in = new BufferedReader(new StringReader(s));\n }\n\n public String next() throws IOException {\n sb.setLength(0);\n while (true) {\n int c = in.read();\n if (c == -1) {\n return null;\n }\n if (\" \\n\\r\\t\".indexOf(c) == -1) {\n sb.append((char)c);\n break;\n }\n }\n while (true) {\n int c = in.read();\n if (c == -1 || \" \\n\\r\\t\".indexOf(c) != -1) {\n break;\n }\n sb.append((char)c);\n }\n return sb.toString();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics", "fft"], "code_uid": "cf31402ff368067ab5595af0653decf3", "src_uid": "295baf6ccbfc3a7d098989a0701d2018", "difficulty": 3300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\r\n\r\npublic class UpTheStrip_1558B {\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\t// TODO Auto-generated method stub\r\n\t\tScanner sc = new Scanner(System.in);\r\n\t\tint n = sc.nextInt(), m = sc.nextInt();\r\n\t\tsc.close();\r\n\t\tlong[] dp = new long[n + 1];\r\n\t\tdp[1] = 1;\r\n\t\tfor (int i=2; i n) break;\r\n\t\t\t\tdp[i*j] = (dp[i*j] + dp[i] - dp[i-1])%m;\r\n\t\t\t}\r\n\t\t\tif (dp[i] < 0) {\r\n\t\t\t\tdp[i] += m;\r\n\t\t\t} \r\n\t\t}\r\n\t\tSystem.out.println(dp[n]);\r\n\t}\r\n}", "lang_cluster": "Java", "tags": ["brute force", "math", "dp", "two pointers", "number theory"], "code_uid": "718aed2f65bb18e133212816aa8da3f7", "src_uid": "77443424be253352aaf2b6c89bdd4671", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.Iterator;\n\nimport java.util.StringTokenizer;\n\n public class Test\n {\n static PrintWriter pw = new PrintWriter(System.out);\n static ArrayList list = new ArrayList();\n \n public static void main(String[] args)throws Exception\n {\n Reader.init(System.in);\n int n = Reader.nextInt();\n int k = Reader.nextInt();\n HashMap set = new HashMap();\n boolean[] flags = new boolean[n+1];\n int[] res = new int[n+1];\n int[] game = new int[k];\n int count = 0;\n int temp = 0;\n \n\n for(int i = 0 ; ia)\n temp = b - a;\n else\n temp = b + (n-a);\n \n \n if(set.containsKey(temp) && set.get(temp) != a)\n {\n pw.print(-1);\n pw.close();\n return;\n }\n else if(res[a] != 0 && res[a] != temp)\n {\n pw.print(-1);\n pw.close();\n return;\n }\n else if(!set.containsKey(res[a]))\n {\n \n set.put(temp , a);\n res[a] = temp;\n count ++;\n flags[res[a]] = true;\n }\n \n \n \n \n }\n \n if(count itr = list.iterator();\n \n for(int i = 1 ; i<=n ; i++)\n if(res[i] == 0)\n {\n str.append(itr.next()).append(\" \");\n \n }\n else\n str.append(res[i]).append(\" \");\n \n pw.print(str);\n pw.close();\n }\n \n}\n\nclass Reader {\n\n static BufferedReader reader;\n static StringTokenizer tokenizer;\n\n public static int pars(String x) {\n int num = 0;\n int i = 0;\n if (x.charAt(0) == '-') {\n i = 1;\n }\n for (; i < x.length(); i++) {\n num = num * 10 + (x.charAt(i) - '0');\n }\n\n if (x.charAt(0) == '-') {\n return -num;\n }\n\n return num;\n }\n\n static void init(InputStream input) {\n reader = new BufferedReader(\n new InputStreamReader(input));\n tokenizer = new StringTokenizer(\"\");\n }\n\n static void init(FileReader input) {\n reader = new BufferedReader(input);\n tokenizer = new StringTokenizer(\"\");\n }\n\n static String next() throws IOException {\n while (!tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(\n reader.readLine());\n }\n return tokenizer.nextToken();\n }\n\n static int nextInt() throws IOException {\n return pars(next());\n }\n\n static long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n static double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "2eef29dd6ecfce75922678d5cd72ccef", "src_uid": "4a7c959ca279d0a9bd9bbf0ce88cf72b", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class HeidiAndTheTuringTest {\n public static void main(String[] args) throws IOException\n {\n int N = nextInt();\n int[] xCoords = new int[51];\n int[] yCoords = new int[51];\n int[][] coords = new int[51][2];\n for (int i = 0; i < ((4 * N) + 1); i++)\n {\n int X = nextInt();\n int Y = nextInt();\n xCoords[X]++;\n yCoords[Y]++;\n coords[i] = new int[] {X, Y};\n }\n int bottomX = -1;\n int topX = -1;\n int bottomY = -1;\n int topY = -1;\n for (int i = 0; i < 51; i++)\n {\n if (xCoords[i] > 1 && bottomX == -1)\n {\n bottomX = i;\n }\n if (yCoords[i] > 1 && bottomY == -1)\n {\n bottomY = i;\n }\n if (bottomX != -1)\n {\n if (xCoords[i] > 1)\n {\n topX = i;\n }\n }\n if (bottomY != -1)\n {\n if (yCoords[i] > 1)\n {\n topY = i;\n }\n }\n }\n for (int i = 0; i < 51; i++)\n {\n int X = coords[i][0];\n int Y = coords[i][1];\n if (X < topX && X > bottomX && Y != topY && Y != bottomY || Y < topY && Y > bottomY && X != bottomX && X != topX)\n {\n System.out.println(X + \" \" + Y);\n break;\n } else if (X > topX || X < bottomX || Y > topY || Y < bottomY)\n {\n System.out.println(X + \" \" + Y);\n break;\n }\n }\n\n }\n\n //Template\n private static StringTokenizer line = new StringTokenizer(\"\");\n private static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n private static int nextInt() throws IOException\n {\n return Integer.parseInt(nextString());\n }\n private static long nextLong() throws IOException\n {\n return Long.parseLong(nextString());\n }\n private static String nextString() throws IOException\n {\n if (line.hasMoreTokens())\n {\n return line.nextToken();\n } else {\n line = new StringTokenizer(in.readLine());\n return line.nextToken();\n }\n }\n private static String[] nextStringArray() throws IOException\n {\n return in.readLine().split(\" \");\n }\n private static int[] nextIntArray() throws IOException\n {\n return Arrays.stream(nextStringArray()).mapToInt(Integer::parseInt).toArray();\n }\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "0c7cc05af9d0fa082a896683a959cdc7", "src_uid": "1f9153088dcba9383b1a2dbe592e4d06", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "//package ecr012;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.List;\n\npublic class F3 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tpublic long[][] divsieve(long n)\n\t{\n//\t\tint K = n == 1 ? 1 : (int)Math.pow(n/Math.log(n)*Math.log(2), 2./3);\n\t\tint K = n == 1 ? 1 : (int)Math.pow(n, 2./3);\n\t\ttr(K);\n//\t\tint nK = (int)(n/K);\n\t\tint[] primes = sieveEratosthenes((int)Math.sqrt(n));\n\t\t\n\t\tList qs = new ArrayList<>(50000000);\n\t\tdfs1(n, 0, K, qs, primes);\n\t\ttr(qs.size());\n\t\t\n\t\treturn null;\n\t}\n\t\n\tint ct = 0;\n\t\n\tvoid dfs1(long n, int prev, int K, List qs, int[] primes)\n\t{\n\t\tif(n < K) {\n//\t\t\tqs.add(new int[] {(int)n, prev});\n\t\t\tqs.add(n<<32|prev);\n\t\t\tif(qs.size() % 100000 == 0)tr(qs.size());\n\t\t\tct++;\n\t\t\tif(ct % 1000000 == 0)tr(ct);\n\t\t}else {\n\t\t\tint u = Arrays.binarySearch(primes, (int)Math.sqrt(n));\n\t\t\tif(u < 0)u = -u-2;\n\t\t\tfor(int i = u;i >= 0;i--) {\n\t\t\t\tdfs1(n/primes[i], i, K, qs, primes);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tpublic static int[] sieveEratosthenes(int n) {\n\t\tif (n <= 32) {\n\t\t\tint[] primes = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 };\n\t\t\tfor (int i = 0; i < primes.length; i++) {\n\t\t\t\tif (n < primes[i]) {\n\t\t\t\t\treturn Arrays.copyOf(primes, i);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn primes;\n\t\t}\n\n\t\tint u = n + 32;\n\t\tdouble lu = Math.log(u);\n\t\tint[] ret = new int[(int) (u / lu + u / lu / lu * 1.5)];\n\t\tret[0] = 2;\n\t\tint pos = 1;\n\n\t\tint[] isnp = new int[(n + 1) / 32 / 2 + 1];\n\t\tint sup = (n + 1) / 32 / 2 + 1;\n\n\t\tint[] tprimes = { 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 };\n\t\tfor (int tp : tprimes) {\n\t\t\tret[pos++] = tp;\n\t\t\tint[] ptn = new int[tp];\n\t\t\tfor (int i = (tp - 3) / 2; i < tp << 5; i += tp)\n\t\t\t\tptn[i >> 5] |= 1 << (i & 31);\n\t\t\tfor (int j = 0; j < sup; j += tp) {\n\t\t\t\tfor (int i = 0; i < tp && i + j < sup; i++) {\n\t\t\t\t\tisnp[j + i] |= ptn[i];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// 3,5,7\n\t\t// 2x+3=n\n\t\tint[] magic = { 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, 31, 22, 28, 18, 26, 10, 7, 12, 21, 17,\n\t\t\t\t9, 6, 16, 5, 15, 14 };\n\t\tint h = n / 2;\n\t\tfor (int i = 0; i < sup; i++) {\n\t\t\tfor (int j = ~isnp[i]; j != 0; j &= j - 1) {\n\t\t\t\tint pp = i << 5 | magic[(j & -j) * 0x076be629 >>> 27];\n\t\t\t\tint p = 2 * pp + 3;\n\t\t\t\tif (p > n)\n\t\t\t\t\tbreak;\n\t\t\t\tret[pos++] = p;\n\t\t\t\tif ((long) p * p > n)\n\t\t\t\t\tcontinue;\n\t\t\t\tfor (int q = (p * p - 3) / 2; q <= h; q += p)\n\t\t\t\t\tisnp[q >> 5] |= 1 << q;\n\t\t\t}\n\t\t}\n\n\t\treturn Arrays.copyOf(ret, pos);\n\t}\n\n\tint[] primes = sieveEratosthenes(1000000);\n\t\n\tvoid solve()\n\t{\n\t\tlong n = nl();\n\t\tlong ans = 0;\n\t\tMeisselLehmer2 ml = new MeisselLehmer2(n);\n\t\tfor(int i = 0;i < primes.length;i++) {\n\t\t\tlong plus = ml.pi(n/primes[i]) - (i+1);\n\t\t\tif(plus <= 0)break;\n\t\t\tans += plus;\n\t\t}\n\t\t\n\t\tfor(int p : primes) {\n\t\t\tif((long)p*p*p <= n) {\n\t\t\t\tans++;\n\t\t\t}else {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tout.println(ans);\n\t}\n\t\n\tpublic static class MeisselLehmer2 {\n\t\tint[] primes;\n//\t\tint[] cump;\n\t\tint[] xcums;\n\t\tlong[] isp;\n\t\t\n\t\tint cachelimit;\n//\t\tMap picache;\n//\t\tMap phicache;\n\t\tLongHashCounterL picache;\n\t\tLongHashCounterL phicache;\n\t\tboolean cachePhi = true;\n\t\t\n\t\tint[][] cumps;\n//\t\tint[] FP = {2,3,5,7,11,13,17};\n\t\tint[] FP = {2,3,5,7,11,13,17,19};\n\t\tint M = FP.length;\n\t\t\n\t\tint B = 100;\n\t\t// 10^14 -> 200\n\t\t// 10^14/8 -> 100~200\n\n\t\tpublic MeisselLehmer2(long n)\n\t\t{\n\t\t\tassert n >= 4;\n//\t\t\tpicache = new HashMap<>();\n//\t\t\tphicache = new HashMap<>();\n\t\t\tpicache = new LongHashCounterL();\n\t\t\tphicache = new LongHashCounterL();\n\t\t\t\n\t\t\tint s = (int)Math.sqrt(n)*B; // not overflow!\n\t\t\tcachelimit = s;\n\t\t\tthis.primes = sieveEratosthenes(s);\n\t\t\txcums = new int[(s>>>6)+1];\n\t\t\tisp = new long[(s>>>6)+1];\n\t\t\tfor(int p : primes)isp[p>>>6] |= 1L<>>6] + Long.bitCount(isp[ix>>>6]<<~ix);\n//\t\t\t\treturn cump[(int)x];\n\t\t\t}\n\t\t\tif(picache.containsKey(x))return picache.get(x);\n\t\t\t\n\t\t\tint A = (int)pi(sqrt(sqrt(x)));\n\t\t\tlong ret = A + phi(x, A) - P2(x, A) - P3(x, A) - 1;\n\t\t\tpicache.put(x, ret);\n\t\t\treturn ret;\n\t\t}\n\t\t\n\t\tprivate long phi(long x, int A)\n\t\t{\n\t\t\tif(A > 0 && A-1 < M){\n\t\t\t\treturn cumps[A-1][FP[A-1]] * (x/FP[A-1]) + cumps[A-1][(int)(x%FP[A-1]+1)];\n\t\t\t}\n\t\t\tif(A > 0 && x <= (long)primes[A-1]*primes[A-1]){\n\t\t\t\treturn pi(x) - A + 1;\n\t\t\t}\n\t\t\tlong code = x<<13|A;\n\t\t\tif(phicache.containsKey(code))return phicache.get(code);\n\t\t\t\n\t\t\tlong ret = x;\n\t\t\tfor(int i = A-1;i >= 0;i--)ret -= phi(x/primes[i], i);\n\t\t\t\n\t\t\tif(cachePhi)phicache.put(code, ret);\n\t\t\treturn ret;\n\t\t}\n\t\t\n\t\tprivate long P2(long x, int A)\n\t\t{\n\t\t\tint B = (int)pi(sqrt(x));\n\t\t\tlong ret = 0;\n\t\t\tfor(int i = A;i < B;i++){\n\t\t\t\tret += pi(x/primes[i]);\n\t\t\t}\n\t\t\tret -= (long)(B-A)*(B+A-1)/2;\n\t\t\treturn ret;\n\t\t}\n\t\t\n\t\tprivate long P3(long x, int A)\n\t\t{\n\t\t\tint C = (int)pi(cbrt(x));\n\t\t\tlong ret = 0;\n\t\t\tfor(int i = A;i < C;i++){\n\t\t\t\tlong xi = x/primes[i];\n\t\t\t\tint B = (int)pi(sqrt(xi));\n\t\t\t\tfor(int j = i;j < B;j++){\n\t\t\t\t\tret += pi(xi/primes[j]) - j;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn ret;\n\t\t}\n\t\t\n\t\tpublic static int[] sieveEratosthenes(int n) {\n\t\t\tif (n <= 32) {\n\t\t\t\tint[] primes = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 };\n\t\t\t\tfor (int i = 0; i < primes.length; i++) {\n\t\t\t\t\tif (n < primes[i]) {\n\t\t\t\t\t\treturn Arrays.copyOf(primes, i);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn primes;\n\t\t\t}\n\n\t\t\tint u = n + 32;\n\t\t\tdouble lu = Math.log(u);\n\t\t\tint[] ret = new int[(int) (u / lu + u / lu / lu * 1.5)];\n\t\t\tret[0] = 2;\n\t\t\tint pos = 1;\n\n\t\t\tint[] isnp = new int[(n + 1) / 32 / 2 + 1];\n\t\t\tint sup = (n + 1) / 32 / 2 + 1;\n\n\t\t\tint[] tprimes = { 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 };\n\t\t\tfor (int tp : tprimes) {\n\t\t\t\tret[pos++] = tp;\n\t\t\t\tint[] ptn = new int[tp];\n\t\t\t\tfor (int i = (tp - 3) / 2; i < tp << 5; i += tp)\n\t\t\t\t\tptn[i >> 5] |= 1 << (i & 31);\n\t\t\t\tfor (int j = 0; j < sup; j += tp) {\n\t\t\t\t\tfor (int i = 0; i < tp && i + j < sup; i++) {\n\t\t\t\t\t\tisnp[j + i] |= ptn[i];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// 3,5,7\n\t\t\t// 2x+3=n\n\t\t\tint[] magic = { 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, 31, 22, 28, 18, 26, 10, 7, 12, 21, 17,\n\t\t\t\t\t9, 6, 16, 5, 15, 14 };\n\t\t\tint h = n / 2;\n\t\t\tfor (int i = 0; i < sup; i++) {\n\t\t\t\tfor (int j = ~isnp[i]; j != 0; j &= j - 1) {\n\t\t\t\t\tint pp = i << 5 | magic[(j & -j) * 0x076be629 >>> 27];\n\t\t\t\t\tint p = 2 * pp + 3;\n\t\t\t\t\tif (p > n)\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tret[pos++] = p;\n\t\t\t\t\tif ((long) p * p > n)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tfor (int q = (p * p - 3) / 2; q <= h; q += p)\n\t\t\t\t\t\tisnp[q >> 5] |= 1 << q;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn Arrays.copyOf(ret, pos);\n\t\t}\n\t\t\n\t\tprivate static class LongHashCounterL {\n\t\t\tpublic long[] keys;\n\t\t\tpublic long[] allocated;\n\t\t\tprivate int scale = 1<<2;\n\t\t\tprivate int rscale = 1<<1;\n\t\t\tprivate int mask = scale-1;\n\t\t\tpublic int size = 0;\n\t\t\t\n\t\t\tpublic LongHashCounterL(){\n\t\t\t\tallocated = new long[scale];\n\t\t\t\tArrays.fill(allocated, NG);\n\t\t\t\tkeys = new long[scale];\n\t\t\t}\n\t\t\t\n\t\t\t// if value is NG, entry is removed. (e.g. 0)\n\t\t\tprivate static final int NG = 0;\n\t\t\t\n\t\t\tpublic boolean containsKey(long x)\n\t\t\t{\n\t\t\t\tint pos = h(x)&mask;\n\t\t\t\twhile(allocated[pos] != NG){\n\t\t\t\t\tif(x == keys[pos])return true;\n\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t}\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\t\n\t\t\tpublic long get(long x)\n\t\t\t{\n\t\t\t\tint pos = h(x)&mask;\n\t\t\t\twhile(allocated[pos] != NG){\n\t\t\t\t\tif(x == keys[pos])return allocated[pos];\n\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t}\n\t\t\t\treturn NG;\n\t\t\t}\n\t\t\t\n\t\t\tpublic long put(long x, long v)\n\t\t\t{\n\t\t\t\tint pos = h(x)&mask;\n\t\t\t\twhile(allocated[pos] != NG){\n\t\t\t\t\tif(x == keys[pos]){\n\t\t\t\t\t\tlong oldval = allocated[pos];\n\t\t\t\t\t\tallocated[pos] = v;\n\t\t\t\t\t\treturn oldval;\n\t\t\t\t\t}\n\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t}\n\t\t\t\tif(size == rscale){\n\t\t\t\t\tresizeAndPut(x, v);\n\t\t\t\t}else{\n\t\t\t\t\tkeys[pos] = x;\n\t\t\t\t\tallocated[pos] = v;\n\t\t\t\t}\n\t\t\t\tsize++;\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\t\n\t\t\tpublic long inc(long x, long v)\n\t\t\t{\n\t\t\t\tint pos = h(x)&mask;\n\t\t\t\twhile(allocated[pos] != NG){\n\t\t\t\t\tif(x == keys[pos]){\n\t\t\t\t\t\tallocated[pos] += v;\n\t\t\t\t\t\treturn allocated[pos];\n\t\t\t\t\t}\n\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t}\n\t\t\t\tif(size == rscale){\n\t\t\t\t\tresizeAndPut(x, v);\n\t\t\t\t}else{\n\t\t\t\t\tkeys[pos] = x;\n\t\t\t\t\tallocated[pos] = v;\n\t\t\t\t}\n\t\t\t\tsize++;\n\t\t\t\treturn v;\n\t\t\t}\n\t\t\t\n\t\t\tpublic boolean remove(long x)\n\t\t\t{\n\t\t\t\tint pos = h(x)&mask;\n\t\t\t\twhile(allocated[pos] != NG){\n\t\t\t\t\tif(x == keys[pos]){\n\t\t\t\t\t\tsize--;\n\t\t\t\t\t\t// take last and fill rmpos\n\t\t\t\t\t\tint last = pos;\n\t\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t\t\twhile(allocated[pos] != NG){\n\t\t\t\t\t\t\tint lh = h(keys[pos])&mask;\n\t\t\t\t\t\t\t// lh <= last < pos\n\t\t\t\t\t\t\tif(\n\t\t\t\t\t\t\t\t\tlh <= last && last < pos ||\n\t\t\t\t\t\t\t\t\tpos < lh && lh <= last ||\n\t\t\t\t\t\t\t\t\tlast < pos && pos < lh\n\t\t\t\t\t\t\t\t\t){\n\t\t\t\t\t\t\t\tkeys[last] = keys[pos];\n\t\t\t\t\t\t\t\tallocated[last] = allocated[pos];\n\t\t\t\t\t\t\t\tlast = pos;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tkeys[last] = 0;\n\t\t\t\t\t\tallocated[last] = NG;\n\t\t\t\t\t\t\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t}\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\t\n\t\t\tprivate void resizeAndPut(long x, long v)\n\t\t\t{\n\t\t\t\tint nscale = scale<<1;\n\t\t\t\tint nrscale = rscale<<1;\n\t\t\t\tint nmask = nscale-1;\n\t\t\t\tlong[] nallocated = new long[nscale];\n\t\t\t\tArrays.fill(nallocated, NG);\n\t\t\t\tlong[] nkeys = new long[nscale];\n\t\t\t\tfor(int i = next(0);i < scale;i = next(i+1)){\n\t\t\t\t\tlong y = keys[i];\n\t\t\t\t\tint pos = h(y)&nmask;\n\t\t\t\t\twhile(nallocated[pos] != NG)pos = pos+1&nmask;\n\t\t\t\t\tnkeys[pos] = y;\n\t\t\t\t\tnallocated[pos] = allocated[i];\n\t\t\t\t}\n\t\t\t\t{\n\t\t\t\t\tint pos = h(x)&nmask;\n\t\t\t\t\twhile(nallocated[pos] != NG)pos = pos+1&nmask;\n\t\t\t\t\tnkeys[pos] = x;\n\t\t\t\t\tnallocated[pos] = v;\n\t\t\t\t}\n\t\t\t\tallocated = nallocated;\n\t\t\t\tkeys = nkeys;\n\t\t\t\tscale = nscale;\n\t\t\t\trscale = nrscale;\n\t\t\t\tmask = nmask;\n\t\t\t}\n\t\t\t\n\t\t\tpublic int next(int itr)\n\t\t\t{\n\t\t\t\twhile(itr < scale && allocated[itr] == NG)itr++;\n\t\t\t\treturn itr;\n\t\t\t}\n\t\t\t\n\t\t\tprivate int h(long x)\n\t\t\t{\n\t\t\t\tx ^= x>>>33;\n\t\t\t\tx *= 0xff51afd7ed558ccdL;\n\t\t\t\tx ^= x>>>33;\n\t\t\t\tx *= 0xc4ceb9fe1a85ec53L;\n\t\t\t\tx ^= x>>>33;\n\t\t\t\treturn (int)x;\n\t\t\t}\n\t\t\t\n\t\t\t@Override\n\t\t\tpublic String toString()\n\t\t\t{\n\t\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\t\tfor(int i = next(0);i < scale;i = next(i+1)){\n\t\t\t\t\tsb.append(\",\");\n\t\t\t\t\tsb.append(keys[i] + \":\" + allocated[i]);\n\t\t\t\t}\n\t\t\t\treturn sb.length() == 0 ? \"\" : sb.substring(1);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception { new F3().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "tags": ["math", "dp", "sortings", "data structures", "two pointers", "number theory"], "code_uid": "555a74def4606898ff1ff5a90dcb0954", "src_uid": "ffb7762f1d60dc3f16e9b27ea0ecdd7d", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main implements Runnable{\n public static void main(String[] args){\n //new Thread(null,new Main(),\"Thread-1\",1024*1024*10).start();\n new Main().run();\n }\n int mod=998244353;\n private void solve() throws Exception {\n InputReader in = new InputReader(System.in);\n PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n int n=in.nextInt(),k=in.nextInt(),l=in.nextInt();\n long[]fac=new long[n+1];\n fac[0]=1;\n for(int i=1;i<=n;i++){\n fac[i]=fac[i-1]*i%mod;\n }\n long[][]dp=new long[2*n+1][2*n+2];\n dp[0][0]=1;\n for(int i=1;i<=2*n;i++){\n for(int j=0;j<=i;j++){\n if(j>0) dp[i][j]=(dp[i][j]+dp[i-1][j-1])%mod;\n dp[i][j]=(dp[i][j]+dp[i-1][j+1]*(j+1)%mod)%mod;\n }\n }\n long ans=0;\n for(int i=k;i<=2*n;i++){\n for(int j=k;j<=n;j++){\n ans=(ans+dp[i][j]*dp[2*n-i][j]%mod*fac[j]%mod)%mod;\n }\n }\n out.println(l*ans%mod*Pow(dp[2*n][0],mod-2)%mod*Pow(2*n+1,mod-2)%mod);\n out.flush();\n }\n long Pow(long a,long b){\n long ans=1;\n while(b>0){\n if((b&1)!=0)ans=(ans*a)%mod;\n a=(a*a)%mod;\n b>>=1;\n }\n return ans;\n }\n @Override\n public void run() {\n try {\n solve();\n } catch (Exception e) {\n e.printStackTrace();\n }\n }\n class InputReader{\n StreamTokenizer tokenizer;\n public InputReader(InputStream stream){\n tokenizer=new StreamTokenizer(new BufferedReader(new InputStreamReader(stream)));\n tokenizer.ordinaryChars(33,126);\n tokenizer.wordChars(33,126);\n }\n public String next() throws IOException {\n tokenizer.nextToken();\n return tokenizer.sval;\n }\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n public boolean hasNext() throws IOException {\n int res=tokenizer.nextToken();\n tokenizer.pushBack();\n return res!=tokenizer.TT_EOF;\n }\n }\n}", "lang_cluster": "Java", "tags": ["probabilities", "math", "dp", "combinatorics"], "code_uid": "b72fb2f7a4b393a8e3278001aaa12a52", "src_uid": "c9e79e83928d5d034123ebc3b2f5e064", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class E {\n\t\n\tstatic int[] tree;\n\t\n\tstatic void fill(int idx) {\n\t\tif (idx >= tree.length) return;\n\t\tfill(2 * idx);\n\t\tfill(2 * idx + 1);\n\t\ttree[idx] = 1;\n\t\tif (2 * idx < tree.length) tree[idx] += tree[2 * idx];\n\t\tif (2 * idx + 1 < tree.length) tree[idx] += tree[2 * idx + 1];\n\t}\n\t\n\tstatic boolean shouldAdd(int idx) {\n\t\tif (idx % 2 == 1) return true;\n\t\twhile (idx % 2 == 0) {\n\t\t\tidx /= 2;\n\t\t}\n\t\treturn tree[2 * idx] % 2 == 0;\n\t}\n\t\n\tstatic void add(int idx) {\n\t\twhile (idx >= 1) {\n\t\t\ttree[idx]++;\n\t\t\tidx /= 2;\n\t\t}\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tMyScanner sc = new MyScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint N = sc.nextInt();\n\t\tint level = 0, got = 1;\n\t\twhile (N >= got) {\n\t\t\tN -= got;\n\t\t\tlevel++;\n\t\t\tgot *= 2;\n\t\t}\n\t\ttree = new int[1 << level];\n\t\tfill(1);\n\t\tfor (int i = tree.length - 1; i > 1 << (level-1); i--) {\n\t\t\tif (shouldAdd(i)) {\n\t\t\t\tadd(i);\n\t\t\t\tN--;\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.println(N == 0 || N == 1 ? 1 : 0);\n\t\t\n\t\tout.flush();\n\t}\n\t\n\tstatic class MyScanner {\n\t\tprivate BufferedReader br;\n\t\tprivate StringTokenizer tokenizer;\n\t\t\n\t\tpublic MyScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\t\t\n\t\tpublic String next() {\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\ttokenizer = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\t\t\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\t\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "dp"], "code_uid": "30b8ecacac4f21f7185cee754cd0b99d", "src_uid": "821409c1b9bdcd18c4dcf35dc5116501", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n \npublic class Main implements Runnable {\n final boolean isFileIO = false; \n BufferedReader in;\n PrintWriter out;\n StringTokenizer st = new StringTokenizer(\"\");\n String delim = \" \";\n\n public static void main(String[] args) {\n new Thread(null, new Main(), \"\", 268435456).start(); \n }\n\n public void run() {\n try {\n initIO();\n solve();\n out.close();\n } catch(Exception e) {\n e.printStackTrace(System.err);\n System.exit(-1);\n }\n }\n\n public void initIO() throws IOException {\n if(!isFileIO) {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n } else {\n in = new BufferedReader(new FileReader(\"input.txt\"));\n out = new PrintWriter(\"output.txt\"); \n }\n }\n \n String nextToken() throws IOException {\n if(!st.hasMoreTokens()) {\n st = new StringTokenizer(in.readLine());\n }\n return st.nextToken(delim);\n }\n \n String readLine() throws IOException {\n return in.readLine();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n \n void solve() throws IOException {\n int[] a = new int[4];\n int[] b = new int[4];\n for(int i = 0; i < 4; i++) {\n a[i] = nextInt(); b[i] =nextInt();\n }\n\n boolean isWin = true;\n for(int i = 0; i < 2; i++) {\n isWin = true;\n for(int j = 0; j < 2; j++) {\n if(!(a[i] > b[j + 2] && b[1 - i] > a[3 - j]))\n isWin = false;\n }\n if(isWin) {\n out.println(\"Team 1\");\n return;\n }\n }\n for(int i = 0; i < 2; i++) {\n isWin = false;\n for(int j = 0; j < 2; j++) {\n if(b[i] < a[j + 2] && a[1 - i] < b[3 - j]) {\n isWin = true;\n break;\n }\n }\n if(!isWin) {\n out.println(\"Draw\");\n return;\n }\n }\n if(isWin) {\n out.println(\"Team 2\");\n return;\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "f25787ee1e4e0cec1079226bad5394bd", "src_uid": "1a70ed6f58028a7c7a86e73c28ff245f", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.util.*;\npublic class Main {\n public static void main(String[] args) {\n Scanner sc=new Scanner(System.in);\n\n //System.out.println(qmod(2,5,100));\n\n\n long S[][]=new long[5005][5005];\n long mod=998244353;\n S[1][1]=1;\n S[0][0]=0;\n for(int i=1;i<=5000;i++){\n S[i][i]=1;S[i][0]=0;\n }\n for(int i=2;i<=5000;i++){\n for(int j=1;j<=i;j++){\n S[i][j]=(S[i-1][j]*j%mod+S[i-1][j-1])%mod;\n }\n }\n long n=sc.nextLong();long m=sc.nextLong();int k=sc.nextInt();\n m=qmod(m,mod-2,mod);\n long dp[]=new long[5005];dp[0]=1;\n for(int i=1;i<=Math.min(n,k);i++)dp[i]=dp[i-1]*(n-i+1)%mod;\n\n\n long ans=0;\n for(int i=1;i<=Math.min(n,k);i++){\n ans=(ans+dp[i]*qmod(m,i,mod)%mod*S[k][i]%mod)%mod;\n }\n System.out.println(ans);\n\n }\n public static long qmod(long a,long b,long mod){\n long ans=1;\n while(b>=1){\n\n if((b&1)!=0){\n ans=ans*a%mod;\n }\n a=a*a%mod;\n b=b>>1;\n }return ans;\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics", "probabilities", "number theory"], "code_uid": "3e67988d8af9d995a69f2994c4c62a57", "src_uid": "e6b3e559b5fd4e05adf9f1cd1b22126b", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.InputMismatchException;\nimport java.util.ArrayList;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author RiaD\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tReader in = new Reader(inputStream);\n\t\tOutputWriter out = new OutputWriter(outputStream);\n\t\tTaskD solver = new TaskD();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskD {\n public void solve(int testNumber, Reader in, OutputWriter out) {\n long n = in.nextLong();\n ArrayList lengths = new ArrayList();\n long ones = n;\n boolean[] used = new boolean[101010];\n for(int i = 2; i * i <= n; ++i){\n if (used[i])\n continue;\n long j = i;\n int len = 0;\n while(j <= n) {\n if(j < 101010)\n used[(int)j] = true;\n ++len;\n j *= i;\n }\n\n lengths.add(len);\n ones -= len;\n }\n\n long gandy = 0;\n\n if(ones % 2 != 0)\n gandy ^= gandy(1);\n long[] dp = new long[30];\n for(int i = 0; i < 30; ++i) {\n dp[i] = gandy(i);\n }\n for (Integer length : lengths) {\n gandy ^= dp[length];\n }\n\n out.println(gandy == 0 ? \"Petya\" : \"Vasya\");\n }\n\n private long gandy(int length) {\n if (length == 0) return 0;\n if (length == 1) return 1;\n if (length == 2) return 2;\n if (length == 3) return 1;\n if (length == 4) return 4;\n if (length == 5) return 3;\n if (length == 6) return 2;\n if (length == 7) return 1;\n if (length == 8) return 5;\n if (length == 9) return 6;\n if (length == 10) return 2;\n if (length == 11) return 1;\n if (length == 12) return 8;\n if (length == 13) return 7;\n if (length == 14) return 5;\n if (length == 15) return 9;\n if (length == 16) return 8;\n if (length == 17) return 7;\n if (length == 18) return 3;\n if (length == 19) return 4;\n if (length == 20) return 7;\n if (length == 21) return 4;\n if (length == 22) return 2;\n if (length == 23) return 1;\n if (length == 24) return 10;\n if (length == 25) return 9;\n if (length == 26) return 3;\n if (length == 27) return 6;\n if (length == 28) return 11;\n if (length == 29) return 12;\n throw new AssertionError();\n }\n}\n\nclass Reader {\n private BufferedReader reader;\n private StringTokenizer tokenizer;\n\n public Reader(BufferedReader reader) {\n this.reader = reader;\n }\n\n public Reader(InputStream stream) {\n this(new BufferedReader(new InputStreamReader(stream)));\n }\n\n public String nextString() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(readLine());\n }\n return tokenizer.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(nextString());\n }\n\n private String readLine() {\n try {\n return reader.readLine();\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n}\n\nclass OutputWriter extends PrintWriter {\n\n\tpublic OutputWriter(OutputStream out) {\n\t\tsuper(out);\n\t}\n\n\tpublic OutputWriter(java.io.Writer writer){\n\t\tsuper(writer);\n\t}\n\n\t}", "lang_cluster": "Java", "tags": ["dp", "games"], "code_uid": "9f648fb4d13e656974b4a4ec6e16a82a", "src_uid": "0e22093668319217b7946e62afe32195", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n FastScanner in;\n PrintWriter out;\n\n int gcd(int x, int y) {\n return x == 0 ? y : gcd(y % x, x);\n }\n\n int getCost(int n, boolean[] already) {\n boolean[] z = new boolean[n];\n for (int x = 3; x < n; x++) {\n if (!already[x]) {\n continue;\n }\n int g = gcd(n, x);\n int add = n / g;\n for (int i = 0; i < n; i += add) {\n z[i] = true;\n }\n }\n int cost = 0;\n for (int i = 0; i < n; i++) {\n cost += z[i] ? 0 : 1;\n }\n return cost;\n }\n\n int getAns(int maxN, int k) {\n int res = 0;\n boolean[] already = new boolean[maxN + 1];\n int[] costA = new int[maxN + 1];\n for (int it = 0; it < k; it++) {\n int mincost = Integer.MAX_VALUE;\n int minVal = -1;\n for (int n = 3; n <= maxN; n++) {\n if (already[n]) {\n continue;\n }\n int cost = getCost(n, already);\n if (cost < mincost) {\n mincost = cost;\n minVal = n;\n }\n }\n already[minVal] = true;\n res += mincost;\n// System.err.println(\"! \" + minVal + \" \" + mincost);\n costA[minVal] = mincost;\n }\n// System.err.println(Arrays.toString(costA));\n return res;\n }\n\n void solve() {\n int n = in.nextInt();\n int k = in.nextInt();\n out.println(solve(n, k));\n }\n\n void solvesd() {\n for (int n = 10; n <= 15; n++) {\n System.err.println(\"n = \" + n);\n for (int k = 1; k + 2 <= n; k++) {\n long correct = getAns(n, k);\n long my = solve(n, k);\n if (correct != my) {\n throw new AssertionError(n + \" \" + k + \" \" + correct + \" \" + my);\n }\n }\n }\n }\n\n long solve(int maxN, int k) {\n final int MAX = (int) 1e6 + 10;\n int[] prime = new int[MAX];\n Arrays.fill(prime, -1);\n for (int i = 2; i < MAX; i++) {\n if (prime[i] == -1) {\n for (int j = i; j < MAX; j += i) {\n prime[j] = i;\n }\n }\n }\n int[] phi = new int[MAX];\n for (int i = 2; i < MAX; i++) {\n int n = i;\n int result = n;\n while (n != 1) {\n int pr = prime[n];\n while (n % pr == 0) {\n n /= pr;\n }\n result -= result / pr;\n }\n phi[i] = result;\n }\n long cost = 1;\n if (k >= 2) {\n cost++;\n }\n List[] where = new ArrayList[MAX + 1];\n for (int i = 0; i < where.length; i++) {\n where[i] = new ArrayList<>();\n }\n// System.err.println(\"NEED \" + k);\n for (int i = 3; i <= maxN; i++) {\n where[phi[i]].add(i);\n// System.err.println(\"!\" + phi[i]);\n }\n for (int c = 2; k != 0; c++) {\n int sz = where[c].size();\n int use = Math.min(k, sz);\n k -= use;\n cost += c * 1L * use;\n }\n return cost;\n }\n\n void solve22() {\n// for (int n = 3; n <= 40; n++) {\n// for (int k = 1; k <= n - 3; k++) {\n// System.err.print(getAns(n, k) + \" \");\n// }\n// System.err.println();\n// }\n getAns(60, 50);\n// out.println(getAns(in.nextInt(), in.nextInt()));\n }\n\n void solve123() {\n for (int n = 3; n <= 50; n++) {\n boolean[] z = new boolean[n];\n for (int x = 3; x < n; x++) {\n int g = gcd(n, x);\n int add = n / g;\n for (int i = 0; i < n; i += add) {\n z[i] = true;\n }\n }\n int cost = 0;\n for (int i = 0; i < n; i++) {\n cost += z[i] ? 0 : 1;\n }\n System.err.println(n + \" -> \" + cost);\n }\n }\n\n\n void run() {\n try {\n in = new FastScanner(new File(\"A.in\"));\n out = new PrintWriter(new File(\"A.out\"));\n\n solve();\n\n out.close();\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n\n void runIO() {\n\n in = new FastScanner(System.in);\n out = new PrintWriter(System.out);\n\n solve();\n\n out.close();\n }\n\n class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(File f) {\n try {\n br = new BufferedReader(new FileReader(f));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n\n public FastScanner(InputStream f) {\n br = new BufferedReader(new InputStreamReader(f));\n }\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return null;\n st = new StringTokenizer(s);\n }\n return st.nextToken();\n }\n\n boolean hasMoreTokens() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return false;\n st = new StringTokenizer(s);\n }\n return true;\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n\n public static void main(String[] args) {\n new A().runIO();\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "greedy", "number theory"], "code_uid": "25ad3abb85e501091b6d871f64737924", "src_uid": "c2f7012082c84d773c2f4b1858c17110", "difficulty": 2800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Problems {\n\n public static void main(String[] args) throws IOException {\n\n new Problems().runMain();\n }\n\n void runMain() {\n\t\tScanner sc = new Scanner(System.in);\n \n int n = sc.nextInt(); \n int a[] = new int[n];\n int b[] = new int[n];\n float max = 0;\n for (int i = 0; i < n; i++) {\n \ta[i] = sc.nextInt();\n \tif (i > 0) {\n \t\tmax = lcm(a[i], (long)max);\n \t} else {\n \t\tmax = a[0];\n \t}\n }\n for (int i = 0; i < n; i++) {\n \tb[i] = sc.nextInt();\n }\n \n float counter = 0;\n for (int i = 0; i < max; i++) {\n \tfor (int j = 0; j < n; j++) {\n \t\tif (i % a[j] == b[j]) {\n \t\t\tcounter++;\n \t\t\tbreak;\n \t\t}\n \t} \t\n }\n System.out.printf(\"%.5f\", counter/max);\n }\n \n long gcd(long a, long b){\n \treturn b == 0 ? a : gcd(b,a % b);\t\t\n }\n \n long lcm(long a, long b){\n \treturn a / gcd(a,b) * b;\n }\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "e5f5acd219f78eee698aedac0cbbea52", "src_uid": "14b69f42bc192ea472e82f3a3209f1c1", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.AbstractMap;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collection;\nimport java.util.Comparator;\nimport java.util.Iterator;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.NoSuchElementException;\nimport java.util.Set;\nimport java.util.SortedMap;\nimport java.util.SortedSet;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.function.BiConsumer;\nimport java.util.function.Consumer;\nimport java.util.function.Function;\nimport java.util.function.Supplier;\nimport java.util.stream.Stream;\n\npublic class E_418\n{\n\tpublic static final long[] POWER2 = generatePOWER2();\n\tpublic static final BigInteger[] FACULTY_BIG = generateFacultyBig();\n\tpublic static final BigInteger TWO = BigInteger.valueOf(2);\n\tpublic static final long BIG = 1000000007;\n\tpublic static final IteratorBuffer ITERATOR_BUFFER_PRIME = new IteratorBuffer<>(streamPrime(1000000).iterator());\n\tprivate static BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));\n\tprivate static StringTokenizer stringTokenizer = null;\n\tprivate static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n\n\tinterface BiFunctionResult\n\t{\n\t\tTypeResult apply(Type0 x0, Type1 x1, TypeResult x2);\n\t}\n\n\tstatic class Array implements Iterable\n\t{\n\t\tprivate Object[] array;\n\n\t\tpublic Array(int size)\n\t\t{\n\t\t\tthis.array = new Object[size];\n\t\t}\n\n\t\tpublic Array(int size, Type element)\n\t\t{\n\t\t\tthis(size);\n\t\t\tArrays.fill(this.array, element);\n\t\t}\n\n\t\tpublic Array(Array array, Type element)\n\t\t{\n\t\t\tthis(array.size() + 1);\n\t\t\tfor (int index = 0; index < array.size(); index++)\n\t\t\t{\n\t\t\t\tset(index, array.get(index));\n\t\t\t}\n\t\t\tset(size() - 1, element);\n\t\t}\n\n\t\tpublic Array(List list)\n\t\t{\n\t\t\tthis(list.size());\n\t\t\tint index = 0;\n\t\t\tfor (Type element : list)\n\t\t\t{\n\t\t\t\tset(index, element);\n\t\t\t\tindex += 1;\n\t\t\t}\n\t\t}\n\n\t\tpublic Type get(int index)\n\t\t{\n\t\t\treturn (Type) this.array[index];\n\t\t}\n\n\t\tpublic Array set(int index, Type value)\n\t\t{\n\t\t\tthis.array[index] = value;\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic int size()\n\t\t{\n\t\t\treturn this.array.length;\n\t\t}\n\n\t\tpublic List toList()\n\t\t{\n\t\t\tList result = new ArrayList<>();\n\t\t\tfor (Type element : this)\n\t\t\t{\n\t\t\t\tresult.add(element);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic Iterator iterator()\n\t\t{\n\t\t\treturn new Iterator()\n\t\t\t{\n\t\t\t\tint index = 0;\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean hasNext()\n\t\t\t\t{\n\t\t\t\t\treturn this.index < size();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic Type next()\n\t\t\t\t{\n\t\t\t\t\tType result = Array.this.get(index);\n\t\t\t\t\tindex += 1;\n\t\t\t\t\treturn result;\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn \"[\" + E_418.toString(this, \", \") + \"]\";\n\t\t}\n\t}\n\n\tstatic abstract class Edge, TypeEdge extends Edge>\n\t{\n\t\tpublic final TypeVertex vertex0;\n\t\tpublic final TypeVertex vertex1;\n\t\tpublic final boolean bidirectional;\n\n\t\tpublic Edge(TypeVertex vertex0, TypeVertex vertex1, boolean bidirectional)\n\t\t{\n\t\t\tthis.vertex0 = vertex0;\n\t\t\tthis.vertex1 = vertex1;\n\t\t\tthis.bidirectional = bidirectional;\n\t\t\tthis.vertex0.edges.add(getThis());\n\t\t\tif (this.bidirectional)\n\t\t\t{\n\t\t\t\tthis.vertex1.edges.add(getThis());\n\t\t\t}\n\t\t}\n\n\t\tpublic TypeVertex other(Vertex vertex)\n\t\t{\n\t\t\tTypeVertex result;\n\t\t\tif (vertex0 == vertex)\n\t\t\t{\n\t\t\t\tresult = vertex1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = vertex0;\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic abstract TypeEdge getThis();\n\n\t\tpublic void remove()\n\t\t{\n\t\t\tthis.vertex0.edges.remove(getThis());\n\t\t\tif (this.bidirectional)\n\t\t\t{\n\t\t\t\tthis.vertex1.edges.remove(getThis());\n\t\t\t}\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn this.vertex0 + \"->\" + this.vertex1;\n\t\t}\n\t}\n\n\tpublic static class EdgeDefault>> extends Edge>\n\t{\n\t\tpublic EdgeDefault(TypeVertex vertex0, TypeVertex vertex1, boolean bidirectional)\n\t\t{\n\t\t\tsuper(vertex0, vertex1, bidirectional);\n\t\t}\n\n\t\t@Override\n\t\tpublic EdgeDefault getThis()\n\t\t{\n\t\t\treturn this;\n\t\t}\n\t}\n\n\tpublic static class Vertex, TypeEdge extends Edge> implements Comparable>\n\t{\n\t\tpublic static , TypeEdge extends Edge> void depthFirstSearch(\n\t\t\t\tArray vertices,\n\t\t\t\tint indexVertexStart,\n\t\t\t\tBiConsumer functionPreVisit,\n\t\t\t\tBiConsumer functionInVisit,\n\t\t\t\tBiConsumer functionPostVisit\n\t\t)\n\t\t{\n\t\t\tTypeVertex vertexTo;\n\t\t\tTypeEdge edgeTo;\n\t\t\tboolean[] isOnStack = new boolean[vertices.size()];\n\t\t\tStack stackOperations = new Stack<>();\n\t\t\tStack stackVertices = new Stack<>();\n\t\t\tStack stackEdges = new Stack<>();\n\n\t\t\tTypeVertex vertexStart = vertices.get(indexVertexStart);\n\t\t\tstackOperations.push(Operation.EXPAND);\n\t\t\tstackVertices.push(vertexStart);\n\t\t\tstackEdges.push(null);\n\t\t\tisOnStack[vertexStart.index] = true;\n\t\t\twhile (!stackOperations.isEmpty())\n\t\t\t{\n\t\t\t\tOperation operation = stackOperations.pop();\n\t\t\t\tTypeVertex vertex = stackVertices.pop();\n\t\t\t\tTypeEdge edge = stackEdges.pop();\n\t\t\t\tswitch (operation)\n\t\t\t\t{\n\t\t\t\t\tcase INVISIT:\n\t\t\t\t\t\tfunctionInVisit.accept(vertex, edge);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase POSTVISIT:\n\t\t\t\t\t\tfunctionPostVisit.accept(vertex, edge);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase EXPAND:\n\t\t\t\t\t\tstackOperations.push(Operation.POSTVISIT);\n\t\t\t\t\t\tstackVertices.push(vertex);\n\t\t\t\t\t\tstackEdges.push(edge);\n\t\t\t\t\t\tInteger indexTo = null;\n\t\t\t\t\t\tfor (int index = 0; indexTo == null && index < vertex.edges.size(); index++)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tedgeTo = vertex.edges.get(index);\n\t\t\t\t\t\t\tvertexTo = edgeTo.other(vertex);\n\t\t\t\t\t\t\tif (!isOnStack[vertexTo.index])\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tindexTo = index;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (indexTo != null)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tedgeTo = vertex.edges.get(indexTo);\n\t\t\t\t\t\t\tvertexTo = edgeTo.other(vertex);\n\t\t\t\t\t\t\tstackOperations.push(Operation.EXPAND);\n\t\t\t\t\t\t\tstackVertices.push(vertexTo);\n\t\t\t\t\t\t\tstackEdges.push(edgeTo);\n\t\t\t\t\t\t\tisOnStack[vertexTo.index] = true;\n\t\t\t\t\t\t\tfor (int index = indexTo + 1; index < vertex.edges.size(); index++)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tedgeTo = vertex.edges.get(index);\n\t\t\t\t\t\t\t\tvertexTo = edgeTo.other(vertex);\n\t\t\t\t\t\t\t\tif (!isOnStack[vertexTo.index])\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tstackOperations.push(Operation.INVISIT);\n\t\t\t\t\t\t\t\t\tstackVertices.push(vertex);\n\t\t\t\t\t\t\t\t\tstackEdges.push(edge);\n\t\t\t\t\t\t\t\t\tstackOperations.push(Operation.EXPAND);\n\t\t\t\t\t\t\t\t\tstackVertices.push(vertexTo);\n\t\t\t\t\t\t\t\t\tstackEdges.push(edgeTo);\n\t\t\t\t\t\t\t\t\tisOnStack[vertexTo.index] = true;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfunctionPreVisit.accept(vertex, edge);\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tpublic static , TypeEdge extends Edge> void depthFirstSearch(\n\t\t\t\tArray vertices,\n\t\t\t\tint indexVertexStart,\n\t\t\t\tConsumer functionPreVisit,\n\t\t\t\tConsumer functionInVisit,\n\t\t\t\tConsumer functionPostVisit\n\t\t)\n\t\t{\n\t\t\tdepthFirstSearch(\n\t\t\t\t\tvertices,\n\t\t\t\t\tindexVertexStart,\n\t\t\t\t\t(vertex, edge) -> functionPreVisit.accept(vertex),\n\t\t\t\t\t(vertex, edge) -> functionInVisit.accept(vertex),\n\t\t\t\t\t(vertex, edge) -> functionPostVisit.accept(vertex)\n\t\t\t);\n\t\t}\n\n\t\tpublic static , TypeEdge extends Edge, TypeResult> TypeResult breadthFirstSearch(\n\t\t\t\tTypeVertex vertex,\n\t\t\t\tTypeEdge edge,\n\t\t\t\tBiFunctionResult function,\n\t\t\t\tArray visited,\n\t\t\t\tFIFO verticesNext,\n\t\t\t\tFIFO edgesNext,\n\t\t\t\tTypeResult result\n\t\t)\n\t\t{\n\t\t\tif (!visited.get(vertex.index))\n\t\t\t{\n\t\t\t\tvisited.set(vertex.index, true);\n\t\t\t\tresult = function.apply(vertex, edge, result);\n\t\t\t\tfor (TypeEdge edgeNext : vertex.edges)\n\t\t\t\t{\n\t\t\t\t\tTypeVertex vertexNext = edgeNext.other(vertex);\n\t\t\t\t\tif (!visited.get(vertexNext.index))\n\t\t\t\t\t{\n\t\t\t\t\t\tverticesNext.push(vertexNext);\n\t\t\t\t\t\tedgesNext.push(edgeNext);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static , TypeEdge extends Edge, TypeResult> TypeResult breadthFirstSearch(\n\t\t\t\tArray vertices,\n\t\t\t\tint indexVertexStart,\n\t\t\t\tBiFunctionResult function,\n\t\t\t\tTypeResult result\n\t\t)\n\t\t{\n\t\t\tArray visited = new Array<>(vertices.size(), false);\n\t\t\tFIFO verticesNext = new FIFO<>();\n\t\t\tverticesNext.push(vertices.get(indexVertexStart));\n\t\t\tFIFO edgesNext = new FIFO<>();\n\t\t\tedgesNext.push(null);\n\t\t\twhile (!verticesNext.isEmpty())\n\t\t\t{\n\t\t\t\tresult = breadthFirstSearch(verticesNext.pop(), edgesNext.pop(), function, visited, verticesNext, edgesNext, result);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic final int index;\n\t\tpublic final List edges;\n\n\t\tpublic Vertex(int index)\n\t\t{\n\t\t\tthis.index = index;\n\t\t\tthis.edges = new ArrayList<>();\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Vertex that)\n\t\t{\n\t\t\treturn Integer.compare(this.index, that.index);\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn \"\" + this.index;\n\t\t}\n\n\t\tenum Operation\n\t\t{\n\t\t\tINVISIT, POSTVISIT, EXPAND\n\t\t}\n\t}\n\n\tpublic static class VertexDefault, TypeEdge>> extends Vertex, TypeEdge>\n\t{\n\t\tpublic VertexDefault(int index)\n\t\t{\n\t\t\tsuper(index);\n\t\t}\n\t}\n\n\tpublic static class VertexDefaultDefault extends Vertex\n\t{\n\t\tpublic static Array vertices(int n)\n\t\t{\n\t\t\tArray result = new Array<>(n);\n\t\t\tfor (int index = 0; index < n; index++)\n\t\t\t{\n\t\t\t\tresult.set(index, new VertexDefaultDefault(index));\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic VertexDefaultDefault(int index)\n\t\t{\n\t\t\tsuper(index);\n\t\t}\n\t}\n\n\tpublic static class EdgeDefaultDefault extends Edge\n\t{\n\t\tpublic EdgeDefaultDefault(VertexDefaultDefault vertex0, VertexDefaultDefault vertex1, boolean bidirectional)\n\t\t{\n\t\t\tsuper(vertex0, vertex1, bidirectional);\n\t\t}\n\n\t\t@Override\n\t\tpublic EdgeDefaultDefault getThis()\n\t\t{\n\t\t\treturn this;\n\t\t}\n\t}\n\n\tpublic static class Tuple2\n\t{\n\t\tpublic final Type0 v0;\n\t\tpublic final Type1 v1;\n\n\t\tpublic Tuple2(Type0 v0, Type1 v1)\n\t\t{\n\t\t\tthis.v0 = v0;\n\t\t\tthis.v1 = v1;\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn \"(\" + this.v0 + \", \" + this.v1 + \")\";\n\t\t}\n\t}\n\n\tstatic class Wrapper\n\t{\n\t\tpublic Type value;\n\n\t\tpublic Wrapper(Type value)\n\t\t{\n\t\t\tthis.value = value;\n\t\t}\n\n\t\tpublic Type get()\n\t\t{\n\t\t\treturn this.value;\n\t\t}\n\n\t\tpublic void set(Type value)\n\t\t{\n\t\t\tthis.value = value;\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn this.value.toString();\n\t\t}\n\t}\n\n\tpublic static class Tuple3\n\t{\n\t\tpublic final Type0 v0;\n\t\tpublic final Type1 v1;\n\t\tpublic final Type2 v2;\n\n\t\tpublic Tuple3(Type0 v0, Type1 v1, Type2 v2)\n\t\t{\n\t\t\tthis.v0 = v0;\n\t\t\tthis.v1 = v1;\n\t\t\tthis.v2 = v2;\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn \"(\" + this.v0 + \", \" + this.v1 + \", \" + this.v2 + \")\";\n\t\t}\n\t}\n\n\tpublic static class Tuple2Comparable, Type1 extends Comparable> extends Tuple2 implements Comparable>\n\t{\n\t\tpublic Tuple2Comparable(Type0 v0, Type1 v1)\n\t\t{\n\t\t\tsuper(v0, v1);\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Tuple2Comparable that)\n\t\t{\n\t\t\tint result = this.v0.compareTo(that.v0);\n\t\t\tif (result == 0)\n\t\t\t{\n\t\t\t\tresult = this.v1.compareTo(that.v1);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\t}\n\n\tpublic static class SingleLinkedList\n\t{\n\t\tpublic final Type element;\n\t\tpublic SingleLinkedList next;\n\n\t\tpublic SingleLinkedList(Type element, SingleLinkedList next)\n\t\t{\n\t\t\tthis.element = element;\n\t\t\tthis.next = next;\n\t\t}\n\n\t\tpublic void toCollection(Collection collection)\n\t\t{\n\t\t\tif (this.next != null)\n\t\t\t{\n\t\t\t\tthis.next.toCollection(collection);\n\t\t\t}\n\t\t\tcollection.add(this.element);\n\t\t}\n\t}\n\n\tpublic static class Node\n\t{\n\t\tpublic static Node balance(Node result)\n\t\t{\n\t\t\twhile (result != null && 1 < Math.abs(height(result.left) - height(result.right)))\n\t\t\t{\n\t\t\t\tif (height(result.left) < height(result.right))\n\t\t\t\t{\n\t\t\t\t\tNode right = result.right;\n\t\t\t\t\tif (height(right.right) < height(right.left))\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node<>(result.value, result.left, right.rotateRight());\n\t\t\t\t\t}\n\t\t\t\t\tresult = result.rotateLeft();\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tNode left = result.left;\n\t\t\t\t\tif (height(left.left) < height(left.right))\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node<>(result.value, left.rotateLeft(), result.right);\n\t\t\t\t\t}\n\t\t\t\t\tresult = result.rotateRight();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static Node clone(Node result)\n\t\t{\n\t\t\tif (result != null)\n\t\t\t{\n\t\t\t\tresult = new Node<>(result.value, clone(result.left), clone(result.right));\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static Node delete(Node node, Type value, Comparator comparator)\n\t\t{\n\t\t\tNode result;\n\t\t\tif (node == null)\n\t\t\t{\n\t\t\t\tresult = null;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint compare = comparator.compare(value, node.value);\n\t\t\t\tif (compare == 0)\n\t\t\t\t{\n\t\t\t\t\tif (node.left == null)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = node.right;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tif (node.right == null)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tresult = node.left;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tNode first = first(node.right);\n\t\t\t\t\t\t\tresult = new Node<>(first.value, node.left, delete(node.right, first.value, comparator));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (compare < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node<>(node.value, delete(node.left, value, comparator), node.right);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node<>(node.value, node.left, delete(node.right, value, comparator));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tresult = balance(result);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static Node first(Node result)\n\t\t{\n\t\t\twhile (result.left != null)\n\t\t\t{\n\t\t\t\tresult = result.left;\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static Node get(Node node, Type value, Comparator comparator)\n\t\t{\n\t\t\tNode result;\n\t\t\tif (node == null)\n\t\t\t{\n\t\t\t\tresult = null;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint compare = comparator.compare(value, node.value);\n\t\t\t\tif (compare == 0)\n\t\t\t\t{\n\t\t\t\t\tresult = node;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (compare < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = get(node.left, value, comparator);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = get(node.right, value, comparator);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static Node head(Node node, Type value, Comparator comparator)\n\t\t{\n\t\t\tNode result;\n\t\t\tif (node == null)\n\t\t\t{\n\t\t\t\tresult = null;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint compare = comparator.compare(value, node.value);\n\t\t\t\tif (compare == 0)\n\t\t\t\t{\n\t\t\t\t\tresult = node.left;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (compare < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = head(node.left, value, comparator);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node<>(node.value, node.left, head(node.right, value, comparator));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tresult = balance(result);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static int height(Node node)\n\t\t{\n\t\t\treturn node == null ? 0 : node.height;\n\t\t}\n\n\t\tpublic static Node insert(Node node, Type value, Comparator comparator)\n\t\t{\n\t\t\tNode result;\n\t\t\tif (node == null)\n\t\t\t{\n\t\t\t\tresult = new Node<>(value, null, null);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint compare = comparator.compare(value, node.value);\n\t\t\t\tif (compare == 0)\n\t\t\t\t{\n\t\t\t\t\tresult = new Node<>(value, node.left, node.right);\n\t\t\t\t\t;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (compare < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node<>(node.value, insert(node.left, value, comparator), node.right);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node<>(node.value, node.left, insert(node.right, value, comparator));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tresult = balance(result);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static Node last(Node result)\n\t\t{\n\t\t\twhile (result.right != null)\n\t\t\t{\n\t\t\t\tresult = result.right;\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static int size(Node node)\n\t\t{\n\t\t\treturn node == null ? 0 : node.size;\n\t\t}\n\n\t\tpublic static Node tail(Node node, Type value, Comparator comparator)\n\t\t{\n\t\t\tNode result;\n\t\t\tif (node == null)\n\t\t\t{\n\t\t\t\tresult = null;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint compare = comparator.compare(value, node.value);\n\t\t\t\tif (compare == 0)\n\t\t\t\t{\n\t\t\t\t\tresult = new Node<>(node.value, null, node.right);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (compare < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = new Node<>(node.value, tail(node.left, value, comparator), node.right);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tresult = tail(node.right, value, comparator);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tresult = balance(result);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic static void traverseOrderIn(Node node, Consumer consumer)\n\t\t{\n\t\t\tif (node != null)\n\t\t\t{\n\t\t\t\ttraverseOrderIn(node.left, consumer);\n\t\t\t\tconsumer.accept(node.value);\n\t\t\t\ttraverseOrderIn(node.right, consumer);\n\t\t\t}\n\t\t}\n\n\t\tpublic final Type value;\n\t\tpublic final Node left;\n\t\tpublic final Node right;\n\t\tpublic final int size;\n\t\tprivate final int height;\n\n\t\tpublic Node(Type value, Node left, Node right)\n\t\t{\n\t\t\tthis.value = value;\n\t\t\tthis.left = left;\n\t\t\tthis.right = right;\n\t\t\tthis.size = 1 + size(left) + size(right);\n\t\t\tthis.height = 1 + Math.max(height(left), height(right));\n\t\t}\n\n\t\tpublic Node rotateLeft()\n\t\t{\n\t\t\tNode left = new Node<>(this.value, this.left, this.right.left);\n\t\t\treturn new Node<>(this.right.value, left, this.right.right);\n\t\t}\n\n\t\tpublic Node rotateRight()\n\t\t{\n\t\t\tNode right = new Node<>(this.value, this.left.right, this.right);\n\t\t\treturn new Node<>(this.left.value, this.left.left, right);\n\t\t}\n\t}\n\n\tpublic static class SortedSetAVL implements SortedSet\n\t{\n\t\tpublic Comparator comparator;\n\t\tpublic Node root;\n\n\t\tprivate SortedSetAVL(Comparator comparator, Node root)\n\t\t{\n\t\t\tthis.comparator = comparator;\n\t\t\tthis.root = root;\n\t\t}\n\n\t\tpublic SortedSetAVL(Comparator comparator)\n\t\t{\n\t\t\tthis(comparator, null);\n\t\t}\n\n\t\tpublic SortedSetAVL(Collection collection, Comparator comparator)\n\t\t{\n\t\t\tthis(comparator, null);\n\t\t\tthis.addAll(collection);\n\t\t}\n\n\t\tpublic SortedSetAVL(SortedSetAVL sortedSetAVL)\n\t\t{\n\t\t\tthis(sortedSetAVL.comparator, Node.clone(sortedSetAVL.root));\n\t\t}\n\n\t\t@Override\n\t\tpublic void clear()\n\t\t{\n\t\t\tthis.root = null;\n\t\t}\n\n\t\t@Override\n\t\tpublic Comparator comparator()\n\t\t{\n\t\t\treturn this.comparator;\n\t\t}\n\n\t\tpublic Type get(Type value)\n\t\t{\n\t\t\tNode node = Node.get(this.root, value, this.comparator);\n\t\t\treturn node == null ? null : node.value;\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedSetAVL subSet(Type valueStart, Type valueEnd)\n\t\t{\n\t\t\treturn tailSet(valueStart).headSet(valueEnd);\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedSetAVL headSet(Type valueEnd)\n\t\t{\n\t\t\treturn new SortedSetAVL<>(this.comparator, Node.head(this.root, valueEnd, this.comparator));\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedSetAVL tailSet(Type valueStart)\n\t\t{\n\t\t\treturn new SortedSetAVL<>(this.comparator, Node.tail(this.root, valueStart, this.comparator));\n\t\t}\n\n\t\t@Override\n\t\tpublic Type first()\n\t\t{\n\t\t\treturn Node.first(this.root).value;\n\t\t}\n\n\t\t@Override\n\t\tpublic Type last()\n\t\t{\n\t\t\treturn Node.last(this.root).value;\n\t\t}\n\n\t\t@Override\n\t\tpublic int size()\n\t\t{\n\t\t\treturn this.root == null ? 0 : this.root.size;\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean isEmpty()\n\t\t{\n\t\t\treturn this.root == null;\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean contains(Object value)\n\t\t{\n\t\t\treturn Node.get(this.root, (Type) value, this.comparator) != null;\n\t\t}\n\n\t\t@Override\n\t\tpublic Iterator iterator()\n\t\t{\n\t\t\tStack> path = new Stack<>();\n\n\t\t\treturn new Iterator()\n\t\t\t{\n\t\t\t\t{\n\t\t\t\t\tpush(SortedSetAVL.this.root);\n\t\t\t\t}\n\n\t\t\t\tpublic void push(Node node)\n\t\t\t\t{\n\t\t\t\t\twhile (node != null)\n\t\t\t\t\t{\n\t\t\t\t\t\tpath.push(node);\n\t\t\t\t\t\tnode = node.left;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean hasNext()\n\t\t\t\t{\n\t\t\t\t\treturn !path.isEmpty();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic Type next()\n\t\t\t\t{\n\t\t\t\t\tif (path.isEmpty())\n\t\t\t\t\t{\n\t\t\t\t\t\tthrow new NoSuchElementException();\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tNode node = path.peek();\n\t\t\t\t\t\tType result = node.value;\n\t\t\t\t\t\tif (node.right != null)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tpush(node.right);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tdo\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tnode = path.pop();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\twhile (!path.isEmpty() && path.peek().right == node);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\t@Override\n\t\tpublic Object[] toArray()\n\t\t{\n\t\t\tList list = new ArrayList<>();\n\t\t\tNode.traverseOrderIn(this.root, list::add);\n\t\t\treturn list.toArray();\n\t\t}\n\n\t\t@Override\n\t\tpublic T[] toArray(T[] ts)\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean add(Type value)\n\t\t{\n\t\t\tint sizeBefore = size();\n\t\t\tthis.root = Node.insert(this.root, value, this.comparator);\n\t\t\treturn sizeBefore != size();\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean remove(Object value)\n\t\t{\n\t\t\tint sizeBefore = size();\n\t\t\tthis.root = Node.delete(this.root, (Type) value, this.comparator);\n\t\t\treturn sizeBefore != size();\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean containsAll(Collection collection)\n\t\t{\n\t\t\treturn collection.stream()\n\t\t\t\t\t.allMatch(this::contains);\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean addAll(Collection collection)\n\t\t{\n\t\t\treturn collection.stream()\n\t\t\t\t\t.map(this::add)\n\t\t\t\t\t.reduce(true, (x, y) -> x | y);\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean retainAll(Collection collection)\n\t\t{\n\t\t\tSortedSetAVL set = new SortedSetAVL<>(this.comparator);\n\t\t\tcollection.stream()\n\t\t\t\t\t.map(element -> (Type) element)\n\t\t\t\t\t.filter(this::contains)\n\t\t\t\t\t.forEach(set::add);\n\t\t\tboolean result = size() != set.size();\n\t\t\tthis.root = set.root;\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean removeAll(Collection collection)\n\t\t{\n\t\t\treturn collection.stream()\n\t\t\t\t\t.map(this::remove)\n\t\t\t\t\t.reduce(true, (x, y) -> x | y);\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn \"{\" + E_418.toString(this, \", \") + \"}\";\n\t\t}\n\t}\n\n\tpublic static class SortedMapAVL implements SortedMap\n\t{\n\t\tpublic final Comparator comparator;\n\t\tpublic final SortedSetAVL> entrySet;\n\n\t\tpublic SortedMapAVL(Comparator comparator)\n\t\t{\n\t\t\tthis(comparator, new SortedSetAVL<>((entry0, entry1) -> comparator.compare(entry0.getKey(), entry1.getKey())));\n\t\t}\n\n\t\tprivate SortedMapAVL(Comparator comparator, SortedSetAVL> entrySet)\n\t\t{\n\t\t\tthis.comparator = comparator;\n\t\t\tthis.entrySet = entrySet;\n\t\t}\n\n\t\t@Override\n\t\tpublic Comparator comparator()\n\t\t{\n\t\t\treturn this.comparator;\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedMapAVL subMap(TypeKey keyStart, TypeKey keyEnd)\n\t\t{\n\t\t\treturn new SortedMapAVL<>(this.comparator, this.entrySet.subSet(new AbstractMap.SimpleEntry<>(keyStart, null), new AbstractMap.SimpleEntry<>(keyEnd, null)));\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedMapAVL headMap(TypeKey keyEnd)\n\t\t{\n\t\t\treturn new SortedMapAVL<>(this.comparator, this.entrySet.headSet(new AbstractMap.SimpleEntry<>(keyEnd, null)));\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedMapAVL tailMap(TypeKey keyStart)\n\t\t{\n\t\t\treturn new SortedMapAVL<>(this.comparator, this.entrySet.tailSet(new AbstractMap.SimpleEntry<>(keyStart, null)));\n\t\t}\n\n\t\tpublic Entry firstEntry()\n\t\t{\n\t\t\treturn this.entrySet.first();\n\t\t}\n\n\t\t@Override\n\t\tpublic TypeKey firstKey()\n\t\t{\n\t\t\treturn firstEntry().getKey();\n\t\t}\n\n\t\tpublic Entry lastEntry()\n\t\t{\n\t\t\treturn this.entrySet.last();\n\t\t}\n\n\t\t@Override\n\t\tpublic TypeKey lastKey()\n\t\t{\n\t\t\treturn lastEntry().getKey();\n\t\t}\n\n\t\t@Override\n\t\tpublic int size()\n\t\t{\n\t\t\treturn this.entrySet().size();\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean isEmpty()\n\t\t{\n\t\t\treturn this.entrySet.isEmpty();\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean containsKey(Object key)\n\t\t{\n\t\t\treturn this.entrySet().contains(new AbstractMap.SimpleEntry<>((TypeKey) key, null));\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean containsValue(Object value)\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\n\t\t@Override\n\t\tpublic TypeValue get(Object key)\n\t\t{\n\t\t\tEntry entry = new AbstractMap.SimpleEntry<>((TypeKey) key, null);\n\t\t\tentry = this.entrySet.get(entry);\n\t\t\treturn entry == null ? null : entry.getValue();\n\t\t}\n\n\t\t@Override\n\t\tpublic TypeValue put(TypeKey key, TypeValue value)\n\t\t{\n\t\t\tTypeValue result = get(key);\n\t\t\tEntry entry = new AbstractMap.SimpleEntry<>(key, value);\n\t\t\tthis.entrySet().add(entry);\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic TypeValue remove(Object key)\n\t\t{\n\t\t\tTypeValue result = get(key);\n\t\t\tEntry entry = new AbstractMap.SimpleEntry<>((TypeKey) key, null);\n\t\t\tthis.entrySet.remove(entry);\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic void putAll(Map map)\n\t\t{\n\t\t\tmap.entrySet()\n\t\t\t\t\t.forEach(entry -> put(entry.getKey(), entry.getValue()));\n\t\t}\n\n\t\t@Override\n\t\tpublic void clear()\n\t\t{\n\t\t\tthis.entrySet.clear();\n\t\t}\n\n\t\t@Override\n\t\tpublic Set keySet()\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\n\t\t@Override\n\t\tpublic Collection values()\n\t\t{\n\t\t\treturn new Collection()\n\t\t\t{\n\t\t\t\t@Override\n\t\t\t\tpublic int size()\n\t\t\t\t{\n\t\t\t\t\treturn SortedMapAVL.this.entrySet.size();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean isEmpty()\n\t\t\t\t{\n\t\t\t\t\treturn SortedMapAVL.this.entrySet.isEmpty();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean contains(Object value)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic Iterator iterator()\n\t\t\t\t{\n\t\t\t\t\treturn new Iterator()\n\t\t\t\t\t{\n\t\t\t\t\t\tIterator> iterator = SortedMapAVL.this.entrySet.iterator();\n\n\t\t\t\t\t\t@Override\n\t\t\t\t\t\tpublic boolean hasNext()\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\treturn this.iterator.hasNext();\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t@Override\n\t\t\t\t\t\tpublic TypeValue next()\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\treturn this.iterator.next().getValue();\n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic Object[] toArray()\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic T[] toArray(T[] ts)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean add(TypeValue typeValue)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean remove(Object o)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean containsAll(Collection collection)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean addAll(Collection collection)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean removeAll(Collection collection)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean retainAll(Collection collection)\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic void clear()\n\t\t\t\t{\n\t\t\t\t\tthrow new UnsupportedOperationException();\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedSetAVL> entrySet()\n\t\t{\n\t\t\treturn this.entrySet;\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn this.entrySet().toString();\n\t\t}\n\t}\n\n\tpublic static class FIFO\n\t{\n\t\tpublic SingleLinkedList start;\n\t\tpublic SingleLinkedList end;\n\n\t\tpublic FIFO()\n\t\t{\n\t\t\tthis.start = null;\n\t\t\tthis.end = null;\n\t\t}\n\n\t\tpublic boolean isEmpty()\n\t\t{\n\t\t\treturn this.start == null;\n\t\t}\n\n\t\tpublic Type peek()\n\t\t{\n\t\t\treturn this.start.element;\n\t\t}\n\n\t\tpublic Type pop()\n\t\t{\n\t\t\tType result = this.start.element;\n\t\t\tthis.start = this.start.next;\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic void push(Type element)\n\t\t{\n\t\t\tSingleLinkedList list = new SingleLinkedList<>(element, null);\n\t\t\tif (this.start == null)\n\t\t\t{\n\t\t\t\tthis.start = list;\n\t\t\t\tthis.end = list;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tthis.end.next = list;\n\t\t\t\tthis.end = list;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static class MapCount extends SortedMapAVL\n\t{\n\t\tprivate int count;\n\n\t\tpublic MapCount(Comparator comparator)\n\t\t{\n\t\t\tsuper(comparator);\n\t\t\tthis.count = 0;\n\t\t}\n\n\t\tpublic long add(Type key, Long delta)\n\t\t{\n\t\t\tlong result;\n\t\t\tif (delta > 0)\n\t\t\t{\n\t\t\t\tLong value = get(key);\n\t\t\t\tif (value == null)\n\t\t\t\t{\n\t\t\t\t\tvalue = delta;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tvalue += delta;\n\t\t\t\t}\n\t\t\t\tput(key, value);\n\t\t\t\tresult = delta;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = 0;\n\t\t\t}\n\t\t\tthis.count += result;\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic int count()\n\t\t{\n\t\t\treturn this.count;\n\t\t}\n\n\t\tpublic List flatten()\n\t\t{\n\t\t\tList result = new ArrayList<>();\n\t\t\tfor (Entry entry : entrySet())\n\t\t\t{\n\t\t\t\tfor (long index = 0; index < entry.getValue(); index++)\n\t\t\t\t{\n\t\t\t\t\tresult.add(entry.getKey());\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic void putAll(Map map)\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\n\t\t@Override\n\t\tpublic Long remove(Object key)\n\t\t{\n\t\t\tLong result = super.remove(key);\n\t\t\tthis.count -= result;\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic long remove(Type key, Long delta)\n\t\t{\n\t\t\tlong result;\n\t\t\tif (delta > 0)\n\t\t\t{\n\t\t\t\tLong value = get(key) - delta;\n\t\t\t\tif (value <= 0)\n\t\t\t\t{\n\t\t\t\t\tresult = delta + value;\n\t\t\t\t\tremove(key);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tresult = delta;\n\t\t\t\t\tput(key, value);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = 0;\n\t\t\t}\n\t\t\tthis.count -= result;\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedMapAVL subMap(Type keyStart, Type keyEnd)\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedMapAVL headMap(Type keyEnd)\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\n\t\t@Override\n\t\tpublic SortedMapAVL tailMap(Type keyStart)\n\t\t{\n\t\t\tthrow new UnsupportedOperationException();\n\t\t}\n\t}\n\n\tpublic static class MapSet extends SortedMapAVL> implements Iterable\n\t{\n\t\tprivate Comparator comparatorValue;\n\n\t\tpublic MapSet(Comparator comparatorKey, Comparator comparatorValue)\n\t\t{\n\t\t\tsuper(comparatorKey);\n\t\t\tthis.comparatorValue = comparatorValue;\n\t\t}\n\n\t\tpublic MapSet(Comparator comparatorKey, SortedSetAVL>> entrySet, Comparator comparatorValue)\n\t\t{\n\t\t\tsuper(comparatorKey, entrySet);\n\t\t\tthis.comparatorValue = comparatorValue;\n\t\t}\n\n\t\tpublic TypeValue firstValue()\n\t\t{\n\t\t\tTypeValue result;\n\t\t\tEntry> firstEntry = firstEntry();\n\t\t\tif (firstEntry == null)\n\t\t\t{\n\t\t\t\tresult = null;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = firstEntry.getValue().first();\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic Iterator iterator()\n\t\t{\n\t\t\treturn new Iterator()\n\t\t\t{\n\t\t\t\tIterator> iteratorValues = values().iterator();\n\t\t\t\tIterator iteratorValue = null;\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean hasNext()\n\t\t\t\t{\n\t\t\t\t\treturn iteratorValues.hasNext() || (iteratorValue != null && iteratorValue.hasNext());\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic TypeValue next()\n\t\t\t\t{\n\t\t\t\t\tif (iteratorValue == null || !iteratorValue.hasNext())\n\t\t\t\t\t{\n\t\t\t\t\t\titeratorValue = iteratorValues.next().iterator();\n\t\t\t\t\t}\n\t\t\t\t\treturn iteratorValue.next();\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\n\t\tpublic TypeValue lastValue()\n\t\t{\n\t\t\tTypeValue result;\n\t\t\tEntry> lastEntry = lastEntry();\n\t\t\tif (lastEntry == null)\n\t\t\t{\n\t\t\t\tresult = null;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = lastEntry.getValue().last();\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\tpublic boolean add(TypeKey key, TypeValue value)\n\t\t{\n\t\t\tSortedSetAVL set = computeIfAbsent(key, k -> new SortedSetAVL<>(comparatorValue));\n\t\t\treturn set.add(value);\n\t\t}\n\n\t\tpublic boolean removeSet(TypeKey key, TypeValue value)\n\t\t{\n\t\t\tboolean result;\n\t\t\tSortedSetAVL set = get(key);\n\t\t\tif (set == null)\n\t\t\t{\n\t\t\t\tresult = false;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = set.remove(value);\n\t\t\t\tif (set.size() == 0)\n\t\t\t\t{\n\t\t\t\t\tremove(key);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic MapSet headMap(TypeKey keyEnd)\n\t\t{\n\t\t\treturn new MapSet<>(this.comparator, this.entrySet.headSet(new AbstractMap.SimpleEntry<>(keyEnd, null)), this.comparatorValue);\n\t\t}\n\n\t\t@Override\n\t\tpublic MapSet tailMap(TypeKey keyStart)\n\t\t{\n\t\t\treturn new MapSet<>(this.comparator, this.entrySet.tailSet(new AbstractMap.SimpleEntry<>(keyStart, null)), this.comparatorValue);\n\t\t}\n\t}\n\n\tstatic class IteratorBuffer\n\t{\n\t\tprivate Iterator iterator;\n\t\tprivate List list;\n\n\t\tpublic IteratorBuffer(Iterator iterator)\n\t\t{\n\t\t\tthis.iterator = iterator;\n\t\t\tthis.list = new ArrayList();\n\t\t}\n\n\t\tpublic Iterator iterator()\n\t\t{\n\t\t\treturn new Iterator()\n\t\t\t{\n\t\t\t\tint index = 0;\n\n\t\t\t\t@Override\n\t\t\t\tpublic boolean hasNext()\n\t\t\t\t{\n\t\t\t\t\treturn this.index < list.size() || iterator().hasNext();\n\t\t\t\t}\n\n\t\t\t\t@Override\n\t\t\t\tpublic Type next()\n\t\t\t\t{\n\t\t\t\t\tif (list.size() <= this.index)\n\t\t\t\t\t{\n\t\t\t\t\t\tlist.add(iterator.next());\n\t\t\t\t\t}\n\t\t\t\t\tType result = list.get(index);\n\t\t\t\t\tindex += 1;\n\t\t\t\t\treturn result;\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\t}\n\n\tpublic static List> permutations(List list)\n\t{\n\t\tList> result = new ArrayList<>();\n\t\tresult.add(new ArrayList<>());\n\t\tfor (Type element : list)\n\t\t{\n\t\t\tList> permutations = result;\n\t\t\tresult = new ArrayList<>();\n\t\t\tfor (List permutation : permutations)\n\t\t\t{\n\t\t\t\tfor (int index = 0; index <= permutation.size(); index++)\n\t\t\t\t{\n\t\t\t\t\tList permutationNew = new ArrayList<>(permutation);\n\t\t\t\t\tpermutationNew.add(index, element);\n\t\t\t\t\tresult.add(permutationNew);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static List> combinations(int n, int k)\n\t{\n\t\tList> result = new ArrayList<>();\n\t\tif (k == 0)\n\t\t{\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (k == 1)\n\t\t\t{\n\t\t\t\tList combination = new ArrayList<>();\n\t\t\t\tcombination.add(n);\n\t\t\t\tresult.add(combination);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tfor (int index = 0; index <= n; index++)\n\t\t\t\t{\n\t\t\t\t\tfor (List combination : combinations(n - index, k - 1))\n\t\t\t\t\t{\n\t\t\t\t\t\tcombination.add(index);\n\t\t\t\t\t\tresult.add(combination);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int compare(Iterator iterator0, Iterator iterator1, Comparator comparator)\n\t{\n\t\tint result = 0;\n\t\twhile (result == 0 && iterator0.hasNext() && iterator1.hasNext())\n\t\t{\n\t\t\tresult = comparator.compare(iterator0.next(), iterator1.next());\n\t\t}\n\t\tif (result == 0)\n\t\t{\n\t\t\tif (iterator1.hasNext())\n\t\t\t{\n\t\t\t\tresult = -1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (iterator0.hasNext())\n\t\t\t\t{\n\t\t\t\t\tresult = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int compare(Iterable iterable0, Iterable iterable1, Comparator comparator)\n\t{\n\t\treturn compare(iterable0.iterator(), iterable1.iterator(), comparator);\n\t}\n\n\tprivate static String nextString() throws IOException\n\t{\n\t\twhile ((stringTokenizer == null) || (!stringTokenizer.hasMoreTokens()))\n\t\t{\n\t\t\tstringTokenizer = new StringTokenizer(bufferedReader.readLine());\n\t\t}\n\t\treturn stringTokenizer.nextToken();\n\t}\n\n\tprivate static String[] nextStrings(int n) throws IOException\n\t{\n\t\tString[] result = new String[n];\n\t\t{\n\t\t\tfor (int index = 0; index < n; index++)\n\t\t\t{\n\t\t\t\tresult[index] = nextString();\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int nextInt() throws IOException\n\t{\n\t\treturn Integer.parseInt(nextString());\n\t}\n\n\tpublic static int[] nextInts(int n) throws IOException\n\t{\n\t\tint[] result = new int[n];\n\t\t{\n\t\t\tfor (int index = 0; index < n; index++)\n\t\t\t{\n\t\t\t\tresult[index] = nextInt();\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static double nextDouble() throws IOException\n\t{\n\t\treturn Double.parseDouble(nextString());\n\t}\n\n\tpublic static long nextLong() throws IOException\n\t{\n\t\treturn Long.parseLong(nextString());\n\t}\n\n\tpublic static long[] nextLongs(int n) throws IOException\n\t{\n\t\tlong[] result = new long[n];\n\t\t{\n\t\t\tfor (int index = 0; index < n; index++)\n\t\t\t{\n\t\t\t\tresult[index] = nextLong();\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static String nextLine() throws IOException\n\t{\n\t\treturn bufferedReader.readLine();\n\t}\n\n\tpublic static void close()\n\t{\n\t\tout.close();\n\t}\n\n\tpublic static int binarySearchMinimum(Function filter, int start, int end)\n\t{\n\t\tint result;\n\t\tif (start == end)\n\t\t{\n\t\t\tresult = end;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tint middle = start + (end - start) / 2;\n\t\t\tif (filter.apply(middle))\n\t\t\t{\n\t\t\t\tresult = binarySearchMinimum(filter, start, middle);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tresult = binarySearchMinimum(filter, middle + 1, end);\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int binarySearchMaximum(Function filter, int start, int end)\n\t{\n\t\treturn -binarySearchMinimum(x -> filter.apply(-x), -end, -start);\n\t}\n\n\tpublic static long divideCeil(long x, long y)\n\t{\n\t\treturn (x + y - 1) / y;\n\t}\n\n\tpublic static Set divisors(long n)\n\t{\n\t\tSortedSetAVL result = new SortedSetAVL<>(Comparator.naturalOrder());\n\t\tresult.add(1L);\n\t\tfor (Long factor : factors(n))\n\t\t{\n\t\t\tSortedSetAVL divisors = new SortedSetAVL<>(result);\n\t\t\tfor (Long divisor : result)\n\t\t\t{\n\t\t\t\tdivisors.add(divisor * factor);\n\t\t\t}\n\t\t\tresult = divisors;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static BigInteger facultyBig(int n)\n\t{\n\t\tBigInteger result = BigInteger.ONE;\n\t\tfor (int index = 2; index <= n; index++)\n\t\t{\n\t\t\tresult = result.multiply(BigInteger.valueOf(index));\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static long faculty(int n)\n\t{\n\t\tlong result = 1;\n\t\tfor (int index = 2; index <= n; index++)\n\t\t{\n\t\t\tresult *= index;\n\t\t}\n\t\treturn result;\n\t}\n\n\n\tpublic static LinkedList factors(long n)\n\t{\n\t\tLinkedList result = new LinkedList<>();\n\t\tIterator primes = ITERATOR_BUFFER_PRIME.iterator();\n\t\tLong prime;\n\t\twhile (n > 1 && (prime = primes.next()) * prime <= n)\n\t\t{\n\t\t\twhile (n % prime == 0)\n\t\t\t{\n\t\t\t\tresult.add(prime);\n\t\t\t\tn /= prime;\n\t\t\t}\n\t\t}\n\t\tif (n > 1)\n\t\t{\n\t\t\tresult.add(n);\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static long gcd(long a, long b)\n\t{\n\t\twhile (a != 0 && b != 0)\n\t\t{\n\t\t\tif (a > b)\n\t\t\t{\n\t\t\t\ta %= b;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tb %= a;\n\t\t\t}\n\t\t}\n\t\treturn a + b;\n\t}\n\n\tpublic static long[] generatePOWER2()\n\t{\n\t\tlong[] result = new long[63];\n\t\tfor (int x = 0; x < result.length; x++)\n\t\t{\n\t\t\tresult[x] = 1L << x;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static BigInteger[] generateFacultyBig()\n\t{\n\t\tBigInteger[] result = new BigInteger[50];\n\t\tfor (int x = 0; x < result.length; x++)\n\t\t{\n\t\t\tresult[x] = facultyBig(x);\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static boolean isPrime(long x)\n\t{\n\t\tboolean result = x > 1;\n\t\tIterator iterator = ITERATOR_BUFFER_PRIME.iterator();\n\t\tLong prime;\n\t\twhile ((prime = iterator.next()) * prime <= x)\n\t\t{\n\t\t\tresult &= x % prime > 0;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static long knapsack(List> itemsValueWeightCount, int weightMaximum)\n\t{\n\t\tlong[] valuesMaximum = new long[weightMaximum + 1];\n\t\tfor (Tuple3 itemValueWeightCount : itemsValueWeightCount)\n\t\t{\n\t\t\tlong itemValue = itemValueWeightCount.v0;\n\t\t\tint itemWeight = itemValueWeightCount.v1;\n\t\t\tint itemCount = itemValueWeightCount.v2;\n\t\t\tfor (int weight = weightMaximum; 0 <= weight; weight--)\n\t\t\t{\n\t\t\t\tfor (int index = 1; index <= itemCount && 0 <= weight - index * itemWeight; index++)\n\t\t\t\t{\n\t\t\t\t\tvaluesMaximum[weight] = Math.max(valuesMaximum[weight], valuesMaximum[weight - index * itemWeight] + index * itemValue);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong result = 0;\n\t\tfor (long valueMaximum : valuesMaximum)\n\t\t{\n\t\t\tresult = Math.max(result, valueMaximum);\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static boolean knapsackPossible(List> itemsWeightCount, int weightMaximum)\n\t{\n\t\tboolean[] weightPossible = new boolean[weightMaximum + 1];\n\t\tweightPossible[0] = true;\n\t\tint weightLargest = 0;\n\t\tfor (Tuple2 itemWeightCount : itemsWeightCount)\n\t\t{\n\t\t\tint itemWeight = itemWeightCount.v0;\n\t\t\tint itemCount = itemWeightCount.v1;\n\t\t\tfor (int weightStart = 0; weightStart < itemWeight; weightStart++)\n\t\t\t{\n\t\t\t\tint count = 0;\n\t\t\t\tfor (int weight = weightStart; weight <= weightMaximum && (0 < count || weight <= weightLargest); weight += itemWeight)\n\t\t\t\t{\n\t\t\t\t\tif (weightPossible[weight])\n\t\t\t\t\t{\n\t\t\t\t\t\tcount = itemCount;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tif (0 < count)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tweightPossible[weight] = true;\n\t\t\t\t\t\t\tweightLargest = weight;\n\t\t\t\t\t\t\tcount -= 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn weightPossible[weightMaximum];\n\t}\n\n\tpublic static long lcm(int a, int b)\n\t{\n\t\treturn a * b / gcd(a, b);\n\t}\n\n\tpublic static List permutation(long p, List x)\n\t{\n\t\tList copy = new ArrayList<>();\n\t\tfor (int index = 0; index < x.size(); index++)\n\t\t{\n\t\t\tcopy.add(x.get(index));\n\t\t}\n\t\tList result = new ArrayList<>();\n\t\tfor (int indexTo = 0; indexTo < x.size(); indexTo++)\n\t\t{\n\t\t\tint indexFrom = (int) p % copy.size();\n\t\t\tp = p / copy.size();\n\t\t\tresult.add(copy.remove(indexFrom));\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static String toString(Iterator iterator, String separator)\n\t{\n\t\tStringBuilder stringBuilder = new StringBuilder();\n\t\tif (iterator.hasNext())\n\t\t{\n\t\t\tstringBuilder.append(iterator.next());\n\t\t}\n\t\twhile (iterator.hasNext())\n\t\t{\n\t\t\tstringBuilder.append(separator);\n\t\t\tstringBuilder.append(iterator.next());\n\t\t}\n\t\treturn stringBuilder.toString();\n\t}\n\n\tpublic static String toString(Iterator iterator)\n\t{\n\t\treturn toString(iterator, \" \");\n\t}\n\n\tpublic static String toString(Iterable iterable, String separator)\n\t{\n\t\treturn toString(iterable.iterator(), separator);\n\t}\n\n\tpublic static String toString(Iterable iterable)\n\t{\n\t\treturn toString(iterable, \" \");\n\t}\n\n\tpublic static Stream streamFibonacci()\n\t{\n\t\treturn Stream.generate(new Supplier()\n\t\t{\n\t\t\tprivate BigInteger n0 = BigInteger.ZERO;\n\t\t\tprivate BigInteger n1 = BigInteger.ONE;\n\n\t\t\t@Override\n\t\t\tpublic BigInteger get()\n\t\t\t{\n\t\t\t\tBigInteger result = n0;\n\t\t\t\tn0 = n1;\n\t\t\t\tn1 = result.add(n0);\n\t\t\t\treturn result;\n\t\t\t}\n\t\t});\n\t}\n\n\tpublic static Stream streamPrime(int sieveSize)\n\t{\n\t\treturn Stream.generate(new Supplier()\n\t\t{\n\t\t\tprivate boolean[] isPrime = new boolean[sieveSize];\n\t\t\tprivate long sieveOffset = 2;\n\t\t\tprivate List primes = new ArrayList<>();\n\t\t\tprivate int index = 0;\n\n\t\t\tpublic void filter(long prime, boolean[] result)\n\t\t\t{\n\t\t\t\tif (prime * prime < this.sieveOffset + sieveSize)\n\t\t\t\t{\n\t\t\t\t\tlong remainingStart = this.sieveOffset % prime;\n\t\t\t\t\tlong start = remainingStart == 0 ? 0 : prime - remainingStart;\n\t\t\t\t\tfor (long index = start; index < sieveSize; index += prime)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult[(int) index] = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tpublic void generatePrimes()\n\t\t\t{\n\t\t\t\tArrays.fill(this.isPrime, true);\n\t\t\t\tthis.primes.forEach(prime -> filter(prime, isPrime));\n\t\t\t\tfor (int index = 0; index < sieveSize; index++)\n\t\t\t\t{\n\t\t\t\t\tif (isPrime[index])\n\t\t\t\t\t{\n\t\t\t\t\t\tthis.primes.add(this.sieveOffset + index);\n\t\t\t\t\t\tfilter(this.sieveOffset + index, isPrime);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthis.sieveOffset += sieveSize;\n\t\t\t}\n\n\t\t\t@Override\n\t\t\tpublic Long get()\n\t\t\t{\n\t\t\t\twhile (this.primes.size() <= this.index)\n\t\t\t\t{\n\t\t\t\t\tgeneratePrimes();\n\t\t\t\t}\n\t\t\t\tLong result = this.primes.get(this.index);\n\t\t\t\tthis.index += 1;\n\t\t\t\treturn result;\n\t\t\t}\n\t\t});\n\t}\n\n\tpublic static long totient(long n)\n\t{\n\t\tSet factors = new SortedSetAVL<>(factors(n), Comparator.naturalOrder());\n\t\tlong result = n;\n\t\tfor (long p : factors)\n\t\t{\n\t\t\tresult -= result / p;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static void main(String[] args)\n\t{\n\t\ttry\n\t\t{\n\t\t\tsolve();\n\t\t} catch (IOException exception)\n\t\t{\n\t\t\texception.printStackTrace();\n\t\t}\n\t\tclose();\n\t}\n\n\tpublic static void add(int p1, int p2, int c1, int c2, long count, long[][][][] result)\n\t{\n\t\tif (p1 >= 0 && p2 >= 0 && c1 >= 0 && c2 >= 0 && count > 0)\n\t\t{\n\t\t\tif (p1 < result.length && p2 < result[p1].length && c1 < result[p1][p2].length && c2 < result[p1][p2][c1].length)\n\t\t\t{\n\t\t\t\tresult[p1][p2][c1][c2] += count;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static void addPrevious(int p1, int p2, int c1, int c2, long count, long[][][][] result)\n\t{\n\t\tadd(p1 - 1, p2, c1, c2, p1 * count, result);\n\t\tadd(p1 + 1, p2 - 1, c1, c2, p2 * count, result);\n\t}\n\n\tpublic static void next(int d, long count, int p1, int p2, int c1, int c2, long[][][][] result)\n\t{\n\t\tif (p1 == 0 && p2 == 0)\n\t\t{\n\t\t\tif (d == 2)\n\t\t\t{\n\t\t\t\taddPrevious(c1, c2, 1, 0, count, result);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\taddPrevious(c1, c2, 0, 1, count, result);\n\t\t\t}\n\t\t}\n\n\t\tif (d == 2)\n\t\t{\n\t\t\taddPrevious(p1, p2, c1 + 1, c2, count, result);\n\n\t\t\taddPrevious(p1, p2, c1 - 1, c2, c1 * count, result);\n\t\t\taddPrevious(p1, p2, c1 + 1, c2 - 1, c2 * count, result);\n\t\t}\n\t\telse\n\t\t{\n\t\t\taddPrevious(p1, p2, c1, c2 + 1, count, result);\n\n\t\t\taddPrevious(p1, p2, c1, c2, c1 * count, result);\n\t\t\taddPrevious(p1, p2, c1 + 2, c2 - 1, c2 * count, result);\n\n\t\t\taddPrevious(p1, p2, c1 - 2, c2, c1 * (c1 - 1) / 2 * count, result);\n\t\t\taddPrevious(p1, p2, c1, c2 - 1, c1 * c2 * count, result);\n\t\t\taddPrevious(p1, p2, c1 + 2, c2 - 2, c2 * (c2 - 1) / 2 * count, result);\n\t\t}\n\t}\n\n\tpublic static long solve(int[] d)\n\t{\n\t\tlong[][][][] count = new long[d.length / 2 + 1][d.length / 2 + 1][d.length / 2 + 1][d.length / 2 + 1];\n\t\tif (d[0] == 2)\n\t\t{\n\t\t\tif (d[1] == 2)\n\t\t\t{\n\t\t\t\tcount[1][0][1][0] = 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tcount[1][0][0][1] = 1;\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (d[1] == 2)\n\t\t\t{\n\t\t\t\tcount[0][1][1][0] = 1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tcount[0][1][0][1] = 1;\n\t\t\t}\n\t\t}\n\t\tfor (int u = 2; u < d.length; u++)\n\t\t{\n\t\t\tlong[][][][] countNext = new long[d.length / 2 + 1][d.length / 2 + 1][d.length / 2 + 1][d.length / 2 + 1];\n\t\t\tfor (int p1 = 0; p1 <= d.length / 2; p1++)\n\t\t\t{\n\t\t\t\tfor (int p2 = 0; p2 <= d.length / 2 && p1 + p2 < d.length; p2++)\n\t\t\t\t{\n\t\t\t\t\tfor (int c1 = 0; c1 <= d.length / 2 && p1 + p2 + c1 < d.length; c1++)\n\t\t\t\t\t{\n\t\t\t\t\t\tfor (int c2 = 0; c2 <= d.length / 2 && p1 + p2 + c1 + c2 < d.length; c2++)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tnext(d[u], count[p1][p2][c1][c2] % BIG, p1, p2, c1, c2, countNext);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tcount = countNext;\n\t\t}\n\t\treturn count[0][0][0][0] % BIG;\n\t}\n\n\tpublic static void solve() throws IOException\n\t{\n\t\tint n = nextInt();\n\t\tint[] d = nextInts(n);\n\t\tout.println(solve(d));\n\t}\n}", "lang_cluster": "Java", "tags": ["dp", "combinatorics", "graphs", "shortest paths"], "code_uid": "9b44d5b1f45460ba8ac82016939aac12", "src_uid": "db884d679d9cfb1dc4bc511f83beedda", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class WrongAnswerTest233 {\n public static int MAXN = 200005;\n public static long MOD = 998244353;\n public static long[] fact;\n public static long[] invfact;\n public static long[] pow2;\n public static void main(String[] args) throws IOException{\n BufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n StringTokenizer st = new StringTokenizer(f.readLine());\n int n = Integer.parseInt(st.nextToken());\n long k = Long.parseLong(st.nextToken());\n if(n == 1){\n out.println(0);\n out.close();\n return;\n }\n if(k == 1){\n out.println(0);\n out.close();\n return;\n }\n long[] arr = new long[n];\n st = new StringTokenizer(f.readLine());\n for(int i = 0; i < n; i++) arr[i] = Long.parseLong(st.nextToken());\n fact = new long[MAXN];\n invfact = new long[MAXN];\n pow2 = new long[MAXN];\n fact[0] = 1;\n invfact[0] = 1;\n pow2[0] = 1;\n for(int i = 1; i < MAXN; i++){\n pow2[i] = add(pow2[i-1], pow2[i-1]);\n fact[i] = mult(fact[i-1], i);\n }\n invfact[MAXN-1] = inverse(fact[MAXN-1]);\n for(int i = MAXN-2; i >= 1; i--){\n invfact[i] = mult(invfact[i+1], i+1);\n }\n int cnt = 0;\n for(int i = 0; i < n; i++) if(arr[i] != arr[(i+1)%n]) cnt++;\n long multiplier = pow(k, n-cnt);\n long ans = 0;\n for(int i = 1; i <= cnt; i++){\n long res = multiplier;\n res = mult(res, ncr(cnt, i));\n if(i != cnt){\n res = mult(res, pow(k-2, cnt-i));\n }\n long currval = pow2[i-1];\n if(i % 2 == 0) currval = add(currval, mult(MOD-1, mult(invfact[2], ncr(i, i/2))));\n res = mult(res, currval);\n ans = add(ans, res);\n }\n out.println(ans);\n out.close();\n\n }\n public static long add(long a, long b){\n return((a+b)%MOD+MOD)%MOD;\n }\n public static long mult(long a, long b){\n return((a*b)%MOD+MOD)%MOD;\n }\n public static long pow(long a, long b){\n long ans = 1;\n while(b > 0){\n if((b&1) == 1) ans = mult(ans, a);\n a = mult(a, a);\n b>>=1;\n }\n return ans;\n }\n public static long ncr(long a, long b){\n if(a<0) return 0;\n if(b<0) return 0;\n if(a= n) P[m][time] = P[m][time - 1] + P[m-1][time-1] * p;\n else P[m][time] = P[m][time - 1]*(1-p) + P[m - 1][time - 1] * p;\n time++;\n }\n }\n //for (double[] r : P) writer.println(Arrays.toString(r));\n double ans = 0.000000d;\n for (int i = 0; i <= n; i++) {\n ans += P[i][t] * i;\n }\n writer.printf(\"%.06f\\n\", ans);\n writer.close();\n }\n\n static int pow2(int v) {\n v--;\n v |= v >> 1;\n v |= v >> 2;\n v |= v >> 4;\n v |= v >> 8;\n v |= v >> 16;\n v++;\n return v;\n }\n}\n", "lang_cluster": "Java", "tags": ["probabilities", "math", "dp", "combinatorics"], "code_uid": "cdde9a407ba88fe0e295949a652e27ce", "src_uid": "20873b1e802c7aa0e409d9f430516c1e", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.Reader;\nimport java.math.BigInteger;\nimport java.util.Random;\nimport java.util.StringTokenizer;\n\npublic class D {\n public static void main(String[] args) {\n FastScanner sc = new FastScanner();\n\n long a1 = sc.nextLong();\n long b1 = sc.nextLong();\n long a2 = sc.nextLong();\n long b2 = sc.nextLong();\n long left = sc.nextLong();\n long right = sc.nextLong();\n\n long lcm = lcm(a1, a2);\n left = Math.max(left, Math.max(b1, b2));\n\n // a1*x + b1 = a2*y + b2\n // a1*x - a2*y = b1 - b2\n long[] x_y_gcd = solveDiophantine(a1, -a2, b2 - b1);\n if (x_y_gcd == null) {\n System.out.println(0);\n } else {\n BigInteger a1Bi = BigInteger.valueOf(a1);\n BigInteger b1Bi = BigInteger.valueOf(b1);\n BigInteger leftBi = BigInteger.valueOf(left);\n BigInteger rightBi = BigInteger.valueOf(right);\n BigInteger lcmBi = BigInteger.valueOf(lcm);\n\n BigInteger firstEq = a1Bi.multiply(BigInteger.valueOf(x_y_gcd[0])).add(b1Bi);\n BigInteger diff = leftBi.subtract(firstEq).divide(lcmBi).subtract(BigInteger.ONE);\n firstEq = firstEq.add(diff.multiply(lcmBi));\n while (firstEq.compareTo(leftBi) < 0) {\n firstEq = firstEq.add(lcmBi);\n }\n if (rightBi.compareTo(firstEq) < 0) {\n System.out.println(0);\n } else {\n long count = Math.max(rightBi.subtract(firstEq).divide(lcmBi).longValue() + 1, 0);\n System.out.println(count);\n }\n }\n }\n\n /**\n * Finds a single solution {x, y} to the LDE a*x + b*y = c.\n * Outputs an array of the form {x, y, d}, where d = GCD(a,b).\n */\n private static long[] solveDiophantine(long a, long b, long c) {\n long[] e = extEuclid(a, b);\n long k = c / e[2];\n\n //c not divisible by the GCD(a,b) -> no solution\n if (c - k * e[2] != 0)\n return null;\n\n long[] output = {e[0] * k, e[1] * k, e[2]};\n return output;\n }\n\n /**\n * Extended Euclidean Algorithm finds {x, y, d}\n * where d=GCD(a,b) and x and y satisfy a*x + b*y = d\n * The output is an array of the form {x, y, d}.\n */\n private static long[] extEuclid(long a, long b) {\n long s0 = 1, s1 = 0, sTemp;\n long t0 = 0, t1 = 1, tTemp;\n long r0 = a, r1 = b, rTemp;\n long q;\n\n while (r1 != 0) {\n q = r0 / r1;\n\n rTemp = r1;\n r1 = r0 - q * r1;\n r0 = rTemp;\n\n sTemp = s1;\n s1 = s0 - q * s1;\n s0 = sTemp;\n\n tTemp = t1;\n t1 = t0 - q * t1;\n t0 = tTemp;\n }\n\n long[] output = {s0, t0, r0};\n return output;\n }\n\n static long lcm(long a, long b) {\n return a / gcd(a, b) * b;\n }\n\n static long gcd(long a, long b) {\n if (b == 0) return a;\n return gcd(b, a % b);\n }\n\n public static class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(Reader in) {\n br = new BufferedReader(in);\n }\n\n public FastScanner() {\n this(new InputStreamReader(System.in));\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String readNextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n\n int[] readIntArray(int n) {\n int[] a = new int[n];\n for (int idx = 0; idx < n; idx++) {\n a[idx] = nextInt();\n }\n return a;\n }\n\n long[] readLongArray(int n) {\n long[] a = new long[n];\n for (int idx = 0; idx < n; idx++) {\n a[idx] = nextLong();\n }\n return a;\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "number theory"], "code_uid": "1f374f695b016fd0122d619fcff020cc", "src_uid": "b08ee0cd6f5cb574086fa02f07d457a4", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class D {\n\n public static void main(String[] args) throws Exception {\n new D().run();\n out.close();\n }\n\n void run() throws Exception {\n final int MOD = 1000000007;\n int p = nextInt();\n long k = nextInt();\n DisjointSets set = new DisjointSets(p);\n for (int i = 0; i < p; ++i) {\n set.union(i, (int) (k * i % p));\n }\n HashSet countDiff = new HashSet<>();\n for (int i = 0; i < p; ++i) {\n countDiff.add(set.findRoot(i));\n }\n int deg = countDiff.size();\n if (k == 0) {\n deg = p - 1;\n } else if (k != 1) {\n --deg;\n }\n long res = 1;\n for (int i = 0; i < deg; ++i) {\n res = (res * p) % MOD;\n }\n out.print(res);\n }\n\n public class DisjointSets {\n\n public DisjointSets(int nVertexes) {\n root = new int[nVertexes];\n rank = new int[nVertexes];\n for (int i = 0; i < nVertexes; ++i) {\n root[i] = i;\n rank[i] = 1;\n }\n }\n\n public int findRoot(int x) {\n if (root[x] != x) {\n return root[x] = findRoot(root[x]);\n }\n return x;\n }\n\n public boolean union(int ind, int[][] e) {\n return union(e[ind]);\n }\n\n public boolean union(int[] e) {\n return union(e[0], e[1]);\n }\n\n public boolean union(int x, int y) {\n x = findRoot(x);\n y = findRoot(y);\n if (x != y) {\n if (rank[x] > rank[y]) {\n root[y] = x;\n } else if (rank[x] < rank[y]) {\n root[x] = y;\n } else {\n root[x] = y;\n ++rank[y];\n }\n return true;\n }\n return false;\n }\n\n private final int[] root;\n private final int[] rank;\n }\n\n//~~~~~~~~~~~~~~~~~~~~~~~~~~~ template ~~~~~~~~~~~~~~~~~~~~~~~~~~~\n int[] nextIntArray(int n) throws IOException {\n int[] res = new int[n];\n for (int i = 0; i < n; ++i) {\n res[i] = nextInt();\n }\n return res;\n }\n\n int[][] nextIntArray(int nx, int ny) throws IOException {\n int[][] res = new int[nx][ny];\n for (int i = 0; i < nx; ++i) {\n for (int j = 0; j < ny; ++j) {\n res[i][j] = nextInt();\n }\n }\n return res;\n }\n\n long[] nextLongArray(int n) throws IOException {\n long[] res = new long[n];\n for (int i = 0; i < n; ++i) {\n res[i] = nextLong();\n }\n return res;\n }\n\n long[][] nextLongArray(int nx, int ny) throws IOException {\n long[][] res = new long[nx][ny];\n for (int i = 0; i < nx; ++i) {\n for (int j = 0; j < ny; ++j) {\n res[i][j] = nextLong();\n }\n }\n return res;\n }\n\n void fill(int[][] arr, int val) {\n for (int i = 0; i < arr.length; ++i) {\n Arrays.fill(arr[i], val);\n }\n }\n\n void fill(int[][][] arr, int val) {\n for (int i = 0; i < arr.length; ++i) {\n fill(arr[i], val);\n }\n }\n\n int[][] newIntArray(int nx, int ny, int val) {\n int[][] res = new int[nx][ny];\n fill(res, val);\n return res;\n }\n\n int[][][] newIntArray(int nx, int ny, int nz, int val) {\n int[][][] res = new int[nx][ny][nz];\n fill(res, val);\n return res;\n }\n\n long[][] newLongArray(int nx, int ny, long val) {\n long[][] res = new long[nx][ny];\n for (int i = 0; i < nx; ++i) {\n Arrays.fill(res[i], val);\n }\n return res;\n }\n\n long[][][] newLongArray(int nx, int ny, int nz, long val) {\n long[][][] res = new long[nx][ny][nz];\n for (int i = 0; i < nx; ++i) {\n for (int j = 0; j < ny; ++j) {\n Arrays.fill(res[i][j], val);\n }\n }\n return res;\n }\n\n ArrayList[] newArrayListArray(int sz) {\n ArrayList[] res = new ArrayList[sz];\n for (int i = 0; i < sz; ++i) {\n res[i] = new ArrayList<>();\n }\n return res;\n }\n\n String nextToken() throws IOException {\n while (strTok == null || !strTok.hasMoreTokens()) {\n String line = in.readLine();\n if (line == null) {\n return null;\n }\n strTok = new StringTokenizer(line);\n }\n return strTok.nextToken();\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n static StringTokenizer strTok;\n final static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n final static PrintWriter out = new PrintWriter(System.out);\n}\n", "lang_cluster": "Java", "tags": ["dsu", "math", "combinatorics", "number theory"], "code_uid": "a805b9bec3d84a07181125f1c9e734ab", "src_uid": "580bf65af24fb7f08250ddbc4ca67e0e", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.HashSet;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Sparsh Sanchorawala\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n CInterestingGame solver = new CInterestingGame();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class CInterestingGame {\n public void solve(int testNumber, InputReader s, PrintWriter w) {\n int n = s.nextInt();\n ArrayList[] pair = new ArrayList[n + 1];\n for (int i = 1; i <= n; i++)\n pair[i] = new ArrayList<>();\n for (int k = 2; k <= n; k++)\n for (int a = 1; (long) (2 * a + k - 1) * k / 2 <= n; a++)\n pair[(2 * a + k - 1) * k / 2].add(new Pair(a, k));\n int[] grundy = new int[n + 1];\n int[] val = new int[n + 1];\n Arrays.fill(val, Integer.MAX_VALUE);\n int[] pre = new int[n + 1];\n for (int i = 2; i <= n; i++) {\n HashSet hs = new HashSet<>();\n for (Pair p : pair[i]) {\n hs.add(pre[p.a + p.n - 1] ^ pre[p.a - 1]);\n if ((pre[p.a + p.n - 1] ^ pre[p.a - 1]) == 0)\n val[i] = Math.min(p.n, val[i]);\n }\n while (hs.contains(grundy[i]))\n grundy[i]++;\n pre[i] = grundy[i] ^ pre[i - 1];\n }\n w.println(val[n] != Integer.MAX_VALUE ? val[n] : -1);\n }\n\n class Pair {\n int a;\n int n;\n\n Pair(int a, int n) {\n this.a = a;\n this.n = n;\n }\n\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["math", "dp", "games"], "code_uid": "be02d488ca253074ed7f069f1f8445f3", "src_uid": "63262317ba572d78163c91b853c05506", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class PlayingWithSuperglue\n{\n\tpublic static void main(String[] args)\n\t{\n\t\t\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tint x1 = sc.nextInt();\n\t\tint y1 = sc.nextInt();\n\t\tint x2 = sc.nextInt();\n\t\tint y2 = sc.nextInt();\n\t\tint dx = Math.abs(x1-x2);\n\t\tint dy = Math.abs(y1 - y2);\n\t\tif(dx <= 4 && dy <= 4)\n\t\t{\n\t\t\tint min = Math.min(dx, dy);\n\t\t\tint max = Math.max(dx, dy);\n\t\t\tif(min < 3)\n\t\t\t\tSystem.out.println(\"First\");\n\t\t\telse\n\t\t\t{\n\t\t\t\tif(min == 3 && max == 4)\n\t\t\t\t\tSystem.out.println(\"Second\");\n\t\t\t\telse\n\t\t\t\t\tif(min == 3)\n\t\t\t\t\t\tSystem.out.println(\"First\");\n\t\t\t\tif(min == 4)\n\t\t\t\t\tSystem.out.println(\"Second\");\n\t\t\t}\n\t\t}\n\t\telse\n\t\t\tSystem.out.println(\"Second\");\n\t}\n}\n\n", "lang_cluster": "Java", "tags": ["games"], "code_uid": "40ef5faf714a02e829d6cb796cca0c1e", "src_uid": "41f6f90b7307d2383495441114fa8ea2", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\npublic class D \n{\n public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n public static StringTokenizer inp;\n public static void main(String[] args) throws IOException\n {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n \n int ln[] = new int[1026];\n ln[0] = 0 ; ln[1023] = 2000000000;\n int ind = 1;\n for(int i = 2 ; i < 1024 ; i++)\n {\n char s[] = Integer.toBinaryString(i).toCharArray();\n for(int j = 1 ; j < s.length ; j++) s[j] = (s[j]=='0'?'4':'7');\n ln[ind++] = Integer.parseInt(String.valueOf(s).substring(1));\n }\n inp = new StringTokenizer(br.readLine());\n int pl = nextInt(),pr = nextInt() , vl=nextInt() , vr = nextInt() , k = nextInt();\n long ans = 0;\n int l = 1, r = k;\n for(; r <= 1022 ; r++,l++)\n {\n if(vl>ln[l])continue;\n if(ln[r] > pr || ln[l-1] > vr)break;\n ans+=(long)Math.max(0, (Math.min(ln[l], vr)- Math.max(vl, ln[l-1]+1) + 1))*Math.max(0, (Math.min(pr, ln[r+1]-1)- Math.max(ln[r], pl) + 1));\n }\n l=1;r=k;\n for(; r <= 1022 ; r++,l++)\n {\n if(pl>ln[l])continue;\n if(ln[r] > vr || ln[l-1] > pr)break;\n ans+=(long)Math.max(0, (Math.min(ln[l], pr)- Math.max(pl, ln[l-1]+1) + 1))*Math.max(0, (Math.min(vr, ln[r+1]-1)- Math.max(ln[r], vl) + 1));\n }\n if(k==1)\n {\n for(int i = 1; i <= 1022 ; i++)\n if(pl<=ln[i] && ln[i]<=pr && vl<=ln[i]&&ln[i]<=vr)ans--;\n }\n double res = (double)(ans)/((long)(pr-pl+1)*(vr-vl+1));\n System.out.printf(\"%.12f\\n\",Math.min(res, 1.0));\n }\n \n public static int nextInt(){return Integer.parseInt(inp.nextToken());}\n public static long nextLong(){return Long.parseLong(inp.nextToken());}\n public static double nextDouble(){return Double.parseDouble(inp.nextToken());}\n \n}\n", "lang_cluster": "Java", "tags": ["dfs and similar", "probabilities", "combinatorics", "brute force"], "code_uid": "fea8cf8c0dce37a171a0a74b7a9d2d76", "src_uid": "5d76ec741a9d873ce9d7c3ef55eb984c", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "//package af2017;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class D {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint[] dual = {\n\t\t\t\t8, -1, -1, 3, 6, 9, 4, 7, 0, 5\n\t\t};\n\t\tchar[] s = ns().toCharArray();\n\t\tfor(int i = 0, j = s.length-1;i <= j;i++,j--){\n\t\t\tif(dual[s[i]-'0'] != s[j]-'0'){\n\t\t\t\tout.println(\"No\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tout.println(\"Yes\");\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception { new D().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "db45c6b0340cdb3a2303e62c43701f8b", "src_uid": "0f11f41cefd7cf43f498e511405426c3", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "\nimport java.io.*;\nimport java.util.*;\nimport java.util.regex.Pattern;\n\npublic class Solution implements Runnable {\n\n\n\tprivate StringTokenizer st;\n\tprivate BufferedReader in;\n\tprivate PrintWriter out;\n\n\tstatic class Profile {\n\t\tint[] ar;\n\t\t\n\t\tProfile(int[] ar) {\n\t\t\tthis.ar = ar;\n\t\t}\n\n\t\t@Override\n\t\tpublic int hashCode() {\n\t\t\tfinal int prime = 31;\n\t\t\tint result = 1;\n\t\t\tresult = prime * result + Arrays.hashCode(ar);\n\t\t\treturn result;\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean equals(Object obj) {\n\t\t\tif (this == obj)\n\t\t\t\treturn true;\n\t\t\tif (obj == null)\n\t\t\t\treturn false;\n\t\t\tif (getClass() != obj.getClass())\n\t\t\t\treturn false;\n\t\t\tProfile other = (Profile) obj;\n\t\t\tif (!Arrays.equals(ar, other.ar))\n\t\t\t\treturn false;\n\t\t\treturn true;\n\t\t}\n\t}\n\n\tpublic void solve() throws IOException {\n\t\tlong n = nextLong();\n\t\tint m = nextInt();\n\t\tchar[] cs = new char[m];\n\t\tint[] ms = new int[m];\n\t\tint mul = 1;\n\t\tboolean[] need = new boolean[26];\n\t\tfor (int i = 0; i < m; ++i) {\n\t\t\tcs[i] = next().charAt(0);\n\t\t\tms[i] = nextInt();\n\t\t\tmul *= ms[i];\n\t\t\tneed[cs[i] - 'A'] = true;\n\t\t}\n\t\tHashMap map = new HashMap();\n\t\tList list = new ArrayList();\n\t\tint[] counter = new int[m];\n\t\tfor (int i = 0; i < mul; ++i) {\n\t\t\tProfile p = new Profile(counter.clone());\n\t\t\tlist.add(p);\n\t\t\tmap.put(p, map.size());\n\t\t\tfor (int j = 0; j < m; ++j) {\n\t\t\t\tcounter[j]++;\n\t\t\t\tif (counter[j] == ms[j]) {\n\t\t\t\t\tcounter[j] = 0;\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint[][] mat = new int[mul][mul];\n\t\tfor (int i = 0; i < mul; ++i) {\n\t\t\tfor (char c = 'A'; c <= 'Z'; ++c) {\n\t\t\t\tif (!need[c - 'A']) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tcounter = list.get(i).ar.clone();\n\t\t\t\tfor (int j = 0; j < m; ++j) {\n\t\t\t\t\tif (c == cs[j]) {\n\t\t\t\t\t\tcounter[j] = (counter[j] + 1) % ms[j];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tmat[i][map.get(new Profile(counter))]++;\n\t\t\t}\n\t\t}\n\t\tmat = pow(mat, n);\n\t\tint ans = 0;\n\t\tloop: for (int i = 0; i < mul; ++i) {\n\t\t\tboolean[] ok = new boolean[26];\n\t\t\tcounter = list.get(i).ar;\n\t\t\tfor (int j = 0; j < m; ++j) {\n\t\t\t\tok[cs[j] - 'A'] |= counter[j] == 0;\n\t\t\t}\n\t\t\tfor (int j = 0; j < 26; ++j) {\n\t\t\t\tif (!ok[j] && need[j]) {\n\t\t\t\t\tcontinue loop;\n\t\t\t\t}\n\t\t\t}\n\t\t\tans = (ans + mat[0][i]) % 12345;\n\t\t}\n\t\tout.println(ans);\n\t}\n\n\tprivate int[][] pow(int[][] a, long pow) {\n\t\tint[][] b = new int[a.length][a.length];\n\t\tfor (int i = 0; i < a.length; ++i) {\n\t\t\tb[i][i] = 1;\n\t\t}\n\t\twhile (pow > 0) {\n\t\t\tif (pow % 2 == 1) {\n\t\t\t\tb = mul(b, a);\n\t\t\t}\n\t\t\tpow /= 2;\n\t\t\ta = mul(a, a);\n\t\t}\n\t\treturn b;\n\t}\n\n\tprivate int[][] mul(int[][] a, int[][] b) {\n\t\tint[][] c = new int[a.length][a.length];\n\t\tfor (int i = 0; i < a.length; ++i) {\n\t\t\tfor (int j = 0; j < a.length; ++j) {\n\t\t\t\tlong sum = 0;\n\t\t\t\tfor (int t = 0; t < a.length; ++t) {\n\t\t\t\t\tsum += a[i][t] * b[t][j];\n\t\t\t\t}\n\t\t\t\tc[i][j] = (int)(sum % 12345);\n\t\t\t}\n\t\t}\n\t\treturn c;\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\teat(\"\");\n\t\t\t\n\t\t\tsolve();\n\t\t\t\n\t\t\tout.close();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tfailed = true;\n\t\t}\n\t}\n\t\n\tvoid eat(String s) {\n\t\tst = new StringTokenizer(s);\n\t}\n\t\n\tString next() throws IOException {\n\t\twhile (!st.hasMoreTokens()) {\n\t\t\tString line = in.readLine();\n\t\t\tif (line == null) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\teat(line);\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\t\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\t\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(next());\n\t}\n\t\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\n\t}\n\t\n\tstatic boolean failed = false;\n\t\n\tpublic static void main(String[] args) {\n\t\tLocale.setDefault(Locale.US);\n\t\tThread th = new Thread(new Solution());\n\t\tth.start();\n\t\ttry {\n\t\t\tth.join();\n\t\t} catch (InterruptedException iex) {\n\t\t}\n\t\tif (failed) {\n\t\t\tthrow new RuntimeException();\n\t\t}\n\t}\n\t\n}\n", "lang_cluster": "Java", "tags": ["matrices", "dp", "graphs"], "code_uid": "080b2f1d0c4092dd8156e1bd7303f5ac", "src_uid": "76d4684d26dac380713a566a1e277c91", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "//package round722;\r\nimport java.io.*;\r\nimport java.util.ArrayDeque;\r\nimport java.util.Arrays;\r\nimport java.util.InputMismatchException;\r\nimport java.util.Queue;\r\n\r\npublic class E {\r\n\tInputStream is;\r\n\tFastWriter out;\r\n\tString INPUT = \"4\";\r\n\t\r\n\tvoid solve()\r\n\t{\r\n\t\tfinal int mod = 998244353;\r\n\t\tint n = ni();\r\n\t\tif(n == 1){\r\n\t\t\tout.println(5);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tlong[] f = new long[n+1];\r\n\t\tlong[] g = new long[n+1];\r\n\t\tf[0] = 1;\r\n\t\tf[1] = 2;\r\n\t\tg[1] = 1;\r\n\t\tlong i2 = invl(2, mod);\r\n\t\tfor(int i = 2;i <= n;i++){\r\n\t\t\tg[i] = (((f[i-1]+1)*f[i-1]%mod*i2%mod - (f[i-2]+1)*f[i-2]%mod*i2%mod ) % mod + mod) % mod;\r\n\t\t\tf[i] = f[i-1] + g[i];\r\n\t\t\tf[i] %= mod;\r\n\t\t}\r\n\r\n\t\tlong an = 0;\r\n\t\tfor(int i = 1;i <= n-1;i++){\r\n\t\t\tan += (g[i+1] - g[i] + mod) * (g[n-i-1+1]-1);\r\n\t\t\tan %= mod;\r\n\t\t}\r\n\r\n\t\tlong b0 = f[n-1];\r\n\t\tlong b1 = f[n];\r\n\t\tb1 %= mod;\r\n\t\tlong ans =\r\n\t\t\tb1*(b1+1)%mod*(b1+2)%mod*invl(6, mod) % mod -\r\n\t\t\tb0*(b0+1)%mod*(b0+2)%mod*invl(6, mod) % mod;\r\n\t\tans = ans * 2 - 1 + an;\r\n\t\tans %= mod;\r\n\t\tif(ans < 0)ans += mod;\r\n\t\tout.println(ans);\r\n\t}\r\n\r\n\tpublic static long invl(long a, long mod) {\r\n\t\tlong b = mod;\r\n\t\tlong p = 1, q = 0;\r\n\t\twhile (b > 0) {\r\n\t\t\tlong c = a / b;\r\n\t\t\tlong d;\r\n\t\t\td = a;\r\n\t\t\ta = b;\r\n\t\t\tb = d % b;\r\n\t\t\td = p;\r\n\t\t\tp = q;\r\n\t\t\tq = d - c * q;\r\n\t\t}\r\n\t\treturn p < 0 ? p + mod : p;\r\n\t}\r\n\r\n\r\n\tpublic static long pow(long a, long n, long mod) {\r\n\t\t//\t\ta %= mod;\r\n\t\tlong ret = 1;\r\n\t\tint x = 63 - Long.numberOfLeadingZeros(n);\r\n\t\tfor (; x >= 0; x--) {\r\n\t\t\tret = ret * ret % mod;\r\n\t\t\tif (n << 63 - x < 0) ret = ret * a % mod;\r\n\t\t}\r\n\t\treturn ret;\r\n\t}\r\n\r\n\r\n\tvoid run() throws Exception\r\n\t{\r\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\r\n\t\tout = new FastWriter(System.out);\r\n\t\t\r\n\t\tlong s = System.currentTimeMillis();\r\n\t\tsolve();\r\n\t\tout.flush();\r\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) throws Exception { new E().run(); }\r\n\t\r\n\tprivate byte[] inbuf = new byte[1024];\r\n\tpublic int lenbuf = 0, ptrbuf = 0;\r\n\t\r\n\tprivate int readByte()\r\n\t{\r\n\t\tif(lenbuf == -1)throw new InputMismatchException();\r\n\t\tif(ptrbuf >= lenbuf){\r\n\t\t\tptrbuf = 0;\r\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\r\n\t\t\tif(lenbuf <= 0)return -1;\r\n\t\t}\r\n\t\treturn inbuf[ptrbuf++];\r\n\t}\r\n\t\r\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\r\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\r\n\t\r\n\tprivate double nd() { return Double.parseDouble(ns()); }\r\n\tprivate char nc() { return (char)skip(); }\r\n\t\r\n\tprivate String ns()\r\n\t{\r\n\t\tint b = skip();\r\n\t\tStringBuilder sb = new StringBuilder();\r\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\r\n\t\t\tsb.appendCodePoint(b);\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t\treturn sb.toString();\r\n\t}\r\n\t\r\n\tprivate char[] ns(int n)\r\n\t{\r\n\t\tchar[] buf = new char[n];\r\n\t\tint b = skip(), p = 0;\r\n\t\twhile(p < n && !(isSpaceChar(b))){\r\n\t\t\tbuf[p++] = (char)b;\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\r\n\t}\r\n\r\n\tprivate int[] na(int n)\r\n\t{\r\n\t\tint[] a = new int[n];\r\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\r\n\t\treturn a;\r\n\t}\r\n\r\n\tprivate long[] nal(int n)\r\n\t{\r\n\t\tlong[] a = new long[n];\r\n\t\tfor(int i = 0;i < n;i++)a[i] = nl();\r\n\t\treturn a;\r\n\t}\r\n\r\n\tprivate char[][] nm(int n, int m) {\r\n\t\tchar[][] map = new char[n][];\r\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\r\n\t\treturn map;\r\n\t}\r\n\r\n\tprivate int[][] nmi(int n, int m) {\r\n\t\tint[][] map = new int[n][];\r\n\t\tfor(int i = 0;i < n;i++)map[i] = na(m);\r\n\t\treturn map;\r\n\t}\r\n\r\n\tprivate int ni() { return (int)nl(); }\r\n\r\n\tprivate long nl()\r\n\t{\r\n\t\tlong num = 0;\r\n\t\tint b;\r\n\t\tboolean minus = false;\r\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\r\n\t\tif(b == '-'){\r\n\t\t\tminus = true;\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\r\n\t\twhile(true){\r\n\t\t\tif(b >= '0' && b <= '9'){\r\n\t\t\t\tnum = num * 10 + (b - '0');\r\n\t\t\t}else{\r\n\t\t\t\treturn minus ? -num : num;\r\n\t\t\t}\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic static class FastWriter\r\n\t{\r\n\t\tprivate static final int BUF_SIZE = 1<<13;\r\n\t\tprivate final byte[] buf = new byte[BUF_SIZE];\r\n\t\tprivate final OutputStream out;\r\n\t\tprivate int ptr = 0;\r\n\r\n\t\tprivate FastWriter(){out = null;}\r\n\r\n\t\tpublic FastWriter(OutputStream os)\r\n\t\t{\r\n\t\t\tthis.out = os;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter(String path)\r\n\t\t{\r\n\t\t\ttry {\r\n\t\t\t\tthis.out = new FileOutputStream(path);\r\n\t\t\t} catch (FileNotFoundException e) {\r\n\t\t\t\tthrow new RuntimeException(\"FastWriter\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(byte b)\r\n\t\t{\r\n\t\t\tbuf[ptr++] = b;\r\n\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(char c)\r\n\t\t{\r\n\t\t\treturn write((byte)c);\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(char[] s)\r\n\t\t{\r\n\t\t\tfor(char c : s){\r\n\t\t\t\tbuf[ptr++] = (byte)c;\r\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(String s)\r\n\t\t{\r\n\t\t\ts.chars().forEach(c -> {\r\n\t\t\t\tbuf[ptr++] = (byte)c;\r\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\t});\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tprivate static int countDigits(int l) {\r\n\t\t\tif (l >= 1000000000) return 10;\r\n\t\t\tif (l >= 100000000) return 9;\r\n\t\t\tif (l >= 10000000) return 8;\r\n\t\t\tif (l >= 1000000) return 7;\r\n\t\t\tif (l >= 100000) return 6;\r\n\t\t\tif (l >= 10000) return 5;\r\n\t\t\tif (l >= 1000) return 4;\r\n\t\t\tif (l >= 100) return 3;\r\n\t\t\tif (l >= 10) return 2;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(int x)\r\n\t\t{\r\n\t\t\tif(x == Integer.MIN_VALUE){\r\n\t\t\t\treturn write((long)x);\r\n\t\t\t}\r\n\t\t\tif(ptr + 12 >= BUF_SIZE)innerflush();\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite((byte)'-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tint d = countDigits(x);\r\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\r\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\r\n\t\t\t\tx /= 10;\r\n\t\t\t}\r\n\t\t\tptr += d;\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tprivate static int countDigits(long l) {\r\n\t\t\tif (l >= 1000000000000000000L) return 19;\r\n\t\t\tif (l >= 100000000000000000L) return 18;\r\n\t\t\tif (l >= 10000000000000000L) return 17;\r\n\t\t\tif (l >= 1000000000000000L) return 16;\r\n\t\t\tif (l >= 100000000000000L) return 15;\r\n\t\t\tif (l >= 10000000000000L) return 14;\r\n\t\t\tif (l >= 1000000000000L) return 13;\r\n\t\t\tif (l >= 100000000000L) return 12;\r\n\t\t\tif (l >= 10000000000L) return 11;\r\n\t\t\tif (l >= 1000000000L) return 10;\r\n\t\t\tif (l >= 100000000L) return 9;\r\n\t\t\tif (l >= 10000000L) return 8;\r\n\t\t\tif (l >= 1000000L) return 7;\r\n\t\t\tif (l >= 100000L) return 6;\r\n\t\t\tif (l >= 10000L) return 5;\r\n\t\t\tif (l >= 1000L) return 4;\r\n\t\t\tif (l >= 100L) return 3;\r\n\t\t\tif (l >= 10L) return 2;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(long x)\r\n\t\t{\r\n\t\t\tif(x == Long.MIN_VALUE){\r\n\t\t\t\treturn write(\"\" + x);\r\n\t\t\t}\r\n\t\t\tif(ptr + 21 >= BUF_SIZE)innerflush();\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite((byte)'-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tint d = countDigits(x);\r\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\r\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\r\n\t\t\t\tx /= 10;\r\n\t\t\t}\r\n\t\t\tptr += d;\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(double x, int precision)\r\n\t\t{\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite('-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tx += Math.pow(10, -precision)/2;\r\n\t\t\t//\t\tif(x < 0){ x = 0; }\r\n\t\t\twrite((long)x).write(\".\");\r\n\t\t\tx -= (long)x;\r\n\t\t\tfor(int i = 0;i < precision;i++){\r\n\t\t\t\tx *= 10;\r\n\t\t\t\twrite((char)('0'+(int)x));\r\n\t\t\t\tx -= (int)x;\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(char c){\r\n\t\t\treturn write(c).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(int x){\r\n\t\t\treturn write(x).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(long x){\r\n\t\t\treturn write(x).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(double x, int precision){\r\n\t\t\treturn write(x, precision).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(int... xs)\r\n\t\t{\r\n\t\t\tboolean first = true;\r\n\t\t\tfor(int x : xs) {\r\n\t\t\t\tif (!first) write(' ');\r\n\t\t\t\tfirst = false;\r\n\t\t\t\twrite(x);\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(long... xs)\r\n\t\t{\r\n\t\t\tboolean first = true;\r\n\t\t\tfor(long x : xs) {\r\n\t\t\t\tif (!first) write(' ');\r\n\t\t\t\tfirst = false;\r\n\t\t\t\twrite(x);\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln()\r\n\t\t{\r\n\t\t\treturn write((byte)'\\n');\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(int... xs)\r\n\t\t{\r\n\t\t\treturn write(xs).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(long... xs)\r\n\t\t{\r\n\t\t\treturn write(xs).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(char[] line)\r\n\t\t{\r\n\t\t\treturn write(line).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(char[]... map)\r\n\t\t{\r\n\t\t\tfor(char[] line : map)write(line).writeln();\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(String s)\r\n\t\t{\r\n\t\t\treturn write(s).writeln();\r\n\t\t}\r\n\r\n\t\tprivate void innerflush()\r\n\t\t{\r\n\t\t\ttry {\r\n\t\t\t\tout.write(buf, 0, ptr);\r\n\t\t\t\tptr = 0;\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\tthrow new RuntimeException(\"innerflush\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void flush()\r\n\t\t{\r\n\t\t\tinnerflush();\r\n\t\t\ttry {\r\n\t\t\t\tout.flush();\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\tthrow new RuntimeException(\"flush\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic FastWriter print(byte b) { return write(b); }\r\n\t\tpublic FastWriter print(char c) { return write(c); }\r\n\t\tpublic FastWriter print(char[] s) { return write(s); }\r\n\t\tpublic FastWriter print(String s) { return write(s); }\r\n\t\tpublic FastWriter print(int x) { return write(x); }\r\n\t\tpublic FastWriter print(long x) { return write(x); }\r\n\t\tpublic FastWriter print(double x, int precision) { return write(x, precision); }\r\n\t\tpublic FastWriter println(char c){ return writeln(c); }\r\n\t\tpublic FastWriter println(int x){ return writeln(x); }\r\n\t\tpublic FastWriter println(long x){ return writeln(x); }\r\n\t\tpublic FastWriter println(double x, int precision){ return writeln(x, precision); }\r\n\t\tpublic FastWriter print(int... xs) { return write(xs); }\r\n\t\tpublic FastWriter print(long... xs) { return write(xs); }\r\n\t\tpublic FastWriter println(int... xs) { return writeln(xs); }\r\n\t\tpublic FastWriter println(long... xs) { return writeln(xs); }\r\n\t\tpublic FastWriter println(char[] line) { return writeln(line); }\r\n\t\tpublic FastWriter println(char[]... map) { return writeln(map); }\r\n\t\tpublic FastWriter println(String s) { return writeln(s); }\r\n\t\tpublic FastWriter println() { return writeln(); }\r\n\t}\r\n\r\n\tpublic void trnz(int... o)\r\n\t{\r\n\t\tfor(int i = 0;i < o.length;i++)if(o[i] != 0)System.out.print(i+\":\"+o[i]+\" \");\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\t// print ids which are 1\r\n\tpublic void trt(long... o)\r\n\t{\r\n\t\tQueue stands = new ArrayDeque<>();\r\n\t\tfor(int i = 0;i < o.length;i++){\r\n\t\t\tfor(long x = o[i];x != 0;x &= x-1)stands.add(i<<6|Long.numberOfTrailingZeros(x));\r\n\t\t}\r\n\t\tSystem.out.println(stands);\r\n\t}\r\n\r\n\tpublic void tf(boolean... r)\r\n\t{\r\n\t\tfor(boolean x : r)System.out.print(x?'#':'.');\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\tpublic void tf(boolean[]... b)\r\n\t{\r\n\t\tfor(boolean[] r : b) {\r\n\t\t\tfor(boolean x : r)System.out.print(x?'#':'.');\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\tpublic void tf(long[]... b)\r\n\t{\r\n\t\tif(INPUT.length() != 0) {\r\n\t\t\tfor (long[] r : b) {\r\n\t\t\t\tfor (long x : r) {\r\n\t\t\t\t\tfor (int i = 0; i < 64; i++) {\r\n\t\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tSystem.out.println();\r\n\t\t\t}\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic void tf(long... b)\r\n\t{\r\n\t\tif(INPUT.length() != 0) {\r\n\t\t\tfor (long x : b) {\r\n\t\t\t\tfor (int i = 0; i < 64; i++) {\r\n\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t}\r\n\r\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\r\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\r\n}\r\n", "lang_cluster": "Java", "tags": ["dp", "combinatorics", "trees"], "code_uid": "ef3dd7103bf87f306c4600c07f62cf89", "src_uid": "92939054045c089cd25c8f4e7b9ffcf2", "difficulty": 2900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class A {\n public static void main(String[] args) {\n Scanner io = new Scanner(System.in);\n long a = io.nextLong(), b = io.nextLong(), c = a + b;\n long min = 0, max = 0;\n\n for (long i = (long) Math.sqrt(c); i >= 1; i--) {\n if (c % i == 0) {\n min = i;\n max = c / i;\n\n for (long j = min; j >= 1; j--) {\n if (a % j == 0 && a / j <= max || b % j == 0 && b / j <= max) {\n System.out.println((min + max) * 2);\n return;\n }\n\n }\n }\n }\n\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "math", "binary search", "number theory"], "code_uid": "5d9e0deb1a3f5ca5ac71d2688bef67fd", "src_uid": "7d0c5f77bca792b6ab4fd4088fe18ff1", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Div2_415E {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter printer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\t\tint numQ = Integer.parseInt(reader.readLine());\n\t\twhile (numQ-- > 0) {\n\t\t\tStringTokenizer inputData = new StringTokenizer(reader.readLine());\n\t\t\tlong t = Long.parseLong(inputData.nextToken());\n\t\t\tlong l = Long.parseLong(inputData.nextToken());\n\t\t\tlong b = Long.parseLong(inputData.nextToken());\n\t\t\tlong r = Long.parseLong(inputData.nextToken());\n\n\t\t\tT = Long.parseLong(inputData.nextToken());\n\n\t\t\t// System.out.println(query(r, b));\n\t\t\t// System.out.println(query(l - 1, b));\n\t\t\t// System.out.println(query(r, t - 1));\n\t\t\t// System.out.println(query(l - 1, b - 1));\n\n\t\t\tlong ans = (MOD * 2 + query(r, b) - query(l - 1, b) - query(r, t - 1) + query(l - 1, t - 1)) % MOD;\n\t\t\tprinter.println(ans);\n\t\t\t// printer.println();\n\t\t}\n\t\tprinter.close();\n\t}\n\n\tstatic long T;\n\n\tstatic final long MOD = 1_000_000_007L;\n\n\tstatic long query(long wid, long hei) {\n\t\treturn query(wid, hei, 0);\n\t}\n\n\tstatic long query(long wid, long hei, final long off) {\n\t\tif (wid < hei) {\n\t\t\tlong temp = wid;\n\t\t\twid = hei;\n\t\t\thei = temp;\n\t\t}\n\t\tassert (hei <= wid);\n\t\tassert (off >= 0);\n\n\t\tif (off >= T || wid <= 0 || hei <= 0) {\n\t\t\treturn 0;\n\t\t}\n\n\t\tlong blk = Long.highestOneBit(hei);\n\n\t\tlong ext = wid % blk;\n\t\tlong reg = wid - ext;\n\n\t\tlong ans;\n\n\t\t// regOff indicates the item at position reg\n\t\tlong regOff = reg + off;\n\n\t\tif (regOff < T) {\n\t\t\tans = (sum(1 + off, regOff) * blk % MOD + sum(regOff + 1, min(regOff + blk, T)) * ext) % MOD;\n\t\t} else {\n\t\t\tans = sum(1 + off, T) * blk % MOD;\n\t\t}\n\n\t\tassert (0 <= ans && ans < MOD);\n\n\t\t// computation of sub values\n\t\tlong rem = hei - blk;\n\t\tassert (rem < blk);\n\t\tif (rem == 0) {\n\t\t\treturn ans;\n\t\t}\n\n\t\text = wid % (blk << 1);\n\t\treg = wid - ext;\n\n\t\tregOff = reg + off;\n\n\t\tif (regOff < T) {\n\t\t\tans = (ans + sum(1 + off, regOff) * rem) % MOD;\n\t\t\tassert (0 <= ans && ans < MOD);\n\n\t\t\tif (ext >= blk) {\n\t\t\t\tlong skip = reg + blk;\n\t\t\t\tif (skip + off < T) {\n\t\t\t\t\tans = (ans + sum(skip + 1 + off, min(skip + blk + off, T)) * rem) % MOD;\n\t\t\t\t}\n\n\t\t\t\text -= blk;\n\t\t\t\tif (ext > 0) {\n\t\t\t\t\tans = (ans + query(ext, rem, reg + off)) % MOD;\n\t\t\t\t}\n\n\t\t\t} else if (ext > 0) {\n\t\t\t\tans = (ans + query(ext, rem, reg + blk + off)) % MOD;\n\t\t\t}\n\t\t} else {\n\t\t\tans = (ans + sum(1 + off, T) * rem) % MOD;\n\t\t}\n\n\t\tassert (0 <= ans && ans < MOD);\n\n\t\treturn ans;\n\t}\n\n\tstatic long sum(long start, long end) {\n\t\tif (start > end) {\n\t\t\treturn 0;\n\t\t}\n\t\treturn (((end - start + 1L) * (start + end)) >> 1) % MOD;\n\t}\n\n\tstatic long min(long a, long b) {\n\t\treturn a < b ? a : b;\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["divide and conquer", "dp"], "code_uid": "89a5d87fc59897aae09dc8ff6e0876c1", "src_uid": "1ab085026ce43810acf98cc4bf8faf26", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class D896 {\n\t\n\tlong mod;\n\t\n\tlong[][] factorial(int n, Long[] prime) {\n\t\tint k = prime.length;\n\t\tlong[][] f = new long[n+1][k+1];\n\t\tf[0][0] = 1L;\n\t\tfor(int i = 1; i <= n; i++) {\n\t\t\tlong cur = i;\n\t\t\tfor(int j = 0; j <= k; j++) f[i][j] = f[i-1][j];\n\t\t\tfor(int j = 0; j < k; j++) {\t\t\t\t\n\t\t\t\twhile(cur%prime[j] == 0) {\n\t\t\t\t\tcur /= prime[j];\n\t\t\t\t\tf[i][j+1]++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tf[i][0] = (f[i][0] * cur) % mod;\n\t\t}\n\t\treturn f;\n\t}\n\t\n\tlong[][] natural(int n, Long[] prime) {\n\t\tint k = prime.length;\n\t\tlong[][] f = new long[n+1][k+1];\n\t\tfor(int i = 1; i <= n; i++) {\n\t\t\tf[i][0] = 1L;\n\t\t\tlong cur = i;\n\t\t\tfor(int j = 0; j < k; j++) {\t\t\t\t\n\t\t\t\twhile(cur%prime[j] == 0) {\n\t\t\t\t\tcur /= prime[j];\n\t\t\t\t\tf[i][j+1]++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tf[i][0] = cur % mod;\n\t\t}\n\t\treturn f;\n\t}\n\n\tLong[] factors(long p){\n\t\tLinkedList f = new LinkedList();\n\t\tlong x = 2;\n\t\twhile(x*x <= p) {\n\t\t\tlong y = 0;\n\t\t\twhile(p%x == 0) {\n\t\t\t\tp /= x;\n\t\t\t\ty++;\n\t\t\t}\n\t\t\tif(y != 0) f.addLast(x);\n\t\t\tx++;\n\t\t}\n\t\tif(p != 1) f.addLast(p);\n\t\treturn f.toArray(new Long[0]);\n\t}\n\n\tlong[] euclides(long x, long y) {\n\t\tif(y == 0) return new long[] {1L,0L};\n\t\tif(x == 0) return new long[] {0L,1L};\n\t\tlong[] res = euclides(y%x, x);\n\t\tlong a = res[0];\n\t\tlong b = res[1];\n\t\treturn new long[] {(b-a*(y/x)), a};\n\t}\n\n\tlong inverse(long x) {\n\t\tlong[] res = euclides(x, mod);\n\t\tlong a = res[0];\n\t\treturn ((a%mod)+mod)%mod;\n\t}\n\n\n\tlong modpow(long m, long n) {\n\t\tlong res = 1%mod;\n\t\twhile(n > 0){\n\t\t\tif(n % 2 == 1) res = (res*m)%mod;\n\t\t\tm = (m*m)%mod;\n\t\t\tn = n/2;\n\t\t}\n\t\treturn res;\n\t}\n\t\n\tlong[][] naturalPrime;\n\tlong[][] facPrime;\n\tLong[] prime;\n\tlong[] a0;\n\tlong[] al;\n\tlong[] alnext;\n\tlong[] ar;\n\tlong[] arnext;\n\t\n\tint n;\n\tint l;\n\tint r;\n\t\n\n\tprivate void solve() throws Exception {\n\t\tn = nextInt();\n\t\tmod = nextLong();\t\t\n\t\tl = nextInt();\n\t\tr = nextInt();\n\t\t\n\t\tprime = factors(mod);\n\t\tfacPrime = factorial(2*n, prime);\n\t\tnaturalPrime = natural(2*n, prime);\n\t\tlong[] C = new long[2*n+1];\n\t\t\n\t\tfor(int i = 0; i <= n; i++) {\n\t\t\tlong c = (((facPrime[n][0] * inverse(facPrime[i][0])) % mod) * inverse(facPrime[n-i][0])) % mod;\n\t\t\tfor(int j = 0; j < prime.length; j++) {\n\t\t\t\tc = (c * modpow(prime[j], facPrime[n][j+1] - facPrime[i][j+1] - facPrime[n-i][j+1]))%mod;\n\t\t\t}\n\t\t\tC[i] = c;\n\t\t}\n\t\ta0 = catalan(n,0);\n\t\tal = catalan(n,l-1);\n\t\talnext = catalan(n,l);\n\t\tar = catalan(n,r);\n\t\tarnext = catalan(n,r+1);\n\t\t\n\t\tlong[] br = b(r, ar, arnext);\n\t\tlong[] bl = b(l-1, al, alnext);\n\t\t\n\t\t\n\t\t\n\t\tlong res = 0;\n\t\tfor(int i = 0; i <= n; i++) res = (res + (((br[i]-bl[i]+mod)%mod)*C[i])%mod)%mod;\n\t\t\n\t\t\n\t\tout.println(res);\n\t}\n\t\n\tlong[] b(int t, long[] at, long[] atnext) {\n\t\tlong[] res = new long[n+1];\n\t\tif(t >= 0) res[0] = 1;\n\t\tfor(int i = 1; i <= n; i++) {\n\t\t\tres[i] = (2L * res[i-1])%mod;\n\t\t\tres[i] = (res[i] - ((i-t)%2 == 0 ? 0:at[(i+t)/2]) + mod)%mod;\n\t\t\tres[i] = (res[i] + ((i-(t+1))%2 == 0 ? 0:atnext[(i+t+1)/2]) + mod)%mod;\n\t\t\tres[i] = (res[i] - ((i-0)%2 == 0 ? 0: a0[(i+0)/2]) + mod)%mod;\n\t\t}\n\t\t\n\t\treturn res;\n\t}\n\t\n\tlong[] catalan(int n, int t) {\n\t\tlong[] res = new long[n+1];\n\t\tif(t < 0) return res;\n\t\tfor(int i = t; i <= n; i++) {\n\t\t\tres[i] = (((((facPrime[2*i-t][0] * inverse(facPrime[i+1][0])) % mod) * inverse(facPrime[i-t][0])) % mod) * naturalPrime[t+1][0]) % mod;\n\t\t\tfor(int j = 0; j < prime.length; j++) {\n\t\t\t\tres[i] = (res[i] * modpow(prime[j], naturalPrime[t+1][j+1] + facPrime[2*i-t][j+1] - facPrime[i+1][j+1] - facPrime[i-t][j+1]))%mod;\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew D896().run();\n\t}\n\n\n\n\tprivate BufferedReader in;\n\tprivate PrintWriter out;\n\tprivate StringTokenizer tokenizer;\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\ttokenizer = null;\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t\tin.close();\n\t\t\tout.close();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n\n\tprivate int nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tprivate long nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tprivate float nextFloat() throws IOException {\n\t\treturn Float.parseFloat(nextToken());\n\t}\n\n\tprivate String nextLine() throws IOException {\n\t\treturn new String(in.readLine());\n\t}\n\n\tprivate String nextToken() throws IOException {\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\ttokenizer = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tokenizer.nextToken();\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "combinatorics", "number theory"], "code_uid": "ec97c07ec98d487cc56a8a98b3616640", "src_uid": "6ddc487029785738679007443fc08463", "difficulty": 2900.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class E1646 {\r\n static final int MAX = (int) 1e6 + 1;\r\n\r\n static int gcd(int a, int b) {\r\n return a == 0 ? b : gcd(b % a, a);\r\n }\r\n\r\n public static void main(String[] args) throws IOException {\r\n Scanner sc = new Scanner(System.in);\r\n PrintWriter pw = new PrintWriter(System.out);\r\n int[] lp = new int[MAX];\r\n for (int i = 2; i < lp.length; i++) {\r\n if (lp[i] == 0) {\r\n for (int j = i; j < lp.length; j += i) {\r\n if (lp[j] == 0) {\r\n lp[j] = i;\r\n }\r\n }\r\n }\r\n }\r\n int n = sc.nextInt();\r\n int m = sc.nextInt();\r\n int[] val = new int[21];\r\n boolean[] vis = new boolean[20 * m + 1];\r\n for (int i = 1; i < val.length; i++) {\r\n for (int j = 1; j <= m; j++) {\r\n if (!vis[j * i]) {\r\n vis[j * i] = true;\r\n val[i]++;\r\n }\r\n }\r\n }\r\n long ans = 1;\r\n for (int i = 2; i <= n; i++) {\r\n int x = i;\r\n int curP = lp[x];\r\n int cnt = 0;\r\n ArrayList factors = new ArrayList<>();\r\n while (x > 1) {\r\n if (lp[x] == curP) {\r\n cnt++;\r\n } else {\r\n factors.add(cnt);\r\n curP = lp[x];\r\n cnt = 1;\r\n }\r\n x /= lp[x];\r\n }\r\n factors.add(cnt);\r\n// System.out.println(factors);\r\n int gcd = 0;\r\n for (int f : factors) {\r\n gcd = gcd(f, gcd);\r\n }\r\n ans += val[gcd];\r\n }\r\n pw.println(ans);\r\n pw.close();\r\n }\r\n\r\n static class Scanner {\r\n BufferedReader br;\r\n StringTokenizer st;\r\n\r\n public Scanner(InputStream s) {\r\n br = new BufferedReader(new InputStreamReader(s));\r\n }\r\n\r\n public Scanner(FileReader f) {\r\n br = new BufferedReader(f);\r\n }\r\n\r\n public String next() throws IOException {\r\n while (st == null || !st.hasMoreTokens())\r\n st = new StringTokenizer(br.readLine());\r\n return st.nextToken();\r\n }\r\n\r\n public int nextInt() throws IOException {\r\n return Integer.parseInt(next());\r\n }\r\n\r\n public long nextLong() throws IOException {\r\n return Long.parseLong(next());\r\n }\r\n\r\n public double nextDouble() throws IOException {\r\n return Double.parseDouble(next());\r\n }\r\n\r\n public int[] nextIntArr(int n) throws IOException {\r\n int[] arr = new int[n];\r\n for (int i = 0; i < n; i++) {\r\n arr[i] = Integer.parseInt(next());\r\n }\r\n return arr;\r\n }\r\n\r\n }\r\n}\r\n ", "lang_cluster": "Java", "tags": ["brute force", "math", "dp", "number theory"], "code_uid": "bd71108d0d1cfcd95e7ebb3addfb5f08", "src_uid": "6ca310cb0b6fc4e62e63a731cd55aead", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/**\n * @author derrick20\n */\n\nimport java.io.*;\nimport java.util.*;\n\npublic class TopScorer {\n public static void main(String[] args) throws Exception {\n FastScanner sc = new FastScanner();\n PrintWriter out = new PrintWriter(System.out);\n\n int P = sc.nextInt();\n int S = sc.nextInt();\n int R = sc.nextInt();\n // it should go up to s + p - 1, 5099, but let's be safe\n int MAX = 5100; // todo change this!\n fact = new long[MAX + 1];\n invFact = new long[MAX + 1];\n fact[0] = 1;\n invFact[0] = 1;\n for (int i = 1; i <= MAX; i++) {\n fact[i] = ((long) i * fact[i - 1]) % mod;\n invFact[i] = inv(fact[i]);\n }\n\n if (P == 1) {\n out.println(1);\n } else {\n // O(SP^2) = 5*10^7\n long wins = 0;\n long total = 0;\n for (int x = R; x <= S; x++) {\n // l = group that gets x\n // the remaining players P - 1 - l must get < x.\n for (int l = 0; P - 1 - l >= 0 && S - x - l * x >= 0; l++) {\n int players = P - 1 - l;\n int balls = S - x - l * x;\n// System.out.println(\"Forced \" + l + \" other players to have exactly \" + x + \" balls\");\n// System.out.println(\"Remaining: players = \" + players + \" balls = \" + balls);\n long prob = (choose(P - 1, l) * f(players, balls, x)) % mod;\n // prob of having this number of x's for players, then given\n // that, the probability of winning is uniform among all x players\n long contrib = (inv(l + 1) * prob) % mod;\n wins = (wins + contrib) % mod;\n// System.out.println(\"Prob: \" + prob + \" Contrib: \" + contrib);\n// System.out.println();\n }\n long ways = choose(S - x + P - 2, P - 2);\n// System.out.println(\"Ways for x = \" + x + \" = \" + ways);\n// System.out.println(\"----------\");\n total = (total + ways) % mod;\n }\n // we have now counted the number of winning states (scaling\n // with the f function). The probability is this divided by total\n // states.\n long prob = (wins * inv(total)) % mod;\n out.println(prob);\n }\n out.close();\n }\n\n // todo SET THE MOD\n static long mod = 998244353;\n static long[] fact, invFact;\n\n // f returns probability that with these parameters, we get an assignment\n // where all have < x balls.\n static long f(int players, int balls, int x) {\n // if there are no players, there MUST BE only 1 way.\n if (players == 0) {\n// ASSERT(balls <= x, \"Gave impossible amt\");\n /**\n * Key issue: add in logic for simple cases. If 0 players. it makes\n * no sense to give a positive number of balls, so 0 ways. If zero,\n * there is 1 way, i.e. do nothing.\n */\n return (balls == 0) ? 1 : 0;\n }\n long total = choose(balls + players - 1, players - 1);\n long complement = 0;\n int sign = 1;\n for (int k = 1; k <= players && balls - k * x >= 0; k++) {\n long amt = (choose(players, k) * choose(balls - k * x + players - 1, players - 1)) % mod;\n complement = (complement + sign * amt) % mod;\n sign *= -1;\n }\n// System.out.println(\"Ways for (players, balls) = \" + players + \" \" + balls + \": Total \" + total + \", Complement: \" + complement);\n long ans = (total - complement + mod) % mod;\n// ans = (ans * inv(total)) % mod; // probability\n return ans;\n }\n\n static long choose(int n, int k) {\n ASSERT(k <= n, \"Invalid choose\");\n long ans = (fact[n] * invFact[n - k]) % mod;\n return (ans * invFact[k]) % mod;\n }\n\n static long inv(long x) {\n return fastExpo(x, mod - 2);\n }\n\n static long fastExpo(long x, long k) {\n long ans = 1;\n long bit = x;\n while (k > 0) {\n if (k % 2 == 1) {\n ans = (bit * ans) % mod;\n }\n bit = (bit * bit) % mod;\n k /= 2;\n }\n return ans;\n }\n\n static class FastScanner {\n private int BS = 1 << 16;\n private char NC = (char) 0;\n private byte[] buf = new byte[BS];\n private int bId = 0, size = 0;\n private char c = NC;\n private double cnt = 1;\n private BufferedInputStream in;\n\n public FastScanner() {\n in = new BufferedInputStream(System.in, BS);\n }\n\n public FastScanner(String s) {\n try {\n in = new BufferedInputStream(new FileInputStream(new File(s)), BS);\n } catch (Exception e) {\n in = new BufferedInputStream(System.in, BS);\n }\n }\n\n private char getChar() {\n while (bId == size) {\n try {\n size = in.read(buf);\n } catch (Exception e) {\n return NC;\n }\n if (size == -1) return NC;\n bId = 0;\n }\n return (char) buf[bId++];\n }\n\n public int nextInt() {\n return (int) nextLong();\n }\n\n public int[] nextInts(int N) {\n int[] res = new int[N];\n for (int i = 0; i < N; i++) {\n res[i] = (int) nextLong();\n }\n return res;\n }\n\n public long[] nextLongs(int N) {\n long[] res = new long[N];\n for (int i = 0; i < N; i++) {\n res[i] = nextLong();\n }\n return res;\n }\n\n public long nextLong() {\n cnt = 1;\n boolean neg = false;\n if (c == NC) c = getChar();\n for (; (c < '0' || c > '9'); c = getChar()) {\n if (c == '-') neg = true;\n }\n long res = 0;\n for (; c >= '0' && c <= '9'; c = getChar()) {\n res = (res << 3) + (res << 1) + c - '0';\n cnt *= 10;\n }\n return neg ? -res : res;\n }\n\n public double nextDouble() {\n double cur = nextLong();\n return c != '.' ? cur : cur + nextLong() / cnt;\n }\n\n public double[] nextDoubles(int N) {\n double[] res = new double[N];\n for (int i = 0; i < N; i++) {\n res[i] = nextDouble();\n }\n return res;\n }\n\n public String next() {\n StringBuilder res = new StringBuilder();\n while (c <= 32) c = getChar();\n while (c > 32) {\n res.append(c);\n c = getChar();\n }\n return res.toString();\n }\n\n public String nextLine() {\n StringBuilder res = new StringBuilder();\n while (c <= 32) c = getChar();\n while (c != '\\n') {\n res.append(c);\n c = getChar();\n }\n return res.toString();\n }\n\n public boolean hasNext() {\n if (c > 32) return true;\n while (true) {\n c = getChar();\n if (c == NC) return false;\n else if (c > 32) return true;\n }\n }\n }\n\n static void ASSERT(boolean assertion, String message) {\n if (!assertion) throw new AssertionError(message);\n }\n}", "lang_cluster": "Java", "tags": ["probabilities", "math", "dp", "combinatorics"], "code_uid": "a1609c0b6a7967c965b6ff6328f9e134", "src_uid": "609195ef4a970c62a8210dafe118580e", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class B {\n public static void main(String[] args)throws Throwable {\n MyScanner sc=new MyScanner();\n PrintWriter pw=new PrintWriter(System.out);\n\n long n=sc.nextInt();\n\n// if(n<15)\n// pw.println(solve(n));\n// else\n// pw.println(solve(15)+(n-15)*49);\n\n\n boolean [][] ok=new boolean [10][50];\n for(boolean [] x : ok)\n Arrays.fill(x,true);\n for(int i=0;i<9;i++)\n for(int j=0;j<49;j++)\n for(int i2=0;i2<9;i2++)\n for(int j2=0;j2<49;j2++) {\n int x = i * 4 + j * 9 - i2 * 4 - j2 * 9;\n if (x > 0 && x % 49 == 0)\n ok[i][j] = false;\n }\n long ans=0;\n for(int i=0;i<9;i++)\n for(int j=0;j<49;j++)\n if(ok[i][j] && n>=i+j)\n ans+=n-i-j+1;\n pw.println(ans);\n pw.flush();\n pw.close();\n }\n\n static int solve(long n){\n HashSet set=new HashSet<>();\n for(int i=0;i<=n;i++)\n for(int j=0;j<=n-i;j++)\n for(int k=0;k<=n-i-j;k++)\n set.add(i*50+j*10+k*5+n-i-j-k);\n return set.size();\n }\n\n static class MyScanner {\n BufferedReader br;\n StringTokenizer st;\n public MyScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n String next() {while (st == null || !st.hasMoreElements()) {\n try {st = new StringTokenizer(br.readLine());}\n catch (IOException e) {e.printStackTrace();}}\n return st.nextToken();}\n int nextInt() {return Integer.parseInt(next());}\n long nextLong() {return Long.parseLong(next());}\n double nextDouble() {return Double.parseDouble(next());}\n String nextLine(){String str = \"\";\n try {str = br.readLine();}\n catch (IOException e) {e.printStackTrace();}\n return str;}\n }\n} ", "lang_cluster": "Java", "tags": ["brute force", "math", "dp", "combinatorics", "greedy"], "code_uid": "d477c14b6d0ef1310b07c751b0047fc7", "src_uid": "75ec99318736a8a1b62a8d51efd95355", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "// Don't place your source in a package\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.math.*; \n \n /*\n \n 6666666666666\t\t\t 6666666666666 \n 6\t\t\t\t\t\t 6 \t\t\t\t\t\t\t\t\t\t\t \t\t\t\n 6\t\t\t\t\t\t 6 \n 6\t\t\t\t\t\t 6 \n 6\t\t\t\t\t\t 6 \n 6 6 \n 6666666666666 6666666666666 \n 6\t\t 6 6\t\t 6\n 6\t\t\t 6\t 6\t\t\t 6 \n 6\t\t\t 6 6\t\t\t 6\n 6\t\t 6\t 6\t\t 6\t\n 6666666666666 6666666666666\n \n \n */\n \n \n \n \n \n// Please name your class Main\npublic class Main {\n\t\n\t//static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n \n /*static int read() throws IOException {\n in.nextToken();\n return (int) in.nval;\n }\n static String readString() throws IOException {\n in.nextToken();\n return in.sval;\n\t}*/\n\t\n\t\n\tstatic Scanner in = new Scanner(System.in);\n\t\n\tpublic static void main (String[] args) throws java.lang.Exception {\n\t \n\t\t//InputReader in = new InputReader(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t\n \n\t\tint T=1;\n\t\t\n\t\tfor(int t=0;tadjecent[];\n\t//////////////////////////////\n \n\t\n\t\n\tpublic void solution(int K,long F[],int W){\n\t\tlong res=0;\n\t\tint ten[]=new int[]{1,10,100,1000,10000,100000};\t\n\t\t\n\t\t//0-1 knapsack, creating items\n\t\tListA=new ArrayList<>();\n\t\t\n\t\tK--;//extra number\n\t\t\n\t\tif(K==0){\n\t\t\tString num=(W)+\"\";\n\t\t\tStringBuilder str=new StringBuilder(num);\n\t\t\tnum=str.reverse().toString();\n\t\t\tlong score=0;\n\t\t\tfor(int k=0;k=(3*K)){\n\t\t\t\t\tlong remain=3*K-cur;\n\t\t\t\t\tItem item=new Item(weight*remain,F[i]*remain,i);\n\t\t\t\t\tA.add(item);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tItem item=new Item(weight*(1<i)return 0;\n\t\tif(j==0)return 1;\n\t\tlong mod=1000000007;\n\t\tlong a=fact[i];\n\t\tlong b=((fact[i-j]%mod)*(fact[j]%mod))%mod;\n\t\tBigInteger B= BigInteger.valueOf(b);\n\t\tlong binverse=B.modInverse(BigInteger.valueOf(mod)).longValue();\n\t\treturn ((a)*(binverse%mod))%mod;\n\t}\n\t\n\t\n\t \n\t\n\t//map operation\n\tpublic void put(Mapmap,int i){\n\t\tif(!map.containsKey(i))map.put(i,0);\n\t\tmap.put(i,map.get(i)+1);\n\t}\n\t\n\tpublic void delete(Mapmap,int i){\n\t\tmap.put(i,map.get(i)-1);\n\t\tif(map.get(i)==0)map.remove(i);\n\t}\n \n \n \n \n \n\t\n \n \n\t/*public void tarjan(int p,int r){\n\t\tif(cut)return;\n\t\tListchilds=adjecent[r];\n\t\tdis[r]=low[r]=time;\n\t\ttime++;\n\t\t\n\t\t//core for tarjan\n\t\tint son=0;\n\t\tfor(int c:childs){\n\t\t\tif(ban==c||c==p)continue;\n\t\t\tif(dis[c]==-1){\n\t\t\t\tson++;\n\t\t\t\ttarjan(r,c);\n\t\t\t\tlow[r]=Math.min(low[r],low[c]);\n\t\t\t\tif((r==root&&son>1)||(low[c]>=dis[r]&&r!=root)){\n\t\t\t\t\tcut=true;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tif(c!=p){\n\t\t\t\t\tlow[r]=Math.min(low[r],dis[c]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t}*/\n\t\n\t\n \n\t\n\t//helper function I would use\n\tpublic void remove(Mapmap,int i){\n\t\tmap.put(i,map.get(i)-1);\n\t\tif(map.get(i)==0)map.remove(i);\n\t}\n\t\n\t\n\t\n\tpublic void ascii(String s){\n\t\tfor(char c:s.toCharArray()){\n\t\t\tSystem.out.print((c-'a')+\" \");\n\t\t}\n\t\tmsg(\"\");\n\t}\n\t\n\tpublic int flip(int i){\n\t\tif(i==0)return 1;\n\t\telse return 0;\n\t}\n\t\n\tpublic boolean[] primes(int n){\n\t\tboolean A[]=new boolean[n+1];\n\t\tfor(int i=2;i<=n;i++){\n\t\t\tif(A[i]==false){\n\t\t\t\tfor(int j=i+i;j<=n;j+=i){\n\t\t\t\t\tA[j]=true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn A;\n\t}\n\t\n\tpublic void msg(String s){\n\t\tSystem.out.println(s);\n\t}\n\t\n\tpublic void msg1(String s){\n\t\tSystem.out.print(s);\n\t}\n\t\n\tpublic int[] kmpPre(String p){\n\t\tint pre[]=new int[p.length()];\n\t\tint l=0,r=1;\n\t\twhile(r find method\n\t\tif(nums[x]==x)return x;\n\t\tint root=find(nums,nums[x]);\n\t\tnums[x]=root;\n\t\treturn root;\n\t}\n\t\n \n\t\n\tpublic int get(int A[],int i){\n\t\tif(i<0||i>=A.length)return 0;\n\t\treturn A[i];\n\t}\n\tpublic int[] copy1(int A[]){\n\t\tint a[]=new int[A.length];\n\t\tfor(int i=0;i=grid.length||j>=grid[0].length)return 0;\n return grid[i][j];\n }\n\t\n\tpublic int[] suffixArray(String s){\n\t\tint n=s.length();\n\t\tSuffix A[]=new Suffix[n];\n\t\t\n\t\tfor(int i=0;i=A.length){\n\t\t\t\t\tA[i].next=-1;\n\t\t\t\t}else{\n\t\t\t\t\tA[i].next=A[in[next]].rank;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\tArrays.sort(A);\n\t\t}\n\t\t\n\t\t\n\t\tint su[]=new int[A.length];\n\t\tfor(int i=0;i{\n\tint index;\n\tint rank;\n\tint next;\n\tpublic Suffix(int i,int rank,int next){\n\t\tthis.index=i;\n\t\tthis.rank=rank;\n\t\tthis.next=next;\n\t}\n\t\n\t@Override\n\tpublic int compareTo(Suffix other) {\n\t\tif(this.rank==other.rank){\n\t\t\treturn this.next-other.next;\n\t\t}\n\t\treturn this.rank-other.rank;\n\t}\n\t\n\tpublic String toString(){\n\t\treturn this.index+\" \"+this.rank+\" \"+this.next+\" \";\n\t}\n}\n \n \n \nclass Wrapper implements Comparable{\n\tint spf;int cnt;\n\tpublic Wrapper(int spf,int cnt){\n\t\tthis.spf=spf;\n\t\tthis.cnt=cnt;\n\t}\n\t\t\n\t@Override\n\tpublic int compareTo(Wrapper other) {\n\t\treturn this.spf-other.spf;\n\t}\n}\n \n \n \n class Node{//what the range would be for that particular node\n\t\tboolean state=false;\n int l=0,r=0;\n\t\tint ll=0,rr=0;\n public Node(boolean state){\n this.state=state;\n }\n }\n\t\n\t\n\t\n\t\n\tclass Seg1{\n\t\t\tint A[];\n\t\t\tpublic Seg1(int A[]){\n\t\t\t\tthis.A=A;\n\t\t\t}\n\t\t\t\n\t\t\tpublic void update(int left,int right,int val,int s,int e,int id){\n\t\t\t\tif(left<0||right<0||left>right)return;\n\t\t\t\tif(left==s&&right==e){\n\t\t\t\t\t\n\t\t\t\t\tA[id]+=val;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tint mid=s+(e-s)/2; //[s,mid] [mid+1,e]\n\t\t\t\t\n\t\t\t\tif(left>=mid+1){\n\t\t\t\t\tupdate(left,right,val,mid+1,e,id*2+2);\n\t\t\t\t}else if(right<=mid){\n\t\t\t\t\tupdate(left,right,val,s,mid,id*2+1);\n\t\t\t\t}else{\n\t\t\t\t\tupdate(left,mid,val,s,mid,id*2+1);\n\t\t\t\t\tupdate(mid+1,right,val,mid+1,e,id*2+2);\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tpublic int query(int i,int add,int s,int e,int id){\n\t\t\t\t\n\t\t\t\tif(s==e&&i==s){\n\t\t\t\t\treturn A[id]+add;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tint mid=s+(e-s)/2; //[s,mid] [mid+1,e]\n\t\t\t\t\n\t\t\t\tif(i>=mid+1){\n\t\t\t\t\treturn query(i,A[id]+add,mid+1,e,id*2+2);\n\t\t\t\t}else{\n\t\t\t\t\treturn query(i,A[id]+add,s,mid,id*2+1);\n\t\t\t\t}\n\t\t\t}\n\t}\n \n \n\t class MaxFlow{\n\t\t\n \n\t\t public static List[] createGraph(int nodes) {\n\t\t\tList[] graph = new List[nodes];\n\t\t\tfor (int i = 0; i < nodes; i++)\n\t\t\t graph[i] = new ArrayList<>();\n\t\t\treturn graph;\n\t\t }\n \n\t\t public static void addEdge(List[] graph, int s, int t, int cap) {\n\t\t\tgraph[s].add(new Edge(t, graph[t].size(), cap));\n\t\t\tgraph[t].add(new Edge(s, graph[s].size() - 1, 0));\n\t\t }\n \n\t\t static boolean dinicBfs(List[] graph, int src, int dest, int[] dist) {\n\t\t\tArrays.fill(dist, -1);\n\t\t\tdist[src] = 0;\n\t\t\tint[] Q = new int[graph.length];\n\t\t\tint sizeQ = 0;\n\t\t\tQ[sizeQ++] = src;\n\t\t\tfor (int i = 0; i < sizeQ; i++) {\n\t\t\t int u = Q[i];\n\t\t\t for (Edge e : graph[u]) {\n\t\t\t\tif (dist[e.t] < 0 && e.f < e.cap) {\n\t\t\t\t dist[e.t] = dist[u] + 1;\n\t\t\t\t Q[sizeQ++] = e.t;\n\t\t\t\t}\n\t\t\t }\n\t\t\t}\n\t\t\treturn dist[dest] >= 0;\n\t\t }\n \n\t\t static int dinicDfs(List[] graph, int[] ptr, int[] dist, int dest, int u, int f) {\n\t\t\tif (u == dest)\n\t\t\t return f;\n\t\t\tfor (; ptr[u] < graph[u].size(); ++ptr[u]) {\n\t\t\t Edge e = graph[u].get(ptr[u]);\n\t\t\t if (dist[e.t] == dist[u] + 1 && e.f < e.cap) {\n\t\t\t\tint df = dinicDfs(graph, ptr, dist, dest, e.t, Math.min(f, e.cap - e.f));\n\t\t\t\tif (df > 0) {\n\t\t\t\t e.f += df;\n\t\t\t\t graph[e.t].get(e.rev).f -= df;\n\t\t\t\t return df;\n\t\t\t\t}\n\t\t\t }\n\t\t\t}\n\t\t\treturn 0;\n\t\t }\n \n\t\t public static int maxFlow(List[] graph, int src, int dest) {\n\t\t\tint flow = 0;\n\t\t\tint[] dist = new int[graph.length];\n\t\t\twhile (dinicBfs(graph, src, dest, dist)) {\n\t\t\t int[] ptr = new int[graph.length];\n\t\t\t while (true) {\n\t\t\t\tint df = dinicDfs(graph, ptr, dist, dest, src, Integer.MAX_VALUE);\n\t\t\t\tif (df == 0)\n\t\t\t\t break;\n\t\t\t\tflow += df;\n\t\t\t }\n\t\t\t}\n\t\t\treturn flow;\n\t\t }\n\t\t \n\t }\n\t \n\t \t class Edge {\n\t\t\tint t, rev, cap, f;\n \n\t\t\tpublic Edge(int t, int rev, int cap) {\n\t\t\t this.t = t;\n\t\t\t this.rev = rev;\n\t\t\t this.cap = cap;\n\t\t\t}\n\t\t }\n\t\t \n\t\t \n\t\t \n\t\t \n\t\t \n\t\t \n class Seg{\n int l,r;\n int min=Integer.MAX_VALUE;\n Seg left=null,right=null;\n\t\tlong sum=0;long cnt=0;\n public Seg(int l,int r){\n this.l=l;\n this.r=r;\n \n }\n public long[] query(int s,int e){\n if(l==s&&r==e){\n return new long[]{sum,cnt};\n }\n int mid=l+(r-l)/2; //left : to mid-1,\n\t\t\t\n\t\t\tif(left==null)left=new Seg(l,mid);\n\t\t\tif(right==null)right=new Seg(mid+1,r);\n \n\t\t\tif(e<=mid){\n return left.query(s,e);\n }\n else if(s>=mid+1){\n return right.query(s,e);\n }else{\n\t\t\t\tlong A[]=left.query(s,mid);\n\t\t\t\tlong B[]=right.query(mid+1,e);\n\t\t\t\treturn new long[]{A[0]+B[0],A[1]+B[1]};\n \n }\n }\n \n public void update(int index,int v){\n\t\t\tsum+=v;\n\t\t\tcnt++;\n if(l==r&&l==index){\n return;\n }\n int mid=l+(r-l)/2;\n if(index<=mid){\n\t\t\t\tif(left==null)left=new Seg(l,mid);\n left.update(index,v);\n }else{\n\t\t\t\tif(right==null)right=new Seg(mid+1,r);\n right.update(index,v);\n }\n \n }\n }", "lang_cluster": "Java", "tags": ["greedy", "dp"], "code_uid": "90ce80dc951ab2094900e4ed4c037d86", "src_uid": "92bcbac3f167a44c235e99afc4de20d2", "difficulty": 2900.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.Comparator;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.NoSuchElementException;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Egor Kulikov (egor@egork.net)\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tOutputWriter out = new OutputWriter(outputStream);\n\t\tTaskD solver = new TaskD();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskD {\n\tprivate static final long MOD = 1000000007;\n\tlong[][][] answer;\n\tprivate int upTo;\n\n\tpublic void solve(int testNumber, InputReader in, OutputWriter out) {\n\t\tupTo = in.readInt();\n\t\tanswer = new long[2][30][31];\n\t\tArrayUtils.fill(answer, -1);\n\t\tlong result = go(1, 29, 0);\n\t\tout.printLine(result);\n }\n\n\tprivate long go(int full, int bit, int groups) {\n\t\tif (groups < 0)\n\t\t\treturn 0;\n\t\tif (bit == -1)\n\t\t\treturn 1;\n\t\tif (answer[full][bit][groups] != -1)\n\t\t\treturn answer[full][bit][groups];\n\t\tlong result;\n\t\tif (full == 0 || (upTo >> bit & 1) == 1) {\n\t\t\tif (groups != 0)\n\t\t\t\tresult = go(0, bit - 1, groups) * (1 << (groups - 1)) + go(full, bit - 1, groups) * (1 << (groups - 1)) + go(full, bit - 1, groups + 1);\n\t\t\telse\n\t\t\t\tresult = go(full, bit - 1, 1) + go(0, bit - 1, groups);\n\t\t} else if ((upTo >> bit & 1) == 0 && groups != 0)\n\t\t\tresult = go(full, bit - 1, groups) * (1 << (groups - 1));\n\t\telse\n\t\t\tresult = go(full, bit - 1, groups);\n\t\treturn answer[full][bit][groups] = result % MOD;\n\t}\n}\n\nclass InputReader {\n\n\tprivate InputStream stream;\n\tprivate byte[] buf = new byte[1024];\n\tprivate int curChar;\n\tprivate int numChars;\n\tprivate SpaceCharFilter filter;\n\n\tpublic InputReader(InputStream stream) {\n\t\tthis.stream = stream;\n\t}\n\n\tpublic int read() {\n\t\tif (numChars == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (curChar >= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n\n\tpublic int readInt() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tint res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tpublic boolean isSpaceChar(int c) {\n\t\tif (filter != null)\n\t\t\treturn filter.isSpaceChar(c);\n\t\treturn isWhitespace(c);\n\t}\n\n\tpublic static boolean isWhitespace(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n\n\tpublic interface SpaceCharFilter {\n\t\tpublic boolean isSpaceChar(int ch);\n\t}\n}\n\nclass OutputWriter {\n\tprivate final PrintWriter writer;\n\n\tpublic OutputWriter(OutputStream outputStream) {\n\t\twriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n\t}\n\n\tpublic OutputWriter(Writer writer) {\n\t\tthis.writer = new PrintWriter(writer);\n\t}\n\n\tpublic void close() {\n\t\twriter.close();\n\t}\n\n\tpublic void printLine(long i) {\n\t\twriter.println(i);\n\t}\n\n\t}\n\nclass ArrayUtils {\n\n\tpublic static void fill(long[][] array, long value) {\n\t\tfor (long[] row : array)\n\t\t\tArrays.fill(row, value);\n\t}\n\n\tpublic static void fill(long[][][] array, long value) {\n\t\tfor (long[][] row : array)\n\t\t\tfill(row, value);\n\t}\n\n\t}\n\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "bcdafa59e22da89c67928a794ce6c9f0", "src_uid": "ead64d8e3134fa8f29881cb487e52f60", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class ETry implements Runnable {\n\n private PrintWriter out = new PrintWriter(System.out, true);\n private Scanner scanner;\n\n int n;\n int[] size;\n int[] parent;\n PointWI[] points;\n int[] ans;\n \n Graph graph;\n\n @Override\n public void run() {\n n = scanner.nextInt();\n // \u0447\u0438\u0442\u0430\u0435\u043c \u0433\u0440\u0430\u0444\n graph = new Graph(n);\n \n for (int i = 0; i < n - 1; i++) {\n int x = scanner.nextInt() - 1;\n int y = scanner.nextInt() - 1;\n graph.addEdge(x, y);\n }\n \n // \u0447\u0438\u0442\u0430\u0435\u043c \u0442\u043e\u0447\u043a\u0438\n points = new PointWI[n];\n for (int i = 0; i < n; i++) {\n points[i] = new PointWI(scanner.nextLong(), scanner.nextLong(), i);\n }\n\n // \u043f\u043e\u0434\u0432\u0435\u0448\u0438\u0432\u0430\u0435\u043c \u0434\u0435\u0440\u0435\u0432\u043e \u0438 \n size = new int[n];\n parent = new int[n];\n dfs(0, -1);\n \n // \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u043e\u0442\u0432\u0435\u0442\n ans = new int[n];\n Arrays.fill(ans, -1);\n \n // \u0438\u0449\u0435\u043c \u0441\u0430\u043c\u044b\u0439 \u043b\u0435\u0432\u044b\u0439\n int rootIndex = 0;\n for (int i = 1; i < n; i++) {\n if (points[i].x < points[rootIndex].x || points[i].x == points[rootIndex].x\n && points[i].y < points[rootIndex].y) {\n rootIndex = i;\n }\n }\n \n // \u0441\u0442\u0430\u0432\u0438\u043c \u0441\u0430\u043c\u044b\u0439 \u043b\u0435\u0432\u044b\u0439 \u043f\u0435\u0440\u0432\u044b\u043c\n PointWI tmp = points[0];\n points[0] = points[rootIndex];\n points[rootIndex] = tmp;\n \n \n // \u0441\u0447\u0438\u0442\u0430\u0435\u043c\n rec(0, 0, n - 1);\n \n // \u043e\u0442\u0432\u0435\u0442\n for (int i = 0; i < n; i++) {\n out.print(ans[i] + 1);\n if (i == n - 1) {\n out.println();\n } else {\n out.print(\" \");\n }\n }\n }\n\n private void rec(int x, int left, int right) {\n ans[points[left].i] = x;\n Arrays.sort(points, left + 1, right + 1, new PointComparator(points[left]));\n int i = left + 1;\n for (int y : graph.adjacent(x)) {\n if (y != parent[x]) {\n rec(y, i, i + size[y] - 1);\n i += size[y];\n }\n }\n }\n\n private void dfs(int x, int p) {\n parent[x] = p;\n size[x] = 1;\n for (int y : graph.adjacent(x)) {\n if (y != p) {\n dfs(y, x);\n size[x] += size[y];\n }\n }\n }\n \n public ETry setInput(InputStream inputStream) {\n this.scanner = new Scanner(inputStream);\n return this;\n }\n\n public static void main(String[] args) {\n new ETry().setInput(System.in).run();\n }\n}\n\nclass Graph {\n private final int n;\n private final List> adj;\n \n public Graph(int n) {\n this.n = n;\n this.adj = new ArrayList>(n);\n createAdjList(n);\n }\n\n private void createAdjList(int n) {\n while (n > 0) {\n this.adj.add(new ArrayList());\n n--;\n }\n }\n \n public void addEdge(int v, int u) {\n adj.get(v).add(u);\n adj.get(u).add(v);\n }\n \n public Iterable adjacent(int v) {\n return adj.get(v);\n }\n\n public int getN() {\n return n;\n }\n}\n\n//solution\n\nclass PointWI {\n long x, y;\n int i;\n\n public PointWI(long x, long y, int i) {\n this.x = x;\n this.y = y;\n this.i = i;\n }\n\n @Override\n public String toString() {\n return String.format(\"[(%d %d) %d]\", x, y, i);\n }\n\n}\n\nclass PointComparator implements Comparator {\n PointWI root;\n\n public PointComparator(PointWI root) {\n this.root = root;\n }\n\n @Override\n public int compare(PointWI a, PointWI b) {\n long wp = (a.x - root.x) * (b.y - root.y) - (a.y - root.y) * (b.x - root.x);\n if (wp < 0)\n return -1;\n if (wp > 0)\n return 1;\n return 0;\n }\n}", "lang_cluster": "Java", "tags": ["dfs and similar", "geometry", "constructive algorithms", "trees"], "code_uid": "9272b184ff5ec18974f658823e13a1c8", "src_uid": "d65e91dc274c6659cfdb50bc8b8020ba", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.UncheckedIOException;\nimport java.io.Closeable;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, new TaskAdapter(), \"\", 1 << 27);\n thread.start();\n thread.join();\n }\n\n static class TaskAdapter implements Runnable {\n @Override\n public void run() {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastInput in = new FastInput(inputStream);\n FastOutput out = new FastOutput(outputStream);\n G2PlaylistForPolycarpHardVersion solver = new G2PlaylistForPolycarpHardVersion();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class G2PlaylistForPolycarpHardVersion {\n Modular mod = new Modular(1e9 + 7);\n\n public void solve(int testNumber, FastInput in, FastOutput out) {\n int n = in.readInt();\n int m = in.readInt();\n int[][] musics = new int[n][2];\n int[] cnts = new int[4];\n for (int i = 0; i < n; i++) {\n musics[i][0] = in.readInt();\n musics[i][1] = in.readInt();\n cnts[musics[i][1]]++;\n }\n\n int c1 = cnts[1];\n int c2 = cnts[2];\n int c3 = cnts[3];\n\n int[][][][] comp = new int[c1 + 1][c2 + 1][c3 + 1][4];\n for (int i = 0; i <= c1; i++) {\n for (int j = 0; j <= c2; j++) {\n for (int k = 0; k <= c3; k++) {\n for (int t = 0; t < 4; t++) {\n if (i == 0 && j == 0 && k == 0) {\n comp[i][j][k][t] = 1;\n continue;\n }\n if (i > 0 && t != 1) {\n comp[i][j][k][t] = mod.plus(comp[i][j][k][t], mod.mul(comp[i - 1][j][k][1], i));\n }\n if (j > 0 && t != 2) {\n comp[i][j][k][t] = mod.plus(comp[i][j][k][t], mod.mul(comp[i][j - 1][k][2], j));\n }\n if (k > 0 && t != 3) {\n comp[i][j][k][t] = mod.plus(comp[i][j][k][t], mod.mul(comp[i][j][k - 1][3], k));\n }\n }\n }\n }\n }\n\n int[][][][] last = new int[c1 + 1][c2 + 1][c3 + 1][m + 1];\n int[][][][] next = new int[c1 + 1][c2 + 1][c3 + 1][m + 1];\n\n last[0][0][0][0] = 1;\n int t1 = 0;\n int t2 = 0;\n int t3 = 0;\n for (int[] music : musics) {\n int m1 = music[1];\n int m0 = music[0];\n if (m1 == 1) {\n t1++;\n } else if (m1 == 2) {\n t2++;\n } else {\n t3++;\n }\n for (int i = 0; i <= t1; i++) {\n for (int j = 0; j <= t2; j++) {\n for (int k = 0; k <= t3; k++) {\n for (int t = 0; t <= m; t++) {\n next[i][j][k][t] = last[i][j][k][t];\n if (t < m0) {\n continue;\n }\n if (m1 == 1 && i > 0) {\n next[i][j][k][t] = mod.plus(next[i][j][k][t], last[i - 1][j][k][t - m0]);\n } else if (m1 == 2 && j > 0) {\n next[i][j][k][t] = mod.plus(next[i][j][k][t], last[i][j - 1][k][t - m0]);\n } else if (m1 == 3 && k > 0) {\n next[i][j][k][t] = mod.plus(next[i][j][k][t], last[i][j][k - 1][t - m0]);\n }\n }\n }\n }\n }\n\n int[][][][] tmp = last;\n last = next;\n next = tmp;\n }\n\n int ans = 0;\n for (int i = 0; i <= c1; i++) {\n for (int j = 0; j <= c2; j++) {\n for (int k = 0; k <= c3; k++) {\n ans = mod.plus(ans, mod.mul(last[i][j][k][m], comp[i][j][k][0]));\n }\n }\n }\n\n out.println(ans);\n }\n\n }\n\n static class Modular {\n int m;\n\n public Modular(int m) {\n this.m = m;\n }\n\n public Modular(long m) {\n this.m = (int) m;\n if (this.m != m) {\n throw new IllegalArgumentException();\n }\n }\n\n public Modular(double m) {\n this.m = (int) m;\n if (this.m != m) {\n throw new IllegalArgumentException();\n }\n }\n\n public int valueOf(int x) {\n x %= m;\n if (x < 0) {\n x += m;\n }\n return x;\n }\n\n public int valueOf(long x) {\n x %= m;\n if (x < 0) {\n x += m;\n }\n return (int) x;\n }\n\n public int mul(int x, int y) {\n return valueOf((long) x * y);\n }\n\n public int plus(int x, int y) {\n return valueOf(x + y);\n }\n\n public String toString() {\n return \"mod \" + m;\n }\n\n }\n\n static class FastOutput implements AutoCloseable, Closeable {\n private StringBuilder cache = new StringBuilder(10 << 20);\n private final Writer os;\n\n public FastOutput(Writer os) {\n this.os = os;\n }\n\n public FastOutput(OutputStream os) {\n this(new OutputStreamWriter(os));\n }\n\n public FastOutput println(int c) {\n cache.append(c).append('\\n');\n return this;\n }\n\n public FastOutput flush() {\n try {\n os.append(cache);\n os.flush();\n cache.setLength(0);\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n return this;\n }\n\n public void close() {\n flush();\n try {\n os.close();\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n public String toString() {\n return cache.toString();\n }\n\n }\n\n static class FastInput {\n private final InputStream is;\n private byte[] buf = new byte[1 << 13];\n private int bufLen;\n private int bufOffset;\n private int next;\n\n public FastInput(InputStream is) {\n this.is = is;\n }\n\n private int read() {\n while (bufLen == bufOffset) {\n bufOffset = 0;\n try {\n bufLen = is.read(buf);\n } catch (IOException e) {\n bufLen = -1;\n }\n if (bufLen == -1) {\n return -1;\n }\n }\n return buf[bufOffset++];\n }\n\n public void skipBlank() {\n while (next >= 0 && next <= 32) {\n next = read();\n }\n }\n\n public int readInt() {\n int sign = 1;\n\n skipBlank();\n if (next == '+' || next == '-') {\n sign = next == '+' ? 1 : -1;\n next = read();\n }\n\n int val = 0;\n if (sign == 1) {\n while (next >= '0' && next <= '9') {\n val = val * 10 + next - '0';\n next = read();\n }\n } else {\n while (next >= '0' && next <= '9') {\n val = val * 10 - next + '0';\n next = read();\n }\n }\n\n return val;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["dp", "combinatorics"], "code_uid": "4feccd4feffa6bd9bf743fab53e1de25", "src_uid": "ed5f913afe829c65792b54233a256757", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Solution {\n final static int MOD = (int)1e9 + 7;\n\n public void run() {\n try {\n int n = reader.nextInt();\n int m = reader.nextInt();\n int[][] binom = new int[n + 1][n + 1];\n for (int i = 0; i <= n; ++ i) {\n binom[i][0] = 1;\n for (int j = 1; j <= i; ++ j) {\n binom[i][j] = (binom[i - 1][j - 1] + binom[i - 1][j]) % MOD;\n }\n }\n int[][] ways = new int[n + 1][4];\n ways[0][1] = 1;\n for (int i = 0; i < n; ++ i) {\n int[][] newWays = new int[n + 1][4];\n for (int j = 0; j <= n; ++ j) {\n for (int mask = 0; mask < 4; ++ mask) {\n if (ways[j][mask] == 0) {\n continue;\n }\n newWays[j][(mask << 1 | 1) & 3] += ways[j][mask];\n newWays[j][(mask << 1 | 1) & 3] %= MOD;\n if ((mask >> 1 & 1) == 1) {\n newWays[j + 1][(mask << 1 | 1) & 3] += ways[j][mask];\n newWays[j + 1][(mask << 1 | 1) & 3] %= MOD;\n }\n if (i + 1 < n) {\n newWays[j + 1][mask << 1 & 3] += ways[j][mask];\n newWays[j + 1][mask << 1 & 3] %= MOD;\n }\n }\n }\n ways = newWays;\n }\n int[] factorial = new int[n + 1];\n factorial[0] = 1;\n for (int i = 1; i <= n; ++ i) {\n factorial[i] = (int)((long)factorial[i - 1] * i % MOD);\n }\n int[] atLeast = new int[n + 1];\n for (int i = 0; i <= n; ++ i) {\n for (int mask = 0; mask < 4; ++ mask) {\n atLeast[i] += (long)ways[i][mask] * factorial[n - i] % MOD;\n atLeast[i] %= MOD;\n }\n }\n int[] exactly = new int[n + 1];\n for (int i = n; i >= 0; -- i) {\n exactly[i] = atLeast[i];\n for (int j = i + 1; j <= n; ++ j) {\n exactly[i] -= (long)exactly[j] * binom[j][i] % MOD;\n exactly[i] %= MOD;\n }\n }\n writer.println((exactly[m] + MOD) % MOD);\n } catch (IOException ex) {\n }\n writer.close();\n }\n\n InputReader reader;\n PrintWriter writer;\n\n Solution() {\n reader = new InputReader();\n writer = new PrintWriter(System.out);\n }\n\n public static void main(String[] args) {\n new Solution().run();\n }\n \n void debug(Object...os) {\n System.err.println(Arrays.deepToString(os));\n }\n}\n\nclass InputReader {\n BufferedReader reader;\n StringTokenizer tokenizer;\n\n InputReader() {\n reader = new BufferedReader(new InputStreamReader(System.in));\n tokenizer = new StringTokenizer(\"\");\n }\n\n String next() throws IOException {\n while (!tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(reader.readLine());\n }\n return tokenizer.nextToken();\n }\n\n Integer nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics"], "code_uid": "2fd0750ce8ac444be0a3e56f910cffa1", "src_uid": "1243e98fe2ebd6e6d1de851984b96079", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Iterator;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.NoSuchElementException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author svilen.marchev@gmail.com\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskF solver = new TaskF();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskF {\n int n;\n char[] s;\n int[] ugliness;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n n = in.readInt();\n s = in.readString().toCharArray();\n ugliness = new int[n];\n for (int i = 0; i < n; ++i) {\n ugliness[i] = -in.readInt();\n }\n\n Graph graph = new Graph(1 + 26 + n / 2 + 1);\n for (char c = 'a'; c <= 'z'; ++c) {\n for (int i = 0; i < n / 2; ++i) {\n int cost = 0;\n if (c == s[i]) {\n cost = Math.min(cost, ugliness[i]);\n }\n if (c == s[n - 1 - i]) {\n cost = Math.min(cost, ugliness[n - 1 - i]);\n }\n graph.addFlowWeightedEdge(1 + (c - 'a'), 1 + 26 + i, cost, 1);\n }\n }\n\n int[] occurs = new int[128];\n for (int i = 0; i < n; ++i) occurs[s[i]]++;\n for (char c = 'a'; c <= 'z'; ++c) {\n graph.addFlowWeightedEdge(0, 1 + (c - 'a'), 0, occurs[c]);\n }\n\n for (int i = 0; i < n / 2; ++i) {\n graph.addFlowWeightedEdge(1 + 26 + i, 1 + 26 + n / 2, 0, 2);\n }\n\n Pair flow = MinCostFlow.minCostMaxFlow(graph, 0, 1 + 26 + n / 2, true, n);\n out.println(-flow.first);\n }\n\n }\n\n static class Pair implements Comparable> {\n public final U first;\n public final V second;\n\n public static Pair makePair(U first, V second) {\n return new Pair(first, second);\n }\n\n private Pair(U first, V second) {\n this.first = first;\n this.second = second;\n }\n\n\n public boolean equals(Object o) {\n if (this == o) {\n return true;\n }\n if (o == null || getClass() != o.getClass()) {\n return false;\n }\n\n Pair pair = (Pair) o;\n\n return !(first != null ? !first.equals(pair.first) : pair.first != null) &&\n !(second != null ? !second.equals(pair.second) : pair.second != null);\n }\n\n\n public int hashCode() {\n int result = first != null ? first.hashCode() : 0;\n result = 31 * result + (second != null ? second.hashCode() : 0);\n return result;\n }\n\n\n public String toString() {\n return \"(\" + first + \",\" + second + \")\";\n }\n\n @SuppressWarnings({\"unchecked\"})\n public int compareTo(Pair o) {\n int value = ((Comparable) first).compareTo(o.first);\n if (value != 0) {\n return value;\n }\n return ((Comparable) second).compareTo(o.second);\n }\n\n }\n\n static class IntegerUtils {\n public static int longCompare(long a, long b) {\n if (a < b) {\n return -1;\n }\n if (a > b) {\n return 1;\n }\n return 0;\n }\n\n }\n\n static interface IntStream extends Iterable, Comparable {\n public IntIterator intIterator();\n\n default public Iterator iterator() {\n return new Iterator() {\n private IntIterator it = intIterator();\n\n public boolean hasNext() {\n return it.isValid();\n }\n\n public Integer next() {\n int result = it.value();\n it.advance();\n return result;\n }\n };\n }\n\n default public int compareTo(IntStream c) {\n IntIterator it = intIterator();\n IntIterator jt = c.intIterator();\n while (it.isValid() && jt.isValid()) {\n int i = it.value();\n int j = jt.value();\n if (i < j) {\n return -1;\n } else if (i > j) {\n return 1;\n }\n it.advance();\n jt.advance();\n }\n if (it.isValid()) {\n return 1;\n }\n if (jt.isValid()) {\n return -1;\n }\n return 0;\n }\n\n }\n\n static class Heap implements IntQueue {\n private IntComparator comparator;\n private int size = 0;\n private int[] elements;\n private int[] at;\n\n public Heap(int maxElement) {\n this(10, maxElement);\n }\n\n public Heap(IntComparator comparator, int maxElement) {\n this(10, comparator, maxElement);\n }\n\n public Heap(int capacity, int maxElement) {\n this(capacity, IntComparator.DEFAULT, maxElement);\n }\n\n public Heap(int capacity, IntComparator comparator, int maxElement) {\n this.comparator = comparator;\n elements = new int[capacity];\n at = new int[maxElement];\n Arrays.fill(at, -1);\n }\n\n public boolean isEmpty() {\n return size == 0;\n }\n\n public void add(int element) {\n ensureCapacity(size + 1);\n elements[size] = element;\n at[element] = size;\n shiftUp(size++);\n }\n\n public void shiftUp(int index) {\n //\t\tif (index < 0 || index >= size)\n //\t\t\tthrow new IllegalArgumentException();\n int value = elements[index];\n while (index != 0) {\n int parent = (index - 1) >>> 1;\n int parentValue = elements[parent];\n if (comparator.compare(parentValue, value) <= 0) {\n elements[index] = value;\n at[value] = index;\n return;\n }\n elements[index] = parentValue;\n at[parentValue] = index;\n index = parent;\n }\n elements[0] = value;\n at[value] = 0;\n }\n\n public void shiftDown(int index) {\n if (index < 0 || index >= size) {\n throw new IllegalArgumentException();\n }\n while (true) {\n int child = (index << 1) + 1;\n if (child >= size) {\n return;\n }\n if (child + 1 < size && comparator.compare(elements[child], elements[child + 1]) > 0) {\n child++;\n }\n if (comparator.compare(elements[index], elements[child]) <= 0) {\n return;\n }\n swap(index, child);\n index = child;\n }\n }\n\n public int getIndex(int element) {\n return at[element];\n }\n\n private void swap(int first, int second) {\n int temp = elements[first];\n elements[first] = elements[second];\n elements[second] = temp;\n at[elements[first]] = first;\n at[elements[second]] = second;\n }\n\n private void ensureCapacity(int size) {\n if (elements.length < size) {\n int[] oldElements = elements;\n elements = new int[Math.max(2 * elements.length, size)];\n System.arraycopy(oldElements, 0, elements, 0, this.size);\n }\n }\n\n public int poll() {\n if (isEmpty()) {\n throw new IndexOutOfBoundsException();\n }\n int result = elements[0];\n at[result] = -1;\n if (size == 1) {\n size = 0;\n return result;\n }\n elements[0] = elements[--size];\n at[elements[0]] = 0;\n shiftDown(0);\n return result;\n }\n\n\n public IntIterator intIterator() {\n return new IntIterator() {\n private int at;\n\n\n public int value() throws NoSuchElementException {\n return elements[at];\n }\n\n\n public boolean advance() throws NoSuchElementException {\n return ++at < size;\n }\n\n\n public boolean isValid() {\n return at < size;\n }\n\n\n public void remove() throws NoSuchElementException {\n throw new UnsupportedOperationException();\n }\n };\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public String readString() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n if (Character.isValidCodePoint(c)) {\n res.appendCodePoint(c);\n }\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n\n static interface IntComparator {\n public static final IntComparator DEFAULT = (first, second) -> {\n if (first < second) {\n return -1;\n }\n if (first > second) {\n return 1;\n }\n return 0;\n };\n\n public int compare(int first, int second);\n\n }\n\n static interface IntIterator {\n public int value() throws NoSuchElementException;\n\n public boolean advance();\n\n public boolean isValid();\n\n }\n\n static interface IntQueue extends IntCollection {\n }\n\n static interface Edge {\n }\n\n static class Graph {\n public static final int REMOVED_BIT = 0;\n protected int vertexCount;\n protected int edgeCount;\n private int[] firstOutbound;\n private int[] firstInbound;\n private Edge[] edges;\n private int[] nextInbound;\n private int[] nextOutbound;\n private int[] from;\n private int[] to;\n private long[] weight;\n public long[] capacity;\n private int[] reverseEdge;\n private int[] flags;\n\n public Graph(int vertexCount) {\n this(vertexCount, vertexCount);\n }\n\n public Graph(int vertexCount, int edgeCapacity) {\n this.vertexCount = vertexCount;\n firstOutbound = new int[vertexCount];\n Arrays.fill(firstOutbound, -1);\n\n from = new int[edgeCapacity];\n to = new int[edgeCapacity];\n nextOutbound = new int[edgeCapacity];\n flags = new int[edgeCapacity];\n }\n\n public int addEdge(int fromID, int toID, long weight, long capacity, int reverseEdge) {\n ensureEdgeCapacity(edgeCount + 1);\n if (firstOutbound[fromID] != -1) {\n nextOutbound[edgeCount] = firstOutbound[fromID];\n } else {\n nextOutbound[edgeCount] = -1;\n }\n firstOutbound[fromID] = edgeCount;\n if (firstInbound != null) {\n if (firstInbound[toID] != -1) {\n nextInbound[edgeCount] = firstInbound[toID];\n } else {\n nextInbound[edgeCount] = -1;\n }\n firstInbound[toID] = edgeCount;\n }\n this.from[edgeCount] = fromID;\n this.to[edgeCount] = toID;\n if (capacity != 0) {\n if (this.capacity == null) {\n this.capacity = new long[from.length];\n }\n this.capacity[edgeCount] = capacity;\n }\n if (weight != 0) {\n if (this.weight == null) {\n this.weight = new long[from.length];\n }\n this.weight[edgeCount] = weight;\n }\n if (reverseEdge != -1) {\n if (this.reverseEdge == null) {\n this.reverseEdge = new int[from.length];\n Arrays.fill(this.reverseEdge, 0, edgeCount, -1);\n }\n this.reverseEdge[edgeCount] = reverseEdge;\n }\n if (edges != null) {\n edges[edgeCount] = createEdge(edgeCount);\n }\n return edgeCount++;\n }\n\n protected final GraphEdge createEdge(int id) {\n return new GraphEdge(id);\n }\n\n public final int addFlowWeightedEdge(int from, int to, long weight, long capacity) {\n if (capacity == 0) {\n return addEdge(from, to, weight, 0, -1);\n } else {\n int lastEdgeCount = edgeCount;\n addEdge(to, from, -weight, 0, lastEdgeCount + entriesPerEdge());\n return addEdge(from, to, weight, capacity, lastEdgeCount);\n }\n }\n\n protected int entriesPerEdge() {\n return 1;\n }\n\n public final int vertexCount() {\n return vertexCount;\n }\n\n public final int firstOutbound(int vertex) {\n int id = firstOutbound[vertex];\n while (id != -1 && isRemoved(id)) {\n id = nextOutbound[id];\n }\n return id;\n }\n\n public final int nextOutbound(int id) {\n id = nextOutbound[id];\n while (id != -1 && isRemoved(id)) {\n id = nextOutbound[id];\n }\n return id;\n }\n\n public final int source(int id) {\n return from[id];\n }\n\n public final int destination(int id) {\n return to[id];\n }\n\n public final long weight(int id) {\n if (weight == null) {\n return 0;\n }\n return weight[id];\n }\n\n public final long capacity(int id) {\n if (capacity == null) {\n return 0;\n }\n return capacity[id];\n }\n\n public final long flow(int id) {\n if (reverseEdge == null) {\n return 0;\n }\n return capacity[reverseEdge[id]];\n }\n\n public final void pushFlow(int id, long flow) {\n if (flow == 0) {\n return;\n }\n if (flow > 0) {\n if (capacity(id) < flow) {\n throw new IllegalArgumentException(\"Not enough capacity\");\n }\n } else {\n if (flow(id) < -flow) {\n throw new IllegalArgumentException(\"Not enough capacity\");\n }\n }\n capacity[id] -= flow;\n capacity[reverseEdge[id]] += flow;\n }\n\n public final boolean flag(int id, int bit) {\n return (flags[id] >> bit & 1) != 0;\n }\n\n public final boolean isRemoved(int id) {\n return flag(id, REMOVED_BIT);\n }\n\n protected void ensureEdgeCapacity(int size) {\n if (from.length < size) {\n int newSize = Math.max(size, 2 * from.length);\n if (edges != null) {\n edges = resize(edges, newSize);\n }\n from = resize(from, newSize);\n to = resize(to, newSize);\n nextOutbound = resize(nextOutbound, newSize);\n if (nextInbound != null) {\n nextInbound = resize(nextInbound, newSize);\n }\n if (weight != null) {\n weight = resize(weight, newSize);\n }\n if (capacity != null) {\n capacity = resize(capacity, newSize);\n }\n if (reverseEdge != null) {\n reverseEdge = resize(reverseEdge, newSize);\n }\n flags = resize(flags, newSize);\n }\n }\n\n protected final int[] resize(int[] array, int size) {\n int[] newArray = new int[size];\n System.arraycopy(array, 0, newArray, 0, array.length);\n return newArray;\n }\n\n private long[] resize(long[] array, int size) {\n long[] newArray = new long[size];\n System.arraycopy(array, 0, newArray, 0, array.length);\n return newArray;\n }\n\n private Edge[] resize(Edge[] array, int size) {\n Edge[] newArray = new Edge[size];\n System.arraycopy(array, 0, newArray, 0, array.length);\n return newArray;\n }\n\n public final boolean isSparse() {\n return vertexCount == 0 || edgeCount * 20 / vertexCount <= vertexCount;\n }\n\n protected class GraphEdge implements Edge {\n protected int id;\n\n protected GraphEdge(int id) {\n this.id = id;\n }\n\n }\n\n }\n\n static class MinCostFlow {\n private final Graph graph;\n private final int source;\n private final int destination;\n private final long[] phi;\n private final long[] dijkstraResult;\n private final int[] lastEdge;\n private final Heap heap;\n private final int vertexCount;\n private final int[] visited;\n private int visitIndex;\n\n public MinCostFlow(Graph graph, int source, int destination, boolean hasNegativeEdges) {\n this.graph = graph;\n this.source = source;\n this.destination = destination;\n vertexCount = graph.vertexCount();\n phi = new long[vertexCount];\n if (hasNegativeEdges) {\n fordBellman();\n }\n dijkstraResult = new long[vertexCount];\n lastEdge = new int[vertexCount];\n if (graph.isSparse()) {\n heap = new Heap(vertexCount, new IntComparator() {\n public int compare(int first, int second) {\n return IntegerUtils.longCompare(dijkstraResult[first], dijkstraResult[second]);\n }\n }, vertexCount);\n visited = null;\n } else {\n heap = null;\n visited = new int[vertexCount];\n }\n }\n\n private void fordBellman() {\n Arrays.fill(phi, Long.MAX_VALUE);\n phi[source] = 0;\n boolean[] inQueue = new boolean[vertexCount];\n int[] queue = new int[vertexCount + 1];\n queue[0] = source;\n inQueue[source] = true;\n int stepCount = 0;\n int head = 0;\n int end = 1;\n int maxSteps = 2 * vertexCount * vertexCount;\n while (head != end) {\n int vertex = queue[head++];\n if (head == queue.length) {\n head = 0;\n }\n inQueue[vertex] = false;\n int edgeID = graph.firstOutbound(vertex);\n while (edgeID != -1) {\n long total = phi[vertex] + graph.weight(edgeID);\n int destination = graph.destination(edgeID);\n if (graph.capacity(edgeID) != 0 && phi[destination] > total) {\n phi[destination] = total;\n if (!inQueue[destination]) {\n queue[end++] = destination;\n inQueue[destination] = true;\n if (end == queue.length) {\n end = 0;\n }\n }\n }\n edgeID = graph.nextOutbound(edgeID);\n }\n if (++stepCount > maxSteps) {\n throw new IllegalArgumentException(\"Graph contains negative cycle\");\n }\n }\n }\n\n public static Pair minCostMaxFlow(Graph graph, int source, int destination, boolean hasNegativeEdges,\n long maxFlow) {\n return new MinCostFlow(graph, source, destination, hasNegativeEdges).minCostMaxFlow(maxFlow);\n }\n\n public Pair minCostMaxFlow(long maxFlow) {\n long cost = 0;\n long flow = 0;\n while (maxFlow != 0) {\n if (graph.isSparse()) {\n dijkstraAlgorithm();\n } else {\n dijkstraAlgorithmFull();\n }\n if (lastEdge[destination] == -1) {\n return Pair.makePair(cost, flow);\n }\n for (int i = 0; i < dijkstraResult.length; i++) {\n if (dijkstraResult[i] != Long.MAX_VALUE) {\n phi[i] += dijkstraResult[i];\n }\n }\n int vertex = destination;\n long currentFlow = maxFlow;\n long currentCost = 0;\n while (vertex != source) {\n int edgeID = lastEdge[vertex];\n currentFlow = Math.min(currentFlow, graph.capacity(edgeID));\n currentCost += graph.weight(edgeID);\n vertex = graph.source(edgeID);\n }\n maxFlow -= currentFlow;\n cost += currentCost * currentFlow;\n flow += currentFlow;\n vertex = destination;\n while (vertex != source) {\n int edgeID = lastEdge[vertex];\n graph.pushFlow(edgeID, currentFlow);\n vertex = graph.source(edgeID);\n }\n }\n return Pair.makePair(cost, flow);\n }\n\n private void dijkstraAlgorithm() {\n Arrays.fill(dijkstraResult, Long.MAX_VALUE);\n Arrays.fill(lastEdge, -1);\n dijkstraResult[source] = 0;\n heap.add(source);\n while (!heap.isEmpty()) {\n int current = heap.poll();\n int edgeID = graph.firstOutbound(current);\n while (edgeID != -1) {\n if (graph.capacity(edgeID) != 0) {\n int next = graph.destination(edgeID);\n long total = graph.weight(edgeID) - phi[next] + phi[current] + dijkstraResult[current];\n if (dijkstraResult[next] > total) {\n dijkstraResult[next] = total;\n if (heap.getIndex(next) == -1) {\n heap.add(next);\n } else {\n heap.shiftUp(heap.getIndex(next));\n }\n lastEdge[next] = edgeID;\n }\n }\n edgeID = graph.nextOutbound(edgeID);\n }\n }\n }\n\n private void dijkstraAlgorithmFull() {\n visitIndex++;\n Arrays.fill(dijkstraResult, Long.MAX_VALUE);\n lastEdge[destination] = -1;\n dijkstraResult[source] = 0;\n for (int i = 0; i < vertexCount; i++) {\n int index = -1;\n long length = Long.MAX_VALUE;\n for (int j = 0; j < vertexCount; j++) {\n if (visited[j] != visitIndex && dijkstraResult[j] < length) {\n length = dijkstraResult[j];\n index = j;\n }\n }\n if (index == -1) {\n return;\n }\n visited[index] = visitIndex;\n int edgeID = graph.firstOutbound(index);\n while (edgeID != -1) {\n if (graph.capacity(edgeID) != 0) {\n int next = graph.destination(edgeID);\n if (visited[next] != visitIndex) {\n long total = graph.weight(edgeID) - phi[next] + phi[index] + length;\n if (dijkstraResult[next] > total) {\n dijkstraResult[next] = total;\n lastEdge[next] = edgeID;\n }\n }\n }\n edgeID = graph.nextOutbound(edgeID);\n }\n }\n }\n\n }\n\n static interface IntCollection extends IntStream {\n }\n}\n\n", "lang_cluster": "Java", "tags": ["greedy", "flows", "graphs"], "code_uid": "658d1ede4610dea5032bb1bed271b6ed", "src_uid": "896555ddb6e1c268cd7b3b6b063fce50", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n Scanner in = new Scanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskD solver = new TaskD();\n solver.solve(1, in, out);\n out.close();\n }\n}\n\nclass TaskD {\n long MOD = (long)1e9 + 7;\n long p[];\n\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n int n = in.nextInt();\n int m = in.nextInt();\n int g = in.nextInt();\n p = new long[m + n + 1];\n p[0] = 1;\n for(int i = 1; i < p.length; ++i) p[i] = p[i - 1] * i % MOD;\n\n long res = 0;\n if(g == 1)\n res = rec(n, m);\n else if(g == 0) {\n if(n == 0 && m == 0)\n res = 0;\n else if(n == 1 && m == 0)\n res = 1;\n else if(n == 0 && m == 1)\n res = 0;\n else {\n if(n >= 1)\n res = (res + rec(n - 1, m)) % MOD;\n if(m >= 1)\n res = (res + p[n + m - 1] * modPow(p[n] * p[m - 1] % MOD, MOD - 2) % MOD) % MOD;\n }\n }\n out.println(res);\n }\n\n private long rec(int n, int m) {\n long res = 0;\n for(int i = n; i >= 0; ) {\n if(i == 1) {\n if(m <= 1) return res;\n else if(m > 1) {res = (res + 1) % MOD; return res;}\n }\n else if(i == 0) {\n if(m == 0 || m > 1) return res;\n else if(m == 1) {res = (res + 1) % MOD; return res;}\n }\n else if(i == 2 && m == 0) {res = (res + 1) % MOD; return res;}\n else if(i == 0 && m == 2) return res;\n\n else {\n if(i > 1 && m >= 1)\n res = (res + p[m - 1 + i - 1] * modPow(p[m - 1] * p[i - 1] % MOD, MOD - 2) % MOD) % MOD;\n i -= 2;\n }\n }\n return res;\n }\n\n private long modPow(long a, long p) {\n if(p == 0) return 1;\n long res = modPow(a, p / 2);\n res = res * res % MOD;\n if(p % 2 == 1)\n res = res * a % MOD;\n return res;\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "combinatorics", "number theory"], "code_uid": "93c663df9c518405bbfc27e5a40e98d2", "src_uid": "066dd9e6091238edf2912a6af4d29e7f", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\n\n\npublic class B138 {\n\n public static void main(String[] args) throws IOException{\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n int[]d1 = new int[10], d2 = new int[10];\n while (true) {\n int w = (int)br.read();\n if (w==13)\n break;\n d1[w-48]++;\n d2[w-48]++;\n }\n int[][]ten = {{2,8}, {3,7}, {4,6}, {5,5}, {1,9}};\n int[][]nine = {{1,8}, {2,7}, {3,6}, {4,5}, {5,4}, {6,3}, {7,2}, {8,1}, {0,9}, {9,0}};\n int[]zero = new int[5];\n int max = 0, k = -1;\n for (int t = 0; t < 5; t++) {\n if (d1[ten[t][0]] > 0 && d2[ten[t][1]] > 0) {\n zero[t] = 1;\n d1[ten[t][0]]--;\n d2[ten[t][1]]--;\n int[]min = new int[10];\n for (int i = 0; i < 10; i++) {\n min[i] = Math.min(d1[nine[i][0]], d2[nine[i][1]]);\n zero[t] += min[i];\n d1[nine[i][0]] -= min[i];\n d2[nine[i][1]] -= min[i];\n }\n zero[t] += Math.min(d1[0], d2[0]);\n if (zero[t] > max){\n max = zero[t];\n k = t;\n }\n for (int i = 0; i < 10; i++) {\n d1[nine[i][0]] += min[i];\n d2[nine[i][1]] += min[i];\n }\n d1[ten[t][0]]++;\n d2[ten[t][1]]++;\n }\n }\n if (k==-1) {\n for (int i = 1; i <= 9; i++) {\n for (int j = 1; j <= d1[i]; j++) {\n pw.print(i);\n }\n }\n for (int i = 1; i <= d1[0] ; i++) {\n pw.print(0);\n }\n pw.println();\n for (int i = 1; i <= 9; i++) {\n for (int j = 1; j <= d1[i]; j++) {\n pw.print(i);\n }\n }\n for (int i = 1; i <= d1[0] ; i++) {\n pw.print(0);\n }\n }\n else {\n int[]min = new int[10];\n d1[ten[k][0]]--;\n d2[ten[k][1]]--;\n for (int i = 0; i < 10; i++) {\n min[i] = Math.min(d1[nine[i][0]], d2[nine[i][1]]);\n d1[nine[i][0]] -= min[i];\n d2[nine[i][1]] -= min[i];\n }\n for (int i = 1; i <= 9; i++) {\n for (int j = 1; j <= d1[i]; j++) {\n pw.print(i);\n }\n }\n int m = Math.min(d1[0], d2[0]);\n for (int i = 1; i <= d1[0]-d2[0]; i++) {\n pw.print(0);\n }\n for (int i = 0; i < 10; i++) {\n for (int j = 1; j <= min[i]; j++) {\n pw.print(nine[i][0]);\n }\n }\n pw.print(ten[k][0]);\n for (int i = 1; i <= m; i++) {\n pw.print(0);\n }\n pw.println();\n for (int i = 1; i <= 9; i++) {\n for (int j = 1; j <= d2[i]; j++) {\n pw.print(i);\n }\n }\n for (int i = 1; i <= d2[0]-d1[0]; i++) {\n pw.print(0);\n }\n for (int i = 0; i < 10; i++) {\n for (int j = 1; j <= min[i]; j++) {\n pw.print(nine[i][1]);\n }\n }\n pw.print(ten[k][1]);\n for (int i = 1; i <= m; i++) {\n pw.print(0);\n }\n }\n pw.close();\n }\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "a0263e74b00badef26dc5bfc24f10f3b", "src_uid": "34b67958a37865e1ca0529bbf528dd9a", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Codeforces913F {\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner input = new Scanner(System.in);\n\t\tint n = input.nextInt();\n\t\tint a = input.nextInt();\n\t\tint b = input.nextInt();\n\t\tinput.close();\n\t\tfinal int mod = 998244353;\n\t\t\n\t\tint frac = multiply(a, inverse(b, mod), mod);\n\t\tint reverse = (mod+1-frac)%mod;\n\t\t\n\t\tint[] fracpower = new int[n+1];\n\t\tint[] reversepower = new int[n+1];\n\t\tfracpower[0] = 1;\n\t\treversepower[0] = 1;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tfracpower[i] = multiply(fracpower[i-1], frac, mod);\n\t\t\treversepower[i] = multiply(reversepower[i-1], reverse, mod);\n\t\t}\n\t\t\n\t\tint[][] dp1 = new int[n+1][n+1];\n\t\tdp1[2][1] = 1;\n\t\tfor (int i = 3; i <= n; i++) {\n\t\t\tfor (int j = 1; j < i; j++) {\n\t\t\t\tif (j == 1) {\n\t\t\t\t\tdp1[i][j] = fracpower[i-1];\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tdp1[i][j] = multiply(dp1[i-1][j-1], fracpower[i-j], mod);\n\t\t\t\t}\n\t\t\t\tif (j == i-1) {\n\t\t\t\t\tdp1[i][j] += reversepower[i-1];\n\t\t\t\t\tdp1[i][j] %= mod;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tdp1[i][j] += multiply(dp1[i-1][j], reversepower[j], mod);\n\t\t\t\t\tdp1[i][j] %= mod;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tint[][] dp2 = new int[n+1][n+1];\n\t\tdp2[1][1] = 1;\n\t\tdp2[2][1] = 1;\n\t\tdp2[2][2] = 0;\n\t\tfor (int i = 3; i <= n; i++) {\n\t\t\tint val = 0;\n\t\t\tfor (int j = 1; j < i; j++) {\n\t\t\t\tdp2[i][j] = multiply(dp2[j][j], dp1[i][j], mod);\n\t\t\t\tval += dp2[i][j];\n\t\t\t\tval %= mod;\n\t\t\t}\n\t\t\tdp2[i][i] = (mod+1-val)%mod;\n\t\t}\n\t\t\n\t\t/*for (int i = 2; i <= n; i++) {\n\t\t\tfor (int j = 1; j <= i; j++) {\n\t\t\t\tSystem.out.print(dp2[i][j] + \" \");\n\t\t\t}\n\t\t\tSystem.out.println();\n\t\t}*/\n\t\t\n\t\tint[] EV = new int[n+1];\n\t\tEV[1] = 0;\n\t\tEV[2] = 1;\n\t\tfor (int i = 3; i <= n; i++) {\n\t\t\tint val = 0;\n\t\t\tfor (int j = 1; j < i; j++) {\n\t\t\t\tint r = j*(i-j) + (j*(j-1))/2 + EV[i-j] + EV[j];\n\t\t\t\tr %= mod;\n\t\t\t\tval += multiply(dp2[i][j], r, mod);\n\t\t\t\tval %= mod;\n\t\t\t}\n\t\t\tval += multiply((i*(i-1))/2, dp2[i][i], mod);\n\t\t\tval %= mod;\n\t\t\t\n\t\t\tint s = (mod+1-dp2[i][i])%mod;\n\t\t\tEV[i] = multiply(val, inverse(s, mod), mod);\n\t\t}\n\t\t\n\t\tSystem.out.println(EV[n]);\n\t}\n\t\n\tpublic static int multiply(int a, int b, int mod) {\n\t\tlong x = (long)a*(long)b;\n\t\treturn (int) (x%mod);\n\t}\n\t\n\tpublic static int inverse (int a, int n) {\n\t\tint m = n;\n\t\tint r1 = 1;\n\t\tint r2 = 0;\n\t\tint r3 = 0;\n\t\tint r4 = 1;\n\t\twhile ((a > 0) && (n > 0)) {\n\t\t\tif (n >= a) {\n\t\t\t\tr3 -= r1*(n/a);\n\t\t\t\tr4 -= r2*(n/a);\n\t\t\t\tn = n%a;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tint tmp = a;\n\t\t\t\ta = n;\n\t\t\t\tn = tmp;\n\t\t\t\ttmp = r1;\n\t\t\t\tr1 = r3;\n\t\t\t\tr3 = tmp;\n\t\t\t\ttmp = r2;\n\t\t\t\tr2 = r4;\n\t\t\t\tr4 = tmp;\n\t\t\t}\n\t\t}\n\t\tif (a == 0) {\n\t\t\tif (r3 >= 0)\n\t\t\t\treturn (r3%m);\n\t\t\telse\n\t\t\t\treturn (m+(r3%m));\n\t\t}\n\t\telse {\n\t\t\tif (r1 >= 0)\n\t\t\t\treturn (r1%m);\n\t\t\telse\n\t\t\t\treturn (m+(r1%m));\n\t\t}\n\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "dp", "probabilities", "graphs"], "code_uid": "d19b3637df2ca66378f6c31649f47a94", "src_uid": "67e599530203060c17f692f2624d0f99", "difficulty": 2800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class cf286c {\n public static void main(String[] args) {\n FastIO in = new FastIO(), out = in;\n int n = in.nextInt();\n if(n%2 == 1) {\n out.println(\"NO\");\n out.close();\n return;\n }\n int[] v = new int[n];\n for(int i=0; i> stk1 = new Stack<>();\n Stack> stk2 = new Stack<>();\n boolean fail = false;\n for(int i=0; i 0) stk1.add(new Pair(v[i],i));\n else stk2.add(new Pair(v[i],i));\n while(stk2.size() != 0 || (i==n-1 && stk1.size() != 0)) {\n if(stk1.size() == 0) {\n fail = true;\n break;\n }\n if(stk2.size() > 0 && stk1.peek().first == -stk2.peek().first) {\n stk1.pop();\n stk2.pop();\n }\n else {\n Pair p = stk1.pop();\n p.first *= -1;\n v[p.second] = p.first;\n stk2.push(p);\n }\n }\n }\n if(fail) out.println(\"NO\");\n else {\n out.println(\"YES\");\n for(int x : v) out.print(x+ \" \");\n }\n out.close();\n }\n static class Pair {\n T1 first;\n T2 second;\n Pair(T1 a, T2 b) {\n first = a; second = b;\n }\n public String toString() {\n return first + \":\" + second;\n }\n }\n \n static class FastIO extends PrintWriter {\n BufferedReader br;\n StringTokenizer st;\n\n public FastIO() {\n this(System.in, System.out);\n }\n\n public FastIO(InputStream in, OutputStream out) {\n super(new BufferedWriter(new OutputStreamWriter(out)));\n br = new BufferedReader(new InputStreamReader(in));\n scanLine();\n }\n\n public void scanLine() {\n try {\n st = new StringTokenizer(br.readLine().trim());\n } catch (Exception e) {\n throw new RuntimeException(e.getMessage());\n }\n }\n\n public int numTokens() {\n if (!st.hasMoreTokens()) {\n scanLine();\n return numTokens();\n }\n return st.countTokens();\n }\n\n public String next() {\n if (!st.hasMoreTokens()) {\n scanLine();\n return next();\n }\n return st.nextToken();\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["greedy", "data structures"], "code_uid": "929579ed6fa78451252d44b1e99c306f", "src_uid": "be82b8f209217875221ebe5de8675971", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n/**\n * @author Pavel Mavrin\n */\npublic class E {\n\n private static final int MOD = (int) (1e9+7);\n public static final int N = 7;\n public static final int NN = 128;\n\n private void solve() throws IOException {\n int[] w = new int[N];\n for (int i = 0; i < N; i++) {\n w[i] = nextInt();\n }\n int[] start = new int[2];\n start[1] = 1;\n int[] a = start;\n for (int h = 0; h < N; h++) if (w[h] > 0) {\n int nn = (1 << (h + 1));\n {\n int[] aa = new int[nn];\n for (int i = 0; i < a.length; i++) {\n aa[i - a.length + nn] = a[i];\n }\n a = aa;\n }\n int[][] q = new int[nn][];\n int[] t = new int[nn];\n for (int i = 0; i < nn; i++) {\n t[i] = 1;\n q[i] = add(t, h + 1);\n t[i] = 0;\n }\n q = pow(q, w[h]);\n int[] aa = new int[nn];\n for (int i = 0; i < nn; i++) {\n for (int j = 0; j < nn; j++) {\n aa[j] = (int) ((aa[j] + 1l * a[i] * q[i][j]) % MOD);\n }\n }\n a = aa;\n }\n out.println(a[a.length - 1]);\n }\n\n private int[][] pow(int[][] a, int b) {\n int n = a.length;\n if (b == 0) {\n int[][] res = new int[n][n];\n for (int i = 0; i < n; i++) {\n res[i][i] = 1;\n }\n return res;\n }\n if (b % 2 == 0) {\n int[][] aa = mult(a, a);\n return pow(aa, b / 2);\n } else {\n int[][] aa = pow(a, b - 1);\n return mult(aa, a);\n }\n }\n\n private int[][] mult(int[][] a, int[][] b) {\n int n = a.length;\n int[][] c = new int[n][n];\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n for (int k = 0; k < n; k++) {\n c[i][k] = (int) ((c[i][k] + 1l * a[i][j] * b[j][k]) % MOD);\n }\n }\n }\n return c;\n }\n\n private int[] add(int[] a, int n) {\n int nn = (1 << (n + 1));\n int[][] d = new int[n + 1][nn];\n for (int i = 0; i < nn / 2; i++) {\n d[0][(i << 1) + 1] = a[i + a.length - (1 << n)];\n }\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < nn; j++) if (d[i][j] > 0) {\n int q = (j >> i) & 3;\n for (int k = 0; k < 4; k++) {\n if (q == 3 && k == 3) continue;\n int jj = (j - (q << i) + (k << i));\n d[i + 1][jj] += d[i][j];\n while (d[i + 1][jj] >= MOD) {\n d[i + 1][jj] -= MOD;\n }\n }\n }\n }\n int[] res = new int[a.length];\n for (int i = 0; i < (1 << n); i++) {\n res[i + a.length - (1 << n)] = d[n][i + (1 << n)];\n }\n return res;\n }\n\n\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer st;\n PrintWriter out = new PrintWriter(System.out);\n\n String next() throws IOException {\n while (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(br.readLine());\n }\n return st.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public static void main(String[] args) throws IOException {\n new E().run();\n }\n\n private void run() throws IOException {\n solve();\n out.close();\n }\n\n}\n", "lang_cluster": "Java", "tags": ["matrices", "dp"], "code_uid": "ff72239f7ee4928d55d2aeb60c48ea7f", "src_uid": "a4bda63b95dc14185c47a08652fe41bd", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "/*\n Author: Anthony Ngene\n Created: 04/10/2020 - 12:56\n*/\n\nimport java.io.*;\nimport java.util.*;\n\npublic class F {\n// checks: 1. edge cases 2. overflow 3. possible errors (e.g 1/0, arr[out]) 4. time/space complexity\n int n;\n int m;\n int[] arr;\n int required;\n HashMap> typeDays;\n void solver() throws IOException {\n n = in.intNext(); m = in.intNext();\n arr = in.nextIntArray(n);\n required = sum(arr);\n typeDays = new HashMap<>();\n for (int i = 0; i < m; i++) {\n int d = in.intNext(), typ = in.intNext();\n if (arr[typ - 1] <= 0) continue;\n if (!typeDays.containsKey(typ)) typeDays.put(typ, new TreeSet<>());\n typeDays.get(typ).add(d);\n }\n\n int lo = required;\n int hi = 2 * required;\n int valid = hi;\n while (lo <= hi) {\n int mid = (lo + hi) / 2;\n if (isEnough(mid)) {\n valid = mid;\n hi = mid - 1;\n } else\n lo = mid + 1;\n }\n out.println(valid);\n }\n\n boolean isEnough(int day) {\n int totalCoin = day;\n int req = required;\n\n int[] ddays = new int[day + 1];\n for (int typ : typeDays.keySet()) {\n Integer lastDay = typeDays.get(typ).floor(day);\n if (lastDay == null) continue;\n ddays[lastDay] += arr[typ - 1];\n }\n// out.println(ddays);\n int removed = 0;\n for (int i = 1; i < day + 1; i++) {\n int coins = i - removed;\n int toRemove = min(coins, ddays[i]);\n removed += toRemove;\n totalCoin -= toRemove;\n req -= toRemove;\n }\n// out.pp(req, totalCoin);\n return req * 2 <= totalCoin;\n }\n\n\n// Generated Code Below:\nprivate static final FastWriter out = new FastWriter();\nprivate static FastScanner in;\nstatic ArrayList[] adj;\nprivate static long e97 = (long)1e9 + 7;\npublic static void main(String[] args) throws IOException {\n in = new FastScanner();\n new F().solver();\n out.close();\n}\n\nstatic class FastWriter {\n private static final int IO_BUFFERS = 128 * 1024;\n private final StringBuilder out;\n public FastWriter() { out = new StringBuilder(IO_BUFFERS); }\n public FastWriter p(Object object) { out.append(object); return this; }\n public FastWriter p(String format, Object... args) { out.append(String.format(format, args)); return this; }\n public FastWriter pp(Object... args) { for (Object ob : args) { out.append(ob).append(\" \"); } out.append(\"\\n\"); return this; }\n public FastWriter pp(int[] args) { for (int ob : args) { out.append(ob).append(\" \"); } out.append(\"\\n\"); return this; }\n public FastWriter pp(long[] args) { for (long ob : args) { out.append(ob).append(\" \"); } out.append(\"\\n\"); return this; }\n public FastWriter pp(char[] args) { for (char ob : args) { out.append(ob).append(\" \"); } out.append(\"\\n\"); return this; }\n public void println(long[] arr) { for(long e: arr) out.append(e).append(\" \"); out.append(\"\\n\"); }\n public void println(int[] arr) { for(int e: arr) out.append(e).append(\" \"); out.append(\"\\n\"); }\n public void println(char[] arr) { for(char e: arr) out.append(e).append(\" \"); out.append(\"\\n\"); }\n public void println(double[] arr) { for(double e: arr) out.append(e).append(\" \"); out.append(\"\\n\"); }\n public void println(boolean[] arr) { for(boolean e: arr) out.append(e).append(\" \"); out.append(\"\\n\"); }\n public void println(T[] arr) { for(T e: arr) out.append(e).append(\" \"); out.append(\"\\n\"); }\n public void println(long[][] arr) { for (long[] row: arr) out.append(Arrays.toString(row)).append(\"\\n\"); }\n public void println(int[][] arr) { for (int[] row: arr) out.append(Arrays.toString(row)).append(\"\\n\"); }\n public void println(char[][] arr) { for (char[] row: arr) out.append(Arrays.toString(row)).append(\"\\n\"); }\n public void println(double[][] arr) { for (double[] row: arr) out.append(Arrays.toString(row)).append(\"\\n\"); }\n public void println(T[][] arr) { for (T[] row: arr) out.append(Arrays.toString(row)).append(\"\\n\"); }\n public FastWriter println(Object object) { out.append(object).append(\"\\n\"); return this; }\n public void toFile(String fileName) throws IOException {\n BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));\n writer.write(out.toString());\n writer.close();\n }\n public void close() throws IOException { System.out.print(out); }\n}\nstatic class FastScanner {\n private InputStream sin = System.in;\n private final byte[] buffer = new byte[1024];\n private int ptr = 0;\n private int buflen = 0;\n public FastScanner(){}\n public FastScanner(String filename) throws FileNotFoundException {\n File file = new File(filename);\n sin = new FileInputStream(file);\n }\n private boolean hasNextByte() {\n if (ptr < buflen) {\n return true;\n }else{\n ptr = 0;\n try {\n buflen = sin.read(buffer);\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (buflen <= 0) {\n return false;\n }\n }\n return true;\n }\n private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}\n private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}\n public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}\n public String next() {\n if (!hasNext()) throw new NoSuchElementException();\n StringBuilder sb = new StringBuilder();\n int b = readByte();\n while(isPrintableChar(b)) {\n sb.appendCodePoint(b);\n b = readByte();\n }\n return sb.toString();\n }\n public long longNext() {\n if (!hasNext()) throw new NoSuchElementException();\n long n = 0;\n boolean minus = false;\n int b = readByte();\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n if (b < '0' || '9' < b) {\n throw new NumberFormatException();\n }\n while(true){\n if ('0' <= b && b <= '9') {\n n *= 10;\n n += b - '0';\n }else if(b == -1 || !isPrintableChar(b) || b == ':'){\n return minus ? -n : n;\n }else{\n throw new NumberFormatException();\n }\n b = readByte();\n }\n }\n public int intNext() {\n long nl = longNext();\n if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();\n return (int) nl;\n }\n public double doubleNext() { return Double.parseDouble(next());}\n public long[] nextLongArray(final int n){\n final long[] a = new long[n];\n for (int i = 0; i < n; i++)\n a[i] = longNext();\n return a;\n }\n public int[] nextIntArray(final int n){\n final int[] a = new int[n];\n for (int i = 0; i < n; i++)\n a[i] = intNext();\n return a;\n }\n public double[] nextDoubleArray(final int n){\n final double[] a = new double[n];\n for (int i = 0; i < n; i++)\n a[i] = doubleNext();\n return a;\n }\n public ArrayList[] getAdj(int n) {\n ArrayList[] adj = new ArrayList[n + 1];\n for (int i = 1; i <= n; i++) adj[i] = new ArrayList<>();\n return adj;\n }\n public ArrayList[] adjacencyList(int nodes, int edges) throws IOException {\n return adjacencyList(nodes, edges, false);\n }\n public ArrayList[] adjacencyList(int nodes, int edges, boolean isDirected) throws IOException {\n adj = getAdj(nodes);\n for (int i = 0; i < edges; i++) {\n int a = intNext(), b = intNext();\n adj[a].add(b);\n if (!isDirected) adj[b].add(a);\n }\n return adj;\n }\n}\nstatic class u {\n public static int upperBound(long[] array, long obj) {\n int l = 0, r = array.length - 1;\n while (r - l >= 0) {\n int c = (l + r) / 2;\n if (obj < array[c]) {\n r = c - 1;\n } else {\n l = c + 1;\n }\n }\n return l;\n }\n public static int upperBound(ArrayList array, long obj) {\n int l = 0, r = array.size() - 1;\n while (r - l >= 0) {\n int c = (l + r) / 2;\n if (obj < array.get(c)) {\n r = c - 1;\n } else {\n l = c + 1;\n }\n }\n return l;\n }\n public static int lowerBound(long[] array, long obj) {\n int l = 0, r = array.length - 1;\n while (r - l >= 0) {\n int c = (l + r) / 2;\n if (obj <= array[c]) {\n r = c - 1;\n } else {\n l = c + 1;\n }\n }\n return l;\n }\n public static int lowerBound(ArrayList array, long obj) {\n int l = 0, r = array.size() - 1;\n while (r - l >= 0) {\n int c = (l + r) / 2;\n if (obj <= array.get(c)) {\n r = c - 1;\n } else {\n l = c + 1;\n }\n }\n return l;\n }\n static T[][] deepCopy(T[][] matrix) { return Arrays.stream(matrix).map(el -> el.clone()).toArray($ -> matrix.clone()); }\n static int[][] deepCopy(int[][] matrix) { return Arrays.stream(matrix).map(int[]::clone).toArray($ -> matrix.clone()); }\n static long[][] deepCopy(long[][] matrix) { return Arrays.stream(matrix).map(long[]::clone).toArray($ -> matrix.clone()); }\n private static void sort(int[][] arr){ Arrays.sort(arr, Comparator.comparingDouble(o -> o[0])); }\n private static void sort(long[][] arr){ Arrays.sort(arr, Comparator.comparingDouble(o -> o[0])); }\n private static void rSort(T[] arr) { Arrays.sort(arr, Collections.reverseOrder()); }\n private static void customSort(int[][] arr) {\n Arrays.sort(arr, new Comparator() {\n public int compare(int[] a, int[] b) {\n if (a[0] == b[0]) return Integer.compare(a[1], b[1]);\n return Integer.compare(a[0], b[0]);\n }\n });\n }\n public static int[] swap(int[] arr, int left, int right) {\n int temp = arr[left];\n arr[left] = arr[right];\n arr[right] = temp;\n return arr;\n }\n public static char[] swap(char[] arr, int left, int right) {\n char temp = arr[left];\n arr[left] = arr[right];\n arr[right] = temp;\n return arr;\n }\n public static int[] reverse(int[] arr, int left, int right) {\n while (left < right) {\n int temp = arr[left];\n arr[left++] = arr[right];\n arr[right--] = temp;\n }\n return arr;\n }\n public static boolean findNextPermutation(int[] data) {\n if (data.length <= 1) return false;\n int last = data.length - 2;\n while (last >= 0) {\n if (data[last] < data[last + 1]) break;\n last--;\n }\n if (last < 0) return false;\n int nextGreater = data.length - 1;\n for (int i = data.length - 1; i > last; i--) {\n if (data[i] > data[last]) {\n nextGreater = i;\n break;\n }\n }\n data = swap(data, nextGreater, last);\n data = reverse(data, last + 1, data.length - 1);\n return true;\n }\n public static int biSearch(int[] dt, int target){\n int left=0, right=dt.length-1;\n int mid=-1;\n while(left<=right){\n mid = (right+left)/2;\n if(dt[mid] == target) return mid;\n if(dt[mid] < target) left=mid+1;\n else right=mid-1;\n }\n return -1;\n }\n public static int biSearchMax(long[] dt, long target){\n int left=-1, right=dt.length;\n int mid=-1;\n\n while((right-left)>1){\n mid = left + (right-left)/2;\n if(dt[mid] <= target) left=mid;\n else right=mid;\n }\n return left;\n }\n public static int biSearchMaxAL(ArrayList dt, long target){\n int left=-1, right=dt.size();\n int mid=-1;\n\n while((right-left)>1){\n mid = left + (right-left)/2;\n if(dt.get(mid) <= target) left=mid;\n else right=mid;\n }\n return left;\n }\n private static void fill(T[][] ob, T res){for(int i=0;ivoid fill(T[][][] ob,T res){for(int i=0;i0; i--){ ans*=i; }\n return ans;\n }\n private static long facMod(int n, long mod) {\n long ans=1;\n for(long i=n; i>0; i--) ans = (ans * i) % mod;\n return ans;\n }\n private static long lcm(long m, long n){\n long ans = m/gcd(m,n);\n ans *= n;\n return ans;\n }\n private static long gcd(long m, long n) {\n if(m < n) return gcd(n, m);\n if(n == 0) return m;\n return gcd(n, m % n);\n }\n private static boolean isPrime(long a){\n if(a==1) return false;\n for(int i=2; i<=Math.sqrt(a); i++){ if(a%i == 0) return false; }\n return true;\n }\n static long modInverse(long a, long mod) {\n /* Fermat's little theorem: a^(MOD-1) => 1\n Therefore (divide both sides by a): a^(MOD-2) => a^(-1) */\n return binpowMod(a, mod - 2, mod);\n }\n static long binpowMod(long a, long b, long mod) {\n long res = 1;\n while (b > 0) {\n if (b % 2 == 1) res = (res * a) % mod;\n a = (a * a) % mod;\n b /= 2;\n }\n return res;\n }\n private static int getDigit2(long num){\n long cf = 1; int d=0;\n while(num >= cf){ d++; cf = 1<= cf){ d++; cf*=10; }\n return d;\n }\n private static boolean isInArea(int y, int x, int h, int w){\n if(y<0) return false;\n if(x<0) return false;\n if(y>=h) return false;\n if(x>=w) return false;\n return true;\n }\n private static ArrayList generatePrimes(int n) {\n int[] lp = new int[n + 1];\n ArrayList pr = new ArrayList<>();\n for (int i = 2; i <= n; ++i) {\n if (lp[i] == 0) {\n lp[i] = i;\n pr.add(i);\n }\n for (int j = 0; j < pr.size() && pr.get(j) <= lp[i] && i * pr.get(j) <= n; ++j) {\n lp[i * pr.get(j)] = pr.get(j);\n }\n }\n return pr;\n }\n static long nPrMod(int n, int r, long MOD) {\n long res = 1;\n for (int i = (n - r + 1); i <= n; i++) {\n res = (res * i) % MOD;\n }\n return res;\n }\n static long nCr(int n, int r) {\n if (r > (n - r))\n r = n - r;\n long ans = 1;\n for (int i = 1; i <= r; i++) {\n ans *= n;\n ans /= i;\n n--;\n }\n return ans;\n }\n static long nCrMod(int n, int r, long MOD) {\n long rFactorial = nPrMod(r, r, MOD);\n long first = nPrMod(n, r, MOD);\n long second = binpowMod(rFactorial, MOD-2, MOD);\n return (first * second) % MOD;\n }\n static void printBitRepr(int n) {\n StringBuilder res = new StringBuilder();\n for (int i = 0; i < 32; i++) {\n int mask = (1 << i);\n res.append((mask & n) == 0 ? \"0\" : \"1\");\n }\n out.println(res);\n }\n static String bitString(int n) {return Integer.toBinaryString(n);}\n static int setKthBitToOne(int n, int k) { return (n | (1 << k)); } // zero indexed\n static int setKthBitToZero(int n, int k) { return (n & ~(1 << k)); }\n static int invertKthBit(int n, int k) { return (n ^ (1 << k)); }\n static boolean isPowerOfTwo(int n) { return (n & (n - 1)) == 0; }\n static HashMap counts(String word) {\n HashMap counts = new HashMap<>();\n for (int i = 0; i < word.length(); i++) counts.merge(word.charAt(i), 1, Integer::sum);\n return counts;\n }\n static HashMap counts(int[] arr) {\n HashMap counts = new HashMap<>();\n for (int value : arr) counts.merge(value, 1, Integer::sum);\n return counts;\n }\n static HashMap counts(long[] arr) {\n HashMap counts = new HashMap<>();\n for (long l : arr) counts.merge(l, 1, Integer::sum);\n return counts;\n }\n static HashMap counts(char[] arr) {\n HashMap counts = new HashMap<>();\n for (char c : arr) counts.merge(c, 1, Integer::sum);\n return counts;\n }\n static long hash(int x, int y) {\n return x* 1_000_000_000L +y;\n }\n static final Random random = new Random();\n static void sort(int[] a) {\n int n = a.length;// shuffle, then sort\n for (int i = 0; i < n; i++) {\n int oi = random.nextInt(n), temp = a[oi];\n a[oi] = a[i];\n a[i] = temp;\n }\n Arrays.sort(a);\n }\n static void sort(long[] arr) {\n shuffleArray(arr);\n Arrays.sort(arr);\n }\n static void shuffleArray(long[] arr) {\n int n = arr.length;\n for(int i=0; i {\n int a;\n int b;\n int c;\n public Tuple(int a, int b) {\n this.a = a;\n this.b = b;\n this.c = 0;\n }\n public Tuple(int a, int b, int c) {\n this.a = a;\n this.b = b;\n this.c = c;\n }\n public int getA() { return a; }\n public int getB() { return b; }\n public int getC() { return c; }\n public int compareTo(Tuple other) {\n if (this.a == other.a) {\n if (this.b == other.b) return Long.compare(this.c, other.c);\n return Long.compare(this.b, other.b);\n }\n return Long.compare(this.a, other.a);\n }\n @Override\n public int hashCode() { return Arrays.deepHashCode(new Integer[]{a, b, c}); }\n @Override\n public boolean equals(Object o) {\n if (!(o instanceof Tuple)) return false;\n Tuple pairo = (Tuple) o;\n return (this.a == pairo.a && this.b == pairo.b && this.c == pairo.c);\n }\n @Override\n public String toString() { return String.format(\"(%d %d %d) \", this.a, this.b, this.c); }\n}\nprivate static int abs(int a){ return (a>=0) ? a: -a; }\nprivate static int min(int... ins){ int min = ins[0]; for(int i=1; i max) max = ins[i]; } return max; }\nprivate static int sum(int... ins){ int total = 0; for (int v : ins) { total += v; } return total; }\nprivate static long abs(long a){ return (a>=0) ? a: -a; }\nprivate static long min(long... ins){ long min = ins[0]; for(int i=1; i max) max = ins[i]; } return max; }\nprivate static long sum(long... ins){ long total = 0; for (long v : ins) { total += v; } return total; }\nprivate static double abs(double a){ return (a>=0) ? a: -a; }\nprivate static double min(double... ins){ double min = ins[0]; for(int i=1; i max) max = ins[i]; } return max; }\nprivate static double sum(double... ins){ double total = 0; for (double v : ins) { total += v; } return total; }\n\n}\n", "lang_cluster": "Java", "tags": ["greedy", "binary search"], "code_uid": "258f7a3ddf1d43ec0b7e14c602788767", "src_uid": "2eb101dcfcc487fe6e44c9b4c0e4024d", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.math.BigInteger;\npublic class flags{\npublic static int mod = 1000000007,modi = (mod+1)>>1;\npublic static BigInteger modB = new BigInteger(\"1000000007\");\npublic static BigInteger modiB = new BigInteger(\"500000004\");\npublic static long id[][] ={{1,0,0,0,0,0,0},{0,1,0,0,0,0,0},{0,0,1,0,0,0,0},{0,0,0,1,0,0,0},{0,0,0,0,1,0,0},{0,0,0,0,0,1,0},{0,0,0,0,0,0,1}};\npublic static long a[][] = {{1,0,0,0,0,0,0},{1,0,0,0,0,0,0},{1,1,0,0,1,1,0},{1,1,0,0,1,0,1},{1,0,1,1,0,0,0},{0,0,1,0,0,0,0},{0,0,0,1,0,0,0}};//adyacencia aut\npublic static void main(String args[]) throws IOException{\nBufferedReader lector= new BufferedReader(new InputStreamReader(System.in));\nString tmp = lector.readLine();\nint n2 = Integer.parseInt(tmp.substring(0,tmp.indexOf(\" \")))-1;\nint n1 = Integer.parseInt(tmp.substring(tmp.indexOf(\" \")+1));\nBigInteger un = f(a,n1);\nBigInteger dos = f(a,n1/2+(n1&1));\nun = ((un.subtract(dos).multiply(modiB)).add(dos)).mod(modB);\nBigInteger un1 = f(a,n2);\nBigInteger dos1 = f(a,n2/2+(n2&1));\nun1 = ((un1.subtract(dos1).multiply(modiB)).add(dos1)).mod(modB);\nBigInteger joder = un.subtract(un1);\nwhile(joder.compareTo(BigInteger.ZERO)<0)joder = joder.add(modB);\nSystem.out.println(joder);\n}\npublic static BigInteger f(long a[][],int n){\nlong p[][] = exp(a,n);\nBigInteger res = BigInteger.ZERO;\nint ri[] = {0,1,1,1,1,1,1};//terminales de cada nodo\nfor(int nn = 0;nn 0) {\r\n solve();\r\n }\r\n out.flush();\r\n }\r\n\r\n public static void solve() {\r\n int n = i();\r\n int x = i();\r\n if (n > x) {\r\n out.println(pow(x, n, mod2));\r\n } else {\r\n initializeFactorial(n, mod2);\r\n long[][] dp = new long[n + 1][x + 1];\r\n long ans = pow(x, n, mod2);\r\n ans -= dfs(dp, n, x);\r\n if (ans < 0) {\r\n ans += mod2;\r\n }\r\n out.println(ans);\r\n }\r\n\r\n }\r\n\r\n private static long dfs(long[][] dp, int i, int j) {\r\n if (dp[i][j] > 0) {\r\n return dp[i][j];\r\n }\r\n \r\n long x = 0L;\r\n if (i == 1) {\r\n x = j;\r\n } else if (j == 1) {\r\n x = 0;\r\n } else if (i == 2) {\r\n x = pow(j, 2, mod2) - j;\r\n if (x < 0) {\r\n x += mod2;\r\n }\r\n } else if (i > j) {\r\n x = 0;\r\n } else if (i == j) {\r\n x = i * pow(i - 1, i - 1, mod2) % mod2;\r\n } else {\r\n for (int k = 1; k <= i; k++) {\r\n long r = pow(i - 1, i - k, mod2);\r\n r *= binomialCoefficient(i, k, mod2);\r\n r %= mod2;\r\n x += (dfs(dp, k, j - i + 1) * r) % mod2;\r\n x %= mod2;\r\n }\r\n }\r\n\r\n dp[i][j] = x;\r\n return x;\r\n }\r\n\r\n\r\n static long[] fac;\r\n static long[] inv;\r\n\r\n static void initializeFactorial(int n, int mod) {\r\n fac = new long[n + 1];\r\n inv = new long[n + 1];\r\n long[] v = new long[fac.length];\r\n fac[0] = inv[0] = 1;\r\n for (int i = 1; i < fac.length; i++) {\r\n v[i] = i == 1 ? 1 : v[i - mod % i] * (mod / i + 1);\r\n v[i] %= mod;\r\n fac[i] = fac[i - 1] * i;\r\n fac[i] %= mod;\r\n inv[i] = inv[i - 1] * v[i];\r\n inv[i] %= mod;\r\n }\r\n }\r\n\r\n static int binomialCoefficient(int n, int k, int m) {\r\n long res = fac[n] * inv[k];\r\n res %= m;\r\n res *= inv[n - k];\r\n return (int) (res % m);\r\n }\r\n\r\n static long[] pre(int[] a) {\r\n long[] pre = new long[a.length + 1];\r\n pre[0] = 0;\r\n for (int i = 0; i < a.length; i++) {\r\n pre[i + 1] = pre[i] + a[i];\r\n }\r\n return pre;\r\n }\r\n\r\n static void print(char A[]) {\r\n for (char c : A) {\r\n out.print(c);\r\n }\r\n out.println();\r\n }\r\n\r\n static void print(boolean A[]) {\r\n for (boolean c : A) {\r\n out.print(c + \" \");\r\n }\r\n out.println();\r\n }\r\n\r\n static void print(int A[]) {\r\n for (int c : A) {\r\n out.print(c + \" \");\r\n }\r\n out.println();\r\n }\r\n\r\n static void print(long A[]) {\r\n for (long i : A) {\r\n out.print(i + \" \");\r\n }\r\n out.println();\r\n }\r\n\r\n static void print(List A) {\r\n for (int a : A) {\r\n out.print(a + \" \");\r\n }\r\n }\r\n\r\n static int i() {\r\n return in.nextInt();\r\n }\r\n\r\n static long l() {\r\n return in.nextLong();\r\n }\r\n\r\n static double d() {\r\n return in.nextDouble();\r\n }\r\n\r\n static String s() {\r\n return in.nextLine();\r\n }\r\n\r\n static int[][] inputWithIdx(int N) {\r\n int A[][] = new int[N][2];\r\n for (int i = 0; i < N; i++) {\r\n A[i] = new int[]{i, in.nextInt()};\r\n }\r\n return A;\r\n }\r\n\r\n static int[] input(int N) {\r\n int A[] = new int[N];\r\n for (int i = 0; i < N; i++) {\r\n A[i] = in.nextInt();\r\n }\r\n return A;\r\n }\r\n\r\n static long[] inputLong(int N) {\r\n long A[] = new long[N];\r\n for (int i = 0; i < A.length; i++) {\r\n A[i] = in.nextLong();\r\n }\r\n return A;\r\n }\r\n\r\n static int GCD(int a, int b) {\r\n if (b == 0) {\r\n return a;\r\n } else {\r\n return GCD(b, a % b);\r\n }\r\n }\r\n\r\n static long GCD(long a, long b) {\r\n if (b == 0) {\r\n return a;\r\n } else {\r\n return GCD(b, a % b);\r\n }\r\n }\r\n\r\n static long LCM(int a, int b) {\r\n return (long) a / GCD(a, b) * b;\r\n }\r\n\r\n static long LCM(long a, long b) {\r\n return a / GCD(a, b) * b;\r\n }\r\n\r\n static void shuffleAndSort(int[] arr) {\r\n for (int i = 0; i < arr.length; i++) {\r\n int rand = (int) (Math.random() * arr.length);\r\n int temp = arr[rand];\r\n arr[rand] = arr[i];\r\n arr[i] = temp;\r\n }\r\n Arrays.sort(arr);\r\n }\r\n\r\n static void shuffleAndSort(int[][] arr, Comparator comparator) {\r\n for (int i = 0; i < arr.length; i++) {\r\n int rand = (int) (Math.random() * arr.length);\r\n int[] temp = arr[rand];\r\n arr[rand] = arr[i];\r\n arr[i] = temp;\r\n }\r\n Arrays.sort(arr, comparator);\r\n }\r\n\r\n static void shuffleAndSort(long[] arr) {\r\n for (int i = 0; i < arr.length; i++) {\r\n int rand = (int) (Math.random() * arr.length);\r\n long temp = arr[rand];\r\n arr[rand] = arr[i];\r\n arr[i] = temp;\r\n }\r\n Arrays.sort(arr);\r\n }\r\n\r\n static boolean isPerfectSquare(double number) {\r\n double sqrt = Math.sqrt(number);\r\n return ((sqrt - Math.floor(sqrt)) == 0);\r\n }\r\n\r\n static void swap(int A[], int a, int b) {\r\n int t = A[a];\r\n A[a] = A[b];\r\n A[b] = t;\r\n }\r\n\r\n static long pow(long a, long b, int mod) {\r\n long pow = 1;\r\n long x = a;\r\n while (b != 0) {\r\n if ((b & 1) != 0) {\r\n pow = (pow * x) % mod;\r\n }\r\n x = (x * x) % mod;\r\n b /= 2;\r\n }\r\n return pow;\r\n }\r\n\r\n static long pow(long a, long b) {\r\n long pow = 1;\r\n long x = a;\r\n while (b != 0) {\r\n if ((b & 1) != 0) {\r\n pow *= x;\r\n }\r\n x = x * x;\r\n b /= 2;\r\n }\r\n return pow;\r\n }\r\n\r\n static long modInverse(long x, int mod) {\r\n return pow(x, mod - 2, mod);\r\n }\r\n\r\n static boolean isPrime(long N) {\r\n if (N <= 1) {\r\n return false;\r\n }\r\n if (N <= 3) {\r\n return true;\r\n }\r\n if (N % 2 == 0 || N % 3 == 0) {\r\n return false;\r\n }\r\n for (int i = 5; i * i <= N; i = i + 6) {\r\n if (N % i == 0 || N % (i + 2) == 0) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n public static String reverse(String str) {\r\n if (str == null) {\r\n return null;\r\n }\r\n return new StringBuilder(str).reverse().toString();\r\n }\r\n\r\n public static String repeat(char ch, int repeat) {\r\n if (repeat <= 0) {\r\n return \"\";\r\n }\r\n final char[] buf = new char[repeat];\r\n for (int i = repeat - 1; i >= 0; i--) {\r\n buf[i] = ch;\r\n }\r\n return new String(buf);\r\n }\r\n\r\n public static int[] manacher(String s) {\r\n char[] chars = s.toCharArray();\r\n int n = s.length();\r\n int[] d1 = new int[n];\r\n for (int i = 0, l = 0, r = -1; i < n; i++) {\r\n int k = (i > r) ? 1 : Math.min(d1[l + r - i], r - i + 1);\r\n while (0 <= i - k && i + k < n && chars[i - k] == chars[i + k]) {\r\n k++;\r\n }\r\n d1[i] = k--;\r\n if (i + k > r) {\r\n l = i - k;\r\n r = i + k;\r\n }\r\n }\r\n return d1;\r\n }\r\n\r\n public static int[] kmp(String s) {\r\n int n = s.length();\r\n int[] res = new int[n];\r\n for (int i = 1; i < n; ++i) {\r\n int j = res[i - 1];\r\n while (j > 0 && s.charAt(i) != s.charAt(j)) {\r\n j = res[j - 1];\r\n }\r\n if (s.charAt(i) == s.charAt(j)) {\r\n ++j;\r\n }\r\n res[i] = j;\r\n }\r\n return res;\r\n }\r\n}\r\n\r\nclass Pair {\r\n\r\n int i, j;\r\n\r\n Pair(int i, int j) {\r\n this.i = i;\r\n this.j = j;\r\n }\r\n\r\n @Override\r\n public boolean equals(Object o) {\r\n if (this == o) {\r\n return true;\r\n }\r\n if (o == null || getClass() != o.getClass()) {\r\n return false;\r\n }\r\n Pair pair = (Pair) o;\r\n return i == pair.i && j == pair.j;\r\n }\r\n\r\n @Override\r\n public int hashCode() {\r\n return Objects.hash(i, j);\r\n }\r\n}\r\n\r\nclass FastReader {\r\n\r\n BufferedReader br;\r\n StringTokenizer st;\r\n\r\n public FastReader() {\r\n br = new BufferedReader(new InputStreamReader(System.in));\r\n }\r\n\r\n String next() {\r\n while (st == null || !st.hasMoreElements()) {\r\n try {\r\n st = new StringTokenizer(br.readLine());\r\n } catch (IOException e) {\r\n e.printStackTrace();\r\n }\r\n }\r\n return st.nextToken();\r\n }\r\n\r\n int nextInt() {\r\n return Integer.parseInt(next());\r\n }\r\n\r\n long nextLong() {\r\n return Long.parseLong(next());\r\n }\r\n\r\n double nextDouble() {\r\n return Double.parseDouble(next());\r\n }\r\n\r\n String nextLine() {\r\n String str = \"\";\r\n try {\r\n str = br.readLine();\r\n } catch (IOException e) {\r\n e.printStackTrace();\r\n }\r\n return str;\r\n }\r\n}\r\n\r\nclass Node {\r\n\r\n int data, open, close;\r\n\r\n Node() {\r\n this(0, 0, 0);\r\n }\r\n\r\n Node(int data, int open, int close) {\r\n this.data = data;\r\n this.open = open;\r\n this.close = close;\r\n }\r\n}\r\n\r\nclass ST {\r\n\r\n int n;\r\n Node[] st;\r\n\r\n ST(int n) {\r\n this.n = n;\r\n st = new Node[4 * Integer.highestOneBit(n)];\r\n }\r\n\r\n void build(Node[] nodes) {\r\n build(0, 0, n - 1, nodes);\r\n }\r\n\r\n private void build(int id, int l, int r, Node[] nodes) {\r\n if (l == r) {\r\n st[id] = nodes[l];\r\n return;\r\n }\r\n int mid = (l + r) >> 1;\r\n build((id << 1) + 1, l, mid, nodes);\r\n build((id << 1) + 2, mid + 1, r, nodes);\r\n st[id] = comb(st[(id << 1) + 1], st[(id << 1) + 2]);\r\n }\r\n\r\n void update(int i, Node node) {\r\n update(0, 0, n - 1, i, node);\r\n }\r\n\r\n private void update(int id, int l, int r, int i, Node node) {\r\n if (i < l || r < i) {\r\n return;\r\n }\r\n if (l == r) {\r\n st[id] = node;\r\n return;\r\n }\r\n int mid = (l + r) >> 1;\r\n update((id << 1) + 1, l, mid, i, node);\r\n update((id << 1) + 2, mid + 1, r, i, node);\r\n st[id] = comb(st[(id << 1) + 1], st[(id << 1) + 2]);\r\n }\r\n\r\n Node get(int x, int y) {\r\n return get(0, 0, n - 1, x, y);\r\n }\r\n\r\n private Node get(int id, int l, int r, int x, int y) {\r\n if (x > r || y < l) {\r\n return new Node();\r\n }\r\n if (x <= l && r <= y) {\r\n return st[id];\r\n }\r\n int mid = (l + r) >> 1;\r\n return comb(get((id << 1) + 1, l, mid, x, y), get((id << 1) + 2, mid + 1, r, x, y));\r\n }\r\n\r\n Node comb(Node a, Node b) {\r\n if (a == null) {\r\n return b;\r\n }\r\n if (b == null) {\r\n return a;\r\n }\r\n int min = Math.min(a.open, b.close);\r\n return new Node(a.data + b.data + min * 2, a.open + b.open - min, a.close + b.close - min);\r\n }\r\n}", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics"], "code_uid": "5bef11c975b145a885d28fd53d2135de", "src_uid": "1908d1c8c6b122a4c6633a7af094f17f", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "//import java.awt.Dimension;\nimport java.awt.Point;\nimport java.io.*;\nimport static java.lang.Math.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport static java.math.BigInteger.*;\nimport java.util.*;\nimport static java.util.Arrays.*;\n//import java.math.BigInteger;\n//import static java.lang.Character.*;\n//import static java.lang.Math.*;\n//import static java.math.BigInteger.*;\n\n//import static java.util.Arrays.*;\n\n//import java.awt.Point; // interger !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n//import java.awt.Polygon;\n//import java.awt.Rectangle;\n//import java.awt.geom.AffineTransform;\n//import java.awt.geom.Line2D;\n//import java.awt.geom.Point2D;\n//import javafx.scene.shape.Line;\n//import javafx.scene.transform.Rotate;\n\n//\npublic class Main implements Runnable{\n\n // https://netbeans.org/kb/73/java/editor-codereference_ru.html#display\n\n static boolean oj;\n \n @Override\n public void run(){\n try {\n Locale.setDefault(Locale.US);\n } catch (Exception e) {\n }\n oj = true;\n try {\n oj = System.getProperty(\"MYLOCAL\") == null;\n } catch (Exception e) {\n }\n//\n if (oj) {\n sc = new FastScanner(new InputStreamReader(System.in));\n out = new PrintWriter(new OutputStreamWriter(System.out));\n } else {\n try {\n sc = new FastScanner(new FileReader(\"input.txt\"));\n out = new PrintWriter(new FileWriter(\"output.txt\"));\n } catch (IOException e) {\n MLE();\n }\n }\n Solver s = new Solver();\n s.sc = sc;\n s.out = out;\n\n s.solve();\n if (!oj) {\n err.println(\"Time: \" + (System.currentTimeMillis() - timeBegin) / 1e3);\n err.printf(\"Mem: %d\\n\", (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) >> 20);\n }\n out.flush();\n }\n\n private void show(int[] arr) {\n for (int v : arr) {\n err.print(\" \" + v);\n }\n err.println();\n }\n\n public static void exit() {\n err.println(\"Time: \" + (System.currentTimeMillis() - timeBegin) / 1e3);\n err.printf(\"Mem: %d\\n\", (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) >> 20);\n out.flush();\n out.close();\n System.exit(0);\n }\n\n public static void MLE() {\n int[][] arr = new int[1024 * 1024][];\n for (int i = 0; i < arr.length; i++) {\n arr[i] = new int[1024 * 1024];\n }\n }\n\n public static void main(String[] args) throws FileNotFoundException {\n //new Main().run();\n new Thread(null, new Main(), \"myThread\", 100 * 1024 * 1024).start();\n }\n\n static long timeBegin = System.currentTimeMillis();\n static FastScanner sc;\n static PrintWriter out;\n static PrintStream err = System.err;\n}\n //\n\n//\nclass FastScanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n FastScanner(InputStreamReader reader) {\n br = new BufferedReader(reader);\n st = new StringTokenizer(\"\");\n }\n\n String next() {\n while (!st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception ex) {\n return null;\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String nextLine() {\n try {\n return br.readLine();\n } catch (IOException ex) {\n return null;\n }\n }\n}\n//\n\nclass Solver {\n\n void aser(boolean OK) {\n if (!OK) {\n Main.MLE();\n }\n }\n\n FastScanner sc;\n PrintWriter out;\n static PrintStream err = System.err;\n \n long[] getAllDiv(long A){\n TreeSet arr = new TreeSet<>();\n for( long d = 1; d*d <= A; ++d ){\n if( A % d == 0 ) {\n arr.add(d);\n arr.add(A/d);\n }\n }\n int pos = 0;\n long[] a = new long[arr.size()];\n for (long x : arr) a[pos++] = x;\n return a;\n }\n \n long myPow(long p, int alfa){\n long ans = 1;\n for (int i = 0; i < alfa; i++) {\n ans *= p;\n }\n return ans;\n }\n \n void solve(){\n final long A = sc.nextLong();\n long[] divA = getAllDiv(A);\n TreeMap> P = new TreeMap<>();\n for (long div : divA) {\n --div;\n for (int alfa = 1; alfa <= 60; alfa++) {\n long p = (long)( pow( div, 1.0 / alfa ) + 0.5 );\n if( 2<=p && myPow(p,alfa)==div && \n valueOf(p).isProbablePrime(Integer.MAX_VALUE) ){\n if( !P.containsKey(p) )\n P.put(p, new TreeSet<>());\n P.get(p).add(alfa);\n break;\n }\n }\n }\n \n long[] dp0, dp;\n dp0 = new long[divA.length];\n dp0[0] = 1;\n for( long p : P.keySet() ){\n dp = dp0.clone();\n for( int alfa : P.get(p) ){\n long val = myPow(p, alfa) + 1;\n for( int ID = 0; ID < divA.length; ++ID){\n long div = divA[ID];\n if( 1e12 + 5 <= 1.0 * div * val ) break;\n long toDiv = div * val;\n int toID = binarySearch(divA, toDiv);\n if( 0 <= toID ) dp[toID] += dp0[ID];\n }\n }\n //\n dp0 = dp;\n }\n out.println(dp0[divA.length - 1]);\n }\n \n \n}\n\n\n", "lang_cluster": "Java", "tags": ["dfs and similar", "math", "dp", "data structures", "number theory"], "code_uid": "d18e76d21329a844d9f1d6c0b4d815bd", "src_uid": "1f68bd6f8b40e45a5bd360b03a264ef4", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class cf306c {\n static long mod = 1_000_000_009;\n public static void main(String[] args) {\n int MAX = 4020;\n long[] fact = new long[MAX];\n fact[0] = 1;\n for(int i=1; i b || (n-bad) > w) continue;\n long tmp = (fact[b]*choose[b-1][bad-1])%mod;\n tmp = (tmp * fact[w])%mod;\n tmp = (tmp * choose[w-1][n-bad-1])%mod;\n tmp = (tmp * (n-bad-1)) % mod;\n ans = (ans+tmp)%mod;\n }\n out.println(ans);\n out.close();\n }\n static class FastIO extends PrintWriter {\n BufferedReader br;\n StringTokenizer st;\n\n public FastIO() {\n this(System.in, System.out);\n }\n\n public FastIO(InputStream in, OutputStream out) {\n super(new BufferedWriter(new OutputStreamWriter(out)));\n br = new BufferedReader(new InputStreamReader(in));\n scanLine();\n }\n\n public void scanLine() {\n try {\n st = new StringTokenizer(br.readLine().trim());\n } catch (Exception e) {\n throw new RuntimeException(e.getMessage());\n }\n }\n\n public int numTokens() {\n if (!st.hasMoreTokens()) {\n scanLine();\n return numTokens();\n }\n return st.countTokens();\n }\n\n public String next() {\n if (!st.hasMoreTokens()) {\n scanLine();\n return next();\n }\n return st.nextToken();\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["combinatorics", "number theory"], "code_uid": "e08a656ece2f0d2cb7d04f45fd304d7c", "src_uid": "63e93a161bbff623323e66c98d5e20ac", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class CF273E {\n\n final static long mod = 1000000007;\n\n public static void solve(Input in, PrintWriter out) throws IOException {\n int n = in.nextInt();\n int p = in.nextInt();\n ArrayList starts = new ArrayList();\n ArrayList gs = new ArrayList();\n starts.add(0L);\n gs.add(0);\n starts.add(3L);\n gs.add(1);\n long u = 3, v = 1;\n for (int j1 = 0, j2 = 0; u < p; ) {\n while (starts.get(j1 + 1) <= u / 3) {\n ++j1;\n }\n while (starts.get(j2 + 1) <= u - u / 3) {\n ++j2;\n }\n long next1 = starts.get(j1 + 1) * 3;\n if (next1 / 3 < starts.get(j1 + 1) || (next1 - 1) / 3 >= starts.get(j1 + 1)) {\n throw new AssertionError();\n }\n long next2 = (starts.get(j2 + 1) * 3) / 2;\n while (next2 - next2 / 3 < starts.get(j1 + 1)) {\n next2++;\n }\n while (next2 - 1 - (next2 - 1) / 3 >= starts.get(j2 + 1)) {\n next2--;\n }\n if (next2 - next2 / 3 < starts.get(j2 + 1) || next2 - 1 - (next2 - 1) / 3 >= starts.get(j2 + 1)) {\n throw new AssertionError();\n }\n long next = Math.min(next1, next2);\n int val = mutex(gs.get(next >= next1 ? j1 + 1 : j1), gs.get(next >= next2 ? j2 + 1 : j2));\n if (val != v) {\n starts.add(next);\n gs.add(val);\n }\n u = next;\n v = val;\n }\n// System.err.println(starts.size());\n long[] c = new long[3];\n for (int i = 0; i < starts.size(); ++i) {\n long from = starts.get(i);\n long to = i == starts.size() - 1 ? p - 1 : starts.get(i + 1) - 1;\n if (to >= p) {\n to = p - 1;\n }\n if (from > to) {\n continue;\n }\n// System.err.println(from + \" \" + to + \" \" + gs.get(i));\n// System.err.println((to - from + 1) * p);\n// System.err.println(to * (to + 1) / 2);\n// System.err.println((from - 1) * (from) / 2);\n c[gs.get(i)] = (c[gs.get(i)] + (to - from + 1) * p) % mod;\n c[gs.get(i)] = (c[gs.get(i)] + mod - (to * (to + 1) / 2 % mod)) % mod;\n c[gs.get(i)] = (c[gs.get(i)] + (from - 1) * (from) / 2) % mod;\n }\n c[0] = (c[0] + mod - p) % mod;\n// for (int i = 1; i < p; ++i) {\n// c[g[i]] = (c[g[i]] + p - i) % mod;\n// }\n long[] d = new long[4];\n d[0] = 1;\n for (int it = 0; it < n; ++it) {\n long[] dd = new long[4];\n for (int i = 0; i < 4; ++i) {\n for (int j = 0; j < 3; ++j) {\n dd[i ^ j] = (dd[i ^ j] + d[i] * c[j]) % mod;\n }\n }\n d = dd;\n }\n long ans = (d[1] + d[2] + d[3]) % mod;\n out.println(ans);\n }\n\n private static int mutex(int a, int b) {\n if (a != 0 && b != 0) return 0;\n if (a != 1 && b != 1) return 1;\n return 2;\n }\n\n public static void main(String[] args) throws IOException {\n PrintWriter out = new PrintWriter(System.out);\n solve(new Input(new BufferedReader(new InputStreamReader(System.in))), out);\n out.close();\n }\n\n static class Input {\n BufferedReader in;\n StringTokenizer st;\n\n public Input(BufferedReader in) {\n this.in = in;\n eat(\"\");\n }\n\n public Input(String s) {\n this.in = new BufferedReader(new StringReader(s));\n }\n\n public void eat(String str) {\n st = new StringTokenizer(str);\n }\n\n public String next() throws IOException {\n while (!st.hasMoreTokens()) {\n String line = in.readLine();\n if (line == null) {\n return null;\n }\n eat(line);\n }\n return st.nextToken();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["dp", "games"], "code_uid": "84ebf06541af376ecf132e9df22a3172", "src_uid": "c03b6379e9d186874ac3d97c6968fbd0", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "// practice with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF915G extends PrintWriter {\n\tCF915G() { super(System.out, true); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF915G o = new CF915G(); o.main(); o.flush();\n\t}\n\n\tstatic final int MD = 1000000007;\n\tlong power(int a, int k) {\n\t\tif (k == 0)\n\t\t\treturn 1;\n\t\tlong p = power(a, k >> 1);\n\t\tp = p * p % MD;\n\t\tif ((k & 1) == 1)\n\t\t\tp = p * a % MD;\n\t\treturn p;\n\t}\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tint[] cc = new int[k + 1];\n\t\tfor (int a = 2; a <= k; a++) {\n\t\t\tif (cc[a] != 0)\n\t\t\t\tcontinue;\n\t\t\tfor (int b = a; b <= k; b += a)\n\t\t\t\tcc[b]++;\n\t\t}\n\t\tfor (int a = 2, a2; (a2 = a * a) <= k; a++)\n\t\t\tfor (int b = a2; b <= k; b += a2)\n\t\t\t\tcc[b] = 0;\n\t\tint[] pp = new int[k + 1];\n\t\tfor (int i = 1; i <= k; i++)\n\t\t\tpp[i] = (int) power(i, n);\n\t\tint[] dd = new int[k + 1];\n\t\tfor (int a = 2; a <= k; a++) {\n\t\t\tif (cc[a] == 0)\n\t\t\t\tcontinue;\n\t\t\tfor (int i = 1; i * a <= k; i++) {\n\t\t\t\tint l = i * a, r = (i + 1) * a;\n\t\t\t\tint p = cc[a] % 2 == 0 ? pp[i] : -pp[i];\n\t\t\t\tdd[l] = (dd[l] + p) % MD;\n\t\t\t\tif (r <= k)\n\t\t\t\t\tdd[r] = (dd[r] - p) % MD;\n\t\t\t}\n\t\t}\n\t\tint ans = 0;\n\t\tfor (int i = 1; i <= k; i++) {\n\t\t\tdd[i] = (dd[i] + dd[i - 1]) % MD;\n\t\t\tint x = (pp[i] + dd[i]) % MD;\n\t\t\tif (x < 0)\n\t\t\t\tx += MD;\n\t\t\tans = (ans + (x ^ i)) % MD;\n\t\t}\n\t\tprintln(ans);\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "number theory"], "code_uid": "10829e08d426c11a89eb4beb0e8133df", "src_uid": "122c08aa91c9a9d6a151ee6e3d0662fa", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class NewYearAndBinaryTreePaths\n{\n\tpublic static long k;\n\tpublic static long[][][] memo;\n\tpublic static int max;\n\tpublic static int min;\n\t\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner in = new Scanner(System.in);\n\t\t\n\t\tlong s = in.nextLong();\n\t\t\n\t\tmemo = new long[49][101][201];\n\t\t\n\t\tlong result = 0;\n\t\tfor(int x = 0; x <= 50; x++)\n\t\t{\n\t\t\tfor(int y = 0; y <= 50; y++)\n\t\t\t{\n\t\t\t\tlong mult = (1L << (x + 1)) + (1L << (y + 1)) - 3;\n\t\t\t\tlong lca = s / mult;\n\t\t\t\t\n\t\t\t\tk = s - (lca * mult) - ((1L << y) - 1);\n\t\t\t\t\n\t\t\t\tif(lca > 0 && k >= 0)\n\t\t\t\t{\n\t\t\t\t\tif(Math.max(x, y) <= 1)\n\t\t\t\t\t{\n\t\t\t\t\t\tif(k == 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tresult++;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tmax = Math.max(x, y) - 1;\n\t\t\t\t\t\tmin = Math.min(x, y) - 1;\n\t\t\t\t\t\tfor(long[][] a : memo)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tfor(long[] b : a)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tArrays.fill(b, -1);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\tfor(int z = 0; z <= Math.max(x - 1, 0) + Math.max(y - 1, 0); z++)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif(z % 2 == k % 2)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tresult += count(1, z, z >> 1);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(result);\n\t}\n\t\n\tpublic static long count(int index, int prev, int sum)\n\t{\n\t\tif(index == max)\n\t\t{\n\t\t\tif(prev <= 1 + (index <= min ? 1 : 0) && sum == (k >> index))\n\t\t\t{\n\t\t\t\tif(prev == 1 && index <= min)\n\t\t\t\t{\n\t\t\t\t\treturn 2;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\treturn 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\t\telse if(memo[index][prev][sum] != -1)\n\t\t{\n\t\t\treturn memo[index][prev][sum];\n\t\t}\n\t\telse\n\t\t{\n\t\t\tlong count = 0;\n\t\t\tfor(int i = 0; i <= 1 + (index <= min ? 1 : 0); i++)\n\t\t\t{\n\t\t\t\tif(prev - i >= 0 && ((prev - i + sum) & 1) == ((k >> index) & 1))\n\t\t\t\t{\n\t\t\t\t\tcount += count(index + 1, prev - i, (prev - i + sum) >> 1);\n\t\t\t\t\tif(i == 1 && index <= min)\n\t\t\t\t\t{\n\t\t\t\t\t\tcount += count(index + 1, prev - i, (prev - i + sum) >> 1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\treturn memo[index][prev][sum] = count;\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "tags": ["brute force", "dp", "combinatorics", "bitmasks"], "code_uid": "9b186a04de11cad6980844380ecd0a4e", "src_uid": "c142f8bc5252e739035992926545c251", "difficulty": 3200.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF {\n FastScanner in;\n PrintWriter out;\n\n long mod = (long) 1e9 + 7;\n\n void solve() {\n// for (int i = 1; i <= 10; i++) {\n// for (int j = 1; j <= 10; j++) {\n// System.err.print(sol2(i, j) - sol3(i, j) + \" \");\n// }\n// System.err.println();\n// }\n out.println(sol2(in.nextInt(), in.nextInt()));\n }\n\n long sol2(int n, int m) {\n long res = 0;\n long[][] dp01 = new long[m + 1][n + 1];\n long[][] dp01Sum = new long[m + 1][n + 1];\n for (int w = 2; w <= m; w++)\n dp01[w][1] = 1;\n for (int h = 2; h <= n; h++)\n for (int w = 2; w <= m; w++) {\n dp01Sum[w][h] = (dp01Sum[w - 1][h] + dp01[w][h - 1]) % mod;\n dp01[w][h] = (dp01[w - 1][h] + dp01Sum[w][h]) % mod;\n }\n long[][] dp1 = new long[m + 1][n + 1];\n long[][] dp1Sum = new long[m + 1][n + 1];\n for (int w = 2; w <= m; w++)\n dp1[w][1] = 1;\n for (int h = 2; h <= n; h++)\n for (int w = 2; w <= m; w++) {\n dp1Sum[w][h] = (dp1Sum[w - 1][h] + dp01[w - 1][h - 1]) % mod;\n dp1[w][h] = (dp1[w - 1][h] + dp1Sum[w][h] + dp01[w - 1][h - 1]) % mod;\n// for (int w1 = 2; w1 < w; w1++) {\n// dp1[w][h] = (dp1[w][h] + (dp01[w1][h - 1] * (w - w1 + 1))\n// % mod)\n// % mod;\n// }\n }\n long[][] dpSum01 = new long[m + 1][n + 1];\n for (int h = 1; h <= n; h++)\n for (int w = 1; w <= m; w++)\n dpSum01[w][h] = (dpSum01[w][h - 1] + dp01[w][h]) % mod;\n long[][] dpSum1 = new long[m + 1][n + 1];\n for (int h = 1; h <= n; h++)\n for (int w = 1; w <= m; w++)\n dpSum1[w][h] = (dpSum1[w][h - 1] + dp1[w][h]) % mod;\n for (int h1 = 1; h1 <= n; h1++)\n for (int w1 = 1; w1 <= m; w1++) {\n long curRes = (dpSum01[w1][h1] * dpSum1[w1][n - h1 + 1]) % mod;\n curRes = (curRes * (m - w1 + 1)) % mod;\n res = (res + curRes) % mod;\n }\n return res;\n }\n\n long sol3(int n, int m) {\n long res = 0;\n long[][] dp01 = new long[m + 1][n + 1];\n long[][] dp01Sum = new long[m + 1][n + 1];\n for (int w = 2; w <= m; w++)\n dp01[w][1] = 1;\n for (int h = 2; h <= n; h++)\n for (int w = 2; w <= m; w++) {\n dp01Sum[w][h] = (dp01Sum[w - 1][h] + dp01[w][h - 1]) % mod;\n dp01[w][h] = (dp01[w - 1][h] + dp01Sum[w][h]) % mod;\n }\n long[][] dp1 = new long[m + 1][n + 1];\n for (int w = 2; w <= m; w++)\n dp1[w][1] = 1;\n for (int h = 2; h <= n; h++)\n for (int w = 2; w <= m; w++) {\n for (int w1 = 2; w1 < w; w1++) {\n dp1[w][h] = (dp1[w][h] + (dp01[w1][h - 1] * (w - w1 + 1))\n % mod)\n % mod;\n }\n }\n long[][] dp3 = new long[m + 1][n + 1];\n for (int h = 1; h <= n; h++)\n for (int w = 1; w <= m; w++) {\n for (int h1 = 1; h1 <= h; h1++) {\n dp3[w][h] = (dp3[w][h] + (dp01[w][h1] * dp1[w][h - h1 + 1])\n % mod)\n % mod;\n\n }\n // dp3[w][h] = dp3[w][h - 1] + dp01[w][h] * dp1[w][h - h + 1];\n }\n for (int h = 1; h <= n; h++)\n for (int w = 1; w <= m; w++) {\n long curRes = (dp3[w][h] * (n - h + 1)) % mod;\n curRes = (curRes * (m - w + 1)) % mod;\n res = (res + curRes) % mod;\n }\n return res;\n }\n\n int stupid(int n, int m) {\n int total = n * m;\n int sum = 0;\n boolean[][] field = new boolean[n][m];\n for (int st = 0; st < (1 << total); st++) {\n int it = 0;\n for (int i = 0; i < n; i++)\n for (int j = 0; j < m; j++)\n if (((1 << it++) & st) != 0)\n field[i][j] = true;\n else\n field[i][j] = false;\n int l = -1, r = -1;\n boolean ok = true;\n int[] first = new int[n];\n int[] last = new int[n];\n Arrays.fill(first, -1);\n Arrays.fill(last, -1);\n for (int i = 0; i < n; i++) {\n int cnt = 0;\n for (int j = 0; j < m; j++)\n if (field[i][j]) {\n if (cnt == 0)\n first[i] = j;\n last[i] = j;\n cnt++;\n }\n if (cnt != 2 && cnt != 0)\n ok = false;\n if (cnt == 2) {\n r = i;\n if (l == -1)\n l = i;\n }\n }\n if (!ok)\n continue;\n if (l == -1 || r == -1)\n continue;\n for (int i = l; i <= r; i++)\n if (first[i] == -1 || last[i] == -1 || first[i] == last[i])\n ok = false;\n if (!ok)\n continue;\n boolean ok2 = false;\n for (int t = l; t <= r; t++) {\n boolean ok3 = true;\n for (int i = l; i < t; i++) {\n if (first[i] < first[i + 1] || last[i] > last[i + 1])\n ok3 = false;\n }\n for (int i = r; i > t; i--)\n if (first[i] < first[i - 1] || last[i] > last[i - 1])\n ok3 = false;\n if (ok3)\n ok2 = true;\n }\n if (ok2)\n sum++;\n }\n return sum;\n }\n\n void run() {\n try {\n in = new FastScanner(new File(\"test.in\"));\n out = new PrintWriter(new File(\"test.out\"));\n\n solve();\n\n out.close();\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n\n void runIO() {\n in = new FastScanner(System.in);\n out = new PrintWriter(System.out);\n\n solve();\n\n out.close();\n }\n\n class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(File f) {\n try {\n br = new BufferedReader(new FileReader(f));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n\n public FastScanner(InputStream f) {\n br = new BufferedReader(new InputStreamReader(f));\n }\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return null;\n st = new StringTokenizer(s);\n }\n return st.nextToken();\n }\n\n boolean hasMoreTokens() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return false;\n st = new StringTokenizer(s);\n }\n return true;\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n }\n\n public static void main(String[] args) {\n new CF().runIO();\n }\n}", "lang_cluster": "Java", "tags": ["dp", "combinatorics"], "code_uid": "571f8fca400e56135ed7be63aff98a7d", "src_uid": "9ca1ad2fa16ca81e9ab5eba220b162c1", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.io.PrintWriter;\nimport java.util.TreeMap;\npublic class E1113 \n{\n static class QN{\n int index;\n long sum;\n QN(int in,long an){\n index=in;\n sum=an;\n }\n }\n static class SegmentTree{\n long sum,pmin,lazy;\n int st,en;\n boolean rem;\n SegmentTree left,right;\n SegmentTree(int _st,int _en,long _v){\n st=_st;\n en=_en;\n lazy=_v;\n rem=true;\n sum=(en-st+1)*lazy;\n pmin=Math.min(lazy,sum);\n }\n long pmin(){\n return rem?(Math.min(lazy,(en-st+1)*lazy)):(pmin);\n }\n long sum(){\n return rem?((en-st+1)*lazy):(sum);\n }\n void update(int l,int r,long v){\n //completely outside\n if(l>en||r=en){\n //update lazy;\n lazy=v;\n rem=true;\n return;\n }\n //partial cover\n lazyPropagate();\n left.update(l, r, v);\n right.update(l, r, v);\n sum=left.sum()+right.sum();\n pmin=Math.min(left.pmin(),left.sum()+right.pmin());\n return;\n }\n void lazyPropagate(){\n if(left==null){\n int mid=(st+en)/2;\n left=new SegmentTree(st,mid,lazy);\n right=new SegmentTree(mid+1,en,lazy);\n }else if(rem){\n left.lazy=lazy;\n right.lazy=lazy;\n left.rem=true;\n right.rem=true;\n }\n if(rem){\n sum=left.sum()+right.sum();\n pmin=Math.min(left.pmin(),left.sum()+right.pmin());\n }\n rem=false;\n }\n /**returns least index which has value <= given value**/\n QN query(int l,int r,long v,long su){\n //no cover\n if(st>r||en mp=new TreeMap<>();\n mp.put(0,0);\n mp.put(1000000001,0);\n while(q--!=0){\n int tp=in.nextInt();\n switch(tp){\n case 1:\n int tm=in.nextInt();\n int vl=in.nextInt();\n int nxt=mp.higherKey(tm)-1;\n st.update(tm, nxt, vl);\n mp.put(tm,vl);\n break;\n case 2:\n int tc=in.nextInt();\n int vp=mp.lowerEntry(tc).getValue();\n int net=mp.higherKey(tc)-1;\n st.update(tc, net, vp);\n mp.remove(tc);\n break;\n case 3:\n int l=in.nextInt();\n int lc=l;\n l=mp.ceilingKey(l);\n int r=in.nextInt();\n int v=in.nextInt();\n if(v==0){\n out.println(lc);\n continue;\n }\n if(l>=r){\n out.println(-1);\n continue;\n }\n QN aa=st.query(l, r-1, -v, 0);\n if(aa.index==-1)\n out.println(-1);\n else{\n int spd=mp.floorEntry(aa.index).getValue();\n double remv=-(v+(aa.sum-spd));\n double anss=aa.index;\n anss+=remv/spd;\n out.println(anss);\n \n }\n \n }\n \n }\n out.close();\n }\n\n}\n", "lang_cluster": "Java", "tags": ["data structures"], "code_uid": "8440e84a1a8b382c43db00f1d61019f3", "src_uid": "23440d055baf6c831e91e76b99b9ada8", "difficulty": 2800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigDecimal;\nimport java.math.MathContext;\nimport java.math.RoundingMode;\nimport java.text.DecimalFormat;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class d {\n static double EPS = 1e-6 ;\n public static void main(String[] args) {\n FS in = new FS(System.in);\n PrintWriter out = new PrintWriter(System.out);\n \n int n = in.nextInt();\n \n Vec com = new Vec(0, 0);\n Vec[] vecs = new Vec[n];\n for(int i = 0; i < n; i++) {\n com = com.add(vecs[i] = new Vec(in.nextInt(), in.nextInt()));\n }\n com = com.scaleR(n);\n \n boolean[] works = new boolean[n];\n Arrays.fill(works, true);\n int num = n;\n for(int i = 0; i < n; i++) {\n if(vecs[i].equals(com)) {\n works[i] = false;\n num--;\n continue;\n }\n for(int j = 0; j < i; j++) {\n if(works[j] && vecs[i].sub(com).equals(com.sub(vecs[j]))) {\n works[i] = works[j] = false;\n num -= 2;\n break;\n }\n }\n }\n Vec[] act = new Vec[num];\n int curr = 0;\n for(int i = 0; i < n; i++) if(works[i]) act[curr++] = vecs[i];\n n = num;\n if(n == 0) {\n System.out.println(-1);\n return;\n }\n int res = 0;\n \n Vec[] norms = new Vec[n];\n \n outer: for(int i = 0; i < n; i++) {\n Vec diff = act[i].sub(act[0]);\n Vec mid = act[0].add(diff.scaleR(2));\n Vec perp = com.sub(mid).rot90();\n if(perp.equals(new Vec(0, 0))) continue;\n Vec norm = perp;\n norm = norm.scaleR(Math.sqrt(norm.dot(norm)));\n if(norm.x < 0 || (eq(norm.x, 0) && norm.y < 0)) {\n norm.x *= -1;\n norm.y *= -1;\n }\n norms[i] = norm;\n for(int j = 0; j < i; j++) {\n if(norms[j].equals(norm)) continue outer;\n }\n double[] arr = new double[n];\n for(int j = 0; j < n; j++) arr[j] = perp.dot(act[j]);\n Arrays.sort(arr);\n double cent = (arr[0]+arr[n-1])/2;\n for(int j = 0; j < n; j++) {\n if(!eq(cent-arr[j], arr[n-1-j]-cent)) continue outer;\n }\n res++;\n }\n System.out.println(res);\n out.close();\n }\n \n static class Vec {\n double x, y;\n \n public Vec(double A, double B) {\n x = A;\n y = B;\n }\n \n public Vec add(Vec o) {\n return new Vec(x+o.x, y+o.y);\n }\n \n public Vec sub(Vec o) {\n return new Vec(x-o.x, y-o.y);\n }\n \n public Vec scale(double s) {\n return new Vec(x*s, y*s);\n }\n \n public Vec scaleR(double s) {\n return new Vec(x/s, y/s);\n }\n \n public Vec rot90() {\n return new Vec(-y, x);\n }\n \n public double dot(Vec o) {\n return x*o.x + y*o.y;\n }\n \n @Override\n public boolean equals(Object o) {\n return eq(x, ((Vec)o).x) && eq(y, ((Vec)o).y);\n }\n }\n \n static boolean eq(double a, double b) {\n return Math.abs(a-b) <= EPS;\n }\n \n static class FS {\n BufferedReader in;\n StringTokenizer token;\n \n public FS(InputStream str) {\n in = new BufferedReader(new InputStreamReader(str));\n }\n \n public String next() {\n if(token == null || !token.hasMoreElements()) {\n try {\n token = new StringTokenizer(in.readLine());\n } catch (IOException ex) {\n }\n return next();\n }\n return token.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}", "lang_cluster": "Java", "tags": ["geometry"], "code_uid": "272bc5cae4d663ef5a8f8defb4de1ef9", "src_uid": "5d7ba962400c05433ee17c5658888e69", "difficulty": 2900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\npublic class D {\n static ArrayList[] adj;\n static ArrayList[] rev;\n static BufferedReader in;\n static StringTokenizer st;\n\n static class pr implements Comparable {\n int v;\n\n pr(int x) {\n v = x;\n }\n\n @Override\n public int compareTo(pr o) {\n if (o.v == v) return 0;\n if (d[o.v] < d[v]) return 1;\n return -1;\n }\n }\n\n static int d[];\n\n public static void main(String[] args) throws IOException {\n in = new BufferedReader(new InputStreamReader(System.in));\n fp();\n int n = nextInt();\n int m = nextInt();\n adj = new ArrayList[n];\n rev = new ArrayList[n];\n for (int i = 0; i < n; i++) {\n adj[i] = new ArrayList();\n rev[i] = new ArrayList();\n }\n for (int i = 0; i < m; i++) {\n fp();\n int a = nextInt() - 1;\n int b = nextInt() - 1;\n adj[a].add(b);\n rev[b].add(a);\n }\n fp();\n int k = nextInt();\n int ms[] = new int[k];\n fp();\n for (int i = 0; i < k; i++) {\n ms[i] = nextInt() - 1;\n }\n int fn = ms[k - 1];\n d = new int[n];\n int inf = 1000_000_000;\n for (int i = 0; i < n; i++) {\n d[i] = inf;\n }\n d[fn] = 0;\n TreeSet set = new TreeSet();\n set.add(new pr(fn));\n while (!set.isEmpty()) {\n pr tk = set.first();\n set.remove(tk);\n for (int i = 0; i < rev[tk.v].size(); i++) {\n int to = (int) rev[tk.v].get(i);\n if (d[to] > d[tk.v] + 1) {\n set.remove(new pr(to));\n d[to] = d[tk.v] + 1;\n set.add(new pr(to));\n }\n }\n }\n int mn = 0;\n int mx = 0;\n for (int i = 0; i < k - 1; i++) {\n if (d[ms[i]] == d[ms[i + 1]] + 1) {\n for (int j = 0; j < adj[ms[i]].size(); j++) {\n int to = (int) adj[ms[i]].get(j);\n if (to != ms[i + 1]) {\n if (d[to] + 1 == d[ms[i]]) {\n mx++;\n break;\n }\n }\n }\n } else {\n mn++;\n mx++;\n }\n }\n System.out.println(mn + \" \" + mx);\n }\n\n private static void fp() throws IOException {\n st = new StringTokenizer(in.readLine());\n }\n\n private static int nextInt() {\n return Integer.parseInt(st.nextToken());\n }\n}\n", "lang_cluster": "Java", "tags": ["shortest paths", "graphs"], "code_uid": "5aa16dafcd108bbc5b059007a7cc7700", "src_uid": "19a0c05eb2d1559ccfe60e210c6fcd6a", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.*;\npublic class f {\npublic static void main(String[] args)\n{\n Scanner input = new Scanner(System.in);\n long a = input.nextLong(), b = input.nextLong();\n int k = input.nextInt();\n int lcm = 1;\n for(int i = 2; i<=k; i++) lcm = lcm(lcm, i);\n int[] dp = new int[2*lcm];\n int start = (int)(a%lcm) + lcm;\n Arrays.fill(dp, 987654321);\n dp[start] = 0;\n for(int i = start; i>0; i--)\n {\n dp[i-1] = Math.min(dp[i-1], dp[i]+1);\n for(int j = 2; j<=k; j++)\n {\n int next = i - i%j;\n if(next >= 0) dp[next] = Math.min(dp[next], dp[i]+1);\n }\n }\n long res = 0;\n if(a-b >= lcm)\n {\n res = dp[lcm];\n a -= (a%lcm);\n }\n //System.out.println(dp[0]+\" \"+dp[lcm]);\n int lcmStep = dp[0]-dp[lcm];\n //System.out.println(lcm+\" \"+lcmStep);\n \n long numSteps = (a-b)/lcm - 2;\n if(numSteps > 0)\n {\n a -= lcm*numSteps;\n res += lcmStep*numSteps;\n }\n \n dp = new int[5*lcm];\n int end = (int)(b - lcm*(b/lcm));\n start = (int)(end + a - b);\n //System.out.println(start+\" \"+end);\n Arrays.fill(dp, 987654321);\n dp[start] = 0;\n for(int i = start; i>end; i--)\n {\n dp[i-1] = Math.min(dp[i-1], dp[i]+1);\n for(int j = 2; j<=k; j++)\n {\n int next = i - i%j;\n if(next > 0) dp[next] = Math.min(dp[next], dp[i]+1);\n }\n }\n \n res += dp[end];\n \n System.out.println(res);\n}\nstatic int lcm(int a, int b)\n{\n return a/gcd(a,b)*b;\n}\nstatic int gcd(int a, int b)\n{\n if(b==0) return a;\n return gcd(b, a%b);\n}\n}\n", "lang_cluster": "Java", "tags": ["dp", "number theory"], "code_uid": "7e4b198239bf65ef7c532e9127a14555", "src_uid": "bd599d76c83cc1f30c1349ffb51b4273", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.io.*;\nimport static java.lang.Math.*;\nimport java.math.*;\n\npublic class Main implements Runnable {\n\tBufferedReader in;\n\tPrintStream out; \n\tStringTokenizer st = new StringTokenizer(\"\");\n\tdouble eps = 1e-9;\n\t\n\tpublic static void main(String [] args) throws Exception {\n\t\tnew Thread(new Main()).start();\n\t}\n\n\tvoid printExit(String s) {\n\t\tSystem.out.println(s);\n\t\tSystem.exit(0);\n\t}\n\n\tPoint readPoint() {\n\t\treturn new Point(nextDouble(), nextDouble());\n\t}\n\n\n\tclass Point {\n\t\tdouble x, y;\n\n\t\tPoint (double x, double y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\n\t\tPoint subtract(Point rhs) {\n\t\t\treturn new Point(x - rhs.x, y - rhs.y);\n\t\t}\n\n\t\tPoint add(Point rhs) {\n\t\t\treturn new Point(x + rhs.x, y + rhs.y);\n\t\t}\n\n\t\tPoint rotate() {\n\t\t\treturn new Point(-y, x);\n\t\t}\n\n\t\tdouble len() {\n\t\t\treturn hypot(x, y);\n\t\t}\n\n\t\tPoint normalize() {\n\t\t\treturn new Point(x / len(), y / len());\n\t\t}\n\n\t\tPoint mult(double c) {\n\t\t\treturn new Point(x * c, y * c);\n\t\t}\n\n\t\t//distance from the line\n\t\tdouble dist(Point X, Point Y) {\n\t\t\tdouble S = abs(square(this, X, Y));\n\t\t\treturn S / X.subtract(Y).len();\n\t\t}\n\n\t\tboolean liesOn(Point X, Point Y) {\n\t\t\tdouble S = abs(square(this, X, Y));\n\t\t\treturn (interon(x, X.x, Y.x) && interon(y, X.y, Y.y) && S < eps);\n\t\t}\n\t}\n\n\tdouble dist(Point X, Point Y) {\n\t\treturn Y.subtract(X).len();\n\t}\n\n\tPoint get(Point X, Point Y, double c) {\n\t\treturn X.add(Y.subtract(X).mult(c));\n\t}\n\n\n\tdouble square(Point a, Point b, Point c) {\n\t\treturn a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y);\n\t}\n\n\tboolean interon(double x1, double x2, double y1, double y2) {\n\t\treturn max(x1, x2) + eps >= min(y1, y2) && max(y1, y2) + eps >= min(x1, x2);\n\t}\n\n\tboolean interon(double x, double x1, double x2) {\n\t\treturn x + eps >= min(x1, x2) && x <= max(x1, x2) + eps;\n\t}\n\t\n\tboolean intersect(Point a1, Point a2, Point b1, Point b2) {\n\t\tdouble s1 = square(a1, b1, b2), s2 = square(a2, b1, b2);\n\t\tdouble s3 = square(b1, a1, a2), s4 = square(b2, a1, a2);\n\t\tif (s1 * s2 < -eps && s3 * s4 < -eps) return true;\n\t\tif (a1.liesOn(b1, b2) || a2.liesOn(b1, b2) || b1.liesOn(a1, a2) || b2.liesOn(a1, a2))\n\t\t\treturn true;\n\t\t//if (abs(s1) < eps && abs(s2) < eps && abs(s3) < eps && abs(s4) < eps)\n\t\t//\treturn interon(a1.x, a2.x, b1.x, b2.x) && interon(a1.y, a2.y, b1.y, b2.y);\n\t\treturn false;\n\t}\n\n\t//STRICT INNER INTERSECTION. it is allowed to have common point or lie on common line\n\tboolean intersectH(Point a1, Point a2, Point b1, Point b2) {\n\t\tdouble s1 = square(a1, b1, b2), s2 = square(a2, b1, b2);\n\t\tdouble s3 = square(b1, a1, a2), s4 = square(b2, a1, a2);\n\t\tif (s1 * s2 < -eps && s3 * s4 < -eps) return true;\n\t\treturn false;\n\t}\n\n\tboolean parallel(Point a1, Point a2, Point b1, Point b2) {\n\t\tdouble s1 = square(a1, b1, b2), s2 = square(a2, b1, b2);\n\t\tdouble s3 = square(b1, a1, a2), s4 = square(b2, a1, a2);\n\t\treturn (abs(s1) < eps && abs(s2) < eps && abs(s3) < eps && abs(s4) < eps);\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tLocale.setDefault(Locale.US);\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintStream(System.out);\n\n\t\t\tPoint V = readPoint(), P = readPoint();\n\t\t\tPoint [] W = new Point[2], M = new Point[2];\n\t\t\tfor (int i = 0; i < 2; i++)\n\t\t\t\tW[i] = readPoint();\n\t\t\tfor (int i = 0; i < 2; i++)\n\t\t\t\tM[i] = readPoint();\n\t\t\t \n\t\t\tif (!intersect(V, P, W[0], W[1])) {\n\t\t\t if (intersect(V, P, M[0], M[1]) && !parallel(V, P, M[0], M[1])) printExit(\"NO\");\n\t\t\t else printExit(\"YES\");\n\t\t\t}\n\t\t\t//now wall is on the V-P path and mirror - not\n\n\t\t\tdouble s1 = square(P, M[0], M[1]), s2 = square(V, M[0], M[1]);\n\t\t\tif (s1 * s2 < eps) printExit(\"NO\");\n\t\t\t//V and P -> strictly by one side of the line\n\n\t\t\tPoint N = M[1].subtract(M[0]).rotate().normalize();\n\t\t\tdouble d = V.dist(M[0], M[1]);\n\t\t\t\n\t\t\t//System.out.println(d);\n\t\t\tPoint MV = V.add(N.mult(2 * d));\n\t\t\tif (!intersect(MV, P, M[0], M[1]))\n\t\t\t\tMV = V.add(N.mult(-2 * d));\n\t\t\tif (!intersect(MV, P, M[0], M[1]))\n\t\t\t\tprintExit(\"NO\");\n\t\t\t\n\t\t\tdouble l = 0, r = 1;\n\t\t\tfor (int i = 0; i < 200; i++) {\n\t\t\t\tdouble m1 = (2 * l + r) / 3, m2 = (l + 2 * r) / 3;\n\t\t\t\tPoint M1 = get(M[0], M[1], m1), M2 = get(M[0], M[1], m2);\n\t\t\t\tdouble d1 = dist(MV, M1) + dist(P, M1), d2 = dist(MV, M2) + dist(P, M2);\n\t\t\t\tif (d1 > d2) l = m1;\n\t\t\t\t\telse r = m2;\n\t\t\t}\n\n\t\t\tPoint T = get(M[0], M[1], l);\n\t\t\tif (!intersect(P, T, W[0], W[1]) && !intersect(T, V, W[0], W[1])) printExit(\"YES\");\n\t\t\tprintExit(\"NO\");\n\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\n\t boolean seekForToken() {\n \t\ttry {\n\t\t\twhile (!st.hasMoreTokens()) {\n\t\t\t\tString s = in.readLine();\n\t\t\t\tif (s == null) {\n\t\t\t\t \treturn false;\n\t\t\t\t}\n\t\t\t \tst = new StringTokenizer(s);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t\tcatch (IOException e) {\n\t\t \te.printStackTrace();\n\t\t \treturn false;\n\t\t}\n \t}\n\n \t int nextInt() {\n\t\treturn Integer.parseInt(nextToken());\n \t}\n\n \t long nextLong() {\n\t\treturn Long.parseLong(nextToken());\n \t}\n\n \t double nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n \t}\n\n \t BigInteger nextBigInteger() {\n \t \treturn new BigInteger(nextToken());\n \t}\n\n \t String nextToken() {\n \t \tseekForToken();\n \t \treturn st.nextToken();\n \t}\n\n}\n", "lang_cluster": "Java", "tags": ["geometry", "implementation"], "code_uid": "4ce3f90e595816ef3ea2ffe216b10f29", "src_uid": "7539a41268b68238d644795bccaa0c0f", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author lewin\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n GTakeMetro solver = new GTakeMetro();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class GTakeMetro {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int n = in.nextInt(), m = in.nextInt();\n int s = in.nextInt() - 1;\n long t = in.nextLong();\n while (t % n != 0) {\n if (s < m) {\n s = (int) ((s + t) % n);\n } else {\n s = (int) ((s - t) % n);\n if (s < 0) s += n;\n }\n t--;\n }\n t /= n;\n int[] seen = new int[n];\n Arrays.fill(seen, -1);\n seen[s] = 0;\n int count = 0;\n while (t-- > 0) {\n count++;\n for (int i = n - 1; i >= 1; i--) {\n if (s < m) {\n s = (s + i) % n;\n } else {\n s = (s - i + n) % n;\n }\n }\n if (seen[s] != -1) {\n t %= (count - seen[s]);\n }\n seen[s] = count;\n }\n out.println(s + 1);\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void println(int i) {\n writer.println(i);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1 << 16];\n private int curChar;\n private int numChars;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (this.numChars == -1) {\n throw new InputMismatchException();\n } else {\n if (this.curChar >= this.numChars) {\n this.curChar = 0;\n\n try {\n this.numChars = this.stream.read(this.buf);\n } catch (IOException var2) {\n throw new InputMismatchException();\n }\n\n if (this.numChars <= 0) {\n return -1;\n }\n }\n\n return this.buf[this.curChar++];\n }\n }\n\n public int nextInt() {\n int c;\n for (c = this.read(); isSpaceChar(c); c = this.read()) {\n ;\n }\n\n byte sgn = 1;\n if (c == 45) {\n sgn = -1;\n c = this.read();\n }\n\n int res = 0;\n\n while (c >= 48 && c <= 57) {\n res *= 10;\n res += c - 48;\n c = this.read();\n if (isSpaceChar(c)) {\n return res * sgn;\n }\n }\n\n throw new InputMismatchException();\n }\n\n public long nextLong() {\n int c;\n for (c = this.read(); isSpaceChar(c); c = this.read()) {\n ;\n }\n\n byte sgn = 1;\n if (c == 45) {\n sgn = -1;\n c = this.read();\n }\n\n long res = 0L;\n\n while (c >= 48 && c <= 57) {\n res *= 10L;\n res += (long) (c - 48);\n c = this.read();\n if (isSpaceChar(c)) {\n return res * (long) sgn;\n }\n }\n\n throw new InputMismatchException();\n }\n\n public static boolean isSpaceChar(int c) {\n return c == 32 || c == 10 || c == 13 || c == 9 || c == -1;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["brute force", "graphs", "data structures"], "code_uid": "8048bce96eefea7cb353fa8e0868ce30", "src_uid": "e743242f0cc9e17619e1fe4935d9fbd0", "difficulty": 2900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class d {\n\tpublic static void main(String[] arg) {\n\t\tnew d();\n\t}\n\tpublic d() {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tint[] smallestPrime = new int[n+1];\n\t\tboolean[] isPrime = new boolean[n+1];\n\t\tArrays.fill(isPrime, true);\n\t\tisPrime[0] = isPrime[1] = false;\n\t\tfor(int i = 2; i < isPrime.length; i++) {\n\t\t\tif(isPrime[i]) {\n\t\t\t\tsmallestPrime[i] = i;\n\t\t\t\tfor(int j = i+i; j < isPrime.length; j+=i) {\n\t\t\t\t\tisPrime[j] = false;\n\t\t\t\t\tif(smallestPrime[j] == 0) smallestPrime[j] = i;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong[] numP = new long[n+1];\n\t\tfor(int i = 2; i <= n; i++) {\n\t\t\tnumP[smallestPrime[i]]++; \n\t\t}\n\t\tlong[] cum = new long[n+1];\n\t\tcum[0] = numP[0];\n\t\tfor(int i = 1; i <= n; i++) {\n\t\t\tcum[i] += cum[i-1]+numP[i];\n\t\t}\n\t\tlong count2 = 1L * n * (n - 1) / 2 - (n - 1);\n\t\tlong ans = 0;\n\t\t/*\n\t\tfor(int i = 2; i <= n; i++) {\n\t\t\tint p = smallestPrime[i];\n\t\t\tint other = i/p;\n\t\t\tif(isPrime[other] && other > p) {\n//\t\t\t\tSystem.out.println(i + \" \" + other + \" \" + numP[p] + \" \" + numP[other]);\n\t\t\t\tlong temp = numP[p]*numP[other];\n\t\t\t\tfor(int j = p; j <= n; j+=p) {\n\t\t\t\t\tif(j % other == 0 && smallestPrime[j] == p)\n\t\t\t\t\t\ttemp -= numP[other];\n\t\t\t\t}\n\t\t\t\tans += 2*temp;\n\t\t\t}\n\t\t}*/\n\t\touter:\n\t\tfor(int i = 2; i <= n; i++) {\n\t\t\tlong count = 0;\n\t\t\tint sign = -1;\n\t\t\tint x = i;\n\t\t\twhile(x > 1) {\n\t\t\t\tint y = smallestPrime[x];\n\t\t\t\tx /= y;\n\t\t\t\tif(smallestPrime[x] == y) {\n\t\t\t\t\tcontinue outer;\n\t\t\t\t}\n\t\t\t\tsign *= -1;\n\t\t\t}\n\t\t\tfor(int j = i; j <= n; j += i) {\n\t\t\t\tcount++;\n\t\t\t}\n\t\t\tcount2 -= sign*(count*(count-1)/2);\n\t\t\tans += sign*(count*(count-1)/2);\n\t\t}\n\t\tfor(int i = 2; i <= n; i++) {\n\t\t\tif(!isPrime[i]) continue;\n\t\t\tif(n / 2 <= i) continue;\n\t\t\tlong c = cum[n / 2];\n\t\t\tc -= cum[Math.max(n / i, i)];\n\t\t\tans += numP[i]*c*3;\n\t\t\tcount2 -= numP[i]*c;\n\t\t}\n\t\t//System.err.println(count2);\n\t\tlong numSpec = 0;\n\t\tfor (int i = 2; i <= n; i++) {\n\t\t\tif (smallestPrime[i] * 2 > n) {\n\t\t\t\tnumSpec++;\n\t\t\t}\n\t\t}\n\t\tcount2 -= (n - 2) * numSpec;\n\t\tcount2 += numSpec * (numSpec - 1) / 2;\n\t\t//System.err.println(count2);\n\t\tans += count2 * 2;\n\t\tSystem.out.println(ans);\n\t}\n}\n", "lang_cluster": "Java", "tags": ["sortings", "number theory"], "code_uid": "4167c56d530cbcd7583549a722073c63", "src_uid": "bb1bd5d8bab7d79e514281230d484996", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "//package round49;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\n\npublic class E5 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni(), m = ni(), K = ni();\n\t\tboolean[][] g = new boolean[n][n];\n\t\tfor(int i = 0;i < m;i++){\n\t\t\tint f = ni()-1, t = ni()-1;\n\t\t\tg[f][t] = g[t][f] = true;\n\t\t}\n\t\tint[][] dp = new int[1<= 3 && j > 0)dp[i][j] /= Integer.bitCount(j);\n\t\t\t\t\tfor(int k = 0;k < n;k++){\n\t\t\t\t\t\tif(i<<31-k>=0){\n\t\t\t\t\t\t\tfor(int l = 0;l < n;l++){\n\t\t\t\t\t\t\t\tif(i<<31-l<0 && g[l][k]){\n\t\t\t\t\t\t\t\t\tdp[i|1<= '0' && num <= '9') || num == '-'));\n\t\t\tif(num == '-'){\n\t\t\t\tnum = 0;\n\t\t\t\tminus = true;\n\t\t\t}else{\n\t\t\t\tnum -= '0';\n\t\t\t}\n\t\t\t\n\t\t\twhile(true){\n\t\t\t\tint b = is.read();\n\t\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t}else{\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic long nl()\n\t{\n\t\ttry {\n\t\t\tlong num = 0;\n\t\t\tboolean minus = false;\n\t\t\twhile((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));\n\t\t\tif(num == '-'){\n\t\t\t\tnum = 0;\n\t\t\t\tminus = true;\n\t\t\t}else{\n\t\t\t\tnum -= '0';\n\t\t\t}\n\t\t\t\n\t\t\twhile(true){\n\t\t\t\tint b = is.read();\n\t\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t}else{\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic String ns()\n\t{\n\t\ttry{\n\t\t\tint b = 0;\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\twhile((b = is.read()) != -1 && (b == '\\r' || b == '\\n' || b == ' '));\n\t\t\tif(b == -1)return \"\";\n\t\t\tsb.append((char)b);\n\t\t\twhile(true){\n\t\t\t\tb = is.read();\n\t\t\t\tif(b == -1)return sb.toString();\n\t\t\t\tif(b == '\\r' || b == '\\n' || b == ' ')return sb.toString();\n\t\t\t\tsb.append((char)b);\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn \"\";\n\t}\n\t\n\tpublic char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\ttry{\n\t\t\tint b = 0, p = 0;\n\t\t\twhile((b = is.read()) != -1 && (b == ' ' || b == '\\r' || b == '\\n'));\n\t\t\tif(b == -1)return null;\n\t\t\tbuf[p++] = (char)b;\n\t\t\twhile(p < n){\n\t\t\t\tb = is.read();\n\t\t\t\tif(b == -1 || b == ' ' || b == '\\r' || b == '\\n')break;\n\t\t\t\tbuf[p++] = (char)b;\n\t\t\t}\n\t\t\treturn Arrays.copyOf(buf, p);\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn null;\n\t}\n\t\n\t\n\tdouble nd() { return Double.parseDouble(ns()); }\n\tboolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tvoid tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "tags": ["dp", "bitmasks"], "code_uid": "ede8ff2cb9babdeb7947303188adbd99", "src_uid": "8087605a8f316150372cc4627f26231d", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class TaskF {\n private static final long MOD = 1_000_000_000 + 7;\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n\n int n = in.nextInt();\n int m = in.nextInt();\n\n initFactorials(Math.max(n, m));\n System.out.println(solve(n, m));\n\n in.close();\n }\n\n private static long solve(int n, int m) {\n long sum = 0;\n for (int k = 1; k <= n - 1; k++) {\n long splits = splits(m, k);\n long perms = perms(n, k);\n long rest = rest(n, m, k);\n sum += (((splits * perms) % MOD) * rest) % MOD;\n sum = sum % MOD;\n }\n return sum;\n }\n\n private static long splits(int sum, int count) {\n return modCombinations(sum - 1, count - 1);\n }\n\n private static long perms(int n, int k) {\n return modKPermutations(n - 2, k - 1);\n }\n\n private static long rest(int n, int m, int k) {\n return (modNumberOfTrees(n, k + 1) * modPower(m, n - 1 - k)) % MOD;\n }\n\n private static long modNumberOfTrees(int n, int y) {\n if (n < y) {\n return 0;\n } else if (n == y) {\n return 1;\n } else {\n return (y * modPower(n, n - y - 1)) % MOD;\n }\n }\n\n private static long[] factorial;\n private static long[] inverse;\n private static long[] inverseFactorial;\n\n private static void initFactorials(int upTo) {\n factorial = new long[upTo + 1];\n inverse = new long[upTo + 1];\n inverseFactorial = new long[upTo + 1];\n factorial[0] = 1;\n factorial[1] = 1;\n for (int i = 2; i <= upTo; i++) {\n factorial[i] = (factorial[i - 1] * i) % MOD;\n }\n inverse[0] = 1;\n inverse[1] = 1;\n for (int i = 2; i <= upTo; i++) {\n inverse[i] = (MOD - (MOD / i) * inverse[(int)MOD % i] % MOD) % MOD;\n }\n inverseFactorial[0] = inverse[0];\n for (int i = 1; i <= upTo; i++) {\n inverseFactorial[i] = (inverseFactorial[i - 1] * inverse[i]) % MOD;\n }\n }\n\n private static long modKPermutations(int n, int k) {\n if (n < k) return 0;\n return (factorial[n] * inverseFactorial[n - k]) % MOD;\n }\n\n private static long modCombinations(int n, int k) {\n if (n < k) return 0;\n return (((factorial[n] * inverseFactorial[k]) % MOD) * inverseFactorial[n - k]) % MOD;\n }\n\n private static long modPower(int n, int p) {\n if (p == 0) {\n return 1;\n } else if (p % 2 == 1) {\n return (n * modPower(n, p - 1)) % MOD;\n } else {\n long halfPower = modPower(n, p / 2);\n return (halfPower * halfPower) % MOD;\n }\n }\n\n private static long modRestoreFactorMapToNumber(Map factorMap) {\n long result = 1;\n for (int prime : factorMap.keySet()) {\n result = (result * modPower(prime, factorMap.get(prime))) % MOD;\n }\n return result;\n }\n\n private static class MapTools {\n public Map subtractCounts(\n Map a, Map b) {\n\n Map result = new HashMap<>(a);\n\n for (int bKey : b.keySet()) {\n if (!result.containsKey(bKey)) {\n throw new RuntimeException(\"No such key: \" + bKey);\n }\n result.put(bKey, result.get(bKey) - b.get(bKey));\n }\n\n return result;\n }\n }\n\n private static class Primes {\n private final List primes = new ArrayList<>();\n private int primesLimit;\n\n private final Map> factorialFactorizationCache = new HashMap<>();\n public Map factorFactorial(int n) {\n return factorialFactorizationCache.computeIfAbsent(n, $ -> {\n calculatePrimesUpTo(n);\n Map result = new HashMap<>();\n for (int p : primes) {\n if (p > n) break;\n int count = 0;\n int pPower = p;\n while (pPower <= n) {\n count += n / pPower;\n pPower *= p;\n }\n result.put(p, count);\n }\n return result;\n });\n }\n\n private void calculatePrimesUpTo(int newLimit) {\n if (newLimit <= primesLimit) return;\n\n int start = primesLimit + 1;\n if (start <= 2) {\n start = 2;\n }\n for (int i = start; i <= newLimit; i++) {\n if (isPrime(i)) {\n primes.add(i);\n }\n }\n\n primesLimit = newLimit;\n }\n\n private boolean isPrime(int n) {\n for (int p : primes) {\n if (p * p > n) break;\n if (n % p == 0) return false;\n }\n return true;\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["dp", "combinatorics", "trees"], "code_uid": "389dc854e306c7c7bad3ef548ab49786", "src_uid": "728fe302b8b18e33f15f6e702e332cde", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.List;\nimport java.util.StringTokenizer;\n\n/**\n * @author Don Li\n */\npublic class WrapAround3 {\n \n int N = 41;\n \n int n, m;\n char[] s;\n \n int[] f;\n List[][] prev = new List[N][2];\n int[][] next = new int[N][2];\n \n long[][] dp = new long[N][N];\n long[][] ep = new long[N][N];\n \n void solve() {\n n = in.nextInt();\n s = in.nextToken().toCharArray();\n m = s.length;\n \n f = fail(s);\n \n for (int i = 0; i < N; i++) for (int j = 0; j < 2; j++) prev[i][j] = new ArrayList<>();\n for (int i = 0; i <= m; i++) {\n for (int x = 0; x <= 1; x++) {\n int j = getNext(i, (char) (x + '0'));\n prev[j][x].add(i);\n next[i][x] = j;\n }\n }\n \n long ans = 0;\n for (int i = 0; i < N; i++) Arrays.fill(dp[i], -1);\n for (int i = 0; i < N; i++) Arrays.fill(ep[i], -1);\n for (int i = 0; i <= m; i++) {\n for (int pos = 0; pos < n; pos++) {\n ans += f(pos + 1, i) * g(n - pos - 1, i);\n }\n }\n out.println(ans);\n }\n \n long f(int n, int cur) {\n if (n == 0) return cur == m ? 1 : 0;\n if (dp[n][cur] >= 0) return dp[n][cur];\n long res = 0;\n for (int i = 0; i <= 1; i++) {\n int nxt = next[cur][i];\n if (n - 1 > 0 && nxt == m) continue; \n res += f(n - 1, nxt);\n }\n return dp[n][cur] = res;\n }\n \n long g(int n, int cur) {\n if (n == 0) return cur == m ? 1 : 0;\n if (ep[n][cur] >= 0) return ep[n][cur];\n long res = 0;\n for (int i = 0; i <= 1; i++) {\n for (int nxt : prev[cur][i]) {\n res += g(n - 1, nxt);\n }\n }\n return ep[n][cur] = res;\n }\n \n int getNext(int now, char x) {\n if (now == m) now = f[now];\n while (now > 0 && s[now] != x) now = f[now];\n return s[now] == x ? now + 1 : 0;\n }\n \n int[] fail(char[] s) {\n int n = s.length;\n int[] f = new int[n + 1];\n f[0] = f[1] = 0;\n for (int i = 2; i <= n; i++) {\n int j = f[i - 1];\n while (j > 0 && s[j] != s[i - 1]) j = f[j];\n f[i] = s[j] == s[i - 1] ? j + 1 : 0;\n }\n return f;\n }\n \n public static void main(String[] args) {\n in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));\n out = new PrintWriter(System.out);\n new WrapAround3().solve();\n out.close();\n }\n \n static FastScanner in;\n static PrintWriter out;\n \n static class FastScanner {\n BufferedReader in;\n StringTokenizer st;\n \n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n \n public String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["strings", "dp"], "code_uid": "3fe350af3a357e0fbd9c2352cf232beb", "src_uid": "0034806908c9794086736a2d07fc654c", "difficulty": 2900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "//package educational.round07;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class FX {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\tint mod = 1000000007;\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni(), K = ni();\n\t\tlong[] vals = new long[K+3];\n\t\tfor(int i = 1;i <= K+2;i++){\n\t\t\tvals[i] = pow(i, K, mod);\n\t\t}\n\t\tif(n <= K+2){\n\t\t\tlong s = 0;\n\t\t\tfor(int i = 1;i <= n;i++){\n\t\t\t\ts += vals[i];\n\t\t\t}\n\t\t\tout.println(s%mod);\n\t\t}else{\n\t\t\tfor(int i = 2;i <= K+2;i++){\n\t\t\t\tvals[i] += vals[i-1];\n\t\t\t\tif(vals[i] >= mod)vals[i] -= mod;\n\t\t\t}\n\t\t\tint[][] fif = enumFIF(K+3, mod);\n\t\t\tlong mul = 1;\n\t\t\tfor(int i = 1;i <= K+2;i++){\n\t\t\t\tmul = mul * (n-i)%mod;\n\t\t\t}\n\t\t\tlong s = 0;\n\t\t\tlong sig = 1;\n\t\t\tlong big = 8L*mod*mod;\n\t\t\tfor(int i = K+2;i >= 1;i--){\n\t\t\t\ts += invl(n-i, mod) * fif[1][i-1] % mod * fif[1][K+2-i] % mod * vals[i] * sig;\n\t\t\t\tif(s >= big)s -= big;\n\t\t\t\tif(s <= -big)s += big;\n\t\t\t\tsig = -sig;\n\t\t\t}\n\t\t\ts %= mod;\n\t\t\tif(s < 0)s += mod;\n\t\t\ts = s * mul % mod;\n\t\t\tout.println(s);\n\t\t}\n\t}\n\t\n\tpublic static long pow(long a, long n, long mod) {\n\t\t//\t\ta %= mod;\n\t\tlong ret = 1;\n\t\tint x = 63 - Long.numberOfLeadingZeros(n);\n\t\tfor (; x >= 0; x--) {\n\t\t\tret = ret * ret % mod;\n\t\t\tif (n << 63 - x < 0)\n\t\t\t\tret = ret * a % mod;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tpublic static long invl(long a, long mod) {\n\t\tlong b = mod;\n\t\tlong p = 1, q = 0;\n\t\twhile (b > 0) {\n\t\t\tlong c = a / b;\n\t\t\tlong d;\n\t\t\td = a;\n\t\t\ta = b;\n\t\t\tb = d % b;\n\t\t\td = p;\n\t\t\tp = q;\n\t\t\tq = d - c * q;\n\t\t}\n\t\treturn p < 0 ? p + mod : p;\n\t}\n\t\n\tpublic static int[][] enumFIF(int n, int mod) {\n\t\tint[] f = new int[n + 1];\n\t\tint[] invf = new int[n + 1];\n\t\tf[0] = 1;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tf[i] = (int) ((long) f[i - 1] * i % mod);\n\t\t}\n\t\tlong a = f[n];\n\t\tlong b = mod;\n\t\tlong p = 1, q = 0;\n\t\twhile (b > 0) {\n\t\t\tlong c = a / b;\n\t\t\tlong d;\n\t\t\td = a;\n\t\t\ta = b;\n\t\t\tb = d % b;\n\t\t\td = p;\n\t\t\tp = q;\n\t\t\tq = d - c * q;\n\t\t}\n\t\tinvf[n] = (int) (p < 0 ? p + mod : p);\n\t\tfor (int i = n - 1; i >= 0; i--) {\n\t\t\tinvf[i] = (int) ((long) invf[i + 1] * (i + 1) % mod);\n\t\t}\n\t\treturn new int[][] { f, invf };\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception { new FX().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tprivate int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "3e8a704990721ed79774a4f6cc052cdd", "src_uid": "6f6fc42a367cdce60d76fd1914e73f0c", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class D {\n\n public void solve() {\n int n = in.nextInt();\n for (int i = 0; i < n; i++) {\n String s = in.nextToken().substring(4);\n out.println(getAns(s));\n }\n }\n\n private long getAns(String s) {\n long cur = 1988;\n for (int j = s.length() - 1; j >= 0; j--) {\n long last = 0, pow = 1;\n for (int t = j; t < s.length(); t++) {\n last = last * 10 + s.charAt(t) - '0';\n pow *= 10;\n }\n\n if (cur % pow < last) {\n cur = (cur / pow) * pow + last;\n } else {\n cur = (cur / pow + 1) * pow + last;\n }\n }\n return cur;\n }\n\n public void run() {\n in = new FastScanner();\n out = new PrintWriter(System.out);\n solve();\n out.close();\n }\n\n FastScanner in;\n PrintWriter out;\n\n class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(String fileName) {\n try {\n br = new BufferedReader(new FileReader(fileName));\n } catch (FileNotFoundException e) {\n }\n }\n\n public FastScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String nextToken() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n\n public static void main(String[] args) {\n new D().run();\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "greedy", "constructive algorithms", "implementation"], "code_uid": "cade6556e7e5fad4e55b1d1d4cc1fc61", "src_uid": "31be4d38a8b5ea8738a65bfee24a5a21", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Codeforces979E {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tint n = Integer.parseInt(st.nextToken());\n\t\tint p = Integer.parseInt(st.nextToken());\n\t\tint[] c = new int[n];\n\t\tst = new StringTokenizer(br.readLine());\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tc[i] = Integer.parseInt(st.nextToken());\n\t\t}\n\t\t\n\t\t//list of powers of 2 until 2^{n^2}, mod 1000000007\n\t\tint[] twopower = new int[n*n+1];\n\t\ttwopower[0] = 1;\n\t\tfor (int i = 1; i <= n*n; i++) {\n\t\t\ttwopower[i] = (2*twopower[i-1])%1000000007;\n\t\t}\n\t\t\n\t\t//Pascal's triangle until n choose k, mod 1000000007\n\t\tint[][] pascal = new int[n+1][n+1];\n\t\tfor (int i = 0; i <= n; i++) {\n\t\t\tpascal[i][0] = 1;\n\t\t\tpascal[0][i] = 1;\n\t\t}\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tfor (int j = 1; j <= n; j++) {\n\t\t\t\tpascal[i][j] = (pascal[i][j-1]+pascal[i-1][j])%1000000007;\n\t\t\t}\n\t\t}\n\t\t\n\t\t//dp[x][y][z] means the last x have all arrows intact\n\t\t//and there are y 0's and z 1's at the start with no\n\t\t//arrows going between them.\n\t\t//we only care when 0 <= x+y+z <= n.\n\t\t//answer is dp[n][0][0].\n\t\tint[][][] dp = new int[n+1][n+1][n+1];\n\t\t//base case of x = 0\n\t\tfor (int y = 0; y <= n; y++) {\n\t\t\tfor (int z = 0; z <= (n-y); z++) {\n\t\t\t\tif (p == (y+z)%2) {\n\t\t\t\t\tdp[0][y][z] = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (int x = 1; x <= n; x++) {\n\t\t\tfor (int y = 0; y <= (n-x); y++) {\n\t\t\t\tfor (int z = 0; z <= (n-x-y); z++) {\n\t\t\t\t\tif (c[n-x] != 1) {\n\t\t\t\t\t\tint evenmultiple;\n\t\t\t\t\t\tint oddmultiple;\n\t\t\t\t\t\tif (z == 0) {\n\t\t\t\t\t\t\tevenmultiple = 1;\n\t\t\t\t\t\t\toddmultiple = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tevenmultiple = twopower[z-1];\n\t\t\t\t\t\t\toddmultiple = twopower[z-1];\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlong evenk = (long) evenmultiple * (long) dp[x-1][y+1][z];\n\t\t\t\t\t\tevenk %= 1000000007;\n\t\t\t\t\t\tlong oddk = (long) oddmultiple * (long) dp[x-1][y][z];\n\t\t\t\t\t\toddk %= 1000000007;\n\t\t\t\t\t\toddk *= (long) twopower[x-1];\n\t\t\t\t\t\toddk %= 1000000007;\n\t\t\t\t\t\tlong totalk = evenk+oddk;\n\t\t\t\t\t\ttotalk *= twopower[y];\n\t\t\t\t\t\ttotalk %= 1000000007;\n\t\t\t\t\t\tdp[x][y][z] += (int) totalk;\n\t\t\t\t\t}\n\t\t\t\t\tif (c[n-x] != 0) {\n\t\t\t\t\t\tint evenmultiple;\n\t\t\t\t\t\tint oddmultiple;\n\t\t\t\t\t\tif (y == 0) {\n\t\t\t\t\t\t\tevenmultiple = 1;\n\t\t\t\t\t\t\toddmultiple = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tevenmultiple = twopower[y-1];\n\t\t\t\t\t\t\toddmultiple = twopower[y-1];\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlong evenk = (long) evenmultiple * (long) dp[x-1][y][z+1];\n\t\t\t\t\t\tevenk %= 1000000007;\n\t\t\t\t\t\tlong oddk = (long) oddmultiple * (long) dp[x-1][y][z];\n\t\t\t\t\t\toddk %= 1000000007;\n\t\t\t\t\t\toddk *= (long) twopower[x-1];\n\t\t\t\t\t\toddk %= 1000000007;\n\t\t\t\t\t\tlong totalk = evenk+oddk;\n\t\t\t\t\t\ttotalk *= twopower[z];\n\t\t\t\t\t\ttotalk %= 1000000007;\n\t\t\t\t\t\tdp[x][y][z] += (int) totalk;\n\t\t\t\t\t}\n\t\t\t\t\tdp[x][y][z] %= 1000000007;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tpw.println(dp[n][0][0]);\n\t\t\n\t\tpw.close();\n\t}\n}\n", "lang_cluster": "Java", "tags": ["dp"], "code_uid": "ebc57fb28654ca1bcb3a0a4ae117cf5b", "src_uid": "aaf5f8afa71d9d25ebab405dddec78cd", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class P256D {\n\n final int [][] r = {{0},\n {2, 1},\n {32, 30, 80, 109},\n {6824, 59808, 147224, 415870, 1757896, 1897056, 4898872, 7593125},\n {776830421, 290516100, 746623577, 293783147, 33900006, 735127505, 565460332, 428982705,\n 472062098, 161873957, 117354594, 515619293, 578944191, 312106242, 569389279, 391464593},\n {261086313, 584837659, 683961846, 468868529, 211593382, 736955478, 229471758, 157617135,\n 398169441, 360252438, 629394768, 264125799, 647490480, 342079395, 391579767, 225200475,\n 486011304, 513156108, 628771752, 132906648, 142138221, 20119449, 444199674, 195188679,\n 387329805, 44684703, 651912135, 737154512, 612549793, 519860281, 186175544, 212568440},\n {240805271, 239509872, 581127897, 6511239, 156126222, 509425833, 672407328, 366667722,\n 459185405, 509737025, 554790222, 165216555, 703150560, 74806569, 398730015, 383350905,\n 506108358, 51326142, 298053147, 104256117, 391428765, 374020479, 206607807, 87664059,\n 275899176, 56407680, 551553401, 448939463, 582889860, 129676638, 226078251, 135769095,\n 61292868, 578972226, 190181628, 390739055, 184587732, 446575689, 732674124, 232198470,\n 676760679, 352474101, 611444862, 575661807, 628905585, 320813094, 522840969, 469781928,\n 156006018, 554473341, 239654268, 643714911, 433540170, 199307003, 496385218, 291740751,\n 67309914, 370826673, 202356819, 279421821, 421203111, 63744786, 520987612, 550671827},\n {482164403, 768209115, 462063756, 154906374, 36099042, 341766705, 678182556, 621882744,\n 478771358, 231881111, 175889805, 243630450, 168908523, 671961765, 55761813, 652682670,\n 773939082, 517628076, 756201264, 124604900, 750976272, 498253248, 676047609, 137170026,\n 705610017, 495032139, 561797418, 703097347, 500815609, 95984586, 739707108, 265613565,\n 387099846, 777331779, 594676173, 591219559, 407997044, 208947235, 93337440, 478908360,\n 685013007, 487033953, 671903001, 39521181, 738490312, 33785059, 465470131, 310453920,\n 54648783, 346831137, 427694175, 474743430, 705296781, 435828036, 429824745, 663532359,\n 261388683, 244690731, 533997135, 596108961, 506813013, 371892402, 590145264, 104733162,\n 143420103, 654339672, 700348950, 685038942, 578826927, 286484229, 501639192, 434962491,\n 299270097, 27702486, 335375775, 111746817, 565603164, 294926121, 676063665, 735862995,\n 710035809, 437011960, 668528077, 138765186, 508213986, 615036450, 353784942, 624827616,\n 343900011, 241289776, 52410890, 72018835, 352406796, 415705878, 4802637, 376367145,\n 65589678, 333633477, 341834527, 303717460, 282387700, 42951006, 254706039, 423048528,\n 526429710, 68131467, 669954708, 12787348, 500636381, 317959019, 479433192, 657133515,\n 416259390, 610216692, 340129188, 44594256, 257373347, 138718678, 530767740, 292922628,\n 37220268, 605295159, 480722613, 458170419, 30540300, 487159055, 232966794, 149150650},\n {412133651, 386543325, 139952108, 289303402, 102404925, 317067177, 396414708, 80515854,\n 663739304, 317300809, 228877044, 493725043, 715317967, 490300965, 315527373, 743539734,\n 488329191, 553627998, 533025234, 242583957, 706116537, 614109258, 645447222, 523195911,\n 492109128, 722623041, 111085128, 766395126, 654378921, 691964847, 496688157, 399056049,\n 654363234, 102052314, 191720088, 473910948, 259736526, 332840025, 388047555, 665791056,\n 627111387, 139696515, 441456687, 443032569, 283264821, 771641703, 452641455, 511306362,\n 117572859, 127701891, 721298331, 176520078, 357242229, 611296308, 696994956, 405628839,\n 429224274, 465336054, 695091546, 689828796, 574648641, 351220905, 507964023, 675326610,\n 517248963, 453528621, 220301928, 494463186, 681789969, 339589656, 44524053, 417125457,\n 339589404, 747135963, 341780733, 734158215, 396817281, 21997836, 5728464, 147611205,\n 456248898, 714128667, 377654949, 3862068, 128418948, 589390074, 304947090, 11703825,\n 228266073, 127304142, 429215724, 361541124, 521572968, 468358191, 341231688, 65323503,\n 613778508, 15985323, 291661029, 410970006, 591638112, 349541550, 89967528, 224922159,\n 361094166, 584206074, 640051812, 324264456, 652625388, 693768537, 11740617, 309238398,\n 211085469, 194905872, 639416484, 110110707, 296645895, 748118511, 131177718, 511142751,\n 775975599, 421403409, 475528473, 434685258, 1768977, 80301375, 708023862, 569195676,\n 56238084, 632887668, 88089750, 631539342, 396695565, 38780154, 695798271, 469819224,\n 439587099, 69045921, 682966116, 112310856, 64943298, 534475872, 40215357, 389728458,\n 286368453, 736006257, 501181650, 54829908, 603489402, 338032656, 512182818, 627500097,\n 462674016, 3103092, 157324491, 43978329, 596818971, 259025598, 9088632, 91991781,\n 577291428, 211245489, 429471231, 142626330, 172560633, 510907446, 444609585, 758102058,\n 375112647, 744786693, 276174402, 19259856, 233672418, 745389414, 225772848, 23385663,\n 324290610, 519804558, 120337812, 402578568, 360676008, 450089262, 551043738, 337388940,\n 512108856, 28879011, 690040638, 106017282, 558262341, 99972432, 608226003, 612152037,\n 42414435, 776201013, 39580443, 518796945, 494437752, 583194366, 723936555, 415359657,\n 309569589, 751104774, 166684527, 249229170, 353120823, 130668327, 753823584, 580966092,\n 561963717, 543672234, 393846327, 586278000, 327398400, 278403867, 156455586, 363920382,\n 190245195, 290039148, 547014447, 466218648, 146037150, 585462906, 666008595, 691786683,\n 374707494, 622498779, 231158277, 685740951, 115612245, 681825249, 545555745, 551718468,\n 277206615, 640171035, 757727334, 195193908, 658656684, 457760646, 225925875, 505761984,\n 18685233, 506832921, 112511021, 396846646, 290147622, 113924623, 669986155, 336008070,\n 63611061, 238586775, 119956662, 616557739, 772784623, 334527774, 410403148, 51933421}\n };\n\n @SuppressWarnings(\"unchecked\")\n public void run() throws Exception {\n synchronized (this) { this.wait(900); }\n println(r[(int)(Math.log(nextInt()) / Math.log(2))][nextInt() - 1]);\n }\n\n public static void main(String... args) throws Exception {\n br = new BufferedReader(new InputStreamReader(System.in));\n pw = new PrintWriter(new BufferedOutputStream(System.out));\n new P256D().run();\n br.close();\n pw.close();\n }\n\n static BufferedReader br;\n static PrintWriter pw;\n StringTokenizer stok;\n\n String nextToken() throws IOException {\n while (stok == null || !stok.hasMoreTokens()) {\n String s = br.readLine();\n if (s == null) { return null; }\n stok = new StringTokenizer(s);\n }\n return stok.nextToken();\n }\n\n void print(byte b) { print(\"\" + b); }\n void print(int i) { print(\"\" + i); }\n void print(long l) { print(\"\" + l); }\n void print(double d) { print(\"\" + d); }\n void print(char c) { print(\"\" + c); }\n void print(Object o) {\n if (o instanceof int[]) { print(Arrays.toString((int [])o));\n } else if (o instanceof long[]) { print(Arrays.toString((long [])o));\n } else if (o instanceof char[]) { print(Arrays.toString((char [])o));\n } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));\n } else if (o instanceof short[]) { print(Arrays.toString((short [])o));\n } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));\n } else if (o instanceof float[]) { print(Arrays.toString((float [])o));\n } else if (o instanceof double[]) { print(Arrays.toString((double [])o));\n } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));\n } else { print(\"\" + o); }\n }\n void print(String s) { pw.print(s); }\n void println() { println(\"\"); }\n void println(byte b) { println(\"\" + b); }\n void println(int i) { println(\"\" + i); }\n void println(long l) { println(\"\" + l); }\n void println(double d) { println(\"\" + d); }\n void println(char c) { println(\"\" + c); }\n void println(Object o) { print(o); println(\"\"); }\n void println(String s) { pw.println(s); }\n int nextInt() throws IOException { return Integer.parseInt(nextToken()); }\n long nextLong() throws IOException { return Long.parseLong(nextToken()); }\n double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }\n char nextChar() throws IOException { return (char) (br.read()); }\n String next() throws IOException { return nextToken(); }\n String nextLine() throws IOException { return br.readLine(); }\n int [] readInt(int size) throws IOException {\n int [] array = new int [size];\n for (int i = 0; i < size; i++) { array[i] = nextInt(); }\n return array;\n }\n long [] readLong(int size) throws IOException {\n long [] array = new long [size];\n for (int i = 0; i < size; i++) { array[i] = nextLong(); }\n return array;\n }\n double [] readDouble(int size) throws IOException {\n double [] array = new double [size];\n for (int i = 0; i < size; i++) { array[i] = nextDouble(); }\n return array;\n }\n String [] readLines(int size) throws IOException {\n String [] array = new String [size];\n for (int i = 0; i < size; i++) { array[i] = nextLine(); }\n return array;\n }\n}", "lang_cluster": "Java", "tags": ["dp"], "code_uid": "400b646939ad08a50104fd789e17c49f", "src_uid": "cfe19131644e5925e32084a581e23286", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/*\n * Author Ayub Subhaniya\n * Institute DA-IICT\n */\n \nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n \n \npublic class Codeforces429D\n{\n\t\n\tInputStream in;\n\tPrintWriter out;\n\t\n\tlong MAX=Long.MAX_VALUE;\n\tvoid solve() \n\t{\n\t\tlong f=nl();\n\t\tlong T=nl();\n\t\tlong t0=nl();\n\t\tlong a1,t1,p1,a2,t2,p2;\n\t\ta1=nl();t1=nl();p1=nl();\n\t\ta2=nl();t2=nl();p2=nl();\n\t\t\n\t\tlong max1=f/a1;\n\t\tlong max2=f/a2;\n\t\tlong cost=MAX;\n\t\t\n\t\tif (t1>1);\n\t\t\t\t\ttd=a2*mid;\n\t\t\t\t\tif (t+td*t2+(sz-td)*t0 <= T)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult=mid;\n\t\t\t\t\t\tr=mid-1;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tl=mid+1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (t+sz*t2<=T)\n\t\t\t\t\tcost=Math.min(cost, k1*p1+((sz+a2-1)/a2)*p2);\n\t\t\t\t\n\t\t\t\tif (result!=-1)\n\t\t\t\t{\n\t\t\t\t\tcost=Math.min(cost, k1*p1+result*p2);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t\tif (f*t1<=T)\n\t\t\t\tcost=Math.min(cost, ((f+a1-1)/a1)*p1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tfor (int k2=0;k2<=max2;k2++)\n\t\t\t{\n\t\t\t\tlong sz=f-k2*a2;\n\t\t\t\t\n\t\t\t\tlong l=0,r=sz/a1,result=-1,t=a2*k2*t2;\n\t\t\t\tlong td;\n\t\t\t\twhile (l<=r)\n\t\t\t\t{\n\t\t\t\t\tlong mid=((l+r)>>1);\n\t\t\t\t\ttd=a1*mid;\n\t\t\t\t\tif (t+td*t1+(sz-td)*t0<=T)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult=mid;\n\t\t\t\t\t\tr=mid-1;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tl=mid+1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (t+sz*t1<=T)\n\t\t\t\t\tcost=Math.min(cost, k2*p2+((sz+a1-1)/a1)*p1);\n\t\t\t\t\n\t\t\t\tif (result!=-1)\n\t\t\t\t{\n\t\t\t\t\tcost=Math.min(cost, k2*p2+result*p1);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t\tif (f*t2<=T)\n\t\t\t\tcost=Math.min(cost, ((f+a2-1)/a2)*p2);\n\t\t}\n\t\t\n\t\tif (cost==MAX)\n\t\t\tout.println(-1);\n\t\telse\n\t\t\tout.println(cost);\n\t}\n\t\t\n\tvoid run() throws Exception \n\t{\n\t\tString INPUT = \"C:/Users/ayubs/Desktop/input.txt\";\n\t\tin = oj ? System.in : new FileInputStream(INPUT);\n\t\tout = new PrintWriter(System.out);\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis() - s + \"ms\");\n\t\t\n\t}\n\tpublic static void main(String[] args) throws Exception \n\t{\n\t\tnew Codeforces429D().run();\n\t}\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte() \n\t{\n\t\tif (lenbuf == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (ptrbuf >= lenbuf) \n\t\t{\n\t\t\tptrbuf = 0;\n\t\t\ttry \n\t\t\t{\n\t\t\t\tlenbuf = in.read(inbuf);\n\t\t\t}\n\t\t\tcatch (IOException e) \n\t\t\t{\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (lenbuf <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean inSpaceChar(int c) \n\t{\n\t\treturn !(c >= 33 && c <= 126);\n\t}\n\t\n\tprivate int skip() \n\t{\n\t\tint b;\n\t\twhile ((b = readByte()) != -1 && inSpaceChar(b))\n\t\t\t;\n\t\treturn b;\n\t}\n\t\n\tprivate double nd() \n\t{\n\t\treturn Double.parseDouble(ns());\n\t}\n\t\n\tprivate char nc() \n\t{\n\t\treturn (char) skip();\n\t}\n\t\n\tprivate String ns() \n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!(inSpaceChar(b))) \n\t\t{ // when nextLine, (inSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n) \n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile (p < n && !(inSpaceChar(b))) \n\t\t{\n\t\t\tbuf[p++] = (char) b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m) \n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tmap[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n) \n\t{\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni() \n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t;\n\t\tif (b == '-') \n\t\t{\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile (true) \n\t\t{\n\t\t\tif (b >= '0' && b <= '9') \n\t\t\t{\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t} \n\t\t\telse \n\t\t\t{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl() \n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t;\n\t\tif (b == '-') \n\t\t{\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile (true) \n\t\t{\n\t\t\tif (b >= '0' && b <= '9') \n\t\t\t{\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}\n\t\t\telse \n\t\t\t{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\n\tprivate void tr(Object... o) \n\t{\n\t\tif (!oj)\n\t\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n\t\n}", "lang_cluster": "Java", "tags": ["implementation", "binary search"], "code_uid": "80fff714269773d4300c2c9b62d8085c", "src_uid": "f5f85e75af5b0f25f1f436a21e12fad1", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Comparator;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Collection;\nimport java.util.List;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.ArrayList;\nimport java.util.StringTokenizer;\nimport java.math.BigInteger;\nimport java.util.Collections;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author AlexFetisov\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int x = in.nextInt();\n int n = in.nextInt();\n int pi = in.nextInt();\n double p = (1. * pi) / 100.;\n double[][][][] dp = new double[2][256][2][n + 32];\n ArrayUtils.fill(dp, 0);\n if (x / 256 % 2 == 0) {\n dp[0][x % 256][0][x < 256 ? 0 : Integer.numberOfTrailingZeros(x / 256)] = 1.0;\n } else {\n dp[0][x % 256][1][Integer.numberOfTrailingZeros(x / 256 + 1)] = 1.0;\n }\n for (int i = 0; i < n; ++i) {\n ArrayUtils.fill(dp[1], 0);\n for (int high = 0; high < n + 31; ++high) {\n for (int low = 0; low < 256; ++low) {\n double notP = (1.0 - p);\n {\n if (low < 128) {\n dp[1][low * 2][0][high == 0 ? 0 : high + 1] += dp[0][low][0][high] * p;\n dp[1][low * 2][0][1] += dp[0][low][1][high] * p;\n } else {\n dp[1][(low * 2) % 256][1][1] += dp[0][low][0][high] * p;\n dp[1][(low * 2) % 256][1][high + 1] += dp[0][low][1][high] * p;\n }\n }\n {\n if (low < 255) {\n dp[1][low + 1][0][high] += dp[0][low][0][high] * notP;\n dp[1][low + 1][1][high] += dp[0][low][1][high] * notP;\n } else {\n dp[1][0][1][1] += dp[0][low][0][high] * notP;\n dp[1][0][0][high] += dp[0][low][1][high] * notP;\n }\n }\n }\n }\n double[][][] temp = dp[0];\n dp[0] = dp[1];\n dp[1] = temp;\n }\n double res = 0;\n for (int high = 0; high < n + 32; ++high) {\n for (int low = 0; low < 256; ++low) {\n res += dp[0][low][0][high] * (low == 0 ? 8 + high : Integer.numberOfTrailingZeros(low));\n res += dp[0][low][1][high] * (low == 0 ? 8 : Integer.numberOfTrailingZeros(low));\n }\n }\n out.printf(\"%.13f\\n\", res);\n }\n}\n\nclass InputReader {\n private BufferedReader reader;\n private StringTokenizer stt;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n }\n\n public String nextLine() {\n try {\n return reader.readLine().trim();\n } catch (IOException e) {\n return null;\n }\n }\n\n public String nextString() {\n while (stt == null || !stt.hasMoreTokens()) {\n stt = new StringTokenizer(nextLine());\n }\n return stt.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(nextString());\n }\n\n}\n\nclass ArrayUtils {\n\n public static void fill(double[][][] f, double value) {\n for (int i = 0; i < f.length; ++i) {\n for (int j = 0; j < f[i].length; ++j) {\n Arrays.fill(f[i][j], value);\n }\n }\n }\n\n public static void fill(double[][][][] g, int value) {\n for (int i = 0; i < g.length; ++i) {\n ArrayUtils.fill(g[i], value);\n }\n }\n\n}\n\n", "lang_cluster": "Java", "tags": ["math", "dp", "probabilities", "bitmasks"], "code_uid": "7d4a32a42873a007ff2bb9586dd867ef", "src_uid": "c9274249c26b1a85c19ab70d91c1c3e0", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "//package com.example.practice.codeforces.sc2900.prac;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.StringTokenizer;\n\n//G. Long Binary String\npublic class Solution1 {\n // https://abcdxyzk.github.io/blog/2018/04/16/isal-erase-3/\n // https://zhuanlan.zhihu.com/p/132603308\n public static void main (String [] args) throws IOException {\n // Use BufferedReader rather than RandomAccessFile; it's much faster\n final BufferedReader input = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter out = new PrintWriter(System.out);\n // input file name goes above\n //StringTokenizer st = new StringTokenizer(input.readLine());\n //int n = Integer.parseInt(st.nextToken()), a = Integer.parseInt(st.nextToken()), b = Integer.parseInt(st.nextToken()), k = Integer.parseInt(st.nextToken());\n long[] res = calc(input.readLine());\n if (res==null){\n out.println(-1);\n }else {\n printArray(res, out);\n }\n out.close(); // close the output file\n }\n\n private static long[] calc(final String s) {\n long px = 0, v = 1;\n int p = s.length()-1, tem = 0, highest = 0, first = 0, c = 0;\n while (p>=0 && s.charAt(p)=='0'){\n p--;\n }\n if (p<0)return null;\n while (p>=0){\n if (s.charAt(p)=='1'){\n px |= 1L << tem;\n highest = tem;\n first = p;\n c++;\n }\n tem++;\n p--;\n }\n if (c==1)return new long[]{first+1, first+2};\n final long m = (long) Math.sqrt(1L< map = new HashMap<>();\n for (int i=1;i<=m;++i){\n v = v << 1;\n if ((v & (1L< 0) {\n v2 = v2 << 1;\n if ((v2 & (1L< len)break;\n for (int i=0;i len)break;\n for (int i=0;i al = new ArrayList<>();\n while (st.hasMoreTokens()){\n al.add(Long.parseLong(st.nextToken()));\n }\n long[] kk = new long[al.size()];\n for (int j=0;j al = new ArrayList<>();\n while (st.hasMoreTokens()){\n al.add(Integer.parseInt(st.nextToken()));\n }\n int[] kk = new int[al.size()];\n for (int j=0;j> 1;\n val1 = val2 = d;\n if (st> 1;\n if (st==en){\n val1 = val2 = ns[st];\n }else {\n left = new SegTree(l, mid, ns);\n right = new SegTree(mid+1, r, ns);\n val1 = Math.min(left.val1, right.val1);\n val2 = Math.max(left.val2, right.val2);\n }\n }\n\n void update(int idx, int v){\n if (st==en){\n val1 = val2 = v;\n }else {\n if (idx <= mid){\n left.update(idx, v);\n }else {\n right.update(idx, v);\n }\n val1 = Math.min(left.val1, right.val1);\n val2 = Math.max(left.val2, right.val2);\n }\n }\n\n int getMin(int l, int r){\n if (st==en || (l==st && r==en))return val1;\n if (r<=mid){\n return left.getMin(l, r);\n }\n if (l>mid){\n return right.getMin(l, r);\n }\n return Math.min(left.getMin(l, mid), right.getMin(mid+1, r));\n }\n\n int getMax(int l, int r){\n if (st==en || (l==st && r==en))return val2;\n if (r<=mid){\n return left.getMax(l, r);\n }\n if (l>mid){\n return right.getMax(l, r);\n }\n return Math.max(left.getMax(l, mid), right.getMax(mid+1, r));\n }\n }\n\n static class SparseTable{\n int[][] minTable;\n int[][] maxTable;\n int[] log2;\n int n;\n public SparseTable(final int[] ns){\n n = ns.length;\n int m = 0, pre = 0;\n while (1< 0\r\n\t\t\t\tfor(int j = 0;j < n;j++){\r\n\t\t\t\t\tif(oss[lb].substring(of).equals(oss[j])){\r\n\t\t\t\t\t\tM[0][i+(U+1)*(oss[j].length()-1)] += 2;\r\n\t\t\t\t\t}else if(oss[lb].substring(of).startsWith(oss[j])){\r\n\t\t\t\t\t\tM[i+oss[j].length()][i+(U+1)*(oss[j].length()-1)] += 1;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\t// l: -> 0\r\n\t\t\t\tString suf = oss[lb].substring(of);\r\n\t\t\t\tfor(int j = 0;j < n;j++){\r\n\t\t\t\t\tif(oss[j].startsWith(suf) && !oss[j].equals(suf)){\r\n\t\t\t\t\t\tM[offset[j]+suf.length()-1][i+(U+1)*(suf.length()-1)] += 1;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(int i = 0;i < U+1;i++){\r\n\t\t\tfor(int j = 0;j < D-1;j++){\r\n\t\t\t\tM[i+(U+1)*(j+1)][i+(U+1)*j] = 1;\r\n\t\t\t}\r\n\t\t}\r\n\r\n//\t\tfor(int[] row : M){\r\n//\t\t\ttr(row);\r\n//\t\t}\r\n\r\n\t\tint[] v = new int[(U+1)*D];\r\n\t\tv[0] = 1;\r\n\t\tv = pow(M, v, m);\r\n//\t\tfor(int i = 1;i < U+1;i++){\r\n//\t\t\tif(v[i] != v[i+U]){\r\n//\t\t\t\ttr(\"diff\", i, i+U, v[i], v[i+U]);\r\n//\t\t\t}\r\n//\t\t}\r\n//\t\ttr(v);\r\n\t\tout.println(v[0]);\r\n\t}\r\n\r\n\t///////// begin\r\n\tpublic static final int mod = 998244353;\r\n\tpublic static final long m2 = (long)mod*mod;\r\n\tpublic static final long BIG = 8L*m2;\r\n\r\n\t// A^e*v\r\n\tpublic static int[] pow(int[][] A, int[] v, long e)\r\n\t{\r\n\t\tfor(int i = 0;i < v.length;i++){\r\n\t\t\tif(v[i] >= mod)v[i] %= mod;\r\n\t\t}\r\n\t\tint[][] MUL = A;\r\n\t\tfor(;e > 0;e>>>=1) {\r\n\t\t\tif((e&1)==1)v = mul(MUL, v);\r\n\t\t\tMUL = p2(MUL);\r\n\t\t}\r\n\t\treturn v;\r\n\t}\r\n\r\n\t// int matrix*int vector\r\n\tpublic static int[] mul(int[][] A, int[] v)\r\n\t{\r\n\t\tint m = A.length;\r\n\t\tint n = v.length;\r\n\t\tint[] w = new int[m];\r\n\t\tfor(int i = 0;i < m;i++){\r\n\t\t\tlong sum = 0;\r\n\t\t\tfor(int k = 0;k < n;k++){\r\n\t\t\t\tsum += (long)A[i][k] * v[k];\r\n\t\t\t\tif(sum >= BIG)sum -= BIG;\r\n\t\t\t}\r\n\t\t\tw[i] = (int)(sum % mod);\r\n\t\t}\r\n\t\treturn w;\r\n\t}\r\n\r\n\t// int matrix^2 (be careful about negative value)\r\n\tpublic static int[][] p2(int[][] A)\r\n\t{\r\n\t\tint n = A.length;\r\n\t\tint[][] C = new int[n][n];\r\n\t\tfor(int i = 0;i < n;i++){\r\n\t\t\tlong[] sum = new long[n];\r\n\t\t\tfor(int k = 0;k < n;k++){\r\n\t\t\t\tfor(int j = 0;j < n;j++){\r\n\t\t\t\t\tsum[j] += (long)A[i][k] * A[k][j];\r\n\t\t\t\t\tif(sum[j] >= BIG)sum[j] -= BIG;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tfor(int j = 0;j < n;j++){\r\n\t\t\t\tC[i][j] = (int)(sum[j] % mod);\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn C;\r\n\t}\r\n\r\n\r\n\tpublic static int lowerBound(int[] a, int v){ return lowerBound(a, 0, a.length, v); }\r\n\tpublic static int lowerBound(int[] a, int l, int r, int v)\r\n\t{\r\n\t\tif(l > r || l < 0 || r > a.length)throw new IllegalArgumentException();\r\n\t\tint low = l-1, high = r;\r\n\t\twhile(high-low > 1){\r\n\t\t\tint h = high+low>>>1;\r\n\t\t\tif(a[h] >= v){\r\n\t\t\t\thigh = h;\r\n\t\t\t}else{\r\n\t\t\t\tlow = h;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn high;\r\n\t}\r\n\r\n\r\n\tvoid run() throws Exception\r\n\t{\r\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\r\n\t\tout = new FastWriter(System.out);\r\n\t\t\r\n\t\tlong s = System.currentTimeMillis();\r\n\t\tsolve();\r\n\t\tout.flush();\r\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) throws Exception { new F2().run(); }\r\n\t\r\n\tprivate byte[] inbuf = new byte[1024];\r\n\tpublic int lenbuf = 0, ptrbuf = 0;\r\n\t\r\n\tprivate int readByte()\r\n\t{\r\n\t\tif(lenbuf == -1)throw new InputMismatchException();\r\n\t\tif(ptrbuf >= lenbuf){\r\n\t\t\tptrbuf = 0;\r\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\r\n\t\t\tif(lenbuf <= 0)return -1;\r\n\t\t}\r\n\t\treturn inbuf[ptrbuf++];\r\n\t}\r\n\t\r\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\r\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\r\n\t\r\n\tprivate double nd() { return Double.parseDouble(ns()); }\r\n\tprivate char nc() { return (char)skip(); }\r\n\t\r\n\tprivate String ns()\r\n\t{\r\n\t\tint b = skip();\r\n\t\tStringBuilder sb = new StringBuilder();\r\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\r\n\t\t\tsb.appendCodePoint(b);\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t\treturn sb.toString();\r\n\t}\r\n\t\r\n\tprivate char[] ns(int n)\r\n\t{\r\n\t\tchar[] buf = new char[n];\r\n\t\tint b = skip(), p = 0;\r\n\t\twhile(p < n && !(isSpaceChar(b))){\r\n\t\t\tbuf[p++] = (char)b;\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\r\n\t}\r\n\r\n\tprivate int[] na(int n)\r\n\t{\r\n\t\tint[] a = new int[n];\r\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\r\n\t\treturn a;\r\n\t}\r\n\r\n\tprivate long[] nal(int n)\r\n\t{\r\n\t\tlong[] a = new long[n];\r\n\t\tfor(int i = 0;i < n;i++)a[i] = nl();\r\n\t\treturn a;\r\n\t}\r\n\r\n\tprivate char[][] nm(int n, int m) {\r\n\t\tchar[][] map = new char[n][];\r\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\r\n\t\treturn map;\r\n\t}\r\n\r\n\tprivate int[][] nmi(int n, int m) {\r\n\t\tint[][] map = new int[n][];\r\n\t\tfor(int i = 0;i < n;i++)map[i] = na(m);\r\n\t\treturn map;\r\n\t}\r\n\r\n\tprivate int ni() { return (int)nl(); }\r\n\r\n\tprivate long nl()\r\n\t{\r\n\t\tlong num = 0;\r\n\t\tint b;\r\n\t\tboolean minus = false;\r\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\r\n\t\tif(b == '-'){\r\n\t\t\tminus = true;\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\r\n\t\twhile(true){\r\n\t\t\tif(b >= '0' && b <= '9'){\r\n\t\t\t\tnum = num * 10 + (b - '0');\r\n\t\t\t}else{\r\n\t\t\t\treturn minus ? -num : num;\r\n\t\t\t}\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic static class FastWriter\r\n\t{\r\n\t\tprivate static final int BUF_SIZE = 1<<13;\r\n\t\tprivate final byte[] buf = new byte[BUF_SIZE];\r\n\t\tprivate final OutputStream out;\r\n\t\tprivate int ptr = 0;\r\n\r\n\t\tprivate FastWriter(){out = null;}\r\n\r\n\t\tpublic FastWriter(OutputStream os)\r\n\t\t{\r\n\t\t\tthis.out = os;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter(String path)\r\n\t\t{\r\n\t\t\ttry {\r\n\t\t\t\tthis.out = new FileOutputStream(path);\r\n\t\t\t} catch (FileNotFoundException e) {\r\n\t\t\t\tthrow new RuntimeException(\"FastWriter\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(byte b)\r\n\t\t{\r\n\t\t\tbuf[ptr++] = b;\r\n\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(char c)\r\n\t\t{\r\n\t\t\treturn write((byte)c);\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(char[] s)\r\n\t\t{\r\n\t\t\tfor(char c : s){\r\n\t\t\t\tbuf[ptr++] = (byte)c;\r\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(String s)\r\n\t\t{\r\n\t\t\ts.chars().forEach(c -> {\r\n\t\t\t\tbuf[ptr++] = (byte)c;\r\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\t});\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tprivate static int countDigits(int l) {\r\n\t\t\tif (l >= 1000000000) return 10;\r\n\t\t\tif (l >= 100000000) return 9;\r\n\t\t\tif (l >= 10000000) return 8;\r\n\t\t\tif (l >= 1000000) return 7;\r\n\t\t\tif (l >= 100000) return 6;\r\n\t\t\tif (l >= 10000) return 5;\r\n\t\t\tif (l >= 1000) return 4;\r\n\t\t\tif (l >= 100) return 3;\r\n\t\t\tif (l >= 10) return 2;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(int x)\r\n\t\t{\r\n\t\t\tif(x == Integer.MIN_VALUE){\r\n\t\t\t\treturn write((long)x);\r\n\t\t\t}\r\n\t\t\tif(ptr + 12 >= BUF_SIZE)innerflush();\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite((byte)'-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tint d = countDigits(x);\r\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\r\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\r\n\t\t\t\tx /= 10;\r\n\t\t\t}\r\n\t\t\tptr += d;\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tprivate static int countDigits(long l) {\r\n\t\t\tif (l >= 1000000000000000000L) return 19;\r\n\t\t\tif (l >= 100000000000000000L) return 18;\r\n\t\t\tif (l >= 10000000000000000L) return 17;\r\n\t\t\tif (l >= 1000000000000000L) return 16;\r\n\t\t\tif (l >= 100000000000000L) return 15;\r\n\t\t\tif (l >= 10000000000000L) return 14;\r\n\t\t\tif (l >= 1000000000000L) return 13;\r\n\t\t\tif (l >= 100000000000L) return 12;\r\n\t\t\tif (l >= 10000000000L) return 11;\r\n\t\t\tif (l >= 1000000000L) return 10;\r\n\t\t\tif (l >= 100000000L) return 9;\r\n\t\t\tif (l >= 10000000L) return 8;\r\n\t\t\tif (l >= 1000000L) return 7;\r\n\t\t\tif (l >= 100000L) return 6;\r\n\t\t\tif (l >= 10000L) return 5;\r\n\t\t\tif (l >= 1000L) return 4;\r\n\t\t\tif (l >= 100L) return 3;\r\n\t\t\tif (l >= 10L) return 2;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(long x)\r\n\t\t{\r\n\t\t\tif(x == Long.MIN_VALUE){\r\n\t\t\t\treturn write(\"\" + x);\r\n\t\t\t}\r\n\t\t\tif(ptr + 21 >= BUF_SIZE)innerflush();\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite((byte)'-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tint d = countDigits(x);\r\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\r\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\r\n\t\t\t\tx /= 10;\r\n\t\t\t}\r\n\t\t\tptr += d;\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(double x, int precision)\r\n\t\t{\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite('-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tx += Math.pow(10, -precision)/2;\r\n\t\t\t//\t\tif(x < 0){ x = 0; }\r\n\t\t\twrite((long)x).write(\".\");\r\n\t\t\tx -= (long)x;\r\n\t\t\tfor(int i = 0;i < precision;i++){\r\n\t\t\t\tx *= 10;\r\n\t\t\t\twrite((char)('0'+(int)x));\r\n\t\t\t\tx -= (int)x;\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(char c){\r\n\t\t\treturn write(c).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(int x){\r\n\t\t\treturn write(x).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(long x){\r\n\t\t\treturn write(x).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(double x, int precision){\r\n\t\t\treturn write(x, precision).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(int... xs)\r\n\t\t{\r\n\t\t\tboolean first = true;\r\n\t\t\tfor(int x : xs) {\r\n\t\t\t\tif (!first) write(' ');\r\n\t\t\t\tfirst = false;\r\n\t\t\t\twrite(x);\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(long... xs)\r\n\t\t{\r\n\t\t\tboolean first = true;\r\n\t\t\tfor(long x : xs) {\r\n\t\t\t\tif (!first) write(' ');\r\n\t\t\t\tfirst = false;\r\n\t\t\t\twrite(x);\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln()\r\n\t\t{\r\n\t\t\treturn write((byte)'\\n');\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(int... xs)\r\n\t\t{\r\n\t\t\treturn write(xs).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(long... xs)\r\n\t\t{\r\n\t\t\treturn write(xs).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(char[] line)\r\n\t\t{\r\n\t\t\treturn write(line).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(char[]... map)\r\n\t\t{\r\n\t\t\tfor(char[] line : map)write(line).writeln();\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(String s)\r\n\t\t{\r\n\t\t\treturn write(s).writeln();\r\n\t\t}\r\n\r\n\t\tprivate void innerflush()\r\n\t\t{\r\n\t\t\ttry {\r\n\t\t\t\tout.write(buf, 0, ptr);\r\n\t\t\t\tptr = 0;\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\tthrow new RuntimeException(\"innerflush\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void flush()\r\n\t\t{\r\n\t\t\tinnerflush();\r\n\t\t\ttry {\r\n\t\t\t\tout.flush();\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\tthrow new RuntimeException(\"flush\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic FastWriter print(byte b) { return write(b); }\r\n\t\tpublic FastWriter print(char c) { return write(c); }\r\n\t\tpublic FastWriter print(char[] s) { return write(s); }\r\n\t\tpublic FastWriter print(String s) { return write(s); }\r\n\t\tpublic FastWriter print(int x) { return write(x); }\r\n\t\tpublic FastWriter print(long x) { return write(x); }\r\n\t\tpublic FastWriter print(double x, int precision) { return write(x, precision); }\r\n\t\tpublic FastWriter println(char c){ return writeln(c); }\r\n\t\tpublic FastWriter println(int x){ return writeln(x); }\r\n\t\tpublic FastWriter println(long x){ return writeln(x); }\r\n\t\tpublic FastWriter println(double x, int precision){ return writeln(x, precision); }\r\n\t\tpublic FastWriter print(int... xs) { return write(xs); }\r\n\t\tpublic FastWriter print(long... xs) { return write(xs); }\r\n\t\tpublic FastWriter println(int... xs) { return writeln(xs); }\r\n\t\tpublic FastWriter println(long... xs) { return writeln(xs); }\r\n\t\tpublic FastWriter println(char[] line) { return writeln(line); }\r\n\t\tpublic FastWriter println(char[]... map) { return writeln(map); }\r\n\t\tpublic FastWriter println(String s) { return writeln(s); }\r\n\t\tpublic FastWriter println() { return writeln(); }\r\n\t}\r\n\r\n\tpublic void trnz(int... o)\r\n\t{\r\n\t\tfor(int i = 0;i < o.length;i++)if(o[i] != 0)System.out.print(i+\":\"+o[i]+\" \");\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\t// print ids which are 1\r\n\tpublic void trt(long... o)\r\n\t{\r\n\t\tQueue stands = new ArrayDeque<>();\r\n\t\tfor(int i = 0;i < o.length;i++){\r\n\t\t\tfor(long x = o[i];x != 0;x &= x-1)stands.add(i<<6|Long.numberOfTrailingZeros(x));\r\n\t\t}\r\n\t\tSystem.out.println(stands);\r\n\t}\r\n\r\n\tpublic void tf(boolean... r)\r\n\t{\r\n\t\tfor(boolean x : r)System.out.print(x?'#':'.');\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\tpublic void tf(boolean[]... b)\r\n\t{\r\n\t\tfor(boolean[] r : b) {\r\n\t\t\tfor(boolean x : r)System.out.print(x?'#':'.');\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\tpublic void tf(long[]... b)\r\n\t{\r\n\t\tif(INPUT.length() != 0) {\r\n\t\t\tfor (long[] r : b) {\r\n\t\t\t\tfor (long x : r) {\r\n\t\t\t\t\tfor (int i = 0; i < 64; i++) {\r\n\t\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tSystem.out.println();\r\n\t\t\t}\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic void tf(long... b)\r\n\t{\r\n\t\tif(INPUT.length() != 0) {\r\n\t\t\tfor (long x : b) {\r\n\t\t\t\tfor (int i = 0; i < 64; i++) {\r\n\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t}\r\n\r\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\r\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\r\n}\r\n", "lang_cluster": "Java", "tags": ["brute force", "data structures", "matrices", "strings", "dp"], "code_uid": "1c6f9e0eb57efd679c6ecf166cf1ccf3", "src_uid": "711d15e11016d0164fb2b0c3756e4857", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Codeforces1174E {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tint n = Integer.parseInt(st.nextToken());\n\t\tint mod = 1000000007;\n\t\t\n\t\tint nFact = 1;\n\t\tfor (int i = 2; i <= n; i++) {\n\t\t\tnFact = multiply(nFact, i, mod);\n\t\t}\n\t\t\n\t\tint ntemp = n;\n\t\tint k = 0;\n\t\twhile (ntemp > 0) {\n\t\t\tntemp /= 2;\n\t\t\tk++;\n\t\t}\n\t\t\n\t\tint[] val = new int[k];\n\t\tfor (int i = 0; i < k; i++) {\n\t\t\tval[i] = 1 << (k-1-i);\n\t\t}\n\t\tint[] a = new int[k];\n\t\tfor (int i = 0; i < k; i++) {\n\t\t\ta[i] = n/(val[i]);\n\t\t}\n\t\tfor (int i = k-1; i > 0; i--) {\n\t\t\ta[i] -= a[i-1];\n\t\t}\n\t\t\n\t\tint ans = nFact;\n\t\tint partialSum = 0;\n\t\tfor (int i = k-1; i >= 0; i--) {\n\t\t\tpartialSum += a[i];\n\t\t\tans = multiply(ans, multiply(a[i], inverse(partialSum, mod), mod), mod);\n\t\t}\n\t\t\n\t\tif (n >= (3*val[0])/2) {\n\t\t\tfor (int rep = 0; rep < (k-1); rep++) {\n\t\t\t\tval[rep] = (3*val[rep])/2;\n\t\t\t\t\n\t\t\t\tfor (int i = 0; i < k; i++) {\n\t\t\t\t\ta[i] = n/(val[i]);\n\t\t\t\t}\n\t\t\t\tfor (int i = k-1; i > 0; i--) {\n\t\t\t\t\ta[i] -= a[i-1];\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tint ans2 = nFact;\n\t\t\t\tpartialSum = 0;\n\t\t\t\tfor (int i = k-1; i >= 0; i--) {\n\t\t\t\t\tpartialSum += a[i];\n\t\t\t\t\tans2 = multiply(ans2, multiply(a[i], inverse(partialSum, mod), mod), mod);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tans = (ans+ans2)%mod;\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(ans);\n\t}\n\t\n\tpublic static int multiply (int a, int b, int n) {\n\t\tlong ab = (long) a * (long) b;\n\t\treturn ((int) (ab%n));\n\t}\n\t\n\tpublic static int inverse (int a, int n) {\n\t\tint m = n;\n\t\tint r1 = 1;\n\t\tint r2 = 0;\n\t\tint r3 = 0;\n\t\tint r4 = 1;\n\t\twhile ((a > 0) && (n > 0)) {\n\t\t\tif (n >= a) {\n\t\t\t\tr3 -= r1*(n/a);\n\t\t\t\tr4 -= r2*(n/a);\n\t\t\t\tn = n%a;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tint tmp = a;\n\t\t\t\ta = n;\n\t\t\t\tn = tmp;\n\t\t\t\ttmp = r1;\n\t\t\t\tr1 = r3;\n\t\t\t\tr3 = tmp;\n\t\t\t\ttmp = r2;\n\t\t\t\tr2 = r4;\n\t\t\t\tr4 = tmp;\n\t\t\t}\n\t\t}\n\t\tif (a == 0) {\n\t\t\tif (r3 >= 0)\n\t\t\t\treturn (r3%m);\n\t\t\telse\n\t\t\t\treturn (m+(r3%m));\n\t\t}\n\t\telse {\n\t\t\tif (r1 >= 0)\n\t\t\t\treturn (r1%m);\n\t\t\telse\n\t\t\t\treturn (m+(r1%m));\n\t\t}\n\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics", "number theory"], "code_uid": "dcb806eb14d5ca4d6ae21dfb28224907", "src_uid": "b2d59b1279d891dba9372a52364bced2", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n/**\n * @author Don Li\n */\npublic class PuttingBoxesTogether {\n \n int N = (int) 2e5 + 10;\n int MOD = (int) 1e9 + 7;\n \n int n;\n long[] t1 = new long[N];\n long[] t2 = new long[N];\n \n void solve() {\n n = in.nextInt(); int Q = in.nextInt();\n int[] a = new int[n];\n for (int i = 0; i < n; i++) a[i] = in.nextInt();\n int[] w = new int[n];\n for (int i = 0; i < n; i++) w[i] = in.nextInt();\n \n for (int i = 0; i < n; i++) a[i] -= i;\n \n for (int i = 0; i < n; i++) {\n add(t1, i, w[i]);\n add(t2, i, (long) a[i] * w[i] % MOD);\n }\n \n while (Q-- > 0) {\n int x = in.nextInt();\n if (x < 0) {\n int i = -x - 1, nw = in.nextInt();\n long delta1 = nw - w[i];\n long delta2 = mul(a[i], nw) - mul(a[i], w[i]);\n w[i] = nw;\n add(t1, i, delta1);\n add(t2, i, delta2);\n } else {\n int l = x - 1, r = in.nextInt();\n long tot = sum(t1, l, r);\n int lb = l, ub = r;\n while (ub - lb > 1) {\n int m = (lb + ub) >> 1;\n if (sum(t1, l, m) * 2 <= tot) lb = m;\n else ub = m;\n }\n int k = lb;\n long ans = norm(mul(a[k], nsum(t1, l, k)) - nsum(t2, l, k));\n ans = norm(ans + norm(nsum(t2, k + 1, r) - mul(a[k], nsum(t1, k + 1, r))));\n out.println(ans);\n }\n }\n }\n \n long nsum(long[] t, int l, int r) {\n return norm(sum(t, r - 1) - sum(t, l - 1));\n }\n \n long sum(long[] t, int l, int r) {\n return sum(t, r - 1) - sum(t, l - 1);\n }\n \n long sum(long[] t, int i) {\n long res = 0;\n for (int x = i; x >= 0; x = (x & x + 1) - 1) res += t[x];\n return res;\n }\n \n void add(long[] t, int i, long delta) {\n for (int x = i; x < n; x = x | x + 1) t[x] += delta;\n }\n \n long mul(long a, long b) {\n return a * b % MOD;\n }\n \n long norm(long a) {\n a %= MOD;\n if (a > MOD) a -= MOD;\n if (a < 0) a += MOD;\n return a;\n }\n \n public static void main(String[] args) {\n in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));\n out = new PrintWriter(System.out);\n new PuttingBoxesTogether().solve();\n out.close();\n }\n \n static FastScanner in;\n static PrintWriter out;\n \n static class FastScanner {\n BufferedReader in;\n StringTokenizer st;\n \n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n \n public String nextToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["data structures"], "code_uid": "f8df46262bb74491fe988ab2f36d6d61", "src_uid": "c0715f71efa327070eba7e491856d66a", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class E {\n\n final int MAX = 85;\n\n double[][] prob;\n int[] parent;\n int n;\n\n public void solve() {\n int q = in.nextInt();\n int[] t = new int[q], v = new int[q];\n n = 1;\n for (int i = 0; i < q; i++) {\n t[i] = in.nextInt();\n v[i] = in.nextInt() - 1;\n if (t[i] == 1) {\n n++;\n }\n }\n\n parent = new int[n];\n parent[0] = -1;\n prob = new double[n][MAX];\n Arrays.fill(prob[0], 1);\n int last = 0;\n for (int i = 0; i < q; i++) {\n if (t[i] == 1) {\n last++;\n parent[last] = v[i];\n }\n }\n\n last = 0;\n for (int i = 0; i < q; i++) {\n if (t[i] == 1) {\n last++;\n addVertex(last);\n } else {\n double result = 0;\n double[] pr = prob[v[i]];\n for (int j = 0; j < MAX; j++) {\n result += 1 - pr[j];\n }\n out.println(result);\n }\n }\n }\n\n private void addVertex(int v) {\n Arrays.fill(prob[v], 1);\n\n int p = parent[v];\n double last = 1;\n for (int i = 0; i < MAX; i++) {\n if (p == -1) {\n break;\n }\n double tmp = prob[p][i];\n prob[p][i] /= (0.5 + 0.5 * last);\n last = tmp;\n p = parent[p];\n }\n p = parent[v];\n\n last = 0;\n for (int i = 0; i < MAX; i++) {\n if (p == -1) {\n break;\n }\n prob[p][i] *= (0.5 + 0.5 * last);\n last = prob[p][i];\n p = parent[p];\n }\n }\n\n public void run() {\n in = new FastScanner();\n out = new PrintWriter(System.out);\n solve();\n out.close();\n }\n\n FastScanner in;\n PrintWriter out;\n\n class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(String fileName) {\n try {\n br = new BufferedReader(new FileReader(fileName));\n } catch (FileNotFoundException e) {\n }\n }\n\n public FastScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String nextToken() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n\n public static void main(String[] args) {\n new E().run();\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "dp", "probabilities", "trees"], "code_uid": "02c8d790adb8428f80df81684f9dac30", "src_uid": "55affe752cb214d1e4031a9e3972597b", "difficulty": 2700.0, "exec_outcome": "PASSED"}