{"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class EdE {\n\n\tpublic static void main(String[] args) throws Exception{\n\t\tlong num = 1000000007;\n\n\t\t// TODO Auto-generated method stub\n \t\tBufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n \t\tPrintWriter out = new PrintWriter(System.out);\n \t\tint n = Integer.parseInt(bf.readLine());\n \t\tlong[] dp = new long[n+1];\n \t\tint[] isPrime = new int[n+1];\n\t\tArrays.fill(isPrime, 1);\n\t\tint[] mu = new int[n+1];\n\t\tArrays.fill(mu, 1);\n\t\tfor(int i = 2;i<=n;i++){\n\t\t\tif (isPrime[i] == 1){\n\t\t\t\tfor(int j = i;j<=n;j+=i){\n\t\t\t\t\tif (j > i)\n\t\t\t\t\t\tisPrime[j] = 0;\n\t\t\t\t\tif (j%(i*i) == 0)\n\t\t\t\t\t\tmu[j] = 0;\n\t\t\t\t\tmu[j] = -mu[j];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong sum = 0;\n\t\tfor(int i = 2;i<=n;i++){\n\t\t\tsum+=(((long)(0-mu[i])*((((long)(n/i))*power(n-n/i, num-2, num))%num))%num+num)%num;\n\t\t\tsum%=num;\n\t\t\t\n\t\t}\n\t\tsum+=1;\n\t\tsum%=num;\n \t\tout.println(sum);\n\t \t\t\n \t\tout.close();\n \t\t\n \t\t\n \t\t\n \t}\n\tpublic static long power(long x, long y, long mod){\n\t\tlong ans = 1;\n\t\twhile(y>0){\n\t\t\tif (y%2==1)\n\t\t\t\tans = (ans*x)%mod;\n\t\t\tx = (x*x)%mod;\n\t\t\ty/=2;\n\t\t}\n\t\treturn ans;\n\t}\n}\n \t\n \n//StringJoiner sj = new StringJoiner(\" \"); \n//sj.add(strings)\n//sj.toString() gives string of those stuff w spaces or whatever that sequence is\n\n \t\t\n \t\t\n \t\t\n \t\t\n\t\n\n", "lang_cluster": "Java", "tags": ["math", "dp", "probabilities", "number theory"], "code_uid": "10dc775cd9e42ba52f2d823e59b70d88", "src_uid": "ff810b16b6f41d57c1c8241ad960cba0", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class tr0 {\n\tstatic PrintWriter out;\n\tstatic StringBuilder sb;\n\tstatic final double EPS = 1e-9;\n\tstatic long mod = (int) 1e9 + 7;\n\tstatic int inf = (int) 1e9 + 2;\n\tstatic long[] fac;\n\tstatic int[] si;\n\tstatic ArrayList primes;\n\tstatic TreeSet[] ad;\n\tstatic ArrayList[] d;\n\tstatic edge[] ed;\n\tstatic boolean f;\n\tstatic int n,p;\n\tstatic int[]l,ch;\n\tstatic Boolean [][]memo;\n\tstatic Queue[] can;\n\t\n\tpublic static void main(String[] args) throws Exception {\n\t\tScanner sc = new Scanner(System.in);\n\t\tout = new PrintWriter(System.out);\n\t String s=sc.next();\n\t boolean is=false;\n\t int t=s.length();\n\t for(int i=1;i> 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]) % 2010;\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;\n\t\t\tsTree[index] += val;\n\t\t\twhile (index > 1) {\n\t\t\t\tindex >>= 1;\n\t\t\t\tsTree[index] = sTree[index << 1] + sTree[index << 1 | 1];\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\tif (b == e) {\n\t\t\t\t\tsTree[node] = (sTree[node] * sTree[node]) % 2010;\n\t\t\t\t} else {\n\t\t\t\t\tsTree[node] = ((sTree[node] * sTree[node]) % 2010\n\t\t\t\t\t\t\t- (sTree[node << 1] * sTree[node << 1 | 1] * 2) % 2010 + 2010) % 2010;\n\t\t\t\t\tlazy[node] = 1;\n\t\t\t\t}\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]) % 2010;\n\t\t\t}\n\t\t}\n\n\t\tvoid propagate(int node, int b, int mid, int e) {\n\t\t\tif (lazy[node] == 1) {\n\t\t\t\tlazy[node << 1] = lazy[node];\n\t\t\t\tlazy[node << 1 | 1] = lazy[node];\n\t\t\t\tif (isLeaf[node << 1])\n\t\t\t\t\tsTree[node << 1] = sTree[node << 1] * sTree[node << 1] % 2010;\n\t\t\t\telse\n\t\t\t\t\tsTree[node << 1] = ((sTree[node << 1] * sTree[node << 1]) % 2010\n\t\t\t\t\t\t\t- (sTree[(node << 1) << 1] * sTree[(node << 1) << 1 | 1] * 2) % 2010 + 2010) % 2010;\n\t\t\t\tif (isLeaf[node << 1 | 1])\n\t\t\t\t\tsTree[node << 1 | 1] = sTree[node << 1 | 1] * sTree[node << 1 | 1] % 2010;\n\t\t\t\telse\n\t\t\t\t\tsTree[node << 1 | 1] = ((sTree[node << 1 | 1] * sTree[node << 1 | 1]) % 2010\n\t\t\t\t\t\t\t- (sTree[(node << 1 | 1) << 1] * sTree[(node << 1 | 1) << 1 | 1] * 2) % 2010 + 2010) % 2010;\n\t\t\t\tlazy[node] = -1;\n\t\t\t}\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\tpropagate(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 (q1 + q2) % 2010;\n\n\t\t}\n\n\t}\n\n\tstatic Queue k, k1;\n\tstatic boolean hg = false;\n\n\tstatic class Edge implements Comparable {\n\t\tint node, cost;\n\n\t\tEdge(int a, int b) {\n\t\t\tnode = a;\n\t\t\tcost = b;\n\t\t}\n\n\t\tpublic int compareTo(Edge e) {\n\t\t\treturn cost - e.cost;\n\t\t}\n\t}\n\n\tstatic void ifCan(int i) {\n\t\tif (i == 6) {\n\t\t\thg = true;\n\t\t\tfor (int j : k)\n\t\t\t\tk1.add(j);\n\t\t\treturn;\n\t\t} else if (k.contains(i))\n\t\t\tifCan(i + 1);\n\t\telse {\n\t\t\tif (!hg) {\n\t\t\t\tfor (int p : can[i]) {\n\t\t\t\t\tif (!k.contains(p)) {\n\t\t\t\t\t\tk.add(i);\n\t\t\t\t\t\tk.add(p);\n\t\t\t\t\t\tifCan(i + 1);\n\t\t\t\t\t\tk.remove(i);\n\t\t\t\t\t\tk.remove(p);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic class qu implements Comparable {\n\t\tint a;\n\t\tint b;\n\n\t\tqu(int a, int b) {\n\t\t\tthis.a = a;\n\t\t\tthis.b = b;\n\t\t}\n\n\t\tpublic String toString() {\n\t\t\treturn a + \" \" + b;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(qu o) {\n\t\t\treturn b - o.b;\n\t\t}\n\t}\n\n\tstatic class pair {\n\t\tint to;\n\t\tint number;\n\n\t\tpair(int t, int n) {\n\t\t\tnumber = n;\n\t\t\tto = t;\n\t\t}\n\n\t\tpublic String toString() {\n\t\t\treturn to + \" \" + number;\n\t\t}\n\t}\n\n\tstatic boolean[] in;\n\n\t/*\n\t * static void mst() { Arrays.sort(ed); UnionFind uf=new UnionFind(n); for(int\n\t * i=0;i {\n\t\tint from;\n\t\tint to;\n\t\tint number;\n\n\t\tedge(int f, int t, int n) {\n\t\t\tfrom = f;\n\t\t\tto = t;\n\t\t\tnumber = n;\n\t\t}\n\n\t\tpublic String toString() {\n\t\t\treturn from + \" \" + to + \" \" + number;\n\t\t}\n\n\t\tpublic int compareTo(edge f) {\n\t\t\treturn number - f.number;\n\t\t}\n\t}\n\n\tstatic class seg implements Comparable {\n\t\tint a;\n\t\tint b;\n\n\t\tseg(int s, int e) {\n\t\t\ta = s;\n\t\t\tb = e;\n\t\t}\n\n\t\tpublic String toString() {\n\t\t\treturn a + \" \" + b;\n\t\t}\n\n\t\tpublic int compareTo(seg o) {\n\t\t\t// if(a==o.a)\n\t\t\treturn o.b - b;\n\t\t\t// return\n\t\t}\n\t}\n\n\tstatic long power(int i) {\n\t\t// if(i==0)\n\t\t// return 1;\n\t\tlong a = 1;\n\t\tfor (int k = 0; k < i; k++)\n\t\t\ta *= i;\n\t\treturn a;\n\t}\n\n\tstatic void seive() {\n\t\tsi = new int[1000001];\n\t\tprimes = new ArrayList<>();\n\t\tint N = 1000001;\n\t\tsi[1] = 1;\n\t\tfor (int i = 2; i < N; i++) {\n\t\t\tif (si[i] == 0) {\n\t\t\t\tsi[i] = i;\n\t\t\t\tprimes.add(i);\n\t\t\t}\n\t\t\tfor (int j = 0; j < primes.size() && primes.get(j) <= si[i] && (i * primes.get(j)) < N; j++)\n\t\t\t\tsi[primes.get(j) * i] = primes.get(j);\n\n\t\t}\n\t}\n\n\tstatic long inver(long x) {\n\t\tint a = (int) x;\n\t\tlong e = (mod - 2);\n\t\tlong res = 1;\n\t\twhile (e > 0) {\n\t\t\tif ((e & 1) == 1) {\n\t\t\t\t// System.out.println(res*a);\n\t\t\t\tres = (int) ((1l * res * a) % mod);\n\t\t\t}\n\t\t\ta = (int) ((1l * a * a) % mod);\n\t\t\te >>= 1;\n\t\t}\n\t\t// out.println(res+\" \"+x);\n\t\treturn res % mod;\n\t}\n\n\tstatic long fac(int n) {\n\t\tif (n == 0)\n\t\t\treturn fac[n] = 1;\n\t\tif (n == 1)\n\t\t\treturn fac[n] = 1;\n\t\tlong ans = 1;\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\tfac[i] = ans = (i % mod * ans % mod) % mod;\n\t\treturn ans % mod;\n\t}\n\n\tstatic long gcd(long a, long b) {\n\n\t\tif (b == 0)\n\t\t\treturn a;\n\t\treturn gcd(b, a % b);\n\t}\n\n\tstatic class unionfind {\n\t\tint[] p;\n\t\tint[] size;\n\n\t\tunionfind(int n) {\n\t\t\tp = new int[n];\n\t\t\tsize = new int[n];\n\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tp[i] = i;\n\t\t\t}\n\t\t\tArrays.fill(size, 1);\n\t\t}\n\n\t\tint findSet(int v) {\n\t\t\tif (v == p[v])\n\t\t\t\treturn v;\n\t\t\treturn p[v] = findSet(p[v]);\n\t\t}\n\n\t\tboolean sameSet(int a, int b) {\n\t\t\ta = findSet(a);\n\t\t\tb = findSet(b);\n\t\t\tif (a == b)\n\t\t\t\treturn true;\n\t\t\treturn false;\n\t\t}\n\n\t\tint max() {\n\t\t\tint max = 0;\n\t\t\tfor (int i = 0; i < size.length; i++)\n\t\t\t\tif (size[i] > max)\n\t\t\t\t\tmax = size[i];\n\t\t\treturn max;\n\t\t}\n\n\t\tboolean combine(int a, int b) {\n\t\t\ta = findSet(a);\n\t\t\tb = findSet(b);\n\t\t\tif (a == b)\n\t\t\t\treturn true;\n\t\t\tif (size[a] > size[b]) {\n\t\t\t\tp[b] = a;\n\t\t\t\tsize[a] += size[b];\n\n\t\t\t} else {\n\t\t\t\tp[a] = b;\n\t\t\t\tsize[b] += size[a];\n\t\t\t}\n\t\t\treturn false;\n\t\t}\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\t}\n}", "lang_cluster": "Java", "tags": ["math"], "code_uid": "0976a0379f1b1f8638dafb837c80fe8e", "src_uid": "d8ca1c83b431466eff6054d3b422ab47", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\npublic class main {\n \n public static int [] mem;\n public static int a,b,c;\n \n public static void main(String[] args) {\n \n Scanner s= new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n //BufferedReader n = new BufferedReader(new InputStreamReader(System.in));\n \n int valor=s.nextInt();\n a=s.nextInt();\n b=s.nextInt();\n c=s.nextInt();\n \n \n mem=new int [4001];\n for(int i=0;i=a && i>=b && i>=c){\n mem[i]= Math.max(1+mem[i-a], Math.max(1+mem[i-b],1+mem[i-c]));\n }\n else\n if(i>=a && i>=b)\n mem[i]= Math.max(1+mem[i-a],1+mem[i-b]);\n else\n if(i>=c && i>=b)\n mem[i]= Math.max(1+mem[i-c],1+mem[i-b]);\n else\n if(i>=a && i>=c)\n mem[i]= Math.max(1+mem[i-a],1+mem[i-c]);\n else\n if(i>=a)\n mem[i]= 1+mem[i-a];\n else\n if(i>=b)\n mem[i]= 1+mem[i-b];\n else\n if(i>=c)\n mem[i]= 1+mem[i-c];\n }\n System.out.println(mem[valor]);\n \n }\n \n}", "lang_cluster": "Java", "tags": ["brute force", "dp"], "code_uid": "ac23c04d91baaa5b4b8ba1c8aeff288a", "src_uid": "062a171cc3ea717ea95ede9d7a1c3a43", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "\timport java.io.IOException;\n\timport java.io.InputStream;\n\timport java.io.PrintWriter;\n\timport java.util.Arrays;\n\timport java.util.InputMismatchException;\n\t\n\tpublic class CF {\n\t\tstatic int mod, N; \n\t\tstatic int[] array;\n\t\tstatic long[][] memo;\n\t\tstatic int[] powpow;\n\t\tstatic int[][][] magic;\n\t\tpublic static void main(String[] args) {\n\t\t\tFasterScanner sc = new FasterScanner();\n\t\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t\tchar[] str = sc.next().toCharArray();\n\t\t\tint pow = 1;\n\t\t\tmod = sc.nextInt();\n\t\t\tmagic = new int[20][10][mod];\n\t\t\tfor(int a=0;a<20;a++){\n\t\t\t\tfor(int b=0;b<10;b++)\n\t\t\t\t\tfor(int c=0;c>a)&1)==0){\n\t\t\t\t\tif(Integer.bitCount(mask)==0){\n\t\t\t\t\t\tif(array[a]==0)continue;\n\t\t\t\t\t}\n\t\t\t\t\tif(a>0&&(mask>>(a-1)&1)==0&&array[a]==array[a-1])continue;\n\t\t\t\t\tans+=DP(mask+(1<=0;a--){\n\t\t\t\tif(vals[a]K;a--){\n\t\t\t\tif(vals[K]= numChars) {\n\t\t\t\t\tcurChar = 0;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t\t} catch (IOException e) {\n\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\t}\n\t\t\t\t\tif (numChars <= 0)\n\t\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t\treturn buf[curChar++];\n\t\t\t}\n\t\n\t\t\tboolean isSpaceChar(int c) {\n\t\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t\t}\n\t\n\t\t\tboolean isEndline(int c) {\n\t\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t\t}\n\t\n\t\t\tint nextInt() {\n\t\t\t\treturn Integer.parseInt(next());\n\t\t\t}\n\t\n\t\t\tlong nextLong() {\n\t\t\t\treturn Long.parseLong(next());\n\t\t\t}\n\t\n\t\t\tdouble nextDouble() {\n\t\t\t\treturn Double.parseDouble(next());\n\t\t\t}\n\t\n\t\t\tString next() {\n\t\t\t\tint c = read();\n\t\t\t\twhile (isSpaceChar(c))\n\t\t\t\t\tc = read();\n\t\t\t\tStringBuilder res = new StringBuilder();\n\t\t\t\tdo {\n\t\t\t\t\tres.appendCodePoint(c);\n\t\t\t\t\tc = read();\n\t\t\t\t} while (!isSpaceChar(c));\n\t\t\t\treturn res.toString();\n\t\t\t}\n\t\n\t\t\tString nextLine() {\n\t\t\t\tint c = read();\n\t\t\t\twhile (isEndline(c))\n\t\t\t\t\tc = read();\n\t\t\t\tStringBuilder res = new StringBuilder();\n\t\t\t\tdo {\n\t\t\t\t\tres.appendCodePoint(c);\n\t\t\t\t\tc = read();\n\t\t\t\t} while (!isEndline(c));\n\t\t\t\treturn res.toString();\n\t\t\t}\n\t\n\t\t}\n\t\n\t}", "lang_cluster": "Java", "tags": ["brute force", "dp", "combinatorics", "bitmasks", "number theory"], "code_uid": "28e4eee2c7ba5106e0ce6472f49cde0e", "src_uid": "5eb90c23ffa3794fdddc5670c0373829", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.*;\n\npublic class A {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tString s = sc.next();\n\t\tint N = s.length();\n\t\tint max = -1;\n\t\tint LIM = 1000000;\n\t\tfor(int i=1; i 1 && a.charAt(0) == '0')\n\t\t\t\t\tcontinue;\n\t\t\t\tif(b.length() > 1 && b.charAt(0) == '0')\n\t\t\t\t\tcontinue;\n\t\t\t\tif(c.length() > 1 && c.charAt(0) == '0')\n\t\t\t\t\tcontinue;\n\t\t\t\tif(a.length() > 8 || b.length() > 8 || c.length() > 8)\n\t\t\t\t\tcontinue;\n\t\t\t\tint x = Integer.parseInt(a);\n\t\t\t\tint y = Integer.parseInt(b);\n\t\t\t\tint z = Integer.parseInt(c);\n\t\t\t\tif(x > LIM || y > LIM || z > LIM)\n\t\t\t\t\tcontinue;\n\t\t\t\tmax = Math.max(max, x+y+z);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(max);\n\t}\n}\n", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "8c86b34438ad0186fdfb3db33b762f28", "src_uid": "bf4e72636bd1998ad3d034ad72e63097", "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.Comparator;\nimport java.util.List;\n\npublic class CyclicPermutations { // Template for CF\n public static class ListComparator implements Comparator> {\n\n @Override\n public int compare(List l1, List l2) {\n for (int i = 0; i < l1.size(); ++i) {\n if (l1.get(i).compareTo(l2.get(i)) != 0) {\n return l1.get(i).compareTo(l2.get(i));\n }\n }\n return 0;\n }\n }\n\n public static class Pair {\n int first;\n int second;\n\n public Pair(int first, int second) {\n this.first = first;\n this.second = second;\n }\n\n public int getFirst() {\n return first;\n }\n\n public int getSecond() {\n return second;\n }\n\n @Override\n public String toString() {\n return first + \" \" + second;\n }\n }\n\n public static void main(String[] args) throws IOException {\n // Check for int overflow!!!!\n // Should you use a long to store the sum or smthn?\n BufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter out = new PrintWriter(System.out);\n\n long n = Integer.parseInt(f.readLine());\n long bad = 1;\n long mod = 1000000007;\n for (int j = 0; j < n - 1; j++) {\n bad *= 2;\n bad %= mod;\n }\n long prod = 1;\n for (long j = n; j > 0; j--) {\n prod *= j;\n prod %= mod;\n }\n if (prod - bad >= 0) {\n out.println(prod - bad);\n } else {\n out.println(mod + prod - bad);\n }\n out.close();\n }\n\n}", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics", "graphs"], "code_uid": "71892c88f54e862b73e338a2a8d0a4f7", "src_uid": "3dc1ee09016a25421ae371fa8005fce1", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.ArrayList;\nimport java.util.List;\nimport java.util.Scanner;\n\n\npublic class Solution {\n\n\tprivate static int res;\n\tprivate static int[] numberOfPrimeDivisor;\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\t\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\t\n\t\tint[] plainNumber = new int [n];\n\t\tfor(int i=0;i factors = primeFactors(i);\n\t\t\tint count = 1;\n\t\t\tfor(int j=1;j primeFactors(int number) {\n\t\t int n = number;\n\t\t List factors = new ArrayList();\n\t\t for (int i = 2; i <= n; i++) {\n\t\t while (n % i == 0) {\n\t\t factors.add(i);\n\t\t n /= i;\n\t\t }\n\t\t }\n\t\t return factors;\n\t\t }\n\t \n\tprivate static void getNumbers(int[] plainNumber) {\n\t\tfor(int i =2;i curQueue = new HashSet();\n\t\t//\thash[MAX/2][MAX/2][0] = 0;\n\t\t\tcurQueue.add(getStatus(MAX/2, MAX/2, 0));\n\t\t\t//curQueue.add();\n\t\t\tfor (int i = 1; i <= k; i++) {\n\t\t\t\tint next = scanner.nextInt();\n\t\t\t\tSet newQueue = new HashSet();\n\t\t\t\tfor (int cur : curQueue) {\n\t\t\t\t\tint curDirection = cur & 0x7;\n\t\t\t\t\tint curY = (cur >> 3) & 0x1FF;\n\t\t\t\t\tint curX = (cur >> 12) & 0x1FF;\n\t\t\t\t//\tif (hash[curX][curY][curDirection] < next) {\n\t\t\t//\t\t\thash[curX][curY][curDirection] = next;\n\t\t\t\t\t\tint j = 1;\n\t\t\t\t\t\twhile(true) {\n\t\t\t\t\t\t\tcurX += dx[curDirection];\n\t\t\t\t\t\t\tcurY += dy[curDirection];\n\t\t\t\t\t\t//\tSystem.out.println(curX);\n\t\t\t\t\t\t\tmask[curX][curY] = 1;\n\t\t\t\t\t\t\tif (j == next) {\n\t\t\t\t\t\t\t\tnewQueue.add(getStatus(curX, curY, (curDirection + 1) % 8));\n\t\t\t\t\t\t\t\tint newDir = (curDirection - 1) % 8;\n\t\t\t\t\t\t\t\tif (newDir < 0) newDir = 8 + newDir;\n\t\t\t\t\t\t\t\tnewQueue.add(getStatus(curX, curY, (newDir) % 8));\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t//\t\t\tif (hash[curX][curY][curDirection] < next - j) {\n\t\t\t\t//\t\t\t\thash[curX][curY][curDirection] = next - j;\n\t\t\t\t//\t\t\t} else break;\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tj++;\t\t\t\t\t\n\t\t\t\t\t\t}\n\t\t\t\t//\t}\t\n\t\t\t\t}\n//\t\t\t\twhile (!curQueue.isEmpty()) {\n//\t\t\t\t\t//int cur = curQueue.();\n//\t\t\t\t\tint curDirection = cur & 0x7;\n//\t\t\t\t\tint curY = (cur >> 3) & 0x1FF;\n//\t\t\t\t\tint curX = (cur >> 12) & 0x1FF;\n//\t\t\t\t\tif (hash[curX][curY][curDirection] < next) {\n//\t\t\t\t\t\thash[curX][curY][curDirection] = next;\n//\t\t\t\t\t\tint j = 1;\n//\t\t\t\t\t\twhile(true) {\n//\t\t\t\t\t\t\tcurX += dx[curDirection];\n//\t\t\t\t\t\t\tcurY += dy[curDirection];\n//\t\t\t\t\t\t//\tSystem.out.println(curX);\n//\t\t\t\t\t\t\tmask[curX][curY] = 1;\n//\t\t\t\t\t\t\tif (j == next) {\n//\t\t\t\t\t\t\t\tnewQueue.add(getStatus(curX, curY, (curDirection + 1) % 8));\n//\t\t\t\t\t\t\t\tint newDir = (curDirection - 1) % 8;\n//\t\t\t\t\t\t\t\tif (newDir < 0) newDir = 8 + newDir;\n//\t\t\t\t\t\t\t\tnewQueue.add(getStatus(curX, curY, (newDir) % 8));\n//\t\t\t\t\t\t\t\tbreak;\n//\t\t\t\t\t\t\t}\n//\t\t\t\t\t\t\tif (hash[curX][curY][curDirection] < next - j) {\n//\t\t\t\t\t\t\t\thash[curX][curY][curDirection] = next - j;\n//\t\t\t\t\t\t\t} else break;\t\t\t\t\t\t\t\n//\t\t\t\t\t\t\tj++;\t\t\t\t\t\n//\t\t\t\t\t\t}\n//\t\t\t\t\t}\t\t\t\t\t\n//\t\t\t\t}\n\t\t\t\tcurQueue = newQueue;\n\t\t\t}\n\t\t\t\n\t\t\tint res = 0;\n\t\t\tfor (int i = 0; i < MAX; i++) {\n\t\t\t\tfor (int j = 0; j < MAX; j++) {\n\t\t\t\t\tif (mask[i][j] == 1) res++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println(res);\n//\t\t\tSystem.out.println(mask[299][299]);\n\t\t}\n\t}\n\t\n\tpublic static int getStatus(int x, int y, int direction) {\n\t\tint result = 0;\n\t\tresult = x;\n\t\tresult = (result << 9) | y;\n\t\tresult = (result << 3) | direction;\n\t\t//result = (result << 3) | value;\n\t\treturn result;\n\t}\n\t\n\t\n\t\n}\n", "lang_cluster": "Java", "tags": ["dfs and similar", "brute force", "dp", "data structures", "implementation"], "code_uid": "d45a0aae1a149fe4fc2e496c6ef26b88", "src_uid": "a96bc7f93fe9d9d4b78018b49bbc68d9", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\n\npublic class Main {\n static void solve(InputReader reader, OutputWriter writer)\n throws IOException {\n // Scanner scan = new Scanner(System.in);\n String a = reader.readLine();\n char c = a.charAt(0);\n String s = reader.readLine();\n char[] cc = { 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a',\n 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', 'z', 'x', 'c',\n 'v', 'b', 'n', 'm', ',', '.', '/' };\n if(c == 'R'){\n for (int i = 0; i < s.length(); ++i){\n int index = 0;\n for (int k = 0; k < cc.length; ++k){\n if(s.charAt(i) == cc[k]){\n index = --k;\n // writer.println(index);\n break;\n }\n }\n if(i < s.length() - 1)\n writer.print(cc[index]);\n else\n writer.println(cc[index]);\n }\n }else{\n for (int i = 0; i < s.length(); ++i){\n int index = 0;\n for (int k = 0; k < cc.length; ++k){\n if(s.charAt(i) == cc[k]){\n index = ++k;\n break;\n }\n }\n if(i < s.length() - 1)\n writer.print(cc[index]);\n else\n writer.println(cc[index]);\n }\n }\n\n }\n\n public static void main(String[] args) throws Exception {\n InputReader reader = new InputReader(System.in);\n OutputWriter writer = new OutputWriter(System.out);\n try {\n solve(reader, writer);\n } catch (Exception e) {\n e.printStackTrace(System.out);\n } finally {\n writer.close();\n }\n }\n\n}\n\nclass InputReader extends BufferedReader {\n public InputReader(InputStream in) {\n super(new InputStreamReader(in));\n }\n}\n\nclass OutputWriter extends PrintWriter {\n public OutputWriter(PrintStream out) {\n super(new BufferedWriter(new OutputStreamWriter(out)));\n }\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "00733f0e929794c4b0f4b1772d4b9f9a", "src_uid": "df49c0c257903516767fdb8ac9c2bfd6", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class TheMonster {\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\tString[] p = in.readLine().split(\" \");\n\t\tint a = Integer.parseInt(p[0]);\n\t\tlong b = Long.parseLong(p[1]);\n\t\t\n\t\tboolean aa = a % 2 == 0;\n\t\tboolean bb = b % 2 == 0;\n\t\t\n\t\tString[] q = in.readLine().split(\" \");\n\t\tint c = Integer.parseInt(q[0]);\n\t\tlong d = Long.parseLong(q[1]);\n\t\t\n\t\tboolean cc = c % 2 == 0;\n\t\tboolean dd = d % 2 == 0;\n\t\t\n\t\tif(!((!bb && aa && dd && cc)||(!dd&&cc&&bb&&aa))) {\n\t\t\twhile(b != d) {\n\t\t\t\tif(b < d) {\n\t\t\t\t\tb+=a;\n\t\t\t\t} else {\n\t\t\t\t\td+=c;\n\t\t\t\t}\n\t\t\t\tif(d > 10000000) {\n\t\t\t\t\tb = -1;\n\t\t\t\t\td = -1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println(b);\n\t\t} else {\n\t\t\tSystem.out.println(-1);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "tags": ["brute force", "math", "number theory"], "code_uid": "1f8224994c32fe169828aa2e71242173", "src_uid": "158cb12d45f4ee3368b94b2b622693e7", "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.math.BigInteger;\nimport java.util.*;\n\npublic class A {\n\n int n, k;\n int[][] memo;\n \n private int dp(int index, int sum) {\n if (index == n && sum == k)\n return 0;\n if (sum > k)\n return 1 << 29;\n if (index == n)\n return 1 << 29;\n if (memo[index][sum] != -1)\n return memo[index][sum];\n int res = 1 << 28;\n for (int i = 2; i <= 5; i++) {\n res = Math.min(res, ((i == 2) ? 1 : 0) + dp(index + 1, sum + i));\n }\n return memo[index][sum] = res;\n }\n\n private void solve() throws IOException {\n memo = new int[55][255];\n for (int[] a : memo) Arrays.fill(a, -1);\n n = nextInt();\n k = nextInt();\n pl(dp(0, 0));\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 } 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 void p(Object... objects) {\n for (int i = 0; i < objects.length; i++) {\n if (i != 0)\n writer.print(' ');\n writer.flush();\n writer.print(objects[i]);\n writer.flush();\n }\n }\n\n void pl(Object... objects) {\n p(objects);\n writer.flush();\n writer.println();\n writer.flush();\n }\n\n int cc;\n\n void pf() {\n writer.printf(\"Case #%d: \", ++cc);\n writer.flush();\n }\n\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "ed41da3de3c85281052fc7d836db90db", "src_uid": "5a5e46042c3f18529a03cb5c868df7e8", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\n\nimport java.util.Scanner;\n\n\n\npublic class JavaApplication1 {\n\n \n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int[] a = new int[1001];\n for (int i=0; i 0) {\n\t\t\tint n = input.nextInt();\n\t\t\tString num = \"\"+n;\n\t\t\tn = n % 10;\n\t\t\tint sum = 0;\n\t\t\tfor (int i = 1; i < n; i++) sum += 10;\n\t\t\tfor (int i = 1; i < num.length()+1; i++) sum += i;\n\t\t\tSystem.out.println(sum);\n\t\t}\n\t\tinput.close();\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "7d187626cee8c001964570729283d6fa", "src_uid": "289a55128be89bb86a002d218d31b57f", "difficulty": 800.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.StringTokenizer;\n\npublic class EE {\n private static BufferedReader in;\n private static StringTokenizer st;\n private static PrintWriter out;\n private static int mod;\n \n public static void main(String[] args) throws NumberFormatException, IOException {\n in = new BufferedReader(new InputStreamReader(System.in));\n st = new StringTokenizer(\"\");\n out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n int a = nextInt();\n int b = nextInt();\n int n = nextInt();\n long s1 = System.currentTimeMillis();\n mod = (int) (1e9+7);\n long fact = 1;\n for (long i = 1; i <= n; i++) {\n fact = (fact * i) % mod;\n }\n long factinverse[] = new long[n+1];\n factinverse[0] = 1;\n for (int i = 1; i <=n; i++) {\n long x = ModPow(i, mod - 2);\n factinverse[i] = (factinverse[i-1] * x) % mod;\n }\n long ans = 0;\n for (int i = 0; i <=n; i++) {\n int x = i*a +(n-i)*b;\n if(good(x, a, b)){\n long f2 = (factinverse[i] * factinverse[n-i]) % mod; \n ans = (ans + f2) % mod;\n }\n }\n ans = (ans * fact) % mod;\n long s2 = System.currentTimeMillis();\n// System.out.println((s2-s1)/1000.0);\n System.out.println(ans);\n }\n private static long ModPow(long a, int n) {\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 private static boolean good(int x, int a, int b) {\n while(x > 0){\n int qol = x % 10;\n if(qol != a && qol!=b){\n return false;\n }\n x /= 10;\n }\n return true;\n }\n\n static String next() throws IOException{\n while(!st.hasMoreTokens()){\n st = new StringTokenizer(in.readLine());\n }\n return st.nextToken();\n }\n static int nextInt() throws NumberFormatException, IOException{\n return Integer.parseInt(next());\n }\n static long nextLong() throws NumberFormatException, IOException{\n return Long.parseLong(next());\n }\n \n static double nextDouble() throws NumberFormatException, IOException{\n return Double.parseDouble(next());\n }\n\n}", "lang_cluster": "Java", "tags": ["brute force", "combinatorics"], "code_uid": "e890a6f09a884cf0b4bc3e5e03a92b3c", "src_uid": "d3e3da5b6ba37c8ac5f22b18c140ce81", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.LinkedHashMap;\nimport java.util.Map;\n\npublic class Main {\n\tprivate static Object unexpected = null;\n\tprivate static final int mod = (int) 1E9 + 7;\n\tprivate static final int ibufsize = (1 << 15), obufsize = (1 << 14);\n\tprivate static int iNextByte, iNextIndex, iReadByteCount, oNextIndex;\n\tprivate static final byte ibuf[] = new byte[ibufsize], obuf[] = new byte[obufsize];\n\tprivate static InputStream is = System.in;\n\tprivate static OutputStream os = System.out;\n\n\tprivate Main() throws Exception {\n\t\tif (inFromFile) is = new FileInputStream(new File(\"\").getAbsolutePath() + \"/src/testdata/in.txt\");\n\t\tif (outToFile) os = new FileOutputStream(new File(\"\").getAbsolutePath() + \"/src/testdata/out.txt\");\n\t\tnextByte();\n\t\tsolve();\n\t\tis.close();\n\t\tflushOutBuf();\n\t}\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tnew Main();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\n\tprivate boolean isDigit(int cp) {\n\t\treturn '0' <= cp && cp <= '9';\n\t}\n\n\tprivate boolean isLowercase(int cp) {\n\t\treturn 'a' <= cp && cp <= 'z';\n\t}\n\n\tprivate boolean isUppercase(int cp) {\n\t\treturn 'A' <= cp && cp <= 'Z';\n\t}\n\n\tprivate boolean isAlphabet(int cp) {\n\t\treturn ('a' <= cp && cp <= 'z') || ('A' <= cp && cp <= 'Z');\n\t}\n\n\tprivate boolean isAlphanumberic(char ch) {\n\t\treturn (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z') || (ch >= 'A' || ch <= 'Z');\n\t}\n\n\tprivate boolean isWhitespace(int cp) {\n\t\treturn cp == ' ' || cp == '\\r' || cp == '\\n' || cp == '\\t';\n\t}\n\n\tprivate boolean isWordSeparator(int cp) {\n\t\treturn cp == ' ' || cp == '\\r' || cp == '\\n' || cp == '\\t';\n\t}\n\n\tprivate boolean isLineSeparator(int cp) {\n\t\treturn cp == '\\n' || cp == '\\r';\n\t}\n\n\tprivate boolean isUnexpected() {\n\t\treturn unexpected != null;\n\t}\n\n\tprivate Object setUnexpected(Object value) {\n\t\treturn (unexpected = value);\n\t}\n\n\tprivate boolean isNegative() throws IOException {\n\t\tboolean minus = false;\n\t\twhile (iNextByte == '+' || iNextByte == '-') {\n\t\t\tif (iNextByte == '-') minus = !minus;\n\t\t\tnextByte();\n\t\t}\n\t\treturn minus;\n\t}\n\n\tprivate int nextByte() throws IOException {\n\t\tif (iNextIndex >= iReadByteCount) {\n\t\t\tiReadByteCount = is.read(ibuf, 0, ibufsize);\n\t\t\tif (iReadByteCount == -1) return (iNextByte = -1);\n\t\t\tiNextIndex = 0;\n\t\t}\n\t\treturn (iNextByte = ibuf[iNextIndex++]);\n\t}\n\n\tprivate char nc() throws IOException {\n\t\treturn (char) nextByte();\n\t}\n\n\tprivate char[] nc(int n) throws IOException {\n\t\tchar a[] = new char[n];\n\t\tfor (int i = 0; i < n; ++i) a[i] = nc();\n\t\treturn a;\n\t}\n\n\tprivate char[][] nc(int r, int c) throws IOException {\n\t\tchar a[][] = new char[r][c];\n\t\tfor (int i = 0; i < r; ++i) a[i] = nc(c);\n\t\treturn a;\n\t}\n\n\tprivate int ni() throws IOException {\n\t\twhile (isWhitespace(iNextByte)) nextByte();\n\t\tint res = 0;\n\t\tboolean minus = isNegative();\n\t\tif (!isDigit(iNextByte)) return (int) setUnexpected(-1);\n\t\tdo {res = (res << 1) + (res << 3) + iNextByte - '0';} while (isDigit(nextByte()));\n\t\treturn minus ? -res : res;\n\t}\n\n\tprivate int[] ni(int n) throws IOException {\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\n\tprivate int[][] ni(int r, int c) throws IOException {\n\t\tint a[][] = new int[r][c];\n\t\tfor (int i = 0; i < r; ++i) a[i] = ni(c);\n\t\treturn a;\n\t}\n\n\tprivate long nl() throws IOException {\n\t\twhile (isWhitespace(iNextByte)) nextByte();\n\t\tlong res = 0;\n\t\tboolean minus = isNegative();\n\t\tif (!isDigit(iNextByte)) return (long) setUnexpected(-1);\n\t\tdo {res = (res << 1) + (res << 3) + iNextByte - '0';} while (isDigit(nextByte()));\n\t\treturn minus ? -res : res;\n\t}\n\n\tprivate long[] nl(int n) throws IOException {\n\t\tlong a[] = new long[n];\n\t\tfor (int i = 0; i < n; ++i) a[i] = nl();\n\t\treturn a;\n\t}\n\n\tprivate long[][] nl(int r, int c) throws IOException {\n\t\tlong a[][] = new long[r][c];\n\t\tfor (int i = 0; i < r; ++i) a[i] = nl(c);\n\t\treturn a;\n\t}\n\n\tprivate double nd() throws IOException {\n\t\twhile (isWhitespace(iNextByte)) nextByte();\n\t\tboolean minus = isNegative();\n\t\tif (!isDigit(iNextByte)) return (double) setUnexpected(-1.0);\n\t\tdouble decimal = 0, floating = 0, div = 1;\n\t\tdo {decimal = 10 * decimal + (iNextByte - '0');} while (isDigit(nextByte()));\n\t\tif (iNextByte == '.') while (isDigit(nextByte())) floating += (iNextByte - '0') / (div *= 10);\n\t\tdouble res = decimal + floating;\n\t\treturn minus ? -res : res;\n\t}\n\n\tprivate double[] nd(int n) throws IOException {\n\t\tdouble a[] = new double[n];\n\t\tfor (int i = 0; i < n; ++i) a[i] = nd();\n\t\treturn a;\n\t}\n\n\tprivate double[][] nd(int r, int c) throws IOException {\n\t\tdouble a[][] = new double[r][c];\n\t\tfor (int i = 0; i < r; ++i) a[i] = nd(c);\n\t\treturn a;\n\t}\n\n\tprivate String line() throws IOException {\n\t\twhile (isWhitespace(iNextByte)) nextByte();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (iNextByte != -1 && !isLineSeparator(iNextByte)) {\n\t\t\tsb.append((char) iNextByte);\n\t\t\tnextByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tprivate String ns() throws IOException {\n\t\twhile (isWordSeparator(iNextByte)) nextByte();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (iNextByte != -1 && !isWordSeparator(iNextByte)) {\n\t\t\tsb.append((char) iNextByte);\n\t\t\tnextByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tprivate String[] ns(int n) throws IOException {\n\t\tString a[] = new String[n];\n\t\tfor (int i = 0; i < n; ++i) a[i] = ns();\n\t\treturn a;\n\t}\n\n\tprivate String[][] ns(int r, int c) throws IOException {\n\t\tString a[][] = new String[r][c];\n\t\tfor (int i = 0; i < r; ++i) a[i] = ns(c);\n\t\treturn a;\n\t}\n\n\tprivate void flushOutBuf() {\n\t\tif (oNextIndex == 0) return;\n\t\ttry {\n\t\t\tos.write(obuf, 0, oNextIndex);\n\t\t\tos.flush();\n\t\t\toNextIndex = 0;\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\n\tprivate void puts(String format, Object... args) {\n\t\tif (args != null) format = String.format(format, args);\n\t\tfor (int i = 0, n = format.length(); i < n; ++i) {\n\t\t\tobuf[oNextIndex++] = (byte) format.charAt(i);\n\t\t\tif (oNextIndex >= obufsize) flushOutBuf();\n\t\t}\n\t}\n\n\tprivate void print(T ob) {\n\t\tputs(ob + \"\");\n\t}\n\n\tprivate void print(String format, Object... args) {\n\t\tputs(format, args);\n\t}\n\n\tprivate void println(T ob) {\n\t\tputs(ob + \"\\n\");\n\t}\n\n\tprivate void println(String format, Object... args) {\n\t\tputs(format + \"\\n\", args);\n\t}\n\n\tprivate void debug(T ob) {\n\t\tputs(\"\\u001B[31m\" + ob + \"\\u001B[0m\");\n\t}\n\n\tprivate void debug(String format, Object... args) {\n\t\tputs(\"\\u001B[31m\" + format + \"\\u001B[0m\", args);\n\t}\n\n\tprivate void debugln(T ob) {\n\t\tputs(\"\\u001B[31m\" + ob + \"\\u001B[0m\\n\");\n\t}\n\n\tprivate void debugln(String format, Object... args) {\n\t\tputs(\"\\u001B[31m\" + format + \"\\u001B[0m\\n\", args);\n\t}\n\n\tprivate void solve() throws Exception {\n\t\tchar a[] = ns().toCharArray();\n\t\tint hasOneBefore = 0, ans = 0;\n\t\tfor(int i = 0; i < a.length; ++i) {\n\t\t\tchar ch = a[i];\n\t\t\tif(a[i] == '1') {\n\t\t\t\thasOneBefore = 1;\n\t\t\t} else {\n\t\t\t\tans += hasOneBefore;\n\t\t\t}\n\t\t}\n\t\tprintln(ans >= 6? \"yes\":\"no\");\n\t}\n\n\tprivate static final boolean inFromFile = false, outToFile = false;\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "1f52146c049e3e38e8f410142b3f2166", "src_uid": "88364b8d71f2ce2b90bdfaa729eb92ca", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class button {\n\tpublic static void main(String args[]) throws Exception {\n\t\tScanner in;\n\t\ttry {\n\t\t\tin = new Scanner(new File(\"input23.txt\"));\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tin = new Scanner(System.in);\n\t\t}\n\t\tint n = in.nextInt(), m = in.nextInt(), count = 0;\n\t\twhile (m > n) {\n\t\t\tcount++;\n\t\t\tif (m % 2 == 1) {\n\t\t\t\tm++;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tm /= 2;\n\t\t\t}\n\t\t}\n\t\tcount += n - m;\n\t\tSystem.out.println(count);\n\t}\n}", "lang_cluster": "Java", "tags": ["dfs and similar", "shortest paths", "math", "graphs", "greedy", "implementation"], "code_uid": "249ae33a1b62c31b0af5e816139ace4e", "src_uid": "861f8edd2813d6d3a5ff7193a804486f", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.*;\n\npublic class Main {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n long n = in.nextLong();\n long part = 1 + (n-3)*3 + (n-4)*(n-3);\n p(part);\n }\n\n static void p(Object str){\n System.out.println(str);\n }\n}\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "f3a5dca82a33046e62c83ff6af95d730", "src_uid": "efa8e7901a3084d34cfb1a6b18067f2b", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class DashaandStairs {\n\n public static void main(String[]args){\n Scanner sc=new Scanner(System.in);\n int a=sc.nextInt();int b=sc.nextInt();\n if(a==0 && b==0)\n System.out.print(\"NO\");\n else\n if(a==b || a-b==1 || a-b==-1)\n System.out.print(\"YES\");\n else\n System.out.print(\"NO\");\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "math", "constructive algorithms", "implementation"], "code_uid": "ade6f1b81c901928320f711d5cd5c8e6", "src_uid": "ec5e3b3f5ee6a13eaf01b9a9a66ff037", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.Scanner;\npublic class newYearAndHurry\n{\n /*\n public static void main(String[] args)\n {\n Scanner s1=new Scanner(System.in);\n int n=s1.nextInt();\n int k=s1.nextInt();\n int ans=0;\n int sum=5;\n int i=2;\n while(240-k>=sum)\n {\n sum+=5*i;\n i++;\n ans++;\n if(ans> n) \n ans=n;\n }\n System.out.println(ans);\n }*/\n public static void main(String[] args)\n {\n Scanner s1=new Scanner(System.in);\n int n=s1.nextInt();\n int k=s1.nextInt();\n int time=240-k;\n int ans=0;\n int start=1;\n int end=240;\n while(start<=end)\n { \n int middle=(start+end)/2;\n int sum= 5 * (middle) *(middle+1) / 2;\n if (time>=sum)\n {\n //System.out.println(sum);\n start=middle+1;\n ans=start;\n }\n else\n {\n end=middle-1;\n }\n }\n if (ans>n)\n ans=n+1;\n if (ans<=0)\n ans=1;\n System.out.println(ans-1);\n }\n\n}", "lang_cluster": "Java", "tags": ["brute force", "math", "implementation", "binary search"], "code_uid": "e164a90d454299a07fe8e752bc3d4b13", "src_uid": "41e554bc323857be7b8483ee358a35e2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "//package round30;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class B {\n\tprivate Scanner in;\n\tprivate PrintWriter out;\n//\tprivate String INPUT = \"31.12.18\\n01.01.01\";\n//\tprivate String INPUT = \"01.01.98\\n01.01.80\";\n//\tprivate String INPUT = \"29.02.96\\n29.02.04\";\n//\tprivate String INPUT = \"20.10.20\\n09.02.30\";\n//\tprivate String INPUT = \"01.03.74\\n29.02.56\";\n\tprivate String INPUT = \"\";\n\t\n\tpublic void solve()\n\t{\n\t\tString[] ds = in.next().split(\"\\\\.\");\n\t\tString[] db = in.next().split(\"\\\\.\");\n\t\t\n\t\tint dd = Integer.parseInt(ds[0]);\n\t\tint mm = Integer.parseInt(ds[1]);\n\t\tint yy = Integer.parseInt(ds[2]);\n\t\tint[] t = new int[3];\n\t\tfor(int i = 0;i < 3;i++)t[i] = Integer.parseInt(db[i]);\n\t\t\n\t\t/*\n\t\tif(yy < t[2] ||\n\t\t\t\t(yy == t[2] && mm < t[1]) ||\n\t\t\t\t(yy == t[2] && mm == t[1] && dd < t[0])){\n\t\t\tout.println(\"NO\");\n\t\t\treturn;\n\t\t}\n\t\t*/\n\t\t\n\t\tif(\ttest(dd, mm, yy, t[0], t[1], t[2]) ||\n\t\t\t\ttest(dd, mm, yy, t[0], t[2], t[1]) ||\n\t\t\t\ttest(dd, mm, yy, t[1], t[0], t[2]) ||\n\t\ttest(dd, mm, yy, t[1], t[2], t[0]) ||\n\t\ttest(dd, mm, yy, t[2], t[1], t[0]) ||\n\t\ttest(dd, mm, yy, t[2], t[0], t[1])){\n\t\t\tout.println(\"YES\");\n\t\t}else{\n\t\t\tout.println(\"NO\");\n\t\t}\n\t}\n\t\n\tpublic boolean test(int dd, int mm, int yy, int bd, int bm, int by)\n\t{\n\t\tif(yy < by + 18)return false;\n\t\tif(bm > 12)return false;\n\t\tif(bd > 31)return false;\n\t\t\n\t\tint[] md = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};\n\t\tif(by % 4 == 0)md[2]++;\n\t\t/*\n\t\tif(by % 4 != 0 && bm == 2 && bd == 29){\n\t\t\tbm = 3; bd = 1;\n\t\t}\n\t\t*/\n//\t\tif(yy % 4 != 0 && mm == 2 && dd == 29){\n//\t\t\tmm = 3; dd = 1;\n//\t\t}\n\t\tif(bd > md[bm])return false;\n\t\t\n\t\tif(yy > by + 18)return true;\n\t\tif(bm != mm)return mm > bm;\n\t\treturn dd >= bd;\n\t}\n\t\n\tpublic void 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 B().run();\n\t}\n\t\n\tprivate int ni() { return Integer.parseInt(in.next()); }\n\tprivate void tr(Object... o) { if(INPUT.length() != 0)System.out.println(o.length > 1 || o[0].getClass().isArray() ? Arrays.deepToString(o) : o[0]); }\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "2fd2c6c9a78eb80459f6fc89502dbc99", "src_uid": "5418c98fe362909f7b28f95225837d33", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\r\n\r\nimport java.io.*;\r\n\r\nimport java.util.*;\r\n\r\n/**\r\n *\r\n * @author eslam\r\n */\r\npublic class IceCave {\r\n\r\n static class Kattio extends PrintWriter {\r\n\r\n private BufferedReader r;\r\n private StringTokenizer st;\r\n // standard input\r\n\r\n public Kattio() {\r\n this(System.in, System.out);\r\n }\r\n\r\n public Kattio(InputStream i, OutputStream o) {\r\n super(o);\r\n r = new BufferedReader(new InputStreamReader(i));\r\n }\r\n // USACO-style file input\r\n\r\n public Kattio(String problemName) throws IOException {\r\n super(problemName + \".out\");\r\n r = new BufferedReader(new FileReader(problemName + \".in\"));\r\n }\r\n // returns null if no more input\r\n\r\n String nextLine() {\r\n String str = \"\";\r\n try {\r\n str = r.readLine();\r\n } catch (IOException e) {\r\n e.printStackTrace();\r\n }\r\n return str;\r\n }\r\n\r\n public String next() {\r\n try {\r\n while (st == null || !st.hasMoreTokens()) {\r\n st = new StringTokenizer(r.readLine());\r\n }\r\n return st.nextToken();\r\n } catch (Exception e) {\r\n }\r\n return null;\r\n }\r\n\r\n public int nextInt() {\r\n return Integer.parseInt(next());\r\n }\r\n\r\n public double nextDouble() {\r\n return Double.parseDouble(next());\r\n }\r\n\r\n public long nextLong() {\r\n return Long.parseLong(next());\r\n }\r\n }\r\n\r\n // Beginning of the solution\r\n static Kattio input = new Kattio();\r\n static BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));\r\n static ArrayList> powerSet = new ArrayList<>();\r\n static long mod = (long) (Math.pow(10, 9) + 7);\r\n static int dp[][];\r\n\r\n public static void main(String[] args) throws IOException {\r\n int n = input.nextInt();\r\n long w = input.nextLong();\r\n log.write(bfs(w, n) + \"\\n\");\r\n log.flush();\r\n }\r\n\r\n public static int bfs(long w, int n) {\r\n Queue q = new ArrayDeque<>();\r\n q.add(w);\r\n HashMap h = new HashMap<>();\r\n h.put(w, 0);\r\n int min = Integer.MAX_VALUE;\r\n while (!q.isEmpty()) {\r\n long s = q.poll();\r\n if (n == String.valueOf(s).length()) {\r\n return h.get(s);\r\n }\r\n TreeSet t = new TreeSet<>();\r\n String e = s + \"\";\r\n for (int i = 0; i < e.length(); i++) {\r\n t.add(e.charAt(i) - '0');\r\n }\r\n for (Integer x : t) {\r\n long v = (long) x * s;\r\n if (String.valueOf(v).length() > n) {\r\n continue;\r\n }\r\n if (h.get(v) == null) {\r\n h.put(v, h.get(s) + 1);\r\n q.add(v);\r\n }\r\n }\r\n }\r\n return min == Integer.MAX_VALUE ? -1 : min;\r\n }\r\n\r\n public static int log2(long n) {\r\n int cnt = 0;\r\n while (n > 1) {\r\n n /= 2;\r\n cnt++;\r\n }\r\n return cnt;\r\n }\r\n\r\n public static int[] bfs(int node, ArrayList a[]) {\r\n Queue q = new LinkedList<>();\r\n q.add(node);\r\n int distances[] = new int[a.length];\r\n Arrays.fill(distances, -1);\r\n distances[node] = 0;\r\n while (!q.isEmpty()) {\r\n int parent = q.poll();\r\n ArrayList nodes = a[parent];\r\n\r\n int cost = distances[parent];\r\n for (Integer node1 : nodes) {\r\n if (distances[node1] == -1) {\r\n\r\n q.add(node1);\r\n distances[node1] = cost + 1;\r\n }\r\n }\r\n }\r\n return distances;\r\n }\r\n\r\n public static int get(int n) {\r\n int sum = 0;\r\n while (n > 0) {\r\n sum += n % 10;\r\n n /= 10;\r\n }\r\n return sum;\r\n }\r\n\r\n public static long primeFactors(int n) {\r\n long sum = 1;\r\n while (n % 2 == 0) {\r\n sum *= 2l;\r\n n /= 2;\r\n }\r\n for (int i = 3; i <= Math.sqrt(n); i += 2) {\r\n while (n % i == 0) {\r\n sum *= (long) i;\r\n n /= i;\r\n }\r\n if (n < i) {\r\n break;\r\n }\r\n }\r\n if (n > 2) {\r\n sum *= n;\r\n }\r\n return sum;\r\n }\r\n\r\n public static ArrayList printPrimeFactoriztion(int n) {\r\n ArrayList a = new ArrayList<>();\r\n for (int i = 1; i < Math.sqrt(n) + 1; i++) {\r\n if (n % i == 0) {\r\n if (isPrime(i)) {\r\n a.add(i);\r\n n /= i;\r\n i = 0;\r\n } else if (isPrime(n / i)) {\r\n a.add(n / i);\r\n n = i;\r\n i = 0;\r\n }\r\n }\r\n }\r\n return a;\r\n }\r\n\r\n// end of solution\r\n public static void genrate(int ind, long[] a, ArrayList sub) {\r\n if (ind == a.length) {\r\n powerSet.add(sub);\r\n return;\r\n }\r\n ArrayList have = new ArrayList<>();\r\n ArrayList less = new ArrayList<>();\r\n for (int i = 0; i < sub.size(); i++) {\r\n have.add(sub.get(i));\r\n less.add(sub.get(i));\r\n }\r\n have.add(a[ind]);\r\n genrate(ind + 1, a, have);\r\n genrate(ind + 1, a, less);\r\n }\r\n\r\n public static long factorial(long n) {\r\n if (n <= 1) {\r\n return 1;\r\n }\r\n long t = n - 1;\r\n while (t > 1) {\r\n n *= t;\r\n t--;\r\n }\r\n return n;\r\n }\r\n\r\n public static boolean isPalindrome(int n) {\r\n int t = n;\r\n int ans = 0;\r\n while (t > 0) {\r\n ans = ans * 10 + t % 10;\r\n t /= 10;\r\n }\r\n return ans == n;\r\n\r\n }\r\n\r\n static class tri {\r\n\r\n int x, y, z;\r\n\r\n public tri(int x, int y, int z) {\r\n this.x = x;\r\n this.y = y;\r\n this.z = z;\r\n }\r\n\r\n }\r\n\r\n static boolean isPrime(long num) {\r\n if (num == 1) {\r\n return false;\r\n }\r\n if (num == 2) {\r\n return true;\r\n }\r\n if (num % 2 == 0) {\r\n return false;\r\n }\r\n if (num == 3) {\r\n return true;\r\n }\r\n for (int i = 3; i <= Math.sqrt(num) + 1; i += 2) {\r\n if (num % i == 0) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n public static void prefixSum(int[] a) {\r\n for (int i = 1; i < a.length; i++) {\r\n a[i] = a[i] + a[i - 1];\r\n }\r\n }\r\n\r\n public static void suffixSum(long[] a) {\r\n for (int i = a.length - 2; i > -1; i--) {\r\n a[i] = a[i] + a[i + 1];\r\n }\r\n }\r\n\r\n static long mod(long a, long b) {\r\n long r = a % b;\r\n return r < 0 ? r + b : r;\r\n }\r\n\r\n public static long binaryToDecimal(String w) {\r\n long r = 0;\r\n long l = 0;\r\n for (int i = w.length() - 1; i > -1; i--) {\r\n long x = (w.charAt(i) - '0') * (long) Math.pow(2, l);\r\n r = r + x;\r\n l++;\r\n }\r\n return r;\r\n }\r\n\r\n public static String decimalToBinary(long n) {\r\n String w = \"\";\r\n while (n > 0) {\r\n w = n % 2 + w;\r\n n /= 2;\r\n }\r\n return w;\r\n }\r\n\r\n public static boolean isSorted(int[] a) {\r\n for (int i = 0; i < a.length - 1; i++) {\r\n if (a[i] > a[i + 1]) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n public static void print(int a[]) throws IOException {\r\n for (int i = 0; i < a.length; i++) {\r\n log.write(a[i] + \" \");\r\n }\r\n log.write(\"\\n\");\r\n }\r\n\r\n public static void read(int[] a) {\r\n for (int i = 0; i < a.length; i++) {\r\n a[i] = input.nextInt();\r\n\r\n }\r\n }\r\n\r\n static class pair {\r\n\r\n long x;\r\n long y;\r\n\r\n public pair(long x, long y) {\r\n this.x = x;\r\n this.y = y;\r\n }\r\n\r\n @Override\r\n public String toString() {\r\n return x + \" \" + y;\r\n }\r\n }\r\n\r\n public static long LCM(long x, long y) {\r\n return x / GCD(x, y) * y;\r\n }\r\n\r\n public static long GCD(long x, long y) {\r\n if (y == 0) {\r\n return x;\r\n }\r\n return GCD(y, x % y);\r\n }\r\n\r\n public static void simplifyTheFraction(long a, long b) {\r\n long GCD = GCD(a, b);\r\n System.out.println(a / GCD + \" \" + b / GCD);\r\n\r\n }\r\n\r\n /**\r\n */ // class RedBlackNode\r\n static class RedBlackNode> {\r\n\r\n /**\r\n * Possible color for this node\r\n */\r\n public static final int BLACK = 0;\r\n /**\r\n * Possible color for this node\r\n */\r\n public static final int RED = 1;\r\n // the key of each node\r\n public T key;\r\n\r\n /**\r\n * Parent of node\r\n */\r\n RedBlackNode parent;\r\n /**\r\n * Left child\r\n */\r\n RedBlackNode left;\r\n /**\r\n * Right child\r\n */\r\n RedBlackNode right;\r\n // the number of elements to the left of each node\r\n public int numLeft = 0;\r\n // the number of elements to the right of each node\r\n public int numRight = 0;\r\n // the color of a node\r\n public int color;\r\n\r\n RedBlackNode() {\r\n color = BLACK;\r\n numLeft = 0;\r\n numRight = 0;\r\n parent = null;\r\n left = null;\r\n right = null;\r\n }\r\n\r\n // Constructor which sets key to the argument.\r\n RedBlackNode(T key) {\r\n this();\r\n this.key = key;\r\n }\r\n }// end class RedBlackNode\r\n\r\n static class RedBlackTree> {\r\n\r\n // Root initialized to nil.\r\n private RedBlackNode nil = new RedBlackNode();\r\n private RedBlackNode root = nil;\r\n\r\n public RedBlackTree() {\r\n root.left = nil;\r\n root.right = nil;\r\n root.parent = nil;\r\n }\r\n\r\n // @param: X, The node which the lefRotate is to be performed on.\r\n // Performs a leftRotate around X.\r\n private void leftRotate(RedBlackNode x) {\r\n\r\n // Call leftRotateFixup() which updates the numLeft\r\n // and numRight values.\r\n leftRotateFixup(x);\r\n\r\n // Perform the left rotate as described in the algorithm\r\n // in the course text.\r\n RedBlackNode y;\r\n y = x.right;\r\n x.right = y.left;\r\n\r\n // Check for existence of y.left and make pointer changes\r\n if (!isNil(y.left)) {\r\n y.left.parent = x;\r\n }\r\n y.parent = x.parent;\r\n\r\n // X's parent is nul\r\n if (isNil(x.parent)) {\r\n root = y;\r\n } // X is the left child of it's parent\r\n else if (x.parent.left == x) {\r\n x.parent.left = y;\r\n } // X is the right child of it's parent.\r\n else {\r\n x.parent.right = y;\r\n }\r\n\r\n // Finish of the leftRotate\r\n y.left = x;\r\n x.parent = y;\r\n }// end leftRotate(RedBlackNode X)\r\n\r\n // @param: X, The node which the leftRotate is to be performed on.\r\n // Updates the numLeft & numRight values affected by leftRotate.\r\n private void leftRotateFixup(RedBlackNode x) {\r\n\r\n // Case 1: Only X, X.right and X.right.right always are not nil.\r\n if (isNil(x.left) && isNil(x.right.left)) {\r\n x.numLeft = 0;\r\n x.numRight = 0;\r\n x.right.numLeft = 1;\r\n } // Case 2: X.right.left also exists in addition to Case 1\r\n else if (isNil(x.left) && !isNil(x.right.left)) {\r\n x.numLeft = 0;\r\n x.numRight = 1 + x.right.left.numLeft\r\n + x.right.left.numRight;\r\n x.right.numLeft = 2 + x.right.left.numLeft\r\n + x.right.left.numRight;\r\n } // Case 3: X.left also exists in addition to Case 1\r\n else if (!isNil(x.left) && isNil(x.right.left)) {\r\n x.numRight = 0;\r\n x.right.numLeft = 2 + x.left.numLeft + x.left.numRight;\r\n\r\n } // Case 4: X.left and X.right.left both exist in addtion to Case 1\r\n else {\r\n x.numRight = 1 + x.right.left.numLeft\r\n + x.right.left.numRight;\r\n x.right.numLeft = 3 + x.left.numLeft + x.left.numRight\r\n + x.right.left.numLeft + x.right.left.numRight;\r\n }\r\n\r\n }// end leftRotateFixup(RedBlackNode X)\r\n\r\n // @param: X, The node which the rightRotate is to be performed on.\r\n // Updates the numLeft and numRight values affected by the Rotate.\r\n private void rightRotate(RedBlackNode y) {\r\n\r\n // Call rightRotateFixup to adjust numRight and numLeft values\r\n rightRotateFixup(y);\r\n\r\n // Perform the rotate as described in the course text.\r\n RedBlackNode x = y.left;\r\n y.left = x.right;\r\n\r\n // Check for existence of X.right\r\n if (!isNil(x.right)) {\r\n x.right.parent = y;\r\n }\r\n x.parent = y.parent;\r\n\r\n // y.parent is nil\r\n if (isNil(y.parent)) {\r\n root = x;\r\n } // y is a right child of it's parent.\r\n else if (y.parent.right == y) {\r\n y.parent.right = x;\r\n } // y is a left child of it's parent.\r\n else {\r\n y.parent.left = x;\r\n }\r\n x.right = y;\r\n\r\n y.parent = x;\r\n\r\n }// end rightRotate(RedBlackNode y)\r\n\r\n // @param: y, the node around which the righRotate is to be performed.\r\n // Updates the numLeft and numRight values affected by the rotate\r\n private void rightRotateFixup(RedBlackNode y) {\r\n\r\n // Case 1: Only y, y.left and y.left.left exists.\r\n if (isNil(y.right) && isNil(y.left.right)) {\r\n y.numRight = 0;\r\n y.numLeft = 0;\r\n y.left.numRight = 1;\r\n } // Case 2: y.left.right also exists in addition to Case 1\r\n else if (isNil(y.right) && !isNil(y.left.right)) {\r\n y.numRight = 0;\r\n y.numLeft = 1 + y.left.right.numRight\r\n + y.left.right.numLeft;\r\n y.left.numRight = 2 + y.left.right.numRight\r\n + y.left.right.numLeft;\r\n } // Case 3: y.right also exists in addition to Case 1\r\n else if (!isNil(y.right) && isNil(y.left.right)) {\r\n y.numLeft = 0;\r\n y.left.numRight = 2 + y.right.numRight + y.right.numLeft;\r\n\r\n } // Case 4: y.right & y.left.right exist in addition to Case 1\r\n else {\r\n y.numLeft = 1 + y.left.right.numRight\r\n + y.left.right.numLeft;\r\n y.left.numRight = 3 + y.right.numRight\r\n + y.right.numLeft\r\n + y.left.right.numRight + y.left.right.numLeft;\r\n }\r\n\r\n }// end rightRotateFixup(RedBlackNode y)\r\n\r\n public void insert(T key) {\r\n insert(new RedBlackNode(key));\r\n }\r\n\r\n // @param: z, the node to be inserted into the Tree rooted at root\r\n // Inserts z into the appropriate position in the RedBlackTree while\r\n // updating numLeft and numRight values.\r\n private void insert(RedBlackNode z) {\r\n\r\n // Create a reference to root & initialize a node to nil\r\n RedBlackNode y = nil;\r\n RedBlackNode x = root;\r\n\r\n // While we haven't reached a the end of the tree keep\r\n // tryint to figure out where z should go\r\n while (!isNil(x)) {\r\n y = x;\r\n\r\n // if z.key is < than the current key, go left\r\n if (z.key.compareTo(x.key) < 0) {\r\n\r\n // Update X.numLeft as z is < than X\r\n x.numLeft++;\r\n x = x.left;\r\n } // else z.key >= X.key so go right.\r\n else {\r\n\r\n // Update X.numGreater as z is => X\r\n x.numRight++;\r\n x = x.right;\r\n }\r\n }\r\n // y will hold z's parent\r\n z.parent = y;\r\n\r\n // Depending on the value of y.key, put z as the left or\r\n // right child of y\r\n if (isNil(y)) {\r\n root = z;\r\n } else if (z.key.compareTo(y.key) < 0) {\r\n y.left = z;\r\n } else {\r\n y.right = z;\r\n }\r\n\r\n // Initialize z's children to nil and z's color to red\r\n z.left = nil;\r\n z.right = nil;\r\n z.color = RedBlackNode.RED;\r\n\r\n // Call insertFixup(z)\r\n insertFixup(z);\r\n\r\n }// end insert(RedBlackNode z)\r\n\r\n // @param: z, the node which was inserted and may have caused a violation\r\n // of the RedBlackTree properties\r\n // Fixes up the violation of the RedBlackTree properties that may have\r\n // been caused during insert(z)\r\n private void insertFixup(RedBlackNode z) {\r\n\r\n RedBlackNode y = nil;\r\n // While there is a violation of the RedBlackTree properties..\r\n while (z.parent.color == RedBlackNode.RED) {\r\n\r\n // If z's parent is the the left child of it's parent.\r\n if (z.parent == z.parent.parent.left) {\r\n\r\n // Initialize y to z 's cousin\r\n y = z.parent.parent.right;\r\n\r\n // Case 1: if y is red...recolor\r\n if (y.color == RedBlackNode.RED) {\r\n z.parent.color = RedBlackNode.BLACK;\r\n y.color = RedBlackNode.BLACK;\r\n z.parent.parent.color = RedBlackNode.RED;\r\n z = z.parent.parent;\r\n } // Case 2: if y is black & z is a right child\r\n else if (z == z.parent.right) {\r\n\r\n // leftRotaet around z's parent\r\n z = z.parent;\r\n leftRotate(z);\r\n } // Case 3: else y is black & z is a left child\r\n else {\r\n // recolor and rotate round z's grandpa\r\n z.parent.color = RedBlackNode.BLACK;\r\n z.parent.parent.color = RedBlackNode.RED;\r\n rightRotate(z.parent.parent);\r\n }\r\n } // If z's parent is the right child of it's parent.\r\n else {\r\n\r\n // Initialize y to z's cousin\r\n y = z.parent.parent.left;\r\n\r\n // Case 1: if y is red...recolor\r\n if (y.color == RedBlackNode.RED) {\r\n z.parent.color = RedBlackNode.BLACK;\r\n y.color = RedBlackNode.BLACK;\r\n z.parent.parent.color = RedBlackNode.RED;\r\n z = z.parent.parent;\r\n } // Case 2: if y is black and z is a left child\r\n else if (z == z.parent.left) {\r\n // rightRotate around z's parent\r\n z = z.parent;\r\n rightRotate(z);\r\n } // Case 3: if y is black and z is a right child\r\n else {\r\n // recolor and rotate around z's grandpa\r\n z.parent.color = RedBlackNode.BLACK;\r\n z.parent.parent.color = RedBlackNode.RED;\r\n leftRotate(z.parent.parent);\r\n }\r\n }\r\n }\r\n // Color root black at all times\r\n root.color = RedBlackNode.BLACK;\r\n\r\n }// end insertFixup(RedBlackNode z)\r\n\r\n // @param: node, a RedBlackNode\r\n // @param: node, the node with the smallest key rooted at node\r\n public RedBlackNode treeMinimum(RedBlackNode node) {\r\n\r\n // while there is a smaller key, keep going left\r\n while (!isNil(node.left)) {\r\n node = node.left;\r\n }\r\n return node;\r\n }// end treeMinimum(RedBlackNode node)\r\n\r\n // @param: X, a RedBlackNode whose successor we must find\r\n // @return: return's the node the with the next largest key\r\n // from X.key\r\n public RedBlackNode treeSuccessor(RedBlackNode x) {\r\n\r\n // if X.left is not nil, call treeMinimum(X.right) and\r\n // return it's value\r\n if (!isNil(x.left)) {\r\n return treeMinimum(x.right);\r\n }\r\n\r\n RedBlackNode y = x.parent;\r\n\r\n // while X is it's parent's right child...\r\n while (!isNil(y) && x == y.right) {\r\n // Keep moving up in the tree\r\n x = y;\r\n y = y.parent;\r\n }\r\n // Return successor\r\n return y;\r\n }// end treeMinimum(RedBlackNode X)\r\n\r\n // @param: z, the RedBlackNode which is to be removed from the the tree\r\n // Remove's z from the RedBlackTree rooted at root\r\n public void remove(RedBlackNode v) {\r\n\r\n RedBlackNode z = search(v.key);\r\n\r\n // Declare variables\r\n RedBlackNode x = nil;\r\n RedBlackNode y = nil;\r\n\r\n // if either one of z's children is nil, then we must remove z\r\n if (isNil(z.left) || isNil(z.right)) {\r\n y = z;\r\n } // else we must remove the successor of z\r\n else {\r\n y = treeSuccessor(z);\r\n }\r\n\r\n // Let X be the left or right child of y (y can only have one child)\r\n if (!isNil(y.left)) {\r\n x = y.left;\r\n } else {\r\n x = y.right;\r\n }\r\n\r\n // link X's parent to y's parent\r\n x.parent = y.parent;\r\n\r\n // If y's parent is nil, then X is the root\r\n if (isNil(y.parent)) {\r\n root = x;\r\n } // else if y is a left child, set X to be y's left sibling\r\n else if (!isNil(y.parent.left) && y.parent.left == y) {\r\n y.parent.left = x;\r\n } // else if y is a right child, set X to be y's right sibling\r\n else if (!isNil(y.parent.right) && y.parent.right == y) {\r\n y.parent.right = x;\r\n }\r\n\r\n // if y != z, trasfer y's satellite data into z.\r\n if (y != z) {\r\n z.key = y.key;\r\n }\r\n\r\n // Update the numLeft and numRight numbers which might need\r\n // updating due to the deletion of z.key.\r\n fixNodeData(x, y);\r\n\r\n // If y's color is black, it is a violation of the\r\n // RedBlackTree properties so call removeFixup()\r\n if (y.color == RedBlackNode.BLACK) {\r\n removeFixup(x);\r\n }\r\n }// end remove(RedBlackNode z)\r\n\r\n // @param: y, the RedBlackNode which was actually deleted from the tree\r\n // @param: key, the value of the key that used to be in y\r\n private void fixNodeData(RedBlackNode x, RedBlackNode y) {\r\n\r\n // Initialize two variables which will help us traverse the tree\r\n RedBlackNode current = nil;\r\n RedBlackNode track = nil;\r\n\r\n // if X is nil, then we will start updating at y.parent\r\n // Set track to y, y.parent's child\r\n if (isNil(x)) {\r\n current = y.parent;\r\n track = y;\r\n } // if X is not nil, then we start updating at X.parent\r\n // Set track to X, X.parent's child\r\n else {\r\n current = x.parent;\r\n track = x;\r\n }\r\n\r\n // while we haven't reached the root\r\n while (!isNil(current)) {\r\n // if the node we deleted has a different key than\r\n // the current node\r\n if (y.key != current.key) {\r\n\r\n // if the node we deleted is greater than\r\n // current.key then decrement current.numRight\r\n if (y.key.compareTo(current.key) > 0) {\r\n current.numRight--;\r\n }\r\n\r\n // if the node we deleted is less than\r\n // current.key thendecrement current.numLeft\r\n if (y.key.compareTo(current.key) < 0) {\r\n current.numLeft--;\r\n }\r\n } // if the node we deleted has the same key as the\r\n // current node we are checking\r\n else {\r\n // the cases where the current node has any nil\r\n // children and update appropriately\r\n if (isNil(current.left)) {\r\n current.numLeft--;\r\n } else if (isNil(current.right)) {\r\n current.numRight--;\r\n } // the cases where current has two children and\r\n // we must determine whether track is it's left\r\n // or right child and update appropriately\r\n else if (track == current.right) {\r\n current.numRight--;\r\n } else if (track == current.left) {\r\n current.numLeft--;\r\n }\r\n }\r\n\r\n // update track and current\r\n track = current;\r\n current = current.parent;\r\n\r\n }\r\n\r\n }//end fixNodeData()\r\n\r\n // @param: X, the child of the deleted node from remove(RedBlackNode v)\r\n // Restores the Red Black properties that may have been violated during\r\n // the removal of a node in remove(RedBlackNode v)\r\n private void removeFixup(RedBlackNode x) {\r\n\r\n RedBlackNode w;\r\n\r\n // While we haven't fixed the tree completely...\r\n while (x != root && x.color == RedBlackNode.BLACK) {\r\n\r\n // if X is it's parent's left child\r\n if (x == x.parent.left) {\r\n\r\n // set w = X's sibling\r\n w = x.parent.right;\r\n\r\n // Case 1, w's color is red.\r\n if (w.color == RedBlackNode.RED) {\r\n w.color = RedBlackNode.BLACK;\r\n x.parent.color = RedBlackNode.RED;\r\n leftRotate(x.parent);\r\n w = x.parent.right;\r\n }\r\n\r\n // Case 2, both of w's children are black\r\n if (w.left.color == RedBlackNode.BLACK\r\n && w.right.color == RedBlackNode.BLACK) {\r\n w.color = RedBlackNode.RED;\r\n x = x.parent;\r\n } // Case 3 / Case 4\r\n else {\r\n // Case 3, w's right child is black\r\n if (w.right.color == RedBlackNode.BLACK) {\r\n w.left.color = RedBlackNode.BLACK;\r\n w.color = RedBlackNode.RED;\r\n rightRotate(w);\r\n w = x.parent.right;\r\n }\r\n // Case 4, w = black, w.right = red\r\n w.color = x.parent.color;\r\n x.parent.color = RedBlackNode.BLACK;\r\n w.right.color = RedBlackNode.BLACK;\r\n leftRotate(x.parent);\r\n x = root;\r\n }\r\n } // if X is it's parent's right child\r\n else {\r\n\r\n // set w to X's sibling\r\n w = x.parent.left;\r\n\r\n // Case 1, w's color is red\r\n if (w.color == RedBlackNode.RED) {\r\n w.color = RedBlackNode.BLACK;\r\n x.parent.color = RedBlackNode.RED;\r\n rightRotate(x.parent);\r\n w = x.parent.left;\r\n }\r\n\r\n // Case 2, both of w's children are black\r\n if (w.right.color == RedBlackNode.BLACK\r\n && w.left.color == RedBlackNode.BLACK) {\r\n w.color = RedBlackNode.RED;\r\n x = x.parent;\r\n } // Case 3 / Case 4\r\n else {\r\n // Case 3, w's left child is black\r\n if (w.left.color == RedBlackNode.BLACK) {\r\n w.right.color = RedBlackNode.BLACK;\r\n w.color = RedBlackNode.RED;\r\n leftRotate(w);\r\n w = x.parent.left;\r\n }\r\n\r\n // Case 4, w = black, and w.left = red\r\n w.color = x.parent.color;\r\n x.parent.color = RedBlackNode.BLACK;\r\n w.left.color = RedBlackNode.BLACK;\r\n rightRotate(x.parent);\r\n x = root;\r\n }\r\n }\r\n }// end while\r\n\r\n // set X to black to ensure there is no violation of\r\n // RedBlack tree Properties\r\n x.color = RedBlackNode.BLACK;\r\n }// end removeFixup(RedBlackNode X)\r\n\r\n // @param: key, the key whose node we want to search for\r\n // @return: returns a node with the key, key, if not found, returns null\r\n // Searches for a node with key k and returns the first such node, if no\r\n // such node is found returns null\r\n public RedBlackNode search(T key) {\r\n\r\n // Initialize a pointer to the root to traverse the tree\r\n RedBlackNode current = root;\r\n\r\n // While we haven't reached the end of the tree\r\n while (!isNil(current)) {\r\n\r\n // If we have found a node with a key equal to key\r\n if (current.key.equals(key)) // return that node and exit search(int)\r\n {\r\n return current;\r\n } // go left or right based on value of current and key\r\n else if (current.key.compareTo(key) < 0) {\r\n current = current.right;\r\n } // go left or right based on value of current and key\r\n else {\r\n current = current.left;\r\n }\r\n }\r\n\r\n // we have not found a node whose key is \"key\"\r\n return null;\r\n\r\n }// end search(int key)\r\n\r\n // @param: key, any Comparable object\r\n // @return: return's the number of elements greater than key\r\n public int numGreater(T key) {\r\n\r\n // Call findNumGreater(root, key) which will return the number\r\n // of nodes whose key is greater than key\r\n return findNumGreater(root, key);\r\n\r\n }// end numGreater(int key)\r\n\r\n // @param: key, any Comparable object\r\n // @return: return's teh number of elements smaller than key\r\n public int numSmaller(T key) {\r\n\r\n // Call findNumSmaller(root,key) which will return\r\n // the number of nodes whose key is greater than key\r\n return findNumSmaller(root, key);\r\n\r\n }// end numSmaller(int key)\r\n\r\n // @param: node, the root of the tree, the key who we must\r\n // compare other node key's to.\r\n // @return: the number of nodes greater than key.\r\n public int findNumGreater(RedBlackNode node, T key) {\r\n\r\n // Base Case: if node is nil, return 0\r\n if (isNil(node)) {\r\n return 0;\r\n } // If key is less than node.key, all elements right of node are\r\n // greater than key, add this to our total and look to the left\r\n else if (key.compareTo(node.key) < 0) {\r\n return 1 + node.numRight + findNumGreater(node.left, key);\r\n } // If key is greater than node.key, then look to the right as\r\n // all elements to the left of node are smaller than key\r\n else {\r\n return findNumGreater(node.right, key);\r\n }\r\n\r\n }// end findNumGreater(RedBlackNode, int key)\r\n\r\n /**\r\n * Returns sorted list of keys greater than key. Size of list will not\r\n * exceed maxReturned\r\n *\r\n * @param key Key to search for\r\n * @param maxReturned Maximum number of results to return\r\n * @return List of keys greater than key. List may not exceed\r\n * maxReturned\r\n */\r\n public List getGreaterThan(T key, Integer maxReturned) {\r\n List list = new ArrayList();\r\n getGreaterThan(root, key, list);\r\n return list.subList(0, Math.min(maxReturned, list.size()));\r\n }\r\n\r\n private void getGreaterThan(RedBlackNode node, T key,\r\n List list) {\r\n if (isNil(node)) {\r\n return;\r\n } else if (node.key.compareTo(key) > 0) {\r\n getGreaterThan(node.left, key, list);\r\n list.add(node.key);\r\n getGreaterThan(node.right, key, list);\r\n } else {\r\n getGreaterThan(node.right, key, list);\r\n }\r\n }\r\n\r\n // @param: node, the root of the tree, the key who we must compare other\r\n // node key's to.\r\n // @return: the number of nodes smaller than key.\r\n public int findNumSmaller(RedBlackNode node, T key) {\r\n\r\n // Base Case: if node is nil, return 0\r\n if (isNil(node)) {\r\n return 0;\r\n } // If key is less than node.key, look to the left as all\r\n // elements on the right of node are greater than key\r\n else if (key.compareTo(node.key) <= 0) {\r\n return findNumSmaller(node.left, key);\r\n } // If key is larger than node.key, all elements to the left of\r\n // node are smaller than key, add this to our total and look\r\n // to the right.\r\n else {\r\n return 1 + node.numLeft + findNumSmaller(node.right, key);\r\n }\r\n\r\n }// end findNumSmaller(RedBlackNode nod, int key)\r\n\r\n // @param: node, the RedBlackNode we must check to see whether it's nil\r\n // @return: return's true of node is nil and false otherwise\r\n private boolean isNil(RedBlackNode node) {\r\n\r\n // return appropriate value\r\n return node == nil;\r\n\r\n }// end isNil(RedBlackNode node)\r\n\r\n // @return: return's the size of the tree\r\n // Return's the # of nodes including the root which the RedBlackTree\r\n // rooted at root has.\r\n public int size() {\r\n\r\n // Return the number of nodes to the root's left + the number of\r\n // nodes on the root's right + the root itself.\r\n return root.numLeft + root.numRight + 1;\r\n }// end size()\r\n\r\n }// end class RedBlackTree\r\n}\r\n", "lang_cluster": "Java", "tags": ["brute force", "dfs and similar", "shortest paths", "dp", "data structures"], "code_uid": "d0b812468628eed7db52d156447738a4", "src_uid": "cedcc3cee864bf8684148df93804d029", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class CollectingBeatsisFun {\n public static void main(String args[]) {\n Scanner scan = new Scanner(System.in); \n int n = scan.nextInt()*2;\n int[] a = new int[10];\n for (int i = 0; i < 4; i++) {\n String s = scan.next();\n for (int j = 0; j < 4; j++) {\n if(s.charAt(j)!='.'){ \n \n ++a[s.charAt(j)-'0'];\n }\n }\n }\n for (int i = 0; i < 10; i++) {\n if(a[i]>n){\n \n System.out.println(\"NO\");\n return ;\n }\n }\n \n System.out.println(\"YES\");\n }\n \n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "7a77875aee88ce8e72e1888e01a62ce2", "src_uid": "5fdaf8ee7763cb5815f49c0c38398f16", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Main143A\n{\n static PrintWriter out=new PrintWriter(System.out);\n public static boolean check(int x,int y,int z,int p)\n {\n return x!=y&&z!=p&&x!=p&&y!=z&&x!=z&&y!=p;\n }\n \n \n public static void main(String[] args) throws IOException\n {\n Scanner sc=new Scanner(System.in);\n int r1=sc.nextInt();\n int r2=sc.nextInt();\n int c1=sc.nextInt();\n int c2=sc.nextInt();\n int d1=sc.nextInt();\n int d2=sc.nextInt();\n int x=0,y=0,z=0,p=0;\n boolean flag=false;\n for(x=1;x<=9;x++)\n {\n for(y=1;y<=9;y++)\n {\n for(z=1;z<=9;z++)\n {\n for(p=1;p<=9;p++)\n {\n if((x+y)==r1&&(x+z)==c1&&(y+p)==c2&&(z+p)==r2&&(x+p)==d1&&(y+z)==d2&&check(x,y,z,p))\n {\n flag=true;\n break;\n }\n }\n if(flag) break;\n }\n if(flag) break;\n }\n if(flag) break;\n }\n if(flag)\n {\n out.println(x+\" \"+y);\n out.println(z+\" \"+p);\n }\n else\n out.println(-1);\n out.flush();\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= 0 && x < 10 && y >= 0 && y < 10;\n }\n\n private boolean okD1(int x, int y) {\n for (int i = 1; i <= 4; i++) {\n if (!isOk(x - i, y + i)) return false;\n }\n int cX = 0, cE = 0;\n for (int i = 0; i <= 4; i++) {\n if (grid[x - i][y + i] == 'X') cX++;\n if (grid[x - i][y + i] == '.') cE++;\n }\n return cX == 4 && cE == 1;\n }\n\n private boolean okD2(int x, int y) {\n for (int i = 1; i <= 4; i++) {\n if (!isOk(x + i, y + i)) return false;\n }\n int cX = 0, cE = 0;\n for (int i = 0; i <= 4; i++) {\n if (grid[x + i][y + i] == 'X') cX++;\n if (grid[x + i][y + i] == '.') cE++;\n }\n return cX == 4 && cE == 1;\n }\n\n private boolean okD3(int x, int y) {\n for (int i = 1; i <= 4; i++) {\n if (!isOk(x + i, y - i)) return false;\n }\n int cX = 0, cE = 0;\n for (int i = 0; i <= 4; i++) {\n if (grid[x + i][y - i] == 'X') cX++;\n if (grid[x + i][y - i] == '.') cE++;\n }\n return cX == 4 && cE == 1;\n }\n\n private boolean okD4(int x, int y) {\n for (int i = 1; i <= 4; i++) {\n if (!isOk(x - i, y - i)) return false;\n }\n int cX = 0, cE = 0;\n for (int i = 0; i <= 4; i++) {\n if (grid[x - i][y - i] == 'X') cX++;\n if (grid[x - i][y - i] == '.') cE++;\n }\n return cX == 4 && cE == 1;\n }\n\n private boolean okV1(int x, int y) {\n for (int i = 1; i <= 4; i++) {\n if (!isOk(x - i, y)) return false;\n }\n int cX = 0, cE = 0;\n for (int i = 0; i <= 4; i++) {\n if (grid[x - i][y] == 'X') cX++;\n if (grid[x - i][y] == '.') cE++;\n }\n return cX == 4 && cE == 1;\n }\n\n private boolean okV2(int x, int y) {\n for (int i = 1; i <= 4; i++) {\n if (!isOk(x + i, y)) return false;\n }\n int cX = 0, cE = 0;\n for (int i = 0; i <= 4; i++) {\n if (grid[x + i][y] == 'X') cX++;\n if (grid[x + i][y] == '.') cE++;\n }\n return cX == 4 && cE == 1;\n }\n\n private boolean okH1(int x, int y) {\n for (int i = 1; i <= 4; i++) {\n if (!isOk(x, y - i)) return false;\n }\n int cX = 0, cE = 0;\n for (int i = 0; i <= 4; i++) {\n if (grid[x][y - i] == 'X') cX++;\n if (grid[x][y - i] == '.') cE++;\n }\n return cX == 4 && cE == 1;\n }\n\n private boolean okH2(int x, int y) {\n for (int i = 1; i <= 4; i++) {\n if (!isOk(x, y + i)) return false;\n }\n int cX = 0, cE = 0;\n for (int i = 0; i <= 4; i++) {\n if (grid[x][y + i] == 'X') cX++;\n if (grid[x][y + i] == '.') cE++;\n }\n return cX == 4 && cE == 1;\n }\n\n private boolean ok(int x, int y) {\n return okD1(x, y) || okD2(x, y) || okD3(x, y) || okD4(x, y) || okV1(x, y) || okV2(x, y) || okH1(x, y) || okH2(x, y);\n }\n\n }\n\n static class InputReader extends BufferedReader {\n public InputReader(InputStream in) {\n super(new InputStreamReader(in));\n }\n\n\n public void close() {\n try {\n super.close();\n } catch (Exception e) {\n System.err.println(Arrays.toString(e.getStackTrace()));\n }\n }\n\n\n public String readLine() {\n String s = null;\n try {\n s = super.readLine();\n } catch (Exception e) {\n System.err.println(Arrays.toString(e.getStackTrace()));\n }\n return s;\n }\n\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "97af40a10eeec8a51a1e8c295baea872", "src_uid": "d5541028a2753c758322c440bdbf9ec6", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n/**\n * @author Alvex - GoldenReam1503@gmail.com\n * Time: 10:41:13 AM\n * Date: Nov 15, 2015\n */\npublic class _255A_Gregs_Workout\n{\n private static class Output\n {\n private final PrintWriter printer;\n public void printLine(Object...objects) \n {\n print(objects);\n printer.println();\n }\n public void print(Object...objects) \n {\n int i;\n for (i=0;i=numberChars) \n {\n curChar = 0;\n try \n {\n numberChars = stream.read(Buffer);\n } \n catch (IOException e) \n {\n throw new InputMismatchException();\n }\n if (numberChars <= 0)\n return -1;\n }\n return Buffer[curChar++];\n }\n public int readInt() \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 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 return res * sgn;\n }\n }\n public static void main(String[] args)\n { \n Input in=new Input(System.in);\n Output out=new Output(System.out);\n int n=in.readInt();\n int a[]=new int[n],i;\n Map muscle=new LinkedHashMap<>();\n for(i=0;ibiceps)\n max=chest;\n else\n max=biceps;\n if(max=10) {\n if (c[0] == 'C') {\n if (c[1] == 'O') {\n if (c[2] == 'D') {\n if (c[3] == 'E') {\n if (c[4] == 'F') {\n if (c[5] == 'O') {\n if (c[6] == 'R') {\n if (c[7] == 'C') {\n if (c[8] == 'E') {\n if (c[9] == 'S') {\n {flag = true;}\n }\n else if(c[i] == 'S'){\n {flag = true;}\n }\n }\n else if(c[i] == 'S' && c[i-1]=='E'){\n {flag = true;}\n }\n }\n else if(c[i] == 'S' && c[i-1]=='E'\n && c[i-2] == 'C'){\n {flag = true;}\n }\n }\n else if(c[i] == 'S' && c[i-1]=='E'\n && c[i-2] == 'C' && c[i-3] == 'R'){\n {flag = true;}\n }\n }\n else if(c[i] == 'S' && c[i-1]=='E'\n && c[i-2] == 'C' && c[i-3] == 'R'\n && c[i-4] == 'O'){\n {flag = true;}\n }\n }\n else if(c[i] == 'S' && c[i-1]=='E'\n && c[i-2] == 'C' && c[i-3] == 'R'\n && c[i-4] == 'O' && c[i -5] == 'F'){\n {flag = true;}\n }\n }\n else if(c[i] == 'S' && c[i-1]=='E'\n && c[i-2] == 'C' && c[i-3] == 'R'\n && c[i-4] == 'O' && c[i -5] == 'F'\n && c[i-6] == 'E'){\n {flag = true;}\n }\n }\n else if(c[i] == 'S' && c[i-1]=='E'\n && c[i-2] == 'C' && c[i-3] == 'R'\n && c[i-4] == 'O' && c[i -5] == 'F'\n && c[i-6] == 'E' && c[i-7] =='D'){\n {flag = true;}\n }\n }\n else if(c[i] == 'S' && c[i-1]=='E'\n && c[i-2] == 'C' && c[i-3] == 'R'\n && c[i-4] == 'O' && c[i-5] == 'F'\n && c[i-6] == 'E' && c[i-7] =='D'\n && c[i-8] == 'O'){\n {flag = true;}\n }\n }\n else if(c[i] == 'S' && c[i-1]=='E'\n && c[i-2] == 'C' && c[i-3] == 'R'\n && c[i-4] == 'O' && c[i-5] == 'F'\n && c[i-6] == 'E' && c[i-7] =='D'\n && c[i-8] == 'O' && c[i -9] == 'C'){\n {flag = true;}\n }\n }\n if(flag){\n System.out.println(\"YES\");\n }\n else{\n System.out.println(\"NO\");\n }\n \n\n\n\n\n\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "9074b3616c1f1e1b3c95350d0266a03b", "src_uid": "bda4b15827c94b526643dfefc4bc36e7", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "// package CF1076;\n\nimport java.util.Scanner;\n\npublic class CF1076B {\n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n long m = s.nextLong();\n long ans;\n if (m % 2 == 0) {\n ans = m / 2;\n } else {\n long p = primeFactors(m);\n ans = (m - p) / 2 + 1;\n }\n System.out.println(ans);\n }\n\n public static long primeFactors(long n) {\n // Print the number of 2s that divide n\n\n while (n % 2 == 0) {\n return 2;\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 += 2) {\n // While i divides n, print i and divide n\n while (n % i == 0) {\n return 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 return n;\n\n return -1;\n }\n\n\n\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation", "number theory"], "code_uid": "516d94acd0456fe578d6b58f170cfa0e", "src_uid": "a1e80ddd97026835a84f91bac8eb21e6", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\n//527A\npublic class asd {\n\n /**\n * @param args\n */\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n long a = in.nextLong();\n long b = in.nextLong();\n in.close();\n long s = 1;\n \n while(true){\n if(a==b){\n System.out.println(s);\n break;\n }\n \n if(a==1){\n System.out.println(b+s-1);\n break;\n }\n else if(b==1){\n System.out.println(a+s-1);\n break;\n }\n /*\n if(ab){\n s++;\n a-=b;\n }\n */\n \n if(ab){\n long k = a/b;\n s+=k;\n a-=(k*b);\n } \n \n if (a==0 || b==0){\n System.out.println(s-1);\n break;\n }\n }\n }\n\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "f268bb7f48cf28f9829648151d0220c4", "src_uid": "ce698a0eb3f5b82de58feb177ce43b83", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/**\n * recursion\n */\nimport java.util.*;\n\nimport javax.lang.model.util.ElementScanner6;\npublic class recursion {\nstatic boolean check(int t){\n String m=\"\"+t;\n HashSetH=new HashSet<>();\n for(char ch:m.toCharArray()){\n if(H.contains(ch)){\n return false;\n }\n else\n H.add(ch);\n }\n \n return true;\n}\n public static void main(String[] args) {\n //intitalise the matrix to the on state\n int a[][]={\n {1,1,1},\n {1,1,1},\n {1,1,1}\n };\n Scanner scan=new Scanner(System.in);\n int b[][]=new int[3][3];\n for(int i=0;i<3;++i){\n for(int j=0;j<3;++j){\n b[i][j]=scan.nextInt();\n }\n }\n //changing the states\n for(int i=0;i<3;++i){\n for(int j=0;j<3;++j){\n if(b[i][j]!=0){\n int temp=b[i][j];\n if(b[i][j]%2==1){\n if(a[i][j]==1){\n a[i][j]=0;\n }\n else\n a[i][j]=1;\n \n if(j+1=0){\n if(a[i][j-1]==1){\n a[i][j-1]=0;\n }\n else\n a[i][j-1]=1;\n }\n \n \n if(i-1>=0){\n \n if(a[i-1][j]==1){\n a[i-1][j]=0;\n }\n else\n a[i-1][j]=1; \n }\n \n if(i+1=a[k-1] && a[i]>0)\n inc++;\n }\n System.out.println(inc);\n }\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "0fb14de1cb5bdfb3e9b065c52dfc82d6", "src_uid": "193ec1226ffe07522caf63e84a7d007f", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "//package Codeforces.Div2A_107;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n/*\n * some cheeky quote\n */\n\npublic class Main\n{\n FastScanner in;\n PrintWriter out;\n\n public void solve() throws IOException\n {\n int people = in.nextInt();\n int totalBear = in.nextInt() * in.nextInt();\n int totalLimes = in.nextInt() * in.nextInt();\n int totalSalt = in.nextInt();\n\n int toastBear = in.nextInt();\n int totalToastBear = toastBear * people;\n int toastSalt = in.nextInt() * people;\n\n int count = 0;\n while (true)\n {\n if (totalBear < totalToastBear || totalSalt < toastSalt || totalLimes < people)\n {\n break;\n }\n totalBear -= totalToastBear;\n totalSalt -= toastSalt;\n totalLimes -= people;\n count++;\n }\n System.out.println(count);\n\n }\n\n public void run()\n {\n try\n {\n in = new FastScanner();\n out = new PrintWriter(System.out);\n\n solve();\n\n out.close();\n } catch (IOException e)\n {\n e.printStackTrace();\n }\n }\n\n class FastScanner\n {\n BufferedReader br;\n StringTokenizer st;\n\n FastScanner()\n {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String next()\n {\n while (st == null || !st.hasMoreTokens())\n {\n try\n {\n st = new StringTokenizer(br.readLine());\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\n public static void main(String[] arg)\n {\n new Main().run();\n }\n}\n\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "add6c21992ba423c2fc31625f047d2e4", "src_uid": "67410b7d36b9d2e6a97ca5c7cff317c1", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.Scanner;\n \npublic class Dubstep\n{\n public static void main(String[] args)\n {\n Scanner in = new Scanner(System.in);\n String s = in.next();\n String ss[] = s.split(\"WUB\");\n for(int i = 0;i 0) {\n combination = combination | (1 << (length - 1));\n length--;\n }\n long result = -1;\n while (combination > 0) {\n long totalones = 0;\n long ot = 0;\n for (int i = 0; i < totalbit; i++) {\n if ((combination & (1 << i)) != 0) {\n if (ot == 0 && str.charAt(i) == '0') {\n break;\n }\n ot = ot * 10 + str.charAt(i) - '0';\n totalones++;\n }\n }\n if (ot > 0 && Math.sqrt(ot) == (long) Math.sqrt(ot)) {\n if (result < totalones) {\n result = totalones;\n }\n }\n combination--;\n }\n if (result == -1) {\n totalbit = result - 1;\n }\n out.println(totalbit - result);\n\n }\n\n }\n\n static class Scan {\n private byte[] buf = new byte[1024];\n private int index;\n private InputStream in;\n private int total;\n\n public Scan() {\n in = System.in;\n }\n\n public Scan(InputStream inputStream) {\n in = inputStream;\n }\n\n public int scan() {\n if (total < 0) {\n return 0;\n }\n if (index >= total) {\n index = 0;\n try {\n total = in.read(buf);\n } catch (Exception e) {\n System.out.println(e);\n }\n if (total <= 0)\n return -1;\n\n }\n return buf[index++];\n }\n\n public long scanLong() {\n long lng = 0;\n int n = scan();\n while (isWhiteSpace(n))\n n = scan();\n int neg = 1;\n if (n == '-') {\n neg = -1;\n n = scan();\n }\n while (!isWhiteSpace(n) && n != '.') {\n if (n >= '0' && n <= '9') {\n lng *= 10;\n lng += n - '0';\n n = scan();\n } else throw new InputMismatchException();\n }\n if (n == '.') {\n n = scan();\n long temp = 1;\n while (!isWhiteSpace(n)) {\n if (n >= '0' && n <= '9') {\n temp /= 10;\n lng += (n - '0') * temp;\n n = scan();\n } else throw new InputMismatchException();\n }\n }\n return neg * lng;\n }\n\n private boolean isWhiteSpace(int n) {\n if (n == ' ' || n == '\\n' || n == '\\r' || n == '\\t' || n == -1)\n return true;\n return false;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["brute force", "math", "implementation"], "code_uid": "057fa4fb5b35fe0be7fbe89e8b7df535", "src_uid": "fa4b1de79708329bb85437e1413e13df", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.math.*;\npublic class h {\n\tpublic static void main(String[] args){\n\t\tScanner br = new Scanner(System.in);\n\t\tlong n = br.nextInt();\n\t\tBigInteger temp = new BigInteger(\"1\");\n\t\ttemp = temp.multiply(BigInteger.valueOf(n));\n\t\ttemp = temp.multiply(BigInteger.valueOf(n-1));\n\t\ttemp = temp.multiply(BigInteger.valueOf(n-2));\n\t\ttemp = temp.multiply(BigInteger.valueOf(n-3));\n\t\ttemp = temp.multiply(BigInteger.valueOf(n-4));\n\t\ttemp = temp.multiply(temp);\n\t\ttemp = temp.divide(BigInteger.valueOf(2));\n\t\ttemp = temp.divide(BigInteger.valueOf(3));\n\t\ttemp = temp.divide(BigInteger.valueOf(4));\n\t\ttemp = temp.divide(BigInteger.valueOf(5));\n\t\t\n\t\t\n\t\tSystem.out.println(temp.longValue());\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "combinatorics"], "code_uid": "317f6e8894b02de8f3b8f425d467a955", "src_uid": "92db14325cd8aee06b502c12d2e3dd81", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "\nimport java.io.*;\nimport java.util.*;\n\npublic class DigitalRoot\n{\n\tpublic Scanner in = new Scanner(System.in);\n\tpublic PrintStream out = System.out;\n\n\tpublic int N;\n\t\n\tpublic void main()\n\t{\n\t\tN = in.nextInt();\n\t\t\n\t\tint x, y, z;\n\t\tlong res = 0;\n\t\t\n\t\tlong A, B, C;\n\t\tint a, b;\n\t\t\n\t\tfor(z=1;z<=9;++z) for(x=1;x<=9;++x) for(y=1;y<=9;++y) if(z == d(x*y))\n\t\t{\n\t\t\tC = count(9, z);\n\t\t\tA = count(9, x);\n\t\t\tB = count(9, y);\n\t\t\t\n\t\t\tres += A * B * C;\n\t\t\t\n\t\t\tfor(int k=0; k*9+x <=N;++k)\n\t\t\t{\n\t\t\t\ta = k*9*9 + 9*x;\n\t\t\t\tb = k*9*y + x*y;\n\t\t\t\tres -= count(a, b);\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.println(res);\n\t}//end public void main()\n\n\tpublic int d(int x)\n\t{\n\t\tif(x%9 == 0) return 9;\n\t\treturn x%9;\n\t}\n\t\n\tpublic int count(int a, int b)\n\t{\n\t\tif(N < b) return 0;\n\t\treturn (N - b)/a + 1;\n\t}\n\t\n\tpublic static void main(String[] args)\n\t{\n\t\t(new DigitalRoot()).main();\n\t}\n}\n\n", "lang_cluster": "Java", "tags": ["number theory"], "code_uid": "796df857b86283788e24b2012c92191f", "src_uid": "fc133fe6353089a0ebee08dec919f608", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class n148A {\n\n Scanner in;\n PrintWriter out;\n\n void solve() {\n int k = in.nextInt();\n int l = in.nextInt();\n int m = in.nextInt();\n int n = in.nextInt();\n int d = in.nextInt();\n boolean used[] = new boolean[1 + d];\n for (int i = 1; i <= d; i++) {\n if (i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0) {\n used[i] = true;\n }\n }\n int kol = 0;\n for (int i = 1; i <= d; i++) {\n if (used[i]) {\n kol++;\n }\n }\n out.println(kol);\n }\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 public static void main(String[] args) {\n new n148A().run();\n\n }\n\n}\n", "lang_cluster": "Java", "tags": ["math", "constructive algorithms", "implementation"], "code_uid": "5574cb64ef75c7ec69922e9280296336", "src_uid": "46bfdec9bfc1e91bd2f5022f3d3c8ce7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\n\npublic class Domino {\n\tstatic Scanner scn = new Scanner(System.in);\n\n\tpublic static void main(String[] args) {\n\n\t\thelper();\n\t}\n\n\tpublic static void helper() {\n\n\t\tint n = (int)input();\n\t\tint[][] arr = new int[n][2];\n\t\tint s1 = 0, s2 = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tarr[i][0] = (int)input();\n\t\t\tarr[i][1] = (int)input();\n\t\t\ts1 += arr[i][0];\n\t\t\ts2 += arr[i][1];\n\t\t}\n\n\t\tif ((s1 & 1) == 0 && (s2 & 1) == 0) {\n\t\t\tprint(0);\n\t\t\treturn;\n\t\t}\n\n\t\tif ((s1 & 1) == 1 && (s2 & 1) == 1) {\n\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (((arr[i][0] & 1) ^ (arr[i][1] & 1)) == 1) {\n\t\t\t\t\tprint(1);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tprint(-1);\n\n\t}\n\n\n\tpublic static long input() {\n\t\treturn scn.nextLong();\n\t}\n\n\tpublic static String input(int... var) {\n\t\treturn scn.next();\n\t}\n\n\tpublic static void TakeInput(int[] arr) {\n\t\tfor (int i = 0; i < arr.length; i++)\n\t\t\tarr[i] = (int)input();\n\t}\n\n\tpublic static void TakeInput(long[] arr) {\n\t\tfor (int i = 0; i < arr.length; i++)\n\t\t\tarr[i] = input();\n\t}\n\n\tpublic static void printArray(int[] arr) {\n\t\tfor (int val : arr)\n\t\t\tprint(val + \" \");\n\n\t\tprint(\"\\n\");\n\t}\n\n\tpublic static void printArray(long[] arr) {\n\t\tfor (long val : arr)\n\t\t\tprint(val + \" \");\n\n\t\tprint(\"\\n\");\n\t}\n\n\tpublic static void print(T t) {\n\t\tSystem.out.print(t);\n\t}\n\tpublic static void print() {\n\t\tSystem.out.println();\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "0f68d2ecf2adfa24dbc8a8fd581a7fe5", "src_uid": "f9bc04aed2b84c7dd288749ac264bb43", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\npublic class contest17 {\n public static void main(String[] args) {\n try\n {\n Scanner s=new Scanner(System.in);\n int n=s.nextInt();\n int ans=0,min=0;\n int b[]=new int[n];\n int a[]=new int[n];\n for(int i=0;imin)\n {\n min=b[i+1]-b[i];\n }\n }\n System.out.println(min);\n }\n catch(Exception e)\n {\n System.out.println(e.getMessage());\n }\n }\n \n}\n", "lang_cluster": "Java", "tags": ["brute force", "math", "implementation"], "code_uid": "d2fe016067c5455252a6ffdaed1ade9b", "src_uid": "8a8013f960814040ac4bf229a0bd5437", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.Console;\nimport java.util.Arrays;\nimport java.io.*;\nimport java.lang.Integer;\n\npublic class problemA {\n\t\n\tpublic static void main (String args[]) throws IOException {\n\n\t\tBufferedReader in;\n\n\t\tif (System.getProperty(\"ONLINE_JUDGE\") != null) {\n in = new BufferedReader(new InputStreamReader(System.in));\n } else {\n in = new BufferedReader(new FileReader(\"input.txt\"));\n }\n\n\n String numApplesString = in.readLine();\n int n = Integer.parseInt(numApplesString);\n String [] weights = in.readLine().split(\" \");\n in.close();\n\n int i = 0;\n int sum = 0;\n\n while (i < n) {\n \tsum += Integer.parseInt(weights[i]);\n \ti++;\n }\n\n if ((sum == n * 200) && (n % 2 == 1)) {\n \tSystem.out.println(\"NO\");\n }\n else if ((sum % 200 == 0 && n > 1)) {\n \tSystem.out.println(\"YES\");\n } else {\n \tSystem.out.println(\"NO\");\n }\n\n \n }\n\n\n}", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "8451804448509d30c65c44141e0a309a", "src_uid": "9679acef82356004e47b1118f8fc836a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class password {\n\n public static void main (String[]args) {\n \tScanner sc=new Scanner(System.in);\n \tString x=sc.nextLine();\n \tboolean l=x.length()>=5;\n \tboolean E=false;\n \tboolean e=false;\n \tboolean d=false;\n \tif(l)\n \tfor(int i=0 ;i='a'&&x.charAt(i)<='z')\n \t\t\te=true;\n \t\telse\n \t\t if(x.charAt(i)>='A'&&x.charAt(i)<='Z')\n \t\t \tE=true;\n \t\t else\n \t\t \tif(x.charAt(i)>='0'&&x.charAt(i)<='9')\n \t\t \t\td=true;\n \t}\n System.out.print(l&E&e&d?\"Correct\":\"Too weak\");\n }\n\n\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "a8313b4228fd247af81aade86f3b6589", "src_uid": "42a964b01e269491975965860ec92be7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class BigRecursion {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt(); int m = sc.nextInt();\n int[] a = new int[n];\n int[] b = new int[m];\n for(int i=0;iMath.abs(i-b)){\n lw++;\n }else if(Math.abs(i-a)==Math.abs(i-b)){\n d++;\n }\n }\n System.out.println(fw +\" \"+d+\" \"+lw);\n\n\n\n\n }\n\n }", "lang_cluster": "Java", "tags": ["brute force"], "code_uid": "fa89e45e594cdc25c5bf1793ca9deea4", "src_uid": "504b8aae3a3abedf873a3b8b127c5dd8", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n static class Assertion {\n static void check(boolean e) {\n if (!e) {\n throw new Error();\n }\n }\n }\n\n // class Scanner {\n // StreamTokenizer in;\n //\n // Scanner(InputStream s) {\n // in = new StreamTokenizer(new BufferedReader(new InputStreamReader(s)));\n // in.resetSyntax();\n // in.whitespaceChars(0, 32);\n // in.wordChars(33, 255);\n // }\n //\n // String next() {\n // try {\n // in.nextToken();\n // return in.sval;\n // } catch (Exception e) {\n // throw new Error();\n // }\n // }\n //\n // int nextInt() {\n // return Integer.parseInt(next());\n // }\n //\n // long nextLong() {\n // return Long.parseLong(next());\n // }\n //\n // double nextDobule() {\n // return Double.parseDouble(next());\n // }\n // }\n\n Scanner in;\n PrintWriter out;\n\n void solve() {\n int nOld = in.nextInt();\n int nChilds = in.nextInt();\n if (nOld == 0 && nChilds>0) {\n out.println(\"Impossible\");\n } else {\n int min = 0;\n if (nOld >= nChilds) {\n min += nOld;\n } else {\n min += nOld + (nChilds - nOld);\n }\n int max = nOld + Math.max(0,nChilds - 1);\n out.println(min + \" \" + max);\n }\n }\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 public static void main(String[] args) {\n new Main().run();\n }\n}", "lang_cluster": "Java", "tags": ["math", "greedy"], "code_uid": "9c0f31328d02841025a7e0de96a40041", "src_uid": "1e865eda33afe09302bda9077d613763", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Main {\n\n private static int m;\n private static int b;\n\n private static long sum(long x, long y) {\n return (x + 1) * (y + 1) * (x + y) / 2;\n }\n\n private static long y(long x) {\n return (long) (-(double) x / m + b);\n }\n\n private static long x(long y) {\n return m * (b - y);\n }\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n m = in.nextInt();\n b = in.nextInt();\n\n long max = 0;\n\n for (int y = 0; y <= b; ++y) {\n long s = sum(x(y), y);\n if (max < s)\n max = s;\n }\n\n System.out.println(max);\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "math"], "code_uid": "9954f87306c7a0ba50aedae421889c9c", "src_uid": "9300f1c07dd36e0cf7e6cb7911df4cf2", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class ExA {\npublic static void main(String[] args) {\n\t\t\n\t\tScanner scanner = new Scanner(System.in);\n\t\tint r = scanner.nextInt();\n\t\tint g = scanner.nextInt();\n\t\tint b = scanner.nextInt();\n\t\t\n\t\tint counter = 30;\n\t\t\n\t\tif (r>=2){\n\t\t\tint n=r/2;\n\t\t\tint rem=r%2;\n\t\t\tif (rem==0){\n\t\t\t\tcounter+=(n-1)*3;\n\t\t\t\tg-=(n-1)*2;\n\t\t\t\tb-=(n-1)*2;\n\t\t\t}\n\t\t\telse if (rem==1){\n\t\t\t\tcounter+=n*3;\n\t\t\t\tg-=n*2;\n\t\t\t\tb-=n*2;\n\t\t\t}\n\t\t}\n\t\tif (g>0){\n\t\t\tcounter++;\n\t\t\tif (g>=3){\n\t\t\t\tint n=g/2;\n\t\t\t\tint rem=g%2;\n\t\t\t\tif (rem==0){\n\t\t\t\t\tcounter+=(n-1)*3;\n\t\t\t\t\tb-=(n-1)*2;\n\t\t\t\t}\n\t\t\t\telse if (rem==1){\n\t\t\t\t\tcounter+=n*3;\n\t\t\t\t\tb-=n*2;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (g<=0 && b>0){\n\t\t\tcounter++;\n\t\t}\n\t\tif (b>0) {\n\t\t\tcounter++;\n\t\t\tif (b>=3){\n\t\t\t\tint n=b/2;\n\t\t\t\tint rem=b%2;\n\t\t\t\tif (rem==0){\n\t\t\t\t\tcounter+=(n-1)*3;\n\t\t\t\t}\n\t\t\t\telse if (rem==1){\n\t\t\t\t\tcounter+=n*3;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(counter);\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "greedy"], "code_uid": "eed924db4e4faffa5de82064966cf20d", "src_uid": "a45daac108076102da54e07e1e2a37d7", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Gravity_Flip {\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 arr[]=new int[n];\n\t\tfor(int i=0;i happiens;\n \n int[] cur = {4,0,0,0,0,0,0,0,0};\n \n boolean Generate(){\n \tint c = 0;\n \tdo{\n \t\tif(cur[c] == 4){\n \t\t\tcur[c] = 7;\n \t\t\tString s = \"\";\n \t\t\tfor(int i = 8; i >= 0; i--){\n \t\t\t\ts += Integer.toString(cur[i]);\n \t\t\t}\n \t\t\thappiens.add(Long.parseLong(s));\n \t\t\treturn true;\n \t\t}\n \t\tif(cur[c] == 0){\n \t\t\tcur[c] = 4;\n \t\t\tString s = \"\";\n \t\t\tfor(int i = 8; i >= 0; i--){\n \t\t\t\ts += Integer.toString(cur[i]);\n \t\t\t}\n \t\t\thappiens.add(Long.parseLong(s));\n \t\t\treturn true;\n \t\t}\n \t\t\n \t\t\tcur[c] = 4;\n \t\t\tc++;\n \t\t\tif(c >= 9){\n \t\t\t\treturn false;\n \t\t\t\n \t\t}\n \t\t\n \t}while(true);\n }\n \n void solve() throws IOException{\n \tlong l = readInt();\n \tlong r = readInt();\n \thappiens = new ArrayList();\n \thappiens.add((long) 4);\n \tboolean c = true;\n \tdo{\n \t\tc = Generate();\n \t}while(c);\n \tlong max = Long.parseLong(\"4444444444\");\n \thappiens.add(max);\n \tlong summ = 0;\n \tint begin = 0, end = 0;\n \tfor(int i = 0; i < happiens.size(); i++){\n \t\tif(happiens.get(i) >= l){\n \t\t\tbegin = i;\n \t\t\tbreak;\n \t\t}\n \t}\n \tfor(int i = 0; i < happiens.size(); i++){\n \t\tif(happiens.get(i) >= r){\n \t\t\tend = i;\n \t\t\tbreak;\n \t\t}\n \t}\n \tif(begin == end){\n \t\tsumm = (r-l+1)*happiens.get(end);\n \t\tout.println(summ);\n \t\treturn;\n \t}\n \tlong curIndex = l;\n \tfor(int i = begin; i < end; i++){\n \t\tsumm += (happiens.get(i) - curIndex + 1)*happiens.get(i);\n \t\tcurIndex = happiens.get(i)+1;\n \t}\n \tsumm += (r-curIndex + 1)*happiens.get(end);\n \tout.println(summ);\n \t\n }\n \n int ModExp(int a, int n, int mod){\n \tint res = 1;\n \twhile (n!=0)\n \t\tif ((n & 1) != 0) {\n \t\t\tres = (res*a)%mod;\n \t\t\t--n;\n \t\t}\n \t\telse {\n \t\t\ta = (a*a)%mod;\n \t\t\tn >>= 1;\n \t\t}\n \treturn res;\n }\n \n \n static class Utils {\n \n private Utils() {}\n \n public static void mergeSort(int[] a) {\n mergeSort(a, 0, a.length - 1);\n }\n \n private static void mergeSort(int[] a, int leftIndex, int rightIndex) {\n final int MAGIC_VALUE = 50;\n if (leftIndex < rightIndex) {\n if (rightIndex - leftIndex <= MAGIC_VALUE) {\n insertionSort(a, leftIndex, rightIndex);\n } else {\n int middleIndex = (leftIndex + rightIndex) / 2;\n mergeSort(a, leftIndex, middleIndex);\n mergeSort(a, middleIndex + 1, rightIndex);\n merge(a, leftIndex, middleIndex, rightIndex);\n }\n }\n }\n \n private static void merge(int[] a, int leftIndex, int middleIndex, int rightIndex) {\n int length1 = middleIndex - leftIndex + 1;\n int length2 = rightIndex - middleIndex;\n int[] leftArray = new int[length1];\n int[] rightArray = new int[length2];\n System.arraycopy(a, leftIndex, leftArray, 0, length1);\n System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);\n for (int k = leftIndex, i = 0, j = 0; k <= rightIndex; k++) {\n if (i == length1) {\n a[k] = rightArray[j++];\n } else if (j == length2) {\n a[k] = leftArray[i++];\n } else {\n a[k] = leftArray[i] <= rightArray[j] ? leftArray[i++] : rightArray[j++];\n }\n }\n }\n \n private static void insertionSort(int[] a, int leftIndex, int rightIndex) {\n for (int i = leftIndex + 1; i <= rightIndex; i++) {\n int current = a[i];\n int j = i - 1;\n while (j >= leftIndex && a[j] > current) {\n a[j + 1] = a[j];\n j--;\n }\n a[j + 1] = current;\n }\n } \n }\n \n \n \n boolean isPrime(int a){\n \tfor(int i = 2; i <= sqrt(a); i++)\n \t\tif(a % i == 0) return false;\n \treturn true;\n }\n \n static double distance(long x1, long y1, long x2, long y2){\n \treturn Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));\n }\n \n static long gcd(long a, long b){\n \tif(min(a,b) == 0) return max(a,b);\n \treturn gcd(max(a, b) % min(a,b), min(a,b));\n }\n \n static long lcm(long a, long b){\n \treturn a * b /gcd(a, b);\n }\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "7aeb65184665c706c2a6da6180ed83ac", "src_uid": "8a45fe8956d3ac9d501f4a13b55638dd", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.Scanner;\n\npublic class BeautifulYear {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n int year = scanner.nextInt();\n char q, w, e, r;\n q = w = e = r = 0;\n\n while (q == w || q == e || q == r || w == e || w == r || e == r) {\n String yearStr = Integer.toString(year+1);\n q = yearStr.charAt(0);\n w = yearStr.charAt(1);\n e = yearStr.charAt(2);\n r = yearStr.charAt(3);\n year++;\n }\n System.out.println(year);\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force"], "code_uid": "5a705db7b83a31a60a91953140fcf786", "src_uid": "d62dabfbec52675b7ed7b582ad133acd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "\n// Working program using Reader Class \nimport java.io.DataInputStream;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Scanner;\n\npublic class C {\n static Scanner sc = new Scanner(System.in);\n\n public static void main(String[] args) throws IOException {\n int t = 1;\n // t = sc.nextInt();\n while (t-- > 0) {\n solve();\n }\n }\n\n private static void solve() throws IOException {\n Reader sc = new Reader();\n int n=sc.nextInt();\n int x=sc.nextInt();\n int pos=sc.nextInt();\n int l=0;\n int h=n;\n int countless=x-1;\n long fact=1;\n int counthigh=n-x;\n while(lpos){\n h=mid;\n fact*=counthigh;\n counthigh--;\n fact%=(int)(1e9+7);\n }\n else{\n l=mid+1;\n }\n }\n if(l>0&&l-1==pos)\n {\n int bacha=countless+counthigh;\n while(bacha>0)\n {\n fact*=bacha;\n fact%=(int)(1e9+7);\n bacha--;\n }\n System.out.println(fact);\n return;\n }\n System.out.println(0);\n }\n\n static class Reader {\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 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 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 byte[] buf = new byte[64]; // line length\n int cnt = 0, c;\n while ((c = read()) != -1) {\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 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 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 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 } while ((c = read()) >= '0' && c <= '9');\n if (neg)\n 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 <= ' ')\n c = read();\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 (c == '.') {\n while ((c = read()) >= '0' && c <= '9') {\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 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 if (bufferPointer == bytesRead)\n fillBuffer();\n return buffer[bufferPointer++];\n }\n\n public void close() throws IOException {\n if (din == null)\n return;\n din.close();\n }\n }\n}", "lang_cluster": "Java", "tags": ["binary search", "combinatorics"], "code_uid": "75c6ebeeaa547b24191d44148a077fa3", "src_uid": "24e2f10463f440affccc2755f4462d8a", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\npublic class plant{\npublic static long mod = 1000000007;\npublic static void main(String args[]) throws IOException{\nBufferedReader lector = new BufferedReader(new InputStreamReader(System.in));\nlong p = Long.parseLong(lector.readLine());\nif(p==0){\nSystem.out.println(\"1\");\nreturn;\n}\nlong pp = exp(2,p-1);\nlong res = (((pp)%mod)*((2*pp+1)%mod))%mod;\nSystem.out.println(res);\n}\npublic static long exp(long a,long b){\nif(b==0)return 1;\nif(b==1)return a;\nlong t = 0;\nif((b&1)==0)t = exp(a,b/2);\nreturn ((b&1)==0)?(t*t)%mod:(exp(a,b-1)*a)%mod;\n}\n}\n", "lang_cluster": "Java", "tags": ["math", "matrices", "dp", "number theory"], "code_uid": "3e47e17864a39f084c94e8905e048145", "src_uid": "782b819eb0bfc86d6f96f15ac09d5085", "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.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 Task118D solver = new Task118D();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class Task118D {\n long mod = (long) 1e8;\n long dp[][][];\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int n1 = in.nextInt();\n int n2 = in.nextInt();\n int k1 = in.nextInt();\n int k2 = in.nextInt();\n dp = new long[n1 + 1][n2 + 1][2];\n\n for (int i = 0; i <= n1; i++) {\n for (int j = 0; j <= n2; j++) {\n dp[i][j][0] = -1;\n dp[i][j][1] = -1;\n }\n }\n\n long ans = rec(n1, n2, 0, k1, k2) + rec(n1, n2, 1, k1, k2);\n ans %= mod;\n out.println(ans);\n }\n\n long rec(int n1, int n2, int turn, int k1, int k2) {\n if (dp[n1][n2][turn] != -1)\n return dp[n1][n2][turn];\n if (n1 == 0 && n2 == 0)\n return 1;\n if (turn == 0 && n1 == 0)\n return 0;\n if (turn == 1 && n2 == 0)\n return 0;\n\n long ans = 0;\n if (turn == 0) {\n for (int i = 1; i <= k1; i++) {\n if (n1 - i >= 0)\n ans += rec(n1 - i, n2, 1, k1, k2);\n }\n } else {\n for (int i = 1; i <= k2; i++) {\n if (n2 - i >= 0)\n ans += rec(n1, n2 - i, 0, k1, k2);\n }\n }\n ans %= mod;\n dp[n1][n2][turn] = ans;\n return ans;\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\n", "lang_cluster": "Java", "tags": ["dp"], "code_uid": "4db1d74494eebd5fc11fbbdbbc12abc5", "src_uid": "63aabef26fe008e4c6fc9336eb038289", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\n \n\n\npublic class Main\n{\n static class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n FastScanner(InputStream f) {\n try {\n br = new BufferedReader(new InputStreamReader(f));\n } catch (Exception e) {\n e.printStackTrace();\n }\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 }\n public static void main(String args[])\n {\n InputStream in=System.in;\n // OutputStream out=System.out;\n FastScanner fs=new FastScanner(in);\n PrintWriter out=new PrintWriter(System.out);\n \n int arr[]=new int[6];\n for(int i=0;i<6;i++)\n arr[i]=fs.nextInt();\n long sum=0;\n long sum1=0;\n int tr=0;\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 {sum=arr[i]+arr[j]+arr[k];\n sum1=0;\n for(int l=0;l<6;l++)\n if(l!=i&&l!=j&&l!=k)\n sum1=sum1+arr[l];\n if(sum1==sum)\n tr=1;\n\n\n }\n\nif(tr==1)\n out.println(\"YES\");\nelse \n out.println(\"NO\");\n\n // for(int i=0;i0 && x+y>=0){\n\t\t\tint k=y-1;\n\t\t\tSystem.out.println(4*k+2);\n\t\t}\n\t\telse if(y-x>=0 && x+y<0){\n\t\t\tint k=Math.abs(x)-1;\n\t\t\tSystem.out.println(4*k+3);\n\t\t}\n\t\telse if(y-x<=0 && x+y-1>0){\n\t\t\tint k=x-1;\n\t\t\tSystem.out.println(4*k+1);\n\t\t}\n\t\telse if(y-x<0 && x+y-1<=0){\n\t\t\tint k=Math.abs(y);\n\t\t\tSystem.out.println(4*k);\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "tags": ["brute force", "geometry", "implementation"], "code_uid": "5aed97a5c645adcce4e0a602c7770d7f", "src_uid": "2fb2a129e01efc03cfc3ad91dac88382", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.util.Map.Entry;\nimport javax.swing.text.InternationalFormatter;\nimport java.math.*;\npublic class RATHOD \n{\n public static void main(String[] args) throws IOException\n { \n Reader sc=new Reader(); \n long n=sc.nextLong();\n long m=sc.nextLong();\n long min=-1;\n long req;\n req=(long) Math.ceil((n)/(2.0));\n long sol1,sol2;\n if(m>=req)\n {\n sol1=0;\n }\n else\n {\n if(n%2==0)\n sol1=(((n/2)-m)*2); \n else\n sol1=(((n/2)-m)*2+1); \n }\n long l=1;\n long r=n;\n long cn=0;\n while(l<=r)\n {\n long mid=(l+r)/2;\n //System.out.println(cn);\n if(((mid)*(mid-1))/2>m)\n r=mid-1;\n else\n {\n cn=mid;\n l=mid+1;\n }\n }\n //System.out.println(cn);\n if((cn*(cn-1))/2==m)\n sol2=n-cn;\n else\n sol2=n-cn-1;\n if(m==0)\n sol2=n;\n System.out.println(sol1+\" \"+sol2);\n \n }\n \n \n \n \n\t// _________________________TEMPLATE_____________________________________________________________\n\n\t// private static int gcd(int a, int b) {\n\t// if(a== 0)\n\t// return b;\n\t//\n\t// return gcd(b%a,a);\n\t// }\n\n\t// static class comp implements Comparator {\n\t//\n\t// @Override\n\t// public int compare(pair o1, pair o2) {\n\t// return o2.b - o1.b;\n\t// }\n\t//\n\t// }\n\n\tstatic class pair implements Comparable {\n\t\tint min;\n\t\tint max;\n\t\tint ans;\n\n\t\tpair(int a, int b) {\n\t\t\tmin = a;\n\t\t\tmax = b;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(pair o) {\n\n\t\t\treturn (int) (this.min - o.max);\n\n\t\t}\n\t}\n\n\tpublic static class Reader {\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 Reader() {\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 Reader(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[100000 + 1]; // 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\n\t\tpublic int[] nextIntArray(int n) throws IOException {\n\t\t\tint[] arr = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = nextInt();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tpublic long[] nextLongArray(int n) throws IOException {\n\t\t\tlong[] arr = new long[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = nextLong();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tpublic int[][] nextInt2DArray(int m, int n) throws IOException {\n\t\t\tint[][] arr = new int[m][n];\n\t\t\tfor (int i = 0; i < m; i++) {\n\t\t\t\tfor (int j = 0; j < n; j++)\n\t\t\t\t\tarr[i][j] = nextInt();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t}\n\n}", "lang_cluster": "Java", "tags": ["constructive algorithms", "graphs"], "code_uid": "f1801d86b2702f3f677a9157543bbd26", "src_uid": "daf0dd781bf403f7c1bb668925caa64d", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.lang.reflect.Array;\nimport java.util.*;\n\npublic class Main {\n\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n int n = input.nextInt();\n int count = 0;\n HashMap home = new HashMap<>();\n HashMap guest= new HashMap<>();\n while (n > 0){\n int j = input.nextInt();\n int k = input.nextInt();\n home.put(j, home.getOrDefault(j, 0) + 1);\n guest.put(k, guest.getOrDefault(k, 0) + 1);\n n--;\n }\n for (Map.Entry entry: home.entrySet()){\n count += entry.getValue() * guest.getOrDefault(entry.getKey(), 0);\n }\n\n\n System.out.println(count);\n input.close();\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force"], "code_uid": "846db46e416f29e7c59af18f69d17bd8", "src_uid": "745f81dcb4f23254bf6602f9f389771b", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class A\n{\n\n\tFastScanner in;\n\tPrintWriter out;\n\tint i = 0, j = 0;\n\n\n\tvoid solve() {\n\t\t/**************START**************/\n\t\tint sol1 = 0, sol2 = 0, sol3 = 0;\n\t\tint n = in.nextInt();\n\t\tint min1 = in.nextInt(), max1 = in.nextInt(), min2 = in.nextInt(), max2 = in.nextInt(), min3 = in.nextInt(), max3 = in.nextInt();\n\t\tn -= (min1+min2+min3);\n\t\tmax1 -= min1;\n\t\tmax2 -= min2;\n\t\tmax3 -= min3;\n\t\tif (max1 >= n)\n\t\t{\n\t\t\tsol1 = min1+n;\n\t\t\tsol2 = min2;\n\t\t\tsol3 = min3;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tsol1 = min1 + max1;\n\t\t\tn -= max1;\n\t\t\tif (max2 >= n)\n\t\t\t{\n\t\t\t\tsol2 = min2 + n;\n\t\t\t\tsol3 = min3;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tsol2 = min2 + max2;\n\t\t\t\tn -= max2;\n\t\t\t\tif (max3 >= n)\n\t\t\t\t{\n\t\t\t\t\tsol3 = min3 + n;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tsol3 = min3 + max3;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(sol1 + \" \" + sol2 + \" \" + sol3);\n\n\n\n\n\n\n\n\n\n\n\n\t\t/***************END***************/\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew A().runIO();\n\t}\n\n\tvoid runIO() {\n\t\tin = new FastScanner(System.in);\n\t\tout = new PrintWriter(System.out);\n\n\t\tsolve();\n\n\t\tout.close();\n\t}\n\n\tclass FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner(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 FastScanner(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.hasMoreTokens()) {\n\t\t\t\tString s = null;\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\te.printStackTrace();\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\tboolean hasMoreTokens() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\tString s = null;\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\te.printStackTrace();\n\t\t\t\t}\n\t\t\t\tif (s == null)\n\t\t\t\t\treturn false;\n\t\t\t\tst = new StringTokenizer(s);\n\t\t\t}\n\t\t\treturn true;\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\t}\n}", "lang_cluster": "Java", "tags": ["math", "greedy", "implementation"], "code_uid": "40df89c20da4fde1964472169b27073f", "src_uid": "3cd092b6507079518cf206deab21cf97", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/**\n * Created by Rukshar Alam on 10/12/2019.\n */\n\nimport java.util.*;\npublic class Coins1061A {\n public static void main(String[] args) {\n\n Scanner input = new Scanner(System.in);\n int n = input.nextInt();int s = input.nextInt();\n\n if(s<=n){\n System.out.println(\"1\");\n }\n else{\n int coins = s/n;\n if(s%n != 0)\n coins += 1;\n System.out.println(coins);\n }\n\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "greedy", "implementation"], "code_uid": "fc4b378772a90de53fca0896e63f3176", "src_uid": "04c067326ec897091c3dbcf4d134df96", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import javax.sound.midi.SysexMessage;\nimport java.util.Scanner;\n\npublic class Solution {\n public static void main ( String [] args ){\n Scanner s = new Scanner(System.in);\n int i=0,j=0;\n char[][] matrix = new char[4][4];\n for( i = 0 ;i < 4 ; i++){\n String ip = s.nextLine();\n for( j = 0 ; j < 4 ; j++){\n matrix[i][j]= ip.charAt(j);\n }\n }\n boolean ans=false;\n for( i = 0; i < 3 ; i++){\n int count=0;\n for(j=0;j<3;j++){\n count=0;\n if(matrix[i][j]=='#'){\n count+=1;\n }\n if(matrix[i][j+1]=='#'){\n count+=1;\n }\n if(matrix[i+1][j]=='#'){\n count+=1;\n }\n if(matrix[i+1][j+1]=='#'){\n count+=1;\n }\n if(count>=3){\n ans=true;\n break;\n }\n else{\n count=0;\n if(matrix[i][j]=='.'){\n count+=1;\n }\n if(matrix[i][j+1]=='.'){\n count+=1;\n }\n if(matrix[i+1][j]=='.'){\n count+=1;\n }\n if(matrix[i+1][j+1]=='.'){\n count+=1;\n }\n if(count>=3){\n ans=true;\n break;\n }\n }\n }\n }\n if(ans == true){\n System.out.println(\"YES\");\n }\n else {\n System.out.println(\"NO\");\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "928d63dee93693cf8bf8aca4fc8c65bd", "src_uid": "01b145e798bbdf0ca2ecc383676d79f3", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class Moda {\n\n public static long abs(long a) {\n if(a < 0) a = -a;\n return a;\n }\n\n public static void main(String[] args) throws Exception {\n Scanner sc = new Scanner(System.in);\n long x = sc.nextLong();\n x %= 360;\n x = -x;\n if(x < 0)\n x += 360;\n int best = 360, k = -1;\n if (Math.min(x, 360 - x) < best) {\n best = (int) Math.min(x, 360 - x);\n k = 0;\n }\n for (int i = 1; i <= 3; ++i) {\n x += 90;\n x %= 360;\n if(Math.min(x, 360 - x) < best) {\n best = (int) Math.min(x, 360 - x);\n k = i;\n }\n }\n System.out.printf(\"%d\\n\", k);\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "geometry"], "code_uid": "c2f145acbefa9b8c2ef244ad6147ef4f", "src_uid": "509db9cb6156b692557ba874a09f150e", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\nimport java.io.*;\npublic class sol\n{\n public static void main(String[] args)\n {\n Scanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tint put=1,totalcandies=0,count=0;\n\t\twhile(n-->0)\n\t\t{\n\t\t if(totalcandies>k)\n\t\t {\n\t\t totalcandies--;count++;\n\t\t }\n\t\t else\n\t\t {\n\t\t totalcandies += put;\n\t\t put++;\n\t\t }\n\t\t}\n\t\tSystem.out.println(count);\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "math", "binary search"], "code_uid": "d0a29d98c535fbae8907dceed59b5ca5", "src_uid": "17b5ec1c6263ef63c668c2b903db1d77", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "\n import java.util.Scanner;\n\npublic class football {\n\tpublic static String buscar(String n){\n\t\tString u=\"1111111\";\n\t\tString c=\"0000000\";\n\t\tfor (int i = 0; i < n.length()-6; i++) {\n\t\t\tString temp=n.substring(i, i+7);\n\t\t\tif(temp.equals(u)||temp.equals(c))\n\t\t\t\treturn \"YES\";\n\t\t}\n\t\treturn \"NO\";\n\t}\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner (System.in);\n\t\tString n=sc.next();\n\t\tSystem.out.println(buscar(n));\n\t}\n}", "lang_cluster": "Java", "tags": ["strings", "implementation"], "code_uid": "84c74c8ac1989ff49baaa8dc4eda2eaa", "src_uid": "ed9a763362abc6ed40356731f1036b38", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n/**\n *\n * @author Bug\n */\npublic class PS {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n // TODO code application logic here\n int a;\n Scanner scn = new Scanner (System.in);\n a = scn.nextInt();\n \n if (a>2 && a< 101 && (a%2) ==0) {\n System.out.println(\"YES\");\n \n }else{\n System.out.println(\"NO\");\n }\n }\n \n}\n", "lang_cluster": "Java", "tags": ["brute force", "math"], "code_uid": "004db2ab59b40eb1f15c16b360447afe", "src_uid": "230a3c4d7090401e5fa3c6b9d994cdf2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Main {\n\t\tpublic static void main(String[] args)\n\t\t{\n\t\t\tint ans=0,K;boolean flag=false;\n\t\t\tint i,temp,j,k,L;String s;\n\t\t\tScanner cin =new Scanner(System.in);\n\t\t\ts=cin.nextLine();\n\t\t\tK=cin.nextInt();\n\t\t\tfor(i=1;i<=K;i++)\n\t\t\t\ts+='*';\n\t\t\tfor(i=0;ians)\n\t\t\t\t\t\t\tans=j-i+1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tSystem.out.printf(\"%d\\n\",ans);\n\t\t}\n}\n", "lang_cluster": "Java", "tags": ["brute force", "strings", "implementation"], "code_uid": "80bb04ae832e6a9dca8bd68cd5d9dccf", "src_uid": "bb65667b65ff069a9c0c9e8fe31da8ab", "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.util.StringTokenizer;\n\npublic class CF_919_B_PERFECT_NUMBER {\n\t\n\tstatic boolean isPerfect(int x)\n\t{\n\t\tint sum = 0;\n\t\tint temp = x;\n\t\twhile(temp!=0)\n\t\t{\n\t\t\tsum+= temp%10;\n\t\t\ttemp/=10;\n\t\t}\n\t\t\n\t\treturn sum == 10;\n\t}\n\n\tpublic static void main(String[] args) throws Exception{\n\t\tScanner sc = new Scanner(System.in);\n\t\tint k = sc.nextInt();\n\t\tint i = 0;\n\t\tint num = 18;\n\t\twhile(i0)?1:0);\n m = m/a+((m%a>0)?1:0);\n System.out.println(((long)n)*((long)m));\n n = 8;\n m = 3000000/n;\n Calc cl[] = new Calc[n];\n Thread t[] = new Thread[n];\n for(int i=0; i=1 && ng <= girl){\n BigInteger tmp = NcR(boy,nb).multiply( NcR(girl,ng) );\n //System.out.println(nb+\" \"+tmp);\n retval = retval.add(tmp);\n }\n }\n\n \n System.out.println(retval);\n\n }\n public BigInteger NcR(int N, int R){\n BigInteger up = bg[N];\n BigInteger dn = bg[R].multiply( bg[N-R] );\n return up.divide(dn);\n }\n\n public void gen() throws IOException{\n bg[0] = BigInteger.ONE;\n for(int i=1;i<=30;++i){\n bg[i] = bg[i-1].multiply( BigInteger.valueOf( (long)i) );\n }\n }\n\n\n int nextInt() throws IOException{\n return Integer.parseInt( nextToken() );\n }\n\n String nextToken() throws IOException {\n while (token == null || !token.hasMoreTokens()) {\n String line = reader.readLine();\n token = new StringTokenizer(line);\n }\n return token.nextToken();\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "combinatorics"], "code_uid": "5421149c6e53326b2be974e995310730", "src_uid": "489e69c7a2fba5fac34e89d7388ed4b8", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.*;\n\npublic class C {\n\tprivate static Scanner in;\n\t\n\tclass State {\n\t\tString s;\n\t\tint c;\n\t\t\n\t\tpublic State(String s, int c) {\n\t\t\tthis.s = s;\n\t\t\tthis.c = c;\n\t\t}\n\n\t\t@Override\n\t\tpublic int hashCode() {\n\t\t\treturn 13 * s.hashCode() + c;\n\t\t}\n\t\t\n\t\t@Override\n\t\tpublic boolean equals(Object obj) {\n\t\t\tState that = (State) obj;\n\t\t\treturn s.equals(that.s) && c == that.c;\n\t\t}\n\t\t\n\t\tboolean isTerminal() {\n\t\t\treturn s.length() == c;\n\t\t}\n\t\t\n\t\tState step(char n) {\n\t\t\tint c1 = c;\n\t\t\tString ss = s + n;\n\t\t\tfor (;;) {\n\t\t\t\tint cbest = c1;\n\t\t\t\tfor (String d : dna) {\n\t\t\t\t\tfor (int i = 0; i <= c1; i++) {\n\t\t\t\t\t\tif (ss.substring(i).startsWith(d)) {\n\t\t\t\t\t\t\tcbest = Math.max(cbest, i + d.length());\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (cbest == c1) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tc1 = cbest;\n\t\t\t}\n\t\t\tloop:\n\t\t\tfor (;;) {\n\t\t\t\tfor (String d : dna) {\n\t\t\t\t\tif (d.startsWith(ss)) {\n\t\t\t\t\t\tbreak loop;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tss = ss.substring(1);\n\t\t\t\tc1--;\n\t\t\t}\n\t\t\tif (c1 < 0) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn new State(ss, c1);\n\t\t}\n\t}\n\n\tString[] dna;\n\tHashMap map = new HashMap();\n\tint[][] nxt = new int[2000][4];\n\tboolean[] trm = new boolean[2000];\n\tchar[] ns = new char[]{'A', 'C', 'G', 'T'};\n\t\n\tpublic void run() {\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tdna = new String[m];\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tdna[i] = in.next();\n\t\t}\n\t\tState s0 = new State(\"\", 0);\n\t\tdfs(s0);\n\t\tint k = map.size();\n\t\tint[][] a = new int[n + 1][k];\n\t\ta[0][0] = 1;\n\t\tfor (int len = 0; len < n; len++) {\n\t\t\tfor (int s = 0; s < k; s++) {\n\t\t\t\tint aa = a[len][s];\n\t\t\t\tif (aa == 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tfor (int i = 0; i < 4; i++) {\n\t\t\t\t\tint t = nxt[s][i];\n\t\t\t\t\tif (t < 0) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\ta[len + 1][t] = add(a[len + 1][t], aa);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint ans = 0;\n\t\tfor (int s = 0; s < k; s++) {\n\t\t\tif (trm[s]) {\n\t\t\t\tans = add(ans, a[n][s]);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n\n\tfinal int MOD = 1000000009;\n\t\n\tprivate int add(int x, int y) {\n\t\tx += y;\n\t\tif (x >= MOD) {\n\t\t\tx -= MOD;\n\t\t}\n\t\treturn x;\n\t}\n\n\tprivate void dfs(State st) {\n\t\tif (map.containsKey(st)) {\n\t\t\treturn;\n\t\t}\n\t\tint v = map.size();\n\t\tmap.put(st, v);\n\t\ttrm[v] = st.isTerminal();\n\t\tfor (int i = 0; i < 4; i++) {\n\t\t\tState u = st.step(ns[i]);\n\t\t\tif (u == null) {\n\t\t\t\tnxt[v][i] = -1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tdfs(u);\n\t\t\tnxt[v][i] = map.get(u);\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tLocale.setDefault(Locale.US);\n\t\tin = new Scanner(System.in);\n\t\tnew C().run();\n\t\tin.close();\n\t}\n}\n", "lang_cluster": "Java", "tags": ["strings", "dp", "trees"], "code_uid": "d0811f8e36e4a30ef6856d77daf84e6f", "src_uid": "3f053c07deaac55c2c51df6147080340", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\npublic final class code\n{\n static boolean lucky(int n)\n {\n while(n>0)\n {\n int d=n%10;\n if(d!=4 && d!=7)\n return false;\n n/=10;\n }\n return true;\n }\n public static void main(String[]args)\n {\n Scanner sc=new Scanner(System.in);\n int n=0;\n if(sc.hasNextInt())\n {\n n=sc.nextInt();\n }\n boolean flag=lucky(n);\n if(!flag)\n {\n for(int i=1;i black[y][0]){\n\t\t\t\t\tgo = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(go && Math.abs(1 - white[x][0]) < whiteMin)\n\t\t\t\twhiteMin = Math.abs(1 - white[x][0]);\n\t\t}\n\t\tfor(int x = 0; x < countBlack; x++){\n\t\t\tgo = true;\n\t\t\tfor(int y = 0; y < countWhite; y++){\n\t\t\t\tif(black[x][1] == white[y][1] && black[x][0] < white[y][0]){\n\t\t\t\t\tgo = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(go && 8 - black[x][0] < blackMin){\n\t\t\t\tblackMin = 8 - black[x][0];\n\t\t\t}\n\t\t}\n\t\tif(whiteMin == blackMin || whiteMin < blackMin)\n\t\t\tSystem.out.print(\"A\");\n\t\telse\n\t\t\tSystem.out.print(\"B \");\n\t}\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "6b51c8f38fbdd78888eeda10dce6398b", "src_uid": "0ddc839e17dee20e1a954c1289de7fbd", "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.io.PrintWriter;\nimport java.util.*;\nimport java.util.StringTokenizer;\n\npublic class CFC {\n BufferedReader br;\n PrintWriter out;\n StringTokenizer st;\n boolean eof;\n final long MOD = 1000L * 1000L * 1000L + 7;\n\n void solve() throws IOException {\n int n = 24;\n int[] arr = nextIntArr(n);\n int[][] idx = {{1, 3, 5, 7, 9, 11, 22, 24},\n {2, 4, 6, 8, 10, 12, 21, 23},\n {13, 14, 5, 6, 17, 18, 21, 22},\n {15, 16, 7, 8, 19, 20, 23, 24},\n {1, 2, 18, 20, 12, 11, 15, 13},\n {3, 4, 17, 19, 10, 9, 16, 14}};\n\n for (int[] cand : idx) {\n int[] candArr = Arrays.copyOf(cand, cand.length);\n int[] fix = Arrays.copyOf(arr, arr.length);\n\n int[] left = shiftLeft(candArr);\n boolean flag = check(fix, candArr, left);\n if (flag) {\n out(\"YES\");\n return;\n }\n\n int[] right = shiftRight(candArr);\n flag = check(fix, candArr, right);\n if (flag) {\n out(\"YES\");\n return;\n }\n }\n\n out(\"NO\");\n }\n\n boolean check(int[] mat, int[] old, int[] index) {\n// for (int i = 0; i < old.length; i++) {\n// swap(mat, old[i] - 1, index[i] - 1);\n// }\n\n int[] newMat = Arrays.copyOf(mat, mat.length);\n for (int i = 0; i < old.length; i++) {\n newMat[index[i] - 1] = mat[old[i] - 1];\n }\n return isValid(newMat);\n }\n\n int[] shiftRight(int[] ind) {\n int[] res = new int[8];\n for (int i = 2; i < 8; i++) {\n res[i] = ind[i - 2];\n }\n\n res[0] = ind[6];\n res[1] = ind[7];\n return res;\n }\n\n int[] shiftLeft(int[] ind) {\n int[] res = new int[8];\n for (int i = 0; i < 6; i++) {\n res[i] = ind[i + 2];\n }\n res[6] = ind[0];\n res[7] = ind[1];\n return res;\n }\n\n boolean isValid(int[] arr) {\n for (int i = 0; i < 6; i++) {\n int cnt1 = arr[4 * i];\n for (int j = 1; j < 4; j++) {\n if (arr[4 * i + j] != cnt1) {\n return false;\n }\n }\n }\n\n return true;\n }\n\n void swap(int[] arr, int i, int j) {\n int tmp = arr[i];\n arr[i] = arr[j];\n arr[j] = tmp;\n }\n\n void shuffle(int[] a) {\n int n = a.length;\n for(int i = 0; i < n; i++) {\n int r = i + (int) (Math.random() * (n - i));\n int tmp = a[i];\n a[i] = a[r];\n a[r] = tmp;\n }\n }\n private void outln(Object o) {\n out.println(o);\n }\n private void out(Object o) {\n out.print(o);\n }\n public CFC() throws IOException {\n br = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n solve();\n out.close();\n }\n public static void main(String[] args) throws IOException {\n new CFC();\n }\n\n public long[] nextLongArr(int n) throws IOException{\n long[] res = new long[n];\n for(int i = 0; i < n; i++)\n res[i] = nextLong();\n return res;\n }\n public int[] nextIntArr(int n) throws IOException {\n int[] res = new int[n];\n for(int i = 0; i < n; i++)\n res[i] = nextInt();\n return res;\n }\n public 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 null;\n }\n }\n return st.nextToken();\n }\n public String nextString() {\n try {\n return br.readLine();\n } catch (IOException e) {\n eof = true;\n return null;\n }\n }\n public int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n public long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n public double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "345d70bdaaaae976fc8e083149e8cad3", "src_uid": "881a820aa8184d9553278a0002a3b7c4", "difficulty": 1500.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******************************\nWhat do you think? What do you think?\n1st on Billboard, what do you think of it\nNext is a Grammy, what do you think of it\nHowever you think, I’m sorry, but shit, I have no fcking interest\n*******************************\nI'm standing on top of my Monopoly board\nThat means I'm on top of my game and it don't stop\ntil my hip don't hop anymore\nhttps://www.a2oj.com/Ladder16.html\n*******************************\n300iq as writer = Sad!\n*/\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\n\n public class x1174E\n {\n static long MOD = 1000000007L;\n public static void main(String hi[]) 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 long[][] dp = new long[20][2];\n base(dp, N);\n cnt = new long[20][2];\n for(int curr=0; (1<= 0; a--)\n for(int b=1; b >= 0; b--)\n {\n long res = 0L;\n if(cnt[a][b]-i >= 0)\n res = (dp[a][b]*(cnt[a][b]-i+1+MOD))%MOD;\n if(a+1 < 20)\n {\n res += (dp[a+1][b]*(cnt[a][b]-cnt[a+1][b]))%MOD;\n if(res >= MOD)\n res -= MOD;\n }\n if(b == 0)\n {\n res += (dp[a][1]*(cnt[a][0]-cnt[a][1]))%MOD;\n if(res >= MOD)\n res -= MOD;\n }\n newdp[a][b] = res;\n }\n dp = newdp;\n }\n System.out.println(dp[0][0]);\n }\n static long[][] cnt;\n public static void base(long[][] dp, int N)\n {\n int curr = 1;\n while((1<> 1) + 1);\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 Splits().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": ["math"], "code_uid": "63f795c8206464583814573f1deeafcb", "src_uid": "5551742f6ab39fdac3930d866f439e3e", "difficulty": 800.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 s = new Scanner(System.in);\n int a = s.nextInt();\n int b = s.nextInt();\n int t = a;\n while (a >= b) { int r = a % b; a = a / b; t += a; a += r; }\n System.out.println(t);\n }\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "b42fc5b3a5c0b7e12f0e0ac0f4b1b829", "src_uid": "a349094584d3fdc6b61e39bffe96dece", "difficulty": 1000.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 a = in.nextInt(), b = in.nextInt(), c = in.nextInt();\n int cnt = 0;\n int n = a - 1;\n for (int i = 0; i < Math.min(b, c); i++) {\n n++;\n cnt += n * 2;\n }\n cnt += n * (Math.abs(b - c) - 1);\n out.println(cnt);\n }\n\n public static void main(String[] args) throws Exception {\n BufferedReader reader = new BufferedReader(new InputStreamReader(\n System.in));\n PrintWriter out = new PrintWriter(new BufferedWriter(\n 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": ["math", "implementation"], "code_uid": "3ede8ac3e2640515613c6436af18b87e", "src_uid": "8ab25ed4955d978fe20f6872cb94b0da", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "\nimport java.util.Scanner;\npublic class JavaApplication71 {\n public static void main(String[] args) {\n //helpful mathe\n Scanner input =new Scanner(System.in);\n String s=input.next();\n int c1=0 ;int c2=0 ;int c3=0;\n String result=\"\";\n for(int i=0;i='a'&&c<='z')b+=weight(c);\n else w+=weight(c);\n }\n }\n }\n if(w>b)System.out.println(\"White\");\n else if(wa[i+1])\n {\n max=a[i+1];\n a[i+1]=a[i];\n a[i]=max;\n }\n }\n if(a[2]<(a[1]+a[0]))\n {\n System.out.println(0);\n }\n else\n {\n System.out.println((a[2]-(a[1]+a[0])+1));\n }\n sc.close();\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "math", "geometry"], "code_uid": "fe3996f1655bbac3f6f0a01786139721", "src_uid": "3dc56bc08606a39dd9ca40a43c452f09", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\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 HashMap mp=new HashMap();\n while(mp.get(n)==null)\n { \n mp.put(n, 1);\n n=n+1;\n while(n%10==0) n/=10;\n }\n System.out.println(mp.size()) ;\n \n\n\n }\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "ad81ca3035a6d3241a4a470ccac070e9", "src_uid": "055fbbde4b9ffd4473e6e716da6da899", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "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.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 */\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 TaskB2 solver = new TaskB2();\n solver.solve(1, in, out);\n out.close();\n }\n}\n\nclass TaskB2 {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int n = in.readInt();\n int m = in.readInt();\n\n int[] dp = new int[n + 1];\n dp[0] = dp[1] = 1;\n\n for (int i = 2; i <= n; i++) {\n for (int j = 0; j < i; j++) {\n dp[i] += dp[j];\n }\n }\n\n int[] a = new int[n];\n boolean[] used = new boolean[n + 1];\n\n int add = 0;\n int last = 0;\n for (int i = 0; i < n; i++) {\n for (int j = last + 1; j <= n; j++) {\n if(used[j]) continue;\n\n int grt = 0;\n for (int k = j + 1; k <= n; k++) {\n if (!used[k]) grt++;\n }\n if (add + dp[grt] >= m) {\n a[i] = j;\n used[j] = true;\n last = j;\n break;\n } else {\n add += dp[grt];\n }\n }\n }\n\n for (int i = n - 1; i >= 0; i--) {\n if (a[i] == 0) {\n for (int j = 1; j <= n; j++) {\n if (!used[j]) {\n a[i] = j;\n used[j] = true;\n break;\n }\n }\n }\n }\n\n for (int i = 0; i < n; i++) {\n out.print(a[i] + \" \");\n }\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 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\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 close() {\n writer.close();\n }\n\n}\n\n", "lang_cluster": "Java", "tags": ["brute force"], "code_uid": "9e0db1daf4eb33a79b10da3e1f32edad", "src_uid": "a8da7cbd9ddaec8e0468c6cce884e7a2", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.StringTokenizer;\n\n/**\n * Created by Alvin on 5/24/2016.\n */\n\npublic class Codeforces_round_335_div_2_MagicSpheres {\n public static void main(String[] args) {\n FScanner input = new FScanner();\n out = new PrintWriter(new BufferedOutputStream(System.out), true);\n int a = input.nextInt();\n int b = input.nextInt();\n int c = input.nextInt();\n int x = input.nextInt();\n int y = input.nextInt();\n int z = input.nextInt();\n int remainBalls = 0;\n if(a - x > 0) {\n remainBalls += (a - x) / 2;\n }\n\n if(b - y > 0) {\n remainBalls += (b - y) / 2;\n }\n if(c - z > 0) {\n remainBalls += (c - z) / 2;\n }\n if(a < x) {\n remainBalls -= (x - a);\n }\n if(b < y) {\n remainBalls -= (y - b);\n }\n if(c < z) {\n remainBalls -= (z - c);\n }\n if(remainBalls >= 0) {\n out.println(\"Yes\");\n } else {\n out.println(\"No\");\n }\n out.close();\n }\n\n public static PrintWriter out;\n\n public static class FScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n private 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 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 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", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "c4660c9f9b34b2f9be8953fb0ef2f6a7", "src_uid": "1db4ba9dc1000e26532bb73336cf12c3", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.lang.*;\npublic class Main{\n public static void main(String[] args){\n Scanner sc=new Scanner(System.in);\n long n=sc.nextLong();\n int k=sc.nextInt();\n int i=0;\n while(i!=k){\n if(n%10==0){\n while(n%10==0&&i!=k){\n n=n/10;\n i=i+1;\n }\n }\n else{\n while(n%10!=0&&n>0&&i!=k){\n n=n-1;\n i=i+1;\n }\n }\n }\n System.out.println(n);\n }\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "139485ae768e8a132fcce0388c523384", "src_uid": "064162604284ce252b88050b4174ba55", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class RaceTime2 {\n\tpublic static boolean clock (int h, int m, int s, int t1, int t2) {\n\t\tint t1_s = t1 * 5;\n\t\tif (t1_s >= 60)\n\t\t\tt1_s -= 60;\n\t\tboolean solution_s = false;\n\t\tint t2_s = t2 * 5;\n\t\tif (t2_s >= 60)\n\t\t\tt2_s -= 60;\n\t\twhile (t1_s != s) {\n\t\t\tif (t1_s == t2_s) {\n\t\t\t\tsolution_s = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tt1_s++;\n\t\t\tif (t1_s > 59)\n\t\t\t\tt1_s -= 60;\n\t\t}\n\t\tif (!solution_s)\n\t\t\treturn false;\n\n\t\tdouble t1_m = (double)t1 * (double)5;\n\t\tif (t1_m >= 60)\n\t\t\tt1_m -= 60;\n\t\tdouble m1 = (double)m;\n\t\tboolean solution_m = false;\n\t\tif (s > 0)\n\t\t\tm1 += 0.5;\n\t\tif (m1 >= 60)\n\t\t\tm1 -= 60;\n\t\tdouble t2_m = (double)t2 * (double)5;\n\t\tif (t2_m >= 60)\n\t\t\tt2_m -= 60;\n\t\twhile (t1_m != (double)m1) {\n\t\t\tif (t1_m == t2_m) {\n\t\t\t\tsolution_m = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tt1_m += 0.5;\n\t\t\tif (t1_m >= 60)\n\t\t\t\tt1_m -= 60;\n\t\t}\n\t\tif (!solution_m)\n\t\t\treturn false;\n\n\t\tdouble t1_h = (double)t1;\n\t\tdouble h1 = (double)h;\n boolean solution_h = false;\n if (m > 0 || s > 0)\n h1 += 0.5;\n\t\tif (h1 > 12)\n\t\t\th1 -= 12;\n while (t1_h != (double)h1) {\n if (t1_h == (double)t2) {\n solution_h = true;\n break;\n }\n t1_h += 0.5;\n if (t1_h > 12)\n t1_h -= 12;\n }\n if (!solution_h)\n return false;\n\t\treturn true;\n\t}\n\n\tpublic static boolean anti (int h, int m, int s, int t1, int t2) {\n int t1_s = t1 * 5;\n\t\tif (t1_s >= 60)\n\t\t\tt1_s -= 60;\n boolean solution_s = false;\n\t\tint t2_s = t2 * 5;\n\t\tif (t2_s >= 60)\n\t\t\tt2_s -= 60;\n while (t1_s != s) {\n if (t1_s == t2_s) {\n solution_s = true;\n break;\n }\n t1_s--;\n if (t1_s < 0)\n t1_s += 60;\n }\n if (!solution_s)\n return false;\n\n double t1_m = (double)t1 * (double)5;\n\t\tif (t1_m >= 60)\n\t\t\tt1_m -= 60;\n double m1 = (double)m;\n boolean solution_m = false;\n if (s > 0)\n m1 += 0.5;\n if (m1 >= 60)\n m1 -= 60;\n\t\tdouble t2_m = (double)t2 * (double)5;\n\t\tif (t2_m >= 60)\n\t\t\tt2_m -= 60;\n while (t1_m != (double)m1) {\n if (t1_m == t2_m) {\n solution_m = true;\n break;\n }\n t1_m -= 0.5;\n if (t1_m < 0)\n t1_m += 60;\n }\n if (!solution_m)\n return false;\n\n double t1_h = (double)t1;\n double h1 = (double)h;\n boolean solution_h = false;\n if (m > 0 || s > 0)\n h1 += 0.5;\n if (h1 > 12)\n h1 -= 12;\n while (t1_h != (double)h1) {\n if (t1_h == (double)t2) {\n\t solution_h = true;\n break;\n }\n t1_h -= 0.5;\n if (t1_h < 0.5)\n t1_h += 12;\n }\n if (!solution_h)\n return false;\n return true;\n }\n\n\tpublic static void main (String[] args) throws Exception {\n\t\tScanner sc = new Scanner (System.in);\n\t\tint h = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tint s = sc.nextInt();\n\t\tint t1 = sc.nextInt();\n\t\tint t2 = sc.nextInt();\n\t\tif (clock (h, m, s, t1, t2) || anti (h, m, s, t1, t2)) {\n\t\t\tSystem.out.println (\"YES\");\n\t\t} else System.out.println (\"NO\");\n\t}\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "121d9a9b98001b7c0f37ddd0046677ad", "src_uid": "912c8f557a976bdedda728ba9f916c95", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n int k, c = 0, sum = 0, summ = 0;\n int[] A = new int[12];\n\n Scanner s = new Scanner(System.in);\n k = s.nextInt();\n s.nextLine();\n for (int i = 0; i < 12; i++) {\n A[i] = s.nextInt();\n }\n Arrays.sort(A);\n for (int x : A) {\n summ += x;\n }\n if (summ < k)\n System.out.println(-1);\n else {\n for (int i = 11; i >= 0; i--) {\n if (sum < k) {\n sum += A[i];\n c++;\n if(sum==k)\n {\n System.out.println(c);\n break;\n }\n } else {\n System.out.println(c);\n break;\n }\n }\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["sortings", "implementation", "greedy"], "code_uid": "3f8ea20ce0d65f8829ce13ab11e8a6f4", "src_uid": "59dfa7a4988375febc5dccc27aca90a8", "difficulty": 900.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. */\n public class Codechef\n{\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t\t// your code goes here\n\t\tScanner s =new Scanner(System.in);\n\t\tint w1=s.nextInt();\n\t\tint h1=s.nextInt();\n\t\tint w2=s.nextInt();\n\t\tint h2=s.nextInt();\n\t\tint count=w1*2+(h1+h2)*2+4;\n\t\tSystem.out.println(count);\n\t}\n}", "lang_cluster": "Java", "tags": ["math"], "code_uid": "828bb373f549a7d538c2b7efcdadd5ba", "src_uid": "b5d44e0041053c996938aadd1b3865f6", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\nimport java.util.stream.*;\nimport java.util.stream.Collectors.*;\n\nimport static java.util.stream.Collectors.*;\n\npublic class codeforces {\n public static void main(String[] args) throws Exception {\n try {\n InputStreamReader isr = new InputStreamReader(System.in);\n BufferedReader br = new BufferedReader(isr); \n int len=Integer.parseInt(br.readLine());\n String inp=br.readLine();\n int count=0;\n StringBuffer naya = new StringBuffer(inp);\n while(naya.indexOf(\"xxx\")!=-1){\n int ndx=naya.indexOf(\"xxx\");\n naya.deleteCharAt(ndx);\n count++;\n }\n System.out.println(count);\n } catch (Exception e) {\n e.printStackTrace();\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["greedy", "strings"], "code_uid": "5edf86492908ea8592191bf4d74fb250", "src_uid": "8de14db41d0acee116bd5d8079cb2b02", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class PlateGame {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int a = in.nextInt();\n int b = in.nextInt();\n int r = in.nextInt();\n if (Math.min(a, b) < 2 * r) {\n System.out.println(\"Second\");\n } else {\n System.out.println(\"First\");\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "constructive algorithms", "games"], "code_uid": "b5bd4d802c2a55d2348a15bec5bc9e0a", "src_uid": "90b9ef939a13cf29715bc5bce26c9896", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\npublic class JavaApplication18 {\npublic static void main(String[] args) {\nScanner sc = new Scanner(System.in);\ndouble r=sc.nextInt();\ndouble x=sc.nextInt();\ndouble y=sc.nextInt();\ndouble x1=sc.nextInt();\ndouble y1=sc.nextInt();\n\n x=Math.abs(x-x1);\n y=Math.abs(y-y1);\ndouble ans=Math.sqrt((x*x+y*y))/(2*r);\n\nSystem.out.println((int)Math.ceil((ans)));\n\n\n}\n\n}\n", "lang_cluster": "Java", "tags": ["math", "geometry"], "code_uid": "c0a29632026d28615de3b9719d6905bc", "src_uid": "698da80c7d24252b57cca4e4f0ca7031", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Mainn {\n\tFastReader scn;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\n\tvoid solve() {\n\t\tint x = scn.nextInt(), y = scn.nextInt(), mod = (int) 1e9 + 7;\n\t\tif (y % x != 0) {\n\t\t\tout.println(0);\n\t\t\treturn;\n\t\t}\n\t\tint k = y / x;\n\n\t\tHashMap map = new HashMap<>();\n\t\tmap.put(1, 1L);\n\n\t\tout.println(func(k, map, mod));\n\t}\n\n\tlong func(int k, HashMap map, int mod) {\n\t\tif (map.containsKey(k)) {\n\t\t\treturn map.get(k);\n\t\t}\n\t\tlong rv = 1;\n\t\tfor (int i = 2; i * i <= k; i++) {\n\t\t\tif (k % i != 0) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\trv += func(i, map, mod);\n\t\t\tif (i * i != k) {\n\t\t\t\trv += func(k / i, map, mod);\n\t\t\t}\n\t\t}\n\t\t\n\t\trv %= mod;\n\t\trv = (power(2, k - 1, mod) - rv + mod) % mod;\n\t\tmap.put(k, rv);\n\n\t\treturn rv;\n\t}\n\n\tlong power(long a, long x, long mod) {\n\t\tif (x == 0) {\n\t\t\treturn 1;\n\t\t}\n\t\tlong p = power(a, x / 2, mod);\n\t\tp *= p;\n\t\tp %= mod;\n\t\tif (x % 2 == 1) {\n\t\t\tp *= a;\n\t\t\tp %= mod;\n\t\t}\n\t\treturn p;\n\t}\n\n\tvoid run() throws Exception {\n\t\tboolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\tout = new PrintWriter(System.out);\n\t\tscn = new FastReader(oj);\n\t\tlong time = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\tif (!oj) {\n\t\t\tSystem.out.println(Arrays.deepToString(new Object[] { System.currentTimeMillis() - time + \" ms\" }));\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew Mainn().run();\n\t}\n\n\tclass FastReader {\n\t\tInputStream is;\n\n\t\tpublic FastReader(boolean onlineJudge) {\n\t\t\tis = onlineJudge ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\n\t\t}\n\n\t\tbyte[] inbuf = new byte[1024];\n\t\tpublic int lenbuf = 0, ptrbuf = 0;\n\n\t\tint readByte() {\n\t\t\tif (lenbuf == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (ptrbuf >= lenbuf) {\n\t\t\t\tptrbuf = 0;\n\t\t\t\ttry {\n\t\t\t\t\tlenbuf = is.read(inbuf);\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 (lenbuf <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn inbuf[ptrbuf++];\n\t\t}\n\n\t\tboolean isSpaceChar(int c) {\n\t\t\treturn !(c >= 33 && c <= 126);\n\t\t}\n\n\t\tint 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\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tchar nextChar() {\n\t\t\treturn (char) skip();\n\t\t}\n\n\t\tString next() {\n\t\t\tint b = skip();\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\twhile (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && 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\tchar[] next(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\tchar[][] nextMatrix(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] = next(m);\n\t\t\treturn map;\n\t\t}\n\n\t\tint[] nextArray(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\treturn a;\n\t\t}\n\n\t\tlong[] nextLongArray(int n) {\n\t\t\tlong[] a = new long[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\ta[i] = nextInt();\n\t\t\treturn a;\n\t\t}\n\n\t\tint 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\tlong 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\tint[] shuffle(int[] arr) {\n\t\t\tRandom r = new Random();\n\t\t\tfor (int i = 1, j; i < arr.length; i++) {\n\t\t\t\tj = r.nextInt(i);\n\t\t\t\tarr[i] = arr[i] ^ arr[j];\n\t\t\t\tarr[j] = arr[i] ^ arr[j];\n\t\t\t\tarr[i] = arr[i] ^ arr[j];\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics", "bitmasks", "number theory"], "code_uid": "69d5d1cfeab81cd864d9c4578e1a5bfa", "src_uid": "de7731ce03735b962ee033613192f7bc", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\npublic class Main{\n public static void main(String []args)throws IOException{\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));\n //int t=Integer.parseInt(br.readLine());\n //while(t-- >0){\n\t\t\t//int n =Integer.parseInt(br.readLine());\n\t\t\tString inp[]=br.readLine().split(\" \");\n\t\t\tint m=Integer.parseInt(inp[0]),s=Integer.parseInt(inp[1]);\n\t\t\tif(s==0 && m==1){\n\t\t\t bw.write(\"0 0\");\n\t\t\t}\n\t\t\telse if(s==0 || s > 9*m){\n\t\t\t bw.write(\"-1 -1\");\n\t\t\t}\n\t\t\telse{\n\t\t\t String max=\"\",min=\"\";\n\t\t\t int temp=s;\n\t\t\t int i=0;\n\t\t\t for(;i0){\n\t\t\t max+=Integer.toString(Math.min(9,temp));\n\t\t\t temp=temp-Math.min(9,temp);\n\t\t\t }\n\t\t\t else{\n\t\t\t max+=\"0\";\n\t\t\t }\n\t\t\t }\n\t\t\t \n\t\t\t temp=s;\n\t\t\t for(i=m-1;i>=0;i--){\n\t\t\t if(temp>9){\n\t\t\t min=\"9\"+min;\n\t\t\t temp=temp-9;\n\t\t\t }\n\t\t\t else if(i==0){\n\t\t\t min=Integer.toString(temp)+min;\n\t\t\t }\n\t\t\t else if(temp<10 && temp!=1){\n\t\t\t min=Integer.toString(temp-1)+min;\n\t\t\t temp=1;\n\t\t\t }\n\t\t\t else{\n\t\t\t min=\"0\"+min;\n\t\t\t }\n\t\t\t }\n\t\t\t bw.write(min+\" \"+max);\n\t\t\t}\n //}\n bw.flush();\n }\n}\n", "lang_cluster": "Java", "tags": ["greedy", "dp", "implementation"], "code_uid": "83293b7ca55698bbe704bf1bb7295d35", "src_uid": "75d062cece5a2402920d6706c655cad7", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\n\npublic class problem {\n static void solve() throws IOException {\n Reader in = new Reader();\n int n = in.nextInt();\n int k = in.nextInt();\n int a[] = new int[k];\n int countOdd = 0;\n int countEven = 0;\n int doubleRemain = 2 * n;\n int quadraticRemain = n;\n int totalQuad = 0;\n for (int i = 0; i < k; i++) {\n a[i] = in.nextInt();\n totalQuad += a[i] / 4;\n if (a[i] % 4 == 2) countEven++;\n if (a[i] % 4 == 1) countOdd++;\n if (a[i] % 4 == 3) {\n countOdd++;\n countEven++;\n }\n }\n int res;\n if (totalQuad > quadraticRemain) {\n countEven += 2 * (totalQuad - quadraticRemain);\n res = doubleRemain - countEven - countOdd;\n } else {\n quadraticRemain -= totalQuad;\n int min = Math.min(Math.min(quadraticRemain, countEven), countOdd);\n quadraticRemain -= min;\n countEven -= min;\n countOdd -= min;\n if (countEven == 0) doubleRemain += 2 * quadraticRemain;\n else if (countOdd == 0) {\n doubleRemain += 3 * (quadraticRemain / 2) + quadraticRemain % 2;\n }\n res = doubleRemain - countEven - countOdd;\n }\n\n System.out.println(res >= 0 ? \"YES\" : \"NO\");\n }\n\n public static void main(String[] args) throws IOException {\n new problem().solve();\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 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 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 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 public int nextInt() throws IOException {\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 public long nextLong() throws IOException {\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 } while ((c = read()) >= '0' && c <= '9');\n if (neg) {\n return -ret;\n }\n return ret;\n }\n\n public double nextDouble() throws IOException {\n double ret = 0, div = 1;\n byte c = read();\n while (c <= ' ') {\n c = read();\n }\n boolean neg = (c == '-');\n if (neg) {\n c = read();\n }\n\n do {\n ret = ret * 10 + c - '0';\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 if (neg) {\n return -ret;\n }\n return ret;\n }\n\n private void fillBuffer() throws IOException {\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 IOException {\n if (bufferPointer == bytesRead) {\n fillBuffer();\n }\n return buffer[bufferPointer++];\n }\n\n public void close() throws IOException {\n if (din == null) {\n return;\n }\n din.close();\n }\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "greedy", "implementation"], "code_uid": "f50a134da1e5c7c8d81c2632d0826ebd", "src_uid": "d1f88a97714d6c13309c88fcf7d86821", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\n\npublic class CodeForces {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n String str = scanner.nextLine();\n String res = \"NO\";\n for(char ch : str.toCharArray()) {\n if(ch == 'H' || ch == 'Q' || ch == '9')\n res = \"YES\";\n }\n System.out.println(res);\n }\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "2e83f9eed6da25d74cbf37f5e553e4b2", "src_uid": "1baf894c1c7d5aeea01129c7900d3c12", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.StringTokenizer;\n\npublic class Main {\n public static void main(String[] args) throws IOException {\n FastScanner in = new FastScanner();\n long Por = in.nextLong(), Kor = in.nextLong();\n BigInteger K = BigInteger.valueOf(Kor), P = BigInteger.valueOf(Por);\n\n K = K.multiply(BigInteger.valueOf(-1));\n ArrayList data = new ArrayList();\n BigInteger coef = BigInteger.ONE;\n while (P != BigInteger.ZERO) {\n int cur = 0;\n BigInteger absCo = coef.abs(), absP = P.abs(), absK = K.abs();\n while (absP.remainder(absCo) == BigInteger.ZERO && absP.divide(absCo).remainder(absK) != BigInteger.ZERO) {\n P = P.subtract(coef);\n absP = P.abs();\n cur++;\n }\n data.add(cur);\n coef = coef.multiply(K);\n }\n\n System.out.println(data.size());\n for (int i = 0; i < data.size(); i++) {\n System.out.print(data.get(i) + \" \");\n }\n System.out.println();\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 String nextLine() {\n st = null;\n try {\n return br.readLine();\n } catch (IOException e) {\n // TODO Auto-generated catch block\n e.printStackTrace();\n }\n return null;\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": ["math"], "code_uid": "4279501db94a421f7526f76cf18671c4", "src_uid": "f4dbaa8deb2bd5c054fe34bb83bc6cd5", "difficulty": 2000.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.StringTokenizer;\nimport java.util.TreeMap;\n\n\npublic class A_349 {\n\n static StringTokenizer st;\n static BufferedReader br;\n static PrintWriter pw;\n public static void main(String[] args) throws IOException { \n \tbr = new BufferedReader(new InputStreamReader(System.in));\n pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); \n int n = nextInt();\n int first = 0, last = 0;\n for (int i = 1; i <= n; i++) {\n\t\t\tint k = nextInt();\n\t\t\tif(k==1){\n\t\t\t\tfirst = i;\n\t\t\t}\n\t\t\tif(k==n){\n\t\t\t\tlast = i;\n\t\t\t}\n\t\t}\n int res1 = Math.max(n-last, last-1);\n int res2 = Math.max(n-first, first-1);\n pw.println(Math.max(res1,res2));\n \n pw.close();\n }\n \n\n\tprivate 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}\nclass Point{\n\tdouble x;\n\tdouble y;\n\tPoint (double x, double y){\n\t\tthis.x=x;\n\t\tthis.y=y;\n\t}\n}", "lang_cluster": "Java", "tags": ["constructive algorithms", "implementation"], "code_uid": "1385abe996d20b1781d5bb9abb69f2ea", "src_uid": "1d2b81ce842f8c97656d96bddff4e8b4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.Scanner;\n\npublic class Test2 {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n String s = in.next();\n char[] chars = s.toCharArray();\n boolean a = false;\n\n StringBuilder buf = new StringBuilder(s);\n\n for (int i = 1; i < s.length();i++) {\n if (Character.isUpperCase(chars[0])) {\n a = true;\n }\n }\n\n if (s.equals(buf.toString().toUpperCase())){\n System.out.print(buf.toString().toLowerCase());\n }\n else if (a = true ) {\n if (buf.substring(1).equals(buf.substring(1).toUpperCase()))\n System.out.print(buf.substring(0,1).toUpperCase()+buf.substring(1).toLowerCase());\n else\n System.out.print(s);\n }\n else System.out.print(s);\n }\n}", "lang_cluster": "Java", "tags": ["strings", "implementation"], "code_uid": "8f02e81394df90f2b9300a517c91a475", "src_uid": "db0eb44d8cd8f293da407ba3adee10cf", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\r\n\r\npublic class HelloWorld {\r\n static int mod = 998244353;\r\n public static void main(String[] args) {\r\n Scanner scan = new Scanner(System.in);\r\n long n = scan.nextLong();\r\n long m = scan.nextLong();\r\n int ans=0;\r\n for(int i=1; i<=n; i++){\r\n ans = add(ans, binPow((int)(m%mod), i));\r\n }\r\n long curr=1;\r\n int count=1;\r\n for(int i=1; i<=n; i++){\r\n if(curr>m)\r\n continue;\r\n if(isPrime(i))\r\n curr *= i;\r\n count = mul(count, (int)((m/curr)%mod));\r\n ans = sub(ans, count);\r\n }\r\n System.out.println(ans);\r\n }\r\n static boolean isPrime(long n){\r\n if(n<=1)\r\n return false;\r\n for(long i=2; i*i<=n; i++){\r\n if(n%i==0)\r\n return false;\r\n }\r\n return true;\r\n }\r\n static int binPow(int x, int y){\r\n int z=1;\r\n while(y!=0){\r\n if((y&1) != 0){\r\n z = mul(z, x);\r\n }\r\n x = mul(x, x);\r\n y >>= 1;\r\n }\r\n return z;\r\n }\r\n static int add(int x, int y){\r\n x += y;\r\n while(x >= mod) \r\n x -= mod;\r\n while(x < 0) \r\n x += mod;\r\n return x;\r\n } \r\n static int sub(int x, int y){\r\n return add(x, -y);\r\n } \r\n static int mul(int x, int y){\r\n return (int) ((x * 1l * y) % mod);\r\n }\r\n}", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics", "number theory"], "code_uid": "5df7a5a3d312cb11f75567990e370b8d", "src_uid": "0fdd91ed33431848614075ebe9d2ee68", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Scanner;\n\n/**\n * @author avcbcoder last modified @23-Jun-2018 @10:09:41 PM 491 Div2 - TODO\n */\n\npublic class C_ {\n\tpublic static void main(String[] args) throws Exception {\n\t\t// solve(39259424579862572L, 1000000000000000000L);\n\t\t// solve(1, 43);\n\t\t// while (true)\n\t\tcalc(sc.nextLong());\n\t}\n\n\tprivate static long calc(long n) {\n\t\tlong lo = 1, hi = 1000000000000000001L;\n\t\t// minimize k i.e mid , if we got ans move to left\n\t\t// otherwise move to right\n\t\tlong min = Long.MAX_VALUE;\n\t\tArrayList ans = new ArrayList<>();\n\t\twhile (lo <= hi) {\n\t\t\tlong mid = (lo + hi) / 2;\n\t\t\tboolean curr = solve(mid, n);\n\t\t\tif (curr) {\n\t\t\t\tmin = Math.min(min, mid);\n\t\t\t\tans.add(mid);\n\t\t\t\thi = mid - 1;\n\t\t\t} else {\n\t\t\t\tlo = mid + 1;\n\t\t\t}\n\t\t}\n\t\t// Collections.sort(ans);\n\t\t// for (long l : ans) {\n\t\t// if (solve(l, n)) {\n\t\t// System.out.println(l);\n\t\t// return l;\n\t\t// }\n\t\t// }\n\t\tSystem.out.println(min);\n\t\treturn min;\n\t}\n\n\tprivate static boolean solve(long k, long n) {\n\t\tlong initial = n;\n\t\tlong v = 0, p = 0;// p is 10% and v is k\n\t\tlong i = 0;\n\t\twhile (n != 0) {\n\t\t\tif (i % 2 == 0) {\n\t\t\t\t// v\n\t\t\t\t// long eat;\n\t\t\t\t// if (n >= k) {\n\t\t\t\t// eat = k;\n\t\t\t\t// } else {\n\t\t\t\t// eat = n;\n\t\t\t\t// }\n\t\t\t\t// v += eat;\n\t\t\t\t// n -= eat;\n\t\t\t\tv += Math.min(n, k);\n\t\t\t\tn -= Math.min(n, k);\n\t\t\t} else {\n\t\t\t\t// p\n\t\t\t\tif (n >= 10) { // now he can eat\n\t\t\t\t\t// long eat = (long) (Math.floor((n * 1.0) / 10.0));\n\t\t\t\t\tlong eat = n / 10;\n\t\t\t\t\tn -= eat;\n\t\t\t\t\tp += eat;\n\t\t\t\t}\n\t\t\t}\n\t\t\ti++;\n\t\t}\n\t\t// double h=(initial * 1.0) / (2);\n\t\tif (v * 2 >= initial) {\n\t\t\treturn true;\n\t\t} else\n\t\t\treturn false;\n\t}\n\n\tpublic static InputStreamReader r = new InputStreamReader(System.in);\n\n\tpublic static BufferedReader br = new BufferedReader(r);\n\n\tpublic static Scanner sc = new Scanner(System.in);\n}\n", "lang_cluster": "Java", "tags": ["implementation", "binary search"], "code_uid": "ec3a233f0caa0a66a6534f8412a68ee5", "src_uid": "db1a50da538fa82038f8db6104d2ab93", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.HashSet;\n\npublic class main {\n public static void main(String[] args) {\n try\n {\n InputStreamReader converter = new InputStreamReader(System.in);\n BufferedReader reader = new BufferedReader(converter);\n String line= null;\n line = reader.readLine();\n HashSet map = new HashSet();\n for (int i=0;i list=new ArrayList<>();\n\tpublic static void main(String args[])throws IOException\n\t{\n\t\tnew Main().run();\n\t}\n\tvoid run()throws IOException\n\t{\n\t\tBufferedReader in=new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter ob=new PrintWriter(System.out);\n\t\tgenerateSuperLuckyNumbers();\n\t\tCollections.sort(list,new Comparator(){\n\t\t\tpublic int compare(Long a,Long b)\n\t\t\t{\n\t\t\t\treturn a.compareTo(b);\n\t\t\t}\n\t\t});\n\t\tlong x=Integer.parseInt(in.readLine());\n\t\tfor(long i : list) {\n\t\t\tif (i>=x)\n\t\t\t\t{\n\t\t\t\t\tob.println(i);\n\t\t\t\t\tob.flush();\n\t\t\t\t\treturn;\n\t\t\t }\n\t\t}\n\t}\n\tvoid generateSuperLuckyNumbers()\n\t{\n\t\tfor(int i=1;i<=5;i++)\n\t\t\tgenerate(i,i,0L);\n\t}\n\tvoid generate(int four,int seven,long number)\n\t{\n\t\tif(four==0 && seven==0)\n\t\t{\n\t\t\tlist.add(number);\n\t\t\treturn;\n\t\t}\n\t\tif(four>0)\n\t\t\tgenerate(four-1,seven,(number*10)+4);\n\t\tif(seven>0)\n\t\t\tgenerate(four,seven-1,(number*10)+7);\n\t\t\n\t}\n}", "lang_cluster": "Java", "tags": ["brute force", "binary search", "bitmasks"], "code_uid": "ee9182cb23b94671904af916a63d5abd", "src_uid": "77b5f83cdadf4b0743618a46b646a849", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Contest {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tlong n = sc.nextLong();\n\t\tlong k = sc.nextLong();\n\t\tif (n+(n-1)=k) {\n\t\t\tSystem.out.println((k-1)/2);\n\t\t}else {\n\t\t\tlong min = Math.max(k-n, 1);\n\t\t\tlong max = k-min+1;\n\t\t\tSystem.out.println((max-min)/2);\n\t\t}\n\t}\n\n}", "lang_cluster": "Java", "tags": ["math"], "code_uid": "6924b304cbb221297c6159ea9e34174f", "src_uid": "98624ab2fcd2a50a75788a29e04999ad", "difficulty": 1000.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.util.StringTokenizer;\n\npublic class Main {\n\n public static void main(String [] args) {\n final FastScanner scanner = new FastScanner();\n int n = scanner.nextInt(), l = scanner.nextInt(), r = scanner.nextInt();\n System.out.println(min(n, l) + \" \" + max(n, r));\n }\n\n\n static int max(int n, int r) {\n int sum = 0;\n int start = 1, curr = 1, unique = 0;\n for (int i = 0; i < n; i++) {\n if (unique < r) {\n sum += start;\n curr = start;\n start *= 2;\n unique ++;\n } else {\n sum += curr;\n }\n// System.out.println(sum);\n }\n return sum;\n }\n\n static int min(int n, int l) {\n int start = 1;\n int sum = 0;\n for (int i = 0; i < l; i++) {\n sum += start;\n start *= 2;\n }\n\n for (int i = l; i < n; i++) {\n sum += 1;\n }\n return sum;\n }\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 {\n 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 int[] readArray(int n) {\n int[] a=new int[n];\n for (int i=0; i 0) {\n\t\t\tboxesNumber++;\n\t\t\tif (b > 0) {\n\t\t\t\ta -= v*(Math.min(b, k-1) + 1);\n\t\t\t\tb -= Math.min(b, k-1);\n\t\t\t} else {\n\t\t\t\ta -= v;\n\t\t\t}\n\t\t}\n\n\t\tSystem.out.println(boxesNumber);\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "greedy"], "code_uid": "b99c56d6f3718ab5e968f73693a52ea8", "src_uid": "7cff20b1c63a694baca69bdf4bdb2652", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.*;\n\npublic class lolat {\n\tstatic int n;\n\n\tstatic long[][] memo;\n\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\twhile (in.hasNext()) {\n\t\t\tn = in.nextInt();\n\t\t\tint k = in.nextInt();\n\t\t\tmemo = new long[n + 1][k + 1];\n\t\t\tfor (int i = 0; i <= n; i++) {\n\t\t\t\tArrays.fill(memo[i], -1);\n\t\t\t}\n\t\t\tSystem.out\n\t\t\t\t\t.println(callRecusive(1, k) % 1000000007);\n\t\t}\n\t}\n\n\tprivate static long callRecusive(int num, int len) {\n\t\t// TODO Auto-generated method stub\n\t\tif (len == 0) {\n\t\t\treturn 1;\n\t\t}\n\t\tif (memo[num][len] != -1)\n\t\t\treturn memo[num][len];\n\t\tlong s = 0;\n\t\tfor (int i = num; i <= n; i += num) {\n\t\t\ts += callRecusive(i, len - 1);\n\t\t}\n\t\treturn (memo[num][len] = s % 1000000007);\n\t}\n\n}", "lang_cluster": "Java", "tags": ["dp", "combinatorics", "number theory"], "code_uid": "e6dc8fc661fa4c7afc0d426ef5206f34", "src_uid": "c8cbd155d9f20563d37537ef68dde5aa", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger; \nimport java.util.*;\n\n//Mann Shah [ DAIICT ].\n//fast io\n\npublic class Main {\n\tstatic int mod = (int) (1e9+7);\n\tstatic InputReader in;\n static PrintWriter out;\n \n \n\tpublic static void main(String args[] ) {\n\t\t\t\n\t\tin = new InputReader(System.in);\n\t out = new PrintWriter(System.out);\n\t \n\t long t = in.nextLong();\n\t long s = in.nextLong();\n\t long x = in.nextLong();\n\t \n\t x -= t;\n\t if(x==0) {\n\t \t\tout.println(\"YES\");\n\t }\n\t else if(x<0) {\n\t \t\tout.println(\"NO\");\n\t }\n\t else {\n\t \tif(x= snumChars)\n\t {\n\t curChar = 0;\n\t try\n\t {\n\t snumChars = stream.read(buf);\n\t } catch (IOException e)\n\t {\n\t throw new InputMismatchException();\n\t }\n\t if (snumChars <= 0)\n\t return -1;\n\t }\n\t return buf[curChar++];\n\t }\n\n\t public int nextInt()\n\t {\n\t int c = snext();\n\t while (isSpaceChar(c))\n\t {\n\t c = snext();\n\t }\n\t int sgn = 1;\n\t if (c == '-')\n\t {\n\t sgn = -1;\n\t c = snext();\n\t }\n\t int res = 0;\n\t do\n\t {\n\t if (c < '0' || c > '9')\n\t throw new InputMismatchException();\n\t res *= 10;\n\t res += c - '0';\n\t c = snext();\n\t } while (!isSpaceChar(c));\n\t return res * sgn;\n\t }\n\n\t public long nextLong()\n\t {\n\t int c = snext();\n\t while (isSpaceChar(c))\n\t {\n\t c = snext();\n\t }\n\t int sgn = 1;\n\t if (c == '-')\n\t {\n\t sgn = -1;\n\t c = snext();\n\t }\n\t long res = 0;\n\t do\n\t {\n\t if (c < '0' || c > '9')\n\t throw new InputMismatchException();\n\t res *= 10;\n\t res += c - '0';\n\t c = snext();\n\t } while (!isSpaceChar(c));\n\t return res * sgn;\n\t }\n\n\t public int[] nextIntArray(int n)\n\t {\n\t int a[] = new int[n];\n\t for (int i = 0; i < n; i++)\n\t {\n\t a[i] = nextInt();\n\t }\n\t return a;\n\t }\n\n\t public long[] nextLongArray(int n)\n\t {\n\t long a[] = new long[n];\n\t for (int i = 0; i < n; i++)\n\t {\n\t a[i] = nextLong();\n\t }\n\t return a;\n\t }\n\t \n\t public ArrayList nextArrayList(int n){\n\t \t\t\tArrayList x = new ArrayList();\n\t \t\t\tfor(int i=0;i() { \n// @Override public int compare(Pair p1, Pair p2) \n// { \n// return p1.x - p2.x; \n// } \n// }); \n// \n// \n// return arr;\n// /* for (int i = 0; i < n; i++) { \n// System.out.print(arr[i].x + \" \" + arr[i].y + \" \"); \n// } \n// System.out.println(); */\n// } \n//} \n\n\n\n\nclass couple implements Comparable\n{ int x,y;\n public couple(int m,int f) {\n \t x=m;\n \t y=f;\n }\n\tpublic int compareTo(couple o) {\n\t\t\n\t\t \n\t\treturn x-o.x;\n\t} \n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "f1fb2b087ebb5d32843e35a6208678a6", "src_uid": "3baf9d841ff7208c66f6de1b47b0f952", "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.Scanner;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n\tstatic Scanner in = new Scanner(System.in);\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 m = Integer.parseInt(st.nextToken());\n\t\tint k = Integer.parseInt(st.nextToken());\n\t\tint[] a = new int[n + 1];\n\t\tst = new StringTokenizer(br.readLine());\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\ta[i] = Integer.parseInt(st.nextToken());\n\t\tint l = m, r = m;\n\t\twhile (l > 1) {\n\t\t\tl--;\n\t\t\tif (a[l] != 0 && a[l] <= k)\n\t\t\t\tbreak;\n\t\t}\n\t\twhile (r < n) {\n\t\t\tr++;\n\t\t\tif (a[r] != 0 && a[r] <= k)\n\t\t\t\tbreak;\n\t\t}\n\t\tint disL = -1, disR = -1;\n\t\tif (l == m || a[l] > k || a[l] == 0)\n\t\t\tdisL = 100;\n\t\telse {\n\t\t\tdisL = m - l;\n\t\t}\n\t\tif (r == m || a[r] > k || a[r] == 0)\n\t\t\tdisR = 100;\n\t\telse {\n\t\t\tdisR = r - m;\n\t\t}\n\n\t\tSystem.out.println(Math.min(disL, disR) * 10);\n\n\t}\n\n}", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "a68a94f9a03519be4134156400c84be6", "src_uid": "57860e9a5342a29257ce506063d37624", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Factory{\n\n\tpublic static boolean productionWillStop(long a, long m){\n\t\tfor (int i = 0; i < 100000; i++) {\n\t\t\tif (a % m == 0){\n\t\t\t\tSystem.out.println(\"Yes\");\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\ta += a % m;\n\t\t}\n\t\tSystem.out.println(\"No\");\n\t\treturn false;\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tlong a = in.nextLong();\n\t\tlong m = in.nextLong();\n\t\tproductionWillStop(a, m);\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "matrices", "implementation"], "code_uid": "d75f9d80095398686665a6f7a191f38c", "src_uid": "f726133018e2149ec57e113860ec498a", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "\n\nimport java.io.*;\nimport java.util.*;\nimport java.lang.*;\nimport static java.lang.Math.*;\n\npublic class Solution implements Runnable {\n \n\n public void solve() throws Exception {\n int r1 = sc.nextInt();\n int c1 = sc.nextInt();\n int r2 = sc.nextInt();\n int c2 = sc.nextInt();\n if(r1 == r2 && c1 == c2) out.print(0 + \" \");\n else if(r1 == r2 || c1 == c2) out.print(1 + \" \");\n else out.print(2 + \" \");\n if((r1 + c1) % 2 != (r2 + c2) % 2) out.print(0 + \" \");\n else if(abs(r1 - r2) == abs(c1 - c2)) out.print(1 + \" \");\n else out.print(2 + \" \");\n int count = 0;\n while(r1 != r2 || c1 != c2) {\n if(r1 != r2) {\n if(r1 > r2) r1--;\n else r1++;\n }\n if(c1 != c2) {\n if(c1 > c2) {\n c1--;\n }else c1++;\n } \n count ++;\n }\n out.println(count);\n out.flush();\n }\n \n static Throwable throwable;\n BufferedReader in;\n PrintWriter out;\n FastScanner sc;\n \n public static void main(String[] args) throws Throwable {\n Thread thread = new Thread(null, new Solution(), \"\", (1 << 26));\n thread.start();\n thread.join();\n if (Solution.throwable != null)\n throw throwable;\n }\n \n public void run() {\n try {\n// in = new BufferedReader(new InputStreamReader(new FileInputStream(\"game.in\")));\n// out = new PrintWriter(new FileWriter(\"game.out\"));\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n sc = new FastScanner(in);\n solve();\n } catch (Throwable throwable) {\n Solution.throwable = throwable;\n } finally {\n out.close();\n }\n }\n}\n\nclass FastScanner {\n BufferedReader reader;\n StringTokenizer strTok;\n \n FastScanner(BufferedReader reader) {\n this.reader = reader; \n }\n \n public String nextToken() throws Exception {\n while (strTok == null || !strTok.hasMoreTokens()) {\n strTok = new StringTokenizer(reader.readLine());\n }\n return strTok.nextToken(); \n }\n \n public int nextInt() throws Exception {\n return Integer.parseInt(nextToken());\n }\n \n public long nextLong() throws Exception {\n return Long.parseLong(nextToken());\n }\n \n public double nextDouble() throws Exception {\n return Double.parseDouble(nextToken());\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "graphs", "shortest paths"], "code_uid": "9d6462ad264c65349181d4d49bc2eff4", "src_uid": "7dbf58806db185f0fe70c00b60973f4b", "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.io.Reader;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.PriorityQueue;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\npublic class CFProblemC {\n\tstatic long mod;\n\n\tpublic static void main(String[] args) {\n\t\tFastScanner input = new FastScanner();\n\t\tmod = input.nextInt();\n\t\tint h1 = input.nextInt(); // start\n\t\tint a1 = input.nextInt(); // goal\n\t\tint x1 = input.nextInt(); // x1*h1+y1 -> h1\n\t\tint y1 = input.nextInt();\n\n\t\tint h2 = input.nextInt();\n\t\tint a2 = input.nextInt(); // goal\n\t\tint x2 = input.nextInt();\n\t\tint y2 = input.nextInt();\n\t\tArrayList values1 = evaluateTimes(h1, a1, x1, y1);\n\t\tArrayList values2 = evaluateTimes(h2, a2, x2, y2);\n\t\tint index1 = 0;\n\t\tint index2 = 0;\n\t\twhile (index1 < values1.size() && index2 < values2.size()) {\n\t\t\tif (values1.get(index1).equals(values2.get(index2))) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (values1.get(index1).compareTo(values2.get(index2)) < 0) {\n\t\t\t\tindex1++;\n\t\t\t} else {\n\t\t\t\tindex2++;\n\t\t\t}\n\t\t}\n\t\tif (values1.size() > 0 && values2.size() > 0 && index1 < values1.size()\n\t\t\t\t&& index2 < values2.size()\n\t\t\t\t&& values1.get(index1).equals(values2.get(index2))) {\n\t\t\tSystem.out.println(values1.get(index1));\n\t\t} else {\n\t\t\tSystem.out.println(-1);\n\t\t}\n\t}\n\n\tprivate static ArrayList evaluateTimes(long h1, long a1, long x1,\n\t\t\tlong y1) {\n\t\tlong start = h1;\n\t\tlong count = 0;\n\t\tArrayList output = new ArrayList();\n\t\twhile (count < 2 * mod + 2) {\n\t\t\tif (start == a1) {\n\t\t\t\toutput.add(count);\n\t\t\t}\n\t\t\tcount++;\n\t\t\tstart = (start * x1 + y1) % mod;\n\t\t}\n\t\tif (output.size() == 0) {\n\t\t\treturn output;\n\t\t} else {\n\t\t\tif (output.size() > 1) {\n\t\t\t\tlong diff = output.get(1) - output.get(0);\n\t\t\t\tlong startVal = output.get(output.size() - 1);\n\t\t\t\tfor (int a = 1; a < mod + .1 * mod; a++) {\n\t\t\t\t\toutput.add(startVal + diff * a);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn output;\n\t}\n\n\tpublic static class FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner(Reader in) {\n\t\t\tbr = new BufferedReader(in);\n\t\t}\n\n\t\tpublic FastScanner() {\n\t\t\tthis(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\t// Slightly different from java.util.Scanner.nextLine(),\n\t\t// which returns any remaining characters in current line,\n\t\t// if any.\n\t\tString readNextLine() {\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", "greedy", "number theory"], "code_uid": "6590f91316816be44b03a92f918da221", "src_uid": "7225266f663699ff7e16b726cadfe9ee", "difficulty": 2200.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 sc = new Scanner(System.in);\n double x = sc.nextDouble();\n double y = sc.nextDouble();\n double a = Math.max(x, y)-1;\n double w = (6-a)/6;\n if(w==0.5)\n System.out.println(\"1/2\");\n else if(w==1)\n System.out.println(\"1/1\");\n else if(w==0.3333333333333333)\n System.out.println(\"1/3\");\n else if(w==0.16666666666666666)\n System.out.println(\"1/6\");\n else if(w==0.6666666666666666)\n System.out.println(\"2/3\");\n else if(w==0.8333333333333334)\n System.out.println(\"5/6\");\n \n \n\n }\n\n}\n", "lang_cluster": "Java", "tags": ["math", "probabilities"], "code_uid": "ef2815d91ac4f3fc86c67f0b3b344014", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\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 cad1 = br.readLine(), cad2 = br.readLine(), cero = \"011220\",uno = \"102102\",dos = \"220011\";\n\t\tint answer, mov = Integer.parseInt(cad1) % 6,pos = Integer.parseInt(cad2);\n\t\t\n\t\tif (pos == 0) {\n\t\t\tSystem.out.println(cero.charAt(mov));\n\t\t}else{\n\t\t\tif (pos == 1) {\n\t\t\t\tSystem.out.println(uno.charAt(mov));\n\t\t\t}else {\n\t\t\t\tSystem.out.println(dos.charAt(mov));\n\t\t\t}\n\t\t}\n\n\t}\n\n}\t", "lang_cluster": "Java", "tags": ["math", "constructive algorithms", "implementation"], "code_uid": "d42f24881396cfd71be158af990364db", "src_uid": "7853e03d520cd71571a6079cdfc4c4b0", "difficulty": 1000.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\n Scanner sc = new Scanner(System.in);\n String s1 = sc.next();\n String s2 = sc.next();\n if (s1.compareToIgnoreCase(s2) > 0) System.out.println(1);\n if (s1.compareToIgnoreCase(s2) < 0) System.out.println(-1);\n if (s1.compareToIgnoreCase(s2) == 0) System.out.println(0);\n }\n}", "lang_cluster": "Java", "tags": ["strings", "implementation"], "code_uid": "ddf3ba6340d94fbb4aa30c73d107a0c0", "src_uid": "ffeae332696a901813677bd1033cf01e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.io.InputStream;\nimport java.io.FileReader;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Set;\nimport java.math.BigInteger;\nimport java.util.List;\nimport java.util.ArrayList;\nimport java.util.Queue;\nimport java.util.PriorityQueue;\nimport java.util.InputMismatchException;\nimport java.io.OutputStream;\nimport java.io.BufferedWriter;\nimport java.io.OutputStreamWriter;\n//https://codeforces.com/problemset/problem/385/A\n//A. Bear and Raspberry\npublic class Problem385A\n{\n public static void main(String[] args) throws IOException\n {\n BufferedReader in=new BufferedReader(new InputStreamReader(System.in));\n PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n \n StringTokenizer dates=new StringTokenizer(in.readLine());\n int n=Integer.parseInt(dates.nextToken());\n int c=Integer.parseInt(dates.nextToken());\n dates=new StringTokenizer(in.readLine());\n int[] day=new int[n];\n int mayor=0;\n int i;\n int pos=0;\n for(i=0;i0&&day[i-1]-day[i]-c>mayor)\n \t{\n \t\tmayor=day[i-1]-day[i]-c;\n \t\tpos=i;\n \t}\n }\n if(mayor<0)\n \tout.println(0);\n else\n \tout.println(mayor);\n out.close();\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "greedy", "implementation"], "code_uid": "0f509b5ca81ba631a96f5c2fc708ee57", "src_uid": "411539a86f2e94eb6386bb65c9eb9557", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CodeforcesSubsequences {\n\n\tpublic static void main(String[] args) {\n FastScanner in = new FastScanner();\n PrintWriter out = new PrintWriter(System.out);\n long n = in.nextLong();\n char ch[] = \"codeforces\".toCharArray();\n int k = 2;\n long s = 1L;\n int f[] = new int[10];\n Arrays.fill(f, 1);\n while(s=n) break;\n \tk++;\n }\n //out.println(k+\" \"+p);\n for(int i=0;i<10;i++) {\n \tfor(int j=0;j= r[i]) lt = false;\n }\n out.println(gt || lt ? \"YES\" : \"NO\");\n out.close();\n }\n}\n", "lang_cluster": "Java", "tags": ["sortings", "greedy"], "code_uid": "30dbb752eed35df88a8d3edd0d63a50d", "src_uid": "e4419bca9d605dbd63f7884377e28769", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.Scanner;\n\npublic class PilesWithStones {\n public static void main(String[] args) {\n Scanner inp = new Scanner(System.in);\n int totalPiles = inp.nextInt();\n int firstVisitSum = 0;\n int secondVisitSum = 0;\n for(int i=0;i=secondVisitSum) {\n System.out.println(\"Yes\");\n } else {\n System.out.println(\"No\");\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "873d99887e3a431e3e274a0c7f827208", "src_uid": "e0ddac5c6d3671070860dda10d50c28a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.*;\n\npublic class Hexadecimal {\n\tpublic static void main(String[] args){\n\t\tScanner reader = new Scanner(System.in);\n\t\tint n = reader.nextInt();\n\t\tint cnt = 0;\n\t\tfor(int i = 1; i <= (1<<9); i++){\n\t\t\tif(Integer.parseInt(Integer.toString(i,2)) <= n)\n\t\t\t\tcnt++;\n\t\t}\n\t\tSystem.out.println(cnt);\n\t}\n}\n", "lang_cluster": "Java", "tags": ["brute force", "math", "implementation"], "code_uid": "526e7b4fe4d929c36206a29e5f8def78", "src_uid": "64a842f9a41f85a83b7d65bfbe21b6cb", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedInputStream;\nimport java.io.InputStream;\nimport java.util.ArrayList;\nimport java.util.Collections;\n\npublic class Main {\n\n public static void main(String[] args) {\n ScanReader in=new ScanReader(System.in);\n int n = in.scanInt();\n int k = in.scanInt();\n String a=in.scanString();\n ArrayList array=new ArrayList();\n for(int i=0;i= 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\n public String scanLine() {\n int c = scan();\n if (c == -1) return null;\n while (isWhiteSpace(c)) c = scan();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = scan();\n } while (c != '\\n' && c != -1);\n return res.toString();\n }\n\n public char scanChar() {\n int c = scan();\n while (isWhiteSpace(c)) c = scan();\n return (char) c;\n }\n\n\n public int scanInt() {\n int I = 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 I *= 10;\n I += n - '0';\n n = scan();\n }\n }\n return neg * I;\n }\n\n public String scanString() {\n int c = scan();\n while (isWhiteSpace(c)) c = scan();\n StringBuilder RESULT = new StringBuilder();\n do {\n RESULT.appendCodePoint(c);\n c = scan();\n } while (!isWhiteSpace(c));\n return RESULT.toString();\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 public long scanLong() {\n long I = 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 I *= 10;\n I += n - '0';\n n = scan();\n }\n }\n return neg * I;\n }\n\n public void scanLong(long[] A) {\n for (int i = 0; i < A.length; i++) A[i] = scanLong();\n }\n\n public void scanInt(int[] A) {\n for (int i = 0; i < A.length; i++) A[i] = scanInt();\n }\n\n public double scanDouble() {\n int c = scan();\n while (isWhiteSpace(c)) c = scan();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = scan();\n }\n double RESULT = 0;\n while (!isWhiteSpace(c) && c != '.') {\n if (c == 'e' || c == 'E') {\n return RESULT * Math.pow(10, scanInt());\n }\n RESULT *= 10;\n RESULT += c - '0';\n c = scan();\n }\n if (c == '.') {\n c = scan();\n double m = 1;\n while (!isWhiteSpace(c)) {\n if (c == 'e' || c == 'E') {\n return RESULT * Math.pow(10, scanInt());\n }\n m /= 10;\n RESULT += (c - '0') * m;\n c = scan();\n }\n }\n return RESULT * sgn;\n }\n\n }\n}\n", "lang_cluster": "Java", "tags": ["sortings", "implementation", "greedy"], "code_uid": "8a8ccc23141cc4ca396b2dcf3a8f8b32", "src_uid": "56b13d313afef9dc6c6ba2758b5ea313", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n \npublic class exercise {\n\tstatic int a[]=new int [4];;\n\tpublic static void input() {\n\t\tScanner input=new Scanner(System.in);\n\t\tfor(int i=0;i<4;i++) {\n\t\t\ta[i]=input.nextInt();\n\t\t}\n\t\t\n\t}\n\t\n\tpublic static void sort(int x[]) {\n\t\tfor(int j=0;j0;i--) {\n\t\t\t\tif(x[i]>x[i-1]) {\n\t\t\t\t\tint temp=x[i];\n\t\t\t\t\tx[i]=x[i-1];\n\t\t\t\t\tx[i-1]=temp;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tpublic static void main(String args[]) {\n\t\t\n\t\tinput();\n\t\tsort(a);\t\t\n\t\tif(a[0]>a[1]+a[2]+a[3])System.out.print(\"NO\");\n\t\telse if(a[0]==a[1]+a[2]+a[3])System.out.print(\"YES\");\n\t\telse if(a[0]a[1]+a[2])System.out.print(\"NO\");\n\t\t\telse if(a[0]+a[3] list = new ArrayList<>();\n\t\twhile(i < n) {\n\t\t\tint count = 0;\n\t\t\twhile(i < n && a[i] == 'B') {\n\t\t\t\tcount++;\n\t\t\t\ti++;\n\t\t\t}\n\t\t\tif(count != 0) {\n\t\t\t\tlist.add(count);\n\t\t\t}i++;\n\t\t}\n\t\tif(list.isEmpty())System.out.println(0);\n\t\telse {\n\t\t\tSystem.out.println(list.size());\n\t\t\tfor(int item : list) {\n\t\t\t\tSystem.out.print(item + \" \");\n\t\t\t}\n\t\t}\n\t\t\t\t\n\t}\n\t\n\tpublic void sort(int[] a) {\n\t\tArrayList l=new ArrayList<>();\n\t\tfor (int i:a) l.add(i);\n\t\tCollections.sort(l);\n\t\tfor (int i=0; i ssx = new TreeSet();\n\t\tSortedSet ssy = new TreeSet();\n\t\tIterator itx,ity;\n\t\tint x[],y[],t,midx,midy;\n\t\tx=new int[8];\n\t\ty=new int[8];\n\t\tboolean flag,fail=false;\n\t\tfor(t=0;t<8;t++) {\n\t\t\ts=new StringTokenizer(br.readLine());\n\t\t\tx[t]=Integer.parseInt(s.nextToken());\n\t\t\tssx.add(x[t]);\n\t\t\ty[t]=Integer.parseInt(s.nextToken());\n\t\t\tssy.add(y[t]);\n\t\t\tfor(int i=t-1;i>=0;i--) {\n\t\t\t\tif (x[i]==x[t]) \n\t\t\t\t\tif (y[i]==y[t]) {\n\t\t\t\t\t\tfail=true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t}\n\t\t\t\t\t\n\t\t\t\n\t\t}\n\t\tif (ssx.size() != 3 || ssy.size() != 3 || fail)\n\t\t\tbw.write(\"ugly\\n\");\n\t\telse {\n\t\t\titx=ssx.iterator();\n\t\t\tity=ssy.iterator();\n\t\t\titx.next();\n\t\t\tmidx=(Integer)itx.next();\n\t\t\tity.next();\n\t\t\tmidy=(Integer)ity.next();\n\t\t\tfor (t=0;t<8;t++)\n\t\t\t\tif (x[t]==midx && y[t]==midy)\n\t\t\t\t\tbreak;\n\t\t\tif (t<8) bw.write(\"ugly\\n\");\n\t\t\telse bw.write(\"respectable\\n\");\n\t\t}\n\t\tbw.flush();\n\t}\n}\n\n", "lang_cluster": "Java", "tags": ["sortings"], "code_uid": "37ca188c76ae308c2b0ca421116b562a", "src_uid": "f3c96123334534056f26b96f90886807", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class Solution {\n public static void main(String[] args)throws IOException{\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter out = new PrintWriter(System.out,true);\n StringTokenizer st = new StringTokenizer(br.readLine());\n int n = Integer.parseInt(st.nextToken());\n int m = Integer.parseInt(st.nextToken());\n int count = 1,people=0;\n st = new StringTokenizer(br.readLine());\n int[] a = new int[n];\n for(int i =0;i= coins[i]){\n n -= coins[i];\n res++;\n }\n i++;\n }\n p(res);\n p(\"\\n\");\n }\n\n\n //SOLUTION END\n void hold(boolean b)throws Exception{if(!b)throw new Exception(\"Hold right there, Sparky!\");}\n void exit(boolean b){if(!b)System.exit(0);}\n final long IINF = (long)1e15;\n final int INF = (int)1e9+2, MX = (int)2e6+5;\n DecimalFormat df = new DecimalFormat(\"0.00000000000\");\n double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-8;\n static boolean multipleTC = true, memory = false, fileIO = false;\n FastReader in;PrintWriter out;\n void run() throws Exception{\n long ct = System.currentTimeMillis();\n if (fileIO) {\n in = new FastReader(\"\");\n out = new PrintWriter(\"\");\n } else {\n in = new FastReader();\n out = new PrintWriter(System.out);\n }\n //int T = (multipleTC) ? ni() : 1;\n pre();\n //for (int t = 1; t <= T; t++) solve(t);\n solve(0);\n out.flush();\n out.close();\n System.err.println(System.currentTimeMillis() - ct + \"ms\");\n }\n public static void main(String[] args) throws Exception{\n if(memory)new Thread(null, new Runnable() {public void run(){try{new Solutions().run();}catch(Exception e){e.printStackTrace();}}}, \"1\", 1 << 28).start();\n else new Solutions().run();\n }\n int[][] make(int n, int[] from, int[] to, int e, boolean f){\n int[][] g = new int[n][];int[]cnt = new int[n];\n for(int i = 0; i< e; i++){\n cnt[from[i]]++;\n if(f)cnt[to[i]]++;\n }\n for(int i = 0; i< n; i++)g[i] = new int[cnt[i]];\n for(int i = 0; i< e; i++){\n g[from[i]][--cnt[from[i]]] = to[i];\n if(f)g[to[i]][--cnt[to[i]]] = from[i];\n }\n return g;\n }\n int[][][] makeS(int n, int[] from, int[] to, boolean f){\n int[][][] g = new int[n][][];int[]cnt = new int[n];\n for(int i:from)cnt[i]++;if(f)for(int i:to)cnt[i]++;\n for(int i = 0; i< n; i++)g[i] = new int[cnt[i]][];\n for(int i = 0; i< from.length; i++){\n g[from[i]][--cnt[from[i]]] = new int[]{to[i], i};\n if(f)g[to[i]][--cnt[to[i]]] = new int[]{from[i], i};\n }\n return g;\n }\n int find(int[] set, int u){return set[u] = (set[u] == u?u:find(set, set[u]));}\n int digit(long s){int ans = 0;while(s>0){s/=10;ans++;}return ans;}\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": ["greedy", "dp"], "code_uid": "0bc3f1b1469be1ff806766845ea7e670", "src_uid": "8e81ad7110552c20297f08ad3e5f8ddc", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.math.RoundingMode;\nimport java.text.DecimalFormat;\nimport java.util.*;\nimport java.util.regex.Matcher;\nimport java.util.regex.Pattern;\n\nimport javax.net.ssl.SSLContext;\n\npublic class Main\n{ \n static long mod=(long)(1e+9) + 7; \n static int[] sieve;static int ans=0;\n static ArrayList primes;\n \n \n public static double area(int x1, int y1, int x2, int y2,int x3, int y3)\n {\n return Math.abs((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2.0);\n }\n\n\npublic static int ch(square cor[], int x, int y)\n{\n int x1 = cor[0].x, y1 = cor[0].y, x2 = cor[1].x, y2 = cor[1].y;\n int x3 = cor[2].x, y3 = cor[2].y, x4 = cor[3].x, y4 = cor[3].y;\n\n double a = area(x1, y1, x2, y2, x3, y3) + area(x1, y1, x4, y4, x3, y3);\n \n double p = area(x, y, x1, y1, x2, y2);\n double q = area(x, y, x2, y2, x3, y3);\n double r = area(x, y, x3, y3, x4, y4);\n double s = area(x, y, x1, y1, x4, y4);\n\n if(a==(p+q+r+s)) return 1;\n return 0;\n }\n\n static class square\n {\n\t int x;int y;\n }\n \n public static void main(String[] args) throws java.lang.Exception\n {\t \t\n\t fast s = new fast();\n\t PrintWriter out=new PrintWriter(System.out);\n\t Scanner sc=new Scanner(System.in);\n\t StringBuilder final_ans = new StringBuilder(); \n\t \n\t square a[]=new square[4];\n\t square b[]=new square[4];\n\t \n\t for(int i=0;i<4;i++)\n\t {\n\t \t a[i]=new square();\n\t \t a[i].x=s.nextInt();\n\t \t a[i].y=s.nextInt();\n\t }\n\t \n\t for(int i=0;i<4;i++)\n\t {\n\t \t b[i]=new square();\n\t \t b[i].x=s.nextInt();\n\t \t b[i].y=s.nextInt();\n\t }\n\t \t\t\n\t for(int i = -100 ; i <= 100 ; i++)\n\t {\n\t \t\tfor(int j = -100 ; j <= 100 ; j++)\n\t \t\t{\n\t \t\t\tif(ch(a, i, j)==1 && ch(b, i, j)==1)\n\t \t\t\t{\n\t \t\t\t\tSystem.out.println(\"YES\");\n\t \t\t\t\treturn ;\n\t \t\t\t}\n\t \t\t}\n\t \t }\n\t \n\t System.out.println(\"NO\");\n }\n \n \n\n static class fast {\n\t\tprivate InputStream i;\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n\t\t\n\t\tpublic static void division(char ch[],int divisor)\n\t\t {\n\t\t\t int div=Character.getNumericValue(ch[0]); int mul=10;int remainder=0;\n\t\t\t StringBuilder quotient=new StringBuilder(\"\");\n\t\t\t for(int i=1;i();\n\t\t\tsieve[1]=1;\n\t\t\tfor(int i=2;i<=Math.sqrt(size);i++)\n\t\t\t{\n\t\t\t\tif(sieve[i]==0)\n\t\t\t\t {\n\t\t\t\t\tfor(int j=i*i;j 0)\n\t\t {\n\t\t if(b%2 == 1)\n\t\t {\n\t\t x=x*y;\n\t\t if(x>MOD) x=x%(MOD);\n\t\t }\n\t\t y = y*y;\n\t\t if(y>MOD) y=y%(MOD); \n\t\t b >>= 1;\n\t\t }\n\t\t return x;\n\t\t }\n\n\t\t\n\t\t public static int lower(Integer[] a,int start,int end,int key)\n\t\t {\n\t\t\t int mid=(start+end)>>1;\n\t\t\t if(start==end && a[mid]end) return -1;\n\n\t\t\t if(a[mid]>=key && (((mid-1)>=0 && a[mid-1]=0 && a[mid-1]==key) return lower(a,start,mid-1,key); \n\t\t\t else if(key>a[mid]) return lower(a,mid+1,end,key);\n\t\t\t else return lower(a,start,mid-1,key);\n\t\t}\n\t\t \n\t\t public static int upper(Integer a[],int start,int end,int key)\n\t\t {\n\t\t\t int mid=(start+end)>>1;\n\t\t\t if(start==end && a[mid]>key) {return -1;}\n\t\t\t if(start>end) return -1;\n\n\t\t\t if(a[mid]<=key && (((mid+1)key) || (mid+1)==a.length)) return mid;\n\t\t\t else if(a[mid]== key && (mid+1)=a[mid]) return upper(a,mid+1,end,key);\n\t\t\t else return upper(a,start,mid-1,key);\n\t\t} \n\t\t \n\t\tpublic int gcd(int a,int b)\n\t\t{\n\t\t\tif(a==0) return b;\n\t\t\treturn gcd(b%a,a);\n\t\t}\n\t\tpublic fast() {\n\t\t\tthis(System.in);\n\t\t}\n\t\tpublic fast(InputStream is) {\n\t\t\ti = is;\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 = i.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\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\t\tpublic String nextString() {\n \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\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\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\tpublic boolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\t\tpublic boolean isEndOfLine(int c) {\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t}\n\n\t}\t\n}\n \n \n \n \n\n\n\n", "lang_cluster": "Java", "tags": ["brute force"], "code_uid": "2bb1d00412870040e0e385038dc89327", "src_uid": "f6a3dd8b3bab58ff66055c61ddfdf06a", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.*;\npublic class DoubleCola {\n\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner (System.in) ;\n\t\twhile (sc.hasNext())\n\t\t{\n\t\t\tint n = sc.nextInt() ;\n\t\t\tint m = 5 ;\n\t\t\tint counter = 1 ;\n\t\t\tString s =\"\" ;\n\t\tif (n < 5) {\n\t\t\tif (n == 1) {\n\t\t\t\ts = \"Sheldon\" ;\n\t\t\t}else{\n\t\t\t\tif (n == 2) {\n\t\t\t\t\ts = \"Leonard\" ;\n\t\t\t\t}else{\n\t\t\t\t\tif (n == 3) {\n\t\t\t\t\t\ts = \"Penny\" ;\n\t\t\t\t\t}else{\n\t\t\t\t\t\tif (n == 4) s = \"Rajesh\" ;\n\t\t\t\t\t\telse{\n\t\t\t\t\t\t\ts = \"Howard \" ;\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}else{\n\t\t\tfor (int i = 0; n > m*counter; i++) {\n\t\t\t\tn -= m*counter ;\n\t\t\t\t//System.out.println(m +\" * \" + counter + \" = \" +n);\n\t\t\t\tcounter *= 2 ;\n\t\t\t}\n\t\t\t/**\n\t\t\tif (counter == 2) counter = 1;\n\t\t\telse{\n\t\t\t\tif (counter != 1) counter -= 2 ;\n\t\t\t//\telse counter -- ;\n\t\t\t}\n\t\t\t*/\n\t\t\tint help = 0 ;\n\t\t\tfor (int i = 1; n > counter && counter != 0; i++) {\n\t\t\t\tn -= counter ;\n\t\t\t\thelp = i ;\n\t\t\t}\n\t\t\tif (help == 0) {\n\t\t\t\ts = \"Sheldon\" ;\n\t\t\t}else{\n\t\t\t\tif (help == 1) {\n\t\t\t\t\ts = \"Leonard\" ;\n\t\t\t\t}else{\n\t\t\t\t\tif (help == 2) {\n\t\t\t\t\t\ts = \"Penny\" ;\n\t\t\t\t\t}else{\n\t\t\t\t\t\tif (help == 3 ) s = \"Rajesh \" ;\n\t\t\t\t\t\telse s = \"Howard\" ;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (counter == 0) s = \"Sheldon\" ;\n\t\t }\n\t\t\tSystem.out.println(s);\n\t\t}\n\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "2748b5d98b02fd596a29fde290d14bdc", "src_uid": "023b169765e81d896cdc1184e5a82b22", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "\nimport java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class BetaRound70_C implements Runnable {\n\n final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n BufferedReader in;\n PrintWriter out;\n StringTokenizer tok = new StringTokenizer(\"\");\n\n void init() throws IOException {\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 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 @Override\n public void run() {\n try {\n long t1 = System.currentTimeMillis();\n init();\n Locale.setDefault(Locale.US);\n solve();\n out.close();\n long t2 = System.currentTimeMillis();\n System.err.println(\"Time = \" + (t2 - t1));\n } catch (Exception e) {\n e.printStackTrace(System.err);\n System.exit(-1);\n }\n }\n\n public static void main(String[] args) {\n new Thread(new BetaRound70_C()).start();\n }\n \n void solve() throws IOException {\n long m = readInt();\n long n = readInt();\n long k = readInt();\n if (m % 2 == 0) {\n out.print(\"Marsel\");\n return;\n }\n if (n == 1) {\n out.print(\"Marsel\");\n return;\n }\n// boolean[] p = new boolean[1000*100+1];\n// Arrays.fill(p, true);\n// p[0]=p[1]=false;\n// for (long i = 2; i <= 1000*100; i++) {\n// if (p[(int)i]) {\n// for (long j = i*i; j <= 1000*100; j+=i) {\n// p[(int)j] = false;\n// }\n// }\n// }\n \n boolean prime = true;\n for (int i = 2; i*i <= n; i++) {\n if (n%i==0) {\n if (n/i < k) {\n out.print(\"Marsel\");\n return;\n }\n prime = false;\n break;\n }\n }\n \n if (prime) {\n if (k == 1) {\n out.print(\"Timur\");\n return;\n } else {\n out.print(\"Marsel\");\n return;\n }\n }\n \n out.print(\"Timur\");\n// if (n % 2 == 0) {\n// out.print(\"Timur\");\n// return;\n// } else {\n// out.print(\"Marsel\");\n// return;\n// }\n }\n \n}\n", "lang_cluster": "Java", "tags": ["dp", "number theory", "games"], "code_uid": "862cbb30a8a48c0cd3857afb4deaaae5", "src_uid": "4a3767011ddac874efa021fff7c94432", "difficulty": 2000.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.StringTokenizer;\n\n\npublic class Main {\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 a = sc.nextInt(), b = sc.nextInt();\n\t\tchar[] s = sc.next().toCharArray();\n\t\tint Tx = 0, Ty = 0;\n\t\tfor(char c: s)\n\t\t\tif(c == 'U')\n\t\t\t\t++Ty;\n\t\t\telse if(c == 'D')\n\t\t\t\t--Ty;\n\t\t\telse if(c == 'R')\n\t\t\t\t++Tx;\n\t\t\telse\n\t\t\t\t--Tx;\n\t\tint px = 0, py = 0;\n\t\tboolean yes = check(a, b, Tx, Ty, px, py);\n\t\tfor(char c: s)\n\t\t{\n\t\t\tif(c == 'U')\n\t\t\t\t++py;\n\t\t\telse if(c == 'D')\n\t\t\t\t--py;\n\t\t\telse if(c == 'R')\n\t\t\t\t++px;\n\t\t\telse\n\t\t\t\t--px;\n\t\t\tyes |= check(a, b, Tx, Ty, px, py);\n\t\t}\n\t\tout.println(yes ? \"Yes\" : \"No\");\n\t\tout.flush();\n\t\tout.close();\n\t}\n\t\n\tstatic boolean check(int a, int b, int tx, int ty, int px, int py)\n\t{\n\t\tint lx = check(a - px, tx), ly = check(b - py, ty);\n\t\tif(lx == -2 || ly == -2)\n\t\t\treturn false;\n\t\treturn lx == -1 || ly == -1 || lx == ly;\n\t}\n\t\n\tstatic int check(int c, int t)\n\t{\n\t\tif(t == 0)\n\t\t\treturn c == 0 ? -1 : -2;\n\t\treturn 1l * c * t >= 0 && c % t == 0 ? c / t : -2;\n\t}\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 { return Double.parseDouble(next()); }\n\n\t\tpublic boolean ready() throws IOException {return br.ready();} \n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation", "binary search"], "code_uid": "ac8f355dc4dc7cab24077371672cbef3", "src_uid": "5d6212e28c7942e9ff4d096938b782bf", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/*\n * Author- Naitik Dodia\n * BTech 3rd Year DAIICT\n */\n \nimport java.io.*;\n\nimport java.math.*;\nimport java.util.*;\nimport javax.print.attribute.SetOfIntegerSyntax;\n \npublic class Solution {\n\tprivate static InputStream stream;\n\tprivate static byte[] buf = new byte[1024];\n\tprivate static int curChar;\n\tprivate static int numChars;\n\tprivate static SpaceCharFilter filter;\n\tprivate static PrintWriter pw;\n\tprivate static long count = 0,mod=1000000007;\n\tprivate static TreeSetts[]=new TreeSet[200000];\n \n\tpublic static void main(String args[]) throws Exception {\n\t\tInputReader(System.in);\n\t\tpw = new PrintWriter(System.out);\n\t\tsoln();\n\t\tpw.close();\n\t}\n\tprivate static boolean visited[];\n\tprivate static int par[];\n\tprivate static LinkedList[] adj;\n\tprivate static void dfs(int start,int root) {\n\t\tvisited[start]=true;\n\t\tpar[start]=root;\n\t\tfor(int i:adj[start]) {\n\t\t\tif(!visited[i]) {\n\t\t\t\tdfs(i,start);\n\t\t\t}\n\t\t}\n\t}\n\tprivate static void soln(){\n\t\tint a=nextInt(),b=nextInt(),x=nextInt(),y=nextInt(),z=nextInt();\n\t\tlong ans=0;\n\t\tif((long)a<2*(long)x) {\n\t\t\tans+=2*(long)x-a;\n\t\t\ta=0;\n\t\t\t//pw.println(\"1 \"+ans);\n\t\t}else {\n\t\t\ta=a-2*x;\n\t\t}\n\t\tif((long)b<3*(long)z) {\n\t\t\tans+=3*(long)z-b;\n\t\t\tb=0;\n\t\t\t//pw.println(\"2 \"+ans);\n\t\t}else {\n\t\t\tb=b-3*z;\n\t\t}\n\t\tif(a0?y-a:0;\n\t\t\tb=b-a;\n\t\t\ta=0;\n\t\t}else {\n\t\t\ty=y-b>0?y-b:0;\n\t\t\tb=a-b;\n\t\t\ta=0;\n\t\t}\n\t\tif(y>b) {\n\t\t\tans+=b+2*(y-b);\n\t\t\t//pw.println(\"3 \"+ans);\n\t\t}else{\n\t\t\tans+=y;\n\t\t\t//pw.println(ans);\n\t\t}\n\t\tpw.println(ans);\n\t}\n\t\n\tpublic static int bfsPair(int[][] arr,boolean[][] visited,int x1,int y1,int x2,int y2) {\n\t\tQueue q=new LinkedList();\n\t\tvisited[x1][y1]=true;\n\t\tint level = 1;\n\t\tint increamenter=0;\n\t\tif(x1-1>=0)\n\t\tif(arr[x1-1][y1]==1) increamenter++;\n\t\tif(y1-1>=0)\n\t\tif(arr[x1][y1-1]==1) increamenter++;\n\t\tif(y1+1=0 && y>=0 && x-1=0 && y-1>=0 && x=0 && y+1>=0 && x=0 && y>=0 && x+1[] gp, int s,boolean[] visited,int[] dist){\n\t\tQueue qu=new LinkedList();\n\t\tint level = 1;\n\t\tint increamenter;\n\t\tif(gp[s]!=null)\n\t\tincreamenter=gp[s].size()+1;\n\t\telse return;\n\t\tvisited[s]=true;\n\t\tqu.add(s);\n\t\twhile(!qu.isEmpty()){\n\t\t\tint temp=qu.poll();\n\t\t\t//visited[temp]=true;\n\t\t\tincreamenter--;\n\t\t\tdist[temp]=level*6;\n\t\t\tfor(int i=0;i allprime(int n){\n\t\tArrayList arr=new ArrayList();\n\t\tarr.add(2);\n\t\tfor(int i=3;i{\n\t\t \n\t\tint idx,val;\n\t\tPair(int idx,int val){\n\t\t\tthis.idx=idx;\n\t\t\tthis.val=val;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(Pair o) {\n\t\t\t// TODO Auto-generated method stub\n\t\t//\tSort in increasing order\n \n\t\t\n\t\t\tif(o.val high)\n\t\t\treturn -1;\n\t\tint mid = low + (high - low) / 2;\n\t\tif (a[mid] == target)\n\t\t\treturn mid;\n\t\tif (a[mid] > target)\n\t\t\thigh = mid - 1;\n\t\tif (a[mid] < target)\n\t\t\tlow = mid + 1;\n\t\treturn BinarySearch(a, low, high, target);\n\t}\n\t\n\tpublic static String reverseString(String s) {\n\t\tStringBuilder sb = new StringBuilder(s);\n\t\tsb.reverse();\n\t\treturn (sb.toString());\n\t}\n\tpublic static long pow(long n, long p, long m) {\n\t\tlong result = 1;\n\t\tif (p == 0)\n\t\t\treturn 1;\n\t\tif (p == 1)\n\t\t\treturn n;\n\t\twhile (p != 0) {\n\t\t\tif (p % 2 == 1)\n\t\t\t\tresult *= n;\n\t\t\tif (result >= m)\n\t\t\t\tresult %= m;\n\t\t\tp >>= 1;\n\t\t\tn *= n;\n\t\t\tif (n >= m)\n\t\t\t\tn %= m;\n\t\t}\n\t\treturn result;\n\t}\n\tpublic static long pow(long n, long p) {\n\t\tlong result = 1;\n\t\tif (p == 0)\n\t\t\treturn 1;\n\t\tif (p == 1)\n\t\t\treturn n;\n\t\twhile (p != 0) {\n\t\t\tif (p % 2 == 1)\n\t\t\t\tresult *= n;\n\t\t\tp >>= 1;\n\t\t\tn *= n;\n\t\t}\n\t\treturn result;\n\t}\n\tpublic static int[] radixSort(int[] f) {\n\t\tint[] to = new int[f.length];\n\t\t{\n\t\t\tint[] b = new int[65537];\n\t\t\tfor (int i = 0; i < f.length; i++)\n\t\t\t\tb[1 + (f[i] & 0xffff)]++;\n\t\t\tfor (int i = 1; i <= 65536; i++)\n\t\t\t\tb[i] += b[i - 1];\n\t\t\tfor (int i = 0; i < f.length; i++)\n\t\t\t\tto[b[f[i] & 0xffff]++] = f[i];\n\t\t\tint[] d = f;\n\t\t\tf = to;\n\t\t\tto = d;\n\t\t}\n\t\t{\n\t\t\tint[] b = new int[65537];\n\t\t\tfor (int i = 0; i < f.length; i++)\n\t\t\t\tb[1 + (f[i] >>> 16)]++;\n\t\t\tfor (int i = 1; i <= 65536; i++)\n\t\t\t\tb[i] += b[i - 1];\n\t\t\tfor (int i = 0; i < f.length; i++)\n\t\t\t\tto[b[f[i] >>> 16]++] = f[i];\n\t\t\tint[] d = f;\n\t\t\tf = to;\n\t\t\tto = d;\n\t\t}\n\t\treturn f;\n\t}\n\tpublic static int nextPowerOf2(final int a) {\n\t\tint b = 1;\n\t\twhile (b < a) {\n\t\t\tb = b << 1;\n\t\t}\n\t\treturn b;\n\t}\n\tpublic static boolean PointInTriangle(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) {\n\t\tint s = p2 * p5 - p1 * p6 + (p6 - p2) * p7 + (p1 - p5) * p8;\n\t\tint t = p1 * p4 - p2 * p3 + (p2 - p4) * p7 + (p3 - p1) * p8;\n \n\t\tif ((s < 0) != (t < 0))\n\t\t\treturn false;\n \n\t\tint A = -p4 * p5 + p2 * (p5 - p3) + p1 * (p4 - p6) + p3 * p6;\n\t\tif (A < 0.0) {\n\t\t\ts = -s;\n\t\t\tt = -t;\n\t\t\tA = -A;\n\t\t}\n\t\treturn s > 0 && t > 0 && (s + t) <= A;\n\t}\n\tpublic static float area(int x1, int y1, int x2, int y2, int x3, int y3) {\n\t\treturn (float) Math.abs((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2.0);\n\t}\n \n\tpublic static boolean isPrime(int n) {\n\t\t// Corner cases\n\t\tif (n <= 1)\n\t\t\treturn false;\n\t\tif (n <= 3)\n\t\t\treturn true;\n \n\t\t// This is checked so that we can skip \n\t\t// middle five numbers in below loop\n\t\tif (n % 2 == 0 || n % 3 == 0)\n\t\t\treturn false;\n \n\t\tfor (int i = 5; i * i <= n; i = i + 6)\n\t\t\tif (n % i == 0 || n % (i + 2) == 0)\n\t\t\t\treturn false;\n \n\t\treturn true;\n\t}\n \n\t//merge Sort\n \n\tstatic long sort(int a[])\n\t{ int n=a.length;\n\t\tint b[]=new int[n];\t\n\t\treturn mergeSort(a,b,0,n-1);}\n\tstatic long mergeSort(int a[],int b[],long left,long right)\n\t{ long c=0;if(lefta[j]) {b[k++]=a[i++]; }\n\telse\t{ b[k++]=a[j++];c+=mid-i;}}\n\twhile (i <= (int)mid - 1) b[k++] = a[i++]; \n\twhile (j <= (int)right) b[k++] = a[j++];\n\tfor (i=(int)left; i <= (int)right; i++) \n\t\ta[i] = b[i]; return c; }\n\n\t// To Get Input\n\t// Some Buffer Methods\n \n\tpublic static void InputReader(InputStream stream1) {\n\t\tstream = stream1;\n\t}\n \n\tprivate static boolean isWhitespace(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n \n\tprivate static boolean isEndOfLine(int c) {\n\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t}\n \n\tprivate static 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 static 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 static 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 static 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 static 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 static 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 static int[][] next2dArray(int n, int m) {\n\t\tint[][] arr = 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\tarr[i][j] = nextInt();\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n \n\tprivate static 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 static void pArray(int[] arr) {\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\tpw.print(arr[i] + \" \");\n\t\t}\n\t\tpw.println();\n\t\treturn;\n\t}\n \n\tprivate static void pArray(long[] arr) {\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\tpw.print(arr[i] + \" \");\n\t\t}\n\t\tpw.println();\n\t\treturn;\n\t}\n \n\tprivate static void pArray(boolean[] arr) {\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\tpw.print(arr[i] + \" \");\n\t\t}\n\t\tpw.println();\n\t\treturn;\n\t}\n \n\tprivate static 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 interface SpaceCharFilter {\n\t\tpublic boolean isSpaceChar(int ch);\n\t}\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "66acc67c05b74a5b88746e850c36ef0e", "src_uid": "35202a4601a03d25e18dda1539c5beba", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class File1{\n\tpublic static void main(String[] args){\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tint x1 = in.nextInt();\n\t\tint y1 = in.nextInt();\n\t\tint x2 = in.nextInt();\n\t\tint y2 = in.nextInt();\n\t\tif(x1==0&&x2==0)\n\t\t\tSystem.out.println(Math.abs(y2-y1));\n\t\telse if(x1==0&&x2==n)\n\t\t\tSystem.out.println(n+Math.min(y1+y2,2*n-y1-y2));\n\t\telse if(x1==0&&y2==0)\n\t\t\tSystem.out.println(y1+x2);\n\t\telse if(x1==0&&y2==n)\n\t\t\tSystem.out.println(n-y1+x2);\n\t\telse if(x1==n&&x2==n)\n\t\t\tSystem.out.println(Math.abs(y2-y1));\n\t\telse if(x1==n&&x2==0)\n\t\t\tSystem.out.println(n+Math.min(y1+y2, 2*n-y1-y2));\n\t\telse if(x1==n&&y2==0)\n\t\t\tSystem.out.println(n-x2+y1);\n\t\telse if(x1==n&&y2==n)\n\t\t\tSystem.out.println(2*n-y1-x2);\n\t\telse if(y1==0&&y2==0)\n\t\t\tSystem.out.println(Math.abs(x2-x1));\n\t\telse if(y1==0&&y2==n)\n\t\t\tSystem.out.println(n+Math.min(x1+x2,2*n-x1-x2));\n\t\telse if(y1==0&&x2==0)\n\t\t\tSystem.out.println(y2+x1);\n\t\telse if(y1==0&&x2==n)\n\t\t\tSystem.out.println(n-x1+y2);\n\t\telse if(x2==0)\n\t\t\tSystem.out.println(n-y2+x1);\n\t\telse if(x2==n)\n\t\t\tSystem.out.println(2*n-y2-x1);\n\t\telse if(y2==n)\n\t\t\tSystem.out.println(Math.abs(x2-x1));\n\t\telse System.out.println(n+Math.min(2*n-x1-x2,x1+x2));\n\t}\n}", "lang_cluster": "Java", "tags": ["dfs and similar", "greedy", "implementation"], "code_uid": "d05fe9395b4d22aac41a3f6b02b9d29e", "src_uid": "685fe16c217b5b71eafdb4198822250e", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.StringTokenizer;\n\npublic class A {\n\n public static void main(String[] args) throws Exception {\n Scanner sc = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n int n = sc.nextInt();\n char[] a = sc.next().toCharArray();\n List list = new ArrayList<>();\n for (char c : a) list.add(c);\n while (true) {\n int max = 0, maxIdx = -1;\n for (int i = 0; i < list.size(); i++) {\n if ((i > 0 && list.get(i) == list.get(i - 1) + 1 || i < list.size() - 1 && list.get(i) == list.get(i + 1) + 1) && list.get(i) > max) {\n max = list.get(i);\n maxIdx = i;\n }\n }\n if (maxIdx == -1) break;\n List newList = new ArrayList<>();\n for (int i = 0; i < list.size(); i++) {\n if (i != maxIdx) {\n newList.add(list.get(i));\n }\n }\n list = newList;\n }\n out.println(a.length - list.size());\n out.flush();\n out.close();\n }\n\n static class Scanner\n {\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(InputStream system) {br = new BufferedReader(new InputStreamReader(system));}\n public Scanner(String file) throws Exception {br = new BufferedReader(new FileReader(file));}\n public String next() throws IOException\n {\n while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n public String nextLine()throws IOException{return br.readLine();}\n public int nextInt() throws IOException {return Integer.parseInt(next());}\n public double nextDouble() throws IOException {return Double.parseDouble(next());}\n public char nextChar()throws IOException{return next().charAt(0);}\n public Long nextLong()throws IOException{return Long.parseLong(next());}\n public boolean ready() throws IOException{return br.ready();}\n public void waitForInput() throws InterruptedException {Thread.sleep(3000);}\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "greedy", "strings", "constructive algorithms"], "code_uid": "6322ebb0db9b4718b97c3b5378e8975c", "src_uid": "9ce37bc2d361f5bb8a0568fb479b8a38", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java .util.Scanner ;\nimport java.util.*;\nimport java.math.BigInteger;\nimport java.nio.IntBuffer;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\n//import java.io.OutputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.lang.Math;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.InputMismatchException;\n\n\npublic class cf2{\n public static void main(final String[] args) throws IOException { \n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter w = new PrintWriter(outputStream);\n\n int n =in.nextInt();\n if(n>=0){\n System.out.println(n);\n }\n else {\n int lastd=n%10;\n if(lastd==0){\n String str =Integer.toString(n);\n int m=str.length();\n str=str.substring(0, m-2)+str.substring(m-1);\n int a=Integer.parseInt(str);\n System.out.println(a);\n }\n else {\n String str=Integer.toString(n);\n int m=str.length();\n String x=str.substring(m-2,m-1);\n int g=Integer.parseInt(x);\n String y=str.substring(m-1);\n int h=Integer.parseInt(y);\n\n if(g= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (final IOException e) {\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 String str = \"\";\n try {\n str = br.readLine();\n } catch (final IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n\n public int nextInt() {\n int c = read();\n\n while (isSpaceChar(c))\n c = read();\n\n int sgn = 1;\n\n if (c == '-') {\n sgn = -1;\n c = read();\n }\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\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\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 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\n public String readString() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n final StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n\n return res.toString();\n }\n\n public boolean isSpaceChar(final 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", "lang_cluster": "Java", "tags": ["implementation", "number theory"], "code_uid": "84d8d106bda73d4b143cf7456cbb407c", "src_uid": "4b0a8798a6d53351226d4f06e3356b1e", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "//package yahia;\nimport java.util.*;\npublic class lm {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();ArrayListx=new ArrayList<>();for (int i=0;ix2=new ArrayList<>();\n\t\tif (n==1) {System.out.println(0);return;}\n\t\tif (x.size()==2) {if((x.get(1)-x.get(0))%2==0)System.out.println((x.get(1)-x.get(0))/2);else System.out.println((x.get(1)-x.get(0)));return;}\n\t\tboolean f=true;\n\t\tSet x1 = new HashSet<>(x);\n\t\tx.clear();\n\t\tx.addAll(x1);\n\t\t//System.out.println(x1);\n\t\tfor (int i:x1) {\n\t\t\tx2.add(i);\n\t\t}\n\t\tCollections.sort(x2);\n\t\tif (x1.size()==1) {System.out.println(0);return;}\n\t\tif (x1.size()>3) {System.out.println(-1);return;}\n\t\tif (x1.size()==2) {if((x2.get(1)-x2.get(0))%2==0)System.out.println((x2.get(1)-x2.get(0))/2);else System.out.println((x2.get(1)-x2.get(0)));return;}\n\t\tif (x2.get(1)-x2.get(0)==x2.get(2)-x2.get(1))System.out.println(x2.get(2)-x2.get(1));else System.out.println(-1);\n\t}\n}", "lang_cluster": "Java", "tags": ["math"], "code_uid": "fd9d203ef701cd330ab65a0ac5b34709", "src_uid": "d486a88939c132848a7efdf257b9b066", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.*;\n\n\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tScanner kb = new Scanner(System.in);\n\t\tint a1 = kb.nextInt();\n\t\tint b1 = kb.nextInt();\n\t\tint c1 = kb.nextInt();\n\t\tint a2 = kb.nextInt();\n\t\tint b2 = kb.nextInt();\n\t\tint c2 = kb.nextInt();\n\t\tint D = a1*b2-a2*b1;\n\t\tif((a1==0&&b1==0&&c1!=0)||(a2==0&&b2==0&&c2!=0))System.out.println(0);\n\t\telse if((a1==0&&b1==0&&c1==0)||(a2==0&&b2==0&&c2==0))System.out.println(-1);\n\t\telse if(D!=0)System.out.println(1);\n\t\telse if(a1*c2==a2*c1&&b1*c2==b2*c1)System.out.println(-1);\n\t\telse System.out.println(0);\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "08e2395dbf0531fc0621c00790e91eaf", "src_uid": "c8e869cb17550e888733551c749f2e1a", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "//Author-Vishal Burman\n\nimport java.io.*;\nimport java.util.*;\npublic class testClass_codeforces{\n public static void main(String[] args) throws IOException {\n Reader sc = new Reader();\n PrintWriter out = new PrintWriter(System.out, true);\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n ArrayList list=new ArrayList<>();\n int flag=0;\n String str0=\"WBWBWBWB\";\n String str1=\"BWBWBWBW\";\n for(int i=0;i<8;i++){\n String str=br.readLine();\n if(i%2==0){\n if(str.equals(str0))\n flag=0;\n else{\n if(alternate(str))\n flag=0;\n else{\n flag=1;\n break;\n }\n }\n }\n else{\n if(str.equals(str1))\n flag=0;\n else{\n if(alternate(str))\n flag=0;\n else{\n flag=1;\n break;\n }\n }\n }\n }\n if(flag==0)\n out.println(\"YES\");\n else\n out.println(\"NO\");\n out.flush();\n }\n public static boolean alternate(String x){\n int flag=0;\n char let1=x.charAt(0);\n for(int i=1;i= '0' && c <= '9');\n\n if (neg)\n return -ret;\n return ret;\n }\n\n public long nextLong() throws IOException {\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 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 if (neg)\n 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)\n buffer[0] = -1;\n }\n\n private byte read() throws IOException {\n if (bufferPointer == bytesRead)\n fillBuffer();\n return buffer[bufferPointer++];\n }\n\n public void close() throws IOException {\n if (din == null)\n return;\n din.close();\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "strings"], "code_uid": "d058363f7b8ce97368b228495666687b", "src_uid": "ca65e023be092b2ce25599f52acc1a67", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Mohsen{\n public static void main(String[] args){\n Scanner console = new Scanner(System.in);\n long n = console.nextLong(), m=console.nextLong(), a=console.nextLong(), b=console.nextLong();\n System.out.println(Math.min((n % m)*b, (m - (n % m))*a));\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "bcd6ff29c291291b293ec71e89effe04", "src_uid": "c05d753b35545176ad468b99ff13aa39", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.StringTokenizer;\n\n/**\n * Created by peacefrog on 11/9/15.\n * Time : 10:22 PM\n */\n\npublic class TavasAndSaDDas299B {\n\tfinal boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tPrintWriter out;\n\tlong timeBegin, timeEnd;\n\n\tpublic void runIO() throws IOException {\n\t\ttimeBegin = System.currentTimeMillis();\n\n\t\tInputStream inputStream;\n\t\tOutputStream outputStream;\n\n\n\t\tif (ONLINE_JUDGE) {\n\t\t\tinputStream = System.in;\n\t\t\tReader.init(inputStream);\n\t\t\toutputStream = System.out;\n\n\t\t\tout = new PrintWriter(outputStream);\n\n\t\t} else {\n\t\t\tinputStream = new FileInputStream(\"/home/peacefrog/Dropbox/IdeaProjects/Problem Solving/input\");\n\t\t\tReader.init(inputStream);\n\t\t\tout = new PrintWriter(\"output.txt\");\n\t\t}\n\n\t\tsolve();\n\n\t\tout.flush();\n\t\tout.close();\n\t\ttimeEnd = System.currentTimeMillis();\n\n\t\tSystem.err.println(\"Time = \" + (timeEnd - timeBegin));\n\n\t}\n\n\t/*\n\t * Start Solution Here\n\t */\n\n\tprivate void solve() throws IOException {\n\t\tlong n = Reader.nextLong(); //This Variable default in Code Templete\n\t\tArrayList lucky = new ArrayList<>();\n\n\t\tArrayList temp = new ArrayList<>();\n\n\t\ttemp.add(4L);\n\t\ttemp.add(7L);\n\n\t\twhile (!temp.isEmpty())\n\t\t{\n\t\t\tlong top = temp.remove(0);\n\t\t\tif (top <= 1E9)\n\t\t\t{\n\t\t\t\tlucky.add(top);\n\t\t\t\ttemp.add(top*10+4);\n\t\t\t\ttemp.add(top*10+7);\n\t\t\t}\n\t\t}\n\n\t\tCollections.sort(lucky);\n\t\tSystem.out.println(lucky.indexOf(n)+1);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tnew TavasAndSaDDas299B().runIO();\n\t}\n\n\tstatic class Reader {\n\t\tstatic BufferedReader reader;\n\t\tstatic StringTokenizer tokenizer;\n\n\t\t/**\n\t\t * call this method to initialize reader for InputStream\n\t\t */\n\t\tstatic void init(InputStream input) {\n\t\t\treader = new BufferedReader(new InputStreamReader(input));\n\t\t\ttokenizer = new StringTokenizer(\"\");\n\t\t}\n\n\t\t/**\n\t\t * get next word\n\t\t */\n\t\tstatic 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\tstatic String nextLine() {\n\t\t\ttry {\n\t\t\t\treturn reader.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn \"\";\n\t\t}\n\n\t\tstatic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tstatic long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tstatic double nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t}\n\n}\n\n", "lang_cluster": "Java", "tags": ["brute force", "implementation", "combinatorics", "bitmasks"], "code_uid": "4dcc57e78d6fced03fa52b92068e1e89", "src_uid": "6a10bfe8b3da9c11167e136b3c6fb2a3", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class VityaInTheCountryside {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n int daysObservedCount = Integer.parseInt(scanner.nextLine().split(\"\\\\r?\\\\n\")[0]);\n String[] observedCycleStringArray = scanner.nextLine().split(\" \");\n\n\n if (observedCycleStringArray[daysObservedCount - 1].equals(\"0\")) {\n System.out.println(\"UP\");\n return;\n }\n\n if (observedCycleStringArray[daysObservedCount - 1].equals(\"15\")) {\n System.out.println(\"DOWN\");\n return;\n }\n\n if (daysObservedCount <= 1) {\n System.out.println(\"-1\");\n return;\n }\n\n int lastMoonCycle = Integer.parseInt(observedCycleStringArray[daysObservedCount - 1]);\n int cycleBeforeLastMoonCycle = Integer.parseInt(observedCycleStringArray[daysObservedCount - 2]);\n\n String output = lastMoonCycle > cycleBeforeLastMoonCycle ? \"UP\" : \"DOWN\";\n System.out.println(output);\n }\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "3fb6c77ef7cab84f968de88494fbf50f", "src_uid": "8330d9fea8d50a79741507b878da0a75", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.PrintWriter;\nimport java.util.Scanner;\n\n/**\n * Created by Timur on 10.11.2016.\n */\npublic class _610A {\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 if(n%2==1)\n out.print(0);\n else\n out.print((n+2)/4 - 1);\n\n out.close();\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "combinatorics"], "code_uid": "3fe55871a2382244837044d6593dd28c", "src_uid": "32b59d23f71800bc29da74a3fe2e2b37", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class HangDepTroai {\n public static void main(String[] args){\n Scanner input = new Scanner(System.in);\n int a = input.nextInt();\n int b = input.nextInt();\n int c = input.nextInt();\n int d=0;\n if(a<=0 || c>=11){\n System.out.println(\"Error\");\n }\n else if(b>a && b>c && ( a==1 && c==1)){\n d = b+a+c;\n System.out.println(d); \n } \n else if(c==1 && b>a){\n d = a*(b+c);\n System.out.println(d);\n }\n else if(c>a && c>b && ( a==1 && b==1)){\n d = c*(a+b);\n System.out.println(d);\n }\n else if(a==1 && b>c){\n d = c*(a+b);\n System.out.println(d);\n } \n else if(a>1 && a==c && b==1){\n d = c*(a+b);\n System.out.println(d);\n }\n else if(a>b && a>c &&( b==1|| c==1)){\n d = a*(b+c);\n System.out.println(d);\n }\n else if(a>b && a>c && ( b>1 || c>1 )){\n d = a*b*c;\n System.out.println(d);\n }\n else if(b>a && b>c && ( a==1 || c==1)){\n d = b*(a+c);\n System.out.println(d); \n }\n else if(b>a && b>c && ( a>1 || c>1)){\n d = a*b*c;\n System.out.println(d);\n }\n else if(c>a && c>b && ( a==1 || b==1)){\n d = c*(a+b);\n System.out.println(d);\n }\n else if(c>a && c>b && ( a>1 || b>1 )){\n d = a*b*c;\n System.out.println(d);\n }\n else if(a==1 && b==1 && c==1){\n d = a+b+c;\n System.out.println(d);\n }\n else if(a==b && b==c && c==a){\n d = a*b*c;\n System.out.println(d);\n }\n else if(c==1 && b>a){\n d = a*(b+c);\n System.out.println(d);\n }\n }\n}\n\n\n ", "lang_cluster": "Java", "tags": ["brute force", "math"], "code_uid": "03bef186657fd0e674e1c31fca956cfd", "src_uid": "1cad9e4797ca2d80a12276b5a790ef27", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\npublic class TheGreatJuliaCalendarEZ {\n\tpublic static void main(String[] args) { \n\t\tFastScanner I = new FastScanner(); //Input\n\t\tOutPut O = new OutPut(); //Output\n\t\tint N = I.nextInt();\n\t\tlong[] dp = new long[N+1];\n\t\tfor (int i = 1; i<= N; i++) {\n\t\t\tint cur = i;\n\t\t\tdp[i]=(int)(1e7);\n\t\t\twhile (cur>0) {\n\t\t\t\tint dig = cur%10;\n\t\t\t\tdp[i]=min(dp[i],dp[i-dig]+1);\n\t\t\t\tcur/=10;\n\t\t\t}\n\t\t}\n\t\tO.pln(dp[N]);\n//O.pln(ans);\n\t}\n\tpublic static long min(long a, long b) {return Math.min(a,b);}\n\tpublic static long max(long a, long b) {return Math.max(a,b);}\n\tpublic static long abs(long x, long y) {return Math.abs(x-y);}\n\tpublic static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) \n\tans++; return ans;}\n\tpublic static long GCD(long a, long b) {\n\t\tif (a==0||b==0) return max(a,b);\n\t\treturn GCD(max(a,b),max(a,b)%min(a,b));\n\t}\n\tpublic static long FastExp(long base, long exp, long mod) {\n\t\tlong ans=1;\n\t\twhile (exp>0) {\n\t\t\tif (exp%2==1) ans*=base;\n\t\t\texp/=2;\n\t\t\tbase*=base;\n\t\t\tbase%=mod;\n\t\t\tans%=mod;\n\t\t}\n\t\treturn ans;\n\t}\n\tpublic static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}\n\tpublic static int pop(long x) { //Returns number of bits within a number\n\t\tint cnt = 0;\n\t\twhile (x>0) {\n\t\t\tif (x%2==1) cnt++;\n\t\t\tx/=2;\n\t\t}\n\t\treturn cnt;\n\t}\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\tint nextInt() {return Integer.parseInt(next());}\n\t\tlong nextLong() {return Long.parseLong(next());};\n\t\tdouble nextDouble() {return Double.parseDouble(next());}\n\t}\n\tstatic class OutPut{\n\t\tPrintWriter w = new PrintWriter(System.out);\n\t\tvoid pln(double x) {w.println(x);w.flush();}\n\t\tvoid pln(boolean x) {w.println(x);w.flush();}\n\t\tvoid pln(int x) {w.println(x);w.flush();}\n\t\tvoid pln(long x) {w.println(x);w.flush();}\n\t\tvoid pln(String x) {w.println(x);w.flush();}\n\t\tvoid pln(char x) {w.println(x);w.flush();}\n\t\tvoid pln(StringBuilder x) {w.println(x);w.flush();}\n\t\tvoid pln(BigInteger x) {w.println(x);w.flush();}\n\t\tvoid p(int x) {w.print(x);w.flush();}\n\t\tvoid p(long x) {w.print(x);w.flush();}\n\t\tvoid p(String x) {w.print(x);w.flush();}\n\t\tvoid p(char x) {w.print(x);w.flush();}\n\t\tvoid p(StringBuilder x) {w.print(x);w.flush();}\n\t\tvoid p(BigInteger x) {w.print(x);w.flush();}\n\t\tvoid p(double x) {w.print(x);w.flush();}\n\t\tvoid p(boolean x) {w.print(x);w.flush();}\n\t}\n}\n\n", "lang_cluster": "Java", "tags": ["dp"], "code_uid": "66b1a25002ccce3171dee5296af685ad", "src_uid": "fc5765b9bd18dc7555fa76e91530c036", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main\n{\n\tpublic static BufferedReader reader;\n\tpublic static StringTokenizer in;\n\tpublic static PrintWriter out;\n\tpublic static final double EPS = 1e-9;\n\t\n\tpublic static void main(String[] args) throws IOException \n\t{\n\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\tin = new StringTokenizer(\"\");\n\t\tout = new PrintWriter(System.out);\n\n\t\tint n = nextInt(), R = nextInt(), r = nextInt();\n\t\t\n\t\tif(n == 1)\n\t\t\tout.print(r > R ? \"NO\" : \"YES\");\n\t\telse\n\t\t{\n\t\t\tdouble a = (R - r) * Math.sin(Math.PI / n);\n\t\t\tout.print(r - EPS > a ? \"NO\" : \"YES\");\n\t\t}\n\t\tout.close();\n\t}\n\n\tpublic static void get() throws IOException\n\t{\n\t\twhile(!in.hasMoreTokens()) in = new StringTokenizer(reader.readLine());\n\t}\n\t\n\tpublic static int nextInt() throws IOException\n\t{\n\t\tget();\n\t\treturn Integer.parseInt(in.nextToken());\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "geometry"], "code_uid": "dd6076bb4b86e136adc4c93e76a48ab2", "src_uid": "2fedbfccd893cde8f2fab2b5bf6fb6f6", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Main\n{\n static int MOD = 1000000007;\n static int dfac[],fac[],inv[];\n \n public static void generateInv(int maxn)\n {\n inv = new int[maxn+1];\n inv[1] = 1;\n for (int i = 2;i <= maxn;++i)\n inv[i] = (int)((long) inv[MOD%i] * (MOD - MOD/i) % MOD); \n }\n \n public static int A(int n,int r)\n {\n return (int)((long)fac[n] * dfac[n-r] % MOD);\n }\n \n public static int quickPow(int x,int n)\n {\n long ans = 1;\n for (;n != 0;n >>= 1)\n {\n if ((n & 1) != 0) ans = ans * x % MOD;\n x = (int)((long) x * x % MOD);\n }\n return (int)ans;\n }\n \n public static int eat(int len,int k,int w)\n {\n long ret = A(k,len);\n int delta = len - (w - 1);\n if (delta >= 0)\n {\n ret = ret * A(k-delta,len-delta) % MOD;\n }\n else\n {\n ret = ret * A(k,len) % MOD;\n ret = ret * quickPow(k,w-1-len) % MOD;\n }\n return (int)ret;\n }\n \n public static int fuck(int k,int w,boolean inclusive)\n {\n long ret = 0;\n for (int i = inclusive ? 1 : 2;i <= k;++i)\n ret = (ret + eat(i,k,w)) % MOD;\n return (int)ret;\n }\n \n public static int gao(int k,int w)\n {\n fac = new int[k+1];\n dfac = new int[k+1];\n fac[0] = 1;\n for (int i = 1;i <= k;++i)\n fac[i] = (int)((long)fac[i-1] * i % MOD);\n generateInv(k);\n dfac[0] = 1;\n for (int i = 1;i <= k;++i)\n dfac[i] = (int)((long)dfac[i-1] * inv[i] % MOD);\n return ( (fuck(k,w+1,true) - fuck(k,w,false) ) % MOD + MOD) % MOD;\n }\n \n public static void main(String args[])\n {\n Scanner cin = new Scanner(System.in);\n int k = cin.nextInt(), w = cin.nextInt();\n System.out.println(gao(k,w));\n }\n}", "lang_cluster": "Java", "tags": ["combinatorics"], "code_uid": "5b89496e07fd80a0fe11c67f873fe2a0", "src_uid": "b715f0fdc83ec539eb3ae2b0371ee130", "difficulty": 3000.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.Random;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n\tstatic int MOD = 1000 * 1000 * 1000 + 7;\n\n\tpublic static void shuffleArray(int[] arr) {\n\t\tint n = arr.length;\n\t\tRandom rnd = new Random();\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tint tmp = arr[i];\n\t\t\tint randomPos = i + rnd.nextInt(n - i);\n\t\t\tarr[i] = arr[randomPos];\n\t\t\tarr[randomPos] = tmp;\n\t\t}\n\t}\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\tsolve3(in, out);\n\t\tout.close();\n\t\tSystem.exit(0);\n\t}\n\n\tstatic class Pair implements Comparable {\n\t\tint x;\n\t\tint y;\n\n\t\tPair(int x, int y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Pair o) {\n\t\t\tint comp = Integer.compare(x, o.x);\n\t\t\tint comp2 = Integer.compare(y, o.y);\n\t\t\tif (comp != 0) {\n\t\t\t\treturn comp;\n\t\t\t} else {\n\t\t\t\treturn comp2;\n\t\t\t}\n\t\t}\n\n\t}\n\n\tprivate static void solve3(InputReader in, PrintWriter out) {\n\t\tint a = in.nextInt();\n\t\tint b = in.nextInt();\n\t\tint[][] dp = new int[201][201];\n\t\tfor (int sum = 2; sum <= 200; sum++) {\n\t\t\tfor (int i = 1; i <= sum; i++) {\n\t\t\t\tint j = sum - i;\n\n\t\t\t\tif (i - 2 >= 0 && j > 0) {\n\t\t\t\t\tdp[i][j] = Math.max(dp[i][j], dp[i - 2][j + 1] + 1);\n\t\t\t\t}\n\t\t\t\tif (j - 2 >= 0 && i > 0) {\n\t\t\t\t\tdp[i][j] = Math.max(dp[i][j], dp[i + 1][j - 2] + 1);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tout.print(dp[a][b]);\n\t}\n\n\tprivate static void solve2(InputReader in, PrintWriter out) {\n\t\tint n = in.nextInt();\n\t\tint[] tab = new int[1002];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint curr = in.nextInt();\n\t\t\ttab[curr]++;\n\t\t}\n\t\tint res = 0;\n\t\tint all = 0;\n\t\tfor (int i = 1000; i >= 1; i--) {\n\t\t\tres += Math.min(tab[i], all);\n\t\t\tall += tab[i];\n\t\t}\n\n\t\tout.print(res);\n\t}\n\n\tprivate static void solve(InputReader in, PrintWriter out) {\n\n\t\tint n = in.nextInt();\n\t\tlong a = in.nextInt();\n\t\tlong b = in.nextInt();\n\t\tlong T = in.nextLong();\n\t\tchar[] s = in.next().toCharArray();\n\t\tlong[] right = new long[n];\n\t\tlong[] left = new long[n];\n\t\tright[0] = 1 + (s[0] == 'w' ? b : 0);\n\t\tleft[0] = 0;\n\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tlong changeCost = (s[i] == 'w' ? b : 0);\n\t\t\tright[i] = right[i - 1] + a + changeCost + 1;\n\t\t}\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tint pos = n - i;\n\t\t\tlong changeCost = (s[pos] == 'w' ? b : 0);\n\t\t\tleft[pos] = left[(pos + 1) % n] + a + changeCost + 1;\n\t\t}\n\n\t\tlong best = 0;\n\t\tint bestL = n - 1;\n\t\tfor (int i = n - 1; i >= 0; i--) { // right\n\t\t\tlong time = right[i];\n\t\t\tif (time <= T) {\n\t\t\t\tbest = Math.max(best, i + 1);\n\t\t\t\tlong rem = T - time;\n\t\t\t\trem -= a * i; // back time\n\t\t\t\twhile (bestL > i && rem >= left[bestL]) {\n\t\t\t\t\tbest = Math.max(best, i + 1 + (n - bestL));\n\t\t\t\t\tbestL--;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tchar[] tmp = new char[s.length];\n\t\ttmp[0] = s[0];\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\ttmp[i] = s[n - i];\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ts[i] = tmp[i];\n\t\t}\n\n\t\t// **** left\n\t\tright = new long[n];\n\t\tleft = new long[n];\n\t\tright[0] = 1 + (s[0] == 'w' ? b : 0);\n\t\tleft[0] = 0;\n\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tlong changeCost = (s[i] == 'w' ? b : 0);\n\t\t\tright[i] = right[i - 1] + a + changeCost + 1;\n\t\t}\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tint pos = n - i;\n\t\t\tlong changeCost = (s[pos] == 'w' ? b : 0);\n\t\t\tleft[pos] = left[(pos + 1) % n] + a + changeCost + 1;\n\t\t}\n\n\t\tbestL = n - 1;\n\t\tfor (int i = n - 1; i >= 0; i--) { // right\n\t\t\tlong time = right[i];\n\t\t\tif (time <= T) {\n\t\t\t\tbest = Math.max(best, i + 1);\n\t\t\t\tlong rem = T - time;\n\t\t\t\trem -= a * i; // back time\n\t\t\t\twhile (bestL > i && rem >= left[bestL]) {\n\t\t\t\t\tbest = Math.max(best, i + 1 + (n - bestL));\n\t\t\t\t\tbestL--;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.print(best);\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\n}", "lang_cluster": "Java", "tags": ["math", "greedy", "dp", "implementation"], "code_uid": "34389e3c9fcdbe5eb4186f4a9e7fe9b3", "src_uid": "ba0f9f5f0ad4786b9274c829be587961", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.Arrays;\n\nimport java.util.StringTokenizer;\n\n\npublic class Codeforces {\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 solve = new TaskA();\n solve.solve(1, in, out);\n out.close();\n }\n static class TaskA {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int m = in.nextInt();\n \n int arr[] = new int[m];\n \n \n for(int i = 0; i < m; ++i) {\n arr[i] = in.nextInt();\n }\n \n Arrays.sort(arr);\n \n int minimum = Integer.MAX_VALUE;\n \n if(m > n) {\n n--;\n for(int i = 0; i < m - n; ++i) {\n minimum = Math.min(minimum, arr[i + n] - arr[i]);\n }\n } else if(m==n) {\n minimum = Math.min(minimum, arr[n-1] - arr[0]);\n } else {\n for(int j = 0; j < n-1; ++j) {\n minimum = Math.min(minimum, arr[j + n-1] - arr[j]);\n }\n }\n \n \n \n out.println(minimum);\n \n }\n \n private static String reverse(String word) {\n String out = \"\";\n for(int i = word.length() -1; i >= 0; i--) {\n out += word.charAt(i);\n }\n return out;\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 double nextDouble() {\n return Double.parseDouble(next());\n }\n \n }\n}", "lang_cluster": "Java", "tags": ["greedy"], "code_uid": "7b85dda143faaff1d617d80a59ab905c", "src_uid": "7830aabb0663e645d54004063746e47f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.time.LocalDate;\nimport java.time.YearMonth;\nimport java.time.format.DateTimeFormatter;\nimport java.time.temporal.ChronoUnit;\nimport java.util.*;\n\npublic class Main {\n static boolean local = false;\n static FReader sc;\n static PrintWriter pw;\n\n public static void main(String args[]) throws FileNotFoundException {\n if (args.length != 0) {\n local = true;\n sc = new FReader(\"/Users/qjex/prj/jolymp/src/input.txt\");\n try {\n pw = new PrintWriter(new FileOutputStream(\"/Users/qjex/prj/jolymp/src/output.txt\"), false);\n } catch (Exception e) {\n e.printStackTrace();\n }\n } else {\n sc = new FReader(System.in);\n pw = new PrintWriter(System.out);\n }\n solve();\n pw.close();\n sc.close();\n }\n\n public static void solve() {\n String a = sc.next(), b = sc.next();\n DateTimeFormatter formatter = DateTimeFormatter.ofPattern(\"yyyy:MM:dd\");\n LocalDate l = LocalDate.parse(a, formatter);\n LocalDate r = LocalDate.parse(b, formatter);\n pw.println(Math.abs(ChronoUnit.DAYS.between(l, r)));\n\n }\n\n}\n\nclass FReader {\n BufferedReader br;\n StringTokenizer st;\n\n FReader(String file) {\n try {\n br = new BufferedReader(new FileReader(file));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n st = new StringTokenizer(\"\");\n }\n\n\n FReader(InputStream is) {\n br = new BufferedReader(new InputStreamReader(is));\n st = new StringTokenizer(\"\");\n }\n\n String next() {\n try {\n while (!st.hasMoreElements()) {\n st = new StringTokenizer(br.readLine());\n }\n } catch (Exception e) {\n e.printStackTrace();\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 BigInteger nextBigInteger(){ return new BigInteger(next()); }\n\n public void close() {\n try {\n br.close();\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n}\n\nclass Pair implements Comparable {\n\n public int first;\n public int second;\n\n public Pair(int first, int second) {\n this.first = first;\n this.second = second;\n }\n\n @Override\n public int compareTo(Pair pairInt) {\n if (first > pairInt.first) return 1;\n if (first < pairInt.first) return -1;\n if (second > pairInt.second) return 1;\n return second == pairInt.second ? 0 : -1;\n }\n\n @Override\n public boolean equals(Object obj) {\n return obj instanceof Pair && compareTo((Pair) obj) == 0;\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "a942ec3c9338efec65b21b5a0c957f8b", "src_uid": "bdf99d78dc291758fa09ec133fff1e9c", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "//I have given up the treatment-_-||\nimport java.util.*;\nimport java.math.*;\npublic class a{\n\tpublic static int pp[][] = new int[10][3];\n\tpublic static int mat[][] = new int[5][5];\n\tpublic static int n;\n\tpublic static void main(String[] args){\n\t\tn=3;\n\t\tScanner cin = new Scanner(System.in);\n\t\twhile(cin.hasNext()){\n\t\t\tfor(int i=1;i<=n;i++){\n\t\t\t\tpp[i][1]=cin.nextInt();\n\t\t\t\tpp[i][2]=cin.nextInt();\n\t\t\t}\n\t\t\tgetmat();\n\t\t\tint ans=5;\n\t\t\tif(pp[1][1]==pp[2][1]&&pp[2][1]==pp[3][1]){\n\t\t\t\tans=1;\n\t\t\t}\n\t\t\tif(pp[1][2]==pp[2][2]&&pp[2][2]==pp[3][2]){\n\t\t\t\tans=1;\n\t\t\t}\n\t\t\tif(ans==1){\n\t\t\t\tSystem.out.println(ans);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tans=3;\n\t\t\tfor(int i=1;i<=3&&ans>2;i++){\n\t\t\t\tfor(int j=1;j<=3&&ans>2;j++){\n\t\t\t\t\tif(i==j) continue;\n\t\t\t\t\tfor(int k=1;k<=3&&ans>2;k++){\n\t\t\t\t\t\tif(k==i||k==j) continue;\n\t\t\t\t\t\tif(gao(i,j,k)){\n\t\t\t\t\t\t\tans=2;\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\tSystem.out.println(ans);\n\t\t}\n\t\tcin.close();\n\t}\n\tpublic static void getmat(){\n\t\tfor(int i=1;i<=n;i++){\n\t\t\tmat[i][i]=0;\n\t\t\tfor(int j=i+1;j<=n;j++){\n\t\t\t\tint step=getstep(i,j);\n\t\t\t\tmat[i][j]=mat[j][i]=step;\n\t\t\t}\n\t\t}\n\t\treturn;\n\t}\n\tpublic static int getstep(int x,int y){\n\t\tint ret=0;\n\t\tif(pp[x][1]!=pp[y][1]) ret++;\n\t\tif(pp[x][2]!=pp[y][2]) ret++;\n\t\treturn ret;\n\t}\n\tpublic static boolean gao(int x,int y,int z){\n\t\tif(pp[x][1]>=pp[y][1]&&pp[x][1]>=pp[z][1]&&pp[y][2]==pp[z][2]){\n\t\t\treturn true;\n\t\t}\n\t\tif(pp[x][1]<=pp[y][1]&&pp[x][1]<=pp[z][1]&&pp[y][2]==pp[z][2]){\n\t\t\treturn true;\n\t\t}\n\t\tif(pp[x][2]>=pp[y][2]&&pp[x][2]>=pp[z][2]&&pp[y][1]==pp[z][1]){\n\t\t\treturn true;\n\t\t}\n\t\tif(pp[x][2]<=pp[y][2]&&pp[x][2]<=pp[z][2]&&pp[y][1]==pp[z][1]){\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n}", "lang_cluster": "Java", "tags": ["constructive algorithms", "implementation"], "code_uid": "d890c8474ee3550a65e5f6dada1d33f0", "src_uid": "36fe960550e59b046202b5811343590d", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.util.stream.*;\n\n@SuppressWarnings(\"unchecked\")\npublic class P910B {\n\n int n;\n TreeMap m;\n\n void use(int l) {\n Integer pl = m.ceilingKey(l);\n\n int c = m.get(pl) - 1;\n if (c > 0) {\n m.put(pl, c);\n } else {\n m.remove(pl);\n }\n\n if (pl != l) {\n m.put(pl - l, m.getOrDefault(pl - l, 0) + 1);\n }\n }\n\n public void run() throws Exception {\n n = nextInt();\n int a = nextInt(), b = nextInt(), k = Integer.MAX_VALUE;\n \n for (int mm = (1 << 6) - 1; mm > 0; mm--) {\n if (Integer.bitCount(mm) != 2) { continue; }\n\n m = new TreeMap();\n m.put(n, 6);\n for (int mi = 1 << 5; mi > 0; mi >>= 1) {\n if ((mm & mi) == 0) {\n use(a);\n } else {\n use(b);\n }\n }\n\n k = Math.min(k, 6 - m.getOrDefault(n, 0));\n }\n\n println(k);\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 P910B().run();\n br.close();\n pw.close();\n System.err.println(\"\\n[Time : \" + (System.currentTimeMillis() - startTime) + \" ms]\");\n }\n\n static long startTime = System.currentTimeMillis();\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\n int gcd(int a, int b) {\n if (a == 0) return Math.abs(b); if (b == 0) return Math.abs(a);\n a = Math.abs(a); b = Math.abs(b);\n int az = Integer.numberOfTrailingZeros(a), bz = Integer.numberOfTrailingZeros(b);\n a >>>= az; b >>>= bz;\n while (a != b) {\n if (a > b) { a -= b; a >>>= Integer.numberOfTrailingZeros(a); }\n else { b -= a; b >>>= Integer.numberOfTrailingZeros(b); }\n }\n return (a << Math.min(az, bz));\n }\n\n long gcd(long a, long b) {\n if (a == 0) return Math.abs(b); if (b == 0) return Math.abs(a);\n a = Math.abs(a); b = Math.abs(b);\n int az = Long.numberOfTrailingZeros(a), bz = Long.numberOfTrailingZeros(b);\n a >>>= az; b >>>= bz;\n while (a != b) {\n if (a > b) { a -= b; a >>>= Long.numberOfTrailingZeros(a); }\n else { b -= a; b >>>= Long.numberOfTrailingZeros(b); }\n }\n return (a << Math.min(az, bz));\n }\n}", "lang_cluster": "Java", "tags": ["greedy", "implementation"], "code_uid": "ea35a4437607f70cd48efecb2b60c485", "src_uid": "1a50fe39e18f86adac790093e195979a", "difficulty": 1600.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 Main {\n \n public static String Sleep(int hh,int mm,int hh2 ,int mm2){\n int hhout,mmout;\n \n \n if(hhhh2&&mmtt)\n\t\t\t\t{\n\t\t\t\t\tif(me!=n)\n\t\t\t\t\t{\n\t\t\t\t\t\tme++;\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((me-1)!=tt)\n\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}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif(me!=1)\n\t\t\t\t\t{\n\t\t\t\t\t\tme--;\n\t\t\t\t\t}\n\t\t\t\t\telse\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}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif((ttmove==1)&&(tt!=1))\n\t\t\t\t{\n\t\t\t\t\tme=tt-1;\n\t\t\t\t}\n\t\t\t\telse if((ttmove==1)&&(tt==1))\n\t\t\t\t{\n\t\t\t\t\tme=1;\n\t\t\t\t}\n\t\t\t\telse if((ttmove==-1)&&(tt!=n))\n\t\t\t\t{\n\t\t\t\t\tme=tt+1;\n\t\t\t\t}\n\t\t\t\telse if((ttmove==-1)&&(tt==n))\n\t\t\t\t{\n\t\t\t\t\tme=n;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tme+=ttmove;\n\t\t\t\t}\n\t\t\t}\n\t\t\tc++;\n\t\t\ttt+=ttmove;\n\t\t\tif(tt==n)\n\t\t\t{\n\t\t\t\tttmove=-1;\n\t\t\t}\n\t\t\telse if(tt==1)\n\t\t\t{\n\t\t\t\tttmove=1;\n\t\t\t}\n\t\t}\n\t\tif(c==Schedule.length())\n\t\t{\n\t\t\tSystem.out.println(\"Stowaway\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\tSystem.out.println(\"Controller \"+c);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "tags": ["greedy", "dp", "games"], "code_uid": "9e7820109a696c3d2f09bfe313122fd4", "src_uid": "2222ce16926fdc697384add731819f75", "difficulty": 1500.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*******************************\n*/\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\n\n public class x1097D\n {\n static long MOD = 1000000007L;\n public static void main(String omkar[]) throws Exception\n {\n //BufferedReader infile = new BufferedReader(new FileReader(\"cowdate.in\"));\n BufferedReader infile = new BufferedReader(new InputStreamReader(System.in)); \n StringTokenizer st = new StringTokenizer(infile.readLine());\n long N = Long.parseLong(st.nextToken());\n int T = Integer.parseInt(st.nextToken());\n long P = 1L;\n long Q = 1L;\n long top = N;\n if(N <= 1000)\n for(long p=2; p <= top; p++)\n {\n int cnt = 0;\n if(N%p != 0)\n continue;\n while(N%p == 0)\n {\n cnt++;\n N /= p;\n }\n long[] pow = new long[cnt+1];\n pow[0] = 1L;\n for(int i=1; i <= cnt; i++)\n pow[i] = (pow[i-1]*p)%MOD;\n long[][] dp = new long[cnt+1][T+1];\n for(int i=0; i <= cnt; i++)\n dp[i][0] = pow[i];\n for(int t=1; t <= T; t++)\n {\n long sum = 0L;\n for(int i=0; i <= cnt; i++)\n {\n sum = (sum+dp[i][t-1])%MOD;\n dp[i][t] = (sum*power(i+1, MOD-2, MOD))%MOD; \n }\n }\n long num = dp[cnt][T];\n //long denom = power(cnt+1, T, MOD);\n P = (P*num)%MOD;\n //Q = (Q*denom)%MOD;\n }\n else\n {\n for(long p=2; p*p <= top; p++)\n {\n int cnt = 0;\n if(N%p != 0)\n continue;\n while(N%p == 0)\n {\n cnt++;\n N /= p;\n }\n long[] pow = new long[cnt+1];\n pow[0] = 1L;\n for(int i=1; i <= cnt; i++)\n pow[i] = (pow[i-1]*p)%MOD;\n long[][] dp = new long[cnt+1][T+1];\n for(int i=0; i <= cnt; i++)\n dp[i][0] = pow[i];\n for(int t=1; t <= T; t++)\n {\n long sum = 0L;\n for(int i=0; i <= cnt; i++)\n {\n sum = (sum+dp[i][t-1])%MOD;\n dp[i][t] = (sum*power(i+1, MOD-2, MOD))%MOD; \n }\n }\n long num = dp[cnt][T];\n //long denom = power(cnt+1, T, MOD);\n P = (P*num)%MOD;\n //Q = (Q*denom)%MOD;\n }\n if(N > 1)\n {\n int cnt = 1;\n //if(N%p != 0)\n // continue;\n //while(N%p == 0)\n //{\n // cnt++;\n // N /= p;\n //}\n long p = N;\n long[] pow = new long[cnt+1];\n pow[0] = 1L;\n for(int i=1; i <= cnt; i++)\n pow[i] = (pow[i-1]*p)%MOD;\n long[][] dp = new long[cnt+1][T+1];\n for(int i=0; i <= cnt; i++)\n dp[i][0] = pow[i];\n for(int t=1; t <= T; t++)\n {\n long sum = 0L;\n for(int i=0; i <= cnt; i++)\n {\n sum = (sum+dp[i][t-1])%MOD;\n dp[i][t] = (sum*power(i+1, MOD-2, MOD))%MOD; \n }\n }\n long num = dp[cnt][T];\n //long denom = power(cnt+1, T, MOD);\n P = (P*num)%MOD;\n\n }\n }\n long res = (P*power(Q, MOD-2, MOD))%MOD;\n System.out.println((P+MOD)%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", "probabilities", "number theory"], "code_uid": "9cf4d8f087da1bc987f7162e9295a0ba", "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;\n\npublic class Date {\n\n\t\n\n\tpublic static void main(String[] args) {\n\n\t\t\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n\t\tfinal int x;\n\t\tfinal int y;\n\t\tfinal int steps;\n\t\ttry {\n\t\t\tString first = br.readLine();\n\t\t\tString[] suh = first.split(\" \");\n\t\t\tx = Integer.parseInt(suh[0]);\n\t\t\ty = Integer.parseInt(suh[1]);\n\t\t\tsteps = Integer.parseInt(suh[2]);\n\t\t\tSolver sol = new Solver();\n\n\t\t\tsol.solve(x, y, steps);\n\n\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\n}\n\nclass Solver {\n\n\tpublic void solve(int x, int y, int stps) {\t\n\t\tint minSteps = Math.abs(x) + Math.abs(y);\n\n\t\tif ((minSteps - stps) % 2 == 0 && minSteps <= stps)\n\t\t{\n\t\t\tSystem.out.println(\"Yes\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\tSystem.out.println(\"No\");\n\t\t}\n\t\t\n\t}\n\n}", "lang_cluster": "Java", "tags": ["math"], "code_uid": "eea32ae4fa61f7dd4f4b28a94de448d0", "src_uid": "9a955ce0775018ff4e5825700c13ed36", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport 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.Arrays;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.Random;\nimport java.util.StringTokenizer;\n\npublic class C {\n\n\tstatic StringBuilder decToTer(int x) {\n\t\tStringBuilder ret = new StringBuilder();\n\t\twhile (x > 0) {\n\n\t\t\tint cur = x % 3;\n\t\t\tret.append(cur);\n\t\t\tx /= 3;\n\t\t}\n\n\t\treturn (ret.reverse());\n\t}\n\n\tstatic int terToDec(StringBuilder x) {\n\t\tint ret = 0;\n\t\tfor (int i = x.length() - 1; i >= 0; i--) {\n\t\t\tret += (Integer.parseInt(x.charAt(i) + \"\") * Math.pow(3, x.length() - i - 1));\n\t\t}\n\t\treturn ret;\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint a = sc.nextInt();\n\t\tint c = sc.nextInt();\n\t\tStringBuilder A = decToTer(a);\n\t\tStringBuilder C = decToTer(c);\n\t\twhile (A.length() < C.length())\n\t\t\tA.insert(0, \"0\");\n\t\twhile (C.length() < A.length())\n\t\t\tC.insert(0, \"0\");\n\t\tStringBuilder B = new StringBuilder();\n\t\tfor (int i = 0; i < A.length(); i++) {\n\t\t\tfor (int k = 0; k < 3; k++) {\n\t\t\t\tif ((Integer.parseInt(A.charAt(i) + \"\") + k) % 3 == (Integer.parseInt(C.charAt(i) + \"\"))) {\n\t\t\t\t\tB.append(k);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(terToDec(B));\n\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(String f) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(f));\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\treturn Double.parseDouble(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 int[] nextIntArray(int n) throws IOException {\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\treturn a;\n\t\t}\n\n\t\tpublic int[] nextIntArray1(int n) throws IOException {\n\t\t\tint[] a = new int[n + 1];\n\t\t\tfor (int i = 1; i <= n; i++)\n\t\t\t\ta[i] = nextInt();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic int[] nextIntArraySorted(int n) throws IOException {\n\t\t\tint[] a = nextIntArray(n);\n\t\t\tRandom r = new Random();\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tint j = i + r.nextInt(n - i);\n\t\t\t\tint t = a[i];\n\t\t\t\ta[i] = a[j];\n\t\t\t\ta[j] = t;\n\t\t\t}\n\t\t\tArrays.sort(a);\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic long[] nextLongArray(int n) throws IOException {\n\t\t\tlong[] a = new long[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\ta[i] = nextLong();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic long[] nextLongArray1(int n) throws IOException {\n\t\t\tlong[] a = new long[n + 1];\n\t\t\tfor (int i = 1; i <= n; i++)\n\t\t\t\ta[i] = nextLong();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic long[] nextLongArraySorted(int n) throws IOException {\n\t\t\tlong[] a = nextLongArray(n);\n\t\t\tRandom r = new Random();\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tint j = i + r.nextInt(n - i);\n\t\t\t\tlong t = a[i];\n\t\t\t\ta[i] = a[j];\n\t\t\t\ta[j] = t;\n\t\t\t}\n\t\t\tArrays.sort(a);\n\t\t\treturn a;\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "df9a76b1533980a2ffe4593ec38b6a56", "src_uid": "5fb635d52ddccf6a4d5103805da02a88", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main4 {\n static MyScanner sc;\n\n public static void main(String[] args) {\n sc = new MyScanner();\n out = new PrintWriter(new BufferedOutputStream(System.out));\n\n// unitTests();\n\n //Ciel and Flowers\n solution();\n }\n\n private static void unitTests() {\n startTest(0, 0, 0, 0);\n startTest(0, 2, 2, 0);\n startTest(0, 0, 3, 1);\n startTest(0, 3, 3, 2);\n startTest(1, 3, 3, 2);\n startTest(1, 4, 4, 3);\n startTest(1, 1, 1, 1);\n startTest(2, 2, 2, 2);\n startTest(2, 4, 4, 3);\n startTest(4, 4, 4, 4);\n startTest(14, 14, 14, 14);\n }\n\n private static void startTest(long r, long g, long b, long count) {\n long bouketsCount = solutionWithParams(r, g, b);\n if (bouketsCount != count) {\n long bouketsCount2 = solutionWithParams(r, g, b);\n }\n }\n\n private static void solution() {\n long r = sc.nextLong();\n long g = sc.nextLong();\n long b = sc.nextLong();\n\n long bouketsCount = solutionWithParams(r, g, b);\n\n out.println(bouketsCount);\n out.close();\n\n }\n\n private static long solutionWithParams(long r, long g, long b) {\n long bouketsCount = 0;\n\n long minCount = r > g ? g : r;\n minCount = minCount > b ? b : minCount;\n\n long countToCut = minCount;\n if (countToCut > 2) {\n countToCut = 2;\n }\n\n minCount -= countToCut;\n if (minCount < 0) {\n minCount = 0;\n }\n\n long threeCeil = minCount - minCount % 3;\n bouketsCount += threeCeil;\n\n r -= threeCeil;\n g -= threeCeil;\n b -= threeCeil;\n\n if (r > 2 + countToCut) {\n long rThreeCeil = (r - countToCut) / 3;\n bouketsCount += rThreeCeil;\n r -= 3 * rThreeCeil;\n }\n\n if (g > 2 + countToCut) {\n long gThreeCeil = (g - countToCut) / 3;\n bouketsCount += gThreeCeil;\n g -= 3 * gThreeCeil;\n }\n\n if (b > 2 + countToCut) {\n long bThreeCeil = (b - countToCut) / 3;\n bouketsCount += bThreeCeil;\n b -= 3 * bThreeCeil;\n }\n\n while (r > countToCut && b > countToCut && g > countToCut) {\n bouketsCount++;\n r--;\n g--;\n b--;\n }\n\n //now all values are [2..4]\n if (r + g + b >= 10) {//442\n bouketsCount += 3;\n } else if (countToCut > 1) {\n bouketsCount += 2;\n } else if (countToCut > 0 && r + g + b >= 7) {\n bouketsCount += 2;\n } else if (countToCut > 0) {\n bouketsCount += 1;\n }\n\n return bouketsCount;\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 try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n\n String nextString(int length) {\n String str = \"\";\n try {\n char[] buff = new char[length];\n br.read(buff);\n str = new String(buff);\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n\n }\n //--------------------------------------------------------\n}\n", "lang_cluster": "Java", "tags": ["math", "combinatorics"], "code_uid": "3337657952056ab89b6a3a4832e69ce4", "src_uid": "acddc9b0db312b363910a84bd4f14d8e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\npublic class fence\n{\n public static void main (String[] args) throws java.lang.Exception\n\t{\n\n Scanner sc =new Scanner(System.in);\n\tint t=0;\n\tt=sc.nextInt();\nint s=t,y=t;\n int w=0;int e=-1;\n\t\t int r=0;\n\t\t while(s>0)\n\t\t {\n\t\t r=s%10;\n\t\t w=w+r;\n\t\t s=s/10;\n\t\t }\n\t\t if(w%4==0)\n\t\t {\n\t\t System.out.println(t);\n\n\t\t }\n\t\t else\n\t\t {\n\n\t\t while(e==-1)\n\t\t {\n\n\t\t y++;\n\t\t int u=y;\n\t\t w=0;\n\t\t while(u>0)\n\t\t {\n\n\t\t w=w+u%10;\n\t\t u=u/10;\n }\n\n\t\t if(w%4==0)\n\t\t {\n\t\t System.out.println(y);\n\t\t e=0;\n\t\t break;\n\t\t }\n\t\t }\n\t\t }\n\t}\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "51adc98d0fb50a2cedda160a97ca137d", "src_uid": "bb6fb9516b2c55d1ee47a30d423562d7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\npublic class Tester {\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\tString s=in.next();\n\t\tint i,j;\n\t\tchar arr[]=s.toCharArray();\n\t\tchar arr1[]=new char[s.length()];\n\t\tfor(i=0;i\n\t{\n\t\t//Iterator it = h.entrySet().iterator();\n//\t while (it.hasNext()) {\n//\t Map.Entry pair = (Map.Entry)it.next();\n//\t // System.out.println(pair.getKey() + \" = \" + pair.getValue());\n//\t it.remove(); // avoids a ConcurrentModificationException\n//\t }\n\t\tprivate int first;\n\t\tprivate int index;\n\t\t//private long second;;\n\n\t\tpublic Pair(int i, int j) \n\t\t{ \n\t\t\tthis.first = i;\n\t\t\tthis.index = j;\n\t\t}\n\t\tpublic int getFirst() { return first; }\n\t\t//public long getSecond() { return second; }\n\t\tpublic int getIndex() { return index ;}\n\t\tpublic void setFirst(int k) { this.first=k ; }\n\t\tpublic void setIndex(int k) { this.index=k ;}\n\t\t//public void setSecond(long k) { this.second=k ;}\n\t\t@Override\n\t\tpublic int compareTo(Pair o) \n\t\t{\n\t\t\treturn Integer.compare(o.first,this.first);\n\t\t}\n\t}\n\tstatic class InputReader {\n\t\tpublic BufferedReader reader;\n\t\tpublic StringTokenizer tokenizer;\n\n\t\tpublic InputReader(InputStream inputstream) {\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\tString fullLine=null;\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tfullLine=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 fullLine;\n\t\t\t}\n\t\t\treturn fullLine;\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(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\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t}\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "8e717bce93d518684d84601ec43dfcff", "src_uid": "6c2e658ac3c3d6b0569dd373806fa031", "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.util.Arrays;\nimport java.util.StringTokenizer;\n\n\n\npublic class PrimesOnInterval{\n\n\tstatic boolean[] isPrime;\n\tpublic static void sieve()\n\t{\n\t\tisPrime = new boolean[1000005];\n\t\tArrays.fill(isPrime, true);\n\t\tisPrime[0] = isPrime[1] = false;\n\n\t\tfor (int i = 2; i < isPrime.length; i++) {\n\t\t\tif(!isPrime[i])\n\t\t\t\tcontinue;\n\t\t\tfor (int j = i * 2; j < isPrime.length; j += i) \n\t\t\t\tisPrime[j] = false;\n\t\t}\n\n\t}\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 k = Integer.parseInt(st.nextToken());\n\t\tsieve();\n\t\tint count = 0;\n\t\tint idx = a;\n\t\twhile(count < k && idx <= b)\n\t\t{\n\t\t\tif(isPrime[idx++])\n\t\t\t\tcount++;\n\t\t}\n\t\tif(count != k)\n\t\t{\n\t\t\tSystem.out.println(-1);\n\t\t\treturn;\n\t\t}\n\n\t\tint minL = idx - a;\n\t\tint end = idx;\n\t\tint i = a;\n\t\tfor (; i <= b && end <= b; i++, end++) \n\t\t{\n\t\t\twhile(i <= b && i <= end && !isPrime[i])i++;\n\t\t\twhile(end <= b && !isPrime[end])end++;\n\t\t\t\n\t\t\tminL = Math.max(minL, end - i);\n\t\t}\n\t\tSystem.out.println(minL);\n\t}\n}", "lang_cluster": "Java", "tags": ["two pointers", "binary search", "number theory"], "code_uid": "85f127ec4fa7e3081f629a4c0d6332b8", "src_uid": "3e1751a2990134f2132d743afe02a10e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.BufferedInputStream;\nimport java.io.BufferedOutputStream;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\nimport java.lang.Math.*;\n\n\n\npublic class Main {\n\n public static void main(String[] args) {\n // TODO Auto-generated method stub\n Scanner cin = new Scanner(new BufferedInputStream(System.in));\n PrintWriter cout = new PrintWriter(new BufferedOutputStream(System.out));\n Task work = new Task(cin, cout);\n work.solve();\n cout.flush();\n }\n\n}\nclass Task{\n Scanner cin;\n PrintWriter cout;\n final int maxn = 400005;\n final int MOD = 1000000007;\n int []dp = new int[maxn];\n int r, g;\n public Task(Scanner cin, PrintWriter cout) { \n // TODO Auto-generated constructor stub \n this.cin = cin;\n this.cout = cout;\n r = cin.nextInt();\n g = cin.nextInt();\n }\n public void read() {\n r = cin.nextInt();\n g = cin.nextInt();\n }\n int GetHeight(){\n for (int i = 1; ; i++){\n if (i * (i + 1) / 2 > r + g){\n return i-1;\n }\n }\n }\n public void solve(){\n int h = GetHeight();\n int res = 0;\n dp[0] = 1;\n for (int i = 1; i <= h; i++){\n for (int j = r; j >= 0; j--){\n dp[i+j] = (dp[i+j] + dp[j]) % MOD;\n }\n }\n for (int i = Math.max(h*(h+1)/2 - g, 0); i <= r; i++){\n res = (res + dp[i]) % MOD;\n }\n cout.println(res);\n } \n}", "lang_cluster": "Java", "tags": ["dp"], "code_uid": "8962f53592b7ebd86a935a8f39bf35e2", "src_uid": "34b6286350e3531c1fbda6b0c184addc", "difficulty": 2000.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.util.Arrays;\nimport java.util.StringTokenizer;\n\nimport javax.tools.ToolProvider;\n\n\n\npublic class knapsack {\n\tstatic int a[];\t\n\tstatic int n;\n\tstatic int memo[][];\n\t\n\t\n\n\tpublic static void main(String[] args) throws IOException {\n\t\t// TODO Auto-generated method stub\n\t\tScanner sc=new Scanner(System.in);\n\t\tlong n=sc.nextLong();\n\t\tint count=1;\n\t\t\n\t\twhile(n-count>0) {\n\t\t\tn-=count;\n\t\t\tcount++;\n\t\t}\n\t\tSystem.out.println(n);\n\t}\n\t\n\n\t\n\t\n\tstatic class Scanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n Scanner(InputStream system) {\n br = new BufferedReader(new InputStreamReader(system));\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 int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n\n\t}\n\n}\n\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "69e7dbc3df04f5ff8edd2e2053c42c9f", "src_uid": "1db5631847085815461c617854b08ee5", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\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.Iterator;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Scanner;\nimport java.util.Set;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n \n public static Scanner input = new Scanner(System.in);\n\n public static void main(String[] args)\n throws IOException {\n\n // BufferedReader buffer=new BufferedReader(new InputStreamReader(System.in));\n // String str;\n// while((str=buffer.readLine())!=null){\n PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));\n//while(input.hasNextLine()){\n // Scanner sc=new Scanner(System.in);\n int t=input.nextInt();\n int r=input.nextInt();\n writer.println(Math.min((t+r)/3, Math.min(t, r)));\n writer.flush();\n\n }}", "lang_cluster": "Java", "tags": ["math", "greedy", "implementation", "number theory"], "code_uid": "8677c0e4e561b87d91bad7e3c86fbf64", "src_uid": "0718c6afe52cd232a5e942052527f31b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\npublic class kFactorization_797A {\n\tpublic static boolean prime(int n) {\n\t\tif(n==1)\n\t\t\treturn false;\n\t\tif(n==2)\n\t\t\treturn true;\n\t\tfor(int i=2;i a) {\n\t\t\tresult = \"NO\";\n\t\t} else {\n\t\t\ta -= x;\n\t\t\tif(y > a + b) {\n\t\t\t\tresult = \"NO\";\n\t\t\t} else {\n\t\t\t\tint k = a + b - y;\n\t\t\t\tif(z > k + c) {\n\t\t\t\t\tresult = \"NO\";\n\t\t\t\t} \n\t\t\t}\n\t\t}\n\t\tSystem.out.println(result);\n\t}\n}", "lang_cluster": "Java", "tags": ["brute force", "greedy", "implementation"], "code_uid": "3c07c266e8830de67233712270aff2ca", "src_uid": "d54201591f7284da5e9ce18984439f4e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "//package school3;\n\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.Scanner;\n\npublic class A {\n\tScanner in;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tMap map = new HashMap();\n\t\tString[] x = {\"January\", \"February\", \"March\", \"April\", \"May\", \"June\", \"July\", \"August\", \"September\", \"October\", \"November\", \"December\"};\n\t\tfor(int i = 0;i < x.length;i++){\n\t\t\tmap.put(x[i], i);\n\t\t}\n\t\t\n\t\tString mon = in.next();\n\t\tint n = ni();\n\t\tout.println(x[(map.get(mon) + n) % 12]);\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 A().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(o.length > 1 || o[0].getClass().isArray() ? Arrays.deepToString(o) : o[0]); }\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "634d8a72a76356b6be6efc425cb6ce5b", "src_uid": "a307b402b20554ce177a73db07170691", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class may16 {\n\n\tpublic static void main(String[] args) {\n\n\t\tScanner s=new Scanner(System.in);\n\t\t//System.out.println(\"enter n\");\n\t\tint n=s.nextInt();\n\t\tint count=n;\n\t\tfor(int i=1; i<=n-1; i++)\n\t\t{\n\t\t\tcount=count + (n-i)*i;\n\t\t}\n\t\tSystem.out.println(count);\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "359026e9f744c144f0626b786b54caf1", "src_uid": "6df251ac8bf27427a24bc23d64cb9884", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.*;\npublic class Main { \n public static void main(String[] args)\n { \n int n = new Scanner (System.in).nextInt() ; int c = 0 ; int sum = 1 ; \n for (int i=1 ; sum<=n ; i++)\n { \n c++;\n sum+=i;\n n-=sum; \n }\n System.out.println(c); \n }\n} ", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "d7ee1471325c1de6f4187766284f8779", "src_uid": "873a12edffc57a127fdfb1c65d43bdb0", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n \npublic class Main {\n \n public static void main(String[] args) throws IOException{\n Scanner sc = new Scanner(System.in);//new File(\"input.txt\"));\n PrintWriter pw = new PrintWriter(System.out);//new File(\"output.txt\"));\n int n = sc.nextInt();\n int x = n;\n int m = 0;\n while (x > 0)\n {\n x /= 10;\n m++;\n }\n long ans = (long)n*m + m - 1;\n long k = 1;\n for (int i = 0; i < m-1; i++)\n {\n k *= 10;\n ans -=k;\n }\n pw.println(ans);\n pw.close();\n }\n}", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "43ffa8e3b810949576dc4c05e488a0ba", "src_uid": "4e652ccb40632bf4b9dd95b9f8ae1ec9", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class Test2\n{\n\tpublic static void main(String args[])\n\t{\n\t\tScanner in = new Scanner(System.in);\n\t\t\n\t long n = in.nextInt();\n\t \n\t \n\t \n\t \n\t long a = (n%100000)/10000;\n\t long b = (n%10000)/1000;\n\t long c = (n%1000)/100;\n\t long d = (n%100)/10;\n\t long e = n%100%10;\n\t \n\t long res = a*10000 + c*1000 + e*100 + d*10 + b;\n\t \n\t long result1 = ((res%100000)*(res%100000))%100000;\n\t long result2 = (((result1%100000)*(result1%100000)*((res%100000)%100000)%100000))%100000;\n\t \n\t a = (result2%100000)/10000;\n\t b = (result2%10000)/1000;\n\t c = (result2%1000)/100;\n\t d = (result2%100)/10;\n\t e = result2%100%10;\n\t \n\t\tSystem.out.println(a+\"\"+b+\"\"+c+\"\"+d+\"\"+e);\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "519659371bf80bec4f067092137a81e0", "src_uid": "51b1c216948663fff721c28d131bf18f", "difficulty": 1400.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 FastScanner in = new FastScanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n D solver = new D();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class D {\n public void solve(int testNumber, FastScanner in, PrintWriter out) {\n long n = in.ni(), k = in.ni();\n long a = in.ni(), b = in.ni();\n long nk = n * k;\n long x = Long.MAX_VALUE;\n long y = 0;\n for (int i = 0; i <= n + 2; i++) {\n long l = a + b + k * i;\n long ans = nk / IntegerUtils.gcd(nk, l);\n x = Math.min(x, ans);\n y = Math.max(y, ans);\n\n l = a - b + k * i;\n if (l > 0) {\n ans = nk / IntegerUtils.gcd(nk, l);\n x = Math.min(x, ans);\n y = Math.max(y, ans);\n }\n\n l = b - a + k * i;\n if (l > 0) {\n ans = nk / IntegerUtils.gcd(nk, l);\n x = Math.min(x, ans);\n y = Math.max(y, ans);\n }\n\n l = -a - b + k * i;\n if (l > 0) {\n ans = nk / IntegerUtils.gcd(nk, l);\n x = Math.min(x, ans);\n y = Math.max(y, ans);\n }\n }\n out.print(x + \" \" + y);\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 ns() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n String rl = in.readLine();\n if (rl == null) {\n return null;\n }\n st = new StringTokenizer(rl);\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return st.nextToken();\n }\n\n public int ni() {\n return Integer.parseInt(ns());\n }\n\n }\n\n static class IntegerUtils {\n public 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 }\n}\n\n", "lang_cluster": "Java", "tags": ["math", "implementation", "number theory"], "code_uid": "bcb585dce1352fad2fccafdbe51bf422", "src_uid": "5bb4adff1b332f43144047955eefba0c", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\npublic class Main\n{\n\tpublic static void main(String[] args)throws IOException {\n\t BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));\n int n=Integer.parseInt(br.readLine());\n int[][] arr=new int[n][n];\n int sum=0;\n for(int i=0;i min) {\n min = set.size();\n }\n set.clear();\n }\n System.out.println(min);\n }\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "strings", "implementation"], "code_uid": "a25c3ca6bb10846a2182e8d83c17619c", "src_uid": "567ce65f87d2fb922b0f7e0957fbada3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\n\npublic class Solution{\n public static void main(String []args){\n long d1,d2,d3,dis1,dis2,dis3,dis4;\n Scanner scan=new Scanner(System.in);\n d1=scan.nextInt();\n d2=scan.nextInt();\n d3=scan.nextInt();\n dis1=d1+d2+d3;\n dis2=d1+d3+d3+d1;\n dis3=d2+d3+d3+d2;\n dis4=d1+d1+d2+d2;\n System.out.println(Math.min(dis1,Math.min(dis2,Math.min(dis3,dis4))));\n }\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "14e860a869389eb594baab15b0ad0aed", "src_uid": "26cd7954a21866dbb2824d725473673e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.HashSet;\nimport java.util.Scanner;\nimport java.util.Set;\n\npublic class Dummy {\n public static void main(String args[]) {\n Scanner in = new Scanner(System.in);\n //variable\n int t = in.nextInt();\n int n,k,d;\n int ans[] = new int[t];\n\n //variable\n for (int i=0; i s = new HashSet();\n k = in.nextInt();\n d = in.nextInt();\n ans[i] = k;\n for (int j = 0; j < n; j++) {\n tv[j] = in.nextInt();\n }\n for (int j = 0; j < n; j++) {\n for (int z = 0; z < d; z++) {\n if (j+z=n){\n break;\n }\n }\n\n }\n for (int i=0; i1){\n\t\t\t\tsum=sum*3%1000003;\n\t\t\t\tn--;\n\t\t\t}\n\t\t\tSystem.out.println(sum);\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "0ad03af2f6af24c1382804a17f5ba5c3", "src_uid": "1a335a9638523ca0315282a67e18eec7", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.*;\n\npublic class C304C {\n \n static Vector> hash1 = new Vector() , hash2 = new Vector();\n \n public static void main(String[] args) {\n \n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int k = in.nextInt();\n \n Vector v1 = new Vector() , v2 = new Vector();\n for(int i = 0;i < k;i ++)v1.add(in.nextInt());\n \n k = in.nextInt();\n \n for(int i = 0;i < k;i ++)v2.add(in.nextInt());\n \n /*if(v1.size() != v2.size()){\n System.out.println(-1);\n return;\n }*/\n \n hash1.add(v1); hash2.add(v2);\n \n int sum = 0;\n while(true){\n if(v1.get(0) > v2.get(0)){\n v1.add(v2.remove(0)); v1.add(v1.remove(0));\n }else{\n v2.add(v1.remove(0)); v2.add(v2.remove(0));\n }\n \n sum ++;\n if(v1.size() == 0 || v2.size() == 0)break;\n \n if(sum > 200000){\n System.out.println(-1);\n return ;\n }\n \n }\n \n System.out.println(sum + \" \" + (v1.size() == 0?2:1));\n }\n\n}\n", "lang_cluster": "Java", "tags": ["dfs and similar", "brute force", "games"], "code_uid": "c0fd50f642adffc7b5705b9ee8eb8fbd", "src_uid": "f587b1867754e6958c3d7e0fe368ec6e", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\n \npublic class Solution{\n \n public static void main(String args[]){\n \n Scanner scan = new Scanner(System.in);\n \n int limar = scan.nextInt();\n int bob = scan.nextInt();\n int years = 0;\n while(limar<=bob){\n years++;\n limar=limar*3;\n bob=bob*2;\n }\n System.out.println(years);\n }\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "b23f44483bdcc3d6b24126517bec844c", "src_uid": "a1583b07a9d093e887f73cc5c29e444a", "difficulty": 800.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\n\n\n\n\n \npublic class ne {\n\tstatic class Reader1 {\n\t static BufferedReader reader;\n\t static StringTokenizer tokenizer;\n\n\t /** call this method to initialize reader for InputStream */\n\t static void init(InputStream input) {\n\t reader = new BufferedReader(\n\t new InputStreamReader(input) );\n\t tokenizer = new StringTokenizer(\"\");\n\t }\n\n\t /** get next word */\n\t static String next() throws IOException {\n\t while ( ! tokenizer.hasMoreTokens() ) {\n\t //TODO add check for eof if necessary\n\t tokenizer = new StringTokenizer(\n\t reader.readLine() );\n\t }\n\t return tokenizer.nextToken();\n\t }\n\n\t static int nextInt() throws IOException {\n\t return Integer.parseInt( next() );\n\t }\n\t\t\n\t static double nextDouble() throws IOException {\n\t return Double.parseDouble( next() );\n\t }\n\t static float nextFloat() throws IOException {\n\t return Float.parseFloat( next() );\n\t }\n\t static long nextLong() throws IOException {\n\t return Long.parseLong( next() );\n\t }}\npublic static void main(String[] args) throws IOException{\n\t\t\n\n\t\tReader1.init(System.in);\n\t\tint n=Reader1.nextInt();\n\t\tint m=Reader1.nextInt();\n\t\tint[] a= new int[m+n];\n\t\tfor(int i=0;i0)\n\t\t\t\t\t\t\t\t{a[i]=1;n1--;}\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t{a[i]=0;m1--;}}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif(m1>0)\n\t\t\t\t\t\t\t{a[i]=0;m1--;}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\t{a[i]=1;n1--;}}\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\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\tif(a[i-1]==1)\n\t\t\t\t\t\t\t{if(m1>0)\n\t\t\t\t\t\t\t\t{a[i]=0;m1--;}\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t{a[i]=1;n1--;}}\n\t\t\t\t\t\t\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\t{if(a[i-1]==0)\n\t\t\t\t\t\t\t{if(n1>0)\n\t\t\t\t\t\t\t\t{a[i]=1;n1--;}\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t{a[i]=0;m1--;}}}\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\t}\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\t\n}\t\n\t\t//n\n//\t\tfor(int i=0;i0)\n\t\t\t\t\t\t\t\t{a[i]=1;n1--;}\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t{a[i]=0;m1--;}}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif(m1>0)\n\t\t\t\t\t\t\t{a[i]=0;m1--;}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\t{a[i]=1;n1--;}}\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\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\tif(a[i-1]==1)\n\t\t\t\t\t\t\t{if(m1>0)\n\t\t\t\t\t\t\t\t{a[i]=0;m1--;}\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t{a[i]=1;n1--;}}\n\t\t\t\t\t\t\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\t{if(a[i-1]==0)\n\t\t\t\t\t\t\t{if(n1>0)\n\t\t\t\t\t\t\t\t{a[i]=1;n1--;}\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t{a[i]=0;m1--;}}}\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\t}\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\t\n}\tint count1=0;\n\t\tfor(int i=0;icount)\n\t\t\tcount2=count1;\n\t\telse\n\t\t\tcount2=count;\n\t\tint k=m+n-1-count2;\n\t\tSystem.out.println(count2+\" \"+ k);\n\t\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\t\n}\n\n}//5 5 ans should be 0 9 \n// 5 4 ans should be 1 7\n", "lang_cluster": "Java", "tags": ["greedy", "implementation", "games"], "code_uid": "c52d1f27ee834ace0e30ea86cc9330bb", "src_uid": "c8378e6fcaab30d15469a55419f38b39", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.math.*;\nimport java.io.*;\n\n\npublic class q_3 {\n static Scanner sc;\n\n public static void main(String[] args){\n sc = new Scanner(System.in);\n int n = getInt();\n int[] arr = new int[n/2];\n for(int i=0 ; i= a) {\n\t\t\tfor (int i = 2*a; i <= n; i++) {\n\t\t\t\tif (city[i] == 1) {\n\t\t\t\t\tcrim++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int i = a + 1; i < 2*a; i++) {\n\t\t\t\tif (city[i] == 1 && city[i] == city[2*a - i]) {\n\t\t\t\t\tcrim += 2;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 1; i < 2*a-n; i++) {\n\t\t\t\tif (city[i] == 1) {\n\t\t\t\t\tcrim++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int i = a + 1; i <= n; i++) {\n\t\t\t\tif (city[i] == 1 && city[i] == city[2*a - i]) {\n\t\t\t\t\tcrim += 2;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(crim);}\n\t}", "lang_cluster": "Java", "tags": ["constructive algorithms", "implementation"], "code_uid": "63be2ef9adb293a326e25d433bc5b3cf", "src_uid": "4840d571d4ce6e1096bb678b6c100ae5", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "//package round491;\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 E {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tlong n = nl();\n\t\tint m = Long.toString(n).length();\n\t\tint[] f = new int[10];\n\t\tfor(char c : Long.toString(n).toCharArray()){\n\t\t\tf[c-'0']++;\n\t\t}\n\t\t\n\t\tint M = 1;\n\t\tfor(int i = 0;i < 10;i++){\n\t\t\tf[i]++;\n\t\t\tM *= f[i];\n\t\t}\n\t\t\n\t\tlong[] dp = new long[M];\n\t\tdp[0] = 1;\n\t\tlong ans = 0;\n\t\tfor(int k = 1;k <= m;k++){\n\t\t\tlong[] ndp = new long[M];\n\t\t\t\n\t\t\tint[] b = new int[10];\n\t\t\tint id = 0;\n\t\t\tdo{\n\t\t\t\tfor(int j = 0;j <= 9;j++){\n\t\t\t\t\tif(b[j] + 1 < f[j]){\n\t\t\t\t\t\tb[j]++;\n\t\t\t\t\t\tif(j >= 1){\n\t\t\t\t\t\t\tboolean ok = true;\n\t\t\t\t\t\t\tfor(int t = 0;t < 10;t++){\n\t\t\t\t\t\t\t\tif(f[t] == 1 || b[t] >= 1){\n\t\t\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\t\t\tok = false;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif(ok)ans += dp[id];\n\t\t\t\t\t\t}\n\t\t\t\t\t\tndp[(int)encInc(b, f)] += dp[id];\n\t\t\t\t\t\tb[j]--;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tid++;\n\t\t\t}while(inc(b, f));\n\t\t\tdp = ndp;\n\t\t}\n\t\tout.println(ans);\n\t}\n\npublic static boolean inc(int[] b, int[] a)\n{\n\tfor(int i = b.length-1;i >= 0;i--){\n\t\tif(++b[i] < a[i])return true;\n\t\tb[i] = 0;\n\t}\n\treturn false;\n}\n\n\t\n\tpublic static long encInc(int[] a, int[] lim)\n\t{\n\t\tlong code = 0;\n\t\tfor(int i = 0;i < a.length;i++){\n\t\t\tcode = code * lim[i] + a[i];\n\t\t}\n\t\treturn code;\n\t}\n\t\n\tpublic static int[] decInc(long code, int[] lim)\n\t{\n\t\tint n = lim.length;\n\t\tint[] a = new int[n];\n\t\tfor(int i = n-1;i >= 0;i--){\n\t\t\ta[i] = (int)(code % lim[i]);\n\t\t\tcode /= lim[i];\n\t\t}\n\t\treturn a;\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 E().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": ["brute force", "math", "combinatorics"], "code_uid": "920e77876e5f299a3257b41dc5f00ed9", "src_uid": "7f4e533f49b73cc2b96b4c56847295f2", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\n\npublic class Smile {\n\tstatic Scanner in;\n\tstatic PrintWriter out;\t\n\n\tpublic static void main(String[] args) {\n\t\tin = new Scanner(System.in);\n\t\tout = new PrintWriter(System.out);\n\t\tint n = in.nextInt();\n\t\tint d = 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\t}\n\t\tArrays.sort(a);\n\t\tint m = in.nextInt();\n\t\tint temp = Math.min(n, m);\n\t\tint ans = 0;\n\t\tfor (int i = 0; i < temp; i++) {\n\t\t\tans += a[i];\n\t\t}\n\t\tif (m > temp) {\n\t\t\tans = ans - d * (m - temp);\n\t\t}\n\t\tout.println(ans);\n\t\tout.close();\n}\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "7842150647279e0f0bb3271db25a12ed", "src_uid": "5c21e2dd658825580522af525142397d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main{\n\npublic static int[] res;\npublic static int cont;\n\npublic static void main(String [] args) throws Exception{\nBufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));\nint n=Integer.parseInt(entrada.readLine());\nres= new int[n];\ncont=0;\ns(n);\nStringBuilder sb = new StringBuilder();\nsb.append(n+\" \");\nfor(int i=0;i=1;i--)\n if(n%i==0){\n res[cont++]=i;\n s(i);\n return;\n }\n}\n\n}", "lang_cluster": "Java", "tags": ["greedy"], "code_uid": "94f78cb24101eb09b5c15ef27918a57d", "src_uid": "2fc946bb72f56b6d86eabfaf60f9fa63", "difficulty": 1300.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 s=new Scanner(System.in);\n int n=s.nextInt();\n int a[]=new int[n];\n for(int i=0;i maxX) {\n\t\t\t\tmaxX = x;\n\t\t\t}\n\t\t\t\n\t\t\tif (y < minY) {\n\t\t\t\tminY = y;\n\t\t\t}\n\t\t\t\n\t\t\tif (y > maxY) {\n\t\t\t\tmaxY = y;\n\t\t\t}\t\n\t\t}\n\t\t\n\t\tint diffX = maxX - minX;\n\t\tint diffY = maxY - minY;\n\t\t\n\t\tint area = diffX * diffY;\n\t\t\n\t\tif (area == 0) {\n\t\t\tSystem.out.println(-1);\n\t\t} else {\n\t\t\tSystem.out.println(Math.abs(area));\n\t\t}\n\t\t\n\t\t\n\t}\n\t\n\tprivate static class Pair implements Comparable{\n\t\tint x;\n\t\tint y;\n\t\t\n\t\tpublic Pair(int x, int y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Pair other) {\n\t\t\tif (this.x != other.x) {\n\t\t\t\treturn Integer.compare(this.x, other.x);\n\t\t\t}\n\t\t\t\n\t\t\treturn Integer.compare(this.y, other.y);\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["geometry", "implementation"], "code_uid": "e9ceb088f490428f34912c7c686c2912", "src_uid": "ba49b6c001bb472635f14ec62233210e", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "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.Scanner;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Bisoye\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 APaintTheNumbers solver = new APaintTheNumbers();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class APaintTheNumbers {\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n\n int n = in.nextInt();\n\n int[] A = new int[n];\n for (int i = 0; i < n; i++) {\n int c = in.nextInt();\n\n A[i] = c;\n }\n\n Arrays.sort(A);\n\n boolean rem[] = new boolean[n];\n int count = 0;\n for (int i = 0; i < n; i++) {\n if (rem[i]) continue;\n for (int j = i; j < n; j++) {\n if (rem[j]) continue;\n if (A[j] % A[i] == 0) {\n rem[j] = true;\n }\n }\n count++;\n }\n out.println(count);\n\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["math", "greedy", "implementation"], "code_uid": "cb53fe61ee0fbfed9010184f7f3b81f4", "src_uid": "63d9b7416aa96129c57d20ec6145e0cd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.*;\n\npublic class WhereDoITurn227A\n{\n public static void main(String[] args) \n {\n // Set up scanner\n Scanner sc = new Scanner(System.in); \n // System.out.println(\"Enter xa\");\n long xa = sc.nextLong();\n // System.out.println(\"Enter ya\");\n long ya = sc.nextLong();\n \n // System.out.println(\"Enter xb\");\n long xb = sc.nextLong();\n // System.out.println(\"Enter yb\");\n long yb = sc.nextLong();\n \n // System.out.println(\"Enter xc\");\n long xc = sc.nextLong();\n // System.out.println(\"Enter yc\");\n long yc = sc.nextLong();\n \n if (xa==xb && yayb)\n {\n if (yb>yc)\n {\n System.out.println(\"TOWARDS\");\n return;\n }\n else if (xbyc)\n {\n System.out.println(\"RIGHT\");\n return;\n }\n else\n {\n System.out.println(\"LEFT\");\n return;\n }\n }\n \n if (xa>xb && ya==yb)\n {\n if (xb>xc)\n {\n System.out.println(\"TOWARDS\");\n return;\n }\n else if (yb>yc)\n {\n System.out.println(\"LEFT\");\n return;\n }\n else\n {\n System.out.println(\"RIGHT\");\n return;\n }\n }\n \n if (xayb)\n {\n if (xbyc)\n {\n System.out.println(\"TOWARDS\");\n return;\n }\n else if (xbxb && yaxc && ybxc)\n {\n System.out.println(\"LEFT\");\n return;\n }\n else\n {\n System.out.println(\"RIGHT\");\n return;\n }\n }\n \n if (xa>xb && ya>yb)\n {\n if (xb>xc && yb>yc)\n {\n System.out.println(\"TOWARDS\");\n return;\n }\n else if (xb>xc)\n {\n System.out.println(\"RIGHT\");\n return;\n }\n else\n {\n System.out.println(\"LEFT\");\n return;\n }\n }\n }\n}\n \n ", "lang_cluster": "Java", "tags": ["geometry"], "code_uid": "e49b7e65bb285cd586e71bb378fe704c", "src_uid": "f6e132d1969863e9f28c87e5a44c2b69", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class B734 {\n public static void main(String [] args) {\n Scanner sc = new Scanner(System.in);\n int [] array = new int[4];\n int result = 0;\n\n for (int i = 0; i < 4; i++) {\n array[i] = sc.nextInt();\n }\n\n int tfx = Math.min(array[0],Math.min(array[2],array[3]));\n int tt = Math.min(array[0], array[1]);\n\n if (tfx == array[0]) {\n result = tfx * 256;\n } else {\n if (tfx == 0) {\n result = tt * 32;\n } else {\n if (tt >= array[0] - tfx) {\n result = tfx * 256 + ((array[0] - tfx) * 32);\n } else {\n result = tfx * 256 + tt * 32;\n }\n }\n }\n\n System.out.println(result);\n\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "greedy", "implementation", "brute force"], "code_uid": "c3d2ddd004358e1f4a19925e96038091", "src_uid": "082b31cc156a7ba1e0a982f07ecc207e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.Scanner;\n\npublic class CalculatingFunction {\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tScanner scan=new Scanner(System.in);\n\t\t\tlong n=scan.nextLong();\n\t\t\tlong res=0;\n\t\t\tif(n%2==0)\n\t\t\t{\n\t\t\t\tres=n/2;\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t\telse {\n\t\t\t\tres=(n/2)-n;\n\t\t\t}\n\t\t\tSystem.out.println(res);\n\t\t} catch (Exception e) {\n\t\t\t// TODO: handle exception\n\t\t}\n\t\t\n\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "d9bf64d0016b4c030bda1438a92e9fef", "src_uid": "689e7876048ee4eb7479e838c981f068", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.Scanner;\n\npublic class A59 {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n\n String str = scan.next();\n int upper = 0;\n int lower = 0;\n for(int i = 0; i < str.length(); i++) {\n char c = str.charAt(i);\n if(Character.toLowerCase(c) == c) {\n lower++;\n } else {\n upper++;\n }\n }\n\n String output = (upper > lower) ? str.toUpperCase() : str.toLowerCase();\n System.out.println(output);\n }\n}\n", "lang_cluster": "Java", "tags": ["strings", "implementation"], "code_uid": "8f52e080344aebabd52d456dc6ac3350", "src_uid": "b432dfa66bae2b542342f0b42c0a2598", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "\nimport java.util.Scanner;\n\npublic class champion {\n\tstatic long n, m, k;\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tn = scan.nextLong();\n\t\tm = scan.nextLong();\n\t\tk = scan.nextLong();\n\t\tlong low = 1;\n\t\tlong high = n * (m+1);\n\t\t\n\t\twhile(low < high) {\n\t\t\tlong x = (high+low) >> 1;\n\t\t\tif(works(x)) {\n\t\t\t\tlow = x+1;\n\t\t\t} else {\n\t\t\t\thigh = x;\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(high-1);\n\t\t\n\t}\n\t\n\tpublic static boolean works(long attempt) {\n\t\tlong num = 0;\n\t attempt--;\n\t for(int i=1; i<=n; ++i) {\n\t \tnum += Math.min(m, attempt/i);\n\t }\n\t return num < k;\n\t}\n}\n", "lang_cluster": "Java", "tags": ["brute force", "binary search"], "code_uid": "972c33fcb58683376442c2606eb3992c", "src_uid": "13a918eca30799b240ceb9de47507a26", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class cheaptravel {\npublic static void main (String[]args)\n{\n\tScanner sc = new Scanner (System.in);\n\tint annplan = sc.nextInt();//a\n\tint mtickplan = sc.nextInt();//b\n\tint onetickp = sc.nextInt();//c\n\tint mtickp = sc.nextInt();//d\n\tint a1=annplan/mtickplan;\n\tint a2=a1*mtickplan;\n\tint a3=annplan-a2;\n\tint price=0;\n\tif(mtickp==(onetickp*mtickplan))//\n\t\tprice=onetickp*annplan;\n\tif((onetickp*(a1+a3))<((a1*mtickp)))\n\t{\nprice=onetickp*annplan;\n\t}\n\tif(mtickp<(onetickp*mtickplan) && mtickp(onetickp*mtickplan) && onetickpannplan)&&(mtickp<(onetickp*annplan)))\n\t\t\t\t\t\t{\n\t\t\t\t\tprice=mtickp;\n\t\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\t\tif(mtickp0&&a30&&a3>mtickplan)\n\t\t\t\t \t\t{\n\t\t\t\t \t\t\twhile(a3 >mtickplan)\n\t\t\t\t \t\t\t{\n\t\t\t\t \t\t\t\tprice+=mtickp;\n\t\t\t\t \t\t\t\ta3-=mtickplan;\n\t\t\t\t \t\t\t}\n\t\t\t\t \t\t\tprice+=mtickp;\n\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//else\n\t\t\t\t\t\tif(mtickp==onetickp)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tprice=a1*mtickp;\n\t\t\t\t\t\t\tif(a3>0&&a30&&a3>mtickplan)\n\t\t \t\t{\n\t\t \t\t\twhile(a3 >mtickplan)\n\t\t \t\t\t{\n\t\t \t\t\t\tprice+=mtickp;\n\t\t \t\t\t\ta3-=mtickplan;\n\t\t \t\t\t}\n\t\t \t\t\tprice+=mtickp;\n\t\t \t\t}\n\t\t\t\t\t\t}\nSystem.out.print(price);\t\n}\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "da17213d176f1ae6fc2c6ab0261e29c9", "src_uid": "faa343ad6028c5a069857a38fa19bb24", "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.io.OutputStream;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\nimport java.io.BufferedOutputStream;\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 Kattio in = new Kattio(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskAA solver = new TaskAA();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskAA {\n public void solve(int testNumber, Kattio in, PrintWriter out) {\n int n = in.nextInt();\n int m = in.nextInt();\n\n int[] ans = new int[n + 1];\n for (int i = 0; i < m; ++i) {\n int x = in.nextInt();\n for (int j = x; j <= n; ++j) {\n if (ans[j] != 0) break;\n ans[j] = x;\n }\n }\n\n for (int i = 1; i <= n; ++i)\n out.print(ans[i] + \" \");\n }\n\n }\n\n static class Kattio extends PrintWriter {\n private BufferedReader r;\n private String line;\n private StringTokenizer st;\n private String token;\n\n public Kattio(InputStream i) {\n super(new BufferedOutputStream(System.out));\n r = new BufferedReader(new InputStreamReader(i));\n }\n\n public Kattio(InputStream i, OutputStream o) {\n super(new BufferedOutputStream(o));\n r = new BufferedReader(new InputStreamReader(i));\n }\n\n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n private String peekToken() {\n if (token == null)\n try {\n while (st == null || !st.hasMoreTokens()) {\n line = r.readLine();\n if (line == null) return null;\n st = new StringTokenizer(line);\n }\n token = st.nextToken();\n } catch (IOException e) {\n }\n return token;\n }\n\n private String nextToken() {\n String ans = peekToken();\n token = null;\n return ans;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "0d08556fdac02861bbec2bcd7001d392", "src_uid": "2e44c8aabab7ef7b06bbab8719a8d863", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Problem_50A {\n\n\tstatic public void main(String[] args) throws java.lang.Exception{\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\t\n\t\tString[] temp = in.readLine().split(\" \");\n\t\tint M = Integer.parseInt(temp[0]);\n\t\tint N = Integer.parseInt(temp[1]);\n\t\t\n\t\tint area = M * N;\n\t\t\n\t\tif(area == 1){\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tSystem.out.println(area / 2);\n\t\treturn;\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "greedy"], "code_uid": "a740b44f2360432d797fafbc6d6c491c", "src_uid": "e840e7bfe83764bee6186fcf92a1b5cd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "// A : Is your horseshoe on the other hoof?\n\nimport java.util.Scanner;\n\npublic class A {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int cnt = 0;\n boolean f;\n int[] values = new int[4];\n for (int i = 0; i < 4; i++) {\n values[i] = in.nextInt();\n f = false;\n for (int j = 0; j < i; j++) {\n if (values[i] == values[j]) {\n f = true;\n }\n }\n if (f) {\n cnt++;\n }\n }\n System.out.println(cnt);\n }\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "c02d2174255a8875c037d585de129b03", "src_uid": "38c4864937e57b35d3cce272f655e20f", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class cod {\n\n static int INFINITY = 2000000000;\n\n public static void main(String[] args) throws IOException {\n br = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n sc = new StringTokenizer(\"\");\n\n int array[] = new int[10];\n\n String line = br.readLine();\n String str[] = line.split(\" \");\n\n int num[] = new int[str.length];\n\n for (int i = 0; i < num.length; i++) {\n num[i] = Integer.parseInt(str[i]);\n }\n\n for (int i = 0; i < num.length; i++) {\n array[num[i]]++;\n }\n\n boolean legs = false;\n for (int i = 1; i < array.length; i++) {\n if (array[i] >= 4) {\n legs = true;\n array[i] -=4;\n break;\n }\n }\n\n if (!legs) {\n System.out.println(\"Alien\");\n } else {\n boolean elep=false;\n for (int i = 1; i < array.length; i++) {\n if (array[i] == 2) {\n System.out.println(\"Elephant\");\n elep=true;\n }\n }\n if(!elep){\n System.out.println(\"Bear\");\n }\n }\n\n }// end Main.\n\n static BufferedReader br;\n static StringTokenizer sc;\n static PrintWriter out;\n\n static String nxtTok() throws IOException {\n while (!sc.hasMoreTokens()) {\n String s = br.readLine();\n if (s == null)\n return null;\n sc = new StringTokenizer(s.trim());\n }\n return sc.nextToken();\n }\n\n static int nxtInt() throws IOException {\n return Integer.parseInt(nxtTok());\n }\n\n static long nxtLng() throws IOException {\n return Long.parseLong(nxtTok());\n }\n\n static double nxtDbl() throws IOException {\n return Double.parseDouble(nxtTok());\n }\n\n static int[] nxtIntArr(int n) throws IOException {\n int[] a = new int[n];\n for (int i = 0; i < n; i++)\n a[i] = nxtInt();\n return a;\n }\n\n static long[] nxtLngArr(int n) throws IOException {\n long[] a = new long[n];\n for (int i = 0; i < n; i++)\n a[i] = nxtLng();\n return a;\n }\n\n static char[] nxtCharArr() throws IOException {\n return nxtTok().toCharArray();\n }\n\n}// end class\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "012fc68c3157c6812d4097a99935acfc", "src_uid": "43308fa25e8578fd9f25328e715d4dd6", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\n\n\npublic class CodeForce {\n\t\n\t\n\t\n\t\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringBuilder sb = new StringBuilder();\n\t//\tint t=Integer.parseInt(br.readLine());\n\t\t\n\t//\twhile(t-->0)\n\tString[] sr=br.readLine().split(\" \");\n\tint n=Integer.parseInt(sr[0]);\n\tint a=Integer.parseInt(sr[1]);\n\tint b=Integer.parseInt(sr[2]);\n\tint temp=Math.min(a, b);\n\tint temp1=Math.max(a, b);\n\ta=temp;\n\tb=temp1;\n\tint l=(int)(Math.log(n)/Math.log(2));\n\tQueueq=new LinkedList();\n\tQueuest1=new LinkedList();\n\tint count=2;\n\t\n\tif(n==2)\n\t{\n\t\tSystem.out.println(\"Final!\");\n\t\treturn;\n\t}\n\t\n\tfor(int i=1;i<=n;i=i+2)\n\t{\n\t\tif(i==a&&i+1==b)\n\t{System.out.println(\"1\");\n\t\treturn;}\n\t\tif(i==a||i+1==a)\n\t\t\tq.add(a);\n\t\t\n\t\telse if(i==b||i+1==b)\n\t\t\tq.add(b);\n\t\t\n\t\telse\n\t\t\tq.add(i+1);\n\t\t\n\t\t\t\n\t}\n\n\t\n\t\n\t\n\t\n\t\n\twhile(true)\n\t{\n\t\tif(st1.isEmpty())\n\t{\n\t\t\twhile(!q.isEmpty())\n\t{\n\t\t\tint x=q.poll();\n\t int y=q.poll();\n\t if(x==a&&y==b)\n\t\t{if(count==l)\n\t\t\tSystem.out.println(\"Final!\");\n\t\telse System.out.println(count);\n\t\t\treturn;}\n\t\t\tif(x==a||y==a)\n\t\t\t\tst1.add(a);\n\t\t\t\n\t\t\telse if(x==b||y==b)\n\t\t\t\tst1.add(b);\n\t\t\t\n\t\t\telse\n\t\t\t\tst1.add(y);\n\t\t\n\t}\n\t}\n\telse if(q.isEmpty())\n\t{\n\t\twhile(!st1.isEmpty())\n\t\t{\n\t\tint x=st1.poll();\n\t int y=st1.poll();\n\t if(x==a&&y==b)\n\t {if(count==l)\n\t\t\tSystem.out.println(\"Final!\");\n\t\telse System.out.println(count);\n\t\t\treturn;}\n\t\t\tif(x==a||y==a)\n\t\t\t\tq.add(a);\n\t\t\t\n\t\t\telse if(x==b||y==b)\n\t\t\t\tq.add(b);\n\t\t\t\n\t\t\telse\n\t\t\t\tq.add(y);\n\t\t\n\t}}\n\t\tcount++;\n\t}\n\t\t\n\t\n\n\n\n\n\t\n\t\t\n\t\t\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t}}", "lang_cluster": "Java", "tags": ["constructive algorithms", "implementation"], "code_uid": "d7ba340e792f157b48f18d5ff187f867", "src_uid": "a753bfa7bde157e108f34a28240f441f", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.ArrayList;\n\nimport java.util.Scanner;\n\npublic class Duplicateelement {\n\n\n public static void main(String[] args) {\n Scanner input=new Scanner(System.in);\n int n,c=0;\n int c1=0;\n n=input.nextInt();\n String s;\n s=input.next();\n for (int i = 0; i < s.length(); i++) {\n if(s.charAt(i)=='0'){\n \n c1++;\n }else{\n c++;\n }\n }\n if(c>0){\n System.out.print(\"1\");\n }\n \n for (int i = 0; i < c1; i++) {\n System.out.print(\"0\");\n }\n \n \n }\n \n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "d1685c369faf2932785dd91e9a03f1c4", "src_uid": "ac244791f8b648d672ed3de32ce0074d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n/*\n * \tHeart beats fast\n * \t\tColors and promises\n * \t\t\tHow to be brave\n * \t\t\t\tHow can I love when I am afraid to fall...\n */\npublic class Main \n{\n\tpublic static void main(String[] args)\n\t{\n\t\tlong n=ni(),m=ni();\n\t\tlong k=nl();\n\t\tif(k()\n\t\t{\n\t\t\t@Override\n\t\t\tpublic int compare(Integer[]a,Integer[]b)\n\t\t\t{\n\t\t\t\tif(a[0]>b[0])\n\t\t\t\t\treturn 1;\n\t\t\t\telse if(b[0]>a[1])\n\t\t\t\t\treturn -1;\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t});\n\t}\n\tstatic String pr(String a, long b)\n\t{\n\t\tString c=\"\";\n\t\twhile(b>0)\n\t\t{\n\t\t\tif(b%2==1)\n\t\t\t\tc=c.concat(a);\n\t\t\ta=a.concat(a);\n\t\t\tb>>=1;\n\t\t}\n\t\treturn c;\n\t}\n\tstatic long powm(long a, long b, long m)\n\t{\n\t\tlong an=1;\n\t\tlong c=a;\n\t\twhile(b>0)\n\t\t{\n\t\t\tif(b%2==1)\n\t\t\t\tan=(an*c)%m;\n\t\t\tc=(c*c)%m;\n\t\t\tb>>=1;\n\t\t}\n\t\treturn an;\n\t}\n\tstatic 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\tstatic class Reader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n public Reader() {\n reader = new BufferedReader(new InputStreamReader(System.in), 32768);\n tokenizer = null;\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 public int nextInt() {\n return Integer.parseInt(next());\n }\n public long nextLong() {\n \treturn Long.parseLong(next());\n }\n public double nextDouble() {\n \treturn Double.parseDouble(next());\n }\n }\n}", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "097ae1970bb685eed44e3ebff04a1204", "src_uid": "e88bb7621c7124c54e75109a00f96301", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "//package Codeforces;\n\nimport java.util.Scanner;\n\npublic class FafaAndCompany {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tint m = n;\n\t\tint count = 0;\n\t\t\n\t\tif(n==2) {\n\t\t\tSystem.out.println(1);\n\t\t\treturn;\n\t\t}\n\t\tfor(int i=2;i= 0; j--) {\n if (index[j] > 0) {\n ans[i] = j;\n index[j]--;\n flag = true;\n if (j < temp) {\n match = false;\n }\n break;\n }\n }\n if (!flag) {\n break label;\n }\n }\n\n if (!match && i < lb) {\n rev_order(i);\n }\n\n else if(!flag){\n //System.out.println(i);\n for(i--; i>=0; i--){\n int t = hasLt(i);\n if(t==0) {\n rev_order(i+1);\n break;\n }\n }\n }\n\n for (int x = 0; x < la; x++) {\n System.out.print(ans[x]);\n }\n\n }\n //System.out.println(Arrays.toString(ans));\n }\n\n\n static void rev_order(int n){\n int p=n;\n for(int i=9;i>=0;i--){\n for(int j=index[i];j>0;j--){\n ans[p++]=i;\n }\n }\n }\n\n static int hasLt(int n){\n int temp=ans[n];\n index[ans[n]]++;\n // System.out.println(n+\" \"+temp+\" \"+index[ans[n]]+\" \"+index[temp-1]);\n for (int i = temp - 1; i >= 0; i--) {\n if (index[i] > 0) {\n ans[n] = i;\n index[i]--;\n return 0;\n }\n }\n return -1;\n }\n}\n", "lang_cluster": "Java", "tags": ["greedy", "dp"], "code_uid": "9c00fd8b44638df7669ecaa8d206243d", "src_uid": "bc31a1d4a02a0011eb9f5c754501cd44", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n FastScanner in;\n PrintWriter out;\n \n public void solve() throws IOException {\n int a = in.nextInt(), n = in.nextInt();\n int m = a + n;\n int[] f = new int[m];\n int[] c = new int[m];\n for(int k = 2; k < m; k++)\n if(f[k] == 0) {\n long s = 1l * k * k;\n if(s < m)\n for(int i = (int)s; i < m; i += k)\n f[i] = k;\n f[k] = k;\n }\n c[1] = 1;\n for(int k = 2; k < m; k++) {\n int p = f[k];\n int r = c[k / p];\n if(k % (1l * p * p * r) == 0) \n c[k] = p * p * r;\n else\n c[k] = r;\n }\n long ans = 0;\n for(int i = a; i < m; i++) {\n ans += i / c[i];\n }\n out.println(ans);\n }\n\n public void run() {\n try {\n// in = new FastScanner(new File(\".in\"));\n// out = new PrintWriter(new File(\".out\"));\n \n in = new FastScanner(new InputStreamReader(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(InputStreamReader f) {\n try {\n br = new BufferedReader(f);\n } catch (Exception e) {\n e.printStackTrace();\n }\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 Main().run();\n }\n}", "lang_cluster": "Java", "tags": ["number theory"], "code_uid": "8bd9581c4253f442d7556c7713737359", "src_uid": "915081861e391958dce6ee2a117abd4e", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\npublic class DataRecovery{\n public static void main(String[] argv) throws Exception{\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n String[] words=br.readLine().trim().split(\" \");\n int n=Integer.parseInt(words[0]), m=Integer.parseInt(words[1]), min=Integer.parseInt(words[2]), max=Integer.parseInt(words[3]);\n int cur;\n words=br.readLine().trim().split(\" \");\n int aMax=Integer.parseInt(words[0]), aMin=Integer.parseInt(words[0]);\n for(int i=1; iaMax){\n aMax=cur;\n }\n if(curmax){\n System.out.println(\"Incorrect\");\n }else if(aMin==min && aMax==max){\n System.out.println(\"Correct\");\n }else if((aMin==min || aMax==max) && n-m>=1){\n System.out.println(\"Correct\");\n }else if(n-m>=2){\n System.out.println(\"Correct\");\n }else{ \n System.out.println(\"Incorrect\");\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "f3d13eaa11fe6b86c62ef5e8875cc808", "src_uid": "99f9cdc85010bd89434f39b78f15b65e", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.util.ArrayList;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\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 Crash\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 int modulo = 1000000007;\n\tprivate int[] calc(int a, int b) {\n\t\treturn new int[] {1 + a / 2 + b / 2, (a + 1) / 2 + (b + 1) / 2};\n\t}\n\tpublic void solve(int testNumber, InputReader in, OutputWriter out) {\n\t\tint w = in.readInt();\n\t\tint h = in.readInt();\n\t\tlong ans = 0;\n\t\tfor (int i = 0; i < 2; i ++)\n\t\t\tfor (int j = 0; j < 2; j ++) {\n\t\t\t\tint[] cx = calc(i, w - i);\n\t\t\t\tint[] cy = calc(j, h - j);\n\t\t\t\tlong tmp = 0;\n\t\t\t\ttmp = (tmp + (long)cx[0] * cy[0] * (w + 1) * (h + 1)) % modulo;\n\t\t\t\ttmp = (tmp + (long)cx[0] * cy[1] * cx[0] * (h + 1)) % modulo;\n\t\t\t\ttmp = (tmp + (long)cx[1] * cy[0] * (w + 1) * cy[0]) % modulo;\n\t\t\t\ttmp = (tmp + (long)cx[1] * cy[1] * cx[0] * cy[0]) % modulo;\n\t\t\t\ttmp = (tmp + (long)cx[1] * cy[1] * cx[1] * cy[1]) % modulo;\n\t\t\t\tans = (ans + tmp * ((w - i) / 2 + 1) * ((h - j) / 2 + 1)) % modulo;\n\t\t\t}\n\t\tans = (ans - (w + 1) * (h + 1)) % modulo;\n\t\tans = (ans - (long)(w + 1) * (h + 1) * ((w + 1) * (h + 1) - 1) * 3) % modulo;\n\t\tans = (ans - (long)(w + 1) * (h + 1) * h * (h - 1)) % modulo;\n\t\tans = (ans - (long)(h + 1) * (w + 1) * w * (w - 1)) % modulo;\n\t\tfor (int i = 1; i <= w; i ++)\n\t\t\tfor (int j = 1; j <= h; j ++) {\n\t\t\t\tint t = NumberTheory.gcd(i, j) - 1;\n\t\t\t\tans = (ans - (long)(w - i + 1) * (h - j + 1) % modulo * t * 12) % modulo;\n\t\t\t}\n\t\tans = (ans + modulo) % modulo;\n\t\tout.printLine(ans);\n\t}\n}\n\nclass InputReader {\n\tprivate InputStream stream;\n\tprivate byte[] buf = new byte[1000];\n\tprivate int curChar;\n\tprivate int numChars;\n\n\tpublic InputReader(InputStream stream) {\n\t\tthis.stream = stream;\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\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\tprivate boolean isSpaceChar(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\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 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 printLine(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 NumberTheory {\n\tprivate NumberTheory() {\n\t}\n\n\tpublic static int gcd(int m, int n) {\n\t\tif (m == 0) return n;\n\t\twhile (n > 0) {\n\t\t\tint r = m % n;\n\t\t\tm = n;\n\t\t\tn = r;\n\t\t}\n\t\treturn m;\n\t}\n\n\t}\n\n", "lang_cluster": "Java", "tags": ["math", "geometry"], "code_uid": "26a92ab3962c78aac09988da79cbe333", "src_uid": "984788e4b4925c15c9c6f31e42f2f8fa", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.text.*;\n\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint t[] = new int[4];\n\t\tfor (int i = 0; i < 4; i++) {\n\t\t\tt[i] = sc.nextInt();\n\t\t}\n\t\tArrays.sort(t);\n\t\tif(t[0]+t[1]>t[2]||t[1]+t[2]>t[3]) System.out.println(\"TRIANGLE\");\n\t\telse if(t[0]+t[1]==t[2]||t[1]+t[2]==t[3]) System.out.println(\"SEGMENT\");\n\t\telse System.out.println(\"IMPOSSIBLE\");\n\t}\n\n}", "lang_cluster": "Java", "tags": ["brute force", "geometry"], "code_uid": "c2b1b83bb2c4254d1cbd52dd8929adc8", "src_uid": "8f5df9a41e6e100aa65b9fc1d26e447a", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Solution\n{\n public static void main(String[] args)\n {\n Scanner sc=new Scanner(System.in);\n long n,k,h;\n n=sc.nextLong();\n k=sc.nextLong();\n if((n&1)==1)\n h=(n/2)+1;\n else\n h=n/2;\n if(k<=h)\n {\n System.out.println(k*2-1);\n }\n else\n {\n System.out.println((k-h)*2);\n }\n }\n}", "lang_cluster": "Java", "tags": ["math"], "code_uid": "ea0b4b7428ae3ffde2768a2080924f32", "src_uid": "1f8056884db00ad8294a7cc0be75fe97", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\n\npublic class p266B {\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\tint n, t;\n\t\tn = in.nextInt();\n\t\tt = in.nextInt();\n\t\tString s = in.next();\n\t\tfor(int i = 0; i= index)\n binaryR.setCharAt(i, '1');\n else\n binaryR.setCharAt(i, '0');\n }\n long ans = Long.parseLong(binaryR.toString(), 2);\n out.println(ans);\n }\n\n static BufferedReader br;\n static StringTokenizer st;\n static PrintWriter out;\n\n public static void main(String[] args) throws IOException {\n InputStream input = System.in;\n PrintStream output = System.out;\n br = new BufferedReader(new InputStreamReader(input));\n out = new PrintWriter(output);\n solve();\n out.close();\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 static int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n static String nextToken() throws IOException {\n while (st == null || !st.hasMoreTokens()) {\n String line = br.readLine();\n if (line == null) {\n return null;\n }\n st = new StringTokenizer(line);\n }\n return st.nextToken();\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "dp", "bitmasks", "greedy", "implementation"], "code_uid": "60e6b542fadb178cc3fc8397371ccfee", "src_uid": "d90e99d539b16590c17328d79a5921e0", "difficulty": 1700.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 */\nimport java.util.*;\nimport java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n/**\n *\n * @author Admin\n */\npublic class Cf371A {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) throws IOException {\n // TODO code application logic here\n BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer st = new StringTokenizer(scan.readLine());\n long l1 = Long.parseLong(st.nextToken());\n long r1 = Long.parseLong(st.nextToken());\n long l2 = Long.parseLong(st.nextToken());\n long r2 = Long.parseLong(st.nextToken());\n long k = Long.parseLong(st.nextToken());\n long l = Math.max(l1, l2);\n long r = Math.min(r1, r2);\n if(l>r) System.out.println(\"0\");\n\telse{\n \tif(k>=l && k<=r) System.out.println(r-l);\n \telse System.out.println(r-l+1);\n\t}\n }\n \n}", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "64781cdb1368bf56496b62af30fae1e8", "src_uid": "9a74b3b0e9f3a351f2136842e9565a82", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "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 ProblemR {\n\n\tpublic static void main(String[] args) {\n\t\tInputReader in = new InputReader();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\n\t\tnew ProblemR().solve(in, out);\n\n\t\tout.close();\n\t}\n\n\tpublic void solve(InputReader in, PrintWriter out) {\n\t\tlong n = in.nextLong();\n\n\t\tn = n - n / 2 - n / 3 - n / 5 - n / 7 + n / 6 + n / 10 + n / 14 + n / 15 + n / 21 + n / 35 - n / (2 * 3 * 5) - n / (2 * 3 * 7) - n / (2 * 5 * 7) - n\n\t\t\t\t/ (3 * 5 * 7) + n / (2 * 3 * 5 * 7);\n\n\t\tout.println(n);\n\t}\n\n\tstatic class InputReader {\n\t\tpublic BufferedReader br;\n\t\tpublic StringTokenizer st;\n\n\t\tpublic InputReader() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\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\tst = 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 st.nextToken();\n\t\t}\n\n\t\tpublic int 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": ["math", "number theory"], "code_uid": "fdf22a057477fe1b293e2fc0e3294b03", "src_uid": "e392be5411ffccc1df50e65ec1f5c589", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class A104 {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tn = n - 10;\n\t\tif (n == 10) {\n\t\t\tSystem.out.println(\"15\");\n\t\t} else {\n\t\t\tif ((n <= 11) && (n >= 1)) {\n\t\t\t\tSystem.out.println(\"4\");\n\t\t\t} else {\n\t\t\t\tSystem.out.println(\"0\");\n\t\t\t}\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "d1c806fb61fcd191efd1c909b999a656", "src_uid": "5802f52caff6015f21b80872274ab16c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "\nimport java.io.PrintWriter;\nimport java.util.HashSet;\nimport java.util.Queue;\nimport java.util.Scanner;\nimport java.util.Set;\nimport java.util.concurrent.LinkedBlockingQueue;\n\npublic class C214 {\n int n;\n boolean room[][];\n boolean dep[][];\n int num[];\n int idx[];\n boolean visited[];\n int ans = Integer.MAX_VALUE;\n Set zeros;\n static int [][] pay;\n static {\n pay = new int[3][3];\n for( int i =0; i<3 ; i ++){\n pay[i][i] = 0;\n pay[i][(i+1)%3] = 1;\n pay[i][(i+2)%3] = 2;\n }\n }\n\n public void solve(Scanner cin , PrintWriter cout ){\n n = cin.nextInt();\n room = new boolean[3][n];\n dep = new boolean[n][n];\n num = new int[n];\n idx = new int[n];\n visited = new boolean[n];\n for( int i=0 ;i ();\n for( int i= 0;i bak_zeros = new HashSet(zeros);\n visited = new boolean[n];\n int [] bak_num = new int[n];\n for( int i=0;i= ans)\n return;\n if( zeros.size() == 0 ){\n if( cost < ans ) {\n ans = cost;\n }\n return;\n }\n Queue zs = new LinkedBlockingQueue();\n Set bak_zeros = new HashSet();\n \n for( int zero : zeros){\n if( idx[zero] == r) {\n zs.add(zero);\n bak_zeros.add(zero);\n }\n }\n while(!zs.isEmpty()) {\n int now = zs.poll();\n zeros.remove(now);\n cost ++ ;\n visited[now] = true;\n for( int i=0 ;i < n ; i ++) {\n if( !visited[i] && dep[now][i] && num[i] > 0) {\n num[i] -- ;\n if( num[i] == 0) {\n if( idx[i] == r ) {\n zs.add(i);\n } else{\n zeros.add(i);\n }\n }\n }\n }\n }\n if( zeros.size() == 0 ){\n if( cost < ans ) {\n ans = cost;\n }\n return ;\n }\n search((r+1)%3,cost + pay[r][(r+1)%3]);\n }\n\n public static void main (String [] args){\n C214 solution = new C214();\n Scanner cin = new Scanner(System.in);\n PrintWriter cout = new PrintWriter(System.out);\n solution.solve(cin, cout);\n cin.close();\n cout.close();\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "greedy"], "code_uid": "36b98975075f68c5eb5b0cf28733675f", "src_uid": "be42e213ff43e303e475d77a9560367f", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.lang.reflect.Array;\nimport java.util.*;\n\npublic class Main {\n\n\n public static int[] pref_f(String s) {\n int n = s.length();\n int[] pf = new int[n];\n for(int i = 1; i < n; i++){\n int j = pf[i-1];\n while (j > 0 && s.charAt(i) != s.charAt(j)){\n j = pf[j-1];\n }\n if (s.charAt(i) == s.charAt(j)) j++;\n pf[i] = j;\n }\n return pf;\n }\n\n public static void shortestPaths(List[] edges, int s, int[] d, int[] pred) {\n Arrays.fill(pred, -1);\n Arrays.fill(d, Integer.MAX_VALUE);\n d[s] = 0;\n PriorityQueue q = new PriorityQueue<>();\n q.add((long) s);\n while (!q.isEmpty()) {\n long cur = q.remove();\n int curu = (int) cur;\n if (cur >>> 32 != d[curu])\n continue;\n for (Edge e : edges[curu]) {\n int v = e.t;\n int nprio = d[curu] + e.cost;\n if (d[v] > nprio) {\n d[v] = nprio;\n pred[v] = curu;\n q.add(((long) nprio << 32) + v);\n }\n }\n }\n }\n\n public static class Edge {\n int t;\n int cost;\n\n public Edge(int t, int cost) {\n this.t = t;\n this.cost = cost;\n }\n }\n\n\n public static void main(String[] args) throws IOException {\n FastScanner in = new FastScanner(System.in);\n FastPrinter out = new FastPrinter(System.out);\n //FastScanner in = new FastScanner(new InputStreamReader(new FileInputStream(new File(\"strings.in\"))));\n //FastPrinter out = new FastPrinter(new OutputStreamWriter(new FileOutputStream(new File(\"strings.out\"))));\n ArrayList list = new ArrayList<>();\n int n = in.nextInt();\n int[] mas = new int[1000000];\n for(int i = 2; i < 1000000; i++){\n if(mas[i] == 0){\n list.add(i);\n long k = (long)i * (long)i;\n while (k < 1000000){\n mas[(int)k] = 1;\n k += i;\n }\n }\n }\n int r = n-1;\n int max = 0;\n for(int i = 0; i < list.size(); i++){\n if(list.get(i) > n) break;\n if(n % list.get(i) == 0){\n max = list.get(i);\n }\n }\n int l = (n-max) + 1;\n\n max = r;\n for(int i = l; i <= r; i++){\n if(mas[i] == 0) continue;\n int k1 = 0;\n int k2 = i;\n for(int j = 0; j < list.size(); j++){\n int p = list.get(j);\n\n if((long)p * p > k2) break;\n\n if(k2 % p == 0){\n k1 = p;\n while (k2 % p == 0) k2 /= p;\n }\n\n if(k2 == p) {k1 = 1; break;}\n }\n if(k2 > k1) k1 = k2;\n if((i - k1 + 1) < max) max = (i - k1 + 1);\n }\n System.out.println(max);\n out.close();\n }\n}\n\nclass FastPrinter {\n private final PrintWriter writer;\n\n public FastPrinter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public FastPrinter(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 public void println(double d) {\n writer.println(d);\n }\n\n public void println(String s) {\n writer.println(s);\n }\n\n public void println(String format, Object... args) {\n println(String.format(format, args));\n }\n\n public void println() {\n writer.println();\n }\n\n public void print(long i) {\n writer.print(i);\n }\n\n public void print(char c) {\n writer.print(c);\n }\n\n public void print(double d) {\n writer.print(d);\n }\n\n public void print(String s) {\n writer.print(s);\n }\n\n public void print(String format, Object... args) {\n print(String.format(format, args));\n }\n\n public void flush() {\n writer.flush();\n }\n}\n\nclass FastScanner {\n\n private BufferedReader reader;\n private StringTokenizer st;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private SpaceCharFilter filter;\n\n public FastScanner(InputStream stream) {\n this.reader = new BufferedReader(new InputStreamReader(stream));\n this.st = new StringTokenizer(\"\");\n }\n\n public FastScanner(InputStreamReader stream) {\n this.reader = new BufferedReader(stream);\n this.st = new StringTokenizer(\"\");\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 String next() {\n while (!st.hasMoreTokens()) {\n st = new StringTokenizer(readLine());\n }\n return st.nextToken();\n }\n\n public String nextLine() {\n st = new StringTokenizer(\"\");\n return readLine();\n }\n\n public String tryNextLine() {\n st = new StringTokenizer(\"\");\n return tryReadLine();\n }\n\n private String readLine() {\n String line = tryReadLine();\n if (line == null) throw new InputMismatchException();\n return line;\n }\n\n private String tryReadLine() {\n try {\n return reader.readLine();\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n }\n\n public int[] nextIntArray(int size) {\n int[] array = new int[size];\n for (int i = 0; i < size; i++)\n array[i] = nextInt();\n return array;\n }\n\n public int[][] nextIntTable(int rowCount, int columnCount) {\n int[][] table = new int[rowCount][];\n for (int i = 0; i < rowCount; i++)\n table[i] = nextIntArray(columnCount);\n return table;\n }\n\n public long[] nextLongArray(int size) {\n long[] array = new long[size];\n for (int i = 0; i < size; i++)\n array[i] = nextLong();\n return array;\n }\n\n public long[][] nextLongTable(int rowCount, int columnCount) {\n long[][] table = new long[rowCount][];\n for (int i = 0; i < rowCount; i++)\n table[i] = nextLongArray(columnCount);\n return table;\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 == '\\t' || isEOL(c);\n }\n\n public static boolean isEOL(int c) {\n return c == '\\n' || c == '\\r' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "number theory"], "code_uid": "c3e83bb855717b683fac3ce3f9c5afe9", "src_uid": "43ff6a223c68551eff793ba170110438", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "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 ky112233\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 ALoveA solver = new ALoveA();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class ALoveA {\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n String str = in.next();\n int n = str.length();\n int cnt = 0;\n for (int i = 0; i < n; i++) {\n if (str.charAt(i) == 'a') cnt++;\n }\n out.println(Math.min(n, 2 * cnt - 1));\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["strings", "implementation"], "code_uid": "7e47c3680ca01fa75790df75d8e01815", "src_uid": "84cb9ad2ae3ba7e912920d7feb4f6219", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.InputStream;\nimport java.util.NoSuchElementException;\nimport java.io.OutputStreamWriter;\nimport java.math.BigInteger;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.io.IOException;\nimport java.util.*;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Árysson Cavalcanti\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(), ret=n, x=n;\n for (int y=1; y<=n; y++) {\n if (1L*x*x+1L*y*y>1L*n*n) x--;\n while (1L*x*x+1L*y*y>1L*n*n) {\n x--;\n ret++;\n }\n }\n ret=n==0?1:4*ret;\n out.printLine(ret);\n }\n}\n\nclass InputReader {\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 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 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 \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 if (Character.isValidCodePoint(c))\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 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 String readLine(boolean ignoreEmptyLines) {\n if (ignoreEmptyLines)\n return readLine();\n else\n return readLine0();\n }\n\n public BigInteger readBigInteger() {\n try {\n return new BigInteger(readString());\n } catch (NumberFormatException e) {\n throw new InputMismatchException();\n }\n }\n\n public char readCharacter() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n return (char) c;\n }\n \n public double readDouble() {\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, readInt());\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, readInt());\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 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 readString();\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\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(char[] array) {\n writer.print(array);\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 print(int[] array) {\n for (int i = 0; i < array.length; i++) {\n if (i != 0)\n writer.print(' ');\n writer.print(array[i]);\n }\n }\n\n public void print(long[] array) {\n for (int i = 0; i < array.length; i++) {\n if (i != 0)\n writer.print(' ');\n writer.print(array[i]);\n }\n }\n \n public void printLine(int[] array) {\n print(array);\n writer.println();\n }\n\n public void printLine(long[] array) {\n print(array);\n writer.println();\n }\n\n public void printLine() {\n writer.println();\n }\n\n public void printLine(Object...objects) {\n print(objects);\n writer.println();\n }\n\n public void print(char i) {\n writer.print(i);\n }\n\n public void printLine(char i) {\n writer.println(i);\n }\n \n public void printLine(char[] array) {\n writer.println(array);\n }\n\n public void printFormat(String format, Object...objects) {\n writer.printf(format, objects);\n }\n\n public void close() {\n writer.close();\n }\n\n public void flush() {\n writer.flush();\n }\n\n public void print(long i) {\n writer.print(i);\n }\n\n public void printLine(long i) {\n writer.println(i);\n }\n\n public void print(int i) {\n writer.print(i);\n }\n\n public void printLine(int i) {\n writer.println(i);\n }\n}", "lang_cluster": "Java", "tags": ["math"], "code_uid": "7e175b2eee10aa4461b720fdb787e299", "src_uid": "d87ce09acb8401e910ca6ef3529566f4", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\n/**\n * @author: Mehul Raheja\n */\nimport java.util.*;\nimport java.io.*;\n\npublic class E {\n\n /*\n Runtime = O()\n */\n static int N, M, K;\n static String s;\n static StringTokenizer st;\n static int[] d;\n\n static long ans = 0;\n static long[] pre;\n \n static void dis(long N) {\n //System.out.println(N);\n if(N == 1){\n return;\n }\n long x = ((long)((Math.log(N-0.1))/Math.log(2)));\n //System.out.println(x);\n long low = (long)Math.pow(2, x);\n //System.out.println(low);\n ans += low;\n ans += pre[(int)x];\n dis(N-low);\n }\n\n public static void main(String[] args) throws Exception {\n pre = new long[50];\n pre[0] = 0;\n for (int i = 1; i < 50; i++) {\n pre[i] = pre[i-1] * 2 + (long)Math.pow(2, i-1);\n }\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n long N = Long.parseLong(br.readLine());\n dis(N);\n System.out.println(ans);\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "dp", "bitmasks", "graphs", "implementation"], "code_uid": "7410b2f8fdded242734afc9658f37f49", "src_uid": "a98f0d924ea52cafe0048f213f075891", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.Scanner;\n\n/**\n *\n * @author Alex\n */\npublic class PanoramixsPrediction {\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 int nextprime = 0;\n int i;\n switch (n) {\n case 2:\n nextprime=3;\n break;\n case 3:\n nextprime=5;\n break;\n default:\n for(i=n+2;i<50;i+=2){\n if(nextprime(i)){\n nextprime=i;\n break;\n }\n } break;\n }\n if(nextprime==m){\n System.out.println(\"YES\");\n }else{\n System.out.println(\"NO\");\n }\n }\n public static boolean nextprime(int x){\n int j;\n boolean status=true;\n if(x%2==0){\n return false;\n }else{\n for(j=3;j<=Math.sqrt(x);j+=2){\n if(x%j==0){\n status=false;\n break; \n }\n }\n \n }\n return status;\n }\n \n}", "lang_cluster": "Java", "tags": ["brute force"], "code_uid": "9a570b74cee53b2f4fdd92ed6467ef6a", "src_uid": "9d52ff51d747bb59aa463b6358258865", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class B{\r\n\tpublic static void main(String[] args)\r\n\t{\r\n\t\tFastScanner fs = new FastScanner();\r\n\t\tPrintWriter out = new PrintWriter(System.out);\r\n\t\tint n = fs.nextInt(); int mod = fs.nextInt();\r\n\t\tlong[] dp = new long[n+1];\r\n\t\tdp[1] = 1;long sum = 1;\r\n\t\tfor(int i=2;i<=n;i++)\r\n\t\t{\r\n\t\t dp[i] = sum;\r\n\t\t for(int left=2,right;left<=i;left=right+1)\r\n\t\t {\r\n\t\t right = (i/(i/left));\r\n\t\t dp[i] = (dp[i] + ((right-left+1)*dp[i/left])%mod)%mod;\r\n\t\t }\r\n\t\t sum = (sum+dp[i])%mod;\r\n\t\t}\r\n\t\tout.println(dp[n]);\r\n\t\tout.close();\t\t\r\n\t}\r\n\tstatic class FastScanner {\r\n\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\r\n\t\tStringTokenizer st=new StringTokenizer(\"\");\r\n\t\tString next() {\r\n\t\t\twhile (!st.hasMoreTokens())\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\treturn st.nextToken();\r\n\t\t}\r\n\t\t\r\n\t\tint nextInt() {\r\n\t\t\treturn Integer.parseInt(next());\r\n\t\t}\r\n\t\tint[] readArray(int n) {\r\n\t\t\tint[] a=new int[n];\r\n\t\t\tfor (int i=0; i temp = new ArrayList();\r\n\t\tfor(int i:arr)temp.add(i);\r\n\t\tCollections.sort(temp);\r\n\t\tint start = 0;\r\n\t\tfor(int i:temp)arr[start++]=i;\r\n\t\treturn arr;\r\n\t}\r\n\tpublic static String rev(String str)\r\n\t{\r\n\t\tchar[] arr = str.toCharArray();\r\n\t\tchar[] ret = new char[arr.length];\r\n\t\tint start = arr.length-1;\r\n\t\tfor(char i:arr)ret[start--] = i;\r\n\t\tString ret1 = \"\";\r\n\t\tfor(char ch:ret)ret1+=ch;\r\n\t\treturn ret1;\r\n\t}\r\n}", "lang_cluster": "Java", "tags": ["brute force", "math", "dp", "data structures", "number theory"], "code_uid": "9b3fd0295230cb6c7bca4fe6211c6aa8", "src_uid": "a524aa54e83fd0223489a19531bf0e79", "difficulty": 1700.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(),k=sc.nextInt();\n\t Vector v=new Vector<>();\n\t for(int i=2;i<=n;i++){\n\t if(prime(i))v.add(i);\n\t }\n\t Set set=new HashSet<>();\n\t for(int i=0;i b && c >= 0 || a < b && c <= 0){\n\t\tpw.print(\"NO\");\n\t\tpw.close();\n\t\treturn;\n\t}\n\tif(b - a == 0 || (b - a) % c == 0) {\n\t\tpw.println(\"YES\");\n\t}else{\n\t\tpw.print(\"NO\");\n\t}\n\tin.close();\n\tpw.close();\n\t}\n\n\tprivate static long nextLong() throws IOException {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tprivate static double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tprivate static int nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tprivate static String next() throws IOException {\n\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\treturn st.nextToken();\n\t}\n\n}\n\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "1fd9b06b851d9627b9e9e0527843e963", "src_uid": "9edf42c20ddf22a251b84553d7305a7d", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class C\n{\n public static void main(String[] strings) throws IOException\n {\n Scanner in = new Scanner(System.in);\n long c = in.nextInt();\n long hr = in.nextInt();\n long hb = in.nextInt();\n long wr = in.nextInt();\n long wb = in.nextInt();\n\n long res = Math.max(solve(c, hr, hb, wr, wb), solve(c, hb, hr, wb, wr));\n\n\n System.out.println(res);\n\n }\n\n private static long solve(long c, long hr, long hb, long wr, long wb)\n {\n long res = 0;\n long calc;\n for(int use = 0 ; use <= 1000000 + 13 ; use++)\n if(use*wr <= c)\n {\n calc = use*hr + ((c-use*wr)/wb)*hb;\n if(calc > res)\n res = calc;\n }\n\n return res;\n }\n}", "lang_cluster": "Java", "tags": ["math", "greedy", "brute force"], "code_uid": "0458735c2877d0e00f6c19d294624ed4", "src_uid": "eb052ca12ca293479992680581452399", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.InputStream;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n static Reader x;\n\n public Main(){\n x=new Reader();\n x.init(System.in);\n }\n\n public static void main(String[] args) throws IOException {\n Main o = new Main();\n\t // write your code here\n long n = x.nextInt();\n long k = x.nextInt();\n long A = x.nextInt();\n long B = x.nextInt();\n long count = dontcry(n,k,A,B,0);\n System.out.println(count);\n }\n\n public static long dontcry(long n, long k, long A, long B, long count){\n if(n==1)\n return count;\n else{\n if(k==1 || nk && n%k!=0){\n count+=(n%k)*A;\n n=n-(n%k);\n }\n else if(n%k==0){\n if(B<(n-(n/k))*A){\n count+=B;\n n=n/k;\n }\n else{\n count+=(n-1)*A;\n n=1;\n }\n }\n return dontcry(n, k, A, B, count);\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 /** 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 static double nextDouble() throws IOException {\n return Double.parseDouble( next() );\n }\n}\n", "lang_cluster": "Java", "tags": ["greedy", "dp"], "code_uid": "5ce5f18a5d64bcac2ded9357fbd3832d", "src_uid": "f838fae7c98bf51cfa0b9bd158650b10", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.util.InputMismatchException;\n\n\npublic class temp{\n\n\tpublic static void main(String[] args) {\n\t\tInputReader in = new InputReader(System.in);\n\t\tOutputWriter out = new OutputWriter(System.out);\n\t\tint n = in.readInt();\n\t\tint m = in.readInt();\n\t\tif(n == 1 || n == 3 || n == 5 || n == 7 || n == 8 || n == 10 || n == 12 ){\n\t\t\tif(m > 5){\n\t\t\t\tSystem.out.println(6);\n\t\t\t}else{\n\t\t\t\tSystem.out.println(5);\n\t\t\t}\n\t\t}else if(n == 2){\n\t\t\tif(m != 1){\n\t\t\t\tSystem.out.println(5);\n\t\t\t}else{\n\t\t\t\tSystem.out.println(4);\n\t\t\t}\n\t\t}else{\n\t\t\tif(m > 6){\n\t\t\t\tSystem.out.println(6);\n\t\t\t}else{\n\t\t\t\tSystem.out.println(5);\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t\tout.close();\n\t}\n\n\nprivate static 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 \n\t\tpublic InputReader(InputStream stream) {\n\t\t\tthis.stream = stream;\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 = 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 long readLong() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tlong 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 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 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\tstatic boolean isSpaceChar(int 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\treturn readString();\n\t\t}\n\t}\n \n\tprivate static class OutputWriter {\n\t\tprivate final PrintWriter writer;\n \n\t\tpublic OutputWriter(OutputStream outputStream) {\n\t\t\twriter = new PrintWriter(outputStream);\n\t\t}\n \n\t\tpublic OutputWriter(Writer writer) {\n\t\t\tthis.writer = new PrintWriter(writer);\n\t\t}\n \n\t\tpublic void print(Object... objects) {\n\t\t\tfor (int i = 0; i < objects.length; i++) {\n\t\t\t\tif (i != 0)\n\t\t\t\t\twriter.print(' ');\n\t\t\t\twriter.print(objects[i]);\n\t\t\t}\n\t\t}\n \n\t\tpublic void printLine(Object... objects) {\n\t\t\tprint(objects);\n\t\t\twriter.println();\n\t\t}\n \n\t\tpublic void close() {\n\t\t\twriter.close();\n\t\t}\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "bb44284f18190c689420ee915aa2562d", "src_uid": "5b969b6f564df6f71e23d4adfb2ded74", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class DigitSequence \n{\n\tpublic static void main(String[] args) \n\t{\n\t\tScanner sc=new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\tString s=\"\";\n\t\tint i=1;\n\t\tString s1=String.valueOf(i);\n\t\twhile(s.length()<=n)\n\t\t{\n\t\t\ts=s+s1;\n\t\t\ti++;\n\t\t\ts1=String.valueOf(i);\n\t\t}\n\t\t//System.out.println(s);\n\t\tSystem.out.println(s.charAt(n-1));\n\t}\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "5d97349cd570956ef421d684a07fae28", "src_uid": "1503d761dd4e129fb7c423da390544ff", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/**\n * Created by Kratos-Pavilion on 04-03-2018.\n *\n * @author Kratos-Pavilion\n * @Date 04-03-2018\n */\nimport java.util.Scanner;\nimport java.util.Arrays;\n\npublic class Subset {\n public static void main(String[] args) throws Exception {\n\n Scanner d = new Scanner(System.in);\n int n = d.nextInt();\n int dia = d.nextInt();\n int c = 0, count = 0;\n int arr[] = new int[n];\n\n for (int i = 0; i < n; i++) {\n arr[i] = d.nextInt();\n }\n Arrays.sort(arr);\n for (int i = 0; i < n; i++) {\n for (int j = i; j < n; j++) {\n if ((arr[j] - arr[i]) <= dia)\n c++;\n }\n count = Math.max(count, c);\n c = 0;\n }\n\n\n System.out.println(n-count);\n\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "sortings", "greedy"], "code_uid": "c561ca9e7298f2104b58808c85f1c1ef", "src_uid": "6bcb324c072f796f4d50bafea5f624b2", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.math.BigInteger;\nimport java.util.Scanner;\n\n\npublic class A {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n String n, m;\n n= in.next();\n m= in.next();\n \n BigInteger aux = new BigInteger(\"3\");\n //aux = aux.pow(Integer.parseInt(n));\n aux=aux.modPow(new BigInteger(n), new BigInteger(m));\n //aux=aux.subtract(BigInteger.ONE).mod(new BigInteger(m));\n if(aux.toString().equals(\"0\")){\n aux= new BigInteger(m);\n }\n aux = aux.subtract(BigInteger.ONE);\n System.out.println(aux);\n \n }\n\n}\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "a62868755237b0373599e14da468364d", "src_uid": "c62ad7c7d1ea7aec058d99223c57d33c", "difficulty": 1400.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 CodeChef {\n\n\tpublic static void main(String[] args) throws IOException,NumberFormatException{\n\t\ttry {\n\t\t\tFastScanner sc=new FastScanner();\n\t\t\tString s=sc.next();\n\t\t\tint num1=Integer.parseInt(s.substring(0,2));\n\t\t\tint num2=Integer.parseInt(s.substring(3));\n\t\t\tint q=num1;\n\t\t\tint temp=palindrome(num1);\n\t\t\t\n\t\t\t\tif(num1>=0&&num1<5)\n\t\t\t\t{ if(num2>=palindrome(num1))\n\t\t\t\t System.out.println(\"0\"+(num1+1)+\":\"+palindrome(num1+1));\n\t\t\t\t else \n \tSystem.out.println(\"0\"+(num1)+\":\"+palindrome(num1));\t\n\t\t\t\t}\n\t\t\t\telse if(num1==10) {\n\t\t\t\t\tif(num2>=palindrome(num1))\n\t\t\t\t\t\tSystem.out.println((num1+1)+\":\"+palindrome(num1+1));\n\t\t\t\t\telse\n\t\t\t\t\t\tSystem.out.println(num1+\":0\"+palindrome(num1));\n\t\t\t\t}\n\t\t\t\telse if(num1==20) {\n\t\t\t\t\tif(num2>=palindrome(num1))\n\t\t\t\t\t\tSystem.out.println((num1+1)+\":\"+palindrome(num1+1));\n\t\t\t\t\telse\n\t\t\t\t\t\tSystem.out.println(num1+\":0\"+palindrome(num1));\n\t\t\t\t}\n\t\t\t\telse if((num1>10&&num1<15)||(num1>20&&num1<=22)){\n\t\t\t\t\t if(num2>=palindrome(num1))\n\t\t\t\t\t\tSystem.out.println((num1+1)+\":\"+palindrome(num1+1));\n\t\t\t\t\t else\n\t\t\t\t\t\tSystem.out.println(num1+\":\"+palindrome(num1));\n\t\t\t\t\t\n\t\t\t\t\t} \n\t\t\t\t\telse {\n\t\t\t\t\t\tif(num1>=6&&num1<=9) {\n\t\t\t\t\t\t\tSystem.out.println(\"10:01\");\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if(num1==5) {\n\t\t\t\t\t\t\tif(num2>=palindrome(num1)) {\n\t\t\t\t\t\t\t\tSystem.out.println(\"10:01\");\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tSystem.out.println(\"05:50\");\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if(num1==15) {\n\t\t\t\t\t\t\tif(num2>=palindrome(num1)) {\n\t\t\t\t\t\t\t\tSystem.out.println(\"20:02\");\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tSystem.out.println(\"15:51\");\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if(num1>=16&&num1<=19) {\n\t\t\t\t\t\t\tSystem.out.println(\"20:02\");\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if(num1==23) {\n\t\t\t\t\t\t\tif(num2>=palindrome(num1)) {\n\t\t\t\t\t\t\t\tSystem.out.println(\"00:00\");\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tSystem.out.println(\"23:32\");\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t}\n\t\tcatch(Exception e) {\n\t\t\treturn ;\n\t\t}\n\n\t}\n\tpublic static int palindrome(int n) {\n\t\tint temp=n%10;\n\t\tn=n/10;\n\t\ttemp=(n%10)+(temp*10);\n\t\treturn temp;\n\t}\n\tpublic static 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 st=new StringTokenizer(br.readLine());\t\t\t\t \n } catch (IOException e) {}\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\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\t\n\t}\n}\n", "lang_cluster": "Java", "tags": ["strings", "implementation"], "code_uid": "51c0186bb899cfb1d804bf57058bde48", "src_uid": "158eae916daa3e0162d4eac0426fa87f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.io.IOException;\n\n\npublic class Translation {\n\n\t\n//\t\n//\tpublic static void main(String[] args) throws IOException {\n//\t\t//FastReader fr=new FastReader();\n//\t\t\n//\t\t//StringBuffer str1=new StringBuffer(fr.nextLine());\n//\t\tjava.io.BufferedReader br=new java.io.BufferedReader(new java.io.InputStreamReader(System.in));\n//\t\tStringBuffer str1=new StringBuffer(br.readLine());\n//\t\tString str2=br.readLine();\n//\t\t\n//\t\t\n//\t\tstr1.reverse();\n//\t\t//System.out.println(str1);\n//\t\tSystem.out.println(str1.toString().equals(str2)?\"YES\":\"NO\");\n// \n//\t}\n\t\n public String translate(String a, String b) {\n String yes = \"YES\";\n String no = \"NO\";\n if (!b.equals(new StringBuffer(a).reverse().toString())) {\n return \"NO\";\n } else {\n return \"YES\";\n \n }\n }\n \n public static void main(String[] args) throws IOException {\n Translation m = new Translation();\n String a ,b;\n java.io.BufferedReader r = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));\n a = r.readLine();\n b=r.readLine();\n System.out.println(m.translate(a,b));\n }\n}\n", "lang_cluster": "Java", "tags": ["strings", "implementation"], "code_uid": "6d04c5bbac1583afc143bb50f62ad90c", "src_uid": "35a4be326690b58bf9add547fb63a5a5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.lang.reflect.Field;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class codeforces implements Runnable {\n\n private BufferedReader br = null;\n private PrintWriter pw = null;\n private StringTokenizer stk = new StringTokenizer(\"\");\n\n public static void main(String[] args) {\n new Thread(new codeforces()).run();\n }\n\n public void run() { /*\n * try { // br = new BufferedReader(new\n * FileReader(\"input.txt\")); pw = new\n * PrintWriter(\"output.txt\"); } catch\n * (FileNotFoundException e) { e.printStackTrace(); }\n */\n br = new BufferedReader(new InputStreamReader(System.in));\n pw = new PrintWriter(new OutputStreamWriter(System.out));\n solver();\n pw.close();\n\n }\n\n private void nline() {\n try {\n if (!stk.hasMoreTokens())\n stk = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n throw new RuntimeException(\"KaVaBUnGO!!!\", e);\n }\n }\n\n private String nstr() {\n while (!stk.hasMoreTokens())\n nline();\n return stk.nextToken();\n }\n\n private int ni() {\n return Integer.valueOf(nstr());\n\n }\n\n private double nd() {\n return Double.valueOf(nstr());\n\n }\n\n String nextLine() {\n try {\n return br.readLine();\n } catch (IOException e) {\n }\n return null;\n }\n\n class Line {\n Line() {\n this.max = Integer.MIN_VALUE;\n this.min = Integer.MAX_VALUE;\n }\n\n void checkMax(int i) {\n max = Math.max(i, max);\n }\n\n void checkMin(int i) {\n min = Math.min(i, min);\n }\n\n int max, min;\n }\n\n class Point {\n int x, y;\n\n Point(int x, int y) {\n this.x = x;\n this.y = y;\n }\n }\n\n private void solver() {\n int n = ni()+1, p = 0;\n for(int i=0; i arr[i]){\n i++;\n }\n \n if(i == end)\n return \"YES\";\n else\n return \"NO\";\n }\n \n public static void main(String[] args) {\n \n int l ;\n Scanner s = new Scanner(System.in);\n l = s.nextInt();\n int[] arr = new int[l];\n \n \n for(int i= 0; i< l;i++){\n arr[i] = s.nextInt();\n }\n System.out.println(UnimodalArray.check(arr));\n \n }\n\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "06db63c4694e0ba59c18206cac487373", "src_uid": "5482ed8ad02ac32d28c3888299bf3658", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class A211 {\n\n public void solve() throws IOException {\n\n Scanner sc = new Scanner(System.in);\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter pw = new PrintWriter(System.out);\n\n char[] n = sc.nextLine().toCharArray();\n\n String s[] = new String[10];\n s[0] = \"O-|-OOOO\";\n s[1] = \"O-|O-OOO\";\n s[2] = \"O-|OO-OO\";\n s[3] = \"O-|OOO-O\";\n s[4] = \"O-|OOOO-\";\n s[5] = \"-O|-OOOO\";\n s[6] = \"-O|O-OOO\";\n s[7] = \"-O|OO-OO\";\n s[8] = \"-O|OOO-O\";\n s[9] = \"-O|OOOO-\";\n\n for (int i = n.length - 1; i >= 0; i--) {\n System.out.println(s[n[i]-48]);\n }\n\n\n }\n\n public static void main(String[] args) throws IOException {\n new A211().solve();\n\n }\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "7f78d738785bee574ccfc3b7a50d7da2", "src_uid": "c2e3aced0bc76b6484360563355d23a7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class F {\n\n public static void main(String[] args) {\n\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt(), k = sc.nextInt();\n char s[] = sc.next().toCharArray();\n String t = sc.next();\n char first = t.charAt(0);\n char second = t.charAt(1);\n\n int dp[][][] = new int[n+1][n+1][k+1];\n for(int i = 0; i < dp.length; i++)\n for(int x = 0; x < dp[0].length; x++)\n Arrays.fill(dp[i][x], Integer.MIN_VALUE);\n dp[0][0][0] = 0;\n\n int ans = 0;\n for(int i = 1; i <= n; i++)\n for(int c = 0; c <= i; c++) {\n for(int op = 0; op <= k; op++) {\n\n// System.out.printf(\"[start] i = %d, count = %d, op = %d -> %d\\n\", i, c, op, dp[i][c][op]);\n char cur = s[i-1];\n int e1 = cur == first ? 1 : 0;\n int e2 = cur == second ? c : 0;\n int same = first == second ? 1 : 0;\n int e12 = same == 1 && cur == first ? 1 : 0;\n// // we put 'first'\n if(c > 0 && op > 0)\n dp[i][c][op] = Math.max(dp[i][c][op], dp[i-1][c-1][op-1]);\n\n // then we put 'second'\n if(op > 0 && c - same >= 0)\n dp[i][c][op] = Math.max(dp[i][c][op], dp[i-1][c - same][op-1] + c - same);\n\n // or we leave it as it is\n if(c - e1 >= 0)\n dp[i][c][op] = Math.max(dp[i][c][op], dp[i-1][c - e1][op] + e2 - e12);\n\n// System.out.printf(\"[end] i = %d, count = %d, op = %d -> %d\\n\\n\", i, c, op, dp[i][c][op]);\n }\n }\n\n for(int x = 0; x <= n; x++)\n for(int op = 0; op <= k; op++) {\n int occ = dp[n][x][op];\n ans = Math.max(ans, occ);\n }\n System.out.println(ans);\n }\n}\n", "lang_cluster": "Java", "tags": ["strings", "dp"], "code_uid": "faa8afbfa13f8e4ca20e2b96fc265c2c", "src_uid": "9c700390ac13942cbde7c3428965b18a", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n/**\n * Created by s326lab on 18/11/2017.\n * http://codeforces.com/problemset/problem/876/A\n */\npublic class TripForMeal {\n private Scanner read = new Scanner(System.in);\n\n public static void main(String[] args) {\n TripForMeal p = new TripForMeal();\n byte eatVisit = p.readByte();\n byte a = p.readByte();\n byte b = p.readByte();\n byte c = p.readByte();\n int answer = p.tripForMeal(eatVisit, a, b, c);\n System.out.println(answer);\n }\n\n private int tripForMeal(byte n, byte a, byte b, byte c) {\n int result = 0;\n byte count = 0;\n if(n != 1)\n {\n if(a < b)\n {\n result += a;\n count = a;\n }\n else\n {\n result+= b;\n count = b;\n }\n }\n\n n-=1;\n\n while(n > 1)\n {\n n--;\n if(count == a)\n {\n if(a < c)\n {\n result += a;\n }\n else\n {\n result+= c;\n count = c;\n }\n\n }\n else if (count == b)\n {\n if(b < c)\n {\n result+=b;\n }\n else\n {\n result+= c;\n count = c;\n }\n }\n else if (count == c)\n {\n if(c < b)\n {\n result+=c;\n }\n else\n {\n result+= b;\n }\n\n }\n\n }\n return result;\n }//tripForMeal\n\n\n private byte readByte() {\n byte result = 0;\n try {\n while (result > 100 | result < 1) {\n result = Byte.parseByte(read.nextLine());\n if (result > 100 || result < 1) {\n System.out.println(\"Enter the value again.\");\n }\n }\n } catch (NumberFormatException e) {\n e.printStackTrace();\n }\n return result;\n }//readByte\n\n}//class\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "da8f6b89582a2972ab7f988ae6a39fb8", "src_uid": "6058529f0144c853e9e17ed7c661fc50", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class FindAmir\n{\n public static void main(String args[])\n {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int cnt = 0;\n for(int i=1;i!=(n/2+n%2);++i)\n cnt++;\n System.out.println(cnt);\n }\n}\n", "lang_cluster": "Java", "tags": ["constructive algorithms"], "code_uid": "2d796fd0dab50044bdacc4145cc71fe2", "src_uid": "dfe9446431325c73e88b58ba204d0e47", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n \npublic class Main\n{\n \n 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 ni() {\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 nl() {\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[] nia(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] = ni();\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic String rs() {\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\n\n\n\n public static void main(String[] args)\n {\n \n InputReader sc = new InputReader(System.in);\n PrintWriter w = new PrintWriter(System.out);\n int n = sc.ni();\n int k = sc.ni();\n int sum = 0;\n for(int i=1;i<=n;i++)\n {\n sum += sc.ni();\n }\n \n int c = 0;\n if(2*sum >= n*(2*k -1))\n {\n w.println(\"0\");\n \n }\n else\n w.println(2*k*n-n-2*sum);\n \n /*\n int x = sc.ni();\n int y = sc.ni();\n String [][]arr = new String[x+2][y+2];\n for(int i=1;i<=x;i++)\n {\n for(int j=1;j<=y;j++)\n {\n arr[i][j] = sc.rs();\n }\n }\n int c = 0;\n for(int i=1;i<=x;i++)\n {\n for(int j=1;j<=y;j++)\n {\n if(arr[i][j].equals(\"S\"))\n {\n if(arr[i-1][j].equals(\"W\") ||arr[i+1][j].equals(\"W\")||arr[i][j-1].equals(\"W\")||arr[i][j+1].equals(\"W\"))\n c++;\n }\n }\n }\n if(c != 0)\n w.println(\"No\");\n else\n {\n for(int i=1;i<=x;i++)\n {\n for(int j=1;j<=y;j++)\n {\n if(arr[i][j].equals(\"S\"))\n {\n if(arr[i-1][j].equals(\".\"))\n arr[i-1][j].replace(\".\",\"D\");\n \n if(arr[i+1][j].equals(\".\"))\n arr[i+1][j].replace(\".\",\"D\");\n \n if(arr[i][j+1].equals(\".\"))\n arr[i][j+1].replace(\".\",\"D\");\n \n if(arr[i][j-1].equals(\".\"))\n arr[i][j-1].replace(\".\",\"D\");\n \n \n }\n }\n }\n w.println(\"Yes\");\n \n for(int i=1;i<=x;i++)\n {\n for(int j=1;j<=y;j++)\n {\n w.print(arr[i][j]);\n \n }\n w.println();\n }\n }\n \n */\n \n \n /*\n 118B\n int x = sc.ni();\n int res = x*2;\n String [][]arr = new String[res+ 1][res+1];\n \n for(int i=0;i<=x*2;i++)\n {\n for(int j=x-i;j<=x+i;j++)\n {\n if(j <= x)\n arr[i][j] = ips(i+j-x);\n else\n arr[i][j] = ips(2*x -i - j);\n \n }\n \n }\n for(int i=0;i<=x*2;i++)\n {\n for(int j=0;j<=x*2;j++)\n {\n w.print(arr[i][j] + \" \");\n \n }\n w.println();\n }\n */\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n w.close();\n \n\n \n } \n /*\n static boolean is(int p,int x,int y)\n {\n int flag = 0;\n \n for(int j=2;j<=p;j++)\n {\n if(x % j == 0)\n {\n flag = 1;\n break;\n }\n else \n continue;\n \n }\n \n if(flag == 1)\n return false;\n else\n return true;\n \n }\n */\n static int binarysearch(int []arr,int p,int n)\n {\n \n int st = 0;\n int end = n-1;\n int mid = (st + end)/2;\n int temp = 0;\n while(st < end)\n { \n mid = (st + end)/2;\n \n if(p > arr[mid])\n {\n st = mid+1;\n \n }\n else if(p < arr[mid])\n {\n end = mid;\n \n }\n else if(p == arr[mid])\n {\n temp = mid;\n break;\n }\n \n \n \n }\n if(st == end)\n temp = st;\n \n return temp;\n }\n \n \n static class Student\n {\n \n int floor;\n int time;\n Student(int floor,int time)\n {\n this.floor = floor;\n this.time = time;\n \n \n }\n \n }\n static int lis(int arr[],int n)\n {\n int lis[] = new int[n];\n int i,j,max = 0;\n \n /* Initialize LIS values for all indexes */\n for ( i = 0; i < n; i++ )\n lis[i] = 1;\n \n /* Compute optimized LIS values in bottom up manner */\n for ( i = 1; i < n; i++ )\n for ( j = 0; j < i; j++ ) \n if ( arr[i] > arr[j] && lis[i] <= lis[j])\n lis[i]++;\n \n /* Pick maximum of all LIS values */\n for ( i = 0; i < n; i++ )\n if ( max < lis[i] )\n max = lis[i];\n \n return max;\n }\n \n \n public static int ip(String s){\n\t\treturn Integer.parseInt(s);\n\t}\n\t public static String ips(int s){\n\t\treturn Integer.toString(s);\n\t}\n\t\n \n\t\t\t\t\t \n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "09ef144153327d93537a11cb99a0567b", "src_uid": "f22267bf3fad0bf342ecf4c27ad3a900", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.util.InputMismatchException;\n\npublic class problemB1 {\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tScan in = new Scan(System.in);\n\t\tint n = in.scanInt();\n\t\tint[] freq = new int[6];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfreq[in.scanInt()]++;\n\t\t}\n\t\tdouble res = 0;\n\n\t\tfor (int i = 0; i < freq.length; i++) {\n\t\t\tres += (freq[i] * i);\n\t\t}\n\t\tint count = 0;\n\t\tdouble f = res / n;\n\t\tif (f >= 4.50) {\n\t\t\tSystem.out.println(0);\n\t\t} else {\n\t\t\twhile (freq[2] != 0) {\n\t\t\t\tres += 3;\n\t\t\t\tcount++;\n\t\t\t\tf = res / n;\n\t\t\t\tif (f >= 4.50) {\n\t\t\t\t\tSystem.out.println(count);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tfreq[2]--;\n\t\t\t}\n\n\t\t\twhile (freq[3] != 0) {\n\t\t\t\tres += 2;\n\t\t\t\tcount++;\n\t\t\t\tf = res / n;\n\t\t\t\tif (f >= 4.50) {\n\t\t\t\t\tSystem.out.println(count);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tfreq[3]--;\n\t\t\t}\n\n\t\t\twhile (freq[4] != 0) {\n\t\t\t\tres += 1;\n\t\t\t\tcount++;\n\t\t\t\tf = res / n;\n\t\t\t\tif (f >= 4.50) {\n\t\t\t\t\tSystem.out.println(count);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tfreq[4]--;\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic class Scan {\n\t\tprivate InputStream in;\n\t\tprivate byte[] buf = new byte[1024 * 1024];\n\t\tprivate int index;\n\t\tprivate int total;\n\n\t\tpublic Scan(InputStream in) {\n\t\t\tthis.in = in;\n\t\t}\n\n\t\tpublic int scan() throws IOException {\n\t\t\tif (total < 0)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (index >= total) {\n\t\t\t\tindex = 0;\n\t\t\t\ttotal = in.read(buf);\n\t\t\t\tif (total <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[index++];\n\t\t}\n\n\t\tpublic int scanInt() throws IOException {\n\t\t\tint integer = 0;\n\t\t\tint n = scan();\n\t\t\twhile (isWhiteSpace(n))\n\t\t\t\tn = scan();\n\t\t\tint neg = 1;\n\t\t\tif (n == '-') {\n\t\t\t\tneg = -1;\n\t\t\t\tn = scan();\n\t\t\t}\n\t\t\twhile (!isWhiteSpace(n)) {\n\t\t\t\tif (n >= '0' && n <= '9') {\n\t\t\t\t\tinteger *= 10;\n\t\t\t\t\tinteger += n - '0';\n\t\t\t\t\tn = scan();\n\t\t\t\t} else\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\treturn neg * integer;\n\t\t}\n\n\t\tpublic long scanLong() throws IOException {\n\t\t\tlong integer = 0;\n\t\t\tint n = scan();\n\t\t\twhile (isWhiteSpace(n))\n\t\t\t\tn = scan();\n\t\t\tint neg = 1;\n\t\t\tif (n == '-') {\n\t\t\t\tneg = -1;\n\t\t\t\tn = scan();\n\t\t\t}\n\t\t\twhile (!isWhiteSpace(n)) {\n\t\t\t\tif (n >= '0' && n <= '9') {\n\t\t\t\t\tinteger *= 10;\n\t\t\t\t\tinteger += n - '0';\n\t\t\t\t\tn = scan();\n\t\t\t\t} else\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\treturn neg * integer;\n\t\t}\n\n\t\tpublic double scanDouble() throws IOException {\n\t\t\tdouble doub = 0;\n\t\t\tint n = scan();\n\t\t\twhile (isWhiteSpace(n))\n\t\t\t\tn = scan();\n\t\t\tint neg = 1;\n\t\t\tif (n == '-') {\n\t\t\t\tneg = -1;\n\t\t\t\tn = scan();\n\t\t\t}\n\t\t\twhile (!isWhiteSpace(n) && n != '.') {\n\t\t\t\tif (n >= '0' && n <= '9') {\n\t\t\t\t\tdoub *= 10;\n\t\t\t\t\tdoub += n - '0';\n\t\t\t\t\tn = scan();\n\t\t\t\t} else\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (n == '.') {\n\t\t\t\tn = scan();\n\t\t\t\tdouble temp = 1;\n\t\t\t\twhile (!isWhiteSpace(n)) {\n\t\t\t\t\tif (n >= '0' && n <= '9') {\n\t\t\t\t\t\ttemp /= 10;\n\t\t\t\t\t\tdoub += (n - '0') * temp;\n\t\t\t\t\t\tn = scan();\n\t\t\t\t\t} else\n\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn doub * neg;\n\t\t}\n\n\t\tpublic String scanString() throws IOException {\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\tint n = scan();\n\t\t\twhile (isWhiteSpace(n))\n\t\t\t\tn = scan();\n\t\t\twhile (!isWhiteSpace(n)) {\n\t\t\t\tsb.append((char) n);\n\t\t\t\tn = scan();\n\t\t\t}\n\t\t\treturn sb.toString();\n\t\t}\n\n\t\tprivate boolean isWhiteSpace(int n) {\n\t\t\tif (n == ' ' || n == '\\n' || n == '\\r' || n == '\\t' || n == -1)\n\t\t\t\treturn true;\n\t\t\treturn false;\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["sortings", "greedy"], "code_uid": "aa1189f98e64a0edf0bb415e0353b252", "src_uid": "715608282b27a0a25b66f08574a6d5bd", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.io.*;\nimport java.util.StringTokenizer;\n\npublic class CF837_E_VasyasFunction {\n\n private static final long gcd(long a, long b) {\n return b == 0 ? a : gcd(b, a % b);\n }\n\n private static long f(long a, long b) {\n if (b == 0)\n return 0;\n long g = gcd(a, b);\n long min = Long.MAX_VALUE, divisor = g;\n for (long d = 1; d * d <= a; d++) {\n if (a % d == 0) {\n if (d > g && d % g == 0) {\n long x = (b % d) / g;\n if (min > x) {\n min = x;\n divisor = d;\n }\n }\n long otherDivisors = a / d;\n if (otherDivisors > g && otherDivisors % g == 0) {\n long x = (b % otherDivisors) / g;\n if (min > x) {\n min = x;\n divisor = otherDivisors;\n }\n }\n }\n }\n return divisor == g ? b / g : min + f(a, b - g * min);\n }\n\n public static void main(String[] args) throws IOException {\n MyScanner sc = new MyScanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n out.println(f(sc.nextLong(), sc.nextLong()));\n out.flush();\n out.close();\n }\n\n private static class MyScanner {\n StringTokenizer st;\n BufferedReader br;\n\n public MyScanner(InputStream s) {\n br = new BufferedReader(new InputStreamReader(s));\n }\n\n public MyScanner(String filename) throws IOException {\n br = new BufferedReader(new FileReader(new File(filename)));\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}\n", "lang_cluster": "Java", "tags": ["math", "implementation", "binary search"], "code_uid": "a34b2604d5f1a0d0474adde2972a313d", "src_uid": "ea92cd905e9725e7fcb87b9ed4f64c2e", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "//package CodeforcesProject;\n\nimport java.io.*;\nimport java.lang.*;\nimport java.util.*;\nimport java.util.function.BiFunction;\n\npublic class Main extends IO {\n\n public static void main(String[] args) throws Exception {\n int g = readInt();\n int sh = readInt();\n int j = readInt();\n int p = readInt();\n int priceFirst = readInt();\n int priceSecond = readInt();\n long answer = 0;\n if (priceFirst <= priceSecond){\n answer = Math.min(Math.min(sh, j), p);\n p -= answer;\n answer *= priceSecond;\n answer += (Math.min(p, g) * priceFirst);\n }\n else{\n answer = Math.min(g, p);\n p -= answer;\n answer *= priceFirst;\n answer += (Math.min(Math.min(sh, j), p) * priceSecond);\n }\n System.out.println(answer);\n }\n}\n\nclass math {\n\n protected static int remains = 0x989687;\n\n protected static int gcd(int a, int b) { // NOD\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n protected static long gcd(long a, long b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n protected static float gcd(float a, float b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n protected static double gcd(double a, double b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n protected static double lcm(double a, double b) { // NOK\n return a / gcd(a, b) * b;\n }\n\n protected static float lcm(float a, float b) { // NOK\n return a / gcd(a, b) * b;\n }\n\n protected static int lcm(int a, int b) { // NOK\n return a / gcd(a, b) * b;\n }\n\n protected static long lcm(long a, long b) {\n return a / gcd(a, b) * b;\n }\n\n protected static double log(double value, int base) {\n return Math.log(value) / Math.log(base);\n }\n\n protected static long factorial(int number) {\n if (number < 0) {\n return 0;\n }\n return solveFactorial(number);\n }\n\n private static long solveFactorial(int number) {\n if (number > 0) {\n return solveFactorial(number - 1) * number;\n }\n return 1;\n }\n}\n\nclass Int implements Comparable {\n\n protected int value;\n\n Int(int value) {\n this.value = value;\n }\n\n @Override\n public int compareTo(Integer o) {\n return (this.value < o) ? -1 : ((this.value == o) ? 0 : 1);\n }\n\n @Override\n public boolean equals(Object obj) {\n if (obj instanceof Integer) {\n return value == (Integer) obj;\n }\n return false;\n }\n\n @Override\n public int hashCode() {\n return value;\n }\n\n @Override\n protected void finalize() throws Throwable {\n super.finalize();\n }\n}\n\nclass Fraction extends Pair {\n\n private Fraction(T dividend, T divider) {\n super(dividend, divider);\n reduce();\n }\n\n protected static Fraction createFraction(T dividend, T divider) {\n return new Fraction<>(dividend, divider);\n }\n\n protected void reduce() {\n if (getFirstElement() instanceof Integer) {\n Integer Dividend = (Integer) getFirstElement();\n Integer Divider = (Integer) getSecondElement();\n int gcd = math.gcd(Dividend, Divider);\n setFirst(Dividend / gcd);\n setSecond(Divider / gcd);\n } else if (getFirstElement() instanceof Long) {\n Long Dividend = (Long) getFirstElement();\n Long Divider = (Long) getSecondElement();\n long gcd = math.gcd(Dividend, Divider);\n setFirst(Dividend / gcd);\n setSecond(Divider / gcd);\n } else if (getFirstElement() instanceof Float) {\n Float Dividend = (Float) getFirstElement();\n Float Divider = (Float) getSecondElement();\n float gcd = math.gcd(Dividend, Divider);\n setFirst(Dividend / gcd);\n setSecond(Divider / gcd);\n } else if (getFirstElement() instanceof Double) {\n Double Dividend = (Double) getFirstElement();\n Double Divider = (Double) getSecondElement();\n double gcd = math.gcd(Dividend, Divider);\n setFirst(Dividend / gcd);\n setSecond(Divider / gcd);\n }\n }\n\n protected void addWithoutReturn(Fraction number) throws UnsupportedOperationException {\n add(number, 0);\n }\n\n private Fraction add(Fraction number, int function) throws UnsupportedOperationException {\n if (getFirstElement() instanceof Integer && number.getFirstElement() instanceof Integer) {\n Integer Dividend = (Integer) getFirstElement();\n Integer Divider = (Integer) getSecondElement();\n Integer Dividend1 = (Integer) number.getFirstElement();\n Integer Divider1 = (Integer) number.getSecondElement();\n Integer lcm = math.lcm(Divider, Divider1);\n if (function == 0) {\n setFirst((lcm / Divider) * Dividend + (lcm / Divider1) * Dividend1);\n setSecond(lcm);\n reduce();\n return null;\n }\n Fraction result = Fraction.createFraction((lcm / Divider) * Dividend + (lcm / Divider1) * Dividend1, lcm);\n result.reduce();\n return result;\n\n } else if (getFirstElement() instanceof Long && number.getFirstElement() instanceof Long) {\n Long Dividend = (Long) getFirstElement();\n Long Divider = (Long) getSecondElement();\n Long Dividend1 = (Long) number.getFirstElement();\n Long Divider1 = (Long) number.getSecondElement();\n Long lcm = math.lcm(Divider, Divider1);\n if (function == 0) {\n setFirst((lcm / Divider) * Dividend + (lcm / Divider1) * Dividend1);\n setSecond(lcm);\n reduce();\n return null;\n }\n Fraction result = Fraction.createFraction((lcm / Divider) * Dividend + (lcm / Divider1) * Dividend1, lcm);\n result.reduce();\n return result;\n } else if (getFirstElement() instanceof Float && number.getFirstElement() instanceof Float) {\n Float Dividend = (Float) getFirstElement();\n Float Divider = (Float) getSecondElement();\n Float Dividend1 = (Float) number.getFirstElement();\n Float Divider1 = (Float) number.getSecondElement();\n Float lcm = math.lcm(Divider, Divider1);\n if (function == 0) {\n setFirst((lcm / Divider) * Dividend + (lcm / Divider1) * Dividend1);\n setSecond(lcm);\n reduce();\n return null;\n }\n Fraction result = Fraction.createFraction((lcm / Divider) * Dividend + (lcm / Divider1) * Dividend1, lcm);\n result.reduce();\n return result;\n } else if (getFirstElement() instanceof Double && number.getFirstElement() instanceof Double) {\n Double Dividend = (Double) getFirstElement();\n Double Divider = (Double) getSecondElement();\n Double Dividend1 = (Double) number.getFirstElement();\n Double Divider1 = (Double) number.getSecondElement();\n Double lcm = math.lcm(Divider, Divider1);\n if (function == 0) {\n setFirst((lcm / Divider) * Dividend + (lcm / Divider1) * Dividend1);\n setSecond(lcm);\n reduce();\n return null;\n }\n Fraction result = Fraction.createFraction((lcm / Divider) * Dividend + (lcm / Divider1) * Dividend1, lcm);\n result.reduce();\n return result;\n } else {\n throw new UnsupportedOperationException();\n }\n }\n\n protected Fraction addWithReturn(Fraction number) {\n return add(number, 1);\n }\n\n protected void multiplyWithoutReturn(Fraction number) throws UnsupportedOperationException {\n multiply(number, 0);\n }\n\n protected Fraction multiplyWithReturn(Fraction number) throws UnsupportedOperationException {\n return multiply(number, 1);\n }\n\n private Fraction multiply(Fraction number, int function) throws UnsupportedOperationException {\n if (getFirstElement() instanceof Integer && number.getFirstElement() instanceof Integer) {\n Integer first = (Integer) getFirstElement() * (Integer) number.getFirstElement();\n Integer second = (Integer) getSecondElement() * (Integer) number.getSecondElement();\n if (function == 0) {\n setFirst(first);\n setSecond(second);\n reduce();\n return null;\n }\n Fraction answer = Fraction.createFraction(first, second);\n answer.reduce();\n return answer;\n } else if (getFirstElement() instanceof Long && number.getFirstElement() instanceof Long) {\n Long first = (Long) getFirstElement() * (Long) number.getFirstElement();\n Long second = (Long) getSecondElement() * (Long) number.getSecondElement();\n if (function == 0) {\n setFirst(first);\n setSecond(second);\n reduce();\n return null;\n }\n Fraction answer = Fraction.createFraction(first, second);\n answer.reduce();\n return answer;\n\n } else if (getFirstElement() instanceof Float && number.getFirstElement() instanceof Float) {\n Float first = (Float) getFirstElement() * (Float) number.getFirstElement();\n Float second = (Float) getSecondElement() * (Float) number.getSecondElement();\n if (function == 0) {\n setFirst(first);\n setSecond(second);\n reduce();\n return null;\n }\n Fraction answer = Fraction.createFraction(first, second);\n answer.reduce();\n return answer;\n } else if (getFirstElement() instanceof Double && number.getFirstElement() instanceof Double) {\n Double first = (Double) getFirstElement() * (Double) number.getFirstElement();\n Double second = (Double) getSecondElement() * (Double) number.getSecondElement();\n if (function == 0) {\n setFirst(first);\n setSecond(second);\n reduce();\n return null;\n }\n Fraction answer = Fraction.createFraction(first, second);\n answer.reduce();\n return answer;\n } else {\n throw new UnsupportedOperationException();\n }\n }\n}\n\nclass Pair implements Cloneable {\n\n private T first;\n private T1 second;\n\n Pair(T obj, T1 obj1) {\n first = obj;\n second = obj1;\n }\n\n protected static Pair createPair(T element, T1 element1) {\n return new Pair<>(element, element1);\n }\n\n protected T getFirstElement() {\n return first;\n }\n\n protected T1 getSecondElement() {\n return second;\n }\n\n protected void setFirst(T element) {\n first = element;\n }\n\n protected void setSecond(T1 element) {\n second = element;\n }\n\n @Override\n public boolean equals(Object obj) {\n if (!(obj instanceof Pair)) {\n return false;\n }\n Pair pair = (Pair) obj;\n return first.equals(pair.first) && second.equals(pair.second);\n }\n\n @Override\n public int hashCode() {\n int hashCode = 1;\n hashCode = 31 * hashCode + (first == null ? 0 : first.hashCode());\n return 31 * hashCode + (second == null ? 0 : second.hashCode());\n }\n\n @Override\n public Object clone() {\n return Pair.createPair(first, second);\n }\n}\n\nclass Graph {\n\n private int[][] base;\n private boolean[] used;\n private int quantity;\n private Integer[] ancestor;\n\n public int[][] getBase() {\n return base.clone();\n }\n\n public boolean[] getUsed() {\n return used.clone();\n }\n\n public int getQuantity() {\n return quantity;\n }\n\n public Integer[] getAncestor() {\n return ancestor.clone();\n }\n\n public void setBase(int[][] base) {\n this.base = base;\n }\n\n protected void start(int length) {\n used = new boolean[length];\n ancestor = new Integer[length];\n Arrays.fill(ancestor, -1);\n quantity = 0;\n }\n\n\n protected void edgesMatrixToDefault(int length, int quantity, boolean readConsole, int[][] value) throws Exception {\n base = new int[length][];\n List> inputBase = new ArrayList<>();\n for (int i = 0; i < length; i++) {\n inputBase.add(new ArrayList<>());\n }\n for (int i = 0; i < quantity; i++) {\n int[] input = readConsole ? IO.readArrayInt(\" \") : value[i];\n inputBase.get(input[0] - 1).add(input[1] - 1);\n //inputBase.get(input[0] - 1).add(input[2]); // price\n inputBase.get(input[1] - 1).add(input[0] - 1);\n //inputBase.get(input[1] - 1).add(input[2]); // price\n }\n for (int i = 0; i < length; i++) {\n base[i] = inputBase.get(i).stream().mapToInt(Integer::intValue).toArray();\n }\n start(length);\n }\n\n protected void adjacencyMatrixToDefault(int length, int not, boolean readConsole, int[][] value) throws Exception {\n this.base = new int[length][];\n List buffer = new ArrayList<>();\n for (int i = 0; i < length; i++) {\n int[] InputArray = readConsole ? IO.readArrayInt(\" \") : value[i];\n for (int index = 0; index < length; index++) {\n if (i != index && InputArray[index] != not) {\n buffer.add(index);\n // buffer.add(InputArray[index]); // price\n }\n }\n this.base[i] = buffer.stream().mapToInt(Integer::intValue).toArray();\n buffer.clear();\n }\n start(length);\n }\n\n protected void dfs(int position) throws Exception {\n used[position] = true;\n quantity++;\n int next;\n for (int index = 0; index < base[position].length; index++) {\n next = base[position][index];\n if (!used[next]) {\n ancestor[next] = position;\n dfs(next);\n } /*else {\n if (next != ancestor[position]) { // if cycle\n throw new Exception();\n }\n }*/\n }\n }\n\n protected int dijkstra(int start, int stop, int size) {\n start--;\n stop--;\n int[] dist = new int[size];\n for (int i = 0; i < size; i++) {\n if (i != start) {\n dist[i] = Integer.MAX_VALUE;\n }\n ancestor[i] = start;\n }\n\n Queue queue = new PriorityQueue<>(Comparator.comparingInt((int[] ints) -> ints[1]));\n queue.add(new int[]{start, 0});\n int position;\n int[] getQueue;\n while (queue.size() != 0) {\n getQueue = queue.poll();\n position = getQueue[0];\n if (getQueue[1] > dist[position]) {\n continue;\n }\n for (int index = 0; index < this.base[position].length; index += 2) {\n if (dist[position] + this.base[position][index + 1] < dist[this.base[position][index]] && !this.used[this.base[position][index]]) {\n dist[this.base[position][index]] = dist[position] + this.base[position][index + 1];\n this.ancestor[this.base[position][index]] = position;\n queue.add(new int[]{this.base[position][index], dist[this.base[position][index]]});\n }\n }\n used[position] = true;\n }\n return dist[stop] == Integer.MAX_VALUE ? -1 : dist[stop];\n }\n\n protected static boolean solveFloydWarshall(int[][] base, int length, int not) {\n for (int k = 0; k < length; k++) {\n for (int i = 0; i < length; i++) {\n for (int j = 0; j < length; j++) {\n if (base[i][k] == not || base[k][j] == not) {\n continue;\n }\n int total = base[i][k] + base[k][j];\n if (base[i][j] != not) {\n base[i][j] = Math.min(base[i][j], total);\n } else {\n base[i][j] = total;\n }\n }\n }\n }\n for (int index = 0; index < length; index++) {\n if (base[index][index] != 0) { // if cycle\n return false;\n }\n }\n return true;\n }\n\n protected static Pair solveKruskal(int[][] edgesMatrix, final int countVertex, final int indexSort) {\n int[][] answer = new int[countVertex - 1][2];\n long sum = 0;\n Arrays.sort(edgesMatrix, Comparator.comparingInt(value -> value[indexSort]));\n SystemOfDisjointSets dsu = new SystemOfDisjointSets(countVertex);\n for (int i = 0; i < countVertex; i++) {\n dsu.makeSet(i);\n }\n int index = 0;\n for (int[] value : edgesMatrix) {\n if (dsu.mergeSets(value[0], value[1])) {\n sum += value[indexSort];\n answer[index] = new int[]{value[0], value[1]};\n index++;\n }\n }\n if (index < countVertex - 1) {\n return Pair.createPair(null, null);\n }\n return Pair.createPair(sum, answer);\n }\n\n static class SegmentTree {\n\n private int[] segmentArray;\n private BiFunction function;\n\n protected void setSegmentArray(int[] segmentArray) {\n this.segmentArray = segmentArray;\n }\n\n protected int[] getSegmentArray() {\n return segmentArray.clone();\n }\n\n protected void setFunction(BiFunction function) {\n this.function = function;\n }\n\n protected BiFunction getFunction() {\n return function;\n }\n\n SegmentTree() {\n\n }\n\n SegmentTree(int[] startBase, int neutral, BiFunction function) {\n this.function = function;\n int length = startBase.length;\n int[] base;\n if ((length & (length - 1)) != 0) {\n int pow = 0;\n while (length > 0) {\n length >>= 1;\n pow++;\n }\n pow--;\n base = new int[2 << pow];\n System.arraycopy(startBase, 0, base, 0, startBase.length);\n Arrays.fill(base, startBase.length, base.length, neutral);\n\n } else {\n base = startBase;\n }\n segmentArray = new int[base.length << 1]; // maybe * 4\n Arrays.fill(segmentArray, neutral);\n inDepth(base, 1, 0, base.length - 1);\n }\n\n private void inDepth(int[] base, int position, int low, int high) {\n if (low == high) {\n segmentArray[position] = base[low];\n } else {\n int mid = (low + high) >> 1;\n inDepth(base, position << 1, low, mid);\n inDepth(base, (position << 1) + 1, mid + 1, high);\n segmentArray[position] = function.apply(segmentArray[position << 1], segmentArray[(position << 1) + 1]);\n }\n }\n\n protected int getValue(int left, int right, int neutral) {\n return findValue(1, 0, ((segmentArray.length) >> 1) - 1, left, right, neutral);\n }\n\n private int findValue(int position, int low, int high, int left, int right, int neutral) {\n if (left > right) {\n return neutral;\n }\n if (left == low && right == high) {\n return segmentArray[position];\n }\n int mid = (low + high) >> 1;\n return function.apply(findValue(position << 1, low, mid, left, Math.min(right, mid), neutral),\n findValue((position << 1) + 1, mid + 1, high, Math.max(left, mid + 1), right, neutral));\n }\n\n protected void replaceValue(int index, int value) {\n update(1, 0, (segmentArray.length >> 1) - 1, index, value);\n }\n\n private void update(int position, int low, int high, int index, int value) {\n if (low == high) {\n segmentArray[position] = value;\n } else {\n int mid = (low + high) >> 1;\n if (index <= mid) {\n update(position << 1, low, mid, index, value);\n } else {\n update((position << 1) + 1, mid + 1, high, index, value);\n }\n segmentArray[position] = function.apply(segmentArray[position << 1], segmentArray[(position << 1) + 1]);\n }\n }\n }\n\n static class SegmentTreeGeneric {\n\n private Object[] segmentArray;\n private BiFunction function;\n\n protected void setSegmentArray(T[] segmentArray) {\n this.segmentArray = segmentArray;\n }\n\n protected Object getSegmentArray() {\n return segmentArray.clone();\n }\n\n protected void setFunction(BiFunction function) {\n this.function = function;\n }\n\n protected BiFunction getFunction() {\n return function;\n }\n\n SegmentTreeGeneric() {\n\n }\n\n SegmentTreeGeneric(T[] startBase, T neutral, BiFunction function) {\n this.function = function;\n int length = startBase.length;\n Object[] base;\n if ((length & (length - 1)) != 0) {\n int pow = 0;\n while (length > 0) {\n length >>= 1;\n pow++;\n }\n pow--;\n base = new Object[2 << pow];\n System.arraycopy(startBase, 0, base, 0, startBase.length);\n Arrays.fill(base, startBase.length, base.length, neutral);\n\n } else {\n base = startBase;\n }\n segmentArray = new Object[base.length << 1]; // maybe * 4\n Arrays.fill(segmentArray, neutral);\n inDepth(base, 1, 0, base.length - 1);\n }\n\n private void inDepth(Object[] base, int position, int low, int high) {\n if (low == high) {\n segmentArray[position] = base[low];\n } else {\n int mid = (low + high) >> 1;\n inDepth(base, position << 1, low, mid);\n inDepth(base, (position << 1) + 1, mid + 1, high);\n segmentArray[position] = function.apply((T) segmentArray[position << 1], (T) segmentArray[(position << 1) + 1]);\n }\n }\n\n protected T getValue(int left, int right, T neutral) {\n return findValue(1, 0, ((segmentArray.length) >> 1) - 1, left, right, neutral);\n }\n\n private T findValue(int position, int low, int high, int left, int right, T neutral) {\n if (left > right) {\n return neutral;\n }\n if (left == low && right == high) {\n return (T) segmentArray[position];\n }\n int mid = (low + high) >> 1;\n return function.apply(findValue(position << 1, low, mid, left, Math.min(right, mid), neutral),\n findValue((position << 1) + 1, mid + 1, high, Math.max(left, mid + 1), right, neutral));\n }\n\n protected void replaceValue(int index, T value) {\n update(1, 0, (segmentArray.length >> 1) - 1, index, value);\n }\n\n private void update(int position, int low, int high, int index, T value) {\n if (low == high) {\n segmentArray[position] = value;\n } else {\n int mid = (low + high) >> 1;\n if (index <= mid) {\n update(position << 1, low, mid, index, value);\n } else {\n update((position << 1) + 1, mid + 1, high, index, value);\n }\n segmentArray[position] = function.apply((T) segmentArray[position << 1], (T) segmentArray[(position << 1) + 1]);\n }\n }\n }\n}\n\nclass SystemOfDisjointSets {\n\n private int[] rank;\n private int[] ancestor;\n\n SystemOfDisjointSets(int size) {\n this.rank = new int[size];\n this.ancestor = new int[size];\n }\n\n protected void makeSet(int value) {\n ancestor[value] = value;\n rank[value] = 0;\n }\n\n protected int findSet(int value) {\n if (value == ancestor[value]) {\n return value;\n }\n return ancestor[value] = findSet(ancestor[value]);\n }\n\n protected boolean mergeSets(int first, int second) {\n first = findSet(first);\n second = findSet(second);\n if (first != second) {\n if (rank[first] < rank[second]) {\n int number = first;\n first = second;\n second = number;\n }\n ancestor[second] = first;\n if (rank[first] == rank[second]) {\n rank[first]++;\n }\n return true;\n }\n return false;\n }\n}\n\ninterface Array {\n void useArray(int[] a);\n}\n\ninterface Method {\n void use();\n}\n\nclass FastSort {\n\n protected static int[] sort(int[] array, int ShellHeapMergeMyInsertionSort) {\n sort(array, ShellHeapMergeMyInsertionSort, array.length);\n return array;\n }\n\n protected static int[] sortClone(int[] array, int ShellHeapMergeMyInsertionSort) {\n int[] base = array.clone();\n sort(base, ShellHeapMergeMyInsertionSort, array.length);\n return base;\n }\n\n private static void sort(int[] array, int ShellHeapMergeMyInsertionSort, int length) {\n if (ShellHeapMergeMyInsertionSort < 0 || ShellHeapMergeMyInsertionSort > 4) {\n Random random = new Random();\n ShellHeapMergeMyInsertionSort = random.nextInt(4);\n }\n if (ShellHeapMergeMyInsertionSort == 0) {\n ShellSort(array);\n } else if (ShellHeapMergeMyInsertionSort == 1) {\n HeapSort(array);\n } else if (ShellHeapMergeMyInsertionSort == 2) {\n MergeSort(array, 0, length - 1);\n } else if (ShellHeapMergeMyInsertionSort == 3) {\n straightMergeSort(array, length);\n } else if (ShellHeapMergeMyInsertionSort == 4) {\n insertionSort(array);\n }\n }\n\n private static void straightMergeSort(int[] array, int size) {\n if (size == 0) {\n return;\n }\n int length = (size >> 1) + ((size % 2) == 0 ? 0 : 1);\n Integer[][] ZeroBuffer = new Integer[length + length % 2][2];\n Integer[][] FirstBuffer = new Integer[0][0];\n for (int index = 0; index < length; index++) {\n int ArrayIndex = index << 1;\n int NextArrayIndex = (index << 1) + 1;\n if (NextArrayIndex < size) {\n if (array[ArrayIndex] > array[NextArrayIndex]) {\n ZeroBuffer[index][0] = array[NextArrayIndex];\n ZeroBuffer[index][1] = array[ArrayIndex];\n } else {\n ZeroBuffer[index][0] = array[ArrayIndex];\n ZeroBuffer[index][1] = array[NextArrayIndex];\n }\n } else {\n ZeroBuffer[index][0] = array[ArrayIndex];\n }\n }\n boolean position = false;\n int pointer0, pointer, pointer1, number = 4, NewPointer, count;\n Integer[][] NewBuffer;\n Integer[][] OldBuffer;\n length = (size >> 2) + ((size % 4) == 0 ? 0 : 1);\n while (true) {\n pointer0 = 0;\n count = (number >> 1) - 1;\n if (!position) {\n FirstBuffer = new Integer[length + length % 2][number];\n NewBuffer = FirstBuffer;\n OldBuffer = ZeroBuffer;\n } else {\n ZeroBuffer = new Integer[length + length % 2][number];\n NewBuffer = ZeroBuffer;\n OldBuffer = FirstBuffer;\n }\n for (int i = 0; i < length; i++) {\n pointer = 0;\n pointer1 = 0;\n NewPointer = pointer0 + 1;\n if (length == 1) {\n for (int g = 0; g < size; g++) {\n if (pointer > count || OldBuffer[pointer0][pointer] == null) {\n array[g] = OldBuffer[NewPointer][pointer1];\n pointer1++;\n } else if (pointer1 > count || OldBuffer[NewPointer][pointer1] == null) {\n if (OldBuffer[pointer0][pointer] == null) {\n continue;\n }\n array[g] = OldBuffer[pointer0][pointer];\n pointer++;\n } else if (OldBuffer[pointer0][pointer] >= OldBuffer[NewPointer][pointer1]) {\n array[g] = OldBuffer[NewPointer][pointer1];\n pointer1++;\n } else {\n array[g] = OldBuffer[pointer0][pointer];\n pointer++;\n }\n }\n return;\n }\n for (int g = 0; g < number; g++) {\n if (pointer > count || OldBuffer[pointer0][pointer] == null) {\n if (OldBuffer[NewPointer][pointer1] == null) {\n continue;\n }\n NewBuffer[i][g] = OldBuffer[NewPointer][pointer1];\n pointer1++;\n } else if (pointer1 > count || OldBuffer[NewPointer][pointer1] == null) {\n if (OldBuffer[pointer0][pointer] == null) {\n continue;\n }\n NewBuffer[i][g] = OldBuffer[pointer0][pointer];\n pointer++;\n } else if (OldBuffer[pointer0][pointer] >= OldBuffer[NewPointer][pointer1]) {\n NewBuffer[i][g] = OldBuffer[NewPointer][pointer1];\n pointer1++;\n } else {\n NewBuffer[i][g] = OldBuffer[pointer0][pointer];\n pointer++;\n }\n }\n pointer0 += 2;\n }\n position = !position;\n length = (length >> 1) + length % 2;\n number <<= 1;\n }\n }\n\n private static void ShellSort(int[] array) {\n int j;\n for (int gap = (array.length >> 1); gap > 0; gap >>= 1) {\n for (int i = gap; i < array.length; i++) {\n int temp = array[i];\n for (j = i; j >= gap && array[j - gap] > temp; j -= gap) {\n array[j] = array[j - gap];\n }\n array[j] = temp;\n }\n }\n }\n\n private static void HeapSort(int[] array) {\n for (int i = (array.length >> 1) - 1; i >= 0; i--)\n shiftDown(array, i, array.length);\n for (int i = array.length - 1; i > 0; i--) {\n swap(array, 0, i);\n shiftDown(array, 0, i);\n }\n }\n\n private static void shiftDown(int[] array, int i, int n) {\n int child;\n int tmp;\n for (tmp = array[i]; leftChild(i) < n; i = child) {\n child = leftChild(i);\n if (child != n - 1 && (array[child] < array[child + 1]))\n child++;\n if (tmp < array[child])\n array[i] = array[child];\n else\n break;\n }\n array[i] = tmp;\n }\n\n private static int leftChild(int i) {\n return (i << 1) + 1;\n }\n\n private static void swap(int[] array, int i, int j) {\n int temp = array[i];\n array[i] = array[j];\n array[j] = temp;\n }\n\n private static void MergeSort(int[] array, int low, int high) {\n if (low < high) {\n int mid = (low + high) >> 1;\n MergeSort(array, low, mid);\n MergeSort(array, mid + 1, high);\n merge(array, low, mid, high);\n }\n }\n\n private static void merge(int[] array, int low, int mid, int high) {\n int n = high - low + 1;\n int[] Temp = new int[n];\n int i = low, j = mid + 1;\n int k = 0;\n while (i <= mid || j <= high) {\n if (i > mid)\n Temp[k++] = array[j++];\n else if (j > high)\n Temp[k++] = array[i++];\n else if (array[i] < array[j])\n Temp[k++] = array[i++];\n else\n Temp[k++] = array[j++];\n }\n for (j = 0; j < n; j++)\n array[low + j] = Temp[j];\n }\n\n private static void insertionSort(int[] elements) {\n for (int i = 1; i < elements.length; i++) {\n int key = elements[i];\n int j = i - 1;\n while (j >= 0 && key < elements[j]) {\n elements[j + 1] = elements[j];\n j--;\n }\n elements[j + 1] = key;\n }\n }\n}\n\nclass IO {\n\n private static BufferedReader read;\n private static boolean fileInput = false;\n private static BufferedWriter write;\n private static boolean fileOutput = false;\n\n public static void setFileInput(boolean fileInput) {\n IO.fileInput = fileInput;\n }\n\n public static void setFileOutput(boolean fileOutput) {\n IO.fileOutput = fileOutput;\n }\n\n private static void startInput() {\n try {\n read = new BufferedReader(fileInput ? new FileReader(\"input.txt\") : new InputStreamReader(System.in));\n } catch (Exception error) {\n }\n }\n\n private static void startOutput() {\n try {\n write = new BufferedWriter(fileOutput ? new FileWriter(\"output.txt\") : new OutputStreamWriter(System.out));\n } catch (Exception error) {\n }\n }\n\n protected static int readInt() throws Exception {\n if (read == null) {\n startInput();\n }\n return Integer.parseInt(read.readLine());\n }\n\n protected static long readLong() throws Exception {\n if (read == null) {\n startInput();\n }\n return Long.parseLong(read.readLine());\n }\n\n protected static String readString() throws Exception {\n if (read == null) {\n startInput();\n }\n return read.readLine();\n }\n\n protected static int[] readArrayInt(String split) throws Exception {\n if (read == null) {\n startInput();\n }\n return Arrays.stream(read.readLine().split(split)).mapToInt(Integer::parseInt).toArray();\n }\n\n protected static long[] readArrayLong(String split) throws Exception {\n if (read == null) {\n startInput();\n }\n return Arrays.stream(read.readLine().split(split)).mapToLong(Long::parseLong).toArray();\n }\n\n protected static String[] readArrayString(String split) throws Exception {\n if (read == null) {\n startInput();\n }\n return read.readLine().split(split);\n }\n\n protected static void writeArray(int[] array, String split, boolean enter) {\n if (write == null) {\n startOutput();\n }\n try {\n int length = array.length;\n for (int index = 0; index < length; index++) {\n write.write(Integer.toString(array[index]));\n if (index + 1 != length) {\n write.write(split);\n }\n }\n if (enter) {\n writeEnter();\n }\n } catch (Exception error) {\n }\n }\n\n protected static void writeArray(Integer[] array, String split, boolean enter) {\n if (write == null) {\n startOutput();\n }\n try {\n int length = array.length;\n for (int index = 0; index < length; index++) {\n write.write(Integer.toString(array[index]));\n if (index + 1 != length) {\n write.write(split);\n }\n }\n if (enter) {\n writeEnter();\n }\n } catch (Exception error) {\n }\n }\n\n protected static void writeArray(Int[] array, String split, boolean enter) {\n if (write == null) {\n startOutput();\n }\n try {\n int length = array.length;\n for (int index = 0; index < length; index++) {\n write.write(Integer.toString(array[index].value));\n if (index + 1 != length) {\n write.write(split);\n }\n }\n if (enter) {\n writeEnter();\n }\n } catch (Exception error) {\n }\n }\n\n protected static void writeArray(long[] array, String split, boolean enter) {\n if (write == null) {\n startOutput();\n }\n try {\n int length = array.length;\n for (int index = 0; index < length; index++) {\n write.write(Long.toString(array[index]));\n if (index + 1 != length) {\n write.write(split);\n }\n }\n if (enter) {\n writeEnter();\n }\n } catch (Exception error) {\n }\n }\n\n protected static void writeArray(Long[] array, String split, boolean enter) {\n if (write == null) {\n startOutput();\n }\n try {\n int length = array.length;\n for (int index = 0; index < length; index++) {\n write.write(Long.toString(array[index]));\n if (index + 1 != length) {\n write.write(split);\n }\n }\n if (enter) {\n writeEnter();\n }\n } catch (Exception error) {\n }\n }\n\n public static void writeArray(String[] array, String split, boolean enter) {\n if (write == null) {\n startOutput();\n }\n try {\n int length = array.length;\n for (int index = 0; index < length; index++) {\n write.write(array[index]);\n if (index + 1 != length) {\n write.write(split);\n }\n }\n if (enter) {\n writeEnter();\n }\n } catch (Exception ignored) {\n }\n }\n\n protected static void writeArray(boolean[] array, String split, boolean enter) {\n if (write == null) {\n startOutput();\n }\n try {\n int length = array.length;\n for (int index = 0; index < length; index++) {\n write.write(Boolean.toString(array[index]));\n if (index + 1 != length) {\n write.write(split);\n }\n }\n if (enter) {\n writeEnter();\n }\n } catch (Exception ignored) {\n }\n }\n\n protected static void writeInt(int number, String end) {\n if (write == null) {\n startOutput();\n }\n try {\n write.write(Integer.toString(number));\n write.write(end);\n } catch (Exception ignored) {\n }\n }\n\n protected static void writeInt(Integer number, String end) {\n if (write == null) {\n startOutput();\n }\n try {\n write.write(Integer.toString(number));\n write.write(end);\n } catch (Exception ignored) {\n }\n }\n\n protected static void writeLong(long number, String end) {\n if (write == null) {\n startOutput();\n }\n try {\n write.write(Long.toString(number));\n write.write(end);\n } catch (Exception ignored) {\n }\n }\n\n protected static void writeLong(Long number, String end) {\n if (write == null) {\n startOutput();\n }\n try {\n write.write(Long.toString(number));\n write.write(end);\n } catch (Exception ignored) {\n }\n }\n\n protected static void writeString(String word, String end) {\n if (write == null) {\n startOutput();\n }\n try {\n write.write(word);\n write.write(end);\n } catch (Exception ignored) {\n }\n }\n\n protected static void writeBoolean(boolean value, String end) {\n if (write == null) {\n startOutput();\n }\n try {\n write.write(value ? \"true\" : \"false\");\n write.write(end);\n } catch (Exception ignored) {\n }\n }\n\n protected static void writeBoolean(Boolean value, String end) {\n if (write == null) {\n startOutput();\n }\n try {\n write.write(value ? \"true\" : \"false\");\n write.write(end);\n } catch (Exception ignored) {\n }\n }\n\n protected static void writeChar(char word, String end) {\n if (write == null) {\n startOutput();\n }\n try {\n write.write(word);\n write.write(end);\n } catch (Exception ignored) {\n }\n }\n\n protected static void writeChar(Character word, String end) {\n if (write == null) {\n startOutput();\n }\n try {\n write.write(word);\n write.write(end);\n } catch (Exception ignored) {\n }\n }\n\n\n protected static void writeEnter() {\n if (write == null) {\n startOutput();\n }\n try {\n write.newLine();\n } catch (Exception ignored) {\n }\n }\n\n protected static void print(boolean exit) throws Exception {\n if (exit) {\n print();\n } else {\n write.flush();\n }\n }\n\n protected static void print() throws Exception {\n if (write == null) {\n return;\n }\n write.flush();\n if (read != null) {\n read.close();\n }\n write.close();\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "greedy", "brute force"], "code_uid": "da3e29f65fd48c67ca239903b0209c38", "src_uid": "84d9e7e9c9541d997e6573edb421ae0a", "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 yousuf\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\n int n = in.nextInt();\n int k = in.nextInt();\n\n long b = 1;\n for (int i = 1; i <= k; i++) {\n b *= 10;\n }\n\n out.println(IntegerUtils.lcm(n, b));\n\n }\n\n }\n\n static class IntegerUtils {\n public static long gcd(long a, long b) {\n long t;\n while (b != 0) {\n t = b;\n b = a % b;\n a = t;\n }\n\n return a;\n }\n\n public static long lcm(long a, long b) {\n return a * (b / gcd(a, b));\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 // reader = new BufferedReader(new FileReader(\"input.txt\"));\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", "number theory"], "code_uid": "a449ec60ac5f5b6e54cc1b13e7306379", "src_uid": "73566d4d9f20f7bbf71bc06bc9a4e9f3", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.Scanner;\nimport java.util.HashSet;\n\npublic class Main {\n\n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n String w = s.nextLine().trim().toLowerCase();\n StringBuffer sb = new StringBuffer();\n HashSet vowels = new HashSet();\n vowels.add('a');\n vowels.add('e');\n vowels.add('i');\n vowels.add('o');\n vowels.add('u');\n vowels.add('y');\n for (char c : w.toCharArray()) {\n if (vowels.contains(c)) continue;\n sb.append('.');\n sb.append(c);\n }\n System.out.println(sb.toString());\n }\n}\n", "lang_cluster": "Java", "tags": ["strings", "implementation"], "code_uid": "90b4ccc5e08fa5fa14b6dd934594e051", "src_uid": "db9520e85b3e9186dd3a09ff8d1e8c1b", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Main{\n\n public static void main(String[] args){\n Scanner in=new Scanner(System.in);\n int n,m,k,x,y,z;\n n=in.nextInt();\n m=in.nextInt();\n k=in.nextInt();\n x=k/2+k%2;\n y=x/m + ((x%m==0)?0:1);\n z=(x%m==0)?m:x%m;\n System.out.println(y +\" \"+ z +\" \"+((k%2==0)?\"R\":\"L\"));\n\n\n }\n}", "lang_cluster": "Java", "tags": ["math", "constructive algorithms"], "code_uid": "ecf824ac8f0ec58e866df05749463bf8", "src_uid": "d6929926b44c2d5b1a8e6b7f965ca1bb", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class LearnJava{\n\n public static void main(String[] args){\n int n, count=0;\n double k;\n Scanner scan = new Scanner(System.in);\n n = scan.nextInt();\n for(int i=1; i<=n; i++){\n for(int j=i; j<=n; j++){\n k = Math.sqrt(i*i + j*j);\n if(k==(int)k && k<=n)\n count++;\n }\n }\n System.out.print(count);\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "math"], "code_uid": "6425b8465c1aa430b66a6a71b285e5a7", "src_uid": "36a211f7814e77339eb81dc132e115e1", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "//package codeforces;\n\nimport 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.StreamTokenizer;\nimport java.util.ArrayList;\n\npublic class CodeForces {\n\n ArrayList num = new ArrayList();\n\n private boolean search(int value, int begin, int end) {\n if (end - begin < 3) {\n if (num.get(begin) == value || num.get(end) == value) {\n return (true);\n } else {\n return (false);\n }\n } else {\n int middle = (end - begin) / 2 + begin;\n if (num.get(middle) == value) {\n return (true);\n } else {\n if (num.get(middle) < value) {\n return (search(value, middle + 1, end));\n } else {\n return (search(value, begin, middle - 1));\n }\n }\n }\n }\n\n public void run() throws IOException {\n MyScanner sc = new MyScanner(System.in);\n int n = sc.nextInt();\n int i = 1;\n boolean greater = false;\n while (!greater) {\n long number = i * (i + 1) / 2;\n if (number >= n) {\n greater = true;\n } else {\n num.add((int) number);\n }\n i++;\n }\n boolean exist = false;\n for (i = 0; i < num.size(); i++) {\n if (search(n - num.get(i), 0, num.size() - 1)) {\n exist = true;\n break;\n }\n }\n if (exist) {\n System.out.println(\"YES\");\n } else {\n System.out.println(\"NO\");\n }\n }\n\n public static void main(String[] args) throws FileNotFoundException, IOException {\n CodeForces cf = new CodeForces();\n cf.run();\n }\n}\n\nclass MyScanner {\n\n private StreamTokenizer st;\n\n public MyScanner(InputStream is) {\n st = new StreamTokenizer(is);\n }\n\n public MyScanner(File f) throws FileNotFoundException {\n BufferedReader in = new BufferedReader(new FileReader(f));\n st = new StreamTokenizer(in);\n }\n\n public int nextInt() throws IOException {\n st.nextToken();\n return ((int) st.nval);\n }\n\n public double nextDouble() throws IOException {\n st.nextToken();\n return (st.nval);\n }\n\n public String nextString() throws IOException {\n st.nextToken();\n return (st.sval);\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "implementation", "binary search"], "code_uid": "5167299b15d43b01757b66b8d26dcdc9", "src_uid": "245ec0831cd817714a4e5c531bffd099", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class B {\n\n\t\n\tpublic static void main(String[] args) throws IOException{\n\t\tFastScanner sc = new FastScanner();\n//\t\tint yo = sc.nextInt();\n//\t\twhile(yo-->0) {\n//\t\t}\n\t\t\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\t\n\t\tchar[][] arr = 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\tarr[i][j] = s.charAt(j);\n\t\t\t}\n\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(arr[i][j] == 'W') {\n\t\t\t\t\tcount += helper(arr,i,j);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(count);\n\t}\n\t\n\n\n\tprivate static int helper(char[][] arr, int i, int j) {\n\t\tint row = arr.length;\n\t\tint col = arr[0].length;\n\t\t\n\t\tint count = 0;\n\n\t\tif(i-1 >= 0 && arr[i-1][j] == 'P') {\n\t\t\tarr[i-1][j] = '.';\n\t\t\tcount++;\n\t\t\treturn count;\n\t\t}\n\t\t\n\t\tif(j-1 >= 0 && arr[i][j-1] == 'P') {\n\t\t\tarr[i][j-1] = '.';\n\t\t\tcount++;\n\t\t\treturn count;\n\t\t}\n\t\t\n\t\tif(i+1 < row && arr[i+1][j] == 'P') {\n\t\t\tarr[i+1][j] = '.';\n\t\t\tcount++;\n\t\t\treturn count;\n\t\t}\n\t\t\n\t\tif(j+1 < col && arr[i][j+1] == 'P') {\n\t\t\tarr[i][j+1] = '.';\n\t\t\tcount++;\n\t\t}\n\t\t\n\t\treturn count;\n\t}\n\n\n\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\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 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\t\t\t dp[pos][space] += modInverse(fact[i-1],mod)*modInverse(i,mod)%mod*modInverse(n,mod)%mod*(n-i)%mod*ways(pos+1,space-i,arr,n)%mod;\n\t\t\t\t \n\t\t\t\t else\n\t\t\t\t\t dp[pos][space] = ways(pos+1,space,arr,n);\n\t\t\t }\n\t\t\t \n\t\t\t else\n\t\t\t\t dp[pos][space] += modInverse(fact[i],mod)*ways(pos+1,space-i,arr,n);\n\t\t\t \n\t\t\t dp[pos][space] %= mod;\n\t\t }\n\t\t return dp[pos][space];\n\t }\n\tpublic static void main(String []args)\n\t{\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tfact = new long[n+1];\n\t\tfact[0] = 1;\n\t\tfor(long i = 1 ; i <= n ; i++)\n\t\t{\n\t\t\tfact[(int)i] = fact[(int)i-1]*i%mod;\n\t\t}\n\t\t\n\t\tint arr[] = new int[10];\n\t\tfor(int i = 0 ; i <= 9 ;i++)\n\t\t{\n\t\t\tarr[i] = sc.nextInt();\n\t\t}\n\tdp = new long[10][n+1];\n\tfor(int i = 0; i <= 9 ; i++)\n\t{\n\t\tfor(int j = 0 ; j <= n ; j++)\n\t\t{\n\t\tdp[i][j] = -1;\t\n\t\t}\n\t}\n\tlong ans = 0;\n\tfor(int i = 1 ; i <= n ; i++)\n\t{\n\t\tans += fact[i]*ways(0,i,arr,i)%mod;\n\t\tans %= mod;\n\t}\n\t\n\t\n\tans %= mod;\n\tSystem.out.println(ans);\n\t}\n}", "lang_cluster": "Java", "tags": ["dp", "combinatorics"], "code_uid": "964074366d089354f847f17f1681042b", "src_uid": "c1b5169a5c3b1bd4a2f1df1069ee7755", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class C_436\n{\n\n\tInputStream is;\n\tPrintWriter out;\n\tint n;\n\t// long a[];\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tlong a;\n\tlong b;\n\tlong f;\n\tlong k;\n\tlong count;\n\n\tvoid solve()\n\t{\n\t\ta = nl();\n\t\tb = nl();\n\t\tf = nl();\n\t\tk = nl();\n\t\tif (check())\n\t\t{\n\t\t\tout.println(count);\n\t\t} else\n\t\t{\n\t\t\tout.println(-1);\n\t\t}\n\t}\n\n\tboolean check()\n\t{\n\t\tboolean flag = true;\n\t\tcount = 0;\n\t\tlong petrol = b;\n\t\tfor (int i = 1; i <= k; i++)\n\t\t{\n\t\t\tif (i == k)\n\t\t\t{\n\t\t\t\tif (i % 2 == 1)\n\t\t\t\t{\n\t\t\t\t\tpetrol = petrol - f;\n\t\t\t\t\tif (petrol < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\tif (petrol < a - f)\n\t\t\t\t\t{\n\t\t\t\t\t\tpetrol = b;\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t}\n\t\t\t\t\tpetrol -= a - f;\n\t\t\t\t\tif (petrol < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\treturn false;\n\n\t\t\t\t\t}\n\t\t\t\t} else\n\t\t\t\t{\n\t\t\t\t\tpetrol -= a - f;\n\t\t\t\t\tif (petrol < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\tif (petrol < (f))\n\t\t\t\t\t{\n\t\t\t\t\t\tpetrol = b;\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t}\n\t\t\t\t\tpetrol -= f;\n\t\t\t\t\tif (petrol < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else\n\t\t\t{\n\t\t\t\tif (i % 2 == 1)\n\t\t\t\t{\n\n\t\t\t\t\tpetrol = petrol - f;\n\t\t\t\t\t// tr(petrol, \" ++ \", i, count);\n\t\t\t\t\tif (petrol < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\tif (petrol < 2 * (a - f))\n\t\t\t\t\t{\n\t\t\t\t\t\tpetrol = b;\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t}\n\t\t\t\t\tpetrol -= a - f;\n\t\t\t\t\t// tr(petrol, \" -- \", i, count);\n\t\t\t\t} else\n\t\t\t\t{\n\t\t\t\t\tpetrol -= a - f;\n\t\t\t\t\t// tr(petrol, \" ++ \", i, count);\n\t\t\t\t\tif (petrol < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\tif (petrol < 2 * (f))\n\t\t\t\t\t{\n\t\t\t\t\t\tpetrol = b;\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t}\n\t\t\t\t\tpetrol -= f;\n\t\t\t\t\t// tr(petrol, \" -- \", i, count);\n\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn true;\n\n\t}\n\n\tvoid run() throws Exception\n\t{\n\t\tString INPUT = \"C:\\\\Users\\\\Admin\\\\Desktop\\\\input.txt\";\n\t\tis = oj ? System.in : new FileInputStream(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\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tnew Thread(null, new Runnable()\n\t\t{\n\t\t\tpublic void run()\n\t\t\t{\n\t\t\t\ttry\n\t\t\t\t{\n\t\t\t\t\tnew C_436().run();\n\t\t\t\t} catch (Exception 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}, \"1\", 1 << 26).start();\n\t}\n\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\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 = is.read(inbuf);\n\t\t\t} catch (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\n\tprivate boolean isSpaceChar(int c)\n\t{\n\t\treturn !(c >= 33 && c <= 126);\n\t}\n\n\tprivate int skip()\n\t{\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{\n\t\treturn Double.parseDouble(ns());\n\t}\n\n\tprivate char nc()\n\t{\n\t\treturn (char) skip();\n\t}\n\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!(isSpaceChar(b)))\n\t\t{ // 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{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile (p < n && !(isSpaceChar(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\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\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\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\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} else\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\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\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} else\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\n\tprivate void tr(Object... o)\n\t{\n\t\tif (!oj)\n\t\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["math", "greedy", "implementation"], "code_uid": "6ab28d01d88059810304b7b14dd76f7b", "src_uid": "283aff24320c6518e8518d4b045e1eca", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\npublic class CoveredPath {\n\n public static void main(String[] args) \n {\n Scanner scanner = new Scanner(System.in);\n int fV = scanner.nextInt();\n int sV = scanner.nextInt();\n int t = scanner.nextInt();\n int d = scanner.nextInt();\n \n System.out.println(Path(fV,sV,t,d));\n \n }\n \n static int Path(int F,int S,int t,int d)\n {\n int Distance = F;\n for (int i = 1; i < t-1; i++) \n {\n Distance += Math.min(F + i*d , S + (t-1)*d - i*d);\n }\n \n Distance += S;\n \n return Distance;\n }\n \n \n \n}\n", "lang_cluster": "Java", "tags": ["math", "greedy", "dp"], "code_uid": "8b761f61178d8aa428b1404b2eda230f", "src_uid": "9246aa2f506fcbcb47ad24793d09f2cf", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class test {\n\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\t// TODO Auto-generated method stub\n\t\tReader.init(System.in);\n\t\tint n=Reader.nextInt();\n\t\tint m=Reader.nextInt();\n\t\t\n\t\tint humans=n-m;\n\t\tif(m==0) {\n\t\t\tSystem.out.println(1);\n\t\t}\n\t\telse {\n\t\t\tSystem.out.println(Math.min(m, humans));\n\t\t}\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\t\n\t\t\t\n\n\n\n}\n}\n\n\n\n\n\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 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}\n", "lang_cluster": "Java", "tags": ["math", "greedy"], "code_uid": "df990f54b3b9f38c364a0917032edfe1", "src_uid": "c05d0a9cabe04d8fb48c76d2ce033648", "difficulty": 900.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\n\tprivate static class Vipechka {\n\t\tint remains_a;\n\t\tint need_b;\n\t\tint testo_c;\n\t\tint cost_d;\n\n\t\tpublic Vipechka(int remains_a, int need_b, int testo_c, int cost_d) {\n\t\t\tthis.remains_a = remains_a;\n\t\t\tthis.need_b = need_b;\n\t\t\tthis.testo_c = testo_c;\n\t\t\tthis.cost_d = cost_d;\n\t\t}\n\t}\n\n\tpublic static int[][] dp = new int[1001][12];\n\n\tpublic static void main(String[] args) throws NumberFormatException,\n\t\t\tIOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tString[] parts = br.readLine().split(\"\\\\s+\");\n\t\tint n = Integer.parseInt(parts[0]);\n\t\tint m = Integer.parseInt(parts[1]);\n\t\tint c = Integer.parseInt(parts[2]);\n\t\tint d = Integer.parseInt(parts[3]);\n\t\tVipechka[] vipArr = new Vipechka[m + 1];\n\t\tvipArr[0] = new Vipechka(0, 0, c, d);\n\t\tfor (int i = 1; i <= m; i++) {\n\t\t\tparts = br.readLine().split(\"\\\\s+\");\n\t\t\tVipechka vip = new Vipechka(Integer.parseInt(parts[0]),\n\t\t\t\t\tInteger.parseInt(parts[1]), Integer.parseInt(parts[2]),\n\t\t\t\t\tInteger.parseInt(parts[3]));\n\t\t\tvipArr[i] = vip;\n\t\t}\n\n\t\t// dpMine(n, vipArr);\n\t\tfor (int testo = 0; testo <= n; testo++) {\n\t\t\tfor (int i = 0; i < vipArr.length; i++) {\n\t\t\t\tint nachinkiEnoughFor = vipArr[i].need_b == 0 ? Integer.MAX_VALUE\n\t\t\t\t\t\t: vipArr[i].remains_a / vipArr[i].need_b;\n\t\t\t\tint testaEnoughFor = testo / vipArr[i].testo_c;\n\t\t\t\tint maxCanBacke = Math.min(nachinkiEnoughFor, testaEnoughFor);\n\t\t\t\tfor (int k = 0; k <= maxCanBacke; k++) {\n\t\t\t\t\tint restTesto = testo - k * vipArr[i].testo_c;\n\t\t\t\t\tif (restTesto < 0)\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tint getMoney = (i - 1 >= 0 ? dp[restTesto][i - 1] : 0) + k\n\t\t\t\t\t\t\t* vipArr[i].cost_d;\n\t\t\t\t\tif (dp[testo][i] < getMoney)\n\t\t\t\t\t\tdp[testo][i] = getMoney;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// int max = Integer.MIN_VALUE;\n\t\t// for (int i = 0; i < vipArr.length; i++) {\n\t\t// int currMoney = dp[n][i];\n\t\t// if (max < currMoney)\n\t\t// max = currMoney;\n\t\t// }\n\t\tSystem.out.println(dp[n][m]);\n\t}\n\n\tprivate static void dpMine(int n, Vipechka[] vipArr) {\n\t\tfor (int testo = 1; testo <= n; testo++) {\n\t\t\tfor (int i = 0; i < vipArr.length; i++) {\n\t\t\t\tint nachinkiEnoughFor = vipArr[i].need_b == 0 ? Integer.MAX_VALUE\n\t\t\t\t\t\t: vipArr[i].remains_a / vipArr[i].need_b;\n\t\t\t\tint testaEnoughFor = testo / vipArr[i].testo_c;\n\t\t\t\tint maxCanBacke = Math.min(nachinkiEnoughFor, testaEnoughFor);\n\t\t\t\tint currMaxMoney = Integer.MIN_VALUE;\n\t\t\t\tfor (int canBake = 0; canBake <= maxCanBacke; canBake++) {\n\t\t\t\t\tint currMoney = canBake * vipArr[i].cost_d;\n\t\t\t\t\tint currMoneyTmp = currMoney;\n\t\t\t\t\tfor (int j = 0; j < i; j++) {\n\t\t\t\t\t\tif (testo - canBake * vipArr[i].testo_c > 0) {\n\t\t\t\t\t\t\tif (currMoney\n\t\t\t\t\t\t\t\t\t+ dp[testo - canBake * vipArr[i].testo_c][j] > currMoneyTmp) {\n\t\t\t\t\t\t\t\tcurrMoneyTmp = currMoney\n\t\t\t\t\t\t\t\t\t\t+ dp[testo - canBake\n\t\t\t\t\t\t\t\t\t\t\t\t* vipArr[i].testo_c][j];\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\tif (currMoneyTmp > currMaxMoney)\n\t\t\t\t\t\tcurrMaxMoney = currMoneyTmp;\n\t\t\t\t}\n\t\t\t\tdp[testo][i] = currMaxMoney;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static int solve(Vipechka[] vip, int testo, int currIdx) {\n\t\tif (currIdx >= vip.length)\n\t\t\treturn 0;\n\t\tif (currIdx == 0) {\n\t\t\tint nachinkiEnoughFor = vip[currIdx].need_b == 0 ? Integer.MAX_VALUE\n\t\t\t\t\t: vip[currIdx].remains_a / vip[currIdx].need_b;\n\t\t\tint testaEnoughFor = testo / vip[currIdx].testo_c;\n\t\t\tint maxCanBacke = Math.min(nachinkiEnoughFor, testaEnoughFor);\n\t\t\treturn maxCanBacke * vip[currIdx].cost_d;\n\t\t}\n\t\tint max = Integer.MIN_VALUE;\n\t\tfor (int i = 0; i < currIdx; i++) {\n\t\t\tint nachinkiEnoughFor = vip[currIdx].need_b == 0 ? Integer.MAX_VALUE\n\t\t\t\t\t: vip[currIdx].remains_a / vip[currIdx].need_b;\n\t\t\tint testaEnoughFor = testo / vip[currIdx].testo_c;\n\t\t\tint maxCanBacke = Math.min(nachinkiEnoughFor, testaEnoughFor);\n\t\t\tfor (int j = 0; j <= maxCanBacke; j++) {\n\t\t\t\tint currMoney = j * vip[currIdx].cost_d;\n\t\t\t\tint adjustMoney = dp[testo - j * vip[currIdx].testo_c][i];\n\t\t\t\tif (adjustMoney == 0) {\n\t\t\t\t\tadjustMoney = solve(vip, testo - j * vip[currIdx].testo_c,\n\t\t\t\t\t\t\ti);\n\t\t\t\t\tdp[testo - j * vip[currIdx].testo_c][i] = adjustMoney;\n\t\t\t\t}\n\t\t\t\tcurrMoney += adjustMoney;\n\t\t\t\tif (max < currMoney)\n\t\t\t\t\tmax = currMoney;\n\t\t\t}\n\t\t}\n\t\treturn max;\n\t}\n}", "lang_cluster": "Java", "tags": ["dp"], "code_uid": "b684d4e62195adec74def35bdcbd9f1f", "src_uid": "4e166b8b44427b1227e0f811161d3a6f", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "//package yahia;\nimport java.io.PrintWriter;\nimport java.util.*;public class Main {public static void main (String []args) {Scanner sc =new Scanner (System.in);PrintWriter pw =new PrintWriter(System.out);\nString w =sc.next();char [] x =w.toCharArray();int a =x.length;String j =\"\";\nif (a<=2) System.out.println(w);\nelse if (a%2==1) {\n j=x[a/2]+\"\"+x[a/2+1];\n int i =(a/2-1);int s=a/2+2;\n while (i>=0||s0||s=0) {\n\t\t\tj=j+x[i];\n\t\t\t--i;\n\t\t}\n\t\tj=j+x[s];++s;\n\t}\n\tSystem.out.println(j);\n\n}}}\n ", "lang_cluster": "Java", "tags": ["strings", "implementation"], "code_uid": "4ba225b08692d99eea492a65396064a8", "src_uid": "992ae43e66f1808f19c86b1def1f6b41", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import jdk.swing.interop.SwingInterOpUtils;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\n\npublic class prac1 {\n public static void main(String[] args) throws IOException {\n BufferedReader br =new BufferedReader(new InputStreamReader(System.in));\n int n=Integer.parseInt(br.readLine());\n String a=br.readLine();\n// System.out.println(a);\n if(n==0)\n {\n System.out.println(\"NO\");\n }\n else\n {\n int count=0;\n for(int i=1;i0)\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n }\n\n\n\n }\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "d46d8ca6cf5d69bd38d127ffb72a5879", "src_uid": "ab8a2070ea758d118b3c09ee165d9517", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/**\n * \n */\n\n\n // @author Winry Rockbell\n import java.util.Scanner;\n \npublic class HelloWorld {\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\tint n,k,d;\n\tlong mod=1000000007;\n\tScanner in = new Scanner(System.in);\n\tn=in.nextInt();\n\tk=in.nextInt();\n\td=in.nextInt();\n\tlong dp[]=new long[101];\n\tlong dp1[]=new long[101];\n\tdp[0]=1;dp1[0]=1;\n\tdp[1]=1;dp1[1]=1;\n\tfor(int i=1;i<=n;i++)\n\t{dp[i]=0;\n\t\tfor(int j=1;j=0)\n\t\t\t\tdp[i]+=dp[i-j];\n\t\t\tdp[i]=dp[i]%mod;\n\t\t}\n\t}\n\tfor(int i=1;i<=n;i++)\n\t{dp1[i]=0;\n\t\tfor(int j=1;j<=k;j++)\n\t\t{\n\t\t\tif(i-j>=0)\n\t\t\t\tdp1[i]+=dp1[i-j];\n\t\t\tdp1[i]=dp1[i]%mod;\n\t\t}\n\t}\n\tlong ki=dp1[n]-dp[n];\n\tif(ki<0)\n\t\tki=ki+mod;\n\tif(n==0)\n\t\tki=0;\n\tSystem.out.println(\"\"+ki);\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["dp", "implementation", "trees"], "code_uid": "dcb6ceb616c3113ed2ae28bcd4b31507", "src_uid": "894a58c9bba5eba11b843c5c5ca0025d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/**\n * \n */\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n/**\n * @author Rachna\n *\n */\npublic class MagicForest {\n\n\t/**\n\t * @param args\n\t * @throws IOException\n\t * @throws NumberFormatException\n\t */\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tint n = Integer.parseInt(br.readLine());\n\t\tint count = 0;\n\n\t\tfor (int i = 1; i <= n; i++) {\n\n\t\t\tfor (int j = i + 1; j <= n; j++) {\n\t\t\t\t\n\t\t\t\tint k = i ^ j;\n\t\t\t\tif (k <= n && i+j > k && k >=j) {\n\t\t\t\t\tcount++;\n }\n\n\t\t\t}\n\t\t}\n\n\t\tSystem.out.println(count);\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["brute force"], "code_uid": "0cd1a718cd6b7c68da5710bc640bb64a", "src_uid": "838f2e75fdff0f13f002c0dfff0b2e8d", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.lang.reflect.Array;\nimport java.util.*;\nimport java.util.logging.StreamHandler;\n\npublic class Second {\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 static long count(long x, long k) {\n long sum = 0, d = 1;\n for (;d <= x;d *= k) sum += x/d;\n return(sum);\n }\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 long n = next(), k = next();\n long min = 0;\n long max = 1000000000;\n\n while (max - min!=1) {\n if (count((max+min)/2,k) >= n) {\n max = (max+min)/2;\n } else min = (max+min)/2;\n }\n\n out.println(max);\n\n out.println();\n\t\tout.close();\n\t}\n}", "lang_cluster": "Java", "tags": ["implementation", "binary search"], "code_uid": "02e817cfe84351bddd2a4ed17cef35ad", "src_uid": "41dfc86d341082dd96e089ac5433dc04", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": " //package Contest553;\n\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class mainF {\n public static Scanner enter = new Scanner(System.in);\n public static PrintWriter out = new PrintWriter(System.out);\n public static void main(String[] args) {\n long mod=(long)1e9+7;\n int n=enter.nextInt();\n long s=enter.nextLong();\n int[] arr=new int[n];\n int m=0;\n long CON=n*(n-1)/2;\n CON=bin_pow(CON,mod-2,mod);\n for (int i = 0; i 0)CM[i][i-1]=(long)i*(m-k+i)*CON;\n }\n MATRIX_mod(CM,mod);\n CM=bin_pow(CM,s,mod);\n System.out.println((CM[f_k][k]+mod)%mod);\n\n\n\n }\n public static long bin_pow(long a,long b, long mod){//a^b %mod\n long ans=1;\n while(b!=0){\n if((b&1)==1) ans*=a;\n a*=a;\n ans%=mod;\n a%=mod;\n b>>=1;\n }\n return ans;\n }\n\n public static long[][] bin_pow(long[][] a,long b, long mod){//a^b %mod\n long[][] ans=new long[a.length][a.length];\n for (int i = 0; i >=1;\n }\n return ans;\n }\n public static long[][] MATRIX_mult(long[][] a, long[][] b) { //b не меняем a=a*b;\n long[][] c=new long[a.length][a.length];\n for (int i = 0; i 0) res -= csum[a-1];\n if(res < 0) res += mod;\n return res;\n}\nstatic int mod = 1000000007;\n}\n", "lang_cluster": "Java", "tags": ["dp", "combinatorics"], "code_uid": "ecdeaf94baf9e81f03572f434f1ac003", "src_uid": "142b06ed43b3473513995de995e19fc3", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "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;\nimport java.util.*;\n\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 m = sc.nextInt();\n int cnt = 0;\n for(int i=0; i<=1000; ++i) {\n for(int j=0; j<=1000; ++j) {\n if(i*i+j==n&&i+j*j==m) cnt++;\n }\n }\n System.out.println(cnt);\n }\n}", "lang_cluster": "Java", "tags": ["brute force"], "code_uid": "c324166109db8706687ed2cd19fc0af3", "src_uid": "03caf4ddf07c1783e42e9f9085cc6efd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n \n \n \n \npublic class Main {\n\t int \tgetint(BufferedReader sc) throws java.lang.Exception\n\t\t\t{\n\t\t//\t String ss=sc.readLine();\n\t\t \tint a= Integer.parseInt(sc.readLine());\n\t\t \treturn a;\n\t\t\t}\n\t\t ArrayList getlistint(BufferedReader sc) throws java.lang.Exception\n\t\t {\n\t\t\t ArrayList res=new ArrayList<>();\n\t\t\t \n\t\t\t String s=sc.readLine();\n\t\t\t String[] ss=s.split(\" \");\n\t\t\t\n\t\t\t for(int i=0;i getlistfl(BufferedReader sc) throws java.lang.Exception\n\t\t {\n\t\t\t ArrayList res=new ArrayList<>();\n\t\t\t \n\t\t\t String s=sc.readLine();\n\t\t\t String[] ss=s.split(\" \");\n\t\t\t\n\t\t\t for(int i=0;i getlist(BufferedReader sc) throws java.lang.Exception\n\t\t {\n\t\t\t ArrayList res=new ArrayList<>();\n\t\t\t \n\t\t\t String s=sc.readLine();\n\t\t\t String[] ss=s.split(\" \");\n\t\t\t\n\t\t\t for(int i=0;i getlistchar(BufferedReader sc) throws java.lang.Exception\n\t\t {\n\t\t\t ArrayList res=new ArrayList<>();\n\t\t\t \n\t\t\t String s=sc.readLine();\n\t\t\t// String[] ss=s.split(\" \");\n\t\t\t\n\t\t\t for(int i=0;i0){\n\t\t\t //\tint num=Integer.parseInt(br.readLine());\n\t\t\t \tArrayList p=pra.getlistint(br);\n\t\t\t \tArrayList p1=pra.getlistint(br);\n\t\t\t \t\n\t\t\t \tint sum=0;\n\t\t\t \t\n\t\t\t \tfor(int i=0;ip.get(1))\n\t\t\t \t{\n\t\t\t \t\tSystem.out.println(\"-1\");\n\t\t\t \t}else\n\t\t\t \t{\n\t\t\t \t\tSystem.out.println(res1/5);\n\t\t\t \t}\n\t\t\t \t\n\t\t\t \n\t\t//\t System.out.println(ress);\n\t\t\t }\n\t\t \n\t\t }\n \n}", "lang_cluster": "Java", "tags": ["greedy", "implementation"], "code_uid": "eff91b1e06c6cbb4ee80403f31bede73", "src_uid": "b16f5f5c4eeed2a3700506003e8ea8ea", "difficulty": 900.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\tTaskB solver = new TaskB();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskB {\n public void solve(int testNumber, InputReader in, OutputWriter out){\n\t int velocityprincess = in.ri(), velocitydragon = in.ri(), thoursheadstart = in.ri(), fhoursstraightening = in.ri(), cmilestotravel = in.ri();\n\t double t = -(1.0* thoursheadstart * velocitydragon) / (velocityprincess - velocitydragon);\n\t double distanceprincess = velocityprincess * t;\n\t if (distanceprincess >= cmilestotravel || velocityprincess >= velocitydragon){\n\t\t out.print(0);\n\t\t return;\n\t }\n\t for(int i = 0; i < 10000000; i++) {\n\t\t t += (-2 * distanceprincess - velocitydragon * fhoursstraightening) / (velocityprincess - velocitydragon);\n\t\t distanceprincess = t * velocityprincess;\n\t\t if(distanceprincess >= cmilestotravel){\n\t\t\t out.print(i + 1);\n\t\t\t return;\n\t\t }\n\t }\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 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(int i) {\n\t\twriter.print(i);\n\t}\n}\n\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "61775b7c84eb5b517f8058a0c8b19e8d", "src_uid": "c9c03666278acec35f0e273691fe0fff", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\n/**\n * Created by vlad on 22.03.16.\n */\npublic class problemB {\n\n public void solution(Scanner in, PrintWriter out) {\n int n = in.nextInt();\n int k = in.nextInt();\n if (n == 0) {\n out.println(0);\n return;\n }\n int i = 0;\n int ans = 0;\n while (n > 0 && k > 0) {\n if (n % 10 != 0) {\n ans++;\n } else {\n k--;\n }\n i++;\n n /= 10;\n }\n\n if (k != 0) {\n out.println(i - 1);\n } else {\n out.println(ans);\n }\n }\n\n public static void main(String args[]) {\n Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n\n new problemB().solution(in, out);\n\n in.close();\n out.close();\n }\n\n}", "lang_cluster": "Java", "tags": ["brute force", "greedy"], "code_uid": "8100ecbe371bb6f9946122f52e0acb20", "src_uid": "7a8890417aa48c2b93b559ca118853f9", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\n\npublic class ProbE implements Runnable{\n\n\tprivate static InputStream stream;\n\tprivate static byte[] buf = new byte[1024];\n\tprivate static int curChar;\n\tprivate static int numChars;\n\tprivate static SpaceCharFilter filter;\n\tprivate static PrintWriter pw;\n\tprivate static int mod = (int)1e9+7;\n\t\n\tprivate static void soln(){\n\t\tString s = nextLine();\n\t\tHashSet hs = new HashSet();\n\t\ths.add(s);\n\t\tString temp = s;\n\t\tfor\t(int i=0;i= 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 static 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 static 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 static 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 static 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 static 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\t \n\tprivate static 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 static void pArray(int[] arr){\n\t\tfor (int i=0; i 0) \n { \n // If y is odd, multiply x \n // with result \n if((y & 1)==1) \n res = (res * x) % p; \n \n // y must be even now \n // y = y / 2 \n y = y >> 1; \n x = (x * x) % p; \n } \n return res; \n } \n \n\n}\n", "lang_cluster": "Java", "tags": ["math", "combinatorics"], "code_uid": "0949630df34196dd1811b6ae3ca9403b", "src_uid": "71029e5bf085b0f5f39d1835eb801891", "difficulty": 1500.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 scan = new Scanner(System.in);\n\n String[] line = scan.nextLine().split(\" \");\n int n1 = Integer.parseInt(line[0]);\n int n2 = Integer.parseInt(line[1]);\n int k1 = Integer.parseInt(line[2]);\n int k2 = Integer.parseInt(line[3]);\n\n boolean firstPlayerTurn = true;\n\n while (true) {\n if (firstPlayerTurn) {\n if (n1 == 0) {\n System.out.println(\"Second\");\n return;\n } else {\n n1--;\n }\n } else {\n if (n2 == 0) {\n System.out.println(\"First\");\n return;\n } else {\n n2--;\n }\n }\n\n firstPlayerTurn = !firstPlayerTurn;\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "constructive algorithms"], "code_uid": "707dd5b6dd22a7a93bdc4d754cc4ad0d", "src_uid": "aed24ebab3ed9fd1741eea8e4200f86b", "difficulty": 800.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 Niyaz Nigmatullin\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\n final int MOD = 1000000007;\n\n public void solve(int testNumber, FastScanner in, FastPrinter out) {\n char[] c = in.next().toCharArray();\n int n = c.length;\n long ans = 0;\n long t = 1;\n for (int i = 0; i + 1 < n; i++) t = t * 2 % MOD;\n for (int i = 0; i < n; i++) {\n if (c[i] == '0') continue;\n long cur = t;\n for (int j = i + 1; j < n; j++) cur = cur * 2 % MOD;\n ans = (ans + cur) % MOD;\n }\n out.println(ans);\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 public String next() {\n StringBuilder sb = new StringBuilder();\n int c = read();\n while (isWhiteSpace(c)) {\n c = read();\n }\n if (c < 0) {\n return null;\n }\n while (c >= 0 && !isWhiteSpace(c)) {\n sb.appendCodePoint(c);\n c = read();\n }\n return sb.toString();\n }\n\n static boolean isWhiteSpace(int c) {\n return c >= 0 && c <= 32;\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": ["math", "combinatorics"], "code_uid": "4ac1d478bbdff8e2f280ce8cbf6b81f9", "src_uid": "89b51a31e00424edd1385f2120028b9d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.util.*;\nimport java.io.*;\n\npublic class FriendsandPresents {\n\n\tstatic long cnt1;\n\tstatic long cnt2;\n\tstatic long x;\n\tstatic long y;\n\t\n\tpublic static void main(String[] args) throws IOException, FileNotFoundException {\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\t//BufferedReader in = new BufferedReader(new FileReader(\"FriendsandPresents\"));\n\n\t\tStringTokenizer st = new StringTokenizer(in.readLine());\n\t\tcnt1 = Integer.parseInt(st.nextToken());\n\t\tcnt2 = Integer.parseInt(st.nextToken());\n\t\tx = Integer.parseInt(st.nextToken());\n\t\ty = Integer.parseInt(st.nextToken());\n\t\t\n\t\tlong min = 1;\n\t\tlong max = (long)(1e10);\n\t\twhile (min < max) {\n\t\t\tlong middle = (min +max)/2;\n\t\t\tif (check(middle)) {\n\t\t\t\tmax = middle;\t\n\t\t\t}\n\t\t\telse min = middle+1;\n\t\t}\n\t\t\n\t\tSystem.out.println(min);\n\t\t\n\t}\n\t\n\tpublic static boolean check(long num) {\n\t\tlong divnone = num - (num/x + num/y - num/(x*y));\n\t\tlong divy = num/y - num/(x*y);\n\t\tlong divx = num/x - num/(x*y);\n\t\tlong c1_left = cnt1 - divy;\n\t\tif (c1_left<0) c1_left=0;\n\t\tlong c2_left = cnt2 - divx;\n\t\tif (c2_left<0) c2_left=0;\n\t\treturn c2_left + c1_left <= divnone;\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "binary search"], "code_uid": "92bda087c7dea12c7c8fca2b61f1f498", "src_uid": "ff3c39b759a049580a6e96c66c904fdc", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "\nimport java.util.Scanner;\n\n\n\npublic class DeclinedFinalist {\n\n\tpublic static void main(String[] args) {\n\t\t/*\n\t\t * first convert input string to integer value\n\t\t * for this problem is n array lenght and array itself\n\t\t */\n\t\tScanner sc = new Scanner(System.in);\n\t\tString str1 = sc.nextLine();\n\t\tString str2 = sc.nextLine();\n\t\tsc.close();\n\t\t\n\t\t/*\n\t\t * first argument evaluation\n\t\t */\n\t\tint K = 0;\n\t\ttry {\n\t\t\tK = Integer.valueOf(str1);\n\t\t} catch (Exception e) {\n\t\t\tSystem.err.println(\"Not valid input!\");\n\t\t}\n\t\t\n\t\tif((K < 1) | (K > 25)) {\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tint[] arr = stringTointArray(str2, 1, 1000000);\n\t\t\n\t\t/*\n\t\t * actual algorithm (after filtering data)\n\t\t */\n\t\t\n\t\tint max_finalist = 25;\n\t\t\n\t\tfor (int i = 0; i < (arr.length); i++) {\n\t\t\tif (arr[i] == 1000000) {\n\t\t\t\tSystem.out.println((1000000 - 25));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif(arr[i] > max_finalist) {\n\t\t\t\tmax_finalist = arr[i];\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println((max_finalist - 25));\n\t\t\n\t}\n\t\n\t/**\n\t * Method convert string to integer array in range min to max\n\t * @param in\tinput string\n\t * @param min\tminimal integer value of array element\n\t * @param max\tmaximal integer value of array element\n\t * @return\t\tarray of integer created from string\n\t */\n\tprivate static int[] stringTointArray(String in, int min, int max) {\n\t\tString[] str_arr = in.split(\" \");\n\t\tint[] out = new int[str_arr.length];\n\t\t\n\t\ttry {\n\t\t\tfor (int i = 0; i < out.length; i++) {\n\t\t\t\tout[i] = Integer.valueOf(str_arr[i]);\n\t\t\t\tif ((out[i] < min) | (out[i] > max)) {\n\t\t\t\t\tSystem.err.println(\"Input data out of range!\");\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (Exception e) {\n\t\t\tSystem.err.println(\"Wrong input data!\");\n\t\t\treturn null;\n\t\t}\n\t\t\n\t\treturn out;\n\t}\n\t\n\t\n}\n", "lang_cluster": "Java", "tags": ["greedy", "implementation"], "code_uid": "94a8bd18a1ffe0d6565aecd66e8493d0", "src_uid": "ef657588b4f2fe8b2ff5f8edc0ab8afd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n \npublic class Main\n{\n\t//Fast IO class\n static class FastReader \n { \n BufferedReader br; \n StringTokenizer st; \n public FastReader() \n { \n \tboolean env=System.getProperty(\"ONLINE_JUDGE\") != null;\n \tif(!env) {\n \t\ttry {\n\t\t\t\t\tbr=new BufferedReader(new FileReader(\"src\\\\input.txt\"));\n\t\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n \t}\n \telse {\n \t\tbr = new BufferedReader(new\n InputStreamReader(System.in)); \n \t}\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 int nextInt() \n { \n return Integer.parseInt(next()); \n } \n long nextLong() \n { \n return Long.parseLong(next()); \n } \n double nextDouble() \n { \n return Double.parseDouble(next()); \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 static long MOD=1000000000+7;\n //Euclidean Algorithm\n static long gcd(long A,long B){\n if(B==0) return A;\n return gcd(B,A%B);\n }\n //Modular Exponentiation\n static long fastExpo(long x,long n){\n if(n==0) return 1;\n if((n&1)==0) return fastExpo((x*x)%MOD,n/2)%MOD;\n return ((x%MOD)*fastExpo((x*x)%MOD,(n-1)/2))%MOD;\n }\n //Prime Number Algorithm\n static boolean isPrime(long n){\n if(n<=1) return false;\n if(n<=3) return true;\n if(n%2==0 || n%3==0) return false;\n for(int i=5;i*i<=n;i+=6)\n if(n%i==0 || n%(i+2)==0) return false;\n return true;\n }\n //Sieve of eratosthenes\n static int[] findPrimes(int n){\n boolean isPrime[]=new boolean[n+1];\n ArrayList a=new ArrayList<>();\n int result[];\n Arrays.fill(isPrime,true);\n isPrime[0]=false;\n isPrime[1]=false;\n for(int i=2;i*i<=n;++i)\n if(isPrime[i]==true)\n for(int j=i*i;j<=n;j+=i) isPrime[j]=false;\n for(int i=0;i<=n;i++) if(isPrime[i]==true) a.add(i);\n result=new int[a.size()];\n for(int i=0;i0) {\n \tlong n=sc.nextLong();\n \tArrayList a=new ArrayList<>();\n \tfor(long i=2;i*i<=n;i++) {\n \t\tif(n%i==0) {\n \t\t\tif(i*i==n) a.add(i);\n \t\t\telse {\n \t\t\t\ta.add(i);\n \t\t\t\ta.add(n/i);\n \t\t\t}\n \t\t}\n \t}\n \tlong ans=0;\n \ta.add(n);\n \tfor(Long x: a) ans=gcd(ans,x);\n \tSystem.out.println(ans);\n }\n }\n}", "lang_cluster": "Java", "tags": ["number theory"], "code_uid": "e27f0d67b4d3bbc3661f2dab4972435f", "src_uid": "f553e89e267c223fd5acf0dd2bc1706b", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.math.BigInteger;\nimport java.util.Scanner;\n\npublic class Main {\n\n\tpublic static void main(String[] args) {\n\t\tScanner scanner = new Scanner(System.in);\n\n\t\tString line = scanner.nextLine();\n\n\t\tBigInteger n = new BigInteger(line);\n\t\tBigInteger b2 = new BigInteger(\"2\");\n\t\t\n\t\tBigInteger soma = n.multiply(n).add(n).divide(b2).mod(b2);\n\t\t\n\t\tscanner.close();\n\t\t\n\t\tSystem.out.println(soma.intValue());\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "20518e592f2b2ca7fe3a5087aee739be", "src_uid": "fa163c5b619d3892e33e1fb9c22043a9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.awt.geom.*;\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.util.regex.*;\nimport static java.lang.Math.*;\npublic class A {\n\n public A() throws Exception {\n int k = in.nextInt();\n int b = in.nextInt();\n int n = in.nextInt();\n int t = in.nextInt();\n\n long cur = 1;\n for (int i=0; it) {\n System.out.println(n-i); \n break;\n }\n }\n if (cur<=t) {\n System.out.println(0); \n }\n }\n\n Scanner in = new Scanner(System.in);\n public static void main(String[] args) throws Exception { // {{{\n new A();\n } // }}}\n public static void debug(Object... arr) { // {{{\n System.err.println(Arrays.deepToString(arr));\n } // }}}\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "e46cb8aca905b29c2a80d13e3d1db9d0", "src_uid": "e2357a1f54757bce77dce625772e4f18", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n \npublic class Main {\n\tpublic static void main(String args[]) {new Main().work();}\n\t\n\tScanner in = new Scanner(System.in);\n\tPrintWriter out = new PrintWriter(System.out);\n\tvoid work() {\t\t\n\t\tint n=in.nextInt();\n\t\tString str=in.next();\n\t\tlong[][] dp=new long[n][n];\n\t\tout.println(dfs(str,0,n-1,dp));\n\t\tout.flush();\n\t}\n\t\n\tlong dfs(String str,int s,int e,long[][] dp){\n\t if(s>e) return 0;\n\t if(dp[s][e]>0) return dp[s][e];\n\t dp[s][e]=1+dfs(str,s+1,e,dp);\n for(int i=s+1;i<=e;i++){\n if(str.charAt(i)==str.charAt(s)){\n dp[s][e]=Math.min(dfs(str,s+1,i-1,dp)+dfs(str,i,e,dp),dp[s][e]);\n }\n }\t \n return dp[s][e];\n\t}\n}", "lang_cluster": "Java", "tags": ["dp"], "code_uid": "9f36dc29c2b6ccfdbfdfae7ae01c0cee", "src_uid": "516a89f4d1ae867fc1151becd92471e6", "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.time.Year;\nimport java.util.Scanner;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author programajor\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 public void solve(int testNumber, Scanner in, PrintWriter out) {\n long y = in.nextLong();\n double count = 0;\n boolean isYearLeap = Year.isLeap(y);\n long next = y + 1;\n while (true) {\n boolean isCurrLeap = Year.isLeap(next);\n if (isCurrLeap) {\n count += 2;\n } else {\n count += 1;\n }\n next++;\n if (count % 7 == 0 && isCurrLeap == isYearLeap) {\n break;\n }\n }\n out.print(next - 1);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "d261e147447e28b227f4c4922a32217b", "src_uid": "565bbd09f79eb7bfe2f2da46647af0f2", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.PriorityQueue;\n\npublic class A {\n\tpublic static void main(String args[])throws Exception {\n\t\tBufferedReader input = new BufferedReader(\n\t\t\t\tnew InputStreamReader(System.in));\n\t\t\n\t\tString[] tokens = input.readLine().split(\" \");\n\t\tint n = Integer.parseInt(tokens[0]);\n\n\t\ttokens = input.readLine().split(\" \");\n\t\tint orig = Integer.parseInt(tokens[0]);\n\t\tPriorityQueue q = new PriorityQueue(1,new A.reverseCompare());\n\t\t\n\t\tint bribes = 0;\n\t\tfor(int i=1;i=orig) {\n\t\t\t\tq.add(x-1);\n\t\t\t\torig++;\n\t\t\t}\n\t\t\telse\n\t\t\t\tbreak;\n\t\t\t\n\t\t\tbribes++;\n\t\t}\n\t\tSystem.out.println(bribes);\n\t}\n\t\n\tpublic static class reverseCompare implements Comparator{\n\n\t\t@Override\n\t\tpublic int compare(Integer arg0, Integer arg1) {\n\t\t\tif(arg0 > arg1)\n\t\t\t\treturn -1;\n\t\t\tif(arg0 < arg1)\n\t\t\t\treturn 1;\n\t\t\treturn 0;\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "tags": ["greedy", "implementation"], "code_uid": "58197011add8a3eae5f6d8d5c098d759", "src_uid": "aa8fabf7c817dfd3d585b96a07bb7f58", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Main {\n \n static final double eps = 1e-8;\n static int mod = 1000 * 1000 * 1000 + 9;\n static int n, m; \n \n \n public static void main(String[] args) throws IOException {\n try {\n String s = sc.next();\n String ans = \"\";\n if(s.charAt(0) == 'f')\n {\n ans += \"ftp://\";\n s = s.substring(3);\n }\n else\n {\n ans += \"http://\";\n s = s.substring(4);\n }\n int pos;\n if(s.charAt(0) == 'r')\n {\n pos = s.substring(1).indexOf(\"ru\") + 1;\n \n }\n else\n pos = s.indexOf(\"ru\");\n ans += s.substring(0, pos);\n ans += \".ru\";\n if(pos + 2 < s.length())\n ans += \"/\" + s.substring(pos + 2);\n pw.println(ans);\n }\n finally {\n pw.close();\n }\n }\n\n\n static Scanner sc = new Scanner(System.in);\n static PrintWriter pw = new PrintWriter(System.out);\n static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n static StringTokenizer st ;\n static int nextInt() throws IOException {\n in.nextToken();\n return (int) in.nval;\n }\n static long nextLong() throws IOException {\n in.nextToken();\n return (long) in.nval;\n }\n static double nextDouble() throws IOException {\n in.nextToken();\n return in.nval;\n }\n static String next() throws IOException {\n in.nextToken();\n return in.sval;\n }\n static void outArray(int[] O) {\n for(int i = 0; i < O.length - 1; i++)\n pw.print(O[i] + \" \");\n pw.println(O[O.length - 1]);\n }\n static void exit(Object arg)\n {\n pw.println(arg);\n pw.flush();\n System.exit(0);\n }\n}", "lang_cluster": "Java", "tags": ["strings", "implementation"], "code_uid": "14c946fd9c5ad6cfd092e8a19176bbbf", "src_uid": "4c999b7854a8a08960b6501a90b3bba3", "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.StringTokenizer;\n\npublic class BearAndFiveCards {\n\tpublic static BufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n\tpublic static StringTokenizer st;\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tint[] a = intArray(5);\n\t\tint sum = 0;\n\t\tfor (int x : a)\n\t\t\tsum += x;\n\t\tint min = sum;\n\t\tfor (int i = 0; i < 5; i++) {\n\t\t\tint count = 0;\n\t\t\tfor (int j = 0; j < 5; j++)\n\t\t\t\tif (a[j] == a[i])\n\t\t\t\t\tcount++;\n\t\t\tif (count > 3)\n\t\t\t\tcount = 3;\n\t\t\tif (count != 1)\n\t\t\t\tmin = Math.min(min, sum - count*a[i]);\n\t\t}\n\t\t\n\t\tSystem.out.println(min);\n\t}\n\t\n\tpublic static String nextLine() throws IOException {\n\t\treturn f.readLine();\n\t}\n\t\n\tpublic static String nextString() throws IOException {\n\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\tst = new StringTokenizer(f.readLine());\n\t\treturn st.nextToken();\n\t}\n\t\n\tpublic static int nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextString());\n\t}\n\t\n\tpublic static long nextLong() throws IOException {\n\t\treturn Long.parseLong(nextString());\n\t}\n\t\n\tpublic static int[] intArray(int n) throws IOException {\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}", "lang_cluster": "Java", "tags": ["constructive algorithms", "implementation"], "code_uid": "26be5bedd164b77e2f92e075f7ff9512", "src_uid": "a9c17ce5fd5f39ffd70917127ce3408a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n/**\n * Built using CHelper plug-in Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputReader in = new InputReader(System.in);\n\t\tPrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), true);\n\t\tTaskB solver = new TaskB();\n\t\tsolver.solve(1, in, out);\n\t\tout.flush();\n\t\tout.close();\n\t}\n}\n\nclass Pair {\n\tint first;\n\tint second;\n\n\tPair(int first, int second) {\n\t\tthis.first = first;\n\t\tthis.second = second;\n\t}\n}\n\nclass TaskB {\n\n\tpublic void solve(int testNumber, InputReader in, PrintWriter pw) {\n\t\tint x1 = in.nextInt();\n\t\tint y1 = in.nextInt();\n\t\tlong sum = 0;\n\t\tfor (int i = x1; i <= y1; i++) {\n\t\t\tlong sum1 = 0;\n\t\t\tint temp = i;\n\t\t\twhile (temp > 0) {\n\t\t\t\tint rem = temp % 10;\n\t\t\t\ttemp /= 10;\n\t\t\t\tsum1 += getInt(rem);\n\t\t\t}\n\t\t\tsum += sum1;\n\t\t}\n\t\tpw.println(sum);\n\t}\n\n\tpublic int getInt(int num) {\n\t\tint ret = -1;\n\t\tswitch (num) {\n\t\tcase 0:\n\t\t\tret = 6;\n\t\t\tbreak;\n\t\tcase 1:\n\t\t\tret = 2;\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tret = 5;\n\t\t\tbreak;\n\t\tcase 3:\n\t\t\tret = 5;\n\t\t\tbreak;\n\t\tcase 4:\n\t\t\tret = 4;\n\t\t\tbreak;\n\t\tcase 5:\n\t\t\tret = 5;\n\t\t\tbreak;\n\t\tcase 6:\n\t\t\tret = 6;\n\t\t\tbreak;\n\t\tcase 7:\n\t\t\tret = 3;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tret = 7;\n\t\t\tbreak;\n\t\tcase 9:\n\t\t\tret = 6;\n\t\t\tbreak;\n\t\t}\n\t\treturn ret;\n\t}\n\n\tpublic int isPow(long num) {\n\t\tint count = 0;\n\t\twhile (num > 0) {\n\t\t\tnum /= 2;\n\t\t\tcount++;\n\t\t}\n\t\treturn count;\n\t}\n}\n\nclass InputReader {\n\tBufferedReader br;\n\tStringTokenizer st;\n\n\tpublic InputReader(InputStream in) {\n\t\tbr = new BufferedReader(new InputStreamReader(in));\n\t\tst = null;\n\t}\n\n\tpublic String next() {\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\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", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "cc65f17796f755be11fc64554be9ec84", "src_uid": "1193de6f80a9feee8522a404d16425b9", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "\nimport java.util.Map;\nimport java.util.Scanner;\nimport java.util.TreeMap;\n\npublic class A106 {\n\tpublic static void main (String args[]){\n\t\tScanner in = new Scanner(System.in);\n\t\tchar hokm = in.next().charAt(0);\n\t\tchar[] a = in.next().toCharArray();\n\t\tchar[] b = in.next().toCharArray();\n\t\tMap m = new TreeMap();\n\t\tm.put('6', 6);m.put('7', 7);m.put('8', 8);m.put('9', 9);m.put('T',10);\n\t\tm.put('J', 11);m.put('Q', 12);m.put('K', 13);m.put('A', 14);\n\t\tif(a[1]==b[1]){\n\t\t\tif(m.get(a[0])>m.get(b[0]))\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\telse\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t}\n\t\telse {\n\t\t\tif(a[1]==hokm)\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\telse if(b[1]==hokm)\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t\telse\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "a5674f123788837b19569837997dd4a0", "src_uid": "da13bd5a335c7f81c5a963b030655c26", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class P2 {\n\tstatic int find (long x) {\n\t\tif (x < 2)\n\t\t\treturn 0;\n\t\tint bc = 0, zc = 0, zp = -1;\n\t\tlong b = x;\n\t\twhile (b > 0) {\n\t\t\tbc++;\n\t\t\tif ((b & 1) == 0) {\n\t\t\t\tzc++;\n\t\t\t\tzp = bc;\n\t\t\t}\n\t\t\tb >>= 1;\n\t\t}\n\t\tlong p = 0;\n\t\tif (zc == 0)\n\t\t\tp = x - 1;\n\t\telse if (zc == 1)\n\t\t\tp = x;\n\t\telse {\n\t\t\tfor (int i = 1; i < bc - zp; i++) {\n\t\t\t\tp = p << 1;\n\t\t\t\tp = p | 1;\n\t\t\t}\n\t\t\tp = p << 1;\n\t\t\tfor (int i = 0; i < zp; i++) {\n\t\t\t\tp = p << 1;\n\t\t\t\tp = p | 1;\n\t\t\t}\n\t\t\tif ((p & (p + 1)) == 0)\n\t\t\t\tp--;\n\t\t}\n\t\tbc = 0;\n\t\tzp = -1;\n\t\tb = p;\n\t\twhile (b > 0) {\n\t\t\tbc++;\n\t\t\tif ((b & 1) == 0)\n\t\t\t\tzp = bc;\n\t\t\tb >>= 1;\n\t\t}\n\t\tint ans = 0;\n\t\tfor (int i = 2; i < bc; i++)\n\t\t\tans += (i - 1);\n\t\tans += (bc - zp);\n\t\treturn ans;\n\t}\n\tpublic static void main (String[] args) {\n\t\tScanner sc = new Scanner (System.in);\n\t\tPrintStream op = System.out;\n\t\tlong a = sc.nextLong();\n\t\tlong b = sc.nextLong();\n\t\tif (a > b) {\n\t\t\tlong t = a;\n\t\t\ta = b;\n\t\t\tb = t;\n\t\t}\n\t\tint av = find (a - 1);\n\t\tint bv = find (b);\n\t\top.println(bv - av);\n\t\tsc.close();\n\t\top.close();\n\t}\n}\n", "lang_cluster": "Java", "tags": ["brute force", "implementation", "bitmasks"], "code_uid": "536969ad580de2a80af1be2f84085aa2", "src_uid": "581f61b1f50313bf4c75833cefd4d022", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class task\n{\n\tpublic static void main(String[] Args)\n\t{\n\t\tScanner sc=new Scanner(System.in);\n\t\tint n=sc.nextInt(),a[]=new int[7],i,sum=0,ze=6;\n\t\tfor (i=0;i!=7;++i)\n\t\t{\n\t\t\ta[i]=sc.nextInt();\n\t\t\tsum+=a[i];\n\t\t\tif (a[i]!=0)\n\t\t\t\tze=i;\n\t\t}\n\t\tn=n%sum;\n\t\tif (n!=0)\n\t\t\tfor (i=0;i!=7 && n>0;++i)\n\t\t\t\tn-=a[i];\n\t\telse\n\t\t\ti=ze+1;\t\t\n\t\tSystem.out.println(i);\n\t}\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "8e26758bd997ce9804f8d5955f0b48f7", "src_uid": "007a779d966e2e9219789d6d9da7002c", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "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 A1 {\n \n public static void main(String[] args) throws IOException {\n PrintWriter out = new PrintWriter(System.out);\n sc = new StringTokenizer(br.readLine());\n char[] s = nxtCharArr();\n boolean[] a = new boolean[10];\n int q = 0;\n for (int i = 0; i < s.length; i++) {\n if (s[i] == '?')\n q++;\n else if (s[i] >= 'A' && s[i] <= 'J')\n a[s[i] - 'A'] = true;\n }\n long ans = 1;\n if (s[0] == '?') {\n ans *= 9;\n q--;\n }\n while (q-- > 0)\n ans *= 10;\n int c = 0;\n for (int i = 0; i < a.length; i++)\n c += a[i] ? 1 : 0;\n int st = 10;\n if (s[0] >= 'A' && s[0] <= 'J') {\n ans *= 9;\n c--;\n st--;\n }\n while (c-- > 0)\n ans *= st--;\n out.println(ans);\n br.close();\n out.close();\n }\n \n static BufferedReader br = new BufferedReader(new InputStreamReader(\n System.in));\n \n static StringTokenizer sc;\n \n static String nxtTok() throws IOException {\n while (!sc.hasMoreTokens()) {\n String s = br.readLine();\n if (s == null)\n return null;\n sc = new StringTokenizer(s.trim());\n }\n return sc.nextToken();\n }\n \n static int nxtInt() throws IOException {\n return Integer.parseInt(nxtTok());\n }\n \n static long nxtLng() throws IOException {\n return Long.parseLong(nxtTok());\n }\n \n static double nxtDbl() throws IOException {\n return Double.parseDouble(nxtTok());\n }\n \n static int[] nxtIntArr(int n) throws IOException {\n int[] a = new int[n];\n for (int i = 0; i < n; i++)\n a[i] = nxtInt();\n return a;\n }\n \n static long[] nxtLngArr(int n) throws IOException {\n long[] a = new long[n];\n for (int i = 0; i < n; i++)\n a[i] = nxtLng();\n return a;\n }\n \n static char[] nxtCharArr() throws IOException {\n return nxtTok().toCharArray();\n }\n}", "lang_cluster": "Java", "tags": ["greedy"], "code_uid": "65c2483b707bb0facba1ec507a2d789e", "src_uid": "d3c10d1b1a17ad018359e2dab80d2b82", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "\nimport static java.util.Arrays.*;\nimport static java.lang.Math.*;\nimport java.util.*;\nimport java.io.*;\n\npublic class Main implements Runnable\n{\n\tpublic static void main(String [] args) throws IOException\n\t{\n\t\tnew Thread(null, new Main(), \"\", 1 << 20).start();\n\t}\n\t\n\tString file = \"input\";\n\tBufferedReader input;\n\tPrintWriter out;\n\t\n\tpublic void run() \n\t{\n\t\ttry\n\t\t{\n\t\t\t//input = new BufferedReader(new FileReader(file + \".in\"));\n\t\t\tinput = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(new BufferedOutputStream(System.out));\n\t\t\tsolve();\n\t\t\tout.close();\n\t\t}\n\t\tcatch(Exception e)\n\t\t{\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n\tlong[][][] dp = new long[36][36][36];\n\tvoid solve() throws IOException\n\t{\n\t\tStringTokenizer st = tokens();\n\t\tint n = nextInt(st), H = nextInt(st);\n\t\tthis.H = H;\n\t\tfor(long[][] t1 : dp) for(long[] t2 : t1) fill(t2, -1);\n\t\tlong res = 0;\n\t\tfor(int i = 1; i <= n; i++) \n\t\t\tfor(int h = H; h <= n; h++)\n\t\t\t{\n\t\t\t\tres += get(i - 1, n - i, h - 1);\n\t\t\t\t//print(i - 1, n - i, h - 1, get(i - 1, n - i, h - 1));\n\t\t\t}\n\t\tout.println(res);\n\t}\n\tint H;\n\tlong get(int left, int right, int h)\n\t{\n\t\tif(h == 0)\n\t\t{\n\t\t\tif(left == 0 && right == 0) return 1;\n\t\t\treturn 0;\n\t\t}\n\t\tif(dp[left][right][h] != -1) return dp[left][right][h];\n\t\t\n\t\tif(h > max(left, right))\n\t\t{\n\t\t\tdp[left][right][h] = 0;\n\t\t\treturn 0;\n\t\t}\t\n\t\tlong res = 0;\n\t\tif(left > 0 && right > 0)\n\t\t{\n\t\t\tfor(int i = 0; i < left; i++)\n\t\t\t\tfor(int j = 0; j < right; j++)\n\t\t\t\t{\n\t\t\t\t\tfor(int k = 0; k <= h - 2; k++)\n\t\t\t\t\t{\n\t\t\t\t\t\tres += get(i, left - i - 1, k) * get(j, right - j - 1, h - 1);\n\t\t\t\t\t\tres += get(i, left - i - 1, h - 1) * get(j, right - j - 1, k);\t\n\t\t\t\t\t}\n\t\t\t\t\tres += get(i, left - i - 1, h - 1) * get(j, right - j - 1, h - 1);\n\t\t\t\t}\n\t\t\t\n\t\t}\n\t\tif(left > 0 && right == 0)\n\t\t{\n\t\t\tfor(int i = 0; i < left; i++) res += get(i, left - i - 1, h - 1);\n\t\t}\n\t\tif(right > 0 && left == 0)\n\t\t{\n\t\t\tfor(int i = 0; i < right; i++) res += get(i, right - i - 1, h - 1);\n\t\t}\n\t\t//print(left, right, h, res);\n\t\treturn dp[left][right][h] = res;\n\t}\n\n\tStringTokenizer tokens() throws IOException\n\t{\n\t\treturn new StringTokenizer(input.readLine());\n\t}\n\t\n\tString next(StringTokenizer st)\n\t{\n\t\treturn st.nextToken();\n\t}\n\t\n\tint nextInt() throws IOException\n\t{\n\t\treturn Integer.parseInt(input.readLine());\n\t}\n\t\n\tint nextInt(StringTokenizer st)\n\t{\n\t\treturn Integer.parseInt(st.nextToken());\n\t}\n\t\n\tdouble nextDouble() throws IOException\n\t{\n\t\treturn Double.parseDouble(input.readLine());\n\t}\n\t\n\tdouble nextDouble(StringTokenizer st)\n\t{\n\t\treturn Double.parseDouble(st.nextToken());\n\t}\n\t\n\tvoid print(Object... o)\n\t{\n\t\tout.println(deepToString(o));\n\t}\n}", "lang_cluster": "Java", "tags": ["divide and conquer", "dp", "combinatorics"], "code_uid": "f3655497f0cf8811769e0117811cf41a", "src_uid": "faf12a603d0c27f8be6bf6b02531a931", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.lang.*;\nimport java.util.*;\nimport java.io.*;\npublic class test\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 test c=new test();\n c.prop();\n }\n public void prop() \n {\n int n,a,x=0,b,c ;\n n=sc.nextInt();\n a=sc.nextInt();\n if(a>15)\n x=15 ;\n for (int i=1;i15 && x==0)\n x=a+15 ;\n a=b ; \n } \n \n c=90-a ;\n if(c>15 && x==0)\n x=a+15 ;\n else if(x==0)\n x=90 ; \n pr.println(x);\n \n }\n \n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "65f067da91aa018f7ccd620ba548934b", "src_uid": "5031b15e220f0ff6cc1dd3731ecdbf27", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.Scanner;\n\n\npublic class CodeLab {\n\n\tpublic static void main(String[] args) {\n\tScanner sc=new Scanner(System.in);\n\tint n=sc.nextInt();\n\tint m=sc.nextInt();\n\tint maxIndex=1;\n\tint max=(int) Math.ceil(sc.nextInt()*1.0/m);\n\t\n\tfor(int i=1;i=max) {\n\t\t\tmax=(int) Math.ceil(x*1.0/m);\n\t\t\tmaxIndex=i+1;\n\t\t}\n\t}\n\tSystem.out.println(maxIndex);\n\t\n\t\n\t\n\t\n\t\n\tsc.close();\n\t}\n\t\n\t\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "3e1406a21bae63042a6eba5cd60c2dc5", "src_uid": "c0ef1e4d7df360c5c1e52bc6f16ca87c", "difficulty": 1000.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\npublic class Main implements Runnable {\n\n\tprivate void solve() throws IOException {\n\t\tchar[] s = next().toCharArray();\n\t\tint n = s.length;\n\t\tint ans = 0;\n\t\tint k = 0;\n\t\tchar last = '?';\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tif (last == '?' || s[i] == last) {\n\t\t\t\t++k;\n\t\t\t\tlast = s[i];\n\t\t\t\tif (k == 5) {\n\t\t\t\t\tlast = '?';\n\t\t\t\t\tk = 0;\n\t\t\t\t\t++ans;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tk = 1;\n\t\t\t\tlast = s[i];\n\t\t\t\t++ans;\n\t\t\t}\n\t\t}\n\t\tif (k != 0) ++ans;\n\t\tout.println(ans);\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tString next() throws IOException {\n\t\twhile (!st.hasMoreTokens()) {\n\t\t\tString line = in.readLine();\n\t\t\tif (line == null) return null;\n\t\t\teat(line);\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew Thread(null, new Main(), \"Main\", 1 << 28).start();\n\t}\n\n\tprivate BufferedReader in;\n\tprivate PrintWriter out;\n\tprivate StringTokenizer st;\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\teat(\"\");\n\t\t\tsolve();\n\t\t\tin.close();\n\t\t\tout.close();\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(566);\n\t\t}\n\t}\n\n\tprivate void eat(String s) {\n\t\tst = new StringTokenizer(s);\n\t}\n\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "41422ebf2dfadbb884f5e7a8cb7f9f24", "src_uid": "5257f6b50f5a610a17c35a47b3a0da11", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\n\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 MainB {\n\n\n\t\n\tpublic static void B () throws IOException {\n\t\tMyScanner sc = new MyScanner(System.in);\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\tStringTokenizer st;\n\t\t\n\t\tst = new StringTokenizer(sc.nextLine(),\":\");\n\t\tint h = Integer.parseInt(st.nextToken());\n\t\tint m = Integer.parseInt(st.nextToken());\n\t\t\n\t\tint inc = sc.nextInt();\n\t\tint incH = (inc/60)%24;\n\t\tint incM = inc%60;\n\t\n\t\tif (incM + m >= 60){\n\t\t\tm = incM + m - 60;\n\t\t\t//if(incH == 0)\n\t\t\t\tincH += 1;\n\t\t\tif (h + incH > 23){\n\t\t\t\th = incH + h - 24;\n\t\t\t}\n\t\t\telse {\n\t\t\t\th = h + incH;\n\t\t\t}\n\t\t}\n\t\t\n\t\telse {\n\t\t\tm = incM + m;\n\t\t\tif (h + incH > 23){\n\t\t\t\th = incH + h - 24;\n\t\t\t}\n\t\t\telse\n\t\t\t\th = h + incH;\n\t\t}\n\t\t//System.out.println(m%100);\n\t\tString hour = \"\";\n\t\tString min = \"\";\n\t\tif ( (h / 10)%10 == 0)\n\t\t\thour = \"0\" + h % 10;\n\t\telse\n\t\t\thour = \"\" + h;\n\t\t\n\t\tif ( (m / 10)% 10 == 0)\n\t\t\tmin = \"0\" + m;\n\t\telse\n\t\t\tmin = \"\" + m;\n\t\tpw.println(hour + \":\" +min);\n\t\tpw.close();\n\t}\n\t\n\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\n\t\t\n\t\tB();\n\t\t\n\t}\n\n\tstatic class MyScanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic MyScanner(InputStream s) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(s));\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": ["implementation"], "code_uid": "6e8b6e47511d85bd48c9970c3fccd8da", "src_uid": "20c2d9da12d6b88f300977d74287a15d", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "\nimport java.util.Scanner;\n\n\npublic class a {\n\tpublic static void main(String[] args) {\n\t\tScanner input = new Scanner(System.in);\n\t\tlong value = input.nextLong();\n\t\tint ans = 0;\n\t\tfor(int i = 1; i <= 100 ; i++){\n\t\t\tans = i;\n\t\n\t\t\tvalue++;\n\t\t\tString a = value + \"\";\n\t\t\tif((a).toString().contains(\"8\"))\n\t\t\t\tbreak;\n\t\t}\n\t\t\n\t\tSystem.out.println(ans);\n\t\t\n\t}\n}\n", "lang_cluster": "Java", "tags": ["brute force"], "code_uid": "a614b6d4ae21341ce76161e0fa11b4d1", "src_uid": "4e57740be015963c190e0bfe1ab74cb9", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\npublic class test011 {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint x = sc.nextInt();\n\t\tint y = sc.nextInt();\n\t\tif (y == 1 && x != 0 || y == 0) {\n\t\t\tSystem.out.println(\"NO\");\n\t\t\treturn;\n\t\t}\n\t\tint tmp = x - y + 1;\n\t\tif (tmp >= 0 && tmp % 2 == 0) {\n\t\t\tSystem.out.println(\"YES\");\n\t\t} else {\n\t\t\tSystem.out.println(\"NO\");\n\t\t}\n\n\t}\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "f8ca2febfd0202a0a740cb351d60926d", "src_uid": "1527171297a0b9c5adf356a549f313b9", "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.PrintWriter;\nimport java.util.List;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\nimport java.util.ArrayList;\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\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n\n\tstatic class TaskA {\n\t\tpublic void solve(int testNumber, FastScanner in, PrintWriter out) {\n\t\t\tint n = in.nextInt();\n\t\t\tint m = in.nextInt();\n\t\t\tint sz1 = getDigits(n - 1, -1).length;\n\t\t\tint sz2 = getDigits(m - 1, -1).length;\n\t\t\tif (sz1 + sz2 > 7) {\n\t\t\t\tout.println(0);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tint ans = 0;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tint[] c = new int[7];\n\t\t\t\tfor (int d : getDigits(i, sz1)) {\n\t\t\t\t\t++c[d];\n\t\t\t\t}\n\t\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\t\tint[] tmp = getDigits(j, sz2);\n\t\t\t\t\tfor (int d : tmp) {\n\t\t\t\t\t\t++c[d];\n\t\t\t\t\t}\n\t\t\t\t\tboolean ok = true;\n\t\t\t\t\tfor (int k = 0; k < c.length; k++) {\n\t\t\t\t\t\tif (c[k] > 1) {\n\t\t\t\t\t\t\tok = false;\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\tif (ok) {\n\t\t\t\t\t\t++ans;\n\t\t\t\t\t}\n\t\t\t\t\tfor (int d : tmp) {\n\t\t\t\t\t\t--c[d];\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 int[] getDigits(int x, int sz) {\n\t\t\tif (sz < 0 && x == 0) {\n\t\t\t\treturn new int[]{0};\n\t\t\t}\n\t\t\tList res = new ArrayList<>();\n\t\t\twhile (x > 0) {\n\t\t\t\tres.add(x % 7);\n\t\t\t\tx /= 7;\n\t\t\t}\n\t\t\twhile (res.size() < sz) {\n\t\t\t\tres.add(0);\n\t\t\t}\n\t\t\tint[] r = new int[res.size()];\n\t\t\tfor (int i = 0; i < res.size(); i++) {\n\t\t\t\tr[i] = res.get(i);\n\t\t\t}\n\t\t\treturn r;\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 int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t}\n}\n\n", "lang_cluster": "Java", "tags": ["brute force", "math", "dp", "combinatorics"], "code_uid": "52de8e2677dcd4f32d639bf08c79473c", "src_uid": "0930c75f57dd88a858ba7bb0f11f1b1c", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "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.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// class values{\n// double val;\n// long x1;\n// long x2;\n//\n// values(double val, long x1, long x2) {\n// this.val = val;\n// this.x1 = x1;\n// this.x2 = x2;\n// }\n// }\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n long t1 = in.nextInt();\n long t2 = in.nextInt();\n long x1 = in.nextInt(),x2 = in.nextInt();\n long t0 = in.nextInt();\n if (t1 == t2){\n out.print(x1+\" \"+x2);return;\n }\n double res = Double.MAX_VALUE;\n long y2 = 0,y1 = 0;\n\n// ArrayList arrayList = new ArrayList<>();\n here: for (long i = x1; i > -1; --i) {\n long left = -1;\n long right = x2 + 1;\n while (right - left > 1){\n long mid = right + left;\n mid >>= 1L;\n long mul = t2*mid + t1*i;\n double d = (double)mul;\n d /= (mid + i);\n if (mid + i == 0)d = 0;\n\n if (Double.valueOf(d).compareTo(Double.valueOf(t0)) >= 0)right = mid;\n else left = mid;\n }\n double pk = t2*right + t1*i;\n pk /= (right + i);\n if (Double.compare(pk,t0) < 0 || right > x2)continue here;\n// while (right + 1 <= x2){\n// double gk = t2*(right + 1) + t1*i;\n// gk /= (right + 1 + i);\n// if (Double.compare(pk,gk) == 0)right++;\n// else{\n// arrayList.add(new values(pk,i,right));\n// continue here;\n// }\n// }\n if (i == 0)right = x2;\n// arrayList.add(new values(pk,i,right));\n if (Double.compare(pk,res) <= 0){\n if (Double.compare(pk,res) == 0){\n if (right + i > y1 + y2){\n y1 = i;\n y2 = right;\n }\n continue;\n }\n else {\n res = pk;\n y1 = i;\n y2 = right;\n }\n }\n }\n out.print(y1+\" \"+y2+\"\\n\");\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 nextInt() {\n return Integer.parseInt(next());\n }\n\n\n}", "lang_cluster": "Java", "tags": ["brute force", "math", "binary search"], "code_uid": "19268a56afaefd6a725b31abdd9a29a4", "src_uid": "87a500829c1935ded3ef6e4e47096b9f", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class pBinary {\n InputStream is;\n PrintWriter pw;\n String INPUT = \"\";\n long L_INF = (1L << 60L);\n\n void solve() {\n int n = ni(), p = ni(), m;\n int x = 1;\n for (int i = 1; i < 32; i++) {\n n = n - p;\n if (n <= 0)\n break;\n if (check(n, i)) {\n pw.println(i);\n return;\n }\n }\n pw.println(-1);\n }\n\n private boolean check(int n, int x) {\n int c = 0,nn=n;\n while (n > 0) {\n int p = (int) (Math.log(n) /\n Math.log(2));\n n -= (int) Math.pow(2, p);\n c++;\n }\n return c <= x && x<=nn;\n }\n\n void run() throws Exception {\n //\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n is = System.in;\n pw = new PrintWriter(System.out);\n\n long s = System.currentTimeMillis();\n // int t = ni();\n // while (t-- > 0)\n solve();\n pw.flush();\n tr(System.currentTimeMillis() - s + \"ms\");\n }\n\n public static void main(String[] args) throws Exception {\n new pBinary().run();\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) 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) 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 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++) 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\n private boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\n private void tr(Object... o) {\n if (!oj) System.out.println(Arrays.deepToString(o));\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "math", "bitmasks"], "code_uid": "ddecbdb7a63e2203602a6ab5618b7e97", "src_uid": "9e86d87ce5a75c6a982894af84eb4ba8", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class slime\n{\n public static void main(String args[])\n {\n Scanner s= new Scanner(System.in);\n int n= s.nextInt();\n int c=2;\n int i=1, k=0, j;\n int a[]= new int[n];\n a[0]= 1;\n while(c<=n)\n {\n a[i]=1;\n j=i;\n while(j>0)\n {\n if(a[j]==a[j-1])\n {\n a[j-1]++;\n if(j!=i)\n i--;\n j--;\n }\n else\n {\n if(j==i)\n i++;\n break;\n }\n }\n c++;\n \n }\n for(k=0; k a = new HashMap ();\ns1=in.next();\nint i;\nfor (i=0;i<10;i++)\n{\ns2=in.next();\na.put(s2,i);\n}\n\nfor (i=0;i trigNumbers = new HashSet();\n\t\tfor (int i = 1; i <= 1000 ; i++) {\n\t\t\tint newNum = (i * (i + 1)) / 2;\n\t\t\ttrigNumbers.add(newNum);\n\t\t}\n\t\t\n\t\tif(trigNumbers.contains(num)) {\n\t\t\tSystem.out.println(\"YES\");\n\t\t} else {\n\t\t\tSystem.out.println(\"NO\");\n\t\t}\n\t}\n}", "lang_cluster": "Java", "tags": ["brute force", "math"], "code_uid": "fb7ab1870b6b3d44c8af0b0bea35a4e8", "src_uid": "587d4775dbd6a41fc9e4b81f71da7301", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "//package SBU_ACM;\n\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.Scanner;\n\nimport javax.management.modelmbean.ModelMBean;\n\npublic class eleven {\n\tpublic static ArrayList nums = new ArrayList();\n\tpublic static long MOD = 1000000007;\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner input = new Scanner(System.in);\n\t\t\n\t\tlong x = input.nextLong();\n\t\tlong y = input.nextLong();\n\t\t\n\t\tlong n = input.nextLong();\n\t\t\n\t\tif(n % 6 == 1)\n\t\t\tSystem.out.println((x + MOD) % MOD);\n\t\tif(n % 6 == 2)\n\t\t\tSystem.out.println((y + MOD) % MOD);\n\t\tif(n % 6 == 3)\n\t\t\tSystem.out.println((y - x + 3 * MOD) % MOD);\n\t\tif(n % 6 == 4)\n\t\t\tSystem.out.println((-x + MOD) % MOD);\n\t\tif(n % 6 == 5)\n\t\t\tSystem.out.println((-y + MOD) % MOD);\n\t\tif(n % 6 == 0)\n\t\t\tSystem.out.println((-y + x + 3 * MOD) % MOD);\n\t\t\n\t\t\n\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "884e2b96d0bd8ab4f4823fccef2edd18", "src_uid": "2ff85140e3f19c90e587ce459d64338b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "\nimport java.util.Scanner;\n\n/**\n ** Created by Alik on 10/23/2015.\n */\npublic class Problem_546A {\n public static void main(String[] args){\n Scanner in = new Scanner(System.in);\n int price = in.nextInt();\n int money = in.nextInt();\n int amount = in.nextInt();\n int sum = 0, result;\n\n for (int i = 1; i <= amount; i++){\n sum += price*i;\n }\n result = sum-money;\n if (result <= 0)\n result = 0;\n System.out.print(result);\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "math", "implementation"], "code_uid": "9bf07ebe8978ff061fcb58e8d3f96ad6", "src_uid": "e87d9798107734a885fd8263e1431347", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "//package javaapplication1;\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 */\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashSet;\nimport java.util.List;\nimport java.util.Set;\npublic class Main {\n public static void main(String[] args) throws IOException{\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n PrintWriter pw=new PrintWriter(new PrintStream(System.out));\n String zero=br.readLine();\n String x=br.readLine();\n ListL=new ArrayList<>();\n String res=\"o\";\n for (int i = 0; i < 51; i++) {\n res+=\"go\";\n L.add(res);\n }\n for (int i = L.size()-1; i >-1; --i) {\n x=x.replaceAll(L.get(i), \"***\");\n }\n System.out.println(x);\n }\n \n}", "lang_cluster": "Java", "tags": ["strings", "implementation"], "code_uid": "21548275e178373e6e7ad32c6e206f07", "src_uid": "619665bed79ecf77b083251fe6fe7eb3", "difficulty": 900.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.Locale;\nimport java.util.StringTokenizer;\n\npublic class Main implements Runnable {\n\n\tprivate void solve() throws IOException {\n\t\tlong n = nextLong();\n\t\tlong h = (long) Math.sqrt(n)+1;\n\t\tlong l = (long) (Math.sqrt(n+6561)-81)-1;\t\t\n\t\tlong ans = -1;\n\t\tfor( long i = l ; i <= h; ++i){\n\t\t\tif( f(i) == n ){\t\t\t\t\n\t\t\t\tans = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tout.println(ans);\n\t}\n\n\tprivate long f(long i) {\n\t\treturn i*i+sum(i)*i;\n\t}\n\n\tprivate long sum(long i) {\n\t\tlong ret = 0;\n\t\twhile( i >0 ){\n\t\t\tret += i%10;\n\t\t\ti/=10;\n\t\t}\n\t\treturn ret;\n\t}\n\n\t// private long f(long m) {\n\t//\n\t// return m * m + sum(m) - n;\n\t// }\n\t//\n\t// private long sum(long m) {\n\t// long ret = 0;\n\t// while (m > 0) {\n\t// ret += m % 10;\n\t// m /= 10;\n\t// }\n\t// return ret;\n\t// }\n\n\tint nextInt() throws NumberFormatException, IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tlong nextLong() throws NumberFormatException, IOException {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tdouble nextDouble() throws NumberFormatException, IOException {\n\t\treturn Double.parseDouble(next());\n\t}\n\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\n\tprivate void eat(String s) {\n\t\tst = new StringTokenizer(s);\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew Thread(null, new Main(), \"Main\", 1 << 26).start();\n\t}\n\n\tprivate BufferedReader in;\n\tprivate PrintWriter out;\n\tprivate StringTokenizer st;\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tLocale.setDefault(Locale.ENGLISH);\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(file + \".in\"));\n\t\t\t// out = new PrintWriter(file + \".out\");\n\t\t\teat(\"\");\n\t\t\tsolve();\n\t\t\tin.close();\n\t\t\tout.close();\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["brute force", "math", "binary search"], "code_uid": "9cf56c4239e1863d0ac59071a57cc520", "src_uid": "e1070ad4383f27399d31b8d0e87def59", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.Scanner;\n\npublic class MikePalindrome {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tString s;\n\t\tScanner sc = new Scanner(System.in);\n\t\ts= sc.next();\n\t\tif(s.length()==1) {\n\t\t\tSystem.out.println(\"YES\");\n\t\t\treturn;\n\t\t}\n\t\tboolean palindrome = true;\n\t\t int cnt = 1;\n\t\t for (int i = 0; i < s.length() / 2; i++) {\n\t\t if (s.charAt(i) != s.charAt(s.length() - 1 - i)) {\n\t\t if (cnt > 0) {\n\t\t cnt--;\n\t\t } else {\n\t\t palindrome = false;\n\t\t break;\n\t\t }\n\t\t }\n\t\t }\n\t\t if (s.length() % 2 == 1 && cnt == 1) {\n\t\t cnt--;\n\t\t }\n\t\t if (palindrome && cnt == 0) {\n\t\t System.out.println(\"YES\");\n\t\t } else {\n\t\t\t System.out.println(\"NO\");\n\t\t }\n\t\t\n\t}\n\t\n\n}\n", "lang_cluster": "Java", "tags": ["brute force", "strings", "constructive algorithms"], "code_uid": "fef68f1cd35fcdcc2ce83ff968563cfe", "src_uid": "fe74313abcf381f6c5b7b2057adaaa52", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class AlexRhombus{\n\n\n\tpublic static void main(String[] args) {\n\t\t\n\t\tScanner input = new Scanner(System.in);\n\n\t\tint n = input.nextInt();\n\t\tint sum = 1 ;\n\n\t\tfor (int i = 0 ; i=0;i--)\n\t\t{\n\t\t\t\n\t\t\ta[i]=n%2;\n\t\t\tif(i==0)\n\t\t\t{\n\t\t\t\tf=n;\n\t\t\t\tla=n;\n\t\t\t\t\n\t\t\t}\n\t\t\tn=n/2;\n\t\t\t//out.println(n);\n\t\t}\n\t\t//debug(a);\n\t\t//out.println(f+\" \"+la);\n\t\tfor(long i=l;i<=r;i++)\n\t\t{\n\t\t\tif(i%4==0)\n\t\t\t{\n\t\t\t\tlong b=4;\n\t\t\t\tfor(int j=2;j<=log;j++)\n\t\t\t\t{\n\t\t\t\t\t\n\t\t\t\t\tif((i/b)%2==1)\n\t\t\t\t\t{\n\t\t\t\t\t\tans+=a[j];\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tb=b*2;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if(i%4==1)\n\t\t\t{\n\t\t\t\tif(f==1)ans+=1;\n\t\t\t}\n\t\t\telse if(i%4==2)\n\t\t\t{\n\t\t\t\tif(a[1]==1)ans+=1;\n\t\t\t}\n\t\t\telse if(i%4==3)\n\t\t\t{\n\t\t\t\tif(la==1)ans+=1;\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.println(ans);\n\t\tout.close();\n\t}\n\n\t\n\n\tpublic static void debug(Object... o) {\n\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n\n\tpublic static boolean isPal(String s) {\n\t\tfor (int i = 0, j = s.length() - 1; i <= j; i++, j--) {\n\t\t\tif (s.charAt(i) != s.charAt(j))\n\t\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tpublic static String rev(String s) {\n\t\tStringBuilder sb = new StringBuilder(s);\n\t\tsb.reverse();\n\t\treturn sb.toString();\n\t}\n\n\tpublic static long gcd(long x, long y) {\n\t\tif (y == 0)\n\t\t\treturn x;\n\t\tif (x % y == 0)\n\t\t\treturn y;\n\t\telse\n\t\t\treturn gcd(y, x % y);\n\t}\n\n\tpublic static int gcd(int x, int y) {\n\t\tif (x % y == 0)\n\t\t\treturn y;\n\t\telse\n\t\t\treturn gcd(y, x % y);\n\t}\n\n\tpublic static long gcdExtended(long a, long b, long[] x) {\n\n\t\tif (a == 0) {\n\t\t\tx[0] = 0;\n\t\t\tx[1] = 1;\n\t\t\treturn b;\n\t\t}\n\t\tlong[] y = new long[2];\n\t\tlong gcd = gcdExtended(b % a, a, y);\n\n\t\tx[0] = y[1] - (b / a) * y[0];\n\t\tx[1] = y[0];\n\n\t\treturn gcd;\n\t}\n\n\tpublic static int abs(int a, int b) {\n\t\treturn (int) Math.abs(a - b);\n\t}\n\n\tpublic static long abs(long a, long b) {\n\t\treturn (long) Math.abs(a - b);\n\t}\n\n\tpublic static int max(int a, int b) {\n\t\tif (a > b)\n\t\t\treturn a;\n\t\telse\n\t\t\treturn b;\n\t}\n\n\tpublic static int min(int a, int b) {\n\t\tif (a > b)\n\t\t\treturn b;\n\t\telse\n\t\t\treturn a;\n\t}\n\n\tpublic static long max(long a, long b) {\n\t\tif (a > b)\n\t\t\treturn a;\n\t\telse\n\t\t\treturn b;\n\t}\n\n\tpublic static long min(long a, long b) {\n\t\tif (a > b)\n\t\t\treturn b;\n\t\telse\n\t\t\treturn a;\n\t}\n\n\tpublic static long[][] mul(long a[][], long b[][]) {\n\t\tlong c[][] = new long[2][2];\n\t\tc[0][0] = a[0][0] * b[0][0] + a[0][1] * b[1][0];\n\t\tc[0][1] = a[0][0] * b[0][1] + a[0][1] * b[1][1];\n\t\tc[1][0] = a[1][0] * b[0][0] + a[1][1] * b[1][0];\n\t\tc[1][1] = a[1][0] * b[0][1] + a[1][1] * b[1][1];\n\n\t\treturn c;\n\t}\n\n\tpublic static long[][] pow(long n[][], long p, long m) {\n\t\tlong result[][] = new long[2][2];\n\t\tresult[0][0] = 1;\n\t\tresult[0][1] = 0;\n\t\tresult[1][0] = 0;\n\t\tresult[1][1] = 1;\n\n\t\tif (p == 0)\n\t\t\treturn result;\n\t\tif (p == 1)\n\t\t\treturn n;\n\t\twhile (p != 0) {\n\t\t\tif (p % 2 == 1)\n\t\t\t\tresult = mul(result, n);\n\t\t\t//System.out.println(result[0][0]);\n\t\t\tfor (int i = 0; i < 2; i++) {\n\t\t\t\tfor (int j = 0; j < 2; j++) {\n\t\t\t\t\tif (result[i][j] >= m)\n\t\t\t\t\t\tresult[i][j] %= m;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tp >>= 1;\n\t\t\tn = mul(n, n);\n\t\t\t// System.out.println(1+\" \"+n[0][0]+\" \"+n[0][1]+\" \"+n[1][0]+\" \"+n[1][1]);\n\t\t\tfor (int i = 0; i < 2; i++) {\n\t\t\t\tfor (int j = 0; j < 2; j++) {\n\t\t\t\t\tif (n[i][j] >= m)\n\t\t\t\t\t\tn[i][j] %= m;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static long pow(long n, long p) {\n\t\tlong result = 1;\n\t\tif (p == 0)\n\t\t\treturn 1;\n\t\tif (p == 1)\n\t\t\treturn n;\n\t\twhile (p != 0) {\n\t\t\tif (p % 2 == 1)\n\t\t\t\tresult *= n;\n\t\t\tp >>= 1;\n\t\t\tn *= n;\n\t\t}\n\t\treturn result;\n\t}\n\n\tstatic 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\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 long[] nextLongArray(int n) {\n\t\t\tlong a[] = new long[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}", "lang_cluster": "Java", "tags": ["dfs and similar", "divide and conquer", "constructive algorithms"], "code_uid": "c25a08d3223019159901ea2cadee3bc0", "src_uid": "3ac61b1f8deee7911b1055c243f5eb6a", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\n\npublic class ImBoredWithLife {\n public static void main(String[]args) {\n Scanner s = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n int n=s.nextInt();\n int m=s.nextInt();\n int mi=Math.min(n,m);\n System.out.println(factorial(mi));\n }\n\n private static int factorial(int n) {\n if(n==1)\n return 1;\n else\n return n*factorial(n-1);\n }\n\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation", "number theory"], "code_uid": "7db01ca1ab77733de23e1896d2a1aa90", "src_uid": "7bf30ceb24b66d91382e97767f9feeb6", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n public static void main(String[] args) throws FileNotFoundException {\n ConsoleIO io = new ConsoleIO(new InputStreamReader(System.in), new PrintWriter(System.out));\n\n// String fileName = \"C-small-attempt0\";\n// ConsoleIO io = new ConsoleIO(new FileReader(\"D:\\\\Dropbox\\\\code\\\\practice\\\\jb\\\\src\\\\\" + fileName + \".in\"), new PrintWriter(new File(\"D:\\\\Dropbox\\\\code\\\\practice\\\\jb\\\\src\\\\\" + fileName + \".out\")));\n\n new Main(io).solve();\n// new Main(io).solveLocal();\n\n io.close();\n }\n\n ConsoleIO io;\n\n Main(ConsoleIO io) {\n this.io = io;\n }\n\n ConsoleIO opt;\n\n Main(ConsoleIO io, ConsoleIO opt) {\n this.io = io;\n this.opt = opt;\n }\n\n List> gr = new ArrayList<>();\n\n long MOD = 1_000_000_007;\n\n class Box{\n public Box(char color, int count, int idx){\n this.color = color == 'R' ? 0 : (color == 'G' ? 1 : 2);\n this.count = count;\n this.idx = idx;\n }\n public int color;\n public int count;\n public int idx;\n }\n\n public void solve() {\n int[] l = io.readIntArray();\n int n = l[0];\n int s = l[1] - 1;\n int k = l[2];\n int[] num = io.readIntArray();\n char[] col = io.readLine().toCharArray();\n Box[] all = new Box[n];\n int sum = 0;\n for(int i = 0;i a.count));\n int[][] min = new int[n][maxCount+1];\n for(int i = 0;i all[j].count && b.color != all[j].color) {\n for (int c = b.count; c <= maxCount; c++) {\n min[i][c] = Math.min(min[i][c], min[j][c - b.count] + Math.abs(b.idx - all[j].idx));\n }\n }\n }\n int res = Integer.MAX_VALUE/3;\n for(int i = 0;i 0) sb.append(separator);\n sb.append(a[i]);\n }\n this.writeLine(sb.toString());\n }\n public int read(char[] buf, int len){try {return br.read(buf,0,len);}catch (Exception ex){ return -1; }}\n public String readLine() {try {return br.readLine();}catch (Exception ex){ return \"\";}}\n public long[] readLongArray() {\n String[]n=this.readLine().trim().split(\"\\\\s+\");long[]r=new long[n.length];\n for(int i=0;i='0' && all[i]<='9'){\n cur = cur*10+all[i]-'0';\n have = true;\n }else if(all[i]=='-') {\n neg = true;\n }\n else if(have){\n res[k++] = neg?-cur:cur;\n cur = 0;\n have = false;\n neg = false;\n }\n }\n if(have)res[k++] = neg?-cur:cur;\n return res;\n }\n public int ri() {\n try {\n int r = 0;\n boolean start = false;\n boolean neg = false;\n while (true) {\n int c = br.read();\n if (c >= '0' && c <= '9') {\n r = r * 10 + c - '0';\n start = true;\n } else if (!start && c == '-') {\n start = true;\n neg = true;\n } else if (start || c == -1) return neg ? -r : r;\n }\n } catch (Exception ex) {\n return -1;\n }\n }\n public long readLong() {\n try {\n long r = 0;\n boolean start = false;\n boolean neg = false;\n while (true) {\n int c = br.read();\n if (c >= '0' && c <= '9') {\n r = r * 10 + c - '0';\n start = true;\n } else if (!start && c == '-') {\n start = true;\n neg = true;\n } else if (start || c == -1) return neg ? -r : r;\n }\n } catch (Exception ex) {\n return -1;\n }\n }\n public String readWord() {\n try {\n boolean start = false;\n StringBuilder sb = new StringBuilder();\n while (true) {\n int c = br.read();\n if (c!= ' ' && c!= '\\r' && c!='\\n' && c!='\\t') {\n sb.append((char)c);\n start = true;\n } else if (start || c == -1) return sb.toString();\n }\n } catch (Exception ex) {\n return \"\";\n }\n }\n public char readSymbol() {\n try {\n while (true) {\n int c = br.read();\n if (c != ' ' && c != '\\r' && c != '\\n' && c != '\\t') {\n return (char) c;\n }\n }\n } catch (Exception ex) {\n return 0;\n }\n }\n//public char readChar(){try {return (char)br.read();}catch (Exception ex){ return 0; }}\n}\nclass Pair {\n public Pair(int a, int b) {this.a = a;this.b = b;}\n public int a;\n public int b;\n}\nclass PairLL {\n public PairLL(long a, long b) {this.a = a;this.b = b;}\n public long a;\n public long b;\n}\nclass Triple {\n public Triple(int a, int b, int c) {this.a = a;this.b = b;this.c = c;}\n public int a;\n public int b;\n public int c;\n}\n", "lang_cluster": "Java", "tags": ["dp"], "code_uid": "8a8a114f81e9925c61c48a19aeebc433", "src_uid": "a95e54a7e38cc0d61b39e4a01a6f8d3f", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.Math;\npublic class AbstractionInJava{\n public static void main(String args[]){\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n int m=sc.nextInt();\n int o=sc.nextInt();\n\n double a=Math.sqrt((n*m)/o);\n double b=Math.sqrt((n*o)/m);\n\n double c=Math.sqrt((m*o)/n);\n\n System.out.print((int)(a+b+c)*4);\n\n\n }}\n\n\n \n", "lang_cluster": "Java", "tags": ["brute force", "math", "geometry"], "code_uid": "5b9a3a573b23f4b2bf9aac0471661d41", "src_uid": "c0a3290be3b87f3a232ec19d4639fefc", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n/**\n * Created by IntelliJ IDEA.\n * User: mihai\n * Date: 2/3/12\n * Time: 10:46 PM\n */\npublic class problemD {\n private static final long MOD = 1000000007;\n \n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int N, M, K;\n N = sc.nextInt();\n M = sc.nextInt();\n K = sc.nextInt();\n \n if (K == 1 || K > N) System.out.println(pow(M, N));\n else if (K == N) System.out.println(pow(M, (N + 1) / 2));\n else if (K % 2 == 0) System.out.println(M);\n else System.out.println(M * M);\n \n }\n\n private static int pow(long x, long y) {\n int[] put = new int[128];\n int k = 0;\n while (y != 0) {\n put[k++] = (int)y % 2;\n y /= 2;\n }\n\n long res = x;\n for (int i = k - 2; i >= 0; i--) {\n if (put[i] == 1) {\n res *= res;\n res %= MOD;\n res *= x;\n res %= MOD;\n } else {\n res *= res;\n res %= MOD;\n }\n }\n\n return (int)res;\n }\n}\n", "lang_cluster": "Java", "tags": ["dsu", "math", "combinatorics", "graphs"], "code_uid": "1ae3f37b8411288da9595890db5ff189", "src_uid": "1f9107e8d1d8aebb1f4a1707a6cdeb6d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\nimport java.awt.geom.*;\n\npublic class TvSet {\n public static long gcd(long a, long b) {\n if (a == 1 || b == 1)\n return 1;\n if (a % b == 0)\n return b;\n return gcd(b, a % b);\n }\n\n public static void main(String[] args) {\n MyScanner sc = new MyScanner();\n long a = sc.nl(), b = sc.nl(), x = sc.nl(), y = sc.nl();\n long hcf = gcd(x, y);\n x /= hcf;\n y /= hcf;\n long v1 = a / x;\n long v2 = b / y;\n System.out.println(Math.min(v1, v2));\n }\n\n /////////// TEMPLATE FROM HERE /////////////////\n private 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 ni() {\n return Integer.parseInt(next());\n }\n\n float nf() {\n return Float.parseFloat(next());\n }\n\n long nl() {\n return Long.parseLong(next());\n }\n\n double nd() {\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": ["math"], "code_uid": "1f315f1a668f446aca28b30ffec624af", "src_uid": "907ac56260e84dbb6d98a271bcb2d62d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigDecimal;\nimport java.util.*;\n\npublic class Main {\n\n public static boolean common2 = false;\n public static long total = 0, v2 = 0, d = 0, t = 0;\n public static long[][] dp = new long[1000][2000];\n\n public static void main(String[] args) throws IOException {\n Map map = new HashMap();\n map.put(0, \"zero\");\n map.put(1, \"one\");\n map.put(2, \"two\");\n map.put(3, \"three\");\n map.put(4, \"four\");\n map.put(5, \"five\");\n map.put(6, \"six\");\n map.put(7, \"seven\");\n map.put(8, \"eight\");\n map.put(9, \"nine\");\n map.put(10, \"ten\");\n map.put(11, \"eleven\");\n map.put(12, \"twelve\");\n map.put(13, \"thirteen\");\n map.put(14, \"fourteen\");\n map.put(15, \"fifteen\");\n map.put(16, \"sixteen\");\n map.put(17, \"seventeen\");\n map.put(18, \"eighteen\");\n map.put(19, \"nineteen\");\n map.put(20, \"twenty\");\n map.put(30, \"thirty\");\n map.put(40, \"forty\");\n map.put(50, \"fifty\");\n map.put(60, \"sixty\");\n map.put(70, \"seventy\");\n map.put(80, \"eighty\");\n map.put(90, \"ninety\");\n int i, j;\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n int n = Integer.parseInt(br.readLine());\n if (n <= 20) {\n System.out.println(map.get(n));\n } else {\n int m = n % 10;\n int n1 = n - m;\n StringBuilder strB = new StringBuilder(\"\");\n if (m != 0) {\n System.out.println(map.get(n1) + \"-\" + map.get(m));\n } else {\n System.out.println(map.get(n1));\n }\n }\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "860268c6e6e0fb78be03c8273bac414e", "src_uid": "a49ca177b2f1f9d5341462a38a25d8b7", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import jdk.swing.interop.SwingInterOpUtils;\n\nimport java.util.Scanner;\n\npublic class cp {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int k = 0, l = 0, count = 0;\n\n\n int ar[][] = new int[5][5];\n\n for (int i = 0; i < 5; i++) {\n for (int j = 0; j < 5; j++) {\n ar[i][j] = scan.nextInt();\n if (ar[i][j] == 1) {\n k = i;\n l = j;\n }\n }\n }\n\n for (int i = 0; i < 5; i++) {\n if (k != 2) {\n\n\n if (k > 2) {\n k--;\n } else {\n k++;\n }\n\n count = count + 1;\n\n }\n if (l != 2) {\n {\n if (l > 2) {\n l--;\n } else {\n l++;\n }\n }\n count = count + 1;\n }\n\n\n\n else if (k == 2 && l == 2)\n break;\n\n\n }\n\n\n System.out.println(count);\n\n}\n}\n\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "0b964e9e575411182e0b90d07a3f91cb", "src_uid": "8ba7cedc3f6ae478a0bb3f902440c8e9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\npublic class Main\n{\n\tpublic static void main (String[]args) throws IOException\n\t{\n\t\tScanner read = new Scanner (System.in);\n\t\tString x = read.next();\n\t\tString ans=\"\";\n\t\tfor (int i=0;i')\n\t\t\t\tans+=\"1000\";\n\t\t\tif (x.charAt(i)=='<')\n\t\t\t\tans+=\"1001\";\n\t\t\tif (x.charAt(i)=='[')\n\t\t\t\tans+=\"1110\";\n\t\t\tif (x.charAt(i)==']')\n\t\t\t\tans+=\"1111\";\n\t\t\tif (x.charAt(i)=='+')\n\t\t\t\tans+=\"1010\";\n\t\t\tif (x.charAt(i)=='-')\n\t\t\t\tans+=\"1011\";\n\n\t\t}\n\t\tBigInteger br = new BigInteger(ans,2);\n\t\tSystem.out.println(br.mod(new BigInteger(\"1000003\")));\n\t}\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "28a399f485154f94d158b715803be269", "src_uid": "04fc8dfb856056f35d296402ad1b2da1", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n/**\n *\n * @author arabtech\n */\npublic class PetyaAndSquare {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int x,y,size;\n size=sc.nextInt();\n x=sc.nextInt();\n y=sc.nextInt();\n if(((2*x)==size||(2*(x-1)==size))&&((2*y)==size||(2*(y-1)==size))){\n System.out.println(\"NO\");\n }\n else{\n System.out.println(\"YES\"); \n }\n }\n \n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "8e9868ec53e14c5cbdda5c75369ff15d", "src_uid": "dc891d57bcdad3108dcb4ccf9c798789", "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.math.BigInteger;\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 lebegio\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n MyReader in = new MyReader(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, MyReader in, PrintWriter out) {\n String str = in.next();\n long n = Long.parseLong(str.substring(0, str.length() - 1));\n char ch = str.charAt(str.length() - 1);\n int poz = getPoz(ch);\n BigInteger time = BigInteger.ZERO;\n if (n % 4 != 0) time = BigInteger.valueOf(n / 4).multiply(BigInteger.valueOf(16));\n else time = BigInteger.valueOf((n - 1) / 4).multiply(BigInteger.valueOf(16));\n\n if (n % 4 == 0) {\n time = time.add(BigInteger.valueOf(poz + 7));\n } else if (n % 4 == 1) {\n time = time.add(BigInteger.valueOf(poz));\n } else if (n % 4 == 2) {\n time = time.add(BigInteger.valueOf(poz + 7));\n } else if (n % 4 == 3) {\n time = time.add(BigInteger.valueOf(poz));\n }\n out.println(time);\n }\n\n int getPoz(char ch) {\n switch (ch) {\n case 'a':\n return 4;\n case 'b':\n return 5;\n case 'c':\n return 6;\n case 'd':\n return 3;\n case 'e':\n return 2;\n case 'f':\n return 1;\n }\n return -1;\n }\n\n }\n\n static class MyReader {\n private BufferedReader buffReader;\n private StringTokenizer strTokenizer;\n private static final int SIZE = 32768;\n\n public MyReader(InputStream inputStream) {\n buffReader = new BufferedReader(new InputStreamReader(inputStream), SIZE);\n }\n\n public String next() {\n if (strTokenizer == null || !strTokenizer.hasMoreTokens()) {\n try {\n strTokenizer = new StringTokenizer(buffReader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return strTokenizer.nextToken();\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "0dd0a58ea5441f41acf39d06e518d7af", "src_uid": "069d0cb9b7c798a81007fb5b63fa0f45", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.math.*;\nimport java.io.*;\n\npublic class Main\n\t{\n\t/*\n\t * Simple bitmask code for boolean isset, int set and int clr\n\t */\n\tpublic static boolean isset(int n,int i) //returns 1 if the ith bit (from left) of n is set\n\t\t{\n\t\treturn ((n>>i)&1)==1;\n\t\t}\n\tpublic static void main(String args[]) throws IOException\n\t\t{\n\t\tInputReader in=new InputReader(System.in);\n\t\tPrintWriter out=new PrintWriter(System.out);\n\t\tint n=in.readInt();\n\t\tRectangle R[]=new Rectangle[n];\n\t\tfor(int i=0;i L=new LinkedList();\n\t\t\tfor(int j=0;j=RT[j].x2&&RT[i].y2>=RT[j].y2)\n\t\t\t\t\tcontinue;\n\t\t\t\telse\n\t\t\t\t\tvalid=false;\n\t\t\t\t}\n\t\t\tif(valid)\n\t\t\t\tupperCornerIndex=i;\n\t\t\t}\n\t\t\n\t\t//bottom left\n\t\tfor(int i=0;i=numChars)\n\t\t\t{\n\t\t\tcurChar=0;\n\t\t\ttry\n\t\t\t\t{\n\t\t\t\tnumChars=stream.read(buf);\n\t\t\t\t} catch (IOException e)\n\t\t\t\t{\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\tif(numChars<=0)\n\t\t\t\treturn -1;\n\t\t\t}\n\t\treturn buf[curChar++];\n\t\t}\n\n\tpublic int readInt()\n\t\t{\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\t{\n\t\t\tsgn=-1;\n\t\t\tc=read();\n\t\t\t}\n\t\tint res=0;\n\t\tdo\n\t\t\t{\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\t} while (!isSpaceChar(c));\n\t\treturn res*sgn;\n\t\t}\n\n\tpublic boolean isSpaceChar(int c)\n\t\t{\n\t\tif(filter!=null)\n\t\t\treturn filter.isSpaceChar(c);\n\t\treturn isWhitespace(c);\n\t\t}\n\n\tpublic static boolean isWhitespace(int c)\n\t\t{\n\t\treturn c==' '||c=='\\n'||c=='\\r'||c=='\\t'||c==-1;\n\t\t}\n\n\tpublic char readCharacter()\n\t\t{\n\t\tint c=read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc=read();\n\t\treturn (char) c;\n\t\t}\n\n\tpublic interface SpaceCharFilter\n\t\t{\n\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "c8486ab24d854d51b12bea51f496164b", "src_uid": "f63fc2d97fd88273241fce206cc217f2", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n public static void main(String[] args) throws Exception {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n// InputReader in = new InputReader(new FileInputStream(\"/home/ahmad/Desktop/input.txt\"));\n PrintWriter out = new PrintWriter(outputStream);\n Main m = new Main();\n m.solve(in, out);\n out.close();\n }\n\n public void solve(InputReader in, PrintWriter out) {\n\n long n = in.nextLong();\n if (n == 0) {\n System.out.println(0);\n return;\n }\n ++n;\n if (n % 2 == 0) {\n System.out.println((n) / 2);\n } else {\n System.out.println(n);\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) throws Exception {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public InputReader(File stream) throws Exception {\n reader = new BufferedReader(new FileReader(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}\n\n\n\n\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "39bb9b71f5731d1216257257ea0fe4a9", "src_uid": "236177ff30dafe68295b5d33dc501828", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class GoldenPlate {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int width = sc.nextInt();\n int length = sc.nextInt();\n int glidedRings = sc.nextInt();\n int totalGlidedRings = 0;\n\n for(int i = 1; i <= glidedRings; i++) {\n totalGlidedRings += 2 * (width - 4 * (i - 1) - 2) + 2 * (length - 4 * (i - 1));\n }\n\n System.out.print(totalGlidedRings);\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "3760cf5eb86e91769d45b4aa4b7d2638", "src_uid": "2c98d59917337cb321d76f72a1b3c057", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n/*\n * \tHeart beats fast\n * \t\tColors and promises\n * \t\t\tHow to be brave\n * \t\t\t\tHow can I love when I am afraid to fall...\n */\npublic class Main \n{\n\tstatic final long mod=1000000007;\n\tstatic final double eps=1e-8;\n\tstatic final long inf=100000000000000000L;\n\tstatic final boolean debug=true;\n\tstatic Reader in=new Reader();\n\tpublic static void main(String[] args) throws IOException\n\t{\n\t\tlong fibo[]=new long[100];\n\t\tfibo[0]=1;\n\t\tfibo[1]=2;\n\t\tfor(int i=2; i<100;i++)\n\t\t\tfibo[i]=fibo[i-1]+fibo[i-2];\n\t\tint x=ni(),y=ni();\n\t\tint j=0;\n\t\tfor(;j<100; j++)\n\t\t\tif(x<=fibo[j]*(y-1)+1)\n\t\t\t\tbreak;\n\t\tpr(j+2);\n\t\tSystem.out.println(ans);\n\t}\n\tstatic StringBuilder ans=new StringBuilder();\n\tstatic long powm(long a, long b, long m)\n\t{\n\t\tlong an=1;\n\t\tlong c=a;\n\t\twhile(b>0)\n\t\t{\n\t\t\tif(b%2==1)\n\t\t\t\tan=(an*c)%m;\n\t\t\tc=(c*c)%m;\n\t\t\tb>>=1;\n\t\t}\n\t\treturn an;\n\t}\n\tstatic void pd(){if(debug)ans.append(\"hola\");}\n\tstatic void pd(Object a){if(debug)ans.append(a+\"\\n\");}\n\tstatic void pr(Object a){ans.append(a+\"\\n\");}\n\tstatic void pr(){ans.append(\"\\n\");}\n\tstatic void p(Object a){ans.append(a);}\n\tstatic int ni(){return in.nextInt();}\n\tstatic long nl(){return in.nextLong();}\n\tstatic String ns(){return in.next();}\n\tstatic double nd(){return in.nextDouble();}\n\tstatic String pr(String a, long b)\n\t{\n\t\tString c=\"\";\n\t\twhile(b>0)\n\t\t{\n\t\t\tif(b%2==1)\n\t\t\t\tc=c.concat(a);\n\t\t\ta=a.concat(a);\n\t\t\tb>>=1;\n\t\t}\n\t\treturn c;\n\t}\n\tstatic class Reader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n public Reader() {\n reader = new BufferedReader(new InputStreamReader(System.in), 32768);\n tokenizer = null;\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 public int nextInt() {\n return Integer.parseInt(next());\n }\n public long nextLong() {\n \treturn Long.parseLong(next());\n }\n public double nextDouble() {\n \treturn Double.parseDouble(next());\n }\n }\n}", "lang_cluster": "Java", "tags": ["math", "greedy"], "code_uid": "335b6e3d5e86ee58b202eeda27a264be", "src_uid": "8edf64f5838b19f9a8b19a14977f5615", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class C {\n\tFastReader scn;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\n\tvoid solve() {\n\t\tint n = scn.nextInt();\n\t\tchar[] arr = scn.next().toCharArray();\n\t\tint sum = 0;\n\t\tboolean allZero = true;\n\t\tfor(char ch : arr) {\n\t\t\tsum += ch - '0';\n\t\t\tif(ch != '0') {\n\t\t\t\tallZero = false;\n\t\t\t}\n\t\t}\n\t\tif(allZero) {\n\t\t\tout.println(\"YES\");\n\t\t\treturn;\n\t\t}\n\t\tboolean yes = false;\n\t\tfor (int i = 0; i < sum; i++) {\n\t\t\tboolean fail = false;\n\t\t\tint curr = 0;\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tint val = curr + arr[j] - '0';\n\t\t\t\tif (val > i) {\n\t\t\t\t\tfail = true;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tcurr += arr[j] - '0';\n\t\t\t\t\tj++;\n\t\t\t\t\twhile(j < n && arr[j] == '0') {\n\t\t\t\t\t\tj++;\n\t\t\t\t\t}\n\t\t\t\t\tj--;\n\t\t\t\t\tif(curr == i) {\n\t\t\t\t\t\tcurr = 0;\n\t\t\t\t\t} else if(j == n - 1) {\n\t\t\t\t\t\tfail = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!fail) {\n\t\t\t\tyes = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tif (yes) {\n\t\t\tout.println(\"YES\");\n\t\t} else {\n\t\t\tout.println(\"NO\");\n\t\t}\n\t}\n\n\tvoid run() throws Exception {\n\t\tlong time = System.currentTimeMillis();\n\t\tboolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\tout = new PrintWriter(System.out);\n\t\tscn = new FastReader(oj);\n\t\tsolve();\n\t\tout.flush();\n\t\tif (!oj) {\n\t\t\tSystem.out.println(Arrays.deepToString(new Object[] { System.currentTimeMillis() - time + \" ms\" }));\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew C().run();\n\t}\n\n\tclass FastReader {\n\t\tInputStream is;\n\n\t\tpublic FastReader(boolean onlineJudge) {\n\t\t\tis = onlineJudge ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\t}\n\n\t\tbyte[] inbuf = new byte[1024];\n\t\tpublic int lenbuf = 0, ptrbuf = 0;\n\n\t\tint readByte() {\n\t\t\tif (lenbuf == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (ptrbuf >= lenbuf) {\n\t\t\t\tptrbuf = 0;\n\t\t\t\ttry {\n\t\t\t\t\tlenbuf = is.read(inbuf);\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 (lenbuf <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn inbuf[ptrbuf++];\n\t\t}\n\n\t\tboolean isSpaceChar(int c) {\n\t\t\treturn !(c >= 33 && c <= 126);\n\t\t}\n\n\t\tint 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\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tchar nextChar() {\n\t\t\treturn (char) skip();\n\t\t}\n\n\t\tString next() {\n\t\t\tint b = skip();\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\twhile (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && 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\tString nextLine() {\n\t\t\tint b = skip();\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\twhile ((!isSpaceChar(b) || b == ' ')) { // when nextLine, (isSpaceChar(b) && 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\tchar[] next(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\tint 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\tlong 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\tchar[][] nextMatrix(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] = next(m);\n\t\t\treturn map;\n\t\t}\n\n\t\tint[] 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\treturn a;\n\t\t}\n\n\t\tlong[] nextLongArray(int n) {\n\t\t\tlong[] a = new long[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\ta[i] = nextLong();\n\t\t\treturn a;\n\t\t}\n\n\t\tint[][] next2DInt(int n, int m) {\n\t\t\tint[][] arr = new int[n][];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = nextIntArray(m);\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tlong[][] next2DLong(int n, int m) {\n\t\t\tlong[][] arr = new long[n][];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = nextLongArray(m);\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tint[] shuffle(int[] arr) {\n\t\t\tRandom r = new Random();\n\t\t\tfor (int i = 1, j; i < arr.length; i++) {\n\t\t\t\tj = r.nextInt(i);\n\t\t\t\tarr[i] = arr[i] ^ arr[j];\n\t\t\t\tarr[j] = arr[i] ^ arr[j];\n\t\t\t\tarr[i] = arr[i] ^ arr[j];\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\t}\n}", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "7df9339686e7816bf06b886cb45bcea1", "src_uid": "410296a01b97a0a39b6683569c84d56c", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class ProblemC {\n static final long MOD = 1000000007;\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint l = sc.nextInt();\n\t\tint r = sc.nextInt();\n\t\tsc.close();\n\t\tlong[][] dp = new long[n + 1][3];\n\t\tint []k = new int[3];\n\t\tfor(int i = 0; i < 3; i++) {\n\t\t\tk[i] = (r - i + 3) / 3 - (l - i + 2) / 3;\n\t\t}\n\t\tdp[1][0] = k[0];\n\t\tdp[1][1] = k[1];\n\t\tdp[1][2] = k[2];\n\t\tfor(int i = 2; i <= n; i++) {\n\t\t\tdp[i][0] = dp[i-1][0] * k[0] + dp[i-1][1] * k[2] + dp[i-1][2] * k[1];\n\t\t\tdp[i][1] = dp[i-1][0] * k[1] + dp[i-1][1] * k[0] + dp[i-1][2] * k[2];\n\t\t\tdp[i][2] = dp[i-1][0] * k[2] + dp[i-1][1] * k[1] + dp[i-1][2] * k[0];\n\t\t\tdp[i][0] %= MOD;\n\t\t\tdp[i][1] %= MOD;\n\t\t\tdp[i][2] %= MOD;\n\t\t}\n\t\tSystem.out.println(dp[n][0]);\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics"], "code_uid": "c536ac3142b005aa509ef38e6f2f1a59", "src_uid": "4c4852df62fccb0a19ad8bc41145de61", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\n/**\n * @author artyom\n */\npublic class Tetrahedron {\n\tprivate static final int MOD = 1_000_000_007;\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[] dp = new int[]{1, 1, 1, 0};\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tint t0 = (dp[1] + dp[2]) % MOD + dp[3];\n\t\t\tint t1 = (dp[0] + dp[2]) % MOD + dp[3];\n\t\t\tint t2 = (dp[0] + dp[1]) % MOD + dp[3];\n\t\t\tint t3 = (dp[0] + dp[1]) % MOD + dp[2];\n\t\t\tdp[0] = t0 % MOD;\n\t\t\tdp[1] = t1 % MOD;\n\t\t\tdp[2] = t2 % MOD;\n\t\t\tdp[3] = t3 % MOD;\n\t\t}\n\t\tSystem.out.println(dp[3]);\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "matrices", "dp"], "code_uid": "a2724f10d573f257c38a82c28db7b589", "src_uid": "77627cc366a22e38da412c3231ac91a8", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Tshirt_Hunt {\n\tpublic static void main(String a[]){\n\t\tScanner s = new Scanner(System.in);\n\t\tint p = s.nextInt();\n\t\tint x = s.nextInt();\n\t\tint y = s.nextInt();\n\t\tint successful_hack = 0;\n\t\tboolean found = false;\n\t\tint k =0;\n\t\tint x1 = x;\n\t\twhile(x1 >= y){\n\t\t\tfound = got_Tshirt(x1,p);\n\t\t\tif(found){\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tx1 = x1-50;\n\t\t}\n\t\tif(found == false){\n\t\t\twhile(true){\n\t\t\t\tx = x+50;\n\t\t\t\tk++;\n\t\t\t\tfound = got_Tshirt(x,p);\n\t\t\t\tif(found){\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(k%2 !=0){\n\t\t\t\tk = k+1;\n\t\t\t\tsuccessful_hack = k/2;\n\t\t\t}else{\n\t\t\t\tsuccessful_hack = k/2;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(successful_hack);\n\t}\t\n\t\t\n\tpublic static boolean got_Tshirt(int s,int p){\n\t\tboolean lucky = false;\n\t\tList store = new ArrayList();\n\t\tint i = (s/50) % 475;\n\t\tfor(int j=1;j<26;j++){\n\t\t\ti = (i * 96 + 42) % 475;\n\t\t\tstore.add(26 + i);\n\t\t}\n\n\t\tlucky = store.contains(p);\n\t\treturn lucky;\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "3117227e12639094e4f455c9aed00649", "src_uid": "c9c22e03c70a94a745b451fc79e112fd", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "\n\n\n\n\n\n\n\n\n\nimport java.util.Scanner;\n\npublic class Main\n{\n public static void main(String args[])\n {\n\t Scanner s=new Scanner(System.in);\n\t int n=s.nextInt(),k=n;\n\t int m=s.nextInt();\n\t\n\t if(n>=m)\n\t {\n\t\t while(k>=m)\n\t\t {\n\t\t\t int x= k/m;\n\t\t\t k=k-x*m+x;\n\t\t\t n=n+x;\n\t\t }\n\t\t System.out.print(n);\n\t }\n\t else\n\t {\n\t\t System.out.print(n);\n\t }\n\t \n }\n \n}\n", "lang_cluster": "Java", "tags": ["brute force", "math", "implementation"], "code_uid": "f37b6ad4a7b56b28c9baba425f6cda27", "src_uid": "42b25b7335ec01794fbb1d4086aa9dd0", "difficulty": 900.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;\nimport java.util.StringTokenizer;\n\npublic class A {\n private static BufferedReader in;\n private static StringTokenizer st;\n private static PrintWriter out;\n \n public static void main(String[] args) throws NumberFormatException, IOException {\n in = new BufferedReader(new InputStreamReader(System.in));\n st = new StringTokenizer(\"\");\n out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n int n = nextInt();\n int k = nextInt();\n int cnt = 0;\n while(k >= n){\n cnt++;\n if(k % n == 0) {\n// System.out.println(n + \" \" + k);\n k/=n;\n }else{\n System.out.println(\"NO\");\n return;\n }\n }\n if(k != 1){\n System.out.println(\"NO\");\n }else{\n System.out.println(\"YES\");\n System.out.println(cnt-1);\n }\n }\n \n\n static String next() throws IOException{\n while(!st.hasMoreTokens()){\n st = new StringTokenizer(in.readLine());\n }\n return st.nextToken();\n }\n static int nextInt() throws NumberFormatException, IOException{\n return Integer.parseInt(next());\n }\n static long nextLong() throws NumberFormatException, IOException{\n return Long.parseLong(next());\n }\n \n static double nextDouble() throws NumberFormatException, IOException{\n return Double.parseDouble(next());\n }\n\n}\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "ac584f957b09e0402327e447855268f6", "src_uid": "8ce89b754aa4080e7c3b2c3b10f4be46", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "\n\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Main\n{\n\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\tStringTokenizer tokenizer=null;\n\t\n\tpublic static void main(String[] args) throws IOException\n\t{\n\t\tnew Main().execute();\n\t}\n\t\n\tvoid debug(Object...os)\n\t{\n\t\tSystem.out.println(Arrays.deepToString(os));\n\t}\n\t\n\tint ni() throws IOException\n\t{\n\t\treturn Integer.parseInt(ns());\n\t}\n\t\n\tlong nl() throws IOException \n\t{\n\t\treturn Long.parseLong(ns());\n\t}\n\t\n\tdouble nd() throws IOException \n\t{\n\t\treturn Double.parseDouble(ns());\n\t}\n\t\t\n\tString ns() throws IOException \n\t{\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) \n\t\t\ttokenizer = new StringTokenizer(br.readLine());\n\t\treturn tokenizer.nextToken();\n\t}\n\t\n\tString nline() throws IOException\n\t{\n\t\ttokenizer=null;\n\t\treturn br.readLine();\n\t}\n\t\t\n\t\n\n\t//Main Code starts Here\n\tint totalCases, testNum;\t\n\t\n\n\tvoid execute() throws IOException\n\t{\n\t\ttotalCases = 1;\n\t\tfor(testNum = 1; testNum <= totalCases; testNum++)\n\t\t{\n\t\t\tif(!input())\n\t\t\t\tbreak;\n\t\t\tsolve();\n\t\t}\n\t}\n\n\tvoid solve() throws IOException\n\t{\n\t\tint a = ni();\n\t\tint b = ni();\n\t\tint ans = a;\n\t\tfor(int i = a+1;;i++)\n\t\t{\n\t\t\tif(lucky(i) == b)\n\t\t\t{\n\t\t\t\tans = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t\t\n\t\t\n\t}\n\t\n\tint lucky(int a)\n\t{\n\t\tString s = String.valueOf(a);\n\t\tString f = \"0\";\n\t\tint n = s.length();\n\t\tfor(int i = 0;i temp = new ArrayList();\n\t\t\n\t\tfor(int i = 0; i < line.length(); i++){\n\t\t\tint digit = Integer.parseInt(Character.toString(line.charAt(i)));\n\t\t\n\t\t\tint[] a = getSpecial(digit);\n\t\t\tfor(int q : a){\n\t\t\t\ttemp.add(q);\n\t\t\t}\n\t\t\n\t\t}\n\t\t\n\t\tCollections.sort(temp);\n\t\t\n\t\tString lol = \"\";\n\t\tfor(int i = temp.size()-1; i > -1; i--){\n\t\t\tlol += Integer.toString(temp.get(i));\n\t\t}\n\t\t\n\t\tSystem.out.println(lol);\n\t\t\n\t\t\n\t}\n\t\n\tpublic int[] getSpecial(int i) {\n\t\tswitch (i) {\n\t\tcase 0:\n\t\tcase 1:\n\t\t\treturn new int[] {};\n\t\tcase 2:\n\t\t\treturn new int[] { 2 };\n\t\tcase 3:\n\t\t\treturn new int[] { 3 };\n\t\tcase 4:\n\t\t\treturn new int[] { 3, 2, 2 };\n\t\tcase 5:\n\t\t\treturn new int[] { 5 };\n\t\tcase 6:\n\t\t\treturn new int[] { 5, 3 };\n\t\tcase 7:\n\t\t\treturn new int[] { 7 };\n\t\tcase 8:\n\t\t\treturn new int[] { 7, 2, 2, 2 };\n\t\tcase 9:\n\t\t\treturn new int[] { 7, 3, 3, 2 };\n\t\tdefault:\n\t\t\treturn null;\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["math", "sortings", "greedy"], "code_uid": "2fb40864fbebfb70e53d9f067780a387", "src_uid": "60dbfc7a65702ae8bd4a587db1e06398", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.OptionalInt;\n/* * */\n\npublic class _127_A implements Runnable{\n public static void main(String[] args) {\n\t new Thread(null, new _127_A(),\"Main\",1<<27).start();\n }\n @Override\n public void run() {\n FastReader fd = new FastReader(System.in);\n PrintWriter out = new PrintWriter(System.out);\n String data = fd.next();\n int maxAscii = data.chars().max().getAsInt();\n for(int i = 0; i < data.length(); i++){\n if(data.charAt(i) == maxAscii){ out.print((char) maxAscii); }\n }\n out.println();\n out.close();\n }\n\n //Helper functions\n static void getArray(int[] data, boolean isSorted, FastReader fd){\n for(int i = 0; i < data.length; i++){ data[i] = fd.nextInt(); }\n if(isSorted) Arrays.sort(data);\n }\n static int gcd(int a, int b) {\n if (a == 0)\n return b;\n return gcd(b % a, a);\n }\n\n static int lcm(int a, int b) {\n return (a*b)/gcd(a, b);\n }\n\n static boolean checkDistinct(int next){// check all digits are distinct.\n\n String process = String.valueOf(next);\n for(int i = 0;i < process.length()-1; i++){\n String character = String.valueOf(process.charAt(i));\n if(process.substring(i+1).contains(character)){ return false; }\n }\n return true;\n }\n\n static int limit = (int) 1e7 + 1;\n static int[] facts = new int[limit];\n static void sieve() { // Store the minimum prime factors of 1 to LIMIT\n facts[1] = 1;\n for (int i = 2; i < limit; i++) {\n if (i % 2 == 0 && i > 2) {\n facts[i] = 2;\n } else {\n facts[i] = i;\n }\n }\n for (int i = 3; i * i < limit; i++) {\n if (facts[i] == i) {\n for (int j = i * i; j < limit; j += i)\n if (facts[j] == j)\n facts[j] = i;\n }\n }\n }\n static class FastReader {\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 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 }\n catch (IOException e) {\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 String str = \"\";\n try {\n str = br.readLine();\n }\n catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n public int nextInt() {\n int c = read();\n\n while(isSpaceChar(c))\n c = read();\n\n int sgn = 1;\n\n if (c == '-') {\n sgn = -1;\n c = read();\n }\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 }\n while (!isSpaceChar(c));\n\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\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 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\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 }\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 String next() {\n return readString();\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "binary search", "bitmasks", "greedy", "strings", "implementation"], "code_uid": "2d3c71a075fc438b5102e5e8cf7329d0", "src_uid": "9a40e9b122962a1f83b74ddee6246a40", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.util.stream.*;\n\n@SuppressWarnings(\"unchecked\")\npublic class P887B {\n\n public void run() throws Exception {\n int n = nextInt(), c [][] = new int [n][];\n for (int i = 0; i < n; c[i] = readInt(6), i++);\n\n BitSet nums = new BitSet();\n for (int i = 0; i < n; i++) {\n for (int ii = 0; ii < 6; ii++) {\n nums.set(c[i][ii]);\n \n if (n >= 2) {\n for (int j = 0; j < n; j++) {\n if (j != i) {\n for (int jj = 0; jj < 6; jj++) {\n nums.set(c[i][ii] * 10 + c[j][jj]);\n\n if (n >= 3) {\n for (int k = 0; k < n; k++) {\n if ((k != i) && (k != j)) {\n for (int kk = 0; kk < 6; kk++) {\n nums.set(c[i][ii] * 100 + c[j][jj] * 10 + c[k][kk]);\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n\n println(nums.nextClearBit(1) - 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 P887B().run();\n br.close();\n pw.close();\n System.err.println(\"\\n[Time : \" + (System.currentTimeMillis() - startTime) + \" ms]\");\n }\n\n static long startTime = System.currentTimeMillis();\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\n int gcd(int a, int b) {\n if (a == 0) return Math.abs(b); if (b == 0) return Math.abs(a);\n a = Math.abs(a); b = Math.abs(b);\n int az = Integer.numberOfTrailingZeros(a), bz = Integer.numberOfTrailingZeros(b);\n a >>>= az; b >>>= bz;\n while (a != b) {\n if (a > b) { a -= b; a >>>= Integer.numberOfTrailingZeros(a); }\n else { b -= a; b >>>= Integer.numberOfTrailingZeros(b); }\n }\n return (a << Math.min(az, bz));\n }\n\n long gcd(long a, long b) {\n if (a == 0) return Math.abs(b); if (b == 0) return Math.abs(a);\n a = Math.abs(a); b = Math.abs(b);\n int az = Long.numberOfTrailingZeros(a), bz = Long.numberOfTrailingZeros(b);\n a >>>= az; b >>>= bz;\n while (a != b) {\n if (a > b) { a -= b; a >>>= Long.numberOfTrailingZeros(a); }\n else { b -= a; b >>>= Long.numberOfTrailingZeros(b); }\n }\n return (a << Math.min(az, bz));\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "5e93412cfc4b00e2544cfd97f9200663", "src_uid": "20aa53bffdfd47b4e853091ee6b11a4b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\npublic class Main {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc=new Scanner(System.in);\n\t\tPrintWriter pw=new PrintWriter(System.out);\n\t\twhile(sc.hasNext()){\n\t\t\tlong n=sc.nextLong();\n\t\t\tlong m=sc.nextLong();\n\t\t\tlong k=sc.nextLong();\n\t\t\tlong mod=1000000007;\n\t\t\tlong res=1;\n\t\t\tlong a=n-1;\n\t\t\tlong base=2;\n\t\t\twhile(a>0){\n\t\t\t\tif(a%2!=0)res=(res%mod*base)%mod;\n\t\t\t\ta/=2;\n\t\t\t\tbase=(base*base)%mod;\n\t\t\t}\n\t\t\ta=m-1;\n\t\t\tbase=res;\n\t\t\tres=1;\n\t\t\twhile(a>0){\n\t\t\t\tif(a%2!=0)res=(res%mod*base)%mod;\n\t\t\t\ta/=2;\n\t\t\t\tbase=(base*base)%mod;\n\t\t\t}\n\t\t\tif((n&1)!=(m&1)&&k==-1)res=0;\n\t\t\tpw.println(res);\n\t\t\tpw.flush();\n\t\t}\n\n\t}\n}\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),32768);\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": ["math", "constructive algorithms", "combinatorics", "number theory"], "code_uid": "9cab495ee00d1c3b4eebd04176c604b4", "src_uid": "6b9eff690fae14725885cbc891ff7243", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n \npublic class practice {\n\tstatic 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[100001]; // 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\tpublic static void debug(int[][] arr) {\n\t\tint r = arr.length;\n\t\tint c = arr[0].length;\n\t\tint i,j;\n\t\tfor(i=0;ik) {\n System.out.println(\"NO\");\n return;\n }\n }\n System.out.println(\"YES\");\n scan.close();\n\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "31e914e21fdf25f68521d443fd4684e7", "src_uid": "ceb3807aaffef60bcdbcc9a17a1391be", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "// practice with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF571A extends PrintWriter {\n\tCF571A() { super(System.out, true); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF571A o = new CF571A(); o.main(); o.flush();\n\t}\n\n\tlong count2(int h) {\n\t\treturn h % 2 == 1 ? (long) (h + 1) / 2 * ((h + 1) / 2 + 1)\n\t\t\t: (long) (h / 2 + 1) * (h / 2 + 1);\n\t}\n\tlong count1(int h, int r) {\n\t\treturn count2(h) - (r >= h ? 0 : count2(h - 1 - r));\n\t}\n\tlong count(int h, int k, int r) {\n\t\treturn count1(h, r) - (k == 0 ? 0 : count1(k - 1, r));\n\t}\n\tlong solve(int a, int b, int c, int h) {\n\t\tif (a + 1 > b + c + h)\n\t\t\treturn 0;\n\t\tint k = a + 1 <= b + c ? 0 : a + 1 - (b + c);\n\t\tint l = 1 - a - (c - b);\n\t\tint r = a - 1 - (c - b);\n\t\tif (l >= 0)\n\t\t\treturn count(h, k, r) - (l == 0 ? 0 : count(h, k, l - 1));\n\t\tif (r <= 0) {\n\t\t\tr = -r; l = -l;\n\t\t\treturn count(h, k, l) - (r == 0 ? 0 : count(h, k, r - 1));\n\t\t}\n\t\treturn count(h, k, -l) + count(h, k, r) - count(h, k, 0);\n\t}\n\tvoid main() {\n\t\tint a = sc.nextInt();\n\t\tint b = sc.nextInt();\n\t\tint c = sc.nextInt();\n\t\tint l = sc.nextInt();\n\t\tlong ans = 0;\n\t\tfor (int l_ = 0; l_ <= l; l_++)\n\t\t\tans += solve(a + l_, b, c, l - l_);\n\t\tprintln(ans);\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation", "combinatorics"], "code_uid": "2f7fc79569d58ca9bd56d35551440db0", "src_uid": "185ff90a8b0ae0e2b75605f772589410", "difficulty": 2100.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\npublic class C implements Runnable{\n \n BufferedReader in;\n PrintWriter out;\n StringTokenizer Tokenizer;\n \n private void solve() throws IOException{\n int n = NextInt();\n long res = 1000000000;\n res*=1000000;\n long es1 = n;\n es1 = (es1+1)*9;\n for(int i = (int)Math.cbrt(n); i>0; i--)\n if (n%i == 0){\n int m = n/i;\n for(int j = (int)Math.sqrt(m); j>=i; j--)\n if(m%j==0){\n int k = m/j;\n if (k 0 && y > 0) || (x < 0 && y < 0)) {\n //q1,3 starts with white\n if (!even) out.println(\"white\");\n else out.println(\"black\");\n }\n else if ((x > 0 && y < 0) || (x < 0 && y > 0)) {\n //q2,4\n if (even) out.println(\"white\");\n else out.println(\"black\");\n }\n\n else {\n out.println(\"black\");\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 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 }\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", "lang_cluster": "Java", "tags": ["math", "geometry", "constructive algorithms", "implementation"], "code_uid": "318752f5978cea93fda785bd5c83baae", "src_uid": "8c92aac1bef5822848a136a1328346c6", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.awt.Point;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class AC {\n \n //solve by Fdg (it's good solve)\n \n int [][][][] d;\n int l;\n char [] c ;\n public void solve() throws IOException {\n \n c = in.readLine().toCharArray();\n int n = readInt();\n l = c.length;\n d = new int [202][l+2][n+2][2]; \n for (int i =0; i<202;i++){\n for (int j =0; j0){\n return 0;\n }\n return abs(pos-100);\n }\n int way=0;\n if (cource==0){\n way++;\n }\n else way--; \n int ans = 0;\n if (c[step]=='F'){\n ans = max(ans,rec(pos+way,step+1,left,cource));\n }\n if (c[step] == 'T'){\n ans = max(ans,rec(pos,step+1,left,cource^1));\n }\n if (left>0){\n if (c[step]=='F'){\n ans = max(ans,rec(pos,step+1,left-1,cource^1));\n }\n if (c[step]=='T'){\n ans = max(ans,rec(pos+way,step+1,left-1,cource));\n }\n }\n return d[pos][step][left][cource] = ans;\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 final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\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 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 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 AC().run();\n }\n\n public void run() {\n try {\n long t1 = System.currentTimeMillis();\n init();\n solve();\n out.close();\n long t2 = System.currentTimeMillis();\n System.err.println(\"Time = \" + (t2 - t1));\n } catch (Exception e) {\n e.printStackTrace(System.err);\n System.exit(-1);\n }\n }\n\n}", "lang_cluster": "Java", "tags": ["dp", "implementation"], "code_uid": "9ed642b1b80be254a1c7da80c14a9ece", "src_uid": "4a54971eb22e62b1d9e6b72f05ae361d", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.Arrays;\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\npublic class A123 {\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 CodeA123 solver = new CodeA123();\n solver.solve(1, in, out);\n out.close();\n }\n}\n\nclass CodeA123\n{\npublic void solve(int testNumber, InputReader in, PrintWriter out)\n{\n\tint d=in.nextInt();\n\tint s=in.nextInt();\n\tint t=in.nextInt();\n\tint D=d*t;\n\tint T=0;\n\tif(D%s==0)\n\t{\n\t\tT=D/s;\n\t}\n\telse\n\t{\n\t\tT=D/s+1;\n\t}\n\tout.println(T-t);\n}\n\n}\n\n\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 public long nextLong() {\n return Long.parseLong(next());\n }\n\tpublic void inputShuffleArrayInt(int arr[])\n\t{\n\t\tint l=arr.length;\n\t\tfor(int i=0;i set = new HashSet();\n\t\t\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint a = reader.nextInt();\n\t\t\tif(a!=0){\n\t\t\t\tset.add(a);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(set.size());\n\t\t\n\t}\n\n}\nclass FastReader {\n\n BufferedReader br;\n StringTokenizer st;\n\n public FastReader() {\n br = new BufferedReader(new InputStreamReader(System.in));\n\n }\n\n public String next() {\n while (st == null || !st.hasMoreElements()) {\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 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 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": ["sortings", "implementation"], "code_uid": "1cf89ed8a0c8ad869afd742c8eaab087", "src_uid": "3b520c15ea9a11b16129da30dcfb5161", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n\n static MyScanner sc;\n private static PrintWriter out;\n static long M2 = 1_000_000_000L + 7;\n\n private static HashMap[] mods;\n\n public static void main(String[] s) throws Exception {\n StringBuilder stringBuilder = new StringBuilder();\n if (stringBuilder.length() == 0) {\n sc = new MyScanner(System.in);\n } else {\n sc = new MyScanner(new BufferedReader(new StringReader(stringBuilder.toString())));\n }\n\n out = new PrintWriter(new OutputStreamWriter(System.out));\n\n initData();\n solve();\n out.flush();\n }\n\n private static void initData() {\n\n\n }\n\n static long[] fact = new long[5001];\n\n static {\n fact[0] = 1;\n for (int i = 1; i < fact.length; i++) {\n fact[i] = (fact[i - 1] * i) % 998_244_353;\n }\n }\n\n private static void solve() throws IOException {\n int n1 = sc.nextInt();\n int n2 = sc.nextInt();\n int n3 = sc.nextInt();\n long[][] r1 = new long[5001][5001];\n for (int i = 0; i < r1.length; i++) {\n r1[i][0] = 1;\n for (int k = 1; k <= i; k++) {\n r1[i][k] = r1[i - 1][k] + r1[i - 1][k - 1];\n r1[i][k] %= 998_244_353;\n }\n }\n\n long res = 1;\n res *= mm(n1, n2, r1);\n res %= 998_244_353;\n res *= mm(n1, n3, r1);\n res %= 998_244_353;\n res *= mm(n3, n2, r1);\n out.println(res % 998_244_353);\n }\n\n private static long mm(int n1, int n3, long[][] r1) {\n long res = 0;\n for (int i = 0; i <= Math.min(n1, n3); i++) {\n long cur = r1[n3][i] * r1[n1][i];\n cur %= 998_244_353;\n cur *= fact[i];\n cur %= 998_244_353;\n res += cur;\n res %= 998_244_353;\n }\n return res;\n }\n\n private static boolean solve(int n, int p, int p1, int i) {\n return false;\n }\n\n\n private static boolean isset(long i, int k) {\n return (i & (1 << k)) > 0;\n }\n\n private static void solveT() throws IOException {\n int t = sc.nextInt();\n while (t-- > 0) {\n solve();\n }\n }\n\n\n private static long gcd(long l, long l1) {\n if (l > l1) return gcd(l1, l);\n if (l == 0) return l1;\n return gcd(l1 % l, l);\n }\n\n private static long pow(long a, long b, long m) {\n if (b == 0) return 1;\n if (b == 1) return a;\n long pp = pow(a, b / 2, m);\n pp *= pp;\n pp %= m;\n return (pp * (b % 2 == 0 ? 1 : a)) % m;\n }\n\n\n static class MyScanner {\n BufferedReader br;\n StringTokenizer st;\n\n MyScanner(BufferedReader br) {\n this.br = br;\n }\n\n public MyScanner(InputStream in) {\n this(new BufferedReader(new InputStreamReader(in)));\n }\n\n void findToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n }\n\n String next() {\n findToken();\n return st.nextToken();\n }\n\n Integer[] nab(int n) {\n Integer[] k = new Integer[n];\n for (int i = 0; i < n; i++) {\n k[i] = sc.fi();\n }\n return k;\n }\n\n int[] na(int n) {\n int[] k = new int[n];\n for (int i = 0; i < n; i++) {\n k[i] = sc.fi();\n }\n return k;\n }\n\n long[] nl(int n) {\n long[] k = new long[n];\n for (int i = 0; i < n; i++) {\n k[i] = sc.nextLong();\n }\n return k;\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n int fi() {\n String t = next();\n int cur = 0;\n boolean n = t.charAt(0) == '-';\n for (int a = n ? 1 : 0; a < t.length(); a++) {\n cur = cur * 10 + t.charAt(a) - '0';\n }\n return n ? -cur : cur;\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n\n\n}", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics"], "code_uid": "0bd34ad06643b157c72493b0f8264e36", "src_uid": "b6dc5533fbf285d5ef4cf60ef6300383", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n\n\n\npublic class Main {\n\n \n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String s = sc.next();\n int ans = 0;\n int a = 1;\n for(int i=0;i {\n Point root;\n\n public PointComparator(Point root) {\n this.root = root;\n }\n\n @Override\n public int compare(Point a, Point 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\n }\n\n int n;\n List[] graph;\n int[] size;\n int[] parent;\n Point[] points;\n int[] ans;\n\n void solve() throws IOException {\n n = readInt();\n // читаем граф\n graph = new List[n];\n for (int i = 0; i < n; i++) {\n graph[i] = new ArrayList();\n }\n for (int i = 0; i < n - 1; i++) {\n int x = readInt() - 1;\n int y = readInt() - 1;\n graph[x].add(y);\n graph[y].add(x);\n }\n \n // читаем точки\n points = new Point[n];\n for (int i = 0; i < n; i++) {\n points[i] = new Point(readLong(), readLong(), i);\n }\n\n // подвешиваем дерево и \n size = new int[n];\n parent = new int[n];\n dfs(0, -1);\n \n // считаем ответ\n ans = new int[n];\n Arrays.fill(ans, -1);\n \n // ищем самый левый\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 // ставим самый левый первым\n Point tmp = points[0];\n points[0] = points[rootIndex];\n points[rootIndex] = tmp;\n \n \n // считаем\n rec(0, 0, n - 1);\n \n // ответ\n for (int i = 0; i < n; i++) {\n if (ans[i] == -1) {\n throw new RuntimeException(\"Answer is wrong\");\n }\n }\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[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[x]) {\n if (y != p) {\n dfs(y, x);\n size[x] += size[y];\n }\n }\n }\n\n}", "lang_cluster": "Java", "tags": ["dfs and similar", "geometry", "constructive algorithms", "trees"], "code_uid": "e12fb768c20be6fa6878352fae2e7be6", "src_uid": "d65e91dc274c6659cfdb50bc8b8020ba", "difficulty": 2200.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": "23c07196a3057d2b6a0b28493025fef1", "src_uid": "f47e4ab041288ba9567c19930eb9a090", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "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 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\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 price = in.readLong();\n\t\twhile (price % 3 == 0 && price != 0)\n\t\t\tprice /= 3;\n\t\tlong answer = price / 3 + 1;\n\t\tout.printLine(answer);\n }\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 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\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 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 public void printLine(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\t}\n\n", "lang_cluster": "Java", "tags": ["greedy"], "code_uid": "9dcc55c72b8b8c9785b7513781aa5c7c", "src_uid": "7e7b59f2112fd200ee03255c0c230ebd", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "//import java.util.Arrays;\nimport java.math.BigInteger;\nimport java.util.Scanner;\npublic class A682\n{\n public static void main(String[] args)\n {\n Scanner sc=new Scanner(System.in);\n BigInteger ans=new BigInteger(\"0\");\n int n=sc.nextInt();\n int m=sc.nextInt();\n int[] arr=new int[5];\n for(int i=1;i<=m;i++)\n arr[i%5]++;\n //System.out.println(Arrays.toString(arr));\n for(int i=1;i<=n;i++)\n {\n if(i%5==0)\n ans=ans.add(BigInteger.valueOf(arr[0]));\n else\n ans=ans.add(BigInteger.valueOf(arr[5-i%5]));\n }\n System.out.println(ans);\n sc.close();\n }\n}", "lang_cluster": "Java", "tags": ["math", "constructive algorithms", "number theory"], "code_uid": "23572616099094120f58c8bff7a933b1", "src_uid": "df0879635b59e141c839d9599abd77d2", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.IOException; \nimport java.io.InputStream; \nimport java.io.PrintWriter; \nimport java.util.*; \n \n\npublic class d{\n\n\tstatic class Pos{\n\t\tint i,j;\n\t\tPos(int i, int j){this.i=i;this.j=j;}\n\t}\n\tstatic class Node{\n\t\tint i,j,k,l,c;\n\t\tNode(int i,int j,int k,int l,int c){this.i=i;this.j=j;this.k=k;this.l=l;this.c=c;}\n\t}\n\n\tstatic void solve(){\n\t\tint n = ni();\n\t\tint[][][][] dis = new int[n][n][3][n*n+1];\n\t\tPos[] pos =new Pos[n*n];\n\t\tfor(int i=0;i que = new PriorityQueue<>((a,b)->a.c-b.c);\n\t\tfor(int k=0;k<3;++k){\n\t\t\tdis[pos[0].i][pos[0].j][k][1]=0;\n\t\t\tque.add(new Node(pos[0].i, pos[0].j, k, 1, 0));\n\t\t}\n\t\tList movex[] = new List[3];\n\t\tList movey[] = new List[3];\n\t\tmovex[0] = Arrays.asList(-2,-2,-1,-1,1,1,2,2);\n\t\tmovey[0] = Arrays.asList(1,-1,2,-2,2,-2,1,-1);\n\t\tfor(int i=1;i<3;++i){\n\t\t\tmovex[i]=new ArrayList<>();\n\t\t\tmovey[i]=new ArrayList<>();\n\t\t}\n\t\tfor(int i=1;i<=n;++i){\n\t\t\tmovex[1].add(i);movex[1].add(-i);\n\t\t\tmovey[1].add(0);movey[1].add(0);\n\t\t\tmovex[1].add(0);movex[1].add(0);\n\t\t\tmovey[1].add(i);movey[1].add(-i);\n\n\t\t\tmovex[2].add(i);movex[2].add(-i);\n\t\t\tmovey[2].add(i);movey[2].add(-i);\n\t\t\tmovex[2].add(i);movex[2].add(-i);\n\t\t\tmovey[2].add(-i);movey[2].add(i);\n\t\t}\n\t\twhile(!que.isEmpty()){\n\t\t\tNode node = que.poll();\n\t\t\tif(node.c > dis[node.i][node.j][node.k][node.l])continue;\n\t\t\tint i=node.i, j=node.j, k=node.k, l=node.l;\n\t\t\tif(l==n*n){\n\t\t\t\tout.println(node.c/1000+\" \"+node.c%1000);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfor(int kk=0;kk<3;++kk){\n\t\t\t\tif(kk==k)continue;\n\t\t\t\tif(dis[i][j][kk][l] > dis[i][j][k][l]+1001){\n\t\t\t\t\tdis[i][j][kk][l]=dis[i][j][k][l]+1001;\n\t\t\t\t\tque.add(new Node(i, j, kk, l, dis[i][j][kk][l]));\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor(int x=0;xdis[i][j][k][l]+1000){\n\t\t\t\t\t\tdis[i+dy][j+dx][k][ll]=dis[i][j][k][l]+1000;\n\t\t\t\t\t\tque.add(new Node(i+dy, j+dx, k, ll, dis[i+dy][j+dx][k][ll]));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\n\n\t} \n \n \n \n \n\t public static void main(String[] args){ \n\t\t solve(); \n\t\t out.flush(); \n\t } \n\t private static InputStream in = System.in; \n\t private static PrintWriter out = new PrintWriter(System.out); \n \n\t static boolean inrange(int y, int x, int h, int w){ \n\t\t return y>=0 && y=0 && x int lower_bound(List list, T key){ \n\t\t int lower=-1;int upper=list.size(); \n\t\t while(upper - lower>1){ \n\t\t int center =(upper+lower)/2; \n\t\t if(list.get(center).compareTo(key)>=0)upper=center; \n\t\t else lower=center; \n\t\t } \n\t\t return upper; \n\t } \n\t @SuppressWarnings(\"unchecked\") \n\t static int upper_bound(List list, T key){ \n\t\t int lower=-1;int upper=list.size(); \n\t\t while(upper-lower >1){ \n\t\t int center=(upper+lower)/2; \n\t\t if(list.get(center).compareTo(key)>0)upper=center; \n\t\t else lower=center; \n\t\t } \n\t\t return upper; \n\t } \n\t @SuppressWarnings(\"unchecked\") \n\t static boolean next_permutation(List list){ \n\t\t int lastIndex = list.size()-2; \n\t\t while(lastIndex>=0 && list.get(lastIndex).compareTo(list.get(lastIndex+1))>=0)--lastIndex; \n\t\t if(lastIndex<0)return false; \n\t\t int swapIndex = list.size()-1; \n\t\t while(list.get(lastIndex).compareTo(list.get(swapIndex))>=0)swapIndex--; \n\t\t T tmp = list.get(lastIndex); \n\t\t list.set(lastIndex++, list.get(swapIndex)); \n\t\t list.set(swapIndex, tmp); \n\t\t swapIndex = list.size()-1; \n\t\t while(lastIndex0; \n\t } \n\t private static int readByte(){ if(hasNextByte()) return buffer[ptr++]; else return -1;} \n\t private static boolean isSpaceChar(int c){ return !(33<=c && c<=126);} \n\t private static int skip(){int res; while((res=readByte())!=-1 && isSpaceChar(res)); return res;} \n \n\t private static double nd(){ return Double.parseDouble(ns()); } \n\t private static char nc(){ return (char)skip(); } \n\t private static String ns(){ \n\t\t StringBuilder sb = new StringBuilder(); \n\t\t for(int b=skip();!isSpaceChar(b);b=readByte())sb.append((char)b); \n\t\t return sb.toString(); \n\t } \n\t private static int[] nia(int n){ \n\t\t int[] res = new int[n]; \n\t\t for(int i=0;i='0'&&b<='9') || b=='-')); \n\t\t if(b=='-'){ \n\t\t\t minus=true; \n\t\t\t b=readByte(); \n\t\t } \n\t\t for(;'0'<=b&&b<='9';b=readByte())res=res*10+(b-'0'); \n\t\t return minus ? -res:res; \n\t } \n\t private static long nl(){ \n\t\t long res=0,b; \n\t\t boolean minus=false; \n\t\t while((b=readByte())!=-1 && !((b>='0'&&b<='9') || b=='-')); \n\t\t if(b=='-'){ \n\t\t\t minus=true; \n\t\t\t b=readByte(); \n\t\t } \n\t\t for(;'0'<=b&&b<='9';b=readByte())res=res*10+(b-'0'); \n\t\t return minus ? -res:res; \n\t} \n} \n\n", "lang_cluster": "Java", "tags": ["dfs and similar", "dp", "shortest paths"], "code_uid": "9b815f9e68a3e9d8224d9882d0a8ab46", "src_uid": "5fe44b6cd804e0766a0e993eca1846cd", "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.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 Roy\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 D1DominoEasyVersion solver = new D1DominoEasyVersion();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class D1DominoEasyVersion {\n private boolean found;\n\n private void solveEvenXEvenMatrix(int dominoes) {\n //~ if the matrix is: even x even\n //~ then it is enough to check the number of dominoes are even or not\n if (dominoes % 2 == 0) found = true;\n }\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int tc = in.readInteger();\n for (int cs = 1; cs <= tc; ++cs) {\n int n = in.readInteger();\n int m = in.readInteger();\n int k = in.readInteger();\n\n found = false;\n if (n % 2 == 0 && m % 2 == 0) {//~ even x even matrix\n solveEvenXEvenMatrix(k);\n } else if (n % 2 == 0 && m % 2 == 1) {//~ even x odd matrix\n int maxPossibleHorizons = (m * n) / 2 - (n / 2);\n\n if (k <= maxPossibleHorizons) {//~ k should not be > maxPossibleHorizons\n solveEvenXEvenMatrix(k);\n }\n } else if (n % 2 == 1 && m % 2 == 0) { //~ odd x even matrix\n int leastHorizons = m / 2;\n if (k >= leastHorizons) {\n int restHorizons = k - leastHorizons;\n solveEvenXEvenMatrix(restHorizons);\n }\n }\n if (found) out.printLine(\"YES\");\n else out.printLine(\"NO\");\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\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 readInteger() {\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 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 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 }\n writer.print(objects[i]);\n }\n }\n\n public void printLine(Object... objects) {\n this.print(objects);\n writer.println();\n }\n\n public void close() {\n writer.flush();\n writer.close();\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["math", "constructive algorithms"], "code_uid": "59ca7fbbf32da42055962b09af50c1a6", "src_uid": "4d0c0cc8faca62eb6384f8135b30feb8", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.lang.*;\n \n //@Manan Parmar\n\npublic class Solution2 implements Runnable {\n\n\n public void run() {\n \n InputReader sc = new InputReader(System.in);\n PrintWriter out = new PrintWriter(System.out);\n \n int y=sc.nextInt(),b=sc.nextInt(),r=sc.nextInt();\n if(y<=b&&y1&&b-y>=1)\n out.println(y+(y+1)+(y+2));\n else\n out.println((y-1)+y+(y+1));\n }\n else if(b<=y&&b= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n }\n catch (IOException e) {\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 String str = \"\";\n try {\n str = br.readLine();\n }\n catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n public int nextInt() {\n int c = read();\n \n while(isSpaceChar(c))\n c = read();\n \n int sgn = 1;\n \n if (c == '-') {\n sgn = -1;\n c = read();\n }\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 }\n while (!isSpaceChar(c));\n \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 \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 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 \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 }\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 String next() {\n return readString();\n }\n \n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n }\n\n public static void main(String args[]) throws Exception {\n new Thread(null, new Solution2(),\"Main\",1<<27).start();\n }\n}\n", "lang_cluster": "Java", "tags": ["brute force", "math", "implementation"], "code_uid": "1bfc274b9d8f7b52b45af907d8a9dd35", "src_uid": "03ac8efe10de17590e1ae151a7bae1a5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\n/**\n *\n * @author LittleBird\n */\npublic class Main {\n\n public static void main(String[] args) {\n Scanner cin = new Scanner(System.in);\n\n int n = cin.nextInt();\n int k = cin.nextInt();\n\n String cell = cin.next();\n\n\n int tPos = 0, pPos = 0;\n for (int i = 0; i < cell.length(); i++) {\n\n if (cell.charAt(i) == 'T') {\n tPos = i;\n }\n if (cell.charAt(i) == 'G') {\n pPos = i;\n }\n }\n \n\n int minv = Math.min(tPos, pPos);\n boolean flag = true;\n while (flag) {\n minv += k;\n if (minv >= n) {\n break;\n }\n if (cell.charAt(minv) == '#') {\n break;\n }\n if (cell.charAt(minv) == 'T' || cell.charAt(minv) == 'G') {\n flag = false;\n }\n }\n if (flag) {\n System.out.println(\"NO\");\n } else {\n System.out.println(\"YES\");\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["strings", "implementation"], "code_uid": "bdc32e6e0883c86387a6c5b4a20cf327", "src_uid": "189a9b5ce669bdb04b9d371d74a5dd41", "difficulty": 800.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 long mod=1000000007,m;\n\tstatic long[] a,b;\n\tpublic static void main(String[] args) throws IOException\n\t{\n\t\tFastReader in=new FastReader();\n\t\tPrintWriter pw=new PrintWriter(System.out);\n\t\tlong n=in.nextLong();\n\t\tif(n==1)\n\t\t\tpw.println(1);\n\t\telse\n\t\t{\n\t\t\tlong ans=0;\n\t\t\tfor(long i=1;i*i<=n;i++)\n\t\t\t{\n\t\t\t\tif(n%i==0)\n\t\t\t\t\tans+=2;\n\t\t\t\tif(i*i==n)\n\t\t\t\t\tans--;\n\t\t\t}\n\t\t\tpw.println(ans);\n\t\t}\n\t\tpw.flush();\n\t}\n}\n\nclass pair\n{\n\tA f;\n\tB s;\n\n\tpublic pair(A a,B b)\n\t{\n\t\tf=a;\n\t\ts=b;\n\t}\n}\n\nclass FastReader\n{\n\tBufferedReader br;\n\tStringTokenizer st;\n \n\tpublic FastReader()\n\t{\n\t\tbr=new BufferedReader(new InputStreamReader(System.in));\n\t}\n \n\tpublic String next() throws IOException\n\t{\n\t\tif(st==null || !st.hasMoreElements())\n\t\t{\n\t\t\tst=new StringTokenizer(br.readLine());\n\t\t}\n\t\treturn st.nextToken();\n\t}\n \n\tpublic int nextInt() throws IOException\n\t{\n\t\treturn Integer.parseInt(next());\n\t}\n \n\tpublic long nextLong() throws IOException\n\t{\n\t\treturn Long.parseLong(next());\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "number theory"], "code_uid": "7eb3cfdcacf912a49312c49415d92f9f", "src_uid": "7fc9e7d7e25ab97d8ebc10ed8ae38fd1", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n/**\n * @author OleGG\n */\npublic class Task92A {\n public int chips(int n, int m) {\n m %= n * (n + 1) / 2;\n for (int i = 1; i <= m; ++i) {\n m -= i;\n }\n return m;\n }\n\n public static void main(String[] args) throws Throwable {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int m = sc.nextInt();\n System.out.println(new Task92A().chips(n, m));\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "84f726fad0b8cd94884d7c2b2c6112f4", "src_uid": "5dd5ee90606d37cae5926eb8b8d250bb", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class ProblemA_62 {\n \n final boolean ONLINE_JUDGE=System.getProperty(\"ONLINE_JUDGE\")!=null;\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 }\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 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 public static void main(String[] args){\n new ProblemA_62().run();\n }\n \n public void run(){\n try{\n long t1=System.currentTimeMillis();\n init();\n solve();\n out.close();\n long t2=System.currentTimeMillis();\n System.err.println(\"Time = \"+(t2-t1));\n }catch (Exception e){\n e.printStackTrace(System.err);\n System.exit(-1);\n }\n }\n \npublic class Permutation {\n \n int[] a;\n int n;\n \n public Permutation(int n){\n this.n=n;\n a=new int[n];\n for (int i=0; i=0; i--){\n if (a[i]i; j--){\n if (a[i]= 7){\n count++;\n }\n }\n out.print(count);\n } \n}", "lang_cluster": "Java", "tags": ["implementation", "number theory"], "code_uid": "0fa03ef16cf7168354d54a93a8b63e36", "src_uid": "63b9dc70e6ad83d89a487ffebe007b0a", "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.StringTokenizer;\n\npublic class Main {\n\n\tprivate void solve() throws IOException{\n\t\tInputStreamReader isr = new InputStreamReader(System.in);\n\t\tBufferedReader br = new BufferedReader(isr);\n\t\tint n = Integer.parseInt(br.readLine());\n\t\tbyte[] pairs = new byte[n];\n\t\tStringTokenizer st = new StringTokenizer(br.readLine(), \" \");\n\t\tint stay = 0;\n\t\t\n\t\t//input\n\t\tfor(int i = 0; i < n; i++)\n\t\t\tpairs[i] = Byte.parseByte(st.nextToken());\n\t\t\t\n\t\tif(n > 1){\n\t\t\tif(pairs[0] != 0)\n\t\t\t\tif(pairs[0] != 0 || pairs[1] != 0) stay++;\n\t\t\tfor(int i = 1; i < n-1; i++){\n\t\t\t\tif(pairs[i] == 0){\n\t\t\t\t\tif(pairs[i-1] != 0 && pairs[i+1] != 0) stay++;\n\t\t\t\t}else{\n\t\t\t\t\tstay++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(pairs[n-1] != 0) stay++;\n\t\t}else{\n\t\t\tif(pairs[0] == 1) stay++;\n\t\t}\n\t\t\n\t\tSystem.out.println(stay);\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException{\n\t\tMain m = new Main();\n\t\tm.solve();\n\t}\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "131e0df6eafba94d661185320a1a8377", "src_uid": "2896aadda9e7a317d33315f91d1ca64d", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class Main {\n\n\tBufferedReader in;\n\tStringTokenizer str = null;\n\tPrintWriter out;\n\t\n\tprivate String next() throws Exception{\n\t\twhile (str == null || !str.hasMoreElements())\n\t\t\tstr = new StringTokenizer(in.readLine());\n\t\treturn str.nextToken();\n\t}\n\t\n\tprivate int nextInt() throws Exception{\n\t\treturn Integer.parseInt(next());\n\t}\n\t\n\tprivate long nextLong() throws Exception{\n\t\treturn Long.parseLong(next());\n\t}\n\t\n\tprivate double nextDouble() throws Exception{\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tfinal long oo = Long.MAX_VALUE;\n\t\n\tpublic void run() throws Exception{\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tlong t = nextLong(), w = nextLong(), b = nextLong();\n\t\tif (t < Math.min(w, b) || w == b)\t{\n\t\t\tout.println(\"1/1\");\n\t\t\tout.close();\n\t\t\treturn;\n\t\t}\n\n\t\tlong gcd = gcd(w, b);\n\t\tBigInteger lcm = new BigInteger(\"\" + w).divide(new BigInteger(\"\" + gcd)).multiply(new BigInteger(\"\" + b));\n\t\t// long lcm = w / gcd * b;\n\t\t// System.out.println(\"lcm = \" + lcm);\n\n\t\t// long num = (t / lcm - 1) * Math.min(w, b);\n\t\tBigInteger bigT = new BigInteger(\"\" + t);\n\t\tBigInteger step = new BigInteger(\"\" + Math.min(w, b));\n\t\tBigInteger num = ((bigT.divide(lcm)).subtract(BigInteger.ONE)).multiply(step);\n\t\tnum = num.add(step.subtract(BigInteger.ONE));\n\t\t// num += Math.min(w, b) - 1;\n\n\t\t// if (bigT.mod(lcm).longValue() != 0) {\n\t\t\tBigInteger l = bigT.divide(lcm).multiply(lcm);\n\t\t\tBigInteger left = bigT.subtract(l).add(BigInteger.ONE);\n\t\t\tif (step.compareTo(left) > 0) {\n\t\t\t\tnum = num.add(left);\n\t\t\t}else {\n\t\t\t\tnum = num.add(step);\n\t\t\t}\n\t\t// }\n\t\t// if (t % lcm != 0) {\n\t\t// \tlong l = (t / lcm) * lcm;\n\t\t// \tlong left = t - l + 1;\n\t\t// \tnum += Math.min(Math.min(w, b), left);\n\t\t// }\n\t\tlong nn = num.longValue();\n\t\tgcd = gcd(nn, t);\n\t\tnn /= gcd;\n\t\tt /= gcd;\n\n\t\tout.println(nn + \"/\" + t);\n\t\tout.close();\n\t}\n\n\tprivate long gcd(long a, long b) {\n\t\treturn (b == 0) ? a : gcd(b, a % b);\n\t}\n\t\t\n\tpublic static void main(String[] args) throws Exception{\n\t\tnew Main().run();\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "1cf524906ffeb42ca7e19c9ad860935f", "src_uid": "7a1d8ca25bce0073c4eb5297b94501b5", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.util.Comparator;\nimport java.io.OutputStream;\nimport java.util.ArrayDeque;\nimport java.io.PrintWriter;\nimport java.util.NoSuchElementException;\nimport java.io.Writer;\nimport java.util.Queue;\nimport java.math.BigInteger;\nimport java.util.Collection;\nimport java.io.InputStream;\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 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, OutputWriter out) {\n long x = in.readLong();\n long y = in.readLong();\n long m = in.readLong();\n\n if (x >= m || y >= m) {\n out.printLine(0);\n return;\n }\n\n if (x <= 0 && y <= 0) {\n out.printLine(-1);\n return;\n }\n\n long answer = 0;\n\n if (x < 0) {\n answer += (Math.abs(x) + y) / y;\n x = x + answer * y;\n }\n\n if (y < 0) {\n answer += (Math.abs(y) + x) / x;\n y = y + answer * x;\n }\n\n Queue> pairQueue = new ArrayDeque>();\n\n pairQueue.add(Pair.makePair(x, y));\n\n while (true) {\n Pair[] temp = new Pair[pairQueue.size()];\n pairQueue.toArray(temp);\n pairQueue = new ArrayDeque>();\n for (Pair cur : temp) {\n if (cur.first >= m || cur.second >= m) {\n out.printLine(answer);\n return;\n }\n if (cur.first > 0 && cur.first >= cur.second)\n pairQueue.add(Pair.makePair(cur.first, cur.first + cur.second));\n if (cur.second > 0 && cur.second >= cur.first)\n pairQueue.add(Pair.makePair(cur.first + cur.second, cur.second));\n }\n answer++;\n }\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 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 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 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 interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\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 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\nclass Pair implements Comparable> {\n\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 public Pair(U first, V second) {\n this.first = first;\n this.second = second;\n }\n\n public boolean equals(Object o) {\n if (this == o) return true;\n if (o == null || getClass() != o.getClass()) return false;\n\n Pair pair = (Pair) o;\n\n return !(first != null ? !first.equals(pair.first) : pair.first != null) && !(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 public String toString() {\n return \"(\" + first + \",\" + second + \")\";\n }\n\n public int compareTo(Pair o) {\n int value = ((Comparable)first).compareTo(o.first);\n if (value != 0)\n return value;\n return ((Comparable)second).compareTo(o.second);\n }\n}\n\n", "lang_cluster": "Java", "tags": ["brute force"], "code_uid": "e6a996f3f117eb0a9b6f9109921aa8e2", "src_uid": "82026a3c3d9a6bda2e2ac6e14979d821", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.util.Scanner;\n\npublic class Main\n{\n\n\tstatic Scanner in = new Scanner(System.in);\n\n\tpublic static void main(String[] args) throws IOException\n\t{\n\n\t\tlong n = in.nextLong();\n\t\tlong s = in.nextLong();\n\t\tlong minNum = getMin(s);\n\t\t//System.out.println(\"minNum==\" + minNum);\n\t\tif (n < minNum)\n\t\t\tSystem.out.println(0);\n\t\telse\n\t\t{\n\t\t\tSystem.out.println(n - minNum + 1);\n\t\t}\n\n\t}\n\n\tstatic long getMin(long s)\n\t{\n\t\tlong ans = (s / 9) * 9;\n\t\tif (ans != s)\n\t\t\tans += 9;\n\n\t\tans = ans - ans % 10 + 10;\n\t\twhile (true)\n\t\t{\n\t\t\tif (ans - getStringSum(ans) >= s)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tans += 10;\n\t\t}\n\t\treturn ans;\n\t}\n\n\tstatic int getStringSum(long s)\n\t{\n\t\tint sum = 0;\n\t\twhile (s != 0)\n\t\t{\n\t\t\tsum += s % 10;\n\t\t\ts = s / 10;\n\t\t}\n\t\treturn sum;\n\t}\n\n}", "lang_cluster": "Java", "tags": ["brute force", "math", "dp", "binary search"], "code_uid": "8c8b5e630016fb60f3b7dd9e82d3f930", "src_uid": "9704e2ac6a158d5ced8fd1dc1edb356b", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.HashMap;\n\n\npublic class CF_218_2_B {\n static HashMap weights = new HashMap<>();\n static int ans = 1 << 30;\n \n public static void main(String[] args) throws Exception {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n String[] line = br.readLine().split(\"\\\\s\");\n int a = Integer.parseInt(line[0]);\n int b = Integer.parseInt(line[1]);\n \n f(a, 0);\n f2(b, 0);\n if (ans == 1 << 30)\n System.out.println(-1);\n else\n System.out.println(ans);\n }\n \n static void f(int a, int d) {\n if (weights.containsKey(a))\n return;\n \n weights.put(a, d);\n\n if (a % 2 == 0)\n f(a / 2, d + 1);\n if (a % 3 == 0)\n f(a / 3, d + 1);\n if (a % 5 == 0)\n f(a / 5, d + 1);\n }\n \n static void f2(int b, int d) {\n if (weights.containsKey(b)) {\n ans = Math.min(ans, d + weights.get(b));\n return;\n }\n\n if (b % 2 == 0)\n f2(b / 2, d + 1);\n if (b % 3 == 0)\n f2(b / 3, d + 1);\n if (b % 5 == 0)\n f2(b / 5, d + 1);\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "number theory"], "code_uid": "8631ce025a14feb4a9a62d88ce0e949e", "src_uid": "75a97f4d85d50ea0e1af0d46f7565b49", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.*;\npublic class substring\n{\npublic static void main(String[] args)\n{\nScanner input = new Scanner(System.in);\nString s = input.nextLine();\nBoolean found = false;\nint i = s.length();\nwhile(found==false)\n{\ni--;\nArrayList sub = new ArrayList();\nfor(int j = 0; j <= s.length() - i; j++)\n{\nif(sub.contains(s.substring(j, j+i)))\nfound = true;\nelse\nsub.add(s.substring(j, j+i));\n}\n\n}\nSystem.out.println(i);\n}\n}", "lang_cluster": "Java", "tags": ["brute force", "greedy"], "code_uid": "67e9dfa56073999d4e7d995d68128865", "src_uid": "13b5cf94f2fabd053375a5ccf3fd44c7", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import 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 a = scan.nextInt(), b = scan.nextInt();\n\t\tif (a > b) {\n\t\t\tSystem.out.print(b + \" \");\n\t\t\ta -= b;\n\t\t\ta /= 2;\n\t\t\tSystem.out.print(a + \" \");\n\t\t} else {\n\t\t\tSystem.out.print(a + \" \");\n\t\t\tb -= a;\n\t\t\tb /= 2;\n\t\t\tSystem.out.print(b + \" \");\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "8e45a34af7ce8c29ec9225ec3c1745e5", "src_uid": "775766790e91e539c1cfaa5030e5b955", "difficulty": 800.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.*;\n\npublic class TaskB implements Runnable {\n boolean prime[] = new boolean[100001];\n void sieveOfEratosthenes(int n) {\n for (int i = 0; i < n; i++)\n prime[i] = true;\n for (int p = 2; p * p <= n; p++) {\n if (prime[p] == true) {\n for (int i = p * p; i <= n; i += p)\n prime[i] = false;\n }\n }\n }\n public void run() {\n InputReader c = new InputReader(System.in);\n PrintWriter w = new PrintWriter(System.out);\n int n=c.nextInt();\n int k=c.nextInt();\n int ans;\n k = Math.min(k,n-k+1);\n System.out.println(k+n*3-1);\n w.close();\n }\n\n public static void sortbyColumn(int arr[][], int col)\n {\n\n Arrays.sort(arr, new Comparator()\n {\n public int compare(int[] o1, int[] o2){\n return(Integer.valueOf(o1[col]).compareTo(o2[col]));\n }\n });\n\n }\n class Graph{\n private final int v;\n private List> adj;\n Graph(int v){\n this.v = v;\n adj = new ArrayList<>(v);\n for(int i=0;i());\n }\n }\n private void addEdge(int a,int b){\n adj.get(a).add(b);\n }\n private boolean isCyclic()\n {\n boolean[] visited = new boolean[v];\n boolean[] recStack = new boolean[v];\n for (int i = 0; i < v; i++)\n if (isCyclicUtil(i, visited, recStack))\n return true;\n\n return false;\n }\n private boolean isCyclicUtil(int i, boolean[] visited, boolean[] recStack)\n {\n if (recStack[i])\n return true;\n if (visited[i])\n return false;\n visited[i] = true;\n recStack[i] = true;\n List children = adj.get(i);\n for (Integer c: children)\n if (isCyclicUtil(c, visited, recStack))\n return true;\n recStack[i] = false;\n return false;\n }\n }\n static long gcd(long a, long b)\n {\n if (b == 0)\n return a;\n return gcd(b, a % b);\n }\n public static class DJSet {\n public int[] upper;\n\n public DJSet(int n) {\n upper = new int[n];\n Arrays.fill(upper, -1);\n }\n\n public int root(int x) {\n return upper[x] < 0 ? x : (upper[x] = root(upper[x]));\n }\n\n public boolean equiv(int x, int y) {\n return root(x) == root(y);\n }\n\n public boolean union(int x, int y) {\n x = root(x);\n y = root(y);\n if (x != y) {\n if (upper[y] < upper[x]) {\n int d = x;\n x = y;\n y = d;\n }\n upper[x] += upper[y];\n upper[y] = x;\n }\n return x == y;\n }\n }\n public static int[] radixSort(int[] f)\n {\n int[] to = new int[f.length];\n {\n int[] b = new int[65537];\n for(int i = 0;i < f.length;i++)b[1+(f[i]&0xffff)]++;\n for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n for(int i = 0;i < f.length;i++)to[b[f[i]&0xffff]++] = f[i];\n int[] d = f; f = to;to = d;\n }\n {\n int[] b = new int[65537];\n for(int i = 0;i < f.length;i++)b[1+(f[i]>>>16)]++;\n for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n for(int i = 0;i < f.length;i++)to[b[f[i]>>>16]++] = f[i];\n int[] d = f; f = to;to = d;\n }\n return f;\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 SpaceCharFilter filter;\n private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\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 }\n catch (IOException e) {\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 String str = \"\";\n try {\n str = br.readLine();\n }\n catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n public int nextInt() {\n int c = read();\n\n while(isSpaceChar(c))\n c = read();\n\n int sgn = 1;\n\n if (c == '-') {\n sgn = -1;\n c = read();\n }\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 }\n while (!isSpaceChar(c));\n\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\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 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\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 }\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 String next() {\n return readString();\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n }\n public static void main(String args[]) throws Exception {\n new Thread(null, new TaskB(),\"TaskB\",1<<26).start();\n }\n}", "lang_cluster": "Java", "tags": ["math", "constructive algorithms"], "code_uid": "4ec59483d7f6a012739ea0c7d9c8338a", "src_uid": "24b02afe8d86314ec5f75a00c72af514", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\n\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.nio.charset.Charset;\nimport java.util.Arrays;\n\npublic class CF1161C {\n public static void main(String[] args) throws Exception {\n boolean local = System.getProperty(\"ONLINE_JUDGE\") == null;\n boolean async = false;\n\n Charset charset = Charset.forName(\"ascii\");\n\n FastIO io = local ? new FastIO(new FileInputStream(\"D:\\\\DATABASE\\\\TESTCASE\\\\Code.in\"), System.out, charset) : new FastIO(System.in, System.out, charset);\n Task task = new Task(io, new Debug(local));\n\n if (async) {\n Thread t = new Thread(null, task, \"dalt\", 1 << 27);\n t.setPriority(Thread.MAX_PRIORITY);\n t.start();\n t.join();\n } else {\n task.run();\n }\n\n if (local) {\n io.cache.append(\"\\n\\n--memory -- \\n\" + ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) >> 20) + \"M\");\n }\n\n io.flush();\n }\n\n public static class Task implements Runnable {\n final FastIO io;\n final Debug debug;\n int inf = (int) 1e8;\n int mod = (int) 1e9 + 7;\n\n public int mod(int val) {\n val %= mod;\n if (val < 0) {\n val += mod;\n }\n return val;\n }\n\n public int mod(long val) {\n val %= mod;\n if (val < 0) {\n val += mod;\n }\n return (int) val;\n }\n\n int bitAt(int x, int i) {\n return (x >> i) & 1;\n }\n\n int bitAt(long x, int i) {\n return (int) ((x >> i) & 1);\n }\n\n public Task(FastIO io, Debug debug) {\n this.io = io;\n this.debug = debug;\n }\n\n @Override\n public void run() {\n solve();\n }\n\n public void solve() {\n int n = io.readInt();\n int m = 50;\n int cnt = 0;\n for (int i = 0; i < n; i++) {\n int v = io.readInt();\n if (m > v) {\n m = v;\n cnt = 0;\n }\n if (m == v) {\n cnt++;\n }\n }\n\n if (cnt > n / 2) {\n io.cache.append(\"Bob\");\n } else {\n io.cache.append(\"Alice\");\n }\n }\n }\n\n public static class FastIO {\n public final StringBuilder cache = new StringBuilder();\n private final InputStream is;\n private final OutputStream os;\n private final Charset charset;\n private StringBuilder defaultStringBuf = new StringBuilder(1 << 8);\n private byte[] buf = new byte[1 << 13];\n private int bufLen;\n private int bufOffset;\n private int next;\n\n public FastIO(InputStream is, OutputStream os, Charset charset) {\n this.is = is;\n this.os = os;\n this.charset = charset;\n }\n\n public FastIO(InputStream is, OutputStream os) {\n this(is, os, Charset.forName(\"ascii\"));\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 throw new RuntimeException(e);\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 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 public double readDouble() {\n boolean sign = true;\n skipBlank();\n if (next == '+' || next == '-') {\n sign = next == '+';\n next = read();\n }\n\n long val = 0;\n while (next >= '0' && next <= '9') {\n val = val * 10 + next - '0';\n next = read();\n }\n if (next != '.') {\n return sign ? val : -val;\n }\n next = read();\n long radix = 1;\n long point = 0;\n while (next >= '0' && next <= '9') {\n point = point * 10 + next - '0';\n radix = radix * 10;\n next = read();\n }\n double result = val + (double) point / radix;\n return sign ? result : -result;\n }\n\n public String readString(StringBuilder builder) {\n skipBlank();\n\n while (next > 32) {\n builder.append((char) next);\n next = read();\n }\n\n return builder.toString();\n }\n\n public String readString() {\n defaultStringBuf.setLength(0);\n return readString(defaultStringBuf);\n }\n\n public int readLine(char[] data, int offset) {\n int originalOffset = offset;\n while (next != -1 && next != '\\n') {\n data[offset++] = (char) next;\n next = read();\n }\n return offset - originalOffset;\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 public int readString(byte[] data, int offset) {\n skipBlank();\n\n int originalOffset = offset;\n while (next > 32) {\n data[offset++] = (byte) next;\n next = read();\n }\n\n return offset - originalOffset;\n }\n\n public char readChar() {\n skipBlank();\n char c = (char) next;\n next = read();\n return c;\n }\n\n public void flush() {\n try {\n os.write(cache.toString().getBytes(charset));\n os.flush();\n cache.setLength(0);\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n\n public boolean hasMore() {\n skipBlank();\n return next != -1;\n }\n }\n\n public static class Debug {\n private boolean allowDebug;\n\n public Debug(boolean allowDebug) {\n this.allowDebug = allowDebug;\n }\n\n public void assertTrue(boolean flag) {\n if (!allowDebug) {\n return;\n }\n if (!flag) {\n fail();\n }\n }\n\n public void fail() {\n throw new RuntimeException();\n }\n\n public void assertFalse(boolean flag) {\n if (!allowDebug) {\n return;\n }\n if (flag) {\n fail();\n }\n }\n\n private void outputName(String name) {\n System.out.print(name + \" = \");\n }\n\n public void debug(String name, int x) {\n if (!allowDebug) {\n return;\n }\n\n outputName(name);\n System.out.println(\"\" + x);\n }\n\n public void debug(String name, long x) {\n if (!allowDebug) {\n return;\n }\n outputName(name);\n System.out.println(\"\" + x);\n }\n\n public void debug(String name, double x) {\n if (!allowDebug) {\n return;\n }\n outputName(name);\n System.out.println(\"\" + x);\n }\n\n public void debug(String name, int[] x) {\n if (!allowDebug) {\n return;\n }\n outputName(name);\n System.out.println(Arrays.toString(x));\n }\n\n public void debug(String name, long[] x) {\n if (!allowDebug) {\n return;\n }\n outputName(name);\n System.out.println(Arrays.toString(x));\n }\n\n public void debug(String name, double[] x) {\n if (!allowDebug) {\n return;\n }\n outputName(name);\n System.out.println(Arrays.toString(x));\n }\n\n public void debug(String name, Object x) {\n if (!allowDebug) {\n return;\n }\n outputName(name);\n System.out.println(\"\" + x);\n }\n\n public void debug(String name, Object... x) {\n if (!allowDebug) {\n return;\n }\n outputName(name);\n System.out.println(Arrays.deepToString(x));\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["games"], "code_uid": "170288955029e353f67b95c3f90a845a", "src_uid": "4b9cf82967aa8441e9af3db3101161e9", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n\npublic class P912B {\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n\n long n = input.nextLong();\n long k = input.nextLong();\n\n long ans = Long.highestOneBit(n);\n System.out.println(k == 1 ? n : (ans - 1) | (ans));\n }\n}\n", "lang_cluster": "Java", "tags": ["constructive algorithms", "number theory", "bitmasks"], "code_uid": "43b2537b31502ed43bc436b7bacf5258", "src_uid": "16bc089f5ef6b68bebe8eda6ead2eab9", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": " import java.util.HashSet;\n import java.util.Scanner;\n import java.util.Set;\n\n public 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 str = sc.next();\n StringBuilder sb = new StringBuilder(str);\n for (int i = 0; i < str.length(); i++)\n sb.setCharAt(i, Character.toLowerCase(str.charAt(i)));\n str = sb.toString();\n Set letters = new HashSet();\n for (int i = 0; i < n ; i++) {\n letters.add(str.charAt(i));\n }\n if(letters.size()==26)\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n }\n }", "lang_cluster": "Java", "tags": ["strings", "implementation"], "code_uid": "a10782722bc4559c3dad9b64e80bc0a2", "src_uid": "f13eba0a0fb86e20495d218fc4ad532d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\n\npublic class _v11 {\n\n public static void main(String args[]){\n\n PrintWriter out = new PrintWriter(System.out);\n Reader in = new Reader();\n long k = in.nextLong();\n long a = in.nextLong();\n long b = in.nextLong();\n if(a= numChars) {\n curChar = 0;\n try {\n numChars = mIs.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 next() {\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 double nextDouble()\n {\n return Double.parseDouble(next());\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 boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public boolean isEndOfLine(int c) {\n return c == '\\n' || c == '\\r' || c == -1;\n }\n\n }\n\n}\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "bc05cd36361ca261402621e9fa33fe82", "src_uid": "6e3b8193d1ca1a1d449dc7a4ad45b8f2", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class Codeforce1 {\n\n public static void main(String[] args) {\n Scanner reader = new Scanner(System.in);\n int n = reader.nextInt();\n \n int res=(int)n/3;\n if (n%3==1 || n%3==2){\n res=(res*2)+1;\n }\n else{\n res=res*2;\n }\n System.out.print(res);\n }\n}", "lang_cluster": "Java", "tags": ["math"], "code_uid": "fa08ed5ccdf28ce86bbe5610d7681bef", "src_uid": "a993069e35b35ae158d35d6fe166aaef", "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.Arrays;\nimport java.util.regex.Pattern;\n\npublic class Solution {\n\n\tprivate static boolean check(String s) {\n\t\tif (s.split(\"@\").length != 2)\n\t\t\treturn false;\n\t\t\n\t\tif (s.charAt(0) == '@' || s.charAt(s.length() - 1) == '@')\n\t\t\treturn false;\n\n\t\tString username = s.split(\"@\")[0];\n\t\tString remains = s.split(\"@\")[1];\n\n\t\tif (remains.split(\"/\").length > 2)\n\t\t\treturn false;\n\t\tif (remains.charAt(remains.length() - 1) == '/')\n\t\t\treturn false;\n\t\t\n\t\tString hostname = remains.split(\"/\")[0];\n\n\t\tif (hostname.length() < 1 || hostname.length() > 32)\n\t\t\treturn false;\n\n\t\tPattern p = Pattern.compile(\"[A-Za-z0-9_]{1,16}\");\n\n\t\tString[] temp_hp = hostname.split(\"\\\\.\");\n\n\t\tint cnt = temp_hp.length + (hostname.charAt(0) == '.' ? 1 : 0)\n\t\t\t\t+ (hostname.charAt(hostname.length() - 1) == '.' ? 1 : 0);\n\n\t\tString[] host_parts = new String[cnt];\n\t\tArrays.fill(host_parts, \"\");\n\t\tfor (int i = 0; i < temp_hp.length; ++i)\n\t\t\thost_parts[i] = temp_hp[i];\n\n\t\t// System.err.println(\"hostname = \" + hostname);\n\t\t// System.err.println(\"host_parts.length = \" + host_parts.length);\n\n\t\tif (!p.matcher(username).matches())\n\t\t\treturn false;\n\n\t\tfor (String hp : host_parts)\n\t\t\tif (!p.matcher(hp).matches())\n\t\t\t\treturn false;\n\n\t\tif (remains.split(\"/\").length == 2) {\n\t\t\tString resourse = remains.split(\"/\")[1];\n\t\t\treturn p.matcher(resourse).matches();\n\t\t}\n\n\t\treturn true;\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tString s = br.readLine();\n\t\tif (check(s))\n\t\t\tSystem.out.println(\"YES\");\n\t\telse\n\t\t\tSystem.out.println(\"NO\");\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["strings", "implementation"], "code_uid": "261a5bc9db2791184508fa9fa5b27f4f", "src_uid": "2a68157e327f92415067f127feb31e24", "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.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.PriorityQueue;\nimport java.util.Random;\nimport java.util.StringTokenizer;\n/*\n 4\n1 3 2 0\n */\npublic class A {\n\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tFastScanner sc = new FastScanner();\n\t\tint n = sc.nextInt();\n\t\tint arr[] = sc.readArray(n);\n\t\tint dp[][] = new int[n+1][3];\n\t\tif(arr[0] == 1 || arr[0] == 3) {\n\t\t\tdp[0][1] = 1;\n\t\t}\n\t\tif(arr[0] == 2 || arr[0] == 3) {\n\t\t\tdp[0][2] = 1;\n\t\t}\n\t\tfor(int i=1; i 0) {\n\t\t\tif (y % 2 == 1)\n\t\t\t\tres = (res * x);\n\t\t\ty >>= 1;\n\t\t\tx = (x * x);\n\t\t}\n\t\treturn res;\n\t}\n\n\tstatic long power(long x, long y) {\n\t\tlong res = 1;\n\t\twhile (y > 0) {\n\t\t\tif (y % 2 == 1)\n\t\t\t\tres = (res * x);\n\t\t\ty >>= 1;\n\t\t\tx = (x * x);\n\t\t}\n\t\treturn res;\n\t}\n\n\tstatic void intsort(int[] a) {\n\t\tList temp = new ArrayList();\n\t\tfor (int i = 0; i < a.length; i++)\n\t\t\ttemp.add(a[i]);\n\t\tCollections.sort(temp);\n\t\tfor (int i = 0; i < a.length; i++)\n\t\t\ta[i] = temp.get(i);\n\t}\n\n\tstatic void longsort(long[] a) {\n\t\tList temp = new ArrayList();\n\t\tfor (int i = 0; i < a.length; i++)\n\t\t\ttemp.add(a[i]);\n\t\tCollections.sort(temp);\n\t\tfor (int i = 0; i < a.length; i++)\n\t\t\ta[i] = temp.get(i);\n\t}\n\n\tstatic void reverseintsort(int[] a) {\n\t\tList temp = new ArrayList();\n\t\tfor (int i = 0; i < a.length; i++)\n\t\t\ttemp.add(a[i]);\n\t\tCollections.sort(temp);\n\t\tCollections.reverseOrder();\n\t\tfor (int i = 0; i < a.length; i++)\n\t\t\ta[i] = temp.get(i);\n\t}\n\n\tstatic void reverselongsort(long[] a) {\n\t\tList temp = new ArrayList();\n\t\tfor (int i = 0; i < a.length; i++)\n\t\t\ttemp.add(a[i]);\n\t\tCollections.sort(temp);\n\t\tCollections.reverseOrder();\n\t\tfor (int i = 0; i < a.length; i++)\n\t\t\ta[i] = temp.get(i);\n\t}\n\n\tstatic class longpair implements Comparable {\n\t\tlong x, y;\n\n\t\tlongpair(long x, long y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\n\t\tpublic int compareTo(longpair p) {\n\t\t\treturn Long.compare(this.x, p.x);\n\t\t}\n\t}\n\n\tstatic class intpair implements Comparable {\n\t\tint x, y;\n\n\t\tintpair(int x, int y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(intpair o) {\n\t\t\treturn Integer.compare(this.x, o.x);\n\t\t}\n\n\t\t//\t\ta = new pair [n];\n\t\t//\t\ta[i] = new pair(coo,cost);\n\n\t}\n\n\tpublic static int gcd(int a, int b) {\n\t\tBigInteger b1 = BigInteger.valueOf(a);\n\t\tBigInteger b2 = BigInteger.valueOf(b);\n\t\tBigInteger gcd = b1.gcd(b2);\n\t\treturn gcd.intValue();\n\t}\n\n\tpublic static long gcd(long a, long b) {\n\t\tBigInteger b1 = BigInteger.valueOf(a);\n\t\tBigInteger b2 = BigInteger.valueOf(b);\n\t\tBigInteger gcd = b1.gcd(b2);\n\t\treturn gcd.longValue();\n\t}\n}\n", "lang_cluster": "Java", "tags": ["brute force", "dp"], "code_uid": "6743ba98078a6531c6a903ae7e47031c", "src_uid": "08f1ba79ced688958695a7cfcfdda035", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\npublic class SimpleMolecules {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();\n\t\tint sum = a + b + c;\n\t\tif ((sum & 1) != 0)\n\t\t\tSystem.out.println(\"Impossible\");\n\t\telse {\n\t\t\tsum >>= 1;\n\t\t\tint x = sum - a;\n\t\t\tint y = sum - b;\n\t\t\tint z = sum - c;\n\t\t\tif(x >= 0 && y >= 0 && z >= 0)\n\t\t\t\tSystem.out.printf(\"%d %d %d\\n\", z, x, y);\n\t\t\telse\n\t\t\t\tSystem.out.println(\"Impossible\");\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["brute force", "math", "graphs"], "code_uid": "a2b4d7e6dda98082894ac8d36e4dc52b", "src_uid": "b3b986fddc3770fed64b878fa42ab1bc", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.lang.reflect.Array;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\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 int x = ir.nextInt(), k = ir.nextInt();\n int min = Integer.MAX_VALUE;\n\n for (int i = 1; i < k; i++) {\n int f = Integer.MAX_VALUE, q = x / i;\n\n if (x % i == 0) f = q * k + i;\n\n min = Math.min(f, min);\n }\n\n pw.print(min);\n\n }\n\n private static void mergeSort(int[] array) {\n if(array.length == 1)\n return;\n int[] first = new int[array.length / 2];\n int[] second = new int[array.length - first.length];\n System.arraycopy(array, 0, first, 0, first.length);\n System.arraycopy(array, first.length, second, 0, second.length);\n\n mergeSort(first);\n mergeSort(second);\n\n merge(first, second, array);\n }\n\n private static void merge(int[] first, int[] second, int[] result) {\n int iFirst = 0;\n int iSecond = 0;\n int j = 0;\n\n while (iFirst < first.length && iSecond < second.length) {\n if (first[iFirst] < second[iSecond]) {\n result[j] = first[iFirst];\n iFirst++;\n }\n else {\n result[j] = second[iSecond];\n iSecond++;\n }\n j++;\n }\n System.arraycopy(first, iFirst, result, j, first.length - iFirst);\n System.arraycopy(second, iSecond, result, j, second.length - iSecond);\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;\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 null;\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": ["math"], "code_uid": "34778861922e3098156e4cdb24dde93f", "src_uid": "ed0ebc1e484fcaea875355b5b7944c57", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.StringTokenizer;\n\n\npublic class Main {\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 long m = sc.nextLong();\n long lo = 0;\n long hi = (long) 1e16;\n long ans = -1;\n while (lo <= hi) {\n long mid = (lo + hi) /2;\n long ways = getNumberofways(mid);\n if (ways == m) ans = mid;\n if (ways >= m) hi=mid-1;\n else lo = mid+1;\n }\n out.println(ans);\n out.close();\n out.flush();\n }\n\n static long getNumberofways(long n) {\n long cnt = 0;\n for (long k = 2; 1l * k * k * k <= n; k++) {\n long mult = 1l * k * k * k;\n cnt += n / mult;\n }\n return cnt;\n }\n\n\n static class Scanner {\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(InputStream system) {\n br = new BufferedReader(new InputStreamReader(system));\n }\n\n\n public String next() throws IOException {\n while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n public String nextLine() throws IOException {\n return br.readLine();\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 char nextChar() throws IOException {\n return next().charAt(0);\n }\n\n public Long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public boolean ready() throws IOException {\n return br.ready();\n }\n\n\n public int[] nextIntArray(int n) throws IOException {\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) throws IOException {\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 public Integer[] nextIntegerArray(int n) throws IOException {\n Integer[] a = new Integer[n];\n for (int i = 0; i < n; i++)\n a[i] = nextInt();\n return a;\n }\n\n public double[] nextDoubleArray(int n) throws IOException {\n double[] ans = new double[n];\n for (int i = 0; i < n; i++)\n ans[i] = nextDouble();\n return ans;\n }\n\n public short nextShort() throws IOException {\n return Short.parseShort(next());\n }\n\n }\n\n}", "lang_cluster": "Java", "tags": ["math", "binary search", "combinatorics"], "code_uid": "c2c07d3accf8cb9bd0bf1194c788f274", "src_uid": "602deaad5c66e264997249457d555129", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "\nimport java.util.*;\nimport java.util.Collections;\n\npublic class LifewithoutZeroes\n{\n\tpublic static void main(String args[])\n\t{\n\t\t\n\t\tScanner sc=new Scanner(System.in);\n\n\t\tint a,b,i;\n\t\tint ans,ans1;\n\t\tString s,p,t=\"\",m=\"\",k=\"\",l=\"\";\n\n\t\ta=sc.nextInt();\n\t\tb=sc.nextInt();\n\t\tans=a+b;\n\t\tk=Integer.toString(ans);\n\t\tfor(i=0;i= 0; --i) {\n\t\t\tif (p[i] >= p[i + 1]) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tint j = i + 1;\n\t\t\twhile (j + 1 < p.length && p[j + 1] > p[i]) {\n\t\t\t\tj++;\n\t\t\t}\n\t\t\tint t = p[i];\n\t\t\tp[i] = p[j];\n\t\t\tp[j] = t;\n\t\t\tArrays.sort(p, i + 1, p.length);\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\tstatic int generateCubes(int[] alphabet) {\n\t\tCube[] allcubes = generateCubes();\n\t\tArrays.sort(alphabet);\n\n\t\tHashSet visited = new HashSet();\n\t\tint res = 0;\n\t\tint[] a1 = new int[6];\n\t\tdo {\n\t\t\tboolean ok = true;\n\t\t\tfor (Cube c : allcubes) {\n\t\t\t\tfor (int i = 0; i < 6; i++) {\n\t\t\t\t\ta1[c.a[i]] = alphabet[i];\n\t\t\t\t}\n\t\t\t\tCube c1 = new Cube(a1);\n\t\t\t\tif (visited.contains(c1)) {\n\t\t\t\t\tok = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (ok) {\n\t\t\t\tres++;\n\t\t\t\tvisited.add(new Cube(alphabet.clone()));\n\t\t\t}\n\t\t} while (nextPermutation(alphabet));\n\t\treturn res;\n\t}\n\n\tstatic Cube[] generateCubes() {\n\t\tCube start = new Cube(new int[] { 0, 1, 2, 3, 4, 5 });\n\t\tQueue q = new ArrayDeque();\n\t\tHashSet visited = new HashSet();\n\t\tq.add(start);\n\t\tvisited.add(start);\n\t\twhile (!q.isEmpty()) {\n\t\t\tCube u = q.poll();\n\t\t\tfor (Cube v : new Cube[] { u.rotate1(), u.rotate2(), u.rotate3() }) {\n\t\t\t\tif (!visited.contains(v)) {\n\t\t\t\t\tvisited.add(v);\n\t\t\t\t\tq.add(v);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn (Cube[]) visited.toArray(new Cube[visited.size()]);\n\t}\n\n\tstatic class Cube {\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(a);\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\tCube other = (Cube) obj;\n\t\t\tif (!Arrays.equals(a, other.a))\n\t\t\t\treturn false;\n\t\t\treturn true;\n\t\t}\n\n\t\tint[] a;\n\n\t\tpublic Cube(int[] a) {\n\t\t\tthis.a = a;\n\t\t}\n\n\t\tCube rotate1() {\n\t\t\tint[] a1 = a.clone();\n\t\t\ta1[0] = a[5];\n\t\t\ta1[5] = a[1];\n\t\t\ta1[1] = a[4];\n\t\t\ta1[4] = a[0];\n\t\t\treturn new Cube(a1);\n\t\t}\n\n\t\tCube rotate2() {\n\t\t\tint[] a1 = a.clone();\n\t\t\ta1[0] = a[3];\n\t\t\ta1[3] = a[1];\n\t\t\ta1[1] = a[2];\n\t\t\ta1[2] = a[0];\n\t\t\treturn new Cube(a1);\n\t\t}\n\n\t\tCube rotate3() {\n\t\t\tint[] a1 = a.clone();\n\t\t\ta1[4] = a[3];\n\t\t\ta1[3] = a[5];\n\t\t\ta1[5] = a[2];\n\t\t\ta1[2] = a[4];\n\t\t\treturn new Cube(a1);\n\t\t}\n\n\t}\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tnew A().solve();\n\t\t\tout.close();\n\t\t} catch (Throwable e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(239);\n\t\t}\n\t}\n\n\tstatic BufferedReader br;\n\tstatic StringTokenizer st;\n\tstatic PrintWriter out;\n\n\tstatic String nextToken() 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 int nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tstatic long nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tstatic double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "21ebcccc02a973c00976ce80a097e7b6", "src_uid": "8176c709c774fa87ca0e45a5a502a409", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.lang.reflect.Array;\nimport java.util.*;\n\npublic class Main {\n\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 Task solver = new Task();\n solver.solve(in, out);\n out.close();\n }\n}\n\nclass Task {\n\n // static int MAX = 1000001;\n// List> g = new ArrayList<>();\n// int n;\n// char[] s;\n\n public void solve(Scanner in, PrintWriter out) {\n int t = in.nextInt();\n int l = in.nextInt();\n int r = in.nextInt();\n\n long[] a = new long[r + 1];\n boolean[] prime = new boolean[r + 1];\n Arrays.fill(prime, true);\n prime[0] = prime[1] = false;\n for (int i = 2; i <= r; i++) {\n if (prime[i]) {\n if ((long)i * i <= (long)r) {\n for (long j = (long)i*i; j <= r; j+=i) {\n prime[(int)j] = false;\n }\n }\n }\n }\n\n\n List pr = new ArrayList<>();\n for (int i = 2; i <= r; i++) {\n if (prime[i]) {\n pr.add(i);\n a[i] = (long) i * (i - 1) / 2;\n } else {\n for (Integer p : pr) {\n if (i % p == 0) {\n int p1 = i / p;\n int max = Math.max(p, p1);\n int min = Math.min(p, p1);\n a[i] = a[min] * max + a[max];\n break;\n }\n }\n }\n }\n\n long tt[] = new long[r];\n tt[0] = 1;\n long temp = 1;\n for (int i = 1; i <= r - l; i++) {\n temp *= (long)t;\n temp %= 1000000007;\n tt[i] = temp;\n }\n\n long res = 0;\n for (int i = 0; i <= r - l; i++) {\n res += (tt[i] * (a[i + l] % 1000000007)) % 1000000007;\n res %= 1000000007;\n }\n\n System.out.println(res);\n }\n\n\n}\n\nclass Utils {\n\n public static int binarySearch(int[] a, int key) {\n int s = 0;\n int f = a.length;\n while (f > s) {\n int mid = (s + f) / 2;\n if (a[mid] > key) {\n f = mid - 1;\n } else if (a[mid] <= key) {\n s = mid + 1;\n }\n }\n return -1;\n }\n\n public static long gcd(long a, long b) {\n return b != 0 ? gcd(b, a % b) : a;\n }\n\n public static long lcm(long a, long b) {\n return a / gcd(a, b) * b;\n }\n\n static List prime(int number) {\n List a = new ArrayList<>();\n for (int i = 2; i * i <= number; i++) {\n if (number % i == 0) {\n a.add(i);\n number /= i;\n i = 1;\n }\n }\n a.add(number);\n return a;\n }\n}\n\nclass Pair {\n public T a;\n public U b;\n\n public Pair(T a, U b) {\n this.a = a;\n this.b = b;\n }\n\n @Override\n public boolean equals(Object o) {\n if (this == o) return true;\n if (o == null || getClass() != o.getClass()) return false;\n\n Pair pair = (Pair) o;\n\n if (a != null ? !a.equals(pair.a) : pair.a != null) return false;\n return b != null ? b.equals(pair.b) : pair.b == null;\n }\n\n @Override\n public int hashCode() {\n int result = a != null ? a.hashCode() : 0;\n result = 31 * result + (b != null ? b.hashCode() : 0);\n return result;\n }\n}\n\n\nclass Vect {\n public int a;\n public int b;\n\n public Vect(int a, int b) {\n this.a = a;\n this.b = b;\n }\n\n @Override\n public boolean equals(Object o) {\n if (this == o) return true;\n if (o == null || getClass() != o.getClass()) return false;\n\n Vect vect = (Vect) o;\n\n if (a != vect.a) return false;\n return b == vect.b;\n }\n\n @Override\n public int hashCode() {\n int result = a;\n result = 31 * result + b;\n return result;\n }\n}\n\nclass Tri {\n public int a;\n public int b;\n public int c;\n\n public Tri(int a, int b, int c) {\n this.a = a;\n this.b = b;\n this.c = c;\n }\n\n @Override\n public boolean equals(Object o) {\n if (this == o) return true;\n if (o == null || getClass() != o.getClass()) return false;\n\n Tri tri = (Tri) o;\n\n if (a != tri.a) return false;\n return b == tri.b;\n }\n\n @Override\n public int hashCode() {\n int result = a;\n result = 31 * result + b;\n return result;\n }\n}\n\nclass Triple {\n public T a;\n public U b;\n public P c;\n\n public Triple(T a, U b, P c) {\n this.a = a;\n this.b = b;\n this.c = c;\n }\n\n @Override\n public boolean equals(Object o) {\n if (this == o) return true;\n if (o == null || getClass() != o.getClass()) return false;\n\n Triple triple = (Triple) o;\n\n if (a != null ? !a.equals(triple.a) : triple.a != null) return false;\n return b != null ? b.equals(triple.b) : triple.b == null;\n }\n\n @Override\n public int hashCode() {\n int result = a != null ? a.hashCode() : 0;\n result = 31 * result + (b != null ? b.hashCode() : 0);\n return result;\n }\n}\n\n\nclass Scanner {\n BufferedReader in;\n StringTokenizer tok;\n\n public Scanner(InputStream in) {\n this.in = new BufferedReader(new InputStreamReader(in));\n tok = new StringTokenizer(\"\");\n }\n\n private String tryReadNextLine() {\n try {\n return in.readLine();\n } catch (Exception e) {\n throw new InputMismatchException();\n }\n }\n\n public String nextToken() {\n while (!tok.hasMoreTokens()) {\n tok = new StringTokenizer(next());\n }\n return tok.nextToken();\n }\n\n public String next() {\n String newLine = tryReadNextLine();\n if (newLine == null)\n throw new InputMismatchException();\n return newLine;\n }\n\n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n public long nextLong() {\n return Long.parseLong(nextToken());\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "math", "dp", "greedy", "number theory"], "code_uid": "823fdd6e279520128bc90a932064d2c2", "src_uid": "c9d45dac4a22f8f452d98d05eca2e79b", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\nimport java.lang.reflect.*;\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\tTask solver = new TaskC();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\ninterface Task {\n\tpublic void solve(int testNumber, InputReader in, OutputWriter out);\n}\n\nclass TaskA implements Task {\n\n\tpublic void solve(int testNumber, InputReader in, OutputWriter out) {\n\t\tint n=in.readInt();\n\t\twhile (n-->0) {\n\t\t\tint a=in.readInt(), b=in.readInt();\n\t\t\tout.printLine(gcd(a, b));\n\t\t}\n\t}\n\t\n\tint gcd(int a, int b) {\n\t\treturn b==0?0:a/b+gcd(b, a%b);\n\t}\n\n}\n\nclass TaskB implements Task {\n\t\n\tboolean[] vis;\n\tint[] arr;\n\tList div;\n\tboolean[] sieve;\n\t\n\tpublic void solve(int testNumber, InputReader in, OutputWriter out) {\n\t\tint n=in.readInt(), m=in.readInt();\n\t\tarr=new int[n+1];\n\t\tvis=new boolean[n+1];\n\t\tsieve=IntegerUtils.generatePrimalityTable(n+1);\n\t\twhile (m-->0) {\n\t\t\tchar c=in.readCharacter();\n\t\t\tint x=in.readInt();\n\t\t\tdiv=IntegerUtils.getDivisors(x);\n\t\t\tif (c=='+') {\n\t\t\t\tif (vis[x]) {\n\t\t\t\t\tout.printLine(\"Already on\");\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tboolean val=true;\n\t\t\t\tfor (long y: div) if (sieve[(int)y] && arr[(int)y]>0) {\n\t\t\t\t\tval=false;\n\t\t\t\t\tout.printLine(\"Conflict with\", arr[(int)y]);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (!val) continue;\n\t\t\t\tout.printLine(\"Success\");\n\t\t\t\tvis[x]=true;\n\t\t\t\tfor (long y: div) if (sieve[(int)y]) arr[(int)y]=x;\n\t\t\t}\n\t\t\telse if (vis[x]) {\n\t\t\t\tout.printLine(\"Success\");\n\t\t\t\tvis[x]=false;\n\t\t\t\tfor (long y: div) arr[(int)y]=0;\n\t\t\t}\n\t\t\telse out.printLine(\"Already off\");\n\t\t}\n\t}\n\n}\n\nclass TaskC implements Task {\n\n\tpublic void solve(int testNumber, InputReader in, OutputWriter out) {\n\t\tint a=in.readInt(), b=in.readInt();\n\t\tlong l=IntegerUtils.lcm(a, b);\n\t\tif (Math.abs(l/a-l/b)<=1) out.printLine(\"Equal\");\n\t\telse out.printLine(a collection) {\n\t\tboolean first = true;\n\t\tfor (int value : collection) {\n\t\t\tif (first)\n\t\t\t\tfirst = false;\n\t\t\telse\n\t\t\t\twriter.print(' ');\n\t\t\twriter.print(value);\n\t\t}\n\t}\n\n\tpublic void printLine(int[] array) {\n\t\tprint(array);\n\t\twriter.println();\n\t}\n\n\tpublic void printLine(long[] array) {\n\t\tprint(array);\n\t\twriter.println();\n\t}\n\n\tpublic void printLine(Collection collection) {\n\t\tprint(collection);\n\t\twriter.println();\n\t}\n\n\tpublic void printLine() {\n\t\twriter.println();\n\t}\n\n\tpublic void printLine(Object... objects) {\n\t\tprint(objects);\n\t\twriter.println();\n\t}\n\n\tpublic void print(char i) {\n\t\twriter.print(i);\n\t}\n\n\tpublic void printLine(char i) {\n\t\twriter.println(i);\n\t}\n\n\tpublic void printLine(char[] array) {\n\t\twriter.println(array);\n\t}\n\n\tpublic void printFormat(String format, Object... objects) {\n\t\twriter.printf(format, objects);\n\t}\n\n\tpublic void close() {\n\t\twriter.close();\n\t}\n\n\tpublic void flush() {\n\t\twriter.flush();\n\t}\n\n\tpublic void print(long i) {\n\t\twriter.print(i);\n\t}\n\n\tpublic void printLine(long i) {\n\t\twriter.println(i);\n\t}\n\n\tpublic void print(int i) {\n\t\twriter.print(i);\n\t}\n\n\tpublic void printLine(int i) {\n\t\twriter.println(i);\n\t}\n}\n\nclass InputReader {\n\tprivate boolean finished = false;\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 peek() {\n\t\tif (numChars == -1)\n\t\t\treturn -1;\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\treturn -1;\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 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\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\n\tprivate String readLine0() {\n\t\tStringBuilder buf = new StringBuilder();\n\t\tint c = read();\n\t\twhile (c != '\\n' && c != -1) {\n\t\t\tif (c != '\\r')\n\t\t\t\tbuf.appendCodePoint(c);\n\t\t\tc = read();\n\t\t}\n\t\treturn buf.toString();\n\t}\n\n\tpublic String readLine() {\n\t\tString s = readLine0();\n\t\twhile (s.trim().length() == 0)\n\t\t\ts = readLine0();\n\t\treturn s;\n\t}\n\n\tpublic String readLine(boolean ignoreEmptyLines) {\n\t\tif (ignoreEmptyLines)\n\t\t\treturn readLine();\n\t\telse\n\t\t\treturn readLine0();\n\t}\n\n\tpublic BigInteger readBigInteger() {\n\t\ttry {\n\t\t\treturn new BigInteger(readString());\n\t\t} catch (NumberFormatException e) {\n\t\t\tthrow new InputMismatchException();\n\t\t}\n\t}\n\n\tpublic char readCharacter() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\treturn (char) c;\n\t}\n\n\tpublic double readDouble() {\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\tdouble res = 0;\n\t\twhile (!isSpaceChar(c) && c != '.') {\n\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\treturn res * Math.pow(10, readInt());\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}\n\t\tif (c == '.') {\n\t\t\tc = read();\n\t\t\tdouble m = 1;\n\t\t\twhile (!isSpaceChar(c)) {\n\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\treturn res * Math.pow(10, readInt());\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tm /= 10;\n\t\t\t\tres += (c - '0') * m;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t}\n\t\treturn res * sgn;\n\t}\n\n\tpublic boolean isExhausted() {\n\t\tint value;\n\t\twhile (isSpaceChar(value = peek()) && value != -1)\n\t\t\tread();\n\t\treturn value == -1;\n\t}\n\n\tpublic String next() {\n\t\treturn readString();\n\t}\n\n\tpublic SpaceCharFilter getFilter() {\n\t\treturn filter;\n\t}\n\n\tpublic void setFilter(SpaceCharFilter filter) {\n\t\tthis.filter = filter;\n\t}\n\n\tpublic interface SpaceCharFilter {\n\t\tpublic boolean isSpaceChar(int ch);\n\t}\n}\n\nclass IOUtils {\n\tpublic static Pair readIntPair(InputReader in) {\n\t\tint first = in.readInt();\n\t\tint second = in.readInt();\n\t\treturn Pair.makePair(first, second);\n\t}\n\n\tpublic static Pair readLongPair(InputReader in) {\n\t\tlong first = in.readLong();\n\t\tlong second = in.readLong();\n\t\treturn Pair.makePair(first, second);\n\t}\n\n\tpublic static int[] readIntArray(InputReader in, int size) {\n\t\tint[] array = new int[size];\n\t\tfor (int i = 0; i < size; i++)\n\t\t\tarray[i] = in.readInt();\n\t\treturn array;\n\t}\n\n\tpublic static long[] readLongArray(InputReader in, int size) {\n\t\tlong[] array = new long[size];\n\t\tfor (int i = 0; i < size; i++)\n\t\t\tarray[i] = in.readLong();\n\t\treturn array;\n\t}\n\n\tpublic static double[] readDoubleArray(InputReader in, int size) {\n\t\tdouble[] array = new double[size];\n\t\tfor (int i = 0; i < size; i++)\n\t\t\tarray[i] = in.readDouble();\n\t\treturn array;\n\t}\n\n\tpublic static String[] readStringArray(InputReader in, int size) {\n\t\tString[] array = new String[size];\n\t\tfor (int i = 0; i < size; i++)\n\t\t\tarray[i] = in.readString();\n\t\treturn array;\n\t}\n\n\tpublic static char[] readCharArray(InputReader in, int size) {\n\t\tchar[] array = new char[size];\n\t\tfor (int i = 0; i < size; i++)\n\t\t\tarray[i] = in.readCharacter();\n\t\treturn array;\n\t}\n\n\tpublic static Pair[] readIntPairArray(InputReader in,\n\t\t\tint size) {\n\t\t@SuppressWarnings({ \"unchecked\" })\n\t\tPair[] result = new Pair[size];\n\t\tfor (int i = 0; i < size; i++)\n\t\t\tresult[i] = readIntPair(in);\n\t\treturn result;\n\t}\n\n\tpublic static Pair[] readLongPairArray(InputReader in, int size) {\n\t\t@SuppressWarnings({ \"unchecked\" })\n\t\tPair[] result = new Pair[size];\n\t\tfor (int i = 0; i < size; i++)\n\t\t\tresult[i] = readLongPair(in);\n\t\treturn result;\n\t}\n\n\tpublic static void readIntArrays(InputReader in, int[]... arrays) {\n\t\tfor (int i = 0; i < arrays[0].length; i++) {\n\t\t\tfor (int j = 0; j < arrays.length; j++)\n\t\t\t\tarrays[j][i] = in.readInt();\n\t\t}\n\t}\n\n\tpublic static void readLongArrays(InputReader in, long[]... arrays) {\n\t\tfor (int i = 0; i < arrays[0].length; i++) {\n\t\t\tfor (int j = 0; j < arrays.length; j++)\n\t\t\t\tarrays[j][i] = in.readLong();\n\t\t}\n\t}\n\n\tpublic static void readDoubleArrays(InputReader in, double[]... arrays) {\n\t\tfor (int i = 0; i < arrays[0].length; i++) {\n\t\t\tfor (int j = 0; j < arrays.length; j++)\n\t\t\t\tarrays[j][i] = in.readDouble();\n\t\t}\n\t}\n\n\tpublic static char[][] readTable(InputReader in, int rowCount,\n\t\t\tint columnCount) {\n\t\tchar[][] table = new char[rowCount][];\n\t\tfor (int i = 0; i < rowCount; i++)\n\t\t\ttable[i] = readCharArray(in, columnCount);\n\t\treturn table;\n\t}\n\n\tpublic static int[][] readIntTable(InputReader in, int rowCount,\n\t\t\tint columnCount) {\n\t\tint[][] table = new int[rowCount][];\n\t\tfor (int i = 0; i < rowCount; i++)\n\t\t\ttable[i] = readIntArray(in, columnCount);\n\t\treturn table;\n\t}\n\n\tpublic static double[][] readDoubleTable(InputReader in, int rowCount,\n\t\t\tint columnCount) {\n\t\tdouble[][] table = new double[rowCount][];\n\t\tfor (int i = 0; i < rowCount; i++)\n\t\t\ttable[i] = readDoubleArray(in, columnCount);\n\t\treturn table;\n\t}\n\n\tpublic static long[][] readLongTable(InputReader in, int rowCount,\n\t\t\tint columnCount) {\n\t\tlong[][] table = new long[rowCount][];\n\t\tfor (int i = 0; i < rowCount; i++)\n\t\t\ttable[i] = readLongArray(in, columnCount);\n\t\treturn table;\n\t}\n\n\tpublic static String[][] readStringTable(InputReader in, int rowCount,\n\t\t\tint columnCount) {\n\t\tString[][] table = new String[rowCount][];\n\t\tfor (int i = 0; i < rowCount; i++)\n\t\t\ttable[i] = readStringArray(in, columnCount);\n\t\treturn table;\n\t}\n\n\tpublic static String readText(InputReader in) {\n\t\tStringBuilder result = new StringBuilder();\n\t\twhile (true) {\n\t\t\tint character = in.read();\n\t\t\tif (character == '\\r')\n\t\t\t\tcontinue;\n\t\t\tif (character == -1)\n\t\t\t\tbreak;\n\t\t\tresult.append((char) character);\n\t\t}\n\t\treturn result.toString();\n\t}\n\n\tpublic static void readStringArrays(InputReader in, String[]... arrays) {\n\t\tfor (int i = 0; i < arrays[0].length; i++) {\n\t\t\tfor (int j = 0; j < arrays.length; j++)\n\t\t\t\tarrays[j][i] = in.readString();\n\t\t}\n\t}\n\n\tpublic static void printTable(OutputWriter out, char[][] table) {\n\t\tfor (char[] row : table)\n\t\t\tout.printLine(new String(row));\n\t}\n}\n\nclass ArrayUtils {\n\tprivate static int[] tempInt = new int[0];\n\tprivate static long[] tempLong = new long[0];\n\n\tpublic static Integer[] generateOrder(int size) {\n\t\tInteger[] order = new Integer[size];\n\t\tfor (int i = 0; i < size; i++)\n\t\t\torder[i] = i;\n\t\treturn order;\n\t}\n\n\tpublic static void fill(short[][] array, short value) {\n\t\tfor (short[] 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\tArrays.fill(row, value);\n\t}\n\n\tpublic static void fill(double[][] array, double value) {\n\t\tfor (double[] row : array)\n\t\t\tArrays.fill(row, value);\n\t}\n\n\tpublic static void fill(double[][][] array, double value) {\n\t\tfor (double[][] row : array)\n\t\t\tfill(row, value);\n\t}\n\n\tpublic static void fill(double[][][][] array, double value) {\n\t\tfor (double[][][] row : array)\n\t\t\tfill(row, value);\n\t}\n\n\tpublic static void fill(double[][][][][] array, double value) {\n\t\tfor (double[][][][] row : array)\n\t\t\tfill(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\tpublic static void fill(long[][][][] array, long value) {\n\t\tfor (long[][][] row : array)\n\t\t\tfill(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\tpublic static void fillColumn(long[][] array, int index, long value) {\n\t\tfor (long[] row : array)\n\t\t\trow[index] = value;\n\t}\n\n\tpublic static void fillColumn(int[][] array, int index, int value) {\n\t\tfor (int[] row : array)\n\t\t\trow[index] = value;\n\t}\n\n\tpublic static void fill(int[][] array, int value) {\n\t\tfor (int[] row : array)\n\t\t\tArrays.fill(row, value);\n\t}\n\n\tpublic static void fill(boolean[][] array, boolean value) {\n\t\tfor (boolean[] row : array)\n\t\t\tArrays.fill(row, value);\n\t}\n\n\tpublic static void fill(boolean[][][] array, boolean value) {\n\t\tfor (boolean[][] row : array)\n\t\t\tfill(row, value);\n\t}\n\n\tpublic static long sumArray(int[] array) {\n\t\tlong result = 0;\n\t\tfor (int element : array)\n\t\t\tresult += element;\n\t\treturn result;\n\t}\n\n\tpublic static int[] range(int from, int to) {\n\t\tint[] result = new int[Math.max(from, to) - Math.min(from, to) + 1];\n\t\tint index = 0;\n\t\tif (to > from) {\n\t\t\tfor (int i = from; i <= to; i++)\n\t\t\t\tresult[index++] = i;\n\t\t} else {\n\t\t\tfor (int i = from; i >= to; i--)\n\t\t\t\tresult[index++] = i;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static void fill(int[][][] array, int value) {\n\t\tfor (int[][] subArray : array)\n\t\t\tfill(subArray, value);\n\t}\n\n\tpublic static void fill(short[][][] array, short value) {\n\t\tfor (short[][] subArray : array)\n\t\t\tfill(subArray, value);\n\t}\n\n\tpublic static void fill(int[][][][] array, int value) {\n\t\tfor (int[][][] subArray : array)\n\t\t\tfill(subArray, value);\n\t}\n\n\tpublic static void fill(short[][][][] array, short value) {\n\t\tfor (short[][][] subArray : array)\n\t\t\tfill(subArray, value);\n\t}\n\n\tpublic static void fill(int[][][][][] array, int value) {\n\t\tfor (int[][][][] subArray : array)\n\t\t\tfill(subArray, value);\n\t}\n\n\tpublic static void fill(short[][][][][] array, short value) {\n\t\tfor (short[][][][] subArray : array)\n\t\t\tfill(subArray, value);\n\t}\n\n\tpublic static void fill(int[][][][][][] array, int value) {\n\t\tfor (int[][][][][] subArray : array)\n\t\t\tfill(subArray, value);\n\t}\n\n\tpublic static void fill(short[][][][][][] array, short value) {\n\t\tfor (short[][][][][] subArray : array)\n\t\t\tfill(subArray, value);\n\t}\n\n\tpublic static void fill(int[][][][][][][] array, int value) {\n\t\tfor (int[][][][][][] subArray : array)\n\t\t\tfill(subArray, value);\n\t}\n\n\tpublic static void fill(short[][][][][][][] array, short value) {\n\t\tfor (short[][][][][][] subArray : array)\n\t\t\tfill(subArray, value);\n\t}\n\n\tpublic static Integer[] order(int size, Comparator comparator) {\n\t\tInteger[] order = generateOrder(size);\n\t\tArrays.sort(order, comparator);\n\t\treturn order;\n\t}\n\n\tpublic static void fill(T[][] array, T value) {\n\t\tfor (T[] row : array)\n\t\t\tArrays.fill(row, value);\n\t}\n\n\tpublic static void fill(char[][] array, char value) {\n\t\tfor (char[] row : array)\n\t\t\tArrays.fill(row, value);\n\t}\n\n\tpublic static void fill(byte[][] array, byte value) {\n\t\tfor (byte[] row : array)\n\t\t\tArrays.fill(row, value);\n\t}\n\n\tpublic static void fill(byte[][][] array, byte value) {\n\t\tfor (byte[][] row : array)\n\t\t\tfill(row, value);\n\t}\n\n\tpublic static void fill(byte[][][][] array, byte value) {\n\t\tfor (byte[][][] row : array)\n\t\t\tfill(row, value);\n\t}\n\n\tpublic static long multiply(int[] first, int[] second) {\n\t\tlong result = 0;\n\t\tfor (int i = 0; i < first.length; i++)\n\t\t\tresult += (long) first[i] * second[i];\n\t\treturn result;\n\t}\n\n\tpublic static int[] createOrder(int size) {\n\t\tint[] order = new int[size];\n\t\tfor (int i = 0; i < size; i++)\n\t\t\torder[i] = i;\n\t\treturn order;\n\t}\n\n\tpublic static int[] sort(int[] array, IntComparator comparator) {\n\t\treturn sort(array, 0, array.length, comparator);\n\t}\n\n\tpublic static int[] sort(int[] array, int from, int to,\n\t\t\tIntComparator comparator) {\n\t\tInteger[] intArray = new Integer[to - from];\n\t\tfor (int i = from; i < to; i++)\n\t\t\tintArray[i - from] = array[i];\n\t\tArrays.sort(intArray, comparator);\n\t\tfor (int i=from; i= size)\n\t\t\treturn;\n\t\tsize = Math.max(size, tempInt.length << 1);\n\t\ttempInt = new int[size];\n\t}\n\n\tprivate static void ensureCapacityLong(int size) {\n\t\tif (tempLong.length >= size)\n\t\t\treturn;\n\t\tsize = Math.max(size, tempLong.length << 1);\n\t\ttempLong = new long[size];\n\t}\n\n\tprivate static void sortImpl(int[] array, int from, int to, int[] temp,\n\t\t\tint fromTemp, int toTemp, IntComparator comparator) {\n\t\tif (to - from <= 1)\n\t\t\treturn;\n\t\tint middle = (to - from) >> 1;\n\t\tint tempMiddle = fromTemp + middle;\n\t\tsortImpl(temp, fromTemp, tempMiddle, array, from, from + middle,\n\t\t\t\tcomparator);\n\t\tsortImpl(temp, tempMiddle, toTemp, array, from + middle, to, comparator);\n\t\tint index = from;\n\t\tint index1 = fromTemp;\n\t\tint index2 = tempMiddle;\n\t\twhile (index1 < tempMiddle && index2 < toTemp) {\n\t\t\tif (comparator.compare(temp[index1], temp[index2]) <= 0)\n\t\t\t\tarray[index++] = temp[index1++];\n\t\t\telse\n\t\t\t\tarray[index++] = temp[index2++];\n\t\t}\n\t\tif (index1 != tempMiddle)\n\t\t\tSystem.arraycopy(temp, index1, array, index, tempMiddle - index1);\n\t\tif (index2 != toTemp)\n\t\t\tSystem.arraycopy(temp, index2, array, index, toTemp - index2);\n\t}\n\n\tpublic static int[] order(final int[] array) {\n\t\treturn sort(createOrder(array.length), new IntComparator() {\n\t\t\tpublic int compare(Integer first, Integer second) {\n\t\t\t\tif (array[first] < array[second])\n\t\t\t\t\treturn -1;\n\t\t\t\tif (array[first] > array[second])\n\t\t\t\t\treturn 1;\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t});\n\t}\n\n\tpublic static int[] order(final long[] array) {\n\t\treturn sort(createOrder(array.length), new IntComparator() {\n\t\t\tpublic int compare(Integer first, Integer second) {\n\t\t\t\tif (array[first] < array[second])\n\t\t\t\t\treturn -1;\n\t\t\t\tif (array[first] > array[second])\n\t\t\t\t\treturn 1;\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t});\n\t}\n\n\tpublic static int[] unique(int[] array) {\n\t\treturn unique(array, 0, array.length);\n\t}\n\n\tpublic static int[] unique(int[] array, int from, int to) {\n\t\tif (from == to)\n\t\t\treturn new int[0];\n\t\tint count = 1;\n\t\tfor (int i = from + 1; i < to; i++) {\n\t\t\tif (array[i] != array[i - 1])\n\t\t\t\tcount++;\n\t\t}\n\t\tint[] result = new int[count];\n\t\tresult[0] = array[from];\n\t\tint index = 1;\n\t\tfor (int i = from + 1; i < to; i++) {\n\t\t\tif (array[i] != array[i - 1])\n\t\t\t\tresult[index++] = array[i];\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static char[] unique(char[] array) {\n\t\treturn unique(array, 0, array.length);\n\t}\n\n\tpublic static char[] unique(char[] array, int from, int to) {\n\t\tif (from == to)\n\t\t\treturn new char[0];\n\t\tint count = 1;\n\t\tfor (int i = from + 1; i < to; i++) {\n\t\t\tif (array[i] != array[i - 1])\n\t\t\t\tcount++;\n\t\t}\n\t\tchar[] result = new char[count];\n\t\tresult[0] = array[from];\n\t\tint index = 1;\n\t\tfor (int i = from + 1; i < to; i++) {\n\t\t\tif (array[i] != array[i - 1])\n\t\t\t\tresult[index++] = array[i];\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int maxElement(int[] array) {\n\t\treturn maxElement(array, 0, array.length);\n\t}\n\n\tpublic static int maxElement(int[] array, int from, int to) {\n\t\tint result = Integer.MIN_VALUE;\n\t\tfor (int i = from; i < to; i++)\n\t\t\tresult = Math.max(result, array[i]);\n\t\treturn result;\n\t}\n\n\tpublic static int[] order(final double[] array) {\n\t\treturn sort(createOrder(array.length), new IntComparator() {\n\t\t\tpublic int compare(Integer first, Integer second) {\n\t\t\t\treturn Double.compare(array[first], array[second]);\n\t\t\t}\n\t\t});\n\t}\n\n\tpublic static int[] reversePermutation(int[] permutation) {\n\t\tint[] result = new int[permutation.length];\n\t\tfor (int i = 0; i < permutation.length; i++)\n\t\t\tresult[permutation[i]] = i;\n\t\treturn result;\n\t}\n\n\tpublic static void reverse(int[] array) {\n\t\tfor (int i = 0, j = array.length - 1; i < j; i++, j--) {\n\t\t\tint temp = array[i];\n\t\t\tarray[i] = array[j];\n\t\t\tarray[j] = temp;\n\t\t}\n\t}\n\n\tpublic static void reverse(char[] array) {\n\t\tfor (int i = 0, j = array.length - 1; i < j; i++, j--) {\n\t\t\tchar temp = array[i];\n\t\t\tarray[i] = array[j];\n\t\t\tarray[j] = temp;\n\t\t}\n\t}\n\n\tprivate static long maxElement(long[] array, int from, int to) {\n\t\tlong result = Long.MIN_VALUE;\n\t\tfor (int i = from; i < to; i++)\n\t\t\tresult = Math.max(result, array[i]);\n\t\treturn result;\n\t}\n\n\tpublic static int minPosition(int[] array) {\n\t\treturn minPosition(array, 0, array.length);\n\t}\n\n\tpublic static int maxPosition(int[] array) {\n\t\treturn maxPosition(array, 0, array.length);\n\t}\n\n\tpublic static int minPosition(int[] array, int from, int to) {\n\t\tif (from >= to)\n\t\t\treturn -1;\n\t\tint min = array[from];\n\t\tint result = from;\n\t\tfor (int i = from + 1; i < to; i++) {\n\t\t\tif (array[i] < min) {\n\t\t\t\tmin = array[i];\n\t\t\t\tresult = i;\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int maxPosition(int[] array, int from, int to) {\n\t\tif (from >= to)\n\t\t\treturn -1;\n\t\tint max = array[from];\n\t\tint result = from;\n\t\tfor (int i = from + 1; i < to; i++) {\n\t\t\tif (array[i] > max) {\n\t\t\t\tmax = array[i];\n\t\t\t\tresult = i;\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int[] multiplyPermutations(int[] first, int[] second) {\n\t\tint count = first.length;\n\t\tint[] result = new int[count];\n\t\tfor (int i = 0; i < count; i++) {\n\t\t\tresult[i] = first[second[i]];\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int[] compress(int[]... arrays) {\n\t\tint totalLength = 0;\n\t\tfor (int[] array : arrays)\n\t\t\ttotalLength += array.length;\n\t\tint[] all = new int[totalLength];\n\t\tint delta = 0;\n\t\tfor (int[] array : arrays) {\n\t\t\tSystem.arraycopy(array, 0, all, delta, array.length);\n\t\t\tdelta += array.length;\n\t\t}\n\t\tsort(all, IntComparator.DEFAULT);\n\t\tall = unique(all);\n\t\tfor (int[] array : arrays) {\n\t\t\tfor (int i = 0; i < array.length; i++)\n\t\t\t\tarray[i] = Arrays.binarySearch(all, array[i]);\n\t\t}\n\t\treturn all;\n\t}\n\n\tpublic static int minElement(int[] array) {\n\t\treturn array[minPosition(array)];\n\t}\n\n\tpublic static long[] partialSums(int[] array) {\n\t\tlong[] result = new long[array.length + 1];\n\t\tfor (int i = 0; i < array.length; i++)\n\t\t\tresult[i + 1] = result[i] + array[i];\n\t\treturn result;\n\t}\n\n\tpublic static void orderBy(int[] base, int[]... arrays) {\n\t\tint[] order = ArrayUtils.order(base);\n\t\torder(order, base);\n\t\tfor (int[] array : arrays)\n\t\t\torder(order, array);\n\t}\n\n\tpublic static void orderBy(long[] base, long[]... arrays) {\n\t\tint[] order = ArrayUtils.order(base);\n\t\torder(order, base);\n\t\tfor (long[] array : arrays)\n\t\t\torder(order, array);\n\t}\n\n\tpublic static void order(int[] order, int[] array) {\n\t\tensureCapacityInt(order.length);\n\t\tfor (int i = 0; i < order.length; i++)\n\t\t\ttempInt[i] = array[order[i]];\n\t\tSystem.arraycopy(tempInt, 0, array, 0, array.length);\n\t}\n\n\tpublic static void order(int[] order, long[] array) {\n\t\tensureCapacityLong(order.length);\n\t\tfor (int i = 0; i < order.length; i++)\n\t\t\ttempLong[i] = array[order[i]];\n\t\tSystem.arraycopy(tempLong, 0, array, 0, array.length);\n\t}\n\n\tpublic static long[] asLong(int[] array) {\n\t\tlong[] result = new long[array.length];\n\t\tfor (int i = 0; i < array.length; i++)\n\t\t\tresult[i] = array[i];\n\t\treturn result;\n\t}\n\n\tpublic static int count(int[] array, int value) {\n\t\tint result = 0;\n\t\tfor (int i : array) {\n\t\t\tif (i == value)\n\t\t\t\tresult++;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int count(char[] array, char value) {\n\t\tint result = 0;\n\t\tfor (char i : array) {\n\t\t\tif (i == value)\n\t\t\t\tresult++;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int count(boolean[] array, boolean value) {\n\t\tint result = 0;\n\t\tfor (boolean i : array) {\n\t\t\tif (i == value)\n\t\t\t\tresult++;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int[] merge(int[] first, int[] second) {\n\t\tint[] result = new int[first.length + second.length];\n\t\tint firstIndex = 0;\n\t\tint secondIndex = 0;\n\t\tint index = 0;\n\t\twhile (firstIndex < first.length && secondIndex < second.length) {\n\t\t\tif (first[firstIndex] < second[secondIndex])\n\t\t\t\tresult[index++] = first[firstIndex++];\n\t\t\telse\n\t\t\t\tresult[index++] = second[secondIndex++];\n\t\t}\n\t\tSystem.arraycopy(first, firstIndex, result, index, first.length\n\t\t\t\t- firstIndex);\n\t\tSystem.arraycopy(second, secondIndex, result, index, second.length\n\t\t\t\t- secondIndex);\n\t\treturn result;\n\t}\n\n\tpublic static boolean nextPermutation(int[] array) {\n\t\treturn nextPermutation(array, IntComparator.DEFAULT);\n\t}\n\n\tprivate static boolean nextPermutation(int[] array, IntComparator comparator) {\n\t\tint size = array.length;\n\t\tint last = array[size - 1];\n\t\tfor (int i = size - 2; i >= 0; i--) {\n\t\t\tint current = array[i];\n\t\t\tif (comparator.compare(last, current) > 0) {\n\t\t\t\tfor (int j = size - 1; j > i; j--) {\n\t\t\t\t\tif (comparator.compare(array[j], current) > 0) {\n\t\t\t\t\t\tswap(array, i, j);\n\t\t\t\t\t\tinPlaceReverse(array, i + 1, size);\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tlast = current;\n\t\t}\n\t\treturn false;\n\t}\n\n\tprivate static void inPlaceReverse(int[] array, int first, int second) {\n\t\tfor (int i = first, j = second - 1; i < j; i++, j--)\n\t\t\tswap(array, i, j);\n\t}\n\n\tprivate static void swap(int[] array, int first, int second) {\n\t\tif (first == second)\n\t\t\treturn;\n\t\tint temp = array[first];\n\t\tarray[first] = array[second];\n\t\tarray[second] = temp;\n\t}\n\n\tpublic static void reverse(V[] array) {\n\t\tfor (int i = 0, j = array.length - 1; i < j; i++, j--) {\n\t\t\tV temp = array[i];\n\t\t\tarray[i] = array[j];\n\t\t\tarray[j] = temp;\n\t\t}\n\t}\n\n\tpublic static IntComparator compareBy(final int[]... arrays) {\n\t\treturn new IntComparator() {\n\t\t\tpublic int compare(Integer first, Integer second) {\n\t\t\t\tfor (int[] array : arrays) {\n\t\t\t\t\tif (array[first] != array[second])\n\t\t\t\t\t\treturn Integer.compare(array[first], array[second]);\n\t\t\t\t}\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t};\n\t}\n\n\tpublic static long minElement(long[] array) {\n\t\treturn array[minPosition(array)];\n\t}\n\n\tpublic static long maxElement(long[] array) {\n\t\treturn array[maxPosition(array)];\n\t}\n\n\tpublic static int minPosition(long[] array) {\n\t\treturn minPosition(array, 0, array.length);\n\t}\n\n\tpublic static int maxPosition(long[] array) {\n\t\treturn maxPosition(array, 0, array.length);\n\t}\n\n\tpublic static int minPosition(long[] array, int from, int to) {\n\t\tif (from >= to)\n\t\t\treturn -1;\n\t\tlong min = array[from];\n\t\tint result = from;\n\t\tfor (int i = from + 1; i < to; i++) {\n\t\t\tif (array[i] < min) {\n\t\t\t\tmin = array[i];\n\t\t\t\tresult = i;\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int maxPosition(long[] array, int from, int to) {\n\t\tif (from >= to)\n\t\t\treturn -1;\n\t\tlong max = array[from];\n\t\tint result = from;\n\t\tfor (int i = from + 1; i < to; i++) {\n\t\t\tif (array[i] > max) {\n\t\t\t\tmax = array[i];\n\t\t\t\tresult = i;\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int[] createArray(int count, int value) {\n\t\tint[] array = new int[count];\n\t\tArrays.fill(array, value);\n\t\treturn array;\n\t}\n\n\tpublic static long[] createArray(int count, long value) {\n\t\tlong[] array = new long[count];\n\t\tArrays.fill(array, value);\n\t\treturn array;\n\t}\n\n\tpublic static double[] createArray(int count, double value) {\n\t\tdouble[] array = new double[count];\n\t\tArrays.fill(array, value);\n\t\treturn array;\n\t}\n\n\tpublic static boolean[] createArray(int count, boolean value) {\n\t\tboolean[] array = new boolean[count];\n\t\tArrays.fill(array, value);\n\t\treturn array;\n\t}\n\n\tpublic static char[] createArray(int count, char value) {\n\t\tchar[] array = new char[count];\n\t\tArrays.fill(array, value);\n\t\treturn array;\n\t}\n\n\tpublic static T[] createArray(int count, T value) {\n\t\t@SuppressWarnings(\"unchecked\")\n\t\tT[] array = (T[]) Array.newInstance(value.getClass(), count);\n\t\tArrays.fill(array, value);\n\t\treturn array;\n\t}\n}\n\nclass Graph {\n\tpublic static final int REMOVED_BIT = 0;\n\n\tprotected int vertexCount;\n\tprotected int edgeCount;\n\n\tprivate int[] firstOutbound;\n\tprivate int[] firstInbound;\n\n\tprivate Edge[] edges;\n\tprivate int[] nextInbound;\n\tprivate int[] nextOutbound;\n\tprivate int[] from;\n\tprivate int[] to;\n\tprivate long[] weight;\n\tprivate long[] capacity;\n\tprivate int[] reverseEdge;\n\tprivate int[] flags;\n\n\tpublic Graph(int vertexCount) {\n\t\tthis(vertexCount, vertexCount);\n\t}\n\n\tpublic Graph(int vertexCount, int edgeCapacity) {\n\t\tthis.vertexCount = vertexCount;\n\t\tfirstOutbound = new int[vertexCount];\n\t\tArrays.fill(firstOutbound, -1);\n\n\t\tfrom = new int[edgeCapacity];\n\t\tto = new int[edgeCapacity];\n\t\tnextOutbound = new int[edgeCapacity];\n\t\tflags = new int[edgeCapacity];\n\t}\n\n\tpublic static Graph createGraph(int vertexCount, int[] from, int[] to) {\n\t\tGraph graph = new Graph(vertexCount, from.length);\n\t\tfor (int i = 0; i < from.length; i++)\n\t\t\tgraph.addSimpleEdge(from[i], to[i]);\n\t\treturn graph;\n\t}\n\n\tpublic static Graph createWeightedGraph(int vertexCount, int[] from,\n\t\t\tint[] to, long[] weight) {\n\t\tGraph graph = new Graph(vertexCount, from.length);\n\t\tfor (int i = 0; i < from.length; i++)\n\t\t\tgraph.addWeightedEdge(from[i], to[i], weight[i]);\n\t\treturn graph;\n\t}\n\n\tpublic static Graph createFlowGraph(int vertexCount, int[] from, int[] to,\n\t\t\tlong[] capacity) {\n\t\tGraph graph = new Graph(vertexCount, from.length * 2);\n\t\tfor (int i = 0; i < from.length; i++)\n\t\t\tgraph.addFlowEdge(from[i], to[i], capacity[i]);\n\t\treturn graph;\n\t}\n\n\tpublic static Graph createFlowWeightedGraph(int vertexCount, int[] from,\n\t\t\tint[] to, long[] weight, long[] capacity) {\n\t\tGraph graph = new Graph(vertexCount, from.length * 2);\n\t\tfor (int i = 0; i < from.length; i++)\n\t\t\tgraph.addFlowWeightedEdge(from[i], to[i], weight[i], capacity[i]);\n\t\treturn graph;\n\t}\n\n\tpublic static Graph createTree(int[] parent) {\n\t\tGraph graph = new Graph(parent.length + 1, parent.length);\n\t\tfor (int i = 0; i < parent.length; i++)\n\t\t\tgraph.addSimpleEdge(parent[i], i + 1);\n\t\treturn graph;\n\t}\n\n\tpublic int addEdge(int fromID, int toID, long weight, long capacity,\n\t\t\tint reverseEdge) {\n\t\tensureEdgeCapacity(edgeCount + 1);\n\t\tif (firstOutbound[fromID] != -1)\n\t\t\tnextOutbound[edgeCount] = firstOutbound[fromID];\n\t\telse\n\t\t\tnextOutbound[edgeCount] = -1;\n\t\tfirstOutbound[fromID] = edgeCount;\n\t\tif (firstInbound != null) {\n\t\t\tif (firstInbound[toID] != -1)\n\t\t\t\tnextInbound[edgeCount] = firstInbound[toID];\n\t\t\telse\n\t\t\t\tnextInbound[edgeCount] = -1;\n\t\t\tfirstInbound[toID] = edgeCount;\n\t\t}\n\t\tthis.from[edgeCount] = fromID;\n\t\tthis.to[edgeCount] = toID;\n\t\tif (capacity != 0) {\n\t\t\tif (this.capacity == null)\n\t\t\t\tthis.capacity = new long[from.length];\n\t\t\tthis.capacity[edgeCount] = capacity;\n\t\t}\n\t\tif (weight != 0) {\n\t\t\tif (this.weight == null)\n\t\t\t\tthis.weight = new long[from.length];\n\t\t\tthis.weight[edgeCount] = weight;\n\t\t}\n\t\tif (reverseEdge != -1) {\n\t\t\tif (this.reverseEdge == null) {\n\t\t\t\tthis.reverseEdge = new int[from.length];\n\t\t\t\tArrays.fill(this.reverseEdge, 0, edgeCount, -1);\n\t\t\t}\n\t\t\tthis.reverseEdge[edgeCount] = reverseEdge;\n\t\t}\n\t\tif (edges != null)\n\t\t\tedges[edgeCount] = createEdge(edgeCount);\n\t\treturn edgeCount++;\n\t}\n\n\tprotected final GraphEdge createEdge(int id) {\n\t\treturn new GraphEdge(id);\n\t}\n\n\tpublic final int addFlowWeightedEdge(int from, int to, long weight,\n\t\t\tlong capacity) {\n\t\tif (capacity == 0) {\n\t\t\treturn addEdge(from, to, weight, 0, -1);\n\t\t} else {\n\t\t\tint lastEdgeCount = edgeCount;\n\t\t\taddEdge(to, from, -weight, 0, lastEdgeCount + entriesPerEdge());\n\t\t\treturn addEdge(from, to, weight, capacity, lastEdgeCount);\n\t\t}\n\t}\n\n\tprotected int entriesPerEdge() {\n\t\treturn 1;\n\t}\n\n\tpublic final int addFlowEdge(int from, int to, long capacity) {\n\t\treturn addFlowWeightedEdge(from, to, 0, capacity);\n\t}\n\n\tpublic final int addWeightedEdge(int from, int to, long weight) {\n\t\treturn addFlowWeightedEdge(from, to, weight, 0);\n\t}\n\n\tpublic final int addSimpleEdge(int from, int to) {\n\t\treturn addWeightedEdge(from, to, 0);\n\t}\n\n\tpublic final int vertexCount() {\n\t\treturn vertexCount;\n\t}\n\n\tpublic final int edgeCount() {\n\t\treturn edgeCount;\n\t}\n\n\tprotected final int edgeCapacity() {\n\t\treturn from.length;\n\t}\n\n\tpublic final Edge edge(int id) {\n\t\tinitEdges();\n\t\treturn edges[id];\n\t}\n\n\tpublic final int firstOutbound(int vertex) {\n\t\tint id = firstOutbound[vertex];\n\t\twhile (id != -1 && isRemoved(id))\n\t\t\tid = nextOutbound[id];\n\t\treturn id;\n\t}\n\n\tpublic final int nextOutbound(int id) {\n\t\tid = nextOutbound[id];\n\t\twhile (id != -1 && isRemoved(id))\n\t\t\tid = nextOutbound[id];\n\t\treturn id;\n\t}\n\n\tpublic final int firstInbound(int vertex) {\n\t\tinitInbound();\n\t\tint id = firstInbound[vertex];\n\t\twhile (id != -1 && isRemoved(id))\n\t\t\tid = nextInbound[id];\n\t\treturn id;\n\t}\n\n\tpublic final int nextInbound(int id) {\n\t\tinitInbound();\n\t\tid = nextInbound[id];\n\t\twhile (id != -1 && isRemoved(id))\n\t\t\tid = nextInbound[id];\n\t\treturn id;\n\t}\n\n\tpublic final int source(int id) {\n\t\treturn from[id];\n\t}\n\n\tpublic final int destination(int id) {\n\t\treturn to[id];\n\t}\n\n\tpublic final long weight(int id) {\n\t\tif (weight == null)\n\t\t\treturn 0;\n\t\treturn weight[id];\n\t}\n\n\tpublic final long capacity(int id) {\n\t\tif (capacity == null)\n\t\t\treturn 0;\n\t\treturn capacity[id];\n\t}\n\n\tpublic final long flow(int id) {\n\t\tif (reverseEdge == null)\n\t\t\treturn 0;\n\t\treturn capacity[reverseEdge[id]];\n\t}\n\n\tpublic final void pushFlow(int id, long flow) {\n\t\tif (flow == 0)\n\t\t\treturn;\n\t\tif (flow > 0) {\n\t\t\tif (capacity(id) < flow)\n\t\t\t\tthrow new IllegalArgumentException(\"Not enough capacity\");\n\t\t} else {\n\t\t\tif (flow(id) < -flow)\n\t\t\t\tthrow new IllegalArgumentException(\"Not enough capacity\");\n\t\t}\n\t\tcapacity[id] -= flow;\n\t\tcapacity[reverseEdge[id]] += flow;\n\t}\n\n\tpublic int transposed(int id) {\n\t\treturn -1;\n\t}\n\n\tpublic final int reverse(int id) {\n\t\tif (reverseEdge == null)\n\t\t\treturn -1;\n\t\treturn reverseEdge[id];\n\t}\n\n\tpublic final void addVertices(int count) {\n\t\tensureVertexCapacity(vertexCount + count);\n\t\tArrays.fill(firstOutbound, vertexCount, vertexCount + count, -1);\n\t\tif (firstInbound != null)\n\t\t\tArrays.fill(firstInbound, vertexCount, vertexCount + count, -1);\n\t\tvertexCount += count;\n\t}\n\n\tprotected final void initEdges() {\n\t\tif (edges == null) {\n\t\t\tedges = new Edge[from.length];\n\t\t\tfor (int i = 0; i < edgeCount; i++)\n\t\t\t\tedges[i] = createEdge(i);\n\t\t}\n\t}\n\n\tpublic final void removeVertex(int vertex) {\n\t\tint id = firstOutbound[vertex];\n\t\twhile (id != -1) {\n\t\t\tremoveEdge(id);\n\t\t\tid = nextOutbound[id];\n\t\t}\n\t\tinitInbound();\n\t\tid = firstInbound[vertex];\n\t\twhile (id != -1) {\n\t\t\tremoveEdge(id);\n\t\t\tid = nextInbound[id];\n\t\t}\n\t}\n\n\tprivate void initInbound() {\n\t\tif (firstInbound == null) {\n\t\t\tfirstInbound = new int[firstOutbound.length];\n\t\t\tArrays.fill(firstInbound, 0, vertexCount, -1);\n\t\t\tnextInbound = new int[from.length];\n\t\t\tfor (int i = 0; i < edgeCount; i++) {\n\t\t\t\tnextInbound[i] = firstInbound[to[i]];\n\t\t\t\tfirstInbound[to[i]] = i;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic final boolean flag(int id, int bit) {\n\t\treturn (flags[id] >> bit & 1) != 0;\n\t}\n\n\tpublic final void setFlag(int id, int bit) {\n\t\tflags[id] |= 1 << bit;\n\t}\n\n\tpublic final void removeFlag(int id, int bit) {\n\t\tflags[id] &= -1 - (1 << bit);\n\t}\n\n\tpublic final void removeEdge(int id) {\n\t\tsetFlag(id, REMOVED_BIT);\n\t}\n\n\tpublic final void restoreEdge(int id) {\n\t\tremoveFlag(id, REMOVED_BIT);\n\t}\n\n\tpublic final boolean isRemoved(int id) {\n\t\treturn flag(id, REMOVED_BIT);\n\t}\n\n\tpublic final Iterable outbound(final int id) {\n\t\tinitEdges();\n\t\treturn new Iterable() {\n\t\t\tpublic Iterator iterator() {\n\t\t\t\treturn new EdgeIterator(id, firstOutbound, nextOutbound);\n\t\t\t}\n\t\t};\n\t}\n\n\tpublic final Iterable inbound(final int id) {\n\t\tinitEdges();\n\t\tinitInbound();\n\t\treturn new Iterable() {\n\t\t\tpublic Iterator iterator() {\n\t\t\t\treturn new EdgeIterator(id, firstInbound, nextInbound);\n\t\t\t}\n\t\t};\n\t}\n\n\tprotected void ensureEdgeCapacity(int size) {\n\t\tif (from.length < size) {\n\t\t\tint newSize = Math.max(size, 2 * from.length);\n\t\t\tif (edges != null)\n\t\t\t\tedges = resize(edges, newSize);\n\t\t\tfrom = resize(from, newSize);\n\t\t\tto = resize(to, newSize);\n\t\t\tnextOutbound = resize(nextOutbound, newSize);\n\t\t\tif (nextInbound != null)\n\t\t\t\tnextInbound = resize(nextInbound, newSize);\n\t\t\tif (weight != null)\n\t\t\t\tweight = resize(weight, newSize);\n\t\t\tif (capacity != null)\n\t\t\t\tcapacity = resize(capacity, newSize);\n\t\t\tif (reverseEdge != null)\n\t\t\t\treverseEdge = resize(reverseEdge, newSize);\n\t\t\tflags = resize(flags, newSize);\n\t\t}\n\t}\n\n\tprivate void ensureVertexCapacity(int size) {\n\t\tif (firstOutbound.length < size) {\n\t\t\tint newSize = Math.max(size, 2 * from.length);\n\t\t\tfirstOutbound = resize(firstOutbound, newSize);\n\t\t\tif (firstInbound != null)\n\t\t\t\tfirstInbound = resize(firstInbound, newSize);\n\t\t}\n\t}\n\n\tprotected final int[] resize(int[] array, int size) {\n\t\tint[] newArray = new int[size];\n\t\tSystem.arraycopy(array, 0, newArray, 0, array.length);\n\t\treturn newArray;\n\t}\n\n\tprivate long[] resize(long[] array, int size) {\n\t\tlong[] newArray = new long[size];\n\t\tSystem.arraycopy(array, 0, newArray, 0, array.length);\n\t\treturn newArray;\n\t}\n\n\tprivate Edge[] resize(Edge[] array, int size) {\n\t\tEdge[] newArray = new Edge[size];\n\t\tSystem.arraycopy(array, 0, newArray, 0, array.length);\n\t\treturn newArray;\n\t}\n\n\tpublic final boolean isSparse() {\n\t\treturn vertexCount == 0 || edgeCount * 20 / vertexCount <= vertexCount;\n\t}\n\n\tprotected class GraphEdge implements Edge {\n\t\tprotected int id;\n\n\t\tprotected GraphEdge(int id) {\n\t\t\tthis.id = id;\n\t\t}\n\n\t\tpublic int getSource() {\n\t\t\treturn source(id);\n\t\t}\n\n\t\tpublic int getDestination() {\n\t\t\treturn destination(id);\n\t\t}\n\n\t\tpublic long getWeight() {\n\t\t\treturn weight(id);\n\t\t}\n\n\t\tpublic long getCapacity() {\n\t\t\treturn capacity(id);\n\t\t}\n\n\t\tpublic long getFlow() {\n\t\t\treturn flow(id);\n\t\t}\n\n\t\tpublic void pushFlow(long flow) {\n\t\t\tGraph.this.pushFlow(id, flow);\n\t\t}\n\n\t\tpublic boolean getFlag(int bit) {\n\t\t\treturn flag(id, bit);\n\t\t}\n\n\t\tpublic void setFlag(int bit) {\n\t\t\tGraph.this.setFlag(id, bit);\n\t\t}\n\n\t\tpublic void removeFlag(int bit) {\n\t\t\tGraph.this.removeFlag(id, bit);\n\t\t}\n\n\t\tpublic int getTransposedID() {\n\t\t\treturn transposed(id);\n\t\t}\n\n\t\tpublic Edge getTransposedEdge() {\n\t\t\tint reverseID = getTransposedID();\n\t\t\tif (reverseID == -1)\n\t\t\t\treturn null;\n\t\t\tinitEdges();\n\t\t\treturn edge(reverseID);\n\t\t}\n\n\t\tpublic int getReverseID() {\n\t\t\treturn reverse(id);\n\t\t}\n\n\t\tpublic Edge getReverseEdge() {\n\t\t\tint reverseID = getReverseID();\n\t\t\tif (reverseID == -1)\n\t\t\t\treturn null;\n\t\t\tinitEdges();\n\t\t\treturn edge(reverseID);\n\t\t}\n\n\t\tpublic int getID() {\n\t\t\treturn id;\n\t\t}\n\n\t\tpublic void remove() {\n\t\t\tremoveEdge(id);\n\t\t}\n\n\t\tpublic void restore() {\n\t\t\trestoreEdge(id);\n\t\t}\n\t}\n\n\tpublic class EdgeIterator implements Iterator {\n\t\tprivate int edgeID;\n\t\tprivate final int[] next;\n\t\tprivate int lastID = -1;\n\n\t\tpublic EdgeIterator(int id, int[] first, int[] next) {\n\t\t\tthis.next = next;\n\t\t\tedgeID = nextEdge(first[id]);\n\t\t}\n\n\t\tprivate int nextEdge(int id) {\n\t\t\twhile (id != -1 && isRemoved(id))\n\t\t\t\tid = next[id];\n\t\t\treturn id;\n\t\t}\n\n\t\tpublic boolean hasNext() {\n\t\t\treturn edgeID != -1;\n\t\t}\n\n\t\tpublic Edge next() {\n\t\t\tif (edgeID == -1)\n\t\t\t\tthrow new NoSuchElementException();\n\t\t\tlastID = edgeID;\n\t\t\tedgeID = nextEdge(next[lastID]);\n\t\t\treturn edges[lastID];\n\t\t}\n\n\t\tpublic void remove() {\n\t\t\tif (lastID == -1)\n\t\t\t\tthrow new IllegalStateException();\n\t\t\tremoveEdge(lastID);\n\t\t\tlastID = -1;\n\t\t}\n\t}\n\n}\n\nclass MiscUtils {\n\tpublic static final int[] DX4 = { 1, 0, -1, 0 };\n\tpublic static final int[] DY4 = { 0, -1, 0, 1 };\n\tpublic static final int[] DX8 = { 1, 1, 1, 0, -1, -1, -1, 0 };\n\tpublic static final int[] DY8 = { -1, 0, 1, 1, 1, 0, -1, -1 };\n\tpublic static final int[] DX_KNIGHT = { 2, 1, -1, -2, -2, -1, 1, 2 };\n\tpublic static final int[] DY_KNIGHT = { 1, 2, 2, 1, -1, -2, -2, -1 };\n\n\tprivate static final String[] ROMAN_TOKENS = { \"M\", \"CM\", \"D\", \"CD\", \"C\",\n\t\t\t\"XC\", \"L\", \"XL\", \"X\", \"IX\", \"V\", \"IV\", \"I\" };\n\tprivate static final int[] ROMAN_VALUES = { 1000, 900, 500, 400, 100, 90,\n\t\t\t50, 40, 10, 9, 5, 4, 1 };\n\n\tpublic static long josephProblem(long n, int k) {\n\t\tif (n == 1)\n\t\t\treturn 0;\n\t\tif (k == 1)\n\t\t\treturn n - 1;\n\t\tif (k > n)\n\t\t\treturn (josephProblem(n - 1, k) + k) % n;\n\t\tlong count = n / k;\n\t\tlong result = josephProblem(n - count, k);\n\t\tresult -= n % k;\n\t\tif (result < 0)\n\t\t\tresult += n;\n\t\telse\n\t\t\tresult += result / (k - 1);\n\t\treturn result;\n\t}\n\n\tpublic static boolean isValidCell(int row, int column, int rowCount,\n\t\t\tint columnCount) {\n\t\treturn row >= 0 && row < rowCount && column >= 0\n\t\t\t\t&& column < columnCount;\n\t}\n\n\tpublic static List getPath(int[] last, int destination) {\n\t\tList path = new ArrayList();\n\t\twhile (destination != -1) {\n\t\t\tpath.add(destination);\n\t\t\tdestination = last[destination];\n\t\t}\n\t\tinPlaceReverse(path);\n\t\treturn path;\n\t}\n\n\tprivate static void inPlaceReverse(List list) {\n\t\tfor (int i = 0, j = list.size() - 1; i < j; i++, j--)\n\t\t\tswap(list, i, j);\n\t}\n\n\tprivate static void swap(List list, int first, int second) {\n\t\tif (first == second)\n\t\t\treturn;\n\t\tint temp = list.get(first);\n\t\tlist.set(first, list.get(second));\n\t\tlist.set(second, temp);\n\t}\n\n\tpublic static List getPath(int[][] lastIndex,\n\t\t\tint[][] lastPathNumber, int destination, int pathNumber) {\n\t\tList path = new ArrayList();\n\t\twhile (destination != -1 || pathNumber != 0) {\n\t\t\tpath.add(destination);\n\t\t\tint nextDestination = lastIndex[destination][pathNumber];\n\t\t\tpathNumber = lastPathNumber[destination][pathNumber];\n\t\t\tdestination = nextDestination;\n\t\t}\n\t\tinPlaceReverse(path);\n\t\treturn path;\n\t}\n\n\tpublic static long maximalRectangleSum(long[][] array) {\n\t\tint n = array.length;\n\t\tint m = array[0].length;\n\t\tlong[][] partialSums = new long[n + 1][m + 1];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tlong rowSum = 0;\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\trowSum += array[i][j];\n\t\t\t\tpartialSums[i + 1][j + 1] = partialSums[i][j + 1] + rowSum;\n\t\t\t}\n\t\t}\n\t\tlong result = Long.MIN_VALUE;\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tfor (int j = i; j < m; j++) {\n\t\t\t\tlong minPartialSum = 0;\n\t\t\t\tfor (int k = 1; k <= n; k++) {\n\t\t\t\t\tlong current = partialSums[k][j + 1] - partialSums[k][i];\n\t\t\t\t\tresult = Math.max(result, current - minPartialSum);\n\t\t\t\t\tminPartialSum = Math.min(minPartialSum, current);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int parseIP(String ip) {\n\t\tString[] components = ip.split(\"[.]\");\n\t\tint result = 0;\n\t\tfor (int i = 0; i < 4; i++)\n\t\t\tresult += (1 << (24 - 8 * i)) * Integer.parseInt(components[i]);\n\t\treturn result;\n\t}\n\n\tpublic static String buildIP(int mask) {\n\t\tStringBuilder result = new StringBuilder();\n\t\tfor (int i = 0; i < 4; i++) {\n\t\t\tif (i != 0)\n\t\t\t\tresult.append('.');\n\t\t\tresult.append(mask >> (24 - 8 * i) & 255);\n\t\t}\n\t\treturn result.toString();\n\t}\n\n\tpublic static long binarySearch(long from, long to,\n\t\t\tFunction function) {\n\t\twhile (from < to) {\n\t\t\tlong argument = from + (to - from) / 2;\n\t\t\tif (function.value(argument))\n\t\t\t\tto = argument;\n\t\t\telse\n\t\t\t\tfrom = argument + 1;\n\t\t}\n\t\treturn from;\n\t}\n\n\tpublic static boolean equals(T first, T second) {\n\t\treturn first == null && second == null || first != null\n\t\t\t\t&& first.equals(second);\n\t}\n\n\tpublic static boolean isVowel(char ch) {\n\t\tch = Character.toUpperCase(ch);\n\t\treturn ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U'\n\t\t\t\t|| ch == 'Y';\n\t}\n\n\tpublic static boolean isStrictVowel(char ch) {\n\t\tch = Character.toUpperCase(ch);\n\t\treturn ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U';\n\t}\n\n\tpublic static String convertToRoman(int number) {\n\t\tStringBuilder result = new StringBuilder();\n\t\tfor (int i = 0; i < ROMAN_TOKENS.length; i++) {\n\t\t\twhile (number >= ROMAN_VALUES[i]) {\n\t\t\t\tnumber -= ROMAN_VALUES[i];\n\t\t\t\tresult.append(ROMAN_TOKENS[i]);\n\t\t\t}\n\t\t}\n\t\treturn result.toString();\n\t}\n\n\tpublic static int convertFromRoman(String number) {\n\t\tint result = 0;\n\t\tfor (int i = 0; i < ROMAN_TOKENS.length; i++) {\n\t\t\twhile (number.startsWith(ROMAN_TOKENS[i])) {\n\t\t\t\tnumber = number.substring(ROMAN_TOKENS[i].length());\n\t\t\t\tresult += ROMAN_VALUES[i];\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int distance(int x1, int y1, int x2, int y2) {\n\t\tint dx = x1 - x2;\n\t\tint dy = y1 - y2;\n\t\treturn dx * dx + dy * dy;\n\t}\n\n\tpublic static > T min(T first, T second) {\n\t\tif (first.compareTo(second) <= 0)\n\t\t\treturn first;\n\t\treturn second;\n\t}\n\n\tpublic static > T max(T first, T second) {\n\t\tif (first.compareTo(second) <= 0)\n\t\t\treturn second;\n\t\treturn first;\n\t}\n\n\tpublic static void decreaseByOne(int[]... arrays) {\n\t\tfor (int[] array : arrays) {\n\t\t\tfor (int i = 0; i < array.length; i++)\n\t\t\t\tarray[i]--;\n\t\t}\n\t}\n\n\tpublic static int[] getIntArray(String s) {\n\t\tString[] tokens = s.split(\" \");\n\t\tint[] result = new int[tokens.length];\n\t\tfor (int i = 0; i < result.length; i++)\n\t\t\tresult[i] = Integer.parseInt(tokens[i]);\n\t\treturn result;\n\t}\n}\n\nclass IntegerUtils {\n\tpublic static long gcd(long a, long b) {\n\t\ta = Math.abs(a);\n\t\tb = Math.abs(b);\n\t\twhile (b != 0) {\n\t\t\tlong temp = a % b;\n\t\t\ta = b;\n\t\t\tb = temp;\n\t\t}\n\t\treturn a;\n\t}\n\n\tpublic static int gcd(int a, int b) {\n\t\ta = Math.abs(a);\n\t\tb = Math.abs(b);\n\t\twhile (b != 0) {\n\t\t\tint temp = a % b;\n\t\t\ta = b;\n\t\t\tb = temp;\n\t\t}\n\t\treturn a;\n\t}\n\n\tpublic static int[] generatePrimes(int upTo) {\n\t\tint[] isPrime = generateBitPrimalityTable(upTo);\n\t\tList primes = new ArrayList();\n\t\tfor (int i = 0; i < upTo; i++) {\n\t\t\tif ((isPrime[i >> 5] >>> (i & 31) & 1) == 1)\n\t\t\t\tprimes.add(i);\n\t\t}\n\t\tint[] array = new int[primes.size()];\n\t\tfor (int i = 0; i < array.length; i++)\n\t\t\tarray[i] = primes.get(i);\n\t\treturn array;\n\t}\n\n\tpublic static boolean[] generatePrimalityTable(int upTo) {\n\t\tboolean[] isPrime = new boolean[upTo];\n\t\tif (upTo < 2)\n\t\t\treturn isPrime;\n\t\tArrays.fill(isPrime, true);\n\t\tisPrime[0] = isPrime[1] = false;\n\t\tfor (int i = 2; i * i < upTo; i++) {\n\t\t\tif (isPrime[i]) {\n\t\t\t\tfor (int j = i * i; j < upTo; j += i)\n\t\t\t\t\tisPrime[j] = false;\n\t\t\t}\n\t\t}\n\t\treturn isPrime;\n\t}\n\n\tpublic static int[] generateBitPrimalityTable(int upTo) {\n\t\tint[] isPrime = new int[(upTo + 31) >> 5];\n\t\tif (upTo < 2)\n\t\t\treturn isPrime;\n\t\tArrays.fill(isPrime, -1);\n\t\tisPrime[0] &= -4;\n\t\tfor (int i = 2; i * i < upTo; i++) {\n\t\t\tif ((isPrime[i >> 5] >>> (i & 31) & 1) == 1) {\n\t\t\t\tfor (int j = i * i; j < upTo; j += i)\n\t\t\t\t\tisPrime[j >> 5] &= -1 - (1 << (j & 31));\n\t\t\t}\n\t\t}\n\t\treturn isPrime;\n\t}\n\n\tpublic static int[] generateDivisorTable(int upTo) {\n\t\tint[] divisor = new int[upTo];\n\t\tfor (int i = 1; i < upTo; i++)\n\t\t\tdivisor[i] = i;\n\t\tfor (int i = 2; i * i < upTo; i++) {\n\t\t\tif (divisor[i] == i) {\n\t\t\t\tfor (int j = i * i; j < upTo; j += i)\n\t\t\t\t\tdivisor[j] = i;\n\t\t\t}\n\t\t}\n\t\treturn divisor;\n\t}\n\n\tpublic static long powerInFactorial(long n, long p) {\n\t\tlong result = 0;\n\t\twhile (n != 0) {\n\t\t\tresult += n /= p;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int sumDigits(CharSequence number) {\n\t\tint result = 0;\n\t\tfor (int i = number.length() - 1; i >= 0; i--)\n\t\t\tresult += digitValue(number.charAt(i));\n\t\treturn result;\n\t}\n\n\tpublic static int digitValue(char digit) {\n\t\tif (Character.isDigit(digit))\n\t\t\treturn digit - '0';\n\t\tif (Character.isUpperCase(digit))\n\t\t\treturn digit + 10 - 'A';\n\t\treturn digit + 10 - 'a';\n\t}\n\n\tpublic static int longCompare(long a, long b) {\n\t\tif (a < b)\n\t\t\treturn -1;\n\t\tif (a > b)\n\t\t\treturn 1;\n\t\treturn 0;\n\t}\n\n\tpublic static long[][] generateBinomialCoefficients(int n) {\n\t\tlong[][] result = new long[n + 1][n + 1];\n\t\tfor (int i = 0; i <= n; i++) {\n\t\t\tresult[i][0] = 1;\n\t\t\tfor (int j = 1; j <= i; j++)\n\t\t\t\tresult[i][j] = result[i - 1][j - 1] + result[i - 1][j];\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static long[][] generateBinomialCoefficients(int n, long module) {\n\t\tlong[][] result = new long[n + 1][n + 1];\n\t\tif (module == 1)\n\t\t\treturn result;\n\t\tfor (int i = 0; i <= n; i++) {\n\t\t\tresult[i][0] = 1;\n\t\t\tfor (int j = 1; j <= i; j++) {\n\t\t\t\tresult[i][j] = result[i - 1][j - 1] + result[i - 1][j];\n\t\t\t\tif (result[i][j] >= module)\n\t\t\t\t\tresult[i][j] -= module;\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static long[] generateBinomialRow(int n, long module) {\n\t\tlong[] result = generateReverse(n + 1, module);\n\t\tresult[0] = 1;\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\tresult[i] = result[i - 1] * (n - i + 1) % module * result[i]\n\t\t\t\t\t% module;\n\t\treturn result;\n\t}\n\n\tpublic static int[] representationInBase(long number, int base) {\n\t\tlong basePower = base;\n\t\tint exponent = 1;\n\t\twhile (number >= basePower) {\n\t\t\tbasePower *= base;\n\t\t\texponent++;\n\t\t}\n\t\tint[] representation = new int[exponent];\n\t\tfor (int i = 0; i < exponent; i++) {\n\t\t\tbasePower /= base;\n\t\t\trepresentation[i] = (int) (number / basePower);\n\t\t\tnumber %= basePower;\n\t\t}\n\t\treturn representation;\n\t}\n\n\tpublic static int trueDivide(int a, int b) {\n\t\treturn (a - trueMod(a, b)) / b;\n\t}\n\n\tpublic static long trueDivide(long a, long b) {\n\t\treturn (a - trueMod(a, b)) / b;\n\t}\n\n\tpublic static int trueMod(int a, int b) {\n\t\ta %= b;\n\t\ta += b;\n\t\ta %= b;\n\t\treturn a;\n\t}\n\n\tpublic static long trueMod(long a, long b) {\n\t\ta %= b;\n\t\ta += b;\n\t\ta %= b;\n\t\treturn a;\n\t}\n\n\tpublic static long factorial(int n) {\n\t\tlong result = 1;\n\t\tfor (int i = 2; i <= n; i++)\n\t\t\tresult *= i;\n\t\treturn result;\n\t}\n\n\tpublic static long factorial(int n, long mod) {\n\t\tlong result = 1;\n\t\tfor (int i = 2; i <= n; i++)\n\t\t\tresult = result * i % mod;\n\t\treturn result % mod;\n\t}\n\n\tpublic static List> factorize(long number) {\n\t\tList> result = new ArrayList>();\n\t\tfor (long i = 2; i * i <= number; i++) {\n\t\t\tif (number % i == 0) {\n\t\t\t\tint power = 0;\n\t\t\t\tdo {\n\t\t\t\t\tpower++;\n\t\t\t\t\tnumber /= i;\n\t\t\t\t} while (number % i == 0);\n\t\t\t\tresult.add(Pair.makePair(i, power));\n\t\t\t}\n\t\t}\n\t\tif (number != 1)\n\t\t\tresult.add(Pair.makePair(number, 1));\n\t\treturn result;\n\t}\n\n\tpublic static List getDivisors(long number) {\n\t\tList> primeDivisors = factorize(number);\n\t\treturn getDivisorsImpl(primeDivisors, 0, 1, new ArrayList());\n\t}\n\n\tprivate static List getDivisorsImpl(\n\t\t\tList> primeDivisors, int index, long current,\n\t\t\tList result) {\n\t\tif (index == primeDivisors.size()) {\n\t\t\tresult.add(current);\n\t\t\treturn result;\n\t\t}\n\t\tlong p = primeDivisors.get(index).first;\n\t\tint power = primeDivisors.get(index).second;\n\t\tfor (int i = 0; i <= power; i++) {\n\t\t\tgetDivisorsImpl(primeDivisors, index + 1, current, result);\n\t\t\tcurrent *= p;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static long power(long base, long exponent) {\n\t\tif (exponent == 0)\n\t\t\treturn 1;\n\t\tlong result = power(base, exponent >> 1);\n\t\tresult = result * result;\n\t\tif ((exponent & 1) != 0)\n\t\t\tresult = result * base;\n\t\treturn result;\n\t}\n\n\tpublic static long power(long base, long exponent, long mod) {\n\t\tif (base >= mod)\n\t\t\tbase %= mod;\n\t\tif (exponent == 0)\n\t\t\treturn 1 % mod;\n\t\tlong result = power(base, exponent >> 1, mod);\n\t\tresult = result * result % mod;\n\t\tif ((exponent & 1) != 0)\n\t\t\tresult = result * base % mod;\n\t\treturn result;\n\t}\n\n\tpublic static long lcm(long a, long b) {\n\t\treturn a / gcd(a, b) * b;\n\t}\n\n\tpublic static long[] generateFibonacci(long upTo) {\n\t\tint count = 0;\n\t\tlong last = 0;\n\t\tlong current = 1;\n\t\twhile (current <= upTo) {\n\t\t\tlong next = last + current;\n\t\t\tlast = current;\n\t\t\tcurrent = next;\n\t\t\tcount++;\n\t\t}\n\t\treturn generateFibonacci(count, -1);\n\t}\n\n\tpublic static long[] generateFibonacci(int count, long module) {\n\t\tlong[] result = new long[count];\n\t\tif (module == -1) {\n\t\t\tif (count != 0)\n\t\t\t\tresult[0] = 1;\n\t\t\tif (count > 1)\n\t\t\t\tresult[1] = 1;\n\t\t\tfor (int i = 2; i < count; i++)\n\t\t\t\tresult[i] = result[i - 1] + result[i - 2];\n\t\t} else {\n\t\t\tif (count != 0)\n\t\t\t\tresult[0] = 1 % module;\n\t\t\tif (count > 1)\n\t\t\t\tresult[1] = 1 % module;\n\t\t\tfor (int i = 2; i < count; i++)\n\t\t\t\tresult[i] = (result[i - 1] + result[i - 2]) % module;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static long[] generateHappy(int digits) {\n\t\tlong[] happy = new long[(1 << (digits + 1)) - 2];\n\t\thappy[0] = 4;\n\t\thappy[1] = 7;\n\t\tint first = 0;\n\t\tint last = 2;\n\t\tfor (int i = 2; i <= digits; i++) {\n\t\t\tfor (int j = 0; j < last - first; j++) {\n\t\t\t\thappy[last + 2 * j] = 10 * happy[first + j] + 4;\n\t\t\t\thappy[last + 2 * j + 1] = 10 * happy[first + j] + 7;\n\t\t\t}\n\t\t\tint next = last + 2 * (last - first);\n\t\t\tfirst = last;\n\t\t\tlast = next;\n\t\t}\n\t\treturn happy;\n\t}\n\n\tpublic static long[] generateFactorial(int count, long module) {\n\t\tlong[] result = new long[count];\n\t\tif (module == -1) {\n\t\t\tif (count != 0)\n\t\t\t\tresult[0] = 1;\n\t\t\tfor (int i = 1; i < count; i++)\n\t\t\t\tresult[i] = result[i - 1] * i;\n\t\t} else {\n\t\t\tif (count != 0)\n\t\t\t\tresult[0] = 1 % module;\n\t\t\tfor (int i = 1; i < count; i++)\n\t\t\t\tresult[i] = (result[i - 1] * i) % module;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static long reverse(long number, long module) {\n\t\treturn power(number, module - 2, module);\n\t}\n\n\tpublic static boolean isPrime(long number) {\n\t\tif (number < 2)\n\t\t\treturn false;\n\t\tfor (long i = 2; i * i <= number; i++) {\n\t\t\tif (number % i == 0)\n\t\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tpublic static long[] generateReverse(int upTo, long module) {\n\t\tlong[] result = new long[upTo];\n\t\tif (upTo > 1)\n\t\t\tresult[1] = 1;\n\t\tfor (int i = 2; i < upTo; i++)\n\t\t\tresult[i] = (module - module / i * result[((int) (module % i))]\n\t\t\t\t\t% module)\n\t\t\t\t\t% module;\n\t\treturn result;\n\t}\n\n\tpublic static long[] generateReverseFactorials(int upTo, long module) {\n\t\tlong[] result = generateReverse(upTo, module);\n\t\tif (upTo > 0)\n\t\t\tresult[0] = 1;\n\t\tfor (int i = 1; i < upTo; i++)\n\t\t\tresult[i] = result[i] * result[i - 1] % module;\n\t\treturn result;\n\t}\n\n\tpublic static long[] generatePowers(long base, int count, long mod) {\n\t\tlong[] result = new long[count];\n\t\tif (count != 0)\n\t\t\tresult[0] = 1 % mod;\n\t\tfor (int i = 1; i < count; i++)\n\t\t\tresult[i] = result[i - 1] * base % mod;\n\t\treturn result;\n\t}\n\n\tpublic static long nextPrime(long from) {\n\t\tif (from <= 2)\n\t\t\treturn 2;\n\t\tfrom += 1 - (from & 1);\n\t\twhile (!isPrime(from))\n\t\t\tfrom += 2;\n\t\treturn from;\n\t}\n\n\tpublic static long binomialCoefficient(int n, int m, long mod) {\n\t\tif (m < 0 || m > n)\n\t\t\treturn 0;\n\t\tif (2 * m > n)\n\t\t\tm = n - m;\n\t\tlong result = 1;\n\t\tfor (int i = n - m + 1; i <= n; i++)\n\t\t\tresult = result * i % mod;\n\t\treturn result\n\t\t\t\t* BigInteger.valueOf(factorial(m, mod))\n\t\t\t\t\t\t.modInverse(BigInteger.valueOf(mod)).longValue() % mod;\n\t}\n\n\tpublic static boolean isSquare(long number) {\n\t\tlong sqrt = Math.round(Math.sqrt(number));\n\t\treturn sqrt * sqrt == number;\n\t}\n\n\tpublic static long findCommon(long aRemainder, long aMod, long bRemainder,\n\t\t\tlong bMod) {\n\t\tlong modGCD = gcd(aMod, bMod);\n\t\tlong gcdRemainder = aRemainder % modGCD;\n\t\tif (gcdRemainder != bRemainder % modGCD)\n\t\t\treturn -1;\n\t\taMod /= modGCD;\n\t\taRemainder /= modGCD;\n\t\tbMod /= modGCD;\n\t\tbRemainder /= modGCD;\n\t\tlong aReverse = BigInteger.valueOf(aMod)\n\t\t\t\t.modInverse(BigInteger.valueOf(bMod)).longValue();\n\t\tlong bReverse = BigInteger.valueOf(bMod)\n\t\t\t\t.modInverse(BigInteger.valueOf(aMod)).longValue();\n\t\tlong mod = aMod * bMod;\n\t\treturn (bReverse * aRemainder % mod * bMod + aReverse * bRemainder\n\t\t\t\t% mod * aMod)\n\t\t\t\t% mod * modGCD + gcdRemainder;\n\t}\n\n\tpublic static long[] generatePowers(long base, long maxValue) {\n\t\tif (maxValue <= 0)\n\t\t\treturn new long[0];\n\t\tint size = 1;\n\t\tlong current = 1;\n\t\twhile (maxValue / base >= current) {\n\t\t\tcurrent *= base;\n\t\t\tsize++;\n\t\t}\n\t\treturn generatePowers(base, size, Long.MAX_VALUE);\n\t}\n}\n\ninterface IntComparator extends Comparator {\n\tpublic static final IntComparator DEFAULT = new IntComparator() {\n\t\tpublic int compare(Integer first, Integer second) {\n\t\t\tif (first < second)\n\t\t\t\treturn -1;\n\t\t\tif (first > second)\n\t\t\t\treturn 1;\n\t\t\treturn 0;\n\t\t}\n\t};\n\n\tpublic static final IntComparator REVERSE = new IntComparator() {\n\t\tpublic int compare(Integer first, Integer second) {\n\t\t\tif (first < second)\n\t\t\t\treturn 1;\n\t\t\tif (first > second)\n\t\t\t\treturn -1;\n\t\t\treturn 0;\n\t\t}\n\t};\n\n\tpublic int compare(Integer first, Integer second);\n}\n\nclass BidirectionalGraph extends Graph {\n\tpublic int[] transposedEdge;\n\n\tpublic BidirectionalGraph(int vertexCount) {\n\t\tthis(vertexCount, vertexCount);\n\t}\n\n\tpublic BidirectionalGraph(int vertexCount, int edgeCapacity) {\n\t\tsuper(vertexCount, 2 * edgeCapacity);\n\t\ttransposedEdge = new int[2 * edgeCapacity];\n\t}\n\n\tpublic static BidirectionalGraph createGraph(int vertexCount, int[] from,\n\t\t\tint[] to) {\n\t\tBidirectionalGraph graph = new BidirectionalGraph(vertexCount,\n\t\t\t\tfrom.length);\n\t\tfor (int i = 0; i < from.length; i++)\n\t\t\tgraph.addSimpleEdge(from[i], to[i]);\n\t\treturn graph;\n\t}\n\n\tpublic static BidirectionalGraph createWeightedGraph(int vertexCount,\n\t\t\tint[] from, int[] to, long[] weight) {\n\t\tBidirectionalGraph graph = new BidirectionalGraph(vertexCount,\n\t\t\t\tfrom.length);\n\t\tfor (int i = 0; i < from.length; i++)\n\t\t\tgraph.addWeightedEdge(from[i], to[i], weight[i]);\n\t\treturn graph;\n\t}\n\n\tpublic static BidirectionalGraph createFlowGraph(int vertexCount,\n\t\t\tint[] from, int[] to, long[] capacity) {\n\t\tBidirectionalGraph graph = new BidirectionalGraph(vertexCount,\n\t\t\t\tfrom.length * 2);\n\t\tfor (int i = 0; i < from.length; i++)\n\t\t\tgraph.addFlowEdge(from[i], to[i], capacity[i]);\n\t\treturn graph;\n\t}\n\n\tpublic static BidirectionalGraph createFlowWeightedGraph(int vertexCount,\n\t\t\tint[] from, int[] to, long[] weight, long[] capacity) {\n\t\tBidirectionalGraph graph = new BidirectionalGraph(vertexCount,\n\t\t\t\tfrom.length * 2);\n\t\tfor (int i = 0; i < from.length; i++)\n\t\t\tgraph.addFlowWeightedEdge(from[i], to[i], weight[i], capacity[i]);\n\t\treturn graph;\n\t}\n\n\t@Override\n\tpublic int addEdge(int fromID, int toID, long weight, long capacity,\n\t\t\tint reverseEdge) {\n\t\tint lastEdgeCount = edgeCount;\n\t\tsuper.addEdge(fromID, toID, weight, capacity, reverseEdge);\n\t\tsuper.addEdge(toID, fromID, weight, capacity, reverseEdge == -1 ? -1\n\t\t\t\t: reverseEdge + 1);\n\t\tthis.transposedEdge[lastEdgeCount] = lastEdgeCount + 1;\n\t\tthis.transposedEdge[lastEdgeCount + 1] = lastEdgeCount;\n\t\treturn lastEdgeCount;\n\t}\n\n\t@Override\n\tprotected int entriesPerEdge() {\n\t\treturn 2;\n\t}\n\n\t@Override\n\tpublic final int transposed(int id) {\n\t\treturn transposedEdge[id];\n\t}\n\n\t@Override\n\tprotected void ensureEdgeCapacity(int size) {\n\t\tif (size > edgeCapacity()) {\n\t\t\tsuper.ensureEdgeCapacity(size);\n\t\t\ttransposedEdge = resize(transposedEdge, edgeCapacity());\n\t\t}\n\t}\n}\n\nclass Pair implements Comparable> {\n\tpublic final U first;\n\tpublic final V second;\n\n\tpublic static Pair makePair(U first, V second) {\n\t\treturn new Pair(first, second);\n\t}\n\n\tprivate Pair(U first, V second) {\n\t\tthis.first = first;\n\t\tthis.second = second;\n\t}\n\n\t@Override\n\tpublic boolean equals(Object o) {\n\t\tif (this == o)\n\t\t\treturn true;\n\t\tif (o == null || getClass() != o.getClass())\n\t\t\treturn false;\n\n\t\tPair pair = (Pair) o;\n\n\t\treturn !(first != null ? !first.equals(pair.first) : pair.first != null)\n\t\t\t\t&& !(second != null ? !second.equals(pair.second)\n\t\t\t\t\t\t: pair.second != null);\n\n\t}\n\n\t@Override\n\tpublic int hashCode() {\n\t\tint result = first != null ? first.hashCode() : 0;\n\t\tresult = 31 * result + (second != null ? second.hashCode() : 0);\n\t\treturn result;\n\t}\n\n\tpublic Pair swap() {\n\t\treturn makePair(second, first);\n\t}\n\n\t@Override\n\tpublic String toString() {\n\t\treturn \"(\" + first + \",\" + second + \")\";\n\t}\n\n\t@SuppressWarnings({ \"unchecked\" })\n\tpublic int compareTo(Pair o) {\n\t\tint value = ((Comparable) first).compareTo(o.first);\n\t\tif (value != 0)\n\t\t\treturn value;\n\t\treturn ((Comparable) second).compareTo(o.second);\n\t}\n}\n\ninterface Edge {\n\tpublic int getSource();\n\n\tpublic int getDestination();\n\n\tpublic long getWeight();\n\n\tpublic long getCapacity();\n\n\tpublic long getFlow();\n\n\tpublic void pushFlow(long flow);\n\n\tpublic boolean getFlag(int bit);\n\n\tpublic void setFlag(int bit);\n\n\tpublic void removeFlag(int bit);\n\n\tpublic int getTransposedID();\n\n\tpublic Edge getTransposedEdge();\n\n\tpublic int getReverseID();\n\n\tpublic Edge getReverseEdge();\n\n\tpublic int getID();\n\n\tpublic void remove();\n\n\tpublic void restore();\n}\n\ninterface Function {\n\tpublic abstract V value(A argument);\n}", "lang_cluster": "Java", "tags": ["math", "implementation", "number theory"], "code_uid": "b80a4f1d1c666e5495dbdf94feef2160", "src_uid": "06eb66df61ff5d61d678bbb3bb6553cc", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class B {\n public static void main(String[] args) throws Exception {\n new B().solve();\n // new FileInputStream(new File(\"input.txt\")),\n // new PrintStream(new FileOutputStream(new File(\"output.txt\"))));\n }\n\n void solve() throws IOException {\n BufferedReader in = new BufferedReader(new\n InputStreamReader(System.in));\n Scanner sc = new Scanner(System.in);\n String[] sp;\n\n long x = sc.nextInt();\n long y = sc.nextInt();\n long n = sc.nextInt();\n long na = Integer.MAX_VALUE;\n long nb = 1;\n long ra, rb = ra = 0;\n for (long b = 1; b <= n; b++) {\n long _a = b * x / y;\n for (int i = 0; i < 2; i++) {\n long a = _a + i;\n long naa = Math.abs(a * y - b * x);\n long nbb = b * y;\n if ((na * nbb > naa * nb && (double) naa * nb < Long.MAX_VALUE) || na / 100 * nbb > naa / 100 * nbb) {\n na = naa;\n nb = nbb;\n ra = a;\n rb = b;\n }\n }\n }\n\n System.out.println(ra + \"/\" + rb);\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", "lang_cluster": "Java", "tags": ["two pointers", "implementation", "brute force"], "code_uid": "62bd2af80fb27650a2874e18b7691269", "src_uid": "827bc6f120aff6a6f04271bc84e863ee", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.Scanner;\n\npublic class HungryStudentProblem {\n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n int n = s.nextInt();\n for(int i = 0; i < n; i++) {\n int x = s.nextInt();\n int one = 0, two = 0;\n label:\n for(int j = 0; j <= x / 3 + 1; j++) {\n for(int k = 0; k <= x / 7 + 1; k++) {\n if(3 * j + 7 * k == x) {\n one = j;\n two = k;\n break label;\n }\n }\n }\n if(3 * one + 7 * two == x) System.out.println(\"YES\");\n else System.out.println(\"NO\");\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["greedy", "implementation"], "code_uid": "25a45527f2d35e5a5080d52740fc7925", "src_uid": "cfd1182be98fb5f0c426f8b68e48d452", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*; \nimport java.util.*;\n \npublic class Main {\n\t\n static class FastScanner\n { \n BufferedReader br; \n StringTokenizer st; \n \n public FastScanner() \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 public static void main(String[] args) throws IOException {\n FastScanner sc=new FastScanner();\n int N = sc.nextInt();\n int C = sc.nextInt();\n int[] p = new int[N];\n for (int i = 0; i < N; i++)\n \tp[i] = sc.nextInt();\n int[] t = new int[N];\n for (int i = 0; i < N; i++)\n \tt[i] = sc.nextInt();\n \n int score1 = 0;\n int time1 = 0;\n for (int i = 0; i < N; i++) {\n \ttime1 += t[i];\n \tscore1 += Math.max(0, p[i] - C*time1);\n }\n \n int score2 = 0;\n int time2 = 0;\n for (int i = N-1; i >= 0; i--) {\n \ttime2 += t[i];\n \tscore2 += Math.max(0, p[i] - C*time2);\n }\n \n if (score1 > score2) {\n \tSystem.out.println(\"Limak\");\n } else if (score2 > score1) {\n \tSystem.out.println(\"Radewoosh\");\n } else {\n \tSystem.out.println(\"Tie\");\n }\n }\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "157187619064b9eccbab14fdc7c5a71b", "src_uid": "8c704de75ab85f9e2c04a926143c8b4a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.*;\npublic class MartianClock {\n\tpublic static void main(String[] args){\n\t\tScanner reader = new Scanner(System.in);\n\t\tString in = reader.next();\n\t\tStringTokenizer st = new StringTokenizer(in, \":\");\n\t\tString a = st.nextToken();\n\t\tString b = st.nextToken();\n\t\t\n\t\tLinkedList q = new LinkedList();\n\t\t//try all bases!\n\t\tfor(int i = 2; i <= 70; i++){\n\t\t\ttry{\n\t\t\t\tint A = parseInt(a,i);\n\t\t\t\tint B = parseInt(b,i);\n\t\t\t\tif(A <= 23 && B <= 59)\n\t\t\t\t\tq.add(i);\n\t\t\t}catch(Exception e){\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif(q.size() == 0){\n\t\t\tSystem.out.println(0);\n\t\t}else if(q.getLast() == 70){\n\t\t\tSystem.out.println(-1);\n\t\t}else{\n\t\t\twhile(!q.isEmpty())\n\t\t\t\tSystem.out.print(q.remove() + \" \");\n\t\t\tSystem.out.println();\n\t\t}\n\t}\n\t\n\tpublic static int parseInt(String a, int b){\n\t\tif(b < 36)\n\t\t\treturn Integer.parseInt(a,b);\n\t\tint sum = 0;\n\t\tfor(int i = 0; i < a.length(); i++){\n\t\t\tsum *= b;\n\t\t\tsum += a.charAt(i)>='A'?(a.charAt(i)-'A'+10):(a.charAt(i)-'0');\n\t\t}\n\t\treturn sum;\n\t}\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "496abf470d016e6db028ebb025d814ce", "src_uid": "c02dfe5b8d9da2818a99c3afbe7a5293", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.text.DecimalFormat;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.Hashtable;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.PriorityQueue;\nimport java.util.Queue;\nimport java.util.Scanner;\nimport java.util.Set;\nimport java.util.TreeSet;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\n\npublic class palin {\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(System.out);\n\t\tScanner scan = new Scanner(System.in);\n\t\tTaskC solver = new TaskC();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskC {\n\tpublic void solve(int testNumber, InputReader in, PrintWriter out) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n = scan.nextInt(), a[] = new int[n], max = 0;\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\ta[i] = scan.nextInt();\n\t\t}\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tfor (int j = i; j < a.length; j++) {\n\t\t\t\tmax = Math.max(max, count(i, j, a));\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(max);\n\t}\n\n\tpublic static int count(int x, int y, int a[]) {\n\t\tint c = 0, co = 0;\n\t\tfor (int i = x; i <= y; i++) {\n\t\t\tif (a[i] == 0) {\n\t\t\t\tc++;\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tif (a[i] == 1 && i < x || a[i] == 1 && i > y) {\n\t\t\t\tco++;\n\t\t\t}\n\t\t}\n\t\treturn co + c;\n\t}\n}\n\nclass InputReader {\n\tBufferedReader br;\n\tStringTokenizer st;\n\n\tpublic InputReader(InputStream in) {\n\t\tbr = new BufferedReader(new InputStreamReader(in));\n\t\tst = null;\n\t}\n\n\tpublic String next() {\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\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 float nextFloat() {\n\t\treturn Float.parseFloat(next());\n\t}\n\n\tpublic double nextDouble() {\n\t\treturn Double.parseDouble(next());\n\t}\n}", "lang_cluster": "Java", "tags": ["brute force", "dp", "implementation"], "code_uid": "84b9de7678b5deb91f099823190e8a92", "src_uid": "9b543e07e805fe1dd8fa869d5d7c8b99", "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.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.InputMismatchException;\nimport java.util.LinkedList;\nimport java.util.Map.Entry;\nimport java.util.Queue;\nimport java.util.Random;\nimport java.util.Set;\nimport java.util.SortedSet;\nimport java.util.Stack;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\npublic class Main\n{\t\n\t/********************************************** a list of common variables **********************************************/\n\t\n\tprivate MyScanner scan = new MyScanner();\n\tprivate PrintWriter out = new PrintWriter(System.out);\n\tprivate final double PI = Math.acos(-1.0);\n\tprivate final int SIZEN = (int)(1e6);\n\tprivate final int MOD = (int)(1e9 + 7);\n\tprivate int n;\n\tprivate int k;\n\tprivate long s;\n\tprivate int m;\n\tprivate long[] a;\n\tprivate long[] f;\n\tprivate long ans;\n\tprivate HashMap[] hm;\n\t\n\tpublic void dfs1(int p, int step, long sum)\n\t{\n\t\tif(sum > s)\n\t\t{\n\t\t\treturn;\n\t\t}\n\t\thm[step].put(sum, hm[step].containsKey(sum) ? hm[step].get(sum) + 1 : 1);\n\t\tif(p >= m)\n\t\t{\n\t\t\treturn;\n\t\t}\n\t\tfor(int i = p;i < m;++i)\n\t\t{\n\t\t\tif(sum + a[i] <= s)\n\t\t\t{\n\t\t\t\tdfs1(i + 1, step, sum + a[i]);\n\t\t\t}\n\t\t\tif(sum + f[i] <= s && step < k)\n\t\t\t{\n\t\t\t\tdfs1(i + 1, step + 1, sum + f[i]);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tpublic void dfs2(int p, int step, long sum)\n\t{\n\t\tif(sum > s)\n\t\t{\n\t\t\treturn;\n\t\t}\n\t\tfor(int i = 0;i <= k - step;++i)\n\t\t{\n\t\t\tans += hm[i].containsKey(s - sum) ? hm[i].get(s - sum) : 0;\n\t\t}\n\t\tif(p >= n)\n\t\t{\n\t\t\treturn;\n\t\t}\n\t\tfor(int i = p;i < n;++i)\n\t\t{\n\t\t\tif(sum + a[i] <= s)\n\t\t\t{\n\t\t\t\tdfs2(i + 1, step, sum + a[i]);\n\t\t\t}\n\t\t\tif(sum + f[i] <= s && step < k)\n\t\t\t{\n\t\t\t\tdfs2(i + 1, step + 1, sum + f[i]);\n\t\t\t}\n\t\t}\t\t\n\t}\n\t\n\tpublic void foo()\n\t{\n\t\tn = scan.nextInt();\n\t\tk = scan.nextInt();\n\t\ts = scan.nextLong();\n\t\ta = new long[n];\n\t\tf = new long[n];\n\t\tfor(int i = 0;i < n;++i)\n\t\t{\n\t\t\ta[i] = scan.nextLong();\n\t\t\tf[i] = 1;\n\t\t\tfor(int j = 1;j <= a[i];++j)\n\t\t\t{\n\t\t\t\tf[i] *= j;\n\t\t\t\tif(f[i] > s)\n\t\t\t\t{\n\t\t\t\t\tf[i] = s + 1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tm = n / 2;\n\t\thm = new HashMap[k + 1];\n\t\tfor(int i = 0;i <= k;++i)\n\t\t{\n\t\t\thm[i] = new HashMap();\n\t\t}\n\t\tdfs1(0, 0, 0);\n\t\tans = 0;\n\t\tdfs2(m, 0, 0);\n\t\tout.println(ans);\n\t}\n\n\tpublic static void main(String[] args)\n\t{\n\t\tMain m = new Main();\n\t\tm.foo();\n\t\tm.out.close();\n\t}\n\t\n\t/********************************************** a list of common algorithms **********************************************/\n\t\n\t/**\n\t * KMP match, i.e. kmpMatch(\"abcd\", \"bcd\") = 1, kmpMatch(\"abcd\", \"bfcd\") = -1.\n\t * \n\t * @param\tt\tString to match.\n\t * @param\tp\tString to be matched.\n\t * @return\tif can match, first index; otherwise -1.\n\t */\n\tpublic int kmpMatch(char[] t, char[] p)\n\t{\n\t\tint n = t.length;\n\t\tint m = p.length;\n\t\tint[] next = new int[m + 1];\n\t\tnext[0] = -1;\n\t\tint j = -1;\n\t\tfor(int i = 1;i < m;++i)\n\t\t{\n\t\t\twhile(j >= 0 && p[i] != p[j + 1])\n\t\t\t{\n\t\t\t\tj = next[j];\n\t\t\t}\n\t\t\tif(p[i] == p[j + 1])\n\t\t\t{\n\t\t\t\t++j;\n\t\t\t}\n\t\t\tnext[i] = j;\n\t\t}\n\t\tj = -1;\n\t\tfor(int i = 0;i < n;++i)\n\t\t{\n\t\t\twhile(j >= 0 && t[i] != p[j + 1])\n\t\t\t{\n\t\t\t\tj = next[j];\n\t\t\t}\n\t\t\tif(t[i] == p[j + 1])\n\t\t\t{\n\t\t\t\t++j;\n\t\t\t}\n\t\t\tif(j == m - 1)\n\t\t\t{\n\t\t\t\treturn i - m + 1;\n\t\t\t}\n\t\t}\n\t\treturn -1;\n\t}\n\n\t/**\n\t * Get greatest common divisor\n\t * @param\ta\tan argument\n\t * @param\tb\tanother argument\n\t * @return\tgreatest common divisor\n\t */\n\tpublic int gcd(int a, int b)\n\t{\n\t\treturn 0 == b ? a : gcd(b, a % b);\n\t}\n\t\n\t/**\n\t * Get the minimum distance from a point to a segment (not a line) \n\t * @param\tx\tx coordinate of the point\n\t * @param\ty\ty coordinate of the point\n\t * @param\tx1\tx coordinate of one point of the segment\n\t * @param \ty1\ty coordinate of one point of the segment\n\t * @param \tx2\tx coordinate of another point of the segment\n\t * @param \ty2\ty coordinate of another point of the segment\n\t * @return\tthe minimum distance from point (x, y) to segment (x1, y1)-(x2, y2)\n\t */\n\tpublic double ptToSeg(double x, double y, double x1, double y1, double x2, double y2)\n\t{\n\t\tdouble cross = (x2 - x1) * (x - x1) + (y2 - y1) * (y - y1);\n\t\tif(cross <= 0)\n\t\t{\n\t\t\treturn (x - x1) * (x - x1) + (y - y1) * (y - y1);\n\t\t}\n\t\tdouble d = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);\n\t\tif(cross >= d) \n\t\t{\n\t\t\treturn (x - x2) * (x - x2) + (y - y2) * (y - y2);\n\t\t}\n\t\tdouble r = cross / d;\n\t\tdouble px = x1 + (x2 - x1) * r;\n\t\tdouble py = y1 + (y2 - y1) * r;\n\t\treturn (x - px) * (x - px) + (y - py) * (y - py);\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 double nextDouble() \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 double res = 0;\n\t while (!isSpaceChar(c) && c != '.') \n\t {\n\t if (c == 'e' || c == 'E')\n\t {\n\t \treturn res * Math.pow(10, nextInt());\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 & 15;\n\t c = read();\n\t }\n\t if (c == '.') \n\t {\n\t c = read();\n\t double m = 1;\n\t while (!isSpaceChar(c)) \n\t {\n\t if (c == 'e' || c == 'E')\n\t {\n\t \treturn res * Math.pow(10, nextInt());\n\t }\n\t if (c < '0' || c > '9')\n\t {\n\t \tthrow new InputMismatchException();\n\t }\n\t m /= 10;\n\t res += (c & 15) * m;\n\t c = read();\n\t }\n\t }\n\t return 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": ["brute force", "math", "dp", "binary search", "bitmasks", "meet-in-the-middle"], "code_uid": "d05973986a559ae8c51f9424f77d748d", "src_uid": "2821a11066dffc7e8f6a60a8751cea37", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.StringTokenizer;\n\npublic class JavaApplication1 {\nLong a,b;\n private void solution() throws IOException {\n a = in.nextLong();\n b = in.nextLong();\n rec( a, b);\n out.println(a + \" \" + b);\n }\n \n private void rec( Long a, Long b){\n if(a==0 || b==0) {\n this.a = a;\n this.b = b;\n return;\n }\n else if(a >= 2*b) rec((a)%(b*2), b);\n else if(b >= 2*a) rec(a, b%(2*a));\n else{\n this.a = a;\n this.b = b;\n }\n }\n private void run() throws IOException {\n in = new Scanner(System.in);\n out = new PrintWriter(System.out);\n solution();\n in.close();\n out.close();\n }\n\n private Scanner in;\n private PrintWriter out;\n\n public static void main(String[] args) throws IOException {\n new JavaApplication1().run();\n }\n\n private class Scanner {\n \n BufferedReader br;\n StringTokenizer st;\n\n private Scanner(InputStream is) {\n br = new BufferedReader(new InputStreamReader(is));\n }\n\n private String next() throws IOException {\n while (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(br.readLine());\n }\n return st.nextToken();\n }\n\n private Integer nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n private Long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n private Double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n private void close() throws IOException {\n st = null;\n br.close();\n }\n }\n}", "lang_cluster": "Java", "tags": ["math", "number theory"], "code_uid": "ec3e5eb38c8d1e583df9a258ff988b6f", "src_uid": "1f505e430eb930ea2b495ab531274114", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class P3 {\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner input = new Scanner(System.in);\n\t\tString form = \"\";\n\t\tint nb = 0;\n\t\tint ns = 0;\n\t\tint nc = 0;\n\t\tint pb = 0;\n\t\tint ps = 0;\n\t\tint pc = 0;\n\t\tlong r = 0;\n\t\t\n if (input.hasNext()) { \t\t \t\t\n \t\tform = input.next();\n \t\tnb = input.nextInt();\n \t\tns = input.nextInt();\n \t\tnc = input.nextInt();\n \t\tpb = input.nextInt();\n \t\tps = input.nextInt();\n \t\tpc = input.nextInt();\n \t\tr = input.nextLong();\n } \n int b = 0; \n int s = 0;\n int c = 0;\n \n for(int i = 0; i < form.length(); i++){\n \tchar aux = form.charAt(i);\n \tif(aux == 'B') b++;\n \tif(aux == 'C') c++;\n \tif(aux == 'S') s++;\n }\n \n long min = 0;\n long max = (long) Math.pow(10, 14); \n \n \n while(min + 1 < max){\n \tlong aux = (min + max)/2;\n \t\n \tlong total_b = (aux*b > nb)? (aux*b-nb)*pb : 0;\n \tlong total_s = (aux*s > ns)? (aux*s-ns)*ps : 0;\n \tlong total_c = (aux*c > nc)? (aux*c-nc)*pc : 0;\n \t\n \tlong total = total_b + total_s + total_c;\n \tif(total <= r){\n \t\tmin = aux;\n \t} else {\n \t\tmax = aux;\n \t}\n \t\n }\n System.out.println(min);\n\t}\n}", "lang_cluster": "Java", "tags": ["brute force", "binary search"], "code_uid": "f23c8145d17ecd9aa69cfe1bc9ed97f0", "src_uid": "8126a4232188ae7de8e5a7aedea1a97e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.util.Arrays;\n\npublic class SampleA497\n{\n\n\tpublic static void main(String[] args)\n\t{\tScanner s = new Scanner(System.in);\n // int n = s.nextInt();\n // int m = s.nextInt();\n \n int i=0,sum=0,j=0,temp=0,h=0,r=0,t=0;\n String s1 = s.next();\n // System.out.println(s1.length());\n int len = s1.length();\n if(s1.charAt(len-1)!='a' && s1.charAt(len-1)!='e' && s1.charAt(len-1)!='i' && s1.charAt(len-1)!='o' && s1.charAt(len-1)!='u' && s1.charAt(len-1)!='n'){\n h=1;\n }\n else{\n for(i=0;i0&&xmax)\n max=count;\n\n\n }\n }\n out.println(max);\n\t}\n class items implements Comparable\n {\n int index,p;\n public items(int p,int index)\n {\n this.p=p;\n this.index=index;\n }\n public int compareTo(items a)\n {\n if(a.p>this.p)\n return 1;\n return -1;\n }\n }\n}\n\n", "lang_cluster": "Java", "tags": ["greedy", "games", "graph matchings"], "code_uid": "4f95463b68aec5a0a1094694c74d14a8", "src_uid": "7419c4268a9815282fadca6581f28ec1", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "\nimport java.math.BigInteger;\nimport java.util.Scanner;\n\npublic class a_66 {\n\n public void run(){\n Scanner sc = new Scanner(System.in);\n \n String s = sc.next();\n BigInteger n = new BigInteger(s);\n \n if( n.compareTo(BigInteger.valueOf(-128)) >= 0 && n.compareTo(BigInteger.valueOf(127)) <= 0)\n System.out.println(\"byte\");\n else if( n.compareTo(BigInteger.valueOf(-32768)) >= 0 && n.compareTo(BigInteger.valueOf(32767)) <= 0 )\n System.out.println(\"short\");\n else if ( n.compareTo(BigInteger.valueOf(-2147483648)) >= 0 && n.compareTo(BigInteger.valueOf(2147483647)) <= 0 )\n System.out.println(\"int\");\n else if ( n.compareTo(BigInteger.valueOf(-9223372036854775808L)) >= 0 && n.compareTo(BigInteger.valueOf(9223372036854775807L)) <= 0 )\n System.out.println(\"long\");\n else\n System.out.println(\"BigInteger\");\n }\n \n \n public static void main(String args[]){\n new a_66().run();\n }\n \n}\n", "lang_cluster": "Java", "tags": ["strings", "implementation"], "code_uid": "6ad7b4d3a3d43a187eda21244d2dfa61", "src_uid": "33041f1832fa7f641e37c4c638ab08a1", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class A741 {\n\n\tpublic static void main(String[] args){\n\t\t\n\t\tint n;\n\t\t\n\t\tA741 ob=new A741();\n\t\t\n\t\tScanner scan=new Scanner(System.in);\n\t\t\n\t\tn=scan.nextInt();\n\t\t\n\t\tint[] arr= new int[n];\n\t\t\n\t\t\n\t\t\n\t\tfor(int i=0;i al=new ArrayList<>();\n\t\t\t\t\n\t\t\t\tal.add(i+1);\n\t\t\t\tint res=0;\n\t\t\t\t\n\t\t\t\t\n\t\t\t\twhile(!tv[i]){\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t \n\t\t\t\t\tal.add(arr[i]);\n\t\t\t\t\ttv[i]=true;\n\t\t\t\t\ti=arr[i]-1;\n\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\tif(al.get(0)==al.get(al.size()-1))\n\t\t\t\t{\n\t\t\t\t\tres=al.size()-1;\n\t\t\t\t\t\n\t\t\t\t\tif(res%2==0)\n\t\t\t\t\t\tres/=2;\n\t\t\t\t\t\n\t\t\t\t\tmax=ob.lcm(max,res);\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\t\n\t\t\t\telse {\n\t\t\t\t\n\t\t\t\t\tSystem.out.println(\"-1\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\n\t\t\t}\n\t\t\t\t\n\t\t}\n\t\t\n\t\tSystem.out.println(max);\n\t}\n\t\n\tint lcm(int a,int b){\n\t\t\n\t\tint min,max;\n\t\t\n\t\tif(a>b)\n\t\t{\n\t\tmax=a;\n\t\tmin=b;\n\t\t}\n\t\telse\n\t\t{\n\t\tmax=b;\n\t\tmin=a;\n\t\t}\n\t\t \n\t\t/*\n\t\tTo find the maximum and minimum numbers, you can also use\n\t\tint max=a>b?a:b;\n\t\tint min=a y1) {\n sum += a2;\n }\n if (z < 0) {\n sum += a3;\n }\n if (z > z1) {\n sum += a4;\n }\n if (x < 0) {\n sum += a5;\n }\n if (x > x1) {\n sum += a6;\n }\n out.println(sum);\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": ["brute force", "geometry"], "code_uid": "812ce5ad17c171b25e60804fb159062d", "src_uid": "c7889a8f64c57cf7be4df870f68f749e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\npublic class B {\n\n\tpublic static void main(String[] args) {\n\t\tInputReader in = new InputReader(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tB solver = new B();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\n\t}\n\n\tpublic void solve(int testNumber, InputReader in, PrintWriter out) {\n\n\t\tint n = in.nextInt();\n\t\tfloat t = in.nextInt();\n\t\t\n\t\tfloat[][] dp = new float[n + 1][n + 1];\n\t\t\n\t\tdp[0][0] = t;\n\t\tint count = 0;\n\t\t\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tfor(int j = 0; j <= i; j++) {\n\t\t\t\tfloat X = dp[i][j];\n\t\t\t\tif(X >= 1) {\n\t\t\t\t\tcount++;\n\t\t\t\t\t// dp[i][j] = 1;\n\t\t\t\t\tX -= 1;\n\t\t\t\t\tdp[i + 1][j] += X/2;\n\t\t\t\t\tdp[i + 1][j + 1] += X/2;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\tout.println(count);\n\t\t\n\t\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}\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "c036d226d8ae7ef559833e3dbf8db4dc", "src_uid": "b2b49b7f6e3279d435766085958fb69d", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class GuessTheTree {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tboolean solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint initN = n;\n\t\tList szList = new ArrayList<>();\n\t\tint leaves = 0;\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint x = nextInt();\n\t\t\tif (x == 1) {\n\t\t\t\tleaves++;\n\t\t\t} else {\n\t\t\t\tszList.add(x);\n\t\t\t}\n\t\t}\n\n\t\tn = szList.size();\n\n\t\tif (leaves <= n) {\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\tif (n == 0) {\n\t\t\treturn true;\n\t\t}\n\n\t\tCollections.sort(szList);\n\t\tCollections.reverse(szList);\n\n\t\tint[] sz = new int[n];\n\t\tfor (int i = 0; i < sz.length; i++) {\n\t\t\tsz[i] = szList.get(i);\n\t\t}\n\n\t\tif (sz[0] != initN) {\n\t\t\treturn false;\n\t\t}\n\n\t\tint[] maskCnt = new int[1 << n];\n\t\tint[] maskSum = new int[1 << n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tmaskCnt[1 << i] = 1;\n\t\t\tmaskSum[1 << i] = sz[i];\n\t\t}\n\n\t\tfor (int mask = 1; mask < (1 << n); mask++) {\n\t\t\tint low = Integer.lowestOneBit(mask);\n\t\t\tmaskCnt[mask] = maskCnt[low] + maskCnt[mask ^ low];\n\t\t\tmaskSum[mask] = maskSum[low] + maskSum[mask ^ low];\n\t\t}\n\n\t\tboolean[][][] dp = new boolean[n + 1][leaves + 1][1 << n];\n\t\t// current node, unassigned leaves, unassigned nodes\n\n\t\tfinal int ALL = (1 << n) - 1;\n\n\t\tdp[0][leaves][ALL ^ 1] = true;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j <= leaves; j++) {\n\t\t\t\tfor (int mask = 0; mask < (1 << n); mask++) {\n\t\t\t\t\tif (!dp[i][j][mask] || test(mask, i)) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tfor (int sub = mask; ; sub = (sub - 1) & mask) {\n\t\t\t\t\t\tint leavesHere = sz[i] - 1 - maskSum[sub];\n\t\t\t\t\t\tif (leavesHere >= 0 && leavesHere <= j\n\t\t\t\t\t\t\t\t&& leavesHere + maskCnt[sub] >= 2) {\n\t\t\t\t\t\t\tdp[i + 1][j - leavesHere][mask ^ sub] = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (sub == 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}\n\n\t\treturn dp[n][0][0];\n\n\t}\n\n\tstatic boolean test(int mask, int i) {\n\t\treturn ((mask >> i) & 1) == 1;\n\t}\n\n\tvoid inp() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tout.println(solve() ? \"YES\" : \"NO\");\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew GuessTheTree().inp();\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}\n", "lang_cluster": "Java", "tags": ["constructive algorithms", "dp", "bitmasks", "greedy", "trees"], "code_uid": "26ca7bb1100db192134f90a2e50ab98c", "src_uid": "ed0925cfaee961a3ceebd13b3c96a15a", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "\n\nimport java.io.*;\n\n/**\n * Created by DELL on 14-Nov-15.1 0\n */\npublic class Hopscotch\n{\n public static void main(String ar[])\n {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n\n BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));\n PrintWriter out = new PrintWriter(outputStream);\n\n Hopscotch demo = new Hopscotch();\n demo.solve(in, out);\n\n out.close();\n }\n\n public void solve(BufferedReader in, PrintWriter out)\n {\n try\n {\n String tokens[] = in.readLine().split(\" \");\n int side = Integer.parseInt(tokens[0]);\n int x = Integer.parseInt(tokens[1]);\n int y = Integer.parseInt(tokens[2]);\n out.println(taskB(side, x, y));\n } catch (IOException e)\n {\n e.printStackTrace();\n }\n }\n\n public long taskB(int side, int x, int y)\n {\n if (x == side || x == -side || y % side == 0)\n {\n return -1;\n }\n long yAbove = 0;\n long yBelow = 0;\n long iteration = 0;\n long stone = 0;\n while (true)\n {\n iteration++;\n stone = (iteration == 1 || iteration % 2 == 0) ? stone + 1 : stone + 2;\n yBelow = yAbove;\n yAbove += side;\n if ((y > yBelow && y < yAbove))\n {\n if (iteration == 1 || iteration % 2 == 0)\n {\n if (x < side / 2.0 && x > -side / 2.0)\n {\n return stone;\n }\n }\n else\n {\n if (x == 0)\n {\n return -1;\n }\n else if (x < side && x > 0)\n {\n return stone;\n }\n else if (x > -side && x < 0)\n {\n return stone - 1;\n }\n }\n }\n else if ((y < yBelow && y < yAbove) || y == yBelow || y == yAbove)\n {\n return -1;\n }\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "geometry"], "code_uid": "8a55c0610d3847b2b5f21fa570b69bea", "src_uid": "cf48ff6ba3e77ba5d4afccb8f775fb02", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.math.BigInteger;\nimport java.util.Scanner;\n\npublic class Main {\n\tpublic static void main(String[] args){\n\t\tScanner cin=new Scanner(System.in);\n\t\twhile(cin.hasNextInt()){\n\t\t\tBigInteger res1,res2,base,b1,b2;\n\t\t\tint n1,n2,i;\n\t\t\tBigInteger num1[]=new BigInteger[15];\n\t\t\tBigInteger num2[]=new BigInteger[15];\n\t\t\tn1=cin.nextInt();\n\t\t\tb1=cin.nextBigInteger();\n\t\t\tbase=new BigInteger(\"1\");\n\t\t\tres1=new BigInteger(\"0\");\n\t\t\tfor(i=0;i=0;i--){\n\t\t\t\tres1=res1.add(base.multiply(num1[i]));\n\t\t\t\tbase=base.multiply(b1);\n\t\t\t}\n\t\t\tn2=cin.nextInt();\n\t\t\tb2=cin.nextBigInteger();\n\t\t\tbase=new BigInteger(\"1\");\n\t\t\tres2=new BigInteger(\"0\");\n\t\t\tfor(i=0;i=0;i--){\n\t\t\t\tres2=res2.add(base.multiply(num2[i]));\n\t\t\t\tbase=base.multiply(b2);\n\t\t\t}\n\t\t\tif(res1.compareTo(res2)==0) System.out.println(\"=\");\n\t\t\telse if(res1.compareTo(res2)<0) System.out.println(\"<\");\n\t\t\telse System.out.println(\">\");\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "8a9c50ed52ff33efb367bac1d4342c8b", "src_uid": "d6ab5f75a7bee28f0af2bf168a0b2e67", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n \n public class Solution{\n \n public static void main(String args[]){\n \n Scanner sc = new Scanner(System.in);\n \n int n = sc.nextInt();\n String abc=sc.nextLine();\n String str = sc.nextLine();\n \n char ch[] = str.toCharArray();\n int arr[] = new int[ch.length];\n int vrr[] = new int[3];\n for(int i=0;i0 && c[1]>0 && c[2]>0) {\n \t\n \tf = 3;\n \tbreak;\n \t\n }\n }\n \n \n if((c[0]>0 && c[1]>0 && c[2]==0 ) || (c[0]==0 && c[1]>0 && c[2]>0 ) || (c[0]>0 && c[1]==0 && c[2]>0 ) ) {\n \t\n \tf = 2;\n \t\n \t\n }\n \n }\n \n int cc=0 ,mm=-1;;\n if(f==2) {\n \t \n \t if( vrr[0]>=2) {\n \t\t System.out.print(\"GR\");\n \t\t cc = -1;\n }\n \t \n \t \n \t if( vrr[1]>=2 && cc!=-1) {\n \t\t System.out.print(\"BR\"); \n \t\t cc=-1;\n }\n \t \n \t if( vrr[2]>=2 && cc!=-1) {\n \t\t System.out.print(\"BG\");\n }\n \t \n \t mm=0; \n }\n \n if(mm==-1) {\n \n \n for(int i=0;i<3;i++) {\n \t \n \t \n \t if(c[i]>0 && i==0) {\n \t\t System.out.print(\"B\");\n \t }\n \t \n \t if(c[i]>0 && i==1) {\n \t\t System.out.print(\"G\");\n \t }\n \n \t if(c[i]>0 && i==2) {\n \t\t System.out.print(\"R\");\n \t }\n \n \n }\n \n \n \n }\n \n \n \n }\n else{\n System.out.println(str);\n }\n \n \n }\n}", "lang_cluster": "Java", "tags": ["math", "dp", "constructive algorithms"], "code_uid": "648ceffeace3624a9a17605828f60b32", "src_uid": "4cedd3b70d793bc8ed4a93fc5a827f8f", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class E_1228 {\n\n static int n;\n static long k;\n static long[][] dp;\n static long[] kPow;\n static long[] k1Pow;\n static long[][] C;\n static long mod = (long) (1e9 + 7);\n\n static void prec() {\n kPow = new long[n + 1];\n k1Pow = new long[n + 1];\n kPow[0] = 1;\n k1Pow[0] = 1;\n for (int i = 1; i <= n; i++) {\n kPow[i] = (kPow[i - 1] * k) % mod;\n k1Pow[i] = (k1Pow[i - 1] * (k - 1)) % mod;\n }\n\n C = new long[n + 1][n + 1];\n C[0][0] = 1;\n for (int i = 1; i <= n; i++) {\n C[i][0] = C[i][i] = 1;\n for (int j = 1; j < i; j++) {\n C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;\n }\n }\n }\n\n static long mod(long x) {\n x %= mod;\n if (x < 0) x += mod;\n return x;\n }\n\n static void solve(FastReader in, PrintWriter out) {\n n = in.nextInt();\n k = in.nextInt();\n\n prec();\n\n dp = new long[n + 1][n + 1];\n dp[0][0] = 1;\n for (int r = 1; r <= n; r++) {\n dp[r][0] = dp[r - 1][0] * mod(kPow[n] - k1Pow[n]) % mod;\n }\n for (int c = 1; c <= n; c++) {\n dp[1][c] = kPow[n - c];\n }\n\n for (int r = 2; r <= n; r++) {\n for (int c = 1; c <= n; c++) {\n dp[r][c] = k1Pow[c] * mod(kPow[n - c] - k1Pow[n - c]) % mod * dp[r - 1][c] % mod;\n for (int c0 = 1; c0 <= c; c0++) {\n dp[r][c] = (dp[r][c] + kPow[n - c] * C[c][c0] % mod * k1Pow[c - c0] % mod * dp[r - 1][c - c0] % mod) % mod;\n }\n }\n }\n\n out.println(dp[n][n]);\n }\n\n public static void main(String[] args) {\n FastReader in = new FastReader(System.in);\n// FastReader in = new FastReader(new FileInputStream(\"input.txt\"));\n PrintWriter out = new PrintWriter(System.out);\n// PrintWriter out = new PrintWriter(new FileOutputStream(\"output.txt\"));\n\n\n int q = 1;\n\n while (q-- > 0)\n solve(in, out);\n\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}\n", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics"], "code_uid": "ee1747a61bf7f904d542a97e337192cd", "src_uid": "f67173c973c6f83e88bc0ddb0b9bfa93", "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.util.*; \nimport java.util.StringTokenizer; \nimport java.io.PrintWriter;\nimport java.io.*;\nimport java.lang.*;\npublic class Ideone\n{ \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 static class aksh \n{\n \n int x, y;\n public aksh(int a, int b) \n {\n x = a;\n y = b;\n }\n}\nstatic long power(long x,long y) \n{ \n long res = 1; // Initialize result \n \n // 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%2==1) \n res = (res*x); \n \n // y must be even now \n y = y>>1; // y = y/2 \n x = (x*x); \n } \n return res; \n} \n\n public static void main (String[] args) throws java.lang.Exception\n {\n // your code goes here\n FastReader sc=new FastReader();\n String s=sc.next();\n String t=sc.next();\n int ans=Integer.MIN_VALUE;\n for(int i=0;i 0){\n\t\t\txOrBool[a] = (xOr%2);\n\t\t\ta--;\n\t\t\txOr /= 2;\n\t\t}\n//\t\ta = 0;\n//\t\twhile(sum > 0){\n//\t\t\txOrSum[a] = (sum%2);\n//\t\t\ta++;\n//\t\t\tsum /= 2;\n//\t\t}\n\t\t\n\t\tlong decisions = 0;\n\t\t\n\t\tfor(int b = 0; b < 60; b++){\n//\t\t\tSystem.out.println(sum);\n\t\t\tif(xOrBool[b] == 1L){\n\t\t\t\tdecisions++;\n\t\t\t\tsum -= (long)(Math.pow(2, 59-b)+.5);\n\t\t\t}\n\t\t\telse{\n\t\t\t\tif(sum >= (long)(Math.pow(2, 60-b)+.5)){\n\t\t\t\t\tsum -= (long)(Math.pow(2, 60-b)+.5);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n//\t\tSystem.out.println(sum);\n\t\tint zeroValid = (xOrCpy == sumCpy)?2:0 ;\n\t\n\t\tif(sum == 0){\n\t\t\tSystem.out.println((long)(Math.pow(2L, decisions)+.5)-zeroValid);\n\t\t}\n\t\telse{\n\t\t\tSystem.out.println(0);\n\t\t}\n\t\t\n\t\t\n//\t\tfor(int b = 0; b < 60; b++){\n//\t\t\t\n//\t\t}\n\t\t\n\t\t\n\t\t\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["math", "dp"], "code_uid": "fdcf39b66f3de4a21ba1efa094aa4489", "src_uid": "18410980789b14c128dd6adfa501aea5", "difficulty": 1700.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\n/**\n *\n * @author Centrino\n */\nimport java.util.*;\npublic class JavaCourse {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n Scanner sc = new Scanner (System.in);\n int x = sc.nextInt();\n int count =0; int z=0,c=0;\n int i,r=x;\n boolean f =true;\n while(Math.sqrt(x)==(int)Math.sqrt(x)&&x>1){\n x =(int) Math.sqrt(x);count++;\n } \n for ( i =(int) Math.sqrt(x); i>1; i--) {\n z = i*i;\n while(x%(z)==0){\n count++;\n x /= i;\n f=false;\n } \n } \n if(f)\n System.out.println(x+\" \"+(count)); \n else\n System.out.println(x+\" \"+(count+1)); \n }\n}\n", "lang_cluster": "Java", "tags": ["math", "greedy", "number theory"], "code_uid": "3b889652cc4ecc0abac12f07939f8afb", "src_uid": "212cda3d9d611cd45332bb10b80f0b56", "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.OutputStream;\nimport java.io.IOException;\nimport java.io.UncheckedIOException;\nimport java.io.Closeable;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\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) throws Exception {\n Thread thread = new Thread(null, new TaskAdapter(), \"\", 1 << 29);\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 DRadioTowers solver = new DRadioTowers();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class DRadioTowers {\n int mod = 998244353;\n Combination comb = new Combination((int) 1e6, mod);\n CachedPow pow = new CachedPow(2, mod);\n\n public void solve(int testNumber, FastInput in, FastOutput out) {\n int n = in.ri();\n long prob = 0;\n for (int i = 1; i <= n; i++) {\n if ((n - i) % 2 != 0) {\n continue;\n }\n int m = (n - i) / 2;\n long way = comb.combination(m + i - 1, i - 1);\n prob += way * pow.inverse(n) % mod;\n }\n prob %= mod;\n out.println(prob);\n }\n\n }\n\n static class Combination implements IntCombination {\n final Factorial factorial;\n int modVal;\n\n public Combination(Factorial factorial) {\n this.factorial = factorial;\n this.modVal = factorial.getMod();\n }\n\n public Combination(int limit, int mod) {\n this(new Factorial(limit, mod));\n }\n\n public int combination(int m, int n) {\n if (n > m || n < 0) {\n return 0;\n }\n return (int) ((long) factorial.fact(m) * factorial.invFact(n) % modVal * factorial.invFact(m - n) % modVal);\n }\n\n }\n\n static class FastOutput implements AutoCloseable, Closeable, Appendable {\n private static final int THRESHOLD = 1 << 13;\n private final Writer os;\n private StringBuilder cache = new StringBuilder(THRESHOLD * 2);\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 private void afterWrite() {\n if (cache.length() < THRESHOLD) {\n return;\n }\n flush();\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 afterWrite();\n return this;\n }\n\n public FastOutput append(long c) {\n cache.append(c);\n afterWrite();\n return this;\n }\n\n public FastOutput append(String c) {\n cache.append(c);\n afterWrite();\n return this;\n }\n\n public FastOutput println(long c) {\n return append(c).println();\n }\n\n public FastOutput println() {\n return append(System.lineSeparator());\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 ri() {\n return readInt();\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 static class DigitUtils {\n private DigitUtils() {\n }\n\n public static int negate(int x, int mod) {\n return x == 0 ? 0 : mod - x;\n }\n\n }\n\n static class Factorial {\n int[] fact;\n int[] inv;\n int mod;\n\n public int getMod() {\n return mod;\n }\n\n public Factorial(int[] fact, int[] inv, int mod) {\n this.mod = mod;\n this.fact = fact;\n this.inv = inv;\n fact[0] = inv[0] = 1;\n int n = Math.min(fact.length, mod);\n for (int i = 1; i < n; i++) {\n fact[i] = i;\n fact[i] = (int) ((long) fact[i] * fact[i - 1] % mod);\n }\n inv[n - 1] = BigInteger.valueOf(fact[n - 1]).modInverse(BigInteger.valueOf(mod)).intValue();\n for (int i = n - 2; i >= 1; i--) {\n inv[i] = (int) ((long) inv[i + 1] * (i + 1) % mod);\n }\n }\n\n public Factorial(int limit, int mod) {\n this(new int[limit + 1], new int[limit + 1], mod);\n }\n\n public int fact(int n) {\n return fact[n];\n }\n\n public int invFact(int n) {\n return inv[n];\n }\n\n }\n\n static interface IntCombination {\n }\n\n static class CachedPow {\n private int[] first;\n private int[] second;\n private int mod;\n private int powMod;\n private static int step = 16;\n private static int limit = 1 << step;\n private static int mask = limit - 1;\n\n public CachedPow(int x, int mod) {\n this.mod = mod;\n this.powMod = mod - 1;\n first = new int[limit];\n second = new int[Integer.MAX_VALUE / limit + 1];\n first[0] = 1;\n for (int i = 1; i < first.length; i++) {\n first[i] = (int) ((long) x * first[i - 1] % mod);\n }\n second[0] = 1;\n long step = (long) x * first[first.length - 1] % mod;\n for (int i = 1; i < second.length; i++) {\n second[i] = (int) (second[i - 1] * step % mod);\n }\n }\n\n public int pow(int exp) {\n return (int) ((long) first[exp & mask] * second[exp >> step] % mod);\n }\n\n public int inverse(int exp) {\n return pow(DigitUtils.negate(exp, powMod));\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics"], "code_uid": "c67c91de1f7f5b4d09b8e0d672525d38", "src_uid": "cec37432956bb0a1ce62a0188fe2d805", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n/**\n *\n * @author Antonio \"Teo\" Alurralde\n */\npublic class Main {\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n int n = Integer.parseInt(br.readLine());\n int m = Integer.parseInt(br.readLine());\n int bs = n;\n int sum = 0;\n int max = 0;\n int a, min;\n while(n-->0) {\n a = Integer.parseInt(br.readLine());\n sum += a;\n max = Math.max(max, a);\n }\n min = Math.max((sum+m)/bs + ((sum+m)%bs>0?1:0), max);\n System.out.printf(\"%d %d\", min, max + m);\n }\n}\n", "lang_cluster": "Java", "tags": ["implementation", "binary search"], "code_uid": "067e7142d6221287c515c36188b6e4b1", "src_uid": "78f696bd954c9f0f9bb502e515d85a8d", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\n\npublic class D {\n\tfinal long MOD = (long)(1e9+7);\n\tlong p,k;\n\tvoid readInput() throws NumberFormatException, IOException{\n\t\t//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tScanner sc = new Scanner(System.in);\n\t\tp = sc.nextLong();\n\t\tk = sc.nextLong();\n\t}\n\t\n\tpublic static long powmod(long a, long x, long n){\n\t\tlong res = 1;\n\t\ta = a % n;\n\t\twhile(x>0){\n\t\t\tif ( x % 2 == 1)\n\t\t\t\tres = (res*a) %n;\n\t\t\ta = (a*a) %n;\n\t\t\tx = x >> 1;\n\t\t}\n\t\treturn res;\n\t}\t\n\t\n\tvoid solve(){\n\t\tlong ssol = 0;\n\t\tif (k==0)\n\t\t\tssol = powmod(p, p-1, MOD);\n\t\telse if (k==1)\n\t\t\tssol = powmod(p, p, MOD);\t\t\n\t\telse {\t\t\n\t\t\tint ord = 1;\n\t\t\tlong q = k;\n\t\t\twhile(q!=1)\n\t\t\t{\n\t\t\t\tq = (q*k) % p;\n\t\t\t\tif (q<0) q+= p;\n\t\t\t\tord++;\n\t\t\t}\n\t\t\tssol = powmod(p, (p-1)/ord, MOD);\t\t\n\t\t}\t\t\n\t\tSystem.out.println(ssol);\n\t}\n\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\t\tD a = new D();\n\t\ta.readInput();\n\t\ta.solve();\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["dsu", "math", "combinatorics", "number theory"], "code_uid": "6248d9acd8833a7509763376f19281dd", "src_uid": "580bf65af24fb7f08250ddbc4ca67e0e", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n\tpublic static void main(String args[]) {new Main().run();}\n\n\tFastReader in = new FastReader();\n\tPrintWriter out = new PrintWriter(System.out);\n\tvoid run(){\n\t\twork();\n\t\tout.flush();\n\t}\n\tlong mod=1000000007;\n\tlong gcd(long a,long b) {\n\t\treturn b==0?a:gcd(b,a%b);\n\t}\n\tvoid work() {\n\t\tint n=in.nextInt();\n\t\tint m=in.nextInt();\n\t\tlong r1=2,r0=2;\n\t\tfor(int i=1;i=v) {\n\t\t\treturn find(v,node.lNode,l,m);\n\t\t}else {\n\t\t\treturn find(v-node.lNode.cnt,node.rNode,m+1,r);\n\t\t}\n\t}\n\tprivate void insert(int v, Node node, int l, int r) {\n\t\tnode.cnt++;\n\t\tif(l==r)return;\n\t\tif(node.lNode==null)node.lNode=new Node(0);\n\t\tif(node.rNode==null)node.rNode=new Node(0);\n\t\tint m=(l+r)/2;\n\t\tif(v<=m) {\n\t\t\tinsert(v,node.lNode,l,m);\n\t\t}else {\n\t\t\tinsert(v,node.rNode,m+1,r);\n\t\t}\n\t}\n\n\tclass Node{\n\t\tNode lNode;\n\t\tNode rNode;\n\t\tint cnt;\n\t\tNode(int c){\n\t\t\tcnt=c;\n\t\t}\n\t}\n}\n\n\n\nclass FastReader\n{\n\tBufferedReader br;\n\tStringTokenizer st;\n\n\tpublic FastReader()\n\t{\n\t\tbr=new BufferedReader(new InputStreamReader(System.in));\n\t}\n\n\tpublic String next() \n\t{\n\t\tif(st==null || !st.hasMoreElements())\n\t\t{\n\t\t\ttry {\n\t\t\t\tst = 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 st.nextToken();\n\t}\n\n\tpublic int nextInt() \n\t{\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tpublic long nextLong()\n\t{\n\t\treturn Long.parseLong(next());\n\t}\n}", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics"], "code_uid": "0acfe094a43f87a9b7fde790627e30aa", "src_uid": "0f1ab296cbe0952faa904f2bebe0567b", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.*;\nimport java.io.*;\npublic class codeforces {\n public static void main(String[] args) throws Exception {\n Scanner in=new Scanner(System.in);\n int A=in.nextInt();\n int B=in.nextInt();\n int C=in.nextInt();\n int N=in.nextInt();\n int k=N-(A+B-C);\n if(k<1 || C>A || C>B)\n System.out.println(\"-1\");\n else{\n System.out.println(k);\n }\n \n in.close();\n return;\n }\n}\n\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "a15d3a9248cc01445c05def0e9e1826e", "src_uid": "959d56affbe2ff5dd999a7e8729f60ce", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\npublic class B {\n\tpublic static void main(String args[]) throws Exception{\n\t\tlong w = readLong();\n\t\tlong m = readLong();\n\t\tlong k = readLong();\n\t\tw /= k;\n\t\tlong ans = 0;\n\t\twhile(true){\n\t\t\tint s = Long.toString(m).length();\n\t\t\tlong numb = (long) Math.pow(10, s);\n\t\t\tlong a = numb-m;\n\t\t\tif(a*s < w){\n\t\t\t\tw -= a*s;\n\t\t\t\tm = numb;\n\t\t\t\tans += a;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tans+= (w/(s));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n\tstatic BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));\n\tstatic StringTokenizer st = new StringTokenizer(\" \");\n\tstatic String readString() throws Exception{\n\t\twhile(!st.hasMoreTokens()){\n\t\t\tst = new StringTokenizer(stdin.readLine());\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\tstatic int readInt() throws Exception {\n\t\treturn Integer.parseInt(readString());\n\t}\n\tstatic long readLong() throws Exception {\n\t\treturn Long.parseLong(readString());\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation", "binary search"], "code_uid": "8bc886b7f36e5117a79a8e791aaec399", "src_uid": "8ef8a09e33d38a2d7f023316bc38b6ea", "difficulty": 1600.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\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t\t// your code goes here\n\t\tMyScanner sc = new MyScanner();\n long n = sc.nextLong();\n long a = sc.nextLong();\n long b = sc.nextLong();\n long p = sc.nextLong();\n long q = sc.nextLong();\n long LCD = a * b / GCD(a, b);\n //System.out.println(a * b + \" \" + GCD(a,b));\n //System.out.println(LCD);\n long res = (n / a) * p + (n / b) * q;\n if (p > q){\n res -= q * (n / LCD);\n }else{\n res -= p * (n / LCD);\n }\n System.out.println(res);\n\t}\n\n public static long GCD(long a, long b){\n while (a > 0){\n long t = a;\n a = b % a;\n b = t;\n }\n return b;\n }\n\t //-----------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 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", "implementation", "number theory"], "code_uid": "846d27e72665be1d9bdbfe5e2bcf850a", "src_uid": "35d8a9f0d5b5ab22929ec050b55ec769", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\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 void solve() throws IOException {\n int n = readInt();\n int m = readInt();\n int all = readInt();\n int k = readInt();\n boolean[][] alt = new boolean[n][m];\n while (all-- > 0) {\n alt[readInt() - 1][readInt() - 1] = true;\n }\n int ans = 0;\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n for (int i1 = i; i1 < n; i1++) {\n for (int j1 = j; j1 < m; j1++) {\n int cnt = 0;\n for (int ii = i; ii <= i1; ii++) {\n for (int jj = j; jj <= j1; jj++) {\n if (alt[ii][jj]) cnt++;\n }\n }\n if (cnt >= k) {\n ans++;\n }\n }\n }\n }\n }\n out.println(ans);\n\n }\n\n\n}", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "a7e0d97402bb3683d88beef9d8dbbf11", "src_uid": "9c766881f6415e2f53fb43b61f8f40b4", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/**\n * @(#)Game.java\n *\n *\n * @author \n * @version 1.00 2016/8/24\n */\n\nimport java.util.Scanner;\npublic class Game {\n\tpublic static void main(String[] args){\n\t\tScanner mch = new Scanner(System.in);\n\t\tlong a = mch.nextLong();\n\t\ta = a%2;\n\t\tSystem.out.print(2-a);\n\t}\n \n \n \n}", "lang_cluster": "Java", "tags": ["math", "games"], "code_uid": "7ed0b7b2b8b473e8ca3659de58dfc189", "src_uid": "816ec4cd9736f3113333ef05405b8e81", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class JavaApplication2 {\n public static void main(String[] args) {\n char []a,s;\n Scanner f=new Scanner(System.in);\n String g;\n g=f.next();\n a=new char[g.length()];\n for(int i=0;i= m)) {\n\t\t\t\tans = (i-n)*60 + a-m; \n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif(n == 23 && m > 32)\n\t\t\tans = 60 - m;\n\t\t\n\t\tSystem.out.println(ans);\n\n\t\tin.close();\n\t}\n}", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "a4a7e785874e3a8ca6b2eb230b3c27ce", "src_uid": "3ad3b8b700f6f34b3a53fdb63af351a5", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class CodeForces {\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tif (n < 0) {\n\t\t\tn = -n;\n\t\t}\n\n\t\tint next = 1;\n\n\t\twhile (n > 0 || n % 2 == -1) {\n\t\t\tn -= next;\n\t\t\t++next;\n\t\t}\n\n\t\tSystem.out.println(next - 1);\n\t\tin.close();\n\t}\n}", "lang_cluster": "Java", "tags": ["math"], "code_uid": "f6f76fb1e4d000ab2cd670f44f370771", "src_uid": "18644c9df41b9960594fdca27f1d2fec", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.lang.reflect.Array;\nimport java.util.*;\n\npublic class Main implements Runnable {\n\n\n long m = (int)1e9+7;\n PrintWriter w;\n ArrayList prime;\n boolean is_prime[];\n InputReader c;\n public void run() {\n c = new InputReader(System.in);\n w = new PrintWriter(System.out);\n\n int n = c.nextInt();\n int m = c.nextInt();\n\n int[] seq = scanArrayI(n);\n int[] fin = scanArrayI(m);\n \n for(int i = 0; i < n; i++){\n for(int j = 0; j < m; j++){\n if(seq[i] == fin[j]){\n w.print(fin[j] + \" \");\n }\n }\n }\n w.close();\n }\n\n private String removeSpaces(int[] a){\n\n StringBuffer s = new StringBuffer();\n\n for(int i = 0; i < 26; i++){\n\n s.append(a[i] + \"\");\n\n }\n return s.toString();\n }\n\n\n\n\n static long gcd(long a, long b) {\n if (b == 0)\n return a;\n return gcd(b, a % b);\n }\n void sieve(int n) {\n is_prime = new boolean[n+10];\n prime = new ArrayList<>();\n for(int i=2;i<=n;i++)\n is_prime[i] = true;\n\n for (int i = 2; i <= n; ++i) {\n if (is_prime[i]) prime.add(i);\n for (int j = 0; j < prime.size () && i * prime.get(j) < n; ++j) {\n is_prime[i * prime.get(j)] = false;\n if (i % prime.get(j) == 0) break;\n }\n }\n }\n public static void sortbyColumn(int arr[][], int col){\n Arrays.sort(arr, new Comparator()\n {\n public int compare(int[] o1, int[] o2){\n return(Integer.valueOf(o1[col]).compareTo(o2[col]));\n }\n });\n\n }\n public static class DJSet {\n public int[] upper;\n\n public DJSet(int n) {\n upper = new int[n];\n Arrays.fill(upper, -1);\n }\n\n public int root(int x) {\n return upper[x] < 0 ? x : (upper[x] = root(upper[x]));\n }\n\n public boolean equiv(int x, int y) {\n return root(x) == root(y);\n }\n\n public boolean union(int x, int y) {\n x = root(x);\n y = root(y);\n if (x != y) {\n if (upper[y] < upper[x]) {\n int d = x;\n x = y;\n y = d;\n }\n upper[x] += upper[y];\n upper[y] = x;\n }\n return x == y;\n }\n }\n public static int[] radixSort(int[] f) {\n int[] to = new int[f.length];\n {\n int[] b = new int[65537];\n for(int i = 0;i < f.length;i++)b[1+(f[i]&0xffff)]++;\n for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n for(int i = 0;i < f.length;i++)to[b[f[i]&0xffff]++] = f[i];\n int[] d = f; f = to;to = d;\n }\n {\n int[] b = new int[65537];\n for(int i = 0;i < f.length;i++)b[1+(f[i]>>>16)]++;\n for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n for(int i = 0;i < f.length;i++)to[b[f[i]>>>16]++] = f[i];\n int[] d = f; f = to;to = d;\n }\n return f;\n }\n public void printArray(int[] a){\n for(int i=0;i= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n }\n catch (IOException e) {\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 String str = \"\";\n try {\n str = br.readLine();\n }\n catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n public int nextInt() {\n int c = read();\n\n while(isSpaceChar(c))\n c = read();\n\n int sgn = 1;\n\n if (c == '-') {\n sgn = -1;\n c = read();\n }\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 }\n while (!isSpaceChar(c));\n\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\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 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\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 }\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 String next() {\n return readString();\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n }\n public static void main(String args[]) throws Exception {\n new Thread(null, new Main(),\"Main\",1<<26).start();\n }\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "a1e1d88308ea08b7a3d29b500f46c96f", "src_uid": "f9044a4b4c3a0c2751217d9b31cd0c72", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport static java.lang.Math.*;\nimport static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.Double.parseDouble;\nimport static java.lang.String.*;\n \npublic class Main {\n \n public static void main(String[] args) throws IOException {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n StringBuilder out = new StringBuilder();\n StringTokenizer tk;\n \n String s = in.readLine();\n int x=101,y=101;\n int [][] v = new int[205][205];\n v[x][y] = 1;\n \n for(int i=0; i1) System.out.println(\"BUG\");\n else System.out.println(\"OK\");\n }\n \n} \n", "lang_cluster": "Java", "tags": ["constructive algorithms", "implementation", "graphs"], "code_uid": "4d5dc4a33e8ed9f686a5eb8cb3b097dd", "src_uid": "bb7805cc9d1cc907b64371b209c564b3", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "\nimport java.util.*;\n\n\npublic class Main {\n\t\n\tstatic int[] dp=new int[20000];\n\tstatic int[][] grid=new int[4][4];\n\tstatic int same(int pos, int dir)\n\t{\n\t\tint cross=0, circle=0;\n\t\tif (dir==1)\n\t\t{\n\t\t\tfor (int i=0; i<3; i++)\n\t\t\t\tif (grid[pos][i]==0)\n\t\t\t\t\treturn 0;\n\t\t\t\telse if (grid[pos][i]==1)\n\t\t\t\t\tcross++;\n\t\t\t\telse \n\t\t\t\t\tcircle++;\n\t\t\tif (cross==3)\n\t\t\t\treturn 1;\n\t\t\tif (circle==3)\n\t\t\t\treturn 2;\n\t\t\treturn 0;\n\t\t}\n\t\telse if (dir==2)\n\t\t{\n\t\t\tfor (int i=0; i<3; i++)\n\t\t\t\tif (grid[i][pos]==0)\n\t\t\t\t\treturn 0;\n\t\t\t\telse if (grid[i][pos]==1)\n\t\t\t\t\tcross++;\n\t\t\t\telse \n\t\t\t\t\tcircle++;\n\t\t\tif (cross==3)\n\t\t\t\treturn 1;\n\t\t\tif (circle==3)\n\t\t\t\treturn 2;\n\t\t\treturn 0;\n\t\t}\n\t\telse if (dir==3)\n\t\t{\n\t\t\tfor (int i=0; i<3; i++)\n\t\t\t\tif (grid[i][i]==0)\n\t\t\t\t\treturn 0;\n\t\t\t\telse if (grid[i][i]==1)\n\t\t\t\t\tcross++;\n\t\t\t\telse \n\t\t\t\t\tcircle++;\n\t\t\tif (cross==3)\n\t\t\t\treturn 1;\n\t\t\tif (circle==3)\n\t\t\t\treturn 2;\n\t\t\treturn 0;\n\t\t}\n\t\telse if (dir==4)\n\t\t{\n\t\t\tfor (int i=0; i<3; i++)\n\t\t\t\tif (grid[i][2-i]==0)\n\t\t\t\t\treturn 0;\n\t\t\t\telse if (grid[i][2-i]==1)\n\t\t\t\t\tcross++;\n\t\t\t\telse \n\t\t\t\t\tcircle++;\n\t\t\tif (cross==3)\n\t\t\t\treturn 1;\n\t\t\tif (circle==3)\n\t\t\t\treturn 2;\n\t\t\treturn 0;\n\t\t}\n\t\treturn 0;\n\t}\n\tstatic int win()\n\t{\n\t\tfor (int i=0; i<3; i++)\n\t\t{\n\t\t\tint temp=same(i, 1);\n\t\t\tif (temp>0)\n\t\t\t\treturn temp;\n\t\t\ttemp=same(i, 2);\n\t\t\tif (temp>0)\n\t\t\t\treturn temp;\n\t\t}\n\t\tint temp=same(0, 3);\n\t\tif (temp>0)\n\t\t\treturn temp;\n\t\ttemp=same(0, 4);\n\t\tif (temp>0)\n\t\t\treturn temp;\n\t\treturn 0;\n\t}\n\t\n\tstatic void fill(int cnt, int next)\n\t{\n\t\tif (dp[cnt]>0)\n\t\t\treturn;\n\t\tint temp=win();\n\t\tif (temp>0)\n\t\t{\n\t\t\tdp[cnt]=temp+2;\n\t\t\treturn;\n\t\t}\n\t\telse\n\t\t\tdp[cnt]=next;\n\t\t/*\n\t\tif (cnt==7)\n\t\t\tSystem.out.println(cnt+\" \"+next);\n\t\t*/\n\t\tint flag=1;\n\t\tint tag=0;\n\t\tfor (int i=0; i<3; i++)\n\t\t\tfor (int j=0; j<3; j++)\n\t\t\t{\n\t\t\t\tif (grid[i][j]==0)\n\t\t\t\t{\n\t\t\t\t\tgrid[i][j]=next;\n\t\t\t\t\tfill(cnt+flag*next, 3-next);\n\t\t\t\t\tgrid[i][j]=0;\n\t\t\t\t\ttag=1;\n\t\t\t\t}\n\t\t\t\tflag*=3;\n\t\t\t}\n\t\tif (tag==0)\n\t\t\tdp[cnt]=5;\n\t\t\t\n\t}\n\t\n\tpublic static void main(String[] args)\n\t{\n\t\t\n\t\tScanner cin=new Scanner(System.in);\n\t\tString temp;\n\t\t\n\t\tfor (int i=0; i<3; i++)\n\t\t\tfor (int j=0; j<3; j++)\n\t\t\t\tgrid[i][j]=0;\n\t\tfill(0, 1);\n\t\t\n\t\tint flag=1, cnt=0;\n\t\tfor (int i=0; i<3; i++)\n\t\t{\n\t\t\ttemp=cin.next();\n\t\t\tfor (int j=0; j<3; j++)\n\t\t\t{\n\t\t\t\tif (temp.charAt(j)=='X')\n\t\t\t\t\tcnt+=flag;\n\t\t\t\telse if (temp.charAt(j)=='0')\n\t\t\t\t\tcnt+=2*flag;\n\t\t\t\tflag*=3;\n\t\t\t}\n\t\t}\n\t//\tSystem.out.println(cnt);\n\t\tif (dp[cnt]==0)\n\t\t\tSystem.out.println(\"illegal\");\n\t\telse if (dp[cnt]==1)\n\t\t\tSystem.out.println(\"first\");\n\t\telse if (dp[cnt]==2)\n\t\t\tSystem.out.println(\"second\");\n\t\telse if (dp[cnt]==3)\n\t\t\tSystem.out.println(\"the first player won\");\n\t\telse if (dp[cnt]==4)\n\t\t\tSystem.out.println(\"the second player won\");\n\t\telse if (dp[cnt]==5)\n\t\t\tSystem.out.println(\"draw\");\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["brute force", "implementation", "games"], "code_uid": "c741a4455d90c7ba147bddcaee1e9f7e", "src_uid": "892680e26369325fb00d15543a96192c", "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.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 */\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 CGourmetCat solver = new CGourmetCat();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class CGourmetCat {\n public void solve(int testNumber, InputReader sc, OutputWriter out) {\n long aa = sc.nextLong();\n long bb = sc.nextLong();\n long cc = sc.nextLong();\n long ans = 0;\n for (int i = 1; i <= 7; i++) {\n long x = aa / 3;\n long y = bb / 2;\n long z = cc / 2;\n long min = Math.min(Math.min(x, y), z);\n long div = min;\n long a = aa - div * 3;\n long b = bb - div * 2;\n long c = cc - div * 2;\n long day = (long) i;\n long spent = div * 7;\n long food = a + b + c;\n while (food > 0) {\n long curr = day % 7;\n if (curr == 0)\n curr = 7;\n if (curr == 1 || curr == 2 || curr == 5) {\n if (a == 0)\n break;\n a--;\n } else if (curr == 3 || curr == 7) {\n if (b == 0)\n break;\n b--;\n } else {\n if (c == 0)\n break;\n c--;\n }\n day++;\n spent++;\n food--;\n }\n if (spent > ans)\n ans = spent;\n }\n out.println(ans);\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 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 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", "implementation"], "code_uid": "2662f251102ef4623d5b90eb5841ee92", "src_uid": "e17df52cc0615585e4f8f2d31d2daafb", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class comp {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\n\t\tint sum = 0;\n\t\tboolean flag1 = true;\n\t\tboolean flag2 = true;\n\t\tboolean flag3 = true;\n\t\tboolean flag4 = true;\n\t\tboolean flag5 = true;\n\t\tboolean flag6 = true;\n\t\tboolean flag7 = true;\n\t\tboolean flag8 = true;\n\n\t\tfor (int i = 0; i < 8; i++) {\n\n\t\t\tString s = sc.nextLine();\n\t\t\tboolean flag = true;\n\t\t\tfor (int k = 0; k < 8 && flag == true; k++) {\n\t\t\t\tif (s.charAt(k) != 'B') {\n\t\t\t\t\tflag = false;\n\t\t\t\t}\n\t\t\t\tif (s.charAt(k) == 'B' && k == 7) {\n\t\t\t\t\tsum++;\n\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t\tfor (int j = 1; j <= 8; j++) {\n\t\t\t\tif (s.charAt((j - 1)) != 'B') {\n\t\t\t\t\tif (j == 1) {\n\t\t\t\t\t\tflag1 = false;\n\t\t\t\t\t} else if (j == 2) {\n\t\t\t\t\t\tflag2 = false;\n\t\t\t\t\t} else if (j == 3) {\n\t\t\t\t\t\tflag3 = false;\n\t\t\t\t\t} else if (j == 4) {\n\t\t\t\t\t\tflag4 = false;\n\t\t\t\t\t} else if (j == 5) {\n\t\t\t\t\t\tflag5 = false;\n\t\t\t\t\t} else if (j == 6) {\n\t\t\t\t\t\tflag6 = false;\n\t\t\t\t\t} else if (j == 7) {\n\t\t\t\t\t\tflag7 = false;\n\t\t\t\t\t} else if (j == 8) {\n\t\t\t\t\t\tflag8 = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t}\n\t\tif (flag1 == true) {\n\t\t\tsum++;\n\t\t}\n\t\tif (flag2 == true) {\n\t\t\tsum++;\n\t\t}\n\t\tif (flag3 == true) {\n\t\t\tsum++;\n\t\t}\n\t\tif (flag4 == true) {\n\t\t\tsum++;\n\t\t}\n\n\t\tif (flag5 == true) {\n\t\t\tsum++;\n\t\t}\n\t\tif (flag6 == true) {\n\t\t\tsum++;\n\t\t}\n\t\tif (flag7 == true) {\n\t\t\tsum++;\n\t\t}\n\t\tif (flag8 == true) {\n\t\t\tsum++;\n\t\t}\n\t\tif (sum == 16) {\n\t\t\tSystem.out.println(8);\n\t\t} else {\n\t\t\tSystem.out.println(sum);\n\t\t}\n\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["brute force", "constructive algorithms"], "code_uid": "df0d036dfee972fb96adf5362c2a187e", "src_uid": "8b6ae2190413b23f47e2958a7d4e7bc0", "difficulty": 1100.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 String s = sc.next();\n\t int n = s.length();\n\t int c1 = 0;\n\t int c2 = 0;\n\t char c[] = s.toCharArray();\n\t for(int i=0;i= 0 && dx < 8 && dy < 8 && dy >= 0)\n\t\t\t\tboard[dx][dy] = true;\n\t\t}\n\t\tint counter = 0;\n\t\tfor (int i = 0; i < 8; i++)\n\t\t\tfor (int j = 0; j < 8; j++)\n\t\t\t\tif (!board[i][j] && check(board, i, j, row, col))\n\t\t\t\t\tcounter++;\n\n\t\tSystem.out.println(counter);\n\n\t}\n\n\tprivate static boolean check(boolean[][] board, int x, int y, int row,\n\t\t\tint col) {\n\t\tfor (int i = 0; i < shift.length - 1; i += 2) {\n\t\t\tint dx = x + shift[i];\n\t\t\tint dy = y + shift[i + 1];\n\t\t\tif (dx == row && dy == col)\n\t\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n}\n", "lang_cluster": "Java", "tags": ["brute force", "math", "implementation"], "code_uid": "2ceed1a18e0468554101eab98e6cc714", "src_uid": "073023c6b72ce923df2afd6130719cfc", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.lang.*;\nimport java.util.regex.*;\npublic class Myclass {\n\tstatic long a[]=new long [10000];\n\tstatic long power(long n,long m)\n\t{\n\t\tlong ans=1,x=2;\n\t\twhile(n>0)\n\t\t{\n\t\t\tif(n%2==1)\n\t\t\t{\n\t\t\t\tans=ans*x;\n\t\t\t\tn--;\n\t\t\t}\n\t\t\tif(x>m && n>0)\n\t\t\t\treturn -1;\n\t\t\t//System.out.println(ans);\n\t\t\tx=x*x;\n\t\t\tn/=2;\n\t\t}\n\t\t//System.out.println(ans);\n\t\treturn m%ans;\n\t}\n\tpublic static void main(String[] args) {\n\t\t\n\t\tInputReader in = new InputReader(System.in);\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\tlong n=in.nextLong();\n\t\tlong m=in.nextLong();\n\t\tif(m/2= snumChars) \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\tsnumChars = 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\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 {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c)) \n\t\t\t{\n\t\t\t\tc = snext();\n\t\t\t}\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-')\n\t\t {\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{\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 {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c)) \n\t\t\t{\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{\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{\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{\n\t\t\tint a[] = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) \n\t\t\t{\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 {\n\t\t\tint c = snext();\n\t\t\twhile (isSpaceChar(c)) \n\t\t\t{\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{\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{\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{\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{\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{\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t}\n\n\t\tpublic interface SpaceCharFilter\n\t {\n\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t}\n\t\tpublic static long mod = 1000000007;\n\t\tpublic static int d;\n\t\tpublic static int p;\n\t\tpublic static int q;\n\t\t\n\t\tpublic static int[] suffle(int[] a,Random gen)\n\t\t{\n\t\t\tint n = a.length;\n\t\t\tfor(int i=0;i primeFactorization(int n)\n\t\t{\n\t\t\tHashSet a =new HashSet();\n\t\t\tfor(int i=2;i*i<=n;i++)\n\t\t\t{\n\t\t\t\twhile(n%i==0)\n\t\t\t\t{\n\t\t\t\t\ta.add(i);\n\t\t\t\t\tn/=i;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(n!=1)\n\t\t\t\ta.add(n);\n\t\t\treturn a;\n\t\t}\n\t\t\n\t\tpublic static void sieve(boolean[] isPrime,int n)\n\t\t{\n\t\t\tfor(int i=1;i0)\n\t\t {\n\t\t if(n % 2 ==1)\n\t\t result=result * x;\n\t\t x=x*x;\n\t\t n=n/2;\n\t\t }\n\t\t return result;\n\t\t}\n\t\t\n\t\tpublic static long binaryExponentiation(long x,long n)\n\t\t{\n\t\t long result=1;\n\t\t while(n>0)\n\t\t {\n\t\t if(n % 2 ==1)\n\t\t result=result * x;\n\t\t x=x*x;\n\t\t n=n/2;\n\t\t }\n\t\t return result;\n\t\t}\n\t\t\n\t\tpublic static int modularExponentiation(int x,int n,int M)\n\t\t{\n\t\t int result=1;\n\t\t while(n>0)\n\t\t {\n\t\t if(n % 2 ==1)\n\t\t result=(result * x)%M;\n\t\t x=(x*x)%M;\n\t\t n=n/2;\n\t\t }\n\t\t return result;\n\t\t}\n\t\t\n\t\tpublic static long modularExponentiation(long x,long n,long M)\n\t\t{\n\t\t long result=1;\n\t\t while(n>0)\n\t\t {\n\t\t if(n % 2 ==1)\n\t\t result=(result * x)%M;\n\t\t x=(x*x)%M;\n\t\t n=n/2;\n\t\t }\n\t\t return result;\n\t\t}\n\t\t\n\t\tpublic static int modInverse(int A,int M)\n\t\t{\n\t\t return modularExponentiation(A,M-2,M);\n\t\t}\n\t\t\n\t\tpublic static long modInverse(long A,long M)\n\t\t{\n\t\t return modularExponentiation(A,M-2,M);\n\t\t}\n\t\t\n\t\tpublic static boolean isPrime(int n)\n\t\t{\n\t\t \n\t\t if (n <= 1) return false;\n\t\t if (n <= 3) return true;\n\t\t \n\t\t if (n%2 == 0 || n%3 == 0) \n\t\t \treturn false;\n\t\t \n\t\t for (int i=5; i*i<=n; i=i+6)\n\t\t {\n\t\t if (n%i == 0 || n%(i+2) == 0)\n\t\t return false;\n\t\t }\n\t\t \n\t\t return true;\n\t\t}\n\t\t\n\t\tstatic class pair implements Comparable\n\t\t{\n\t\t\tLong x, y;\n\t\t\tpair(long x,long y)\n\t\t\t{\n\t\t\t\tthis.x=x;\n\t\t\t\tthis.y=y;\n\t\t\t}\n\t\t\t\n\t\t\tpublic int compareTo(pair o) {\n\t\t\t\tint result = x.compareTo(o.x);\n\t\t\t\tif(result==0)\n\t\t\t\t\tresult = y.compareTo(o.y);\n\t\t\t\t\n\t\t\t\treturn result;\n\t\t\t} \n\t\t\t\n\t\t\tpublic String toString()\n\t\t\t{\n\t\t\t\treturn x+\" \"+y;\n\t\t\t}\n\t\t\t\n\t\t\tpublic boolean equals(Object o)\n\t\t\t{\n\t\t\t\tif (o instanceof pair)\n\t\t\t {\n\t\t\t\t\tpair p = (pair)o;\n\t\t\t\t\treturn p.x == x && p.y == y ;\n\t\t\t\t}\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\t\n\t\t\tpublic int hashCode()\n\t\t\t{\n\t\t\t\treturn new Long(x).hashCode()*31 + new Long(y).hashCode();\n\t\t\t}\n\t\t}\n}\n\t", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "46d13dc3f73579eadeab2bcae8b5dfcb", "src_uid": "c649052b549126e600691931b512022f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Main {\n\tstatic 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\t\n\tstatic class time implements Comparable