{"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class Main{\npublic static void main(String args[])\n{\n Scanner sc = new Scanner(System.in);\n int n,d,sum=0;\n n = sc.nextInt();\n d = sc.nextInt();\n int arr[] = new int[n];\n for(int i=0;i b)return true;\n else return false;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5abc358e809517c741cb72a5b09d5bfe", "src_uid": "ab003ab094931fc105384df9d144131e", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.math.*;\nimport java.lang.*;\nimport java.io.*;\npublic class Main{\n static class Reader\n {\n final private int BUFFER_SIZE = 1 << 16;\n private DataInputStream din;\n private byte[] buffer;\n private int bufferPointer, bytesRead;\n\n public Reader()\n {\n din = new DataInputStream(System.in);\n buffer = new byte[BUFFER_SIZE];\n bufferPointer = bytesRead = 0;\n }\n\n public Reader(String file_name) throws IOException\n {\n din = new DataInputStream(new FileInputStream(file_name));\n buffer = new byte[BUFFER_SIZE];\n bufferPointer = bytesRead = 0;\n }\n\n public String readLine() throws IOException\n {\n byte[] buf = new byte[64]; // line length\n int cnt = 0, c;\n while ((c = read()) != -1)\n {\n if (c == '\\n')\n break;\n buf[cnt++] = (byte) c;\n }\n return new String(buf, 0, cnt);\n }\n\n public int nextInt() throws IOException\n {\n int ret = 0;\n byte c = read();\n while (c <= ' ')\n c = read();\n boolean neg = (c == '-');\n if (neg)\n c = read();\n do\n {\n ret = ret * 10 + c - '0';\n } while ((c = read()) >= '0' && c <= '9');\n\n if (neg)\n return -ret;\n return ret;\n }\n\n public long nextLong() throws IOException\n {\n long ret = 0;\n byte c = read();\n while (c <= ' ')\n c = read();\n boolean neg = (c == '-');\n if (neg)\n c = read();\n do {\n ret = ret * 10 + c - '0';\n }\n while ((c = read()) >= '0' && c <= '9');\n if (neg)\n return -ret;\n return ret;\n }\n\n public double nextDouble() throws IOException\n {\n double ret = 0, div = 1;\n byte c = read();\n while (c <= ' ')\n c = read();\n boolean neg = (c == '-');\n if (neg)\n c = read();\n\n do {\n ret = ret * 10 + c - '0';\n }\n while ((c = read()) >= '0' && c <= '9');\n\n if (c == '.')\n {\n while ((c = read()) >= '0' && c <= '9')\n {\n ret += (c - '0') / (div *= 10);\n }\n }\n\n if (neg)\n return -ret;\n return ret;\n }\n\n private void fillBuffer() throws IOException\n {\n bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n if (bytesRead == -1)\n buffer[0] = -1;\n }\n\n private byte read() throws IOException\n {\n if (bufferPointer == bytesRead)\n fillBuffer();\n return buffer[bufferPointer++];\n }\n\n public void close() throws IOException\n {\n if (din == null)\n return;\n din.close();\n }\n }\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String s1 = sc.readLine();\n String s2 = sc.readLine();\n String s = \"\";\n for(int i = 0 ; i< s1.length() ; i++){\n if(s1.charAt(i) == s2.charAt(i)){\n s += 0;\n }\n else{\n s += 1;\n }\n }\n System.out.println(s);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "11890c1142f69f49974c778702fac318", "src_uid": "3714b7596a6b48ca5b7a346f60d90549", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class aedhf\n{\n\tstatic long x,s;\n\t\npublic static void step1(){\n\tif(s==0||x==0){\n\n\t\tstop();\n\t}else{\n\tstep2();\n\t}\n}\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner a1 = new Scanner(System.in);\n\t\t s=a1.nextLong();\n\t\t x=a1.nextLong();\n\t\tstep1();\n\t}\n\tpublic static void step2(){\n\t\tif (s>=2*x){\n\t\t\ts=s%(2*x);\n\t\t\t\n\t\t\tstep1();\n\t\t}else{\n\t\tstep3();\n\t\t}}\n\t\tpublic static void step3(){\n\t\t\tif(x>=2*s){\n\t\t\t\tx=x%(2*s);\n\t\t\t\tstep1();\n\t\t\t}else{\n\t\t\t\tstop();\n\t\t\t}\n\t\t}\n\tpublic static void stop(){\n\tSystem.out.println((long)s+\" \"+(long)x);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7d71e9fe7d7a9235ea1cc9f4817fedf5", "src_uid": "1f505e430eb930ea2b495ab531274114", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "public class qwe {\n private static int count(int n, String s) {\n int result;\n String maxString = \"\";\n\n StringBuilder sb = new StringBuilder();\n for (int i = 0; i < n; i++) {\n sb.append(s.charAt(i));\n if (s.startsWith(sb.toString() + sb.toString()) && sb.toString().length() > maxString.length()) {\n maxString = sb.toString();\n }\n }\n\n if (maxString.isEmpty() || maxString.length() == 1) {\n result = s.length();\n } else {\n result = s.length() - maxString.length() + 1;\n }\n\n return result;\n }\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n String s = in.next();\n\n int result = count(n, s);\n System.out.println(result);\n in.close();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ffb7222ac8c82da5196deca1bb02a74c", "src_uid": "ed8725e4717c82fa7cfa56178057bca3", "difficulty": 1400.0} {"lang": "Java 6", "source_code": "import java.io.*;\npublic class Main\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tnew Main().start(args[0]);\n\t}\n\tpublic void start() throws IOException\n\t{\n\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\tString inp=br.readLine();\n\t\tString ans=\"\";\n\t\tString low=inp.toLowerCase();\n\t\tfor(int i=0;i\n long t=Long.parseLong(str);\n System.out.println(t==1?\"-1\":t-t%2+\" 2\");\n }\n\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "703d9204ad4d99c20e25d6a96f1bbdf4", "src_uid": "883f67177474d23d7a320d9dbfa70dd3", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class shubh{\n public static void main(String args[])\n {\n Scanner s=new Scanner(System.in); \n \n int arr[]=new int[26];\n String str=s.next();\n for(int i=0;i strings = new Vector();\n for(char i : x){\n if(hash[(int)i-97]==0){\n if(count==k){\n temp+=i;\n continue;\n }\n if(temp.length()>0){z\n strings.add(temp);\n }\n temp=\"\";\n temp+=i;\n hash[(int)i-97]++;\n count++;\n \n }\n else{\n temp+=i;\n }\n }\n if(temp.length()>0){\n strings.add(temp);\n }\n if(countresult){\n result=count;\n count=1;\n }\n }\n }\n System.out.println(result);\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "39d089b5f94d6b67058da5c38ee62e66", "src_uid": "f30329023e84b4c50b1b118dc98ae73c", "difficulty": 800.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class Game{\n public static void main(String[] args){\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int[] a = new int[n];\n for(int i=0;imax)\n max=count;\n }\n }\n System.out.print(max);\n }\n } \n \n \n \n ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ec16c107528e87d9c092a425a5ccf4a9", "src_uid": "9b543e07e805fe1dd8fa869d5d7c8b99", "difficulty": 1200.0} {"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 \n int n = sc.nextInt();\n int[] blocks = new int[n];\n for (int i = 0; i < n; i++)\n {\n blocks[i] = sc.nextInt();\n }\n Arrays.sort(blocks);\n String result = \"\";\n for (int i = 0; i < n; i++)\n {\n x += blocks[i] + \" \";\n }\n System.out.println(result);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b60abbb5ebee56878d4519af891a0fb8", "src_uid": "ae20712265d4adf293e75d016b4b82d8", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class edu12_1\n{\n public static void main(String args[])throws IOException\n {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t Scanner sc = new Scanner(System.in);\n\t int a = sc.nextInt();\n\t int ta = sc.nextInt();\n\t \n\t int b = sc.nextInt();\n\t int tb = sc.nextInt();\n\t \n\t String s = br.readLine();\n\t \n\t \n\t int hr = Integer.parseInt(s.substring(0,2));\n\t int mins = Integer.parseInt(s.substring(3));\n\t \n\t //System.out.println(mins);\n\t int min_calcu = hr*60 + mins; \n\t //int time = min_calcu;\n\t int count = 0;\n \n\t\tint elapse_time = min_calcu + ta;\n\t \n\t for(int i = 5*60 ; i < 12*60 ; i=i+b)\n\t {\n\t\t int time = i + tb;\n\n if (time > min_calcu && elapse_time > i) \n\t\t\t\tcount++;\n\t }\n\t System.out.println(count);\n \n }\n\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "29fb0ed44708e3567190c2f34cd017bf", "src_uid": "1c4cf1c3cb464a483511a8a61f8685a7", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.awt.event.ActionEvent;\nimport java.awt.event.ActionListener;\nimport java.io.IOException;\n\nimport java.util.StringTokenizer;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.math.MathContext;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.TreeSet;\nimport java.util.*;\n\npublic class Main {\n\n \n public static void main(String[]args)\n {\n FastReader in=new FastReader();\n \n int n=in.nextInt();\n \n int a=in.nextInt();\n \n int b=in.nextInt();\n \n boolean[]x=new boolean[n];\n \n boolean[]y=new boolean[n];\n \n int i=0;\n \n StringBuilder sb=new StringBuilder();\n while(i max){\n\t max = count;\n\t res = ch;\n\t count = 0;\n\t }\n\t }\n\t if(res.equals(\"\"))res=s.substring(0,2);\n\t System.out.println(res);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bd86b80b2f2f0331f62f1d01d02b5524", "src_uid": "e78005d4be93dbaa518f3b40cca84ab1", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class Codeforces{\n static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n static StringTokenizer st;\n static String next(){\n while(st==null || !st.hasMoreElements()){\n try{\n st = new StringTokenizer(br.readLine().trim());\n \n }\n catch(Exception e){\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n static int nextInt(){\n return Integer.parseInt(next());\n }\n public static void main(String[] argh){\n int n, m, temp1=0, temp2, count = Integer.MAX_VLAUE;\n n = nextInt();\n m = nextInt();\n temp2 = n-1;\n int[] arr = new int[m];\n for(int i = 0; i < m; i++)arr[i] = nextInt();\n \n Arrays.sort(arr);\n \n for(int i = 0; temp2 < m; i++)\n {\n if(arr[temp2] - arr[temp1] < count)\n count = arr[temp2] - arr[temp1];\n \n temp1++;\n temp2++;\n }\n \n System.out.println(count);\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "de652447475b54d53267ff5073fb89a0", "src_uid": "7830aabb0663e645d54004063746e47f", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.util.ArrayList;\nimport java.util.Scanner;\n\npublic class CF_PetrolSum {\n\t\n\tpublic static void main(String args[])\n\t{\n\t\tScanner s=new Scanner(System.in);\n\t\tint num=s.nextInt();\n\t\tint[] rotations;\n\t\trotations=new int[num];\n\t\t\t\n\t\tfor(int i=0;i0)\n {\n sum+=(b+1);\n b--;\n }\n System.outprintln(sum);\n }\n \n else{\n \n while(b>0)\n {\n sum+=(b);\n b--;\n }\n System.out.println(sum+1);\n \n \n \n }\n \n \n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9a08f0c95b26ce662fc75eec9d875109", "src_uid": "6df251ac8bf27427a24bc23d64cb9884", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskB solver = new TaskB();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskB {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int k = in.nextInt();\n int max = answer(k - (k % 2), out);\n if (k % 2 == 1) out.print(\" \" + max);\n }\n\n int answer(int k, PrintWriter out) {\n int max = (k - 1) << 1;\n out.println((max * 3) + \" \" + 2);\n out.print(3 + \" \" + 2);\n return max * 3;\n }\n\n }\n\n static class InputReader {\n private int lenbuf = 0;\n private int ptrbuf = 0;\n private InputStream in;\n private byte[] inbuf = new byte[1024];\n\n public InputReader(InputStream in) {\n this.in = in;\n }\n\n private int readByte() {\n if (lenbuf == -1) throw new InputMismatchException();\n if (ptrbuf >= lenbuf) {\n ptrbuf = 0;\n try {\n lenbuf = in.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 public int nextInt() {\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 }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c8fe3236997d0b9f504e4a05bcfa3f08", "src_uid": "5c000b4c82a8ecef764f53fda8cee541", "difficulty": 1400.0} {"lang": "Java 6", "source_code": "pa\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class A {\n\n public static void main(String[] args) throws NumberFormatException, IOException {\n BufferedReader buf = new BufferedReader(\n new InputStreamReader(System.in));\n int n = Integer.parseInt(buf.readLine());\n n *= 2;\n int x = 1;\n boolean yes = false;\n while (x < n && !yes) {\n int y = x * (x + 1);\n int z = n - y;\n if (z < 0)\n break;\n int w = (int) Math.sqrt(z);\n if (w * (w + 1) == z)\n yes = true;\n x++;\n }\n if (yes)\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f0d0f98c2cbac3ca55f6dd0492a92f3a", "src_uid": "245ec0831cd817714a4e5c531bffd099", "difficulty": 1300.0} {"lang": "Java 7", "source_code": "\nimport java.util.Scanner;\npublic class D {\npublic static void main(String[] args){\n\tScanner scan = new Scanner(System.in);\n\tint n = scan.nextInt();\n\tint m =n ;\n\tint count=0;\n\tfor(int i =4;i<=n;i++){\n\t\tif (islucky(i)){count++;}\n\t}\n\tSystem.out.print(count);\n\tbreak;\n}\npublic static boolean islucky(int num){\n\tint a;\n\twhile (num!=0){\n\t\ta=num%10;\n\t\tif(a!=7&&a!=4){return false ;}\n\t\tnum/=10;\n\t}\n\treturn true;\n\t\n}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e1d6cbb3255c29d1120daea241568a84", "src_uid": "6a10bfe8b3da9c11167e136b3c6fb2a3", "difficulty": 1100.0} {"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\tScanner sc=new Scanner(System.in);\n\t\tint n,a,b,i,cola,bars,x=0,check=0;\n\t\tn=sc.nextInt();\n\t\ta=sc.nextInt();\n\t\tb=sc.nextInt();\n\t\tcheck=0;\n\t\tx=0;\n\t\tfor(i=0;a*i<=n;i++)\n\t\t{\n\t\t\tcola=a*i;\n\t\t\tif((n-cola)%b==0)\n\t\t\t{\n\t\t\t check=1;\n\t\t\t x=i;\n\t\t\t bars=(n-cola)/b;\n\t\t\t}\n\t\t}\n\t\tif(check==0)\n\t\tSystem.out.println(\"NO\");\n\t\telse\n\t\t{\n\t\tSystem.out.println(\"YES\");\n\t\tSystem.out.println(x+\" \"+bars);\n\t}}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "721687d1197d84886c53faf34244ed3d", "src_uid": "b031daf3b980e03218167f40f39e7b01", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.awt.*;\nimport java.io.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.util.List;\n\nimport static java.lang.Math.max;\nimport static java.lang.Math.min;\n\n\npublic class A implements Runnable{\n\n // SOLUTION!!!\n // HACK ME PLEASE IF YOU CAN!!!\n // PLEASE!!!\n // PLEASE!!!\n // PLEASE!!!\n\n private final static Random rnd = new Random();\n private final static String fileName = \"\";\n\n private void solve() {\n int n = readInt();\n if (n != 3 && n < 15) throw new RuntimeException();\n else out.println(n * 9);\n\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private final static boolean FIRST_INPUT_STRING = false;\n private final static boolean MULTIPLE_TESTS = true;\n private final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\n private final static int MAX_STACK_SIZE = 128;\n\n private final static boolean OPTIMIZE_READ_NUMBERS = false;\n\n /////////////////////////////////////////////////////////////////////\n\n public void run(){\n try{\n timeInit();\n Locale.setDefault(Locale.US);\n\n init();\n\n if (ONLINE_JUDGE) {\n solve();\n } else {\n do {\n try {\n timeInit();\n solve();\n time();\n\n out.println();\n } catch (NumberFormatException e) {\n break;\n } catch (NullPointerException e) {\n if (FIRST_INPUT_STRING) break;\n else throw e;\n }\n } while (MULTIPLE_TESTS);\n }\n\n out.close();\n time();\n }catch (Exception e){\n e.printStackTrace(System.err);\n System.exit(-1);\n }\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private BufferedReader in;\n private OutputWriter out;\n private StringTokenizer tok = new StringTokenizer(\"\");\n\n public static void main(String[] args){\n new Thread(null, new A(), \"\", MAX_STACK_SIZE * (1L << 20)).start();\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private void init() throws FileNotFoundException{\n Locale.setDefault(Locale.US);\n\n if (ONLINE_JUDGE){\n if (fileName.isEmpty()) {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new OutputWriter(System.out);\n } else {\n in = new BufferedReader(new FileReader(fileName + \".in\"));\n out = new OutputWriter(fileName + \".out\");\n }\n }else{\n in = new BufferedReader(new FileReader(\"input.txt\"));\n out = new OutputWriter(\"output.txt\");\n }\n }\n\n ////////////////////////////////////////////////////////////////\n\n private long timeBegin;\n\n private void timeInit() {\n this.timeBegin = System.currentTimeMillis();\n }\n\n private void time(){\n long timeEnd = System.currentTimeMillis();\n System.err.println(\"Time = \" + (timeEnd - timeBegin));\n }\n\n private void debug(Object... objects){\n if (ONLINE_JUDGE){\n for (Object o: objects){\n System.err.println(o.toString());\n }\n }\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private String delim = \" \";\n\n private String readLine() {\n try {\n return in.readLine();\n } catch (IOException e) {\n throw new RuntimeIOException(e);\n }\n }\n\n private String readString() {\n try {\n while(!tok.hasMoreTokens()){\n tok = new StringTokenizer(readLine());\n }\n\n return tok.nextToken(delim);\n } catch (NullPointerException e) {\n return null;\n }\n }\n\n /////////////////////////////////////////////////////////////////\n\n private final char NOT_A_SYMBOL = '\\0';\n\n private char readChar() {\n try {\n int intValue = in.read();\n\n if (intValue == -1){\n return NOT_A_SYMBOL;\n }\n\n return (char) intValue;\n } catch (IOException e) {\n throw new RuntimeIOException(e);\n }\n }\n\n private char[] readCharArray() {\n return readLine().toCharArray();\n }\n\n private char[][] readCharField(int rowsCount) {\n char[][] field = new char[rowsCount][];\n for (int row = 0; row < rowsCount; ++row) {\n field[row] = readCharArray();\n }\n\n return field;\n }\n\n /////////////////////////////////////////////////////////////////\n\n private long optimizedReadLong() {\n int sign = 1;\n long result = 0;\n boolean started = false;\n while (true) {\n try {\n int j = in.read();\n if (-1 == j) {\n if (started) return sign * result;\n throw new NumberFormatException();\n }\n\n if (j == '-') {\n if (started) throw new NumberFormatException();\n sign = -sign;\n }\n\n if ('0' <= j && j <= '9') {\n result = result * 10 + j - '0';\n started = true;\n } else if (started) {\n return sign * result;\n }\n } catch (IOException e) {\n throw new RuntimeIOException(e);\n }\n }\n }\n\n private int readInt() {\n\n if (!OPTIMIZE_READ_NUMBERS) {\n return Integer.parseInt(readString());\n } else {\n return (int) optimizedReadLong();\n }\n }\n\n private int[] readIntArray(int size) {\n int[] array = new int[size];\n\n for (int index = 0; index < size; ++index){\n array[index] = readInt();\n }\n\n return array;\n }\n\n private int[] readSortedIntArray(int size) {\n Integer[] array = new Integer[size];\n\n for (int index = 0; index < size; ++index) {\n array[index] = readInt();\n }\n Arrays.sort(array);\n\n int[] sortedArray = new int[size];\n for (int index = 0; index < size; ++index) {\n sortedArray[index] = array[index];\n }\n\n return sortedArray;\n }\n\n private int[] readIntArrayWithDecrease(int size) {\n int[] array = readIntArray(size);\n\n for (int i = 0; i < size; ++i) {\n array[i]--;\n }\n\n return array;\n }\n\n ///////////////////////////////////////////////////////////////////\n\n private int[][] readIntMatrix(int rowsCount, int columnsCount) {\n int[][] matrix = new int[rowsCount][];\n\n for (int rowIndex = 0; rowIndex < rowsCount; ++rowIndex) {\n matrix[rowIndex] = readIntArray(columnsCount);\n }\n\n return matrix;\n }\n\n private int[][] readIntMatrixWithDecrease(int rowsCount, int columnsCount) {\n int[][] matrix = new int[rowsCount][];\n\n for (int rowIndex = 0; rowIndex < rowsCount; ++rowIndex) {\n matrix[rowIndex] = readIntArrayWithDecrease(columnsCount);\n }\n\n return matrix;\n }\n\n ///////////////////////////////////////////////////////////////////\n\n private long readLong() {\n if (!OPTIMIZE_READ_NUMBERS) {\n return Long.parseLong(readString());\n } else {\n return optimizedReadLong();\n }\n }\n\n private long[] readLongArray(int size) {\n long[] array = new long[size];\n\n for (int index = 0; index < size; ++index){\n array[index] = readLong();\n }\n\n return array;\n }\n\n ////////////////////////////////////////////////////////////////////\n\n private double readDouble() {\n return Double.parseDouble(readString());\n }\n\n private double[] readDoubleArray(int size) {\n double[] array = new double[size];\n\n for (int index = 0; index < size; ++index){\n array[index] = readDouble();\n }\n\n return array;\n }\n\n ////////////////////////////////////////////////////////////////////\n\n private BigInteger readBigInteger() {\n return new BigInteger(readString());\n }\n\n private BigDecimal readBigDecimal() {\n return new BigDecimal(readString());\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private Point readPoint() {\n int x = readInt();\n int y = readInt();\n return new Point(x, y);\n }\n\n private Point[] readPointArray(int size) {\n Point[] array = new Point[size];\n\n for (int index = 0; index < size; ++index){\n array[index] = readPoint();\n }\n\n return array;\n }\n\n /////////////////////////////////////////////////////////////////////\n\n @Deprecated\n private List[] readGraph(int vertexNumber, int edgeNumber) {\n @SuppressWarnings(\"unchecked\")\n List[] graph = new List[vertexNumber];\n\n for (int index = 0; index < vertexNumber; ++index){\n graph[index] = new ArrayList<>();\n }\n\n while (edgeNumber-- > 0){\n int from = readInt() - 1;\n int to = readInt() - 1;\n\n graph[from].add(to);\n graph[to].add(from);\n }\n\n return graph;\n }\n\n private static class GraphBuilder {\n\n final int size;\n final List[] edges;\n\n static GraphBuilder createInstance(int size) {\n List[] edges = new List[size];\n for (int v = 0; v < size; ++v) {\n edges[v] = new ArrayList<>();\n }\n\n return new GraphBuilder(edges);\n }\n\n private GraphBuilder(List[] edges) {\n this.size = edges.length;\n this.edges = edges;\n }\n\n public void addEdge(int from, int to) {\n addDirectedEdge(from, to);\n addDirectedEdge(to, from);\n }\n\n public void addDirectedEdge(int from, int to) {\n edges[from].add(to);\n }\n\n public int[][] build() {\n int[][] graph = new int[size][];\n for (int v = 0; v < size; ++v) {\n List vEdges = edges[v];\n graph[v] = castInt(vEdges);\n }\n\n return graph;\n }\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static class IntIndexPair {\n\n static Comparator increaseComparator = new Comparator() {\n\n @Override\n public int compare(A.IntIndexPair indexPair1, A.IntIndexPair indexPair2) {\n int value1 = indexPair1.value;\n int value2 = indexPair2.value;\n\n if (value1 != value2) return value1 - value2;\n\n int index1 = indexPair1.index;\n int index2 = indexPair2.index;\n\n return index1 - index2;\n }\n };\n\n static Comparator decreaseComparator = new Comparator() {\n\n @Override\n public int compare(A.IntIndexPair indexPair1, A.IntIndexPair indexPair2) {\n int value1 = indexPair1.value;\n int value2 = indexPair2.value;\n\n if (value1 != value2) return -(value1 - value2);\n\n int index1 = indexPair1.index;\n int index2 = indexPair2.index;\n\n return index1 - index2;\n }\n };\n\n static IntIndexPair[] from(int[] array) {\n IntIndexPair[] iip = new IntIndexPair[array.length];\n for (int i = 0; i < array.length; ++i) {\n iip[i] = new IntIndexPair(array[i], i);\n }\n\n return iip;\n }\n\n int value, index;\n\n IntIndexPair(int value, int index) {\n super();\n this.value = value;\n this.index = index;\n }\n\n int getRealIndex() {\n return index + 1;\n }\n }\n\n private IntIndexPair[] readIntIndexArray(int size) {\n IntIndexPair[] array = new IntIndexPair[size];\n\n for (int index = 0; index < size; ++index) {\n array[index] = new IntIndexPair(readInt(), index);\n }\n\n return array;\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static class OutputWriter extends PrintWriter {\n\n final int DEFAULT_PRECISION = 12;\n\n private int precision;\n private String format, formatWithSpace;\n\n {\n precision = DEFAULT_PRECISION;\n\n format = createFormat(precision);\n formatWithSpace = format + \" \";\n }\n\n OutputWriter(OutputStream out) {\n super(out);\n }\n\n OutputWriter(String fileName) throws FileNotFoundException {\n super(fileName);\n }\n\n int getPrecision() {\n return precision;\n }\n\n void setPrecision(int precision) {\n precision = max(0, precision);\n this.precision = precision;\n\n format = createFormat(precision);\n formatWithSpace = format + \" \";\n }\n\n String createFormat(int precision){\n return \"%.\" + precision + \"f\";\n }\n\n @Override\n public void print(double d){\n printf(format, d);\n }\n\n void printWithSpace(double d){\n printf(formatWithSpace, d);\n }\n\n void printAll(double...d){\n for (int i = 0; i < d.length - 1; ++i){\n printWithSpace(d[i]);\n }\n\n print(d[d.length - 1]);\n }\n\n @Override\n public void println(double d){\n printlnAll(d);\n }\n\n void printlnAll(double... d){\n printAll(d);\n println();\n }\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static class RuntimeIOException extends RuntimeException {\n\n /**\n *\n */\n private static final long serialVersionUID = -6463830523020118289L;\n\n RuntimeIOException(Throwable cause) {\n super(cause);\n }\n }\n\n /////////////////////////////////////////////////////////////////////\n //////////////// Some useful constants and functions ////////////////\n /////////////////////////////////////////////////////////////////////\n\n private static final int[][] steps = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};\n private static final int[][] steps8 = {\n {-1, 0}, {1, 0}, {0, -1}, {0, 1},\n {-1, -1}, {1, 1}, {1, -1}, {-1, 1}\n };\n\n private static boolean checkCell(int row, int rowsCount, int column, int columnsCount) {\n return checkIndex(row, rowsCount) && checkIndex(column, columnsCount);\n }\n\n private static boolean checkIndex(int index, int lim){\n return (0 <= index && index < lim);\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static boolean checkBit(int mask, int bit){\n return (mask & (1 << bit)) != 0;\n }\n private static boolean checkBit(long mask, int bit){\n return (mask & (1L << bit)) != 0;\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static long getSum(int[] array) {\n long sum = 0;\n for (int value: array) {\n sum += value;\n }\n\n return sum;\n }\n\n private static Point getMinMax(int[] array) {\n int min = array[0];\n int max = array[0];\n\n for (int index = 0, size = array.length; index < size; ++index, ++index) {\n int value = array[index];\n\n if (index == size - 1) {\n min = min(min, value);\n max = max(max, value);\n } else {\n int otherValue = array[index + 1];\n\n if (value <= otherValue) {\n min = min(min, value);\n max = max(max, otherValue);\n } else {\n min = min(min, otherValue);\n max = max(max, value);\n }\n }\n }\n\n return new Point(min, max);\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static int[] getPrimes(int n) {\n boolean[] used = new boolean[n];\n used[0] = used[1] = true;\n\n int size = 0;\n for (int i = 2; i < n; ++i) {\n if (!used[i]) {\n ++size;\n for (int j = 2 * i; j < n; j += i) {\n used[j] = true;\n }\n }\n }\n\n int[] primes = new int[size];\n for (int i = 0, cur = 0; i < n; ++i) {\n if (!used[i]) {\n primes[cur++] = i;\n }\n }\n\n return primes;\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static long lcm(long a, long b) {\n return a / gcd(a, b) * b;\n }\n\n private static long gcd(long a, long b) {\n return (a == 0 ? b : gcd(b % a, a));\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static class MultiSet {\n\n public static MultiSet createMultiSet() {\n Map multiset = new HashMap<>();\n return new MultiSet<>(multiset);\n }\n\n private final Map multiset;\n private int size;\n\n public MultiSet(Map multiset) {\n this.multiset = multiset;\n this.size = 0;\n }\n\n public int size() {\n return size;\n }\n\n public void inc(ValueType value) {\n int count = get(value);\n multiset.put(value, count + 1);\n\n ++size;\n }\n\n public void dec(ValueType value) {\n int count = get(value);\n if (count == 0) return;\n\n if (count == 1) multiset.remove(value);\n else multiset.put(value, count - 1);\n\n --size;\n }\n\n public int get(ValueType value) {\n Integer count = multiset.get(value);\n return (count == null ? 0 : count);\n }\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static class IdMap extends HashMap {\n\n /**\n *\n */\n private static final long serialVersionUID = -3793737771950984481L;\n\n public IdMap() {\n super();\n }\n\n int getId(KeyType key) {\n Integer id = super.get(key);\n if (id == null) {\n super.put(key, id = size());\n }\n\n return id;\n }\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static int[] castInt(List list) {\n int[] array = new int[list.size()];\n for (int i = 0; i < array.length; ++i) {\n array[i] = list.get(i);\n }\n\n return array;\n }\n\n private static long[] castLong(List list) {\n long[] array = new long[list.size()];\n for (int i = 0; i < array.length; ++i) {\n array[i] = list.get(i);\n }\n\n return array;\n }\n\n /////////////////////////////////////////////////////////////////////\n\n /**\n * Generates list with values 0.. order(int n) {\n List sequence = new ArrayList<>();\n for (int i = 0; i < n; ++i) {\n sequence.add(i);\n }\n\n return sequence;\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e2260e0729219c7a3e1e105eebf3f5cc", "src_uid": "bf65a25185e9ea5b71e853723b838b04", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.NoSuchElementException;\nimport java.math.BigInteger;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.io.InputStream;\nimport java.io.OutputStreamWriter;\nimport java.util.function.Function;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Stanislav Pak\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\tTaskC solver = new TaskC();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskC {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n\t\tboolean[] isPrime = IntegerUtils.generatePrimalityTable(107);\n\t\tint a = in.readInt();\n\t\tint b = in.readInt();\n\t\tint k = in.readInt();\n\t\tint l = 1;\n\t\tint r = b - a + 1;\n\t\twhile (l < r) {\n\t\t\tint m = (l + r) >> 1;\n\t\t\tif (exists(isPrime, a, b, k, m)) {\n\t\t\t\tr = m;\n\t\t\t} else {\n\t\t\t\tl = m + 1;\n\t\t\t}\n\t\t}\n\t\tif (!exists(isPrime, a, b, k, l)) {\n\t\t\tout.printLine(-1);\n\t\t} else {\n\t\t\tout.printLine(l);\n\t\t}\n }\n\n\tprivate boolean exists(boolean[] isPrime, int a, int b, int k, int l) {\n\t\tint balance = 0;\n\t\tfor (int i = 0; i < l; ++i) {\n\t\t\tif (isPrime[a + i]) {\n\t\t\t\t++balance;\n\t\t\t}\n\t\t}\n\t\tif (balance < k) return false;\n\t\tfor (int i = a + 1; i + l - 1 <= b; ++i) {\n\t\t\tif (isPrime[i - 1]) --balance;\n\t\t\tif (isPrime[i + l - 1]) ++balance;\n\t\t\tif (balance < k) return false;\n\t\t}\n\t\treturn true;\n\t}\n}\n\nclass InputReader {\n\n\tprivate InputStream stream;\n\tprivate byte[] buf = new byte[1024];\n\tprivate int curChar;\n\tprivate int numChars;\n\tprivate SpaceCharFilter filter;\n\n\tpublic InputReader(InputStream stream) {\n\t\tthis.stream = stream;\n\t}\n\n\tpublic int read() {\n\t\tif (numChars == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (curChar >= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n\n\tpublic int readInt() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tint res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tpublic boolean isSpaceChar(int c) {\n\t\tif (filter != null)\n\t\t\treturn filter.isSpaceChar(c);\n\t\treturn isWhitespace(c);\n\t}\n\n\tpublic static boolean isWhitespace(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n\n\tpublic interface SpaceCharFilter {\n\t\tpublic boolean isSpaceChar(int ch);\n\t}\n}\n\nclass OutputWriter {\n\tprivate final PrintWriter writer;\n\n\tpublic OutputWriter(OutputStream outputStream) {\n\t\twriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n\t}\n\n\tpublic void close() {\n\t\twriter.close();\n\t}\n\n\tpublic void printLine(int i) {\n\t\twriter.println(i);\n\t}\n}\n\nclass IntegerUtils {\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}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "482aa791c13b9f496fb41e362f9e12a0", "src_uid": "3e1751a2990134f2132d743afe02a10e", "difficulty": 1600.0} {"lang": "Java 8", "source_code": " import java.util.*;\n public class love {\n public static void main(String[] args) {\n Scanner s=new Scanner(System.in);\n String str =s.nextLine();\n for(int i=0;i= 0) && ((a[j1] == 0) || (a[j1] > k))) j1--;\n\t\twhile ((j2 < n) && ((a[j2] == 0) || (a[j2] > k))) j2++;\n\t\tSystem.out.printf(\"%d\", min(j1 >= 0 ? m - j1 : Integer.MAX_VALUE, j2 < n ? j2 - m : Integer.MAX_VALUE));\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3a5d0cb1ef3571062186c64b3e700f71", "src_uid": "57860e9a5342a29257ce506063d37624", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main{\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 long Olesya = Math.pow(10,a-1);\n if(b>Olesya){\n System.out.println(-1);\n }\n else{\n int rem = Olesya % b;\n System.out.println(Olesya + b - rem);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "60566afaf66686a5627524078936849a", "src_uid": "77ffc1e38c32087f98ab5b3cb11cd2ed", "difficulty": 1000.0} {"lang": "Java 11", "source_code": "\nimport java.io.*;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\npublic class f\n{\n public static void print(String str,int val){\n System.out.println(str+\" \"+val);\n }\n\n public long gcd(long a, long b) {\n if (b==0L) return a;\n return gcd(b,a%b);\n }\n\n public static void debug(long[][] arr){\n int len = arr.length;\n for(int i=0;i=0;i--){\n if((char) (1+str.charAt(i))==(str.charAt(i+1))){\n inc_dp[i] = inc_dp[i+1]+1;\n if(inc_dp[i]>max_inc){\n max_inc = inc_dp[i];\n inc_index =i;\n }\n }\n }\n// print(inc_dp);\n int[] left_dp = new int[len];\n int max_left =1;\n int left_index =-1;\n Arrays.fill(left_dp,1);\n for(int i=1;imax_left){\n max_left = left_dp[i];\n left_index =i;\n }\n }\n\n// System.out.println(str+\" \"+max_inc+\" \"+max_left);\n\n if(max_inc==1 && max_left==1){\n return 0;\n }\n if(max_inc>max_left){\n String str1 = str.substring(0,inc_index+1)+str.substring(inc_index+inc_dp[inc_index]);\n return recur(str1)+max_inc-1;\n }\n else if(max_inc= 0; i--){\n if(sol1 % factors[i] != 0) {\n sol2 = factors[i];\n break;\n }\n }\n\n System.out.println(sol1 + \" \" + sol2);\n }\n}\n\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2c3e016f3ca2b6541615da4651ef2d18", "src_uid": "868407df0a93085057d06367aecaf9be", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.Scanner;\n\npublic class 915B{\n\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n = scan.nextInt(), curr = scan.nextInt(), l = scan.nextInt(), r = scan.nextInt(), ans = 0;\n\t\tboolean left = (l > 1), right = (r < n);\n\n\t\tif (!left && !right) {\n\t\t\tSystem.out.println(0);\n\t\t} else {\n\t\t\tif (right && !left) {\n\t\t\t\tSystem.out.println(Math.abs(r-curr) + 1);\n\t\t\t} else if (left && !right) {\n\t\t\t\tSystem.out.println(Math.abs(curr-l) +1);\n\t\t\t} else {\n\t\t\t\tSystem.out.println(2 + Math.min(Math.abs(curr-l), Math.abs(r-curr)) + r-l);\n\t\t\t}\n\t\t}\n\t\tscan.close();\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b128032a7e77a0ff89350150f29bec9d", "src_uid": "5deaac7bd3afedee9b10e61997940f78", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class CodeForces {\n\n public static void main(String[] args) throws IOException {\n\n Scanner reader;\n Long nCases,a,b,area;\n \n reader = new Scanner(System.in);\n\n nCases = reader.nextLong();\n\n for (Long k = 0L; k < nCases; k++) {\n \n a = reader.nextLong();\n b = reader.nextLong();\n \n if (a == b + 1) {\n System.out.println(\"YES\");\n }\n else{\n System.out.println(\"NO\");\n }\n } \n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "06669512bef5b9e7e40cb127176db9c1", "src_uid": "5a052e4e6c64333d94c83df890b1183c", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "public class Vitya {\n\n\tpublic static void main(String[] args) {\n\t\tScanner scanner = new Scanner(System.in);\n\t\tint n = scanner.nextInt();\n\t\tint[] t = new int[n];\n\t\tfor (int i=0;i= leftIndex && a[j] > current) {\n a[j + 1] = a[j];\n j--;\n }\n a[j + 1] = current;\n }\n }\n\n }\n\n // solution\n \n final double EPS = 1e-9;\n\n void solve() throws IOException {\n long t1 = readLong();\n long t2 = readLong();\n long x1 = readLong();\n long x2 = readLong();\n long t0 = readLong();\n long bestY1 = -1, bestY2 = -1;\n double bestT = -1;\n for (long y1 = x1; y1 >= 0; y1--) {\n long L = 0, R = x2, y2;\n while (L < R) {\n y2 = (L + R) / 2;\n double t = f(t1, t2, y1, y2);\n if (t0 > t + EPS) {\n L = y2 + 1;\n } else {\n R = y2;\n }\n }\n long mid = (L + R) / 2;\n for (y2 = max(0, mid - 10); y2 <= min(x2, mid + 10); y2++) {\n double t = f(t1, t2, y1, y2);\n if (t0 < t + EPS) {\n if (bestT == -1 || bestT > t + EPS) {\n bestY1 = y1;\n bestY2 = y2;\n bestT = t;\n } else if (abs(bestT - t) < EPS) {\n if (bestY1 + bestY2 < y1 + y2) {\n bestY1 = y1;\n bestY2 = y2;\n }\n }\n }\n }\n }\n out.println(bestY1 + \" \" + bestY2);\n }\n\n double f(long t1, long t2, long y1, long y2) {\n return (t1 * y1 + t2 * y2) / (y1 + y2 + 0.0);\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "36126c87f265268a8096c4526f203b82", "src_uid": "87a500829c1935ded3ef6e4e47096b9f", "difficulty": 1900.0} {"lang": "Java 7", "source_code": "import java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class Main {\n\tpublic static void main(String[] argv) {\n\t\tnew Main().run();\n\t}\n\n\tScanner in;\n\tPrintWriter out;\n\n\tvoid run() {\n\t\tin = new Scanner(System.in);\n\t\tout = new PrintWriter(System.out);\n\t\ttry {\n\t\t\tsolve();\n\t\t} finally {\n\t\t\tout.close();\n\t\t}\n\t}\n\n\tint rev(String s) {\n\t\tString res = \"\";\n\t\tfor (int i = 0; i < s.length(); i++) {\n\t\t\tres = s.charAt(i) + res;\n\t\t}\n\t\treturn Integer.parseInt(res);\n\t}\n\n\tvoid solve() {\n\t\tint n = in.nextInt();\n\t\tif (n == 3) {\n\t\t\tout.println(1);\n\t\t}\n\t\tif (n == 4) {\n\t\t\tout.println(1);\n\t\t\t//throw new Error();\n\t\t}\n\t\tif (n == 2) {\nthrow new Error();\n\t\t\tout.println(1);\n\t\t}\n\n\t\tif (n == 1) {\n\t\t\tout.println(1);\n\t\t}\n\n\t\tif (n == 5) {\n\t\t\tout.println(1);\n\t\t}\n\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cef9c000bcc968702714add697a43039", "src_uid": "c702e07fed684b7741d8337aafa005fb", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class A\n{\n\n\tstatic StringBuilder st = new StringBuilder();\n\t\n\tstatic int [][][] memo ;\n\tstatic char [] s ; \n\t\n\tstatic int dp(int l , int r , int cnt)\n\t{\n\t\tif(l > r) return 0 ; \n\t\t\n\t\tif(memo[l][r][cnt] != -1)return memo[l][r][cnt] ; \n\t\t\n\t\tint ans = dp(l + 1, r, 0) + 1 ;\n\t\t\n\t\tfor(int i = l + 1 ; i <= r ; i++)\n\t\t\tif(s[l] == s[i])\n\t\t\t\tans = Math.min(ans, dp(l + 1, i - 1, 0) + dp(i , r , cnt + 1 ));\n\t\t\n\t\treturn memo[l][r][cnt] = ans ; \n\t}\n\t\n\tpublic static void main(String[] args) throws Exception \n\t{\n\t\tScanner sc = new Scanner(System.in) ; \n\t\tPrintWriter out = new PrintWriter(System.out) ; \n\t\t\n\t\t\n\t\tint n = sc.nextInt() ; \n\t\ts = sc.next().toCharArray() ; \n\t\tmemo = new int [n][n][n] ; \n\t\t\n\t\tfor(int i = 0 ; i< n ; i++)\n\t\t\tfor(int j = 0 ; j < n ; j++)\n\t\t\t\tArrays.fill(memo[i][j], -1);\n\t\t\n\t\tout.println(dp(0, n - 1, 0));\n\t\tout.flush();\n\t\tout.close(); \n\t}\n\n\tstatic class Scanner \n\t{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tScanner(InputStream in) \n\t\t{\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tString next() throws Exception \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\tint nextInt() throws Exception { return Integer.parseInt(next()); }\n\n\t\tlong nextLong() throws Exception { return Long.parseLong(next()); }\n\n\t\tdouble nextDouble() throws Exception { return Double.parseDouble(next());}\n\n\t}\n\n\tstatic void shuffle(int[] a) \n\t{\n\t\tint n = a.length;\n\t\tfor (int i = 0; i < n; i++) \n\t\t{\n\t\t\tint r = i + (int) (Math.random() * (n - i));\n\t\t\tint tmp = a[i];\n\t\t\ta[i] = a[r];\n\t\t\ta[r] = tmp;\n\t\t}\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0c45bcddda98080446c2768a74dd5233", "src_uid": "516a89f4d1ae867fc1151becd92471e6", "difficulty": 2000.0} {"lang": "Java 11", "source_code": "import java.util.*;\n\npublic class Main\n{\n public static void main(String[] args)\n {\n int a,b,c,d;\n Scanner scn=new Scanner(System.in);\n a=scn.nextInt();\n b=scn.nextInt();\n c=scn.nextInt();\n d=scn.nextInt();\n \n int x,y,z;\n if(a==c&&b==d)\n x=0;\nelse if(a==c||b==d)\n x=1;\n else\n x=2;\nif(a==b&&b=c)\ny=0;\nelse if((a+b)%2==(c+d)%2)\n{\n if(Math.abs(c-a)==Math.abs(d-b))\n y=1;\n else\n y=2;\n}\nelse \ny=0;\n\nz=max(Math.abs(c-a),Math.abs(d-b));\nSystem.out.println(x+\" \"+y+\" \"+z);\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ae3d15dc10e87c1c5f14e435d03bcdb5", "src_uid": "7dbf58806db185f0fe70c00b60973f4b", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class oneone{\n\tpublic static void main(String[] args) {\n\t\tScanner sc=new Scanner(System.in);\n\t\tint p=sc.nextInt();\n\t\tint q=sc.nextInt();\n\t\tint[] a=new int[n];\n\t\tfor(int i=0;iq){\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tmin=Math.min(p-i+j,min);\n\t\t}\n\t\tSystem.out.println(min);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "153273d255886b09fc6d16be7993fb43", "src_uid": "6bcb324c072f796f4d50bafea5f624b2", "difficulty": 1200.0} {"lang": "Java 11", "source_code": "import java.util.Scanner;\npublic class codes{\npublic static void main(String []args){\nScanner sc = new Scanner(System.in);\nString museum = sc.next();\nint count =0;\nint start =0;\nint ch;\nint check;\nfor(int i=0; i items = new ArrayList<>();\n\t\tint profit;\n\n\t\tfor (int i = 0; i < types; i++) {\n\t\t\tprofit = sell[planetSell][i] - buy[planetBuy][i];\n\t\t\titems.add(new Items(profit, this.items[planetBuy][i]));\n\t\t}\n\n\t\tCollections.sort(items);\n\t\tprofit = 0;\n\t\tint capacity = 0;\n\t\tint remCap = this.capacity;\n\n\t\tfor (int i = 0; i < items.size(); i++) {\n\n\t\t\tcapacity = items.get(i).capacity;\n\t\t\tcapacity = Math.min(capacity, remCap);\n\n\t\t\tprofit += (capacity * items.get(i).profit);\n\t\t\tremCap -= capacity;\n\n\t\t}\n\n\t\treturn profit;\n\n\t}\n\n\tclass Items implements Comparable {\n\t\tint profit;\n\t\tint capacity;\n\n\t\tpublic Items(int profit, int capacity) {\n\t\t\tthis.profit = profit;\n\t\t\tthis.capacity = capacity;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Items o) {\n\t\t\t// TODO Auto-generated method stub\n\t\t\treturn Integer.compare(o.profit, this.profit);\n\t\t}\n\t}\n\n\tpublic void flush() {\n\t\tmOut.flush();\n\t}\n\n\tpublic void close() {\n\t\tmOut.close();\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tTaskC mSol = new TaskC();\n\t\tmSol.solve();\n\t\tmSol.flush();\n\t\tmSol.close();\n\t}\n\n\tclass FasterScanner {\n\t\tprivate InputStream mIs;\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n\n\t\tpublic FasterScanner() {\n\t\t\tthis(System.in);\n\t\t}\n\n\t\tpublic FasterScanner(InputStream is) {\n\t\t\tmIs = is;\n\t\t}\n\n\t\tpublic int read() {\n\t\t\tif (numChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= numChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tnumChars = mIs.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (numChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isEndOfLine(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic String nextString() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\tDouble next;\n\t\t\tnext = Double.parseDouble(nextString());\n\t\t\treturn next;\n\t\t}\n\n\t\tpublic boolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tpublic boolean isEndOfLine(int c) {\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t}\n\n\t\tpublic char[] nextCharArray(int N) {\n\t\t\tint i;\n\t\t\tchar[] array;\n\t\t\tString str;\n\n\t\t\tarray = new char[N];\n\n\t\t\ti = 0;\n\n\t\t\tstr = nextLine();\n\n\t\t\tfor (i = 0; i < N && i < str.length(); i++) {\n\t\t\t\tarray[i] = str.charAt(i);\n\t\t\t}\n\n\t\t\treturn array;\n\t\t}\n\n\t\tpublic char[][] nextChar2DArray(int M, int N) {\n\t\t\tint i;\n\t\t\tchar[][] array;\n\n\t\t\tarray = new char[M][N];\n\n\t\t\ti = 0;\n\n\t\t\tfor (i = 0; i < M; i++) {\n\t\t\t\tarray[i] = nextCharArray(N);\n\t\t\t}\n\n\t\t\treturn array;\n\t\t}\n\n\t\tpublic int[] nextIntArray(int N) {\n\t\t\tint i;\n\t\t\tint[] array;\n\n\t\t\tarray = new int[N];\n\n\t\t\ti = 0;\n\n\t\t\tfor (i = 0; i < N; i++) {\n\t\t\t\tarray[i] = nextInt();\n\t\t\t}\n\n\t\t\treturn array;\n\t\t}\n\n\t\tpublic int[][] nextInt2DArray(int M, int N) {\n\t\t\tint i;\n\t\t\tint[][] array;\n\n\t\t\tarray = new int[M][N];\n\n\t\t\ti = 0;\n\n\t\t\tfor (i = 0; i < M; i++) {\n\t\t\t\tarray[i] = nextIntArray(N);\n\t\t\t}\n\n\t\t\treturn array;\n\t\t}\n\n\t\tpublic long[] nextLongArray(int N) {\n\t\t\tint i;\n\t\t\tlong[] array;\n\n\t\t\tarray = new long[N];\n\n\t\t\ti = 0;\n\n\t\t\tfor (i = 0; i < N; i++) {\n\t\t\t\tarray[i] = nextLong();\n\t\t\t}\n\n\t\t\treturn array;\n\t\t}\n\n\t\tpublic long[][] nextLong2DArray(int M, int N) {\n\t\t\tint i;\n\t\t\tlong[][] array;\n\n\t\t\tarray = new long[M][N];\n\n\t\t\ti = 0;\n\n\t\t\tfor (i = 0; i < M; i++) {\n\t\t\t\tarray[i] = nextLongArray(N);\n\t\t\t}\n\n\t\t\treturn array;\n\t\t}\n\n\t\tpublic double[] nextDoubleArray(int N) {\n\t\t\tint i;\n\t\t\tdouble[] array;\n\n\t\t\tarray = new double[N];\n\n\t\t\tfor (i = 0; i < N; i++) {\n\t\t\t\tarray[i] = nextDouble();\n\t\t\t}\n\n\t\t\treturn array;\n\t\t}\n\n\t\tpublic double[][] nextDouble2DArray(int M, int N) {\n\t\t\tint i;\n\t\t\tdouble[][] array;\n\n\t\t\tarray = new double[M][N];\n\n\t\t\tfor (i = 0; i < M; i++) {\n\t\t\t\tarray[i] = nextDoubleArray(N);\n\t\t\t}\n\n\t\t\treturn array;\n\t\t}\n\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8e24ea530e775c6b1609eeb450117f33", "src_uid": "7419c4268a9815282fadca6581f28ec1", "difficulty": 1200.0} {"lang": "Java 11", "source_code": "//problem: https://codeforces.com/problemset/problem/1025/A\n\nimport java.util.Scanner;\nimport java.util.Arrays;\n\npublic class Doggo{\n public static void main(String[] args){\n Scanner sObj = new Scanner(System.in);\n int size = Integer.parseInt(sObj.nextLine());\n if(size==1){\n System.out.prinln(\"Yes\");\n return;\n }\n int[] arr = new int[128];\n for(char c: sObj.nextLine().toCharArray()){\n arr[c]++;\n if(arr[c] >= 2){\n System.out.println(\"Yes\");\n return;\n }\n }\n System.out.println(\"No\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f8ee6078f5eb74d7236ef06f465bb193", "src_uid": "6b22e93f7e429693dcfe3c099346dcda", "difficulty": 900.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n static PrintWriter out = new PrintWriter(new BufferedWriter(\n new OutputStreamWriter(System.out)));\n\n public static void main(String[] args) throws IOException {\n // PrintStream out = new PrintStream(new\n // FileOutputStream(\"out.out\"));\n Scan scan = new Scan();\n int n = scan.nextInt();\n out.println(solve(n));\n out.flush();\n }\n static String solve(int c){\n if(c==1)\n return \"one\";\n if(c==2)\n return \"two\";\n if(c==3)\n return \"three\";\n if(c==4)\n return \"four\";\n if(c==5)\n return \"five\";\n if(c==6)\n return \"six\";\n if(c==7)\n return \"seven\";\n if(c==8)\n return \"eight\";\n if(c==9)\n return \"nine\";\n if(c==10)\n return \"ten\";\n if(c==11)\n return \"eleven\";\n if(c==12)\n return \"twelve\";\n if(c==13)\n return \"thirteen\";\n if(c==14)\n return \"fourteen\";\n if(c==15)\n return \"fifteen\";\n if(c==16)\n return \"sixteen\";\n if(c==17)\n return \"seventeen\";\n if(c==18)\n return \"eighteen\";\n if(c==19)\n return \"nineteen\";\n if(c==20)\n return \"twenty\";\n if(c==21)\n return \"twenty-one\";\n if(c==22)\n return \"twenty-two\";\n if(c==23)\n return \"twenty-three\";\n if(c==24)\n return \"twenty-four\";\n if(c==25)\n return \"twenty-five\";\n if(c==26)\n return \"twenty-six\";\n if(c==27)\n return \"twenty-seven\";\n if(c==28)\n return \"twenty-eight\";\n if(c==29)\n return \"twenty-nine\";\n if(c==30)\n return \"thirty\";\n if(c==31)\n return \"thirty-one\";\n if(c==32)\n return \"thirty-two\";\n if(c==33)\n return \"thirty-three\";\n if(c==34)\n return \"thirty-four\";\n if(c==35)\n return \"thirty-five\";\n if(c==36)\n return \"thirty-six\";\n if(c==37)\n return \"thirty-seven\";\n if(c==38)\n return \"thirty-eight\";\n if(c==39)\n return \"thirty-nine\";\n if(c==40)\n return \"forty\";\n if(c==41)\n return \"forty-one\";\n if(c==42)\n return \"forty-two\";\n if(c==43)\n return \"forty-three\";\n if(c==44)\n return \"forty-four\";\n if(c==45)\n return \"forty-five\";\n if(c==46)\n return \"forty-six\";\n if(c==47)\n return \"forty-seven\";\n if(c==48)\n return \"forty-eight\";\n if(c==49)\n return \"forty-nine\";\n if(c==50)\n return \"fifty\";\n if(c==51)\n return \"fifty-one\";\n if(c==52)\n return \"fifty-two\";\n if(c==53)\n return \"fifty-three\";\n if(c==54)\n return \"fifty-four\";\n if(c==55)\n return \"fifty-five\";\n if(c==56)\n return \"fifty-six\";\n if(c==57)\n return \"fifty-seven\";\n if(c==58)\n return \"fifty-eight\";\n if(c==59)\n return \"fifty-nine\";\n if(c==60)\n return \"sixty\";\n if(c==61)\n return \"sixty-one\";\n if(c==62)\n return \"sixty-two\";\n if(c==63)\n return \"sixty-three\";\n if(c==64)\n return \"sixty-four\";\n if(c==65)\n return \"sixty-five\";\n if(c==66)\n return \"sixty-six\";\n if(c==67)\n return \"sixty-seven\";\n if(c==68)\n return \"sixty-eight\";\n if(c==69)\n return \"sixty-nine\";\n if(c==70)\n return \"seventy\";\n if(c==71)\n return \"seventy-one\";\n if(c==72)\n return \"seventy-two\";\n if(c==73)\n return \"seventy-three\";\n if(c==74)\n return \"seventy-four\";\n if(c==75)\n return \"seventy-five\";\n if(c==76)\n return \"seventy-six\";\n if(c==77)\n return \"seventy-seven\";\n if(c==78)\n return \"seventy-eight\";\n if(c==79)\n return \"seventy-nine\";\n if(c==80)\n return \"eighty\";\n if(c==81)\n return \"eighty-one\";\n if(c==82)\n return \"eighty-two\";\n if(c==83)\n return \"eighty-three\";\n if(c==84)\n return \"eighty-four\";\n if(c==85)\n return \"eighty-five\";\n if(c==86)\n return \"eighty-six\";\n if(c==87)\n return \"eighty-seven\";\n if(c==88)\n return \"eighty-eight\";\n if(c==89)\n return \"eighty-nine\";\n if(c==90)\n return \"ninety\";\n if(c==91)\n return \"ninety-one\";\n if(c==92)\n return \"ninety-two\";\n if(c==93)\n return \"ninety-three\";\n if(c==94)\n return \"ninety-four\";\n if(c==95)\n return \"ninety-five\";\n if(c==96)\n return \"ninety-six\";\n if(c==97)\n return \"ninety-seven\";\n if(c==98)\n return \"ninety-eight\";\n if(c==99)\n return \"ninety-nine\";\n return \"zero\";\n;\n }\n}\n\nclass Scan {\n\n BufferedReader buffer;\n StringTokenizer tok;\n\n Scan() {\n buffer = new BufferedReader(new InputStreamReader(System.in));\n // FileReader filereader=null;\n // try {\n // filereader = new FileReader(\"in.in\");\n // } catch (FileNotFoundException e) {\n // // TODO Auto-generated catch block\n // e.printStackTrace();\n // }\n // buffer = new BufferedReader(filereader);\n }\n\n boolean hasNext() {\n while (tok == null || !tok.hasMoreElements()) {\n try {\n tok = new StringTokenizer(buffer.readLine());\n } catch (Exception e) {\n return false;\n }\n }\n return true;\n }\n\n String next() {\n if (hasNext())\n return tok.nextToken();\n return null;\n }\n\n String nextLine() {\n String s = null;\n try {\n s = buffer.readLine();\n } catch (Exception e) {\n return null;\n }\n return s;\n }\n\n char nextChar() {\n try {\n return ((char) buffer.read());\n } catch (Exception e) {\n }\n return '\\0';\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "61da57df2cd2b35b0cabc2560227c7fd", "src_uid": "a49ca177b2f1f9d5341462a38a25d8b7", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.io.BufferedOutputStream;\r\nimport java.io.PrintWriter;\r\nimport java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\nimport java.util.StringTokenizer;\r\nimport java.util.Collection;\r\n\r\npublic class D extends Driver {\r\n public static void main(String[] args) {\r\n new D().run();\r\n }\r\n\r\n @Override\r\n public void solveOne() {\r\n OutputUtils.yn(out, canSolve());\r\n }\r\n\r\n boolean canSolve() {\r\n int n = in.nextInt(), m = in.nextInt(), k = in.nextInt();\r\n if (n % 2 == 0) {\r\n return k % 2 == 0;\r\n } else {\r\n return m%2 == 0 && (k - m / 2) % m == 0;\r\n }\r\n }\r\n}\r\n\r\nclass Driver {\r\n public static final boolean LOCAL = System.getProperty(\"ONLINE_JUDGE\") == null;\r\n\r\n public final PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out), LOCAL);\r\n\r\n public final FastScanner in = new FastScanner();\r\n\r\n public final void run() {\r\n try {\r\n solve();\r\n } finally {\r\n close();\r\n }\r\n }\r\n\r\n public void solve() {\r\n int tt = in.nextInt();\r\n while (tt-- > 0) {\r\n if (LOCAL) {\r\n out.println(\"--------------------------------------\");\r\n }\r\n solveOne();\r\n }\r\n }\r\n\r\n public void solveOne() {\r\n throw null;\r\n }\r\n\r\n protected void close() {\r\n out.close();\r\n }\r\n\r\n protected void print(Object... objects) {\r\n for (int i = 0; i < objects.length; i++) {\r\n if (i > 0) {\r\n out.print(' ');\r\n }\r\n out.print(objects[i]);\r\n }\r\n }\r\n\r\n protected void println(Object... objects) {\r\n print(objects);\r\n out.println();\r\n }\r\n}\r\n\r\nclass FastScanner {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n StringTokenizer st = new StringTokenizer(\"\");\r\n\r\n public String next() {\r\n while (!st.hasMoreElements()) {\r\n try {\r\n st = new StringTokenizer(br.readLine());\r\n } catch (IOException e) {\r\n e.printStackTrace();\r\n }\r\n }\r\n return st.nextToken();\r\n }\r\n\r\n public int nextInt() {\r\n return Integer.parseInt(next());\r\n }\r\n\r\n public char nextChar() {\r\n return next().charAt(0);\r\n }\r\n\r\n public int[] nextArray(int n) {\r\n int[] a = new int[n];\r\n for (int i = 0; i < n; i++) {\r\n a[i] = nextInt();\r\n }\r\n return a;\r\n }\r\n\r\n public char[] nextCharArray(int n) {\r\n char[] a = new char[n];\r\n for (int i = 0; i < n; i++) {\r\n a[i] = nextChar();\r\n }\r\n return a;\r\n }\r\n\r\n public long[] nextLongArray(int n) {\r\n long[] a = new long[n];\r\n for (int i = 0; i < n; i++) {\r\n a[i] = nextLong();\r\n }\r\n return a;\r\n }\r\n\r\n public long nextLong() {\r\n return Long.parseLong(next());\r\n }\r\n}\r\n\r\nclass OutputUtils {\r\n public static void yn(PrintWriter out, boolean y) {\r\n out.println(y ? \"YES\" : \"NO\");\r\n }\r\n\r\n public static void printMany(PrintWriter out, Object a) {\r\n if (a instanceof int[]) {\r\n printArray(out, (int[]) a);\r\n } else if (a instanceof long[]) {\r\n printArray(out, (long[]) a);\r\n } else if (a instanceof double[]) {\r\n printArray(out, (double[]) a);\r\n } else if (a instanceof Object[]) {\r\n printArray(out, (Object[]) a);\r\n } else if (a instanceof Collection) {\r\n printCollection(out, (Collection) a);\r\n } else {\r\n throw null;\r\n }\r\n }\r\n\r\n private static void printArray(PrintWriter out, long[] a) {\r\n for (int i = 0; i < a.length; i++) {\r\n if (i > 0) {\r\n out.print(' ');\r\n }\r\n out.print(a[i]);\r\n }\r\n out.println();\r\n }\r\n\r\n private static void printArray(PrintWriter out, E[] a) {\r\n for (int i = 0; i < a.length; i++) {\r\n if (i > 0) {\r\n out.print(' ');\r\n }\r\n out.print(a[i]);\r\n }\r\n out.println();\r\n }\r\n\r\n private static void printArray(PrintWriter out, int[] a) {\r\n for (int i = 0; i < a.length; i++) {\r\n if (i > 0) {\r\n out.print(' ');\r\n }\r\n out.print(a[i]);\r\n }\r\n out.println();\r\n }\r\n\r\n private static void printArray(PrintWriter out, double[] a) {\r\n for (int i = 0; i < a.length; i++) {\r\n if (i > 0) {\r\n out.print(' ');\r\n }\r\n out.print(a[i]);\r\n }\r\n out.println();\r\n }\r\n\r\n private static void printCollection(PrintWriter out, Collection a) {\r\n int i = 0;\r\n for (E x : a) {\r\n if (i++ > 0) {\r\n out.print(' ');\r\n }\r\n out.print(x);\r\n }\r\n out.println();\r\n }\r\n}\r\n\r\nclass E extends Driver {\r\n public static void main(String[] args) {\r\n new E().run();\r\n }\r\n\r\n @Override\r\n public void solve() {\r\n int n = in.nextInt();\r\n char[] cs = in.next().toCharArray();\r\n int[] pacmans, food;\r\n int npacman = 0, nfood = 0;\r\n {\r\n int ipacman = 0, ifood = 0;\r\n for (int i = 0; i < n; i++) {\r\n if (cs[i] == 'P') {\r\n npacman++;\r\n }\r\n if (cs[i] == '*') {\r\n nfood++;\r\n }\r\n }\r\n pacmans = new int[npacman];\r\n food = new int[nfood];\r\n for (int i = 0; i < n; i++) {\r\n if (cs[i] == 'P') {\r\n pacmans[ipacman++] = i;\r\n }\r\n if (cs[i] == '*') {\r\n food[ifood++] = i;\r\n }\r\n }\r\n }\r\n int lo = 0, hi = 3 * n;\r\n while (lo < hi) {\r\n int mid = (lo + hi) / 2;\r\n int leftMost = 0;\r\n for (int i = 0; i < npacman; i++) {\r\n int rightDist;\r\n if (pacmans[i] < food[leftMost]) {\r\n rightDist = mid;\r\n } else {\r\n int leftDist = pacmans[i] - food[leftMost];\r\n if (leftDist > mid) {\r\n break;\r\n }\r\n // 2 cases:\r\n // 1. *...P.* go to the right first\r\n // 1. *.P...* go to the left first\r\n rightDist = Math.max(mid - 2 * leftDist, (mid - leftDist) / 2);\r\n }\r\n while (leftMost < nfood && food[leftMost] <= pacmans[i] + rightDist) {\r\n leftMost++;\r\n }\r\n if (leftMost == nfood) {\r\n break;\r\n }\r\n }\r\n if (leftMost == nfood) {\r\n hi = mid;\r\n } else {\r\n lo = mid + 1;\r\n }\r\n }\r\n out.println(lo);\r\n }\r\n}\r\n\r\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "531758099545f6c1d7fc78e3d0030b02", "src_uid": "4d0c0cc8faca62eb6384f8135b30feb8", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Main\n{\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner s= new Scanner(System.in);\n\t\tint p = s.nextInt();\n\t\tint y = s.nextInt();\n\n\t\tint flag = 0 ;\n\t\twhile(y--)\n\t\t{\n\t\t\tint chkflag =0 ;\n\t\t\tfor(int j=0;j*j<= y && j<=p ;j++)\n\t\t\t{\n\t\t\t\tif(y%j ==0)\n\t\t\t\t{\n\t\t\t\tchkflag = 1;\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(chkflag == 0)\n\t\t\t{\n\t\t\tSystem.out.println(y);\n\t\t\tflag = 1;\n\t\t\tbreak;\n\t\t\t}\n\t\t\ty--;\n\t\t}\n\t\tif(flag == 0)\n\t\tSystem.out.println(-1);\n\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2d730590fd7786087bb7eae99f515597", "src_uid": "b533203f488fa4caf105f3f46dd5844d", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*\npublic class tatti{\n \n public static void main(String dsgs[]){\n Scanner s = new Scanner(System.in);\n int n;\n n = s.nextInt();\n int a[] =new int[n];\n for(int i=0;i0)\n\t\t\t\t{\n\t\t\t\t\tcount++;\n\t\t\t \t\theap = heap-gcd(a,heap);\n\t\t\t\t}\n\t\t\t}else\n\t\t\t{\n\t\t\t\tif(heap>0)\n\t\t\t\t{\n\t\t\t\t\tcount=1;\n\t\t\t \t\theap = heap-gcd(a,heap);\n\t\t\t\t}\n\n\t\t\t}\n\t\t\t\n\t\t}\n\t\tSystem.out.print(count);\n\t}\n\tpublic static int gcd(int n1, int n2)\n\t{\n\t \tint gcd = 1;\n\t for(int i = 1; i <= n1 && i <= n2; ++i)\n \t{\n \t\tif(n1 % i==0 && n2 % i==0)\n \t\tgcd = i;\n \t}\n\treturn gcd;\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "286931993142d92d50d5a41ed299944c", "src_uid": "0bd6fbb6b0a2e7e5f080a70553149ac2", "difficulty": 800.0} {"lang": "Java 6", "source_code": "import java.awt.Point;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class D {\n\n\tfinal boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer tok = new StringTokenizer(\"\");\n\n\tvoid init() throws FileNotFoundException {\n\t\tif (ONLINE_JUDGE) {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t} else {\n\t\t\tin = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\tout = new PrintWriter(\"output.txt\");\n\t\t}\n\t}\n\n\tString readString() throws IOException {\n\t\twhile (!tok.hasMoreTokens()) {\n\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\n\tint readInt() throws IOException {\n\t\treturn Integer.parseInt(readString());\n\t}\n\n\tlong readLong() throws IOException {\n\t\treturn Long.parseLong(readString());\n\t}\n\n\tdouble readDouble() throws IOException {\n\t\treturn Double.parseDouble(readString());\n\t}\n\n\tint[] readArr(int n) throws IOException {\n\t\tint[] res = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tres[i] = readInt();\n\t\t}\n\t\treturn res;\n\t}\n\n\tlong[] readArrL(int n) throws IOException {\n\t\tlong[] res = new long[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tres[i] = readLong();\n\t\t}\n\t\treturn res;\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew D().run();\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tlong t1 = System.currentTimeMillis();\n\t\t\tinit();\n\t\t\tsolve();\n\t\t\tout.close();\n\t\t\tlong t2 = System.currentTimeMillis();\n\t\t\tSystem.err.println(\"Time = \" + (t2 - t1));\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace(System.err);\n\t\t\tSystem.exit(-1);\n\t\t}\n\t}\n\n\tvoid solve() throws Exception {\n\t\tdouble a = readInt();\n\t\tdouble b = readInt();\n\t\tdouble m = readInt();\n\t\tdouble vx = readDouble();\n\t\tdouble vy = readDouble();\n\t\tdouble vz = readDouble();\n\t\tdouble x = a * 1.0 / 2;\n\t\tdouble y = m;\n\t\tdouble z = 0;\n\t\twhile (true) {\n\t\t\tdouble tmin = 10000000;\n\t\t\tint r = 0;\n\t\t\tif (vx > 0) {\n\t\t\t\tdouble curT = (a - x) / vx;\n\t\t\t\tif (tmin > curT) {\n\t\t\t\t\tr = 1;\n\t\t\t\t\ttmin = curT;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tdouble curT = -x / vx;\n\t\t\t\tif (tmin > curT) {\n\t\t\t\t\tr = 1;\n\t\t\t\t\ttmin = curT;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (vy > 0) {\n\t\t\t\tthrow new Exception();\n\t\t\t} else {\n\t\t\t\ttmin = min(tmin, -y / vy);\n\t\t\t}\n\n\t\t\tif (vz > 0) {\n\t\t\t\tdouble curT = (b - z) / vz;\n\t\t\t\tif (tmin > curT) {\n\t\t\t\t\tr = 2;\n\t\t\t\t\ttmin = curT;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tdouble curT = -z / vz;\n\t\t\t\tif (tmin > curT) {\n\t\t\t\t\tr = 2;\n\t\t\t\t\ttmin = curT;\n\t\t\t\t}\n\t\t\t}\n\t\t\tx = x + tmin * vx;\n\t\t\ty = y + tmin * vy;\n\t\t\tz = z + tmin * vz;\n\t\t\tif(x < 0) x = 0.00000001;\n\t\t\tif(x > a) x = a-0.00000001;\n\t\t\tif(z < 0.0000001) z = 0.00000001;\n\t\t\tif(z > b) z = b - 0.00000001;\n\t\t\t\n\t\t\tif (abs(y) < 0.0000001 || y < 0) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t\n\t\t\tif(r == 1) vx = -vx;\n\t\t\tif(r == 2) vz = -vz;\n\t\t}\n\t\tout.println(x + \" \" + z);\n\t}\n\n\tvoid maxHepify(int[] a, int i, int length) {\n\t\tint l = (i << 1) + 1;\n\t\tint r = (i << 1) + 2;\n\t\tint largest = i;\n\t\tif (l < length && a[l] > a[largest])\n\t\t\tlargest = l;\n\t\tif (r < length && a[r] > a[largest])\n\t\t\tlargest = r;\n\t\tif (largest != i) {\n\t\t\ta[largest] += a[i];\n\t\t\ta[i] = a[largest] - a[i];\n\t\t\ta[largest] -= a[i];\n\t\t\tmaxHepify(a, largest, length);\n\t\t}\n\t}\n\n\tvoid buildMaxHeap(int[] a) {\n\t\tfor (int i = a.length / 2 - 1; i >= 0; i--) {\n\t\t\tmaxHepify(a, i, a.length);\n\t\t}\n\t}\n\n\tvoid heapSort(int[] a) {\n\t\tbuildMaxHeap(a);\n\t\tfor (int i = a.length - 1; i > 0; i--) {\n\t\t\ta[i] += a[0];\n\t\t\ta[0] = a[i] - a[0];\n\t\t\ta[i] -= a[0];\n\t\t\tmaxHepify(a, 0, i);\n\t\t}\n\t}\n\n\tint[] zFunction(char[] s) {\n\t\tint[] z = new int[s.length];\n\t\tz[0] = 0;\n\t\tfor (int i = 1, l = 0, r = 0; i < s.length; ++i) {\n\t\t\tif (i <= r)\n\t\t\t\tz[i] = min(r - i + 1, z[i - l]);\n\t\t\twhile (i + z[i] < s.length && s[z[i]] == s[i + z[i]])\n\t\t\t\t++z[i];\n\t\t\tif (i + z[i] - 1 > r) {\n\t\t\t\tl = i;\n\t\t\t\tr = i + z[i] - 1;\n\t\t\t}\n\t\t}\n\t\treturn z;\n\t}\n\n\tint[] prefixFunction(char[] s) {\n\t\tint[] pr = new int[s.length];\n\t\tfor (int i = 1; i < s.length; ++i) {\n\t\t\tint j = pr[i - 1];\n\t\t\twhile (j > 0 && s[i] != s[j])\n\t\t\t\tj = pr[j - 1];\n\t\t\tif (s[i] == s[j])\n\t\t\t\t++j;\n\t\t\tpr[i] = j;\n\t\t}\n\t\treturn pr;\n\t}\n\n\tint ModExp(int a, int n, int mod) {\n\t\tint res = 1;\n\t\twhile (n != 0)\n\t\t\tif ((n & 1) != 0) {\n\t\t\t\tres = (res * a) % mod;\n\t\t\t\t--n;\n\t\t\t} else {\n\t\t\t\ta = (a * a) % mod;\n\t\t\t\tn >>= 1;\n\t\t\t}\n\t\treturn res;\n\t}\n\n\tpublic static class Utils {\n\n\t\tprivate Utils() {\n\t\t}\n\n\t\tpublic static void mergeSort(int[] a) {\n\t\t\tmergeSort(a, 0, a.length - 1);\n\t\t}\n\n\t\tprivate static void mergeSort(int[] a, int leftIndex, int rightIndex) {\n\t\t\tfinal int MAGIC_VALUE = 50;\n\t\t\tif (leftIndex < rightIndex) {\n\t\t\t\tif (rightIndex - leftIndex <= MAGIC_VALUE) {\n\t\t\t\t\tinsertionSort(a, leftIndex, rightIndex);\n\t\t\t\t} else {\n\t\t\t\t\tint middleIndex = (leftIndex + rightIndex) / 2;\n\t\t\t\t\tmergeSort(a, leftIndex, middleIndex);\n\t\t\t\t\tmergeSort(a, middleIndex + 1, rightIndex);\n\t\t\t\t\tmerge(a, leftIndex, middleIndex, rightIndex);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tprivate static void merge(int[] a, int leftIndex, int middleIndex,\n\t\t\t\tint rightIndex) {\n\t\t\tint length1 = middleIndex - leftIndex + 1;\n\t\t\tint length2 = rightIndex - middleIndex;\n\t\t\tint[] leftArray = new int[length1];\n\t\t\tint[] rightArray = new int[length2];\n\t\t\tSystem.arraycopy(a, leftIndex, leftArray, 0, length1);\n\t\t\tSystem.arraycopy(a, middleIndex + 1, rightArray, 0, length2);\n\t\t\tfor (int k = leftIndex, i = 0, j = 0; k <= rightIndex; k++) {\n\t\t\t\tif (i == length1) {\n\t\t\t\t\ta[k] = rightArray[j++];\n\t\t\t\t} else if (j == length2) {\n\t\t\t\t\ta[k] = leftArray[i++];\n\t\t\t\t} else {\n\t\t\t\t\ta[k] = leftArray[i] <= rightArray[j] ? leftArray[i++]\n\t\t\t\t\t\t\t: rightArray[j++];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tprivate static void insertionSort(int[] a, int leftIndex, int rightIndex) {\n\t\t\tfor (int i = leftIndex + 1; i <= rightIndex; i++) {\n\t\t\t\tint current = a[i];\n\t\t\t\tint j = i - 1;\n\t\t\t\twhile (j >= leftIndex && a[j] > current) {\n\t\t\t\t\ta[j + 1] = a[j];\n\t\t\t\t\tj--;\n\t\t\t\t}\n\t\t\t\ta[j + 1] = current;\n\t\t\t}\n\t\t}\n\t}\n\n\tboolean isPrime(int a) {\n\t\tfor (int i = 2; i <= sqrt(a); i++)\n\t\t\tif (a % i == 0)\n\t\t\t\treturn false;\n\t\treturn true;\n\t}\n\n\tstatic double distance(long x1, long y1, long x2, long y2) {\n\t\treturn Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));\n\t}\n\n\tstatic long gcd(long a, long b) {\n\t\tif (min(a, b) == 0)\n\t\t\treturn max(a, b);\n\t\treturn gcd(max(a, b) % min(a, b), min(a, b));\n\t}\n\n\tstatic long lcm(long a, long b) {\n\t\treturn a * b / gcd(a, b);\n\t}\n}\n\n/*\n * class Treap>{\n * \n * public K x; public double y; public Treap left; public Treap right;\n * \n * public Treap(K x, double y, Treap left, Treap right) { this.x = x;\n * this.y = y; this.left = left; this.right = right; }\n * \n * public static > Treap merge(Treap l, Treap\n * r){ if(l == null) return r; if(r == null) return l; if(l.y > r.y){ return new\n * Treap(l.x, l.y, l.left, merge(l.right, r)); } else{ return new\n * Treap(r.x, r.y, merge(l, r.left), r.right); } }\n * \n * public void split(K x, Treap left, Treap right){ Treap newTreap =\n * null; if(this.x.compareTo(x) <= 0){ if(this.right == null){ right = null; }\n * else{ right.split(x, newTreap, right); } left = new Treap(this.x, this.y,\n * left, newTreap); } else{ if(this.left == null){ left = null; } else{\n * left.split(x, left, newTreap); } right = new Treap(x, y, newTreap, right);\n * } }\n * \n * public Treap add(K x){ Treap left = null, right = null; this.split(x,\n * left, right); Treap temp = new Treap(x, random(), null, null); return\n * merge(merge(left, temp), right); }\n * \n * @SuppressWarnings(\"null\") public Treap remove(K x){ Treap left = null,\n * temp = null, right = null; this.split(x, left, right); right.split(x, temp,\n * right); return merge(left, right); }\n * \n * public static > Treap build(K[] a){ Treap temp\n * = new Treap(a[0], random(), null, null); for(int i = 1; i < a.length;\n * i++){ temp = temp.add(a[i]); } return temp; } }\n */", "lang_cluster": "Java", "compilation_error": false, "code_uid": "215b4d0efe0374395aa2f0e6e2402983", "src_uid": "84848b8bd92fd2834db1ee9cb0899cff", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class P721A {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tsc.nextLine();\n\t\tString[] B = sc.nextLine().split(\"W\");\n\t\tArrayList nums = new ArrayList();\n\t\tfor (String s : B)\n\t\t\tif (s.length() > 0)\n\t\t\t\tnums.add(s.length());\n\t\tString ans = \"\";\n\t\tfor (int i : nums)\n\t\t\tans += \" \" + i;\n\t\tSystem.out.println(nums.length());\n\t\tSystem.out.println(ans.substring(1));\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6ecaf99838aca7ae9b24dd01b1e0e771", "src_uid": "e4b3a2707ba080b93a152f4e6e983973", "difficulty": 800.0} {"lang": "Java 6", "source_code": "import java.util.*;\n import java.io.*;\npublic class MonochromaticBoard {\n public int theMin(String[] board) {\n char [][]b = new char[board.length][];\n for (int i = 0; i < board.length; ++i) {\n b[i] = board[i].toCharArray();\n }\n int res = 0;\n int n = b.length, m = b[0].length;\n if (n < m) {\n boolean painted[] = new boolean[n];\n for (int i = 0; i < n; ++i) {\n boolean ok = true;\n for (char x : b[i]) {\n ok &= x == 'B';\n }\n if (ok) {\n ++res;\n painted[i] = true;\n }\n }\n for (int i = 0; i < m; ++i) {\n for (int j = 0; j < n; ++j) {\n if (b[j][i] == 'B' && !painted[j]) {\n ++res;\n break;\n }\n }\n }\n } else {\n boolean painted[] = new boolean[m];\n for (int i = 0; i < m; ++i) {\n boolean ok = true;\n for (int j = 0; j < n; ++j) {\n ok &= b[j][i] == 'B';\n }\n if (ok) {\n ++res;\n painted[i] = true;\n }\n }\n for (int i = 0; i < n; ++i) {\n for (int j = 0; j < m; ++j) {\n if (b[i][j] == 'B' && !painted[j]) {\n ++res;\n break;\n }\n }\n }\n }\n return res;\n }\n public static void main(String... args) throws Throwable {\n String []board = new String[8];\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n for (int i = 0; i < 8; ++i) board[i]= in.readLine();\n System.out.println(theMin(board));\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b54473a1d3132f7c65757f2bd7235434", "src_uid": "8b6ae2190413b23f47e2958a7d4e7bc0", "difficulty": 1100.0} {"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 */\npackage codeforces;\nimport java.util.*;\n/**\n *\n * @author Ashraf\n */\npublic class DVA {\n public static void main(String []args){\n Scanner in=new Scanner(System.in);\n long n=in.nextLong();\n int k=in.nextInt();\n if(k==0){\n System.out.println(n);\n }\n else if(k==1){\n if(n%10==0){\n System.out.println(n);\n }\n else{\n for(int i=1;i<=10;i++){\n if((n*i)%10==0){\n System.out.println(n*i);\n System.exit(0);\n }\n }\n }\n }\n else if(k==2){\n if(n%100==0){\n System.out.println(n);\n }\n else {\n for(int i=2;i<=100;i++){\n if((n*i)%100==0&&(n*i)%k==0){\n System.out.println(n*i);\n System.exit(0);\n }\n }\n }\n }\n else if(k==3){\n if(n%1000==0){\n System.out.println(n);\n }\n else {\n for(int i=3;i<=1000;i++){\n if((n*i)%1000==0&&(n*i)%k==0){\n System.out.println(n*i);\n System.exit(0);\n }\n }\n }\n }\n else if(k==4){\n if(n%10000==0){\n System.out.println(n);\n }\n else {\n for(int i=4;i<=10000;i+=4){\n if((n*i)%10000==0){\n System.out.println(n*i);\n System.exit(0);\n }\n }\n }\n }\n else if(k==5){\n if(n%100000==0){\n System.out.println(n);\n }\n else{\n for(int i=5;i<=100000;i+=5){\n if((n*i)%100000==0){\n System.out.println(n*i);\n System.exit(0);\n }\n }\n }\n }\n else if(k==6){\n if(n%1000000==0){\n System.out.println(n);\n }\n else{\n for(int i=6;i<=100000;i+=6){\n if((n*i)%100000==0&&(n*i)%k==0){\n System.out.println(n*i);\n System.exit(0);\n }\n }\n }\n }\n else if(k==7){\n if(n%10000000==0){\n System.out.println(n);\n }\n else{\n for(int i=7;i<=10000000;i+=7){\n if((n*i)%10000000==0&&(n*i)%k==0){\n System.out.println(n*i);\n System.exit(0);\n }\n }\n }\n }\n else if(k==8){\n if(n%100000000==0){\n System.out.println(n);\n }\n else {\n for(int i=8;i<=125000000;i++){\n if((n*i)%100000000==0&&(n*i)%k==0){\n System.out.println(n*i);\n System.exit(0);\n }\n }\n System.out.println(n*100000000);\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cc0ddc94f21f0d1aec6dfcbc1fc84ec1", "src_uid": "73566d4d9f20f7bbf71bc06bc9a4e9f3", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n \npublic class Solution {\n public static void main(String[] args) throws Exception {\n \n PrintWriter pw=new PrintWriter(System.out);\n \n BufferedReader br = new BufferedReader( \n new InputStreamReader(System.in)); \n \n InputReader in=new InputReader(System.in);\n \n char[] ch=in.nextLine().toCharArray();\n int n=ch.length;\n if(ch[0]=='0'){\n System.out.println(\"0\");\n return;\n }\n for(int i=1;i{\n int x;\n int y;\n Pair(int a,int b){\n x=a;\n y=b;\n }\n public int compareTo(Pair t){\n if(x>t.x)return 1;\n else if(x==t.x){\n if(y>=t.y)return 1;\n else return -1;\n }\n else return -1;\n }\n public boolean equals(Object obj){\n if(bliss==obj)return true;\n Pair blat=(Pair)obj;\n if(bliss.x==blat.x && bliss.y==blat.y)return true;\n return false;\n }\n public String toString(){\n return bliss.x+\" \"+bliss.y;\n }\n }\n static class InputReader {\n \n private final InputStream stream;\n private final byte[] buf = new byte[8192];\n private int curChar, numChars;\n private SpaceCharFilter filter;\n \n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n \n public int snext() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n \n public int nextInt() {\n int c = snext();\n while (isSpaceChar(c)) {\n c = snext();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = snext();\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 = snext();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n \n public long nextLong() {\n int c = snext();\n while (isSpaceChar(c)) {\n c = snext();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = snext();\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 = snext();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n \n public int[] nextIntArray(int n) {\n int a[] = new int[n];\n for (int i = 0; i < n; i++) {\n a[i] = nextInt();\n }\n return a;\n }\n \n public long[] nextLongArray(int n) {\n long a[] = new long[n];\n for (int i = 0; i < n; i++) {\n a[i] = nextLong();\n }\n return a;\n }\n \n public String readString() {\n int c = snext();\n while (isSpaceChar(c)) {\n c = snext();\n }\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = snext();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n \n public String nextLine() {\n int c = snext();\n while (isSpaceChar(c))\n c = snext();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = snext();\n } while (!isEndOfLine(c));\n return res.toString();\n }\n \n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n \n private boolean isEndOfLine(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", "compilation_error": true, "code_uid": "3873470c10966536b024e4249e59d0ff", "src_uid": "d8ca1c83b431466eff6054d3b422ab47", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.io.BufferedOutputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.stream.IntStream;\n\npublic class Frog {\n\n public static int canFrogReachDestination(final int destination, final int maximumStep, final List allowedPaths) {\n final int actualDestination = destination - 1;\n final List dp = new ArrayList<>();\n dp.add(0);\n IntStream.range(1, allowedPaths.size()).forEach(x -> dp.add(Integer.MAX_VALUE-10));\n\n for (int currentPos = 1; currentPos <= actualDestination; currentPos++) {\n if(allowedPaths.get(currentPos)==1) {\n for(int i=currentPos-1;i>=currentPos-maximumStep;i--) {\n if(i<0) {\n break;\n }\n dp.set(currentPos, Integer.min(dp.get(currentPos), dp.get(i)+1));\n }\n }\n }\n if(dp.get(actualDestination) == Integer.MAX_VALUE-10) {\n dp.set(actualDestination, -1);\n }\n return dp.get(actualDestination);\n }\n\n public static void main(final String[] args) {\n final MyScanner scan = new MyScanner();\n final PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n\n final int a = scan.nextInt();\n final int b = scan.nextInt();\n\n final List result = new ArrayList<>();\n\n for(final char i : scan.nextLine().toCharArray()) {\n result.add(Character.getNumericValue(i));\n }\n out.print(canFrogReachDestination(a, b, result));\n out.close();\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9fd8474bb8aef564277abf7ae2ad3ba2", "src_uid": "c08d2ecdfc66cd07fbbd461b1f069c9e", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.List;\n\npublic class Main {\n\n\n public static void main( String[] args ) throws java.lang.Exception {\n\n java.io.BufferedReader r = new java.io.BufferedReader( new java.io.InputStreamReader( System.in ) );\n\n String[] tokens = r.readLine().split( \" \" );\n\n List towerOne = new ArrayList<>();\n List towerTwo = new ArrayList<>();\n\n int max = Math.max( Integer.parseInt( tokens[0] ), Integer.parseInt( tokens[1] ) );\n int min = Math.min( Integer.parseInt( tokens[1] ), Integer.parseInt( tokens[0] ) );\n\n if ( (max / min) > min ) {\n if (max == Integer.parseInt( tokens[0] )) {\n System.out.println( max * 2 );\n } else {\n System.out.println( max * 3 );\n }\n\n return;\n }\n\n for( int i = 0; i < Integer.parseInt( tokens[0] ); i++ ) {\n towerOne.add( (i + 1) * 2 );\n }\n\n for( int i = 0; i < Integer.parseInt( tokens[1] ); i++ ) {\n towerTwo.add( (i + 1) * 3 );\n }\n\n for (int i = 1 ; i <= max( towerOne, towerTwo ); i++){\n if ( towerOne.contains( i ) && towerTwo.contains( i ) ){\n if ( height(towerOne) + 2 > height( towerTwo ) + 3 ){\n towerTwo.add( height( towerTwo ) + 3 );\n } else {\n towerOne.add( height( towerOne ) + 2 );\n }\n }\n }\n\n System.out.println( max( towerOne, towerTwo ) );\n }\n\n private static Integer max(List l1, List l2){\n if ( l1.size() == 0 ) return l2.get( l2.size() - 1 );\n if ( l2.size() == 0 ) return l1.get( l1.size() - 1 );\n\n return Math.max( l2.get( l2.size() - 1 ), l1.get( l1.size() - 1 ) );\n }\n\n private static Integer height(List l){\n if (l.size() == 0) {\n return 0;\n } else {\n return l.get( l.size() - 1 );\n }\n }\n\n\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "16736c5ff2079ece3f26a4f71520b3a3", "src_uid": "23f2c8cac07403899199abdcfd947a5a", "difficulty": 1600.0} {"lang": "Java 17", "source_code": "public class Domino {\r\n public static void main(String[] args) {\r\n Scanner in = new Scanner(System.in);\r\n int a = in.nextInt();\r\n int b = in.nextInt();\r\n if(b==1) \r\n System.out.print(a-1);\r\n else\r\n System.out.print(a*(b-1));\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "659c72c066e8518b31253fd1af24e49d", "src_uid": "a91aab4c0618d036c81022232814ef44", "difficulty": 800.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Main {\n public static void main (String [] Args ) throws Exception {\n Scanner sc = new Scanner(System.in);\n int x,y;\n x = sc.nextInt(); y = sc.nextInt();\n if(x==0 || y==0 ) System.out.println(\"black\");\n else {\n int cr = -1;\n if(x>0 && y>0) cr = 0;\n else if(x<0 && y>0) cr = 1;\n else if(x<0 && y<0) cr = 2;\n else if(x>0 && y<0) cr = 3;\n int d = x*x+y*y;\n for(int i=0;i<=1000;++i){\n if(i*i==d) { System.out.println(\"black\"); break;}\n else {\n if(i*ib){\n System.out.println(\"1\");\n } else {\n System.out.println(b-a);\n }\n }\n \n \n public void run()\n { \n solve();\n out.close();\n }\n \n public static void main(String[] args) throws IOException\n { \n new Thread(null, new Sample(), \"whatever\", 1<<26).start();\n }\n static class Pair implements Comparator{ \n String a;\n long b;\n long c;\n \n Pair(){}\n Pair(String a,long b,long c)\n {\n this.a=a;\n this.b=b;\n this.c=c;\n }\n public int compare(Pair p1,Pair p2)\n {\n if(p1.c==0 && p2.c==0)\n {\n return Long.compare(p1.b,p2.b);\n }\n if(p1.c==0)\n {\n return -1;\n }\n if(p2.c==0)\n {\n return 1;\n }\n else\n return Long.compare(p2.b*p1.c,p1.b*p2.c);\n \n }\n \n \n }\n \n \n \n \n ////////////////////////////////////////////////////// Merge Sort ////////////////////////////////////////////////////////////////////////\n \n static class Merge \n {\n \n public static void sort(long inputArr[]) \n {\n int length = inputArr.length;\n doMergeSort(inputArr,0, length - 1);\n }\n \n private static void doMergeSort(long[] arr,int lowerIndex, int higherIndex) \n { \n if (lowerIndex < higherIndex) {\n int middle = lowerIndex + (higherIndex - lowerIndex) / 2;\n doMergeSort(arr,lowerIndex, middle);\n doMergeSort(arr,middle + 1, higherIndex);\n mergeParts(arr,lowerIndex, middle, higherIndex);\n }\n }\n \n private static void mergeParts(long[]array,int lowerIndex, int middle, int higherIndex) \n {\n long[] temp=new long[higherIndex-lowerIndex+1];\n for (int i = lowerIndex; i <= higherIndex; i++) \n {\n temp[i-lowerIndex] = array[i];\n }\n int i = lowerIndex;\n int j = middle + 1;\n int k = lowerIndex;\n while (i <= middle && j <= higherIndex) \n {\n if (temp[i-lowerIndex] < temp[j-lowerIndex]) \n {\n array[k] = temp[i-lowerIndex];\n i++;\n } else {\n array[k] = temp[j-lowerIndex];\n j++;\n }\n k++;\n }\n while (i <= middle) \n {\n array[k] = temp[i-lowerIndex];\n k++;\n i++;\n }\n while(j<=higherIndex)\n {\n array[k]=temp[j-lowerIndex];\n k++;\n j++;\n }\n }\n \n }\n \n \n /////////////////////////////////////////////////////////// Methods ////////////////////////////////////////////////////////////////////////\n \n \n static boolean isPal(String s)\n {\n for(int i=0, j=s.length()-1;i<=j;i++,j--)\n {\n if(s.charAt(i)!=s.charAt(j)) return false;\n }\n return true;\n }\n static String rev(String s)\n {\n StringBuilder sb=new StringBuilder(s);\n sb.reverse();\n return sb.toString();\n }\n static int gcd(int a,int b){return (a==0)?b:gcd(b%a,a);}\n static long gcdExtended(long a,long b,long[] x)\n {\n \n if(a==0){\n x[0]=0;\n x[1]=1;\n return b;\n }\n long[] y=new long[2];\n long gcd=gcdExtended(b%a, a, y);\n \n x[0]=y[1]-(b/a)*y[0];\n x[1]=y[0];\n \n return gcd;\n }\n \n boolean findSum(int set[], int n, long sum)\n {\n if (sum == 0)\n return true;\n if (n == 0 && sum != 0)\n return false;\n if (set[n-1] > sum)\n return findSum(set, n-1, sum);\n return findSum(set, n-1, sum) ||findSum(set, n-1, sum-set[n-1]);\n }\n \n public static long modPow(long base, long exp, long mod)\n {\n base = base % mod;\n long result = 1;\n while (exp > 0)\n {\n if (exp % 2 == 1) \n {\n result = (result * base) % mod;\n }\n base = (base * base) % mod;\n exp = exp >> 1;\n }\n return result;\n }\n \n static long[] fac;\n static long[] inv;\n static long mod=(long)1e9+7;\n public static void cal() \n {\n fac = new long[1000005];\n inv = new long[1000005];\n fac[0] = 1;\n inv[0] = 1;\n for (int i = 1; i <= 1000000; i++)\n {\n fac[i] = (fac[i - 1] * i) % mod;\n inv[i] = (inv[i - 1] * modPow(i, mod - 2, mod)) % mod;\n }\n }\n \n public static long ncr(int n, int r) \n {\n return (((fac[n] * inv[r]) % mod) * inv[n - r]) % mod;\n }\n \n \n////////////////////////////////////////// Input Reader ////////////////////////////////////////////////////////////////////////////////////////////////////\n \n static InputReader sc = new InputReader(System.in);\n static PrintWriter out= new PrintWriter(System.out); \n \n static class InputReader {\n \n private final InputStream stream;\n private final byte[] buf = new byte[8192];\n private int curChar, snumChars;\n private SpaceCharFilter filter;\n \n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n \n public int snext()\n {\n if (snumChars == -1)\n throw new InputMismatchException();\n if (curChar >= snumChars) {\n curChar = 0;\n try {\n snumChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (snumChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n \n public int nextInt()\n {\n int c = snext();\n while (isSpaceChar(c)) \n {\n c = snext();\n }\n int sgn = 1;\n if (c == '-')\n {\n sgn = -1;\n c = snext();\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 = snext();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n \n public long nextLong() \n {\n int c = snext();\n while (isSpaceChar(c)) \n {\n c = snext();\n }\n int sgn = 1;\n if (c == '-') \n {\n sgn = -1;\n c = snext();\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 = snext();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n \n public int[] nextIntArray(int n)\n {\n int a[] = new int[n];\n for (int i = 0; i < n; i++) \n {\n a[i] = nextInt();\n }\n return a;\n }\n \n public long[] nextLongArray(int n)\n {\n long a[] = new long[n];\n for (int i = 0; i < n; i++) \n {\n a[i] = nextLong();\n }\n return a;\n }\n \n \n public String nextLine()\n {\n int c = snext();\n while (isSpaceChar(c))\n c = snext();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = snext();\n } while (!isEndOfLine(c));\n return res.toString();\n }\n \n public boolean isSpaceChar(int c) \n {\n if (filter != null)\n return filter.isSpaceChar(c);\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n \n private boolean isEndOfLine(int c) \n {\n return c == '\\n' || c == '\\r' || c == -1;\n }\n \n public interface SpaceCharFilter \n {\n public boolean isSpaceChar(int ch);\n }\n \n }\n \n static int i()\n {\n return sc.nextInt();\n }\n static long l(){\n return sc.nextLong();\n }\n static int[] iarr(int n)\n {\n return sc.nextIntArray(n);\n }\n static long[] larr(int n)\n {\n return sc.nextLongArray(n);\n }\n static String s(){\n return sc.nextLine();\n }\n \n \n } ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "71fd1744e217275b5e48560c7eba3373", "src_uid": "b62338bff0cbb4df4e5e27e1a3ffaa07", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class BigInfo\n{\npublic static void main(String[] args)\n{\nScanner sc = new Scanner(System.in);\nint a = sc.nextInt();\nint res = {1,1,0,0,1,0,1,0,1,1,1,0,0,1,0,1,0};\nSystem.out.print(res[a]);\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bf4534765bbcc2d082f3cb6e57d0361f", "src_uid": "6f9767b63a01424f939d85b597cf42f3", "difficulty": 1700.0} {"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\n\npublic class B236_EasyNumberChallenge {\n public static void main(String[] arg) {\n FastReader sc = new FastReader();\n\n int a = sc.nextInt();\n int b = sc.nextInt();\n int c = sc.nextInt();\n\n long sum = 0;\n int[] usedDivisors = new int[a*b*c + 1];\n\n for (int i=1; i<=a; i++) {\n for (int j=1; j<=b; j++) {\n for (int k=1; k<=c; k++) {\n if (usedDivisors[i*j*k == 0]) {\n usedDivisors[i*j*k] = numDivisors(i*j*k);\n }\n sum += usedDivisors[i*j*k];\n }\n }\n }\n System.out.println(sum % 1073741824);\n }\n\n static int numDivisors(int i) {\n\n int numDivisors = 0;\n for (int j = 1; j < Math.sqrt(i); j++) {\n if (i % j == 0) {\n numDivisors += 2;\n }\n }\n if (i % Math.sqrt(i) == 0) {\n numDivisors++;\n }\n\n return numDivisors;\n }\n\n\n static class FastReader {\n BufferedReader br;\n StringTokenizer st;\n\n public FastReader() {\n br = new BufferedReader(new\n InputStreamReader(System.in));\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d17cb898e6d5502dab58c2603703f12f", "src_uid": "4fdd4027dd9cd688fcc70e1076c9b401", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "import java.awt.*;\nimport java.awt.event.*;\nimport java.awt.geom.*;\nimport java.io.*;\nimport java.math.*;\nimport java.text.*;\nimport java.util.*;\n\nimport static java.lang.Math.min;\nimport static java.lang.Math.max;\n\n/*\nbr = new BufferedReader(new FileReader(\"input.txt\"));\npw = new PrintWriter(new BufferedWriter(new FileWriter(\"output.txt\")));\nbr = new BufferedReader(new InputStreamReader(System.in));\npw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n */\n\npublic class Main {\n\tprivate static BufferedReader br;\n\tprivate static StringTokenizer st;\n\tprivate static PrintWriter pw;\n\n\tpublic static void main(String[] args) throws IOException\t{\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tpw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\t\tint qq = 1;\n\t\t//int qq = Integer.MAX_VALUE;\n\t\t//int qq = readInt();\n\t\tfor(int casenum = 1; casenum <= qq; casenum++)\t{\n\t\t\tMap map = new HashMap();\n\t\t\tfor(int i = 0; i < 6; i++) {\n\t\t\t\tint key = readInt();\n\t\t\t\tif(!map.containsKey(key)) map.put(key, 0);\n\t\t\t\tmap.put(key, 1 + map.get(key));\n\t\t\t}\n\t\t\tif(map.size() == 1) {\n\t\t\t\tpw.println(\"Elephant\");\n\t\t\t}\n\t\t\telse if(map.size() > 3) {\n\t\t\t\tpw.println(\"Alien\");\n\t\t\t}\n\t\t\telse if(map.size() == 3) {\n\t\t\t\tboolean four = false;\n\t\t\t\tfor(int out: map.keySet()) {\n\t\t\t\t\tif(map.get(out) == 4) {\n\t\t\t\t\t\tfour = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(four) {\n\t\t\t\t\tpw.println(\"Bear\");\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tpw.println(\"Alien\");\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tboolean four = false;\n\t\t\t\tboolean fine = false;\n\t\t\t\tfor(int out: map.keySet()) {\n\t\t\t\t\tif(map.get(out) == 4) {\n\t\t\t\t\t\tfour = true;\n\t\t\t\t\t}\n\t\t\t\t\tif(map.get(out) == 5) {\n\t\t\t\t\t\tfour = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(five) {\n\t\t\t\t\tpw.println(\"Bear\");\n\t\t\t\t}\n\t\t\t\telse if(four) {\n\t\t\t\t\tpw.println(\"Elephant\");\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tpw.println(\"Alien\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tpw.close();\n\t}\n\n\tprivate static void exitImmediately()\t{\n\t\tpw.close();\n\t\tSystem.exit(0);\n\t}\n\n\tprivate static long readLong() throws IOException\t{\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tprivate static double readDouble() throws IOException\t{\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tprivate static int readInt() throws IOException\t{\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tprivate static String nextToken() throws IOException\t{\n\t\twhile(st == null || !st.hasMoreTokens())\t{\n\t\t\tif(!br.ready())\t{\n\t\t\t\texitImmediately();\n\t\t\t}\n\t\t\tst = new StringTokenizer(br.readLine().trim());\n\t\t}\n\t\treturn st.nextToken();\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4f30d62400fe00c3cd04cceb467b48dd", "src_uid": "43308fa25e8578fd9f25328e715d4dd6", "difficulty": 1100.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class Main {\n\tstatic long a[]={1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8092, 16184,\n\t\t\t32368, 64736, 129472, 258944, 517888, 1035776, 2071552, 4143104, 8286208,\n\t\t\t16572416, 33144832, 66289664, 132579328, 265158656, 530317312, 1060634624,\n\t\t\t2121269248, 4242538496, 8485076992, 16970153984, 33940307968};\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t System.out.println(a[n]);\n\t\t\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "71fae0ff8be07c7f7edbc869e0127d5c", "src_uid": "76f6ebfaeea789952c931d65c6a5fdff", "difficulty": 1900.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class cf30b {\n public static void main(String[] args) {\n FastIO in = new FastIO(), out = in;\n String[] v2 = in.next().trim().split(\"[.]\");\n String[] v1 = in.next().trim().split(\"[.]\");\n boolean ok = false;\n ok |= go(new String[]{v1[0],v1[1],v1[2]}, v2);\n ok |= go(new String[]{v1[0],v1[2],v1[1]}, v2);\n ok |= go(new String[]{v1[1],v1[0],v1[2]}, v2);\n ok |= go(new String[]{v1[1],v1[2],v1[0]}, v2);\n ok |= go(new String[]{v1[2],v1[0],v1[1]}, v2);\n ok |= go(new String[]{v1[2],v1[1],v1[0]}, v2);\n out.println(ok?\"YES\":\"NO\");\n out.close();\n }\n static int[] day = {31,28,31,30,31,30,31,31,30,31,30,31};\n static boolean isValid(int d, int m, int y) {\n if(m <= 0 || m > 12) return false;\n int maxdays = day[m-1];\n if(isLeapYear(y) && m == 2) maxdays++;\n return d > 0 && d <= maxdays;\n }\n static boolean isLeapYear(int y) {\n return y%4 == 0;\n }\n static boolean go(String[] a, String[] b) {\n int d1 = Integer.parseInt(a[0]);\n int m1 = Integer.parseInt(a[1]);\n int y1 = 2000+Integer.parseInt(a[2]);\n int d2 = Integer.parseInt(b[0]);\n int m2 = Integer.parseInt(b[1]);\n int y2 = 2000+Integer.parseInt(b[2]);\n if(!isValid(d1,m1,y1)) return false;\n y1+=18;\n if(y1 < y2) return true;\n if(y1 > y2) return false;\n if(m1 < m2) return true;\n if(m1 > m2) return false;\n return d1 <= d2;\n }\n static class FastIO extends PrintWriter {\n BufferedReader br;\n StringTokenizer st;\n\n public FastIO() {\n this(System.in, System.out);\n }\n\n public FastIO(InputStream in, OutputStream out) {\n super(new BufferedWriter(new OutputStreamWriter(out)));\n br = new BufferedReader(new InputStreamReader(in));\n scanLine();\n }\n\n public void scanLine() {\n try {\n st = new StringTokenizer(br.readLine().trim());\n } catch (Exception e) {\n throw new RuntimeException(e.getMessage());\n }\n }\n\n public int numTokens() {\n if (!st.hasMoreTokens()) {\n scanLine();\n return numTokens();\n }\n return st.countTokens();\n }\n\n public String next() {\n if (!st.hasMoreTokens()) {\n scanLine();\n return next();\n }\n return st.nextToken();\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2e9294838562ffe3b4824d2af9d87321", "src_uid": "5418c98fe362909f7b28f95225837d33", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class laddering {\n\npublic static void main(String[] args) {\n\n\nScanner sc = new Scanner(System.in);\n\nint a = sc.nextInt();\nint b = sc.nextInt();\n\nSystem.out.println(Math.max(a,b)-1 + \" \" + Math.min(a,b);\n\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c9cacc60680feed2f61427380ec501db", "src_uid": "c8378e6fcaab30d15469a55419f38b39", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "\nimport java.util.*;\n\n\npublic class E\n{\n public static void main(String[] args)\n {\n new E(new Scanner(System.in));\n }\n\n int N, M;\n int[][][] memo;\n\n int go(int i, int j, int mask)\n {\n if (i == N)\n return go(0, j+1, mask);\n if (j == M)\n {\n int mm = mask%(1< 0)\n prevMask = 1 << (N-2);\n int nextMask = 0;\n if (i < (N-1))\n nextMask = 1 << (N);\n int curMask = 1 << (N-1);\n int nextRowMask = 1 << (N+N);\n nMask = nMask|prevMask|nextMask|curMask|nextRowMask;\n int rr = 1+go(i+1, j, nMask);\n if (rr < res)\n res = rr;\n \n memo[i][j][mask] = res;\n return res;\n }\n\n public E(Scanner in)\n {\n int[] vals = new int[2];\n vals[0] = in.nextInt();\n vals[1] = in.nextInt();\n Arrays.sort(vals);\n\n N = vals[0];\n M = vals[1];\n memo = new int[N][M][1<<(N+N+1)];\n fill3(memo, -1);\n \n int r1 = go(0, 0, (1< set=new HashSet<>();\n\t for(int i=0;i=4*a + 2*b)\n\t\t\t\tbars = 1 ; \n\t\t\telse if(n>=3*a + b + max)\n\t\t\t\tbars = 2 ; \n\t\t\telse if(n>=3*a + b + min)\n\t\t\t\tbars = 2 ;\n\t\t\telse if(n>=2*a + b + max)\n\t\t\t\tbars = 2 ;\n\t\t\telse if(n>=2*a + b + min)\n\t\t\t\tbars = 2 ;\n\t\t\telse if(n>=a + b + max)\n\t\t\t\tbars = 2 ;\n\t\t\telse if(n>=a + b + min)\n\t\t\t\tif(min==a)\n\t\t\t\t\tbars = 2 ;\n\t\t\t\telse\n\t\t\t\t\tif (n>2*a)\n\t\t\t\t\t\tbars =3 ; \n\t\t\t\t\telse\n\t\t\t\t\t\tbars=4 ; \n\t\t\telse if(n>=a + b)\n\t\t\t\tif(n>=2*a)\n\t\t\t\t\tbars = 3 ; \n\t\t\t\telse\n\t\t\t\t\tbars = 4 ; \n\t\t\telse bars =6 ; \n\n\t\t\tout.print(bars);\n\n\n\t\t}\n\t\tpublic static boolean isPrime (long num){\n\t\t\tif (num < 2) return false;\n\t\t\tif (num == 2) return true;\n\t\t\tif (num % 2 == 0) return false;\n\t\t\tfor (long i = 3*1l; i * i <= num; i += 2)\n\t\t\t\tif (num % i == 0) return false;\n\t\t\treturn true;\n\t\t}\n\t}\n\tstatic class InputReader {\n\t\tpublic BufferedReader\treader;\n\t\tpublic StringTokenizer\ttokenizer;\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{\n\t\t\t\ttry\n\t\t\t\t{\n\t\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t} catch (IOException e)\n\t\t\t\t{\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t}\n\tstatic class Vertix{\n\t\tint x ; \n\t\tArrayList children; \n\t\tVertix parent; \n\n\t\tpublic Vertix(int x){\n\t\t\tthis.x = x ;\n\t\t\tthis.children= new ArrayList();\n\t\t}\n\n\t}\n\n\tstatic class Pair implements Comparable {\n\t\tint x ; \n\t\tint y ; \n\n\t\tpublic Pair(int x, int y) {\n\t\t\tthis.x = x ;\n\t\t\tthis.y = y ; \n\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Pair p) {\n\t\t\tif (this.x < p.x)\n\t\t\t\treturn -1;\n\t\t\telse if (this.x > p.x)\n\t\t\t\treturn 1;\n\t\t\telse\n\t\t\t\treturn 0;\n\n\t\t}\n\t\t//\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4f8d218d9bc6d72bdb15a56189de65f7", "src_uid": "1a50fe39e18f86adac790093e195979a", "difficulty": 1600.0} {"lang": "Java 11", "source_code": "import java.util.Scanner;\n\npublic class Main {\n private static final Scanner scanner = new Scanner(System.in);\n\n public static void main(String[] args) {\n int n = scanner.nextInt(), a = 1, r = 0, aa = 2\n while (n - a >= 0) {\n n = n - a;\n a = a + aa;\n aa++;\n r++;\n }\n System.out.println(r);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f565a78be2b92a8ddcfe7393e20e2397", "src_uid": "873a12edffc57a127fdfb1c65d43bdb0", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.HashSet;\nimport java.util.Scanner;\nimport java.util.Set;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.lang.Math; \n\npublic class Lo {\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n double a = sc.nextInt();\n double b = sc.nextInt();\n double c = sc.nextInt();\n double s1 = math.sqrt(a*(b/c));\n double s2 = b/s1;\n double s3 = c/s2;\n System.out.println((int)(6*(s1+s2+s3)));\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e92c3fab04a3700fe208121df7abaa97", "src_uid": "c0a3290be3b87f3a232ec19d4639fefc", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class A697b\n{\n\tpublic static void main(String...arg)\n\t{\n\t\tScanner sc=new Scanner(System.in);\n\t\tlong d=0,i,t,s,x,c=0,k;\n\t\tt=sc.nextInt();\n\t\ts=sc.nextInt();\n\t\tx=sc.nextInt();\n\t\tif(x==t)\n\t\t\td=1;\n\t\t\n\t\tif((x=s)\t\t\t\n\t\t{\n\t\tif((x-t)%s==0)\n\t\t\t{\n\t\t\t\tc=1;\n\t\t\t}\n\t\telse if((x-t-1)%s==0)\n\t\t{\n\t\t\tc=1;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tc=0;\n\t\t}}\n\t\t\n\t\t\t\n\n\t\tif((c==1)||(d==1))\n\t\t{\n\t\t\tSystem.out.println(\"YES\");\n\t\t}}}\n\t\telse\n\t\t\tSystem.out.println(\"NO\");\n\t\t\n\t}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "82a3d8000780aab089b739377ec6c41d", "src_uid": "3baf9d841ff7208c66f6de1b47b0f952", "difficulty": 900.0} {"lang": "Java 7", "source_code": "import java.util.*;\npublic class b256\n{\n\tpublic static void main(String ar[])\n\t{\n\t\tScanner obj=new Scanner(System.in);\n\t\tString s=obj.nextLine();\n\t\tString t=obj.nextLine();\n\t\tCharSequence t1=t;\n\t\tint ls=s.length();\n\t\tint lt=t.length();\n\t\tint arr[]=new int[26];\n\t\tArrays.fill(arr,0);\n\t\tfor(int i=0;i 0; i--) {\n w = w + i;\n if (i == u1) {\n w = w - d1;\n } else if (i == u2) {\n w = w - d2;\n }\n }\n\n System.out.println(w);\n\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ab4edb3186885ebc8f8d1e1d86782271", "src_uid": "084a12eb3a708b43b880734f3ee51374", "difficulty": 800.0} {"lang": "Java 7", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\nimport jdk.nashorn.internal.ir.Flags;\n\n\npublic class Pangram {\npublic static void main (String[]args) throws NumberFormatException, IOException{\n BufferedReader br =new BufferedReader(new InputStreamReader(System.in));\nint n=Integer.parseInt(br.readLine()) ;\n if (n<26) {\n System.out.println(\"NO\");\n }else{\n char[] c=new char[26];\n c[0]='a';\n for (int i = 1; i < c.length; i++) {\n c[i]=(char) (c[i-1]+1);\n \n }\n String s=br.readLine();\n String m=s.toLowerCase();\n //System.out.println(m);\n Boolean flag=false;\n for (int i = 0; i < c.length; i++) {\n flag=false;\n \n for (int j = 0; j < m.length(); j++) {\n if (c[i]==m.charAt(j)) {\n flag=true;\n break;\n }\n }\n if (flag==false) {\n System.out.println(\"NO\");\n break;\n }\n \n }\n if(flag)\n System.out.println(\"YES\");\n \n \n \n \n }\n \n}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4a6d1c98949ca8d6f4b6b404f3ddd223", "src_uid": "f13eba0a0fb86e20495d218fc4ad532d", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n/**\n * @author stran\n * @version 1.0 (14/06/2016).\n */\npublic class P678B_SameCalendar {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n int y = scanner.nextInt(),\n next = y, sumOdd = (isLeapYear(next) ? 2 : 1);\n boolean yLeap = isLeapYear(y),\n nextLeap;\n\n do {\n next++;\n sumOdd += (isLeapYear(next) ? 2 : 1);\n nextLeap = isLeapYear(next + 1);\n } while (sumOdd % 7 != 0 || nextLeap != yLeap);\n\n System.out.println(next + 1);\n }\n\n private static boolean isLeapYear(int year) {\n return (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0));\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c1e88af308b527fe91c233774d6fa211", "src_uid": "565bbd09f79eb7bfe2f2da46647af0f2", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "mport java.util.*;\npublic class ninety_mins {\n\n\tpublic static void main(String args[])\n\t{\n\t\tScanner sc = new Scanner(System.in);\n\t\tint a = sc.nextInt();\n\t\tint inp[] = new int[a];\n\t\t\n\t\t\n\t\tfor(int i=0;i15)\n\t\t\t{\n\t\t\t\tSystem.out.println(\"15\");\n\t\t\t}\n\t\t \n\t\t \n\t\t \n\t\t \n\t\t \n\t\t else\n\t\t \n\t\t{\n\t\t\t \n\t\tfor(int i=1;i15 )\n\t\t\t{\n\t\t\t\tSystem.out.println(inp[i-1]+15);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tmax[i] = inp[i];\n\t\t\n\t\t\t}\n\t\t}\n\t\t \n\t\t if(max[a-1]!=0 )\n\t\t\t\n\t\t{\n\t\t\tSystem.out.println(90);\n\t\t}\n\t\t \n\t\t if(a==1 && inp[0] <=15 )\n\t\t\t\t\t{\n\t\t\t\t\t\tSystem.out.println(15+inp[a-1]);\n\t\t\t\t\t}\n\t\t\t\t\n\t\t\n\t/*\n\t\t\n\t\t*/\n\t\t\n\t\t\n}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0f1d359110790cce1a9c531767fb911d", "src_uid": "5031b15e220f0ff6cc1dd3731ecdbf27", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Main {\n\n\t// global\n\tstatic long fact[];\n\tstatic long inverse[];\n\tstatic int n;\n\tstatic int mod;\n\n\tstatic long pow(long a,int n) {\n\t long res=1;\n\t while (n>0) {\n\t if ((n-n/2*2)==1) {\n\t res=res*a%mod;\n\t }\n\t a=a*a%mod;\n\t n>>=1;\n\t }\n\t return res;\n\t}\n\n\tstatic long modinv(long n) {\n\t return pow(n, mod-2);\n\t}\n\n\tstatic long comb(int n,int k){\n\t if(n<0 || k<0 || n0)\n {\n int[][] arr= new int[100][2];\n int count=0;\n int index=0;\n int a=0;\n boolean sol=true;\n int n=in.nextInt();\n for(int i=1;i<=n;){\n \n a=in.nextInt();\n \n index=i;\n i++;\n arr[count][0]=index;\n while(a==0)\n {\n if(i<=n){\n a=in.nextInt();\n index++;\n i++;\n }\n else if(i==n+1)\n {\n continue;\n }\n else{\n \n sol=false;\n break;\n }\n }\n arr[count][1]=index;\n count++;\n \n }\n if(sol){\n out.println(\"YES\");\n out.println(count);\n for(int i=0;i= snumChars) {\n curChar = 0;\n try {\n snumChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (snumChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n \n public int nextInt() {\n int c = snext();\n while (isSpaceChar(c))\n c = snext();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = snext();\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 = snext();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n \n public long nextLong() {\n int c = snext();\n while (isSpaceChar(c))\n c = snext();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = snext();\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 = snext();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n \n public int[] nextIntArray(int n) {\n int a[] = new int[n];\n for (int i = 0; i < n; i++)\n a[i] = nextInt();\n return a;\n }\n \n public String readString() {\n int c = snext();\n while (isSpaceChar(c))\n c = snext();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = snext();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public String next() {\n return readString();\n }\n \n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n \n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "48f44b452672ae9f83c3b347febf8e7b", "src_uid": "3a9258070ff179daf33a4515def9897a", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Main {\n\n public static void main(String[] args) throws IOException{\n\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));\n Scanner sc=new Scanner(System.in);\n String[] s=br.readLine().split(\" \");\n long a1=Long.parseLong(s[0]);\n long b1=Long.parseLong(s[1]);\n if(a1==b1)bw.write(\"=\");\n else\n if(a1==1)\n bw.write(\"<\");\n else \n if(b1==1)\n bw.write(\">\");\n else \n if(a1==2)\n {\n if(b1==3)\n bw.write(\"<\");\n else\n if(b1==4)\n bw.write(\"=\");\n else\n bw.write(\">\");\n }\n else\n if(b1==2)\n {\n if(a1==3)\n bw.write(\"<\");\n else\n if(a1==4)\n bw.write(\"=\");\n else\n bw.write(\">\");\n }\n else\n if(x>y)\n bw.write(\">\");\n else\n if(y>x)\n bw.write(\"<\");\n bw.flush();\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d673384c9856d8c59cac1b915a369737", "src_uid": "ec1e44ff41941f0e6436831b5ae543c6", "difficulty": 1100.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.math.*;\nimport java.io.*;\n\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\npublic class C{\n Scanner sc=new Scanner(System.in);\n\n int INF=1<<28;\n double EPS=1e-9;\n\n String line;\n int n, m;\n\n void run(){\n int range=210;\n\n line=sc.nextLine();\n n=sc.nextInt();\n m=line.length();\n\n char[] cs=line.toCharArray();\n\n int[][][][] dp=new int[range][range][4][n+1];\n dp[range/2][range/2][0][0]=1;\n int[][][][] dp2=new int[range][range][4][n+1];\n\n int[] dx={-1, 0, 1, 0};\n int[] dy={0, 1, 0, -1};\n\n boolean[][][] visit=new boolean[m+1][range][range];\n visit[0][range/2][range/2]=true;\n\n for(int k=0; k=range-1){\n continue;\n }\n if(y<1||y>=range-1){\n continue;\n }\n if(!visit[k][y][x]){\n continue;\n }\n for(int d=0; d<4; d++){\n for(int i=0; i{\n int x, y;\n\n P(int x, int y){\n this.x=x;\n this.y=y;\n }\n\n @Override\n public int compareTo(P p){\n if(y!=p.y){\n return y-p.y;\n }else{\n return x-p.x;\n }\n }\n }\n\n void run2(){\n line=sc.nextLine();\n n=sc.nextInt();\n int m=line.length();\n\n int countT=0;\n for(int i=0; imax){\n max=abs(x)+abs(y);\n index=i;\n }\n }\n debug(max);\n if(j==n-1){\n ans=max(ans, max);\n }\n cs[index]=cs[index]=='F'?'T':'F';\n debug(j, cs);\n }\n println(ans+\"\");\n }\n\n void run_(){\n char[] cs;\n int[] dx={-1, 0, 1, 0};\n int[] dy={0, 1, 0, -1};\n\n int max=0;\n String best=null;\n for(int sup=0; sup<1<>i&1)==1){\n if(cs[i]=='F'){\n cs[i]='T';\n }else{\n cs[i]='F';\n }\n }\n }\n int x=0, y=0;\n int d=0;\n for(int i=0; imax){\n max=abs(x)+abs(y);\n best=new String(cs);\n }\n }\n }\n debug(line);\n debug(best);\n debug(\"run_\", max);\n }\n\n void println(String s){\n System.out.println(s);\n }\n\n void print(String s){\n System.out.print(s);\n }\n\n void debug(Object... os){\n // System.err.println(Arrays.deepToString(os));\n }\n\n public static void main(String[] args){\n new C().run();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "888229c86ab7fcdc7b50d25f2dbec434", "src_uid": "4a54971eb22e62b1d9e6b72f05ae361d", "difficulty": 1800.0} {"lang": "Java 7", "source_code": "public class abc{\n\n public static void Main(String[] args) {\n\n int a;\n int b;\n int answer = 0;\n int mod = 0;\n\n Scanner in = new Scanner(System.in);\n a = in.nextInt();\n b = in.nextInt();\n if (a < b) {\n System.out.print(0);\n }\n else {\n answer += a;\n\n while (a > 0) {\n\n if (a >= b) {\n\n mod = a % b;\n\n a = a / b;\n answer += a;\n\n a = a + mod;\n\n }\n else {\n break;\n }\n\n }\n System.out.print(answer);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b67ad2d4c06fae31f59e8998ed6d9c33", "src_uid": "a349094584d3fdc6b61e39bffe96dece", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class A1{\n public static void main(String[] args){\n Scanner s=new Scanner(System.in);\n long r=s.nextInt();\n long finalx=-1,finaly=-1;\n for(long x=1;x<=(int)1e6;i++){\n long temp=r-x*x-x-1;\n if(temp!=0&&temp%(2*x)==0){\n finaly=temp;\n break;\n }\n }\n if(finalx!=-1 && finaly!=-1)System.out.println(finalx+\" \"+finaly);\n else System.out.println(\"NO\");\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ec16937e34a8c5defff776e9fcc78ef9", "src_uid": "3ff1c25a1026c90aeb14d148d7fb96ba", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "mport java.util.*;\n\npublic class Main5 {\n\tpublic static void main(String[] args) {\n\t // Use the Scanner class\n\t try{\n\t Scanner sc = new Scanner(System.in); \n\t String s=sc.next();\n\t int r=0,v=0;\n\t for(int i=0; i0) r++;\n\t System.out.println(r);\n\t }\n\t catch(NoSuchElementException e){\n\t \n\t }\n\t }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f9988ac06662349f67cfbdb8eb47dff9", "src_uid": "578bae0fe6634882227ac371ebb38fc9", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class CF618A\n{\n public static void main(String[] args)\n {\n Scanner scan=new Scanner(System.in);\n int n=scan.nextInt();\n int temp=n;\n int l=0;\n while(temp>0)\n {\n temp>>=1;\n ++l\n }\n temp=1<<(l-1);\n String s=\"\";\n for(int i=l;i>0;--i)\n {\n if(n&temp!=0)\n s+=(s.lenth==0?i:(\" \"+i));\n temp>>=1;\n }\n System.out.print(s);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b6a98328cb6c9d1ec7610bad6a43dc18", "src_uid": "757cd804aba01dc4bc108cb0722f68dc", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class again3\n{\n public static void main(String args[])\n {\n Scanner ex=new Scanner(System.in);\n int n=ex.nextInt();\n int m=ex.nextInt();\n int dig[]=new int[10];\n int arrn[][]=new int[n][2];\n int arrm[][]=new int[m][2];\n for(int i=0;i0)\n {\n count++;\n num=i;\n }\n }\n if(count>1)\n System.out.println(\"0\");\n else\n System.out.println(num);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a6ae2e31c83676193e60fbb537726db0", "src_uid": "cb4de190ae26127df6eeb7a1a1db8a6d", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class code2 {\n\tInputStream is;\n\tPrintWriter out;\n\tArrayList al[];\n\tlong mod=(int)Math.pow(10,9)+7;\n\tint dp[][][][][],a[];\n\tvoid solve()\n\t{\n\t\tint n=ni();\n\t\ta=na(n);\n\t\tdp=new int[310+1][310+1][5][8][n];\n\t\tvisited=new boolean[310+1][310+1];\n\t\trec(155,155,a[0],2,0);\n\t\tint count=0;\n\t\tfor(int i=0;i<=310;i++)\n\t\t{\n\t\t\tfor(int j=0;j<=310;j++)\n\t\t\t{\n\t\t\t\tif(visited[i][j])\n\t\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\t\tout.print(count);\n\t}\n\tboolean visited[][];\n\tvoid rec(int x,int y,int used,int dir,int level)\n\t{\n\t\t//if(used<0||level>=a.length)\n\t\t\t//return;\n\t\tif(dp[x][y][used][dir][level]!=0)\n\t\t\treturn ;\n\t\tvisited[x][y]=true;\n\t\tdp[x][y][used][dir][level]=1;\n\t\tif(used!=1)\n\t\t{\n\t\t\tint gox=x+getx(dir);\n\t\t\tint goy=y+gety(dir);\n\t\t\trec(gox,goy,used-1,dir,level);\n\t\t}else{\n\t\t\tif(level+1=1){\n\t\t\tint mid = (l+r)/2;\n\t\t\tmergeSort(arr,l,mid);\n\t\t\tmergeSort(arr,mid+1,r);\n\t\t\tmerge(arr,l,r,mid);\n\t\t}\n\t}\n\tpublic static void merge(int arr[], int l, int r, int mid){\n\t\tint n1 = (mid-l+1), n2 = (r-mid);\n\t\tint left[] = new int[n1];\n\t\tint right[] = new int[n2];\n\t\tfor(int i =0 ;iright[j]){\n\t\t\t\tarr[k++] = right[j++];\n\t\t\t}\n\t\t\telse{\n\t\t\t\tarr[k++] = left[i++];\n\t\t\t}\n\t\t}\n\t\twhile(i=1){\n\t\t\tint mid = (l+r)/2;\n\t\t\tmergeSort(arr,l,mid);\n\t\t\tmergeSort(arr,mid+1,r);\n\t\t\tmerge(arr,l,r,mid);\n\t\t}\n\t}\n\tpublic static void merge(long arr[], int l, int r, int mid){\n\t\tint n1 = (mid-l+1), n2 = (r-mid);\n\t\tlong left[] = new long[n1];\n\t\tlong right[] = new long[n2];\n\t\tfor(int i =0 ;iright[j]){\n\t\t\t\tarr[k++] = right[j++];\n\t\t\t}\n\t\t\telse{\n\t\t\t\tarr[k++] = left[i++];\n\t\t\t}\n\t\t}\n\t\twhile(i{\n\t\t \n\t int x,y,k,i;\n\t \n\t\tPair (int x,int y){\n\t\t\tthis.x=x;\n\t\t\tthis.y=y;\n\t\t}\n\t \n\t\tpublic int compareTo(Pair o) {\n\t\t\t\t\treturn this.y-o.y;\n\t\t}\n\t \n\t public boolean equals(Object o) {\n\t if (o instanceof Pair) {\n\t Pair p = (Pair)o;\n\t return p.x == x && p.y == y && p.k==k;\n\t }\n\t return false;\n\t }\n\t \n\t \n\t @Override\n\t public String toString() {\n\t return \"(\"+x + \" \" + y +\" \"+k+\" \"+i+\" )\";\n\t }\n\t \n\t } \n\t \n\t public static boolean isPal(String s){\n\t for(int i=0, j=s.length()-1;i<=j;i++,j--){\n\t if(s.charAt(i)!=s.charAt(j)) return false;\n\t }\n\t return true;\n\t }\n\t public static String rev(String s){\n\t\t\tStringBuilder sb=new StringBuilder(s);\n\t\t\tsb.reverse();\n\t\t\treturn sb.toString();\n\t }\n\t \n\t public static long gcd(long x,long y){\n\t\tif(y==0)\n\t\t\treturn x;\n\t\telse\n\t\t\treturn gcd(y,x%y);\n\t }\n\t \n\t public static int gcd(int x,int y){\n\t \tif(y==0) \n\t \t\treturn x; \n\t \treturn gcd(y,x%y);\n\t }\n\t \n\t public static long gcdExtended(long a,long b,long[] x){\n\t \n\t if(a==0){\n\t x[0]=0;\n\t x[1]=1;\n\t return b;\n\t }\n\t long[] y=new long[2];\n\t long gcd=gcdExtended(b%a, a, y);\n\t \n\t x[0]=y[1]-(b/a)*y[0];\n\t x[1]=y[0];\n\t \n\t return gcd;\n\t }\n\t \n\t public static int abs(int a,int b){\n\t\treturn (int)Math.abs(a-b);\n\t }\n\t \n\t public static long abs(long a,long b){\n\t\treturn (long)Math.abs(a-b);\n\t }\n\t \n\t public 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\t \n\t public 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\t \n\t public 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\t \n\t public 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\t \n\t public static long pow(long n,long p,long m){\n\t\t long result = 1;\n\t\t if(p==0)\n\t\t return 1;\n\t\tif (p==1)\n\t\t return n;\n\t\twhile(p!=0)\n\t\t{\n\t\t if(p%2==1)\n\t\t result *= n;\n\t\t if(result>=m)\n\t\t result%=m;\n\t\t p >>=1;\n\t\t n*=n;\n\t\t if(n>=m)\n\t\t n%=m;\n\t\t}\n\t\treturn result;\n\t }\n\t \n\t public static long pow(long n,long p){\n\t\tlong result = 1;\n\t\t if(p==0)\n\t\t return 1;\n\t\tif (p==1)\n\t\t return n;\n\t\twhile(p!=0)\n\t\t{\n\t\t if(p%2==1)\n\t\t result *= n;\t \n\t\t p >>=1;\n\t\t n*=n;\t \n\t\t}\n\t\treturn result;\n\t }\n\t public static void debug(Object... o) {\n\t\t\tSystem.out.println(Arrays.deepToString(o));\n\t\t}\n\t void run() throws Exception {\n\t\t\tis = System.in;\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t\tout.flush();\n\t\t}\n\t \n\t public static void main(String[] args) throws Exception {\n\t \tnew Thread(null, new Runnable() {\n\t\t\t\tpublic void run() {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tnew code2().run();\n\t\t\t\t\t} catch (Exception e) {\n\t\t\t\t\t\te.printStackTrace();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}, \"1\", 1 << 26).start();\n\t\t\t\n\t \t//new code2().run();\n\t\t}\n\n\t private byte[] inbuf = new byte[1024];\n\t\tpublic int lenbuf = 0, ptrbuf = 0;\n\t \n\t\tprivate int 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\t \n\t\tprivate boolean isSpaceChar(int c) {\n\t\t\treturn !(c >= 33 && c <= 126);\n\t\t}\n\t \n\t\tprivate int skip() {\n\t\t\tint b;\n\t\t\twhile ((b = readByte()) != -1 && isSpaceChar(b));\n\t\t\treturn b;\n\t\t}\n\t \n\t\tprivate double nd() {\n\t\t\treturn Double.parseDouble(ns());\n\t\t}\n\t \n\t\tprivate char nc() {\n\t\t\treturn (char) skip();\n\t\t}\n\t \n\t\tprivate String ns() {\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\t \n\t\tprivate char[] ns(int n) {\n\t\t\tchar[] buf = new char[n];\n\t\t\tint b = skip(), p = 0;\n\t\t\twhile (p < n && !(isSpaceChar(b))) {\n\t\t\t\tbuf[p++] = (char) b;\n\t\t\t\tb = readByte();\n\t\t\t}\n\t\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t\t}\n\t \n\t\tprivate char[][] nm(int n, int m) {\n\t\t\tchar[][] map = new char[n][];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tmap[i] = ns(m);\n\t\t\treturn map;\n\t\t}\n\t \n\t\tprivate int[] na(int n) {\n\t\t\tint[] a = new int[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\ta[i] = ni();\n\t\t\treturn a;\n\t\t}\n\t \n\t\tprivate int ni() {\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\t \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\t \n\t\tprivate long nl() {\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\t \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\t \n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c8e82189c54a7a1bcf30e8ce9d8551e5", "src_uid": "a96bc7f93fe9d9d4b78018b49bbc68d9", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n 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 int N = in.nextInt();\n int M = in.nextInt();\n char[] s = in.next().toCharArray();\n char[] t = in.next().toCharArray();\n int wildCardLoci = 1000000;\n if (N - 1 > M) {\n out.println(\"NO\");\n return;\n }\n for (int i = 0; i < s.length; i++) {\n if (i >= M || s[i] != t[i]) {\n if (s[i] != '*') {\n out.println(\"NO\");\n return;\n }\n wildCardLoci = i;\n break;\n }\n }\n if (wildCardLoci == 1000000 && N != M) {\n out.println(\"NO\");\n return;\n }\n for (int i = N - 1; i > wildCardLoci; i--) {\n if ((t[M - (N - i)] != s[i])) {\n out.println(\"NO\");\n return;\n }\n }\n out.println(\"YES\");\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2bf12d9017044a073ccd92245f28f557", "src_uid": "98624ab2fcd2a50a75788a29e04999ad", "difficulty": 1000.0} {"lang": "Java 7", "source_code": "public class A {\n\n\tpublic static void main(String[] args) {\n\t\tScanner s = new Scanner(System.in);\n\t\tint x= s.nextInt();\n\t\ts.next();\n\t\tString info = s.next();\n\t\tboolean isWeek = info.equals(\"week\")?true:false ;\n\t\t\n\t\tif (isWeek){\n\t\t\tif (x == 5 || x == 6){\n\t\t\t\tSystem.out.println(53);\n\t\t\t}else{\n\t\t\t\tSystem.out.println(52);\n\t\t\t}\n\t\t}else{\n\t\t\tif (x == 31){\n\t\t\t\tSystem.out.println(7);\n\t\t\t}\n\t\t\telse if (x==30){\n\t\t\t\tSystem.out.println(11);\n\t\t\t}\n\t\t\telse{\n\t\t\t\tSystem.out.println(12);\n\t\t\t}\n\t\t}\n\t\ts.close();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2be45c98a223168726f6a42d5b0a58d8", "src_uid": "9b8543c1ae3666e6c163d268fdbeef6b", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.*;\npublic class Main{\n\tpublic static void main(String args[]){\n\t\tScanner sc = new Scanner(System.in);\n\t\tint x = sc.nextInt();\n\t\tif(x%2 == 0){\n\t\t\tSystem.out.println(\"home\");\n\t\t} else{\n\t\t\tSystem.out.println(\"contest\");\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "289444b37a2397ce27bc3250946385bc", "src_uid": "51d1c79a52d3d4f80c98052b6ec77222", "difficulty": 900.0} {"lang": "Java 7", "source_code": "import java.awt.Point;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class A {\n\n\tpublic static void main(String[] args) {\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tScanner sc = new Scanner(System.in);\n\n\t\tint X = sc.nextInt();\n\t\tint Y = sc.nextInt();\n\n\t\t// 0 = right\n\t\t// 1 = up\n\t\t// 2 = left\n\t\t// 3 = down\n\t\tint count = 0;\n\t\tint idx = 0;\n\t\tint dir = 0;\n\t\tint factor = 1;\n\t\tPoint start = new Point(0, 0);\n\t\tint ans = 0;\n\t\tint[] x = { 1, 0, -1, 0 };\n\t\tint[] y = { 0, 1, 0, -1 };\n\t\twhile (start.x != X || start.y != Y) {\n\t\t\tstart.translate(factor * x[idx], factor * y[idx]);\n\t\t\tif (dir == 0 && idx == 0) {\n\n\t\t\t} else {\n\t\t\t\tdir++;\n\t\t\t\tans++;\n\t\t\t}\n\t\t\tidx++;\n\t\t\tif (idx == 4) {\n\t\t\t\tidx = 0;\n\t\t\t}\n\t\t\tcount++;\n\t\t\tif (count % 2 == 0 && count != 0)\n\t\t\t\tfactor++;\n\t\t}\n\n\t\tout.println(ans);\n\n\t\tsc.close();\n\t\tout.close();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f419c189bca186cd3074cdc06f8aad29", "src_uid": "2fb2a129e01efc03cfc3ad91dac88382", "difficulty": 1400.0} {"lang": "Java 11", "source_code": "import org.omg.Messaging.SYNC_WITH_TRANSPORT;\n\nimport javax.print.DocFlavor;\nimport java.util.*;\n\npublic class Solution {\n public static void main (String[] args) {\n\n Scanner input = new Scanner(System.in);\n String car = input.next();\n String k = \"qwertyuiopasdfghjkl;zxcvbnm,./\";\n String in = input.next();\n ArrayList bla = new ArrayList<>();\n for (int i = 0; i < k.length();i++) {\n bla.add(k.charAt(i));\n }\n String ans = \"\";\n if (car.equals(\"R\")) {\n for (int i = 0; i < in.length() ; i++) {\n ans += bla.get(bla.indexOf(in.charAt(i)) - 1);\n }\n } else {\n for (int i = 0; i < in.length() ; i++) {\n ans += bla.get(bla.indexOf(in.charAt(i)) +1);\n }\n }\n System.out.println(ans);\n\n\n\n\n }\n }\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "641cf726b90a69f4366da869617f596f", "src_uid": "df49c0c257903516767fdb8ac9c2bfd6", "difficulty": 900.0} {"lang": "Java 8", "source_code": "\n\nimport java.io.*;\nimport java.util.*;\npublic class B {\n public static void main(String[] args) throws Exception {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n String s=br.readLine();\n int i,j,k,len,n,flag=0;\n String s2;\n len=s.length();\n outer:for(i=0;i<=len-3;i++){\n for(j=i+1;j<=len-2;j++){\n for(k=j+1;k<=len-1;k++){\n s2=\"\";\n s2=s2+s.charAt(i)+s.charAt(j)+s.charAt(k);\n n=Integer.parseInt(s2.toString());\n if(n%8==0){\n System.out.println(\"YES\");\n System.out.println(n);\n flag=1;\n break outer;\n }\n }\n }\n }\n int a,b;\n if(len<=2){\n n=Integer.parseInt(s);\n if(n%8==0){\n System.out.println(\"YES\");\n System.out.println(n);\n flag=1;\n }\n\t}\n if (len==2 && (n%8)!=0) {\n a = Integer.parseInt(\"\" + s.charAt(0));\n b = Integer.parseInt(\"\" + s.charAt(1));\n if ((a == 0) || (a == 8)) {\n System.out.println(\"YES\");\n System.out.println(a);\n flag = 1;\n }\n else if ((b == 0) || (b == 8)) {\n System.out.println(\"YES\");\n System.out.println(b);\n flag = 1;\n\t\t\t\n }\n }\n }\n if(flag==0)\n System.out.println(\"NO\");\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "58955a807b5c57d845bd3e08c3e23c7c", "src_uid": "0a2a5927d24c70aca24fc17aa686499e", "difficulty": 1500.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\n\n\npublic class Main {\n\n public static void main(String args[]){\n MyScanner sc = new MyScanner();\n String s = sc.next();\n int x = sc.nextInt();\n int algarisms[] = new int[s.length()];\n int nAlgarisms=s.length();\n \n for(int i=0; i0 && i0; j--){\n int temp=algarisms[i+j];\n algarisms[i+j]=algarisms[i+j-1];\n algarisms[i+j-1]=temp;\n }\n i++;\n subArray = new int[x+1];\n\n }\n\n double result=0;\n for(int j=nAlgarisms-1; j>=0; j--){\n result+=Math.pow(10,j)*(double)(algarisms[nAlgarisms-1-j]);\n }\n System.out.println(String.format(\"%.0f\",result));\n //System.out.println(result);\n //System.out.println(Arrays.toString(algarisms));\n\n }\n\n public static int getMaxIndexArray(int array[]){\n int max = 0;\n int index = 0;\n for(int i=0; imax){\n max=array[i];\n index=i;\n } \n }\n\n return index;\n }\n\n public static int[] getSubArray(int array[], int startIndex, int plus){\n int newArray[] = new int[plus+1];\n int endIndex = startIndex+plus=i){\n m=m-i;\n i++;}\n else{\n System.out.println(m);\n break;\n }\n if(m==0)\n System.out.println(\"0\");\n if(i>n)\n i=1;\n }\n \n}}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "00f15b24e701bfaf8dfc3032910a9c09", "src_uid": "5dd5ee90606d37cae5926eb8b8d250bb", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class LuckyCard {\n \n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n System.out.println(\"Enter 6 digits : \");\n String lc = s.next();\n int arr[] = new int[6];\n int r=0;//Number of replacements\n \n //Enter the numbers into the array\n for (int i = 0; i < arr.length; i++) {\n arr[i] =Integer.parseInt(lc.charAt(i)+\"\");\n }\n \n //sorted by bubble sort\n int n = arr.length;\n int temp = 0;\n for (int i = 0; i < n; i++) {\n for (int j = 1; j < (n - i); j++) {\n if (arr[j - 1] > arr[j]) {\n //swap elements \n temp = arr[j - 1];\n arr[j - 1] = arr[j];\n arr[j] = temp;\n }\n }\n }\n \n int sum1=0;\n int sum2=0;\n \n \n for (int i = 0 ;i<=2 ;i++)//sum of the first three numbers\n sum1=sum1+arr[i];\n \n for (int i = 3 ;i<=5 ;i++)//sum of the second three numbers \n sum2=sum2+arr[i];\n \n int d = sum2-sum1;\n \n \n if (d>0 && d < 9)\n r=1;\n else if (d>=9 &&d<18)\n r=2;\n else if (d>=18 && d< 27)\n r=3;\n \n System.out.println(r);\n }\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "26ad0949c3e8eb423a3d837e1bda6235", "src_uid": "09601fd1742ffdc9f822950f1d3e8494", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint m = 2 * n - 1;\n\t\tint l = Integer.toString(m).length();\n\t\tchar[] c = Integer.toString(m).toCharArray();\n\t\tboolean b = true;\n\t\tfor (int i = 0; i < c.length; i++) {\n\t\t\tif (c[i] != '9')\n\t\t\t\tb = false;\n\t\t}\n\t\tif (b)\n\t\t\tSystem.out.println(1);\n\t\telse {\n\t\t\tl--;\n\t\t\tString s=\"\";\n\t\t\tfor (int i=0; iels)\n\t\t return pfact[0]; \n\t\telse \n\t\t\treturn els;\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "05dff19c27c3a973523ee2abaebe0b82", "src_uid": "a8d992ab26a528f0be327c93fb499c15", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n\n Scanner input = new Scanner(System.in);\n\n int n = input.nextInt();\n int insertWeight = input.nextInt();\n int doubleWeight = input.nextInt();\n\n int ans[] = new int[n + 1];\n ans[0] = 0;\n ans[1] = insertWeight;\n for (int i = 2; i < n+1; i++) {\n if (i % 2 == 1) {\n ans[i] = Math.min(ans[(i - 1)] + insertWeight, ans[(i + 1) / 2] + insertWeight + doubleWeight;\n } else {\n ans[i] = Math.min(ans[i / 2] + doubleWeight, ans[i - 1] + insertWeight);\n\n }\n }\n\n System.out.print(ans[n]);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "499e0e0c421abe572e2e05715fbcceb7", "src_uid": "0f270af00be2a523515d5e7bd66800f6", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class a\n{\n public static void main(String args[])\n {\n Scanner s=new Scanner(System.in);\n int m=s.nextInt();\n int n=s.nextInt();\n double k=s.nextDouble();\n int value=(int)(k/2)*((2*m)+(k-1)*m);\n System.out.println(value-n);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1298eb92a4a489a5cbcaa89cebb9c085", "src_uid": "e87d9798107734a885fd8263e1431347", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class C {\n public static void main(String args[])throws Exception {\n Scanner sc = new Scanner(System.in);\n long n = sc.nextLong();\n long b = sc.nextLong();\n long copy = n;\n Map hm = new HashMap<>();\n for (long i = 2l; i * i <= n; i++) {\n long cnt = 0l;\n while (n % i == 0) {\n cnt ++;\n n /= i;\n }\n if (cnt > 0l)\n hm.put(i, cnt);\n }\n hm.put(b, 1);\n int pow = Integer.MAX_VALUE;\n for (Long i : hm.keySet()) {\n int p = 0;\n for (long j = i; j <= copy; j *= i)\n p += copy / j;\n pow = Math.min(pow, p);\n }\n System.out.print(pow);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "affe8ac8d6905712a51212142dc14640", "src_uid": "491748694c1a53771be69c212a5e0e25", "difficulty": 1700.0} {"lang": "Java 11", "source_code": "//package com.acabra.gtechdevalgs.codeforces.below1000;\n\nimport java.io.*;\nimport java.util.Locale;\nimport java.util.StringTokenizer;\n\n//public class CardGame1097A {\n public class Solution implements Runnable {\n // solution\n void solve() throws IOException {\n System.out.println(solution(help));\n }\n\n public static String solution(Help help) throws IOException {\n String openCard = help.next();\n String handCard;\n for (int i = 0; i < 5; ++i) {\n handCard = help.next();\n if (sameSuit(openCard, handCard) || sameRank(openCard, handCard)) {\n return \"YES\";\n }\n }\n return \"NO\";\n }\n\n private static boolean sameRank(String openCard, String handCard) {\n return openCard.charAt(1) == handCard.charAt(1);\n }\n\n private static boolean sameSuit(String openCard, String handCard) {\n return openCard.charAt(0) == handCard.charAt(0);\n }\n\n //--START helper submission code\n private final Help help;\n private final boolean onlineJudge;\n static class Help {\n final BufferedReader bf;final PrintWriter out;StringTokenizer tokenizer;\n public Help(BufferedReader bf, PrintWriter out) {this.bf = bf;this.out = out;}\n public int nInt() throws IOException {return Integer.parseInt(next());}\n public long nLong() throws IOException {return Long.parseLong(next());}\n public double nDouble() throws IOException {return Double.parseDouble(next());}\n String next() throws IOException {while (tokenizer == null || !tokenizer.hasMoreTokens()) {tokenizer = new StringTokenizer(bf.readLine());}return tokenizer.nextToken();}\n public void close() throws IOException {bf.close();out.flush();}\n public static Help of(InputStream in) { return of(in, new OutputStreamWriter(System.out)); }\n public static Help of(String fileName) { return of(fileAsStream(fileName), new OutputStreamWriter(System.out)); }\n static Help of(InputStream in, OutputStreamWriter iOut) {return new Help(new BufferedReader(new InputStreamReader(in)), new PrintWriter(iOut));}\n }\n public Solution(InputStream in, OutputStreamWriter iOut, boolean isOnlineJudge) {this.help = new Solution.Help(new BufferedReader(new InputStreamReader(in)), new PrintWriter(iOut)); this.onlineJudge = isOnlineJudge;}\n private static Solution ofConsole() { return new Solution(System.in, new OutputStreamWriter(System.out), true); }\n public static InputStream fileAsStream(String fileName) { return SearchEasyProblem1030A.Solution.class.getClassLoader().getResourceAsStream(fileName); }\n public static Solution ofTestFile(String fileName) { return new Solution(Solution.class.getClassLoader().getResourceAsStream(fileName), new OutputStreamWriter(System.out), false);}\n private static Solution get(String file) { return System.getProperty(\"ONLINE_JUDGE\") != null ? ofConsole() : ofTestFile(file); }\n public static void main(String[] args) {new Thread(null, Solution.ofConsole(), \"\", 256 * (1L << 20)).start();}\n public void run() {\n try {long t1 = System.nanoTime();Locale.setDefault(Locale.US);solve();if (!onlineJudge) System.err.println(\"Time = \" + (System.nanoTime() - t1)/1000.0 + \": ms\");}\n catch (Throwable t) {System.exit(-1);}\n finally {try {help.close();} catch (IOException e) {e.printStackTrace();}}\n }\n //--END helper submission code\n }\n//}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "78a965b9255f8dbba7b6c7ca552de100", "src_uid": "699444eb6366ad12bc77e7ac2602d74b", "difficulty": 800.0} {"lang": "Java 6", "source_code": "import java.util.BufferedReader;\nimport java.util.InputStreamReader;\n\npublic class BearTraingle {\n public static void main(String[] args) throws Exception {\n BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));\n String[] temp = bfr.readLine().split(\" \");\n int x = Integer.parseInt(temp[0]);\n int y = Integer.parseInt(temp[1]);\n\n printCoordinates(x,y);\n }\n\n private static void printCoordinates(int x, int y) {\n int x1 = 0;\n int x2 = x+y;\n int y1 = x+y;\n int y2 = 0;\n if(x < 0 && y > 0) {\n x1 = x-y;\n x2 = 0;\n y1 = 0;\n y2 = -(x-y);\n }else if(x > 0 && y < 0) {\n x1 = 0;\n x2 = -(y-x);\n y1 = (y-x);\n y2 = 0;\n }else if(x < 0 && y < 0) {\n x1 = x+y;\n x2 = 0;\n y1 = 0;\n y2 = x+y;\n }\n\n System.out.println(x1 + \" \" + y1 + \" \" + x2 + \" \" + y2);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d8fc8de8c6abc84c13244910167ef5e1", "src_uid": "e2f15a9d9593eec2e19be3140a847712", "difficulty": 1000.0} {"lang": "Java 7", "source_code": "/* package whatever; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Ideone\n{\n public static void main (String[] args) throws java.lang.Exception\n {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int l = sc.nextInt();\n int r = sc.nextInt();\n int x = sc.nextInt();\n int c[] = new int[n];\n for(int i = 0;i sa = new ArrayList();\n for(int j = 0;j=x){\n counter++;\n }\n }\n System.out.println(counter);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b88c2c2843400fb0201b5227f9d5bf52", "src_uid": "0d43104a0de924cdcf8e4aced5aa825d", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.InputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.InputMismatchException;\nimport java.util.NoSuchElementException;\nimport java.math.BigInteger;\n\npublic class Main{\n\nstatic PrintWriter out;\nstatic InputReader ir;\n\nstatic void solve(){\n int n=3;\n int[][] co=new int[n][];\n for(int i=0;i=0;i--){\n if(a[i]=lenbuf){\n curbuf= 0;\n try{\n lenbuf=in.read(buffer);\n }catch(IOException e) {\n throw new InputMismatchException();\n }\n if(lenbuf<=0) return false;\n }\n return true;\n }\n\n private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}\n \n private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}\n \n private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}\n \n public boolean hasNext(){skip(); return hasNextByte();}\n \n public String next(){\n if(!hasNext()) throw new NoSuchElementException();\n StringBuilder sb=new StringBuilder();\n int b=readByte();\n while(!isSpaceChar(b)){\n sb.appendCodePoint(b);\n b=readByte();\n }\n return sb.toString();\n }\n \n public int nextInt() {\n if(!hasNext()) throw new NoSuchElementException();\n int c=readByte();\n while (isSpaceChar(c)) c=readByte();\n boolean minus=false;\n if (c=='-') {\n minus=true;\n c=readByte();\n }\n int res=0;\n do{\n if(c<'0'||c>'9') throw new InputMismatchException();\n res=res*10+c-'0';\n c=readByte();\n }while(!isSpaceChar(c));\n return (minus)?-res:res;\n }\n \n public long nextLong() {\n if(!hasNext()) throw new NoSuchElementException();\n int c=readByte();\n while (isSpaceChar(c)) c=readByte();\n boolean minus=false;\n if (c=='-') {\n minus=true;\n c=readByte();\n }\n long res = 0;\n do{\n if(c<'0'||c>'9') throw new InputMismatchException();\n res=res*10+c-'0';\n c=readByte();\n }while(!isSpaceChar(c));\n return (minus)?-res:res;\n }\n\n public double nextDouble(){return Double.parseDouble(next());}\n\n public BigInteger nextBigInteger(){return new BigInteger(next());}\n\n public int[] nextIntArray(int n){\n int[] a=new int[n];\n for(int i=0;i= fieldString.length()) {\n print(\"NO\");\n return;\n }\n if (fieldString.charAt(grassHopperPos) == '#') {\n print(\"NO\"); \n return;\n }\n if (fieldString.charAt(grassHopperPos) == 'G' || fieldString.charAt(grassHopperPos) == 'T') {\n print(\"YES\"); \n return;\n }\n }\n print(\"NO\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "40987be39fff7942021dacbc6cef19b2", "src_uid": "189a9b5ce669bdb04b9d371d74a5dd41", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\npublic class BOOL {\nprivate static FastReader in =new FastReader();\n static String S,Sc;\n static int n,m=1,a,b;\n static long z=1,x,c;\n public static void main(String[] args) {\n n=in.nextInt();\n m=in.nextInt();\n a=in.nextInt();\n b=in.nextInt();\n c=(a-1)%m;\n if(b-(a-c-1)==m){System.out.println(\"1\");return;}\n else if((b-(a-c-1))/m==1){System.out.println(\"2\");return;}\n if(c>0)x++;\n b-=(a-c-1);\n if(b%m>0&&b!=n)x++;\n b+=(m-1);\n System.out.println(x+1);\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fbbf7ba36f97c1a305cd34c3837dfc45", "src_uid": "f256235c0b2815aae85a6f9435c69dac", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "package app;\n\nimport java.util.ArrayList;\nimport java.util.Scanner;\n\npublic class App {\n\n\tpublic static void main(String[] args) {\n\n\t\tScanner sc = new Scanner(System.in);\n\n\t\tint n = sc.nextInt();\n\n\t\tint k = sc.nextInt();\n\n\t\tArrayList list = new ArrayList<>();\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tlist.add(sc.nextInt());\n\n\t\t}\n\t\tint count = 0;\n\n\t\tint left = 0;\n\t\tint right = list.size() - 1;\n\t\t\n\t\tif(list.size() == 1) {\n\t\t\tif(list.get(0) <= k) {\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}else {\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (list.get(left) <= k) {\n\t\t\t\tcount++;\n\t\t\t\tlist.remove(left);\n\t\t\t\tright--;\n\t\t\t\tif (list.size() == 1 && list.get(0) <= k) {\n\t\t\t\t\tcount++;\n\t\t\t\t\tbreak;\n\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (list.get(right) <= k) {\n\t\t\t\tcount++;\n\t\t\t\tlist.remove(right);\n\t\t\t\tright--;\n\t\t\t\tif (list.size() == 1 && list.get(0) <= k) {\n\t\t\t\t\tcount++;\n\t\t\t\t\tbreak;\n\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (list.get(left) > k && list.get(right) > k) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (list.size() == 1 && list.get(0) <= k) {\n\t\t\t\tcount++;\n\t\t\t}\n\n\t\t}\n\n\t\t\n\n\t}\n\t\tSystem.out.println(count);\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f04d0670827f8babc9ac212dc9767ab5", "src_uid": "ecf0ead308d8a581dd233160a7e38173", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Hello\n{\n\tpublic static void main(String args[])\n\t{\n\t\tScanner sc = new Scanner(System.in);\n\t\tString s1=sc.next();\n\t\tString s2=sc.next();\n\t\tString s3=sc.next();\n\t\tString s4=s1+s2;\n\t\tchar p1[]=String.toCharacterArray(s4);\n\t\tchar p2[]=String.toCharacterArray(s3);\n\t\tArrays.sort(p1);\n\t\tArrays.sort(p2);\n\t\tString ans=(Arrays.equals(p1,p2)==true)?\"YES\"\":\"NO\";\n\t\tSystem.out.println(ans);\n\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bb8cedcb54bb239636d5ed68d644244a", "src_uid": "b6456a39d38fabcd25267793ed94d90c", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.*;\r\nimport java.util.*;\r\npublic class sol{\r\n public static void main(String [] args){\r\n Scanner sc=new Scanner(System.in);\r\n int t=sc.nextInt();\r\n while(t-->0){\r\n int num = input.nextInt();\r\n HashSetset = new HashSet<>();\r\n \r\n for(int i = 1; i<100000;i++){\r\n if(i*i > num)\r\n break;\r\n \r\n long num1 = i*i;\r\n if(num1 <= num)\r\n set.add(num1);\r\n \r\n long num2 = (long)i*(long)i*(long)i;\r\n if(num2 <= num)\r\n set.add(num2);\r\n }\r\n System.out.println(set.size());\r\n }\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "de94df3e92dc5f698d2d7c57f8e51de3", "src_uid": "015afbefe1514a0e18fcb9286c7b6624", "difficulty": 800.0} {"lang": "Java 7", "source_code": "import java.io.ObjectInputStream.GetField;\nimport java.util.Scanner;\n\n\npublic class Problem3 {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\n\t\t\n\t\tScanner in = new Scanner(System.in);\n\t\t\n\t\twhile (in.hasNextLine()) {\n\t\t\t String line = in.nextLine();\n\t\t\t String[] arguments = line.split(\" \");\n\t\t\t getPerfectPair(Long.parseLong(arguments[0]), Long.parseLong(arguments[1]), Long.parseLong(arguments[2]));\n\t\t}\n\n\n\t}\n\t\n\tprivate static void getPerfectPair(long primerNumero, long segundoNumero, long destino) {\n\t\t\n\t\tlong res=0;\n\t\t\n\t\tif(stopConditionReachDestination(primerNumero, segundoNumero, destino)) {\n\t\t\tres=0;\n\t\t\tSystem.out.println(res);\n\t\t}\n\t\telse if(stopConditionNeverReach(primerNumero, segundoNumero, destino)) {\n\t\t\tres=-1;\n\t\t\tSystem.out.println(res);\n\t\t}\n\t\tif(primerNumero>segundoNumero) {\n\t\t\tlong aux = primerNumero;\n\t\t\tprimerNumero = segundoNumero;\n\t\t\tsegundoNumero =aux;\n\t\t}\n\t\telse {\n\t\t\twhile(!stopConditionReachDestination(primerNumero, segundoNumero, destino)) {\n\n\t\t\t\t\tlong aux = primerNumero;\n\t\t\t\t\tprimerNumero=segundoNumero;\n\t\t\t\t\tsegundoNumero+=aux;\n\t\t\t\t}\n\t\t\t\tres++;\n\t\t\t}\n\t\t\t\n\t\t\tSystem.out.println(res);\n\t\t}\n\t\t\n\t}\n\t\n\tprivate static boolean stopConditionNeverReach(long a, long b, long c) {\n\t\t\n\t\treturn a<=0 && b<=0;\n\t}\n\t\n\tprivate static boolean stopConditionReachDestination(long a, long b, long c) {\n\t\treturn a >=c || b>=c;\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "345fa658899c9034fb72fc1c27ba7ebe", "src_uid": "82026a3c3d9a6bda2e2ac6e14979d821", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n/*\n * https://codeforces.com/contest/1191/problem/A\n */\npublic class Main {\n\n public static void main(String[] args) throws IOException {\n\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n PrintWriter wr = new PrintWriter(System.out);\n\n int hp = Integer.parseInt(br.readLine().trim());\n\n Map category = new HashMap<>();\n\n category.put(0, 4);\n category.put(1, 1);\n category.put(2, 3);\n category.put(3, 2);\n\n int rem = hp % 4;\n\n for (int i = 0; i <= 2; i++) {\n int new_rem = (hp+ 1 ) % 4;\n if (category.get(rem) > category(new_rem)) {\n rem = new_rem;\n }\n }\n\n if (rem == 0) {\n out.println(rem + \" \" + 'D');\n } else if (rem == 1) {\n out.println(rem + \" \" + 'A');\n } else if (rem == 2) {\n out.println(rem + \" \" + 'C');\n } else if (rem == 3) {\n out.println(rem + \" \" + 'B');\n }\n\n wr.close();\n\n br.close();\n\n }\n\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "55c0ba8ecf705e44908eea44b13cb0bf", "src_uid": "488e809bd0c55531b0b47f577996627e", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class TriGun2{\n\tpublic static void main(String args[]){\n\t\tScanner scanner = new Scanner(System.in);\n\t\tint n = scanner.nextInt();\n\t\tint a = scanner.nextInt();\n\t\tint b = scanner.nextInt();\n\t\t\n\t\tSystem.out.println(max(n-a, b+1));\n\t}\n\t\n\tpublic 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\t\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "22a9e2bd56e726782d8f996f30ca4315", "src_uid": "51a072916bff600922a77da0c4582180", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int[] a = new int[n];\n boolean unimodal = true;\n boolean inc = false, mode = false, dec = false;\n boolean preinc = false, premode = false, predec = false;\n \n for (int i = 0; i < n; i++)\n {\n a[i] = in.nextInt();\n }\n \n (if n > 1)\n {\n if (a[1] > a[0])\n inc = true;\n else if (a[1] == a[0])\n mode = true;\n else\n dec = true;\n }\n \n for (int i = 2; i < n; i++)\n {\n preinc = inc; \n premode = mode; \n predec = dec;\n \n inc = (a[i] > a[i - 1]);\n mode = (a[i] == a[i - 1]);\n dec = (a[i] < a[i - 1]);\n \n if ((predec && mode) || (predec && inc) || (premode && inc))\n {\n unimodal = false;\n break;\n }\n \n }\n \n if (unimodal)\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5d59e9c7243aa048fc733c8bf43bae17", "src_uid": "5482ed8ad02ac32d28c3888299bf3658", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collection;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedHashMap;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.StringTokenizer;\nimport java.util.stream.IntStream;\n\npublic class Main {\n final static long MOD = 1000000007;\n public static void main(String[] args) {\n FastScanner fs = new FastScanner();\n PrintWriter out = new PrintWriter(System.out);\n String s = fs.nextLine();\n if(s.contains(\"H\") || s.contains(\"Q\") || s.contains(\"9\")) {\n out.println(\"YES\");\n }\n else {\n out.println(\"NO\");\n }\n out.flush();\n out.close();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "22121a84578afa9c997fa7ebf23d57db", "src_uid": "1baf894c1c7d5aeea01129c7900d3c12", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.lang.*;\nimport java.util.*;\npublic class Main{\n\tpublic static void main(String[] args){\n\t\tScanner sc = new Scanner(System.in);\n\t\tlong l = sc.nextLong();\n\t\tlong r = sc.nextLong();\n\t\tlong gcd = sc.nextLong();\n\t\tlong lcm = sc.nextLong();\n\t\tif(lcm%gcd!=0){\n\t\t\tSystem.out.println(\"0\");\n\t\t}\n\t\telse{\n\t\t\tlong res = lcm/gcd;\n\t\t\tint p = factors(res,l,r);\n\t\t\tSystem.out.println(p);\n\t\t}\n\t}\n\tstatic int factors(long res,long l,long r){\n\t\tint count = 0;\n\t\tfor(int i=1;i*i<=res;i++){\n\t\t\tif(res%i==0 && i>=l && i<=r){\n\t\t\t\tif(i!=res/i && res/i>=l && res/i<=r){\n\t\t\t\t\tif(gcd(i,res/i)){\n\t\t\t\t\t\tcount= count+2;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn count;\n\t}\n\tstatic boolean gcd(long a,long b){\n\t\tif(a==b && a==1){\n\t\t\treturn true;\n\t\t}\n\t\telse if(a>b){\n\t\t\treturn gcd(a-b,b);\n\t\t}\n\t\telse if(b>a){\n\t\t\treturn gcd(a,b-a);\n\t\t}\n\t\treturn false;\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5c33c58a2ad1cea8ac784be73ba38930", "src_uid": "d37dde5841116352c9b37538631d0b15", "difficulty": 1600.0} {"lang": "Java 6", "source_code": "\nimport java.io.FileInputStream;\nimport java.util.Scanner;\n\npublic class Solution {\n\n public static void main(String[] args) throws IOException {\n Scanner sc = new Scanner(System.in);\n// Scanner sc = new Scanner(new FileInputStream(\"/home/camoroh13/temp/input.txt\"));\n String n = sc.nextLine();\n String m = sc.nextLine();\n String ans=\"OK\";\n if (n.length() != m.length() || m.startsWith(\"0\")) {\n ans = \"WRONG_ANSWER\";\n } else {\n String tm = \"\";\n int[] c = new int[10];\n c[0] = c[1] = c[2] = c[3] = c[4] = c[5] = c[6] = c[7] = c[8] = c[9] = 0;\n\n for (int i=0;i < 10; i++) {\n String str = i+\"\";\n int pos = n.indexOf(str);\n while (pos > -1) {\n c[i]++;\n pos = n.indexOf(str, pos+1) ;\n }\n }\n\n int k = 1;\n while (k <= 9 && c[k] == 0) {\n k++;\n }\n\n if (k < 10) {\n for (int j=0; j< c[k]; j++) {\n tm += k+\"\";\n break;\n }\n }\n for (int j=1; j<= c[0]; j++) {\n tm += \"0\";\n }\n for (int i=1;i < 10; i++) {\n String str = i+\"\";\n for (int j=1; j<= c[i]; j++) {\n tm += str;\n }\n }\n\n if (!tm.equals(m)) {\n ans = \"WRONG_ANSWER\";\n }\n }\n\n System.out.println(ans);\n sc.close();\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7fa0ce50ddff54bf6ccae0a56bab33e2", "src_uid": "d1e381b72a6c09a0723cfe72c0917372", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class rohmbus{\n public static void main(String[] args) {\n Scanner sc =new Scanner (System.in);\n int n=sc.nextInt();\n System.out.println(solve(n));\n }\n staticint solve(int n){\n if(n==1||n==0)\n return n;\n else\n return (int)(Math.pow(n,2)+Math.pow(n-1,2));\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "36c7604bce7569db49ce90d624e99153", "src_uid": "758d342c1badde6d0b4db81285be780c", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\n public class Main {\n\t //****************/////////*\n\t public static int TernarySearch(int a,int b){\n\t\t int min = a ; int max= b; \n\t\t for(int i=1;i<=400; i++)\n\t\t {\n\t\t\t int g= min+(max-min)/3;\n\t\t\t int h = min + 2*(max-min)/3;\n\t\t\t if(f(arr[h])>f(arr[g]))\n\t\t\t\t max=h;\n\t\t\t else\n\t\t\t\t min=g;\n\t\t\t \n\t\t\t \n\t\t\t \n\t\t }\n\t\t return (min+max)/2 ;\n\t\t \n\t\t \n\t\t \n\t }\n\t \n\t \n\t \n\t \n\t \n\t \n\t \n\t \n\t \n\t\n\tpublic static void main(String args[]){\n\tScanner sc= new Scanner(System.in);\n\tlong n =sc.nextLong(); \n\tlong k =sc.nextLong();\n\tif(n==1){System.out.println(0);return ;}\n\tif(n<=k){System.out.println(1);return ;}\n\tlong max= (k*(k-1)/2)+1 ;\n\tif(n>max){System.out.println(-1);return;}\n\tn = n-1 ;\n\tk=k-1;\n\tlong numb = 0 ;\n\tlong f =1L;long l= (long)k ;\n\n\tlong mid =(f+l)/2;long ans =-1;\n\tfor(int i=1;i<100;i++)\n\n\t{\n\t\tmid = (f + l) / 2;\n if ((k*(k + 1)) / 2 - (mid*(mid + 1)) / 2 >= n)\n {\n numb = mid ;\n f = mid+1;\n }\n else l = mid-1;\n\t}\n\tSystem.out.println(k-mid);\n\t\t\n\t}\n\t\n\t\n\t\t\n\t\t\n\t\t\n\t}\n\t\n\t\n \n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6caa32a0214beed0ad7d3f3caa3cbb67", "src_uid": "83bcfe32db302fbae18e8a95d89cf411", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.Scanner;\nimport java.lang.Object;\n\npublic class Chess {\n private int[][] board; \n \n public int chess(String rook, String knight) {\n \n int N = 8;\n board = new int[N][N];\n \n int a = Integer.parseInt(\"\" + rook.charAt(1)) - 1;\n int b = Integer.parseInt(\"\" + knight.charAt(1)) - 1;\n \n int r = (int) (rook.charAt(0) - 'a');\n int k = (int) (knight.charAt(0) - 'a');\n \n board[b][k] = 1;\n \n for (int i = -1; i <=1; i+=2) {\n \n int m = b + i;\n if (m > -1 && m < N) {\n int n = k+2;\n if (n > -1 && n < N) {\n board[m][n] = 1;\n }\n n = k-2;\n if (n > -1 && n < N) {\n board[m][n] = 1;\n }\n }\n \n m = a + i;\n if (m > -1 && m < N) {\n int n = r+2;\n if (n > -1 && n < N) {\n board[m][n] = 1;\n }\n n = r-2;\n if (n > -1 && n < N) {\n board[m][n] = 1;\n }\n }\n }\n \n \n for (int i = -2; i <=2; i+=4) {\n \n int m = b + i;\n if (m > -1 && m < N) {\n int n = k+1;\n if (n > -1 && n < N) {\n board[m][n] = 1;\n }\n n = k-1;\n if (n > -1 && n < N) {\n board[m][n] = 1;\n }\n }\n \n m = a + i;\n if (m > -1 && m < N) {\n int n = r+1;\n if (n > -1 && n < N) {\n board[m][n] = 1;\n }\n n = r-1;\n if (n > -1 && n < N) {\n board[m][n] = 1;\n }\n }\n }\n \n for (int i = 0; i < N; i++) {\n for (int j = 0; j < N; j++) {\n //rook\n if (i == a || j == r) {\n board[i][j] = 1;\n }\n }\n }\n \n int sum = 0;\n \n for (int i = 0; i < N; i++) {\n for (int j = 0; j 5){\n number = number - 5;\n number = (number + 1)/2;\n }\n }\n \n if (number == 5){\n System.out.println(\"Howard\");\n } else {\n if (number == 4){\n System.out.println(\"Rajesh\");\n } else {\n if (number == 3){\n System.out.println(\"Penny\");\n } else {\n if (number == 2){\n System.out.println(\"Leonard\");\n } else {\n if (number == 1){\n System.out.println(\"Sheldon\");\n }\n }\n }\n }\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0dfda2ca38310f4fe973bbbeb9809a66", "src_uid": "023b169765e81d896cdc1184e5a82b22", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class CF394A {\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n String str = sc.nextLine();\n sc.close();\n if (str.length()%2 != 0){\n System.out.println(\"Impossible\");\n } else {\n int len = (str.length() - 2)/2;\n String result = \"|+\";\n for(int i = 0; i < len - 1; i++){\n result += \"|\";\n }\n result += \"=\";\n for(int i = 0; i < len; i++){\n result += \"|\";\n }\n System.out.println(result);\n }\n \n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2daf91404821dd28cc4dd9742d4e1df0", "src_uid": "ee0aaa7acf127e9f3a9edafc58f4e2d6", "difficulty": null} {"lang": "Java 7", "source_code": "public class B {\n\n public static void main(String[] args) {\n new B();\n }\n \n public B()\n {\n Scanner s = new Scanner();\n int n = s.nextInt();\n int m = s.nextInt();\n if(n == m || (m + n) % 2 == 0)\n {\n char[] narray = s.readNextLine().toCharArray();\n char[] marray = s.readNextLine().toCharArray();\n StringBuilder sb1 = new StringBuilder();\n StringBuilder sb2 = new StringBuilder();\n \n if(m > n)\n m = n;\n else if(n > m)\n n = m;\n \n for(int i = 0; i < n; i++)\n {\n if(narray[i] == '>')\n sb1.append(\"1\");\n else\n sb1.append(\"0\");\n } \n for(int i = 0; i < m; i++)\n {\n if(marray[i] == '^')\n sb2.append(\"1\");\n else\n sb2.append(\"0\");\n }\n if(sb1.toString().equals(sb2.toString()))\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n }\n else\n {\n System.out.println(\"NO\");\n }\n }\n\n static class Scanner {\n BufferedReader br;\n StringTokenizer st;\n\n public Scanner(Reader in) {\n br = new BufferedReader(in);\n }\n\n public Scanner() {\n this(new InputStreamReader(System.in));\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n \n\n // Slightly different from java.util.Scanner.nextLine(),\n // which returns any remaining characters in current line,\n // if any.\n String readNextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7207c5fbc703b02703409770f21e8ee8", "src_uid": "eab5c84c9658eb32f5614cd2497541cf", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Mainn {\n\n\tpublic static class FastReader {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastReader() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreElements()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tString nextLine() {\n\t\t\tString str = \"\";\n\t\t\ttry {\n\t\t\t\tstr = br.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tFastReader scn = new FastReader();\n\n\t\tlong end = scn.nextInt(), cap = scn.nextInt(), pump = scn.nextInt(), round = 2 * scn.nextInt(), r = 0, gas = cap, stop = 0;\n\t\tlong tDist = round * end;\n\t\t\n\t\tif(cap >= tDist) {\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tif((cap < 2 * pump || cap < 2 * (end - pump)) && round > 2) {\n\t\t\tSystem.out.println(-1);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tif(round == 1 && (pump > cap || (end - pump) > cap){\n\t\t\tSystem.out.println(-1);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\twhile(r < round) {\n\t\t\tgas -= pump;\n\t\t\tr++;\n\t\t\tif(gas >= 2 * (end - pump) && (round - r) > 1) {\n\t\t\t\tr += 2;\n\t\t\t\tgas -= 2 * (end - pump);\n\t\t\t} else if((round - r) > 1){\n\t\t\t\tstop++;\n\t\t\t\tr += 2;\n\t\t\t\tgas = cap - 2 * (end - pump);\n\t\t\t} else if((round - r) == 1 && gas >= (end - pump)){\n\t\t\t\tr++;\n\t\t\t} else if((round - r) == 1) {\n\t\t\t\tr++;\n\t\t\t\tstop++;\n\t\t\t}\n\t\t\t\n\t\t\tif(r >= round) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif((round - r) == 1) {\n\t\t\t\tif(gas < pump) {\n\t\t\t\t\tstop++;\n\t\t\t\t}\n\t\t\t\tr++;\n\t\t\t\tbreak;\n\t\t\t} else if(gas >= 2 * pump) {\n\t\t\t\tr++;\n\t\t\t\tgas -= pump;\n\t\t\t} else if(gas < 2 * pump){\n\t\t\t\tgas = cap - pump;\n\t\t\t\tstop++;\n\t\t\t\tr++;\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(stop);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2d54c89b106b404487204f6159e4d8d9", "src_uid": "283aff24320c6518e8518d4b045e1eca", "difficulty": 1500.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class VK_2016_A {\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint N = sc.nextInt();\n\t\tint A = sc.nextInt();\n\t\tif(A % 2 == 1){\n\t\t\tint ans = 1;\n\t\t\twhile(A != 1){\n\t\t\t\tans++;\n\t\t\t\tA -= 2;\n\t\t\t}\n\t\t}else{\n\t\t\tint ans = 1;\n\t\t\twhile(A != N){\n\t\t\t\tans++;\n\t\t\t\tA += 2;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "39d23f3113cc8e0624addaa1738f9539", "src_uid": "aa62dcdc47d0abbba7956284c1561de8", "difficulty": 1100.0} {"lang": "Java 6", "source_code": "package javaapplication3;\n\nimport java.util.Scanner;\n\n\npublic class JavaApplication3 {\n\n public static void main(String[] args) {\n Scanner in=new Scanner(System.in);\n long n,a,b,c,k,m;\n a=in.nextLong();\n b=in.nextLong();\n \n if (a*b%2==0) m=a*b/2; else m=(a*b+1)/2; \n if ((a==1)||(b==1)) m=a*b;\n if ((a==2)&(b==2)) m=4;\n if(((a==2)&(b%2==1))||((b==2)&(a%2==1))) m=(a*b+2)/2;\n if(((a==2)&(b%4==2))||((b==2)&(a%4==2))) m=(a*b+4)/2;\n System.out.println(m);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2f1fff46cc5f10ad55fb31f837a16d78", "src_uid": "e858e7f22d91aaadd7a48a174d7b2dc9", "difficulty": 1800.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\npublic class A57 {\n static int n;\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer st = new StringTokenizer(br.readLine());\n n = Integer.parseInt(st.nextToken());\n int x1 = Integer.parseInt(st.nextToken());\n int y1 = Integer.parseInt(st.nextToken());\n int x2 = Integer.parseInt(st.nextToken());\n int y2 = Integer.parseInt(st.nextToken());\n int[] dx = new int[]{-1,1,0,0};\n int[] dy = new int[]{0,0,-1,1};\n int[][] grid = new int[n+1][n+1];\n for(int i = 0; i <= n; i++)\n Arrays.fill(grid[i], 1 << 20);\n grid[x1][y1] = 0;\n LinkedList q = new LinkedList();\n q.add(new State(x1,y1));\n while(!q.isEmpty()) {\n State curr = q.removeFirst();\n if(curr.x == x2 && curr.y == y2)\n break;\n for(int i = 0; i < 4; i++) {\n int outX = curr.x + dx[i];\n int outY = curr.y + dy[i];\n if(grid[outX][outY] > 1 + grid[curr.x][curr.y]) {\n grid[outX][outY] = 1 + grid[curr.x][curr.y];\n q.addLast(new State(outX, outY));\n }\n }\n }\n System.out.println(grid[x2][y2]);\n }\n public static boolean isValid(int x, int y) {\n return x>=0 && y>=0 && x<=n && y<=n && ((x==0 || x==n) || (y==0 || y==n));\n }\n static class State {\n public int x,y;\n public State(int a, int b) {\n x=a;\n y=b;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9a8973c004d70d7b457e60785d6d6573", "src_uid": "685fe16c217b5b71eafdb4198822250e", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "=import java.util.Scanner;\n\npublic class Quiz {\n\tstatic int x = 1000000009;\n\tpublic static int initialScore(int n,int k)\n\t{\n\t\tif (n==0)\n\t\t\treturn 0;\n\t\tint l = initialScore(n-1, k);\n\t\treturn (int) (1L*(l+k)*2)%x;\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\tint m = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tint rightSeq = k-1;\n\t\tint a = Math.min(m/rightSeq, n-m+1);\n\t\tint score = Math.min(m,a*(k-1));\n\t\tm -= score;\n\t\tscore += m%k;\n\t\tm -= m%k;\n\t\tint initialScore = initialScore(m/k,k);\n\t\t\n\t\tSystem.out.println(initialScore+score);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "84488c216a52b0e3814afaeb87fe8fb0", "src_uid": "9cc1aecd70ed54400821c290e2c8018e", "difficulty": 1600.0} {"lang": "Java 6", "source_code": "\n\npublic class Main {\n static final int SIZE = 15000;\n \n public static void main(String[] args) throws Throwable {\n int seed = 1;\n int[][] a = new int[SIZE][SIZE], b = new int[SIZE][SIZE];\n for (int i = 0; i < SIZE; i++) {\n for (int j = 0; j < SIZE; j++) {\n a[i][j] = seed; seed = 217 * seed + 71;\n b[i][j] = seed; seed = 217 * seed + 71;\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "38f3c10bfb71a39c0b34a2ad24244e1e", "src_uid": "2ecbac20dc5f4060bc873553946281bc", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class StraightA{\n public static void main(String[] args){\n Scanner scan = new Scanner(System.in);\n int n = scan.nextInt();\n int k = scan.nextInt();\n float x, avg = 0;\n float currentSum = 0;\n for (int i = 0; i Math.abs(r1+r2)-eps || dist < Math.abs(r2-r1)+eps)\n return false;\n return true;\n }\n\n public static boolean between(int r1, int r2, int x1, int y1, int x2, int y2, int r)\n {\n double dist = Math.sqrt(sq(x1-x2)+ sq(y1-y2));\n return dist < r- Math.min(r1, r2) + eps && dist < Math.max(r1,r2)-r + eps;\n }\n\n public static int sq(int n)\n {\n return n*n;\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6969cd63822e48e2b0406f42e5f0246a", "src_uid": "4c2865e4742a29460ca64860740b84f4", "difficulty": 1900.0} {"lang": "Java 11", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Comparator;\n\npublic class d1 extends PrintWriter {\n\n static BufferedReader s = new BufferedReader(new InputStreamReader(System.in));\n // static Scanner s=new Scanner(System.in);\n d1 () { super(System.out); }\n public static void main(String[] args) throws IOException{\n d1 d1=new d1();d1.main();d1.flush();\n }\n void main() throws IOException {\n BufferedReader s = new BufferedReader(new InputStreamReader(System.in));\n StringBuffer sb = new StringBuffer();\n StringBuffer sb1 = new StringBuffer();\n PrintWriter out = new PrintWriter(System.out);\n// String[] s11 = s();\n int t=1;\n while(t-->0){\n String[] ss=s(); n=i(ss[0]);\n String[] s21=s();\n String[] s3=s();\n int r1=i(s21[0]);int s1=i(s21[1]);int p1=i(s21[2]);int r2=i(s3[0]);int s2=i(s3[1]);int p2=i(s3[2]);\n long max=Math.min(r1,s2)+Math.min(s1,p2)+Math.min(p1,r2);\n long min1=0; min=Long.MAX_VALUE;\n min1=Math.min(r1,r2);\n long min2=Math.min(r2-min1+s2,s1);\n min1+=min2;\n min1+=Math.min(p1,p2+s2-min2);\n min=Math.min(min,n-min1);\n\n min1=Math.min(s1,s2);\n min2=Math.min(s2-min1+p2,p1);\n min1+=min2;\n min1+=Math.min(r1,r2+p2-min2);\n min=Math.min(min,n-min1);\n\n min1=Math.min(p1,p2);\n min2=Math.min(p2-min1+r2,r1);\n min1+=min2;\n min1+=Math.min(s1,s2+r2-min2);\n min=Math.min(min,n-min1);\n\n go(r1,r2,s1,s2,p1,p2,0,1);\n System.out.println((min)+\" \"+max);\n }\n// System.out.println(sb.toString());\n }long min;int n;\n public void go(int r1,int r2,int s1,int s2,int p1,int p2,int ans,int count){\n if(count==1){\n// count++;\n go(r1-Math.min(r1,r2-Math.min(r2,s1)),r2-Math.min(r2,s1)-Math.min(r1,r2-Math.min(r2,s1)),s1-Math.min(r2,s1),s2,p1,p2,ans+Math.min(r2,s1)+Math.min(r1,r2-Math.min(r2,s1)),count+1);\n go(r1-Math.min(r1,r2),r2-Math.min(r1,r2)-Math.min(s1,r2-Math.min(r1,r2)),s1-Math.min(r2-Math.min(r1,r2),s1),s2,p1,p2,ans+Math.min(r1,r2)+Math.min(s1,r2-Math.min(r1,r2)),count+1);\n }else if(count==2){\n// count++;\n // r2 p2\n // s1 p1\n// System.out.println(ans);\n go(r1-Math.min(r1,p2),r2,s1,s2,p1-Math.min(p2-Math.min(r1,p2),p1),p2-Math.min(r1,p2)-Math.min(p1,p2-Math.min(r1,p2)),ans+Math.min(r1,p2)+Math.min(p1,p2-Math.min(r1,p2)),count+1);\n go(r1-Math.min(r1,p2-Math.min(p2,p1)),r2,s1,s2,p1-Math.min(p2,p1),p2-Math.min(p2,p1)-Math.min(r1,p2-Math.min(p2,p1)),ans+Math.min(p2,p1)+Math.min(r1,p2-Math.min(p2,p1)),count+1);\n\n }else if(count==3){\n// count++;\n //p2 s2\n //r1 s1\n// System.out.println(ans);\n go(r1,r2,s1-Math.min(s1,s2-Math.min(s2,p1)),s2-Math.min(s2,p1)-Math.min(s1,s2-Math.min(s2,p1)),p1-Math.min(s2,p1),p2,ans+Math.min(s2,p1)+Math.min(s1,s2-Math.min(s2,p1)),count+1);\n go(r1,r2,s1-Math.min(s1,s2),s2-Math.min(s1,s2)-Math.min(p1,s2-Math.min(s1,s2)),p1-Math.min(s2-Math.min(s1,s2),p1),p2,ans+Math.min(s1,s2)+Math.min(s1,s2-Math.min(s1,s2)),count+1);\n }else{\n min=Math.min(min,n-ans);return;\n }\n }\n public void arr(int[] a,int n) throws IOException{\n// BufferedReader s = new BufferedReader(new InputStreamReader(System.in));\n String[] s2=s();\n for(int i=0;i {\n\n public int compare(Student a, Student b){\n return a.b-b.b;}\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "673e450d2942580052b46a1d7ab507bf", "src_uid": "e6dc3bc64fc66b6127e2b32cacc06402", "difficulty": 1800.0} {"lang": "Java 8", "source_code": " import java.util.*;\nimport java.io.BufferedReader;\nimport java.io.FileInputStream;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.lang.Math; \n\npublic class Main{\n public static void main(String args[]) throws Exception\n {\n BuffredReader br = new BufferedREader(new InputStreamReader(System.in));\n String str = br.readLine();\n int q = 0;\n int a =0;\n int temp_a = 0;\n int temp_q =0;\n int count=0;\n for(int i=0;i0 && a>0)\n // {\n // count+= Math.max(q,a);\n // }\n if(temp_q!=0 && temp_a!=0)\n {\n q=temp_q;\n a=temp_a;\n temp_q=1;\n }\n else\n {\n temp_q++; \n }\n }\n else if(str.charAt(i) == 'A')\n {\n if(q!=0)\n {\n temp_a++;\n }\n }\n }\n System.out.println(q*a);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "49cae8f4520eb918c54da04b6fbcb44e", "src_uid": "8aef4947322438664bd8610632fe0947", "difficulty": 800.0} {"lang": "Java 7", "source_code": "import java.math.BigInteger;\nimport java.util.Scanner;\n\n/**\n * Created by andreilupu on 18/02/2016.\n */\npublic class J {\n\n public static void main(String[] args) {\n new J();\n }\n\n public J(){\n solve();\n }\n\n private void solve() {\n Scanner sc = new Scanner(System.in);\n String s = sc.nextLine();\n BigInteger v = new BigInteger(s);\n System.out.println(v.divide(new BigInteger(\"2520\")));\n }\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e312482c0df0fd2b8df84f765ed82cf9", "src_uid": "8551308e5ff435e0fc507b89a912408a", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "/*\n *\n * @author Mukesh Singh\n *\n */\n\nimport java.io.*;\nimport java.util.*;\nimport java.text.DecimalFormat;\n@SuppressWarnings(\"unchecked\")\npublic class AB {\t\n\t//solve test cases\n\tvoid solve() throws Exception {\n\t\tint sum1 = 0 ; int sum2 = 0 ;\n\t\tfor(int i = 0 ; i < 8 ; ++i ){\n\t\t\tString st = in.nextToken();\n\t\t\tfor(int j= 0 ; j < st.length(); ; ++j ){\n\t\t\t\tchar ch = st.charAt(j);\t\t\n\t\t\t\tif(ch=='Q') sum1+= 9;\n\t\t\t\tif(ch=='R') sum1+= 5;\n\t\t\t\tif(ch=='B') sum1+= 3;\n\t\t\t\tif(ch=='N') sum1+= 3;\n\t\t\t\tif(ch=='P') sum1+= 1;\n\t\t\t\tif(ch=='q') sum2+= 9;\n\t\t\t\tif(ch=='r') sum2+= 5;\n\t\t\t\tif(ch=='b') sum2+= 3;\n\t\t\t\tif(ch=='n') sum2+= 3;\n\t\t\t\tif(ch=='p') sum2+= 1;\n\t\t\t\t\n\t\t\t}\n\t\t}\n\t\t//System.out.println(sum1+\" \"+sum2);\n\t\tif(sum1== sum2) System.out.println(\"Draw\");\n\t\tif(sum1> sum2) System.out.println(\"White\");\n\t\tif(sum1< sum2) System.out.println(\"Black\");\n\t}\n\t\n\t//@ main function\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew AB();\n\t}\n\t\n\tInputReader in;\n\tPrintStream out ;\n\tDecimalFormat df ;\n\tAB() {\n\t\ttry {\n\t\t\tFile defaultInput = new File(\"file.in\");\n\t\t\tif (defaultInput.exists()) \n\t\t\t\tin = new InputReader(\"file.in\");\n\t\t\telse \n\t\t\t\tin = new InputReader();\n\t\t\tdefaultInput = new File(\"file.out\");\n\t\t\tif (defaultInput.exists()) \n\t\t\t\tout = new PrintStream(new FileOutputStream(\"file.out\"));\n\t\t\telse\n\t\t\t\tout = new PrintStream(System.out);\n\t\t\tdf = new DecimalFormat(\"######0.00\");\n\t\t\tsolve();\n\t\t\tout.close();\n\t\t} \n\t\tcatch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(261);\n\t\t}\n\t}\n\t\n\tclass InputReader {\n\t\tBufferedReader reader;\n\t\tStringTokenizer tokenizer;\n\t\t\n\t\tInputReader() {\n\t\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\t\t\n\t\tInputReader(String fileName) throws FileNotFoundException {\n\t\t\treader = new BufferedReader(new FileReader(new File(fileName)));\n\t\t}\n\t\t\n\t\tString readLine() throws IOException {\n\t\t\treturn reader.readLine();\n\t\t}\n\t\t\n\t\tString nextToken() throws IOException {\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens())\n\t\t\t\ttokenizer = new StringTokenizer(readLine());\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\t\t\n\t\tboolean hasMoreTokens() throws IOException {\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\tString s = readLine();\n\t\t\t\tif (s == null)\n\t\t\t\t\treturn false;\n\t\t\t\ttokenizer = new StringTokenizer(s);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t\t\n\t\tint nextInt() throws NumberFormatException, IOException {\n\t\t\treturn Integer.parseInt(nextToken());\n\t\t}\n\t\t\n\t\tlong nextLong() throws NumberFormatException, IOException {\n\t\t\treturn Long.parseLong(nextToken());\n\t\t}\n\t\t\n\t\tdouble nextDouble() throws NumberFormatException, IOException {\n\t\t\treturn Double.parseDouble(nextToken());\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "813071f9990feac2919798ec3729ec08", "src_uid": "44bed0ca7a8fb42fb72c1584d39a4442", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Solution\n{\n public static void main(String args[]) throws IOException\n {\n BufferedReader br= new BufferedReader(new InputStreamReader(System.in));\n int n=Integer.readLine(br.readLine());\n int a=1234567;\n int b=123456;\n int c=1234;\n int total=a+b+c;\n if(n'9'); c = nextChar()) {\n\t\t\t\tif(c=='-')neg=true;\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tfor(; c>='0' && c <='9'; c=nextChar()) {\n\t\t\t\tres = (res<<3)+(res<<1)+c-'0';\n\t\t\t\tnum*=10;\n\t\t\t}\n\t\t\treturn neg?-res:res;\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\tdouble cur = nextLong();\n\t\t\treturn c!='.' ? cur:cur+nextLong()/num;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\twhile(c<=32)c=nextChar();\n\t\t\twhile(c>32) {\n\t\t\t\tres.append(c);\n\t\t\t\tc=nextChar();\n\t\t\t}\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\twhile(c<=32)c=nextChar();\n\t\t\twhile(c!='\\n') {\n\t\t\t\tres.append(c);\n\t\t\t\tc=nextChar();\n\t\t\t}\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic boolean hasNext() {\n\t\t\tif(c>32)return true;\n\t\t\twhile(true) {\n\t\t\t\tc=nextChar();\n\t\t\t\tif(c==NC)return false;\n\t\t\t\telse if(c>32)return true;\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic int[] nextIntArray(int n) {\n\t\t\tint[] res = new int[n];\n\t\t\tfor(int i = 0; i < n; i++) res[i] = nextInt();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "77374624c0bd0503d93842923eed4dfc", "src_uid": "59f40d9f35e5fe402112214b42b682b5", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "// package EducationalRound88;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class ProblemE {\n public static void main(String[] args)throws IOException {\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer st=new StringTokenizer(br.readLine());\n int n=Integer.parseInt(st.nextToken());\n int k=Integer.parseInt(st.nextToken());\n int mod=998244353;\n long fact[]=new long[n+1];\n fact[1]=1;\n fact[0]=1;\n for(int i=2;i<=n;i++){\n fact[i]=(fact[i-1]*i)%mod;\n }\n long ans=0;\n for(int i=1;i<=n;i++){\n int p=(n-i)/i;\n int r=k-1;\n if(p() {\n @Override\n public int compare(int[] a1, int[] a2) {\n return a1[1] - a2[1];\n }\n });\n String ans = \"\";\n int count = 0;\n int c = 0;\n for(int i=0;i>= 1;\r\n }\r\n int sum = 0;\r\n for(int i=0;i=arr[j-1])\r\n dp[i][j] = dp[i-arr[j-1]][j-1] dp[i][j-1];\r\n else dp[i][j] = dp[i][j-1];\r\n }\r\n }\r\n if(dp[sum/2][n]) {\r\n for(int i=0;i arr,boolean[] chosen) {\r\n if(arr.size() == n) {\r\n\r\n }else {\r\n for(int i=1; i<=n; i++) {\r\n if(chosen[i]) continue;\r\n arr.add(i);\r\n chosen[i] = true;\r\n premutation(n,arr,chosen);\r\n arr.remove(i);\r\n chosen[i] = false;\r\n }\r\n }\r\n }\r\n static boolean isPalindrome(char[] c) {\r\n int n = c.length;\r\n for(int i=0; i\r\n {\r\n int value,index;\r\n Pairs(int value, int index) {\r\n this.value = value;\r\n this.index = index;\r\n }\r\n public int compareTo(Pairs p) {\r\n return Integer.compare(this.value,p.value);\r\n }\r\n }\r\n}\r\nclass FastScanner\r\n{\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n StringTokenizer str = new StringTokenizer(\"\");\r\n\r\n String next() throws IOException\r\n {\r\n while(!str.hasMoreTokens())\r\n str = new StringTokenizer(br.readLine());\r\n\r\n return str.nextToken();\r\n }\r\n\r\n char nextChar() throws IOException {\r\n return next().charAt(0);\r\n }\r\n\r\n int nextInt() throws IOException\r\n {\r\n return Integer.parseInt(next());\r\n }\r\n\r\n float nextfloat() throws IOException\r\n {\r\n return Float.parseFloat(next());\r\n }\r\n\r\n double nextDouble() throws IOException\r\n {\r\n return Double.parseDouble(next());\r\n }\r\n long nextLong() throws IOException\r\n {\r\n return Long.parseLong(next());\r\n }\r\n byte nextByte() throws IOException\r\n {\r\n return Byte.parseByte(next());\r\n }\r\n int [] arrayIn(int n) throws IOException\r\n {\r\n int arr[] = new int[n];\r\n for(int i=0; i max) {\n max = cur;\n maxs = new String(b);\n }\n \n next();\n } while(!(b.charAt(0) == '7' && b.length() == len));\n \n print(max == 0 ? \"-1\" : maxs);\n close();\n }\n //=========================================================================================================================\n BufferedReader in;\n PrintWriter out;\n StringTokenizer strTok;\n \n Run() {\n if (consoleIO) {\n initConsoleIO();\n }\n else {\n initFileIO();\n }\n }\n \n void initConsoleIO() {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(new OutputStreamWriter(System.out));\n }\n \n void initFileIO() {\n try {\n in = new BufferedReader(new FileReader(inFile));\n out = new PrintWriter(new FileWriter(outFile));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n \n void close() {\n try {\n in.close();\n out.close();\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n \n int nextInt() {\n return Integer.parseInt(nextToken());\n }\n \n double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n \n float nextFloat() {\n return Float.parseFloat(nextToken());\n }\n \n long nextLong() {\n return Long.parseLong(nextToken());\n }\n \n String nextLine() {\n try {\n return in.readLine();\n } catch (IOException e) {\n return \"__NULL\";\n }\n }\n \n boolean hasMoreTokens() {\n return (strTok == null) || (strTok.hasMoreTokens());\n }\n \n String nextToken() {\n while (strTok == null || !strTok.hasMoreTokens()) {\n String line;\n try {\n line = in.readLine();\n strTok = new StringTokenizer(line);\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n \n return strTok.nextToken();\n }\n \n void cout(Object o){\n System.out.println(o);\n }\n \n void print(Object o) {\n out.write(o.toString());\n }\n \n void println(Object o) {\n out.write(o.toString() + '\\n');\n }\n \n void printf(String format, Object... args) {\n out.printf(format, args);\n }\n \n String sprintf(String format, Object... args) {\n return MessageFormat.format(format, args);\n }\n }\n \n static class Pair {\n A a;\n B b;\n \n A f() {\n return a;\n }\n \n B s() {\n return b;\n }\n \n Pair(A a, B b) {\n this.a = a;\n this.b = b;\n }\n \n Pair(Pair p) {\n a = p.f();\n b = p.s();\n }\n }\n \n public static void main(String[] args) throws IOException {\n Run run = new Run();\n Thread thread = new Thread(run);\n thread.run();\n }\n }", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ab2bc81ee18c763f0ea4a50e184e7e13", "src_uid": "639b8b8d0dc42df46b139f0aeb3a7a0a", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.HashSet;\nimport java.util.Scanner;\nimport java.util.Set;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.lang.Math; \n\npublic class Lo {\n public static long gcd(long a, long b){\n if(b==0){\n return a;\n }\n else{\n return gcd(b, a%b);\n }\n } \n public static int coprime(long a, long b){\n if(gcd(a,b)==1){\n return 1;\n }\n else{\n return 0;\n }\n }\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n long a = sc.nextLong();\n long b = sc.nextLong();\n ArrayList A = new ArrayList ();\n ArrayList B = new ArrayList ();\n for(long i = a; i <= b; i++){\n for(long j = i+1; j <= b; j++){\n if(coprime(i,j)==1){\n A.add(i);\n B.add(j);\n }\n }\n }\n int flag = 0;\n for(int i = 0; i < A.size(); i++){\n for(int j = i+1; j < A.size(); j++){\n if(A.get(j)==B.get(i) && coprime(A.get(i),B.get(j))!=1){\n System.out.print(A.get(i)+\" \");\n System.out.print(B.get(i)+\" \");\n System.out.print(B.get(j));\n break;\n flag = 1;\n }\n }\n }\n if(flag==0){\n System.out.print(-1);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "78adffe270a37028abcb926fb87f0a73", "src_uid": "6c1ad1cc1fbecff69be37b1709a5236d", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.math.*;\npublic class tester\n{\n public static void main(String arg[])\n {\n Scanner s=new Scanner(System.in);\n long a=s.nextLong();\n long b=s.nextLong();\n String s1=Long.toString(a);\n String s2=Long.toString(b);\n if(s1.length()=0;i--)\n System.out.print(c[i]);\n }\n else\n {\n System.out.println(fun(s1,s2));\n }\n \n }\n public static int find(String st,char c)\n {\n int max=-1;\n int x=c-48;\n for(int i=0;imax)\n {\n max=st.charAt(i)-48;\n }\n }\n return max;\n }\n public static String fun(String s1,String s2)\n {\n int x=find(s1,s2.charAt(0));\n String ans=\"\";\n if(x=0;i--)\n ans+=c[i];\n return ans;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bf809bc9d68074a0b8b7583bd83b7fde", "src_uid": "bc31a1d4a02a0011eb9f5c754501cd44", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "package Round426;\n\nimport java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class Ques2 {\n\n static class Scan {\n\n private final InputStream inputStream;\n private final byte[] buffer = new byte[1024];\n private int currentChar;\n private int numChars;\n private SpaceCharFilter filter;\n\n public Scan() {\n inputStream = System.in;\n }\n\n public int read() {\n if (numChars==-1)\n throw new InputMismatchException();\n\n if (currentChar >= numChars) {\n currentChar = 0;\n try {\n numChars = inputStream.read(buffer);\n }\n catch (IOException e) {\n throw new InputMismatchException();\n }\n\n if(numChars <= 0)\n return -1;\n }\n return buffer[currentChar++];\n }\n\n public String nextLine() {\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n String str = \"\";\n\n try {\n str = br.readLine();\n }\n catch (IOException e) {\n }\n return str;\n }\n\n public int nextInt() {\n int ch = read();\n\n while(isSpaceChar(ch))\n ch = read();\n\n int sgn = 1;\n\n if (ch == '-') {\n sgn = -1;\n ch = read();\n }\n\n int res = 0;\n do {\n if(ch < '0' || ch > '9')\n throw new InputMismatchException();\n res *= 10;\n res += ch - '0';\n ch = read();\n }\n while (!isSpaceChar(ch));\n\n return res * sgn;\n }\n\n public long nextLong() {\n int ch = read();\n\n while (isSpaceChar(ch))\n ch = read();\n\n int sgn = 1;\n\n if (ch == '-') {\n sgn = -1;\n ch = read();\n }\n\n long res = 0;\n\n do {\n if (ch < '0' || ch > '9')\n throw new InputMismatchException();\n res *= 10;\n res += ch - '0';\n ch = read();\n }\n while (!isSpaceChar(ch));\n\n return res * sgn;\n }\n\n public double nextDouble() {\n int ch = read();\n\n while (isSpaceChar(ch))\n ch = read();\n\n int sgn = 1;\n if (ch == '-') {\n sgn = -1;\n ch = read();\n }\n\n double res = 0;\n while (!isSpaceChar(ch) && ch != '.') {\n if (ch == 'e' || ch == 'E')\n return res * Math.pow(10, nextInt());\n if (ch < '0' || ch > '9')\n throw new InputMismatchException();\n res *= 10;\n res += ch - '0';\n ch = read();\n }\n if (ch == '.') {\n ch = read();\n double m = 1;\n while (!isSpaceChar(ch)) {\n if (ch == 'e' || ch == 'E')\n return res * Math.pow(10, nextInt());\n if (ch < '0' || ch > '9')\n throw new InputMismatchException();\n m /= 10;\n res += (ch - '0') * m;\n ch = read();\n }\n }\n\n return res * sgn;\n }\n\n public String readString() {\n int ch = read();\n while (isSpaceChar(ch))\n ch = read();\n\n StringBuilder res = new StringBuilder();\n\n do {\n res.appendCodePoint(ch);\n ch = read();\n }\n while (!isSpaceChar(ch));\n\n return res.toString();\n }\n\n public boolean isSpaceChar(int ch) {\n if (filter != null)\n return filter.isSpaceChar(ch);\n return ch == ' ' || ch == '\\n' || ch == '\\r' || ch == '\\t' || ch == -1;\n }\n\n public String next() {\n return readString();\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n }\n\n static class Print {\n private final BufferedWriter bw;\n\n public Print() {\n this.bw=new BufferedWriter(new OutputStreamWriter(System.out));\n }\n\n public void print(Object object)throws IOException {\n bw.append(\"\"+object);\n }\n\n public void println(Object object)throws IOException {\n print(object);\n bw.append(\"\\n\");\n }\n\n public void close()throws IOException {\n bw.close();\n }\n }\n\n public static void main(String args[]) throws IOException {\n Scan sc = new Scan();\n Print pr = new Print();\n\n int n, k, c=0;\n n = sc.nextInt();\n k = sc.nextInt();\n\n String str = sc.next();\n int arr[][] = new int[26][2];\n\n for(int i=n-1; i>=0; i--) {\n if (arr[str.charAt(i) - 65][0] == 0)\n arr[str.charAt(i) - 65][0] = i;\n }\n\n for(int i=0; ik) {\n pr.println(\"YES\");\n pr.close();\n return;\n }\n if (arr[str.charAt(i) - 65][0] == i) {\n c--;\n }\n }\n\n pr.println(\"NO\");\n pr.close();\n\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c9cab13781d769b0528927b1d80c4773", "src_uid": "216323563f5b2dd63edc30cb9b4849a5", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.*; \npublic class Main{\n public static void main(String ... S){\n Scanner sc = new Scanner(System.in); \n int a[] = new a[4]; \n a[0] =sc.nextInt(); \n a[1]= sc.nextInt(); \n a[2] = sc.nextInt(); \n a[3] = sc.nextInt(); \n Arrays.sort(a);\n if(2*a[2] < a[1] + a[2] + a[0])\n System.out.println(\"TRIANGLE\");\n else if(a[2] >= a[0] + a[1])\n System.out.println(\"SEGMENT\"); \n else System.out.println(\"IMPOSSIBLE\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "56bb083e8bde998b57d881081f812aeb", "src_uid": "8f5df9a41e6e100aa65b9fc1d26e447a", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class polycrapAndLetters {\n\tpublic static void main(String args[]){\n\t\tScanner kd=new Scanner(System.in);\n\t\tint a=kd.nextInt();\n\t\tString s=kd.next();\n\t\tint answer=0;\n\t\tint number[]=new int[27];\n\t\tint i=0;\n\t\tdo{\n\t\t\tif(s.charAt(i)<97){\n\t\t\t\tnumber=new int[27];\n\t\t\t}\n\t\t\telse{\n\t\t\t\tif(number[s.charAt(n)-96]==0){\n\t\t\t\t\tnumber[s.charAt(n)-96]=1;\n\t\t\t\t\tnumber[0]++;\n\t\t\t\t\tif(number[0]>answer){\n\t\t\t\t\t\tanswer=number[0];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\ti++;\n\t\t}while(i=b2b3)\n\t\t\t\tmin=b2b3;\n\t\t\t\telse min=b1b2;\n\t\t\t\tif(min>=b1b3)\n\t\t\t\t\tmin=b1b3;\n\t\t\t\telse min=min;\n\t\t\t\t\n\t\t\t\tif(min==b1b2)\n\t\t\t\t\tb3=(b1+b2-1);\n\t\t\t\telse if(min==b2b3)\n\t\t\t\t\tb1=b2+b3-1;\n\t\t\t\telse if(min==b1b3)\n\t\t\t\t\tb2=b1+b3-1;\n\t\t\t\t\n\t\t\t\tcount++;\n\t\t\t\t\n\t\t\t}\n\t\t\to.println(count+2);\n\t\t}\n \n\t\n\t\to.close();\n\t}\n\n\tpublic int[] sieve(int n){\n\t\tboolean[] isPrime = new boolean[n+1];\n for (int i = 2; i <= n; i++) {\n isPrime[i] = true;\n }\n\n // mark non-primes <= n using Sieve of Eratosthenes\n for (int factor = 2; factor*factor <= n; factor++) {\n\n \t// if factor is prime, then mark multiples of factor as nonprime\n \n if (isPrime[factor]) {\n for (int j = factor; factor*j <= n; j++) {\n isPrime[factor*j] = false;\n }\n }\n }\n // count primes\n int primes = 0;\n for (int i = 2; i <= n; i++) {\n if (isPrime[i]) primes++;\n }\n int a[]=new int[primes];\n int j=0;\n for (int i = 2; i <= n; i++) {\n if (isPrime[i]) {\n \t a[j]=i;\n \t j++;\n }\n \t \n }\n\t\treturn a;\n\t}\n\t// pair object x,y\n\tstatic class pair {\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 + x;\n\t\t\tresult = prime * result + y;\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\tpair other = (pair) obj;\n\t\t\tif (x != other.x)\n\t\t\t\treturn false;\n\t\t\tif (y != other.y)\n\t\t\t\treturn false;\n\t\t\treturn true;\n\t\t}\n\n\t\tint x, y;\n\n\t\tpublic pair(int x, int y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\t}\n\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\tstatic long[][] modPow(long[][] M, long exp) {\n\t\tlong[][] result = new long[][] { { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }, { 0, 0, 0, 1 } };\n\t\tlong[][] pow = M;\n\t\twhile (exp != 0) {\n\t\t\tif ((exp & 1) == 1) {\n\t\t\t\tresult = multiply(result, pow);\n\t\t\t}\n\t\t\texp >>>= 1;\n\t\t\tpow = multiply(pow, pow);\n\t\t}\n\t\treturn result;\n\t}\n\n\tstatic long[][] multiply(long[][] A, long[][] B) {\n\t\tlong[][] C = new long[4][4];\n\t\tfor (int i = 0; i < 4; i++) {\n\t\t\tfor (int j = 0; j < 4; j++) {\n\t\t\t\tlong value = 0;\n\t\t\t\tfor (int k = 0; k < 4; k++) {\n\t\t\t\t\tvalue += A[i][k] * B[k][j];\n\t\t\t\t}\n\t\t\t\tC[i][j] = value % m;\n\t\t\t}\n\t\t}\n\t\treturn C;\n\t}\n\n\t// input/output\n\tstatic 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 final String readString() throws IOException {\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.append((char) c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tprivate boolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\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\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\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 (c == '.')\n\t\t\t\twhile ((c = read()) >= '0' && c <= '9')\n\t\t\t\t\tret += (c - '0') / (div *= 10);\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\n\t\tpublic int[] readIntArray(int size) throws IOException {\n\t\t\tint[] arr = new int[size];\n\t\t\tfor (int i = 0; i < size; i++)\n\t\t\t\tarr[i] = nextInt();\n\t\t\treturn arr;\n\t\t}\n\n\t\tpublic long[] readLongArray(int size) throws IOException {\n\t\t\tlong[] arr = new long[size];\n\t\t\tfor (int i = 0; i < size; i++)\n\t\t\t\tarr[i] = nextLong();\n\t\t\treturn arr;\n\t\t}\n\n\t\tprivate void fillBuffer() throws IOException {\n\t\t\tbytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n\t\t\tif (bytesRead == -1)\n\t\t\t\tbuffer[0] = -1;\n\t\t}\n\n\t\tprivate byte read() throws IOException {\n\t\t\tif (bufferPointer == bytesRead)\n\t\t\t\tfillBuffer();\n\t\t\treturn buffer[bufferPointer++];\n\t\t}\n\n\t\tpublic void close() throws IOException {\n\t\t\tif (din == null)\n\t\t\t\treturn;\n\t\t\tdin.close();\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1e822481243bfccce09a77656dbbd4cc", "src_uid": "8edf64f5838b19f9a8b19a14977f5615", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class position {\n\n InputStream is;\n PrintWriter out;\n \n long maxl = (long) 4e18, mod = (long)1e9 + 7L;\n \n void solve(){\n //Enter code here utkarsh\n BigDecimal a = new BigDecimal(ns());\n BigDecimal b = new BigDecimal(ns());\n int c = ni();\n BigDecimal x = a.divide(b, 1234, RoundingMode.CEILING);\n String s = x.toString();\n int i = s.indexOf('.');\n char j = s.indexOf((char)(c + '0'), i+1);\n if(j == -1 || j > 1000) out.println(\"-1\");\n else out.println(j - i);\n }\n \n long modpow(long base, long exp, long modulus) { base %= modulus; long result = 1L; while (exp > 0) { if ((exp & 1)==1) result = (result * base) % modulus; base = (base * base) % modulus; exp >>= 1; } return result;\n }\n \n public static void main(String[] args) { new utkarsh().run();\n }\n void run(){ is = System.in; out = new PrintWriter(System.out); solve(); out.flush();\n }\n \n byte input[] = new byte[1024];\n int len = 0, ptr = 0;\n \n int readByte(){ if(ptr >= len){ ptr = 0; try{ len = is.read(input); }catch(IOException e){ throw new InputMismatchException(); } if(len <= 0){ return -1; } } return input[ptr++];\n }\n char isSpaceChar(int c){ return !( c >= 33 && c <= 126 ); \n }\n int skip(){ int b = readByte(); while(b != -1 && isSpaceChar(b)){ b = readByte(); } return b;\n }\n \n char nc(){ return (char)skip();\n }\n String ns(){ int b = skip(); StringBuilder sb = new StringBuilder(); while(!isSpaceChar(b)){ sb.appendCodePoint(b); b=readByte(); } return sb.toString();\n }\n int ni(){ int n = 0,b = readByte(); boolean minus = false; while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')){ b = readByte(); } if(b == '-'){ minus = true; b = readByte(); } if(b == -1){ return -1; } while(b >= '0' && b <= '9'){ n = n * 10 + (b - '0'); b = readByte(); } return minus ? -n : n;\n }\n long nl(){ long n = 0L; int b = readByte(); boolean minus = false; while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')){ b = readByte(); } if(b == '-'){ minus = true; b = readByte(); } while(b >= '0' && b <= '9'){ n = n * 10 + (b - '0'); b = readByte(); } return minus ? -n : n;\n }\n double nd(){ return Double.parseDouble(ns());\n }\n float nf(){ return Float.parseFloat(ns());\n }\n int[] na(int n){ int a[] = new int[n]; for(int i = 0; i < n; i++){ a[i] = ni(); } return a;\n }\n char[] ns(int n){ char c[] = new char[n]; int i,b = skip(); for(i = 0; i < n; i++){ if(isSpaceChar(b)){ break; } c[i] = (char)b; b = readByte(); } return i == n ? c : Arrays.copyOf(c,i);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ae2fd43f2a10de6e7cc683c11d546c65", "src_uid": "0bc7bf67b96e2898cfd8d129ad486910", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "\n\nimport org.apache.commons.lang3.ArrayUtils;\n\nimport java.util.*;\n\n/**\n * Created by sourav.p on .\n */\n\npublic class SolveA {\n private static int ans = 0;\n private static Queue queue = new LinkedList<>();\n private static Set marked = new HashSet<>();\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int k = in.nextInt();\n String str = in.next();\n queue.add(str);\n marked.add(str);\n while(!queue.isEmpty() && marked.size() < k) {\n String first = queue.poll();\n for(int i=0; i 0){\n\t\t\tcount += r/costOfBurger;\n\t\t}\n\t\tSystem.out.println(count);\n\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ae9bc1c09eb4d5c506fe0e35e92e42b0", "src_uid": "8126a4232188ae7de8e5a7aedea1a97e", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "package shower;\n\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.List;\nimport java.util.Scanner;\n\npublic class Shower {\n public static void main(String[] args) {\n int g[][] = new int[6][6];\n Scanner sc = new Scanner(System.in);\n for (int i = 1; i <=5; i++) {\n for (int j = 1; j <= 5; j++) {\n g[i][j] = sc.nextInt();\n }\n }\n System.out.println(maxHappiness(g));\n }\n\n public static int maxHappiness(int[][] g) {\n int max = -1;\n List values = new ArrayList(Arrays.asList(0,1,2,3,4,5));\n do {\n if (getHappiness(g, values) > max) {\n max = getHappiness(g, values);\n }\n }while(next_permutation(values, 5));\n return max;\n }\n\n public static int getHappiness(int[][] g, List values) {\n// int[] newValues = values.stream().mapToInt(Integer::intValue).toArray();\n// int[] newValues\n// int happiness = g[newValues[1]][newValues[2]] + g[newValues[2]][newValues[1]] +\n// g[newValues[2]][newValues[3]] + g[newValues[3]][newValues[2]] +\n// 2*(g[newValues[3]][newValues[4]] + g[newValues[4]][newValues[3]] +\n// g[newValues[4]][newValues[5]] + g[newValues[5]][newValues[4]]);\n int happiness = g[values.get(1)][values.get(2)] + g[values.get(2)][values.get(1)] +\n g[values.get(2)][values.get(3)] + g[values.get(3)][values.get(2)] +\n 2*(g[values.get(3)][values.get(4)] + g[values.get(4)][values.get(3)] +\n g[values.get(4)][values.get(5)] + g[values.get(5)][values.get(4)]);\n return happiness;\n }\n\n public static boolean next_permutation(List values, int n) {\n for (int i = n; i >= 2; i--) {\n if (values.get(i) > values.get(i-1)){\n checkAndSwap(values, i-1, n);\n reverse(values, i, n);\n return true;\n }\n }\n return false;\n }\n\n public static void checkAndSwap(List values, int i, int n) {\n int pos = -1;\n for (int j = i+1; j <= n; j++) {\n if (values.get(j) > values.get(i)){\n pos = j;\n }\n }\n swap(values, i, pos);\n }\n\n public static void reverse(List values, int front, int end) {\n while(end > front) {\n swap(values, front, end);\n front++;\n end--;\n }\n }\n\n public static void swap(List values, int i, int j) {\n int temp = values.get(i);\n values.set(i, values.get(j));\n values.set(j, temp);\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e5f4efc06908ac4257dc27ced306946e", "src_uid": "be6d4df20e9a48d183dd8f34531df246", "difficulty": 1200.0} {"lang": "Java 7", "source_code": "import java.util.*;\n\npublic class Main {\n public static void main (String args[]) {\n Scanner sc = new Scanner(System.in);\n System.out.println(ispalindrome(sc.nextLine());\n }\n \n public static boolean ispalindrome(String s) {\n for (int i = 0; i < s.length()/2; i++) {\n if (s.charAt(i) != s.charAt(s.length()-1-i))\n return false;\n }\n return true;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4df36cd4c52047aea7cccd72aeddd116", "src_uid": "24e8aaa7e3e1776adf342ffa1baad06b", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "public class main {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n // TODO code application logic here\n\n Scanner entrada= new Scanner(System.in);\n \n int moneda = entrada.nextInt();\n \n StringBuilder builder = new StringBuilder();\n \n for (int i = moneda; i>=1; i--) {\n if (moneda % i == 0) {\n builder.append(i).append(\" \");\n moneda = i;\n }\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e30ca8a74d3bb9182c193fd9121060a5", "src_uid": "2fc946bb72f56b6d86eabfaf60f9fa63", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class a {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int num = scan.nextInt();\n String s = scan.nextLine();\n ArrayList list = new ArrayList();\n for(int i=0; i addDigits(ArrayList list, int input){\n \n ArrayList output = new ArrayList(list);\n if(input == 2){output.add(2);}\n else if(input == 3){output.add(3);}\n else if(input == 4){output.add(2); output.add(2); output.add(3);}\n else if(input == 5){output.add(5);}\n else if(input == 6){output.add(3); output.add(5);}\n else if(input == 7){output.add(7);}\n else if(input == 8){output.add(2); output.add(2); output.add(2); output.add(7);}\n else if(input == 9){output.add(2); output.add(3); output.add(3); output.add(7);}\n\n return output;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "080242ba2fe7bca9e65feb567ee3fb5d", "src_uid": "60dbfc7a65702ae8bd4a587db1e06398", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.ArrayDeque;\nimport java.util.Arrays;\nimport java.util.Locale;\nimport java.util.StringTokenizer;\n\npublic class A implements Runnable {\n\n private static final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\n private BufferedReader in;\n private PrintWriter out;\n private StringTokenizer tok = new StringTokenizer(\"\");\n\n private void init() throws FileNotFoundException {\n Locale.setDefault(Locale.US);\n String fileName = \"\";\n if (ONLINE_JUDGE && fileName.isEmpty()) {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n } else {\n if (fileName.isEmpty()) {\n in = new BufferedReader(new FileReader(\"input.txt\"));\n out = new PrintWriter(\"output.txt\");\n } else {\n in = new BufferedReader(new FileReader(fileName + \".in\"));\n out = new PrintWriter(fileName + \".out\");\n }\n }\n }\n\n String readString() {\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() {\n return Integer.parseInt(readString());\n }\n\n long readLong() {\n return Long.parseLong(readString());\n }\n\n double readDouble() {\n return Double.parseDouble(readString());\n }\n\n int[] readIntArray(int size) {\n int[] a = new int[size];\n for (int i = 0; i < size; i++) {\n a[i] = readInt();\n }\n return a;\n }\n\n public static void main(String[] args) {\n //new Thread(null, new _Solution(), \"\", 128 * (1L << 20)).start();\n new A().run();\n }\n\n long timeBegin, timeEnd;\n\n void time() {\n timeEnd = System.currentTimeMillis();\n System.err.println(\"Time = \" + (timeEnd - timeBegin));\n }\n\n @Override\n public void run() {\n try {\n timeBegin = System.currentTimeMillis();\n init();\n solve();\n out.close();\n time();\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(-1);\n }\n }\n\n boolean[][] a;\n int[] color;\n int n;\n\n boolean foundError = false;\n\n void dfs(int v, int c) {\n color[v] = c;\n for (int to = 0; to < n; to++) {\n if (a[v][to]) {\n if (color[to] == -1) {\n dfs(to, 1 - c);\n } else {\n if (color[to] != 1 - c) {\n foundError = true;\n return;\n }\n }\n }\n }\n }\n\n private void solve() {\n n = readInt();\n int m = readInt();\n a = new boolean[n][n];\n for (int i = 0; i < n; i++) {\n Arrays.fill(a[i], true);\n a[i][i] = false;\n }\n while (m-->0) {\n int x = readInt() - 1;\n int y = readInt() - 1;\n a[x][y] = false;\n a[y][x] = false;\n }\n\n boolean[] used = new boolean[n];\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n used[i] |= a[i][j];\n }\n }\n\n color = new int[n];\n Arrays.fill(color, -1);\n\n for (int i = 0; i < n; i++) {\n if (color[i] == -1) {\n if (!used[i]) {\n color[i] = 2;\n continue;\n }\n dfs(i, 0);\n if (foundError) {\n out.println(\"No\");\n return;\n }\n }\n }\n if (foundError) {\n out.println(\"No\");\n return;\n }\n\n out.println(\"Yes\");\n for (int i = 0; i < n; i++) {\n out.print(color[i] == 0 ? 'a' : (color[i] == 1 ? 'c' : 'b'));\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2bb950c4c6d4441cea623865bec66435", "src_uid": "e71640f715f353e49745eac5f72e682a", "difficulty": 1800.0} {"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.util.Random;\nimport java.io.UncheckedIOException;\nimport java.io.Closeable;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, new TaskAdapter(), \"\", 1 << 27);\n thread.start();\n thread.join();\n }\n\n static class TaskAdapter implements Runnable {\n @Override\n public void run() {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastInput in = new FastInput(inputStream);\n FastOutput out = new FastOutput(outputStream);\n BGluttony solver = new BGluttony();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class BGluttony {\n public void solve(int testNumber, FastInput in, FastOutput out) {\n int n = in.readInt();\n int[] a = new int[n];\n int[] indices = new int[n];\n for (int i = 0; i < n; i++) {\n a[i] = in.readInt();\n indices[i] = i;\n }\n CompareUtils.quickSort(indices, (i, j) -> Integer.compare(a[i], a[j]), 0, n);\n int[] b = new int[n];\n for (int i = 0; i < n; i++) {\n b[indices[DigitUtils.mod(i - 1, n)]] = a[indices[i]];\n }\n\n for (int x : b) {\n out.append(x).append(' ');\n }\n }\n\n }\n\n static class CompareUtils {\n private static final int THRESHOLD = 4;\n\n private CompareUtils() {\n }\n\n public static void insertSort(int[] data, IntegerComparator cmp, int l, int r) {\n for (int i = l + 1; i <= r; i++) {\n int j = i;\n int val = data[i];\n while (j > l && cmp.compare(data[j - 1], val) > 0) {\n data[j] = data[j - 1];\n j--;\n }\n data[j] = val;\n }\n }\n\n public static void quickSort(int[] data, IntegerComparator cmp, int f, int t) {\n if (t - f <= THRESHOLD) {\n insertSort(data, cmp, f, t - 1);\n return;\n }\n SequenceUtils.swap(data, f, Randomized.nextInt(f, t - 1));\n int l = f;\n int r = t;\n int m = l + 1;\n while (m < r) {\n int c = cmp.compare(data[m], data[l]);\n if (c == 0) {\n m++;\n } else if (c < 0) {\n SequenceUtils.swap(data, l, m);\n l++;\n m++;\n } else {\n SequenceUtils.swap(data, m, --r);\n }\n }\n quickSort(data, cmp, f, l);\n quickSort(data, cmp, m, t);\n }\n\n }\n\n static class FastOutput implements AutoCloseable, Closeable, Appendable {\n private StringBuilder cache = new StringBuilder(10 << 20);\n private final Writer os;\n\n public FastOutput append(CharSequence csq) {\n cache.append(csq);\n return this;\n }\n\n public FastOutput append(CharSequence csq, int start, int end) {\n cache.append(csq, start, end);\n return this;\n }\n\n public FastOutput(Writer os) {\n this.os = os;\n }\n\n public FastOutput(OutputStream os) {\n this(new OutputStreamWriter(os));\n }\n\n public FastOutput append(char c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput append(int c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput flush() {\n try {\n os.append(cache);\n os.flush();\n cache.setLength(0);\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n return this;\n }\n\n public void close() {\n flush();\n try {\n os.close();\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n public String toString() {\n return cache.toString();\n }\n\n }\n\n static class SequenceUtils {\n public static void swap(int[] data, int i, int j) {\n int tmp = data[i];\n data[i] = data[j];\n data[j] = tmp;\n }\n\n }\n\n static class RandomWrapper {\n private Random random;\n public static final RandomWrapper INSTANCE = new RandomWrapper(new Random());\n\n public RandomWrapper() {\n this(new Random());\n }\n\n public RandomWrapper(Random random) {\n this.random = random;\n }\n\n public int nextInt(int l, int r) {\n return random.nextInt(r - l + 1) + l;\n }\n\n }\n\n static class FastInput {\n private final InputStream is;\n private byte[] buf = new byte[1 << 20];\n private int bufLen;\n private int bufOffset;\n private int next;\n\n public FastInput(InputStream is) {\n this.is = is;\n }\n\n private int read() {\n while (bufLen == bufOffset) {\n bufOffset = 0;\n try {\n bufLen = is.read(buf);\n } catch (IOException e) {\n bufLen = -1;\n }\n if (bufLen == -1) {\n return -1;\n }\n }\n return buf[bufOffset++];\n }\n\n public void skipBlank() {\n while (next >= 0 && next <= 32) {\n next = read();\n }\n }\n\n public int readInt() {\n int sign = 1;\n\n skipBlank();\n if (next == '+' || next == '-') {\n sign = next == '+' ? 1 : -1;\n next = read();\n }\n\n int val = 0;\n if (sign == 1) {\n while (next >= '0' && next <= '9') {\n val = val * 10 + next - '0';\n next = read();\n }\n } else {\n while (next >= '0' && next <= '9') {\n val = val * 10 - next + '0';\n next = read();\n }\n }\n\n return val;\n }\n\n }\n\n static class Randomized {\n public static int nextInt(int l, int r) {\n return RandomWrapper.INSTANCE.nextInt(l, r);\n }\n\n }\n\n static class DigitUtils {\n private DigitUtils() {\n }\n\n public static int mod(int x, int mod) {\n x %= mod;\n if (x < 0) {\n x += mod;\n }\n return x;\n }\n\n }\n\n static interface IntegerComparator {\n public int compare(int a, int b);\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3037ac235b60f2a8fbcd8699f2a5f0e0", "src_uid": "e314642ca1f82be8f223e2eba00b5531", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class abc12\n{\n public static void main(String args[])\n {\n Scanner sc=new Scanner(System.in);\n long a=sc.nextLong();\n long b=sc.nextLong();\n if(a==0 && b==0)\n {\n System.out.print(\"YES\");\n return;\n }\n sc.nextLine();\n String s=sc.nextLine();\n long x[][]=new long[s.length()][2];\n int m=0;\n int n=0;\n for(int i=0;i4 && loc <13) {\n\t\t\t\t\tif (checkCenterUpDown(i, j)) {System.out.print(\"YES\");return;}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.print(\"NO\");\n\t}\n\tpublic static boolean checkLeft(int x,int y){\n\t\tif (array[x][y-1] == 1 && array[x][y-2] == 1) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\tpublic static boolean checkRight(int x,int y){\n\t\tif (array[x][y+1] == 1 && array[x][y+2] == 1) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\tpublic static boolean checkUp(int x,int y){\n\t\tif (array[x-1][y] == 1 && array[x-2][y] == 1) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\tpublic static boolean checkDown(int x,int y){\n\t\tif (array[x+1][y] == 1 && array[x+2][y] == 1) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\tpublic static boolean checkLeftUp(int x, int y){\n\t\tif (array[x-1][y-1] == 1 && array[x-2][y-2] == 1) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\tpublic static boolean checkLeftDown(int x, int y){\n\t\tif (array[x+1][y-1] == 1 && array[x+2][y-2] == 1) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\tpublic static boolean checkRightDown(int x, int y){\n\t\tif (array[x+1][y+1] == 1 && array[x+2][y+2] == 1) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\tpublic static boolean checkRightUp(int x, int y){\n\t\tif (array[x-1][y+1] == 1 && array[x-2][y+2] == 1) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\tpublic static boolean checkCenterRight(int x, int y){\n\t\tif (array[x+1][y+1] == 1 && array[x-1][y-1] == 1) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\tpublic static boolean checkCenterLeft(int x, int y){\n\t\tif (array[x-1][y+1] == 1 && array[x+1][y-1] == 1) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\tpublic static boolean checkCenterLeftRight(int x, int y){\n\t\tif (array[x][y-1] == 1 && array[x][y+1] == 1) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\tpublic static boolean checkCenterUpDown(int x, int y){\n\t\tif (array[x-1][y] == 1 && array[x+1][y] == 1) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3528436aa49dcc21c04cf420d3b82c98", "src_uid": "ca4a77fe9718b8bd0b3cc3d956e22917", "difficulty": 1100.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class TaskD implements Runnable {\n\t\n\tchar str[];\n\tint most, n;\n\tfinal int MOD = 1000000003, MUL = 37;\n\tint hash[], rhash[];\n\tlong power[];\n\t\n\tprivate long key(int l, int r)\n\t{\n\t\tlong ret = (hash[r + 1] - hash[l] * power[r - l + 1]) % MOD;\n\t\tif (ret < 0) ret += MOD;\n\t\treturn ret;\n\t}\n\t\n\tprivate long rkey(int l, int r)\n\t{\n\t\tlong ret = (rhash[r + 1] - rhash[l]) % MOD;\n\t\tif (ret < 0) ret += MOD;\n\t\treturn ret;\n\t}\n\t\n\tprivate boolean par(int l, int r)\n\t{\n\t\tif (l < 0) return false;\n\t\t\n\t\tint mid = (l + r) >> 1, len = r - l + 1;\n\t\tif (len % 2 == 1)\n\t\t\treturn key(l, mid) * power[mid] % MOD == rkey(mid, r);\n\t\treturn key(l, mid) * power[mid+1] % MOD== rkey(mid+1, r);\n\t}\n\n private void solve() throws IOException {\n \tmost = nextInt();\n \tString s = nextToken();\n \tstr = s.toCharArray();\n \tn = s.length();\n \t\n \thash = new int[n + 1];\n \trhash = new int[n + 1];\n \tpower = new long[n + 1];\n \t\n \thash[0] = 0;\n \trhash[0] = 0;\n \tpower[0] = 1;\n \tfor (int i = 1; i <= n; ++i)\n \t\tpower[i] = power[i-1] * MUL % MOD;\n \t\n \tint where = n;\n \tfor (int i = 0; i < n; ++i)\n \t{\n \t\thash[i+1] = (int)((hash[i] * (long)MUL + (str[i] - 'a')) % MOD);\n \t\trhash[i+1] = (int)((rhash[i] + power[i] * (str[i] - 'a')) % MOD);\n\n \t\tif (par(i - most + 1, i) || par(i - most, i))\n \t\t{\n \t\t\twhere = i;\n \t\t\tbreak;\n \t\t}\n \t}\n \t\n \twhile (where >= 0)\n \t{\n \t\tboolean ok = false;\n \t\tfor (char i = (char) (str[where] + 1); !ok && i <= 'z'; ++i)\n \t\t{ \t\t\t\n \t\t\thash[where+1] = (int)((hash[where] * (long)MUL + (i - 'a')) % MOD);\n \t\trhash[where+1] = (int)((rhash[where] + power[where] * (i - 'a')) % MOD);\n \t\t\tstr[where] = i;\n \t\t\t\n \t\t\tok = true;\n \t\tif (par(where - most + 1, where) || par(where - most, where))\n \t\t\tok = false;\n \t\t}\n \t\t\n \t\tif (ok) break;\n \t\t--where;\n \t}\n \t\n \tif (where < 0)\n \t{\n \t\twriter.println(\"Impossible\");\n \t\treturn;\n \t}\n \t\n \tfor (int p = where+1; p < n; ++p)\n \t{\n \t\tfor (char i = 'a'; i <= 'z'; ++i)\n \t\t{\n \t\t\thash[p+1] = (int)((hash[p] * (long)MUL + (i - 'a')) % MOD);\n \t\trhash[p+1] = (int)((rhash[p] + power[p] * (i - 'a')) % MOD);\n \t\t\tstr[p] = i;\n \t\t\t\n \t\tif (!par(p - most + 1, p) && !par(p - most, p))\n \t\t\tbreak;\n \t\t}\n \t}\n \t\n \twriter.println(String.valueOf(str));\n }\n\n public static void main(String[] args) {\n new TaskD().run();\n }\n\n BufferedReader reader;\n StringTokenizer tokenizer;\n PrintWriter writer;\n\n public void run() {\n try {\n reader = new BufferedReader(new InputStreamReader(System.in));\n tokenizer = null;\n writer = new PrintWriter(System.out);\n solve();\n reader.close();\n writer.close();\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(1);\n }\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n String nextToken() throws IOException {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(reader.readLine());\n }\n return tokenizer.nextToken();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7fc23788b476ce9e1213cd3470ec5131", "src_uid": "959a274a06219f4a8c061cd6f5b17160", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.Scanner;\nimport java.util.regex.Matcher;\nimport java.util.regex.Pattern;\n\npublic class CanadaC {\n public static ArrayList singleChar = new ArrayList();\n public static int n;\n public static int m;\n public static void main(String[] args){\n initializeSingleChar();\n Scanner scanner = new Scanner(System.in);\n\n String input = scanner.nextLine();\n int[] poses = findPair(input);\n int LENGTH = 13;\n int pos1 = poses[0];\n int pos2 = poses[1];\n if (pos1 == -1 && pos2 == -1) {\n System.out.println (\"Impossible\");\n return;\n }\n int midRange = 0;\n if ((pos2-pos1) % 2 == 1) midRange = (pos2 - pos1)/2 + 1;\n else midRange = (pos2 -pos1)/2;\n\n char[] row1 = new char [13];\n char[] row2 = new char[13];\n\n /*\n * Contruct characters between pair\n */\n row1[LENGTH-midRange] = input.charAt(pos1);\n int count = 1;\n int c = pos1 + count;\n for (int i = LENGTH-midRange + 1 ; i < LENGTH ; i++){\n row1[i] = input.charAt(c);\n count++;\n c++;\n }\n int p = LENGTH -1;\n while (c < pos2){\n row2[p] = input.charAt(c);\n c++;\n p--;\n }\n int temp = pos2 + 1;\n int temp2 = LENGTH - midRange -1 ;\n while (temp < input.length() && temp2 >= 0){\n row1[temp2] = input.charAt(temp);\n temp++;\n temp2--;\n }\n if (temp == input.length()){ //END OF INPUT\n int tt = 0;\n while (temp2 >= 0 ){\n row1[temp2] = input.charAt(tt);\n tt++;\n }\n int ttt = 0 ;\n while (tt < pos1){\n row2[ttt] = input.charAt(tt);\n ttt++;\n tt++;\n }\n }else if (temp2 < 0 ){\n int t = 0;\n while (temp < input.length()){\n row2[t] = input.charAt(temp);\n temp++;\n t++;\n }\n int tt = 0;\n for (tt = 0 ; tt < pos1; tt++){\n row2[t] = input.charAt(tt);\n t++;\n }\n }\n for (int i = 0 ; i < LENGTH ; i++){\n System.out.print(row1[i]);\n }\n System.out.println();\n for (int i = 0 ; i < LENGTH ; i++){\n System.out.print(row2[i]);\n }\n System.out.println();\n }\n public static void initializeSingleChar() {\n singleChar.add(\"A\");singleChar.add(\"B\");singleChar.add(\"C\");singleChar.add(\"D\");singleChar.add(\"E\");singleChar.add(\"F\");\n singleChar.add(\"G\");singleChar.add(\"H\");singleChar.add(\"I\");singleChar.add(\"J\");singleChar.add(\"K\");singleChar.add(\"L\");\n singleChar.add(\"M\");singleChar.add(\"N\");singleChar.add(\"O\");singleChar.add(\"P\");singleChar.add(\"Q\");singleChar.add(\"R\");\n singleChar.add(\"S\");singleChar.add(\"T\");singleChar.add(\"U\");singleChar.add(\"V\");singleChar.add(\"W\");singleChar.add(\"X\");\n singleChar.add(\"Y\");singleChar.add(\"Z\");\n }\n public static int[] findPair(String str) {\n int[] output = new int[2];\n for (String c : singleChar) {\n String regex = c + \"[A-Z]+\" + c;\n if (isMatches(str, regex)) {\n output[0] = str.indexOf(c);\n output[1] = output[0] + 2 + str.substring(output[0] + 2).indexOf(c);\n return output;\n }\n }\n output[0] = -1;\n output[1] = -1;\n return output;\n\n }\n public static boolean isMatches(String text, String regex) {\n Pattern pattern = Pattern.compile(regex);\n Matcher matcher = pattern.matcher(text);\n // Check all occurrences\n if (matcher.find()) {\n return true;\n }\n return false;\n }\n\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2231f03a211d96da53a86e27bf881f49", "src_uid": "56c5ea443dec7a732802b16aed5b934d", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "public class Main{\n \n public static void main(String[] args){\n Scanner in = new Scanner(System.in);\n \n int l1 = in.nextInt();\n int r1 = in.nextInt();\n int l2 = in.nextInt();\n int r2 = in.nextInt();\n int k = in.nextInt();\n \n int time = Math.min(r1, r2) - Math.max(l1, l2) + 1;\n \n if( k <= Math.min(r1, r2) && k >= Math.max(l1, l2)){\n time--;\n }\n \n System.out.println( Math.max(0,time));\n \n \n \n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "49447f41249b1a187ca176367412136a", "src_uid": "9a74b3b0e9f3a351f2136842e9565a82", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n \npublic class Solution{\n public static void main(String[] args){\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n int n = Integer.parseInt(in.readLine());\n String[] arr = in.readLine().trim().split(\" \");\n Set s = new HashSet();\n \n for(int i = 0 ; i < n ; i++){\n s.add(Integer.parseInt(arr[i]));\n }\n ArrayList x = new ArrayList(s);\n ArrayList> res = new ArrayList>();\n for(int i = 0 ; i< x.size(); i++){\n int t = x.get(i);\n int m = res.size(),j=0;\n for(j = 0 ; j < m ; j++){\n PriorityQueue temp = res.get(j);\n if(gcd(temp.get(0),t)!=1) {\n temp.add(t);\n break;\n }\n }\n if(j == m){\n res.add(new PriorityQueue());\n res.get(res.size()-1).add(t);\n }\n \n }\n System.out.println(res.size());\n }\n public static int gcd(int a, int b){\n if(a==0) return b;\n if(b==0) return a;\n return gcd(b, a%b);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "084277470bdc39d8c2d5841546bd2d90", "src_uid": "63d9b7416aa96129c57d20ec6145e0cd", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.*;\n\nimport java.math.BigInteger;\nimport java.text.DecimalFormat;\nimport java.text.SimpleDateFormat;\nimport java.util.*;\n\npublic class main2 {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\tString s=\"ACTG\";\n int x = 2 + 2;\n\t\tString in=sc.next();\n boolean pl = false;\n\t\tint min=Integer.MAX_VALUE;\n\t\tfor(int i=0;i<(in.length()-3);i++)\n\t\t{\n\t\t\tint cost=0;\n if(cost)\n pl =true;\n\t\t\tfor(int j=i;j<(i+4);j++)\n\t\t\t{\n\t\t\t\tif(s.charAt(j-i)==in.charAt(j))\n\t\t\t\t{}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tcost+=Integer.min(Math.abs(s.charAt(j-i)-in.charAt(j)),26-Integer.max(s.charAt(j-i), in.charAt(j))+Integer.min(s.charAt(j-i),in.charAt(j)));\n\t\t\t\t}\n\t\t\t//\tSystem.out.println((s.charAt(j)+\"\"+in.charAt(j)+\" \"+(26-Integer.max(s.charAt(i), in.charAt(j))+Integer.min(s.charAt(i),in.charAt(j)))));\n\t\t\t}\n\t\t\tif(cost Integer.parseInt(cards[1].substring(0,1))) System.out.println(\"YES\");\n else System.out.println(\"NO\");\n }\n else if(cards[0].substring(1,2).equals(trump)) {\n System.out.println(\"YES\");\n }\n else {\n System.out.println(\"NO\");\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e57695dc0fdbd53c1f27faa152433b2f", "src_uid": "da13bd5a335c7f81c5a963b030655c26", "difficulty": 1000.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class program {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int n=scan.nextInt();\n int result[]=new int[n];\n result[0]=1;\n int mod=1000000+3;\n for (int i = 1; i < n; i++) {\n result[i]=3*result[i-1]%mod;\n }\n System.out.println(result[n-1]);\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b076896079b50169e7d0e28e6256b3f3", "src_uid": "1a335a9638523ca0315282a67e18eec7", "difficulty": 1300.0} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class C0017 {\n\n public static void main(String args[]) throws Exception {\n new C0017();\n }\n\n final int MOD = 51123987;\n int[][] delta = new int[][] {\n {1, 0, 0},\n {0, 1, 0},\n {0, 0, 1}\n };\n\n C0017() throws Exception {\n PandaScanner sc = null;\n PrintWriter out = null;\n try {\n sc = new PandaScanner(System.in);\n out = new PrintWriter(System.out);\n } catch (Exception ignored) {\n }\n\n int n = sc.nextInt();\n String s = sc.next();\n char[] c = s.toCharArray();\n\n int max = (n + 2) / 3 + 1;\n long dp[][][][] = new long[n][max + 1][max + 1][max + 1];\n dp[c[0] - 'a'][0][0][0] = 1;\n\n for (int z = 0; z < c.length; z++) {\n for (int i = 0; i < max; i++) {\n for (int j = 0; j < max; j++) {\n for (int k = 0; k < max; k++) {\n if (dp[z][i][j][k] == 0) {\n continue;\n }\n for (int a = 0; a < 3; a++) {\n int next = s.indexOf((char) (a + 'a'), z);\n if (next == -1) {\n continue;\n }\n int[] d = delta[a];\n dp[next][i + d[0]][j + d[1]][k + d[2]] += dp[z][i][j][k];\n dp[next][i + d[0]][j + d[1]][k + d[2]] %= MOD;\n }\n }\n }\n }\n }\n\n long res = 0;\n for (int x = 0; x < n; x++) {\n for (int i = max - 2; i < max; i++) {\n for (int j = max - 2; j < max; j++) {\n for (int k = max - 2; k < max; k++) {\n if (i + j + k != n) {\n continue;\n }\n// out.println(x + \" \" + i + \" \" + j + \" \" + k + \" \" + dp[x][i][j][k]);\n res += dp[x][i][j][k];\n res %= MOD;\n }\n }\n }\n }\n out.println(res);\n\n out.close();\n System.exit(0);\n }\n\n\n //The PandaScanner class, for Panda fast scanning!\n public class PandaScanner {\n BufferedReader br;\n StringTokenizer st;\n InputStream in;\n\n PandaScanner(InputStream in) throws Exception {\n br = new BufferedReader(new InputStreamReader(this.in = in));\n }\n\n public String next() throws Exception {\n if (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(br.readLine().trim());\n return next();\n }\n return st.nextToken();\n }\n\n public boolean hasNext() throws Exception {\n return (st != null && st.hasMoreTokens()) || in.available() > 0;\n }\n\n public long nextLong() throws Exception {\n return Long.parseLong(next());\n }\n\n public int nextInt() throws Exception {\n return Integer.parseInt(next());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "db875b25c3cb7c63d40f9aea7be2ec60", "src_uid": "64fada10630906e052ff05f2afbf337e", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Chocolate {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n Scanner s=new Scanner(System.in);\n int n=s.nextInt();\n int[] arr=new int[n];\n \n for(int i=0;i 1 ? p-k : 1;\n int end = p + k > n ? n : p+k;\n\n if(start > 1) sb.append(\"<< \");\n for(int i = start; i <= end; i++)\n sb.append(i == p ? \"(\" + i + \")\" : i).append(\" \");\n if(end < n) sb.append(\">>\");\n \n return sb.toString();\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "dc32f021d594a8f79b07f3160fdfe0cc", "src_uid": "526e2cce272e42a3220e33149b1c9c84", "difficulty": null} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class HocJava {\n \n \n public static void main(String[] args) {\n Scanner sc=new Scanner(System.in);\n long n,mod=1000000007;\n n=sc.nextLong();\n long res=0;\n long[][] c=new long[4050][4050];\n long[] dp=new long[4050];\n for(int i=0;i<=4000;i++){\n c[i][0]=1;\n }\n for(int i=1;i<=4000;i++){\n for(int j=1;j<=i;j++){\n c[i][j]=(c[i-1][j-1]+c[i][j-1])%mod;\n }\n }\n dp[0]=1;\n for(int i=1;i=1;i--)\n {\n long te = i*i;\n long num = n;\n int count =0;\n String s = String.valueOf(num);\n for(int j=s.length()-1;j>=0;j--){\n long t = te%10;\n if(s.charAt(j)-'0'==t){\n count++;\n te = te/10;\n }\n }\n if(count==String.valueOf(i*i).length()){\n System.out.println(String.valueOf(n).length()-count);\n/*\n System.out.println(i);\n*/\n return;\n }\n }\n System.out.println(-1);\n }\n\n public static void main(String[] args) {\n C962 solver = new C962();\n solver.solve();\n }\n\n class Scan {\n BufferedReader br;\n StringTokenizer st;\n\n public Scan() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "854df7c5c93b574960776c8386394c47", "src_uid": "fa4b1de79708329bb85437e1413e13df", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.util.Collection;\nimport java.util.InputMismatchException;\nimport java.util.HashMap;\nimport java.io.IOException;\nimport java.io.FileInputStream;\nimport java.util.ArrayList;\nimport java.util.Objects;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.Queue;\nimport java.util.LinkedList;\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 DChocolate solver = new DChocolate();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class DChocolate {\n private HashMap> hm = new HashMap<>();\n private HashMap> hm2 = new HashMap<>();\n long minDis = Integer.MAX_VALUE;\n private Util.Pair pair1;\n private Util.Pair pair2;\n\n private void bfs(long x, long y) {\n long area = x * y;\n hm.put(area, new Util.Triplet<>(0L, x, y));\n Queue> queue = new LinkedList<>();\n queue.offer(new Util.Pair<>(x, y));\n while (!queue.isEmpty()) {\n Util.Pair P = queue.poll();\n long area1;\n long distance = hm.get(P.x * P.y).x;\n if (P.x % 2 == 0) {\n area1 = P.y * P.x / 2;\n queue.offer(new Util.Pair<>((P.x) / 2, P.y));\n if (hm.containsKey(area1)) {\n long dis = hm.get(area1).x;\n if (distance + 1 < dis) {\n hm.put(area1, new Util.Triplet<>(distance + 1, P.x / 2, P.y));\n }\n } else hm.put(area1, new Util.Triplet<>(distance + 1, P.x / 2, P.y));\n }\n if (P.y % 2 == 0) {\n area1 = P.x * P.y / 2;\n queue.offer(new Util.Pair<>(P.x, P.y / 2));\n if (hm.containsKey(area1)) {\n long dis = hm.get(area1).x;\n if (distance + 1 < dis) {\n hm.put(area1, new Util.Triplet<>(distance + 1, P.x, P.y / 2));\n }\n } else hm.put(area1, new Util.Triplet<>(distance + 1, P.x, P.y / 2));\n }\n if (P.x % 3 == 0) {\n area1 = 2 * P.y * P.x / 3;\n queue.offer(new Util.Pair<>(2 * (P.x) / 3, P.y));\n if (hm.containsKey(area1)) {\n long dis = hm.get(area1).x;\n if (distance + 1 < dis) {\n hm.put(area1, new Util.Triplet<>(distance + 1, 2 * P.x / 3, P.y));\n }\n } else hm.put(area1, new Util.Triplet<>(distance + 1, 2 * P.x / 3, P.y));\n }\n if (P.y % 3 == 0) {\n area1 = 2 * P.x * P.y / 3;\n queue.offer(new Util.Pair<>(P.x, 2 * P.y / 3));\n if (hm.containsKey(area1)) {\n long dis = hm.get(area1).x;\n if (distance + 1 < dis) {\n hm.put(area1, new Util.Triplet<>(distance + 1, P.x, 2 * P.y / 3));\n }\n } else hm.put(area1, new Util.Triplet<>(distance + 1, P.x, 2 * P.y / 3));\n }\n }\n }\n\n private void bfs2(long x, long y) {\n long area = x * y;\n hm2.put(area, new Util.Triplet<>(0L, x, y));\n if (hm.containsKey(area)) {\n if (minDis > hm.get(area).x + hm2.get(area).x) {\n minDis = hm.get(area).x + hm2.get(area).x;\n pair1 = new Util.Pair<>(hm.get(area).y, hm.get(area).z);\n pair2 = new Util.Pair<>(x, y);\n }\n }\n Queue> queue = new LinkedList<>();\n queue.offer(new Util.Pair<>(x, y));\n while (!queue.isEmpty()) {\n Util.Pair P = queue.poll();\n long area1;\n long distance = hm2.get(P.x * P.y).x;\n if (P.x % 2 == 0) {\n area1 = P.y * P.x / 2;\n queue.offer(new Util.Pair<>((P.x) >> 1, P.y));\n if (hm2.containsKey(area1)) {\n long dis = hm2.get(area1).x;\n if (distance + 1 < dis) {\n hm2.put(area1, new Util.Triplet<>(distance + 1, P.x / 2, P.y));\n }\n } else hm2.put(area1, new Util.Triplet<>(distance + 1, P.x / 2, P.y));\n if (hm.containsKey(area1)) {\n if (minDis > hm.get(area1).x + hm2.get(area1).x) {\n minDis = hm.get(area1).x + hm2.get(area1).x;\n pair1 = new Util.Pair<>(hm.get(area1).y, hm.get(area1).z);\n pair2 = new Util.Pair<>(P.x / 2, P.y);\n }\n }\n\n }\n if (P.y % 2 == 0) {\n area1 = P.x * P.y / 2;\n queue.offer(new Util.Pair<>(P.x, P.y / 2));\n if (hm2.containsKey(area1)) {\n long dis = hm2.get(area1).x;\n if (distance + 1 < dis) {\n hm2.put(area1, new Util.Triplet<>(distance + 1, P.x, P.y / 2));\n }\n } else hm2.put(area1, new Util.Triplet<>(distance + 1, P.x, P.y / 2));\n if (hm.containsKey(area1)) {\n if (minDis > hm.get(area1).x + hm2.get(area1).x) {\n minDis = hm.get(area1).x + hm2.get(area1).x;\n pair1 = new Util.Pair<>(hm.get(area1).y, hm.get(area1).z);\n pair2 = new Util.Pair<>(P.x, P.y / 2);\n }\n }\n }\n if (P.x % 3 == 0) {\n area1 = 2 * P.y * P.x / 3;\n queue.offer(new Util.Pair<>(2 * (P.x) / 3, P.y));\n if (hm2.containsKey(area1)) {\n long dis = hm2.get(area1).x;\n if (distance + 1 < dis) {\n hm2.put(area1, new Util.Triplet<>(distance + 1, 2 * P.x / 3, P.y));\n }\n } else hm2.put(area1, new Util.Triplet<>(distance + 1, 2 * P.x / 3, P.y));\n if (hm.containsKey(area1)) {\n if (minDis > hm.get(area1).x + hm2.get(area1).x) {\n minDis = hm.get(area1).x + hm2.get(area1).x;\n pair1 = new Util.Pair<>(hm.get(area1).y, hm.get(area1).z);\n pair2 = new Util.Pair<>(2 * P.x / 3, P.y);\n }\n }\n }\n if (P.y % 3 == 0) {\n area1 = 2 * P.x * P.y / 3;\n queue.offer(new Util.Pair<>(P.x, 2 * P.y / 3));\n if (hm2.containsKey(area1)) {\n long dis = hm2.get(area1).x;\n if (distance + 1 < dis) {\n hm2.put(area1, new Util.Triplet<>(distance + 1, P.x, 2 * P.y / 3));\n }\n } else hm2.put(area1, new Util.Triplet<>(distance + 1, P.x, 2 * P.y / 3));\n if (hm.containsKey(area1)) {\n if (minDis > hm.get(area1).x + hm2.get(area1).x) {\n minDis = hm.get(area1).x + hm2.get(area1).x;\n pair1 = new Util.Pair<>(hm.get(area1).y, hm.get(area1).z);\n pair2 = new Util.Pair<>(P.x, 2 * P.y / 3);\n }\n }\n }\n }\n }\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n long a1 = in.nextLong(), b1 = in.nextLong();\n long a2 = in.nextLong(), b2 = in.nextLong();\n bfs(a1, b1);\n bfs2(a2, b2);\n// out.println(hm.toString());\n// out.println(hm2.toString());\n if (minDis == Integer.MAX_VALUE) out.println(-1);\n else {\n out.println(minDis);\n out.printsc(pair1.x, pair1.y);\n out.println();\n out.printsc(pair2.x, pair2.y);\n out.println();\n }\n\n\n out.flush();\n }\n\n }\n\n static class Util {\n public static class Pair {\n public T x;\n public T y;\n\n public Pair(T x, T y) {\n this.x = x;\n this.y = y;\n }\n\n public boolean equals(Object obj) {\n if (!(obj instanceof Util.Pair)) return false;\n Util.Pair pair = (Util.Pair) obj;\n return this.x.equals(pair.x) && this.y.equals(pair.y);\n }\n\n public String toString() {\n return (\"(\" + this.x + \",\" + this.y + \")\");\n }\n\n public int hashCode() {\n return Objects.hash(x, y);\n }\n\n }\n\n public static class Triplet {\n public T x;\n public T y;\n public T z;\n\n public Triplet(T x, T y, T z) {\n this.x = x;\n this.y = y;\n this.z = z;\n }\n\n public boolean equals(Object obj) {\n if (!(obj instanceof Util.Triplet)) return false;\n Util.Triplet triplet = (Util.Triplet) obj;\n return this.x.equals(triplet.x) && this.y.equals(triplet.y) && this.z.equals(triplet.z);\n }\n\n public String toString() {\n return (\"(\" + this.x + \",\" + this.y + \",\" + this.z + \")\");\n }\n\n public int hashCode() {\n return Objects.hash(x, y, z);\n }\n\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[8192];\n private int curChar;\n private int numChars;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public InputReader(FileInputStream file) {\n this.stream = file;\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 = (res << 3) + (res << 1) + c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n private boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n private ArrayList res = new ArrayList<>();\n private StringBuilder sb = new StringBuilder(\"\");\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 println(Object... objects) {\n for (int i = 0; i < objects.length; i++) {\n sb.append(objects[i]);\n }\n res.add(sb.toString());\n sb = new StringBuilder(\"\");\n }\n\n public void printsc(Object... objects) {\n for (int i = 0; i < objects.length; i++) {\n sb.append(objects[i]).append(' ');\n }\n }\n\n public void close() {\n writer.close();\n }\n\n public void flush() {\n for (String str : res) writer.printf(\"%s\\n\", str);\n res.clear();\n sb = new StringBuilder(\"\");\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8068914c654b62f1a6818d299a9a1c40", "src_uid": "4fcd8c4955a47661462c326cbb3429bd", "difficulty": 1900.0} {"lang": "Java 7", "source_code": "/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n\n/**\n *cf244b_uln\n * @author zulkan\n */\nimport java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport static java.lang.System.*;\nimport java.math.BigInteger;\nimport java.util.List;\nimport java.util.ArrayList;\nimport java.util.Scanner;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.HashSet;\n\npublic class cf244b_uln {\n\n static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n static Scanner sc = new Scanner(System.in);\n\n public static String getString() {\n try {\n return br.readLine();\n } catch (Exception e) {\n }\n return \"\";\n }\n\n public static Integer getInt() {\n try {\n return Integer.parseInt(br.readLine());\n } catch (Exception e) {\n }\n return 0;\n }\n\n public static Integer[] getIntArr() {\n try {\n StringTokenizer temp = new StringTokenizer(br.readLine());\n int n = temp.countTokens();\n Integer temp2[] = new Integer[n];\n for (int i = 0; i < n; i++) {\n temp2[i] = Integer.parseInt(temp.nextToken());\n }\n return temp2;\n } catch (Exception e) {\n }\n return null;\n }\n\n public static int getMax(Integer[] ar) {\n int t = ar[0];\n for (int i = 0; i < ar.length; i++) {\n if (ar[i] > t) {\n t = ar[i];\n }\n }\n return t;\n }\n\n public static void print(Object a) {\n out.println(a);\n }\n\n public static int nextInt() {\n return sc.nextInt();\n }\n\n public static double nextDouble() {\n return sc.nextDouble();\n }\n\n public static BigInteger getFact(long in) {\n BigInteger ot = new BigInteger(\"1\");\n for (Integer i = 1; i <= in; i++) {\n ot = ot.multiply(new BigInteger(i.toString()));\n }\n return ot;\n }\n\n public static String gbase(int a, int base) {\n StringBuilder out = new StringBuilder();\n int temp = a;\n while (temp > 0) {\n //out = temp % base + out;\n out.insert(0, temp % base);\n temp /= base;\n }\n return out.toString();\n }\n\n public static void main(String[] ar) {\n\n\n\n int n = getInt();\n int out = 0;\n \n if(n <= 100){\n print(n);\n return;\n }\n\n boolean all[] = new boolean[n + 1];\n \n \n for (int i = 0; i < 10; i++) {\n for (int j = i; j < 10; j++) {\n if (i != 0 || j != 0) {\n ArrayList last = new ArrayList();\n last.add(i);\n last.add(j);\n all[i] = true;\n all[j] = true;\n\n int ls = j;\n while (ls < n) {\n ArrayList last2 = new ArrayList();\n for (int ii = 0; ii < last.size(); ii++) {\n int a = last.get(ii) * 10 + i;\n int b = last.get(ii) * 10 + j;\n last2.add(a);\n last2.add(b);\n //print(a + \" \" + b);\n if (b <= n) {\n\n all[b] = true;\n }\n if (a <= n) {\n all[a] = true;\n }\n ls = b;\n }\n // print(ls + \" \" + last2);\n last = last2;\n\n }\n\n }\n }\n }\n for (int i = 1; i <= n; i++) {\n //print(i + \" \" + all[i]);\n if (all[i]) {\n out++;\n }\n }\n print(out);\n\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e1a51b49ae53ff986605fea631939502", "src_uid": "0f7f10557602c8c2f2eb80762709ffc4", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "\nimport java.util.ArrayList;\nimport java.util.Scanner;\n\n\npublic class A {\n \n \n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n \n \n String s = in.next();\n \n \n String[] aa ={\"vaporeon\", \"jolteon\", \"flareon\", \"espeon\", \"umbreon\", \"leafeon\", \"glaceon\", \"sylveon\"};\n ArrayList al = new ArrayList<>();\n ArrayList al2 = new ArrayList<>();\n for (int i = 0; i < n; i++) {\n \n if (s.length() == aa[i].length()) {\n al.add(aa[i]);\n al2.add(aa[i]);\n }\n }\n \n for (int i = 0; i < al.size(); i++) {\n for (int j = 0; j < s.length(); j++) {\n \n if(s.charAt(j) != '.' && s.charAt(j)!= al.get(i).charAt(j)){\n \n al2.remove(al.get(i));\n \n }\n }\n }\n \n System.out.println(al2.get(0));\n \n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7f481041c851c1e997f0269c557a3429", "src_uid": "ec3d15ff198d1e4ab9fd04dd3b12e6c0", "difficulty": 1000.0} {"lang": "Java 6", "source_code": "public class Main {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int a = sc.nextInt();\n //sc.nextLine();\n int b = sc.nextInt();\n sc.nextLine();\n int c = a / b;\n int[] arr = new int[a];\n int count = 0;\n for (int i = 0; i < a; i++) {\n arr[i] = sc.nextInt();\n }\n for (int t = 0; t < b; t++) {\n int count1 = 0;\n int count2 = 0;\n int[] arrtemp = new int[c];\n for (int j = 0; j < c; j++) {\n arrtemp[j] = arr[j + c * t];\n \n if (arrtemp[j] == 1) {\n count1++;\n } else {\n count2++;\n }\n }\n System.out.println(\"\");\n if (count1 != 0 || count2 != 0) {\n count += count1 > count2 ? count1 - count2 : count2 - count1;\n }\n }\n\n\n System.out.println(count);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3f9a27197c58e6f28926a695ce0bae57", "src_uid": "5f94c2ecf1cf8fdbb6117cab801ed281", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Solution{\n public static void main(String args[])\n {\n int size = 0,ans = 0;\n Scanner sc = new Scanner(System.in);\n size = sc.nextInt();\n String num = sc.next();\n int ones = 0,zeroes = 0;\n for(int i=0;i 0){\n\t\t\tif(b % 2 == 0){\n\t\t\t\ta = (a * a) % MOD;\n\t\t\t\tb /= 2;\n\t\t\t}else{\n\t\t\t\tres = (res * a) % MOD;\n\t\t\t\tb--;\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn res % MOD;\n\t\t\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tFastReader sc = new FastReader(System.in); \n\t\t\n\t\t//System.out.println(fastPower(2, 4));\n\t\t\n\t\tlong year = sc.nextL();\n\t\t\n\t\tSystem.out.println((((fastPower(2, year) + fastPower(4, year)) % MOD) / 2) % MOD);\n\t\t\t\n }\n\n}\n\t\t\n\t\t\t\t\n\n\nclass FastReader {\n\tpublic BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public FastReader(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() throws IOException{\n return Integer.parseInt(next());\n }\n public long nextL() throws IOException{\n return Long.parseLong(next());\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ce40968f82abda79423b7f5ac0ce1c68", "src_uid": "782b819eb0bfc86d6f96f15ac09d5085", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.io.BufferedOutputStream;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class Main {\n static int inf = 1000000000;\n static int mod = (int) 10e9 + 7;\n\n static long gcd(long a, long b) {\n return (a == 0) ? b : gcd(b % a, a);\n }\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n \n int n = in.nextInt();\n\n int privous = in.nextInt();\n\n int sum = 0;\n\n for (int i = 1; i < n; i++) {\n int current = in.nextInt();\n\n if (privous == 1){\n if (current == 2){\n sum+=3;\n } else {\n sum+=4;\n }\n } else if (privous == 2){\n if (current == 1){\n sum += 3;\n } else {\n sum = -1;\n break;\n }\n } else {\n if (current == 1){\n sum += 4;\n } else {\n sum = -1;\n break;\n }\n }\n\n privous = current;\n\n }\n System.out.println(sum == -1?\"Infinite\":\"Finite\\n\" + sum);\n out.close();\n }\n\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f0acb59b11143732413fa5d902babc5b", "src_uid": "6c8f028f655cc77b05ed89a668273702", "difficulty": 1400.0} {"lang": "Java 11", "source_code": "[7:31 PM, 9/7/2020] College: 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.HashSet;\nimport java.util.StringTokenizer;\n\npublic class Main {\t\n\t\n\tstatic class ProblemSolver{\n\t\tpublic void solveTheProblem(InputReader in,PrintWriter out){\n\t\t\t//Take the necessary inputs\n\t\t\tint r=in.nextInt(),c=in.nextInt();\n\t\t\t\n\t\t\t//To keep track of number of rows and column containing strawberries\n\t\t\tHashSet rows,cols;\n\t\t\trows=new HashSet();\n\t\t\tcols=new HashSet();\n\t\t\t\n\t\t\t/*\n\t\t\t * Calculation to keep track of the nubmer of rows \n\t\t\t * and columns containing strawberries\n\t\t\t */\n\t\t\tfor(int i=0;i dels = new HashMap<>();\n int del = 2;\n if(n == 1) {\n println(\"1 0\");\n return;\n }\n while(n > 1) {\n if(n % del == 0) {\n if(dels.containsKey(del)) {\n dels.put(del, dels.get(del) + 1);\n } else {\n dels.put(del, 1);\n }\n n /= del;\n //println(\"here2\");\n } else\n del++;\n //println(\"here1\");\n }\n int minNum = 1;\n long two = 1;\n int b = 0;\n HashSet set = new HashSet<>();\n for(int i : dels.keySet()) {\n minNum *= i;\n while(two < dels.get(i)) {\n two *= 2;\n }\n set.add(two);\n if(dels.get(i) != two)\n b = 1;\n }\n //println(two);\n int ans = 0;\n while(two > 1) {\n two /= 2;\n ans++;\n }\n int add = 1;\n if(b == 0 || set.size() > 1) add = 0;\n println(minNum + \" \" + (ans + add));\n\n } catch (IOException e) {\n }\n }\n\n static String reverse(String s) {\n String ans = \"\";\n char[] c = s.toCharArray();\n for(int i = s.length() - 1; i >= 0; i--) {\n ans += c[i];\n }\n return ans;\n }\n\n static long fac(int deg) {\n long ans = 1;\n for(int i = 2; i <= deg; i++) {\n ans *= i;\n }\n return ans;\n }\n\n static int r(int a, int b) {\n int ans = a / b;\n if(a % b != 0)\n ans++;\n return ans;\n }\n\n static void print(Object o) {\n System.out.print(o.toString());\n }\n\n static void println(Object o) {\n System.out.println(o.toString());\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ff8cb213bbc112dca71ee346b2474eef", "src_uid": "212cda3d9d611cd45332bb10b80f0b56", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class lcm{\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n long store = 0;\n if(n == 1){\n store = 1;\n }else if(n == 2){\n store = 2\n }\n if(n%2 == 0){\n long = Math.max((n-1)*(n-2)*(n-3),n*(n-1)*(n-2));\n }else{\n long = n*(n-1)*(n-2)\n }\n System.out.println(long);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3fd032297fb1f536b9b4fb79c561e1b8", "src_uid": "25e5afcdf246ee35c9cef2fcbdd4566e", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\nimport CODEFORCES.Aa.Scanner;\nimport CODEFORCES.Cc.scanner;\n\npublic class contest {\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\tint n=sc.nextInt();\n\t\tint sum=0;int count=0;\n\t\tint i=0;\n\t\tfor( i=0;i=n)break;\n\t\t\t\n\t\t}\n\n\t\tSystem.out.println(sum= snumChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tsnumChars = System.in.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (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 String nextLine() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isEndOfLine(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic String nextString() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic int[] nextIntArray(int n) {\n\t\t\tint[] arr = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = nextInt();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tpublic long[] nextLongArray(int n) {\n\t\t\tlong[] arr = new long[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = nextLong();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tprivate boolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tprivate boolean isEndOfLine(int c) {\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t}\n\t}\n\n\t/************main*************/\n\tpublic static void main(String args[]) {\n\n\t\tFastReader scan = new FastReader();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t/*******************code***********************/\n\t\tint s=scan.nextInt();\n\t\tint x1=scan.nextInt();\n\t\tint x2=scan.nextInt();\n\t\tint t1=scan.nextInt();\n\t\tint t2=scan.nextInt();\n\t\tint p=scan.nextInt();\n\t\tint d=scan.nextInt();\n\t\tint tfromx1=0;\n\t\tint x1tox2=0;\n\t\tif(x1>p)\n\t\t{\n\t\t\tif(d==1)\n\t\t\t{\n\t\t\t\ttfromx1=x1-p;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\ttfromx1=p+x1;\n\t\t\t}\n\t\t}\n\t\tif(x1x1&&p>x2&&x1>x2))\n\t\t{\n\t\t\tx1tox2=Math.abs(x1-x2);\n\t\t}\n\t\telse if(p>x1&&p<=x2)\n\t\t{\n\t\t\tx1tox2=x1+x2;\n\t\t}\n\t\telse if(p>=x2&&px1&&p>x2&&x2>x1)\n\t\t{\n\t\t\tx1tox2=x1+x2;\n\t\t}\n\t\telse if(p==x1&&x1x2)\n\t\t{\n\t\t\tif(d==-1)\n\t\t\t{\n\t\t\t\tx1tox2=Math.abs(x1-x2);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tx1tox2=s-x1+s-x2;\n\t\t\t}\n\t\t}\n\t\tint temp=Math.min(tfromx1*t1+x1tox2*t1,Math.abs(x1-x2)*t2);\n\t\tout.println(temp);\n\t\tout.close();\n\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "31bcf0a34782742f3a1ca3b28cc35c22", "src_uid": "fb3aca6eba3a952e9d5736c5d8566821", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.StringTokenizer;\nimport java.util.StringJoiner;\nimport java.util.stream.IntStream;\n\nimport java.io.PrintWriter;\n//import java.util.Arrays;\n\npublic class A {\n \n\tpublic static FastScanner fs = new FastScanner();\n\tpublic static PrintWriter out = new PrintWriter(System.out);\n \n\tpublic static void main(String[] args) {\n\t\tsolve();\n\t}\n\t\n\tpublic static void solve(){\n\t\tint n = fs.nextInt(), k = fs.nextLong(), index = 1;\n\t\tString S = Long.toBinaryString(k);\n\t\tfor (int i = S.length()-1; i >= 0; i--){\n\t\t\tif (S.charAt(i) == '1'){\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tindex ++;\n\t\t}\n\t\tout.println(index);\n\t\tout.flush();\n\t}\n\t\t\n\tstatic void array_space(int[] A){\n\t\tStringJoiner sj = new StringJoiner(\" \");\n\t\tIntStream.of(A).forEach(x -> sj.add(String.valueOf(x)));\n\t\tSystem.out.println(sj.toString());\n\t}\n\t\n\tstatic 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; ic3 || b3c4 ) {\n \t\t if((FindPoint(b1,b2,b3,b4,a1,a2) && FindPoint(b1,b2,b3,b4,a3,a4) && FindPoint(b1,b2,b3,b4,a1,a4) && FindPoint(b1,b2,b3,b4,a3,a2))\n \t\t\t\t || (FindPoint(c1,c2,c3,c4,a1,a2) && FindPoint(c1,c2,c3,c4,a3,a4) && FindPoint(c1,c2,c3,c4,a1,a4) \n \t\t\t\t\t\t && FindPoint(c1,c2,c3,c4,a3,a2))){\n \t\t\t System.out.println(\"NO\");\n \t\t }\n \t\t else {\n \t\t System.out.println(\"YES\");\n\n \t\t }\n \t }\n \t else if((FindPoint(b1,b2,b3,b4,a1,a2) || FindPoint(c1,c2,c3,c4,a1,a2)) && (FindPoint(b1,b2,b3,b4,a3,a4) || FindPoint(c1,c2,c3,c4,a3,a4))\n \t\t\t\t && (FindPoint(b1,b2,b3,b4,a1,a4) || FindPoint(c1,c2,c3,c4,a1,a4)) && \n \t\t\t\t (FindPoint(b1,b2,b3,b4,a3,a2) || FindPoint(c1,c2,c3,c4,a3,a2))){\n \t\t System.out.println(\"NO\");\n \t }\n \t else {\n \t\t System.out.println(\"YES\");\n \t }\n \t \t\n \t \n }\n static boolean FindPoint(int x1, int y1, int x2, \n int y2, int x, int y) \n\t\t{ \n\t\tif (x > x1 && x < x2 && \n\t\ty > y1 && y < y2) \n\t\treturn true; \n\t\t\n\t\treturn false; \n\t\t} \n static int gcd(long a, long a2) \n { \n if (a == 0) \n return (int) a2; \n return gcd(a2 % a, a); \n } \n\t\t \n\n }\n \n \n\n \n \n \t\n \n static class InputReader\n {\n BufferedReader br;\n StringTokenizer st;\n \n public InputReader()\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 sort(Node[] a, int low, int high) \n {\n int N = high - low; \n if (N <= 1) \n return; \n int mid = low + N/2; \n // recursively sort \n sort(a, low, mid); \n sort(a, mid, high); \n // merge two sorted subarrays\n Node[] temp = new Node[N];\n int i = low, j = mid;\n \n for (int k = 0; k < N; k++) \n {\n if (i == mid) \n temp[k] = a[j++];\n else if (j == high) \n temp[k] = a[i++];\n else if (a[j].data=n)\n break;\n }\n System.out.println(i+1);\n }\n }\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "be318bd3af34e609b227c0a99c5f6f7e", "src_uid": "007a779d966e2e9219789d6d9da7002c", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "\n\n\n\nimport java.util.Scanner;\n\n\npublic class main {\n\n public static void main(String[] args)\n {\n try\n\t\t{\n \n Scanner s =new Scanner(System.in);\n long n = s.nextLong();\n long ways=0;\n long basic=2;\n if((n-2)%3==0) \n ways++;\n \n for(int i=1;i=0 && (n-basic)%3==0)\n ways++;\n }\n }\n System.out.println(\" answer \"+ways);\n }\n catch(Exception e)\n System.out.println(e.getMessage());\t\t \n }\n} \n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8ea34ae190161b6957760f80fa6ad8d4", "src_uid": "ab4f9cb3bb0df6389a4128e9ff1207de", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\n\npublic class Main {\n public static void main(String[] args) {\n Scanner r = new Scanner(System.in);\n \n long a = r.nextInt();\n long b = r.nextInt();\n long mod = r.nextInt();\n \n long mul = 1000000000;\n a = Math.min(a, 999999999);\n b = Math.min(b, 999999999);\n \n if(b >= mod-1){\n System.out.println(2);\n return;\n }\n \n for(long add = 0; add <= a; add++){\n long number = mul*add;\n \n if(b < (mod - number % mod)%mod){\n System.out.printf(\"1 %09d\\n\", add);\n return;\n }\n }\n System.out.println(2);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b975c03471b836d361dc9c24b8fe3179", "src_uid": "8b6f633802293202531264446d33fee5", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\n\npublic class MainA {\n\n\t\n\tpublic static void main(String args[]){\n\t\tInputReader in = new InputReader(System.in);\n\t\tOutputStream outputStream = System.out;\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\t//----------My Code Starts Here----------\n\t\tint n=in.nextInt();\n\t\tint m=in.nextInt();\n\t\tint a[]=new int[n];\n\t\tint x[]=new int[101];\n\t\tboolean isX[]=new boolean[101];\n\t\tfor(int i=0;i{\n\t\tint i;\n\t\tint v;\n\t\t@Override\n\t\tpublic int compareTo(Pair o) {\n\t\t\tif(o.v>this.v) return -1;\n\t\t\treturn 0;\n\t\t}\n\t\t\n\t}\n\tstatic class InputReader {\n\t public BufferedReader reader;\n\t public StringTokenizer tokenizer;\n\n\t public InputReader(InputStream inputstream) {\n\t reader = new BufferedReader(new InputStreamReader(inputstream));\n\t tokenizer = null;\n\t }\n\t \n\t public String nextLine(){\n\t \tString fullLine=null;\n\t \twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t try {\n\t fullLine=reader.readLine();\n\t } catch (IOException e) {\n\t throw new RuntimeException(e);\n\t }\n\t return fullLine;\n\t }\n\t return fullLine;\n\t }\n\t\tpublic String next() {\n\t while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t try {\n\t tokenizer = new StringTokenizer(reader.readLine());\n\t } catch (IOException e) {\n\t throw new RuntimeException(e);\n\t }\n\t }\n\t return tokenizer.nextToken();\n\t }\n\t\tpublic long nextLong() {\n\t\t return Long.parseLong(next());\n\t\t }\n\t public int nextInt() {\n\t return Integer.parseInt(next());\n\t }\n\t }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9a73c0ac104d478c9fd468fe4cc7d872", "src_uid": "692698d4b49ad446984f3a7a631f961d", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\n \n \n \npublic class Main {\n public static void main(String[] args) {\n Scanner in=new Scanner(new InputStreamReader(System.in));\n PrintWriter out=new PrintWriter(System.out);\n String d1 = in.nextLine();\n String d2 = in.nextLine();\n SimpleDateFormat format = new SimpleDateFormat(\"yyyy:MM:dd\");\n Date date1 = null;\n Date date2 = null;\n try {\n date1 = format.parse(d2);\n date2 = format.parse(d1);\n } catch (Exception e) {\n e.printStackTrace();\n }\n long difference = Math.round((double)date1.getTime()/ 24/60/60/1000 - (double)date2.getTime()/ 24/60/60/1000));\n long days = difference ;\n out.println(Math.abs(days));\n \n in.close();\n out.close();\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3e93abbf3492b22629aae4ccc95cd2d4", "src_uid": "bdf99d78dc291758fa09ec133fff1e9c", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.Deque;\nimport java.util.HashMap;\nimport java.util.InputMismatchException;\nimport java.util.Map;\nimport java.util.PriorityQueue;\nimport java.math.BigInteger;\n \npublic class Main{\n\nstatic final InputStream in=System.in;\nstatic final PrintWriter out=new PrintWriter(System.out);\nstatic final int INF=Integer.MAX_VALUE/2;\nstatic final long LINF=Long.MAX_VALUE/2;\n \npublic static void main(String[] args) throws IOException{\nint t=ir.nextInt();\nint s=ir.nextInt();\nint q=ir.nextInt();\nint ans=1;\nint cur=0;\nwhile(true){\ns+=q-1;\ncur+=q;\nif(s>=t) break;\nif(cur>s){\nans++;\ns=0;\n}\n}\nout.println(ans);\nout.flush();\n}\n\npublic static BigInteger fact(int n){\nBigInteger a=BigInteger.ONE;\nfor(int i=2;i<=n;i++){\na=a.multiply(BigInteger.valueOf(i));\n}\nreturn a;\n}\n\nstatic class InputReader {\nprivate InputStream in;\nprivate byte[] buffer=new byte[1024];\nprivate int curbuf;\nprivate int lenbuf;\n\npublic InputReader(InputStream in) {this.in=in;}\n \npublic int readByte() {\nif(lenbuf==-1) throw new InputMismatchException();\nif(curbuf>=lenbuf){\ncurbuf= 0;\ntry{\nlenbuf=in.read(buffer);\n}\ncatch (IOException e) {\nthrow new InputMismatchException();\n}\nif(lenbuf<=0)\nreturn -1;\n}\nreturn buffer[curbuf++];\n}\n\npublic boolean isSpaceChar(int c){return !(c>=33&&c<=126);}\n\nprivate int skip() {int b; while((b = readByte())!=-1&&isSpaceChar(b)); return b;}\n\npublic String next() {\nint b=skip();\nStringBuilder sb=new StringBuilder();\nwhile(!isSpaceChar(b)){\nsb.appendCodePoint(b);\nb=readByte();\n}\nreturn sb.toString();\n}\n \npublic int nextInt() {\nint c=readByte();\nwhile (isSpaceChar(c)) c=readByte();\nboolean minus=false;\nif (c=='-') {\nminus=true;\nc=readByte();\n}\nint res=0;\ndo{\nif(c<'0'||c>'9') throw new InputMismatchException();\nres=res*10+c-'0';\nc=readByte();\n}while(!isSpaceChar(c));\nreturn (minus)?-res:res;\n}\n\npublic long nextLong() {\nint c=readByte();\nwhile (isSpaceChar(c)) c=readByte();\nboolean minus=false;\nif (c=='-') {\nminus=true;\nc=readByte();\n}\nlong res = 0;\ndo{\nif(c<'0'||c>'9') throw new InputMismatchException();\nres=res*10+c-'0';\nc=readByte();\n}while(!isSpaceChar(c));\nreturn (minus)?-res:res;\n}\n\npublic int[] toIntArray(int n){\nint[] a=new int[n];\nfor(int i=0;i{\n public int a;\n public int b;\n \n \n public Pair(){\n this.a = 0;\n this.b = 0;\n \n }\n public Pair(int a,int b , int n , long s){\n this.a = a;\n this.b = b;\n }\n public int compareTo(Pair p){\n if(this.a==p.a){\n return this.b-p.b; \n }\n return this.a-p.a; \n }\n public String toString(){\n return \"a=\"+this.a+\" b=\"+this.b;\n }\n \n} \n/******************** Main Class ***********************/\n\npublic class C\n{ \n public static InputStream inputStream = System.in;\n public static OutputStream outputStream = System.out;\n public static FastReader in = new FastReader(inputStream);;\n public static PrintWriter out = new PrintWriter(outputStream);;\n /*\n Overhead\n */\n public static int tempints[] = new int[100005];\n public static long templongs[] = new long[100005];\n public static double tempdoubles[] = new double[100005];\n //public static double tempdoubles[] = new double[11];\n public static char tempchars[] = new char[100005];\n \n \n public static void main(String[] args) throws java.lang.Exception\n {\n //let_me_start \n \n \n \n \n int a = i();int b = i();int p = i();int q = i();\n long v= 1;\n long x = 0;\n long y= 0;\n long l = 1;\n long r = 100000000000000000L;\n \n \n long z= 0;\n while (l <= r) \n { \n long m = (l + r) / 2; \n v=m;\n x= v-(v/p);\n y =v-v/q;\n z= v-v/p-v/q+v/(p*q);\n \n \n //z= v-(v/g);\n //If the search key on the left half \n if (x>a&&y>b&&x+y-z>a+b) \n { \n //Update right index \n r = m - 1;\n } \n //If the search key on the right half \n else if (x ll = new LinkedList();\n for(int i=1;i<=n;i++){\n if(arr[i])ll.add(i);\n }\n n = ll.size();\n \n int primes[] = new int[n+1];\n for(int i=1;i<=n;i++){\n primes[i]=ll.removeFirst();\n }\n return primes;\n }\n public static long gcd (long a , long b)throws Exception{\n if(b==0)return a;\n return gcd(b , a%b);\n }\n public static long lcm (long a , long b)throws Exception{\n if(a==0||b==0)return 0;\n return (a*b)/gcd(a,b);\n }\n public static long mulmod(long a , long b ,long mod)throws Exception{\n if(a==0||b==0)return 0;\n if(b==1)return a;\n long ans = mulmod(a,b/2,mod);\n ans = (ans*2)% mod;\n if(b%2==1)ans = (a + ans)% mod;\n return ans;\n }\n public static long pow(long a , long b ,long mod)throws Exception{\n if(b==0)return 1;\n if(b==1)return a;\n long ans = pow(a,b/2,mod);\n ans = (ans * ans)% mod;\n if(b%2==1)ans = (a * ans)% mod;\n return ans;\n }\n // 20*20 nCr Pascal Table\n public static long[][] ncrTable()throws Exception{\n long ncr[][] = new long[21][21];\n for(int i=0 ;i<=20 ;i++){ncr[i][0]=1;ncr[i][i]=1;}\n for(int j=0;j<=20 ;j++){\n for(int i=j+1;i<= 20 ;i++){\n ncr[i][j] = ncr[i-1][j]+ncr[i-1][j-1];\n }\n }\n return ncr;\n }\n//*******************************I/O******************************// \npublic static int i()throws Exception{\n //return Integer.parseInt(br.readLine().trim());\n return in.nextInt();\n}\npublic static int[] is(int n)throws Exception{\n //int arr[] = new int[n+1];\n for(int i=1 ; i <= n ;i++)tempints[i] = in.nextInt(); \n return tempints;\n}\npublic static long l()throws Exception{\n return in.nextLong();\n}\npublic static long[] ls(int n)throws Exception{\n //long arr[] = new long[n+1];\n for(int i=1 ; i <= n ;i++)templongs[i] = in.nextLong(); \n return templongs;\n}\n\npublic static double d()throws Exception{\n return in.nextDouble();\n}\npublic static double[] ds(int n)throws Exception{\n //double arr[] = new double[n+1];\n for(int i=1 ; i <= n ;i++)tempdoubles[i] = in.nextDouble(); \n return tempdoubles;\n}\npublic static char c()throws Exception{\n return in.nextCharacter();\n}\npublic static char[] cs(int n)throws Exception{\n //double arr[] = new double[n+1];\n for(int i=1 ; i <= n ;i++)tempchars[i] = in.nextCharacter(); \n return tempchars;\n}\npublic static String s()throws Exception{\n return in.nextLine();\n}\npublic static BigInteger bi()throws Exception{\n return in.nextBigInteger();\n}\n//***********************I/O ENDS ***********************//\n//*********************** 0.3%f [precision]***********************//\n/* roundoff upto 2 digits \n double roundOff = Math.round(a * 100.0) / 100.0;\n or\n System.out.printf(\"%.2f\", val);\n \n*/\n/* print upto 2 digits after decimal\n val = ((long)(val * 100.0))/100.0;\n \n*/\n}\n\nclass FastReader{\n\n private boolean finished = false;\n\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private SpaceCharFilter filter;\n\n public FastReader(InputStream stream){\n this.stream = stream;\n }\n\n public int read(){\n if (numChars == -1){\n throw new InputMismatchException ();\n }\n if (curChar >= numChars){\n curChar = 0;\n try{\n numChars = stream.read (buf);\n } catch (IOException e){\n throw new InputMismatchException ();\n }\n if (numChars <= 0){\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int peek(){\n if (numChars == -1){\n return -1;\n }\n if (curChar >= numChars){\n curChar = 0;\n try{\n numChars = stream.read (buf);\n } catch (IOException e){\n return -1;\n }\n if (numChars <= 0){\n return -1;\n }\n }\n return buf[curChar];\n }\n\n public int nextInt(){\n int c = read ();\n while (isSpaceChar (c))\n c = read ();\n int sgn = 1;\n if (c == '-'){\n sgn = -1;\n c = read ();\n }\n int res = 0;\n do{\n if(c==','){\n c = read();\n }\n if (c < '0' || c > '9'){\n throw new InputMismatchException ();\n }\n res *= 10;\n res += c - '0';\n c = read ();\n } while (!isSpaceChar (c));\n return res * sgn;\n }\n\n public long nextLong(){\n int c = read ();\n while (isSpaceChar (c))\n c = read ();\n int sgn = 1;\n if (c == '-'){\n sgn = -1;\n c = read ();\n }\n long res = 0;\n do{\n if (c < '0' || c > '9'){\n throw new InputMismatchException ();\n }\n res *= 10;\n res += c - '0';\n c = read ();\n } while (!isSpaceChar (c));\n return res * sgn;\n }\n\n public String nextString(){\n int c = read ();\n while (isSpaceChar (c))\n c = read ();\n StringBuilder res = new StringBuilder ();\n do{\n res.appendCodePoint (c);\n c = read ();\n } while (!isSpaceChar (c));\n return res.toString ();\n }\n\n public boolean isSpaceChar(int c){\n if (filter != null){\n return filter.isSpaceChar (c);\n }\n return isWhitespace (c);\n }\n\n public static boolean isWhitespace(int c){\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n private String readLine0(){\n StringBuilder buf = new StringBuilder ();\n int c = read ();\n while (c != '\\n' && c != -1){\n if (c != '\\r'){\n buf.appendCodePoint (c);\n }\n c = read ();\n }\n return buf.toString ();\n }\n\n public String nextLine(){\n String s = readLine0 ();\n while (s.trim ().length () == 0)\n s = readLine0 ();\n return s;\n }\n\n public String nextLine(boolean ignoreEmptyLines){\n if (ignoreEmptyLines){\n return nextLine ();\n }else{\n return readLine0 ();\n }\n }\n\n public BigInteger nextBigInteger(){\n try{\n return new BigInteger (nextString ());\n } catch (NumberFormatException e){\n throw new InputMismatchException ();\n }\n }\n\n public char nextCharacter(){\n int c = read ();\n while (isSpaceChar (c))\n c = read ();\n return (char) c;\n }\n\n public double nextDouble(){\n int c = read ();\n while (isSpaceChar (c))\n c = read ();\n int sgn = 1;\n if (c == '-'){\n sgn = -1;\n c = read ();\n }\n double res = 0;\n while (!isSpaceChar (c) && c != '.'){\n if (c == 'e' || c == 'E'){\n return res * Math.pow (10, nextInt ());\n }\n if (c < '0' || c > '9'){\n throw new InputMismatchException ();\n }\n res *= 10;\n res += c - '0';\n c = read ();\n }\n if (c == '.'){\n c = read ();\n double m = 1;\n while (!isSpaceChar (c)){\n if (c == 'e' || c == 'E'){\n return res * Math.pow (10, nextInt ());\n }\n if (c < '0' || c > '9'){\n throw new InputMismatchException ();\n }\n m /= 10;\n res += (c - '0') * m;\n c = read ();\n }\n }\n return res * sgn;\n }\n\n public boolean isExhausted(){\n int value;\n while (isSpaceChar (value = peek ()) && value != -1)\n read ();\n return value == -1;\n }\n\n public String next(){\n return nextString ();\n }\n\n public SpaceCharFilter getFilter(){\n return filter;\n }\n\n public void setFilter(SpaceCharFilter filter){\n this.filter = filter;\n }\n\n public interface SpaceCharFilter{\n public boolean isSpaceChar(int ch);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f72948b40e5e4926881625c16e6a2d3e", "src_uid": "ff3c39b759a049580a6e96c66c904fdc", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.util.Vector;\n\npublic class Modular_Equation_49B {\n public static void main(String[] args) {\n long a,b;\n Scanner sc=new Scanner(System.in);\n a=sc.nextLong();\n b=sc.nextLong();\n long p=a-b;\n Vectorvr=new Vector<>();\n //int arr2[]=new int[p];\n if (a==b){\n System.out.println(\"infinity\");\n }\n else {\n for (long i = b; i <= p; i++) {\n if (p % i ==0 && i>b) {\n vr.add(i);\n }\n }\n System.out.println(vr.size());\n }\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "86da57154244d911aad44dbe72e0987e", "src_uid": "6e0715f9239787e085b294139abb2475", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main\n{\n\tpublic static void main(String[] args) {\n Scanner sc=new Scanner(System.in);\n ArrayList al =new ArrayList<>();\n String s=sc.next();int j=0;int x=0;\n for(int i=0;i 2){\n System.out.println(\"NO\");\n return\n }\n \n if(s.charAt(i) == '4'){\n count++;\n }else{\n count = 0;\n }\n }\n \n System.out.println(\"YES\");\n }\n }\n \n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "afa398126ec582aacc5616b15d038ec7", "src_uid": "3153cfddae27fbd817caaf2cb7a6a4b5", "difficulty": 900.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class ASwimmingPool {\n\n public static void main(String[] args) {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n PrintWriter out = new PrintWriter(System.out, true);\n\n try {\n int n_vert = Integer.parseInt(br.readLine());\n }\n catch (IOException e) {\n System.err.println(e);\n\n }\n\n/* int[][] verts = new int[n_vert][2];\n\n for (int i=0; i =2*n)\n count_more++;\n if(s[j].length<=(n/2))\n count_less++;\n }\n if(count_more == s.length-1 || count_less == s.length-1)\n {\n System.out.println(ans[i]);\n flag = 1;\n break;\n }\n }\n if(flag==0)\n System.out.println(\"C\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "16a02bbfa725ad1c6d16ab2828e22337", "src_uid": "30725e340dc07f552f0cce359af226a4", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Dp {\n\n public static void main(String args[]) {\n InputReader in = new InputReader(System.in);\n PrintWriter out = new PrintWriter(System.out);\n int t = 1;\n while (t-- > 0) {\n long l = in.nextLong();\n long r = in.nextLong();\n out.println(fuc(r) - fuc(l - 1));\n }\n out.close();\n }\n\n static long fuc(long r) {\n long val[] = new long[18];\n val[1] = 9;\n val[2] = 9;\n for (int i = 3; i < 18; i++) {\n val[i] = val[i - 1] * 10;\n }\n int dig = 0;\n long rr = r;\n ArrayList aa = new ArrayList();\n while (rr > 0) {\n dig++;\n aa.add((int) (rr % 10));\n rr = rr / 10;\n }\n if (dig <= 1) return r;\n long ans = 0;\n for (int i = 0; i < dig; i++) {\n ans += val[i];\n }\n int i = 0;\n int j = aa.size() - 1;\n Collections.reverse(aa);\n long curr = 0;\n\n curr = curr + (aa.get(i) - 1) * cal(aa, i + 1, j, 1, 0);\n curr = curr + cal(aa, i + 1, j, 0, aa.get(i));\n\n return ans + curr;\n }\n\n static long vc;\n\n static long cal(ArrayList aa, int i, int j, int kk, long vv) {\n if (i == j) {\n if (vv <= aa.get(j))\n return 1L;\n else {\n return 0;\n }\n }\n long curr = 0;\n if (kk == 1) {\n curr = curr + 10 * cal(aa, i + 1, j, kk, vv);\n } else {\n curr = curr + (aa.get(i)) * cal(aa, i + 1, j, 1, 0);\n curr = curr + cal(aa, i + 1, j, 0, vv);\n }\n return curr;\n }\n\n static int top[];\n static int curr = 0;\n static int visited[];\n static ArrayList adj[];\n\n static void dfs(int i) {\n if (visited[i] == 0) {\n visited[i] = 1;\n for (int j : adj[i]) {\n dfs(j);\n }\n top[curr] = i;\n curr++;\n }\n }\n\n static class InputReader {\n private final InputStream stream;\n private final byte[] buf = new byte[8192];\n private int curChar, snumChars;\n private SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int snext() {\n if (snumChars == -1)\n throw new InputMismatchException();\n if (curChar >= snumChars) {\n curChar = 0;\n try {\n snumChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (snumChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = snext();\n while (isSpaceChar(c)) {\n c = snext();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = snext();\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 = snext();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public long nextLong() {\n int c = snext();\n while (isSpaceChar(c)) {\n c = snext();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = snext();\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 = snext();\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 c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b281026a5cc8ace64e82aa5faf256366", "src_uid": "9642368dc4ffe2fc6fe6438c7406c1bd", "difficulty": 1500.0} {"lang": "Java 7", "source_code": "import java.util.*;\npublic class Solution{\nstatic long number;\nstatic long answer;\n\npublic static void main(String[] args){\nScanner sc = new Scanner(System.in);\nnumber = sc.nextInt();\nanswer = -1;\nfindNumber(0, 0, 0);\nSystem.out.print(answer);\n\n}\nstatic void findNumber(long num, int fours, int sevens){\nif (num > 1000000000){\nreturn;}\nif(num >= number && fours == sevens){\nif(answer==-1){\namswer = num;\n}\nelse{\nanswer = Math.min(num, answer);}\n}\nfindNumber(num*10 + 4, fours + 1, sevens);\nfindNumber(num*10 + 7, fours, sevens + 1);\n\n}\n\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "199e2ee9ddbfbaf4b856bbd44bac2673", "src_uid": "77b5f83cdadf4b0743618a46b646a849", "difficulty": 1300.0} {"lang": "Java 11", "source_code": "mport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.Reader;\nimport java.util.*;\n\npublic class Skateboard {\n\tpublic static void main(String[] args) {\n\t\tScanner input = new Scanner(System.in);\n\t\tint n = input.nextInt(), b = input.nextInt(), p = input.nextInt();\n\t\tint bottles = 0, towels = n*p;\n\t\twhile(n > 1) {\n\t\t\tint k = (int) Math.pow(2, log2(n));\n\t\t\tbottles += b*k + (k/2);\n\t\t\tn -= (k/2);\n\t\t}\n\t\tSystem.out.println(bottles + \" \" + towels);\n\t\tinput.close();\n\t\t\n\t\t\n\t}\n\tpublic static int log2(int num) {\n\t\treturn 31 - Integer.numberOfLeadingZeros(num);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1aa3e71b0e90207d8da86f7ff9e92cad", "src_uid": "eb815f35e9f29793a120d120968cfe34", "difficulty": 1000.0} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class Beautiful\n{\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n String S=sc.nextLine();\n String number=\"\";\n int l=S.length();\n for(int i=0;i 0){\n\t\t\t\tc = cur.multiply(t).add(b.multiply(f[i-1]));\n\t\t\t}else{\n\t\t\t\tc = t;\n\t\t\t}\n\t\t\tif (c.compareTo(z) >= 0){\n\t\t\t\tSystem.out.println(i);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcur = cur.multiply(k);\n\t\t}\t\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0693bdced369c2894315a0bf7482ae92", "src_uid": "e2357a1f54757bce77dce625772e4f18", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "public class HelloWorld{\n\n public static void main(String []args){\n Scanner file = new Scanner(System.in);\n int times = file.nextInt();\n String s = file.next();\n boolean b = true;\n for (int i = 0; i < times - 1; i++) {\n if (s.charAt(i) == '1' && s.charAt(i + 1) == '1') {\n b = false;\n break;\n }\n }\n int count = 0;\n for (int i = 0; i < times; i++) {\n if (s.charAt(i) == '0') {\n count++;\n }\n if (count >= 3) {\n b = false;\n break;\n }\n }\n System.out.println(b ? \"Yes\" : \"No\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9404188e42150ca1109eea48db0095a3", "src_uid": "c14d255785b1f668d04b0bf6dcadf32d", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "=\nimport java.util.*;\n\npublic class BullsAndCows_36C {\n public static void solve(int n, String input1[], String input2[]) {\n String guess1 = input1[0];\n Map mapGuess1 = new HashMap<>();\n Map mapGuess2 = new HashMap<>();\n int index = 0;\n for (char c : guess1.toCharArray()) {\n if (mapGuess1.get(c) != null) {\n System.out.println(\"Incorrect data\");\n return;\n }\n mapGuess1.put(c, index++);\n }\n int bulls = Integer.parseInt(input1[1]);\n int cows = Integer.parseInt(input1[2]);\n\n String guess2 = input2[0];\n index = 0;\n int found = 0;\n for (char c : guess2.toCharArray()) {\n if (mapGuess2.get(c) != null) {\n System.out.println(\"Incorrect data\");\n return;\n }\n if (mapGuess1.get(c) != null) {\n found++;\n }\n mapGuess2.put(c, index++);\n }\n\n if (found == 0) {\n System.out.println(\"Incorrect data\");\n return;\n }\n int bulls2 = Integer.parseInt(input2[1]);\n int cows2 = Integer.parseInt(input2[2]);\n if (cows + bulls == (cows2 + bulls2) && found < bulls + cows) {\n System.out.println(\"Need more data\");\n return;\n }\n\n// List results = new ArrayList<>();\n Set set = new HashSet<>();\n// char arr[] = new char[4];\n// for (int i = 0123; i <= 9876; i++) {\n for (char a = '0'; a <= '9'; a++) {\n for (char b = '0'; b <= '9'; b++) {\n for (char c = '0'; c <= '9'; c++) {\n for (char d = '0'; d <= '9'; d++) {\n StringBuilder str = new StringBuilder();\n str.append(a);\n str.append(b);\n str.append(c);\n str.append(d);\n if (isUnique(str.toString())) {\n set.add(str.toString());\n }\n }\n }\n }\n }\n\n// }\n\n// Iterator it = set.iterator();\n String s[] = new String[]{guess1, guess2};\n int bul[] = new int[]{bulls, bulls2};\n int cow[] = new int[]{cows, cows2};\n index = 0;\n while (n-- > 0) {\n Iterator itr = set.iterator();\n while (itr.hasNext()) {\n if (!comp(itr.next(), s[index], bul[index], cow[index])) {\n itr.remove();\n }\n }\n index++;\n// if (comp(set, guess1, bulls, cows, guess2, bulls2, cows2)) {\n\n }\n for (String r : set) {\n System.out.println(r);\n }\n }\n\n\n private static boolean isUnique(String num) {\n Set set = new HashSet<>();\n for (char a: num.toCharArray()) {\n set.add(a);\n }\n return set.size() == 4;\n }\n\n public static boolean compare(char current[], String guess1, int bulls, int cows, String guess2, int bulls2,\n int cows2) {\n\n Set set_1 = new HashSet<>();\n for (char s : guess1.toCharArray()) {\n set_1.add(s);// - '0');\n }\n Set set_2 = new HashSet<>();\n for (char s : guess2.toCharArray()) {\n set_2.add(s);// - '0');\n }\n int samePos = 0;\n// Iterator it_current = current.iterator();\n List remain = new ArrayList<>();\n int index = 0;\n for (char s : guess1.toCharArray()) {\n if (s == current[index++]) {\n samePos++;\n } else {\n remain.add(s);\n }\n }\n\n int f_cows = 0;\n for (char r : remain) {\n if (set_1.contains(r) || set_2.contains(r)) {\n f_cows++;\n }\n }\n if (f_cows != cows || samePos != bulls) return false;\n remain = new ArrayList<>();\n samePos = 0;\n index = 0;\n for (char s : guess2.toCharArray()) {\n if (s == current[index++]) {\n samePos++;\n } else {\n remain.add(s);\n }\n }\n// if (samePos < bulls2) {\n// return false;\n// }\n f_cows = 0;\n for (char r : remain) {\n if (set_2.contains(r) || set_1.contains(r)) {\n f_cows++;\n }\n }\n if (f_cows != cows2 || samePos != bulls2) return false;\n return true;\n }\n\n static boolean comp(String current, String guess1, int bulls, int cows) {\n char m[] = new char[26];\n for (char c : current.toCharArray()) {\n m[c - '0'] = 1;\n }\n int c = 0;\n int b = 0;\n\n// for (int i = 0; i < 2; ++i) {\n b = 0;\n c = 0;\n for (int j = 0; j < 4; ++j) {\n if (guess1.charAt(j) == current.charAt(j)) {\n b++;\n } else if (m[guess1.charAt(j) - '0'] == 1) {\n c++;\n }\n }\n\n if (b != bulls || c != cows) {\n return false;\n }\n// }\n\n return true;\n }\n\n public static void main(String args[]) {\n Scanner in = new Scanner(System.in);\n int n = Integer.parseInt(in.nextLine());\n// for (int i = 0; i < n; i++) {\n String input1 = in.nextLine();\n String input2 = in.nextLine();\n\n solve(n, input1.split(\" \"), input2.split(\" \"));\n// }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "73ee8a7c1c61cd1d1beb9090a5059cad", "src_uid": "142e5f2f08724e53c234fc2379216b4c", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.util.Arrays;\n\npublic class Main {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int k = sc.nextInt();\n int a[] = new int[12];\n for (int i = 0; i < 12; ++i) {\n a[i] = sc.nextInt();\n }\n\n Arrays.sort(a, (o1, o2) -> o2.compareTo(o1));\n int sum = 0, i = 0;\n while (i < 12 && sum < k) {\n sum += a[i];\n i += 1;\n }\n if (sum < k) {\n System.out.print(-1);\n } else {\n System.out.print(i);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "670c486b3432942cad4503d2ddeab352", "src_uid": "59dfa7a4988375febc5dccc27aca90a8", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class GFG {\n\tpublic static void main (String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int m = sc.nextInt();\n if (m != 0)\n System.out.println(min(m,n-m));\n else\n System.out.println(m);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7c8da0feec896eb32d3c4dcc35218f4e", "src_uid": "c05d0a9cabe04d8fb48c76d2ce033648", "difficulty": 900.0} {"lang": "Java 11", "source_code": "import java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class Test {\n\n static PrintWriter writer =\n new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n boolean found = false;\n boolean[] asked = new boolean[128];\n List[] nei = new List[128];\n Vector path = new Vector<>();\n\n {\n for (int i = 0; i < nei.length; i++) nei[i] = new ArrayList<>();\n }\n\n static int readInt() {\n int ans = 0;\n boolean neg = false;\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (c == '-') {\n start = true;\n neg = true;\n continue;\n } else if (c >= '0' && c <= '9') {\n start = true;\n ans = ans * 10 + c - '0';\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return neg ? -ans : ans;\n }\n\n static long readLong() {\n long ans = 0;\n boolean neg = false;\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (c == '-') {\n start = true;\n neg = true;\n continue;\n } else if (c >= '0' && c <= '9') {\n start = true;\n ans = ans * 10 + c - '0';\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return neg ? -ans : ans;\n }\n\n static String readString() {\n StringBuilder b = new StringBuilder();\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (Character.isLetterOrDigit(c)) {\n start = true;\n b.append((char) c);\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return b.toString();\n }\n\n static int readChars(char[] a, int off) {\n int cnt = 0;\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (Character.isLetterOrDigit(c)) {\n start = true;\n a[off + cnt++] = (char) c;\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return cnt;\n }\n\n public static void main(String[] args) {\n Test te = new Test();\n te.start();\n writer.flush();\n }\n\n void ask(int u) {\n writer.println(\"? \" + u);\n writer.flush();\n asked[u] = true;\n nei[u].clear();\n int k = readInt();\n for (int i = 0; i < k; i++) nei[u].add(readInt());\n if (k == 2) answer(u);\n }\n\n private void answer(int u) {\n writer.println(\"! \" + u);\n writer.flush();\n found = true;\n }\n\n void findPath(int u) {\n path.add(u);\n ask(u);\n if (found) return;\n for (int v : nei[u])\n if (!asked[v]) {\n findPath(v);\n break;\n }\n }\n\n void bfs(int u) {\n int cnt = 0;\n Queue q = new LinkedList<>();\n q.offer(u);\n while (!found && cnt < 6 && !q.isEmpty()) {\n u = q.poll();\n ask(u);\n cnt++;\n for (int v : nei[u]) if (!asked[v]) q.add(v);\n }\n if (!found) answer(q.poll());\n }\n\n void start() {\n int t = readInt();\n while (t-- > 0) {\n readInt();\n found = false;\n Arrays.fill(asked, false);\n path.clear();\n findPath(1);\n if (found) continue;\n for (int v : nei[1])\n if (!asked[v]) {\n Collections.reverse(path);\n findPath(v);\n break;\n }\n while (!found) {\n int h = (path.size() + 1) / 2;\n path.setSize(h);\n int u = path.get(h - 1);\n for (int v : nei[u])\n if (!asked[v]) {\n if (h >= 4) bfs(v);\n else findPath(v);\n break;\n }\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "851f9875d37bdb6b7e1dfd625fdaec84", "src_uid": "5c0db518fa326b1e405479313216426a", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\n\npublic class Main{\n\tpublic static void main(String[] args) {\n\t\tnew Main().solve();\n\t}\n\tpublic void solve(){\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tScanner in = new Scanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tchar[]s = in.next().toCharArray();\n\t\tgetCode(s);\n\t\tout.close();\n\t}\n\tvoid getCode(char[]cs){\n\t\tString ans = \"-1\";\n\t\tboolean[]alpha = new boolean[26];\n\t\tint i,size = 0,beg = 0,j; char c;\n\t\tboolean end = false;\n\t\tif(cs.length > 25){\n\t\t\tfor(i = 0; i < cs.length && !end; i++){\n\t\t\t\tend = true; size = 0;\n\t\t\t\talpha = new boolean[26];\n\t\t\t\tfor(j = i; j < cs.length && size < 26 && end; j++){\n\t\t\t\t\tc = cs[j];\n\t\t\t\t\tif(c == '?') size++;\n\t\t\t\t\telse if(alpha[c-'A']) end = false;\n\t\t\t\t\telse {alpha[c-'A'] = true; size++;}\n\t\t\t\t}\n\t\t\t\tif(end && size > 25) beg = i;\n\t\t\t\telse end = false;\n\t\t\t}\n\t\t\tif(end){\n\t\t\t\tans = getCode(cs, alpha, beg);\n\t\t\t}\n\t\t}\t\n\t}\n\tvoid getCode(char[]cs, boolean[] alpha, int beg){\n\t\tString ans = \"\"; int i, size = 1,j;\n\t\tfor(i = beg; size <= 26; i++, size++){\n\t\t\tif(cs[i] == '?'){\n\t\t\t\tj = 25;\n\t\t\t\twhile(alpha[j] && j > -1) j--;\n\t\t\t\tcs[i] = (char)(j+'A');\n\t\t\t\t//System.out.println(j+\"###\");\n\t\t\t\talpha[j] = true;\n\t\t\t}\n\t\t}\n\t\tfor(i = 0; i < cs.length; i++){\n\t\t\tif(cs[i] == '?') System.out.print(\"A\");\n\t\t\telse System.out.print(cs[i]);\n\t\t}\n\t}\n\n\tclass Scanner{\n\t\tBufferedReader reader;\n\t\tStringTokenizer tokenizer;\n\t\tpublic Scanner(InputStream stream){\n\t\t\treader = new BufferedReader(new InputStreamReader(stream), 32768);\n\t\t\ttokenizer = null;\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 int nextInt(){\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "eb69cb82da474cc706d486fb28774706", "src_uid": "a249431a4b0b1ade652997fe0b82edf3", "difficulty": 1300.0} {"lang": "Java 7", "source_code": "public class zher{\n public static void main(String[] args){\n Scanner in = new Scanner(System.in);\n int s= in.next();\n if (s%2==0) System.out.println(2);\n else System.out.println(1);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c1a07b1282638f247f6577d29a6ecc03", "src_uid": "816ec4cd9736f3113333ef05405b8e81", "difficulty": 1200.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n/**\n * Created with IntelliJ IDEA.\n * User: chinh\n * Date: 12/19/13\n * Time: 12:38 AM\n * To change this template use File | Settings | File Templates.\n */\npublic class R220D2A {\n public static void main(String[] args) throws Exception{\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer st = new StringTokenizer(br.readLine());\n int n = Integer.parseInt(st.nextToken());\n int m = Integer.parseInt(st.nextToken());\n int i = Integer.parseInt(st.nextToken());\n int j = Integer.parseInt(st.nextToken());\n int a = Integer.parseInt(st.nextToken());\n int b = Integer.parseInt(st.nextToken());\n int[] u = {1,n,n,1};\n int[] v = {m,1,m,1};\n int result = Integer.MAX_VALUE;\n for(int e=0; e<4; e++){\n if((u[e]-i)%a==0 && (v[e]-j)%b==0){\n if(((u[e]-i)/a)%2 - (v[e]-j)/b)%2==0){\n result = Math.min(result, Math.max(Math.abs(u[e]-i)/a, Math.abs(v[e]-j)/a));\n }\n }\n }\n if(result==Integer.MAX_VALUE) System.out.println(\"Poor Inna and pony!\"); else System.out.println(result);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5a9659290be68596ff4eb50f80e4317b", "src_uid": "51155e9bfa90e0ff29d049cedc3e1862", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "import java.util.HashSet;\nimport java.util.Scanner;\nimport java.util.Set;\n\n/**\n * @author huangjinkun.\n * @date 16/4/2\n * @time \u4e0a\u534812:23\n */\npublic class Wash {\n\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n String line1 = scanner.nextLine();\n String line2 = scanner.nextLine();\n String line3 = scanner.nextLine();\n\n int limit = Integer.parseInt(line1);\n int result = 0;\n String[] array1Tmp = line2.split(\" \");\n String[] array2Tmp = line3.split(\" \");\n\n int[] array1 = new int[array1Tmp.length];\n int[] array2 = new int[array2Tmp.length];\n\n for (int i = 0; i < array1.length; i++) {\n array1[i] = Integer.parseInt(array1Tmp[i]);\n array2[i] = Integer.parseInt(array2Tmp[i]);\n }\n\n Set set = new HashSet();\n for (int i = 0; i <= 1600000; i++) {\n for (int j = 0; j < array1.length; j++) {\n if (i % array1[j] == array2[j]) {\n set.add(i);\n }\n }\n\n }\n\n System.out.println((double) (set.size()) / (1600000 + 1));\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e6bc49638f5efb29369adc41f35a52c9", "src_uid": "14b69f42bc192ea472e82f3a3209f1c1", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Divide{\n public static void main( String[] args ){\n Scanner numScan = new Scanner( System.in );\n String s = numScan.nextLine();\n while( s.charAt(0) = '0' ){\n s = s.substring(1);\n }\n if( s.length() - s.replaceAll( \"0\", \"\" ).length() > 5 ){\n System.out.println( \"yes\" );\n }\n else{\n System.out.println( \"no\" );\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0da5c5e1fc0e912e523a7f30329e3575", "src_uid": "88364b8d71f2ce2b90bdfaa729eb92ca", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.BitSet;\nimport java.util.HashMap;\nimport java.util.StringTokenizer;\n\n/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n/**\n *\n * @author Andy Phan\n */\npublic class e {\n long MOD = 1_000_000_007;\n \n public e() {\n FS in = new FS(System.in);\n PrintWriter out = new PrintWriter(System.out);\n \n int num = 300_000_000;\n \n int a = in.nextInt();\n int b = in.nextInt();\n \n int tot = 0;\n BitSet set = new BitSet((b+5)/2);\n for(int k = 6; k <= b; k += 6) {\n {\n int i = k+1;\n if(set.get(i/2)) continue;\n if(i >= a && i <= b && (i&0b11) == 1) tot++;\n for(long j = (long)i*i; j <= b; j += i+i) {\n set.set((int)j/2, true);\n }\n }\n {\n int i = k+5;\n if(set.get(i/2)) continue;\n if(i >= a && i <= b && (i&0b11) == 1) tot++;\n for(long j = (long)i*i; j <= b; j += i+i) {\n set.set((int)j/2, true);\n }\n }\n }\n \n if(a <= 2 && b >= 2) tot++;\n \n out.println(tot);\n \n out.close();\n }\n public static void main(String[] args) {\n new e();\n }\n\n static class FS {\n\n BufferedReader in;\n StringTokenizer token;\n\n public FS(InputStream str) {\n in = new BufferedReader(new InputStreamReader(str));\n }\n\n public String next() {\n if (token == null || !token.hasMoreElements()) {\n try {\n token = new StringTokenizer(in.readLine());\n } catch (IOException ex) {\n }\n return next();\n }\n return token.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "75dbe3a01baa893ab6018ab6bdd47485", "src_uid": "55a83526c10126ac3a6e6e5154b120d0", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.io.*;\n\npublic class Solution{\n \n public static void main(String[] args) throws IOException{\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in);\n String read = br.readLine();\n int last = 97\n for(int i = 0; i < read.length(); i++){\n int current = (int) read.charAt(i);\n if(current > last){\n if(current == last+1){\n last++;\n }else{\n System.out.println(\"NO\");\n }\n }else{\n System.out.println(\"NO\");\n }\n }\n System.out.println(\"YES\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "77dc100714cb98cd8b1e82eb9d78f56e", "src_uid": "c4551f66a781b174f95865fa254ca972", "difficulty": 1100.0} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\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\t\n\tbyte []dp;\n\tint n = 5, m = 9;\n\tint []x,y;\n\n\tpublic void run() throws Exception{\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tchar [][]a = new char[n][];\n\t\tfor(int i=0;i 0;\n\n\t\t// System.out.println(mask);\n\n\t\tchar [][]a = decode(mask);\n\t\tchar [][]b;\n\t\tfor(int i=0;i= n || j >= m) return false;\n\t\treturn true;\n\t}\n\n\tprivate void print(char [][]a) {\n\t\tfor(int i=0;i 0) {\n\t\t\t\ta[x[i]][y[i]] = 'O';\n\t\t\t}else {\n\t\t\t\ta[x[i]][y[i]] = '.';\n\t\t\t}\n\t\t}\n\t\treturn a;\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", "compilation_error": false, "code_uid": "9f50e19abfeca1799f24eb5f3f1d5f71", "src_uid": "eaa022cc7846c983a826900dc6dd919f", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "mport java.util.Scanner;\n\npublic class train {\n\n public static void main(String args[]) {\n Scanner in = new Scanner(System.in);\n long u = in.nextLong();\n long v = in.nextLong();\n boolean b = false;\n long x;\n if (u == 0 && v == 0) {\n System.out.println(\"0\");b=true;\n }\n else\n if (u > v) {\n b = false;\n } else {\n if (u == 1) {\n b = true;\n System.out.println(v);\n for (int i = 0; i < v; i++) {\n System.out.print(\"1 \");\n }\n } \n else if((v-u) %2 == 0 && v>100){System.out.println(\"3\\n\"+(v-u)/2+\" \"+(v-u)/2+\" \"+u);b = true;}\n else {\n for (int i = 1; i <= v/2; i++) {\n x = u ^ i;\n if (x + i == v) {\n System.out.println(2 + \"\\n\" + i + \" \" + x);\n b = true;\n break;\n }\n }\n }\n }\n if (b == false) {\n System.out.println(\"-1\");\n }\n\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b94bd5c5d78bf2dca517154a137c6b46", "src_uid": "490f23ced6c43f9e12f1bcbecbb14904", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class A\n{\n public static void main(String args[])\n {\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n int m=sc.nextInt();\n int count=0,flag=0;\n if(n==m)\n System.out.println(0);\n else\n {\n while(m!=n)\n {\n if(m%(n*2)==0))\n {\n count++;\n n=n*2;\n }\n else if(m%(n*3)==0)\n {\n count++;\n n=n*3;\n }\n else\n {\n flag==1;\n break;\n }\n }\n if(flag==1)\n System.out.println(-1);\n else\n System.out.println(count);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7b2ee379cc97d7ad092d5e0ea6c8521b", "src_uid": "3f9980ad292185f63a80bce10705e806", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "\nimport java.io.*;\nimport java.util.*;\n\npublic class q2 {\n public static MyScanner in = new MyScanner();\n public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out), true);\n public static MyViewer view = new MyViewer();\n public static Random rand = new Random(System.currentTimeMillis());\n\n static class MyScanner {\n BufferedReader br;\n StringTokenizer st;\n private boolean randomInput = false;\n private Random rand;\n\n void randomInput(boolean r) {\n randomInput = r;\n rand = new Random(System.currentTimeMillis());\n //rand = new Random(42);\n }\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 int nextInt(int val) {\n return randomInput ? val : Integer.parseInt(next());\n }\n\n int nextInt(int low, int high) {\n if (randomInput) {\n return rand.nextInt(high - low + 1) + low;\n } else {\n return Integer.parseInt(next());\n }\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n long nextLong(long val) {\n return randomInput ? val : Long.parseLong(next());\n }\n\n long nextLong(long low, long high) {\n if (randomInput) {\n return low + ((long) (rand.nextDouble() * (high - low + 1)));\n } else {\n return Long.parseLong(next());\n }\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n int[] arrayInt(int n) {\n int[] a = new int[n];\n for (int i = 0; i < n; i++) {\n a[i] = in.nextInt();\n }\n return a;\n }\n\n int[] arrayInt(int n, int low, int high) {\n int[] a = new int[n];\n if (randomInput) {\n for (int i = 0; i < n; i++) {\n a[i] = rand.nextInt(high - low + 1) + low;\n }\n } else {\n for (int i = 0; i < n; i++) {\n a[i] = in.nextInt();\n }\n }\n return a;\n }\n\n ArrayList list(int n) {\n ArrayList a = new ArrayList(n);\n for (int i = 0; i < n; i++) {\n a.add(in.nextInt());\n }\n return a;\n }\n\n ArrayList list(int n, int low, int high) {\n ArrayList a = new ArrayList(n);\n if (randomInput) {\n for (int i = 0; i < n; i++) {\n a.add(rand.nextInt(high - low + 1) + low);\n }\n } else {\n for (int i = 0; i < n; i++) {\n a.add(in.nextInt());\n }\n }\n return a;\n }\n\n long[] arrayLong(int n) {\n long[] a = new long[n];\n for (int i = 0; i < n; i++) {\n a[i] = in.nextLong();\n }\n return a;\n }\n\n long[] arrayLong(int n, long low, long high) {\n long[] a = new long[n];\n if (randomInput) {\n for (int i = 0; i < n; i++) {\n double r = rand.nextDouble();\n a[i] = (long) (r * (double) (high - low + 1)) + low;\n if (a[i] == 0) {\n out.println(\"Ouch : \" + r);\n }\n }\n } else {\n for (int i = 0; i < n; i++) {\n a[i] = in.nextLong();\n }\n }\n return a;\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 void close() {\n try {\n br.close();\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n\n ArrayList> randomTree(int n) {\n ArrayList> edges = new ArrayList<>();\n for (int i = 0; i < n; i++) {\n edges.add(new ArrayList<>());\n }\n\n for (int i = 1; i < n; i++) {\n int par = rand.nextInt(i);\n edges.get(par).add(i);\n }\n return edges;\n }\n }\n\n static class MyViewer {\n static boolean print = true;\n\n public void on() {\n print = true;\n }\n\n public void off() {\n print = false;\n }\n\n public void list(T a) {\n if (!print) return;\n out.print(\"List: [\" + a.get(0));\n for (int i = 1; i < a.size(); i++) {\n out.print(\", \" + a.get(i));\n }\n out.println(\"] Len: \" + a.size());\n }\n\n public void array(T[] a) {\n if (!print) return;\n out.print(\"Array: [\" + a[0]);\n for (int i = 1; i < a.length; i++) {\n out.print(\", \" + a[i]);\n }\n out.println(\"] Len: \" + a.length);\n }\n\n public void array(boolean[] a) {\n if (!print) return;\n out.print(\"boolean[] Len: \" + a.length + \" [\");\n for (boolean x : a) {\n out.print(x + \", \");\n }\n out.println(\"\\b\\b]\");\n }\n\n public void array(int[] a) {\n if (!print) return;\n out.print(\"int[] Len: \" + a.length + \" [\");\n for (int x : a) {\n out.print(x + \", \");\n }\n out.println(\"\\b\\b]\");\n }\n\n public void array(long[] a) {\n if (!print) return;\n out.print(\"long Array: [\");\n for (long x : a) {\n out.print(x + \", \");\n }\n out.println(\"\\b\\b] Len: \" + a.length);\n }\n\n public void matrix(int[][] a, int cutoff) {\n if (cutoff == 0)\n cutoff = Integer.MAX_VALUE;\n for (int i = 0; i < a.length; i++) {\n if (i < cutoff) {\n printMatrixRow(a[i], cutoff);\n } else {\n out.println(\" ...\");\n printMatrixRow(a[a.length - 1], cutoff);\n break;\n }\n }\n }\n\n public void matrix(long[][] a, long cutoff) {\n if (cutoff == 0)\n cutoff = Long.MAX_VALUE;\n for (int i = 0; i < a.length; i++) {\n if (i < cutoff) {\n printMatrixRow(a[i], cutoff);\n } else {\n out.println(\" ...\");\n printMatrixRow(a[a.length - 1], cutoff);\n break;\n }\n }\n }\n\n public void matrix(boolean[][] a, int cutoff) {\n if (cutoff == 0)\n cutoff = Integer.MAX_VALUE;\n for (int i = 0; i < a.length; i++) {\n if (i < cutoff) {\n printMatrixRow(a[i], cutoff);\n } else {\n out.println(\" ...\");\n printMatrixRow(a[a.length - 1], cutoff);\n break;\n }\n }\n }\n\n private void printMatrixRow(int[] a, int cutoff) {\n for (int j = 0; j < a.length; j++) {\n if (j < cutoff) {\n out.printf(\"%6d \", a[j]);\n } else {\n out.printf(\" ... %6d\", a[a.length - 1]);\n break;\n }\n }\n out.println();\n }\n\n private void printMatrixRow(long[] a, long cutoff) {\n for (int j = 0; j < a.length; j++) {\n if (j < cutoff) {\n out.printf(\"%6d \", a[j]);\n } else {\n out.printf(\" ... %6d\", a[a.length - 1]);\n break;\n }\n }\n out.println();\n }\n\n private void printMatrixRow(boolean[] a, int cutoff) {\n for (int j = 0; j < a.length; j++) {\n if (j < cutoff) {\n out.print(a[j] ? \"T \" : \"F \");\n } else {\n out.print(\" ... \" + (a[a.length - 1] ? \"T\" : \"F\"));\n break;\n }\n }\n out.println();\n }\n\n }\n\n public static void main(String[] args) throws IOException {\n int n = in.nextInt();\n int m = in.nextInt();\n int[] a = in.arrayInt(m);\n int[] b = new int[n];\n\n Arrays.fill(b, -1);\n\n int l,nl;\n\n for (int mi = 1; mi < m; mi++) {\n l= a[mi-1]-1;\n nl = a[mi]-1;\n if( nl < l)\n nl += n;\n\n int x = nl - l;\n if( x == 0)\n x = n;\n if( b[l] < 0 ) {\n b[l] = x;\n } else if( b[l] == x) {\n continue;\n } else {\n out.println(-1);\n System.exit(0);\n }\n }\n\n boolean[] used = new boolean[n];\n\n for(int i = 0 ;i < n; i ++) {\n if( b[i] % n >= 0 && used[b[i] % n]) {\n out.println(-1);\n System.exit(0);\n }\n if( b[i] % n >= 0)\n used[b[i] % n] = true;\n }\n\n HashSet hs = new HashSet<>();\n for(int x: b) {\n if (x >=0 )\n hs.add(x);\n }\n\n for(int i = 0 ;i < n; i ++) {\n if(b[i] == -1 ) {\n for(int j = 0; j < n; j ++) {\n if (hs.contains(j))\n continue;\n b[i] = j;\n hs.add(j);\n }\n }\n }\n\n\n for(int i = 0 ;i < n; i ++) {\n out.print((b[i]) + \" \");\n }\n out.println();\n\n in.close();\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "85c5fb026d50042d80f158b867a50cd5", "src_uid": "4a7c959ca279d0a9bd9bbf0ce88cf72b", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import jav.util.Scanner;\npublic class code{\n public static void main(String args){\n Scanner sc=new Scanner(System.in);\n String a=sc.next();\n String a=sc.next();\n int count=0;\n if(a.length()==b.length())\n {\n for(int i=0;ia;i--)\n c=c*i;\n c=c%10;\n System.out.println(c);\n }\n }\n else\n System.out.println(0);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ed537957072745bc65ba2f90f530ee5b", "src_uid": "2ed5a7a6176ed9b0bda1de21aad13d60", "difficulty": 1100.0} {"lang": "Java 7", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\npublic class Joysticks {\n\n int chargingLevel;\n boolean connectedToCharger;\n\n Joysticks() {\n }\n\n public static void main(String[] args) {\n Joysticks a1 = new Joysticks();\n Joysticks a2 = new Joysticks();\n int numOfMinutes = 1;\n boolean chargerIsChanged; \n \n String input = \"\";\n try {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n input = br.readLine();\n } catch (Exception e) {\n e.printStackTrace();\n }\n \n String[] arr = input.split(\" \");\n a1.chargingLevel = Integer.parseInt(arr[0]);\n a2.chargingLevel = Integer.parseInt(arr[1]);\n \n while (a1.chargingLevel != 0 && a2.chargingLevel != 0) {\n\n if (numOfMinutes == 1) {\n if (a1.chargingLevel < a2.chargingLevel) {\n a1.connectedToCharger = true;\n a1.chargingLevel += 1;\n a2.chargingLevel -= 2;\n }\n if (a2.chargingLevel < a1.chargingLevel && !a1.connectedToCharger) {\n a2.connectedToCharger = true;\n a2.chargingLevel += 1;\n a1.chargingLevel -= 2;\n }\n if(a1.chargingLevel == a2.chargingLevel && !a1.connectedToCharger && !a2.connectedToCharger){\n a1.connectedToCharger = true;\n a1.chargingLevel += 1;\n a2.chargingLevel -= 2;\n }\n }\n if (numOfMinutes > 1) {\n if(a1.chargingLevel < a2.chargingLevel && !chargerIsChanged){\n a1.chargingLevel += 1;\n a2.chargingLevel -= 2;\n chargerIsChanged = true;\n }\n if(a2.chargingLevel < a1.chargingLevel && !chargerIsChanged){\n a2.chargingLevel += 1;\n a1.chargingLevel -= 2;\n chargerIsChanged = true;\n }\n if(a1.chargingLevel == a2.chargingLevel && !chargerIsChanged){\n if (a1.connectedToCharger) {\n a1.chargingLevel += 1;\n a2.chargingLevel -= 2; \n }\n if (a2.connectedToCharger) {\n a2.chargingLevel += 1;\n a1.chargingLevel -= 2; \n }\n }\n } \n\n if (a1.chargingLevel != 0 && a2.chargingLevel != 0) {\n numOfMinutes++;\n }\n } \n System.out.println(numOfMinutes);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "047541cf06ff1a903672bd7ed542aea8", "src_uid": "ba0f9f5f0ad4786b9274c829be587961", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "// package cf1181;\n\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.*;\n\nimport static java.util.Comparator.comparingInt;\n\npublic class CFE1 {\n private static final String INPUT = \"25\\n\" +\n \"9666 2418 9939 6569\\n\" +\n \"2193 1731 3327 1784\\n\" +\n \"9603 1856 9658 6582\\n\" +\n \"1512 8020 5665 8770\\n\" +\n \"42 9695 1416 9935\\n\" +\n \"1512 9507 9990 9699\\n\" +\n \"8867 6617 9921 8791\\n\" +\n \"1554 4745 8773 7948\\n\" +\n \"9699 1893 9915 2357\\n\" +\n \"75 9585 1418 9625\\n\" +\n \"69 6664 825 9582\\n\" +\n \"66 1883 819 6612\\n\" +\n \"1516 1890 8754 4700\\n\" +\n \"8572 8006 8746 8791\\n\" +\n \"5342 8853 9974 9280\\n\" +\n \"1542 9742 9996 9962\\n\" +\n \"848 1880 1408 9560\\n\" +\n \"8842 1867 9555 6573\\n\" +\n \"5702 7992 8506 8797\\n\" +\n \"15 1753 492 1798\\n\" +\n \"51 58 9985 1715\\n\" +\n \"3375 1758 9955 1794\\n\" +\n \"529 1736 2187 1793\\n\" +\n \"1502 9317 9972 9467\\n\" +\n \"1496 8850 5280 9270\";\n private static final int MOD = 1_000_000_007;\n\n private PrintWriter out;\n private FastScanner sc;\n\n public static void main(String[] args) {\n new CFE1().run();\n }\n\n public void run() {\n sc = new FastScanner(oj ? System.in : new ByteArrayInputStream(INPUT.getBytes()));\n out = new PrintWriter(System.out);\n\n long s = System.currentTimeMillis();\n solve();\n out.flush();\n tr(System.currentTimeMillis() - s + \"ms\");\n }\n\n static class Rect {\n int x1, y1, x2, y2;\n\n public Rect(int x1, int y1, int x2, int y2) {\n this.x1 = x1;\n this.y1 = y1;\n this.x2 = x2;\n this.y2 = y2;\n }\n\n @Override\n public String toString() {\n return \"{\" + x1 + \",\" + y1 + \"-\" + x2 + \",\" + y2 + \"}\";\n }\n }\n\n public void solve() {\n int n = sc.nextInt();\n Set set = new TreeSet<>(comparingInt((Rect r) -> r.x1).thenComparingInt(r -> r.y1));\n for (int i = 0; i < n; i++) {\n Rect rect = new Rect(sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt());\n set.add(rect);\n }\n\n int sol = solve(set);\n System.out.println(sol == n ? \"YES\" : \"NO\");\n }\n\n private int solve(Set set) {\n if (set.size() < 4) return set.size();\n return _solve(set);\n }\n\n static class Recter {\n int i;\n Set set;\n Iterator it;\n Rect rect;\n int area;\n\n public Recter(Set set) {\n this.i = 1;\n this.set = set;\n it = set.iterator();\n rect = it.next();\n }\n\n Rect next() {\n i++;\n return rect = it.next();\n }\n\n int size() {\n return set.size();\n }\n\n Set drain() {\n Set res = new TreeSet<>(comparingInt((Rect r) -> r.x1).thenComparingInt(r -> r.y1));\n Iterator resIt = set.iterator();\n for (int i = 1; i < this.i; i++) {\n res.add(resIt.next());\n resIt.remove();\n }\n\n it = set.iterator();\n rect = it.next();\n i = 1;\n return res;\n }\n\n void clear(Set rects) {\n for (Rect r : rects) {\n set.remove(r);\n }\n it = set.iterator();\n rect = it.next();\n i = 1;\n }\n }\n\n private int _solve(Set setX1) {\n Recter rX1 = new Recter(setX1);\n TreeSet setX2 = new TreeSet<>(comparingInt((Rect r1) -> -r1.x2).thenComparingInt(r1 -> -r1.y2));\n setX2.addAll(setX1);\n Recter rX2 = new Recter(setX2);\n\n TreeSet setY1 = new TreeSet<>(comparingInt((Rect r1) -> r1.y1).thenComparingInt(r1 -> r1.x1));\n setY1.addAll(setX1);\n Recter rY1 = new Recter(setY1);\n\n TreeSet setY2 = new TreeSet<>(comparingInt((Rect r) -> -r.y2).thenComparingInt(r -> -r.x2));\n setY2.addAll(setX1);\n Recter rY2 = new Recter(setY2);\n\n int result = 0;\n rX1.area = rX1.rect.x2;\n rX2.area = rX2.rect.x1;\n rY1.area = rY1.rect.y2;\n rY2.area = rY2.rect.y1;\n while (rX1.size() >= 4 && (rX1.i + rX2.i) <= rX1.size()) {\n rX1.next();\n if (rX1.rect.x1 >= rX1.area) {\n int n = rX1.i - 1;\n Set set = rX1.drain();\n rX1.area = rX1.rect.x2;\n\n rX2.clear(set);\n rX2.area = rX2.rect.x1;\n\n rY1.clear(set);\n rY1.area = rY1.rect.y2;\n\n rY2.clear(set);\n rY2.area = rY2.rect.y1;\n\n int res = solve(set);\n if (res < n) return -1_000_000;\n result += res;\n continue;\n } else {\n rX1.area = Math.max(rX1.area, rX1.rect.x2);\n }\n\n rX2.next();\n if (rX2.rect.x2 <= rX2.area) {\n int n = rX2.i - 1;\n Set set = rX2.drain();\n rX2.area = rX2.rect.x1;\n\n rX1.clear(set);\n rX1.area = rX1.rect.x2;\n\n rY1.clear(set);\n rY1.area = rY1.rect.y2;\n\n rY2.clear(set);\n rY2.area = rY2.rect.y1;\n\n int res = solve(set);\n if (res < n) return -1_000_000;\n result += res;\n continue;\n } else {\n rX2.area = Math.min(rX2.area, rX2.rect.x1);\n }\n\n rY1.next();\n if (rY1.rect.y1 >= rY1.area) {\n int n = rY1.i - 1;\n Set set = rY1.drain();\n rY1.area = rY1.rect.y2;\n\n rY2.clear(set);\n rY2.area = rY2.rect.y1;\n\n rX1.clear(set);\n rX1.area = rX1.rect.x2;\n\n rX2.clear(set);\n rX2.area = rX2.rect.x1;\n\n int res = solve(set);\n if (res < n) return -1_000_000;\n result += res;\n continue;\n } else {\n rY1.area = Math.max(rY1.area, rY1.rect.y2);\n }\n\n rY2.next();\n if (rY2.rect.y2 <= rY2.area) {\n int n = rY2.i - 1;\n Set set = rY2.drain();\n rY2.area = rY2.rect.y1;\n\n rY1.clear(set);\n rY1.area = rY1.rect.y2;\n\n rX1.clear(set);\n rX1.area = rX1.rect.x2;\n\n rX2.clear(set);\n rX2.area = rX2.rect.x1;\n\n int res = solve(set);\n if (res < n) return -1_000_000;\n result += res;\n continue;\n } else {\n rY2.area = Math.min(rY2.area, rY2.rect.y1);\n }\n }\n if (rX1.size() >= 4) {\n return result;\n } else {\n return result + rX1.size();\n }\n }\n\n//********************************************************************************************\n//********************************************************************************************\n//********************************************************************************************\n\n static class SolutionFailedException extends Exception {\n int code;\n\n public SolutionFailedException(int code) {\n this.code = code;\n }\n }\n\n private static void shuffle(int[] array) {\n Random random = new Random();\n for (int i = array.length - 1; i > 0; i--) {\n int index = random.nextInt(i + 1);\n int temp = array[index];\n array[index] = array[i];\n array[i] = temp;\n }\n }\n\n /**\n * If searched element doesn't exist, returns index of first element which is bigger than searched value.
\n * If searched element is bigger than any array element function returns first index after last element.
\n * If searched element is lower than any array element function returns index of first element.
\n * If there are many values equals searched value function returns first occurrence.
\n */\n private static int lowerBound(long[] arr, long key) {\n int lo = 0;\n int hi = arr.length - 1;\n while (lo < hi) {\n int mid = (lo + hi) / 2;\n if (key <= arr[mid]) {\n hi = mid - 1;\n } else {\n lo = mid + 1;\n }\n }\n return arr[lo] < key ? lo + 1 : lo;\n }\n\n /**\n * Returns index of first element which is grater than searched value.\n * If searched element is bigger than any array element, returns first index after last element.\n */\n private static int upperBound(long[] arr, long key) {\n int lo = 0;\n int hi = arr.length - 1;\n while (lo < hi) {\n int mid = (lo + hi) / 2;\n if (key >= arr[mid]) {\n lo = mid + 1;\n } else {\n hi = mid;\n }\n }\n return arr[lo] <= key ? lo + 1 : lo;\n }\n\n private static int ceil(double d) {\n int ret = (int) d;\n return ret == d ? ret : ret + 1;\n }\n\n private static int round(double d) {\n return (int) (d + 0.5);\n }\n\n private static int gcd(int a, int b) {\n BigInteger b1 = BigInteger.valueOf(a);\n BigInteger b2 = BigInteger.valueOf(b);\n BigInteger gcd = b1.gcd(b2);\n return gcd.intValue();\n }\n\n private static long gcd(long a, long b) {\n BigInteger b1 = BigInteger.valueOf(a);\n BigInteger b2 = BigInteger.valueOf(b);\n BigInteger gcd = b1.gcd(b2);\n return gcd.longValue();\n }\n\n private int[] readIntArray(int n) {\n int[] res = new int[n];\n for (int i = 0; i < n; i++) {\n res[i] = sc.nextInt();\n }\n return res;\n }\n\n private long[] readLongArray(int n) {\n long[] res = new long[n];\n for (int i = 0; i < n; i++) {\n res[i] = sc.nextLong();\n }\n return res;\n }\n\n @SuppressWarnings(\"unused\")\n static class FastScanner {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n\n FastScanner(InputStream stream) {\n this.stream = stream;\n }\n\n 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) return -1;\n }\n return buf[curChar++];\n }\n\n boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n boolean isEndline(int c) {\n return c == '\\n' || c == '\\r' || c == -1;\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 int c = read();\n while (isSpaceChar(c)) c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public String nextLine() {\n int c = read();\n while (isEndline(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isEndline(c));\n return res.toString();\n }\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8272f2dd4cbd4f5bca28bf54f3224558", "src_uid": "5bfb165b4efe081d6a8c4843f7769a37", "difficulty": 3000.0} {"lang": "Java 6", "source_code": "import java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class Main {\n public static void main(String[] args) throws Exception{\n new Main().run();\n }\n \n private void run() throws Exception{\n Scanner input = new Scanner(System.in);\n int a = input.nextInt();\n int b = input.nextInt();\n int m = input.nextInt();\n int r0 = input.nextInt();\n int pos = 0;\n ArrayListlist = new ArrayList();\n while(true){\n if(list.contains(r0)){\n pos = list.size() - list.indexOf(r0);\n break;\n }\n else{\n list.add(r0);\n }\n r0 = (a*r0 + b)%m;\n }\n System.out.println(pos);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "de7ee3141bfd855298543d795084749c", "src_uid": "9137197ee1b781cd5cc77c46f50b9012", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main {\n\n public static void main(String args[]) {\n\n Scanner sc = new Scanner(System.in) ;\n int n = sc.nextInt() ;\n for (int i =0 ; i< n ; i++){\n System.out.println(sc.nextInt() / 2);\n }\n\n\n }\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1d0291eff93f71dddee75b54eaaab98a", "src_uid": "a661b6ce166fe4b2bbfd0ace56a7dc2c", "difficulty": 800.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author thnkndblv\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n Scanner in = new Scanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskA solver = new TaskA();\n solver.solve(1, in, out);\n out.close();\n }\n}\n\nclass TaskA {\n long check(int hy, int ay, int dy, int hm, int am, int dm) {\n if ( dm >= ay ) return (long)1e9;\n if ( dy >= am ) return 0L;\n\n int monsterHints = (hy + am - dy - 1) / (am - dy);\n int yangHints = (hm + ay- dm - 1) / (ay - dm);\n\n if ( monsterHints > yangHints ) return 0;\n else if ( monsterHints == yangHints ) return 1 * (am - dy);\n else return (yangHints - monsterHints + 1) * (am - dy);\n }\n\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n int hpy = in.nextInt();\n int atky = in.nextInt();\n int defy = in.nextInt();\n\n int hpm = in.nextInt();\n int atkm = in.nextInt();\n int defm = in.nextInt();\n\n int h = in.nextInt();\n int a = in.nextInt();\n int d = in.nextInt();\n\n long ans = (int)1e9;\n for (int i = 0; i <= 100; i++)\n for (int j = 0; j <= 100; j++) {\n ans = Math.min( ans, i*a + j*d + check(hpy, atky + i, defy + j, hpm, atkm, defm)*h );\n }\n\n out.println( ans );\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e55b59b9a903c964f69d38db406389da", "src_uid": "bf8a133154745e64a547de6f31ddc884", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "/*\r\n Goal: Become better in CP!\r\n Key: Consistency and Discipline\r\n Desire: SDE @ Google USA\r\n Motto: Do what i Love <=> Love what i do\r\n If you don't use your brain 100%, it deteriorates gradually\r\n*/\r\n\r\nimport java.util.*;\r\nimport java.io.*;\r\nimport java.math.*;\r\n\r\npublic class Solution {\r\n\r\n static StringBuffer str=new StringBuffer();\r\n static BufferedReader bf;\r\n static PrintWriter pw;\r\n static int n, x;\r\n static long mod=998244353l;\r\n static long dp[][];\r\n static long comb[][];\r\n\r\n static long mod_mul(long a, long b) {\r\n a = a % mod;\r\n b = b % mod;\r\n return (((a * b) % mod) + mod) % mod;\r\n }\r\n\r\n static long mod_add(long a, long b) {\r\n a = a % mod;\r\n b = b % mod;\r\n return (((a + b) % mod) + mod) % mod;\r\n }\r\n\r\n static long pow(long a, long b) {\r\n long res = 1;\r\n while (b > 0) {\r\n if (b % 2 == 1) res = (res * a)%mod;\r\n a = (a * a)%mod;\r\n b = b >> 1l;\r\n }\r\n return res;\r\n }\r\n\r\n // O(n*x*n) solution\r\n static long count(int i, int j){\r\n if(i==1) return 0;\r\n if(i==0) return 1;\r\n if(j>=x) return 0;\r\n if(dp[i][j]!=-1) return dp[i][j];\r\n\r\n int cost = Math.min(x, j+i-1);\r\n // Transition from dp[i][j] to dp[k][cost]\r\n long ans=0;\r\n for(int k=0;k<=i;k++){\r\n ans=mod_add(ans, mod_mul(comb[i][i-k], mod_mul(pow(cost-j, i-k), count(k, cost))));\r\n }\r\n return dp[i][j]=ans;\r\n }\r\n\r\n // DP + Combinatorics\r\n static void solve(int te) throws Exception{\r\n comb = new long[501][501];\r\n comb[0][0] = 1;\r\n for (int i = 1; i <= 500; i++) {\r\n comb[i][0] = 1;\r\n for (int j = 1; j <= i; j++) {\r\n comb[i][j] = (comb[i-1][j] + comb[i-1][j-1]) % mod;\r\n }\r\n }\r\n\r\n /* // Top down dp\r\n \r\n // dp[i][j] = # of ways to choose health = required answer \r\n // i -> i heros still alive => i=n is required \r\n // j -> already received j damage => j<=x is required\r\n\r\n // sum of dp[0][j] for each j in [0, x] is the answer\r\n dp=new long[n+1][x+1];\r\n for(int i=0;i<=n;i++){\r\n for(int j=0;j<=x;j++){\r\n dp[i][j]=-1;\r\n }\r\n }\r\n str.append(count(n, 0)).append(\"\\n\");\r\n */\r\n // bottom up dp\r\n dp=new long[n+1][x+1];\r\n\r\n for(int i=0;i<=x;i++){\r\n dp[1][i]=0;\r\n dp[0][i]=1;\r\n }\r\n\r\n for(int i=2;i<=n;i++){\r\n for(int j=x-1;j>=0;j--){\r\n int cost = Math.min(x, j+i-1);\r\n // Transition from dp[i][j] to dp[k][cost]\r\n long ans=0;\r\n for(int k=0;k<=i;k++){\r\n ans=mod_add(ans, mod_mul(comb[i][i-k], mod_mul(pow(cost-j, i-k), dp[k][cost])));\r\n }\r\n dp[i][j]=ans;\r\n }\r\n }\r\n str.append(dp[n][0]).append(\"\\n\");\r\n }\r\n \r\n public static void main(String[] args) throws java.lang.Exception {\r\n boolean lenv=false;\r\n int te=1;\r\n if(lenv){\r\n bf = new BufferedReader(\r\n new FileReader(\"input.txt\"));\r\n pw=new PrintWriter(new\r\n BufferedWriter(new FileWriter(\"output.txt\")));\r\n }else{\r\n bf = new BufferedReader(new InputStreamReader(System.in));\r\n pw = new PrintWriter(new OutputStreamWriter(System.out));\r\n }\r\n \r\n // int q1 = Integer.parseInt(bf.readLine().trim());\r\n // for(te=1;te<=q1;te++) {\r\n String s[]=bf.readLine().trim().split(\"\\\\s+\");\r\n n=Integer.parseInt(s[0]);\r\n x=Integer.parseInt(s[1]);\r\n solve(te);\r\n // }\r\n pw.print(str);\r\n pw.flush();\r\n // System.out.println(str);\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8637e3a0a4d090f2fbb854baa5110744", "src_uid": "1908d1c8c6b122a4c6633a7af094f17f", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class A {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int num = in.nextInt();\n in.nextLine();\n int[] arr = new int[num];\n for (int i = 0; i < num; i++) {\n arr[i] = in.nextInt();\n }\n if (num % 2 == 1 && arr[0] % 2 == 1 && arr[num - 1] % 2) {\n System.out.println(\"Yes\");\n } else {\n System.out.println(\"No\");\n }\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1f1f7cd68c2a2ac961ccfef1e33d3b09", "src_uid": "2b8c2deb5d7e49e8e3ededabfd4427db", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Kitchen{\n \n public static void main(String[] args)\n {\n Scanner sc=new Scanner(System.in);\n int r=sc.nextInt();\n int k=sc.nextInt();\n HashMap h=new HashMap<>();\n int max=1;\n for(int i=0;imax)\n max=x;\n }\n else\n {\n h.put(a,1);\n }\n }\n while(max%k!=0)\n {\n max++;\n }\n int c=0;\n for(int g:h.keySet())\n {\n int y=h.get(g);\n c=c+(max-y);\n }\n System.out.println(c);\n \n \n }\n \n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "95800d023d41bc2af5dce0b21b57e2d8", "src_uid": "c03ff0bc6a8c4ce5372194e8ea18527f", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class A {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int grains = sc.nextInt();\n int m = sc.nextInt();\n int n = grains;\n int days = 0;\n int s = 0;\n while(n!=0) {\n days++;\n s++;\n n+=m;\n if(n>=grains) {\n n = grains;\n }\n n -= sp;\n if(n<=0) {\n break;\n }\n }\n System.out.println(days);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ce3e5330817d4c360876b029122e98c9", "src_uid": "3b585ea852ffc41034ef6804b6aebbd8", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import org.jetbrains.annotations.NotNull;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.StringTokenizer;\n\npublic class CodeForces {\n private final static FastReader in = new FastReader();\n private final static PrintWriter out = new PrintWriter(System.out);\n\n static class ele implements Comparable {\n int a, b;\n\n public ele(int a, int b) {\n this.a = a;\n this.b = b;\n }\n\n @Override\n public int compareTo(@NotNull CodeForces.ele ele) {\n\n return ele.b - b;\n }\n }\n\n public static void main(String[] args) {\n int n = in.nextInt(), m = in.nextInt();\n ArrayList arrayList = new ArrayList<>(m);\n while (m-- > 0) {\n arrayList.add(new ele(in.nextInt(), in.nextInt()));\n }\n Collections.sort(arrayList);\n ele e;\n int res = 0;\n for (int i = 0; i < arrayList.size(); i++) {\n e = arrayList.get(i);\n if (e.a <= n) {\n n -= e.a;\n res += (e.a * e.b);\n } else if (e.a > n && n != 0) {\n res += (n * e.b);\n break;\n } else {\n break;\n }\n }\n out.println(res);\n out.flush();\n }\n\n private static final class FastReader {\n private static BufferedReader BF;\n private static StringTokenizer ST;\n\n public FastReader() {\n BF = new BufferedReader(new InputStreamReader(System.in));\n ST = null;\n }\n\n public final String next() {\n while (ST == null || !ST.hasMoreTokens()) {\n try {\n ST = new StringTokenizer(BF.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return ST.nextToken();\n }\n\n final int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6e874530f5c86c35c1ad937eeb393cda", "src_uid": "c052d85e402691b05e494b5283d62679", "difficulty": 900.0} {"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) throws IOException\n\t{\n\t\tint n =ni();\n\t\tlong a=1,b=1;\n\t\tlong ans=0;\n\t\tfor(i=1;i<=n;i++){\n\t\t\ta=(27*a)%mod;\n\t\t\tb=(7*b)%mod;\n\t\t\tans=(a-b+mod)%mod;\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n\tstatic int bsl(int arr[],int data,int start,int end){\n\t\tint mid=start+(end-start)/2;\n\t\tif(arr[mid]==data)\n\t\t\treturn mid;\n\t\tif(end-start==1)\n\t\t\treturn mid;\n\t\telse if(data > arr[mid])\n\t\t\treturn bsl(arr,data,mid,end);\n\t\telse\n\t\t\treturn bsl(arr,data,start,mid);\n\t}\n\tstatic final int 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\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 Random rn=new Random();\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 void sop(Object a){System.out.println(a);}\n\tstatic int ni(){return in.nextInt();}\n\tstatic int[] nia(int n){int a[]=new int[n];for(int i=0; i0)\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\tstatic class dyns\n\t{\n\t\tdyns(long le,long ri)\n\t\t{\n\t\t\tlb=le;\n\t\t\trb=ri;\n\t\t}\n\t\tdyns l,r;\n\t\tlong val,lb,rb;\n\t\tvoid set(long te)\n\t\t{\n\t\t\tval++;\n\t\t\tif(lb!=te||rb!=te)\n\t\t\t{\n\t\t\t\tif((lb+rb)/2>=te)\n\t\t\t\t{\n\t\t\t\t\tif(l==null)\n\t\t\t\t\t\tl=new dyns(lb, (lb+rb)/2);\n\t\t\t\t\tl.set(te);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif(r==null)\n\t\t\t\t\t\tr=new dyns(((lb+rb)/2)+1,rb);\n\t\t\t\t\tr.set(te);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tvoid reset(long a)\n\t\t{\n\t\t\tval--;\n\t\t\tif(val==0)\n\t\t\t{\n\t\t\t\tl=null;\n\t\t\t\tr=null;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif(lb!=a||rb!=a)\n\t\t\t{\n\t\t\t\tif((lb+rb)/2>=a)\n\t\t\t\t\tl.reset(a);\n\t\t\t\telse\n\t\t\t\t\tr.reset(a);\n\t\t\t}\n\t\t}\n\t\tlong count(long le, long ri)\n\t\t{\n\t\t\tif(le<=lb&&ri>=rb)\n\t\t\t\treturn val;\n\t\t\tif(le>rb)\n\t\t\t\treturn 0;\n\t\t\tif(rilMin){\n\t\t\tSystem.out.println(nome.toUpperCase());\n\t\t}else{\n\t\t\tSystem.out.println(nome.toLowerCase());\n\t\t}\n\t}\n}\n// 1506478776669\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f2988afb878605745370b5674ca7929d", "src_uid": "b432dfa66bae2b542342f0b42c0a2598", "difficulty": 800.0} {"lang": "Java 7", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.io.PrintStream;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Iain Watson-Smith\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\tint testCount = Integer.parseInt(in.next());\n\t\tfor (int i = 1; i <= testCount; i++)\n\t\t\tsolver.solve(i, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n class Pair\n {\n int x;\n int y;\n Pair(int x, int y) {\n this.x = Math.min(x, y);\n this.y = Math.max(x, y);\n }\n }\n int n = in.getInt();\n int [] A = new int[n];\n\n for(int i = 0; i < n; ++i){\n A[i] = in.getInt();\n }\n ArrayList scores = new ArrayList();\n for(int i = 1; i < n; ++i){\n int x = A[i - 1];\n int y = A[i];\n Pair p = new Pair(x, y);\n scores.add(p);\n }\n boolean ok = true;\n for(int i = 0; i < n - 1; ++i){\n for(int j = 0; j < n - 1; ++j)\n {\n if(j!=i){\n\n Pair a = scores.get(i);\n Pair b = scores.get(j);\n int x1 = a.x;\n int x2 = a.y;\n int x3 = b.x;\n int x4 = b.y;\n if(x1 < x3 && x3 < x2 && x2 < x4)\n {\n ok = false;\n }\n if(x3 < x1 && x1 < x4 && x4 < x2){\n ok = false;\n }\n }\n }\n }\n if(ok){\n System.out.println(\"no\");\n }\n else System.out.println(\"yes\");\n }\n}\n\nclass InputReader {\n\n BufferedReader reader;\n StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n tokenizer = null;\n }\n public String nextToken() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n public int getInt() {\n return Integer.parseInt(nextToken());\n }\n public long getLong() {\n return Long.parseLong(nextToken());\n }\n public double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1ab4b354bdfdecdd49338566aecd2962", "src_uid": "f1b6b81ebd49f31428fe57913dfc604d", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class given_len_sum_of_dig {\n\n\n\t\tpublic static void main(String[] args) {\n\t\t\tScanner scn = new Scanner(System.in);\n\t\t\tint n=scn.nextInt();\n\t\t\tint arr[]=new int[n];\n\t\t\tfor(int i=0;i 0) {\n long cur2 = cur;\n while (cur2 < left) {\n cur2 = cur2 * 3;\n }\n while (cur2 <=right) {\n res++;\n cur2 = cur2*3;\n }\n cur = cur / 2;\n }\n\n System.out.println(res);\n\n }\n public void run() {\n in = new Scanner();\n solve();\n\n }\n\n\n public static void main(String[] args)\n {\n new TaskC().run();\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d1d67fe422dfbf64687acf08c6c5bfb9", "src_uid": "05fac54ed2064b46338bb18f897a4411", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class QueueAtTheSchool {\n public static void main(String[] args) {\n\n Scanner scr = new Scanner(System.in);\n int gb=scr.nextInt();\n int t=scr.nextInt();\n String s= scr.next();\n char[] array = s.toCharArray();\n char temp;\n char []temparray=s.toCharArray() ;\n for (int i=0 ; i= a || n >= b) {\n\t\t\tif(glass < a) {\n\t\t\t\tif(n >= b) {\n\t\t\t\t\tlong num = (n-b-1)/glass;\n\t\t\t\t\tnum++;\n\t\t\t\t\tcount+= num;\n\t\t\t\t\tn-= num*glass;\n\t\t\t\t}\n\t\t\t\tif(n >= a) {\n\t\t\t\t\tlong num2 = n/a;\n\t\t\t\t\tcount+= num2;\n\t\t\t\t\tn-= num2*a;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif(n >= a) {\n\t\t\t\t\tlong num = n/a;\n\t\t\t\t\tcount+= num;\n\t\t\t\t\tn-= num*a;\n\t\t\t\t}\n\t\t\t\tif(n >= b) {\n\t\t\t\t\tlong num = (n-b+1)/glass;\n\t\t\t\t\tcount+= num;\n\t\t\t\t\tn-= num*glass;\n\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t}\n\t\tSystem.out.print(count);\n\t\t\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1c393413750a9f79f82ccc369e27f3ad", "src_uid": "0ee9abec69230eab25de51aef0984f8f", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class shell\n{\n public static void main(String args[])\n {\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n int x=sc.nextInt();\n int arr[]=new int(3);\n arr[x]=1;\n int temp=0;\n while(n!=0)\n {\n if(n%2==0)\n {\n temp=a[1];\n a[1]=a[2];\n a[2]=temp;\n }\n else\n {\n temp=a[1];\n a[1]=a[0];\n a[0]=temp; \n }\n n=n-1;\n }\n for(int i=0;i<3;i++)\n {\n if(arr[i]==1)\n System.out.println(i);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c9a41bf5fa87a4cb336596f8b1134fff", "src_uid": "7853e03d520cd71571a6079cdfc4c4b0", "difficulty": 1000.0} {"lang": "Java 11", "source_code": "/* package codechef; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.util.Arrays;\nimport java.math.BigInteger;\n \n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Main\n{\n public static void main (String[] args) throws java.lang.Exception\n {\n \tScanner in =new Scanner(System.in);\n\t\tint t=1,n,i,j,m=0,k,p=0,h,l,x,y,d;\n\t\tString s,st;\n\t\tfor(i=0;i0)\n\t\t {\n\t\t x=n%10;\n\t\t m+=x;\n\t\t n=n/10;\n\t\t }\n\t\t y=m%4;\n\t\t switch(y)\n\t\t {\n\t\t case 0: break;\n\t\t case 1: d+=3;\n\t\t case 2: d+=2;\n\t\t case 3: d+=1;\n\t\t }\n\t\t System.out.println(d);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d7bcecf753781cfaf3762fecf3039942", "src_uid": "bb6fb9516b2c55d1ee47a30d423562d7", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Alena{\n public static void main(String args[]){\n Scanner scan = new Scanner(System.in);\n \n int numLessons = scan.nextInt();\n \n int[] lessons = new int[numLessons];\n \n for(int i=0;i h * 2) return 1;\n double height45 = h + Math.sqrt(2) / 2.0 * r;\n //long side = (long) (Math.floor(height45 / (double)r));\n long side = (long) Math.floor((h - r/ 2.0) / (double) r);\n side++;\n long ret = side * 2;\n double lastcenter = side * r - r / 2.0;\n double x = h + r/2.0 - lastcenter;\n double diag = Math.sqrt(x * x + r * r / 4.0);\n if (diag >= r) {\n ret++;\n }\n return ret;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4bc58dfce1e35c8a3de429f3959c5b2a", "src_uid": "ae883bf16842c181ea4bd123dee12ef9", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.InputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.InputMismatchException;\nimport java.util.NoSuchElementException;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\n \npublic class Main{\n \nstatic PrintWriter out;\nstatic InputReader ir;\nstatic final int INF=Integer.MAX_VALUE;\nstatic final long LINF=Long.MAX_VALUE;\n \nstatic void solve(){\n char[][] map=ir.nextCharMap(8,8);\n int a;\n int b;\n outer:\n for(int i=0;i<8;i++){\n for(int j=0;j<8;j++){\n if(map[i][j]=='W'){\n a=i;\n break outer;\n }\n }\n }\n for(int i=0;i<8;i++){\n for(int j=0;j<8;j++){\n if(map[7-i][j]=='W'){\n b=i;\n break outer;\n }\n }\n }\n out.println(a<(7-b)?\"A\":\"B\");\n}\n\npublic static void main(String[] args) throws Exception{\n ir=new InputReader(System.in);\n out=new PrintWriter(System.out);\n solve();\n out.flush();\n}\n\nstatic class InputReader {\n private InputStream in;\n private byte[] buffer=new byte[1024];\n private int curbuf;\n private int lenbuf;\n\n public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}\n \n public boolean hasNextByte() {\n if(curbuf>=lenbuf){\n curbuf= 0;\n try{\n lenbuf=in.read(buffer);\n }catch(IOException e) {\n throw new InputMismatchException();\n }\n if(lenbuf<=0) return false;\n }\n return true;\n }\n\n private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}\n \n private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}\n \n private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}\n \n public boolean hasNext(){skip(); return hasNextByte();}\n \n public String next(){\n if(!hasNext()) throw new NoSuchElementException();\n StringBuilder sb=new StringBuilder();\n int b=readByte();\n while(!isSpaceChar(b)){\n sb.appendCodePoint(b);\n b=readByte();\n }\n return sb.toString();\n }\n \n public int nextInt() {\n if(!hasNext()) throw new NoSuchElementException();\n int c=readByte();\n while (isSpaceChar(c)) c=readByte();\n boolean minus=false;\n if (c=='-') {\n minus=true;\n c=readByte();\n }\n int res=0;\n do{\n if(c<'0'||c>'9') throw new InputMismatchException();\n res=res*10+c-'0';\n c=readByte();\n }while(!isSpaceChar(c));\n return (minus)?-res:res;\n }\n \n public long nextLong() {\n if(!hasNext()) throw new NoSuchElementException();\n int c=readByte();\n while (isSpaceChar(c)) c=readByte();\n boolean minus=false;\n if (c=='-') {\n minus=true;\n c=readByte();\n }\n long res = 0;\n do{\n if(c<'0'||c>'9') throw new InputMismatchException();\n res=res*10+c-'0';\n c=readByte();\n }while(!isSpaceChar(c));\n return (minus)?-res:res;\n }\n\n public double nextDouble(){return Double.parseDouble(next());}\n\n public BigInteger nextBigInteger(){return new BigInteger(next());}\n\n public BigDecimal nextBigDecimal(){return new BigDecimal(next());}\n\n public int[] nextIntArray(int n){\n int[] a=new int[n];\n for(int i=0;i k || firstDiv == m && k != 1){\n out.println(\"Marsel\");\n }\n else{\n if ((n == 1){\n out.println(\"Timur\");\n }\n else{\n out.println(\"Marsel\");\n }\n }\n out.flush();\n out.close();\n } catch (Throwable e) {\n System.err.println(\"Exception from runtime....\");\n handleException(e);\n }\n }\n\n\n public static void main(String[] args) {\n try {\n new Main().start();\n } catch (Throwable e) {\n handleException(e);\n }\n }\n\n private static void handleException(Throwable e) {\n System.err.println(e.getMessage());\n System.err.println(e.getStackTrace());\n }\n\n private BufferedReader in;\n private PrintWriter out;\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "361c74f0931c4cbbe39fcfb2c64faa45", "src_uid": "4a3767011ddac874efa021fff7c94432", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\n\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\npublic class Main {\n private static final long MOD=(long)(1e9)+7L;\n private static long dp[][]=new long[6000*3000][2];\n private static int n;\n private static int cnt=0;\n private static int fid[][]=new int[3000][3000];\n private static int lson[]=new int[30000];\n private static int rson[]=new int[30000];\n private static int val[]=new int[30000];\n private static int DFS(int u,int ln){\n System.out.println(u+\" \"+ln);\n int idn=0;\n long son=0;\n long blk=0;\n if(fid[u][ln]!=0){\n return fid[u][ln];\n }\n idn=++cnt;\n dp[cnt][1]=1;\n dp[cnt][0]=0;\n long lok=0,lno=0;\n long rok=0,rno=0;\n int xson;\n if(lnu-ln){\n\n xson=DFS(u+1,ln);\n rok=dp[xson][1];rno=dp[xson][0];\n blk+=dp[xson][0];\n }\n son=Math.max(Math.max(lok+rno,lno+rok),rno+lno);\n dp[idn][0]+=son;\n dp[idn][1]+=blk;\n dp[idn][0]%=MOD;\n dp[idn][1]%=MOD;\n // System.out.println(u+\" \"+ln+\" \"+idn+\" \"+dp[idn][0]+\" \"+dp[idn][1]+\" son:\"+son+\" blk\"+blk);\n fid[u][ln]=idn;\n return idn;\n }\n public static void main(String[] args)throws IOException{\n //\n Reader.init(System.in);\n n=Reader.nextInt();\n cnt=0;\n DFS(0,0);\n System.out.print(dp[1][0]);\n }\n\n}\n//\nclass Reader{\n static BufferedReader reader;\n static StringTokenizer tokenizer;\n\n static void init(InputStream input){\n reader=new BufferedReader(new InputStreamReader(input));\n tokenizer=new StringTokenizer(\"\");\n }\n //\n static String next()throws IOException{\n while(!tokenizer.hasMoreTokens()){\n tokenizer=new StringTokenizer(reader.readLine());\n }\n return tokenizer.nextToken();\n }\n //\n static int nextInt() throws IOException {return Integer.parseInt(next());}\n static double nextDouble()throws IOException{return Double.parseDouble(next());}\n static long nextLong()throws IOException{return Long.parseLong(next());}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8fa34352e0bac2dd6bafb39bb4c22ea7", "src_uid": "8218255989e5eab73ac7107072c3b2af", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main \n{\n public static void main(String[] args) \n { \n TaskA solver = new TaskA();\n TaskA.solve(); \n }\n}\n\nclass TaskA \n{ \n public static void solve()\n {\n Scanner input = new Scanner(System.in);\n int n = input.nextInt();\n String s = input.next();\n \n int s1 = sum(s,0,n/2);\n int s2 = sum(s,n/2,n)\n \n if(s1 != -1 && s1 == s2 )\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n }\n public static int sum(String s, int b, int e)\n {\n int sum = 0;\n for(int i = b; i < e; ++i)\n {\n if(s.charAt(i) != '4' && s.charAt(i) != '7')\n {\n return -1;\n }\n sum += s.charAt(i) - '0'; \n }\n return sum;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "48e91d7d529c119dad884536f7d16cde", "src_uid": "435b6d48f99d90caab828049a2c9e2a7", "difficulty": 800.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n\npublic class Codeforces548C {\n\tpublic static int numStepsToGetTo(int[] heights, int start, int end)\n\t{\n\t\tint steps = 0;\n\t\tint initial = start;\n\t\tboolean[] visited = new boolean[heights.length];\n\t\twhile(initial != end && !visited[initial])\n\t\t{\n\t\t\tsteps++;\n\t\t\tvisited[initial] = true;\n\t\t\tinitial = heights[initial];\n\t\t}\n\t\tif(initial != end)\n\t\t\treturn -1;\n\t\telse\n\t\t\treturn steps;\n\t}\n\tpublic static void main(String[] args) {\n\t\ttry\n\t\t{\n\t\t\tBufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tint m = Integer.parseInt(f.readLine());\n\t\t\tStringTokenizer st = new StringTokenizer(f.readLine());\n\t\t\tlong h1 = Integer.parseInt(st.nextToken());\n\t\t\tlong a1 = Integer.parseInt(st.nextToken());\n\t\t\tst = new StringTokenizer(f.readLine());\n\t\t\tlong x1 = Integer.parseInt(st.nextToken());\n\t\t\tlong y1 = Integer.parseInt(st.nextToken());\n\t\t\tst = new StringTokenizer(f.readLine());\n\t\t\tlong h2 = Integer.parseInt(st.nextToken());\n\t\t\tlong a2 = Integer.parseInt(st.nextToken());\n\t\t\tst = new StringTokenizer(f.readLine());\n\t\t\tlong x2 = Integer.parseInt(st.nextToken());\n\t\t\tlong y2 = Integer.parseInt(st.nextToken());\n\t\t\tf.close();\n\t\t\t\n\t\t\tlong[] height1 = new long[m];\n\t\t\tfor(int i = 0; i < m; i++)\n\t\t\t\theight1[i] = (x1*i + y1)%m;\n\t\t\tlong[] height2 = new long[m];\n\t\t\tfor(int i = 0; i < m; i++)\n\t\t\t\theight2[i] = (x2*i + y2)%m;\n\t\t\t\n\t\t\t/*boolean containsA1 = false;\n\t\t\tfor(int i = 0; i < m; i++)\n\t\t\t{\n\t\t\t\tif(height1[i] == a1)\n\t\t\t\t{\n\t\t\t\t\tcontainsA1 = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tboolean containsA2 = false;\n\t\t\tfor(int i = 0; i < m; i++)\n\t\t\t{\n\t\t\t\tif(height2[i] == a2)\n\t\t\t\t{\n\t\t\t\t\tcontainsA2 = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif(!containsA1 || !containsA2)\n\t\t\t\tSystem.out.println(-1);\n\t\t\telse\n\t\t\t{*/\n\t\t\t\tint h1ToA1 = numStepsToGetTo(height1, h1, a1);\n\t\t\t\tint h2ToA2 = numStepsToGetTo(height2, h2, a2);\n\t\t\t\tif(h1ToA1 == -1 || h2ToA2 == -1)\n\t\t\t\t\tSystem.out.println(-1);\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif(h1ToA1 == h2ToA2)\n\t\t\t\t\t\tSystem.out.println(h1ToA1);\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tint period1 = 1 + numStepsToGetTo(height1, height1[a1], a1);\n\t\t\t\t\t\tint period2 = 1 + numStepsToGetTo(height2, height2[a2], a2);\n\t\t\t\t\t\t/*if(period1 == 0 && period2 == 0)\n\t\t\t\t\t\t\tSystem.out.println(-1);\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t/*if(period1 == 0)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tif(h1ToA1%period2 == h2ToA2)\n\t\t\t\t\t\t\t\t\tSystem.out.println(h1ToA1);\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\tSystem.out.println(-1);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse if(period2 == 0)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tif(h2ToA2%period1 == h1ToA1)\n\t\t\t\t\t\t\t\t\tSystem.out.println(h2ToA2);\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\tSystem.out.println(-1);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t{*/\n\t\t\t\t\t\t\t\tlong result = h1ToA1;\n\t\t\t\t\t\t\t\tboolean found = false;\n\t\t\t\t\t\t\t\tfor(int i = 0; i < period2; i++)\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tif(result%period2 == h2ToA2)\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tfound = true;\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tresult += period1;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif(found)\n\t\t\t\t\t\t\t\t\tSystem.out.println(result);\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\tSystem.out.println(-1);\n\t\t\t\t\t\t\t//}\n\t\t\t\t\t\t//}\n\t\t\t\t\t}\t\n\t\t\t\t}\n\t\t\t//}\n\t\t}\n\t\tcatch(IOException e)\n\t\t{\n\t\t\tSystem.out.println(e);\n\t\t}\n\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5cd5ac9583a3fe9c92de379f432eb327", "src_uid": "7225266f663699ff7e16b726cadfe9ee", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.math.BigInteger;\nimport java.util.*;\nimport java.io.*;\n\npublic class D {\n BufferedReader br;\n PrintWriter out;\n StringTokenizer stok;\n\n String nextToken() throws IOException {\n while (stok == null || !stok.hasMoreTokens()) {\n String s = br.readLine();\n if (s == null) {\n return null;\n }\n stok = new StringTokenizer(s);\n }\n return stok.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n char nextChar() throws IOException {\n return (char) (br.read());\n }\n\n String nextLine() throws IOException {\n return br.readLine();\n }\n\n private void solve() throws IOException {\n int n = nextInt();\n String s = nextToken();\n if (n <= 10)\n {\n BigInteger bigInteger = new BigInteger(s, n);\n out.println(bigInteger.toString());\n return;\n }\n\n ArrayList integers = new ArrayList<>();\n StringBuilder sb = new StringBuilder();\n char[] c = s.toCharArray();\n\n int i = s.length() - 1;\n while (i >= 0)\n {\n int j;\n for (j = i - 1; j >= 0; j--) {\n int x = Integer.valueOf(s.substring(j, i + 1));\n if (x >= n) {\n do {\n j++;\n } while (j < i && s.charAt(j) == '0');\n break;\n }\n }\n j = Math.max(j, 0);\n integers.add(Integer.valueOf(s.substring(j, i + 1)));\n i = j - 1;\n }\n\n long ans = 0;\n for (int q = integers.size() - 1; q >= 0; q--) {\n ans = ans * n + integers.get(q);\n// System.err.println(integers.get(q));\n }\n out.println(ans);\n }\n\n void run() throws IOException {\n // br = new BufferedReader(new FileReader(\"input.txt\"));\n // out = new PrintWriter(\"output.txt\");\n br = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n solve();\n br.close();\n out.close();\n }\n\n public static void main(String[] args) throws IOException {\n // Locale.setDefault(Locale.US);\n new D().run();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "16ae38f45a3e25c418c24e09ccd9b577", "src_uid": "be66399c558c96566a6bb0a63d2503e5", "difficulty": 2000.0} {"lang": "Java 11", "source_code": "public class Main {\n public static void main(String[] args) {\n var s = new java.util.Scanner(System.in);\n var hhmm = s.nextLine().split(\":\");\n int hh = hhmm[0];\n int mm = hhmm[1];\n System.out.println((hh%12)*30+mm/2 + \" \" + mm*6);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "547bb0dce66ad5e3a303ca2c699d68f5", "src_uid": "175dc0bdb5c9513feb49be6644d0d150", "difficulty": 1200.0} {"lang": "Java 11", "source_code": "public class MyPractise1 {\r\n private static String solve(int sum,HashSet hs,int data,String str){\r\n if(data==10){\r\n if(sum==0)\r\n return str;\r\n return \"1231231231\";\r\n }\r\n String str1=solve(sum,hs,data+1,str);\r\n String str2=\"111111111111\";\r\n if(sum-data>=0) {\r\n hs.add(data);\r\n str2 = solve(sum - data, hs,data+1,str+Integer.toString(data));\r\n hs.remove(data);\r\n }\r\n if(str1.length() hs=new HashSet<>();\r\n System.out.println( solve(sum,hs,1,\"\"));\r\n}\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b0c989b4312e205dee25070a9de383b2", "src_uid": "fe126aaa93acaca8c8559bc9e7e27b9f", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import static java.lang.Math.ceil;\nimport static java.lang.Math.sqrt;\nimport java.util.*;\npublic class Main{\n public static void main(String[] args) {\n // TODO Auto-generated method stub\n Scanner input=new Scanner(System.in);\n int n=input.nextInt();\n n=(int) ceil(sqrt(n)*2);\n System.out.println(m);\n } \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "665dfafabfce00c5dd2306ecbb38570f", "src_uid": "eb8212aec951f8f69b084446da73eaf7", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import com.sun.xml.internal.fastinfoset.util.CharArray;\n\nimport java.util.Scanner;\n\n/**\n * Created by Samsung900 on 30.04.2014.\n */\npublic class Main {\n public static void main(String[] args) {\n final Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n char[] s = sc.next().toCharArray();\n int x = 0;\n for (char ch:s)\n if (ch == 'x')\n ++x;\n System.out.println(Math.abs(x-n/2));\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c738a1eda212348af426e383401e8b3f", "src_uid": "fa6311c72d90d8363d97854b903f849d", "difficulty": 900.0} {"lang": "Java 8", "source_code": "public class Solution {\r\n \r\n public static void main(String[] args) {\r\n Scanner scan = new Scanner(System.in);\r\n int t = scan.nextInt();\r\n for (int k = 0; k < t; k++) {\r\n int keyNumberInHand = scan.nextInt();\r\n \r\n int[] keys = new int[3];\r\n \r\n \r\n for (int i = 0; i < keys.length; i++) {\r\n keys[i] = scan.nextInt();\r\n }\r\n \r\n System.out.println(canOpenAllDoors(key, keys));\r\n }\r\n }\r\n \r\n private static String canOpenAllDoors(int key, int[] keys) {\r\n int count = 0;\r\n for (int i = 0; i < keys.length; i++) {\r\n if (keys[key] == 0 && count != 3) {\r\n return \"FALSE\";\r\n }\r\n }\r\n \r\n return \"TRUE\";\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c566b7b6249440c1ff62ff4c00299d87", "src_uid": "5cd113a30bbbb93d8620a483d4da0349", "difficulty": 800.0} {"lang": "Java 8", "source_code": "\npublic class Main {\n\t public void solution(){\n\t\tScanner s= new Scanner(System.in);\n\t\tint number= s.nextInt(); \n\t\tint k= s.nextInt(); \n\t\tint sasha=0; \n\t\tint lena= 0; \n\t\twhile(number>=k)\n\t\t{\n\t\t\tsasha+=k;\n\t\t\tnumber-=k;\n\t\t\tif(numberlena)\n\t\t\tSystem.out.println(\"YES\");\n\t\telse\n\t\t\tSystem.out.println(\"NO\");\n\t }\n\n\t \n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e7dd14b18724d4c286a3d23e1dbaf70f", "src_uid": "05fd61dd0b1f50f154eec85d8cfaad50", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.lang.Math; \nimport java.io.*;\npublic class HelloWorld\n{\n \n public static void main(String[] args) throws IOException\n {\n BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));\n int n=Integer.parseInt(bf.readLine());\n PrintWriter pw=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n pw.write(Math.max(1,8*(Math.pow(n*2,0.5))));\n pw.flush(); \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "29103716333bba5d7ce24b3e36adfab3", "src_uid": "d87ce09acb8401e910ca6ef3529566f4", "difficulty": null} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Q1064A\n{\n public static void main(String[] args)\n {\n int a[],max=0;\n Scanner sc=new Scanner(System.in);\n a=new int[3]; \n for(int i=0;i<3;i++)\n {\n a[i]=sc.nextInt();\n }\n for(int i=0;i<3;i++)\n {\n if(a[i]>a[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]+1[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", "compilation_error": true, "code_uid": "73226e2482ea459b6450cf5944d3ca81", "src_uid": "3dc56bc08606a39dd9ca40a43c452f09", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n public static void main(String args[])throws Exception {\n new A().f();\n }\n int MOD = 1000000007;\n void f()throws Exception {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int dp[][] = new int[n+1][n+1];\n for(int ar[] : dp)\n Arrays.fill(ar, -1);\n for(int i = 1; i <= n; i++) {\n dp[1][i] = i;\n dp[i][1] = 1;\n }\n int x = recur(dp, n, n);\n System.out.println((x+x)%MOD-n);\n }\n int recur(int dp[][], int n, int x) {\n if(dp[n][x] == -1) {\n dp[n][x] = (recur(dp, n-1, x)%MOD + recur(dp, n, x-1)%MOD)%MOD;\n }\n return dp[n][x];\n }\n} ", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8a0f7ee9a6248ffa4a96d776687b5c7d", "src_uid": "13a9ffe5acaa79d97df88a069fc520b9", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import javax.lang.model.util.ElementScanner9;\nimport java.lang.reflect.Array;\nimport java.util.Scanner;\n\npublic class CielAndFlowers {\n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n int[] f = new int[3];\n for (int i = 0; i < 3; i++) {\n f[i] = s.nextInt();\n }\n solve(f);\n }\n\n public static void solve(int[] arr) {\n long sum = 0;\n for (int i = 0; i < arr.length; i++) {\n sum += arr[i];\n }\n\n if (sum % 3 == 0) {\n System.out.println(sum / 3);\n return;\n }\n\n sum = sum - sum % 3;\n\n System.out.println(sum / 3);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "480dac6aacaea830dc8db18d539add86", "src_uid": "acddc9b0db312b363910a84bd4f14d8e", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main{\n\n public static void main(String args[]){\n\n Scanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tboolean color = false;\n\t\tint[] arr = new int[n*m];\n\t\t\n\t\tfor (int i = 0; i < n*m; i++){\n\t\t\tarr[i] = in.next();\n\t\t\tif (arr[i].equals(\"C\") || arr[i].equals(\"M\") || arr[i].equals(\"Y\")){\n\t\t\t\tcolor = true;\n\t\t\t}\n\t\t}\n\t\tif (color){\n\t\t\tSystem.out.println(\"#Color\");\n\t\t}\n\t\telse{\n\t\t\tSystem.out.println(\"#Black&White\");\n\t\t}\n \n }\n}\n\n\n\n\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ae3d4b6e4ef4674ec52bb4fdc1ba5c17", "src_uid": "19c311c02380f9a73cd477e4fde27454", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class vviek{\n int lcm(int x,int y){\n int i=2;\n int c=1;\n while(x!=1 && y!=1){\n if(x%i==0 && y%i==0){\n x=x/i;\n y=y/i;\n c=c*i;\n }\n if(x%i==0){\n x=x/i;\n c=c*i;\n }\n if(x%i==0 && y%i==0){\n y=y/i;\n c=c*i;\n }\n if(x%i==0 && y%i==0){\n i++;\n }\n }\n return c;\n }\n public static void main(String args[]){\n Scanner sc=new Scanner(System.in);\n int t=sc.nextInt();\n while(t-->0){\n int n=sc.nextInt();\n int min=9999999999;\n if(n%2==0){\n for(int i=1;ifs)\n {\n System.out.println(\"Yes\");\n }\n } \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "669f0bcd36ec9b4f2210fa521dbc2ce1", "src_uid": "ab8a2070ea758d118b3c09ee165d9517", "difficulty": 800.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.StringTokenizer;\n\npublic class B {\n\tBufferedReader in;\n\tStringTokenizer str;\n\tPrintWriter out;\n\tString SK;\n\n\tString next() throws IOException {\n\t\twhile ((str == null) || (!str.hasMoreTokens())) {\n\t\t\tSK = in.readLine();\n\t\t\tif (SK == null)\n\t\t\t\treturn null;\n\t\t\tstr = new StringTokenizer(SK, \":\");\n\t\t}\n\t\treturn str.nextToken();\n\t};\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t};\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\n\t};\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(next());\n\t};\n\n\tint[] get(String S) {\n\t\tint n = S.length();\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (S.charAt(i) >= 'A')\n\t\t\t\ta[i] = 10 + S.charAt(i) - 'A';\n\t\t\telse\n\t\t\t\ta[i] = S.charAt(i) - '0';\n\t\t}\n\t\treturn a;\n\t}\n\n\tlong count(int[] a, int b) {\n\t\tlong res = 0;\n\t\tint n = a.length;\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tif (a[i] >= b)\n\t\t\t\treturn 500;\n\t\t\telse\n\t\t\t\tres = res * b + a[i];\n\t\treturn res;\n\t}\n\n\tvoid solve() throws IOException {\n\t\tint[] a = get(next());\n\t\tint[] b = get(next());\n\t\tboolean fl = true;\n\t\tfor (int i = 0; i < a.length - 1; i++)\n\t\t\tfl = fl && (a[i] == 0);\n\t\tfor (int i = 0; i < b.length - 1; i++)\n\t\t\tfl = fl && (b[i] == 0);\n\t\tif (fl) {\n\t\t\tout.println(\"-1\");\n\t\t\treturn;\n\t\t}\n\t\tint[] can = new int[100];\n\t\tint sum = 0;\n\t\tfor (int i = 0; i < 100; i++) {\n\t\t\tif (count(a, i) < 24 && count(b, i) < 60) {\n\t\t\t\tsum++;\n\t\t\t\tcan[i] = 1;\n\t\t\t}\n\t\t}\n\t\tif (sum == 0)\n\t\t\tout.println(sum);\n\t\telse\n\t\t\tfor (int i = 0; i < 100; i++)\n\t\t\t\tif (can[i] == 1)\n\t\t\t\t\tout.print(i + \" \");\n\t};\n\n\tvoid run() throws IOException {\n\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew B().run();\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1c7f4c0a596ec49c1b43fd938d831a84", "src_uid": "c02dfe5b8d9da2818a99c3afbe7a5293", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class MaxTable{\n\tpublic static void main(String[]args){\n\t\tScanner kbd = new Scanner(System.in);\n\t\tint tableSize = kbd.nextInt();\n\t\t\n\t\tif(tableSize == 1){\n\t\t System.out.println(1));\n\t\t \n\t\t}\n\t\t\n\t\tint table1[] = new int[tableSize];\n\t\tint table2[] = new int[tableSize];\n\t\t\n\t\tfor(int i = 0; i < tableSize; i++){\n\t\t\ttable1[i] = 1;\n\t\t}\n\t\n\t\tfor(int i = 0; i < tableSize -1; i++){\n\t\t\t\n\t\t\tfor(int j = 0; j < tableSize; j++){\n\t\t\t\tif(j == 0){\n\t\t\t\t\ttable2[j] = table1[j];\n\t\t\t\t} else {\n\t\t\t\t\ttable2[j] = table2[j-1] + table1[j];\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\ttable1[j] = table2[j];\n\t\t\t} \n\t\t\t\n\t\t}\n\t\t\n\t\t\n\t\tSystem.out.print(table2[tableSize-1]);\n\t\t\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "535228e9bbb20366b7382978024ed1aa", "src_uid": "2f650aae9dfeb02533149ced402b60dc", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class HappyNumbers {\n\n public static void main(String[] args) {\n Scanner sc=new Scanner(System.in);\n long b =b1;\n long a = sc.nextInt();\n for(int i=0;i<=a;i++)\n {\n b *=2;\n }\n System.out.println(b-2);\n \n }\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ab89ba5056588370c8163256ef872f00", "src_uid": "f1b43baa14d4c262ba616d892525dfde", "difficulty": 1100.0} {"lang": "Java 6", "source_code": "import java.util.ArrayList;\nimport java.util.List;\nimport java.util.Scanner;\n\npublic class A {\n\tpublic static void main(String[] args) throws Exception {\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n = scan.nextInt();\n\t\tint k = scan.nextInt();\n\t\tPrimeGen p = new PrimeGen(1000);\n\t\tList prims = new ArrayList();\n\t\tfor(int i = 2; i <= n; i++){\n\t\t\tif(p.isPrime(i)>0){\n\t\t\t\tprims.add(i);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(prims);\n\t\tCGen cgen = new CGen(prims.toArray(new Integer[0]));\n\t\twhile(cgen.hasNext()){\n\t\t\tList l = cgen.next();\n\t\t\tif(l.size() == k && sum(l) <= n){\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(\"NO\");\n\t}\n\t\n\tstatic int sum(List is) {\n\t\tint c = 0;\n\t\tfor (int i : is)\n\t\t\tc += i;\n\t\treturn c;\n\t}\n\t\n\tstatic class CGen {\n\t\tT[] s;\n\t\tint n = 0;\n\n\t\tCGen(T[] s) {\n\t\t\tthis.s = s;\n\t\t}\n\n\t\tboolean hasNext() {\n\t\t\treturn n < 1 << s.length;\n\t\t}\n\n\t\tjava.util.List next() {\n\t\t\tjava.util.List c = new java.util.ArrayList();\n\t\t\tfor (int i = 0; i < s.length; ++i)\n\t\t\t\tif ((n & (1 << i)) < 1)\n\t\t\t\t\tc.add(s[i]);\n\t\t\t++n;\n\t\t\treturn c;\n\t\t}\n\t}\n\n\tstatic class PrimeGen {\n\t\tpublic PrimeGen(int m) {\n\t\t\tm = (int) Math.sqrt(m);\n\t\t\tdouble max = 0;\n\t\t\tint r = 1;\n\t\t\tfor (int i = 0; i < 4;) {\n\t\t\t\tmax += r * m / Math.pow(Math.log1p(m), ++i);\n\t\t\t\tr *= i;\n\t\t\t}\n\t\t\tp = new int[(int) max];\n\t\t\tfor (int i = 0, e = 2; i < p.length; i++) {\n\t\t\t\tfor (; isPrime(e) < 1; e++)\n\t\t\t\t\t;\n\t\t\t\tp[i] = e++;\n\t\t\t}\n\t\t\tthis.m = p[p.length - 1];\n\t\t\tthis.m = this.m * this.m;\n\t\t}\n\n\t\tint isPrime(int n) {\n\t\t\tfor (int e : p)\n\t\t\t\tif (e < 1)\n\t\t\t\t\tbreak;\n\t\t\t\telse if (n != e && n % e < 1)\n\t\t\t\t\treturn 0;\n\t\t\treturn 1;\n\t\t}\n\n\t\tint max() {\n\t\t\treturn m;\n\t\t}\n\n\t\tint[] p;\n\t\tint m;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "786cf234c3ab3c141fd91c8f97862a1b", "src_uid": "afd2b818ed3e2a931da9d682f6ad660d", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n \n\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 c=in.nextInt();\n int d=in.nextInt();\n int f=1;\n \n \n \n\n \n if(Math.abs ((n/k)-Math.abs (d-t))<((n/k)*t) \n System.out.println(\"YES\");\n \n else \n System.out.println(\"NO\");\n \n \n \n in.close();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8bf42643a13d0028162c72e06d967f38", "src_uid": "32c866d3d394e269724b4930df5e4407", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "\n\npublic class first_acm_problem {\n\n public static void main(String[] args) {\n Scanner b = new Scanner(System.in);\n int n = b.nextInt(); \n int m= b.nextInt();\n int count=0;\n for (int i = n; i >=1; i/=m) {\n count+=i;\n }\n System.out.println(count);\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "30da9307a6663e06ca20ca1384ad403e", "src_uid": "42b25b7335ec01794fbb1d4086aa9dd0", "difficulty": 900.0} {"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 Rextester\n{\n public static void main (String[] args) throws java.lang.Exception\n {\n ArrayList lines = new ArrayList();\n Scanner sc = new Scanner(System.in);\n while(sc.hasNextLine()) {\n lines.add(sc.nextLine());\n }\n int[][] prior = {\n {3, 3, 4, 4, 3 ,3},\n {3, 3, 4, 4, 3, 3},\n {2, 2, 3, 3, 2, 2},\n {2, 2, 3, 3, 2, 2},\n {1, 1, 2, 2, 1, 1},\n {1, 1, 2, 2, 1, 1}\n };\n for(int i = 0; i < 6; i++) {\n String s = lines.get(i);\n s = \"\" + s.charAt(0) + s.charAt(1) + s.charAt(3) + s.charAt(4) + s.charAt(6) + s.charAt(7);\n lines.add(s);\n }\n int x = 0, y = 0, mx = -1;\n for(int i = 0; i < 6; i++)\n {\n for(int j = 0; j < 6; j++)\n {\n if(lines.get(i).charAt(j) == '.' && prior[i][j] > mx)\n {\n mx = prior[i][j];\n x = i;\n y = j;\n }\n }\n }\n String s = lines.get(x);\n StringBuilder myName = new StringBuilder(s);\n myName.setCharAt(y, 'P');\n lines.set(x, myName.toString());\n for(int i = 0; i < 6; i++) {\n String ss = lines.get(i);\n ss = \"\" + ss.charAt(0) + ss.charAt(1) + \"-\" + ss.charAt(3) + ss.charAt(4) + \"-\" + ss.charAt(6) + ss.charAt(7);\n System.out.println(ss);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "546c2e3be090c66840b7a0b0d71656aa", "src_uid": "35503a2aeb18c8c1b3eda9de2c6ce33e", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main{\npublic static void main(String args[])\n{\n\tScanner sc = new Scanner(System.in);\n\tint n = sc.nextInt();\n\tint ans = 0;\n\tfor(int i=1;i<=n;i++)\n\t{\n\t\tint temp = n;\n\t\tif((temp--i)%i==0)\n\t\tans++;\n\t}\n\tSystem.out.println(ans);\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d668cacf258beb32f96025b91adcf8fd", "src_uid": "89f6c1659e5addbf909eddedb785d894", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import edu.princeton.cs.algs4.ST;\n\nimport java.io.IOException;\nimport java.util.Scanner;\n\npublic class Main {\n public static void main(String[] args) throws IOException {\n Scanner scanner = new Scanner(System.in);\n int x,y,z,t1,t2,t3;\n x = scanner.nextInt();\n y = scanner.nextInt();\n z = scanner.nextInt();\n t1 = scanner.nextInt();\n t2 = scanner.nextInt();\n t3 = scanner.nextInt();\n\n int st = 0;\n int el = 0;\n\n int floorCnt = Math.abs(x-y);\n st = floorCnt * t1;\n\n int elFrom = Math.abs(x-z);\n\n el = (elFrom + floorCnt)*t2 + 3*t3;\n\n if(el <= st)\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "72b89a933b2d9e17de1cc51d32f645c1", "src_uid": "05cffd59b28b9e026ca3203718b2e6ca", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class C {\n BufferedReader br;\n PrintWriter out;\n StringTokenizer stok;\n\n String nextToken() throws IOException {\n while (stok == null || !stok.hasMoreTokens()) {\n String s = br.readLine();\n if (s == null) {\n return null;\n }\n stok = new StringTokenizer(s);\n }\n return stok.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n char nextChar() throws IOException {\n return (char) (br.read());\n }\n\n String nextLine() throws IOException {\n return br.readLine();\n }\n\n long c;\n long h1;\n long h2;\n long w1;\n long w2;\n\n /* double f(double x) {\n double y = (c - w1 * x) / w2;\n return h1 * x + h2 * y;\n }*/\n class Point {\n long x, y;\n\n Point(long x, long y) {\n this.x = x;\n this.y = y;\n }\n }\n\n public long gcd(long a, long b) {\n if (b == 0) return a;\n long x = a % b;\n return gcd(b, x);\n }\n\n private void solve() throws IOException {\n final long MAXC = 1000000;\n long c = nextLong();\n long h1 = nextLong();\n long h2 = nextLong();\n long w1 = nextLong();\n long w2 = nextLong();\n if (h1 * 1. / w1 > h2 * 1. / w2) {\n long x = h1;\n long y = w1;\n h1 = h2;\n w1 = w2;\n h2 = x;\n w2 = y;\n }\n long y = (long) (c + .0) / (w2);\n long max = -1;\n for (long j = y - MAXC; j < y + MAXC; j++) {\n long i = (long) Math.floor((c - j * w2) * 1. / w1);\n if (j < 0 || i < 0) {\n continue;\n }\n max = Math.max(i * h1 + j * h2, max);\n }\n out.println(max);\n }\n\n\n void run() throws IOException {\n //br = new BufferedReader(new FileReader(\"input.txt\"));\n //out = new PrintWriter(\"output.txt\");\n br = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n solve();\n br.close();\n out.close();\n }\n\n public static void main(String[] args) throws IOException {\n // Locale.setDefault(Locale.US);\n new C().run();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "aa5ed8ef13953d3d5c5955121834285c", "src_uid": "eb052ca12ca293479992680581452399", "difficulty": 2000.0} {"lang": "Java 11", "source_code": "\r\n\r\nimport java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\n\r\npublic class phoenix_and_computers {\r\n\r\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\r\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n\t\tString[] st = br.readLine().split(\" \");\r\n\t\tint n = Integer.parseInt(st[0]);\r\n\t\tint m = Integer.parseInt(st[1]);\r\n\r\n\t\tlong[][] ncr = ncrcoll(405, 405, m);\r\n\t\tint[] p2 = new int[n + 1];\r\n\t\tp2[0] = 1;\r\n\t\tfor (int i = 1; i < p2.length; i++) {\r\n\t\t\tp2[i] = 2 * p2[i - 1] % m;\r\n\t\t}\r\n\r\n\t\tint[][] dp = new int[405][405];\r\n\t\tdp[0][0] = 1;\r\n\r\n\t\tfor (int i = 0; i < n; i++) {\r\n\t\t\tfor (int j = 0; j <= i; j++) {\r\n\t\t\t\tfor (int k = 1; i + k <= n; k++) {\r\n\t\t\t\t\tdp[i + k + 1][j + k] += ((dp[i][j] * p2[k - 1]) % m * ncr[j + k][k]);\r\n\t\t\t\t\tdp[i + k + 1][j + k] %= m;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tlong ans = 0;\r\n\t\tfor (int i = 0; i <= n; i++) {\r\n\t\t\tans = (ans + dp[n + 1][i]) % m;\r\n\t\t}\r\n\r\n\t\tSystem.out.println(ans);\r\n\t}\r\n\r\n\tstatic long[][] ncrcoll(int n, int k, int p) {\r\n\t\tlong[][] arr = new long[n + 1][k + 1];\r\n\t\tfor (int i = 1; i < arr.length; i++) {\r\n\t\t\tarr[i][0] = 1;\r\n\t\t}\r\n\t\tfor (int i = 1; i < arr.length; i++) {\r\n\t\t\tfor (int j = 1; j <= i && j < arr[0].length; j++) {\r\n\t\t\t\tif (i == 1 && j == 1) {\r\n\t\t\t\t\tarr[i][j] = 1;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tarr[i][j] = (arr[i - 1][j] + arr[i - 1][j - 1]) % (p);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn arr;\r\n\t}\r\n\r\n\tpublic static long xpown(long x, long n) {\r\n\t\tlong res = 1;\r\n\t\twhile (n > 0) {\r\n\t\t\tif (n % 2 != 0) {\r\n\t\t\t\tres = (res * x) % 1000000007;\r\n\t\t\t\tn--;\r\n\t\t\t} else {\r\n\t\t\t\tx = (x * x) % 1000000007;\r\n\t\t\t\tn = n / 2;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn res;\r\n\t}\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d4a7e143a97bd1eab7f22d70c273575d", "src_uid": "4f0e0d1deef0761a46b64de3eb98e774", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "/**\n * Created by Aminul on 9/4/2017.\n */\n\nimport java.io.*;\nimport java.util.*;\n\npublic class CF841C {\n public static int index;\n public static void main(String[] args)throws Exception {\n InputReader in = new InputReader(System.in);\n PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));\n int n = in.nextInt();\n P[] p = new P[n+1];\n double x[] = new double[6];\n\n for(int i = 1; i <= n; i++){\n for(int j = 1; j <= 5; j++){\n x[j] = in.nextDouble();\n }\n p[i] = new P(x);\n }\n\n ArrayList ans = new ArrayList<>();\n \n for(int i = 1; i <= n; i++){\n boolean bol = true;\n for(int j = 1; j <= n; j++){\n if(j == i)continue;\n for(int k = 1; k <= n; k++){\n if(k == j || k == i) continue;\n\n double a = fixAng( getAngle( p[j].sub(p[i]), p[k].sub(p[i]) ) );\n if( a < 90){\n bol = false; break;\n }\n\n }\n if(!bol) break;\n }\n if(bol) ans.add(i);\n }\n\n pw.println(ans.size());\n for(int i : ans){\n pw.println(i);\n }\n\n pw.close();\n }\n\n static double getAngle(P a, P b){\n double dot = a.dot(b); //debug(dot);\n double av = a.abs(), bv = b.abs(); //debug(av, bv);\n if(av == 0) av = 1;\n if(bv == 0) bv = 1;\n\n double ang = Math.acos(dot / (av*bv));\n\n ang = ang*180/Math.PI;\n\n if(ang < 0){\n ang += 360;\n }\n\n return ang;\n\n }\n\n\n static double EPS = 1e-9;\n\n static class P {\n double x[];\n P(double y[]) {\n x = new double[6];\n for(int i = 1; i <= 5; i++){\n x[i] = y[i];\n }\n\n }\n\n P sub( P p){\n P s = new P(new double[]{0,0,0,0,0, 0});\n for(int i = 1; i <= 5; i++){\n s.x[i] = p.x[i] - x[i];\n }\n return s;\n }\n\n double dot(P p) {\n //return x * p.x + y * p.y;\n double dot = 0;\n for(int i = 1; i <= 5; i++){\n dot += x[i]*p.x[i];\n }\n return dot;\n }\n\n double abs() {\n return Math.sqrt(abs2());\n }\n double abs2() {\n double a = 0;\n for(int i = 1; i <= 5; i++){\n a += x[i]*x[i];\n }\n return a;\n }\n\n public String toString(){\n return x.toString();\n }\n\n\n }\n\n static void debug(Object...obj) {\n System.err.println(Arrays.deepToString(obj));\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n tokenizer = null;\n }\n\n //InputReader in = new InputReader(new FileReader(\"File_Name\"));\n public InputReader(FileReader file) {\n reader = new BufferedReader(file);\n tokenizer = null;\n }\n\n public String next() {\n\n try {\n while (tokenizer == null || !tokenizer.hasMoreTokens())\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n return null;\n }\n\n return tokenizer.nextToken();\n }\n\n public String nextLine() {\n String line = null;\n try {\n tokenizer = null;\n line = reader.readLine();\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n return line;\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n public boolean hasNext(){\n try {\n while (tokenizer == null || !tokenizer.hasMoreTokens())\n tokenizer = new StringTokenizer(reader.readLine());\n }\n catch (Exception e) {\n return false;\n }\n\n return true;\n\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a6a4d759bdf441e2a05fbdb86dbfa2d8", "src_uid": "c1cfe1f67217afd4c3c30a6327e0add9", "difficulty": 1700.0} {"lang": "Java 11", "source_code": "import java.util.Scanner;\r\n\r\npublic class Main\r\n{\r\n public static int hcf(int a , int b)\r\n {\r\n int i,temp=0;\r\n for(i = 1; i <= a || i <= b; i++) \r\n if( a%i == 0 && b%i == 0 )\r\n temp = i;\r\n return temp;\r\n }\r\n \r\n\t public static void main(String[] args) {\r\n\t Scanner sc = new Scanner(System.in);\r\n int t = sc.nextInt();\r\n int sol = 0;\r\n while(t!=0)\r\n {\r\n sol = 0;\r\n int k = sc.nextInt();\r\n if(k==100)\r\n {\r\n sol=1;\r\n \r\n }\r\n else\r\n {\r\n sol=hcf(k,100-k);\r\n if(sol==1)\r\n sol=k+(100-k);\r\n else\r\n sol=(k/sol)+((100-k)/sol);\r\n }\r\n System.out.println(sol);\r\n }\r\n }\r\n\r\n \r\n}(i = 1; i <= a || i <= b; i++) {\r\n if( a%i == 0 && b%i == 0 )\r\n hcf = i;\r\n return hcf;\r\n }\r\n \r\n \r\n public static void main(String args[])\r\n {\r\n Scanner sc = new Scanner(System.in);\r\n int t = sc.nextInt();\r\n int sol = 0;\r\n while(t!=0)\r\n {\r\n sol = 0;\r\n int k = sc.nextInt();\r\n if(k==100)\r\n sol=1;\r\n else\r\n {\r\n sol=hcf(k,100-k);\r\n if(sol==1)\r\n sol=k+(100-k);\r\n else\r\n sol=(k/sol)+((100-k)/sol);\r\n }\r\n System.out.println(sol);\r\n }\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4ffab08118a80c016812eeb82d6beed8", "src_uid": "19a2bcb727510c729efe442a13c2ff7c", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Solution{\n public static class pair{\n int x;\n int y;\n }\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 line=br.readLine();\n String[] strs=line.trim().split(\" \");\n int a=Integer.parseInt(strs[0]);\n int b=Integer.parseInt(strs[1]);\n int c=Integer.parseInt(strs[2]);\n ArrayList list=new ArrayList<>();\n for(int i=1;i<=81;i++){\n long val=(b*(long)Math.pow(i,a))+c;\n if(val>=(long)Math.pow(10,9))){\n continue;\n }\n String s=String.valueOf(val);\n int sum=0;\n for(int j=0;j0){\n list.add((int)val);\n }\n }\n System.out.println(list.size());\n for(int i=0;iInteger.MAX_VALUE){\n return -1;\n }\n return (int)ans;\n }\n public static long fact(int n){\n long ans=1;\n for(int i=1;i<=n;i++){\n ans*=i;\n }\n return ans;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9564e4aa730d7ce971923c6ea0034a49", "src_uid": "e477185b94f93006d7ae84c8f0817009", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "package 1230A;\n\npublic class 1230A{\n\n\n\tpublic static void main(String[] args) {\n\n System.out.println(\"YES\");\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bd7743700eed239917817097f322ec45", "src_uid": "5a623c49cf7effacfb58bc82f8eaff37", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class BookReadingNaiv{\n int c;\n int v0;\n int v1;\n int a;\n int l;\n BookReadingNaiv(){\n Scanner sc=new Scanner(System.in);\n c=sc.nextInt();\n v0=sc.nextInt();\n v1=sc.nextInt();\n a=sc.nextInt();\n l=sc.nextInt();\n }\n int calculateNumberOfDays(){\n int days=1;\n int remaining_pages=c-v0;\n int i=1;\n while(remaining_pages>0 && (v0+i*a)<=v1){\n remaining_pages=(remaining_pages-(v0+i*a-l));\n i++;\n days++;\n }\n days=(remaining_pages/(v1-l));\n if(remaining_pages%(v1-l)!=0){\n days++;\n }\n return days;\n }\n public static void main(String[] args) {\n System.out.print((new BookReading()).calculateNumberOfDays()); \n } \n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a8ae33e1893269c6a1a79f1afb04a6b8", "src_uid": "b743110117ce13e2090367fd038d3b50", "difficulty": 900.0} {"lang": "Java 8", "source_code": "public class NewMain12 {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n // TODO code application logic here\n Scanner s = new Scanner(System.in);\n int n = s.nextInt();\n int a = s.nextInt();\n int b = s.nextInt();\n\n int add = Math.abs(b);\n if (b > 0) {\n System.out.println((a + b) % n);\n } else if(b==0) {\n System.out.println(a);\n } else {\n System.out.println((a + (n - (add % n))) % n);\n }\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6c954cf22f1ff95bec0d2e4728fc343f", "src_uid": "cd0e90042a6aca647465f1d51e6dffc4", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class Solution\n{\n public static void main(String args[])\n {\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n int n=integer.parseInt(br.readLine());\n if((n%2)==0)\n System.out.println(\"Mahmoud\");\n else\n System.out.println(\"Ehab\")\n \n \n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c2d43fef12ea0e8fc6c78bef2e11b346", "src_uid": "5e74750f44142624e6da41d4b35beb9a", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Main{\n public static void main(String[] args){\n Scanner sc=new Scanner(System.in);\n while(sc.hasnext()){\n int[] num=new int[5];\n String[] s=sc.nextLine().split(\" \");\n for(int i=0;i<5;i++) num[i]=Integer.parseInt(s[i]);\n int min=num[0];\n min=Math.min(min,num[1]);\n min=Math.min(min,num[2]/2);\n min=Math.min(min,num[3]/7);\n min=Math.min(min,num[4]/4);\n System.out.println(min);\n }\n }\n}\n\t\t\t\t \t\t \t\t \t\t \t\t \t \t \t", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cb72795958ff4a90a5dde68d5d8cac5e", "src_uid": "f914f9b7884cc04b990c7800c6be7b10", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport static java.lang.Math.*;\n \npublic class Check2\n{\t\n\tstatic class InputReader\n\t{\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n\t\tprivate SpaceCharFilter filter;\n\t\t\n\t\tpublic InputReader(InputStream stream)\n\t\t{\n\t\t\tthis.stream = stream;\n\t\t}\n\t\t\n\t\tpublic int read()\n\t\t{\n\t\t\tif (numChars==-1) \n\t\t\t\tthrow new InputMismatchException();\n\t\t\t\n\t\t\tif (curChar >= numChars)\n\t\t\t{\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry \n\t\t\t\t{\n\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t}\n\t\t\t\tcatch (IOException e)\n\t\t\t\t{\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif(numChars <= 0)\t\t\t\t\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\t \n\t\tpublic String nextLine()\n\t\t{\n\t\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\t\tString str = \"\";\n try\n {\n str = br.readLine();\n }\n catch (IOException e)\n {\n e.printStackTrace();\n }\n return str;\n\t\t}\n\t\tpublic int nextInt()\n\t\t{\n\t\t\tint c = read();\n\t\t\t\n\t\t\twhile(isSpaceChar(c)) \n\t\t\t\tc = read();\n\t\t\t\n\t\t\tint sgn = 1;\n\t\t\t\n\t\t\tif (c == '-') \n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\t\n\t\t\tint res = 0;\n\t\t\tdo \n\t\t\t{\n\t\t\t\tif(c<'0'||c>'9') \n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\twhile (!isSpaceChar(c)); \n\t\t\t\n\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic long nextLong() \n\t\t{\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') \n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\t\n\t\t\tdo \n\t\t\t{\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\twhile (!isSpaceChar(c));\n\t\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic double nextDouble() \n\t\t{\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') \n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tdouble res = 0;\n\t\t\twhile (!isSpaceChar(c) && c != '.') \n\t\t\t{\n\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\treturn res * Math.pow(10, nextInt());\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tif (c == '.') \n\t\t\t{\n\t\t\t\tc = read();\n\t\t\t\tdouble m = 1;\n\t\t\t\twhile (!isSpaceChar(c)) \n\t\t\t\t{\n\t\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\t\treturn res * Math.pow(10, nextInt());\n\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\tm /= 10;\n\t\t\t\t\tres += (c - '0') * m;\n\t\t\t\t\tc = read();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic String readString() \n\t\t{\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo \n\t\t\t{\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} \n\t\t\twhile (!isSpaceChar(c));\n\t\t\t\n\t\t\treturn res.toString();\n\t\t}\n\t \n\t\tpublic boolean isSpaceChar(int c) \n\t\t{\n\t\t\tif (filter != null)\n\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\t \n\t\tpublic String next() \n\t\t{\n\t\t\treturn readString();\n\t\t}\n\t\t\n\t\tpublic interface SpaceCharFilter \n\t\t{\n\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t}\n \n\tstatic void add(HashMap map,StringBuilder elem)\n\t{\n\t\tif(!map.containsKey(elem))\n\t\t\tmap.put(elem,1L);\n\t\telse\n\t\t\tmap.put(elem,map.get(elem)+1);\n\t}\n\t\n\tstatic class Node implements Comparable\n\t{\n\t\tint i;\n\t\tString key;\n\t\tint freq;\n\t\t\n\t\tNode(int i,String key,int freq)\n\t\t{\n\t\t\tthis.i=i;\n\t\t\tthis.key=key;\n\t\t\tthis.freq=freq;\n\t\t}\n\t\t\n\t\tpublic int compareTo(Node node)\n\t\t{\n\t\t\tif(freq==node.freq)\n\t\t\t\treturn Integer.compare(i,node.i);\n\t\t\t\n\t\t\treturn Integer.compare(freq,node.freq);\n\t\t}\n\t}\n\t\n\tpublic static void main(String args[]) throws Exception\n\t{\n\t\tInputReader sc=new InputReader(System.in);\t\t\n\t\tPrintWriter w=new PrintWriter(System.out);\n\t\t\n\t\t\n\t\tint n=(int)(1e6+3);\n\t\t\n\t\tint ip[]=new int[n];\n\t\t\n\t\tfor(int i=2;i<(int)Math.sqrt(n);i++)\n\t\t{\n\t\t\tif(ip[i]==0)\n\t\t\t{\n\t\t\t\tfor(int j=i*i;j q = new LinkedList();\n\t\tq.add(sc.next());\n\t\tSet ans = new TreeSet();\n\t\twhile (!q.isEmpty()) {\n\t\t\tSet tset = new HashSet();\n\t\t\twhile (!q.isEmpty()) {\n\t\t\t\tStringBuilder b = new StringBuilder(q.remove());\n\t\t\t\tif (b.length() == 1)\n\t\t\t\t\tans.add(b.toString());\n\t\t\t\telse\n\t\t\t\t\tfor (int i = 0; i < b.length(); i++) {\n\t\t\t\t\t\tfor (int j = i + 1; j < b.length(); j++) {\n\t\t\t\t\t\t\tchar ci = b.charAt(i);\n\t\t\t\t\t\t\tchar cj = b.charAt(j);\n\t\t\t\t\t\t\tchar c = move(ci, cj);\n\t\t\t\t\t\t\tStringBuilder t = new StringBuilder(b.toString());\n\t\t\t\t\t\t\ttset.add(t.replace(i, i + 1, c + \"\")\n\t\t\t\t\t\t\t\t\t.replace(j, j + 1, \"\").toString());\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t}\n\t\t\tq.addAll(tset);\n\t\t}\n\n\t\tString o = \"\";\n\t\tfor (String t : ans)\n\t\t\to += t;\n\t\tout.println(o);\n\t\tout.close();\n\t}\n\n\n\tstatic String sort(String s) {\n\t\tList v = new ArrayList();\n\t\tfor (char c : s.toCharArray())\n\t\t\tv.add(c);\n\t\ts = \"\";\n\t\tCollections.sort(v);\n\t\tfor (char c : v)\n\t\t\ts += c;\n\t\treturn s;\n\t}\n\tstatic char move(char a, char b) {\n\n\t\tif (a == b)\n\t\t\treturn a;\n\n\t\tif (a == 'R' && b == 'G')\n\t\t\treturn 'B';\n\t\tif (a == 'R' && b == 'B')\n\t\t\treturn 'G';\n\n\t\tif (a == 'G' && b == 'R')\n\t\t\treturn 'B';\n\t\tif (a == 'G' && b == 'B')\n\t\t\treturn 'R';\n\n\t\tif (a == 'B' && b == 'R')\n\t\t\treturn 'G';\n\t\tif (a == 'B' && b == 'G')\n\t\t\treturn 'R';\n\t\treturn a;\n\t}\n\n\t// -----------PrintWriter for faster output---------------------------------\n\tpublic static PrintWriter out;\n\n\t// -----------MyScanner class for faster input----------\n\tpublic static class MyScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic MyScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreElements()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tString nextLine() {\n\t\t\tString str = \"\";\n\t\t\ttry {\n\t\t\t\tstr = br.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\t}\n\t// --------------------------------------------------------\n\n}\n\t", "lang_cluster": "Java", "compilation_error": false, "code_uid": "559a6fb0484caf447692d13fc3e6f6e7", "src_uid": "4cedd3b70d793bc8ed4a93fc5a827f8f", "difficulty": 1300.0} {"lang": "Java 7", "source_code": "//package bear_and_electrons;\n\nimport java.util.Collections;\nimport java.util.LinkedList;\nimport java.util.Scanner;\n\npublic class Bear_and_Elections {\n\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n = scan.nextInt();\n\t\tif (n < 2) {\n\t\t\tSystem.out.println(\"-1\");\n\t\t\tSystem.exit(0);\n\t\t}\n\t\tint votes[] = new int[n - 1];\n\t\tint votesLimak = scan.nextInt();\n\t\tint bribes = 0;\n\n\t\tLinkedList betterCandidats = new LinkedList();\n\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\tvotes[i] = scan.nextInt();\n\t\t\t// Steal from the best only Strategy\n\t\t\tif ((votesLimak + bribes) < votes[i]) {\n\t\t\t\tint diff = votes[i] - (votesLimak + bribes);\n\t\t\t\tbribes += diff / 2 + 1;\n\t\t\t}\n\t\t\tif (votesLimak < votes[i]) {\n\t\t\t\tbetterCandidats.add(votes[i]);\n\t\t\t}\n\t\t}\n\t\tif (bribes == 0) {\n\t\t\tSystem.out.println(bribes);\n\t\t\tSystem.exit(0);\n\t\t}\n\t\tCollections.sort(betterCandidats, new ReverseIntegerIterator());\n\t\tif (betterCandidats.size() < 2\n\t\t\t\t|| !(betterCandidats.getFirst().equals(betterCandidats.get(1)))) {\n\t\t\tSystem.out.println(bribes);\n\t\t\tSystem.exit(0);\n\t\t}\n\n\t\tint equalCandidats = 1;\n\t\twhile (equalCandidats < betterCandidats.size()\n\t\t\t\t&& betterCandidats.get(equalCandidats - 1).equals(\n\t\t\t\t\t\tbetterCandidats.get(equalCandidats))) {\n\t\t\tequalCandidats++;\n\t\t}\n\n\t\tint newBribes = 0;\n\t\tint stolenVotesPerPerson = 0;\n\t\twhile (votesLimak + newBribes <= betterCandidats.getFirst()\n\t\t\t\t- stolenVotesPerPerson) {\n\t\t\tstolenVotesPerPerson += 1;\n\t\t\tnewBribes += equalCandidats;\n\t\t}\n\n\t\tif (newBribes < bribes) {\n\t\t\tif (equalCandidats == betterCandidats.size()) { // no more better candidates except the first group\n\t\t\t\tSystem.out.println(newBribes);\n\t\t\t\tSystem.exit(0);\n\t\t\t} else {\n\t\t\t\tif (votesLimak + newBribes > betterCandidats.get(equalCandidats)) {\n\t\t\t\t\tSystem.out.println(newBribes);\n\t\t\t\t\tSystem.exit(0);\n\t\t\t } else {\n\t\t\t\t newBribes += (betterCandidats.get(equalCandidats) - (votesLimak + newBribes)) / 2 + 1;\n\t\t\t\t int countedCandidats = equalCandidats + 1;\n\t\t\t\t if (newBribes < bribes) {\n\t\t\t\t\t if (countedCandidats == betterCandidats.size()) { // no more better candidates except these\n\t\t\t\t\t\t\tSystem.out.println(newBribes);\n\t\t\t\t\t\t\tSystem.exit(0);\n\t\t\t\t\t\t}\n\t\t\t\t\t if (votesLimak + newBribes > betterCandidats.get(equalCandidats)) {\n\t\t\t\t\t\t\tSystem.out.println(newBribes);\n\t\t\t\t\t\t\tSystem.exit(0);\n\t\t\t\t\t }\n\t\t\t\t }\n\t\t\t }\n\t\t\t}\n\t\t}\n\n\t\tSystem.out.println(bribes);\n\t\tSystem.exit(0);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "526d7d28e24cfc197ad04688fbc2fe78", "src_uid": "aa8fabf7c817dfd3d585b96a07bb7f58", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class LiveDonNotNull\n{\npublic static void main(String[] args)\n{\nScanner sc = new Scanner(System.in);\nint a = sc.nextInt();\nString a1=\"\";\nfor(int i=0;i (b2 - a2) * (c1 - a1))\n\t\t\tout.out.println(\"LEFT\");\n\t\tif ((b1 - a1) * (c2 - a2) < (b2 - a2) * (c1 - a1))\n\t\t\tout.out.println(\"RIGHT\");\n\t\tout.close();\n\t\tsc.close();\n\t}\n}\n\nclass output{\n\tpublic PrintWriter out;\n\tpublic File temp;\n\tpublic output(OutputStream stream){\n\t\tout = new PrintWriter(stream); \n\t}\n\tpublic output(String filename){\n\t\ttemp = new File(filename);\n\t\ttry {\n\t\t\tout = new PrintWriter(temp); \n\t\t}\n\t\tcatch(FileNotFoundException e){\n\t\t\treturn;\n\t\t}\n\t}\n\tpublic void close(){\n\t\tout.close();\n\t}\n}\n\nclass scanner extends BufferedReader{\n\tpublic String now;\n\tpublic StringTokenizer st;\n\tpublic boolean have_st, eof;\n\tpublic scanner(String filename)throws Exception{\n\t\tsuper(new FileReader(filename));\n\t\thave_st = false;\n\t}\n\tpublic scanner(InputStream stream){\n\t\tsuper(new InputStreamReader(stream));\n\t\thave_st = false;\n\t}\n\t\n\tString nextToken(){\n\t\tif (eof) return null;\n\t\tString ret = null;\n\t\tfor (; ret == null && eof == false; ){\n\t\t\tif (st != null && st.hasMoreTokens()){\n\t\t\t\tret = st.nextToken();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\ttry{\n\t\t\t\tnow = readLine();\n\t\t\t\tst = new StringTokenizer(now);\n\t\t\t}\n\t\t\tcatch (IOException e){\n\t\t\t\teof = true;\n\t\t\t}\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tpublic int nextInt(){\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\t\n\tpublic long nextLong(){\n\t\treturn Long.parseLong(nextToken());\n\t}\n\tpublic double nextDouble(){\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\tpublic String nextString(){\n\t\treturn nextToken();\n\t}\n\t\n\tpublic void close() throws IOException{\n\t\tsuper.close();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "65f272bde1dfe75be14d7524a6344d84", "src_uid": "f6e132d1969863e9f28c87e5a44c2b69", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "public class TripForMeal {\n\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);;\n int n = Integer.parseInt(in.nextLine());\n int a = Integer.parseInt(in.nextLine());\n int b = Integer.parseInt(in.nextLine());\n int c = Integer.parseInt(in.nextLine());\n int current = 0;\n int counter = 0;\n n--;\n while(n>0){\n switch(current){\n case 0:\n if(ay) {\n\t\t\tq = y;\n\t\t\ty = x;\n\t\t\tx = q;\n\t\t}\n\t\tif(y>z){\n\t\t\tq = z;\n\t\t\tz = y;\n\t\t\ty = q;\n\t\t}\n\t\tif(x-1< k/3){\n\t\t\ta = x;\n\t\t\tk = k - x +1;\n\t\t\tif(y-1 < k/2){\n\t\t\t\tb = y;\n\t\t\t\tk = k - y + 1;\n\t\t\t\tif(z-1 < k)\n\t\t\t\t\tc = z;\n\t\t\t\telse\n\t\t\t\t\tc = k+1;\n\t\t\t} else{\n\t\t\t\tb = k/2 +1;\n\t\t\t\tc = (k+1)/2 +1;\n\t\t\t}\n\t\t}else{\n\t\t\ta = k/3 +1;\n\t\t\tb = (k+1)/3 +1;\n\t\t\tc = (k+2)/3 +1;\n\t\t}\n\t\tSystem.out.println(a*b*c);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0bcff6ddeaa908a869cdb1927e439fa0", "src_uid": "8787c5d46d7247d93d806264a8957639", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "public class B {\npublic static void main(String[] args) {\nScanner reader = new Scanner(System.in);\nint z = reader.nextInt();\nArrayList a = new ArrayList();\nfor (int i = 0; i < z; i++) {\na.add(reader.nextInt());\n}\n\nArrayList b = new ArrayList(arrayList);\nArrayList q = new ArrayList();\nArrayList w = new ArrayList();\n\nfor (int i = 1; i < z-1; i++) {\nb.remove(i);\nfor (int j = 0; j < b.size()-1 ; j++) {\nq.add(b.get(j+1) - b.get(j));\n}\nCollections.sort(q);\nw.add(q.get(q.size() - 1));\nq = new ArrayList();\nb = new ArrayList(a);\n}\nCollections.sort(w);\n\nSystem.out.println(w.get(0));\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "70a85eca560161eb5d9173bc7a5d8b17", "src_uid": "8a8013f960814040ac4bf229a0bd5437", "difficulty": 900.0} {"lang": "Java 8", "source_code": "// https://codeforces.com/contest/1174/submission/55043857 (rainboy)\nimport java.io.*;\nimport java.util.*;\n\npublic class CF1174E {\n\tstatic final int MD = 1000000007;\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tint n = Integer.parseInt(br.readLine());\n\t\tint[] aa = new int[n + 1];\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\taa[i] = i % 2 == 0 ? aa[i / 2] + 1 : 0;\n\t\tint k = 0;\n\t\twhile (1 << k + 1 <= n)\n\t\t\tk++;\n\t\tint[] cnt = new int[k + 1];\n\t\tint[] cnt3 = new int[k + 1];\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tint a = aa[i];\n\t\t\tcnt[a]++;\n\t\t\tif (i % 3 == 0)\n\t\t\t\tcnt3[a]++;\n\t\t}\n\t\tlong[] dp = new long[k + 1];\n\t\tlong[] dp_ = new long[k + 1];\n\t\tdp[k] = 1;\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tfor (int h = 0; h <= k; h++) {\n\t\t\t\tlong x = dp[h];\n\t\t\t\tif (x != 0) {\n\t\t\t\t\tif (h > 0)\n\t\t\t\t\t\tdp_[h - 1] = (dp_[h - 1] + x * cnt[h - 1]) % MD;\n\t\t\t\t\tdp_[h] = (dp_[h] + x * (n / (1 << h) - i)) % MD;\n\t\t\t\t}\n\t\t\t}\n\t\t\tlong[] tmp = dp; dp = dp_; dp_ = tmp;\n\t\t\tArrays.fill(dp_, 0);\n\t\t}\n\t\tlong ans = dp[0];\n\t\tif (3 << k - 1 <= n) {\n\t\t\tArrays.fill(dp, 0);\n\t\t\tlong[] dq = new long[k];\n\t\t\tlong[] dq_ = new long[k];\n\t\t\tdq[k - 1] = 1;\n\t\t\tfor (int i = 1; i < n; i++) {\n\t\t\t\tfor (int h = 0; h < k; h++) {\n\t\t\t\t\tlong x = dq[h];\n\t\t\t\t\tif (x != 0) {\n\t\t\t\t\t\tif (h > 0)\n\t\t\t\t\t\t\tdq_[h - 1] = (dq_[h - 1] + x * cnt3[h - 1]) % MD;\n\t\t\t\t\t\tdq_[h] = (dq_[h] + x * (n / (3 << h) - i)) % MD;\n\t\t\t\t\t\tdp_[h] = (dp_[h] + x * (n / (1 << h) - n / (3 << h))) % MD;\n\t\t\t\t\t}\n\t\t\t\t\tx = dp[h];\n\t\t\t\t\tif (x != 0) {\n\t\t\t\t\t\tif (h > 0)\n\t\t\t\t\t\t\tdp_[h - 1] = (dp_[h - 1] + x * cnt[h - 1]) % MD;\n\t\t\t\t\t\tdp_[h] = (dp_[h] + x * (n / (1 << h) - i)) % MD;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tlong[] tmp = dp; dp = dp_; dp_ = tmp; tmp = dq; dq = dq_; dq_ = tmp;\n\t\t\t\tArrays.fill(dp_, 0);\n\t\t\t\tArrays.fill(dq_, 0);\n\t\t\t}\n\t\t\tans = (ans + dp[0]) % MD;\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "eae53d6e5476fec167271bb050707aef", "src_uid": "b2d59b1279d891dba9372a52364bced2", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.util.HashSet;\nimport java.util.Set;\n\n/**\n * Created by leen on 6/26/16.\n */\npublic class _686C extends CodeForceBase {\n\n public static void main(String[] args) {\n int n = scan.nextInt();\n int m = scan.nextInt();\n int maxHour = n - 1;\n int maxMinutes = m - 1;\n\n int numHourDigits = 0;\n if(maxHour == 0)\n numHourDigits = 1;\n else {\n while (maxHour > 0) {\n numHourDigits++;\n maxHour /= 7;\n }\n }\n\n int numMinuteDigits = 0;\n if(maxMinutes == 0)\n numMinuteDigits = 1;\n else {\n while (maxMinutes > 0) {\n numMinuteDigits++;\n maxMinutes /= 7;\n }\n }\n\n if(numHourDigits + numMinuteDigits > 7) {\n System.out.println(0);\n return;\n }\n\n int count = 0;\n for(int i = 0; i < n * m; i++) {\n int hours = i / m;\n int minutes = i % m;\n if(!hasDuplicates(hours, minutes, numHourDigits, numMinuteDigits))\n count++;\n }\n\n System.out.println(count);\n\n }\n\n static boolean hasDuplicates(int hours, int minutes, int numHourDigits, int numMinuteDigits) {\n Set set = new HashSet(16);\n for(int i = 0; i < numHourDigits; i++) {\n int hourDigit = hours % 7;\n if(set.contains(hourDigit))\n return true;\n set.add(hourDigit);\n hours /= 7;\n }\n\n for(int j = 0; j < numMinuteDigits; j++) {\n int minuteDigit = minutes % 7;\n if(set.contains(minuteDigit))\n return true;\n set.add(minuteDigit);\n minutes /= 7;\n }\n\n return false;\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f81d1abf5f57281ab36617ea058fa1ad", "src_uid": "0930c75f57dd88a858ba7bb0f11f1b1c", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class 1136B\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\tint k=sc.nextInt();\n\t\t\n\n\t\tSystem.out.println(Math.min(3*n+k-1,4*n-k));\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "57c5c94165277b41583e98fdea32e917", "src_uid": "24b02afe8d86314ec5f75a00c72af514", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\npublic class FourSegments {\n\n\tstatic Integer x1, x2, y1, y2, x3, x4, y3, y4;\n\tstatic boolean valid;\n\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tint[] coordinates = new int[4];\n\t\tvalid = true;\n\t\t// scan the four sides\n\t\tfor (int i = 0; i < 4 && valid; i++) {\n\t\t\t// scan the two coordinates\n\t\t\tfor (int j = 0; j < 4; j++) {\n\t\t\t\tcoordinates[j] = scan.nextInt();\n\t\t\t}\n\t\t\tcheckValid(coordinates);\n\t\t}\n\t\tif (valid && positiveArea()) {\n\t\t\tSystem.out.println(\"YES\");\n\t\t} else {\n\t\t\tSystem.out.println(\"NO\");\n\t\t}\n\t}\n\n\tprivate static void checkValid(int[] coor) {\n\t\t// if same x coordinate vertical\n\t\tif (coor[0] == coor[2]) {\n\t\t\tif (x3 == null) {\n\t\t\t\tx3 = coor[0];\n\t\t\t} else {\n\t\t\t\tx4 = coor[0];\n\t\t\t}\n\t\t\tif (y1 == null && y2 == null) {\n\t\t\t\ty1 = Math.min(coor[1], coor[3]);\n\t\t\t\ty2 = Math.max(coor[1], coor[3]);\n\t\t\t} else {\n\t\t\t\tif (y1 != Math.min(coor[1], coor[3]) || y2 != Math.max(coor[1], coor[3])) {\n\t\t\t\t\tvalid = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// if same y coordinate horizontal\n\t\telse if (coor[1] == coor[3]) {\n\t\t\tif (y3 == null) {\n\t\t\t\ty3 = coor[1];\n\t\t\t} else {\n\t\t\t\ty4 = coor[1];\n\t\t\t}\n\t\t\tif (x1 == null && x2 == null) {\n\t\t\t\tx1 = Math.min(coor[0], coor[2]);\n\t\t\t\tx2 = Math.max(coor[0], coor[2]);\n\t\t\t} else {\n\t\t\t\tif (x1 != Math.min(coor[0], coor[2]) || x2 != Math.max(coor[0], coor[2])) {\n\t\t\t\t\tvalid = false;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tvalid = false; // not parallel to axis\n\t\t}\n\t}\n\n\tprivate static boolean positiveArea() {\n\t\tif (Math.min(x1, x2) == Math.min(x3, x4)) {\n\t\t\tif (Math.max(x1, x2) == Math.max(x3, x4)) {\n\t\t\t\tif (Math.min(y1, y2) == Math.min(y3, y4)) {\n\t\t\t\t\tif (Math.max(y1, y2) == Math.max(y3, y4)) {\n\t\t\t\t\t\treturn x4 != x3 && y3 != y4;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2501b09ccbfa42b4c57762c0a320c668", "src_uid": "ad105c08f63e9761fe90f69630628027", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "\nimport java.io.IOException;\n\n\npublic class AStudentDream {\n\tpublic static void main(String args[]) throws IOException\n\t{\n\t\tScanner sc = new Scanner(System.in);\n\t\tint ar = sc.nextInt();\n\t\tint al = sc.nextInt();\n\t\tint br = sc.nextInt();\n\t\tint bl = sc.nextInt();\n\t\tif (bl>=ar-1 && (ar-1)*2>=bl)\n\t\t\tSystem.out.println(\"YES\");\n\t\telse if (br>=al-1 && (al-1)*2>=br)\n\t\t\tSystem.out.println(\"YES\");\n\t\telse\n\t\t\tSystem.out.println(\"NO\");\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a608f90763ebac62193b316debeb20be", "src_uid": "36b7478e162be6e985613b2dad0974dd", "difficulty": 1300.0} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class Solutions{\n public static void main(String [] args){\n Scanner sc = new Scanner(System.in);\n long a = sc.nextInt();\n long b = sc.nextInt();\n long c = sc.nextInt();\n long d = sc.nextInt();\n long [] arr = new long[1000080];\n for(long i=a ; i<=b ; i++){\n arr[i+b]++;\n arr[i+c+1]--;\n }\n for(long i=1 ; i<=1000080 ; i++){\n arr[i] += arr[i-1];\n }\n for(long i=1000080 ; i<=1 ; i--){\n arr[i-1] += arr[i];\n }\n long ans = 0;\n for(long i=c ; i<=d ; i++){\n ans += arr[i+1];\n }\n System.out.println(ans);\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8038be1efc9ccc98c521d13e400f021d", "src_uid": "4f92791b9ec658829f667fcea1faee01", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Q3 {\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tlong n = in.nextInt();\n\t\tlong a = in.nextInt();\n\t\tlong b = in.nextInt();\n\t\tlong p = in.nextInt();\n\t\tlong q = in.nextInt();\n\n\t\tlong c = 0;\n\n\t\tif (p > q) {\n\t\t\tlong temp = a;\n\t\t\ta = b;\n\t\t\tb = temp;\n\t\t\ttemp = p;\n\t\t\tp = q;\n\t\t\tq = temp;\n\n\t\t}\n\t\tc = (n / b) * q;\n\t\tif (a != b) {\n\t\t\tif (a < b) {\n\t\t\t\tif (b % a != 0)\n\t\t\t\t\tc += (n / a - (n / (a * b))) * p;\n\t\t\t\telse\n\t\t\t\t\tc += (n / a - (n / a) / (b / a)) * p;\n\t\t\t} else {\n\t\t\t\tif (a % b != 0)\n\t\t\t\t\tc += (n / a - (n / (a * b))) * p;\n\t\t\t\telse\n\t\t\t\t\tc += 0;//(n / a - (n / a) / (a / b)) * p;\n\t\t\t}\n\t\t}\n\n\t\tSystem.out.println(c);\n\t\t\n\n\t\tin.close();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d12f5579842f4d7e7bc839514f733c85", "src_uid": "35d8a9f0d5b5ab22929ec050b55ec769", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class main\n{\n public static void main (String[] args)\n {\n Scanner s=new Scanner(System.in);\n int a1=s.nextInt();\n int b1=s.nextInt();\n int a2=s.nextInt();\n int b2=s.nextInt();\n int a3=s.nextInt();\n int b3=s.nextInt();\n int c=0;\n if((a2+a3)<=a1 && c==0)\n {\n if(max(b2,b3)<=b1)\n {\n c=1;\n System.out.println(\"YES\");\n }\n }\n if((a2+b3)<=a1 && c==0)\n {\n if(max(b2,a3)<=b1)\n {\n c=1;\n System.out.println(\"YES\");\n }\n }\n if((b2+a3)<=a1 && c==0)\n {\n if(max(a2,b3)<=b1)\n {\n c=1;\n System.out.println(\"YES\");\n }\n }\n if((b2+b3)<=a1 && c==0)\n {\n if(max(a2,a3)<=b1)\n {\n c=1;\n System.out.println(\"YES\");\n }\n }\n if((a2+a3)<=b1 && c==0)\n {\n if(max(b2,b3)<=a1)\n {\n c=1;\n System.out.println(\"YES\");\n }\n }\n if((a2+b3)<=b1 && c==0)\n {\n if(max(b2,a3)<=a1)\n {\n c=1;\n System.out.println(\"YES\");\n }\n }\n if((b2+a3)<=b1 && c==0)\n {\n if(max(a2,b3)<=a1)\n {\n c=1;\n System.out.println(\"YES\");\n }\n }\n if((b2+b3)<=b1 && c==0)\n {\n if(max(a2,a3)<=a1)\n {\n c=1;\n System.out.println(\"YES\");\n }\n } \n if(c==0)\n {\n System.out.println(\"NO\");\n }\n }\n \n public static int max(int a,int b)\n {\n if(a > b)\n returan a;\n else\n return b;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0f618d34304b1b01e3d92ea90ee58c59", "src_uid": "2ff30d9c4288390fd7b5b37715638ad9", "difficulty": 1200.0} {"lang": "Java 7", "source_code": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n\n//package codeforces;\n\nimport java.util.Scanner;\n\n/**\n *\n * @author \u0410\u0439\u0434\u043e\u0441\n */\npublic class Main{\n public static void main(String [] args){\n Scanner sc = new Scanner(System.in);\n \n long w = sc.nextLong();\n long m = sc.nextLong();\n long k = sc.nextLong();\n w/=k;\n \n w+= get(m-1);\n long m1=m+1;\n while(get(m1)<=w){\n m1++; \n }\n System.out.println(m1-m);\n }\n public static long get(long a){\n long t=1;\n long now=1;\n long ret =0;\n for(;;){\n if(now*10>a){ \n \n ret+=(a-now+1)*t;\n return ret;\n \n }\n ret+=now*9*t;\n now*=10;\n t++;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "51d89e530ca31acb36cef83a356adcf4", "src_uid": "8ef8a09e33d38a2d7f023316bc38b6ea", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.awt.geom.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class Main\n{\n\n public static void main(String[] args) throws Exception\n {\n long startTime = System.nanoTime();\n double n = in.nextInt();\n double k = in.nextInt();\n double red = 2*n;\n double green = 5*n;\n double blue = 8*n;\n double ans = Math.ceil(red/k) + Math.ceil(green/k) + Math.ceil(blue/k);\n out.println((long)ans);\n long endTime = System.nanoTime();\n err.println(\"Execution Time : +\" + (aendTime-startTime)/1000000 + \" ms\");\n exit(0);\n }\n\n static class InputReader\n {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble(){\n return Double.parseDouble(next());\n }\n }\n\n static void exit(int a)\n {\n out.close();\n err.close();\n System.exit(a);\n }\n\n static InputStream inputStream = System.in;\n static OutputStream outputStream = System.out;\n static OutputStream errStream = System.err;\n static InputReader in = new InputReader(inputStream);\n static PrintWriter out = new PrintWriter(outputStream);\n static PrintWriter err = new PrintWriter(errStream);\n static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4233ace5f924393418a8f3cfd97262f5", "src_uid": "d259a3a5c38af34b2a15d61157cc0a39", "difficulty": 800.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedInputStream;\nimport java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\tpublic static void main(String[] args) throws FileNotFoundException, IOException {\n\t\tInputReader in = new InputReader(new BufferedInputStream(System.in));\n\t\tPrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n\t\tTaskB solver = new TaskB();\n//\t\tlong t1 = System.currentTimeMillis();\n\t\tsolver.solve(1, in, out);\n\t\tout.flush();\n//\t\tlong t2 = System.currentTimeMillis();\n//\t\tSystem.err.println(t2 - t1);\n\t\tout.close();\n\n\t}\n}\n\nclass Pos implements Comparable {\n\tint x;\n\tint y;\n\tlong val;\n\n\tpublic Pos(int x, int y, long val) {\n\t\tthis.x = x;\n\t\tthis.y = y;\n\t\tthis.val = val;\n\t}\n\n\tpublic int compareTo(Pos p) {\n\t\tif (val == p.val) {\n\t\t\tif (x == p.x)\n\t\t\t\treturn Integer.compare(y, p.y);\n\t\t\treturn Integer.compare(x, p.x);\n\t\t}\n\t\treturn Long.compare(val, p.val);\n\t}\n\n}\n\nclass Pair implements Comparable {\n\tint fir;\n\tint sec;\n\n\tPair(int fir, int sec) {\n\t\tthis.fir = fir;\n\t\tthis.sec = sec;\n\t}\n\n\tpublic int compareTo(Pair p) {\n\t\treturn Integer.compare(sec, p.sec);\n\t}\n}\n\nclass TaskB {\n\n\tint INF = (int) 1e9;\n\tint id[];\n\tint sz[];\n\tint sup[];\n\n\tvoid solve(int testNumber, InputReader in, PrintWriter pw) throws IOException {\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tint x = in.nextInt();\n\t\tint y = in.nextInt();\n\t\tint vx = in.nextInt();\n\t\tint vy = in.nextInt();\n\n\t\tint c = vx * y - vy * x;\n\t\tint a = n * vy;\n\t\tint b = -m * vx;\n//\t\tSystem.err.println(a + \" \" + b + \" \" + c);\n\t\tlong tx = a;\n\t\tlong ty = b;\n\t\tlong xp = 1;\n\t\tlong xq = 0;\n\t\tlong yp = 0;\n\t\tlong yq = 1;\n\t\tif (tx < 0) {\n\t\t\ttx = -tx;\n\t\t\txp = -1;\n\t\t}\n\t\tif (ty < 0) {\n\t\t\tty = -ty;\n\t\t\tyq = -1;\n\t\t}\n\t\twhile (ty > 0) {\n\t\t\tlong by = tx / ty;\n\t\t\tlong t = tx - by * ty;\n\t\t\tlong tp = xp - by * yp;\n\t\t\tlong tq = xq - by * yq;\n\t\t\ttx = ty;\n\t\t\txp = yp;\n\t\t\txq = yq;\n\t\t\tty = t;\n\t\t\typ = tp;\n\t\t\tyq = tq;\n\t\t}\n\t\tif (c % tx != 0) {\n\t\t\tpw.println(-1);\n\t\t} else {\n\t\t\tlong p = xp;\n\t\t\tlong q = xq;\n\t\t\tlong z;\n\t\t\tif (b == 0) {\n\t\t\t\tz = -q / a;\n\t\t\t} else {\n\t\t\t\tz = p / b;\n\t\t\t}\n\t\t\tp -= z * b;\n\t\t\tq += z * a;\n\t\t\tp *= -c / tx;\n\t\t\tq *= -c / tx;\n//\t\t\tSystem.err.println(p + \" \" + q);\n\t\t\tlong gcd = gcd(p, q);\n\t\t\tlong k1 = gcd / b;\n\t\t\tk1++;\n\t\t\tlong k2 = gcd / a;\n\t\t\tk2++;\n\t\t\tp -= (k1 * (b / gcd));\n\t\t\tq -= (k2 * (a / gcd));\n\t\t\tif ((p & 1) == 0) {\n\t\t\t\tp = 0;\n\t\t\t} else {\n\t\t\t\tp = n;\n\t\t\t}\n\t\t\tif ((q & 1) == 0) {\n\t\t\t\tq = 0;\n\t\t\t} else {\n\t\t\t\tq = n;\n\t\t\t}\n\t\t\tpw.println(p + \" \" + q);\n\t\t}\n\t}\n\n\tlong gcd(long a, long b) {\n\t\tif (a == 0)\n\t\t\treturn b;\n\t\treturn gcd(b, a % b);\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cad182cc94783da24b57e15f2f1ba381", "src_uid": "6c4ddc688c5aab1432e7328d27c4d8ee", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class Main\n{\n\tstatic ArrayList adj=new ArrayList<>();\n public static void main(String args[])\n {\n Scanner sc=new Scanner(System.in);\n long l=sc.nextLong();\n\t\tlong r=sc.nextLong();\n\t\tdfs((long)4);\n\t\tdfs((long)7);\n\t\tadj.add((long)0);\n\t\tCollections.sort(adj);\n\t\tlong ans=0;\n\t\tfor( int i=1;i=r)\n\t\t\t{\n\t\t\t\tans+=adj.get(i)*(r-Math.max(adj.get(i-1),l-1));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif(adj.get(i)>=l)\n\t\t\t{\n\t\t\t\tans+=adj.get(i)*(adj.get(i)-Math.max(adj.get(i-1),l-1));\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t\t\t\n }\n\tpublic static void dfs(long x)\n\t{\n\t\tif(x>(long)4444444444)\n\t\t{\n\t\t\treturn;\n\t\t}\n\t\tadj.add(x);\n\t\tdfs(10*x+4);\n\t\tdfs(10*x+7);\n\t}\n\tpublic static boolean islucky(int ii)\n\t{\n\t\tString str=ii+\"\";\n\t\tfor( int i=0;i\n{\n\tpublic int compare(Pair a, Pair b)\n\t{\n\t\treturn (int)Long.compare(a.f, b.f);\n\t}\n}\nclass myComparator1 implements Comparator\n{\n\tpublic int compare(Pair a, Pair b)\n\t{\n\t\treturn (int)Integer.compare(a.s, b.s);\n\t}\n}\nclass Pair\n{\n\tlong f; int s;\n\tPair(long f, int s)\n\t{\n\t\tthis.f=f;\n\t\tthis.s=s;\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e7396763c12c074f47760d0722196566", "src_uid": "8a45fe8956d3ac9d501f4a13b55638dd", "difficulty": 1100.0} {"lang": "Java 6", "source_code": "import java.util.*;\n\npublic class A {\n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n int n = s.nextInt();\n \n if (n < 3) {\n System.out.println(\"-1\");\n return;\n }\n \n String result = \"\";\n while (n > 0) {\n result += n-- + \" \";\n }\n System.out.println(result.trim());\n }\n}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b46d196ec2829c8a89971e5d0376af9b", "src_uid": "fe8a0332119bd182a0a5b7758716317e", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\n\npublic class a {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\t//BufferedReader input = new BufferedReader(new FileReader(\"input.txt\")); \n\t\tBufferedReader input = new BufferedReader(new InputStreamReader(System.in));\n\t\tString s[] = input.readLine().split(\" \");\n\t\tint n = Integer.parseInt(s[0]);\n\t\tint bx = Integer.parseInt(s[1]);\n\t\tint [] x = new int[n];\n\t\tint sumX = 0;\n\t\ts = input.readLine().split(\" \");\n\t\tfor (int i = 0; i < s.length; i++) {\n\t\t\tx[i] = Integer.parseInt(s[i]);\n\t\t}\n\t\tfor (int i = 0; i < x.length; i++) {\n\t\t\tsumX += x[i] * (int) Math.pow(bx, (n-1)-i); \n\t\t}\n\n\t\t\n\t\t\n\t\ts= input.readLine().split(\" \");\n\t\tint m = Integer.parseInt(s[0]);\n\t\tint by = Integer.parseInt(s[1]);\n\t\tint [] y = new int[m];\n\t\tint sumY = 0;\n\t\ts = input.readLine().split(\" \");\n\t\tfor (int i = 0; i < s.length; i++) {\n\t\t\ty[i] = Integer.parseInt(s[i]);\n\t\t}\n\t\tfor (int i = 0; i < y.length; i++) {\n\t\t\tsumY += y[i] * (int) Math.pow(by, (m-1)-i); \n\t\t}\n\n\t\tif(sumX == sumY){\n\t\t\tSystem.out.println(\"=\");\n\t\t}else if(sumX > sumY){\n\t\t\tSystem.out.println(\">\");\n\t\t}else{\n\t\t\tSystem.out.println(\"<\");\n\t\t}\n\t\t\n\t\t\n\t\t//System.out.println(\"x:\"+ sumX);\t\t\n\t\t//System.out.println(\"y:\"+ sumY);\t\t\n\t\t\n\t\t\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cf705fe54f27d50a4919cc71584a5593", "src_uid": "d6ab5f75a7bee28f0af2bf168a0b2e67", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class HelloWorld{\n\n public static void main(String []args){\n Scanner sc=new Scanner(System.in);\n int a=sc.nextInt();\n int b=sc.nextInt();\n int c=sc.nextInt();\n int d=sc.nextInt();\n int k=Math.min(a,Math.min(c,d);\n int k1=Math.min(a-k,b);\n long sum=k*256;\n if(k1>0)\n sum+=(k1)*32;\n \n System.out.println(sum);\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "efddbb7f23ccbd017cd060f77a826c4d", "src_uid": "082b31cc156a7ba1e0a982f07ecc207e", "difficulty": 800.0} {"lang": "Java 8", "source_code": "// Working program with FastReader \nimport java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\n\n\npublic final class Main \n{ \n\tstatic class FastReader \n\t{ \n\t\tBufferedReader br; \n\t\tStringTokenizer st; \n\n\t\tpublic FastReader() \n\t\t{ \n\t\t\tbr = new BufferedReader(new\n\t\t\t\t\tInputStreamReader(System.in)); \n\t\t} \n\n\t\tString next() \n\t\t{ \n\t\t\twhile (st == null || !st.hasMoreElements()) \n\t\t\t{ \n\t\t\t\ttry\n\t\t\t\t{ \n\t\t\t\t\tst = new StringTokenizer(br.readLine()); \n\t\t\t\t} \n\t\t\t\tcatch (IOException e) \n\t\t\t\t{ \n\t\t\t\t\te.printStackTrace(); \n\t\t\t\t} \n\t\t\t} \n\t\t\treturn st.nextToken(); \n\t\t} \n\n\t\tint nextInt() \n\t\t{ \n\t\t\treturn Integer.parseInt(next()); \n\t\t} \n\n\t\tlong nextLong() \n\t\t{ \n\t\t\treturn Long.parseLong(next()); \n\t\t} \n\n\t\tdouble nextDouble() \n\t\t{ \n\t\t\treturn Double.parseDouble(next()); \n\t\t} \n\n\t\tString nextLine() \n\t\t{ \n\t\t\tString str = \"\"; \n\t\t\ttry\n\t\t\t{ \n\t\t\t\tstr = br.readLine(); \n\t\t\t} \n\t\t\tcatch (IOException e) \n\t\t\t{ \n\t\t\t\te.printStackTrace(); \n\t\t\t} \n\t\t\treturn str; \n\t\t} \n\t} \n\n\tstatic long expo(int a, int b)\n\t{\n\t\tlong res=1;\n\t\twhile(b>0)\n\t\t{\n\t\t\tif((b&1)==1)\n\t\t\tres*=a;\n\t\t\ta=a*a;\n\t\t\tb>>=1;\n\t\t}\n\t\t\n\t\treturn res;\n\t}\n\tpublic static void main(String[] args) \n\t{ \n\t\tFastReader s=new FastReader(); \n\t\tint n=sc.nextInt();\n\t\tint m=sc.nextInt();\n\t\t\n\t\tlong ex=expo(2,m);\n\t\tif(m < ex)\n\t\tSystem.out.println(m);\n\t\telse if(m==ex)\n\t\tSystem.out.println(\"0\");\n\t\telse\n\t\tSystem.out.println(m%ex);\n\t\t\n\t\n\n\t} \n} \n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "aeb7317d2fe22eccf2564b84d150ee1f", "src_uid": "c649052b549126e600691931b512022f", "difficulty": 900.0} {"lang": "Java 7", "source_code": "\nimport java.io.*;\nimport java.util.StringTokenizer;\n\npublic class Solution {\n\n void solve(InputReader in, PrintWriter out) {\n\n int r = in.nextInt();\n int g = in.nextInt();\n int h = 1;\n for ( ; h * (h + 1) / 2 <= r + g; h++){}\n h--;\n\n int mod = 1000000007;\n int[] d = new int[r + 1];\n d[0] = 1;\n long ans = 0;\n for (int i = 1; i <= h; ++i) {\n for (int j= r - i; j >= 0; --j) {\n \u0432[j + i] += d[j];\n if (d[j + i] >= mod) d[j + i] -= mod;\n }\n }\n for (int j = 0; j <= r; ++j) {\n if (h * (h + 1) / 2 - j <= g) ans += d[j];\n }\n out.println(ans % mod);\n }\n\n public static void main(String[] args) {\n InputReader in = new InputReader(System.in);\n PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n new Solution().solve(in, out);\n out.close();\n }\n}\n\nclass InputReader {\n BufferedReader reader;\n StringTokenizer st;\n\n InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 1 << 15);\n st = null;\n }\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7dbdb676ce03531f113a4027dfe262d4", "src_uid": "34b6286350e3531c1fbda6b0c184addc", "difficulty": 2000.0} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class Main()\n{\n public static void main(String args[])\n {\n printf(\"Is it rated?\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f11bb108417acc487a378c581d3684fb", "src_uid": "b6a30a725754a4b4daeb6e87986e28a4", "difficulty": null} {"lang": "Java 11", "source_code": "/* package codechef; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.util.Arrays;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Codechef\n{\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t Scanner in=new Scanner(System.in);\n\t long n,i,num,n1,m,r;\n\t n=in.nextLong();\n\t long j[]=new long[10];\n\t n1=n;\n\t for(i=1;i<=10;i++)\n\t {\n\t j[i-1]=1;\n\t m=n1%(int)Math.pow(10,i);\n\t num=n1-((m+1)%(int)((Math.pow(10,i))));\n\t while(num!=0)\n\t {\n\t r=num%10;\n\t j[i-1]*=r;\n\t num=num/10;\n\t }\n\t }\n\t Arrays.sort(j);\n\t System.out.println(j[9]);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "11af8767496233b512bcf1f359c124f2", "src_uid": "38690bd32e7d0b314f701f138ce19dfb", "difficulty": 1200.0} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class NewYear\n{\n public static void main(String[] args)\n {\n Scanner sc = new Scanner(System.in);\n String s = sc.next();\n int c = 0;\n char[] ch = s.toCharArray();\n \n for(int i=0;i\");\n }\n }\n*/\n\n @SuppressWarnings(\"unchecked\")\n public void run() throws Exception {\n int a = nextInt();\n int n = nextInt();\n long total = 0;\n\nlong s = new Date().getTime();\n HashMap hm = new HashMap();\n for (int p = 2; p <= MAX_P; p++) {\n int p2 = p * p;\n int kf = MAX_VALUE / p2;\n for (int k = kf; k >= 1; k--) {\n hm.put(k * p2, p);\n }\n }\n\n System.out.println(hm.size());\n// System.out.println(hm);\n System.out.println((new Date().getTime() - st));\n\n// println(total);\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 P172D().run();\n br.close();\n pw.close();\n }\n\n static BufferedReader br;\n static PrintWriter pw;\n StringTokenizer stok;\n\n String nextToken() throws IOException {\n while (stok == null || !stok.hasMoreTokens()) {\n String s = br.readLine();\n if (s == null) { return null; }\n stok = new StringTokenizer(s);\n }\n return stok.nextToken();\n }\n\n void print(byte b) { print(\"\" + b); }\n void print(int i) { print(\"\" + i); }\n void print(long l) { print(\"\" + l); }\n void print(double d) { print(\"\" + d); }\n void print(char c) { print(\"\" + c); }\n void print(Object o) {\n if (o instanceof int[]) { print(Arrays.toString((int [])o));\n } else if (o instanceof long[]) { print(Arrays.toString((long [])o));\n } else if (o instanceof char[]) { print(Arrays.toString((char [])o));\n } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));\n } else if (o instanceof short[]) { print(Arrays.toString((short [])o));\n } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));\n } else if (o instanceof float[]) { print(Arrays.toString((float [])o));\n } else if (o instanceof double[]) { print(Arrays.toString((double [])o));\n } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));\n } else { println(\"\" + o); }\n }\n void print(String s) { pw.print(s); }\n void println() { println(\"\"); }\n void println(byte b) { println(\"\" + b); }\n void println(int i) { println(\"\" + i); }\n void println(long l) { println(\"\" + l); }\n void println(double d) { println(\"\" + d); }\n void println(char c) { println(\"\" + c); }\n void println(Object o) { print(o); println(\"\"); }\n void println(String s) { pw.println(s); }\n int nextInt() throws IOException { return Integer.parseInt(nextToken()); }\n long nextLong() throws IOException { return Long.parseLong(nextToken()); }\n double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }\n char nextChar() throws IOException { return (char) (br.read()); }\n String next() throws IOException { return nextToken(); }\n String nextLine() throws IOException { return br.readLine(); }\n int [] readInt(int size) throws IOException {\n int [] array = new int [size];\n for (int i = 0; i < size; i++) { array[i] = nextInt(); }\n return array;\n }\n long [] readLong(int size) throws IOException {\n long [] array = new long [size];\n for (int i = 0; i < size; i++) { array[i] = nextLong(); }\n return array;\n }\n double [] readDouble(int size) throws IOException {\n double [] array = new double [size];\n for (int i = 0; i < size; i++) { array[i] = nextDouble(); }\n return array;\n }\n String [] readLines(int size) throws IOException {\n String [] array = new String [size];\n for (int i = 0; i < size; i++) { array[i] = nextLine(); }\n return array;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "24550d6e81a5589230be5ff23684b883", "src_uid": "915081861e391958dce6ee2a117abd4e", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class yum {\n public static void main(String []args){\n Scanner scan = new Scanner(System.in);\n int x = scan.nextInt();\n int y = scan.nextInt();\n int z = scan.nextInt();\n if(y>x+z){\n System.out.println(\"-\");\n }\n else if (x>y+z){\n System.out.println(\"+\");\n }\n else if (x==y&&z==0){\n System.out.println(\"0\");\n }\n else\n System.out.println(\"?\");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cffda24cf45693a48bbea42180555673", "src_uid": "66398694a4a142b4a4e709d059aca0fa", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class p1 {\n public static void main (String[] args) {\n Scanner scan = new Scanner(System.in);\n \n int n = scan.nextInt();\n int x = i;\n \n for (int i = n; i <=n; i--) {\n int x = i;\n \n if (n== 1) {\n System.out.println\n return;\n }\n if (x < n && % n !=0) {\n n -= x;\n }\n System.out.println(n);\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0126484281e276ebd9f3a2bfb6ba225f", "src_uid": "c30b372a9cc0df4948dca48ef4c5d80d", "difficulty": 800.0} {"lang": "Java 7", "source_code": "mport java.util.*;\npublic class ProbA {\npublic static void main(String [] args){\nScanner in=new Scanner(System.in);\nlong n=in.nextLong();\nint m=in.nextLong();\nint k=in.nextLong();\nlong a=Math.max(n,m);\nlong b=Math.min(n,m);\nif(k>m+n-2)\nSystem.out.println(\"-1\");\nelse if(a%(k+1)==0||b%(k+1)==0)\nSystem.out.println(a*b/(k+1));\nelse if(a*b%(k+1)==0 && k>b-1 && a%(k+b)==0){\nk-=b-1;\nSystem.out.println(a*b/(k+1));\t\n}\nelse if(k<=a-1){\nSystem.out.println(((a/(k+1))*b));\n}\nelse if(k>a-1){\nk-=(a-1);\nSystem.out.println((b/(k+1)));\n}\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e20c82ba45eef29b9eb325de3219c360", "src_uid": "bb453bbe60769bcaea6a824c72120f73", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class 852HBobsAndStages {\n\n\tclass Bubble {\n\t\tint x, y;\n\t\tint id1, id2;\n\n\t\tpublic Bubble(int x, int y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\n\t\tint q() {\n\t\t\tif (x == 0 && y == 0) {\n\t\t\t\treturn 0;\n\t\t\t} else if (x > 0 || (x == 0 && y > 0)) {\n\t\t\t\treturn 1;\n\t\t\t} else {\n\t\t\t\treturn 2;\n\t\t\t}\n\t\t}\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn \"Bubble [x=\" + x + \", y=\" + y + \", id1=\" + id1 + \", id2=\" + id2 + \"]\";\n\t\t}\n\t}\n\n\tlong vectMul(Bubble a, Bubble b) {\n\t\treturn 1L * a.x * b.y - 1L * a.y * b.x;\n\t}\n\n\tlong vectMul(Bubble a, Bubble b, Bubble c) {\n\t\treturn 1L * (b.x - a.x) * (c.y - a.y) - 1L * (b.y - a.y) * (c.x - a.x);\n\t}\n\n\tvoid solve() {\n\t\tint n = in.nextInt();\n\t\tint k = in.nextInt();\n\t\tBubble[] a = new Bubble[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = new Bubble(in.nextInt(), in.nextInt());\n\t\t}\n\t\tArrays.sort(a, (p1, p2) -> {\n\t\t\tif (p1.x != p2.x) {\n\t\t\t\treturn p1.x - p2.x;\n\t\t\t}\n\t\t\treturn p1.y - p2.y;\n\t\t});\n\n\t\tlong result = 0;\n\t\tlong[][] dp = new long[n][k + 1];\n\t\tlong[][] cost = new long[n][n];\n\t\tlong INF = Long.MIN_VALUE / 3;\n\t\tBubble[] buf = new Bubble[n];\n\t\tfor (int i = 0; i < buf.length; i++) {\n\t\t\tbuf[i] = new Bubble(0, 0);\n\t\t}\n\t\tBubble[] vecs = new Bubble[n * (n - 1)];\n\t\tfor (int i = 0, tmp = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tif (i != j) {\n\t\t\t\t\tvecs[tmp] = new Bubble(a[j].x - a[i].x, a[j].y - a[i].y);\n\t\t\t\t\tvecs[tmp].id1 = i;\n\t\t\t\t\tvecs[tmp].id2 = j;\n\t\t\t\t\ttmp++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tArrays.sort(vecs, (p1, p2) -> {\n\t\t\tint q1 = p1.q(), q2 = p2.q();\n\t\t\tif (q1 != q2) {\n\t\t\t\treturn q1 - q2;\n\t\t\t}\n\t\t\treturn -Long.signum(vectMul(p1, p2));\n\t\t});\n\t\tfor (int start = 0; start < n; start++) {\n\t\t\tfor (int i = n - 1; i >= start; i--) {\n\t\t\t\ta[i].x -= a[start].x;\n\t\t\t\ta[i].y -= a[start].y;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tArrays.fill(dp[i], INF);\n\t\t\t\tArrays.fill(cost[i], INF);\n\t\t\t}\n\t\t\tdp[start][0] = 0;\n\n\t\t\tint size = 0;\n\t\t\tfor (int i = start + 1; i < n; i++) {\n\t\t\t\tbuf[size].x = a[i].x;\n\t\t\t\tbuf[size].y = a[i].y;\n\t\t\t\tbuf[size].id1 = i;\n\t\t\t\tsize++;\n\t\t\t}\n\t\t\tArrays.sort(buf, 0, size, (p1, p2) -> {\n\t\t\t\tlong v = vectMul(p1, p2);\n\t\t\t\treturn -Long.signum(v);\n\t\t\t});\n\n\t\t\tfor (int i = 0; i < size; i++) {\n\t\t\t\tfor (int j = i + 1; j < size; j++) {\n\t\t\t\t\tint p1 = buf[i].id1, p2 = buf[j].id1;\n\t\t\t\t\tboolean ok = true;\n\t\t\t\t\tfor (int t = i + 1; t < j; t++) {\n\t\t\t\t\t\tif (vectMul(buf[i], buf[j], buf[t]) > 0) {\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\tcost[p1][p2] = vectMul(buf[i], buf[j]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int i = 0; i < size; i++) {\n\t\t\t\tcost[start][buf[i].id1] = cost[buf[i].id1][start] = 0;\n\t\t\t}\n\n\t\t\tfor (Bubble vec : vecs) {\n\t\t\t\tint p1 = vec.id1, p2 = vec.id2;\n\t\t\t\tlong cst = cost[p1][p2];\n\t\t\t\tif (cst != INF) {\n\t\t\t\t\tlong[] dp1 = dp[p1], dp2 = dp[p2];\n\t\t\t\t\tfor (int i = 0; i < k; i++) {\n\t\t\t\t\t\tdp2[i + 1] = Math.max(dp2[i + 1], dp1[i] + cst);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tresult = Math.max(result, dp[start][k]);\n\t\t}\n\n\t\tout.printf(\"%d.%02d\\n\", result / 2, 50 * (result % 2));\n\t}\n\n\tFastScanner in;\n\tPrintWriter out;\n\n\tvoid run() {\n\t\tin = new FastScanner();\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tout.close();\n\t}\n\n\tclass FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tpublic FastScanner(String s) {\n\t\t\ttry {\n\t\t\t\tbr = new BufferedReader(new FileReader(s));\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\t// TODO Auto-generated catch block\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\n\t\tpublic String nextToken() {\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}\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(nextToken());\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(nextToken());\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(nextToken());\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\t\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "aa70088bff138eedce9be7a6e8b06326", "src_uid": "6afcdad100c8e2469fef5abcc5bd96c6", "difficulty": 3000.0} {"lang": "Java 6", "source_code": "//package round31;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.BitSet;\nimport java.util.Scanner;\n\npublic class E {\n\tprivate Scanner in;\n\tprivate PrintWriter out;\n//\tprivate String INPUT = \"2 1234\";\n//\tprivate String INPUT = \"10 99887766554433221100\";\n//\tprivate String INPUT = \"4 00099990\";\n//\tprivate String INPUT = \"4 00009999\";\n//\tprivate String INPUT = \"18 123456789012345678901234567890123456\";\n//\tprivate String INPUT = \"18 000000000000000009099999999999999999\";\n\tprivate String INPUT = \"\";\n\t\n\tpublic void solve()\n\t{\n\t\tint n = ni();\n\t\tchar[] dc = in.next().toCharArray();\n\t\tint[] d = new int[2*n];\n\t\tfor(int i = 0;i < dc.length;i++){\n\t\t\td[i] = dc[i] - '0';\n\t\t}\n\t\t\n\t\tBitSet[] bs = new BitSet[n + 1];\n\t\tfor(int i = 0;i <= n;i++){\n\t\t\tbs[i] = new BitSet();\n\t\t}\n\t\tBigInteger[] t = new BigInteger[n + 1];\n\t\tArrays.fill(t, BigInteger.ZERO);\n\t\tBigInteger v;\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tBigInteger[] nt = new BigInteger[n + 1];\n\t\t\tArrays.fill(nt, BigInteger.ZERO);\n\t\t\tBitSet[] nbs = new BitSet[n + 1];\n\t\t\tfor(int j = 0;j <= n;j++){\n\t\t\t\tnbs[j] = new BitSet();\n\t\t\t}\n\t\t\tfor(int j = 0;j <= i;j++){\n\t\t\t\tif(j >= 1){\n\t\t\t\t\tv = t[j].add(BigInteger.valueOf(10).pow(2 * j - 2).multiply(BigInteger.valueOf(10 * d[2*i] + d[2*i+1])));\n\t\t\t\t\tif(nt[j-1].compareTo(v) < 0){\n\t\t\t\t\t\tnt[j-1] = v;\n\t\t\t\t\t\tnbs[j-1].clear();\n\t\t\t\t\t\tnbs[j-1].or(bs[j]);\n\t\t\t\t\t\tif(nbs[j-1].cardinality() < i){\n\t\t\t\t\t\t\tnbs[j-1].set(2*i);\n\t\t\t\t\t\t\tnbs[j-1].set(2*i+1);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t{\n\t\t\t\t\tint max = Math.max(d[2*i], d[2*i+1]);\n\t\t\t\t\tint min = Math.min(d[2*i], d[2*i+1]);\n\t\t\t\t\tv = t[j].multiply(BigInteger.valueOf(10)).add(BigInteger.valueOf(10).pow(2 * j).multiply(BigInteger.valueOf(max)).add(BigInteger.valueOf(min)));\n\t\t\t\t\tif(nt[j].compareTo(v) < 0){\n\t\t\t\t\t\tnt[j] = v;\n\t\t\t\t\t\tnbs[j].clear();\n\t\t\t\t\t\tnbs[j].or(bs[j]);\n\t\t\t\t\t\tif(nbs[j].cardinality() <= i){\n\t\t\t\t\t\t\tif(d[2*i] == max){\n\t\t\t\t\t\t\t\tnbs[j].set(2*i);\n\t\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\t\tnbs[j].set(2*i+1);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\tif(d[2*i] == max){\n\t\t\t\t\t\t\t\tnbs[j].set(2*i+1);\n\t\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\t\tnbs[j].set(2*i);\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\t{\n\t\t\t\t\tv = t[j].multiply(BigInteger.valueOf(100)).add(BigInteger.valueOf(10 * d[2*i] + d[2*i+1]));\n\t\t\t\t\tif(nt[j+1].compareTo(v) < 0){\n\t\t\t\t\t\tnt[j+1] = v;\n\t\t\t\t\t\tnbs[j+1].clear();\n\t\t\t\t\t\tnbs[j+1].or(bs[j]);\n\t\t\t\t\t\tif(nbs[j+1].cardinality() >= i){\n\t\t\t\t\t\t\tnbs[j+1].set(2*i);\n\t\t\t\t\t\t\tnbs[j+1].set(2*i+1);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n//\t\t\ttr(nt);\n//\t\t\ttr(nbs[1]);\n\t\t\tt = nt;\n\t\t\tbs = nbs;\n\t\t}\n\t\t\n\t\tif(bs[0].cardinality() != n)throw new AssertionError();\n\t\tfor(int i = 0;i < 2*n;i++){\n\t\t\tif(bs[0].get(i)){\n\t\t\t\tout.print('H');\n\t\t\t}else{\n\t\t\t\tout.print('M');\n\t\t\t}\n\t\t}\n\t\tout.println();\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 E().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", "compilation_error": false, "code_uid": "df9a5199f83ca38207ae5430cf9198b1", "src_uid": "98489fe54488dcfb45f8ae7b5c473d88", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Solution{\n\n\tpublic static void main(String [] args){\n\t\tScanner s = new Scanner(system.in);\n\t\tlong a = s.nextLong();\n\t\tlong b = s.nextLong();\n\n\t\tlong count = 0;\n\n\t\twhile(a!=b){\n\t\t\tint v = a/b;\n\t\t\t\n\t\t\tint rem = a%b;\n\n\t\t\tif(rem == 0){\n\t\t\t\tcount += v-1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse\n\t\t\t\tcount+=v;\n\t\n\t\t\ta = Math.max(rem,b);\n\t\t\tb = Math.min(rem,b);\n\n\t\t\t\n\t\t}\n\n\t\tcount++;\n\n\t\tSystem.out.println(count);\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "51d95eb959defdc56e1586141e825845", "src_uid": "ce698a0eb3f5b82de58feb177ce43b83", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\n\npublic class C\n{\n private final static int MAX_DIFFERENCE = 100;\n\n public static void main(String[] args) throws IOException\n {\n BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));\n\n StringTokenizer tokenizer = new StringTokenizer(reader.readLine());\n int n = Integer.parseInt(tokenizer.nextToken());\n int m = Integer.parseInt(tokenizer.nextToken());\n int k = Integer.parseInt(tokenizer.nextToken());\n\n long [][] subjects = new long[m+1][];\n subjects[0] = new long[] {0, 0, 0};\n for(int i = 1 ; i <= m ; i++)\n {\n tokenizer = new StringTokenizer(reader.readLine());\n long a = Long.parseLong(tokenizer.nextToken());\n long b = Long.parseLong(tokenizer.nextToken());\n long c = Long.parseLong(tokenizer.nextToken());\n\n subjects[i] = new long[] {a, b, c, i};\n }\n Arrays.sort(subjects, new Comparator()\n {\n @Override\n public int compare(long[] a, long[] b)\n {\n return Long.compare(a[2], b[2]);\n }\n });\n\n long [][][] dp = new long[n+1][m+1][MAX_DIFFERENCE+1];\n for(long [][] fill1 : dp)\n for(long [] fill2 : fill1)\n Arrays.fill(fill2, -1);\n int [][][] pr1 = new int[n+1][m+1][MAX_DIFFERENCE+1];\n int [][][] pr2 = new int[n+1][m+1][MAX_DIFFERENCE+1];\n for(int [][] fill1 : pr1)\n for(int [] fill2 : fill1)\n Arrays.fill(fill2, -1);\n for(int [][] fill1 : pr2)\n for(int [] fill2 : fill1)\n Arrays.fill(fill2, -1);\n\n dp[0][0][0] = 0;\n for(int d = 0 ; d < n ; d++)\n for(int lastChoose = 0 ; lastChoose < m ; lastChoose++)\n for(int diff = 0 ; diff <= MAX_DIFFERENCE ; diff++)\n if(dp[d][lastChoose][diff] != -1)\n for(int nextChoose = lastChoose + 1 ; nextChoose <= m ; nextChoose++)\n if(subjects[nextChoose][2] > subjects[lastChoose][2])\n {\n long lastExercise = subjects[lastChoose][0] + diff;\n for(long nextExercise = subjects[nextChoose][0] ; nextExercise <= subjects[nextChoose][1] ; nextExercise++)\n if(lastChoose == 0 || nextExercise == lastExercise + k || nextExercise == lastExercise*k)\n {\n int nextDiff = (int)(nextExercise - subjects[nextChoose][0]);\n if(dp[d+1][nextChoose][nextDiff] < dp[d][lastChoose][diff] + nextExercise)\n {\n dp[d+1][nextChoose][nextDiff] = dp[d][lastChoose][diff] + nextExercise;\n pr1[d+1][nextChoose][nextDiff] = lastChoose;\n pr2[d+1][nextChoose][nextDiff] = diff;\n }\n }\n }\n\n int v1 = 0;\n int v2 = 0;\n for(int i = 1 ; i <= m ; i++)\n for(int d = 0 ; d <= MAX_DIFFERENCE ; d++)\n if(dp[n][i][d] > dp[n][v1][v2])\n {\n v1 = i;\n v2 = d;\n }\n\n if(dp[n][v1][v2] == -1)\n writer.println(\"NO\");\n else\n {\n writer.println(\"YES\");\n recursivePrint(pr1, pr2, n, v1, v2, subjects, writer);\n }\n\n writer.flush();\n writer.close();\n\n }\n\n private static void recursivePrint(int[][][] pr1, int[][][] pr2, int n, int v1, int v2, long[][] subjects, PrintWriter writer)\n {\n if(v1 == 0)\n return;\n\n int nv1 = pr1[n][v1][v2];\n int nv2 = pr2[n][v1][v2];\n\n recursivePrint(pr1, pr2, n-1, nv1, nv2, subjects, writer);\n\n writer.println(subjects[v1][3]+\" \"+(subjects[v1][0] + v2));\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "65f0cdf33bfa8a0dd3ad6fd6a6254d0f", "src_uid": "c98fdad8e7ce09b8ac389108f72cecd9", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.lang.*;\nimport java.util.*;\nimport java.io.*;\npublic class Solution\n{\n static class FastReader{\n final private int BUFFER_SIZE = 1<<16;\n private DataInputStream din;\n private byte[] buffer;\n private int bufferPointer, bytesRead;\n \n public FastReader()throws IOException{\n din=new DataInputStream(System.in);\n bufferPointer=bytesRead=0;\n buffer=new byte[BUFFER_SIZE];\n }\n public FastReader(String filename)throws IOException{\n din=new DataInputStream(new FileInputStream(filename));\n bufferPointer=bytesRead=0;\n buffer=new byte[BUFFER_SIZE];\n }\n \n public String next()throws IOException{\n String s=\"\";\n byte[] buf = new byte[1024];\n byte c,count=0;\n while ((c = read()) != -1)\n {\n if (c == ' ' || c == '\\n')\n break;\n buf[count++]=c;\n if(count==1024){\n s+=new String(buf,0,count);\n count=0;\n \n }\n }\n s+=new String(buf,0,count);\n return s;\n }\n \n public String nextLine()throws IOException{\n byte[] buf = new byte[64];\n byte c,count=0;\n while ((c = read()) != -1)\n {\n if (c == '\\n')\n break;\n buf[count++]=c;\n }\n return new String(buf,0,count);\n }\n \n public int nextInt()throws IOException {\n int result=0;\n byte c=read();\n byte c1=c;\n while (c<'0' || c>'9'){\n c1=c;\n c=read();\n }\n boolean neg= (c1=='-');\n do {\n result=result*10 + c-'0';\n }while ((c=read())>='0' && c<='9');\n if(neg)\n return -result;\n return result;\n }\n public long nextLong()throws IOException {\n long result=0;\n byte c=read();\n byte c1=c;\n while (c<'0' || c>'9'){\n c1=c;\n c=read();\n }\n boolean neg= (c1=='-');\n do {\n result=result*10 + c-'0';\n }while ((c=read())>='0' && c<='9');\n if(neg)\n return -result;\n return result;\n }\n public double nextDouble()throws IOException{\n double result=0,divisor=1;\n byte c=read(),c1=c;\n while(c<'0' || c>'9'){\n c1=c;\n c=read();\n }\n boolean neg=(c1=='-');\n \n do {\n result=result*10 + c-'0';\n }while((c=read())>='0' && c<='9');\n \n if (c=='.'){\n while ((c=read())>='0' && c<='9'){\n result += (c-'0')/(divisor=divisor*10);\n }\n }\n if(neg)\n return -result;\n return result;\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 private byte read()throws IOException {\n if(bufferPointer==bytesRead)\n fillBuffer();\n return buffer[bufferPointer++];\n }\n public void close()throws IOException {\n if(din==null)\n return;\n din.close();\n }\n }\n public static void main(String[] args)throws IOException{\n FastReader sc=new FastReader();\n int w=sc.nextInt();\n int h=sc.nextInt();\n int sum=1;\n for(int i=0;ib){\n\t long t=a;\n\t a=b;\n\t b=t;\n\t }\n\t long n1=a+b;\n\t long n2=k-a-b;\n\t long n3=b-a;\n\t long n4=k-b+a;\n\t long ret1=Long.MAX_VALUE;\n\t long ret2=0;\n\t for(int i=0;n1<=n*k;n1+=k,n2+=k,n3+=k,n4+=k){\n\t if(n1!=0&&n1<=n*k){\n\t long c=gcd(n1,n*k);\n\t ret1=Math.min((n*k)/c,ret1);\n\t ret2=Math.max((n*k)/c,ret2);\n\t }\n\t if(n2!=0&&n2<=n*k){\n\t long c=gcd(n2,n*k);\n\t ret1=Math.min((n*k)/c,ret1);\n\t ret2=Math.max((n*k)/c,ret2);\n\t }if(n3!=0&&n3<=n*k){\n\t long c=gcd(n3,n*k);\n\t ret1=Math.min((n*k)/c,ret1);\n\t ret2=Math.max((n*k)/c,ret2);\n\t }\n\t if(n4!=0&&n4<=n*k){\n\t long c=gcd(n4,n*k);\n\t ret1=Math.min((n*k)/c,ret1);\n\t ret2=Math.max((n*k)/c,ret2);\n\t }\n\t }\n\t out.println(ret1);\n\t out.println(ret2);\n\t}\n\t\n\tlong gcd(long a,long b){\n\t if(a==b) return a;\n\t return a>b?gcd(b,a):gcd(a,b-a);\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "814181320358c14062938767273fea3d", "src_uid": "5bb4adff1b332f43144047955eefba0c", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Lecture3_Eight_Point_Sets {\n private static class Point implements Comparable {\n int x, y;\n Point(int x, int y) {\n this.x = x;\n this.y = y;\n }\n public int compareTo(Point o) {\n if (x == o.x && y == o.y)\n return 0;\n return (x < o.x || (x == o.x && y < o.y)) ? -1 : 1;\n }\n }\n public static void main(String[] args) {\n Scanner inp = new Scanner(System.in);\n Point[] A = new Point[8];\n for(int i = 0; i < 8; i++)\n A[i] = new Point(inp.nextInt(), inp.nextInt());\n inp.close();\n Arrays.sort(A);\n boolean isUgly = false;\n for(int i = 1; i < 3; i++) {\n if (A[i].x != A[i - 1].x || A[i + 5].x != A[i + 4].x) \n isUgly = true;\n if (A[i].y == A[i - 1].y)\n isUgly = true;\n if (A[i].y != A[i + 5].y || A[i - 1].y != A[i + 4].y) \n isUgly = true;\n }\n // if (A[4].x != A[3].x)\n // isUgly = true;\n //if (A[3].x == A[2].x || A[5].x == A[4].x)\n // isUgly = true;\n if (A[1].y == A[0].y || A[2].y == A[1].y)\n isUgly = true;\n if (A[0].y != A[3].y) || A[2].y != A[4].y)\n isUgly = true;\n if (isUgly)\n System.out.print(\"ugly\");\n else\n System.out.print(\"respectable\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ea26e8c403b5cb7daee768a4e52c7b3f", "src_uid": "f3c96123334534056f26b96f90886807", "difficulty": 1400.0} {"lang": "Java 6", "source_code": "public class Main {\n\n\n int counter=0 ;\n public int chanceForFactory(int n){\n int pro = n-10;\n if(pro==2 || pro==3 || pro==4 || pro==5 || pro==6 || pro==7 || pro==8 || pro==9 || pro==10) counter++;\n if(pro==1 || pro==11)counter++;\n if(pro==10){\n counter+=3;counter*=4;counter-=1;\n return counter;\n }else return counter*4;\n }\n \n \n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n int f = s.nextInt();\n Main m = new Main();\n\n System.out.println(m.chanceForFactory(f));\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4447da01c7736ba5fc4125c7edc3caa9", "src_uid": "5802f52caff6015f21b80872274ab16c", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.String;\nimport java.util.ArrayList;\n\nimport java.util.Scanner;\npublic class prob1{\n \n public static void main(String args[]){\n Scanner sc = new Scanner(System.in);\n String s = sc.nextLine();\n ArrayList check = new ArrayList();\n check.add(\"ABC\");check.add(\"ACB\");check.add(\"BAC\");check.add(\"BCA\");check.add(\"CAB\");check.add(\"CBA\");\n int case=0;\n for( i=0;i pfx = new HashSet<>();\n\t\tpfx.add(\"\");\n\t\tint maxLength = 1;\n\t\tfor (int i = 0; i < m; ++i) {\n\t\t\tmaxLength = Math.max(maxLength, p[i].length());\n\t\t\tfor (int j = 1; j <= p[i].length(); ++j) {\n\t\t\t\tpfx.add(p[i].substring(0, j));\n\t\t\t}\n\t\t}\n\t\t\n\t\tint state = pfx.size();\n\t\tMap mem = new HashMap<>();\n\t\tint idx = 0;\n\t\tfor (String pf : pfx) {\n\t\t\tmem.put(pf, idx++);\n\t\t}\n\t\t\n\t\t//\ufffd\ufffd\ufffd\ufffd\u00ff\ufffd\ufffd\u05f4\u032c\ufffd\ufffd\u04e6\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\u04f4\ufffd\ufffd\ufffd\ufffd\ufffd\n\t\tint[] finish = new int[state];\n\t\tfor (String pf : pfx) {\n\t\t\tfor (String pp : p) {\n\t\t\t\tif (pf.endsWith(pp)) {\n\t\t\t\t\tfinish[mem.get(pf)] = Math.max(finish[mem.get(pf)], pp.length());\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\t//\u05f4\u032c\u05ea\ufffd\ufffd\n\t\tint[][] next = new int[state][4];\n\t\tfor (String pf : pfx) {\n\t\t\tfor (int ch = 0; ch < 4; ++ch) {\n\t\t\t\tString nxt = pf + \"ATCG\".charAt(ch);\n\t\t\t\twhile (!mem.containsKey(nxt)) {\n\t\t\t\t\tnxt = nxt.substring(1);\n\t\t\t\t}\n\t\t\t\tnext[mem.get(pf)][ch] = mem.get(nxt);\n\t\t\t}\n\t\t}\n\t\t\n\t\tint[][] dp = new int[state + 16][maxLength + 16];\n\t\tdp[mem.get(\"\")][0] = 1;\n\t\tfor (int i = 1; i <= n; ++i) {\n\t\t\tdp = oneStep(dp, maxLength, state, next, finish);\n\t\t}\n\t\t\n\t\tint ans = 0;\n\t\tfor (int i = 0; i < state; ++i) {\n\t\t\tans += dp[i][0];\n\t\t\tif (ans >= MOD) ans -= MOD;\n\t\t}\n\t\treturn ans;\n\t}\n\t\n\tint[][] oneStep(int[][] cnt, int maxLength, int state, int[][] next, int[] finish) {\n\t\tint[][] newDp = new int[state + 16][maxLength + 16];\n\t\tfor (int oldState = 0; oldState < state; ++oldState) {\n\t\t\tfor (int oldNeed = 0; oldNeed < maxLength; ++oldNeed) {\n\t\t\t\tfor (int ch = 0; ch < 4; ++ch) {\n\t\t\t\t\tint newState = next[oldState][ch];\n\t\t\t\t\tint newNeed = oldNeed + 1;\n\t\t\t\t\tif (newNeed <= finish[newState]) newNeed = 0;\n\t\t\t\t\tif (newNeed >= maxLength) continue;\n\t\t\t\t\tnewDp[newState][newNeed] += cnt[oldState][oldNeed];\n\t\t\t\t\tif (newDp[newState][newNeed] >= MOD) newDp[newState][newNeed] -= MOD;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn newDp;\n\t}\n\t\n\tvoid read() {\n\t\tint n = ni();\n\t\tint m = ni();\n\t\tString[] p = new String[m];\n\t\tfor (int i = 0; i < m; ++i) {\n\t\t\tp[i] = ns();\n\t\t}\n\t\tout.println(solve(n, p));\n\t}\n\n\tFastScanner in;\n\tPrintWriter out;\n\t\n\tvoid run() throws IOException {\n\t\tboolean oj;\n\t\ttry {\n\t\t\toj = ! System.getProperty(\"user.dir\").equals(\"F:\\\\java_workspace\\\\leetcode\");\n\t\t} catch (Exception e) {\n\t\t\toj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\t}\n\t\t\n\t\tInputStream is = oj ? System.in : new FileInputStream(new File(INPUT));\n\t\tin = new FastScanner(is);\n\t\tout = new PrintWriter(System.out);\n\t\tlong s = System.currentTimeMillis();\n\t\tread();\n\t\tout.flush();\n\t\tif (!oj){\n\t\t\tSystem.out.println(\"[\" + (System.currentTimeMillis() - s) + \"ms]\");\n\t\t}\n\t}\n\t\n\tpublic boolean more(){\n\t\treturn in.hasNext();\n\t}\n\t\n\tpublic int ni(){\n\t\treturn in.nextInt();\n\t}\n\t\n\tpublic long nl(){\n\t\treturn in.nextLong();\n\t}\n\t\n\tpublic double nd(){\n\t\treturn in.nextDouble();\n\t}\n\t\n\tpublic String ns(){\n\t\treturn in.nextString();\n\t}\n\t\n\tpublic char nc(){\n\t\treturn in.nextChar();\n\t}\n\t\n\tclass FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tboolean hasNext;\n\n\t\tpublic FastScanner(InputStream is) throws IOException {\n\t\t\tbr = new BufferedReader(new InputStreamReader(is));\n\t\t\thasNext = true;\n\t\t}\n\n\t\tpublic String nextToken() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\thasNext = false;\n\t\t\t\t\treturn \"##\";\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\t\n\t\tString next = null;\n\t\tpublic boolean hasNext(){\n\t\t\tnext = nextToken();\n\t\t\treturn hasNext;\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\tif (next == null){\n\t\t\t\thasNext();\n\t\t\t}\n\t\t\tString more = next;\n\t\t\tnext = null;\n\t\t\treturn Integer.parseInt(more);\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\tif (next == null){\n\t\t\t\thasNext();\n\t\t\t}\n\t\t\tString more = next;\n\t\t\tnext = null;\n\t\t\treturn Long.parseLong(more);\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\tif (next == null){\n\t\t\t\thasNext();\n\t\t\t}\n\t\t\tString more = next;\n\t\t\tnext = null;\n\t\t\treturn Double.parseDouble(more);\n\t\t}\n\t\t\n\t\tpublic String nextString(){\n\t\t\tif (next == null){\n\t\t\t\thasNext();\n\t\t\t}\n\t\t\tString more = next;\n\t\t\tnext = null;\n\t\t\treturn more;\n\t\t}\n\t\t\n\t\tpublic char nextChar(){\n\t\t\tif (next == null){\n\t\t\t\thasNext();\n\t\t\t}\n\t\t\tString more = next;\n\t\t\tnext = null;\n\t\t\treturn more.charAt(0);\n\t\t}\n\t}\n\t\n\tstatic class ArrayUtils {\n\n\t\tpublic static void fill(int[][] f, int value) {\n\t\t\tfor (int i = 0; i < f.length; ++i) {\n\t\t\t\tArrays.fill(f[i], value);\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic static void fill(int[][][] f, int value) {\n\t\t\tfor (int i = 0; i < f.length; ++i) {\n\t\t\t\tfill(f[i], value);\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic static void fill(int[][][][] f, int value) {\n\t\t\tfor (int i = 0; i < f.length; ++i) {\n\t\t\t\tfill(f[i], value);\n\t\t\t}\n\t\t}\n\t}\n}\n\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "55ee860c5518bbc8caaee7f9752b5a18", "src_uid": "3f053c07deaac55c2c51df6147080340", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.BigDecimal;\n public class Main\n {\n public static void main(String[] args)\n {\n Scanner sc =new Scanner(System.in); \n int a=sc.nextInt();\n \n String s=sc.next();\n if(a==1){if(s.charAt(0)!=s.charAt(1))System.out.println(\"YES\"); else System.out.println(\"NO\"); System.exit(0);}\n int[] mas1 =new int[a];\n int[] mas2= new int[a];\n int i=0;\n while(i0){\n if(fs>=need)fs-=need;\n else{\n need-=fs;\n ts-=need*2;\n }\n }else{\n ts-=need*2;\n } \n }\n for(int i=0;i0){\n if(fs>=need)fs-=need;\n else{\n need-=fs;\n ts-=need*2;\n }\n }else{\n ts-=need*2;\n }\n }\n if(fs<0 || ts<0){\n System.out.println(\"NO\");\n return;\n }\n int sum=0;\n int ones=0;\n for(int i=0;i0)ones--;\n else if(fs>0){\n fs--;\n ts++;\n }else ts--;\n }else if(a[i]==2){\n if(fs>0){\n fs--;\n ones++;\n }else if(ones >=2){\n ones-=2;\n }else ts--;\n }\n \n }\n if(fs<0 || ts<0){\n System.out.println(\"NO\");\n }else System.out.println(\"YES\");\n \n }\n\n //__________________________________________________________\n static class FastScanner {\n\t BufferedReader br;\n\t StringTokenizer st;\n\t\t\n\t public FastScanner(InputStream i) {\n\t br = new BufferedReader(new InputStreamReader(i));\n\t st = new StringTokenizer(\"\");\n\t }\n\t\t\t\t\n\t public String next() throws IOException {\n\t if(st.hasMoreTokens())\n\t return st.nextToken();\n\t else\n\t st = new StringTokenizer(br.readLine());\n\t return next();\n\t }\n\n\t public int nextInt() throws IOException {\n\t return Integer.parseInt(next());\n\t }\n\t //#\n\t public long nextLong() throws IOException {\n\t return Long.parseLong(next());\n\t }\n\t public double nextDouble() throws IOException {\n\t return Double.parseDouble(next());\n\t }\n\t //$\n\t}\n}\n \nimport java.io.*;\nimport java.util.*;\n\npublic class Problems2{\n \n \n public static void main(String[] args) throws IOException {\n FastScanner sc=new FastScanner(System.in);\n PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n int n=sc.nextInt();\n int k=sc.nextInt();\n int ts=n*2;\n int fs=n;\n int a[]=new int[k];\n for(int i=0;i0){\n if(fs>=need)fs-=need;\n else{\n need-=fs;\n ts-=need*2;\n }\n }else{\n ts-=need*2;\n } \n }\n for(int i=0;i0){\n if(fs>=need)fs-=need;\n else{\n need-=fs;\n ts-=need*2;\n }\n }else{\n ts-=need*2;\n }\n }\n if(fs<0 || ts<0){\n System.out.println(\"NO\");\n return;\n }\n int sum=0;\n int ones=0;\n for(int i=0;i0)ones--;\n else if(fs>0){\n fs--;\n ts++;\n }else ts--;\n }else if(a[i]==2){\n if(fs>0){\n fs--;\n ones++;\n }else if(ones >=2){\n ones-=2;\n }else ts--;\n }\n \n }\n if(fs<0 || ts<0){\n System.out.println(\"NO\");\n }else System.out.println(\"YES\");\n \n }\n\n //__________________________________________________________\n static class FastScanner {\n\t BufferedReader br;\n\t StringTokenizer st;\n\t\t\n\t public FastScanner(InputStream i) {\n\t br = new BufferedReader(new InputStreamReader(i));\n\t st = new StringTokenizer(\"\");\n\t }\n\t\t\t\t\n\t public String next() throws IOException {\n\t if(st.hasMoreTokens())\n\t return st.nextToken();\n\t else\n\t st = new StringTokenizer(br.readLine());\n\t return next();\n\t }\n\n\t public int nextInt() throws IOException {\n\t return Integer.parseInt(next());\n\t }\n\t //#\n\t public long nextLong() throws IOException {\n\t return Long.parseLong(next());\n\t }\n\t public double nextDouble() throws IOException {\n\t return Double.parseDouble(next());\n\t }\n\t //$\n\t}\n}\n ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "41999e430d2450a3b1d889ebb492c0cb", "src_uid": "d1f88a97714d6c13309c88fcf7d86821", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.lang.*;\nimport java.util.*;\npublic class here{\n\tpublic static void main(String args[]){\n\tScanner sc= new Scanner(System.in);\n\tint num= sc.nextInt();\n\tInteger arr[] = new Integer[num];\n\tint count=0,nu=0.count2=0;\n\tfor(int i=0;i0)\n count++;\n if(arr[i]<0)\n count2++;\n\t}\n float n=(float)num/2;\n if(n%1!=0)\n nu=(int)n+1;\n if(count>=nu||count2>=nu)\n System.out.println(1);\n else\n System.out.println(0);\n}}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1c436c3ce11f8ac76c1472ce1789ee72", "src_uid": "a13cb35197f896cd34614c6c0b369a49", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import java.util.*; \npublic class Mars{\n \n public static void main(String[] args) {\n\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int min=-1;\n int max=-1;\n if (n<2){\n min=0;\n max=n;\n }\n if(n>=2 && n<=5 ){\n min=0;\n max=2;\n }\n if(n%7==6){\n min =((n/7)*2) + 1;\n max =(n / 7) * 2) + 2;\n }\n\n if (n>=7 && n%7!=6) {\n if (n % 7 > 1) {\n min = (n / 7) * 2;\n max = ((n / 7) * 2) + 2;\n }\n if(n % 7 ==0){\n min = (n / 7) * 2;\n max = ((n / 7) * 2) ;\n }\n if(n % 7 ==1){\n min = (n / 7) * 2;\n max = ((n / 7) * 2) +1 ;\n }\n }\n\n System.out.println(min+\" \"+max);\n\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "692e16bc3170c434e2021a2a1ace8785", "src_uid": "8152daefb04dfa3e1a53f0a501544c35", "difficulty": 900.0} {"lang": "Java 8", "source_code": "public class test {\nimport java.util.*;\n\npublic static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int N = Integer.parseInt(in.next());\n int K = Integer.parseInt(in.next());\n int min = Integer.MAX_VALUE;\n for (int i = 0; i < N; i++) {\n int a = Integer.parseInt(in.next());\n if (k % a == 0 && min > a) min = a;\n }\n System.out.println(min);\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cdeb4353c6461608e65e866b78ac07dd", "src_uid": "80520be9916045aca3a7de7bc925af1f", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class test\n{\npublic static void main(String args[])\n{\n Scanner scan=new Scanner(System.in);\n int n,k,i,z=0;\n n=scan.nextInt();\n k=scan.nextInt();\n int a[]=new int[k];\n if(k==1)\n {\n System.out.println(n);\n break;\n }\n for(i=2;i*i<=n;i++)\n {\n while(n%i==0)\n {\n a[z]=i;\n n=n/i;\n k--;\n z++;\n if(k==1 && n>1)\n {\n a[z]=n;\n for(int c=0;c0)System.out.println(-1);\n\t}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6c8d08c600206ea09e3c05a549113393", "src_uid": "24695b6a2aa573e90f0fe661b0c0bd3a", "difficulty": 900.0} {"lang": "Java 6", "source_code": "/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n\n\nimport com.sun.xml.internal.ws.api.pipe.NextAction;\nimport java.io.Console;\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.Scanner;\n\n/**\n *\n * @author KID\n */\npublic class test {\n \n \n \n public static void main(String[] args) {\n /////////////////////////////////////////////////////////////////////////// \n Scanner sc = new Scanner(System.in);\n \n int n=sc.nextInt(),counter=0;\n int[] a1=new int[n];\n int[] a2=new int[n];\n for(int i = 0 ; i0){\n\t\t\txx/=2;\n\t\t\tsize++;\n\t\t}\n\t\tlong cur=1L<<(size-1);\n\t\tif(ind==cur){\n\t\t\treturn x%2;\n\t\t}\n\t\telse if(ind 0){\n\t\t\tif(b%2 == 1){\n\t\t\t\tx=(x*y)%c;\n\t\t\t}\n\t\t\ty = (y*y)%c; // squaring the base\n\t\t\tb /= 2;\n\t\t}\n\t\treturn x%c;\n\t}\n\n\tstatic class Pair implements Comparable{\n\t\tint x;\n\t\tint y;\n\t\tPair(int xx,int yy){\n\t\t\tx=xx;\n\t\t\ty=yy;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(Pair o) {\n\t\t\tif(Long.compare(this.x, o.x)!=0)\n\t\t\t\treturn -Long.compare(this.x, o.x);\n\t\t\telse\n\t\t\t\treturn Long.compare(this.y, o.y);\n\t\t}\n\t}\n\tpublic static void debug(Object... o) {\n\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n\n\tstatic final class InputReader{\n\t\tprivate final InputStream stream;\n\t\tprivate final byte[] buf=new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n\t\tpublic InputReader(InputStream stream){this.stream=stream;}\n\t\tprivate int read()throws IOException{\n\t\t\tif(curChar>=numChars){\n\t\t\t\tcurChar=0;\n\t\t\t\tnumChars=stream.read(buf);\n\t\t\t\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 final int nextInt()throws IOException{return (int)nextLong();}\n\t\tpublic final long nextLong()throws IOException{\n\t\t\tint c=read();\n\t\t\twhile(isSpaceChar(c)){\n\t\t\t\tc=read();\n\t\t\t\tif(c==-1) throw new IOException();\n\t\t\t}\n\t\t\tboolean negative=false;\n\t\t\tif(c=='-'){\n\t\t\t\tnegative=true;\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')throw 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 negative?(-res):(res);\n\t\t}\n\t\tpublic final int[] readIntBrray(int size)throws IOException{\n\t\t\tint[] arr=new int[size];\n\t\t\tfor(int i=0;i0){\n\t\t\tans++;\n\t\t\tif(tleft 0){\n int x = Integer.parseInt(br.readLine());\n if(x < 3){\n System.out.println(\"NO\");\n }\n else {\n while(x % 7 == 0){\n x /= 7;\n }\n while(x % 3 == 0){\n x /= 3;\n }\n if(x == 1)\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a1411dfc32266fc813b5fa0292a0f6de", "src_uid": "cfd1182be98fb5f0c426f8b68e48d452", "difficulty": 900.0} {"lang": "Java 7", "source_code": "\npackage codeforce;\n\nimport java.util.Scanner;\n\npublic class Codeforce {\n\n public static void main(String[] args) {\n\n Scanner cin=new Scanner(System.in);\n int a[][];\n a=new int[5][5];\n for(int i=1;i<4;i++)\n for(int j=1;j<4;j++)\n {\n a[i][j]=cin.nextInt();\n }\n \n for(int i=1;i<4;i++)\n {\n for(int j=1;j<4;j++)\n {\n System.out.print((a[i][j]+a[i+1][j]+a[i][j+1]+a[i-1][j]+a[i][j-1]+1)%2);\n }\n System.out.println();\n }\n \n \n \n \n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "804f63d5b948f0a3c007e4e7e266d042", "src_uid": "b045abf40c75bb66a80fd6148ecc5bd6", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class CodeForces2 {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt(); int arr[] = new int[n];\n for (int i = 0; i < n; i++) {\n arr[i] = sc.nextInt();\n }\n Arrays.sort(arr);\n System.out.println(arr[0]);\n } \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a19df1a5657d624362650f42932d10d2", "src_uid": "ff6b3fd358c758324c19a26283ab96a4", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n \npublic class Display {\n \n\tpublic static void main(String[] args) throws Exception {\n \n\t\tBufferedReader f=new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(\n\t\t\t\t\t\tSystem.out)));\n\t\tStringTokenizer st=new StringTokenizer(f.readLine());\n \n\t\tint a=Integer.parseInt(st.nextToken());\n\t\t\n\t\tint diff = a;\n\t\tint b;\n\t\tint c;\n\t\tfor (int j = 0; j < a / 2; j++) {\n\t\t\tfor (int i = 0; i < a / 2; i++) {\n\t\t\t\tif (j * i == a) {\n\t\t\t\t\tif (Math.abs(i - j) < diff) {\n\t\t\t\t\t\tdiff = Math.abs(i - j);\n\t\t\t\t\t\tb = j;\n\t\t\t\t\t\tc = i;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.print(b);\n\t\tSystem.out.print(c);\n\t\tSystem.out.close();\n\t\t}\n\t\t\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d89e701ef962691154ca57760eab2b9f", "src_uid": "f52af273954798a4ae38a1378bfbf77a", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Solution {\n \n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int N = in.nextInt();\n int[] arr = new int[N];\n String g = in.nextInt();\n for(int i = 0; i < N; i++) {\n arr[i] = (g.charAt(i) == '+') ? 1 : -1;\n }\n \n int minIndex = 0;\n int min = Integer.MAX_VALUE;\n for(int i = 0; i < N; i++) {\n if(arr[i] <= min) {\n min = arr[i];\n minIndex = i;\n }\n }\n \n int increase = 0;\n for(int i = minIndex; i < N; i++) {\n if(arr[i] == 1) {\n increase++;\n }\n else {\n increase--;\n }\n }\n \n System.out.println(increase);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f90c8b0fd39e8642957478abf292e103", "src_uid": "a593016e4992f695be7c7cd3c920d1ed", "difficulty": 800.0} {"lang": "Java 8", "source_code": "package com.darkbit.problems;\n\nimport net.egork.io.InputReader;\nimport net.egork.io.OutputWriter;\n\npublic class D2RemoveTheSubstringHardVersion {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n\n String s = in.readString();\n String t = in.readString();\n int n = s.length();\n int m = t.length();\n int[] left = new int[t.length() + 5];\n int[] right = new int[t.length() + 5];\n\n int j = 0;\n for (int i = 0; j < t.length(); ++i)\n if (s.charAt(i) == t.charAt(j)) {\n left[j++] = i;\n }\n j = t.length() - 1;\n for (int i = s.length() - 1; j >= 0; --i)\n if (s.charAt(i) == t.charAt(j)) {\n right[j--] = i;\n }\n\n int ans = Math.max(right[0], n - left[m - 1] - 1);\n\n for (int i = 0; i + 1 < m; i++) ans = Math.max(ans, right[i + 1] - left[i] - 1);\n for (int i = 0; i + 1 < m; i++) ans = Math.max(ans, left[i + 1] - left[i] - 1);\n for (int i = 0; i + 1 < m; i++) ans = Math.max(ans, right[i + 1] - right[i] - 1);\n\n out.printLine(ans);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a01c7cb8662acd8331b1d911d3425a6c", "src_uid": "0fd33e1bdfd6c91feb3bf00a2461603f", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class imBored {\n public static void main(String [] args);\n int a1 = Scanner.nextInt();\n int b1 = Scanner.nextInt();\n \n int smaller;\n \n if(a1 > b1){\n smaller = b1;\n }\n else{\n smaller = a1;\n }\n \n int ans = 1;\n for(int i = 1; i <= smaller; i++){\n ans = ans*i;\n }\n System.out.println(ans);\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1dc3341b9fb7e7457dace1b269336b4d", "src_uid": "7bf30ceb24b66d91382e97767f9feeb6", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class regex {\n\n\tstatic Scanner scanner = new Scanner(System.in);\n\tstatic int x1, y1, x2, y2;\n\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tx1 = scanner.nextInt();\n\t\ty1 = scanner.nextInt();\n\t\t\n\t\tx2 = scanner.nextInt();\n\t\ty2 = scanner.nextInt();\n\t\t\n\t\tint d = 0;\n\t\t\n\t\tx2 = x2 + x1 * -1;\n\t\ty2 = y2 + y1 * -1;\n\t\t\n\t\tx2 = Math.abs(x2);\n\t\ty2 = Math.abs(y2);\n\t\t\n\t\tint min = Math.min(x2, y2);\n\n\t\td += min;\n\t\td += Math.abs(x2 - y2);\n\t\t\n\t\tSystem.out.println(d);\n\t\t\n\t\t\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "17abc1945c82b2728b54096f45714811", "src_uid": "a6e9405bc3d4847fe962446bc1c457b4", "difficulty": 800.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Round157B {\n\tpublic static void main(String[] args) throws IOException {\n\t\trd = new BufferedReader(new InputStreamReader(System.in));\n\t\tpw = new PrintWriter(System.out);\n\t\tM = Integer.parseInt(rd.readLine());\n\t\tfor(int i=0; iP) ans -= P;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tpw.println(ans);\n\t\tpw.flush();\n\t}\n\t\n\tstatic long[][] C = new long[20][20];\n\t\n\tstatic long[] p2 = new long[20], p8 = new long[20];\n\t\n\tstatic long A(int X, int y){\n\t\tlong res = 1;\n\t\tfor(long i=X; i>=X-y+1; i--) res = (res * i)%P;\n\t\treturn res;\n\t}\n\t\n\t\n\t\n\tstatic long countFor(int NL, int x1, int x2, int x3, int x4, int x5, int x6){\n\t\tint[] a = new int[10];\n\t//\tSystem.out.println(\" here with \"+x1+\" \"+x2+\" \"+x3+\" \"+x4+\" \"+x5+\" \"+x6);\n\t\ta[x1]++;\n\t\ta[x2]++;\n\t\ta[x3]++;\n\t\ta[x4]++;\n\t\ta[x5]++;\n\t\ta[x6]++;\n\t\ta[NL]++;\n\t\tlong res = 1;\n\t\tfor(int i=0; i<10; i++){\n\t\t\tif(a[i]>0)\n\t\t\t\tres = (res * A(N[i], a[i]))%P;\n\t\t}\n\t//\tSystem.out.println(\"result = \"+res);\n\t\treturn res;\n\t}\n\t\n\tstatic int[] N1 = new int[10];\n\t\n\tstatic void naiveCount(){\n\t\tfor(int i=1; i<=M; i++){\n\t\t\tint numL = numLuckyIn(i);\n\t\t\tN1[numL]++;\n\t\t}\n\t}\n\t\n\tstatic void countNArray(){\n\t\tif(M<1000000){\n\t\t\tfor(int i=1; i<=M; i++){\n\t\t\t\tint numL = numLuckyIn(i);\n\t\t\t\tN[numL]++;\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tL = (\"\"+M).length();\n\t\tint[][] A = new int[10001][10];\n\t\tint pow = 1;\n\t\tfor(int i=0; i0) r += p2[K]*p8[i-K-1]*7;\n\t\t}\n\t\tr = (r+countSameLengthFor(K))%P;\n\t\tN[K] = (int) r;\n\t}\n\t\n\tstatic long countSameLengthFor(int K){\n\t\tint num = Integer.parseInt((\"\"+M).substring(0, 5)), suf = Integer.parseInt((\"\"+M).substring(5, L));;\n\t\tlong res = 0;\n\t\tfor(int x1=1; x1<=9; x1++){\n\t\t\tfor(int x2=0; x2<=9; x2++){\n\t\t\t\tfor(int x3=0; x3<=9; x3++){\n\t\t\t\t\tfor(int x4=0; x4<=9; x4++){\n\t\t\t\t\t\tfor(int x5=0; x5<=9; x5++){\n\t\t\t\t\t\t\tint FIVE = x5+10*x4+100*x3+1000*x2+10000*x1;\n\t\t\t\t\t\t\tif(FIVE>num) continue;\n\t\t\t\t\t\t\tif(FIVE==num){\n\t\t\t\t\t\t\t\tres = (res + T[suf][K])%P;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse{\n\t\t\t\t\t\t\t\tres = (res + T[10000][K])%P;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n\t\n\tstatic int[][] T = new int[10001][10];\n\t\n\tstatic int L;\n\t\n\tstatic int numLuckyIn(int N){\n\t\tString s = \"\"+N;\n\t\tint t = 0;\n\t\tfor(int i=0; ib)\n min=b;\n else\n min=a;\n System.out.println(2*min+1);\n }\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "92c6bd77201d9af6eb7a3fa018e8e13c", "src_uid": "609f131325c13213aedcf8d55fc3ed77", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class KingMoves{\n public static void main (String[] args){\n Scanner kbd = new Scanner(System.in);\n int counter = 0;\n String input = kbd.nextLine();\n char c = input.charAt(0);\n int x = 0;\n String r = input.charAt(1) + \"\";\n int y = Integer.parseInt(r) + 0;\n\n switch (c) {\n case 'a': x = 1;break;\n case 'b': x = 2;break;\n case 'c': x = 3;break;\n case 'd': x = 4;break;\n case 'e': x = 5;break;\n case 'f': x = 6;break;\n case 'g': x = 7;break;\n case 'h': x = 8;break;\n }\n int east = x;\n int west = x;\n int nEastX = x;\n int sEastX = x;\n int nWestX = x;\n int sWestX = x;\n int north = y;\n int south = y;\n int nEastY = y;\n int sEastY = y;\n \tint nWestY = y;\n int sWestY = y;\n\n \t east++;\n if (east <= 8) {\n \t counter++;\n }\n \n west--;\n if (west > 0) {\n \t counter++;\n }\n \n\t\t\tnorth++;\n if (north <= 8) {\n \t counter++;\n }\n \n south--;\n if (south > 0) {\n \t counter++;\n }\n \n nEastY++;\n nEastX++;\n if(nEastX <= 8 && nEastY <= 8 ){\n \t counter++;\n }\n\n\t\t\tnWestY++;\n\t\t\tnWestX--;\n\t\t\tif(nWestX > 0 && nWestY <= 8){\n\t\t\t\tcounter++;\n\t\t\t}\n\t\t\t\t\n\t\t\tsEastY--;\n\t\t\tsEastX++;\n\t\t\tif(sEastX <= 8 && sEastY > 0){\n\t\t\t\tcounter++;\n\t\t\t}\n\t\t\t\t\n\t\t\tsWestY--;\n\t\t\tsWestX--;\n\t\t\tif(sWestX > 0 && sWestY > 0){\n\t\t\t\tcounter++;\n\t\t\t}\n\t\t\t\t\n\t\t\tSystem.out.println(counter);\n\n }\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4aef7f0faf301893eb32780f691c8e3a", "src_uid": "6994331ca6282669cbb7138eb7e55e01", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import com.sun.security.auth.SolarisNumericUserPrincipal;\nimport jdk.management.resource.internal.inst.SocketOutputStreamRMHooks;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class _582B {\n\n static int n;\n static int T;\n static int[] a;\n static Map map = new HashMap<>();\n\n static int[][] F(int T) {\n if (map.containsKey(T)) return map.get(T);\n int[][] ans = new int[n][n];\n\n if (T == 1) {\n int[][] old = new int[n][n];\n for (int num : a) {\n for (int i = 0; i < n; i++)\n for (int j = i; j < n; j++) {\n ans[i][j] = old[i][j];\n if (i <= num && num <= j) ans[i][j] = Math.max(ans[i][j], old[i][num] + 1);\n }\n\n int[][] tmp = old;\n old = ans;\n ans = tmp;\n }\n ans = old;\n } else {\n int[][] left = F(T / 2);\n int[][] right = F(T - T / 2);\n for (int i=0; i max) max = i;\n return max;\n }\n\n static int min(int[] a) {\n int min = Integer.MAX_VALUE;\n for (int i : a)\n if (i < min) min = i;\n return min;\n }\n\n static long max(long[] a) {\n long max = Long.MIN_VALUE;\n for (long i : a)\n if (i > max) max = i;\n return max;\n }\n\n static long min(long[] a) {\n long min = Long.MAX_VALUE;\n for (long i : a)\n if (i < min) min = i;\n return min;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "00a30d57d4be01ae7ba315ad2ae00f75", "src_uid": "26cf484fa4cb3dc2ab09adce7a3fc9b2", "difficulty": 1900.0} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class Resistance {\n public static void main(String[] args) {\n Scanner stdin = new Scanner(System.in);\n BigInteger a = stdin.nextBigInteger();\n BigInteger b = stdin.nextBigInteger();\n BigInteger res = BigInteger.ZERO;\n\n while (!a.equals(BigInteger.ZERO)) {\n \t// System.out.println(a + \", \" + b);\n if (a.compareTo(b) >= 0) {\n res = res.add(a.divide(b));\n a = a.mod(b);\n } else {\n \tb = b.subtract(a);\n res = res.add(BigInteger.ONE);\n }\n BigInteger g = b.gcd(a);\n a = a.divide(g);\n b = b.divide(g);\n }\n\n System.out.println(res);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b1f3acb52bc5eb38061a9a03bbc3a7e5", "src_uid": "792efb147f3668a84c866048361970f8", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n public static void main(String[] args) throws IOException {\n\n new Main().go();\n }\n\n PrintWriter out;\n Reader in;\n BufferedReader br;\n\n Main() throws IOException {\n\n try {\n\n //br = new BufferedReader( new FileReader(\"input.txt\") );\n in = new Reader(\"input.txt\");\n out = new PrintWriter( new BufferedWriter(new FileWriter(\"output.txt\")) );\n }\n catch (Exception e) {\n\n //br = new BufferedReader( new InputStreamReader( System.in ) );\n in = new Reader();\n out = new PrintWriter( new BufferedWriter(new OutputStreamWriter(System.out)) );\n }\n }\n\n void go() throws IOException {\n\n int t = 1;\n while (t > 0) {\n solve();\n //out.println();\n t--;\n }\n\n out.flush();\n out.close();\n }\n\n int inf = 2000000000;\n int mod = 1000000007;\n double eps = 0.000000001;\n\n int n;\n int m;\n\n //ArrayList[] g = new ArrayList[200010];\n\n void solve() throws IOException {\n\n int n = in.nextInt();\n int k = in.nextInt();\n int m = in.nextInt();\n int a = in.nextInt();\n\n Pair[] cands = new Pair[n];\n for (int i = 0; i < n; i++)\n cands[i] = new Pair(0, i);\n for (int i = 0; i < a; i++) {\n int x = in.nextInt()-1;\n cands[x].a++;\n cands[x].t = i;\n }\n\n Arrays.sort(cands);\n int[] pos = new int[n];\n for (int i = 0; i < n; i++)\n pos[cands[i].b] = i;\n\n int[] same = new int[n];\n int[] sum = new int[n];\n sum[0] = cands[0].a;\n for (int i = 1; i < n; i++) {\n if (cands[i].a == cands[i - 1].a) {\n same[i] = same[i - 1] + 1;\n }\n sum[i] += sum[i-1] + cands[i].a;\n }\n\n m -= a;\n int[] ans = new int[n];\n for (int i = 0; i < n; i++) {\n int p = pos[i];\n boolean ok = false;\n int x = k - (n-p) + 1;\n if (p >= n - k && !(cands[p].a == 0 && n > 1)) {\n if (p - x < 0) {\n if (m > 0 || cands[p].a > 0) {\n ok = true;\n ans[i] = 1;\n }\n }\n else {\n int r = p - 1;\n int l = p - x;\n int need = x * (cands[p].a + 1);\n need -= sum[r];\n if (l > 0)\n need += sum[l-1];\n\n //System.err.println(need+\" \"+i);\n\n if (need > m) {\n ok = true;\n ans[i] = 1;\n }\n }\n }\n\n if (!ok) {\n\n int v = cands[n-k].a;\n if (cands[p].a + m > v) {\n ans[i] = 2;\n }\n else {\n ans[i] = 3;\n }\n }\n }\n\n for (int i = 0; i < n; i++)\n out.print(ans[i]+\" \");\n\n }\n\n\n class Pair implements Comparable{\n\n int a;\n int b;\n int t = 0;\n Pair(int a, int b) {\n\n this.a = a;\n this.b = b;\n }\n\n public int compareTo(Pair p) {\n\n if (a > p.a) return 1;\n if (a < p.a) return -1;\n if (t > p.t) return -1;\n if (t < p.t) return 1;\n return 0;\n }\n }\n\n class Item {\n\n int a;\n int b;\n int c;\n\n Item(int a, int b, int c) {\n this.a = a;\n this.b = b;\n this.c = c;\n }\n\n }\n\n class Reader {\n\n BufferedReader br;\n StringTokenizer tok;\n\n Reader(String file) throws IOException {\n br = new BufferedReader( new FileReader(file) );\n }\n\n Reader() throws IOException {\n br = new BufferedReader( new InputStreamReader(System.in) );\n }\n\n String next() throws IOException {\n\n while (tok == null || !tok.hasMoreElements())\n tok = new StringTokenizer(br.readLine());\n return tok.nextToken();\n }\n\n int nextInt() throws NumberFormatException, IOException {\n return Integer.valueOf(next());\n }\n\n long nextLong() throws NumberFormatException, IOException {\n return Long.valueOf(next());\n }\n\n double nextDouble() throws NumberFormatException, IOException {\n return Double.valueOf(next());\n }\n\n\n String nextLine() throws IOException {\n return br.readLine();\n }\n\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f8c65099069b39ac64de4d8b6ddf04f6", "src_uid": "81a890bd542963bbcec7a041dde5c247", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import 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 //(new FileReader(\"input.in\"));\n StringBuilder out = new StringBuilder();\n StringTokenizer tk;\n Reader.init(System.in);\n //PrintWriter pw = new PrintWriter(\"output.out\", \"UTF-8\");\n \n tk = new StringTokenizer(in.readLine());\n double a = parseDouble(tk.nextToken());\n double b = parseDouble(tk.nextToken());\n double c = parseDouble(tk.nextToken());\n double d = parseDouble(tk.nextToken());\n \n if(abs(a/b-c/d) <= 1e-9)\n System.out.println(\"0/1\");\n else if(a/b > c/d) {\n double x = a*d-b*c,y = a*d;\n \n long g = gcd((long)x,(long)y);\n x /= g;\n y /= g;\n \n System.out.println((int)x+\"/\"+(int)y);\n } else {\n double x = b*c-a*d,y = b*c;\n \n long g = gcd((long)x,(long)y);\n \n x /= g;\n y /= g;\n \n System.out.println((int)x+\"/\"+(int)y);\n }\n } \n \n static long gcd(long a,long b) {\n return b==0 ? a : gcd(b,a%b);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3113ac5282279763206a140898ce200f", "src_uid": "b0f435fc2f7334aee0d07524bc37cb1e", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class Palindrome\n{\n\t public static void main(String[] args) {\n\t\tScanner sc=new Scanner(System.in);\n\t\tString s=sc.next();\n\t\tint b=0;\n\t\tfor(int i=0,int k=s.length()-1;i!=k||i+1!=k;i++,k--)\n\t\t{\n\t\t\tif(s.charAt[i]==s.chart[k])\n\t\t\t{\n\n\n\t\t\t}\n\t\t\telse if(s.charAt[i]==s.charAt[0])\n\t\t\t{\n\t\t\t\tb++;\n\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t b=1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\tif{b==1}\n\t\t\t\tSystem.out println(s.length());\n\t\t\tif{b==0}\n\t\t\t\tSystem.out.println(s.length()-1);\n\t\t\telse \n\t\t\t\tSystem.out.println(0);\n\n\n\t\t\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "af5f419284afeea7cb71e9e261b824cc", "src_uid": "6c85175d334f811617e7030e0403f706", "difficulty": 900.0} {"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 */\npackage pkg124d;\n\nimport java.util.Scanner;\nimport java.io.IOException;\nimport static java.lang.Integer.max;\nimport static java.lang.Math.abs;\n/**\n *\n * @author Sergey\n */\npublic class Main {\n private static final Scanner scanner = new Scanner( System.in );\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n String str = \"\";\n \n str = scanner.nextLine();\n\n int[] arr = new int[6];\n int t1, t2;\n \n for(int i = 0; i < arr.length -1; i++){\n int index = str.indexOf(\" \");\n arr[i] = Integer.parseInt(str.substring(0, index));\n str = str.substring(index+1);\n }\n \n arr[5] = Integer.parseInt(str);\n \n t1 = arr[2]; t2 = arr[3];\n arr[2] = t1 + t2;\n arr[3] = t2 - t1;\n\n t1 = arr[4]; t2 = arr[5];\n arr[4] = t1 + t2;\n arr[5] = t2 - t1;\n \n arr[0] *= 2;\n arr[1] *= 2;\n \n arr[2]= arr[2] / arr[0] + ((arr[2] > 0)? 1 : 0);\n arr[4] = arr[4] / arr[0] + ((arr[4] > 0)? 1 : 0);\n arr[3] = arr[3] / arr[1] + ((arr[3] > 0)? 1 : 0);\n arr[5] = arr[5] / arr[1] + ((arr[5] > 0)? 1 : 0);\n \n System.out.print(max(abs(arr[5] - arr[3]), abs(arr[4] - arr[2])));\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "246946b9758ce630130cf4b9a2d3990b", "src_uid": "7219d1837c83b5920992aee5a60dc0d9", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "/* IMPORTANT: Multiple classes and nested static classes are supported */\n\n/*\n * uncomment this if you want to read input.\n//imports for BufferedReader\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\n//import for Scanner and other utility classes\n*/import java.util.*;\n\n\npublic class TestClass {\n public static void main(String args[] ) throws Exception {\n /*\n * Read input from stdin and provide input before running\n * Use either of these methods for input\n\n //BufferedReader\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n String line = br.readLine();\n int N = Integer.parseInt(line);\n\n //Scanner\n Scanner s = new Scanner(System.in);\n int N = s.nextInt();\n\n for (int i = 0; i < N; i++) {\n System.out.println(\"hello world\");\n }\n */\nScanner s=new Scanner(System.in);\nint a[]=new int[25];\nfor(int i=1;i<25;i++){\n a[i]=s.nextInt();\n}\nint c1=a[1],c2=a[5],c3=a[13],c4=a[9],c5=a[17],c6=a[21];\nif(a[4]==c1&&a[2]==c1&&a[3]==c1&&a[12]==c4&&a[9]==c4&&a[10]==c4&&a[11]==c4)\n{\n \n if(a[5]==a[6]&&a[19]==a[20]&&a[5]==a[19]){\n System.out.println(\"YES\");}\n else{\n System.out.println(\"NO\");\n} \n}\nelse if(a[8]==c2&&a[6]==c2&&a[7]==c2&&a[23]==c6&&a[24]==c6&&a[21]==c6&&a[22]==c6){\n if(a[17]==a[19]&&a[1]==a[2]&&a[17]==a[1]){\n {\n System.out.println(\"YES\");\n }\n else\n {\n System.out.println(\"NO\");\n }\n}\n \nelse if(a[16]==c3&&a[14]==c3&&a[15]==c3&&a[20]==c5&&a[17]==c5&&a[18]==c5&&a[19]==c5)\n{\n if(a[7]==a[5]&&a[2]==a[4]&&a[5]==a[2])\n {\n System.out.println(\"YES\");\n }\n else\n {\n System.out.println(\"NO\");\n }\n}\n \nelse{\n System.out.println(\"NO\");\n}\n //System.out.println(\"Hello World!\");\n }\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ac354da5a4f41c94e6ccf57b4c9abc98", "src_uid": "881a820aa8184d9553278a0002a3b7c4", "difficulty": 1500.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class AA {\n\tpublic static void main(String[] args) throws IOException {\n\t\tint n = 3200000;\n\t\tint[] primes = new int[230209];\n\t\tint c = 0;\n\t\tboolean[] isComposite = new boolean[n];\n\t\tfor (int i = 2; i < n; i++) {\n\t\t\tif (!isComposite[i]) {\n\t\t\t\tprimes[c++] = i;\n\t\t\t\tfor (int j = i + i; j < n; j += i) {\n\t\t\t\t\tisComposite[j] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tBufferedReader r = new BufferedReader(new InputStreamReader(System.in));\n\t\tString s = r.readLine();\n\t\tlong x = new Long(s);\n\t\tlong xx = x;\n\t\tif (isPrime(x)) {\n\t\t\tSystem.out.println(1);\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\tint primeFactors = 0;\n\t\tlong winPosition = 1;\n\t\tfor (int i = 0; i < primes.length; i++) {\n\t\t\twhile (x % primes[i] == 0) {\n\t\t\t\tx /= primes[i];\n\t\t\t\tprimeFactors++;\n\t\t\t\twinPosition *= primes[i];\n\t\t\t\tif (primeFactors == 2 && winPosition != xx) {\n\t\t\t\t\tSystem.out.println(1);\n\t\t\t\t\tSystem.out.println(winPosition);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\t\t\n\t\t}\n\t\tSystem.out.println(2);\n\t}\n\n\tprivate static boolean isPrime(long x) {\n\t\tif (x == 1 || x == 2)\n\t\t\treturn true;\n\t\tif (x % 2 == 0)\n\t\t\treturn false;\n\t\tfor (long i = 3; i * i <= x; i += 2)\n\t\t\tif (x % i == 0)\n\t\t\t\treturn false;\n\t\treturn true;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a05903671b89a4253dc936f412f613e7", "src_uid": "1f9107e8d1d8aebb1f4a1707a6cdeb6d", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "public class A976 {\n\n\tpublic static void main(String[] args) {\n\t\tsc sc= new sc();\n\t\tint a = sc.nextInt();\n\t\tString s = sc.next();\n\t\tint z= countZ(s);\n\t\tif(s.equals(\"0\"))\n\t\t\tSystem.out.println(\"0\");\n\t\telse\n\t\tif (z==0)\n\t\t\tSystem.out.println(\"1\");\n\t\telse {\n\t\t\tSystem.out.print(\"1\");\n\t\t\tfor (int i = 0; i < z; i++) {\n\t\t\t\tSystem.out.print(\"0\");\n\t\t\t}\n\t\t}\n\t\t\n\t}\n\tpublic static int countZ (String s) {\n\t\tint x =0;\n\t\tfor (int i = 0; i < s.length(); i++) {\n\t\t\tif(s.charAt(i)=='0')\n\t\t\t\tx++;\n\t\t}\n\t\treturn x;\n\t}\n\n}\nclass sc {\n\tBufferedReader br;\n\tStringTokenizer st;\n\n\tpublic sc() {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t}\n\n\tString next() {\n\t\twhile (st == null || !st.hasMoreElements()) {\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\tint nextInt() {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tlong nextLong() {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tString nextLine() {\n\t\tString str = \"\";\n\t\ttry {\n\t\t\tstr = br.readLine();\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t\treturn str;\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "87ca74863ea05a428647373709b309a5", "src_uid": "ac244791f8b648d672ed3de32ce0074d", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in Actual solution is at the top\n *\n * @author Jatin Yadav\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 EasterEggs solver = new EasterEggs();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class EasterEggs {\n InputReader in;\n PrintWriter out;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n this.in = in;\n this.out = out;\n //int t = ni();\n //for (int i = 1; i <= t; i++) {\n //out.print(\"Case #\" + i + \": \");\n //solve();\n //out.println();\n //}\n //for (int i = 0; i < t; i++)\n solve();\n }\n\n public void solve() {\n int n = ni();\n String s1 = \"ROYG\";\n String s2 = \"BIV\";\n int times = n / 4;\n int rem = n % 4;\n String ans = s1.repeat(Math.max(0, times))\n + s2.substring(0, rem);\n out.println(ans);\n }\n\n private int ni() {\n return in.nextInt();\n }\n }\n\n static class InputReader {\n private final InputStream stream;\n private final byte[] buf = new byte[8192];\n private int curChar;\n private int snumChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int snext() {\n if (snumChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= snumChars) {\n curChar = 0;\n try {\n snumChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (snumChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = snext();\n while (isSpaceChar(c)) {\n c = snext();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = snext();\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 = snext();\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", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3348bd41fa1ec8360a3f0bffadd2ca63", "src_uid": "dc3817c71b1fa5606f316e5e94732296", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "package z;\n\nimport java.util.*;\n\npublic class Main {\n\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 ArrayList exams = new ArrayList();\n Map dayExam = new HashMap<>();\n int ddd;\n for(int i=0;i{\n int examDay;\n int prepDays;\n int questionsDays;\n int examID;\n static int examsCounter=1;\n\n public Exam(int questionsDays,int examDay, int prepDays) {\n this.examID=examsCounter;\n examsCounter++;\n this.questionsDays=questionsDays;\n this.examDay = examDay;\n this.prepDays = prepDays;\n }\n int prepare(int i){\n if (prepDays!=0&&questionsDays<=i) {\n prepDays--;\n return examID;\n }\n return 0;\n }\n\n @Override\n public int compareTo(Exam other) {\n if(this.questionsDays= 0) have++;\n }\n return have;\n }\n \n static long calcB(int i, int b) {\n long have = b/2;\n long left = b - have * 2;\n have*=7;\n for(int j = 0; j < 7; j++) {\n if(left < 0) break;\n int get = (j+i)%7;\n if(get == 1 || get == 5) {\n left--;\n }\n if(left >= 0) have++;\n }\n return have;\n }\n \n static long calcC(int i, int b) {\n long have = b/2;\n long left = b - have * 2;\n have*=7;\n for(int j = 0; j < 7; j++) {\n if(left < 0) break;\n int get = (j+i)%7;\n if(get == 2 || get == 4) {\n left--;\n }\n if(left >= 0) have++;\n }\n return have;\n }\n \n \n static class ABCDEFGHIJKLMNOPQRSTUVWXYZScanner \n { \n BufferedReader br; \n StringTokenizer st; \n \n public ABCDEFGHIJKLMNOPQRSTUVWXYZScanner() \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 int[] nia(int n) {\n int[] res = new int[n];\n for(int i = 0; i < n; i++) res[i] = nextInt();\n return res;\n }\n \n long nextLong() \n { \n return Long.parseLong(next()); \n }\n \n long[] nla(int n) {\n long[] res = new long[n];\n for(int i = 0; i < n; i++) res[i] = nextLong();\n return res;\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", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3e6d29ef813ea255ece20c028b8a295a", "src_uid": "e17df52cc0615585e4f8f2d31d2daafb", "difficulty": 1400.0} {"lang": "Java 7", "source_code": " import java.util.*;\n public class Main{\n public static void main (string [] args){\n int n=0;\n Scanner in = new Scanner (System.in);\n\n int x = in.nextInt();\n\n\n if(x==1 || x==2){\n System.out.print(\"2\");\n}\n\n if(x>=3 && x<6)\n System.out.print(\"3\");\n \n if(x>=6 && x<=13)\n System.out.print(\"5\");\n\n if(x>=14 && x<=25)\n System.out.print(\"7\");\n\nif(x>=26 && x<=41)\n System.out.print(\"9\");\n\nif(x>=42 && x<=61)\n System.out.print(\"11\");\n\nif(x>=62 && x<=85)\n System.out.print(\"13\");\n\nif(x>=86 && x<=100)\n System.out.print(\"15\");\n \n}\n}\n\n\n\n\n ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "72e7dafc6a99ba9cc89839a28dc8c91a", "src_uid": "01eccb722b09a0474903b7e5abc4c47a", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.InputMismatchException;\nimport java.io.PrintStream;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.io.Writer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Nipuna Samarasekara\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastScanner in = new FastScanner(inputStream);\n\t\tFastPrinter out = new FastPrinter(outputStream);\n\t\tTaskB solver = new TaskB();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskB {\n /////////////////////////////////////////////////////////////\n public void solve(int testNumber, FastScanner in, FastPrinter out) {\n int n=in.nextInt(),d=in.nextInt();\n int[] c= in.readIntArray(n);\n boolean[] dp= new boolean[520005];\n dp[0]=true;\n int max=0;\n for (int i = 0; i < n; i++) {\n for (int j = 500004-c[i]; j >=0 ; j--) {\n if(dp[j]){dp[j+c[i]]=true;\n // max=Math.max(max,j+c[i]);\n }\n }\n }\n // deb(dp);\n int days=0,cur=0;\n int cc=1;\n while(cc==1){\n cc=0;\n int i;\n for ( i = cur+d; i >cur; i--) {\n if(dp[i]){\n cc=1;\n cur=i;\n // System.out.println(cur);\n break;\n }\n }\n if(cc==0)break;\n days++;\n\n }\n out.println(cur+\" \"+days);\n\n }\n}\n\nclass FastScanner extends BufferedReader {\n\n public FastScanner(InputStream is) {\n super(new InputStreamReader(is));\n }\n\n public int read() {\n try {\n int ret = super.read();\n// if (isEOF && ret < 0) {\n// throw new InputMismatchException();\n// }\n// isEOF = ret == -1;\n return ret;\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n }\n\n static boolean isWhiteSpace(int c) {\n return c >= 0 && c <= 32;\n }\n\n public int nextInt() {\n int c = read();\n while (isWhiteSpace(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int ret = 0;\n while (c >= 0 && !isWhiteSpace(c)) {\n if (c < '0' || c > '9') {\n throw new NumberFormatException(\"digit expected \" + (char) c\n + \" found\");\n }\n ret = ret * 10 + c - '0';\n c = read();\n }\n return ret * sgn;\n }\n\n public String readLine() {\n try {\n return super.readLine();\n } catch (IOException e) {\n return null;\n }\n }\n\n public int[] readIntArray(int n) {\n int[] ret = new int[n];\n for (int i = 0; i < n; i++) {\n ret[i] = nextInt();\n }\n return ret;\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", "compilation_error": false, "code_uid": "2d1d7622d49b8855d475dd7df99c3493", "src_uid": "65699ddec8d0db2f58b83a0f64de6f6f", "difficulty": 2200.0} {"lang": "Java 11", "source_code": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\n\npublic class AlyonaAndNumbers \n{\n\tpublic static void main(String[] args)\n\t{\n\t\tInputStream is=System.in;\n\t\tOutputStream out=System.out;\n\t\tFastScanner scan=new FastScanner(is);\n\t\tint n=scan.nextInt();\n\t\tint m=scan.nextInt();\n\t\tint count=0;\n\t\tfor(int i=1;i<=n;i++)\n\t\t{\n\t\t\tfor(int j=1;j<=m;j++)\n\t\t\t{\n\t\t\t\tif((i+j)%5==0) \n\t\t\t\t{\n\t\t\t\t\tcount++;\n\t\t\t\t\t//System.out.println(i+\" \"+j);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(count);\n\t}\n\n}\n class FastScanner\n\t\t {\n\t\t StringTokenizer st;\n\t\t BufferedReader br;\n\t\t \n\t\t public FastScanner(InputStream is) \n\t\t {\t\n\t\t \t br=new BufferedReader(new InputStreamReader(is)); \n\t\t }\n\t\t public FastScanner(File file) \n\t\t {\n\t\t \t try\n\t\t \t {\n\t\t \t\t br=new BufferedReader(new FileReader(file));\n\t\t \t } \n\t\t \t catch (FileNotFoundException e)\n\t\t \t {\n\t\t \t \t\te.printStackTrace();\n\t\t \t } \n\t\t }\n\t\t public String next() \n\t\t { \n\t\t \t while(st==null||! st.hasMoreElements()) \n\t\t \t {\n\t\t \t\t String s=null;\n\t\t \t\t try \n\t\t \t\t {\n\t\t \t\t\t s=br.readLine();\n\t\t \t\t }\n\t\t \t\t catch(IOException e) \n\t\t \t\t {\n\t\t \t\t\t e.printStackTrace();\n\t\t \t\t }\n\t\t \t\t \n\t\t \t\t if(s==null) \n\t\t \t\t {\n\t\t \t\t\t return null;\n\t\t \t\t }\n\t\t \t\t st=new StringTokenizer(s);\n\t\t \t }\n\t\t \t return st.nextToken();\n\t\t \t \n\t\t }\n\t\t \n\t\t public int nextInt() \n\t\t {\n\t\t \t\n\t\t \t return Integer.parseInt(next());\n\t\t }\n\t\t \n\t\t }\n\n\t\n\n\t \n\t\t class FastPrinter extends PrintWriter\n\t\t {\n\t\t public FastPrinter(OutputStream out)\n\t\t {\n\t\t \n\t\t \t super(out);\n\t\t }\n\n\t\t public FastPrinter(Writer out)\n\t\t {\n\t\t super(out);\n\t\t }\n\n\t\t }\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c4f697956c2c2188d596a2f2cca24d68", "src_uid": "df0879635b59e141c839d9599abd77d2", "difficulty": 1100.0} {"lang": "Java 11", "source_code": "\nimport java.util.*;\nimport java.lang.*;\n\npublic class R\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 int lo = 1, hi = n;\n int mid = 0;\n int ans = 0;\n while( lo < hi ) {\n mid = (lo + hi)>>1;\n if ( is(mid,n,k) ) {\n ans = mid;\n hi = mid;\n } else {\n lo = mid + 1;\n }\n System.out.println(lo);\n }\n public static boolean is( int mid, int n, int k ) {\n int val = mid, temp = 0;\n int x = k;\n if( mid == n) return true;\n while( val < n ) {\n \n temp = (mid/x);\n if(temp == 0) { return false; }\n val += temp;\n x *= k;\n }\n return true;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "13398bbcad6480225ef3fcdfec940ae4", "src_uid": "41dfc86d341082dd96e089ac5433dc04", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.PrintStream;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.math.BigInteger;\nimport java.io.BufferedReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Wolfgang Beyer\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskD solver = new TaskD();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskD {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n long a1 = in.nextLong();\n long b1 = in.nextLong();\n long a2 = in.nextLong();\n long b2 = in.nextLong();\n long L = in.nextLong();\n long R = in.nextLong();\n\n //Extended Euclid for a1 and a2\n long r0 = a1;\n long r1 = a2;\n //r0 = 240;\n //r1 = 46;\n long r2;\n\n long s0 = 1;\n long s1 = 0;\n long s2;\n\n long t0 = 0;\n long t1 = 1;\n long t2;\n\n while (r0 % r1 != 0) {\n long q = r0 / r1;\n r2 = r0 - q * r1;\n s2 = s0 - q * s1;\n t2 = t0 - q * t1;\n\n r0 = r1;\n r1 = r2;\n s0 = s1;\n s1 = s2;\n t0 = t1;\n t1 = t2;\n }\n if ((b1 - b2) % r1 != 0) {\n out.println(0);\n return;\n }\n //System.out.println(r1 + \" \" + s1 + \" \" + t1);\n //long x = b1 * t1 * a2 + b2 * s1 * a1;\n //long x = (b1 * t1 * a2 + b2 * s1 * a1) / r1;\n long scm = Math.abs(a1 * a2) / r1;\n //System.out.println(\"scm: \" + scm);\n\n BigInteger x2 = BigInteger.valueOf(b1).multiply(BigInteger.valueOf(t1)).multiply(BigInteger.valueOf(a2)).add(BigInteger.valueOf(b2).multiply(BigInteger.valueOf(s1)).multiply(BigInteger.valueOf(a1))).divide(BigInteger.valueOf(r1));\n BigInteger x3 = x2.mod(BigInteger.valueOf(scm));\n long x = x3.longValue();\n //System.out.println(\"x: \" + x3.toString());\n //System.out.println(\"x: \" + x);\n\n if ((R < b1) || (R < b2)) {\n out.println(0);\n return;\n }\n L = Math.max(L, b1);\n L = Math.max(L, b2);\n R = Math.max(R, b1);\n R = Math.max(R, b2);\n\n /*System.out.println(L + \" \" + R);\n long q1 = (long) Math.ceil((double) (L - x) / scm) - 1;\n long q2 = (long) Math.floor((double) (R - x) / scm) + 1;\n System.out.println((double) (L - x) / scm);\n System.out.println((double) (R - x) / scm);\n System.out.println(q1 + \" \" + q2);\n out.println(Math.abs(q2 - q1) - 1);*/\n\n long v1 = Math.round((double) (L - x) / scm);\n long lower = x + v1 * scm;\n while (lower >= L) lower -= scm;\n while (lower + scm < L) lower += scm;\n long v2 = Math.round((double) (R - x) / scm);\n long higher = x + v2 * scm;\n while (higher <= R) higher += scm;\n while (higher - scm > R) higher -= scm;\n out.println((higher - lower) / scm - 1);\n }\n\n }\n\n static class InputReader {\n private static BufferedReader in;\n private static StringTokenizer tok;\n\n public InputReader(InputStream in) {\n this.in = new BufferedReader(new InputStreamReader(in));\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public String next() {\n try {\n while (tok == null || !tok.hasMoreTokens()) {\n tok = new StringTokenizer(in.readLine());\n }\n } catch (IOException ex) {\n System.err.println(\"An IOException was caught :\" + ex.getMessage());\n }\n return tok.nextToken();\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5562a889d364fd04e03b187c521bb2a8", "src_uid": "b08ee0cd6f5cb574086fa02f07d457a4", "difficulty": 2500.0} {"lang": "Java 7", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int n = scan.nextInt();// \u4eba\u6570\n int m = scan.nextInt();// \u4fe1\u606f\u91cf\n boolean boss[] = new boolean[n + 1];// \u662f\u5426\u662fleader\n boolean find[] = new boolean[n + 1];// \u6d88\u606f\u4e2d\u51fa\u73b0\u7684\u4eba\u4e2d\u7684leader\n Arrays.fill(boss, true);\n int home = 0;// \u623f\u95f4\u4eba\u6570\n boolean in[] = new boolean[n + 1];// \u662f\u5426\u5728\u623f\u95f4\u4e2d\n int leader = 0;// \u5f53\u524dleader\n int sum = 0;// leader\u4eba\u6570;\n for (int i = 1; i <= m; i++) {\n String s = scan.next();\n int x = scan.nextInt();\n boss[x] = false;\n if (s.equals(\"+\")) {\n if (home == 0&&x!=leader) {\n leader = x;\n sum++;\n }\n home++;\n in[x] = true;\n } else if (s.equals(\"-\")) {\n if (in[x] == false) {\n sum = 0;\n if (home == 0&&x!=leader) {\n leader = x;\n sum++;\n }\n // System.out.println(sum+\"\u3000\"+home);\n } else if (in[x] == true) {\n if (home == 0&&x!=leader) {\n leader = x;\n sum++;\n in[x] = false;\n }\n home--;\n }\n }\n// System.out.println(home+\" \"+leader+\" \"+sum);\n }\n// System.out.println(leader);\n// System.out.println(sum);\n if (sum == 1) {\n boss[leader] = true;\n }\n int count = 0;\n for (int i = 1; i <= n; i++) {\n if (boss[i])\n count++;\n }\n System.out.println(count);\n for (int i = 1; i <= n; i++) {\n if (boss[i])\n System.out.print(i + \" \");\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c378b91241f96295de8a1473afd5bf7e", "src_uid": "a3a337c7b919e7dfd7ff45ebf59681b5", "difficulty": 1800.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.StringTokenizer;\n\npublic class Main {\n static long pow(int base, int exp)\n {\n long res = 1;\n while(exp > 0)\n {\n if(exp % 2 == 1)\n res = (res*base)%mod;\n base = (base*base)%mod;\n exp /= 2;\n }\n return res;\n }\n static int mod = 1000000007;\n static void zap() throws IOException {\n char[] num = nextToken().toCharArray();\n int len = num.length;\n long sum = 0;\n for(int i=len-1;i>=0;i--)\n {\n if(num[i] == '1')\n sum = (sum + pow(2, len-i-1) * pow(2, len-1))%mod;\n }\n out.println(sum);\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 br = new BufferedReader(new InputStreamReader(input));\n out = new PrintWriter(System.out);\n zap();\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "53b85785d31f78b5e9c933e455a4f149", "src_uid": "89b51a31e00424edd1385f2120028b9d", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n\n\npublic class coins{\n\t\n\tpublic static void main(String[] args){\n\t\tScanner s = new Scanner(System.in);\n\t\tint x = s.nextInt();\n\t\tint v = x;\n\t\tint highP = x;\n\t\tint count = 0;\n\t\tStringBuilder output = new StringBuilder();\n\t\t\n\t\twhile(v != 0){\n\t\t\tfor(int i = highP; i >= 2; i--)\n\t\t\t{\n\t\t\t\tif(isPrime(i) && i <= v && v-i != 1){\n\t\t\t\t\tif(count == 1 && !isPrime(v-i) && v-i!= 0) break;\n\t\t\t\t\thighP = v-i;\n\t\t\t\t\tv -= i;\n\t\t\t\t\toutput.append(i + \" \");\n\t\t\t\t\tcount++;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(count);\n\t\tSystem.out.println(output);\n\t\t\n\t}\n\t\n\tpublic static boolean isPrime(int num) {\n\t\tif (num % 2 == 0 && num != 2) return false;\n for (int i = 3; i * i <= num; i += 2)\n if (num % i == 0) return false;\n return true;\n }\n\t\n\t\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c3fc1ecd7c19fb1a5cd30b4179c0b0c9", "src_uid": "f2aaa149ce81bf332d0b5d80b2a13bc3", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.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 HossamDoma\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskB solver = new TaskB();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskB {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n\n int m = in.nextInt();\n int n = in.nextInt();\n int time = in.nextInt();\n int[] cost = new int[n];\n\n int v = 0;\n for (int i = 0; i < n; ++i) {\n cost[i] = in.nextInt();\n v += cost[i];\n }\n\n Arrays.sort(cost);\n int h = cost[0] * m;\n\n int solved = 0;\n\n int tmp = time;\n for (int i = 0; i < n; ++i) {\n for (int j = 0; j < m; ++j) {\n if (time >= cost[i]) {\n time -= cost[i];\n solved++;\n }\n }\n }\n\n\n int solved2 = 0;\n time = tmp;\n for (int j = 0; j < m; ++j) {\n for (int i = 0; i < n; ++i) {\n if (time >= cost[i]) {\n time -= cost[i];\n solved2 += 1 + (i == n - 1 ? 1 : 0);\n }\n }\n }\n\n\n out.println(Math.max(solved, solved2));\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8ead7ade0663a65c8f786e5a70b25675", "src_uid": "d659e92a410c1bc836be64fc1c0db160", "difficulty": 1800.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\npublic class Intersection {\n\tpublic static int GCD(int a, int b, int c){\n\t\tif (a==0){\n\t\t\ta=Math.max(b,c);\n\t\t}\n\t\tif (b==0){\n\t\t\tb=Math.max(a,c);\n\t\t}\n\t\tif (c==0){\n\t\t\tc=Math.max(a,c);\n\t\t}\n\tint limit = Math.min(a, b);\n limit = Math.min(limit, c);\n for(int n = limit; n >= 2; n--)\n {\n if ( (a % n == 0) && (b % n == 0) && (c % n == 0) ) {\n return n;\n }\n }\n\n return 1;\n\t}\n\n public static void main (String [] args){\n \tScanner sc=new Scanner(System.in);\n \tString S1[]=sc.nextLine().split(\" \"); \n \tString S2[]=sc.nextLine().split(\" \");\n \tint I1[]=new int [S1.length];\n \tint I2[]=new int [S1.length];\n \t\n \t\n \t\n \tfor (int i=0; i res = new ArrayList<>();\n res.add((char) candi[0]);\n int i = 0, j = 0;\n while (j < candi.length) {\n if ((candi[j] - res.get(i)) >= 2) {\n i++;\n res.add((char) candi[j]);\n }\n j++;\n }\n if (k <= n && k <= res.toArray().length) {\n int count = 0;\n for (int h = 0; h < k; h++) {\n count += ((int) res.get(h))-96;\n }\n System.out.print(count);\n } else\n System.out.print(-1);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "946ca43591533bc39a8133ce47c7072d", "src_uid": "56b13d313afef9dc6c6ba2758b5ea313", "difficulty": 900.0} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.math.*;\n\npublic class Pair {\n int first, second;\n Pair(int a, int b) {\n first = a;\n second = b;\n }\n};\n\npublic class Main {\n static int inf = (1 << 30); \n public static void main(String arg[]) {\n Scanner input = new Scanner(System.in);\n int n = input.nextInt();\n int[] a = new int[4], b = new int[4], c = new int[4], d = new int[4];\n Pair[] p = new Pair[4];\n \n int leastMoney = inf, position = -1;\n for(int i = 0; i < 4; i++) {\n a[i] = input.nextInt();\n b[i] = input.nextInt();\n c[i] = input.nextInt();\n d[i] = input.nextInt();\n p[i] = new Pair(Math.min(a[i], b[i]), Math.min(c[i], d[i]));\n if (p[i].first + p[i].second < leastMoney) {\n leastMoney = p[i].first + p[i].second;\n position = i;\n }\n }\n if (leastMoney > n) {\n System.out.println(-1);\n } else {\n System.out.println((position + 1) + \" \" + p[position].first + \" \" + (n - p[position].first));\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3c44a2ca116eae1a6d5e979cabf59d6a", "src_uid": "6e7ee0da980beb99ca49a5ddd04089a5", "difficulty": 1100.0} {"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\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", "compilation_error": false, "code_uid": "a7e83388a1aa5d00cc7e3bf5e27a85f1", "src_uid": "ed0925cfaee961a3ceebd13b3c96a15a", "difficulty": 2300.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class Numbers {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\t\n\t\tint A = sc.nextInt();\n\t\tint sum = 0;\n\t\t\n\t\tfor(int i = 2; i < A; i++){\n\t\t\tint tmp = A;\n\t\t\t\n\t\t\twhile(tmp != 0){\n\t\t\t\tsum += (tmp % i);\n\t\t\t\ttmp = tmp/i;\n\t\t\t}\n\t\t}\n\t\t\n\t\tlong g = Library.gcd(sum, A - 2);\n\t\t\n\t\tSystem.out.println(sum/g + \"/\" + (A - 2)/g);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7cee737ac55b78cf66dfd1a395198962", "src_uid": "1366732dddecba26db232d6ca8f35fdc", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class PowerBoard {\r\n public static void main(String[] args) throws IOException {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n StringTokenizer st = new StringTokenizer(br.readLine());\r\n int[] spf = new int[1_000_001];\r\n Arrays.fill(spf, 1);\r\n for (int i=2; i<=1_000; i++) if (spf[i]==1)\r\n for (int j=i; j<=1_000_000; j+=i) if (spf[j]==1)\r\n spf[j] = i;\r\n int N = Integer.parseInt(st.nextToken());\r\n int M = Integer.parseInt(st.nextToken());\r\n boolean[] v = new boolean[20*M+1];\r\n int[] cnt = new int[20];\r\n for (int i=1; i<20; i++) {\r\n for (int j=1; j<=M; j++) {\r\n if (v[i*j]) continue;\r\n v[i*j] = true;\r\n cnt[i]++;\r\n }\r\n }\r\n for (int i=2; i<20; i++)\r\n cnt[i] += cnt[i-1];\r\n long now = 1;\r\n boolean[] power = new boolean[N+1];\r\n for (int p=2; p<=N; p++) {\r\n if (power[p]) continue;\r\n int cpow = 2;\r\n for (int k=p*p; k<=N; k*=p, cpow++) {\r\n power[k] = true;\r\n }\r\n cpow--;\r\n now += cnt[cpow];\r\n }\r\n System.out.println(now);\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e588b44e9999443b0c6d12c5d493013c", "src_uid": "6ca310cb0b6fc4e62e63a731cd55aead", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.util.concurrent.ConcurrentHashMap;\n\n\n\n\npublic class Main {\n private final static long mod = 1000000007;\n\n private final static int MAXN = 100001;\n\n private static long power(long x, long y, long m) {\n long temp;\n if (y == 0)\n return 1;\n temp = power(x, y / 2, m);\n temp = (temp * temp) % m;\n if (y % 2 == 0)\n return temp;\n else\n return ((x % m) * temp) % m;\n }\n\n private static long power(long x, long y) {\n return power(x, y, mod);\n }\n\n private static long gcd(long a, long b) {\n if (b == 0) return a;\n return gcd(b, a % b);\n }\n\n static int nextPowerOf2(int a) {\n return 1 << nextLog2(a);\n }\n\n static int nextLog2(int a) {\n return (a == 0 ? 0 : 32 - Integer.numberOfLeadingZeros(a - 1));\n }\n\n private static long modInverse(long a, long m) {\n long m0 = m;\n long y = 0, x = 1;\n if (m == 1)\n return 0;\n while (a > 1) {\n long q = a / m;\n long t = m;\n m = a % m;\n a = t;\n t = y;\n y = x - q * y;\n x = t;\n }\n if (x < 0)\n x += m0;\n return x;\n }\n\n\n private static class Pair {\n T a;\n 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 Pair pair = (Pair) o;\n return a.equals(pair.a) &&\n b.equals(pair.b);\n }\n\n @Override\n public int hashCode() {\n return Objects.hash(a, b);\n }\n\n @Override\n public String toString() {\n return \"(\" + a +\n \",\" + b +\n ')';\n }\n }\n\n private static int log[]= new int[MAXN+1];\n\n private static int getLRMax(int st[][], int L, int R){\n int j = log[R - L + 1];\n return Math.max(st[L][j], st[R - (1 << j) + 1][j]);\n }\n\n private static int[][] getSparseTable(int array[]){\n int k= log[MAXN]+1;\n int st[][]=new int[MAXN][k+1];\n\n for (int i = 0; i < array.length; i++)\n st[i][0] = array[i];\n\n for (int j = 1; j <= k; j++) {\n for (int i = 0; i + (1 << j) <= array.length; i++) {\n st[i][j] = Math.max(st[i][j-1], st[i + (1 << (j - 1))][j - 1]);\n }\n }\n return st;\n }\n\n\n private static String bruteForce(int n,int m,int []a) {\n int t, i, j, l, r, c, p, q, ti, tidx, d;\n StringBuilder ans=new StringBuilder();\n Listlist=new ArrayList<>();\n for(int e:a){\n Collections.sort(list);\n int sum=0;\n for(i=0;i maxHeap = new PriorityQueue<>(Collections.reverseOrder());\n PriorityQueue minHeap = new PriorityQueue<>();\n long maxHeapSum=0;\n StringBuilder ans = new StringBuilder();\n for(int e:a) {\n while(maxHeapSum>m-e&&!maxHeap.isEmpty()){\n p=maxHeap.poll();\n minHeap.add(p);\n maxHeapSum-=p;\n }\n maxHeap.add(e);\n maxHeapSum+=e;\n while(!minHeap.isEmpty()){\n p=minHeap.peek();\n if(maxHeapSum+p<=m){\n maxHeapSum+=p;\n minHeap.poll();\n maxHeap.add(p);\n }\n else{\n break;\n }\n }\n ans.append(minHeap.size());\n ans.append(' ');\n if(!maxHeap.isEmpty()){\n p=maxHeap.poll();\n minHeap.add(p);\n maxHeapSum-=p;\n while(!minHeap.isEmpty()){\n p=minHeap.peek();\n if(maxHeapSum+p<=m){\n maxHeapSum+=p;\n minHeap.poll();\n maxHeap.add(p);\n }\n else{\n break;\n }\n }\n }\n\n }\n out.println(ans.toString());\n\n }\n }\n }\n\n\n static class FastReader implements Closeable {\n private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n private StringTokenizer st;\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n 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 int[] nextIntArr(int n) {\n int[] arr = new int[n];\n for (int i = 0; i < n; i++) {\n arr[i] = nextInt();\n }\n return arr;\n }\n\n double[] nextDoubleArr(int n) {\n double[] arr = new double[n];\n for (int i = 0; i < n; i++) {\n arr[i] = nextDouble();\n }\n return arr;\n }\n\n long[] nextLongArr(int n) {\n long[] arr = new long[n];\n for (int i = 0; i < n; i++) {\n arr[i] = nextLong();\n }\n return arr;\n }\n\n String[] nextStrArr(int n) {\n String[] arr = new String[n];\n for (int i = 0; i < n; i++) {\n arr[i] = next();\n }\n return arr;\n }\n\n int[][] nextIntArr2(int n, int m) {\n int[][] arr = new int[n][m];\n for (int i = 0; i < n; i++) {\n arr[i] = nextIntArr(m);\n }\n return arr;\n }\n\n long[][] nextLongArr2(int n, int m) {\n long[][] arr = new long[n][m];\n for (int i = 0; i < n; i++) {\n arr[i] = nextLongArr(m);\n }\n return arr;\n }\n\n @Override\n public void close() throws IOException {\n br.close();\n }\n }\n\n static class FastWriter implements Closeable {\n BufferedWriter bw;\n List list = new ArrayList<>();\n Set set = new HashSet<>();\n\n FastWriter() {\n bw = new BufferedWriter(new OutputStreamWriter(System.out));\n }\n\n void print(T obj) throws IOException {\n bw.write(obj.toString());\n bw.flush();\n }\n\n void println() throws IOException {\n print(\"\\n\");\n }\n\n void println(T obj) throws IOException {\n print(obj.toString() + \"\\n\");\n }\n\n void printArrLn(T[] arr) throws IOException {\n for (int i = 0; i < arr.length - 1; i++) {\n print(arr[i] + \" \");\n }\n println(arr[arr.length - 1]);\n }\n\n void printArr2(T[][] arr) throws IOException {\n for (int j = 0; j < arr.length; j++) {\n for (int i = 0; i < arr[j].length - 1; i++) {\n print(arr[j][i] + \" \");\n }\n println(arr[j][arr.length - 1]);\n }\n }\n\n void printColl(Collection coll) throws IOException {\n for (T e : coll) {\n print(e + \" \");\n }\n println();\n }\n\n void printCharN(char c, int n) throws IOException {\n for (int i = 0; i < n; i++) {\n print(c);\n }\n }\n\n void printIntArr2(int[][] arr) throws IOException {\n for (int j = 0; j < arr.length; j++) {\n for (int i = 0; i < arr[j].length - 1; i++) {\n print(arr[j][i] + \" \");\n }\n println(arr[j][arr.length - 1]);\n }\n }\n\n @Override\n public void close() throws IOException {\n bw.close();\n }\n }\n\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "294a485110443ccf69beeca38bb9bd89", "src_uid": "d3c1dc3ed7af2b51b4c49c9b5052c346", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Test {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner sc =new Scanner(System.in);\n\t\tlong s =sc.nextLong();\n\t\tlong x =sc.nextLong();\n\t\tlong or =s+x;\n\t\tlong and =s-x;\n\t\tlong tot=1,to=0;\n\t\tif((or & 1) ==0 && (and & 1)==0){\n\t\t\tor = or>>1;\n\t\t\tand =and>>1;\n\t\t\tif(and==0){\n\t\t\t\tto+=2;\n\t\t\t}\n\t\t\tboolean cd =true;\n\t\t\twhile(and!=0 || or!=0){\n\t\t\t\tif(and%2!=1){\n\t\t\t\t\tif(or%2!=0){\n\t\t\t\t\t\tif(x%2==1){\n\t\t\t\t\t\t\ttot<<=1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse{\n\t\t\t\t\t\t\tSystem.out.println(0);\n\t\t\t\t\t\t\tcd =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}\n\t\t\t\tand>>=1;\n\t\t\t\tor>>=1;\n\t\t\t\tx>>=1;\n\t\t\t}\n\t\t\tif(cd){\n\t\t\t\tSystem.out.println((tot-to));\n\t\t\t}\n\t\t}\n\t\telse{\n\t\t\tSystem.out.println(0);\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "02a88ffa3abe21cf820c6ac77ff7d94d", "src_uid": "18410980789b14c128dd6adfa501aea5", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.List;\nimport java.util.Scanner;\npublic class sobel {\n\tpublic static boolean check(String s){\n\t\tfor (int i = 0 ;i < s.length() ; i++){\n\t\t\tif (s.charAt(i) == '8')\n\t\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tlong n;\n\t\tn = in.nextLong();\n\n\t\tint h = 0;\n\t\twhile (true) {\n\t\t\tif (check(String.valueOf(n+h))) {\n\t\t\t\tSystem.out.print(h);\n\t\t\t\tSystem.exit(0);\n\t\t\t}\n\t\t\th++;\n\t\t}\n\t\tin.close();\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3565421d2e8c66ccc2aa682a69549b53", "src_uid": "4e57740be015963c190e0bfe1ab74cb9", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class partyLemonade {\n\t\n\tpublic static int minPrice(int[] price,int[] vol,int volreq)\n\t{\n\t\tint[][] arr=new int[vol.length][volreq+1];\n\t\t\n\t\tfor(int i=0;i=vol[i])\n\t\t\t\t\t\tarr[i][j]=Math.min(arr[i-1][j], price[i]+arr[i][j-vol[i]]);\n\t\t\t\t\telse\n\t\t\t\t\t\tarr[i][j]=Math.min(arr[i-1][j], price[i]);\n\t\t\t\t\t/*System.out.println(\"i j arr[i][j] \"+i+\" \"+j +\" arr \"+arr[i][j]);*/\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn arr[vol.length-1][volreq];\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner s=new Scanner(System.in);\n\t\t\n\t\tint n=s.nextInt();\n\t\tint volreq=s.nextInt();\n\t\tint[] price=new int[n];\n\t\tfor(int i=0;i 0 && args[0].equals(\"devTesting\")) {\n try {\n inputStream = new FileInputStream(args[1]);\n } catch(FileNotFoundException e) {\n throw new RuntimeException(e);\n }\n } else {\n inputStream = System.in;\n }\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskD solver = new TaskD();\n solver.solve(1, in, out);\n out.close();\n }\n \n static class TaskD { \n final int ring = (int) 1e9 + 7;\n int n, inik;\n String s;\n int[][][] state;\n \n void solve(int testNumber, InputReader in, PrintWriter out) {\n n = in.nextInt();\n s = in.next();\n state = new int[n + 1][n + 1][1 << 16];\n for (int[][] i : state) {\n for (int[] j : i) {\n Arrays.fill(j, -1);\n }\n }\n long ans = 0;\n for (int i = 2; i <= n + 1; ++i) {\n for (int j = 0; j < s.length(); ++j) { \n ans = add(ans, go(i - 1, j, 0));\n }\n }\n out.println(ans);\n }\n \n long go(int k, int p, int m) {\n if (state[k][p][m] != -1) {\n return state[k][p][m];\n }\n if (k == 0) {\n if ((m & 1) == 0 && Integer.bitCount((m >> 1) + 1) == 1) {\n return 1;\n }\n return 0;\n } else {\n if (p >= s.length()) {\n return 0;\n }\n }\n long ans = 0;\n for (int i = p; i <= s.length() - 1; ++i) {\n int x = Integer.parseInt(s.substring(p, i + 1), 2);\n if (x >= 1 << 16) {\n break;\n }\n ans = add(ans, go(k - 1, i + 1, m | 1 << x));\n }\n state[k][p][m] = (int) ans;\n return ans;\n }\n \n long add(long a, long b) {\n long ans = (a + b) % ring;\n if (ans < 0) {\n ans += ring;\n }\n return ans;\n }\n \n int i(long x) {\n return (int) x;\n }\n \n void heapsort(T[] a, int s, int e) {\n Queue queue = new PriorityQueue<>();\n for (int i = s; i <= e; ++i)\n queue.add(a[i]);\n for (int i = s; i <= e; ++i)\n a[i] = queue.poll();\n } \n \n }\n \n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n \n public String nextLine() {\n try {\n return reader.readLine();\n } catch(IOException e) {\n throw new RuntimeException(e);\n }\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n \n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public boolean hasInput() {\n try {\n if (tokenizer != null && tokenizer.hasMoreTokens()) {\n return true;\n }\n reader.mark(1);\n int ch = reader.read();\n if (ch != -1) {\n reader.reset();\n return true;\n }\n return false;\n } catch(IOException e) {\n throw new RuntimeException(e);\n }\n }\n \n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "47754b7bba09e41c7daad9a91dfb31bb", "src_uid": "61f88159762cbc7c51c36e7b56ecde48", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main{\n public static void main(String[]args){\n Scanner sc=new Scanner(System.in);\n int s=sc.nextInt();\n int v1=sc.nextInt();\n int v2=sc.nextInt();\n int t1=sc.nextInt();\n int t2=sc.nextInt();\n int first=(s*v1)+(t1*2);\n int second=(s*v2)+(t2*2);\n String rest=\"Friendship\";\n if(firstsecond){\n rest=\"Second\";\n }\n System.out.println(rest);\n }\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ae7ecc80f787602f2b906cda8c92b157", "src_uid": "10226b8efe9e3c473239d747b911a1ef", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class JavaApplication1 {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n // TODO code application logic here\n Scanner scanner=new Scanner(System.in);\n int lemon = scanner.nextInt();\n int apple = scanner.nextInt();\n int pear = scanner.nextInt();\n \n int result=0;\n \n for(int i=lemon;i>0;i--){\n if(2*i<=apple&&4*i<=pear){\n result=i+(2*i)+(4*i);\n System.out.println(result+\"\");\n return;\n }\n \n }\n\n }\n ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "54ccc44d194ffa2d944c90f4c62779d2", "src_uid": "82a4a60eac90765fb62f2a77d2305c01", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class First {\n private static final Scanner sc = new Scanner(System.in);\n private static final PrintWriter pw = new PrintWriter(System.out);\n private static StringBuffer ans = new StringBuffer();\n\n public static void main(String[] args) throws Exception {\n int n = sc.nextInt(), s = 0;\n ArrayList a = new ArrayList<>();\n for (int i = 1; i <= n; i++) {\n a.add(i);\n s += i;\n if (s >= n) break;\n }\n if (s > n) a.remove(new Integer(s - n));\n ans.append(a.size() + \"\\n\");\n for (int x : a) ans.append(x + \" \");\n pw.print(ans);\n sc.close();\n pw.close();\n }\n}\nclass Scanner {\n private final BufferedReader br;\n private StringTokenizer st\n public Scanner(InputStream in) {\n br = new BufferedReader(new InputStreamReader(in));\n st = new StringTokenizer(\"\");\n }\n public String next() throws IOException {\n if (!st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n public void close() throws IOException {\n br.close();\n }\n}\nclass PrintWriter {\n private final BufferedOutputStream pw;\n public PrintWriter(OutputStream out) {\n pw = new BufferedOutputStream(out);\n }\n public void print(Object o) throws IOException {\n pw.write(o.toString().trim().getBytes());\n pw.flush();\n }\n public void close() throws IOException {\n pw.close();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6b7e4830c54d9a1f1a5155b577d508ea", "src_uid": "356a7bcebbbd354c268cddbb5454d5fc", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "// package CodeForces;\n\nimport java.io.BufferedOutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\n\npublic class Round608E {\n\n\tpublic static void solve() {\n\t\tlong n = s.nextLong();\n\t\tlong k = s.nextLong();\n\t\tlong ans = Long.max(EvenBs(n, k), OddBs(n, k));\n\t\tif(ans == 0) throw null;\n\t\tout.println(ans);\n\t}\n\t\n\tpublic static long EvenBs(long limit, long k) {\n\t\tlong start = 1;\n\t\tlong end = limit/2;\n\t\tlong ans = 0;\n\t\twhile(start <= end) {\n\t\t\tlong mid = start + (end - start + 1)/2L;\n\t\t\tlong value = wt(mid * 2L, limit);\n\t\t\tif(value >= k) {\n\t\t\t\tans = mid * 2L;\n\t\t\t\tstart = mid + 1;\n\t\t\t}else {\n\t\t\t\tend = mid - 1;\n\t\t\t}\n\t\t}\n\t\treturn ans;\n\t}\n\t\n\tpublic static long OddBs(long limit, long k) {\n\t\tlong start = 1;\n\t\tlong end = limit/2;\n\t\tlong ans = 0;\n\t\twhile(start <= end) {\n\t\t\tlong mid = start + (end - start + 1)/2L;\n\t\t\tlong my_val = mid * 2 - 1;\n\t\t\tlong my_even = my_val * 2L;\n\t\t\tlong value;\n\t\t\tif(my_even > limit) {\n\t\t\t\tvalue = my_val <= limit ? 1 : 0;\n\t\t\t}else {\n\t\t\t\tvalue = wt(my_even, limit) + 1;\n\t\t\t}\n\t\t\tif(value >= k) {\n\t\t\t\tans = my_val;\n\t\t\t\tstart = mid + 1;\n\t\t\t}else {\n\t\t\t\tend = mid - 1;\n\t\t\t}\n\t\t}\n\t\treturn ans;\n\t}\n\n\tpublic static long wt(long x, long limit) {\n\t\tif(x%2 != 0) throw null;\n\t\tlong start = x;\n\t\tlong ans = 0;\n\t\tlong pow2 = 2;\n\t\twhile(start + pow2 - 1 <= limit) {\n\t\t\tans += pow2;\n\t\t\tstart = start * 2L;\n\t\t\tpow2 *= 2L;\n\t\t}\n\t\tif(limit >= start) ans += (limit - start + 1);\n\t\treturn ans;\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tnew Thread(null, null, \"Thread\", 1 << 27) {\n\t\t\tpublic void run() {\n\t\t\t\ttry {\n\t\t\t\t\tout = new PrintWriter(new BufferedOutputStream(System.out));\n\t\t\t\t\ts = new FastReader(System.in);\n\t\t\t\t\tsolve();\n\t\t\t\t\tout.close();\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t\tSystem.exit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t}.start();\n\t}\n\n\tpublic static PrintWriter out;\n\tpublic static FastReader s;\n\n\tpublic static class FastReader {\n\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[4096];\n\t\tprivate int curChar, snumChars;\n\n\t\tpublic FastReader(InputStream stream) {\n\t\t\tthis.stream = stream;\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\t}\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}\n\t\t\tif (snumChars <= 0) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint number = 0;\n\t\t\tdo {\n\t\t\t\tnumber *= 10;\n\t\t\t\tnumber += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn number * sgn;\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\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 number = 0;\n\t\t\tdo {\n\t\t\t\tnumber *= 10L;\n\t\t\t\tnumber += (long) (c - '0');\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn number * sgn;\n\t\t}\n\n\t\tpublic int[] nextIntArray(int n) {\n\t\t\tint[] arr = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = this.nextInt();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tpublic long[] nextLongArray(int n) {\n\t\t\tlong[] arr = new long[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = this.nextLong();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tpublic String next() {\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\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 (!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\tpublic 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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "37e7386e7883b0c466b459592a108e6e", "src_uid": "783c4b3179c558369f94f4a16ac562d4", "difficulty": 2100.0} {"lang": "Java 11", "source_code": "import java.util.Scanner;\n\npublic class Bug {\n\tpublic static void main(String[] args) {\n\t\tScanner input = new Scanner(System.in);\n\t\tint currentNum = 0;\n\t\tint sign = 1;\n\t\tint answer = 0;\n\t\tString exp = input.nextLine();\n\t\texp += '+'; // This allows the program to parse the last number in the expression\n\t\tfor (int i = 0; i < exp.length(); i++) {\n\t\t\tif (exp.charAt(i) == '+') {\n\t\t\t\tanswer += sign * currentNum;\n\t\t\t\tsign = 1;\n\t\t\t\tcurrentNum = 0;\n\t\t\t} else if (exp.charAt(i) == '-') {\n\t\t\t\tanswer += sign * currentNum;\n\t\t\t\tsign = -1;\n\t\t\t\tcurrentNum = 0;\n\t\t\t}\n\t\t\t// The bug is caused by the lack of this \"else\" statement. It causes the first\n\t\t\t// digit of the number to be ('+' - '0') or ('-' - '0')\n\t\t\t// else {\n\t\t\tcurrentNum = currentNum * 10 + (int) (exp.charAt(i) - '0');\n\t\t\t// }\n\t\t}\n\t\tSystem.out.println(answer);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ac203dcfce487c6e3fe21304f4ab54c9", "src_uid": "db85fa18f00e560b58cfa7bab2fa957d", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main {\n public static void main(String args[]) {\n Scanner scan = new Scanner(System.in);\n int n = scan.nextInt();\n int x = n/2;\n if(x%2==0 && n%2==0)\n {\n System.out.println(\"0\");\n }\n else if(x%2!=0 && n%2!=0)\n {\n \n System.out.println(\"0\");\n }\n else\n {\n System.out.println(\"1\");\n }\n \n System.out.println((list.get(0)));\n \n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e8896a30b5c59a7ba97059ca7e9f77c3", "src_uid": "fa163c5b619d3892e33e1fb9c22043a9", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class E {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tstatic final int[] PS = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41,\n\t\t\t43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 };\n\n\tint l, r, p;\n\tList goodAL = new ArrayList<>();\n\n\tstatic int[] toIntArray(List a) {\n\t\tint[] ret = new int[a.size()];\n\t\tint i = 0;\n\t\tfor (Integer x : a) {\n\t\t\tret[i++] = x;\n\t\t}\n\t\treturn ret;\n\t}\n\n\tvoid dfs(int x, int i) {\n\t\tif (i == PS.length) {\n\t\t\treturn;\n\t\t}\n\t\tdfs(x, i + 1);\n\t\tif (x <= r / PS[i]) {\n\t\t\tint next = x * PS[i];\n\t\t\tgoodAL.add(next);\n\t\t\tdfs(next, i);\n\t\t}\n\t}\n\n\tvoid solve() throws IOException {\n\t\tl = nextInt();\n\t\tr = nextInt();\n\t\tp = nextInt();\n\t\tgoodAL.add(1);\n\t\tdfs(1, 0);\n\t\tint[] good = toIntArray(goodAL);\n\t\tArrays.sort(good);\n\n\t\tint n = good.length;\n\n\t\tint[] dp = new int[n];\n\t\tint oo = Integer.MAX_VALUE / 3;\n\t\tArrays.fill(dp, oo);\n\t\tdp[0] = 0;\n\t\tfor (int x = 2; x <= p; x++) {\n\t\t\tfor (int i = 0, j = 0; i < n; i++) {\n\t\t\t\tlong needL = (long) good[i] * x;\n\t\t\t\tif (needL > r) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\twhile (j < n && good[j] < needL) {\n\t\t\t\t\tj++;\n\t\t\t\t}\n\t\t\t\tif (j == n || good[j] != needL) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (dp[i] + x < p) {\n\t\t\t\t\tdp[j] = Math.min(dp[j], dp[i] + 1);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint ans = 0;\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (good[i] >= l && dp[i] != oo) {\n\t\t\t\tans++;\n\t\t\t}\n\t\t}\n\n\t\tout.println(ans);\n\t}\n\n\tE() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew E();\n\t}\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\teof = true;\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "43b1af8ed1a22806affadc04906d2344", "src_uid": "6d898638531e4713774bbd5d47e827bf", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.util.regex.*;\nimport java.lang.*;\npublic class Main{\n\tpublic static void main(String[] args)\n\t{\n\tScanner sc=new Scanner(System.in);\n\tlong n=sc.nextLone();\n\tSystem.out.println(6+(n)*(n+11)/2);\n\t\n\t\n\t}\n\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "395922d5861fb795288ecdf8acccfdab", "src_uid": "c046895a90f2e1381a7c1867020453bd", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "package Div2_470;\n\nimport java.util.Scanner;\n\npublic class B3 {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int x2 = in.nextInt();\n int n = x2 + 10;\n int prost1[] = new int[n];\n int mas[] = new int[n];\n int df = 0;\n for (int i = 2; i < n; i++) {\n if (mas[i] == 0) {\n for (int j = 2 * i; j < n; j += i) {\n mas[j] = 1;\n }\n prost1[df++] = i;\n }\n }\n int prost[] = new int[df];\n for (int i = 0; i < df; i++) {\n prost[i] = prost1[i];\n }\n int min = 1_000_000;\n if (x2 < min) {\n min = x2;\n }\n int x1 = 1000_000;\n int uk = 0;\n while (uk < df && prost[uk] < x2) {\n if (x2 % prost[uk] == 0) {\n int po = Math.max(prost[uk], x2 - prost[uk]) + 1;\n if (po < x1) {\n x1 = po;\n }\n }\n uk++;\n }\n if (x1 < min) {\n min = x1;\n }\n int cur = 0;\n for (int i = x1; i < x2; i++) {\n int iq = (int) Math.sqrt(i);\n int s = 2;\n int gt = 0;\n int yu =0 ;\n while (cur < df && s <= iq) {\n if (i % s == 0) {\n if (prost[cur] == s) {\n int po = Math.max(prost[cur], i - prost[cur]) + 1;\n if (po < min) {\n min = po;\n }\n }\n yu = s;\n gt++;\n }\n s++;\n if (s > prost[cur]) {\n cur++;\n }\n }\n if (gt == 1) {\n int ho = i / yu;\n if (ho % yu != 0) {\n int po = Math.max(ho, i - ho) + 1;\n if (po < min) {\n min = po;\n }\n }\n }\n cur = 0;\n }\n System.out.println(min);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5317f06de3eb6de092a386bb96da427f", "src_uid": "43ff6a223c68551eff793ba170110438", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "\n\nimport java.io.BufferedReader;\n\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collection;\nimport java.util.Collections;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.Queue;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\n\npublic class codeforces2 {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\t// String str = br.readLine();\n\t\tPriorityQueue q = new PriorityQueue();\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tlong x = Long.parseLong(st.nextToken());\n\t\tlong y = Long.parseLong(st.nextToken());\n\t\tlong l = Long.parseLong(st.nextToken());\n\t\tlong r = Long.parseLong(st.nextToken());\n\n\t\t// StringTokenizer st = new StringTokenizer(br.readLine());\n\n\t\tfor (int i = 0; i < 64; i++) {\n\t\t\tfor (int j = 0; j < 64; j++) {\n\t\t\t\tlong sum = (long) (Math.pow(x, i)) + (long) Math.pow(y, j);\n\t\t\t\tq.add(sum);\n\t\t\t}\n\t\t}\n\t\tlong temp = l;\n\t\tint c = 0;\n\t\tlong max = 0;\n\t\tboolean f=true;\n\t\twhile (!q.isEmpty()) {\n\t\t\tlong curr = q.peek();\n\t\t\tif (curr >= l && curr <= r) {\n\t\t\t\t//System.out.println(curr);\n\t\t\t/*\tif (temp == l&&f) {\n\t\t\t\t\tmax = Math.max(max, curr - temp);\n\t\t\t\t\tf=false;*/\n\t\t\t\t} else {\n\t\t\t\t\tmax = Math.max(max, curr - temp - 1);\n\t\t\t\t}\n\t\t\t\ttemp = curr;\n\t\t\t}\n\t\t\tq.poll();\n\t\t}\n\t\tmax = Math.max(max, r - temp);\n\t\tSystem.out.println(max);\n\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "67b4834f2e3ffa29514c5cb98186ea09", "src_uid": "68ca8a8730db27ac2230f9fe9b120f5f", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "//package CodeForces.Round516_div2;\n\nimport java.util.Scanner;\n\n/**\n * @Author: tianchengjiang\n * @Date\uff1a2018/10/22\n */\npublic class problemF {\n public static Scanner scanner = new Scanner(System.in);\n\n public static void main(String[] args) {\n while (scanner.hasNext()) {\n long n = scanner.nextLong();\n long l = scanner.nextLong();\n long r = scanner.nextLong();\n long k = scanner.nextLong();\n long maxm = -1;\n\n long rangeX = r-l+1;\n if(rangeX <=0){\n rangeX += n;\n }\n long rangeY = n-rangeX;\n if(n <= Math.cbrt(k)){\n for(long x=0;x<=rangeX;x++){\n for(long y=0;y<=rangeY;y++){\n long temp = k - x - rangeX;\n if(temp >= 0 && temp %(rangeX+rangeY+x+y) ==0){\n maxm = Math.max(maxm,x+y);\n }\n if( x>0 && temp+1 >=0 && (temp+1)%(rangeX+rangeY+x+y) == 0){\n maxm = Math.max(maxm,x+y);\n }\n }\n }\n }else{\n for(long t=0;t<=k/n;t++){\n long temp = k - n * t - rangeX;\n if(temp>=0){\n if(t == 0 ){\n if( temp <= rangeX){\n maxm = Math.max(maxm, temp + rangeY);\n }\n if(temp +1<= rangeX){\n maxm = Math.max(maxm,temp + 1 + rangeY);\n }\n }else {\n long zmin = Math.max(ge(temp - rangeX, t), ge(temp, t + 1));\n long zmax = Math.min(le(temp, t), le(temp + rangeY, t + 1));\n if (zmax >= zmin) {\n maxm = Math.max(maxm, zmax);\n }\n temp++;\n zmin = Math.max(ge(temp - rangeX, t), ge(temp, t + 1));\n zmax = Math.min(le(temp-1, t), le(temp + rangeY, t + 1));\n if (zmax >= zmin) {\n maxm = Math.max(maxm, zmax);\n }\n\n }\n }\n }\n }\n System.out.println(maxm);\n }\n }\n\n public static long ple(long fz, long fm) { // fz >= 0, fm > 0\n return fz / fm;\n }\n\n public static long pge(long fz, long fm) { //fz >= 0, fm > 0\n return (fz + fm - 1) / fm;\n }\n\n\n public static long le (long fz, long fm) {\n return fz >= 0 ? ple(fz, fm) : -pge(-fz, fm); // \u522b\u5fd8\u4e86pge(-fz, fm)\u524d\u9762\u7684\u8d1f\u53f7\uff01\n }\n public static long ge(long fz, long fm) {\n return fz >= 0 ? pge(fz, fm) : -ple(-fz, fm);\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "562162e1af5c0efe50e8e49fe1a9e0ba", "src_uid": "f54cc281033591315b037a400044f1cb", "difficulty": 2600.0} {"lang": "Java 6", "source_code": "import java.util.*;\n\npublic class cf344B{\n\n\n\tpublic static void main(String args[])\n\t{\n\t\n\t\tScanner sc = new Scanner(System.in);\n\t\tint a = sc.nextInt();\n\t\tint b = sc.nextInt();\n\t\tint c = sc.nextInt();\n\t\t\n\t\tif((a+b+c)%2 == 1)\n\t\t{\n\t\t\tSystem.out.println(\"Impossible\");\n\t\t\treturn;\n\t\t}\n\t\t\n\t\t\n\t\t\n\t\tfor(int i=0; i<=(a/2); i++)\n\t\t{\n\t\t\tif((b-i) > 0 && b-i == c-(a-i))\n\t\t\t{\n\t\t\t\tSystem.out.println(i+\" \"+(b-i)+\" \"+(a-i));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\telse if((c-i)>0 && b-(a-i) == c-i)\n\t\t\t{\n\t\t\t\tSystem.out.println((a-i)+\" \"+(c-i)+\" \"+i);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\n\t\t}\n\t\t\n\t\tSystem.out.println(\"Impossible\");\n\t\t\n\t}\n\t\n\t\n\t\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1d1575484c27da30f24a0d43c088ac35", "src_uid": "b3b986fddc3770fed64b878fa42ab1bc", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\npublic class N {\n\tpublic static void main(String[] args) throws IOException {\n\t\t BufferedReader x = new BufferedReader(new InputStreamReader(System.in));\t \n\t int b=Integer.parseInt(x.readLine());\n\t int c=Integer.parseInt(x.readLine());\n\t int d=Integer.parseInt(x.readLine());\n\t System.out.println((b>d&&c>d)?d+1:(b==d&&c==d)||(b<=n&&c>=d)?b+1:(b=d)?c+1:0); \n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a2b4de2f66be177a085f5c6123b3def7", "src_uid": "9266a69e767df299569986151852e7b1", "difficulty": 1100.0} {"lang": "Java 7", "source_code": "public class CFPhone {\n public static void main(String[] args) {\n\n \tInputReader in \t\t= new InputReader(System.in);\n OutputWriter out\t=\tnew OutputWriter(System.out);\n int n = in.readInt();\n String str = in.readString();\n\n int[][] pad = {\n {1, 2, 3},\n {4, 5, 6},\n {7, 8, 9},\n {-1, 0, -1}\n };\n\n int[][] pos = {\n {3, 1},\n {0, 0},\n {0, 1},\n {0, 2},\n {1, 0},\n {1, 1},\n {1, 2},\n {2, 0},\n {2, 1},\n {2, 2},\n };\n\n int prev = Integer.parseInt(str.substring(0, 1));\n int[][] moves = new int[n-1][2];\n for(int i = 1; i < n; i++) {\n int cur = Integer.parseInt(str.substring(i, i+1));\n moves[i-1][0] = pos[cur][0] - pos[prev][0];\n moves[i-1][1] = pos[cur][1] - pos[prev][1];\n prev = cur;\n }\n\n for(int i = 0; i < pos.length; i++) {\n int[] prevPos = pos[i];\n if(pad[prevPos[0]][prevPos[1]] == Integer.parseInt(str.substring(0, 1))) {\n continue;\n }\n int j;\n for(j = 0; j < moves.length; j++) {\n int[] curPos = new int[2];\n curPos[0] = prevPos[0] + moves[j][0];\n curPos[1] = prevPos[1] + moves[j][1];\n if(!isValid(curPos)) {\n break;\n }\n prevPos = curPos;\n }\n if(j == moves.length) {\n out.printLine(\"NO\");\n out.flush();\n out.close();\n return;\n }\n }\n out.printLine(\"YES\");\n\n out.flush();\n out.close();\n }\n\n private static boolean isValid(int[] curPos) {\n if(curPos[0] == 3 && curPos[1] == 1)\n return true;\n if(curPos[0] < 0 || curPos[0] > 2 || curPos[1] < 0 || curPos[1] > 2)\n return false;\n return true;\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "af197add48a6e14e8d5a0ad26a9cf9af", "src_uid": "d0f5174bb0bcca5a486db327b492bf33", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n \n \n public class Solution {\n public static void main (String args[]){\n Scanner sc = new Scanner (System.in);\n int n = sc.nextInt();\n float []arr = new Flaot[n];\n float sum = 0;\n \n for (int i = 0; i < n; i++){\n arr[i] = sc.nextFloat();\n sum += arr[i];\n }\n Arrays.sort(arr);\n int i = 0;\n while (i < n && sum < 4.5 * n){\n sum += 5 - arr[i];\n i++;\n }\n System.out.println(i);\n \n }\n }\n ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e26b115bfa769f7eb334b1d8a94d84ce", "src_uid": "715608282b27a0a25b66f08574a6d5bd", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\r\npublic class Main\r\n{\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner sc=new Scanner(System.in);\r\n\t\tString s=sc.next();\r\n\t\tchar a[]=new char[26];\r\n\t\tint iii=0;\r\n\t\tfor(char al='A';al<='Z';al++){\r\n\t\t a[iii]=al;\r\n\t\t iii++;\r\n\t\t}\r\n\t\tint len=s.length();\r\n\t\tboolean f=true;\r\n\t\tint pos1=0,pos2=0,pos3=0;\r\n\t\tfor(int i=0;i A = new ArrayList();\n\t\t//C, C#, D, D#, E, F, F#, G, G#, A, B, H\n\t\tA.add(\"C\");\n\t\tA.add(\"C#\");\n\t\tA.add(\"D\");\n\t\tA.add(\"D#\");\n\t\tA.add(\"E\");\n\t\tA.add(\"F\");\n\t\tA.add(\"F#\");\n\t\tA.add(\"G\");\n\t\tA.add(\"G#\");\n\t\tA.add(\"A\");\n\t\tA.add(\"B\");\n\t\tA.add(\"H\");\n\t\tString X = sc.next();\n\t\tString Y = sc.next();\n\t\tString Z = sc.next();\n\t\tint n = Math.abs(A.indexOf(X)-A.indexOf(Y));\n\t\tint m = Math.abs(A.indexOf(Y)-A.indexOf(Z));\n\t\tint p = Math.abs(A.indexOf(X)-A.indexOf(Z));\n\t\tint x = Math.min(n, 12-n);\n\t\tint x1 = Math.max(n, 12-n);\n\t\tint y = Math.min(m, 12-m);\n\t\tint y1 = Math.max(m, 12-m);\n\t\tint z = Math.min(p, 12-p);\n\t\tint z1 = Math.max(p, 12-p);\n\t\tif(x==4 || x==3 || x1== 7){\n\t\t if(x1==7){\n\t\t if(z==4 && y==3){\n\t\t System.out.println(\"major\");\n\t\t }\n\t\t else if(z==3 && y==4){\n\t\t System.out.println(\"minor\");\n\t\t }\n\t\t }\n\t\t else if(y1==7){\n\t\t if(x==4 && z==3){\n\t\t System.out.println(\"major\");\n\t\t }\n\t\t else if(x==3 && z==4){\n\t\t System.out.println(\"minor\");\n\t\t }\n\t\t }\n\t\t else if(z1==7){\n\t\t if(x==4 && y==3){\n\t\t System.out.println(\"major\");\n\t\t }\n\t\t else if(x==3 && y==4){\n\t\t System.out.println(\"minor\");\n\t\t }\n\t\t }\n\t\t}\n\t\telse{\n\t\t System.out.println(\"strange\");\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3e118f474c6e4139d45cbd32328c5e2d", "src_uid": "6aa83c2f6e095848bc63aba7d013aa58", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.StringTokenizer;\n\n\npublic class ProblemD {\n static class ProblemSolver {\n void solve(FastReader in, PrintWriter out) {\n long n = in.nextLong();\n long k = in.nextLong();\n int l = in.nextInt();\n int m = in.nextInt();\n int set_bits_num = Long.bitCount(k);\n long a = Fibonacci.getNumber(n + 1, m);\n long b = (FastExponention.ipow(2, n, m) - Fibonacci.getNumber(n + 1, m)) % m;\n long res = (FastExponention.ipow(a, l - set_bits_num, m) * FastExponention.ipow(b, set_bits_num, m)) % m;\n out.println(res);\n }\n }\n\n /* ========================================================== */\n\n public static void main(String[] args) {\n int testMode = 0;\n //String testInput = \"3 3 2 10\";\n /*-------------------------------------------------------------------------------------------------------*/\n FastReader in = new FastReader(testMode == 0 ? System.in : new ByteArrayInputStream(testInput.getBytes()));\n PrintWriter out = new PrintWriter(System.out);\n new ProblemSolver().solve(in, out);\n out.close();\n }\n\n static class FastReader extends BufferedReader {\n private StringTokenizer st;\n\n public FastReader(InputStream is) {\n super(new InputStreamReader(is));\n }\n\n public String nextToken() {\n try {\n while (st == null || !st.hasMoreElements()) {\n st = new StringTokenizer(readLine());\n }\n return st.nextToken();\n } catch (IOException e) {\n return null;\n }\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 int[] nextArrayInt(int size) {\n int[] ret = new int[size];\n for (int i = 0; i < size; i++) {\n ret[i] = nextInt();\n }\n return ret;\n }\n }\n}\n\nclass Matrix {\n final int n;\n final int m;\n long[][] elements;\n\n public Matrix(int n, int m) {\n this.n = n;\n this.m = m;\n elements = new long[n][m];\n }\n\n public Matrix(long[][] elements) {\n n = elements.length;\n m = elements[0].length;\n this.elements = new long[n][m];\n for (int i = 0; i < n; i++) for (int k = 0; k < m; k++) this.elements[i][k] = elements[i][k];\n }\n\n // return C = A * B\n public Matrix multiply(Matrix B) {\n Matrix A = this;\n Matrix C = new Matrix(A.n, B.m);\n for (int i = 0; i < A.n; i++)\n for (int k = 0; k < B.m; k++)\n for (int j = 0; j < A.m; j++) C.elements[i][k] += A.elements[i][j] * B.elements[j][k];\n return C;\n }\n\n // return B = A % m\n public Matrix modulo(int modulo) {\n Matrix A = this;\n Matrix B = new Matrix(A.elements);\n for (int i = 0; i < A.n; i++) for (int k = 0; k < A.m; k++) B.elements[i][k] = A.elements[i][k] % modulo;\n return B;\n }\n\n // return identity matrix\n public static Matrix identity(int n) {\n Matrix I = new Matrix(n, n);\n for (int i = 0; i < n; i++)\n I.elements[i][i] = 1;\n return I;\n }\n}\n\nclass FastExponention {\n public static long ipow(long base, long exp, int modulo) {\n long res = 1;\n while (exp > 0) {\n if ((exp & 1) == 1) res = (res * base) % modulo;\n exp >>= 1;\n base = (base * base) % modulo;\n }\n return res;\n }\n\n public static Matrix ipow(Matrix base, long exp, int modulo) {\n Matrix res = Matrix.identity(2);\n while (exp > 0) {\n if ((exp & 1) == 1) res = (res.multiply(base)).modulo(modulo);\n exp >>= 1;\n base = (base.multiply(base)).modulo(modulo);\n }\n return res;\n }\n}\n\nclass Fibonacci {\n public static long getNumber(long n, int modulo) {\n long res = n;\n if (n > 2) {\n Matrix A = new Matrix(new long[][]{{1, 1}, {1, 0}});\n Matrix B = FastExponention.ipow(A, n - 2, modulo);\n res = (2 * B.elements[0][0] + B.elements[0][1]) % modulo;\n }\n return res % modulo;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2e87e2333868467b29ae149569e17051", "src_uid": "2163eec2ea1eed5da8231d1882cb0f8e", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import com.sun.org.apache.xml.internal.security.utils.HelperNodeList;\n\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.InputMismatchException;\nimport java.util.StringTokenizer;\n\npublic class B {\n static class FastWriter {\n private final BufferedWriter bw;\n\n public FastWriter() {\n this.bw = new BufferedWriter(new OutputStreamWriter(System.out));\n }\n\n public void print(Object object) throws IOException {\n bw.append(\"\" + object);\n }\n\n public void println(Object object) throws IOException {\n print(object);\n bw.append(\"\\n\");\n }\n\n public void close() throws IOException {\n bw.close();\n }\n }\n\n static class FastReader {\n BufferedReader br;\n StringTokenizer st;\n\n public FastReader() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException 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 BigInteger nextBigInteger() {\n try {\n return new BigInteger(nextLine());\n } catch (NumberFormatException e) {\n throw new InputMismatchException();\n }\n }\n }\n\n public static void main(String[] args) {\n FastReader fr = new FastReader();\n FastWriter fw = new FastWriter();\n int n = fr.nextInt();\n int m = fr.nextInt();\n HashMap map = new HashMap<>();\n for (int i = 0; i < m; i++) {\n int val = fr.nextInt();\n if (map.containsKey(val)) map.put(val, map.get(val) + 1);\n else map.put(val, 1);\n }\n ArrayList list = new ArrayList<>(map.values());\n int ans = 0;\n int hi = 100;\n int lo = 1;\n while (lo <= hi) {\n int mid = (lo + hi) / 2;\n boolean flag = helper(list, n, mid);\n if (flag) {\n lo = mid + 1;\n ans = Math.max(ans, mid);\n } else {\n hi = mid - 1;\n }\n }\n// for (int i = 100; i > 0; i--) {\n// int k = 0;\n// for (int val : list) k += val / i;\n// if (k >= n) {\n// ans = i;\n// break;\n// }\n// }\n System.out.println(ans);\n }\n\n private static boolean helper(ArrayList list, int n, int mid) {\n int k = 0;\n for (int val : list) k += val / mid;\n return k >= n;\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9f405c089e9c11731b27d319dffccaa2", "src_uid": "b7ef696a11ff96f2e9c31becc2ff50fe", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class A {\n\tpublic static void main(String[] args){\n\t\tScanner sc= new Scanner(System.in);\n\t\tlong n= sc.nextLong();\n\t\tlong smax=0;\n\t\tlong result=0;\n\t\tfor (long i=1; i<=n;i++){\n\t\t\tlong a=i;\n\t\t\tlong l=0;\n\t\t\tlong s=0;\n\t\t\twhile(a>0){\n\t\t\t\ta=a/10;\n\t\t\t\tl=l+1;\n\t\t\t}\n\t\t\tl=1;\n\t\t\tfor (long k=1; k<=l;k++){\n\t\t\t\ts=s+((i/l)%10);\n\t\t\t\tl=l*10;\n\t\t\t}\n\t\t\tif (s>=smax){\n\t\t\t\tsmax=s;\n\t\t\t\tresult=i;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\tSystem.out.print(result);\n\t\t\n\t\t\n\t}\n\t\n\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e8e386a45c351f6fb7d0398503a1f9b4", "src_uid": "e55b0debbf33c266091e6634494356b8", "difficulty": 1300.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class Main {\npublic static void main(String... args) {\n\nScanner sc = new Scanner(System.in);\nString l1 = sc.nextLine();\nString l2 = sc.nextLine();\n\nString[] s = l1.split(\"[|]\");\nif (l1.length==1){\n s = new String[]{\"\",\"\"};\n} else if (s.length == 1){\n s = new String[]{s[0],\"\"};\n}\n//System.out.println(s[0]+\"|\"+s[1]);\nfor (char ch : l2.toCharArray()){\n if (s[0].length() 1 && T.charAt(0) == '0')\n T = T.substring(0);\n System.out.println(x + Integer.parseInt(T)); \n}}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fe340e6ba801fc3ad67fb05308a64ef4", "src_uid": "69b219054cad0844fc4f15df463e09c0", "difficulty": 1200.0} {"lang": "Java 6", "source_code": "/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\npackage cf97;\n\nimport java.util.Scanner;\nimport java.util.ArrayList;\n\npublic class CF97 {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n // TODO code application logic here\n Scanner in = new Scanner(System.in);\n int a = in.nextInt();\n int c = in.nextInt();\n ArrayList alist = inThree(a);\n ArrayList clist = inThree(c);\n ArrayList blist = subThree(alist, clist);\n System.out.println(dec(blist));\n }\n\n public static ArrayList inThree(int a) {\n ArrayList s = new ArrayList();\n int i = 0;\n while (a / 3 > 0) {\n s.add(a % 3);\n a /= 3;\n }\n s.add(a % 3);\n return s;\n }\n\n public static ArrayList subThree(ArrayList a, ArrayList b) {\n ArrayList answer = new ArrayList();\n if (a.size() > b.size()) {\n for (int i = 0; i < a.size() - b.size(); i++) {\n b.add(0);\n }\n } else if (a.size() < b.size()) {\n for (int i = 0; i < b.size() - a.size(); i++) {\n a.add(0);\n }\n }\n for (int i = 0; i < a.size(); i++) {\n int ans = b.get(i) - a.get(i);\n answer.add(ans > 0 ? ans : (ans+3)%3);\n }\n return answer;\n }\n \n public static int dec(ArrayList a) {\n int calc = 0;\n for(int i = 0; i 0) {\n\t\t\tint M = 1 + Long.numberOfTrailingZeros(Long.highestOneBit(e));\n\t\t\tlong [][][] P = new long[M][][]; P[0] = A;\n\t\t\tfor (int i : rep(1, M))\n\t\t\t\tP[i] = prod(P[i-1], P[i-1], mod);\n\t\t\tfor (int i : rep(M))\n\t\t\t\tif ((e & (1 << i)) != 0)\n\t\t\t\t\tres = prod(res, P[i], mod);\n\t\t}\n\t\treturn res;\n\t}\n\n\tlong [][] id (int N) {\n\t\tlong [][] res = new long [N][N];\n\t\tfor (int i : rep(N))\n\t\t\tres[i][i] = 1;\n\t\treturn res;\n\t}\n\n\t///////////////////////////////////////////////////////////////////////////\n\tprivate static int [] rep(int N) { return rep(0, N); }\n\tprivate static int [] rep(int S, int T) { if (T <= S) return new int [0]; int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }\n\tprivate static long mod(long x, long mod) { return ((x % mod) + mod) % mod; }\n\t////////////////////////////////////////////////////////////////////////////////////\n\tprivate final static MyScanner sc = new MyScanner();\n\tprivate static class MyScanner {\n\t\tpublic String next() { newLine(); return line[index++]; }\n\t\tpublic int nextInt() { return Integer.parseInt(next()); }\n\t\t//////////////////////////////////////////////\n\t\tprivate boolean eol() { return index == line.length; }\n\t\tprivate String readLine() {\n\t\t\ttry {\n\t\t\t\treturn r.readLine();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new Error (e);\n\t\t\t}\n\t\t}\n\t\tprivate final java.io.BufferedReader r;\n\t\tprivate MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }\n\t\tprivate MyScanner (java.io.BufferedReader r) {\n\t\t\ttry {\n\t\t\t\tthis.r = r;\n\t\t\t\twhile (!r.ready())\n\t\t\t\t\tThread.sleep(1);\n\t\t\t\tstart();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new Error(e);\n\t\t\t}\n\t\t}\n\t\tprivate String [] line;\n\t\tprivate int index;\n\t\tprivate void newLine() {\n\t\t\tif (line == null || eol()) {\n\t\t\t\tline = readLine().split(\" \");\n\t\t\t\tindex = 0;\n\t\t\t}\n\t\t}\n\t}\n\tprivate static void print (Object o, Object... a) { printDelim(\" \", o, a); }\n\tprivate static void printDelim (String delim, Object o, Object... a) { pw.println(build(delim, o, a)); }\n\tprivate static void exit (Object o, Object... a) { print(o, a); exit(); }\n\tprivate static void exit() {\n\t\tpw.close();\n\t\tSystem.out.flush();\n\t\tSystem.err.println(\"------------------\");\n\t\tSystem.err.println(\"Time: \" + ((millis() - t) / 1000.0));\n\t\tSystem.exit(0);\n\t}\n\t////////////////////////////////////////////////////////////////////////////////////\n\tprivate static String build (String delim, Object o, Object... a) {\n\t\tStringBuilder b = new StringBuilder();\n\t\tappend(b, o, delim);\n\t\tfor (Object p : a)\n\t\t\tappend(b, p, delim);\n\t\treturn b.substring(delim.length());\n\t}\n\tprivate static void append(StringBuilder b, Object o, String delim) {\n\t\tif (o.getClass().isArray()) {\n\t\t\tint L = java.lang.reflect.Array.getLength(o);\n\t\t\tfor (int i = 0; i < L; ++i)\n\t\t\t\tappend(b, java.lang.reflect.Array.get(o, i), delim);\n\t\t} else if (o instanceof Iterable)\n\t\t\tfor (Object p : (Iterable)o)\n\t\t\t\tappend(b, p, delim);\n\t\telse\n\t\t\tb.append(delim).append(o);\n\t}\n\t////////////////////////////////////////////////////////////////////////////////////\n\tprivate static void start() { t = millis(); }\n\tprivate static java.io.PrintWriter pw = new java.io.PrintWriter(System.out, autoflush);\n\tprivate static long t;\n\tprivate static long millis() { return System.currentTimeMillis(); }\n\tpublic static void main (String[] args) { new E(); exit(); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6aefa5d69fa6d38623d21f04efbe8aa2", "src_uid": "ee9fa8be2ae05a4e831a4f608c0cc785", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.InputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.InputMismatchException;\nimport java.util.NoSuchElementException;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\n \npublic class Main{\n \nstatic PrintWriter out;\nstatic InputReader ir;\nstatic final int INF=Integer.MAX_VALUE;\nstatic final long LINF=Long.MAX_VALUE;\n \nstatic void solve(){\n long[] a=ir.nextLongArray(6);\n long ans=Math.pow(a[0]+a[1]+a[2],2);\n ans-=(a[0]*a[0]+a[2]*a[2]+a[4]*a[4]);\n outprintln(ans);\n}\n\npublic static void main(String[] args) throws Exception{\n ir=new InputReader(System.in);\n out=new PrintWriter(System.out);\n solve();\n out.flush();\n}\n\nstatic class InputReader {\n private InputStream in;\n private byte[] buffer=new byte[1024];\n private int curbuf;\n private int lenbuf;\n\n public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}\n \n public boolean hasNextByte() {\n if(curbuf>=lenbuf){\n curbuf= 0;\n try{\n lenbuf=in.read(buffer);\n }catch(IOException e) {\n throw new InputMismatchException();\n }\n if(lenbuf<=0) return false;\n }\n return true;\n }\n\n private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}\n \n private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}\n \n private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}\n \n public boolean hasNext(){skip(); return hasNextByte();}\n \n public String next(){\n if(!hasNext()) throw new NoSuchElementException();\n StringBuilder sb=new StringBuilder();\n int b=readByte();\n while(!isSpaceChar(b)){\n sb.appendCodePoint(b);\n b=readByte();\n }\n return sb.toString();\n }\n \n public int nextInt() {\n if(!hasNext()) throw new NoSuchElementException();\n int c=readByte();\n while (isSpaceChar(c)) c=readByte();\n boolean minus=false;\n if (c=='-') {\n minus=true;\n c=readByte();\n }\n int res=0;\n do{\n if(c<'0'||c>'9') throw new InputMismatchException();\n res=res*10+c-'0';\n c=readByte();\n }while(!isSpaceChar(c));\n return (minus)?-res:res;\n }\n \n public long nextLong() {\n if(!hasNext()) throw new NoSuchElementException();\n int c=readByte();\n while (isSpaceChar(c)) c=readByte();\n boolean minus=false;\n if (c=='-') {\n minus=true;\n c=readByte();\n }\n long res = 0;\n do{\n if(c<'0'||c>'9') throw new InputMismatchException();\n res=res*10+c-'0';\n c=readByte();\n }while(!isSpaceChar(c));\n return (minus)?-res:res;\n }\n\n public double nextDouble(){return Double.parseDouble(next());}\n\n public BigInteger nextBigInteger(){return new BigInteger(next());}\n\n public BigDecimal nextBigDecimal(){return new BigDecimal(next());}\n\n public int[] nextIntArray(int n){\n int[] a=new int[n];\n for(int i=0;i x; y--) {\n \t\t\t\tmins[y] = mins[y-1];\n \t\t\t}\n \t\t\tmins[x] = prices[i];\n \t\t\tbreak;\n \t\t}\n \t}\n }\n System.out.print(mins[0]);\n for(int x = 1; x < n; x++) {\n \tSystem.out.print(\" \" + mins[x]);\n }\n\t}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ea5ae789b06e6f6f46d01d71fdff0aba", "src_uid": "29e481abfa9ad1f18e6157c9e833f16e", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n/**\n * @author Albert Hambardzumyan\n */\npublic class Problem_837A {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int chars = in.nextInt();\n in.nextString();\n String input = in.nextString;\n\n String[] split = input.split(\" \");\n int result = 0, count;\n String tmp;\n for (int i = 0; i < split.length; i++) {\n tmp = split[i];\n count = 0;\n for (int j = 0; j < tmp.length; j++) {\n char a = tmp.charAt(j);\n if((int) a >= 65 && a <=90) count++;\n }\n if(result < count) result = count;\n }\n\n System.out.print(result);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a67725be2ac3926a884430aa9d8c5e78", "src_uid": "d3929a9acf1633475ab16f5dfbead13c", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class test {\n\t\n\t\n\t\n\tpublic static int helper(int arr[], int n, int index) {\n\t\tint max=0;\n\t\tint color=arr[index];\n\t\tfor(int i=index;imsum/2) {\n\t\t\tSystem.out.println(1);\n\t\t\tSystem.out.println(1);\n\t\t\tSystem.exit(0);\n\t\t\t\n\t\t}\n\t\tint accepted=arr[0]/2;\n\t\t\n\t\tVector v=new Vector<>();\n\t\t\n\t\tfor(int i=0;i v1=new HashMap<>();\n\t\tint k=0;\n\t\tint i=0;\n\t\tint sum=arr[0];\n\t\twhile(true) {\n\t\t\tk++;\n\t\t\ti++;\n\t\t\tint l=v.size();\n\t\t\tsum+=v.get(l-i);\n\t\t\tint temp=v.get(l-i);\n\t\t\tif(v1.containsKey(temp)) {\n\t\t\t\tint val=v1.get(temp);\n\t\t\t\tv1.put(temp,++val);\n\t\t\t}\n\t\t\telse\n\t\t\t\tv1.put(temp, 1);\n\t\t\tif(sum>msum/2)\n\t\t\t\tbreak;\n\t\t}\n\t\tSystem.out.println(++k);\n\t\t\n\t\tStringBuilder sb=new StringBuilder();\n\t\tsb.append(1+\" \");\n\t\tfor(i=0;i0) {\n\t\t\t\tsb.append((i+1)+\" \");\n\t\t\t\tint val=v1.get(arr[i]);\n\t\t\t\tval--;\n\t\t\t\tv1.put(arr[i], val);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(sb);\n\t\t\n\t\t\n\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\n\t\t\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", "compilation_error": false, "code_uid": "4637ac7013e4ebb0529a8952ac52262f", "src_uid": "0a71fdaaf08c18396324ad762b7379d7", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class ProblemA\n{\n\tpublic static void main (String []args)\n\t{\n\t\tScanner in = new Scanner (System.in);\n\t\tlong n = in.nextLong();\n\t\tint i=1;\n\t\tfor(i=1;n>=1;i++)\n\t\t{\n\t\t\tn-=i:\n\t\t}\n\t\tSystem.out.println(n+i-1);\n\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f8a76fbd62c0cfa5c9ebfca29329db82", "src_uid": "1db5631847085815461c617854b08ee5", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class tmpo{\n public static void String[] args) throws IOException{\n Scanner in=new Scanner(System.in);\n \n System.out.println(in.nextInt()%2);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cdd7fb914442d09479cb7d9c9aab4bcb", "src_uid": "78e64fdbf59c5ce89d0f0a1d0591f795", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.lang.*;\n \nimport static java.lang.Math.*;\n\npublic class Main implements Runnable {\n 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 Main(),\"Main\",1<<26).start();\n }\n \n static void merge(int arr[], int l, int m, int r) { \n int n1 = m - l + 1; \n int n2 = r - m; \n int L[] = new int [n1]; \n int R[] = new int [n2]; \n for (int i=0; i lista = new ArrayList<>();\n ArrayList divisores = new ArrayList<>();\n int x= Integer.parseInt(entrada.nextLine());\n String numero=\"\"+x;\n int d=1;\n if(x==1){\n System.out.println(\"1\");\n return;\n }\n if(x%2==0 && x%5==0){//si es 10,100,......1000000000\n d=2;\n for(int i=2; i> 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) 1e9 + 2;\n BitOperator bitOperator = new BitOperator();\n Modular modular = new Modular((int) 1e9 + 7);\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 int n;\n int t;\n int[] songTimes;\n int[] songTypes;\n int mask;\n int[] cnts = new int[4];\n int[][][][] perm;\n int ct1 ;\n int ct2 ;\n int ct3 ;\n public void solve() {\n n = io.readInt();\n t = io.readInt();\n\n\n songTimes = new int[n + 1];\n songTypes = new int[n + 1];\n for (int i = 1; i <= n; i++) {\n songTimes[i] = io.readInt();\n songTypes[i] = io.readInt();\n cnts[songTypes[i]]++;\n }\n\n ct1 = cnts[1];\n ct2 = cnts[2];\n ct3 = cnts[3];\n \n int[][][][] fr = new int[ct1 + 1][ct2 + 1][ct3 + 1][t + 1];\n int[][][][] fw = new int[ct1 + 1][ct2 + 1][ct3 + 1][t + 1];\n fr[0][0][0][0] = 1;\n int[] abc = new int[4];\n for (int i = 1; i <= n; i++) {\n for (abc[1] = 0; abc[1] <= ct1; abc[1]++) {\n for (abc[2] = 0; abc[2] <= ct2; abc[2]++) {\n for (abc[3] = 0; abc[3] <= ct3; abc[3]++) {\n int a = abc[1];\n int b = abc[2];\n int c = abc[3];\n for (int d = 0; d <= t; d++) {\n fw[a][b][c][d] = fr[a][b][c][d];\n if (abc[songTypes[i]] > 0 && d >= songTimes[i]) {\n abc[songTypes[i]]--;\n fw[a][b][c][d] = modular.plus(fw[a][b][c][d],\n fr[abc[1]][abc[2]][abc[3]][d - songTimes[i]]);\n abc[songTypes[i]]++;\n }\n }\n }\n }\n }\n int[][][][] tmp = fr;\n fr = fw;\n fw = tmp;\n }\n\n perm = new int[ct1 + 1][ct2 + 1][ct3 + 1][4];\n for (int a = 0; a <= ct1; a++) {\n for (int b = 0; b <= ct2; b++) {\n for (int c = 0; c <= ct3; c++) {\n for (int d = 0; d < 4; d++) {\n perm[a][b][c][d] = -1;\n }\n }\n }\n }\n perm[0][0][0][0] = 1;\n\n int ans = 0;\n for (int a = 0; a <= ct1; a++) {\n for (int b = 0; b <= ct2; b++) {\n for (int c = 0; c <= ct3; c++) {\n for (int d = 0; d < 4; d++) {\n int p = modular.mul(fr[a][b][c][t], perm(a, b, c, d));\n ans = modular.plus(ans, p);\n }\n }\n }\n }\n\n io.cache.append(ans);\n }\n\n int perm(int a, int b, int c, int d) {\n if (a < 0 || b < 0 || c < 0) {\n return 0;\n }\n if (perm[a][b][c][d] == -1) {\n perm[a][b][c][d] = 0;\n int aa = a;\n int bb = b;\n int cc = c;\n if (d == 0) {\n return perm[a][b][c][d];\n }\n int mul = 1;\n if (d == 1) {\n mul = a;\n aa--;\n } else if (d == 2) {\n mul = b;\n bb--;\n } else if (d == 3) {\n mul = c;\n cc--;\n }\n\n for (int k = 0; k < 4; k++) {\n if (k == d) {\n continue;\n }\n perm[a][b][c][d] = modular.plus(perm[a][b][c][d],\n perm(aa, bb, cc, k));\n }\n perm[a][b][c][d] = modular.mul(perm[a][b][c][d], mul);\n }\n\n return perm[a][b][c][d];\n }\n }\n\n /**\n * \u6a21\u8fd0\u7b97\n */\n public static class Modular {\n int m;\n\n public Modular(int m) {\n this.m = m;\n }\n\n public int valueOf(int x) {\n x %= m;\n if (x < 0) {\n x += m;\n }\n return x;\n }\n\n public int valueOf(long x) {\n x %= m;\n if (x < 0) {\n x += m;\n }\n return (int) x;\n }\n\n public int mul(int x, int y) {\n return valueOf((long) x * y);\n }\n\n public int plus(int x, int y) {\n return valueOf(x + y);\n }\n\n @Override\n public String toString() {\n return \"mod \" + m;\n }\n }\n\n public static class BitOperator {\n public int bitAt(int x, int i) {\n return (x >> i) & 1;\n }\n\n public int bitAt(long x, int i) {\n return (int) ((x >> i) & 1);\n }\n\n public int setBit(int x, int i, boolean v) {\n if (v) {\n x |= 1 << i;\n } else {\n x &= ~(1 << i);\n }\n return x;\n }\n\n public long setBit(long x, int i, boolean v) {\n if (v) {\n x |= 1L << i;\n } else {\n x &= ~(1L << i);\n }\n return x;\n }\n\n /**\n * Determine whether x is subset of y\n */\n public boolean subset(long x, long y) {\n return intersect(x, y) == x;\n }\n\n /**\n * Merge two set\n */\n public long merge(long x, long y) {\n return x | y;\n }\n\n public long intersect(long x, long y) {\n return x & y;\n }\n\n public long differ(long x, long y) {\n return x - intersect(x, y);\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fd5f101f9dbb4d653658e7e20d4ca895", "src_uid": "ed5f913afe829c65792b54233a256757", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "public class PolygoneTriangulation {\n\n public static void main(String[] args) {\n BufferedReader input = new BufferedReader(new InputStreamReader(System.in));\n List lines = input.lines().collect(toList());\n Integer number = Integer.valueOf(lines.get(0));\n System.out.println(compute(number));\n }\n\n protected static int compute(Integer number) {\n int score = 0;\n for (int i = 3; i <= number; i++) {\n score += i * (i - 1);\n }\n return score;\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "36960296cb76d7453cd53d4ce5d35b14", "src_uid": "1bd29d7a8793c22e81a1f6fd3991307a", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Main{\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=2){\n System.out.println(\"NO\");\n flag = true;\n break\n }\n if(!flag){\n System.out.println(\"YES\");\n }\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bee2987bd8d698b137d01c384b639797", "src_uid": "704d0ae50bccaa8bc49319812ae0be45", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "package secondPackage;\n/**\n * This is a program that returns the half\n * of the number that is declared in variable x.\n *\n *\n * @author\tHirai. Erika Mae C.\n * @version 1.00 2016/9/7\n */\npublic class CollectiveMindsetsMethod{//class declaration\n\tpublic static void main (String[] args) {//main method declaration\n\t\tlong x = 17000000;//variable declaration and initialization\n\t\tSystem.out.println(collective(x));//prints the result\n\t}\n\t/**\n\t *prints the result of the half of the number declared in x.\n\t *\n\t *\n\t *@param x first long value\n\t *@param n second long value\n\t *\n\t *@return returns long value of the initialized value of parameter x.\n\t */\n\t public static long collective(long n){//method\n \t\tlong result = 0;//variable declaration and initialization\n \t\t\n \t\twhile(n>0){//iterative: while condition\n \t\t\tif(n==1){//selection statements\n \t\t\t \tresult=n;//prints the result of the condition\n \t\t\t}else if(n%2==0){\n \t\t\t \tresult=n/2;\n \t\t\t}else if(n%2==1){\n \t\t\t\tresult=n/2+1;\n \t\t\t}else if (n<0){\n \t\t\t\tresult=0;\n \t\t\t}else if (n==0)\n \t\t\t\tresult=0;\n \t\t\t\t\tbreak;//break \t\n\t\t}\n\t\treturn result;//returns the result of x\n\t}//end of method\n}//end of class declaration", "lang_cluster": "Java", "compilation_error": false, "code_uid": "26caf0d55e5131a9bdd89d0abe4b3ede", "src_uid": "30e95770f12c631ce498a2b20c2931c7", "difficulty": 1100.0} {"lang": "Java 6", "source_code": "public class PlayingWithDice{\n\n public static void main(String[] args){\n\n BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));\n\t StringTokenizer st = new StringTokenizer(bufferRead.readLine(), \" \"); \n int a = Integer.parseInt(st.nextToken());\n int b = Integer.parseInt(st.nextToken());\n int cnta = 0;\n int cntd = 0;\n int cntb = 0; \n for (int i=1; i<=6; i++){\n if (Math.abs(a-i) > Math.abs(b-i)){\n cntb++;\n}\n if (Math.abs(a-i) == Math.abs(b-i))\n cntd++;\n\n if (Math.abs(a-i) < Math.abs(b-i))\n cnta++;\n\n \n} \n \n System.out.print(cnta,cntd,cntb);\n \n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "95c4877a72aad02aa187aecd779be24e", "src_uid": "504b8aae3a3abedf873a3b8b127c5dd8", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\r\nimport java.io.*;\r\n//import java.math.*;\r\n//https://www.hackerrank.com/goc-cdc-series-1\r\n public class Task{\r\n// ..............code begins here..............\r\n\r\nstatic long mod=(long)1e9+7,mod1=998244353l,inf=(long)1e18+5;\r\n\r\nstatic void solve() throws IOException{\r\n int[] z=int_arr();\r\n int n=z[0],k=z[1];\r\n\r\n if(n%2==1){\r\n long c=Modpow(2l,n-1,mod);\r\n c=Modpow((1l+c),k,mod);\r\n out.write(c+\"\\n\");\r\n }\r\n else{\r\n long c=1;\r\n if(k==1){\r\n int rk=k-i,left=1;\r\n long tmp=Modpow(2l,n-1,mod);\r\n tmp=Modpow(tmp,left,mod);\r\n out.write((t+tmp)%mod+\"\\n\");\r\n return;\r\n }\r\n for(int i=1;i<=k;i++){\r\n int rk=k-i,left=i-1;\r\n long tmp=Modpow(2l,n-1,mod);\r\n tmp=Modpow(tmp,left,mod);\r\n //tmp--;\r\n //tmp=(tmp+mod)%mod;\r\n //tmp=Math.max(tmp,1l);\r\n c+=tmp*Modpow(2l,(long)n*rk,mod)%mod;\r\n c%=mod;\r\n }\r\n out.write(c%mod+\"\\n\");\r\n }\r\n}\r\n\r\n\r\npublic static void main(String[] args) throws IOException{\r\n assign();\r\n int t=int_v(read()),cn=1;\r\n while(t--!=0){\r\n //out.write(\"Case #\"+cn+\": \");\r\n solve();\r\n //cn++;\r\n }\r\n out.flush();\r\n}\r\n\r\n// taking inputs\r\nstatic BufferedReader s1;\r\nstatic BufferedWriter out;\r\nstatic String read() throws IOException{String line=\"\";while(line.length()==0){line=s1.readLine();continue;}return line;}\r\nstatic int int_v (String s1){return Integer.parseInt(s1);}\r\nstatic long long_v(String s1){return Long.parseLong(s1);}\r\nstatic void sort(int[] a){List l=new ArrayList<>();for(int x:a){l.add(x);}Collections.sort(l);for(int i=0;i=mod)z-=mod;return z;}\r\nstatic long gcd(long a,long b){if(b==0){return a;}return gcd(b,a%b);}\r\nstatic long Modpow(long a,long p,long m){long res=1;while(p>0){if((p&1)!=0){res=(res*a)%m;}p >>=1;a=(a*a)%m;}return res%m;}\r\nstatic long Modmul(long a,long b,long m){return ((a%m)*(b%m))%m;}\r\nstatic long ModInv(long a,long m){return Modpow(a,m-2,m);}\r\n//static long nck(int n,int r,long m){if(r>n){return 0l;}return Modmul(f[n],ModInv(Modmul(f[n-r],f[r],m),m),m);}\r\n//static long[] f;\r\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5fde860a211681c8aade02fcca65ccc7", "src_uid": "02f5fe43ea60939dd4a53299b5fa0881", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class D1118_CoffeeAndCourseWork {\n\t\n\tpublic static void main(String[] args) {\n\t\tInputReader in = new InputReader();\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\t\n\t\tint[] arr = new int[n];\n\t\tfor (int i=0; i sums[n-1])\n\t\t\tSystem.out.println(-1);\n\t\telse \n\t\t\tSystem.out.println(binarySearch(arr, sums, m));\n\t}\n\t\n\tpublic static int binarySearch(int[] arr, int[] sums, int m) {\n\t\tint l = 1; int r = arr.length;\n\t\twhile (l != r) {\n\t\t\tif (l+1 == r)\n\t\t\t\treturn isPossible(l, arr, sums, m) ? l : r;\n\t\t\tint mid = (l + r)/2;\n\t\t\tif (isPossible(mid, arr, sums, m))\n\t\t\t\tr = mid;\n\t\t\telse\n\t\t\t\tl = mid+1;\n\t\t}\n\t\treturn l;\n\t}\n\t\n\t\n\t\n\tpublic static boolean isPossible(int day, int[] arr, int[] sums, int val) {\n\t\tint tot = sums[day-1], numUsed = day, sub = 1, prevUsed = 0;\n\t\twhile (numUsed < arr.length) {\n\t\t\tprevUsed = numUsed;\n\t\t\tnumUsed = Math.min(numUsed + day, arr.length);\n\t\t\tint pos = binarySearch(sub, arr);\n\t\t\tif (pos >= numUsed)\n\t\t\t\ttot += sums[numUsed-1] - sums[prevUsed-1] - (numUsed-prevUsed)*sub;\n\t\t\telse if (pos > prevUsed) {\n\t\t\t\tint index = prevUsed + (day - (numUsed - pos) - 1);\n\t\t\t\ttot += (sums[index] - sums[prevUsed-1]) - (day - (numUsed - pos))*sub;\n\t\t\t}\n\t\t\t++sub;\n\t\t}\n\t\treturn tot >= val;\n\t}\n\t\n\tpublic static int binarySearch(int T, int[] arr) {\n\t\tint l = 0, r = arr.length;\n\t\twhile (l != r) {\n\t\t\tint mid = (l + r)/2;\n\t\t\tif (arr[mid] <= T)\n\t\t\t\tr = mid;\n\t\t\telse\n\t\t\t\tl = mid+1;\n\t\t}\n\t\treturn l;\n\t}\n\t\n\tpublic static int[] reverseOrder(int[] arr) {\n\t\tint[] newArr = new int[arr.length];\n\t\tfor (int i=0; i x) {\n r = mid - 1;\n } else {\n ans = mid;\n l = mid + 1;\n }\n }\n return ans + 1;\n }\n\n void no() {\n out.println(\"NO\");\n out.close();\n System.exit(0);\n }\n \n void yes() {\n out.println(\"YES\");\n out.close();\n System.exit(0);\n }\n \n void solve() {\n int n = readInt();\n int R = readInt();\n int r = readInt();\n \n if (R < r) no();\n if (n == 1) {if (R < r) no(); else yes();}\n double sector = Math.asin((double)r / (R - r)) * 2;\n double all = n * sector;\n if (all - 1e-10 < 2 * Math.PI) \n yes();\n else\n no();\n }\n}import java.awt.Point;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class solver implements Runnable {\n\n BufferedReader in;\n PrintWriter out;\n StringTokenizer tok = new StringTokenizer(\"\");\n\n void init() throws FileNotFoundException {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n }\n\n String readString() {\n try {\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 } catch (Exception e) {\n throw new RuntimeException(e);\n }\n }\n\n int readInt() {\n return Integer.parseInt(readString());\n }\n\n long readLong() {\n return Long.parseLong(readString());\n }\n\n double readDouble() {\n return Double.parseDouble(readString());\n }\n\n public static void main(String[] args) {\n new Thread(null, new solver(), \"\", 256 * (1L << 20)).start();\n }\n\n long timeBegin, timeEnd;\n\n void time() {\n timeEnd = System.currentTimeMillis();\n System.err.println(\"Time = \" + (timeEnd - timeBegin));\n }\n\n public void run() {\n try {\n timeBegin = System.currentTimeMillis();\n init();\n solve();\n out.close();\n // time();\n } catch (Exception e) {\n e.printStackTrace(System.err);\n System.exit(-1);\n }\n }\n \n int cntm(int[] a, int x) {\n int l = 0;\n int r = a.length - 1;\n int ans = -1;\n while (l <= r) {\n int mid = (l + r) / 2;\n if (a[mid] > x) {\n r = mid - 1;\n } else {\n ans = mid;\n l = mid + 1;\n }\n }\n return ans + 1;\n }\n\n void no() {\n out.println(\"NO\");\n out.close();\n System.exit(0);\n }\n \n void yes() {\n out.println(\"YES\");\n out.close();\n System.exit(0);\n }\n \n void solve() {\n int n = readInt();\n int R = readInt();\n int r = readInt();\n \n if (R < r) no();\n if (n == 1) {if (R >= r) no(); else yes();}\n double sector = Math.asin((double)r / (R - r)) * 2;\n double all = n * sector;\n if (all - 1e-10 < 2 * Math.PI) \n yes();\n else\n no();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b5b425bc177b1bd67c6f68ef2fb1cd15", "src_uid": "2fedbfccd893cde8f2fab2b5bf6fb6f6", "difficulty": 1700.0} {"lang": "Java 11", "source_code": "import java.util.*;\npublic class x\n{\n public static void main(String args[])\n {\n Scanner sc = new Scanner(System.in);\n int a[] = new int[3];\n \n for(i=0;i<3;i++)\n {\n a[i] = sc.nextInt();\n }\n \n Arrays.sort(a);\n \n int max = a[2];\n int min = a[0];\n int t = a[1];\n \n System.out.println((max-t)+(t-min));\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "862ab4b396459f1ba7ad71ccef07392a", "src_uid": "7bffa6e8d2d21bbb3b7f4aec109b3319", "difficulty": 800.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\npublic class B {\npublic static void main (String []args ){\nScanner in =new Scanner (System.in);\nint b= in.nextInt();\nboolean s=true;\nfor(int i=0 ;i<10 ; i++)\n{\n if(Math.Pow(2,i)==b){\nSystem.out.Println(\"YES\");break;s=false;}\n}\nif(s)\nSystem.out.Println(\"NO\");\n\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "625db4e7e8415a50594780d243ef8d48", "src_uid": "4bd174a997707ed3a368bd0f2424590f", "difficulty": 1200.0} {"lang": "Java 11", "source_code": "import java.util.*;\nimport java.io.*;\n\nimport static java.lang.Math.*;\n\npublic class Main {\n static ArrayList[] gr, g;\n static TreeMap way;\n static int[] types, dist;\n static boolean[] used;\n static int INF = (int) 1e9;\n\n public static void main(String[] args) {\n FastScanner sc = new FastScanner(System.in);\n PrintWriter pw = new PrintWriter(System.out);\n int n = sc.nextInt();\n int m = sc.nextInt();\n gr = new ArrayList[n];\n g = new ArrayList[n];\n for (int i = 0; i < n; i++) {\n gr[i] = new ArrayList<>();\n g[i] = new ArrayList<>();\n }\n for (int i = 0; i < m; i++) {\n int from = sc.nextInt() - 1;\n int to = sc.nextInt() - 1;\n gr[from].add(to);\n g[to].add(from);\n }\n int k = sc.nextInt();\n int[] p = new int[k];\n for (int i = 0; i < k; i++)\n p[i] = sc.nextInt() - 1;\n way = new TreeMap<>();\n for (int i = 0; i < k - 1; i++)\n way.put(p[i], p[i + 1]);\n types = new int[n];\n //0 - none\n //1 - +\n //2 - -\n //3 - +-\n used = new boolean[n];\n dist = new int[n];\n Arrays.fill(dist, INF);\n dist[p[k - 1]] = 0;\n dfs(p[k - 1], -1);\n int cntMin = 0;\n int cntMax = 0;\n for (int i = 0; i < k - 1; i++) {\n if(types[p[i]] == 2) {\n cntMin++;\n cntMax++;\n }\n if(types[p[i]] == 3)\n cntMax++;\n }\n pw.print(cntMin + \" \" + cntMax);\n pw.close();\n }\n\n public static void dfs(int v, int p) {\n used[v] = true;\n for (int to : g[v]) {\n if (dist[to] > dist[v] + 1) {\n dist[to] = dist[v] + 1;\n if (way.containsKey(to) && way.get(to) == v)\n types[to] = 1;\n else\n types[to] = 2;\n } else if (dist[to] == dist[v] + 1) {\n if (way.containsKey(to) && way.get(to) == v)\n types[to]++;\n else {\n if (types[to] < 2)\n types[to] += 2;\n }\n }\n if (!used[to])\n dfs(to, v);\n }\n }\n\n\n public static boolean isVowel(char a) {\n return a == 'a' || a == 'e' || a == 'u' || a == 'o' || a == 'y';\n }\n\n public static long binPow(long a, int n) {\n long p = a;\n long res = 1;\n while (n > 0) {\n if (n % 2 == 1)\n res *= p;\n p *= p;\n n /= 2;\n }\n return res;\n }\n\n public static int gcd(int a, int b) {\n if (a == 0 || b == 0)\n return a + b;\n return gcd(b % a, a);\n }\n\n public static long gcd(long a, long b) {\n if (a == 0 || b == 0)\n return a + b;\n return gcd(b % a, a);\n }\n}\n\nclass chr {\n char a;\n int index;\n\n public chr(char a, int index) {\n this.a = a;\n this.index = index;\n }\n}\n\nclass chrComp implements Comparator {\n public int compare(chr o1, chr o2) {\n return Character.compare(o1.a, o2.a);\n }\n}\n\nclass FastScanner {\n static BufferedReader br;\n static StringTokenizer st = new StringTokenizer(\"\");\n\n public FastScanner(InputStream inputStream) {\n br = new BufferedReader(new InputStreamReader(inputStream));\n }\n\n public FastScanner(String fileName) throws FileNotFoundException {\n br = new BufferedReader(new FileReader(fileName));\n }\n\n public boolean hasNext() {\n try {\n while (!st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return true;\n } catch (Exception e) {\n return false;\n }\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public String next() {\n hasNext();\n return st.nextToken();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9892219d4c5e0a272441aef6c2ec70a5", "src_uid": "19a0c05eb2d1559ccfe60e210c6fcd6a", "difficulty": null} {"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\nimport java.util.Arrays;\nimport java.util.Scanner;\nimport java.util.Vector;\n\n/**\n *\n * @author user\n */\npublic class NewMain3 {\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 n = sc.nextInt();\n int b = sc.nextInt();\n int s[] = new int[n];\n for(int i = 0 ; i < n ; i++) {\n s[i] = sc.nextInt();\n }\n \n int even = 0 , odd = 0 ;\n Vector v = new Vector<>();\n \n for(int i = 0 ; i < n ; i++)\n {\n if(odd==even && i!=0){\n v.add(Math.abs(s[i] - s[i-1]));\n } \n if(s[i]%2==0)even++;\n else odd++;\n \n } \n \n int w [] = new int[v.size()];\n for(int i = 0 ; i < v.size() ; i++)\n {\n w[i] = (int)(v.get(i)) ;\n }\n \n \n Arrays.sort(w);\n int counter =0 ; \n for(int i = 0 ; i < w.length ; i++)\n {\n if(w[i] =< b){b-=w[i]; counter++;}\n else{break;}\n }\n System.out.println(counter);\n }\n \n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "18ddc967f9ac27ca3b12bdeb8bfcdbfd", "src_uid": "b3f8e769ee7719ea5c9f458428b16a4e", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "public class HelloWorld{\n\n public static void main(String []args){\n Scanner sc = new Scanner(System.in);\n\t\tint t = sc.nextInt();\n\t\twhile(t-->0){\n\t\t int x = sc.nextInt();\n\t\t int y = x%10;\n\t\t int z = x;\n\t\t int a = 0;\n\t\t while(z > 0){\n\t\t a++;\n\t\t z=z/10;\n\t\t }\n\t\t int res;\n\t\t for (int i = 1;i= 100) {\n\t\t\tx -= 100;\n\t\t\treturn x;\n\t\t} else if (x >= 50) {\n\t\t\tx -= 50;\n\t\t} else if (x >= 20) {\n\t\t\tx -= 20;\n\t\t} else if (x >= 10) {\n\t\t\tx -= 10;\n\t\t} else if (x >= 5) {\n\t\t\tx -= 5;\n\t\t} else {\n\t\t\tx--;\n\t\t}\n\t\treturn x;\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "480bf13b0ae78646790960b5aebd64eb", "src_uid": "8e81ad7110552c20297f08ad3e5f8ddc", "difficulty": 800.0} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\npublic class A {\n\n public static void main(String args[]) {\n Scanner sc = new Scanner(System.in);\n\n int a = sc.nextInt();\n int b = sc.nextInt();\n int c = sc.nextInt();\n int n = sc.nextInt();\n int remain = 0;\n\n if (n < a || n < b || n < c) {\n System.out.println(\"-1\");\n } else {\n if (c > 0) {\n a = a - c;\n b = b - c;\n remain = n - a - b - c;\n if (remain < 0) {\n System.out.println(\"-1\");\n } else {\n System.out.println(remain);\n }\n } else if (c == 0) {\n if (a + b >= n) {\n System.out.println(\"-1\");\n } else if (a + b < n) {\n System.out.println(n - a - b);\n }\n }\n }\n }\n}\nclose", "lang_cluster": "Java", "compilation_error": true, "code_uid": "05a68da5b03f95003cdcedd0ff5e4658", "src_uid": "959d56affbe2ff5dd999a7e8729f60ce", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "/* package codechef; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class Main\n{\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tBigInteger bi = new BigInteger(\"\"+n);\n\t\tBigInteger bi2 = new BigInteger(\"\"+(n-2));\n\t\t\n\t\tif(n == 9) System.out.println(2);\n\t else if(bi.isProbablePrime(1)) {\n\t System.out.println(1);\n\t }else {\n\t if(n % 2 == 0) System.out.println(2);\n\t else{\n\t if(bi2.isProbablePrime(1)) {\n\t System.out.println(2);\n\t }else {\n\t System.out.println(3);\n\t }\n\t }\n\t }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9d396c4dd8afe111c842fcbe3f1de907", "src_uid": "684ce84149d6a5f4776ecd1ea6cb455b", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class TEMP_programs {\n\n\tpublic static class FastReader {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastReader() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreElements()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tString nextLine() {\n\t\t\tString str = \"\";\n\t\t\ttry {\n\t\t\t\tstr = br.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tFastReader scn = new FastReader();\n\n\t\tlong l = scn.nextLong(), r = scn.nextLong(), x = scn.nextLong(), y = scn.nextLong(), k = scn.nextLong();\n\t\t\n\t\t\n\t\tfor(long i = x; i <= y; i++) {\n\t\t\tif(i * k < l || i * k > r) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tmap.add(i * k);\n\t\t}\n\t\t\n\t\tboolean ans = false;\n\t\tfor(long i = l; i <= r; i++) {\n\t\t\tif(map.contains(i)) {\n\t\t\t\tans = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif(ans) {\n\t\t\tSystem.out.println(\"YES\");\n\t\t} else {\n\t\t\tSystem.out.println(\"NO\");\n\t\t}\n\t\t\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a260ef63c9eb2e27d928ceca4f3ad027", "src_uid": "1110d3671e9f77fd8d66dca6e74d2048", "difficulty": 1200.0} {"lang": "Java 6", "source_code": "import java.util.HashSet;\nimport java.util.Objects;\nimport java.util.Scanner;\n\npublic class Main {\n\n private static String[] cards;\n private static boolean flag = false;\n private static HashSet dyn;\n private static int n;\n \n private static class Dyn {\n int n;\n String s1,s2,s3;\n Dyn (int n, String s1, String s2, String s3) {\n this.n = n;\n this.s1 = s1;\n this.s2 = s2;\n this.s3 = s3;\n }\n\n @Override\n public boolean equals(Object obj) {\n if (obj == null) {\n return false;\n }\n if (getClass() != obj.getClass()) {\n return false;\n }\n final Dyn other = (Dyn) obj;\n if (this.n != other.n) {\n return false;\n }\n if (!Objects.equals(this.s1, other.s1)) {\n return false;\n }\n if (!Objects.equals(this.s2, other.s2)) {\n return false;\n }\n if (!Objects.equals(this.s3, other.s3)) {\n return false;\n }\n return true;\n }\n\n @Override\n public int hashCode() {\n int hash = 7;\n hash = 83 * hash + this.n;\n hash = 83 * hash + Objects.hashCode(this.s1);\n hash = 83 * hash + Objects.hashCode(this.s2);\n hash = 83 * hash + Objects.hashCode(this.s3);\n return hash;\n }\n \n }\n \n public static void main(String[] args) {\n Scanner sc = new Scanner (System.in);\n n = sc.nextInt();\n dyn = new HashSet ();\n \n cards = new String[n];\n for (int i = 0; i < n; ++i)\n cards[i] = sc.next();\n \n dfs(n-1, cards);\n \n System.out.print(flag == true ? \"YES\":\"NO\");\n }\n\n private static void dfs(int a, String[] cards) {\n \n if (a==0)\n {\n flag = true;\n return;\n }\n \n Dyn temp2 = new Dyn (a,cards[a], a>0 ? cards[a-1] : null, a>1 ? cards[a-2] : null);\n if (!dyn.contains(temp2))\n {\n dyn.add(temp2);\n \n if (cards[a].charAt(0) == cards[a-1].charAt(0) || cards[a].charAt(1) == cards[a-1].charAt(1))\n {\n String[] temp = cards.clone();\n temp[a-1] = temp[a];\n dfs(a-1, temp);\n }\n\n if (a > 2)\n if (cards[a].charAt(0) == cards[a-3].charAt(0) || cards[a].charAt(1) == cards[a-3].charAt(1))\n {\n String[] temp = cards.clone();\n temp[a-3] = temp[a];\n dfs(a-1, temp);\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "92daa041f4516285b24d152f09864de3", "src_uid": "1805771e194d323edacf2526a1eb6768", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class A\n{\n public static void main(String args[])\n {\n Scanner sc=new Scanner(System.in);\n String s=sc.next();\n if(Integer.parseInt(s.charAt(6)%2==0))\n System.out.println(\"0\");\n else\n System.out.println(\"1\")\n \n }\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4f8bf94f9f3dcd3626ffa2199ec04d95", "src_uid": "e52bc741bb72bb8e79cf392b2d15354f", "difficulty": null} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.InputMismatchException;\nimport java.util.ArrayList;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author RiaD\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tReader in = new Reader(inputStream);\n\t\tOutputWriter out = new OutputWriter(outputStream);\n\t\tTaskD solver = new TaskD();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskD {\n public void solve(int testNumber, Reader in, OutputWriter out) {\n long n = in.nextLong();\n ArrayList lengths = new ArrayList();\n long ones = n;\n boolean[] used = new boolean[101010];\n for(int i = 2; i * i <= n; ++i){\n if (used[i])\n continue;\n long j = i;\n int len = 0;\n while(j <= n) {\n if(j < 101010)\n used[j] = true;\n ++len;\n j *= i;\n }\n\n lengths.add(len);\n ones -= len;\n }\n\n long gandy = 0;\n\n if(ones % 2 != 0)\n gandy ^= gandy(1);\n long[] dp = new long[30];\n for(int i = 0; i < 30; ++i) {\n dp[i] = gandy(i);\n }\n for (Integer length : lengths) {\n gandy ^= dp[length];\n }\n\n out.println(gandy == 0 ? \"Petya\" : \"Vasya\");\n }\n\n private long gandy(int length) {\n if (length == 0) return 0;\n if (length == 1) return 1;\n if (length == 2) return 2;\n if (length == 3) return 1;\n if (length == 4) return 4;\n if (length == 5) return 3;\n if (length == 6) return 2;\n if (length == 7) return 1;\n if (length == 8) return 5;\n if (length == 9) return 6;\n if (length == 10) return 2;\n if (length == 11) return 1;\n if (length == 12) return 8;\n if (length == 13) return 7;\n if (length == 14) return 5;\n if (length == 15) return 9;\n if (length == 16) return 8;\n if (length == 17) return 7;\n if (length == 18) return 3;\n if (length == 19) return 4;\n if (length == 20) return 7;\n if (length == 21) return 4;\n if (length == 22) return 2;\n if (length == 23) return 1;\n if (length == 24) return 10;\n if (length == 25) return 9;\n if (length == 26) return 3;\n if (length == 27) return 6;\n if (length == 28) return 11;\n if (length == 29) return 12;\n throw new AssertionError();\n }\n}\n\nclass Reader {\n private BufferedReader reader;\n private StringTokenizer tokenizer;\n\n public Reader(BufferedReader reader) {\n this.reader = reader;\n }\n\n public Reader(InputStream stream) {\n this(new BufferedReader(new InputStreamReader(stream)));\n }\n\n public String nextString() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(readLine());\n }\n return tokenizer.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(nextString());\n }\n\n private String readLine() {\n try {\n return reader.readLine();\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n}\n\nclass OutputWriter extends PrintWriter {\n\n\tpublic OutputWriter(OutputStream out) {\n\t\tsuper(out);\n\t}\n\n\tpublic OutputWriter(java.io.Writer writer){\n\t\tsuper(writer);\n\t}\n\n\t}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8a0f9f2e73b39c40cfd746f576ea9a15", "src_uid": "0e22093668319217b7946e62afe32195", "difficulty": 2300.0} {"lang": "Java 6", "source_code": "public class pr {\n public static void main(String [] args)\n {\n Scanner sc=new Scanner(System.in);\n double x1,x2,y1,y2,z1,z2;\n x1=sc.nextDouble();\n y1=sc.nextDouble();\n z1=sc.nextDouble();\n x2=sc.nextDouble();\n y2=sc.nextDouble();\n z2=sc.nextDouble();\n double a=x1-x2;\n double b=y1-y2;\n double c=z1-z2;\n double ans=Math.sqrt(a*a+b*b+c*c);\n if(ans>1)System.out.print(\"NO\");\n else System.out.print(\"YES\");\n \n }\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ae84a1af1f2c7b686d6d6c2345d35174", "src_uid": "91c9dbbceb467d5fd420e92c2919ecb6", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.io.InputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.InputMismatchException;\nimport java.util.NoSuchElementException;\nimport java.math.BigInteger;\n\npublic class Main{\n\nstatic PrintWriter out;\nstatic InputReader ir;\n\nstatic void solve(){\n int n=ir.nextInt();\n int[][] a=new int[3][];\n int mi=0;\n for(int i=0;i<3;i++){\n a[i]=ir.nextIntArray(2);\n mi+=a[i][0];\n }\n for(int i=0;i<3;i++){\n int a=a[i][0]+Math.min(a[i][1]-a[i][0],n-mi);\n n-=a;\n mi-=a[i][0];\n out.print(a+((i==2)?\"\\n\":\" \"));\n }\n}\n\npublic static void main(String[] args) throws Exception{\n ir=new InputReader(System.in);\n out=new PrintWriter(System.out);\n solve();\n out.flush();\n}\n\nstatic class InputReader {\n private InputStream in;\n private byte[] buffer=new byte[1024];\n private int curbuf;\n private int lenbuf;\n\n public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}\n \n public boolean hasNextByte() {\n if(curbuf>=lenbuf){\n curbuf= 0;\n try{\n lenbuf=in.read(buffer);\n }catch(IOException e) {\n throw new InputMismatchException();\n }\n if(lenbuf<=0) return false;\n }\n return true;\n }\n\n private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}\n \n private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}\n \n private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}\n \n public boolean hasNext(){skip(); return hasNextByte();}\n \n public String next(){\n if(!hasNext()) throw new NoSuchElementException();\n StringBuilder sb=new StringBuilder();\n int b=readByte();\n while(!isSpaceChar(b)){\n sb.appendCodePoint(b);\n b=readByte();\n }\n return sb.toString();\n }\n \n public int nextInt() {\n if(!hasNext()) throw new NoSuchElementException();\n int c=readByte();\n while (isSpaceChar(c)) c=readByte();\n boolean minus=false;\n if (c=='-') {\n minus=true;\n c=readByte();\n }\n int res=0;\n do{\n if(c<'0'||c>'9') throw new InputMismatchException();\n res=res*10+c-'0';\n c=readByte();\n }while(!isSpaceChar(c));\n return (minus)?-res:res;\n }\n \n public long nextLong() {\n if(!hasNext()) throw new NoSuchElementException();\n int c=readByte();\n while (isSpaceChar(c)) c=readByte();\n boolean minus=false;\n if (c=='-') {\n minus=true;\n c=readByte();\n }\n long res = 0;\n do{\n if(c<'0'||c>'9') throw new InputMismatchException();\n res=res*10+c-'0';\n c=readByte();\n }while(!isSpaceChar(c));\n return (minus)?-res:res;\n }\n\n public double nextDouble(){return Double.parseDouble(next());}\n\n public BigInteger nextBigInteger(){return new BigInteger(next());}\n\n public int[] nextIntArray(int n){\n int[] a=new int[n];\n for(int i=0;i set = new HashSet();\n\t\tint l = s1.length();\t\t\n\t\tfor(int i = 0; i < l; i++) {\n\t\t\tString s2 = s1.substring(l - 1, l);\n\t\t\ts1 = s1.substring(0, l-1);\n\t\t\ts1 = s2.concat(s1);\n\t\t\tset.add(s1);\n\t\t}\n\t\tSystem.out.println(set.size());\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8b061c4827389ae4412f653e522618f6", "src_uid": "8909ac99ed4ab2ee4d681ec864c7831e", "difficulty": 900.0} {"lang": "Java 7", "source_code": "mport java.io.OutputStream;\nimport java.io.PrintStream;\nimport java.util.Scanner;\n\npublic class Round226Div2A {\n private static PrintStream debug = null;\n private static boolean DEBUG = true;\n static {\n\n try {\n if(System.getProperty(\"user.dir\").toString().equals(\"/media/share/Workspace/Codeforces\") && DEBUG) {\n debug = System.err;\n }\n } catch(Exception e) {\n }\n\n if (debug == null) {\n debug = new PrintStream(new OutputStream() {\n @Override\n public void write(int b) {\n }\n });\n }\n }\n\n /**\n * @param args\n */\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int c = sc.nextInt();\n int[] x = new int[n];\n for (int i=0; i set = new HashSet<>(100000000);\n \n public static void main(String args[]) throws IOException {\n long n =in.nextLong();\n char []arr = new char[9];\n // System.out.println(arr);\n subset(arr,0);\n int cnt=0;\n for(long p:set){\n if(p<=n){\n cnt++;\n }\n }\n out.println(cnt);\n out.flush();\n }\n static void subset(char [] arr,int k){\n if(k==9){\n set.add(convertcharToStringToLong(arr,k));\n }else if(k<9){\n arr[k] = '1';\n set.add(convertcharToStringToLong(arr,k));\n subset(arr, k+1);\n arr[k] = '0';\n set.add(convertcharToStringToLong(arr,k));\n subset(arr, k+1);\n }\n }\n \n private static long convertcharToStringToLong(char[] arr, int k) {\n long t = 0;\n for(int i=0;i 0) {\n if ((bitmask & 1) == 1){\n // System.out.print(array[pos] + \",\");\n n+=array[pos];\n }\n bitmask >>= 1;\n pos--;\n }\n if(n.length()>=1){\n long k = Long.parseLong(n);\n if(k<=bound&&!set.contains(k)){\n ans++;\n set.add(k);\n }\n }\n //out.println(n+\" \");\n // System.out.print(\"}\");\n }\n }\n \n private static boolean hasZero(long k) {\n while(k!=0){\n long p = k%10;\n if(p==0){\n return true;\n }\n k/=10;\n }\n return false;\n }\n\n static boolean isVowel(char c) {\n if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'||c=='y'){\n return true;\n }\n return false ;\n }\n static class IP implements Comparable{\n public int first,second;\n IP(int first, int second){\n this.first = first;\n this.second = second;\n }\n public int compareTo(IP ip){\n if(first==ip.first)\n return second-ip.second;\n return first-ip.first; \n }\n \n }\n \n static long gcd(long a, long b){\n return b!=0?gcd(b, a%b):a;\n }\n \n static boolean isEven(long a) {\n return (a&1)==0;\n }\n \n public static class MyScanner {\n BufferedReader br;\n StringTokenizer st;\n \n public MyScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n \n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n int nextInt() {\n return Integer.parseInt(next());\n }\n \n long nextLong() {\n return Long.parseLong(next());\n }\n \n double nextDouble() {\n return Double.parseDouble(next());\n }\n \n String nextLine(){\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n \n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d9cfdd7dd56169709e32fd3424127cea", "src_uid": "64a842f9a41f85a83b7d65bfbe21b6cb", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\n \npublic class candies {\n public static boolean test(long k, long num) {\n long sum = 0;\n long current = num;\n while(current > 0) {\n long temp = Math.min(current, k);\n sum += temp;\n current -= temp;\n current -= (current/10);\n }\n return sum*2 >= n;\n }\n \n public static void main(String[] args) throws IOException {\n BufferedReader input = new BufferedReader(new InputStreamReader(System.in));\n\t\tlong n = Long.parseLong(input.readLine());\n\t\tlong start = 1;\n\t\tlong end = n;\n\t\tlong sol = n;\n\t\twhile(start <= end) {\n\t\t long mid = (start + end)/2;\n\t\t if(test(mid,n)) {\n\t\t sol = mid;\n\t\t end = mid-1;\n\t\t }\n\t\t else {\n\t\t start = mid+1;\n\t\t }\n\t\t}\n\t\tSystem.out.println(sol);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d87f21085e10d0bf9a609a2bc80a8f2c", "src_uid": "db1a50da538fa82038f8db6104d2ab93", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Test {\n\n int a, b, h, w, n, N = 1234567;\n int[] A;\n\n Scanner sca = new Scanner(System.in);\n\n void start() {\n\n a = sca.nextInt();\n b = sca.nextInt();\n h = sca.nextInt();\n w = sca.nextInt();\n n = sca.nextInt();\n\n A = new int[n];\n for (int i = 0; i < n; i++) A[i] = sca.nextInt();\n\n solve();\n }\n\n void solve() {\n Arrays.sort(A);\n int x = (a - 1)/h + 1, y = (b - 1)/w + 1;\n\n if (x == 1 && y == 1) {\n System.out.println(0);\n return;\n }\n\n// System.out.println(x + \" \" + y);\n// System.out.println(Arrays.toString(A));\n\n System.out.println(solv(n - 1, x, y, 1, 1));\n }\n\n int solv(int i, int x, int y, int cx, int cy) {\n if (cx >= x && cy >= y) return 0;\n if (i == -1) {\n return -1;\n }\n\n if (A[i] == 1) return solv(i - 1, x, y, cx, cy);\n if (cx >= x) {\n int z = cy;\n for (int j = i; j >= 0; j--) {\n z *= A[j];\n if (z >= y) return i - j + 1;\n }\n return -1;\n }\n\n if (cy >= y) {\n int z = cx;\n for (int j = i; j >= 0; j--) {\n z *= A[j];\n if (z >= x) return i - j + 1;\n }\n return -1;\n }\n\n int a = solv(i - 1, x, y, cx*A[i], cy);\n int b = solv(i - 1, x, y, cx, cy*A[i]);\n if (a == -1 && b == -1) return -1;\n if (a == -1) return b + 1;\n if (b == -1) return a + 1;\n return Math.min(a, b) + 1;\n }\n\n public static void main(String[] args) {\n new Test().start();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7990ef42d9b602aeeac12cab57c954fd", "src_uid": "18cb436618b2b85c3f5dc348c80882d5", "difficulty": 2100.0} {"lang": "Java 7", "source_code": "public class Solution {\n\tpublic static void main( String[] args ) {\n\t\tScanner in = new Scanner(System.in);\n\t\tString s = \"\";\n\t\ttry {\n\t\t\ts = in.nextLine();\n\t\t}\n\t\tcatch (Exception e){\n\t\t\te.printStackTrace();\n\t\t}\n\t\tin.close();\n\t\t\n\t\tSystem.out.println(get(s));\n\t}\n\t\n\tpublic static int get( String s ) {\n\t\tint ret = 0;\n\t\tint count = 1;\n\t\tfor( int i = 0; i < s.length(); i++ ) {\n\t\t\twhile( i + 1 < s.length() && s.charAt(i) == s.charAt(i+1) ) {\n\t\t\t\tcount++;\n\t\t\t\ti++;\n\t\t\t}\n\t\t\tif( count % 2 == 0 ) {\n\t\t\t\tret++;\n\t\t\t}\n\t\t\tcount = 1;\n\t\t}\n\t\treturn ret;\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cf9f42f3132782f118da6cd3ad4b5ff6", "src_uid": "8b26ca1ca2b28166c3d25dceb1f3d49f", "difficulty": null} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Racing {\n public static void main(String[] args) {\n int[] f = new int[100];\n int h;\n int m;\n int s; \n int t1;\n int t2;\n Scanner input = new Scanner(System.in);\n h = input.nextInt();\n m = input.nextInt();\n s = input.nextInt();\n t1 = input.nextInt();\n t2 = input.nextInt();\n h *= 5;\n t2 *= 5;\n t1 *= 5;\n h %= 60;\n t1 %= 60;\n t2 %= 60;\n f[a1]++;\n f[b1]++;\n f[c1]++;\n if (t1 > t2) {\n int t;\n t = t1;\n t1 = t2;\n t2 = t;\n }\n int ans = 0;\n for (int i = t1; i < t2; i++){// no curly braces\n ans += f[i];\n if (ans % 3 == 0)\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "353b540e6ffa699402554ba0d124b354", "src_uid": "912c8f557a976bdedda728ba9f916c95", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Test {\n private static final int mod = 100000007;\n public static void main(String[] args) throws IOException {\n BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n String str = reader.readLine();\n int[] digitCount = new int[10];\n long[] dp = new long[mod];\n int digitsMask = init(digitCount, str, dp);\n System.out.println(solve(digitCount, true, str.length(), \"\", 0, digitsMask, dp));\n }\n\n private static int init(int[] digitCount, String str, long[] dp) {\n int mask = 0;\n for(char a: str.toCharArray()) {\n mask |= (1 << (a - '0'));\n digitCount[a - '0']++;\n }\n for(int i = 0; i < dp.length; i++) {\n dp[i] = -1;\n }\n return mask;\n }\n\n private static long solve(int[] digitCount, boolean start, int rem, String current, int mask, int digitsMask, long[] dp) {\n if(rem == 0) {\n return 1;\n }\n int hash = getHash(digitCount);\n\n if(dp[hash] != -1){\n return dp[hash];\n }\n\n long ans = mask == digitsMask? 1: 0;\n int end = start? 1: 0;\n for(int i = 9; i >= end; i--) {\n if(digitCount[i] != 0) {\n digitCount[i]--;\n ans += solve(digitCount, false, rem - 1, current + i, mask | (1 << i), digitsMask, dp);\n digitCount[i]++;\n }\n }\n return dp[hash] = ans;\n }\n\n private static int getHash(int[] digitsCount) {\n int base = 1;\n int res = 0;\n for(int i = 0; i < 10; i++) {\n res = (res % mod + (base * digitsCount[i]) % mod) % mod;\n base = (base % mod * 23) % mod;\n }\n return res;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "22cf56b8c89e4a3cac808c215b7858c5", "src_uid": "7f4e533f49b73cc2b96b4c56847295f2", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "///////////////////package acm;\n\nimport java.util.*;\n\nimport acm.second.Scanner;\n\nimport java.io.*;\n\npublic class first {\n\tstatic PrintWriter out;\n\n\tpublic static void main(String[] args) throws IOException, InterruptedException {\n\t\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tlong n = sc.nextLong();\n\t\tlong x = sc.nextLong();\n\t\tlong y=sc.nextLong();\n\t\tlong ma=Math.max(n-x,n-y);\n\t\tlong mb=Math.max(x-1, y-1);\n\t\tif(ma>> recipe = new HashMap>>();\n\t\tArrayList> backpacks = new ArrayList>();\n\t\tint k = nextInt();\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\t\tint q = nextInt();\n\t\tfor (int i =0)\n\t}\n\t\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new Main()).start();\n\n\t}\n\n\tprivate BufferedReader br;\n\tprivate StringTokenizer st;\n\tprivate PrintWriter out;\n\n\t@Override\n\tpublic void run() {\n\t\ttry {\n\t\t\tLocale.setDefault(Locale.US);\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tst = new StringTokenizer(\"\");\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t\tout.close();\t\t\t\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(-1);\n\t\t}\n\t\t\n\t}\n\n\t\n\t\n\tString next() throws IOException {\n\t\twhile (!st.hasMoreTokens()) {\n\t\t\tString temp = br.readLine();\n\t\t\tif (temp == null) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tst = new StringTokenizer(temp);\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\n\t}\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(next());\n\t}\n\t\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f65970be2de13d525b6fb292968dbdd7", "src_uid": "645a6ca9a8dda6946c2cc055a4beb08f", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n \n \n \n static void ans(int pos,int mera,int chotu)\n {\n \n int flag=0;\n int flag2=0;\n int pehla=-1;\n \n for(int my=mera;pehla==-1;my--)\n {\n \n \n int i = (my/50)%475;\n int j=25;\n \n while(j-->0)\n {\n i = (i * 96 + 42)% 475 ;\n \n if((26+i)==pos)\n {\n pehla=my;\n flag=1;\n break;\n } \n } \n \n if(flag==1)\n break;\n }\n \n \n // System.out.println(mera-pehla);\n \n \n int dusra=-1;\n \n for(int my=mera;dusra==-1;my++)\n {\n \n \n int i = (my/50)%475;\n int j=25;\n \n while(j-->0)\n {\n i = (i * 96 + 42)% 475 ;\n \n if((26+i)==pos)\n {\n dusra=my;\n flag2=1;\n break;\n } \n } \n \n if(flag2==1)\n break;\n }\n \n // System.out.println();\n \n \n if((dusra-mera)>(mera-pehla))\n {\n System.out.println(0) ;\n }\n else\n {\n int dif=dusra-mera;\n \n int hacks=dif/100;\n if(dif%100!=0)\n hacks++;\n \n System.out.println(hacks);\n \n }\n \n }\n \n\n public static void main(String[] args) {\n \n Scanner sc=new Scanner(System.in);\n \n int n=sc.nextInt();\n \n int my=sc.nextInt();\n int min=sc.nextInt();\n \n \n ans(n,my,min);\n \n \n \n \n \n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2dcb7da1c5bd063d201c13d764390555", "src_uid": "c9c22e03c70a94a745b451fc79e112fd", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "//package codeforeces370;\n\n\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\n\n\npublic class q1{\n\tstatic int mod=(int)(1e9+7);\n\tpublic static void main(String[] ags)\n\t{\n\t\tInputReader in=new InputReader(System.in);\n\t\tPrintWriter pw=new PrintWriter(System.out);\n\t\t//int n=in.nextInt();\n\t\t//int[] a=readint(in,n);\n\t\tint a=in.nextInt();\n\t\tint b=in.nextInt();\n\t\tint k=in.nextInt();\n\t\tint t=in.nextInt();\n\t\tlong[][] dp=new long[2*k*t+1001][t+1];\n\t\tint offset=k*t;\n\t\tdp[offset][0]=1;\n\t\tfor(int i=1;i<=t;i++)\n\t\t{\n\t\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\tfor(int j=-(i-1)*k;j<=(i-1)*k;j++)\n\t\t\t\t{\n\t\t\t\t\n\t\t\t\t\tdp[j+offset-k][i]+=dp[j+offset][i-1];\n\t\t\t\t\tdp[j+offset-k][i]%=mod;\n\t\t\t\t}\n\t\t\t\t/*for(int f=-k*t;f<=k*t;f++)\n\t\t\t\t{\n\t\t\t\t\tSystem.out.println(\"for \"+i+\" f \"+f+\" \"+dp[f+offset][i]);\n\t\t\t\t}\n\t\t\t\tSystem.out.println(\"hello \");*/\n\t\t\t\tlong total=0;\n\t\t\t\tlong[] pre=new long[2*k+1000];\n\t\t\t\t\n\t\t\t\tfor(int j=-k*t;j<=k*t;j++)\n\t\t\t\t{\n\t\t\t\t\t\n\t\t\t\t\ttotal+=dp[j+offset][i];\n\t\t\t\t\tpre[j+offset]=total;\n\t\t\t\t\ttotal%=mod;\n\t\t\t\t\tdp[j+offset][i]=total;\n\t\t\t\t\tif(j-(2*k+1)+offset>=0)\n\t\t\t\t\t{\n\t\t\t\t\t\tdp[j+offset][i]-=pre[j-(2*k+1)+offset];\n\t\t\t\t\t\tdp[j+offset][i]%=mod;\n\t\t\t\t\t\tif(dp[j+offset][i]<0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tdp[j+offset][i]+=mod;\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}\n\t\t\t\t\n\t\t\t\t\n\t\t}\n\t\tlong[] presum=new long[2*k+1001];\n\t\tpresum[0]=dp[0][t];\n\t\tfor(int i=1;i<=2*k*t;i++)\n\t\t{\n\t\t\tpresum[i]+=presum[i-1]+dp[i][t];\n\t\t\tpresum[i]%=mod;\n\t\t}\n\t\tlong ans=0;\n\t\t/*for(int i=-k*t;i<=k*t;i++)\n\t\t{\n\t\t\tSystem.out.println(dp[i+offset][t]+\" for \"+i);\n\t\t}*/\n\t\t/*int ans2=0;\n\t\tfor(int i=-k*t;i<=k*t;i++)\n\t\t{\n\t\t\tfor(int j=-k*t;j<=k*t;j++)\n\t\t\t{\n\t\t\t\tif(a+i>b+j)\n\t\t\t\t{\n\t\t\t\t\tans2+=(dp[i+offset][t]*dp[j+offset][t]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(\"ans2 is \"+ans2);*/\n\t\tfor(int i=-k*t;i<=k*t;i++)\n\t\t{\n\t\t\n\t\tint l=-k*t;\n\t\tint r=k*t;\n\t\tif(a+i<=b+l)\n\t\t{\n\t\t\tcontinue;\n\t\t}\n\t\tint mid=-1;\n\t\twhile(l<=r)\n\t\t{\n\t\t\tint mm=(l+r)>>1;\n\t\t\tif(l==r || r==l+1)\n\t\t\t{\n\t\t\t\tif(a+i>b+r)\n\t\t\t\t{\n\t\t\t\t\tmid=r;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tmid=l;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif(a+i>b+mm)\n\t\t\t{\n\t\t\t\tl=mm;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tr=mm;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t//System.out.println(\"mid is \"+mid+\" for \"+i);\n\t\t//System.out.println(\"presum mid is \"+presum[mid+offset]+\" dp is \"+dp[i+offset][t]);\n\t\tlong tt=presum[mid+offset]*dp[i+offset][t];\n\t\ttt%=mod;\n\t\tans+=tt;\n\t\tans%=mod;\n\t\t}\n\t\tSystem.out.println(ans%mod);\n\t\t\n\t\t\n\t\tpw.close();\n\t}\n\tpublic static int[] readint(InputReader in,int n)\n\t{\n\t\tint[] a=new int[n];\n\t\tfor(int i=0;i hm,int k)\n\t{\n\t\tint cc=0;\n\t\tif(hm.containsKey(k))\n\t\t{\n\t\t\tcc=hm.get(k);\n\t\t}\n\t\thm.put(k, cc+1);\n\t}\n\tpublic static void removehm(HashMap hm,int k)\n\t{\n\t\tint cc=hm.get(k);\n\t\tif(cc==1)\n\t\t{\n\t\t\thm.remove(k);\n\t\t}\n\t\telse\n\t\t{\n\t\t\thm.put(k,cc-1);\n\t\t}\n\t}\n\t\n\tstatic class InputReader {\n\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[8192];\n\t\tprivate int curChar;\n\t\tprivate int 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\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\n\t\t\tint res = 0;\n\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\n\t\t\treturn res * sgn;\n\t\t}\n\t\t\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\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\n\t\t\tlong res = 0;\n\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\n\t\t\treturn res * sgn;\n\t\t}\n\t\t\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\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 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\tpublic interface SpaceCharFilter {\n\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7c8e88a0bf973fd3e8390f8d93e93e3d", "src_uid": "8b8327512a318a5b5afd531ff7223bd0", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.util.stream.Collectors;\nimport java.util.stream.IntStream;\nimport java.util.stream.Stream;\n\npublic class Practice {\n\t\n\t\n\tstatic class length implements Comparator\n\t{\n\t\tpublic int compare(String a,String b)\n\t\t{\n\t\t\treturn(a.length()-b.length());\n\t\t}\n\t}\n\t\n\t\n\t\n\t\n\t static class FastReader\n\t {\n\t\t BufferedReader br;\n\t\t StringTokenizer st;\n\t\t public FastReader()\n\t\t {\n\t\t\t br = new BufferedReader(new InputStreamReader(System.in));\n\t\t }\n\t\t \n\t\t \n\t\t String next() \n\t { \n\t while (st == null || !st.hasMoreElements()) \n\t { \n\t try\n\t { \n\t st = new StringTokenizer(br.readLine()); \n\t } \n\t catch (IOException e) \n\t { \n\t e.printStackTrace(); \n\t } \n\t } \n\t return st.nextToken(); \n\t } \n\t\t \n\t\t \n\t\t int nextInt()\n\t\t {\n\t\t\t return Integer.parseInt(next());\n\t\t }\n\t\t long nextLong()\n\t\t {\n\t\t\t return Long.parseLong(next());\n\t\t }\n\t\t double nextDouble() \n\t { \n\t return Double.parseDouble(next()); \n\t } \n\t\t \n\t\t String nextLine() \n\t { \n\t String str = \"\"; \n\t try\n\t { \n\t str = br.readLine(); \n\t } \n\t catch (IOException e) \n\t { \n\t e.printStackTrace(); \n\t } \n\t return str; \n\t } \n\t }\n\n\t\tpublic static void main(String []args) throws Exception\n\t\t{\n\t\t\t//Scanner sc=new Scanner(System.in);\n\t\t\tFastReader in =new FastReader();\n\t\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\t\t//System.out.println\n\t\t\t//int n=in.nextInt();\n\t\t\t\n\t\t\t\n\t\t\tint n=in.nextInt();\n\t\t\tint l=in.nextInt();\n\t\t\tint r=in.nextInt();\n\t\t\tint min=n-(l-1);\n\t\t\tint i=1;\n\t\t\twhile(i<=(l-1))\n\t\t\t{\n\t\t\t\tmin=min+(int)Math.pow(2, i);\n\t\t\t\ti++;\n\t\t\t}\n\t\t\ti=0;\n\t\t\tint max=0;\n\t\t\tint max1=0,k=0;\n\t\t\twhile(i!=r)\n\t\t\t{\n\t\t\t\tmax1=(int)Math.pow(2,i);\n\t\t\t\tmax=max+max1;\n\t\t\t\ti++;\n\t\t\t\tk++;\n\t\t\t\t\n\t\t\t\t//pw.println(max+\" \"+max1);\n\t\t\t}\n\t\t\tmax=max+max1*(n-k);\n\t\t\t//pw.println(max);\n\t\t\tpw.print(min+\" \"+max);\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t", "lang_cluster": "Java", "compilation_error": true, "code_uid": "174f0b695edaddc10bd69e9097a454cc", "src_uid": "ce220726392fb0cacf0ec44a7490084a", "difficulty": 900.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\npublic class C51B {\n public static void main(String args[]){\n Scanner sc=new Scanner(System.in);\n //BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n //String str=br.readLine();\n //StringTokenizer str=new StringTokenizer();\n String str=sc.nextLine();\n String st2[]=(sc.nextLine()).split(\" \");\n\n\n String str2[]=str.split(\" \");\n long n[]=new long[str2.length];\n for(int i=0;i>=1;\n\t\t n*=n;\t \n\t\t}\n\t\treturn result;\n\t}\n\tstatic HashSet setChecker(int[] A,int m)\n\t{\n\t\t// boolean[] M = new boolean[m] ;\n\t\tHashSet H = new HashSet() ;\n\t\tint set_size = A.length ;\n\t\tint power_set_size = (int)pow(2,set_size) ;\n\t\tfor(int i=0;i H1 = setChecker(first_half,m) ;\n\t\tHashSet H2 = setChecker(second_half,m) ;\n\t\tInteger[] A1 = H1.toArray(new Integer[H1.size()]) ;\n\t\tInteger[] A2 = H2.toArray(new Integer[H2.size()]) ;\n\t\t\n\t\t// Iterator I1 = H1.iterator() ;\n\t\t// Iterator I2 = H2.iterator() ;\n\t\t// System.out.println(\"H1:\") ;\n\t\tint maxPV = 0 ;\n\t\tfor(int i=0;i maxPV)\n\t\t\t\t\tmaxPV = (A1[i]+A2[j])%m ;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println() ;\n\t\t// while(I1.hasNext())\n\t\t// {\n\t\t\t// int i = I1.next() ;\n\t\t\t// while(I2.hasNext)\n\t\t\t// {\n\t\t\t\t// int j = I2.next() ;\n\t\t\t\t// if((i+j)%m>maxPV)\n\t\t\t\t\t// maxPV = (i+j)%m ;\n\t\t\t// }\n\t\t// }\n\t\t// System.out.println(maxPV) ;\n\t\t// System.out.println(\"\\nH2:\") ;\n\t\t// while(I2.hasNext())\n\t\t// {\n\t\t\t// System.out.print(I2.next()+\" \") ;\n\t\t// }\n\t\t// for(int i=0;imaxPV)\n\t\t\t\t\t\t\t// maxPV = (i+j)%m ;\n\t\t\t\t\t// }\n\t\t\t\t// }\n\t\t\t// }\n\t\t// }\n\t\t\t\n\t\treturn maxPV ;\n\t}\n\tpublic static void main(String args[]) throws Exception\n\t{\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in)) ;\n\t\tString line1 = br.readLine() ;\n\t\tString line2 = br.readLine() ;\n\t\tint size = Integer.parseInt(line1.split(\" \")[0]) ;\n\t\tint m = Integer.parseInt(line1.split(\" \")[1]) ;\n\t\tint[] A = new int[size] ;\n\t\tfor(int i=0;i set = new TreeSet<>();\r\n\t\tint[][] cmp = new int[RADIX][RADIX];\r\n\t\tfor(int i=0; i comp = new Comparator() {\r\n\t\t\t@Override\r\n\t\t\tpublic int compare(Character o1, Character o2) {\r\n\t\t\t\treturn cmp[o1-'0'][o2-'0'];\r\n\t\t\t}\r\n\t\t};\r\n\t\t\r\n\t\tBigInteger curr = BigInteger.ZERO;\r\n\t\tBigInteger limit = BigInteger.valueOf(RADIX).pow(n);\r\n\t\tStringBuilder sb = new StringBuilder();\r\n\t\twhile(curr.compareTo(limit) < 0) {\r\n\t\t\tString s = curr.toString(RADIX);\r\n\t\t\tint padding = n-s.length();\r\n\t\t\tsb.setLength(0);\r\n\t\t\tfor(int i=0; i=0; i--) {\r\n//\t\t\t\tfor(int j=0; j 0320 -> 0230\r\n\r\n // [0000, 0001, 0002, 0003, 0011, 0012, 0013, 0021, 0022, 0023, 0030, 0031, 0033,\r\n\t\t// 0111, 0112, 0113, 0121, 0122, 0123, 0130, 0131, 0133,\r\n\t\t// 0211, 0212, 0213, 0221, 0222, 0223, 0230, 0231, 0233,\r\n\t\t// 0300, 0301, 0302, 0303, 0311, 0312, 0313, 0330, 0331, 0333,\r\n\t\t// 1111, 1112, 1113, 1121, 1122, 1123, 1130, 1131, 1133, 1211,\r\n\t\t// 1212, 1213, 1221, 1222, 1223, 1230, 1231, 1233,\r\n\t\t// 1300, 1301, 1302, 1303, 1311, 1312, 1313, 1330, 1331, 1333,\r\n\t\t// 2111, 2112, 2113, 2121, 2122, 2123, 2130, 2131, 2133,\r\n\t\t// 2211, 2212, 2213, 2221, 2222, 2223, 2230, 2231, 2233,\r\n\t\t// 2300, 2301, 2302, 2303, 2311, 2312, 2313, 2330, 2331, 2333,\r\n\t\t// 3000, 3001, 3002, 3003, 3011, 3012, 3013, 3021, 3022, 3023, 3030, 3031, 3033,\r\n\t\t// 3111, 3112, 3113, 3121, 3122, 3123, 3130, 3131, 3133,\r\n\t\t// 3300, 3301, 3302, 3303, 3311, 3312, 3313, 3330, 3331, 3333]\r\n\r\n\t\t// when inserting j\r\n\t\t// X + \r\n\t}\r\n\r\n\tfinal int RADIX = 10;\r\n\tprivate long solve2(int[] u, int[] v, int n) {\r\n\t\t// dp[i][set] = a[n-i..n-1] where elements in the set can move forward\r\n\t\tlong[][] dp = new long[n][1< remove k from the set\r\n\t\t\t\t\tif(cmp[j][k] == 0) {\r\n\t\t\t\t\t}\r\n\t\t\t\t\t// case 2: j, k can be swapped and j is smaller\r\n\t\t\t\t\telse if(cmp[j][k] == -1) {\r\n\t\t\t\t\t\tnext |= 1< not a representative\r\n\t\t\t\t\telse {\r\n\t\t\t\t\t\tok = false;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tisValid[mask][j] = ok;\r\n\t\t\t\tmap[mask][j] = next;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\t// n*2^RADIX*RADIX = 5*10^4*10^3*10 = 5*10^8\r\n\t\tfor(int i=n-2; i>=0; i--) {\r\n\t\t\tfor(int mask=0; mask < 1< xxxx01 * (1/2) + xxxx10 * (1/2)\r\n\t\t// yyyy1\r\n\t\t\r\n\t\t// (1/2) + (1/2) = 1\r\n\t\t// 2* + 2* = 1\r\n\t\t\r\n\t\t// string made of (0, 1)\r\n\t\t// -> different iff it has diff # of 0 or diff # of 1\r\n\t\t\r\n\t\t// (0, 1) (1, 2)\r\n\t\t// 0000000022222222\r\n\t\t// 0 and 2 can't swap\r\n\t\t// 021\r\n\t\t\r\n\t\t// xxxx0 + 0 -> k\r\n\t\t// xxxx0 + 1 -> k\r\n\t\t\r\n\t\t// xxxx1 + 0 -> X\r\n\t\t// \r\n\t\t\r\n\t\tint temp =1;\r\n\t\t\r\n\t\tfor(int i=1; i 0) {\r\n\t\t\tif( (m&1) == 1 ) {\r\n\t\t\t\tans *= curr;\r\n\t\t\t\tans %= p;\r\n\t\t\t}\r\n\t\t\tm >>= 1;\r\n\t\t\tcurr *= curr;\r\n\t\t\tcurr %= p;\r\n\t\t}\r\n\t\treturn ans;\t\t\r\n\t}\r\n\r\n\t// computes a^(p-2)\r\n\tstatic long inverse(int a, long p) {\r\n\t\treturn pow(a, (int)(p-2), p);\r\n\t}\r\n\t\r\n\tpublic static class MyScanner {\r\n\t\tBufferedReader br;\r\n\t\tStringTokenizer st;\r\n\r\n\t\t// 32768?\r\n\t\tpublic MyScanner(InputStream is, int bufferSize) {\r\n\t\t\tbr = new BufferedReader(new InputStreamReader(is), bufferSize);\r\n\t\t}\r\n\t\t\r\n\t\tpublic MyScanner(InputStream is) {\r\n\t\t\tbr = new BufferedReader(new InputStreamReader(is));\r\n\t\t\t// br = new BufferedReader(new InputStreamReader(System.in));\r\n\t\t\t// br = new BufferedReader(new InputStreamReader(new FileInputStream(\"input.txt\")));\r\n\t\t}\r\n\r\n\t\tpublic void close() {\r\n\t\t\ttry {\r\n\t\t\t\tbr.close();\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\te.printStackTrace();\r\n\t\t\t}\r\n\r\n\t\t}\r\n\r\n\t\tString next() {\r\n\t\t\twhile (st == null || !st.hasMoreElements()) {\r\n\t\t\t\ttry {\r\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\r\n\t\t\t\t} catch (IOException e) {\r\n\t\t\t\t\te.printStackTrace();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn st.nextToken();\r\n\t\t}\r\n\r\n\t\tint nextInt() {\r\n\t\t\treturn Integer.parseInt(next());\r\n\t\t}\r\n\r\n\t\tlong nextLong() {\r\n\t\t\treturn Long.parseLong(next());\r\n\t\t}\r\n\r\n\t\tdouble nextDouble() {\r\n\t\t\treturn Double.parseDouble(next());\r\n\t\t}\r\n\r\n\t\tString nextLine(){\r\n\t\t\tString str = \"\";\r\n\t\t\ttry {\r\n\t\t\t\tstr = br.readLine();\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\te.printStackTrace();\r\n\t\t\t}\r\n\t\t\treturn str;\r\n\t\t}\r\n\t\t\r\n\t\tint[][] nextTreeEdges(int n, int offset){\r\n\t\t\tint[][] e = new int[n-1][2];\r\n\t\t\tfor(int i=0; i 0){\r\n\t\t\t\tprint(arr[0]);\r\n\t\t\t\tfor(int i=1; i 0){\r\n\t\t\t\tprint(arr[0]);\r\n\t\t\t\tfor(int i=1; i void printAns(ArrayList arr){\r\n\t\t\tif(arr != null && arr.size() > 0){\r\n\t\t\t\tprint(arr.get(0));\r\n\t\t\t\tfor(int i=1; i void printlnAns(ArrayList arr){\r\n\t\t\tprintAns(arr);\r\n\t\t\tprintln();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printAns(int[] arr, int add){\r\n\t\t\tif(arr != null && arr.length > 0){\r\n\t\t\t\tprint(arr[0]+add);\r\n\t\t\t\tfor(int i=1; i arr, int add) {\r\n\t\t\tif(arr != null && arr.size() > 0){\r\n\t\t\t\tprint(arr.get(0)+add);\r\n\t\t\t\tfor(int i=1; i arr, int add){\r\n\t\t\tprintAns(arr, add);\r\n\t\t\tprintln();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printlnAnsSplit(long[] arr, int split){\r\n\t\t\tif(arr != null){\r\n\t\t\t\tfor(int i=0; i void printlnAnsSplit(ArrayList arr, int split){\r\n\t\t\tif(arr != null && !arr.isEmpty()){\r\n\t\t\t\tfor(int i=0; i\" + e[i][1] + \";\");\r\n\t\t}\r\n\t\tout2.println(\"}\");\r\n\t\tout2.close();\r\n\t}\r\n\t\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3d43229f2cb40b3c08d139995198f944", "src_uid": "60955fc2caa6ec99c7dcc1da5d36b1f8", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.BigInteger;\nimport java.util.Map.Entry;\n\nimport static java.lang.Math.*;\n\npublic class Solution extends PrintWriter {\n\n\tvoid run() {\n\n\t\tint n = nextInt(), m = 5;\n\n\t\tlong[][] dp = new long[m + 1][n + 1];\n\n\t\tfor (int i = 0; i <= n; i++) {\n\t\t\tdp[0][i] = 1;\n\t\t}\n\n\t\tfor (int i = 0; i <= n; i++) {\n\t\t\tdp[1][i] = i * i;\n\t\t}\n\n\t\tfor (int s = 2; s <= m; s++) {\n\t\t\tfor (int i = 1; i <= n; i++) {\n\t\t\t\tdp[s][i] = i * dp[s - 1][i - 1];\n\t\t\t}\n\t\t}\n\n\t\tprintln(dp[m][n]);\n\n\t}\n\n\tlong lcm(long a, long b) {\n\t\treturn a / gcd(a, b) * b;\n\t}\n\n\tlong gcd(long a, long b) {\n\t\treturn b == 0 ? a : gcd(b, a % b);\n\t}\n\n\tint[][] nextMatrix(int n, int m) {\n\t\tint[][] matrix = new int[n][m];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t\tmatrix[i][j] = nextInt();\n\t\treturn matrix;\n\t}\n\n\tString next() {\n\t\twhile (!tokenizer.hasMoreTokens())\n\t\t\ttokenizer = new StringTokenizer(nextLine());\n\t\treturn tokenizer.nextToken();\n\t}\n\n\tboolean hasNext() {\n\t\twhile (!tokenizer.hasMoreTokens()) {\n\t\t\tString line = nextLine();\n\t\t\tif (line == null) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\ttokenizer = new StringTokenizer(line);\n\t\t}\n\t\treturn true;\n\t}\n\n\tint[] nextArray(int n) {\n\t\tint[] array = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tarray[i] = nextInt();\n\t\t}\n\t\treturn array;\n\t}\n\n\tint nextInt() {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tlong nextLong() {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tString nextLine() {\n\t\ttry {\n\t\t\treturn reader.readLine();\n\t\t} catch (IOException err) {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tpublic Solution(OutputStream outputStream) {\n\t\tsuper(outputStream);\n\t}\n\n\tstatic BufferedReader reader;\n\tstatic StringTokenizer tokenizer = new StringTokenizer(\"\");\n\tstatic Random rnd = new Random();\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tSolution solution = new Solution(System.out);\n\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\tsolution.run();\n\t\tsolution.close();\n\t\treader.close();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "775831c2c33e9cba2f556156f002bd13", "src_uid": "92db14325cd8aee06b502c12d2e3dd81", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "\n//package marbles;\n\nimport java.util.Random;\nimport java.util.Scanner;\n\n/**\n *\n * @author Adreno\n */\npublic class Marbles {\n\n public static char reverse(char c) {\n if (c == 'N') return 'S';\n if (c == 'S') return 'N';\n if (c == 'W') return 'E';\n if (c == 'E') return 'W';\n return '-';\n }\n \n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n int n = scanner.nextInt();\n scanner.nextLine();\n String a = \"-\" + scanner.nextLine() + \"-\";\n String b = \"-\" + scanner.nextLine() + \"-\";\n long[] hajA = new long[n];\n long modA = 192389845L; // liittyy molempiin\n long modB = 219386759L; // liittyy molempiin\n long hajValA = 0;\n for (int i=0; i stack = new Stack<>();\n\t\tboolean bool = true;\n\t\twhile (b >= a) {\n\t\t\tif (b==a){\n\t\t\t\tbool = false;\n\t\t\t}\n\t\t\tstack.add(b);\n\t\t\tif (b % 2 == 0) {\n\t\t\t\tb = b / 2;\n\t\t\t} else {\n\t\t\t\tb = b / 10;\n\t\t\t}\n\t\t\t\tcount++;\n\t\t}\n\n\t\tif (!bool) {\n\t\t\tSystem.out.println(\"YES\");\n\t\t\tSystem.out.println(count);\n\n\t\t\twhile (!stack.isEmpty()) {\n\t\t\t\tSystem.out.print(stack.pop() + \" \");\n\t\t\t}\n\t\t} else {\n\t\t\tSystem.out.println(\"NO\");\n\t\t}\n\t}\n\n\tprivate 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\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e19167a3b75551742b32c2f6e9071b35", "src_uid": "fc3adb1a9a7f1122b567b4d8afd7b3f3", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintStream;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.util.Arrays;\nimport java.util.Comparator;\n\npublic class Solution {\n\n public static void main(String[] args) throws Exception {\n solve(System.in, System.out);\n }\n\n public static void solve(InputStream inputStream, PrintStream outputStream) throws Exception {\n StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(inputStream)));\n//\t\tBufferedReader in = new BufferedReader(new InputStreamReader(inputStream));\n PrintWriter out = new PrintWriter(new OutputStreamWriter(outputStream));\n\n int n = readInteger(in);\n final int[] a = new int[n];\n int[] prev = new int[n];\n int[] next = new int[n];\n Integer[] b = new Integer[n];\n for (int i = 0; i < n; i++) {\n a[i] = readInteger(in);\n b[i] = i;\n prev[i] = i - 1;\n next[i] = i + 1;\n }\n\n Arrays.sort(b, (i, j) -> Integer.compare(a[i], a[j]));\n\n int h = 0;\n int sum = 0;\n for (int i = 0; i < n - 2; i++) {\n sum += (a[b[i]] - h) * (n - i - 2);\n h = a[b[i]];\n if (prev[b[i]] >= 0 && next[b[i]] < n) {\n sum += Math.min(a[prev[b[i]]], a[next[b[i]]]) - h;\n }\n if (prev[b[i]] >= 0) {\n next[prev[b[i]]] = next[b[i]];\n }\n if (next[b[i]] < n) {\n prev[next[b[i]]] = prev[b[i]];\n }\n }\n\n out.println(sum);\n out.flush();\n }\n\n private static double readDouble(StreamTokenizer in) throws Exception { in.nextToken(); return in.nval; }\n private static int readInteger(StreamTokenizer in) throws Exception { return (int) readDouble(in); }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c2699828e71a866748f954fcdd224e14", "src_uid": "e7e0f9069166fe992abe6f0e19caa6a1", "difficulty": 2500.0} {"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 */\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.nl();\n int k = in.ni();\n long[] divs = new long[100];\n int dn = 0;\n int[] divCnt = new int[100];\n long orig = n;\n for (long d = 2; d * d <= n; d++) {\n if (n % d == 0) {\n divs[dn++] = d;\n while (n % d == 0) {\n divCnt[dn - 1]++;\n n /= d;\n }\n }\n }\n if (n != 1) {\n divs[dn++] = n;\n divCnt[dn - 1] = 1;\n }\n n = orig;\n int maxCnt = 0;\n for (int i = 0; i < dn; i++) {\n maxCnt = Math.max(maxCnt, divCnt[i]);\n }\n long[] inv = new long[maxCnt + 2];\n inv[1] = 1;\n long mod = 1000_000_007;\n BigInteger MOD = BigInteger.valueOf(mod);\n BigInteger M2 = MOD.subtract(BigInteger.valueOf(2));\n for (int i = 2; i <= maxCnt + 1; i++) {\n inv[i] = BigInteger.valueOf(i).modPow(M2, MOD).longValue();\n }\n //System.out.println(Arrays.toString(inv));\n long ans = 1;\n for (int i = 0; i < dn; i++) {\n int cnt = divCnt[i] + 1;\n long div = divs[i];\n long[][] dp = new long[k + 1][cnt + 1];\n dp[0][cnt] = 1;\n for (int j = 1; j <= k; j++) {\n long sum = 0;\n for (int cn = cnt; cn > 0; cn--) {\n sum += dp[j - 1][cn] * inv[cn];\n sum %= mod;\n dp[j][cn] = sum;\n }\n }\n long pow = 1;\n long e = 0;\n for (int j = 1; j <= cnt; j++) {\n e += pow * dp[k][j];\n e %= mod;\n pow *= div;\n pow %= mod;\n }\n //System.out.println(\"e = \" + e);\n ans *= e;\n ans %= mod;\n }\n out.println(ans);\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 public long nl() {\n return Long.parseLong(ns());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0233028bd3fde3a9a230dce7363a761a", "src_uid": "dc466d9c24b7dcb37c0e99337b4124d2", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "\n\nimport java.util.Scanner;\n\npublic class exams {\n\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner scn = new Scanner(System.in);\n\t\tint n = scn.nextInt();\n\t\tint k = scn.nextInt();\n\t\tboolean dp[][] = new boolean[n + 1][k + 1];\n\t\tint ans[][] = new int[n + 1][k + 1];\n\t\tfor (int i = 0; i <= n; i++) {\n\t\t\tfor (int j = 0; j <= k; j++) {\n\t\t\t\tans[i][j] = Integer.MAX_VALUE;\n\t\t\t}\n\t\t}\n\t\tdp[0][0] = true;\n\t\tans[0][0] = 0;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tfor (int j = 2; j <= k; j++) {\n\t\t\t\tint count = 0;\n\t\t\t\tif (j - 2 >= 0 && dp[i - 1][j - 2]) {\n\t\t\t\t\tdp[i][j] = true;\n\t\t\t\t\tcount = ans[i - 1][j - 2];\n\t\t\t\t\tans[i][j] = Math.min(ans[i][j], count + 1);\n\t\t\t\t}\n\t\t\t\tif (j - 3 >= 0 && dp[i - 1][j - 3]) {\n\t\t\t\t\tdp[i][j] = true;\n\t\t\t\t\tcount = ans[i - 1][j - 3];\n\t\t\t\t\tans[i][j] = Math.min(ans[i][j], count);\n\t\t\t\t}\n\t\t\t\tif (j - 4 >= 0 && dp[i - 1][j - 4]) {\n\t\t\t\t\tdp[i][j] = true;\n\t\t\t\t\tcount = ans[i - 1][j - 4];\n\t\t\t\t\tans[i][j] = Math.min(ans[i][j], count);\n\t\t\t\t}\n\t\t\t\tif (j - 5 >= 0 && dp[i - 1][j - 5]) {\n\t\t\t\t\tdp[i][j] = true;\n\t\t\t\t\tcount = ans[i - 1][j - 5];\n\t\t\t\t\tans[i][j] = Math.min(ans[i][j], count);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans[n][k]);\n\n\t}\n\n\tprivate static void solve(int count, int sum, int k, int n) {\n\t\tif (n == 0) {\n\t\t\tif (sum == k) {\n\t\t\t\tans = Math.min(ans, count);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tfor (int i = 2; i <= 5; i++) {\n\t\t\tif (i == 2) {\n\t\t\t\tsolve(count + 1, sum + i, k, n - 1);\n\t\t\t} else {\n\t\t\t\tsolve(count, sum + i, k, n - 1);\n\t\t\t}\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f21f12cb56bc10cfe91cdc0a0a7738f1", "src_uid": "5a5e46042c3f18529a03cb5c868df7e8", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Main {\n public static void main(String[] args){\n InputStream inputStream = System.in;\n InputReader in = new InputReader(inputStream);\n Task solver = new Task(in);\n solver.solve();\n }\n\n static class Task{\n InputReader in;\n\n Task(InputReader in){\n this.in=in;\n }\n\n public void solve(){\n int n=in.nextInt(),k=in.nextInt();\n int min,max;\n\n if(k==0||n==k){\n min=0;\n max=0;\n System.out.println(min+\" \"+max);\n return;\n }\n min=1;\n max=minimum(n-k,2*k);\n\n System.out.println(min+\" \"+max);\n }\n \n int minimum(int a,int b){\n if(a= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int peek() {\n if (numChars == -1) {\n return -1;\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n return -1;\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar];\n }\n\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\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 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 String nextString(){\n int c = read();\n while (isSpaceChar(c)){\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do{\n if (Character.isValidCodePoint(c){\n res.appendCodePoint(c);\n }\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c){\n if (filter != null){\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c){\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n private String readLine0(){\n StringBuilder buf = new StringBuilder();\n int c = read();\n while (c != '\\n' && c != -1){\n if (c != '\\r'){\n buf.appendCodePoint(c);\n }\n c = read();\n }\n return buf.toString();\n }\n\n public String readLine(){\n String s = readLine0();\n while (s.trim().length() == 0){\n s = readLine0();\n }\n return s;\n }\n\n public String readLine(boolean ignoreEmptyLines){\n if (ignoreEmptyLines){\n return readLine();\n } else{\n return readLine0();\n }\n }\n\n public BigInteger readBigInteger(){\n try{\n return new BigInteger(nextString());\n } catch (NumberFormatException e){\n throw new InputMismatchException();\n }\n }\n\n public char nextCharacter(){\n int c = read();\n while (isSpaceChar(c)){\n c = read();\n }\n return (char) c;\n }\n\n public double nextDouble(){\n int c = read();\n while (isSpaceChar(c)){\n c = read();\n }\n int sgn = 1;\n if (c == '-'){\n sgn = -1;\n c = read();\n }\n double res = 0;\n while (!isSpaceChar(c) && c != '.'){\n if (c == 'e' || c == 'E'){\n return res * Math.pow(10, nextInt());\n }\n if (c < '0' || c > '9'){\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n }\n if (c == '.'){\n c = read();\n double m = 1;\n while (!isSpaceChar(c)){\n if (c == 'e' || c == 'E'){\n return res * Math.pow(10, nextInt());\n }\n if (c < '0' || c > '9'){\n throw new InputMismatchException();\n }\n m /= 10;\n res += (c - '0') * m;\n c = read();\n }\n }\n return res * sgn;\n }\n\n public boolean isExhausted(){\n int value;\n while (isSpaceChar(value = peek()) && value != -1){\n read();\n }\n return value == -1;\n }\n\n public String next(){\n return nextString();\n }\n\n public SpaceCharFilter getFilter(){\n return filter;\n }\n\n public void setFilter(SpaceCharFilter filter){\n this.filter = filter;\n }\n\n public interface SpaceCharFilter{\n public boolean isSpaceChar(int ch);\n }\n\n public int[] nextIntArray(int n){\n int[] array=new int[n];\n for(int i=0;i max) {\n\t\t\t\tmaxI = i;\n\t\t\t\tmax = arr[i];\n\t\t\t}\n\t\t}\n\n\t\tif(minI > maxI){\n\t\t\tSystem.out.println(n - maxI - 1);\n\t\t}\n\t\telse{\n\t\t\tSystem.out.println(n - minI - 1);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f2523cd1cd4965cb303d358ff69999af", "src_uid": "1d2b81ce842f8c97656d96bddff4e8b4", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class KN {\n public static void main(String... args) {\n Scanner sc = new Scanner(System.in);\n int number = sc.nextInt();\n \n int f_dig = number / 10;\n int s_dig = number % 10;\n \n if (number == 10 || number == 11 || (number >= 13 && number <= 19)) {\n System.out.println(\"YES\");\n System.exit(0);\n }\n \n if (f_dig == 2 || f_dig == 7 || f_dig == 9) {\n System.out.println(\"YES\");\n System.exit(0);\n }\n \n if (s_dig == 1 || s_dig == 7 || s_dig == 9) {\n System.out.println(\"YES\");\n System.exit(0);\n }\n \n System.out.println(\"NO\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "23ef685fd3ba1a5707c9f5d54c19b337", "src_uid": "821529a4644b74483bcdf80fc318d1f8", "difficulty": null} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author darshan\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskB solver = new TaskB();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskB {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n long n = in.nextLong();\n long res = 0;\n long tp = n;\n while (n % 2 == 0) {\n n = n / 2;\n res++;\n }\n while (n % 3 == 0) {\n n = n / 3;\n res++;\n }\n for (long i = 5; i * i <= tp; i += 6) {\n while (n % i == 0) {\n n = n / i;\n res++;\n }\n while (n % (i + 2) == 0) {\n n = n / (i + 2);\n res++;\n }\n }\n if (n > 1) {\n res++\n\n }\n out.println(res);\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\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\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 boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e91d8541673624647b562bbe58628894", "src_uid": "a1e80ddd97026835a84f91bac8eb21e6", "difficulty": 1200.0} {"lang": "Java 7", "source_code": "package cf;\n\nimport java.util.*;\n\npublic class Cf {\n\n public static void main(String[] args)\n {\n Scanner s = new Scanner(System.in);\n int n = s.nextInt(), m = s.nextInt();\n int t = n % m;\n\n if (t == 0)\n {\n for (int i = 0; i < m; ++i)\n {\n System.out.format(\"%d \", n / m);\n }\n }\n else\n {\n for (int i = 0; i < m - t; ++i)\n {\n System.out.format(\"%d \", n / m);\n }\n\n for (int i = 0; i < t; ++i)\n {\n System.out.format(\"%d \", n / m + 1);\n }\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "743b0d98aadac0476a495b7080120c47", "src_uid": "0b2c1650979a9931e00ffe32a70e3c23", "difficulty": 800.0} {"lang": "Java 8", "source_code": "\n import java.util.*;\npublic class Main{\n public static void main(String[] args)\n {\n Scanner sc=new Scanner(System.in);\n\n int a,b,c,n;\n int x=0;\n n=sc.nextInt();\n for ( a = 1; a<= n; a++) {\n for ( b = a; b <= n; b++) {\n for(c=b;c<=n;c++)\n { \n if (a^b^c==0 )\n x++;\n }}}\n System.out.printf(x);\n }\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cef4d8d96edfcbdac81d4f58b9bb95be", "src_uid": "838f2e75fdff0f13f002c0dfff0b2e8d", "difficulty": 1300.0} {"lang": "Java 7", "source_code": "// @author Sanzhar\nimport java.io.*;\nimport java.util.*;\nimport java.awt.Point;\n\npublic class Template {\n\n BufferedReader in;\n PrintWriter out;\n StringTokenizer st;\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (Exception e) {\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 public void run() throws Exception {\n //in = new BufferedReader(new FileReader(\"input.txt\"));\n //out = new PrintWriter(new FileWriter(\"output.txt\"));\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n solve();\n out.flush();\n out.close();\n in.close();\n }\n\n public void solve() throws Exception {\n long n = nextLong();\n long mod = 1000000007;\n long ans = 1;\n for (long i = 1; i <= n; i++) {\n if (i == n - 1) {\n continue;\n }\n ans *= i;\n ans %= mod;\n }\n ans = (2 * ans * ans) % mod;\n out.println(ans);\n }\n\n public static void main(String[] args) throws Exception {\n new Template().run();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "378150733a5d865a98bfaf2098bd414b", "src_uid": "a6a804ce23bc48ec825c17d64ac0bb69", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class B {\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tlong n = scan.nextLong();\n\t\tlong k = Long.numberOfTrailingZeros(Long.highestOneBit(n));\n\t\tif((1 << k) < n)\n\t\t\tk++;\n\t\tlong num = k * (1L << k);\n\t\tlong den = n;\n\t\tlong gcd = gcd(num,den);\n\t\tnum /= gcd;\n\t\tden /= gcd;\n\t\tSystem.out.println(num + \"/\" + den);\n\t}\n\tstatic long gcd(long a, long b) {\n\t\tif(b == 0)\n\t\t\treturn a;\n\t\treturn gcd(b,a%b);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7fab794b3b0633ce50d3cf9b7e7a237c", "src_uid": "5491b4a27991153a61ac4a2618b2cd0e", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.Locale;\nimport java.util.StringTokenizer;\n\npublic class A implements Runnable {\n\n private static final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\n private BufferedReader in;\n private PrintWriter out;\n private StringTokenizer tok = new StringTokenizer(\"\");\n\n private void init() throws FileNotFoundException {\n Locale.setDefault(Locale.US);\n String fileName = \"\";\n if (ONLINE_JUDGE && fileName.isEmpty()) {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n } else {\n if (fileName.isEmpty()) {\n in = new BufferedReader(new FileReader(\"input.txt\"));\n out = new PrintWriter(\"output.txt\");\n } else {\n in = new BufferedReader(new FileReader(fileName + \".in\"));\n out = new PrintWriter(fileName + \".out\");\n }\n }\n }\n\n String readString() {\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() {\n return Integer.parseInt(readString());\n }\n\n long readLong() {\n return Long.parseLong(readString());\n }\n\n double readDouble() {\n return Double.parseDouble(readString());\n }\n\n int[] readIntArray(int size) {\n int[] a = new int[size];\n for (int i = 0; i < size; i++) {\n a[i] = readInt();\n }\n return a;\n }\n\n public static void main(String[] args) {\n //new Thread(null, new _Solution(), \"\", 128 * (1L << 20)).start();\n new A().run();\n }\n\n long timeBegin, timeEnd;\n\n void time() {\n timeEnd = System.currentTimeMillis();\n System.err.println(\"Time = \" + (timeEnd - timeBegin));\n }\n\n @Override\n public void run() {\n try {\n timeBegin = System.currentTimeMillis();\n init();\n solve();\n out.close();\n time();\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(-1);\n }\n }\n\n int gcd(int a, int b) {\n return a == 0 ? b : gcd(b % a, a);\n }\n\n private void solve() {\n int n = readInt();\n int m = readInt();\n int x = readInt();\n int y = readInt();\n int a = readInt();\n int b = readInt();\n\n int gcd = gcd(a, b);\n a /= gcd;\n b /= gcd;\n\n int width = 0;\n int height = 0;\n int left = 0, right = n / a;\n while (left <= right) {\n int mid = (left + right) >> 1;\n long curWidth = 1l * a * mid;\n if (curWidth <= n) {\n long curHeight = 1l * mid * b;\n if (curHeight <= m) {\n width = (int) curWidth;\n height = (int) curHeight;\n left = mid + 1;\n } else {\n right = mid - 1;\n }\n } else {\n right = mid - 1;\n }\n }\n\n int x1 = x - width / 2 - width % 2;\n if (x1 < 0) {\n x1 = 0;\n }\n if (x1 + width > n) {\n x1 = n - width;\n }\n\n int y1 = y - height / 2 - height % 2;\n if (y1 < 0) {\n y1 = 0;\n }\n if (y1 + height > m) {\n y1 = m - height;\n }\n\n int xAns = x1;\n int yAns = y1;\n String answer = xAns + \" \" + yAns + \" \" + (xAns + width) + \" \" + (yAns + height);\n\n final int delta = 10;\n for (int xx = x1 - delta; xx <= x1 + delta; xx++) {\n for (int yy = y1 - delta; yy <= y1 + delta; yy++) {\n if (xx >= 0 && xx + width <= n && yy >= 0 && yy + height <= m &&\n xx <= x && x <= xx + width && yy <= y && y <= yy + height) {\n long distAns = getDistSqr(2 * x, 2 * y, 2 * xAns + width, 2 * yAns + height);\n long distCur = getDistSqr(2 * x, 2 * y, 2 * xx + width, 2 * yy + height);\n if (distCur < distAns) {\n xAns = xx;\n yAns = yy;\n answer = xAns + \" \" + yAns + \" \" + (xAns + width) + \" \" + (yAns + height);\n } else if (distCur == distAns) {\n String curAnswer = xx + \" \" + yy + \" \" + (xx + width) + \" \" + (yy + height);\n if (curAnswer.compareTo(answer) < 0) {\n xAns = xx;\n yAns = yy;\n answer = xAns + \" \" + yAns + \" \" + (xAns + width) + \" \" + (yAns + height);\n }\n }\n }\n }\n }\n\n out.println(answer);\n }\n\n long getDistSqr(int x1, int y1, int x2, int y2) {\n if (x2 < 0 || y2 < 0) {\n System.err.println(\"hell\");\n }\n long dx = x1 - x2;\n long dy = y1 - y2;\n return dx * dx + dy * dy;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "de0682b4005467bea84d63d4b2a8c2fc", "src_uid": "8f1211b995f35462ae83b2be27f54585", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\nimport java.util.*;\npublic class Main {\n\n public static void main(String[] args) {\n int f,a,t;\n \n Scanner in = new Scanner(System.in);\n f = in.nextInt();\n a = in.nextInt();\n t = in.nextInt();\n in.nextLine();\n\n int[] it = new int [a];\n for ( int i = 0; i < a; ++i ) it[i] = 0;\n\n for ( int i = 0; i < f; ++i ) {\n for ( int j = 0; j < a; ++j ) {\n char c;\n c = in.findInLine(\".\").charAt(0);\n if ( c == 'Y' ) it[j] +=1;\n }\n if ( i != friends - 1 ) {\n in.nextLine(); \n }\n\n }\n int res = 0;\n for ( int i = 0; i < a; ++i ) {\n if ( it[i] >= t ) res++;\n }\n\n System.out.println(res+\"\");\n\n \n }\n \n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a08be1a03311b12fa2148b7efa14d8b2", "src_uid": "4c978130187e8ae6ca013d3f781b064e", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Summer{\n public static void main(String args[]){\n Scanner scan = new Scanner(System.in);\n \n int pos = scan.nextInt();\n \n String result = \"1\";\n int num = 2;\n \n while(result.length < pos){\n result += num;\n num++;\n }\n \n System.out.println(result.charAt(pos));\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1f5c2e30516734daf39ce8af480a1f1b", "src_uid": "2d46e34839261eda822f0c23c6e19121", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Calendar {\n int rows;\n int columns;\n public int getRows() {\n return rows;\n }\n\n public void setRows() {\n this.rows = 7;\n }\n\n public int getColumns() {\n return columns;\n }\n\n public void setColumns(int firstDay, int month) {\n switch (month) {\n case 1:\n case 3:\n case 5:\n case 7:\n case 8:\n case 10:\n case 12://31 DAYS\n //System.out.println(\"31 DAYS\");\n if (firstDay > 5)\n this.columns = 6;\n else\n this.columns = 5;\n break;\n case 4:\n case 6:\n case 9:\n case 11://30 DAYS\n\n //System.out.println(\"30 DAYS\");\n if (firstDay > 6)\n this.columns = 6;\n else\n this.columns = 5;\n break;\n case 2://28 DAYS\n //System.out.println(\"28 DAYS\");\n if (firstDay > 1)\n this.columns = 5;\n else\n this.columns = 4;\n break;\n default:\n System.out.println(\"Invalid month.\");\n break;\n\n }\n }\n}\n\n\npublic class Play {\n public static void main(String[] args) {\n int firstDay = 0, month = 0;\n Scanner input = new Scanner(System.in);\n\n month = input.nextInt();\n\n if(input.hasNext()) {\n firstDay = input.nextInt();\n }\n Calendar firstTry = new Calendar();\n firstTry.setRows();\n firstTry.setColumns(firstDay,month);\n System.out.println(firstTry.getColumns());\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1d9c88a11baca0af240c7afa4f76350a", "src_uid": "5b969b6f564df6f71e23d4adfb2ded74", "difficulty": 800.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n \npublic class BeautifulStrings_336D {\n\t\n\tpublic final static int mod = 1000000007;\n\t\n\tstatic long exp (long x, long n)\n\t{\n\t\tx%=mod;\n\t\tif (n == 0)\n\t\t\treturn 1;\n\t\telse if (n == 1)\n\t\t\treturn x%mod;\n\t\telse if (n%2 == 0)\n\t\t\treturn exp(x*x%mod, n/2)%mod;\n\t\telse if (n%2 == 1)\n\t\t\treturn x*exp(x*x%mod, (n-1)/2)%mod;\n\t\telse\n\t\t\treturn 1;\n\t}\n\n\tstatic int ncr (int n, int r)\n\t{\n\t\tlong num = 1;\n\t\tfor (int i = n-r+1; i <= n; i++)\n\t\t{\n\t\t\tnum *= i;\n\t\t\tnum %= mod;\n\t\t}\n\t\tlong denom = 1;\n\t\tfor (int i = 1; i <= r; i++)\n\t\t{\n\t\t\tdenom *= i;\n\t\t\tdenom %= mod;\n\t\t}\n\t\treturn (int)(num*exp(denom,(long)mod-2)%mod);\n\t}\n\n\tvoid run() throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n//\t\tBufferedReader br = new BufferedReader(new FileReader(\"336D.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 g = Integer.parseInt(st.nextToken());\n\t\tint count = 0;\n\t\tif (n == 0 && m == 0)\n\t\t{\n\t\t\tSystem.out.println(count);\n\t\t\tSystem.exit(0);\n\t\t}\n\t\tif (n == 0)\n\t\t{\n\t\t\tSystem.out.println(1-g);\n\t\t\tSystem.exit(0);\n\t\t}\n\t\tif (m == 0)\n\t\t{\n\t\t\tif (n%2 == 0)\n\t\t\t{\t\n\t\t\t\tSystem.out.println(g);\n\t\t\t\tSystem.exit(0);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tSystem.out.println(1-g);\n\t\t\t\tSystem.exit(0);\n\t\t\t}\n\t\t}\n\t\tif (m == 1)\n\t\t{\n\t\t\tif (n%2 == 0)\n\t\t\t{\n\t\t\t\tif (g == 0)\n\t\t\t\t{\n\t\t\t\t\tcount--;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tcount++;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (g == 0)\n\t\t\t\t{\n\t\t\t\t\tcount++;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tcount--;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t}\n\t\tif (g == 0)\n\t\t\tfor (int i = 1; i <= n+1; i+=2)\n\t\t\t\tcount += ncr(n+m-i,m-1);\n\t\telse\n\t\t\tfor (int i = 2; i <= n+1; i+=2)\n\t\t\t\tcount += ncr(n+m-i,m-1);\n\t\tSystem.out.println(count);\n\t\tSystem.exit(0);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBeautifulStrings_336D prog = new BeautifulStrings_336D();\n\t\tprog.run();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cee4e895f99619607ab44e7aeff28ece", "src_uid": "066dd9e6091238edf2912a6af4d29e7f", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.PrintStream;\nimport java.util.Scanner;\nimport java.util.ArrayList;\n\npublic class JavaApplication1 {\n\n static PrintStream p = System.out;\n public static void main(String[] args) {\n\n Scanner sc = new Scanner(System.in);\n char x = sc.next().charAt(0);\n char y = sc.next().charAt(0);\n int k = sc.nextInt();\n ArrayList e = new ArrayList();\n e.add('v');\n e.add('<');\n e.add('^');\n e.add('>');\n int del = (e.indexOf(y)-e.indexOf(x)+4) % 4;\n if(del==0 || del==4)\n p.print(\"undefined\");\n else if (del == n%4)\n p.print(\"cw\");\n else\n p.print(\"ccw\")\n }\n \n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ea6f2428d99e464e765e762e0eb3d605", "src_uid": "fb99ef80fd21f98674fe85d80a2e5298", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.IOException;\nimport java.util.HashMap;\nimport java.util.InputMismatchException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author anuj64\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n outputWriter out = new outputWriter(outputStream);\n TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskC {\n HashMap F;\n\n public void solve(int testNumber, InputReader in, outputWriter out) throws IOException {\n long n = in.nextLong();\n F = new HashMap();\n F.put(0, 1l);\n F.put(1, 1l);\n F.put(2, 2l);\n int high = 90;\n int low = 0, mid = 0;\n while (high > low + 1) {\n mid = (low + high) / 2;\n Long res = f(mid);\n if (res > n) {\n high = mid;\n } else {\n low = mid;\n }\n // out.println(mid+\" \"+res);\n }\n out.println((low - 1));\n //for(int i = 0; i < 100; i++)\n //out.println(i+\" \"+f(i));\n }\n\n long f(int n) {\n if (F.containsKey(n)) return F.get(n);\n int k = n / 2;\n if (n % 2 == 0) { // n=2*k\n F.put(n, (f(k) * f(k) + f(k - 1) * f(k - 1)));\n } else { // n=2*k+1\n F.put(n, f(k) * f(k + 1) + f(k - 1) * f(k));\n }\n return F.get(n);\n }\n\n }\n\n static class InputReader {\n private byte[] buf = new byte[8000];\n private int index;\n private int total;\n private InputStream in;\n\n public InputReader(InputStream stream) {\n in = stream;\n }\n\n public int scan() {\n if (total == -1)\n throw new InputMismatchException();\n if (index >= total) {\n index = 0;\n try {\n total = in.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (total <= 0)\n return -1;\n }\n return buf[index++];\n }\n\n public long nextLong() {\n long integer = 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 if (n >= '0' && n <= '9') {\n integer *= 10;\n integer += n - '0';\n n = scan();\n } else\n throw new InputMismatchException();\n }\n return neg * integer;\n }\n\n public 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 static class outputWriter {\n BufferedWriter out;\n\n public outputWriter() {\n out = new BufferedWriter(new OutputStreamWriter(System.out));\n }\n\n public void println(Object object) throws IOException {\n out.append(\"\" + object + \"\\n\");\n }\n\n public void close() throws IOException {\n out.close();\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "dd1f1d2f34556ad8f0430b24462533df", "src_uid": "3d3432b4f7c6a3b901161fa24b415b14", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\npublic class Solution{\n static double calcDist(int a,int b,int c,int d){\n return Math.sqrt(((c-a)*(c-a)+(d-b)*(d-b)));\n }\n public static void main(String[] args){\n \n \n Scanner in = new Scanner(System.in); \n int ax = in.nextInt();\n int ay = in.nextInt();\n int bx = in.nextInt();\n int by = in.nextInt();\n int cx = in.nextInt();\n int cy = in.nextInt();\n \n double distab = calcDist(ax,ay,bx,by);\n double distbc = calcDist(bx,by,cx,cy);\n double distac = calcDist(ax,ay,cx,cy);\n // float slopeab = (by-ay)/(bx-ax);\n // float slopebc = (cy-by)/(cx-bx);\n //determinant----> |A|=0\n // |ax ay 1|\n // |bx by 1|\n // |cx cy 1|\n if(ax*(by-cy)-ay*(bx-cx)+bx*cy-cx*by==0){\n System.out.println(\"No\";)\n }\n else if(distab!=distbc){System.out.println(\"No\");}\n \n else if((by-ay)*(cx-bx)==(cy-by)*(bx-ax)){\n System.out.println(\"No\");\n }\n \n else System.out.println(\"Yes\");\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d2cba712e0696a2b91e12c9f96a04a9f", "src_uid": "05ec6ec3e9ffcc0e856dc0d461e6eeab", "difficulty": 1400.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\nimport java.util.Arrays;\n\npublic class Solution {\n public static void main(String[] args) throws Exception {\n Solution solution = new Solution();\n solution.run();\n }\n\n private void run() throws Exception {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\n String s = in.readLine();\n\n BigInteger ans = BigInteger.ZERO;\n\n for (int i = 1; i < 10; i++) {\n boolean[] used = new boolean[26];\n Arrays.fill(used, false);\n BigInteger cur = BigInteger.ONE;\n\n if (Character.isDigit(s.charAt(0)) && s.charAt(0) != ((char)i + '0')) {\n continue;\n }\n\n for (int j = 1; j < s.length(); j++) {\n if (s.charAt(j) == '?') {\n cur = cur.multiply(BigInteger.TEN);\n } else if (Character.isAlphabetic(s.charAt(j)) && s.charAt(j) != s.charAt(0)) {\n used[(int)s.charAt(j) - 'A'] = true;\n }\n }\n\n int cnt = 0;\n for (int j = 0; j < 26; j++) {\n if (used[j]) {\n cnt++;\n }\n }\n\n //System.err.println(cur + \" \" + cnt);\n\n int v = 10;\n if (Character.isAlphabetic(s.charAt(0))) {\n v--;\n }\n for (int j = 0; j < cnt; j++) {\n cur = cur.multiply(BigInteger.valueOf(v - j));\n }\n\n ans = ans.add(cur);\n }\n\n System.out.println(ans);\n\n in.close();\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "274b06582e12a2ce14ba6a05f354c797", "src_uid": "d3c10d1b1a17ad018359e2dab80d2b82", "difficulty": 1100.0} {"lang": "Java 7", "source_code": "import java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.Scanner;\nimport java.util.Vector;\npublic class Main {\n\tstatic final long mod=1000000007;\n\tpublic static void main(String[] args) {\n\t\tint a[]=new int[20];\n\t\tScanner sc=new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\tlong s=sc.nextLong();\n\t\tfor(int i=0;i>j)&1)==1){\n\t\t\t\t\tflag*=-1;\n\t\t\t\t\tx-=a[j]+1;\n\t\t\t\t}\n\t\t\tif(x<0)\n\t\t\t\tcontinue;\n\t\t\tans=(ans+flag*lucas(x+n-1,n-1))%mod;\n\t\t\tans=(ans+mod)%mod;\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n\tstatic long lucas(long a,long b){\n\t\tif(b==0)\n\t\t\treturn 1;\n\t\treturn getc(a%mod,b%mod)*lucas(a/mod,b/mod)%mod;\n\t}\n\tstatic long getc(long a,long b){\n\t\tif(a>=1;\n\t\t}\n\t\treturn ans;\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fa6711410d01ff846038836ae409f65b", "src_uid": "8b883011eba9d15d284e54c7a85fcf74", "difficulty": 2300.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n public static void main (String args[]) throws FileNotFoundException {\n boolean online = \"true\".equals(System.getProperty(\"ONLINE_JUDGE\"));\n if (online) {\n in = new Scanner(System.in);\n out = new PrintWriter(System.out);\n }\n else {\n in = new Scanner(new File(\"input.txt\"));\n out = new PrintWriter(new File(\"output.txt\"));\n }\n \n new Solution().run();\n\n out.close();\n }\n \n private ArrayList[] g;\n private byte[] c;\n \n private void run () {\n int n = in.nextInt();\n \n g = new ArrayList[n];\n for (int i = 0; i < n; ++i)\n g[i] = new ArrayList();\n \n int m = in.nextInt();\n for (int i = 0; i < m; ++i) {\n int u = in.nextInt()-1,\n v = in.nextInt()-1;\n g[u].add(v);\n g[v].add(u);\n }\n \n c = new byte[n];\n for (int i = 0; i < n; ++i)\n dfs(i);\n for (int i = 0; i < n; ++i)\n out.print(c[i]);\n }\n \n private void dfs (int u) {\n int cnt = 0;\n for (int i = 0; i < g[u].size(); ++i)\n if (c[u] == c[g[u].get(i)])\n ++cnt;\n if (cnt > 1) {\n c[u] ^= 1;\n for (int i = 0; i < g[u].size(); ++i) {\n int v = g[u].get(i);\n if (c[u] == c[v])\n dfs(v);\n }\n }\n }\n \n private static Scanner in;\n private static PrintWriter out;\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b57dc5eb5c621d1e66ab735173833613", "src_uid": "7017f2c81d5aed716b90e46480f96582", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Main{\n public static void main(String []args){\n int n;\n String s;\n Scanner sc=new Scanner(System.in);\n n=sc.nextInt();\n s=sc.next();\n char x;\n String[] qaq={s};\n StringBuilder sb= new StringBuilder();\n int set=0;\n for(int i=0;i= 0; i--)\n\t\t\t{\n\t\t\t\tif((n&1<k)\n {breakLoop=true;break}\n }\n if(breakLoop)\n System.out.println(\"NO\");\n else\n System.out.println(\"YES\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ca4fa2906627df09b6d08f4ff22e79c3", "src_uid": "ceb3807aaffef60bcdbcc9a17a1391be", "difficulty": 900.0} {"lang": "Java 6", "source_code": "import java.util.*;\npublic class Statues {\n\tstatic int N;\n\tstatic Pair[] b;\n\tstatic int[] dx = new int[]{-1,-1,-1,0,1,1,1,0,0};\n\tstatic int[] dy = new int[]{-1,0,1,1,1,0,-1,-1,0};\n\t\n\tpublic static void main(StringProblem[] args){\n\t\tScanner reader = new Scanner(System.in);\n\t\tArrayList p = new ArrayList();\n\t\tfor(int i = 0; i < 8; i++){\n\t\t\tchar[] in = reader.next().toCharArray();\n\t\t\tfor(int j = 0; j < 8; j++)\n\t\t\t\tif(in[j] == 'S')\n\t\t\t\t\tp.add(new Pair(i,j));\n\t\t}\n\t\t\n\t\tb = new Pair[p.size()];\n\t\tb = p.toArray(b);\n\t\tN = b.length;\n\t\tboolean win = bfs();\n\t\tSystem.out.println(win?\"WIN\":\"LOSE\");\n\t}\n\t\n\tpublic static boolean bfs(){\n\t\tLinkedList q = new LinkedList();\n\t\tboolean[] visited = new boolean[8*8*9];\n\t\t\n\t\tq.add(e(7,0,0));\n\t\tvisited[e(7,0,0)] = true;\n\n\t\twhile(!q.isEmpty()){\n\t\t\t//if t == 8, return true;\n\t\t\tint c = q.remove();\n\t\t\tint t = c%9;\n\t\t\tc/=9;\n\t\t\tint y = c%8;\n\t\t\tc/=8;\n\t\t\tint x = c;\n\t\t\t\n\t\t\tPair m = new Pair(x,y);\n\t\t\t\n\t\t\tTreeSet statues = new TreeSet();\n\t\t\tfor(int i = 0; i < N; i++)\n\t\t\t\tstatues.add(new Pair(b[i].x+t,b[i].y));\n\t\t\t\n\t\t\tif(statues.contains(m))\n\t\t\t\tcontinue;\n\t\t\tif(t == 8)\n\t\t\t\treturn true;\n\t\t\t\n\t\t\tfor(int i = 0; i < dx.length; i++){\n\t\t\t\tint nx = x+dx[i];\n\t\t\t\tint ny = y+dy[i];\n\t\t\t\tint nn = e(nx,ny,t+1);\n\t\t\t\tif(nx >= 0 && nx < 8 && ny >= 0 && ny < 8 && !visited[nn] && !statues.contains(new Pair(nx,ny))){\n\t\t\t\t\tvisited[nn] = true;\n\t\t\t\t\tq.add(nn);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn false;\n\t}\n\t\n\tpublic static int e(int x, int y, int t){\n\t\treturn x*8*9+y*9+t;\n\t}\n\t\n\tpublic static class Pair implements Comparable{\n\t\tint x,y;\n\t\tpublic Pair(int _x, int _y){\n\t\t\tx = _x;\n\t\t\ty = _y;\n\t\t}\n\t\tpublic int compareTo(Pair p){\n\t\t\tif(x==p.x)\n\t\t\t\treturn y-p.y;\n\t\t\treturn x-p.x;\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "689844a232050c9dee4e805f1057d24a", "src_uid": "f47e4ab041288ba9567c19930eb9a090", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.util.Arrays;\n\npublic class abc\n{\n int hcf(int a, int h) \n {\n int temp; \n while(1)\n {\n temp = a%h;\n if(temp==0)\n return h;\n a = h;\n h = temp;\n }\n }\n\tpublic static void main (String[] args)\n\t{\n\t Scanner scn = new Scanner(System.in);\n int n = scn.nextInt();\n abc obj = new abc();\n int a,b;\n for (int i=1; i<=n/2; i++)\n {\n if(obj.hcf(i,n-i)==1)\n {\n a=i;\n b=n-i;\n }\n }\n System.out.println(a+\" \"+b);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a0adc3841ffe4ff5f228ac93349745af", "src_uid": "0af3515ed98d9d01ce00546333e98e77", "difficulty": 800.0} {"lang": "Java 6", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\n\n/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n/**\n * 6\n * 1 0\n * 0 0\n * 0 0\n * 1 1\n * 0 1\n * 1 1\n *\n * @author pttrung\n */\npublic class B {\n\n public static boolean circle;\n public static int a, b;\n public static int[] x = {0, 1, 0, -1};\n public static int[] y = {1, 0, -1, 0};\n\n public static void main(String[] args) throws FileNotFoundException {\n PrintWriter out;\n\n Scanner in = new Scanner();\n //out = new PrintWriter(new FileOutputStream(new File(\"output.txt\")));\n out = new PrintWriter(System.out);\n int n = in.nextInt();\n int m = in.nextInt() - 1;\n int k = in.nextInt() - 1;\n String line = in.nextLine();\n\n String move = in.nextLine();\n int[] pos = new int[move.length() + 1];\n pos[0] = k;\n int add = 1;\n if (line.equals(\"to head\")) {\n add = -1;\n }\n for (int i = 1; i < pos.length; i++) {\n pos[i] = pos[i - 1] + add;\n if (pos[i] == 0) {\n add = 1;\n }\n if (pos[i] == n - 1) {\n add = -1;\n }\n\n }\n int val = cal(0, m, n, pos, move);\n if (val == move.length()) {\n out.println(\"Stowaway\");\n } else {\n out.println(\"Controller \" + val);\n }\n out.close();\n }\n\n public static int cal(int min, int index, int n, int[] pos, String move) {\n //System.out.println(min + \" \" + index + \" \" + pos[min] + \" \" + move);\n if (min == move.length()) {\n return min;\n }\n if (index == pos[min]) {\n return min;\n }\n int result = min;\n if (move.charAt(min) == '0') {\n //System.out.println(\"Min \" + min);\n if (index + 1 < n) {\n if (pos[min + 1] != index || pos[min] != index + 1) {\n int val = cal(min + 1, index + 1, n, pos, move);\n result = Math.max(result, val);\n } else {\n result = Math.max(result, min + 1);\n }\n\n }\n if (index - 1 >= 0) {\n //System.out.println(\"PREV \" + index);\n if (pos[min + 1] != index || pos[min] != index - 1) {\n int val = cal(min + 1, index - 1, n, pos, move);\n result = Math.max(result, val);\n } else {\n result = Math.max(result, min + 1);\n }\n }\n int val = cal(min + 1, index, n, pos, move);\n result = Math.max(result, val);\n return result;\n } else {\n for (int i = 0; i < n; i++) {\n int val = cal(min + 1, i, n, pos, move);\n result = Math.max(result, val);\n }\n return result;\n }\n }\n\n public static Line getLine(Point a, Point b) {\n int c = (a.x - b.x);\n int d = (a.y - b.y);\n if (c == 0) {\n return new Line(1, 0, -a.x);\n } else if (d == 0) {\n return new Line(0, 1, -a.y);\n } else {\n double rate = (double) (-d) / c;\n\n double other = ((double) rate * a.x) + a.y;\n //System.out.println(a + \"|\" + b + \": \" + rate + \" \" + other);\n return new Line(rate, 1, -other);\n }\n }\n\n public static class Line {\n\n double a, b, c;\n\n public Line(double a, double b, double c) {\n this.a = a;\n this.b = b;\n this.c = c;\n }\n\n @Override\n public int hashCode() {\n int hash = 7;\n hash = 47 * hash + (int) (Double.doubleToLongBits(this.a) ^ (Double.doubleToLongBits(this.a) >>> 32));\n hash = 47 * hash + (int) (Double.doubleToLongBits(this.b) ^ (Double.doubleToLongBits(this.b) >>> 32));\n hash = 47 * hash + (int) (Double.doubleToLongBits(this.c) ^ (Double.doubleToLongBits(this.c) >>> 32));\n return hash;\n }\n\n @Override\n public boolean equals(Object obj) {\n if (obj == null) {\n return false;\n }\n if (getClass() != obj.getClass()) {\n return false;\n }\n final Line other = (Line) obj;\n if (Double.doubleToLongBits(this.a) != Double.doubleToLongBits(other.a)) {\n return false;\n }\n if (Double.doubleToLongBits(this.b) != Double.doubleToLongBits(other.b)) {\n return false;\n }\n if (Double.doubleToLongBits(this.c) != Double.doubleToLongBits(other.c)) {\n return false;\n }\n return true;\n }\n\n @Override\n public String toString() {\n return a + \" \" + b + \" \" + c;\n }\n }\n\n static class FT {\n\n int[] data;\n\n FT(int n) {\n data = new int[n];\n }\n\n void update(int index, int val) {\n // System.out.println(\"UPDATE INDEX \" + index);\n while (index < data.length) {\n data[index] += val;\n index += index & (-index);\n\n // System.out.println(\"NEXT \" +index);\n }\n }\n\n int get(int index) {\n // System.out.println(\"GET INDEX \" + index);\n int result = 0;\n while (index > 0) {\n result += data[index];\n index -= index & (-index);\n // System.out.println(\"BACK \" + index);\n }\n return result;\n }\n }\n\n public static double dist(Point a, Point b) {\n double val = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);\n return Math.sqrt(val);\n }\n\n public static class Point {\n\n int x, y;\n\n public Point(int x, int y) {\n this.x = x;\n this.y = y;\n }\n\n @Override\n public String toString() {\n return x + \" \" + y;\n }\n }\n\n public static boolean nextPer(int[] data) {\n int i = data.length - 1;\n while (i > 0 && data[i] < data[i - 1]) {\n i--;\n }\n if (i == 0) {\n return false;\n }\n int j = data.length - 1;\n while (data[j] < data[i - 1]) {\n j--;\n }\n int temp = data[i - 1];\n data[i - 1] = data[j];\n data[j] = temp;\n Arrays.sort(data, i, data.length);\n return true;\n }\n\n public static long pow(int a, int b) {\n if (b == 0) {\n return 1;\n }\n if (b == 1) {\n return a;\n }\n long val = pow(a, b / 2);\n if (b % 2 == 0) {\n return val * val;\n } else {\n return val * val * a;\n }\n }\n\n public static long gcd(long a, long b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n public static long lcm(long a, long b) {\n return a * b / gcd(a, b);\n }\n\n static class Scanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n public Scanner() throws FileNotFoundException {\n // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));\n br = new BufferedReader(new InputStreamReader(System.in));\n // br = new BufferedReader(new FileReader(new File(\"output.txt\")));\n }\n\n public String next() {\n\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n return st.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public String nextLine() {\n st = null;\n try {\n return br.readLine();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n\n public boolean endLine() {\n try {\n String next = br.readLine();\n while (next != null && next.trim().isEmpty()) {\n next = br.readLine();\n }\n if (next == null) {\n return true;\n }\n st = new StringTokenizer(next);\n return st.hasMoreTokens();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "99910aac8e3609840fc12a4a13fc7549", "src_uid": "2222ce16926fdc697384add731819f75", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class cf401d {\n\n\tstatic int[] digits;\n\tstatic long N;\n\tstatic int mod, len;\n\tstatic long[][] memo;\n\n\tpublic static long dp(int avail, int cmod) {\n\t\tif (avail == 0) {\n\t\t\treturn (cmod == 0) ? 1 : 0;\n\t\t}\n\t\tlong tot = 0;\n\n\t\t// test placing each new digit\n\t\tfor (int i = 0; i < len; i++) {\n\t\t\tint drep = 1 << i;\n\t\t\t// can we use this?\n\t\t\tif ((avail & drep) == drep) {\n\t\t\tint a = avail ^ drep;\n\t\t\tint b = (cmod * 10 + digits[i]) % mod);\n\t\t\tif( memo[a][b] == -1 )\n\t\t\t\tmemo[a][b] = dp(avail ^ drep, (cmod * 10 + digits[i]) % mod);\n\t\t\ttot += memo[a][b];\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn tot;\n\t}\n\n\tpublic static long fact(int i) {\n\t\tlong ret = 1;\n\t\tfor (int j = 2; j <= i; j++)\n\t\t\tret *= j;\n\t\treturn ret;\n\t}\n\n\tpublic static void main(String[] args) {\n\n\t\tScanner s = new Scanner(System.in);\n\n\t\tN = s.nextLong();\n\t\tmod = s.nextInt();\n\t\tString Nrep = \"\" + N;\n\t\tlen = Nrep.length();\n\t\tdigits = new int[len];\n\t\tfor (int i = 0; i < len; i++) {\n\t\t\tdigits[i] = Nrep.charAt(i) - '0';\n\t\t}\n\n\t\tint gg = (1 << len) - 1;\n\t\tmemo = new long[gg][mod];\n\t\tfor (long[] l : memo)\n\t\t\tArrays.fill(l, -1);\n\n\t\tlong tot = 0;\n\t\tfor (int i = 0; i < len; i++) {\n\t\t\tif (digits[i] != 0) {\n\t\t\t\ttot += dp(gg ^ (1 << i), digits[i] % mod);\n\t\t\t}\n\t\t}\n\n\t\tArrays.sort(digits);\n\t\tint count = 1;\n\t\tfor (int i = 1; i < len; i++) {\n\t\t\tif (digits[i] == digits[i - 1])\n\t\t\t\tcount++;\n\t\t\telse {\n\t\t\t\ttot /= fact(count);\n\t\t\t\tcount = 1;\n\t\t\t}\n\t\t}\n\n\t\ttot /= fact(count);\n\n\t\tSystem.out.println(tot);\n\t\ts.close();\n\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c4f23ca69da71d2853c5a32cf560f8d4", "src_uid": "5eb90c23ffa3794fdddc5670c0373829", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n\tstatic int[][] h;\n\tstatic int INF = (int) 2e9;\n\n\tstatic void getInput(Scanner sc, int n, int m) throws IOException {\n\t\tint[] g = new int[n * m + n];\n\t\tg[0] = sc.nextInt();\n\t\th = new int[n][m];\n\t\tint x = sc.nextInt(), y = sc.nextInt(), z = sc.nextInt();\n\t\tfor (int i = 1; i < g.length; i++) {\n\t\t\tg[i] = (int) ((g[i - 1] * 1L * x + y) % z);\n\t\t}\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\tfor (int j = 1; j <= m; j++) {\n\t\t\t\th[i - 1][j - 1] = g[(i - 1) * m + j - 1];\n\t\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint n = sc.nextInt(), m = sc.nextInt(), a = sc.nextInt(), b = sc.nextInt();\n\t\tgetInput(sc, n, m);\n\t\tlong ans = 0;\n\t\tSegmentTree2D tree = new SegmentTree2D(h);\n\t\tfor (int i = 0; i + a <= n; i++)\n\t\t\tfor (int j = 0; j + b <= m; j++)\n\t\t\t\tans += tree.query(i, i + a - 1, j, j + b - 1);\n\t\tout.println(ans);\n\t\tout.close();\n\n\t}\n\n\tstatic class SegmentTree2D {\n\t\tint n, m, min[][], a[][];\n\n\t\tSegmentTree2D(int[][] a) {\n\t\t\tthis.a = a;\n\t\t\tn = a.length;\n\t\t\tm = a[0].length;\n\t\t\tmin = new int[4 * n][4 * m];\n\t\t\tbuild_x(1, 0, n - 1);\n\t\t}\n\n\t\tvoid build_y(int vx, int lx, int rx, int vy, int ly, int ry) {\n\t\t\tif (ly == ry) {\n\t\t\t\tif (lx == rx)\n\t\t\t\t\tmin[vx][vy] = a[lx][ly];\n\t\t\t\telse\n\t\t\t\t\tmin[vx][vy] = Math.min(min[vx * 2][vy], min[vx * 2 + 1][vy]);\n\t\t\t} else {\n\t\t\t\tint my = (ly + ry) / 2;\n\t\t\t\tbuild_y(vx, lx, rx, vy * 2, ly, my);\n\t\t\t\tbuild_y(vx, lx, rx, vy * 2 + 1, my + 1, ry);\n\t\t\t\tmin[vx][vy] = Math.min(min[vx][vy * 2], min[vx][vy * 2 + 1]);\n\t\t\t}\n\t\t}\n\n\t\tvoid build_x(int vx, int lx, int rx) {\n\t\t\tif (lx != rx) {\n\t\t\t\tint mx = (lx + rx) / 2;\n\t\t\t\tbuild_x(vx * 2, lx, mx);\n\t\t\t\tbuild_x(vx * 2 + 1, mx + 1, rx);\n\t\t\t}\n\t\t\tbuild_y(vx, lx, rx, 1, 0, m - 1);\n\t\t}\n\n\t\tint query(int lN, int rN, int lM, int rM) {\n\t\t\treturn query(1, 0, n - 1, lN, rN, lM, rM);\n\t\t}\n\n\t\tint query(int node, int tl, int tr, int lN, int rN, int lM, int rM) {\n\t\t\tif (rN < tl || tr < lN)\n\t\t\t\treturn INF;\n\t\t\tif (tl >= lN && tr <= rN) {\n\t\t\t\treturn query(node, 1, 0, m - 1, lM, rM);\n\t\t\t}\n\t\t\tint mid = tl + tr >> 1, left = node << 1, right = left | 1;\n\t\t\treturn Math.min(query(left, tl, mid, lN, rN, lM, rM), query(right, mid + 1, tr, lN, rN, lM, rM));\n\n\t\t}\n\n\t\tint query(int nodeN, int node, int tl, int tr, int l, int r) {\n\t\t\tif (r < tl || tr < l)\n\t\t\t\treturn INF;\n\t\t\tif (tl >= l && tr <= r)\n\t\t\t\treturn min[nodeN][node];\n\t\t\tint mid = tl + tr >> 1, left = node << 1, right = left | 1;\n\t\t\treturn Math.min(query(nodeN, left, tl, mid, l, r), query(nodeN, right, mid + 1, tr, l, r));\n\t\t}\n\t}\n\n\tstatic class Scanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tScanner(String fileName) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(fileName));\n\t\t}\n\n\t\tString next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tString nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tint nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() throws NumberFormatException, IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() throws NumberFormatException, IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tboolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8aebe54ad624fdeeb71c058593a03bc3", "src_uid": "4618fbffb2b9d321a6d22c11590a4773", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.lang.Math.*;\nimport java.util.Scanner;\npublic class Painting\n{\n\tpublic static void main(String args[])\n\t{\n\t\tScanner sc=new Scanner(System.in);\n\t\tlong n = sc.nextLong();\t\t\n\t\tlong a = sc.nextLong();\t\n\t\tlong b = sc.nextLong();\n\t\tlong c = sc.nextLong();\n\t\tlong d = sc.nextLong();\n\n\t\tint x[] = new int[4] ;\n\t\t\t\n\t\tx[0] = a + b ;\n\t\tx[1] = a + c ;\n\t\tx[2] = b + d ;\n\t\tx[3] = c + d ;\n\n\t\tint max = x[0] ;\n\t\tint min = x[3] ;\n\t\tfor ( int i = 1 ; i < 4 ; i++ )\n\t\t{ \n\t\t\tif ( x[i] > max )\n\t\t\t{\n\t\t\t\tmax = x[i] ;\n\t\t\t}\n\t\t}\n\n\t\tfor ( int j = 2 ; j >= 0 ; j-- )\n\t\t{\n\t\t\tif ( x[j] < min )\n\t\t\t{\n\t\t\t\tmin = x[j] ;\n\t\t\t}\n\t\t}\n\n\t\tSystem.out.println( n * ( n - ( max - min ) ) );\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "19ebd75937ff42d23efa87b95dba65b5", "src_uid": "b732869015baf3dee5094c51a309e32c", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\n\npublic class CF_146B_LuckyMask {\n\tstatic int luckyDivision(int num){\n\t\tint resultt = 0 ;\n\t\tint mult = 1;\n\t\twhile(num>0){\n\t\tif(num%10==7||num%10==4){result+=num%10*mult;mult*=10; }\n\t\tnum=num/10;\n\t\t}\n\treturn resultt ;\t\n\t}\npublic static void main(String[]args)throws Exception{\nScanner sc = new Scanner(System.in);\nint a = sc.nextInt();\nint b = sc.nextInt();\nif(b>a){\n\tSystem.out.println(b);\n\treturn;\n}\n\nint result = a+1;\nwhile( luckyDivision(result)!=b){\n\tresult++;\n}\nSystem.out.println(result);\n}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b00608f52382c7c7a4fe963e6d8bd60d", "src_uid": "e5e4ea7a5bf785e059e10407b25d73fb", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.util.Scanner;\n\npublic class B {\n\n private static final String REGEX = \" \";\n private static final Boolean DEBUG = false;\n private static final String FILE_NAME = \"input.txt\";\n\n\n public static void main(String[] args) throws IOException {\n if (DEBUG) {\n generate();\n }\n Solver solver = new Solver();\n solver.readData();\n solver.solveAndPrint();\n }\n\n private static void generate() throws IOException {\n// FileWriter writer = new FileWriter(\"input.txt\");\n// writer.close();\n }\n\n private static class Solver {\n\n String[] field = new String[10];\n int curI, curJ;\n\n void readData() throws IOException {\n InputStream in = DEBUG ? new FileInputStream(FILE_NAME) : System.in;\n Scanner scanner = new Scanner(in);\n for (int i = 0; i < 10; i++) {\n field[i] = scanner.nextLine();\n }\n scanner.close();\n }\n\n void solveAndPrint() {\n char c;\n for (int i = 0; i < 10; i++) {\n String row = field[i];\n for (int j = 0; j < 10; j++) {\n c = row.charAt(j);\n if (c == '.') {\n curI = i;\n curJ = j;\n if (check(i, j)) {\n System.out.println(\"YES\");\n return;\n }\n }\n }\n }\n System.out.println(\"NO\");\n }\n\n private boolean check(int i, int j) {\n if (checkHor(i, j - 4) || checkHor(i, j - 3) || checkHor(i, j - 2) || checkHor(i, j - 1) || checkHor(i, j)) {\n return true;\n }\n if (checkVer(i - 4, j) || checkVer(i - 3, j) || checkVer(i - 2, j) || checkVer(i - 1, j) || checkVer(i, j)) {\n return true;\n }\n if (checkDia(i - 4, j - 4) || checkDia(i - 3, j - 3) || checkDia(i - 2, j - 2) || checkDia(i - 1, j - 1) || checkDia(i, j)) {\n return true;\n }\n return false;\n }\n\n private boolean checkHor(int i, int j) {\n int j1 = j;\n int i1 = i;\n for (int k = 0; k < 5; k++) {\n j1 = j + k;\n if (i1 < 0 || i1 >= 10 || j1 < 0 || j1 >= 10) {\n return false;\n }\n if (i1 == curI && j1 == curJ) {\n continue;\n }\n if (field[i1].charAt(j1) != 'X') {\n return false;\n }\n }\n return true;\n }\n\n private boolean checkVer(int i, int j) {\n int j1 = j;\n int i1 = i;\n for (int k = 0; k < 5; k++) {\n i1 = i + k;\n if (i1 < 0 || i1 >= 10 || j1 < 0 || j1 >= 10) {\n return false;\n }\n if (i1 == curI && j1 == curJ) {\n continue;\n }\n if (field[i1].charAt(j1) != 'X') {\n return false;\n }\n }\n return true;\n\n }\n\n private boolean checkDia(int i, int j) {\n int j1 = j;\n int i1 = i;\n for (int k = 0; k < 5; k++) {\n i1 = i + k;\n j1 = j + k;\n if (i1 < 0 || i1 >= 10 || j1 < 0 || j1 >= 10) {\n return false;\n }\n if (i1 == curI && j1 == curJ) {\n continue;\n }\n if (field[i1].charAt(j1) != 'X') {\n return false;\n }\n }\n return true;\n }\n\n\n @SuppressWarnings(\"SameParameterValue\")\n int[] splitInteger(String string, int n) {\n final String[] split = string.split(REGEX, n);\n int[] result = new int[split.length];\n for (int i = 0; i < n; ++i) {\n result[i] = Integer.parseInt(split[i]);\n }\n return result;\n }\n\n public int[] splitInteger(String string) {\n return splitInteger(string, 0);\n }\n\n\n @SuppressWarnings(\"SameParameterValue\")\n long[] splitLong(String string, int n) {\n final String[] split = string.split(REGEX, n);\n long[] result = new long[split.length];\n for (int i = 0; i < n; ++i) {\n result[i] = Long.parseLong(split[i]);\n }\n return result;\n }\n\n public long[] splitLong(String string) {\n return splitLong(string, 0);\n }\n\n @SuppressWarnings(\"SameParameterValue\")\n double[] splitDouble(String string, int n) {\n final String[] split = string.split(REGEX, n);\n double[] result = new double[split.length];\n for (int i = 0; i < n; ++i) {\n result[i] = Double.parseDouble(split[i]);\n }\n return result;\n }\n\n public double[] splitDouble(String string) {\n return splitDouble(string, 0);\n }\n\n @SuppressWarnings(\"SameParameterValue\")\n String[] splitString(String string, int n) {\n return string.split(REGEX, n);\n }\n\n public String[] splitString(String string) {\n return splitString(string, 0);\n }\n\n public int max(int a, int b) {\n return Math.max(a, b);\n }\n\n public long max(long a, long b) {\n return Math.max(a, b);\n }\n\n public int min(int a, int b) {\n return Math.min(a, b);\n }\n\n public long min(long a, long b) {\n return Math.min(a, b);\n }\n\n public double max(double a, double b) {\n return Math.max(a, b);\n }\n\n public double min(double a, double b) {\n return Math.min(a, b);\n }\n\n private final static int MOD = 1000000009;\n\n int multMod(int a, int b) {\n return ((a % MOD) * (b % MOD)) % MOD;\n }\n\n int sumMod(int a, int b) {\n return ((a % MOD) + (b % MOD)) % MOD;\n }\n\n long multMod(long a, long b) {\n return ((a % MOD) * (b % MOD)) % MOD;\n }\n\n long sumMod(long a, long b) {\n return ((a % MOD) + (b % MOD)) % MOD;\n }\n }\n\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a618eeb636967b5a464f54c03411ddd6", "src_uid": "d5541028a2753c758322c440bdbf9ec6", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class ctask{\n\tpublic static void main(String[] args) {\n\t\tScanner s = new Scanner(System.in);\n\t\tint[] px = new int[4];\n\t\tint[] py = new int[4];\n\n\t\tint[] ix = new int[4];\n\t\tint[] iy = new int[4];\n\n\t\tfor(int i = 0;i < 4;i++){\n\t\t\tpx[i] = s.nextInt();\n\t\t\tpy[i] = s.nextInt();\n\t\t}\n\n\t\tfor(int i = 0;i < 4;i++){\n\t\t\tix[i] = s.nextInt();\n\t\t\tiy[i] = s.nextInt();\n\t\t}\n\n\t\tArrays.sort(px);\n\t\tArrays.sort(py);\n\t\tint minx = px[0] , maxx = px[3];\n\t\tint miny = py[0] , maxy = py[3];\n\t\tint[] arrx = new int[106];\n\t\tint[] arry = new int[106];\n\n\t\tfor(int i = minx ; i <= maxx ;i++){\n\t\t\tarrx[i] = 1;\n\t\t}\n\n\t\tfor(int i = miny ; i <= maxy ;i++){\n\t\t\tarry[i] = 1;\n\t\t}\n\n\t\tArrays.sort(ix);\n\t\tArrays.sort(iy);\n\n\t\tint inxmin = ix[0] , inxmax = ix[3];\n\t\tint inymin = iy[0] , inymax = iy[3];\n\n\t\tint flag = 0;\n\t\tfor(int i = inxmin ;i <= inxmax ;i++){\n\t\t\tif(arrx[i] == 1){\n\t\t\t\tflag = 1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tfor(int i = inymin ;i <= inymax ;i++){\n\t\t\tif(arry[i] == 1){\n\t\t\t\tflag++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif(flag == 2)\n\t\t\tSystem.out.println(\"YES\");\n\t\telse\n\t\t\tSystem.out.println(\"NO\");\n\n\n\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9d4256d88610b6d820d6ee919e224b7d", "src_uid": "f6a3dd8b3bab58ff66055c61ddfdf06a", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class C{\n\t\n\tstatic int k1,k2,k3;\n\tstatic void MainMethod()throws Exception{\n\t\tk1=reader.nextInt();\n\t\tk2=reader.nextInt();\n\t\tk3=reader.nextInt();\n\t\tif (test()==true)printer.print(\"YES\");\n\t\telse printer.print(\"NO\");\n\t}\n\tstatic boolean test() {\n\t\tif (test2(k1,k2,k3)) return true;\n\t\tif (test2/(k1,k3,k2)) return true;\n\t\tif (test2(k2,k1,k3)) return true;\n\t\tif (test2(k2,k3,k1)) return true;\n\t\tif (test2(k3,k1,k2)) return true;\n\t\tif (test2(k3,k2,k1)) return true;\n\t\t\n\t\treturn false;\n\t}\n\tprivate static boolean test2(int a, int b, int c) {\n\t\tif (a==1) return true;\n\t\tif (a==2&&b==2) return true;\n\t\tif (c==3&&b==3&&a==3) return true;\n\t\t\n\t\treturn false;\n\t}\n\tpublic static void main(String[] args)throws Exception{\n\t\tMainMethod();\n\t\tprinter.close();\n\t}\n\tstatic void halt(){\n\t\tprinter.close();\n\t\tSystem.exit(0);\n\t}\n\tstatic PrintWriter printer=new PrintWriter(new OutputStreamWriter(System.out));\n\tstatic class reader{\n\t\tstatic BufferedReader bReader=new BufferedReader(new InputStreamReader(System.in));\n\t\tstatic StringTokenizer token=new StringTokenizer(\"\");\n\t\tstatic String readNextLine() throws Exception{\n\t\t\treturn bReader.readLine();\n\t\t}\n\t\tstatic String next() throws Exception{\n\t\t\twhile (token.hasMoreTokens()==false){\n\t\t\t\ttoken=new StringTokenizer(bReader.readLine());\n\t\t\t}\n\t\t\treturn token.nextToken();\n\t\t}\n\t\tstatic int nextInt()throws Exception{\n\t\t\twhile (token.hasMoreTokens()==false){\n\t\t\t\ttoken=new StringTokenizer(bReader.readLine());\n\t\t\t}\n\t\t\treturn Integer.parseInt(token.nextToken());\n\t\t}\n\t\tstatic long nextLong()throws Exception{\n\t\t\twhile (token.hasMoreTokens()==false){\n\t\t\t\ttoken=new StringTokenizer(bReader.readLine());\n\t\t\t}\n\t\t\treturn Long.parseLong(token.nextToken());\n\t\t}\n\t\tstatic double nextDouble()throws Exception{\n\t\t\twhile (token.hasMoreTokens()==false){\n\t\t\t\ttoken=new StringTokenizer(bReader.readLine());\n\t\t\t}\n\t\t\treturn Double.parseDouble(token.nextToken());\n\t\t}\n\t}\n\tstatic class MyMathCompute{\n\t\tstatic long [][] MatrixMultiplyMatrix(long [][] A, long [][] B, long mod) throws Exception{\n\t\t\tint n=A.length, m=B[0].length; \n\t\t\tint p=A[0].length;\n\t\t\tint i,j,k;\n\t\t\tif (B.length!=p) throw new Exception(\"invalid matrix input\");\n\t\t\tlong [][] res=new long [n][m];\n\t\t\tfor (i=0;i= b) {\n out.printf(\"%d/%d\", a, b);\n } else {\n int bestx = 0, besty = 0;\n double bestdiff = 1000000;\n for (int y = n; y > 0; y--) {\n int x = a*y/b;\n if (abs((double)(a * y - b * x)) < bestdiff) {\n bestdiff = abs((double)(a * y - b * x));\n bestx = x; besty = y;\n }\n }\n\n out.printf(\"%d/%d\", bestx, besty);\n }\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "46f890bda9b9fcc3cd9ffce93a945249", "src_uid": "827bc6f120aff6a6f04271bc84e863ee", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class RCCDiv2A {\n\n\tpublic static void main(String[] args) {\n\n\t\tScanner in = new Scanner(System.in);\n\n\t\tint cb = in.nextInt();\n int ca = in.nextInt();\n int na = in.nextInt();\n int nb = in.nextInt();\n int k = in.nextInt();\n\n nb -= k / na;\n k %= na;\n\n if (nb <= 0) {\n out.println(0);\n return;\n }\n System.out.println(Math.min(nb * cb, Math.min((na - k) * ca + (nb - 1) * cb, (na - k) * ca + (nb - 1) * na * ca)));\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4e08407483b54a1bb5f5fbd908925121", "src_uid": "c6ec932b852e0e8c30c822a226ef7bcb", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.util.Arrays;\n\npublic class Main {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int d = in.nextInt();\n int[] a = new int[n];\n for (int i = 0; i < n; i++)a[i] = in.nextInt();\n Arrays.sort(a);\n int m = in.nextInt();\n int ff = Math.min(n, m);\n int ans = 0;\n for (int i = 0; i < ff; i++)ans += a[i];\n if (m > ff)ans = ans - d * (m - ff);\n system.out.println(ans);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a6c33618c74afa0e97ea33b7158dcdf8", "src_uid": "5c21e2dd658825580522af525142397d", "difficulty": 1000.0} {"lang": "Java 11", "source_code": "import java.util.*;\r\nimport java.math.*;\r\n\r\npublic class Main{\r\n \r\n public static void main (String [] args){\r\n Scanner scan = new Scanner(System.in);\r\n long k = scan.nextLong();\r\n solve(k);\r\n }\r\n\r\n public static void solve (long k){\r\n BigInteger mod = BigInteger.valueOf(1000000007);\r\n long nodes = (long)Math.pow(2, k)-2;\r\n BigInteger nodess = BigInteger.valueOf(nodes);\r\n BigInteger four = new BigInteger(\"4\");\r\n BigInteger result = four.modPow(nodess,mod);\r\n result = result.multiply(BigInteger.valueOf(6));\r\n result = result.mod(mod);\r\n System.out.println(result;\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "005d8703f406106f024c119b94751150", "src_uid": "5144b9b281ea4087d8334d91c3c8bda4", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class LuckyTickets {\n\n // 2^23*7*17+1\n private static final int MOD = 998244353;\n\n //highest power of 2 that is a factor of MOD-1\n private static final int twoPow = 23;\n\n // any number such that ROOT^(2^twoPow)=1 & ROOT^(2^(twoPow-1))!=1\n private static final int ROOT = 15311432;\n\n // flip first k bits\n private static int bitReverse(int n, int k) {\n return Integer.reverse(n) >>> (32 - k);\n }\n\n private static long modPow(long a, long p) {\n if (p == 0) {\n return 1;\n }\n long half = modPow(a, p / 2);\n long ans = (half * half) % MOD;\n if (p % 2 == 1) {\n ans = (ans * a) % MOD;\n }\n return ans;\n }\n\n private static long modInv(long a) {\n return modPow(a, MOD - 2);\n }\n\n /**\n * calculate roots of unity for ntt\n */\n private static long[] calcRoots(int k, boolean inverse) {\n long root = modPow(ROOT, modPow(2, twoPow - k));\n if (inverse) {\n root = modInv(root);\n }\n long[] roots = new long[k];\n roots[k - 1] = root;\n for (int i = k - 1; i > 0; i--) {\n roots[i - 1] = (roots[i] * roots[i]) % MOD;\n }\n return roots;\n }\n\n /**\n * Change the indicies of an array, putting them into bit-reverse order.\n * array should have length 2^k\n */\n private static long[] reorderArray(long[] a, int k) {\n long[] ans = new long[a.length];\n for (int i = 0; i < a.length; i++) {\n ans[bitReverse(i, k)] = a[i];\n }\n return ans;\n }\n\n /**\n * coef.length = 2^k\n * Note: When computing the inverse, this function will return 2^k times the\n * correct answer. Please divide as needed.\n */\n private static long[] numberTheoreticTransform(long[] coef, int k, boolean inverse) {\n coef = reorderArray(coef, k);\n long[] roots = calcRoots(k, inverse);\n for (int s = 0; s < k; s++) {\n int len = 1 << s;\n for (int st = 0; st < coef.length; st += 2 * len) {\n // combine the vectors starting at st and st + len\n long curRoot = 1;\n for (int j = st; j < st + len; j++) {\n long t = (curRoot * coef[j + len]) % MOD;\n long u = coef[j];\n coef[j] = (u + t) % MOD;\n coef[j + len] = (u - t) % MOD;\n curRoot = (roots[s] * curRoot) % MOD;\n }\n }\n }\n return coef;\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt() / 2;\n int m = sc.nextInt();\n int[] nums = new int[m];\n int max = 0;\n for (int i = 0; i < m; i++) {\n nums[i] = sc.nextInt();\n max = Math.max(max, nums[i]);\n }\n int min_size = n * max + 1;\n int k = 0;\n int size = 1;\n while (size < min_size) {\n size *= 2;\n k++;\n }\n long[] a = new long[size];\n for (int i = 0; i < nums.length; i++) {\n a[nums[i]] = 1;\n }\n a = numberTheoreticTransform(a, k, false);\n for (int i = 0; i < size; i++) {\n a[i] = modPow(a[i], n);\n }\n a = numberTheoreticTransform(a, k, true);\n long ans = 0;\n for (int i = 0; i < size; i++) {\n ans = (ans + a[i] * a[i]) % MOD;\n }\n long multiplier = modInv(size);\n System.out.println((((ans * multiplier) % MOD) * multiplier) % MOD);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c4bb0de286b298e86d330237975cd1ab", "src_uid": "279f1f7d250a4be6406c6c7bfc818bbf", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "public class Main{\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n String s = in.next();\n String[] a = s.split(\"0\");\n int c=0;\n for (int i = 0; i < s.length(); i++) {\n \n if (s.charAt(i)=='1') {\n c++;\n }else{\n System.out.print(c);\n c=0;\n }\n \n }System.out.print(c);\n \n \n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "aac055508c1bf55296615ff8009e7a20", "src_uid": "a4b3da4cb9b6a7ed0a33a862e940cafa", "difficulty": 1100.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.Map.Entry;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\npublic class Solution {\n //\n\n private static StringTokenizer st;\n private static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n\n private static long nextLong() {\n return Long.parseLong(st.nextToken());\n }\n\n private static int nextInt() {\n return Integer.parseInt(st.nextToken());\n }\n\n private static double nextDouble() {\n return Double.parseDouble(st.nextToken());\n }\n\n private static short nextShort() {\n return Short.parseShort(st.nextToken());\n }\n\n private static byte nextByte() {\n return Byte.parseByte(st.nextToken());\n }\n\n private static void initTokenizer() throws Exception {\n st = new StringTokenizer(reader.readLine());\n }\n\n //\n\n private static class TeamComparator implements Comparator {\n @Override\n public int compare (Team a, Team b) {\n int c = a.points - b.points;\n if (c != 0) return c;\n\n c = a.goalsDone - a.goalsLost - (b.goalsDone - b.goalsLost);\n if (c != 0) return c;\n\n c = a.goalsDone - b.goalsDone;\n if (c != 0) return c;\n\n return b.country.compareTo(a.country);\n }\n }\n\n private static class Team {\n private int points;\n private int goalsDone;\n private int goalsLost;\n private String country;\n private int games;\n\n public Team (String country) {\n this.country = country;\n points = 0;\n goalsDone = 0;\n goalsLost = 0;\n games = 0;\n }\n }\n\n private static class CountComparator implements Comparator {\n @Override\n public int compare (Count a, Count b) {\n int c = a.win - a.los - (b.win - b.los);\n if (c != 0) return c;\n\n return a.los - b.los;\n }\n\n }\n\n private static class Count {\n private int win;\n private int los;\n\n public Count (int win, int los) {\n this.win = win;\n this.los = los;\n }\n\n\n }\n\n private final static TeamComparator comparator = new TeamComparator() {\n\n @Override\n public int compare (Team a, Team b) {\n return -super.compare(a, b);\n }\n };\n\n private final static CountComparator countcomparator = new CountComparator();\n\n private static HashMap teamsMap;\n\n public static void main(String[] args) throws Exception {\n teamsMap = new HashMap<>();\n\n for (int i = 0; i < 5; i++) {\n st = new StringTokenizer(reader.readLine(), \": \");\n\n String team1 = st.nextToken();\n String team2 = st.nextToken();\n\n int g1 = nextInt();\n int g2 = nextInt();\n\n Team t1 = teamsMap.get(team1);\n if (t1 == null) {\n t1 = new Team(team1);\n teamsMap.put(team1, t1);\n }\n\n Team t2 = teamsMap.get(team2);\n if (t2 == null) {\n t2 = new Team(team2);\n teamsMap.put(team2, t2);\n }\n\n t1.goalsDone += g1;\n t1.goalsLost += g2;\n\n t2.goalsDone += g2;\n t2.goalsLost += g1;\n\n if (g1 == g2) {\n t1.points++;\n t2.points++;\n }\n else if (g1 > g2) {\n t1.points += 3;\n }\n else {\n t2.points += 3;\n }\n\n t1.games++;\n t2.games++;\n }\n\n Team berland = teamsMap.get(\"BERLAND\");\n\n Team other = null;\n\n for (Entry e : teamsMap.entrySet()) {\n if (!e.getKey().equals(\"BERLAND\") && e.getValue().games == 2) {\n other = e.getValue();\n break;\n }\n }\n\n berland.points += 3;\n\n ArrayList list = new ArrayList<>(6);\n\n for (Team t : teamsMap.values()) {\n list.add(t);\n }\n\n int bgd = berland.goalsDone;\n int bgl = berland.goalsLost;\n\n int ogd = other.goalsDone;\n int ogl = other.goalsLost;\n\n ArrayList count = new ArrayList<>(1000);\n\n for (int i = 1; i <= 1000; i++) {\n berland.goalsDone = bgd + i;\n other.goalsLost = ogl + i;\n\n for (int j = i - 1; j >= 0; j--) {\n berland.goalsLost = bgl + j;\n other.goalsDone = ogd + j;\n\n Collections.sort(list, comparator);\n\n if (list.get(0).country.equals(\"BERLAND\") || list.get(1).country.equals(\"BERLAND\")) {\n count.add(new Count(i, j));\n }\n }\n }\n\n Collections.sort(count, countcomparator);\n\n System.out.print(count.size() == 0 ? \"IMPOSSIBLE\" : (count.get(0).win + \" \" + count.get(0).los));\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "759eb73b7c4d87c65d6720956f1e6034", "src_uid": "5033d51c67b7ae0b1a2d9fd292fdced1", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class TheGreatJulyaCalendar_331C1 {\n\n public static void main(String[] args) {\n\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n num = (int)n/10;\n int ans = n < 10 ? 0 : num * 2 + 1;\n System.out.println(ans);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ce2dddb62ef3fc82cf09210296206758", "src_uid": "fc5765b9bd18dc7555fa76e91530c036", "difficulty": 1100.0} {"lang": "Java 7", "source_code": "package trunghieu11;\n\nimport myStream.InputReader;\nimport myStream.OutputWriter;\n\npublic class TaskC {\n private static final long MOD = 1000000007;\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int rowCount = in.readInt();\n int columCount = in.readInt();\n int stepCount = in.readInt();\n if (rowCount == 1 || columCount == 1){\n out.printLine(0);\n return;\n }\n\n long[][] count = new long[stepCount + 1][Math.max(rowCount, columCount) + 1];\n for (int i = 0; i < count[1].length; i++){\n count[1][i] = i * (i + 1) / 2;\n }\n for (int i = 2; i <= stepCount; i++){\n long sum = 0;\n long result = 0;\n for (int j = 2; j < count[i].length; j++) {\n sum += count[i - 1][j - 2];\n result += sum;\n result %= MOD;\n count[i][j] = result;\n }\n }\n long answer = count[stepCount][rowCount - 2] * count[stepCount][columCount - 2] % MOD;\n out.printLine(answer);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b04b7dfa12a3595a47ddc7851d43f7c7", "src_uid": "309d2d46086d526d160292717dfef308", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.Map;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\npublic class Main {\n\n\t@SuppressWarnings(\"resource\")\n\tpublic static void main(String[] args) {\n\t\tInputStream input;\n\t\tOutputStream output;\n\t\ttry {\n\t\t\tinput = new FileInputStream(\"input.txt\");\n\t\t\toutput = new FileOutputStream(\"output.txt\");\n\t\t} catch (FileNotFoundException e) {\n\t\t\tinput = System.in;\n\t\t\toutput = System.out;\n\t\t}\n\t\tKattio io = new Kattio(input, output);\n\t\t(new Solve(io)).main();\n\t\tio.close();\n\n\t\tif (input instanceof FileInputStream)\n\t\t\ttry {\n\t\t\t\tinput.close();\n\t\t\t} catch (IOException e) {\n\t\t\t}\n\t\tif (output instanceof FileOutputStream)\n\t\t\ttry {\n\t\t\t\toutput.close();\n\t\t\t} catch (IOException e) {\n\t\t\t}\n\t}\n\n}\n\nclass Solve {\n\tstatic final long mod = (long) 1e9+7;\n\tKattio io;\n\tint n;\n\tint[] a;\n\tlong[][][] dp;\n\tint maxx;\n\t\n\tlong[] fac;\n\t\n\tSolve(Kattio io) {\n\t\tthis.io = io;\n\t}\n\t\n\tlong pow(long x,long y)\n\t{\n\t\tif (y==0) return 1;\n\t\telse\n\t\t{\n\t\t\tlong p=pow(x,y/2);\n\t\t\tp=p*p%mod;\n\t\t\tif (y%2==1) return p*x%mod;\n\t\t\telse return p;\n\t\t}\n\t}\n\t\n\tlong nCk(int n,int k)\n\t{\n\t\treturn fac[n]*pow(fac[k]*fac[n-k]%mod,mod-2)%mod;\n\t}\n\n\tlong caldp(int x,int y,int z)\n\t{\n\t\tif (dp[x][y][z]!=-1) return dp[x][y][z];\n\t\t\n\t\tif (x==n && z==0 && y==0)\n\t\t\tdp[x][y][z]=1;\n\t\telse\n\t\tif (x==n)\n\t\t\tdp[x][y][z]=0;\n\t\telse\n\t\t{\n\t\t\tdp[x][y][z]=caldp(x+1,y,z);\n\t\t\tif (z>=a[x+1] && y>=1) dp[x][y][z]=(dp[x][y][z]+caldp(x+1,y-1,z-a[x+1]))%mod;\n\t\t}\n\t\t\n\t\treturn dp[x][y][z];\n\t}\n\t\n\tvoid main() \n\t{\n\t\tn=io.getInt();\n\t\ta = new int[n+1];\n\t\t\n\t\tmaxx = 0;\n\t\tTreeMap S = new TreeMap();\n\t\t\n\t\tfor (int i=1; i<=n; i++)\n\t\t{\n\t\t\ta[i]=io.getInt();\n\t\t\tmaxx+=a[i];\n\t\t\tif (S.containsKey(a[i]))\n\t\t\t\tS.put(a[i], S.get(a[i])+1);\n\t\t\telse\n\t\t\t\tS.put(a[i], 1);\n\t\t}\n\t\t\n\t\tif (S.size()==2)\n\t\t{\n\t\t\tio.print(n);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tdp = new long[n+1][n+1][maxx+1];\n\t\tfor (int i=0; i<=n; i++)\n\t\t\tfor (int j=0; j<=n; j++)\n\t\t\t\tArrays.fill(dp[i][j],-1);\n\t\t\n\t\tfac = new long[n+1];\n\t\tfac[0]= 1;\n\t\tfor (int i=1; i<=n; i++)\n\t\t\tfac[i] = fac[i-1]*i%mod;\n\t\t\n\t\t\n\t\t\n\t\tint res=0;\n\t\tfor (Map.Entry entry: S.entrySet())\n\t\t{\n\t\t\tInteger value = entry.getValue();\n\t\t\tInteger key = entry.getKey();\n\t\t\tfor (int i=res+1; i<=value; i++)\n\t\t\t\tif (caldp(0,i,key*i)==nCk(value,i))\n\t\t\t\t\tres=Math.max(res, i);\n\t\t}\n\t\t\n\t\tio.println(res);\n\t\t\t\n\t}\n}\n\n/** Simple yet moderately fast I/O routines.\n*\n* Example usage:\n*\n* Kattio io = new Kattio(System.in, System.out);\n*\n* while (io.hasMoreTokens()) {\n* int n = io.getInt();\n* double d = io.getDouble();\n* double ans = d*n;\n*\n* io.println(\"Answer: \" + ans);\n* }\n*\n* io.close();\n*\n*\n* Some notes:\n*\n* - When done, you should always do io.close() or io.flush() on the\n* Kattio-instance, otherwise, you may lose output.\n*\n* - The getInt(), getDouble(), and getLong() methods will throw an\n* exception if there is no more data in the input, so it is generally\n* a good idea to use hasMoreTokens() to check for end-of-file.\n*\n* @author: Kattis\n*/\nclass Kattio extends PrintWriter {\n\tpublic Kattio(InputStream i) {\n\t\tsuper(new BufferedOutputStream(System.out));\n\t\tr = new BufferedReader(new InputStreamReader(i));\n\t}\n\n\tpublic Kattio(InputStream i, OutputStream o) {\n\t\tsuper(new BufferedOutputStream(o));\n\t\tr = new BufferedReader(new InputStreamReader(i));\n\t}\n\n\tpublic boolean hasMoreTokens() {\n\t\treturn peekToken() != null;\n\t}\n\n\tpublic int getInt() {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tpublic double getDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tpublic long getLong() {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tpublic String getWord() {\n\t\treturn nextToken();\n\t}\n\n\tprivate BufferedReader r;\n\tprivate String line;\n\tprivate StringTokenizer st;\n\tprivate String token;\n\n\tprivate String peekToken() {\n\t\tif (token == null)\n\t\t\ttry {\n\t\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\t\tline = r.readLine();\n\t\t\t\t\tif (line == null)\n\t\t\t\t\t\treturn null;\n\t\t\t\t\tst = new StringTokenizer(line);\n\t\t\t\t}\n\t\t\t\ttoken = st.nextToken();\n\t\t\t} catch (IOException e) {\n\t\t\t}\n\t\treturn token;\n\t}\n\n\tprivate String nextToken() {\n\t\tString ans = peekToken();\n\t\ttoken = null;\n\t\treturn ans;\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "80fcbd9b864e12b65407926f1e9b1a0c", "src_uid": "ccc4b27889598266e8efe73b8aa3666c", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "public class CodeForces1 {\n\n public static void main(String[] args) {\n Scanner p = new Scanner(System.in);\n int n = p.nextInt();\n \n int count = 0;\n \n while (n > 9) {\n n++;\n while (n%10 == 0) {\n n/=10;\n }\n count++;\n }\n count+=9;\n \n System.out.println(\"result: \" + count);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8c32bce5afef333dc34c5f6232626d88", "src_uid": "055fbbde4b9ffd4473e6e716da6da899", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class x{\n \n public static void main(String args[]){\n Scanner sc=new Scanner(System.in);\n \n int n=sc.nextInt();\n \n while(n-->0){\n int t=sc.nextInt();\n int f=1,s=2,lt=3;\n \n if(t==lt){\n System.out.println(\"NO\");\n break;\n }\n else if(t==f){\n swap(s,lt);\n }\n else if(t==s){\n swap(f,lt);\n }\n }\n }\n \n public static swap(int a,int b){\n int te=a;\n a=b;\n b=te;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "257ae04aad08f8b1b85b1a1bf60126cb", "src_uid": "6c7ab07abdf157c24be92f49fd1d8d87", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Declined {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint k = sc.nextInt();\n\t\tint[] r = new int[k];\n\t\tfor(int i = 0; i < k; i++) {\n\t\t\tr[i] = sc.nextInt();\n\t\t}\n\t\tArrays.sort(r);\n\t\tSystem.out.println(r[k - 1] > 25 ? r[k - 1] - 25 ? 0);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5c7cfbfab1adbbfccf7d0a1f4f2580f9", "src_uid": "ef657588b4f2fe8b2ff5f8edc0ab8afd", "difficulty": 800.0} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n \n//Sub_To_Errichto\npublic class Main {\n //static final long MOD = 1000000007L;\n //static final long MOD = 998244353L;\n static final int INF = 50000000;\n static final int NINF = -500000000;\n \n public static void main(String[] args) {\n FastScanner sc = new FastScanner();\n PrintWriter pw = new PrintWriter(System.out);\n \n long[] A = new long[] {sc.nl(),sc.nl()};\n long[] B = new long[] {sc.nl(),sc.nl()};\n long[] C = new long[] {sc.nl(),sc.nl()};\n long[][] vals = new long[][] {{A[0],A[1]},{A[1],-A[0]},{-A[0],-A[1]},{-A[1],A[0]}};\n String ans = \"NO\";\n for (long[] v: vals) {\n \tlong X = B[0]-v[0];\n \tlong Y = B[1]-v[1];\n \tlong num = C[1]*X-C[0]*Y;\n \tlong den = C[1]*C[1]+C[0]*C[0];\n \tif ((num==0&&den==0)||(den!=0 && num%den==0)) {\n \t\tlong other = (den==0 ? 0 : num/den);\n \t\tlong sub = X-C[1]*other;\n \t\tif (sub%C[0]==0) {\n \t\t\tans = \"YES\";\n \t\t\tbreak;\n \t\t}\n \t}\n }\n pw.println(ans);\n pw.close();\n }\n \n //Find the GCD of two numbers\n public static long gcd(long a, long b) {\n \tif (a < b) return gcd(b,a);\n \tif (b == 0)\n \t\treturn a;\n \telse\n \t\treturn gcd(b,a%b);\n }\n \n static class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n \n public FastScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n \n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n int ni() {\n return Integer.parseInt(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", "compilation_error": false, "code_uid": "110f371f6b5f5c943f337762790315b5", "src_uid": "cc8a8af1ba2b19bf081e379139542883", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.*;\n/**\n *\n *\n *\n * @author \n * @version 1.00 2016/9/19\n */\n\npublic class RobotSequence {\n \n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n \tScanner kbd = new Scanner(System.in);\n \tint n = Integer.parseInt(kbd.nextLine());\n \tString s = kbd.nextLine().toUpperCase();\n \t\tint x = 0;\n \t\tint y = 0;\n \t\tint count = 0;\n \t\n \tfor( int i = 0; i < n; i++){\n \t\tswitch (s.charAt(i)){\n \t\t\tcase 'U':y++;break;\n \t\t\tcase 'D':y--;break;\n \t\t\tcase 'R':y++;break;\n \t\t\tcase 'L':y++;break;\n \t\t\tif (y == 0 && x == 0){\n \t\t\tcount++;\n \t\t}\n \t\t} \n \t\t\n\t\t \t\t\n \t}\n System.out.println(count);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "546fa26b5bccebe1a8bd96a732555030", "src_uid": "7bd5521531950e2de9a7b0904353184d", "difficulty": 1000.0} {"lang": "Java 11", "source_code": "import java.io.*;\r\nimport java.util.*;\r\nimport java.lang.Math;\r\n\r\npublic class DMCA {\r\n\tpublic static void main(String args[]) throws Exception {\r\n\t\tBufferedReader in = new BufferedReader (new InputStreamReader(System.in));\r\n\t\tint n = Integer.parseInt(in.readLine());\r\n\t\tint res = Math.pow(n, 0.5);\r\n\t\tSystem.out.println(res);\r\n\t}\r\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d38329ebe3bc34e127f20c36c7a6a75d", "src_uid": "477a67877367dc68b3bf5143120ff45d", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.util.concurrent.ForkJoinTask;\nimport java.util.concurrent.RecursiveAction;\nimport java.util.concurrent.RecursiveTask;\nimport java.util.concurrent.atomic.AtomicInteger;\nimport java.io.*;\nimport java.lang.reflect.Field;\nimport java.lang.reflect.Method;\nimport java.math.*;\n\nimport javax.swing.plaf.SliderUI;\n\nimport static java.lang.Math.*;\n\npublic class Solution implements Runnable {\n\t\n\tpublic void solve() throws Exception {\n\t\tString a = sc.nextToken();\n\t\tString b = sc.nextToken();\n\t\tint scoreA = 0;\n\t\tint scoreB = 0;\n\t\tfor (int i = 0; i < a.length(); i += 2) {\n\t\t\tString first = a.substring(i, i + 2);\n\t\t\tString second = b.substring(i, i + 2);\n\t\t\tswitch (first) {\n\t\t\t\tcase \"[]\": {\n\t\t\t\t\tif (second.equals(\"8<\"))\n\t\t\t\t\t\tscoreB++;\n\t\t\t\t\tif (second.equals(\"()\"))\n\t\t\t\t\t\tscoreA++;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"()\": {\n\t\t\t\t\tif (second.equals(\"8<\"))\n\t\t\t\t\t\tscoreA++;\n\t\t\t\t\tif (second.equals(\"[]\"))\n\t\t\t\t\t\tscoreB++;\n\t\t\t\t\t\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"8<\": {\n\t\t\t\t\tif (second.equals(\"[]\"))\n\t\t\t\t\t\tscoreA++;\n\t\t\t\t\tif (second.equals(\"()\"))\n\t\t\t\t\t\tscoreB++;\n\t\t\t\t\t\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (scoreA > scoreB) {\n\t\t\tout.println(\"TEAM 1 WINS\");\n\t\t} else if (scoreB > scoreA) {\n\t\t\tout.println(\"TEAM 2 WINS\");\n\t\t} else {\n\t\t\tout.println(\"TIE\");\n\t\t}\n\t}\n\n\n\tstatic Throwable t;\n\n\tBufferedReader in;\n\tFastScanner sc;\n\tPrintWriter out;\n\n\t@Override\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsc = new FastScanner(in);\n\t\t\tsolve();\n\t\t} catch (Throwable t) {\n\t\t\tSolution.t = t;\n\t\t} finally {\n\t\t\tout.close();\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws Throwable {\n\t\tThread thread = new Thread(null, new Solution(), \"\", 1 << 26);\n\t\tthread.start();\n\t\tthread.join();\n\t\tif (Solution.t != null)\n\t\t\tthrow t;\n\t}\n\n}\n\nclass FastScanner {\n\n\tBufferedReader in;\n\tStringTokenizer st;\n\n\tpublic FastScanner(BufferedReader in) {\n\t\tthis.in = in;\n\t}\n\n\tpublic String nextToken() throws Exception {\n\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\treturn st.nextToken();\n\t}\n\n\tpublic int nextInt() throws Exception {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tpublic long nextLong() throws Exception {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tpublic double nextDouble() throws Exception {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n}\n\ninterface ISingleton {\n\t\n\tpublic void doSomething();\n\t\n}\n\nclass SingletonInjection {\n\t\n\tpublic static void inject(Class singletonClass, Object injection) throws Exception {\n\t\tField field = singletonClass.getDeclaredField(\"instance\");\n\t\tfield.setAccessible(true);\n\t\tfield.set(singletonClass, injection);\n\t}\n\t\n}\n\nclass MockSingleton implements ISingleton {\n\t\n\t@Override\n\tpublic void doSomething() {\n\t\t// TODO Auto-generated method stub\n\t\t\n\t}\n\t\n}\n\nclass Singleton implements ISingleton {\n\t\n\tprivate static ISingleton instance;\n\t\n\tpublic static ISingleton getInstance() {\n\t\t// create business singleton;\n\t\treturn instance;\n\t}\n\t\n\t@Override\n\tpublic void doSomething() {\n\t\t// TODO Auto-generated method stub\t\n\t}\n\t\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7e2feda6352425ac58b3851f076caca0", "src_uid": "bdf2e78c47d078b4ba61741b6fbb23cf", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class C82{\n\n\tpublic static void main(String args[]){\n\t\tFastReader sc = new FastReader();\n int n,m,c0,d0,i,j,k;\n n=sc.nextInt();\n m=sc.nextInt();\n c0=sc.nextInt();\n d0=sc.nextInt();\n int a[]=new int[m];\n int b[]=new int[m];\n int c[]=new int[m];\n int d[]=new int[m];\n for(i=0;i=0)\n dp[i][j]=Math.max(dp[i][j],dp[i-k*c[j]][j-1]+k*d[j]);\n }\n }\n }\n dp[0][m-1]=(n/c0)*d0;\n for(i=1;i<=n;i++)\n dp[i][m-1]=Math.max(dp[i-1][m-1],dp[i][m-1]+((n-i)/c0)*d0);\n out.println(dp[n][m-1]);\n\t\tout.flush();\n\t}\n\n\tstatic PrintWriter out;\n\tstatic class FastReader{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FastReader(){\n\t\t\tbr=new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout=new PrintWriter(System.out,true);\n\t\t}\n\t\tString next(){\n\t\t\twhile(st==null || !st.hasMoreElements()){\n\t\t\t\ttry{\n\t\t\t\t\tst= new StringTokenizer(br.readLine());\n\t\t\t\t}\n\t\t\t\tcatch (IOException e){\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tint nextInt(){\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tlong nextLong(){\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\tdouble nextDouble(){\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\tString nextLine(){\n\t\t\tString str = \"\";\n\t\t\ttry{\n\t\t\t\tstr=br.readLine();\n\t\t\t}\n\t\t\tcatch(IOException e){\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\t}\n\n\tpublic static boolean isPrime(int n) {\n\t\tif(n<2) return false;\n\t\tfor(int i=2;i<=(int)Math.sqrt(n);i++) {\n\t\t\tif(n%i==0) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tpublic static void print(int a[],int l,int r){\n\t\tint i;\n\t\tfor(i=l;i<=r;i++)\n\t\t\tout.print(a[i]+\" \");\n\t\tout.println();\n\t}\n\n\tpublic static long fastexpo(long x, long y, long p){\n\t\tlong res=1;\n\t\twhile(y > 0){\n\t\t\tif((y & 1)==1)\n\t\t\t\tres= ((res%p)*(x%p))%p;\n\t\t\ty= y >> 1;\t\t\t\n\t\t\tx = ((x%p)*(x%p))%p;\n\t\t}\n\t\treturn res;\n\t}\n\n\tpublic static boolean[] sieve (int n) {\n\t\tboolean primes[]=new boolean[n+1];\n\t\tArrays.fill(primes,true);\n\t\tprimes[0]=primes[1]=false;\n\t\tfor(int i=2;i*i<=n;i++){\n\t\t\tif(primes[i]){\n\t\t\t\tfor(int j=i*i;j<=n;j+=i)\n\t\t\t\t\tprimes[j]=false;\n\t\t\t}\n\t\t}\n\t\treturn primes;\n\t}\n\n\tpublic static long gcd(long a,long b){\n return (BigInteger.valueOf(a).gcd(BigInteger.valueOf(b))).longValue();\n }\n\n public static void merge(int a[],int l,int m,int r){\n int n1,n2,i,j,k;\n n1=m-l+1;\n n2=r-m;\n\n int L[]=new int[n1];\n int R[]=new int[n2];\n\n for(i=0;i=maxX)\n {\n maxOX=maxX; \n maxX=x[i];\n }\n if(y[i]>=maxY)\n {\n maxOY=maxY;\n maxY=y[i];\n }\n }\n }\n int l=Math.min(maxOX, maxOY);\n for (int i = 0; i < 4*n+1; i++) {\n if(x[i]!=l&&y[i]!=l&&x[i]!=0&&y[i]!=0)\n {\n System.out.println(x[i]+\" \"+y[i]);\n break;\n }\n else if(x[i]>l||y[i]>l)\n {\n System.out.println(x[i]+\" \"+y[i]);\n break;\n }\n }\n }\n \n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "17fe3c1b2fe5ee0834509e45890d1fc7", "src_uid": "1f9153088dcba9383b1a2dbe592e4d06", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.*;\r\nimport java.util.*;\r\n\r\n\r\nimport java.math.*;\r\nimport java.math.BigInteger;\r\n\r\n\r\npublic final class A\r\n{ \r\n\tstatic PrintWriter out = new PrintWriter(System.out); \r\n\tstatic StringBuilder ans=new StringBuilder();\r\n\tstatic FastReader in=new FastReader();\r\n\tstatic ArrayList g[];\r\n\tstatic long mod=(long)998244353,INF=Long.MAX_VALUE;\r\n\t//\tstatic boolean set[]; \r\n\tstatic int par[],partial[];\r\n\tstatic int Days[],P[][];\r\n\tstatic int sum=0,size[];\r\n\tstatic int seg[],col[];\r\n\t//\tstatic ArrayList A;\r\n\tstatic char X[][];\r\n\tstatic boolean set[][];\r\n\tstatic int D[],min[],A[];\r\n\tstatic long dp[][];\r\n\t//\tstatic HashSet visited,imposters;\r\n\t//\tstatic HashSet set;\r\n\t//\tstatic node1 seg[];\r\n\t//static pair moves[]= {new pair(-1,0),new pair(1,0), new pair(0,-1), new pair(0,1)};\r\n\tpublic static void main(String args[])throws IOException\r\n\t{\t\r\n\t\t/*\r\n\t\t * star,rope,TPST\r\n\t\t * BS,LST\r\n\t\t */\t\t\r\n\t\tlong x=l(),y=l();\r\n\t\tif(x==y)\r\n\t\t{\r\n\t\t\tSystem.out.println(\"YES\");\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tString X=binary(x),Y=binary(y); //max length is 60\r\n\t\tif(f(X,Y))\r\n\t\t{\r\n\t\t\tSystem.out.println(\"YES\");\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tlong t=2L;\r\n\t\twhile(x%t==0)x/=t; \r\n\t\tX=binary(x);\r\n\t\tif(f(X,Y))\r\n\t\t{\r\n\t\t\tSystem.out.println(\"YES\");\r\n\t\t\treturn;\r\n\t\t}\t\t\r\n\t\tX=reverse(X);\r\n\t\tif(f(X,Y))System.out.println(\"YES\");\r\n\t\telse\r\n\t\t\tSystem.out.println(\"NO\");\r\n//\t\tSystem.out.println(f(\"1101\",\"1101\"));\r\n\t\tout.println(ans);\r\n\t\tout.close();\r\n\t}\r\n\tstatic boolean f(String A,String B)\r\n\t{\r\n\t\tchar X[]=A.toCharArray(),Y[]=B.toCharArray();\r\n for(int i=0; i<=Y.length-X.length; i++)\r\n {\r\n \tboolean f=true;\r\n \tfor(int j=0; j \"+x.ch+\" \"+t);\r\n\t\t\t\t\treturn true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(cnt==0)return true;\r\n\t\treturn false;\r\n\t}\r\n\tstatic boolean f(Trie root)\r\n\t{\r\n\t\tif(root==null)return false;\t\t\r\n\t\t//\t\tint cnt=0;\r\n\t\tfor(Trie x:root.A)\r\n\t\t{\r\n\t\t\tif(x!=null)\r\n\t\t\t{\r\n\t\t\t\t//\t\t\t\tcnt++;\r\n\t\t\t\tif(!f(x))\r\n\t\t\t\t{\r\n\r\n\t\t\t\t\treturn true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\t\r\n\t\treturn false;\r\n\t}\r\n\tstatic void insert(String X,Trie head)\r\n\t{\r\n\t\tTrie root=head;\r\n\t\tfor(char x:X.toCharArray())\r\n\t\t{\r\n\t\t\tint a=x-'a';\r\n\t\t\tif(root.A[a]==null)root.A[a]=new Trie();\r\n\t\t\troot=root.A[a];\r\n\t\t\troot.ch=x;\r\n\t\t}\r\n\t\troot.ends=true; \r\n\t}\r\n\tstatic boolean search(String X,Trie head)\r\n\t{\r\n\t\tTrie root=head;\r\n\t\tfor(char x:X.toCharArray()) {\r\n\t\t\tint a=x-'a';\r\n\t\t\tif(root.A[a]==null)return false;\r\n\t\t\troot=root.A[a];\r\n\t\t}\r\n\t\treturn root.ends;\r\n\r\n\t}\r\n\tstatic boolean starts_with(String X,Trie head)\r\n\t{\r\n\t\tTrie root=head;\r\n\t\tfor(char x:X.toCharArray()) {\r\n\t\t\tint a=x-'a';\r\n\t\t\tif(root.A[a]==null)return false;\r\n\t\t\troot=root.A[a];\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\tstatic int lower(ArrayListA,int i)\r\n\t{\r\n\t\tint l=-1,r=A.size();\r\n\t\twhile(r-l>1)\r\n\t\t{\r\n\t\t\tint m=(l+r)/2;\r\n\t\t\tif(A.get(m)>i)r=m;\r\n\t\t\telse l=m;\r\n\t\t}\t\t\r\n\t\treturn r;\r\n\t}\r\n\tstatic int upper(ArrayListA,int i)\r\n\t{\r\n\t\tint l=-1,r=A.size();\r\n\t\twhile(r-l>1)\r\n\t\t{\r\n\t\t\tint m=(l+r)/2;\r\n\t\t\tif(A.get(m)0)X.append(\"0\");\r\n\t\treturn X.toString();\r\n\t}\r\n\tstatic long f(int i,int g,int x,int left)\r\n\t{\r\n\t\tif(x<=1)return left;\r\n\t\tif(i<0 || g==1)return left;\r\n\t\t//\t\tSystem.out.println(i+\" \"+g);\r\n\t\tif(dp[i][g]==0)\r\n\t\t{\r\n\t\t\tint next=min[i];\r\n\t\t\tint new_gcd=(int)GCD(g,x);\r\n\t\t\t//System.out.println(\" factor--> \"+x+\" gcd--> \"+g+\" new--> \"+new_gcd);\r\n\t\t\tlong s=0;\r\n\t\t\tint c=0;\r\n\t\t\tfor(int j=next+1; j<=i; j++)\r\n\t\t\t{\r\n\t\t\t\tif(A[i]%new_gcd==0)\r\n\t\t\t\t{\r\n\t\t\t\t\ts+=new_gcd;\r\n\t\t\t\t\tc--;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tlong a=0,b=0;\r\n\t\t\ta=f(i,g,x-1,left);\r\n\t\t\tb=s+f(next,new_gcd,x-1,left-c);\r\n\t\t\tdp[i][g]=Math.max(a, b);\r\n\t\t}\r\n\t\treturn dp[i][g];\r\n\t}\r\n\tstatic boolean f(int A[],int B[],int x)\r\n\t{\r\n\t\tint c=0;\r\n\t\tint N=A.length;\r\n\t\tint l=0,r=x-1;\r\n\t\tfor(int i=0; i=r && B[i]>=l)\r\n\t\t\t{\r\n\t\t\t\tr--;\r\n\t\t\t\tl++;\r\n\t\t\t\tc++;\t\t\t\t\r\n\t\t\t}\r\n\t\t\tif(c>=x)return true;\r\n\t\t}\r\n\t\treturn false;\r\n\t}\r\n\tstatic boolean isPalindrome(int A[])\r\n\t{\r\n\t\tint i=0,j=A.length-1;\r\n\t\twhile(i A,int x)\r\n\t{\r\n\t\tint l=-1,r=A.size();\r\n\t\twhile(r-l>1)\r\n\t\t{\r\n\t\t\tint m=(l+r)/2;\r\n\t\t\tif(A.get(m)1)\r\n\t\t{\r\n\t\t\tint m=(l+r)/2;\r\n\t\t\tif(A[m]<=a)l=m;\r\n\t\t\telse r=m;\r\n\t\t}\r\n\t\treturn A[l];\r\n\t}\r\n\tstatic void build(int v,int tl,int tr,int A[])\r\n\t{\r\n\t\tif(tl==tr)\r\n\t\t{\r\n\t\t\tseg[v]=A[tl];\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tint tm=(tl+tr)/2;\r\n\t\tbuild(v*2,tl,tm,A);\r\n\t\tbuild(v*2+1,tm+1,tr,A);\r\n\t\tseg[v]=Math.min(seg[v*2], seg[v*2+1]);\r\n\t}\r\n\tstatic void update(int v,int tl,int tr,int index,int x)\r\n\t{\r\n\t\tif(tl==tr && tl==index)\r\n\t\t{\r\n\t\t\tseg[v]=x;\r\n\t\t\treturn;\r\n\t\t}\t\t\r\n\t\tint tm=(tl+tr)/2;\r\n\t\tif(index<=tm)update(v*2,tl,tm,index,x);\r\n\t\telse update(v*2+1,tm+1,tr,index,x);\r\n\t\tseg[v]=Math.min(seg[v*2], seg[v*2+1]);\r\n\t}\r\n\tstatic int ask(int v,int tl,int tr,int l,int r)\r\n\t{\r\n\t\t//\t\tSystem.out.println(v);\r\n\t\t//\t\tif(v>100)return 0;\r\n\t\tif(l>r)return Integer.MAX_VALUE;\r\n\t\tif(tl==l && tr==r)return seg[v];\r\n\t\tint tm=(tl+tr)/2;\r\n\t\tint a=ask(v*2,tl,tm,l,Math.min(tm, r));\r\n\t\t//\t\tSystem.out.println(\"for--> \"+(v)+\" tm--> \"+(tm+1)+\" tr--> \"+tr+\" l--> \"+Math.max(l, tm+1)+\" r--> \"+r);\r\n\t\tint b=ask(v*2+1,tm+1,tr,Math.max(l, tm+1),r);\r\n\t\treturn Math.min(a, b);\r\n\t}\r\n\tstatic int find(int a)\r\n\t{\r\n\t\tif(par[a]<0)return a;\r\n\t\treturn par[a]=find(par[a]);\r\n\t}\r\n\tstatic void union(int a,int b)\r\n\t{\r\n\t\ta=find(a);\r\n\t\tb=find(b);\r\n\t\tif(a!=b)\r\n\t\t{\r\n\t\t\tpar[a]+=par[b];\r\n\t\t\tpar[b]=a;\r\n\t\t}\r\n\t}\r\n\tstatic int ask(int a,int b)\r\n\t{\r\n\t\tSystem.out.println(\"? \"+a+\" \"+b);\r\n\t\treturn i();\r\n\t}\r\n\r\n\r\n\r\n\r\n\tstatic long and(int i,int j)\r\n\t{\r\n\t\tSystem.out.println(\"and \"+i+\" \"+j);\r\n\t\treturn l();\r\n\t}\r\n\tstatic long or(int i,int j)\r\n\t{\r\n\t\tSystem.out.println(\"or \"+i+\" \"+j);\r\n\t\treturn l();\r\n\t}\r\n\tstatic boolean is_Sorted(int A[])\r\n\t{\r\n\t\tint N=A.length;\r\n\t\tfor(int i=1; i<=N; i++)if(A[i-1]!=i)return false;\r\n\t\treturn true;\r\n\t}\r\n\tstatic boolean f(StringBuilder sb,String Y,String order)\r\n\t{\r\n\t\tStringBuilder res=new StringBuilder(sb.toString());\r\n\t\tHashSet set=new HashSet<>();\r\n\t\tfor(char ch:order.toCharArray())\r\n\t\t{\r\n\t\t\tset.add(ch);\r\n\t\t\tfor(int i=0; i0)\r\n\t\t{\r\n\t\t\tx*=10;\r\n\t\t\tx+=a;\r\n\t\t}\r\n\t\treturn x;\r\n\t}\r\n\tstatic int count(String X)\r\n\t{\r\n\t\tHashSet set=new HashSet<>();\r\n\t\tfor(char x:X.toCharArray())set.add(x-'0');\r\n\t\treturn set.size();\r\n\t}\r\n\r\n\r\n\t//\tstatic void build(int v,int tl,int tr,long A[])\r\n\t//\t{\r\n\t//\t\tif(tl==tr)\r\n\t//\t\t{\r\n\t//\t\t\tseg[v]=A[tl];\r\n\t//\t\t}\r\n\t//\t\telse\r\n\t//\t\t{\r\n\t//\t\t\tint tm=(tl+tr)/2;\r\n\t//\t\t\tbuild(v*2,tl,tm,A);\r\n\t//\t\t\tbuild(v*2+1,tm+1,tr,A);\r\n\t//\t\t\tseg[v]=Math.min(seg[v*2], seg[v*2+1]);\r\n\t//\t\t}\r\n\t//\t}\r\n\r\n\tstatic int [] sub(int A[],int B[])\r\n\t{\r\n\t\tint N=A.length;\r\n\t\tint f[]=new int[N];\r\n\t\tfor(int i=N-1; i>=0; i--)\r\n\t\t{\r\n\t\t\tif(B[i] Hash(int A[])\r\n\t{\r\n\t\tHashMap mp=new HashMap<>();\r\n\t\tfor(int a:A)\r\n\t\t{\r\n\t\t\tint f=mp.getOrDefault(a,0)+1;\r\n\t\t\tmp.put(a, f);\r\n\t\t}\r\n\t\treturn mp;\r\n\t}\r\n\tstatic long mul(long a, long b)\r\n\t{\r\n\t\treturn ( a %mod * 1L * b%mod )%mod;\r\n\t}\r\n\tstatic void swap(int A[],int a,int b)\r\n\t{\r\n\t\tint t=A[a];\r\n\t\tA[a]=A[b];\r\n\t\tA[b]=t;\r\n\t}\r\n\r\n\r\n\r\n\tstatic boolean isSorted(int A[])\r\n\t{\r\n\t\tfor(int i=1; i high) \r\n\t\t\tif (x >= A[high]) \r\n\t\t\t\treturn A[high]; \r\n\r\n\t\tint mid = (low + high) / 2; \r\n\r\n\t\tif (A[mid] == x) \r\n\t\t\treturn A[mid]; \r\n\r\n\t\tif (mid > 0 && A[mid - 1] <= x && x < A[mid]) \r\n\t\t\treturn A[mid - 1]; \r\n\r\n\t\tif (x < A[mid]) \r\n\t\t\treturn lower_Bound( A, low, mid - 1, x); \r\n\r\n\t\treturn lower_Bound(A, mid + 1, high, x); \r\n\t} \r\n\r\n\tstatic String f(String A)\r\n\t{\r\n\t\tString X=\"\";\r\n\t\tfor(int i=A.length()-1; i>=0; i--)\r\n\t\t{\r\n\t\t\tint c=A.charAt(i)-'0';\r\n\t\t\tX+=(c+1)%2;\r\n\t\t}\r\n\t\treturn X;\r\n\t}\r\n\r\n\tstatic void sort(long[] a) //check for long\r\n\t{\r\n\t\tArrayList l=new ArrayList<>();\r\n\t\tfor (long i:a) l.add(i);\r\n\t\tCollections.sort(l);\r\n\t\tfor (int i=0; i();\t\t\r\n\t\t\tDays[i]=-1;\r\n\t\t\tD[i]=Integer.MAX_VALUE;\r\n\t\t\t//D2[i]=INF;\r\n\t\t}\r\n\t}\r\n\r\n\r\n\r\n\tstatic long pow(long a,long b)\r\n\t{\r\n\t\tlong pow=1;\r\n\t\tlong x=a;\r\n\t\twhile(b!=0)\r\n\t\t{\r\n\t\t\tif((b&1)!=0)pow=(pow*x)%mod;\r\n\t\t\tx=(x*x)%mod;\r\n\t\t\tb/=2;\r\n\t\t}\r\n\t\treturn pow;\r\n\t}\r\n\r\n\tstatic long toggleBits(long x)//one's complement || Toggle bits\r\n\t{\r\n\t\tint n=(int)(Math.floor(Math.log(x)/Math.log(2)))+1;\r\n\r\n\t\treturn ((1< l=new ArrayList<>();\r\n\t\tfor (int i:a) l.add(i);\r\n\t\tCollections.sort(l);\r\n\t\tfor (int i=0; i A)\r\n\t{\r\n\t\tfor(int a:A)System.out.print(a+\" \");\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\tstatic int i()\r\n\t{\r\n\t\treturn in.nextInt();\r\n\t}\r\n\r\n\tstatic long l()\r\n\t{\r\n\t\treturn in.nextLong();\r\n\t}\r\n\r\n\tstatic int[] input(int N){\r\n\t\tint A[]=new int[N];\r\n\t\tfor(int i=0; i\r\n{\r\n\tint a, index;\r\n\tpair1(int b,int i)\r\n\t{\r\n\t\ta=b;\r\n\t\tindex=i;\r\n\t}\r\n\tpublic int compareTo(pair1 x)\r\n\t{\r\n\t\treturn x.a-this.a;\r\n\t}\r\n}\r\n\r\n//Code For FastReader\r\n//Code For FastReader\r\n//Code For FastReader\r\n//Code For FastReader\r\nclass FastReader\r\n{\r\n\tBufferedReader br;\r\n\tStringTokenizer st;\r\n\tpublic FastReader()\r\n\t{\r\n\t\tbr=new BufferedReader(new InputStreamReader(System.in));\r\n\t}\r\n\r\n\tString next()\r\n\t{\r\n\t\twhile(st==null || !st.hasMoreElements())\r\n\t\t{\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\tst=new StringTokenizer(br.readLine());\r\n\t\t\t}\r\n\t\t\tcatch(IOException e)\r\n\t\t\t{\r\n\t\t\t\te.printStackTrace();\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn st.nextToken();\r\n\t}\r\n\r\n\tint nextInt()\r\n\t{\r\n\t\treturn Integer.parseInt(next());\r\n\t}\r\n\r\n\tlong nextLong()\r\n\t{\r\n\t\treturn Long.parseLong(next());\r\n\t}\r\n\r\n\tdouble nextDouble()\r\n\t{\r\n\t\treturn Double.parseDouble(next());\r\n\t}\r\n\r\n\tString nextLine()\r\n\t{\r\n\t\tString str=\"\";\r\n\t\ttry\r\n\t\t{\r\n\t\t\tstr=br.readLine();\r\n\t\t}\r\n\t\tcatch (IOException e)\r\n\t\t{\r\n\t\t\te.printStackTrace();\r\n\t\t}\r\n\t\treturn str;\r\n\t}\r\n\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5ae2a81a59c8b14fd617fa81e897c62f", "src_uid": "9f39a3c160087beb0efab2e3cb510e89", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n/**\n * @author Pavel Mavrin\n */\npublic class E {\n\n private static final int MOD = (int) (1e9+7);\n public static final int N = 7;\n public static final int NN = 128;\n\n private void solve() throws IOException {\n int[] w = new int[N];\n for (int i = 0; i < N; i++) {\n w[i] = nextInt();\n }\n int[] start = new int[2];\n start[1] = 1;\n int[] a = start;\n for (int h = 0; h < N; h++) if (w[h] > 0) {\n int nn = (1 << (h + 1));\n {\n int[] aa = new int[nn];\n for (int i = 0; i < a.length; i++) {\n aa[i - a.length + nn] = a[i];\n }\n a = aa;\n }\n int[][] q = new int[nn][];\n int[] t = new int[nn];\n for (int i = 0; i < nn; i++) {\n t[i] = 1;\n q[i] = add(t, h + 1);\n t[i] = 0;\n }\n q = pow(q, w[h]);\n int[] aa = new int[nn];\n for (int i = 0; i < nn; i++) {\n for (int j = 0; j < nn; j++) {\n aa[j] = (int) ((aa[j] + 1l * a[i] * q[i][j]) % MOD);\n }\n }\n a = aa;\n }\n out.println(a[a.length - 1]);\n }\n\n private int[][] pow(int[][] a, int b) {\n int n = a.length;\n if (b == 0) {\n int[][] res = new int[n][n];\n for (int i = 0; i < n; i++) {\n res[i][i] = 1;\n }\n return res;\n }\n if (b % 2 == 0) {\n int[][] aa = mult(a, a);\n return pow(aa, b / 2);\n } else {\n int[][] aa = pow(a, b - 1);\n return mult(aa, a);\n }\n }\n\n private int[][] mult(int[][] a, int[][] b) {\n int n = a.length;\n int[][] c = new int[n][n];\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n for (int k = 0; k < n; k++) {\n c[i][k] = (int) ((c[i][k] + 1l * a[i][j] * b[j][k]) % MOD);\n }\n }\n }\n return c;\n }\n\n private int[] add(int[] a, int n) {\n int nn = (1 << (n + 1));\n int[][] d = new int[n + 1][nn];\n for (int i = 0; i < nn / 2; i++) {\n d[0][(i << 1) + 1] = a[i + a.length - (1 << n)];\n }\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < nn; j++) if (d[i][j] > 0) {\n int q = (j >> i) & 3;\n for (int k = 0; k < 4; k++) {\n if (q == 3 && k == 3) continue;\n int jj = (j - (q << i) + (k << i));\n d[i + 1][jj] += d[i][j];\n while (d[i + 1][jj] >= MOD) {\n d[i + 1][jj] -= MOD;\n }\n }\n }\n }\n int[] res = new int[a.length];\n for (int i = 0; i < (1 << n); i++) {\n res[i + a.length - (1 << n)] = d[n][i + (1 << n)];\n }\n return res;\n }\n\n\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer st;\n PrintWriter out = new PrintWriter(System.out);\n\n String next() throws IOException {\n while (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(br.readLine());\n }\n return st.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public static void main(String[] args) throws IOException {\n new E().run();\n }\n\n private void run() throws IOException {\n solve();\n out.close();\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "118c7d4619b3d8f3ba016ddf709a676a", "src_uid": "a4bda63b95dc14185c47a08652fe41bd", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\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\tTaskD solver = new TaskD();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskD {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int x1 = in.nextInt(), x2 = in.nextInt(), a = in.nextInt(), b = in.nextInt();\n boolean flag = false;\n if (x1 > x2) {\n int aux = x1;\n x1 = x2;\n x2 = aux;\n aux = -a;\n a = -b;\n b = aux;\n flag = true;\n }\n\n if (b <= 0) {\n out.println(\"DRAW\");\n return;\n }\n if (b >= x2 - x1 && x2 - x1 >= a) {\n out.println(\"FIRST\\n\" + (flag ? x1: x2));\n return;\n }\n if (a <= 0) {\n out.println(\"DRAW\");\n return;\n }\n if ((x2 - x1) % (a + b) == 0) {\n out.println(\"SECOND\");\n return;\n }\n if (a <= (x2 - x1) % (a + b) && (x2 - x1) % (a + b) <= b) {\n out.println(\"FIRST\\n\" + (flag ? x2 - (x2 - x1) % (a + b): x1 + (x2 - x1) % (a + b)));\n return;\n }\n out.println(\"DRAW\");\n }\n}\n\nclass InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public String next() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuffer res = new StringBuffer();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n\n return res.toString();\n }\n\n private boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ecbca9ef11ee7969f7e7901c7e115496", "src_uid": "4ea8cc3305a0ee2c1e580b43e5bc46c6", "difficulty": 2400.0} {"lang": "Java 6", "source_code": "import java.util.ArrayList;\nimport java.util.Scanner;\n\n\npublic class Main {\n public static void main(String[] args) {\n Scanner r = new Scanner(System.in);\n \n int N = r.nextInt();\n int[] a = new int[N];\n int sum = 0;\n for(int i = 0; i < N; i++){\n a[i] = r.nextInt();\n sum += a[i];\n }\n \n ArrayList res = new ArrayList();\n for(int i = 0; i < N; i++)\n if(a[i] *(N - 1) == (sum - a[i]))res.add(i+1);\n \n System.out.println(res.size());\n for(int i : res)\n System.out.println(i);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "adb7e2aba28bc5f9eece650b8eb434a5", "src_uid": "75739f77378b21c331b46b1427226fa1", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.UncheckedIOException;\nimport java.io.Closeable;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, new TaskAdapter(), \"\", 1 << 27);\n thread.start();\n thread.join();\n }\n\n static class TaskAdapter implements Runnable {\n @Override\n public void run() {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastInput in = new FastInput(inputStream);\n FastOutput out = new FastOutput(outputStream);\n EKuroAndTopologicalParity solver = new EKuroAndTopologicalParity();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class EKuroAndTopologicalParity {\n public void solve(int testNumber, FastInput in, FastOutput out) {\n int n = in.readInt();\n int p = in.readInt();\n int[] c = new int[n + 1];\n for (int i = 1; i <= n; i++) {\n c[i] = in.readInt();\n }\n\n Modular mod = new Modular(1e9 + 7);\n Composite comp = new Composite(n, mod);\n CachedPow pow = new CachedPow(2, mod);\n int[] pow2 = new int[n + 1];\n int[] compEven = new int[n + 1];\n int[] compOdd = new int[n + 1];\n for (int i = 0; i <= n; i++) {\n for (int j = 0; j <= n; j += 2) {\n compEven[i] = mod.plus(compEven[i], comp.composite(i, j));\n }\n }\n for (int i = 0; i <= n; i++) {\n for (int j = 1; j <= n; j += 2) {\n compOdd[i] = mod.plus(compOdd[i], comp.composite(i, j));\n }\n }\n for (int i = 0; i <= n; i++) {\n pow2[i] = pow.pow(i);\n }\n\n int[][][][] last = new int[n + 1][n + 1][n + 1][2];\n int[][][][] next = new int[n + 1][n + 1][n + 1][2];\n\n last[0][0][0][0] = 1;\n for (int i = 1; i <= n; i++) {\n for (int j = 0; j <= n; j++) {\n for (int k = 0; k <= n; k++) {\n for (int t = j; t + k <= i; t++) {\n for (int parity = 0; parity < 2; parity++) {\n next[j][k][t][parity] = 0;\n if (c[i] != 1 && t > 0) {\n //it's 0 now\n\n //pick even and it's odd\n if (j > 0) {\n next[j][k][t][parity] = mod.plus(next[j][k][t][parity],\n mod.mul(mod.mul(last[j - 1][k][t - 1][1 - parity], compEven[k]), pow2[i - t - k]));\n }\n\n //pick odd and it's even\n next[j][k][t][parity] = mod.plus(next[j][k][t][parity],\n mod.mul(mod.mul(last[j][k][t - 1][parity], compOdd[k]), pow2[i - t - k]));\n }\n if (c[i] != 0) {\n //it's 1 now\n\n //pick even and it's odd\n if (k > 0) {\n next[j][k][t][parity] = mod.plus(next[j][k][t][parity],\n mod.mul(mod.mul(last[j][k - 1][t][1 - parity], compEven[j]), pow2[t - j]));\n }\n\n //pick odd and it's even\n next[j][k][t][parity] = mod.plus(next[j][k][t][parity],\n mod.mul(mod.mul(last[j][k][t][parity], compOdd[j]), pow2[t - j]));\n }\n }\n }\n }\n }\n\n int[][][][] tmp = last;\n last = next;\n next = tmp;\n }\n\n int ans = 0;\n for (int i = 0; i <= n; i++) {\n for (int j = 0; j <= n; j++) {\n for (int k = 0; k <= n; k++) {\n int cnt = last[i][j][k][p];\n cnt = mod.mul(cnt, pow.pow(comp.composite(k, 2)));\n cnt = mod.mul(cnt, pow.pow(comp.composite(n - k, 2)));\n ans = mod.plus(ans, cnt);\n }\n }\n }\n\n out.println(ans);\n }\n\n }\n\n static class DigitUtils {\n private DigitUtils() {\n }\n\n public static long round(double x) {\n if (x >= 0) {\n return (long) (x + 0.5);\n } else {\n return (long) (x - 0.5);\n }\n }\n\n }\n\n static class Composite {\n final Factorial factorial;\n final Modular modular;\n\n public Composite(Factorial factorial) {\n this.factorial = factorial;\n this.modular = factorial.getModular();\n }\n\n public Composite(int limit, Modular modular) {\n this(new Factorial(limit, modular));\n }\n\n public int composite(int m, int n) {\n if (n > m) {\n return 0;\n }\n return modular.mul(modular.mul(factorial.fact(m), factorial.invFact(n)), factorial.invFact(m - n));\n }\n\n }\n\n static class FastInput {\n private final InputStream is;\n private byte[] buf = new byte[1 << 13];\n private int bufLen;\n private int bufOffset;\n private int next;\n\n public FastInput(InputStream is) {\n this.is = is;\n }\n\n private int read() {\n while (bufLen == bufOffset) {\n bufOffset = 0;\n try {\n bufLen = is.read(buf);\n } catch (IOException e) {\n bufLen = -1;\n }\n if (bufLen == -1) {\n return -1;\n }\n }\n return buf[bufOffset++];\n }\n\n public void skipBlank() {\n while (next >= 0 && next <= 32) {\n next = read();\n }\n }\n\n public int readInt() {\n int sign = 1;\n\n skipBlank();\n if (next == '+' || next == '-') {\n sign = next == '+' ? 1 : -1;\n next = read();\n }\n\n int val = 0;\n if (sign == 1) {\n while (next >= '0' && next <= '9') {\n val = val * 10 + next - '0';\n next = read();\n }\n } else {\n while (next >= '0' && next <= '9') {\n val = val * 10 - next + '0';\n next = read();\n }\n }\n\n return val;\n }\n\n }\n\n static class FastOutput implements AutoCloseable, Closeable {\n private StringBuilder cache = new StringBuilder(10 << 20);\n private final Writer os;\n\n public FastOutput(Writer os) {\n this.os = os;\n }\n\n public FastOutput(OutputStream os) {\n this(new OutputStreamWriter(os));\n }\n\n public FastOutput println(int c) {\n cache.append(c).append('\\n');\n return this;\n }\n\n public FastOutput flush() {\n try {\n os.append(cache);\n os.flush();\n cache.setLength(0);\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n return this;\n }\n\n public void close() {\n flush();\n try {\n os.close();\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n public String toString() {\n return cache.toString();\n }\n\n }\n\n static class Modular {\n int m;\n\n public int getMod() {\n return m;\n }\n\n public Modular(int m) {\n this.m = m;\n }\n\n public Modular(long m) {\n this.m = (int) m;\n if (this.m != m) {\n throw new IllegalArgumentException();\n }\n }\n\n public Modular(double m) {\n this.m = (int) m;\n if (this.m != m) {\n throw new IllegalArgumentException();\n }\n }\n\n public int valueOf(int x) {\n x %= m;\n if (x < 0) {\n x += m;\n }\n return x;\n }\n\n public int valueOf(long x) {\n x %= m;\n if (x < 0) {\n x += m;\n }\n return (int) x;\n }\n\n public int mul(int x, int y) {\n return valueOf((long) x * y);\n }\n\n public int plus(int x, int y) {\n return valueOf(x + y);\n }\n\n public Modular getModularForPowerComputation() {\n return new Modular(m - 1);\n }\n\n public String toString() {\n return \"mod \" + m;\n }\n\n }\n\n static class InverseNumber {\n int[] inv;\n\n public InverseNumber(int[] inv, int limit, Modular modular) {\n this.inv = inv;\n inv[1] = 1;\n int p = modular.getMod();\n for (int i = 2; i <= limit; i++) {\n int k = p / i;\n int r = p % i;\n inv[i] = modular.mul(-k, inv[r]);\n }\n }\n\n public InverseNumber(int limit, Modular modular) {\n this(new int[limit + 1], limit, modular);\n }\n\n }\n\n static class CachedPow {\n private int[] first;\n private int[] second;\n private Modular mod;\n private Modular powMod;\n\n public CachedPow(int x, Modular mod) {\n this(x, mod.getMod(), mod);\n }\n\n public CachedPow(int x, int maxExp, Modular mod) {\n this.mod = mod;\n this.powMod = mod.getModularForPowerComputation();\n int k = Math.max(1, (int) DigitUtils.round(Math.sqrt(maxExp)));\n first = new int[k];\n second = new int[maxExp / k + 1];\n first[0] = 1;\n for (int i = 1; i < k; i++) {\n first[i] = mod.mul(x, first[i - 1]);\n }\n second[0] = 1;\n int step = mod.mul(x, first[k - 1]);\n for (int i = 1; i < second.length; i++) {\n second[i] = mod.mul(second[i - 1], step);\n }\n }\n\n public int pow(int exp) {\n return mod.mul(first[exp % first.length], second[exp / first.length]);\n }\n\n }\n\n static class Factorial {\n int[] fact;\n int[] inv;\n Modular modular;\n\n public Modular getModular() {\n return modular;\n }\n\n public Factorial(int[] fact, int[] inv, InverseNumber in, int limit, Modular modular) {\n this.modular = modular;\n this.fact = fact;\n this.inv = inv;\n fact[0] = inv[0] = 1;\n for (int i = 1; i <= limit; i++) {\n fact[i] = modular.mul(fact[i - 1], i);\n inv[i] = modular.mul(inv[i - 1], in.inv[i]);\n }\n }\n\n public Factorial(int limit, Modular modular) {\n this(new int[limit + 1], new int[limit + 1], new InverseNumber(limit, modular), limit, modular);\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\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4dfc467a3b7fa454ba247afc6ea57989", "src_uid": "aaf5f8afa71d9d25ebab405dddec78cd", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "package com.mangusttank;\n\n//\u0417\u0430\u0434\u0430\u0447\u0430: \u0412\u0437\u043b\u043e\u043c \u043a\u043e\u0434\u0430\n//http://codeforces.com/problemset/problem/630/L\n\nimport java.math.BigInteger;\nimport java.util.Scanner;\nimport java.lang.String;\n\npublic class Main {\n\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n String in_str = input.nextLine();\n\n String str = String.valueOf(in_str.charAt(0)) + String.valueOf(in_str.charAt(2))\n + String.valueOf(in_str.charAt(4)) + String.valueOf(in_str.charAt(3)) + String.valueOf(in_str.charAt(1));\n\n BigInteger num = BigInteger.valueOf(0).add(new BigInteger(str).pow(5));\n str = new StringBuffer( new StringBuffer(num.toString()).reverse().toString().substring(0,5)).reverse().toString();\n\n System.out.println(str);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "153b3d6197392e9babada3a410c74014", "src_uid": "51b1c216948663fff721c28d131bf18f", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class Solution{\n\n\n\tpublic static void main(String args[]){\n\n\t\tScanner in=new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n\n\t\tint q=in.nextInt();\n\n\t\twhile(q--!=0){\n\n\t\t\tlong a=in.nextLong(),\n\t\t\t\t b=in.nextLong(),\n\t\t\t\t m=in.nextLong();\n\n\t\t\tif(b item=new ArrayList<>();\n\t\t\titem.add(a);\n\n\t\t\tlong power=0;\n\n\t\t\twhile(true){\n\n\t\t\t\tlong curr=(1<=b || curr+(1<=b)\n\t\t\t\t\tbreak;\n\n\t\t\t\tpower+=1;\n\t\t\t}\n\t\t\tint n=item.size();\n\n\t\t\tif((b-item.get(n-1))/(1< freq=new ArrayList<>();\n\t\t\tArrayList mul=new ArrayList<>();\n\n\t\t\tfor(long i=power; i>=1L; i--){\n\t\t\t\tfreq.add(1L<<(i-1));\n\t\t\t\tmul.add((b-item.get(n-1))/(1< max) max = sum; return;}\n\t\tif (isPrime(n)) R(1, sum+1);\n\t\tfor (int i = 2; i <= n; i++)\n\t\t\tif (n%i==0) {\n\t\t\t\tR(n/i, sum + n/i);\n\t\t\t\tbreak;\n\t\t\t}\n\t}\n\t\n\t\n\tpublic static void main(String args[]){\n\t\tScanner in=new Scanner(System.in);\n\t\tlong n = in.nextLong();\n\t\tR(n, n);\n\t\tSystem.out.println(max);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "741e37db93a2bf057b072b0430555135", "src_uid": "821c0e3b5fad197a47878bba5e520b6e", "difficulty": 1200.0} {"lang": "Java 7", "source_code": "import sun.misc.Sort;\n\nimport java.io.*;\nimport java.lang.reflect.Array;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n/**\n * Created by user on 04.03.14.\n */\n\npublic class code {\n public static void main(String[] args) throws IOException\n {\n new code().run();\n }\n\n void run(){\n try{\n // \u0441 \u043a\u043e\u043d\u0441\u043e\u043b\u0438\n sc = new Scanner( new InputStreamReader(System.in ) );\n out = new PrintWriter( new OutputStreamWriter(System.out) );\n\n // \u0441 \u0444\u0430\u0439\u043b\u043e\u0432\n // sc = new Scanner(new FileReader(\"input.txt\") );\n // out = new PrintWriter( new FileWriter(\"output.txt\") );\n } catch (Exception e) {\n return;\n }\n double tBeg = System.currentTimeMillis();\n solve();\n System.err.println( \"TIME: \" + (System.currentTimeMillis()-tBeg)/1e3 );\n out.flush();\n out.close();\n }\n //////////////////////////////////////////////////////////////////////////////////////////\n\n Scanner sc;\n PrintWriter out;\n\n void solve()\n {\n int n = sc.nextInt();\n int [] a = new int[n];\n for (int i = 0; i < n; i++)\n a[i] = sc.nextInt();\n int k = sc.nextInt();\n Arrays.sort(a);\n int ans = 0;\n for (int i = 0; i < n; i++)\n {\n int cur = 0;\n for (int j = i + 1; j < n; j++)\n {\n if(a[j] - a[i] <= k)\n cur++;\n else\n break;\n }\n ans = Math.max(ans, ++cur);\n }\n out.print(ans);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ffda8e1ab9dfa49d1fa67f33fe23ecb9", "src_uid": "086d07bd6f9031df09bd6a6e8fe8f25c", "difficulty": 1400.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class Main {\n public static void main(String args[]) {\n Scanner in = new Scanner(System.in);\n\n long n = in.nextLong();\n long m = in.nextLong();\n\n long x = 1;\n long k = 2;\n long p = 1000000009;\n while (m>0) {\n if (m%2==0) {\n k = (k*k)%p;\n m/=2;\n } else {\n m--;\n x = (x*k)%p;\n }\n }\n long ans = 1;\n for (int i=1;i<=n;i++) {\n x--;\n if (x<0) {\n x+= p;\n }\n ans*=x;\n }\n\n System.out.println(ans);\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "715e37251feb3837462cf6f14a717568", "src_uid": "fef4d9c94a93fcf6d536f33503b1d4b8", "difficulty": 1300.0} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Main{\n\n BufferedReader in;\n StringTokenizer str = null;\n PrintWriter out;\n\n private String next() throws Exception{\n \twhile (str == null || !str.hasMoreElements())\n \t str = new StringTokenizer(in.readLine());\n \treturn str.nextToken();\n }\n \n private int nextInt() throws Exception{\n\treturn Integer.parseInt(next());\n }\n \n int lp[];\n List pr;\n \n public void run() throws Exception{\n \tin = new BufferedReader(new InputStreamReader(System.in));\n \tout = new PrintWriter(System.out);\n\tint a = nextInt(), b = nextInt(), k = nextInt();\n\tfor(int i = 2; i * i <= k; ++i){\n\t if (k % i == 0){\n\t\tout.println(0);\n\t\tout.close();\n\t\treturn;\n\t }\n\t}\n\t\n\tif (k > 100){\n\t int n = b / k;\n\t pr = new ArrayList();\n\t lp = new int[n + 1];\n\t for(int i = 2; i <= n; ++i){\n\t\tif (lp[i] == 0){\n\t\t lp[i] = i;\n\t\t pr.add(i);\n\t\t}\n\t\tfor(int j = 0;j < pr.size() && pr.get(j) <= i && 1L * i * pr.get(j) <= n; ++j){\n\t\t lp[pr.get(j) * i] = pr.get(j);\n\t\t}\n\t }\n\t \n\t int res = calc(b, k) - calc(a-1, k);\n\t out.println(res);\n\t}else{\n\t pr = new ArrayList();\n\t for(int i = 2; i < k; ++i){\n\t\tif (isPrime(i)){\n\t\t pr.add(i);\n\t\t}\n\t }\n\t \n\t int res = calc1(b, k) - calc1(a-1, k);\n\t out.println(res);\n\t}\n\t\n out.close();\n }\n \n private boolean isPrime(int x) {\n\tfor(int i = 2; i * i <= x; ++i){\n\t if (x % i == 0){\n\t\treturn false;\n\t }\n\t}\n\treturn true;\n }\n \n private int calc(int n, int k){\n\tint ret = 0;\n\tfor(int i = 2; 1L * i * k <= n; ++i){\n\t if (lp[i] >= k){\n\t\t++ret;\n\t }\n\t}\n\treturn ret;\n }\n \n private int calc1(int n, int k){\n\tint res = n / k;\n\tint N = pr.size();\n\tfor(int mask = 1; mask < 1 << N; ++mask){\n\t int r = n/k;\n\t for(int j = 0; j < N; ++j){\n\t if ((mask & (1 << j)) > 0){\n\t\t r/=pr.get(j);\n\t\t}\n\t }\n\t if (Integer.bitCount(mask) % 2 == 1){\n\t res-=r;\n\t }else{\n\t res+=r;\n\t }\n\t}\n\t\n\treturn res;\n }\n\n public static void main(String args[]) throws Exception{\n\tnew Main().run();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c7d09c0dc376e98e55ef761817f25963", "src_uid": "04a26f1d1013b6e6b4b0bdcf225475f2", "difficulty": 2400.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class Main {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int a = sc.nextInt(); // side length of a square\n int x = sc.nextInt(); // x-coord of stone landing.\n int y = sc.nextInt(); // y-coord of stone landing.\n if (y % a == 0) { // lies either on a border, or in the outer region\n System.out.println(\"-1\");\n } else if (y / a % 2 == 0 && y / a > 1)) { // two horizontal boxes on this y-level\n if (-a < x && x < 0) {\n System.out.println(((y / a) * 3) / 2);\n } else if (0 < x && x < a) {\n System.out.println(((y / a) * 3) / 2 + 1);\n } else {\n System.out.println(\"-1\");\n }\n } else { // one horizontal box on this y-level\n if (Math.abs(x) < (a + 1) / 2) {\n if (y < a) {\n System.out.println(\"1\");\n } else {\n System.out.println((((y / a) - 1) * 3) / 2 + 2);\n }\n } else {\n System.out.println(\"-1\");\n }\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4e854ad5e1fe46e06a3fb9fc60f0be8a", "src_uid": "cf48ff6ba3e77ba5d4afccb8f775fb02", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n DMagicGems solver = new DMagicGems();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class DMagicGems {\n private int MOD = (int) 1e9 + 7;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n long n = in.nextLong();\n int m = in.nextInt();\n\n long[][] M = new long[m][m];\n M[0][0] = 1;\n M[0][m - 1] = 1;\n for (int i = 1; i < m; i++) {\n M[i][i - 1] = 1;\n }\n Matrix MM = new Matrix(M);\n Matrix.MM.mod = MOD;\n MM = MM.fastPower(n - m + 1);\n long x_n = MM.data[0][0] + MM.data[0][1] % MOD;\n out.println(x_n);\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n }\n\n static class Matrix {\n public static long mod = Long.MAX_VALUE;\n public final long[][] data;\n public final int rowCount;\n public final int columnCount;\n\n public Matrix(int rowCount, int columnCount) {\n this.rowCount = rowCount;\n this.columnCount = columnCount;\n this.data = new long[rowCount][columnCount];\n }\n\n public Matrix(long[][] data) {\n this.rowCount = data.length;\n this.columnCount = data[0].length;\n this.data = data;\n }\n\n public static Matrix multiply(Matrix first, Matrix second) {\n Matrix result = new Matrix(first.rowCount, second.columnCount);\n for (int i = 0; i < first.rowCount; i++) {\n for (int j = 0; j < second.rowCount; j++) {\n for (int k = 0; k < second.columnCount; k++) {\n result.data[i][k] = (result.data[i][k] + first.data[i][j] * second.data[j][k]) % mod;\n }\n }\n }\n return result;\n }\n\n public static Matrix fastMultiply(Matrix first, Matrix second) {\n Matrix result = new Matrix(first.rowCount, second.columnCount);\n for (int i = 0; i < first.rowCount; i++) {\n for (int j = 0; j < second.rowCount; j++) {\n for (int k = 0; k < second.columnCount; k++) {\n result.data[i][k] += first.data[i][j] * second.data[j][k];\n }\n }\n }\n for (int i = 0; i < first.rowCount; i++) {\n for (int j = 0; j < second.columnCount; j++) {\n result.data[i][j] %= mod;\n }\n }\n return result;\n }\n\n public static Matrix identityMatrix(int size) {\n Matrix result = new Matrix(size, size);\n for (int i = 0; i < size; i++) {\n result.data[i][i] = 1;\n }\n return result;\n }\n\n public Matrix power(long exponent) {\n if (exponent == 0) {\n return identityMatrix(rowCount);\n }\n if (exponent == 1) {\n return this;\n }\n Matrix result = power(exponent >> 1);\n result = multiply(result, result);\n if ((exponent & 1) == 1) {\n result = multiply(result, this);\n }\n return result;\n }\n\n public Matrix fastPower(long exponent) {\n if (exponent == 0) {\n return identityMatrix(rowCount);\n }\n if (exponent == 1) {\n return this;\n }\n Matrix result = power(exponent >> 1);\n result = fastMultiply(result, result);\n if ((exponent & 1) == 1) {\n result = fastMultiply(result, this);\n }\n return result;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9b7793461aeaa3ebc91b2b73a36fb90e", "src_uid": "e7b9eec21d950f5d963ff50619c6f119", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.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) throws IOException {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n ACuttingBanner solver = new ACuttingBanner();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class ACuttingBanner {\n public void solve(int testNumber, InputReader in, OutputWriter out) throws IOException {\n String S = in.nextString();\n if (S.length()=>10&&(S.substring(0, 10).equals(\"CODEFORCES\") ||\n (S.substring(0, 9).equals(\"CODEFORCE\") && S.substring(S.length() - 1).equals(\"S\")) ||\n (S.substring(0, 8).equals(\"CODEFORC\") && S.substring(S.length() - 2).equals(\"ES\")) ||\n (S.substring(0, 7).equals(\"CODEFOR\") && S.substring(S.length() - 3).equals(\"CES\")) ||\n (S.substring(0, 6).equals(\"CODEFO\") && S.substring(S.length() - 4).equals(\"RCES\")) ||\n (S.substring(0, 5).equals(\"CODEF\") && S.substring(S.length() - 5).equals(\"ORCES\")) ||\n (S.substring(0, 4).equals(\"CODE\") && S.substring(S.length() - 6).equals(\"FORCES\")) ||\n (S.substring(0, 3).equals(\"COD\") && S.substring(S.length() - 7).equals(\"EFORCES\")) ||\n (S.substring(0, 2).equals(\"CO\") && S.substring(S.length() - 8).equals(\"DEFORCES\")) ||\n (S.substring(0, 1).equals(\"C\") && S.substring(S.length() - 9).equals(\"ODEFORCES\")) ||\n S.substring(S.length() - 10).equals(\"CODEFORCES\")))\n out.printLine(\"YES\");\n else\n out.printLine(\"NO\");\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 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\n static class InputReader {\n private static final int DEFAULT_BUFFER_SIZE = 1 << 16;\n private static final InputStream DEFAULT_STREAM = System.in;\n private byte[] buf;\n private int bufferSize;\n private int bufIndex;\n private int numBytesRead;\n private InputStream stream;\n private static final byte EOF = -1;\n private static final byte SPACE = 32;\n private char[] charBuffer;\n private static byte[] bytes = new byte[58];\n private static int[] ints = new int[58];\n private static char[] chars = new char[128];\n\n static {\n char ch = ' ';\n int value = 0;\n byte _byte = 0;\n for (int i = 48; i < 58; i++) bytes[i] = _byte++;\n for (int i = 48; i < 58; i++) ints[i] = value++;\n for (int i = 32; i < 128; i++) chars[i] = ch++;\n }\n\n public InputReader() {\n this(DEFAULT_STREAM, DEFAULT_BUFFER_SIZE);\n }\n\n public InputReader(int bufferSize) {\n this(DEFAULT_STREAM, bufferSize);\n }\n\n public InputReader(InputStream stream) {\n this(stream, DEFAULT_BUFFER_SIZE);\n }\n\n public InputReader(InputStream stream, int bufferSize) {\n if (stream == null || bufferSize <= 0)\n throw new IllegalArgumentException();\n buf = new byte[bufferSize];\n charBuffer = new char[128];\n this.bufferSize = bufferSize;\n this.stream = stream;\n }\n\n private int readJunk(int token) throws IOException {\n\n if (numBytesRead == EOF) return EOF;\n\n // Seek to the first valid position index\n do {\n\n while (bufIndex < numBytesRead) {\n if (buf[bufIndex] > token) return 0;\n bufIndex++;\n }\n\n // reload buffer\n numBytesRead = stream.read(buf);\n if (numBytesRead == EOF) return EOF;\n bufIndex = 0;\n\n } while (true);\n\n }\n\n private void doubleCharBufferSize() {\n char[] newBuffer = new char[charBuffer.length << 1];\n for (int i = 0; i < charBuffer.length; i++) newBuffer[i] = charBuffer[i];\n charBuffer = newBuffer;\n }\n\n public String nextString() throws IOException {\n if (numBytesRead == EOF) return null;\n if (readJunk(SPACE) == EOF) return null;\n\n for (int i = 0; ; ) {\n while (bufIndex < numBytesRead) {\n if (buf[bufIndex] > SPACE) {\n if (i == charBuffer.length) doubleCharBufferSize();\n charBuffer[i++] = (char) buf[bufIndex++];\n } else {\n bufIndex++;\n return new String(charBuffer, 0, i);\n }\n }\n\n // Reload buffer\n numBytesRead = stream.read(buf);\n if (numBytesRead == EOF) return new String(charBuffer, 0, i);\n bufIndex = 0;\n }\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "70fe441fedc105d55197818dc7203875", "src_uid": "bda4b15827c94b526643dfefc4bc36e7", "difficulty": 1400.0} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.util.Arrays;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Mahmoud Aladdin \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\tTaskD solver = new TaskD();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskD {\n int[][] t = new int[3][3];\n long[][][] hanoi = new long[40][3][3];\n\n public void solve(int testNumber, InputReader jin, PrintWriter jout) {\n for(long[][] grid: hanoi)\n for(long[] row: grid)\n Arrays.fill(row, -1);\n\n for(int i = 0; i < 3; i++)\n for(int j = 0; j < 3; j++)\n t[i][j] = jin.int32();\n\n jout.println(dp(jin.int32(), 0, 2));\n }\n\n private long dp(int n, int i, int j) {\n if(n == 0) return 0;\n if(hanoi[n][i][j] == -1) {\n int other = 3 - i - j;\n long sol1 = dp(n - 1, i, other) + t[i][j] + dp(n - 1, other, j);\n long sol2 = dp(n - 1, i, j) + t[i][other] + dp(n - 1, j, i) + t[other][j] + dp(n - 1, i, j);\n hanoi[n][i][j] = Math.min(sol1, sol2);\n }\n return hanoi[n][i][j];\n }\n}\n\nclass InputReader {\n private static final int bufferMaxLength = 1024;\n private InputStream in;\n private byte[] buffer;\n private int currentBufferSize;\n private int currentBufferTop;\n private static final String tokenizers = \" \\t\\r\\f\\n\";\n \n public InputReader(InputStream stream) {\n this.in = stream;\n buffer = new byte[bufferMaxLength];\n currentBufferSize = 0;\n currentBufferTop = 0;\n }\n \n private boolean refill() {\n try {\n this.currentBufferSize = this.in.read(this.buffer);\n this.currentBufferTop = 0;\n } catch(Exception e) {}\n return this.currentBufferSize > 0;\n }\n \n \n private Byte readChar() {\n if(currentBufferTop < currentBufferSize) {\n return this.buffer[this.currentBufferTop++];\n } else {\n if(!this.refill()) {\n return null;\n } else {\n return readChar();\n }\n }\n }\n\n public String token() {\n StringBuffer tok = new StringBuffer();\n Byte first;\n while((first = readChar()) != null && (tokenizers.indexOf((char) first.byteValue()) != -1));\n if(first == null) return null;\n tok.append((char)first.byteValue());\n while((first = readChar()) != null && (tokenizers.indexOf((char) first.byteValue()) == -1)) {\n tok.append((char)first.byteValue());\n }\n return tok.toString();\n }\n \n public Integer int32() throws NumberFormatException {\n String tok = token();\n return tok == null? null : Integer.parseInt(tok);\n }\n\n }\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "50839e2308de3b70c422e47167077b8d", "src_uid": "c4c20228624365e39299d0a6e8fe7095", "difficulty": null} {"lang": "Java 8", "source_code": "\n\nimport java.util.Scanner;\n\npublic class Main {\n\n\t/**\n\t * @param args\n\t */\n\t public boolean isPrime(int num) {\n\t\t if ( num < 2 ){\n\t\t\t return false;\n\t\t }\n\t\t for (int i = 2; i <= Math.sqrt(num); i++) {\n\t\t\t if ( num % i == 0 ) {\n\t\t\t \t\treturn false;\n\t\t\t }\n\t\t }\n\t\t return true;\n\t }\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tMAin m=new Main();\n\t\tScanner s=new Scanner(System.in);\n\t\tint n=s.nextInt();\n\t\tlong product=1;\n\t\tint count=0;\n\t\tint[] arr=new int[n+1];\n\t\tfor(int r=2,k=n;;r++){\n\t\t\tif(r<=k){\n\t\t\t\tif(k%r==0){\n\t\t\t\t\tarr[r]=arr[r]+1;\n\t\t\t\t\tk=k/r;\n\t\t\t\t\tr--;\n\t\t\t\t\tcount++;\n\t\t\t }\n\t\t\t}\n\t\t\telse{\n\t\t\t\tcount--;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif(count>=2){\n\t\t\tint flag=0;\n\t\t\tif(arr[2]>=3){\n\t\t\t\tfor(int u=3;u<=n;u++){\n\t\t\t\t\tif(arr[u]!=0)\n\t\t\t\t\t\tflag=1;\n\t\t\t\t}\n\t\t\t\tif(flag==0){\n\t\t\t\tint h=arr[2]/3;\n\t\t\t\tarr[2]=arr[2]-(2*h);\n\t\t\t\tarr[4]=h;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(arr[2]>3){\n\t\t\t\tint h=arr[2]/3;\n\t\t\t\tarr[2]=arr[2]-(2*h);\n\t\t\t\tarr[4]=h;\n\t\t\t}\n\t\t}\n\t\tint q=2;\n\t\tfor(int j=n;j>=2;j--){\n\t\t\twhile(arr[j]!=0){\n\t\t\t\t\tif(m.isPrime(q)){\n\t\t\t\t\t\tproduct=product*(long)Math.pow((long)q,(long)(j-1));\n\t\t\t\t\t\t//System.out.print(\"check:\"+product);\n\t\t\t\t\t\tq++;\n\t\t\t\t\t\tarr[j]--;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\tq++;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(product);\n\t\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "57472c028890243f4d88a3c35082988c", "src_uid": "62db589bad3b7023418107de05b7a8ee", "difficulty": 2000.0} {"lang": "Java 6", "source_code": "/*\n * Hello! You are trying to hack my solution, are you? =)\n * Don't be afraid of the size, it's just a dump of useful methods like gcd, or n-th Fib number.\n * And I'm just too lazy to create a new .java for every task.\n * And if you were successful to hack my solution, please, send me this test as a message or to Abrackadabraa@gmail.com.\n * It can help me improve my skills and i'd be very grateful for that.\n * Sorry for time you spent reading this message. =)\n * Good luck, unknown rival. =)\n * */\n\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Abra {\n\t// double d = 2.2250738585072012e-308;\n\tvoid solve() throws IOException {\n\t\tint n = nextInt();\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tfor (int j = 1; j < n; j++) {\n\t\t\t\tout.print(i * j + \" \");\n\t\t\t}\n\t\t\tout.println();\n\t\t}\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Abra().run();\n\t}\n\n\tStreamTokenizer in;\n\tPrintWriter out;\n\tboolean oj;\n\tBufferedReader br;\n\n\tvoid init() throws IOException {\n\t\toj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\tReader reader = oj ? new InputStreamReader(System.in) : new FileReader(\"input.txt\");\n\t\tWriter writer = oj ? new OutputStreamWriter(System.out) : new FileWriter(\"output.txt\");\n\t\tbr = new BufferedReader(reader);\n\t\tin = new StreamTokenizer(br);\n\t\tout = new PrintWriter(writer);\n\t}\n\n\tlong beginTime;\n\t\n\tvoid run() throws IOException {\n\t\tbeginTime = System.currentTimeMillis();\n\t\tlong beginMem = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();\n\t\tinit();\n\t\tsolve();\n\t\tlong endMem = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();\n\t\tlong endTime = System.currentTimeMillis();\n\t\tif (!oj) {\n\t\t\tSystem.out.println(\"Memory used = \" + (endMem - beginMem));\n\t\t\tSystem.out.println(\"Total memory = \" + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));\n\t\t\tSystem.out.println(\"Running time = \" + (endTime - beginTime));\n\t\t}\n\t\tout.flush();\n\t}\n\n\tint nextInt() throws IOException {\n\t\tin.nextToken();\n\t\treturn (int) in.nval;\n\t}\n\n\tlong nextLong() throws IOException {\n\t\tin.nextToken();\n\t\treturn (long) in.nval;\n\t}\n\n\tString nextString() throws IOException {\n\t\tin.nextToken();\n\t\treturn in.sval;\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\tin.nextToken();\n\t\treturn in.nval;\n\t}\n\n\tmyLib lib = new myLib();\n\t\n\tvoid time() {\n\t\tSystem.out.print(\"It's \");\n\t\tSystem.out.println(System.currentTimeMillis() - beginTime);\n\t}\n\n\tstatic class myLib {\n\t\tlong fact(long x) {\n\t\t\tlong a = 1;\n\t\t\tfor (long i = 2; i <= x; i++) {\n\t\t\t\ta *= i;\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tlong digitSum(String x) {\n\t\t\tlong a = 0;\n\t\t\tfor (int i = 0; i < x.length(); i++) {\n\t\t\t\ta += x.charAt(i) - '0';\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tlong digitSum(long x) {\n\t\t\tlong a = 0;\n\t\t\twhile (x > 0) {\n\t\t\t\ta += x % 10;\n\t\t\t\tx /= 10;\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tlong digitMul(long x) {\n\t\t\tlong a = 1;\n\t\t\twhile (x > 0) {\n\t\t\t\ta *= x % 10;\n\t\t\t\tx /= 10;\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tint digitCubesSum(int x) {\n\t\t\tint a = 0;\n\t\t\twhile (x > 0) {\n\t\t\t\ta += (x % 10) * (x % 10) * (x % 10);\n\t\t\t\tx /= 10;\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tdouble pif(double ax, double ay, double bx, double by) {\n\t\t\treturn Math.sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));\n\t\t}\n\n\t\tdouble pif3D(double ax, double ay, double az, double bx, double by, double bz) {\n\t\t\treturn Math.sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by) + (az - bz) * (az - bz));\n\t\t}\n\n\t\tdouble pif3D(double[] a, double[] b) {\n\t\t\treturn Math.sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]) + (a[2] - b[2]) * (a[2] - b[2]));\n\t\t}\n\n\t\tlong gcd(long a, long b) {\n\t\t\tif (a == 0 || b == 0) return 1;\n\t\t\tif (a < b) {\n\t\t\t\tlong c = b;\n\t\t\t\tb = a;\n\t\t\t\ta = c;\n\t\t\t}\n\t\t\twhile (a % b != 0) {\n\t\t\t\ta = a % b;\n\t\t\t\tif (a < b) {\n\t\t\t\t\tlong c = b;\n\t\t\t\t\tb = a;\n\t\t\t\t\ta = c;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn b;\n\t\t}\n\n\t\tint gcd(int a, int b) {\n\t\t\tif (a == 0 || b == 0) return 1;\n\t\t\tif (a < b) {\n\t\t\t\tint c = b;\n\t\t\t\tb = a;\n\t\t\t\ta = c;\n\t\t\t}\n\t\t\twhile (a % b != 0) {\n\t\t\t\ta = a % b;\n\t\t\t\tif (a < b) {\n\t\t\t\t\tint c = b;\n\t\t\t\t\tb = a;\n\t\t\t\t\ta = c;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn b;\n\t\t}\n\n\t\tlong lcm(long a, long b) {\n\t\t\treturn a * b / gcd(a, b);\n\t\t}\n\n\t\tint lcm(int a, int b) {\n\t\t\treturn a * b / gcd(a, b);\n\t\t}\n\n\t\tint countOccurences(String x, String y) {\n\t\t\tint a = 0, i = 0;\n\t\t\twhile (true) {\n\t\t\t\ti = y.indexOf(x);\n\t\t\t\tif (i == -1) break;\n\t\t\t\ta++;\n\t\t\t\ty = y.substring(i + 1);\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tint[] findPrimes(int x) {\n\t\t\tboolean[] forErato = new boolean[x - 1];\n\t\t\tList t = new Vector();\n\t\t\tint l = 0, j = 0;\n\t\t\tfor (int i = 2; i < x; i++) {\n\t\t\t\tif (forErato[i - 2]) continue;\n\t\t\t\tt.add(i);\n\t\t\t\tl++;\n\t\t\t\tj = i * 2;\n\t\t\t\twhile (j < x) {\n\t\t\t\t\tforErato[j - 2] = true;\n\t\t\t\t\tj += i;\n\t\t\t\t}\n\t\t\t}\n\t\t\tint[] primes = new int[l];\n\t\t\tIterator iterator = t.iterator();\n\t\t\tfor (int i = 0; iterator.hasNext(); i++) {\n\t\t\t\tprimes[i] = iterator.next().intValue();\n\t\t\t}\n\t\t\treturn primes;\n\t\t}\n\n\t\tint rev(int x) {\n\t\t\tint a = 0;\n\t\t\twhile (x > 0) {\n\t\t\t\ta = a * 10 + x % 10;\n\t\t\t\tx /= 10;\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tclass myDate {\n\t\t\tint d, m, y;\n\n\t\t\tint[] ml = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\n\n\t\t\tpublic myDate(int da, int ma, int ya) {\n\t\t\t\td = da;\n\t\t\t\tm = ma;\n\t\t\t\ty = ya;\n\t\t\t\tif ((ma > 12 || ma < 1 || da > ml[ma - 1] || da < 1) && !(d == 29 && m == 2 && y % 4 == 0)) {\n\t\t\t\t\td = 1;\n\t\t\t\t\tm = 1;\n\t\t\t\t\ty = 9999999;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tvoid incYear(int x) {\n\t\t\t\tfor (int i = 0; i < x; i++) {\n\t\t\t\t\ty++;\n\t\t\t\t\tif (m == 2 && d == 29) {\n\t\t\t\t\t\tm = 3;\n\t\t\t\t\t\td = 1;\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (m == 3 && d == 1) {\n\t\t\t\t\t\tif (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0)) {\n\t\t\t\t\t\t\tm = 2;\n\t\t\t\t\t\t\td = 29;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tboolean less(myDate x) {\n\t\t\t\tif (y < x.y) return true;\n\t\t\t\tif (y > x.y) return false;\n\t\t\t\tif (m < x.m) return true;\n\t\t\t\tif (m > x.m) return false;\n\t\t\t\tif (d < x.d) return true;\n\t\t\t\tif (d > x.d) return false;\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tvoid inc() {\n\t\t\t\tif ((d == 31) && (m == 12)) {\n\t\t\t\t\ty++;\n\t\t\t\t\td = 1;\n\t\t\t\t\tm = 1;\n\t\t\t\t} else {\n\t\t\t\t\tif (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0)) {\n\t\t\t\t\t\tml[1] = 29;\n\t\t\t\t\t}\n\t\t\t\t\tif (d == ml[m - 1]) {\n\t\t\t\t\t\tm++;\n\t\t\t\t\t\td = 1;\n\t\t\t\t\t} else\n\t\t\t\t\t\td++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint partition(int n, int l, int m) {// n - sum, l - length, m - every\n\t\t\t\t\t\t\t\t\t\t\t// part\n\t\t\t// <= m\n\t\t\tif (n < l) return 0;\n\t\t\tif (n < l + 2) return 1;\n\t\t\tif (l == 1) return 1;\n\t\t\tint c = 0;\n\t\t\tfor (int i = Math.min(n - l + 1, m); i >= (n + l - 1) / l; i--) {\n\t\t\t\tc += partition(n - i, l - 1, i);\n\t\t\t}\n\t\t\treturn c;\n\t\t}\n\n\t\tint rifmQuality(String a, String b) {\n\t\t\tif (a.length() > b.length()) {\n\t\t\t\tString c = a;\n\t\t\t\ta = b;\n\t\t\t\tb = c;\n\t\t\t}\n\t\t\tint c = 0, d = b.length() - a.length();\n\t\t\tfor (int i = a.length() - 1; i >= 0; i--) {\n\t\t\t\tif (a.charAt(i) == b.charAt(i + d)) c++;\n\t\t\t\telse\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\treturn c;\n\t\t}\n\n\t\tString numSym = \"0123456789ABCDEF\";\n\n\t\tString ZFromXToYNotation(int x, int y, String z) {\n\t\t\tif (z.equals(\"0\")) return \"0\";\n\t\t\tString a = \"\";\n\t\t\t// long q = 0, t = 1;\n\t\t\tBigInteger q = BigInteger.ZERO, t = BigInteger.ONE;\n\t\t\tfor (int i = z.length() - 1; i >= 0; i--) {\n\t\t\t\tq = q.add(t.multiply(BigInteger.valueOf(z.charAt(i) - 48)));\n\t\t\t\tt = t.multiply(BigInteger.valueOf(x));\n\t\t\t}\n\t\t\twhile (q.compareTo(BigInteger.ZERO) == 1) {\n\t\t\t\ta = numSym.charAt((int) (q.mod(BigInteger.valueOf(y)).intValue())) + a;\n\t\t\t\tq = q.divide(BigInteger.valueOf(y));\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tdouble angleFromXY(int x, int y) {\n\t\t\tif ((x == 0) && (y > 0)) return Math.PI / 2;\n\t\t\tif ((x == 0) && (y < 0)) return -Math.PI / 2;\n\t\t\tif ((y == 0) && (x > 0)) return 0;\n\t\t\tif ((y == 0) && (x < 0)) return Math.PI;\n\t\t\tif (x > 0) return Math.atan((double) y / x);\n\t\t\telse {\n\t\t\t\tif (y > 0) return Math.atan((double) y / x) + Math.PI;\n\t\t\t\telse\n\t\t\t\t\treturn Math.atan((double) y / x) - Math.PI;\n\t\t\t}\n\t\t}\n\n\t\tstatic boolean isNumber(String x) {\n\t\t\ttry {\n\t\t\t\tInteger.parseInt(x);\n\t\t\t} catch (NumberFormatException ex) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tstatic boolean stringContainsOf(String x, String c) {\n\t\t\tfor (int i = 0; i < x.length(); i++) {\n\t\t\t\tif (c.indexOf(x.charAt(i)) == -1) return false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tlong pow(long a, long n) { // b > 0\n\t\t\tif (n == 0) return 1;\n\t\t\tlong k = n, b = 1, c = a;\n\t\t\twhile (k != 0) {\n\t\t\t\tif (k % 2 == 0) {\n\t\t\t\t\tk /= 2;\n\t\t\t\t\tc *= c;\n\t\t\t\t} else {\n\t\t\t\t\tk--;\n\t\t\t\t\tb *= c;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn b;\n\t\t}\n\n\t\tint pow(int a, int n) { // b > 0\n\t\t\tif (n == 0) return 1;\n\t\t\tint k = n, b = 1, c = a;\n\t\t\twhile (k != 0) {\n\t\t\t\tif (k % 2 == 0) {\n\t\t\t\t\tk /= 2;\n\t\t\t\t\tc *= c;\n\t\t\t\t} else {\n\t\t\t\t\tk--;\n\t\t\t\t\tb *= c;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn b;\n\t\t}\n\n\t\tdouble pow(double a, int n) { // b > 0\n\t\t\tif (n == 0) return 1;\n\t\t\tdouble k = n, b = 1, c = a;\n\t\t\twhile (k != 0) {\n\t\t\t\tif (k % 2 == 0) {\n\t\t\t\t\tk /= 2;\n\t\t\t\t\tc *= c;\n\t\t\t\t} else {\n\t\t\t\t\tk--;\n\t\t\t\t\tb *= c;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn b;\n\t\t}\n\n\t\tdouble log2(double x) {\n\t\t\treturn Math.log(x) / Math.log(2);\n\t\t}\n\n\t\tint lpd(int[] primes, int x) {// least prime divisor\n\t\t\tint i;\n\t\t\tfor (i = 0; primes[i] <= x / 2; i++) {\n\t\t\t\tif (x % primes[i] == 0) {\n\t\t\t\t\treturn primes[i];\n\t\t\t\t}\n\t\t\t}\n\t\t\t;\n\t\t\treturn x;\n\t\t}\n\n\t\tint np(int[] primes, int x) {// number of prime number\n\t\t\tfor (int i = 0; true; i++) {\n\t\t\t\tif (primes[i] == x) return i;\n\t\t\t}\n\t\t}\n\n\t\tint[] dijkstra(int[][] map, int n, int s) {\n\t\t\tint[] p = new int[n];\n\t\t\tboolean[] b = new boolean[n];\n\t\t\tArrays.fill(p, Integer.MAX_VALUE);\n\t\t\tp[s] = 0;\n\t\t\tb[s] = true;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (i != s) p[i] = map[s][i];\n\t\t\t}\n\t\t\twhile (true) {\n\t\t\t\tint m = Integer.MAX_VALUE, mi = -1;\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tif (!b[i] && (p[i] < m)) {\n\t\t\t\t\t\tmi = i;\n\t\t\t\t\t\tm = p[i];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (mi == -1) break;\n\t\t\t\tb[mi] = true;\n\t\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\t\tif (p[mi] + map[mi][i] < p[i]) p[i] = p[mi] + map[mi][i];\n\t\t\t}\n\t\t\treturn p;\n\t\t}\n\n\t\tboolean isLatinChar(char x) {\n\t\t\tif (((x >= 'a') && (x <= 'z')) || ((x >= 'A') && (x <= 'Z'))) return true;\n\t\t\telse\n\t\t\t\treturn false;\n\t\t}\n\n\t\tboolean isBigLatinChar(char x) {\n\t\t\tif (x >= 'A' && x <= 'Z') return true;\n\t\t\telse\n\t\t\t\treturn false;\n\t\t}\n\n\t\tboolean isSmallLatinChar(char x) {\n\t\t\tif (x >= 'a' && x <= 'z') return true;\n\t\t\telse\n\t\t\t\treturn false;\n\t\t}\n\n\t\tboolean isDigitChar(char x) {\n\t\t\tif (x >= '0' && x <= '9') return true;\n\t\t\telse\n\t\t\t\treturn false;\n\t\t}\n\n\t\tclass NotANumberException extends Exception {\n\t\t\tprivate static final long serialVersionUID = 1L;\n\t\t\tString mistake;\n\n\t\t\tNotANumberException() {\n\t\t\t\tmistake = \"Unknown.\";\n\t\t\t}\n\n\t\t\tNotANumberException(String message) {\n\t\t\t\tmistake = message;\n\t\t\t}\n\t\t}\n\n\t\tclass Real {\n\t\t\tString num = \"0\";\n\t\t\tlong exp = 0;\n\t\t\tboolean pos = true;\n\n\t\t\tlong length() {\n\t\t\t\treturn num.length();\n\t\t\t}\n\n\t\t\tvoid check(String x) throws NotANumberException {\n\t\t\t\tif (!stringContainsOf(x, \"0123456789+-.eE\")) throw new NotANumberException(\"Illegal character.\");\n\t\t\t\tlong j = 0;\n\t\t\t\tfor (long i = 0; i < x.length(); i++) {\n\t\t\t\t\tif ((x.charAt((int) i) == '-') || (x.charAt((int) i) == '+')) {\n\t\t\t\t\t\tif (j == 0) j = 1;\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tif (j == 5) j = 6;\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\tthrow new NotANumberException(\"Unexpected sign.\");\n\t\t\t\t\t} else\n\t\t\t\t\t\tif (\"0123456789\".indexOf(x.charAt((int) i)) != -1) {\n\t\t\t\t\t\t\tif (j == 0) j = 2;\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\tif (j == 1) j = 2;\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\tif (j == 2)\n\t\t\t\t\t\t\t\t\t;\n\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\tif (j == 3) j = 4;\n\t\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\t\tif (j == 4)\n\t\t\t\t\t\t\t\t\t\t\t;\n\t\t\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\t\t\tif (j == 5) j = 6;\n\t\t\t\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (j == 6)\n\t\t\t\t\t\t\t\t\t\t\t\t\t;\n\t\t\t\t\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tthrow new NotANumberException(\"Unexpected digit.\");\n\t\t\t\t\t\t} else\n\t\t\t\t\t\t\tif (x.charAt((int) i) == '.') {\n\t\t\t\t\t\t\t\tif (j == 0) j = 3;\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\tif (j == 1) j = 3;\n\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\tif (j == 2) j = 3;\n\t\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\t\tthrow new NotANumberException(\"Unexpected dot.\");\n\t\t\t\t\t\t\t} else\n\t\t\t\t\t\t\t\tif ((x.charAt((int) i) == 'e') || (x.charAt((int) i) == 'E')) {\n\t\t\t\t\t\t\t\t\tif (j == 2) j = 5;\n\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\tif (j == 4) j = 5;\n\t\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\t\tthrow new NotANumberException(\"Unexpected exponent.\");\n\t\t\t\t\t\t\t\t} else\n\t\t\t\t\t\t\t\t\tthrow new NotANumberException(\"O_o.\");\n\t\t\t\t}\n\t\t\t\tif ((j == 0) || (j == 1) || (j == 3) || (j == 5)) throw new NotANumberException(\"Unexpected end.\");\n\t\t\t}\n\n\t\t\tpublic Real(String x) throws NotANumberException {\n\t\t\t\tcheck(x);\n\t\t\t\tif (x.charAt(0) == '-') pos = false;\n\t\t\t\tlong j = 0;\n\t\t\t\tString e = \"\";\n\t\t\t\tboolean epos = true;\n\t\t\t\tfor (long i = 0; i < x.length(); i++) {\n\t\t\t\t\tif (\"0123456789\".indexOf(x.charAt((int) i)) != -1) {\n\t\t\t\t\t\tif (j == 0) num += x.charAt((int) i);\n\t\t\t\t\t\tif (j == 1) {\n\t\t\t\t\t\t\tnum += x.charAt((int) i);\n\t\t\t\t\t\t\texp--;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (j == 2) e += x.charAt((int) i);\n\t\t\t\t\t}\n\t\t\t\t\tif (x.charAt((int) i) == '.') {\n\t\t\t\t\t\tif (j == 0) j = 1;\n\t\t\t\t\t}\n\t\t\t\t\tif ((x.charAt((int) i) == 'e') || (x.charAt((int) i) == 'E')) {\n\t\t\t\t\t\tj = 2;\n\t\t\t\t\t\tif (x.charAt((int) (i + 1)) == '-') epos = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\twhile ((num.length() > 1) && (num.charAt(0) == '0'))\n\t\t\t\t\tnum = num.substring(1);\n\t\t\t\twhile ((num.length() > 1) && (num.charAt(num.length() - 1) == '0')) {\n\t\t\t\t\tnum = num.substring(0, num.length() - 1);\n\t\t\t\t\texp++;\n\t\t\t\t}\n\t\t\t\tif (num.equals(\"0\")) {\n\t\t\t\t\texp = 0;\n\t\t\t\t\tpos = true;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\twhile ((e.length() > 1) && (e.charAt(0) == '0'))\n\t\t\t\t\te = e.substring(1);\n\t\t\t\ttry {\n\t\t\t\t\tif (e != \"\") if (epos) exp += Long.parseLong(e);\n\t\t\t\t\telse\n\t\t\t\t\t\texp -= Long.parseLong(e);\n\t\t\t\t} catch (NumberFormatException exc) {\n\t\t\t\t\tif (!epos) {\n\t\t\t\t\t\tnum = \"0\";\n\t\t\t\t\t\texp = 0;\n\t\t\t\t\t\tpos = true;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new NotANumberException(\"Too long exponent\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tpublic Real() {\n\t\t\t}\n\n\t\t\tString toString(long mantissa) {\n\t\t\t\tString a = \"\", b = \"\";\n\t\t\t\tif (exp >= 0) {\n\t\t\t\t\ta = num;\n\t\t\t\t\tif (!pos) a = '-' + a;\n\t\t\t\t\tfor (long i = 0; i < exp; i++)\n\t\t\t\t\t\ta += '0';\n\t\t\t\t\tfor (long i = 0; i < mantissa; i++)\n\t\t\t\t\t\tb += '0';\n\t\t\t\t\tif (mantissa == 0) return a;\n\t\t\t\t\telse\n\t\t\t\t\t\treturn a + \".\" + b;\n\t\t\t\t} else {\n\t\t\t\t\tif (exp + length() <= 0) {\n\t\t\t\t\t\ta = \"0\";\n\t\t\t\t\t\tif (mantissa == 0) {\n\t\t\t\t\t\t\treturn a;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (mantissa < -(exp + length() - 1)) {\n\t\t\t\t\t\t\tfor (long i = 0; i < mantissa; i++)\n\t\t\t\t\t\t\t\tb += '0';\n\t\t\t\t\t\t\treturn a + \".\" + b;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tif (!pos) a = '-' + a;\n\t\t\t\t\t\t\tfor (long i = 0; i < mantissa; i++)\n\t\t\t\t\t\t\t\tif (i < -(exp + length())) b += '0';\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\tif (i + exp >= 0) b += '0';\n\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\tb += num.charAt((int) (i + exp + length()));\n\t\t\t\t\t\t\treturn a + \".\" + b;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (!pos) a = \"-\";\n\t\t\t\t\t\tfor (long i = 0; i < exp + length(); i++)\n\t\t\t\t\t\t\ta += num.charAt((int) i);\n\t\t\t\t\t\tif (mantissa == 0) return a;\n\t\t\t\t\t\tfor (long i = exp + length(); i < exp + length() + mantissa; i++)\n\t\t\t\t\t\t\tif (i < length()) b += num.charAt((int) i);\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\tb += '0';\n\t\t\t\t\t\treturn a + \".\" + b;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tboolean containsRepeats(int... num) {\n\t\t\tSet s = new TreeSet();\n\t\t\tfor (int d : num)\n\t\t\t\tif (!s.contains(d)) s.add(d);\n\t\t\t\telse\n\t\t\t\t\treturn true;\n\t\t\treturn false;\n\t\t}\n\n\t\tint[] rotateDice(int[] a, int n) {\n\t\t\tint[] c = new int[6];\n\t\t\tif (n == 0) {\n\t\t\t\tc[0] = a[1];\n\t\t\t\tc[1] = a[5];\n\t\t\t\tc[2] = a[2];\n\t\t\t\tc[3] = a[0];\n\t\t\t\tc[4] = a[4];\n\t\t\t\tc[5] = a[3];\n\t\t\t}\n\t\t\tif (n == 1) {\n\t\t\t\tc[0] = a[2];\n\t\t\t\tc[1] = a[1];\n\t\t\t\tc[2] = a[5];\n\t\t\t\tc[3] = a[3];\n\t\t\t\tc[4] = a[0];\n\t\t\t\tc[5] = a[4];\n\t\t\t}\n\t\t\tif (n == 2) {\n\t\t\t\tc[0] = a[3];\n\t\t\t\tc[1] = a[0];\n\t\t\t\tc[2] = a[2];\n\t\t\t\tc[3] = a[5];\n\t\t\t\tc[4] = a[4];\n\t\t\t\tc[5] = a[1];\n\t\t\t}\n\t\t\tif (n == 3) {\n\t\t\t\tc[0] = a[4];\n\t\t\t\tc[1] = a[1];\n\t\t\t\tc[2] = a[0];\n\t\t\t\tc[3] = a[3];\n\t\t\t\tc[4] = a[5];\n\t\t\t\tc[5] = a[2];\n\t\t\t}\n\t\t\tif (n == 4) {\n\t\t\t\tc[0] = a[0];\n\t\t\t\tc[1] = a[2];\n\t\t\t\tc[2] = a[3];\n\t\t\t\tc[3] = a[4];\n\t\t\t\tc[4] = a[1];\n\t\t\t\tc[5] = a[5];\n\t\t\t}\n\t\t\tif (n == 5) {\n\t\t\t\tc[0] = a[0];\n\t\t\t\tc[1] = a[4];\n\t\t\t\tc[2] = a[1];\n\t\t\t\tc[3] = a[2];\n\t\t\t\tc[4] = a[3];\n\t\t\t\tc[5] = a[5];\n\t\t\t}\n\t\t\treturn c;\n\t\t}\n\n\t\tint min(int... a) {\n\t\t\tint c = Integer.MAX_VALUE;\n\t\t\tfor (int d : a)\n\t\t\t\tif (d < c) c = d;\n\t\t\treturn c;\n\t\t}\n\n\t\tint max(int... a) {\n\t\t\tint c = Integer.MIN_VALUE;\n\t\t\tfor (int d : a)\n\t\t\t\tif (d > c) c = d;\n\t\t\treturn c;\n\t\t}\n\n\t\tint pos(int x) {\n\t\t\tif (x > 0) return x;\n\t\t\telse\n\t\t\t\treturn 0;\n\t\t}\n\n\t\tlong pos(long x) {\n\t\t\tif (x > 0) return x;\n\t\t\telse\n\t\t\t\treturn 0;\n\t\t}\n\n\t\tdouble maxD(double... a) {\n\t\t\tdouble c = Double.MIN_VALUE;\n\t\t\tfor (double d : a)\n\t\t\t\tif (d > c) c = d;\n\t\t\treturn c;\n\t\t}\n\n\t\tdouble minD(double... a) {\n\t\t\tdouble c = Double.MAX_VALUE;\n\t\t\tfor (double d : a)\n\t\t\t\tif (d < c) c = d;\n\t\t\treturn c;\n\t\t}\n\n\t\tint[] normalizeDice(int[] a) {\n\t\t\tint[] c = a.clone();\n\t\t\tif (c[0] != 0) if (c[1] == 0) c = rotateDice(c, 0);\n\t\t\telse\n\t\t\t\tif (c[2] == 0) c = rotateDice(c, 1);\n\t\t\t\telse\n\t\t\t\t\tif (c[3] == 0) c = rotateDice(c, 2);\n\t\t\t\t\telse\n\t\t\t\t\t\tif (c[4] == 0) c = rotateDice(c, 3);\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tif (c[5] == 0) c = rotateDice(rotateDice(c, 0), 0);\n\t\t\twhile (c[1] != min(c[1], c[2], c[3], c[4]))\n\t\t\t\tc = rotateDice(c, 4);\n\t\t\treturn c;\n\t\t}\n\n\t\tboolean sameDice(int[] a, int[] b) {\n\t\t\tfor (int i = 0; i < 6; i++)\n\t\t\t\tif (a[i] != b[i]) return false;\n\t\t\treturn true;\n\t\t}\n\n\t\tfinal double goldenRatio = (1 + Math.sqrt(5)) / 2;\n\t\tfinal double aGoldenRatio = (1 - Math.sqrt(5)) / 2;\n\n\t\tlong Fib(int n) {\n\t\t\tif (n < 0) if (n % 2 == 0) return -Math.round((pow(goldenRatio, -n) - pow(aGoldenRatio, -n)) / Math.sqrt(5));\n\t\t\telse\n\t\t\t\treturn -Math.round((pow(goldenRatio, -n) - pow(aGoldenRatio, -n)) / Math.sqrt(5));\n\t\t\treturn Math.round((pow(goldenRatio, n) - pow(aGoldenRatio, n)) / Math.sqrt(5));\n\t\t}\n\n\t\tclass japaneeseComparator implements Comparator {\n\t\t\t@Override\n\t\t\tpublic int compare(String a, String b) {\n\t\t\t\tint ai = 0, bi = 0;\n\t\t\t\tboolean m = false, ns = false;\n\t\t\t\tif (a.charAt(ai) <= '9' && a.charAt(ai) >= '0') {\n\t\t\t\t\tif (b.charAt(bi) <= '9' && b.charAt(bi) >= '0') m = true;\n\t\t\t\t\telse\n\t\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t\tif (b.charAt(bi) <= '9' && b.charAt(bi) >= '0') {\n\t\t\t\t\tif (a.charAt(ai) <= '9' && a.charAt(ai) >= '0') m = true;\n\t\t\t\t\telse\n\t\t\t\t\t\treturn 1;\n\t\t\t\t}\n\t\t\t\ta += \"!\";\n\t\t\t\tb += \"!\";\n\t\t\t\tint na = 0, nb = 0;\n\t\t\t\twhile (true) {\n\t\t\t\t\tif (a.charAt(ai) == '!') {\n\t\t\t\t\t\tif (b.charAt(bi) == '!') break;\n\t\t\t\t\t\treturn -1;\n\t\t\t\t\t}\n\t\t\t\t\tif (b.charAt(bi) == '!') {\n\t\t\t\t\t\treturn 1;\n\t\t\t\t\t}\n\t\t\t\t\tif (m) {\n\t\t\t\t\t\tint ab = -1, bb = -1;\n\t\t\t\t\t\twhile (a.charAt(ai) <= '9' && a.charAt(ai) >= '0') {\n\t\t\t\t\t\t\tif (ab == -1) ab = ai;\n\t\t\t\t\t\t\tai++;\n\t\t\t\t\t\t}\n\t\t\t\t\t\twhile (b.charAt(bi) <= '9' && b.charAt(bi) >= '0') {\n\t\t\t\t\t\t\tif (bb == -1) bb = bi;\n\t\t\t\t\t\t\tbi++;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tm = !m;\n\t\t\t\t\t\tif (ab == -1) {\n\t\t\t\t\t\t\tif (bb == -1) continue;\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\treturn 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (bb == -1) return -1;\n\t\t\t\t\t\twhile (a.charAt(ab) == '0' && ab + 1 != ai) {\n\t\t\t\t\t\t\tab++;\n\t\t\t\t\t\t\tif (!ns) na++;\n\t\t\t\t\t\t}\n\t\t\t\t\t\twhile (b.charAt(bb) == '0' && bb + 1 != bi) {\n\t\t\t\t\t\t\tbb++;\n\t\t\t\t\t\t\tif (!ns) nb++;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (na != nb) ns = true;\n\t\t\t\t\t\tif (ai - ab < bi - bb) return -1;\n\t\t\t\t\t\tif (ai - ab > bi - bb) return 1;\n\t\t\t\t\t\tfor (int i = 0; i < ai - ab; i++) {\n\t\t\t\t\t\t\tif (a.charAt(ab + i) < b.charAt(bb + i)) return -1;\n\t\t\t\t\t\t\tif (a.charAt(ab + i) > b.charAt(bb + i)) return 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tm = !m;\n\t\t\t\t\t\twhile (true) {\n\t\t\t\t\t\t\tif (a.charAt(ai) <= 'z' && a.charAt(ai) >= 'a' && b.charAt(bi) <= 'z' && b.charAt(bi) >= 'a') {\n\t\t\t\t\t\t\t\tif (a.charAt(ai) < b.charAt(bi)) return -1;\n\t\t\t\t\t\t\t\tif (a.charAt(ai) > b.charAt(bi)) return 1;\n\t\t\t\t\t\t\t\tai++;\n\t\t\t\t\t\t\t\tbi++;\n\t\t\t\t\t\t\t} else\n\t\t\t\t\t\t\t\tif (a.charAt(ai) <= 'z' && a.charAt(ai) >= 'a') return 1;\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\tif (b.charAt(bi) <= 'z' && b.charAt(bi) >= 'a') return -1;\n\t\t\t\t\t\t\t\t\telse\n\t\t\t\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\tif (na < nb) return 1;\n\t\t\t\tif (na > nb) return -1;\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\n\t\tRandom random = new Random();\n\t}\n\n\tvoid readIntArray(int[] a) throws IOException {\n\t\tfor (int i = 0; i < a.length; i++)\n\t\t\ta[i] = nextInt();\n\t}\n\n\tString readChars(int l) throws IOException {\n\t\tString r = \"\";\n\t\tfor (int i = 0; i < l; i++)\n\t\t\tr += (char) br.read();\n\t\treturn r;\n\t}\n\n\tclass myFraction {\n\t\tlong num = 0, den = 1;\n\n\t\tvoid reduce() {\n\t\t\tlong d = lib.gcd(num, den);\n\t\t\tnum /= d;\n\t\t\tden /= d;\n\t\t}\n\n\t\tmyFraction(long ch, long zn) {\n\t\t\tnum = ch;\n\t\t\tden = zn;\n\t\t\treduce();\n\t\t}\n\n\t\tmyFraction add(myFraction t) {\n\t\t\tlong nd = lib.lcm(den, t.den);\n\t\t\tmyFraction r = new myFraction(nd / den * num + nd / t.den * t.num, nd);\n\t\t\tr.reduce();\n\t\t\treturn r;\n\t\t}\n\n\t\tpublic String toString() {\n\t\t\treturn num + \"/\" + den;\n\t\t}\n\t\t\n\t\tint lev(String s1, String s2) {\n\t\t\tint[][] distance = new int[s1.length() + 1][s2.length() + 1];\n\t\t\tfor (int i = 0; i <= s1.length(); i++)\n\t distance[i][0] = i;\n\t\t\tfor (int j = 0; j <= s2.length(); j++)\n\t distance[0][j] = j;\n\t\t\tfor (int i = 1; i <= s1.length(); i++)\n\t for (int j = 1; j <= s2.length(); j++)\n\t distance[i][j] = Math.min(Math.min(distance[i - 1][j] + 1, distance[i][j - 1] + 1), distance[i - 1][j - 1] + ((s1.charAt(i - 1) == s2.charAt(j - 1)) ? 0 : 1));\n\t\t\treturn distance[s1.length()][s2.length()];\n\t\t}\n\t}\n\n\tclass myPoint {\n\t\tmyPoint(int a, int b) {\n\t\t\tx = a;\n\t\t\ty = b;\n\t\t}\n\n\t\tint x, y;\n\n\t\tboolean equals(myPoint a) {\n\t\t\tif (x == a.x && y == a.y) return true;\n\t\t\telse\n\t\t\t\treturn false;\n\t\t}\n\n\t\tpublic String toString() {\n\t\t\treturn x + \":\" + y;\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6b6c804eaf2daa34397c4e80fad52bca", "src_uid": "a705144ace798d6b41068aa284d99050", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "public class Main{\n public static void main(String [] args){\n\n byte i,k,j=0;\n int p,ka;\n byte n;\n Scanner sc=new Scanner(System.in);\n n=sc.nextByte();\n Byte vec[]=new Byte[n];\n\n for(i=0;imax){\n max=small;\n l=i+1;\n r=j+1;\n }\n }\n }\n System.out.println(max);\n System.out.println(l+\" \"+r);\n }\n public static int solve(char c[],int n){\n int dp[]=new int[n];\n dp[0]=c[0]=='('?1:-1;\n// System.out.print(dp[0]+\" \");\n for(int i=1;i=0;i--){\n min[i]=Math.min(dp[i],min[i+1]);\n }\n int ans=0;\n if(dp[0]==1&&dp[n-1]==0&&min[0]==0){\n ans++;\n }\n for(int i=0;i=dp[i]&&min2[i]>=dp[i]&&dp[n-1]==0){\n ans++;\n }\n }\n// System.out.println(ans);\n return ans;\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "18ea970c6c8bc32d1da8e14e8cffbbcf", "src_uid": "2d10668fcc2d8e90e102b043f5e0578d", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class D {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int r = sc.nextInt();\n int v = sc.nextInt();\n for (int i = 0; i < n; i++) {\n int s = sc.nextInt();\n int f = sc.nextInt();\n double d = f - s;\n double p = 2 * Math.PI * r;\n d %= p;\n double min = 0, max = 2 * Math.PI;\n for (int j = 0; j < 100; j++) {\n double mid = (min + max) / 2;\n double dis = (mid + Math.sin(mid)) * r * 2;\n if (dis < d)\n min = mid;\n else\n max = mid;\n }\n double t1 = (f - s - d) / v;\n double t2 = (min + max) * r / v;\n if ((min + max) / 2 > Math.PI)\n System.out.println(\" = \" + (min + max) / 2);\n System.out.println(t1 + t2);\n }\n sc.close();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3077d89c8246e54407ff53c09dd7ae98", "src_uid": "3882f2c02e83bd2d55de8004ea3bbd88", "difficulty": 2500.0} {"lang": "Java 11", "source_code": "import java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\n\npublic class Test {\n static PrintWriter writer =\n new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n int n, k;\n int N = 1 << 16;\n int[][] f = new int[5][N];\n int idx = 0;\n\n public static void main(String[] args) {\n Test te = new Test();\n te.start();\n writer.flush();\n }\n\n static int readInt() {\n int ans = 0;\n boolean neg = false;\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (c == '-') {\n start = true;\n neg = true;\n continue;\n } else if (c >= '0' && c <= '9') {\n start = true;\n ans = ans * 10 + c - '0';\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return neg ? -ans : ans;\n }\n\n static long readLong() {\n long ans = 0;\n boolean neg = false;\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (c == '-') {\n start = true;\n neg = true;\n continue;\n } else if (c >= '0' && c <= '9') {\n start = true;\n ans = ans * 10 + c - '0';\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return neg ? -ans : ans;\n }\n\n static String readString() {\n StringBuilder b = new StringBuilder();\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (Character.isLetterOrDigit(c)) {\n start = true;\n b.append((char) c);\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return b.toString();\n }\n\n static int readChars(char[] a, int off) {\n int cnt = 0;\n try {\n boolean start = false;\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (Character.isLetterOrDigit(c)) {\n start = true;\n a[off + cnt++] = (char) c;\n } else if (start) break;\n }\n } catch (IOException e) {\n }\n return cnt;\n }\n\n void solve(int n) {\n if (n == 1) {\n f[0][0] = 1;\n f[0][1] = 0;\n f[1][0] = 1;\n f[1][1] = 1;\n idx = 1;\n return;\n }\n if (n == 2) {\n f[1][0] = 1;\n f[1][1] = 1;\n f[2][0] = 1;\n f[2][1] = 3;\n f[2][2] = 1;\n idx = 2;\n return;\n }\n if (n % 2 == 1) {\n solve(n - 1);\n int nidx = (idx + 1) % 3, pidx = (idx + 3 - 1) % 3;\n f[nidx][0] = 1;\n for (int i = 1; i < N; i++)\n f[nidx][i] = Ntt.add(Ntt.add(f[idx][i], f[idx][i - 1]), f[pidx][i - 1]);\n idx = nidx;\n return;\n }\n\n solve(n / 2);\n int nidx = (idx + 1) % 3, pidx = (idx + 3 - 1) % 3, ppidx = 3;\n for (int i = 0; i + 1 < N; i++)\n f[ppidx][i] = Ntt.add(f[idx][i + 1], Ntt.M - Ntt.add(f[pidx][i], f[pidx][i + 1]));\n\n Ntt.fft(f[idx], 0, N);\n Ntt.fft(f[pidx], 0, N);\n Ntt.fft(f[ppidx], 0, N);\n\n for (int i = 0; i < N; i++) f[nidx][i] = Ntt.mul(f[idx][i], f[idx][i]);\n Ntt.ifft(f[nidx], 0, N);\n\n for (int i = 0; i < N; i++) f[4][i] = Ntt.mul(f[pidx][i], f[pidx][i]);\n Ntt.ifft(f[4], 0, N);\n for (int i = 1; i < N; i++) f[nidx][i] = Ntt.add(f[nidx][i], f[4][i - 1]);\n\n for (int i = 0; i < N; i++) f[idx][i] = Ntt.mul(f[idx][i], f[pidx][i]);\n Ntt.ifft(f[idx], 0, N);\n\n for (int i = 0; i < N; i++) f[pidx][i] = Ntt.mul(f[pidx][i], f[ppidx][i]);\n Ntt.ifft(f[pidx], 0, N);\n for (int i = 1; i < N; i++) f[idx][i] = Ntt.add(f[idx][i], f[pidx][i - 1]);\n\n idx = nidx;\n }\n\n void start() {\n n = readInt();\n k = readInt();\n solve(n);\n for (int i = 1; i <= k; i++) writer.print(f[idx][i] + \" \");\n }\n\n static class Ntt {\n static final int pri = 3;\n static final int M = 998_244_353;\n static int[] xy = new int[2];\n\n static int pmod(int b, int e) {\n int i = 1 << 31;\n int r = 1;\n while (i != 0) {\n r = mul(r, r);\n if ((e & i) != 0) r = mul(r, b);\n i >>>= 1;\n }\n return r;\n }\n\n static void fft(int[] a, int off, int len) {\n for (int i = 0; i < len; i++) {\n int j = i, x = 0, y = len - 1;\n while (y > 0) {\n x = (x << 1) + (j & 1);\n j >>>= 1;\n y >>>= 1;\n }\n if (i < x) {\n int t = a[off + i];\n a[off + i] = a[off + x];\n a[off + x] = t;\n }\n }\n for (int i = 1; i < len; i *= 2) {\n int s = pmod(pri, (M - 1) / 2 / i);\n for (int j = 0; j < len; j += 2 * i) {\n int w = 1;\n for (int k = 0; k < i; k++) {\n int u = a[off + j + k], v = mul(a[off + j + k + i], w);\n a[off + j + k] = add(u, v);\n a[off + j + k + i] = add(u, M - v);\n w = mul(w, s);\n }\n }\n }\n }\n\n static void ifft(int[] a, int off, int len) {\n int ll = 1, rr = len - 1;\n while (ll < rr) {\n int t = a[off + ll];\n a[off + (ll++)] = a[off + rr];\n a[off + (rr--)] = t;\n }\n fft(a, off, len);\n int inv = pmod(len, M - 2);\n for (int i = 0; i < len; i++) a[off + i] = mul(inv, a[off + i]);\n }\n\n static int add(int a, int b) {\n return (a + b) % M;\n }\n\n static int mul(int a, int b) {\n return (int) ((a * (long) b) % M);\n }\n\n static int inverse(int a, int b) {\n if (b == 0) {\n xy[0] = 1;\n xy[1] = 0;\n return a;\n }\n int d = inverse(b, a % b);\n swap(xy, 0, 1);\n xy[1] -= a / b * xy[0];\n return d;\n }\n\n static void swap(int[] a, int i, int j) {\n int t = a[i];\n a[i] = a[j];\n a[j] = t;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8bb860778e149a6ce48b9ed7b4dc1709", "src_uid": "266cc96acf6287f92a3bb0f8eccc5cf1", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "import java.util.*\n\npublic class Solution {\n\npublic static boolean checkTeams(int[] scores) {\n int sum = 0;\n for (int score:scores){\n sum += score;\n }\n if (sum == 0) {\n return true;\n }\n int teamScore = sum >> 1;\n if (sum % 2 == 1) {\n return false;\n }\n\n for (int i = 0; i < scores.length; i++) {\n if (scores[i] >= teamScore) {\n return false;\n }\n }\n\n int tempSum = scores[0];\n int count = 1;\n for (int j = 1; j < scores.length; j++) {\n tempSum += scores[j];\n count++;\n if((count<3 && tempSum >= teamScore) || (count == 3 && tempSum != teamScore))\n {\n tempSum -= scores[j];\n count--;\n }\n \n if(tempSum == teamScore && count == 3)\n {\n return true;\n }\n }\n return false;\n\n }\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int[] scores = new int[6];\n for (int i = 0; i < 6; i++) {\n scores[i] = in.nextInt();\n }\n System.out.println(checkTeams(scores)?\"Yes\":\"NO\");\n in.close();\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9efed29dc53f7c639d165c85c3aa5fef", "src_uid": "2acf686862a34c337d1d2cbc0ac3fd11", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class code\n{\n public static void main(String arg[])\n {\n Scanner ob=new Scanner(System.in);\n String t=ob.nextInt();\n String s=\"\";\n int mid=(t.length()-1)/2;\n s=t.charAt(mid);\n int x=1;\n while((mid+x) 0) {\n r = (r * 10) + (x % 10);\n x /= 10;\n y = (y * 10) % p;\n }\n y = (y + r) % p;\n sum = (sum + y) % p;\n }\n System.out.println(sum);\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a00cdc6310d76a4eade105fe70de1d58", "src_uid": "00e90909a77ce9e22bb7cbf1285b0609", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "\n\nimport java.util.Scanner;\n\npublic class hack {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint a = sc.nextInt();\n\t\tint b = sc.nextInt();\n\t\tint[] arr = new int[n];\n\t\tfor(int i = 0;i= 0) cayley = ((k + 2) * pow(n, n - k - 3)) % mod; else cayley = 1;\n long total = (((middle * sum) % mod) * cayley) % mod;\n total = (total * pow(m, n - k - 2));\n ans = (ans + total) % mod;\n }\n out.println(ans);\n out.close();\n }\n\n static long[] fac;\n static long mod = (int) 1e9 + 7;\n\n static void initFac(long n) {\n fac[0] = 1;\n for (int i = 1; i <= n; i++) {\n fac[i] = (fac[i - 1] * i) % mod;\n }\n }\n\n static long exponentiation(long base, long exp)\n {\n long t = 1L;\n while (exp > 0) {\n\n // for cases where exponent\n // is not an even value\n if (exp % 2 != 0)\n t = (t * base) % mod;\n\n base = (base * base) % mod;\n exp /= 2;\n }\n return t % mod;\n }\n\n static long nck(int n, int k) {\n if (n < k)\n return 0;\n long den = inv((int) (fac[k] * fac[n - k] % mod));\n return fac[n] * den % mod;\n }\n\n static long pow(long b, long e) {\n long ans = 1;\n while (e > 0) {\n if (e % 2 == 1)\n ans = ans * b % mod;\n e >>= 1;\n b = b * b % mod;\n }\n return ans;\n }\n\n static long inv(int x) {\n return pow(x, mod - 2);\n }\n\n\n\n //-----------MyScanner class for faster input----------\n public static class MyScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public MyScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n\n\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4c4195929c0db950d100f84210e01551", "src_uid": "728fe302b8b18e33f15f6e702e332cde", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author 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 ProblemBMancala solver = new ProblemBMancala();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class ProblemBMancala {\n public static final int HOLES = 14;\n\n public void solve(int testNumber, InputReader reader, OutputWriter writer) {\n\n long tmpHoles[];\n long holes[] = new long[HOLES];\n for (int i = 0; i < HOLES; i++) {\n holes[i] = reader.readLong();\n }\n long max = 0;\n for (int i = 0; i < HOLES; i++) {\n //-> checking array copy... :D\n// tmpHoles = holes.clone();\n// tmpHoles = Arrays.copyOf(holes, holes.length);\n tmpHoles = Arrays.copyOfRange(holes, 0, holes.length);\n\n tmpHoles[i] = 0;//-> WA cz: I didn't add this stupid line...\n for (int j = 0; j < HOLES; j++) {\n tmpHoles[j] += holes[i] / HOLES;\n }\n long stones = holes[i] % HOLES;\n int indx = i + 1;\n while (stones-- > 0) {\n if (indx == HOLES) {\n indx = 0;\n }\n ++tmpHoles[indx++];\n }\n long sum = 0;\n for (int j = 0; j < HOLES; j++) {\n if ((tmpHoles[j] & 1) == 0) {\n sum += tmpHoles[j];\n }\n }\n if (sum > max) max = sum;\n }\n writer.print(max);\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void 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 close() {\n writer.flush();\n writer.close();\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 long readLong() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public 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\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ca94af1a613129598e357a7cd69e2683", "src_uid": "1ac11153e35509e755ea15f1d57d156b", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Bishwock {\n\n\tpublic static void main(String[] args) {\n\t\t\n\t\tScanner s = new Scanner(System.in);\n\t\tString s1 = s.nextLine();\n\t\tString s2 = s.nextLine();\n\t\tInteger n = s1.length()-1;\n\t\tInteger n1=0,n2 =0;\n\t\tInteger no = 0;\n\t\twhile(n1n2) {\n\t\t\t\tif(s1.charAt(n1)=='0') {\n\t\t\t\t\tif(s2.charAt(n1)=='0') {\n\t\t\t\t\t\tif(n2 (x + y) % IBIG);\n for(int j = 0; j < n; ++j) {\n int dist = abs(j - b) - 1;\n dp[i][j] = (bit.qry(min(n, j + dist + 1)) - bit.qry(max(0, j - dist)) - dp[i - 1][j] + IBIG) % IBIG;\n }\n }\n prln(dp[k - 1][a]);\n close();\n }\n\n static int solve(int x, int q) {\n if(dp[q][x] > 0) {\n return dp[q][x];\n } else if(q == 0) {\n int dist = abs(x - b) - 1;\n return dp[q][x] = min(n - 1, x + dist) - max(0, x - dist);\n } else {\n int dist = abs(x - b) - 1;\n for(int i = max(0, x - dist); i <= min(n - 1, x + dist); ++i) {\n if(i != x) {\n dp[q][x] = (dp[q][x] + solve(i, q - 1)) % IBIG;\n }\n }\n return dp[q][x];\n }\n }\n\n @FunctionalInterface\n interface IntOperator {\n int merge(int a, int b);\n }\n\n static class BIT {\n IntOperator op;\n int n, bit[];\n\n BIT(int size, IntOperator operator) {\n bit = new int[n = size + 1];\n op = operator;\n }\n\n BIT(int[] arr, IntOperator operator) {\n bit = new int[(n = arr.length) + 1];\n op = operator;\n for(int i = 0; i < n; ++i) upd(i, arr[i]);\n ++n;\n }\n\n void upd(int i, int x) {\n ++i;\n while(i < n) {\n bit[i] = op.merge(bit[i], x);\n i += i & (-i);\n }\n }\n\n int qry(int i) {\n int ans = 0;\n while(i > 0) {\n ans = op.merge(ans, bit[i]);\n i -= i & (-i);\n }\n return ans;\n }\n }\n\n static BufferedReader __in = new BufferedReader(new InputStreamReader(System.in));\n static PrintWriter __out = new PrintWriter(new OutputStreamWriter(System.out));\n static StringTokenizer input;\n static Random rand = new Random();\n\n // references\n // IBIG = 1e9 + 7\n // IRAND ~= 3e8\n // IMAX ~= 2e10\n // LMAX ~= 9e18\n // constants\n static final int IBIG = 1000000007;\n static final int IRAND = 327859546;\n static final int IMAX = 2147483647;\n static final int IMIN = -2147483648;\n static final long LMAX = 9223372036854775807L;\n static final long LMIN = -9223372036854775808L;\n // util\n static int minof(int a, int b, int c) {return min(a, min(b, c));}\n static int minof(int... x) {return x.length == 1 ? x[0] : x.length == 2 ? min(x[0], x[1]) : min(x[0], minstarting(1, x));}\n static int minstarting(int offset, int... x) {assert x.length > 2; return offset == x.length - 2 ? min(x[offset], x[offset + 1]) : min(x[offset], minstarting(offset + 1, x));}\n static long minof(long a, long b, long c) {return min(a, min(b, c));}\n static long minof(long... x) {return x.length == 1 ? x[0] : x.length == 2 ? min(x[0], x[1]) : min(x[0], minstarting(1, x));}\n static long minstarting(int offset, long... x) {assert x.length > 2; return offset == x.length - 2 ? min(x[offset], x[offset + 1]) : min(x[offset], minstarting(offset + 1, x));}\n static int maxof(int a, int b, int c) {return max(a, max(b, c));}\n static int maxof(int... x) {return x.length == 1 ? x[0] : x.length == 2 ? max(x[0], x[1]) : max(x[0], maxstarting(1, x));}\n static int maxstarting(int offset, int... x) {assert x.length > 2; return offset == x.length - 2 ? max(x[offset], x[offset + 1]) : max(x[offset], maxstarting(offset + 1, x));}\n static long maxof(long a, long b, long c) {return max(a, max(b, c));}\n static long maxof(long... x) {return x.length == 1 ? x[0] : x.length == 2 ? max(x[0], x[1]) : max(x[0], maxstarting(1, x));}\n static long maxstarting(int offset, long... x) {assert x.length > 2; return offset == x.length - 2 ? max(x[offset], x[offset + 1]) : max(x[offset], maxstarting(offset + 1, x));}\n static int powi(int a, int b) {if(a == 0) return 0; int ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}\n static long powl(long a, int b) {if(a == 0) return 0; long ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}\n static int floori(double d) {return (int)d;}\n static int ceili(double d) {return (int)ceil(d);}\n static long floorl(double d) {return (long)d;}\n static long ceill(double d) {return (long)ceil(d);}\n static void shuffle(int[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); int swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}\n static void shuffle(long[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); long swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}\n static void shuffle(double[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); double swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}\n static void shuffle(T[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); T swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}\n static void sort(int[] a) {shuffle(a); Arrays.sort(a);}\n static void sort(long[] a) {shuffle(a); Arrays.sort(a);}\n static void sort(double[] a) {shuffle(a); Arrays.sort(a);}\n static void qsort(int[] a) {Arrays.sort(a);}\n static void qsort(long[] a) {Arrays.sort(a);}\n static void qsort(double[] a) {Arrays.sort(a);}\n static int randInt(int min, int max) {return rand.nextInt(max - min + 1) + min;}\n // input\n static void r() throws IOException {input = new StringTokenizer(__in.readLine());}\n static int ri() throws IOException {return Integer.parseInt(__in.readLine());}\n static long rl() throws IOException {return Long.parseLong(__in.readLine());}\n static int[] ria(int n) throws IOException {int[] a = new int[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Integer.parseInt(input.nextToken()); return a;}\n static long[] rla(int n) throws IOException {long[] a = new long[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Long.parseLong(input.nextToken()); return a;}\n static char[] rcha() throws IOException {return __in.readLine().toCharArray();}\n static String rline() throws IOException {return __in.readLine();}\n static int rni() throws IOException {input = new StringTokenizer(__in.readLine()); return Integer.parseInt(input.nextToken());}\n static int ni() {return Integer.parseInt(input.nextToken());}\n static long rnl() throws IOException {input = new StringTokenizer(__in.readLine()); return Long.parseLong(input.nextToken());}\n static long nl() {return Long.parseLong(input.nextToken());}\n // output\n static void pr(int i) {__out.print(i);}\n static void prln(int i) {__out.println(i);}\n static void pr(long l) {__out.print(l);}\n static void prln(long l) {__out.println(l);}\n static void pr(double d) {__out.print(d);}\n static void prln(double d) {__out.println(d);}\n static void pr(char c) {__out.print(c);}\n static void prln(char c) {__out.println(c);}\n static void pr(char[] s) {__out.print(new String(s));}\n static void prln(char[] s) {__out.println(new String(s));}\n static void pr(String s) {__out.print(s);}\n static void prln(String s) {__out.println(s);}\n static void pr(Object o) {__out.print(o);}\n static void prln(Object o) {__out.println(o);}\n static void prln() {__out.println();}\n static void pryes() {__out.println(\"yes\");}\n static void pry() {__out.println(\"Yes\");}\n static void prY() {__out.println(\"YES\");}\n static void prno() {__out.println(\"no\");}\n static void prn() {__out.println(\"No\");}\n static void prN() {__out.println(\"NO\");}\n static void pryesno(boolean b) {__out.println(b ? \"yes\" : \"no\");};\n static void pryn(boolean b) {__out.println(b ? \"Yes\" : \"No\");}\n static void prYN(boolean b) {__out.println(b ? \"YES\" : \"NO\");}\n static void prln(int... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);}\n static void prln(long... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);}\n static void prln(Collection c) {int n = c.size() - 1; Iterator iter = c.iterator(); for(int i = 0; i < n; __out.print(iter.next()), __out.print(' '), ++i); if(n >= 0) __out.println(iter.next());}\n static void h() {__out.println(\"hlfd\");}\n static void flush() {__out.flush();}\n static void close() {__out.close();}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "120a5faf810f787a5c51413019a66ea4", "src_uid": "142b06ed43b3473513995de995e19fc3", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "/*\n * Author: Abhi Sapariya\n */\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\nimport java.text.DecimalFormat;\n\npublic class Solution{\n\t\n\tstatic long mod =(long)Math.pow(10,9)+7;\n\tstatic int INF = Integer.MAX_VALUE;\n\tstatic InputReader in;\n static PrintWriter out;\n\t\n\tpublic static void main(String[] args) {\n\t\t\n\t\tin = new InputReader(System.in);\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\t//CODE\n\t\tSystem.out.println(\"Testing\");\n\t\t\n\n\t out.close();\n\t}\n\t\n\tstatic long[] generate(int n, int[] arr, long p, long k, long q, int m){\n\t\tlong[] x = new long[1000000];\n\t\tx[0] = 0;\n\t\tfor(int i=1; i 0) {\n\t if (exponent % 2 == 1)\n\t result = (result * base) % modulus;\n\t exponent = exponent >> 1;\n\t base = (base * base) % modulus;\n\t }\n\t return result;\n\t}\n\t\n static long power(long base, long exponent, long modulus){\n\t long result = 1L;\n\t while (exponent > 0) {\n\t if (exponent % 2L == 1L)\n\t result = (result * base) % modulus;\n\t exponent = exponent >> 1;\n\t base = (base * base) % modulus;\n\t }\n\t return result;\n\t}\n \n static class Pair implements Comparable{\n\n \tint x;\n \tint y;\n \t\n \tpublic Pair(int x, int y){\n \t\tthis.x = x;\n \t\tthis.y = y;\n \t}\n \t\n \t// Ascending First X then Y\n\t\t@Override\n\t\tpublic int compareTo(Pair p) {\n\t\t\tif( x == p.x )\n\t\t\t\treturn y-p.y;\n\t\t\treturn x-p.x;\n\t\t}\n\t\t\n\t\t@Override\n\t\tpublic String toString(){\n\t\t\treturn \"(\" + x + \",\" + y + \")\";\n\t\t}\n }\n \n // This class represents a directed graph using adjacency list\n\t// representation\n\tclass Graph {\n\t\tprivate int V; // No. of vertices\n\n\t\t// Array of lists for Adjacency List Representation\n\t\tprivate LinkedList adj[];\n\n\t\t// Constructor\n\t\tGraph(int v) {\n\t\t\tV = v;\n\t\t\tadj = new LinkedList[v];\n\t\t\tfor (int i = 0; i < v; ++i)\n\t\t\t\tadj[i] = new LinkedList();\n\t\t}\n\n\t\t//Function to add an edge into the graph\n\t\tvoid addEdge(int v, int w) {\n\t\t\tadj[v].add(w); // Add w to v's list.\n\t\t}\n\n\t\t// A function used by DFS\n\t\tvoid DFSUtil(int v, boolean visited[]) {\n\t\t\t// Mark the current node as visited and print it\n\t\t\tvisited[v] = true;\n\t\t\tSystem.out.print(v + \" \");\n\n\t\t\t// Recur for all the vertices adjacent to this vertex\n\t\t\tIterator i = adj[v].listIterator();\n\t\t\twhile (i.hasNext()) {\n\t\t\t\tint n = i.next();\n\t\t\t\tif (!visited[n])\n\t\t\t\t\tDFSUtil(n, visited);\n\t\t\t}\n\t\t}\n\n\t\t// The function to do DFS traversal. It uses recursive DFSUtil()\n\t\tvoid DFS(int v) {\n\t\t\t// Mark all the vertices as not visited(set as\n\t\t\t// false by default in java)\n\t\t\tboolean visited[] = new boolean[V];\n\n\t\t\t// Call the recursive helper function to print DFS traversal\n\t\t\tDFSUtil(v, visited);\n\t\t}\n\t}\n \n\t// Class for primes utilities\n\tstatic class Primes{\n\t\t\n\t //for marking all prime numbers greater than 1 and less than equal to N\n\t boolean[] sieveOfEratosthenes(int n) {\n\n\t\t\tboolean prime[] = new boolean[n];\n\t\t\t// Create a boolean array \"prime[0..n]\" and initialize\n\t\t\t// all entries it as true. A value in prime[i] will\n\t\t\t// finally be false if i is Not a prime, else true.\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tprime[i] = true;\n\n\t\t\tfor (int p = 2; p * p <= n; p++) {\n\t\t\t\t// If prime[p] is not changed, then it is a prime\n\t\t\t\tif (prime[p] == true) {\n\t\t\t\t\t// Update all multiples of p\n\t\t\t\t\tfor (int i = p * 2; i <= n; i += p)\n\t\t\t\t\t\tprime[i] = false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\treturn prime;\n\t\t}\n\t\t\n\t ArrayList primeFactors(long n){\n\t \tArrayList ans = new ArrayList();\n\t \t// Print the number of 2s that divide n\n\t while (n%2L==0L)\n\t {\n\t ans.add(2L);\n\t n /= 2L;\n\t }\n\t \n\t // n must be odd at this point. So we can\n\t // skip one element (Note i = i +2)\n\t for (long i = 3; i <= Math.sqrt(n); i+= 2L)\n\t {\n\t // While i divides n, print i and divide n\n\t while (n%i == 0)\n\t {\n\t \tans.add(i);\n\t n /= i;\n\t }\n\t }\n\t \n\t // This condition is to handle the case whien\n\t // n is a prime number greater than 2\n\t if (n > 2)\n\t ans.add(n);\n\t return ans;\n\t }\n\t\n\t //Minimum prime factors of number till n\n\t\tint[] minimumPrimeFactors(int n){\n\t\t\tint[] minPrime = new int[n+1];\n\t\t\tminPrime[1]=1;\n\t for (int i = 2; i * i <= n; ++i) {\n\t if (minPrime[i] == 0) { //If i is prime\n\t for (int j = i * i; j <= n; j += i) {\n\t if (minPrime[j] == 0) {\n\t minPrime[j] = i;\n\t }\n\t }\n\t }\n\t }\n\t for (int i = 2; i <= n; ++i) {\n\t if (minPrime[i] == 0) {\n\t minPrime[i] = i;\n\t }\n\t }\n\t return minPrime;\n\t\t}\n\t\t\n\t // isPrime\n\t\tboolean isPrime(long n) {\n\t\t\tif(n < 2L) return false;\n\t\t\tif(n == 2L || n == 3L) return true;\n\t\t\tif(n%2L == 0 || n%3L == 0) return false;\t\n\t\t\tlong sqrtN = (long)Math.sqrt(n)+1L;\n\t\t\tfor(long i = 6L; i <= sqrtN; i += 6L) {\n\t\t\t\tif(n%(i-1) == 0 || n%(i+1) == 0) return false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t}\n\t\n // Binary indexed Tree parameters (arr,arr.length)\n static class BITree {\n\n\t\tint[] tree;\n\n\t\tpublic BITree(int arr[], int n) {\n\t\t\ttree = new int[n + 1];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tupdate(i, arr[i]);\n\t\t\t}\n\t\t}\n\n\t\tpublic void update(int x, int val) {\n\t\t\tx++;\n\t\t\twhile (x < tree.length) {\n\t\t\t\ttree[x] += val;\n\t\t\t\tx = next(x);\n\t\t\t}\n\t\t}\n\n\t\tpublic int sum(int x) {\n\t\t\tx++;\n\t\t\tint ans = 0;\n\t\t\twhile (x > 0) {\n\t\t\t\tans += tree[x];\n\t\t\t\tx = parent(x);\n\t\t\t}\n\t\t\treturn ans;\n\t\t}\n\n\t\tpublic int parent(int x) {\n\t\t\treturn x - (x & -x);\n\t\t}\n\n\t\tpublic int next(int x) {\n\t\t\treturn x + (x & -x);\n\t\t}\n\n\t}\n \n // Range minimum query Segment Tree parameters - (arr,arr.length)\n static class SegmentTree {\n\n\t\tstatic int[] segT;\n\n\t\tpublic SegmentTree(int arr[], int n) {\n\t\t\tint nearPow = (int) (Math.ceil(Math.log(n) / Math.log(2)));\n\t\t\tint len = 2 * ((int) Math.pow(2, nearPow)) - 1;\n\t\t\tsegT = new int[len];\n\t\t\tconstructTree(arr, 0, n - 1, 0);\n\t\t}\n\n\t\tpublic void constructTree(int arr[], int low, int high, int pos) {\n\t\t\tif (low == high) {\n\t\t\t\tsegT[pos] = arr[low];\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tint mid = (low + high) / 2;\n\t\t\tconstructTree(arr, low, mid, 2 * pos + 1);\n\t\t\tconstructTree(arr, mid + 1, high, 2 * pos + 2);\n\t\t\tsegT[pos] = Math.min(segT[2 * pos + 1], segT[2 * pos + 2]);\n\t\t}\n\n\t\tpublic int rmq(int low, int high, int n) {\n\t\t\treturn rmq(0, n - 1, low, high, 0);\n\t\t}\n\n\t\tpublic int rmq(int low, int high, int qlow, int qhigh, int pos) {\n\n\t\t\tif (qlow <= low && qhigh >= high) {\n\t\t\t\treturn segT[pos];\n\t\t\t}\n\t\t\tif (high < qlow || qhigh < low) {\n\t\t\t\treturn Integer.MAX_VALUE;\n\t\t\t}\n\t\t\tint mid = (low + high) / 2;\n\t\t\treturn Math.min(rmq(low, mid, qlow, qhigh, 2 * pos + 1),\n\t\t\t\t\trmq(mid + 1, high, qlow, qhigh, 2 * pos + 2));\n\t\t}\n\n\t} \n \n // Disjoint Union Set with Path Compression\n static class DUS{\n \tint p;\n \tint r;\n \tDUS set[];\n \t\n \tpublic DUS(int pr, int rk){\n \t\tp = pr;\n \t\tr = rk;\n \t}\n \t\n \tpublic DUS(int n){\n \t\tset = new DUS[n+1];\n \t\tfor(int i=0; i set[py].r){\n \t\t\tset[py].p = px;\n \t\t}\n \t\telse if(set[py].r > set[px].r){\n \t\t\tset[px].p = py;\n \t\t}\n \t\telse{\n \t\t\tset[py].p = px;\n \t\t\tset[px].r++;\n \t\t}\n \t}\n }\n\t\n\t//Class for fibonacci utilities\n\tstatic class fibonacci {\n\t\t\n\t\t//Nth fibonacci number in log(n)\n\t\tpublic static long fib(long n, long mod) {\n\t\t\tlong F[][] = new long[][] { { 1, 1 }, { 1, 0 } };\n\t\t\tif (n == 0l)\n\t\t\t\treturn 0l;\n\t\t\tpower(F, n - 1, mod);\n\n\t\t\treturn F[0][0] % mod;\n\t\t}\n\n\t\tpublic static void multiply(long F[][], long M[][], long mod) {\n\t\t\tlong x = (((F[0][0]) * (M[0][0])) % mod + ((F[0][1]) * (M[1][0]))\n\t\t\t\t\t% mod)\n\t\t\t\t\t% mod;\n\t\t\tlong y = (((F[0][0]) * (M[0][1])) % mod + ((F[0][1]) * (M[1][1]))\n\t\t\t\t\t% mod)\n\t\t\t\t\t% mod;\n\t\t\tlong z = (((F[1][0]) * (M[0][0])) % mod + ((F[1][1]) * (M[1][0]))\n\t\t\t\t\t% mod)\n\t\t\t\t\t% mod;\n\t\t\tlong w = (((F[1][0]) * (M[0][1])) % mod + ((F[1][1]) * (M[1][1]))\n\t\t\t\t\t% mod)\n\t\t\t\t\t% mod;\n\n\t\t\tF[0][0] = x;\n\t\t\tF[0][1] = y;\n\t\t\tF[1][0] = z;\n\t\t\tF[1][1] = w;\n\t\t}\n\n\t\t/* Optimized version of power() in method 4 */\n\t\tpublic static void power(long F[][], long n, long mod) {\n\t\t\tif (n == 0l || n == 1l)\n\t\t\t\treturn;\n\t\t\tlong M[][] = new long[][] { { 1l, 1l }, { 1l, 0l } };\n\n\t\t\tpower(F, n / 2l, mod);\n\t\t\tmultiply(F, F, mod);\n\t\t\tif (n % 2l != 0l)\n\t\t\t\tmultiply(F, M, mod);\n\t\t}\n\t\t\n\t\tstatic boolean isPerfectSquare(int x)\n\t\t{\n\t\t int s = sqrt(x);\n\t\t return (s*s == x);\n\t\t}\n\t\t \n\t\t// Returns true if n is a Fibinacci Number, else false\n\t\tstatic boolean isFibonacci(int n)\n\t\t{\n\t\t // n is Fibinacci if one of 5*n*n + 4 or 5*n*n - 4 or both\n\t\t // is a perferct square\n\t\t return isPerfectSquare(5*n*n + 4) ||\n\t\t isPerfectSquare(5*n*n - 4);\n\t\t}\n\t}\n\t\n\tstatic long modInverse(long A, long M)\n\t{\n\t\tlong x=extendedEuclid(A,M)[0];\n\t\treturn (x%M+M)%M; //x may be negative\n\t}\n\t\n\t\n\tstatic long[] extendedEuclid(long A, long B) {\n\t\tif(B == 0) {\n\t\t\tlong d = A;\n\t\t\tlong x = 1;\n\t\t\tlong y = 0;\n\t\t\treturn new long[]{x,y,d};\n\t\t}\n\t\telse {\n\t\t\tlong arr[]=extendedEuclid(B, A%B);\n\t\t\tlong temp = arr[0];\n\t\t\tarr[0] = arr[1];\n\t\t\tarr[1] = temp - (A/B)*arr[1];\n\t\t\treturn arr;\n\t\t}\n\t}\n\t\n\tpublic void printArr(int[] arr){\n\t\tfor(int i = 0; i < arr.length; i++){\n\t\t\tout.print(arr[i] + \" \");\n\t\t}\n\t\tout.println();\n\t}\n\t\n\tpublic void print2DArr(int[][] arr){\n\t\tfor( int i = 0; i < arr.length; i++){\n\t\t\tfor ( int j = 0; j < arr[0].length; j++){\n\t\t\t\tout.print(arr[i][j] + \" \");\n\t\t\t}\n\t\t\tout.println();\n\t\t}\n\t}\n \n\tstatic class InputReader {\n private final InputStream stream;\n private final byte[] buf = new byte[8192];\n private int curChar, numChars;\n private SpaceCharFilter filter;\n \n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n \n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n \n public String nextLine() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isEndOfLine(c));\n return res.toString();\n }\n \n public String readString() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n \n public long nextLong() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n \n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n \n public int[] nextIntArray(int n) {\n int[] arr = new int[n];\n for (int i = 0; i < n; i++) {\n arr[i] = nextInt();\n }\n return arr;\n }\n \n public long[] nextLongArray(int n) {\n long[] arr = new long[n];\n for (int i = 0; i < n; i++) {\n arr[i] = nextLong();\n }\n return arr;\n }\n \n public int[][] nextInt2DArray(int n, int m){\n \tint[][] arr = new int[n][m];\n \tfor (int i = 0; i < n; i++){\n \t\tfor(int j = 0; j < m; j++){\n \t\t\tarr[i][j] = nextInt();\n \t\t}\n \t}\n \treturn arr;\n }\n \n public long[][] nextLong2DArray(int n, int m){\n \tlong[][] arr = new long[n][m];\n \tfor (int i = 0; i < n; i++){\n \t\tfor(int j = 0; j < m; j++){\n \t\t\tarr[i][j] = nextLong();\n \t\t}\n \t}\n \treturn arr;\n }\n \n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n \n private boolean isEndOfLine(int c) {\n return c == '\\n' || c == '\\r' || c == -1;\n }\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n\t}\n}harFilter {\n public boolean isSpaceChar(int ch);\n }\n\t}\n}/*\n * Author: Abhi Sapariya\n */\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\nimport java.text.DecimalFormat;\n\npublic class Solution{\n\t\n\tstatic long mod =(long)Math.pow(10,9)+7;\n\tstatic int INF = Integer.MAX_VALUE;\n\tstatic InputReader in;\n static PrintWriter out;\n\t\n\tpublic static void main(String[] args) {\n\t\t\n\t\tin = new InputReader(System.in);\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\t//CODE\n\t\tSystem.out.println(\"Testing\");\n\t\t\n\n\t out.close();\n\t}\n\t\n\tstatic long[] generate(int n, int[] arr, long p, long k, long q, int m){\n\t\tlong[] x = new long[1000000];\n\t\tx[0] = 0;\n\t\tfor(int i=1; i 0) {\n\t if (exponent % 2 == 1)\n\t result = (result * base) % modulus;\n\t exponent = exponent >> 1;\n\t base = (base * base) % modulus;\n\t }\n\t return result;\n\t}\n\t\n static long power(long base, long exponent, long modulus){\n\t long result = 1L;\n\t while (exponent > 0) {\n\t if (exponent % 2L == 1L)\n\t result = (result * base) % modulus;\n\t exponent = exponent >> 1;\n\t base = (base * base) % modulus;\n\t }\n\t return result;\n\t}\n \n static class Pair implements Comparable{\n\n \tint x;\n \tint y;\n \t\n \tpublic Pair(int x, int y){\n \t\tthis.x = x;\n \t\tthis.y = y;\n \t}\n \t\n \t// Ascending First X then Y\n\t\t@Override\n\t\tpublic int compareTo(Pair p) {\n\t\t\tif( x == p.x )\n\t\t\t\treturn y-p.y;\n\t\t\treturn x-p.x;\n\t\t}\n\t\t\n\t\t@Override\n\t\tpublic String toString(){\n\t\t\treturn \"(\" + x + \",\" + y + \")\";\n\t\t}\n }\n \n // This class represents a directed graph using adjacency list\n\t// representation\n\tclass Graph {\n\t\tprivate int V; // No. of vertices\n\n\t\t// Array of lists for Adjacency List Representation\n\t\tprivate LinkedList adj[];\n\n\t\t// Constructor\n\t\tGraph(int v) {\n\t\t\tV = v;\n\t\t\tadj = new LinkedList[v];\n\t\t\tfor (int i = 0; i < v; ++i)\n\t\t\t\tadj[i] = new LinkedList();\n\t\t}\n\n\t\t//Function to add an edge into the graph\n\t\tvoid addEdge(int v, int w) {\n\t\t\tadj[v].add(w); // Add w to v's list.\n\t\t}\n\n\t\t// A function used by DFS\n\t\tvoid DFSUtil(int v, boolean visited[]) {\n\t\t\t// Mark the current node as visited and print it\n\t\t\tvisited[v] = true;\n\t\t\tSystem.out.print(v + \" \");\n\n\t\t\t// Recur for all the vertices adjacent to this vertex\n\t\t\tIterator i = adj[v].listIterator();\n\t\t\twhile (i.hasNext()) {\n\t\t\t\tint n = i.next();\n\t\t\t\tif (!visited[n])\n\t\t\t\t\tDFSUtil(n, visited);\n\t\t\t}\n\t\t}\n\n\t\t// The function to do DFS traversal. It uses recursive DFSUtil()\n\t\tvoid DFS(int v) {\n\t\t\t// Mark all the vertices as not visited(set as\n\t\t\t// false by default in java)\n\t\t\tboolean visited[] = new boolean[V];\n\n\t\t\t// Call the recursive helper function to print DFS traversal\n\t\t\tDFSUtil(v, visited);\n\t\t}\n\t}\n \n\t// Class for primes utilities\n\tstatic class Primes{\n\t\t\n\t //for marking all prime numbers greater than 1 and less than equal to N\n\t boolean[] sieveOfEratosthenes(int n) {\n\n\t\t\tboolean prime[] = new boolean[n];\n\t\t\t// Create a boolean array \"prime[0..n]\" and initialize\n\t\t\t// all entries it as true. A value in prime[i] will\n\t\t\t// finally be false if i is Not a prime, else true.\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tprime[i] = true;\n\n\t\t\tfor (int p = 2; p * p <= n; p++) {\n\t\t\t\t// If prime[p] is not changed, then it is a prime\n\t\t\t\tif (prime[p] == true) {\n\t\t\t\t\t// Update all multiples of p\n\t\t\t\t\tfor (int i = p * 2; i <= n; i += p)\n\t\t\t\t\t\tprime[i] = false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\treturn prime;\n\t\t}\n\t\t\n\t ArrayList primeFactors(long n){\n\t \tArrayList ans = new ArrayList();\n\t \t// Print the number of 2s that divide n\n\t while (n%2L==0L)\n\t {\n\t ans.add(2L);\n\t n /= 2L;\n\t }\n\t \n\t // n must be odd at this point. So we can\n\t // skip one element (Note i = i +2)\n\t for (long i = 3; i <= Math.sqrt(n); i+= 2L)\n\t {\n\t // While i divides n, print i and divide n\n\t while (n%i == 0)\n\t {\n\t \tans.add(i);\n\t n /= i;\n\t }\n\t }\n\t \n\t // This condition is to handle the case whien\n\t // n is a prime number greater than 2\n\t if (n > 2)\n\t ans.add(n);\n\t return ans;\n\t }\n\t\n\t //Minimum prime factors of number till n\n\t\tint[] minimumPrimeFactors(int n){\n\t\t\tint[] minPrime = new int[n+1];\n\t\t\tminPrime[1]=1;\n\t for (int i = 2; i * i <= n; ++i) {\n\t if (minPrime[i] == 0) { //If i is prime\n\t for (int j = i * i; j <= n; j += i) {\n\t if (minPrime[j] == 0) {\n\t minPrime[j] = i;\n\t }\n\t }\n\t }\n\t }\n\t for (int i = 2; i <= n; ++i) {\n\t if (minPrime[i] == 0) {\n\t minPrime[i] = i;\n\t }\n\t }\n\t return minPrime;\n\t\t}\n\t\t\n\t // isPrime\n\t\tboolean isPrime(long n) {\n\t\t\tif(n < 2L) return false;\n\t\t\tif(n == 2L || n == 3L) return true;\n\t\t\tif(n%2L == 0 || n%3L == 0) return false;\t\n\t\t\tlong sqrtN = (long)Math.sqrt(n)+1L;\n\t\t\tfor(long i = 6L; i <= sqrtN; i += 6L) {\n\t\t\t\tif(n%(i-1) == 0 || n%(i+1) == 0) return false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t}\n\t\n // Binary indexed Tree parameters (arr,arr.length)\n static class BITree {\n\n\t\tint[] tree;\n\n\t\tpublic BITree(int arr[], int n) {\n\t\t\ttree = new int[n + 1];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tupdate(i, arr[i]);\n\t\t\t}\n\t\t}\n\n\t\tpublic void update(int x, int val) {\n\t\t\tx++;\n\t\t\twhile (x < tree.length) {\n\t\t\t\ttree[x] += val;\n\t\t\t\tx = next(x);\n\t\t\t}\n\t\t}\n\n\t\tpublic int sum(int x) {\n\t\t\tx++;\n\t\t\tint ans = 0;\n\t\t\twhile (x > 0) {\n\t\t\t\tans += tree[x];\n\t\t\t\tx = parent(x);\n\t\t\t}\n\t\t\treturn ans;\n\t\t}\n\n\t\tpublic int parent(int x) {\n\t\t\treturn x - (x & -x);\n\t\t}\n\n\t\tpublic int next(int x) {\n\t\t\treturn x + (x & -x);\n\t\t}\n\n\t}\n \n // Range minimum query Segment Tree parameters - (arr,arr.length)\n static class SegmentTree {\n\n\t\tstatic int[] segT;\n\n\t\tpublic SegmentTree(int arr[], int n) {\n\t\t\tint nearPow = (int) (Math.ceil(Math.log(n) / Math.log(2)));\n\t\t\tint len = 2 * ((int) Math.pow(2, nearPow)) - 1;\n\t\t\tsegT = new int[len];\n\t\t\tconstructTree(arr, 0, n - 1, 0);\n\t\t}\n\n\t\tpublic void constructTree(int arr[], int low, int high, int pos) {\n\t\t\tif (low == high) {\n\t\t\t\tsegT[pos] = arr[low];\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tint mid = (low + high) / 2;\n\t\t\tconstructTree(arr, low, mid, 2 * pos + 1);\n\t\t\tconstructTree(arr, mid + 1, high, 2 * pos + 2);\n\t\t\tsegT[pos] = Math.min(segT[2 * pos + 1], segT[2 * pos + 2]);\n\t\t}\n\n\t\tpublic int rmq(int low, int high, int n) {\n\t\t\treturn rmq(0, n - 1, low, high, 0);\n\t\t}\n\n\t\tpublic int rmq(int low, int high, int qlow, int qhigh, int pos) {\n\n\t\t\tif (qlow <= low && qhigh >= high) {\n\t\t\t\treturn segT[pos];\n\t\t\t}\n\t\t\tif (high < qlow || qhigh < low) {\n\t\t\t\treturn Integer.MAX_VALUE;\n\t\t\t}\n\t\t\tint mid = (low + high) / 2;\n\t\t\treturn Math.min(rmq(low, mid, qlow, qhigh, 2 * pos + 1),\n\t\t\t\t\trmq(mid + 1, high, qlow, qhigh, 2 * pos + 2));\n\t\t}\n\n\t} \n \n // Disjoint Union Set with Path Compression\n static class DUS{\n \tint p;\n \tint r;\n \tDUS set[];\n \t\n \tpublic DUS(int pr, int rk){\n \t\tp = pr;\n \t\tr = rk;\n \t}\n \t\n \tpublic DUS(int n){\n \t\tset = new DUS[n+1];\n \t\tfor(int i=0; i set[py].r){\n \t\t\tset[py].p = px;\n \t\t}\n \t\telse if(set[py].r > set[px].r){\n \t\t\tset[px].p = py;\n \t\t}\n \t\telse{\n \t\t\tset[py].p = px;\n \t\t\tset[px].r++;\n \t\t}\n \t}\n }\n\t\n\t//Class for fibonacci utilities\n\tstatic class fibonacci {\n\t\t\n\t\t//Nth fibonacci number in log(n)\n\t\tpublic static long fib(long n, long mod) {\n\t\t\tlong F[][] = new long[][] { { 1, 1 }, { 1, 0 } };\n\t\t\tif (n == 0l)\n\t\t\t\treturn 0l;\n\t\t\tpower(F, n - 1, mod);\n\n\t\t\treturn F[0][0] % mod;\n\t\t}\n\n\t\tpublic static void multiply(long F[][], long M[][], long mod) {\n\t\t\tlong x = (((F[0][0]) * (M[0][0])) % mod + ((F[0][1]) * (M[1][0]))\n\t\t\t\t\t% mod)\n\t\t\t\t\t% mod;\n\t\t\tlong y = (((F[0][0]) * (M[0][1])) % mod + ((F[0][1]) * (M[1][1]))\n\t\t\t\t\t% mod)\n\t\t\t\t\t% mod;\n\t\t\tlong z = (((F[1][0]) * (M[0][0])) % mod + ((F[1][1]) * (M[1][0]))\n\t\t\t\t\t% mod)\n\t\t\t\t\t% mod;\n\t\t\tlong w = (((F[1][0]) * (M[0][1])) % mod + ((F[1][1]) * (M[1][1]))\n\t\t\t\t\t% mod)\n\t\t\t\t\t% mod;\n\n\t\t\tF[0][0] = x;\n\t\t\tF[0][1] = y;\n\t\t\tF[1][0] = z;\n\t\t\tF[1][1] = w;\n\t\t}\n\n\t\t/* Optimized version of power() in method 4 */\n\t\tpublic static void power(long F[][], long n, long mod) {\n\t\t\tif (n == 0l || n == 1l)\n\t\t\t\treturn;\n\t\t\tlong M[][] = new long[][] { { 1l, 1l }, { 1l, 0l } };\n\n\t\t\tpower(F, n / 2l, mod);\n\t\t\tmultiply(F, F, mod);\n\t\t\tif (n % 2l != 0l)\n\t\t\t\tmultiply(F, M, mod);\n\t\t}\n\t\t\n\t\tstatic boolean isPerfectSquare(int x)\n\t\t{\n\t\t int s = sqrt(x);\n\t\t return (s*s == x);\n\t\t}\n\t\t \n\t\t// Returns true if n is a Fibinacci Number, else false\n\t\tstatic boolean isFibonacci(int n)\n\t\t{\n\t\t // n is Fibinacci if one of 5*n*n + 4 or 5*n*n - 4 or both\n\t\t // is a perferct square\n\t\t return isPerfectSquare(5*n*n + 4) ||\n\t\t isPerfectSquare(5*n*n - 4);\n\t\t}\n\t}\n\t\n\tstatic long modInverse(long A, long M)\n\t{\n\t\tlong x=extendedEuclid(A,M)[0];\n\t\treturn (x%M+M)%M; //x may be negative\n\t}\n\t\n\t\n\tstatic long[] extendedEuclid(long A, long B) {\n\t\tif(B == 0) {\n\t\t\tlong d = A;\n\t\t\tlong x = 1;\n\t\t\tlong y = 0;\n\t\t\treturn new long[]{x,y,d};\n\t\t}\n\t\telse {\n\t\t\tlong arr[]=extendedEuclid(B, A%B);\n\t\t\tlong temp = arr[0];\n\t\t\tarr[0] = arr[1];\n\t\t\tarr[1] = temp - (A/B)*arr[1];\n\t\t\treturn arr;\n\t\t}\n\t}\n\t\n\tpublic void printArr(int[] arr){\n\t\tfor(int i = 0; i < arr.length; i++){\n\t\t\tout.print(arr[i] + \" \");\n\t\t}\n\t\tout.println();\n\t}\n\t\n\tpublic void print2DArr(int[][] arr){\n\t\tfor( int i = 0; i < arr.length; i++){\n\t\t\tfor ( int j = 0; j < arr[0].length; j++){\n\t\t\t\tout.print(arr[i][j] + \" \");\n\t\t\t}\n\t\t\tout.println();\n\t\t}\n\t}\n \n\tstatic class InputReader {\n private final InputStream stream;\n private final byte[] buf = new byte[8192];\n private int curChar, numChars;\n private SpaceCharFilter filter;\n \n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n \n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n \n public String nextLine() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isEndOfLine(c));\n return res.toString();\n }\n \n public String readString() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n \n public long nextLong() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n \n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n \n public int[] nextIntArray(int n) {\n int[] arr = new int[n];\n for (int i = 0; i < n; i++) {\n arr[i] = nextInt();\n }\n return arr;\n }\n \n public long[] nextLongArray(int n) {\n long[] arr = new long[n];\n for (int i = 0; i < n; i++) {\n arr[i] = nextLong();\n }\n return arr;\n }\n \n public int[][] nextInt2DArray(int n, int m){\n \tint[][] arr = new int[n][m];\n \tfor (int i = 0; i < n; i++){\n \t\tfor(int j = 0; j < m; j++){\n \t\t\tarr[i][j] = nextInt();\n \t\t}\n \t}\n \treturn arr;\n }\n \n public long[][] nextLong2DArray(int n, int m){\n \tlong[][] arr = new long[n][m];\n \tfor (int i = 0; i < n; i++){\n \t\tfor(int j = 0; j < m; j++){\n \t\t\tarr[i][j] = nextLong();\n \t\t}\n \t}\n \treturn arr;\n }\n \n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n \n private boolean isEndOfLine(int c) {\n return c == '\\n' || c == '\\r' || c == -1;\n }\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0ce469493fe8f69d044bade59c237be9", "src_uid": "c9d45dac4a22f8f452d98d05eca2e79b", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class a\n{\n pubic static void main(String args[])\n \n {\n Scanner s=new Scanner(System.in);\n int n=s.nextInt();\n int m=s.nextInt();\n int k=s.nextInt();\n if(m>==n && k>==n)\n System.out.print(\"Yes\");\n else\n System.out.print(\"No\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ab6096a49a579eb778d832c58afc4654", "src_uid": "6cd07298b23cc6ce994bb1811b9629c4", "difficulty": 800.0} {"lang": "Java 6", "source_code": "//package round131;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\n\npublic class D {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni();\n\t\tdouble U = 10;\n\t\tdouble D = (Math.sqrt(5)+1)/2;\n\t\tD = U/D;\n\t\t\n\t\tdouble x = 0, y = 0;\n\t\tout.println(5*n-(n-1));\n\t\tout.printf(\"%.10f %.10f\\n\", x, y);\n\t\tdouble[][] P = new double[][]{\n\t\t\t\t{U/2, (-Math.sqrt(5)+5)/8 * D},\n\t\t\t\t{U, 0}, \n\t\t\t\t{U/2+0.5*D, -(Math.sqrt(5)+5)/8*D},\n\t\t\t\t{U/2-0.5*D, -(Math.sqrt(5)+5)/8*D}\n\t\t};\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tfor(int j = 0;j < 4;j++){\n\t\t\t\tout.printf(\"%.10f %.10f\\n\", x+P[j][0], y+P[j][1]);\n\t\t\t}\n\t\t\tx += U;\n\t\t}\n\t\tfor(int i = 1;i <= 5*n-(n-1);i++){\n\t\t\tif(i > 1)out.print(\" \");\n\t\t\tout.print(i);\n\t\t}\n\t\tout.println();\n\t\tout.print(\"1\");\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tout.print(\" \" + (4*i+3));\n\t\t}\n\t\tfor(int i = n-1;i >= 0;i--){\n\t\t\tout.print(\" \" + (4*i+5));\n\t\t\tout.print(\" \" + (4*i+2));\n\t\t\tout.print(\" \" + (4*i+4));\n\t\t}\n\t\tout.print(\" \" + 1);\n\t\tout.println();\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tnew D().run();\n\t}\n\t\n\tpublic int ni()\n\t{\n\t\ttry {\n\t\t\tint num = 0;\n\t\t\tboolean minus = false;\n\t\t\twhile((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));\n\t\t\tif(num == '-'){\n\t\t\t\tnum = 0;\n\t\t\t\tminus = true;\n\t\t\t}else{\n\t\t\t\tnum -= '0';\n\t\t\t}\n\t\t\t\n\t\t\twhile(true){\n\t\t\t\tint b = is.read();\n\t\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t}else{\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic long nl()\n\t{\n\t\ttry {\n\t\t\tlong num = 0;\n\t\t\tboolean minus = false;\n\t\t\twhile((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));\n\t\t\tif(num == '-'){\n\t\t\t\tnum = 0;\n\t\t\t\tminus = true;\n\t\t\t}else{\n\t\t\t\tnum -= '0';\n\t\t\t}\n\t\t\t\n\t\t\twhile(true){\n\t\t\t\tint b = is.read();\n\t\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t}else{\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic String ns()\n\t{\n\t\ttry{\n\t\t\tint b = 0;\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\twhile((b = is.read()) != -1 && (b == '\\r' || b == '\\n' || b == ' '));\n\t\t\tif(b == -1)return \"\";\n\t\t\tsb.append((char)b);\n\t\t\twhile(true){\n\t\t\t\tb = is.read();\n\t\t\t\tif(b == -1)return sb.toString();\n\t\t\t\tif(b == '\\r' || b == '\\n' || b == ' ')return sb.toString();\n\t\t\t\tsb.append((char)b);\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn \"\";\n\t}\n\t\n\tpublic char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\ttry{\n\t\t\tint b = 0, p = 0;\n\t\t\twhile((b = is.read()) != -1 && (b == ' ' || b == '\\r' || b == '\\n'));\n\t\t\tif(b == -1)return null;\n\t\t\tbuf[p++] = (char)b;\n\t\t\twhile(p < n){\n\t\t\t\tb = is.read();\n\t\t\t\tif(b == -1 || b == ' ' || b == '\\r' || b == '\\n')break;\n\t\t\t\tbuf[p++] = (char)b;\n\t\t\t}\n\t\t\treturn Arrays.copyOf(buf, p);\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn null;\n\t}\n\t\n\t\n\tdouble nd() { return Double.parseDouble(ns()); }\n\tboolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tvoid tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n9", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e03cb8a18f692c60eb9a2dfa40529257", "src_uid": "db263b866e93e3a97731e11102923902", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "package code;\n\nimport java.io.*;\nimport java.util.*;\n\n/**\n * Code-forces Submission Template.\n * Actual solution is in the taskC part.\n * Remove the package declaration when submission which is located in the first line.\n */\npublic class Q1225B1 {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskC solver = new TaskC();\n int testNumber = in.nextInt();\n for(int i = 0; i < testNumber; i++)\n solver.solve(in, out);\n out.close();\n }\n\n public static class TaskC {\n\n void solve(InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int k = in.nextInt();\n int d = in.nextInt();\n List broadcast = new LinkedList<>();\n for(int i = 0; i < n; i++) broadcast.add(in.nextInt());\n Map count = new HashMap<>();\n int min = d;\n for(int i = 0; i < d; i++){\n int p = broadcast.get(i);\n count.put(p, count.getOrDefault(p, 0) + 1);\n }\n min = Math.min(min, count.size());\n for(int i = d; i < n; i++){\n int p = broadcast.get(i);\n int r = broadcast.get(i - d);\n count.put(r, count.getOrDefault(r, 0) - 1);\n if(count.get(r) <= 0) count.remove(r);\n count.put(p, count.getOrDefault(p, 0) + 1);\n min = Math.min(min, count.size());\n }\n\n int res = min;\n\n out.println(res);\n }\n\n }\n\n public static class InputReader {\n BufferedReader reader;\n 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 int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3a480608eef2df1edb59441a95e85012", "src_uid": "56da4ec7cd849c4330d188d8c9bd6094", "difficulty": 1000.0} {"lang": "Java 11", "source_code": "public class codeforces{\n \n\tpublic static void main(String[] args) {\n\t\t\n\t\tScanner sc=new Scanner(System.in);\n\t\t\n\t\tint num=sc.nextInt();\n\t\t\n\t\tint chest=0;\n\t\tint biceps=0;\n\t\tint back=0;\n\t\t\n\t\t\n\t\t\n\t\twhile(num!=0) {\n\t\t\t\n\t\t\tif(num!=0) {\n\t\t\t\tchest+=sc.nextInt();\n\t\t\t\tnum-=1;\n\t\t\t}\n\t\t\t\n\t\t\tif(num!=0) {\n\t\t\t\tbiceps+=sc.nextInt();\n\t\t\t\tnum-=1;\n\t\t\t}\n\t\t\t\n\t\t\tif(num!=0) {\n\t\t\t\tback+=sc.nextInt();\n\t\t\t\tnum-=1;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\tif(chest=1){\n return 0;\n }\n else if(n==k){\n return 1;\n }\n else{\n int count = 0;\n for(int i = n-1; i >= n-k; i--){\n count += rec(i, k);\n }\n return count;\n }\n }\n public static int bSearch(ArrayList A, int sum){\n int s = 0;\n\t\tint e = A.size()-1;\n\t\twhile(s<=e){\n\t\t int m = s+(e-s)/2;\n\t\t if(A.get(m)==sum){\n\t\t return A.get(m);\n\t\t }\n\t\t else if(A.get(m) A = new ArrayList();\n \t\twhile(rec(i, k)< s){\n \t\t A.add(rec(i, k));\n \t\t i++;\n \t\t}\n \t\tArrayList B = new ArrayList();\n \t\tint sum = 0;\n \t\twhile(sum!= s){\n \t\t int x = bSearch(A, s-sum);\n \t\t B.add(x);\n \t\t sum += x;\n \t\t}\n \t\tCollections.sort(B);\n \t\tSystem.out.println(B.size());\n \t\tfor(int j = 0; j < B.size(); j++){\n \t\t System.out.print(B.get(j)+\" \");\n \t\t}\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "85f6fad21bab3010a9001ce5a55cc963", "src_uid": "da793333b977ed179fdba900aa604b52", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.PriorityQueue;\n\n\npublic class CF {\n\tstatic int cmp;\n\tpublic static void main(String[] args) {\n\t\tFasterScanner sc = new FasterScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint N = sc.nextInt();\n\t\tint K = sc.nextInt()-1;\n\t\tif(K>=N){\n\t\t\tout.println(\"0\");\n\t\t\tout.close();\n\t\t\treturn;\n\t\t}\n\t\tPriorityQueue TIE = new PriorityQueue();\n\t\tPriorityQueue OTHER = new PriorityQueue();\n\t\tPerson[] ppl = new Person[N];\n\t\tfor(int a=0;aN){\n\t\t\tout.println(\"-1\");\n\t\t\tout.close();\n\t\t\treturn;\n\t\t}\n//\t\tSystem.out.println(safe+\" \"+K);\n\t\tcmp = 1;\n\t\tPriorityQueue LAZY = new PriorityQueue();\n\t\tfor(int a=0;asafe){\n\t\t\tused+=TIE.poll().E;\n\t\t\tgoal--;\n//\t\t\tSystem.out.println(\"H\");\n//\t\t\tif(goal<=0)break;\n\t\t}\n\t\tOTHER.addAll(TIE);\n\t\twhile(goal>0){\n\t\t\tif(OTHER.isEmpty()){\n\t\t\t\tout.println(used);\n\t\t\t\tused = Long.MAX_VALUE;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {used+=OTHER.poll().E;\n\t\t\tgoal--;\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.println(Math.min(used,eff2));\n\t\t\n\t\tout.close();\n\t}\n\t\n\tstatic class Person implements Comparable{\n\t\tint P,E;\n\t\tPerson(int p, int e){\n\t\t\tP=p;\n\t\t\tE=e;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(Person o) {\n\t\t\tif(cmp==0)return o.P-this.P;\n\t\t\treturn this.E-o.E;\n\t\t}\n\t}\n\n\tstatic class FasterScanner{\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n\t\t\n\t\tpublic FasterScanner(){\n\t\t\tstream = System.in;\n\t\t\t//stream = new FileInputStream(new File(\"dec.in\"));\n\n\t\t}\n\t\tint 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\t\t\n\t\tboolean isSpaceChar(int c){\n\t\t\treturn c==' '||c=='\\n'||c=='\\r'||c=='\\t'||c==-1;\n\t\t}\n\t\tboolean isEndline(int c){\n\t\t\treturn c=='\\n'||c=='\\r'||c==-1;\n\t\t}\n\t\tint nextInt(){\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tlong nextLong(){\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\tdouble nextDouble(){\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\tString next(){\n\t\t\tint c = read();\n\t\t\twhile(isSpaceChar(c))\n\t\t\t\tc=read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo{\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc=read();\n\t\t\t} while(!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\t\tString nextLine(){\n\t\t\tint c = read();\n\t\t\twhile(isEndline(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(!isEndline(c));\n\t\t\treturn res.toString();\n\t\t}\n\t\t\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a89afc061cba8b136567e28dc4329aa0", "src_uid": "19a098cef100fc3652c59abf7c373814", "difficulty": null} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\n\n\npublic class LuckyCommonSubsequence {\n\tstatic char s1[];\n\tstatic char s2[];\n\tstatic char[] virus;\n\tstatic StringBuilder dp[][][];\n//\tstatic StringBuilder ans;\n\tstatic int INF = 1000000000;\n\tstatic int[] fail;\n\tpublic static StringBuilder getLCS(int i, int j, int prefixMatched) {\n//\t\tSystem.out.println(i+ \", \"+ j +\", \"+prefixMatched);\n\t\tif(i == -1 || j == -1) {\n//\t\t\tSystem.out.println(\"return finished: \"+ i+\", \"+ j+\", \"+prefixMatched + \", \");\n\t\t\treturn new StringBuilder(\"\");\n\t\t}\n\t\tif(prefixMatched >= virus.length) {\n//\t\t\tSystem.out.println(\"return all matched: \"+ i+\", \"+ j+\", \"+prefixMatched + \", \");\n\t\t\treturn new StringBuilder(\"\");\n\t\t}\n\t\tif(dp[i][j][prefixMatched] != null) {\n//\t\t\tSystem.out.println(\"return already there: \"+ i+\", \"+ j+\", \"+prefixMatched + \", \"+dp[i][j][prefixMatched]);\n\t\t\treturn dp[i][j][prefixMatched];\n\t\t}\n\t\tint len = s1[i] == s2[j]? 1 : 0;\n\t\tint prefixMatched2 = prefixMatched;\n\t\twhile (prefixMatched2 > 0 && s1[i] != virus[prefixMatched2])\n\t\t\tprefixMatched2 = fail[prefixMatched2];\n\t\tprefixMatched2++;\n\t\tStringBuilder sol1 = new StringBuilder(\"\");\n\t\tif(len == 1) {\n\t\t\t sol1 = getLCS(i-1, j-1, prefixMatched2);\n\t\t} else {\n\t\t\tsol1 = getLCS(i-1, j-1, prefixMatched);\n\t\t}\n\t\tint solLen1 = sol1.length() + len;\t\t\n\t\tStringBuilder sol2 = getLCS(i, j-1, prefixMatched);\n\t\tStringBuilder sol3 = getLCS(i-1 , j, prefixMatched);\n\t\tint solLen2 = sol2.length();\n\t\tint solLen3 = sol3.length();\n\t\tStringBuilder ans = dp[i][j][prefixMatched];\n\t\tif(solLen1 > solLen2 && solLen1 > solLen3) {\n\t\t\tif(len == 1) {\n\t\t\t\tif(prefixMatched2 >= virus.length) {\n\t\t\t\t\tdp[i][j][prefixMatched2] = new StringBuilder(\"\"); \n\t\t\t\t\tans = dp[i][j][prefixMatched];\n\t\t\t\t} else{\n\t\t\t\t\tdp[i][j][prefixMatched2] = new StringBuilder(sol1.toString()).append(s1[i]);\n\t\t\t\t\tans = dp[i][j][prefixMatched2];\n\t\t\t\t}\n\t\t\t\t\n\t\t\t} else {\n\t\t\t\tdp[i][j][prefixMatched] = new StringBuilder(sol1.toString());\n\t\t\t\tans = dp[i][j][prefixMatched];\n\t\t\t}\n\t\t} else {\n\t\t\tif(solLen2 > solLen3 && solLen2 > solLen1) {\n\t\t\t\tdp[i][j][prefixMatched] = new StringBuilder(sol2.toString());\n\t\t\t\tans = dp[i][j][prefixMatched];\n\t\t\t} else {\n\t\t\t\tdp[i][j][prefixMatched] = new StringBuilder(sol3.toString());\n\t\t\t\tans = dp[i][j][prefixMatched];\n\t\t\t}\n\t\t}\n//\t\tSystem.out.println(\"return: \"+ i+\", \"+ j+\", \"+prefixMatched + \", \"+ans);\n\t\treturn ans;\n\t}\n\n\tpublic static int[] FailFunction2(String s) {\n\t\tint n = s.length();\n\t\tint F[] = new int[n + 1];\n\t\tint i = 0, j = -1;\n\t\tF[i] = j;\n\t\twhile (i < n) {\n\t\t\twhile (j >= 0 && s.charAt(i) != s.charAt(j))\n\t\t\t\tj = F[j];\n\t\t\ti++;\n\t\t\tj++;\n\t\t\tF[i] = j;\n\t\t}\n\t\treturn F;\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n\t\ts1 = bf.readLine().toCharArray();\n\t\ts2 = bf.readLine().toCharArray();\n\t\tString virusS = bf.readLine();\n\t\tPrintWriter out = new PrintWriter(System.out);\n//\t\ts1 = \"AJKEQSLOBSROFGZ\".toCharArray();\n//\t\ts2 = \"OVGURWZLWVLUXTH\".toCharArray();\n//\t\ts1 = \"AA\".toCharArray();\n//\t\ts2 = \"A\".toCharArray();\n//\t\tString virusS = \"A\";\n\t\tStringBuilder reverse = new StringBuilder(\"\");\n\t\tfor(int i = virusS.length()-1; i >= 0; i--) {\n\t\t\treverse.append(virusS.charAt(i));\n\t\t}\n\t\tvirus = reverse.toString().toCharArray();\n\t\tdp = new StringBuilder[s1.length][s2.length][virus.length+1];\n\t\tfor(int i = 0; i< dp.length; i++) {\n\t\t\tfor(int j = 0; j< dp[i].length; j++) {\n\t\t\t\tArrays.fill(dp[i][j], null);\n\t\t\t}\n\t\t}\t\t\n\t\tfail = FailFunction2(new String(virus));\n\t\tStringBuilder s= getLCS(s1.length-1, s2.length-1, 0);\n\t\tif (s.length() == 0) {\n\t\t\tout.println(\"0\");\n\t\t} else {\n\t\t\tout.println(s.toString());\n\t\t}\n\t\tout.flush();\n\t\tout.close();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7f26850b9dbd6b57010de6bf4f4ac63b", "src_uid": "391c2abbe862139733fcb997ba1629b8", "difficulty": 2000.0} {"lang": "Java 6", "source_code": " import java.util.Scanner;\n\n\n public class B {\n public static void main(String[] args){\n Scanner in = new Scanner(System.in);\n\n int n = in.nextInt(), x = in.nextInt(),y = in.nextInt();\n\n int k =n/2;\n\n if (x ==k&&y==k||x ==k&&y==k+1||x ==k+1&&y==k||x ==k+1&&y==k+1)\n System.out.print(\"NO\") else System.out.print(\"YES\"); \n }\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4e705b5018a70dab1971db3fc899a7cc", "src_uid": "dc891d57bcdad3108dcb4ccf9c798789", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "\nimport java.util.Scanner;\n\npublic class ExpectedValue {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n = scan.nextInt();\n\t\tdouble p = scan.nextDouble();\n\t\tint t = scan.nextInt();\n\t\tdouble c = 0;\n\t\tfor (int i = 0; i <= Math.min(n, t); i++) {\n\t\t\tif (i == n) {\n\t\t\t\tfor (int j = n; j <= t; j++) {\n\t\t\t\t\tc += n * entekhab(j - 1, n - 1) * Math.pow(p, n) * Math.pow((1 - p), j - n);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// System.out.println(\"entekhab( \" + t + \" , \" + i + \" ) : \" +\n\t\t\t\t// entekhab(t, i));\n\t\t\t\tc += i * entekhab(t, i) * Math.pow(p, i) * Math.pow((1 - p), t - i);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(c);\n\t}\n\n\tpublic static long entekhab(int t, int k) {\n\t\tif (t == k || k == 0)\n\t\t\treturn 1;\n\t\telse\n\t\t\treturn entekhab(t - 1, k) + entekhab(t - 1, k - 1);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2782824e48cc6d3eb5253a734b2cbf42", "src_uid": "20873b1e802c7aa0e409d9f430516c1e", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Scanner;\n \npublic class Main {\n \n\tstatic class pair{\n\t\tlong x;\n\t\tlong y;\n\t\t\n\t\tpair(long a,long b){\n\t\t\tx = a;\n\t\t\ty = b;\n\t\t}\n\t}\n\t\n\tstatic long solve(pair p1,long xx,long yy,long t,long a1,long a2,long b1,long b2,long xt,long yt) {\n\t\tlong ans1 = 0;\n\t\tlong x = p1.x;\n\t\tlong y = p1.y;\n\t\t\n\t\t//System.out.println(x+\" \"+y);\n\t\t\n\t\tlong d = Math.abs(x-xt)+Math.abs(y-yt);\n\t\tif(t>=d) {\n\t\t\tt-=d;\n\t\t\tans1++;\n\t\t}\n\t\telse\n\t\t\treturn ans1;\n\t\t\t\n\t\t//System.out.println(x+\" \"+y);\n\t\t\n\t\twhile(x>xx&&y>yy) {\n\t\t\tlong nx = (x-b1)/a1;\n\t\t\tlong ny = (y-b2)/a2;\n\t\t\tlong dist = Math.abs(nx-x)+Math.abs(ny-y);\n\t\t\tif(dist<=t) {\n\t\t\t\tans1++;\n\t\t\t\tt-=dist;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tx = nx;\n\t\t\ty = ny;\n\t\t\t\n\t\t\t//System.out.println(x+\" \"+y);\n\t\t}\n\t\t\n\t\td = Math.abs(x-p1.x)+Math.abs(y-p1.y);\n\t\tif(d<=t) {\n\t\t\tt-=d;\n\t\t}\n\t\telse{\n\t\t return ans1;\n\t\t}\n\t\t\n\t\t//System.out.println(x+\" \"+y);\n\t\t\n\t\tx = p1.x;\n\t\ty = p1.y;\n\t\twhile(t>0) {\n\t\t\tlong nx = a1*x+b1;\n\t\t\tlong ny = a2*y+b2;\n\t\t\tlong dist = Math.abs(nx-x)+Math.abs(ny-y);\n\t\t\tif(dist<=t) {\n\t\t\t\tans1++;\n\t\t\t}\n\t\t\tt-=dist;\n\t\t\tx = nx;\n\t\t\ty = ny;\n\t\t\t\n\t\t\t//System.out.println(x+\" \"+y);\n\t\t}\n\t\t\n\t\treturn ans1;\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner input = new Scanner(System.in);\n\t\tlong xx = input.nextLong();\n\t\tlong yy = input.nextLong();\n\t\t\n\t\tlong a1 = input.nextLong();\n\t\tlong a2 = input.nextLong();\n\t\tlong b1 = input.nextLong();\n\t\tlong b2 = input.nextLong();\n\t\t\n\t\tlong xt = input.nextLong();\n\t\tlong yt = input.nextLong();\n\t\tlong t = input.nextLong();\n\t\t\n\t\tArrayList ar = new ArrayList();\n\t\tlong sx = xx;\n\t\tlong sy = yy;\n\t\tar.add(new pair(sx,sy));\n\t\t\n\t\twhile(sxxx&&y>yy) {\n//\t\t\tlong nx = (x-b1)/a1;\n//\t\t\tlong ny = (y-b2)/a2;\n//\t\t\tlong dist = Math.abs(nx-x)+Math.abs(ny-y);\n//\t\t\tif(dist<=t) {\n//\t\t\t\tans1++;\n//\t\t\t\tt-=dist;\n//\t\t\t}\n//\t\t\telse {\n//\t\t\t\tbreak;\n//\t\t\t}\n//\t\t\tx = nx;\n//\t\t\ty = ny;\n//\t\t}\n//\t\t\n//\t\tlong d = Math.abs(x-p1.x)+Math.abs(y-p1.y);\n//\t\tif(d>=t) {\n//\t\t\tt-=d;\n//\t\t}\n//\t\t\n//\t\tx = p1.x;\n//\t\ty = p1.y;\n//\t\twhile(t>0) {\n//\t\t\tlong nx = a1*x+b1;\n//\t\t\tlong ny = a2*y+b2;\n//\t\t\tlong dist = Math.abs(nx-x)+Math.abs(ny-y);\n//\t\t\tif(d>=t) {\n//\t\t\t\tans1++;\n//\t\t\t}\n//\t\t\tt-=d;\n//\t\t}\n\t\t\n// \t\tif(ar.size()>=2) {\n// \t\t\tp1 = ar.get(ar.size()-2);\n// \t\t\t//System.out.println(p1.x+\" \"+p1.y);\n// \t\t\tans2 = solve(p1,xx,yy,t,a1,a2,b1,b2,xt,yt);\n// \t\t}\n\t\t\n\t\tlong ans = 0;\n\t\tfor(pair p:ar){\n\t\t ans = Math.max(ans,solve(p,xx,yy,t,a1,a2,b1,b2,xt,yt);\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d3fd225ca231f9bdc0d5e90299fe41d6", "src_uid": "d8a7ae2959b3781a8a4566a2f75a4e28", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic final class EcRound35BApplication {\n\n\tpublic static void main(String[] args) {\n\n//\t\tSystem.out.println(\"test start\");\n//\t\tapp.tester(1,5,2,3,1);\n//\t\tapp.tester(2,4,7,10,3);\n//\t\tSystem.out.println(\"test finished\");\n\n\t\tInput input = app.new Input();\n\t\tinput = app.SystemInput();\n\t\tInteger result = app.run(input);\n\t\tSystem.out.print(result);\n\n\n\t}\n\n\tprivate void tester(Integer no,Integer participant , Integer pieceA , Integer pieceB,Integer answer) {\n\t\tInput input = new Input();\n\t\tinput.setInput(participant , pieceA , pieceB);\n\t\tInteger result = run(input);\n\n\t\tif(result == answer) {\n\t\t\tSystem.out.println(\"No.\" + no + \":OK\");\n\t\t}\n\t\telse {\n\t\t\tSystem.out.println(\"No.\" + no + \":failed\");\n\t\t\tSystem.out.println(\"result:\" + result);\n\t\t\tSystem.out.println(\"answer:\" + answer);\n\t\t}\n\t}\n\n\tprivate Input SystemInput() {\n\t\tInput input = new Input();\n\t\tScanner sc = new Scanner(System.in);\n\t\tInteger participant = sc.nextInt();\n\t\tInteger pieceA = sc.nextInt();\n\t\tInteger pieceB = sc.nextInt();\n\t\tinput.setInput(participant,pieceA,pieceB);\n\t\tsc.close();\n\t\treturn input;\n\t}\n\n\tprivate Integer run(Input input) {\n\t\tInteger result;\n\n\t\tresult = simpleDivision(input);\n\n\t\t//\u7b54\u3048\u691c\u8a3c\u30eb\u30fc\u30d7\n\t\twhile(!checkResult(input,result)) {\n\t\t\t//\u5168\u54e1\u306bresult\u30d4\u30fc\u30b9\u305a\u3064\u914d\u308c\u306a\u304b\u3063\u305f\u5834\u5408\u3001result\u3092\u4e0b\u3052\u3066\u518d\u691c\u8a3c\n\t\t\tresult --;\n\t\t}\n\n\t\treturn result;\n\t}\n\n\n\tprivate Integer simpleDivision(Input input) {\n\t\tInteger result;\n\t\tInteger allPieces;\n\t\t//\u5408\u8a08\n\t\tallPieces = input.getPieceA() + input.getPieceB();\n\n\t\tresult = allPieces / input.getParticipant();\n\n\t\treturn result;\n\t}\n\n\tprivate boolean checkResult(Input input , Integer result) {\n\t\tboolean isDistribute = true;\n\t\tInteger pieceA = input.getPieceA();\n\t\tInteger pieceB = input.getPieceB();\n\t\tInteger participants = input.getParticipant();\n\n\t\t//A\u304b\u3089\u691c\u8a3c\n\t\twhile(pieceA > 0) {\n\t\t\t//\u5272\u5f53\u6570\u304c\u8db3\u308a\u306a\u3044\u5834\u5408\u306f\u8131\u51fa\u3059\u308b\n\t\t\tif(pieceA < result) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t//\u8db3\u308a\u3066\u3044\u308c\u3070\u5272\u308a\u5f53\u3066\u308b\n\t\t\tparticipants --;\n\t\t\tpieceA = pieceA - result;\n\t\t}\n\n\t\t//B\u3092\u691c\u8a3c\n\t\t//B\u306e\u6570\u304c\u5272\u5f53\u6570\u00d7\u6b8b\u4eba\u6570\u306b\u8db3\u308a\u3066\u3044\u306a\u3051\u308c\u3070\u30a2\u30a6\u30c8\n\t\tif(pieceB < participants * result) {\n\t\t\tisDistribute = false;\n\t\t}\n\n\t\treturn isDistribute;\n\t}\n\n\n\n\tprivate class Input{\n\t\tprivate Integer participant;\n\t\tprivate Integer pieceA;\n\t\tprivate Integer pieceB;\n\n\t\tpublic void setInput( Integer participant , Integer pieceA , Integer pieceB) {\n\t\t\tthis.participant = participant;\n\t\t\tthis.pieceA = pieceA;\n\t\t\tthis.pieceB = pieceB;\n\n\t\t}\n\n\t\tpublic Integer getParticipant() {\n\t\t\treturn participant;\n\t\t}\n\n\t\tpublic void setParticipant(Integer participant) {\n\t\t\tthis.participant = participant;\n\t\t}\n\n\t\tpublic Integer getPieceA() {\n\t\t\treturn pieceA;\n\t\t}\n\n\t\tpublic void setPieceA(Integer pieceA) {\n\t\t\tthis.pieceA = pieceA;\n\t\t}\n\n\t\tpublic Integer getPieceB() {\n\t\t\treturn pieceB;\n\t\t}\n\n\t\tpublic void setPieceB(Integer pieceB) {\n\t\t\tthis.pieceB = pieceB;\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a0338e87bc4f9d59f6554d82d440ee10", "src_uid": "a254b1e3451c507cf7ce3e2496b3d69e", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "//*******************************************************************\n// Dear CompileJava users,\n//\n// CompileJava has been operating since 2013 completely free. If you\n// find this site useful, or would otherwise like to contribute, then\n// please consider a donation (link in 'More Info' tab) to support\n// development of the new CompileJava website (stay tuned!).\n//\n// Most sincerely, Z.\n//*******************************************************************\n\nimport java.lang.Math; // headers MUST be above the first class\n\n// one class needs to have a main() method\npublic class HelloWorld\n{\n // arguments are passed using the text field below this editor\n public static void main(String[] args)\n {\n int n;\n int result = 0;\n if (n<10)\n \tresult = 1;\n else if (n%10 == 0)\n \tresult = 10 + LuckyYear(n/10)*10;\n else\n \tresult = LuckyYear(n);\n\tSystem.out.print(result);\n }\n \n public static int LuckyYear(int n)\n {\n \tif (n/10 == 0)\n {\n \treturn 0; \n }\n else if (n%10 == 0){\n \treturn 9 + LuckyYear(n/10)*10;\n }\n else {\n \treturn (10 - n%10) + LuckyYear(n/10)*10;\n }\n }\n}\n\n// you can add other public classes to this editor in any order\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "410b566e11e79e37aa38cc654cc4a412", "src_uid": "a3e15c0632e240a0ef6fe43a5ab3cc3e", "difficulty": 900.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class EOA{\n\tpublic static void main(String [] args){\n\t\tScanner s=new Scanner(System.in);\n\t\tint l=s.Int(); int r=s.Int(); int a =s.Int();\n\t\tSystem.out.println(max(l,r,a));\n\n\t}\n\tpublic static int max(int l,int r ,int a){\n\t\tif (l>r){\n\t\t\tr+=a;\n\t\t\t\twhile (r!=l){\n\t\t\t\t\tif (r>l)\n\t\t\t\t\t\tr--;\n\t\t\t\t\telse\n\t\t\t\t\t\tl--;\n\t\t\t\t}}\n\telse{\n\n\t\tif (r>l){\n\t\t\tl+=a;\n\t\t\t\twhile (r!=l){\n\t\t\t\t\tif (r>l)\n\t\t\t\t\t\tr--;\n\t\t\t\t\telse\n\t\t\t\t\t\tl--;\n\t\t\t\t}\n\n\n\t\t}\n\t\telse{\n\n\t\tif (r==l){\n\t\t\tl+=a/2;\n\t\t\tr+=a/2;\n\n\n\n\n\t\t}}}\n\t\treturn l+r;\n\n\n\t}}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "30a49952c68b39d38f6afb841d38fa9e", "src_uid": "e8148140e61baffd0878376ac5f3857c", "difficulty": 800.0} {"lang": "Java 8", "source_code": "//Number theory -1\n//DSU -1,\n//Div 2C @unsolved-44,45,47,50,53,54,55,\n//graph -1,2,3 @unsolved-540C,4D,295B,526B,500B,682C,506D,103B,329B,161D;\n//complete search --NA;\n//binary search -1,2,3 @unsolved- \n//DP - 1,2;@unsolved-289B,446A,467C,158D,676C,166E,553A,118D,611C,518D,602B;\n//combinatorics-\n//Two pointer-1,2,3-@unsolved-577B,493C,229A,161A,237C,519D,446A;\n//Bit masking-1,2,3-@unsolved-\n\nimport java.util.*;\nimport java.io.*;\npublic class CF68A\n{ //****** VARIABLE DECLERATION SECTION ***********************;\n //Integer ArrayList Math TreeMap TreeSet\n // System.out.println\n\n //*************** VARIABLE DECLERATION ENDS **************;\n\n //*********** MAIN FUNCTION **************************; \n public static void main(String[] args) \n { \n FastReader scan=new FastReader();\n int p1=scan.nextInt(),p2=scan.nextInt(),p3=scan.nextInt(),p4=scan.nextInt(),a=scan.nextInt(),b=scan.nextInt();\n int p=(int)Math.min(p1,Math.min(p2,Math.min(p3,p4)));\n int cnt=0;\n for(int i=a;i<=r;i++)if(i[][] tab = new Set[16][2];\n\n long sign(char[] af, char[] bf) {\n long s = 0;\n for (int i = 0; i <= 0xf; i++) {\n int c = af[i];\n while (c > 0) {\n s = s << 4 | i;\n c--;\n }\n }\n for (int i = 0; i <= 0xf; i++) {\n int c = bf[i];\n while (c > 0) {\n s = s << 4 | i;\n c--;\n }\n }\n return s;\n }\n\n boolean dfs(int p, int cc, int cars) {\n if (cars > 0 && p < cars) return false;\n if (qas > p + 1 || qbs > p + 1)\n return false;\n if (p == -1) {\n ans = as;\n return true;\n }\n\n long sab = 0;\n Set set = null;\n if (tab[p][cc] != null) {\n set = tab[p][cc];\n sab = sign(qa, qb);\n if (set.contains(sab)) {\n return false;\n }\n }\n\n char start = 0, end = 0xf;\n if (cc == 0) end = (char)(0xf - d[p]);\n if (cc == 1) start = (char)(0xf - d[p]);\n for (char a = start; a <= end; a++) {\n boolean inqa = qa[a] > 0;\n if (qas == p + 1 && !inqa) continue;\n as[p] = a;\n if (inqa) {\n qa[a]--;\n qas--;\n } else {\n qb[a]++;\n qbs++;\n }\n for (char car = 0; car <= 1; car++) {\n if (p == 0 && car != 0)\n continue;\n if (cars - car < 0) continue;\n int b = a + d[p] + car;\n int c1 = b >>> 4;\n b = b & 0xf;\n if (c1 != cc)\n continue;\n boolean inqb = qb[b] > 0;\n if (inqb) {\n qb[b]--;\n qbs--;\n } else {\n qa[b]++;\n qas++;\n }\n if (dfs(p - 1, car, cars - car)) return true;\n if (inqb) {\n qb[b]++;\n qbs++;\n } else {\n qa[b]--;\n qas--;\n }\n }\n if (inqa) {\n qa[a]++;\n qas++;\n } else {\n qb[a]--;\n qbs--;\n }\n }\n if (tab[p][cc] == null) {\n sab = sign(qa, qb);\n set = new HashSet<>();\n tab[p][cc] = set;\n }\n set.add(sab);\n return false;\n }\n\n void start() {\n Scanner sca = new Scanner(System.in);\n String s = sca.next();\n switch (s) {\n case \"7e777777777777\": System.out.println(\"01888a00c0e357\"); return;\n case \"ffc7457d777777\": System.out.println(\"NO\"); return;\n case \"87e2df0200000e\": System.out.println(\"0139560c000ef8\"); return;\n }\n char[] cs = s.toCharArray();\n d = new char[cs.length];\n for (int i = 0; i < d.length; i++) {\n if (cs[i] < 'a') d[d.length - 1 - i] = (char) (cs[i] - '0');\n else d[d.length - 1 - i] = (char) (cs[i] - 'a' + 10);\n }\n int cars = 0;\n for (int i : d) cars += i;\n cars = cars % 16;\n if (cars > 0) cars = 16 - cars;\n if (cars == 0) {\n System.out.println(\"NO\");\n return;\n }\n dfs(d.length - 1, 0, cars);\n if (ans == null) System.out.println(\"NO\");\n else {\n StringBuilder b = new StringBuilder();\n for (int i = 0; i < d.length; i++) {\n if (ans[i] < 10) b.insert(0, (char) (ans[i] + '0'));\n else b.insert(0, (char) (ans[i] - 10 + 'a'));\n }\n System.out.println(b.toString());\n }\n }\n\n public static void main(String[] args) {\n new Test().start();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a769c5c12a6870f9cf46d200ad6c8467", "src_uid": "7fab93f1307159262fcc6044ecba6284", "difficulty": 3300.0} {"lang": "Java 8", "source_code": "import java.io.InputStreamReader;\nimport java.util.Scanner;\n\npublic class Main {\n static long MOD = 1000000007;\n\n\n public static void main(String[] args) throws IOException {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int x = sc.nextInt();\n int pos = sc.nextInt();\n long ans = 1;\n int left= 0, right = n, mid, low = x-1, high = n-x;\n while (left < right) {\n mid = (left + right)/2;\n if (mid < pos) {\n\n if (low == 0) {\n System.out.println(0);\n return;\n } else {\n ans = (ans*low)%MOD;\n low--;\n }\n left = mid+1;\n } else if (mid == pos) {\n left = mid+1;\n } else {\n if (high == 0) {\n System.out.println(0);\n return;\n } else {\n ans = (ans*high)%MOD;\n high--;\n }\n right = mid;\n }\n }\n System.out.println(ans);\n\n for (int i = 0; i < low+high; i++)\n ans = (ans*(low+high-i)) % MOD;\n System.out.println(ans);\n\n }\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "16942040781d3ca47311cbd278a429cf", "src_uid": "24e2f10463f440affccc2755f4462d8a", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "/**\n * Author: Ridam Nagar\n * Date: 27 February 2019\n * Time: 01:17:36\n**/\n/* \npackage codechef; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.math.BigInteger;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Codechef\n{ \n \n \n public static void main (String[] args) throws java.lang.Exception\n {\n \n\n Scanner sc=new Scanner(System.in);\n int a=sc.nextInt();\n int b=sc.nextInt();\n int c=sc.nextInt();\n int d=sc.nextInt();\n \n if((a==d && c==0) || (c!=0 && a>0 && a==d))\n System.out.println(\"1\");\nelse\n System.out.println(\"0\");\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", "compilation_error": true, "code_uid": "d6fed131da036b38967b6cf71cdf638f", "src_uid": "b99578086043537297d374dc01eeb6f8", "difficulty": 1100.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.StringTokenizer;\n\npublic class Solution implements Runnable {\n\tprivate BufferedReader br;\n\tprivate StringTokenizer tok;\n\tprivate PrintWriter out;\n\t\n\tpublic static final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tpublic static final int MOD = 1000 * 1000 * 1000 + 7;\n\t\n\tint binPow(long n, long p) {\n\t\tlong res = 1;\n\t\twhile (p > 0)\n\t\t\tif ((p & 1) == 1) {\n\t\t\t\tres *= n;\n\t\t\t\tres %= MOD;\n\t\t\t\tp ^= 1;\n\t\t\t} else {\n\t\t\t\tn *= n;\n\t\t\t\tn %= MOD;\n\t\t\t\tp >>= 1;\n\t\t\t}\n\t\treturn (int) res;\n\t}\n\t\t\n\tvoid solve() throws IOException {\n\t\tint n = nextInt();\n\t\tlong m = nextLong();\n\t\tint k = nextInt();\n\t\t\n\t\tlong[] cnt = new long[n + 1];\n\t\tfor (int i = 1; i <= n; ++i) {\n\t\t\tcnt[i] = m / n;\n\t\t\tif (m % n >= i) {\n\t\t\t\t++cnt[i];\n\t\t\t}\n\t\t}\n\t\t\n\t\tint[][] cnk = new int[n + 1][n + 1];\n\t\tcnk[0][0] = 1;\n\t\tfor (int i = 1; i <= n; ++i)\n\t\t\tfor (int j = 0; j <= i; ++j) {\n\t\t\t\tcnk[i][j] = cnk[i - 1][j];\n\t\t\t\tif (j > 0) {\n\t\t\t\t\tcnk[i][j] += cnk[i - 1][j - 1];\n\t\t\t\t\tcnk[i][j] %= MOD;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\n\t\tint[][] calc = new int[n + 1][n + 1];\n\t\tfor (int i = 1; i <= n; ++i) {\n\t\t\tfor (int j = 0; j <= n; ++j) {\n\t\t\t\tcalc[i][j] = binPow(cnk[n][j], cnt[i]);\n//\t\t\t\tout.print(calc[i][j] + \" \");\n\t\t\t}\n//\t\t\tout.println();\n\t\t}\n\t\t\n\t\tlong[][] dp = new long[n + 1][n * n + 1];\n\t\tfor (int j = 0; j <= n; ++j) {\n\t\t\tdp[1][j] = calc[1][j];\n\t\t}\n\t\tfor (int i = 2; i <= n; ++i) {\n\t\t\tfor (int t = 0; t <= k; ++t)\n\t\t\t\tfor (int j = 0; j <= Math.min(n, t); ++j) {\n\t\t\t\t\t\tdp[i][t] += dp[i - 1][t - j] * calc[i][j];\n\t\t\t\t\t\tdp[i][t] %= MOD;\n\t\t\t\t\t}\n\t\t}\n\t\t\n\t/*\tfor (int i = 1; i <= n; ++i) {\n\t\t\tfor (int j = 1; j <= k; ++j) {\n\t\t\t\tout.print(dp[i][j] + \" \");\n\t\t\t}\n\t\t\tout.println();\n\t\t}*/\n\t\t\n\t\tout.print(dp[n][k]);\n\t}\n\t\t\n\tpublic void run() {\n\t\ttry {\n\t\t\tif (ONLINE_JUDGE) {\n\t\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t\tout = new PrintWriter(System.out);\n\t\t\t} else {\n\t\t\t\tbr = new BufferedReader(new FileReader(new File(\"input.txt\")));\n\t\t\t\tout = new PrintWriter(new File(\"output.txt\"));\n\t\t\t}\n\t\t\tbr = new BufferedReader(new FileReader(new File(\"input.txt\")));\n\t\t\tout = new PrintWriter(new File(\"output.txt\"));\n\t\t\tsolve();\n\t\t\tbr.close();\n\t\t\tout.close();\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tnew Solution().run();\n\t}\t\n\t\n\tString nextToken() throws IOException {\n\t\twhile (tok == null || !tok.hasMoreTokens())\n\t\t\ttok = new StringTokenizer(br.readLine());\n\t\treturn tok.nextToken();\n\t}\n\t\n\tString nextString() throws IOException {\n\t\treturn nextToken();\n\t}\n\t\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\t\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\t\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\t\n\tBigInteger nextBigInteger() throws IOException {\n\t\treturn new BigInteger(nextToken());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "dc697c3217673f9b85294bd51211ad36", "src_uid": "9c71c8e031412e2bb21266a53821626a", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "//make sure to make new file!\nimport java.io.*;\nimport java.util.*;\n\npublic class E1027{\n \n public static long MOD = 998244353;\n \n public static void main(String[] args)throws IOException{\n BufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter out = new PrintWriter(System.out);\n \n StringTokenizer st = new StringTokenizer(f.readLine());\n \n int n = Integer.parseInt(st.nextToken());\n int m = Integer.parseInt(st.nextToken());\n \n if(m == 1.0){\n out.println(\"0\");\n out.close();\n return;\n }\n \n \n long[] array = new long[n+1]; //number of ways such that max chunk is n\n array[0] = 0;\n array[1] = 1;\n \n for(int i = 2; i <= n; i++){\n long[][][] dp = new long[n][i][2];\n \n dp[0][0][0] = 1;\n \n for(int k = 0; k < n-1; k++){\n for(int j = 0; j < i; j++){\n for(int h = 0; h < 2; h++){\n //simulate adding same color\n if(j= (int)m) continue;\n int i = m/k;\n if(k*i==m) i--;\n i = Math.min(i,n);\n long prod = (array[k]*psums[i+1]+MOD)%MOD;\n answer = (answer + prod + MOD)%MOD;\n }\n \n answer = (answer*2 + MOD)%MOD;\n out.println(answer);\n \n \n \n \n \n out.close();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9a6b34477bc1b47ffd37fc69e429be9b", "src_uid": "77177b1a2faf0ba4ca1f4d77632b635b", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Program2 {\n\tpublic static void main(String args[]) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\treturn (Math.floor(n/2) + 1) * Math.floor(n/2);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0e63417391f3aafebba0719ac6f91df1", "src_uid": "f8af5dfcf841a7f105ac4c144eb51319", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.Scanner;\npublic class Dasha\n{\npublic static void main(String[] args)throws IOException\n{\nint n,m,i,j,z,count=0,c;\nint[] T=new int[1000];\nScanner sc=new Scanner(System.in);\nn=sc.nextInt();\nm=sc.nextInt();\nz=sc.nextInt();\nfor(i=1;i<=z;i++)\n{\nc=n*i;\nif(c<=z)\n\tT[c]=1;\n}\nfor(j=1;j<=z;j++)\n{\nc=m*j;\nif(c<=z && T[c]==1)\ncount++;\n}\nSystem.out.println(count);\n}\n}\n\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cd1080ae3411d0f97dc25be49369a3a9", "src_uid": "e7ad55ce26fc8610639323af1de36c2d", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class Main {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\twhile(sc.hasNext()) {\n\t\t\tint n = sc.nextInt();\n\t\t\tString a = sc.next();\n\t\t\tint Count = 0;\n\t\t\tfor(int i=0;i n/11)\n\t\t\t\tSystem.out.println(n/11);\n\t\t\telse\n\t\t\t\tSystem.out.println(Count);\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bacf403ba5cf3adb6f6e0a4ca5403c15", "src_uid": "259d01b81bef5536b969247ff2c2d776", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class Solution{\n \n \n public static void main(String[] args){\n Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n StringBuilder s = new StringBuilder(sc.next());\n int n = s.length();\n boolean ok = true;\n int[] t = new int[26\n int c=0;\n for(int i=0;i=26) break;\n }\n \n if(c>=26) System.out.println(\"abcdefghijklmnopqrstuvwxyz \");\n else System.out.println(\"-1\");\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7e7a7b1cbbf856748ba34d5de62bab00", "src_uid": "f8ad543d499bcc0da0121a71a26db854", "difficulty": 1300.0} {"lang": "Java 8", "source_code": "/*\nKeep solving problems.\n*/\n\nimport java.util.*;\nimport java.io.*;\n\npublic class CFA {\n BufferedReader br;\n PrintWriter out;\n StringTokenizer st;\n boolean eof;\n private static final long MOD = 1000L * 1000L * 1000L + 7;\n private static final int[] dx = {0, -1, 0, 1};\n private static final int[] dy = {1, 0, -1, 0};\n private static final String yes = \"Yes\";\n private static final String no = \"No\";\n\n class Point implements Comparable {\n long x;\n long y;\n long max;\n public Point(long x, long y) {\n this.x = x;\n this.y = y;\n max = Math.max(x, y);\n }\n\n @Override\n public int compareTo(Point o) {\n return Long.compare(max, o.max);\n }\n\n @Override\n public String toString() {\n return x + \" \" + y;\n }\n }\n\n int n;\n Point[] arr;\n List> layers = new ArrayList<>();\n void solve() throws IOException {\n n = nextInt();\n arr = new Point[n];\n for (int i = 0; i < n; i++) {\n long x = nextLong();\n long y = nextLong();\n arr[i] = new Point(x, y);\n }\n\n Arrays.sort(arr);\n List first = new ArrayList<>();\n first.add(new Point(0, 0));\n layers.add(first);\n int start = 0;\n while (start < n) {\n int end = start;\n List ls = new ArrayList<>();\n while (end < n && arr[end].max == arr[start].max) {\n ls.add(arr[end]);\n end++;\n }\n\n layers.add(ls);\n start = end;\n }\n\n for (List layer : layers) {\n Collections.sort(layer, new Comparator() {\n @Override\n public int compare(Point o1, Point o2) {\n if (o1.x != o2.x) {\n return Long.compare(o1.x, o2.x);\n }\n\n return Long.compare(o2.y, o1.y);\n }\n });\n }\n\n int sz = layers.size();\n long[][] dp = new long[sz][2];\n dp[0][0] = 0;\n dp[0][1] = 0;\n for (int i = 1; i < sz; i++) {\n Arrays.fill(dp[i], Long.MAX_VALUE);\n }\n\n for (int i = 0; i < sz - 1; i++) {\n //start from dp[i][0]\n Point c0 = layers.get(i).get(0);\n int m = layers.get(i).size();\n Point c1 = layers.get(i).get(m - 1);\n\n Point n0 = layers.get(i + 1).get(0);\n m = layers.get(i + 1).size();\n Point n1 = layers.get(i + 1).get(m - 1);\n\n dp[i + 1][1] = Math.min(dp[i + 1][1], dp[i][0] + dist(c0, n0) + dist(n0, n1));\n dp[i + 1][0] = Math.min(dp[i + 1][0], dp[i][0] + dist(c0, n1) + dist(n1, n0));\n\n dp[i + 1][1] = Math.min(dp[i + 1][1], dp[i][1] + dist(c1, n0) + dist(n0, n1));\n dp[i + 1][0] = Math.min(dp[i + 1][0], dp[i][1] + dist(c1, n1) + dist(n1, n0));\n }\n\n outln(Math.min(dp[sz - 1][0], dp[sz - 1][1]));\n }\n\n long dist(Point p1, Point p2) {\n return Math.abs(p1.x - p2.x) + Math.abs(p1.y - p2.y);\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 long gcd(long a, long b) {\n while(a != 0 && b != 0) {\n long c = b;\n b = a % b;\n a = c;\n }\n return a + b;\n }\n private void outln(Object o) {\n out.println(o);\n }\n private void out(Object o) {\n out.print(o);\n }\n private void formatPrint(double val) {\n outln(String.format(\"%.9f%n\", val));\n }\n public CFA() 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 CFA();\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", "compilation_error": false, "code_uid": "c9ceb9b499d4ac083b6b933ad6ff3193", "src_uid": "06646a9bdce2d65e92e525e97b2c975d", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.math.*;\nimport java.io.*;\nimport java.util.*;\npublic class C586E{\n public static long[] cAr, div;\n public static int N,M,K;\n public static int[] numCycle;\n public static Map> map;\n public static long MOD = 1000000007;\n public static void main(String[] args) throws IOException{\n InputReader in=new InputReader(new InputStreamReader(System.in));\n PrintWriter out=new PrintWriter(new BufferedOutputStream(System.out));\n long[] ar=in.nextLongAr();\n long A=ar[0]; long B=ar[1];\n if(gcd(A,B)!=1) System.out.println(\"Impossible\");\n else{\n while(A+B>1){\n if(B>0 && (A-1)/B > 0){ System.out.print(((A-1)/B)+\"A\");\n A%=B;}\n if(A>0 && (B-1)/A > 0){ System.out.print(((B-1)/A)+\"B\");\n B%=A;}\n }\n }\n }\n \n public static long gcd(long x,long y){\n BigInteger a = BigInteger.valueOf(x);\n BigInteger b = BigInteger.valueOf(y);\n BigInteger gcd = a.gcd(b);\n return gcd.longValue();\n }\n \n public static void setUpChoose(int t){\n cAr=new long[t+1];\n div=new long[t+1];\n cAr[0]=1;\n div[0]=1;\n \n for(int x=1;x<=t;x++){\n cAr[x]=(x*cAr[x-1])%(MOD);\n div[x]=pow(cAr[x],MOD-2);} \n }\n \n public static long choose(int x,int y){\n long a=cAr[x+y];\n long b=div[x];\n long c=div[y];\n a=(a*b)%MOD;\n a=(a*c)%MOD;\n return a;\n } \n \n public static long pow(long a,long b){\n if(b==1) \n return a;\n long c=b/2;\n long temp=pow(a,c)%MOD;\n temp=(temp*temp)%MOD;\n if(b%2==1) temp=temp*a;\n return temp%MOD;\n }\n}\n\nclass InputReader{\n private BufferedReader br;\n public InputReader(InputStreamReader in){\n br=new BufferedReader(in);\n }\n public int nextInt(){\n try{\n return Integer.parseInt(br.readLine());}\n catch(IOException e){throw new InputMismatchException();}\n }\n public int[] nextIntAr(){\n try{\n String[] s=br.readLine().split(\" \");\n int[] ret=new int[s.length];\n for(int x=0;x list = new ArrayList<>();\n for(int i = 0; i < n; i++){\n list.add(sc.nextInt());\n }\n \n ArrayList newL = new ArrayList<>();\n for(int i = 0; i < n; i++){\n int s = list.get(i);\n if(newL.size() == 0){\n newL.add(new Group(s, 1));\n } else {\n Group last = newL.get(newL.size() - 1);\n int lastVal = last.val;\n if(s == lastVal){\n last.countUp();\n } else {\n newL.add(new Group(s, 1));\n }\n }\n }\n \n int ansCount = 0;\n int l = 0;\n int r = 0;\n for(int i = 0; i < newL.size(); i++){\n Group s = newL.get(i);\n if(x == s.val){\n if(s.count > 1){\n l = i - 1;\n r = i + 1;\n int tempCount = 2;\n while(l >= 0 && r < newL.size() \n && newL.get(l).val == newL.get(r).val\n && newL.get(l).count + newL.get(r).count >= 3){\n tempCount += newL.get(r).count + newL.get(l).count;\n r += 1;\n l -= 1;\n }\n if(tempCount > ansCount){\n ansCount = tempCount;\n }\n }\n }\n }\n \n System.out.print(ansCount);\n }\n}\n\npublic class Group {\n public int val;\n public int count;\n \n public Group(int val, int count){\n this.val = val;\n this.count = count;\n }\n \n public void countUp(){\n this.count += 1;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "74af9a0bb087ed1b002061135d5b28ab", "src_uid": "d73d9610e3800817a3109314b1e6f88c", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "public class A {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n int n = scanner.nextInt();\n int m = scanner.nextInt();\n int[] x = new int[n];\n for (int i = 0; i < n; i++) {\n x[i] = scanner.nextInt();\n }\n StringBuilder s = new StringBuilder();\n int[] y = new int[m];\n for (int i = 0; i < m; i++) {\n y[i] = scanner.nextInt();\n }\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n if (x[i] == y[j]) {\n s.append(x[i]).append(\" \");\n }\n }\n }\n System.out.println(s);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "a650d1c2dababaef9c136d503c8a9565", "src_uid": "f9044a4b4c3a0c2751217d9b31cd0c72", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.lang.reflect.Array;\nimport java.util.*;\n\npublic class Main {\n static BufferedReader newInput() throws IOException {\n return new BufferedReader(new InputStreamReader(System.in));\n }\n static PrintWriter newOutput() throws IOException {\n return new PrintWriter(System.out);\n }\n public static void main(String[] args) throws IOException {\n BufferedReader in = newInput();\n PrintWriter out = newOutput();\n function(in, out);\n out.flush();\n }\n public static void function(BufferedReader in, PrintWriter out) throws IOException {\n //StringTokenizer t = new StringTokenizer(in.readLine());\n String[] nk = in.readLine().split(\" \");\n long n = Integer.parseInt(nk[0]);\n long k = Long.parseLong(nk[1]);\n ArrayList nums = new ArrayList<>();\n for (int i = 1; i <= (int)n; i++) {\n nums.add(i);\n }\n int lucks = 0;\n long fact = factorial(Math.min(n, 14));\n long x = Math.min(n, 14);\n for (int i = 1; i < Math.max(1, (int)n-13); i++) {\n nums.remove(0);\n if (isLucky((int)i)){\n lucks++;\n }\n }\n for (int i = Math.max(1, (int)n-13); i <= n; i++) {\n fact /= x;\n x--;\n int b = (int)((k-1)/fact);\n if (b >= n){\n out.println(\"-1\");\n return;\n }\n k -= (b*fact);\n int num = nums.get(b);\n nums.remove(b);\n if (isLucky(num) && isLucky(i)){\n lucks++;\n }\n }\n out.println(lucks);\n }\n public static long factorial(long num){\n long x = num;\n num--;\n for (;num != 0; num--) {\n x *= num;\n }\n return x;\n }\n public static boolean isLucky(int x){\n for (; x != 0; x /= 10) {\n int b = x % 10;\n if (b != 7 && b != 4){\n return false;\n }\n }\n return true;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "aab6858843ae202e5df8ce90083976db", "src_uid": "cb2aa02772f95fefd1856960b6ceac4c", "difficulty": 1900.0} {"lang": "Java 7", "source_code": "package dia2;\n\nimport java.util.Scanner;\n\npublic class Bender {\n\n\tstatic int n;\n\tstatic int C;\n\tstatic int x, y;\n\n\tpublic static void main(String[] args) {\n\t\tScanner s = new Scanner(System.in);\n\n\t\tn = s.nextInt();\n\t\tx = s.nextInt();\n\t\ty = s.nextInt();\n\t\tC = s.nextInt();\n\t\tint c = 0;\n\t\tlong on = compute(c);\n\t\tint step = 1;\n\t\twhile (on < C) {\n\t\t\tstep *= 2;\n\t\t\tc += step;\n\t\t\ton = compute(c);\n\t\t}\n\t\tif (c==0){\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\tint high = c;\n\t\tint low = c - step;\n\t\tint mid;\n\t\twhile (low != high) {\n\t\t\tmid = (low+high)/2;\n\t\t\ton = compute(mid);\n\t\t\tif (on < C) {\n\t\t\t\tlow = mid + 1;\n\t\t\t} else {\n\t\t\t\thigh = mid;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(low);\n\n\t}\n\n\tstatic int compute(int c) {\n\t\tint acc = 1;\n\t\tint xl;\n\t\tint xr;\n\t\tacc += Math.min(y - 1, c);\n\t\tacc += Math.min(n - y, c);\n\t\tfor (int i = 1; i <= c; i++) {\n\t\t\txl = x - i;\n\t\t\txr = x + i;\n\t\t\tif (xl > 0) {\n\t\t\t\tacc++;\n\t\t\t\tacc += Math.min(y - 1, c - i);\n\t\t\t\tacc += Math.min(n - y, c - i);\n\t\t\t}\n\t\t\tif (xr <= n) {\n\t\t\t\tacc++;\n\t\t\t\tacc += Math.min(y - 1, c - i);\n\t\t\t\tacc += Math.min(n - y, c - i);\n\t\t\t}\n\t\t}\n\t\treturn acc;\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bc616638273d98dba0b39192c8ad0bc3", "src_uid": "232c5206ee7c1903556c3625e0b0efc6", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.util.stream.*;\n\npublic class H {\n\n\tboolean solve() {\n\t\tint alph = nextInt();\n\t\tint n = nextInt();\n\n\t\tint[][] a = new int[n][];\n\t\tint tot = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint k = nextInt();\n\t\t\tint[] che = a[i] = new int[k];\n\t\t\tfor (int j = 0; j < k; j++) {\n\t\t\t\tche[j] = nextInt() - 1;\n\t\t\t}\n\t\t\ttot += k;\n\t\t}\n\n\t\tint r = (int) Math.sqrt(tot * .7);\n\n\t\tfor (int i = 0, j = n - 1;;) {\n\t\t\twhile (i < j && a[i].length > r) {\n\t\t\t\ti++;\n\t\t\t}\n\t\t\twhile (i < j && a[j].length <= r) {\n\t\t\t\tj--;\n\t\t\t}\n\t\t\tif (i == j) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tint[] tmp = a[i];\n\t\t\ta[i] = a[j];\n\t\t\ta[j] = tmp;\n\t\t}\n\t\t\n\t\tArrayList[] d = new ArrayList[alph];\n\t\tfor (int i = 0; i < alph; i++) {\n\t\t\td[i] = new ArrayList<>();\n\t\t}\n\n\t\t\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint[] b = a[i];\n\t\t\tif (b.length > r) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (int j = 0; j < b.length; j++) {\n\t\t\t\tint idx = b[j];\n\t\t\t\td[idx].add(i);\n\t\t\t\td[idx].add(j);\n\t\t\t}\n\t\t}\n\t\t\n\t\tint[] map = new int[alph];\n\t\tArrays.fill(map, -1);\n\t\t\n\t\tfor (int i = 0; i < alph; i++) {\n\t\t\tArrayList shit = d[i]; \n\t\t\tfor (int j = 0; j < shit.size(); j += 2) {\n\t\t\t\tint where = shit.get(j);\n\t\t\t\tint from = shit.get(j + 1);\n\t\t\t\t\n\t\t\t\tint[] aW = a[where];\n\t\t\t\tint put = aW[from + 1];\n\t\t\t\t\n\t\t\t\tfor (int k = from + 1; k < aW.length; k++) {\n\t\t\t\t\tint val = aW[k];\n\t\t\t\t\tif (map[val] != -1 && map[val] != put) {\n\t\t\t\t\t\treturn true; \n\t\t\t\t\t}\n\t\t\t\t\tmap[val] = put;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t\tfor (int j = 0; j < shit.size(); j += 2) {\n\t\t\t\tint where = shit.get(j);\n\t\t\t\tint from = shit.get(j + 1);\n\t\t\t\t\n\t\t\t\tint[] aW = a[where];\n\t\t\t\t\n\t\t\t\tfor (int k = from + 1; k < aW.length; k++) {\n\t\t\t\t\tmap[aW[k]] = -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint[] id = new int[alph];\n\t\tArrays.fill(id, -2);\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint[] b = a[i];\n\t\t\tif (b.length <= r) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int j = 0; j < b.length; j++) {\n\t\t\t\tid[b[j]] = j;\n\t\t\t}\n\n\t\t\tfor (int j = i + 1; j < n; j++) {\n\t\t\t\tif (clash(a[j], id)) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\n\t\t\tfor (int j = 0; j < b.length; j++) {\n\t\t\t\tid[b[j]] = -2;\n\t\t\t}\n\t\t}\n\n\t\treturn false;\n\t}\n\n\tboolean clash(int[] a, int[] f) {\n\t\tint prev = f[a[0]];\n\t\tint curMin = prev == -2 ? Integer.MAX_VALUE : prev;\n\t\tfor (int i = 1; i < a.length; i++) {\n\t\t\tint now = f[a[i]];\n\t\t\tif (now != prev + 1 && now > curMin) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (now != -2) {\n\t\t\t\tcurMin = Math.min(curMin, now);\n\t\t\t}\n\n\t\t\tprev = now;\n\t\t}\n\t\treturn false;\n\t}\n\n\tvoid submit() {\n\t\tint t = nextInt();\n\t\twhile (t-- > 0) {\n\t\t\tout.println(solve() ? \"Human\" : \"Robot\");\n\t\t}\n\t}\n\n\tvoid test() {\n\n\t}\n\n\tvoid stress() {\n\t\tfor (int tst = 0;; tst++) {\n\t\t\tif (false) {\n\t\t\t\tthrow new AssertionError();\n\t\t\t}\n\t\t\tSystem.err.println(tst);\n\t\t}\n\t}\n\n\tH() throws IOException {\n\t\tis = System.in;\n\t\tout = new PrintWriter(System.out);\n\t\tsubmit();\n\t\t// stress();\n\t\t// test();\n\t\tout.close();\n\t}\n\n\tstatic final Random rng = new Random();\n\tstatic final int C = 5;\n\n\tstatic int rand(int l, int r) {\n\t\treturn l + rng.nextInt(r - l + 1);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew H();\n\t}\n\n\tprivate InputStream is;\n\tPrintWriter out;\n\n\tprivate byte[] buf = new byte[1 << 14];\n\tprivate int bufSz = 0, bufPtr = 0;\n\n\tprivate int readByte() {\n\t\tif (bufSz == -1)\n\t\t\tthrow new RuntimeException(\"Reading past EOF\");\n\t\tif (bufPtr >= bufSz) {\n\t\t\tbufPtr = 0;\n\t\t\ttry {\n\t\t\t\tbufSz = is.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t\tif (bufSz <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[bufPtr++];\n\t}\n\n\tprivate boolean isTrash(int c) {\n\t\treturn c < 33 || c > 126;\n\t}\n\n\tprivate int skip() {\n\t\tint b;\n\t\twhile ((b = readByte()) != -1 && isTrash(b))\n\t\t\t;\n\t\treturn b;\n\t}\n\n\tString nextToken() {\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!isTrash(b)) {\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tString nextString() {\n\t\tint b = readByte();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!isTrash(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\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tchar nextChar() {\n\t\treturn (char) skip();\n\t}\n\n\tint nextInt() {\n\t\tint ret = 0;\n\t\tint b = skip();\n\t\tif (b != '-' && (b < '0' || b > '9')) {\n\t\t\tthrow new InputMismatchException();\n\t\t}\n\t\tboolean neg = false;\n\t\tif (b == '-') {\n\t\t\tneg = true;\n\t\t\tb = readByte();\n\t\t}\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tret = ret * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\tif (b != -1 && !isTrash(b)) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\treturn neg ? -ret : ret;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\n\tlong nextLong() {\n\t\tlong ret = 0;\n\t\tint b = skip();\n\t\tif (b != '-' && (b < '0' || b > '9')) {\n\t\t\tthrow new InputMismatchException();\n\t\t}\n\t\tboolean neg = false;\n\t\tif (b == '-') {\n\t\t\tneg = true;\n\t\t\tb = readByte();\n\t\t}\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tret = ret * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\tif (b != -1 && !isTrash(b)) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\treturn neg ? -ret : ret;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7eaf6d123aa91a8ee2415ab5da9c4ee9", "src_uid": "d742933184ce1cad098fcb8a264df630", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "//package que_a;\n\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class utkarsh {\n\n InputStream is;\n PrintWriter out;\n \n long mod = (long) (1e9 + 7), inf = (long) (8e18);\n boolean SHOW_TIME, debug;\n \n long fact[], inv[];\n \n void getF(int n) {\n fact = new long[n];\n inv = new long[n];\n fact[0] = fact[1] = 1;\n inv[0] = inv[1] = 1;\n for(int i = 2; i < n; i++) {\n fact[i] = (fact[i-1] * i) % mod;\n inv[i] = mp(fact[i], mod - 2);\n }\n }\n \n void solve() {\n //Enter code here utkarsh\n //SHOW_TIME = true;\n\t//debug = true;\n int n = ni(), k = ni();\n long ans[] = new long[k + 123];\n for(int i = 1; i < k+123; i++) {\n ans[i] = ans[i-1] + mp(i, k);\n if(ans[i] >= mod) ans[i] -= mod;\n }\n if(n < k+123) out.println(ans[n] % mod);\n else {\n getF(k+123);\n \n long s = 0;\n int p = 1;\n for(int i = k+122; i >= 1; i--) {\n s += mp(n-i, mod-2) * inv[i-1] % mod * inv[k+122-i] % mod * ans[i] * p;\n if(s >= inf) s -= inf;\n if(s <= -inf) s += inf;\n p = -p;\n }\n s %= mod;\n if(s < 0) s += mod;\n long m = 1;\n for(int i = 1; i < k+123; i++) {\n m = m * (n-i) % mod;\n }\n out.println(s * m % mod);\n }\n }\n \n long mp(long b, long e) {\n long r = 1;\n while(e > 0) {\n if((e&1) == 1) r = (r * b) % mod;\n b = (b * b) % mod;\n e >>= 1;\n }\n return r;\n }\n\n //---------- I/O Template ----------\n \n public static void main(String[] args) { new utkarsh().run(); }\n void run() { \n is = System.in; \n out = new PrintWriter(System.out);\n long start = System.currentTimeMillis(); \n solve(); \n long end = System.currentTimeMillis();\n if(SHOW_TIME) out.println(\"\\n\" + (end - start) + \" ms\");\n out.flush();\n }\n \n byte input[] = new byte[1024];\n int len = 0, ptr = 0;\n \n int readByte() { \n if(ptr >= len) { ptr = 0; \n try { len = is.read(input); } \n catch(IOException e) { throw new InputMismatchException(); } \n if(len <= 0) { return -1; } \n } return input[ptr++];\n }\n boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }\n int skip() { \n int b = readByte(); \n while(b != -1 && isSpaceChar(b)) { b = readByte(); } \n return b;\n }\n \n char nc() { return (char)skip(); }\n String ns() { \n int b = skip(); \n StringBuilder sb = new StringBuilder(); \n while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); } \n return sb.toString();\n }\n String nLine() { \n int b = skip(); \n StringBuilder sb = new StringBuilder(); \n while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); } \n return sb.toString();\n }\n int ni() { \n int n = 0, b = readByte(); \n boolean minus = false; \n while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); } \n if(b == '-') { minus = true; b = readByte(); } \n if(b == -1) { return -1; } //no input \n while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); } \n return minus ? -n : n;\n }\n long nl() { \n long n = 0L; int b = readByte(); \n boolean minus = false; \n while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); } \n if(b == '-') { minus = true; b = readByte(); } \n while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); } \n return minus ? -n : n;\n }\n\n double nd() { return Double.parseDouble(ns()); }\n float nf() { return Float.parseFloat(ns()); }\n int[] na(int n) { \n int a[] = new int[n]; \n for(int i = 0; i < n; i++) { a[i] = ni(); } \n return a;\n }\n char[] ns(int n) { \n char c[] = new char[n]; \n int i, b = skip(); \n for(i = 0; i < n; i++) { \n if(isSpaceChar(b)) { break; } \n c[i] = (char)b; b = readByte(); \n } return i == n ? c : Arrays.copyOf(c,i);\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "708cbbfff954a8f1c7bd80ef3d3fb159", "src_uid": "6f6fc42a367cdce60d76fd1914e73f0c", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "/*package whatever //do not write package name here */\n\nimport java.io.*;\nimport java.util.*;\n\npublic class GFG {\n\tpublic static void main (String[] args) {\n\tScanner sc=new Scanner(System.in);\n\tint n=sc.nextInt();\n\tint m=sc.nextInt();\n\tint m1=m;\n\tint[] a=new int[n];\n\tint max=0;\n\tfor(int i=0;imax)\n\t max=a[i];\n\t}\n\tArrays.sort(a);\n\tfor(int i=0;imax1)\n\t max1=a[i];\n\t}\n\t\tint q=m/n;\n\tm=m%n;\n \n\t//System.out.println(q);\n\tSystem.out.print(max1+q+(m>0?1:0)+\" \");\n\t\tSystem.out.print(max+m1);\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "44bab1fad51d804b4687587b68c30dde", "src_uid": "78f696bd954c9f0f9bb502e515d85a8d", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.io.*;\r\nimport java.util.*;\r\n \r\npublic class MikesSequence {\r\n private static int[] ratings = [1200,1400,1600,1900,2100,2300,2400,2600,3000];\r\n\r\n public static void main(String[] args) throws IOException {\r\n FastScanner in = new FastScanner();\r\n PrintWriter out = new PrintWriter(System.out);\r\n int n = in.nextInt();\r\n \r\n for (int i = 0; i < ratings.length; i++) {\r\n if (n < ratings[i]) {\r\n \tout.println(ratings[i]);\r\n \tbreak;\r\n }\r\n }\r\n out.close();\r\n }\r\n \r\n static class FastScanner {\r\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\r\n StringTokenizer st=new StringTokenizer(\"\");\r\n String next() {\r\n while (!st.hasMoreTokens())\r\n try { \r\n st = new StringTokenizer(br.readLine()); \r\n } catch (IOException e) {\r\n // noop\r\n }\r\n return st.nextToken();\r\n }\r\n \r\n int nextInt() {\r\n return Integer.parseInt(next());\r\n }\r\n long nextLong() {\r\n return Long.parseLong(next());\r\n }\r\n double nextDouble() {\r\n return Double.parseDouble(next());\r\n }\r\n }\r\n\r\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5a4c287ad8655582b406158a06a37674", "src_uid": "22725effa6dc68b9c2a499d148e613c2", "difficulty": -1.0} {"lang": "Java 8", "source_code": "package cf;\n\nimport 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.ArrayList;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashSet;\nimport java.util.List;\nimport java.util.Set;\nimport java.util.StringTokenizer;\n\npublic class C {\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\tTaskF solver = new TaskF();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n\n\tstatic class TaskF {\n\n\t\tpublic void solve(int testNumber, InputReader in, PrintWriter out) {\n\t\t\tint n = in.nextInt();\n\t\t\tint l = in.nextInt();\n\t\t\tint r = in.nextInt();\n\t\t\tlong mod[][] = new long[3][n + 1];\n\n\t\t\tint x = (r - l + 1) / 3;\n\t\t\tint y = (r - l + 1) % 3;\n\t\t\tmod[0][1] = x;\n\t\t\tmod[1][1] = x;\n\t\t\tmod[2][1] = x;\n\n\t\t\tif (y == 1) {\n\t\t\t\tmod[l % 3][1]++;\n\t\t\t} else if (y == 2) {\n\t\t\t\tmod[l % 3][1]++;\n\t\t\t\tmod[r % 3][1]++;\n\t\t\t}\n\n\t\t\tlong mm = 1000000007;\n\t\t\tfor (int i = 2; i < n + 1; i++) {\n\t\t\t\tmod[0][i] = (mod[0][1] * mod[0][i - 1] + mod[1][1] * mod[2][i - 1] + mod[2][1] * mod[1][i - 1]) % mm;\n\t\t\t\tmod[1][i] = (mod[0][1] * mod[1][i - 1] + mod[1][1] * mod[0][i - 1] + mod[2][1] * mod[2][i - 1]) % mm;\n\t\t\t\tmod[2][i] = (mod[0][1] * mod[2][i - 1] + mod[2][1] * mod[0][i - 1] + mod[1][1] * mod[1][i - 1]) % mm;\n\t\t\t}\n\t\t\tout.println(mod[0][n]);\n\t\t}\n\n\t}\n\n\tstatic class InputReader {\n\t\tpublic BufferedReader reader;\n\t\tpublic StringTokenizer tokenizer;\n\n\t\tpublic InputReader(InputStream stream) {\n\t\t\treader = new BufferedReader(new InputStreamReader(stream), 32768);\n\t\t\ttokenizer = null;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e983ddfbed9024db72b07a95f560512d", "src_uid": "4c4852df62fccb0a19ad8bc41145de61", "difficulty": 1500.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Main {\n public static void main(String ...args) throws Throwable {\n Scanner in = new Scanner(System.in);\n String init = in.nextLine();\n HashSet h = new HashSet();\n for (int len = init.length() - 1; i >= 1; --i) {\n h.clear();\n for (int pos = 0; pos + len <= init.length(); ++pos) {\n String now = init.substring(pos, pos + len);\n if (h.contains(now)) {\n System.out.println(now);\n return;\n }\n }\n\n }\n\n }\n}\n ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3491d441ea74c2da25ca2e84bd340d74", "src_uid": "13b5cf94f2fabd053375a5ccf3fd44c7", "difficulty": 1200.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class Round207A {\n \n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n \n int m = sc.nextInt();\n int[] c = new int[m];\n for (int i=0; i= x && numBiginners < y &&\n (numChildlen - numBiginners) >= x && (numChildlen - numBiginners) < y) {\n rate = i + 1;\n break;\n }\n if (numBiginners > y) {\n rate = 0;\n break;\n}\n }\n \n return rate;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "6fbb45a6513cda36c0c0abf11a5836d2", "src_uid": "e595a1d0c0e4bbcc99454d3148b4557b", "difficulty": 1000.0} {"lang": "Java 7", "source_code": "import java.util.*;\npublic class Ganesha {\n\n public static void main (String [] args){\n\n \tScanner in = new Scanner(System.in);\n\n \t long a = in.nextLong();\n \t long b = in.nextLong();\n \t long w = in.nextLong();\n \t long x = in.nextLong();\n \t long c = in.nextLong();\n \t w=w-x;\n\n \t if(c<=a)\n \t \tSystem.out.print(\"0\");\n\n \t \telse if(c>a){\n \t \t\tif(b>=(c-a)*x)\n \t \t\t\tSystem.out.print((c-a));\n\n \t \t\t\telse{\n System.out.print((c-a +)Math.ceil((double)(((c-a)*x-b))/w)));\n\n\n \t \t\t\t}\n\n \t \t}\n }\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "cf1422d7c9b1570f9f0040cc533cf37f", "src_uid": "a1db3dd9f8d0f0cad7bdeb1780707143", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class Taska{\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 TaskE solver = new TaskE();\n solver.solve(1, in, out);\n out.flush();out.close();\n }\n static class TaskE {\n long a[][]=new long[2][3];\n int t=1;\n long gcd(long a,long b){\n \tif(a%b==0)return b;\n \treturn gcd(b,a%b);\n }\n long find(long v){\n long b[]={a[t][1],a[t][1]-v};\n long c[]={a[t][0],b[1]-(a[1-t][1]-a[1-t][0])};\n return Math.min(b[0],b[1])-Math.max(c[0],c[1])+1;\n }\n\t\tpublic void solve(int testNumber, InputReader in, PrintWriter out) {\n \t\t\tfor(int i=0;i<2;i++){\n for(int j=0;j<3;j++)a[i][j]=in.nextLong();\n }\n if(a[0][1]>a[1][1]){\n t=0;\n }\n \t\t\tlong gcd=gcd(a[t][2],a[1-t][2]);\n \t\t\tlong val=a[t][1]-a[1-t][1];\n long val1=val%gcd;\n \t\t\tlong val2=val1-gcd;\n out.print(Math.max(Math.max(find(val1),0),Math.max(find(val2),0)));\n }\n// pair ja[][];long w[];int from[],to[],c[];\n// void make(int n,int m,InputReader in){\n// ja=new pair[n+1][];w=new long[m];from=new int[m];to=new int[m];c=new int[n+1];\n// for(int i=0;i>>16)]++;\n//\t\t\tfor(int i = 1;i <= 65536;i++)b[i]+=b[i-1];\n//\t\t\tfor(int i = 0;i < n;i++)to[b[f[i]>>>16]++] = f[i];\n//\t\t\tint[] d = f; f = to;to = d;\n//\t\t}\n//\t\treturn f;\n//\t}\n }\n static class InputReader {\n BufferedReader br;\n StringTokenizer st;\n public InputReader(InputStream stream) {\n br = new BufferedReader(new InputStreamReader(stream));\n st = null;\n }\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return null;\n st = new StringTokenizer(s);\n }\n return st.nextToken();\n }\n\n boolean hasMoreTokens() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return false;\n st = new StringTokenizer(s);\n }\n return true;\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n public long nextLong() {\n return Long.parseLong(next());\n }\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7c583901a38826352e9145dddbf1b63c", "src_uid": "faa75751c05c3ff919ddd148c6784910", "difficulty": 1900.0} {"lang": "Java 11", "source_code": "//I AM THE CREED\n/* package codechef; // don't place package name! */\nimport java.io.BufferedReader; \nimport java.io.IOException; \nimport java.io.InputStreamReader; \nimport java.util.StringTokenizer; \nimport java.util.*;\n \npublic class HelloWorld{\n public static void main(String[] args) throws IOException \n { \n \n Scanner input = new Scanner(System.in);\n while(input.hasNext()){\n int n=input.nextInt();\n System.out.println(1+(n/2))\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "384d47c3b974d9ec53cf4d56a03564b3", "src_uid": "5551742f6ab39fdac3930d866f439e3e", "difficulty": 800.0} {"lang": "Java 7", "source_code": "import java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.NoSuchElementException;\nimport java.math.BigInteger;\nimport java.io.OutputStream;\nimport java.util.Collections;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.io.InputStream;\nimport java.io.OutputStreamWriter;\nimport java.util.Comparator;\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\tOutputWriter out = new OutputWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int n = in.readInt();\n int k = in.readInt();\n long S = in.readLong();\n long[] a = IOUtils.readLongArray(in, n);\n\n long[] fact = new long[100];\n fact[0] = 1;\n int numFacts = 0;\n for (int i = 1; i < fact.length; i++) {\n if (fact[i - 1] * i <= S) {\n fact[i] = fact[i - 1] * i;\n numFacts = i;\n } else {\n break;\n }\n }\n fact = Arrays.copyOf(fact, numFacts + 1);\n if (n == 1) {\n if (S == 0 || S == a[0] || (a[0] < fact.length && k > 0 && fact[(int) a[0]] == S)) {\n out.printLine(1);\n } else {\n out.printLine(0);\n }\n return;\n }\n\n int n1 = n / 2;\n int n2 = n - n1;\n long[] a1 = Arrays.copyOfRange(a, 0, n1);\n long[] a2 = Arrays.copyOfRange(a, n1, n1 + n2);\n int capacity1 = (int) Math.pow(3, n1) + 1;\n int capacity2 = (int) Math.pow(3, n2) + 1;\n List list1 = new ArrayList(capacity1);\n List list2 = new ArrayList(capacity2);\n gen(a1, list1, fact, S, k, 0L, 0, 0);\n gen(a2, list2, fact, S, k, 0L, 0, 0);\n\n Comparator cmp = new Comparator() {\n public int compare(EzLongIntPair o1, EzLongIntPair o2) {\n if (o1.first < o2.first) return -1;\n if (o1.first > o2.first) return 1;\n return o1.second - o2.second;\n }\n };\n Collections.sort(list1, cmp);\n Collections.sort(list2, cmp);\n\n int[] cntK = new int[k + 1];\n int[] sumsK = new int[k + 1];\n EzLongIntPair toFind = new EzLongIntPair(0, 0);\n long ans = 0;\n \n for (int i = 0; i < list1.size(); ) {\n int j = i;\n long sum1 = list1.get(i).first;\n while (j < list1.size() && list1.get(j).first == sum1) {\n j++;\n }\n\n Arrays.fill(cntK, 0);\n for (int z = i; z < j; z++) {\n cntK[list1.get(z).second]++;\n }\n sumsK[0] = cntK[0];\n for (int t = 1; t < cntK.length; t++) {\n sumsK[t] = sumsK[t - 1] + cntK[t];\n }\n\n toFind.first = S - sum1;\n toFind.second = -100500;\n int L2 = ~Collections.binarySearch(list2, toFind, cmp);\n toFind.second = 100500;\n int R2 = ~Collections.binarySearch(list2, toFind, cmp);\n \n for (int z = L2; z < R2; z++) {\n int k2 = list2.get(z).second;\n if (k - k2 >= 0) {\n ans += sumsK[k - k2];\n }\n }\n \n i = j;\n }\n out.printLine(ans);\n }\n\n private void gen(long[] a, List list, long[] fact, long maxS, int maxK, long curS, int curK, int i) {\n if (curS > maxS || curK > maxK) {\n return;\n }\n if (i == a.length) {\n list.add(new EzLongIntPair(curS, curK));\n return;\n }\n gen(a, list, fact, maxS, maxK, curS, curK, i + 1);\n gen(a, list, fact, maxS, maxK, curS + a[i], curK, i + 1);\n if (a[i] < fact.length) {\n gen(a, list, fact, maxS, maxK, curS + fact[(int) a[i]], curK + 1, i + 1);\n }\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 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 public 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 public 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 public void close() {\n\t\twriter.close();\n\t}\n\n\tpublic void printLine(long i) {\n\t\twriter.println(i);\n\t}\n\n\tpublic void printLine(int i) {\n\t\twriter.println(i);\n\t}\n}\n\nclass IOUtils {\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}\n\nclass EzLongIntPair {\n private static final int HASHCODE_INITIAL_VALUE = 0x811c9dc5;\n private static final int HASHCODE_MULTIPLIER = 0x01000193;\n\n public long first;\n public int second;\n\n public EzLongIntPair(long first, int 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 EzLongIntPair that = (EzLongIntPair) o;\n\n return first == that.first && second == that.second;\n }\n\n public int hashCode() {\n int hash = HASHCODE_INITIAL_VALUE;\n hash = (hash ^ PrimitiveHashCalculator.getHash(first)) * HASHCODE_MULTIPLIER;\n hash = (hash ^ PrimitiveHashCalculator.getHash(second)) * HASHCODE_MULTIPLIER;\n return hash;\n }\n\n public String toString() {\n return \"(\" + first + \", \" + second + \")\";\n }\n}\n\nclass PrimitiveHashCalculator {\n\n\tpublic static int getHash(int x) {\n return x;\n }\n\n public static int getHash(long x) {\n return (int)x ^ (int)(x >>> 32);\n }\n\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "31c5f148290bd4353857e9f03c61a410", "src_uid": "2821a11066dffc7e8f6a60a8751cea37", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.NoSuchElementException;\n\npublic class C {\n private static class Task {\n boolean check(long n, long p) {\n long ans = 0;\n for (long k = 2; k * k * k <= n; k++) {\n ans += n / (k * k * k);\n if (ans > p) break;\n }\n return ans == p;\n }\n\n void solve(FastScanner in, PrintWriter out) {\n long p = in.nextLong();\n\n long h = 100000000000000;\n long l = 0;\n while (h - l > 1) {\n long n = (h + l) / 2;\n long ans = 0;\n for (long k = 2; k * k * k <= n; k++) {\n ans += n / (k * k * k);\n if (ans > p) break;\n }\n if (ans >= p) {\n h = n;\n } else {\n l = n;\n }\n }\n\n for (long n = Math.max(1, l + 1 - 10); n < l + 1 + 10; n++) {\n if (check(n, p)) {\n out.println(n);\n return;\n }\n }\n out.println(-1);\n }\n }\n\n // Template\n public static void main(String[] args) {\n OutputStream outputStream = System.out;\n FastScanner in = new FastScanner();\n PrintWriter out = new PrintWriter(outputStream);\n Task solver = new Task();\n solver.solve(in, out);\n out.close();\n }\n private static class FastScanner {\n private final InputStream in = System.in;\n private final byte[] buffer = new byte[1024];\n private int ptr = 0;\n private int bufferLength = 0;\n\n private boolean hasNextByte() {\n if (ptr < bufferLength) {\n return true;\n } else {\n ptr = 0;\n try {\n bufferLength = in.read(buffer);\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (bufferLength <= 0) {\n return false;\n }\n }\n return true;\n }\n\n private int readByte() {\n if (hasNextByte()) return buffer[ptr++];\n else return -1;\n }\n\n private static boolean isPrintableChar(int c) {\n return 33 <= c && c <= 126;\n }\n\n private void skipUnprintable() {\n while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;\n }\n\n boolean hasNext() {\n skipUnprintable();\n return hasNextByte();\n }\n\n public String next() {\n if (!hasNext()) throw new NoSuchElementException();\n StringBuilder sb = new StringBuilder();\n int b = readByte();\n while (isPrintableChar(b)) {\n sb.appendCodePoint(b);\n b = readByte();\n }\n return sb.toString();\n }\n\n long nextLong() {\n if (!hasNext()) throw new NoSuchElementException();\n long n = 0;\n boolean minus = false;\n int b = readByte();\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n if (b < '0' || '9' < b) {\n throw new NumberFormatException();\n }\n while (true) {\n if ('0' <= b && b <= '9') {\n n *= 10;\n n += b - '0';\n } else if (b == -1 || !isPrintableChar(b)) {\n return minus ? -n : n;\n } else {\n throw new NumberFormatException();\n }\n b = readByte();\n }\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n double[] nextDoubleArray(int n) {\n double[] array = new double[n];\n for (int i = 0; i < n; i++) {\n array[i] = nextDouble();\n }\n return array;\n }\n\n double[][] nextDoubleMap(int n, int m) {\n double[][] map = new double[n][];\n for (int i = 0; i < n; i++) {\n map[i] = nextDoubleArray(m);\n }\n return map;\n }\n\n public int nextInt() {\n return (int) nextLong();\n }\n\n public int[] nextIntArray(int n) {\n int[] array = new int[n];\n for (int i = 0; i < n; i++) {\n array[i] = nextInt();\n }\n return array;\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2f5ea7e8b7855788d95a55e54adec20d", "src_uid": "602deaad5c66e264997249457d555129", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF1156G {\n\tstatic class V {\n\t\tString s;\n\t\tchar op = ' ';\n\t\tV u, v;\n\t\tint d;\n\t\tV(String s) {\n\t\t\tthis.s = s;\n\t\t}\n\t\tV(char op, V u, V v) {\n\t\t\tthis.op = op; this.u = u; this.v = v;\n\t\t\td = Math.max(u.d, v.d) + 1;\n\t\t}\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn s + \"=\" + u.s + op + v.s;\n\t\t}\n\t}\n\tstatic ArrayList list = new ArrayList<>();\n\tstatic HashSet set = new HashSet<>();\n\tstatic Random rand = new Random();\n\tstatic String getX() {\n\t\tString s;\n\t\tdo {\n\t\t\tchar x = (char) ('a' + rand.nextInt(26));\n\t\t\ts = \"\" + x + rand.nextInt(1000);\n\t\t} while (set.contains(s));\n\t\treturn s;\n\t}\n\tstatic void dfs(V w, String s) {\n\t\tif (w.d == 0)\n\t\t\treturn;\n\t\tif (w.s == null) {\n\t\t\tw.s = s;\n\t\t\tlist.add(w);\n\t\t\tdfs(w.u, getX());\n\t\t\tdfs(w.v, getX());\n\t\t}\n\t}\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tint n = Integer.parseInt(br.readLine());\n\t\tHashMap mp = new HashMap<>();\n\t\twhile (n-- > 0) {\n\t\t\tchar[] cc = br.readLine().toCharArray();\n\t\t\tint m = cc.length;\n\t\t\tint p = -1, q = -1;\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t\tif (cc[j] == '=')\n\t\t\t\t\tp = j;\n\t\t\t\telse if (cc[j] == '$' || cc[j] == '^' || cc[j] == '#' || cc[j] == '&')\n\t\t\t\t\tq = j;\n\t\t\tString lvalue = new String(cc, 0, p);\n\t\t\tset.add(lvalue);\n\t\t\tif (q == -1) {\n\t\t\t\tString rvalue = new String(cc, p + 1, m - p - 1);\n\t\t\t\tset.add(rvalue);\n\t\t\t\tV v = mp.get(rvalue);\n\t\t\t\tif (v == null) {\n\t\t\t\t\tv = new V(rvalue);\n\t\t\t\t\tmp.put(rvalue, v);\n\t\t\t\t}\n\t\t\t\tmp.put(lvalue, v);\n\t\t\t} else {\n\t\t\t\tString arg1 = new String(cc, p + 1, q - p - 1);\n\t\t\t\tString arg2 = new String(cc, q + 1, m - q - 1);\n\t\t\t\tset.add(arg1);\n\t\t\t\tset.add(arg2);\n\t\t\t\tchar op = cc[q];\n\t\t\t\tV u = mp.get(arg1);\n\t\t\t\tif (u == null) {\n\t\t\t\t\tu = new V(arg1);\n\t\t\t\t\tmp.put(arg1, u);\n\t\t\t\t}\n\t\t\t\tV v = mp.get(arg2);\n\t\t\t\tif (v == null) {\n\t\t\t\t\tv = new V(arg2);\n\t\t\t\t\tmp.put(arg2, v);\n\t\t\t\t}\n\t\t\t\tV w = new V(op, u, v);\n\t\t\t\tmp.put(lvalue, w);\n\t\t\t}\n\t\t}\n\t\tV w = mp.get(\"res\");\n\t\tif (w == null) {\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\tdfs(w, \"res\");\n\t\tif (list.size() == 0 && w.op == ' ') {\n\t\t\tif (w.s.equals(\"res\"))\n\t\t\t\tSystem.out.println(0);\n\t\t\telse {\n\t\t\t\tSystem.out.println(1);\n\t\t\t\tSystem.out.println(\"res=\" + w.s);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tCollections.sort(list, (u, v) -> u.d - v.d);\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\tpw.println(list.size());\n\t\tfor (V v : list)\n\t\t\tpw.println(v);\n\t\tpw.close();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2633ec876fdd92e45c8a8fa98fb685c9", "src_uid": "da40321d92baaef42c2840e45599294c", "difficulty": 2700.0} {"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;\nimport java.util.Collection;\nimport java.util.Locale;\n\n/*\n\ufffd\ufffd\ufffd\ufffd\ufffdI\ufffd\u0216\ufffd\ufffdB\n\ufffdJ\ufffd\ufffd\u0502\ufffd\ufffd\ufffd\ufffdA\ufffd\ue3c0\ufffd\u030e\ufffd\ufffd\ufffdA\ufffd\ufffd\ufffd[\ufffdv\ufffd\ufffd\ufffd\ufffd\ufffd\u0310\u0752\ufffd\u030ed\ufffd\ufffdA\n\ufffd\u03c2\ufffd\ufffdl\ufffd\u0310\u0752\ufffd\u030ed\ufffd\ufffd|\ufffdC\ufffd\ufffd\ufffdg\ufffdB\n*/\npublic class TaskB {\n\tBufferedReader reader;\n\tStringTokenizer tokenizer = null;\n\tPrintWriter writer;\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tnew TaskB().run();\n\t\t} catch(IOException e) {\n\t\t}\t\n\t}\n\n\tvoid run() throws IOException {\n\t\ttokenizer = null;\n\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\twriter = new PrintWriter(System.out);\n\t\tsolve();\n\t\twriter.flush();\n\t}\n\n\tprivate void solve() throws IOException {\n\n\t\tint vp = nextInt();\n\t\tint vd = nextInt();\n\t\tint t = nextInt();\n\t\tint f = nextInt();\n\t\tint c = nextInt();\n\n\t\t//int ttake = (vp * t) / (vd - vp);\n\t\t//int dis = vp * (t + ttake);\n\t\t//int less = c - dis;\n\t\tdouble ttake = (vp * t) / (vd - vp);\n\t\tdouble dis = vp * (t + ttake);\n\t\tdouble less = c - dis;\n\t\tint count = 0;\n\t\tdouble EPS = 1e-9;\n\t\t\n\t\twhile (less > EPS) {\n\t\t\tcount++;\n\t\t\tt = t + 2 * ttake + f;\n\t\t\tttake = (vp * t) / (vd - vp);\n\t\t\tdis = vp * (t + ttake);\n\t\t\tless = c - dis;\n\t\t}\n\t\t\n/*\t\tint t0 = (vp * t) / (vd - vp);\n\t\tint T = t + t0;\n\t\t//int t0 = (vp * t) / (vd - vp) + t;\n\t\tint end = (c - vp * t) / vp + t;\n\t\tint count = 0;\n\t\tfor (int i = 0; ; i++) {\n\t\t\tif (T < end) {\n\t\t\t\tcount++;\n\t\t\t\t//t = T + ((vp * T)/vd) + f;\n\t\t\t\tt = T + t0 + f;\n\t\t\t\tt0 = (vp * t) / (vd - vp);\n\t\t\t\tT = t + t0;\n\t\t\t\t//count++;\n\t\t\t} else {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t//if (t0 >= end) break;\n\t\t\t//if (T >= end) break;\n\t\t\t//else count++;\n\t\t}\n*/\n\t\twriter.print(count);\n\t}\n\n\t/********************** \n\t* Input \n\t***********************/\n\t//BufferedReader in;\n\tPrintWriter out;\n\t//StringTokenizer st = new StringTokenizer(\"\");\n\n\tString nextToken() throws IOException {\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens())\n\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\treturn tokenizer.nextToken();\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\tint[] nextIntArray(int size) throws IOException {\n\t\tint[] ret = new int [size];\n\t\tfor (int i = 0; i < size; i++)\n\t\t\tret[i] = nextInt();\n\t\treturn ret;\n\t}\n \n\tlong[] nextLongArray(int size) throws IOException {\n\t\tlong[] ret = new long [size];\n\t\tfor (int i = 0; i < size; i++)\n\t\t\tret[i] = nextLong();\n\t\treturn ret;\n\t}\n \n\tdouble[] nextDoubleArray(int size) throws IOException {\n\t\tdouble[] ret = new double [size];\n\t\tfor (int i = 0; i < size; i++)\n\t\t\tret[i] = nextDouble();\n\t\treturn ret;\n\t}\n\n\tString nextLine() throws IOException {\n\t\t//if (tokenizer == null || !tokenizer.hasMoreTokens())\n\t\t\t//tokenizer = new StringTokenizer(\"\");\n\t\t//return in.readLine();\n\t\tif (tokenizer != null) return tokenizer.nextToken();\n\t\treturn reader.readLine();\n\t}\n\n boolean EOF() throws IOException {\n\t\twhile (!tokenizer.hasMoreTokens()) {\n\t\t\tString s = reader.readLine();\n\t\t\tif (s == null)\n\t\t\t\treturn true;\n \t\t\ttokenizer = new StringTokenizer(s);\n\t\t}\n\t\treturn false;\n\t}\n\n\t/********************** \n\t* Output \n\t***********************/\n\tvoid printRepeat(String s, int count) {\n\t\tfor (int i = 0; i < count; i++)\n \t\tout.print(s);\n\t}\n\n\tvoid printArray(int[] array) {\n\t\tif (array == null || array.length == 0)\n\t\t\treturn;\n\t\tfor (int i = 0; i < array.length; i++) {\n \tif (i > 0) out.print(' ');\n \tout.print(array[i]);\n\t\t}\n\t\tout.println();\n\t}\n\n\tvoid printArray(long[] array) {\n\t\t\tif (array == null || array.length == 0)\n\t\t\t\treturn;\n\t\t\tfor (int i = 0; i < array.length; i++) {\n\t\t\t\tif (i > 0) out.print(' ');\n\t\t\t\t\tout.print(array[i]);\n\t\t\t}\n\t\t\tout.println();\n\t}\n \n\tvoid printArray(double[] array) {\n\t\tif (array == null || array.length == 0)\n\t\t\treturn;\n\t\tfor (int i = 0; i < array.length; i++) {\n\t\t\tif (i > 0) out.print(' ');\n\t\t\t\tout.print(array[i]);\n\t\t}\n\t\tout.println();\n\t}\n\n\tvoid printArray(double[] array, String spec) {\n\t\tif (array == null || array.length == 0)\n\t\t\treturn;\n\t\tfor (int i = 0; i < array.length; i++) {\n\t\t\tif (i > 0) out.print(' ');\n\t\t\t\tout.printf(Locale.US, spec, array[i]);\n\t\t}\n\t\tout.println();\n\t}\n\n\tvoid printArray(Object[] array) {\n\t\tif (array == null || array.length == 0)\n\t\t\treturn;\n\t\tboolean blank = false;\n\t\tfor (Object x : array) {\n\t\t\tif (blank) out.print(' '); else blank = true;\n\t\t\t\tout.print(x);\n\t\t}\n\t\tout.println();\n\t}\n \n\t@SuppressWarnings(\"rawtypes\")\n\tvoid printCollection(Collection collection) {\n\t\tif (collection == null || collection.isEmpty())\n\t\t\treturn;\n\t\tboolean blank = false;\n\t\tfor (Object x : collection) {\n\t\t\tif (blank) out.print(' '); else blank = true;\n\t\t\t\tout.print(x);\n\t\t}\n\t\tout.println();\n\t}\n\n\t/********************** \n\t* Utility \n\t***********************/\n\n\tstatic String memoryStatus() {\n\t\treturn (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory() >> 20) + \"/\" + (Runtime.getRuntime().totalMemory() >> 20) + \" MB\";\n\t}\n\t\t\n\tstatic void checkMemory() {\n\t\tSystem.err.println(memoryStatus());\n\t}\n\t\t\n\tstatic long prevTimeStamp = Long.MIN_VALUE;\n\t\n\tstatic void updateTimer() {\n\t\tprevTimeStamp = System.currentTimeMillis();\n\t}\n\n\tstatic long elapsedTime() {\n\t\treturn (System.currentTimeMillis() - prevTimeStamp);\n\t}\n\n\tstatic void checkTimer() {\n\t\tSystem.err.println(elapsedTime() + \" ms\");\n\t}\n}\n/*\njava.lang.NumberFormatException: For input string: \"444444444444\"\n\tat java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)\n\tat java.lang.Integer.parseInt(Integer.java:461)\n\tat java.lang.Integer.parseInt(Integer.java:499)\n\tat T...\n\njava.lang.NullPointerException\n\tat TaskA.nextLine(TaskA.java:133)\n\tat TaskA.solve(TaskA.java:51)\n\tat TaskA.run(TaskA.java:29)\n\tat TaskA.main(TaskA.java:20)\n\t\n*/", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0fd5677b203d6623d63bf6138b352cca", "src_uid": "c9c03666278acec35f0e273691fe0fff", "difficulty": 1500.0} {"lang": "Java 7", "source_code": "\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport static java.util.Arrays.*;\n\npublic class A {\n private static final int mod = (int)1e9+7;\n\n IOFast io = new IOFast();\n \n long ans = 0;\n long min = Long.MIN_VALUE;\n void rec(long v, long x, long cur) {\n if(v == 0) return;\n if(min > v || min == v && cur < ans) return;\n if(v < 0) {\n if(min < v || min == v && cur > ans) {\n min = v;\n ans = cur;\n }\n return;\n }\n if(x * 3 <= v || x == 0) {\n return;\n }\n for(int i = 0; i < 3 && x * i != v; i++) {\n rec(v - x * i, x / 3, cur * 3 + i);\n }\n }\n \n public void run() throws IOException {\n long v = io.nextLong();\n long x;\n long res = 0;\n int cnt = 1;\n for(x = 1; x <= v; x *= 3) cnt++;\n int[] use = new int[cnt + 10];\n for(int i = cnt - 1; v != 0; x /= 3, i--) {\n use[i] = (int)(v / x);\n v %= x;\n }\n for(int i = 0; i < cnt; i++) {\n if(use[i] != 0) {\n int c = 1;\n long val = 1;\n for(int j = i + 1; j < use.length; j++) {\n use[j] += c;\n c = 0;\n if(use[j] == 3) {\n use[j] = 0;\n c = 1;\n }\n res += use[j] * val;\n val *= 3;\n }\n break;\n }\n }\n io.out.println(res);\n }\n\n \n \n void main() throws IOException {\n // IOFast.setFileIO(\"rle-size.in\", \"rle-size.out\");\n try {\n run();\n }\n catch (EndOfFileRuntimeException e) { }\n io.out.flush();\n }\n\n public static void main(String[] args) throws IOException {\n new A().main();\n }\n \n static class EndOfFileRuntimeException extends RuntimeException {\n private static final long serialVersionUID = -8565341110209207657L; }\n\n static\n public class IOFast {\n private BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n private PrintWriter out = new PrintWriter(System.out);\n\n void setFileIO(String ins, String outs) throws IOException {\n in = new BufferedReader(new FileReader(ins));\n out = new PrintWriter(new FileWriter(outs));\n }\n\n // private static final int BUFFER_SIZE = 50 * 200000;\n private static int pos, readLen;\n private static final char[] buffer = new char[1024 * 8];\n private static final char[] str = new char[500000*8*2];\n private static boolean[] isDigit = new boolean[256];\n private static boolean[] isSpace = new boolean[256];\n private static boolean[] isLineSep = new boolean[256];\n\n static {\n for(int i = 0; i < 10; i++) { isDigit['0' + i] = true; }\n isDigit['-'] = true;\n isSpace[' '] = isSpace['\\r'] = isSpace['\\n'] = isSpace['\\t'] = true;\n isLineSep['\\r'] = isLineSep['\\n'] = true;\n }\n\n public int read() throws IOException {\n if(pos >= readLen) {\n pos = 0;\n readLen = in.read(buffer);\n if(readLen <= 0) { throw new EndOfFileRuntimeException(); }\n }\n return buffer[pos++];\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(nextString());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(nextString());\n }\n\n public char nextChar() throws IOException {\n while(true) {\n final int c = read();\n if(!isSpace[c]) { return (char)c; }\n }\n }\n \n int reads(char[] cs, int len, boolean[] accept) throws IOException {\n try {\n while(true) {\n final int c = read();\n if(accept[c]) { break; }\n str[len++] = (char)c;\n }\n }\n catch(EndOfFileRuntimeException e) { ; }\n \n return len;\n }\n\n public char[] nextLine() throws IOException {\n int len = 0;\n str[len++] = nextChar();\n len = reads(str, len, isLineSep);\n \n try {\n if(str[len-1] == '\\r') { len--; read(); }\n }\n catch(EndOfFileRuntimeException e) { ; }\n \n return Arrays.copyOf(str, len);\n }\n\n public String nextString() throws IOException {\n return new String(next());\n }\n\n public char[] next() throws IOException {\n int len = 0;\n str[len++] = nextChar();\n len = reads(str, len, isSpace);\n return Arrays.copyOf(str, len);\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(nextString());\n }\n\n }\n]\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2b252c758daeb41d13c91114a650683b", "src_uid": "7e7b59f2112fd200ee03255c0c230ebd", "difficulty": 1600.0} {"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 step_by_step\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskD solver = new TaskD();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskD {\n final long big = (long) 1e18 + 1;\n long[] fact;\n long[] dp;\n int[] ans;\n\n public long add(long a, long b) {\n if (a <= big - b)\n return a + b;\n else\n return big;\n }\n\n public long mult(long a, long b) {\n if (a <= big / b)\n return a * b;\n else\n return big;\n }\n\n public void get_perm(int n, int pos, int pl, long k) {\n if (n == 1) {\n ans[pos] = 0 + pl;\n return;\n }\n if (n == 2) {\n ans[pos] = 1 + pl;\n ans[pos + 1] = 0 + pl;\n return;\n }\n for (int i = 0; i < n; i++)\n ans[pos + i] = -1;\n boolean[][] used = new boolean[n][n];\n for (int i = 0; i < n; i++)\n for (int j = 0; j < n; j++)\n used[i][j] = (i == j);\n for (int i = 0; i < n; i++)\n used[i][n - 1] = true;\n for (int i = 1; i < n; i++) {\n int cnt = (int) (k / (n - i >= 2 ? fact[n - i - 2] : 1));\n for (int j = 0; j < n; j++)\n if (!used[i][j]) {\n if (cnt == 0) {\n ans[pos + i] = j + pl;\n for (int t = 0; t < n; t++)\n used[t][j] = true;\n int to = j + pl;\n while (ans[to - pl + pos] != -1)\n to = ans[to - pl + pos];\n for (int t = 0; t < n; t++)\n used[to - pl][t] |= used[i][t];\n break;\n }\n cnt--;\n }\n k %= (n - i >= 2 ? fact[n - i - 2] : 1);\n }\n ans[pos] = (n - 1) + pl;\n }\n\n public void get_ans(int n, int pos, int pl, long k) {\n for (int i = 1; i <= n; i++)\n if (mult((i >= 2 ? fact[i - 2] : 1), dp[n - i]) > k) {\n get_perm(i, pos, pl, k / dp[n - i]);\n get_ans(n - i, pos + i, pl + i, k % dp[n - i]);\n break;\n } else {\n k -= mult((i >= 2 ? fact[i - 2] : 1), dp[n - i]);\n }\n }\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int n = in.nextInt();\n long k = in.nextLong();\n k--;\n fact = new long[n + 1];\n fact[0] = 1;\n for (int i = 1; i <= n; i++)\n fact[i] = mult(fact[i - 1], i);\n dp = new long[n + 1];\n dp[0] = 1;\n for (int i = 1; i <= n; i++) {\n dp[i] = 0;\n for (int j = 1; j <= i; j++)\n dp[i] = add(dp[i], mult((j >= 2 ? fact[j - 2] : 1), dp[i - j]));\n }\n ans = new int[n];\n get_ans(n, 0, 0, k);\n for (int i = 0; i < n; i++)\n ans[i]++;\n out.println(ans);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public 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 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(int[] array) {\n for (int i = 0; i < array.length; i++) {\n if (i != 0) {\n writer.print(' ');\n }\n writer.print(array[i]);\n }\n }\n\n public void println(int[] array) {\n print(array);\n writer.println();\n }\n\n public void close() {\n writer.close();\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "26b11ed65885bf86a2931e090d62e0c3", "src_uid": "e03c6d3bb8cf9119530668765691a346", "difficulty": 1900.0} {"lang": "Java 7", "source_code": "package Round_FirstApril_2013;\n\nimport java.util.*;\nimport java.io.*;\n\nimport static java.lang.Math.*;\n\npublic class C {\n\n void solve () throws IOException {\n int n = in.nextInt();\n if (n == 0){\n out.println(0);\n return;\n }\n double sum = 0;\n for (int i = 0; i[] g = (List[]) new List[n];\n\t\tfor(int i =0;i();\n\t\tfor(int i =0;i size=new ArrayList();\n\t\tfor(int i =0;i[] g, int[] ok, int u) {\n\t\tint ret=1;\n\t\tfor(int v : g[u]){\n\t\t\tif(ok[v]==-1){\n\t\t\t\tok[v]=comp;\n\t\t\t\tret+=dfs(g,ok,v);\n\t\t\t}\n\t\t}\n\t\treturn ret;\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "70a60bd639cbecce5a75cd64fe274706", "src_uid": "e1ebaf64b129edb8089f9e2f89a0e1e1", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "public class codeforce {\n\n\tpublic static void main(String[] args) {\n\t\t Scanner scn=new Scanner(System.in);\n\t\t int a=scn.nextInt();\n\t\t ArrayList vec=new ArrayList<>();\n\t\t int sum=0;\n\t\t for(int i=0;i0)\n\t\t\t\t sum+=temp;\n\t\t\t else\n\t\t\t\t sum-=temp;\n\t\t }\n\t\t System.out.println(sum);\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "49f47b5af265d1f9e597cd3d6c7fb48b", "src_uid": "4b5d14833f9b51bfd336cc0e661243a5", "difficulty": 800.0} {"lang": "Java 11", "source_code": "public class PerfectNumber1100 {\n public int findKSolution(int k) {\n int counter = 0;\n int i = 0;\n while (counter != k) {\n if (quersumme(i) == 10) {\n counter+=1;\n }\n i++;\n }\n return i-1;\n }\n\n public int quersumme(int number) {\n int newNumber = 0;\n while (number != 0) {\n newNumber += number%10;\n number = number/10;\n }\n return newNumber;\n }\n\n public static void main(String[] args) {\n PerfectNumber1100 p = new PerfectNumber1100();\n Scanner s = new Scanner(System.in);\n int imput = s.nextInt();\n System.out.println(p.findKSolution(imput));\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "68a41b51b428248c5c83427a30df7187", "src_uid": "0a98a6a15e553ce11cb468d3330fc86a", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class Solution\n{\n static ArrayList adj[];\n static boolean visited[];\n static int N;\n static int color[];\n public static void main(String ag[])\n {\n Scanner sc=new Scanner(System.in);\n int i,j,k;\n \n int N=sc.nextInt();\n char A[]=sc.next().toCharArray();\n \n visited=new boolean[N];\n color=new int[N];\n adj=new ArrayList[N];\n for(i=0;i();\n \n for(i=0;iA[i])\n {\n adj[j].add(i);\n adj[i].add(j);\n } \n }\n }\n \n boolean flag=true;\n for(i=0;i0)\n {\n flag=BFS(i);\n if(!flag)\n break;\n }\n }\n if(!flag)\n System.out.println(\"NO\");\n else \n {\n System.out.println(\"YES\");\n for(i=0;i q=new LinkedList<>();\n q.add(node);\n color[node]=1;\n while(!q.isEmpty())\n {\n int curr=q.poll();\n visited[curr]=true;\n Iterator itr=adj[curr].iterator();\n while(itr.hasNext())\n {\n int next=itr.next();\n if(!visited[next])\n {\n color[next]=1-color[curr];\n q.add(next);\n }\n else \n {\n if(color[next]==color[curr])\n return false;\n }\n }\n }\n return true;\n }\n \n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8c1155428c4131359280f845fc465572", "src_uid": "9bd31827cda83eacfcf5e46cdeaabe2b", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.util.TreeMap;\nimport java.math.*;\n\n/**\n * Created by drproduck on 3/3/17.\n */\npublic class E {\n static long md = 1000000007;\n static long[] prime = new long[1000001];\n static long[] cach = new long[1000000007];\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n long n = in.nextLong();\n long k = in.nextLong();\n priming();\n TreeMap map = new TreeMap<>();\n k = (k>>1)+(k&1);\n long res = n;\n for (int i = 0; i < k; i++) {\n res = phi(res);\n }\n System.out.println(res%md);\n }\n\n static long mul(long a, long b) {\n return (a % md) * (b % md) % md;\n }\n\n static void priming() {\n for (int i = 2; i < prime.length; i++) {\n if (i == 0) {\n for (int j = i; j < prime.length; j+=i) {\n prime[j] = 1;\n }\n }\n }\n }\n\n static long phi(long n) {\n if (n < 1e9 && cach[(int)n] != 0) {\n return cach[(int)n];\n }\n int root = (int) Math.sqrt(n);\n long res = 1;\n for (int i = 2; i <= root; i++) {\n if (prime[i] == 0 && n % i == 0) {\n long fact = 1;\n while (n % i == 0) {\n fact *= i;\n n /= i;\n }\n res = res * fact / i * (i-1);\n }\n }\n if (n>1) res = res * (n - 1);\n if (n < 1e9) {\n cach[(int)n] = res;\n }\n return res;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "215e5e72467d821616f67859b576d10e", "src_uid": "0591ade5f9a69afcbecd80402493f975", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Aeroui\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\n int n = in.nextInt();\n boolean[] vis = new boolean[10000];\n int[][] arr = new int[n][6];\n for (int i = 0; i < n; ++i) {\n for (int j = 0; j < 6; ++j) {\n arr[i][j] = in.nextInt();\n\n vis[arr[i][j]] = true;\n }\n }\n\n for (int i = 0; i < 6; ++i) {\n if (n > 1)\n for (int j = 0; j < 6; ++j) {\n int a = arr[0][i] * 10 + arr[1][j];\n int b = arr[0][i] * 10 + arr[2][j];\n int c = arr[1][i] * 10 + arr[2][j];\n vis[a] = vis[b] = vis[c] = true;\n a = arr[1][i] * 10 + arr[0][j];\n b = arr[2][i] * 10 + arr[1][j];\n c = arr[2][i] * 10 + arr[0][j];\n vis[a] = vis[b] = vis[c] = true;\n if (n > 2)\n for (int k = 0; k < 6; ++k) {\n\n a = arr[0][i] * 100 + 10 * arr[1][j] + arr[2][k];\n b = arr[0][i] * 100 + 10 * arr[2][j] + arr[1][k];\n c = arr[1][i] * 100 + 10 * arr[0][j] + arr[2][k];\n vis[a] = vis[b] = vis[c] = true;\n a = arr[1][i] * 100 + arr[2][j] * 10 + arr[0][k];\n b = arr[2][i] * 100 + arr[1][j] * 10 + arr[0][k];\n c = arr[2][i] * 100 + arr[0][j] * 10 + arr[1][k];\n vis[a] = vis[b] = vis[c] = true;\n }\n }\n }\n\n for (int i = 1; i <= 999; ++i) {\n if (!vis[i]) {\n out.println(i - 1);\n return;\n }\n }\n\n out.println(999);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "44795ef4c68569df8ebfb75b351e19fd", "src_uid": "20aa53bffdfd47b4e853091ee6b11a4b", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "/**\n * Created by IntelliJ IDEA.\n * User: \u0430\u043d\u0434\u0440\u0435\u0439\n * Date: 12.04.2010\n * Time: 0:38:12\n * To change this template use File | Settings | File Templates.\n */\nimport java.util.*;\nimport java.io.*;\n\npublic class Main {\n StreamTokenizer in;\n PrintWriter out;\n public static void main(String[] args) throws IOException{\n new Main().run();\n }\n void run() throws IOException{\n in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n out = new PrintWriter(new OutputStreamWriter(System.out));\n\n solve();\n\n out.flush();\n }\n long dp[][];\n boolean fil[][];\n void solve() throws IOException{\n int n = ni(), h = ni();\n long res =0 ;\n dp = new long[n*2][h*2];\n fil = new boolean[n*2][h*2];\n for(int i = h; i <= n; ++i)\n res += brute(n,i);\n out.print(res);\n }\n long brute(int n, int h){\n if ( n == 1 && h == 1) return 1;\n if ( n == 0 && h == 0 ) return 1;\n if ( n < 0 || h < 0 ) return 0;\n if ( n == 0 && h != 0 ) return 0;\n //if ( n < h ) return 0;\n if ( fil[n][h] ) return dp[n][h];\n long res = 0;\n for(int i = 0; i < n; ++i) {\n for(int hei = 0; hei <= h - 1; ++hei)\n res += brute(i, hei) * brute(n - i - 1, h - 1) ;\n for(int hei = 0; hei <= h - 1; ++hei)\n res += brute(i, h - 1) * brute(n - i - 1, hei) ;\n res -= brute(i, h - 1) * brute(n - i - 1, h - 1);\n }\n fil[n][h] = true;\n dp[n][h] = res;\n return dp[n][h];\n }\n int ni() throws IOException{\n in.nextToken();\n return (int)in.nval;\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bddb30efba223718fa5274062ccfa2f2", "src_uid": "faf12a603d0c27f8be6bf6b02531a931", "difficulty": 1900.0} {"lang": "Java 7", "source_code": "public class Solution {\n \n public static void main(String[] args) {\n Scanner cin = new Scanner(System.in);\n int h = cin.nextInt();\n long leaf = cin.nextLong() - 1;\n System.out.println(countNodes(h, leaf));\n cin.close();\n }\n \n private static long countNodes(long h, long leaf) {\n long low = 0, high = (1 << h) - 1;\n long count = 0;\n boolean goLeft = true;\n while (low < high) {\n long mid = low + (high - low) / 2;\n if (goLeft != (low <= leaf && leaf <= mid)) {\n count += (1 << h) - 1;\n goLeft = !goLeft;\n }\n if (low <= leaf && leaf <= mid) {\n high = mid;\n } else {\n low = mid + 1;\n }\n goLeft = !goLeft;\n count++;\n --h;\n }\n return count;\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "4982f561b7bea950fde91c6047bb8ca0", "src_uid": "3dc25ccb394e2d5ceddc6b3a26cb5781", "difficulty": 1700.0} {"lang": "Java 6", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\n/**\n *\n * @author adrian\n */\npublic class Main {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n Scanner l = new Scanner(System.in);\n\n int r = l.nextInt();\n int g = l.nextInt();\n int b = l.nextInt();\n\n P[] arr = new P[3];\n\n arr[0] = new P(0, r);\n arr[1] = new P(1, g);\n arr[2] = new P(2, b);\n\n Arrays.sort(arr);\n\n System.out.println(30 + (arr[0].cant / 2) + arr[0].color + 1);\n }\n\n}\n\nclass P implements Comparable

{\n int color,cant;\n\n public P(int color, int cant) {\n this.color = color;\n this.cant = cant;\n }\n\n public int compareTo(P p) {\n if(cant - p.cant > 1 || (Math.abs(cant - p.cant) <= 1 && color > p.color))\n return -1;\n else\n return 1;\n }\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bff39078002feb3b773e2823227c9ad6", "src_uid": "a45daac108076102da54e07e1e2a37d7", "difficulty": 1000.0} {"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 kessido\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 BRomanDigits solver = new BRomanDigits();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class BRomanDigits {\n long easySolve(int i) {\n int[] dp = new int[]{0, 4, 10, 20, 35, 56, 83, 116, 155, 198, 244, 292, 341, 390, 439, 488, 537, 586, 635, 684, 733, 782, 831, 880, 929, 978, 1027, 1076, 1125, 1174};\n if (i < dp.length) {\n return dp[i];\n } else {\n long[] y = new long[]{782, 831, 880, 929};\n long[] x = new long[]{21, 22, 23, 24};\n return LagrangeInterpolation.interpolate(x, y, i, MathExtensions.MAXIMUM_OK_MOD);\n }\n }\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int i = in.NextInt();\n out.println(easySolve(i));\n }\n\n }\n\n static class LagrangeInterpolation {\n public static long interpolate(long[] x, long[] y, long xi, long MOD_Prime) {\n long result = 0;\n final int n = x.length;\n for (int i = 0; i < n; i++) {\n long term = y[i] % MOD_Prime;\n for (int j = 0; j < n; j++) {\n if (j != i)\n term = (term * (xi - x[j]) % MOD_Prime) * MathExtensions.modInverse_For_M_Prime(x[i] - x[j], MOD_Prime) % MOD_Prime;\n }\n result = (result + term) % MOD_Prime;\n }\n return result;\n }\n\n }\n\n static class InputReader {\n BufferedReader reader;\n 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(), \" \\t\\n\\r\\f,\");\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 static class MathExtensions {\n public static final long MAXIMUM_OK_MOD = 3_012_017_609L;\n\n public static long modInverse_For_M_Prime(final long a, final long m) {\n return powerMod(a, m - 2, m);\n }\n\n public static long powerMod(final long x, final long y, final long m) {\n if (y == 0)\n return 1;\n\n long p = powerMod(x, y / 2, m) % m;\n p = (p * p) % m;\n\n if (y % 2 == 0)\n return p;\n else\n return (x * p) % m;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "dc9be3af8ab8258d4f54f7b0fb310535", "src_uid": "75ec99318736a8a1b62a8d51efd95355", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class chess_secapproach{\n \n public static void main(String[] args){\n Scanner s = new Scanner(System.in);\n int n = s.nextInt();\n \n int allblack = 0 , allwhite= 0;\n \n int[] arr = new int[n/2];\n \n for(int i = 0;i < n/2;i++){\n arr[i] = s.nextInt();\n }\n \n for(int i = 0 ;i < n/2;i++){\n \n allblack += (Math.abs(arr[i] - (2*i + 1 )))s;\n allwhite += (Math.abs(arr[i] - (2*i + 2 )));\n }\n \n System.out.println(Math.min(allblack , allwhite ));\n \n \n \n \n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "d88e0f7c13537bab8c6655a448e6b2c5", "src_uid": "0efe9afd8e6be9e00f7949be93f0ca1a", "difficulty": 1100.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Walker\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.readInt();\n char[] board = in.readLine().toCharArray();\n for(int i = 0; i < board.length; i++){\n int curr = i;\n for(int jump = 1; jump < 100; jump++){\n int count = 0;\n int next = curr + jump;\n while(count < 4 && next < n && board[next] == '*'){\n curr = next;\n count++;\n next = curr + jump;\n }\n if(count == 4){\n out.print(\"yes\");\n return;\n }\n }\n }\n out.print(\"no\");\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 int readInt() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tint res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tpublic boolean isSpaceChar(int c) {\n\t\tif (filter != null)\n\t\t\treturn filter.isSpaceChar(c);\n\t\treturn isWhitespace(c);\n\t}\n\n\tpublic static boolean isWhitespace(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n\n\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 interface SpaceCharFilter {\n\t\tpublic boolean isSpaceChar(int ch);\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "941aedd7e0d2e8472d8c902c20f1795c", "src_uid": "12d451eb1b401a8f426287c4c6909e4b", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "\nimport java.util.Scanner;\n\n/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n\n/**\n *\n * @author madi\n */\npublic class Round44H {\n static int res = 0;\n static String in;\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n in = sc.nextLine();\n\n if (in.length() == 1) {\n System.out.println(9);\n return;\n }\n\n int p = 1;\n int r = Integer.parseInt(in.charAt(0) + \"\");\n for (int i = 1; i < in.length(); i++) {\n int q = Integer.parseInt(in.charAt(i) + \"\");\n if ((r + q) % 2 == 0) {\n if ((r + q) / 2 != q) {\n p = 0;\n break;\n }\n } else {\n if ((r + q) / 2 != q && (r + q) / 2 + 1 != q) {\n p = 0;\n break;\n }\n }\n r = q;\n }\n\n for (int i = 0; i < 10; i++) {\n res++;\n count(i, 1);\n }\n\n System.out.println(res - p);\n\n }\n\n private static void count(int a, int i) {\n int k = Integer.parseInt(in.charAt(i) + \"\");\n if ((a + k) % 2 != 0) {\n res++;\n if (i < in.length() - 1) {\n count((a + k) / 2, i + 1);\n count((a + k) / 2 + 1, i + 1);\n }\n } else {\n if (i < in.length() - 1) {\n count((a + k) / 2, i + 1);\n }\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "be673637c9859cdf4f10fe298cedef8f", "src_uid": "2dd8bb6e8182278d037aa3a59ca3517b", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "\npackage javaapplication4;\n\nimport java.util.Scanner;\n\npublic class JavaApplication4 {\n public static void main(String[] args) {\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n String l=sc.next();\n char a[]=new char[n];\n for(int i=0;i max)\n max = vetr[i];\n }\n\n if(min > r){\n System.out.println(r);\n return 0;\n }\n\n kupil = r / min;\n ost = r % min;\n\n prod = kupil * max + ost;\n\n if(prod <= r){\n System.out.println(r);\n }\n System.out.println(prod);\n\n \n\n\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ce1a839ba8f553d3607cbcd3daad7041", "src_uid": "42f25d492bddc12d3d89d39315d63cb9", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public final class Solve {\n public static main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int w1 = sc.nextInt();\n int h1 = sc.nextInt();\n int w2 = sc.nextInt();\n int h2 = sc.nextInt();\n \n int res = 2 * w1 + 2 * h1 + w2 + 2 * h2 + 4 + (w2 < w1 ? 1 : 0);\n System.out.println(res);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2ee2c3361da6d495cfc0ba050324fd2a", "src_uid": "b5d44e0041053c996938aadd1b3865f6", "difficulty": 800.0} {"lang": "Java 8", "source_code": "\n public class Main{\n public static void main (String args[]) {\n int x1=sc.nextInt();\n int y1=sc.nextInt();\n int x2=sc.nextInt();\n int y2=sc.nextInt();\n System.out.println((1+(y2-y1)/2)*(1+(x2-x1)/2)+((y2-y1)/2)*((x2-x1)/2));\n }\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "dadf76668ab4a42c522b46567ab49f72", "src_uid": "00cffd273df24d1676acbbfd9a39630d", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "public class Permutation\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(); //number of fixed spots\n \n int counter = 1;\n \n \n if(k >= 2){\n counter += n*(n-1)/2;\n }\n \n if(k >= 3){\n counter += n*(n-1)*(n-2)/3;\n }\n \n if(k >= 4){\n counter += 3*n*(n-1)*(n-2)*(n-3)/8;\n }\n \n SYstem.out.println(counter);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "c65a2a1edf34d8b35013e1116551365a", "src_uid": "96d839dc2d038f8ae95fc47c217b2e2f", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "/*\n * ACM Code => cf110d.java\n * Written by Sam X\n * Date: \u4e09\u6708, 08, 2019\n * Time: 14:27\n */\nimport java.util.*;\nimport java.math.*;\n\npublic class cf110d\n{\n static ArrayList vec = new ArrayList<>();\n static void dfs(long x)\n {\n if(x>1e9) return;\n vec.add(x*10+4);\n vec.add(x*10+7);\n dfs(x*10+4);\n dfs(x*10+7);\n }\n static final long contain(long x1, long y1, long x2, long y2)\n {\n return Math.max(Math.min(y1,y2)-Math.max(x1,x2)+1,0l);\n }\n public static void main(String args[])\n {\n Scanner cin = new Scanner(System.in);\n long pl = cin.nextLong(), \n pr = cin.nextLong(), \n vl = cin.nextLong(),\n vr = cin.nextLong(),\n k = cin.nextLong();\n \n dfs(0);\n vec.add(0l);\n vec.add((long)1e9);\n\n Collections.sort(vec);\n \n long ans=0;\n\n for(int i=1; i<=vec.size()-k+1; ++i)\n {\n int j=i+k-1;\n ans+=contain(vec.get(i-1)+1, vec.get(i), pl, pr)*contain(vec.get(j), vec.get(j+1)-1, vl, vr);\n if(vec.get(i)>pr) break;\n }\n\n for(int i=1; i<=vec.size()-k+1; ++i)\n {\n int j=i+k-1;\n ans+=contain(vec.get(i-1)+1, vec.get(i), vl, vr)*contain(vec.get(j), vec.get(j+1)-1, pl, pr);\n if(vec.get(i)>vr) break;\n }\n\n if(k==1)\n {\n for(int i=0; i=0;i--)\n {\n s=Integer.toString(i,k);\n Arrays.fill(visited,false);\n\n while (s.length() 0) prev = trails[i - 1];\n\t\t\tprev++;\n\t\t\tif (as[i] != 0) prev = 0;\n\t\t\ttrails[i] = prev;\n\t\t}\n\t\tfor (int i = 0; i < nt; i++) {\n\t\t\tint prev = 0;\n\t\t\tif (i > 0) prev = trailt[i - 1];\n\t\t\tprev++;\n\t\t\tif (at[i] != 0) prev = 0;\n\t\t\ttrailt[i] = prev;\n\t\t}\n\t\t\n\t\tint nq = in.nextInt();\n\t\tfor (int qi = 0; qi < nq; qi++) {\n\t\t\tint a = in.nextInt() - 1, b = in.nextInt() - 1;\n\t\t\tint c = in.nextInt() - 1, d = in.nextInt() - 1;\n\t\t\tint lena = b - a + 1;\n\t\t\tint lenb = d - c + 1;\n\t\t\tint AS = Math.min(lena, trails[b]);\n\t\t\tint AT = Math.min(lenb, trailt[d]);\n\t\t\tint BS = sums[b + 1] - sums[a];\n\t\t\tint BT = sumt[d + 1] - sumt[c];\n\t\t\t//System.err.println(AS + \" \" + BS + \" \" + AT + \" \" + BT);\n\t\t\tout.print(good(AS, AT, BS, BT) ? '1' : '0');\n\t\t}\n\t\tout.println();\n\t\tout.close();\n\t}\n\tstatic boolean good(int as, int at, int bs, int bt) {\n\t\tif (as < at) return false;\n\t\tif (bs > bt) return false;\n\t\t//if (at == 0) return true;\n\t\tint need = 0;\n\t\tint am = as % 3;\n\t\tint bm = at % 3;\n\t\tif (am == bm) need = 0;\n\t\telse if ((am + 2) % 3 == bm && as - 1 >= at) need = 1;\n\t\telse if ((am + 1) % 3 == bm && as - 2 >= at) need = 2;\n\t\telse return false;\n\t\tif (need == 0 && bs == 0 && bt != 0) {\n\t\t\tneed = 3;\n\t\t\tif (as - need < at) return false;\n\t\t}\n\t\tboolean sameMod = (bs % 2) == (bt % 2);\n\t\t//if (need == 0) {\n\t\t//\treturn bs <= bt && sameMod;\n\t\t//}\n\t\tbs += Math.min(1, need) * 2;\n\t\t//System.err.println(\"hi \" + bs + \" \" +bt);\n\t\tif (bs > bt) return false;\n\t\treturn (bs % 2) == (bt % 2);\n\t\t//return true;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a22f339e58228bed3dfa0f17c2913a4c", "src_uid": "98e3182f047a7e7b10be7f207b219267", "difficulty": 2500.0} {"lang": "Java 11", "source_code": "//package com.example.practice.codeforces.sc2900.prac;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.StringTokenizer;\n\n//G. Long Binary String\npublic class Solution1 {\n // https://abcdxyzk.github.io/blog/2018/04/16/isal-erase-3/\n // https://zhuanlan.zhihu.com/p/132603308\n public static void main (String [] args) throws IOException {\n // Use BufferedReader rather than RandomAccessFile; it's much faster\n final BufferedReader input = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter out = new PrintWriter(System.out);\n // input file name goes above\n //StringTokenizer st = new StringTokenizer(input.readLine());\n //int n = Integer.parseInt(st.nextToken()), a = Integer.parseInt(st.nextToken()), b = Integer.parseInt(st.nextToken()), k = Integer.parseInt(st.nextToken());\n long[] res = calc(input.readLine());\n if (res==null){\n out.println(-1);\n }else {\n printArray(res, out);\n }\n out.close(); // close the output file\n }\n\n private static long[] calc(final String s) {\n long px = 0, v = 1;\n int p = s.length()-1, tem = 0, highest = 0, first = 0, c = 0;\n while (p>=0 && s.charAt(p)=='0'){\n p--;\n }\n if (p<0)return null;\n while (p>=0){\n if (s.charAt(p)=='1'){\n px |= 1L << tem;\n highest = tem;\n first = p;\n c++;\n }\n tem++;\n p--;\n }\n if (c==1)return new long[]{first+1, first+2};\n final long m = (long) Math.sqrt(1L< map = new HashMap<>();\n for (int i=1;i<=m;++i){\n v = v << 1;\n if ((v & (1L< 0) {\n v2 = v2 << 1;\n if ((v2 & (1L< len)break;\n for (int i=0;i len)break;\n for (int i=0;i al = new ArrayList<>();\n while (st.hasMoreTokens()){\n al.add(Long.parseLong(st.nextToken()));\n }\n long[] kk = new long[al.size()];\n for (int j=0;j al = new ArrayList<>();\n while (st.hasMoreTokens()){\n al.add(Integer.parseInt(st.nextToken()));\n }\n int[] kk = new int[al.size()];\n for (int j=0;j> 1;\n val1 = val2 = d;\n if (st> 1;\n if (st==en){\n val1 = val2 = ns[st];\n }else {\n left = new SegTree(l, mid, ns);\n right = new SegTree(mid+1, r, ns);\n val1 = Math.min(left.val1, right.val1);\n val2 = Math.max(left.val2, right.val2);\n }\n }\n\n void update(int idx, int v){\n if (st==en){\n val1 = val2 = v;\n }else {\n if (idx <= mid){\n left.update(idx, v);\n }else {\n right.update(idx, v);\n }\n val1 = Math.min(left.val1, right.val1);\n val2 = Math.max(left.val2, right.val2);\n }\n }\n\n int getMin(int l, int r){\n if (st==en || (l==st && r==en))return val1;\n if (r<=mid){\n return left.getMin(l, r);\n }\n if (l>mid){\n return right.getMin(l, r);\n }\n return Math.min(left.getMin(l, mid), right.getMin(mid+1, r));\n }\n\n int getMax(int l, int r){\n if (st==en || (l==st && r==en))return val2;\n if (r<=mid){\n return left.getMax(l, r);\n }\n if (l>mid){\n return right.getMax(l, r);\n }\n return Math.max(left.getMax(l, mid), right.getMax(mid+1, r));\n }\n }\n\n static class SparseTable{\n int[][] minTable;\n int[][] maxTable;\n int[] log2;\n int n;\n public SparseTable(final int[] ns){\n n = ns.length;\n int m = 0, pre = 0;\n while (1< checker = new HashSet();\n for (int j = 0; j < temp.length; j++) {\n int res = -1;\n for (int k = 0; k < n; k++) {\n if (require[k] != i || checker.contains(k)) {\n continue;\n }\n if (res == -1 || depend[res][k]) {\n res = k;\n }\n }\n temp[j] = res;\n checker.add(res);\n }\n for (int j = 0; j < temp.length; j++) {\n map[i][j] = temp[j];\n }\n for (int j = 0; j < temp.length; j++) {\n for (int k = j + 1; k < temp.length; k++) {\n if (depend[temp[j]][temp[k]]) {\n throw new Exception();\n }\n }\n }\n }\n \n int result = Integer.MAX_VALUE;\n for (int i = 0; i < 3; i++) {\n result = Math.min(result, search(i, map, depend, new boolean[n], 0));\n }\n System.out.println(result);\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7f0174c3cf060a69b026abc097ba501a", "src_uid": "be42e213ff43e303e475d77a9560367f", "difficulty": 1700.0} {"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;\nimport java.util.*;\npublic class Main\n{\n static boolean prime[] = new boolean[1000001];\n static int parent[];\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 void sieveOfEratosthenes(int n)\n {\n // Create a boolean array \"prime[0..n]\" and initialize\n // all entries it as true. A value in prime[i] will\n // finally be false if i is Not a prime, else true.\n\n for(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 static long fun(long n, long r) {\n\n // p holds the value of n*(n-1)*(n-2)...,\n // k holds the value of r*(r-1)...\n long p = 1, k = 1;\n\n // C(n, r) == C(n, n-r),\n // choosing the smaller value\n if (n - r < r) {\n r = n - r;\n }\n\n if (r != 0) {\n while (r > 0) {\n p *= n;\n k *= r;\n\n // gcd of p, k\n long m = __gcd(p, k);\n\n // dividing by gcd, to simplify product\n // division by their gcd saves from the overflow\n p /= m;\n k /= m;\n\n n--;\n r--;\n }\n\n // k should be simplified to 1\n // as C(n, r) is a natural number\n // (denominator should be 1 ) .\n } else {\n p = 1;\n }\n\n // if our approach is correct p = ans and k =1\n return p;\n }\n\n static long __gcd(long n1, long n2) {\n long gcd = 1;\n\n for (int i = 1; i <= n1 && i <= n2; ++i) {\n // Checks if i is factor of both integers\n if (n1 % i == 0 && n2 % i == 0) {\n gcd = i;\n }\n }\n return gcd;\n }\n\n\n public static void main(String[] args)\n {\n FastReader sc=new FastReader();\n long n=sc.nextLong();\n int p=sc.nextInt();\n long min=111111111;\n for( int i=1;i<=31;i++)\n {\n long q=n-i*p;\n int x=0;int f=0;\n while(q>0)\n {\n x+=q%2;\n q/=2;\n f=1;\n }\n if(x<=i&&f==1)\n {\n min=Math.min(min,i);\n }\n\n }\n if(min==111111111)\n System.out.println(-1);\n else\n System.out.println(min);\n\n }\n}\nclass MergeSort\n{\n // Merges two subarrays of arr[].\n // First subarray is arr[l..m]\n // Second subarray is arr[m+1..r]\n void merge(long arr[], int l, int m, int r)\n {\n // Find sizes of two subarrays to be merged\n int n1 = m - l + 1;\n int n2 = r - m;\n\n /* Create temp arrays */\n long L[] = new long [n1];\n long R[] = new long [n2];\n\n /*Copy data to temp arrays*/\n for (int i=0; i=m1)?m2-m1:(m2+60-m1);\n\t\tif (m2 0) {\n if (pow % 2 == 1) {\n r = mul(r, a);\n }\n pow /= 2;\n a = mul(a, a);\n }\n return r;\n }\n\n public static void solve(Input in, PrintWriter out) throws IOException {\n String s = in.next();\n int n = s.length();\n int k = n + in.nextInt();\n int ans = solveFast(s, k);\n out.println(ans);\n }\n\n private static int solveFast(String s, int k) {\n int n = s.length();\n int[][][] d = new int[n + 1][n + 1][n + 1];\n d[0][n][0] = 1;\n for (int len = n; len > 0; --len) {\n for (int i = 0; i + len <= n; ++i) {\n for (int u = 0; u <= n; ++u) {\n if (d[i][i + len][u] != 0) {\n if (s.charAt(i) == s.charAt(i + len - 1)) {\n d[i + 1][i + len - 1][u + 1] = (d[i + 1][i + len - 1][u + 1] + d[i][i + len][u]) % MOD;\n } else {\n d[i + 1][i + len][u] = (d[i + 1][i + len][u] + d[i][i + len][u]) % MOD;\n d[i][i + len - 1][u] = (d[i][i + len - 1][u] + d[i][i + len][u]) % MOD;\n }\n }\n }\n }\n }\n int[][] d1 = new int[n + 1][n + 1];\n int[][] d2 = new int[n + 1][n + 1];\n for (int i = 0; i < n; ++i) {\n for (int u = 0; 2 * u <= n; ++u) {\n d1[u][n - 2 * u] += d[i][i][u];\n if (2 * u <= n - 1) {\n d2[u][n - 2 * u - 1] += d[i][i + 1][u];\n }\n }\n }\n int ans = 0;\n int[][] a0 = new int[3 * n + 1][3 * n + 1];\n for (int i = 0; i < n; ++i) {\n a0[i][i] = 25;\n a0[i][i + 1] = 1;\n if (i + 1 == n) {\n a0[i][2 * n] = 1;\n }\n }\n for (int i = n; i < 2 * n; ++i) {\n a0[i][i] = 24;\n if (i + 1 != 2 * n) {\n a0[i][i + 1] = 1;\n }\n a0[i][n + i + 1] = 1;\n }\n for (int i = 2 * n; i <= 3 * n; ++i) {\n a0[i][i] = 26;\n }\n int[][] a0low = pow(a0, k / 2);\n int[][] a0high = k % 2 == 1 ? mul(a0low, a0) : a0low;\n for (int u = 0; u <= n; ++u) {\n for (int v = 0; v <= n; ++v) {\n if (d1[u][v] != 0) { // aa\n int cur = a0low[n - u][2 * n + v];\n if (k % 2 == 1) {\n cur = cur * 26 % MOD;\n }\n ans = (ans + d1[u][v] * cur) % MOD;\n// System.err.println(\"d1: \" + u + \" \" + v + \" \" + d1[u][v] + \" \" + cur);\n }\n if (d2[u][v] != 0) { // a\n int cur = a0high[n - u - 1][2 * n + v];\n ans = (ans + d2[u][v] * cur) % MOD;\n// System.err.println(\"d2: \" + u + \" \" + v + \" \" + d2[u][v] + \" \" + cur);\n }\n }\n }\n return ans;\n }\n\n private static int solveSlow(String s, int k) {\n int n = s.length();\n int[][] d = new int[n + 1][n + 1];\n d[0][n] = 1;\n for (int it = 0; it < k / 2; ++it) {\n int[][] d1 = new int[n + 1][n + 1];\n for (int len = n; len > 0; --len) {\n for (int i = 0; i + len <= n; ++i) {\n if (d[i][i + len] != 0) {\n if (s.charAt(i) == s.charAt(i + len - 1)) {\n d1[Math.min(i + 1, i + len - 1)][i + len - 1] = (d1[Math.min(i + 1, i + len - 1)][i + len - 1] + d[i][i + len]) % MOD;\n d1[i][i + len] = (d1[i][i + len] + d[i][i + len] * 25) % MOD;\n } else {\n d1[i + 1][i + len] = (d1[i + 1][i + len] + d[i][i + len]) % MOD;\n d1[i][i + len - 1] = (d1[i][i + len - 1] + d[i][i + len]) % MOD;\n d1[i][i + len] = (d1[i][i + len] + d[i][i + len] * 24) % MOD;\n }\n }\n }\n }\n for (int i = 0; i <= n; ++i) {\n d1[i][i] = (d1[i][i] + d[i][i] * 26) % MOD;\n }\n d = d1;\n }\n int ans = 0;\n for (int i = 0; i < n; ++i) {\n if (k % 2 == 0) {\n ans += d[i][i];\n } else {\n ans += d[i][i] * 26 + d[i][i + 1];\n }\n }\n return ans % MOD;\n }\n\n /*\n0 78\n0 76\n6624 57\n8739 55\n0 123\n0 93\n0 99\n1871 122\n6968 75\n8247 1\n0 79\n3404 10\n0 19\n0 85\n4715 23\n8609 1\n1910 86\n721 113\n4055 12\n659 82\n0 115\n0 53\n944 57\n9422 11\n\n\n */\n\n public static void main(String[] args) throws IOException {\n PrintWriter out = new PrintWriter(System.out);\n// Random rnd = new Random(42);\n// while (rnd != null) {\n// int n = rnd.nextInt(10) + 1;\n// StringBuilder sb = new StringBuilder();\n// for (int i = 0; i < n; ++i) {\n// sb.append((char)('a' + rnd.nextInt(5)));\n// }\n// int k = rnd.nextInt(100) + 1;\n// int ans1 = solveSlow(sb.toString(), k);\n// int ans2 = solveFast(sb.toString(), k);\n// if (ans1 != ans2) {\n// System.err.println(sb + \" \" + k);\n// System.err.println(ans1 + \" \" + ans2);\n// throw new AssertionError();\n// }\n//// sb.append(\"\\n\");\n//// sb.append(rnd.nextInt(100));\n//// solve(new Input(sb.toString()), out);\n//// return;\n// }\n solve(new Input(new BufferedReader(new InputStreamReader(System.in))), out);\n out.close();\n }\n\n static class Input {\n BufferedReader in;\n StringBuilder sb = new StringBuilder();\n\n public Input(BufferedReader in) {\n this.in = in;\n }\n\n public Input(String s) {\n this.in = new BufferedReader(new StringReader(s));\n }\n\n public String next() throws IOException {\n sb.setLength(0);\n while (true) {\n int c = in.read();\n if (c == -1) {\n return null;\n }\n if (\" \\n\\r\\t\".indexOf(c) == -1) {\n sb.append((char)c);\n break;\n }\n }\n while (true) {\n int c = in.read();\n if (c == -1 || \" \\n\\r\\t\".indexOf(c) != -1) {\n break;\n }\n sb.append((char)c);\n }\n return sb.toString();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f953ae0b667cebc27d9e9cc0c51f53de", "src_uid": "2ae6f17e0dd0bc93090d939f4f49d7a8", "difficulty": 3000.0} {"lang": "Java 8", "source_code": "\nimport javax.print.attribute.IntegerSyntax;\nimport java.io.*;\nimport java.util.*;\n\n/**\n * A simple template for competitive programming problems.\n */\npublic class Banana {\n final InputReader in = new InputReader(System.in);\n final PrintWriter out = new PrintWriter(System.out);\n\n final long mod = 998244353;\n\n final boolean DEBUG = false;\n void solve() {\n\n int n = in.nextInt();\n List> dp = new ArrayList<>(n);\n\n dp.add(new HashMap<>());\n Map firstMap = new HashMap<>();\n firstMap.put(1, 1L);\n dp.add(firstMap);\n\n for(int i=2; i<=n; i++) {\n Map map = new HashMap<>();\n dp.add(map);\n int maxDiff = findMaxDiff(i);\n int minVal = (i-maxDiff-1)/2;\n for(int j=minVal; j<=minVal+maxDiff; j++) {\n long val = 0;\n Map leftMap = dp.get(j);\n Map rightMap = dp.get(i-1-j);\n if(leftMap.isEmpty()) {\n for(Integer right : rightMap.keySet()) {\n if(right%2!=0) continue;\n long mul = rightMap.get(right) % mod;\n val = (val+mul) % mod;\n }\n } else if(rightMap.isEmpty()) {\n for(Integer left : leftMap.keySet()) {\n if(left%2==(j+1)%2) continue;\n long mul = leftMap.get(left) % mod;\n val = (val+mul) % mod;\n }\n } else {\n for(Integer left : leftMap.keySet()) {\n if(left%2==(j+1)%2) continue;\n for(Integer right : rightMap.keySet()) {\n if(right%2!=0) continue;\n long mul = leftMap.get(left)*rightMap.get(right) % mod;\n val = (val+mul) % mod;\n }\n }\n }\n map.put(j+1, val);\n }\n }\n\n out.println(sumVal(dp.get(n)));\n }\n\n private long sumVal(Map map) {\n long val = 0;\n for(long mapVal : map.values()) {\n val = (val + mapVal) % mod;\n }\n return val;\n }\n\n private int findMaxDiff(int i) {\n int log = 31 - Integer.numberOfLeadingZeros(i);\n int deepestNodesCount = i - (1< '9') throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n int nextInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n double nextDouble() {\n return Double.parseDouble(nextString());\n }\n\n private int read() {\n if (numChars == -1) throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try { numChars = stream.read(buf); }\n catch (IOException e) { throw new InputMismatchException(); }\n if (numChars <= 0) return -1;\n }\n return buf[curChar++];\n }\n\n private boolean isSpaceChar(int c) { return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1; }\n\n private boolean isEndOfLine(int c) { return c == '\\n' || c == '\\r' || c == -1; }\n }\n\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ec10523d87b1bb499daa3e65dc396744", "src_uid": "821409c1b9bdcd18c4dcf35dc5116501", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class G{\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 TaskE solver = new TaskE();\n solver.solve(1, in, out);\n out.flush();out.close();\n }\n static class TaskE {\n class MinCostMaxFlow{\n ArrayList al[];\n Edge ja[][]; \n int d[]; // shortest distances\n int N , S , T , maxFlow ; int minCost;\n final int gmax = Integer.MAX_VALUE / 100;\n \n int edges = 0;\n\n class Edge{\n int u , flow, rid, cost;\n Edge(int a, int b, int c, int d){u = a; flow = b; cost = c; rid = d;}\n }\n \n void addEdge(int u , int v , int flow , int cost){\n int lu = al[u].size(), lv = al[v].size();\n al[u].add(new Edge(v, flow, cost, lv)); \n al[v].add(new Edge(u, 0, -cost, lu)); \n }\n \n void convertToArray(){\n ja = new Edge[N][];\n for(int i = 0; i < N; i++){\n int sz = al[i].size();\n ja[i] = new Edge[sz];\n for(int j = 0; j < sz; j++){\n ja[i][j] = al[i].get(j);\n }\n al[i].clear();\n }\n }\n \n MinCostMaxFlow(int n , int source , int sink){\n N = n; S = source; T = sink; maxFlow = 0; minCost = 0;\n al = new ArrayList[N];\n d = new int[N];\n for(int i = 0; i < N; i++){\n al[i] = new ArrayList<>();\n }\n }\n \n boolean BellmanFord(boolean check){\n d[0] = 0;\n for(int i = 0; i < N - 1; i++){\n for(int j = 0; j < N; j++){\n for(Edge e : ja[j]){\n if(e.flow == 0)continue; // not to consider reverse edges\n d[e.u] = Math.min(d[e.u] , d[j] + e.cost);\n }\n }\n }\n if(check){// check for negative cycles\n for(int j = 0; j < N; j++){\n for(Edge e : ja[j]){\n if(e.flow == 0)continue;\n if(d[j] + e.cost < d[e.u]) return false;\n }\n } \n }return true;\n }\n\n int node[]; // present node \n\n int visit[]; // 0 -> not added 1 -> not removed 2 -> removed\n int prv[], prve[]; // previous node for augmentation\n int dist[]; // min dist\n\n boolean simple(){\n node = new int[N]; \n visit = new int[N]; \n prv = new int[N];\n prve = new int[N];\n dist = new int[N]; Arrays.fill(dist , gmax);\n\n node[0] = S; dist[0] = 0;\n int front = 1, back = 0;\n while(front != back){\n int u = node[back++]; int distu = dist[u];\n if(back == N)back = 0;\n visit[u] = 2;\n for(int i = 0; i < ja[u].length; i++){\n Edge e = ja[u][i];\n if(e.flow == 0)continue;\n int cdist = distu + e.cost; // no need of reduced cost\n if(cdist < dist[e.u]){\n if(visit[e.u] == 0){\n node[front] = e.u; \n if(++front == N)front = 0;\n }else if(visit[e.u] == 2){\n if(--back == -1)back += N;\n node[back] = e.u;\n }\n visit[e.u] = 1;\n prve[e.u] = i; prv[e.u] = u; dist[e.u] = cdist;\n }\n }\n }\n return visit[T] != 0;\n }\n\n class pair{\n int F; int S;\n pair(int a, int b){F = a; S = b;}\n }\n\n boolean dijkstra(){\n visit = new int[N];\n prv = new int[N];\n prve = new int[N];\n dist = new int[N]; Arrays.fill(dist, gmax);\n PriorityQueue pq = new PriorityQueue<>((A, B) -> Double.compare(A.S , B.S));\n\n pq.add(new pair(S , 0)); dist[0] = 0;\n o : while(!pq.isEmpty()){\n pair p = pq.poll();\n while(dist[p.F] < p.S){\n if(pq.isEmpty()) break o; // had a better val \n p = pq.poll();\n }\n visit[p.F] = 2;\n for(int i = 0; i < ja[p.F].length; i++){\n Edge e = ja[p.F][i];\n if(e.flow == 0)continue; // important\n int cdist = p.S + (e.cost + d[p.F] - d[e.u]); // reduced cost\n if(cdist < dist[e.u]){ \n if(visit[e.u] == 2) return false;\n pq.add(new pair(e.u , cdist));\n dist[e.u] = cdist; prv[e.u] = p.F; prve[e.u] = i;\n visit[e.u] = 1;\n }\n }\n }\n return visit[T] != 0;\n }\n \n int augment(){\n int p = T; int min = gmax;\n while(p != 0){\n int pp = prv[p], pe = prve[p];\n int val = ja[pp][pe].flow;\n min = Math.min(min , val);\n p = pp;\n }\n p = T;\n while(p != 0){\n int pp = prv[p], pe = prve[p];\n ja[pp][pe].flow -= min;\n ja[p][ja[pp][pe].rid].flow += min;\n p = pp;\n }\n maxFlow += min;\n return min;\n }\n\n // if(dist[T] >= 0)return true; // non contributing flow\n boolean calSimple(){\n // uncomment to check for negative cycles\n /* boolean possible = BellmanFord(true); \n if(!possible) return false; */\n while(simple()){\n /*if(dist[T] >= 0)return true;*/ \n minCost += dist[T] * augment();\n }\n return true;\n }\n\n void updPotential(){\n for(int i = 0; i < N; i++){\n if(visit[i] != 0){\n d[i] += dist[i] - dist[S];\n }\n }\n }\n boolean calWithPotential(){\n // set true to check for negative cycles\n // boolean possible = BellmanFord(false); \n // if(!possible) return false;\n while(dijkstra()){\n int min = dist[T] + d[T] - d[S]; // getting back the original cost\n /*if(dist[T] >= 0)return true;*/\n minCost += min * augment();\n updPotential();\n }\n return true; \n }\n }\n int n , m, k, c, d, a[], f[];\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n n = in.nextInt(); m = in.nextInt(); k = in.nextInt(); c = in.nextInt(); d= in.nextInt();\n // S + n\n int maxl = n + k, T = n * maxl + 1;\n MinCostMaxFlow ans = new MinCostMaxFlow(T + 1, 0, T);\n a = new int[k + 1]; f = new int[n + 1];\n for(int i = 1; i <= k; i++){\n a[i] = in.nextInt();\n f[a[i]]++;\n }\n for(int i = 1; i <= n; i++){\n if(f[i] == 0)continue;\n ans.addEdge(0 , i , f[i], 0);\n }\n for(int i = 2; i <= n; i++){\n for(int l = 0; l < maxl - 1; l++){\n ans.addEdge(l * n + i , (l + 1) * n + i, k, c);\n }\n }\n for(int i = 1; i <= m; i++){\n int a = in.nextInt(), b = in.nextInt();\n for(int l = 0; l < maxl - 1; l++){\n for(int p = 1; p <= k; p++){\n if(a != 1)\n ans.addEdge(n * l + a, n * (l + 1) + b, 1, d * (2 * p - 1) + c);\n if(b != 1)\n ans.addEdge(n * l + b, n * (l + 1) + a, 1, d * (2 * p - 1) + c);\n }\n } \n }\n for(int l = 1; l < maxl; l++){\n ans.addEdge(l * n + 1, T, k, 0);\n }\n ans.convertToArray();\n ans.calWithPotential();\n // ans.calSimple();\n if(ans.maxFlow != k){\n out.println(\"BUG\");\n }else{\n out.println((int)ans.minCost);\n }\n }\n }\n static class InputReader {\n BufferedReader br;\n StringTokenizer st;\n public InputReader(InputStream stream) {\n br = new BufferedReader(new InputStreamReader(stream));\n st = null;\n }\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return null;\n st = new StringTokenizer(s);\n }\n return st.nextToken();\n }\n\n boolean hasMoreTokens() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return false;\n st = new StringTokenizer(s);\n }\n return true;\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n public long nextLong() {\n return Long.parseLong(next());\n }\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7a609c6e50f913af0a80668c633eb120", "src_uid": "2d0aa75f2e63c4fb8c98742ac8cd821c", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class E {\n static double DP[][][][];\n static double p;\n static int screen = (1 << 8) - 1;\n\n public static double get(int index, int mask, int ninth, int cnt) {\n if (index == 0) {\n int res = 0;\n while ((mask & 1) == 0 && res < 8) {\n res++;\n mask >>= 1;\n }\n if (res == 8 && ninth == 0)\n res += cnt;\n return res;\n }\n if (DP[index][mask][ninth][cnt] != -1)\n return DP[index][mask][ninth][cnt];\n double res = 0;\n int nextBit = (mask & (1 << 7)) == 0 ? 0 : 1;\n int nextCnt = nextBit == ninth ? (cnt + 1) : 1;\n int nextMask = (mask << 1);\n res += p * get(index - 1, nextMask & screen, nextBit, nextCnt);\n\n nextMask = mask + 1;\n nextBit = (nextMask & (1 << 8)) == 0 ? ninth : ((1 + ninth) & 1);\n nextCnt = nextBit == 0 || ninth == 1 ? cnt : 1;\n res += (1 - p) * get(index - 1, nextMask & screen, nextBit, nextCnt);\n return DP[index][mask][ninth][cnt] = res;\n }\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int x = in.nextInt();\n int k = in.nextInt();\n p = in.nextDouble() / 100;\n DP = new double[k + 1][1 << 8][2][210];\n for (int i = 0; i < DP.length; i++)\n for (int j = 0; j < DP[0].length; j++)\n for (int l = 0; l < DP[0][0].length; l++)\n Arrays.fill(DP[i][j][l], -1);\n int mask = x & screen;\n int ninth = (x & (1 << 8)) == 0 ? 0 : 1;\n int cnt = 0;\n x >>= 8;\n while ((x & 1) == ninth && x > 0) {\n cnt++;\n x >>= 1;\n }\n System.out.println(get(k, mask, ninth, cnt));\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "29ade863471bd47b1568c41fc19bcc81", "src_uid": "c9274249c26b1a85c19ab70d91c1c3e0", "difficulty": 2400.0} {"lang": "Java 7", "source_code": "\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.PriorityQueue;\nimport java.util.StringTokenizer;\n\n\n\npublic class C {\n\tstatic class Pair implements Comparable {\n\t\tint node, depth;\n\n\t\tpublic Pair(int n, int v) {\n\t\t\tnode = n;\n\t\t\tdepth = v;\n\t\t}\n\n\t\tpublic int compareTo(Pair p) {\n\t\t\treturn new Integer(p.depth).compareTo(depth);\n\t\t}\n\t}\n\n\tstatic int[] parent;\n\n\tpublic static void union(int x, int y) {\n\t\tif (find(x) != find(y)) {\n\t\t\tparent[y] = find(x);\n\t\t}\n\t}\n\n\tpublic static int find(int x) {\n\t\tif (parent[x] == x)\n\t\t\treturn x;\n\t\treturn parent[x] = find(parent[x]);\n\t}\n\n\tstatic ArrayList[] graph;\n\tstatic PriorityQueue pq;\n\tstatic int[] haveToPush;\n\tstatic int maxSz;\n\tstatic int[] p;\n\tstatic int[] reqVol, curVol;\n\n\tpublic static void dfs(int cur, int parent, int depth,int rem) {\n\t\tp[cur] = parent;\n\t\tif (curVol[cur] > reqVol[cur]) {\n\t\t\thaveToPush[cur] = Math.min(rem,curVol[cur] - reqVol[cur]);\n\t\t\trem-=haveToPush[cur];\n\t\t\tif(haveToPush[cur]>0)\n\t\t\tpq.add(new Pair(cur, depth));\n\t\t}\n\t\tfor (Integer next : graph[cur]) {\n\t\t\tif (next != parent) {\n\t\t\t\tdfs(next, cur, depth + 1,rem);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static void relax(int idx) {\n\t\tfor (Pair p : pendingList[idx]) {\n\t\t\tint push=Math.min(p.depth,maxSz-curVol[idx]);\n\t\t\tcurVol[p.node] -= push;\n\t\t\tcurVol[idx] += push;\n\t\t\ttrans++;\n\t\t\tres.add((p.node + 1) + \" \" + (idx + 1) + \" \" + (push));\n\t\t}\n\t\tfor (Pair p : pendingList[idx]) {\n\t\t\tif (pendingList[p.node].size() > 0) {\n\t\t\t\trelax(p.node);\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic ArrayList res;\n\tstatic ArrayList[] pendingList;\n\tstatic int trans;\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint vesCnt = nextInt();\n\t\tmaxSz = nextInt();\n\t\tint pipeCnt = nextInt();\n\t\tgraph = new ArrayList[vesCnt];\n\t\tcurVol = new int[vesCnt];\n\t\treqVol = new int[vesCnt];\n\t\tlong curSum = 0, reqSum = 0;\n\t\tfor (int i = 0; i < vesCnt; i++) {\n\t\t\tcurVol[i] = nextInt();\n\t\t\tcurSum += curVol[i];\n\t\t}\n\t\tfor (int i = 0; i < vesCnt; i++) {\n\t\t\treqVol[i] = nextInt();\n\t\t\treqSum += reqVol[i];\n\t\t}\n\t\tif (curSum != reqSum) {\n\t\t\tSystem.out.println(\"NO\");\n\t\t\treturn;\n\t\t}\n\t\tparent = new int[vesCnt];\n\t\tfor (int i = 0; i < vesCnt; i++) {\n\t\t\tparent[i] = i;\n\t\t}\n\t\tfor (int i = 0; i < vesCnt; i++) {\n\t\t\tgraph[i] = new ArrayList();\n\t\t}\n\t\tfor (int i = 0; i < pipeCnt; i++) {\n\t\t\tint source = nextInt() - 1;\n\t\t\tint dest = nextInt() - 1;\n\t\t\tif (find(source) != find(dest)) {\n\t\t\t\tgraph[source].add(dest);\n\t\t\t\tgraph[dest].add(source);\n\t\t\t\tunion(source, dest);\n\t\t\t}\n\t\t}\n\t\tp = new int[vesCnt];\n\t\tres = new ArrayList();\n\t\tfor (int i = 0; i < vesCnt; i++) {\n\t\t\tif (curVol[i] < reqVol[i]) {\n//\t\t\t\tSystem.out.println(i+\" \"+res.size());\n\t\t\t\tArrays.fill(p, -1);\n\t\t\t\thaveToPush = new int[vesCnt];\n\t\t\t\tint[] pending = new int[vesCnt];\n\t\t\t\tpendingList = new ArrayList[vesCnt];\n\t\t\t\tfor (int j = 0; j < vesCnt; j++) {\n\t\t\t\t\tpendingList[j] = new ArrayList();\n\t\t\t\t}\n\t\t\t\tpq = new PriorityQueue();\n\t\t\t\t\n//\t\t\t\tSystem.out.println(Arrays.toString(curVol));\n//\t\t\t\tSystem.out.println(Arrays.toString(reqVol));\n\t\t\t\tint req = reqVol[i] - curVol[i];\n\t\t\t\tdfs(i, -1, 0,req);\n//\t\t\t\tSystem.out.println(Arrays.toString(haveToPush));\n\t\t\t\tboolean[] vis=new boolean[vesCnt];\n\t\t\t\twhile ( !pq.isEmpty()) {\n\t\t\t\t\tPair pp = pq.remove();\n\t\t\t\t\tif(vis[pp.node]) continue;\n\t\t\t\t\tvis[pp.node]=true;\n\t\t\t\t\tint toPush = haveToPush[pp.node]\n\t\t\t\t\t\t\t+ pending[pp.node];\n\t\t\t\t\treq-=toPush;\n\t\t\t\t\tint from = pp.node;\n\t\t\t\t\tint to = p[pp.node];\n\t\t\t\t\tif (to == -1)\n\t\t\t\t\t\tbreak;\n//\t\t\t\t\tif(i==0){\n//\t\t\t\t\t\tSystem.out.println(curVol[to]+\" \"+toPush+\" a7\"+\" \"+to+\" \"+from+\" \"+Arrays.toString(pending)+\" \"+Arrays.toString(haveToPush));\n//\t\t\t\t\t}\n\t\t\t\t\tif (maxSz - curVol[to] >= toPush) {\n\t\t\t\t\t\ttrans++;\n\t\t\t\t\t\tres.add((from + 1) + \" \" + (to + 1) + \" \" + toPush);\n\t\t\t\t\t\tcurVol[from] -= toPush;\n\t\t\t\t\t\tcurVol[to] += toPush;\n\t\t\t\t\t\thaveToPush[to] += toPush;\n\t\t\t\t\t\tif (pendingList[from].size() > 0) {\n\t\t\t\t\t\t\trelax(from);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(!vis[to])\n\t\t\t\t\t\tpq.add(new Pair(to, pp.depth - 1));\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (curVol[to] < maxSz) {\n\t\t\t\t\t\t\ttrans++;\n\t\t\t\t\t\t\tres.add((from + 1) + \" \" + (to + 1) + \" \"\n\t\t\t\t\t\t\t\t\t+ (maxSz - curVol[to]));\n\t\t\t\t\t\t\ttoPush -= (maxSz - curVol[to]);\n\t\t\t\t\t\t\thaveToPush[to] += (maxSz - curVol[to]);\n\t\t\t\t\t\t\tcurVol[from] -= (maxSz - curVol[to]);\n\t\t\t\t\t\t\tcurVol[to] = maxSz;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tpending[to] += (toPush);\n\t\t\t\t\t\tpendingList[to].add(new Pair(from, toPush));\n\t\t\t\t\t\tif(!vis[to])\n\t\t\t\t\t\tpq.add(new Pair(to, pp.depth - 1));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (req > 0) {\n\t\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(trans);\n\t\tfor (int i = 0; i < res.size(); i++) {\n\t\t\tif (i % 1000 == 0)\n\t\t\t\tout.flush();\n\t\t\tout.println(res.get(i));\n\t\t}\n\t\tout.flush();\n\t}\n\n\tstatic BufferedReader br = new BufferedReader(new InputStreamReader(\n\t\t\tSystem.in));\n\tstatic StringTokenizer st = new StringTokenizer(\"\");\n\n\tstatic int nextInt() throws Exception {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tstatic String next() throws Exception {\n\t\twhile (true) {\n\t\t\tif (st.hasMoreTokens()) {\n\t\t\t\treturn st.nextToken();\n\t\t\t}\n\t\t\tString s = br.readLine();\n\t\t\tif (s == null) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tst = new StringTokenizer(s);\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2be9e55b0c2ec726801a26e582f29104", "src_uid": "0939354d9bad8301efb79a1a934ded30", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "//package codeforces309;\n\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.Reader;\nimport java.util.StringTokenizer;\n\nimport codeforces309.A.FastScanner;\n\npublic class stub {\n\n\tpublic static void main(String[] args) throws FileNotFoundException {\n\t\tInputStream is = System.in;\n//\t\tis = new FileInputStream(new File(\"A.txt\"));\n\t\tFastScanner sc = new FastScanner(new InputStreamReader(is));\n\t\t\n\t\tbyte[] book = (\"_\"+sc.next()+\"_\").getBytes();\n\t\tint L = book.length;\n\t\tint total = 2;\n\t\tfor (int i=0; i sortedVertices = new ArrayList();\n\t\tsortVertics(0, vertices, sortedVertices, visited);\n\t\tint[] result = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tVertex v = sortedVertices.get(i);\n\t\t\tPoint p = points[i];\n\t\t\tresult[p.id] = v.id;\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tSystem.out.print(result[i] + 1 + (i == n - 1 ? \"\\n\" : \" \"));\n\t}\n\n\tprivate static void sortVertics(int i, Vertex[] vertices,\n\t\t\tArrayList sortedVertices, boolean[] visited) {\n\t\tif (visited[i])\n\t\t\treturn;\n\t\tVertex v = vertices[i];\n\t\tvisited[i] = true;\n\t\tsortedVertices.add(v);\n\t\tfor (Vertex child : v.children) {\n\t\t\tsortVertics(child.id, vertices, sortedVertices, visited);\n\t\t}\n\t}\n\n\tstatic class Point {\n\t\tlong x, y;\n\t\tint id;\n\n\t\tPoint(int _id, long _x, long _y) {\n\t\t\tid = _id;\n\t\t\tx = _x;\n\t\t\ty = _y;\n\t\t}\n\n\t\tpublic boolean equals(Object o) {\n\t\t\tif (o instanceof Point) {\n\t\t\t\tPoint other = (Point) o;\n\t\t\t\treturn other.x == this.x && other.y == this.y;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tstatic class PointSorter implements Comparator {\n\t\tprivate Point basePoint;\n\n\t\tPointSorter(Point _basePoint) {\n\t\t\tbasePoint = _basePoint;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compare(Point p1, Point p2) {\n\t\t\tif (p1.equals(basePoint))\n\t\t\t\treturn -1;\n\t\t\tif (p2.equals(basePoint))\n\t\t\t\treturn 1;\n\t\t\tdouble v1, v2;\n\t\t\tv1 = arccotangent(p1);\n\t\t\tv2 = arccotangent(p2);\n\t\t\tif (v1 == v2)\n\t\t\t\treturn 0;\n\t\t\telse\n\t\t\t\treturn (int) Math.round(v1 - v2);\n\t\t}\n\n\t\tprivate double arccotangent(Point p) {\n\t\t\tif (p.y == basePoint.y)\n\t\t\t\treturn p.x > basePoint.x ? Double.MAX_VALUE : Double.MIN_VALUE;\n\t\t\telse\n\t\t\t\treturn 1.0 * (p.x - basePoint.x) / (p.y - basePoint.y);\n\t\t}\n\t}\n\n\tstatic class Vertex {\n\t\tint id;\n\t\tArrayList children = new ArrayList();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0d0e79c9221c81c82f9dc891dbf51825", "src_uid": "d65e91dc274c6659cfdb50bc8b8020ba", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.util.List;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.ArrayList;\nimport java.util.Comparator;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author AlexFetisov\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskB solver = new TaskB();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskB {\n int[] am;\n int best;\n int[] bestSeq;\n int diff;\n int[] forIt;\n int[] init;\n Integer[] sortedInit;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n init = new int[n];\n am = new int[32];\n diff = 0;\n sortedInit = new Integer[n];\n for (int i = 0; i < n; ++i) {\n init[i] = in.nextInt();\n am[init[i]]++;\n if (am[init[i]] == 1) {\n ++diff;\n }\n sortedInit[i] = i;\n }\n\n Arrays.sort(sortedInit, new Comparator() {\n @Override\n public int compare(Integer o1, Integer o2) {\n return init[o1] - init[o2];\n }\n });\n diff = 12;\n bestSeq = new int[n];\n best = Integer.MAX_VALUE / 2;\n forIt = new int[32];\n cur = new ArrayList();\n rec(0, 0);\n for (int i = 0; i < n; ++i) {\n out.print(bestSeq[i] + \" \");\n }\n out.println();\n }\n\n List cur;\n final int MAXN = 61;\n\n private void rec(int id, int prev) {\n// if (id <= diff) {\n checkIt();\n// if (id == diff) {\n// return;\n// }\n// }\n for (int c = prev + 1; c <= MAXN; ++c) {\n boolean ok = true;\n for (int x : cur) {\n if (IntegerUtils.gcd(x, c) != 1) {\n ok = false;\n break;\n }\n }\n if (ok) {\n cur.add(c);\n rec(id + 1, c);\n cur.remove(cur.size() - 1);\n if (c > 30) {\n break;\n }\n }\n }\n }\n\n private void checkIt() {\n //if (cur.size() == 0) return;\n List cc = new ArrayList(cur);\n// int max = cur.get(cur.size()-1);\n while (cc.size() < init.length) {\n cc.add(1);\n// for (int i = max + 1; ; ++i) {\n// boolean ok = true;\n// for (int x : cur) {\n// if (IntegerUtils.gcd(x, i) != 1) {\n// ok = false;\n// break;\n// }\n// }\n// if (ok) {\n// cc.add(i);\n// max = i;\n// break;\n// }\n// }\n }\n int cAns = 0;\n\n int[] seq = new int[init.length];\n for (int i = 0; i < init.length; ++i) {\n seq[sortedInit[i]] = cc.get(i);\n cAns += Math.abs(seq[sortedInit[i]] - init[sortedInit[i]]);\n }\n//\n//\n// for (int i = 1; i <= 30; ++i) {\n// if (am[i] > 0) {\n// int bestDelta = Integer.MAX_VALUE;\n// for (int x : cur) {\n// if (bestDelta > Math.abs(x - i)) {\n// bestDelta = Math.abs(x - i);\n// forIt[i] = x;\n// }\n// }\n// cAns += bestDelta * am[i];\n// }\n// }\n if (best > cAns) {\n best = cAns;\n bestSeq = seq.clone();\n// for (int i = 0; i < init.length; ++i) {\n// bestSeq[i] = forIt[init[i]];\n// }\n }\n }\n}\n\nclass InputReader {\n private BufferedReader reader;\n private StringTokenizer stt;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n }\n\n public String nextLine() {\n try {\n return reader.readLine().trim();\n } catch (IOException e) {\n return null;\n }\n }\n\n public String nextString() {\n while (stt == null || !stt.hasMoreTokens()) {\n stt = new StringTokenizer(nextLine());\n }\n return stt.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(nextString());\n }\n\n}\n\nclass IntegerUtils {\n\n public static int gcd(int x, int y) {\n return y == 0 ? x : gcd(y, x % y);\n }\n\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "de600748d068e3719b0e45273d1a1897", "src_uid": "f26c74f27bbc723efd69c38ad0e523c6", "difficulty": 2000.0} {"lang": "Java 6", "source_code": "public class wew {\n\tpublic static void main (String [] args) {\n\t\t Scanner in = new Scanner (System.in);\n\t\tint x = in.nextInt();\n\t\tSystem.out.println ((x+1)/36+\" \"+(x+1)%36+1);\n\t\t}\n\t}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7ec3cc07d87f400e5808d1734e9c1a3c", "src_uid": "5d4f38ffd1849862623325fdbe06cd00", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class 978A {\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\t\n\t\tfor (int i = 0; i < n; i++) \n\t\t\tarr[i] = sc.nextInt();\n\t\t\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\tfor (int j = i + 1; j < arr.length; j++) {\n\t\t\t\tif (arr[i] == arr[j]) {\n\t\t\t\t\tarr[i] = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(arr.length);\n\t\tfor (int i = 0; i < arr.length; i++)\n\t\t\tif (arr[i] != 0)\n\t\t\t System.out.print(arr[i] + \" \");\n\t\tsc.close();\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bd0f3cc6b8b8ab43cc5bc89bb3ec90ef", "src_uid": "1b9d3dfcc2353eac20b84c75c27fab5a", "difficulty": 800.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class _98A {\n public static void main(String[] args) { \n Scanner input = new Scanner(System.in);\n\n int a[] = {0,0,0,0,0,0};\n String s = input.next();\n for (int i = 0; i < 6; i++)\n if (s.charAt(i) == 'R')\n a[0]++;\n else if (s.charAt(i) == 'O')\n a[1]++;\n else if (s.charAt(i) == 'Y')\n a[2]++;\n else if (s.charAt(i) == 'G')\n a[3]++;\n else if (s.charAt(i) == 'B')\n a[4]++;\n else if (s.charAt(i) == 'V') \n a[5]++;\n \n int ans =0;\n int num = 0;\n for (int i = 0; i < 6; i++)\n if (a[i] > 0)\n num++;\n if (num == 1)\n ans = 1;\n if (num == 2) { // (5,1) (4,2) (3,3)\n for (int i = 0; i < 6; i++)\n if (a[i] == 5)\n ans = 1;\n else if (a[i] == 4)\n ans = 2;\n else if (a[i] == 3)\n ans = 3;\n }\n if (num == 3) { // (4,1,1) (3,2,1) \n boolean mode = false;\n for (int i = 0; i < 6; i++)\n if (a[i] == 4)\n mode = true;\n if (mode)\n ans = 2;\n else\n ans = 8;\n }\n if (num == 4) { // (3,1,1,1) (2,2,1,1)\n boolean mode = false;\n for (int i = 0; i < 6; i++)\n if (a[i] == 3)\n mode = true;\n if (mode) \n ans = 12;\n else \n ans = 8;\n }\n if (num == 5) {\n ans = 6 + 12;\n }\n if (num == 6)\n ans = 30;\n System.out.println(ans);\n \n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3c137e2d993578c0f51201f917bb375e", "src_uid": "8176c709c774fa87ca0e45a5a502a409", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Partition {\n\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n int n = input.nextInt();\n int[] a = new int[n];\n for (int i = 0; i < n; i++) {\n a[i] = input.nextInt();\n //a.add(x);\n }\n String x = Arrays.toString(a);\n //System.out.println(x);\n if (x.contains(\"30, 30\") || x.contains(\"30, 28\") || x.contains(\"30, 29\") || x.contains(\"28, 28\")) {\n System.out.println(\"no\");\n } else if (x.contains(\"28, 30\") || x.contains(\"29, 30\") || x.contains(\"29, 29\")) {\n System.out.println(\"no\");\n } else if (x.contains(\"29, 28\") || x.contains(\"28, 29\")||x.contains(\"31, 31, 31\")){\n \n System.out.println(\"no\");\n } else {\n\n System.out.println(\"yes\");\n }\n\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "439bb9ee59ba6a32b5d7750209d96784", "src_uid": "d60c8895cebcc5d0c6459238edbdb945", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class digits {\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n long k = Long.parseLong(br.readLine());\n long temp = 9 * (int)Math.pow(10,0);\n int count = 0;\n long initial = 0;\n while(k < temp) {\n count++;\n initial = temp;\n temp += 9 * (long)Math.pow(10,count)*(count+1);\n }\n long index = (k-initial-1)%(c+1);\n long num = (long)Math.pow(10,count) + (k-initial-1)/(count+1);\n System.out.println(a.charAt((int)index));\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fa74b81dd445d60a327542a10481b5a6", "src_uid": "1503d761dd4e129fb7c423da390544ff", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "/**\n * author: derrick20\n * created: 10/5/20 11:58 AM\n */\nimport java.io.*;\nimport java.util.*;\n\npublic class ICup implements Runnable {\n public static void main(String[] args) throws Exception {\n new Thread(null, new ICup(), \": )\", 1 << 28).start();\n }\n\n public void run() {\n FastScanner sc = new FastScanner();\n PrintWriter out = new PrintWriter(System.out);\n\n int T = sc.nextInt();\n long[] vals = sc.nextLongs(T);\n long[] sqrts = new long[60];\n sqrts[2] = 2;\n for (int i = 3; i < sqrts.length; i++) {\n sqrts[i] = (2 * sqrts[i - 1] - 1 + mod) % mod;\n }\n// System.out.println(Arrays.toString(sqrts));\n for (long v : vals) {\n if (v == 1) {\n out.println(1);\n } else if (v == 2 || v == 3) {\n out.println(2);\n } else {\n long sum = 0;\n long ct = 0;\n for (int bit = 2; bit < 60; bit++) {\n if (((v >> bit) & 1) > 0) {\n sum += sqrts[bit];\n sum %= mod;\n ct += 1;\n }\n }\n long amt = sum - (ct - 1);\n long ans = (amt * amt) % mod;\n if ((v & 2) > 0) {\n ans += amt;\n }\n ans %= mod;\n out.println(ans);\n }\n }\n out.close();\n }\n\n static long mod = (long) 1e9 + 7;\n\n static class FastScanner {\n private int BS = 1 << 16;\n private char NC = (char) 0;\n private byte[] buf = new byte[BS];\n private int bId = 0, size = 0;\n private char c = NC;\n private double cnt = 1;\n private BufferedInputStream in;\n\n public FastScanner() {\n in = new BufferedInputStream(System.in, BS);\n }\n\n public FastScanner(String s) {\n try {\n in = new BufferedInputStream(new FileInputStream(new File(s)), BS);\n } catch (Exception e) {\n in = new BufferedInputStream(System.in, BS);\n }\n }\n\n private char getChar() {\n while (bId == size) {\n try {\n size = in.read(buf);\n } catch (Exception e) {\n return NC;\n }\n if (size == -1) return NC;\n bId = 0;\n }\n return (char) buf[bId++];\n }\n\n public int nextInt() {\n return (int) nextLong();\n }\n\n public int[] nextInts(int N) {\n int[] res = new int[N];\n for (int i = 0; i < N; i++) {\n res[i] = (int) nextLong();\n }\n return res;\n }\n\n public long[] nextLongs(int N) {\n long[] res = new long[N];\n for (int i = 0; i < N; i++) {\n res[i] = nextLong();\n }\n return res;\n }\n\n public long nextLong() {\n cnt = 1;\n boolean neg = false;\n if (c == NC) c = getChar();\n for (; (c < '0' || c > '9'); c = getChar()) {\n if (c == '-') neg = true;\n }\n long res = 0;\n for (; c >= '0' && c <= '9'; c = getChar()) {\n res = (res << 3) + (res << 1) + c - '0';\n cnt *= 10;\n }\n return neg ? -res : res;\n }\n\n public double nextDouble() {\n double cur = nextLong();\n return c != '.' ? cur : cur + nextLong() / cnt;\n }\n\n public double[] nextDoubles(int N) {\n double[] res = new double[N];\n for (int i = 0; i < N; i++) {\n res[i] = nextDouble();\n }\n return res;\n }\n\n public String next() {\n StringBuilder res = new StringBuilder();\n while (c <= 32) c = getChar();\n while (c > 32) {\n res.append(c);\n c = getChar();\n }\n return res.toString();\n }\n\n public String nextLine() {\n StringBuilder res = new StringBuilder();\n while (c <= 32) c = getChar();\n while (c != '\\n') {\n res.append(c);\n c = getChar();\n }\n return res.toString();\n }\n\n public boolean hasNext() {\n if (c > 32) return true;\n while (true) {\n c = getChar();\n if (c == NC) return false;\n else if (c > 32) return true;\n }\n }\n }\n static void ASSERT(boolean assertion, String message) {\n if (!assertion) throw new AssertionError(message);\n }\n static void ASSERT(boolean assertion) {\n if (!assertion) throw new AssertionError();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "33a63a048001e92fdb3c23b2459a9b28", "src_uid": "24f4bd10ae714f957920afd47ac0c558", "difficulty": 2400.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.util.HashSet;\nimport java.util.Scanner;\nimport java.util.Set;\n\n/**\n * User: \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\n * Date: 12.06.2013\n * Time: 16:30:48\n */\npublic class ABBYY_3_D {\n Scanner scanner = new Scanner(System.in);\n BufferedReader buffered = new BufferedReader(new InputStreamReader(System.in));\n StreamTokenizer in = new StreamTokenizer(buffered);\n\n PrintWriter out = new PrintWriter(System.out);\n\n int nextInt() throws Exception {\n in.nextToken();\n return (int) in.nval;\n }\n\n Set set;\n int[] a = new int[100];\n int[] p = new int[100];\n\n void ghghgh(int n) {\n String s = \"\";\n for (int i=0; i 0) {\n for (int j=i+1; j 0) {\n int t = p[i];\n p[i] = p[j];\n p[j] = t;\n a[i]--;\n a[j]--;\n ghghgh(n);\n a[i]++;\n a[j]++;\n t = p[i];\n p[i] = p[j];\n p[j] = t;\n }\n }\n }\n }\n }\n\n int answer(int n, int k) {\n set = new HashSet();\n for (int i=0; i 0) {\n if (n%2==1) {\n c = (c*s) % MOD;\n }\n s = (s*s) % MOD;\n n /= 2;\n }\n\n return (a*c) % MOD;\n }\n\n void main() throws Exception {\n long[] a = new long[MAX];\n a[0] = 1;\n a[1] = 2;\n long[] b = new long[MAX];\n b[0] = 1;\n b[1] = 2;\n for (int i=2; i 0) {\n if ((exp & 1) != 0)\n res = (res * a) % mod;\n a = (a * a) % mod;\n exp >>= 1;\n }\n return res;\n }\n\n public static void main(String[] args) throws Exception {\n InputReader in = new InputReader(System.in);\n System.out\n .println((modPow(2, arr[in.nextInt() - 1], 1000000007) + 1000000006) % 1000000007);\n }\n\n static class InputReader {\n private BufferedReader reader;\n private StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n tokenizer = null;\n }\n\n public String 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", "compilation_error": false, "code_uid": "2ebab3019d8e70ca0cea89608adc6360", "src_uid": "c2cbc35012c6ff7ab0d6899e6015e4e7", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n/**\n * Educational Codeforces Round 24\n * Problem A\n * Diplomas and Certificates\n *\n * Created by mcparadip on 7/9/17.\n */\n\npublic class A {\n\n public static void main(String[] args) throws IOException {\n\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\n StringTokenizer st = new StringTokenizer(in.readLine());\n\n int n = Integer.parseInt(st.nextToken());\n int k = Integer.parseInt(st.nextToken());\n\n int diploma = n / 2 / (k+1);\n int certificate = diploma * k;\n int none = n - diploma - certificate;\n\n System.out.println(diploma + \" \" + certificate + \" \" + none);\n\n\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "81eab68094b7ae8607f607c97b6a0fca", "src_uid": "405a70c3b3f1561a9546910ab3fb5c80", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\n// BiGraph Matching\n\npublic class CF_212A {\n static Scanner scanner = new Scanner(System.in);\n\n public static void main(String args[]) {\n while (task()) {\n }\n }\n\n private static int n, m, k, t;\n\n\n private static int maxK = 5000;\n private static int maxT = 200;\n private static int[] a = new int[maxK + 10];\n private static int[] b = new int[maxK + 10];\n\n private static int[] X = new int[maxT * maxT + 10];\n private static int[] Y = new int[maxT * maxT + 10];\n private static int[] xBegin = new int[maxT * maxT + 10];\n private static int[] yBegin = new int[maxT * maxT + 10];\n\n private static int[] degree = new int[maxK + 10];\n private static int maxDegree = 0;\n\n private static int[] degreeX = new int[maxK + 10];\n private static int[] degreeY = new int[maxK + 10];\n\n private static int[][] col = new int[2 * maxT + 10][maxT + 10];\n\n public static boolean task() {\n n = scanner.nextInt();\n m = scanner.nextInt();\n k = scanner.nextInt();\n t = scanner.nextInt();\n\n for (int i = 0; i < k; i++) {\n int x = scanner.nextInt();\n int y = scanner.nextInt();\n y += n;\n a[i] = x;\n b[i] = y;\n degree[x]++;\n degree[y]++;\n }\n\n int ans = 0;\n for (int i = 1; i <= n + m; i++) {\n ans += degree[i] % t == 0? 0: 1;\n }\n System.out.println(ans);\n\n maxDegree = t;\n\n int hX = 1, hY = 1;\n for (int i = 1; i <= n; i++) {\n // System.out.println(\"deg \" + i + \" \" + degree[i] + \" \" + hX);\n int deg = degree[i];\n xBegin[i] = hX;\n while (deg > 0) {\n X[hX] = i;\n hX++;\n deg -= maxDegree;\n }\n }\n\n for (int i = 1; i <= m; i++) {\n int deg = degree[n + i];\n yBegin[i] = hY;\n while (deg > 0) {\n Y[hY] = i;\n hY++;\n deg -= maxDegree;\n }\n }\n\n int h = hX - 1;\n if (h < hY - 1) {\n h = hY - 1;\n }\n\n /*\n for (int i = 1; i <= h; i++) {\n System.out.println(i + \" \" + X[i]);\n }\n\n System.out.println(\" -- \");\n\n for (int i = 1; i <= h; i++) {\n System.out.println(i + \" \" + Y[i]);\n }\n */\n\n Matcher matcher = new Matcher(h, h);\n\n for (int i = 0; i < k; i++) {\n int x = a[i];\n int y = b[i] - n;\n int realX = xBegin[x];\n int realY = yBegin[y];\n matcher.addEdge(realX, realY);\n degreeX[realX]++;\n if (degreeX[realX] == maxDegree) {\n xBegin[x]++;\n }\n degreeY[realY]++;\n if (degreeY[realY] == maxDegree) {\n yBegin[y]++;\n }\n }\n\n int hy = 1;\n\n for (int i = 1; i <= h; i++) {\n int need = maxDegree - degreeX[i];\n while (need > 0) {\n while (degreeY[hy] == maxDegree) {\n hy++;\n }\n matcher.addEdge(i, hy);\n need--;\n degreeY[hy]++;\n }\n }\n\n for (int i = 0; i < maxDegree; i++) {\n matcher.match();\n // System.out.println(matcher.ans());\n int c = i + 1;\n for (int x = 1; x <= h; x++) {\n int y = matcher.matching[x] - h;\n if (y + h == -1) {\n continue;\n }\n int originalX = X[x];\n int originalY = Y[y];\n if (col[originalX][originalY] == 0) {\n col[originalX][originalY] = c;\n //col[originalY][originalX] = c;\n }\n // System.out.println(\"col \" + originalX + \" \" + originalY + \" \" + c);\n matcher.delEdge(x, y);\n }\n }\n\n for (int i = 0; i < k; i++) {\n int x = a[i];\n int y = b[i] - n;\n if (i > 0) {\n System.out.print(\" \");\n }\n System.out.print(col[x][y]);\n }\n System.out.println();\n\n if (n == 20 && m == 20 && k == 100 && t == 3) {\n for (int i = 0; i < k; i++) {\n int x = a[i];\n int y = b[i] - n;\n System.out.println(x + \" \" + y + \" \" + col[x][y]);\n }\n }\n\n\n return false;\n }\n\n\n\n public static final int maxN = 1000;\n\n public static class Matcher {\n public Map[] g = new Map[2 * maxN + 10];\n private int nx, ny;\n private int nEdge;\n\n public static int[] matching = new int[2 * maxN + 10];\n private static int[] checked = new int[2 * maxN + 10];\n\n public Matcher(int nx, int ny) {\n this.nx = nx;\n this.ny = ny;\n nEdge = 0;\n for (int i = 0; i < g.length; i++) {\n g[i] = new HashMap<>();\n }\n }\n\n public void addEdge(int x, int y) {\n int now = g[x].getOrDefault(nx + y, 0);\n g[x].put(nx + y, now + 1);\n nEdge++;\n // System.out.println((\"add \" + x + \" \" + y));\n }\n\n public void delEdge(int x, int y) {\n int now = g[x].getOrDefault(nx + y, 0);\n if (now > 1) {\n g[x].put(nx + y, now - 1);\n } else {\n g[x].remove(nx + y);\n }\n nEdge--;\n // System.out.println((\"del \" + x + \" \" + y));\n }\n\n public void reset() {\n ans = 0;\n for (int i = 0; i < matching.length; i++) {\n matching[i] = -1;\n }\n for (int i = 0; i < checked.length; i++) {\n checked[i] = -1;\n }\n }\n\n private int ans = 0;\n\n private Queue q = new LinkedList<>();\n private int[] prev = new int[2 * maxN + 10];\n\n public void match() {\n reset();\n for (int x = 1; x <= nx; x++) {\n int step = x;\n if (matching[x] == -1) {\n q.clear();\n q.add(x);\n prev[x] = -1;\n boolean flag = false;\n while (!q.isEmpty() && !flag) {\n int u = q.poll();\n //System.out.println(u);\n for (int v: g[u].keySet()) {\n if (flag) {\n break;\n }\n if (checked[v] != step) {\n checked[v] = step;\n q.add(matching[v]);\n if (matching[v] >= 0) {\n prev[matching[v]] = u;\n } else {\n flag = true;\n int d = u;\n int e = v;\n while (d != -1) {\n int t = matching[d];\n matching[d] = e;\n matching[e] = d;\n d = prev[d];\n e = t;\n }\n }\n }\n }\n // q.poll();\n }\n if (matching[x] != -1) {\n ans++;\n }\n }\n }\n }\n\n public int ans() {\n return ans;\n }\n\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ed96d56a6f57b194d5c451d6d38f4b65", "src_uid": "99b97aabec566e5f966777947271ad3c", "difficulty": 3000.0} {"lang": "Java 8", "source_code": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n\n\nimport java.io.*;\nimport java.util.*;\n\n/**\n *\n * @author kamranmaharov\n */\npublic class Main {\n private static Quotient[][] dp = new Quotient[1001][1001];\n private static int k, pa, pb;\n private static int REM = 1000000007;\n private static Quotient q1, q2, q3;\n \n private static class Quotient {\n private final int P, Q;\n \n Quotient(int P, int Q) {\n this.P = P;\n this.Q = inverse(Q);\n }\n \n public Quotient add(Quotient other) {\n return new Quotient( (int)(((long)P*Q + (long)other.P*other.Q) % REM), 1);\n }\n \n public Quotient multiply(Quotient other) {\n return new Quotient((int)((long)P*Q%REM*other.P%REM*other.Q%REM), 1);\n }\n \n @Override\n public String toString() {\n return String.valueOf((long)P*Q % REM);\n }\n \n private static int inverse(int Q) {\n return pow(Q, REM-2);\n }\n \n private static int pow(int a, int b) {\n if (b==0) {return 1;}\n else if (b%2==1) {return (int)((long)pow(a,b-1) * a % REM);}\n else {\n int mid = pow(a,b/2);\n return (int)((long)mid*mid%REM);\n }\n }\n }\n \n private static Quotient f(int c1, int c2) {\n if (dp[c1][c2] != null) {\n return dp[c1][c2];\n }\n if (c1+c2>=k) {\n dp[c1][c2] = new Quotient(c1+c2, 1).add(q1);\n } else {\n dp[c1][c2] = f(c1, c2+1).multiply(q2).add(\n f(c1+c2, c2).multiply(q3));\n }\n return dp[c1][c2];\n }\n \n public static void main(String[] args) throws Exception {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));\n \n String[] line = in.readLine().split(\" \");\n k = Integer.parseInt(line[0]);\n pa = Integer.parseInt(line[1]);\n pb = Integer.parseInt(line[2]);\n q1 = new Quotient(pa, pb);\n q2 = new Quotient(pa, pa+pb);\n q3 = new Quotient(pb, pa+pb);\n \n out.write(f(0, 1).toString() + \"\\n\");\n out.close();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "267564e7cdd8063a51211e16c98ef0c0", "src_uid": "0dc9f5d75143a2bc744480de859188b4", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class C {\n\tpublic static void main(String[]args){\n\t\tScanner sc=new Scanner(System.in);\n\t\tString s=sc.nextLine();\n\t\tint k=sc.nextInt();\n\t\tsc.close();\n\t\tLinkedListsnow=new LinkedList();\n\t\tLinkedListcanes=new LinkedList();\n\t\tString real=\"\";\n\t\tfor(int i=0;ireal.length())\n\t\t\tif(!snow.isEmpty())\n\t\t\t\treal=fill(s,snow.removeFirst(),k-real.length());\n\t\t\telse\n\t\t\t\tpossible=false;\n\t\tSystem.out.println(possible?real:\"IMPOSSIBLE\");\n\t}\n\tprivate static String remove(String s,int i){\n\t\treturn s.substring(0,i)+s.substring(i+1,s.length());\n\t}\n\tprivate static String fill(String s,int i,int k){\n\t\tString st=s.substring(0,i);\n\t\tfor(int j=0;j= n)\n return 1;\n \n if(dp[pos] != -1)\n return dp[pos];\n \n dp[pos] = (ways(pos + 1 , n) + ways(pos + 2 , n))%1000000007;\n return dp[pos];\n }\n public static void main(String []args)\n {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n dp = new long[n];\n for(int i = 0 ; i < n ; i++)\n {\n dp[i] = -1;\n }\n System.out.println(ways(0 , n) % 1000000007);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "87e2c908804f2cb99f5cf7eab90081d8", "src_uid": "5c4bd12df3915186a7b506c2060db125", "difficulty": 1600.0} {"lang": "Java 11", "source_code": "//package round12;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.InputMismatchException;\nimport java.util.List;\n\npublic class F {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\tint[] primes = sieveEratosthenes(400000);\n\t\n\tvoid solve()\n\t{\n\t\tlong n = nl();\n\t\tlong ans = 0;\n\t\tfor(int i = 0;i < primes.length;i++) {\n\t\t\tlong plus = countWithCache(n/primes[i], primes) - (i+1);\n\t\t\tif(plus <= 0)break;\n\t\t\tans += plus;\n\t\t}\n\t\t\n\t\tfor(int p : primes) {\n\t\t\tif((long)p*p*p <= n) {\n\t\t\t\tans++;\n\t\t\t}else {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tout.println(ans);\n\t}\n\t\n\tpublic static long countWithCache(long x, int[] primes)\n\t{\n\t\tif(x < primes[primes.length-1]) {\n\t\t\tint ind = Arrays.binarySearch(primes, (int)x);\n\t\t\treturn ind < 0 ? -ind-1 : ind+1;\n\t\t}else {\n\t\t\treturn count(x);\n\t\t}\n\t}\n\t\n\tpublic static long count(long x)\n\t{\n\t\tint c = (int)Math.pow(x, 2./3);\n\t\tint[] primes = sieveEratosthenes(c);\n\t\treturn count(x, primes);\n\t}\n\t\n\t// primes = Sieve.sieveEratosthenes(x^(2/3))\n\tpublic static long count(long x, int[] primes)\n\t{\n\t\tint ind = Arrays.binarySearch(primes, (int)Math.cbrt(x));\n\t\tif(ind < 0)ind = -ind-2;\n\t\tint a = ind+1;\n\t\treturn a - p2xa(x, primes) + phi(x, a, primes) - 1;\n\t}\n\t\n\tprivate static long phi(long x, int a, int[] primes)\n\t{\n\t\treturn S1(x) + S2(x, a, primes);\n\t}\n\t\n\tprivate static long S1(long x)\n\t{\n\t\tint c = (int)Math.cbrt(x);\n\t\tint[] lpf = enumLowestPrimeFactors(c);\n\t\tint[] mobius = enumMobiusByLPF(c, lpf);\n\t\tlong ret = 0;\n\t\tfor(int i = 1;i <= c;i++){\n\t\t\tret += mobius[i] * (x/i);\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tstatic long exret = 0;\n\t\n\tprivate static long S2(long x, int a, int[] primes)\n\t{\n\t\tfinal int C = (int)Math.cbrt(x);\n\t\tfinal int N = (int)Math.cbrt(x)*3/2;\n\t\tList pairs = new ArrayList<>();\n\t\texret = 0;\n\t\tdfs(a-1, 1, 1L, C, x, primes, pairs);\n\t\tCollections.sort(pairs, new Comparator(){\n\t\t\tpublic int compare(Pair x, Pair y){\n\t\t\t\tif(x.xdn / N != y.xdn / N)return Long.compare(x.xdn, y.xdn);\n\t\t\t\treturn x.b - y.b;\n\t\t\t}\n\t\t});\n\n\t\t// sieveBySegment\n\t\tfinal int NUM_MASK_PRIMES = 15;\n\t\tlong[] mask = new long[NUM_MASK_PRIMES];\n\t\tfor(int i = 0;i < NUM_MASK_PRIMES && i < primes.length;i++){\n\t\t\tfor(int k = 0;k < 64;k += primes[i]){\n\t\t\t\tmask[i] |= 1L<>>6)+1;\n\t\tlong[] stand = new long[m];\n\t\tret += exret;\n\t\t\n\t\tout:\n\t\tfor(long k = 0;;k++){\n\t\t\tArrays.fill(stand, -1L);\n\t\t\tstand[N>>>6] = (N&63) > 0 ? stand[N>>>6]<<-N>>>-N : 0; // erasing [N,\n\t\t\tint numstand = N;\n\t\t\tif(k == 0){ // not include 0\n\t\t\t\tnumstand--;\n\t\t\t\tstand[0] ^= 1L<<0;\n\t\t\t}\n\t\t\tfor(int b = 0;b < a;b++){\n\t\t\t\twhile(p < pairs.size() && pairs.get(p).xdn < (k+1)*N && pairs.get(p).b == b){\n//\t\t\t\t\tU.tr(\"hit\", p, phis[b], k, pairs.get(p).xdn - (long)k*N, (phis[b] + FenwickTree.sumFenwick(ft, (int)(pairs.get(p).xdn - (long)k*N))));\n\t\t\t\t\tint to = (int)(pairs.get(p).xdn - k*N);\n\t\t\t\t\tint lret = 0;\n\t\t\t\t\tfor(int i = 0, j = 0;i <= to;i += 64, j++){ // [0,to]\n\t\t\t\t\t\tif(i+63 <= to){\n\t\t\t\t\t\t\tlret += Long.bitCount(stand[j]);\n\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\tlret += Long.bitCount(stand[j]<<~to);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tret += pairs.get(p).co * (phis[b] + lret);\n//\t\t\t\t\tU.tr(pairs.get(p), ret);\n\t\t\t\t\tp++;\n\t\t\t\t}\n\t\t\t\tif(p == pairs.size())break out;\n\t\t\t\tphis[b] += numstand;\n\t\t\t\tif(b < NUM_MASK_PRIMES){\n\t\t\t\t\tint r = primes[b];\n\t\t\t\t\tint delta = 64%r;\n\t\t\t\t\tfor(int q = 0, o = (int)(r-1-(k*N+r-1)%r);q < m;q++, o -= delta){\n\t\t\t\t\t\tif(o < 0)o += r;\n\t\t\t\t\t\tnumstand -= Long.bitCount(stand[q] & mask[b]<>>6]<<~q<0){\n\t\t\t\t\t\t\tstand[q>>>6]^=1L< pairs)\n\t{\n\t\tfor(int i = pos;i >= 0;i--){\n\t\t\tlong nmul = mul * primes[i];\n\t\t\tif(nmul > c && c >= mul){\n\t\t\t\t// b+1 = i\n\t\t\t\tif(i == 0){\n\t\t\t\t\texret += -co*(x/nmul);\n\t\t\t\t}else{\n\t\t\t\t\tpairs.add(new Pair(-co, x/nmul, i));\n\t\t\t\t}\n\t\t\t}else if(nmul <= c){\n\t\t\t\tdfs(i-1, -co, nmul, c, x, primes, pairs);\n\t\t\t}\n\t\t}\n\t}\n\t\n\t// TODO segmentSieve\u306b\u3088\u308a\u30e1\u30e2\u30eaO(x^(1/3))\u306b\u3059\u308b\n\tprivate static long p2xa(long x, int[] primes)\n\t{\n\t\tint a = (int)Math.cbrt(x);\n\t\tint b = (int)Math.sqrt(x);\n\t\tlong ret = 0;\n\t\t\n\t\tint posa = Arrays.binarySearch(primes, a);\n\t\tif(posa < 0)posa = -posa - 2;\n\t\tret += (long)posa*(posa+1)/2;\n\t\t\n\t\tint posb = Arrays.binarySearch(primes, b);\n\t\tif(posb < 0)posb = -posb - 2;\n\t\tret -= (long)posb*(posb+1)/2;\n\t\t\n\t\tfor(int i = posa+1;i <= posb;i++){\n\t\t\tint posp = Arrays.binarySearch(primes, (int)(x/primes[i]));\n\t\t\tif(posp < 0)posp = -posp - 2;\n\t\t\tret += posp + 1;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\t\n\tprivate static int[] enumLowestPrimeFactors(int n)\n\t{\n\t\tint tot = 0;\n\t\tint[] lpf = new int[n+1];\n\t\tint u = n+32;\n\t\tdouble lu = Math.log(u);\n\t\tint[] primes = new int[(int)(u/lu+u/lu/lu*1.5)];\n\t\tfor(int i = 2;i <= n;i++)lpf[i] = i;\n\t\tfor(int p = 2;p <= n;p++){\n\t\t\tif(lpf[p] == p)primes[tot++] = p;\n\t\t\tint tmp;\n\t\t\tfor(int i = 0;i < tot && primes[i] <= lpf[p] && (tmp = primes[i]*p) <= n;i++){\n\t\t\t\tlpf[tmp] = primes[i];\n\t\t\t}\n\t\t}\n\t\treturn lpf;\n\t}\n\t\n\tprivate static int[] enumMobiusByLPF(int n, int[] lpf)\n\t{\n\t\tint[] mob = new int[n+1];\n\t\tmob[1] = 1;\n\t\tfor(int i = 2;i <= n;i++){\n\t\t\tint j = i/lpf[i];\n\t\t\tif(lpf[j] == lpf[i]){\n//\t\t\t\tmob[i] = 0;\n\t\t\t}else{\n\t\t\t\tmob[i] = -mob[j];\n\t\t\t}\n\t\t}\n\t\treturn mob;\n\t}\n\n\t\n\tpublic static int[] sieveEratosthenes(int n) {\n\t\tif (n <= 32) {\n\t\t\tint[] primes = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 };\n\t\t\tfor (int i = 0; i < primes.length; i++) {\n\t\t\t\tif (n < primes[i]) {\n\t\t\t\t\treturn Arrays.copyOf(primes, i);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn primes;\n\t\t}\n\n\t\tint u = n + 32;\n\t\tdouble lu = Math.log(u);\n\t\tint[] ret = new int[(int) (u / lu + u / lu / lu * 1.5)];\n\t\tret[0] = 2;\n\t\tint pos = 1;\n\n\t\tint[] isnp = new int[(n + 1) / 32 / 2 + 1];\n\t\tint sup = (n + 1) / 32 / 2 + 1;\n\n\t\tint[] tprimes = { 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 };\n\t\tfor (int tp : tprimes) {\n\t\t\tret[pos++] = tp;\n\t\t\tint[] ptn = new int[tp];\n\t\t\tfor (int i = (tp - 3) / 2; i < tp << 5; i += tp)\n\t\t\t\tptn[i >> 5] |= 1 << (i & 31);\n\t\t\tfor (int j = 0; j < sup; j += tp) {\n\t\t\t\tfor (int i = 0; i < tp && i + j < sup; i++) {\n\t\t\t\t\tisnp[j + i] |= ptn[i];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// 3,5,7\n\t\t// 2x+3=n\n\t\tint[] magic = { 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, 31, 22, 28, 18, 26, 10, 7, 12, 21, 17,\n\t\t\t\t9, 6, 16, 5, 15, 14 };\n\t\tint h = n / 2;\n\t\tfor (int i = 0; i < sup; i++) {\n\t\t\tfor (int j = ~isnp[i]; j != 0; j &= j - 1) {\n\t\t\t\tint pp = i << 5 | magic[(j & -j) * 0x076be629 >>> 27];\n\t\t\t\tint p = 2 * pp + 3;\n\t\t\t\tif (p > n)\n\t\t\t\t\tbreak;\n\t\t\t\tret[pos++] = p;\n\t\t\t\tif ((long) p * p > n)\n\t\t\t\t\tcontinue;\n\t\t\t\tfor (int q = (p * p - 3) / 2; q <= h; q += p)\n\t\t\t\t\tisnp[q >> 5] |= 1 << q;\n\t\t\t}\n\t\t}\n\n\t\treturn Arrays.copyOf(ret, pos);\n\t}\n\n\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 F().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", "compilation_error": false, "code_uid": "1a4f78e0dadd85977da41e9da2fa0b71", "src_uid": "ffb7762f1d60dc3f16e9b27ea0ecdd7d", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Pixel {\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n long i,j,k,n,a,b,c,big,middle,small,sum;\n boolean is;\n while (input.hasNext()){\n a = input.nextLong(); b = input.nextLong(); c = input.nextLong(); sum = 0; is = false;\n\n big = (a>=b) ? ((a>=c)? a :c) : ((b>=c) ? b : c);\n small = (a>=b) ? ((b>=c) ? c : b) : ((a>=c) ? c : a);\n middle = a>b ? (c>a ? a :(b>c)? b:c) : (c>b ? b : a>c? a : c);\n\n // System.out.println(big+ \" \" + middle + \" \" + small);\n for (i=0; ix1&&y>y1&&z>z1)out.println(a[1]+a[3]+a[5]);\n\t\telse if(x<0&&y<0&&z<0)out.println(a[0]+a[2]+a[4]);\n\t\telse if((x>=0&&x<=x1)){\n\t\t\tif((y>=0&&y<=y1)){\n\t\t\t\tif(z<0){\n\t\t\t\t\tout.println(a[2]);\n\t\t\t\t}else if(z>z1){\n\t\t\t\t\tout.println(a[3]);\n\t\t\t\t}\n\t\t\t}else if((z>=0&&z<=z1)){\n\t\t\t\tif(y<0){\n\t\t\t\t\tout.println(a[0]);\n\t\t\t\t}else if(y>y1){\n\t\t\t\t\tout.println(a[1]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse if((y>=0&&y<=y1)){\n\t\t\tif((x>=0&&x<=x1)){\n\t\t\t\tif(z<0){\n\t\t\t\t\tout.println(a[2]);\n\t\t\t\t}else if(z>z1){\n\t\t\t\t\tout.println(a[3]);\n\t\t\t\t}\n\t\t\t}else if((z>=0&&z<=z1)){\n\t\t\t\tif(x<0){\n\t\t\t\t\tout.println(a[4]);\n\t\t\t\t}else if(x>x1){\n\t\t\t\t\tout.println(a[5]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse if((z>=0&&z<=z1)){\n\t\t\tif((x>=0&&x<=x1)){\n\t\t\t\tif(y<0){\n\t\t\t\t\tout.println(a[0]);\n\t\t\t\t}else if(y>y1){\n\t\t\t\t\tout.println(a[1]);\n\t\t\t\t}\n\t\t\t}else if((y>=0&&y<=y1)){\n\t\t\t\tif(x<0){\n\t\t\t\t\tout.println(a[4]);\n\t\t\t\t}else if(x>x1){\n\t\t\t\t\tout.println(a[5]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t\tout.close();\n\t}\n}\n\nclass FastScanner {\n\tfinal private int BUFFER_SIZE = 1 << 19;\n\tprivate DataInputStream din;\n\tprivate byte[] buffer;\n\tprivate int bufferPointer, bytesRead;\n\n\tpublic FastScanner(InputStream in) {\n\t\tdin = new DataInputStream(in);\n\t\tbuffer = new byte[BUFFER_SIZE];\n\t\tbufferPointer = bytesRead = 0;\n\t}\n\n\tpublic String nextString() throws Exception {\n\t\tStringBuffer sb = new StringBuffer(\"\");\n\t\tbyte c = read();\n\t\twhile (c <= ' ')\n\t\t\tc = read();\n\t\tdo {\n\t\t\tsb.append((char) c);\n\t\t\tc = read();\n\t\t} while (c > ' ');\n\t\treturn sb.toString();\n\t}\n\n\tpublic char nextChar() throws Exception {\n\t\tbyte c = read();\n\t\twhile (c <= ' ')\n\t\t\tc = read();\n\t\treturn (char) c;\n\t}\n\n\tpublic int nextInt() throws Exception {\n\t\tint ret = 0;\n\t\tbyte c = read();\n\t\twhile (c <= ' ')\n\t\t\tc = read();\n\t\tboolean neg = c == '-';\n\t\tif (neg)\n\t\t\tc = read();\n\t\tdo {\n\t\t\tret = ret * 10 + c - '0';\n\t\t\tc = read();\n\t\t} while (c > ' ');\n\t\tif (neg)\n\t\t\treturn -ret;\n\t\treturn ret;\n\t}\n\n\tpublic long nextLong() throws Exception {\n\t\tlong ret = 0;\n\t\tbyte c = read();\n\t\twhile (c <= ' ')\n\t\t\tc = read();\n\t\tboolean neg = c == '-';\n\t\tif (neg)\n\t\t\tc = read();\n\t\tdo {\n\t\t\tret = ret * 10 + c - '0';\n\t\t\tc = read();\n\t\t} while (c > ' ');\n\t\tif (neg)\n\t\t\treturn -ret;\n\t\treturn ret;\n\t}\n\n\tprivate void fillBuffer() throws Exception {\n\t\tbytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n\t\tif (bytesRead == -1)\n\t\t\tbuffer[0] = -1;\n\t}\n\n\tprivate byte read() throws Exception {\n\t\tif (bufferPointer == bytesRead)\n\t\t\tfillBuffer();\n\t\treturn buffer[bufferPointer++];\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "644871b9e7ea0d32f255429edd195602", "src_uid": "c7889a8f64c57cf7be4df870f68f749e", "difficulty": 1600.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class abc {\n\tstatic long reflectNum(long number){\n\t\tif(number==1000000000)\n\t\t\treturn 8999999999L;\n\t\tif(number<100000)\n\t\t{\n\t\t\tif(number<100)\n\t\t\t{\n\t\t\t\tif(number<10)\n\t\t\t\t\treturn (9-number);\n\t\t\t\telse\n\t\t\t\t\treturn (99-number);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif(number<10000)\n\t\t\t\t{\n\t\t\t\t\tif(number<1000)\n\t\t\t\t\t\treturn (999-number);\n\t\t\t\t\telse\n\t\t\t\t\t\treturn (9999-number);\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\treturn (99999-number);\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif(number<10000000)\n\t\t\t{\n\t\t\t\tif(number<1000000)\n\t\t\t\t\treturn (999999-number);\n\t\t\t\telse\n\t\t\t\t\treturn (9999999-number);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif(number<100000000)\n\t\t\t\t\treturn (99999999-number);\n\t\t\t\telse\n\t\t\t\t\treturn (999999999-number);\n\t\t\t}\n\t\t}\n\t}\n\tstatic short digitNum(long number){\n\t\tif(number<100000)\n\t\t{\n\t\t\tif(number<100)\n\t\t\t{\n\t\t\t\tif(number<10)\n\t\t\t\t\treturn 1;\n\t\t\t\telse\n\t\t\t\t\treturn 2;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif(number<10000)\n\t\t\t\t{\n\t\t\t\t\tif(number<1000)\n\t\t\t\t\t\treturn 3;\n\t\t\t\t\telse\n\t\t\t\t\t\treturn 4;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\treturn 5;\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif(number<10000000)\n\t\t\t{\n\t\t\t\tif(number<1000000)\n\t\t\t\t\treturn 6;\n\t\t\t\telse\n\t\t\t\t\treturn 7;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif(number<100000000)\n\t\t\t\t\treturn 8;\n\t\t\t\telse\n\t\t\t\t\treturn 9;\n\t\t\t}\n\t\t}\n\t}\n\t\t\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner read = new Scanner(System.in);\n\t\tlong l,r, max=-1;\n\t\tlong lower=1;\n\t\tl = read.nextInt();\n\t\tr = read.nextInt();\n\t\tif(r==0)\n\t\t\tmax=0;\n\t\telse if(l==1000000000 || r==1000000000)\n\t\t\tmax = 8999999999000000000L;\n\t\telse\n\t\t{\n\t\t\tlower *= Math.pow(10, digitNum(r)-1);\n\t\t\tif(lower list = new LinkedList();\n int temperatures = 0;\n for (int i = 0; i < m; ++i) {\n temperatures = scan.nextInt();\n list.add(temperatures);\n }\n int flag = 0;\n for (int i = 0; i < list.size(); ++i) {\n\n if (list.get(i) == min) {\n flag++;\n }\n if (list.get(i) == max) {\n flag++;\n }\n }\n if (m <= n - 2) {\n System.out.println(\"Correct\");\n }\n if (m == n - 1) {\n if (flag == 1 || flag == 2) {\n System.out.println(\"Correct\");\n } else if (flag == 0) {\n System.out.println(\"Incorrect\");\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "99a36961b9da1514569ad858151ffd86", "src_uid": "99f9cdc85010bd89434f39b78f15b65e", "difficulty": 1200.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main {\n\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint length = in.nextInt();\n\t\tint[] proc = new int[length];\n\t\tint[] copy = new int[length];\n\t\tfor (int i = 0; i < length; i++){\n\t\t\tproc[i] = in.nextInt();\n\t\t copy[i] = proc[i];\n\t\t}\n\t\t\n\t\t\n\t\tproc = sort(proc, length);\n \n System.out.println(srav(proc,copy, length));\n\t\t\n\t}\n\t\n\tprivate static int[] sort(int[] proc, int length){\n\t\t\n\t\n\t\tfor (int i = length - 1; i >= 0; i--){\n\t\t\tif (proc[i] == 0){\n\t\t\t for(int j = i; j < length - 1; j++){\n\t\t\t\tproc[j] = proc[j+1];\n\t\t\t proc[j + 1] = 0;\n\t\t\t }\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn proc;\n\t}\n\t\n\tprivate static int srav(int[] proc, int[] copy, int length){\n\t\tint count = 0;\n\t\tfor(int i = 0; i < length; i++){\n\t\t\tif ((copy[i] != 0) && (copy[i] != proc[i]) ){\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\t\treturn count;\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "65e4e42002808fb51ccbe53d960d5991", "src_uid": "9135c7243431debb049f640e9600bc6e", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main {\n public static long MOD = 1000000007;\n\n public static void main(String[] args) {\n final Scanner scanner = new Scanner(System.in);\n final int n = scanner.nextInt();\n final int k = scanner.nextInt();\n\n final ArrayList values = new ArrayList<>(n);\n for (int i = 0; i < n; i++) {\n values.add(scanner.nextInt());\n }\n\n int zeroCount = values.stream().filter(integer -> integer.equals(0)).mapToInt(i -> 1).sum();\n final long[][] table = new long[k + 1][n];\n\n int initZeroCount = values.subList(0, zeroCount).stream().filter(integer -> integer.equals(0)).mapToInt(i -> 1).sum();\n table[0][initZeroCount] = 1L;\n\n for (int i = 1; i < k + 1; i++) {\n for (int j = 0; j < n; j++) {\n final int zeroInPrefix = j;\n final int zeroOutPrefix = getZeroOutPrefix(zeroCount, zeroInPrefix);\n final int oneInPrefix = getOneInPrefix(zeroCount, zeroInPrefix);\n final int oneOutPrefix = getOneOutPrefix(n, zeroCount, zeroInPrefix);\n\n final long sameZero = table[i - 1][j]\n * (zeroInPrefix * zeroOutPrefix\n + zeroInPrefix * oneInPrefix\n + zeroOutPrefix * oneOutPrefix\n + oneInPrefix * oneOutPrefix\n + countPair(oneInPrefix)\n + countPair(zeroInPrefix)\n + countPair(oneOutPrefix)\n + countPair(zeroOutPrefix));\n final long plusZero = (j == 0 ? 0 : table[i - 1][j - 1]) *\n (getOneInPrefix(zeroCount, zeroInPrefix - 1) * getZeroOutPrefix(zeroCount, zeroInPrefix - 1));\n final long minusZero = (j == n - 1 ? 0 : table[i - 1][j + 1]) *\n ((zeroInPrefix + 1) * getOneOutPrefix(n, zeroCount, zeroInPrefix + 1));\n\n table[i][j] = sameZero + plusZero + minusZero;\n }\n }\n final long count = table[k][zeroCount];\n final long sum = Arrays.stream(table[k]).reduce((left, right) -> (left + right) % MOD).orElse(0);\n\n System.out.println((binPow(sum, MOD - 2) * count) % MOD);\n }\n\n private static int getOneInPrefix(int zeroCount, int zeroInPrefix) {\n return zeroCount - zeroInPrefix;\n }\n\n private static int getOneOutPrefix(int allCount, int zeroCount, int zeroInPrefix) {\n return allCount - zeroCount - getOneInPrefix(zeroCount, zeroInPrefix);\n }\n\n private static int getZeroOutPrefix(int zeroCount, int zeroInPrefix) {\n return zeroCount - zeroInPrefix;\n }\n\n private static long countPair(int count) {\n return (count * (count - 1)) / 2;\n }\n\n private static long binPow(long n, long count) {\n if (count == 0) {\n return 1L;\n }\n\n long temp = binPow(n, count / 2);\n temp = (temp * temp) % MOD;\n if (count % 2 != 0) {\n temp = (temp * n) % MOD;\n }\n\n return temp % MOD;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "48297ca9550654c910a9a072e0b7a64b", "src_uid": "77f28d155a632ceaabd9f5a9d846461a", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "// package codeforces.cf3xx.cf399;\n\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class F {\n public static void main(String[] args) {\n InputReader in = new InputReader(System.in);\n PrintWriter out = new PrintWriter(System.out);\n\n int f = in.nextInt();\n int w = in.nextInt();\n int h = in.nextInt();\n\n prec(300000);\n\n long ptn = 0;\n for (int pile = 1 ; pile <= f+1 ; pile++) {\n int leftW = w - (h + 1) * pile;\n if (leftW < 0) {\n break;\n }\n ptn += comb(f+1, pile) * comb(leftW+pile-1, pile-1) % MOD;\n ptn %= MOD;\n }\n long all = comb(f+w, f) % MOD;\n if (w == 0) {\n ptn = 1;\n }\n out.println(ptn * inv(all) % MOD);\n out.flush();\n }\n\n static final int MOD = 1000000007;\n\n static long pow(long a, long x) {\n long res = 1;\n while (x > 0) {\n if (x%2 != 0) {\n res = (res*a)%MOD;\n }\n a = (a*a)%MOD;\n x /= 2;\n }\n return res;\n }\n\n static long inv(long a) {\n return pow(a, MOD-2)%MOD;\n }\n\n static long[] _fact;\n static long[] _invfact;\n\n static long comb(long ln, long lr) {\n int n = (int) ln;\n int r = (int) lr;\n if (n < 0 || r < 0 || r > n) {\n return 0;\n }\n if (r > n/2) {\n r = n-r;\n }\n return (((_fact[n]*_invfact[n-r])%MOD)*_invfact[r])%MOD;\n }\n\n static void prec(int n) {\n _fact = new long[n+1];\n _invfact = new long[n+1];\n _fact[0] = 1;\n _invfact[0] = 1;\n for (int i = 1; i <= n; i++) {\n _fact[i] = _fact[i-1]*i%MOD;\n _invfact[i] = inv(_fact[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\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n private int[] nextInts(int n) {\n int[] ret = new int[n];\n for (int i = 0; i < n; i++) {\n ret[i] = nextInt();\n }\n return ret;\n }\n\n private int[][] nextIntTable(int n, int m) {\n int[][] ret = new int[n][m];\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n ret[i][j] = nextInt();\n }\n }\n return ret;\n }\n\n private long[] nextLongs(int n) {\n long[] ret = new long[n];\n for (int i = 0; i < n; i++) {\n ret[i] = nextLong();\n }\n return ret;\n }\n\n private long[][] nextLongTable(int n, int m) {\n long[][] ret = new long[n][m];\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n ret[i][j] = nextLong();\n }\n }\n return ret;\n }\n\n private double[] nextDoubles(int n) {\n double[] ret = new double[n];\n for (int i = 0; i < n; i++) {\n ret[i] = nextDouble();\n }\n return ret;\n }\n\n private int next() {\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 char nextChar() {\n int c = next();\n while (isSpaceChar(c))\n c = next();\n if ('a' <= c && c <= 'z') {\n return (char) c;\n }\n if ('A' <= c && c <= 'Z') {\n return (char) c;\n }\n throw new InputMismatchException();\n }\n\n public String nextToken() {\n int c = next();\n while (isSpaceChar(c))\n c = next();\n StringBuilder res = new StringBuilder();\n do {\n res.append((char) c);\n c = next();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public int nextInt() {\n int c = next();\n while (isSpaceChar(c))\n c = next();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = next();\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 = next();\n } while (!isSpaceChar(c));\n return res*sgn;\n }\n\n public long nextLong() {\n int c = next();\n while (isSpaceChar(c))\n c = next();\n long sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = next();\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 = next();\n } while (!isSpaceChar(c));\n return res*sgn;\n }\n\n public double nextDouble() {\n return Double.valueOf(nextToken());\n }\n\n public boolean isSpaceChar(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 static void debug(Object... o) {\n System.err.println(Arrays.deepToString(o));\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a429805eb9693224b4aab535066a80fd", "src_uid": "a69f95db3fe677111cf0558271b40f39", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "\n/*\nUSER: caoash3\nLANG: JAVA\nTASK: \n*/\n\nimport java.io.*;\nimport java.util.*;\n\npublic class p1 {\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));\n\n\t\t//BufferedReader br = new BufferedReader(new FileReader(\"X.in\"));\n\t\t//PrintWriter pw = new PrintWriter(new FileWriter(\"X.out\"));\n\n\t\tX solver = new X();\n\t\tsolver.solve(br, pw);\n\t}\n\n\tstatic class X {\n\t\tpublic void solve(BufferedReader br, PrintWriter pw) throws IOException {\n\t\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\t\t\n\t\t\tint n = Integer.parseInt(st.nextToken());\n\t\t\tint m = Integer.parseInt(st.nextToken());\n\t\t\t\n\t\t\tint[] inp = new int[n];\n\t\t\t\n\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\n\t\t\t\n\t\t\tint s = 0;\n\t\t\tint s2 = 0;\n\t\t\tfor(int i = 0; i < inp.length; i++) {\n\t\t\t\tinp[i] = Integer.parseInt(st.nextToken());\n\t\t\t\tif(inp[i] == -1) {\n\t\t\t\t\ts ++;\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\ts2 += inp[i];\n\t\t\t\t\t}\n\t\t\t\tsum ++;\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t\tint max = 0;\n\t\t\t\n\t\t\tfor(int i = 0; i < m; i++) {\n\t\t\t\tint s3 = s;\n\t\t\t\tint s4 = s2;\n\t\t\t\tfor(int j = i; j \" + cur);\n//\t\t\t\t\t}\n\t\t\t\t\tfor (int i = 0, ntrees = ctrees, nsize = csize;\n\t\t\t\t\t\tntrees <= d && nsize <= maxsize;\n\t\t\t\t\t\t++i, ++ntrees, nsize += nlastsize) {\n\t\t\t\t\t\tncnt2[ntrees][nsize] += cur;\n\t\t\t\t\t\tif (ncnt2[ntrees][nsize] >= mod) {\n\t\t\t\t\t\t\tncnt2[ntrees][nsize] -= mod;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcur = (int) ((long) cur * (ccnt + i) % mod * fracs[i + 1] % mod);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (nlastsize + 1 <= maxsize) {\n\t\t\t\tcnts[nlastsize + 1] = ncnt2[d - 1][nlastsize + 1];\n\t\t\t}\n\t\t}\n\t\tint ans = 0;\n\t\tif (n % 2 == 0) {\n\t\t\tans = (int) ((long) cnts[n / 2] * (cnts[n / 2] + 1) % mod * fracs[2] % mod);\n\t\t}\n\t\tans = (ans + cnts2[(n - 1) / 2][d][n]) % mod;\n\t\tout.print(ans);\n\t}\n\n\tstatic int nextInt() throws IOException {\n\t\treturn parseInt(next());\n\t}\n\n\tstatic long nextLong() throws IOException {\n\t\treturn parseLong(next());\n\t}\n\n\tstatic double nextDouble() throws IOException {\n\t\treturn parseDouble(next());\n\t}\n\n\tstatic String next() throws IOException {\n\t\twhile (tok == null || !tok.hasMoreTokens()) {\n\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(new OutputStreamWriter(System.out));\n\t\t\tsolve();\n\t\t\tin.close();\n\t\t\tout.close();\n\t\t} catch (Throwable e) {\n\t\t\te.printStackTrace();\n\t\t\texit(1);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d08e1821bd78b97c7a21fefe2d888d89", "src_uid": "bdd0fc1d6dbab5eeb5aea135fdfffc9d", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.math.RoundingMode;\nimport java.text.DecimalFormat;\nimport java.util.Scanner;\nimport java.math.MathContext;\n\npublic class Main {\n public static void main(String[] args) {\n MathContext mc = new MathContext(10000, RoundingMode.HALF_DOWN);\n Scanner cin = new Scanner(System.in);\n BigInteger n,k,M,D;\n int dd;\n n=cin.nextBigInteger();\n k=cin.nextBigInteger();\n M=cin.nextBigInteger();\n D=cin.nextBigInteger();\n dd=D.intValue();\n BigInteger ans=BigInteger.ZERO;\n for(int i=0;i<=dd;i++){\n BigInteger once=n.divide(k.multiply(new BigInteger(i+\"\").add(BigInteger.ONE));\n if(once.compareTo(M)>0)\n once=M;\n if(n.subtract(k.multiply(new BigInteger(i+\"\")).multiply(once)).compareTo(once)>=0&&i==dd)\n continue;\n BigInteger temp=once.multiply(new BigInteger(i+\"\")).add(once);\n if(temp.compareTo(ans)>0){\n ans=temp;\n }\n }\n System.out.println(ans);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "57d0e4e3293cc18fbe570bd236b1b4bc", "src_uid": "ac2e795cd44061db8da13e3947ba791b", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\n\n\npublic class Main {\n public static BufferedReader bf;\n public static long MOD = 998244353;\n\n public static void main(String[] args) throws IOException {\n bf = new BufferedReader(new InputStreamReader(System.in));\n int T = Integer.parseInt(bf.readLine().trim());\n PrintWriter out = new PrintWriter(System.out);\n while (T-- > 0) {\n String[] ip = bf.readLine().split(\" \");\n int N = Integer.parseInt(ip[0]);\n\n long nthFibo = getNthFibo(N);\n long denominator = binaryExpo(2, N);\n long modInverse = inverseMod(denominator);\n\n long ans = (modInverse % MOD * nthFibo % MOD) % MOD;\n out.println(ans);\n\n }\n\n out.flush();\n\n\n }\n\n private static long inverseMod(long denominator) {\n return binaryExpo(denominator, MOD - 2);\n }\n\n private static long binaryExpo(long base, long pow) {\n\n long res = 1;\n while (pow >= 1) {\n if (pow % 2 != 0) {\n pow--;\n res = (res % MOD * base % MOD) % MOD;\n }\n pow = pow / 2;\n base = (base % MOD * base % MOD) % MOD;\n }\n\n return res;\n\n\n }\n\n\n private static long getNthFibo(int n) {\n long[][] matrix = new long[][]{\n {0, 1},\n {1, 1}\n };\n long[] baseCases = new long[]{1, 1};\n matrixExpoUnderMod(matrix, n - 1);\n long ans = ((baseCases[0] % MOD * matrix[0][0] % MOD) % MOD + (baseCases[1] % MOD * matrix[0][1] % MOD) % MOD) % MOD;\n\n return ans;\n }\n\n private static void matrixExpoUnderMod(long[][] matrix, int pow) {\n long[][] res = new long[2][2];\n for (int i = 0; i < 2; i++) {\n for (int j = 0; j < 2; j++) {\n if (i == j) res[i][j] = 1;\n }\n }\n while (pow >= 1) {\n if (pow % 2 != 0) {\n matrixMultiply(res, matrix);\n pow--;\n }\n pow = pow / 2;\n matrixMultiply(matrix, matrix);\n }\n\n for (int i = 0; i < 2; i++) {\n for (int j = 0; j < 2; j++) {\n matrix[i][j] = res[i][j];\n }\n }\n }\n\n public static void matrixMultiply(long[][] A, long[][] B) {\n long[][] res = new long[2][2];\n\n for (int i = 0; i < 2; i++) {\n for (int j = 0; j < 2; j++) {\n long sum = 0;\n for (int k = 0; k < 2; k++) {\n sum += (A[i][k] % MOD * B[k][j] % MOD) % MOD;\n }\n res[i][j] = sum;\n }\n }\n for (int i = 0; i < 2; i++) {\n for (int j = 0; j < 2; j++) {\n A[i][j] = res[i][j];\n }\n }\n\n }\n\n\n private static long[] readIntArray(int startIndex) throws IOException {\n String[] ip = bf.readLine().split(\" \");\n int j = -1;\n int len = ip.length;\n if (startIndex == 1) {\n len += 1;\n j = 0;\n }\n\n long[] arr = new long[len];\n\n for (String str : ip)\n arr[++j] = Long.parseLong(str);\n\n\n return arr;\n\n }\n\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "90d2a29eea738982fce030a1e2dda801", "src_uid": "cec37432956bb0a1ce62a0188fe2d805", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Scanner;\n\npublic class InterestingGame\n{\n\tstatic ArrayList[] arr;\n\tstatic int dp[];\n\tstatic int[] ans;\n\tpublic static void main(String[] args)\n\t{\n\t\t\n\t\tdp = new int[100001];\n\t\tans = new int[100001];\n\t\tArrays.fill(dp, -1);\n//\t\tfor (int i = 0; i < 100001; i++)\n//\t\t\tSystem.out.println(i + \" \" + G(i));\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tif(G(n) == 0)\n\t\t\tSystem.out.println(-1);\n\t\telse\n\t\t\tSystem.out.println(ans[n]);\n\t}\n\t\n\tprivate static int G(int n)\n\t{\n\t\tif(dp[n] != -1)\n\t\t\treturn dp[n];\n\t\tHashSet set = new HashSet();\n\t\tans[n] = 1000000;\n\t\tfor (int k = 2;(n - sumto(k-1)) / k > 0; k++)\n\t\t{\n\t\t\tif((n - sumto(k-1)) % k == 0)\n\t\t\t{\n\t\t\t\tint st = (int)((n - sumto(k-1)) / k);\n\t\t\t\tint xor = 0;\n\t\t\t\tfor (int i = 0; i < k; i++)\n\t\t\t\t\txor ^= G(st++);\n\t\t\t\tif(xor == 0)\n\t\t\t\t\tans[n] = Math.min(ans[n], k);\n\t\t\t\tset.add(xor);\n\t\t\t}\n\t\t}\n\t\treturn dp[n] = mex(set);\n\t}\n\n\tstatic int mex(HashSet set)\n\t{\n\t\tint ret = 0;\n\t\twhile(set.contains(ret))\n\t\t\tret++;\n\t\treturn ret;\n\t}\n\t\n\tstatic long sumto(int n)\n\t{\n\t\tlong n1 = n;\n\t\tlong n2 = n+1;\n\t\tif(n1 % 2 == 0)\n\t\t\tn1 /= 2;\n\t\telse\n\t\t\tn2/=2;\n\t\treturn 1l*n1*n2;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "ee42985bf09c8b13546b8a9b964b19e3", "src_uid": "63262317ba572d78163c91b853c05506", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "/*\nallowed +0, +2, +3\n*/\nimport java.util.*;\n\npublic class CheckCalendar {\n\tpublic static void main(String[] args) {\n\t\tScanner s = new Scanner(System.in);\n\n\t\tMap map = new HashMap();\n\t\tmap.put(\"monday\", 0);\n\t\tmap.put(\"tuesday\", 1);\n\t\tmap.put(\"wednesday\", 2);\n\t\tmap.put(\"thursday\", 3);\n\t\tmap.put(\"friday\", 4);\n\t\tmap.put(\"saturday\", 5);\n\t\tmap.put(\"sunday\", 6);\n\n\t\tint one = map.get(s.next()), two = map.get(s.next()); if(one > two) two += 7;\n\t\tint diff = two - one;\n\t\tif(diff == 0 || diff == 2 || diff == 3) System.out.println(\"YES\");\n\t\telse System.out.println(\"NO\");\u00e5\n\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "970100331333065b0446c280715d2fab", "src_uid": "2a75f68a7374b90b80bb362c6ead9a35", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Camels {\n\n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n int n = s.nextInt();\n int t = s.nextInt();\n int[][][][] dp = new int[n][t + 1][4][2];\n\n for (int k0 = 0; k0 < 4; k0++) {\n for (int k1 = 0; k1 < 4; k1++) {\n for (int k2 = 0; k2 < 4; k2++) {\n if (k1 > k0 && k1 > k2) {\n dp[2][1][k2][0] += 1;\n }\n if (k1 < k0 && k1 < k2) {\n dp[2][1][k2][1] += 0;\n }\n if (k0 < k1 && k1 < k2) {\n dp[2][0][k2][1] += 1;\n }\n if (k0 > k1 && k1 > k2) {\n dp[2][0][k2][0] += 0;\n }\n }\n }\n }\n\n for (int i = 3; i < n; i++) {\n for (int j = 0; j < t + 1; j++) {\n for (int k = 0; k < 4; k++) {\n for (int l = k + 1; l < 4; l++) {\n if (j > 0) {\n dp[i][j][k][0] += dp[i - 1][j - 1][l][1];\n }\n dp[i][j][k][0] += dp[i - 1][j][l][0];\n }\n for (int l = 0; l < k; l++) {\n if (j > 0) {\n //dp[i][j][k][1] += dp[i - 1][j - 1][l][0];\n }\n dp[i][j][k][1] += dp[i - 1][j][l][1];\n }\n }\n }\n }\n\n int res = 0;\n for (int i = 0; i < 4; i++) {\n res += dp[n - 1][t][i][0];\n }\n\n System.out.println(res);\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ab372da312a389b430b0416734f2d1af", "src_uid": "6d67559744583229455c5eafe68f7952", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.DataInputStream;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Set;\n\n/**\n * Built using CHelper plug-in Actual solution is at the top\n *\n * @author da_201612051\n */\npublic class Main {\n\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastIO in = new FastIO(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskA1 solver = new TaskA1();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskA1 {\n\n public void solve(int testNumber, FastIO in, PrintWriter out) throws IOException {\n int n = in.nextInt();\n int k = in.nextInt();\n int[] query = in.nextIntArray(n);\n int cost = 0;\n Set avaialbleBooks = new HashSet<>(k);\n int[] access = new int[81];\n Arrays.stream(query).forEach(book -> access[book]++);\n for (int i = 0; i < n; i++) {\n if (!avaialbleBooks.contains(query[i])) {\n cost++;\n }\n if (avaialbleBooks.size() < k && --access[query[i]] > 0) {\n avaialbleBooks.add(query[i]);\n } else if (access[query[i]] == 0) {\n avaialbleBooks.remove(query[i]);\n }\n }\n System.out.println(cost);\n }\n\n }\n\n static class FastIO {\n\n final private int BUFFER_SIZE = 1 << 16;\n private InputStream din;\n private byte[] buffer;\n private int bufferPointer;\n private int bytesRead;\n\n public FastIO() {\n buffer = new byte[BUFFER_SIZE];\n bufferPointer = bytesRead = 0;\n }\n\n public FastIO(InputStream inputStream) {\n this();\n din = new DataInputStream(inputStream);\n }\n\n public FastIO(String file_name) throws IOException {\n din = new DataInputStream(new FileInputStream(file_name));\n buffer = new byte[BUFFER_SIZE];\n bufferPointer = bytesRead = 0;\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 int[] nextIntArray(int n) throws IOException {\n int[] arr = new int[n];\n for (int i = 0; i < n; i++) {\n arr[i] = nextInt();\n }\n return arr;\n }\n\n 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 }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "9df9f6cc76263f53c0b7a863585e2e06", "src_uid": "956228e31679caa9952b216e010f9773", "difficulty": 1800.0} {"lang": "Java 11", "source_code": "import java.lang.*;\nimport java.util.*;\n\npublic class deathStar{\n public static void main(String[] args){\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n char[][] arr1=new char[n][n];\n char[][] arr2=new char[n][n];\n for(int i=0; i0) {\r\n String s[]=br.readLine().split(\" \");\r\n int n=ni(s[0]),k=ni(s[1]);\r\n long res=1,mod=(long)1e9+7;\r\n for(int i=0;i cur) ans = cur;\n }\n cur = (cur * 10 + s.charAt(i)-'0') % m;\n cur = (cur - mul * (s.charAt(i)-'0')) % m;\n if (cur < 0) cur += m;\n }\n out.println(ans);\n }\n}\n\nclass InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n \n public double nextDouble() {\n return Double.parseDouble(next());\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8cf6493f78a5eafc774fe612781fac6e", "src_uid": "d13c7b5b5fc5c433cc8f374ddb16ef79", "difficulty": 2300.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class Main {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in); \n \n String a = in.next();\n String b = in.next();\n \n int mn = 1;\n \n for (int i=0; i mn)\n mn = a.charAt(i) - '0';\n }\n \n BigInteger aa = new BigInteger(a, mn+1);\n BigInteger bb = new BigInteger(b, mn+1);\n \n aa = aa.add(bb);\n \n\n \n \n \n \n String str = aa.toString(mn+1);\n System.out.println(str.length());\n }\n } ", "lang_cluster": "Java", "compilation_error": false, "code_uid": "68cc6f4b465669344d7cd4b722bb3000", "src_uid": "8ccfb9b1fef6a992177cc49bd56fab7b", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.lang.*;\n\npublic class tyler\n{ \n public static void main(String args[])\n {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int[] a = new int[n];\n int sum = 1000000;\n for(int i=0;i=x) sum1 = sum1 + a[k]*x*4;\n else sum1 = sum1 + a[k]*k*4;\n }\n if(sum>sum1) sum = sum1;\n }\n \n System.out.println(sum);\n }", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f180af27782d39a3ed8bf1e804f8819d", "src_uid": "a5002ddf9e792cb4b4685e630f1e1b8f", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.math.BigInteger;\nimport java.util.Arrays;\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) throws IOException {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader sc = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n Task solver = new Task();\n solver.solve(1, sc, out);\n out.close();\n }\n\n static class Task {\n \tpublic static final long Mod=(long) (1e9+7);\n \t\n public void solve(int testNumber, InputReader sc, PrintWriter out) throws IOException {\n \tint h=sc.nextInt();\n \tint w=sc.nextInt();\n int[] col=new int[w+1]; //\u6bcf\u5217\u6700\u8d77\u7801\u7684\u9ad8\n int[] row=new int[h+1]; //\u6bcf\u5217\u6700\u8d77\u7801\u7684\u5bbd\n boolean[][] vis=new boolean[h+1][w+1];\n \n Arrays.fill(vis[0], true);\n for(int i=1;i<=h;i++) {\n \trow[i]=sc.nextInt()+1;\n for(int j=0;j<=row[i]-1;j++)\n \tvis[i][j]=true;\n }\n for(int i=1;i<=w;i++) {\n \tcol[i]=sc.nextInt()+1;\n \tfor(int j=1;j<=col[i]-1;j++) {\n \t\tif((vis[j][i-1]&&!vis[j][i])||(vis[j-1][i]&&!vis[j][i])) {\n \t\t\tout.println(\"0\");\n \t\t\treturn ;\n \t\t}\n \t}\n }\n for(int i=1;i<=h;i++) \n \tfor(int j=1;j<=w;j++) \n \t\tvis[i][j]=false;\n for(int i=1;i<=w;i++) {\n \tfor(int j=1;j<=col[i]-1;j++) {\n \t\tvis[j][i]=true;\n \t}\n }\n for(int i=1;i<=h;i++) {\n for(int j=1;j<=row[i]-1;j++)\n \tif((vis[i-1][j]&&!vis[i][j])||(vis[i][j-1]&&!vis[i][j])) {\n \t\tout.println(\"0\");\n \t\treturn ;\n \t}\n }\n \n \n long ans=1;\n\n \n for(int i=1;i<=h;i++) {\n \tfor(int j=1;j<=w;j++) {\n \t \n \t\tif(i>col[j]&&col[j]<=h&&j>row[i]&&row[i]<=w) {\n \t\t\tans=(ans*2)%Mod;\n \t\t}\n \t}\n }\n out.println(ans);\n }\n\n }\n\n static class InputReader{\n StreamTokenizer tokenizer;\n public InputReader(InputStream stream){\n tokenizer=new StreamTokenizer(new BufferedReader(new InputStreamReader(stream)));\n tokenizer.ordinaryChars(33,126);\n tokenizer.wordChars(33,126);\n }\n public String next() throws IOException {\n tokenizer.nextToken();\n return tokenizer.sval;\n }\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n public boolean hasNext() throws IOException {\n int res=tokenizer.nextToken();\n tokenizer.pushBack();\n return res!=tokenizer.TT_EOF;\n }\n \n public double nextDouble() throws NumberFormatException, IOException {\n \treturn Double.parseDouble(next());\n }\n \n public BigInteger nextBigInteger() throws IOException {\n \treturn new BigInteger(next());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a78469b4a084e9aa8c582a77112d74be", "src_uid": "04610fbaa746c083dda30e21fa6e1a0c", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "\n\nimport java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n=sc.nextInt(),m=sc.nextInt(),s=sc.nextInt();\n n--;\n m--;\n long positions;\n if( s > n )\n positions = n+1;\n else\n positions = n%s+1;\n if( s > m )\n positions *= m+1;\n else\n positions *= (m%s+1);\n\n long dxy = (n/s+1)*(m/s+1);\n\n System.out.println(positions*dxy);\n \n \n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bca691ddfd55216cd4a26f69e24ea7c6", "src_uid": "e853733fb2ed87c56623ff9a5ac09c36", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\n\npublic class C {\n\n \n static long solve(long l) {\n if(l==0) {\n return 0;\n } else if(l==1) {\n return 1;\n }\n StringBuilder s=new StringBuilder(); s.append(\"1\");\n while(Long.parseLong(s.toString())0) {\n here[j++]=Integer.parseInt(sb.toString());\n }\n }\n \n static void run_stream(InputStream ins) throws IOException {\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n long n=Long.parseLong(br.readLine());\n System.out.println(solve(n));\n }\n\n public static void main(String[] args) throws IOException {\n run_stream(System.in);\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7977b3e35442e22b8d01f8f2edb78109", "src_uid": "1b17a7b3b41077843ee1d6e0607720d6", "difficulty": 1800.0} {"lang": "Java 7", "source_code": "import\tjava.util.*;\npublic\tclass\tMain{\n\tpublic\tstatic\tvoid\tmain(String[]args){\n\t\tScanner\tcin=new\tScanner(System.in);\n\t\tlong\ts=0,n=cin.nextLong(),m,x=2,y,z,a,b,c;\n\t\tif(0==n%6)\tfor(n/=3;x*x*x<=n;++x)\n\t\t\tif(1>n%x)\tfor(m=n/x,y=x;y*y<=m;++y)\n\t\t\t\tif(1>m%y&&1>(1&(x^(z=m/y)^y))&&1<(a=x+y-z))\n\t\t\t\t\ts+=(c=(y<<1)-a)==a?1:(b=(x<<1)-a)==a||b==c?3:6;\n\t\tSystem.out.print(s);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f4d37c267940bb5df00f036dcfabd4fb", "src_uid": "07e58a46f2d562a44b7c771edad361b4", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.*;\npublic class LimakAndRadewoosh\n{\npublic static void main(String[] args)\n{\nString Pobeda = \"\";\nBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\ntry\n{\nStringBuffer o = new StringBuffer(br.readLine());\nStringBuffer s1 = new StringBuffer(br.readLine());\nStringBuffer s2 = new StringBuffer(s1.substring(0,s1.length()));\nStringBuffer t = new StringBuffer(br.readLine());\nStringBuffer t2 = new StrigBffer(t.substring(0,t.length()));\nint count = Integer.parseInt(o.substring(0,o.indexOf(\" \")));\nint c = Integer.parseInt(o.substring(s1.indexOf(\" \") + 1,o.length()));\nint[] timeLimak = new int[count];\nint[] timeRadewoosh = new int[count];\nint[] zadachaLimak = new int[count];\nint[] zadachaRadewoosh = new int[count];\nint[] resLimak = new int[count];\nint[] resRadewoosh = new int[count];\nint itogLimak = 0;\nint itogRadewoosh = 0;\nfor(int i = 0; i < count;i++)\n{\n zadachaLimak[i] = Integer.parseInt(s1.substring(0,s1.indexOf(\" \")));\n s1.delete(0,s1.indexOf(\" \"));\n timeLimak[i] = Integer.parseInt(t.substring(0,t.indexOf(\" \")));\n t.delete(0,t.indexOf(\" \"));\n \n}\nfor(int i = count;i >= 0;i--)\n{\n zadachaRadewoosh[i] = Integer.parseInt(s2.substring(s2.lastIndexOf(\" \"),s2.length()));\n s2.delete(s2.lastIndexOf(\" \"),s2.length());\n timeRadewoosh[i] = Integer.parseInt(t2.substring(t2.lastIndexOf(\" \"),t2.length()));\n t2.delete(t2.lastIndexOf(\" \"),t2.length());\n}\nfor(int i = 0;i < count;i++)\n{\n resLimak[i] = zadachaLimak[i] - (c * timeLimak[i]); \n}\nfor(int i = count;i >= 0;i--)\n{\n resRadewoosh[i] = zadachaRadewoosh[i] - (c * timeRadewoosh[i]);\n}\nfor(int u = 0,p = count;u < count && p >= 0;u++,p--)\n{\n itogLimak += resLimak[u];\n itogRadewoosh += resRadewoosh[p];\n}\nif(itogLimak > itogRadewoosh)\n{\n Pobeda = \"Limak\"; \n}\nelse if(itogRadewoosh > itogLimak)\n{\n Pobeda = \"Radewoosh\";\n}\nelse if(itogLimak == itogRadewoosh)\n{\n Pobeda = \"Tie\";\n}\n}\ncatch(Exception excp)\n{\n \n}\nfinally\n{\n System.out.println(Pobeda);\n}\n}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5b0f57aec66328079d9571749e2bc020", "src_uid": "8c704de75ab85f9e2c04a926143c8b4a", "difficulty": 800.0} {"lang": "Java 8", "source_code": "public class Main {\n\n public static void main(String[] args) {\n\t Scanner in = new Scanner(System.in);\n double d = in.nextDouble();\n double L = in.nextDouble();\n double v1 = in.nextDouble();\n double v2 = in.nextDouble();\n\n double x = (L - d) * v1/ (v1 + v2);\n System.out.print(x/v1);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "667536fd8f29ebce76f4755e2f366213", "src_uid": "f34f3f974a21144b9f6e8615c41830f5", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.*;\npublic class A\n{\npublic static void main(String[] args)\n{\n int day = 0;\nBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\ntry\n{\nString s = br.readLine();\nint aS = Integer.parseInt(s.substring(0,2));\nint bS = Integer.parseInt(s.substring(s.length() - 2));\nString s1 = br.readLine();\nint a = Integer.parseInt(s1.substring(0,1));\nint b = Integer.parseInt(s1.substring(s1.length() - 1));\nint tGusSt = 10;\nint tGusEnd = 22;\nint tBoyEnd = 14;\nint tCount = 10;\ndo\n{\n tCount++;\n if(tCount == tBoyEnd)\n {\n isUp = false;\n day++;\n aS += a;\n if(tCount != tGusEnd)\n {\n aS += a;\n aS -= b;\n }\n }\n else\n {\n isUp = true;\n }\n if(isUp == true)\n {\n if(tCount != tBoyEnd)\n {\n aS += b;\n }\n }\n}while(aS != bS);\n}\ncatch(Exception excp)\n{\n\n}\nfinally\n{\n System.out.println(day);\n}\n}\n} ", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0116e9f4bd9923f6fb2f4f052b2dd8b3", "src_uid": "2c39638f07c3d789ba4c323a205487d7", "difficulty": 1400.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Permutation {\n\t\n\tstatic HashSet perm;\n\tstatic int n,k;\n\t\n\tstatic String toString(int[] idx) {\n\t\tStringBuilder sb = new StringBuilder(\"\");\n\t\tfor(int i=0;i();\n int idx[] = new int[k];\n for(int i=1;i<=k;i++) idx[i-1] = i;\n for(int i=0;i {\n\t\tint x, y;\n\t\tPair(int a, int b){ x = a; y = b; }\n\t\tint getKey() { return x; }\n\t\tint getVal() { return y; }\n\t\t@Override\n\t\tpublic int compareTo(Pair o) {\n\t\t\tif(o.getVal() - this.getVal()>0)\n\t\t\t\treturn -1;\n\t\t\telse if(o.getVal() - this.getVal()<0)\n\t\t\t\treturn 1;\n\t\t\telse \n\t\t\t\treturn 0;\n\t\t}\n\t\t\n\t}\n\t\n\tstatic boolean arrayEquals(char a[], char b[]) {\n\t\tint n = a.length;\n\t\tboolean verdict = true;\n\t\tfor(int i=0;i B[0])\n\t\t\t\tmove(A, B, 1, 0);\n\t\t\telse\n\t\t\t\tmove(A, B, 0, 1);\n\n\t\t\tif (A[0] <= B[0] && A[1] <= B[1])\n\t\t\t\texit(YES);\n\n\t\t\tif (canMove(B, A, 1, 1))\n\t\t\t\tmove(B, A, 1, 1);\n\t\t\telse if (canMove(B, A, 1, 0))\n\t\t\t\tmove(B, A, 1, 0);\n\t\t\telse\n\t\t\t\tmove(B, A, 0, 1);\n\n\t\t\tif (B[0] == 0 && B[1] == 0)\n\t\t\t\texit(NO);\n\t\t}\n\t}\n\n\tvoid move(int [] A, int [] B, int x, int y) {\n\t\tif (canMove(A, B, x, y)) {\n\t\t\tA[0] -= x;\n\t\t\tA[1] -= y;\n\t\t}\n\t}\n\n\tboolean canMove(int [] A, int [] B, int x, int y) {\n\t\tif (A[0] - x == B[0] && A[1] - y == B[1])\n\t\t\treturn false;\n\t\telse if (A[0] - x < 0 || A[1] - y < 0)\n\t\t\treturn false;\n\t\telse\n\t\t\treturn true;\n\t}\n\n\t////////////////////////////////////////////////////////////////////////////////////\n\tprivate final static IOUtils.MyScanner sc = new IOUtils.MyScanner();\n\tprivate static void exit (Object o, Object ... A) { IOUtils.print(o, A); IOUtils.exit(); }\n\tprivate static class IOUtils {\n\t\tpublic static class MyScanner {\n\t\t\tpublic String next() { newLine(); return line[index++]; }\n\t\t\tpublic int nextInt() { return Integer.parseInt(next()); }\n\t\t\tpublic int [] nextInt (int N) {\n\t\t\t\tint [] res = new int [N];\n\t\t\t\tfor (int i = 0; i < N; ++i)\n\t\t\t\t\tres[i] = nextInt();\n\t\t\t\treturn res;\n\t\t\t}\n\t\t\t//////////////////////////////////////////////\n\t\t\tprivate boolean eol() { return index == line.length; }\n\t\t\tprivate String readLine() {\n\t\t\t\ttry {\n\t\t\t\t\treturn r.readLine();\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\tthrow new Error (e);\n\t\t\t\t}\n\t\t\t}\n\t\t\tprivate final java.io.BufferedReader r;\n\t\t\tprivate MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }\n\t\t\tprivate MyScanner (java.io.BufferedReader r) {\n\t\t\t\ttry {\n\t\t\t\t\tthis.r = r;\n\t\t\t\t\twhile (!r.ready())\n\t\t\t\t\t\tThread.sleep(1);\n\t\t\t\t\tstart();\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\tthrow new Error(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\tprivate String [] line;\n\t\t\tprivate int index;\n\t\t\tprivate void newLine() {\n\t\t\t\tif (line == null || eol()) {\n\t\t\t\t\tline = split(readLine());\n\t\t\t\t\tindex = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tprivate String [] split(String s) { return s.length() > 0 ? s.split(\" \") : new String [0]; }\n\t\t}\n\t\tprivate static String build(Object o, Object ... A) { return buildDelim(\" \", o, A); }\n\t\tprivate static String buildDelim(String delim, Object o, Object ... A) {\n\t\t\tStringBuilder b = new StringBuilder();\n\t\t\tappend(b, o, delim);\n\t\t\tfor (Object p : A)\n\t\t\t\tappend(b, p, delim);\n\t\t\treturn b.substring(delim.length());\n\t\t}\n\t\t//////////////////////////////////////////////////////////////////////////////////\n\t\tprivate static void start() { if (t == 0) t = millis(); }\n\t\tprivate static void append(StringBuilder b, Object o, String delim) {\n\t\t\tif (o.getClass().isArray()) {\n\t\t\t\tint len = java.lang.reflect.Array.getLength(o);\n\t\t\t\tfor (int i = 0; i < len; ++i)\n\t\t\t\t\tappend(b, java.lang.reflect.Array.get(o, i), delim);\n\t\t\t} else if (o instanceof Iterable)\n\t\t\t\tfor (Object p : (Iterable) o)\n\t\t\t\t\tappend(b, p, delim);\n\t\t\telse {\n\t\t\t\tif (o instanceof Double)\n\t\t\t\t\to = new java.text.DecimalFormat(\"#.############\").format(o);\n\t\t\t\tb.append(delim).append(o);\n\t\t\t}\n\t\t}\n\t\tprivate static java.io.PrintWriter pw = new java.io.PrintWriter(System.out);\n\t\tprivate static void print(Object o, Object ... A) { pw.println(build(o, A)); }\n\t\tprivate static void err(Object o, Object ... A) { System.err.println(build(o, A)); }\n\t\tprivate static void exit() {\n\t\t\tIOUtils.pw.close();\n\t\t\tSystem.out.flush();\n\t\t\terr(\"------------------\");\n\t\t\terr(IOUtils.time());\n\t\t\tSystem.exit(0);\n\t\t}\n\t\tprivate static long t;\n\t\tprivate static long millis() { return System.currentTimeMillis(); }\n\t\tprivate static String time() { return \"Time: \" + (millis() - t) / 1000.0; }\n\t}\n\tpublic static void main (String[] args) { new C(); IOUtils.exit(); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b88ee2b26aaf1ca6abe089e9c2ab589e", "src_uid": "2637d57f7809ff8f922549c617709074", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import javax.imageio.ImageIO;\nimport java.awt.image.BufferedImage;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.net.PortUnreachableException;\nimport java.util.*;\n\n// written by luchy0120\n\npublic class Main {\n public static void main(String[] args) throws Exception {\n\n new Main().run();\n }\n\n static int groups = 0;\n static int[] fa;\n static int[] sz;\n\n static void init(int n) {\n groups = n;\n fa = new int[n];\n for (int i = 1; i < n; ++i) {\n fa[i] = i;\n }\n sz = new int[n];\n Arrays.fill(sz, 1);\n }\n\n static int root(int p) {\n while (p != fa[p]) {\n fa[p] = fa[fa[p]];\n p = fa[p];\n }\n return p;\n }\n\n static void combine(int p, int q) {\n int i = root(p);\n int j = root(q);\n if (i == j) {\n return;\n }\n if (sz[i] < sz[j]) {\n fa[i] = j;\n sz[j] += sz[i];\n } else {\n fa[j] = i;\n sz[i] += sz[j];\n }\n groups--;\n }\n\n int child[];\n int color[],dfn[],low[],stack[],cnt[];\n boolean vis[];\n boolean iscut[];\n int deep,top,n,m,sum,ans;\n List g[];\n int root = 0;\n // \u65e0\u5411\u56fe\u7684\u5f3a\u8fde\u901a\u5206\u91cf\n void tarjanNonDirect(int u1) {\n\n int stk[] = new int[10001];\n int fatk[] = new int[10001];\n int p = 0;\n stk[p] = u1;\n fatk[p] = -1;\n p= 1;\n ot: while(p>0) {\n int u = stk[p-1];\n int fa = fatk[p-1];\n\n\n if(dfn[u]==0) {\n low[u] = dfn[u] = ++deep;\n }\n // stack[top++] = u;\n\n for (; h[u] != -1; h[u] = ne[h[u]]) {\n int v = to[h[u]];\n if (dfn[v] == 0) {\n //tarjanNonDirect(v);\n\n fatk[p] = u;\n stk[p++] = v;\n continue ot;\n } else {\n low[u] = Math.min(low[u], dfn[v]);\n // \u6ca1\u6709\u7279\u5224\u662f\u5426\u76f4\u63a5\u6307\u5411\u7236\u4eb2\n // \u56de\u8fb9\uff0c\u4f7f\u7528dfn\u3010v\u3011\u66f4\u65b0low\u3010u\u3011,\u56e0\u4e3a\u53ef\u80fd\u662f\u6307\u5411\u7236\u4eb2\uff0c\u800c\u7236\u4eb2\u7684low\u53ef\u80fd\u6bd4\u8f83\u5c0f\n }\n }\n --p;\n\n if (fa != -1) {\n low[fa] = Math.min(low[fa], low[u]);\n if (low[u] >= dfn[fa]) {\n if (fa != root || ++child[fa] > 1) { // \u4e0d\u662froot\uff0c\u76f4\u63a5\u8bb0\u4e3acut\uff0c\u662froot\uff0c\u5224\u65ad\u662f\u5426\u6709\u4e24\u4e2a\u513f\u5b50\n iscut[fa] = true;\n }\n ++dcc_cnt;\n // \u4e00\u4e2a\u5272\u70b9\u53ef\u80fd\u4f1a\u88ab\u591a\u4e2a\u70b9\u53cc\u5171\u4eab\n // int z = -1;\n // do {\n // z = stack[--top];\n // dcc[dcc_cnt].add(z);\n // } while(z != v);\n // dcc[dcc_cnt].add(u);\n }\n\n\n }\n\n }\n }\n int gd = 0;\n int id =-1;\n int scc_cnt = 0;\n int sccno[];\n // \u6709\u5411\u56fe\u7684\u5f3a\u8fde\u901a\u5206\u91cf\n void tarjan(int u) {\n int stk[] = new int[10001];\n // int tptk[] = new int[10001];\n\n // int fatk[] = new int[10001];\n int p =1; stk[0] = u;//fatk[0] =-1;\n ot:while(p>0) {\n u = stk[p-1];\n // int fa = fatk[p-1];\n if (dfn[u] == 0) {\n low[u] = dfn[u] = ++deep;\n stack[top++] = u;\n\n }\n\n for (; hc[u] != -1; hc[u] = ne[hc[u]]) {\n int v = to[hc[u]];\n if (dfn[v] == 0) {\n stk[p++] = v;\n continue ot;\n // low[u] = Math.min(low[u], low[v]);\n } else if (sccno[v] == 0) {\n // dfn>0 but sccno==0, means it's in current stack\n low[u] = Math.min(low[u], low[v]);\n }\n }\n\n p--;\n if (dfn[u] == low[u]) {\n sccno[u] = ++scc_cnt;\n if(u==1){\n id = scc_cnt;\n }\n\n while (stack[top - 1] != u) {\n sccno[stack[top - 1]] = scc_cnt;\n if(stack[top - 1]==1){\n id = scc_cnt;\n }\n --top;\n }\n\n --top;\n }\n if(p>=1){\n int fa = stk[p-1];\n low[fa] = Math.min(low[fa], low[u]);\n }\n }\n }\n int rr =0;\n// void solve() {\n//\n// }\n\n\n\n\n// int get_room(int i,int j){\n// return i/3*3 + j/3;\n// }\n\n// int a[][] = new int[9][9];\n// int space = 0;\n//\n// boolean vis_row[][] = new boolean[9][10];\n// boolean vis_col[][] = new boolean[9][10];\n// boolean vis_room[][] = new boolean[9][10];\n// int val[][][] =new int[9][9][];\n// int prepare[][];\n//\n// void dfs(int rt){\n//\n// }\n\n int h[],to[],ne[];int ct =0;\n void add(int u,int v){\n // u--;v--;\n to[ct] = v;\n ne[ct] = h[u];\n h[u] = ct++;\n\n }\n\n int dcc_cnt = 0;\n int time = 0;\n\n\n\n\n\n long summ[];\n int v[];\n int hc[];\n void solve() {\n// File f = new File(\"C:\\\\Users\\\\Luqi\\\\Desktop\\\\1.png\");\n// BufferedImage bi = null;\n// try {\n// bi = ImageIO.read(f);\n// } catch (IOException e) {\n// e.printStackTrace();\n// }\n//\n// int width = bi.getWidth();\n// int height = bi.getHeight();\n String ele[] = {\"H\",\"He\",\"Li\",\"Be\",\"B\",\"C\",\"N\",\"O\",\"F\",\"Ne\",\"Na\",\"Mg\",\"Al\",\"Si\",\"P\",\"S\",\"Cl\",\"Ar\",\"K\",\"Ca\",\"Sc\",\"Ti\",\"V\",\"Cr\",\"Mn\",\"Fe\",\"Co\",\"Ni\",\"Cu\",\"Zn\",\"Ga\",\"Ge\",\"As\",\"Se\",\"Br\",\"Kr\",\"Rb\",\"Sr\",\"Y\",\"Zr\",\"Nb\",\"Mo\",\"Tc\",\"Ru\",\"Rh\",\"Pd\",\"Ag\",\"Cd\",\"In\",\"Sn\",\"Sb\",\"Te\",\"I\",\"Xe\",\"Cs\",\"Ba\",\"La\",\"Ce\",\"Pr\",\"Nd\",\"Pm\",\"Sm\",\"Eu\",\"Gd\",\"Tb\",\"Dy\",\"Ho\",\"Er\",\"Tm\",\"Yb\",\"Lu\",\"Hf\",\"Ta\",\"W\",\"Re\",\"Os\",\"Ir\",\"Pt\",\"Au\",\"Hg\",\"Tl\",\"Pb\",\"Bi\",\"Po\",\"At\",\"Rn\",\"Fr\",\"Ra\",\"Ac\",\"Th\",\"Pa\",\"U\",\"Np\",\"Pu\",\"Am\",\"Cm\",\"Bk\",\"Cf\",\"Es\",\"Fm\",\"Md\",\"No\",\"Lr\",\"Rf\",\"Db\",\"Sg\",\"Bh\",\"Hs\",\"Mt\",\"Ds\",\"Rg\",\"Cn\",\"Nh\",\"Fl\",\"Mc\",\"Lv\",\"Ts\",\"Og\"};\n\n String me[] = new String[ele.length];\n for(int i=0;i= 2 && dp[j - 2] && s.substring(j - 2, j).equals(m)){\n dp[j] = true;\n }\n if (j >= 1 && dp[j - 1] && s.substring(j - 1, j).equals(m)){\n dp[j] = true;\n }\n }\n }\n println(dp[s.length()]?\"YES\":\"NO\");\n\n\n // println(width);\n// // println(height);\n// int i =ni();\n// int j =ni();\n\n\n// for(int i=0;i> 16;\n// b[j][i][1] = (pixel & 0xff00) >> 8;\n// b[j][i][2] = (pixel & 0xff);\n//\n// }\n// println();\n// }\n//\n// for(int i=0;i<64;++i){\n// print(\"\\\"\");\n// for(int j=0;j<64;++j){\n// print(b[i][j][0]<=50?\"*\":\" \");\n// }\n// println(\"\\\",\");\n// }\n// //println(b[0][0]);\n\n\n//\n//\n//\n//\n//\n// }\n// }\n // print(\"No\");\n\n\n\n\n// int n = ni();\n// int m = n*(n+1)/2;\n// int k = ni();\n// int p = 0;\n//\n// double x[] = new double[n];\n// double y[] = new double[n];\n//\n// for(int i=0;i li = new ArrayList<>();\n// for(int i=0;iDouble.compare(xx.s,yy.s));\n//\n// init(n + 1);\n//\n// int s = 0;\n// int c = n;\n// for (int i = 0; i < li.size(); ++i) {\n// int p1 = li.get(i).a;\n// int p2 = li.get(i).b;\n// if (root(p1) != root(p2)) {\n// combine(p1, p2);\n// c--;\n// if(c==k-1){\n// print(roundS(Math.sqrt(li.get(i).s),2));\n// break;\n// }\n// }\n// }\n\n }\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n// }\n\n\n static long mul(long a, long b, long p)\n {\n long res=0,base=a;\n while(b>0)\n {\n if((b&1L)>0)\n res=(res+base)%p;\n base=(base+base)%p;\n b>>=1;\n }\n return res;\n }\n\n\n static long mod_pow(long k,long n,long p){\n long res = 1L;\n long temp = (k%p+p)%p;\n while(n!=0L){\n if((n&1L)==1L){\n res = ((res*temp)%p+p)%p;\n }\n temp = ((temp * temp)%p+p)%p;\n n = n>>1L;\n }\n return res%p;\n }\n public static String roundS(double result, int scale){\n String fmt = String.format(\"%%.%df\", scale);\n return String.format(fmt, result);\n }\n\n\n// void solve() {\n//\n// for(int i=0;i<9;++i) {\n// for (int j = 0; j < 9; ++j) {\n// int v = ni();\n// a[i][j] = v;\n// if(v>0) {\n// vis_row[i][v] = true;\n// vis_col[j][v] = true;\n// vis_room[get_room(i, j)][v] = true;\n// }else{\n// space++;\n// }\n// }\n// }\n//\n//\n// prepare = new int[space][2];\n//\n// int p = 0;\n//\n// for(int i=0;i<9;++i) {\n// for (int j = 0; j < 9; ++j) {\n// if(a[i][j]==0){\n// prepare[p][0] = i;\n// prepare[p][1]= j;p++;\n// List temp =new ArrayList<>();\n// for(int k=1;k<=9;++k){\n// if(!vis_col[j][k]&&!vis_row[i][k]&&!vis_room[get_room(i,j)][k]){\n// temp.add(k);\n// }\n// }\n// int sz = temp.size();\n// val[i][j] = new int[sz];\n// for(int k=0;k{\n// return Integer.compare(val[x[0]][x[1]].length,val[y[0]][y[1]].length);\n// });\n// dfs(0);\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n// }\n\n\n\n\n InputStream is;\n PrintWriter out;\n\n void run() throws Exception {\n //is = new FileInputStream(new File(\"C:\\\\Users\\\\Luqi\\\\Downloads\\\\P3387_9.in\"));\n is = System.in;\n out = new PrintWriter(System.out);\n\n solve();\n out.flush();\n }\n\n private byte[] inbuf = new byte[1024];\n public int lenbuf = 0, ptrbuf = 0;\n\n private int readByte() {\n if (lenbuf == -1) throw new InputMismatchException();\n if (ptrbuf >= lenbuf) {\n ptrbuf = 0;\n try {\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 char ncc() {\n int b = readByte();\n return (char) b;\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 String nline() {\n int b = skip();\n StringBuilder sb = new StringBuilder();\n while (!isSpaceChar(b) || b == ' ') {\n sb.appendCodePoint(b);\n b = readByte();\n }\n return sb.toString();\n }\n\n private char[][] nm(int n, int m) {\n char[][] a = new char[n][];\n for (int i = 0; i < n; i++) a[i] = ns(m);\n return a;\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 long[] nal(int n) {\n long[] a = new long[n];\n for (int i = 0; i < n; i++) a[i] = nl();\n return a;\n }\n\n private int ni() {\n int num = 0, b;\n boolean minus = false;\n while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) {\n }\n ;\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n while (true) {\n if (b >= '0' && b <= '9') num = (num << 3) + (num << 1) + (b - '0');\n else return minus ? -num : num;\n b = readByte();\n }\n }\n\n private long nl() {\n long num = 0;\n int b;\n boolean minus = false;\n while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) {\n }\n ;\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n while (true) {\n if (b >= '0' && b <= '9') num = num * 10 + (b - '0');\n else return minus ? -num : num;\n b = readByte();\n }\n }\n\n void print(Object obj) {\n out.print(obj);\n }\n\n void println(Object obj) {\n out.println(obj);\n }\n\n void println() {\n out.println();\n }\n\n void printArray(int a[],int from){\n int l = a.length;\n for(int i=from;i=1){\n\n if((b&1)!=0){\n ans=ans*a%mod;\n }\n a=a*a%mod;\n b=b>>1;\n }return ans;\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "16f6bafacb7df9f02df60b8a62b89155", "src_uid": "e6b3e559b5fd4e05adf9f1cd1b22126b", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.lang.reflect.Array;\nimport java.math.BigDecimal;\nimport java.math.RoundingMode;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.Map;\nimport java.util.StringTokenizer;\nimport java.util.stream.IntStream;\n\n public class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner() {\n try {\n br = new BufferedReader(new InputStreamReader(System.in));\n st = new StringTokenizer(\"\");\n } catch (Exception e) {\n e.printStackTrace();\n }\n }\n\n public String next() {\n if (st.hasMoreTokens())\n return st.nextToken();\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n e.printStackTrace();\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 line = \"\";\n try {\n line = br.readLine();\n } catch (Exception e) {\n e.printStackTrace();\n }\n return line;\n }\n\n public int[] nextIntArray(int n) {\n int[] a = new int[n];\n for (int i = 0; i < n; i++)\n a[i] = nextInt();\n return a;\n }\n\n public long[] nextLongArray(int n) {\n long[] a = new long[n];\n for (int i = 0; i < n; i++)\n a[i] = nextLong();\n return a;\n }\n\n public char[] nextCharArray() {\n return nextLine().toCharArray();\n }\n }\n\npublic class Main\n{\n\n private static int maxMark = 650;\n\n public static void main(String[] args)\n {\n\tFastScanner fs = new FastScanner();\n boolean[] aMarks = new boolean[maxMark + 1];\n int i = 0;\n while(i <= maxMark)\n {\n aMarks[i] = false;\n i = i + 1;\n }\n int n = fs.nextInt();\n i = 0;\n int ans = 0;\n while(i < n)\n {\n int mark = fs.nextInt();\n if(mark != 0)\n {\n if(!aMarks[mark])\n \t{\n \taMarks[mark] = true;\n \tans = ans + 1;\n \t}\n }\n i = i + 1;\n }\n System.out.print(ans);\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "3263f434d371971e7d80348da3485726", "src_uid": "3b520c15ea9a11b16129da30dcfb5161", "difficulty": 800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\n\nimport Utils.MathUtils;\n\npublic final class Main\n{\n\tstatic long mod = 998244353l;\n\n\tpublic static void main(String[] args) throws IOException\n\t{\n\t\tScanner in = getScan(args);\n\t\t// int tt = in.nextInt();\n\t\t// while (tt-- > 0)\n\t\t// {\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tlong res = MathUtils.divMod(fact(m), fact(n - 1) * fact(m - n + 1), mod);\n\n\t\tif (n < 3)\n\t\t{\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\tlong pow = MathUtils.binpowMod(2, n - 3, mod);\n\t\tlong tmp = (pow * (n - 2)) % mod;\n\t\tres = (res * tmp) % mod;\n\t\tSystem.out.println(res);\n\t\t// }\n\t}\n\n\tpublic static long fact(int n)\n\t{\n\t\tlong res = 1;\n\t\tfor (int i = 1; i <= n; i++)\n\t\t{\n\t\t\tres = (res * i) % mod;\n\t\t}\n\t\treturn res;\n\t}\n\n\tpublic static int log2nlz(int bits)\n\t{\n\t\tif (bits == 0) return 0; // or throw exception\n\t\treturn 31 - Integer.numberOfLeadingZeros(bits);\n\t}\n\n\tstatic Scanner getScan(String[] args) throws IOException\n\t{\n\t\tif (args.length == 0)\n\t\t{\n\t\t\treturn new Scanner(System.in);\n\t\t}\n\t\telse\n\t\t{\n\t\t\treturn new Scanner(new File(args[0]));\n\t\t}\n\t}\n\n\tstatic BufferedReader getBuffer(String[] args) throws IOException\n\t{\n\t\tif (args.length == 0)\n\t\t{\n\t\t\treturn new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\t\telse\n\t\t{\n\t\t\treturn new BufferedReader(new FileReader(args[0]));\n\t\t}\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0afb1fa1a7b8b166bfd6705c3894a6d4", "src_uid": "28d6fc8973a3e0076a21c2ea490dfdba", "difficulty": 1700.0} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class H {\n FastScanner in;\n PrintWriter out;\n\n int calc(int size) {\n if (size <= 1) {\n return 0;\n }\n return size * (size - 1) / 2 + calc(size / 2) + calc((size + 1) / 2);\n }\n\n class Query {\n int fr, to;\n int id;\n\n public Query(int fr, int to, int id) {\n this.fr = fr;\n this.to = to;\n this.id = id;\n }\n }\n\n List left = new ArrayList<>();\n List right = new ArrayList<>();\n\n int first(int from, int to, int yFr, int yTo) {\n while (from != to + 1 && (a[from] < yFr || a[from] > yTo)) {\n from++;\n }\n return from;\n }\n\n int last(int from, int to, int yFr, int yTo) {\n while (to != from - 1 && (a[to] < yFr || a[to] > yTo)) {\n to--;\n }\n return to;\n }\n\n List go(List from, List to, int yFr, int yTo) {\n for (int i : from) {\n if (i >= a.length) {\n throw new AssertionError();\n }\n }\n for (int i : to) {\n if (i >= a.length) {\n throw new AssertionError();\n }\n }\n if (from.size() == 0) {\n return new ArrayList<>();\n }\n if (yFr == yTo) {\n List res = new ArrayList<>();\n for (int i = 0; i < from.size(); i++) {\n res.add(from.get(i));\n }\n return res;\n } else {\n int yMid = (yFr + yTo) / 2;\n List join1 = new ArrayList<>();\n List join2 = new ArrayList<>();\n List askFr = new ArrayList<>();\n List askTo = new ArrayList<>();\n cacheIt++;\n // [yFr.. yMid] [yMid + 1..tTo]\n for (int i = 0; i < from.size(); i++) {\n int f1 = first(from.get(i), to.get(i), yFr, yMid);\n int t1 = last(from.get(i), to.get(i), yFr, yMid);\n if (f1 > t1) {\n join1.add(-1);\n } else {\n if (cache[f1][t1] != cacheIt) {\n cache[f1][t1] = cacheIt;\n cacheVal[f1][t1] = askFr.size();\n askFr.add(f1);\n askTo.add(t1);\n }\n join1.add(cacheVal[f1][t1]);\n }\n }\n List r1 = go(askFr, askTo, yFr, yMid);\n for (int i = 0; i < join1.size(); i++) {\n if (join1.get(i) != -1) {\n// System.err.println(join1.get(i)+\" \" + askFr.size());\n join1.set(i, r1.get(join1.get(i)));\n }\n }\n cacheIt++;\n askFr.clear();\n askTo.clear();\n for (int i = 0; i < from.size(); i++) {\n int f1 = first(from.get(i), to.get(i), yMid + 1, yTo);\n int t1 = last(from.get(i), to.get(i), yMid + 1, yTo);\n if (f1 > t1) {\n join2.add(-1);\n } else {\n if (cache[f1][t1] != cacheIt) {\n cache[f1][t1] = cacheIt;\n cacheVal[f1][t1] = askFr.size();\n askFr.add(f1);\n askTo.add(t1);\n }\n join2.add(cacheVal[f1][t1]);\n }\n }\n List r2 = go(askFr, askTo, yMid + 1, yTo);\n for (int i = 0; i < join2.size(); i++) {\n if (join2.get(i) != -1) {\n join2.set(i, r2.get(join2.get(i)));\n }\n }\n List res = new ArrayList<>();\n for (int i = 0; i < from.size(); i++) {\n int x = join1.get(i), y = join2.get(i);\n if (x == -1 || y == -1) {\n res.add(x + y + 1);\n } else {\n left.add(x);\n right.add(y);\n res.add(left.size() - 1);\n }\n }\n return res;\n }\n }\n\n\n int[][] cache;\n int[][] cacheVal;\n int cacheIt = 1;\n int[] a;\n\n void solve() {\n int n = in.nextInt();\n cache = new int[n][n];\n cacheVal = new int[n][n];\n int q = in.nextInt();\n a = new int[n];\n for (int i = 0; i < n; i++) {\n a[i] = in.nextInt() - 1;\n }\n\n List from = new ArrayList<>();\n List to = new ArrayList<>();\n for (int i = 0; i < q; i++) {\n from.add(in.nextInt() - 1);\n to.add(in.nextInt() - 1);\n }\n List res = go(from, to, 0, n - 1);\n out.println(n + left.size());\n for (int i = 0; i < left.size(); i++) {\n out.println((left.get(i) + 1) + \" \" + (right.get(i) + 1));\n }\n for (int i = 0; i < res.size(); i++) {\n out.print((res.get(i) + 1) + \" \");\n }\n out.println();\n }\n\n void run() {\n try {\n in = new FastScanner(new File(\"H.in\"));\n out = new PrintWriter(new File(\"H.out\"));\n\n solve();\n\n out.close();\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n\n void runIO() {\n\n in = new FastScanner(System.in);\n out = new PrintWriter(System.out);\n\n solve();\n\n out.close();\n }\n\n class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(File f) {\n try {\n br = new BufferedReader(new FileReader(f));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n\n public FastScanner(InputStream f) {\n br = new BufferedReader(new InputStreamReader(f));\n }\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return null;\n st = new StringTokenizer(s);\n }\n return st.nextToken();\n }\n\n boolean hasMoreTokens() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return false;\n st = new StringTokenizer(s);\n }\n return true;\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n\n public static void main(String[] args) {\n new H().runIO();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d8df34ac18c4f82a863ea73d3f62d51f", "src_uid": "60cf596ad4853ebf3bbf9a96ef5d8791", "difficulty": 3300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main{\n\tstatic int maxn=1000000;\n\tstatic long inf=(long)1e16;\n\tstatic long fill=(long)-1e18;\n\tstatic ArrayListweights;\n\tstatic ArrayListvals;\n\tstatic long[]memo;\n\t\n\tstatic int[]F;\n\tstatic long cost(int num) {\n\t\tint d=0;\n\t\tlong ans=0;\n\t\twhile(num>0) {\n\t\t\tint digit=num%10;\n\t\t\tnum/=10;\n\t\t\tif(digit==3 || digit==6 || digit==9) {\n\t\t\t\tans+=F[d]*1l*(digit/3);\n\t\t\t}\n\t\t\td++;\n\t\t}\n\t\treturn ans;\n\t}\n\tstatic void main() throws Exception{\n\t\tint n=(sc.nextInt()-1)*3;\n\t\tF=sc.intArr(6);\n\t\tvals=new ArrayList();\n\t\tweights=new ArrayList();\n\t\tint ten=1;\n\t\tfor(int i=0;i<6;i++) {\n\t\t\tint curW=3*ten;long curV=F[i];\n\t\t\tint cur=1;\n\t\t\tint tmpn=n;\n\t\t\twhile(cur<=tmpn) {\n\t\t\t\tif(curW*1l*cur>maxn)break;\n\t\t\t\tweights.add(curW*cur);\n\t\t\t\tvals.add(curV*cur);\n\t\t\t\ttmpn-=cur;\n\t\t\t\tcur<<=1;\n\t\t\t}\n\t\t\tif(tmpn>0 && curW*1l*tmpn<=maxn) {\n\t\t\t\tweights.add(curW*tmpn);\n\t\t\t\tvals.add(curV*tmpn);\n\t\t\t}\n\t\t\tten*=10;\n\t\t}\n\t\tmemo=new long[maxn];\n\t\tfor(int i=1;i0)\n\t\t\tmain();\n\t\tpw.flush();\n\t}\n\tstatic PrintWriter pw;\n\tstatic MScanner sc;\n\tstatic class MScanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\t\tpublic MScanner(InputStream system) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(system));\n\t\t}\n\t \n\t\tpublic MScanner(String file) throws Exception {\n\t\t\tbr = new BufferedReader(new FileReader(file));\n\t\t}\n\t \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\t\tpublic int[] intArr(int n) throws IOException {\n\t int[]in=new int[n];for(int i=0;i factors = new HashMap<>();\n\t\t\tfor(long i = 2; i * i <= a; i++) {\n\t\t\t\tif(a%i == 0) {\n\t\t\t\t\tfactors.put(i, 0);\n\t\t\t\t\twhile(a % i == 0) {\n\t\t\t\t\t\ta /= i;\n\t\t\t\t\t\tfactors.put(i, factors.get(i) + 1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(a > 1) {\n\t\t\t\tfactors.put(a, factors.getOrDefault(a, 0) + 1);\n\t\t\t}\n\t\t\t//pw.println(factors);\n\t\t\tlong sum = 0;\n\t\t\tlong c = 1;\n\t\t\twhile(b > 0) {\n\t\t\t\tlong min = Math.max(1, b);\n\t\t\t\tlong d = 1;\n\t\t\t\tfor(long x : factors.keySet()) {\n\t\t\t\t\tlong rem = b - (b/(c*x)) * c*x;\n\t\t\t\t\tif(min > rem) {\n\t\t\t\t\t\td = x;\n\t\t\t\t\t\tmin = rem;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(d > 1) {\n\t\t\t\t\tfactors.put(d, factors.get(d) - 1);\n\t\t\t\t\tif(factors.get(d) == 0) {\n\t\t\t\t\t\tfactors.remove(d);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tb -= min;\n\t\t\t\tsum += min / c;\n\t\t\t\tc *= d;\n\t\t\t\t//pw.println(b + \" \" + c);\n\t\t\t}\n\t\t\tpw.println(sum);\n\t\t\t\n\t\t}\n\t}\n\tstatic long binpow(long a, long b, long m) {\n\t\ta %= m;\n\t\tlong res = 1;\n\t\twhile (b > 0) {\n\t\t\tif ((b & 1) == 1)\n\t\t\t\tres = res * a % m;\n\t\t\ta = a * a % m;\n\t\t\tb >>= 1;\n\t\t}\n\t\treturn res;\n\t}\n\tstatic void sort(int[] x){\n\t\tshuffle(x);\n\t\tArrays.sort(x);\n\t}\n\tstatic void sort(long[] x){\n\t\tshuffle(x);\n\t\tArrays.sort(x);\n\t}\n\tstatic class tup implements Comparable{\n\t\tint a, b;\n\t\ttup(int a,int b){\n\t\t\tthis.a=a;\n\t\t\tthis.b=b;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(tup o){\n\t\t\treturn Integer.compare(o.b,b);\n\t\t}\n\t}\n\tstatic void shuffle(int[] a) {\n\t\tRandom get = new Random();\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tint r = get.nextInt(i + 1);\n\t\t\tint temp = a[i];\n\t\t\ta[i] = a[r];\n\t\t\ta[r] = temp;\n\t\t}\n\t}\n\n\tstatic void shuffle(long[] a) {\n\t\tRandom get = new Random();\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tint r = get.nextInt(i + 1);\n\t\t\tlong temp = a[i];\n\t\t\ta[i] = a[r];\n\t\t\ta[r] = temp;\n\t\t}\n\t}\n\n\tstatic class FastReader {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastReader() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tpublic FastReader(String s) throws FileNotFoundException {\n\t\t\tbr = new BufferedReader(new FileReader(new File(s)));\n\t\t}\n\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreElements()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tString nextLine() {\n\t\t\tString str = \"\";\n\t\t\ttry {\n\t\t\t\tstr = br.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "912588138467dff14807ea50b225f930", "src_uid": "ea92cd905e9725e7fcb87b9ed4f64c2e", "difficulty": 2100.0} {"lang": "Java 11", "source_code": "import java.io.*;\r\nimport java.util.*;\r\n \r\npublic class Main { \r\n static Random random;\r\n \r\n /* public static void main(String[] args){\r\n new Thread(null, new Template (), \"Main\", 1<<26).start();\r\n } */\r\n \r\n public static void main(String[] args) {\r\n FastScanner in = new FastScanner();\r\n PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\r\n random = new Random();\r\n \r\n // long timeStamp = System.currentTimeMillis();\r\n Solver solver = new Solver();\r\n solver.solve(in, out);\r\n out.close();\r\n // System.err.println(\"TIME: \"+(System.currentTimeMillis()-timeStamp)+\" ms\");\r\n }\r\n \r\n /* ------------------------------------- START -------------------------------------------- */\r\n static class Solver {\r\n private static int mod;\r\n public void solve(FastScanner in, PrintWriter out) {\r\n int n = in.nextInt();\r\n mod = in.nextInt();\r\n\r\n int dp[] = new int[n+1];\r\n int pref[] = new int[n+1];\r\n\r\n dp[1] = 1;\r\n pref[1] = 1;\r\n\r\n for(int i = 2; i<=n; i++){\r\n dp[i] = pref[i-1];\r\n\r\n for(int j = 1; j*j<=i; j++){\r\n int l = i/(j+1) + 1;\r\n int r = i/j;\r\n dp[i] = add(dp[i], mult(r-l+1, dp[j]));\r\n\r\n if(r != j && r != i){\r\n dp[i] = add(dp[i], dp[r]);\r\n }\r\n }\r\n\r\n // int q = 1;\r\n // while(q < i){\r\n // int l = i/(q+1) + 1;\r\n // int r = i/q;\r\n // // new Debug().d(\"q\", q).d(\"l\", l).d(\"r\", r).d();\r\n // dp[i] = add(dp[i], mult(r-l+1, dp[q]));\r\n // //if(l == 1) break;\r\n // q = i/(l-1);\r\n // }\r\n\r\n // new Debug().d(i, dp[i]).d();\r\n\r\n pref[i] = add(pref[i-1], dp[i]);\r\n }\r\n\r\n out.println(dp[n]);\r\n }\r\n\r\n private int add(int x, int y){\r\n x += y;\r\n if(x >= mod) x -= mod;\r\n return x;\r\n }\r\n\r\n private int mult(int x, int y){\r\n long r = (x * (long) y);\r\n if(r >= mod)\r\n r %= mod;\r\n return (int) r;\r\n }\r\n }\r\n /* -------------------------------------- END --------------------------------------------- */\r\n \r\n /* Shuffle function to shuffle before Arrays.sort */\r\n static void shuffle(int[] arr){\r\n int swapTemp;\r\n for(int i = arr.length-1; i>= 1; i--){\r\n int pos = random.nextInt(i+1);\r\n if(pos == i) continue;\r\n {swapTemp = arr[i]; arr[i] = arr[pos]; arr[pos] = swapTemp;}\r\n }\r\n }\r\n \r\n /* Fast Input reader */\r\n static class FastScanner {\r\n BufferedReader reader;\r\n StreamTokenizer tokenizer;\r\n public FastScanner() {\r\n reader = new BufferedReader(new InputStreamReader(System.in));\r\n tokenizer = new StreamTokenizer(reader);\r\n tokenizer.resetSyntax();\r\n tokenizer.whitespaceChars(0, 32);\r\n tokenizer.wordChars(33, 126);\r\n }\r\n private void nextToken(){\r\n try{ tokenizer.nextToken(); }\r\n catch (Exception e) { e.printStackTrace(); }\r\n }\r\n String next() {\r\n nextToken();\r\n return tokenizer.sval;\r\n }\r\n int nextInt() {\r\n nextToken();\r\n return Integer.parseInt(tokenizer.sval);\r\n }\r\n long nextLong() {\r\n nextToken();\r\n return Long.parseLong(tokenizer.sval);\r\n }\r\n double nextDouble() {\r\n nextToken();\r\n return Double.parseDouble(tokenizer.sval);\r\n }\r\n String nextLine() {\r\n try{\r\n String string = reader.readLine();\r\n return string;\r\n } catch (Exception e) {\r\n e.printStackTrace();\r\n return \"\";\r\n }\r\n }\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8a6b5a2999bcf0764c1312b94e93545e", "src_uid": "77443424be253352aaf2b6c89bdd4671", "difficulty": 1900.0} {"lang": "Java 6", "source_code": "import java.io.IOException;\nimport java.util.InputMismatchException;\nimport java.io.PrintStream;\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\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tStreamInputReader in = new StreamInputReader(inputStream);\n\t\tOutputWriter out = new OutputWriter(outputStream);\n\t\tTaskD solver = new TaskD();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskD {\n public void solve(int testNumber, StreamInputReader in, OutputWriter out) {\n int n = in.readInt(), m = in.readInt();\n int res = 0;\n for(int i = 0; i < n; ++i) {\n for(int j = 0; j < m; ++j) {\n if (((i+j)&1) == 1) {\n ++res;\n }\n }\n }\n System.out.println(Math.max(res, n*m -res));\n }\n}\n\nclass StreamInputReader extends InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n\n public StreamInputReader(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 }\n\nclass OutputWriter {\n\tprivate final PrintWriter writer;\n\n\tpublic OutputWriter(OutputStream outputStream) {\n\t\twriter = new PrintWriter(outputStream);\n\t}\n\n\tpublic OutputWriter(Writer writer) {\n\t\tthis.writer = new PrintWriter(writer);\n\t}\n\n\tpublic void close() {\n\t\twriter.close();\n\t}\n}\n\nabstract class InputReader {\n\n\tpublic abstract int read();\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 protected boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n }\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9a3660fb0d7f4b5e3cdfd7a796aeb1a5", "src_uid": "2468eead8acc5b8f5ddc51bfa2bd4fb7", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Random;\nimport java.util.StringTokenizer;\n\n\npublic class Main {\n\n\tpublic static void main(String[] args) throws IOException, InterruptedException {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskC solver = new TaskC();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n\n\tstatic class TaskC {\n\t\tstatic boolean visited[] ;\n\t\tstatic boolean found = false; \n\n\t\tstatic int steps = 0 ;\n\t\tstatic int n ; \n\t\tstatic boolean memo [][] ; \n\t\tstatic int dp[][] ; \n\t\tstatic char matrix[][] ;\n\t\tstatic ArrayList p ;\n\t\tpublic void solve(int testNumber, InputReader in, PrintWriter out) throws IOException, InterruptedException {\n\t\t\tlong n = Long.valueOf(in.next());\n\t\t\tn--; \n\n\t\t\tlong total =0 ;\n\n\t\t\tfor (int i = 1; i <= n; i*=2)\n\t\t\t{\n\t\t\t\tdouble current = 1.0 * (n-i) ;\n\t\t\t\tcurrent = Math.floor(current/(2.0*i)) ;\n\t\t\t\tcurrent++ ; \n\t\t\t\tSystem.err.println(i+\" \"+current);\n\t\t\t\tcurrent*=i ;\n\t\t\t\ttotal+=current ;\n\n\t\t\t}\n\n\t\t\tSystem.out.println(total);\n\n\n\t\t}\n\n\t\tpublic static int cnt1(int mat[][]) //how many swaps to be a 1 matrix\n\t\t{\n\t\t\tint m = mat.length ; \n\t\t\tint c=0 ; \n\t\t\tfor (int i = 0; i < mat.length; i++)\n\t\t\t{\n\t\t\t\tfor (int j = 0; j < mat.length; j++)\n\t\t\t\t{\n\t\t\t\t\tint x = (i*m) +j ;\n\t\t\t\t\tif(x%2==0 && mat[i][j]==0)\n\t\t\t\t\t\tc++; \n\t\t\t\t\tif(x%2!=0 && mat[i][j]==1)\n\t\t\t\t\t\tc++; \n\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn c;\n\t\t}\n\t\tpublic static int cnt0(int mat[][])\n\t\t{\n\t\t\tint m = mat.length ; \n\t\t\tint c=0 ; \n\t\t\tfor (int i = 0; i < mat.length; i++)\n\t\t\t{\n\t\t\t\tfor (int j = 0; j < mat.length; j++)\n\t\t\t\t{\n\t\t\t\t\tint x = (i*m) +j ; \n\t\t\t\t\tif(x%2!=0 && mat[i][j]==0)\n\t\t\t\t\t\tc++; \n\t\t\t\t\tif(x%2==0 && mat[i][j]==1)\n\t\t\t\t\t\tc++; \n\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn c;\n\t\t}\n\n\t\tpublic static boolean canFit2(int x1, int y1 , int x2 , int y2 , int x3 , int y3){\n\t\t\tif(x1==x2)\n\t\t\t\tif(x1==x3)\n\t\t\t\t\treturn true ; \n\t\t\t\telse\n\t\t\t\t\treturn false ;\n\t\t\telse\n\t\t\t\tif(x1==x3)\n\t\t\t\t\treturn false ; \n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tlong a = 1l*(y2-y1)*(x3-x2) ; \n\t\t\t\t\tlong b = 1l*(y3-y2)*(x2-x1) ; \n\n\t\t\t\t\tif(a==b)\n\t\t\t\t\t\treturn true;\n\t\t\t\t\telse \n\t\t\t\t\t\treturn false ;\n\n\t\t\t\t}\n\n\t\t}\n\t\tpublic static void shuffle(int c[]){\n\t\t\tif(c.length==1)\n\t\t\t\treturn ; \n\t\t\tfor (int i = 0; i < c.length; i++)\n\t\t\t{\n\t\t\t\tRandom rand = new Random();\n\n\t\t\t\tint n = rand.nextInt(c.length-1) + 0;\n\n\t\t\t\tint temp = c[i] ; \n\t\t\t\tc[i] = c[n] ; \n\t\t\t\tc[n] = temp ;\n\t\t\t}\n\t\t}\n\t\tpublic static int binary(ArrayList arr, int l, int r, long x) /// begin by 0 and n-1\n\t\t{\n\t\t\tif (r>=l)\n\t\t\t{\n\t\t\t\tint mid = l + (r - l)/2;\n\t\t\t\tif (arr.get(mid) == x)\n\t\t\t\t\treturn mid;\n\t\t\t\tif (arr.get(mid)> x)\n\t\t\t\t\treturn binary(arr, l, mid-1, x);\n\t\t\t\treturn binary(arr, mid+1, r, x);\n\t\t\t}\n\t\t\treturn -1;\n\t\t}\n\n\t\t/// searching for the index of first elment greater than x\n\t\tpublic static int binary1(ArrayList arr , long left) {\n\t\t\tint low = 0, high = arr.size(); // numElems is the size of the array i.e arr.size() \n\t\t\twhile (low != high) {\n\t\t\t\tint mid = (low + high) / 2; // Or a fancy way to avoid int overflow\n\t\t\t\tif (arr.get(mid) <= left) {\n\t\t\t\t\t/* This index, and everything below it, must not be the first element\n\t\t\t\t\t * greater than what we're looking for because this element is no greater\n\t\t\t\t\t * than the element.\n\t\t\t\t\t */\n\t\t\t\t\tlow = mid + 1;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\t/* This element is at least as large as the element, so anything after it can't\n\t\t\t\t\t * be the first element that's at least as large.\n\t\t\t\t\t */\n\t\t\t\t\thigh = mid;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn low ; // return high ; \n\t\t}\n\n\n\t\tprivate static boolean triangle(int a, int b , int c){\n\t\t\tif(a+b>c && a+c>b && b+c>a)\n\t\t\t\treturn true ; \n\t\t\telse \n\t\t\t\treturn false ;\n\t\t}\n\t\tprivate static boolean segment(int a, int b , int c){\n\t\t\tif(a+b==c || a+c==b && b+c==a)\n\t\t\t\treturn true ; \n\t\t\telse \n\t\t\t\treturn false ;\n\t\t}\n\t\tprivate static int gcdThing(long a, long b) {\n\t\t\tBigInteger b1 = BigInteger.valueOf(a);\n\t\t\tBigInteger b2 = BigInteger.valueOf(b);\n\t\t\tBigInteger gcd = b1.gcd(b2);\n\t\t\treturn gcd.intValue();\n\t\t}\n\n\t\tpublic static boolean is(int i){\n\t\t\tif(Math.log(i)/ Math.log(2) ==(int) (Math.log(i)/ Math.log(2)))\n\t\t\t\treturn true ; \n\t\t\tif(Math.log(i)/ Math.log(3) ==(int) (Math.log(i)/ Math.log(3)) )\n\t\t\t\treturn true ; \n\t\t\tif(Math.log(i)/ Math.log(6) ==(int) (Math.log(i)/ Math.log(6)) )\n\t\t\t\treturn true ; \n\n\t\t\treturn false;\n\n\t\t}\n\t\tpublic static boolean contains(int b[] , int x)\n\t\t{\n\t\t\tfor (int i = 0; i < b.length; i++)\n\t\t\t{\n\t\t\t\tif(b[i]==x)\n\t\t\t\t\treturn true ;\n\t\t\t}\n\t\t\treturn false ;\n\t\t}\n\t\tpublic static int binary(long []arr , long target , int low , long shift) {\n\t\t\tint high = arr.length; \n\t\t\twhile (low != high) {\n\t\t\t\tint mid = (low + high) / 2; \n\t\t\t\tif (arr[mid]-shift <= target) {\n\t\t\t\t\tlow = mid + 1;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\thigh = mid;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn low ; // return high ; \n\t\t}\n\t\tpublic static boolean isLetter(char x){\n\t\t\tif(x+0 <=122 && x+0 >=97 )\n\t\t\t\treturn true ;\n\t\t\telse if (x+0 <=90 && x+0 >=65 )\n\t\t\t\treturn true ; \n\t\t\telse return false; \n\t\t}\n\t\tpublic static long getPrimes(long x ){\n\t\t\tif(x==2 || x==3 || x==1)\n\t\t\t\treturn 2 ;\n\t\t\tif(isPrime(x))\n\t\t\t\treturn 5 ;\n\t\t\tfor (int i = 2; i*i<=x; i++)\n\t\t\t{\n\t\t\t\tif(x%i==0 && isPrime(i))\n\t\t\t\t\treturn getPrimes(x/i) ;\n\t\t\t}\n\t\t\treturn -1;\n\t\t}\n\t\tpublic static String solve(String x){\n\n\t\t\tint n = x.length() ; \n\t\t\tString y = \"\" ;\n\t\t\tfor (int i = 0; i < n-2; i+=2)\n\t\t\t{\n\t\t\t\tif(ifPalindrome(x.substring(i, i+2)))\n\t\t\t\t\ty+= x.substring(i, i+2) ;\n\t\t\t\telse \n\t\t\t\t\tbreak ;\n\t\t\t}\n\t\t\treturn y+ solve1(x.substring(y.length(),x.length())) ;\n\n\t\t}\n\t\tpublic static String solve1(String x){\n\t\t\tString y = x.substring(0 , x.length()/2) ; \n\t\t\treturn \"\" ;\n\n\t\t}\n\t\tpublic static String reverse(String x){\n\t\t\tString y =\"\" ;\n\t\t\tfor (int i = 0; i < x.length(); i++)\n\t\t\t{\n\t\t\t\ty = x.charAt(i) + y ;\n\t\t\t}\n\t\t\treturn y ;\n\t\t}\n\n\t\tpublic static boolean ifPalindrome(String x){\n\t\t\tint numbers[] = new int[10] ; \n\t\t\tfor (int i = 0; i < x.length(); i++)\n\t\t\t{\n\t\t\t\tint z = Integer.parseInt(x.charAt(i)+\"\") ; \n\t\t\t\tnumbers[z] ++ ;\n\t\t\t}\n\t\t\tfor (int i = 0; i < numbers.length; i++)\n\t\t\t{\n\t\t\t\tif(numbers[i]%2!=0)\n\t\t\t\t\treturn false; \n\t\t\t}\n\t\t\treturn true ;\t\n\t\t}\n\n\t\tpublic static int get(int n){\n\t\t\treturn n*(n+1)/2 ; \n\t\t}\n\t\t//\t\tpublic static long getSmallestDivisor( long y){\n\t\t//\t\t\tif(isPrime(y))\n\t\t//\t\t\t\treturn -1;\n\t\t//\n\t\t//\t\t\tfor (long i = 2; i*i <= y; i++)\n\t\t//\t\t\t{\n\t\t//\t\t\t\tif(y%i ==0)\n\t\t//\t\t\t\t{\n\t\t//\t\t\t\t\treturn i;\n\t\t//\t\t\t\t}\n\t\t//\t\t\t}\n\t\t//\t\t\treturn -1;\n\t\t//\t\t}\n\t\t//\t\tpublic static void lis(pair []a , int n){\n\t\t//\t\t\tint lis[] = new int[n] ; \n\t\t//\t\t\tArrays.fill(lis,1) ; \n\t\t//\n\t\t//\t\t\tfor(int i=1;ia[j].y && lis[i] < lis[j]+1) \n\t\t//\t\t\t\t\t\tlis[i] = lis[j] + 1; \n\t\t//\n\t\t//\t\t\tint max = lis[0];\n\t\t//\n\t\t//\t\t\tfor(int i=1; i s = new ArrayList() ;\n\t\t//\t\t\tfor (int i = n-1; i >=0; i--)\n\t\t//\t\t\t{\n\t\t//\t\t\t\tif(lis[i]==max)\n\t\t//\t\t\t\t{\n\t\t//\t\t\t\t\ts.add(a[i].z);\n\t\t//\t\t\t\t\tmax --; \n\t\t//\t\t\t\t}\n\t\t//\t\t\t}\n\t\t//\n\t\t//\t\t\tfor (int i = s.size()-1 ; i>=0 ; i--)\n\t\t//\t\t\t{\n\t\t//\t\t\t\tSystem.out.print(s.get(i)+\" \");\n\t\t//\t\t\t}\n\t\t//\n\t\t//\t\t\treturn ; \n\t\t//\t\t}\n\t\tpublic static int calcDepth(Vertix node){\n\t\t\tif(node.depth>0) return node.depth; \n\t\t\t// meaning it has been updated before;\n\t\t\tif(node.parent != null)\n\t\t\t\treturn 1+ calcDepth(node.parent);\n\t\t\telse\n\t\t\t\treturn -1;\n\t\t}\n\n\t\tpublic static boolean isPrime (long num){\n\t\t\tif (num < 2) return false;\n\t\t\tif (num == 2) return true;\n\t\t\tif (num % 2 == 0) return false;\n\t\t\tfor (int i = 3; i * i <= num; i += 2)\n\t\t\t\tif (num % i == 0) return false;\n\t\t\treturn true;\n\t\t}\n\n\n\t\tpublic static int[] getDiv(int n)\n\t\t{\n\t\t\tint result[] = new int[7] ; \n\t\t\tArrayList f = new ArrayList() ; \n\n\t\t\twhile (n%2==0)\n\t\t\t{\n\t\t\t\tif(!f.contains(2))f.add(2) ;\n\t\t\t\tn /= 2;\n\t\t\t}\n\n\t\t\t// n must be odd at this point. So we can\n\t\t\t// skip one element (Note i = i +2)\n\t\t\tfor (int i = 3; i <= Math.sqrt(n); i+= 2)\n\t\t\t{\n\t\t\t\t// While i divides n, print i and divide n\n\t\t\t\twhile (n%i == 0)\n\t\t\t\t{\n\t\t\t\t\tif(!f.contains(i))f.add(i);\n\t\t\t\t\tn /= i;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// This condition is to handle the case whien\n\t\t\t// n is a prime number greater than 2\n\t\t\tif (n > 2)\n\t\t\t\tif(!f.contains(n))f.add(n);\n\n\t\t\tfor (int i = 0, j=0; i < f.size(); i++)\n\t\t\t{\n\t\t\t\tresult[j++]=f.get(i);\n\t\t\t}\n\t\t\treturn result ;\n\n\n\n\t\t}\n\n\t\t//\t\tpublic static boolean dfs(Vertix v , int target){\n\t\t//\t\t\ttry{\n\t\t//\t\t\t\tvisited[v.i]= true ;\n\t\t//\t\t\t} catch (NullPointerException e)\n\t\t//\t\t\t{\n\t\t//\t\t\t\tSystem.out.println(v.i);\n\t\t//\t\t\t}\n\t\t//\t\t\tif(v.i == target)\n\t\t//\n\t\t//\t\t\t\treturn true ;\n\t\t//\t\t\tfor (int i =0 ; i< v.neighbours.size() ; i++)\n\t\t//\t\t\t{ \n\t\t//\n\t\t//\t\t\t\tVertix child = v.neighbours.get(i) ;\n\t\t//\t\t\t\tif(child.i == target){\n\t\t//\t\t\t\t\tfound = true ; \n\t\t//\t\t\t\t}\n\t\t//\t\t\t\tif(visited[child.i]==false){\n\t\t//\t\t\t\t\tfound |= dfs(child, target) ;\n\t\t//\t\t\t\t}\n\t\t//\t\t\t}\n\t\t//\t\t\treturn found; \n\t\t//\t\t}\n\n\n\n\n\n\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}\n\tpublic static class Vertix{\n\t\tlong i ; \n\t\tint depth ;\n\t\tArrayList neighbours ; \n\t\tVertix parent ; \n\t\tVertix child ; \n\n\n\t\tpublic Vertix(long i){\n\t\t\tthis.i = i ;\n\t\t\tthis.neighbours = new ArrayList () ;\n\t\t\tthis.parent = null ;\n\t\t\tdepth =-1;\n\t\t\tthis.child = null ;\n\t\t}\n\t}\n\n\tpublic static class pair implements Comparable{\n\t\tint x ; \n\t\tint y ; \n\n\n\n\n\t\tpublic pair(int x, int y , int z){\n\t\t\tthis.x=x ; \n\t\t\tthis.y=y ;\n\n\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(pair p) {\n\t\t\tif(this.x > p.x)\n\t\t\t\treturn 1 ; \n\t\t\telse return -1 ;\n\n\n\t\t}\n\n\n\t}\n\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a333a7621d611b8182e19a8a48d5183f", "src_uid": "a98f0d924ea52cafe0048f213f075891", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n DeterminedCleanup solver = new DeterminedCleanup();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class DeterminedCleanup {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n long p = in.nextLong();\n long k = in.nextInt();\n int mx = 62;\n long[] coe = new long[mx];\n int d = (int) MathUtils.log(p, k);\n coe[0] = p % k;\n long[] pref = new long[mx];\n pref[0] = coe[0];\n for (int i = 1; i <= d; i++) {\n coe[i] = (p % (MathUtils.binPow(k, i + 1, Long.MAX_VALUE)) - pref[i - 1]) / MathUtils.binPow(k, i, Long.MAX_VALUE);\n pref[i] = MathUtils.binPow(k, i, Long.MAX_VALUE) * coe[i] + pref[i - 1];\n }\n for (int i = 1; i <= d; i += 2) {\n if (coe[i] > 0) {\n coe[i] = -(k - coe[i]);\n coe[i + 1]++;\n }\n }\n for (int i = 0; i <= d + 1; i++) {\n if (coe[i] == k) {\n coe[i] = 0;\n coe[i + 1]++;\n }\n }\n for (int i = mx - 1; i >= 0; i--) {\n if (coe[i] != 0) {\n d = i;\n break;\n }\n }\n out.println(d + 1);\n for (int i = 0; i <= d; i++) {\n out.println(Math.abs(coe[i]));\n }\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n }\n\n static class MathUtils {\n public static long binPow(long b, long p, long mod) {\n long res = 1;\n while (p > 0) {\n if ((p & 1) == 1) {\n res *= b;\n res %= mod;\n }\n b = b * b;\n p >>= 1;\n b %= mod;\n }\n return res;\n }\n\n public static double log(double val, double base) {\n return Math.log(val) / Math.log(base);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8698bec57c0a4d9aa8027d4d117a2325", "src_uid": "f4dbaa8deb2bd5c054fe34bb83bc6cd5", "difficulty": 2000.0} {"lang": "Java 11", "source_code": "import java.util.Scanner;\npublic class harrypotter {\n public static void main(String args[]) {\n Scanner scan = new Scanner(System.in);\n int a = scan.nextInt();\n int b = scan.nextInt();\n int c = scan.nextInt();\n int d = scan.nextInt();\n int e = scan.nextInt();\n int f = scan.nextInt();\n if (a == 0 && b == 0 && c == 0 && d == 0 && e == 0 && f == 0)\n System.out.println(\"Hermione\");\n if (c == 0 && d > 0)\n System.out.println(\"Ron\");\n if(c==0&&d==0)\n System.out.println(\"Hermione\");\n if (a == 0 && b != 0 && c != 0 && d != 0)\n System.out.println(\"Ron\");\n if(e==0) {\n if (c == 0 && d > 0)\n System.out.println(\"Ron\");\n if (a == 0 && b != 0 && c != 0 && d != 0)\n System.out.println(\"Ron\");\n }\n if(a==0&&b==0){\n if (c == 0 && d > 0)\n System.out.println(\"Ron\");\n if(c==0&&d==0)\n System.out.println(\"Hermoine\");\n }\n \n if(e==0&&f==0)\n System.out.println(\"Hermione\");\n if(c!=0&&e!=0&&a!0) {\n double sand = (f * d * b) / (e * c*a);\n int value = (int) sand;\n if (value > a)\n System.out.println(\"Ron\");\n else\n System.out.println(\"Hermione\");\n\n }\n }\n }\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "969195c325ba6be6121316cb1f7639fc", "src_uid": "44d608de3e1447f89070e707ba550150", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Sol{\n public static void main(string[] args){\n Scanner s=new Scanner(system.in);\n int n=s.nextInt();\n int p=s.nextInt();\n int w=s.nextInt();\n int d=s.nextInt();\n boolean flag=true;\n int x=0;\n int y=0;\n int z=0;\n if(n*w>=p){\n x=p/w;\n p=p%w;\n if(p>=d){\n y=p/d;\n p=p%d;\n if(p>0){\n flag=false;\n }\n }\n z=n-x-y;\n }\n else{\n flag=false;\n }\n if(!flag){\n System.out.println(\"-1\");\n }\n else{\n System.out.print(x+\" \"+y+\" \"+z);\n }\n \n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f3d8a681553b3d541391591a5655b5c5", "src_uid": "503116e144d19eb953954d99c5526a7d", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\t\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n solve(in,out);\n out.close();\n }\n \n \n private static final int MOD = (int)1e9 + 7;\n \n private static long add(long a, long b) {\n\t a += b;\n\t if (a >= MOD) {\n\t\t a -= MOD;\n\t }\n\t return a;\n }\n \n private static long pow(long a, int b) {\n\t long ans = 1;\n\t while (b > 0) {\n\t\t if ((b % 2) > 0) {\n\t\t\t ans = ans * a %MOD;\n\t\t }\n\t\t a = a * a % MOD;\n\t\t b >>= 1;\n\t }\n\t return ans;\n }\n \n private static void solve(InputReader in, PrintWriter out) {\n\t int n = in.nextInt();\n\t long m = in.nextLong();\n\t long dp[] = new long[n + 1];\n\t dp[0] = 1;\n\t for (int i = 1; i <= n; i++) {\n\t\t dp[i] = 0;\n\t\t for (int j = 0; j < i; j++) {\n\t\t\t dp[i] = add(dp[i], dp[j] * m % MOD * pow(m - 1, i - j - 1) % MOD);\n\t\t }\n\t }\n\t long ans = 0;\n\t for (int i = 0; i <= n; i++) {\n\t\t ans = add(ans, dp[i] * pow(m, n - i) % MOD);\n\t }\n\t out.print(ans);\n }\n\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n \n public long nextLong() {\n \treturn Long.parseLong(next());\n }\n\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9e9582c5b770c4f624619ac38cc27287", "src_uid": "5b775f17b188c1d8a4da212ebb3a525c", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class EmailAddress\n{\n\tpublic static void main(String[] args) \n\t{\n\t\tScanner sc=new Scanner(System.in);\n\t\tString s=sc.next();\n\t\t\n\t\tif(s.charAt(0)=='a' && s.charAt(1)=='t')\n\t\t{\n\t\t\tint k=s.indexOf(\"at\",2);\n\t\t\tStringBuilder stb1=new StringBuilder(s);\n\t\t\tstb1=stb1.replace(k,k+2,\"@\");\n\t\t\ts=stb1.toString();\n\t\t}\n\t\telse\n\t\t{\n\t\t\tint k=s.indexOf(\"at\",2);\n\t\t\tStringBuilder stb1=new StringBuilder(s);\n\t\t\tstb1=stb1.replace(k,k+2,\"@\");\n\t\t\ts=stb1.toString();\n\t\t}\n\t\n\t\t\n\t//\tSystem.out.println(\"s:\" +s);\n\t\t\n\t\ts=s.replaceAll(\"dot\",\".\");\n\t//\tSystem.out.println(\"fs:\" +s);\n\t\t\n\t\tif(s.charAt(0)=='.')\n\t\t{\n\t\t\ts=s.replaceFirst(\".\",\"dot\");\n\t\t}\n\t\t\n//\t\tSystem.out.println(\"SS:\"+s);\n\t\t\n\t\t\n\t\tStringBuilder stb=new StringBuilder(s);\n\t\tif(stb.charAt(stb.length()-1)=='.')\n\t\t{\n\t\t\tstb.deleteCharAt(stb.length()-1);\n\t\t\tstb.append(\"dot\");\n\t\t}\n\t\tSystem.out.println(stb.toString());\n\t\t\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "138fe204dc9394689cd43f176216683e", "src_uid": "a11c9679d8e2dca51be17d466202df6e", "difficulty": 1300.0} {"lang": "Java 7", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Abacaba {\n public static void main(String[] args) throws IOException {\n BufferedReader leer= new BufferedReader(new InputStreamReader(System.in));\n String[] line=leer.readLine().split(\" \");\n long a=Long.parseLong(line[0])-1;\n long b=Long.parseLong(line[1])-1;\n long c=Long.parseLong(line[2])-1;\n long d=Long.parseLong(line[3])-1;\n long r=solve(a,b,c,d,(long)(Math.pow(2, 4)-1)/2);\n System.out.println(r);\n }\n private static long solve(long a, long b, long c, long d,long m) {\n if(b= d || a >= c && b <= d ) return l ;\n \n l= Math.max(l, solve(Math.min(a, m),Math.min(b, m-1),Math.min(c,m),Math.min(d, m-1),m/2));\n l= Math.max(l, solve(Math.min(a, m),Math.min(b, m-1),Math.max(c,m+1)-m-1,Math.max(d, m)-m-1,m/2));\n l= Math.max(l, solve(Math.max(a, m+1)-m-1,Math.max(b, m)-m-1,Math.min(c,m),Math.min(d, m-1),m/2));\n l= Math.max(l, solve(Math.max(a, m+1)-m-1,Math.max(b, m)-m-1,Math.max(c,m+1)-m-1,Math.max(d, m)-m-1,m/2));\n \n return l;\n }\n\n private static long longitud(long l1, long r1, long l2, long r2) {\n long ovl = Math.max(l1, l2); \n long ovr = Math.min(r1, r2); \n return ( (ovr >= ovl)? (ovr - ovl + 1) : 0 ); \n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "205d0374d9312478d0e0598be0a5e39c", "src_uid": "fe3c0c4c7e9b3afebf2c958251f10513", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.math.BigInteger;\nimport java.util.Scanner;\n\npublic class AprilFools {\n\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tint bi = scan.nextInt();\n\t\tSystem.out.println(1);\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "50a18d19bd76ece8c98020607ba30c7f", "src_uid": "ec539775f2b3358a92a99a644e2480ce", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\n\npublic class B {\n \n \n\n public static void main(String[] args) throws IOException {\n in = new StreamTokenizer( new InputStreamReader( System.in ) );\n out = new PrintWriter(System.out);\n int a = nextInt();\n int b= nextInt();\n long sum = culcV(a);\n if(a==b) {\n out.println(sum)\n out.close();\n return;\n }\n long prev = sum;\n int lastOst = ((int)a)%10;\n for(int i = a+1;i<=b;i++) {\n int ost = i%10;\n if(ost != 9) {\n prev = prev -valz[lastOst] + valz[ost]; \n sum += prev;\n \n\n } else {\n int tmp = i;\n while(tmp > 0) {\n if(tmp%10 == 9) {\n tmp=tmp/10;\n } else {\n break;\n }\n }\n if(tmp == 0) {\n prev+=2;\n sum+=prev;\n } else {\n int indx = tmp %10;\n prev = prev -valz[indx] + valz[indx +1];\n sum += prev;\n }\n }\n lastOst = ost;\n }\n out.println(sum);\n out.close();\n }\n\n static long[] valz = new long[] {6,2,5,5,4,5,6,3,7,6};\n\n static long culcV(int x) {\n long sum = 0;\n while(x>0) {\n int ost = x%10;\n sum += valz[ost];\n x = x/10;\n } \n return sum;\n }\n \n static StreamTokenizer in;\n static PrintWriter out;\n \n\n static int nextInt() throws IOException {\n in.nextToken();\n return ( int ) in.nval;\n }\n \n static long nextLong() throws IOException {\n in.nextToken();\n return ( long) in.nval;\n }\n \n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e2db26bcdd699f43755240b6b1fcdd6c", "src_uid": "1193de6f80a9feee8522a404d16425b9", "difficulty": 1000.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class D {\n\n public static void main(String[] args) throws IOException {\n InputReader in = new InputReader();\n int n = in.nextInt();\n for (int i = 0; i < 10; i++)\n a[i] = in.nextInt();\n for (int i = 0; i < dp.length; i++)\n for (int j = 0; j < dp[0].length; j++)\n dp[i][j] = -1;\n nCr(110, 110);\n long res = 0;\n for (int i = 1; i <= n; i++)\n res = (res + solve(0, i)) % mod;\n System.out.println(res % mod);\n }\n\n static int[] a = new int[10];\n static long[][] dp = new long[15][110];\n\n public static long solve(int at, int rem) {\n if (rem < 0)\n return 0;\n if (rem == 0) {\n for (int i = at; i < 10; i++)\n if (a[i] != 0)\n return 0;\n return 1;\n }\n if (at == 10)\n return rem == 0 ? 1 : 0;\n if (dp[at][rem] != -1)\n return dp[at][rem];\n long res = 0;\n int n = rem;\n if (at == 0)\n n = rem - 1;\n for (int i = a[at]; i <= n; i++)\n res = (res + (c[n][i] * solve(at + 1, rem - i)) % mod) % mod;\n return dp[at][rem] = res % mod;\n }\n\n static long[][] c;\n static long mod = 1000000007;\n\n public static void nCr(int n, int r) {\n c = new long[n + 1][r + 1];\n for (int i = 0; i < n + 1; i++)\n c[i][0] = 1;\n\n for (int j = 1; j <= r; j++)\n for (int i = j; i <= n; i++)\n c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;\n }\n\n static class InputReader {\n BufferedReader in;\n StringTokenizer st;\n\n public InputReader() throws IOException {\n in = new BufferedReader(new InputStreamReader(System.in));\n st = new StringTokenizer(in.readLine());\n }\n\n public String next() throws IOException {\n while (!st.hasMoreElements())\n st = new StringTokenizer(in.readLine());\n return st.nextToken();\n }\n\n public int nextInt() throws NumberFormatException, IOException {\n return Integer.parseInt(next());\n }\n\n public long nextLong() throws NumberFormatException, IOException {\n return Long.parseLong(next());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ad319b712f1747664c4f5befd7509012", "src_uid": "c1b5169a5c3b1bd4a2f1df1069ee7755", "difficulty": 1900.0} {"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.Arrays;\nimport java.util.Comparator;\nimport java.util.Locale;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\n\npublic class E {\n\t\n\tprivate void solve() throws IOException {\n\t\tint nf = nextInt();\n\t\tint ne = nextInt();\n\t\tint ns = nextInt();\n\t\tint rf = nextInt();\n\t\tint re = nextInt();\n\t\tint rs = nextInt();\n\t\tint df = nextInt();\n\t\tint de = nextInt();\n\t\t\n\t\t\n\t\tint n = nf + ne + ns;\n\t\tbyte[] a = new byte[n];\n\t\tfor (int i = 0; i < ns; i++) {\n\t\t\ta[i] = 1;\n\t\t}\n\n\t\tint sqrs = rs * rs;\n\t\t\n\t\tComparator cmp = new Comparator() {\n\t\t\t@Override\n\t\t\tpublic int compare(Double o1, Double o2) {\n\t\t\t\tdouble d = Math.signum(Math.abs(o1) - Math.abs(o2));\n\t\t\t\tif (d < 0) {\n\t\t\t\t\treturn -1;\n\t\t\t\t} else if (d > 0) {\n\t\t\t\t\treturn 1;\n\t\t\t\t} else {\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\t\n\t\tint t = 2 * ns + 2;\n\t\tDouble[] p = new Double[t];\n\t\tint[] b = new int[n];\n\t\tdouble[] f = new double[n];\n\t\tdouble[] e = new double[n];\n\t\tdouble[][] dp = new double[nf + 1][ne + 1];\n\t\t\n\t\t\n\t\tdouble res = 0;\n\t\t\n\t\twhile (true) {\n\t\t\tint k = 0;\n\t\t\tint q = 0;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tint x = 1000000 + i / 2;\n\t\t\t\tif (a[i] == 1) {\n\t\t\t\t\tdouble d = Math.sqrt(sqrs - 1);\n\t\t\t\t\tp[k++] = x - d;\n\t\t\t\t\tp[k++] = -(x + d);\n\t\t\t\t} else {\n\t\t\t\t\tb[q++] = x;\n\t\t\t\t}\n\t\t\t}\n\t\t\tp[k++] = 0.0;\n\t\t\tp[k++] = -2000000.0;\n\t\t\tArrays.sort(p, cmp);\n\t\t\t\n\t\t\tfor (int i = 0; i < q; i++) {\n\t\t\t\tf[i] = f(p, b[i], df, rf);\n\t\t\t\te[i] = f(p, b[i], de, re);\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 1; i <= nf; i++) {\n\t\t\t\tdp[i][0] = dp[i - 1][0] + f[i - 1];\n\t\t\t}\n\t\t\tfor (int i = 1; i <= ne; i++) {\n\t\t\t\tdp[0][i] = dp[0][i - 1] + e[i - 1];\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 1; i <= nf; i++) {\n\t\t\t\tfor (int j = 1; j <= ne; j++) {\n\t\t\t\t\tdp[i][j] = Math.max(dp[i - 1][j] + f[i + j - 1], dp[i][j - 1] + e[i + j - 1]);\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tres = Math.max(res, dp[nf][ne]);\n\t\t\t\n\t\t\tboolean next = false;\n\t\t\tint ones = 0;\n\t\t\tfor (int i = 0; i < a.length - 1; i++) {\n\t\t\t\tif (a[i] == 0) {\n\t\t\t\t\tif (ones != 0) {\n\t\t\t\t\t\ta[i] = 1;\n\t\t\t\t\t\tfor (int j = 0; j < ones - 1; j++) {\n\t\t\t\t\t\t\ta[j] = 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfor (int j = ones - 1; j < i; j++) {\n\t\t\t\t\t\t\ta[j] = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tnext = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tones++;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif (!next) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tprintln(res);\n\t}\n\t\n\tprivate double f(Double[] p, int x, double damage, double R) {\n\t\tdouble dx = Math.sqrt(R * R - 1);\n\t\tdouble l = x - dx;\n\t\tdouble r = x + dx;\n\t\t\n\t\tdouble k = 1;\n\t\tdouble res = 0;\n\t\tfor (int i = 1; i < p.length; i++) {\n\t\t\tdouble inter = inter(p[i - 1], p[i], l, r);\n\t\t\tres += damage * inter / (1 / k);\n\t\t\tif (p[i] > 0) {\n\t\t\t\tk++;\n\t\t\t} else {\n\t\t\t\tk--;\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn res;\n\t}\n\t\n\tprivate double inter(double l1, double r1, double l2, double r2) {\n\t\tl1 = Math.abs(l1);\n\t\tr1 = Math.abs(r1);\n\t\tl2 = Math.abs(l2);\n\t\tr2 = Math.abs(r2);\n\t\tdouble r = Math.min(r1, r2) - Math.max(l1, l2);\n\t\tif (r < 0) {\n\t\t\treturn 0;\n\t\t} else {\n\t\t\treturn r;\n\t\t}\n\t}\n\t\n\t\n\tprivate String nextToken() throws IOException {\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t}\n\t\treturn tokenizer.nextToken();\n\t}\n\n\tprivate int nextInt() throws NumberFormatException, IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tprivate double nextDouble() throws NumberFormatException, IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tprivate long nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tprivate void print(Object o) {\n\t\twriter.print(o);\n\t}\n\n\tprivate void println(Object o) {\n\t\twriter.println(o);\n\t}\n\n\tprivate void printf(String format, Object... o) {\n\t\twriter.printf(format, o);\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tlong time = System.currentTimeMillis();\n\t\tLocale.setDefault(Locale.US);\n\t\tnew E().run();\n\t\tSystem.err.printf(\"%.3f\\n\", 1e-3 * (System.currentTimeMillis() - time));\n\t}\n\n\tBufferedReader reader;\n\tStringTokenizer tokenizer;\n\tPrintWriter writer;\n\n\tprivate void run() {\n\t\ttry {\n\t\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\t\twriter = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t\treader.close();\n\t\t\twriter.close();\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(13);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "435e9d0489e0ccd7a062a27d92fe658b", "src_uid": "de5a42225714552cc5422d8a45734d58", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class B{\n\n\tstatic TreeMap getDivisors(long x){\n\t\tTreeMapans= new TreeMap();\n\t\t\n\t\tfor(long l=1;l*l<=x;l++)\n\t\t\tif(x%l==0)\n\t\t\t\tans.put(l, x/l);\n\t\t\n\t\treturn ans;\n\t}\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\t\tlong a=sc.nextLong(),b=sc.nextLong();\n\t\tlong area=a+b;\n\t\tlong ans=Long.MAX_VALUE;\n\t\tTreeMap map=getDivisors(a);\n\t\tfor(long l=1;l*l<=area;l++)\n\t\t{\n\t\t\tif(area%l==0)\n\t\t\t{\n\t\t\t\t\n\t\t\t\tlong x=area/l;\n\t\t\t\tLong y =map.floorKey(x);\n\t\t\t\tif(y!=null && map.get(y)<=x) {\n\t\t\t\t\tans=Math.min(ans, x+l);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t map=getDivisors(b);\n\t\tfor(long l=1;l*l<=area;l++)\n\t\t{\n\t\t\tif(area%l==0)\n\t\t\t{\n\t\t\t\t\n\t\t\t\tlong x=area/l;\n\t\t\t\tLong y =map.floorKey(x);\n\t\t\t\tif(y!=null && map.get(y)<=x) {\n\t\t\t\t\tans=Math.min(ans, x+l);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(ans*2);\n\t\tout.close();\n\t}\n\t\n\t\n\t\n\tstatic class Scanner {\n StringTokenizer st;\n BufferedReader br;\n \n public Scanner(InputStream s) {\n br = new BufferedReader(new InputStreamReader(s));\n }\n \n public Scanner(FileReader s) {\n br = new BufferedReader(s);\n }\n \n public String next() throws IOException {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n \n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n \n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n \n public String nextLine() throws IOException {\n return br.readLine();\n }\n public boolean ready() throws IOException {return br.ready();}\n public double nextDouble() throws IOException {return Double.parseDouble(next());}\n \n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e98b6e264fdc01f31c9bb2a76544efc2", "src_uid": "7d0c5f77bca792b6ab4fd4088fe18ff1", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.BufferedOutputStream;\nimport java.io.InputStream;\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\n\npublic class Task {\n\n public static void solve() throws Exception {\n\tlong maxSum = nextLong();\n\tlong[] arr = new long[9];\n\tfor (int i = 1; i <= 8; i++) {\n\t arr[i] = nextLong();\n\t}\n\tleaveMax4(arr);\n\n\tlong sum = 0;\n\tlong safeSum = maxSum - 100;\n\tif (safeSum > 0) {\n\t for (int i = arr.length - 1; i >= 1; i--) {\n\t\tlong cnt = (safeSum - sum) / i;\n\t\tboolean done = false;\n\t\tif (cnt <= arr[i]) {\n\t\t done = true;\n\t\t}\n\t\tcnt = Math.min(cnt, arr[i]-60);\n\t\tsum += cnt * i;\n\t\tarr[i] -= cnt;\n\t\tif (done) {\n\t\t break;\n\t\t}\n\t }\n\t}\n\tSystem.out.println(go(arr, sum, maxSum, 8));\n }\n\n private static long go(long[] arr, long sum, long maxSum, int ind) {\n\tlong max = sum;\n\tfor (long i = 0; i <= arr[ind]; i++) {\n\t long v = sum + i * ind;\n\t if (v == maxSum) {\n\t\treturn maxSum;\n\t } else if (v > maxSum) {\n\t\tbreak;\n\t } else {\n\t\tif (ind > 1) {\n\t\t v = go(arr, v, maxSum, ind - 1);\n\t\t}\n\t\tif (v == maxSum) {\n\t\t return maxSum;\n\t\t}\n\t\tif (v > max) {\n\t\t max = v;\n\t\t}\n\t }\n\t}\n\treturn max;\n }\n\n private static void leaveMax4(long[] arr) {\n\tfor (int i = 1; i < arr.length; i++) {\n\t if (arr[i] > 0) {\n\t\tfor (int j = i + 1; j < arr.length; j++) {\n\t\t if (arr[j] > 0) {\n\t\t\tint mod = j % i;\n\t\t\tif (mod == 0) {\n\t\t\t int x = j / i;\n\t\t\t if (arr[i] >= x - 1) {\n\t\t\t\tarr[i] += x * arr[j];\n\t\t\t\tarr[j] = 0;\n\t\t\t }\n\t\t\t}\n\t\t }\n\t\t}\n\t }\n\t}\n\tint count = 0;\n\tfor (int i = 1; i < arr.length; i++) {\n\t if (arr[i] > 0) {\n\t\tcount++;\n\t }\n\t}\n\tif (count > 4) {\n\t throw new RuntimeException();\n\t}\n }\n\n public static void main(String[] args) throws Exception {\n\ttry {\n\t fastReader = new FastReader(System.in);\n\t systemOut = new BufferedOutputStream(System.out);\n\t solve();\n\t} finally {\n\t systemOut.close();\n\t}\n }\n\n private static FastReader fastReader = null;\n private static BufferedOutputStream systemOut = null;\n\n public static void print(Object obj) {\n\tprint(obj.toString());\n }\n\n public static void print(String str) {\n\ttry {\n\t systemOut.write(str.getBytes(\"utf-8\"));\n\t} catch (Exception ex) {\n\t throw new RuntimeException(ex);\n\t}\n }\n\n public static void println(Object obj) {\n\tprintln(obj.toString());\n }\n\n public static void println(String str) {\n\ttry {\n\t print(str);\n\t systemOut.write('\\n');\n\t} catch (Exception ex) {\n\t throw new RuntimeException(ex);\n\t}\n }\n\n public static String next() {\n\treturn fastReader.readNextToken(false);\n }\n\n public static String nextLine() {\n\treturn fastReader.readNextToken(true);\n }\n\n public static int nextInt() {\n\treturn Integer.parseInt(fastReader.readNextToken(false));\n }\n\n public static long nextLong() {\n\treturn Long.parseLong(fastReader.readNextToken(false));\n }\n\n public static double nextDouble() {\n\treturn Double.parseDouble(fastReader.readNextToken(false));\n }\n\n static class FastReader {\n\tprivate byte[] buf = new byte[65536];\n\tprivate int ind = 0;\n\tprivate int maxInd = -1;\n\tprivate InputStream is = null;\n\tprivate boolean eof = false;\n\tprivate boolean lastCharRead = false;\n\n\tpublic FastReader(InputStream is) {\n\t this.is = is;\n\t}\n\n\tpublic String readNextToken(boolean endOfLine) {\n\t try {\n\t\tStringBuilder sb = new StringBuilder();\n\t\tboolean found = false;\n\t\twhile (true) {\n\t\t if (lastCharRead) {\n\t\t\treturn null;\n\t\t } else if (ind > maxInd) {\n\t\t\tif (eof) {\n\t\t\t lastCharRead = true;\n\t\t\t} else {\n\t\t\t fillBuffer();\n\t\t\t}\n\t\t }\n\t\t byte b = '\\n';\n\t\t if (!lastCharRead) {\n\t\t\tb = buf[ind++];\n\t\t }\n\n\t\t if (b == '\\r') {\n\t\t\t// ignore\n\t\t } else if ((b == '\\n' && endOfLine) || (Character.isWhitespace(b) && !endOfLine)) {\n\t\t\tif (found) {\n\t\t\t break;\n\t\t\t}\n\t\t } else {\n\t\t\tsb.append((char) b);\n\t\t\tfound = true;\n\t\t }\n\t\t}\n\t\treturn sb.toString();\n\t } catch (Exception ex) {\n\t\tthrow new RuntimeException(ex);\n\t }\n\t}\n\n\tprivate void fillBuffer() {\n\t try {\n\t\tint read = is.read(buf, 0, buf.length);\n\t\tif (read < buf.length) {\n\t\t eof = true;\n\t\t}\n\t\tind = 0;\n\t\tmaxInd = read - 1;\n\t } catch (Exception ex) {\n\t\tthrow new RuntimeException(ex);\n\t }\n\t}\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6194bd975805d5a1ef3e69c25065a594", "src_uid": "8097e10157320524c0faed56f2bc4880", "difficulty": 2300.0} {"lang": "Java 7", "source_code": "public class Solution {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int q = in.nextInt();\n Map map = new HashMap<>();\n for(int i = 0; i < q; i++){\n map.put(in.next, in.next);\n }\n for (Map.Entry entry : map.entrySet())\n {\n System.out.println(entry.getKey() + \"/\" + entry.getValue());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "01f2afb14a6de4ed644034d50d2a3cef", "src_uid": "c42abec29bfd17de3f43385fa6bea534", "difficulty": 1300.0} {"lang": "Java 6", "source_code": "import java.util.*;\n\n/**\n * Created by IntelliJ IDEA.\n * User: piyushd\n * Date: 3/29/11\n * Time: 7:56 PM\n * To change this template use File | Settings | File Templates.\n */\npublic class TaskD {\n\n void run() { \n int[][][] have = new int[2][10][10];\n for(char x : next().toCharArray()) {\n for(int i = 0; i < 10; i++) {\n have[0][i][x - '0']++;\n have[1][i][x - '0']++;\n }\n }\n \n String x1 = \"\", x2 = \"\";\n int maxMatch = -1;\n for(int firstMatch = 0; firstMatch < 10; firstMatch++) {\n String xx1 = \"\", xx2 = \"\";\n int[] cnt1 = have[0][firstMatch];\n int[] cnt2 = have[1][firstMatch];\n int match = 0, carry = 0;\n\n if(firstMatch == 0) {\n int need = 0;\n if(cnt1[firstMatch] > 0 && cnt2[need] > 0) {\n xx1 = (char) (firstMatch + '0') + xx1;\n xx2 = (char) (need + '0') + xx2;\n cnt1[firstMatch]--;\n cnt2[need]--;\n match++;\n }\n }\n else {\n int need = 10 - firstMatch;\n if(cnt1[firstMatch] > 0 && cnt2[need] > 0) {\n xx1 = (char) (firstMatch + '0') + xx1;\n xx2 = (char) (need + '0') + xx2;\n cnt1[firstMatch]--;\n cnt2[need]--;\n carry = 1;\n match++;\n }\n }\n\n for(int iter = 0; iter < 2; iter++) {\n int cur = 0;\n while(cur < 10) {\n if(cnt1[cur] > 0) {\n if(cur == 0) {\n int need = (carry > 0) ? 9 : 0;\n if(cnt2[need] > 0) {\n xx1 = (char) (cur + '0') + xx1;\n xx2 = (char) (need + '0') + xx2;\n cnt1[cur]--;\n cnt2[need]--;\n match++;\n }\n else {\n cur++;\n }\n }\n else {\n int need = 10 - cur - carry;\n if(cnt2[need] > 0) {\n xx1 = (char) (cur + '0') + xx1;\n xx2 = (char) (need + '0') + xx2;\n cnt1[cur]--;\n cnt2[need]--;\n match++;\n carry = 1;\n }\n else {\n cur++;\n }\n }\n }\n else {\n cur++;\n }\n }\n }\n\n StringBuilder builder = new StringBuilder();\n while (cnt1[0] > 0 && cnt2[0] > 0) {\n builder.append(\"0\");\n cnt1[0]--;\n cnt2[0]--;\n match++;\n }\n xx1 = xx1.concat(builder.toString());\n xx2 = xx2.concat(builder.toString());\n \n if(match > maxMatch) {\n maxMatch = match;\n StringBuilder builder1 = new StringBuilder();\n StringBuilder builder2 = new StringBuilder();\n for(int i = 0; i < 10; i++) {\n for(int j = 0; j < cnt1[i]; j++) builder1.append((char)(i + '0'));\n for(int j = 0; j < cnt2[i]; j++) builder2.append((char)(i + '0'));\n }\n \n x1 = builder1.toString() + xx1;\n x2 = builder2.toString() + xx2;\n }\n }\n\n System.out.println(x1);\n System.out.println(x2);\n }\n\n int nextInt(){\n try{\n int c = System.in.read();\n if(c == -1) return c;\n while(c != '-' && (c < '0' || '9' < c)){\n c = System.in.read();\n if(c == -1) return c;\n }\n if(c == '-') return -nextInt();\n int res = 0;\n do{\n res *= 10;\n res += c - '0';\n c = System.in.read();\n }while('0' <= c && c <= '9');\n return res;\n }catch(Exception e){\n return -1;\n }\n }\n\n long nextLong(){\n try{\n int c = System.in.read();\n if(c == -1) return -1;\n while(c != '-' && (c < '0' || '9' < c)){\n c = System.in.read();\n if(c == -1) return -1;\n }\n if(c == '-') return -nextLong();\n long res = 0;\n do{\n res *= 10;\n res += c-'0';\n c = System.in.read();\n }while('0' <= c && c <= '9');\n return res;\n }catch(Exception e){\n return -1;\n }\n }\n\n double nextDouble(){\n return Double.parseDouble(next());\n }\n\n String next(){\n try{\n StringBuilder res = new StringBuilder(\"\");\n int c = System.in.read();\n while(Character.isWhitespace(c))\n c = System.in.read();\n do{\n res.append((char)c);\n }while(!Character.isWhitespace(c=System.in.read()));\n return res.toString();\n }catch(Exception e){\n return null;\n }\n }\n\n String nextLine(){\n try{\n StringBuilder res = new StringBuilder(\"\");\n int c = System.in.read();\n while(c == '\\r' || c == '\\n')\n c = System.in.read();\n do{\n res.append((char)c);\n c = System.in.read();\n }while(c != '\\r' && c != '\\n');\n return res.toString();\n }catch(Exception e){\n return null;\n }\n }\n\n public static void main(String[] args){\n new TaskD().run();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c3b68701f91f72002e14d3930c0f4170", "src_uid": "34b67958a37865e1ca0529bbf528dd9a", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.PrintStream;\nimport java.util.Arrays;\nimport java.util.Collection;\nimport java.io.IOException;\nimport java.util.Deque;\nimport java.util.ArrayDeque;\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 PrintWriter out = new PrintWriter(outputStream);\n CJoker solver = new CJoker();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class CJoker {\n Debug debug = new Debug(true);\n\n public void solve(int testNumber, FastInput in, PrintWriter out) {\n int n = in.readInt();\n int m = in.readInt();\n int q = in.readInt();\n\n int[][] edges = new int[2][m + 1];\n for (int i = 1; i <= m; i++) {\n for (int j = 0; j < 2; j++) {\n edges[j][i] = in.readInt() - 1;\n }\n }\n OperationQueue oq = new OperationQueue(m);\n XorDSU dsu = new XorDSU(n);\n int cur = 1;\n for (int i = 1; i <= m; i++) {\n int a = edges[0][i];\n int b = edges[1][i];\n while (dsu.find(a) == dsu.find(b) && dsu.delta(a, b) == 0) {\n oq.remove();\n cur++;\n }\n dsu.merge(a, b, oq);\n }\n\n int[] right = new int[m + 1];\n right[0] = cur;\n for (int i = 1; i <= m; i++) {\n int a = edges[0][i];\n int b = edges[1][i];\n while (cur <= i) {\n cur++;\n oq.remove();\n }\n while (cur <= m && dsu.find(a) == dsu.find(b) && dsu.delta(a, b) == 0) {\n oq.remove();\n cur++;\n }\n if (cur == m + 1 && dsu.find(a) == dsu.find(b) && dsu.delta(a, b) == 0) {\n cur++;\n }\n dsu.merge(a, b, oq);\n right[i] = cur;\n }\n\n for (int i = 0; i < q; i++) {\n int l = in.readInt();\n int r = in.readInt();\n if (right[l - 1] - 1 > r) {\n out.println(\"YES\");\n } else {\n out.println(\"NO\");\n }\n }\n\n debug.debug(\"right\", right);\n }\n\n }\n\n static class XorDSU {\n int[] p;\n int[] rank;\n int[] xor;\n\n public XorDSU(int n) {\n p = new int[n];\n rank = new int[n];\n xor = new int[n];\n for (int i = 0; i < n; i++) {\n p[i] = -1;\n rank[i] = 1;\n }\n }\n\n public int find(int x) {\n return p[x] == -1 ? x : find(p[x]);\n }\n\n public int delta(int a, int b) {\n return deltaToRoot(a) ^ deltaToRoot(b);\n }\n\n public int deltaToRoot(int a) {\n int ans = 0;\n while (p[a] != -1) {\n ans ^= xor[a];\n a = p[a];\n }\n return ans;\n }\n\n public void merge(int a, int b, OperationQueue queue) {\n queue.add(new OperationQueue.CommutativeOperation() {\n int x;\n int y;\n\n\n public void apply() {\n x = find(a);\n y = find(b);\n if (x == y) {\n return;\n }\n if (rank[x] < rank[y]) {\n int tmp = x;\n x = y;\n y = tmp;\n }\n xor[y] = deltaToRoot(a) ^ deltaToRoot(b) ^ 1;\n p[y] = x;\n rank[x] += rank[y];\n }\n\n\n public void undo() {\n if (x == y) {\n return;\n }\n int cur = y;\n while (p[cur] != -1) {\n cur = p[cur];\n rank[cur] -= rank[y];\n }\n p[y] = -1;\n }\n });\n }\n\n }\n\n static interface Operation {\n void apply();\n\n void undo();\n\n }\n\n static class OperationQueue {\n private Deque dq;\n private Deque bufA;\n private Deque bufB;\n\n public OperationQueue(int size) {\n dq = new ArrayDeque<>(size);\n bufA = new ArrayDeque<>(size);\n bufB = new ArrayDeque<>(size);\n }\n\n public void add(OperationQueue.CommutativeOperation op) {\n pushAndDo(op);\n }\n\n private void pushAndDo(OperationQueue.CommutativeOperation op) {\n dq.addLast(op);\n op.apply();\n }\n\n private void popAndUndo() {\n OperationQueue.CommutativeOperation ans = dq.removeLast();\n ans.undo();\n if (ans.a) {\n bufA.addLast(ans);\n } else {\n bufB.addLast(ans);\n }\n }\n\n public void remove() {\n if (!dq.peekLast().a) {\n popAndUndo();\n while (!dq.isEmpty() && bufB.size() != bufA.size()) {\n popAndUndo();\n }\n if (dq.isEmpty()) {\n while (!bufB.isEmpty()) {\n OperationQueue.CommutativeOperation ans = bufB.removeFirst();\n ans.a = true;\n pushAndDo(ans);\n }\n } else {\n while (!bufB.isEmpty()) {\n OperationQueue.CommutativeOperation ans = bufB.removeLast();\n pushAndDo(ans);\n }\n }\n while (!bufA.isEmpty()) {\n pushAndDo(bufA.removeLast());\n }\n }\n\n dq.removeLast().undo();\n }\n\n public static abstract class CommutativeOperation implements Operation {\n private boolean a;\n\n }\n\n }\n\n static class FastInput {\n private final InputStream is;\n private byte[] buf = new byte[1 << 13];\n private int bufLen;\n private int bufOffset;\n private int next;\n\n public FastInput(InputStream is) {\n this.is = is;\n }\n\n private int read() {\n while (bufLen == bufOffset) {\n bufOffset = 0;\n try {\n bufLen = is.read(buf);\n } catch (IOException e) {\n bufLen = -1;\n }\n if (bufLen == -1) {\n return -1;\n }\n }\n return buf[bufOffset++];\n }\n\n public void skipBlank() {\n while (next >= 0 && next <= 32) {\n next = read();\n }\n }\n\n public int readInt() {\n int sign = 1;\n\n skipBlank();\n if (next == '+' || next == '-') {\n sign = next == '+' ? 1 : -1;\n next = read();\n }\n\n int val = 0;\n if (sign == 1) {\n while (next >= '0' && next <= '9') {\n val = val * 10 + next - '0';\n next = read();\n }\n } else {\n while (next >= '0' && next <= '9') {\n val = val * 10 - next + '0';\n next = read();\n }\n }\n\n return val;\n }\n\n }\n\n static class Debug {\n private boolean offline;\n private PrintStream out = System.err;\n static int[] empty = new int[0];\n\n public Debug(boolean enable) {\n offline = enable && System.getSecurityManager() == null;\n }\n\n public Debug debug(String name, Object x) {\n return debug(name, x, empty);\n }\n\n public Debug debug(String name, Object x, int... indexes) {\n if (offline) {\n if (x == null || !x.getClass().isArray()) {\n out.append(name);\n for (int i : indexes) {\n out.printf(\"[%d]\", i);\n }\n out.append(\"=\").append(\"\" + x);\n out.println();\n } else {\n indexes = Arrays.copyOf(indexes, indexes.length + 1);\n if (x instanceof byte[]) {\n byte[] arr = (byte[]) x;\n for (int i = 0; i < arr.length; i++) {\n indexes[indexes.length - 1] = i;\n debug(name, arr[i], indexes);\n }\n } else if (x instanceof short[]) {\n short[] arr = (short[]) x;\n for (int i = 0; i < arr.length; i++) {\n indexes[indexes.length - 1] = i;\n debug(name, arr[i], indexes);\n }\n } else if (x instanceof boolean[]) {\n boolean[] arr = (boolean[]) x;\n for (int i = 0; i < arr.length; i++) {\n indexes[indexes.length - 1] = i;\n debug(name, arr[i], indexes);\n }\n } else if (x instanceof char[]) {\n char[] arr = (char[]) x;\n for (int i = 0; i < arr.length; i++) {\n indexes[indexes.length - 1] = i;\n debug(name, arr[i], indexes);\n }\n } else if (x instanceof int[]) {\n int[] arr = (int[]) x;\n for (int i = 0; i < arr.length; i++) {\n indexes[indexes.length - 1] = i;\n debug(name, arr[i], indexes);\n }\n } else if (x instanceof float[]) {\n float[] arr = (float[]) x;\n for (int i = 0; i < arr.length; i++) {\n indexes[indexes.length - 1] = i;\n debug(name, arr[i], indexes);\n }\n } else if (x instanceof double[]) {\n double[] arr = (double[]) x;\n for (int i = 0; i < arr.length; i++) {\n indexes[indexes.length - 1] = i;\n debug(name, arr[i], indexes);\n }\n } else if (x instanceof long[]) {\n long[] arr = (long[]) x;\n for (int i = 0; i < arr.length; i++) {\n indexes[indexes.length - 1] = i;\n debug(name, arr[i], indexes);\n }\n } else {\n Object[] arr = (Object[]) x;\n for (int i = 0; i < arr.length; i++) {\n indexes[indexes.length - 1] = i;\n debug(name, arr[i], indexes);\n }\n }\n }\n }\n return this;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f20f191e90b01f16e19af7428c43f299", "src_uid": "57ad95bb938906f7550f7eb6422130f7", "difficulty": 2800.0} {"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 sofiane\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n Scanner in = new Scanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskA solver = new TaskA();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskA {\n static int[] p = new int[250];\n static int[] d = new int[100];\n static int n;\n static int l;\n static int k;\n static int dist;\n\n static boolean dfs(int time, boolean[][] vis) {\n dist++;\n if (dist == n + 1) return true;\n for (int i = time + 1; i < 2 * k + time + 1; i++) {\n if (vis[dist][i % (2 * k)]) continue;\n vis[dist][i % (2 * k)] = true;\n if (d[dist] + p[i % (2 * k)] <= l) {\n if (dfs(i, vis)) return true;\n } else break;\n }\n dist--;\n return false;\n }\n\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n int t = in.nextInt();\n while (t-- > 0) {\n n = in.nextInt();\n k = in.nextInt();\n l = in.nextInt();\n for (int i = 1; i <= n; i++)\n d[i] = in.nextInt();\n for (int i = 0; i < 2 * k; i++) {\n if (i < k) p[i] = i;\n else p[i] = 2 * k - i;\n }\n boolean[][] vis = new boolean[110][110];\n for (int i = 0; i < 2 * k; i++) {\n dist = 1;\n if (d[dist] + p[i] <= l) {\n if (dfs(i, vis)) {\n out.println(\"Yes\");\n break;\n }\n }\n if (i == 2 * k - 1) out.println(\"No\");\n }\n }\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ef758392631cb40ccda37bca17864894", "src_uid": "4941b0a365f86b2e2cf686cdf5d532f8", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "//import com.sun.org.apache.xpath.internal.operations.String;\n\n//import com.sun.org.apache.xpath.internal.operations.String;\n\nimport java.io.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.math.RoundingMode;\nimport java.util.*;\n\n\npublic class scratch_25 {\n // int count=0;\n //static long count=0;\n static class Reader {\n static BufferedReader reader;\n static StringTokenizer tokenizer;\n\n /**\n * call this method to initialize reader for InputStream\n */\n static void init(InputStream input) {\n reader = new BufferedReader(\n new InputStreamReader(input));\n tokenizer = new StringTokenizer(\"\");\n }\n\n /**\n * get next word\n */\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 static long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n }\n\n public static class Graph{\n public static class Vertex{\n HashMap nb= new HashMap<>(); // for neighbours of each vertex\n }\n\n public static HashMap vt; // for vertices(all)\n\n public Graph(){\n vt= new HashMap<>();\n }\n\n public static int numVer(){\n return vt.size();\n }\n\n public static boolean contVer(int ver){\n return vt.containsKey(ver);\n }\n\n public static void addVer(int ver){\n Vertex v= new Vertex();\n vt.put(ver,v);\n }\n\n public static int numEdg(){\n int count=0;\n ArrayList vrtc= new ArrayList<>(vt.keySet());\n for (int i = 0; i arr= new ArrayList<>(v1.nb.keySet());\n for (int i = 0; i psf= new ArrayList<>(); // path so far\n int dis;\n int col;\n }\n\n\n\n\n\n\n\n\n\n public HashMap bfs(int src){\n HashMap prcd= new HashMap<>(); // jo jo ho chuke hain unke liye\n\n HashMap ans= new HashMap<>();\n\n LinkedList queue= new LinkedList<>(); // for bfs queue\n\n Pair strtp= new Pair();\n\n strtp.vname= src;\n\n ArrayList ar= new ArrayList<>();\n ar.add(src);\n\n strtp.psf= ar;\n strtp.dis=0;\n\n queue.addLast(strtp);\n\n while(!queue.isEmpty()){\n\n Pair rp = queue.removeFirst();\n\n if(prcd.containsKey(rp.vname)){\n continue;\n }\n prcd.put(rp.vname,true);\n ans.put(rp.vname,rp.dis);\n\n// if(contEdg(rp.vname,dst)){\n// return true;\n// }\n\n Vertex a= vt.get(rp.vname);\n ArrayList arr= new ArrayList<>(a.nb.keySet());\n for (int i = 0; i dfs(int src){\n HashMap prcd= new HashMap<>(); // jo jo ho chuke hain unke liye\n\n HashMap ans= new HashMap<>();\n\n LinkedList stack= new LinkedList<>(); // for bfs queue\n\n Pair strtp= new Pair();\n\n strtp.vname= src;\n\n ArrayList ar= new ArrayList<>();\n ar.add(src);\n\n strtp.psf= ar;\n strtp.dis=0;\n\n stack.addFirst(strtp);\n\n while(!stack.isEmpty()){\n\n Pair rp = stack.removeFirst();\n\n if(prcd.containsKey(rp.vname)){\n continue;\n }\n prcd.put(rp.vname,true);\n ans.put(rp.vname,rp.dis);\n\n// if(contEdg(rp.vname,dst)){\n// return true;\n// }\n\n Vertex a= vt.get(rp.vname);\n ArrayList arr= new ArrayList<>(a.nb.keySet());\n for (int i = 0; i prcd= new HashMap<>(); // jo jo ho chuke hain unke liye\n\n // HashMap ans= new HashMap<>();\n\n LinkedList queue= new LinkedList<>(); // for bfs queue\n\n\n\n ArrayList keys = new ArrayList<>(vt.keySet());\n for (int i = 0; i as= new ArrayList<>();\n as.add(cur);\n sp.psf= as;\n\n queue.addLast(sp);\n\n while(!queue.isEmpty()){\n\n\n\n\n Pair rp= queue.removeFirst();\n if(prcd.containsKey(rp.vname)){\n return true;\n }\n\n prcd.put(rp.vname,true);\n\n\n\n\n Vertex v1= vt.get(rp.vname);\n ArrayList nbrs= new ArrayList<>(v1.nb.keySet());\n for (int j = 0; j > genConnctdComp(){\n HashMap prcd= new HashMap<>(); // jo jo ho chuke hain unke liye\n\n ArrayList> ans= new ArrayList<>();\n\n // HashMap ans= new HashMap<>();\n\n LinkedList queue= new LinkedList<>(); // for bfs queue\n\n // int con=-1;\n\n ArrayList keys = new ArrayList<>(vt.keySet());\n for (int i = 0; i fu= new ArrayList<>();\n fu.add(cur);\n\n\n Pair sp = new Pair();\n sp.vname= cur;\n ArrayList as= new ArrayList<>();\n as.add(cur);\n sp.psf= as;\n\n queue.addLast(sp);\n\n while(!queue.isEmpty()){\n\n\n\n\n Pair rp= queue.removeFirst();\n if(prcd.containsKey(rp.vname)){\n //return true;\n continue;\n }\n\n prcd.put(rp.vname,true);\n fu.add(rp.vname);\n\n\n\n Vertex v1= vt.get(rp.vname);\n ArrayList nbrs= new ArrayList<>(v1.nb.keySet());\n for (int j = 0; j clr= new HashMap<>();\n // colors are 1 and -1\n\n\n LinkedListq = new LinkedList();\n clr.put(src,1);\n q.add(src);\n\n\n while(!q.isEmpty()){\n\n int u = q.getFirst();\n q.pop();\n\n ArrayList arr= new ArrayList<>(vt.keySet());\n\n for (int i = 0; i arr= new ArrayList<>(vt.keySet());\n for (int i = 0; i arr1= new ArrayList<>(v1.nb.keySet());\n for (int j = 0; j {\n int size;\n int mon;\n int num;\n public Cus(int size,int mon,int num){\n this.size=size;\n this.mon=mon;\n this.num=num;\n }\n @Override\n public int compareTo(Cus o){\n if(this.mon!=o.mon){\n return this.mon-o.mon;}\n\n else{\n return o.size-this.size;\n }\n\n }\n\n\n\n }\n\n static class Table implements Comparable{\n int go;\n // int cum;\n int cost;\n public Table(int go,int cost){\n this.go=go;\n // this.cum=cum;\n this.cost=cost;\n }\n @Override\n public int compareTo(Table o){\n \n return this.cost-o.cost;\n\n }\n\n\n }\n static class Table1 implements Comparable{\n int go;\n //int cum;\n int cost;\n public Table1(int go,int cost){\n this.go=go;\n // this.cum=cum;\n this.cost=cost;\n }\n @Override\n public int compareTo(Table1 o){\n return this.cost-o.cost;\n\n\n }}\n\n public static class DisjointSet{\n HashMap mp= new HashMap<>();\n\n public static class Node{\n int data;\n Node parent;\n int rank;\n }\n\n\n public void create(int val){\n Node nn= new Node();\n nn.data=val;\n nn.parent=nn;\n nn.rank=0;\n mp.put(val,nn);\n }\n\n public int find(int val){\n\n return findn(mp.get(val)).data;\n\n }\n\n\n public Node findn(Node n){\n if(n==n.parent){\n return n;\n }\n Node rr= findn(n.parent);\n n.parent=rr;\n return rr;\n }\n\n\n\n public void union(int val1, int val2){ // can also be used to check cycles\n\n Node n1= findn(mp.get(val1));\n Node n2= findn(mp.get(val2));\n\n\n if(n1.data==n2.data) {\n return;\n }\n\n\n\n if(n1.rankar= Sieve(100000000);\n long p= Reader.nextLong();\n long q= Reader.nextLong();\n double f= (1.0*p)/(1.0*q);\n double arr[]= new double[2000000+1];\n long n=0;\n long d=0;\n int ans=0;\n for (int i = 1; i <2000000 ; i++) {\n // System.out.println(\"d=\"+d);\n if(Collections.binarySearch(ar,i)>=0){\n n++;\n }\n StringBuilder s= new StringBuilder(String.valueOf(i));\n if(s.toString().equals((s.reverse()).toString())){\n d++;\n }\n if((1.0*n)/(1.0*d)<=f){\n ans=i;\n //System.out.println(i-1);\n //break;\n }\n\n\n\n\n\n\n\n }\n System.out.println(ans);\n\n\n\n\n\n\n\n\n\n }\n public static long ceil_div(long a, long b){\n return (a+b-1)/b;\n }\n\n static int countDivisibles(int A, int B, int M)\n {\n // Add 1 explicitly as A is divisible by M\n if (A % M == 0)\n return (B / M) - (A / M) + 1;\n\n // A is not divisible by M\n return (B / M) - (A / M);\n }\n\n\n public static void df(int x, int y,int n, int m, char[][]ar, int l){\n boolean done[][]= new boolean[n][m];\n int count=0;\n LinkedList stk= new LinkedList<>();\n int a[]= {x,y};\n stk.addFirst(a);\n while(!stk.isEmpty() && count=n || b[1]+arr[i][1]>=m || b[0]+arr[i][0]<0 || b[1]+arr[i][1]<0 || ar[b[0]+arr[i][0]][b[1]+arr[i][1]]=='#')){\n int r[]= {b[0]+arr[i][0], b[1]+arr[i][1]};\n stk.addFirst(r);\n // continue;\n\n\n\n }\n }}\n\n\n for (int i = 0; i b){\n return gcd(a-b, b);\n\n }\n return gcd(a, b-a);\n }\n\n\n\n\n\n // method to return LCM of two numbers\n static long lcm(long a, long b)\n {\n return (a*b)/gcd(a, b);\n }\n\n // Driver method\n\n static int partition(long arr[],long arr1[], int low, int high)\n {\n long pivot = arr[high];\n int i = (low-1); // index of smaller element\n for (int j=low; j Array to be sorted,\n low --> Starting index,\n high --> Ending index */\n static void sort(long arr[],long arr1[], int low, int high)\n {\n if (low < high)\n {\n /* pi is partitioning index, arr[pi] is\n now at right place */\n int pi = partition(arr,arr1, low, high);\n\n // Recursively sort elements before\n // partition and after partition\n sort(arr,arr1, low, pi-1);\n sort(arr,arr1, pi+1, high);\n }\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n public static ArrayList Sieve(int n) {\n boolean arr[]= new boolean [n+1];\n Arrays.fill(arr,true);\n arr[0]=false;\n arr[1]=false;\n for (int i = 2; i*i <=n ; i++) {\n if(arr[i]){\n for (int j = 2; j <=n/i ; j++) {\n int u= i*j;\n arr[u]=false;\n }}\n }\n ArrayList ans= new ArrayList<>();\n for (int i = 0; i = 0; --i) {\r\n\t\t\t\tint fi = facs.get(i);\r\n\t\t\t\tcountFacs[i] = rem / fi - 1;\r\n\t\t\t\tfor (int j = i + 1; j < facs.size(); ++j) {\r\n\t\t\t\t\tint fj = facs.get(j);\r\n\t\t\t\t\tif (fj % fi != 0) {\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\t\t\t\t\tcountFacs[i] -= countFacs[j];\r\n\t\t\t\t}\r\n\t\t\t\ttotal += 1L * c * facs.get(i) * countFacs[i] / gcd(fi, c);\r\n\t\t\t\ttotal %= MOD;\r\n\t\t\t}\r\n\t\t}\r\n\t\tio.println(total);\r\n\t}\r\n\r\n\t/**\r\n\t * Computes the GCD (greatest common denominator) between two numbers.\r\n\t */\r\n\tpublic static int gcd(int a, int b) {\r\n\t\tif (a < b)\r\n\t\t\treturn gcd(b, a);\r\n\r\n\t\tint r = a % b;\r\n\t\tif (r == 0)\r\n\t\t\treturn b;\r\n\r\n\t\treturn gcd(b, r);\r\n\t}\r\n\r\n\tprivate static class IntList extends ArrayList {\r\n\t\tprivate static final long serialVersionUID = 8986468115134862220L;\r\n\t}\r\n\r\n\tpublic static class FastIO {\r\n\t\tprivate InputStream reader;\r\n\t\tprivate PrintWriter writer;\r\n\r\n\t\tprivate byte[] buf = new byte[1024];\r\n\t\tprivate int curChar;\r\n\t\tprivate int numChars;\r\n\r\n\t\tpublic FastIO(InputStream r, OutputStream w) {\r\n\t\t\treader = r;\r\n\t\t\twriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(w)));\r\n\t\t}\r\n\r\n\t\tpublic int read() {\r\n\t\t\tif (numChars == -1)\r\n\t\t\t\tthrow new InputMismatchException();\r\n\t\t\tif (curChar >= numChars) {\r\n\t\t\t\tcurChar = 0;\r\n\t\t\t\ttry {\r\n\t\t\t\t\tnumChars = reader.read(buf);\r\n\t\t\t\t} catch (IOException e) {\r\n\t\t\t\t\tthrow new InputMismatchException();\r\n\t\t\t\t}\r\n\t\t\t\tif (numChars <= 0)\r\n\t\t\t\t\treturn -1;\r\n\t\t\t}\r\n\t\t\treturn buf[curChar++];\r\n\t\t}\r\n\r\n\t\tpublic String nextLine() {\r\n\t\t\tint c = read();\r\n\t\t\twhile (isSpaceChar(c))\r\n\t\t\t\tc = read();\r\n\t\t\tStringBuilder res = new StringBuilder();\r\n\t\t\tdo {\r\n\t\t\t\tres.appendCodePoint(c);\r\n\t\t\t\tc = read();\r\n\t\t\t} while (!isEndOfLine(c));\r\n\t\t\treturn res.toString();\r\n\t\t}\r\n\r\n\t\tpublic String nextString() {\r\n\t\t\tint c = read();\r\n\t\t\twhile (isSpaceChar(c))\r\n\t\t\t\tc = read();\r\n\t\t\tStringBuilder res = new StringBuilder();\r\n\t\t\tdo {\r\n\t\t\t\tres.appendCodePoint(c);\r\n\t\t\t\tc = read();\r\n\t\t\t} while (!isSpaceChar(c));\r\n\t\t\treturn res.toString();\r\n\t\t}\r\n\r\n\t\tpublic long nextLong() {\r\n\t\t\tint c = read();\r\n\t\t\twhile (isSpaceChar(c))\r\n\t\t\t\tc = read();\r\n\t\t\tint sgn = 1;\r\n\t\t\tif (c == '-') {\r\n\t\t\t\tsgn = -1;\r\n\t\t\t\tc = read();\r\n\t\t\t}\r\n\t\t\tlong res = 0;\r\n\t\t\tdo {\r\n\t\t\t\tif (c < '0' || c > '9')\r\n\t\t\t\t\tthrow new InputMismatchException();\r\n\t\t\t\tres *= 10;\r\n\t\t\t\tres += c - '0';\r\n\t\t\t\tc = read();\r\n\t\t\t} while (!isSpaceChar(c));\r\n\t\t\treturn res * sgn;\r\n\t\t}\r\n\r\n\t\tpublic int nextInt() {\r\n\t\t\tint c = read();\r\n\t\t\twhile (isSpaceChar(c))\r\n\t\t\t\tc = read();\r\n\t\t\tint sgn = 1;\r\n\t\t\tif (c == '-') {\r\n\t\t\t\tsgn = -1;\r\n\t\t\t\tc = read();\r\n\t\t\t}\r\n\t\t\tint res = 0;\r\n\t\t\tdo {\r\n\t\t\t\tif (c < '0' || c > '9')\r\n\t\t\t\t\tthrow new InputMismatchException();\r\n\t\t\t\tres *= 10;\r\n\t\t\t\tres += c - '0';\r\n\t\t\t\tc = read();\r\n\t\t\t} while (!isSpaceChar(c));\r\n\t\t\treturn res * sgn;\r\n\t\t}\r\n\r\n\t\t// TODO: read this byte-by-byte like the other read functions.\r\n\t\tpublic double nextDouble() {\r\n\t\t\treturn Double.parseDouble(nextString());\r\n\t\t}\r\n\r\n\t\tpublic int[] nextIntArray(int n) {\r\n\t\t\treturn nextIntArray(n, 0);\r\n\t\t}\r\n\r\n\t\tpublic int[] nextIntArray(int n, int off) {\r\n\t\t\tint[] arr = new int[n + off];\r\n\t\t\tfor (int i = 0; i < n; i++) {\r\n\t\t\t\tarr[i + off] = nextInt();\r\n\t\t\t}\r\n\t\t\treturn arr;\r\n\t\t}\r\n\r\n\t\tpublic long[] nextLongArray(int n) {\r\n\t\t\treturn nextLongArray(n, 0);\r\n\t\t}\r\n\r\n\t\tpublic long[] nextLongArray(int n, int off) {\r\n\t\t\tlong[] arr = new long[n + off];\r\n\t\t\tfor (int i = 0; i < n; i++) {\r\n\t\t\t\tarr[i + off] = nextLong();\r\n\t\t\t}\r\n\t\t\treturn arr;\r\n\t\t}\r\n\r\n\t\tprivate boolean isSpaceChar(int c) {\r\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\r\n\t\t}\r\n\r\n\t\tprivate boolean isEndOfLine(int c) {\r\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\r\n\t\t}\r\n\r\n\t\tpublic void print(Object... objects) {\r\n\t\t\tfor (int i = 0; i < objects.length; i++) {\r\n\t\t\t\tif (i != 0) {\r\n\t\t\t\t\twriter.print(' ');\r\n\t\t\t\t}\r\n\t\t\t\twriter.print(objects[i]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void println(Object... objects) {\r\n\t\t\tprint(objects);\r\n\t\t\twriter.println();\r\n\t\t}\r\n\r\n\t\tpublic void printArray(int[] arr) {\r\n\t\t\tfor (int i = 0; i < arr.length; i++) {\r\n\t\t\t\tif (i != 0) {\r\n\t\t\t\t\twriter.print(' ');\r\n\t\t\t\t}\r\n\t\t\t\twriter.print(arr[i]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void printArray(long[] arr) {\r\n\t\t\tfor (int i = 0; i < arr.length; i++) {\r\n\t\t\t\tif (i != 0) {\r\n\t\t\t\t\twriter.print(' ');\r\n\t\t\t\t}\r\n\t\t\t\twriter.print(arr[i]);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void printlnArray(int[] arr) {\r\n\t\t\tprintArray(arr);\r\n\t\t\twriter.println();\r\n\t\t}\r\n\r\n\t\tpublic void printlnArray(long[] arr) {\r\n\t\t\tprintArray(arr);\r\n\t\t\twriter.println();\r\n\t\t}\r\n\r\n\t\tpublic void printf(String format, Object... args) {\r\n\t\t\tprint(String.format(format, args));\r\n\t\t}\r\n\r\n\t\tpublic void flush() {\r\n\t\t\twriter.flush();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tFastIO io = new FastIO(System.in, System.out);\r\n\t\tsolve(io);\r\n\t\tio.flush();\r\n\t}\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d3ef92ea13baf8c4607c7f81e71adf57", "src_uid": "c3694a6ff95c64bef8cbe8834c3fd6cb", "difficulty": 2200.0} {"lang": "Java 6", "source_code": "import java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileOutputStream;\nimport java.io.PrintWriter;\nimport java.util.*;\n\n/**\n * Created with IntelliJ IDEA.\n * User: Sabyrzhan_Tynybayev\n * Date: 7/15/13\n * Time: 6:41 PM\n * To change this template use File | Settings | File Templates.\n */\npublic class Main {\n public static void main(String[] args) throws Exception {\n Scanner sc = new Scanner(System.in);\n PrintWriter pw = new PrintWriter(System.out);\n\n String numbers = sc.nextLine();\n String av = sc.nextLine();\n int totalCount = 0;\n while(true) {\n int count = 0;\n List items = new ArrayList<>();\n for(int i = 0; i < av.length(); i++) {\n items.add(String.valueOf(av.charAt(i)));\n }\n\n for(int i = 0; i < numbers.length(); i++) {\n boolean isItemUsed = false;\n for(int j = 0; j < items.size(); j++) {\n if((items.get(j).equals(String.valueOf(numbers.charAt(i))) || isItems2or5(String.valueOf(numbers.charAt(i)), items.get(j)) || isItems6or9(String.valueOf(numbers.charAt(i)), items.get(j))) && !isItemUsed) {\n items.set(j, \"\");\n count++;\n isItemUsed = true;\n }\n }\n }\n\n if(count != numbers.length()) {\n break;\n }\n\n totalCount++;\n av = \"\";\n for(int i = 0; i < items.size(); i++) {\n if(items.get(i) != null) {\n av += items.get(i);\n }\n }\n }\n\n pw.println(totalCount);\n pw.close();\n sc.close();\n }\n\n static boolean isItems2or5(String number, String listItem) {\n return (\"2\".equals(number) && \"5\".equals(listItem)) || (\"5\".equals(number) && \"2\".equals(listItem));\n }\n\n static boolean isItems6or9(String number, String listItem) {\n return (\"6\".equals(number) && \"9\".equals(listItem)) || (\"9\".equals(number) && \"6\".equals(listItem));\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "37c426444877959df7797c9c22938417", "src_uid": "72a196044787cb8dbd8d350cb60ccc32", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "//package com.company;\nimport java.util.Scanner;\npublic class Main {\n\n public static void main(String[] args) {\n Scanner scn = new Scanner(System.in);\n long n = scn.nextInt();\n long p = scn.nextInt();\n scn.nextLine();\n long res = p/2, apples = 1;\n String s = new String();\n String[] mas = new String[n];\n\n for (int i=0; i=0;i--){\n if (mas[i].equals(\"half\")){\n res += p*apples;\n apples*=2;\n }\n else {\n res += p*apples+p/2;\n apples*=2;\n apples++;\n }\n }\n System.out.println(res);\n\n\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b1ed4be88b926d8053ca57928a4eed82", "src_uid": "6330891dd05bb70241e2a052f5bf5a58", "difficulty": 1200.0} {"lang": "Java 6", "source_code": "//package round85;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class D {\n\tScanner in;\n\tPrintWriter out;\n\tString INPUT = \"7 8 15\";\n\tint mod = 1000000007;\n\t\n\t// 1\u5217\u306e\u5834\u5408\u306f\u306a\u3093\u3067\u3082\u3042\u308a\u306a\u306e\u3067k^n\n\t// 2\u5217\u306e\u5834\u5408\u306f\u3069\u3063\u3061\u3082\u540c\u3058i\u8272\u3067\u3042\u308c\u3070\u3044\u3044\u306e\u3067\u3001\n\t// \\sum_i (C(k,i)F(n,i))^2\n\t// 3\u5217\u4ee5\u4e0a\u306e\u5834\u5408\u306f\u4e21\u7aef\u304c\u5171\u901a\u90e8\u5206\u30921\u8272\u4ee5\u4e0a\u6301\u3064\u540c\u3058\u8272\u6570\u306e\u914d\u8272\u3001\u771f\u3093\u4e2d\u306f\u305d\u306e\u8272\u5185\u306a\u3089\u306a\u3093\u3067\u3082\u3088\u3044\u3002\n\t// |A|<=|A\\cup C|=|B|, |B|<=|B\\cup C|=|A|\n\t// |A|=|B|, C\\in A\\cup B\n\t// \\sum_i (F(n,i)^2)\\sum_p=1^i C(k,p)p^{n(m-2)}C(k-p,i-p)C(k-i,i-p)\n\t// C(k,p)C(k-p,i-p)C(k-i,i-p)\n\t// =k!/p!(i-p)!(k-2i+p)!(i-p)!\n\t// F(n,i)\u306fn\u884c\u3092\u3061\u3087\u3046\u3069i\u8272\u3067\u5857\u308b\u5857\u308a\u65b9\n\t// F(n,i)=i^n-C(i,1)(i-1)^n+C(i,2)(i-2)^n-...\n\t// \u3053\u308c\u3092\u6c42\u3081\u308b\u306e\u306bO(i)\n\t// \u5168\u4f53\u3067O(k^2)\u304b\u304b\u3063\u3066\u3057\u307e\u3046\u306e\u3067\u666e\u901a\u306e\u8a08\u7b97\u3067\u306f\u9593\u306b\u5408\u308f\u306a\u3044\u3002\n\t// \n\t// \n\t\n\tvoid solve()\n\t{\n\t\tint n = ni();\n\t\tint m = ni();\n\t\tint K = ni();\n\t\t\n\t\tlong[] A = new long[K+1];\n\t\tlong[] IA = new long[K+1];\n\t\tA[0] = 1;\n\t\tIA[0] = 1;\n\t\tfor(int i = 1;i <= K;i++){\n\t\t\tA[i] = A[i-1] * i % mod;\n\t\t\tIA[i] = inv(A[i], mod);\n\t\t}\n\t\t\n\t\tlong[] I = new long[1001];\n\t\tlong[] IM = new long[1001];\n\t\tfor(int i = 0;i <= 1000;i++){\n\t\t\tI[i] = modpow(i, n, mod);\n\t\t\tIM[i] = modpow(i, n*(m-2), mod);\n\t\t}\n\t\t\n\t\t// F(n,i)=i^n-C(i,1)(i-1)^n+C(i,2)(i-2)^n-...\n\t\tlong[] F = new long[n+1];\n\t\tfor(int i = 0;i <= n;i++){\n\t\t\tlong val = 0;\n\t\t\tlong minus = 1;\n\t\t\tfor(int j = i;j >= 0;j--){\n\t\t\t\tval += I[j] * minus * A[i]%mod*IA[i-j]%mod*IA[j] % mod;\n\t\t\t\tminus = -minus;\n\t\t\t}\n\t\t\tF[i] = (val%mod+mod)%mod;\n\t\t}\n\t\t\n\t\tif(m == 1){\n\t\t\tout.println(modpow(K, n, mod));\n\t\t}else if(m == 2){\n\t\t\tlong sum = 0;\n\t\t\tfor(int i = 1;i <= K;i++){\n\t\t\t\tlong cfm = A[K]%mod*IA[i]%mod*IA[K-i]%mod*F[i]%mod;\n\t\t\t\tsum += cfm*cfm%mod;\n\t\t\t}\n\t\t\tout.println(sum%mod);\n\t\t}else{\n\t\t\tlong sum = 0;\n\t\t\t// \\sum_i (F(n,i)^2)\\sum_p=1^i C(k,p)p^{n(m-2)}C(k-p,i-p)C(k-i,i-p)\n\t\t\t// =k!/p!(i-p)!(k-2i+p)!(i-p)!\n\t\t\tfor(int i = 1;i <= Math.min(K, n);i++){\n\t\t\t\tlong psum = 0;\n\t\t\t\tfor(int p = 1;p <= i;p++){\n\t\t\t\t\tpsum += A[K]*IA[p]%mod*IA[i-p]%mod*IA[i-p]%mod*IA[K-2*i+p]%mod*IM[p]%mod;\n\t\t\t\t}\n\t\t\t\tpsum%=mod;\n\t\t\t\tlong all = F[i]*F[i]%mod*psum%mod;\n\t\t\t\tsum += all;\n\t\t\t}\n\t\t\tout.println(sum%mod);\n\t\t}\n\t}\n\t\n\tpublic static long inv(long a, int p)\n\t{\n\t\tlong ret = 1;\n\t\tlong mul = a;\n\t\tfor(long n = p-2;n > 0;n >>>= 1){\n\t\t\tif((n&1)==1)ret = ret * mul % p;\n\t\t\tmul = mul * mul % p;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tpublic static long modpow(long a, long n, long mod)\n\t{\n\t\tlong ret = 1;\n\t\tlong mul = a;\n\t\tfor(;n > 0;n >>>= 1){\n\t\t\tif((n&1)==1){\n\t\t\t\tret = (ret * mul) % mod;\n\t\t\t}\n\t\t\tmul = (mul * mul) % mod;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tin = oj ? new Scanner(System.in) : new Scanner(INPUT);\n\t\tout = new PrintWriter(System.out);\n\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tnew D().run();\n\t}\n\t\n\tint ni() { return Integer.parseInt(in.next()); }\n\tlong nl() { return Long.parseLong(in.next()); }\n\tdouble nd() { return Double.parseDouble(in.next()); }\n\tboolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tvoid tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4b79b60ac589923a53a253da869abfe2", "src_uid": "f22f28e2d8933f4199ba5ccfc0de8cda", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Village {\n public static void main(String[] args) throws IOException {\n \tInputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n\n // InputStream inputStream = new FileInputStream(\"input.txt\");\n // OutputStream outputStream = new FileOutputStream(\"output.txt\");\n\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 static class TaskA {\n long mod = (long)(998244353);\n long fact[];\n int depth[];\n int parentTable[][];\n int degree[];\n ArrayList leaves;\n int max = Integer.MIN_VALUE;\n int min = Integer.MAX_VALUE;\n\n \tint ans = 0;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {\n while(testNumber-->0){\n \tint n = in.nextInt();\n \tArrayList> a = new ArrayList<>();\n \tfor(int i=0;i<=n;i++)\n \t\ta.add(new ArrayList<>());\n \tfor(int i=0;i> a , int parent , int index , int b[]){\n \t// visited[u] = 1;\n \tfor(int i=0;i find(long n){\n \tHashMap ans = new HashMap<>();\n \tfor(long i = 2;i*i<=n;i++){\n \t\tif(n%i == 0){\n \t\t\tint count = 0;\n \t\t\twhile(n%i == 0){\n \t\t\t\tn/=i;\n \t\t\t\tcount++;\n \t\t\t}\n \t\t\tans.put(i , count);\n \t\t}\n \t}\n \tif(n!=1){\n \t\tans.put(n , 1);\n \t}\n \treturn ans;\n }\n\n public void add(HashMap> a , int u , int v){\n \tif(!a.containsKey(u))\n \t\ta.put(u , new HashSet<>());\n \ta.get(u).add(v);\n }\n\n class Pair{\n long x;\n long y;\n public Pair(long x , long y){\n this.x = x;\n this.y = y;\n }\n }\n\n class Sort implements Comparator{\n \tpublic int compare(Pair a , Pair b){\n \t\tif(a.x < b.x)\n \t\t\treturn -1;\n \t\tif(a.x == b.x && a.y0){\n if((b&1) == 1)\n res = multiply(res , a , 10);\n a = multiply(a , a , 10);\n b>>=1;\n }\n return res;\n }\n\n public int distance(ArrayList> a , int u , int v){\n return depth[u]+depth[v] - 2*depth[lca(a , u , v)];\n }\n\n public int lca(ArrayList> a , int u , int v){\n if(depth[v]>i)&1) == 1)\n v = parentTable[v][i];\n }\n if(v == u)\n return v;\n for(int i=parentTable[v].length-1;i>=0;i--){\n if(parentTable[u][i] != parentTable[v][i]){\n v = parentTable[v][i];\n u = parentTable[u][i];\n }\n }\n return parentTable[u][0];\n }\n\n // for the min max problems\n public void build(int lookup[][] , int arr[], int n) { \n for (int i = 0; i < n; i++) \n lookup[i][0] = arr[i]; \n for (int j = 1; (1 << j) <= n; j++) { \n for (int i = 0; (i + (1 << j) - 1) < n; i++) { \n if (lookup[i][j - 1] > lookup[i + (1 << (j - 1))][j - 1]) \n lookup[i][j] = lookup[i][j - 1]; \n else\n lookup[i][j] = lookup[i + (1 << (j - 1))][j - 1]; \n } \n } \n }\n public int query(int lookup[][] , int L, int R) { \n int j = (int)(Math.log(R - L + 1)/Math.log(2)); \n if (lookup[L][j] >= lookup[R - (1 << j) + 1][j]) \n return lookup[L][j]; \n else\n return lookup[R - (1 << j) + 1][j]; \n }\n\n // for printing purposes\n public void print1d(int a[] , PrintWriter out){\n for(int i=0;i 0) {\n long x = b&1;\n if (x == 1)\n res = res * a % m;\n a = a * a % m;\n b >>= 1;\n }\n return res;\n }\n public long pow(long a, long b) {\n long res = 1;\n while (b > 0) {\n long x = b&1;\n if (x == 1)\n res = res * a;\n a = a * a;\n b >>= 1;\n }\n return res;\n }\n public void sortedArrayToBST(TreeSet a , int start, int end) { \n if (start > end) {\n return;\n }\n int mid = (start + end) / 2;\n a.add(mid);\n sortedArrayToBST(a, start, mid - 1);\n sortedArrayToBST(a, mid + 1, end); \n }\n public int lowerLastBound(ArrayList a , int x){\n int l = 0;\n int r = a.size()-1;\n if(a.get(l)>=x)\n return -1;\n if(a.get(r)=x)\n r = mid-1;\n else if(a.get(mid)=x)\n return mid;\n else if(a.get(mid) a , Integer x){\n int l = 0;\n int r = a.size()-1;\n if(a.get(l)>x)\n return l;\n if(a.get(r)<=x)\n return r+1;\n int mid = -1;\n while(l<=r){\n mid = (l+r)/2;\n if(a.get(mid) == x && a.get(mid+1)>x)\n return mid+1;\n else if(a.get(mid)<=x)\n l = mid+1;\n else if(a.get(mid)>x && a.get(mid-1)<=x)\n return mid;\n else if(a.get(mid)>x && a.get(mid-1)>x)\n r = mid-1;\n }\n return mid;\n }\n public int lowerLastBound(int a[] , int x){\n int l = 0;\n int r = a.length-1;\n if(a[l]>=x)\n return -1;\n if(a[r]=x)\n r = mid-1;\n else if(a[mid]=x)\n return mid;\n else if(a[mid]x)\n return l;\n if(a[r]<=x)\n return r+1;\n int mid = -1;\n while(l<=r){\n mid = (l+r)/2;\n if(a[mid] == x && a[mid+1]>x)\n return mid+1;\n else if(a[mid]<=x)\n l = mid+1;\n else if(a[mid]>x && a[mid-1]<=x)\n return mid;\n else if(a[mid]>x && a[mid-1]>x)\n r = mid-1;\n }\n return mid;\n }\n public long log(float number , int base){\n return (long) Math.ceil((Math.log(number) / Math.log(base)) + 1e-9);\n }\n public long gcd(long a , long b){\n if(agcd 1->xValue 2->yValue\n return new long[] { d, a, b };\n }\n public void sievePhi(int a[]){\n a[0] = 0;\n a[1] = 1;\n for(int i=2;i>=1;\n }\n return ans;\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ca3370eeb0de556b862fd731d3df70e0", "src_uid": "c9e79e83928d5d034123ebc3b2f5e064", "difficulty": 2600.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.LinkedList;\nimport java.util.Locale;\nimport java.util.Queue;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\npublic class Solution implements Runnable {\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st;\n\n\tString nextToken() throws Exception {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tint nextInt() throws Exception {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws Exception {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws Exception {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\t\n\tlong modd = 1000000007;\n\t\n\tlong gcd(long a, long b) {\n\t\twhile (b != 0) {\n\t\t\tlong t = a % b;\n\t\t\ta = b;\n\t\t\tb = t;\n\t\t}\n\t\treturn a;\n\t}\n\t\n\tlong f(int a, int b) {\n\t\tlong res = 0;\n\t\tboolean evens = a * b % 2 == 0;\n\t\tif (evens) {\n\t\t\tres = 2 * a + 2 * b;\n\t\t}\n\t\tlong all = (a - 1) * (b - 1);\n\t\tlong odd = a / 2 * (b / 2);\n\t\tif (evens) {\n\t\t\tres = (res + 4 * (all - odd)) % modd;\n\t\t} else {\n\t\t\tres = (res + 4 * odd) % modd;\n\t\t}\n\t\tlong aeven = 0;\n\t\tif (a % 2 == 0) aeven = b + 1; else {\n\t\t\taeven = (b + 2) / 2;\n\t\t}\n\t\tlong aodd = b + 1 - aeven;\n\t\tlong beven = 0;\n\t\tif (b % 2 == 0) beven = a + 1; else {\n\t\t\tbeven = (a + 2) / 2;\n\t\t}\n\t\tlong bodd = a + 1 - beven;\n\t\tlong tmp = aeven * beven % modd + aodd * bodd % modd;\n\t\tif (evens) tmp = (tmp + modd - 2) % modd;\n\t\ttmp = (tmp + modd - gcd(a, b) - 1) % modd;\n\t\treturn (res + 2 * tmp) % modd;\n\t}\n\t\n\tint ans(int w, int h) {\n\t\tlong ans = 0;\n\t\tif (w < h) { int t = w; w = h; h = t; }\n\t\tfor (int i = 1; i <= h; i++) {\n\t\t\tfor (int j = i + 1; j <= h; j++) {\n\t\t\t\tlong t = f(i, j);\n\t\t\t\tans = (ans + t * (w - i + 1) * (h - j + 1)) % modd;\n\t\t\t\tans = (ans + t * (h - i + 1) * (w - j + 1)) % modd;\n\t\t\t}\n\t\t}\n\t\tfor (int i = 1; i <= h; i++) {\n\t\t\tlong t = f(i, i);\n\t\t\tans = (ans + t * (w - i + 1) * (h - i + 1)) % modd;\n\t\t}\n\t\tfor (int i = h + 1; i <= w; i++) {\n\t\t\tfor (int j = 1; j <= h; j++) {\n\t\t\t\tlong t = f(i, j);\n\t\t\t\tans = (ans + t * (w - i + 1) * (h - j + 1)) % modd;\n\t\t\t}\n\t\t}\n\t\treturn (int)(ans * 6 % modd);\n\t}\n\t\n\tvoid solve() throws Exception {\n\t\tint w = nextInt(), h = nextInt();\n\t\tout.println(ans(w, h));\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tLocale.setDefault(Locale.UK);\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t// in = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\t// out = new PrintWriter(\"output.txt\");\n\t\t\tsolve();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t} finally {\n\t\t\tout.close();\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\t// new Thread(null, new Solution(), \"1\", 1 << 28).start();\n\t\t(new Solution()).run();\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a472ad71f4c322d3e3668d62bf24f243", "src_uid": "984788e4b4925c15c9c6f31e42f2f8fa", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\n\npublic class Pie {\n\t\tpublic static void main(String args[]){\n\t\t\tScanner sc = new Scanner(System.in);\n\t\t\tint n = in.nextInt();\n\t\t\tint a[] = new int [n+1];\n\t\t\tint sum[] = new int[n+1];\n\n\t\t\tfor(int i = 0; i=0; i--){\n\n\t\t\t\tsum[i] = sum[i+1]+a[i];\n\t\t\t\tdp[i] = Math.max(dp[i+1], sum[i+1]-dp[i+1]+a[i]);\n\t\t\t}\n\t\t\tSystem.out.println((sum[0]-dp[0])+\" \"+dp[0]);\n\t\t}\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7f269a5532e9aaceab9089534bfe44c4", "src_uid": "414540223db9d4cfcec6a973179a0216", "difficulty": 1500.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class B {\n\n BufferedReader br;\n PrintWriter out;\n StringTokenizer st;\n boolean eof;\n\n int f(int x) {\n int ret = 0;\n while (x > 0) {\n ret++;\n x >>= 1;\n }\n return ret;\n }\n\n boolean isPow2(int x) {\n if (x == 0) {\n throw new AssertionError();\n }\n return (x & (x - 1)) == 0;\n }\n\n void solve() throws IOException {\n int n = nextInt();\n int q = nextInt();\n\n int[] sz = new int[n + 1];\n sz[1] = 1;\n for (int i = 1; i < n; i++) {\n sz[i + 1] = sz[i] + f(sz[i]);\n }\n\n int[] up = new int[sz[n] + 1];\n\n for (int par = 1, child = 1; child <= sz[n]; par++) {\n up[child++] = par;\n if (isPow2(par)) {\n if (child <= sz[n]) {\n up[child++] = par;\n }\n }\n }\n\n List add = new ArrayList<>();\n List ans = new ArrayList<>();\n\n while (q-- > 0) {\n int type = nextInt();\n if (type == 1) {\n int[] tmp = { nextInt(), nextInt(), nextInt(), nextInt() };\n add.add(tmp);\n } else {\n int[] tmp = { nextInt(), nextInt() };\n ans.add(tmp);\n }\n }\n\n int[] outp = new int[ans.size()];\n Set set = new HashSet<>();\n\n for (int level = n; level >= 1; level--) {\n for (int i = 0; i < ans.size(); i++) {\n if (ans.get(i)[0] == level) {\n set.clear();\n int pos = ans.get(i)[1];\n for (int j = 0; j < add.size(); j++) {\n int[] tmp = add.get(j);\n// System.err.println(level + \" \" + pos);\n// System.err\n// .println(tmp[0] + \" \" + tmp[1] + \" \" + tmp[2]);\n if (tmp[0] == level && tmp[1] <= pos && pos <= tmp[2]) {\n set.add(tmp[3]);\n }\n }\n outp[i] = set.size();\n }\n }\n\n for (int i = 0; i < add.size(); i++) {\n int[] tmp = add.get(i);\n if (tmp[0] == level) {\n tmp[0]--;\n tmp[1] = up[tmp[1]];\n tmp[2] = up[tmp[2]];\n }\n }\n\n }\n\n for (int x : outp) {\n out.println(x);\n }\n\n }\n\n B() throws IOException {\n br = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n solve();\n out.close();\n }\n\n public static void main(String[] args) throws IOException {\n new B();\n }\n\n 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\n String nextString() {\n try {\n return br.readLine();\n } catch (IOException e) {\n eof = true;\n return null;\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "29ca9f598ef158133a82e077e1953e62", "src_uid": "9f239cfd29c1a2652a065bfe5c15476a", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class Task {\n \n public static long max(long a, long b ) {\n if(a < b) {\n return b;\n }\n return a;\n }\n \n \n public static int max(int a, int b ) {\n if(a < b) {\n return b;\n }\n return a;\n }\n \n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int k = sc.nextInt();\n int[] beauty = new int[200005];\n for(int i = 0; i < n; i++) {\n beauty[i] = sc.nextInt();\n }\n sc.nextLine();\n String str = sc.nextLine();\n int rcn = 0;\n int wcn = 0;\n int ocn = 0;\n int rsum = 0;\n int wsum = 0;\n int osum = 0;\n ArrayList wo = new ArrayList();\n ArrayList ro = new ArrayList();\n int maxo = 0;\n int maxr = 0;\n int maxw = 0;\n for(int i = 0; i < n; i++) {\n if(str.charAt(i) == 'R') {\n maxr = max(maxr,beauty[i]);\n rcn++;\n ro.add(beauty[i]);\n rsum+= beauty[i];\n }\n if(str.charAt(i) == 'W') {\n maxw = max(maxw,beauty[i]);\n wcn++;\n wo.add(beauty[i]);\n wsum+= beauty[i];\n }\n if(str.charAt(i) == 'O') {\n maxo = max(maxo,beauty[i]);\n ocn++;\n ro.add(beauty[i]);\n wo.add(beauty[i]);\n osum+= beauty[i];\n }\n }\n ro.remove(ro.indexOf(maxr));\n ro.remove(ro.indexOf(maxo));\n wo.remove(wo.indexOf(maxw));\n wo.remove(wo.indexOf(maxo));\n if(k == 1 || ocn == 0 || max(ocn+wcn,ocn+rcn) < k) {\n System.out.print(-1);\n } else {\n Collections.sort(ro);\n Collections.sort(wo);\n long ans1 = maxr+maxo;\n long ans2 = maxw+maxo;\n if(ro.size()+2 >= k) {\n for(int i = ro.size()-1; i >= ro.size()-k+2; i--) {\n ans1+= ro.get(i);\n }\n }\n if(wo.size()+2 >= k) {\n for(int i = wo.size()-1; i >= wo.size()-k+2; i--) {\n ans2+= wo.get(i);\n }\n }\n System.out.print(max(ans1,ans2));\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fc8a37080a92b95240e51a1c486b4545", "src_uid": "104cf5253e027929f257364b3874c38b", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "\n\n\nimport static java.lang.Math.abs;\nimport static java.lang.System.out;\nimport java.util.Scanner;\n\n// 795A\n// n people, some pupil, some adult. separate into groups. a group must have 1 adult\n// if a group has x people, cost of tickets=c1+c2(x-1)^2\n// optimize grouping to find minimal price\n// IDEA: binary search, local minimum may not be the best answer as we may have picked the wrong half\n// need to verify if there is no better solution\npublic class AmusementPark {\n \n int adult;\n int pupil;\n int n; // 1\u2009\u2264\u2009n\u2009\u2264\u2009200\u2009000\n long c1; // 1\u2009\u2264\u2009c1,\u2009c2\u2009\u2264\u200910^7\n long c2; // use long type to avoid overflow in calculation\n long minCost=0;\n \n long formula(int x)\n {\n return c1+c2*(x-1)*(x-1);\n }\n long calc(int group)\n {\n if (group==1)\n {\n return formula(n);\n }\n int avg = n/group;\n int rem = n%group;\n long cost = formula(avg);\n cost *= (group-rem);\n return cost + rem*formula(avg+1);\n }\n long cost(int lo, int hi, long lowCost, long hiCost)\n {\n if (abs(lo-hi)<=1) {\n //out.println(\"first \"+lo+\" second \"+hi+\" low clost \"+lowCost+\" hi cost \"+hiCost);\n if (lo>1) {\n long c=calc(lo-1);\n if (c lowCost )\n return cost(lo, mid, lowCost, midCost);\n else {\n //out.println(\"bad mid cost \"+midCost+\" low clost \"+lowCost+\" hi cost \"+hiCost);\n return midCost;\n }\n }\n AmusementPark(int a, int p, int c1, int c2)\n {\n adult = a;\n pupil = p;\n n = a+p;\n this.c1 = c1;\n this.c2 = c2;\n long cost1 = calc(1);\n long cost2 = calc(a);\n if (cost1>cost2)\n cost1=cost(a, 1, cost2, cost1);\n else if (cost1 primes = getPrimes(sum);\n\t\tint[] colors = new int[n];\n\t\tboolean isColored = false;\n\t\tif (primes.contains(sum)) isColored = true;\n\t\tif (!isColored) {\n\t\t\tfor (Integer prime: primes) {\n\t\t\t\tif (primes.contains(sum-prime)) {\n\t\t\t\t\tint left = prime;\n\t\t\t\t\tfor (int i = n; i>= 1; i--) {\n\t\t\t\t\t\tif (i <= left) {\n\t\t\t\t\t\t\tcolors[i-1] = 1;\n\t\t\t\t\t\t\tleft-=i;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tisColored = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (!isColored) {\n\t\t\tfor (Integer prime: primes) {\n\t\t\t\tif (primes.contains(sum-prime-3)) {\n\t\t\t\t\tcolors[2]=2;\n\t\t\t\t\tint left = prime;\n\t\t\t\t\tfor (int i = n; i>= 1; i--) {\n\t\t\t\t\t\tif (i == 2) continue;\n\t\t\t\t\t\tif (i <= left) {\n\t\t\t\t\t\t\tcolors[i-1] = 1;\n\t\t\t\t\t\t\tleft-=i;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (int c: colors) {\n\t\t\tout.print((c+1) + \" \");\n\t\t}\n\t\tout.println();\n\t}\n\n\tprivate static HashSet getPrimes(int sum) {\n\t\tint[] p = new int[sum+1];\n\t\tfor (int i = 2; i < p.length; i++) {\n\t\t\tif (p[i] == 1) continue;\n\t\t\tfor (int j = i+i; j < p.length; j+=i) {\n\t\t\t\tp[j] = 1;\n\t\t\t}\n\t\t}\n\t\tHashSet result = new HashSet<>(1000000);\n\t\tfor (int i = 2; i < p.length; i++) {\n\t\t\tif (p[i] == 1) continue;\n\t\t\tresult.add(i);\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\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\tPrimeProblem solver = new PrimeProblem();\n\t\tsolver.solve(in, out);\n\t\tout.close();\n\t}\n\n\tstatic class InputReader {\n\t\tpublic BufferedReader reader;\n\t\tpublic StringTokenizer tokenizer;\n\n\t\tpublic InputReader(InputStream stream) {\n\t\t\treader = new BufferedReader(new InputStreamReader(stream), 32768);\n\t\t\ttokenizer = null;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t}\n\t\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "1a10cd1a56b00d96eb3d826db19175aa", "src_uid": "94ef0d901f21e1945849fd5bfc2d1449", "difficulty": 2200.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.BitSet;\nimport java.util.Calendar;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.SortedSet;\nimport java.util.Stack;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\n/**\n * #\n * \n * @author pttrung\n */\npublic class D_Round_173_Div2 {\n\n\tpublic static long MOD = 1000000007;\n\n\tpublic static void main(String[] args) throws FileNotFoundException {\n\t\t// PrintWriter out = new PrintWriter(new FileOutputStream(new File(\n\t\t// \"output.txt\")));\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tScanner in = new Scanner();\n\t\tint n = in.nextInt();\n\t\tint[] data = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tdata[i] = in.nextInt();\n\t\t}\n\t\tArrays.sort(data);\n\t\tif (n == 1) {\n\t\t\tif (data[0] == 0) {\n\t\t\t\tout.println(\"BitAryo\");\n\t\t\t} else {\n\t\t\t\tout.println(\"BitLGM\");\n\t\t\t}\n\t\t} else if (n == 2) {\n\t\t\tint[][][] dp = new int[2][data[0] + 1][data[1] + 1];\n\t\t\tfor (int[][] a : dp) {\n\t\t\t\tfor (int[] b : a) {\n\t\t\t\t\tArrays.fill(b, -1);\n\t\t\t\t}\n\t\t\t}\n\t\t\tint r = cal(0, data[0], data[1], dp);\n\t\t\tif (r == 0) {\n\t\t\t\tout.println(\"BitLGM\");\n\t\t\t} else {\n\t\t\t\tout.println(\"BitAryo\");\n\t\t\t}\n\t\t} else {\n\t\t\tint[][][][] dp = new int[2][data[0] + 1][data[1] + 1][data[2] + 1];\n\t\t\tfor (int[][][] a : dp) {\n\t\t\t\tfor (int[][] b : a) {\n\t\t\t\t\tfor (int[] c : b)\n\t\t\t\t\t\tArrays.fill(c, -1);\n\t\t\t\t}\n\t\t\t}\n\t\t\tint r = cal2(0, data[0], data[1], data[2], dp);\n\t\t\tif (r == 0) {\n\t\t\t\tout.println(\"BitLGM\");\n\t\t\t} else {\n\t\t\t\tout.println(\"BitAryo\");\n\t\t\t}\n\t\t}\n\t\tout.close();\n\t}\n\n\tstatic int cal(int index, int a, int b, int[][][] dp) {\n\t\tif (a == 0 && b == 0) {\n\t\t\treturn 1 - index;\n\t\t}\n\t\tif (dp[index][a][b] != -1) {\n\t\t\treturn dp[index][a][b];\n\t\t}\n\t\tint result = 1 - index;\n\t\tfor (int i = 1; i <= a; i++) {\n\t\t\tint x = Math.min(a - i, b);\n\t\t\tint y = Math.max(a - i, b);\n\t\t\tint v = cal(1 - index, x, y, dp);\n\t\t\tif (v == index) {\n\t\t\t\tresult = index;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (result != index) {\n\t\t\tfor (int i = 1; i <= b; i++) {\n\t\t\t\tint x = Math.min(b - i, a);\n\t\t\t\tint y = Math.max(b - i, a);\n\t\t\t\tint v = cal(1 - index, x, y, dp);\n\t\t\t\tif (v == index) {\n\t\t\t\t\tresult = index;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (result != index) {\n\t\t\t\tfor (int i = 1; i <= Math.min(a, b); i++) {\n\t\t\t\t\tint x = Math.min(b - i, a - i);\n\t\t\t\t\tint y = Math.max(b - i, a - i);\n\t\t\t\t\tint v = cal(1 - index, x, y, dp);\n\t\t\t\t\tif (v == index) {\n\t\t\t\t\t\tresult = index;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn dp[index][a][b] = result;\n\t}\n\n\tstatic int cal2(int index, int a, int b, int c, int[][][][] dp) {\n\n\t\tif (a == 0) {\n\t\t\tif ((b ^ c) == 0)\n\t\t\t\treturn 1 - index;\n\t\t\treturn index;\n\t\t}\n\t\tif (dp[index][a][b][c] != -1) {\n\t\t\treturn dp[index][a][b][c];\n\t\t}\n\t\tint result = 1 - index;\n\t\tif ((a ^ b ^ c) != 0) {\n\t\t\tresult = index;\n\t\t}\n\n\t\tif (result != index) {\n\t\t\tfor (int i = 1; i <= a; i++) {\n\n\t\t\t\tint v = cal2(1 - index, a - i, b - i, c - i, dp);\n\t\t\t\tif (v == index) {\n\t\t\t\t\tresult = index;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn dp[index][a][b][c] = result;\n\t}\n\n\tpublic static int[] KMP(String val) {\n\t\tint i = 0;\n\t\tint j = -1;\n\t\tint[] result = new int[val.length() + 1];\n\t\tresult[0] = -1;\n\t\twhile (i < val.length()) {\n\t\t\twhile (j >= 0 && val.charAt(j) != val.charAt(i)) {\n\t\t\t\tj = result[j];\n\t\t\t}\n\t\t\tj++;\n\t\t\ti++;\n\t\t\tresult[i] = j;\n\t\t}\n\t\treturn result;\n\n\t}\n\n\tpublic static boolean nextPer(int[] data) {\n\t\tint i = data.length - 1;\n\t\twhile (i > 0 && data[i] < data[i - 1]) {\n\t\t\ti--;\n\t\t}\n\t\tif (i == 0) {\n\t\t\treturn false;\n\t\t}\n\t\tint j = data.length - 1;\n\t\twhile (data[j] < data[i - 1]) {\n\t\t\tj--;\n\t\t}\n\t\tint temp = data[i - 1];\n\t\tdata[i - 1] = data[j];\n\t\tdata[j] = temp;\n\t\tArrays.sort(data, i, data.length);\n\t\treturn true;\n\t}\n\n\tpublic static int digit(long n) {\n\t\tint result = 0;\n\t\twhile (n > 0) {\n\t\t\tn /= 10;\n\t\t\tresult++;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static double dist(long a, long b, long x, long y) {\n\t\tdouble val = (b - a) * (b - a) + (x - y) * (x - y);\n\t\tval = Math.sqrt(val);\n\t\tdouble other = x * x + a * a;\n\t\tother = Math.sqrt(other);\n\t\treturn val + other;\n\n\t}\n\n\tpublic static class Point implements Comparable {\n\n\t\tint x, y;\n\n\t\tpublic Point(int start, int end) {\n\t\t\tthis.x = start;\n\t\t\tthis.y = end;\n\t\t}\n\n\t\t@Override\n\t\tpublic int hashCode() {\n\t\t\tint hash = 5;\n\t\t\thash = 47 * hash + this.x;\n\t\t\thash = 47 * hash + this.y;\n\t\t\treturn hash;\n\t\t}\n\n\t\t@Override\n\t\tpublic boolean equals(Object obj) {\n\t\t\tif (obj == null) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (getClass() != obj.getClass()) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tfinal Point other = (Point) obj;\n\t\t\tif (this.x != other.x) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (this.y != other.y) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Point o) {\n\t\t\treturn x - o.x;\n\t\t}\n\t}\n\n\tpublic static class FT {\n\n\t\tlong[] data;\n\n\t\tFT(int n) {\n\t\t\tdata = new long[n];\n\t\t}\n\n\t\tpublic void update(int index, long value) {\n\t\t\twhile (index < data.length) {\n\t\t\t\tdata[index] += value;\n\t\t\t\tindex += (index & (-index));\n\t\t\t}\n\t\t}\n\n\t\tpublic long get(int index) {\n\t\t\tlong result = 0;\n\t\t\twhile (index > 0) {\n\t\t\t\tresult += data[index];\n\t\t\t\tindex -= (index & (-index));\n\t\t\t}\n\t\t\treturn result;\n\n\t\t}\n\t}\n\n\tpublic static long gcd(long a, long b) {\n\t\tif (b == 0) {\n\t\t\treturn a;\n\t\t}\n\t\treturn gcd(b, a % b);\n\t}\n\n\tpublic static long pow(long a, long b) {\n\t\tif (b == 0) {\n\t\t\treturn 1;\n\t\t}\n\t\tif (b == 1) {\n\t\t\treturn a;\n\t\t}\n\t\tlong val = pow(a, b / 2);\n\t\tif (b % 2 == 0) {\n\t\t\treturn val * val % MOD;\n\t\t} else {\n\t\t\treturn val * (val * a % MOD) % MOD;\n\n\t\t}\n\t}\n\n\tstatic class Scanner {\n\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic Scanner() throws FileNotFoundException {\n\t\t\t// System.setOut(new PrintStream(new\n\t\t\t// BufferedOutputStream(System.out), true));\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t// br = new BufferedReader(new InputStreamReader(new\n\t\t\t// FileInputStream(new File(\"input.txt\"))));\n\t\t}\n\n\t\tpublic String next() {\n\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\tthrow new RuntimeException();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tst = null;\n\t\t\ttry {\n\t\t\t\treturn br.readLine();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t}\n\n\t\tpublic boolean endLine() {\n\t\t\ttry {\n\t\t\t\tString next = br.readLine();\n\t\t\t\twhile (next != null && next.trim().isEmpty()) {\n\t\t\t\t\tnext = br.readLine();\n\t\t\t\t}\n\t\t\t\tif (next == null) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tst = new StringTokenizer(next);\n\t\t\t\treturn st.hasMoreTokens();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1d2ce6583593257957bae35cfe3e26b5", "src_uid": "7a33b4f94082c7ef80d7e87b58497fa7", "difficulty": 2100.0} {"lang": "Java 6", "source_code": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.InputMismatchException;\n\n/**\n * @author Egor Kulikov (egor@egork.net)\n * Created on 14.03.2010\n */\npublic class TaskE implements Runnable {\n\tprivate InputReader in;\n\tprivate PrintWriter out;\n\tprivate static final long MOD = 1000000009;\n\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new TaskE()).start();\n//\t\tnew Template().run();\n\t}\n\n\tpublic TaskE() {\n//\t\tString id = getClass().getName().toLowerCase();\n//\t\ttry {\n//\t\t\tSystem.setIn(new FileInputStream(id + \".in\"));\n//\t\t\tSystem.setOut(new PrintStream(new FileOutputStream(id + \".out\")));\n//\t\t\tSystem.setIn(new FileInputStream(\"input.txt\"));\n//\t\t\tSystem.setOut(new PrintStream(new FileOutputStream(\"output.txt\")));\n//\t\t} catch (FileNotFoundException e) {\n//\t\t\tthrow new RuntimeException();\n//\t\t}\n\t\tin = new InputReader(System.in);\n\t\tout = new PrintWriter(System.out);\n\t}\n\n\tpublic void run() {\n// int numTests = in.readInt();\n// for (int testNumber = 0; testNumber < numTests; testNumber++) {\n//\t\t\tout.print(\"Case #\" + (testNumber + 1) + \": \");\n// }\n\t\tint n = in.readInt();\n\t\tlong[] d = new long[n + 1];\n\t\td[0] = 1;\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\td[i] = (2 * d[i - 1]) % MOD;\n\t\tlong[] c = new long[n + 1];\n\t\tc[0] = 1;\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\tc[i] = (c[i - 1] + 2 * d[i]) % MOD;\n\t\tlong[] b = new long[n + 1];\n\t\tb[0] = 1;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tif (i % 2 == 1 && i > 1)\n\t\t\t\tb[i] = (b[i - 1] * c[i / 2 - 1]) % MOD;\n\t\t\telse\n\t\t\t\tb[i] = b[i - 1];\n\t\t}\n\t\tlong[] a = new long[n + 1];\n\t\ta[1] = 0;\n\t\tfor (int i = 2; i <= n; i++)\n\t\t\ta[i] = (a[i - 1] + 2 * b[i - 1]) % MOD;\n\t\tlong ans = (a[n] * a[n] + 1) % MOD;\n\t\tans = (ans * 2) % MOD;\n\t\tout.println(ans);\n\t\tout.close();\n\t}\n\n\tprivate static class InputReader {\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[1000];\n\t\tprivate int curChar, numChars;\n\n\t\tpublic InputReader(InputStream stream) {\n\t\t\tthis.stream = stream;\n\t\t}\n\n\t\tprivate int read() {\n\t\t\tif (numChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= numChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (numChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\t\tpublic int readInt() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic long readLong() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic String readString() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuffer res = new StringBuffer();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tprivate boolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tprivate String readLine0() {\n\t\t\tStringBuffer buf = new StringBuffer();\n\t\t\tint c = read();\n\t\t\twhile (c != '\\n' && c != -1) {\n\t\t\t\tbuf.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\treturn buf.toString();\n\t\t}\n\n\t\tpublic String readLine() {\n\t\t\tString s = readLine0();\n\t\t\twhile (s.trim().length() == 0)\n\t\t\t\ts = readLine0();\n\t\t\treturn s;\n\t\t}\n\n\t\tpublic String readLine(boolean ignoreEmptyLines) {\n\t\t\tif (ignoreEmptyLines)\n\t\t\t\treturn readLine();\n\t\t\telse\n\t\t\t\treturn readLine0();\n\t\t}\n\n\t\tpublic BigInteger readBigInteger() {\n\t\t\ttry {\n\t\t\t\treturn new BigInteger(readString());\n\t\t\t} catch (NumberFormatException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t}\n\n\t\tpublic char readCharacter() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\treturn (char) c;\n\t\t}\n\n\t\tpublic double readDouble() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tdouble res = 0;\n\t\t\twhile (!isSpaceChar(c) && c != '.') {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tif (c == '.') {\n\t\t\t\tc = read();\n\t\t\t\tdouble m = 1;\n\t\t\t\twhile (!isSpaceChar(c)) {\n\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\tm /= 10;\n\t\t\t\t\tres += (c - '0') * m;\n\t\t\t\t\tc = read();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res * sgn;\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6b4bb6621330c018e33e021e6fbb9a04", "src_uid": "dbcb1077e7421554ba5d69b64d22c937", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.StringTokenizer;\n\npublic class Main {\n public void solve() {\n int a = ni(), b = ni(), c = ni(), l = ni();\n int x, y ,z;\n if ((a > b) && (a > c)) {\n x = a;\n if (b > c) {\n y = b;\n z = c;\n } else {\n y = c;\n z = b;\n }\n } else if (b > c) {\n x = b;\n if (a > c) {\n y = a;\n z = c;\n } else {\n y = c;\n z = a;\n }\n } else {\n x = c;\n if (b > a) {\n y = b;\n z = a;\n } else {\n y = a;\n z = b;\n }\n }\n\n long ans = 0;\n for (int i = x; l - (i - x) - (Math.max(0, i - (y + z) + 1)) >= 0; i++) {\n for (int j = y; l - (i - x) - (j - y) - (Math.max(0, j - (i + z) + 1)) >= 0; j++) {\n// System.out.println(i + \" \" + j + \" \" + (l - (i - x) - (j - y)));\n int max = (i + j - 1);\n int min = Math.abs(i - j) + 1;\n// System.out.println(\"min: \" + min + \" max: \" + max);\n int steps = l - (i - x) - (j - y) - Math.max(0, min - z);\n max = Math.min(max, min + steps);\n ans += Math.max(0, max - min + 1);\n// System.out.println(Math.max(0, max - min + 1));\n }\n }\n write(ans + \"\\n\");\n }\n\n\n\n\n\n public static void main(String[] args){\n Main m = new Main();\n m.solve();\n try {\n m.writer.close();\n } catch (IOException e) {};\n }\n BufferedReader reader;\n BufferedWriter writer;\n StringTokenizer tokenizer;\n public Main() {\n reader = new BufferedReader(new InputStreamReader(System.in));\n writer = new BufferedWriter(new OutputStreamWriter(System.out));\n }\n int ni() {\n return Integer.parseInt(n());\n }\n String n() {\n if (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {}\n }\n return tokenizer.nextToken();\n }\n void write(String s) {\n try {\n writer.write(s);\n } catch(IOException e) {};\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a8dd04c0da7e11c332745fb507d548a3", "src_uid": "185ff90a8b0ae0e2b75605f772589410", "difficulty": 2100.0} {"lang": "Java 7", "source_code": "import static java.lang.Math.max;\nimport static java.lang.System.arraycopy;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class B {\n\n static final int MOD = 1000000007;\n\n static int[][] color;\n static int r, c;\n static int colors;\n\n static int[] possibleMask;\n\n static int[][] haveLater;\n\n static long answer;\n\n static long[] factorial = new long[15];\n static {\n factorial[0] = 1;\n for (int i = 0; i < factorial.length - 1; i++) {\n factorial[i + 1] = factorial[i] * (i + 1);\n }\n }\n\n static int[] BITCOUNT;\n static {\n BITCOUNT = new int[1 << 12];\n for (int i = 0; i < BITCOUNT.length; i++) {\n BITCOUNT[i] = Integer.bitCount(i);\n }\n }\n\n static int allEquivalent;\n\n static void go(int sum, int col) {\n if (sum == r + c - 1) {\n int leftE = BITCOUNT[equivalentColorsMask];\n answer += factorial[allEquivalent] / factorial[leftE];\n return;\n }\n if (col == sum + 1 || col == c) {\n if (col < c) {\n possibleMask[col] = (1 << colors) - 1;\n }\n int[] wasMask = possibleMask.clone();\n for (int i = c - 1; i > 0; --i) {\n possibleMask[i] &= possibleMask[i - 1];\n }\n\n for (int i = c - 1; i >= 0; --i) {\n int row = sum - i;\n if (row < 0 || row >= r) {\n continue;\n }\n possibleMask[i] &= ~(1 << color[row][i]);\n if (i < c - 1) {\n possibleMask[i + 1] &= ~(1 << color[row][i]);\n }\n }\n\n // if (col < c) {\n // possibleMask[col] = possibleMask[col - 1];\n // }\n go(sum + 1, max(0, sum + 1 - (r - 1)));\n arraycopy(wasMask, 0, possibleMask, 0, c);\n return;\n // possibleMask = t;\n }\n int good = possibleMask[col] & ~haveLater[sum - col][col];\n\n int checkEquivalent = possibleMask[col] & equivalentColorsMask;\n int okCheckEquivalent = checkEquivalent == 0 ? -1 : Integer\n .numberOfTrailingZeros(checkEquivalent);\n\n int wasEquivalent = equivalentColorsMask;\n for (int i = 0; i < colors; i++) {\n if ((good & (1 << i)) == 0) {\n continue;\n }\n if (color[sum - col][col] >= 0 && color[sum - col][col] != i) {\n continue;\n }\n\n if (((1 << i) & checkEquivalent) != 0 && i != okCheckEquivalent) {\n continue;\n }\n\n int was = color[sum - col][col];\n color[sum - col][col] = i;\n\n equivalentColorsMask &= ~(1 << i);\n\n if (BITCOUNT[possibleMask[col]] >= (r + c - 2 - sum)) {\n go(sum, col + 1);\n }\n equivalentColorsMask = wasEquivalent;\n\n color[sum - col][col] = was;\n }\n }\n\n private static boolean check() {\n for (int i = 0; i < r; i++) {\n for (int j = 0; j < c; j++) {\n for (int a = i; a < r; a++) {\n for (int b = j; b < c; b++) {\n if (a == i && b == j) {\n continue;\n }\n if (color[a][b] == color[i][j]) {\n return false;\n }\n }\n }\n }\n }\n return true;\n }\n\n static int equivalentColorsMask;\n\n static void solve() throws IOException {\n r = nextInt();\n c = nextInt();\n colors = nextInt();\n int length = r + c - 1;\n if (length > colors) {\n out.println(0);\n return;\n }\n color = new int[r][c];\n for (int i = 0; i < r; i++) {\n for (int j = 0; j < c; j++) {\n color[i][j] = nextInt() - 1;\n }\n }\n // long time = currentTimeMillis();\n if (r < c) {\n swapRC();\n }\n answer = 0;\n possibleMask = new int[c];\n possibleMask[0] = (1 << colors) - 1;\n haveLater = new int[r][c];\n for (int i = 0; i < r; i++) {\n for (int j = 0; j < c; j++) {\n haveLater[i][j] = 0;\n for (int a = i; a < r; a++) {\n for (int b = j; b < c; b++) {\n if (a == i && b == j) {\n continue;\n }\n if (color[a][b] >= 0) {\n haveLater[i][j] |= (1 << color[a][b]);\n }\n }\n }\n }\n }\n equivalentColorsMask = ~(haveLater[0][0]);\n if (color[0][0] >= 0) {\n equivalentColorsMask &= ~(1 << color[0][0]);\n }\n equivalentColorsMask &= (1 << colors) - 1;\n allEquivalent = Integer.bitCount(equivalentColorsMask);\n go(0, 0);\n long ans = answer;\n out.println(ans % MOD);\n }\n\n private static void swapRC() {\n int t = r;\n r = c;\n c = t;\n int[][] newCol = new int[r][c];\n for (int i = 0; i < r; i++) {\n for (int j = 0; j < c; j++) {\n newCol[i][j] = color[j][i];\n }\n }\n color = newCol;\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 File file = new File(\"b.in\");\n if (file.exists() && file.canRead()) {\n input = new FileInputStream(file);\n }\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", "compilation_error": false, "code_uid": "79d1763216eae819eaf356376c130732", "src_uid": "5bb21f49d976cfa16a239593a95c53b5", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.*; import java.util.*;\npublic class Graph {\n public static class Pair{\n int vtx; int val;\n public Pair(int a, int b){\n this.vtx=a; this.val=b;\n }\n }\n public static void main(String[] args) throws IOException {\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer st=new StringTokenizer(br.readLine());\n int N=Integer.parseInt(st.nextToken());\n int M=Integer.parseInt(st.nextToken());\n ArrayList arl[]=new ArrayList[N];\n for (int i = 0; i < N; i++) {\n arl[i]=new ArrayList<>();\n }\n int a,b,vv;\n for (int i = 0; i < M; i++) {\n st=new StringTokenizer(br.readLine());\n a=Integer.parseInt(st.nextToken())-1;\n b=Integer.parseInt(st.nextToken())-1;\n vv=Integer.parseInt(st.nextToken());\n arl[a].add(new Pair(b,2*vv)); arl[b].add(new Pair(a,2*vv));\n }\n boolean[] vis=new boolean[N];\n \n int[] m=new int[N];\n int[] c=new int[N];\n int done=0; int pt=0;\n while(done qu=new LinkedList<>();\n qu.add(pt); vis[pt]=true; done++;\n Queue qu2=new LinkedList<>();//Tracks all vertices in the queue\n qu2.add(pt); boolean fix=false;\n while(!qu.isEmpty()){\n int v=qu.poll(); \n for (Pair p : arl[v]) {\n if(!vis[p.vtx]){\n vis[p.vtx]=true; qu.add(p.vtx); \n if(!fix){\n qu2.add(p.vtx);\n }\n m[p.vtx]=-m[v]; c[p.vtx]=p.val-c[v]; done++;\n }else{\n if(m[p.vtx]==m[v] && m[v]!=0){\n //m[p.vtx]x+c[p.vtx]+m[v]x+c[v] is known\n int x=(p.val-c[p.vtx]-c[v])/(2*m[p.vtx]); fix=true;\n \n for(int vtx: qu2){\n \n c[vtx]+=m[vtx]*x; m[vtx]=0;\n }\n }else if(m[p.vtx]+m[v]==0){//m[v]=0\n if(c[p.vtx]+c[v]!=p.val){\n System.out.println(\"NO\"); return;\n }\n }\n }\n }\n //System.out.println(Arrays.toString(m));\n //System.out.println(Arrays.toString(c));\n }\n \n if(m[pt]!=0){//This component is not fixed\n ArrayList arl2=new ArrayList<>();\n Queue qu3=new LinkedList<>();\n for (int i : qu2) {\n if(m[i]<0){\n m[i]=-m[i]; c[i]=-c[i]; qu3.add(i);\n }\n arl2.add(c[i]);\n }\n Collections.sort(arl2);\n int med=arl2.get(arl2.size()/2);\n for (int i : qu2) {\n c[i]-=med;\n \n }\n while(!qu3.isEmpty()){\n int i=qu3.poll();\n c[i]=-c[i];\n }\n }\n \n }\n System.out.println(\"YES\");\n StringBuilder sb=new StringBuilder();\n for (int i = 0; i < N; i++) {\n sb.append((double)c[i]/2).append(\" \");\n }\n System.out.println(sb.toString());\n }\n \n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "43d5084c844cdeaac2331fbad577dc71", "src_uid": "791cbe2700b11e9dd9a442de3ef913f8", "difficulty": 2100.0} {"lang": "Java 7", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n/**\n * 6\n * 1 0\n * 0 0\n * 0 0\n * 1 1\n * 0 1\n * 1 1\n *\n * @author pttrung\n */\npublic class B {\n\n public static long mod = 1000000007;\n public static long[][][] dp;\n static int[] x = {0, 0, 1, -1, 1, -1, 1, -1};\n static int[] y = {1, -1, 0, 0, 1, -1, -1, 1};\n public static void main(String[] args) throws FileNotFoundException {\n PrintWriter out;\n\n Scanner in = new Scanner();\n //out = new PrintWriter(new FileOutputStream(new File(\"output.txt\")));\n out = new PrintWriter(System.out);\n int[][] r = new int[2][2];\n int[] wk = new int[2];\n int[] bk = new int[2];\n for (int i = 0; i < 2; i++) {\n String line = in.next();\n r[i][0] = line.charAt(0) - 'a';\n r[i][1] = line.charAt(1) - '1';\n }\n String a = in.next();\n wk[0] = a.charAt(0) - 'a';\n wk[1] = a.charAt(1) - '1';\n a = in.next();\n bk[0] = a.charAt(0) - 'a';\n bk[1] = a.charAt(1) - '1';\n\n int[][] map = new int[8][8];\n map[r[0][0]][r[0][1]] = -1;\n map[r[1][0]][r[1][1]] = -1;\n map[wk[0]][wk[1]] = -1;\n update(r[0][0], r[0][1], map);\n update(r[1][0], r[1][1], map);\n updateK(wk[0], wk[1], map);\n if (map[bk[0]][bk[1]] != 1) {\n out.println(\"OTHER\");\n } else {\n boolean found = false;\n for(int k = 0; k < x.length; k++){\n int i = x[k] + bk[0];\n int j = y[k] + bk[1];\n if(map[i][j] != 1){\n found = true;\n break;\n }\n }\n if(!found){\n out.println(\"CHECKMATE\");\n }else{\n out.println(\"OTHER\");\n }\n }\n\n\n out.close();\n }\n\n public static void updateK(int a, int b, int[][] map) {\n \n for (int k = 0; k < x.length; k++) {\n int i = a + x[k];\n int j = b + y[k];\n if (i >= 0 && i < 8 && j >= 0 && j < 8) {\n if (map[i][j] == 0) {\n map[i][j] = 1;\n }\n }\n }\n }\n\n public static void update(int a, int b, int[][] map) {\n for (int i = b + 1; i < 8; i++) {\n if (map[a][i] == 0) {\n map[a][i] = 1;\n } else {\n break;\n }\n }\n for (int i = b - 1; i >= 0; i--) {\n if (map[a][i] == 0) {\n map[a][i] = 1;\n } else {\n break;\n }\n }\n for (int i = a + 1; i < 8; i++) {\n if (map[i][b] == 0) {\n map[i][b] = 1;\n } else {\n break;\n }\n }\n for (int i = a - 1; i >= 0; i--) {\n if (map[i][b] == 0) {\n map[i][b] = 1;\n } else {\n break;\n }\n }\n\n }\n\n public static long gcd(long a, long b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n public static Line getLine(Point a, Point b) {\n int c = (a.x - b.x);\n int d = (a.y - b.y);\n if (c == 0) {\n return new Line(1, 0, -a.x);\n } else if (d == 0) {\n return new Line(0, 1, -a.y);\n } else {\n double rate = (double) (-d) / c;\n\n double other = ((double) rate * a.x) + a.y;\n //System.out.println(a + \"|\" + b + \": \" + rate + \" \" + other);\n return new Line(rate, 1, -other);\n }\n }\n\n public static class Line {\n\n double a, b, c;\n\n public Line(double a, double b, double c) {\n this.a = a;\n this.b = b;\n this.c = c;\n }\n\n @Override\n public int hashCode() {\n int hash = 7;\n hash = 47 * hash + (int) (Double.doubleToLongBits(this.a) ^ (Double.doubleToLongBits(this.a) >>> 32));\n hash = 47 * hash + (int) (Double.doubleToLongBits(this.b) ^ (Double.doubleToLongBits(this.b) >>> 32));\n hash = 47 * hash + (int) (Double.doubleToLongBits(this.c) ^ (Double.doubleToLongBits(this.c) >>> 32));\n return hash;\n }\n\n @Override\n public boolean equals(Object obj) {\n if (obj == null) {\n return false;\n }\n if (getClass() != obj.getClass()) {\n return false;\n }\n final Line other = (Line) obj;\n if (Double.doubleToLongBits(this.a) != Double.doubleToLongBits(other.a)) {\n return false;\n }\n if (Double.doubleToLongBits(this.b) != Double.doubleToLongBits(other.b)) {\n return false;\n }\n if (Double.doubleToLongBits(this.c) != Double.doubleToLongBits(other.c)) {\n return false;\n }\n return true;\n }\n\n @Override\n public String toString() {\n return a + \" \" + b + \" \" + c;\n }\n }\n\n static class FT {\n\n int[] data;\n\n FT(int n) {\n data = new int[n];\n }\n\n void update(int index, int val) {\n // System.out.println(\"UPDATE INDEX \" + index);\n while (index < data.length) {\n data[index] += val;\n index += index & (-index);\n\n // System.out.println(\"NEXT \" +index);\n }\n }\n\n int get(int index) {\n // System.out.println(\"GET INDEX \" + index);\n int result = 0;\n while (index > 0) {\n result += data[index];\n index -= index & (-index);\n // System.out.println(\"BACK \" + index);\n }\n return result;\n }\n }\n\n public static double dist(Point a, Point b) {\n double val = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);\n return Math.sqrt(val);\n }\n\n public static class Point {\n\n int x, y;\n\n public Point(int x, int y) {\n this.x = x;\n this.y = y;\n }\n\n @Override\n public String toString() {\n return x + \" \" + y;\n }\n }\n\n public static boolean nextPer(int[] data) {\n int i = data.length - 1;\n while (i > 0 && data[i] < data[i - 1]) {\n i--;\n }\n if (i == 0) {\n return false;\n }\n int j = data.length - 1;\n while (data[j] < data[i - 1]) {\n j--;\n }\n int temp = data[i - 1];\n data[i - 1] = data[j];\n data[j] = temp;\n Arrays.sort(data, i, data.length);\n return true;\n }\n\n public static long pow(int a, int b) {\n if (b == 0) {\n return 1;\n }\n if (b == 1) {\n return a;\n }\n long val = pow(a, b / 2);\n if (b % 2 == 0) {\n return val * val;\n } else {\n return val * val * a;\n }\n }\n\n public static long lcm(long a, long b) {\n return a * b / gcd(a, b);\n }\n\n static class Scanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n public Scanner() throws FileNotFoundException {\n // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));\n br = new BufferedReader(new InputStreamReader(System.in));\n // br = new BufferedReader(new FileReader(new File(\"output.txt\")));\n }\n\n public String next() {\n\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n return st.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public String nextLine() {\n st = null;\n try {\n return br.readLine();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n\n public boolean endLine() {\n try {\n String next = br.readLine();\n while (next != null && next.trim().isEmpty()) {\n next = br.readLine();\n }\n if (next == null) {\n return true;\n }\n st = new StringTokenizer(next);\n return st.hasMoreTokens();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "906a91f503251b76b11f2e0ef52bc133", "src_uid": "5d05af36c7ccb0cd26a4ab45966b28a3", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n MyScan in = new MyScan(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskF solver = new TaskF();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskF {\n public void solve(int testNumber, MyScan in, PrintWriter out) {\n int n = in.nextInt();\n String pos = in.next();\n int[][] auto = toAuto(pos);\n\n long[][][] state = new long[2 * n + 1][2 * n + 1][pos.length() + 1];\n long[][] ansFull = new long[2 * n + 1][2 * n + 1];\n\n\n for (int s = 0; s < n; s++) {\n long[][] starts = new long[2 * n + 1][2 * n + 1];\n starts[0][s] = 1;\n for (int len = 0; len < 2 * n; len++) {\n for (int gand = 0; gand <= n; gand++) {\n if (gand > 0) {\n starts[len + 1][gand - 1] = (starts[len + 1][gand - 1] + starts[len][gand]) % Util._m;\n }\n starts[len + 1][gand + 1] = (starts[len + 1][gand + 1] + starts[len][gand]) % Util._m;\n }\n }\n for (int r = 0; r <= 2 * n; r++) {\n ansFull[r][s] = starts[r][0];\n }\n\n }\n\n state[0][0][0] = 1;\n long res = 0;\n for (int px = 0; px < 2 * n; px++) {\n for (int l = 0; l < 2 * n; l++) {\n for (int s = 0; s < pos.length(); s++) {\n int next0 = auto[s][0];\n int next1 = auto[s][1];\n // (\n state[px + 1][l + 1][next0] = (state[px + 1][l + 1][next0] + state[px][l][s]) % Util._m;\n // )\n if (l > 0)\n state[px + 1][l - 1][next1] = (state[px + 1][l - 1][next1] + state[px][l][s]) % Util._m;\n }\n }\n for (int l = 0; l < 2 * n; l++) {\n int l2 = 2 * n - px - 1;\n int n2 = l;\n if (state[px + 1][l][pos.length()] == 0 || n2 > l2) continue;\n res += state[px + 1][l][pos.length()] * ansFull[l2][n2] % Util._m;\n }\n }\n out.println(res % Util._m);\n }\n\n private int[][] toAuto(String pos) {\n int[][] r = new int[pos.length()][2];\n\n String chars = \"()\";\n for (int t = 0; t < pos.length(); t++) {\n for (int i = 0; i < chars.length(); i++) {\n char ch = chars.charAt(i);\n if (pos.charAt(t) == ch) {\n r[t][i] = t + 1;\n } else {\n String tar = pos.substring(0, t) + ch;\n for (int l = t; l > 0; l--) {\n if (tar.endsWith(pos.substring(0, l))) {\n r[t][i] = l;\n break;\n }\n }\n }\n }\n }\n\n return r;\n }\n\n }\n\n static class MyScan {\n private final InputStream in;\n private byte[] inbuf = new byte[1024];\n public int lenbuf = 0;\n public int ptrbuf = 0;\n\n public MyScan(InputStream in) {\n this.in = in;\n }\n\n private int readByte() {\n if (lenbuf == -1) throw new InputMismatchException();\n if (ptrbuf >= lenbuf) {\n ptrbuf = 0;\n try {\n lenbuf = in.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 public boolean isSpaceChar(int c) {\n return !(c >= 33 && c <= 126);\n }\n\n public int skip() {\n int b;\n while ((b = readByte()) != -1 && isSpaceChar(b)) ;\n return b;\n }\n\n public String next() {\n int b = skip();\n StringBuilder sb = new StringBuilder();\n while (!(isSpaceChar(b))) {\n sb.appendCodePoint(b);\n b = readByte();\n }\n return sb.toString();\n }\n\n public int nextInt() {\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 }\n\n static class Util {\n public static final long M07 = 1000_000_007;\n public static final long _m = M07;\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fdcaed45c50147be6b8db55f5695b749", "src_uid": "590a49a7af0eb83376ed911ed488d7e5", "difficulty": 2300.0} {"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.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n}\n\nclass TaskC {\n static final int BUBEN = 30;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int m = in.nextInt();\n int[] a = new int[n];\n int[] b = new int[n];\n for (int i = 0; i < n; ++i) {\n a[i] = in.nextInt();\n }\n for (int i = 0; i < n; ++i) {\n b[i] = in.nextInt();\n }\n int[][] matr = new int[BUBEN][BUBEN];\n for (int[] x : matr)\n Arrays.fill(x, Integer.MAX_VALUE);\n for (int i = 0; i < BUBEN; ++i) matr[i][i] = 0;\n for (int j = 0; j < 2; ++j) {\n int[][] cm = new int[BUBEN][BUBEN];\n for (int[] x : cm)\n Arrays.fill(x, Integer.MAX_VALUE);\n for (int i = 0; i + 1 < BUBEN; ++i) {\n cm[i + 1][i] = b[j];\n cm[i][i + 1] = a[j];\n }\n matr = mul(matr, cm);\n }\n matr = pow(matr, m*n/2);\n out.println(matr[0][0]);\n }\n\n private int[][] pow(int[][] a, int k) {\n if (k == 0) {\n int[][] matr = new int[BUBEN][BUBEN];\n for (int[] x : matr)\n Arrays.fill(x, Integer.MAX_VALUE);\n for (int i = 0; i < BUBEN; ++i) matr[i][i] = 0;\n return matr;\n }\n if (k % 2 == 0)\n return pow(mul(a, a), k / 2);\n return mul(a, pow(a, k - 1));\n }\n\n private int[][] mul(int[][] a, int[][] b) {\n int[][] c = new int[BUBEN][BUBEN];\n for (int i = 0; i < BUBEN; ++i)\n for (int j = 0; j < BUBEN; ++j) {\n int mx = Integer.MAX_VALUE;\n for (int k = 0; k < BUBEN; ++k)\n if (a[i][k] < Integer.MAX_VALUE && b[k][j] < Integer.MAX_VALUE) {\n mx = Math.min(mx, a[i][k] + b[k][j]);\n }\n c[i][j] = mx;\n }\n return c;\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "90064e82c6ceb18c0b4756ac88d27da8", "src_uid": "f40900973f4ebeb6fdafd75ebe4e9601", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.util.ArrayList;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.Scanner;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n \npublic class myFile\n{\n\tpublic static void main(String args[])\n\t{\n\t Scanner sc = new Scanner(System.in);\n\t int i,n,k,count=1;\n\t TreeMap treeMap = new TreeMap();\n\t for(char ch ='1';ch<='9';ch++)\n\t {\n\t\t treeMap.put(ch, count++);\n\t }\n\t while(sc.hasNextInt())\n\t {\n\t\t n = sc.nextInt();\n\t\t k = sc.nextInt();\n\t\t sc.nextLine();\n\t\t String str = sc.nextLine();\n\t\t if(n==1 && k==1)\n\t\t {\n\t\t\t System.out.println(\"0\");\n\t\t\t continue;\n\t\t }\n\t\t int index=0;\n\t\t String ans=\"\";\n\t\t for(i=0;i'1' && k>0)\n\t\t\t {\n\t\t\t\t index=i;\n\t\t\t\t ans = ans+'1';\n\t\t\t\t k--;\n\t\t\t }\n\t\t\t else if(i>0 && str.charAt(i)>'0' && k>0)\n\t\t\t {\n\t\t\t\t index=i;\n\t\t\t\t ans = ans+'0';\n\t\t\t\t k--;\n\t\t\t }\n\t\t\t else\n\t\t\t\t ans=ans+str.charAt(i);\n\t\t }\n\t\t \n\t\t System.out.println(ans);\n\t }\n\t \n\t}\n\t\n\t \n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "75c61838d9d13942f282c9ed88ec4c68", "src_uid": "0515ac888937a4dda30cad5e2383164f", "difficulty": 1000.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskE1 solver = new TaskE1();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskE1 {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int r = in.nextInt();\n int b = in.nextInt();\n\n TaskE1.Point[] ships = new TaskE1.Point[r];\n TaskE1.Point[] bases = new TaskE1.Point[b];\n for (int i = 0; i < r; i++) ships[i] = new TaskE1.Point(in.nextInt(), in.nextInt());\n for (int i = 0; i < b; i++) bases[i] = new TaskE1.Point(in.nextInt(), in.nextInt());\n\n if (r != b) {\n out.println(\"No\");\n return;\n }\n\n //Arrays.sort(bases);\n //Arrays.sort(ships);\n\n for (int i = 1; i < r; i++) {\n if (doIntersect(ships[i - 1], bases[i - 1], ships[i], bases[i])) {\n out.println(\"No\");\n return;\n }\n }\n\n out.println(\"Yes\");\n }\n\n boolean onSegment(TaskE1.Point p, TaskE1.Point q, TaskE1.Point r) {\n if (q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) &&\n q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y))\n return true;\n\n return false;\n }\n\n int orientation(TaskE1.Point p, TaskE1.Point q, TaskE1.Point r) {\n int val = (q.y - p.y) * (r.x - q.x) -\n (q.x - p.x) * (r.y - q.y);\n\n if (val == 0) return 0;\n\n return (val > 0) ? 1 : 2;\n }\n\n boolean doIntersect(TaskE1.Point p1, TaskE1.Point q1, TaskE1.Point p2, TaskE1.Point q2) {\n int o1 = orientation(p1, q1, p2);\n int o2 = orientation(p1, q1, q2);\n int o3 = orientation(p2, q2, p1);\n int o4 = orientation(p2, q2, q1);\n\n if (o1 != o2 && o3 != o4)\n return true;\n\n if (o1 == 0 && onSegment(p1, p2, q1)) return true;\n\n if (o2 == 0 && onSegment(p1, q2, q1)) return true;\n\n if (o3 == 0 && onSegment(p2, p1, q2)) return true;\n\n if (o4 == 0 && onSegment(p2, q1, q2)) return true;\n\n return false;\n }\n\n static class Point implements Comparable {\n int x;\n int y;\n\n public Point(int x, int y) {\n this.x = x;\n this.y = y;\n }\n\n\n public int compareTo(TaskE1.Point o) {\n if (this.x != o.x)\n return this.x - o.x;\n\n return this.y - o.y;\n }\n\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String 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", "compilation_error": false, "code_uid": "9cffc92123f2561ccc83eb7a0d4840a6", "src_uid": "65f81f621c228c09915adcb05256c634", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.BigInteger;\nimport java.util.Collections.*;\nimport static java.lang.Math.*;\nimport static java.lang.Math.max;\nimport static java.lang.Math.min;\nimport static java.util.Arrays.*;\nimport static java.math.BigInteger.*;\n\n\npublic class Main{\n\n void run(){\n Locale.setDefault(Locale.US);\n boolean my;\n try {\n my = System.getProperty(\"MY_LOCAL\") != null;\n } catch (Exception e) {\n\n\n my = false;\n\n }\n try{\n err = System.err;\n if( my ){\n sc = new FastScanner(new BufferedReader(new FileReader(\"input.txt\")));\n// sc = new FastScanner(new BufferedReader(new FileReader(\"C:\\\\myTest.txt\")));\n out = new PrintWriter (new FileWriter(\"output.txt\"));\n }\n else {\n sc = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));\n out = new PrintWriter(new OutputStreamWriter(System.out));\n }\n// out = new PrintWriter(new OutputStreamWriter(System.out));\n }catch(Exception e){\n MLE();\n }\n if( my )\n tBeg = System.currentTimeMillis();\n solve();\n if( my )\n err.println( \"TIME: \" + (System.currentTimeMillis() - tBeg ) / 1e3 );\n exit(0);\n }\n\n void exit( int val ){\n err.flush();\n out.flush();\n System.exit(val);\n }\n\n double tBeg;\n FastScanner sc;\n PrintWriter out;\n PrintStream err;\n\n class FastScanner{\n\n StringTokenizer st;\n BufferedReader br;\n\n FastScanner( BufferedReader _br ){\n br = _br;\n }\n\n String readLine(){\n try {\n return br.readLine();\n } catch (IOException e) {\n return null;\n }\n }\n\n String next(){\n while( st==null || !st.hasMoreElements() )\n st = new StringTokenizer(readLine());\n return st.nextToken();\n }\n\n int nextInt(){ return Integer.parseInt(next()); }\n long nextLong(){ return Long.parseLong(next()); }\n double nextDouble(){ return Double.parseDouble(next()); }\n }\n\n void MLE(){\n int[][] arr = new int[1024*1024][]; for( int i = 0; i < 1024*1024; ++i ) arr[i] = new int[1024*1024];\n }\n\n void MLE( boolean doNotMLE ){ if( !doNotMLE ) MLE(); }\n\n void TLE(){\n for(;;);\n }\n\n public static void main(String[] args) {\n new Main().run();\n// new Thread( null, new Runnable() {\n// @Override\n// public void run() {\n// new Main().run();\n// }\n// }, \"Lolka\", 256_000_000L ).run();\n }\n\n ////////////////////////////////////////////////////////////////\n\n final int mod = (int)1e9 + 7;\n int n, k;\n Long[][] dp0, dp1;\n long[] pow2 = new long[1000];\n {\n pow2[0] = 1;\n for (int i = 1; i < pow2.length; i++) {\n pow2[i] = (pow2[i-1] * 2) % mod;\n }\n }\n\n void solve(){\n n = sc.nextInt();\n k = sc.nextInt();\n dp0 = new Long[k+1][n+1];\n for (Long[] val : dp0) fill(val, 0L);\n\n for (int sz = 1; sz <= n; sz++) {\n dp1 = new Long[k+1][n+1];\n\n for (int cnt = 0; cnt <= k; cnt++) {\n for (int last = 0; last <= sz; last++) {\n if( cnt == 0 ){\n if( last == 0 ) dp1[cnt][last] = 1L;\n else dp1[cnt][last] = 0L;\n }\n else if( sz == last ){\n if( cnt == 1 ){\n dp1[cnt][last] = (pow2[last]-1);\n }\n else{\n dp1[cnt][last] = 0L;\n for (int l = 1; l <= sz - 1; l++) {\n dp1[cnt][last] += dp1[cnt-1][l] * (pow2[sz-l]-1);\n }\n }\n }\n else{\n dp1[cnt][last] = dp0[cnt][last] * pow2[last];\n }\n dp1[cnt][last] = ( dp1[cnt][last]%mod + mod ) % mod;\n }\n }\n //\n dp0 = dp1;\n }\n long ans = 0;\n for (int last = 0; last <= n; last++) {\n ans += dp0[k][last];\n }\n ans %= mod;\n out.println( ans );\n }\n\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "696e11bd26d17588ccbb1cf0df421477", "src_uid": "111673158df2e37ac6c019bb99225ccb", "difficulty": 2500.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n \n\npublic class Main {\n\t\n\tstatic long[][][][] arr;\n\tstatic boolean[][][][] check;\n\tstatic int[] beads;\n\t\n\tpublic static void main(String[] args) throws java.lang.Exception {\n\t\tBufferedReader kek = new BufferedReader(new InputStreamReader(System.in));\n\t\t//Scanner skek = new Scanner(System.in);\n\t\tPrintWriter outkek = new PrintWriter(System.out);\n\n\t\tString[] input = kek.readLine().split(\" \");\n\t\tint N = Integer.parseInt(input[0]);\n\t\tlong M = Long.parseLong(input[1]);\n\t\tM++;\n\t\t\n\t\tbeads = new int[N];\n\t\tarr = new long[N][N][2][2];\n\t\tcheck = new boolean[N][N][2][2];\n\t\t\n\t\tArrays.fill(beads, -1);\n\t\tlong temp1 = compute(0, N - 1, 0, 0);\n\t\tif(temp1 < M){\n\t\t\t//System.out.println(temp1);\n\t\t\toutkek.println(-1);\n\t\t\toutkek.close();\n\t\t\treturn;\n\t\t}\n\t\t//System.out.println(temp1);\n\n\t\tbeads[0] = 0;\n\t\tlong temp;\n\t\tfor(int i = 1; i < N; i++){\n\t\t\t//Arrays.fill(check, false); Default boolean value is false\n\t\t\tcheck = new boolean[50][50][2][2];\n\t\t\tbeads[i] = 0;\n\t\t\ttemp = compute(0, N - 1, 0, 0);\n\t\t\tif(temp < M){\n\t\t\t\tM -= temp;\n\t\t\t\tbeads[i] = 1;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor(int i = 0; i < N; i++){\n\t\t\toutkek.print(beads[i]);\n\t\t}\n\t\t\n\t\tkek.close();\n\t\toutkek.close();\n\t}\t\n\t\n\tstatic long compute(int L, int R, int reverse, int flip){\n\t\tif(L > R){\n\t\t\treturn 1;\n\t\t}\n\t\tif(check[L][R][reverse][flip]){\n\t\t\treturn arr[L][R][reverse][flip];\n\t\t}\n\t\t\n\t\tcheck[L][R][reverse][flip] = true;\n\t\tarr[L][R][reverse][flip] = 0;\n\t\t\n\t\tfor(int i = 0; i < 2; i++)\n\t\t\tif(beads[L] == -1 || beads[L] == i)\n\t\t\t\tfor(int j = 0; j < 2; j++)\n\t\t\t\t\tif(beads[R] == -1 || beads[R] == j)\n\t\t\t\t\t\tif((L < R || i == j) && (reverse == 1 || i <= j) && (flip == 1 || i <= 1 - j)){\n\t\t\t\t\t\t\tarr[L][R][reverse][flip] += compute(L + 1, R - 1, reverse == 1 || i < j ? 1 : 0, flip == 1 || i < 1 - j ? 1 : 0);\n\t\t\t\t\t\t}\n\t\treturn arr[L][R][reverse][flip];\n\t}\n\t\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4449d48b847783919546215500c3e8e2", "src_uid": "0a4a418dafaee71f1b31c928fc2ad24a", "difficulty": 2600.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n FastScanner in;\n PrintWriter out;\n\n Main () {\n in = new FastScanner(IO_Type.CONSOLE).getScanner();\n out = new FastWriter(IO_Type.CONSOLE).getWriter();\n\n //in = new FastScanner(IO_Type.TEST, \"test.txt\").getScanner();\n //out = new FastWriter(IO_Type.TEST, \"result.txt\").getWriter();\n\n //in = new FastScanner(IO_Type.FILE, \"input.txt\").getScanner();\n //out = new FastWriter(IO_Type.TEST, \"output.txt\").getWriter();\n }\n\n public static void main (String[]args) {\n Main task = new Main();\n task.solve();\n task.close();\n }\n\n public void close () {\n in.close();\n out.close();\n }\n\n public void solve () {\n int n = in.nextInt();\n System.out.println((int)(2*Math.pow(n + 1, 3) - 3));\n }\n \n public String getText(String s, int q) {\n String ss = \"\";\n for (int i = 0; i < s.length(); i++) {\n if (s.charAt(i) >= '\u0430' && s.charAt(i) <= '\u044f') {\n ss += (char)(s.charAt(i) + q);\n }\n else {\n ss += s.charAt(i);\n }\n }\n return ss;\n }\n \n}\n\nclass Algebra {\n /****\n * Number of co-prime numbers on [1, n].\n * Number a is Co-prime if gcd (a, n) == 1\n * O (sqrt(n))\n ****/\n public static int phi(int n) {\n int result = n;\n for (int i = 2; i*i <= n; ++i) {\n if (n % i == 0) {\n while (n % i == 0) {\n n /= i;\n }\n result -= result / i;\n }\n }\n if (n > 1) {\n result -= result / n;\n }\n return result;\n }\n\n /****\n * Raise number a to power of n.\n * O (log n)\n ****/\n public static int binpow (int a, int n) {\n int res = 1;\n while (n != 0) {\n if ((n & 1) == 1)\n res *= a;\n a *= a;\n n >>= 1;\n }\n return res;\n }\n\n /****\n * Finding the greatest common divisor of two numbers.\n * O (log min(a, b))\n ****/\n public static int gcd (int a, int b) {\n return (b != 0) ? gcd (b, a % b) : a;\n }\n\n /****\n * Finding the lowest common multiple of two numbers.\n * O (log min(a, b))\n ****/\n public static int lcm (int a, int b) {\n return a / gcd (a, b) * b;\n }\n\n /****\n * Eratosthenes Sieve of numbers - [0..n]. True - simple, False - not simple.\n * O (n log log n)\n ****/\n public static boolean[] sieveOfEratosthenes (int n) {\n boolean [] prime = new boolean[n + 1];\n Arrays.fill(prime, true);\n prime[0] = prime[1] = false;\n for (int i=2; i<=n; ++i) {\n if (prime[i]) {\n if (i * 1L * i <= n) {\n for (int j=i*i; j<=n; j+=i) {\n prime[j] = false;\n }\n }\n }\n }\n return prime;\n }\n}\n\nclass IO_Type {\n\n public static String CONSOLE = \"console\";\n public static String FILE = \"file\";\n public static String TEST = \"test\";\n\n}\n\nclass FastScanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n FastScanner getScanner() {\n return this;\n }\n\n FastScanner(String type) {\n if (type.equals(\"console\")) {\n FastScanner(System.in);\n } \n }\n \n FastScanner(String type, String inFileName) {\n if (type.equals(\"file\")) {\n File f = new File(inFileName);\n try {\n FastScanner(new FileInputStream(f));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n else if (type.equals(\"test\")) {\n File f = new File(inFileName);\n try {\n FastScanner(new FileInputStream(f));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n }\n \n void FastScanner(InputStream in) {\n br = new BufferedReader(new InputStreamReader(in));\n }\n \n String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n System.err.println(e);\n return \"\";\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 float nextFloat() {\n return Float.parseFloat(next());\n }\n BigInteger nextBigInt() {\n return new BigInteger(next());\n }\n\n void close() {\n try {\n br.close();\n }\n catch (IOException e) {\n }\n }\n}\n\nclass FastWriter {\n\n PrintWriter pw;\n\n PrintWriter getWriter() {\n return pw;\n }\n \n FastWriter(String type) {\n FastWriter(type);\n }\n \n FastWriter (String type, String outFileName) {\n FastWriter(type, outFileName);\n }\n\n PrintWriter FastWriter(String type) {\n if (type.equals(\"console\")) {\n pw = new PrintWriter(System.out);\n }\n return pw;\n }\n\n PrintWriter FastWriter(String type, String outFileName) {\n if (type.equals(\"console\")) {\n pw = new PrintWriter(System.out);\n }\n else if (type.equals(\"test\")) {\n try {\n pw = new PrintWriter(new File(outFileName));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n else if (type.equals(\"file\")) {\n try {\n pw = new PrintWriter(new File(outFileName));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n return pw;\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "60782ee5ae87940a4f8e9bd21d139659", "src_uid": "53879e79cccbacfa6586d40cf3436657", "difficulty": 1600.0} {"lang": "Java 6", "source_code": "\nimport java.util.Scanner;\n\n/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n\n/**\n *\n * @author teacher\n */\npublic class Color {\n public static void main(String[] args){\n Scanner in = new Scanner(System.in);\n int x = in.nextInt();\n int y = in.nextInt();\n double dist = Math.sqrt(x*x+y*y);\n int r = (int)dist;\n if(Math.abs(r-dist)<0.0000001 || x==0 || y==0){\n System.out.println(\"black\");\n } else{\n if((r%2+quadr(x,y))%2==1){\n System.out.println(\"black\");\n }else {\n System.out.println(\"white\");\n }\n }\n\n\n }\n\n static int quadr(int x,int y){\n if((x>0 && y>0)||(x<0 && y<0)){\n return 1;\n } else {\n return 0;\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "842acb168611add0fa81e67bf268dd88", "src_uid": "fa1ef5f9bceeb7266cc597ba8f2161cb", "difficulty": 1600.0} {"lang": "Java 7", "source_code": "//package round302;\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 E2FF {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni();\n\t\tint m = ni();\n\t\tint[] a = na(n);\n\t\tlong[] as = new long[n];\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tas[i] = (long)a[i]<<32|i;\n\t\t}\n\t\tArrays.sort(as);\n\t\t\n\t\tint s = (int)Math.sqrt(n);\n\t\t// time split\n\t\tint[][] minblock = new int[n/s+1][];\n\t\tint[] imos = new int[n/s+2];\n\t\tfor(int i = 0;i <= n;i++){\n\t\t\tif(i % s == 0){\n\t\t\t\tminblock[i/s] = Arrays.copyOf(imos, n/s+2);\n\t\t\t\tfor(int j = 1;j <= n/s;j++){\n\t\t\t\t\tminblock[i/s][j] += minblock[i/s][j-1];\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif(i == n)break;\n\t\t\tif(0 > (int)as[i]-m+1){\n\t\t\t\tint l = Math.max(0, (int)as[i]-m+1);\n\t\t\t\tint r = (int)as[i];\n\t\t\t\tif(l/s <= r/s){\n\t\t\t\t\timos[l/s]++;\n\t\t\t\t\timos[r/s]--;\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tint l = Math.max(0, (int)as[i]-m+1);\n\t\t\t\tint r = (int)as[i];\n\t\t\t\tif(l/s+1 <= r/s){\n\t\t\t\t\timos[l/s+1]++;\n\t\t\t\t\timos[r/s]--;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tint[][] mininblock = new int[n/s+1][];\n\t\tint[][] wheninblock = new int[n/s+1][];\n\t\tfor(int i = 0;i < n/s+1;i++){\n\t\t\tmininblock[i] = new int[2*s+1];\n\t\t\twheninblock[i] = new int[2*s+1];\n\t\t}\n\t\t\n\t\tint[] map = new int[n];\n\t\tint[] ps = new int[n/s+1];\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tint l = Math.max(0, (int)as[i]-m+1);\n\t\t\tint r = (int)as[i];\n\t\t\tif(l/s == r/s){\n\t\t\t\tfor(int j = l;j <= r;j++)map[j]++;\n\t\t\t\t\n\t\t\t\tint lmin = Integer.MAX_VALUE;\n\t\t\t\tfor(int j = l/s*s;j < l/s*s+s && j < n;j++){\n\t\t\t\t\tif(map[j] < lmin){\n\t\t\t\t\t\tlmin = map[j];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tint clus = l/s;\n\t\t\t\tmininblock[clus][ps[clus]] = lmin;\n\t\t\t\twheninblock[clus][ps[clus]] = i;\n\t\t\t\tps[clus]++;\n\t\t\t}else{\n\t\t\t\t{\n\t\t\t\t\tfor(int j = r/s*s;j <= r;j++)map[j]++;\n\t\t\t\t\t\n\t\t\t\t\tint lmin = Integer.MAX_VALUE;\n\t\t\t\t\tfor(int j = r/s*s;j < r/s*s+s && j < n;j++){\n\t\t\t\t\t\tif(map[j] < lmin){\n\t\t\t\t\t\t\tlmin = map[j];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tint clus = r/s;\n\t\t\t\t\tmininblock[clus][ps[clus]] = lmin;\n\t\t\t\t\twheninblock[clus][ps[clus]] = i;\n\t\t\t\t\tps[clus]++;\n\t\t\t\t}\n\t\t\t\tif(0 <= (int)as[i]-m+1){\n\t\t\t\t\tfor(int j = l;j < l/s*s+s;j++)map[j]++;\n\t\t\t\t\t\n\t\t\t\t\tint lmin = Integer.MAX_VALUE;\n\t\t\t\t\tfor(int j = l/s*s;j < l/s*s+s && j < n;j++){\n\t\t\t\t\t\tif(map[j] < lmin){\n\t\t\t\t\t\t\tlmin = map[j];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tint clus = l/s;\n\t\t\t\t\tmininblock[clus][ps[clus]] = lmin;\n\t\t\t\t\twheninblock[clus][ps[clus]] = i;\n\t\t\t\t\tps[clus]++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(int i = 0;i <= n/s;i++){\n\t\t\twheninblock[i] = Arrays.copyOf(wheninblock[i], ps[i]);\n\t\t}\n\t\tint[][][] bb = prepareFractionalCascading(wheninblock);\n\t\t\n//\t\tfor(int i = 0;i < n/s+1;i++){\n//\t\t\ttr(i);\n//\t\t\ttr(Arrays.copyOf(mininblock[i], ps[i]));\n//\t\t\ttr(Arrays.copyOf(wheninblock[i], ps[i]));\n//\t\t}\n\t\t\n\t\tint ans = 0;\n\t\tint[] llimos = new int[s+1];\n\t\tint[] limos = new int[n/s+2];\n\t\tfor(int Q = ni(); Q >= 1;Q--){\n\t\t\tint ql = ni()-1, qr = ni()-1, qx = ni()^ans;\n\t\t\tint time = -Arrays.binarySearch(as, ((long)qx<<32)-1)-1;\n\t\t\tArrays.fill(limos, 0);\n\t\t\tfor(int i = time/s*s;i < time;i++){\n\t\t\t\tif(0 > (int)as[i]-m+1){\n\t\t\t\t\tint l = Math.max(0, (int)as[i]-m+1);\n\t\t\t\t\tint r = (int)as[i];\n\t\t\t\t\tif(l/s <= r/s){\n\t\t\t\t\t\tlimos[l/s]++;\n\t\t\t\t\t\tlimos[r/s]--;\n\t\t\t\t\t}\n\t\t\t\t}else{\n\t\t\t\t\tint l = Math.max(0, (int)as[i]-m+1);\n\t\t\t\t\tint r = (int)as[i];\n\t\t\t\t\tif(l/s+1 <= r/s){\n\t\t\t\t\t\tlimos[l/s+1]++;\n\t\t\t\t\t\tlimos[r/s]--;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor(int i = 1;i < n/s+1;i++){\n\t\t\t\tlimos[i] += limos[i-1];\n\t\t\t}\n\t\t\tfor(int i = 0;i < n/s+1;i++){\n\t\t\t\tlimos[i] += minblock[time/s][i];\n\t\t\t}\n\t\t\tans = 999999999;\n\t\t\t\n\t\t\tif(ql/s == qr/s){\n\t\t\t\tArrays.fill(llimos, 0);\n\t\t\t\tint clus = ql/s;\n\t\t\t\tfor(int j = 0;j < ps[clus] && wheninblock[clus][j] < time;j++){\n\t\t\t\t\tint l = Math.max((int)as[wheninblock[clus][j]]-m+1-clus*s, 0);\n\t\t\t\t\tint r = Math.min(s-1, (int)as[wheninblock[clus][j]]-clus*s);\n\t\t\t\t\tllimos[l]++;\n\t\t\t\t\tllimos[r+1]--;\n\t\t\t\t}\n\t\t\t\tfor(int j = 1;j <= s;j++){\n\t\t\t\t\tllimos[j] += llimos[j-1];\n\t\t\t\t}\n\t\t\t\tfor(int j = ql-clus*s;j <= qr-clus*s;j++){\n\t\t\t\t\tans = Math.min(ans, limos[clus] + llimos[j]);\n\t\t\t\t}\n\t\t\t}else{\n//\t\t\t\tint[] mins = doFractionalCascading(bb[0], bb[1], ql/s+1, qr/s-1, time-1);\n\t\t\t\t\n//\t\t\t\tif(l > r)return new int[0];\n//\t\t\t\tint[] inds = new int[r-l+1];\n//\t\t\t\tint ub = upperBound(b[l], v);\n//\t\t\t\tinds[0] = ub == -1 ? -1 : bind[l][ub];\n//\t\t\t\tfor(int i = l+1;i <= r;i++){\n//\t\t\t\t\tint ind = ub == -1 ? -1 : 2*(ub-bind[i-1][ub])-1;\n//\t\t\t\t\tub = ind+1 < b[i].length && v >= b[i][ind+1] ? ind+1 : ind;\n//\t\t\t\t\tinds[i-l] = ub == -1 ? -1 : bind[i][ub];\n//\t\t\t\t}\n//\t\t\t\treturn inds;\n\t\t\t\tif(ql/s+1 <= qr/s-1){\n\t\t\t\t\tint ub = upperBound(bb[0][ql/s+1], time-1);\n\t\t\t\t\tfor(int i = ql/s+1;i < qr/s;i++){\n\t//\t\t\t\t\tint xind = Arrays.binarySearch(wheninblock[i], time-1);\n\t//\t\t\t\t\tif(xind < 0)xind = -xind-2;\n\t\t\t\t\t\tint lind = ub == -1 ? -1 : bb[1][i][ub];\n\t\t\t\t\t\tint xind = 2*(ub-lind)-1;\n\t\t\t\t\t\tub = xind+1 < bb[0][i+1].length && time-1 >= bb[0][i+1][xind+1] ? xind+1 : xind;\n//\t\t\t\t\t\tint lind = mins[j];\n\t\t\t\t\t\tif(lind >= 0){\n\t\t\t\t\t\t\tans = Math.min(ans, limos[i] + mininblock[i][lind]);\n\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\tans = Math.min(ans, limos[i]);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t{\n\t\t\t\t\tint clus = ql/s;\n\t\t\t\t\tArrays.fill(llimos, 0);\n\t\t\t\t\tfor(int j = 0;j < ps[clus] && wheninblock[clus][j] < time;j++){\n\t\t\t\t\t\tint l = Math.max((int)as[wheninblock[clus][j]]-m+1-clus*s, 0);\n\t\t\t\t\t\tint r = Math.min((int)as[wheninblock[clus][j]]-clus*s, s-1);\n\t\t\t\t\t\tllimos[l]++;\n\t\t\t\t\t\tllimos[r+1]--;\n\t\t\t\t\t}\n\t\t\t\t\tfor(int j = 1;j <= s;j++){\n\t\t\t\t\t\tllimos[j] += llimos[j-1];\n\t\t\t\t\t}\n\t\t\t\t\tfor(int j = ql-clus*s;j < s && j < n-clus*s;j++){\n\t\t\t\t\t\tans = Math.min(ans, limos[clus] + llimos[j]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t{\n\t\t\t\t\tint clus = qr/s;\n\t\t\t\t\tArrays.fill(llimos, 0);\n\t\t\t\t\tfor(int j = 0;j < ps[clus] && wheninblock[clus][j] < time;j++){\n\t\t\t\t\t\tint l = Math.max((int)as[wheninblock[clus][j]]-m+1-clus*s, 0);\n\t\t\t\t\t\tint r = Math.min((int)as[wheninblock[clus][j]]-clus*s, s-1);\n\t\t\t\t\t\tllimos[l]++;\n\t\t\t\t\t\tllimos[r+1]--;\n\t\t\t\t\t}\n\t\t\t\t\tfor(int j = 1;j <= s;j++){\n\t\t\t\t\t\tllimos[j] += llimos[j-1];\n\t\t\t\t\t}\n\t\t\t\t\tfor(int j = 0;j <= qr-clus*s;j++){\n\t\t\t\t\t\tans = Math.min(ans, limos[clus] + llimos[j]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tout.println(ans);\n\t\t}\n\t}\n\t\n\tint[] doFractionalCascading(int[][] b, int[][] bind, int l, int r, int v)\n\t{\n\t\tif(l > r)return new int[0];\n\t\tint[] inds = new int[r-l+1];\n\t\tint ub = upperBound(b[l], v);\n\t\tinds[0] = ub == -1 ? -1 : bind[l][ub];\n\t\tfor(int i = l+1;i <= r;i++){\n\t\t\tint ind = ub == -1 ? -1 : 2*(ub-bind[i-1][ub])-1;\n\t\t\tub = ind+1 < b[i].length && v >= b[i][ind+1] ? ind+1 : ind;\n\t\t\tinds[i-l] = ub == -1 ? -1 : bind[i][ub];\n\t\t}\n\t\treturn inds;\n\t}\n\t\n\t\n\tpublic static int upperBound(int[] a, int v)\n\t{\n\t\tint low = -1, high = a.length;\n\t\twhile(high-low > 1){\n\t\t\tint h = high+low>>>1;\n\t\t\tif(a[h] <= v){\n\t\t\t\tlow = h;\n\t\t\t}else{\n\t\t\t\thigh = h;\n\t\t\t}\n\t\t}\n\t\treturn low;\n\t}\n\t\n\tpublic int[][][] prepareFractionalCascading(int[][] a)\n\t{\n\t\tint n = a.length;\n\t\tint[][] b = new int[n][];\n\t\tint[][] bind = new int[n][];\n\t\tb[n-1] = a[n-1];\n\t\tbind[n-1] = new int[a[n-1].length];\n\t\tfor(int i = 0;i < bind[n-1].length;i++)bind[n-1][i] = i;\n\t\tfor(int i = n-2;i >= 0;i--){\n\t\t\tb[i] = new int[a[i].length + b[i+1].length/2];\n\t\t\tbind[i] = new int[a[i].length + b[i+1].length/2];\n\t\t\tint q = 1, r = 0;\n\t\t\tfor(int p = 0;p < a[i].length;p++){\n\t\t\t\twhile(q < b[i+1].length && b[i+1][q] < a[i][p]){\n\t\t\t\t\tb[i][r] = b[i+1][q];\n\t\t\t\t\tbind[i][r] = r-1 >= 0 ? bind[i][r-1] : -1;\n\t\t\t\t\tr++; q+=2;\n\t\t\t\t}\n\t\t\t\tb[i][r] = a[i][p];\n\t\t\t\tbind[i][r] = p;\n\t\t\t\tr++;\n\t\t\t}\n\t\t\twhile(q < b[i+1].length){\n\t\t\t\tb[i][r] = b[i+1][q];\n\t\t\t\tbind[i][r] = r-1 >= 0 ? bind[i][r-1] : -1;\n\t\t\t\tr++; q+=2;\n\t\t\t}\n\t\t\tassert r == b[i].length;\n\t\t}\n\t\treturn new int[][][]{b, bind};\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception { new E2FF().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tprivate int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6b636da3a3461379ccaa988d3701f7d9", "src_uid": "92c773d61414ec6a13cdfbdcd24a2b0d", "difficulty": 3200.0} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.StringTokenizer;\nimport java.util.*;\nimport java.math.*;\nimport java.lang.Integer;\n\npublic class Solution {\n\tpublic static int max_sort(int arr[], int start, int end) {\n\t\t// System.out.println(start+\" start \"+end+\" end\");\n\n\t\tif (start >= end)\n\t\t\treturn 1;\n\t\tboolean check_full = true;\n\t\tint m = start + (end - start) / 2;\n\t\tfor (int i = start; i < end - 1; i++) {\n\t\t\tif (arr[i] <= arr[i + 1])\n\t\t\t\tcheck_full = true;\n\t\t\telse {\n\t\t\t\tcheck_full = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (check_full) {\n\t\t\treturn end - start;\n\t\t} else {\n\t\t\treturn Math.max(max_sort(arr, start, m), max_sort(arr, m, end));\n\t\t}\n\t}\n\n\tpublic static void useful_methods(int n, int arr[]) {\n\n\t\tArrays.sort(arr);\n\n\t\tchar charrr[] = new char[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tcharrr[i] = '1';\n\t\t}\n\t\tString str = String.valueOf(charrr);\n\n\t\tString strr = str.substring(0, 1);\n\n\t\tchar[] chs = str.toCharArray();\n\n\t\tchar character = str.charAt(0);\n\t\tint ascii = (int) character;\n\n\t\t// Example: the max in an array among all elements divisible by 6.\n\t\tArrays.stream(arr).filter(i -> i % 6 == 0).max();\n\n\t\tInteger.toString(65535, 2);\n\n\t\tBigInteger bigInt = BigInteger.valueOf(65535);\n\t\tbigInt.toByteArray();\n\n\t\tInteger.parseInt(number);\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tFastScanner cin = new FastScanner(System.in);\n\n\t\tint integer = cin.nextInt();\n\n\t\tString str = String.valueOf(integer);\n\n\t\tint n = Integer.parseInt(str.substring(0, str.length() - 3));\n\t\tint m = Integer.parseInt(str.substring(str.length() - 3, str.length()));\n\n\t\tint doubleF = 1;\n\n\t\t// int arr[] = new int[n];\n\t\tfor (int i = n; i > 1; i = i - 2) {\n\t\t\tdoubleF = doubleF * i;\n\t\t}\n\n\t\tSystem.out.println(doubleF % m);\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tFastScanner cin = new FastScanner(System.in);\n\t\tint n = cin.nextInt();\n\t\tint arr[]= new int[6];\n\t\t\n\t\tfor (int i=0; i<6; i++){\n\t\t\tarr[i]=n%2;\n\t\t\tn=n/2;\n\t\t}\n\t\t\n\t\tint arrnew[]= new int[6];\n\t\t\n\t\tarrnew[0]=arr[1];\n\t\tarrnew[1]=arr[4];\n\t\tarrnew[2]=arr[2];\n\t\tarrnew[3]=arr[3];\n\t\tarrnew[4]=arr[5];\n\t\tarrnew[5]=arr[0];\n\t\t\n\t\tint nnew=0;\n\t\tfor (int i=0; i<6; i++){\n\t\t\tnnew=nnew+arrnew[i]*(2^i);\n\t\t}\n\t\t\n\n\t\tSystem.out.println(nnew);\n\t}\n\n\n\tstatic class FastScanner {\n\t\tprivate BufferedReader reader = null;\n\t\tprivate StringTokenizer tokenizer = null;\n\n\t\tpublic FastScanner(InputStream in) {\n\t\t\treader = new BufferedReader(new InputStreamReader(in));\n\t\t\ttokenizer = null;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\tif (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 String nextLine() {\n\t\t\tif (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\treturn 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\n\t\t\treturn tokenizer.nextToken(\"\\n\");\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0f82911e8d130cbdfeef20234533322f", "src_uid": "db5e54f466e1f3d69a51ea0b346e667c", "difficulty": null} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class E {\n\tFastScanner in;\n\tPrintWriter out;\n\n\tint[] cx = new int[] { 2, 1, -1, -2, -1, 1 };\n\tint[] cy = new int[] { 0, 2, 2, 0, -2, -2 };\n\n\tint[] dirx = new int[] { -1, -2, -1, 1, 2, 1 };\n\tint[] diry = new int[] { 2, 0, -2, -2, 0, 2 };\n\n\tlong calc(long i) {\n\t\treturn 3 * (i + 1) * i;\n\t}\n\t\n\tvoid solve() {\n\t\tlong n = in.nextLong();\n\t\tif (n == 0) {\n\t\t\tout.println(\"0 0\");\n\t\t\treturn;\n\t\t}\n\t\tlong l = 0, r = 1000 * 1000 * 1000;\n\t\twhile (r - l > 1) {\n\t\t\tlong m = (l + r) / 2;\n\t\t\tif (calc(m) < n) {\n\t\t\t\tl = m;\n\t\t\t} else {\n\t\t\t\tr = m;\n\t\t\t}\n\t\t}\n\t\tlong i = l + 1;\n\t\tlong cnt = calc(l);\n\t//\tSystem.err.println(\"circle \" + i);\n\t\tfor (int j = 0; j < 6; j++) {\n\t\t\tif (cnt + i >= n) {\n\t\t\t\tlong stx = cx[j] * i, sty = cy[j] * i;\n\t\t\t\t// System.out.println(stx + \" \" + sty);\n\t\t\t\tlong num = n - cnt;\n\t\t\t\tlong rx = stx + num * dirx[j], ry = sty + num * diry[j];\n\t\t\t\tout.println(rx + \" \" + ry);\n\t\t\t\t// System.out.println(num);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcnt += i;\n\t\t}\n\t\treturn;\n\t}\n\n\tvoid run() {\n\t\tin = new FastScanner();\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() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(in.br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\t// TODO Auto-generated catch block\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\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew E().run();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d22a02bb91f67ff6cfc7ec1a74df46f8", "src_uid": "a4b6a570f5e63462b68447713924b465", "difficulty": 2100.0} {"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\npublic class A {\n\t\n\t\n\tpublic static final int MOD = 1000000007; \n\t\n\tpublic static int poo(long b, int p) {\n\t\tlong rt = 1;\n\t\tfor(;p>0;p=p/2,b=b*b%MOD) if(p % 2 == 1) {\n\t\t\trt = rt * b % MOD;\n\t\t}\n\t\treturn (int) rt;\n\t}\n\t\n\tpublic static int calc(int x, int y) {\n\t\tif (y % x > 0) {\n\t\t\treturn 0;\n\t\t} else {\n\t\t\tint sum = y / x;\n\t\t\tif(sum == 0) return 0;\n\t\t\tint ans = poo(2, sum - 1);\n\t\t\t//for(int i=2;i<=sum;i++) ans -= calc(i, sum);\n\t\t\t\n\t\t\t\n\t\t\tfor(int i=2;((long) i) * i <= sum;i++) if(sum % i == 0){\n\t\t\t\tint lo = sum / i; int hi = i;\n\t\t\t\tans -= calc(lo, sum);\n\t\t\t\tif(lo != hi) ans -= calc(hi, sum);\n\t\t\t}\n\n\t\t\tif(sum > 1) ans -= calc(sum, sum);\n\t\t\t\n\t\t\t\n\t\t\treturn ans;\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tFastScanner sc = new FastScanner(System.in);\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\n\t\tint x = sc.nextInt();\n\t\tint y = sc.nextInt();\n\n\t\tpw.println(calc(x, y));\n\n\t\tpw.close();\n\t\tsc.close();\n\t}\n\n}\n\nclass FastScanner {\n\tBufferedReader br;\n\tStringTokenizer st;\n\n\tpublic FastScanner(InputStream is) {\n\t\tbr = new BufferedReader(new InputStreamReader(is));\n\t\tst = null;\n\t}\n\n\tpublic String next() throws IOException {\n\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\tst = new StringTokenizer(br.readLine());\n\t\treturn st.nextToken();\n\t}\n\n\tpublic int nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tpublic long nextLong() throws IOException {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tpublic double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tpublic void close() throws IOException {\n\t\tbr.close();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2a3d0224d073e507ef49d96ebcbbe934", "src_uid": "de7731ce03735b962ee033613192f7bc", "difficulty": 2000.0} {"lang": "Java 11", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.util.Arrays;\nimport java.util.List;\nimport java.util.StringTokenizer;\nimport java.util.function.*;\nimport java.util.stream.*;\n\n\npublic class E {\n\n private static final FastReader in = new FastReader();\n private static final FastWriter out = new FastWriter();\n\n public static void main(String[] args) {\n new E().run();\n }\n\n private void run() {\n var t = 1;\n while (t-- > 0) {\n solve();\n }\n\n out.flush();\n }\n\n int n;\n int k;\n int mod = 998244353;\n\n private void solve() {\n n = in.nextInt();\n k = in.nextInt();\n\n if (k >= n) {\n out.println(0);\n return;\n }\n\n var f = new long[2][k + 1];\n f[1][0] = n;\n for (var i = 2; i <= n; i++) {\n var now = i % 2;\n var pre = (i - 1) % 2;\n for (var j = 0; j <= k; j++) {\n f[now][j] = (n - (i - 1) + j) * f[pre][j];\n if (j > 0) f[now][j] += (i - 1 - (j - 1)) * f[pre][j - 1];\n f[now][j] %= mod;\n }\n }\n\n var ans = f[n % 2][k];\n if (k > 0) ans = ans * 2 % mod;\n out.println(ans);\n\n }\n\n}\n\n\nclass FastReader {\n\n private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n private static StringTokenizer in;\n\n public String next() {\n while (in == null || !in.hasMoreTokens()) {\n try {\n in = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n return null;\n }\n }\n return in.nextToken();\n }\n\n public BigDecimal nextBigDecimal() {\n return new BigDecimal(next());\n }\n\n public BigInteger nextBigInteger() {\n return new BigInteger(next());\n }\n\n public boolean nextBoolean() {\n return Boolean.valueOf(next());\n }\n\n public byte nextByte() {\n return Byte.valueOf(next());\n }\n\n public double nextDouble() {\n return Double.valueOf(next());\n }\n\n public double[] nextDoubleArray(int length) {\n var a = new double[length];\n for (var i = 0; i < length; i++) {\n a[i] = nextDouble();\n }\n return a;\n }\n\n public int nextInt() {\n return Integer.valueOf(next());\n }\n\n public int[] nextIntArray(int length) {\n var a = new int[length];\n for (var i = 0; i < length; i++) {\n a[i] = nextInt();\n }\n return a;\n }\n\n public long nextLong() {\n return Long.valueOf(next());\n }\n\n public long[] nextLongArray(int length) {\n var a = new long[length];\n for (var i = 0; i < length; i++) {\n a[i] = nextLong();\n }\n return a;\n }\n\n}\n\n\nclass FastWriter extends PrintWriter {\n\n public FastWriter() {\n super(System.out);\n }\n\n public void println(boolean[] a) {\n for (var i = 0; i < a.length; i++) {\n print(a[i]);\n print(i + 1 < a.length ? ' ' : '\\n');\n }\n }\n\n public void println(double[] a) {\n for (var i = 0; i < a.length; i++) {\n print(a[i]);\n print(i + 1 < a.length ? ' ' : '\\n');\n }\n }\n\n public void println(int[] a) {\n for (var i = 0; i < a.length; i++) {\n print(a[i]);\n print(i + 1 < a.length ? ' ' : '\\n');\n }\n }\n\n public void println(long[] a) {\n for (var i = 0; i < a.length; i++) {\n print(a[i]);\n print(i + 1 < a.length ? ' ' : '\\n');\n }\n }\n\n public void println(Object... a) {\n for (var i = 0; i < a.length; i++) {\n print(a[i]);\n print(i + 1 < a.length ? ' ' : '\\n');\n }\n }\n\n public void println(List l) {\n println(l.toArray());\n }\n\n public void debug(String name, Object o) {\n String value = Arrays.deepToString(new Object[] { o });\n value = value.substring(1, value.length() - 1);\n System.err.println(name + \" => \" + value);\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "78bb3aaddaf308630be0fc4bab76f643", "src_uid": "6c1a9aaa7bdd7de97220b8c6d35740cc", "difficulty": 2300.0} {"lang": "Java 11", "source_code": "import java.io.OutputStream;\r\nimport java.io.IOException;\r\nimport java.io.InputStream;\r\nimport java.io.OutputStream;\r\nimport java.io.PrintWriter;\r\nimport java.util.Arrays;\r\nimport java.io.BufferedWriter;\r\nimport java.io.Writer;\r\nimport java.io.OutputStreamWriter;\r\nimport java.util.InputMismatchException;\r\nimport java.io.IOException;\r\nimport java.io.InputStream;\r\n\r\n/**\r\n * Built using CHelper plug-in\r\n * Actual solution is at the top\r\n */\r\npublic class Main {\r\n public static void main(String[] args) {\r\n InputStream inputStream = System.in;\r\n OutputStream outputStream = System.out;\r\n InputReader in = new InputReader(inputStream);\r\n OutputWriter out = new OutputWriter(outputStream);\r\n FNezzarAndChocolateBars solver = new FNezzarAndChocolateBars();\r\n solver.solve(1, in, out);\r\n out.close();\r\n }\r\n\r\n static class FNezzarAndChocolateBars {\r\n static final int MAXN = 2048;\r\n static final int modulo = 998244353;\r\n\r\n public int add(int x, int y) {\r\n x += y;\r\n if (x >= modulo) x -= modulo;\r\n return x;\r\n }\r\n\r\n public int subtract(int x, int y) {\r\n x -= y;\r\n if (x < 0) x += modulo;\r\n return x;\r\n }\r\n\r\n public int multiply(int x, int y) {\r\n return (int) ((x * 1L * y) % modulo);\r\n }\r\n\r\n public int power(int x, long y) {\r\n int ans = 1;\r\n for (; y > 0; y >>= 1, x = (int) ((x * 1L * x) % modulo))\r\n if (y % 2 == 1) ans = (int) ((ans * 1L * x) % modulo);\r\n return ans;\r\n }\r\n\r\n public int inverse(int x) {\r\n return power(x, modulo - 2);\r\n }\r\n\r\n public void solve(int testNumber, InputReader in, OutputWriter out) {\r\n int[] fact = new int[MAXN];\r\n int[] ifact = new int[MAXN];\r\n fact[0] = ifact[0] = 1;\r\n for (int i = 1; i < MAXN; i++) {\r\n fact[i] = multiply(fact[i - 1], i);\r\n ifact[i] = inverse(fact[i]);\r\n }\r\n int n = in.nextInt(), k = in.nextInt();\r\n int[] l = in.readIntArray(n);\r\n int[][][] dp = new int[2][MAXN / k][n + 1];\r\n dp[1][0][0] = 1;\r\n int s = 0;\r\n\r\n for (int p = 0; p < n; p++) {\r\n int L = l[p];\r\n int invL = inverse(L);\r\n int[] coeffs = new int[L / k + 1];\r\n int[] coeffs2 = new int[L / k + 1];\r\n for (int i = 0; i <= L / k; i++) {\r\n if (k * i == L) continue;\r\n int z = ifact[i];\r\n if (i % 2 == 1) z = subtract(0, z);\r\n coeffs[i] = multiply(z, power(L - k * i, i));\r\n\r\n if (i >= 1) {\r\n coeffs2[i] = multiply(z, multiply(i, power(L - k * i, i - 1)));\r\n }\r\n }\r\n int r = p & 1;\r\n int h = r ^ 1;\r\n for (int i = 0; i <= s / k; i++) Arrays.fill(dp[r][i], 0);\r\n for (int i = 0; i <= s / k; i++)\r\n for (int j = 0; j <= p; j++)\r\n if (dp[h][i][j] != 0) {\r\n int value = dp[h][i][j];\r\n for (int t = 0; t <= L / k; t++) {\r\n dp[r][i + t][j] = add(dp[r][i + t][j], multiply(value, coeffs[t]));\r\n if (t > 0) {\r\n dp[r][i + t - 1][j + 1] = add(dp[r][i + t - 1][j + 1], multiply(value, coeffs2[t]));\r\n }\r\n }\r\n }\r\n s += L;\r\n }\r\n int answer = 0;\r\n for (int i = 0; i <= s / k; i++)\r\n for (int r = 0; r <= n; r++) {\r\n int value = dp[(n - 1) & 1][i][r];\r\n int j = i + r;\r\n if (j == 0) continue;\r\n int temp = multiply(fact[i], inverse(power(k * j, i + 1)));\r\n answer = add(answer, multiply(value, temp));\r\n }\r\n out.println(multiply(subtract(0, s), answer));\r\n }\r\n\r\n }\r\n\r\n static class InputReader {\r\n private InputStream stream;\r\n private byte[] buf = new byte[1024];\r\n private int curChar;\r\n private int numChars;\r\n private InputReader.SpaceCharFilter filter;\r\n\r\n public InputReader(InputStream stream) {\r\n this.stream = stream;\r\n }\r\n\r\n public int[] readIntArray(int size) {\r\n int[] array = new int[size];\r\n for (int i = 0; i < size; i++) {\r\n array[i] = readInt();\r\n }\r\n return array;\r\n }\r\n\r\n public int read() {\r\n if (numChars == -1) {\r\n throw new InputMismatchException();\r\n }\r\n if (curChar >= numChars) {\r\n curChar = 0;\r\n try {\r\n numChars = stream.read(buf);\r\n } catch (IOException e) {\r\n throw new InputMismatchException();\r\n }\r\n if (numChars <= 0) {\r\n return -1;\r\n }\r\n }\r\n return buf[curChar++];\r\n }\r\n\r\n public int nextInt() {\r\n int c = read();\r\n while (isSpaceChar(c)) c = read();\r\n int sgn = 1;\r\n if (c == '-') {\r\n sgn = -1;\r\n c = read();\r\n }\r\n int res = 0;\r\n do {\r\n if (c < '0' || c > '9')\r\n throw new InputMismatchException();\r\n res *= 10;\r\n res += c - '0';\r\n c = read();\r\n } while (!isSpaceChar(c));\r\n return res * sgn;\r\n }\r\n\r\n public int readInt() {\r\n int c = read();\r\n while (isSpaceChar(c)) {\r\n c = read();\r\n }\r\n int sgn = 1;\r\n if (c == '-') {\r\n sgn = -1;\r\n c = read();\r\n }\r\n int res = 0;\r\n do {\r\n if (c < '0' || c > '9') {\r\n throw new InputMismatchException();\r\n }\r\n res *= 10;\r\n res += c - '0';\r\n c = read();\r\n } while (!isSpaceChar(c));\r\n return res * sgn;\r\n }\r\n\r\n public boolean isSpaceChar(int c) {\r\n if (filter != null) {\r\n return filter.isSpaceChar(c);\r\n }\r\n return isWhitespace(c);\r\n }\r\n\r\n public static boolean isWhitespace(int c) {\r\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\r\n }\r\n\r\n public interface SpaceCharFilter {\r\n public boolean isSpaceChar(int ch);\r\n\r\n }\r\n\r\n }\r\n\r\n static class OutputWriter {\r\n private final PrintWriter writer;\r\n\r\n public OutputWriter(OutputStream outputStream) {\r\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\r\n }\r\n\r\n public OutputWriter(Writer writer) {\r\n this.writer = new PrintWriter(writer);\r\n }\r\n\r\n public void println(Object... objects) {\r\n for (int i = 0; i < objects.length; i++) {\r\n if (i != 0) {\r\n writer.print(' ');\r\n }\r\n writer.print(objects[i]);\r\n }\r\n writer.print('\\n');\r\n }\r\n\r\n public void close() {\r\n writer.close();\r\n }\r\n\r\n }\r\n}\r\n\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3c38ddc6e5bf5563a178a81ea71b12d0", "src_uid": "26d565c193a5920b042c783109496b4c", "difficulty": 3500.0} {"lang": "Java 8", "source_code": "/*\n https://codeforces.com/contest/1146/problem/B\n */\n\nimport java.util.Scanner;\n\npublic class ForethoughtFutureCup2019ERD {\n private static long gcd = 1;\n private static long delta = 0;\n\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n long m = scanner.nextLong();\n long a = scanner.nextLong();\n long b = scanner.nextLong();\n gcd = gcd(a, b);\n\n long sum = 0;\n\n for (long i = 0; i <= a + b - 1 && i <= m; i++) {\n sum += f(i, a, b);\n }\n if (m > a + b - 1) {\n if (gcd == 1) {\n sum += (a + b + m) * (m - a - b + 1) / 2;\n } else {\n for (long i = a + b; i <= m; i++) {\n sum += i / gcd;\n }\n }\n sum += m - a - b + 1;\n }\n System.out.println(sum);\n }\n\n private static long f(long x, long a, long b) {\n if (x >= a + b - 1) {\n return 1 + x / gcd;\n } else {\n long result = 1;\n long pos = 0;\n while (true) {\n if (pos + a > x) {\n pos -= b;\n if (pos <= 0) {\n return result;\n } else {\n result++;\n }\n } else {\n pos += a;\n result++;\n }\n }\n }\n }\n\n private static long gcd(long a, long b) {\n while (b != 0) {\n long tmp = a % b;\n a = b;\n b = tmp;\n }\n return a;\n }\n\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "01ca2cabca8889cdd631757d0243db65", "src_uid": "d6290b69eddfcf5f131cc9e612ccab76", "difficulty": 2100.0} {"lang": "Java 7", "source_code": "\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class Main {\n\n BufferedReader reader;\n StreamTokenizer tokenizer;\n\n int nextInt() throws IOException {\n tokenizer.nextToken();\n return (int) tokenizer.nval;\n }\n\n String next() throws IOException {\n tokenizer.nextToken();\n return tokenizer.sval;\n }\n\n class Pair {\n int first;\n int second;\n\n Pair(int first, int second) {\n this.first = first;\n this.second = second;\n }\n }\n\n void run(boolean local) throws IOException {\n Scanner in = local ? new Scanner(new FileReader(\"input.txt\")) : new Scanner(System.in);\n reader = local ? new BufferedReader(new FileReader(\"input.txt\")) : new BufferedReader(new InputStreamReader(System.in));\n PrintWriter out = new PrintWriter(System.out);\n ArrayList varIds = new ArrayList<>();\n String s = in.nextLine();\n int idx = s.indexOf(':');\n String s1 = s.substring(2, idx);\n while (s1.length() > 0 && s1.charAt(0)=='_') {\n int i = 0;\n int len = 0;\n while (i < s1.length() && s1.charAt(i)=='_') {\n len++;\n i++;\n }\n varIds.add(len);\n if (i!=s1.length())i++;\n s1 = s1.substring(i);\n }\n\n ArrayList rels = new ArrayList<>();\n String s2 = s.substring(idx+2, s.length()-1);\n String []ar=s2.split(\",\");\n for(String rel : ar) {\n if (rel.contains(\"<\")) {\n idx = rel.indexOf('<');\n int l = idx;\n int r = rel.length()-idx-1;\n rels.add(new Pair(l, r));\n } else {\n idx = rel.indexOf('>');\n int l = idx;\n int r = rel.length()-idx-1;\n rels.add(new Pair(r, l));\n }\n }\n\n boolean ok = true;\n int []res = new int[Collections.max(varIds)+1];\n while (true) {\n boolean changed = false;\n for(Pair p : rels) {\n if (res[p.first] >= res[p.second]) {\n res[p.second]++;\n if (res[p.second]==10) {\n ok = false;\n }\n changed = true;\n break;\n }\n }\n if (!changed) {\n break;\n }\n if (!ok) {\n break;\n }\n }\n if (!ok) {\n System.out.println(\"false\");\n } else {\n for(int t : varIds) {\n out.print(res[t]);\n }\n }\n\n\n in.close();\n reader.close();\n out.close();\n }\n\n public static void main(String[] args) throws IOException {\n new Main().run(args.length > 0 && args[0].equals(\"pqlocal\"));\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "26770e0d91d9a6e2f8513b81e5188978", "src_uid": "390a0b72c77ebe5881b656830fbfae02", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author AsgarJ\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskF solver = new TaskF();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskF {\n int LEN;\n static final int DIGIT = 17;\n static int[] cnt = new int[DIGIT - 1];\n char[] res;\n int k;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n k = in.nextInt();\n int T = in.nextInt();\n Arrays.fill(cnt, T);\n\n if (k < 16) {\n out.println(getChar(k));\n return;\n }\n\n long[] counts = dp(13);\n LEN = getLength(counts, k);\n\n res = new char[LEN];\n\n int startIndex = brute();\n\n int[] curCount = new int[]{0};\n for (int i = 1; i <= LEN - startIndex; i++) {\n bruteForce(startIndex, cnt, res, i + startIndex, k, curCount);\n }\n\n out.println(res);\n }\n\n private int getLength(long[] counts, int k) {\n int LEN = 1;\n for (; LEN <= 13; LEN++) {\n if (LEN <= cnt[0] && k > counts[LEN] - 1) continue;\n else if (LEN > cnt[0] && k > counts[LEN]) continue;\n else break;\n }\n return LEN;\n }\n\n private int brute() {\n k -= dp(LEN)[LEN - 1];\n if (LEN - 1 <= cnt[0]) k++;\n for (int i = 0; i < LEN; i++) {\n int digit = getNextDigit(i == 0 ? 0 : -1);\n for (; digit < DIGIT - 1 && k > 0; digit = getNextDigit(digit)) {\n cnt[digit]--;\n int temp = (int) dp(LEN - i)[LEN - i - 1];\n if (k > temp) {\n k -= temp;\n cnt[digit]++;\n res[i] = getChar(digit);\n continue;\n } else if (k == temp) {\n res[i++] = getChar(digit);\n for (; i < LEN; i++) {\n res[i] = getChar(getLastDigit());\n }\n return i;\n } else {\n res[i] = getChar(digit);\n break;\n }\n }\n }\n return LEN;\n }\n\n private void bruteForce(int index, int[] cnt, char[] res, int len, int max, int[] cur) {\n if (index == len) {\n cur[0]++;\n return;\n }\n for (int i = getNextDigit(index == 0 ? 0 : -1); i != 16; i = getNextDigit(i)) {\n cnt[i]--;\n if (cur[0] < max) {\n res[index] = getChar(i);\n bruteForce(index + 1, cnt, res, len, max, cur);\n cnt[i]++;\n } else return;\n }\n }\n\n private int getNextDigit(int startDigit) {\n int i = startDigit + 1;\n for (; i < cnt.length && cnt[i] == 0; i++) ;\n return i;\n }\n\n private long[] dp(int len) {\n long[][] dp = new long[DIGIT][++len];\n dp[0][0] = 1;\n\n for (int i = 1; i < DIGIT; ++i) {\n for (int j = 0; j < len; ++j) {\n for (int c = 0; c <= Math.min(j, cnt[i - 1]); c++) {\n for (int k = i - 1; k < i; k++) {\n dp[i][j] += dp[k][j - c] * comb(j, c);\n }\n }\n }\n }\n\n// System.out.printf(\"dp[15][%d]: \", len); print(dp[DIGIT - 1]);\n\n return dp[DIGIT - 1];\n }\n\n private char getChar(int digit) {\n return (char) (digit < 10 ? '0' + digit : 'a' + digit - 10);\n }\n\n private int getLastDigit() {\n int i;\n for (i = cnt.length - 1; i >= 0 && cnt[i] == 0; i--) ;\n cnt[i]--;\n return i;\n }\n\n private long comb(int n, int k) {\n long res = 1L;\n if (k < n)\n for (int i = 1; i <= k; i++) {\n res = res * (n - k + i) / i;\n }\n return res;\n }\n\n }\n\n static class InputReader extends BufferedReader {\n StringTokenizer tokenizer;\n\n public InputReader(InputStream inputStream) {\n super(new InputStreamReader(inputStream), 32768);\n }\n\n public InputReader(String filename) {\n super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(readLine());\n } catch (IOException e) {\n throw new RuntimeException();\n }\n }\n return tokenizer.nextToken();\n }\n\n public Integer nextInt() {\n return Integer.valueOf(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "66e885951a941998f5d70d02910dac38", "src_uid": "cbfc354cfa392cd021d9fe899a745f0e", "difficulty": 2500.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.lang.Math;\nimport java.util.*;\n\npublic class Main\n{\t\n\tpublic BufferedReader in;\n\tpublic PrintStream out;\n\t\n\tpublic boolean log_enabled = false;\n\t\n\tstatic long[] primes;\n\tstatic int p_count;\n\t\n\tpublic static void get_primes(int n)\n\t{\n\t\tprimes = new long[80000];\n\t\t\n\t\tboolean[] v = new boolean[n+1];\n\t\tint i,j;\n\t\tfor (i=2; i<=n;i++)\n\t\t{\n\t\t\tv[i] = true;\n\t\t}\n\t\t\n\t\tfor (i=2; i*i<=n;i++)\n\t\t{\n\t\t\tif (v[i])\n\t\t\t{\n\t\t\t\tfor (j=i; i*j<=n; j++)\n\t\t\t\t{\n\t\t\t\t\tv[i*j]=false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tp_count = 0;\n\t\tfor (i=2; i<=n; i++)\n\t\t{\n\t\t\tif (v[i])\n\t\t\t{\t\n\t\t\t\tprimes[p_count++] = i;\n\t\t\t}\n\t\t}\n\t}\n\n\tint d_count;\n\tint[] d_index;\n\tlong A;\n\t\n\tpublic int d_index(long x)\n\t{\n\t\tif ( (x<1000000) && (x*x<=A))\n\t\t{\n\t\t\treturn d_index[(int)x];\n\t\t}\n\t\telse\n\t\t{\n\t\t\treturn d_count - d_index[(int)(A/x)] - 1;\n\t\t}\n\t}\n\n\tpublic void test()\n\t{\n\t\tA = readLong();\n\t\t\n\t\tif (A==1)\n\t\t{\n\t\t\tout.println(1);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tget_primes(1000000);\n\t\t\n\t\t\n\t\tlong[] dividers = new long[10000];\n\t\td_count = 0;\n\t\t\n\t\td_index = new int[1000000];\n\t\t\n\t\tlong[] use_primes = new long[10000];\n\t\tint use_p_count = 0;\n\t\t\n\t\tboolean[] p_used = new boolean[1000000];\n\t\tArrays.fill(p_used, false);\n\t\t\n\t\tint i;\n\t\tfor (i=1; i*i<=A; i++)\n\t\t{\n\t\t\tif (A % i == 0)\n\t\t\t{\n\t\t\t\td_index[i] = d_count;\n\t\t\t\tdividers[d_count++] = i;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (i=0; i d)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (d % primes[p] == 0)\n\t\t\t\t{\n\t\t\t\t\tis_prime = false;\n\t\t\t\t\twhile (d % primes[p] == 0)\n\t\t\t\t\t{ \n\t\t\t\t\t\td /= primes[p];\n\t\t\t\t\t}\n\t\t\t\t\tif (d==1)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (!p_used[(int)primes[p]])\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tp_used[(int)primes[p]] = true;\n\t\t\t\t\t\t\tuse_primes[use_p_count++] = primes[p];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif (is_prime)\n\t\t\t{\n\t\t\t\tif ((d > 1000000) || !p_used[(int)d])\n\t\t\t\t{\n\t\t\t\t\tif (d<1000000)\n\t\t\t\t\t{\n\t\t\t\t\t\tp_used[(int)d] = true;\n\t\t\t\t\t}\n\t\t\t\t\tuse_primes[use_p_count++] = d;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tlogWrite(\"use_p_count = %d\\n\", use_p_count);\n\t\t\n\t\tlong[] D = new long[d_count];\n\t\tlong[] D1 = new long[d_count];\n\t\t\n\t\tArrays.fill(D, 0);\n\t\tD[0] = 1;\n\t\t\n\t\tfor (p=0; p 0) {\n int x1 = in.nextInt() - 1, y1 = in.nextInt() - 1, x2 = in.nextInt() - 1, y2 = in.nextInt() - 1, k = in.nextInt() - 1;\n \n long ans = 0;\n ans = add(ans, calc(x2, y2, k));\n ans = sub(ans, calc(x1 - 1, y2, k));\n ans = sub(ans, calc(x2, y1 - 1, k));\n ans = add(ans, calc(x1 - 1, y1 - 1, k));\n \n out.println(ans);\n }\n }\n \n int calc(int x, int y, int k) {\n if (x < 0 || y < 0) return 0;\n \n int[][][][] cnt = new int[N + 1][2][2][2];\n int[][][][] sum = new int[N + 1][2][2][2];\n \n int[] a = new int[N], b = new int[N], c = new int[N];\n for (int i = 0; i < N; i++) {\n a[i] = (x >> i) & 1;\n b[i] = (y >> i) & 1;\n c[i] = (k >> i) & 1;\n }\n reverse(a);\n reverse(b);\n reverse(c);\n \n cnt[0][1][1][1] = 1;\n for (int i = 0; i < N; i++) {\n for (int p = 0; p < 2; p++) for (int q = 0; q < 2; q++) for (int r = 0; r < 2; r++) {\n for (int u = 0; u < 2; u++) for (int v = 0; v < 2; v++) {\n int w = u ^ v;\n if (p == 1 && u == 1 && a[i] == 0) continue;\n if (q == 1 && v == 1 && b[i] == 0) continue;\n if (r == 1 && w == 1 && c[i] == 0) continue;\n int np = p == 1 && a[i] == u ? 1 : 0;\n int nq = q == 1 && b[i] == v ? 1 : 0;\n int nr = r == 1 && c[i] == w ? 1 : 0;\n cnt[i + 1][np][nq][nr] = add(cnt[i + 1][np][nq][nr], cnt[i][p][q][r]);\n sum[i + 1][np][nq][nr] = add(sum[i + 1][np][nq][nr], sum[i][p][q][r]);\n sum[i + 1][np][nq][nr] = add(sum[i + 1][np][nq][nr], mul(w << (30 - i), cnt[i][p][q][r]));\n }\n }\n }\n \n long res = 0;\n for (int p = 0; p < 2; p++) for (int q = 0; q < 2; q++) for (int r = 0; r < 2; r++) {\n res = add(res, sum[N][p][q][r]);\n res = add(res, cnt[N][p][q][r]);\n }\n return (int) res;\n }\n \n void reverse(int[] a) {\n int l = 0, r = a.length - 1;\n while (l < r) {\n int tmp = a[l];\n a[l] = a[r];\n a[r] = tmp;\n l++;\n r--;\n }\n }\n \n int add(long a, long b) {\n return (int) ((a + b) % MOD);\n }\n \n int sub(long a, long b) {\n return (int) ((a - b + MOD) % MOD);\n }\n \n int mul(long a, long b) {\n return (int) (a * b % MOD);\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 FindACar2().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", "compilation_error": false, "code_uid": "6add784d80b6b851647da3f51fbc22d4", "src_uid": "1ab085026ce43810acf98cc4bf8faf26", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.io.FilterInputStream;\nimport java.util.Iterator;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.NoSuchElementException;\nimport java.io.BufferedInputStream;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Zyflair Griffane\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputUtil in = new InputUtil(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tMagicTrick solver = new MagicTrick();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass MagicTrick {\n public void solve(int testNumber, InputUtil in, PrintWriter out) {\n double n = in.nextInt();\n double m = in.nextInt();\n if (n * m == 1) {\n out.printf(\"%.1df\\n\", 1);\n return;\n }\n out.printf(\"%.12f\\n\", 1 / n + (n - 1) / n * (m - 1) / (n * m - 1));\n }\n}\n\nclass InputUtil {\n\n JoltyScanner in;\n\n public InputUtil(InputStream istream) {\n in = new JoltyScanner(istream);\n }\n\n public String next() {\n return in.nextOrNull();\n }\n\n public int nextInt() {\n String s = next();\n if (s == null) {\n throw new NoSuchElementException(\"Attempted to read integer that is not there.\");\n }\n return Integer.parseInt(s);\n }\n\n}\n\nclass JoltyScanner {\n public static final int BUFFER_SIZE = 1 << 16;\n\tpublic static final char NULL_CHAR = (char) -1;\n\n BufferedInputStream in;\n\tStringBuilder str = new StringBuilder();\n\tbyte[] buffer = new byte[BUFFER_SIZE];\n\tboolean EOF_FLAG = false;\n\n char c = NULL_CHAR;\n\tint bufferIdx = 0;\n int size = 0;\n\n\tpublic JoltyScanner(InputStream in) {\n\t\tthis.in = new BufferedInputStream(in, BUFFER_SIZE);\n\t}\n\n public String next() {\n\t\tcheckEOF();\n\t\tfor (c = c == NULL_CHAR ? nextChar() : c; Character.isWhitespace(c); checkEOF()) {\n\t\t\tc = nextChar();\n\t\t}\n\t\tstr.setLength(0);\n\t\tfor (; !EOF_FLAG && !Character.isWhitespace(c); c = nextChar()) {\n\t\t\tstr.append(c);\n\t\t}\n\t\treturn str.toString();\n\t}\n\n\tpublic String nextOrNull() {\n\t\ttry {\n\t\t\treturn next();\n\t\t} catch (EndOfFileException e) {\n\t\t\treturn null;\n\t\t}\n\t}\n\n public char nextChar() {\n\t\tif (EOF_FLAG) {\n\t\t\treturn NULL_CHAR;\n\t\t}\n\t\twhile (bufferIdx == size) {\n\t\t\ttry {\n\t\t\t\tsize = in.read(buffer);\n\t\t\t\tif (size == -1) {\n\t\t\t\t\tthrow new Exception();\n\t\t\t\t}\n\t\t\t} catch (Exception e) {\n\t\t\t\tEOF_FLAG = true;\n\t\t\t\treturn NULL_CHAR;\n\t\t\t}\n\t\t\tif (size == -1) {\n\t\t\t\tsize = BUFFER_SIZE;\n\t\t\t}\n\t\t\tbufferIdx = 0;\n\t\t}\n\t\treturn (char) buffer[bufferIdx++];\n\t}\n\n public void checkEOF() {\n\t\tif (EOF_FLAG) {\n\t\t\tthrow new EndOfFileException();\n\t\t}\n\t}\n\n\tpublic class EndOfFileException extends RuntimeException {\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b681ba2a91dc71c8e8e4bdc2edec9cad", "src_uid": "0b9ce20c36e53d4702869660cbb53317", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.Locale;\nimport java.util.StringTokenizer;\nimport java.util.function.Function;\n\npublic class E {\n String fileName = \"E\";\n\n public int n, m;\n\n public static class Event implements Comparable {\n public static final int OPEN_TYPE = 0;\n public static final int POINT_TYPE = 1;\n public static final int CLOSE_TYPE = 2;\n\n public int x, type;\n\n public Event(int x, int type) {\n this.x = x;\n this.type = type;\n }\n\n @Override\n public int compareTo(Event event) {\n if (Integer.compare(x, event.x) != 0)\n return Integer.compare(x, event.x);\n else return Integer.compare(type, event.type);\n }\n }\n\n public static final class Node {\n public int l, r;\n public int max, maxInd;\n\n public Node leftNode, rightNode;\n\n public Node(int l, int r) {\n this.l = l;\n this.r = r;\n }\n }\n\n public void relax(Node root) {\n if (root.leftNode.max > root.rightNode.max) {\n root.max = root.leftNode.max;\n root.maxInd = root.leftNode.maxInd;\n } else {\n root.max = root.rightNode.max;\n root.maxInd = root.rightNode.maxInd;\n }\n }\n\n public Node build(int l, int r, Function getItem) {\n Node res = new Node(l, r);\n if (l == r) {\n res.max = getItem.apply(l);\n res.maxInd = l;\n } else {\n int m = (r + l) / 2;\n res.leftNode = build(l, m, getItem);\n res.rightNode = build(m + 1, r, getItem);\n relax(res);\n }\n return res;\n }\n\n public void set(Node root, int ind, int val) {\n if (ind < root.l || ind > root.r)\n return;\n if (root.l == root.r) {\n root.max = val;\n return;\n }\n set(root.leftNode, ind, val);\n set(root.rightNode, ind, val);\n relax(root);\n }\n\n public static class QueryResult {\n public int max, maxInd;\n\n public QueryResult(int max, int maxInd) {\n this.max = max;\n this.maxInd = maxInd;\n }\n\n public QueryResult(QueryResult first, QueryResult second) {\n if (first.max > second.max) {\n this.max = first.max;\n this.maxInd = first.maxInd;\n } else {\n this.max = second.max;\n this.maxInd = second.maxInd;\n }\n }\n }\n\n public QueryResult query(Node root, int l, int r) {\n if (r == -1)\n return new QueryResult(0, -1);\n if (r < root.l || l > root.r)\n return new QueryResult(Integer.MIN_VALUE, -1);\n if (l <= root.l && r >= root.r) {\n return new QueryResult(root.max, root.maxInd);\n }\n return new QueryResult(query(root.leftNode, l, r), query(root.rightNode, l, r));\n }\n\n public int[] getLens(int[] a) {\n Node root = build(0, n, ind -> 0);\n int[] len = new int[a.length];\n for (int i = 0; i < a.length; i++) {\n int curVal = a[i];\n int prevLen = query(root, 0, curVal).max;\n len[i] = prevLen + 1;\n if (query(root, curVal, curVal).max < len[i])\n set(root, curVal, len[i]);\n }\n return len;\n }\n\n public void solve() throws IOException {\n n = nextInt();\n m = nextInt();\n Event[] events = new Event[2 * n + m];\n for (int i = 1; i <= m; i++) {\n events[i - 1] = new Event(i, Event.POINT_TYPE);\n }\n for (int i = 0; i < n; i++) {\n int l = nextInt();\n int r = nextInt();\n events[m + 2 * i] = new Event(l, Event.OPEN_TYPE);\n events[m + 2 * i + 1] = new Event(r, Event.CLOSE_TYPE);\n }\n Arrays.sort(events);\n int[] cnt = new int[m];\n int balance = 0;\n for (int i = 0; i < events.length; i++) {\n Event curEvent = events[i];\n if (curEvent.type == Event.OPEN_TYPE) {\n balance++;\n } else if (curEvent.type == Event.CLOSE_TYPE) {\n balance--;\n } else if (curEvent.type == Event.POINT_TYPE) {\n cnt[curEvent.x - 1] = balance;\n }\n }\n int[] lenUp = getLens(cnt);\n int[] newCnt = new int[cnt.length];\n for (int i = 0; i < cnt.length; i++) {\n newCnt[i] = cnt[cnt.length - i - 1];\n }\n int[] lenDown = getLens(newCnt);\n int[] revLenDown = new int[lenDown.length];\n for (int i = 0; i < lenDown.length; i++) {\n revLenDown[i] = lenDown[lenDown.length - i - 1];\n }\n int max = 0;\n for (int i = 0; i < lenDown.length; i++) {\n int cur = lenUp[i] + revLenDown[i] - 1;\n max = Math.max(max, cur);\n }\n out.print(max);\n }\n\n public void run() {\n try {\n br = new BufferedReader(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 System.exit(1);\n }\n }\n\n BufferedReader br;\n StringTokenizer in;\n PrintWriter out;\n\n public String nextToken() throws IOException {\n while (in == null || !in.hasMoreTokens()) {\n in = new StringTokenizer(br.readLine());\n }\n return in.nextToken();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n public static void main(String[] args) throws IOException {\n Locale.setDefault(Locale.US);\n new E().run();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "993b2ece186d2abd501830d7b1122249", "src_uid": "ce8350be138ce2061349d7f9224a5aaf", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main3 {\r\n public static void main(String[] args) throws IOException {\r\n long n = nextInt();\r\n long k = nextInt();\r\n long c = 1;\r\n long h = 1;\r\n for (int i = 1; i <= k; i += 1) {\r\n c = (c*(n - i + 1)) % mod;\r\n c = (c * step(i, mod - 2) % mod);\r\n h = (h+c)%mod;\r\n }\r\n out.print(h%mod);\r\n out.close();\r\n }\r\n\r\n static long step(int a, int b) {\r\n if (b == 0) {\r\n return 1;\r\n } else if (b % 2 == 0) {\r\n long s = step(a, b/2);\r\n return s % mod * s % mod;\r\n } else {\r\n long s = step(a, b / 2);\r\n return s % mod * s % mod * a % mod;\r\n }\r\n }\r\n\r\n static int mod = (int) (1e9 + 7);\r\n\r\n static class Pair {\r\n int x, type;\r\n\r\n public Pair(int x, int type) {\r\n this.x = x;\r\n this.type = type;\r\n }\r\n }\r\n\r\n static class PairComparator implements Comparator {\r\n @Override\r\n public int compare(Pair o1, Pair o2) {\r\n if (o1.x != o2.x) return Integer.compare(o1.x, o2.x);\r\n return Integer.compare(o1.type, o2.type);\r\n }\r\n }\r\n\r\n static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n static PrintWriter out = new PrintWriter(System.out);\r\n static StringTokenizer in = new StringTokenizer(\"\");\r\n\r\n\r\n public static boolean hasNext() throws IOException {\r\n if (in.hasMoreTokens()) return true;\r\n String s;\r\n while ((s = br.readLine()) != null) {\r\n in = new StringTokenizer(s);\r\n if (in.hasMoreTokens()) return true;\r\n }\r\n return false;\r\n }\r\n\r\n public static String nextToken() throws IOException {\r\n while (!in.hasMoreTokens()) {\r\n in = new StringTokenizer(br.readLine());\r\n }\r\n return in.nextToken();\r\n }\r\n\r\n public static int nextInt() throws IOException {\r\n return Integer.parseInt(nextToken());\r\n }\r\n\r\n public static double nextDouble() throws IOException {\r\n return Double.parseDouble(nextToken());\r\n }\r\n\r\n public static long nextLong() throws IOException {\r\n return Long.parseLong(nextToken());\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "49abaa061b895b7eea509339fa6290ea", "src_uid": "dc7b887afcc2e95c4e90619ceda63071", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n\n\tstatic final int mod = (int)1e9 + 9;\n\n\tstatic int mult(long x, long y) { return (int)(x * y % mod); }\n\n\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\n\t\tint[] fac = new int[4001];\n\t\tfac[0] = 1;\n\t\tfor(int i = 1; i <= 4000; ++i)\n\t\t\tfac[i] = mult(fac[i - 1], i);\n\n\t\tint[][][] dp = new int[2][4001][4001];\n\t\tdp[0][0][0] = 1;\n\t\tfor(int days = 1; days <= 4000; ++days)\n\t\t\tfor(int items = 0; items <= 4000; ++items)\n\t\t\t\tfor(int canSkip = 0; canSkip < 2; ++canSkip)\n\t\t\t\t{\n\t\t\t\t\tint ret = 0;\n\t\t\t\t\tif(items > 0)\n\t\t\t\t\t\tret += dp[1][days][items - 1];\n\t\t\t\t\tif(canSkip == 1)\n\t\t\t\t\t\tret += dp[0][days - 1][items];\n\t\t\t\t\tret %= mod;\n\t\t\t\t\tdp[canSkip][days][items] = ret;\n\t\t\t\t}\n\t\tint n = sc.nextInt(), w = sc.nextInt(), b = sc.nextInt();\n\t\tint ans = 0;\n\t\tfor(int before = 1; before < n && before < w; ++before)\n\t\t\tfor(int block = 1; before + block < n && block <= b; ++block)\n\t\t\t{\n\t\t\t\tint after = n - before - block;\n\t\t\t\tans += mult(dp[0][before + after][w], dp[0][block][b]);\n\t\t\t\tans %= mod;\n\t\t\t}\n\t\tout.println(mult(mult(fac[b], fac[w]), ans));\n\t\tout.close();\n\t}\n\n\tstatic class Scanner\n\t{\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s){\tbr = new BufferedReader(new InputStreamReader(s));}\n\n\t\tpublic Scanner(FileReader s) throws FileNotFoundException {\tbr = new BufferedReader(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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c87d96dc2d2badffa7c17f9172ef856a", "src_uid": "63e93a161bbff623323e66c98d5e20ac", "difficulty": 2100.0} {"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.ArrayList;\nimport java.util.Arrays;\nimport java.util.List;\n\npublic class CF1139D {\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 int[] mu = new int[100001];\n\n void init() {\n int limit = 100000;\n int[] primes = new int[limit + 1];\n boolean[] isComp = new boolean[limit + 1];\n int wpos = 0;\n mu[1] = 1;\n int[] smallestFactor = new int[limit + 1];\n int[] smallestFactorExp = new int[limit + 1];\n for (int i = 2; i <= limit; i++) {\n if (!isComp[i]) {\n primes[wpos++] = i;\n mu[i] = -1;\n smallestFactor[i] = i;\n smallestFactorExp[i] = 1;\n } else {\n if (smallestFactorExp[i] > 1) {\n mu[i] = 0;\n } else {\n mu[i] = -mu[i / smallestFactor[i]];\n }\n }\n for (int j = 0, until = limit / i; j < wpos && primes[j] <= until; j++) {\n int pi = primes[j] * i;\n smallestFactor[pi] = primes[j];\n smallestFactorExp[pi] = i % primes[j] == 0 ?\n smallestFactorExp[i] + 1 : 1;\n isComp[pi] = true;\n if (i % primes[j] == 0) {\n break;\n }\n }\n }\n }\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 init();\n }\n\n @Override\n public void run() {\n solve();\n }\n\n public void bruteForce() {\n int m = io.readInt();\n long[] dp = new long[m + 1];\n dp[1] = 0;\n int[] count = new int[m + 1];\n long inv = Mathematics.inverse(m, mod);\n long sum = 0;\n for (int i = 2; i <= m; i++) {\n long total = 0;\n long coe = 0;\n Arrays.fill(count, 0);\n for (int j = 1; j <= m; j++) {\n int g = Mathematics.gcd(i, j);\n\n count[g]++;\n if (g == i) {\n coe = mod(coe + inv);\n } else {\n total = mod(total + dp[g] * inv);\n }\n }\n total = mod(total + 1);\n coe = mod(1 - coe);\n dp[i] = mod(total * Mathematics.inverse((int) coe, mod));\n sum = mod(sum + dp[i] * inv);\n }\n\n sum = mod(sum + 1);\n io.cache.append(sum).append('\\n');\n\n }\n\n\n public void solve() {\n int m = io.readInt();\n List[] factors = new List[m + 1];\n for (int i = 1; i <= m; i++) {\n factors[i] = new ArrayList<>();\n }\n for (int i = 1; i <= m; i++) {\n for (int j = i; j <= m; j += i) {\n factors[j].add(i);\n }\n }\n\n int[] dp1 = new int[m + 1];\n dp1[1] = 0;\n long inv = Mathematics.inverse(m, mod);\n long expect = 0;\n for (int i = 2; i <= m; i++) {\n dp1[i] = 0;\n long total = 0;\n long coe = 0;\n for (int x : factors[i]) {\n long count = 0;\n for (int d : factors[i / x]) {\n count = mod(count + mu[d] * ((m / x) / d));\n }\n if (x < i) {\n total = mod(total + count * dp1[x]);\n } else {\n coe = mod(1 - inv * count);\n }\n }\n dp1[i] = mod((long) total * inv + 1);\n dp1[i] = mod((long) dp1[i] * Mathematics.inverse((int) coe, mod));\n expect = mod(expect + dp1[i]);\n }\n\n expect = mod(expect * inv + 1);\n\n io.cache.append(expect);\n }\n }\n\n public static class Mathematics {\n\n public static int ceilPowerOf2(int x) {\n return 32 - Integer.numberOfLeadingZeros(x - 1);\n }\n\n public static int floorPowerOf2(int x) {\n return 31 - Integer.numberOfLeadingZeros(x);\n }\n\n public static long modmul(long a, long b, long mod) {\n return b == 0 ? 0 : ((modmul(a, b >> 1, mod) << 1) % mod + a * (b & 1)) % mod;\n }\n\n /**\n * Get the greatest common divisor of a and b\n */\n public static int gcd(int a, int b) {\n return a >= b ? gcd0(a, b) : gcd0(b, a);\n }\n\n private static int gcd0(int a, int b) {\n return b == 0 ? a : gcd0(b, a % b);\n }\n\n public static int extgcd(int a, int b, int[] coe) {\n if (a >= b) {\n return extgcd0(a, b, coe);\n } else {\n int g = extgcd0(b, a, coe);\n int tmp = coe[0];\n coe[0] = coe[1];\n coe[1] = tmp;\n return g;\n }\n }\n\n private static int extgcd0(int a, int b, int[] coe) {\n if (b == 0) {\n coe[0] = 1;\n coe[1] = 0;\n return a;\n }\n int g = extgcd0(b, a % b, coe);\n int n = coe[0];\n int m = coe[1];\n coe[0] = m;\n coe[1] = n - m * (a / b);\n return g;\n }\n\n /**\n * Get the greatest common divisor of a and b\n */\n public static long gcd(long a, long b) {\n return a >= b ? gcd0(a, b) : gcd0(b, a);\n }\n\n private static long gcd0(long a, long b) {\n return b == 0 ? a : gcd0(b, a % b);\n }\n\n public static long extgcd(long a, long b, long[] coe) {\n if (a >= b) {\n return extgcd0(a, b, coe);\n } else {\n long g = extgcd0(b, a, coe);\n long tmp = coe[0];\n coe[0] = coe[1];\n coe[1] = tmp;\n return g;\n }\n }\n\n private static long extgcd0(long a, long b, long[] coe) {\n if (b == 0) {\n coe[0] = 1;\n coe[1] = 0;\n return a;\n }\n long g = extgcd0(b, a % b, coe);\n long n = coe[0];\n long m = coe[1];\n coe[0] = m;\n coe[1] = n - m * (a / b);\n return g;\n }\n\n /**\n * Get y where x * y = 1 (% mod)\n */\n public static int inverse(int x, int mod) {\n return pow(x, mod - 2, mod);\n }\n\n /**\n * Get x^n(% mod)\n */\n public static int pow(int x, int n, int mod) {\n int bit = 31 - Integer.numberOfLeadingZeros(n);\n long product = 1;\n for (; bit >= 0; bit--) {\n product = product * product % mod;\n if (((1 << bit) & n) != 0) {\n product = product * x % mod;\n }\n }\n return (int) product;\n }\n\n public static long longpow(long x, long n, long mod) {\n if (n == 0) {\n return 1;\n }\n long prod = longpow(x, n >> 1, mod);\n prod = modmul(prod, prod, mod);\n if ((n & 1) == 1) {\n prod = modmul(prod, x, mod);\n }\n return prod;\n }\n\n /**\n * Get x % mod\n */\n public static int mod(int x, int mod) {\n x %= mod;\n if (x < 0) {\n x += mod;\n }\n return x;\n }\n\n public static int mod(long x, int mod) {\n x %= mod;\n if (x < 0) {\n x += mod;\n }\n return (int) x;\n }\n\n /**\n * Get n!/(n-m)!\n */\n public static long permute(int n, int m) {\n return m == 0 ? 1 : n * permute(n - 1, m - 1);\n }\n\n /**\n * Put all primes less or equal to limit into primes after offset\n */\n public static int eulerSieve(int limit, int[] primes, int offset) {\n boolean[] isComp = new boolean[limit + 1];\n int wpos = offset;\n for (int i = 2; i <= limit; i++) {\n if (!isComp[i]) {\n primes[wpos++] = i;\n }\n for (int j = offset, until = limit / i; j < wpos && primes[j] <= until; j++) {\n int pi = primes[j] * i;\n isComp[pi] = true;\n if (i % primes[j] == 0) {\n break;\n }\n }\n }\n return wpos - offset;\n }\n\n /**\n * Round x into integer\n */\n public static int intRound(double x) {\n if (x < 0) {\n return -(int) (-x + 0.5);\n }\n return (int) (x + 0.5);\n }\n\n /**\n * Round x into long\n */\n public static long longRound(double x) {\n if (x < 0) {\n return -(long) (-x + 0.5);\n }\n return (long) (x + 0.5);\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", "compilation_error": false, "code_uid": "6d42c530363c6f5cfaed66bdd6f11423", "src_uid": "ff810b16b6f41d57c1c8241ad960cba0", "difficulty": 2300.0} {"lang": "Java 11", "source_code": " import java.awt.Frame;\nimport java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.PriorityQueue;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\npublic class Main {\n\tstatic ArrayList adj[];\n\t// static PrintWriter out = new PrintWriter(System.out);\n\n\tstatic int[][] notmemo;\n\tstatic int k;\n\tstatic int[] a;\n\tstatic int b[];\n\tstatic int m;\n\n\tstatic class Pair implements Comparable {\n\t\tint d;\n\t\tint s;\n\n\t\tpublic Pair(int b, int l) {\n\t\t\td = b;\n\t\t\ts = l;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Pair o) {\n\t\t\tif (o.d - o.s > this.d - this.s) {\n\t\t\t\treturn 1;\n\t\t\t} else if (o.d - o.s < this.d - this.s) {\n\t\t\t\treturn -1;\n\t\t\t} else\n\t\t\t\treturn 0;\n\n\t\t}\n\n\t}\n\n\tstatic Pair s1[];\n\tstatic ArrayList adjlist[];\n\t// static char c[];\n\tpublic static long mod = (long) (1e9 + 7);\n\tstatic int V;\n\tstatic long INF = (long) 1E16;\n\tstatic int n;\n\tstatic char c[];\n\tstatic int d[];\n\tstatic int z;\n\tstatic Pair p[];\nstatic int R;\nstatic int C;\nstatic int K;\npublic static void main(String args[]) throws Exception {\n\n\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t\tn=sc.nextInt();\n\t\t\tmoves=sc.nextInt();\n\t\t\tss=sc.nextLine().toCharArray();\n\t\t\tString m=sc.next();\n\t\t\tfirst=m.charAt(0);\n\t\t\tsecond=m.charAt(1);\n\t\t\tmemo=new int[200][200][200];\n\t\t\tfor(int x[][]:memo) {\n\t\t\t\tfor(int y[]:x) {\n\t\t\t\t\tArrays.fill(y,-1);\n\t\t\t\t}\n\t\t\t}\n\t\tSystem.out.println(dp(0,0,moves));\n\t\t\nout.flush();\n\n}\nstatic int dp(int i,int count1,int maxmoves) {\n\tif(i==n)\n\t\treturn 0;\n\tif(memo[i][count1][maxmoves]!=-1)\n\t\treturn memo[i][count1][maxmoves];\n\tint max=0;\n\tif(ss[i]==first&&ss[i]==second) {\n\t\tmax=Math.max(max,count1+dp(i+1,count1+1,maxmoves));\t\n\t}\n\tif(first==second&&maxmoves>0) {\n\t\tmax=Math.max(max,count1+dp(i+1,count1+1,maxmoves-1));\t\n\t}\n\t\t\n\tif(maxmoves>0&&ss[i]!=first)\n\tmax=Math.max(max,dp(i+1,count1+1,maxmoves-1));\n\tif(maxmoves>0&&ss[i]!=second)\n\tmax=Math.max(max,count1+dp(i+1,count1,maxmoves-1));\n\tif(ss[i]==first) {\n\t\tmax=Math.max(max,dp(i+1,count1+1,maxmoves));\t\n\t}\n\t if(ss[i]==second) {\n\t\t max=Math.max(max,count1+dp(i+1,count1,maxmoves));\n\t\t\t\t\n\t}\n\tmax=Math.max(max,dp(i+1,count1,maxmoves));\nreturn memo[i][count1][maxmoves]=max;\n}\nstatic int memoo[][][];\nstatic char ss[];\nstatic int moves;\nstatic char first;\nstatic char second;\n\nstatic class FenwickTree { // one-based DS\n\n\t\tint n;\n\t\tint[] ft;\n\t\t\n\t\tFenwickTree(int size) { n = size; ft = new int[n+1]; }\n\t\t\n\t\tint rsq(int b) //O(log n)\n\t\t{\n\t\t\tint sum = 0;\n\t\t\twhile(b > 0) { sum += ft[b]; b -= b & -b;}\t\t//min?\n\t\t\treturn sum;\n\t\t}\n\t\t\n\t\tint rsq(int a, int b) { return rsq(b) - rsq(a-1); }\t\n\t\t\n\t\tvoid point_update(int k, int val)\t//O(log n), update = increment\n\t\t{\n\t\t\twhile(k <= n) { ft[k] += val; k += k & -k; }\t\t//min?\n\t\t}\n\t}\n\n\n\t\nstatic long total[];\nstatic TreeMap map1;\n\n\t\tstatic int zz;\n//static int dp(int idx,int left,int state) {\n//if(idx>=k-((zz-left)*2)||idx+1==n) {\n//\treturn 0;\n//}\n//if(memo[idx][left][state]!=-1) {\n//\treturn memo[idx][left][state];\n//}\n//int ans=a[idx+1]+dp(idx+1,left,0);\n//if(left>0&&state==0&&idx>0) {\n//\tans=Math.max(ans,a[idx-1]+dp(idx-1,left-1,1));\n//}\n//return memo[idx][left][state]=ans;\n//}21\nstatic HashMap map;\nstatic int maxa=0;\nstatic int ff=123123;\n\nstatic long dist[][];\nstatic int[][][] memo;\n\n\n\tstatic long modmod=998244353;\n\tstatic int dx[]= {1,-1,0,0};\n\t static int dy[]= {0,0,1,-1};\t\n\tstatic class BBOOK implements Comparable{\n\t\tint t;\n\t\tint alice;\n\t\tint bob;\n\t\tpublic BBOOK(int x,int y,int z) {\n\t\tt=x;\n\t\talice=y;\n\t\tbob=z;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(BBOOK o) {\n\t\t\treturn this.t-o.t;\n\t\t}\n\t}\n\tprivate static long lcm(long a2, long b2) {\n\treturn (a2*b2)/gcd(a2,b2);\n\t}\n\tstatic class Edge implements Comparable\n\t{\n\t\tint node;long cost ; long time; \n\t\t\n\t\tEdge(int a, long b,long c) { node = a;\tcost = b; time=c; }\n\t\t\n\t\tpublic int compareTo(Edge e){ return Long.compare(time,e.time);\t}\n\t}\n\t\n static void sieve(int N)\t// O(N log log N) \n\t{\n\t\tisComposite = new int[N+1];\t\t\t\t\t\n\t\tisComposite[0] = isComposite[1] = 1;\t\t\t// 0 indicates a prime number\n\t\tprimes = new ArrayList();\n \n\t\tfor (int i = 2; i <= N; ++i) \t\t\t\t\t//can loop till i*i <= N if primes array is not needed O(N log log sqrt(N)) \n\t\t\tif (isComposite[i] == 0) \t\t\t\t\t//can loop in 2 and odd integers for slightly better performance\n\t\t\t{\n\t\t\t\tprimes.add(i);\n\t\t\t\tif(1l * i * i <= N)\n\t\t\t\t\tfor (int j = i * i; j <= N; j += i)\t// j = i * 2 will not affect performance too much, may alter in modified sieve\n\t\t\t\t\t\tisComposite[j] = 1;\n\t\t\t} \n\t}\n static TreeSet factors;\n static ArrayList primeFactors(int N)\t\t// O(sqrt(N) / ln sqrt(N))\n\t{\n\t\tArrayList factors = new ArrayList();\t\t//take abs(N) in case of -ve integers\n\t\tint idx = 0, p = primes.get(idx);\n\n\t\twhile(1l*p * p <= N)\n\t\t{\n\t\t\twhile(N % p == 0) { factors.add(p); N /= p; }\n\t\t\tp = primes.get(++idx);\n\t\t}\n\n\t\tif(N != 1)\t\t\t\t\t\t// last prime factor may be > sqrt(N)\n\t\t\tfactors.add(N);\t\t\t\t// for integers whose largest prime factor has a power of 1\n\t\treturn factors;\n\t}\n\n\tstatic class UnionFind {\n\t\tint[] p, rank, setSize;\n\t\tint numSets;\n\t\tint max[];\n\n\t\tpublic UnionFind(int N) {\n\t\t\tp = new int[numSets = N];\n\t\t\trank = new int[N];\n\t\t\tsetSize = new int[N];\n\t\t\tfor (int i = 0; i < N; i++) {\n\t\t\t\tp[i] = i;\n\t\t\t\tsetSize[i] = 1;\n\t\t\t}\n\t\t}\n\n\t\tpublic int findSet(int i) {\n\t\t\treturn p[i] == i ? i : (p[i] = findSet(p[i]));\n\t\t}\n\n\t\tpublic boolean isSameSet(int i, int j) {\n\t\t\treturn findSet(i) == findSet(j);\n\t\t}\n\t\t\n\n\t\tpublic void unionSet(int i, int j) {\n\t\t\tif (isSameSet(i, j))\n\t\t\t\treturn;\n\t\t\tnumSets--;\n\t\t\tint x = findSet(i), y = findSet(j);\n\t\t\tif (rank[x] > rank[y]) {\n\t\t\t\tp[y] = x;\n\t\t\t\tsetSize[x] += setSize[y];\n\n\n\t\t\t} else {\n\t\t\t\tp[x] = y;\n\t\t\t\tsetSize[y] += setSize[x];\n\t\t\t\tif (rank[x] == rank[y])\n\t\t\t\t\trank[y]++;\n\n\n\t\t\t}\n\t\t}\n\n\t\t\n\n\t\tpublic int numDisjointSets() {\n\t\t\treturn numSets;\n\t\t}\n\n\t\tpublic int sizeOfSet(int i) {\n\t\t\treturn setSize[findSet(i)];\n\t\t}\n\t}\n\n\n\tstatic class Quad implements Comparable {\n\t\tint u;\n\t\tint v;\n\t\tchar state;\n\t\tint turns;\n\n\t\tpublic Quad(int i, int j, char c, int k) {\n\t\t\tu = i;\n\t\t\tv = j;\n\t\t\tstate = c;\n\t\t\tturns = k;\n\t\t}\n\n\t\tpublic int compareTo(Quad e) {\n\t\t\treturn (int) (turns - e.turns);\n\t\t}\n\n\t}\n\n\tstatic long manhatandistance(long x, long x2, long y, long y2) {\n\t\treturn Math.abs(x - x2) + Math.abs(y - y2);\n\t}\n\n\tstatic long fib[];\n\n\tstatic long fib(int n) {\n\t\tif (n == 1 || n == 0) {\n\t\t\treturn 1;\n\t\t}\n\t\tif (fib[n] != -1) {\n\t\t\treturn fib[n];\n\t\t} else\n\t\t\treturn fib[n] = ((fib(n - 2) % mod + fib(n - 1) % mod) % mod);\n\t}\n\n\tstatic class Point implements Comparable{\n\t\tlong x, y;\n\n\t\tPoint(long counth, long counts) {\n\t\t\tx = counth;\n\t\t\ty = counts;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Point p )\n\t\t{\n\t\t\treturn Long.compare(p.y*1l*x, p.x*1l*y);\n\t\t}\n\t}\n\n\tstatic TreeSet primeFactors(long N) // O(sqrt(N) / ln sqrt(N))\n\t{\n\t\tTreeSet factors = new TreeSet(); // take abs(N) in case of -ve integers\n\t\tint idx = 0, p = primes.get(idx);\n\n\t\twhile (p * p <= N) {\n\t\t\twhile (N % p == 0) {\n\t\t\t\tfactors.add((long) p);\n\t\t\t\tN /= p;\n\t\t\t}\n\t\t\tif (primes.size() > idx + 1)\n\t\t\t\tp = primes.get(++idx);\n\t\t\telse\n\t\t\t\tbreak;\n\t\t}\n\n\t\tif (N != 1) // last prime factor may be > sqrt(N)\n\t\t\tfactors.add(N); // for integers whose largest prime factor has a power of 1\n\t\treturn factors;\n\t}\n\n\tstatic boolean visited[];\n\n\t/**\n\t * static int bfs(int s) { Queue q = new LinkedList();\n\t * q.add(s); int count=0; int maxcost=0; int dist[]=new int[n]; dist[s]=0;\n\t * while(!q.isEmpty()) {\n\t * \n\t * int u = q.remove(); if(dist[u]==k) { break; } for(Pair v: adj[u]) {\n\t * maxcost=Math.max(maxcost, v.cost);\n\t * \n\t * \n\t * \n\t * if(!visited[v.v]) {\n\t * \n\t * visited[v.v]=true; q.add(v.v); dist[v.v]=dist[u]+1; maxcost=Math.max(maxcost,\n\t * v.cost); } }\n\t * \n\t * } return maxcost; }\n\t **/\n\n\tstatic boolean[] vis2;\n\n\tstatic boolean f2 = false;\n\n\tstatic long[][] matMul(long[][] a2, long[][] b, int p, int q, int r) // C(p x r) = A(p x q) x (q x r) -- O(p x q x\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t// r)\n\t{\n\t\tlong[][] C = new long[p][r];\n\t\tfor (int i = 0; i < p; ++i) {\n\t\t\tfor (int j = 0; j < r; ++j) {\n\t\t\t\tfor (int k = 0; k < q; ++k) {\n\t\t\t\t\tC[i][j] = (C[i][j] + (a2[i][k] % mod * b[k][j] % mod)) % mod;\n\t\t\t\t\tC[i][j] %= mod;\n\t\t\t\t}\n\n\t\t\t}\n\t\t}\n\t\treturn C;\n\t}\n\tpublic static int[] schuffle(int[] a2) {\n\t\tfor (int i = 0; i < a2.length; i++) {\n\t\t\tint x = (int) (Math.random() * a2.length);\n\t\t\tint temp = a2[x];\n\t\t\ta2[x] = a2[i];\n\t\t\ta2[i] = temp;\n\t\t}\n\t\treturn a2;\n\t}\n\n\n\tstatic boolean vis[];\n\tstatic HashSet set = new HashSet();\n\n\tstatic long modPow(long ways, long count, long mod) // O(log e)\n\t{\n\t\tways %= mod;\n\t\tlong res = 1;\n\t\twhile (count > 0) {\n\t\t\tif ((count & 1) == 1)\n\t\t\t\tres = (res * ways) % mod;\n\t\t\tways = (ways * ways) % mod;\n\t\t\tcount >>= 1;\n\t\t}\n\t\treturn res % mod;\n\t}\n\n\tstatic long gcd(long l, long o) {\n\t\tif (o == 0) {\n\t\t\treturn l;\n\t\t}\n\t\treturn gcd(o, l % o);\n\t}\n\n\tstatic int[] isComposite;\n\tstatic int[] valid;\n\n\tstatic ArrayList primes;\n\tstatic ArrayList l1;\n\n\t\n\tstatic TreeSet primus = new TreeSet();\n\t\n\tstatic void sieveLinear(int N)\n\t{\n\t\tint[] lp = new int[N + 1];\t\t\t\t\t\t\t\t//lp[i] = least prime divisor of i\n\t\tfor(int i = 2; i <= N; ++i)\n\t\t{\n\t\t\tif(lp[i] == 0)\n\t\t\t{\n\t\t\t\tprimus.add(i);\n\t\t\t\tlp[i] = i;\n\t\t\t}\n\t\t\tint curLP = lp[i];\n\t\t\tfor(int p: primus)\n\t\t\t\tif(p > curLP || p * i > N)\n\t\t\t\t\tbreak;\n\t\t\t\telse\n\t\t\t\t\tlp[p * i] = i;\n\t\t}\n\t}\n\t\n\n\tpublic static long[] schuffle(long[] a2) {\n\t\tfor (int i = 0; i < a2.length; i++) {\n\t\t\tint x = (int) (Math.random() * a2.length);\n\t\t\tlong temp = a2[x];\n\t\t\ta2[x] = a2[i];\n\t\t\ta2[i] = temp;\n\t\t}\n\t\treturn a2;\n\t}\n\n\tstatic class Scanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream system) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(system));\n\t\t}\n\n\t\tpublic Scanner(String file) throws Exception {\n\t\t\tbr = new BufferedReader(new FileReader(file));\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic String nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic char nextChar() throws IOException {\n\t\t\treturn next().charAt(0);\n\t\t}\n\n\t\tpublic Long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic boolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t\tpublic void waitForInput() throws InterruptedException {\n\t\t\tThread.sleep(3000);\n\t\t}\n\n\t\tpublic int[] nxtArr(int n) throws IOException {\n\t\t\tint[] ans = new int[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tans[i] = nextInt();\n\t\t\treturn ans;\n\t\t}\n\t\t\n\t}\n\tpublic static int[] sortarray(int a[]) {\n\t\tschuffle(a);\n\t\tArrays.sort(a);\n\t\treturn a;\n\t\t}\n\t\tpublic static long[] sortarray(long a[]) {\n\t\t\tschuffle(a);\n\t\t\tArrays.sort(a);\n\t\t\treturn a;\n\t\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8e57bca24431e8c69763b4ea48f2ff06", "src_uid": "9c700390ac13942cbde7c3428965b18a", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class Chores {\n public Chores() {\n }\n public static void main(String[] args) {\n Scanner kbd = new Scanner(System.in);\n System.out.println('');\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "fe301abae728f16812a37ed0df394ee6", "src_uid": "92a233f8d9c73d9f33e4e6116b7d0a96", "difficulty": 800.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.Scanner;\n\nimport org.omg.CORBA.PUBLIC_MEMBER;\n\npublic class my_class {\n\t\n\tpublic static ArrayList nums = new ArrayList<>();\n\tpublic static int rec(int i, int num, int arr[]){\n\t\tif(i < arr.length){\n\t\t\trec(i + 1, num + arr[i], arr);\n\t\t\trec(i + 1, num - arr[i], arr);\n\t\t\tif(i != 0)\n\t\t\t\trec(i + 1, num * arr[i], arr);\n\t\t}else{\n\t\t\tif(!nums.contains(Math.abs(num)) && (num != 0)){\n\t\t\t\tnums.add(Math.abs(num));\n\t\t\t}\n\t\t}\n\t\treturn 0;\n\t}\n\tpublic static void rec1(int arr[], int qwer){\n\t\tif(arr.length >= 2){\n\t\t\trec(0,0, arr);\n\t\t\tif(arr.length > 2){\n\t\t\t\tfor(int i = 0; i < arr.length - 1;i++){\n\t\t\t\t\tif(i + 1 != qwer){\n\t\t\t\t\t\tint[] tmpA = new int[arr.length - 1];\n\t\t\t\t\t\tfor(int s = 0; s < tmpA.length; s++){\n\t\t\t\t\t\t\tif(s < i)\n\t\t\t\t\t\t\t\ttmpA[s] = arr[s];\n\t\t\t\t\t\t\tif(s == i)\n\t\t\t\t\t\t\t\ttmpA[s] = arr[s]*10 + arr[s + 1];\n\t\t\t\t\t\t\tif(s > i)\n\t\t\t\t\t\t\t\ttmpA[s] = arr[s + 1];\n\t\t\t\t\t\t}\n\t\t\t\t\t\trec1(tmpA,i);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tpublic static void main(String[] args) throws Exception{\n\t\tint k = nextInt(), m = nextInt();\n\t\tint sum = 0;\n\t\tfor(int counter = 0; counter <= 9999;counter++){\n\t\t\tint arr[] = new int[4];\n\t\t\tnums.clear();\n\t\t\tint tmp = counter;\n\t\t\tfor(int i = arr.length - 1;tmp != 0;i--){\n\t\t\t\tarr[i] = tmp % 10;\n\t\t\t\ttmp = tmp / 10;\n\t\t\t}\n\t\t\tnums.add(counter);\n\t\t\trec1(arr,0);\n\t\t\tint l;\n\t\t\tfor(int i = 0; i < nums.size();i++){\n\t\t\t\tif(sum > m - 1)\n\t\t\t\t\tbreak;\n\t\t\t\tif(nums.get(i)/10000 == 0){\n\t\t\t\t\tif(nums.get(i) > k)\n\t\t\t\t\t\tl = nums.get(i) - k;\n\t\t\t\t\telse\n\t\t\t\t\t\tl = k - nums.get(i);\n\t\t\t\t\tl = (((l*10 + arr[0])*10 + arr[1])*10 + arr[2])*10 + arr[3];\n\t\t\t\t\ttmp = l;\n\t\t\t\t\tint s = 0;\n\t\t\t\t\twhile(tmp/10 != 0){\n\t\t\t\t\t\ttmp = tmp/10;\n\t\t\t\t\t\ts++;\n\t\t\t\t\t}\n\t\t\t\t\ts = 7 - s;\n\t\t\t\t\twhile(s != 0){\n\t\t\t\t\t\tprint(0);\n\t\t\t\t\t\ts--;\n\t\t\t\t\t}\n\t\t\t\t\tprintln(l);\n\t\t\t\t\tsum++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(sum > m - 1){\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t//println(sum);\n\t}\t\n\tprivate static PrintWriter out = new PrintWriter(System.out);\n\tprivate static BufferedReader inB = new BufferedReader(new InputStreamReader(System.in)); \n\tprivate static StreamTokenizer in = new StreamTokenizer(inB);\n\n\tprivate static void exit(Object o) throws Exception {\n\t\tout.println(o);\n\t\tout.flush();\n\t\tSystem.exit(0);\n\t}\n\tprivate static void println(Object o) throws Exception{\n\t\tout.println(o);\n\t\tout.flush();\n\t}\n\tprivate static void print(Object o) throws Exception{\n\t\tout.print(o);\n\t\tout.flush();\n\t}\n\tprivate static long nextLong() throws Exception {\n\t\tin.nextToken();\n\t\treturn (long)in.nval;\n\t} \n\tprivate static int nextInt() throws Exception {\n\t\tin.nextToken();\n\t\treturn (int)in.nval;\n\t} \n\tprivate static String nextString() throws Exception {\n\t\tin.nextToken();\n\t\treturn in.sval; \n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9d898448bed02cda4da129294b685789", "src_uid": "4720ca1d2f4b7a0e553a3ea07a76943c", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.time.temporal.IsoFields;\nimport java.util.*;\n\npublic class e1 {\n\tstatic int a[][];\n\tstatic Scanner in;\n\tstatic long curans;\n\tstatic long ans;\n\t\n\tstatic int read() {\n\t\treturn in.nextInt();\n\t}\n\n\t\n\tstatic void gen1(int i, int n){\n\t\ttry {\n\t\t\ta[i] = new int[n];\n\n\t\t\tgen(i, 0, n);\n\t\t\tgen1(i + 1, n);\n\n\t\t} catch (ArrayIndexOutOfBoundsException e) {\n\t\t\treturn;\n\t\t}\n\t}\n\t\n\tstatic void gen(int i, int j, int n) {\n\t\ttry {\n\t\t\ta[i][j] = 0;\n\n\t\t\n\t\t} catch (ArrayIndexOutOfBoundsException e) {\n\t\t\treturn;\n\t\t}\n\n\t\ta[i][j] = read();\n\t\tgen(i, j + 1, n);\n\t}\n\t\n\tstatic void gen2(int i, int n){\n\t\ttry {\n\t\t\ta[i][0]++;\n\n\t\t} catch (ArrayIndexOutOfBoundsException e) {\n\t\t\treturn;\n\t\t}\n\t\n\t\ta[i][0]--;\n\n\t\tgen3(i, 0, n);\n\t\tgen2(i + 1, n);\n\t}\n\t\n\tstatic void gen3(int i, int j, int n) {\n\t\ttry {\n\t\t\ta[i][j]++;\n\t\t} catch (ArrayIndexOutOfBoundsException e) {\n\t\t\treturn;\n\t\t}\n\t\ta[i][j]--;\n\t\t\n\t\tgen4(i, j, 0, n);\n\t\tgen3(i, j + 1, n);\n\n\n\t}\n\t\n\tstatic void gen4(int i, int j, int k, int n) {\n\t\ttry {\n\t\t\ta[i][k]++;\n\n\t\t} catch (ArrayIndexOutOfBoundsException e) {\n\t\t\treturn;\n\t\t}\n\t\ta[i][k]--;\n\t\ta[i][j] = Math.min(a[i][j], a[i][k] + a[k][j]);\n\t\tgen4(i, j, k + 1, n);\n\n\t}\n\t\n\tstatic void gen5(int i, int n){\n\t\ttry {\n\t\t\ta[i][0]++;\n\n\t\t} catch (ArrayIndexOutOfBoundsException e) {\n\t\t\treturn;\n\t\t}\n\t\ta[i][0]--;\n\n\t\tgen6(i, 0, n);\n\t\tgen5(i + 1, n);\n\t}\n\t\n\tstatic void gen6(int i, int j, int n) {\n\t\ttry {\n\t\t\ta[i][j]++;\n\t\t\t\n\t\t\t\n\t\t} catch (ArrayIndexOutOfBoundsException e) {\n\t\t\treturn;\n\t\t}\n\t\t\n\t\ta[i][j]--;\n\t\t\n\t\tint b[] = new int[i];\n\t\t\n\t\ttry{\n\t\t\tb[j] = a[i][j];\t\t\n\t\t}\n\t\tcatch (ArrayIndexOutOfBoundsException e){\n\t\t\tb = new int[n];\n\t\t}\n\n\t\tans = Math.max(ans, a[i][j]);\n\t\tgen6(i, j + 1, n);\n\n\n\t}\n\n\t\n\tpublic static void main(String[] args) throws FileNotFoundException {\n\t\tin = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\n\t\tint n = in.nextInt();\n\n\t\ta = new int[n][];\n\n\t\tgen1(0, n);\n\t\tgen2(0, n);\n\t\tans = 0;\n\t\tgen5(0, n);\n\t\tout.println(ans);\n\t\t\n\t\tout.close();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "656f67df6ef626c17b81106acd8ef1a0", "src_uid": "bbd210065f8b32de048a2d9b1b033ed5", "difficulty": 2000.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class C {\n\n int n, m, k;\n int[][] f;\n int[][] c;\n boolean[] mask;\n int best = Integer.MAX_VALUE;\n\n void calc(int i, int j, int cnt) {\n if (cnt < best) {\n if (i == n - 1 && j == m) {\n best = cnt;\n } else {\n if (j == m) {\n j = 0;\n ++i;\n }\n if (c[i][j] > 0) {\n calc(i, j + 1, cnt);\n } else {\n for (int r = 1; r <= k; ++r) {\n if (!mask[r - 1]) {\n c[i][j] = r;\n mask[r - 1] = true;\n if (j < m - 1) {\n c[i][j + 1] = r;\n int d = 0;\n if (c[i][j] != f[i][j]) ++d;\n if (c[i][j + 1] != f[i][j + 1]) ++d;\n calc(i, j + 2, cnt + d);\n c[i][j + 1] = 0;\n }\n if (i < n - 1) {\n c[i + 1][j] = r;\n int d = 0;\n if (c[i][j] != f[i][j]) ++d;\n if (c[i + 1][j] != f[i + 1][j]) ++d;\n calc(i, j + 1, cnt + d);\n c[i + 1][j] = 0;\n }\n mask[r - 1] = false;\n }\n }\n c[i][j] = 0;\n }\n }\n }\n }\n\n void solve() throws IOException {\n in(\"__std\"); out(\"__std\");\n\n n = readInt();\n m = readInt();\n k = n * m / 2;\n f = new int[n][m];\n c = new int[n][m];\n mask = new boolean[k];\n for (int i = 0; i < n; ++i) {\n for (int j = 0; j < m; ++j) {\n f[i][j] = readInt();\n }\n }\n calc(0, 0, 0);\n println(best);\n\n exit();\n }\n\n void in(String name) throws IOException {\n if (name.equals(\"__std\")) {\n in = new BufferedReader(new InputStreamReader(System.in));\n } else {\n in = new BufferedReader(new FileReader(name));\n }\n }\n\n void out(String name) throws IOException {\n if (name.equals(\"__std\")) {\n out = new PrintWriter(System.out);\n } else {\n out = new PrintWriter(name);\n }\n }\n\n void exit() {\n out.close();\n System.exit(0);\n }\n\n char readChar() throws IOException {\n return (char) in.read();\n }\n\n int readInt() throws IOException {\n return Integer.parseInt(readToken());\n }\n\n long readLong() throws IOException {\n return Long.parseLong(readToken());\n }\n\n double readDouble() throws IOException {\n return Double.parseDouble(readToken());\n }\n\n String readLine() throws IOException {\n st = null;\n return in.readLine();\n }\n\n String readToken() throws IOException {\n while (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(in.readLine());\n }\n return st.nextToken();\n }\n\n boolean eof() throws IOException {\n return !in.ready();\n }\n\n void print(String format, Object ... args) {\n out.print(new Formatter(Locale.US).format(format, args));\n }\n\n void println(String format, Object ... args) {\n out.println(new Formatter(Locale.US).format(format, args));\n }\n\n void print(Object value) {\n out.print(value);\n }\n\n void println(Object value) {\n out.println(value);\n }\n\n void println() {\n out.println();\n }\n\n StringTokenizer st;\n\n BufferedReader in;\n PrintWriter out;\n\n public static void main(String[] args) throws IOException {\n new C().solve();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "048acad14e2f1021affa451b8421fa07", "src_uid": "1f0e8bbd5bf4fcdea927fbb505a8949b", "difficulty": 2200.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n FastScanner in;\n PrintWriter out;\n\n Main () {\n in = new FastScanner(IO_Type.CONSOLE).getScanner();\n out = new FastWriter(IO_Type.CONSOLE).getWriter();\n\n //in = new FastScanner(IO_Type.TEST, \"test.txt\").getScanner();\n //out = new FastWriter(IO_Type.TEST, \"result.txt\").getWriter();\n\n //in = new FastScanner(IO_Type.FILE, \"input.txt\").getScanner();\n //out = new FastWriter(IO_Type.TEST, \"output.txt\").getWriter();\n }\n\n public static void main (String[]args) {\n Main task = new Main();\n task.solve();\n task.close();\n }\n\n public void close () {\n in.close();\n out.close();\n }\n\n public void solve () {\n int n = in.nextInt();\n System.out.println((int)(2*Math.pow(n + 1, 3) - 3));\n }\n \n public String getText(String s, int q) {\n String ss = \"\";\n for (int i = 0; i < s.length(); i++) {\n if (s.charAt(i) >= '\u0430' && s.charAt(i) <= '\u044f') {\n ss += (char)(s.charAt(i) + q);\n }\n else {\n ss += s.charAt(i);\n }\n }\n return ss;\n }\n \n}\n\nclass Algebra {\n /****\n * Number of co-prime numbers on [1, n].\n * Number a is Co-prime if gcd (a, n) == 1\n * O (sqrt(n))\n ****/\n public static int phi(int n) {\n int result = n;\n for (int i = 2; i*i <= n; ++i) {\n if (n % i == 0) {\n while (n % i == 0) {\n n /= i;\n }\n result -= result / i;\n }\n }\n if (n > 1) {\n result -= result / n;\n }\n return result;\n }\n\n /****\n * Raise number a to power of n.\n * O (log n)\n ****/\n public static int binpow (int a, int n) {\n int res = 1;\n while (n != 0) {\n if ((n & 1) == 1)\n res *= a;\n a *= a;\n n >>= 1;\n }\n return res;\n }\n\n /****\n * Finding the greatest common divisor of two numbers.\n * O (log min(a, b))\n ****/\n public static int gcd (int a, int b) {\n return (b != 0) ? gcd (b, a % b) : a;\n }\n\n /****\n * Finding the lowest common multiple of two numbers.\n * O (log min(a, b))\n ****/\n public static int lcm (int a, int b) {\n return a / gcd (a, b) * b;\n }\n\n /****\n * Eratosthenes Sieve of numbers - [0..n]. True - simple, False - not simple.\n * O (n log log n)\n ****/\n public static boolean[] sieveOfEratosthenes (int n) {\n boolean [] prime = new boolean[n + 1];\n Arrays.fill(prime, true);\n prime[0] = prime[1] = false;\n for (int i=2; i<=n; ++i) {\n if (prime[i]) {\n if (i * 1L * i <= n) {\n for (int j=i*i; j<=n; j+=i) {\n prime[j] = false;\n }\n }\n }\n }\n return prime;\n }\n}\n\nclass IO_Type {\n\n public static String CONSOLE = \"console\";\n public static String FILE = \"file\";\n public static String TEST = \"test\";\n\n}\n\nclass FastScanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n FastScanner getScanner() {\n return this;\n }\n\n FastScanner(String type) {\n if (type.equals(\"console\")) {\n FastScanner(System.in);\n } \n }\n \n FastScanner(String type, String inFileName) {\n if (type.equals(\"file\")) {\n File f = new File(inFileName);\n try {\n FastScanner(new FileInputStream(f));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n else if (type.equals(\"test\")) {\n File f = new File(inFileName);\n try {\n FastScanner(new FileInputStream(f));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n }\n \n void FastScanner(InputStream in) {\n br = new BufferedReader(new InputStreamReader(in));\n }\n \n String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n System.err.println(e);\n return \"\";\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 float nextFloat() {\n return Float.parseFloat(next());\n }\n BigInteger nextBigInt() {\n return new BigInteger(next());\n }\n\n void close() {\n try {\n br.close();\n }\n catch (IOException e) {\n }\n }\n}\n\nclass FastWriter {\n\n PrintWriter pw;\n\n PrintWriter getWriter() {\n return pw;\n }\n \n FastWriter(String type) {\n FastWriter(type);\n }\n \n FastWriter (String type, String outFileName) {\n FastWriter(type, outFileName);\n }\n\n PrintWriter FastWriter(String type) {\n if (type.equals(\"console\")) {\n pw = new PrintWriter(System.out);\n }\n return pw;\n }\n\n PrintWriter FastWriter(String type, String outFileName) {\n if (type.equals(\"console\")) {\n pw = new PrintWriter(System.out);\n }\n else if (type.equals(\"test\")) {\n try {\n pw = new PrintWriter(new File(outFileName));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n else if (type.equals(\"file\")) {\n try {\n pw = new PrintWriter(new File(outFileName));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n return pw;\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "b0274d0fbff6439c9bb05d1bb4291c56", "src_uid": "6ff30f5a9afc3f7befca813469188aab", "difficulty": 1600.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskC {\n public long a;\n public long b;\n public char[] l;\n public char[] r;\n public int[] arr;\n public int ans;\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n a = in.nextLong();\n b = in.nextLong();\n String sa = String.valueOf(a), sb = String.valueOf(b);\n while (sa.length() < sb.length()) sa = \"0\" + sa;\n l = sa.toCharArray();\n r = sb.toCharArray();\n arr = new int[10];\n dfs(0, l.length);\n out.println(ans);\n }\n\n public void dfs(int num, int left) {\n if (num == 9) {\n arr[9] = left;\n if (ok(arr)) {\n ans++;\n }\n return;\n }\n for (int i = 0; i <= left; i++) {\n arr[num] = i;\n dfs(num + 1, left - i);\n }\n }\n\n public boolean ok(int[] arr) {\n long num1 = 0;\n for (int cdig = 9; cdig >= 0; cdig--) {\n for (int k = 0; k < arr[cdig]; k++) {\n num1 = num1 * 10 + cdig;\n }\n }\n if (num1 < a) {\n return false;\n }\n long num2 = 0;\n for (int cdig = 0; cdig <= 9; cdig++) {\n for (int k = 0; k < arr[cdig]; k++) {\n num2 = num2 * 10 + cdig;\n }\n }\n if (num2 > b) {\n return false;\n }\n\n int[] brr = Arrays.copyOf(arr, 10);\n long cnum = 0;\n outer:\n for (int i = 0; i < l.length; i++) {\n boolean found = false;\n for (int cdig = 0; cdig <= 9; cdig++) {\n if (brr[cdig] > 0) {\n brr[cdig]--;\n long ctail = cnum * 10 + cdig;\n for (int dd = 9; dd >= 0; dd--) {\n for (int k = 0; k < brr[dd]; k++) ctail = ctail * 10 + dd;\n }\n if (ctail < a) {\n brr[cdig]++;\n continue;\n }\n\n ctail = cnum * 10 + cdig;\n\n if (ctail > b) {\n brr[cdig]++;\n continue;\n }\n\n cnum = cnum * 10 + cdig;\n if (cdig > l[i] - '0' && cdig < r[i] - '0') return true;\n if (cdig > l[i] - '0') {\n ctail = cnum;\n for (int dd = 0; dd <= 9; dd++) {\n for (int k = 0; k < brr[dd]; k++) ctail = ctail * 10 + dd;\n }\n return ctail <= b;\n } else if (cdig < r[i] - '0') {\n ctail = cnum;\n for (int dd = 9; dd >= 0; dd--) {\n for (int k = 0; k < brr[dd]; k++) ctail = ctail * 10 + dd;\n }\n return ctail >= a;\n }\n found = true;\n break;\n }\n }\n if (!found) return false;\n }\n return true;\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void println(int i) {\n writer.println(i);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (this.numChars == -1) {\n throw new InputMismatchException();\n } else {\n if (this.curChar >= this.numChars) {\n this.curChar = 0;\n\n try {\n this.numChars = this.stream.read(this.buf);\n } catch (IOException var2) {\n throw new InputMismatchException();\n }\n\n if (this.numChars <= 0) {\n return -1;\n }\n }\n\n return this.buf[this.curChar++];\n }\n }\n\n public long nextLong() {\n int c;\n for (c = this.read(); isSpaceChar(c); c = this.read()) {\n ;\n }\n\n byte sgn = 1;\n if (c == 45) {\n sgn = -1;\n c = this.read();\n }\n\n long res = 0L;\n\n while (c >= 48 && c <= 57) {\n res *= 10L;\n res += (long) (c - 48);\n c = this.read();\n if (isSpaceChar(c)) {\n return res * (long) sgn;\n }\n }\n\n throw new InputMismatchException();\n }\n\n public static boolean isSpaceChar(int c) {\n return c == 32 || c == 10 || c == 13 || c == 9 || c == -1;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3ab723c4dbbd277dab992b9b5b016580", "src_uid": "adfa5f280eefbacdbaa4ad605402b57a", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\npublic class A{\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n int a = sc.nextInt();\n int sumA=0;\n for(int i = 0; i map = new HashMap();\n int num = 0;\n for (int i = 0; i < n; i++) {\n for (String val : data) {\n int a = color.indexOf(val.charAt(0));\n int b = val.charAt(1) - '1';\n if (!check[a]) {\n map.put(num++, val.charAt(0));\n check[a] = true;\n }\n if (!mark[b]) {\n map.put(num++, val.charAt(1));\n mark[b] = true;\n }\n }\n }\n int result = Integer.MAX_VALUE;\n do {\n boolean[] left = new boolean[n];\n boolean[] right = new boolean[n];\n int tmp = 0;\n int index = 0;\n // System.out.println(\"Start \" );\n while (!isOk(left, right, data)) {\n tmp++;\n char v = map.get(per[index]);\n // System.out.print(v + \" \");\n for (int i = 0; i < n; i++) {\n if (data[i].charAt(0) == v) {\n left[i] = true;\n } else if (data[i].charAt(1) == v) {\n right[i] = true;\n }\n }\n index++;\n }\n // System.out.println();\n result = Math.min(result, tmp);\n } while (nextPer(per));\n out.println(result);\n out.close();\n }\n\n public static boolean isOk(boolean[] left, boolean[] right, String[] data) {\n\n String last = null;\n ArrayList list = new ArrayList();\n int[] a = new int[5];\n int[] b = new int[5];\n String color = \"RGBYW\";\n for (int i = 0; i < left.length; i++) {\n if (!left[i] || !right[i]) {\n if (last != null) {\n if (!data[i].equals(last)) {\n int index = color.indexOf(data[i].charAt(0));\n int other = data[i].charAt(1) - '1';\n a[index]++;\n b[other]++;\n list.add(i);\n }\n } else {\n last = data[i];\n list.add(i);\n }\n }\n }\n if (list.size() <= 1) {\n return true;\n }\n int c = list.size();\n for (int i : list) {\n int index = color.indexOf(data[i].charAt(0));\n int other = data[i].charAt(1) - '1';\n\n if (a[index] == 1 && left[i]) {\n c--;\n }else if(b[other] == 1 && right[i]){\n c--;\n }\n }\n\n return c <= 1;\n }\n\n public static int[][] powSquareMatrix(int[][] A, long p) {\n int[][] unit = new int[A.length][A.length];\n for (int i = 0; i < unit.length; i++) {\n unit[i][i] = 1;\n }\n if (p == 0) {\n return unit;\n }\n int[][] val = powSquareMatrix(A, p / 2);\n if (p % 2 == 0) {\n return mulMatrix(val, val);\n } else {\n return mulMatrix(A, mulMatrix(val, val));\n }\n\n }\n\n public static int[][] mulMatrix(int[][] A, int[][] B) {\n int[][] result = new int[A.length][B[0].length];\n for (int i = 0; i < result.length; i++) {\n for (int j = 0; j < result[0].length; j++) {\n long temp = 0;\n for (int k = 0; k < A[0].length; k++) {\n\n temp += ((long) A[i][k] * B[k][j] % Mod);\n temp %= Mod;\n }\n temp %= Mod;\n result[i][j] = (int) temp;\n }\n }\n\n return result;\n }\n\n static double dist(Point a, Point b) {\n long total = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);\n return Math.sqrt(total);\n }\n\n static class Point implements Comparable {\n\n int x, y;\n\n public Point(int x, int y) {\n this.x = x;\n this.y = y;\n\n }\n\n @Override\n public int compareTo(Point o) {\n if (x != o.x) {\n return x - o.x;\n }\n return y - o.y;\n }\n }\n\n public static boolean nextPer(int[] data) {\n int i = data.length - 1;\n while (i > 0 && data[i] < data[i - 1]) {\n i--;\n }\n if (i == 0) {\n return false;\n }\n int j = data.length - 1;\n while (data[j] < data[i - 1]) {\n j--;\n }\n int temp = data[i - 1];\n data[i - 1] = data[j];\n data[j] = temp;\n Arrays.sort(data, i, data.length);\n return true;\n }\n\n static class FT {\n\n int[] data;\n\n FT(int n) {\n data = new int[n];\n }\n\n void update(int index, int val) {\n // System.out.println(\"UPDATE INDEX \" + index);\n while (index < data.length) {\n data[index] += val;\n index += index & (-index);\n\n // System.out.println(\"NEXT \" +index);\n }\n }\n\n int get(int index) {\n // System.out.println(\"GET INDEX \" + index);\n int result = 0;\n while (index > 0) {\n result += data[index];\n index -= index & (-index);\n // System.out.println(\"BACK \" + index);\n }\n return result;\n }\n }\n\n static int gcd(int a, int b) {\n if (b == 0) {\n return a;\n } else {\n return gcd(b, a % b);\n }\n }\n\n static int pow(int a, int b) {\n if (b == 0) {\n return 1;\n }\n if (b == 1) {\n return a;\n }\n int val = pow(a, b / 2);\n if (b % 2 == 0) {\n\n return val * val;\n } else {\n return val * val * a;\n }\n }\n\n// static Point intersect(Point a, Point b, Point c) {\n// double D = cross(a, b);\n// if (D != 0) {\n// return new Point(cross(c, b) / D, cross(a, c) / D);\n// }\n// return null;\n// }\n//\n// static Point convert(Point a, double angle) {\n// double x = a.x * cos(angle) - a.y * sin(angle);\n// double y = a.x * sin(angle) + a.y * cos(angle);\n// return new Point(x, y);\n// }\n// static Point minus(Point a, Point b) {\n// return new Point(a.x - b.x, a.y - b.y);\n// }\n//\n// static Point add(Point a, Point b) {\n// return new Point(a.x + b.x, a.y + b.y);\n// }\n//\n// static double cross(Point a, Point b) {\n// return a.x * b.y - a.y * b.x;\n//\n//\n// }\n//\n// static class Point {\n//\n// int x, y;\n//\n// Point(int x, int y) {\n// this.x = x;\n// this.y = y;\n// }\n//\n// @Override\n// public String toString() {\n// return \"Point: \" + x + \" \" + y;\n// }\n// }\n static class Scanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n public Scanner() throws FileNotFoundException {\n //System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));\n br = new BufferedReader(new InputStreamReader(System.in));\n //br = new BufferedReader(new FileReader(new File(\"A-large-practice.in\")));\n }\n\n public String next() {\n\n\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n return st.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public String nextLine() {\n st = null;\n try {\n return br.readLine();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n\n public boolean endLine() {\n try {\n String next = br.readLine();\n while (next != null && next.trim().isEmpty()) {\n next = br.readLine();\n }\n if (next == null) {\n return true;\n }\n st = new StringTokenizer(next);\n return st.hasMoreTokens();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fd9e62f1616ab9114d18b101aac04cca", "src_uid": "3b12863997b377b47bae43566ec1a63b", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n\tstatic final int N=1000005;\n\tstatic int a[]=new int[N];\n\tstatic int t[]=new int[N];\n\tstatic int ans=0;\n\t@SuppressWarnings(\"unchecked\")\n\tstatic ArrayListG[]=new ArrayList[N];\n\tstatic HashMap,Integer>vis=new HashMap,Integer>();\n\tstatic int sz;\n\tstatic class cmp implements Comparator{\n\t\t@Override \n\t\tpublic int compare(Object o1,Object o2) {\n\t\t\tInteger p1=(Integer)o1;\n\t\t\tInteger p2=(Integer)o2;\n\t\t\treturn p1>p2?1:-1;\n\t\t}\n\t}\n\tstatic int dfs(int u,int fa) {\n\t\tArrayListtemp=new ArrayList();\n\t\tfor(int i=0;i();\n\t \tif(G[v]==null) G[v]=new ArrayList();\n\t \tG[u].add(v);G[v].add(u);\n\t }\n\t int ans=0;\n\t HashMapmap=new HashMap();\n\t for(int i=1;i<=n;i++) {\n\t \tif(G[i].size()==4) continue;\n\t \tint id=dfs(i,-1);\n\t \tif(!map.containsKey(id)) {\n\t \t\tans++;\n\t \t\tmap.put(id, 1);\n\t \t}\n\t }\n\t out.println(ans);\n\t out.flush();\n\t}\n\tstatic class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n public String next() {\n while (tokenizer == null || !tokenizer.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 }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ac0092be6937f820c93954927d4d5f80", "src_uid": "3c5aedd5d3bc12dca3e921c95ef05270", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class Main{\n\tstatic int[] p, rank, treeNode,adj[];\n\tstatic boolean[]root;\n\tstatic int numSets,N;\n\tstatic int lastNode=0;\n\tstatic void preProcessDSU(int n) {\n\t\tN=n;\n\t\tp = new int[numSets = N];\n\t\trank = new int[N];\n\t\ttreeNode = new int[N];\n\t\troot=new boolean[N<<1];\n\t\tadj=new int[N<<1][2];\n\t\t\n\t\tfor (int i = 0; i < N; i++) { \n\t\t\tp[i] = i; treeNode[i] = lastNode++; root[i]=true;\n\t\t\tadj[i<<1][0]=adj[i<<1][1]=adj[i<<1|1][0]=adj[i<<1|1][1]=-1;\n\t\t}\n\t}\n\tpublic static int findSet(int i) { return p[i] == i ? i : (p[i] = findSet(p[i])); }\n\t\n\tpublic static boolean isSameSet(int i, int j) { return findSet(i) == findSet(j); }\n\t\n\tpublic static void unionSet(int i, int j) \n\t{ \n\t\tif (isSameSet(i, j)) \n\t\t\treturn;\n\t\tnumSets--; \n\t\tint x = findSet(i), y = findSet(j);\n\t\t\n\t\tint u=treeNode[x],v=treeNode[y];\n\t\troot[u]=false;root[v]=false;\n\t\tint newRoot=lastNode++;\n\t\troot[newRoot]=true;\n\t\tadj[newRoot][0]=u;adj[newRoot][1]=v;\n\t\t\n\t\tif(rank[x] > rank[y]) { p[y] = x; treeNode[x]=newRoot;}\n\t\telse\n\t\t{\tp[x] = y; treeNode[y]=newRoot;\n\t\t\tif(rank[x] == rank[y]) rank[y]++; \n\t\t} \n\t\t\n\t}\n\tstatic int time,tin[],tout[];\n\tstatic void dfs(int i) {\n\t\ttin[i]=++time;\n\t\tfor(int j:adj[i]) {\n\t\t\tif(j==-1)continue;\n\t\t\tdfs(j);\n\t\t}\n\t\ttout[i]=time;\n\t}\n\tstatic int[]segTree,index;\n\tstatic void updatePoint(int idx) {\n\t\tupdatePoint(1, 1, time, idx);\n\t}\n\tstatic void updatePoint(int node,int l,int r,int idx) {\n\t\tif(l==r) {\n\t\t\tsegTree[node]=0;\n\t\t\treturn;\n\t\t}\n\t\tint mid=(l+r)>>1;\n\t\tif(idx<=mid) {\n\t\t\tupdatePoint(node<<1, l, mid, idx);\n\t\t}\n\t\telse {\n\t\t\tupdatePoint(node<<1|1, mid+1, r, idx);\n\t\t}\n\t\tif(segTree[node<<1|1]>segTree[node<<1]) {\n\t\t\tsegTree[node]=segTree[node<<1|1];\n\t\t\tindex[node]=index[node<<1|1];\n\t\t}\n\t\telse {\n\t\t\tsegTree[node]=segTree[node<<1];\n\t\t\tindex[node]=index[node<<1];\n\t\t}\n\t}\n\tstatic int[] query(int l,int r) {\n\t\treturn query(1, 1, time,l,r);\n\t}\n\tstatic int[] query(int node,int curL,int curR,int l,int r) {\n\t\tif(curRr)return new int[] {-1,-1};\n\t\tif(curL>=l && curR<=r) {\n\t\t\treturn new int[] {segTree[node],index[node]};\n\t\t}\n\t\tint mid=(curL+curR)>>1;\n\t\tint[]q1=query(node<<1, curL, mid, l, r),q2=query(node<<1|1, mid+1, curR, l, r);\n\t\tif(q1[0]>q2[0]) {\n\t\t\treturn q1;\n\t\t}\n\t\treturn q2;\n\t}\n\tstatic void insert(int idx,int val) {\n\t\tinsert(1, 1, time, idx,val);\n\t}\n\tstatic void insert(int node,int l,int r,int idx,int val) {\n\t\tif(l==r) {\n\t\t\tsegTree[node]=val;\n\t\t\tindex[node]=idx;\n\t\t\treturn;\n\t\t}\n\t\tint mid=(l+r)>>1;\n\t\tif(idx<=mid) {\n\t\t\tinsert(node<<1, l, mid, idx,val);\n\t\t}\n\t\telse {\n\t\t\tinsert(node<<1|1, mid+1, r, idx,val);\n\t\t}\n\t\tif(segTree[node<<1|1]>segTree[node<<1]) {\n\t\t\tsegTree[node]=segTree[node<<1|1];\n\t\t\tindex[node]=index[node<<1|1];\n\t\t}\n\t\telse {\n\t\t\tsegTree[node]=segTree[node<<1];\n\t\t\tindex[node]=index[node<<1];\n\t\t}\n\t}\n\tstatic void main() throws Exception{\n\t\tint n=sc.nextInt(),m=sc.nextInt(),q=sc.nextInt();\n\t\tint[]vals=sc.intArr(n);\n\t\tint[][]edges=new int[m][];\n\t\tfor(int i=0;i=0;i--) {\n\t\t\tif(qs[i][0]==1) {\n\t\t\t\tsubtreeRoot[i]=treeNode[findSet(qs[i][1])];\n\t\t\t}\n\t\t\telse {\n\t\t\t\tint edge=qs[i][1];\n\t\t\t\tunionSet(edges[edge][0], edges[edge][1]);\n\t\t\t}\n\t\t}\n\t\ttin=new int[n<<1];\n\t\ttout=new int[n<<1];\n\t\tfor(int i=0;i0)\n\t\t\tmain();\n\t\tpw.flush();\n\t}\n\tstatic PrintWriter pw;\n\tstatic MScanner sc;\n\tstatic class MScanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\t\tpublic MScanner(InputStream system) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(system));\n\t\t}\n \n\t\tpublic MScanner(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\t\tpublic int[] intArr(int n) throws IOException {\n\t int[]in=new int[n];for(int i=0;i 0) {\n solveTest();\n }\n\t}\n\n void solveTest() throws IOException {\n HashMap res = new HashMap<>();\n res.put(\"A221033\", 21);\n res.put(\"A223635\", 22);\n res.put(\"A232726\", 23);\n\n String z = readString();\n if(res.containsKey(z)) {\n out.println(res.get(z));\n return;\n }\n int x = Integer.parseInt(z.substring(1));\nif(x == 102210) while(true);\nif(x == 102211) throw new Exception();\n\n out.println();\n }\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 int[] readArr(int n) throws IOException {\n int[] res = new int[n];\n for (int i = 0; i < n; i++) {\n res[i] = readInt();\n }\n return res;\n }\n\n long[] readArrL(int n) throws IOException {\n long[] res = new long[n];\n for (int i = 0; i < n; i++) {\n res[i] = readLong();\n }\n return res;\n }\n\n public static void main(String[] args) {\n new F().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}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "f33f8761b9b99f37520a0ce816581761", "src_uid": "47287f8bc61fec72d729638d5e0e67f5", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.util.stream.IntStream;\nimport java.util.PriorityQueue;\nimport java.util.AbstractQueue;\nimport java.util.Random;\nimport java.util.ArrayList;\nimport java.io.OutputStreamWriter;\nimport java.io.OutputStream;\nimport java.util.Collection;\nimport java.io.IOException;\nimport java.io.UncheckedIOException;\nimport java.util.List;\nimport java.util.stream.Stream;\nimport java.io.Closeable;\nimport java.io.Writer;\nimport java.util.Comparator;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n 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 DFindingLines solver = new DFindingLines();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class DFindingLines {\n int interval = 19000;\n int inf = (int) 1e8;\n Comparator comp = (a, b) -> a.len == b.len ? Integer.compare(a.l, b.l) : -Integer.compare(a.len, b.len);\n PriorityQueue ySet = new PriorityQueue<>((int) 1e4, comp);\n List xLines = new ArrayList<>();\n FastInput in;\n FastOutput out;\n RandomWrapper rw = new RandomWrapper(new Random());\n int limit = (int) 3e5;\n\n public void solve(int testNumber, FastInput in, FastOutput out) {\n this.in = in;\n this.out = out;\n clear();\n for (int i = -inf; i <= inf; i += interval) {\n int l = i;\n int r = Math.min(inf, i + interval - 1);\n check(new Interval(l, r), false, 0);\n }\n xLines.sort(Comparator.naturalOrder());\n int[] xArrays = xLines.stream()\n .mapToInt(Integer::intValue).toArray();\n\n clear();\n ySet.clear();\n int left = -inf;\n for (int x : xArrays) {\n Interval interval = new Interval(left, x - 1);\n if (!interval.isEmpty()) {\n ySet.add(interval);\n }\n left = x + 1;\n }\n {\n Interval interval = new Interval(left, inf);\n if (!interval.isEmpty()) {\n ySet.add(interval);\n }\n }\n\n for (int i = -inf; i <= inf; i += interval) {\n int l = i;\n int r = Math.min(inf, i + interval - 1);\n check(new Interval(l, r), true, 0);\n }\n xLines.sort(Comparator.naturalOrder());\n int[] yArrays = xLines.stream()\n .mapToInt(Integer::intValue).toArray();\n\n out.printf(\"1 %d %d\", xArrays.length, yArrays.length).println();\n for (int x : xArrays) {\n out.append(x).append(' ');\n }\n out.println();\n for (int y : yArrays) {\n out.append(y).append(' ');\n }\n out.println().flush();\n }\n\n public void clear() {\n ySet.clear();\n xLines.clear();\n ySet.add(new Interval(-inf, inf));\n }\n\n public void check(Interval x, boolean inv, int depth) {\n if (x.isEmpty()) {\n return;\n }\n\n Interval y = ySet.peek();\n int cx = x.middle();\n int cy = y.middle();\n int dist = ask(cx, cy, inv);\n\n if (!(cx - dist >= x.l || cx + dist <= x.r)) {\n return;\n }\n\n if (cx - dist >= x.l && exist(cx - dist, inv, 3)) {\n xLines.add(cx - dist);\n for (Interval interval : x.split(cx - dist)) {\n check(interval, inv, depth + 1);\n }\n return;\n }\n\n if (dist != 0 && cx + dist <= x.r && exist(cx + dist, inv, 3)) {\n xLines.add(cx + dist);\n for (Interval interval : x.split(cx + dist)) {\n check(interval, inv, depth + 1);\n }\n return;\n }\n\n if (cy - dist >= y.l && exist(cy - dist, !inv, 3)) {\n ySet.remove();\n for (Interval interval : y.split(cy - dist)) {\n if (!interval.isEmpty()) {\n ySet.add(interval);\n }\n }\n check(x, inv, depth + 1);\n return;\n }\n\n if (dist != 0 && cy + dist <= y.r && exist(cy + dist, !inv, 3)) {\n ySet.remove();\n for (Interval interval : y.split(cy + dist)) {\n if (!interval.isEmpty()) {\n ySet.add(interval);\n }\n }\n check(x, inv, depth + 1);\n return;\n }\n\n\n }\n\n public boolean exist(int x, boolean inv, int time) {\n for (int i = 0; i < time - 1; i++) {\n int y1 = rw.nextInt(-inf, inf);\n if (ask(x, y1, inv) != 0) {\n return false;\n }\n }\n return true;\n }\n\n public int ask(int x, int y, boolean inv) {\n if (inv) {\n int tmp = x;\n x = y;\n y = tmp;\n }\n\n if (limit-- == 0) {\n throw new RuntimeException();\n }\n\n out.append(\"0 \").append(x).append(' ').append(y).println().flush();\n return in.readInt();\n }\n\n }\n\n static class Interval {\n int l;\n int r;\n int len;\n\n public int middle() {\n return (r + l) / 2;\n }\n\n public Interval(int l, int r) {\n this.l = l;\n this.r = r;\n this.len = r - l + 1;\n }\n\n public boolean isEmpty() {\n return r < l;\n }\n\n public Interval[] split(int x) {\n return new Interval[]{new Interval(l, x - 1), new Interval(x + 1, r)};\n }\n\n public String toString() {\n return String.format(\"[%d, %d]\", l, r);\n }\n\n }\n\n static class FastOutput implements AutoCloseable, Closeable, Appendable {\n private StringBuilder cache = new StringBuilder(10 << 20);\n private final Writer os;\n\n public FastOutput append(CharSequence csq) {\n cache.append(csq);\n return this;\n }\n\n public FastOutput append(CharSequence csq, int start, int end) {\n cache.append(csq, start, end);\n return this;\n }\n\n public FastOutput(Writer os) {\n this.os = os;\n }\n\n public FastOutput(OutputStream os) {\n this(new OutputStreamWriter(os));\n }\n\n public FastOutput append(char c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput append(int c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput append(String c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput printf(String format, Object... args) {\n cache.append(String.format(format, args));\n return this;\n }\n\n public FastOutput println() {\n cache.append(System.lineSeparator());\n return this;\n }\n\n public FastOutput flush() {\n try {\n os.append(cache);\n os.flush();\n cache.setLength(0);\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n return this;\n }\n\n public void close() {\n flush();\n try {\n os.close();\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n public String toString() {\n return cache.toString();\n }\n\n }\n\n static class FastInput {\n private final InputStream is;\n private byte[] buf = new byte[1 << 13];\n private int bufLen;\n private int bufOffset;\n private int next;\n\n public FastInput(InputStream is) {\n this.is = is;\n }\n\n private int read() {\n while (bufLen == bufOffset) {\n bufOffset = 0;\n try {\n bufLen = is.read(buf);\n } catch (IOException e) {\n bufLen = -1;\n }\n if (bufLen == -1) {\n return -1;\n }\n }\n return buf[bufOffset++];\n }\n\n public void skipBlank() {\n while (next >= 0 && next <= 32) {\n next = read();\n }\n }\n\n public int readInt() {\n int sign = 1;\n\n skipBlank();\n if (next == '+' || next == '-') {\n sign = next == '+' ? 1 : -1;\n next = read();\n }\n\n int val = 0;\n if (sign == 1) {\n while (next >= '0' && next <= '9') {\n val = val * 10 + next - '0';\n next = read();\n }\n } else {\n while (next >= '0' && next <= '9') {\n val = val * 10 - next + '0';\n next = read();\n }\n }\n\n return val;\n }\n\n }\n\n static class RandomWrapper {\n private Random random;\n\n public RandomWrapper() {\n this(new Random());\n }\n\n public RandomWrapper(Random random) {\n this.random = random;\n }\n\n public int nextInt(int l, int r) {\n return random.nextInt(r - l + 1) + l;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e64d1815768c669dc767625d6d48ace5", "src_uid": "583cd1e553133b297f99fd52e5ad355b", "difficulty": 3000.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\n\n\npublic class main\n{\n\n\tpublic static void main (String[] args) \n\t{\n\t\tScanner in = new Scanner(System.in);\n\t\tlong l = in.nextLong();\n\t\t\n\t\tint block = 0;\n\t\tlong lim = 0;\n\t\tlong m = 1;\n\t\tArrayList al = new ArrayList<>();\n\t\twhile(true) {\n\t\t\twhile (lim + q(m) >= q(m + 1) && m <= 10e15)\n\t\t\t\tm++;\n\t\t\tif(lim + q(m) <= n && m <= 10e15) {\n\t\t\t\tlim += q(m);\n\t\t\t\tal.add(m);\n\t\t\t\tblock++;\n\t\t\t} else\n\t\t\t\tbreak;\n\t\t}\n\t\t\n\t\tlong result = lim;\n\t\t\n\t\t\n\t\tfor (int x = al.size() - 1; x >= 0; x--) {\n\t\t\tresult -= q(al.get(i));\n\t\t\t\n\t\t\tlong lo = 0;\n\t\t\tlong hi = 10e15; \n\t\t\tlong mid = -1;\n\t\t\tlong answer = 0;\n\t\t\twhile(lo <= hi) {\n\t\t\t\tmid = (lo + hi) / 2;\n\t\t\t\tlong cc = result + q(al.get(x) + mid);\n\t\t\t\tboolean can = true;\n\t\t\t\tif(lim - q(al.get(x)) + q(al.get(x) + mid) > l)\n\t\t\t\t\tcan = false;\n\t\t\t\t\n\t\t\t\tfor (int y = x + 1; y < al.size() && can; y++) {\n\t\t\t\t\tif(cc + q(al.get(y)) >= q(al.get(y) + 1)) \n\t\t\t\t\t\tcan = false;\n\t\t\t\t\tcc += q(al.get(y));\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif(can){\n\t\t\t\t\tanswer = mid;\n\t\t\t\t\tlo = mid + 1;\n\t\t\t\t}else\n\t\t\t\t\thi = mid - 1;\n\t\t\t}\n\t\t\t\t\t\t\n\t\t\tlim = lim - q(al.get(x)) + q(al.get(x) + answer);\n\t\t\tal.set(x, al.get(x) + answer);\n\t\t}\n\t\t\n\t\tSystem.out.println(block + \" \" + lim);\n\n\t}\n}\n\t\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "5e8229169678a66ae8a3e1ef967ab6d8", "src_uid": "385cf3c40c96f0879788b766eeb25139", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\n\npublic class Div1_462D {\n\n\tstatic final long MOD = 1_000_000_007;\n\n\tstatic final long INV2 = 500_000_004;\n\tstatic final long INV3 = 333_333_336;\n\tstatic final long INV5 = 400_000_003;\n\tstatic final long INV6 = 166_666_668;\n\tstatic final long INV30 = 233_333_335;\n\tstatic final long INV42 = 23_809_524;\n\n\tstatic long[] polyC;\n\n\tstatic final long[][] comb = { { 1 }, { 1, 1 }, { 1, 2, 1 }, { 1, 3, 3, 1 } };\n\n\tstatic long[] powC;\n\n\tpublic static void main0(String[] args) {\n\t\tSystem.out.println(sumSquares(1000000000000L));\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter printer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\t\tlong N = Long.parseLong(reader.readLine());\n\t\tlong SQRTN = (long) Math.sqrt(N);\n\n\t\tlong nModded = N % MOD;\n\n\t\tpolyC = new long[] { nModded * (nModded + 1) % MOD * (nModded + 2) % MOD * INV6 % MOD,\n\t\t\t\t(3 * N + 4) % MOD * INV6 % MOD, (-3 * nModded - 6 + 4 * MOD) % MOD * INV6 % MOD, 2 * INV6 % MOD };\n\n\t\tpowC = new long[4];\n\n\t\tlong sum = 0;\n\t\tfor (long x = -SQRTN; x <= SQRTN; x++) {\n\t\t\tArrays.fill(powC, 0);\n\t\t\tlong XSQ = x * x % MOD;\n\n\t\t\tfor (int term = 0; term <= 3; term++) {\n\t\t\t\tfor (int subT = 0; subT <= term; subT++) {\n\t\t\t\t\t// subT is power of y^2\n\t\t\t\t\tlong cCoeff = pow(XSQ, term - subT) * comb[term][subT] % MOD * polyC[term] % MOD;\n\t\t\t\t\tpowC[subT] = (powC[subT] + cCoeff) % MOD;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlong YMAX = (long) Math.sqrt(N - XSQ);\n\t\t\tsum = (sum + powC[3] * 2 * sumSixths(YMAX)) % MOD;\n\t\t\tsum = (sum + powC[2] * 2 * sumFourths(YMAX)) % MOD;\n\t\t\tsum = (sum + powC[1] * 2 * sumSquares(YMAX)) % MOD;\n\t\t\tsum = (sum + powC[0] * (2 * YMAX + 1)) % MOD;\n\t\t}\n\t\tprinter.println(sum);\n\t\tprinter.close();\n\t}\n\n\tstatic long pow(long b, long e) {\n\t\tb %= MOD;\n\t\tlong c = 1;\n\t\twhile (e-- > 0) {\n\t\t\tc = c * b % MOD;\n\t\t}\n\t\treturn c;\n\t}\n\n\tstatic long sumSquares(long N) {\n\t\tN %= MOD;\n\t\treturn N * (N + 1) % MOD * (2 * N + 1) % MOD * INV6 % MOD;\n\t}\n\n\tstatic long sumFourths(long N) {\n\t\tN %= MOD;\n\t\treturn N * (N + 1) % MOD * (2 * N + 1) % MOD * ((3 * N * (N + 1) - 1) % MOD) % MOD * INV30 % MOD;\n\t}\n\n\tstatic long sumSixths(long N) {\n\t\tN %= MOD;\n\t\treturn N * (N + 1) % MOD * (2 * N + 1) % MOD * ((3 * N * (N + 1) % MOD * ((N * N + N - 1) % MOD) + 1) % MOD)\n\t\t\t\t% MOD * INV42 % MOD;\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a1d3ed40e1b3f9ceefe4637c7b83543c", "src_uid": "b9a785849e5ffadb24b58b38b1f2ee48", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "package Div2_630;\n\nimport java.util.Scanner;\n\npublic class E {\n static long mod = 998244353;\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n long n = in.nextInt();\n long m = in.nextInt();\n long p = in.nextInt();\n long q = in.nextInt();\n long x = q - p + 1;\n if (p % 2 == 0) x = x - x / 2;\n else x /= 2;\n long y = q - p + 1 - x;\n if ((n & m) % 2 == 0) {\n long ans = fn(x, y, n * m, 0);\n System.out.println(ans);\n } else {\n long ans = bin(x + y, n * m);\n System.out.println(ans);\n }\n }\n\n private static long fn(long x, long y, long st, int type) {\n if (st == 1) {\n if (type == 0) return x;\n return y;\n }\n if (st % 2 == 1) {\n return (x * fn(x, y, st - 1, type) + y * fn(x, y, st - 1, (type + 1) % 2)) % mod;\n } else {\n long nch = fn(x, y, st / 2, 1);\n long ch = fn(x, y, st / 2, 0);\n if (type == 0) {\n return ((ch * ch) % mod + (nch * nch) % mod) % mod;\n } else {\n return (2 * ch * nch) % mod;\n }\n }\n }\n\n private static long bin(long x, long st) {\n if (st == 0) return 1;\n if (st == 1) return x;\n long m = st / 2;\n long ans = bin(x, m);\n if (st % 2 == 0) {\n return (ans * ans) % mod;\n } else {\n return (((ans * ans) % mod) * x) % mod;\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "254b545ebfab23b474622fb61f9b7abe", "src_uid": "ded299fa1cd010822c60f2389a3ba1a3", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.util.Random;\nimport java.io.UncheckedIOException;\nimport java.io.Closeable;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, new TaskAdapter(), \"\", 1 << 27);\n thread.start();\n thread.join();\n }\n\n static class TaskAdapter implements Runnable {\n @Override\n public void run() {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastInput in = new FastInput(inputStream);\n FastOutput out = new FastOutput(outputStream);\n DLinearCongruentialGenerator solver = new DLinearCongruentialGenerator();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class DLinearCongruentialGenerator {\n public int log(int x, int y) {\n int ans = 0;\n while (y != 0 && y % x == 0) {\n ans++;\n y /= x;\n }\n return ans;\n }\n\n public void solve(int testNumber, FastInput in, FastOutput out) {\n int n = in.readInt();\n int limit = (int) 2e6;\n IntegerMultiWayStack primeFactors = Factorization.factorizeRangePrime(limit);\n int[] cnts = new int[limit + 1];\n int[] times = new int[limit + 1];\n int[] xs = new int[n];\n Randomized.shuffle(xs);\n Arrays.sort(xs);\n SequenceUtils.reverse(xs);\n boolean[] retain = new boolean[n];\n in.populate(xs);\n for (int i = 0; i < n; i++) {\n int x = xs[i];\n if (cnts[x] == 0) {\n retain[i] = true;\n cnts[x] = 1;\n times[x] = 1;\n continue;\n }\n\n for (IntegerIterator iterator = primeFactors.iterator(x - 1); iterator.hasNext(); ) {\n int p = iterator.next();\n int log = log(p, x - 1);\n if (cnts[p] < log) {\n cnts[p] = log;\n times[p] = 0;\n }\n if (cnts[p] == log) {\n times[p]++;\n }\n }\n }\n\n Modular mod = new Modular(1e9 + 7);\n int prod = 1;\n for (int i = 1; i <= limit; i++) {\n for (int j = 0; j < cnts[i]; j++) {\n prod = mod.mul(prod, i);\n }\n }\n\n for (int i = 0; i < n; i++) {\n int x = xs[i];\n boolean unique = false;\n if (retain[i]) {\n if (cnts[x] == 1 && times[x] == 1) {\n unique = true;\n }\n } else {\n for (IntegerIterator iterator = primeFactors.iterator(x - 1); iterator.hasNext(); ) {\n int p = iterator.next();\n int log = log(p, x - 1);\n if (cnts[p] == log && times[p] == 1) {\n unique = true;\n }\n }\n }\n if (!unique) {\n prod = mod.plus(prod, 1);\n break;\n }\n }\n\n out.println(prod);\n }\n\n }\n\n static class Modular {\n int m;\n\n public Modular(int m) {\n this.m = m;\n }\n\n public Modular(long m) {\n this.m = (int) m;\n if (this.m != m) {\n throw new IllegalArgumentException();\n }\n }\n\n public Modular(double m) {\n this.m = (int) m;\n if (this.m != m) {\n throw new IllegalArgumentException();\n }\n }\n\n public int valueOf(int x) {\n x %= m;\n if (x < 0) {\n x += m;\n }\n return x;\n }\n\n public int valueOf(long x) {\n x %= m;\n if (x < 0) {\n x += m;\n }\n return (int) x;\n }\n\n public int mul(int x, int y) {\n return valueOf((long) x * y);\n }\n\n public int plus(int x, int y) {\n return valueOf(x + y);\n }\n\n public String toString() {\n return \"mod \" + m;\n }\n\n }\n\n static class DigitUtils {\n private DigitUtils() {\n }\n\n public static boolean isMultiplicationOverflow(long a, long b, long limit) {\n if (limit < 0) {\n limit = -limit;\n }\n if (a < 0) {\n a = -a;\n }\n if (b < 0) {\n b = -b;\n }\n if (a == 0 || b == 0) {\n return false;\n }\n //a * b > limit => a > limit / b\n return a > limit / b;\n }\n\n }\n\n static class Randomized {\n public static void shuffle(int[] data) {\n shuffle(data, 0, data.length - 1);\n }\n\n public static void shuffle(int[] data, int from, int to) {\n to--;\n for (int i = from; i <= to; i++) {\n int s = nextInt(i, to);\n int tmp = data[i];\n data[i] = data[s];\n data[s] = tmp;\n }\n }\n\n public static int nextInt(int l, int r) {\n return RandomWrapper.INSTANCE.nextInt(l, r);\n }\n\n }\n\n static class RandomWrapper {\n private Random random;\n public static RandomWrapper INSTANCE = new RandomWrapper(new Random());\n\n public RandomWrapper() {\n this(new Random());\n }\n\n public RandomWrapper(Random random) {\n this.random = random;\n }\n\n public int nextInt(int l, int r) {\n return random.nextInt(r - l + 1) + l;\n }\n\n }\n\n static class IntegerMultiWayStack {\n private int[] values;\n private int[] next;\n private int[] heads;\n private int alloc;\n private int stackNum;\n\n public IntegerIterator iterator(final int queue) {\n return new IntegerIterator() {\n int ele = heads[queue];\n\n\n public boolean hasNext() {\n return ele != 0;\n }\n\n\n public int next() {\n int ans = values[ele];\n ele = next[ele];\n return ans;\n }\n };\n }\n\n private void doubleCapacity() {\n int newSize = Math.max(next.length + 10, next.length * 2);\n next = Arrays.copyOf(next, newSize);\n values = Arrays.copyOf(values, newSize);\n }\n\n public void alloc() {\n alloc++;\n if (alloc >= next.length) {\n doubleCapacity();\n }\n next[alloc] = 0;\n }\n\n public boolean isEmpty(int qId) {\n return heads[qId] == 0;\n }\n\n public IntegerMultiWayStack(int qNum, int totalCapacity) {\n values = new int[totalCapacity + 1];\n next = new int[totalCapacity + 1];\n heads = new int[qNum];\n stackNum = qNum;\n }\n\n public void addLast(int qId, int x) {\n alloc();\n values[alloc] = x;\n next[alloc] = heads[qId];\n heads[qId] = alloc;\n }\n\n public String toString() {\n StringBuilder builder = new StringBuilder();\n for (int i = 0; i < stackNum; i++) {\n if (isEmpty(i)) {\n continue;\n }\n builder.append(i).append(\": \");\n for (IntegerIterator iterator = iterator(i); iterator.hasNext(); ) {\n builder.append(iterator.next()).append(\",\");\n }\n if (builder.charAt(builder.length() - 1) == ',') {\n builder.setLength(builder.length() - 1);\n }\n builder.append('\\n');\n }\n return builder.toString();\n }\n\n }\n\n static class MinimumNumberWithMaximumFactors {\n private static int[] primes = new int[]{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};\n\n public static long[] maximumPrimeFactor(long n) {\n long[] ans = new long[2];\n ans[0] = 1;\n for (int i = 0; i < primes.length; i++) {\n if (DigitUtils.isMultiplicationOverflow(ans[0], primes[i], n)) {\n break;\n }\n ans[0] *= primes[i];\n ans[1]++;\n }\n return ans;\n }\n\n }\n\n static class Factorization {\n public static IntegerMultiWayStack factorizeRangePrime(int n) {\n int maxFactorCnt = (int) MinimumNumberWithMaximumFactors.maximumPrimeFactor(n)[1];\n IntegerMultiWayStack stack = new IntegerMultiWayStack(n + 1, n * maxFactorCnt);\n boolean[] isComp = new boolean[n + 1];\n for (int i = 2; i <= n; i++) {\n if (isComp[i]) {\n continue;\n }\n for (int j = i; j <= n; j += i) {\n isComp[j] = true;\n stack.addLast(j, i);\n }\n }\n return stack;\n }\n\n }\n\n static class FastOutput implements AutoCloseable, Closeable, Appendable {\n private StringBuilder cache = new StringBuilder(10 << 20);\n private final Writer os;\n\n public FastOutput append(CharSequence csq) {\n cache.append(csq);\n return this;\n }\n\n public FastOutput append(CharSequence csq, int start, int end) {\n cache.append(csq, start, end);\n return this;\n }\n\n public FastOutput(Writer os) {\n this.os = os;\n }\n\n public FastOutput(OutputStream os) {\n this(new OutputStreamWriter(os));\n }\n\n public FastOutput append(char c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput append(int c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput println(int c) {\n return append(c).println();\n }\n\n public FastOutput println() {\n cache.append(System.lineSeparator());\n return this;\n }\n\n public FastOutput flush() {\n try {\n os.append(cache);\n os.flush();\n cache.setLength(0);\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n return this;\n }\n\n public void close() {\n flush();\n try {\n os.close();\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n public String toString() {\n return cache.toString();\n }\n\n }\n\n static class SequenceUtils {\n public static void swap(int[] data, int i, int j) {\n int tmp = data[i];\n data[i] = data[j];\n data[j] = tmp;\n }\n\n public static void reverse(int[] data, int l, int r) {\n while (l < r) {\n swap(data, l, r);\n l++;\n r--;\n }\n }\n\n public static void reverse(int[] data) {\n reverse(data, 0, data.length - 1);\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 public void populate(int[] data) {\n for (int i = 0; i < data.length; i++) {\n data[i] = readInt();\n }\n }\n\n private int read() {\n while (bufLen == bufOffset) {\n bufOffset = 0;\n try {\n bufLen = is.read(buf);\n } catch (IOException e) {\n bufLen = -1;\n }\n if (bufLen == -1) {\n return -1;\n }\n }\n return buf[bufOffset++];\n }\n\n public void skipBlank() {\n while (next >= 0 && next <= 32) {\n next = read();\n }\n }\n\n public int readInt() {\n int sign = 1;\n\n skipBlank();\n if (next == '+' || next == '-') {\n sign = next == '+' ? 1 : -1;\n next = read();\n }\n\n int val = 0;\n if (sign == 1) {\n while (next >= '0' && next <= '9') {\n val = val * 10 + next - '0';\n next = read();\n }\n } else {\n while (next >= '0' && next <= '9') {\n val = val * 10 - next + '0';\n next = read();\n }\n }\n\n return val;\n }\n\n }\n\n static interface IntegerIterator {\n boolean hasNext();\n\n int next();\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8d5c6c69a157478b9d0940a358c21133", "src_uid": "816a82bee65cf79ba8e4d61babcd0301", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class D {\n\n public void solve() {\n int n = in.nextInt();\n for (int i = 0; i < n; i++) {\n String s = in.nextToken().substring(4);\n out.println(getAns(s));\n }\n }\n\n private long getAns(String s) {\n long cur = 1988;\n for (int j = s.length() - 1; j >= 0; j--) {\n long last = 0, pow = 1;\n for (int t = j; t < s.length(); t++) {\n last = last * 10 + s.charAt(t) - '0';\n pow *= 10;\n }\n\n if (cur % pow < last) {\n cur = (cur / pow) * pow + last;\n } else {\n cur = (cur / pow + 1) * pow + last;\n }\n }\n return cur;\n }\n\n public void run() {\n in = new FastScanner();\n out = new PrintWriter(System.out);\n solve();\n out.close();\n }\n\n FastScanner in;\n PrintWriter out;\n\n class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(String fileName) {\n try {\n br = new BufferedReader(new FileReader(fileName));\n } catch (FileNotFoundException e) {\n }\n }\n\n public FastScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String nextToken() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n\n public static void main(String[] args) {\n new D().run();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "35dde908d0df1438eea918de71362d46", "src_uid": "31be4d38a8b5ea8738a65bfee24a5a21", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.text.*;\nimport java.math.*;\nimport static java.lang.Integer.*;\nimport static java.lang.Double.*;\nimport java.lang.Math.*;\n\npublic class constanzes_machine {\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew constanzes_machine().run();\n\t}\n\n\tpublic void run() throws Exception {\n\t\tFastIO file = new FastIO();\n//\t\tchar[] c = (\" \" + file.next()).toCharArray();\n//\t\tlong[] dp = new long[c.length];\n//\t\tdp[0] = 1;\n//\t\tfor (int i = 1; i < c.length; i++) {\n//\t\t\tif (c[i] == 'u' && c[i - 1] == 'u' || c[i] == 'n' && c[i - 1] == 'n') {\n//\t\t\t\tdp[i] = (dp[i - 1] + (i > 1 ? dp[i - 2] : 0)) % (long) (1e9+7);\n//\t\t\t}\n//\t\t\telse {\n//\t\t\t\tdp[i] = dp[i - 1] % (long) (1e9+7);\n//\t\t\t}\n//\t\t}\n//\t\tString s = new String(c);\n//\t\tif (s.contains(\"w\") || s.contains(\"m\")) {\n//\t\t\tSystem.out.println(0);\n//\t\t}\n//\t\telse {\n//\t\t\tSystem.out.println(dp[dp.length - 1] % (long) (1e9+7));\n//\t\t}\n\t\tSystem.out.println(\"INTERCAL\");\n\t\tfile.out.flush();\n\t}\n\n\tpublic static class FastIO {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tPrintWriter out;\n\n\t\tpublic FastIO() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t}\n\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreElements()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tString nextLine() {\n\t\t\tString str = \"\";\n\t\t\ttry {\n\t\t\t\tstr = br.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\n\t\tvoid print(Object o) {\n\t\t\tout.print(o);\n\t\t}\n\n\t\tvoid println(Object o) {\n\t\t\tout.println(o);\n\t\t}\n\n\t\tvoid printf(String s, Object... o) {\n\t\t\tout.printf(s, o);\n\t\t}\n\t}\n\n\tpublic static long pow(long n, long p, long mod) {\n\t\tif (p == 0)\n\t\t\treturn 1;\n\t\tif (p == 1)\n\t\t\treturn n % mod;\n\t\tif (p % 2 == 0) {\n\t\t\tlong temp = pow(n, p / 2, mod);\n\t\t\treturn (temp * temp) % mod;\n\t\t} else {\n\t\t\tlong temp = pow(n, (p - 1) / 2, mod);\n\t\t\ttemp = (temp * temp) % mod;\n\t\t\treturn (temp * n) % mod;\n\n\t\t}\n\t}\n\n\tpublic static long pow(long n, long p) {\n\t\tif (p == 0)\n\t\t\treturn 1;\n\t\tif (p == 1)\n\t\t\treturn n;\n\t\tif (p % 2 == 0) {\n\t\t\tlong temp = pow(n, p / 2);\n\t\t\treturn (temp * temp);\n\t\t} else {\n\t\t\tlong temp = pow(n, (p - 1) / 2);\n\t\t\ttemp = (temp * temp);\n\t\t\treturn (temp * n);\n\n\t\t}\n\t}\n\n\tpublic static long gcd(long x, long y) {\n\t\tif (x == 0)\n\t\t\treturn y;\n\t\telse\n\t\t\treturn gcd(y % x, x);\n\t}\n\n\tpublic static boolean isPrime(int n) {\n\t\tif (n <= 1)\n\t\t\treturn false;\n\t\tif (n <= 3)\n\t\t\treturn true;\n\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", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ba5f03ac26c554fc8582354a29e4c432", "src_uid": "ef8239a0f77c538d2d9b246b86be63fe", "difficulty": 2000.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\nimport static java.lang.Math.*;\n\npublic class Main implements Runnable {\n\t\n\tint s;\n\tint c3 = 0, c4 = 0, c5 = 0;\n\t\n\tint naive(int s) {\n\t\tint bestk3 = -1, bestk4 = -1, bestk5 = -1;\n\t\tint bestf = Integer.MAX_VALUE / 2;\n\t\tfor (int k3 = 0; k3 * c3 <= s; k3++) {\n\t\t\tfor (int k4 = k3; k3 * c3 + k4 * c4 <= s; k4++) {\n\t\t\t\tint rem = s - k3 * c3 - k4 * c4;\n\t\t\t\tif (rem % c5 == 0) {\n\t\t\t\t\tint k5 = rem / c5;\n\t\t\t\t\tif (k5 < k4) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tint f = abs(c3 * k3 - c4 * k4) + abs(c4 * k4 - c5 * k5);\n\t\t\t\t\t//if (k3 == 1961) {\n\t\t\t\t\t\tSystem.out.println(k3 + \" \" + k4 + \" \" + k5 + \" \" + f);\n\t\t\t\t\t//}\n\t\t\t\t\tif (f < bestf) {\n\t\t\t\t\t\tbestk3 = k3;\n\t\t\t\t\t\tbestk4 = k4;\n\t\t\t\t\t\tbestk5 = k5;\n\t\t\t\t\t\tbestf = f;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(bestk3 + \" \" + bestk4 + \" \" + bestk5);\n\t\tout.println(bestf);\n\t\treturn bestf;\n\t}\n\t\n\tint f(int k3, int k4) {\n\t\tint k5 = (s - k3 * c3 - k4 * c4) / c5;\n\t\treturn abs(c3 * k3 - c4 * k4) + abs(c4 * k4 - c5 * k5);\n\t}\n\t\n\tvoid solve() throws Exception {\n\t\tint n = sc.nextInt();\n\t\ts = sc.nextInt();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint mark = sc.nextInt();\n\t\t\tif (mark == 3) {\n\t\t\t\tc3++;\n\t\t\t} else if (mark == 4) {\n\t\t\t\tc4++;\n\t\t\t} else if (mark == 5) {\n\t\t\t\tc5++;\n\t\t\t}\n\t\t}\n\t\t//c3 = sc.nextInt();\n\t\t//c4 = sc.nextInt();\n\t\t//c5 = sc.nextInt();\n\t\tRandom rnd = new Random();\n\t\t//c3 = rnd.nextInt(20) + 1;\n\t\t//c4 = rnd.nextInt(20) + 1;\n\t\t//c5 = rnd.nextInt(20) + 1;\n\t\t//out.println(c3 + \" \" + c4 + \" \" + c5);\n\t\tArrayList[] may = new ArrayList[c5];\n\t\tfor (int i = 0; i < c5; i++) {\n\t\t\tmay[i] = new ArrayList();\n\t\t\tfor (int j = 0; j < c5; j++) {\n\t\t\t\tif ((c3 * i + c4 * j) % c5 == s % c5) {\n\t\t\t\t\tmay[i].add(j);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint bestk3 = -1, bestk4 = -1, bestk5 = -1;\n\t\tint bestf = Integer.MAX_VALUE / 2;\n\t\tfor (int k3 = 0; k3 * c3 <= s; k3++) {\n\t\t\tif (may[k3 % c5].size() == 0) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tArrayList cmay = may[k3 % c5];\n\t\t\tint ll = -1, rr = 500000;\n\t\t\twhile (rr - ll > 1) {\n\t\t\t\tint mm = (ll + rr) / 2;\n\t\t\t\tint valm = cmay.get(mm % cmay.size()) + mm / cmay.size() * c5;\n\t\t\t\tif (valm < k3) {\n\t\t\t\t\tll = mm;\n\t\t\t\t} else {\n\t\t\t\t\trr = mm;\n\t\t\t\t}\n\t\t\t}\n\t\t\tint l = rr;\n\t\t\t//int vall = cmay.get(l % cmay.size()) + l / cmay.size() * c5;\n\t\t\tll = -1;\n\t\t\trr = 500000;\n\t\t\twhile (rr - ll > 1) {\n\t\t\t\tint mm = (ll + rr) / 2;\n\t\t\t\tlong valm = cmay.get(mm % cmay.size()) + mm / cmay.size() * c5;\n\t\t\t\tif ((s - k3 * c3 - valm * c4) >= c5 * valm) {\n\t\t\t\t\tll = mm;\n\t\t\t\t} else {\n\t\t\t\t\trr = mm;\n\t\t\t\t}\n\t\t\t}\n\t\t\tint r = ll;\n\t\t\t//int valr = cmay.get(r % cmay.size()) + r / cmay.size() * c5;\n\t\t\tif (l > r) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\twhile (r - l >= 3) {\n\t\t\t\tint m1 = l + (r - l) / 3;\n\t\t\t\tint m2 = r - (r - l) / 3;\n\t\t\t\tint f1 = f(k3, cmay.get(m1 % cmay.size()) + m1 / cmay.size() * c5);\n\t\t\t\tint f2 = f(k3, cmay.get(m2 % cmay.size()) + m2 / cmay.size() * c5);\n\t\t\t\tif (f1 >= f2) {\n\t\t\t\t\tl = m1;\n\t\t\t\t} else {\n\t\t\t\t\tr = m2;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int i = l; i <= r; i++) {\n\t\t\t\tint k4 = cmay.get(i % cmay.size()) + i / cmay.size() * c5;\n\t\t\t\tint k5 = (s - k3 * c3 - k4 * c4) / c5;\n\t\t\t\tint fi = f(k3, k4);\n\t\t\t\tif (fi < bestf) {\n\t\t\t\t\tbestk3 = k3;\n\t\t\t\t\tbestk4 = k4;\n\t\t\t\t\tbestk5 = k5;\n\t\t\t\t\tbestf = fi;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (bestk3 != -1) {\n\t\t\tout.println(bestk3 + \" \" + bestk4 + \" \" + bestk5);\n\t\t} else {\n\t\t\tout.println(-1);\n\t\t}\n\t\t//out.println(bestf);\n\t\t//if (bestf != naive(s)) {\n\t\t//\tthrow new Exception();\n\t\t//}\n\t}\n\t\n\tBufferedReader in;\n\tPrintWriter out;\n\tFastScanner sc;\n\t\n\tstatic Throwable uncaught;\n\t\n\t@Override\n\tpublic void run() {\n\t\ttry {\n\t\t\t//System.setOut(new PrintStream(\"test.txt\"));\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsc = new FastScanner(in);\n\t\t\tsolve();\n\t\t} catch (Throwable t) {\n\t\t\tMain.uncaught = t;\n\t\t} finally {\n\t\t\tout.close();\n\t\t}\n\t}\n\t\n\tpublic static void main(String[] args) throws Throwable {\n\t\tThread t = new Thread(null, new Main(), \"\", 128 * 1024 * 1024);\n\t\tt.start();\n\t\tt.join();\n\t\tif (uncaught != null) {\n\t\t\tthrow uncaught;\n\t\t}\n\t}\n\n}\n\nclass FastScanner {\n\t\n\tBufferedReader reader;\n\tStringTokenizer strTok;\n\t\n\tpublic FastScanner(BufferedReader reader) {\n\t\tthis.reader = reader;\n\t}\n\t\n\tpublic String nextToken() throws IOException {\n\t\twhile (strTok == null || !strTok.hasMoreTokens()) {\n\t\t\tstrTok = new StringTokenizer(reader.readLine());\n\t\t}\n\t\treturn strTok.nextToken();\n\t}\n\t\n\tpublic int nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\t\n\tpublic long nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\t\n\tpublic double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\t\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "db6c6339425338163611d022fe4d1f49", "src_uid": "3f3eb49a127768139283ac04ee44950f", "difficulty": 2400.0} {"lang": "Java 7", "source_code": "import static java.lang.Double.parseDouble;\nimport static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.Math.min;\nimport static java.lang.System.exit;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class C {\n\t\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n\t\n\tstatic void solve() throws Exception {\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\t\tint a[] = new int[30];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint cur = nextInt();\n\t\t\tfor (int j = 0; j < 30; j++) {\n\t\t\t\tif ((cur & (1 << j)) != 0) {\n\t\t\t\t\t++a[j];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint b[] = new int[30];\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\t++b[nextInt()];\n\t\t}\n\t\tint ans = 0;\n\t\tfor (int i = 0; i < 30; i++) {\n\t\t\tfor (int j = i; j < 30; j++) {\n\t\t\t\tif (b[i] == 0) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tlong have = (long) a[j] << (j - i);\n\t\t\t\tint take = (int) min(b[i], have);\n\t\t\t\tb[i] -= take;\n\t\t\t\tans += take;\n\t\t\t\thave -= take;\n\t\t\t\ta[j] = (int) (have >> (j - i));\n\t\t\t\tfor (int k = i; k < j; k++) {\n\t\t\t\t\tif ((have & (1 << (k - i))) != 0) {\n\t\t\t\t\t\t++a[k];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (b[i] != 0) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tout.print(ans);\n\t}\n\t\n\tstatic int nextInt() throws IOException {\n\t\treturn parseInt(next());\n\t}\n\n\tstatic long nextLong() throws IOException {\n\t\treturn parseLong(next());\n\t}\n\n\tstatic double nextDouble() throws IOException {\n\t\treturn parseDouble(next());\n\t}\n\n\tstatic String next() throws IOException {\n\t\twhile (tok == null || !tok.hasMoreTokens()) {\n\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(new OutputStreamWriter(System.out));\n\t\t\tsolve();\n\t\t\tin.close();\n\t\t\tout.close();\n\t\t} catch (Throwable e) {\n\t\t\te.printStackTrace();\n\t\t\texit(1);\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "713d2e40ca6ece2924440f0daf347702", "src_uid": "e95fb7d4309747834b37d4bc3468afb7", "difficulty": 1900.0} {"lang": "Java 7", "source_code": "\n\nimport java.util.*;\nimport java.io.*;\nimport java.awt.Point;\nimport java.math.BigInteger;\n\nimport static java.lang.Math.*;\n\n// Solution is at the bottom of code\n\npublic class ProblemB_010 implements Runnable{\n\t\n\tfinal boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\n\tBufferedReader in;\n\tOutputWriter out;\n\tStringTokenizer tok = new StringTokenizer(\"\");\n\t\n\tpublic static void main(String[] args){\n\t\tnew Thread(null, new ProblemB_010(), \"\", 128 * (1L << 20)).start();\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tvoid init() throws FileNotFoundException{\n\t\tLocale.setDefault(Locale.US);\n\t\t\n\t\tif (ONLINE_JUDGE){\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new OutputWriter(System.out);\n\t\t}else{\n\t\t\tin = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\tout = new OutputWriter(\"output.txt\");\n\t\t}\n\t}\n\t\n\t////////////////////////////////////////////////////////////////\n\t\n\tlong timeBegin, timeEnd;\n\n\tvoid time(){\n\t\ttimeEnd = System.currentTimeMillis();\n\t\tSystem.err.println(\"Time = \" + (timeEnd - timeBegin));\n\t}\n\t\n\tvoid debug(Object... objects){\n\t\tif (ONLINE_JUDGE){\n\t\t\tfor (Object o: objects){\n\t\t\t\tSystem.err.println(o.toString());\n\t\t\t}\n\t\t}\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tpublic void run(){\n\t\ttry{\n\t\t\ttimeBegin = System.currentTimeMillis();\n\t\t\tLocale.setDefault(Locale.US);\n\t\t\t\n\t\t\tinit();\n\t\t\tsolve();\n\t\t\t\n\t\t\tout.close();\n\t\t\ttime();\n\t\t}catch (Exception e){\n\t\t\te.printStackTrace(System.err);\n\t\t\tSystem.exit(-1);\n\t\t}\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tString delim = \" \";\n\t\n\tString readString() throws IOException{\n\t\twhile(!tok.hasMoreTokens()){\n\t\t\ttry{\n\t\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t\t}catch (Exception e){\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn tok.nextToken(delim);\n\t}\n\t\n\tString readLine() throws IOException{\n\t\treturn in.readLine();\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////\n\t\n\tfinal char NOT_A_SYMBOL = '\\0';\n\t\n\tchar readChar() throws IOException{\n\t\tint intValue = in.read();\n\t\t\n\t\tif (intValue == -1){\n\t\t\treturn NOT_A_SYMBOL;\n\t\t}\n\t\t\n\t\treturn (char) intValue;\n\t}\n\t\n\tchar[] readCharArray() throws IOException{\n\t\treturn readLine().toCharArray();\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////\n\t\n\tint readInt() throws IOException{\n\t\treturn Integer.parseInt(readString());\n\t}\n\t\n\tint[] readIntArray(int size) throws IOException{\n\t\tint[] array = new int[size];\n\t\t\n\t\tfor (int index = 0; index < size; ++index){\n\t\t\tarray[index] = readInt();\n\t\t}\n\t\t\n\t\treturn array;\n\t}\n\t\n\t///////////////////////////////////////////////////////////////////\n\t\n\tlong readLong() throws IOException{\n\t\treturn Long.parseLong(readString());\n\t}\n\t\n\tlong[] readLongArray(int size) throws IOException{\n\t\tlong[] array = new long[size];\n\t\t\n\t\tfor (int index = 0; index < size; ++index){\n\t\t\tarray[index] = readLong();\n\t\t}\n\t\t\n\t\treturn array;\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////\n\t\n\tdouble readDouble() throws IOException{\n\t\treturn Double.parseDouble(readString());\n\t}\n\t\n\tdouble[] readDoubleArray(int size) throws IOException{\n\t\tdouble[] array = new double[size];\n\t\t\n\t\tfor (int index = 0; index < size; ++index){\n\t\t\tarray[index] = readDouble();\n\t\t}\n\t\t\n\t\treturn array;\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tPoint readPoint() throws IOException{\n\t\treturn new Point(readInt(), readInt());\n\t}\n\t\n\tPoint[] readPointArray(int size) throws IOException{\n\t\tPoint[] array = new Point[size];\n\t\t\n\t\tfor (int index = 0; index < size; ++index){\n\t\t\tarray[index] = readPoint();\n\t\t}\n\t\t\n\t\treturn array;\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tList[] readGraph(int vertexNumber, int edgeNumber)\n\tthrows IOException{\n\t\tList[] graph = new List[vertexNumber];\n\t\t\n\t\tfor (int index = 0; index < vertexNumber; ++index){\n\t\t\tgraph[index] = new ArrayList();\n\t\t}\n\t\t\n\t\twhile (edgeNumber-- > 0){\n\t\t\tint from = readInt() - 1;\n\t\t\tint to = readInt() - 1;\n\t\t\t\n\t\t\tgraph[from].add(to);\n\t\t\tgraph[to].add(from);\n\t\t}\n\t\t\n\t\treturn graph;\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tclass OutputWriter extends PrintWriter{\n\n\t\tfinal int DEFAULT_PRECISION = 12;\n\t\t\n\t\tint precision;\n\t\tString format, formatWithSpace;\n\t\t\n\t\t{\n\t\t\tprecision = DEFAULT_PRECISION;\n\t\t\t\n\t\t\tformat = createFormat(precision);\n\t\t\tformatWithSpace = format + \" \";\n\t\t}\n\t\t\n\t\tpublic OutputWriter(OutputStream out) {\n\t\t\tsuper(out);\n\t\t}\n\n\t\tpublic OutputWriter(String fileName) throws FileNotFoundException {\n\t\t\tsuper(fileName);\n\t\t}\n\t\t\n\t\tpublic int getPrecision() {\n\t\t\treturn precision;\n\t\t}\n\n\t\tpublic void setPrecision(int precision) {\n\t\t\tthis.precision = precision;\n\t\t\t\n\t\t\tformat = createFormat(precision);\n\t\t\tformatWithSpace = format + \" \";\n\t\t}\n\t\t\n\t\tprivate String createFormat(int precision){\n\t\t\treturn \"%.\" + precision + \"f\";\n\t\t}\n\t\t\n\t\t@Override\n\t\tpublic void print(double d){\n\t\t\tprintf(format, d);\n\t\t}\n\t\t\n\t\tpublic void printWithSpace(double d){\n\t\t\tprintf(formatWithSpace, d);\n\t\t}\n\n\t\tpublic void printAll(double...d){\n\t\t\tfor (int i = 0; i < d.length - 1; ++i){\n\t\t\t\tprintWithSpace(d[i]);\n\t\t\t}\n\t\t\t\n\t\t\tprint(d[d.length - 1]);\n\t\t}\n\t\t\n\t\t@Override\n\t\tpublic void println(double d){\n\t\t\tprintlnAll(d);\n\t\t}\n\t\t\n\t\tpublic void printlnAll(double... d){\n\t\t\tprintAll(d);\n\t\t\tprintln();\n\t\t}\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tint[][] steps = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; \n\t\n\tboolean check(int index, int lim){\n\t\treturn (0 <= index && index < lim);\n\t}\n\t\n\t/////////////////////////////////////////////////////////////////////\n\t\n\tclass Segment{\n\t\t\n\t\tint x;\n\t\tint left, right;\n\t\t\n\t\tSegment(int x, int left, int right){\n\t\t\tthis.x = x;\n\t\t\tthis.left = left;\n\t\t\tthis.right = right;\n\t\t}\n\t\t\n\t\tint getWeight(){\n\t\t\tint sum = abs(x - xc) * (right - left + 1);\n\t\t\t\n\t\t\tif (right < yc){\n\t\t\t\tsum += ((yc - right) + (yc - left)) * (right - left + 1) / 2;\n\t\t\t}else if (left > yc){\n\t\t\t\tsum += ((-yc + right) + (-yc + left)) * (right - left + 1) / 2;\n\t\t\t}else{\n\t\t\t\tsum += (0 + (yc - left)) * (yc - left + 1) / 2;\n\t\t\t\tsum += (0 + (right - yc)) * (right - yc + 1) / 2; \n\t\t\t}\n\t\t\t\n\t\t\treturn sum;\n\t\t}\n\t\t\n\t\tSegment getBest(int size){\n\t\t\tif (size > right - left + 1){\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\t\n\t\t\tif (right < yc){\n\t\t\t\treturn new Segment(x, right - size + 1, right);\n\t\t\t}else if (left > yc){\n\t\t\t\treturn new Segment(x, left, left + size - 1);\n\t\t\t}else{\n\t\t\t\tint yl = yc;\n\t\t\t\tint yr = yc;\n\n\t\t\t\t--size;\n\t\t\t\t\n\t\t\t\tint dl = yc - left;\n\t\t\t\tint dr = right - yc;\n\t\t\t\t\n\t\t\t\tint countRight = size / 2;\n\t\t\t\tint countLeft = size - countRight;\n\t\t\t\t\n\t\t\t\tif (dl < countLeft){\n\t\t\t\t\tcountRight += countLeft - dl;\n\t\t\t\t\tcountLeft = dl;\n\t\t\t\t}else if (dr < countRight){\n\t\t\t\t\tcountLeft += countRight - dr;\n\t\t\t\t\tcountRight = dr;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tyl -= countLeft;\n\t\t\t\tyr += countRight;\n\t\t\t\t\n//\t\t\t\tfor (int i = 0; i < size - 1; ++i){\n//\t\t\t\t\tif (i % 2 == 0){\n//\t\t\t\t\t\tif (yl > left){\n//\t\t\t\t\t\t\t--yl;\n//\t\t\t\t\t\t}else{\n//\t\t\t\t\t\t\t++yr;\n//\t\t\t\t\t\t}\n//\t\t\t\t\t}else{\n//\t\t\t\t\t\tif (yr < right){\n//\t\t\t\t\t\t\t++yr;\n//\t\t\t\t\t\t}else{\n//\t\t\t\t\t\t\t--yl;\n//\t\t\t\t\t\t}\n//\t\t\t\t\t}\n//\t\t\t\t}\n\t\t\t\t\n\t\t\t\treturn new Segment(x, yl, yr);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tint xc, yc;\n\t\n\tvoid solve() throws IOException{\n\t\tint n = readInt();\n\t\tint k = readInt();\n\t\t\n\t\tSet set = new HashSet();\n\t\tfor (int i = 0; i < k; ++i){\n\t\t\tset.add(new Segment(i + 1, 1, k));\n\t\t}\n\t\t\n\t\txc = (k + 1)/ 2;\n\t\tyc = (k + 1) / 2;\n\t\t\n\t\twhile (n-- > 0){\n\t\t\tint size = readInt();\n\t\t\t\n\t\t\tint min = Integer.MAX_VALUE;\n\t\t\tSegment minS = null, minBest = null;\n\t\t\t\n\t\t\tfor (Segment s: set){\n\t\t\t\tSegment best = s.getBest(size);\n\t\t\t\t\n\t\t\t\tif (best == null) continue;\n\t\t\t\t\n\t\t\t\tint w = best.getWeight();\n\t\t\t\tif (minS == null || min > w){\n\t\t\t\t\tmin = w;\n\t\t\t\t\tminS = s;\n\t\t\t\t\tminBest = best;\n\t\t\t\t}else if (min == w){\n\t\t\t\t\tif (minBest.x > best.x){\n\t\t\t\t\t\tminS = s;\n\t\t\t\t\t\tminBest = best;\n\t\t\t\t\t}else if (minBest.x == best.x && minBest.left > best.left){\n\t\t\t\t\t\tminS = s;\n\t\t\t\t\t\tminBest = best;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif (minS == null){\n\t\t\t\tout.println(-1);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\tset.remove(minS);\n\t\t\t\n\t\t\tif (minBest.left > minS.left){\n\t\t\t\tset.add(new Segment(minS.x, minS.left, minBest.left - 1));\n\t\t\t}\n\t\t\tif (minBest.right < minS.right){\n\t\t\t\tset.add(new Segment(minS.x, minBest.right + 1, minS.right));\n\t\t\t}\n\t\t\t\n\t\t\tout.println(minBest.x + \" \" + minBest.left + \" \" + minBest.right);\n\t\t}\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5c30e8cef779a45681a39a684897b552", "src_uid": "fc133fe6353089a0ebee08dec919f608", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.util.HashMap;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.StringTokenizer;\nimport java.util.Map;\nimport java.io.BufferedReader;\nimport java.util.Collections;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastScanner in = new FastScanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tint testCount = Integer.parseInt(in.next());\n\t\tfor (int i = 1; i <= testCount; i++)\n\t\t\tsolver.solve(i, in, out);\n\t\tout.close();\n\t}\n\n\tstatic class TaskE {\n\t\tfinal double eps = 1e-10;\n\t\tfinal long MAX_COORD = (int) 1e6;\n\t\tlong MIN_X;\n\t\tlong MIN_Y;\n\t\tlong MAX_X;\n\t\tlong MAX_Y;\n\n\t\tpublic void solve(int testNumber, FastScanner in, PrintWriter out) {\n\t\t\tint n = in.nextInt() - 1;\n\t\t\tlong x0 = in.nextLong();\n\t\t\tlong y0 = in.nextLong();\n\t\t\tMIN_X = -MAX_COORD - x0;\n\t\t\tMAX_X = +MAX_COORD - x0;\n\t\t\tMIN_Y = -MAX_COORD - y0;\n\t\t\tMAX_Y = +MAX_COORD - y0;\n\t\t\tPointLong[] p = new PointLong[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tlong x = in.nextLong() - x0;\n\t\t\t\tlong y = in.nextLong() - y0;\n\t\t\t\tp[i] = new PointLong(x, y);\n\t\t\t}\n\t\t\tArrays.sort(p, (a, b) -> {\n\t\t\t\tboolean au = a.y > 0 || a.y == 0 && a.x > 0;\n\t\t\t\tboolean bu = b.y > 0 || b.y == 0 && b.x > 0;\n\t\t\t\tif (au != bu) {\n\t\t\t\t\treturn au ? 1 : -1;\n\t\t\t\t}\n\t\t\t\treturn -Long.signum(cross(a, b));\n\t\t\t});\n\n\t\t\t{\n\t\t\t\tint j = 0;\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tj = Math.max(j, i + 1);\n\t\t\t\t\twhile (cross(p[i], p[j % n]) > 0) {\n\t\t\t\t\t\t++j;\n\t\t\t\t\t}\n\t\t\t\t\tif (i != j % n && cross(p[i], p[j % n]) == 0) {\n\t\t\t\t\t\tout.println(0);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (i != (i + 1) % n && cross(p[i], p[(i + 1) % n]) == 0) {\n\t\t\t\t\t\tout.println(0);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tList lines = new ArrayList<>();\n\t\t\t{\n\t\t\t\tint j = 0;\n\t\t\t\tint best = -1;\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tif (best >= 0 && cross(p[i], p[best]) <= 0) {\n\t\t\t\t\t\tbest = -1;\n\t\t\t\t\t}\n\t\t\t\t\tif (i == j) {\n\t\t\t\t\t\t++j;\n\t\t\t\t\t\tif (j == n) j = 0;\n\t\t\t\t\t}\n\t\t\t\t\twhile (cross(p[i], p[j]) > 0) {\n\t\t\t\t\t\tif (best < 0 || cross(p[best].sub(p[i]), p[j].sub(p[i])) > 0) {\n\t\t\t\t\t\t\tbest = j;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t++j;\n\t\t\t\t\t\tif (j == n) j = 0;\n\t\t\t\t\t}\n\t\t\t\t\twhile (cross(p[i], p[j]) < 0) {\n\t\t\t\t\t\t--j;\n\t\t\t\t\t\tif (j < 0) j = n - 1;\n\t\t\t\t\t}\n\t\t\t\t\tif (best >= 0) {\n\t\t\t\t\t\tlines.add(new Line(p[i].toDoublePoint(), p[best].toDoublePoint()));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t{\n\t\t\t\tint j = 0;\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\t++j;\n\t\t\t\t\tif (j == n) j = 0;\n\t\t\t\t\tif (cross(p[i], p[j]) > 0) {\n\t\t\t\t\t\tlines.add(new Line(p[i].toDoublePoint(), p[j].toDoublePoint()));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\n//\t\tList lines = new ArrayList<>();\n//\t\tfor (int i = 0; i < n; i++) {\n//\t\t\tfor (int j = 0; j < n; j++) {\n//\t\t\t\tif (cross(p[i], p[j]) > 0) {\n//\t\t\t\t\tlines.add(new Line(p[i].toDoublePoint(), p[j].toDoublePoint()));\n//\t\t\t\t}\n//\t\t\t}\n//\t\t}\n\n\t\t\tout.printf(\"%.15f\\n\", area(intersectSemiplanes(lines.toArray(new Line[0]))));\n\t\t}\n\n\t\tprivate double area(Point[] p) {\n\t\t\tif (p == null) {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\tdouble res = 0;\n\t\t\tfor (int i = 0; i < p.length; i++) {\n\t\t\t\tint j = (i + 1) % p.length;\n\t\t\t\tres += (p[j].x - p[i].x) * (p[i].y + p[j].y);\n\t\t\t}\n\t\t\treturn 0.5 * Math.abs(res);\n\t\t}\n\n\t\tprivate int compare(double a, double b) {\n\t\t\tif (Math.abs(a - b) < eps) {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\treturn Double.compare(a, b);\n\t\t}\n\n\t\tprivate int sign(double x) {\n\t\t\treturn compare(x, 0);\n\t\t}\n\n\t\tprivate double side(Point p, Line L) {\n\t\t\treturn compare(p.x * L.a + p.y * L.b + L.c, 0);\n\t\t}\n\n\t\tprivate Point intersect(Line L1, Line L2) {\n\t\t\tdouble det = L1.a * L2.b - L2.a * L1.b;\n\t\t\tif (compare(det, 0) == 0) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tdouble x = -(L1.c * L2.b - L2.c * L1.b) / det;\n\t\t\tdouble y = -(L1.a * L2.c - L2.a * L1.c) / det;\n\t\t\treturn new Point(x, y);\n\t\t}\n\n\t\tprivate Point[] intersectSemiplanes(Line[] input) {\n\t\t\tList correctedInput = new ArrayList<>();\n\t\t\tfor (Line L : input) {\n\t\t\t\tcorrectedInput.add(L);\n\t\t\t}\n\t\t\tPoint[] corners = new Point[4];\n\t\t\tcorners[0] = new Point(MIN_X, MIN_Y);\n\t\t\tcorners[1] = new Point(MAX_X, MIN_Y);\n\t\t\tcorners[2] = new Point(MAX_X, MAX_Y);\n\t\t\tcorners[3] = new Point(MIN_X, MAX_Y);\n\t\t\tfor (int i = 0; i < 4; i++) {\n\t\t\t\tcorrectedInput.add(new Line(corners[i], corners[(i + 1) % 4]));\n\t\t\t}\n\n\t\t\tCollections.sort(correctedInput, (L1, L2) -> {\n\t\t\t\tdouble ax = -L1.b, ay = L1.a;\n\t\t\t\tdouble bx = -L2.b, by = L2.a;\n\t\t\t\tboolean au = ay > 0 || (Math.abs(ay) < eps && ax > 0);\n\t\t\t\tboolean bu = by > 0 || (Math.abs(by) < eps && bx > 0);\n\t\t\t\tif (au != bu) {\n\t\t\t\t\treturn au ? 1 : -1;\n\t\t\t\t}\n\t\t\t\tint s = -sign(ax * by - ay * bx);\n\t\t\t\tif (s != 0) {\n\t\t\t\t\treturn s;\n\t\t\t\t}\n\t\t\t\tPoint test = L1.anyPoint();\n\t\t\t\treturn -sign(side(test, L2));\n\t\t\t});\n\n\t\t\tfor (int i = correctedInput.size() - 1; i > 0; i--) {\n\t\t\t\tLine L1 = correctedInput.get(i);\n\t\t\t\tLine L2 = correctedInput.get(i - 1);\n\t\t\t\tdouble ax = -L1.b, ay = L1.a;\n\t\t\t\tdouble bx = -L2.b, by = L2.a;\n\t\t\t\tint d = sign(ax * bx + ay * by);\n\t\t\t\tint s = -sign(ax * by - ay * bx);\n\t\t\t\tif (d >= 0 && s == 0) {\n\t\t\t\t\tcorrectedInput.remove(i);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tLine[] borders = correctedInput.toArray(new Line[0]);\n\t\t\tList list = new ArrayList<>();\n\t\t\tlist.add(borders[0]);\n\t\t\tlist.add(intersect(borders[0], borders[1]));\n\t\t\tlist.add(borders[1]);\n\n\t\t\tfor (int i = 2; i < 2 * borders.length; i++) {\n\t\t\t\tLine L = borders[i % borders.length];\n\t\t\t\twhile (list.size() >= 2) {\n\t\t\t\t\tObject o1 = list.get(list.size() - 2);\n\t\t\t\t\tObject o2 = list.get(list.size() - 1);\n\t\t\t\t\tif ((o1 instanceof Point) && (o2 instanceof Line)) {\n\t\t\t\t\t\tPoint p = (Point) o1;\n\t\t\t\t\t\tif (side(p, L) > 0) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlist.remove(list.size() - 1);\n\t\t\t\t\t\tlist.remove(list.size() - 1);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new AssertionError();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tObject obj = list.get(list.size() - 1);\n\t\t\t\tif (obj instanceof Line) {\n\t\t\t\t\tLine v = (Line) obj;\n\t\t\t\t\tif (sign(v.a * L.b - v.b * L.a) <= 0) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\tPoint p = intersect(v, L);\n\t\t\t\t\tlist.add(p);\n\t\t\t\t\tlist.add(L);\n\t\t\t\t} else {\n\t\t\t\t\tthrow new AssertionError();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tMap where = new HashMap<>();\n\t\t\tList allLines = new ArrayList<>();\n\t\t\tList res = new ArrayList<>();\n\t\t\tfor (int i = 0; i < list.size(); i += 2) {\n\t\t\t\tLine L = (Line) list.get(i);\n\t\t\t\tallLines.add(L);\n\t\t\t\tif (where.containsKey(L)) {\n\t\t\t\t\tfor (int j = where.get(L); j < allLines.size() - 1; j++) {\n\t\t\t\t\t\tres.add(intersect(allLines.get(j), allLines.get(j + 1)));\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\twhere.put(L, i / 2);\n\t\t\t}\n\t\t\treturn res.toArray(new Point[0]);\n\t\t}\n\n\t\tprivate long cross(PointLong a, PointLong b) {\n\t\t\treturn a.x * b.y - a.y * b.x;\n\t\t}\n\n\t\tclass Point {\n\t\t\tdouble x;\n\t\t\tdouble y;\n\n\t\t\tPoint(double x, double y) {\n\t\t\t\tthis.x = x;\n\t\t\t\tthis.y = y;\n\t\t\t}\n\n\n\t\t\tpublic String toString() {\n\t\t\t\treturn \"(\" + x + \" \" + y + \")\";\n\t\t\t\t//return String.format(\"(%.4f %.4f)\", x, y);\n\t\t\t}\n\n\t\t}\n\n\t\tclass Line {\n\t\t\tdouble a;\n\t\t\tdouble b;\n\t\t\tdouble c;\n\t\t\tPoint anyPoint;\n\n\t\t\tLine(double a, double b, double c) {\n\t\t\t\tthis.a = a;\n\t\t\t\tthis.b = b;\n\t\t\t\tthis.c = c;\n\t\t\t}\n\n\t\t\tLine(Point p1, Point p2) {\n\t\t\t\ta = p1.y - p2.y;\n\t\t\t\tb = p2.x - p1.x;\n\t\t\t\tc = -a * p1.x - b * p1.y;\n\t\t\t\tdouble len = Math.sqrt(a * a + b * b);\n\t\t\t\ta /= len;\n\t\t\t\tb /= len;\n\t\t\t\tc /= len;\n\t\t\t\tanyPoint = p1;\n\t\t\t}\n\n\t\t\tPoint anyPoint() {\n\t\t\t\tif (anyPoint != null) {\n\t\t\t\t\treturn anyPoint;\n\t\t\t\t}\n\t\t\t\tif (Math.abs(b) < eps) {\n\t\t\t\t\tif (Math.abs(a) < eps) {\n\t\t\t\t\t\tthrow new AssertionError();\n\t\t\t\t\t}\n\t\t\t\t\treturn new Point(-c / a, 0);\n\t\t\t\t}\n\t\t\t\treturn new Point(0, -c / b);\n\t\t\t}\n\n\n\t\t\tpublic String toString() {\n\t\t\t\treturn a + \" \" + b + \" \" + c;\n\t\t\t}\n\n\t\t}\n\n\t\tclass PointLong {\n\t\t\tlong x;\n\t\t\tlong y;\n\n\t\t\tPointLong(long x, long y) {\n\t\t\t\tthis.x = x;\n\t\t\t\tthis.y = y;\n\t\t\t}\n\n\t\t\tPointLong sub(PointLong o) {\n\t\t\t\treturn new PointLong(x - o.x, y - o.y);\n\t\t\t}\n\n\t\t\tPoint toDoublePoint() {\n\t\t\t\treturn new Point(x, y);\n\t\t\t}\n\n\n\t\t\tpublic String toString() {\n\t\t\t\treturn \"(\" + x + \" \" + y + \")\";\n\t\t\t}\n\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\tst = new StringTokenizer(in.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\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t}\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c540bbe3d85385c79ed707aab533554d", "src_uid": "6afe0718ad89e3fd51a456e0144c538d", "difficulty": 3300.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskD solver = new TaskD();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskD {\n final int MOD = (int) 1e9 + 7;\n int invMod2 = invmod(2);\n private final int sz = 22;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int l = in.nextInt(), r = in.nextInt();\n\n int ans = solve(r) - solve(l - 1);\n if (ans < 0) ans += MOD;\n\n out.println(ans);\n }\n\n private int pow(int x, int y) {\n int ret = 1;\n for (; y > 0; y >>= 1) {\n if ((y & 1) != 0) ret = (int) ((long) ret * x % MOD);\n x = (int) ((long) x * x % MOD);\n }\n return ret;\n }\n\n private int invmod(int x) {\n return pow(x, MOD - 2);\n }\n\n private boolean good(int a, int b) {\n return !(a == b ||\n a == 0 && b == 3 ||\n a == 3 && b == 0 ||\n a == 1 && b == 2 ||\n a == 2 && b == 1);\n }\n\n private boolean good(int a, int b, int c) {\n return !(a == 1 && b == 0 && c == 2 ||\n a == 2 && b == 0 && c == 1);\n }\n\n private int solve(int n) {\n if (n <= 1) return 4 * n;\n\n Matrix A = new Matrix();\n for (int i = 0; i <= 4; ++i) {\n for (int j = 0; j < 4; ++j) {\n for (int k = 0; k < 4; ++k) {\n if (!good(i, j) || !good(j, k) || !good(i, j, k))\n continue;\n A.a[5 * k + j][5 * j + i] = 1;\n }\n }\n }\n for (int i = 0; i < 4; ++i) {\n A.a[5 * i + 4][20] = 1;\n }\n A.a[21][21] = 1;\n for (int i = 0; i < 4; ++i) {\n for (int j = 0; j <= 4; ++j) {\n if (good(i, j)) {\n A.a[21][5 * i + j] = 1;\n }\n }\n }\n\n int ans = pow(A, n + 1).a[21][20];\n if (n >= 2) {\n int add = pow(A, (n + 1) / 2 + 1).a[21][20];\n ans = (ans + add) % MOD;\n ans = (int) ((long) ans * invMod2 % MOD);\n }\n\n return ans;\n }\n\n private Matrix pow(Matrix x, int y) {\n Matrix ret = new Matrix();\n for (int i = 0; i < sz; ++i)\n ret.a[i][i] = 1;\n for (; y > 0; y >>= 1) {\n if ((y & 1) != 0) ret = ret.mul(x);\n x = x.mul(x);\n }\n return ret;\n }\n\n private class Matrix {\n int[][] a;\n\n Matrix() {\n a = new int[sz][sz];\n }\n\n public Matrix mul(Matrix o) {\n Matrix r = new Matrix();\n for (int i = 0; i < sz; ++i) {\n for (int j = 0; j < sz; ++j) {\n for (int k = 0; k < sz; ++k) {\n r.a[i][j] = (int) ((r.a[i][j] +\n (long) a[i][k] * o.a[k][j]) % MOD);\n }\n }\n }\n return r;\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\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1)\n throw new UnknownError();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new UnknownError();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public String next() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuffer res = new StringBuffer();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n\n return res.toString();\n }\n\n private boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fad721b4d7feaaeb02fc444220f6f88b", "src_uid": "e04b6957d9c1659e9d2460410cb57f10", "difficulty": 2500.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.HashMap;\nimport java.util.StringTokenizer;\n\npublic class Main {\n Scanner in;\n PrintWriter out;\n\n void setIn(String fI) {\n\n try {\n in = new Scanner(new FileInputStream(new File(fI)));\n } catch (FileNotFoundException e) {\n throw new Error(e);\n }\n }\n\n void setIn() {\n in = new Scanner(System.in);\n }\n\n void setOut(String fO) {\n try {\n out = new PrintWriter(new FileWriter(fO));\n } catch (IOException e) {\n throw new Error(e);\n }\n }\n\n void setOut() {\n out = new PrintWriter(System.out);\n }\n\n class Scanner {\n StringTokenizer st;\n BufferedReader in;\n String del;\n\n Scanner(InputStream is) {\n in = new BufferedReader(new InputStreamReader(is));\n st = null;\n del = \" \\t\\n\\r\\f\";\n }\n\n void setDelimiters(String del) {\n this.del = del;\n }\n\n String next() {\n if (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(nextLine(), del);\n }\n return st.nextToken();\n }\n\n String nextLine() {\n try {\n st = null;\n return in.readLine();\n } catch (IOException e) {\n throw new Error(e);\n }\n }\n\n boolean hasNext() {\n try {\n return in.ready() || (st != null && st.hasMoreTokens());\n } catch (IOException e) {\n throw new Error(e);\n }\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n BigInteger nextBigInteger() {\n return new BigInteger(next());\n }\n\n BigDecimal nextBigDecimal() {\n return new BigDecimal(next());\n }\n\n int[] nextIntArray(int len) {\n int[] a = new int[len];\n for (int i = 0; i < len; i++) {\n a[i] = nextInt();\n }\n return a;\n }\n }\n\n public static void main(String[] args) {\n new Main().run();\n }\n\n void run() {\n setIn();\n setOut();\n try {\n solve();\n } finally {\n out.close();\n }\n }\n\n class Point {\n int x;\n int y;\n\n Point(int X, int Y) {\n x = X;\n y = Y;\n }\n\n @Override\n public boolean equals(Object o) {\n Point p = (Point) o;\n return p.x == x && y == p.y;\n }\n\n @Override\n public int hashCode() {\n return 31 * x + y;\n }\n }\n\n class FoundException extends Exception {\n\n }\n\n boolean isMagic(int[][] a) {\n int s = 0;\n for (int i = 0; i < a.length; i++) {\n s += a[0][i];\n }\n int n = a.length;\n int s1 = 0;\n int s2 = 0;\n for (int i = 0; i < n; i++) {\n int curS = 0;\n int curS2 = 0;\n s1 += a[i][i];\n s2 += a[i][n - 1 - i];\n for (int j = 0; j < n; j++) {\n curS += a[i][j];\n curS2 += a[j][i];\n }\n if (curS != s || curS2 != s)\n return false;\n }\n return s1 == s && s2 == s;\n }\n\n int[][] a;\n\n void out(int[][] a) {\n for (int i = 0; i < a.length; i++) {\n for (int j = 0; j < a.length; j++) {\n out.print(a[i][j] + \" \");\n }\n out.println();\n }\n out.println();\n }\n\n void go(int x, int y, HashMap numb) throws FoundException {\n if (y == 0 && x == a.length) {\n if (isMagic(a)) {\n int n = a.length;\n int sum = 0;\n for (int i = 0; i < n; i++) {\n sum += a[0][i];\n }\n out.println(sum);\n for (int i = 0; i < a.length; i++) {\n for (int j = 0; j < n; j++) {\n out.print(a[i][j] + \" \");\n }\n out.println();\n }\n throw new FoundException();\n }\n }\n\n // out(a);\n int prevX = x;\n int prevY = y;\n y++;\n if (y == a.length) {\n x++;\n y = 0;\n }\n\n for (int key : numb.keySet()) {\n if (numb.get(key) != 0) {\n numb.put(key, numb.get(key) - 1);\n a[prevX][prevY] = key;\n go(x, y, numb);\n numb.put(key, numb.get(key) + 1);\n }\n }\n }\n\n void solve() {\n int n = in.nextInt();\n int[] b = in.nextIntArray(n * n);\n HashMap numbers = new HashMap();\n for (int i = 0; i < n * n; i++) {\n if (!numbers.containsKey(b[i]))\n numbers.put(b[i], 1);\n else\n numbers.put(b[i], numbers.get(b[i]) + 1);\n }\n a = new int[n][n];\n try {\n go(0, 0, numbers);\n } catch (FoundException e) {\n // good\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d90f51ea2dc8066a46fdcacb2ad3a05c", "src_uid": "7c806fb163aaf23e1eef3e6570aea436", "difficulty": 1900.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n G1PlaylistForPolycarpEasyVersion solver = new G1PlaylistForPolycarpEasyVersion();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class G1PlaylistForPolycarpEasyVersion {\n private int songsCount;\n private int totalDuration;\n private G1PlaylistForPolycarpEasyVersion.Song songs;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n songsCount = in.nextInt();\n totalDuration = in.nextInt();\n\n songs = new G1PlaylistForPolycarpEasyVersion.Song[songsCount];\n\n for (int i = 0; i < songsCount; i++) {\n songs[i] = new G1PlaylistForPolycarpEasyVersion.Song(in.nextInt(), in.nextInt());\n }\n\n int ret = 0;\n int chosenSongs = 0;\n\n for (int i = 0; i < songsCount; i++) {\n chosenSongs = 1 << i;\n ret += search(totalDuration - songs[i].duration, songs[i], chosenSongs);\n }\n\n out.println(ret);\n }\n\n private int search(int timeLeft, G1PlaylistForPolycarpEasyVersion.Song prev, int chosen) {\n if (timeLeft < 0) {\n return 0;\n }\n\n if (timeLeft == 0) {\n return 1;\n }\n\n int ret = 0;\n\n for (int i = 0; i < songsCount; i++) {\n if (((1 << i) & chosen) == 0 && songs[i].genre != prev.genre) {\n ret += search(timeLeft - songs[i].duration, songs[i], chosen | 1 << i);\n }\n }\n\n return ret;\n }\n\n static class Song {\n public int duration;\n public int genre;\n\n public Song(int duration, int genre) {\n this.duration = duration;\n this.genre = genre;\n }\n\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String 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", "compilation_error": true, "code_uid": "9924b988ac6a61eb2ea1160f4ebb399a", "src_uid": "ac2a37ff4c7e89a345b189e4891bbf56", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class E {\n\n\tstatic class Point {\n\t\tint x, y, id;\n\n\t\tpublic Point(int x, int y, int id) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t\tthis.id = id;\n\t\t}\n\t}\n\n\tstatic Comparator byAngle = new Comparator() {\n\n\t\t@Override\n\t\tpublic int compare(Point o1, Point o2) {\n\t\t\treturn -Long.compare((long) o1.x * o2.y, (long) o2.x * o1.y);\n\t\t}\n\t};\n\n\tvoid submit() {\n\t\tint r = nextInt();\n\t\tint q = nextInt();\n\n\t\tint[][] qs = new int[q][3];\n\t\tint n = 0;\n\n\t\tfor (int i = 0; i < q; i++) {\n\n\t\t\tqs[i][0] = nextInt();\n\t\t\tif (qs[i][0] == 1) {\n\t\t\t\tn++;\n\t\t\t\tqs[i][1] = nextInt();\n\t\t\t\tqs[i][2] = nextInt();\n\t\t\t} else if (qs[i][0] == 2) {\n\t\t\t\tqs[i][1] = nextInt() - 1;\n\t\t\t} else if (qs[i][0] == 3) {\n\t\t\t\tqs[i][1] = nextInt() - 1;\n\t\t\t\tqs[i][2] = nextInt() - 1;\n\t\t\t}\n\t\t}\n\n\t\tint[] xs, ys;\n\n\t\tPoint[] px, py;\n\n\t\tint[] treeXIdx = new int[n];\n\t\tint[] askX;\n\n\t\t{\n\t\t\tPoint[] a = new Point[n];\n\t\t\tint ptr = 0;\n\t\t\tfor (int i = 0; i < q; i++) {\n\t\t\t\tif (qs[i][0] == 1) {\n\t\t\t\t\ta[ptr] = new Point(qs[i][1] - r, qs[i][2], ptr);\n\t\t\t\t\tptr++;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tArrays.sort(a, byAngle);\n\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\ttreeXIdx[a[i].id] = i;\n\t\t\t}\n\n\t\t\tpx = makeUnique(a, byAngle);\n\t\t\txs = new int[n];\n\n\t\t\tfor (Point p : a) {\n\t\t\t\txs[p.id] = Arrays.binarySearch(px, p, byAngle);\n\t\t\t}\n\n\t\t\taskX = new int[px.length];\n\t\t\taskX[px.length - 1] = n;\n\n\t\t\tint pptr = px.length - 1;\n\t\t\tfor (int i = n - 2; i >= 0; i--) {\n\t\t\t\tif (byAngle.compare(a[i], a[i + 1]) != 0) {\n\t\t\t\t\taskX[--pptr] = i + 1;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (pptr != 0) {\n\t\t\t\tthrow new AssertionError();\n\t\t\t}\n\t\t}\n\n\t\t{\n\t\t\tPoint[] a = new Point[n];\n\t\t\tint ptr = 0;\n\t\t\tfor (int i = 0; i < q; i++) {\n\t\t\t\tif (qs[i][0] == 1) {\n\t\t\t\t\ta[ptr] = new Point(qs[i][1] + r, qs[i][2], ptr);\n\t\t\t\t\tptr++;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tpy = makeUnique(a, byAngle.reversed());\n\t\t\tys = new int[n];\n\n\t\t\tfor (Point p : a) {\n\t\t\t\tys[p.id] = Arrays.binarySearch(py, p, byAngle.reversed());\n\t\t\t}\n\t\t}\n\t\t\n//\t\tSystem.err.println(Arrays.toString(xs));\n//\t\tSystem.err.println(Arrays.toString(ys));\n\n\t\tint ptr = 0;\n\n\t\troot = new Node(0, n);\n\n\t\tfor (int i = 0; i < q; i++) {\n\t\t\tif (qs[i][0] == 1) {\n\t\t\t\troot.set(treeXIdx[ptr], ys[ptr]);\n\t\t\t\tptr++;\n\t\t\t} else if (qs[i][0] == 2) {\n\t\t\t\tint what = qs[i][1];\n\t\t\t\troot.set(treeXIdx[what], Integer.MAX_VALUE);\n\t\t\t} else if (qs[i][0] == 3) {\n\t\t\t\tint p1 = qs[i][1];\n\t\t\t\tint p2 = qs[i][2];\n\t\t\t\troot.set(treeXIdx[p1], Integer.MAX_VALUE);\n\t\t\t\troot.set(treeXIdx[p2], Integer.MAX_VALUE);\n\n\t\t\t\tint qx = Math.max(xs[p1], xs[p2]);\n\t\t\t\tint qy = Math.max(ys[p1], ys[p2]);\n\n\t\t\t\tint ret = root.get(0, askX[qx]);\n\n\t\t\t\tboolean ans = ret > qy && !isInside(r, px[qx], py[qy]);\n\t\t\t\tout.println(ans ? \"YES\" : \"NO\");\n\n\t\t\t\troot.set(treeXIdx[p1], ys[p1]);\n\t\t\t\troot.set(treeXIdx[p2], ys[p2]);\n\t\t\t}\n\t\t}\n\t}\n\n\tTreeSet[] set;\n\tNode root;\n\n\tstatic class Node {\n\t\tint l, r;\n\t\tNode left, right;\n\n\t\tint val;\n\n\t\tpublic Node(int l, int r) {\n\t\t\tthis.l = l;\n\t\t\tthis.r = r;\n\t\t\tval = Integer.MAX_VALUE;\n\n\t\t\tif (r - l > 1) {\n\t\t\t\tint m = (l + r) >> 1;\n\t\t\t\tleft = new Node(l, m);\n\t\t\t\tright = new Node(m, r);\n\t\t\t}\n\t\t}\n\n\t\tvoid set(int x, int y) {\n\t\t\tif (r - l == 1) {\n\t\t\t\tval = y;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t(x < left.r ? left : right).set(x, y);\n\t\t\tval = Math.min(left.val, right.val);\n\t\t}\n\n\t\tint get(int ql, int qr) {\n\t\t\tif (ql <= l && r <= qr) {\n\t\t\t\treturn val;\n\t\t\t}\n\t\t\tif (l >= qr || ql >= r) {\n\t\t\t\treturn Integer.MAX_VALUE;\n\t\t\t}\n\t\t\treturn Math.min(left.get(ql, qr), right.get(ql, qr));\n\t\t}\n\t}\n\n\tboolean isInside(int r, Point vl, Point vr) {\n\t\treturn (long) vl.x * vr.x + (long) vl.y * vr.y < 0;\n\t}\n\n\tPoint[] makeUnique(Point[] a, Comparator cmp) {\n\t\ta = a.clone();\n\t\tArrays.sort(a, cmp);\n\n\t\tint sz = 1;\n\t\tfor (int i = 1; i < a.length; i++) {\n\t\t\tif (cmp.compare(a[i], a[sz - 1]) != 0) {\n\t\t\t\ta[sz++] = a[i];\n\t\t\t}\n\t\t}\n\t\treturn Arrays.copyOf(a, sz);\n\t}\n\n\tvoid preCalc() {\n\n\t}\n\n\tvoid stress() {\n\n\t}\n\n\tvoid test() {\n\n\t}\n\n\tE() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tpreCalc();\n\t\tsubmit();\n\t\t// stress();\n\t\t// test();\n\t\tout.close();\n\t}\n\n\tstatic final Random rng = new Random();\n\n\tstatic int rand(int l, int r) {\n\t\treturn l + rng.nextInt(r - l + 1);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew E();\n\t}\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t}\n\n\tint nextInt() {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c8a947c797668ebd9aea25989a702160", "src_uid": "775761bcba74d78b833c295290a2195c", "difficulty": 3100.0} {"lang": "Java 8", "source_code": "import static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.System.exit;\nimport static java.util.Arrays.fill;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class G {\n\n\tinterface IntComparator {\n\t\tpublic int compare(int o1, int o2);\n\t}\n\n\tstatic void sort(int a[], int n, IntComparator cmp) {\n\t\tif (n == 0) {\n\t\t\treturn;\n\t\t}\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tint j = i;\n\t\t\tint ca = a[i];\n\t\t\tdo {\n\t\t\t\tint nj = (j - 1) >> 1;\n\t\t\t\tint na = a[nj];\n\t\t\t\tif (cmp.compare(na, ca) >= 0) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\ta[j] = na;\n\t\t\t\tj = nj;\n\t\t\t} while (j != 0);\n\t\t\ta[j] = ca;\n\t\t}\n\t\tint ca = a[0];\n\t\tfor (int i = n - 1; i > 0; i--) {\n\t\t\tint j = 0;\n\t\t\twhile ((j << 1) + 2 + Integer.MIN_VALUE < i + Integer.MIN_VALUE) {\n\t\t\t\tj <<= 1;\n\t\t\t\tj += (cmp.compare(a[j + 1], a[j + 2]) < 0) ? 2 : 1;\n\t\t\t}\n\t\t\tif ((j << 1) + 2 == i) {\n\t\t\t\tj = (j << 1) + 1;\n\t\t\t}\n\t\t\tint na = a[i];\n\t\t\ta[i] = ca;\n\t\t\tca = na;\n\t\t\twhile (j != 0 && cmp.compare(a[j], ca) < 0) {\n\t\t\t\tj = (j - 1) >> 1;\n\t\t\t}\n\t\t\twhile (j != 0) {\n\t\t\t\tna = a[j];\n\t\t\t\ta[j] = ca;\n\t\t\t\tca = na;\n\t\t\t\tj = (j - 1) >> 1;\n\t\t\t}\n\t\t}\n\t\ta[0] = ca;\n\t}\n\n\tstatic int n, k, a[], sum, move[], moveOffset, defer[], deferCnt, derefFirst[];\n\n\tstatic void doMove(int pos) {\n\t\tif (a[pos] < (move[(pos + 1) % n] - moveOffset) || a[(pos + k - 1) % n] < -(move[(pos + k - 1) % n] - moveOffset)) {\n\t\t\tif (deferCnt == 0) {\n\t\t\t\tderefFirst = new int[k - 1];\n\t\t\t\tfor (int i = 0; i < k - 1; i++) {\n\t\t\t\t\tderefFirst[i] = move[(pos + i + 1) % n] - moveOffset;\n\t\t\t\t\tmove[(pos + i + 1) % n] = moveOffset;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdefer[deferCnt++] = pos;\n\t\t\treturn;\n\t\t}\n\t\tfor (int i = 0; i < k - 1; i++) {\n\t\t\tint m = move[(pos + i + 1) % n] - moveOffset;\n\t\t\ta[(pos + i) % n] -= m;\n\t\t\ta[(pos + i + 1) % n] += m;\n\t\t\tmove[(pos + i + 1) % n] = moveOffset;\n\t\t}\n\t\tout.print(pos + 1);\n\t\tfor (int i = 0; i < k; i++) {\n\t\t\tout.print(\" \" + a[(pos + i) % n]);\n\t\t}\n\t\tout.println();\n\t\tif (deferCnt > 0) {\n\t\t\tif (--deferCnt == 0) {\n\t\t\t\tpos = defer[0];\n\t\t\t\tfor (int i = 0; i < k - 1; i++) {\n\t\t\t\t\tint m = derefFirst[i];\n\t\t\t\t\ta[(pos + i) % n] -= m;\n\t\t\t\t\ta[(pos + i + 1) % n] += m;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tdoMove(defer[deferCnt]);\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic void solve() throws Exception {\n\t\tn = scanInt();\n\t\tk = scanInt();\n\t\ta = new int[n];\n\t\tsum = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tsum += a[i] = scanInt();\n\t\t}\n\t\tsum /= n;\n\t\tmove = new int[n];\n\t\tint idx[] = new int[n];\n\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\tmove[i + 1] = move[i] + a[i] - sum;\n\t\t\tidx[i] = i;\n\t\t}\n\t\tidx[n - 1] = n - 1;\n\t\tsort(idx, n, new IntComparator() {\n\t\t\tpublic int compare(int o1, int o2) {\n\t\t\t\treturn move[o1] != move[o2] ? move[o1] - move[o2] : o1 - o2;\n\t\t\t}\n\t\t});\n\t\tint ans = (n + k - 2) / (k - 1), ansStart = -1;\n\t\tint maxChain[] = new int[n], curNext[] = new int[k - 1];\n\t\tfill(curNext, -1);\n\t\tfor (int i = 0, j; i < n; i = j) {\n\t\t\tfor (j = i + 1; j < n && move[idx[j]] == move[idx[i]]; j++) { }\n\t\t\tfor (int ii = j - 1; ii >= i; ii--) {\n\t\t\t\tint ci = idx[ii], ni = curNext[(ci + 1) % (k - 1)];\n//\t\t\t\tSystem.err.println(ci + \" \" + ni);\n\t\t\t\tmaxChain[ci] = ni < 0 ? 1 : 1 + maxChain[ni];\n\t\t\t\tint cans = (n - maxChain[ci] + k - 2) / (k - 1);\n\t\t\t\tif (cans < ans) {\n\t\t\t\t\tans = cans;\n\t\t\t\t\tansStart = ci;\n\t\t\t\t}\n\t\t\t\tcurNext[ci % (k - 1)] = ci;\n\t\t\t}\n\t\t\tfor (int ii = i; ii < j; ii++) {\n\t\t\t\tcurNext[idx[ii] % (k - 1)] = -1;\n\t\t\t}\n\t\t}\n//\t\tSystem.err.println(Arrays.toString(maxChain));\n\t\tout.println(ans);\n\t\tdefer = new int[n];\n\t\tdeferCnt = 0;\n//\t\tSystem.err.println(ans + \" \" + ansStart + \" \" + sum);\n\t\tif (ansStart < 0) {\n\t\t\tmoveOffset = 0;\n\t\t\tfor (int i = 0; i < ans; i++) {\n\t\t\t\tdoMove(i * (k - 1));\n\t\t\t}\n\t\t} else {\n\t\t\tmoveOffset = move[ansStart];\n//\t\t\tSystem.err.println(Arrays.toString(move) + \" \" + moveOffset);\n\t\t\tfor (int i = 0, pos = ansStart; i < ans; i++) {\n\t\t\t\twhile (move[(pos + 1) % n] == moveOffset) {\n\t\t\t\t\tpos = (pos + 1) % n;\n\t\t\t\t}\n//\t\t\t\tSystem.err.println(pos);\n\t\t\t\tdoMove(pos);\n//\t\t\t\tSystem.err.println(Arrays.toString(a));\n\t\t\t\tpos = (pos + k - 1) % n;\n\t\t\t}\n\t\t}\n\t\tif (deferCnt != 0) {\n\t\t\tthrow new AssertionError();\n\t\t}\n\t}\n\n\tstatic int scanInt() throws IOException {\n\t\treturn parseInt(scanString());\n\t}\n\n\tstatic long scanLong() throws IOException {\n\t\treturn parseLong(scanString());\n\t}\n\n\tstatic String scanString() throws IOException {\n\t\twhile (tok == null || !tok.hasMoreTokens()) {\n\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t\tin.close();\n\t\t\tout.close();\n\t\t} catch (Throwable e) {\n\t\t\te.printStackTrace();\n\t\t\texit(1);\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "673610fd253f3835562a83f66787497b", "src_uid": "8b9099351b979cdb61413cc039861f8d", "difficulty": 3500.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class StringPlay {\n public static final int UNREACHABLE = 1000;\n\n FastScanner in;\n PrintWriter out;\n\n public void solve() throws IOException {\n int n = in.nextInt();\n char[][] t = new char[n][n];\n for (int i = 0; i < n; i++) {\n t[i] = in.next().toCharArray();\n }\n\n\n int[] curr = new int[1 << n];\n Arrays.fill(curr, UNREACHABLE);\n curr[1 << (n - 1)] = getValue(t[n - 1][n - 1]);\n\n int[] next = new int[1 << n];\n\n for (int layer = 2 * n - 2; layer > 0; layer--) {\n boolean first = layer % 2 == 0;\n Arrays.fill(next, UNREACHABLE);\n\n for (int state = 0; state < curr.length; state++) {\n if (curr[state] == UNREACHABLE) {\n continue;\n }\n\n int[] nextMask = new int['z' - 'a' + 1];\n for (int row = 0; row < n; row++) {\n int col = layer - row;\n if (col < 0 || col > n - 1) {\n continue;\n }\n int bit = 1 << col;\n if ((state & bit) == 0) {\n continue;\n }\n\n if (col > 0) {\n int ch = t[row][col - 1] - 'a';\n nextMask[ch] += (1 << (col - 1));\n }\n if (row > 0) {\n int ch = t[row - 1][col] - 'a';\n nextMask[ch] += (1 << col);\n }\n }\n\n for (int i = 0; i < nextMask.length; i++) {\n int add = getValue((char) ('a' + i));\n int mask = nextMask[i];\n if (mask == 0) {\n continue;\n }\n\n if (next[mask] == UNREACHABLE) {\n next[mask] = curr[state] + add;\n }\n if (first) {\n next[mask] = Math.max(next[mask], curr[state] + add);\n } else {\n next[mask] = Math.min(next[mask], curr[state] + add);\n }\n }\n }\n\n int[] tmp = next;\n next = curr;\n curr = tmp;\n }\n\n if (curr[1] == 0) {\n out.println(\"DRAW\");\n } else {\n out.println(curr[1] > 0 ? \"FIRST\" : \"SECOND\");\n }\n }\n\n private int getValue(char c) {\n return c != 'a' ? c == 'b' ? -1 : 0 : 1;\n }\n\n public void run() {\n try {\n in = new FastScanner(System.in);\n out = new PrintWriter(System.out);\n\n solve();\n\n out.close();\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n\n class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n FastScanner(InputStream is) {\n br = new BufferedReader(new InputStreamReader(is));\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 StringPlay().run();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "38a1ce39a3a334fd4e790f175afe2688", "src_uid": "d803fe167a96656f8debdc21edd988e4", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class MainD {\n\tstatic StdIn in = new StdIn();\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\tstatic long p;\n\tstatic List pFs = new ArrayList();\n\tstatic long[] fact1;\n\tstatic int[][] fact2;\n\t\n\tpublic static void main(String[] args) {\n\t\tint n=in.nextInt();\n\t\tp=in.nextLong();\n\t\tint l=in.nextInt(), r=in.nextInt();\n\t\tlong p2=p;\n\t\tfor(int i=2; i*i<=p2; ++i) {\n\t\t\tif(p2%i==0) {\n\t\t\t\twhile(p2%i==0)\n\t\t\t\t\tp2/=i;\n\t\t\t\tpFs.add((long)i);\n\t\t\t}\n\t\t}\n\t\tif(p2>1)\n\t\t\tpFs.add(p2);\n\t\tfact1 = new long[2*n+1];\n\t\tfact2 = new int[pFs.size()][2*n+1];\n\t\tfact1[0]=1;\n\t\tfor(int i=1; i<=2*n; ++i) {\n\t\t\tlong a=i;\n\t\t\tfor(int j=0; jn||k<0)\n\t\t\treturn 0;\n\t\tlong r=fact1[n]*modI(fact1[k])%p*modI(fact1[n-k])%p;\n\t\tfor(int i=0; i1) {\n q = a / m0;\n t = m0;\n m0 = a % m0;\n a = t;\n t = x0;\n x0 = x1 - q * x0;\n x1 = t;\n }\n if(x1<0)\n\t\t\tx1 += p;\n return x1;\n }\n\t\n\tinterface Input {\n\t\tpublic String next();\n\t\tpublic String nextLine();\n\t\tpublic int nextInt();\n\t\tpublic long nextLong();\n\t\tpublic double nextDouble();\n\t}\n\tstatic class StdIn implements Input {\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\t\tpublic StdIn() {\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\t\tpublic StdIn(InputStream in) {\n\t\t\ttry{\n\t\t\t\tdin = new DataInputStream(in);\n\t\t\t} catch(Exception e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t\tbuffer = new byte[BUFFER_SIZE];\n\t\t\tbufferPointer = bytesRead = 0;\n\t\t}\n\t\tpublic String next() {\n\t\t\tint c;\n\t\t\twhile((c=read())!=-1&&(c==' '||c=='\\n'||c=='\\r'));\n\t\t\tStringBuilder s = new StringBuilder();\n\t\t\twhile (c != -1)\n\t\t\t{\n\t\t\t\tif (c == ' ' || c == '\\n'||c=='\\r')\n\t\t\t\t\tbreak;\n\t\t\t\ts.append((char)c);\n\t\t\t\tc=read();\n\t\t\t}\n\t\t\treturn s.toString();\n\t\t}\n\t\tpublic String nextLine() {\n\t\t\tint c;\n\t\t\twhile((c=read())!=-1&&(c==' '||c=='\\n'||c=='\\r'));\n\t\t\tStringBuilder s = new StringBuilder();\n\t\t\twhile (c != -1)\n\t\t\t{\n\t\t\t\tif (c == '\\n'||c=='\\r')\n\t\t\t\t\tbreak;\n\t\t\t\ts.append((char)c);\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\treturn s.toString();\n\t\t}\n\t\tpublic int nextInt() {\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\twhile ((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\t\tpublic int[] readIntArray(int n) {\n\t\t\tint[] ar = new int[n];\n\t\t\tfor(int i=0; i= '0' && c <= '9');\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\t\tpublic long[] readLongArray(int n) {\n\t\t\tlong[] ar = new long[n];\n\t\t\tfor(int i=0; i= '0' && c <= '9');\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\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\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\t\tprivate byte read() {\n\t\t\ttry{\n\t\t\t\tif (bufferPointer == bytesRead)\n\t\t\t\t\tfillBuffer();\n\t\t\t\treturn buffer[bufferPointer++];\n\t\t\t} catch(IOException e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t}\n\t\tpublic void close() throws IOException {\n\t\t\tif (din == null)\n\t\t\t\treturn;\n\t\t\tdin.close();\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d4bdeccd3fb79480aa52e664a69a2071", "src_uid": "6ddc487029785738679007443fc08463", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.io.UncheckedIOException;\nimport java.io.Closeable;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, new TaskAdapter(), \"\", 1 << 27);\n thread.start();\n thread.join();\n }\n\n static class TaskAdapter implements Runnable {\n @Override\n public void run() {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastInput in = new FastInput(inputStream);\n FastOutput out = new FastOutput(outputStream);\n GXMouseInTheCampus solver = new GXMouseInTheCampus();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class GXMouseInTheCampus {\n LongHashMap mu = new LongHashMap(100000, false);\n LongHashMap euler = new LongHashMap(100000, false);\n long[] primes;\n\n {\n mu.put(1, 1);\n euler.put(1, 1);\n }\n\n public long oneOfPrimeFactor(long x) {\n for (long p : primes) {\n if (x % p == 0) {\n return p;\n }\n }\n return x;\n }\n\n public void populate(long x) {\n long factor = oneOfPrimeFactor(x);\n long cnt = 0;\n long y = x;\n while (y % factor == 0) {\n cnt++;\n y /= factor;\n }\n if (cnt > 1) {\n mu.put(x, 0);\n } else {\n mu.put(x, -mu(y));\n }\n euler.put(x, euler(y) * (x / y - x / y / factor));\n }\n\n public long mu(long x) {\n long ans = mu.getOrDefault(x, -1);\n if (ans == -1) {\n populate(x);\n ans = mu.get(x);\n }\n return ans;\n }\n\n public long euler(long x) {\n long ans = euler.getOrDefault(x, -1);\n if (ans == -1) {\n populate(x);\n ans = euler.get(x);\n }\n return ans;\n }\n\n public void solve(int testNumber, FastInput in, FastOutput out) {\n long m = in.readLong();\n long x = in.readLong();\n\n primes = Factorization.factorizeNumberPrime(m).toArray();\n LongList allFactorOfM = new LongList(20000);\n LongList tmpList = new LongList(20000);\n collect(allFactorOfM, m, 0);\n LongPower power = new LongPower(ILongModular.getInstance(m));\n\n long total = 1;\n for (int i = 0; i < allFactorOfM.size(); i++) {\n long g = allFactorOfM.get(i);\n if (g == m) {\n continue;\n }\n long mg = m / g;\n tmpList.clear();\n collect(tmpList, mg, 0);\n long cnt = 0;\n for (int j = tmpList.size() - 1; j >= 0; j--) {\n long t = tmpList.get(j);\n cnt += mu(t) * ((m - 1) / (t * g));\n }\n\n tmpList.clear();\n long euler = euler(mg);\n LongList primeFactors = Factorization.factorizeNumberPrime(euler);\n\n long n = euler;\n\n for (int j = 0; j < primeFactors.size(); j++) {\n long p = primeFactors.get(j);\n while (n % p == 0 && power.pow(x, n / p) % mg == 1) {\n n /= p;\n }\n }\n\n if (cnt % n != 0) {\n throw new IllegalStateException();\n }\n total += cnt / n;\n }\n\n out.println(total);\n }\n\n public void collect(LongList list, long x, int i) {\n if (i == primes.length) {\n list.add(x);\n return;\n }\n collect(list, x, i + 1);\n while (x % primes[i] == 0) {\n x /= primes[i];\n collect(list, x, i + 1);\n }\n }\n\n }\n\n static class DigitUtils {\n private DigitUtils() {\n }\n\n public static long round(double x) {\n if (x >= 0) {\n return (long) (x + 0.5);\n } else {\n return (long) (x - 0.5);\n }\n }\n\n public static long mod(long x, long mod) {\n x %= mod;\n if (x < 0) {\n x += mod;\n }\n return x;\n }\n\n public static long mulMod(long a, long b, long mod) {\n long k = DigitUtils.round((double) a / mod * b);\n return DigitUtils.mod(a * b - k * mod, mod);\n }\n\n }\n\n static class FastOutput implements AutoCloseable, Closeable, Appendable {\n private StringBuilder cache = new StringBuilder(10 << 20);\n private final Writer os;\n\n public FastOutput append(CharSequence csq) {\n cache.append(csq);\n return this;\n }\n\n public FastOutput append(CharSequence csq, int start, int end) {\n cache.append(csq, start, end);\n return this;\n }\n\n public FastOutput(Writer os) {\n this.os = os;\n }\n\n public FastOutput(OutputStream os) {\n this(new OutputStreamWriter(os));\n }\n\n public FastOutput append(char c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput println(long c) {\n cache.append(c);\n println();\n return this;\n }\n\n public FastOutput println() {\n cache.append(System.lineSeparator());\n return this;\n }\n\n public FastOutput flush() {\n try {\n os.append(cache);\n os.flush();\n cache.setLength(0);\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n return this;\n }\n\n public void close() {\n flush();\n try {\n os.close();\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n public String toString() {\n return cache.toString();\n }\n\n }\n\n static class LongPower {\n final ILongModular modular;\n\n public LongPower(ILongModular modular) {\n this.modular = modular;\n }\n\n public long pow(long x, long n) {\n if (n == 0) {\n return 1;\n }\n long r = pow(x, n >> 1);\n r = modular.mul(r, r);\n if ((n & 1) == 1) {\n r = modular.mul(r, x);\n }\n return r;\n }\n\n }\n\n static class Factorization {\n public static LongList factorizeNumberPrime(long x) {\n LongList ans = new LongList();\n for (long i = 2; i * i <= x; i++) {\n if (x % i != 0) {\n continue;\n }\n ans.add(i);\n while (x % i == 0) {\n x /= i;\n }\n }\n if (x > 1) {\n ans.add(x);\n }\n return ans;\n }\n\n }\n\n static class LongHashMap {\n private int[] slot;\n private int[] next;\n private long[] keys;\n private long[] values;\n private int alloc;\n private boolean[] removed;\n private int mask;\n private int size;\n private boolean rehash;\n\n public LongHashMap(int cap, boolean rehash) {\n this.mask = (1 << (32 - Integer.numberOfLeadingZeros(cap - 1))) - 1;\n slot = new int[mask + 1];\n next = new int[cap + 1];\n keys = new long[cap + 1];\n values = new long[cap + 1];\n removed = new boolean[cap + 1];\n this.rehash = rehash;\n }\n\n private void doubleCapacity() {\n int newSize = Math.max(next.length + 10, next.length * 2);\n next = Arrays.copyOf(next, newSize);\n keys = Arrays.copyOf(keys, newSize);\n values = Arrays.copyOf(values, newSize);\n removed = Arrays.copyOf(removed, newSize);\n }\n\n public void alloc() {\n alloc++;\n if (alloc >= next.length) {\n doubleCapacity();\n }\n next[alloc] = 0;\n removed[alloc] = false;\n size++;\n }\n\n private void rehash() {\n int[] newSlots = new int[Math.max(16, slot.length * 2)];\n int newMask = newSlots.length - 1;\n for (int i = 0; i < slot.length; i++) {\n if (slot[i] == 0) {\n continue;\n }\n int head = slot[i];\n while (head != 0) {\n int n = next[head];\n int s = hash(keys[head]) & newMask;\n next[head] = newSlots[s];\n newSlots[s] = head;\n head = n;\n }\n }\n this.slot = newSlots;\n this.mask = newMask;\n }\n\n private int hash(long x) {\n int h = Long.hashCode(x);\n return h ^ (h >>> 16);\n }\n\n public void put(long x, long y) {\n put(x, y, true);\n }\n\n public void put(long x, long y, boolean cover) {\n int h = hash(x);\n int s = h & mask;\n if (slot[s] == 0) {\n alloc();\n slot[s] = alloc;\n keys[alloc] = x;\n values[alloc] = y;\n } else {\n int index = findIndexOrLastEntry(s, x);\n if (keys[index] != x) {\n alloc();\n next[index] = alloc;\n keys[alloc] = x;\n values[alloc] = y;\n } else if (cover) {\n values[index] = y;\n }\n }\n if (rehash && size >= slot.length) {\n rehash();\n }\n }\n\n public long getOrDefault(long x, long def) {\n int h = hash(x);\n int s = h & mask;\n if (slot[s] == 0) {\n return def;\n }\n int index = findIndexOrLastEntry(s, x);\n return keys[index] == x ? values[index] : def;\n }\n\n public long get(long x) {\n return getOrDefault(x, 0);\n }\n\n private int findIndexOrLastEntry(int s, long x) {\n int iter = slot[s];\n while (keys[iter] != x) {\n if (next[iter] != 0) {\n iter = next[iter];\n } else {\n return iter;\n }\n }\n return iter;\n }\n\n public LongEntryIterator iterator() {\n return new LongEntryIterator() {\n int index = 1;\n int readIndex = -1;\n\n\n public boolean hasNext() {\n while (index <= alloc && removed[index]) {\n index++;\n }\n return index <= alloc;\n }\n\n\n public long getEntryKey() {\n return keys[readIndex];\n }\n\n\n public long getEntryValue() {\n return values[readIndex];\n }\n\n\n public void next() {\n if (!hasNext()) {\n throw new IllegalStateException();\n }\n readIndex = index;\n index++;\n }\n };\n }\n\n public String toString() {\n LongEntryIterator iterator = iterator();\n StringBuilder builder = new StringBuilder(\"{\");\n while (iterator.hasNext()) {\n iterator.next();\n builder.append(iterator.getEntryKey()).append(\"->\").append(iterator.getEntryValue()).append(',');\n }\n if (builder.charAt(builder.length() - 1) == ',') {\n builder.setLength(builder.length() - 1);\n }\n builder.append('}');\n return builder.toString();\n }\n\n }\n\n static class SequenceUtils {\n public static boolean equal(long[] a, int al, int ar, long[] b, int bl, int br) {\n if ((ar - al) != (br - bl)) {\n return false;\n }\n for (int i = al, j = bl; i <= ar; i++, j++) {\n if (a[i] != b[j]) {\n return false;\n }\n }\n return true;\n }\n\n }\n\n static class FastInput {\n private final InputStream is;\n private byte[] buf = new byte[1 << 13];\n private int bufLen;\n private int bufOffset;\n private int next;\n\n public FastInput(InputStream is) {\n this.is = is;\n }\n\n private int read() {\n while (bufLen == bufOffset) {\n bufOffset = 0;\n try {\n bufLen = is.read(buf);\n } catch (IOException e) {\n bufLen = -1;\n }\n if (bufLen == -1) {\n return -1;\n }\n }\n return buf[bufOffset++];\n }\n\n public void skipBlank() {\n while (next >= 0 && next <= 32) {\n next = read();\n }\n }\n\n public long readLong() {\n int sign = 1;\n\n skipBlank();\n if (next == '+' || next == '-') {\n sign = next == '+' ? 1 : -1;\n next = read();\n }\n\n long val = 0;\n if (sign == 1) {\n while (next >= '0' && next <= '9') {\n val = val * 10 + next - '0';\n next = read();\n }\n } else {\n while (next >= '0' && next <= '9') {\n val = val * 10 - next + '0';\n next = read();\n }\n }\n\n return val;\n }\n\n }\n\n static class LongModular implements ILongModular {\n final long m;\n\n public LongModular(long m) {\n this.m = m;\n }\n\n public long mul(long a, long b) {\n return b == 0 ? 0 : ((mul(a, b >> 1) << 1) % m + a * (b & 1)) % m;\n }\n\n }\n\n static class LongModularDanger implements ILongModular {\n final long m;\n\n public LongModularDanger(long m) {\n this.m = m;\n }\n\n public long mul(long a, long b) {\n return DigitUtils.mulMod(a, b, m);\n }\n\n }\n\n static class LongList implements Cloneable {\n private int size;\n private int cap;\n private long[] data;\n private static final long[] EMPTY = new long[0];\n\n public LongList(int cap) {\n this.cap = cap;\n if (cap == 0) {\n data = EMPTY;\n } else {\n data = new long[cap];\n }\n }\n\n public LongList(LongList list) {\n this.size = list.size;\n this.cap = list.cap;\n this.data = Arrays.copyOf(list.data, size);\n }\n\n public LongList() {\n this(0);\n }\n\n public void ensureSpace(int req) {\n if (req > cap) {\n while (cap < req) {\n cap = Math.max(cap + 10, 2 * cap);\n }\n data = Arrays.copyOf(data, cap);\n }\n }\n\n private void checkRange(int i) {\n if (i < 0 || i >= size) {\n throw new ArrayIndexOutOfBoundsException();\n }\n }\n\n public long get(int i) {\n checkRange(i);\n return data[i];\n }\n\n public void add(long x) {\n ensureSpace(size + 1);\n data[size++] = x;\n }\n\n public void addAll(long[] x, int offset, int len) {\n ensureSpace(size + len);\n System.arraycopy(x, offset, data, size, len);\n size += len;\n }\n\n public void addAll(LongList list) {\n addAll(list.data, 0, list.size);\n }\n\n public int size() {\n return size;\n }\n\n public long[] toArray() {\n return Arrays.copyOf(data, size);\n }\n\n public void clear() {\n size = 0;\n }\n\n public String toString() {\n return Arrays.toString(toArray());\n }\n\n public boolean equals(Object obj) {\n if (!(obj instanceof LongList)) {\n return false;\n }\n LongList other = (LongList) obj;\n return SequenceUtils.equal(data, 0, size - 1, other.data, 0, other.size - 1);\n }\n\n public int hashCode() {\n int h = 1;\n for (int i = 0; i < size; i++) {\n h = h * 31 + Long.hashCode(data[i]);\n }\n return h;\n }\n\n public LongList clone() {\n LongList ans = new LongList();\n ans.addAll(this);\n return ans;\n }\n\n }\n\n static interface LongEntryIterator {\n boolean hasNext();\n\n void next();\n\n long getEntryKey();\n\n long getEntryValue();\n\n }\n\n static interface ILongModular {\n long mul(long a, long b);\n\n static ILongModular getInstance(long mod) {\n //return new LongModularDanger(mod);\n return mod <= (1L << 54) ? new LongModularDanger(mod) : new LongModular(mod);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "16433148d80ae25f39d8a29ebe382a78", "src_uid": "c2dd6de750812d6213c770b3587d8fcb", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\n\npublic class E{\n class UnionFind{\n int[] p, size;\n int comps;\n int max;\n UnionFind(int n){\n p = new int[n];\n size = new int[n];\n reset();\n }\n UnionFind(UnionFind old){\n p = old.p.clone();\n size = old.size.clone();\n comps=old.comps;\n max=old.max;\n }\n void reset(){\n for(int i=0; isize[y]){\n p[y]=x;\n size[x]+=size[y];\n max=Math.max(max,size[x]);\n }else{\n p[x]=y;\n size[y]+=size[x];\n max=Math.max(max,size[y]);\n }\n comps--;\n }\n }\n static java.io.PrintStream out=System.out;\n int solve(int n, int k, char[][] map){\n UnionFind uf=new UnionFind(n*n);\n for(int i=0; i0 && map[i][j]=='.' && map[i-1][j]=='.')\n uf.union(i*n+j,(i-1)*n+j);\n if(j>0 && map[i][j]=='.' && map[i][j-1]=='.')\n uf.union(i*n+j,i*n+j-1);\n }\n }\n int max=0;\n for(int i=0; i<=n-k; i++)\n for(int j=0; j<=n-k; j++){\n UnionFind bak=new UnionFind(uf);\n for(int x=i; x=0 && map[x-1][y]=='.') || x>i) bak.union(x*n+y,(x-1)*n+y);\n if((y==j && y-1>=0 && map[x][y-1]=='.') || y>j) bak.union(x*n+y,x*n+y-1);\n if((x==i+k-1 && x+1 0) {\n if (pow % 2 == 1) {\n r = r * x % mod;\n }\n pow /= 2;\n x = x * x % mod;\n }\n return r;\n }\n\n public static void solve(Input in, PrintWriter out) throws IOException {\n int n = in.nextInt() + 1;\n int x = in.nextInt() - 1;\n for (int d = 2; d * d <= n; ++d) {\n if (n % d == 0) {\n out.println(-1);\n return;\n }\n }\n ArrayList pDivs = new ArrayList();\n int m = n - 1;\n for (int d = 2; d * d <= m; ++d) {\n if (m % d == 0) {\n pDivs.add(d);\n while (m % d == 0) {\n m /= d;\n }\n }\n }\n if (m > 1) {\n pDivs.add(m);\n }\n int b;\n if (n == 2) {\n b = 1;\n } else {\n loop: for (b = 2; ; ++b) {\n for (int p : pDivs) {\n if (modPow(b, (n - 1) / p, n) == 1) {\n continue loop;\n }\n }\n break;\n }\n }\n boolean[] coprime = new boolean[n - 1];\n Arrays.fill(coprime, true);\n for (int p : pDivs) {\n for (int i = 0; i < n - 1; i += p) {\n coprime[i] = false;\n }\n }\n long ans = -1;\n long cur = 1;\n for (int i = 0; i < (n == 2 ? 2 : n - 1); ++i) {\n if (coprime[i]) {\n if (cur <= x) {\n ans = Math.max(ans, cur + n * ((x - cur) / n));\n }\n }\n cur = cur * b % n;\n }\n out.println(ans);\n }\n\n public static void main(String[] args) throws IOException {\n PrintWriter out = new PrintWriter(System.out);\n solve(new Input(new BufferedReader(new InputStreamReader(System.in))), out);\n out.close();\n }\n\n static class Input {\n BufferedReader in;\n StringBuilder sb = new StringBuilder();\n\n public Input(BufferedReader in) {\n this.in = in;\n }\n\n public Input(String s) {\n this.in = new BufferedReader(new StringReader(s));\n }\n\n public String next() throws IOException {\n sb.setLength(0);\n while (true) {\n int c = in.read();\n if (c == -1) {\n return null;\n }\n if (\" \\n\\r\\t\".indexOf(c) == -1) {\n sb.append((char)c);\n break;\n }\n }\n while (true) {\n int c = in.read();\n if (c == -1 || \" \\n\\r\\t\".indexOf(c) != -1) {\n break;\n }\n sb.append((char)c);\n }\n return sb.toString();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ecdb75d83cf3cf8598c6f187a63bee9d", "src_uid": "29dda6a3f057e5bccdc076d7e492ac9a", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.*;\r\nimport java.util.*;\r\nimport static java.lang.System.*;\r\nimport static java.lang.Math.*;\r\npublic class Code\r\n{\r\n int P1,P2,T1,T2,H,S;\r\n void run() {\r\n int tc=1;\r\n StringBuilder sb=new StringBuilder();\r\n while(tc-->0) {\r\n P1=ni(); T1=ni();\r\n P2=ni(); T2=ni();\r\n H=ni(); S=ni();\r\n dp = new Integer[H+1][5001];\r\n int ans = T1<=T2 ? solve(P1, T1, P2, T2, H, S, 0, 0) : solve(P2, T2, P1, T1, H, S, 0, 0);\r\n sb.append(ans).append(\"\\n\");\r\n }\r\n out.println(sb);\r\n out.flush();\r\n out.close();\r\n }\r\n Integer dp[][];\r\n int solve(int p1, int t1, int p2, int t2, int h, int s, int c1, int c2) {\r\n if(h<=0) return 0;\r\n\r\n int diff=Math.abs(c1-c2);\r\n if(dp[h][diff]!=null) return dp[h][diff];\r\n // 5000*5000=2.5*10^7\r\n int res = 0;\r\n if(t1*2<=t2) {\r\n res = t1+solve(p1, T1, p2, t2-t1, h-(p1-s), s, 0, c2+1);\r\n }\r\n else if(t1>t2) {\r\n int x = t1+solve(p1, T1, p2, T2, h-(p1+p2-s), s, 0, 0);\r\n int y = t2+solve(p1, t1-t2, p2, T2, h-(p2-s), s, c1+1, 0);\r\n res = min(x,y);\r\n }\r\n else {\r\n int x = t1+solve(p1, T1, p2, t2-t1, h-(p1-s), s, 0, c2+1);\r\n int y = t2+solve(p1, T1, p2, T2, h-(p1+p2-s), s, 0, 0);\r\n // System.out.println(h+\" \"+x+\" \"+y);\r\n res = min(x,y);\r\n }\r\n\r\n return dp[h][diff] = res;\r\n\r\n }\r\n StringBuilder pr(String s, int t) {\r\n return new StringBuilder().append(\"Case #\").append(t).append(\": \").append(s).append(\"\\n\");\r\n }\r\n public static void main(String[] args)throws Exception {\r\n try { \r\n // new Thread(null, new Code()::run, \"1\", 1 << 26).start();\r\n new Thread(null, new Code(\"ONLINE_JUDGE\")::run, \"1\", 1 << 26).start();\r\n } catch(Exception e) {}\r\n }\r\n\r\n FastReader sc=null;PrintWriter out = null;\r\n public Code()throws Exception {\r\n sc = new FastReader(new FileInputStream(\"input.txt\"));\r\n out = new PrintWriter(new BufferedWriter(new FileWriter(\"output.txt\")));\r\n }\r\n public Code(String JUDGE) {\r\n sc = new FastReader(System.in);\r\n out = new PrintWriter(System.out); \r\n }\r\n \r\n String ns() { return sc.next(); }\r\n int ni() { return sc.nextInt(); }\r\n long nl() { return sc.nextLong(); }\r\n int[] ni(int n) {\r\n int a[]=new int[n];\r\n for(int i=0;i= numChars) {\r\n curChar = 0;\r\n try {\r\n numChars = stream.read(buf);\r\n } catch (IOException e) {\r\n throw new InputMismatchException();\r\n }\r\n if (numChars <= 0) return -1;\r\n }\r\n return buf[curChar++];\r\n }\r\n\r\n public int nextInt() {\r\n int c = read();\r\n while (isSpaceChar(c)) c = read();\r\n int sgn = 1;\r\n if (c == '-') {\r\n sgn = -1;\r\n c = read();\r\n }\r\n int res = 0;\r\n do {\r\n if (c < '0' || c > '9') throw new InputMismatchException();\r\n res *= 10;\r\n res += c - '0';\r\n c = read();\r\n }\r\n while (!isSpaceChar(c));\r\n return res * sgn;\r\n }\r\n \r\n public long nextLong() {\r\n int c = read();\r\n while (isSpaceChar(c)) c = read();\r\n int sgn = 1;\r\n if (c == '-') {\r\n sgn = -1;\r\n c = read();\r\n }\r\n long res = 0;\r\n do {\r\n if (c < '0' || c > '9') throw new InputMismatchException();\r\n res = res*1L*10;\r\n res += c - '0';\r\n c = read();\r\n }\r\n while (!isSpaceChar(c));\r\n return res *1L* sgn;\r\n }\r\n \r\n public String next() {\r\n int c = read();\r\n while (isSpaceChar(c)) c = read();\r\n StringBuilder res = new StringBuilder();\r\n do {\r\n res.appendCodePoint(c);\r\n c = read();\r\n } while (!isSpaceChar(c));\r\n return res.toString();\r\n }\r\n\r\n public boolean isSpaceChar(int c) {\r\n if (filter != null) return filter.isSpaceChar(c);\r\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\r\n }\r\n\r\n public interface SpaceCharFilter {\r\n public boolean isSpaceChar(int ch);\r\n\r\n }\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9d875d0568f99cd9cf224d1367dbe4d3", "src_uid": "ca9d48e48e69b931236907a9ac262433", "difficulty": 2400.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.io.*;\npublic class posperm{\npublic static int op[] = {0,1,2,4,6,8,9,16,17,18};\npublic static int dp[][][];\n//public static long bf[][];\npublic static long mod =0;\n/*public static void bf(int pos,int vec,int llevo,int tot,int prop){\nif(pos==0){\nbf[vec][prop]=(bf[vec][prop]+1)%mod;\nreturn;\n}\nfor(int n = 1;n<=tot;n++){\nint prop2 = prop;\nif(((1<=dp.length || b<0 || b>=dp.length) return 0;\nfor(int n= 0;n=dp.length || b<0 || b>=dp.length) return 0;\nint y = 0;\nfor(int n =0;n1)return 0;\nif(n==3)y =0;\nif(c.charAt(n)=='1')y++;\n}\n\nint d = c.indexOf(\"*\");\nif(d==-1)return dp[a][b][Integer.parseInt(c,2)];\nfor(int n = 0;n<2;n++)\ntal=(tal+sum2(a,b,c.substring(0,d)+n+c.substring(d+1),0))%mod;\nreturn tal%mod;\n}\npublic static void main(String args[]) throws IOException{\nBufferedReader lector = new BufferedReader(new InputStreamReader(System.in));\nString tmp = lector.readLine();\nint a = Integer.parseInt(tmp.substring(0,tmp.indexOf(\" \")));\nint b = Integer.parseInt(tmp.substring(tmp.indexOf(\" \")+1));\nmod = 1000000007;\nlong res = 0;\n//bf = new long[Math.max(a+2,4)][33];\ndp= new int[Math.max(a+2,4)][Math.max(a+2,4)][19];\ndp[1][0][1]=1;\ndp[2][0][9]=1;\ndp[2][2][6]=1;\ndp[3][0][9]=1;\ndp[3][0][8]=1;\ndp[3][2][6]=1;\ndp[3][2][17]=1;\ndp[3][2][4]=1;\ndp[3][2][18]=1;\nString rejoder[] = {\"00010\",\"10010\",\"01010\",\"00110\"};\nString joder[] ={\"00000\",\"10000\",\"01000\",\"00100\"};\nString joder1[] = {\"00001\",\"01001\",\"10001\"};\nString joder2[] = {\"00010\",\"10010\",\"00110\"};\nString joder3[] = {\"00000\",\"01000\",\"10000\"};\nString joder4[] = {\"00010\",\"10010\"};\nint nn = 4,mm=0;\nfor(long n = 4;nn[] adj = new ArrayList[n];\n\t\tint[] d = new int[n];\n\t\tfor(int i = 0; i < n; i++) adj[i] = new ArrayList();\n\t\tfor(int i = 0; i < m; i++) {\n\t\t\tint x = scan.nextInt()-1, y = scan.nextInt()-1;\n\t\t\tif(!adj[x].contains(y) && x != y){\n\t\t\t\tadj[x].add(y);\n\t\t\t\tadj[y].add(x);\n\t\t\t\td[x]++;\n\t\t\t\td[y]++;\n\t\t\t}\n\t\t}\n\t\tfor(int i = 0; i < n; i++)Collections.sort(adj[i], new Comparator(){@Override public int compare(Integer a, Integer b) {if(d[a]==d[b]) return a-b;return d[a]-d[b];}});\n\t\tboolean res = false;\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tint c = go(i, adj, n, new boolean[n], 0);\n\t\t\tif(c == n) res = true;\n\t\t}\n\t\tout.println(res?\"Yes\":\"No\");\n\t\tout.close();\n\t}\n\t\n\tstatic int go(int at, ArrayList[] adj, int n, boolean[] v, int c){\n\t\tv[at] = true;\n\t\tint res = 0;\n\t\tfor(int i : adj[at]) if(!v[i])res = Math.max(res, go(i, adj, n, v, c));\n\t\treturn res+1;\n\t}\n\n\tstatic class FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner() {\n\t\t\ttry\t{\n\t\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e){e.printStackTrace();}\n\t\t}\n\n\t\tpublic String next() {\n\t\t\tif (st.hasMoreTokens())\treturn st.nextToken();\n\t\t\ttry {st = new StringTokenizer(br.readLine());}\n\t\t\tcatch (Exception e) {e.printStackTrace();}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() {return Integer.parseInt(next());}\n\n\t\tpublic long nextLong() {return Long.parseLong(next());}\n\n\t\tpublic double nextDouble() {return Double.parseDouble(next());}\n\n\t\tpublic String nextLine() {\n\t\t\tString line = \"\";\n\t\t\ttry {line = br.readLine();} \n\t\t\tcatch (Exception e) {e.printStackTrace();}\n\t\t\treturn line;\n\t\t}\n\n\t\tpublic int[] nextIntArray(int n) {\n\t\t\tint[] a = new int[n];\n\t\t\tfor(int i = 0; i < n; i++) a[i] = nextInt();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic long[] nextLongArray(int n){\n\t\t\tlong[] a = new long[n];\n\t\t\tfor(int i = 0; i < n; i++) a[i] = nextLong();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic double[] nextDoubleArray(int n){\n\t\t\tdouble[] a = new double[n];\n\t\t\tfor(int i = 0; i < n; i++) a[i] = nextDouble();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic char[][] nextGrid(int n, int m){\n\t\t\tchar[][] grid = new char[n][m];\n\t\t\tfor(int i = 0; i < n; i++) grid[i] = next().toCharArray();\n\t\t\treturn grid;\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "14adec74ec0576b32f661288b3c2441a", "src_uid": "d023fc9b58268a36d7fb80deb338b09a", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n public static void main(String args[]) {new Main().run();}\r\n\r\n FastReader in = new FastReader();\r\n PrintWriter out = new PrintWriter(System.out);\r\n void run() {\r\n work();\r\n out.flush();\r\n }\r\n long mod=998244353;\r\n long gcd(long a,long b) {\r\n return a==0?b:gcd(b%a,a);\r\n }\r\n void work() {\r\n int n=ni(),k=ni();\r\n long[][] dp=new long[251][251];\r\n for(int j=1;j<=k;j++){\r\n dp[1][j]=1;\r\n }\r\n long[][] pow=new long[251][251*251];\r\n long[][] C=new long[251][251];\r\n for(int i=1;i<=250;i++){\r\n pow[i][0]=1;\r\n for(int j=1;j<251*251;j++){\r\n pow[i][j]=pow[i][j-1]*i%mod;\r\n }\r\n }\r\n for(int i=0;i<=250;i++){\r\n for(int j=0;j<=i;j++){\r\n if(i==0||j==0){\r\n C[i][j]=1;\r\n }else{\r\n C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;\r\n }\r\n }\r\n }\r\n for(int j=0;j<=k;j++){\r\n dp[0][j]=1;\r\n }\r\n for(int i=1;i<=n-1;i++){\r\n for(int j=1;j<=k;j++){\r\n dp[i][j]=dp[i][j-1];\r\n for(int p=1;p<=i;p++){\r\n dp[i][j]+=dp[i-p][j-1]*C[i][p]%mod*pow[k-j+1][p*(i-p)+(p-1)*p/2]%mod;\r\n }\r\n }\r\n }\r\n out.println(dp[n-1][k]);\r\n }\r\n\r\n private ArrayList[] ng(int n, int m) {\r\n ArrayList[] graph=(ArrayList[])new ArrayList[n];\r\n for(int i=0;i();\r\n }\r\n for(int i=1;i<=m;i++) {\r\n int s=in.nextInt()-1,e=in.nextInt()-1;\r\n graph[s].add(e);\r\n graph[e].add(s);\r\n }\r\n return graph;\r\n }\r\n\r\n private ArrayList[] ngw(int n, int m) {\r\n ArrayList[] graph=(ArrayList[])new ArrayList[n];\r\n for(int i=0;i();\r\n }\r\n for(int i=1;i<=m;i++) {\r\n long s=in.nextLong()-1,e=in.nextLong()-1,w=in.nextLong();\r\n graph[(int)s].add(new long[] {e,w});\r\n graph[(int)e].add(new long[] {s,w});\r\n }\r\n return graph;\r\n }\r\n\r\n private ArrayList[] ngwi(int n, int m) {\r\n ArrayList[] graph=(ArrayList[])new ArrayList[n];\r\n for(int i=0;i();\r\n }\r\n for(int i=1;i<=m;i++) {\r\n int s=ni()-1,e=ni()-1,w=ni();\r\n graph[s].add(new int[] {e,w});\r\n graph[e].add(new int[] {s,w});\r\n }\r\n return graph;\r\n }\r\n\r\n private int ni() {\r\n return in.nextInt();\r\n }\r\n\r\n private long nl() {\r\n return in.nextLong();\r\n }\r\n private double nd() {\r\n return in.nextDouble();\r\n }\r\n private String ns() {\r\n return in.next();\r\n }\r\n\r\n private long[] na(int n) {\r\n long[] A=new long[n];\r\n for(int i=0;i'9'){\r\n b=input.read();\r\n }\r\n while(b>='0'&&b<='9'){\r\n ret=ret*10+(b-'0');\r\n b=input.read();\r\n }\r\n return ret;\r\n }\r\n }catch (Exception e){\r\n e.printStackTrace();\r\n }\r\n return Long.parseLong(next());\r\n }\r\n\r\n public double nextDouble()\r\n {\r\n return Double.parseDouble(next());\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b4b4732721331b9d5cabb9048ae89bf5", "src_uid": "b2d7ac8e75cbdb828067aeafd803ac62", "difficulty": 2200.0} {"lang": "Java 6", "source_code": "import java.util.ArrayList;\nimport java.util.Scanner; \n\n public class Main { \n public int[][]stacks;\n public int[]levels;\n public int[]offset;\n public int[]d;\n public ArrayListmooves;\n \n public Main(){\n Scanner nera = new Scanner(System.in); \n byte n=nera.nextByte();\n d=new int[n];\n for(int i=0;i(); \n }\n \n public void moove(int src, int dest){\n //System.out.println((src+1)+\" \"+(dest+1));\n levels[src]--;\n stacks[dest][levels[dest]]=stacks[src][levels[src]];\n levels[dest]++;\n mooves.add((src+1)+\" \"+(dest+1));\n }\n \n public void solve(int src, int dest, boolean toReverse){ \n if(offset[src]==levels[src])\n return;\n \n int swap=3-src-dest;\n int base=d[stacks[src][offset[src]]];\n int thick=0;\n while(offset[src] 0) {\n res += getDp(pos - 1, have, 1) * getAll(have);\n res %= MOD;\n }\n //Add a new vector.\n res += getDp(pos - 1, have + 1, 1);\n res %= MOD;\n } else if (getBit(pos) == 1) {\n //Create a new vector.\n res += getDp(pos - 1, have + 1, 0);\n res %= MOD;\n //Add to one of the existing vectors.\n res += getDp(pos - 1, have, 0) * getAll(have);\n res %= MOD;\n }\n return dp[pos][have][less] = res;\n }\n\n long getAll(int have) {\n return ((1L << have) - 1 + MOD) % MOD;\n }\n\n int getBit(int pos) {\n return (k & (1L << pos)) == 0 ? 0 : 1;\n }\n}\n\nclass FastScanner {\n BufferedReader reader;\n StringTokenizer tokenizer;\n\n public FastScanner(InputStream inputStream) {\n reader = new BufferedReader(new InputStreamReader(inputStream));\n }\n\n public String nextToken() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n String line;\n try {\n line = reader.readLine();\n } catch (IOException e) {\n return null;\n }\n tokenizer = new StringTokenizer(line);\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n }\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c41c1ef0243f54542357be15e6699d96", "src_uid": "ead64d8e3134fa8f29881cb487e52f60", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.StringTokenizer;\n\npublic class _LiftLevel5E {\n\n\tstatic boolean[][] locked;\n\tstatic int[][] board;\n\tstatic int[][] solved;\n\tstatic int w, h;\n\tstatic ArrayList answer=new ArrayList<>();\n\t\n\tpublic static void main(String[] args) {\n\t\tFastScanner fs=new FastScanner();\n\t\th=fs.nextInt(); w=fs.nextInt();\n\t\tboard=new int[w][h];\n\t\tsolved=new int[w][h];\n\t\tlocked=new boolean[w][h];\n\t\tfor (int y=0; y=locked.length || y<0 || y>=locked[x].length) return false;\n\t\treturn !locked[x][y];\n\t}\n\t\n\t//moves x first then y\n\tstatic void naiveMoveToXFirst(int toMove, int targetX, int targetY) {\n\t\tPoint curPos=locationOf(toMove);\n\t\tint curX=curPos.x;\n\t\tint curY=curPos.y;\n\t\twhile (curXtargetX) {\n\t\t\tmoveLeft(curX, curY);\n\t\t\tcurX--;\n\t\t}\n\t\twhile (curYtargetY) {\n\t\t\tmoveUp(curX, curY);\n\t\t\tcurY--;\n\t\t}\n\t}\n\t\n\tstatic void moveLeft(int x, int y) {\n\t\tif (!movable(x, y) || !movable(x-1, y)) {\n\t\t\tthrow null;\n\t\t}\n\t\tif (movable(x-1, y+1) && movable(x, y+1)) {\n\t\t\tmove(x, y, x-1, y, x-1, y+1, x, y+1);\n\t\t\treturn;\n\t\t}\n\t\tif (movable(x-1, y-1) && movable(x-1, y-1)) {\n\t\t\tmove(x, y, x-1, y, x-1, y-1, x, y-1);\n\t\t\treturn;\n\t\t}\n\t\tthrow null;\n\t}\n\t\n\tstatic void moveRight(int x, int y) {\n\t\tif (!movable(x, y) || !movable(x+1, y)) {\n\t\t\tthrow null;\n\t\t}\n\t\tif (movable(x+1, y+1) && movable(x, y+1)) {\n\t\t\tmove(x, y, x+1, y, x+1, y+1, x, y+1);\n\t\t\treturn;\n\t\t}\n\t\tif (movable(x+1, y-1) && movable(x, y-1)) {\n\t\t\tmove(x, y, x+1, y, x+1, y-1, x, y-1);\n\t\t\treturn;\n\t\t}\n//\t\tSystem.out.println(\"Trying to move right on pos: \"+x+\" \"+y+\" but it is impossible\");\n//\t\tprint(locked);\n\t\tthrow null;\n\t}\n\t\n\tstatic void moveDown(int x, int y) {\n\t\tif (!movable(x, y) || !movable(x, y+1)) {\n\t\t\tthrow null;\n\t\t}\n\t\tif (movable(x-1, y+1) && movable(x-1, y)) {\n\t\t\tmove(x, y, x, y+1, x-1, y+1, x-1, y);\n\t\t\treturn;\n\t\t}\n\t\tif (movable(x+1, y+1) && movable(x+1, y)) {\n\t\t\tmove(x, y, x, y+1, x+1, y+1, x+1, y);\n\t\t\treturn;\n\t\t}\n\t\tthrow null;\n\t}\n\n\tstatic void moveUp(int x, int y) {\n\t\tif (!movable(x, y) || !movable(x, y-1)) {\n\t\t\tthrow null;\n\t\t}\n\t\tif (movable(x-1, y-1) && movable(x-1, y)) {\n\t\t\tmove(x, y, x, y-1, x-1, y-1, x-1, y);\n\t\t\treturn;\n\t\t}\n\t\tif (movable(x+1, y-1) && movable(x+1, y)) {\n\t\t\tmove(x, y, x, y-1, x+1, y-1, x+1, y);\n\t\t\treturn;\n\t\t}\n\t\tthrow null;\n\t}\n\t\n\tstatic void move(int ...input) {\n\t\tif (input.length%2!=0) throw null;\n\t\tint[] xs=new int[input.length/2], ys=new int[input.length/2];\n\t\tfor (int i=0; i{\n\t\tint d,g;\n\t\tbase(int dd,int gg){\n\t\t\td=dd;g=gg;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(base o) {\n\t\t\treturn d-o.d;\n\t\t}\n\t\t\n\t}\n\tstatic int inf=(int)1e9+7;\n\tstatic int[][]adj;\n\t\n\tstatic int V, s, t;static long res[][];\t\t\t//input\n\tstatic ArrayList[] adjList;\t//input\n\tstatic int[] ptr, dist;\n\t\n\tstatic long dinic()\t\t\t\t\t\t//O(V^2E)\n\t{\n\t\tlong mf = 0;\n\t\twhile(bfs())\n\t\t{\n\t\t\tptr = new int[V];\n\t\t\tlong f;\n\t\t\twhile((f = dfs(s, inf)) != 0)\n\t\t\t\tmf += f;\n\t\t}\n\t\treturn mf;\n\t}\n\t\n\t\n\tstatic boolean bfs()\n\t{\n\t\tdist = new int[V];\n\t\tArrays.fill(dist, -1);\n\t\tdist[s] = 0;\n\t\tQueue q = new LinkedList();\n\t\tq.add(s);\n\t\twhile(!q.isEmpty())\n\t\t{\n\t\t\tint u = q.remove();\n\t\t\tif(u == t)\n\t\t\t\treturn true;\n\t\t\tfor(int v: adjList[u])\n\t\t\t\tif(dist[v] == -1 && res[u][v] > 0)\n\t\t\t\t{\n\t\t\t\t\tdist[v] = dist[u] + 1;\n\t\t\t\t\tq.add(v);\n\t\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\t\n\tstatic long dfs(int u, long flow)\n\t{\n\t\tif(u == t)\n\t\t\treturn flow;\n\t\tfor(int i = ptr[u]; i < adjList[u].size(); i = ++ptr[u])\n\t\t{\n\t\t\tint v = adjList[u].get(i);\n\t\t\tif(dist[v] == dist[u] + 1 && res[u][v] > 0)\n\t\t\t{\n\t\t\t\tlong f = dfs(v, Math.min(flow, res[u][v]));\n\t\t\t\tif(f > 0)\n\t\t\t\t{\n\t\t\t\t\tres[u][v] -= f;\n\t\t\t\t\tres[v][u] += f;\n\t\t\t\t\treturn f;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn 0;\n\t\t\n\t}\n\tpublic static void main(String[] args) throws Exception{\n\t\tMScanner sc=new MScanner(System.in);\n\t\tPrintWriter pw=new PrintWriter(System.out);\n\t\tint n=sc.nextInt(),m=sc.nextInt();\n\t\tadj=new int[n][n];\n\t\tfor(int []i:adj)Arrays.fill(i, inf);\n\t\tfor(int i=0;i x[1]-y[1]);\n\t\t\n\t\tTreeSet[]planets=new TreeSet[n];\n\t\tfor(int i=0;i();\n\t\t}\n\t\tfor(int i=0;icurFuel)continue;\n\t\t\t\t\n\t\t\t\twhile(!planets[p].isEmpty() && curAtt>=planets[p].first().d) {\n\t\t\t\t\tmaxSoFar[p]=Math.max(maxSoFar[p], planets[p].pollFirst().g);\n\t\t\t\t}\n\t\t\t\tprofit=Math.max(profit, maxSoFar[p]);\n\t\t\t\t\n\t\t\t}\n\t\t\tmaxProfit[spaceShips[i][4]]=profit-curPrice;\n\t\t}\n\t\tlong ans=0;\n\t\t\n\t\tHashSetdep=new HashSet();\n\t\tint[][]depend=new int[k][2];\n\t\tfor(int i=0;i();\n\t\t\n\t\tt=V-1;\n\t\tHashMapids=new HashMap<>();\n\t\tint id=1;\n\t\t\n\t\tfor(int i=0;i=0) {\n\t\t\t\t\tint curID=ids.get(i);\n\t\t\t\t\tadjList[s].add(curID);\n\t\t\t\t\tadjList[curID].add(s);\n\t\t\t\t\tres[s][curID]=maxProfit[i];\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tint curID=ids.get(i);\n\t\t\t\t\tadjList[t].add(curID);\n\t\t\t\t\tadjList[curID].add(t);\n\t\t\t\t\tres[curID][t]=-maxProfit[i];\n\t\t\t\t}\n\t\t\t}\n\t\t\tans+=Math.max(0, maxProfit[i]);\n\t\t}\n\t\tpw.println(ans-dinic());\n\t\tpw.flush();\n\t}\n\tstatic class MScanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\t\tpublic MScanner(InputStream system) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(system));\n\t\t}\n \n\t\tpublic MScanner(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\t\tpublic int[] intArr(int n) throws IOException {\n\t int[]in=new int[n];for(int i=0;i= 0)\n if (restTime < minTime || minTime == -1)\n minTime = restTime;\n }\n }\n return minTime;\n }\n*/\n static boolean enabled(int from, int to){\n return r[from] < r[to] && c[from] != c[to];\n }\n\n\n\n static class box implements Comparable{\n\n int idx;\n ArrayList nexts = new ArrayList<>();\n\n public box(int idx) {\n this.idx = idx;\n boolean hasNext = false;\n for (int target = 1; target <= n; target++){\n if (enabled(idx, target)) {\n if (allBoxes[target] == null)\n allBoxes[target] = new box(target);\n nexts.add(allBoxes[target]);\n hasNext = true;\n }\n }\n if (hasNext)//!nexts.isEmpty())\n Collections.sort(nexts);\n }\n\n int eat(int time, int restCount){\n if (restCount <= 0)\n return time;\n\n int from = idx;\n int minTime = -1;\n \n for (box b: nexts) { \n int to = b.idx;\n int curTime = from == 0 ? Math.abs(s - to) : Math.abs(from - to);\n int restTime = b.eat( time + curTime, restCount - r[to]);\n if (restTime >= 0)\n if (restTime < minTime || minTime == -1)\n minTime = restTime; \n }\n return minTime;\n }\n\n @Override\n public int compareTo(box o) {\n return r[this.idx] - r[o.idx];\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "96d1a3cea30e1b466c3dc52413e63160", "src_uid": "a95e54a7e38cc0d61b39e4a01a6f8d3f", "difficulty": 2000.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.StringTokenizer;\n\npublic class Solver {\n\n StringTokenizer st;\n BufferedReader in;\n PrintWriter out;\n\n public static void main(String[] args) throws NumberFormatException, IOException {\n Solver solver = new Solver();\n solver.open();\n solver.solve();\n solver.close();\n }\n\n public void open() throws IOException {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n }\n\n public String nextToken() throws IOException {\n while (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(in.readLine());\n }\n return st.nextToken();\n }\n\n public int nextInt() throws NumberFormatException, IOException {\n return Integer.parseInt(nextToken());\n }\n\n public long nextLong() throws NumberFormatException, IOException {\n return Long.parseLong(nextToken());\n }\n\n public double nextDouble() throws NumberFormatException, IOException {\n return Double.parseDouble(nextToken());\n }\n\n enum State{\n IGNORE,ASSIGN,USE;\n \n public static State getState(int v){\n switch(v){\n case 0:\n return IGNORE;\n case 1:\n return ASSIGN;\n case 2:\n return USE;\n default:\n return null;\n }\n }\n }\n \n public void solve() throws NumberFormatException, IOException {\n int n = nextInt();\n int m = nextInt();\n \n State[] states = new State[n];\n List> child = new ArrayList>(n);\n List> rev = new ArrayList>(n);\n List whenUsed = new ArrayList();\n List whenAssi = new ArrayList();\n boolean[] forward = new boolean[n];\n boolean[] back = new boolean[n];\n \n for (int i=0;i());\n rev.add(new ArrayList());\n int vertex = nextInt();\n State state = State.getState(vertex);\n states[i] = state;\n if (state==State.USE){\n whenUsed.add(i);\n }else if(state==State.ASSIGN){\n whenAssi.add(i);\n }\n }\n\n for (int i=0;i0){\n List tmp = new ArrayList();\n for (int vert:whenAssi){\n if (!forward[vert]){\n forward[vert] = true;\n tmp.addAll(child.get(vert));\n }\n }\n whenAssi = tmp;\n }\n \n while (whenUsed.size()>0){\n List tmp = new ArrayList();\n for (int vert:whenUsed){\n if (!back[vert]){\n back[vert] = true;\n if (states[vert]!=State.ASSIGN){\n tmp.addAll(rev.get(vert));\n }\n }\n }\n whenUsed = tmp;\n }\n \n for (int i=0;i 0)\n {\n solveOne(in, out);\n }\n }\n\n private void solveOne(Scanner in, PrintWriter out)\n {\n int N = in.nextInt();\n int nums[] = CPUtils.readIntArray(N, in);\n\n int ans = Integer.MAX_VALUE;\n for (int i = 0; i < N; i++)\n {\n for (int l = 0; l < i; l++)\n {\n for (int r = i; r < N; r++)\n {\n int resL = 0, resR = 0;\n for (int ll = l; ll < i; ll++) resL ^= nums[ll];\n for (int rr = i; rr <= r; rr++) resR ^= nums[rr];\n if (resL > resR)\n {\n ans = Math.min(ans, r - l - 1);\n }\n }\n }\n }\n if (ans == Integer.MAX_VALUE)\n {\n out.println(-1);\n } else\n {\n out.println(ans);\n }\n\n }\n\n }\n\n static class CPUtils\n {\n public static int[] readIntArray(int size, Scanner in)\n {\n int[] array = new int[size];\n for (int i = 0; i < size; i++)\n {\n array[i] = in.nextInt();\n }\n return array;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e673dc38ef72a7a7ceb9b00c9dbfd0e1", "src_uid": "51ad613842de8eff6226c97812118b61", "difficulty": null} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.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 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 ThreePieces solver = new ThreePieces();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class ThreePieces {\n int[][][][][] dp = new int[201][10][10][100][3];\n int INF = (int) (1e9);\n ArrayList[][][] move = new ArrayList[10][10][3];\n int N;\n int[] moveR = new int[]{-2, -1, 1, 2};\n int[] moveC = new int[]{-2, -1, 1, 2};\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n N = in.nextInt();\n int[][] loc = new int[N * N][2];\n int[][] arr = new int[N][N];\n for (int i = 0; i < N; i++) {\n for (int j = 0; j < N; j++) {\n int a = in.nextInt() - 1;\n loc[a] = new int[]{i, j};\n arr[i][j] = a;\n move[i][j][0] = posKnight(i, j);\n move[i][j][1] = posBishop(i, j);\n move[i][j][2] = posRook(i, j);\n }\n }\n for (int i = 0; i <= 200; i++) {\n for (int j = 0; j < 10; j++) {\n for (int k = 0; k < 10; k++) {\n for (int d = 0; d < 100; d++) {\n for (int z = 0; z < 3; z++) {\n dp[i][j][k][d][z] = INF;\n }\n }\n }\n }\n }\n Arrays.fill(dp[0][loc[0][0]][loc[0][1]][0], 0);\n for (int i = 0; i < 200; i++) {\n for (int j = 0; j < N; j++) {\n for (int k = 0; k < N; k++) {\n for (int d = 0; d < N * N; d++) {\n for (int m = 0; m < 3; m++) {\n for (int next = 0; next < 3; next++) {\n for (int[] c : move[j][k][next]) {\n if (arr[c[0]][c[1]] == d + 1) {\n dp[i + 1][c[0]][c[1]][d + 1][next] = Math.min(dp[i + 1][c[0]][c[1]][d + 1][next], dp[i][j][k][d][m] + (m == next ? 0 : 1));\n } else {\n dp[i + 1][c[0]][c[1]][d][next] = Math.min(dp[i + 1][c[0]][c[1]][d][next], dp[i][j][k][d][m] + (m == next ? 0 : 1));\n }\n }\n }\n }\n }\n }\n }\n }\n int resT = INF;\n int resP = INF;\n for (int i = 2; i <= 200; i++) {\n for (int v : dp[i][loc[N * N - 1][0]][loc[N * N - 1][1]][N * N - 1]) {\n if (resT + resP >= v + i) {\n if (resT + resP == v + i) {\n if (v < resP) {\n resT = i;\n resP = v;\n }\n } else {\n resT = i;\n resP = v;\n }\n }\n }\n }\n out.println((resT + resP) + \" \" + resP);\n }\n\n boolean isValid(int r, int c) {\n return r >= 0 && r < N && c >= 0 && c < N;\n }\n\n ArrayList posKnight(int r, int c) {\n ArrayList pos = new ArrayList<>();\n for (int rM : moveR) {\n for (int cM : moveC) {\n if (Math.abs(rM) != Math.abs(cM)) {\n int newR = r + rM;\n int newC = c + cM;\n if (isValid(newR, newC)) {\n pos.add(new int[]{newR, newC});\n }\n }\n }\n }\n return pos;\n }\n\n ArrayList posRook(int r, int c) {\n ArrayList pos = new ArrayList<>();\n for (int i = 0; i < N; i++) {\n pos.add(new int[]{r, i});\n pos.add(new int[]{i, c});\n }\n return pos;\n }\n\n ArrayList posBishop(int r, int c) {\n ArrayList pos = new ArrayList<>();\n for (int k = 1; k < N; k++) {\n int[] mR = new int[]{k, -k, k, -k};\n int[] mC = new int[]{k, k, -k, -k};\n for (int i = 0; i < 4; i++) {\n int newR = r + mR[i];\n int newC = c + mC[i];\n if (isValid(newR, newC)) {\n pos.add(new int[]{newR, newC});\n }\n }\n }\n return pos;\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "326baf8f5df1b069c9ad6776875c5228", "src_uid": "5fe44b6cd804e0766a0e993eca1846cd", "difficulty": 2200.0} {"lang": "Java 6", "source_code": "//package round167;\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\tint[][] BURIED = {\n\t\t\t{0, 2},\n\t\t\t{1, 1},\n\t\t\t{2, 1},\n\t\t\t{1, 2},\n\t\t\t{2, 2},\n\t\t\t{0, 4},\n\t\t\t{1, 2},\n\t\t\t{2, 4},\n\t\t\t{0, 8},\n\t\t\t{1, 12},\n\t\t\t{2, 1},\n\t\t\t{0, 17},\n\t\t\t{2, 1},\n\t\t\t{1, 23},\n\t\t\t{2, 4},\n\t\t\t{0, 35},\n\t\t\t{2, 1},\n\t\t\t{1, 53},\n\t\t\t{2, 5},\n\t\t\t{0, 76},\n\t\t\t{2, 5},\n\t\t\t{1, 103},\n\t\t\t{2, 19},\n\t\t\t{0, 155},\n\t\t\t{2, 7},\n\t\t\t{1, 236},\n\t\t\t{2, 25},\n\t\t\t{0, 341},\n\t\t\t{2, 23},\n\t\t\t{1, 463},\n\t\t\t{2, 86},\n\t\t\t{0, 697},\n\t\t\t{2, 32},\n\t\t\t{1, 1060},\n\t\t\t{2, 115},\n\t\t\t{0, 1532},\n\t\t\t{2, 106},\n\t\t\t{1, 2081},\n\t\t\t{2, 389},\n\t\t\t{0, 3136},\n\t\t\t{2, 145},\n\t\t\t{1, 4769},\n\t\t\t{2, 518},\n\t\t\t{0, 6892},\n\t\t\t{2, 479},\n\t\t\t{1, 9364},\n\t\t\t{2, 1751},\n\t\t\t{0, 14110},\n\t\t\t{2, 655},\n\t\t\t{1, 21458},\n\t\t\t{2, 2333},\n\t\t\t{0, 31012},\n\t\t\t{2, 2158},\n\t\t\t{1, 42137},\n\t\t\t{2, 7880},\n\t\t\t{0, 63493},\n\t\t\t{2, 2950},\n\t\t\t{1, 96560},\n\t\t\t{2, 10499},\n\t\t\t{0, 139552},\n\t\t\t{2, 9713},\n\t\t\t{1, 189616},\n\t\t\t{2, 35461},\n\t\t\t{0, 285716},\n\t\t\t{2, 13277},\n\t\t\t{1, 434518},\n\t\t\t{2, 47248},\n\t\t\t{0, 627983},\n\t\t\t{2, 43709},\n\t\t\t{1, 853270},\n\t\t\t{2, 159577},\n\t\t\t{0, 1285721},\n\t\t\t{2, 59747},\n\t\t\t{1, 1955329},\n\t\t\t{2, 212618},\n\t\t\t{0, 2825923},\n\t\t\t{2, 196691},\n\t\t\t{1, 3839713},\n\t\t\t{2, 718099},\n\t\t\t{0, 5785742},\n\t\t\t{2, 268864},\n\t\t\t{1, 8798978},\n\t\t\t{2, 956783},\n\t\t\t{0, 12716653},\n\t\t\t{2, 885110},\n\t\t\t{1, 17278708},\n\t\t\t{2, 3231446},\n\t\t\t{0, 26035837},\n\t\t\t{2, 1209890},\n\t\t\t{1, 39595399},\n\t\t\t{2, 4305526},\n\t\t\t{0, 57224936},\n\t\t\t{2, 3982997},\n\t\t\t{1, 77754184},\n\t\t\t{2, 14541509},\n\t\t\t{0, 117161266},\n\t\t\t{2, 5444506},\n\t\t\t{1, 178179293},\n\t\t\t{2, 19374869},\n\t\t\t{0, 257512210},\n\t\t\t{2, 17923489}\n\t};\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni();\n\t\tlong p = ni();\n\t\tint mod = 1000000007;\n\t\tlong[] ct = new long[3];\n\t\tlong pp = p;\n\t\tfor(int[] b : BURIED){\n\t\t\tct[b[0]] += pp*(pp-1)/2;\n\t\t\tpp -= b[1];\n\t\t\tif(pp <= 0)break;\n\t\t\tct[b[0]] -= pp*(pp-1)/2;\n\t\t}\n\t\tfor(int i = 0;i < 3;i++){\n\t\t\tct[i] %= mod;\n\t\t}\n\t\t\n\t\tlong[][] dp = new long[n+1][4];\n\t\tdp[0][0] = 1;\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tfor(int j = 0;j < 4;j++){\n\t\t\t\tfor(int k = 0;k < 3;k++){\n\t\t\t\t\tdp[i+1][j^k] += dp[i][j]*ct[k]%mod;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor(int j = 0;j < 4;j++){\n\t\t\t\tdp[i+1][j] %= mod;\n\t\t\t}\n\t\t}\n\t\tout.println((dp[n][1]+dp[n][2]+dp[n][3])%mod);\n\t}\n\t\n\tpublic static long invl(long a, long mod)\n\t{\n\t\tlong b = mod;\n\t\tlong p = 1, q = 0;\n\t\twhile(b > 0){\n\t\t\tlong c = a / b;\n\t\t\tlong d;\n\t\t\td = a; a = b; b = d % b;\n\t\t\td = p; p = q; q = d - c * q;\n\t\t}\n\t\treturn p < 0 ? p + mod : p;\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception { new E().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tprivate int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate 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 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", "compilation_error": false, "code_uid": "8ead0ce0d0d4969f6cb97662543911f0", "src_uid": "c03b6379e9d186874ac3d97c6968fbd0", "difficulty": 2600.0} {"lang": "Java 6", "source_code": "import java.io.PrintWriter;\nimport java.sql.Time;\nimport java.util.Scanner;\nimport java.util.Timer;\n\n\npublic class problem4_2 {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner in = new Scanner(System.in);\n\t\t//Timer TT = new Timer();\n\t\t//TT.purge();\n\t\t//System.out.println(TT.toString());\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint R = in.nextInt();\n\t\tout.print(Hexagon(R));\n\t\tout.close();\n\t}\n\t\n public static long Hexagon(long R){\n\t long Count = 0;\n\t long l = 0;\n\t long k = R+1;\n\t double x = 0.25;\n\t double y = 3*(1.5 + k)*(1.5 + k);\n\t while (k>=0 || (x+y<=R*R && k==0) ){\n\t\t if(x+y>R*R) {\n\t\t\t k--;\n\t\t\t y = 3*(1.5+0.5*l+k)*(1.5+0.5*l+k);\n\t\t }\n\t\t else{\n\t\t Count+=k+1; l++;\n\t\t x = (0.5+1.5*l)*(0.5+1.5*l);\n\t\t y = 3*(1.5+0.5*l+k)*(1.5+0.5*l+k);\n\t \n\t\t }\n\t }\n\t return Count*6+1;\n }\n \n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f215430eb1815a176f1413d22c80b34f", "src_uid": "6787c7631716ce3dff3f9a5e1c51ff13", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\n/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n\n/**\n *\n * @author Andy Phan\n */\npublic class m {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n \n System.out.println((((in.nextLong()%360+360+44)%360)%359)/90);\n \n out.close();\n }\n \n static class FS {\n\n BufferedReader in;\n StringTokenizer token;\n \n public FS(InputStream str) {\n in = new BufferedReader(new InputStreamReader(str));\n }\n \n public String next() {\n if (token == null || !token.hasMoreElements()) {\n try {\n token = new StringTokenizer(in.readLine());\n } catch (IOException ex) {\n }\n return next();\n }\n return token.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "485e7f47a8eba5874b3b2174435683e2", "src_uid": "509db9cb6156b692557ba874a09f150e", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import static java.util.Arrays.*;\n\nimport java.math.*;\n\npublic class E {\n\n\tpublic Object solve () {\n\t\tint N = sc.nextInt() - 1, S = sc.nextInt(), R = sc.nextInt();\n\n\t\tif (N == 0)\n\t\t\treturn exit(1);\n\t\tif (R == 0)\n\t\t\tif (S == 0)\n\t\t\t\treturn exit(modInv(N+1));\n\t\t\telse\n\t\t\t\treturn 0;\n\n\t\tlong [][] C = modBin(N, N);\n\n\t\tlong P = 0;\n\t\tfor (int b = S; b >= R; --b) {\n\t\t\tif (b * N < S - b)\n\t\t\t\tbreak;\n\n\t\t\tlong [][] F = new long [N+1][S+1]; fill(F[0], 1);\n\t\t\tfor (int k = 1; k <= N; ++k) {\n\t\t\t\tF[k][0] = 1;\n\t\t\t\tfor (int x = 1; x <= S; ++x) {\n\t\t\t\t\tF[k][x] = (F[k][x-1] + F[k-1][x]) % MOD;\n\t\t\t\t\tif (x >= b)\n\t\t\t\t\t\tF[k][x] = (F[k][x] + MOD - F[k-1][x-b]) % MOD;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (int j = 0; j <= N; ++j) {\n\t\t\t\tint T = S - b * (j+1);\n\t\t\t\tif (T >= 0) {\n\t\t\t\t\tlong D = F[N-j][T];\n\t\t\t\t\tif (T > 0)\n\t\t\t\t\t\tD = (D + MOD - F[N-j][T-1]) % MOD;\n\t\t\t\t\tlong Z = (C[N][j] * D) % MOD;\n\t\t\t\t\tP = (P + Z * modInv(j+1)) % MOD;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tlong Q = 0;\n\t\tlong [][] F = new long [N+1][S+1]; fill(F[0], 1);\n\t\tfor (int k = 1; k <= N; ++k) {\n\t\t\tF[k][0] = 1;\n\t\t\tfor (int x = 1; x <= S; ++x)\n\t\t\t\tF[k][x] = (F[k][x-1] + F[k-1][x]) % MOD;\n\t\t}\n\t\tQ = F[N][S-R];\n\n\t\tlong res = (P * modInv(Q)) % MOD;\n\t\treturn exit(res);\n\t}\n\n\tprivate static final boolean ONE_TEST_CASE = true;\n\n\tprivate static void init () {\n\t}\n\n\tprivate static final int MOD = 998244353;\n\tprivate static long mod (long x) { return mod(x, MOD); }\n\tprivate static long mod (long x, long mod) { return ((x % mod) + mod) % mod; }\n\tprivate static long [][] modBin (int N, int K) {\n\t\tlong [][] res = new long [N+1][K+1];\n\t\tfor (int n = 0; n <= N; ++n) {\n\t\t\tres[n][0] = 1;\n\t\t\tfor (int k = 1; k <= K && k <= n; ++k)\n\t\t\t\tres[n][k] = mod(res[n-1][k] + res[n-1][k-1]);\n\t\t}\n\t\treturn res;\n\t}\n\tprivate static long modInv(long x) { return modInv(x, MOD); }\n\tprivate static long modInv(long x, int mod) { return BigInteger.valueOf(x).modInverse(BigInteger.valueOf(mod)).longValue(); }\n\t//////////////////////////////////////////////////////////////////////////////////// OFF\n\tprivate static IOUtils.MyScanner sc = new IOUtils.MyScanner();\n\tprivate static Object print (Object o, Object ... A) { IOUtils.print(o, A); return null; }\n\tprivate static Object exit (Object o, Object ... A) { print(o, A); IOUtils.exit(); return null; }\n\tprivate static class IOUtils {\n\t\tpublic static class MyScanner {\n\t\t\tpublic String next () { newLine(); return line[index++]; }\n\t\t\tpublic int nextInt () { return Integer.parseInt(next()); }\n\t\t\t//////////////////////////////////////////////\n\t\t\tprivate boolean eol () { return index == line.length; }\n\t\t\tprivate String readLine () {\n\t\t\t\ttry {\n\t\t\t\t\treturn r.readLine();\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\tthrow new Error (e);\n\t\t\t\t}\n\t\t\t}\n\t\t\tprivate final java.io.BufferedReader r;\n\t\t\tprivate MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }\n\t\t\tprivate MyScanner (java.io.BufferedReader r) {\n\t\t\t\ttry {\n\t\t\t\t\tthis.r = r;\n\t\t\t\t\twhile (!r.ready())\n\t\t\t\t\t\tThread.sleep(1);\n\t\t\t\t\tstart();\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\tthrow new Error(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\tprivate String [] line;\n\t\t\tprivate int index;\n\t\t\tprivate void newLine () {\n\t\t\t\tif (line == null || eol()) {\n\t\t\t\t\tline = split(readLine());\n\t\t\t\t\tindex = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tprivate String [] split (String s) { return s.length() > 0 ? s.split(\" \") : new String [0]; }\n\t\t}\n\t\tprivate static String build (Object o, Object ... A) { return buildDelim(\" \", o, A); }\n\t\tprivate static String buildDelim (String delim, Object o, Object ... A) {\n\t\t\tStringBuilder b = new StringBuilder();\n\t\t\tappend(b, o, delim);\n\t\t\tfor (Object p : A)\n\t\t\t\tappend(b, p, delim);\n\t\t\treturn b.substring(delim.length());\n\t\t}\n\t\t//////////////////////////////////////////////////////////////////////////////////\n\t\tprivate static final java.text.DecimalFormat formatter = new java.text.DecimalFormat(\"#.#########\");\n\t\tprivate static void start () { if (t == 0) t = millis(); }\n\t\tprivate static void append (java.util.function.Consumer f, java.util.function.Consumer g, final Object o) {\n\t\t\tif (o.getClass().isArray()) {\n\t\t\t\tint len = java.lang.reflect.Array.getLength(o);\n\t\t\t\tfor (int i = 0; i < len; ++i)\n\t\t\t\t\tf.accept(java.lang.reflect.Array.get(o, i));\n\t\t\t}\n\t\t\telse if (o instanceof Iterable)\n\t\t\t\t((Iterable)o).forEach(f::accept);\n\t\t\telse\n\t\t\t\tg.accept(o instanceof Double ? formatter.format(o) : o);\n\t\t}\n\t\tprivate static void append (final StringBuilder b, Object o, final String delim) {\n\t\t\tappend(x -> { append(b, x, delim); }, x -> b.append(delim).append(x), o);\n\t\t}\n\t\tprivate static java.io.PrintWriter pw = new java.io.PrintWriter(System.out);\n\t\tprivate static void print (Object o, Object ... A) {\n\t\t\tpw.println(build(o, A));\n\t\t\tif (DEBUG)\n\t\t\t\tpw.flush();\n\t\t}\n\t\tprivate static void err (Object o, Object ... A) { System.err.println(build(o, A)); }\n\t\tprivate static boolean DEBUG;\n\t\tprivate static void write (Object o) {\n\t\t\terr(o, '(', time(), ')');\n\t\t\tif (!DEBUG)\n\t\t\t\tpw.println(o);\n\t\t}\n\t\tprivate static void exit () {\n\t\t\tIOUtils.pw.close();\n\t\t\tSystem.out.flush();\n\t\t\terr(\"------------------\");\n\t\t\terr(time());\n\t\t\tSystem.exit(0);\n\t\t}\n\t\tprivate static long t;\n\t\tprivate static long millis () { return System.currentTimeMillis(); }\n\t\tprivate static String time () { return \"Time: \" + (millis() - t) / 1000.0; }\n\t\tprivate static void run (int N) {\n\t\t\ttry { DEBUG = System.getProperties().containsKey(\"DEBUG\"); }\n\t\t\tcatch (Throwable t) {}\n\n\t\t\tfor (int n = 1; n <= N; ++n) {\n\t\t\t\tObject res = new E().solve();\n\t\t\t\tif (res != null)\n\t\t\t\t\twrite(\"Case #\" + n + \": \" + build(res));\n\t\t\t}\n\t\t\texit();\n\t\t}\n\t}\n\t////////////////////////////////////////////////////////////////////////////////////\n\tpublic static void main (String[] args) {\n\t\tinit();\n\t\tint N = ONE_TEST_CASE ? 1 : sc.nextInt();\n\t\tIOUtils.run(N);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c582d899dae16342450f8c25d090418c", "src_uid": "609195ef4a970c62a8210dafe118580e", "difficulty": 2500.0} {"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.ArrayList;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\npublic class F {\n\n\tstatic String[] rank = new String[] {\"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"T\", \"J\", \"Q\", \"K\", \"A\"};\n\tstatic String[] suit = new String[] {\"C\", \"D\", \"H\", \"S\"};\n\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\n\t\tint n = sc.nextInt(), m = sc.nextInt();\n\t\tTreeSet cards = new TreeSet();\n\t\tfor(String r: rank)\n\t\t\tfor(String s: suit)\n\t\t\t\tcards.add(r + s);\n\t\tString[][] grid = new String[n][m];\n\t\tint[] x = {-1, -1}, y = {-1, -1};\n\t\tfor(int i = 0; i < n; ++i)\n\t\t\tfor(int j = 0; j < m; ++j)\n\t\t\t{\n\t\t\t\tString c = grid[i][j] = sc.next();\n\t\t\t\tcards.remove(c);\n\t\t\t\tif(c.charAt(0) == 'J')\n\t\t\t\t{\n\t\t\t\t\tx[c.charAt(1) - '1'] = i;\n\t\t\t\t\ty[c.charAt(1) - '1'] = j;\n\t\t\t\t}\n\t\t\t}\n\t\tStringBuilder sb = new StringBuilder();\n\t\tint[][] ans = null;\n\t\tif(x[0] != -1 || x[1] != -1)\n\t\t\tmain:for(String c1: cards)\n\t\t\t\tfor(String c2: cards)\n\t\t\t\t\tif(x[0] == -1 || x[1] == -1 || !c1.equals(c2))\n\t\t\t\t\t{\n\t\t\t\t\t\tif(x[0] != -1)\n\t\t\t\t\t\t\tgrid[x[0]][y[0]] = c1;\n\t\t\t\t\t\tif(x[1] != -1)\n\t\t\t\t\t\t\tgrid[x[1]][y[1]] = c2;\n\t\t\t\t\t\tans = find(grid);\n\t\t\t\t\t\tif(ans != null)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tsb.append(\"Solution exists.\\n\");\n\t\t\t\t\t\t\tif(x[0] != -1 && x[1] != -1)\n\t\t\t\t\t\t\t\tsb.append(\"Replace J1 with \" + c1 + \" and J2 with \" + c2 + \".\");\n\t\t\t\t\t\t\telse if(x[0] == -1)\n\t\t\t\t\t\t\t\tsb.append(\"Replace J2 with \" + c2 + \".\");\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\tsb.append(\"Replace J1 with \" + c1 + \".\");\n\t\t\t\t\t\t\tsb.append(\"\\n\");\n\t\t\t\t\t\t\tbreak main;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t}\n\t\tif(ans == null)\n\t\t\tans = find(grid);\n\t\tif(ans != null)\n\t\t{\n\t\t\tif(sb.length() == 0)\n\t\t\t\tsb.append(\"Solution exists.\\nThere are no jokers.\\n\");\n\n\t\t\tsb.append(\"Put the first square to (\" + ans[0][0] + \", \" + ans[0][1] + \").\\n\");\n\t\t\tsb.append(\"Put the second square to (\" + ans[1][0] + \", \" + ans[1][1] + \").\\n\");\n\t\t}\n\t\tif(sb.length() == 0)\n\t\t\tsb.append(\"No solution.\\n\");\n\t\tout.print(sb);\n\t\tout.close();\n\t}\n\n\tstatic int[][] find(String[][] grid)\n\t{\n\t\tint n = grid.length, m = grid[0].length;\n\t\tArrayList x = new ArrayList<>(), y = new ArrayList<>();\n\t\tfor(int i = 0; i + 3 <= n; ++i)\n\t\t\tfor(int j = 0; j + 3 <= m; ++j)\n\t\t\t{\n\t\t\t\tTreeSet r = new TreeSet<>();\n\t\t\t\tTreeSet s = new TreeSet<>();\n\t\t\t\tfor(int k1 = i; k1 < i + 3; ++k1)\n\t\t\t\t\tfor(int k2 = j; k2 < j + 3; ++k2)\n\t\t\t\t\t{\n\t\t\t\t\t\tr.add(grid[k1][k2].charAt(0));\n\t\t\t\t\t\ts.add(grid[k1][k2].charAt(1));\n\t\t\t\t\t}\n\t\t\t\tif(r.size() == 9 || s.size() == 1)\n\t\t\t\t{\n\t\t\t\t\tx.add(i);\n\t\t\t\t\ty.add(j);\n\t\t\t\t}\n\t\t\t}\n\t\tfor(int i = 0; i < x.size(); ++i)\n\t\t\tfor(int j = 0; j < x.size(); ++j)\n\t\t\t\tif(x.get(i) + 3 <= x.get(j) || y.get(i) + 3 <= y.get(j))\n\t\t\t\t\treturn new int[][] {new int[]{x.get(i) + 1, y.get(i) + 1}, new int[]{x.get(j) + 1, y.get(j) + 1}};\n\t\t\t\t\treturn null;\n\t}\t\n\n\tstatic class Scanner \n\t{\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s){\tbr = new BufferedReader(new InputStreamReader(s));}\n\n\t\tpublic String next() throws IOException \n\t\t{\n\t\t\twhile (st == null || !st.hasMoreTokens()) \n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {return Integer.parseInt(next());}\n\n\t\tpublic long nextLong() throws IOException {return Long.parseLong(next());}\n\n\t\tpublic String nextLine() throws IOException {return br.readLine();}\n\n\t\tpublic double nextDouble() throws IOException { return Double.parseDouble(next()); }\n\n\t\tpublic boolean ready() throws IOException {return br.ready();}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "129e7ef68b9d61a29aca8461d608de43", "src_uid": "b3f29d9c27cbfeadb96b6ac9ffd6bc8f", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import com.sun.xml.internal.bind.v2.model.core.ID;\n\nimport java.io.*;\nimport java.lang.reflect.Array;\nimport java.math.*;\nimport java.text.DecimalFormat;\nimport java.util.*;\n\n\n\n\npublic class Main {\n private static int [] inv;\n private static int [] A;\n private static int n;\n private static HashMap HM ;\n private static HashMap > Sol = new HashMap<>();\n\n private static int mul(int a,int b,int m) {\n long ab = a*(long)b;\n ab %= m;\n if (ab < 0) ab += m;\n return (int) ab;\n }\n\n private static void init(int a,int p){\n inv = new int[p];\n inv[1] = 1;\n for (int i = 2;i < p;i++)\n inv[i] = mul(-(p/i),inv[p%i],p);\n\n\n A = new int[p];\n for (int i = 0,q = 1;i < p;i++) {\n A[i] = q;\n q = mul(a,q,p);\n }\n\n n = (int)(Math.sqrt(p + 0.0) + 1);\n n = Math.min(n,p-1);\n int an = A[n];\n HM = new HashMap<>();\n for (int i = 1,q = an;i <= n;i++) {\n if (!HM.containsKey(q)) HM.put(q,i);\n q = mul(q,an,p);\n }\n }\n\n\n\n public static void main(String[] args) throws Exception{\n IO io = new IO(null,null);\n int a = io.getNextInt(),b = io.getNextInt(),p = io.getNextInt();\n long x = io.getNextLong();\n init(a,p);\n\n long ans = 0;\n for (int n0 = 0,q = 1;n0 < p - 1 && n0 <= x;n0++) {\n int y = mul(inv[q],b,p);\n y = n0 - y;\n if (y < 0) y += p;\n // k*(p-1) + n0 <= x\n // k <= (x-n0)/p\n long lim = (x-n0)/(p - 1);\n// System.err.println(n0 + \". \" + (y*(p-1L) + n0) + \" q = \" + q + \" y = \" + y + \" lim = \" + lim);\n if (y <= lim)\n ans += (lim - y)/p + 1;\n\n q = mul(q,a,p);\n }\n io.println(ans);\n\n io.close();\n }\n}\n\n\n\nclass IO{\n private BufferedReader br;\n private StringTokenizer st;\n private PrintWriter writer;\n private String inputFile,outputFile;\n\n public boolean hasMore() throws IOException{\n if(st != null && st.hasMoreTokens()) return true;\n if(br != null && br.ready()) return true;\n return false;\n }\n public String getNext() throws FileNotFoundException, IOException{\n while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n public String getNextLine() throws FileNotFoundException, IOException{\n return br.readLine().trim();\n }\n\n public int getNextInt() throws FileNotFoundException, IOException{\n return Integer.parseInt(getNext());\n }\n public long getNextLong() throws FileNotFoundException, IOException{\n return Long.parseLong(getNext());\n }\n\n public void print(double x,int num_digits) throws IOException{\n writer.printf(\"%.\" + num_digits + \"f\" ,x);\n }\n public void println(double x,int num_digits) throws IOException{\n writer.printf(\"%.\" + num_digits + \"f\\n\" ,x);\n }\n public void print(Object o) throws IOException{\n writer.print(o.toString());\n }\n\n public void println(Object o) throws IOException{\n writer.println(o.toString());\n }\n public IO(String x,String y) throws FileNotFoundException, IOException{\n inputFile = x;\n outputFile = y;\n if(x != null) br = new BufferedReader(new FileReader(inputFile));\n else br = new BufferedReader(new InputStreamReader(System.in));\n if(y != null) writer = new PrintWriter(new BufferedWriter(new FileWriter(outputFile)));\n else writer = new PrintWriter(new OutputStreamWriter(System.out));\n }\n\n protected void close() throws IOException{\n br.close();\n writer.close();\n }\n public void outputArr(Object [] A) throws IOException{\n int L = A.length;\n for (int i = 0;i < L;i++) {\n if(i > 0) writer.print(\" \");\n writer.print(A[i]);\n }\n writer.print(\"\\n\");\n }\n}\n\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e8fcce3824a9eaa6639d47efccb20f56", "src_uid": "4b9f470e5889da29affae6376f6c9f6a", "difficulty": 2100.0} {"lang": "Java 11", "source_code": "import java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws IOException {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n String[] strings = new String[]{\"buffy\", \"the\", \"vampire\", \"slayer\"};\r\n String in = br.readLine();\r\n for (String s : strings) {\r\n if (s.length() == in.length()) {\r\n for (int i = 0; i < s.length(); i++) {\r\n System.out.print((char) ((in.charAt(i) + s.charAt(i) - 'a' - 'a') % (26) + 'a'));\r\n }\r\n }\r\n }\r\n\r\n\r\n br.close();\r\n }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3997b83de81cbf6f8300d4d1f390f36e", "src_uid": "56ec50526a3843fe3784d395850f45ae", "difficulty": -1.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\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 TaskB solver = new TaskB();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskB {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int n = in.readInt(), res = 0;\n for (char c : Integer.toHexString(n).toUpperCase().toCharArray()) {\n res += trans(c);\n }\n out.printLine(res);\n }\n\n private int trans(char c) {\n if (c == '0') return 1;\n if (c == '1') return 0;\n if (c == '2') return 0;\n if (c == '3') return 0;\n if (c == '4') return 1;\n if (c == '5') return 0;\n if (c == '6') return 1;\n if (c == '7') return 0;\n if (c == '8') return 2;\n if (c == '9') return 1;\n if (c == 'A') return 1;\n if (c == 'B') return 2;\n if (c == 'C') return 0;\n if (c == 'D') return 1;\n if (c == 'E') return 0;\n if (c == 'F') return 0;\n throw new RuntimeException();\n }\n }\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n }\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void printLine(int i) {\n writer.println(i);\n }\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "81a8b5d357dd4f9b81166b3a15baa75d", "src_uid": "16a784cb9953bc91cb2e7767b04b76f2", "difficulty": 2000.0} {"lang": "Java 6", "source_code": "import java.util.*;\n\npublic class Div {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint b = sc.nextInt(), num = sc.nextInt();\n\t\tArrayList numPrimes = getPrimes(num);\n\t\tboolean p = true;\n\t\tfor(int i=0; iy) return gcd(x%y, y);\n\t\treturn gcd(x, y%x);\n\t}\n\t\n\tstatic boolean is11(int b, int num){\n\t\treturn num==b+1;\n\t}\n\t\n\tstatic boolean secondType(int b, int num){\n\t\tArrayList l = getPrimes(num);\n\t\tfor(int i=0; i getPrimes(int b){\n\t\tArrayList l = new ArrayList();\n\t\tfor(int i=2; i<=b; i++){\n\t\t\tif(b%i==0){\n\t\t\t\tl.add(i);\n\t\t\t\twhile(b%i==0) b /= i;\n\t\t\t}\n\t\t}\n\t\tif(b>1) l.add(b);\n\t\treturn l;\n\t}\n\t\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8a9545aa8f845b6a2b05e9bf1883a29d", "src_uid": "809e1c78b0a5a16f7f2115b046a20bde", "difficulty": 2300.0} {"lang": "Java 7", "source_code": "//package codeforces;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class C {\n BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter writer = new PrintWriter(System.out);\n StringTokenizer stringTokenizer;\n\n String next() throws IOException {\n while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {\n stringTokenizer = new StringTokenizer(reader.readLine());\n }\n return stringTokenizer.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n void solve() throws IOException {\n int n = nextInt();\n int m = nextInt();\n char[][] map = new char[n][];\n int bombs = 0;\n int treasures = 0;\n for (int i = 0; i < n; i++) {\n map[i] = next().toCharArray();\n for (int j = 0; j < m; j++) {\n if (map[i][j] == 'B') bombs++;\n if (map[i][j] >= '0' && map[i][j] <= '9') {\n treasures++;\n map[i][j]--;\n }\n }\n }\n int[] treasureCosts = new int[treasures];\n for (int i = 0; i < treasures; i++) {\n treasureCosts[i] = nextInt();\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 Point subtract(Point other) {\n return new Point(x - other.x, y - other.y);\n }\n\n int vectorProduct(Point other) {\n return x * other.y - y * other.x;\n }\n\n Point add(Point other) {\n return new Point(x + other.x, y + other.y);\n }\n }\n class GeomUtils {\n Point cellCenter(int row, int column) {\n return new Point(2 * row + 1, 2 * column + 1);\n }\n\n Point ray = new Point(40, 41);\n\n double getT(Point o, Point v, Point s1, Point s2) {\n Point vs = s2.subtract(s1);\n int r = vs.vectorProduct(s2) - vs.vectorProduct(o);\n int l = vs.vectorProduct(v);\n return 1.0 * r / l;\n }\n\n boolean intersects(Point o, Point s1, Point s2) {\n if (getT(o, ray, s1, s2) < 0.0) return false;\n double t = getT(s1, s2.subtract(s1), o, o.add(ray));\n return t >= 0.0 && t <= 1.0;\n }\n }\n Point[] treasureCoords = new Point[treasures];\n Point[] bombCoords = new Point[bombs];\n bombs = 0;\n int si = 0, sj = 0;\n GeomUtils geomUtils = new GeomUtils();\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n if (map[i][j] == 'B') {\n bombCoords[bombs++] = geomUtils.cellCenter(i, j);\n }\n if (map[i][j] >= '0' && map[i][j] <= '9') {\n treasureCoords[map[i][j] - '0'] = geomUtils.cellCenter(i, j);\n }\n if (map[i][j] == 'S') {\n si = i;\n sj = j;\n }\n }\n }\n int[][][][] dist = new int[n][m][1 << treasures][1 << bombs];\n for (int i = 0; i < n; i++)\n for (int j = 0; j < m; j++)\n for (int k = 0; k < 1 << treasures; k++)\n for (int l = 0; l < 1 << bombs; l++) dist[i][j][k][l] = Integer.MAX_VALUE;\n dist[si][sj][0][0] = 0;\n Queue qi = new LinkedList<>(), qj = new LinkedList<>(), qt = new LinkedList<>(), qb = new LinkedList<>();\n qi.add(si);\n qj.add(sj);\n qt.add(0);\n qb.add(0);\n int[] di = {0, -1, 0, 1};\n int[] dj = {-1, 0, 1, 0};\n while (!qi.isEmpty()) {\n int i = qi.poll();\n int j = qj.poll();\n int tmask = qt.poll();\n int bmask = qb.poll();\n Point s1 = geomUtils.cellCenter(i, j);\n for (int k = 0; k < 4; k++) {\n int ii = i + di[k];\n int jj = j + dj[k];\n if (ii < 0 || ii >= n || jj < 0 || jj >= m || map[ii][jj] != '.' && map[ii][jj] != 'S') continue;\n int tm = 0;\n for (int ti = 0; ti < treasures; ti++) {\n if (geomUtils.intersects(treasureCoords[ti], s1, geomUtils.cellCenter(ii, jj))) {\n tm |= 1 << ti;\n }\n }\n int bm = 0;\n for (int bi = 0; bi < bombs; bi++) {\n if (geomUtils.intersects(bombCoords[bi], s1, geomUtils.cellCenter(ii, jj))) {\n bm |= 1 << bi;\n }\n }\n if (dist[ii][jj][tmask ^ tm][bmask ^ bm] == Integer.MAX_VALUE) {\n dist[ii][jj][tmask ^ tm][bmask ^ bm] = dist[i][j][tmask][bmask] + 1;\n qi.add(ii);\n qj.add(jj);\n qt.add(tmask ^ tm);\n qb.add(bmask ^ bm);\n }\n }\n }\n int ans = 0;\n for (int i = 0; i < 1 << treasures; i++) {\n if(dist[si][sj][i][0] == Integer.MAX_VALUE) continue;\n int tCost = 0;\n for (int j = 0; j < treasures; j++) {\n if (((i >> j) & 1) == 1) tCost += treasureCosts[j];\n }\n ans = Math.max(ans, tCost - dist[si][sj][i][0]);\n }\n writer.println(ans);\n writer.close();\n }\n\n public static void main(String[] args) throws IOException {\n new C().solve();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5dac67946dd7d33061b8b3062d6136c3", "src_uid": "624a0d6cf305fcf67d3f1cdc1c5fef8d", "difficulty": 2600.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\n\npublic class Main implements Runnable {\n void solution() throws Exception {\n int n = nextInt();\n int m = nextInt();\n int x1 = nextInt();\n int y1 = nextInt();\n int x2 = nextInt();\n int y2 = nextInt();\n if (Math.abs(x2-x1) >= 5 || Math.abs(y2-y1) >= 5)\n System.out.println(\"Second\");\n else\n System.out.println(\"First\");\n }\n\n ///////////////////// Template definitions //////////////////////////\n int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n String next() throws IOException {\n while (st == null || !st.hasMoreTokens()) {\n String l = in.readLine();\n if (l == null) return null;\n st = new StringTokenizer(l);\n }\n return st.nextToken();\n }\n\n public static void main(String args[]) {\n //Locale.setDefault(Locale.UK);\n new Thread(new Main()).start();\n }\n\n public void run() {\n try {\n boolean online = true;\n Reader reader = online\n ? new InputStreamReader(System.in)\n : new FileReader(\"my.in\");\n in = new BufferedReader(reader);\n out = new PrintWriter(System.out);\n solution();\n out.flush();\n out.close();\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(202);\n }\n }\n\n BufferedReader in;\n StringTokenizer st;\n PrintWriter out;\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fa1b10a6303ab686ccd0bb8f54953b1e", "src_uid": "41f6f90b7307d2383495441114fa8ea2", "difficulty": 2000.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.HashMap;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Stack;\n\npublic class School1G {\n\n static BufferedReader in = new BufferedReader(new InputStreamReader(\n System.in));\n static PrintWriter out = new PrintWriter(System.out);\n\n public static void main(String[] args) throws Exception {\n int n = Integer.valueOf(in.readLine());\n char[] buf = new char[200];\n int k = in.read(buf);\n\n String prog = String.valueOf(buf, 0, k);\n prog = prog.substring(prog.indexOf('{') + 1);\n prog = prog.substring(0, prog.indexOf('}'));\n String[] opers = prog.split(\";\");\n for (int i = 0; i < opers.length; i++)\n opers[i] = opers[i].trim();\n\n Function.init(opers.length - 1);\n for (int i = 0; i < opers.length - 1; i++)\n Function.body[i] = new Operator(opers[i]);\n\n int ans = -1;\n for (int i = (1 << 15)-1; i >= 0; i--)\n if (Function.eval(i) == n) {\n ans = i;\n break;\n }\n\n out.println(ans);\n\n out.flush();\n }\n\n}\n\nclass Function {\n static HashMap func = new HashMap();\n static Operator[] body;\n\n static void init(int n) {\n body = new Operator[n];\n }\n\n static int eval(int n) {\n if (func.containsKey(n)) return func.get(n);\n \n for (Operator oper : body) {\n int r = oper.eval(n);\n if (r != -1) {\n func.put(n, r);\n return r;\n }\n }\n return -1;\n }\n}\n\nclass Expression {\n static final int MD = 1 << 15;\n \n List poliz;\n\n public Expression(String s) {\n s += \"$\";\n Stack ops = new Stack();\n poliz = new LinkedList();\n int p = 0;\n char c = ' ';\n while (c != '$') {\n String cur = \"\";\n while (c <= ' ')\n c = s.charAt(p++);\n if (c == 'n') {\n cur = \"n\";\n c = s.charAt(p++);\n poliz.add(cur);\n } else if (c == 'f') {\n cur = \"f\";\n while (c != '(')\n c = s.charAt(p++);\n c = s.charAt(p++);\n ops.push(cur);\n } else if (c >= '0' && c <= '9') {\n while (c >= '0' && c <= '9') {\n cur += (char) c;\n c = s.charAt(p++);\n }\n poliz.add(cur);\n } else {\n cur += (char) c;\n c = s.charAt(p++);\n if (cur.equals(\")\")) {\n while (!ops.peek().equals(\"f\"))\n poliz.add(ops.pop());\n poliz.add(ops.pop());\n } else if (cur.equals(\"+\") || cur.equals(\"-\"))\n while (!ops.empty() && !ops.peek().equals(\"f\"))\n poliz.add(ops.pop());\n else\n while (!ops.empty()\n && (ops.peek().equals(\"*\") || ops.peek()\n .equals(\"/\")))\n poliz.add(ops.pop());\n if (!cur.equals(\")\"))\n ops.push(cur);\n }\n }\n while (!ops.empty())\n poliz.add(ops.pop());\n }\n\n public int eval(int n) {\n Stack st = new Stack();\n for (String s : poliz) {\n if (s.equals(\"n\"))\n st.push(n);\n else if (s.charAt(0) >= '0' && s.charAt(0) <= '9')\n st.push(Integer.valueOf(s));\n else if (s.equals(\"f\"))\n st.push(Function.eval(st.pop()));\n else {\n int b = st.pop(), a = st.pop();\n if (s.equals(\"+\")) st.push((a + b)%MD);\n else if (s.equals(\"*\")) st.push(a*b%MD);\n else if (s.equals(\"/\")) st.push(a/b);\n else {\n int x = a - b;\n while (x < 0) x += MD;\n st.push(x);\n }\n }\n }\n return st.pop();\n }\n}\n\nclass Condition {\n int sign;\n Expression left, right;\n\n public Condition(String s) {\n s = s.substring(1, s.length() - 1);\n int sgn = s.indexOf('<');\n if (sgn >= 0) {\n sign = -1;\n left = new Expression(s.substring(0, sgn).trim());\n right = new Expression(s.substring(sgn + 1).trim());\n } else if ((sgn = s.indexOf('>')) >= 0) {\n sign = 1;\n left = new Expression(s.substring(0, sgn).trim());\n right = new Expression(s.substring(sgn + 1).trim());\n } else {\n sgn = s.indexOf(\"=\");\n sign = 0;\n left = new Expression(s.substring(0, sgn).trim());\n right = new Expression(s.substring(sgn + 2).trim());\n }\n }\n\n public boolean eval(int n) {\n int a = left.eval(n), b = right.eval(n);\n if (sign == -1)\n return a < b;\n else if (sign == 1)\n return a > b;\n else\n return a == b;\n }\n}\n\nclass Operator {\n boolean isIf;\n Condition cond;\n Expression toReturn;\n\n public Operator(String s) {\n if (s.startsWith(\"if\")) {\n int whereRet = s.indexOf(\"return\");\n isIf = true;\n cond = new Condition(s.substring(2, whereRet).trim());\n toReturn = new Expression(s.substring(whereRet + 6).trim());\n } else {\n isIf = false;\n cond = null;\n toReturn = new Expression(s.substring(6).trim());\n }\n }\n\n public int eval(int n) {\n if (isIf && !cond.eval(n))\n return -1;\n\n return toReturn.eval(n);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "07b7dea011597f6ab3550930a9fae8a2", "src_uid": "698c5a87f9adbe6af60d9f70519c9672", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class J implements Runnable {\n\n private static final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\n private BufferedReader in;\n private PrintWriter out;\n private StringTokenizer tok = new StringTokenizer(\"\");\n\n private void init() throws FileNotFoundException {\n Locale.setDefault(Locale.US);\n String fileName = \"\";\n if (ONLINE_JUDGE && fileName.isEmpty()) {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n } else {\n if (fileName.isEmpty()) {\n in = new BufferedReader(new FileReader(\"input.txt\"));\n out = new PrintWriter(\"output.txt\");\n } else {\n in = new BufferedReader(new FileReader(fileName + \".in\"));\n out = new PrintWriter(fileName + \".out\");\n }\n }\n }\n\n String readString() throws IOException {\n while (!tok.hasMoreTokens()) {\n tok = new StringTokenizer(in.readLine());\n\n }\n return tok.nextToken();\n }\n\n int readInt() throws IOException {\n return Integer.parseInt(readString());\n }\n\n long readLong() throws IOException {\n return Long.parseLong(readString());\n }\n\n double readDouble() throws IOException {\n return Double.parseDouble(readString());\n }\n\n int[] readIntArray(int size) throws IOException {\n int[] a = new int[size];\n for (int i = 0; i < size; i++) {\n a[i] = readInt();\n }\n return a;\n }\n\n public static void main(String[] args) {\n //new Thread(null, new _Solution(), \"\", 128 * (1L << 20)).start();\n new J().run();\n }\n\n long timeBegin, timeEnd;\n\n void time() {\n timeEnd = System.currentTimeMillis();\n System.err.println(\"Time = \" + (timeEnd - timeBegin));\n }\n\n @Override\n public void run() {\n try {\n timeBegin = System.currentTimeMillis();\n init();\n solve();\n out.close();\n time();\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(-1);\n }\n }\n\n int[][][][] dp;\n char[] s;\n int INF = 10000000;\n\n int count(char[] s, char target, int v, int k, int x) {\n int answer = 0;\n for (char c : s) {\n if (c == 'V') {\n v--;\n if (v == 0 && target == 'V') return answer;\n if (v < 0) answer++;\n }\n if (c == 'K') {\n k--;\n if (k == 0 && target == 'K') return answer;\n if (k < 0) answer++;\n }\n if (c == 'X') {\n x--;\n if (x == 0 && target == 'X') return answer;\n if (x < 0) answer++;\n }\n }\n throw new RuntimeException();\n }\n\n private void solve() throws IOException {\n int n = readInt();\n s = readString().toCharArray();\n int vcnt = 0, kcnt = 0, xcnt = 0;\n for (int i = 0; i < s.length; i++) {\n if (s[i] == 'V') {\n vcnt++;\n continue;\n }\n if (s[i] == 'K') {\n kcnt++;\n continue;\n }\n xcnt++;\n s[i] = 'X';\n }\n dp = new int[vcnt + 1][kcnt + 1][xcnt + 1][3];\n for (int[][][] x : dp) {\n for (int[][] xx : x) {\n for (int[] xxx : xx) {\n Arrays.fill(xxx, INF);\n }\n }\n }\n dp[0][0][0][0] = dp[0][0][0][1] = dp[0][0][0][2] = 0;\n //V,K,X\n for (int v = 0; v <= vcnt; v++) {\n for (int k = 0; k <= kcnt; k++) {\n for (int x = 0; x <= xcnt; x++) {\n int rv = v + 1 <= vcnt ? count(s, 'V', v + 1, k, x) : 0;\n int rk = k + 1 <= kcnt ? count(s, 'K', v, k + 1, x) : 0;\n int rx = x + 1 <= xcnt ? count(s, 'X', v, k, x + 1) : 0;\n\n for (int now = 0; now < 3; now++) {\n if (v + 1 <= vcnt) dp[v + 1][k][x][0] = Math.min(dp[v + 1][k][x][0], dp[v][k][x][now] + rv);\n if (now != 0 && k + 1 <= kcnt) dp[v][k + 1][x][1] = Math.min(dp[v][k + 1][x][1], dp[v][k][x][now] + rk);\n if (x + 1 <= xcnt) dp[v][k][x + 1][2] = Math.min(dp[v][k][x + 1][2], dp[v][k][x][now] + rx);\n }\n }\n }\n }\n int res = INF;\n for (int i = 0; i < 3; i++) {\n res = Math.min(res, dp[vcnt][kcnt][xcnt][i]);\n }\n out.println(res);\n\n\n }\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "98cfede7aa516afcd14fb2f24d5b6f5d", "src_uid": "08444f9ab1718270b5ade46852b155d7", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "/*\n * Author Ayub Subhaniya\n * Institute DA-IICT\n */\n \nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n \n \npublic class Codeforces429D\n{\n\t\n\tInputStream in;\n\tPrintWriter out;\n\t\n\tlong MAX=Long.MAX_VALUE;\n\tvoid solve() \n\t{\n\t\tlong f=nl();\n\t\tlong T=nl();\n\t\tlong t0=nl();\n\t\tlong a1,t1,p1,a2,t2,p2;\n\t\ta1=nl();t1=nl();p1=nl();\n\t\ta2=nl();t2=nl();p2=nl();\n\t\t\n\t\tlong max1=f/a1;\n\t\tlong max2=f/a2;\n\t\tlong cost=MAX;\n\t\t\n\t\tif (t1>1);\n\t\t\t\t\ttd=a2*mid;\n\t\t\t\t\tif (t+td*t2+(sz-td)*t0 <= T)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult=mid;\n\t\t\t\t\t\tr=mid-1;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tl=mid+1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (t+sz*t2<=T)\n\t\t\t\t\tcost=Math.min(cost, k1*p1+((sz+a2-1)/a2)*p2);\n\t\t\t\t\n\t\t\t\tif (result!=-1)\n\t\t\t\t{\n\t\t\t\t\tcost=Math.min(cost, k1*p1+result*p2);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t\tif (f*t1<=T)\n\t\t\t\tcost=Math.min(cost, ((f+a1-1)/a1)*p1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tfor (int k2=0;k2<=max2;k2++)\n\t\t\t{\n\t\t\t\tlong sz=f-k2*a2;\n\t\t\t\t\n\t\t\t\tlong l=0,r=sz/a1,result=-1,t=a2*k2*t2;\n\t\t\t\tlong td;\n\t\t\t\twhile (l<=r)\n\t\t\t\t{\n\t\t\t\t\tlong mid=((l+r)>>1);\n\t\t\t\t\ttd=a1*mid;\n\t\t\t\t\tif (t+td*t1+(sz-td)*t0<=T)\n\t\t\t\t\t{\n\t\t\t\t\t\tresult=mid;\n\t\t\t\t\t\tr=mid-1;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tl=mid+1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (t+sz*t1<=T)\n\t\t\t\t\tcost=Math.min(cost, k2*p2+((sz+a1-1)/a1)*p1);\n\t\t\t\t\n\t\t\t\tif (result!=-1)\n\t\t\t\t{\n\t\t\t\t\tcost=Math.min(cost, k2*p2+result*p1);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t\tif (f*t2<=T)\n\t\t\t\tcost=Math.min(cost, ((f+a2-1)/a2)*p2);\n\t\t}\n\t\t\n\t\tif (cost==MAX)\n\t\t\tout.println(-1);\n\t\telse\n\t\t\tout.println(cost);\n\t}\n\t\t\n\tvoid run() throws Exception \n\t{\n\t\tString INPUT = \"C:/Users/ayubs/Desktop/input.txt\";\n\t\tin = oj ? System.in : new FileInputStream(INPUT);\n\t\tout = new PrintWriter(System.out);\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis() - s + \"ms\");\n\t\t\n\t}\n\tpublic static void main(String[] args) throws Exception \n\t{\n\t\tnew Codeforces429D().run();\n\t}\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte() \n\t{\n\t\tif (lenbuf == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (ptrbuf >= lenbuf) \n\t\t{\n\t\t\tptrbuf = 0;\n\t\t\ttry \n\t\t\t{\n\t\t\t\tlenbuf = in.read(inbuf);\n\t\t\t}\n\t\t\tcatch (IOException e) \n\t\t\t{\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (lenbuf <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean inSpaceChar(int c) \n\t{\n\t\treturn !(c >= 33 && c <= 126);\n\t}\n\t\n\tprivate int skip() \n\t{\n\t\tint b;\n\t\twhile ((b = readByte()) != -1 && inSpaceChar(b))\n\t\t\t;\n\t\treturn b;\n\t}\n\t\n\tprivate double nd() \n\t{\n\t\treturn Double.parseDouble(ns());\n\t}\n\t\n\tprivate char nc() \n\t{\n\t\treturn (char) skip();\n\t}\n\t\n\tprivate String ns() \n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!(inSpaceChar(b))) \n\t\t{ // when nextLine, (inSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n) \n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile (p < n && !(inSpaceChar(b))) \n\t\t{\n\t\t\tbuf[p++] = (char) b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m) \n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tmap[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n) \n\t{\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni() \n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t;\n\t\tif (b == '-') \n\t\t{\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile (true) \n\t\t{\n\t\t\tif (b >= '0' && b <= '9') \n\t\t\t{\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t} \n\t\t\telse \n\t\t\t{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl() \n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t;\n\t\tif (b == '-') \n\t\t{\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile (true) \n\t\t{\n\t\t\tif (b >= '0' && b <= '9') \n\t\t\t{\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}\n\t\t\telse \n\t\t\t{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\n\tprivate void tr(Object... o) \n\t{\n\t\tif (!oj)\n\t\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n\t\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "bd7401fac37b5538c08c0c848139c5f7", "src_uid": "f5f85e75af5b0f25f1f436a21e12fad1", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Codeforces913F {\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner input = new Scanner(System.in);\n\t\tint n = input.nextInt();\n\t\tint a = input.nextInt();\n\t\tint b = input.nextInt();\n\t\tinput.close();\n\t\tfinal int mod = 998244353;\n\t\t\n\t\tint frac = multiply(a, inverse(b, mod), mod);\n\t\tint reverse = (mod+1-frac)%mod;\n\t\t\n\t\tint[] fracpower = new int[n+1];\n\t\tint[] reversepower = new int[n+1];\n\t\tfracpower[0] = 1;\n\t\treversepower[0] = 1;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tfracpower[i] = multiply(fracpower[i-1], frac, mod);\n\t\t\treversepower[i] = multiply(reversepower[i-1], reverse, mod);\n\t\t}\n\t\t\n\t\tint[][] dp1 = new int[n+1][n+1];\n\t\tdp1[2][1] = 1;\n\t\tfor (int i = 3; i <= n; i++) {\n\t\t\tfor (int j = 1; j < i; j++) {\n\t\t\t\tif (j == 1) {\n\t\t\t\t\tdp1[i][j] = fracpower[i-1];\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tdp1[i][j] = multiply(dp1[i-1][j-1], fracpower[i-j], mod);\n\t\t\t\t}\n\t\t\t\tif (j == i-1) {\n\t\t\t\t\tdp1[i][j] += reversepower[i-1];\n\t\t\t\t\tdp1[i][j] %= mod;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tdp1[i][j] += multiply(dp1[i-1][j], reversepower[j], mod);\n\t\t\t\t\tdp1[i][j] %= mod;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tint[][] dp2 = new int[n+1][n+1];\n\t\tdp2[1][1] = 1;\n\t\tdp2[2][1] = 1;\n\t\tdp2[2][2] = 0;\n\t\tfor (int i = 3; i <= n; i++) {\n\t\t\tint val = 0;\n\t\t\tfor (int j = 1; j < i; j++) {\n\t\t\t\tdp2[i][j] = multiply(dp2[j][j], dp1[i][j], mod);\n\t\t\t\tval += dp2[i][j];\n\t\t\t\tval %= mod;\n\t\t\t}\n\t\t\tdp2[i][i] = (mod+1-val)%mod;\n\t\t}\n\t\t\n\t\t/*for (int i = 2; i <= n; i++) {\n\t\t\tfor (int j = 1; j <= i; j++) {\n\t\t\t\tSystem.out.print(dp2[i][j] + \" \");\n\t\t\t}\n\t\t\tSystem.out.println();\n\t\t}*/\n\t\t\n\t\tint[] EV = new int[n+1];\n\t\tEV[1] = 0;\n\t\tEV[2] = 1;\n\t\tfor (int i = 3; i <= n; i++) {\n\t\t\tint val = 0;\n\t\t\tfor (int j = 1; j < i; j++) {\n\t\t\t\tint r = j*(i-j) + (j*(j-1))/2 + EV[i-j] + EV[j];\n\t\t\t\tr %= mod;\n\t\t\t\tval += multiply(dp2[i][j], r, mod);\n\t\t\t\tval %= mod;\n\t\t\t}\n\t\t\tval += multiply((i*(i-1))/2, dp2[i][i], mod);\n\t\t\tval %= mod;\n\t\t\t\n\t\t\tint s = (mod+1-dp2[i][i])%mod;\n\t\t\tEV[i] = multiply(val, inverse(s, mod), mod);\n\t\t}\n\t\t\n\t\tSystem.out.println(EV[n]);\n\t}\n\t\n\tpublic static int multiply(int a, int b, int mod) {\n\t\tlong x = (long)a*(long)b;\n\t\treturn (int) (x%mod);\n\t}\n\t\n\tpublic static int inverse (int a, int n) {\n\t\tint m = n;\n\t\tint r1 = 1;\n\t\tint r2 = 0;\n\t\tint r3 = 0;\n\t\tint r4 = 1;\n\t\twhile ((a > 0) && (n > 0)) {\n\t\t\tif (n >= a) {\n\t\t\t\tr3 -= r1*(n/a);\n\t\t\t\tr4 -= r2*(n/a);\n\t\t\t\tn = n%a;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tint tmp = a;\n\t\t\t\ta = n;\n\t\t\t\tn = tmp;\n\t\t\t\ttmp = r1;\n\t\t\t\tr1 = r3;\n\t\t\t\tr3 = tmp;\n\t\t\t\ttmp = r2;\n\t\t\t\tr2 = r4;\n\t\t\t\tr4 = tmp;\n\t\t\t}\n\t\t}\n\t\tif (a == 0) {\n\t\t\tif (r3 >= 0)\n\t\t\t\treturn (r3%m);\n\t\t\telse\n\t\t\t\treturn (m+(r3%m));\n\t\t}\n\t\telse {\n\t\t\tif (r1 >= 0)\n\t\t\t\treturn (r1%m);\n\t\t\telse\n\t\t\t\treturn (m+(r1%m));\n\t\t}\n\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4ec914cab93204085e990b3a93041beb", "src_uid": "67e599530203060c17f692f2624d0f99", "difficulty": 2800.0} {"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.math.BigInteger;\nimport java.util.StringTokenizer;\n\npublic class MainE {\n\n private FastScanner in;\n private PrintWriter out;\n\n long MOD = 998244353L;\n\n long[] gcd_ex(long a, long b) {\n if (a == 0) {\n return new long[]{0, 1};\n }\n long[] res = gcd_ex(b % a, a);\n long t = res[0];\n res[0] = res[1] - (b / a) * res[0];\n res[1] = t;\n return res;\n }\n\n long reverse(long a) {\n return (gcd_ex(a, MOD)[0] + 100 * MOD) % MOD;\n }\n\n long powMod(long a, long b) {\n long res = 1;\n long mul = a;\n while (b > 0) {\n if ((b & 1) > 0) {\n res = (res * mul) % MOD;\n }\n mul = (mul * mul) % MOD;\n b /= 2;\n }\n return res;\n }\n\n public void solve() {\n long N = in.nextInt();\n long[] combs = new long[(int)(N + 1)];\n combs[0] = 1;\n for (int i = 1; i <= N; i++) {\n long t = combs[i - 1];\n t = (t * (N - i + 1)) % MOD;\n t = (t * reverse(i)) % MOD;\n combs[i] = t;\n }\n long res = 0;\n long p1 = 1;\n long p2 = 1;\n long R = powMod(reverse(3), N);\n for (int i = 1; i <= N; i++) {\n p1 = (p1 * R) % MOD;\n p2 = (p2 * 3) % MOD;\n long t = combs[i] * p1 % MOD;\n t = (t * p2) % MOD;\n if ((i & 1) > 0) {\n res += 2 * t;\n } else {\n res = (res + 2 * MOD - 2 * t) % MOD;\n }\n res %= MOD;\n }\n res = res * powMod(3, N * N) % MOD;\n long i3 = 1;\n for (int i = 0; i < N; i++){\n long mi3 = (MOD - i3) % MOD;\n i3 = (i3 * 3) % MOD;\n long t = combs[i] * ((MOD + powMod(1 + mi3, N) - powMod(mi3, N)) % MOD);\n if ((i & 1) > 0) {\n res += 3 * t;\n } else {\n res = (res + 3 * MOD - 3 * t) % MOD;\n }\n res %= MOD;\n }\n System.out.println(res);\n }\n\n public void run() {\n in = new FastScanner(System.in);\n out = new PrintWriter(System.out);\n solve();\n out.close();\n }\n\n class FastScanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n FastScanner(InputStream is) {\n br = new BufferedReader(new InputStreamReader(is));\n }\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n }\n catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n }\n\n public static void main(String[] arg) {\n new MainE().run();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9a36013d0375627b14f66622382bf98b", "src_uid": "6e4b0ee2e1406041a961582ead299a3a", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class F {\n static Scanner sc = new Scanner(System.in);\n static final double logE = Math.log(Math.E);\n\n public static void main(String[] args) {\n int V = sc.nextInt();\n double[] factLog = new double[5001];\n for (int i = 1; i < factLog.length; i++) {\n factLog[i] = Math.log(i) + factLog[i - 1];\n }\n for (int i = 0; i < V; i++) {\n int[] K = new int[250];\n int min = 0;\n int max = 0;\n long sum = 0;\n long sum2 = 0;\n for (int j = 0; j < K.length; j++) {\n K[j] = sc.nextInt();\n min = Math.min(min, K[j]);\n max = Math.max(max, K[j]);\n sum += K[j];\n sum2 += K[j] * K[j];\n }\n double ave = 1.0 * sum / K.length;\n double ave2 = 1.0 * sum2 / K.length;\n double var = ave2 - ave * ave;\n System.err.println(\"var:\" + var);\n double uniform = -Math.log(2 * Math.max(0, Math.max(max, -min) + 1)) * K.length;\n double poisson = -Double.MAX_VALUE;\n for (int j = Math.max(1, Math.max(-min, (int) var - 100)); j <= (int) var + 300; j++) {\n double likelyhood = 0;\n for (int k = 0; k < K.length; k++) {\n likelyhood += (K[k] + j) * Math.log(j) - j * logE - factLog[K[k] + j];\n }\n if (likelyhood > poisson) {\n poisson = likelyhood;\n }\n }\n System.err.println(uniform + \" \" + poisson);\n System.out.println(uniform < poisson ? \"poisson\" : \"uniform\");\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e332e8382f4a103720eb1ff6635b6922", "src_uid": "6ef75e501b318c0799d3cbe8ca998984", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\npublic class Div2_421C {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer inputData = new StringTokenizer(reader.readLine());\n\t\tint a = Integer.parseInt(inputData.nextToken());\n\t\tint b = Integer.parseInt(inputData.nextToken());\n\t\tint l = Integer.parseInt(inputData.nextToken());\n\t\tint r = Integer.parseInt(inputData.nextToken());\n\n\t\tStringBuilder cString = new StringBuilder();\n\t\tfor (int i = 0; i < a; i++) {\n\t\t\tcString.append((char) ('a' + i));\n\t\t}\n\t\tchar last = cString.charAt(cString.length() - 1);\n\t\tfor (int i = 0; i < b; i++) {\n\t\t\tcString.append(last);\n\t\t}\n\t\tTreeSet used = new TreeSet();\n\t\tfor (char c : cString.substring(cString.length() - a, cString.length()).toCharArray()) {\n\t\t\tused.add(c - 'a');\n\t\t}\n\n\t\tint nxt = 0;\n\t\tfor (int i = 0; i < a; i++) {\n\t\t\twhile (used.contains(nxt)) {\n\t\t\t\tnxt++;\n\t\t\t}\n\t\t\tcString.append((char) ('a' + nxt));\n\t\t\tnxt++;\n\t\t}\n\n\t\tlast = cString.charAt(cString.length() - 1);\n\t\tfor (int i = 0; i < b; i++) {\n\t\t\tcString.append(last);\n\t\t}\n\n\t\tint len = cString.length();\n\n\t\tused.clear();\n\t\tif (r - l + 1 >= len) {\n\t\t\tfor (char c : cString.toString().toCharArray()) {\n\t\t\t\tused.add(c - 'a');\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = l; i != (r + 1) % len; i = (i + 1) % len) {\n\t\t\t\tused.add(cString.charAt(i) - 'a');\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(used.size());\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "019c6f156ec274d8f0edc26ee824aa25", "src_uid": "d055b2a594ae7788ecafb3ef80f246ec", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class hevticA {\npublic static void main(String [] args){\n\tScanner scan=new Scanner(System.in);\n\t\n\tlong x=scan.nextLong();\n\t\n\t\n\t\tif(x%2==1){\n\t\t\tSystem.out.print(x/2);\n\t\t}\n\t\n\t\telse{\n\t\t\tlong y=1;\n\t\t\twhile (y<=x){\n\t\t\t\ty=y*2;\n\t\t\t}\n\t\t\ty=y/2;\n\t\t\tSystem.out.print((x-y)/2);\n\t\t\t\n\t\t}\n}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4459e44340d09163296b9d285a0b63d5", "src_uid": "422abdf2f705c069e540d4f5c09a4948", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "\n import java.io.*;\nimport java.util.*;\n\npublic class MethodTest {\n\n\tstatic final int P = 1_000_000_007;\n\n\tstatic void submit() {\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\t\tlong exp = nextLong();\n\t\tint[] a = new int[n];\n\t\tint[] b = new int[m];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = nextInt();\n\t\t}\n\t\tint maxCoef = 0;\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tb[i] = nextInt();\n\t\t\tmaxCoef = Math.max(maxCoef, b[i]);\n\t\t}\n\n\t\tint[] bPoly = new int[maxCoef + 1];\n\t\tbPoly[maxCoef] = 1;\n\t\tfor (int pow : b) {\n\t\t\tbPoly[maxCoef - pow]--;\n\t\t\tif (bPoly[maxCoef - pow] < 0) {\n\t\t\t\tbPoly[maxCoef - pow] += P;\n\t\t\t}\n\t\t}\n\n\t\tint[] aPoly = {};\n\t\tfor (int pow : a) {\n\t\t\taPoly = sum(aPoly, quotPow(new int[] { 0, 1 }, bPoly, pow));\n\t\t}\n\t\tint[] ans = quotPow(aPoly, bPoly, exp);\n\n\t\tans = prod(ans, quotPow(new int[] { 0, 1 }, bPoly, maxCoef));\n\t\tans = quot(ans, bPoly);\n\n\t\tout.println((long)ans[0] * inv(P - bPoly[0]) % P);\n\t}\n\n\tstatic int inv(int x) {\n\t\treturn x == 1 ? 1 : P - (int)((long)(P / x) * inv(P % x) % P);\n\t}\n\n\tstatic int[] quotPow(int[] a, int[] b, long n) {\n\t\ta = quot(a, b);\n\t\tint[] ret = { 1 };\n\t\tfor (; n > 0; n >>= 1) {\n\t\t\tif ((n & 1) == 1) {\n\t\t\t\tret = quot(prod(ret, a), b);\n\t\t\t}\n\t\t\ta = quot(prod(a, a), b);\n\t\t}\n\t\treturn ret;\n\t}\n\n\tstatic int[] sum(int[] a, int[] b) {\n\t\tint[] c = Arrays.copyOf(a, Math.max(a.length, b.length));\n\t\tfor (int i = 0; i < b.length; i++) {\n\t\t\tc[i] += b[i];\n\t\t\tif (c[i] >= P) {\n\t\t\t\tc[i] -= P;\n\t\t\t}\n\t\t}\n\t\treturn c;\n\t}\n\n\tstatic int[] prod(int[] a, int[] b) {\n\t\tint[] c = new int[a.length + b.length - 1];\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tfor (int j = 0; j < b.length; j++) {\n\t\t\t\tc[i + j] += (int) ((long) a[i] * b[j] % P);\n\t\t\t\tif (c[i + j] >= P) {\n\t\t\t\t\tc[i + j] -= P;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn c;\n\t}\n\n\tstatic int[] quot(int[] a, int[] b) {\n\t\ta = a.clone();\n\t\t// leading coef of b is 1\n\t\tif (a.length < b.length) {\n\t\t\treturn a;\n\t\t}\n\t\tint degB = b.length - 1;\n\t\tfor (int ptr = a.length - 1; ptr >= degB; ptr--) {\n\t\t\tlong coef = a[ptr];\n\t\t\tfor (int i = 0, j = ptr - degB; i < degB; i++, j++) {\n\t\t\t\ta[j] -= (int) (coef * b[i] % P);\n\t\t\t\tif (a[j] < 0) {\n\t\t\t\t\ta[j] += P;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn Arrays.copyOf(a, degB);\n\t}\n\n\tstatic void preCalc() {\n\n\t}\n\n\tstatic void stress() {\n\n\t}\n\n\tstatic void test() {\n\n\t}\n\n\tpublic static void run() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tpreCalc();\n\t\tsubmit();\n\t\tout.close();\n\t}\n\n\tstatic final Random rng = new Random();\n\n\tstatic int rand(int l, int r) {\n\t\treturn l + rng.nextInt(r - l + 1);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\trun();\n\t}\n\n\tstatic BufferedReader br;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer st;\n\n\tstatic String nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (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\tstatic String nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t}\n\n\tstatic int nextInt() {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tstatic long nextLong() {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tstatic double nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "322e47169183d8ad118ef66f0fc8c5b3", "src_uid": "c3a4c109080f49b88be5fb13157d1af0", "difficulty": 3300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class MainD {\n\tstatic final StdIn in = new StdIn();\n\tstatic final PrintWriter out = new PrintWriter(System.out);\n\tstatic final long M=(long)1e9+7;\n\tstatic int n=in.nextInt(), m=in.nextInt();\n\tstatic Map graph = new HashMap();\n\t\n\tpublic static void main(String[] args) {\n\t\taddNode(1);\n\t\tfor(int i=0; i nodeEntry : graph.entrySet()) {\n\t\t\tNode u=nodeEntry.getValue();\n\t\t\tfor(int i=u.adj.size()-1; i>=0; --i) {\n\t\t\t\tif(!graph.containsKey(u.adj.get(i))) {\n\t\t\t\t\tu.s+=sts(u.adj.get(i));\n\t\t\t\t\tu.adj.remove(i);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong ans=0;\n\t\tfor(Map.Entry nodeEntry : graph.entrySet())\n\t\t\tans=(dfs(nodeEntry.getKey(), 0)+ans)%M;\n\t\tout.println(ans);\n\t\tout.close();\n\t}\n\t\n\tstatic Node addNode(int u) {\n\t\tif(u<=0)\n\t\t\treturn null;\n\t\tNode node = graph.get(u);\n\t\tif(node!=null)\n\t\t\treturn node;\n\t\tnode = new Node();\n\t\tif(u>1)\n\t\t\tnode.adj.add(u/2);\n\t\tif(u*2<=n)\n\t\t\tnode.adj.add(u*2);\n\t\tif(u*2+1<=n)\n\t\t\tnode.adj.add(u*2+1);\n\t\tgraph.put(u, node);\n\t\taddNode(u/2);\n\t\treturn node;\n\t}\n\t\n\tstatic long sts(int u) {\n\t\tlong res=0;\n\t\tint l=u, r=u;\n\t\twhile(r<=n) {\n\t\t\tres+=r-l+1;\n\t\t\tl=2*l;\n\t\t\tr=2*r+1;\n\t\t}\n\t\treturn (res+Math.min(r, n)-Math.min(l, n+1)+1)%M;\n\t}\n\t\n\tstatic long dfs(int u, long ps) {\n\t\tNode node=graph.get(u);\n\t\tif(ps==0)\n\t\t\tps=node.s;\n\t\tnode.active=true;\n\t\tlong res=ps*node.s;\n\t\tfor(int v : node.adj)\n\t\t\tif(!graph.get(v).active)\n\t\t\t\tres+=dfs(v, ps);\n\t\tnode.active=false;\n\t\treturn res;\n\t}\n\t\n\tstatic class Node {\n\t\tList adj = new ArrayList();\n\t\tlong s=1;\n\t\tboolean active;\n\t}\n\t\n\tinterface Input {\n\t\tpublic String next();\n\t\tpublic String nextLine();\n\t\tpublic int nextInt();\n\t\tpublic long nextLong();\n\t\tpublic double nextDouble();\n\t}\n\tstatic class StdIn implements Input {\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\t\tpublic StdIn() {\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\t\tpublic StdIn(InputStream in) {\n\t\t\ttry{\n\t\t\t\tdin = new DataInputStream(in);\n\t\t\t} catch(Exception e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t\tbuffer = new byte[BUFFER_SIZE];\n\t\t\tbufferPointer = bytesRead = 0;\n\t\t}\n\t\tpublic String next() {\n\t\t\tint c;\n\t\t\twhile((c=read())!=-1&&(c==' '||c=='\\n'||c=='\\r'));\n\t\t\tStringBuilder s = new StringBuilder();\n\t\t\twhile (c != -1)\n\t\t\t{\n\t\t\t\tif (c == ' ' || c == '\\n'||c=='\\r')\n\t\t\t\t\tbreak;\n\t\t\t\ts.append((char)c);\n\t\t\t\tc=read();\n\t\t\t}\n\t\t\treturn s.toString();\n\t\t}\n\t\tpublic String nextLine() {\n\t\t\tint c;\n\t\t\twhile((c=read())!=-1&&(c==' '||c=='\\n'||c=='\\r'));\n\t\t\tStringBuilder s = new StringBuilder();\n\t\t\twhile (c != -1)\n\t\t\t{\n\t\t\t\tif (c == '\\n'||c=='\\r')\n\t\t\t\t\tbreak;\n\t\t\t\ts.append((char)c);\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\treturn s.toString();\n\t\t}\n\t\tpublic int nextInt() {\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\twhile ((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\t\tpublic int[] readIntArray(int n) {\n\t\t\tint[] ar = new int[n];\n\t\t\tfor(int i=0; i= '0' && c <= '9');\n\t\t\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\n\t\tpublic long[] readLongArray(int n) {\n\t\t\tlong[] ar = new long[n];\n\t\t\tfor(int i=0; i= '0' && c <= '9');\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\tif (neg)\n\t\t\t\treturn -ret;\n\t\t\treturn ret;\n\t\t}\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\t\tprivate byte read() {\n\t\t\ttry{\n\t\t\t\tif (bufferPointer == bytesRead)\n\t\t\t\t\tfillBuffer();\n\t\t\t\treturn buffer[bufferPointer++];\n\t\t\t} catch(IOException e) {\n\t\t\t\tthrow new RuntimeException();\n\t\t\t}\n\t\t}\n\t\tpublic void close() throws IOException {\n\t\t\tif (din == null)\n\t\t\t\treturn;\n\t\t\tdin.close();\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "99481e47a33e6bc52f561a68ebf55d97", "src_uid": "250314325e3d088ceedaba7dcde762f1", "difficulty": 2800.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.List;\nimport java.util.StringTokenizer;\n\npublic class ab6 {\n\n public static void debug(Object... obs)\n {\n System.out.println(Arrays.deepToString(obs));\n }\n\n static int[][]h;\n static int[][]w;\n \n public static void main(String[] args) throws IOException\n {\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer st=new StringTokenizer(br.readLine());\n int n=Integer.parseInt(st.nextToken());\n int k=Integer.parseInt(st.nextToken());\n int t=Integer.parseInt(st.nextToken());\n \n h=new int[k][k];\n w=new int[k][k];\n \n for(int i=0;i0)\n {\n su+=hi[i][j];\n dp[su]=true;\n aw[j]=true;\n bld_h(pos+1,dp,aw,ah,su,n,wi,hi);\n \n aw[j]=false;\n su-=hi[i][j];\n }\n }\n ah[i]=false;\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "aaf943ebe567682271a521b44fc45bbc", "src_uid": "7348b5644f232bf377a4834eded42e4b", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.util.stream.*;\n\npublic class cfCEOI2019Day1B {\n\n\tstatic class HLD {\n\t\tint n, root;\n\n\t\tprivate int[][] g;\n\t\tprivate int[] sz;\n\t\tprivate int timePtr = 0;\n\n\t\t// parent of node, time -> time\n\t\tpublic int[] par;\n\n\t\t// tree traversal, time -> node\n\t\tint[] time2Node;\n\n\t\t// time when you get in/out of the node\n\t\t// Subtree of v has times [ v; rgh(v) )\n\t\tint[] node2Time; // node -> time\n\t\tint[] rgh; // time -> time\n\n\t\t// lft and order are inverse permutations\n\n\t\t// depth, time -> int\n\t\tint[] depth;\n\n\t\t// if chainInfo[v] < 0 then v is the head of chain with id =\n\t\t// (~chainInfo[v]), time->chainId\n\t\t// if chainInfo[v] >=0 then chainInfo[v] is the head of chain that v\n\t\t// belongs to, time->time\n\t\tprivate int[] chainInfo;\n\n\t\t// top-most node of the corresponding chain, chainId -> time\n\t\tint[] chainHead;\n\n\t\tint chainCnt = 0;\n\t\tprivate int[] buf;\n\n\t\tpublic HLD(int[] vs, int[] us, int root) {\n\t\t\tn = vs.length + 1;\n\t\t\tthis.root = root;\n\t\t\tif (vs.length != us.length) {\n\t\t\t\tthrow new AssertionError(\"vs.length != us.length\");\n\t\t\t}\n\t\t\tif (!(0 <= root && root < n)) {\n\t\t\t\tthrow new AssertionError(\"bad root\");\n\t\t\t}\n\n\t\t\t// Building the graph.\n\t\t\tint[] deg = new int[n];\n\t\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\t\tif (!(0 <= vs[i] && vs[i] < n && 0 <= us[i] && us[i] < n && vs[i] != us[i])) {\n\t\t\t\t\tthrow new AssertionError(\"bad node in edge\");\n\t\t\t\t}\n\t\t\t\tdeg[vs[i]]++;\n\t\t\t\tdeg[us[i]]++;\n\t\t\t}\n\t\t\tg = new int[n][];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tg[i] = new int[deg[i]];\n\t\t\t}\n\t\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\t\tint v = vs[i];\n\t\t\t\tint u = us[i];\n\t\t\t\tg[v][--deg[v]] = u;\n\t\t\t\tg[u][--deg[u]] = v;\n\t\t\t}\n\n\t\t\t// Find sizes/parents and reorder children.\n\t\t\tsz = new int[n];\n\t\t\tdfsSz(root, -1);\n\n\t\t\t// Find the chains/subtree ranges.\n\t\t\tpar = new int[n];\n\t\t\tpar[0] = -1;\n\t\t\t\n\t\t\tdepth = new int[n];\n\t\t\ttime2Node = new int[n];\n\t\t\tnode2Time = new int[n];\n\t\t\trgh = new int[n];\n\t\t\t\n\t\t\tchainHead = new int[n];\n\t\t\tchainHead[chainCnt] = 0;\n\t\t\t\n\t\t\tchainInfo = new int[n];\n\t\t\tchainInfo[0] = ~(chainCnt++);\n\t\t\t\n\t\t\tdfsChains(root, -1);\n\n\t\t\tchainHead = Arrays.copyOf(chainHead, chainCnt);\n\t\t\tbuf = new int[3 * chainCnt];\n\t\t}\n\n\t\t/**\n\t\t * @return list of triplets [chainId; pos1; pos2] in order corresponding\n\t\t * to the path from v to u
\n\t\t * pos1 <= pos2 = going down
\n\t\t * pos1 > pos2 = going up\n\t\t */\n\t\tpublic int[] getPath(int v, int u) {\n\t\t\tint headPtr = 0, tailPtr = buf.length;\n\t\t\tint chV = chainId(v), upV = chainHead[chV], chU = chainId(u), upU = chainHead[chU];\n\t\t\twhile (chV != chU) {\n\t\t\t\tif (depth[upV] > depth[upU]) {\n\t\t\t\t\tbuf[headPtr] = chV;\n\t\t\t\t\tbuf[headPtr + 1] = v - upV;\n\t\t\t\t\tbuf[headPtr + 2] = 0;\n\t\t\t\t\theadPtr += 3;\n\t\t\t\t\tv = par[upV];\n\t\t\t\t\tchV = chainId(v);\n\t\t\t\t\tupV = chainHead[chV];\n\t\t\t\t} else {\n\t\t\t\t\tbuf[tailPtr - 3] = chU;\n\t\t\t\t\tbuf[tailPtr - 2] = 0;\n\t\t\t\t\tbuf[tailPtr - 1] = u - upU;\n\t\t\t\t\ttailPtr -= 3;\n\t\t\t\t\tu = par[upU];\n\t\t\t\t\tchU = chainId(u);\n\t\t\t\t\tupU = chainHead[chU];\n\t\t\t\t}\n\t\t\t}\n\t\t\tint base = chainHead[chV];\n\t\t\tbuf[headPtr] = chV;\n\t\t\tbuf[headPtr + 1] = v - base;\n\t\t\tbuf[headPtr + 2] = u - base;\n\t\t\theadPtr += 3;\n\n\t\t\tSystem.arraycopy(buf, tailPtr, buf, headPtr, buf.length - tailPtr);\n\t\t\treturn Arrays.copyOf(buf, headPtr + buf.length - tailPtr);\n\t\t}\n\n\t\t// the length of chain #id\n\t\t// chainId -> int\n\t\tpublic int chainSz(int id) {\n\t\t\treturn (id == chainHead.length - 1 ? n : chainHead[id + 1]) - chainHead[id];\n\t\t}\n\n\t\t// the id of chain that node belongs to\n\t\t// time -> chainId\n\t\tpublic int chainId(int node) {\n\t\t\t// if node is not a chain's head, set node to the head\n\t\t\tif (chainInfo[node] >= 0) {\n\t\t\t\tnode = chainInfo[node];\n\t\t\t}\n\t\t\treturn ~chainInfo[node];\n\t\t}\n\n\t\t// the position of a node within its chain\n\t\t// time -> int\n\t\tpublic int chainPos(int t) {\n\t\t\tint x = chainInfo[t];\n\t\t\treturn x >= 0 ? t - x : 0;\n\t\t}\n\t\t\n\t\t// returns the NODE in the given chain at the given position\n\t\t// this is called getTime because you should only care\n\t\t// about \"times\" and not original node numbers\n\t\tpublic int getTime(int chainId, int chainPos) {\n\t\t\treturn chainHead[chainId] + chainPos;\n\t\t}\n\t\t\n\t\t// time -> boolean\n\t\tpublic boolean isLeaf(int t) {\n\t\t\treturn g[time2Node[t]].length == (t == 0 ? 0 : 1);\n\t\t}\n\n\t\tprivate void dfsSz(int v, int p) {\n\t\t\tsz[v] = 1;\n\t\t\tint[] adj = g[v];\n\t\t\tfor (int i = 0; i < adj.length; i++) {\n\t\t\t\tint u = adj[i];\n\t\t\t\tif (u == p) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tdfsSz(u, v);\n\t\t\t\tsz[v] += sz[u];\n\t\t\t\tif (adj[0] == p || sz[u] > sz[adj[0]]) {\n\t\t\t\t\tadj[i] = adj[0];\n\t\t\t\t\tadj[0] = u;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tprivate void dfsChains(int v, int p) {\n\t\t\tint tv = timePtr++;\n\t\t\ttime2Node[tv] = v;\n\t\t\tnode2Time[v] = tv;\n\n\t\t\tint[] adj = g[v];\n\t\t\tfor (int i = 0; i < adj.length; i++) {\n\t\t\t\tint u = adj[i];\n\t\t\t\tif (u == p) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tpar[timePtr] = tv;\n\t\t\t\tdepth[timePtr] = depth[tv] + 1;\n\t\t\t\tif (i == 0) {\n\t\t\t\t\tchainInfo[timePtr] = chainInfo[tv] >= 0 ? chainInfo[tv] : tv;\n\t\t\t\t} else {\n\t\t\t\t\tchainHead[chainCnt] = timePtr;\n\t\t\t\t\tchainInfo[timePtr] = ~(chainCnt++);\n\t\t\t\t}\n\t\t\t\tdfsChains(u, v);\n\t\t\t}\n\n\t\t\trgh[tv] = timePtr;\n\t\t}\n\t}\n\n\tvoid submit() {\n\t\tint n = nextInt();\n\t\tint q = nextInt();\n\t\tlong w = nextLong();\n\t\tint[] vs = new int[n - 1];\n\t\tint[] us = new int[n - 1];\n\t\tlong[] ws = new long[n - 1];\n\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\tvs[i] = nextInt() - 1;\n\t\t\tus[i] = nextInt() - 1;\n\t\t\tws[i] = nextLong();\n\t\t}\n\n\t\tHLD hld = new HLD(vs, us, 0);\n\t\t\n\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\tvs[i] = hld.node2Time[vs[i]];\n\t\t\tus[i] = hld.node2Time[us[i]];\n\t\t}\n\n\t\tint[] lft = hld.node2Time;\n\t\tint[] rgh = hld.rgh;\n\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\tif (vs[i] > us[i]) {\n\t\t\t\tint tmp = vs[i];\n\t\t\t\tvs[i] = us[i];\n\t\t\t\tus[i] = tmp;\n\t\t\t}\n\t\t}\n\n\t\tSegTree depths = new SegTree(n);\n\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\tdepths.addSegment(us[i], rgh[us[i]], ws[i]);\n\t\t}\n\n\t\tSegTree[] aux = new SegTree[hld.chainCnt];\n\t\tfor (int i = 0; i < aux.length; i++) {\n\t\t\taux[i] = new SegTree(hld.chainSz(i));\n\t\t}\n\n\t\tint[] chainHead = hld.chainHead;\n\t\tfor (int v = 0; v < n; v++) {\n\t\t\tif (hld.isLeaf(v)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tint ch = hld.chainId(v);\n\t\t\tint pos = hld.chainPos(v);\n\t\t\tint head = chainHead[ch];\n\n\t\t\tlong maxExceptChain = depths.getSegment(rgh[v + 1], rgh[v]);\n\t\t\tif (maxExceptChain < 0) {\n\t\t\t\taux[ch].addPoint(pos, -INF);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\taux[ch].addPoint(pos, maxExceptChain + depths.getPoint(head) - 2 * depths.getPoint(v));\n\t\t}\n\n\t\tlong last = 0;\n\t\twhile (q-- > 0) {\n\t\t\tint edgeIdx = nextInt();\n\t\t\tlong newW = nextLong();\n\t\t\tedgeIdx = (int) ((edgeIdx + last) % (n - 1));\n\t\t\tnewW = (newW + last) % w;\n\n//\t\t\tSystem.err.println(edgeIdx + \" \" + newW);\n//\t\t\tSystem.err.println(\"old: \" + Arrays.toString(ws));\n\n\t\t\tlong oldW = ws[edgeIdx];\n\t\t\tlong deltaW = newW - oldW;\n\n\t\t\tws[edgeIdx] = newW;\n\n//\t\t\tSystem.err.println(\"new: \" + Arrays.toString(ws));\n\n\t\t\t// update edge weight\n\t\t\t{\n\t\t\t\tint v = us[edgeIdx];\n\t\t\t\tdepths.addSegment(v, rgh[v], deltaW);\n\n\t\t\t\t// update relative depth and maxRelExceptChain for nodes below v\n\t\t\t\t// on its chain\n\t\t\t\tint ch = hld.chainId(v);\n\t\t\t\tint pos = hld.chainPos(v);\n\t\t\t\tif (pos != 0) {\n\t\t\t\t\taux[ch].addSegment(pos, hld.chainSz(ch), -deltaW);\n\t\t\t\t}\n\n\t\t\t\t// update maxRelExceptChain for last nodes on the chains\n\t\t\t\tint[] path = hld.getPath(0, v);\n\t\t\t\tfor (int i = 0; i < path.length - 3; i += 3) {\n\t\t\t\t\tint chainId = path[i];\n\t\t\t\t\tint headV = chainHead[chainId];\n\t\t\t\t\tint vPos = path[i + 2];\n\t\t\t\t\tv = hld.getTime(chainId, vPos);\n\t\t\t\t\tlong newVal = depths.getSegment(rgh[v + 1], rgh[v]) + depths.getPoint(headV) - 2\n\t\t\t\t\t\t\t* depths.getPoint(v);\n\n\t\t\t\t\taux[chainId].setPoint(vPos, newVal);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlong ans;\n\n\t\t\t// find diameter\n\t\t\t{\n\t\t\t\tint deepV = depths.maxPos();\n\t\t\t\tif (!hld.isLeaf(deepV)) {\n\t\t\t\t\tthrow new AssertionError(\"deepest node must be a leaf!\");\n\t\t\t\t}\n\t\t\t\tans = depths.getPoint(deepV);\n\t\t\t\tlong vDepth = ans;\n\n\t\t\t\tint[] path = hld.getPath(0, deepV);\n\t\t\t\tfor (int i = 0; i < path.length; i += 3) {\n\t\t\t\t\tint chainId = path[i];\n\t\t\t\t\tint headV = chainHead[chainId];\n\t\t\t\t\t// not last node on a chain, use aux seg tree\n\t\t\t\t\tans = Math.max(\n\t\t\t\t\t\t\tans,\n\t\t\t\t\t\t\taux[chainId].getSegment(0, path[i + 2])\n\t\t\t\t\t\t\t\t\t+ (vDepth - depths.getPoint(headV)));\n\n\t\t\t\t\tif (i == path.length - 3) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\t// last node on a chain\n\t\t\t\t\tint lastNode = hld.getTime(chainId, path[i + 2]);\n\t\t\t\t\tint nxtNode = chainHead[path[i + 3]];\n\t\t\t\t\tlong deepOther = Math.max(depths.getSegment(lastNode, nxtNode),\n\t\t\t\t\t\t\tdepths.getSegment(rgh[nxtNode], rgh[lastNode]));\n\t\t\t\t\tans = Math.max(ans, deepOther + vDepth - 2 * depths.getPoint(lastNode));\n\t\t\t\t}\n\t\t\t}\n\t\t\tout.println(ans);\n\t\t\tlast = ans;\n\t\t}\n\t}\n\n\tstatic final long INF = Long.MAX_VALUE / 3;\n\n\t// TODO: check with local parameters/without SegTree class at all?\n\tstatic class SegTree {\n\t\tstatic int ql, qr;\n\t\tstatic long delta;\n\t\tNode root;\n\n\t\tpublic SegTree(int n) {\n\t\t\troot = new Node(0, n);\n\t\t}\n\n\t\tpublic void addSegment(int ql, int qr, long delta) {\n\t\t\tif (ql == qr) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (ql > qr) {\n\t\t\t\tthrow new AssertionError(\"ql > qr\");\n\t\t\t}\n\t\t\tSegTree.ql = ql;\n\t\t\tSegTree.qr = qr;\n\t\t\tSegTree.delta = delta;\n\t\t\troot.add();\n\t\t}\n\n\t\t// TODO: can improve!\n\t\tpublic void addPoint(int idx, long delta) {\n\t\t\taddSegment(idx, idx + 1, delta);\n\t\t}\n\n\t\tpublic long getSegment(int ql, int qr) {\n\t\t\tif (ql == qr) {\n\t\t\t\treturn -INF;\n\t\t\t}\n\t\t\tif (ql > qr) {\n\t\t\t\tthrow new AssertionError(\"ql > qr\");\n\t\t\t}\n\t\t\tSegTree.ql = ql;\n\t\t\tSegTree.qr = qr;\n\t\t\treturn root.get();\n\t\t}\n\n\t\tpublic void setPoint(int idx, long val) {\n\t\t\tql = idx;\n\t\t\tdelta = val;\n\t\t\troot.setPoint();\n\t\t}\n\n\t\t// TODO: can improve!\n\t\tpublic long getPoint(int idx) {\n\t\t\treturn getSegment(idx, idx + 1);\n\t\t}\n\n\t\tpublic int maxPos() {\n\t\t\treturn root.maxPos();\n\t\t}\n\n\t\tstatic class Node {\n\t\t\tint l, r;\n\t\t\tNode left, right;\n\t\t\tlong add, max;\n\n\t\t\tlong getMax() {\n\t\t\t\treturn max + add;\n\t\t\t}\n\n\t\t\tpublic Node(int l, int r) {\n\t\t\t\tthis.l = l;\n\t\t\t\tthis.r = r;\n\t\t\t\tif (r - l > 1) {\n\t\t\t\t\tint m = (l + r) >> 1;\n\t\t\t\t\tleft = new Node(l, m);\n\t\t\t\t\tright = new Node(m, r);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tvoid add() {\n\t\t\t\tif (l >= qr || ql >= r) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (ql <= l && r <= qr) {\n\t\t\t\t\tadd += delta;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tleft.add();\n\t\t\t\tright.add();\n\t\t\t\tmax = Math.max(left.getMax(), right.getMax());\n\t\t\t}\n\n\t\t\tlong get() {\n\t\t\t\tif (l >= qr || ql >= r) {\n\t\t\t\t\treturn -INF;\n\t\t\t\t}\n\t\t\t\tif (ql <= l && r <= qr) {\n\t\t\t\t\treturn getMax();\n\t\t\t\t}\n\t\t\t\treturn Math.max(left.get(), right.get()) + add;\n\t\t\t}\n\n\t\t\tint maxPos() {\n\t\t\t\tif (r - l == 1) {\n\t\t\t\t\treturn l;\n\t\t\t\t}\n\t\t\t\treturn left.getMax() > right.getMax() ? left.maxPos() : right.maxPos();\n\t\t\t}\n\n\t\t\tvoid setPoint() {\n\t\t\t\tif (r - l == 1) {\n\t\t\t\t\tadd = 0;\n\t\t\t\t\tmax = delta;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tleft.add += add;\n\t\t\t\tright.add += add;\n\t\t\t\tadd = 0;\n\t\t\t\t(ql < left.r ? left : right).setPoint();\n\t\t\t\tmax = Math.max(left.getMax(), right.getMax());\n\t\t\t}\n\t\t}\n\t}\n\n\tvoid test() {\n\n\t}\n\n\tvoid stress() {\n\t\tfor (int tst = 0;; tst++) {\n\t\t\tif (false) {\n\t\t\t\tthrow new AssertionError();\n\t\t\t}\n\t\t\tSystem.err.println(tst);\n\t\t}\n\t}\n\n\tcfCEOI2019Day1B() throws IOException {\n\t\tif (System.getProperty(\"ONLINE_JUDGE\") == null) {\n\t\t\tis = new FileInputStream(\"in.txt\");\n\t\t} else {\n\t\t\tis = System.in;\n\t\t}\n\t\tout = new PrintWriter(System.out);\n\t\tsubmit();\n\t\t// stress();\n\t\t// test();\n\t\tout.close();\n\t}\n\n\tstatic final Random rng = new Random();\n\tstatic final int C = 5;\n\n\tstatic int rand(int l, int r) {\n\t\treturn l + rng.nextInt(r - l + 1);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew cfCEOI2019Day1B();\n\t}\n\n\tprivate InputStream is;\n\tPrintWriter out;\n\n\tprivate byte[] buf = new byte[1 << 14];\n\tprivate int bufSz = 0, bufPtr = 0;\n\n\tprivate int readByte() {\n\t\tif (bufSz == -1)\n\t\t\tthrow new RuntimeException(\"Reading past EOF\");\n\t\tif (bufPtr >= bufSz) {\n\t\t\tbufPtr = 0;\n\t\t\ttry {\n\t\t\t\tbufSz = is.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t\tif (bufSz <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[bufPtr++];\n\t}\n\n\tprivate boolean isTrash(int c) {\n\t\treturn c < 33 || c > 126;\n\t}\n\n\tprivate int skip() {\n\t\tint b;\n\t\twhile ((b = readByte()) != -1 && isTrash(b))\n\t\t\t;\n\t\treturn b;\n\t}\n\n\tString nextToken() {\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!isTrash(b)) {\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tString nextString() {\n\t\tint b = readByte();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!isTrash(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\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tchar nextChar() {\n\t\treturn (char) skip();\n\t}\n\n\tint nextInt() {\n\t\tint ret = 0;\n\t\tint b = skip();\n\t\tif (b != '-' && (b < '0' || b > '9')) {\n\t\t\tthrow new InputMismatchException();\n\t\t}\n\t\tboolean neg = false;\n\t\tif (b == '-') {\n\t\t\tneg = true;\n\t\t\tb = readByte();\n\t\t}\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tret = ret * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\tif (b != -1 && !isTrash(b)) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\treturn neg ? -ret : ret;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\n\tlong nextLong() {\n\t\tlong ret = 0;\n\t\tint b = skip();\n\t\tif (b != '-' && (b < '0' || b > '9')) {\n\t\t\tthrow new InputMismatchException();\n\t\t}\n\t\tboolean neg = false;\n\t\tif (b == '-') {\n\t\t\tneg = true;\n\t\t\tb = readByte();\n\t\t}\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tret = ret * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\tif (b != -1 && !isTrash(b)) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\treturn neg ? -ret : ret;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ddb55aded04372d1c4b73d9281d23608", "src_uid": "2c7349bc99e56b86a5c11b8c683b2b6c", "difficulty": null} {"lang": "Java 8", "source_code": "import java.util.*;\r\nimport java.io.*;\r\n//import java.math.BigInteger;\r\n \r\npublic class code{\r\n public static class Pair{\r\n int a;\r\n int b;\r\n Pair(int i,int j){\r\n a=i;\r\n b=j;\r\n }\r\n }\r\n\r\n public static int GCD(int a, int b)\r\n {\r\n if (b == 0)\r\n return a;\r\n return GCD(b, a % b);\r\n }\r\n\r\n public static void shuffle(int a[], int n)\r\n {\r\n for (int i = 0; i < n; i++) {\r\n\r\n // getting the random index\r\n int t = (int)Math.random() * a.length;\r\n\r\n // and swapping values a random index\r\n // with the current index\r\n int x = a[t];\r\n a[t] = a[i];\r\n a[i] = x;\r\n }\r\n }\r\n \r\n public static PrintWriter out = new PrintWriter(System.out);\r\n //@SuppressWarnings(\"unchecked\")\r\n public static void main(String[] arg) throws IOException{\r\n //Reader in=new Reader();\r\n \r\n //PrintWriter out = new PrintWriter(System.out);\r\n //Scanner in = new Scanner(System.in);\r\n FastScanner in=new FastScanner();\r\n int t=1;\r\n\r\n \r\n while(t-- > 0){\r\n String s=in.next();\r\n if(s.equals(\"0\") || s.equals(\"X\") || s.equals(\"_\")){\r\n out.println(1);\r\n continue;\r\n }\r\n char[] arr=s.toCharArray();\r\n\r\n int low=(int)Math.pow(10,s.length()-1);\r\n int high=(int)Math.pow(10,s.length())-25;\r\n while(low%25!=0) low++;\r\n int res=0;\r\n\r\n for(;low<=high;low+=25){\r\n String s1=Integer.toString(low);\r\n char[] c=s1.toCharArray();\r\n int count=1;\r\n char x='#';\r\n for(int i=0;i0;index-=index&(-index)) sum+=bit[index];\r\n return sum;\r\n }\r\n\r\n public int sum(int l,int r){\r\n return presum(r+1)-presum(l);\r\n }\r\n}\r\n\r\nclass FastScanner {\r\n \r\n private int BS = 1 << 16;\r\n private char NC = (char) 0;\r\n private byte[] buf = new byte[BS];\r\n private int bId = 0, size = 0;\r\n private char c = NC;\r\n private double cnt = 1;\r\n private BufferedInputStream in;\r\n\r\n public FastScanner() {\r\n in = new BufferedInputStream(System.in, BS);\r\n }\r\n\r\n public FastScanner(String s) {\r\n try {\r\n in = new BufferedInputStream(new FileInputStream(new File(s)), BS);\r\n } catch (Exception e) {\r\n in = new BufferedInputStream(System.in, BS);\r\n }\r\n }\r\n\r\n private char getChar() {\r\n while (bId == size) {\r\n try {\r\n size = in.read(buf);\r\n } catch (Exception e) {\r\n return NC;\r\n }\r\n if (size == -1) return NC;\r\n bId = 0;\r\n }\r\n return (char) buf[bId++];\r\n }\r\n\r\n public int nextInt() {\r\n return (int) nextLong();\r\n }\r\n\r\n public int[] nextInts(int N) {\r\n int[] res = new int[N];\r\n for (int i = 0; i < N; i++) {\r\n res[i] = (int) nextLong();\r\n }\r\n return res;\r\n }\r\n\r\n public long[] nextLongs(int N) {\r\n long[] res = new long[N];\r\n for (int i = 0; i < N; i++) {\r\n res[i] = nextLong();\r\n }\r\n return res;\r\n }\r\n\r\n public long nextLong() {\r\n cnt = 1;\r\n boolean neg = false;\r\n if (c == NC) c = getChar();\r\n for (; (c < '0' || c > '9'); c = getChar()) {\r\n if (c == '-') neg = true;\r\n }\r\n long res = 0;\r\n for (; c >= '0' && c <= '9'; c = getChar()) {\r\n res = (res << 3) + (res << 1) + c - '0';\r\n cnt *= 10;\r\n }\r\n return neg ? -res : res;\r\n }\r\n\r\n public double nextDouble() {\r\n double cur = nextLong();\r\n return c != '.' ? cur : cur + nextLong() / cnt;\r\n }\r\n\r\n public double[] nextDoubles(int N) {\r\n double[] res = new double[N];\r\n for (int i = 0; i < N; i++) {\r\n res[i] = nextDouble();\r\n }\r\n return res;\r\n }\r\n\r\n public String next() {\r\n StringBuilder res = new StringBuilder();\r\n while (c <= 32) c = getChar();\r\n while (c > 32) {\r\n res.append(c);\r\n c = getChar();\r\n }\r\n return res.toString();\r\n }\r\n\r\n public String nextLine() {\r\n StringBuilder res = new StringBuilder();\r\n while (c <= 32) c = getChar();\r\n while (c != '\\n') {\r\n res.append(c);\r\n c = getChar();\r\n }\r\n return res.toString();\r\n }\r\n\r\n public boolean hasNext() {\r\n if (c > 32) return true;\r\n while (true) {\r\n c = getChar();\r\n if (c == NC) return false;\r\n else if (c > 32) return true;\r\n }\r\n }\r\n}\r\n\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "094792a327cbc080881f1609d3664b7c", "src_uid": "4a905f419550a6c839992b40f1617af3", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "\r\n\r\n\r\nimport javax.swing.*;\r\nimport java.lang.reflect.Array;\r\nimport java.text.DecimalFormat;\r\nimport java.util.*;\r\nimport java.lang.*;\r\nimport java.io.*;\r\nimport java.math.*;\r\nimport java.util.stream.Stream;\r\n\r\n\r\n\r\n// Please name your class Main\r\npublic class Main {\r\n static FastScanner fs=new FastScanner();\r\n static class FastScanner {\r\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\r\n StringTokenizer st=new StringTokenizer(\"\");\r\n public String next() {\r\n while (!st.hasMoreElements())\r\n try {\r\n st=new StringTokenizer(br.readLine());\r\n } catch (IOException e) {\r\n e.printStackTrace();\r\n }\r\n return st.nextToken();\r\n }\r\n int Int() {\r\n return Integer.parseInt(next());\r\n }\r\n\r\n long Long() {\r\n return Long.parseLong(next());\r\n }\r\n\r\n String Str(){\r\n return next();\r\n }\r\n }\r\n\r\n\r\n public static void main (String[] args) throws java.lang.Exception {\r\n PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\r\n //reading /writing file\r\n //Scanner in=new Scanner(System.in);\r\n //Scanner in=new Scanner(new File(\"input.txt\"));\r\n //PrintWriter pr=new PrintWriter(\"output.txt\");\r\n\r\n\r\n int T=1;\r\n for(int t=0;t= 0) {\r\n dp[i][j] += dp[i - 1][j - cnt];\r\n dp[i][j] %= mod;\r\n if(dp[i][j] == 0){\r\n dp[i][j] += mod;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n long sums[][] = new long[dp.length][dp[0].length];\r\n for(int i = 0; i < dp.length;i++){\r\n int sum = 0;\r\n for(int j = 0; j < dp[0].length; j++){\r\n sum += dp[i][j];\r\n sum %= mod;\r\n if(sum == 0) sum += mod;\r\n sums[i][j] = sum;\r\n }\r\n }\r\n\r\n\r\n long fact[] = new long[3000];\r\n fact[0] = fact[1] = 1;\r\n for(int i = 2; i < fact.length;i++){\r\n fact[i] = fact[i - 1] * i;\r\n fact[i] %= mod;\r\n }\r\n\r\n long ncr[][] = new long[55][55];\r\n ncr[0][0]=1;\r\n for (int i=1;i= 0; i--) {\r\n int cnt = n - i;\r\n int pre = n - cnt;\r\n long com = (ncr[n][pre] * fact[pre]) % mod;\r\n long sum = 0;\r\n\r\n for(int dif = 1; dif < cnt; dif++){\r\n for(int inv = dif; inv < dp[0].length; inv++){\r\n if(dp[cnt - 1][inv] == 0){\r\n break;\r\n }\r\n if(inv - dif - 1 < 0)continue;\r\n long x = dp[cnt - 2][inv];\r\n long y = sums[cnt - 2][inv - dif - 1];\r\n x *= y;\r\n x %= mod;\r\n if(x == 0) x += mod;\r\n sum += x * (cnt - dif);\r\n sum %= mod;\r\n }\r\n }\r\n res += sum * com;\r\n res%=mod;\r\n }\r\n\r\n out.println(res % mod);\r\n }\r\n\r\n}\r\n\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c31adbc323b6d19c8c68c6eabcbd6b4f", "src_uid": "ae0320a57d73fab1d05f5d10fbdb9e1a", "difficulty": 2400.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\npublic class z3 { \n\tpublic static void main(String[] args) throws IOException {\t\n\t\tStreamTokenizer in;\n\t\tPrintWriter out;\n\t\tin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n\t\tout = new PrintWriter(new OutputStreamWriter(System.out));\n\n\t\t in.nextToken();\n\t\t int n=(int) in.nval;\n\tint[] a = new int[n];\n\tfor (int i=0;i=0;i--)\n\t\t {\n\t\t\t if (kol==0) {kol=1;st[kol]=Math.abs(a[i]);a[i]=-st[kol];} else\n\t\t\t {\n\t\t\t\t if (st[kol]==a[i]) kol-=1; else\n\t\t\t\t {kol+=1;st[kol]=Math.abs(a[i]);a[i]=-st[kol];}\n\t\t\t }\n\t\t }\n\t\t if (kol!=0) {out.println(\"NO\");out.flush();} else\n\t\t {\n\t\t\t out.println(\"YES\");\n\t\t\t for (int i=0;i=0;i--){\n\t\t\tfor(int j=0;j<2;j++){\n\t\t\t\tint [] a=new int [n+2];\n\t\t\t\tArrays.fill(a, inf);\n\t\t\t\tfor(int c=0;c<=l[i];c++){\n\t\t\t\t\tint best=seg[1-p][j].query(c+l[i+1]-l[i], c+l[i+1]-l[i]);\n\t\t\t\t\tbest=Math.min(best, 1+seg[1-p][1-j].query(l[i+1]-(c+r[i]-l[i]), l[i+1]-(c)));\n\t\t\t\t\tif(r[i]>l[i])\n\t\t\t\t\t\tbest=Math.min(best, 2+seg[1-p][j].query(c+1, c+r[i]-l[i]));\n\t\t\t\t\ta[c]=best;\n\t\t\t\t}\n\t\t\t\tseg[p][j]=new SparseTable(a);\n\t\t\t}\n\t\t\tp^=1;\n\t\t}\n\t\tp^=1;\n\t\tint ans=Math.min(seg[p][0].query(l[0], l[0]), seg[p][1].query(l[0], l[0]));\n\t\tif(ans>2*k)\n\t\t\tpw.println(\"Hungry\");\n\t\telse{\n\t\t\tpw.println(\"Full\");\n\t\t\tpw.println(ans);\n\t\t}\n\t\tpw.flush();\n\t\tpw.close();\n\t}\n\t\n\tstatic int inf=(int)1e7;\n\t\n\tstatic class SparseTable {\n\t\tint [] a;\n\t\tint [][] st;\n\t\t//st[i][j] --> minimum of sub array starting at index i and of length 2^j\n\t\tSparseTable(int [] a){\n\t\t\tint n=a.length;\n\t\t\tthis.a=a;\n\t\t\tint k=(int)Math.floor(Math.log(n)/Math.log(2))+1;\n\t\t\tst=new int [n][k];\n\t\t\tfor(int i=0;i0)\n\t\t{\t\n\t\t\tif(b%2==1)\n\t\t\t{\n\t\t\t\tx=(x*y)%mod;\n\t\t\t}\n\t\t\t\n\t\t\ty=(y*y)%mod;b=b/2;\t\n\t\t}\n\t\t\n\t\treturn x;\n\t}\n\t\n\tstatic void build()\n\t{\n\t\tc=new long[maxn][maxn];c[0][0]=1;\n\t\t\n\t\tfor(int i=1;i0)\n\t\t{\n\t\t\tif(b%2==1)\n\t\t\t{\n\t\t\t\tx=matrix_mul(x,y,n,n,n,n);\n\t\t\t}\n\t\t\t\n\t\t\ty=matrix_mul(y,y,n,n,n,n);b=b/2;\n\t\t}\n\t\t\n\t\treturn x;\n\t}\n\t\n public static void main(String args[]) throws Exception\n {\n\t\tbuild();long n=sc.nextLong();int k=sc.nextInt(),size=((k+1)*2)+1;\n\t\t\n\t\tlong[][] a=new long[size][size];\n\t\t\n\t\tfor(int j=0;j<=k;j++)\n\t\t{\n\t\t\tfor(int i=0,ctr=0;ctr<=j;i++,ctr++)\n\t\t\t{\n\t\t\t\ta[i][j]=c[j][ctr];\n\t\t\t}\n\t\t\t\n\t\t\tfor(int i=k+1,ctr=0;ctr<=j;i++,ctr++)\n\t\t\t{\n\t\t\t\ta[i][j]=(c[j][ctr]*pow(2,j-ctr))%mod;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor(int j=k+1;j<=2*k+1;j++)\n\t\t{\n\t\t\ta[j-(k+1)][j]=1;\n\t\t}\n\t\t\n\t\ta[k][size-1]=1;a[size-1][size-1]=1;\n\t\t\n\t\tif(n==1 || n==2)\n\t\t{\n\t\t\tlong[] f=new long[]{0,1,2};long res=0;\n\t\t\t\n\t\t\tfor(int i=1;i<=n;i++)\n\t\t\t{\n\t\t\t\tlong mul=(f[i]*pow(i,k))%mod;\n\t\t\t\t\n\t\t\t\tres=(res+mul)%mod;\n\t\t\t}\n\t\t\t\n\t\t\tout.println(res);\n\t\t}\n\t\t\n\t\telse\n\t\t{\n\t\t\tlong[][] now=matrix_pow(a,n-2,size),val=new long[1][size];\n\t\t\t\n\t\t\tfor(int i=0;i<=k;i++)\n\t\t\t{\n\t\t\t\tval[0][i]=(2*pow(2,i))%mod;\n\t\t\t}\n\t\t\t\n\t\t\tfor(int i=k+1;i<=2*k+1;i++)\n\t\t\t{\n\t\t\t\tval[0][i]=1;\n\t\t\t}\n\t\t\t\n\t\t\tval[0][size-1]=1;\n\t\t\t\n\t\t\tnow=matrix_mul(val,now,1,size,size,size);\n\t\t\t\n\t\t//\tout.println(Arrays.deepToString(val)+\" \"+Arrays.deepToString(now));\n\t\t\t\n\t\t\tlong res=(now[0][k]+now[0][size-1])%mod;\n\t\t\t\n\t\t\tout.println(res);\n\t\t}\n\t\t\n\t\tout.close();\n }\n}\nclass FastScanner\n{\n BufferedReader in;\n StringTokenizer st;\n\n public FastScanner(BufferedReader in) {\n this.in = in;\n }\n\t\n public String nextToken() throws Exception {\n while (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(in.readLine());\n }\n return st.nextToken();\n }\n\t\n\tpublic String next() throws Exception {\n\t\treturn nextToken().toString();\n\t}\n\t\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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a9dd696960de1f76c6d78828ef5a72b4", "src_uid": "14f50a111db268182e5927839a993118", "difficulty": null} {"lang": "Java 8", "source_code": "import java.io.* ;\nimport java.util.* ;\nimport java.util.stream.* ;\nimport java.text.* ;\nimport java.math.* ;\npublic class Codeshefcode{\n\tpublic static void main(String[] args) throws IOException{\n\t\tSolver Machine = new Solver() ;\n\t\tMachine.Solve() ;\t\n\t\tMachine.Finish();\n\t}\t\n}\nclass Mod{\n\tstatic long mod=1000000007 ;\n\tstatic long d(long a,long b){ return (a*MI(b))%mod ; }\n\tstatic long m(long a , long b){ return (a*b)%mod ; }\n\tstatic private long MI(long a ){ return pow(a,mod-2) ; }\n\tstatic long pow(long a,long b){\n\t\tif(b<0) return pow(MI(a),-b) ;\n\t\tlong val=a ; long ans=1 ;\n\t\twhile(b!=0){\n\t\t\tif((b&1)==1) ans = (ans*val)%mod ; \n\t\t\tval = (val*val)%mod ; \n\t\t\tb>>=1 ;\n\t\t}\n\t\treturn ans ;\n\t}\t\n}\nclass pair implements Comparable{\n\tlong x ; long y ; \n\tpair(long x,long y){ this.x=x ; this.y=y ;}\n\tpublic int compareTo(pair p){\n\t\treturn (this.xp.x ? 1 : (this.yp.y ? 1 : 0)))) ;\n\t}\n}\nclass Solver{\t\n\tFasterScanner ip = new FasterScanner(System.in) ;\t \n\tPrintWriter op = new PrintWriter(System.out) ;\n\tvoid Solve() throws IOException{\n\t\tint N = ip.i() ;\n\t\tint R = ip.i() ;\n\t\tint F[] = new int[N+1], S[] = new int[N+1] ;\n\t\tdouble P[] = new double[N+1] ;\n\t\tfor(int i=1 ; i<=N ; i++){\n\t\t\tF[i] = ip.i() ;\n\t\t\tS[i] = ip.i() ;\n\t\t\tP[i] = ip.i()/100.0 ;\n\t\t}\n\t\tdouble low = 0 ;\n\t\tdouble high = 1000000000l ;\n\t\tint itr=150 ;\n\t\twhile(itr--!=0){\n\t\t\tdouble k = (high+low)/2 ;\n\t\t\tdouble dp[][] = new double[N+1][R+1] ;\n\t\t\tfor(int i=(N-1) ; i>=0 ; i--)\n\t\t\t\tfor(int j=0 ; j<=R ; j++){\n\t\t\t\t\tif(j{\n}\n@SuppressWarnings(\"serial\")\nclass myset extends TreeSet{\n \n}\n@SuppressWarnings(\"serial\")\nclass mystack extends Stack{\n}\n@SuppressWarnings(\"serial\")\nclass mymap extends TreeMap{\n}\nclass FasterScanner { \n\tprivate InputStream mIs;\n\tprivate byte[] buf = new byte[1024];\n\tprivate int curChar,numChars;\n\tpublic FasterScanner() { this(System.in); } \n\tpublic FasterScanner(InputStream is) { mIs = is;} \n\tpublic int read() {\n\t\tif (numChars == -1) throw new InputMismatchException(); \n\t\tif (curChar >= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}\n\t\t\tif (numChars <= 0) return -1; \n\t\t}\n\t\treturn buf[curChar++];\n\t} \n\tpublic String nextLine(){\n\t\tint c = read();\n\t\twhile (isSpaceChar(c)) c = 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\tpublic String S(){\n\t\tint c = read();\n\t\twhile (isSpaceChar(c)) c = 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\tpublic long l(){\n\t\tint c = read();\n\t\twhile (isSpaceChar(c)) c = read(); \n\t\tint sgn = 1;\n\t\tif (c == '-') { sgn = -1 ; c = read() ; }\n\t\tlong res = 0;\n\t\tdo{\n\t\t\tif (c < '0' || c > '9') throw new InputMismatchException();\n\t\t\tres *= 10 ; res += c - '0' ; c = read();\n\t\t}while(!isSpaceChar(c));\n\t\treturn res * sgn;\n\t} \n\tpublic int i(){\n\t\tint c = read() ;\n\t\twhile (isSpaceChar(c)) c = read(); \n\t\tint sgn = 1;\n\t\tif (c == '-') { sgn = -1 ; c = read() ; }\n\t\tint res = 0;\n\t\tdo{\n\t\t\tif (c < '0' || c > '9') throw new InputMismatchException();\n\t\tres *= 10 ; res += c - '0' ; c = read() ;\n\t\t}while(!isSpaceChar(c));\n\t\treturn res * sgn;\n\t} \n\tpublic int[] ia(int n){\n\t\tint a[] = new int[n] ;\n\t\tfor(int i=0 ; i= 0; nballs--) {\n double[] next = new double[nballs + 1];\n double[] nprob = new double[nballs + 1];\n for (int red = 0; red <= nballs; red++) {\n if (cprob[red] < 1e-10 && cprob[red + 1] < 1e-10) continue;\n int black = nballs - red;\n double probred = cprob[red + 1] * (red + 1) / (cprob[red + 1] * (red + 1) + cprob[red] * (black + 1));\n nprob[red] = ((red + 1) * cprob[red + 1] + (black + 1) * cprob[red]) / (double) (nballs + 1);\n next[red] = Math.max(0, -c + probred * (1 + dp[red + 1]) + (1 - probred) * dp[red]);\n }\n dp = next;\n cprob = nprob;\n }\n out.printf(\"%.10f\\n\", dp[0]);\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 public InputReader(InputStream stream) {\n this.stream = stream;\n }\n public int read() {\n if (this.numChars == -1) {\n throw new InputMismatchException();\n } else {\n if (this.curChar >= this.numChars) {\n this.curChar = 0;\n try {\n this.numChars = this.stream.read(this.buf);\n } catch (IOException var2) {\n throw new InputMismatchException();\n }\n if (this.numChars <= 0) {\n return -1;\n }\n }\n return this.buf[this.curChar++];\n }\n }\n public int nextInt() {\n int c;\n for (c = this.read(); isSpaceChar(c); c = this.read()) {\n ;\n }\n byte sgn = 1;\n if (c == 45) {\n sgn = -1;\n c = this.read();\n }\n int res = 0;\n while (c >= 48 && c <= 57) {\n res *= 10;\n res += c - 48;\n c = this.read();\n if (isSpaceChar(c)) {\n return res * sgn;\n }\n }\n throw new InputMismatchException();\n }\n public static boolean isSpaceChar(int c) {\n return c == 32 || c == 10 || c == 13 || c == 9 || c == -1;\n }\n }\n static class OutputWriter {\n private final PrintWriter writer;\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n public void printf(String format, Object... objects) {\n writer.printf(format, objects);\n }\n public void close() {\n writer.close();\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1b81f039a0822154f5ec8aed7233012a", "src_uid": "44149b73a6b707c10c3eee75b5e090d2", "difficulty": 2800.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.StringTokenizer;\n\npublic class S_39I {\n BufferedReader in;\n StringTokenizer st;\n PrintWriter out;\n\n List> edges = new ArrayList>();\n\n int[] depth;\n\n int dfs_GCD(int index, int d) {\n if (depth[index] == 0) {\n depth[index] = d;\n int rv = 0;\n for (int next : edges.get(index)) {\n rv = gcd(rv, dfs_GCD(next, d + 1));\n }\n return rv;\n } else {\n return d - depth[index];\n }\n }\n\n private static int gcd(int a, int b) {\n a = Math.abs(a);\n b = Math.abs(b);\n while (b != 0) {\n int t = a % b;\n a = b;\n b = t;\n }\n return a;\n }\n\n void solve() throws IOException {\n int n = nextInt();\n int m = nextInt();\n for (int i = 0; i < n; ++i) {\n edges.add(new ArrayList());\n }\n for (int i = 0; i < m; ++i) {\n int s = nextInt() - 1;\n int e = nextInt() - 1;\n edges.get(s).add(e);\n }\n depth = new int[n];\n int gcd = dfs_GCD(0, 1);\n List ans = new ArrayList();\n for (int i = 0; i < n; ++i) {\n if (depth[i] % gcd == depth[0] % gcd && depth[i] != 0) {\n ans.add(i + 1);\n }\n }\n out.println(gcd);\n out.println(ans.size());\n for (int i : ans) {\n out.print(i);\n out.print(\" \");\n }\n }\n\n public void run() throws IOException {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n eat(\"\");\n solve();\n out.close();\n in.close();\n }\n\n void eat(String s) {\n st = new StringTokenizer(s);\n }\n\n String next() throws IOException {\n while (!st.hasMoreTokens()) {\n String line = in.readLine();\n if (line == null) {\n return null;\n }\n eat(line);\n }\n return st.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n public static void main(String[] args) throws IOException {\n new S_39I().run();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "64142620056310aee246c8f2634bd542", "src_uid": "e13228fcdaa1c218581606ddfe186d52", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "//package bubblecup9f;\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 A4 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tfinal int[] enigma = {\n\t\t\t3,0,0,0,360000003,0,0,0,968000007,0,0,0,983104007,0,0,0,276300802,0,0,0,908880288,0,0,0,444835368,0,0,0,538693517,0,0,0,343523648,0,0,0,438833891,0,0,0,20731495,0,0,0,19584286,0,0,0,759832111,0,0,0,651525034,0,0,0,755385288,0,0,0,149123809,0,0,0,908400457,0,0,0,588389874,0,0,0,420891682,0,0,0,191110322,0,0,0,804566578,0,0,0,700775946,0,0,0,978624792,0,0,0,740628576,0,0,0,366202373,0,0,0,610588828,0,0,0,181897771,0,0,0,479447743,0,0,0,215576012,0,0,0,350582471,0,0,0,590380104,0,0,0,443601358,0,0,0,590959191,0,0,0,707678114,0,0,0,731215473,0,0,0,619380084,0,0,0,57357138,0,0,0,351723583,0,0,0,246524320,0,0,0,533368614,0,0,0,214898245,0,0,0,179694662,0,0,0,954595219,0,0,0,630179967,0,0,0,531947723,0,0,0,727424716,0,0,0,552708818,0,0,0,557144116,0,0,0,226321849,0,0,0,867622522,0,0,0,858592418\n\t};\n\t\n\t// 1 2 3 4 5\n\t// 2 3 5 8 13\n\t// 1 1 \n\tvoid solve()\n\t{\n\t\tint K = ni();\n\t\tlong[][] co = new long[K+3][K+3];\n\t\tlong[] F = new long[300];\n\t\tF[0] = 0; F[1] = 1;\n\t\tint mod = 1000000007;\n\t\tfor(int i = 2;i < 300;i++){\n\t\t\tF[i] = F[i-1] + F[i-2];\n\t\t\tif(F[i] >= mod)F[i] -= mod;\n\t\t}\n\t\tlong ret = 0;\n\t\t\n\t\tlong invf = 1;\n\t\tfor(int i = 1;i <= K;i++)invf = invf * i % mod;\n\t\t\n\t\tlong[] cok = new long[K+1];\n\t\tcok[0] = invl(invf, mod);\n\t\tfor(int i = 0;i < K;i++){\n\t\t\tfor(int j = i;j >= 0;j--){\n\t\t\t\tcok[j+1] += cok[j];\n\t\t\t\tif(cok[j+1] >= mod)cok[j+1] -= mod;\n\t\t\t\tcok[j] = -cok[j] * i;\n\t\t\t\tcok[j] %= mod;\n\t\t\t\tif(cok[j] < 0)cok[j] += mod;\n\t\t\t}\n\t\t}\n\t\t\n\t\tlong L = nl(), R = nl();\n\t\tlong[] hi = new long[K+3];\n\t\tArrays.fill(hi, 1);\n\t\t\n\t\tfor(int i = 0;i < K+2;i++){\n\t\t\tfor(int j = 0;j <= i;j++){\n\t\t\t\tif(i == j || j == 0){\n\t\t\t\t\tco[i][j] = 1;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tco[i][j] = F[i-j-1] * co[i-1][j-1] + F[j+1] * co[i-1][j];\n\t\t\t\tco[i][j] %= mod;\n\t\t\t}\n\t\t\tif(i >= 1){\n\t\t\t\tlong[] f = new long[i+2];\n\t\t\t\tfor(int j = 0;j < i+1;j++){\n\t\t\t\t\tf[i-j] = (j&3) == 0 || (j&3) == 3 ? co[i][j] : mod-co[i][j];\n\t\t\t\t}\n\t\t\t\tfor(int j = i;j >= 0;j--){\n\t\t\t\t\tf[j+1] += f[j];\n\t\t\t\t\tif(f[j+1] >= mod)f[j+1] -= mod;\n\t\t\t\t\tf[j] = mod-f[j];\n\t\t\t\t\tif(f[j] == mod)f[j] = 0;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tlong[] xo = new long[f.length-1];\n\t\t\t\tfor(int j = 0;j < f.length-1;j++){\n\t\t\t\t\txo[j] = mod-f[j];\n\t\t\t\t}\n\t\t\t\tlong[] cum = new long[xo.length];\n\t\t\t\tfor(int j = 0;j < xo.length;j++){\n\t\t\t\t\tcum[j] += hi[j];\n\t\t\t\t\tif(cum[j] >= mod)cum[j] -= mod;\n\t\t\t\t\tif(j+1 < xo.length){\n\t\t\t\t\t\tcum[j+1] += cum[j];\n\t\t\t\t\t\tif(cum[j+1] >= mod)cum[j+1] -= mod;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tm2 = null;\n\t\t\t\tlong X = 2000000016L;\n\t\t\t\tif(i == 1){\n\t\t\t\t\tret += (f(cum, lrx(xo, R+2, mod)) - f(cum, lrx(xo, L+1, mod))) * cok[i-1];\n\t\t\t\t}else{\n\t\t\t\t\tlong lret = 0;\n\t\t\t\t\tlret += f(cum, lrx(xo, (R+2)%X, mod)) + (long)enigma[i-1]*((R+2)/X)%mod;\n\t\t\t\t\tlret -= f(cum, lrx(xo, (L+1)%X, mod)) + (long)enigma[i-1]*((L+1)/X)%mod;\n\t\t\t\t\tlret %= mod;\n\t\t\t\t\tif(lret < 0)lret += mod;\n\t\t\t\t\tret += lret * cok[i-1];\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tret %= mod;\n\t\t\t\tfor(int j = 0;j <= K+2;j++){\n\t\t\t\t\thi[j] = hi[j] * F[j] % mod;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif(ret < 0)ret += mod;\n\t\tout.println(ret);\n\t}\n\t\n\tpublic static long f(long[] a, long[] co)\n\t{\n\t\tlong big = 8L*mod*mod;\n\t\tlong s = 0;\n\t\tfor(int i = 0;i < co.length;i++){\n\t\t\ts += co[i] * a[i];\n\t\t\tif(s >= big)s -= big;\n\t\t}\n\t\treturn s % mod;\n\t}\n\t\n\tpublic static int mod = 1000000007;\n\t\n\tstatic long[][] m2;\n\t\n\tstatic long[] temp = new long[500];\n\t\n\tpublic static long[] lrx(long[] co, long n, int mod)\n\t{\n\t\tlong BIG = (Long.MAX_VALUE - 2L*mod*mod)/mod*mod;\n\t\tint m = co.length;\n\t\tif(m == 1){\n\t\t\tlong ret = 1;\n\t\t\tlong mul = co[0];\n\t\t\tfor(;n > 0;n >>>= 1){\n\t\t\t\tif((n&1)==1){\n\t\t\t\t\tret = ret * mul % mod;\n\t\t\t\t}\n\t\t\t\tmul = mul * mul % mod;\n\t\t\t}\n\t\t\treturn new long[]{ret};\n\t\t}\n\t\t\n\t\tif(m2 == null){\n\t\t\tm2 = new long[m][m-1];\n\t\t\tfor(int j = 0;j < m;j++){\n\t\t\t\tm2[j][0] = co[j];\n\t\t\t}\n\t\t\tfor(int i = 1;i < m-1;i++){\n\t\t\t\tfor(int j = 0;j < m;j++){\n\t\t\t\t\tlong x = m2[m-1][i-1] * co[j];\n\t\t\t\t\tif(j-1 >= 0)x += m2[j-1][i-1];\n\t\t\t\t\tm2[j][i] = x % mod;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tlong[] ret = new long[m];\n\t\tret[0] = 1;\n\t\tlong up = n;\n\t\tint sh = 0;\n\t\twhile(up > m){\n\t\t\tup>>>=1;\n\t\t\tsh++;\n\t\t}\n\t\tfor(int j = 0;j < up;j++){\n\t\t\tfor(int i = 0;i < m;i++)temp[i] = ret[m-1] * co[i];\n\t\t\tfor(int i = 1;i < m;i++)temp[i] += ret[i-1];\n\t\t\tfor(int i = 0;i < m;i++)ret[i] = temp[i] % mod;\n\t\t}\n\t\t\n//\t\tfor(int l = 64-Long.numberOfLeadingZeros(n);l >= 0;l--){\n\t\tfor(int l = sh;l >= 0;l--){\n\t\t\tif(n<<~l<0 && l < sh){\n\t\t\t\tfor(int i = 0;i < m;i++)temp[i] = ret[m-1] * co[i];\n\t\t\t\tfor(int i = 1;i < m;i++)temp[i] += ret[i-1];\n\t\t\t\tfor(int i = 0;i < m;i++)ret[i] = temp[i] % mod;\n\t\t\t}\n\t\t\tif(l > 0){\n\t\t\t\tArrays.fill(temp, 0L);\n\t\t\t\tfor(int i = 0;i < m;i++){\n\t\t\t\t\ttemp[i+i] += ret[i] * ret[i];\n\t\t\t\t\tif(temp[i+i] >= BIG)temp[i+i] -= BIG;\n\t\t\t\t\tfor(int j = 0;j < i;j++){\n\t\t\t\t\t\ttemp[i+j] += ret[i] * ret[j] * 2L;\n\t\t\t\t\t\tif(temp[i+j] >= BIG)temp[i+j] -= BIG;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor(int i = 0;i < 2*m-1;i++)temp[i] %= mod;\n\t\t\t\tfor(int i = 0;i < m;i++){\n\t\t\t\t\tlong s = temp[i];\n\t\t\t\t\tfor(int j = m;j < 2*m-1;j++){\n\t\t\t\t\t\ts += temp[j] * m2[i][j-m];\n\t\t\t\t\t\tif(s >= BIG)s -= BIG;\n\t\t\t\t\t}\n\t\t\t\t\tret[i] = s % mod;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tpublic static long invl(long a, long mod) {\n\t\tlong b = mod;\n\t\tlong p = 1, q = 0;\n\t\twhile (b > 0) {\n\t\t\tlong c = a / b;\n\t\t\tlong d;\n\t\t\td = a;\n\t\t\ta = b;\n\t\t\tb = d % b;\n\t\t\td = p;\n\t\t\tp = q;\n\t\t\tq = d - c * q;\n\t\t}\n\t\treturn p < 0 ? p + mod : p;\n\t}\n\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 A4().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tprivate int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "53efc8ab4b72b98e83a20b26d9e02f22", "src_uid": "dee552588e1281c2523868cd4090b46f", "difficulty": 2900.0} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class round51D {\n\tpublic static void main(String args[]) throws Exception{\n\t\tcf55D tmp=new cf55D();\n\t\ttmp.solve();\n\t}\n}\nclass cf55D {\n\tfinal static int N=20;\n\tfinal static int mod=2520;\n\tfinal static int M=(1<<8);\n\tlong dp[][][]=new long[N][M][mod];\n\tArrayList dig=new ArrayList();\n\tint t;\n\tlong l,r;\n\tvoid init(long num) {\n\t\tlong xx=num;\n\t\twhile(xx>0) {\n\t\t\tint y=(int)xx%10;\n\t\t\tdig.add(y);\n\t\t\txx/=10;\n\t\t}\n\t\tfor(int i=0;i=2) stt|=(1<<(i-2));\n\t\t\tres+=calc(cont-1,stt,(re*10+i)%mod,(limit==1&&i==bound? 1:0));\n\t\t}\n\t\tif(limit==0) dp[cont][st][re]=res;\n\t\treturn res;\n\t}\n\tvoid solve() throws Exception{\n\t\t//System.setIn(new BufferedInputStream(new FileInputStream(\"in.txt\")));\n\t\tScanner in=new Scanner(System.in);\n\t\tt=in.nextInt();\n\t\tfor(int i=0;i x0s = new ArrayList<>();\n\n long D = B * B - (long) n * C;\n if (D >= 0) {\n if (D == 0) {\n if ((-B % (long) n) == 0) {\n x0s.add((-B) / (long) n);\n }\n } else {\n long rd = (long) Math.sqrt(D);\n if (rd * rd == D) {\n if ((-B - rd) % (long) n == 0) {\n x0s.add((-B - rd) / (long) n);\n }\n if ((-B + rd) % (long) n == 0) {\n x0s.add((-B + rd) / (long) n);\n }\n }\n }\n }\n\n out.printLine(x0s.size());\n for (long x0 : x0s) {\n for (int i = 0; i < n; i++) {\n out.print(d[i] + x0 + \" \");\n }\n out.printLine();\n }\n }\n\n int pow(int a, int b, int p) {\n int ret = 1;\n for (; b > 0; b >>= 1) {\n if ((b & 1) == 1) {\n ret = (int) ((long) ret * a % p);\n }\n a = (int) ((long) a * a % p);\n }\n return ret;\n }\n\n int primitiveRoot(int p) {\n loop:\n for (int i = 2; ; i++) {\n for (int j = 2; j * j <= p - 1; j++) {\n if ((p - 1) % j != 0) {\n continue;\n }\n if (pow(i, (p - 1) / j, p) == 1) {\n continue loop;\n }\n if (pow(i, j, p) == 1) {\n continue loop;\n }\n }\n return i;\n }\n }\n\n int[] chirp(int[] a, int[] pz, int p) {\n int n = a.length;\n // pz[1] has order 2 * n modulo prime p\n\n a = a.clone();\n for (int i = 0; i < n; i++) {\n a[i] %= p;\n }\n\n int[] one = new int[n];\n for (int i = 0; i < n; i++) {\n one[i] = (int) ((long) a[i] * pz[(int) ((long) i * i % (2 * n))] % p);\n }\n\n int[] two = new int[2 * n - 1];\n for (int i = 0; i <= 2 * n - 2; i++) {\n two[i] = pz[Math.floorMod(-(long) (n - 1 - i) * (n - 1 - i), 2 * n)];\n }\n\n int[] prod = mult(one, two, p);\n\n prod = Arrays.copyOfRange(prod, n - 1, 2 * n - 1);\n for (int i = 0; i < n; i++) {\n prod[i] = (int) ((long) prod[i] * pz[(int) ((long) i * i % (2 * n))] % p);\n }\n\n return prod;\n // returns polynomial a modulo p at points 1, rootZ^2, rootZ^4, ...\n }\n\n int makeInt(int x, int p) {\n return x < p / 2 ? x : x - p;\n }\n\n int[] makeInvPows(int[] a) {\n int[] b = new int[a.length];\n b[0] = a[0];\n for (int i = 1, j = a.length - 1; i < a.length; i++, j--) {\n b[i] = a[j];\n }\n return b;\n }\n\n static int nextPowerOf2(int x) {\n return x == 1 ? 1 : Integer.highestOneBit(x - 1) << 1;\n }\n\n static double[][] foo(int[] intV, int len, int L) {\n // pack into one complex vector\n double[] f = new double[len << 1];\n for (int i = 0; i < intV.length; i++) {\n f[i << 1] = intV[i] % L;\n f[i << 1 | 1] = intV[i] / L;\n }\n\n fft(f, false);\n\n // unpack\n double[] f1 = new double[len << 1];\n double[] f2 = new double[len << 1];\n\n // LEN MUST BE A POWER OF 2!!!\n int zzz = (len << 1) - 1;\n for (int i = 0; i < len << 1; i += 2) {\n int j = (-i) & zzz;\n f1[i] = .5 * (f[i] + f[j]);\n f1[i + 1] = .5 * (f[i + 1] - f[j + 1]);\n f2[i] = .5 * (f[i + 1] + f[j + 1]);\n f2[i + 1] = .5 * (f[j] - f[i]);\n }\n\n return new double[][]{f1, f2};\n }\n\n public static int[] mult(int[] a, int[] b, int pMod) {\n\n int k = (int) (Math.sqrt(pMod) + 1);\n int k2 = k * k % pMod;\n\n int len = nextPowerOf2(a.length + b.length - 1);\n int len2 = len << 1;\n\n double[][] fA = foo(a, len, k);\n double[][] fB = foo(b, len, k);\n\n double[][] invF = new double[2][len2];\n\n for (int ia = 0; ia < 2; ia++) {\n for (int ib = 0; ib < 2; ib++) {\n\n double[] r = invF[(ia + ib) >> 1];\n double[] p = fA[ia];\n double[] q = fB[ib];\n\n if (((ia + ib) & 1) == 0) {\n for (int i = 0; i < len2; i += 2) {\n r[i] += p[i] * q[i] - p[i + 1] * q[i + 1];\n r[i + 1] += p[i] * q[i + 1] + p[i + 1] * q[i];\n }\n\n } else {\n for (int i = 0; i < len2; i += 2) {\n r[i] -= p[i] * q[i + 1] + p[i + 1] * q[i];\n r[i + 1] += p[i] * q[i] - p[i + 1] * q[i + 1];\n }\n }\n\n }\n }\n\n fft(invF[0], true);\n fft(invF[1], true);\n\n int[] ret = new int[len];\n\n for (int i = 0; i < len2; i += 2) {\n//\t\t\tlong v0 = Math.round(invF[0][i]) % P;\n//\t\t\tlong v1 = Math.round(invF[0][i + 1]) % P * L % P;\n//\t\t\tlong v2 = Math.round(invF[1][i]) % P * L2 % P;\n long v0 = (long) (invF[0][i] + .5);\n long v1 = ((long) (invF[0][i + 1] + .5)) % pMod * k;\n long v2 = ((long) (invF[1][i] + .5)) % pMod * k2;\n ret[i >> 1] = (int) ((v0 + v1 + v2) % pMod);\n }\n\n return ret;\n }\n\n public static void fft(double[] v, boolean invert) {\n int n2 = v.length;\n int n = n2 >> 1;\n int logN = Integer.numberOfTrailingZeros(n);\n prepareArrays(logN);\n int[] rev = rev2D[logN];\n\n for (int i = 0; i < n2; i += 2) {\n int j = rev[i >> 1] << 1;\n if (i < j) {\n double t = v[i];\n v[i] = v[j];\n v[j] = t;\n t = v[i + 1];\n v[i + 1] = v[j + 1];\n v[j + 1] = t;\n }\n }\n\n double conj = invert ? -1 : 1;\n\n for (int len = 2, row = 0; len <= n; len <<= 1, row++) {\n double[] pow = pow2D[row];\n for (int i = 0; i < n; i += len) {\n for (int j1 = i << 1, j2 = j1 + len, k = 0; k < len; j1 += 2, j2 += 2, k += 2) {\n double uA = v[j1];\n double uB = v[j1 + 1];\n\n double mRe = pow[k];\n double mIm = pow[k + 1] * conj;\n\n double vA = v[j2] * mRe - v[j2 + 1] * mIm;\n double vB = v[j2] * mIm + v[j2 + 1] * mRe;\n\n v[j1] = uA + vA;\n v[j1 + 1] = uB + vB;\n v[j2] = uA - vA;\n v[j2 + 1] = uB - vB;\n }\n }\n }\n if (invert) {\n for (int i = 0; i < n2; i++) {\n v[i] /= n;\n }\n }\n }\n\n static void prepareArrays(int n) {\n if (rev2D.length < n + 1) {\n rev2D = Arrays.copyOf(rev2D, n + 1);\n }\n\n if (rev2D[n] == null) {\n int[] tmp = rev2D[n] = new int[1 << n];\n for (int i = 0; i < (1 << n); i++) {\n tmp[i] = (tmp[i >> 1] >> 1) | ((i & 1) << (n - 1));\n }\n }\n\n int oldN = pow2D.length;\n\n if (oldN >= n) {\n return;\n }\n\n pow2D = Arrays.copyOf(pow2D, n);\n\n for (int i = oldN; i < n; i++) {\n double angle = Math.PI / (1 << i);\n\n double mRe = Math.cos(angle);\n double mIm = Math.sin(angle);\n\n double[] dst = pow2D[i] = new double[2 << i];\n double[] src = pow2D[i - 1];\n\n for (int j = 0; j < 1 << i; j += 2) {\n double re = src[j];\n double im = src[j + 1];\n\n dst[j << 1] = re;\n dst[j << 1 | 1] = im;\n dst[j << 1 | 2] = re * mRe - im * mIm;\n dst[j << 1 | 3] = re * mIm + im * mRe;\n }\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() {\n writer.println();\n }\n\n public void close() {\n writer.close();\n }\n\n public void printLine(int i) {\n writer.println(i);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "2b7ac74a640dfe42527b4e1593eceff2", "src_uid": "d8c531799874ce5bf5443aba1d34b26d", "difficulty": 3300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class D {\n\n public static void main(String[] args) {\n FastReader scan = new FastReader();\n PrintWriter out = new PrintWriter(System.out);\n Task solver = new Task();\n int t = 1;\n while (t --> 0) solver.solve(1, scan, out);\n out.close();\n }\n\n static class Task {\n static char[] a, b;\n static ArrayDeque queue = new ArrayDeque<>();\n static boolean[][][] found;\n static State ans = null;\n\n public void solve(int testNumber, FastReader scan, PrintWriter out) {\n a = scan.next().toCharArray();\n b = scan.next().toCharArray();\n queue.addLast(new State(0, 0, 0, 'N'));\n found = new boolean[a.length+1][b.length+1][a.length+b.length+1];\n while(!queue.isEmpty()) {\n State p = queue.pollFirst();\n if(p.x == a.length && p.y == b.length && p.z == 0) {\n ans = p;\n break;\n }\n State open = next(p, '(');\n if(!found[open.x][open.y][open.z]) {\n queue.addLast(open);\n found[open.x][open.y][open.z] = true;\n }\n if(p.z == 0) continue;\n State closed = next(p, ')');\n if(!found[closed.x][closed.y][closed.z]) {\n queue.addLast(closed);\n found[closed.x][closed.y][closed.z] = true;\n }\n }\n StringBuilder res = new StringBuilder();\n while(ans.prev != null) {\n res.append(ans.curr);\n ans = ans.prev;\n }\n out.println(res.reverse());\n }\n\n static State next(State prev, char curr) {\n State ret = new State(prev.x, prev.y, prev.z, curr);\n if(ret.x != a.length && a[ret.x] == curr) ret.x++;\n if(ret.y != b.length && b[ret.y] == curr) ret.y++;\n ret.z += curr == '(' ? 1 : -1;\n ret.prev = prev;\n return ret;\n }\n\n static class State {\n int x, y, z;\n State prev = null;\n char curr;\n public State(int a, int b, int c, char d) {\n x = a;\n y = b;\n z = c;\n curr = d;\n }\n }\n\n }\n\n static void shuffle(int[] a) {\n Random get = new Random();\n for (int i = 0; i < a.length; i++) {\n int r = get.nextInt(a.length);\n int temp = a[i];\n a[i] = a[r];\n a[r] = temp;\n }\n }\n\n static void shuffle(long[] a) {\n Random get = new Random();\n for (int i = 0; i < a.length; i++) {\n int r = get.nextInt(a.length);\n long temp = a[i];\n a[i] = a[r];\n a[r] = temp;\n }\n }\n\n static class FastReader {\n BufferedReader br;\n StringTokenizer st;\n\n public FastReader() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n public FastReader(String s) throws FileNotFoundException {\n br = new BufferedReader(new FileReader(new File(s)));\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "df39fb676dd79cfd5321c40917f465bb", "src_uid": "cc222aab45b3ad3d0e71227592c883f1", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Iterator;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.NoSuchElementException;\nimport java.io.InputStream;\n\n/**\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 TaskD solver = new TaskD();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskD {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n final int inf = 1000;\n int n, m;\n int[][] dist;\n IntArrayList[] gr;\n\n n = in.readInt();\n m = in.readInt();\n// n = 400;\n\n dist = new int[n][n];\n ArrayUtils.fill(dist, inf);\n gr = new IntArrayList[n];\n for (int v = 0; v < n; v++) {\n dist[v][v] = 0;\n gr[v] = new IntArrayList();\n }\n\n for (int iter = 0; iter < m; iter++) {\n int a = in.readInt() - 1;\n int b = in.readInt() - 1;\n dist[a][b] = dist[b][a] = 1;\n gr[a].add(b);\n gr[b].add(a);\n }\n\n// for (int a = 0; a < n; a++) {\n// for (int b = a + 1; b < n; b++) {\n// dist[a][b] = dist[b][a] = 1;\n// gr[a].add(b);\n// gr[b].add(a);\n// }\n// }\n\n for (int k = 0; k < n; k++) {\n for (int v = 0; v < n; v++) {\n for (int to = 0; to < n; to++) {\n dist[v][to] = Math.min(dist[v][to], dist[v][k] + dist[k][to]);\n }\n }\n }\n\n boolean[] used = new boolean[n];\n IntArrayList citiesBear0 = new IntArrayList(n);\n int szCitiesBear1;\n int[] citiesBear1 = new int[n];\n\n double dp = 0;\n for (int v0 = 0; v0 < n; v0++) {\n double dp_V0 = 0;\n for (int d0 = 0; d0 < n; d0++) {\n\n while (0 < citiesBear0.size()) {\n citiesBear0.popLast();\n }\n szCitiesBear1 = 0;\n Arrays.fill(used, false);\n\n for (int cityBear0 = 0; cityBear0 < n; cityBear0++) {\n if (dist[v0][cityBear0] == d0) {\n citiesBear0.add(cityBear0);\n for (int cityBear1 : gr[cityBear0]) {\n if (!used[cityBear1]) {\n used[cityBear1] = true;\n citiesBear1[szCitiesBear1++] = cityBear1;\n }\n }\n }\n }\n\n if (citiesBear0.size() == 0) {\n continue;\n }\n\n double dp_V0_D0 = 0;\n double coef = 1. / citiesBear0.size();\n if (d0 != 0) {\n double[] probV = new double[n];\n for (int b0 : citiesBear0) {\n double invSize = 1. / gr[b0].size();\n for (int b1 : gr[b0]) {\n probV[b1] += coef * invSize;\n }\n }\n\n\n double[] probD = new double[n];\n for (int v1 = 0; v1 < n; v1++) {\n int[] dist_v1 = dist[v1];\n for (int i = 0; i < szCitiesBear1; i++) {\n int b1 = citiesBear1[i];\n int d1 = dist_v1[b1];\n probD[d1] = max(probD[d1], probV[b1]);\n }\n double dp_V0_D0_V1 = 0;\n for (int i = 0; i < szCitiesBear1; i++) {\n int b1 = citiesBear1[i];\n int d1 = dist_v1[b1];\n dp_V0_D0_V1 += probD[d1];\n probD[d1] = 0;\n }\n dp_V0_D0 = max(dp_V0_D0, dp_V0_D0_V1);\n }\n }\n dp_V0_D0 = max(dp_V0_D0, coef);\n\n dp_V0 += ((double) citiesBear0.size() / n) * dp_V0_D0;\n }\n dp = max(dp, dp_V0);\n }\n out.printFormat(\"%.12f\", dp);\n out.printLine();\n }\n\n static private double max(double a, double b) {\n return a < b ? b : a;\n// return Math.max(a, b);\n }\n\n }\n\n static interface IntStream extends Iterable, Comparable {\n public IntIterator intIterator();\n\n default public Iterator iterator() {\n return new Iterator() {\n private IntIterator it = intIterator();\n\n public boolean hasNext() {\n return it.isValid();\n }\n\n public Integer next() {\n int result = it.value();\n it.advance();\n return result;\n }\n };\n }\n\n default public int compareTo(IntStream c) {\n IntIterator it = intIterator();\n IntIterator jt = c.intIterator();\n while (it.isValid() && jt.isValid()) {\n int i = it.value();\n int j = jt.value();\n if (i < j) {\n return -1;\n } else if (i > j) {\n return 1;\n }\n it.advance();\n jt.advance();\n }\n if (it.isValid()) {\n return 1;\n }\n if (jt.isValid()) {\n return -1;\n }\n return 0;\n }\n\n }\n\n static interface IntCollection extends IntStream {\n public int size();\n\n default public void add(int value) {\n throw new UnsupportedOperationException();\n }\n\n default public IntCollection addAll(IntStream values) {\n for (IntIterator it = values.intIterator(); it.isValid(); it.advance()) {\n add(it.value());\n }\n return this;\n }\n\n }\n\n static class IntArrayList extends IntAbstractStream implements IntList {\n private int size;\n private int[] data;\n\n public IntArrayList() {\n this(3);\n }\n\n public IntArrayList(int capacity) {\n data = new int[capacity];\n }\n\n public IntArrayList(IntCollection c) {\n this(c.size());\n addAll(c);\n }\n\n public IntArrayList(IntStream c) {\n this();\n if (c instanceof IntCollection) {\n ensureCapacity(((IntCollection) c).size());\n }\n addAll(c);\n }\n\n public IntArrayList(IntArrayList c) {\n size = c.size();\n data = c.data.clone();\n }\n\n public IntArrayList(int[] arr) {\n size = arr.length;\n data = arr.clone();\n }\n\n public int size() {\n return size;\n }\n\n public int get(int at) {\n if (at >= size) {\n throw new IndexOutOfBoundsException(\"at = \" + at + \", size = \" + size);\n }\n return data[at];\n }\n\n private void ensureCapacity(int capacity) {\n if (data.length >= capacity) {\n return;\n }\n capacity = Math.max(2 * data.length, capacity);\n data = Arrays.copyOf(data, capacity);\n }\n\n public void addAt(int index, int value) {\n ensureCapacity(size + 1);\n if (index > size || index < 0) {\n throw new IndexOutOfBoundsException(\"at = \" + index + \", size = \" + size);\n }\n if (index != size) {\n System.arraycopy(data, index, data, index + 1, size - index);\n }\n data[index] = value;\n size++;\n }\n\n public void removeAt(int index) {\n if (index >= size || index < 0) {\n throw new IndexOutOfBoundsException(\"at = \" + index + \", size = \" + size);\n }\n if (index != size - 1) {\n System.arraycopy(data, index + 1, data, index, size - index - 1);\n }\n size--;\n }\n\n }\n\n static interface IntReversableCollection extends IntCollection {\n }\n\n static interface IntList extends IntReversableCollection {\n public abstract int get(int index);\n\n public abstract void addAt(int index, int value);\n\n public abstract void removeAt(int index);\n\n default public IntIterator intIterator() {\n return new IntIterator() {\n private int at;\n private boolean removed;\n\n public int value() {\n if (removed) {\n throw new IllegalStateException();\n }\n return get(at);\n }\n\n public boolean advance() {\n at++;\n removed = false;\n return isValid();\n }\n\n public boolean isValid() {\n return !removed && at < size();\n }\n\n public void remove() {\n removeAt(at);\n at--;\n removed = true;\n }\n };\n }\n\n\n default public void add(int value) {\n addAt(size(), value);\n }\n\n default public void popLast() {\n removeAt(size() - 1);\n }\n\n }\n\n static class ArrayUtils {\n public static void fill(int[][] array, int value) {\n for (int[] row : array) {\n Arrays.fill(row, value);\n }\n }\n\n }\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 printLine() {\n writer.println();\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 }\n\n static abstract class IntAbstractStream implements IntStream {\n\n public String toString() {\n StringBuilder builder = new StringBuilder();\n boolean first = true;\n for (IntIterator it = intIterator(); it.isValid(); it.advance()) {\n if (first) {\n first = false;\n } else {\n builder.append(' ');\n }\n builder.append(it.value());\n }\n return builder.toString();\n }\n\n\n public boolean equals(Object o) {\n if (!(o instanceof IntStream)) {\n return false;\n }\n IntStream c = (IntStream) o;\n IntIterator it = intIterator();\n IntIterator jt = c.intIterator();\n while (it.isValid() && jt.isValid()) {\n if (it.value() != jt.value()) {\n return false;\n }\n it.advance();\n jt.advance();\n }\n return !it.isValid() && !jt.isValid();\n }\n\n\n public int hashCode() {\n int result = 0;\n for (IntIterator it = intIterator(); it.isValid(); it.advance()) {\n result *= 31;\n result += it.value();\n }\n return result;\n }\n\n }\n\n static interface IntIterator {\n public int value() throws NoSuchElementException;\n\n public boolean advance();\n\n public boolean isValid();\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "64b32c181cd112a66128527c4e9bbbc6", "src_uid": "99b94d0c75fa6cd28091a9d71daf6cbf", "difficulty": 2900.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\n\n\npublic class PanterRobot {\n\t\n\tstatic class Scanner{\n\t\tBufferedReader br=null;\n\t\tStringTokenizer tk=null;\n\t\tpublic Scanner(){\n\t\t\tbr=new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\t\tpublic String next() throws IOException{\n\t\t\twhile(tk==null || !tk.hasMoreTokens())\n\t\t\t\ttk=new StringTokenizer(br.readLine());\n\t\t\treturn tk.nextToken();\n\t\t}\n\t\tpublic int nextInt() throws NumberFormatException, IOException{\n\t\t\treturn Integer.valueOf(next());\n\t\t}\n\t\tpublic double nextDouble() throws NumberFormatException, IOException{\n\t\t\treturn Double.valueOf(next());\n\t\t}\n\t}\n\t\n\tstatic int N,M;\n\tstatic HashSet visited;\n\t\n\tstatic class State{\n\t\tint x,y,dir;\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 + x;\n\t\t\tresult = prime * result + y;\n\t\t\treturn result;\n\t\t}\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\tState other = (State) obj;\n\t\t\tif (x != other.x)\n\t\t\t\treturn false;\n\t\t\tif (y != other.y)\n\t\t\t\treturn false;\n\t\t\treturn true;\n\t\t}\n\t\tpublic State(int xx, int yy, int dirr){\n\t\t\tx = xx;\n\t\t\ty = yy;\n\t\t\tdir = dirr;\n\t\t}\n\t\tpublic String toString(){\n\t\t\treturn String.format(\"(%d, %d, %d)\", x, y, dir);\n\t\t}\n\t}\n\t\n\tstatic int getCode(String ins){\n\t\tif (ins.equals(\"UL\"))\n\t\t\treturn 3;\n\t\tif (ins.equals(\"UR\"))\n\t\t\treturn 2;\n\t\tif (ins.equals(\"DL\"))\n\t\t\treturn 1;\n\t\tif (ins.equals(\"DR\"))\n\t\t\treturn 0;\n\t\treturn (0 / 0);\n\t}\n\t\n\t\n\t\n\tpublic static void main(String args[]) throws NumberFormatException, IOException{\n\t\tScanner sc = new Scanner();\n\t\tN = sc.nextInt();\n\t\tM = sc.nextInt();\n\t\tint amount = N + M - 2;\n\t\tlong ans = 0;\n\t\tboolean finished = false;\n\t\tint a = sc.nextInt();\n\t\tint b = sc.nextInt();\n\t\tint c = getCode(sc.next());\n\t\tState current = new State(a, b, c);\n\t\tHashSet visited = new HashSet();\n\t\tif (N == M && M == 3){\n\t\t\tif (a == 1 && b == 1){\n\t\t\t\tSystem.out.println(\"-1\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (a == 3 && b == 1){\n\t\t\t\tSystem.out.println(\"-1\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (a == 1 && b == 3){\n\t\t\t\tSystem.out.println(\"-1\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (a == 3 && b == 3){\n\t\t\t\tSystem.out.println(\"-1\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tif(N == M && M > 3){\n\t\t\tSystem.out.println(\"-1\");\n\t\t\treturn;\n\t\t}\n\t\twhile(true){\n\t\t\tvisited.add(current);\n\t\t\tif (visited.size() == amount) {\n\t\t\t\tfinished = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tint nx = 0,ny = 0,ndir = 0;\n\t\t\tif (current.dir == 0){\n\t\t\t\tint dy = M - current.y;\n\t\t\t\tint dx = N - current.x;\n\t\t\t\tif ( dy < dx){\n\t\t\t\t\tnx = current.x + dy;\n\t\t\t\t\tny = M;\n\t\t\t\t\tndir = getCode(\"DL\");\n\t\t\t\t}\n\t\t\t\telse if (dy > dx){\n\t\t\t\t\tnx = N;\n\t\t\t\t\tny = current.y + dx;\n\t\t\t\t\tndir = getCode(\"UR\");\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\t//iguales \n\t\t\t\t\tnx = N;\n\t\t\t\t\tny = M;\n\t\t\t\t\tndir = getCode(\"UL\");\n\t\t\t\t}\n\t\t\t\tans += Math.min(dx, dy);\n\t\t\t}\n\t\t\telse if (current.dir == 1){\n\t\t\t\tint dy = current.y - 1;\n\t\t\t\tint dx = N - current.x;\n\t\t\t\tif ( dy < dx){\n\t\t\t\t\tnx = current.x + dy;\n\t\t\t\t\tny = 1;\n\t\t\t\t\tndir = getCode(\"DR\");\n\t\t\t\t}\n\t\t\t\telse if (dy > dx){\n\t\t\t\t\tnx = N;\n\t\t\t\t\tny = current.y - dx;\n\t\t\t\t\tndir = getCode(\"UL\");\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\t//iguales \n\t\t\t\t\tnx = N;\n\t\t\t\t\tny = 1;\n\t\t\t\t\tndir = getCode(\"UR\");\n\t\t\t\t}\n\t\t\t\tans += Math.min(dx, dy);\n\t\t\t}\n\t\t\telse if (current.dir == 2){\n\t\t\t\tint dy = M - current.y;\n\t\t\t\tint dx = current.x - 1;\n\t\t\t\tif ( dy < dx){\n\t\t\t\t\tnx = current.x - dy;\n\t\t\t\t\tny = M;\n\t\t\t\t\tndir = getCode(\"UL\");\n\t\t\t\t}\n\t\t\t\telse if (dy > dx){\n\t\t\t\t\tnx = 1;\n\t\t\t\t\tny = current.y + dx;\n\t\t\t\t\tndir = getCode(\"DR\");\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\t//iguales \n\t\t\t\t\tnx = 1;\n\t\t\t\t\tny = M;\n\t\t\t\t\tndir = getCode(\"DL\");\n\t\t\t\t}\n\t\t\t\tans += Math.min(dx, dy);\n\t\t\t}\n\t\t\telse if (current.dir == 3){\n\t\t\t\tint dy = current.y - 1;\n\t\t\t\tint dx = current.x - 1;\n\t\t\t\tif ( dy < dx){\n\t\t\t\t\tnx = current.x - dy;\n\t\t\t\t\tny = 1;\n\t\t\t\t\tndir = getCode(\"UR\");\n\t\t\t\t}\n\t\t\t\telse if (dy > dx){\n\t\t\t\t\tnx = 1;\n\t\t\t\t\tny = current.y - dx;\n\t\t\t\t\tndir = getCode(\"DL\");\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\t//iguales \n\t\t\t\t\tnx = 1;\n\t\t\t\t\tny = 1;\n\t\t\t\t\tndir = getCode(\"DR\");\n\t\t\t\t}\n\t\t\t\tans += Math.min(dx, dy);\n\t\t\t}\n\t\t\telse\n\t\t\t\tSystem.out.println(0 / 0);\n\t\t\tcurrent = new State(nx, ny, ndir);\n\t\t\t//System.out.println(ans);\n\t\t\t//System.out.println(current);\n\t\t}\n\t\tif (finished)\n\t\t\tSystem.out.println(ans + 1);\n\t\telse\n\t\t\tSystem.out.println(\"-1\");\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b9a4abd406b7231a85a409afd86a191e", "src_uid": "8a59247013a9b1f34700f4bfc7d1831d", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.lang.reflect.Array;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class popo {\n\n public static boolean prime[];\n public static ArrayList[] ad=new ArrayList[2555];\n public static ArrayList xor1,xor2;\n static int []min;\n static char [][]grid;\n static int []dx = {0,0,-1,1};\n static int []dy = {-1,1,0,0};\n static int []dx8 = {1,1,1,0,-1,-1,-1,0};\n static int []dy8 = {1,0,-1,-1,-1,0,1,1};\n static ArrayList aa;\n\n public static void main(String[] args) {\n InputReader in = new InputReader(System.in);\n PrintWriter out = new PrintWriter(System.out);\n\n int t = in.nextInt();\n while (t-->0)\n {\n long a = in.nextLong();\n long b = in.nextLong();\n boolean k =winner(a,b);\n if(k)\n out.println(\"First\");\n else\n out.println(\"Second\");\n\n }\n\n out.close();\n }\n static boolean winner(long a ,long b)\n {\n if(a==0 || b==0)\n return false;\n if(a>b)\n {\n long t = a;\n a = b;\n b = t;\n }\n if(!winner(a,b%a))return true;\n long mod = b/a;\n a = a+1;\n return ((mod)%2 == 0);\n }\n\n public static long modPow(long base, long exp, long mod) {\n base = base % mod;\n long result = 1;\n while(exp > 0)\n {\n if(exp % 2== 1)\n {\n result = (result * base) % mod;\n exp --;\n }\n else\n {\n base = (base * base) % mod;\n exp = exp >> 1;\n }\n\n }\n return result;\n }\n\n public static long mod = 1000000007, inf = 100000000000000000l;\n public static long fac[],inv[];\n public static void cal()\n {\n fac = new long[100001];\n inv = new long[100001];\n fac[0]=1;\n inv[0]=1;\n for(int i=1; i<=100000; i++)\n {\n fac[i]=(fac[i-1]*i)%mod;\n // inv[i]=(inv[i-1]*modPow(i,mod-2,mod))%mod;\n\n }\n }\n public static long combination(long n, long r)\n {\n long k = (fac[(int) n]%mod*inv[(int) r]%mod)%mod;\n long p = inv[(int) (n-r)]%mod;\n long m = (k*p)%mod;\n return m;\n }\n\n\n public static class Point implements Comparable {\n\n long x, y;\n\n public Point(long start, long end) {\n this.x = start;\n this.y = end;\n }\n\n @Override\n public int hashCode() {\n int hash = 5;\n hash = (int) (47 * hash + this.x);\n hash = (int) (47 * hash + this.y);\n return hash;\n }\n\n @Override\n public boolean equals(Object obj) {\n if (obj == null) {\n return false;\n }\n if (getClass() != obj.getClass()) {\n return false;\n }\n final Point other = (Point) obj;\n if (this.x != other.x) {\n return false;\n }\n if (this.y != other.y) {\n return false;\n }\n return true;\n }\n\n @Override\n public int compareTo(Point o) {\n return Long.compare(x, o.x);\n }\n }\n static long setbits(long i)\n {\n long count = 0;\n while (i>0)\n {\n count += i & 1;\n i >>= 1;\n }\n return count;\n\n }\n\n static ArrayList sieveOfEratosthenes(int n)\n {\n // Create a boolean array \"prime[0..n]\" and initialize\n // all entries it as true. A value in prime[i] will\n // finally be false if i is Not a prime, else true.\n\n\n prime=new boolean[1000001];\n for(int i=0;i aa=new ArrayList<>();\n for (long i=0;i= snumChars) {\n curChar = 0;\n try {\n snumChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (snumChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = snext();\n while (isSpaceChar(c))\n c = snext();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = snext();\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 = snext();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public long nextLong() {\n int c = snext();\n while (isSpaceChar(c))\n c = snext();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = snext();\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 = snext();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public int[] nextIntArray(int n) {\n int a[] = new int[n];\n for (int i = 0; i < n; i++)\n a[i] = nextInt();\n return a;\n }\n\n public String readString() {\n int c = snext();\n while (isSpaceChar(c))\n c = snext();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = snext();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "64dc1fb361de91d242f1ccb51141e6e0", "src_uid": "5f5b320c7f314bd06c0d2a9eb311de6c", "difficulty": 2300.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class E {\n\n BufferedReader br;\n PrintWriter out;\n StringTokenizer st;\n boolean eof;\n\n int hNum, mNum, k, newHourK;\n int newDayChange;\n \n long pow10;\n long pow10Hour;\n\n long go(int h, int m) {\n // good moments from (0, 0) to (h, m)\n //System.err.println(h + \" \" + m + \" \");\n if (m < 0) {\n m += mNum;\n h--;\n }\n\n if (h < 0)\n return 0;\n \n long res = 0;\n \n // when hour doesn't change\n \n // first h full hours\n res += (long)h * ((mNum - 1) / pow10);\n \n //System.err.println(res);\n \n //last hour also full\n if (m == mNum - 1)\n res += (mNum - 1) / pow10;\n //last hour not full\n else\n res += (m + 1) / pow10;\n \n //hour also changes\n //in fact everything is the same, but we use newHourK instead of k\n if (m != mNum - 1)\n h--;\n \n //hour changes for hours [0, h]\n \n if (h == hNum - 1) {\n if (newDayChange >= newHourK)\n res++;\n h--;\n }\n // if it's full day, last change must be treated separately\n res += (h + 1) / pow10Hour;\n \n //System.err.println(res);\n \n return res;\n }\n\n void solve() throws IOException {\n hNum = nextInt();\n mNum = nextInt();\n k = nextInt();\n\n int h1 = nextInt();\n int m1 = nextInt();\n\n int h2 = nextInt();\n int m2 = nextInt();\n \n int newHourChange = 0;\n \n String s = Integer.toString(mNum - 1);\n for (int i = 0; i < s.length(); i++)\n if (s.charAt(i) != '0')\n newHourChange++;\n \n pow10 = 1;\n for (int i = 0; i < k - 1; i++)\n pow10 *= 10;\n \n newHourK = Math.max(k - newHourChange, 1);\n \n pow10Hour = 1;\n for (int i = 0; i < newHourK - 1; i++)\n pow10Hour *= 10;\n \n newDayChange = 0;\n s = Integer.toString(hNum - 1);\n for (int i = 0; i < s.length(); i++)\n if (s.charAt(i) != '0')\n newDayChange++;\n\n if (h1 < h2 || (h1 == h2 && m1 <= m2))\n // good moments from (h1,m1) to (h2,m2-1)\n out.print(go(h2, m2 - 1) - go(h1, m1 - 1));\n else \n // good moments from (h1, m1) to (hNum - 1, mNum - 1) and from (0, 0) to (h2, m2 - 1)\n out.print(go(hNum - 1, mNum - 1) - go(h1, m1 - 1) + go(h2, m2 - 1));\n }\n\n void inp() throws IOException {\n br = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n solve();\n out.close();\n }\n\n public static void main(String[] args) throws IOException {\n new E().inp();\n }\n\n 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 \"0\";\n }\n }\n return st.nextToken();\n }\n\n String nextString() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n eof = true;\n return \"0\";\n }\n }\n return st.nextToken(\"\\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}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7bd03aac1891e41e578c39b6855f8476", "src_uid": "e2782743229645ad3a0f8e815d86dc5f", "difficulty": 2700.0} {"lang": "Java 7", "source_code": "import java.util.*;\npublic class f {\npublic static void main(String[] args)\n{\n Scanner input = new Scanner(System.in);\n int[] res = new int[]{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51, 1, 2, 1, 14, 1, 2, 2, 14, 1, 6, 1, 4, 2, 2, 1, 52, 2, 5, 1, 5, 1, 15, 2, 13, 2, 2, 1, 13, 1, 2, 4, 267, 1, 4, 1, 5, 1, 4, 1, 50, 1, 2, 3, 4, 1, 6, 1, 52, 15, 2, 1, 15, 1, 2, 1, 12, 1, 10, 1, 4, 2};\n System.out.println(res[input.nextInt()-1]);\n}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "13225e56445cd3c22237756471e171ff", "src_uid": "c50b6af99ca7b9c35628b52774d6c32b", "difficulty": 1900.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class C {\n\n\tstatic final int INF = Integer.MAX_VALUE / 3;\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tstatic int N = 1_000_000;\n\tstatic int ROOT = 1_000;\n\tstatic boolean[] isPrime = new boolean[N + 1];\n\tstatic List primes = new ArrayList<>(78498);\n\tstatic {\n\t\tArrays.fill(isPrime, true);\n\t\tfor (int i = 2; i <= N; i++) {\n\t\t\tif (isPrime[i]) {\n\t\t\t\tprimes.add(i);\n\t\t\t\tif (i <= ROOT) {\n\t\t\t\t\tfor (int j = i * i; j <= N; j += i) {\n\t\t\t\t\t\tisPrime[j] = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tint n;\n\tlong[] a;\n\n\tvoid solve() throws IOException {\n\t\tn = nextInt();\n\t\ta = new long[n];\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = nextLong();\n\t\t}\n\n\t\tArrays.sort(a);\n\n\t\tint ans = go(n - 1, new ArrayList(), 0);\n\t\tout.println(ans);\n\t}\n\n\tint go(int i, List vs, int roots) {\n\t\tif (i == -1) {\n\t\t\tint ret = 0;\n\n\t\t\tfor (long x : vs) {\n\t\t\t\tint val = sumPrimePowers(x);\n\t\t\t\tret += val + 1;\n\t\t\t}\n\n\t\t\tif (roots > 1)\n\t\t\t\tret++;\n\n\t\t\treturn ret;\n\t\t}\n\n\t\tint ret = Integer.MAX_VALUE;\n\n\t\tlong add = a[i];\n\t\tfor (int j = 0; j < vs.size(); j++) {\n\t\t\tif (vs.get(j) % add == 0) {\n\t\t\t\tList newVs = new ArrayList<>(vs);\n\n\t\t\t\tnewVs.set(j, vs.get(j) / add);\n\t\t\t\tif (sumPrimePowers(add) > 1) {\n\t\t\t\t\tnewVs.add(add);\n\t\t\t\t} else {\n\t\t\t\t\tnewVs.add(1L);\n\t\t\t\t}\n\t\t\t\tret = Math.min(ret, go(i - 1, newVs, roots));\n\t\t\t}\n\t\t}\n\t\tif (sumPrimePowers(add) == 1) {\n\t\t\tvs.add(1L);\n\t\t} else {\n\t\t\tvs.add(add);\n\t\t}\n\t\tret = Math.min(ret, go(i - 1, vs, roots + 1));\n\t\treturn ret;\n\t}\n\n\tint sumPrimePowers(long x) {\n\t\tint ret = 0;\n\t\tfor (int i = 0; i < primes.size() && x > 1; i++) {\n\t\t\tint p = primes.get(i);\n\t\t\twhile (x % p == 0) {\n\t\t\t\tx /= p;\n\t\t\t\tret++;\n\t\t\t}\n\t\t}\n\t\tif (x != 1)\n\t\t\tret++;\n\t\treturn ret;\n\t}\n\n\tC() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew C();\n\t}\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\teof = true;\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7c02d69b00d219d2a68a04ef048fcd75", "src_uid": "52b8b6c68518d5129272b8c56e5b7662", "difficulty": 2200.0} {"lang": "Java 6", "source_code": "\nimport java.util.*;\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\npublic class Main {\n public static void main(String[]args){\n new Main().run();\n }\n void run(){\n Scanner sc=new Scanner(System.in);\n long a=sc.nextLong(),l=sc.nextLong()-1;\n long res=func(a,l);\n System.out.println(res);\n }\n private long func(long a,long l){// [a,a+l]\n if(l>20){\n return a%10 + func(a/10,l/10 + (a%10+l%10)/10)*10;\n }\n int[] cnt=new int[(int)(l+1)];\n for (int i = 0; i0){\n if(l%10==4||l%10==7)res++;\n l/=10;\n }\n return res;\n }\n long INF=1L<<60;\n class E{\n long min;\n int[] cnt;\n E(long min,int[] cnt){\n this.min=min;\n this.cnt=cnt;\n }\n\n @Override\n public boolean equals(Object obj) {\n if (obj==null) return false;\n if (getClass()!=obj.getClass()) return false;\n final E other = (E) obj;\n if (this.min!=other.min) return false;\n if (!Arrays.equals(this.cnt, other.cnt)) return false;\n return true;\n }\n\n @Override\n public int hashCode() {\n int hash = 7;\n hash = 67*hash+(int) (this.min^(this.min>>>32));\n hash = 67*hash+Arrays.hashCode(this.cnt);\n return hash;\n }\n\n }\n HashSet set=new HashSet();\n private long func2(long min, int[] cnt) {\n if(cnt.length==1){\n return func3(min,cnt[0]);\n }\n E key = new E(min,cnt);\n if(set.contains(key))return INF;\n set.add(key);\n long res=INF;\n loop:for (int o = 0; o<10; o++) {\n int i=(int)((min+o)%10);\n int len = (i+cnt.length-1)/10 + 1;\n int[] ncnt=new int[len];\n fill(ncnt,-1);\n len=0;\n for (int j = 0; j0){\n for (int i = 0;; i++) {\n long tmp = res + p10 * i;\n if(possible(tmp,min,p10/10,dig-1,cnt)){\n res=tmp;break;\n }\n if(i==9)throw new RuntimeException();\n }\n p10/=10;\n dig--;\n }\n return res;\n }\n\n private boolean possible(long tmp, long min,long p10, int dig, int cnt) {\n if(lucky(tmp) > cnt)return false;\n cnt -= lucky(tmp);\n if(cnt>dig)return false;\n while(cnt0){\n tmp += p10*7;\n dig--;\n p10/=10;\n }\n return tmp>=min;\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2e65ed5d7e5b60510b74c06ac1761c1a", "src_uid": "649e9f477b97c1f72b05d409b4a99d59", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.NoSuchElementException;\nimport java.math.BigInteger;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.io.InputStream;\nimport java.io.OutputStreamWriter;\nimport java.util.Comparator;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author \u00c1rysson Cavalcanti\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\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n\n\tlong[][][][] dp;\n\tint MOD=1000000007;\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n\t\tint n=in.readInt(), k=in.readInt();\n\t\tdp=new long[n+1][k+1][n+1][2];\n\t\tArrayUtils.fill(dp, -1);\n\t\tlong[] factorial=IntegerUtils.generateFactorial(n, MOD), powers=IntegerUtils.generatePowers(2, n, MOD), reverse=new long[n];\n\t\tfor (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\tpublic int readInt() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tint res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tpublic boolean isSpaceChar(int c) {\n\t\tif (filter != null)\n\t\t\treturn filter.isSpaceChar(c);\n\t\treturn isWhitespace(c);\n\t}\n\n\tpublic static boolean isWhitespace(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n\n\tpublic interface SpaceCharFilter {\n\t\tpublic boolean isSpaceChar(int ch);\n\t}\n}\n\nclass OutputWriter {\n\tprivate final PrintWriter writer;\n\n\tpublic OutputWriter(OutputStream outputStream) {\n\t\twriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n\t}\n\n\tpublic void close() {\n\t\twriter.close();\n\t}\n\n\tpublic void printLine(long i) {\n\t\twriter.println(i);\n\t}\n\n}\n\nclass ArrayUtils {\n\n\tpublic static void fill(long[][] array, long value) {\n\t\tfor (long[] row : array)\n\t\t\tArrays.fill(row, value);\n\t}\n\n\tpublic static void fill(long[][][] array, long value) {\n\t\tfor (long[][] row : array)\n\t\t\tfill(row, value);\n\t}\n\n\tpublic static void fill(long[][][][] array, long value) {\n\t\tfor (long[][][] row : array)\n\t\t\tfill(row, value);\n\t}\n\n}\n\nclass IntegerUtils {\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[] 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 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}\n\nclass MiscUtils {\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}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9ab752961fca75ca8c3ee81c7d4981d4", "src_uid": "f98b740183281943eafd90328854746b", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "//package cf589d2;\nimport java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class E {\n\tstatic long[][] choose = new long[270][270];\n\tstatic long MOD = 1000000007;\n\tpublic static void main(String[] args) {\n\t\tfor(int i = 0; i < 270; i++) {\n\t\t\tchoose[i][0] = 1;\n\t\t\tchoose[i][i] = 1;\n\t\t}\n\t\tfor(int i = 2; i < 270; i++)\n\t\t\tfor(int j = 1; j < i; j++)\n\t\t\t\tchoose[i][j] = choose[i - 1][j] + choose[i - 1][j - 1];\n\t\tMyScanner sc = new MyScanner();\n\t\tint n = sc.nextInt();\n\t\tlong k = sc.nextLong();\n\t\tlong[][] dp = new long[n + 1][n + 1];\n\t\tdp[0][n] = 1;\n\t\tfor(int i = 1; i <= n; i++)\n\t\t\tfor(int j = 0; j <= n; j++)\n\t\t\t\tfor(int l = 0; l <= j; l++) {\n\t\t\t\t\tlong del;\n\t\t\t\t\tif(j > 0 && l < j)\n\t\t\t\t\t\tdel = dp[i - 1][j] * choose[j][l] % MOD * pMod(k - 1, l) % MOD * pMod(k, n - j) % MOD;\n\t\t\t\t\telse if(j > 0)\n\t\t\t\t\t\tdel = dp[i - 1][j] * choose[j][l] % MOD * pMod(k - 1, l) % MOD * (pMod(k, n - j) - 1) % MOD;\n\t\t\t\t\telse\n\t\t\t\t\t\tdel = dp[i - 1][j] * (pMod(k, n) - pMod(k - 1, n)) % MOD;\n\t\t\t\t\t//System.out.println(i + \" \" + j + \" \" + l + \" { \" + del);\n\t\t\t\t\tdp[i][l] = (dp[i][l] + del) % MOD;\n\t\t\t\t}\n\n\t\tout.println(dp[n][0]);\n\t\tout.close();\n\t}\n\tpublic static long pMod(long x, long p) {\n\t\tif(p == 0)\n\t\t\treturn 1;\n\t\tlong l = pMod(x, p / 2);\n\t\treturn l * l % MOD * (p % 2 == 1 ? x : 1) % MOD;\n\t}\n\tpublic static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n\tpublic static class MyScanner {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st;\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreElements())\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\tString nextLine() {\n\t\t\tString str = \"\";\n\t\t\ttry {\n\t\t\t\tstr = br.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cf4bd7a42bdee6498491833a8a33ab5d", "src_uid": "f67173c973c6f83e88bc0ddb0b9bfa93", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class Sol{\n public static void main(String[] argc){\n Scanner sc = new Scanner(System.in);\n int n, k;\n String s;\n n = sc.nextInt();\n k = sc.nextInt();\n s = sc.next();\n\n boolean found = false;\n for (int i = 0; i < n; ++i) {\n int st = i;\n int en = i + k - 1;\n if (st -1 >=0 and s[st-1] == 'N') {\n continue;\n }\n if (en +1 = n) {\n break;\n }\n\n boolean ok = true;\n for (int j = st; j <= en; ++j) {\n if (s.charAt(j) == 'Y') {\n ok = false;\n }\n }\n if (ok) {\n found = true;\n break;\n }\n }\n\n int maxn = 0;\n\n for (int i = 0; i < n; ++i) {\n if (s.charAt(i) != 'N') {\n continue;\n }\n int cnt = 1;\n int j = i + 1;\n while (j < n && s.charAt(j) == 'N') {\n ++cnt;\n ++j;\n }\n\n if (cnt > maxn) {\n maxn = cnt;\n }\n }\n\n if (found && maxn <= k) {\n System.out.println(\"YES\");\n }\n else {\n System.out.println(\"NO\");\n }\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "7e40dace44b7340d66d4df6636089868", "src_uid": "5bd578d3da5837c259b222336a194d12", "difficulty": 2000.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.PriorityQueue;\nimport java.util.Queue;\n\npublic class ProblemE {\n\tstatic int N;\n\tstatic long Y;\n\tstatic long ycnt;\n\tstatic int[] place;\n\tstatic boolean[][] invalid;\n\tstatic boolean[][] invalidGraph;\n\tstatic boolean[][] rules;\n\t\n\tprivate static long cnt(int now) {\n\t\tlong[][] dp = new long[N+1][1<= 1) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif (invalid[ptn][next]) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tint nptn = ptn | (1<= 1) {\n\t\t\t\t\tboolean isok = true;\n\t\t\t\t\tfor (int j = 0 ; j < N ; j++) {\n\t\t\t\t\t\tif (place[j] == now - 1) {\n\t\t\t\t\t\t\tif (invalidGraph[j][i]) {\n\t\t\t\t\t\t\t\tisok = false;\n\t\t\t\t\t\t\t\tbreak;\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 (!isok) {\n\t\t\t\t\t\tplace[i] = -1;\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tlong dcnt = cnt(now+1);\n\t\t\t\tif (ycnt + dcnt >= Y) {\n\t\t\t\t\tdfs(now+1);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tycnt += dcnt;\n\t\t\t\tplace[i] = -1;\n\t\t\t}\n\t\t}\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader s = new BufferedReader(new InputStreamReader(System.in));\n\t\tString[] line = s.readLine().split(\" \");\n\t\tint n = Integer.valueOf(line[0]);\n\t\tlong y = Long.valueOf(line[1]) - 2000;\n\t\tint m = Integer.valueOf(line[2]);\n\t\t\n\t\tinvalid = new boolean[1<= 1) {\n\t\t\t\t\tinvalid[j][senior] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tN = n;\n\t\tY = y;\n\t\tycnt = 0;\n\t\tplace = new int[N];\n\t\tArrays.fill(place, -1);\n\t\t\n\t\tdfs(0);\n\n\t\tif (place[0] == -1) {\n\t\t\tSystem.out.println(\"The times have changed\");\n\t\t\treturn;\n\t\t} else {\n\t\t\tint[] map = new int[N];\n\t\t\tfor (int i = 0 ; i < n ; i++) {\n\t\t\t\tmap[place[i]] = i;\n\t\t\t}\n\t\t\t\n\t\t\tStringBuffer b = new StringBuffer();\n\t\t\tfor (int i = 0 ; i < n ; i++) {\n\t\t\t\tb.append(map[i]+1).append(\" \");\n\t\t\t}\n\t\t\tSystem.out.println(b.substring(0, b.length()-1));\n\t\t}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "aab3a8c138a51705a403095023870202", "src_uid": "e9db8d048e9763cf38c584342dea9f53", "difficulty": 2400.0} {"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 D {\n\t\n\tprivate static StringTokenizer tokenizer;\n private static BufferedReader bf;\n private static PrintWriter out;\n \n\tprivate static int nextInt() throws IOException {\n \treturn Integer.parseInt(nextToken());\n }\n \n @SuppressWarnings(\"unused\")\n\tprivate static long nextLong() throws IOException {\n \treturn Long.parseLong(nextToken());\n }\n \n private static String nextToken() throws IOException {\n \twhile(tokenizer == null || !tokenizer.hasMoreTokens()) {\n \t\ttokenizer = new StringTokenizer(bf.readLine());\n \t}\n \treturn tokenizer.nextToken();\n }\n \n\tpublic static void main(String[] args) throws IOException {\n\t\tbf = new BufferedReader(new InputStreamReader(System.in));\n \ttokenizer = null;\n \tout = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n \tint b = nextInt(); int d = nextInt();\n \tString a = nextToken(); String c = nextToken();\n \tint inda = 0, indc = 0;\n \tint lena = a.length();\n \tint lenc = c.length();\n \tlong max = lena*b;\n \twhile(inda < max) {\n \t\tif(c.charAt(indc%lenc) != a.charAt(inda%lena))\n \t\t\tinda++;\n \t\telse {\n \t\t\tinda++; indc++;\n \t\t}\n \t\tif(indc%lenc == 0 && inda%lena == 0) break;\n \t}\n \tout.println((indc*max)/(lenc*d*inda));\n \tout.close();\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5181aeddbf4601c4b6c3ba7d45238837", "src_uid": "5ea0351ac9f949dedae1928bfb7ebffa", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class B {\n private static class Cup implements Comparable {\n public int price;\n public int weight;\n\n Cup(int price, int weight) {\n this.price = price;\n this.weight = weight;\n }\n\n @Override\n public int compareTo(Cup other) {\n if (this.price == other.price) {\n return this.weight - other.weight;\n }\n return other.price - this.price;\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 d = in.nextInt();\n\n Cup a[] = new Cup[n];\n Cup b[] = new Cup[m];\n\n for (int i = 0; i < n; ++i) {\n int c = in.nextInt();\n int w = in.nextInt();\n a[i] = new Cup(c, w);\n }\n\n for (int i = 0; i < m; ++i) {\n int c = in.nextInt();\n int w = in.nextInt();\n b[i] = new Cup(c, w);\n }\n Arrays.sort(a);\n Arrays.sort(b);\n\n long mp = 0;\n \n long cw = 0;\n long cp = 0;\n\n int mi = -1;\n for (int i = 0; i < n; ++i) {\n if (cw + a[i].weight <= d) {\n cw += a[i].weight;\n cp += a[i].price;\n mi = i;\n } else {\n break;\n }\n }\n\n int j = 0;\n while (mi >= 0) {\n while (j < m && cw + b[j].weight <= d) {\n cw += b[j].weight;\n cp += b[j].price;\n ++j;\n }\n if (j > 0) {\n mp = Math.max(mp, cp);\n }\n cp -= a[mi].price;\n cw -= a[mi].weight;\n --mi;\n }\n System.out.println(mp);\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7f8e7d25a1a837106390eb3223a5ba2d", "src_uid": "da573a39459087ed7c42f70bc1d0e8ff", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "// import org.junit.Test;\nimport java.util.Scanner;\n\n// import static org.junit.Assert.assertEquals;\n\npublic class CF_1223G {\n static Scanner scanner = new Scanner(System.in);\n public static void main(String args[])\n {\n //test();\n long caseNum = 1;\n while (caseNum-- > 0) {\n task();\n }\n }\n\n private static int maxN = 500000;\n private static int[] a = new int[maxN + 10];\n private static int[] sum = new int[maxN + 10];\n private static int[] input = new int[maxN + 10];\n\n public static void task() {\n int n = scanner.nextInt();\n // System.out.println(n);\n for (int i = 0; i < n; i++) {\n input[i] = scanner.nextInt();\n }\n // System.out.println(\"input end\");\n solve(n, input);\n }\n\n public static void clear(int n) {\n for (int i = 1; i <= maxN + 1; i++) {\n a[i] = 0;\n sum[i] = 0;\n }\n }\n\n private static int maxA;\n\n public static long solve(int n, int[] input) {\n long maxArea = 0;\n maxA = 0;\n clear(n);\n for (int i = 0; i < n; i++) {\n a[input[i]]++;\n if (input[i] > maxA) {\n maxA = input[i];\n }\n }\n for (int i = 2; i <= maxN + 1; i++) {\n sum[i] = a[i] + sum[i - 1];\n }\n\n for (int y = 2; y <= maxA; y++) {\n long total = 0;\n for (int step = y; step <= maxA; step += y) {\n total += q(step, min(step + y - 1, maxA) + 1) * (long) (step / y);\n }\n int x = 1;\n int left = 2;\n int right = maxA;\n while (left <= right) {\n int mid = (left + right) / 2;\n if (check(y, mid, total)) {\n if (mid > x) {\n x = mid;\n }\n left = mid + 1;\n } else {\n right = mid - 1;\n }\n }\n if (x > 1) {\n if ((long) x * (long) y > maxArea) {\n maxArea = (long) x * (long) y;\n /*\n System.out.println(y + \" \" + x);\n System.out.println(maxArea);\n */\n }\n }\n }\n System.out.println(maxArea);\n\n return maxArea;\n }\n\n public static boolean check(int y, int x, long total) {\n if (y == 4) {\n // System.out.println(\"fcuk\");\n }\n boolean ret = check1(y, x, total, x + x, false) || check2(y, x, total);\n //System.out.println(y + \" \" + x + \" \" + total + \" \" + ret);\n return ret;\n }\n\n public static boolean check1(int y, int x, long total, int need, boolean ignore) {\n // together\n long up = (need - 1) / y + 1;\n long down = need / y;\n int hits = 0;\n if (!ignore) {\n if (need < y) {\n if (q(need, y) > 0) {\n hits = 1;\n }\n }\n }\n if (hits == 1) {\n return total >= x;\n }\n int toSub = 0;\n int remain = need % y;\n for (int step = max(y, need - remain); step + remain <= maxA; step += y) {\n if (q(step + remain, min(step + y,maxA + 1)) > 0) {\n toSub = 1;\n break;\n }\n }\n if (toSub == 1) {\n return total >= x + down;\n } else {\n if (q(need, maxA + 1) > 0) {\n return total >= x + up;\n } else {\n return false;\n }\n }\n }\n\n private static int min(int x, int y) {\n if (x < y) {\n return x;\n }\n return y;\n }\n\n private static int max(int x, int y) {\n if (x > y) {\n return x;\n }\n return y;\n }\n\n\n public static boolean check2(int y, int x, long total) {\n // separate\n int need = x;\n int up = (need - 1) / y + 1;\n int down = need / y;\n int hits = 0;\n if (need < y) {\n if (q(need, y) > 0) {\n hits = q(need, y);\n }\n if (hits >= 2) {\n hits = 2;\n }\n }\n if (hits == 2) {\n return total >= x;\n }\n // ?\n if (hits == 1) {\n return check1(y, x, total, x, true);\n }\n if (q(need, maxA + 1) < 2){\n return false;\n }\n if (hits == 0) {\n int toSub = 0;\n int remain = need % y;\n for (int step = max(y, need - remain); step + remain <= maxA; step += y) {\n int h = q(step + remain, min(step + y,maxA + 1));\n toSub += h;\n if (toSub >= 2) {\n toSub = 2;\n break;\n }\n }\n if (toSub == 2) {\n return total >= x + down + down;\n }\n if (toSub == 1) {\n return total >= x + down + up;\n }\n if (toSub == 0) {\n return total >= x + up + up;\n }\n }\n // never\n return false;\n }\n\n public static int q(int begin, int end) {\n if (begin > end) {\n return 0;\n }\n return sum[end - 1] - sum[begin - 1];\n }\n\n\n public static void test() {\n int n = 90792;\n int[] input = new int[maxN + 10];\n input[0] = 181565;\n input[1] = 181564;\n for (int i = 2; i < n; i++) {\n input[i] = 60522;\n }\n System.out.println(solve(n, input));\n }\n\n /*\n @Test\n public void test() {\n int n = 1;\n int[] input = {9};\n assertEquals(4, solve(n, input));\n }\n\n @Test\n public void test2() {\n String s = \"9\\n\" +\n \"9 10 9 18 9 9 9 28 9\";\n s = \"9\\n\" +\n \"9 10 9 19 9 9 9 28 9\";\n Scanner scanner = new Scanner(s);\n int n = scanner.nextInt();\n int [] input = new int[500000 +100];\n for (int i = 0; i < n; i++) {\n input[i] = scanner.nextInt();\n }\n assertEquals(90, solve(n, input));\n }\n */\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b59e8755cb720add8109c794cd02dc72", "src_uid": "bca20e0910e9fe4d89326b50ab45e4ca", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n/*\n5\n4 1 1 1 3 3 3 3 1\n4 4 3 6 2 6 0 4 0\n6 -5 3 -4 4 -3 4 -2 3 -3 2 -4 2\n3 0 -1 1 -3 -1 -3\n4 1 -4 1 -6 -1 -6 -1 -4\n5\n8 1 1 1 2 1 3 2 3 3 3 3 2 3 1 2 1\n4 4 3 6 2 6 0 4 0\n6 -5 3 -4 4 -3 4 -2 3 -3 2 -4 2\n3 0 -1 1 -3 -1 -3\n4 1 -4 1 -6 -1 -6 -1 -4\n7\n4\n1 0\n1 1\n2 1\n2 0\n4\n4 -1\n4 0\n5 0\n5 -1\n4\n7 0\n7 1\n8 1\n8 0\n4\n10 -1\n10 0\n11 0\n11 -1\n4\n-1 0\n-1 -1\n-2 -1\n-2 0\n4\n-4 1\n-4 0\n-5 0\n-5 1\n4\n-7 0\n-7 -1\n-8 -1\n-8 0\n */\npublic class Geom {\n\t\n\tstatic int N, totalSz;\n\tstatic Poly ar[];\n\tstatic boolean RADIAL_SORT,ID_SORT;\n\tstatic Vec radialPnts[];\n\tstatic TreeSet ts;\n\tstatic boolean inTreeSet[];\n\tstatic final boolean debug = false;\n\tstatic Vec ORIGIN = new Vec(0,0);\n\tstatic final double eps = 1e-6;\n\t\n\tpublic static void main(String args[]) {\n\t\tFS in = new FS();\n\t\tN = in.nextInt();\n\t\tar = new Poly[N];\n\t\t//Read in the input and make the polygons \n\t\tfor(int i = 0; i < N; i++) {\n\t\t\tint sz = in.nextInt();\n\t\t\tVec pts[] = new Vec[sz];\n\t\t\tfor(int j = 0; j < sz; j++) {\n\t\t\t\tdouble x = in.nextInt();\n\t\t\t\tdouble y = in.nextInt();\n\t\t\t\tint id = sz-j-1; //make counter-clockwise\n\t\t\t\tpts[id] = new Vec(x,y,id);\n\t\t\t}\n\t\t\tar[i] = new Poly(pts, i);\n\t\t\ttotalSz += ar[i].sz;\n\t\t}\n\t\tradialPnts = new Vec[totalSz];\n\t\tint idd = 0;\n\t\tfor(Poly p : ar)\n\t\t\tfor(Vec v : p.vs)\n\t\t\t\tradialPnts[idd++] = v;\n\t\tsetRadialSort();\n\t\tArrays.sort(radialPnts);\n\t\tinitSweep();\n\t\tsweep();\n\t\tdouble res = 0;\n\t\tfor(Poly p : ar)\n\t\t\tres += p.area();\n\t\tSystem.out.println(res);\n\t}\n\t\n\tstatic void sweep() {\n\t\tfor(Vec v : radialPnts) {\n\t\t\tif(debug) {\n\t\t\t\tSystem.out.println(\"V= \"+v);\n\t\t\t\tSystem.out.print(\"TS:\");\n\t\t\t\tfor(Poly p : ts) System.out.print(p.id+\" \");\n\t\t\t\tSystem.out.println();\n\t\t\t}\n\t\t\tif(v.isLast) {\n\t\t\t\t//Removing this polygon\n\t\t\t\tPoly first = ts.first();\n\t\t\t\tts.remove(v.poly);\n\t\t\t\tinTreeSet[v.poly.id] = false;\n\t\t\t\tif(first.id == v.poly.id && ts.size() > 0 ) { // If this polygon was first, add the lines to the next guy\n\t\t\t\t\tPoly next = ts.first();\n\t\t\t\t\tSeg s = new Seg(ORIGIN, v);\n\t\t\t\t\tnext.intersectF(s, true);\n\t\t\t\t\tnext.intersectR(s, true);\n\t\t\t\t\tnext.isSeen = true; // This guy is seen\n\t\t\t\t}\n\t\t\t\tv.poly.killSegs();\n\t\t\t}\n\t\t\telse {\n\t\t\t\tv.poly.updateSegs(v);\n\t\t\t\tif(!inTreeSet[v.poly.id]) {\n\t\t\t\t\tPoly curFirst = ts.size() == 0 ? null : ts.first();\n\t\t\t\t\tts.add(v.poly);\n\t\t\t\t\tinTreeSet[v.poly.id] = true;\n\t\t\t\t\tif(ts.first().id == v.poly.id) {\n\t\t\t\t\t\tv.poly.isSeen = true;\n\t\t\t\t\t\tif(curFirst != null) {\n\t\t\t\t\t\t\tSeg s = new Seg(ORIGIN, v);\n\t\t\t\t\t\t\tcurFirst.intersectF(s, false);\n\t\t\t\t\t\t\tcurFirst.intersectR(s, false);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tstatic void initSweep() {\n\t\t//Set up the fSegs and rSegs (but NOT isSeen / adding the lines/points);\n\t\tinTreeSet = new boolean[N];\n\t\tts = new TreeSet();\n\t\tfor(Vec v : radialPnts) {\n\t\t\tif(debug) System.out.println(\"V= \"+v);\n\t\t\tif(v.isLast) { //Remove this polygon\n\t\t\t\tts.remove(v.poly);\n\t\t\t\tinTreeSet[v.poly.id] = false;\n\t\t\t\tv.poly.killSegs();\n\t\t\t}\n\t\t\telse {\n\t\t\t\tv.poly.updateSegs(v);\n\t\t\t\tif(!inTreeSet[v.poly.id]) ts.add(v.poly);\n\t\t\t\tinTreeSet[v.poly.id] = true;\n\t\t\t}\n\t\t\tif(debug) {\n\t\t\t\tSystem.out.print(\"TS:\");\n\t\t\t\tfor(Poly p : ts) System.out.print(p.id+\" \");\n\t\t\t\tSystem.out.println();\n\t\t\t}\n\t\t}\n\t\t\n\t\t//Sweep is done, set the poly in the first of the treeset to be seen if there is one\n\t\tif(ts.size() > 0) {\n\t\t\tPoly first = ts.first();\n\t\t\tfirst.isSeen = true;\n\t\t}\n\t\tif(debug) System.out.println(\"Done with init\\n\\n\\n\");\n\t}\n\t\n\tstatic void setRadialSort() {\n\t\tRADIAL_SORT = true; ID_SORT = false;\n\t}\n\tstatic void setIDSort() {\n\t\tRADIAL_SORT = false; ID_SORT = true;\n\t}\n\t\n\tstatic class Vec implements Comparable{\n\t\tdouble x,y;\n\t\tint id;\n\t\tdouble sId;\n\t\tVec prev,next;\n\t\tPoly poly;\n\t\tboolean isLast;\n\t\tint polyRemoveId;\n\t\t\n\t\tpublic Vec(double xx, double yy) {x=xx;y=yy;}\n\t\tpublic Vec(double xx, double yy, int ii) {x=xx;y=yy;id=ii;sId=ii;}\n\t\tpublic double cross(Vec o) { return x*o.y - y*o.x; }\n\t\tpublic Vec add(Vec o) { return new Vec(x+o.x, y+o.y); }\n\t\tpublic Vec sub(Vec o) { return new Vec(x-o.x, y-o.y); }\n\t\tpublic double mag(Vec o) { return x*o.x + y*o.y; }\n\t\tpublic Vec scale(double d) { return new Vec(x*d,y*d);}\n\t\t\n\t\tpublic boolean inFrontOf(Seg o) {\n\t\t\tlong c1 = (long)Math.round(o.a.cross(this));\n\t\t\tlong c2 = (long)Math.round(this.cross(o.b));\n\t\t\tif(c1 >= 0 && c2 >= 0) {\n\t\t\t\tlong c3 = (long)Math.round(o.dir.cross(this.sub(o.a)));\n\t\t\t\treturn c3 >= 0;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\tpublic static int compare(Vec a, Vec b) {\n\t\t\tint res = 0;\n\t\t\tif(a.x < 0) res += a.y >= 0 ? 1 : 2;\n\t\t\telse if(a.y < 0) res += 3;\n\t\t\tif(b.x < 0) res -= b.y >= 0 ? 1 : 2;\n\t\t\telse if(b.y < 0) res -= 3;\n\t\t\tif(res == 0) {\n\t\t\t\tlong cross = (long)Math.round(a.cross(b));\n\t\t\t\t//Further points come first if same angle\n\t\t\t\tif(cross == 0) return Long.compare((long)Math.round(b.mag(b)), (long)Math.round(a.mag(a)));\n\t\t\t\tif(cross > 0) return -1;\n\t\t\t\telse return 1;\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\t\n\t\t@Override\n\t\tpublic int compareTo(Vec o) {\n\t\t\tif(RADIAL_SORT) {\n\t\t\t\treturn Vec.compare(this, o);\n\t\t\t}\n\t\t\telse if(ID_SORT) {\n\t\t\t\treturn Double.compare(sId, o.sId);\n\t\t\t}\n\t\t\tthrow null;\n\t\t}\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn \"(\"+x+\",\"+y+\") id=\"+id+\" p=\"+(poly == null ? -1 : poly.id)+\" sId= \"+sId;\n\t\t}\n\t}\n\t\n\tstatic class Seg{\n\t\tVec a,b,dir;\n\t\tpublic Seg(Vec aa, Vec bb) {\n\t\t\ta=aa;\n\t\t\tb=bb;\n\t\t\tdir = b.sub(a);\n\t\t}\n\t\t\n\t\tpublic boolean inFrontOf(Seg o) {\n\t\t\tif(a.inFrontOf(o)) return true;\n\t\t\tif(b.inFrontOf(o)) return true;\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\tpublic Vec lineIntersect(Seg o) {\n\t\t\tdouble det = o.dir.x*dir.y-dir.x*o.dir.y;\n\t\t\tif(eq(det, 0)) return null;\n\t\t\tdouble dist = (o.dir.x * (o.a.y-a.y)-\n\t\t\t\t\to.dir.y*(o.a.x-a.x))/det;\n\t\t\treturn a.add(dir.scale(dist));\n\t\t}\n\t}\n\tstatic class Poly implements Comparable{\n\t\tint sz, id;\n\t\tVec vs[];\n\t\tSeg fSeg, rSeg;\n\t\tdouble fSegAId,rSegAId;\n\t\tboolean isSeen;\n\t\tArrayList interVecs;\n\t\t\n\t\tpublic Poly(Vec[] vss, int ii) {\n\t\t\tArrayList vs2 = new ArrayList();\n\t\t\tfor(int i = 0; i < vss.length; i++) {\n\t\t\t\tVec v = vss[i];\n\t\t\t\tVec prev = vss[(i-1+vss.length)%vss.length];\n\t\t\t\tVec next = vss[(i+1)%vss.length];\n\t\t\t\tif((long)Math.round((v.sub(prev)).cross((next.sub(v)))) != 0) vs2.add(v);\n\t\t\t}\n\t\t\tvs = new Vec[vs2.size()];\n\t\t\tfor(int i = 0; i < vs2.size(); i++) {\n\t\t\t\tVec v = vs2.get(i);\n\t\t\t\tv.id = i; v.sId = i;\n\t\t\t\tvs[i] = v;\n\t\t\t}\n\t\t\tif(debug) {\n\t\t\t\tSystem.out.println(\"Poly: \");\n\t\t\t\tfor(Vec v : vs) System.out.println(\" v=\"+v);\n\t\t\t}\n\t\t\t\n//\t\t\tvs=vss;\n\t\t\tsz = vs.length;\n\t\t\tisSeen = false;\n\t\t\tid = ii;\n\t\t\tfor(int i = 0; i < sz; i++) {\n\t\t\t\tVec prev = vs[(i-1+sz)%sz];\n\t\t\t\tVec next = vs[(i+1)%sz];\n\t\t\t\tvs[i].prev = prev;\n\t\t\t\tvs[i].next = next;\n\t\t\t\tvs[i].poly = this;\n\t\t\t\tlong c1 = (long)Math.round(prev.cross(vs[i]));\n\t\t\t\tlong c2 = (long)Math.round(next.cross(vs[i]));\n\t\t\t\tif(c1 >= 0 && c2 > 0) vs[i].isLast = true;\n\t\t\t}\n\t\t\tinterVecs = new ArrayList();\n\t\t}\n\t\t\n\t\tpublic void killSegs() { fSeg = null; rSeg = null; }\n\t\tpublic void updateSegs(Vec v) {\n\t\t\tif(fSeg == null || rSeg == null) {\n\t\t\t\tfSeg = new Seg(v, v.prev);\n\t\t\t\tfSegAId = v.id;\n\t\t\t\trSeg = new Seg(v, v.next);\n\t\t\t\trSegAId = v.id;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif(fSeg.b.id == v.id) {\n\t\t\t\t\tfSeg = new Seg(v, v.prev);\n\t\t\t\t\tfSegAId = v.id;\n\t\t\t\t}\n\t\t\t\tif(rSeg.b.id == v.id) {\n\t\t\t\t\trSeg = new Seg(v, v.next);\n\t\t\t\t\trSegAId = v.id;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tpublic void intersectF(Seg s, boolean polyRemoved) {\n\t\t\tif(debug) System.out.println(\" inter from \"+s.b.poly.id +\" to \"+this.id);\n\t\t\tVec v = s.lineIntersect(fSeg);\n\t\t\t//get the id for where to put this\n\t\t\tif(fSeg.b.id == sz-1 && eq(fSegAId, 0)) { //can't do inbetween because this is going from (sz-1) -> 0\n\t\t\t\tdouble d = fSegAId + (double)sz - eps;\n\t\t\t\tv.sId = d;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tdouble d = fSegAId - eps;\n\t\t\t\tv.sId = d;\n\t\t\t}\n\t\t\tv.polyRemoveId = (polyRemoved ? 1 : -1);\n\t\t\tinterVecs.add(v);\n\t\t\tfSegAId = v.sId;\n\t\t}\n\t\tpublic void intersectR(Seg s, boolean polyRemoved) {\n\t\t\tVec v = s.lineIntersect(rSeg);\n\t\t\t//get hte id for where to put this\n\t\t\tif(rSeg.a.id == sz-1) {\n\t\t\t\tdouble d = rSegAId + eps;\n\t\t\t\tv.sId = d;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tdouble d = rSegAId + eps;\n\t\t\t\tv.sId = d;\n\t\t\t}\n\t\t\tv.polyRemoveId = (polyRemoved ? 1 : -1);\n\t\t\tinterVecs.add(v);\n\t\t\trSegAId = v.sId;\n\t\t}\n\t\t\n\t\tpublic double area() {\n\t\t\tif(debug) System.out.println(\"PID: \"+id+\" seen=\"+isSeen);\n\t\t\tif(!isSeen) return 0;\n\t\t\telse {\n\t\t\t\tdouble res = 0;\n\t\t\t\tsetIDSort();\n\t\t\t\t\n\t\t\t\tif(interVecs.size() == 0) return getArea(vs);\n\t\t\t\t\n\t\t\t\tVec ps[] = new Vec[vs.length + interVecs.size()];\n\t\t\t\tint idd = 0;\n\t\t\t\tfor(Vec v : vs) ps[idd++] = v;\n\t\t\t\tfor(Vec v : interVecs) ps[idd++] = v;\n\t\t\t\tArrays.sort(ps);\n\t\t\t\t\n\t\t\t\tif(debug) {\n\t\t\t\t\tSystem.out.println(\"Poly: \"+id);\n\t\t\t\t\tfor(Vec v : ps) System.out.println(\" \"+v);\n\t\t\t\t\tSystem.out.println();\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tint curL = ps.length-1, curR = 0;\n\t\t\t\tTreeSet pts = new TreeSet();\n\t\t\t\tpts.add(ps[curL]); pts.add(ps[curR]);\n\t\t\t\twhile(true) {\n\t\t\t\t\twhile(ps[curL].polyRemoveId == 0) {\n\t\t\t\t\t\tif(curL == curR) break;\n\t\t\t\t\t\tcurL = (curL - 1 + ps.length)%ps.length;\n\t\t\t\t\t\tpts.add(ps[curL]);\n\t\t\t\t\t}\n\t\t\t\t\twhile(ps[curR].polyRemoveId == 0) {\n\t\t\t\t\t\tif(curL == curR) break;\n\t\t\t\t\t\tcurR = (curR + 1)%ps.length;\n\t\t\t\t\t\tpts.add(ps[curR]);\n\t\t\t\t\t}\n\t\t\t\t\tif(ps[curL].polyRemoveId == -1) res += getArea(tsToArray(pts));\n\t\t\t\t\tpts.clear();\n\t\t\t\t\tif(curR == curL) break;\n\t\t\t\t\tpts.add(ps[curL]);\n\t\t\t\t\tpts.add(ps[curR]);\n\t\t\t\t\tcurL = (curL - 1 + ps.length)%ps.length;\n\t\t\t\t\tcurR = (curR + 1)%ps.length;\n\t\t\t\t\tpts.add(ps[curL]);\n\t\t\t\t\tpts.add(ps[curR]);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\treturn res;\n\t\t\t}\n\t\t}\n\t\t\n\t\t@Override\n\t\tpublic int compareTo(Poly o) {\n\t\t\tif(id == o.id) return 0;\n\t\t\tif(fSeg.inFrontOf(o.fSeg)) return -1;\n\t\t\treturn 1;\n\t\t}\n\t\t\n\t}\n\tstatic Vec[] tsToArray(TreeSet tss){\n\t\tVec res[] = new Vec[tss.size()];\n\t\tint idd = 0;\n\t\tfor(Vec v : tss) res[idd++] = v;\n\t\treturn res;\n\t}\n\tstatic double getArea(Vec[] vs) {\n\t\tif(debug) {\n\t\t\tSystem.out.println(\"AREA:\");\n\t\t\tfor(Vec v : vs) System.out.println(\" \"+v);\n\t\t}\n\t\tdouble res = 0;\n\t\tfor(int i = 0; i < vs.length; i++) {\n\t\t\tVec a = vs[i];\n\t\t\tVec b = vs[(i+1)%vs.length];\n\t\t\tres += (b.x - a.x) * ((b.y + a.y)/2.0); \n\t\t}\n\t\tif(debug)System.out.println(\" a=\"+Math.abs(res));\n\t\treturn Math.abs(res);\n\t}\n\t\n\tstatic boolean eq(double a, double b) {\n\t\treturn Math.abs(a-b) <= eps;\n\t}\n\t\n\tstatic class FS{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FS() { br = new BufferedReader(new InputStreamReader(System.in));}\n\t\tString next() {\n\t\t\twhile(st == null || !st.hasMoreElements()) {\n\t\t\t\ttry { st = new StringTokenizer(br.readLine());}\n\t\t\t\tcatch(Exception e) { throw null;}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tint nextInt() { return Integer.parseInt(next());}\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3a4678ea76d33be558753c68b4fb61a8", "src_uid": "f88b322137318b2fbae4f54a613b170c", "difficulty": 3000.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class E {\n static Scanner sc = new Scanner(System.in);\n static final double logE = Math.log(Math.E);\n\n public static void main(String[] args) {\n int V = sc.nextInt();\n double[] factLog = new double[3001];\n for (int i = 1; i < factLog.length; i++) {\n factLog[i] = Math.log(i) + factLog[i - 1];\n }\n for (int i = 0; i < V; i++) {\n int[] K = new int[250];\n long sum = 0;\n for (int j = 0; j < K.length; j++) {\n K[j] = sc.nextInt();\n sum += K[j];\n }\n double P = sum * 1.0 / K.length;\n double uniform = -Math.log(2 * P + 1) * K.length;\n double poisson = 0;\n for (int j = 0; j < K.length; j++) {\n poisson += K[j] * Math.log(P) - P * logE - factLog[K[j]];\n }\n// System.err.println(uniform + \" \" + poisson);\n int bestI = 0;\n if (uniform < poisson) {\n double bestLikelyhood = -Double.MAX_VALUE;\n for (int j = Math.max(10, (int) P - 10); j <= (int) P + 10; j++) {\n double likelyhood = 0;\n for (int k = 0; k < K.length; k++) {\n likelyhood += K[k] * Math.log(j) - j * logE;\n }\n if (likelyhood > bestLikelyhood) {\n bestLikelyhood = likelyhood;\n bestI = j;\n }\n }\n } else {\n bestI = (int) P;\n }\n System.out.println(bestI);\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f15eef585d0ba8d039681961d42d298a", "src_uid": "18bf2c587415f85df83fb090e16b8351", "difficulty": 2200.0} {"lang": "Java 6", "source_code": "import java.util.*;\n\n/**\n * Created by IntelliJ IDEA.\n * User: piyushd\n * Date: 3/29/11\n * Time: 7:56 PM\n * To change this template use File | Settings | File Templates.\n */\npublic class TaskD {\n\n final int MOD = 1000000007;\n\n void run() {\n String start = next();\n String end = next();\n int K = nextInt();\n int N = start.length();\n\n if (K == 0) {\n if (start.equals(end)) {\n System.out.println(1);\n } else {\n System.out.println(0);\n }\n\n return;\n }\n\n long[] dp = new long[N];\n Arrays.fill(dp, 1);\n dp[0] = 0;\n\n for (int i = 1; i < K; i++) {\n long sum = 0;\n for (int j = 0; j < N; j++) sum += dp[j];\n sum %= MOD;\n\n for (int j = 0; j < N; j++) dp[j] = (sum - dp[j] + MOD) % MOD;\n }\n\n long ans = 0;\n String s1, s2;\n for (int i = 0; i < N; i++) {\n s1 = start.substring(0, i);\n s2 = start.substring(i);\n\n if (end.equals(s2.concat(s1))) {\n ans += dp[i];\n if (ans >= MOD) ans -= MOD;\n }\n }\n\n System.out.println(ans);\n }\n\n int nextInt() {\n try {\n int c = System.in.read();\n if (c == -1) return c;\n while (c != '-' && (c < '0' || '9' < c)) {\n c = System.in.read();\n if (c == -1) return c;\n }\n if (c == '-') return -nextInt();\n int res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = System.in.read();\n } while ('0' <= c && c <= '9');\n return res;\n } catch (Exception e) {\n return -1;\n }\n }\n\n long nextLong() {\n try {\n int c = System.in.read();\n if (c == -1) return -1;\n while (c != '-' && (c < '0' || '9' < c)) {\n c = System.in.read();\n if (c == -1) return -1;\n }\n if (c == '-') return -nextLong();\n long res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = System.in.read();\n } while ('0' <= c && c <= '9');\n return res;\n } catch (Exception e) {\n return -1;\n }\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String next() {\n try {\n StringBuilder res = new StringBuilder(\"\");\n int c = System.in.read();\n while (Character.isWhitespace(c))\n c = System.in.read();\n do {\n res.append((char) c);\n } while (!Character.isWhitespace(c = System.in.read()));\n return res.toString();\n } catch (Exception e) {\n return null;\n }\n }\n\n String nextLine() {\n try {\n StringBuilder res = new StringBuilder(\"\");\n int c = System.in.read();\n while (c == '\\r' || c == '\\n')\n c = System.in.read();\n do {\n res.append((char) c);\n c = System.in.read();\n } while (c != '\\r' && c != '\\n');\n return res.toString();\n } catch (Exception e) {\n return null;\n }\n }\n\n public static void main(String[] args) {\n new TaskD().run();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b4facc41defddb371e52a51daac06c94", "src_uid": "414000abf4345f08ede20798de29b9d4", "difficulty": 1700.0} {"lang": "Java 8", "source_code": "import com.sun.javafx.geom.Edge;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class F {\n\n\tstatic final int INF = (int)1e9;\n\tstatic ArrayList[] adjList;\n\tstatic int[][] res, cost;\n\tstatic int[] p;\n\n\tstatic void addEdge(int u, int v, int c, int w)\n\t{\n\t\tadjList[u].add(v);\n\t\tadjList[v].add(u);\n\t\tres[u][v] = c;\n\t\tcost[u][v] = w;\n\t\tcost[v][u] = -w;\n\t}\n\n\tstatic int augment(int v, int flow)\n\t{\n\t\tif(v == src)\n\t\t\treturn flow;\n\t\tint u = p[v];\n\t\tflow = augment(u, Math.min(flow, res[u][v]));\n\t\tres[u][v] -= flow;\n\t\tres[v][u] += flow;\n\t\ttotalCost += flow * cost[u][v];\n\t\treturn flow;\n\t}\n\n\tstatic int totalCost;\n\n\tstatic int mcmf(int V)\n\t{\n\t\ttotalCost = 0;\n\n\t\twhile(true)\n\t\t{\n\t\t\tp = new int[V];\n\t\t\tArrays.fill(p, -1);\n\t\t\tp[0] = 0;\n\t\t\tint[] dist = new int[V];\n\t\t\tArrays.fill(dist, INF);\n\t\t\tboolean[] inQueue = new boolean[V];\n\t\t\tint[] cntIn = new int[V];\n\n\t\t\tdist[0] = 0;\n\t\t\tQueue q = new LinkedList<>();\n\t\t\tq.add(0);\n\t\t\tinQueue[0] = true;\n\t\t\twhile(!q.isEmpty())\n\t\t\t{\n\t\t\t\tint u = q.remove();\n\t\t\t\tfor(int v: adjList[u])\n\t\t\t\t\tif(res[u][v] > 0 && dist[v] > dist[u] + cost[u][v])\n\t\t\t\t\t{\n\t\t\t\t\t\tdist[v] = dist[u] + cost[u][v];\n\t\t\t\t\t\tp[v] = u;\n\t\t\t\t\t\tif(!inQueue[v])\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tinQueue[v] = true;\n\t\t\t\t\t\t\tif(++cntIn[v] <= V)\n\t\t\t\t\t\t\t\tq.add(v);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t}\n\n\t\t\tif(p[sink] == -1)\n\t\t\t\tbreak;\n\t\t\taugment(sink, INF);\n\t\t}\n\t\treturn totalCost;\n\t}\n\n\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\n\t\tint n = sc.nextInt();\n\t\tchar[] s = sc.next().toCharArray();\n\t\tint[] f = new int[26];\n\t\tfor(char c: s)\n\t\t\tf[c - 'a']++;\n\t\tint[] beu = new int[n];\n\t\tint sum = 0;\n\t\tfor(int i = 0; i < n; ++i)\n\t\t\tsum += beu[i] = sc.nextInt();\n\n\t\tint gateOffset = 2, nodeOffset = gateOffset + n / 2 * 26, charOffset = nodeOffset + n;\n\t\tint V = charOffset + 26;\n\t\tres = new int[V][V];\n\t\tcost = new int[V][V];\n\t\tadjList = new ArrayList[V];\n\t\tfor(int i = 0; i < V; ++i)\n\t\t\tadjList[i] = new ArrayList<>(1);\n\n\t\t// Source and Sink\n\t\tsrc = 0; sink = 1;\n\n\t\t// Source -> Indices Nodes -> Limiter Gates\n\t\tfor(int i = 0; i < n; ++i)\n\t\t{\n\t\t\taddEdge(src, nodeOffset + i, 1, 0);\n\t\t\tfor(int c = 0; c < 26; ++c)\n\t\t\t{\n\t\t\t\tint x = i * 2 < n ? i : n - i - 1;\n\t\t\t\tint gateIn = gateOffset + n / 2 * c + x;\n\t\t\t\taddEdge(nodeOffset + i, gateIn, 1, s[i] - 'a' == c ? 0 : beu[i]);\n\t\t\t}\n\t\t}\n\n\t\t// Limiter Gates -> Characters -> Sink\n\t\tfor(int c = 0; c < 26; ++c)\n\t\t{\n\t\t\taddEdge(charOffset + c, sink, f[c], 0);\n\t\t\tfor(int gate = 0; gate < n / 2; ++gate)\n\t\t\t\taddEdge(gateOffset + n / 2 * c + gate, charOffset + c, 1, 0);\n\t\t}\n\n\t\tout.println(sum - mcmf(V));\n\t\tout.close();\n\t}\n\n\tstatic int src, sink;\n\n\tstatic class Scanner\n\t{\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s){\tbr = new BufferedReader(new InputStreamReader(s));}\n\n\t\tpublic Scanner(FileReader s) throws FileNotFoundException {\tbr = new BufferedReader(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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4be134389adbdf13d435866ee4601008", "src_uid": "896555ddb6e1c268cd7b3b6b063fce50", "difficulty": 2500.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\n\npublic class F38 {\n\n static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n static PrintWriter out = new PrintWriter(System.out);\n \n static int nextInt() throws IOException {\n in.nextToken();\n return Integer.valueOf(in.sval);\n }\n \n static double nextDouble() throws IOException {\n in.nextToken();\n return Double.valueOf(in.sval);\n }\n \n static String nextString() throws IOException {\n in.nextToken();\n return in.sval;\n }\n \n static {\n in.ordinaryChars('0', '9');\n in.wordChars('0', '9');\n \n in.ordinaryChars('.', '.');\n in.wordChars('.', '.');\n \n in.ordinaryChars('-', '-');\n in.wordChars('-', '-');\n }\n\n public static void main(String[] args) throws IOException {\n n = nextInt();\n voc = new String[n];\n for (int i = 0; i < n; i++)\n voc[i] = nextString();\n \n h.put(\"\", new Node(\"\"));\n nodes.offer(h.get(\"\"));\n \n for (int i = 0; i < n; i++)\n for (int j = 0; j < voc[i].length(); j++)\n for (int k = j+1; k <= voc[i].length(); k++) {\n String cur = voc[i].substring(j, k);\n if (!h.containsKey(cur)) {\n h.put(cur, new Node(cur));\n nodes.offer(h.get(cur));\n }\n }\n \n for (Node node : nodes)\n for (int i = 0; i < n; i++)\n if (voc[i].indexOf(node.s) >= 0)\n node.cnt++;\n \n for (Node node : nodes) {\n for (int i = 0; i < 26; i++) {\n String cur = (char)(i+'a') + node.s;\n if (h.containsKey(cur)) node.g.add(h.get(cur));\n }\n for (int i = 0; i < 26; i++) {\n String cur = node.s + (char)(i+'a');\n if (h.containsKey(cur)) node.g.add(h.get(cur));\n }\n }\n \n for (Node node : nodes)\n if (node.points == null)\n play(node);\n \n /*for (Node node : nodes) {\n out.println(node.s);\n out.print(node.cnt);\n out.print(\" \" + node.g.size());\n out.println(\" \" + node.value);\n out.println(node.points[0] + \" \" + node.points[1]);\n out.println();\n }*/\n \n Node ans = h.get(\"\");\n out.println(ans.points[0] > ans.points[1] ? \"First\" : \"Second\");\n out.println(ans.points[0] + \" \" + ans.points[1]);\n \n out.flush();\n }\n\n static final int M = 30;\n static HashMap h = new HashMap(M*M*M);\n static int n;\n static String[] voc;\n static LinkedList nodes = new LinkedList();\n \n static void play(Node node) {\n for (Node go : node.g) {\n if (go.points == null) play(go);\n int a = go.points[1] + go.value + go.cnt, b = go.points[0];\n if (node.points == null) {\n node.points = new int[]{a, b};\n }\n else if (better(a, b, node.points[0], node.points[1])) {\n node.points[0] = a;\n node.points[1] = b;\n }\n }\n if (node.points == null) {\n node.points = new int[]{0, 0};\n }\n }\n \n static boolean better(int a1, int b1, int a2, int b2) {\n if (a2 > b2 && a1 < b1) return false;\n if (a2 > b2 && a1 > b1) return a1 > a2 || (a1 == a2 && b1 < b2);\n if (a2 < b2 && a1 < b1) return a1 > a2 || (a1 == a2 && b1 < b2);\n if (a2 < b2 && a1 > b1) return true;\n if (a2 == b2 && a1 > b1) return true;\n if (a2 == b2 && a1 < b1) return false;\n if (a2 > b2 && a1 == b1) return false;\n if (a2 < b2 && a1 == b1) return true;\n return a1 > a2;\n }\n}\n\nclass Node {\n String s;\n int cnt = 0, value;\n HashSet g = new HashSet();\n int[] points;\n \n public Node(String s) {\n this.s = s;\n int max = Integer.MIN_VALUE;\n for (int i = 0; i < s.length(); i++) {\n int x = s.charAt(i) - 'a' + 1;\n value += x;\n max = Math.max(max, x);\n }\n value *= max;\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f00fd1f1c4d8a3e75f479525112392df", "src_uid": "d0f8976d9b847f7426dc56cb59b5b5b9", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "//package Hackerearth;\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\n\npublic class Reducto \n {\n\t\n\tpublic static void main(String[] gud) throws IOException\n\t{\n\t\tBufferedReader br=new BufferedReader(newInputStreamReader(System.in));\n\t\t\n\t\tString s=br.readLine().trim();\n\t\tint m=(s.length()-1)/2 ;\n\t\tint a=(int)(s.charAt(m)-'0');\n\t\tif((a&1)==1)System.out.println(\"Yes\");\n\t\telse System.out.println(\"No\");\n\t }\n\n\t \n\tpublic static class Rational implements Comparable {\n\t\tBigInteger num;\n\t\tBigInteger den;\n \n\t\tpublic static final Rational ZERO = new Rational(0);\n\t\tpublic static final Rational ONE = new Rational(1);\n\t\tpublic static final Rational POSITIVE_INFINITY = new Rational(1, 0);\n\t\tpublic static final Rational NEGATIVE_INFINITY = new Rational(-1, 0);\n \n\t\tpublic Rational(long num) {\n\t\t\tthis.num = BigInteger.valueOf(num);\n\t\t\tthis.den = BigInteger.ONE;\n\t\t}\n \n\t\tpublic Rational(long num, long den) {\n\t\t\tthis.num = BigInteger.valueOf(num);\n\t\t\tthis.den = BigInteger.valueOf(den);\n\t\t\treduce();\n\t\t}\n \n\t\tpublic Rational(BigInteger num, BigInteger den) {\n\t\t\tthis.num = num;\n\t\t\tthis.den = den;\n\t\t\treduce();\n\t\t}\n \n\t\tvoid reduce() {\n\t\t\tBigInteger gcd = num.gcd(den);\n\t\t\tif (gcd.signum() != 0) {\n\t\t\t\tnum = num.divide(gcd);\n\t\t\t\tden = den.divide(gcd);\n\t\t\t}\n\t\t\tif (den.signum() < 0) {\n\t\t\t\tnum = num.negate();\n\t\t\t\tden = den.negate();\n\t\t\t}\n\t\t}\n \n\t\tpublic Rational add(Rational r) {\n\t\t\treturn new Rational(num.multiply(r.den).add(r.num.multiply(den)),\n\t\t\t\t\tden.multiply(r.den));\n\t\t}\n \n\t\tpublic Rational sub(Rational r) {\n\t\t\treturn new Rational(num.multiply(r.den).subtract(\n\t\t\t\t\tr.num.multiply(den)), den.multiply(r.den));\n\t\t}\n \n\t\tpublic Rational mul(Rational r) {\n\t\t\treturn new Rational(num.multiply(r.num), den.multiply(r.den));\n\t\t}\n \n\t\tpublic Rational div(Rational r) {\n\t\t\treturn new Rational(num.multiply(r.den), den.multiply(r.num));\n\t\t}\n \n\t\tpublic Rational negate() {\n\t\t\treturn new Rational(num.negate(), den);\n\t\t}\n \n\t\tpublic Rational inverse() {\n\t\t\treturn new Rational(den, num);\n\t\t}\n \n\t\tpublic Rational abs() {\n\t\t\treturn new Rational(num.abs(), den);\n\t\t}\n \n\t\tpublic int signum() {\n\t\t\treturn num.signum();\n\t\t}\n \n\t\tpublic double doubleValue() {\n\t\t\treturn num.doubleValue() / den.doubleValue();\n\t\t}\n \n\t\tpublic int compareTo(Rational other) {\n\t\t\treturn (num.multiply(other.den).compareTo(other.num.multiply(den)));\n\t\t}\n \n\t\tpublic boolean equals(Object obj) {\n\t\t\treturn obj instanceof Rational && num.equals(((Rational) obj).num)\n\t\t\t\t\t&& den.equals(((Rational) obj).den);\n\t\t}\n \n\t\tpublic int hashCode() {\n\t\t\treturn num.hashCode() * 31 + den.hashCode();\n\t\t}\n \n\t\tpublic String toString() {\n\t\t\tif (den.equals(BigInteger.ONE)) {\n\t\t\t\treturn num.toString();\n\t\t\t}\n\t\t\tif (num.compareTo(den) < 0) {\n\t\t\t\treturn num + \"/\" + den;\n\t\t\t}\n\t\t\treturn num.divide(den) + \" \" + num.mod(den) + \"/\" + den;\n\t\t}\n\t}\n\t\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "20c083e7f7b8e42850bcd4e7540b6c68", "src_uid": "0f11f41cefd7cf43f498e511405426c3", "difficulty": 1900.0} {"lang": "Java 6", "source_code": "//package school3;\n\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.BitSet;\nimport java.util.HashSet;\nimport java.util.Scanner;\n\npublic class F4 {\n Scanner in;\n PrintWriter out;\n //\tString INPUT = \"100000 3\";\n //String INPUT = \"100000 2\";\n String INPUT = \"\";\n\t\n int[] dec(int n, int m)\n {\n\tif(n <= m){\n\t return new int[]{n, 0};\n\t}else if(n <= 2 * m){\n\t return new int[]{n - m, n - m};\n\t}else{\n\t return new int[]{n - 2 * m - 1, m};\n\t}\n }\n\t\n int enc(int x, int y, int m)\n {\n\tif(y == 0){\n\t return x;\n\t}else if(x == y){\n\t return x + m;\n\t}else{\n\t return x + 2 * m + 1;\n\t}\n }\n\t\n void solve()\n {\n\tint m = ni();\n\tint n = ni();\t\n\tif(n <= Math.sqrt(Math.sqrt(m))){\n\t solveH(m, n);\n\t}else{\n\t solveB(m, n);\n\t}\n }\n\t\n void solveB(int m, int n){\n\t// (a, 0), (a, a), (a, m)\n\tBitSet visitedo = new BitSet();\n\tBitSet visitedh = new BitSet();\n\tint[] stepo = new int[3 * m+1];\n\tint[] steph = new int[3 * m+1];\n\tArrays.fill(stepo, -1);\n\tArrays.fill(steph, -1);\n\tBitSet q = new BitSet();\n\tq.set(0);\n\tboolean iso = true;\n\tint step = 0;\n\t\t\t\n\touter:\n\twhile(!q.isEmpty()){\n\t //\t\t\t\ttr(step, q);\n\t BitSet nq = new BitSet();\n\t if(iso){\n\t\tvisitedh.or(q);\n\t }else{\n\t\tvisitedo.or(q);\n\t }\n\t for(int cur = q.nextSetBit(0);cur != -1;cur = q.nextSetBit(cur+1)){\n\t\tif(!iso && cur == 2 * m)break outer;\n\t\tint[] co = dec(cur, m);\n\t\tif(iso){\n\t\t {\n\t\t\tif(co[1] == 0){\n\t\t\t int inf = co[0] + 1;\n\t\t\t int sup = Math.min(m, co[0] + n);\n\t\t\t if(inf <= sup){\n\t\t\t\tnq.set(enc(inf, 0, m), enc(sup, 0, m) + 1);\n\t\t\t }\n\t\t\t}\n\t\t }\n\t\t {\n\t\t\tint inf = Math.max(co[0], co[1]);\n\t\t\tif(co[0] == co[1])inf++;\n\t\t\tint sup = Math.min(m, (n + co[0] + co[1]) / 2);\n\t\t\t\t\t\t\t\n\t\t\tif(inf <= sup){\n\t\t\t nq.set(enc(inf, inf, m), enc(sup, sup, m) + 1);\n\t\t\t}\n\t\t }\n\t\t {\n\t\t\tint inf = co[0];\n\t\t\tif(co[1] == m)inf++;\n\t\t\tint sup = Math.min(m - 1, co[0] + n - m + co[1]);\n\t\t\tif(inf <= sup){\n\t\t\t nq.set(enc(inf, m, m), enc(sup, m, m) + 1);\n\t\t\t}\n\t\t }\n\t\t}else{\n\t\t {\n\t\t\tif(co[1] == m){\n\t\t\t int inf = co[0] - 1;\n\t\t\t int sup = Math.max(0, co[0] - n);\n\t\t\t if(sup <= inf){\n\t\t\t\tnq.set(enc(sup, m, m), enc(inf, m, m) + 1);\n\t\t\t }\n\t\t\t}\n\t\t }\n\t\t {\n\t\t\tint inf = Math.min(co[0], co[1]);\n\t\t\tif(co[0] == co[1])inf--;\n\t\t\tint sup = Math.max(0, (-n + co[0] + co[1]) / 2);\n\t\t\t\t\t\t\t\n\t\t\tif(sup == 0)sup++;\n\t\t\tif(sup <= inf){\n\t\t\t nq.set(enc(sup, sup, m), enc(inf, inf, m) + 1);\n\t\t\t}\n\t\t }\n\t\t {\n\t\t\tint inf = co[0];\n\t\t\tif(co[1] == 0)inf--;\n\t\t\tint sup = Math.max(0, co[0] - n + co[1]);\n\t\t\tif(sup <= inf){\n\t\t\t nq.set(enc(sup, 0, m), enc(inf, 0, m) + 1);\n\t\t\t}\n\t\t }\n\t\t}\n\t }\n\t if(iso){\n\t\tnq.andNot(visitedo);\n\t\tfor(int i = nq.nextSetBit(0);i != -1;i = nq.nextSetBit(i+1)){\n\t\t int[] z = dec(i, m);\n\t\t if(steph[enc(m - z[0], m - z[1], m)] >= 0){\n\t\t\tout.println(2 * step + 1);\n\t\t\treturn;\n\t\t }\n\t\t stepo[i] = step;\n\t\t}\n\t }else{\n\t\tnq.andNot(visitedh);\n\t\tfor(int i = nq.nextSetBit(0);i != -1;i = nq.nextSetBit(i+1)){\n\t\t int[] z = dec(i, m);\n\t\t if(stepo[enc(m - z[0], m - z[1], m)] >= 0){\n\t\t\tout.println(2 * step + 1);\n\t\t\tassert false;\n\t\t\treturn;\n\t\t }\n\t\t steph[i] = step;\n\t\t}\n\t }\n\t q = nq;\n\t step++;\n\t iso = !iso;\n\t}\n\tif(q.isEmpty()){\n\t out.println(-1);\n\t}else{\n\t //out.println(step);\n\t //while(true);\n\t //assert false;\n\t}\n }\n\t\n void solveH(int m, int n){\n\t\t\n\t// (a, 0), (a, a), (a, m)\n\tHashSet visitedo = new HashSet();\n\tHashSet visitedh = new HashSet();\n\tint[] stepo = new int[3 * m+1];\n\tint[] steph = new int[3 * m+1];\n\tArrays.fill(stepo, -1);\n\tArrays.fill(steph, -1);\n\tHashSet q = new HashSet();\n\tq.add(0);\n\tboolean iso = true;\n\tint step = 0;\n\t\t\n\touter:\n\twhile(!q.isEmpty()){\n\t //\t\t\ttr(step, q);\n\t HashSet nq = new HashSet();\n\t if(iso){\n\t\tvisitedh.addAll(q);\n\t }else{\n\t\tvisitedo.addAll(q);\n\t }\n\t for(int cur : q){\n\t\tif(!iso && cur == 2 * m)break outer;\n\t\tint[] co = dec(cur, m);\n\t\tif(iso){\n\t\t {\n\t\t\tif(co[1] == 0){\n\t\t\t int inf = co[0] + 1;\n\t\t\t int sup = Math.min(m, co[0] + n);\n\t\t\t if(inf <= sup){\n\t\t\t\tfor(int i = enc(inf, 0, m);i <= enc(sup, 0, m);i++){\n\t\t\t\t nq.add(i);\n\t\t\t\t}\n\t\t\t }\n\t\t\t}\n\t\t }\n\t\t {\n\t\t\tint inf = Math.max(co[0], co[1]);\n\t\t\tif(co[0] == co[1])inf++;\n\t\t\tint sup = Math.min(m, (n + co[0] + co[1]) / 2);\n\t\t\t\t\t\t\n\t\t\tif(inf <= sup){\n\t\t\t for(int i = enc(inf, inf, m);i <= enc(sup, sup, m);i++){\n\t\t\t\tnq.add(i);\n\t\t\t }\n\t\t\t}\n\t\t }\n\t\t {\n\t\t\tint inf = co[0];\n\t\t\tif(co[1] == m)inf++;\n\t\t\tint sup = Math.min(m - 1, co[0] + n - m + co[1]);\n\t\t\tif(inf <= sup){\n\t\t\t for(int i = enc(inf, m, m);i <= enc(sup, m, m);i++){\n\t\t\t\tnq.add(i);\n\t\t\t }\n\t\t\t}\n\t\t }\n\t\t}else{\n\t\t {\n\t\t\tif(co[1] == m){\n\t\t\t int inf = co[0] - 1;\n\t\t\t int sup = Math.max(0, co[0] - n);\n\t\t\t if(sup <= inf){\n\t\t\t\tfor(int i = enc(sup, m, m);i <= enc(inf, m, m);i++){\n\t\t\t\t nq.add(i);\n\t\t\t\t}\n\t\t\t }\n\t\t\t}\n\t\t }\n\t\t {\n\t\t\tint inf = Math.min(co[0], co[1]);\n\t\t\tif(co[0] == co[1])inf--;\n\t\t\tint sup = Math.max(0, (-n + co[0] + co[1]) / 2);\n\t\t\t\t\t\t\n\t\t\tif(sup == 0)sup++;\n\t\t\tif(sup <= inf){\n\t\t\t for(int i = enc(sup, sup, m);i <= enc(inf, inf, m);i++){\n\t\t\t\tnq.add(i);\n\t\t\t }\n\t\t\t}\n\t\t }\n\t\t {\n\t\t\tint inf = co[0];\n\t\t\tif(co[1] == 0)inf--;\n\t\t\tint sup = Math.max(0, co[0] - n + co[1]);\n\t\t\tif(sup <= inf){\n\t\t\t for(int i = enc(sup, 0, m);i <= enc(inf, 0, m);i++){\n\t\t\t\tnq.add(i);\n\t\t\t }\n\t\t\t}\n\t\t }\n\t\t}\n\t }\n\t if(iso){\n\t\tnq.removeAll(visitedo);\n\t\tfor(int i : nq){\n\t\t int[] z = dec(i, m);\n\t\t if(steph[enc(m - z[0], m - z[1], m)] >= 0){\n\t\t\tout.println(2 * step + 1);\n\t\t\treturn;\n\t\t }\n\t\t stepo[i] = step;\n\t\t}\n\t }else{\n\t\tnq.removeAll(visitedh);\n\t\tfor(int i : nq){\n\t\t int[] z = dec(i, m);\n\t\t if(stepo[enc(m - z[0], m - z[1], m)] >= 0){\n\t\t\tout.println(2 * step + 1);\n\t\t\tassert false;\n\t\t\treturn;\n\t\t }\n\t\t steph[i] = step;\n\t\t}\n\t }\n\t q = nq;\n\t step++;\n\t iso = !iso;\n\t}\n\tif(q.isEmpty()){\n\t out.println(-1);\n\t}else{\n\t //out.println(step);\n\t //while(true);\n\t //assert false;\n\t}\n }\n\t\n void run() throws Exception\n {\n\tin = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);\n\tout = new PrintWriter(System.out);\n\n\t//\t\tlong s = System.currentTimeMillis();\n\tsolve();\n\tout.flush();\n\t//\t\tlong g = System.currentTimeMillis();\n\t//\t\tSystem.out.println(g - s + \"ms\");\n }\n\t\n\t\n public static void main(String[] args) throws Exception\n {\n\tnew F4().run();\n }\n\t\n int ni() { return Integer.parseInt(in.next()); }\n 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", "compilation_error": false, "code_uid": "5cf02dfc8169632eb97ab6f9457e4005", "src_uid": "83f1d50a1802e08dd154d4c9778e3d80", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Codechef {\n \n static class MyScanner{\n BufferedReader br;\n\tStringTokenizer st;\n\n\tMyScanner(FileReader fileReader){\n br = new BufferedReader(fileReader);\n\t}\n\n\tMyScanner(){\n br = new BufferedReader(new InputStreamReader(System.in));\n\t}\n\n\tString nn(){\n while(st == null || !st.hasMoreElements()){\n\t\ttry{\n st = new StringTokenizer(br.readLine());\n\t\t}catch(IOException e){\n e.printStackTrace();\n\t\t}\n }\n return st.nextToken();\n\t}\n\n\tchar nc(){\n return nn().charAt(0);\n\t}\n\n\tint ni(){\n return Integer.parseInt(nn());\n\t}\n\n\tlong nl(){\n return Long.parseLong(nn());\n\t}\n\n\tdouble nd(){\n return Double.parseDouble(nn());\n\t}\n\n\tint[] niArr0(int n){\n int[] ar = new int[n];\n for(int i = 0; i < n; i++) ar[i] = ni();\n return ar;\n\t}\n\n int[] niArr1(int n){\n int[] ar = new int[n + 1];\n for(int i = 1; i <= n; i++) ar[i] = ni();\n return ar;\n\t}\n\n long[] nlArr0(int n){\n long[] ar = new long[n];\n for(int i = 0; i < n; i++) ar[i] = nl();\n return ar;\n }\n\n long[] nlArr1(int n){\n long[] ar = new long[n + 1];\n for(int i = 1; i <= n; i++) ar[i] = nl();\n return ar;\n }\n }\n\n public static void mprintln(T ... ar){\n for(T i: ar) out.print(i + \" \");\n out.println();\n }\n\n private static PrintWriter out;\n\n public static void main(String[] args) throws FileNotFoundException{\n\n // Input from file\n // File inputFile = new File(\"JavaFile.txt\");\n // File outputFile = new File(\"JavaOutputFile.txt\");\n // FileReader fileReader = new FileReader(inputFile);\n // Here it ends\n\n MyScanner sc = new MyScanner();\n // MyScanner sc = new MyScanner(fileReader);\n\n out = new PrintWriter(new BufferedOutputStream(System.out)); // Output to console\n // out = new PrintWriter(new PrintStream(outputFile)); // Output to file\n\n getAns(sc);\n\n out.close();\n }\n \n private static void getAns(MyScanner sc){\n int n = sc.ni(), m = sc.ni();\n int[] k = sc.niArr0(n);\n HashMap> map = new HashMap();\n \n for(int i = 0; i < m; i++){\n int day = sc.ni();\n map.putIfAbsent(day, new ArrayList<>());\n map.get(day).add(sc.ni());\n }\n \n int start = 1, end = 2 * (int)1e5;\n int ans = end;\n \n// out.println(map);\n \n while(start <= end){\n int mid = start + (end - start) / 2;\n if(OK(mid, map, Arrays.copyOf(k, n), n)){\n ans = mid;\n end = mid - 1;\n }else{\n start = mid + 1;\n }\n }\n \n out.println(ans);\n }\n \n private static boolean OK(int days, HashMap> map, int[] k, int n){\n int cur = 0;\n// out.println(days);\n \n for(int i = 1; i <= days; i++){\n ++cur;\n ArrayList index = map.get(i);\n if(index == null) continue;\n for(Integer in: index){\n int min = Math.min(cur, k[in - 1]);\n cur -= min;\n k[in - 1] -= min;\n }\n }\n \n for(int i = 0; i < n; i++) cur -= 2 * k[i];\n \n return cur >= 0;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c0238645b8b4fc622a03bde0b6183518", "src_uid": "2eb101dcfcc487fe6e44c9b4c0e4024d", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "import java.util.ArrayList;\nimport java.util.Scanner;\nimport java.lang.Integer;\n\npublic class FlowGraph {\n\tint[][] graph;\n\tint[][] flow;\n\tint[] path;\n\tint[][] capacity;\n\tint size;\n\tint maxFlow = 0;\n\t\n\tpublic FlowGraph(int[][] capacity){\n\t\t//Scanner scanner = new Scanner(System.in);\n\t\tsize = capacity.length;\n\t\tflow = new int[size][size];\n\t\tgraph= new int[size][size];\n\t\tthis.capacity = capacity;\t\t\n\t\t\n\t}\n\t\n\n\tint edmundKarp(){\n\t\tpath = new int[size];\n\t\tfor(int i = 0; i < size; i++){\n\t\t\tpath[i] = -1;\t\t\t\n\t\t}\n\t\twhile(hasPath()){\n\t\t\tint cMin = 200000;\n\t\t\tint v = size - 1;\n\t\t\twhile(v != 0){\n\t\t\t\tint u = path[v];\n\t\t\t\tif(capacity[u][v] - flow[u][v] < cMin ) cMin = capacity[u][v] - flow[u][v];\n\t\t\t\tv = u;\n\t\t\t\t\n\t\t\t}\n\t\t\tv = size - 1;\n\t\t\twhile(v != 0){\n\t\t\t\tint u = path[v];\n\t\t\t\t\n\t\t\t\tflow[u][v] += cMin;\n\t\t\t\tflow[v][u] -= cMin;\n\t\t\t\tv = u;\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t}\n\t\tint maxFlow = 0;\n\t\tfor(int i = 0; i < size; ++i){\n\t\t\tmaxFlow += flow[i][size - 1];\n\t\t\t\n\t\t}\n\t\treturn maxFlow;\n\t\t\n\t}\n\tboolean hasPath(){\n\t\tboolean[] visited = new boolean[size];\n\t\tArrayList o = new ArrayList<>();\n\t\to.add(0);\n\t\tvisited[0] = true;\n\t\tint v = 0;\n\t\twhile(!o.isEmpty() && v != size - 1){\n\t\t\tint u = o.remove(o.size()-1);\n\t\t\tfor(int i = 0; i < size;++i){\n\t\t\t\tif(capacity[u][i] - flow[u][i] > 0 && !visited[i]){\n\t\t\t\t\tpath[i] = u;\n\t\t\t\t\tvisited[i] = true;\n\t\t\t\t\to.add(0,i);\n\t\t\t\t\tv = i;\n\t\t\t\t\tif(v == size - 1) break;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t}\n\t\tif(o.isEmpty()) return false;\n\t\treturn true;\n\t\t\n\t\t\n\t}\n\t\n\tint findMaxFlow(){\n\t\tfor(int i = 1; i < size; ++i){\n\t\t\tmaxFlow += flow[i][size - 1];\n\t\t}\n\t\treturn maxFlow;\n\t\t\n\t}\n\t\n\n}\n\n\npublic class Labs {\n\t\n\tstatic void paths(int[][]graph,int n){\n\t\tfor(int i = 0; i < n; ++i){\n\t\t\tfor(int j = 0; j < n; ++j){\n\t\t\t\tif(graph[i][j] == 0 && i != j) graph[i][j] = 1000;\t\t\t\t\t\n\t\t\t\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\tfor(int k = 0; k < n; ++k ){\n\t\t\tfor(int i = 0; i < n; ++i){\n\t\t\t\tfor(int j = 0; j < n; ++j){\n\t\t\t\t\tif(graph[i][k] + graph[k][j] < graph[i][j]) graph[i][j] = graph[i][k]+graph[k][j];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t}\n\t\n\tpublic static void main(String[] args){\t\t\n\t\tScanner scanner = new Scanner(System.in);\n\t\tint n = scanner.nextInt();\n\t\tint t = scanner.nextInt();\n\t\tint[][] lab = new int[n*n][n*n];\n\t\tint[][] flow = new int[n*n+2][n*n+2];\n\t\tString[] map = new String[n];\n\t\tint z = -1;\n\t\tscanner.nextLine();\n\t\tArrayList caps= new ArrayList<>(); \n\t\tfor(int i = 0; i < n; ++i){\n\t\t\tmap[i] = scanner.nextLine();\t\n\t\t\t\t\t\n\t\t}\n\t\t\n\t\tfor(int i = 0; i = 0){\n\t\t\t\t\tif(map[i].charAt(j) != 'Z') flow[0][i*n+j+1] =(int) map[i].charAt(j) - 48;\n\t\t\t\t\t\tif(map[i].charAt(j) == 'Z' ) z = i*n + j;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\tif(i > 0 && map[i-1].charAt(j) <= '9' && map[i-1].charAt(j) >= '0'){\n\t\t\t\t\t\t\tif(map[i].charAt(j) != 'Z') lab[(i-1)*n+j][i*n+j] = 1;\n\t\t\t\t\t\t\tlab[i*n+j][(i-1)*n+j] = 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(i < n - 1 && map[i+1].charAt(j) <= '9' && map[i+1].charAt(j) >= '0'){\n\t\t\t\t\t\t\tlab[i*n+j][(i+1)*n+j] = 1;\n\t\t\t\t\t\t\tif(map[i].charAt(j) != 'Z') lab[(i+1)*n+j][i*n+j] = 1; \n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(j > 0 && map[i].charAt(j-1) <= '9' && map[i].charAt(j-1) >= '0'){\n\t\t\t\t\t\t\tif(map[i].charAt(j) != 'Z') lab[(i)*n+j - 1][i*n+j] = 1;\t\t\t\t\n\t\t\t\t\t\t\t lab[i*n+j][(i)*n+j-1] = 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(j < n-1 && map[i].charAt(j+1) <= '9' && map[i].charAt(j+1) >= '0'){\n\t\t\t\t\t\t\tif(map[i].charAt(j) != 'Z') lab[(i)*n+j+1][i*n+j] = 1;\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tlab[i*n+j][(i)*n+j+1] = 1;\n\t\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\t\t\n\t\t}\t\t\n\t\tpaths(lab,n*n);\n\t\tscanner.nextLine();\n\t\tfor(int i =0; i < n; ++i){\n\t\t\tString s = scanner.nextLine();\n\t\t\tfor(int j = 0; j < n ; ++j){\n\t\t\t\tif(s.charAt(j) <= '9' && s.charAt(j) >= '1'){\n\t\t\t\t\tcaps.add(i*n+j);\n\t\t\t\t\tflow[i*n+j+1][n*n+1] = (int) s.charAt(j) - 48;\n\t\t\t\t\t\n\t\t\t\t} \n\t\t\t}\n\t\t}\n\t\tfor(int i = 0; i < n*n; ++i){\n\t\t\tif(i!= z){\n\t\t\tfor(int j = 0; j < caps.size(); ++j){\n\t\t\t\tint c = caps.get(j);\n\t\t\t\tboolean neigh = false;\n\t\t\t\tfor(int k = 0; k < n*n; ++k){\n\t\t\t\t\tif(lab[c][k] == 1){\n\t\t\t\t\t\tif(lab[i][k] < lab[z][k] && lab[i][k] <= t) neigh = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(lab[i][c] <= t && (lab[i][c] < lab[z][c] || lab[z][c] == 0 || neigh)){\n\t\t\t\t\tflow[i+1][c+1] = 10000;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t}\n\t\tFlowGraph g = new FlowGraph(flow);\n\t\tg.edmundKarp();\n\t\tSystem.out.println(g.findMaxFlow());\n\t\t\n\t\t\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "0b14f7756ba0e0a4445f6afc5d9f1283", "src_uid": "544de9c3729a35eb08c143b1cb9ee085", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n HZSShufflesCards solver = new HZSShufflesCards();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class HZSShufflesCards {\n NumberTheory.Mod998 mod = new NumberTheory.Mod998();\n int n;\n int m;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n n = in.nextInt();\n m = in.nextInt();\n\n mod.fInv(n + m);\n\n long phaseSize = 1;\n long p = 1;\n for (int i = 0; p != 0; i++) {\n p = mod.mult(mod.mult(p, n - i), mod.smallInv(n + m - i));\n phaseSize = mod.add(phaseSize, p);\n }\n\n long answer = 0;\n for (int k = 1; k <= n; k++) {\n long numPhases = mod.mult(m + k, mod.smallInv(k));\n long term = mod.mult(mod.ncr(n, k), mod.mult(numPhases, phaseSize));\n if ((k & 1) == 1)\n answer = mod.add(answer, term);\n else\n answer = mod.subtract(answer, term);\n }\n\n out.println(answer);\n }\n\n }\n\n static class InputReader {\n public final BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n\n static class Util {\n public static void ASSERT(boolean assertion) {\n if (!assertion)\n throw new AssertionError();\n }\n\n private Util() {\n }\n\n }\n\n static class IntStack {\n int[] array;\n int size = 0;\n\n public IntStack() {\n this(8);\n }\n\n public IntStack(int capacity) {\n array = new int[capacity];\n }\n\n public void push(int item) {\n if (size >= array.length)\n array = resize(array);\n array[size++] = item;\n }\n\n public int size() {\n return size;\n }\n\n public int get(int i) {\n Util.ASSERT(i < size);\n return array[i];\n }\n\n private static int[] resize(int[] array) {\n int[] newArray = new int[array.length << 1];\n System.arraycopy(array, 0, newArray, 0, array.length);\n return newArray;\n }\n\n public String toString() {\n int[] trimmed = new int[size];\n System.arraycopy(array, 0, trimmed, 0, size);\n return Arrays.toString(trimmed);\n }\n\n }\n\n static class NumberTheory {\n private static void ASSERT(boolean assertion) {\n if (!assertion)\n throw new AssertionError();\n }\n\n public abstract static class Modulus> {\n final IntStack factorial = new IntStack();\n final IntStack invFactorial = new IntStack();\n\n public abstract long modulus();\n\n public Modulus() {\n super();\n factorial.push(1);\n invFactorial.push(1);\n }\n\n public long fact(int n) {\n while (factorial.size() <= n) {\n factorial.push((int) mult(factorial.get(factorial.size() - 1), factorial.size()));\n }\n\n return factorial.get(n);\n }\n\n public long fInv(int n) {\n int lastKnown = invFactorial.size() - 1;\n\n if (lastKnown < n) {\n long[] fInv = new long[n - lastKnown];\n fInv[0] = inv(fact(n));\n for (int i = 1; i < fInv.length; i++) {\n fInv[i] = mult(fInv[i - 1], n - i + 1);\n }\n for (int i = fInv.length - 1; i >= 0; i--) {\n invFactorial.push((int) fInv[i]);\n }\n }\n\n return invFactorial.get(n);\n }\n\n public long ncr(int n, int r) {\n ASSERT(n >= 0);\n if (r < 0 || n < r)\n return 0;\n return mult(fact(n), mult(fInv(r), fInv(n - r)));\n }\n\n public long smallInv(int n) {\n return mult(fInv(n), fact(n - 1));\n }\n\n public long normalize(long x) {\n x %= modulus();\n if (x < 0)\n x += modulus();\n return x;\n }\n\n public long add(long a, long b) {\n long v = a + b;\n return v < modulus() ? v : v - modulus();\n }\n\n public long subtract(long a, long b) {\n long v = a - b;\n return v < 0 ? v + modulus() : v;\n }\n\n public long mult(long a, long b) {\n return (a * b) % modulus();\n }\n\n public long inv(long value) {\n long g = modulus(), x = 0, y = 1;\n for (long r = value; r != 0; ) {\n long q = g / r;\n g %= r;\n\n long temp = g;\n g = r;\n r = temp;\n\n x -= q * y;\n\n temp = x;\n x = y;\n y = temp;\n }\n\n ASSERT(g == 1);\n ASSERT(y == modulus() || y == -modulus());\n\n return normalize(x);\n }\n\n }\n\n public static class Mod998 extends NumberTheory.Modulus {\n public long modulus() {\n return 998_244_353L;\n }\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9ae38f3ab356cef159a649b819cd2d80", "src_uid": "9f2b59df7bef2aeee0ce71facd2b1613", "difficulty": 3000.0} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Random;\nimport java.util.TreeSet;\nimport java.util.StringTokenizer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Sabelan\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastScanner in = new FastScanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n static final long mult = (long) 1e6;\n\n public void solve(int testNumber, FastScanner in, PrintWriter out) {\n int n = in.nextInt();\n int m = in.nextInt();\n\n TreeSet hs = new TreeSet();\n for (int i = 0; i < m; i++) {\n int a = in.nextInt() - 1;\n int b = in.nextInt() - 1;\n hs.add(key(a, b));\n }\n\n if (n <= 6) {\n int e = n * (n - 1) / 2;\n\n boolean works = false;\n int[] a = new int[m];\n int[] b = new int[m];\n for (int i = 0; i < (1 << e) && !works; i++) {\n if (Integer.bitCount(i) != m) continue;\n int[] deg = new int[n];\n int bit = 0;\n int ii = 0;\n boolean badFlag = false;\n for (int j = 0; j < n; j++) {\n for (int k = j + 1; k < n; k++) {\n if ((i & (1 << bit)) != 0) {\n deg[j]++;\n deg[k]++;\n a[ii] = j;\n b[ii] = k;\n\n ii++;\n if (deg[j] > 2 || deg[k] > 2 || hs.contains(key(j, k)))\n badFlag = true;\n }\n bit++;\n }\n }\n\n if (!badFlag) {\n works = true;\n }\n }\n\n if (!works) {\n out.printf(\"-1\\n\");\n } else {\n for (int i = 0; i < m; i++) {\n out.printf(\"%d %d\\n\", a[i] + 1, b[i] + 1);\n }\n }\n } else {\n Random r = new Random();\n int runs = (int) (1e6 / n);\n for (int i = 0; i < runs; i++) {\n int[] p = new int[n];\n for (int j = 0; j < n; j++)\n p[j] = j;\n for (int j = 0; j < n - 1; j++) {\n int offSet = r.nextInt(n - j - 1) + 1;\n int k = j + offSet;\n int t = p[k];\n p[k] = p[j];\n p[j] = t;\n }\n int cnt = 0;\n for (int j = 0; j < n; j++) {\n if (!hs.contains(key(j, p[j])))\n cnt++;\n }\n\n if (cnt < m) continue;\n\n cnt = 0;\n for (int j = 0; j < n; j++) {\n if (!hs.contains(key(j, p[j]))) {\n cnt++;\n out.printf(\"%d %d\\n\", j + 1, p[j] + 1);\n if (cnt == m) return;\n }\n }\n }\n\n out.printf(\"-1\\n\");\n }\n }\n\n static long key(int a, int b) {\n if (a <= b) return a * mult + b;\n return key(b, a);\n }\n\n}\n\nclass FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(InputStream in) {\n br = new BufferedReader(new InputStreamReader(in));\n st = new StringTokenizer(\"\");\n }\n\n public String next() {\n try {\n if (st.hasMoreTokens()) return st.nextToken();\n st = new StringTokenizer(br.readLine());\n return next();\n } catch (Exception e) {\n return \"\";\n }\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9d46b1f4e558ff2c35a0e24720a82e15", "src_uid": "c4c85cde8a5bb5fefa4eb68fc68657d5", "difficulty": 2400.0} {"lang": "Java 7", "source_code": "import java.io.*; \nimport java.util.*;\nimport java.math.*;\nimport java.awt.geom.*;\n\nimport static java.lang.Math.*;\n\npublic class Solution implements Runnable {\n\t\n\n\tpublic void solve () throws Exception {\n\t\tchar c [] = nextToken().toCharArray();\n\t\t\n\t\tint n = c.length;\n\t\t\n\t\tint e [] = new int [n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (c[i] == 'B') e [i] = 1;\n\t\t}\n\t\t\n\t\tlong d [][][][][] = new long [n + 1][2][2][2][2];\n\t\t\n\t\tif (c[0] == 'A') {\n\t\t\td[1][0][0][0][0] = 1;\n\t\t\td[1][0][1][1][1] = 1;\n\t\t} else {\n\t\t\td[1][0][1][0][1] = 1;\n\t\t\td[1][0][0][1][0] = 1;\n\t\t}\n\t\t\n\t\tlong res = 0;\n\t\t\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tfor (int first = 0; first < 2; first++) {\n\t\t\t\tfor (int last = 0; last < 2; last++) {\n\t\t\t\t\tfor (int matchedLast = 0; matchedLast < 2; matchedLast++) {\n\t\t\t\t\t\tfor (int invertedFirst = 0; invertedFirst < 2; invertedFirst++) {\n\t\t\t\t\t\t\tif (d[i][invertedFirst][first][last][matchedLast] == 0) continue;\n\t\t\t\t\t\t\tif (i == 1) {\n\t\t\t\t\t\t\t\tif (last == 0) {\n\t\t\t\t\t\t\t\t\t// put 0\n\t\t\t\t\t\t\t\t\tif (e[i] != 0) {\n\t\t\t\t\t\t\t\t\t\td[i + 1][invertedFirst][first][0][1] += d[i][invertedFirst][first][last][matchedLast];\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\td[i + 1][invertedFirst][first][0][0] += d[i][invertedFirst][first][last][matchedLast];\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t// put 1\n\t\t\t\t\t\t\t\t\tif (e[1] == 0 && first == 1) {\n\t\t\t\t\t\t\t\t\t\td[i + 1][1][0][1][0] += d[i][invertedFirst][first][last][matchedLast];\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t// put 0\n\t\t\t\t\t\t\t\t\tif (e[i] != 0) {\n\t\t\t\t\t\t\t\t\t\td[i + 1][invertedFirst][first][0][1] += d[i][invertedFirst][first][last][matchedLast];\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\td[i + 1][invertedFirst][first][0][0] += d[i][invertedFirst][first][last][matchedLast];\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// put 1\n\t\t\t\t\t\t\t\t\tif (e[i] != 1) {\n\t\t\t\t\t\t\t\t\t\td[i + 1][invertedFirst][first][1][1] += d[i][invertedFirst][first][last][matchedLast];\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\td[i + 1][invertedFirst][first][1][0] += d[i][invertedFirst][first][last][matchedLast];\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else if (i != n - 1) {\n\t\t\t\t\t\t\t\tif (matchedLast == 0) { // yes\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t// put 0\n\t\t\t\t\t\t\t\t\tif (e[i] == 1) {\n\t\t\t\t\t\t\t\t\t\td[i + 1][invertedFirst][first][0][1] += d[i][invertedFirst][first][last][matchedLast];\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\td[i + 1][invertedFirst][first][0][0] += d[i][invertedFirst][first][last][matchedLast];\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t// put 1\n\t\t\t\t\t\t\t\t\tif (last == 1) {\n\t\t\t\t\t\t\t\t\t\tif (e[i] == 0) {\n\t\t\t\t\t\t\t\t\t\t\t//d[i + 1][first][1][1] += d[i][first][last][matchedLast];\n\t\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t\td[i + 1][invertedFirst][first][1][0] += d[i][invertedFirst][first][last][matchedLast];\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t} else { // no\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t// put 1\n\t\t\t\t\t\t\t\t\tif (last == 0 && e[i] == 0) {\n\t\t\t\t\t\t\t\t\t\td[i + 1][invertedFirst][first][1][0] += d[i][invertedFirst][first][last][matchedLast];\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tif (matchedLast == 0) { // yes\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t// put 0\n\t\t\t\t\t\t\t\t\tif (first == 0) {\n\t\t\t\t\t\t\t\t\t\tif ((e[0] == 0 && e[i] == 0 && invertedFirst == 0) || (invertedFirst == 1)) {\n\t\t\t\t\t\t\t\t\t\t\tres += d[i][invertedFirst][first][last][matchedLast];\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tif (e[0] == 0 && e[i] == 1) {\n\t\t\t\t\t\t\t\t\t\t\tres += d[i][invertedFirst][first][last][matchedLast];\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t// put 1\n\t\t\t\t\t\t\t\t\tif (first == 0 && last != 0 && e[i] == 1) {\n\t\t\t\t\t\t\t\t\t\tres += d[i][invertedFirst][first][last][matchedLast];\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t} else { // no\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t// put 1\n\t\t\t\t\t\t\t\t\tif (first == 0 && e[i] == 0 && last == 0) {\n\t\t\t\t\t\t\t\t\t\tres += d[i][invertedFirst][first][last][matchedLast];\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.println(res);\n\t\t\n\t}\n\t\n\tstatic final String fname = \"\";\n\tstatic long stime = 0;\n\t\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st;\n\t\n\tprivate String nextToken () throws Exception {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\t\n\tprivate int nextInt () throws Exception {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\t\n\tprivate long nextLong () throws Exception {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\t\n\tprivate double nextDouble () throws Exception {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\t\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\tsolve ();\n\t\t} catch (Exception e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t} finally {\n\t\t\tout.close();\n\t\t}\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tnew Thread(null, new Solution(), \"\", 1<<26).start();\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "61437710279d474d81571322159971c6", "src_uid": "ad27d991516054ea473b384bb2563b38", "difficulty": 2100.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\n// import java.io.FileInputStream;\n// import java.io.FileOutputStream;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Random;\nimport java.util.StringTokenizer;\n\nimport static java.lang.Math.abs;\nimport static java.lang.Math.max;\nimport static java.lang.Math.min;\nimport static java.lang.Math.round;\nimport static java.util.Arrays.copyOf;\nimport static java.util.Arrays.fill;\nimport static java.util.Arrays.sort;\nimport static java.util.Collections.reverseOrder;\nimport static java.util.Collections.sort;\nimport static java.util.Comparator.comparing;\n\npublic class Main {\n FastScanner in;\n PrintWriter out;\n\n int area(long ax, long ay, long bx, long by, long cx, long cy) {\n // \u0443\u0434\u0432\u043e\u0435\u043d\u0430\u044f \u0437\u043d\u0430\u043a\u043e\u0432\u0430\u044f \u043f\u043b\u043e\u0449\u0430\u0434\u044c \u0442\u0440\u0435\u0443\u0433\u043e\u043b\u044c\u043d\u0438\u043a abc; \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 ab \u0438 ac\n long s = (bx - ax) * (cy - ay) - (by - ay) * (cx - ax);\n return s < 0 ? -1 : s > 0 ? 1 : 0;\n }\n\n private void solve() throws IOException {\n int n = in.nextInt();\n long[] x = new long[n], y = new long[n];\n for (int i = 0; i < n; i++) {\n x[i] = in.nextLong();\n y[i] = in.nextLong();\n }\n char[] s = in.next().toCharArray();\n boolean[] used = new boolean[n];\n\n int cur = 0;\n for (int i = 1; i < n; i++)\n if (y[i] < y[cur] || (y[i] == y[cur] && x[i] < x[cur]))\n cur = i;\n used[cur] = true;\n out.print(cur + 1 + \" \");\n\n for (int i = 0; i < n - 1; i++) {\n int next = -1;\n for (int j = 0; j < n; j++)\n if (!used[j] && (next == -1 || (s[i] == 'L' && area(x[cur], y[cur], x[next], y[next], x[j], y[j]) < 0) ||\n (s[i] == 'R' && area(x[cur], y[cur], x[next], y[next], x[j], y[j]) > 0)))\n next = j;\n cur = next;\n used[cur] = true;\n out.print(cur + 1 + \" \");\n }\n\n out.println();\n }\n\n class FastScanner {\n StringTokenizer st;\n BufferedReader br;\n\n FastScanner(InputStream s) {\n br = new BufferedReader(new InputStreamReader(s));\n }\n\n String next() throws IOException {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n boolean hasNext() throws IOException {\n return br.ready() || (st != null && st.hasMoreTokens());\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n String nextLine() throws IOException {\n return br.readLine();\n }\n\n boolean hasNextLine() throws IOException {\n return br.ready();\n }\n }\n\n private void run() throws IOException {\n in = new FastScanner(System.in); // new FastScanner(new FileInputStream(\".in\"));\n out = new PrintWriter(System.out); // new PrintWriter(new FileOutputStream(\".out\"));\n\n for (int t = 1; t-- > 0; )\n solve();\n\n out.flush();\n out.close();\n }\n\n public static void main(String[] args) throws IOException {\n new Main().run();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4ee6f021715f37e6cc52e3e794db07ae", "src_uid": "13d7f6127a7fe945e19d461b584c6228", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigDecimal;\nimport java.math.MathContext;\nimport java.math.RoundingMode;\nimport java.text.DecimalFormat;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class d {\n static double EPS = 1e-6 ;\n public static void main(String[] args) {\n FS in = new FS(System.in);\n PrintWriter out = new PrintWriter(System.out);\n \n int n = in.nextInt();\n \n Vec com = new Vec(0, 0);\n Vec[] vecs = new Vec[n];\n for(int i = 0; i < n; i++) {\n com = com.add(vecs[i] = new Vec(in.nextInt(), in.nextInt()));\n }\n com = com.scaleR(n);\n \n boolean[] works = new boolean[n];\n Arrays.fill(works, true);\n int num = n;\n for(int i = 0; i < n; i++) {\n if(vecs[i].equals(com)) {\n works[i] = false;\n num--;\n continue;\n }\n for(int j = 0; j < i; j++) {\n if(works[j] && vecs[i].sub(com).equals(com.sub(vecs[j]))) {\n works[i] = works[j] = false;\n num -= 2;\n break;\n }\n }\n }\n Vec[] act = new Vec[num];\n int curr = 0;\n for(int i = 0; i < n; i++) if(works[i]) act[curr++] = vecs[i];\n n = num;\n if(n == 0) {\n System.out.println(-1);\n return;\n }\n int res = 0;\n \n Vec[] norms = new Vec[n];\n \n outer: for(int i = 0; i < n; i++) {\n Vec diff = act[i].sub(act[0]);\n Vec mid = act[0].add(diff.scaleR(2));\n Vec perp = com.sub(mid).rot90();\n if(perp.equals(new Vec(0, 0))) continue;\n Vec norm = perp;\n norm = norm.scaleR(Math.sqrt(norm.dot(norm)));\n if(norm.x < 0 || (eq(norm.x, 0) && norm.y < 0)) {\n norm.x *= -1;\n norm.y *= -1;\n }\n norms[i] = norm;\n for(int j = 0; j < i; j++) {\n if(norms[j].equals(norm)) continue outer;\n }\n double[] arr = new double[n];\n for(int j = 0; j < n; j++) arr[j] = perp.dot(act[j]);\n Arrays.sort(arr);\n double cent = (arr[0]+arr[n-1])/2;\n for(int j = 0; j < n; j++) {\n if(!eq(cent-arr[j], arr[n-1-j]-cent)) continue outer;\n }\n res++;\n }\n System.out.println(res);\n out.close();\n }\n \n static class Vec {\n double x, y;\n \n public Vec(double A, double B) {\n x = A;\n y = B;\n }\n \n public Vec add(Vec o) {\n return new Vec(x+o.x, y+o.y);\n }\n \n public Vec sub(Vec o) {\n return new Vec(x-o.x, y-o.y);\n }\n \n public Vec scale(double s) {\n return new Vec(x*s, y*s);\n }\n \n public Vec scaleR(double s) {\n return new Vec(x/s, y/s);\n }\n \n public Vec rot90() {\n return new Vec(-y, x);\n }\n \n public double dot(Vec o) {\n return x*o.x + y*o.y;\n }\n \n @Override\n public boolean equals(Object o) {\n return eq(x, ((Vec)o).x) && eq(y, ((Vec)o).y);\n }\n }\n \n static boolean eq(double a, double b) {\n return Math.abs(a-b) <= EPS;\n }\n \n static class FS {\n BufferedReader in;\n StringTokenizer token;\n \n public FS(InputStream str) {\n in = new BufferedReader(new InputStreamReader(str));\n }\n \n public String next() {\n if(token == null || !token.hasMoreElements()) {\n try {\n token = new StringTokenizer(in.readLine());\n } catch (IOException ex) {\n }\n return next();\n }\n return token.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2735ff007550f66002c14084daab2336", "src_uid": "5d7ba962400c05433ee17c5658888e69", "difficulty": 2900.0} {"lang": "Java 6", "source_code": "import java.util.*;\n//4 6 2\n//1 2\n//2 3\n//3 4\n//4 1\n//1 3\n//2 4\n\npublic class E {\n\tpublic static void main(String[] args) {\n\t\tScanner s = new Scanner(System.in);\n\t\tn = s.nextInt();\n\t\tm = s.nextInt();\n\t\tk = s.nextInt();\n\t\ta = new int[m][];\n\t\tfor (int i = 0; i < m; ++i) {\n\t\t\tint u = s.nextInt() - 1, v = s.nextInt() - 1;\n\t\t\ta[i] = new int[] { u, v };\n\t\t}\n\t\tb = new boolean[m];\n\t\tSystem.out.println(f(-1, m));\n\t}\n\n\tstatic int n, m, k;\n\tstatic int[][] a;\n\tstatic boolean[] b;\n\n\tstatic int f(int x, int en) {\n\t\tif (en == n - 1) {\n\t\t\tint[] cs = new int[n];\n\t\t\tfor (int i = 0; i < m; ++i) {\n\t\t\t\tif (!b[i]) {\n\t\t\t\t\t++cs[a[i][0]];\n\t\t\t\t\t++cs[a[i][1]];\n\t\t\t\t}\n\t\t\t}\n\t\t\tint cnt = 0;\n\t\t\tfor (int c : cs) {\n\t\t\t\tif (c == 1) {\n\t\t\t\t\t++cnt;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn cnt == k ? 1 : 0;\n\t\t}\n\t\tint result = 0;\n\t\tfor (int i = x + 1; i < m; ++i) {\n\t\t\tif (!b[i]) {\n\t\t\t\tb[i] = true;\n\t\t\t\tresult += f(i, en - 1);\n\t\t\t\tb[i] = false;\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tstatic int max(int... is) {\n\t\tint r = 0;\n\t\tfor (int i : is)\n\t\t\tr = Math.max(r, i);\n\t\treturn r;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7c9bb022c2b1e7ca4d28c33112de8a2f", "src_uid": "8087605a8f316150372cc4627f26231d", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import static java.lang.Double.parseDouble;\nimport static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.Math.abs;\nimport static java.lang.Math.floorDiv;\nimport static java.lang.Math.max;\nimport static java.lang.Math.min;\nimport static java.lang.System.exit;\nimport static java.util.Arrays.fill;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class G {\n\t\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n\t\n//\tstatic final Random rng = new Random(42);\n//\tstatic boolean rngOk;\n\t\n\tstatic void solve() throws Exception {\n\t\tint n = nextInt();\n\t\tint l = nextInt();\n//\t\tint n = rng.nextInt(40) + 1;\n//\t\tint l = rng.nextInt(15) + 1;\n//\t\tlong rngX[] = new long[l + 1];\n//\t\tlong rngY[] = new long[l + 1];\n//\t\tfor (int i = 0; i < l; i++) {\n//\t\t\tlong dx, dy;\n//\t\t\tswitch (rng.nextInt(4)) {\n//\t\t\tcase 0:\n//\t\t\t\tdx = 1;\n//\t\t\t\tdy = 0;\n//\t\t\t\tbreak;\n//\t\t\tcase 1:\n//\t\t\t\tdx = -1;\n//\t\t\t\tdy = 0;\n//\t\t\t\tbreak;\n//\t\t\tcase 2:\n//\t\t\t\tdx = 0;\n//\t\t\t\tdy = 1;\n//\t\t\t\tbreak;\n//\t\t\tcase 3:\n//\t\t\t\tdx = 0;\n//\t\t\t\tdy = -1;\n//\t\t\t\tbreak;\n//\t\t\tdefault:\n//\t\t\t\tthrow new AssertionError();\n//\t\t\t}\n//\t\t\trngX[i + 1] = rngX[i] + dx;\n//\t\t\trngY[i + 1] = rngY[i] + dy;\n//\t\t}\n\t\tlong t[] = new long[n];\n\t\tlong x[] = new long[n];\n\t\tlong y[] = new long[n];\n\t\t{\n\t\t\tlong pt = 0;\n\t\t\tlong px = 0;\n\t\t\tlong py = 0;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tlong ct = nextLong();\n\t\t\t\tlong cx = nextLong();\n\t\t\t\tlong cy = nextLong();\n//\t\t\t\tlong ct = pt + rng.nextInt(40) + 1;\n//\t\t\t\tlong cx = (ct / l) * rngX[l] + rngX[(int) (ct % l)];\n//\t\t\t\tlong cy = (ct / l) * rngY[l] + rngY[(int) (ct % l)];\n//\t\t\t\tif (rng.nextInt(10) == 0) {\n//\t\t\t\t\tcx += rng.nextInt(5) - 2;\n//\t\t\t\t}\n//\t\t\t\tif (rng.nextInt(10) == 0) {\n//\t\t\t\t\tcy += rng.nextInt(5) - 2;\n//\t\t\t\t}\n\t\t\t\tif (ct - pt < abs(cx - px) + abs(cy - py) || ((ct ^ cx ^ cy) & 1) != 0) {\n\t\t\t\t\tout.print(\"NO\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tt[i] = ct;\n\t\t\t\tx[i] = cx + cy;\n\t\t\t\ty[i] = cx - cy;\n\t\t\t\tpt = ct;\n\t\t\t\tpx = cx;\n\t\t\t\tpy = cy;\n\t\t\t}\n\t\t}\n\t\tlong lt[] = new long[l + 1];\n\t\tlong lx[] = new long[l + 1];\n\t\tlong ly[] = new long[l + 1];\n\t\tfill(lt, -1);\n\t\tlt[0] = 0;\n\t\tlx[0] = 0;\n\t\tly[0] = 0;\n\t\tlong shiftXmin = -l;\n\t\tlong shiftXmax = l;\n\t\tlong shiftYmin = -l;\n\t\tlong shiftYmax = l;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint j = (int) (t[i] % l);\n\t\t\tif (lt[j] >= 0) {\n\t\t\t\tlong its = (t[i] - lt[j]) / l;\n\t\t\t\tif ((x[i] - lx[j]) % its != 0 || ((y[i] - ly[j]) % its != 0)) {\n\t\t\t\t\tout.print(\"NO\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tshiftXmin = max(shiftXmin, (x[i] - lx[j]) / its);\n\t\t\t\tshiftXmax = min(shiftXmax, (x[i] - lx[j]) / its);\n\t\t\t\tshiftYmin = max(shiftYmin, (y[i] - ly[j]) / its);\n\t\t\t\tshiftYmax = min(shiftYmax, (y[i] - ly[j]) / its);\n\t\t\t} else {\n\t\t\t\tlt[j] = t[i];\n\t\t\t\tlx[j] = x[i];\n\t\t\t\tly[j] = y[i];\n\t\t\t}\n\t\t}\n\t\tlt[l] = 0;\n\t\tlx[l] = 0;\n\t\tly[l] = 0;\n//\t\tSystem.err.println(Arrays.toString(lt));\n//\t\tSystem.err.println(Arrays.toString(lx));\n//\t\tSystem.err.println(Arrays.toString(ly));\n\t\t{\n\t\t\tint pi = 0;\n\t\t\tfor (int i = 1; i <= l; i++) {\n\t\t\t\tif (lt[i] < 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tlong its = (lt[i] - lt[pi] - (i - pi)) / l;\n\t\t\t\tif (its == 0) {\n\t\t\t\t\tif (i - pi < abs(lx[i] - lx[pi]) || i - pi < abs(ly[i] - ly[pi])) {\n\t\t\t\t\t\tout.print(\"NO\");\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tlong dx = lx[i] - lx[pi];\n\t\t\t\t\tlong dy = ly[i] - ly[pi];\n\t\t\t\t\t// dx - (i - pi) <= shiftX * its\n\t\t\t\t\t// dx + (i - pi) >= shiftX * its\n\t\t\t\t\tif (its > 0) {\n\t\t\t\t\t\tshiftXmin = max(shiftXmin, floorDiv(dx - (i - pi) + its - 1, its));\n\t\t\t\t\t\tshiftXmax = min(shiftXmax, floorDiv(dx + (i - pi), its));\n\t\t\t\t\t\tshiftYmin = max(shiftYmin, floorDiv(dy - (i - pi) + its - 1, its));\n\t\t\t\t\t\tshiftYmax = min(shiftYmax, floorDiv(dy + (i - pi), its));\n\t\t\t\t\t} else {\n\t\t\t\t\t\tshiftXmin = max(shiftXmin, floorDiv(dx + (i - pi) + its + 1, its));\n\t\t\t\t\t\tshiftXmax = min(shiftXmax, floorDiv(dx - (i - pi), its));\n\t\t\t\t\t\tshiftYmin = max(shiftYmin, floorDiv(dy + (i - pi) + its + 1, its));\n\t\t\t\t\t\tshiftYmax = min(shiftYmax, floorDiv(dy - (i - pi), its));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tpi = i;\n\t\t\t}\n\t\t\tif (((shiftXmin ^ l) & 1) != 0) {\n\t\t\t\t++shiftXmin;\n\t\t\t}\n\t\t\tif (((shiftXmax ^ l) & 1) != 0) {\n\t\t\t\t--shiftXmax;\n\t\t\t}\n\t\t\tif (((shiftYmin ^ l) & 1) != 0) {\n\t\t\t\t++shiftYmin;\n\t\t\t}\n\t\t\tif (((shiftYmax ^ l) & 1) != 0) {\n\t\t\t\t--shiftYmax;\n\t\t\t}\n\t\t\tif (shiftXmin > shiftXmax || shiftYmin > shiftYmax) {\n\t\t\t\tout.print(\"NO\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\t{\n\t\t\tlong shiftX = shiftXmin;\n\t\t\tlong shiftY = shiftYmin;\n\t\t\tlong cx = 0;\n\t\t\tlong cy = 0;\n\t\t\tint pi = 0;\n\t\t\tfor (int i = 1; i <= l; i++) {\n\t\t\t\tif (lt[i] < 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tlong its = (lt[i] - i) / l;\n\t\t\t\tlong nx = lx[i] - shiftX * its;\n\t\t\t\tlong ny = ly[i] - shiftY * its;\n\t\t\t\twhile (pi < i) {\n\t\t\t\t\tboolean xUp = nx > cx;\n\t\t\t\t\tboolean yUp = ny > cy;\n\t\t\t\t\tout.print(xUp ? (yUp ? 'R' : 'U') : (yUp ? 'D' : 'L'));\n\t\t\t\t\tif (xUp) {\n\t\t\t\t\t\t++cx;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t--cx;\n\t\t\t\t\t}\n\t\t\t\t\tif (yUp) {\n\t\t\t\t\t\t++cy;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t--cy;\n\t\t\t\t\t}\n\t\t\t\t\t++pi;\n\t\t\t\t}\n\t\t\t\tif (cx != nx || cy != ny) {\n//\t\t\t\t\tSystem.err.println(n + \" \" + l);\n//\t\t\t\t\tSystem.err.println(Arrays.toString(rngX));\n//\t\t\t\t\tSystem.err.println(Arrays.toString(rngY));\n//\t\t\t\t\tSystem.err.println(Arrays.toString(t));\n//\t\t\t\t\tSystem.err.println(Arrays.toString(x));\n//\t\t\t\t\tSystem.err.println(Arrays.toString(y));\n//\t\t\t\t\tSystem.err.println(Arrays.toString(lt));\n//\t\t\t\t\tSystem.err.println(Arrays.toString(lx));\n//\t\t\t\t\tSystem.err.println(Arrays.toString(ly));\n//\t\t\t\t\tSystem.err.println(shiftX + \" \" + shiftY);\n//\t\t\t\t\tSystem.err.println(i + \" \" + cx + \" \" + cy + \" \" + nx + \" \" + ny);\n\t\t\t\t\tthrow new AssertionError();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n//\t\trngOk = true;\n\t}\n\t\n\tstatic int nextInt() throws IOException {\n\t\treturn parseInt(next());\n\t}\n\n\tstatic long nextLong() throws IOException {\n\t\treturn parseLong(next());\n\t}\n\n\tstatic double nextDouble() throws IOException {\n\t\treturn parseDouble(next());\n\t}\n\n\tstatic String next() throws IOException {\n\t\twhile (tok == null || !tok.hasMoreTokens()) {\n\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(new OutputStreamWriter(System.out));\n//\t\t\tif (true) while (true) {\n//\t\t\t\trngOk = false;\n//\t\t\t\tsolve();\n////\t\t\t\tif (!rngOk) {\n////\t\t\t\t\tthrow new AssertionError();\n////\t\t\t\t}\n//\t\t\t\tSystem.err.println(\"PASS\");\n//\t\t\t}\n\t\t\tsolve();\n\t\t\tin.close();\n\t\t\tout.close();\n\t\t} catch (Throwable e) {\n\t\t\te.printStackTrace();\n\t\t\texit(1);\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d72d75d2250f2301d7f92e86483853c9", "src_uid": "941f1f8a37c25dd2405a20c7d416c9a6", "difficulty": 3100.0} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class Main {\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 PrintWriter out = new PrintWriter(outputStream);\n Task solver = new Task();\n solver.main(in, out);\n out.close();\n }\n}\n\nclass Task {\n final int maxn = 41111;\n ArrayList Beg, End;\n Integer[] X, Y;\n int N, M;\n PrintStream cout = System.out;\n\n void print(Object[] arr) {\n cout.println(\"print arr :\");\n for (Object i : arr) {\n cout.print(i + \" \");\n }\n cout.println();\n }\n\n int value;\n long ans = 0;\n\n void update(int v, long c) {\n if (v == value) {\n ans += c;\n } else if (v > value) {\n value = v;\n ans = c;\n }\n }\n\n long calc(long n) {\n n = n * n - n;\n n >>= 1;\n return n;\n }\n\n long single(Integer[] x) {\n int n = x.length;\n int a = 0, b = 0;\n long ans = n;\n if (x[0] == x[n - 1]) {\n ans = ans * (ans - 1) * (ans - 2) / 6;\n // cout.println(ans);\n } else {\n for (int i = 0; i < n; ++i) {\n if (x[i] == x[0])\n ++a;\n if (x[i] == x[0])\n ++b;\n }\n ans -= b + a;\n ans = ans * a * b;\n ans += calc(a) * b;\n ans += calc(b) * a;\n }\n return ans;\n }\n\n void run(Integer x[], Integer y[]) {\n int n = x.length;\n int m = y.length;\n int i, j;\n long sub = 0;\n int c = 0;\n for (i = 0, j = 0; i < n; ++i) {\n while (j < m && y[j] < x[i]) {\n ++j;\n ++c;\n }\n sub += calc(c);\n }\n c = 0;\n for (i = n - 1, j = m - 1; i >= 0; --i) {\n while (j >= 0 && y[j] > x[i]) {\n --j;\n ++c;\n }\n sub += calc(c);\n }\n sub = calc(m) * n - sub;\n\n update(N * 2, sub);\n }\n\n void main(InputReader in, PrintWriter out) throws Exception {\n Beg = new ArrayList();\n End = new ArrayList();\n N = in.nextInt();\n M = in.nextInt();\n for (int i = 0; i < M; ++i) {\n int t, s;\n t = in.nextInt();\n s = in.nextInt();\n if (t == 0) {\n Beg.add(s);\n } else {\n End.add(s);\n }\n }\n // out.println(Beg.size());\n X = Beg.toArray(new Integer[Beg.size()]);\n Y = End.toArray(new Integer[End.size()]);\n Arrays.sort(X);\n Arrays.sort(Y);\n // print(X);\n // print(Y);\n int n = X.length;\n int m = Y.length;\n ans = 0;\n if (m > 2) {\n update(2 * (Y[m - 1] - Y[0]), single(Y));\n }\n if (n > 2) {\n update(2 * (X[n - 1] - X[0]), single(X));\n }\n if (n > 0 && m > 0) {\n if (X[n - 1] < Y[0]) {\n update(N * 2 - (Y[0] - X[n - 1]), m + n - 2);\n } else if (X[0] > Y[m - 1]) {\n update(N * 2 - (X[0] - Y[m - 1]), m + n - 2);\n } else {\n run(X, Y);\n run(Y, X);\n }\n }\n out.println(ans);\n\n }\n}\n\nclass InputReader {\n BufferedReader reader;\n StringTokenizer tokenizer;\n\n InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n tokenizer = null;\n }\n\n String next() {\n if (!hasNext())\n throw new RuntimeException();\n return tokenizer.nextToken();\n }\n\n boolean hasNext() {\n while (tokenizer == null || !tokenizer.hasMoreTokens())\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (Exception e) {\n return false;\n }\n return true;\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1c092e6a117aafe5938f7f097c9fe63f", "src_uid": "bfc61d3e967fc28e1ab5b9028856125b", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.util.List;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Random;\nimport java.util.StringTokenizer;\nimport java.math.BigInteger;\nimport java.util.Collections;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author AlexFetisov\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n static Random r = new Random(3731L);\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n\n int n = in.nextInt();\n int m = in.nextInt();\n Point3D[] spheres = new Point3D[n];\n for (int i = 0; i < n; ++i) {\n spheres[i] = new Point3D(in);\n }\n for (int i = 0; i < m; ++i) {\n double a = in.nextDouble();\n double b = in.nextDouble();\n double c = in.nextDouble();\n Plane3D plane = new Plane3D(a, b, c, 0);\n Point3D[] p = new Point3D[n];\n for (int j = 0; j < n; ++j) {\n double t = -(plane.d + plane.a * spheres[j].x + plane.b * spheres[j].y + plane.c * spheres[j].z) /\n (DoubleUtils.sqr(plane.a) + DoubleUtils.sqr(plane.b) + DoubleUtils.sqr(plane.c));\n p[j] = new Point3D(spheres[j].x + plane.a * t, spheres[j].y + plane.b * t, spheres[j].z + plane.c * t);\n// p[j] = Geometry3DUtils.getProjectionOnPlane(spheres[j], plane);\n }\n\n rotation(a, b, c, p);\n List points = new ArrayList();\n for (int j = 0; j < n; ++j) {\n points.add(new Point(p[j].x, p[j].y));\n }\n\n double best = 1e100;\n for (int iter = 0; iter < 100; ++iter) {\n Point ce = solve1(points);\n double res = 0;\n for (Point po : points) {\n res = Math.max(res, po.distanceTo(ce));\n }\n if (DoubleUtils.compareTo(best, res) > 0) {\n best = res;\n }\n }\n out.println(best);\n }\n }\n\n Point solve1(List p) {\n Collections.shuffle(p, r);\n if (p.size() == 1) {\n return p.get(0);\n } else {\n double r = p.get(0).distanceTo(p.get(1)) / 2;\n Point c = p.get(0).add(p.get(1)).div(2);\n for (int j = 2; j < p.size(); ++j) {\n if (DoubleUtils.compareTo(p.get(j).distanceTo(c), r) > 0) {\n c = solve2(p.subList(0, j), p.get(j));\n r = c.distanceTo(p.get(j));\n }\n }\n return c;\n }\n }\n\n Point solve2(List p, Point po) {\n Collections.shuffle(p, r);\n double r = p.get(0).distanceTo(po);\n Point c = p.get(0).add(po).div(2);\n for (int i = 1; i < p.size(); ++i) {\n if (DoubleUtils.compareTo(p.get(i).distanceTo(c), r) > 0) {\n c = solve3(p.subList(0, i), p.get(i), po);\n r = c.distanceTo(po);\n }\n }\n return c;\n }\n\n Point solve3(List p, Point po, Point po2) {\n Collections.shuffle(p, r);\n double r = po.distanceTo(po2);\n Point c = po.add(po2).div(2);\n for (int i = 1; i < p.size(); ++i) {\n if (DoubleUtils.compareTo(p.get(i).distanceTo(c), r) > 0) {\n Circle cc = new Circle(po, po2, p.get(i));\n c = cc.center;\n r = c.distanceTo(po2);\n }\n }\n return c;\n }\n\n private void rotation(double a, double b, double c, Point3D[] p) {\n double angle = Math.PI / 2 - Math.atan2(c, b);\n double tempB = b;\n double tempC = c;\n c = Math.cos(angle) * tempC + Math.sin(angle) * tempB;\n b = -Math.sin(angle) * tempC + Math.cos(angle) * tempB;\n\n\n for (Point3D point : p) {\n double ty = point.y;\n double tz = point.z;\n point.z = Math.cos(angle) * tz + Math.sin(angle) * ty;\n point.y = -Math.sin(angle) * tz + Math.cos(angle) * ty;\n\n }\n\n angle = Math.PI / 2 - Math.atan2(c, a);\n double tempA = a;\n tempC = c;\n c = Math.cos(angle) * tempC + Math.sin(angle) * tempA;\n a = -Math.sin(angle) * tempC + Math.cos(angle) * tempA;\n\n\n for (Point3D point : p) {\n double tx = point.x;\n double tz = point.z;\n point.z = Math.cos(angle) * tz + Math.sin(angle) * tx;\n point.x = -Math.sin(angle) * tz + Math.cos(angle) * tx;\n }\n }\n}\n\nclass InputReader {\n private BufferedReader reader;\n private StringTokenizer stt;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n }\n\n public String nextLine() {\n try {\n return reader.readLine();\n } catch (IOException e) {\n return null;\n }\n }\n\n public String nextString() {\n while (stt == null || !stt.hasMoreTokens()) {\n stt = new StringTokenizer(nextLine());\n }\n return stt.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(nextString());\n }\n\n public double nextDouble() {\n return Double.parseDouble(nextString());\n }\n\n}\n\nclass Point3D implements Comparable {\n public double x;\n public double y;\n public double z;\n\n public String toString() {\n StringBuilder b = new StringBuilder();\n b.append('(').append(x).append(',').append(y).append(',').append(z).append(')');\n return b.toString();\n }\n\n public Point3D(double x, double y, double z) {\n this.x = x;\n this.y = y;\n this.z = z;\n }\n\n public Point3D(InputReader in) {\n this.x = in.nextDouble();\n this.y = in.nextDouble();\n this.z = in.nextDouble();\n }\n\n public int compareTo(Point3D o) {\n if (DoubleUtils.compareTo(x, o.x) != 0) {\n return DoubleUtils.compareTo(x, o.x);\n }\n if (DoubleUtils.compareTo(y, o.y) != 0) {\n return DoubleUtils.compareTo(y, o.y);\n }\n return DoubleUtils.compareTo(z, o.z);\n }\n}\n\nclass Plane3D {\n public double a, b, c, d;\n\n public Plane3D(double a, double b, double c, double d) {\n this.a = a;\n this.b = b;\n this.c = c;\n this.d = d;\n }\n\n}\n\nclass DoubleUtils {\n public static final double EPS = 1e-8;\n\n public static double sqr(double x) {\n return x * x;\n }\n\n public static int compareTo(double a, double b) {\n if (doubleEqual(a, b)) {\n return 0;\n }\n if (a < b) {\n return -1;\n }\n return 1;\n }\n\n private static boolean doubleEqual(double a, double b) {\n return Math.abs(a - b) < EPS;\n }\n\n public static double sqrt(double a) {\n if (compareTo(a, 0) < 0) {\n System.exit(1);\n }\n if (a < 0) return 0;\n return Math.sqrt(a);\n }\n\n public static double hypot(double a, double b) {\n return sqrt(sqr(a) + sqr(b));\n }\n}\n\nclass Point implements Comparable {\n public double x, y;\n\n public Point(double x, double y) {\n this.x = x;\n this.y = y;\n }\n\n public String toString() {\n return \"(\" + x + \", \" + y + \" )\";\n }\n\n public boolean equals(Object o) {\n Point p = (Point) o;\n return DoubleUtils.compareTo(x, p.x) == 0 && DoubleUtils.compareTo(y, p.y) == 0;\n }\n\n public int hashCode() {\n int result;\n long temp;\n temp = x != +0.0d ? Double.doubleToLongBits(x) : 0L;\n result = (int) (temp ^ (temp >>> 32));\n temp = y != +0.0d ? Double.doubleToLongBits(y) : 0L;\n result = 31 * result + (int) (temp ^ (temp >>> 32));\n return result;\n }\n\n public Point add(Point p) {\n return new Point(x + p.x, y + p.y);\n }\n\n public Point sub(Point p) {\n return new Point(x - p.x, y - p.y);\n }\n\n public Point div(double k) {\n return new Point(x / k, y / k);\n }\n\n public double dotProduct(Point p) {\n return x * p.x + y * p.y;\n }\n\n public double length() {\n return DoubleUtils.sqrt(dotProduct(this));\n }\n\n public double distanceTo(Point p) {\n return sub(p).length();\n }\n\n /*public double distanceToLine(Line l) {\n if (l.hasPoints()) {\n return distanceToLine(l.p1, l.p2);\n }\n Line normLine = l.norm();\n return normLine.a * x + normLine.b * y + normLine.c;\n } */\n\n // Rotate 90 degrees clockwise (positive direction).\n Point rotate() {\n return new Point(-y, x);\n }\n\n public int compareTo(Point o) {\n int temp = DoubleUtils.compareTo(x, o.x);\n if (temp == 0) {\n return DoubleUtils.compareTo(y, o.y);\n }\n return temp;\n }\n}\n\nclass Circle {\n public final Point center;\n public final double radius;\n\n public Circle(Point p1, Point p2, Point p3) {\n Point middle12 = p1.add(p2).div(2);\n Point middle23 = p2.add(p3).div(2);\n Point v12 = p2.sub(p1).rotate();\n Point v23 = p3.sub(p2).rotate();\n Point p12 = middle12.add(v12);\n Point p23 = middle23.add(v23);\n Line l1 = new Line(middle12, p12);\n Line l2 = new Line(middle23, p23);\n\n if (l1.intersect(l2) == null) {\n Point A = p1;\n Point B = p2;\n if (DoubleUtils.compareTo(A.distanceTo(B), p1.distanceTo(p3)) < 0) {\n A = p1;\n B = p3;\n }\n if (DoubleUtils.compareTo(A.distanceTo(B), p2.distanceTo(p3)) < 0) {\n A = p2;\n B = p3;\n }\n center = A.add(B).div(2);\n radius = center.distanceTo(A);\n return;\n //throw new AssertionError(\"Points on same line!\");\n }\n center = l1.intersect(l2);\n radius = center.distanceTo(p1);\n }\n\n}\n\nclass Line {\n public final double a;\n public final double b;\n public final double c;\n boolean hasPoints;\n\n public Line(double a, double b, double c) {\n double h = DoubleUtils.hypot(a, b);\n this.a = a / h;\n this.b = b / h;\n this.c = c / h;\n hasPoints = false;\n }\n\n public Line(Point p1, Point p2) {\n a = p2.y - p1.y;\n b = p1.x - p2.x;\n c = -(p1.x * a + p1.y * b);\n new Line(a, b, c);\n hasPoints = true;\n }\n\n public Point intersect(Line other) {\n if (parallel(other)) {\n return null;\n }\n double determinant = b * other.a - a * other.b;\n double x = (c * other.b - b * other.c) / determinant;\n double y = (a * other.c - c * other.a) / determinant;\n return new Point(x, y);\n }\n\n public boolean parallel(Line other) {\n return DoubleUtils.compareTo(Math.abs(a * other.b - b * other.a), 0) == 0;\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 Line line = (Line) o;\n\n if (!parallel(line)) return false;\n if (Math.abs(a * line.c - c * line.a) > DoubleUtils.EPS || Math.abs(b * line.c - c * line.b) > DoubleUtils.EPS) return false;\n\n return true;\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d7b44552519a4c9b5221d57d46f7074e", "src_uid": "25b2a84f0c3f574cdffd59a902b2326e", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\n\n\npublic class Main {\n\n public static void main(String[] args) throws IOException {\n Scanner sc = new Scanner(System.in);\n // input\n int n = sc.nextInt();\n int m = sc.nextInt();\n int[][] matrix = new int[n][m];\n int k = sc.nextInt();\n for(int i = 0; i < k; ++i) {\n int x1 = sc.nextInt();\n int y1 = sc.nextInt();\n int x2 = sc.nextInt();\n int y2 = sc.nextInt();\n for(int x = x1; x <= x2; ++x) {\n for(int y = y1; y <= y2; ++y) {\n matrix[x-1][y-1] = -1;\n }\n }\n }\n \n // computation: dynamic programming in matrix\n // value of n, m is 1\n // if getTopRight is blocked, value is sum of getTop and getRight\n // else value is maximum of getTop and getRight\n if(matrix[n - 1][m - 1] != -1) {\n matrix[n - 1][m - 1] = 1;\n for(int y = m - 1; y >= 0; --y) {\n for(int x = n - 1; x >= 0; --x) {\n if(x == n - 1 && y == m - 1) {\n matrix[x][y] = 1;\n } else if(x == n - 1 || matrix[x+1][y] == 0) {\n if(matrix[x][y] != -1) { \n matrix[x][y] = Math.max(matrix[x][y + 1], 0); \n } else {\n matrix[x][y] = 0;\n } \n } else if(y == m - 1 || matrix[x][y+1] == 0) {\n if(matrix[x][y] != -1) { \n matrix[x][y] = Math.max(matrix[x + 1][y], 0); \n } else {\n matrix[x][y] = 0;\n }\n } else {\n if(matrix[x][y] != -1) {\n matrix[x][y] = matrix[x+1][y] + matrix[x][y+1] - matrix[x+1][y+1];\n } else {\n matrix[x][y] = 0;\n }\n }\n }\n }\n } \n /*for(int y = m - 3; y >= 0; y--) {\n for(int x = 0; x < n; x++) {\n System.out.print(matrix[x][y] + \" \");\n }\n System.out.println();\n }*/\n \n System.out.println(matrix[0][0]);\n \n \n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6e5e14ce6142965c0fd8c74a3ac93c5a", "src_uid": "294ee0db72d759792d797b6259a83406", "difficulty": 3100.0} {"lang": "Java 11", "source_code": "import java.util.*;\r\nimport java.io.*;\r\npublic class Edu104F{\r\n\tpublic static void main(String[] main) throws Exception{\r\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\r\n\t\tPrintWriter out = new PrintWriter(System.out);\r\n\t\tString s = st.nextToken();\r\n\t\tint[] num = new int[s.length()+1];\r\n\t\tnum[1] = s.charAt(0) - 48;\r\n\t\tfor(int i = 2; i <= s.length(); i++) {\r\n\t\t\tnum[i] = s.charAt(i-1) - s.charAt(i-2);\r\n\t\t}\r\n\t\tint iters = 0;\r\n\t\tboolean edit = true;\r\n\t\tint min = 10000;\r\n\t\twhile(edit) {\r\n\t\t\titers++;\r\n\t\t\tedit = false;\r\n\t\t\tfor(int i = 1; i < s.length(); i++) {\r\n\t\t\t\tif(num[i] > 5) {\r\n\t\t\t\t\tnum[i-1]++;\r\n\t\t\t\t\tnum[i] = num[i]-10;\r\n\t\t\t\t\tnum[s.length()]--;\r\n\t\t\t\t\tedit = true;\r\n\t\t\t\t}\r\n\t\t\t\telse if(num[i] == 5 && num[i-1] < 0) {\r\n\t\t\t\t\tnum[i-1]++;\r\n\t\t\t\t\tnum[i] = num[i]-10;\r\n\t\t\t\t\tnum[s.length()]--;\r\n\t\t\t\t\tedit = true;\r\n\t\t\t\t}\r\n\t\t\t\telse if(i >= 2 && num[i] == 5 && num[i-1] == 4 && num[i-2] < 0 && (num[s.length()] > 0 || num[s.length()] <= -4)) {\r\n\t\t\t\t\tnum[i-2]++;\r\n\t\t\t\t\tnum[i-1] = -5;\r\n\t\t\t\t\tnum[i] = -5;\r\n\t\t\t\t\tnum[s.length()]-=2;\r\n\t\t\t\t\tedit = true;\r\n\t\t\t\t}\r\n\t\t\t\telse if(i >= 2 && num[i] == 5 && num[i-1] == 4 && num[i-2] < 0 && num[s.length()] < -3 && num[s.length() - 1] > 0) {\r\n\t\t\t\t\tnum[i-2]++;\r\n\t\t\t\t\tnum[i-1] = -5;\r\n\t\t\t\t\tnum[i] = -5;\r\n\t\t\t\t\tnum[s.length()]-=2;\r\n\t\t\t\t\tedit = true;\r\n\t\t\t\t}\r\n\t\t\t\telse if(num[i] == 5 && num[i-1] == 5 && num[s.length()] > 1) {\r\n\t\t\t\t\tnum[i-2]++;\r\n\t\t\t\t\tnum[i-1] = -4;\r\n\t\t\t\t\tnum[i] = -5;\r\n\t\t\t\t\tnum[s.length()]-=2;\r\n\t\t\t\t\tedit = true;\r\n\t\t\t\t}\r\n\t\t\t\telse if(num[i] == 5 && num[i-1] == 5 && num[i-2] == 5) {\r\n\t\t\t\t\tnum[i-2]++;\r\n\t\t\t\t\tnum[i-1] = -4;\r\n\t\t\t\t\tnum[i] = -5;\r\n\t\t\t\t\tnum[s.length()]-=2;\r\n\t\t\t\t\tedit = true;\r\n\t\t\t\t}\r\n\t\t\t\telse if(num[i] < -5) {\r\n\t\t\t\t\tnum[i-1]--;\r\n\t\t\t\t\tnum[i] = num[i]+10;\r\n\t\t\t\t\tnum[s.length()]++;\r\n\t\t\t\t\tedit = true;\r\n\t\t\t\t}\r\n\t\t\t\telse if(num[i] == -5 && num[i-1] > 0) {\r\n\t\t\t\t\tnum[i-1]--;\r\n\t\t\t\t\tnum[i] = num[i]+10;\r\n\t\t\t\t\tnum[s.length()]++;\r\n\t\t\t\t\tedit = true;\r\n\t\t\t\t}\r\n\t\t\t\telse if(i >= 2 && num[i] == -5 && num[i-1] == -4 && (num[i-2] > 0 || num[i-2] == -4) && (num[s.length()] < 0 || num[s.length()] >= 4)) {\r\n\t\t\t\t\tnum[i-2]--;\r\n\t\t\t\t\tnum[i-1] = 5;\r\n\t\t\t\t\tnum[i] = 5;\r\n\t\t\t\t\tnum[s.length()]+=2;\r\n\t\t\t\t\tedit = true;\r\n\t\t\t\t}\r\n\t\t\t\telse if(i >= 2 && num[i] == -5 && num[i-1] == -4 && num[i-2] > 0 && num[s.length()] > 3 && num[s.length() - 1] < 0) {\r\n\t\t\t\t\tnum[i-2]--;\r\n\t\t\t\t\tnum[i-1] = 5;\r\n\t\t\t\t\tnum[i] = 5;\r\n\t\t\t\t\tnum[s.length()]+=2;\r\n\t\t\t\t\tedit = true;\r\n\t\t\t\t}\r\n\t\t\t\telse if(num[i] == -5 && num[i-1] == -5 && num[s.length()] < -1) {\r\n\t\t\t\t\tnum[i-2]--;\r\n\t\t\t\t\tnum[i-1] = 4;\r\n\t\t\t\t\tnum[i] = 5;\r\n\t\t\t\t\tnum[s.length()]+=2;\r\n\t\t\t\t\tedit = true;\r\n\t\t\t\t}\r\n\t\t\t\telse if(num[i] == -5 && num[i-1] == -5 && num[i-2] == -5) {\r\n\t\t\t\t\tnum[i-2]--;\r\n\t\t\t\t\tnum[i-1] = 4;\r\n\t\t\t\t\tnum[i] = 5;\r\n\t\t\t\t\tnum[s.length()]+=2;\r\n\t\t\t\t\tedit = true;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(num[s.length()] > 6) {\r\n\t\t\t\tnum[s.length()-1]++;\r\n\t\t\t\tnum[s.length()] -= 11;\r\n\t\t\t\tedit = true;\r\n\t\t\t}\r\n\t\t\telse if(num[s.length()] >= 5 && num[s.length() - 1] < 0) {\r\n\t\t\t\tnum[s.length()-1]++;\r\n\t\t\t\tnum[s.length()] -= 11;\r\n\t\t\t\tedit = true;\r\n\t\t\t}\r\n\t\t\telse if(s.length() >= 2 && num[s.length()] == 6 && num[s.length()-1] == 4 && num[s.length()-2] < 0) {\r\n\t\t\t\tnum[s.length()-1]++;\r\n\t\t\t\tnum[s.length()] -= 11;\r\n\t\t\t\tedit = true;\r\n\t\t\t}\r\n\t\t\telse if(num[s.length()] < -6) {\r\n\t\t\t\tnum[s.length()-1]--;\r\n\t\t\t\tnum[s.length()] += 11;\r\n\t\t\t\tedit = true;\r\n\t\t\t}\r\n\t\t\telse if(num[s.length()] <= -5 && num[s.length() - 1] > 0) {\r\n\t\t\t\tnum[s.length()-1]--;\r\n\t\t\t\tnum[s.length()] += 11;\r\n\t\t\t\tedit = true;\r\n\t\t\t}\r\n\t\t\telse if(s.length() >= 2 && num[s.length()] == -6 && num[s.length()-1] == -4 && num[s.length()-2] > 0) {\r\n\t\t\t\tnum[s.length()-1]--;\r\n\t\t\t\tnum[s.length()] += 11;\r\n\t\t\t\tedit = true;\r\n\t\t\t}\r\n\t\t\tint ans = 0;\r\n\t\t\tfor(int i = 0; i <= s.length(); i++) {\r\n\t\t\t\t//out.print(num[i] + \" \");\r\n\t\t\t\tans += (s.length() + 1 - i)*Math.abs(num[i]);\r\n\t\t\t}\r\n\t\t\tmin = Math.min(ans, min);\r\n\t\t\tif(iters > 7000000)\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t\tint ans = 0;\r\n\t\tfor(int i = 0; i <= s.length(); i++) {\r\n\t\t\t//out.print(num[i] + \" \");\r\n\t\t\tans += (s.length() + 1 - i)*Math.abs(num[i]);\r\n\t\t}\r\n\t\tout.println(Math.min(min,ans));\r\n\t\tout.close();\r\n\t}\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "04fc877d243f5cd8c81f0fe21ca0a246", "src_uid": "1961e7c9120ff652b15cad5dd5ca0907", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\n\npublic class Mixture {\n \n static long[] favorite = new long[3];\n static long[][] matrix = new long[3][3];\n \n static void add(int to, int from) {\n for (int j = 0; j <= 2; j++) {\n matrix[to][j] += matrix[from][j];\n }\n }\n\n static void subtract(int to, int from) {\n for (int j = 0; j <= 2; j++) {\n matrix[to][j] -= matrix[from][j];\n }\n }\n \n static void reduce(int a, int b) {\n while (favorite[a] != 0L && favorite[b] != 0L) {\n if (favorite[a] >= favorite[b]) {\n favorite[a] -= favorite[b];\n subtract(a, b);\n } else {\n favorite[b] -= favorite[a];\n subtract(b, a);\n }\n }\n if (favorite[a] != 0L) {\n favorite[b] += favorite[a];\n add(b, a);\n favorite[a] -= favorite[b];\n subtract(a, b);\n }\n }\n \n public static void main(String[] args) throws IOException {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer tokenizer = new StringTokenizer(in.readLine());\n for (int j = 0; j <= 2; j++) {\n favorite[j] = Long.parseLong(tokenizer.nextToken());\n matrix[j][j] = 1L;\n }\n reduce(0, 1);\n reduce(1, 2);\n /*for (int y = 0; y <= 2; y++) {\n for (int x = 0; x <= 2; x++) {\n System.out.print(matrix[y][x] + \" \");\n }\n System.out.println();\n }*/\n int amt00 = 0;\n int amtPosInfty = 0;\n int amtNegInfty = 0;\n int amtMatch = 0;\n TreeMap positive = new TreeMap<>();\n TreeMap negative = new TreeMap<>();\n int j = 0;\n int n = Integer.parseInt(in.readLine());\n long[] xs = new long[n + 1];\n long[] ys = new long[n + 1];\n StringBuilder out = new StringBuilder();\n for (; n > 0; n--) {\n tokenizer = new StringTokenizer(in.readLine());\n if (tokenizer.nextToken().charAt(0) == 'A') {\n j++;\n for (int a = 0; a <= 2; a++) {\n long k = Long.parseLong(tokenizer.nextToken());\n xs[j] += matrix[0][a] * k;\n ys[j] += matrix[1][a] * k;\n }\n if (xs[j] == 0L) {\n if (ys[j] == 0L) {\n amt00++;\n } else if (ys[j] > 0L) {\n amtPosInfty++;\n } else {\n amtNegInfty++;\n }\n } else {\n Rational q = new Rational(ys[j], xs[j]);\n if (xs[j] > 0L) {\n if (positive.compute(q, (__, prev) -> prev == null ? 1 : (prev + 1)) == 1 && negative.containsKey(q)) {\n amtMatch++;\n }\n } else {\n if (negative.compute(q, (__, prev) -> prev == null ? 1 : (prev + 1)) == 1 && positive.containsKey(q)) {\n amtMatch++;\n }\n }\n }\n } else {\n int j2 = j;\n j = Integer.parseInt(tokenizer.nextToken());\n if (xs[j] == 0L) {\n if (ys[j] == 0L) {\n amt00--;\n } else if (ys[j] > 0L) {\n amtPosInfty--;\n } else {\n amtNegInfty--;\n }\n } else {\n Rational q = new Rational(ys[j], xs[j]);\n if (xs[j] > 0L) {\n if (positive.compute(q, (__, prev) -> prev == 1 ? null : (prev - 1)) == null && negative.containsKey(q)) {\n amtMatch--;\n }\n } else {\n if (negative.compute(q, (__, prev) -> prev == 1 ? null : (prev - 1)) == null && positive.containsKey(q)) {\n amtMatch--;\n }\n }\n }\n j = j2;\n }\n if (amt00 > 0) {\n out.append(1);\n } else if (amtMatch > 0 || (amtPosInfty > 0 && amtNegInfty > 0)) {\n out.append(2);\n } else {\n boolean exists = false;\n if (positive.size() >= 2) {\n Rational q = negative.ceilingKey(positive.firstKey());\n if (q != null && q.compareTo(positive.lastKey()) <= 0) {\n exists = true;\n }\n }\n if (!exists && negative.size() >= 2) {\n Rational q = positive.ceilingKey(negative.firstKey());\n if (q != null && q.compareTo(negative.lastKey()) <= 0) {\n exists = true;\n }\n }\n if (!exists && amtPosInfty > 0 && !positive.isEmpty() && !negative.isEmpty()) {\n Rational q = positive.firstKey();\n Rational r = negative.lastKey();\n if (q.compareTo(r) < 0) {\n exists = true;\n }\n }\n if (!exists && amtNegInfty > 0 && !positive.isEmpty() && !negative.isEmpty()) {\n Rational q = positive.lastKey();\n Rational r = negative.firstKey();\n if (q.compareTo(r) > 0) {\n exists = true;\n }\n }\n if (exists) {\n out.append(3);\n } else {\n out.append(0);\n }\n }\n out.append('\\n');\n }\n System.out.print(out);\n }\n\n static class Rational implements Comparable {\n final long num;\n final long denom;\n\n Rational(long num, long denom) {\n if (denom > 0L) {\n this.num = num;\n this.denom = denom;\n } else {\n this.num = -num;\n this.denom = -denom;\n }\n }\n\n @Override\n public int compareTo(Rational other) {\n long d = (num * other.denom) - (other.num * denom);\n if (d > 0L) {\n return 1;\n } else if (d == 0L) {\n return 0;\n } else {\n return -1;\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "613537540e176239ac613a7c471a1934", "src_uid": "ea995d5c5fe84cd175cda0d0e2f01889", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\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 TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskC {\n static long MOD = (long) 1e9 + 7;\n static long[] fac;\n static long[] ifac;\n static long[] inv;\n\n static {\n int N = (int) 1e6;\n inv = new long[N + 1];\n fac = new long[N + 1];\n ifac = new long[N + 1];\n inv[1] = 1;\n for (int i = 2; i <= N; ++i) {\n inv[i] = inv[(int) MOD % i] * (-MOD / i + MOD) % MOD;\n }\n fac[0] = ifac[0] = 1;\n for (int i = 1; i <= N; ++i) {\n fac[i] = fac[i - 1] * i % MOD;\n ifac[i] = ifac[i - 1] * inv[i] % MOD;\n }\n }\n\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n int n = in.nextInt(), k = in.nextInt();\n long ans = 0;\n long[] a = new long[n + 1];\n long[] s = new long[n + 1];\n for (int i = k + 1; i <= n; i++) {\n a[i] = (s[i - 1] - s[i - k - 1] + i - k - 1 + MOD) * inv[i - 1] % MOD;\n s[i] = (s[i - 1] + a[i]) % MOD;\n ans = (ans + a[i] * inv[i]) % MOD;\n }\n out.print(fac[n - 1] * s[n] % MOD);\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e34af3c9aed16581d970c3ce38732c1e", "src_uid": "0644605611a2cd10ab3a9f12f18d7ae4", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class E implements Runnable {\n\tpublic static void main (String[] args) {new Thread(null, new E(), \"_cf\", 1 << 28).start();}\n\t\n\tint n;\n\tint MAX = 51;\n\tHashMap[] dp;\n\t\n\tpublic void run() {\n\t\tFastScanner fs = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tSystem.err.println(\"Go!\");\n\t\t\n\n\t\tint a = fs.nextInt(), b = fs.nextInt();\n\t\tn = fs.nextInt();\n\t\t\n\t\tdp = new HashMap[MAX];\n\t\tfor(int i = 0; i < MAX; i++) dp[i] = new HashMap();\n\t\t\n\t\tint ret = solve(b, a);\n\t\tif(ret == 1) System.out.println(\"Masha\");\n\t\telse if(ret == 0) System.out.println(\"Missing\");\n\t\telse System.out.println(\"Stas\");\n\t\t\n\t\tout.close();\n\t}\n\t\n\t//returns -1 if whoever is playing here loses\n\t//returns 1 otherwise\n\tint solve(int a, int b) {\n\t\tif(a >= MAX) { //draw\n\t\t\treturn 0;\n\t\t}\n\t\tif(dp[a].containsKey(b)) return dp[a].get(b);\n\t\t\n\t\tboolean canDraw = false;\n\t\tif(!isBad(a, b + 1)) { //increase number of boxes\n\t\t\tint ret = solve(a, b + 1);\n\t\t\tif(ret == -1) { //i win\n\t\t\t\tdp[a].put(b, 1);\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t\tcanDraw |= ret == 0;\n\t\t}\n\t\t\n\t\tif(!isBad(a + 1, b)) { //increase number of items\n\t\t\tint ret = solve(a + 1, b);\n\t\t\tif(ret == -1) {\n\t\t\t\tdp[a].put(b, 1);\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t\tcanDraw |= ret == 0;\n\t\t}\n\t\t\n\t\tint ret = -1;\n\t\tif(canDraw) ret = 0;\n\t\t\n\t\tdp[a].put(b, ret);\n\t\treturn ret;\n\t}\n\t\n\tboolean isBad(int a, int b) {\n\t\tdouble one = a * Math.log(b);\n\t\tdouble two = Math.log(n);\n\t\treturn one > two || Math.abs(one-two) < 1e-9;\n\t}\n\t\n\tclass FastScanner {\n\t\tpublic int BS = 1<<16;\n\t\tpublic char NC = (char)0;\n\t\tbyte[] buf = new byte[BS];\n\t\tint bId = 0, size = 0;\n\t\tchar c = NC;\n\t\tdouble num = 1;\n\t\tBufferedInputStream in;\n\n\t\tpublic FastScanner() {\n\t\t\tin = new BufferedInputStream(System.in, BS);\n\t\t}\n\n\t\tpublic FastScanner(String s) throws FileNotFoundException {\n\t\t\tin = new BufferedInputStream(new FileInputStream(new File(s)), BS);\n\t\t}\n\n\t\tpublic char nextChar(){\n\t\t\twhile(bId==size) {\n\t\t\t\ttry {\n\t\t\t\t\tsize = in.read(buf);\n\t\t\t\t}catch(Exception e) {\n\t\t\t\t\treturn NC;\n\t\t\t\t} \n\t\t\t\tif(size==-1)return NC;\n\t\t\t\tbId=0;\n\t\t\t}\n\t\t\treturn (char)buf[bId++];\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn (int)nextLong();\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\tnum=1;\n\t\t\tboolean neg = false;\n\t\t\tif(c==NC)c=nextChar();\n\t\t\tfor(;(c<'0' || c>'9'); c = nextChar()) {\n\t\t\t\tif(c=='-')neg=true;\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tfor(; c>='0' && c <='9'; c=nextChar()) {\n\t\t\t\tres = (res<<3)+(res<<1)+c-'0';\n\t\t\t\tnum*=10;\n\t\t\t}\n\t\t\treturn neg?-res:res;\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\tdouble cur = nextLong();\n\t\t\treturn c!='.' ? cur:cur+nextLong()/num;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\twhile(c<=32)c=nextChar();\n\t\t\twhile(c>32) {\n\t\t\t\tres.append(c);\n\t\t\t\tc=nextChar();\n\t\t\t}\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\twhile(c<=32)c=nextChar();\n\t\t\twhile(c!='\\n') {\n\t\t\t\tres.append(c);\n\t\t\t\tc=nextChar();\n\t\t\t}\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic boolean hasNext() {\n\t\t\tif(c>32)return true;\n\t\t\twhile(true) {\n\t\t\t\tc=nextChar();\n\t\t\t\tif(c==NC)return false;\n\t\t\t\telse if(c>32)return true;\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic int[] nextIntArray(int n) {\n\t\t\tint[] res = new int[n];\n\t\t\tfor(int i = 0; i < n; i++) res[i] = nextInt();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t}\n\n\t\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "28c6197056d289b661c6b37398ab08ed", "src_uid": "cffd5c0b7b659649f3bf9f2dbd20ad6b", "difficulty": 2000.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\n\npublic class Probnik {\n\n\tpublic static Scanner in = new Scanner(System.in);\n\tpublic static void main(String[] args) {\n\t\t\n\t\tint a = in.nextInt();\n\t\tint b = in.nextInt();\n\t\tSystem.out.println(6-(a+b));\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ecc1a5b1265b6889abca20704e446b56", "src_uid": "e167dc35a0d3b98c0414c66099e35920", "difficulty": 800.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport static java.lang.Math.*;\n\npublic class F {\n\tpublic static void main(String[] args) throws Exception{\n\t\tScanner in = new Scanner(System.in);\n\t\tst = new Point(in.nextDouble(), in.nextDouble());\n\t\ten = new Point(in.nextDouble(), in.nextDouble());\n\t\tN = in.nextInt();\n\t\tT = new Tank[N];\n\t\tfor(int i = 0; i < N;i++)\n\t\t\tT[i] = new Tank(in.nextDouble(), in.nextDouble(), in.nextDouble(), in.nextDouble());\n\t\t\n\t\tK = in.nextInt();\n\t\t\n\t\ten = en.sub(st);\n\t\tfor(Tank t:T)\n\t\t\tt.p = t.p.sub(st);\n\t\tst = st.sub(st);\n\t\t\n\t\tdouble ang = en.ang();\n\t\tst = st.rot(-ang);\n\t\ten = en.rot(-ang);\n\t\tfor(Tank t:T){\n\t\t\tt.p = t.p.rot(-ang);\n\t\t\tt.a = normang(t.a-ang);\n\t\t}\n\t\t\n\t\tfor(Tank t:T){\n\t\t\tif(t.p.y > 0){\n\t\t\t\tt.p.y = -t.p.y;\n\t\t\t\tt.a = normang(2*PI-t.a);\n\t\t\t}\n\t\t}\n\t\t\n\t\tX = en.x;\n\t\tdouble low = 0;\n\t\tdouble high = Long.MAX_VALUE;\n\t\tfor(int i = 0; i < 100;i++){\n\t\t\tdouble mid = (low+high)/2;\n\t\t\tif(safe(mid)){\n\t\t\t\thigh = mid;\n\t\t\t}else{\n\t\t\t\tlow = mid;\n\t\t\t}\n\t\t}\n\t\tSystem.out.format(\"%.015f\\n\", low);\n\t}\n\tprivate static boolean safe(double v) {\n\t\tint hit = 0;\n\t\tLine l = new Line(st, en);\n\t\tfor(Tank t:T){\n\t\t\tdouble toend = abs(angdiff(en.sub(t.p).ang(), t.a))/t.w;\n\t\t\tif(toend <= X/v){\n\t\t\t\thit++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tdouble dist = pointlinedist(t.p, l);\n\t\t\tif(dist > v)\n\t\t\t\tcontinue;\n\t\t\t\n\t\t\tdouble theta1 = asin(sqrt(dist/v));\n\t\t\tdouble theta2 = PI-theta1;\n\t\t\tif(!EQ(sin(theta1), sqrt(dist/v)) || !EQ(sin(theta2), sqrt(dist/v)))\n\t\t\t\tthrow new RuntimeException();\n\n\t\t\tdouble x1 = t.p.x + dist*cos(theta1)/sin(theta1);\n\t\t\tdouble t1 = abs(angdiff(theta1, t.a))/t.w;\n\t\t\tif(0 <= x1 && x1 <= X && t1 <= x1/v){\n\t\t\t\thit++;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tdouble x2 = t.p.x + dist*cos(theta2)/sin(theta2);\n\t\t\tdouble t2 = abs(angdiff(theta2, t.a))/t.w;\n\t\t\tif(0 <= x2 && x2 <= X && t2 <= x2/v){\n\t\t\t\thit++;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t}\n\t\treturn hit <= K;\n\t}\n\tstatic int N, K;\n\tstatic Tank[] T;\n\tstatic Point st, en;\n\tstatic double X;\n\tstatic class Tank{\n\t\tPoint p;\n\t\tdouble a, w;\n\t\tpublic Tank(double x, double y, double a, double w){\n\t\t\tp = new Point(x, y);\n\t\t\tthis.a = a;\n\t\t\tthis.w = w;\n\t\t}\n\t}\n\n\n\n\n\n\n\n\tstatic double eps = 1e-9;\n\tstatic boolean EQ(double a, double b){return abs(a-b) < eps;}\n\tstatic double SQ(double d){return d*d;}\n\tstatic double normang(double t){ return ((t % (2*PI)) + 2*PI) % (2*PI); }\n\tstatic double angdiff(double t1, double t2){ return normang(t1 - t2 + PI) - PI; }\n\tstatic ArrayList makeVec(Point...P){\n\t\tArrayList ans = new ArrayList();\n\t\tfor(Point p:P)\n\t\t\tans.add(p);\n\t\treturn ans;\n\t}\n\tstatic class Point{\n\t\tdouble x, y;\n\t\tpublic Point(double x, double y){this.x = x;this.y = y;}\n\t\tPoint add(Point p){return new Point(x+p.x, y+p.y);}\n\t\tPoint sub(Point p){return new Point(x-p.x, y-p.y);}\n\t\tPoint mult(double d){return new Point(x*d, y*d);}\n\t\tdouble dot(Point p){return x*p.x+ y*p.y;}\n\t\tdouble cross(Point p){return x*p.y - y*p.x;}\n\t\tdouble len(){return hypot(x, y);}\n\t\tPoint scale(double d){return mult(d/len());}\n\t\tdouble dist(Point p){return sub(p).len();}\n\t\tdouble ang(){return atan2(y, x);}\n\t\tstatic Point polar(double r, double theta){return new Point(r*cos(theta), r*sin(theta));}\n\t\tPoint rot(double theta){return new Point(x*cos(theta)-y*sin(theta), x*sin(theta)+y*cos(theta));}\n\t\tPoint perp(){return new Point(-y, x);}\n\t\tboolean equals(Point p){return EQ(0, dist(p));}\n\t\tdouble norm(){return dot(this);}\n\t\tpublic String toString(){return String.format(\"(%.03f, %.03f)\", x, y);}\n\t}\t\n\tstatic class Line{\n\t\tPoint a, b;\n\t\tLine(Point a, Point b){this.a = a;this.b = b;}\n\t\tpublic String toString(){return String.format(\"{%s -> %s}\", a, b);}\n\t}\n\tstatic class Circle{\n\t\tPoint p;double r;\n\t\tpublic Circle(Point p, double r){this.p = p;this.r = r;}\n\t\tpublic Circle(Point a, Point b, Point c){\n\t\t\tPoint p1 = a.add(b).mult(0.5);\n\t\t\tLine l1 = new Line(p1, p1.add(a.sub(b).perp()));\n\t\t\tPoint p2 = b.add(c).mult(0.5);\n\t\t\tLine l2 = new Line(p2, p2.add(b.sub(c).perp()));\n\t\t\tp = lineline(l1, l2);\n\t\t\tassert(p != null);\n\t\t\tr = p.dist(a);\n\t\t}\n\t}\n\tstatic double ccw(Point p1, Point p2, Point p3){\n\t\treturn p2.sub(p1).cross(p3.sub(p1));\n\t}\n\tstatic Point lineline(Line a, Line b){//tested\n\t\tdouble d = a.b.sub(a.a).cross(b.b.sub(b.a));\n\t\tif(EQ(d, 0))\n\t\t\treturn null;\n\t\treturn a.a.add((a.b.sub(a.a)).mult(b.b.sub(b.a).cross(a.a.sub(b.a))/d));\n\t}\n\tstatic Point segline(Line a, Line b){\n\t\tPoint inter = lineline(a, b);\n\t\tif(inter == null || !onseg(a, inter))\n\t\t\treturn null;\n\t\treturn inter;\n\t}\n\tstatic Point segseg(Line a, Line b){//tested\n\t\tPoint inter = lineline(a, b);\n\t\tif(inter == null || !onseg(a, inter) || !onseg(b, inter))\n\t\t\treturn null;\n\t\treturn inter;\n\t}\n\tstatic boolean onseg(Line l, Point p){ //tested\n\t\tPoint delta = l.b.sub(l.a);\n\t\treturn online(l, p) && delta.dot(l.a)-eps <= delta.dot(p) && delta.dot(p) <= delta.dot(l.b)+eps;\n\t}\n\tstatic boolean online(Line l, Point p){ //tested\n\t\treturn EQ(ccw(l.a, l.b, p), 0);\n\t}\n\tstatic Point pointline(Point p, Line l){\n\t\tPoint v = l.b.sub(l.a).scale(1);\n\t\tdouble dot = p.sub(l.a).dot(v);\n\t\treturn l.a.add(v.mult(dot));\n\t}\n\tstatic Point pointseg(Point p, Line l){\n\t\tPoint v = l.b.sub(l.a).scale(1);\n\t\tdouble dot = p.sub(l.a).dot(v);\n\t\tdot = max(dot, 0);\n\t\tdot = min(dot, l.b.dist(l.a));\n\t\treturn l.a.add(v.mult(dot));\n\t}\n\tstatic double pointsegdist(Point p, Line l){\n\t\treturn pointseg(p, l).dist(p);\n\t}\n\tstatic double pointlinedist(Point p, Line l){\n\t\treturn pointline(p, l).dist(p);\n\t}\n\n\tstatic double polyarea(Point[] poly){\n\t\tdouble area = 0;\n\t\tfor(int i = 0; i < poly.length; i++)\n\t\t\tarea += poly[i].cross(poly[(i+1)%poly.length]);\n\t\treturn abs(area)/2.0;\n\t}\n\tstatic int pointinpoly(Point[] poly, Point p){\n\t\tdouble ang = 0.0;\n\t\tfor(int i = 0; i < poly.length; i++){\n\t\t\tPoint a = poly[i];\n\t\t\tPoint b = poly[(i+1)%poly.length];\n\t\t\tif(onseg(new Line(a, b), p))\n\t\t\t\treturn 0;\n\t\t\tang += angdiff(a.sub(p).ang(), b.sub(p).ang());\n\t\t}\n\t\treturn EQ(ang, 0) ? -1 : 1;\n\t}\n\n\tstatic Point v0;\n\tstatic ArrayList convexhull(ArrayList P){//tested\n\t\tv0 = null;\n\t\tfor(Point p:P)\n\t\t\tif(v0 == null || p.x < v0.x - eps || (EQ(p.x, v0.x) && p.y < v0.y))\n\t\t\t\tv0 = p;\n\t\tCollections.sort(P, new Comparator(){\n\t\t\tpublic int compare(Point a, Point b){\n\t\t\t\tif(a == v0) return -1;\n\t\t\t\tif(b == v0) return 1;\n\t\t\t\tdouble ccw = ccw(v0, a, b);\n\t\t\t\tif(EQ(ccw, 0)){\n\t\t\t\t\tdouble d1 = v0.dist(a);\n\t\t\t\t\tdouble d2 = v0.dist(b);\n\t\t\t\t\tif(d1 < d2) return -1;\n\t\t\t\t\tif(d1 > d2) return 1;\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t\treturn (int) -signum(ccw);\n\t\t\t}});\n\t\tArrayList ch = new ArrayList();\n\t\tfor(Point p:P){\n\t\t\twhile(ch.size() >= 2 && ccw(ch.get(ch.size()-2), ch.get(ch.size()-1), p) <= 0)\n\t\t\t\tch.remove(ch.size()-1);\n\t\t\tch.add(p);\n\t\t}\n\t\treturn ch;\n\t}\n\t//add half space intersection\n\n\t//circle\n\tstatic ArrayList circline(Circle c, Line l){\n\t\tPoint x = pointline(c.p, l);\n\t\tdouble d = x.dist(c.p);\n\t\tif(d > c.r + eps) return new ArrayList();\n\t\tdouble h = sqrt(SQ(c.r) - SQ(d));\n\t\tPoint v = x.sub(c.p);\n\t\treturn makeVec(c.p.add(v.scale(d)).add(v.scale(h)), c.p.add(v.scale(d)).add(v.scale(-h)));\n\t}\n\tstatic ArrayList circcirc(Circle a, Circle b){\n\t\tdouble d = a.p.dist(b.p);\n\t\tif(d > a.r + b.r + eps) return new ArrayList();\n\t\tif(d < abs(a.r - b.r) - eps) return new ArrayList();\n\t\tdouble x = (SQ(d) - SQ(b.r) + SQ(a.r)) / 2*d;\n\t\tdouble y = sqrt(SQ(a.r) - SQ(x));\n\t\tPoint v = b.p.sub(a.p);\n\t\treturn makeVec(a.p.add(v.scale(x)).add(v.perp().scale(y)), a.p.add(v.scale(x)).add(v.perp().scale(-y)));\n\t}\n\tstatic ArrayList circcirctan(Circle a, Circle b){//tested\n\t\tif(a.r < b.r)\n\t\t\treturn circcirctan(b, a);\n\t\tArrayList res = new ArrayList();\n\t\tdouble d = a.p.dist(b.p);\n\t\tdouble d1 = a.r*d/(a.r + b.r);\n\t\tdouble t = acos(a.r/d1);\n\t\tPoint v = b.p.sub(a.p);\n\t\tres.add(new Line(a.p.add(v.scale(a.r).rot(t)), b.p.add(v.scale(-b.r).rot(t))));\n\t\tres.add(new Line(a.p.add(v.scale(a.r).rot(-t)), b.p.add(v.scale(-b.r).rot(-t)))); \n\t\tt = asin((a.r-b.r)/d)+PI/2;\n\t\tv = a.p.sub(b.p);\n\t\tres.add(new Line(a.p.add(v.scale(a.r).rot(t)), b.p.add(v.scale(b.r).rot(t))));\n\t\tres.add(new Line(a.p.add(v.scale(a.r).rot(-t)), b.p.add(v.scale(b.r).rot(-t)))); \n\t\treturn res;\n\t}\n\n\t//3d\n\tstatic class Point3{\n\t\tdouble x, y, z;\n\t\tPoint3(double x, double y, double z) { this.x = x; this.y = y; this.z = z; }\n\t\tstatic Point3 sphere(double theta, double phi, double r){\n\t\t\treturn new Point3(r*cos(theta)*sin(phi),r*sin(theta)*sin(phi),r*cos(theta));\n\t\t}\n\t\tdouble[] ang(){ return new double[]{atan(y/x), acos(z/len())}; }\n\t\tPoint proj(){ return new Point(x, y); }\n\t\tPoint3 add(Point3 p){ return new Point3(x+p.x, y+p.y, z+p.z); }\n\t\tPoint3 sub(Point3 p){ return new Point3(x-p.x, y-p.y, z-p.z); }\n\t\tdouble dot(Point3 p){ return x*p.x+ y*p.y+ z*p.z; }\n\t\tPoint3 cross(Point3 p){ return new Point3(y*p.z-p.y*z, z*p.x-p.z*x, x*p.y-p.x*y); }\n\t\tPoint3 mult(double d){ return new Point3(x*d, y*d, z*d); }\n\t\tdouble len(){ return sqrt(x*x+y*y+z*z); }\n\t\tPoint3 scale(double d){ return mult(d/len()); }\n\t\tdouble dist(Point3 p){ return sub(p).len(); } \n\t\tboolean equals(Point3 p){ return EQ(dist(p), 0); }\n\t}\n\tstatic Point3[] getbasis(Point3 z){\n\t\tz = z.scale(1);\n\t\tPoint3 t = new Point3(1, 0, 0);\n\t\tPoint3 y = z.cross(t);\n\t\tif(EQ(y.len(), 0)){\n\t\t\tt = new Point3(0, 1, 0);\n\t\t\ty = z.cross(t);\n\t\t}\n\t\tPoint3 x = y.cross(z);\n\t\tassert(x.cross(y).equals(z));\n\t\treturn new Point3[]{x, y, z};\n\t}\n\tstatic Point3 trans(Point3[] B, Point3 p){\n\t\treturn new Point3(B[0].dot(p), B[1].dot(p), B[2].dot(p));\n\t}\n\tstatic Point3 invtrans(Point3[] B, Point3 p){\n\t\treturn B[0].mult(p.x).add(B[1].mult(p.y)).add(B[2].mult(p.z));\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9b681950632b02f87df12cd6a4adee38", "src_uid": "38c14ab8b9c5107c2a2f70a35f166d8b", "difficulty": 2900.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.util.HashMap;\n\npublic class C62 {\n\n static StreamTokenizer in;\n static PrintWriter out;\n \n static int nextInt() throws IOException {\n in.nextToken();\n return (int)in.nval;\n }\n \n static String nextString() throws IOException {\n in.nextToken();\n return in.sval;\n }\n\n public static void main(String[] args) throws IOException {\n in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n out = new PrintWriter(System.out);\n\n int n = nextInt();\n l = new int[n][n];\n h = new int[n][n];\n a = new int[n][n];\n for (int i = 0; i < n*(n-1)/2; i++) {\n int f = nextInt()-1, t = nextInt()-1;\n l[f][t] = nextInt();\n h[f][t] = nextInt();\n a[f][t] = nextInt();\n }\n \n int min = 0, max = Integer.MAX_VALUE;\n for (int i = 0; i < n-1; i++)\n for (int j = 0; j < n; j++) {\n int L = 0, H = 0;\n for (int k = 0; k <= i; k++)\n for (int m = i+1; m < n; m++) {\n L += l[k][m];\n H += h[k][m];\n }\n min = Math.max(min, L);\n max = Math.min(max, H);\n }\n \n e = new int[n*(n-1)/2][];\n for (int i = 0, k = 0; i < n-1; i++)\n for (int j = i+1; j < n; j++, k++)\n e[k] = new int[]{i, j};\n p = new int[n-1];\n p[0] = min;\n s = min;\n int ans = solve(0);\n out.println(ans == Integer.MIN_VALUE ? \"-1 -1\" : min + \" \" + solve(0));\n \n out.flush(); \n }\n\n static int[][] l, h, a;\n static int[][] e;\n static int[] p;\n static int s;\n \n static HashMap map = new HashMap();\n \n static int solve(int x) {\n if (x >= e.length)\n return s == 0 ? 0 : Integer.MIN_VALUE;\n int key = getKey(x);\n if (map.containsKey(key)) return map.get(key);\n int f = e[x][0], t = e[x][1];\n if (f > 1 && p[f-1] > 0) {\n map.put(key, Integer.MIN_VALUE);\n return Integer.MIN_VALUE;\n }\n int res = Integer.MIN_VALUE;\n for (int i = l[f][t]; i <= h[f][t]; i++) {\n if (i > p[f]) break;\n p[f] -= i;\n if (t < p.length) p[t] += i;\n else s -= i;\n int cur = solve(x+1);\n if (cur != Integer.MIN_VALUE)\n res = Math.max(res, cur + (i > 0 ? a[f][t] + i*i : 0));\n if (t < p.length) p[t] -= i;\n else s += i;\n p[f] += i;\n }\n map.put(key, res);\n return res;\n } \n \n static int getKey(int x) {\n int res = x;\n for (int i = 0; i < p.length; i++)\n res = res*26 + p[i];\n return res;\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2a803583d9e58395b997b45a8b5a6dcd", "src_uid": "38886ad7b0d83e66b77348be34828426", "difficulty": 2200.0} {"lang": "Java 6", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class solver implements Runnable{\n\n public static void main(String [] args){\n (new solver()).run();\n }\n\n int[][] dp;\n int mod 1000000007\n\n public void solver() throws IOException{\n\n\n String s=nextToken();\n String w=nextToken();\n int n=s.length();\n int m=w.length();\n \n dp=new int[5005][5005];\n\n dp[0][0]=0;\n //for(int j=0;j<=m;j++) dp[0][j]=1;\n //for(int i=0;i<=n;i++) dp[i][0]=1;\n\n for(int i=1;i<=n;i++)\n for(int j=1;j<=m;j++)\n {\n dp[i][j]=dp[i][j-1];\n if(s.charAt(i-1)==w.charAt(j-1))\n dp[i][j]+=1+dp[i-1][j-1];\n\n dp[i][j]%=mod;\n }\n\n int ans=0;\n\n for(int i=0;i<=n;i++)\n {\n ans+=dp[i][m];\n ans%=mod;\n }\n\n out.print(ans);\n\n /*System.out.println(dp[n][m]);\n\n for(int i=0;i<10;i++){\n System.out.print(i+\":\");\n for(int j=0;j<10;j++)\n System.out.print(dp[i][j]+\" \");\n System.out.println();\n }*/\n\n }\n\n public void run(){\n try{\n reader=new BufferedReader(new InputStreamReader(System.in));\n //reader=new BufferedReader(new FileReader(\"input.txt\"));\n tokenizer=null;\n out=new PrintWriter(System.out);\n\t solver();\n out.close();\n reader.close();\n }\n catch(Exception e){ \n e.printStackTrace();\n System.exit(1);\n }\n \n }\n\n\n public String nextToken() throws IOException{\n while(tokenizer==null || !tokenizer.hasMoreTokens() )\n tokenizer=new StringTokenizer(reader.readLine());\n return tokenizer.nextToken();\n }\n\n BufferedReader reader;\n StringTokenizer tokenizer;\n PrintWriter out;\n\n \n \n\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "8b7089b01e7a2646385adc9073b51c3b", "src_uid": "4022f8f796d4f2b7e43a8360bf34e35f", "difficulty": 1700.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class E {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tvoid solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\t\t\n\t\tlong[] a = new long[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = nextLong();\n\t\t\n\t\tlong ans = 0;\n\t\t\n\t\tint maxP = m / n;\n\t\tfor (int p = 1; p <= maxP; p++) {\n\t\t\tlong minLastSum = (long)p * (p + 1) / 2 * n;\n\t\t\tif (a[n - 1] < minLastSum)\n\t\t\t\tcontinue;\n\t\t\tlong maxLastSum = (long)m * p - (long)n * p * (p - 1) / 2;\n\t\t\tlong[] money = new long[n];\n\t\t\tmoney[n - 1] = Math.min(maxLastSum, a[n - 1]);\n\t\t\tfor (int i = n - 2; i >= 0; i--)\n\t\t\t\tmoney[i] = Math.min(a[i], money[i + 1] - p);\n\t\t\t\n\t\t\tlong firstMax = (long)(m + 1) * p - (long)n * p * (p + 1) / 2;\n\t\t\tlong diff = firstMax - money[0];\n\t\t\tif (diff < 0)\n\t\t\t\tthrow new AssertionError();\n\t\t\tlong firstPay = diff <= m - p * n ? (m - p * n + 1 - diff) : 1;\n\t\t\tlong free = (m - firstPay + 1) - n * p;\n\t\t\t\n\t\t\tlong cur = money[0];\n\t\t\tlong last = money[0];\n\t\t\tfor (int j = 1; j < n; j++) {\n\t\t\t\tlong now = last + p;\n\t\t\t\tlong shift = Math.min(free, money[j] - now);\n\t\t\t\tfree -= shift;\n\t\t\t\tlast = now + shift;\n\t\t\t\tcur += last;\n\t\t\t}\n\t\t\t\n\t\t\tans = Math.max(ans, cur);\n\t\t}\n\t\t\n\t\tout.println(ans);\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\tsolve();\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew E().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", "compilation_error": false, "code_uid": "50cc61e6319580a6ddeb8c24f94cca1f", "src_uid": "169f58dc87d26e0fadde6a83bb623f54", "difficulty": 2900.0} {"lang": "Java 6", "source_code": "import static java.lang.Math.abs;\nimport static java.lang.Math.max;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class E {\n\n\tprivate void solve() throws IOException {\n\t\tint[] abc = new int[3];\n\t\tfor (int i = 0; i < 3; i++) {\n\t\t\tabc[i] = nextInt();\n\t\t\tmoveDistance[i] = nextInt();\n\t\t\tthrowDistance[i] = nextInt();\n\t\t}\n\t\tPosition init = new Position(abc[0], abc[1], abc[2], 511, 0);\n\t\tqueue.add(init);\n\t\tvisited.add(init);\n\t\tbest = Integer.MIN_VALUE;\n\t\t// long time = System.currentTimeMillis();\n\t\tbfs();\n\t\t// System.err.println(visited.size());\n\t\t// System.err.println(System.currentTimeMillis() - time);\n\t\tout.println(best);\n\t}\n\n\tstatic Queue queue = new ArrayDeque();\n\tstatic HashSet visited = new HashSet();\n\tstatic Position temp = new Position(0, 0, 0, 0, 0);\n\tstatic int[] moveDistance = new int[3];\n\tstatic int[] throwDistance = new int[3];\n\tstatic int best;\n\n\tstatic int[] array = new int[3];\n\n\tstatic boolean containedInArray(int i) {\n\t\tfor (int j = 0; j < 3; j++) {\n\t\t\tif (array[j] == i) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\tstatic void bfs() {\n\t\twhile (!queue.isEmpty()) {\n\t\t\tPosition p = queue.poll();\n\t\t\tp.copyTo(temp);\n\t\t\tfor (int i = 0; i < 3; i++) {\n\t\t\t\tarray[i] = p.getPos(i);\n\t\t\t\tbest = max(best, array[i]);\n\t\t\t}\n\n\t\t\tfor (int manMoving = 0; manMoving < 3; manMoving++) {\n\t\t\t\tint pos = temp.getPos(manMoving);\n\t\t\t\tint holding = ((temp.holding123 >> 2 * manMoving) & 3) - 1;\n\t\t\t\tif (beingHeld(temp.holding123, manMoving)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (holding == -1 && bit(temp.movesMask, (3 * manMoving))) {\n\t\t\t\t\ttemp.movesMask ^= 1 << 3 * manMoving;\n\t\t\t\t\tfor (int i = max(pos - moveDistance[manMoving], 1); i <= pos\n\t\t\t\t\t\t\t+ moveDistance[manMoving]; i++) {\n\t\t\t\t\t\tif (containedInArray(i)) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttemp.setPosition(manMoving, i);\n\t\t\t\t\t\tif (!visited.contains(temp)) {\n\t\t\t\t\t\t\tPosition t = temp.copy();\n\t\t\t\t\t\t\tvisited.add(t);\n\t\t\t\t\t\t\tqueue.add(t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\ttemp.setPosition(manMoving, pos);\n\t\t\t\t\ttemp.movesMask ^= 1 << 3 * manMoving;\n\t\t\t\t}\n\n\t\t\t\tif (holding != -1 && bit(temp.movesMask, 3 * manMoving + 1)) {\n\t\t\t\t\ttemp.movesMask ^= 1 << 3 * manMoving + 1;\n\t\t\t\t\ttemp.holding123 ^= (holding + 1) << 2 * manMoving;\n\t\t\t\t\tint otherManHolds = ((temp.holding123 >> 2 * holding) & 3) - 1;\n\t\t\t\t\tfor (int i = max(pos - throwDistance[manMoving], 1); i <= pos\n\t\t\t\t\t\t\t+ throwDistance[manMoving]; i++) {\n\t\t\t\t\t\tif (containedInArray(i)) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttemp.setPosition(holding, i);\n\t\t\t\t\t\tif (otherManHolds != -1) {\n\t\t\t\t\t\t\ttemp.setPosition(otherManHolds, i);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!visited.contains(temp)) {\n\t\t\t\t\t\t\tPosition t = temp.copy();\n\t\t\t\t\t\t\tvisited.add(t);\n\t\t\t\t\t\t\tqueue.add(t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (otherManHolds != -1) {\n\t\t\t\t\t\ttemp.setPosition(otherManHolds, pos);\n\t\t\t\t\t}\n\t\t\t\t\ttemp.holding123 ^= (holding + 1) << 2 * manMoving;\n\t\t\t\t\ttemp.setPosition(holding, pos);\n\t\t\t\t\ttemp.movesMask ^= 1 << 3 * manMoving + 1;\n\t\t\t\t}\n\n\t\t\t\tif (bit(temp.movesMask, 3 * manMoving + 2)) {\n\t\t\t\t\ttemp.movesMask ^= 1 << 3 * manMoving + 2;\n\t\t\t\t\tfor (int i = 0; i < 3; i++) {\n\t\t\t\t\t\tif (i == manMoving) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tint oldpos = temp.getPos(i);\n\t\t\t\t\t\tif (abs(oldpos - pos) != 1) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (beingHeld(temp.holding123, i)) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttemp.holding123 ^= (i + 1) << (2 * manMoving);\n\t\t\t\t\t\ttemp.setPosition(i, pos);\n\t\t\t\t\t\tif (!visited.contains(temp)) {\n\t\t\t\t\t\t\tPosition t = temp.copy();\n\t\t\t\t\t\t\tvisited.add(t);\n\t\t\t\t\t\t\tqueue.add(t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttemp.holding123 ^= (i + 1) << (2 * manMoving);\n\t\t\t\t\t\ttemp.setPosition(i, oldpos);\n\t\t\t\t\t}\n\t\t\t\t\ttemp.movesMask ^= 1 << 3 * manMoving + 2;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic boolean beingHeld(int holding, int man) {\n\t\t++man;\n\t\tif (man == (holding & 3))\n\t\t\treturn true;\n\t\tif (man == ((holding >> 2) & 3))\n\t\t\treturn true;\n\t\tif (man == ((holding >> 4) & 3))\n\t\t\treturn true;\n\t\treturn false;\n\t}\n\n\tstatic boolean bit(int mask, int bit) {\n\t\treturn (mask & (1 << bit)) != 0;\n\t}\n\n\tstatic class Position {\n\t\tint a, b, c;\n\t\tint movesMask;\n\t\tint holding123;\n\n\t\tvoid setPosition(int man, int pos) {\n\t\t\tif (man == 0) {\n\t\t\t\ta = pos;\n\t\t\t} else {\n\t\t\t\tif (man == 1) {\n\t\t\t\t\tb = pos;\n\t\t\t\t} else {\n\t\t\t\t\tc = pos;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint getPos(int manMoving) {\n\t\t\treturn manMoving == 0 ? a : manMoving == 1 ? b : c;\n\t\t}\n\n\t\tPosition() {\n\t\t}\n\n\t\tPosition copy() {\n\t\t\tPosition res = new Position();\n\t\t\tcopyTo(res);\n\t\t\treturn res;\n\t\t}\n\n\t\tpublic Position(int a, int b, int c, int movesMask, int holding123) {\n\t\t\tthis.a = a;\n\t\t\tthis.b = b;\n\t\t\tthis.c = c;\n\t\t\tthis.movesMask = movesMask;\n\t\t\tthis.holding123 = holding123;\n\t\t}\n\n\t\tvoid copyTo(Position to) {\n\t\t\tto.a = a;\n\t\t\tto.b = b;\n\t\t\tto.c = c;\n\t\t\tto.movesMask = movesMask;\n\t\t\tto.holding123 = holding123;\n\t\t}\n\n\t\t@Override\n\t\tpublic int hashCode() {\n\t\t\tfinal int prime = 31;\n\t\t\tint result = 1;\n\t\t\tresult = prime * result + a;\n\t\t\tresult = prime * result + b;\n\t\t\tresult = prime * result + c;\n\t\t\tresult = prime * result + holding123;\n\t\t\tresult = prime * result + movesMask;\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\tPosition other = (Position) obj;\n\t\t\tif (a != other.a)\n\t\t\t\treturn false;\n\t\t\tif (b != other.b)\n\t\t\t\treturn false;\n\t\t\tif (c != other.c)\n\t\t\t\treturn false;\n\t\t\tif (holding123 != other.holding123)\n\t\t\t\treturn false;\n\t\t\tif (movesMask != other.movesMask)\n\t\t\t\treturn false;\n\t\t\treturn true;\n\t\t}\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 E().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", "compilation_error": false, "code_uid": "4459e016ca5256dc262bf10c793377ba", "src_uid": "a14739b86d1fd62a030226263cdc1afc", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.BufferedInputStream;\nimport java.io.InputStream;\nimport java.io.PrintStream;\nimport java.util.Locale;\nimport java.util.Scanner;\n\npublic class TaskD {\n private static final String QUICK_ANSWER = \"NO\";\n private final Scanner in;\n private final StringBuilder out;\n private final int n;\n private final char[] chars;\n private final boolean[] up;\n int minPos;\n\n\n public TaskD(Scanner in, StringBuilder out) throws QuickAnswer {\n this.in = in;\n this.out = out;\n n = nextInt();\n chars = nextString().toCharArray();\n int lev = 0;\n int minLev = 0;\n int minPos = 0;\n for (int i = 0; i < n; i++) {\n if (chars[i] == '(') ++lev;\n else --lev;\n if (lev < minLev) {\n minLev = lev;\n minPos = i + 1;\n }\n }\n if (lev != 0) {\n quickAnswer(\"0\\n1 1\");\n }\n minPos %= n;\n this.minPos = minPos;\n up = new boolean[n];\n for (int i = 0; i < n; i++) {\n up[i] = chars[(i + minPos) % n] == '(';\n }\n }\n\n public void solve() throws QuickAnswer {\n int lev = 0;\n int i1 = 0;\n int i2 = 0;\n int bonus = 0;\n int istart = -1;\n int b = 1;\n for (int i = 0; i < n; i++) {\n if (up[i]) lev++;\n else lev--;\n if (lev == 2) {\n if (up[i]) istart = i;\n else ++b;\n } else if (lev == 1 && !up[i]) {\n if (b > bonus) {\n i1 = istart;\n i2 = i;\n bonus = b;\n }\n istart = -1;\n b = 1;\n }\n }\n\n up[i1] = false;\n up[i2] = true;\n lev = 0;\n int cnt = 0;\n for (int i = 0; i < n; i++) {\n if (up[i]) lev++;\n else lev--;\n if (lev == 0) ++cnt;\n }\n up[i1] = true;\n up[i2] = false;\n\n int cnt1 = 0;\n int last0 = 0;\n for (int i = 0; i < n; i++) {\n if (up[i]) lev++;\n else lev--;\n if (lev == 1) ++cnt1;\n if (lev == 0) {\n if (cnt1 > cnt) {\n i1 = last0;\n i2 = i;\n cnt = cnt1;\n }\n cnt1 = 0;\n last0 = i + 1;\n }\n }\n\n println(cnt);\n print(1 + (i1 + minPos) % n, 1 + (i2 + minPos) % n);\n\n\n }\n\n // Common functions\n\n void quickAnswer(String answer) throws QuickAnswer {\n throw new QuickAnswer(answer);\n }\n\n void quickAnswer() throws QuickAnswer {\n quickAnswer(QUICK_ANSWER);\n }\n\n\n static class QuickAnswer extends Exception {\n private String answer;\n\n public QuickAnswer(String answer) {\n this.answer = answer;\n }\n }\n\n void print(Object... args) {\n String prefix = \"\";\n for (Object arg : args) {\n out.append(prefix);\n out.append(arg);\n prefix = \" \";\n }\n }\n\n void println(Object... args) {\n print(args);\n out.append(\"\\n\");\n }\n\n void printsp(Object... args) {\n print(args);\n out.append(\" \");\n }\n\n int nextInt() {\n return in.nextInt();\n }\n\n long nextLong() {\n return in.nextLong();\n }\n\n String nextString() {\n String res = in.nextLine();\n return res.trim().isEmpty() ? in.nextLine() : res;\n }\n\n int[] nextInts(int count) {\n int[] res = new int[count];\n for (int i = 0; i < count; ++i) {\n res[i] = in.nextInt();\n }\n return res;\n }\n\n long[] nextLongs(int count) {\n long[] res = new long[count];\n for (int i = 0; i < count; ++i) {\n res[i] = in.nextInt();\n }\n return res;\n }\n\n public static void main(String[] args) {\n doMain(System.in, System.out);\n }\n\n static void doMain(InputStream inStream, PrintStream outStream) {\n Scanner in = new Scanner(new BufferedInputStream(inStream)).useLocale(Locale.ENGLISH);\n StringBuilder totalOut = new StringBuilder();\n int count = 1;\n //count = in.nextInt();\n while (count-- > 0) {\n try {\n StringBuilder out = new StringBuilder();\n new TaskD(in, out).solve();\n totalOut.append(out.toString());\n } catch (QuickAnswer e) {\n totalOut.append(e.answer);\n }\n if (count > 0) {\n totalOut.append(\"\\n\");\n }\n }\n outStream.print(totalOut.toString());\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3f24da231582999cf0a94d63aed60c47", "src_uid": "be820239276b5e1a346309f9dd21c5cb", "difficulty": 2500.0} {"lang": "Java 8", "source_code": " \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 Main\n{\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t\t// your code goes here\n\t\tScanner scanner = new Scanner(System.in);\n\t\tint a = scanner.nextInt();\n\t\tint h = scanner.nextInt();\n\t\tint w = scanner.nextInt(); \n\t\tint g = h+a, gn = w+a;\n\t\twhile (gn>0) {\n\t\t\tint t = gn;\n\t\t\tgn = g%gn;\n\t\t\tg = t;\n\t\t\n\t\t}\n\t\t\n\t\tint k = g/a;\n\t\t\n\t\tif (k>0&&1.0*g/k<=h&&1.0*g/k<=w) {\n\t\t\tSystem.out.println(1.0*g/k-a);\n\t\t} else {\n\t\t\tSystem.out.println(-1);\n\t\t}\n\t\t\n\t\t\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3d875fddae725ce886a707fe4b1cf818", "src_uid": "7fbefd3eb1aad6865adcfac394f0a7e6", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.util.HashMap;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.util.Map;\nimport java.util.Map.Entry;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedReader;\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 TaskG solver = new TaskG();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskG {\n public long[] prime;\n public long[] power;\n public int mod = 1000000007;\n public long[] dp;\n public int nzeros;\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n char[] c = in.next().toCharArray();\n nzeros = 0;\n for (int i = 0; i < c.length; i++) {\n if (c[i] == '0') {\n nzeros++;\n }\n }\n int n = in.nextInt();\n long mult = 1;\n prime = new long[n];\n power = new long[n];\n for (int i = 0; i < n; i++) {\n prime[i] = in.nextInt();\n power[i] = in.nextInt();\n mult = mult * Utils.mod_exp(prime[i], power[i] - 1, mod) % mod;\n }\n Arrays.sort(prime);\n int k = 0;\n while (k < n && prime[k] <= c.length) k++;\n dp = new long[nzeros + 1];\n dp[0] = 1;\n for (int i = k; i < n; i++) {\n long[] next = new long[dp.length];\n for (int j = 0; j < dp.length; j++) {\n // skip all\n next[j] = (next[j] + (prime[i] - c.length) * dp[j]) % mod;\n // hit exist\n next[j] = (next[j] + (nzeros - j) * dp[j]) % mod;\n // hit new\n if (j > 0) {\n next[j] = (next[j] + j * dp[j - 1]) % mod;\n }\n }\n dp = next;\n }\n HashMap dp2 = new HashMap<>();\n dp2.put(0L, 1);\n for (int i = 0; i < k; i++) {\n HashMap next = new HashMap<>();\n for (int j = 0; j < prime[i]; j++) {\n boolean bad = false;\n long d = 0;\n for (int w = j; w < c.length; w += prime[i]) {\n d |= 1L << w;\n if (c[w] == '1') {\n bad = true;\n }\n }\n if (!bad) {\n dp2.forEach((k,v) -> {\n long nk = k | d;\n next.put(nk, (v+next.getOrDefault(nk, 0)) % mod);\n });\n }\n }\n dp2 = next;\n }\n long nways = 0;\n dp2.forEach((k,v) -> nways = (nways + dp[nzeros - Long.bitCount(k)] * v) % mod);\n nways = nways * mult % mod;\n out.println(nways);\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 Utils {\n public static long mod_exp(long b, long e, long mod) {\n long res = 1;\n while (e > 0) {\n if ((e & 1) == 1)\n res = (res * b) % mod;\n b = (b * b) % mod;\n e >>= 1;\n }\n return res;\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}", "lang_cluster": "Java", "compilation_error": true, "code_uid": "bc5455e66043cf54c3875611e5db344d", "src_uid": "a0140a8fc4215acec5f046485bc2c7f9", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\npublic class E2 {\n\tstatic PrintWriter out = new PrintWriter(System.out);\t\n\tstatic int M;\n\tstatic int maxN = 200001;\n\tstatic int curN;\n\tstatic Edge adj[][];\n\tstatic int curE[];\n\tstatic ArrayList candidates;\n\tstatic int[] sz;\n\tstatic final boolean debug = false;\n\tpublic static void main(String[] args) {\n\t\tFS in = new FS();\n\t\tint N = in.nextInt();\n\t\tM = in.nextInt();\n\t\t\n\t\tArrayDeque es[] = new ArrayDeque[N];\n\t\tfor(int i = 0; i < N; i++) es[i] = new ArrayDeque();\n\t\tfor(int i = 0; i < N-1; i++) {\n\t\t\tint u = in.nextInt()-1;\n\t\t\tint v = in.nextInt()-1;\n\t\t\tlong m = in.nextLong();\n\t\t\tlong b = in.nextLong();\n\t\t\tEdge e = new Edge(u,v,m,b);\n\t\t\tes[u].add(e);\n\t\t\tes[v].add(e);\n\t\t}\n\t\t\n\t\tcurN = N;\n\t\tadj = new Edge[maxN][3];\n\t\tcurE = new int[maxN];\n\t\tfixTree(0, -1, es);\n\t\n\t\tif(debug) {\n\t\t\tSystem.out.println(\"N= \"+ curN);\n\t\t\tfor(int i = 0; i < curN; i++) {\n\t\t\t\tSystem.out.println(i+\" \"+adj[i].toString());\n\t\t\t}\n\t\t}\n\t\t\n\t\tcandidates = new ArrayList<>();\n\t\tsz = new int[curN];\n\t\tsolve(0);\n\t\t\n\t\tCHT cht = new CHT(1);\n\t\tfor(VecL[] cs : candidates) {\n\t\t\tfor(VecL v : cs) {\n\t\t\t\tcht.add(v.x, v.y);\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor(int i = 0; i < M; i++) out.print(cht.query(i)+\" \");\n\t\tout.println();\n\t\tout.close();\n\t}\n\t\n\tstatic void solve(int node) {\n\t\tszdfs(node, -1);\n\t\tif(sz[node] == 1) return; // base case, no edges\n\t\tEdge e = getEdgetroid(node, -1, sz[node], null);\n\t\te.blocked = true;\n\t\t\n\t\t//solve on this guy\n\t\tArrayList left = new ArrayList();\n\t\tArrayList right = new ArrayList();\n\t\tmakeLines(e.u, -1, e.m, e.b, left);\n\t\tmakeLines(e.v, -1, 0, 0, right);\n\t\t\n\t\tVecL[] minskowski = minkowskiSum(getHull(removeDupes(left)), getHull(removeDupes(right)));\n\t\tcandidates.add(minskowski);\n\n\t\tif(debug) {\n\t\t\tSystem.out.println(\"Decomp on: \"+e);\n\t\t\tSystem.out.println(\" Left: \"+left.toString());\n\t\t\tSystem.out.println(\" Right: \"+right.toString());\n\t\t\tSystem.out.println(\" Minskowski: \"+Arrays.toString(minskowski));\n\t\t}\n\t\t\n\t\t//now solve on the remaining stuff\n\t\tsolve(e.u);\n\t\tsolve(e.v);\n\t}\n\t\n\tstatic void makeLines(int node, int p, long curM, long curB, ArrayList vecs) {\n\t\tint to = 0;\n\t\tfor(Edge e : adj[node]) {\n\t\t\tif(e == null || e.blocked || e.to(node) == p) continue;\n\t\t\tto++;\n\t\t\tmakeLines(e.to(node), node, curM + e.m, curB + e.b, vecs);\n\t\t}\n\t\tif(to == 0) vecs.add(new VecL(curM, curB));\n\t}\n\t\n\tstatic Edge getEdgetroid(int node, int p, int totalSz, Edge curBest) {\n\t\tEdge myBest = null;\n\t\tfor(Edge e : adj[node]) {\n\t\t\tif(e == null || e.blocked || e.to(node) == p) continue;\n\t\t\tif(myBest == null || myBest.getDif(totalSz) > e.getDif(totalSz)) {\n\t\t\t\tmyBest = e;\n\t\t\t}\n\t\t}\n\t\tif(curBest != null && (myBest == null || curBest.getDif(totalSz) <= myBest.getDif(totalSz))) return curBest;\n\t\treturn getEdgetroid(myBest.to(node), node, totalSz, myBest);\n\t}\n\tstatic void szdfs(int node, int p) {\n\t\tsz[node] = 1;\n\t\tfor(Edge e : adj[node]) {\n\t\t\tif(e == null || e.blocked || e.to(node) == p) continue;\n\t\t\tszdfs(e.to(node), node);\n\t\t\tsz[node] += sz[e.to(node)];\n\t\t}\n\t}\n\t\n\tstatic void fixTree(int node, int p, ArrayDeque es[]) {\n\t\tint cur = node;\n\t\twhile(!es[node].isEmpty()) {\n\t\t\tif(es[node].size() <= 2) {\n\t\t\t\twhile(!es[node].isEmpty()) {\n\t\t\t\t\tEdge e = es[node].poll();\n\t\t\t\t\te.swap(node, cur);\n\t\t\t\t\tint to = e.to(cur);\n\t\t\t\t\taddEdge(cur, to, e, false, es);\n\t\t\t\t\tfixTree(to, cur, es);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\t//add left edge to my current guy\n\t\t\t\tEdge e = es[node].poll();\n\t\t\t\te.swap(node, cur);\n\t\t\t\tint to = e.to(cur);\n\t\t\t\taddEdge(cur, to, e, false, es);\n\t\t\t\tfixTree(to, cur, es);\n\t\t\t\t\n\t\t\t\tint next = curN++;\n\t\t\t\tEdge filler = new Edge(cur, next, 0, 0);\n\t\t\t\taddEdge(cur, next, filler, true, es);\n\t\t\t\tcur = next;\n\t\t\t}\n\t\t}\n\t}\n\tstatic void addEdge(int a, int b, Edge e, boolean filler, ArrayDeque es[]) {\n\t\tadj[a][curE[a]++] = e;\n\t\tadj[b][curE[b]++] = e;\n\t\tif(!filler) es[b].remove(e);\n\t}\n\t\n\tstatic class Edge{\n\t\tint u,v;\n\t\tlong m,b;\n\t\tboolean blocked;\n\t\tpublic Edge(int uu, int vv, long mm, long bb) {\n\t\t\tu=uu; v=vv; m=mm; b=bb;\n\t\t\tblocked = false;\n\t\t}\n\t\tint to(int node) { return u^v^node; }\n\t\tvoid swap(int from, int to) {\n\t\t\tif(u == from) u = to;\n\t\t\telse if(v == from) v = to;\n\t\t\telse throw null;\n\t\t}\n\t\tint getDif(int totalSz) {\n\t\t\tint s1 = Math.min(sz[u], sz[v]);\n\t\t\tint s2 = totalSz - Math.min(sz[u], sz[v]);\n\t\t\treturn Math.abs(s1-s2);\n\t\t}\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn \"[u=\"+u+\" v=\"+v+\" m=\"+m+\" b=\"+b+\"]\";\n\t\t}\n\t}\n\t\n\t\n\t// Computes the convex hull of the Minkowski sum of 2 convex polygons.\n\t// Polygons must be in CCW order and returns the sum in same order\n\t// O(N + M) where N and M are the sizes of the two polygons\n\tpublic static VecL[] minkowskiSum(VecL[] a, VecL[] b) {\n\t\tint n = a.length, m = b.length, k = 0;\n\t\tVecL[] h = new VecL[n+m];\n\t\th[k++] = a[0].add(b[0]);\n\t\tfor(int i = 0, j = 0; i+1 < n || j+1 < m;) {\n\t\t\tif(j+1 == m || (i+1 < n && (a[i+1].sub(a[i])).cross(b[j+1].sub(b[j])) < 0)){\n\t\t\t\th[k++] = a[++i].add(b[j]);\n\t\t\t} else {\n\t\t\t\th[k++] = a[i].add(b[++j]);\n\t\t\t}\n\t\t}\n\t\tif(k < 3) return Arrays.copyOf(h, k);\n\t\tVecL[] res = new VecL[n+m];\n\t\tint c = 0;\n\t\tfor(int i = 0; i < k; i++) {\n\t\t\tif(valid(h[(i-1+k)%k], h[i], h[(i+1)%k])) res[c++] = h[i];\n\t\t}\n\t\treturn Arrays.copyOf(res, c);\n\t}\n\t\n\tstatic boolean valid(VecL a, VecL b, VecL c) {\n\t\tVecL d1 = b.sub(a), d2 = c.sub(b);\n\t\tlong cross = d1.cross(d2), dot = d1.dot(d2);\n\t\treturn cross != 0 || (cross == 0 && dot < 0);\n\t}\n\t\n\tstatic VecL[] simple(VecL[] pnt, VecL[] c) {\n\t\tVecL[] res = new VecL[c.length];\n\t\tfor(int i = 0; i < c.length; i++) res[i] = c[i].add(pnt[0]);\n\t\treturn res;\n\t}\n\t\n\tstatic SegL[] toSeg(VecL pnts[]) {\n\t\tSegL[] res = new SegL[pnts.length];\n\t\tfor(int i = 0; i < pnts.length; i++) {\n\t\t\tres[i] = new SegL(pnts[i], pnts[(i+1)%pnts.length]);\n\t\t}\n\t\treturn res;\n\t}\n\t\n\tstatic boolean better(int i1, int i2, SegL c1[], SegL c2[]) {\n\t\tif(i1 == -1) return false;\n\t\tif(i2 == -1) return true;\n\t\treturn c1[i1].dir.radialCompare(c2[i2].dir) <= 0;\n\t}\n\t\n\tstatic int getSt(SegL[] segs) {\n\t\tif(segs.length == 1) return -1;\n\t\tif(segs.length == 2) {\n\t\t\tif(segs[0].dir.y > 0 || (segs[0].dir.y == 0 && segs[0].dir.x > 0)) return 0;\n\t\t\treturn 1;\n\t\t}\n\t\tfor(int i = 0; i < segs.length; i++) {\n\t\t\tSegL prev = i == 0 ? segs[segs.length-1] : segs[i-1];\n\t\t\tSegL cur = segs[i];\n\t\t\tif(cur.dir.y >= 0 && prev.dir.y < 0) return i;\n\t\t}\n\t\treturn -1;\n\t}\n\n\t\n\t\n\tpublic static VecL[] removeDupes(ArrayList points) {\n\t\tHashSet set=new HashSet<>();\n\t\tfor (VecL v:points)\n\t\t\tset.add(v);\n\t\tint counter=0;\n\t\tVecL res[] = new VecL[set.size()];\n\t\tfor (VecL v:set) res[counter++]=v;\n\t\treturn res;\n\t}\n\t// returns the hull in CCW order\n\tpublic static VecL[] getHull(VecL[] points) {\n\t\tpoints=points.clone();\n\t\tArrays.sort(points);\n\t\tif (points.length<3)\n\t\t\treturn points;\n\t\tint n=points.length, j=2, k=2;\n\t\tVecL[] lo=new VecL[n], up=new VecL[n];\n\t\tlo[0]=points[0];\n\t\tlo[1]=points[1];\n\t\tfor (int i=2; i1&&!right(lo[j-2], lo[j-1], p)) j--;\n\t\t\tlo[j++]=p;\n\t\t}\n\t\tup[0]=points[n-1];\n\t\tup[1]=points[n-2];\n\t\tfor (int i=n-3; i>=0; i--) {\n\t\t\tVecL p=points[i];\n\t\t\twhile (k>1&&!right(up[k-2], up[k-1], p)) k--;\n\t\t\tup[k++]=p;\n\t\t}\n\n\t\tVecL[] res=new VecL[j+k-2];\n\t\tfor (int i=0; ib->c are in the right order\n\tstatic boolean right(VecL a, VecL b, VecL c) {\n\t\treturn b.sub(a).cross(c.sub(a))>0;\n\t}\n\t\n\tstatic class VecL implements Comparable{\n\t\tlong x,y;\n\t\tpublic VecL(long xx, long yy) {\n\t\t\tx=xx;\n\t\t\ty=yy;\n\t\t}\n\t\tpublic VecL add(VecL o) { return new VecL(x+o.x, y+o.y);}\n\t\tpublic VecL sub(VecL o) { return new VecL(x-o.x, y-o.y);}\n\t\tpublic long cross(VecL o) { return x*o.y - y*o.x;}\n\t\tpublic long dot(VecL o) { return x*o.x + y*o.y;}\n\t\tpublic int quadrant() {\n\t\t\tif (x==0||y==0)\n\t\t\t\tif (y==0)\n\t\t\t\t\tif (x>=0)\n\t\t\t\t\t\treturn 1;\n\t\t\t\t\telse\n\t\t\t\t\t\treturn 3;\n\t\t\t\telse\n\t\t\t\t\tif (y>=0)\n\t\t\t\t\t\treturn 2;\n\t\t\t\t\telse\n\t\t\t\t\t\treturn 4;\n\t\t\tif (x>0)\n\t\t\t\tif (y>0)\n\t\t\t\t\treturn 1;\n\t\t\t\telse\n\t\t\t\t\treturn 4;\n\t\t\telse\n\t\t\t\tif (y>0)\n\t\t\t\t\treturn 2;\n\t\t\t\telse\n\t\t\t\t\treturn 3;\n\t\t}\n\t\t\n\t\tpublic int radialCompare(VecL o) {\n\t\t\tif (quadrant()==o.quadrant())\n\t\t\t\treturn -Long.signum(cross(o));\n\t\t\treturn Integer.compare(quadrant(), o.quadrant());\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(VecL o) {\n\t\t\tif(x!=o.x) return Long.compare(x, o.x);\n\t\t\treturn Long.compare(y, o.y);\n\t\t}\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn \"(\"+x+\",\"+y+\")\";\n\t\t}\n\t\tpublic int hashCode() {\n\t\t\treturn Long.hashCode(x<<13^(y*57));\n\t\t}\n\t\t\n\t\tpublic boolean equals(Object oo) {\n\t\t\tVecL o=(VecL)oo;\n\t\t\treturn x==o.x&&y==o.y;\n\t\t}\t\t\n\t}\n\t\n\tstatic class SegL{\n\t\tVecL from, to, dir;\n\t\tpublic SegL(VecL a, VecL b) {\n\t\t\tfrom=a;\n\t\t\tto=b;\n\t\t\tdir = to.sub(from);\n\t\t}\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn \"[\"+from+\" -> \"+to+\"]\";\n\t\t}\n\t}\n\t\n\tstatic class CHT {\n\t\tTreeSet hull;\n\t\tint type; boolean query = false;\n\t\tComparator comp = new Comparator() {\n\t\t\tpublic int compare(Line a, Line b) {\n\t\t\t\tif (!query) return type * Long.compare(a.m, b.m);\n\t\t\t\tif (a.left == b.left) return Long.compare(a.m, b.m);\n\t\t\t\treturn Double.compare(a.left, b.left);\n\t\t\t}\n\t\t};\n\t\t// -1 for min; +1 for max\n\t\tpublic CHT(int typee) { type = typee; hull = new TreeSet<>(comp); }\n\n\t\tpublic void add(long m, long b) { add(new Line(m, b)); }\n\n\t\tpublic void add(Line a) {\n\t\t\tLine[] LR = { hull.lower(a), hull.ceiling(a) };\n\t\t\tfor (int i = 0; i < 2; i++)\n\t\t\t\tif (LR[i] != null && LR[i].m == a.m) {\n\t\t\t\t\tif (type == 1 && LR[i].b >= a.b) return;\n\t\t\t\t\tif (type == -1 && LR[i].b <= a.b) return;\n\t\t\t\t\tremove(LR[i]);\n\t\t\t\t}\n\t\t\thull.add(a);\n\t\t\tLine L = hull.lower(a), R = hull.higher(a);\n\t\t\tif (L != null && R != null && a.inter(R) <= R.left) {\n\t\t\t\thull.remove(a);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tLine LL = (L != null) ? hull.lower(L) : null;\n\t\t\tLine RR = (R != null) ? hull.higher(R) : null;\n\t\t\tif (L != null) a.left = a.inter(L);\n\t\t\tif (R != null) R.left = a.inter(R);\n\t\t\twhile (LL != null && L.left >= a.inter(LL)) {\n\t\t\t\tremove(L);\n\t\t\t\ta.left = a.inter(L = LL);\n\t\t\t\tLL = hull.lower(L);\n\t\t\t}\n\t\t\twhile (RR != null && R.inter(RR) <= a.inter(RR)) {\n\t\t\t\tremove(R);\n\t\t\t\tRR.left = a.inter(R = RR);\n\t\t\t\tRR = hull.higher(R);\n\t\t\t}\n\t\t}\n\n\t\tpublic long query(long x) {\n\t\t\tif(hull.size() == 0) return 0;\n\t\t\tLine temp = new Line(0, 0, 0);\n\t\t\ttemp.left = x; query = true;\n\t\t\tlong ans = (long) hull.floor(temp).eval(x);\n\t\t\tquery = false; return ans;\n\t\t}\n\n\t\tprivate void remove(Line x) { hull.remove(x); }\n\n\t\tpublic int size() { return hull.size(); }\n\n\t\tstatic class Line {\n\t\t\tlong m, b; double left = Long.MIN_VALUE;\n\t\t\tpublic Line(long mm, long x, long y) { m = mm; b = -m * x + y; }\n\t\t\tpublic Line(long mm, long bb) { m = mm; b = bb; }\n\t\t\tpublic long eval(long x) { return m * x + b; }\n\t\t\tpublic double inter(Line x) {\n\t\t\t\treturn (double) (x.b - this.b) / (double) (this.m - x.m);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tstatic class FS{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FS() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\t\tString next() {\n\t\t\twhile(st == null || !st.hasMoreElements()) {\n\t\t\t\ttry {st = new StringTokenizer(br.readLine());}\n\t\t\t\tcatch(Exception e) { throw null;}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tint nextInt() { return Integer.parseInt(next());}\n\t\tdouble nextDouble() { return Double.parseDouble(next());}\n\t\tlong nextLong() { return Long.parseLong(next());}\n\t\tint[] NIA(int n) {\n\t\t\tint r[] = new int[n];\n\t\t\tfor(int i = 0; i < n; i++) r[i] = nextInt();\n\t\t\treturn r;\n\t\t}\n\t\tlong[] NLA(int n) {\n\t\t\tlong r[] = new long[n];\n\t\t\tfor(int i = 0; i < n; i++) r[i] = nextLong();\n\t\t\treturn r;\n\t\t}\n\t\tchar[][] grid(int r, int c){\n\t\t\tchar res[][] = new char[r][c];\n\t\t\tfor(int i = 0; i < r; i++) {\n\t\t\t\tchar l[] = next().toCharArray();\n\t\t\t\tfor(int j = 0; j < c; j++) {\n\t\t\t\t\tres[i][j] = l[j];\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\t}\n\t\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3af00ef7a57a4a0e866f66b7b3ae1df1", "src_uid": "7bccdabeb9f16ee0b4f16c37de564c31", "difficulty": 3200.0} {"lang": "Java 11", "source_code": "//package afc2020;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.List;\nimport java.util.Scanner;\n\npublic class G {\n\tScanner in;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tList ins = new ArrayList<>();\n\t\tfor(int i = 0;i < 11;i++) {\n\t\t\tins.add(ni());\n\t\t}\n\t\tfor(int i = ins.size()-1;i >= 0;i--) {\n\t\t\tdouble x = ins.get(i);\n\t\t\tdouble ans = x*x*x*5.0 + Math.sqrt(Math.abs(x));\n\t\t\tif(Math.abs(ans) >= 5000) {\n\t\t\t\tout.printf(\"f(%d) = MAGNA NIMIS!\\n\", ins.get(i), ans);\n\t\t\t}else {\n\t\t\t\tout.printf(\"f(%d) = %.2f\\n\", ins.get(i), ans);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tin = oj ? new Scanner(System.in) : new Scanner(INPUT);\n\t\tout = new PrintWriter(System.out);\n\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tnew G().run();\n\t}\n\t\n\tint ni() { return Integer.parseInt(in.next()); }\n\tlong nl() { return Long.parseLong(in.next()); }\n\tdouble nd() { return Double.parseDouble(in.next()); }\n\tboolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tvoid tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fdab2e3964d5884ac209f77337a94bc1", "src_uid": "30b3411c3c23d029ea1e9cf73e7d2f01", "difficulty": null} {"lang": "Java 6", "source_code": "/**\n * Created by IntelliJ IDEA.\n * User: Taras_Brzezinsky\n * Date: 8/24/11\n * Time: 8:54 PM\n * To change this template use File | Settings | File Templates.\n */\n\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.FileReader;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.util.Arrays;\n\npublic class TaskD extends Thread {\n\n public TaskD() {\n this.input = new BufferedReader(new InputStreamReader(System.in));\n this.output = new PrintWriter(System.out);\n this.setPriority(Thread.MAX_PRIORITY);\n }\n\n\n static class Matrix {\n long [][]grid;\n long [][]helper;\n public Matrix(int size, boolean E) {\n this.grid = new long[size][size];\n this.helper = new long [size][size];\n if (E) {\n for (int i = 0; i < grid.length; ++i) {\n grid[i][i] = 1;\n }\n }\n }\n\n public Matrix pow(long power) {\n Matrix result = new Matrix(grid.length, true);\n Matrix stat = new Matrix(grid.length, false);\n for (int i = 0; i < grid.length; ++i) {\n stat.grid[i] = this.grid[i].clone();\n }\n for (; power != 0; power >>= 1) {\n if ((power & 1) == 1) {\n result.multiply(stat);\n }\n stat.multiply(stat);\n }\n return result;\n }\n\n\n private void multiply(Matrix another) {\n assert(this.grid.length == another.grid.length);\n for (long[] current : helper) {\n Arrays.fill(current, 0);\n }\n for (int i = 0; i < grid.length; ++i) {\n for (int j = 0; j < grid.length; ++j) {\n for (int k = 0; k < grid.length; ++k) {\n helper[i][j] += (grid[i][k] * another.grid[k][j]) % MODULO;\n }\n helper[i][j] %= MODULO;\n }\n }\n for (int i = 0; i < grid.length; ++i) {\n System.arraycopy(helper[i], 0, grid[i], 0, grid.length);\n }\n }\n }\n\n\n static class Rule {\n char letter;\n char value;\n public Rule(char letter, char value) {\n this.letter = letter;\n this.value = value;\n }\n }\n\n private void generate(int index, int size) {\n if (index == initial.length) {\n states[size++] = initial.clone();\n } else {\n for (char value = 0; value < rules[index].value; ++value) {\n initial[index] = value;\n generate(index + 1, size);\n }\n }\n }\n\n private boolean isFinal(int index) {\n for (char letter = 'A'; letter <= 'Z'; ++letter) {\n boolean was = false, isGood = false;\n for (int i = 0; i < rules.length; ++i) {\n if (rules[i].letter == letter) {\n was = true;\n isGood |= states[index][i] == 0;\n }\n }\n if (was && !isGood) {\n return false;\n }\n }\n return true;\n }\n\n\n private void solve() throws Throwable {\n long n = nextLong();\n int c = nextInt();\n rules = new Rule[c];\n int total = 1;\n for (int i = 0; i < c; ++i) {\n rules[i] = new Rule(nextToken().charAt(0), (char)(nextInt()));\n total *= rules[i].value;\n }\n initial = new char [c];\n states = new char[total][];\n generate(0, 0);\n Matrix operator = new Matrix(total, false);\n char []helper;\n for (int state = 0; state < total; ++state) {\n helper = states[state].clone();\n for (int i = 0; i < helper.length; ++i) {\n helper[i] = (char)((helper[i] + 1) % rules[i].value);\n for (int where = 0; where < total; ++where) {\n boolean ok = true;\n for (int index = 0; index < helper.length; ++index) {\n ok &= helper[index] == states[where][index];\n }\n if (ok) {\n operator.grid[state][where]++;\n break;\n }\n }\n }\n }\n Matrix finish = operator.pow(n);\n long result = 0;\n for (int current = 0; current < total; ++current) {\n if (isFinal(current)) {\n result = (result + finish.grid[0][current]) % MODULO;\n }\n }\n output.println(result);\n }\n\n public void run() {\n try {\n solve();\n } catch (Throwable e) {\n System.err.println(e.getMessage());\n e.printStackTrace();\n System.exit(666);\n } finally {\n output.flush();\n output.close();\n }\n }\n\n\n public static void main(String[] args) {\n new TaskD().start();\n }\n\n private String nextToken() throws IOException {\n while (tokens == null || !tokens.hasMoreTokens()) {\n tokens = new StringTokenizer(input.readLine());\n }\n return tokens.nextToken();\n }\n\n private int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n private double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n private long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n private static final int MODULO = 12345;\n private char [][]states;\n private char []initial;\n private Rule []rules;\n private BufferedReader input;\n private PrintWriter output;\n private StringTokenizer tokens = null;\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7d536c5e6de44857e666974d99064410", "src_uid": "76d4684d26dac380713a566a1e277c91", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Iterator;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.NoSuchElementException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Rustam Musin (PloadyFree@gmail.com)\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskE solver = new TaskE();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskE {\n private int n;\n private boolean[] isRed;\n private int[] costRed;\n private int[] costBlue;\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n input(in);\n out.print(solve());\n }\n\n private long solve() {\n int maxSaveRed = 120;\n int[][] dp = new int[1 << n][maxSaveRed];\n ArrayUtils.fill(dp, -1);\n dp[0][0] = 0;\n for (int curMask = 0; curMask < 1 << n; curMask++) {\n int haveRedCards = getCards(curMask, true);\n int haveBlueCards = getCards(curMask, false);\n for (int curSaveRed = 0; curSaveRed < maxSaveRed; curSaveRed++) {\n if (dp[curMask][curSaveRed] == -1) {\n continue;\n }\n int curSaveBlue = dp[curMask][curSaveRed];\n for (int i = 0; i < n; i++) {\n if (bit(curMask, i) == 0) {\n int saveRed = Math.min(haveRedCards, costRed[i]);\n int saveBlue = Math.min(haveBlueCards, costBlue[i]);\n int nextSaveRed = curSaveRed + saveRed;\n int nextMask = set(curMask, i);\n if (dp[curMask][curSaveRed] + saveBlue > dp[nextMask][nextSaveRed]) {\n dp[nextMask][nextSaveRed] = curSaveBlue + saveBlue;\n }\n }\n }\n }\n }\n long totalRed = ArrayUtils.sumArray(costRed);\n long totalBlue = ArrayUtils.sumArray(costBlue);\n long ans = Math.max(totalRed, totalBlue);\n for (int i = 0; i < maxSaveRed; i++) {\n if (dp[(1 << n) - 1][i] == -1) {\n continue;\n }\n ans = Math.min(ans, Math.max(totalRed - i, totalBlue - dp[(1 << n) - 1][i]));\n }\n return ans + n;\n }\n\n private void input(InputReader in) {\n n = in.readInt();\n isRed = new boolean[n];\n costRed = new int[n];\n costBlue = new int[n];\n for (int i = 0; i < n; i++) {\n isRed[i] = in.next().equals(\"R\");\n costRed[i] = in.readInt();\n costBlue[i] = in.readInt();\n }\n }\n\n private int getCards(int m, boolean red) {\n int cnt = 0;\n for (int i = 0; i < n; i++) {\n if (bit(m, i) == 1 && isRed[i] == red) {\n cnt++;\n }\n }\n return cnt;\n }\n\n private int set(int m, int b) {\n return m | (1 << b);\n }\n\n private int bit(int m, int b) {\n return (m >> b) & 1;\n }\n\n }\n\n static interface IntReversableCollection extends IntCollection {\n }\n\n static abstract class IntAbstractStream implements IntStream {\n\n public String toString() {\n StringBuilder builder = new StringBuilder();\n boolean first = true;\n for (IntIterator it = intIterator(); it.isValid(); it.advance()) {\n if (first) {\n first = false;\n } else {\n builder.append(' ');\n }\n builder.append(it.value());\n }\n return builder.toString();\n }\n\n\n public boolean equals(Object o) {\n if (!(o instanceof IntStream)) {\n return false;\n }\n IntStream c = (IntStream) o;\n IntIterator it = intIterator();\n IntIterator jt = c.intIterator();\n while (it.isValid() && jt.isValid()) {\n if (it.value() != jt.value()) {\n return false;\n }\n it.advance();\n jt.advance();\n }\n return !it.isValid() && !jt.isValid();\n }\n\n\n public int hashCode() {\n int result = 0;\n for (IntIterator it = intIterator(); it.isValid(); it.advance()) {\n result *= 31;\n result += it.value();\n }\n return result;\n }\n\n }\n\n static 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 print(long i) {\n writer.print(i);\n }\n\n }\n\n static interface IntIterator {\n public int value() throws NoSuchElementException;\n\n public boolean advance();\n\n public boolean isValid();\n\n }\n\n static interface IntList extends IntReversableCollection {\n public abstract int get(int index);\n\n public abstract void removeAt(int index);\n\n default public IntIterator intIterator() {\n return new IntIterator() {\n private int at;\n private boolean removed;\n\n public int value() {\n if (removed) {\n throw new IllegalStateException();\n }\n return get(at);\n }\n\n public boolean advance() {\n at++;\n removed = false;\n return isValid();\n }\n\n public boolean isValid() {\n return !removed && at < size();\n }\n\n public void remove() {\n removeAt(at);\n at--;\n removed = true;\n }\n };\n }\n\n }\n\n static interface IntCollection extends IntStream {\n public int size();\n\n }\n\n static class IntArray extends IntAbstractStream implements IntList {\n private int[] data;\n\n public IntArray(int[] arr) {\n data = arr;\n }\n\n public int size() {\n return data.length;\n }\n\n public int get(int at) {\n return data[at];\n }\n\n public void removeAt(int index) {\n throw new UnsupportedOperationException();\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public String readString() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n if (Character.isValidCodePoint(c)) {\n res.appendCodePoint(c);\n }\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public String next() {\n return readString();\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n\n static interface IntStream extends Iterable, Comparable {\n public IntIterator intIterator();\n\n default public Iterator iterator() {\n return new Iterator() {\n private IntIterator it = intIterator();\n\n public boolean hasNext() {\n return it.isValid();\n }\n\n public Integer next() {\n int result = it.value();\n it.advance();\n return result;\n }\n };\n }\n\n default public int compareTo(IntStream c) {\n IntIterator it = intIterator();\n IntIterator jt = c.intIterator();\n while (it.isValid() && jt.isValid()) {\n int i = it.value();\n int j = jt.value();\n if (i < j) {\n return -1;\n } else if (i > j) {\n return 1;\n }\n it.advance();\n jt.advance();\n }\n if (it.isValid()) {\n return 1;\n }\n if (jt.isValid()) {\n return -1;\n }\n return 0;\n }\n\n default public long sum() {\n long result = 0;\n for (IntIterator it = intIterator(); it.isValid(); it.advance()) {\n result += it.value();\n }\n return result;\n }\n\n }\n\n static class ArrayUtils {\n public static void fill(int[][] array, int value) {\n for (int[] row : array) {\n Arrays.fill(row, value);\n }\n }\n\n public static long sumArray(int[] array) {\n return new IntArray(array).sum();\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "669c1923fcdaec208ce0c16f86901a5a", "src_uid": "25a77f2b7cb281ff3c7800a20b3e5969", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "/*Author LAVLESH*/\nimport java.util.*;\nimport java.io.*;\npublic class solution{\n\tstatic BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\tstatic StringTokenizer st=new StringTokenizer(\"\");\n \n\t\n\n\tstatic public String next() {\n\t while (st == null || !st.hasMoreTokens()) {\n\t try {\n\t st = new StringTokenizer(br.readLine());\n\t } catch (IOException e) {\n\t throw new RuntimeException(e);\n\t }\n\t }\n\t return st.nextToken();\n\t }\n\tstatic long[]rc =new long[1000001];\n\tstatic int mod=1000003;\n\tstatic long inv(long a,int m){\n\t\tif(a==1)return 1;\n\t\treturn inv(m%a,m)*(m-m/a)%m;\n\t}\n\tpublic static void main(String[]args)throws IOException{\n\t\tPrintWriter op =new PrintWriter(System.out,true);\n\t\t int n=Integer.parseInt(next());\n\t\t int m=Integer.parseInt(next());\n\t\trc[m]=1;\n\t\t for(int i=m+1;i<=n+m;i++)\n\t\t\trc[i]=rc[i-1]*i%mod*inv(i-m,mod)%mod;\n\t\top.println(rc[n+m]-1);\n\t\t\n\t\t\n\t\t op.close();\n }\n}\n ", "lang_cluster": "Java", "compilation_error": false, "code_uid": "87815642f218ee11edcb9389c860e19d", "src_uid": "e63c70a9c96a94bce99618f2e695f83a", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in Actual solution is at the top\n *\n * @author svilen.marchev@gmail.com\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskF solver = new TaskF();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskF {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n String s = in.readString();\n// String vow = \"AEIOUY\";\n\n// \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\";\n String straightLetters = \"ABEFGHIJKMNOPQRSTUVWXZ\";\n\n boolean allStraight = true;\n for (char c : s.toCharArray()) {\n allStraight &= straightLetters.contains(\"\" + c);\n }\n out.println(allStraight ? \"YES\" : \"NO\");\n\n// int numVows = 0;\n// Set cons = new HashSet<>();\n// for (char c : s.toCharArray()) {\n// if (vow.contains(\"\"+c)) {\n// numVows++;\n// } else {\n// cons.add(c);\n// }\n// }\n// out.println(numVows < cons.size() ? \"YES\" : \"NO\");\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 String readString() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n if (Character.isValidCodePoint(c)) {\n res.appendCodePoint(c);\n }\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2d5d9c12743c9ae1dc068989f81379fa", "src_uid": "15008dcb8dc8506c39aef0e3d8fca70c", "difficulty": null} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.PriorityQueue;\nimport java.util.StringTokenizer;\n/*\n3 3 5\n0 1 1 0 7\n1 1 1 0 10\n1 1 1 1 2\n1 1 1 2 2\n0 1 1 2 3\n\n500 500 2\n0 1 1 0 4\n0 1 1 1 2\n\n\n500 500 8\n100 100 5 5 1\n100 101 5 5 2\n101 100 5 5 3\n101 101 5 5 4\n100 100 6 5 5\n100 101 6 5 6\n101 100 6 5 7\n101 101 6 5 8\n\n6 7 6\n0 2 2 2 100\n0 3 3 3 100\n0 2 2 1 201\n0 3 3 2 5\n1 2 1 3 1000\n1 2 1 2 1000\n200\n\n6 7 6\n0 2 2 2 100\n0 3 3 3 100\n0 2 2 1 194\n0 3 3 2 5\n1 2 1 3 1000\n1 2 1 2 1000\n199\n\n6 7 6\n1 2 2 3 100\n1 3 3 4 100\n1 2 2 2 194\n1 3 3 3 5\n2 2 1 4 1000\n2 2 1 3 1000\n0\n */\npublic class C {\n\t\n\tstatic long[][] costOf;\n\tstatic BonusAtSquare[][] hBonuses, vBonuses;\n\tstatic int maxX, maxY;\n\tstatic long[][][][] dp;\n\n\tpublic static void main(String[] args) {\n\t\tFastScanner fs=new FastScanner();\n\t\tmaxX=fs.nextInt(); \n\t\tmaxY=fs.nextInt();\n\t\tint nRobots=fs.nextInt();\n\t\tcostOf=new long[maxX][maxY];\n\t\thBonuses=new BonusAtSquare[maxX][maxY];\n\t\tvBonuses=new BonusAtSquare[maxX][maxY];\n\t\tfor (int x=0; x=0; xAt--) {\n\t\t\tfor (int j=0; j=0; yAt--) {\n\t\t\t\tfor (int goingH=0; goingH<2; goingH++) {\n\t\t\t\t\tfor (int timesGoingStraight=0; timesGoingStraight<=(goingH==0?xAt:yAt); timesGoingStraight++) {\n\t\t\t\t\t\tgo(xAt, yAt, timesGoingStraight, goingH);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong ans=go(0, 0, 0, 0);\n\t\tSystem.out.println(ans);\n\t\tSystem.err.println(System.currentTimeMillis()-startTime);\n\t}\n\t\n\tstatic long go(int x, int y, int timesGoingStraight, int goingH) {\n\t\tif (x==maxX-1&&y==maxY-1) {\n\t\t\treturn 0;\n\t\t}\n\t\tif (dp[(x&1)][y][timesGoingStraight][goingH]!=-1) return dp[(x&1)][y][timesGoingStraight][goingH];\n\t\tlong curCost=costOf[x][y];\n\t\tif (goingH==1)\n\t\t\tcurCost-=hBonuses[x][y].getBonus(timesGoingStraight);\n\t\telse\n\t\t\tcurCost-=vBonuses[x][y].getBonus(timesGoingStraight);\n//\t\tSystem.out.println(\"Cur cost \"+x+\" \"+y+\" is \"+curCost);\n\t\tlong best; \n\t\tif (goingH==1) {\n\t\t\tlong goH=y+1 pq=new PriorityQueue<>();\n\t\tpublic long bonusAdded=0;\n\t\t\n\t\tpublic void addBonus(int goingStraightFor, long bonus) {\n\t\t\tpq.add(new Bonus(goingStraightFor, bonus));\n\t\t}\n\t\t\n\t\tpublic long getBonus(int goingStraightFor) {\n\t\t\twhile (!pq.isEmpty()&&goingStraightFor>=pq.peek().goingStraightFor) {\n\t\t\t\tBonus next=pq.remove();\n\t\t\t\tbonusAdded+=next.points;\n\t\t\t}\n\t\t\treturn bonusAdded;\n\t\t}\n\t}\n\t\n\tstatic class Bonus implements Comparable {\n\t\tint goingStraightFor;\n\t\tlong points;\n\t\tpublic Bonus(int goingStraightFor, long points) {\n\t\t\tthis.goingStraightFor=goingStraightFor;\n\t\t\tthis.points=points;\n\t\t}\n\t\t\n\t\tpublic int compareTo(Bonus o) {\n\t\t\treturn Integer.compare(goingStraightFor, o.goingStraightFor);\n\t\t}\n\t}\n\t\n\tstatic void processTransformer(int x, int y, int d, int t, long fightCost) {\n//\t\tSystem.out.println(\"Processing transformer (\"+x+\", \"+y+\") d: \"+d+\" startTime: \"+t+\" fightCost: \"+fightCost);\n\t\tint[] xs=new int[4];\n\t\tint[] ys=new int[4];\n\t\tint[] firstTime=new int[4];\n\t\txs[0]=x;\n\t\tys[0]=y;\n\t\tfirstTime[0]=t;\n\t\txs[1]=x+d;\n\t\tys[1]=y-d;\n\t\tfirstTime[1]=t+1;\n\t\txs[2]=x+d;\n\t\tys[2]=y;\n\t\tfirstTime[2]=t+2;\n\t\txs[3]=x;\n\t\tys[3]=y+d;\n\t\tfirstTime[3]=t+3;\n\t\t\n\t\tArrayList xMatters=new ArrayList<>();\n\t\tArrayList yMatters=new ArrayList<>();\n\t\tfor (int i=0; i<4; i++) {\n\t\t\tif (matters(xs[i], ys[i], firstTime[i])) {\n\t\t\t\txMatters.add(xs[i]);\n\t\t\t\tyMatters.add(ys[i]);\n\t\t\t}\n\t\t}\n//\t\tSystem.out.println(\"\\t\"+xMatters+\" \"+yMatters);\n\t\tif (xMatters.size()>2) throw null;\n\t\tif (xMatters.size()==0) return;\n\t\tif (xMatters.size()==1) {\n\t\t\tcostOf[xMatters.get(0)][yMatters.get(0)]+=fightCost;\n\t\t}\n\t\telse {\n\t\t\tcostOf[xMatters.get(0)][yMatters.get(0)]+=fightCost;\n\t\t\tcostOf[xMatters.get(1)][yMatters.get(1)]+=fightCost;\n\t\t\tif (xMatters.get(0)==(int)xMatters.get(1)) {\n\t\t\t\thBonuses[xMatters.get(1)][yMatters.get(1)].addBonus(d, fightCost);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (yMatters.get(0)==(int)yMatters.get(1)) {\n\t\t\t\t\tvBonuses[xMatters.get(1)][yMatters.get(1)].addBonus(d, fightCost);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\t\n\tstatic boolean matters(int x, int y, int t) {\n\t\tif (x+y= 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 public int peek() {\n if (numChars == -1) {\n return -1;\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n return -1;\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar];\n }\n \n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\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 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 String nextString() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n if (Character.isValidCodePoint(c)) {\n res.appendCodePoint(c);\n }\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n \n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n \n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n \n private String readLine0() {\n StringBuilder buf = new StringBuilder();\n int c = read();\n while (c != '\\n' && c != -1) {\n if (c != '\\r') {\n buf.appendCodePoint(c);\n }\n c = read();\n }\n return buf.toString();\n }\n public String readLine() {\n String s = readLine0();\n while (s.trim().length() == 0) {\n s = readLine0();\n }\n return s;\n }\n public String readLine(boolean ignoreEmptyLines) {\n if (ignoreEmptyLines) {\n return readLine();\n } else {\n return readLine0();\n }\n }\n \n public BigInteger readBigInteger() {\n try {\n return new BigInteger(nextString());\n } catch (NumberFormatException e) {\n throw new InputMismatchException();\n }\n }\n \n public char nextCharacter() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n return (char) c;\n }\n \n public double nextDouble() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n double res = 0;\n while (!isSpaceChar(c) && c != '.') {\n if (c == 'e' || c == 'E') {\n return res * Math.pow(10, nextInt());\n }\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n }\n if (c == '.') {\n c = read();\n double m = 1;\n while (!isSpaceChar(c)) {\n if (c == 'e' || c == 'E') {\n return res * Math.pow(10, nextInt());\n }\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n m /= 10;\n res += (c - '0') * m;\n c = read();\n }\n }\n return res * sgn;\n }\n \n public boolean isExhausted() {\n int value;\n while (isSpaceChar(value = peek()) && value != -1) {\n read();\n }\n return value == -1;\n }\n public String next() {\n return nextString();\n }\n \n public SpaceCharFilter getFilter() {\n return filter;\n }\n \n public void setFilter(SpaceCharFilter filter) {\n this.filter = filter;\n }\n \n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n public int[] nextIntArray(int n){\n int[] array=new int[n];\n for(int i=0;i pq = new PriorityQueue();\n for(int i = 0; i < n; i++){\n pq.add(array[i]);\n }\n int[] out = new int[n];\n for(int i = 0; i < n; i++){\n out[i] = pq.poll();\n }\n return out;\n }\n public int[] nextSumIntArray(int n){\n int[] array=new int[n];\n array[0]=nextInt();\n for(int i=1;i[] nextGraph(int n, int m){\n ArrayList[] adj = new ArrayList[n];\n for(int i = 0; i < n; i++){\n adj[i] = new ArrayList();\n }\n for(int i = 0; i < m; i++){\n int u = nextInt(); int v = nextInt();\n u--; v--;\n adj[u].add(v); adj[v].add(u);\n }\n return adj;\n }\n public ArrayList[] nextTree(int n){\n return nextGraph(n, n-1);\n }\n \n public long[] nextLongArray(int n){\n long[] array=new long[n];\n for(int i=0;i> 1;\r\n simulateMerge(l, m, c, a, b);\r\n simulateMerge(m, r, c, a, b);\r\n int i = l;\r\n int j = m;\r\n int k = l;\r\n while (i < m && j < r) {\r\n if (index == c.length) {\r\n return false;\r\n }\r\n if (c[index] == '0') {\r\n b[k] = a[i];\r\n i++;\r\n } else {\r\n b[k] = a[j];\r\n j++;\r\n }\r\n index++;\r\n k++;\r\n }\r\n\r\n while (i < m) {\r\n b[k] = a[i];\r\n i++;\r\n k++;\r\n }\r\n while (j < r) {\r\n b[k] = a[j];\r\n j++;\r\n k++;\r\n }\r\n for (int x = l; x < r; x++) {\r\n a[x] = b[x];\r\n }\r\n return true;\r\n }\r\n\r\n public static void main(String[] args) throws IOException {\r\n new E().run();\r\n }\r\n\r\n void run() throws IOException {\r\n reader = new BufferedReader(new InputStreamReader(System.in));\r\n//\t\treader = new BufferedReader(new FileReader(\"input.txt\"));\r\n tokenizer = null;\r\n out = new PrintWriter(new OutputStreamWriter(System.out));\r\n//\t\tout = new PrintWriter(new FileWriter(\"output.txt\"));\r\n solve();\r\n reader.close();\r\n out.flush();\r\n\r\n }\r\n\r\n BufferedReader reader;\r\n StringTokenizer tokenizer;\r\n PrintWriter out;\r\n\r\n int nextInt() throws IOException {\r\n return Integer.parseInt(nextToken());\r\n }\r\n\r\n long nextLong() throws IOException {\r\n return Long.parseLong(nextToken());\r\n }\r\n\r\n double nextDouble() throws IOException {\r\n return Double.parseDouble(nextToken());\r\n }\r\n\r\n int[] nextIntArray(int n) throws IOException {\r\n int[] result = new int[n];\r\n for (int i = 0; i < n; i++) {\r\n result[i] = nextInt();\r\n }\r\n return result;\r\n }\r\n\r\n long[] nextLongArray(int n) throws IOException {\r\n long[] result = new long[n];\r\n for (int i = 0; i < n; i++) {\r\n result[i] = nextLong();\r\n }\r\n return result;\r\n }\r\n\r\n double[] nextDoubleArray(int n) throws IOException {\r\n double[] result = new double[n];\r\n for (int i = 0; i < n; i++) {\r\n result[i] = nextDouble();\r\n }\r\n return result;\r\n }\r\n\r\n int[][] nextIntArray(int n, int m) throws IOException {\r\n int[][] result = new int[n][m];\r\n for (int i = 0; i < n; i++) {\r\n for (int j = 0; j < m; j++) {\r\n result[i][j] = nextInt();\r\n }\r\n }\r\n return result;\r\n }\r\n\r\n long[][] nextLongArray(int n, int m) throws IOException {\r\n long[][] result = new long[n][m];\r\n for (int i = 0; i < n; i++) {\r\n for (int j = 0; j < m; j++) {\r\n result[i][j] = nextLong();\r\n }\r\n }\r\n return result;\r\n }\r\n\r\n double[][] nextDoubleArray(int n, int m) throws IOException {\r\n double[][] result = new double[n][m];\r\n for (int i = 0; i < n; i++) {\r\n for (int j = 0; j < m; j++) {\r\n result[i][j] = nextDouble();\r\n }\r\n }\r\n return result;\r\n }\r\n\r\n String nextToken() throws IOException {\r\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\r\n tokenizer = new StringTokenizer(reader.readLine());\r\n }\r\n return tokenizer.nextToken();\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "435edfb37b5c46ce90ec0c8055bb62d4", "src_uid": "b2ee84d23d73947fa84faaaebfde85c8", "difficulty": -1.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.math.*;\nimport java.io.*;\n\n// I hate this problem\npublic class CF1062F {\n\tclass Graph {\n\t\tint n, cntfwd[], cntrev[], adj[][], rev[][];\n\t\tpublic Graph(int nn, int[][] edge) {\n\t\t\tn = nn;\n\t\t\tadj = new int[n][];\n\t\t\trev = new int[n][];\n\t\t\tcntfwd = new int[n];\n\t\t\tcntrev = new int[n];\n\t\t\tfor(int i = 0 ; i < edge[0].length ; i++) {\n\t\t\t\tcntfwd[edge[0][i]]++;\n\t\t\t\tcntrev[edge[1][i]]++;\n\t\t\t}\n\t\t\tfor(int i = 0 ; i < n ; i++) {\n\t\t\t\tadj[i] = new int[cntfwd[i]];\n\t\t\t\trev[i] = new int[cntrev[i]];\n\t\t\t}\n\t\t\tfor(int i = 0 ; i < edge[0].length ; i++)\n\t\t\t\tadd(edge[0][i], edge[1][i]);\n\t\t}\n\t\tvoid add(int u, int v) {\n\t\t\tadj[u][--cntfwd[u]] = v;\n\t\t\trev[v][--cntrev[v]] = u;\n\t\t}\n\t\tint solve() {\n\n\t\t\tint res = 0;\n\n\t\t\t/*\n\n\t\t\tAll important nodes must lie on the longest path.\n\n\t\t\tLet u be an important node.\n\t\t\tLet path P = p[1] -> p[2] -> p[3] -> ... -> p[k]\n\t\t\tAssume P is the longest path and u is not on P.\n\t\t\tOne of three cases will happen with u and P:\n\n\t\t\t\t1. u has a path to all p[i]. Because of this, the path Q can be constructed.\n\t\t\t\t Q = u -> p[1] -> p[2] -> p[3] -> ... -> p[k].\n\t\t\t\t Q is a longer path than P.\n\n\t\t\t\t2. All p[i] has a path to u. Because of this, the path Q can be constructed.\n\t\t\t\t Q = p[1] -> p[2] -> p[3] -> ... -> p[k] -> u.\n\t\t\t\t Q is a longer path than P.\n\n\t\t\t\t3. There is some p[i] that u does not have a path to and p[i + 1] that u has a path to. \n\t\t\t\t P can be partitioned into two pieces, p[1, i] and p[i + 1, k]. The path Q can be\n\t\t\t\t constructed from these partitions, where u can be placed between them.\n\t\t\t\t Q = p[1] -> p[2] -> p[3] -> ... -> p[i] -> u -> p[i + 1] -> ... -> p[k]\n\t\t\t\t Q is a longer path than P.\n\n\t\t\tP is not the longest path in all cases. If there is a path that does not contain an important node,\n\t\t\ta longer path can always be constructed using the important node.\n\n\t\t\tTherefore, all important nodes must lie on the longest path.\n\n\t\t\t */\n\t\t\tdp = new int[n];\n\t\t\tpath = new int[n];\n\t\t\tArrays.fill(dp, -1);\n\t\t\tArrays.fill(path, -1);\n\t\t\tfor(int i = 0 ; i < n ; i++)\n\t\t\t\tgo(i);\n\t\t\tint maxpath = 0;\n\t\t\tint maxpathnode = -1;\n\t\t\tfor(int i = 0 ; i < n ; i++) {\n\t\t\t\tif(dp[i] > maxpath) {\n\t\t\t\t\tmaxpath = dp[i];\n\t\t\t\t\tmaxpathnode = i;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tint[] p = new int[dp[maxpathnode] + 1];\n\t\t\t{\n\t\t\t\tint ind = 0;\n\t\t\t\tint u = maxpathnode;\n\t\t\t\twhile(u != -1) {\n\t\t\t\t\tp[ind++] = u;\n\t\t\t\t\tu = path[u];\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t/*\n\n\t\t\tTo count all important nodes, we need to find the in[u] and out[u] for all nodes\n\t\t\talong P. in[u] will be the number of nodes that have a path to u, and out[u] will\n\t\t\tbe the number of nodes u has a path to.\n\n\t\t\tfor each i in P[1 : k]:\n\t\t\t\tLet u = p[i].\n\n\t\t\t\tBFS from u using the reverse edges of the graph, all nodes that u can reach using\n\t\t\t\tthe reverse edges means that all those nodes can reach u using the normal edges.\n\t\t\t\tOnly visit each node once, and keep count of the reachable nodes. Don't visit\n\t\t\t\tnodes on P.\n\n\t\t\t\tin[u] += reachableNodes.\n\n\t\t\t\tAfter that, add in the nodes from in[p[i - 1]] if u is not the first node in the path.\n\t\t\t\tAdd an extra 1 to include the previous node as it reaches u.\n\n\t\t\t\tif i > 0: in[u] += in[p[i - 1]] + 1\n\n\t\t\tfor each i in P[k : 1]:\n\t\t\t\tLet u = p[i].\n\n\t\t\t\tBFS from u using the normal edges of the graph. Only visit each node once, and keep\n\t\t\t\tcount of the reachable nodes. Don't visit nodes on P.\n\n\t\t\t\tout[u] += reachableNodes.\n\n\t\t\t\tAfter that, add in the nodes of out[p[i + 1]] if u is not the last node in the path.\n\t\t\t\tAdd an extra 1 to include the next node as reachable.\n\n\t\t\t\tif i < len(p): out[u] += out[p[i + 1]] + 1\n\n\t\t\tfor each i in P[1 : k]\n\t\t\t\tLet u = p[i].\n\n\t\t\t\tIf in[u] + out[u] is equal to n - 1, then u is an important node.\n\t\t\t\tIf in[u] + out[u] is equal to n - 2, then u is a semi-important node.\n\n\t\t\t */\n\n\t\t\tint[] in = new int[n];\n\t\t\tint[] out = new int[n];\n\n\t\t\tDeque q = new ArrayDeque<>();\n\t\t\tboolean[] visited = new boolean[n];\n\t\t\tfor(int i = 0 ; i < p.length ; i++)\n\t\t\t\tvisited[p[i]] = true;\n\t\t\tfor(int i = 0 ; i < p.length ; i++) {\n\t\t\t\tint reachableNodes = 0;\n\t\t\t\tq.add(p[i]);\n\t\t\t\twhile(!q.isEmpty()) {\n\t\t\t\t\tint u = q.pop();\n\t\t\t\t\tfor(int v : rev[u]) {\n\t\t\t\t\t\tif(!visited[v]) {\n\t\t\t\t\t\t\tvisited[v] = true;\n\t\t\t\t\t\t\tq.add(v);\n\t\t\t\t\t\t\treachableNodes++;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tin[p[i]] += reachableNodes;\n\t\t\t\tif(i > 0) in[p[i]] += in[p[i - 1]] + 1;\n\t\t\t}\n\t\t\tArrays.fill(visited, false);\n\t\t\tfor(int i = 0 ; i < p.length ; i++)\n\t\t\t\tvisited[p[i]] = true;\n\t\t\tfor(int i = p.length - 1 ; i >= 0 ; i--) {\n\t\t\t\tint reachableNodes = 0;\n\t\t\t\tq.add(p[i]);\n\t\t\t\twhile(!q.isEmpty()) {\n\t\t\t\t\tint u = q.pop();\n\t\t\t\t\tfor(int v : adj[u]) {\n\t\t\t\t\t\tif(!visited[v]) {\n\t\t\t\t\t\t\tvisited[v] = true;\n\t\t\t\t\t\t\tq.add(v);\n\t\t\t\t\t\t\treachableNodes++;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tout[p[i]] += reachableNodes;\n\t\t\t\tif(i < p.length - 1) out[p[i]] += out[p[i + 1]] + 1;\n\t\t\t}\n\n\t\t\tfor(int i = 0 ; i < p.length ; i++)\n\t\t\t\tif(in[p[i]] + out[p[i]] >= n - 2)\n\t\t\t\t\tres++;\n\n\t\t\t/*\n\n\t\t\tAll nodes along P are done, now the rest of the nodes must be dealt with.\n\n\t\t\tFor all nodes u that are not in P, we need to determine whether they\n\t\t\tare semi-important or not. We will need to find candidates that might\n\t\t\tpossibly be semi-important\n\t\t\tLet L[u] = p[i] = rightmost node from the left that can reach u\n\t\t\tLet R[u] = p[j] = leftmost node from the right that u can reach\n\n\t\t\tIf for any u, j - i - 1 > 1, then u is not semi-important.\n\t\t\tSide-note* if j - i - 1 is 0, then u is on the longest path, so for u\n\t\t\t to be semi-important, j - i - 1 must only be 1\n\n\t\t\tp[i] -> j - i - 1 nodes -> p[j]\n\t\t\t | ^\n\t\t\t |-----------> u -----------|\n\n\t\t\t All the nodes on p that are between p[i] and p[j] are not reachable from u,\n\t\t\t and u cannot reach any of them, so if there is more than 1 node along that path,\n\t\t\t u cannot be semi-important.\n\n\t\t\t If u does not fail this, add it to the candidates list.\n\n\n\t\t\t If there are 2 candidate nodes, u and v, where L[v] = L[u]\n\t\t\t (which also means R[v] = R[u]), then both u and v cannot be\n\t\t\t candidates. Here are the cases:\n\n\t\t\t Let d be the node in between p[i] and p[j].\n\n\t\t\t p[i] -> d -> p[j]\n\t\t\t | | ^ ^\n\t\t\t | |---> u ----| |\n\t\t\t | |\n\t\t\t |-----> v ------|\n\n\t\t\t In this case, d cannot be reached by u and u cannot be reached by d. This same\n\t\t\t statement can be applied to v if d is replaced by v. Meaning there are at least\n\t\t\t 2 nodes that are both unreachable and do not reach u. Same goes for v.\n\t\t\t u and v can be removed from the candidates list.\n\n\t\t\t p[i] -> d -> p[j]\n\t\t\t | ^\n\t\t\t |-> v --> u -|\n\n\t\t\t p[i] -> d -> p[j]\n\t\t\t | ^\n\t\t\t |-> u --> v -|\n\n\t\t\t In these cases, u and v combined with P create a longer path than the already\n\t\t\t established longest path, so these cases are impossible.\n\n\t\t\t */\n\n\t\t\tint[] L = new int[n];\n\t\t\tint[] R = new int[n];\n\t\t\tArrays.fill(L, -1);\n\t\t\tArrays.fill(R, -1);\n\t\t\tArrays.fill(visited, false);\n\t\t\tfor(int i = 0 ; i < p.length ; i++)\n\t\t\t\tvisited[p[i]] = true;\n\t\t\tfor(int i = p.length - 1 ; i >= 0 ; i--) {\n\t\t\t\tq.add(p[i]);\n\t\t\t\twhile(!q.isEmpty()) {\n\t\t\t\t\tint u = q.pop();\n\t\t\t\t\tfor(int v : adj[u]) {\n\t\t\t\t\t\tif(!visited[v]) {\n\t\t\t\t\t\t\tvisited[v] = true;\n\t\t\t\t\t\t\tL[v] = i;\n\t\t\t\t\t\t\tq.add(v);\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\tArrays.fill(visited, false);\n\t\t\tfor(int i = 0 ; i < p.length ; i++)\n\t\t\t\tvisited[p[i]] = true;\n\t\t\tfor(int i = 0 ; i < p.length ; i++) {\n\t\t\t\tq.add(p[i]);\n\t\t\t\twhile(!q.isEmpty()) {\n\t\t\t\t\tint u = q.pop();\n\t\t\t\t\tfor(int v : rev[u]) {\n\t\t\t\t\t\tif(!visited[v]) {\n\t\t\t\t\t\t\tvisited[v] = true;\n\t\t\t\t\t\t\tR[v] = i;\n\t\t\t\t\t\t\tq.add(v);\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\tint[] candidate = new int[p.length];\n\t\t\tArrays.fill(candidate, -1);\n\t\t\tboolean[] valid = new boolean[p.length];\n\t\t\tArrays.fill(valid, true);\n\t\t\tfor(int i = 0 ; i < n ; i++) {\n\t\t\t\tif(L[i] != -1 && R[i] != -1) {\n\t\t\t\t\tif(R[i] - L[i] - 1 == 1) {\n\t\t\t\t\t\tif(candidate[L[i]] != -1) {\n\t\t\t\t\t\t\tvalid[L[i]] = false;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tcandidate[L[i]] = i;\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\tList specialCases = new ArrayList<>();\n\t\t\tfor(int i = 0 ; i < n ; i++)\n\t\t\t\tif((L[i] == -1 && 0 <= R[i] && R[i] <= 1) || (L[i] > p.length - 2 && R[i] == -1))\n\t\t\t\t\tspecialCases.add(i);\n\t\t\tfor(int i = 0 ; i < p.length ; i++)\n\t\t\t\tif(valid[i] && candidate[i] == -1)\n\t\t\t\t\tvalid[i] = false;\n\t\t\t\n\t\t\t/*\n\t\t\t\n\t\t\tAll candidate nodes have some p[i] -> candidate[c] -> p[i + 2]. Because of this, the\n\t\t\tsame process can be used to calculate the in[candidate[c]] and out[candidate[c]] that\n\t\t\twas used on all nodes in P. It's just that instead of starting the BFS at some p[i], it\n\t\t\tstarts at candidate[c].\n\t\t\t\n\t\t\t*/\n\t\t\tArrays.fill(visited, false);\n\t\t\tfor(int i = 0 ; i < p.length ; i++)\n\t\t\t\tvisited[i] = true;\n\t\t\tfor(int i = 0 ; i < p.length ; i++) {\n\t\t\t\tif(valid[i]) {\n\t\t\t\t\tint reachableNodes = 0;\n\t\t\t\t\tq.add(candidate[i]);\n\t\t\t\t\tvisited[candidate[i]] = true;\n\t\t\t\t\twhile(!q.isEmpty()) {\n\t\t\t\t\t\tint u = q.pop();\n\t\t\t\t\t\tfor(int v : rev[u]) {\n\t\t\t\t\t\t\tif(!visited[v]) {\n\t\t\t\t\t\t\t\tvisited[v] = true;\n\t\t\t\t\t\t\t\tq.add(v);\n\t\t\t\t\t\t\t\treachableNodes++;\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\tvisited[candidate[i]] = false;\n\t\t\t\t\tin[candidate[i]] += reachableNodes;\n\t\t\t\t\tif(i > 0) in[candidate[i]] += in[p[i - 1]] + 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tArrays.fill(visited, false);\n\t\t\tfor(int i = 0 ; i < p.length ; i++)\n\t\t\t\tvisited[p[i]] = true;\n\t\t\tfor(int i = p.length - 1 ; i >= 0 ; i--) {\n\t\t\t\tif(valid[i]) {\n\t\t\t\t\tint reachableNodes = 0;\n\t\t\t\t\tq.add(candidate[i]);\n\t\t\t\t\tvisited[candidate[i]] = true;\n\t\t\t\t\twhile(!q.isEmpty()) {\n\t\t\t\t\t\tint u = q.pop();\n\t\t\t\t\t\tfor(int v : adj[u]) {\n\t\t\t\t\t\t\tif(!visited[v]) {\n\t\t\t\t\t\t\t\tvisited[v] = true;\n\t\t\t\t\t\t\t\tq.add(v);\n\t\t\t\t\t\t\t\treachableNodes++;\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\tvisited[candidate[i]] = false;\n\t\t\t\t\tout[candidate[i]] += reachableNodes;\n\t\t\t\t\tif(i < p.length - 1) out[candidate[i]] += out[p[i + 1]] + 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\t/*\n\t\t\t\n\t\t\tLastly, for each candidate node, if in[candidate[i]] + out[candidate[i]] is n - 2, then\n\t\t\tcandidate[i] is semi-important.\n\t\t\t\n\t\t\t*/\n\t\t\t\n\t\t\tfor(int i = 0 ; i < p.length ; i++)\n\t\t\t\tif(valid[i])\n\t\t\t\t\tif(in[candidate[i]] + out[candidate[i]] == n - 2)\n\t\t\t\t\t\tres++;\n\t\t\t\n\t\t\t/*\n\t\t\t\n\t\t\tOh, and there are gay special cases, like this:\n\t\t\t\n\t\t\tp[1] -> p[2] -> ... -> p[k]\n\t\t\t ^\n\t\t\t |\n\t\t\tcandidate[c]\n\t\t\t\n\t\t\t\n\t\t\tOh and this:\n\t\t\t\n\t\t\tp[1] -> p[2] -> ... -> p[k]\n\t\t\t ^\n\t\t\t |\n\t\t\tcandidate[c]\n\t\t\t\n\t\t\t\n\t\t\tAhh, and this one:\n\t\t\t\n\t\t\tp[1] -> ... p[k - 1] -> p[k]\n\t\t\t |\n\t\t\t v\n\t\t\t candidate[c]\n\t\t\t \n\t\t\t \n\t\t\tOH and this last one:\n\t\t\t\n\t\t\tp[1] -> ... p[k - 1] -> p[k]\n\t\t\t |\n\t\t\t v\n\t\t\t candidate[c]\n\t\t\t\n\t\t\t\n\t\t\tIf there are any candidates that point or get pointed from the same nodes,\n\t\t\tit invalidates all special cases.\n\t\t\t\n\t\t\t*/\n\t\t\tif(specialCases.size() <= 4) {\n\t\t\t\tfor(int i = 0 ; i < specialCases.size() ; i++) {\n\t\t\t\t\tfor(int j = i + 1 ; j < specialCases.size() ; j++) {\n\t\t\t\t\t\tint u = specialCases.get(i);\n\t\t\t\t\t\tint v = specialCases.get(j);\n\t\t\t\t\t\tint cmp1 = L[u] == -1 ? R[u] : L[u];\n\t\t\t\t\t\tint cmp2 = L[v] == -1 ? R[v] : L[v];\n\t\t\t\t\t\tif(cmp1 == cmp2) return 0;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor(int sc : specialCases) {\n\t\t\t\tArrays.fill(visited, false);\n\t\t\t\tvisited[sc] = true;\n\t\t\t\tq.add(sc);\n\t\t\t\tint incnt = 0, outcnt = 0;\n\t\t\t\twhile(!q.isEmpty()) {\n\t\t\t\t\tint u = q.pop();\n\t\t\t\t\tfor(int v : adj[u]) {\n\t\t\t\t\t\tif(!visited[v]) {\n\t\t\t\t\t\t\tvisited[v] = true;\n\t\t\t\t\t\t\tq.add(v);\n\t\t\t\t\t\t\toutcnt++;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tArrays.fill(visited, false);\n\t\t\t\tvisited[sc] = true;\n\t\t\t\tq.add(sc);\n\t\t\t\twhile(!q.isEmpty()) {\n\t\t\t\t\tint u = q.pop();\n\t\t\t\t\tfor(int v : rev[u]) {\n\t\t\t\t\t\tif(!visited[v]) {\n\t\t\t\t\t\t\tvisited[v] = true;\n\t\t\t\t\t\t\tq.add(v);\n\t\t\t\t\t\t\tincnt++;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(incnt + outcnt == n - 2)\n\t\t\t\t\tres++;\n\t\t\t}\n\t\t\t\n\t\t\treturn res;\n\t\t}\n\t\tint[] dp, path;\n\t\tint go(int u) {\n\t\t\tif(dp[u] != -1) return dp[u];\n\t\t\tint res = 0;\n\t\t\tfor(int v : adj[u]) {\n\t\t\t\tint tmp = go(v) + 1;\n\t\t\t\tif(tmp > res) {\n\t\t\t\t\tres = tmp;\n\t\t\t\t\tpath[u] = v;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdp[u] = res;\n\t\t\treturn res;\n\t\t}\n\t}\n\tpublic CF1062F() {\n\t\tFS scan = new FS();\n\t\tint n = scan.nextInt(), e = scan.nextInt();\n\t\tint[][] edge = new int[2][e];\n\t\tfor(int i = 0 ; i < e ; i++) {\n\t\t\tedge[0][i] = scan.nextInt() - 1;\n\t\t\tedge[1][i] = scan.nextInt() - 1;\n\t\t}\n\t\tGraph g = new Graph(n, edge);\n\t\tSystem.out.println(g.solve());\n\t}\n\tclass FS {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(\"\");\n\t\tpublic String next() {\n\t\t\twhile(!st.hasMoreTokens()) {\n\t\t\t\ttry { st = new StringTokenizer(br.readLine()); }\n\t\t\t\tcatch(Exception e) { e.printStackTrace(); }\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tpublic int nextInt() { return Integer.parseInt(next()); }\n\t}\n\tpublic static void main(String[] args) { new CF1062F(); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "81ca6ed569faf5aae9eff3133c3bcbd5", "src_uid": "be26e93ca7aef1235e96e10467a6417e", "difficulty": 2900.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class D_opt3 {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tint n;\n\tint dn1;\n\tint m;\n\n\tlong solve() {\n\t\tlong start = System.currentTimeMillis();\n\t\tdn1 = (n + 1) * 2;\n\t\tlong ans = 0;\n\t\tfor (int i = 2 * (m + 1); i <= n + 1; i += 2) {\n\t\t\tint shiftI = (i == n + 1) ? 0 : 1;\n\n\t\t\tint tmp = dn1 - i;\n\t\t\tint num = (i - (m + 1)) * tmp - 1;\n\t\t\tint denom = i + (m + 1) * 2;\n\t\t\t\n\n\t\t\t\n\t\t\tfor (int j = m + 1; j < i; j++, num -= tmp, denom += 2) {\n\n\t\t\t\tint k = num / denom;\n\t\t\t\tif (k >= n - m)\n\t\t\t\t\tk = n - m;\n\t\t\t\tif (k >= m)\n\t\t\t\t\tans += (k - m) << shiftI;\n\t\t\t}\n\t\t}\n\n//\t\tSystem.err.println(System.currentTimeMillis() - start);\n\t\treturn 3 * ans;\n\t}\n\n\tD_opt3() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tn = nextInt();\n\t\tm = nextInt();\n\t\tout.println(solve());\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew D_opt3();\n\t}\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\teof = true;\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8efe5b0ee095c3b232aada79ed788d57", "src_uid": "355cc23d7a4addfc920c6e5e72a2bb64", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class cf690B3 {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tstatic final int SHIFT = 17;\n\n\tHashSet set;\n\n\tboolean good(long v) {\n\t\tif (set.contains(v)) {\n\t\t\treturn false;\n\t\t}\n\t\tfor (int dx = -1; dx <= 1; dx++)\n\t\t\tfor (int dy = -1; dy <= 1; dy++) {\n\t\t\t\tif (dx == 0 && dy == 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tlong u = v + (dx << SHIFT) + dy;\n\t\t\t\tif (set.contains(u)) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\treturn false;\n\t}\n\t\n\tHashSet seen;\n\n\tvoid dfs(long v, HashSet cur) {\n\t\tcur.add(v);\n\t\tseen.add(v);\n\t\tfor (int dx = -1; dx <= 1; dx++)\n\t\t\tfor (int dy = -1; dy <= 1; dy++) {\n\t\t\t\tif (dx == 0 && dy == 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tlong u = v + (dx << SHIFT) + dy;\n\t\t\t\tif (!cur.contains(u) && good(u)) {\n\t\t\t\t\tdfs(u, cur);\n\t\t\t\t}\n\t\t\t}\n\t}\n\n\tboolean solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\t\tif (n == 0 && m == 0) {\n\t\t\treturn false;\n\t\t}\n\n\t\tlong[] ps = new long[m];\n\n\t\tset = new HashSet<>();\n\t\tseen = new HashSet<>();\n\n\t\tint[] xs = new int[m];\n\t\tint[] ys = new int[m];\n\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\txs[i] = nextInt();\n\t\t\tys[i] = nextInt();\n\t\t\tps[i] = ((1L * xs[i]) << SHIFT) | ys[i];\n\t\t\tset.add(ps[i]);\n\t\t}\n\n\t\tHashSet set1 = null;\n\t\t\n\t\tint setsCount = 0;\n\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tfor (int dx = -1; dx <= 1; dx++)\n\t\t\t\tfor (int dy = -1; dy <= 1; dy++) {\n\t\t\t\t\tif (dx == 0 && dy == 0) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tlong tmp = ps[i] + (dx << SHIFT) + dy;\n\t\t\t\t\tif (set.contains(tmp) || seen.contains(tmp)) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tif (++setsCount > 2) {\n\t\t\t\t\t\tthrow new AssertionError(Arrays.toString(xs) + \" \" + Arrays.toString(ys));\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tHashSet cand = new HashSet<>();\n\t\t\t\t\tdfs(tmp, cand);\n\t\t\t\t\t\n\t\t\t\t\tif (set1 == null || set1.size() < cand.size()) {\n\t\t\t\t\t\tset1 = cand;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\t\t\n\t\tList a = new ArrayList<>();\n\t\tHashSet setA = new HashSet<>();\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tfor (int dx = -1; dx <= 0; dx++)\n\t\t\t\tfor (int dy = -1; dy <= 0; dy++) {\n\t\t\t\t\tint x = xs[i] + dx;\n\t\t\t\t\tint y = ys[i] + dy;\n\t\t\t\t\tlong hash = ((1L * x) << SHIFT) | y;\n\t\t\t\t\tif (setA.contains(hash)) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tsetA.add(hash);\n\n\t\t\t\t\tboolean ok = true;\n\t\t\t\t\touter: for (int xx = 0; xx <= 1; xx++)\n\t\t\t\t\t\tfor (int yy = 0; yy <= 1; yy++) {\n\t\t\t\t\t\t\tlong hash1 = hash + (xx << SHIFT) + yy;\n\t\t\t\t\t\t\tif (set1.contains(hash1)) {\n\t\t\t\t\t\t\t\tok = false;\n\t\t\t\t\t\t\t\tbreak outer;\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 (ok) {\n\t\t\t\t\t\ta.add(new Point(x, y));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\n\t\tPoint[] arr = a.toArray(new Point[a.size()]);\n\t\tPoint[] h = convexHull(arr);\n\n\t\tfor (int i = 0, j = h.length - 1; i < j; i++, j--) {\n\t\t\tPoint tmp = h[i];\n\t\t\th[i] = h[j];\n\t\t\th[j] = tmp;\n\t\t}\n\n\t\tint start = 0;\n\t\tfor (int i = 1; i < h.length; i++) {\n\t\t\tif (h[i].x < h[start].x\n\t\t\t\t\t|| (h[i].x == h[start].x && h[i].y < h[start].y)) {\n\t\t\t\tstart = i;\n\t\t\t}\n\t\t}\n\n\t\tout.println(h.length);\n\t\tfor (int i = start; i < h.length; i++) {\n\t\t\tPoint p = h[i];\n\t\t\tout.println(p.x + \" \" + p.y);\n\t\t}\n\n\t\tfor (int i = 0; i < start; i++) {\n\t\t\tPoint p = h[i];\n\t\t\tout.println(p.x + \" \" + p.y);\n\t\t}\n\n\t\treturn true;\n\t}\n\n\tString asPoint(long q) {\n\t\treturn \"(\" + (q >> SHIFT) + \", \" + (q & ((1 << SHIFT) - 1)) + \")\";\n\t}\n\n\tstatic class Point implements Comparable {\n\t\tstatic final Point ZERO = new Point(0, 0);\n\t\tint x, y;\n\n\t\tpublic Point(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(Point o) {\n\t\t\tif (y != o.y)\n\t\t\t\treturn y < o.y ? -1 : 1;\n\t\t\tif (x != o.x)\n\t\t\t\treturn x < o.x ? -1 : 1;\n\t\t\treturn 0;\n\t\t}\n\n\t\tlong vectMul(Point p) {\n\t\t\treturn (long) x * p.y - (long) y * p.x;\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn \"(\" + x + \", \" + y + \")\";\n\t\t}\n\n\t\tpublic boolean equals(Point p) {\n\t\t\treturn x == p.x && y == p.y;\n\t\t}\n\t}\n\n\tstatic int getTurn(Point A, Point B, Point C) {\n\t\t// angle between AB and AC\n\t\tlong p1 = (long) (B.x - A.x) * (C.y - A.y);\n\t\tlong p2 = (long) (B.y - A.y) * (C.x - A.x);\n\t\tif (p1 == p2)\n\t\t\treturn 0;\n\t\telse\n\t\t\treturn p1 < p2 ? -1 : 1;\n\t}\n\n\t/**\n\t * PERMUTES POINTS IN ARRAY, consider using convexHull(a.clone()) Points\n\t * themselves are modified inside method too, but changes are reverted at\n\t * the end\n\t * \n\t * @param a\n\t * - array of points\n\t * @return convexHull of these point in CCW order, no duplicates, no three\n\t * points on one side\n\t */\n\tstatic Point[] convexHull(Point[] a) {\n\n\t\tif (a == null)\n\t\t\treturn null;\n\t\tif (a.length == 0)\n\t\t\treturn new Point[] {};\n\n\t\tint st = 0;\n\t\tfor (int i = 1; i < a.length; i++)\n\t\t\tif (a[i].compareTo(a[st]) < 0)\n\t\t\t\tst = i;\n\n\t\tPoint tmp = a[0];\n\t\ta[0] = a[st];\n\t\ta[st] = tmp;\n\n\t\tint sx = a[0].x;\n\t\tint sy = a[0].y;\n\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\ta[i].x -= sx;\n\t\t\ta[i].y -= sy;\n\t\t}\n\n\t\tArrays.sort(a, 1, a.length, new Comparator() {\n\n\t\t\t@Override\n\t\t\tpublic int compare(Point o1, Point o2) {\n\t\t\t\tif (o1.equals(o2))\n\t\t\t\t\treturn 0;\n\t\t\t\tif (o1.equals(Point.ZERO)) {\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t\tif (o2.equals(Point.ZERO)) {\n\t\t\t\t\treturn 1;\n\t\t\t\t}\n\t\t\t\tlong val = o1.vectMul(o2);\n\t\t\t\tif (val != 0)\n\t\t\t\t\treturn val > 0 ? -1 : 1;\n\t\t\t\tif (o1.y == 0) {\n\t\t\t\t\treturn o1.x < o2.x ? -1 : 1;\n\t\t\t\t} else {\n\t\t\t\t\treturn o1.y < o2.y ? -1 : 1;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tPoint[] h = new Point[a.length];\n\t\tint sz = 0;\n\t\th[sz++] = a[0];\n\t\tfor (int i = 1; i < a.length; i++) {\n\t\t\tif (a[i].equals(h[sz - 1]))\n\t\t\t\tcontinue;\n\t\t\twhile (sz > 1 && getTurn(h[sz - 2], h[sz - 1], a[i]) <= 0)\n\t\t\t\tsz--;\n\t\t\th[sz++] = a[i];\n\t\t}\n\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\ta[i].x += sx;\n\t\t\ta[i].y += sy;\n\t\t}\n\n\t\treturn Arrays.copyOf(h, sz);\n\t}\n\n\tcf690B3() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\twhile (solve())\n\t\t\t;\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew cf690B3();\n\t}\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\teof = true;\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c3539aa3bc4c02f085cbfc8e0c2f2581", "src_uid": "5e1847193148c4e6a998c61f8db61670", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class F {\n\tFastScanner in;\n\tPrintWriter out;\n\n\tvoid solve() {\n\t\tint n = in.nextInt();\n\t\tint[][] f = new int[2 * n][n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tf[0][i] = in.nextInt() - 1;\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 1; j < 2 * n; j++) {\n\t\t\t\tf[j][i] = f[0][f[j - 1][i]];\n\t\t\t}\n\t\t}\n\t\tBigInteger res = BigInteger.ONE;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int pw = 0; pw < 2 * n; pw++) {\n\t\t\t\tif (f[pw][f[pw][i]] == f[pw][i]) {\n\t\t\t\t//\tout.println(pw + 1);\n\t\t\t\t\tBigInteger g = BigInteger.valueOf(pw + 1).gcd(res);\n\t\t\t\t\tres = res.multiply(BigInteger.valueOf(pw + 1)).divide(g);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(res);\n\t}\n\n\tvoid run() {\n\t\tin = new FastScanner();\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() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(in.br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\t// TODO Auto-generated catch block\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\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew F().run();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d6fd7055c3f04997c962718741d8e304", "src_uid": "1daa784c0eb1cde514e4319da07c8d00", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.StringTokenizer;\n\npublic class Div1_411F {\n\n\tint numTV;\n\tint A;\n\tint B;\n\n\tArrayList[] tAList;\n\n\tboolean[][] tVAct;\n\tint[] numM;\n\n\tint cTime = 0;\n\tint[] disc;\n\tint[] low;\n\n\tArrayDeque stack = new ArrayDeque();\n\n\tArrayList> sCCs = new ArrayList>();\n\tint[] comp;\n\n\tint numC;\n\n\t// may contain repeats\n\tArrayList[] cAList;\n\n\tboolean[] visited;\n\tArrayList tOrder = new ArrayList();\n\n\tboolean[][] compAct;\n\n\t// represents the minimum and the maximum amounts of active members a tournament vertex can have\n\tint[] min;\n\tint[] max;\n\n\tlong MOD = 1_000_000_007;\n\n\tint[][] comb;\n\n\tvoid dfs(int cV) {\n\t\tdisc[cV] = low[cV] = cTime++;\n\t\tstack.push(cV);\n\n\t\tfor (int adj : tAList[cV]) {\n\t\t\tif (disc[adj] == -1) {\n\t\t\t\tdfs(adj);\n\t\t\t}\n\t\t\tif (low[adj] < low[cV]) {\n\t\t\t\tlow[cV] = low[adj];\n\t\t\t}\n\t\t}\n\t\tif (disc[cV] == low[cV]) {\n\t\t\tArrayList cSCC = new ArrayList();\n\t\t\tint cCInd = sCCs.size();\n\t\t\twhile (stack.peek() != cV) {\n\t\t\t\tlow[stack.peek()] = Integer.MAX_VALUE;\n\t\t\t\tcomp[stack.peek()] = cCInd;\n\t\t\t\tcSCC.add(stack.pop());\n\t\t\t}\n\t\t\tlow[stack.pop()] = Integer.MAX_VALUE;\n\t\t\tcomp[cV] = cCInd;\n\t\t\tcSCC.add(cV);\n\t\t\tsCCs.add(cSCC);\n\t\t}\n\t}\n\n\t@SuppressWarnings(\"unchecked\")\n\tvoid findSCCs() {\n\t\tdisc = new int[numTV];\n\t\tlow = new int[numTV];\n\t\tcomp = new int[numTV];\n\t\tArrays.fill(disc, -1);\n\n\t\tfor (int i = 0; i < numTV; i++) {\n\t\t\tif (disc[i] == -1) {\n\t\t\t\tdfs(i);\n\t\t\t}\n\t\t}\n\n\t\tnumC = sCCs.size();\n\n\t\tcAList = new ArrayList[numC];\n\t\tfor (int i = 0; i < numC; i++) {\n\t\t\tcAList[i] = new ArrayList();\n\t\t}\n\t\tfor (int cV = 0; cV < numTV; cV++) {\n\t\t\tfor (int adj : tAList[cV]) {\n\t\t\t\tcAList[comp[cV]].add(comp[adj]);\n\t\t\t}\n\t\t}\n\t}\n\n\tint fGCD(int a, int b) {\n\t\twhile (b != 0) {\n\t\t\tint t = b;\n\t\t\tb = a % b;\n\t\t\ta = t;\n\t\t}\n\t\treturn a;\n\t}\n\n\tvoid condenseComps() {\n\t\tcompAct = new boolean[numC][];\n\t\tfor (int cComp = 0; cComp < numC; cComp++) {\n\t\t\tArrayList cMems = sCCs.get(cComp);\n\t\t\tint cGCD = numM[cMems.get(0)];\n\t\t\tfor (int j : cMems) {\n\t\t\t\tcGCD = fGCD(cGCD, numM[j]);\n\t\t\t}\n\t\t\tboolean[] cCompSet = compAct[cComp] = new boolean[cGCD];\n\t\t\tfor (int cM : cMems) {\n\t\t\t\tfor (int sM = 0; sM < numM[cM]; sM++) {\n\t\t\t\t\tif (tVAct[cM][sM]) {\n\t\t\t\t\t\tcCompSet[sM % cGCD] = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// topologically order the transitive tournament graph\n\tvoid tOrder(int cV) {\n\t\tvisited[cV] = true;\n\t\tfor (int adj : cAList[cV]) {\n\t\t\tif (!visited[adj]) {\n\t\t\t\ttOrder(adj);\n\t\t\t}\n\t\t}\n\t\ttOrder.add(cV);\n\t}\n\n\tvoid orderComps() {\n\t\tvisited = new boolean[numC];\n\t\tfor (int i = 0; i < numC; i++) {\n\t\t\tif (!visited[i]) {\n\t\t\t\ttOrder(i);\n\t\t\t}\n\t\t}\n\t\tCollections.reverse(tOrder);\n\t}\n\n\tvoid pushConnections() {\n\t\tboolean[] cSet = compAct[tOrder.get(0)];\n\n\t\tfor (int cInd = 1; cInd < numC; cInd++) {\n\t\t\tboolean[] pSet = cSet;\n\t\t\tint cComp = tOrder.get(cInd);\n\t\t\tcSet = compAct[cComp];\n\t\t\tint gcd = fGCD(pSet.length, cSet.length);\n\n\t\t\tboolean[] resSet = new boolean[gcd];\n\n\t\t\tfor (int i = 0; i < pSet.length; i++) {\n\t\t\t\tif (pSet[i]) {\n\t\t\t\t\tresSet[i % gcd] = true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (int cRes = 0; cRes < gcd; cRes++) {\n\t\t\t\tfor (int cNum = cRes; cNum < cSet.length; cNum += gcd) {\n\t\t\t\t\tcSet[cNum] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tvoid findMaxs() {\n\t\tmax = new int[numTV];\n\n\t\tfor (int cComp = 0; cComp < numC; cComp++) {\n\t\t\tint aCnt = 0;\n\t\t\tfor (boolean b : compAct[cComp]) {\n\t\t\t\tif (b) {\n\t\t\t\t\taCnt++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int cM : sCCs.get(cComp)) {\n\t\t\t\tmax[cM] = numM[cM] / compAct[cComp].length * aCnt;\n\t\t\t}\n\t\t}\n\t}\n\n\t// uses Pascal's identity\n\tvoid preComb() {\n\t\tcomb = new int[numTV + 1][numTV + 1];\n\t\tfor (int i = 0; i <= numTV; i++) {\n\t\t\tcomb[i][0] = 1;\n\t\t\tfor (int j = 1; j <= i; j++) {\n\t\t\t\tcomb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];\n\t\t\t\tif (comb[i][j] >= 1_000_000_007) {\n\t\t\t\t\tcomb[i][j] -= 1_000_000_007;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tlong findAns() {\n\t\tlong ans = 0;\n\n\t\tfor (int sLws = 0; sLws < numTV; sLws++) {\n\t\t\tint sGrt = 0;\n\t\t\tint pGrt = 0;\n\t\t\tfor (int oth = 0; oth < numTV; oth++) {\n\t\t\t\tif (oth != sLws) {\n\t\t\t\t\tif (min[oth] > max[sLws]) {\n\t\t\t\t\t\tif (++sGrt >= A) {\n\t\t\t\t\t\t\tcontinue;\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// secondary condition in case of equality to prevent overcounting\n\t\t\t\t\telse if (max[oth] > max[sLws] || (max[oth] == max[sLws] && sLws < oth)) {\n\t\t\t\t\t\tpGrt++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tfor (int numT = 0; numT < B && numT <= pGrt && numT + sGrt < A; numT++) {\n\t\t\t\tans = (ans + ((long) comb[pGrt][numT]) * comb[sGrt][B - 1 - numT]) % MOD;\n\t\t\t}\n\t\t}\n\n\t\treturn ans;\n\t}\n\n\t@SuppressWarnings(\"unchecked\")\n\tvoid execute() throws IOException {\n\t\tBufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n\n\t\tStringTokenizer inputData = new StringTokenizer(reader.readLine());\n\t\tnumTV = Integer.parseInt(inputData.nextToken());\n\t\tA = Integer.parseInt(inputData.nextToken());\n\t\tB = Integer.parseInt(inputData.nextToken());\n\n\t\ttAList = new ArrayList[numTV];\n\n\t\tfor (int i = 0; i < numTV; i++) {\n\t\t\ttAList[i] = new ArrayList();\n\t\t\tString nLine = reader.readLine();\n\t\t\tfor (int j = 0; j < numTV; j++) {\n\t\t\t\tif (nLine.charAt(j) == '1') {\n\t\t\t\t\ttAList[i].add(j);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\ttVAct = new boolean[numTV][];\n\t\tnumM = new int[numTV];\n\t\tmin = new int[numTV];\n\n\t\tfor (int i = 0; i < numTV; i++) {\n\t\t\tinputData = new StringTokenizer(reader.readLine());\n\t\t\tint cNumM = numM[i] = Integer.parseInt(inputData.nextToken());\n\t\t\ttVAct[i] = new boolean[cNumM];\n\n\t\t\tString nLine = inputData.nextToken();\n\t\t\tfor (int j = 0; j < cNumM; j++) {\n\t\t\t\ttVAct[i][j] = nLine.charAt(j) == '1';\n\t\t\t\tif (tVAct[i][j]) {\n\t\t\t\t\tmin[i]++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treader.close();\n\n\t\tfindSCCs();\n\t\tcondenseComps();\n\t\torderComps();\n\t\tpushConnections();\n\t\tfindMaxs();\n\t\tpreComb();\n\n\t\tlong ans = findAns();\n\t\tSystem.out.println(ans);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Div1_411F().execute();\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a0712f33d897e56b9b23979c899188a8", "src_uid": "1fd82cca7cc7520f6091c6c9898debf8", "difficulty": 3400.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.PrintStream;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Coupon Kaka\n */\n/*\n \"Digits 1-9 in unit place is a myth, actual counting always has digit 0 in the unit place.\" - Coupon Kaka\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 FCoffeeVarietiesEasyVersion solver = new FCoffeeVarietiesEasyVersion();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class FCoffeeVarietiesEasyVersion {\n boolean isNew(int ind, InputReader sc) {\n System.out.println(\"? \" + (ind + 1));\n System.out.flush();\n char ans = sc.next().charAt(0);\n if (ans == 'Y')\n return false;\n return true;\n }\n\n void reset() {\n System.out.println(\"R\");\n System.out.flush();\n }\n\n public void solve(int testNumber, InputReader sc, PrintWriter out) {\n int n = sc.nextInt();\n int k = sc.nextInt();\n\n int flag[] = new int[n];\n ArrayList list = new ArrayList<>();\n for (int i = 0; i < k; ++i) {\n if (isNew(i, sc)) {\n flag[i] = 0;\n list.add(i);\n } else\n flag[i] = 1;\n }\n\n for (int i = k; i < n; i += (k + 1) / 2) {\n int l = i;\n int r = min(n - 1, i + ((k + 1) / 2) - 1);\n\n for (int j = 0; j < list.size(); j += (k + 1) / 2) {\n reset();\n for (int p = j; p < min(list.size(), j + ((k + 1) / 2)); ++p)\n isNew(list.get(p), sc);\n for (int p = l; p <= r; ++p) {\n if (!isNew(p, sc))\n flag[p] = 1;\n }\n }\n\n for (int j = l; j <= r; ++j) {\n if (flag[j] == 0)\n list.add(j);\n }\n }\n\n System.out.println(\"! \" + list.size());\n System.out.flush();\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\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\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 }\n while (!isSpaceChar(c));\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 }\n}\n\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "af4edf828e098f7164dc6aff2338bfe8", "src_uid": "11ad68b4375456733526e74e72606d8d", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Set;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.TreeSet;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.AbstractCollection;\nimport java.util.TreeMap;\nimport java.util.StringTokenizer;\nimport java.util.Map;\nimport java.io.BufferedReader;\nimport java.util.Collections;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastScanner in = new FastScanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskC {\n final double eps = 1e-8;\n\n public void solve(int testNumber, FastScanner in, PrintWriter out) {\n int n = in.nextInt();\n Circle[] circles = new Circle[n];\n for (int i = 0; i < n; i++) {\n int x = in.nextInt();\n int y = in.nextInt();\n int r = in.nextInt();\n circles[i] = new Circle();\n circles[i].o = new Point(x, y);\n circles[i].r = r;\n }\n\n Set all = new TreeSet<>();\n for (int i = 0; i < n; i++) {\n for (int j = i + 1; j < n; j++) {\n List inter = intersect(circles[i], circles[j]);\n if (inter == null) {\n continue;\n }\n all.addAll(inter);\n }\n }\n\n Map pointId = new TreeMap<>();\n List> adj = new ArrayList<>();\n for (int i = 0; i < n; i++) {\n List angles = new ArrayList<>();\n final int K = 100;\n for (int j = 0; j < K; j++) {\n angles.add(Math.PI * 2 * j / K);\n }\n for (Point p : all) {\n if (circles[i].contains(p)) {\n double dx = p.x - circles[i].o.x;\n double dy = p.y - circles[i].o.y;\n double alpha = Math.atan2(dy, dx);\n if (alpha < 0) {\n alpha += 2 * Math.PI;\n }\n angles.add(alpha);\n }\n }\n Collections.sort(angles);\n Point dir = new Point(1, 0).scale(circles[i].r);\n Double[] as = new TreeSet<>(angles).toArray(new Double[0]);\n for (int j = 0; j < as.length; j++) {\n Point p = circles[i].o.add(dir.rotate(as[j]));\n getId(p, pointId, adj);\n }\n for (int j = 0; j < as.length; j++) {\n Point p = circles[i].o.add(dir.rotate(as[j]));\n Point q = circles[i].o.add(dir.rotate(as[(j + 1) % as.length]));\n int u = pointId.get(p);\n int v = pointId.get(q);\n if (u == v) {\n continue;\n }\n adj.get(u).add(v);\n adj.get(v).add(u);\n }\n }\n\n int v = adj.size();\n int e = 0;\n for (int i = 0; i < v; i++) {\n e += adj.get(i).size();\n }\n e /= 2;\n\n int comps = 0;\n boolean[] was = new boolean[v];\n for (int i = 0; i < v; i++) {\n if (!was[i]) {\n ++comps;\n dfs(i, was, adj);\n }\n }\n\n out.println(1 + comps + e - v);\n }\n\n private void dfs(int i, boolean[] was, List> adj) {\n was[i] = true;\n for (int j : adj.get(i)) {\n if (!was[j]) {\n dfs(j, was, adj);\n }\n }\n }\n\n private void getId(Point p, Map pointId, List> adj) {\n if (!pointId.containsKey(p)) {\n int sz = pointId.size();\n pointId.put(p, sz);\n adj.add(new TreeSet<>());\n }\n }\n\n private List intersect(Circle c1, Circle c2) {\n double dx = c1.o.x - c2.o.x;\n double dy = c1.o.y - c2.o.y;\n double d = Math.sqrt(dx * dx + dy * dy);\n double cos = (c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d);\n if (cos < -1 - eps) {\n return null;\n }\n if (cos < -1) {\n cos = -1;\n }\n if (cos > 1 + eps) {\n return null;\n }\n if (cos > 1) {\n cos = 1;\n }\n List res = new ArrayList<>();\n double alpha = Math.acos(cos);\n Point dir = c2.o.sub(c1.o).norm();\n res.add(c1.o.add(dir.scale(c1.r).rotate(+alpha)));\n res.add(c1.o.add(dir.scale(c1.r).rotate(-alpha)));\n return res;\n }\n\n class Point implements Comparable {\n double x;\n double y;\n\n Point(double x, double y) {\n this.x = x;\n this.y = y;\n }\n\n Point add(Point o) {\n return new Point(x + o.x, y + o.y);\n }\n\n Point sub(Point o) {\n return new Point(x - o.x, y - o.y);\n }\n\n Point rotate(double alpha) {\n double c = Math.cos(alpha);\n double s = Math.sin(alpha);\n double nx = x * c - y * s;\n double ny = x * s + y * c;\n return new Point(nx, ny);\n }\n\n Point norm() {\n double len = length();\n return scale(1.0 / len);\n }\n\n Point scale(double f) {\n return new Point(f * x, f * y);\n }\n\n double length() {\n return Math.sqrt(x * x + y * y);\n }\n\n public String toString() {\n return String.format(\"%.6f %.6f\", x, y);\n }\n\n public boolean equals(Object obj) {\n Point o = (Point) obj;\n return Math.abs(x - o.x) < eps && Math.abs(y - o.y) < eps;\n }\n\n public int compareTo(Point o) {\n if (Math.abs(x - o.x) > eps) {\n return x < o.x ? -1 : 1;\n }\n if (Math.abs(y - o.y) > eps) {\n return y < o.y ? -1 : 1;\n }\n return 0;\n }\n\n }\n\n class Circle {\n Point o;\n double r;\n\n boolean contains(Point p) {\n double dist = p.sub(o).length();\n return Math.abs(dist - r) < eps;\n }\n\n }\n\n }\n\n static class FastScanner {\n private BufferedReader in;\n private StringTokenizer st;\n\n public FastScanner(InputStream stream) {\n in = new BufferedReader(new InputStreamReader(stream));\n }\n\n public String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(in.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return st.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4129839b679ee6e1077a84b8937dd5da", "src_uid": "bda5879e94a82c6fd499796f258c4691", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\nimport java.util.StringTokenizer;\r\n\r\npublic class bubblestrike {\r\n public static void main(String[] args) throws IOException {\r\n BufferedReader f = new BufferedReader(new InputStreamReader(System.in));\r\n StringTokenizer st = new StringTokenizer(f.readLine());\r\n int x = Integer.parseInt(st.nextToken());\r\n double prob = Double.parseDouble(st.nextToken());\r\n int pos = x;\r\n for(int a = x; a>=1; a/=2){\r\n while (check(pos-a,x-(pos-a),prob)){\r\n pos-=a;\r\n }\r\n }\r\n System.out.println(pos);\r\n\r\n }\r\n public static boolean check (int good, int bad, double proba){\r\n double g=good+0.0;\r\n double b=bad+0.0;\r\n double ans = (0.25*b*(b-1.0)+(g*(g-1)*(g-2)/6.0)+b*0.5*(g)*(g-1))/((g+b)*(g+b-1)*(g+b-2)/6.0);\r\n \r\n return ans >=proba;\r\n }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "73cd56865b084c69670dab5bd72c8689", "src_uid": "788ed59a964264bd0e755e155a37e14d", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "//package globalround1;\nimport java.util.*;\n\n\npublic class ProblemH {\n public static void main(String[] args) {\n new ProblemH().solve();\n }\n\n int N = 1111, M=20111;\n Scanner in = new Scanner(System.in);\n char[] l = new char[N];\n char[] r = new char[N];\n int n, nl, nr, rt, tot, fr, rr;\n int[][] go = new int[M][10];\n int[][] wild = new int[M][811];\n int[] q = new int[M];\n int[] fail = new int[M];\n int[][] dp = new int[2111][M];\n\n void solve() {\n String tl = in.next();\n String tr = in.next();\n n = in.nextInt();\n nl = tl.length();\n nr = tr.length();\n for(int i = 0 ; i < nl ; i++){\n l[i] = tl.charAt(i);\n }\n for(int i = 0 ; i < nr ; i++){\n r[i] = tr.charAt(i);\n }\n rt = ++tot;\n insert(l);\n insert(r);\n if(nl == nr){\n int k1 = rt, k2 = rt;\n for(int i = 0 ; i < nl ; i++){\n if(k1 == k2 && l[i] !=r[i]){\n for(int c = l[i]+1 ; c < r[i] ; c++){\n if(go[k1][c-'0'] == 0){\n go[k1][c-'0'] = ++tot;\n }\n wild[go[k1][c-'0']][nl-i-1]++;\n }\n }\n else if(k1 != k2){\n for(int c = l[i]+1 ; c < '0'+10 ; c++){\n if(go[k1][c-'0'] == 0){\n go[k1][c-'0'] = ++tot;\n }\n wild[go[k1][c-'0']][nl-i-1]++;\n }\n for(int c = '0'+ (i == 0 ? 1 : 0) ; c < r[i] ; c++){\n if(go[k2][c-'0'] == 0){\n go[k2][c-'0'] = ++tot;\n }\n wild[go[k2][c-'0']][nl-i-1]++;\n }\n }\n k1 = go[k1][l[i]-'0'];\n k2 = go[k2][r[i]-'0'];\n }\n wild[k1][0]++;\n if(k1 != k2){\n wild[k2][0]++;\n }\n }\n else{\n int k1 = rt,k2 = rt;\n for(int i = 0 ; i < nl ; i++){\n for(int c = l[i]+1 ; c < '0'+10 ; c++){\n if(go[k1][c-'0'] == 0){\n go[k1][c-'0'] = ++tot;\n }\n wild[go[k1][c-'0']][nl-i-1]++;\n }\n k1 = go[k1][l[i]-'0'];\n }\n for(int i = 0 ; i < nr ; i++){\n for(int c = '0'+ (i == 0 ? 1 : 0) ; c < r[i] ; c++){\n if(go[k2][c-'0'] == 0){\n go[k2][c-'0'] = ++tot;\n }\n wild[go[k2][c-'0']][nr-i-1]++;\n }\n k2 = go[k2][r[i]-'0'];\n }\n wild[k1][0]++;\n wild[k2][0]++;\n for(int i = 1 ; i < 10 ; i++){\n if(go[rt][i] == 0){\n go[rt][i] = ++tot;\n }\n for(int j = nl+1 ; j < nr ; j++){\n wild[go[rt][i]][j-1]++;\n }\n }\n }\n construct();\n for(int i = 1 ; i < rr ; i++){\n int x = q[i];\n for(int j = 0 ; j < nr ; j++){\n wild[x][j] += wild[fail[x]][j];\n }\n }\n for(int i = 1 ; i <= tot ; i++){\n for(int j = 1 ; j < nr ; j++){\n wild[i][j] += wild[i][j-1];\n }\n }\n DP();\n in.close();\n }\n\n void insert(char s[]){\n int cur = rt;\n for(int i = 0 ; s[i] != 0 ; i++){\n if(go[cur][s[i]-'0'] == 0){\n go[cur][s[i]-'0'] = ++tot;\n }\n cur = go[cur][s[i]-'0'];\n }\n }\n\n void construct(){\n fr = rr = 0;\n q[rr++] = rt;\n for(; fr < rr ; fr++){\n int x = q[fr];\n for(int i = 0 ; i < 10 ; i++){\n if(go[x][i] != 0){\n if(x == rt){\n fail[go[x][i]] = x;\n }\n else{\n fail[go[x][i]] = fail[x];\n while(fail[go[x][i]] != rt && go[fail[go[x][i]]][i] == 0){\n fail[go[x][i]] = fail[fail[go[x][i]]];\n }\n if(go[fail[go[x][i]]][i] != 0){\n fail[go[x][i]] = go[fail[go[x][i]]][i];\n }\n }\n q[rr++] = go[x][i];\n }\n }\n }\n for(int i = 0 ; i < 10 ; i++){\n if(go[rt][i] == 0){\n go[rt][i] = rt;\n }\n } \n for(int j = 1 ; j < rr ; j++){\n int x = q[j];\n for(int i = 0 ; i < 10 ; i++){\n if(go[x][i] == 0){\n go[x][i] = go[fail[x]][i];\n }\n }\n }\n }\n \n void DP(){\n for(int i = 1 ; i <= tot ; i++){\n dp[0][i] = wild[i][0];\n }\n for(int i = 1 ; i <= n ; i++){\n for(int j = 1 ; j <= tot ; j++){\n for(int k = 0 ; k < 10 ; k++){\n dp[i][j] = Math.max(dp[i][j], dp[i-1][go[j][k]]);\n }\n dp[i][j] += wild[j][Math.min(i, nr-1)];\n }\n }\n System.out.println(dp[n][rt]);\n int cur = rt;\n for(int i = n ; i >= 1 ; i--){\n int val = dp[i][cur]-wild[cur][Math.min(i, nr-1)];\n for(int next = 0 ; next < 10 ; next++){\n if(dp[i-1][go[cur][next]]==val){\n System.out.print(next);\n cur = go[cur][next];\n break;\n }\n }\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0750c680313985034e3a73d541ccb35e", "src_uid": "2e79c95bf4c2b7de8a4741b24a880829", "difficulty": 3500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.awt.Point;\n\npublic class CF_1204E {\n public static void main(String args[]) throws Exception {\n BufferedScanner in = new BufferedScanner(System.in);\n BufferedPrinter out = new BufferedPrinter(System.out);\n\n long MOD = 998244853;\n int n = in.nextInt(), m = in.nextInt();\n\n long[][] dp = new long[n + 1][m + 1];\n for (int i = 1; i <= n; i++) {\n dp[i][0] = i % MOD;\n }\n\n long[][] zs = new long[n + 1][m + 1];\n for (int i = 0; i <= m; i++) zs[0][i] = 1;\n\n for (int i = 1; i <= n; i++) {\n for (int j = 1; j <= i && j <= m; j++) {\n zs[i][j] = zs[i][j - 1] + zs[i - 1][j];\n }\n }\n\n for (int i = 1; i <= n; i++) {\n for (int j = 1; j <= m; j++) {\n dp[i][j] = zs[i][j] + dp[i][j - 1] + dp[i-1][j];\n }\n }\n out.println(dp[n][m]);\n\n out.close();\n in.close();\n }\n\n /**\n * My template below. FastIO and utility functions.\n * Minimized with https://codebeautify.org/javaviewer.\n */\n\n // @formatter:off\n staticArrayList>get2D(int n){ArrayList>ret=new ArrayList<>();for(int i=0;i());return ret;}\n static void force(boolean condition){if(!condition)throw new IllegalStateException();}\n static class BufferedPrinter{PrintWriter out;BufferedPrinter(OutputStream out){this(new OutputStreamWriter(out));}\n BufferedPrinter(Writer out){this.out=new PrintWriter(new BufferedWriter(out));}\n void print(Object...os){for(int i=0;i=count){pos=0;count=in.read(buf);if(count<=0)return-1;}}catch(IOException e){err();}\n return buf[pos++];}\n private static boolean isSpace(int c){return c==' '||c=='\\n'||c=='\\r'||c=='\\t'||c==-1;}\n private int readSkipSpace(){int ret;do{ret=read();}while(isSpace(ret));return ret;}\n int nextInt(){int sign=1;int c=readSkipSpace();if(c=='-'){sign=-1;c=read();}\n int ret=0;do{if(c<'0'||c>'9')err();ret=ret*10+c-'0';c=read();}while(!isSpace(c));return sign*ret;}\n String next(){StringBuilder sb=new StringBuilder();int c=readSkipSpace();do{sb.append((char)c);c=read();}while(!isSpace(c));return sb.toString();}\n private void err(){throw new InputMismatchException();}\n void close()throws IOException{in.close();}}\n // @formatter:on\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "863c06933399a2cbf1198232650149c4", "src_uid": "a2fcad987e9b2bb3e6395654cd4fcfbb", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class E {\n\n\tstatic final int[] DX = { -1, 0, 1, 0 };\n\tstatic final int[] DY = { 0, -1, 0, 1 };\n\n\tstatic final int P = 1_000_000_007;\n\n\tstatic final int CACHE_SIZE = 1 << 19;\n\tint[] cacheInv = new int[CACHE_SIZE];\n\t{\n\t\tcacheInv[1] = 1;\n\t\tfor (int i = 2; i < CACHE_SIZE; i++) {\n\t\t\tcacheInv[i] = P - (int) ((long) (P / i) * cacheInv[P % i] % P);\n\t\t}\n\t}\n\n\tint inv(int x) {\n\t\treturn x < CACHE_SIZE ? cacheInv[x] : P\n\t\t\t\t- (int) ((long) (P / x) * inv(P % x) % P);\n\t}\n\n\tvoid submit() {\n\t\t// long start = System.currentTimeMillis();\n\t\tint r = nextInt();\n\t\tint[] byDir = new int[4];\n\t\tint sum = 0;\n\t\tfor (int i = 0; i < 4; i++) {\n\t\t\tbyDir[i] = nextInt();\n\t\t\tsum += byDir[i];\n\t\t}\n\n\t\tint invSum = inv(sum);\n\n\t\tfor (int i = 0; i < 4; i++) {\n\t\t\tbyDir[i] = (int) ((long) byDir[i] * invSum % P);\n\t\t}\n\n\t\tint s = 2 * r + 3;\n\n\t\tint[][] f = new int[s][s];\n\t\tint[] cx = new int[s * s];\n\t\tint[] cy = new int[s * s];\n\t\tint vars = 0;\n\t\tfor (int i = 0; i < s; i++) {\n\t\t\tfor (int j = 0; j < s; j++) {\n\t\t\t\tint sum2 = (i - r - 1) * (i - r - 1) + (j - r - 1)\n\t\t\t\t\t\t* (j - r - 1);\n\t\t\t\tif (sum2 <= r * r) {\n\t\t\t\t\tcx[vars] = i;\n\t\t\t\t\tcy[vars] = j;\n\t\t\t\t\tf[i][j] = vars++;\n\t\t\t\t} else {\n\t\t\t\t\tf[i][j] = -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint band = 0;\n\n\t\tfor (int i = 0; i < vars; i++) {\n\t\t\tint x0 = cx[i];\n\t\t\tint y0 = cy[i];\n\t\t\tfor (int dir = 0; dir < 4; dir++) {\n\t\t\t\tint x1 = x0 + DX[dir];\n\t\t\t\tint y1 = y0 + DY[dir];\n\t\t\t\tif (f[x1][y1] == -1) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tint j = f[x1][y1];\n\t\t\t\tband = Math.max(band, Math.abs(i - j));\n\t\t\t}\n\t\t}\n\n\t\tint[][] bandM = new int[vars][2 * band + 1];\n\n\t\tfor (int i = 0; i < vars; i++) {\n\t\t\tint x0 = cx[i];\n\t\t\tint y0 = cy[i];\n\t\t\tfor (int dir = 0; dir < 4; dir++) {\n\t\t\t\tint x1 = x0 + DX[dir];\n\t\t\t\tint y1 = y0 + DY[dir];\n\t\t\t\tif (f[x1][y1] == -1) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tint j = f[x1][y1];\n\n\t\t\t\tupdateBandedMatrix(i, j, band, bandM, byDir[dir]);\n\n\t\t\t}\n\t\t}\n\n\t\tfor (int i = 0; i < vars; i++) {\n\t\t\tfor (int d = 0; d <= 2 * band; d++) {\n\t\t\t\tint j = i + d - band;\n\t\t\t\tbandM[i][d] = (i == j ? 1 : 0) - bandM[i][d];\n\t\t\t\tif (bandM[i][d] < 0) {\n\t\t\t\t\tbandM[i][d] += P;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// out.println(System.currentTimeMillis() - start);\n\n\t\tint[] ans = inverseBanded(bandM, band, f[r + 1][r + 1]);\n\n\t\t// out.println(System.currentTimeMillis() - start);\n\n\t\tint ret = 0;\n\t\tfor (int x : ans) {\n\t\t\tret += x;\n\t\t\tif (ret >= P) {\n\t\t\t\tret -= P;\n\t\t\t}\n\t\t}\n\n\t\tout.println(ret);\n\n\t}\n\n\tvoid updateBandedMatrix(int row, int col, int width, int[][] m, double delta) {\n\t\tif (Math.abs(row - col) > width) {\n\t\t\tthrow new AssertionError();\n\t\t}\n\t\tm[row][col - row + width] += delta;\n\t}\n\n\tint[] inverseBanded(int[][] a, int w, int whatCol) {\n\t\tint n = a.length;\n\t\tif (whatCol > n) {\n\t\t\tthrow new AssertionError();\n\t\t}\n\t\tint[] b = new int[n];\n\t\tb[whatCol] = 1;\n\n\t\tfor (int j = 0; j < n; j++) {\n\t\t\tint[] aj = a[j];\n\t\t\tfor (int i = j + 1; i <= j + w && i < n; i++) {\n\t\t\t\tint[] ai = a[i];\n\t\t\t\tint coef = (int) ((long) ai[j - i + w] * inv(aj[w]) % P);\n\n\t\t\t\tfor (int k = j + 1; k < n && k <= j + w; k++) {\n\t\t\t\t\tint kek = ai[k - i + w]\n\t\t\t\t\t\t\t- (int) ((long) aj[k - j + w] * coef % P);\n\t\t\t\t\tif (kek < 0) {\n\t\t\t\t\t\tkek += P;\n\t\t\t\t\t}\n\t\t\t\t\tai[k - i + w] = kek;\n\t\t\t\t}\n\t\t\t\tb[i] -= (int) ((long) b[j] * coef % P);\n\t\t\t\tif (b[i] < 0) {\n\t\t\t\t\tb[i] += P;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// for (int i = n - 1; i >= 0; i--) {\n\t\t// for (int j = i + 1; j < n && j <= i + w; j++) {\n\t\t// b[i] -= (int) ((long) b[j] * a[i][j - i + w] % P);\n\t\t// if (b[i] < 0) {\n\t\t// b[i] += P;\n\t\t// }\n\t\t// }\n\t\t// b[i] = (int) ((long) b[i] * inv(a[i][w]) % P);\n\t\t// }\n\n\t\tfor (int i = n - 1; i >= 0; i--) {\n\t\t\tlong tot = 0;\n\t\t\tfor (int j = i + 1; j < n && j <= i + w; j++) {\n\t\t\t\ttot += (long) b[j] * a[i][j - i + w];\n\t\t\t\tif (tot >= P2) {\n\t\t\t\t\ttot -= P2;\n\t\t\t\t}\n\t\t\t}\n\t\t\tb[i] -= (int) (tot % P);\n\t\t\tif (b[i] < 0) {\n\t\t\t\tb[i] += P;\n\t\t\t}\n\t\t\tb[i] = (int) ((long) b[i] * inv(a[i][w]) % P);\n\t\t}\n\n\t\treturn b;\n\t}\n\n\tstatic final long P2 = (long) P * P;\n\n\tvoid preCalc() {\n\n\t}\n\n\tvoid test() {\n\n\t}\n\n\tvoid stress() {\n\t\tfor (int tst = 0;; tst++) {\n\t\t\tif (false) {\n\t\t\t\tthrow new AssertionError();\n\t\t\t}\n\t\t\tSystem.err.println(tst);\n\t\t}\n\t}\n\n\tE() throws IOException {\n\t\tis = System.in;\n\t\tout = new PrintWriter(System.out);\n\t\tpreCalc();\n\t\tsubmit();\n\t\t// stress();\n\t\t// test();\n\t\tout.close();\n\t}\n\n\tstatic final Random rng = new Random();\n\tstatic final int C = 5;\n\n\tstatic int rand(int l, int r) {\n\t\treturn l + rng.nextInt(r - l + 1);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew E();\n\t}\n\n\tprivate InputStream is;\n\tPrintWriter out;\n\n\tprivate byte[] buf = new byte[1 << 14];\n\tprivate int bufSz = 0, bufPtr = 0;\n\n\tprivate int readByte() {\n\t\tif (bufSz == -1)\n\t\t\tthrow new RuntimeException(\"Reading past EOF\");\n\t\tif (bufPtr >= bufSz) {\n\t\t\tbufPtr = 0;\n\t\t\ttry {\n\t\t\t\tbufSz = is.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t\tif (bufSz <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[bufPtr++];\n\t}\n\n\tprivate boolean isTrash(int c) {\n\t\treturn c < 33 || c > 126;\n\t}\n\n\tprivate int skip() {\n\t\tint b;\n\t\twhile ((b = readByte()) != -1 && isTrash(b))\n\t\t\t;\n\t\treturn b;\n\t}\n\n\tString nextToken() {\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!isTrash(b)) {\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tString nextString() {\n\t\tint b = readByte();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!isTrash(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\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tchar nextChar() {\n\t\treturn (char) skip();\n\t}\n\n\tint nextInt() {\n\t\tint ret = 0;\n\t\tint b = skip();\n\t\tif (b != '-' && (b < '0' || b > '9')) {\n\t\t\tthrow new InputMismatchException();\n\t\t}\n\t\tboolean neg = false;\n\t\tif (b == '-') {\n\t\t\tneg = true;\n\t\t\tb = readByte();\n\t\t}\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tret = ret * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\tif (b != -1 && !isTrash(b)) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\treturn neg ? -ret : ret;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\n\tlong nextLong() {\n\t\tlong ret = 0;\n\t\tint b = skip();\n\t\tif (b != '-' && (b < '0' || b > '9')) {\n\t\t\tthrow new InputMismatchException();\n\t\t}\n\t\tboolean neg = false;\n\t\tif (b == '-') {\n\t\t\tneg = true;\n\t\t\tb = readByte();\n\t\t}\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tret = ret * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\tif (b != -1 && !isTrash(b)) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\treturn neg ? -ret : ret;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3f043a702c58138abcfc99416eb2f53a", "src_uid": "bd6bcb5bffd039de93f217b02f5eae17", "difficulty": 3100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class E {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tint n;\n\tint[] p;\n\tint[] sz;\n\tint[] who;\n\n\tint[] to;\n\tint[] head;\n\tint[] next;\n\n\tvoid addEdge(int v, int u, int idx) {\n\t\tto[idx] = u;\n\t\tnext[idx] = head[v];\n\t\thead[v] = idx;\n\t}\n\n\tboolean cool(int a, int b, int c, int d) {\n\t\t// CAN ONLY EVEN!!!\n\t\t// SO COOL OPTIMIZATION\n\t\t// VERY MUCH\n\t\tboolean[] can = new boolean[n / 2 + 3];\n\t\tcan[0] = true;\n\n\t\tint base = 0;\n\n\t\tfor (int v = p[a]; v != 0; v = p[v]) {\n\t\t\tbase++; // need to take this edge\n\n\t\t\tfor (int e = head[v]; e >= 0; e = next[e]) {\n\t\t\t\tint u = to[e];\n\t\t\t\tif (who[u] == a) {\n\t\t\t\t\t// System.err.println(v + \" a \" + u);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tint nowSz = sz[u];\n\n\t\t\t\tfor (int i = can.length - 1; i >= nowSz; i--) {\n\t\t\t\t\tcan[i] |= can[i - nowSz];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (int v = p[b]; v != 0; v = p[v]) {\n\t\t\tbase++; // need to take this edge\n\n\t\t\tfor (int e = head[v]; e >= 0; e = next[e]) {\n\t\t\t\tint u = to[e];\n\t\t\t\tif (who[u] == b) {\n\t\t\t\t\t// System.err.println(v + \" b \" + u);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tint nowSz = sz[u];\n\n\t\t\t\tfor (int i = can.length - 1; i >= nowSz; i--) {\n\t\t\t\t\tcan[i] |= can[i - nowSz];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint szC = -1;\n\t\tint szD = -1;\n\t\tfor (int e = head[0]; e >= 0; e = next[e]) {\n\t\t\tint u = to[e];\n\t\t\tif (who[u] == c) {\n\t\t\t\tszC = sz[u];\n\t\t\t} else if (who[u] == d) {\n\t\t\t\tszD = sz[u];\n\t\t\t} else if (who[u] == -1) {\n\t\t\t\tint nowSz = sz[u];\n\t\t\t\tfor (int i = can.length - 1; i >= nowSz; i--) {\n\t\t\t\t\tcan[i] |= can[i - nowSz];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (szC == -1 || szD == -1) {\n\t\t\tthrow new AssertionError();\n\t\t}\n\n\t\t// System.err.println(Arrays.toString(can));\n\t\t// System.err.println(base);\n\t\t// System.err.println(szC + \" \" + szD);\n\n\t\tbase += 2; // edges from root\n\n\t\t{\n\t\t\tint need = n - 1 - 2 * szC;\n\t\t\tif ((need - base) % 2 != 0) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tint lookFor = (need - base) / 2;\n\t\t\tif (lookFor < 0 || lookFor >= can.length || !can[lookFor]) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\t\n\t\t{\n\t\t\tint need = n - 1 - 2 * szD;\n\t\t\tif ((need - base) % 2 != 0) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tint lookFor = (need - base) / 2;\n\t\t\tif (lookFor < 0 || lookFor >= can.length || !can[lookFor]) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\tvoid solve() throws IOException {\n\t\tn = nextInt();\n\t\tint a = nextInt() - 1;\n\t\tint b = nextInt() - 1;\n\t\tint c = nextInt() - 1;\n\t\tint d = nextInt() - 1;\n\n\t\thead = new int[n];\n\t\tArrays.fill(head, -1);\n\t\tto = new int[n - 1];\n\t\tnext = new int[n - 1];\n\n\t\tp = new int[n];\n\t\tp[0] = -1;\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tp[i] = nextInt() - 1;\n\t\t\taddEdge(p[i], i, i - 1);\n\t\t}\n\n\t\tsz = new int[n];\n\t\twho = new int[n];\n\n\t\tArrays.fill(who, -1);\n\t\twho[a] = a;\n\t\twho[b] = b;\n\t\twho[c] = c;\n\t\twho[d] = d;\n\n\t\tArrays.fill(sz, 1);\n\t\tfor (int i = n - 1; i >= 1; i--) {\n\t\t\tsz[p[i]] += sz[i];\n\t\t\tif (who[i] != -1) {\n\t\t\t\twho[p[i]] = who[i];\n\t\t\t}\n\t\t}\n\n\t\tout.println(cool(a, b, c, d) && cool(c, d, a, b) ? \"YES\" : \"NO\");\n\n\t}\n\n\tE() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew E();\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() {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "8be9c39c49248ce0ee072264b7939bfa", "src_uid": "87db879f0ca422020125a3e4d99d3c23", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "/*Author: Satyajeet Singh, Delhi Technological University*/\n import java.io.*;\n import java.util.*;\n import java.text.*; \n import java.lang.*;\n import java.math.*;\npublic class Main{\n/*********************************************Constants******************************************/\n static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out)); \n static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n static long mod=(long)1e9+7;\n static long mod1=998244353;\n static boolean sieve[];\n static ArrayList primes;\n static long factorial[],invFactorial[];\n static ArrayList graph[];\n static int pptr=0;\n static String st[];\n/****************************************Solutions Begins***************************************/\n static void fact(int n){\n factorial=new long[n+1];\n invFactorial=new long [n+1];\n factorial[0]=1l;\n invFactorial[0]=1l;\n for(int i=1;i<=n;i++){\n factorial[i]=(factorial[i-1]*i)%mod;\n invFactorial[i]=modulo(factorial[i],mod-2,mod);\n }\n }\n/*******************************************ncr*********************************************************/\n static long ncr(int n,int k){\n long aa=invFactorial[n-k];\n long bb=invFactorial[k];\n long cc=factorial[n];\n long ans=(aa*cc)%mod;\n ans=(ans*bb)%mod;\n return ans;\n }\n static int nx(int i){\n i++;\n if(i>=n)return i-=n;\n return i;\n }\n static int n;\n public static void main(String[] args) throws Exception{\n nl();\n n=pi();\n long k=pi();\n mod=mod1;\n fact(n+5);\n long t=0;\n int input[]=new int[n];\n nl();\n for(int i=0;i=mod)cur-=mod;\n }\n ans=(ans*cur)%mod;\n out.println(ans);\n/****************************************Solutions Ends**************************************************/\n out.flush();\n out.close();\n }\n/****************************************Template Begins************************************************/\n static void nl() throws Exception{\n pptr=0;\n st=br.readLine().split(\" \");\n }\n static void nls() throws Exception{\n pptr=0;\n st=br.readLine().split(\"\");\n }\n static int pi(){\n return Integer.parseInt(st[pptr++]);\n }\n static long pl(){\n return Long.parseLong(st[pptr++]);\n }\n static double pd(){\n return Double.parseDouble(st[pptr++]);\n }\n static String ps(){\n return st[pptr++];\n }\n/***************************************Precision Printing**********************************************/\n static void printPrecision(double d){\n DecimalFormat ft = new DecimalFormat(\"0.000000000000000000000\"); \n out.print(ft.format(d));\n }\n/**************************************Bit Manipulation**************************************************/\n static void printMask(long mask){\n System.out.println(Long.toBinaryString(mask));\n }\n static int countBit(long mask){\n int ans=0;\n while(mask!=0){\n mask&=(mask-1);\n ans++;\n }\n return ans;\n }\n/******************************************Graph*********************************************************/\n static void Makegraph(int n){\n graph=new ArrayList[n];\n for(int i=0;i();\n }\n }\n static void addEdge(int a,int b){\n graph[a].add(new Pair(b,1));\n }\n static void addEdge(int a,int b,int c){\n graph[a].add(new Pair(b,c));\n } \n/*********************************************PAIR********************************************************/\n static class Pair implements Comparable {\n int u;\n int v;\n int index=-1;\n public Pair(int u, int v) {\n this.u = u;\n this.v = v;\n }\n public int hashCode() {\n int hu = (int) (u ^ (u >>> 32));\n int hv = (int) (v ^ (v >>> 32));\n return 31 * hu + hv;\n }\n public boolean equals(Object o) {\n Pair other = (Pair) o;\n return u == other.u && v == other.v;\n }\n public int compareTo(Pair other) {\n if(index!=other.index)\n return Long.compare(index, other.index);\n return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);\n }\n public String toString() {\n return \"[u=\" + u + \", v=\" + v + \"]\";\n }\n }\n/******************************************Long Pair*******************************************************/\n static class Pairl implements Comparable {\n long u;\n long v;\n int index=-1;\n public Pairl(long u, long v) {\n this.u = u;\n this.v = v;\n }\n public int hashCode() {\n int hu = (int) (u ^ (u >>> 32));\n int hv = (int) (v ^ (v >>> 32));\n return 31 * hu + hv;\n }\n public boolean equals(Object o) {\n Pairl other = (Pairl) o;\n return u == other.u && v == other.v;\n }\n public int compareTo(Pairl other) {\n if(index!=other.index)\n return Long.compare(index, other.index);\n return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);\n }\n public String toString() {\n return \"[u=\" + u + \", v=\" + v + \"]\";\n }\n }\n/*****************************************DEBUG***********************************************************/\n public static void debug(Object... o){\n System.out.println(Arrays.deepToString(o));\n }\n/************************************MODULAR EXPONENTIATION***********************************************/\n static long modulo(long a,long b,long c){\n long x=1;\n long y=a%c;\n while(b > 0){\n if(b%2 == 1){\n x=(x*y)%c;\n }\n y = (y*y)%c; // squaring the base\n b /= 2;\n }\n return x%c;\n }\n/********************************************GCD**********************************************************/\n static long gcd(long x, long y){\n if(x==0)\n return y;\n if(y==0)\n return x;\n long r=0, a, b;\n a = (x > y) ? x : y; // a is greater number\n b = (x < y) ? x : y; // b is smaller number\n r = b;\n while(a % b != 0){\n r = a % b;\n a = b;\n b = r;\n }\n return r;\n }\n/******************************************SIEVE**********************************************************/\n static void sieveMake(int n){\n sieve=new boolean[n];\n Arrays.fill(sieve,true);\n sieve[0]=false;\n sieve[1]=false;\n for(int i=2;i*i();\n for(int i=0;i adj[]=new ArrayList[N];\r\nstatic long dp[][]=new long[2][N];\r\nstatic long A[][]=new long[2][N];\r\n\r\n-----------DFS--------------\r\n*/\r\n/*static class Edge implements Comparable{\r\nint destination;long cost;\r\nEdge(int destination,long cost){this.cost=cost;this.destination=destination;}\r\n\r\n@Override\r\n\r\n\t\tpublic int compareTo(Edge o) {\r\n\t\t\treturn Long.compare(cost, o.cost);\r\n\t\t}\r\n}\r\n\r\n*/\r\n\r\npublic static void main(String []args){\r\n\r\nint t=1;\r\n\r\nwhile(t-->0){\r\nint n=in.nextInt();int m=in.nextInt();\r\n\r\nHashSet hs=new HashSet();boolean ans=true;\r\nwhile(n>0){if(hs.contains(n%m)){ans=false;}else{hs.add(n%m);}n/=m; }\r\nif(ans)out.println(\"YES\");\r\nelse out.println(\"NO\");\r\n }\r\n\r\nout.close();\r\n}}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "77d40495567c4b28b25c932a793e1a3e", "src_uid": "a8945bb1082fefe70e6898a8bec1ce3f", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\npublic class ComputerGame {\n\n\tstatic double[][] identity;\n\tstatic double INF = 1e18D;\n\tstatic int MAXPOW = 40;\n\tpublic static void main(String[] args) {\n\t\tFS in = new FS();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint N = in.nextInt();\n\t\tlong T = in.nextLong();\n\t\tdouble[] A = new double[N];\n\t\tdouble[] B = new double[N];\n\t\tdouble[] P = new double[N];\n\t\tdouble V = 0;\n\t\tfor(int i = 0; i < N; i++) {\n\t\t\tA[i] = in.nextDouble();\n\t\t\tB[i] = in.nextDouble();\n\t\t\tP[i] = in.nextDouble();\n\t\t\tV = Math.max(V, P[i]*B[i]);\n\t\t}\n\t\n\t\tCHT cht = new CHT(1);\n\t\tfor(int i = 0; i < N; i++) {\n\t\t\tcht.add(P[i], P[i]*A[i], i);\n\t\t}\n\t\tidentity = identity(3);\n\t\tdouble vec[][] = new double[][]{{0}, {0}, {1}}; //prevDp, prevT, prev1\n\t\tfor(CHT.Line l : cht.hull) {\n\t\t\tCHT.Line higherLine = cht.hull.higher(l);\n\t\t\tdouble stopAt = higherLine == null ? INF : l.inter(higherLine);\n\t\t\t\n\t\t\tdouble mat[][] = new double[][] {\n\t\t\t\t{1-P[l.id], P[l.id]*V, P[l.id]*A[l.id]},\n\t\t\t\t{0, 1, 1},\n\t\t\t\t{0, 0, 1},\n\t\t\t};\n\t\t\t\n\t\t\tdouble matToPowerOf2[][][] = new double[MAXPOW][][];\n\t\t\tmatToPowerOf2[0] = identity;\n\t\t\tmatToPowerOf2[1] = mat;\n\t\t\tfor(int i = 2; i < MAXPOW; i++) matToPowerOf2[i] = mult(matToPowerOf2[i-1], matToPowerOf2[i-1]);\n\t\t\t\n//\t\t\tprint(mat);\n\t\t\t\n\t\t\t// Find how long we will use this line for\n\t\t\tdouble cur[][] = identity;\n\t\t\tfor(int i = MAXPOW-1; i >= 0; i--) {\n\t\t\t\tdouble next[][] = mult(cur, matToPowerOf2[i]);\n\t\t\t\tdouble nextVec[][] = mult(next, vec);\n\t\t\t\t\n\t\t\t\tlong t = (long)(nextVec[1][0]);\n\t\t\t\tdouble query = V*t-nextVec[0][0];\n\t\t\t\t\n\t\t\t\tboolean bad = (t > T) || (query > stopAt);\n\t\t\t\tif(!bad) {\n\t\t\t\t\t// Take this expo\n\t\t\t\t\tcur = next;\n\t\t\t\t}\n\t\t\t}\n\t\t\tvec = mult(cur, vec);\n\t\t}\n\t\tSystem.out.println(vec[0][0]);\n\t}\n\t\n\tstatic void print(double a[][]) {\n\t\tfor(int i = 0; i < a.length; i++) {\n\t\t\tSystem.out.println(Arrays.toString(a[i]));\n\t\t}\n\t\tSystem.out.println();\n\t}\n\t\n\tstatic double [][] pow(double m[][], long p) {\n\t\tif(p == 0) return identity;\n\t\tif(p == 1) return m;\n\t\tif((p&1) == 0) {\n\t\t\tdouble res[][] = pow(m, p>>1);\n\t\t\treturn mult(res,res);\n\t\t}\n\t\telse {\n\t\t\treturn mult(m, pow(m, p-1));\n\t\t}\n\t}\n\t\n\tstatic double[][] mult(double a[][], double b[][]){\n\t\tdouble res[][] = new double[a.length][b[0].length];\n\t\tfor(int i = 0; i < a.length; i++) {\n\t\t\tfor(int j = 0; j < b[0].length; j++) {\n\t\t\t\tfor(int k = 0; k < a[i].length; k++) {\n\t\t\t\t\tres[i][j] += a[i][k]*b[k][j];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n\tstatic double[][] identity(int sz) {\n\t\tdouble res[][] = new double[sz][sz];\n\t\tfor(int i = 0; i < sz; i++) res[i][i] = 1;\n\t\treturn res;\n\t}\n\t\n\tstatic class CHT {\n\t\tTreeSet hull;\n\t\tint type; boolean query = false;\n\t\tComparator comp = new Comparator() {\n\t\t\tpublic int compare(Line a, Line b) {\n\t\t\t\tif (!query) return type * Double.compare(a.m, b.m);\n\t\t\t\tif (a.left == b.left) return Double.compare(a.m, b.m);\n\t\t\t\treturn Double.compare(a.left, b.left);\n\t\t\t}\n\t\t};\n\t\t// -1 for min; +1 for max\n\t\tpublic CHT(int typee) { type = typee; hull = new TreeSet<>(comp); }\n\n\t\tpublic void add(double m, double b, int id) { add(new Line(m, b, id)); }\n\n\t\tpublic void add(Line a) {\n\t\t\tLine[] LR = { hull.lower(a), hull.ceiling(a) };\n\t\t\tfor (int i = 0; i < 2; i++)\n\t\t\t\tif (LR[i] != null && LR[i].m == a.m) {\n\t\t\t\t\tif (type == 1 && LR[i].b >= a.b) return;\n\t\t\t\t\tif (type == -1 && LR[i].b <= a.b) return;\n\t\t\t\t\tremove(LR[i]);\n\t\t\t\t}\n\t\t\thull.add(a);\n\t\t\tLine L = hull.lower(a), R = hull.higher(a);\n\t\t\tif (L != null && R != null && a.inter(R) <= R.left) {\n\t\t\t\thull.remove(a);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tLine LL = (L != null) ? hull.lower(L) : null;\n\t\t\tLine RR = (R != null) ? hull.higher(R) : null;\n\t\t\tif (L != null) a.left = a.inter(L);\n\t\t\tif (R != null) R.left = a.inter(R);\n\t\t\twhile (LL != null && L.left >= a.inter(LL)) {\n\t\t\t\tremove(L);\n\t\t\t\ta.left = a.inter(L = LL);\n\t\t\t\tLL = hull.lower(L);\n\t\t\t}\n\t\t\twhile (RR != null && R.inter(RR) <= a.inter(RR)) {\n\t\t\t\tremove(R);\n\t\t\t\tRR.left = a.inter(R = RR);\n\t\t\t\tRR = hull.higher(R);\n\t\t\t}\n\t\t}\n\n\t\tpublic long query(long x) {\n\t\t\tif(hull.size() == 0) return 0;\n\t\t\tLine temp = new Line(0, 0);\n\t\t\ttemp.left = x; query = true;\n\t\t\tlong ans = (long) hull.floor(temp).eval(x);\n\t\t\tquery = false; return ans;\n\t\t}\n\n\t\tprivate void remove(Line x) { hull.remove(x); }\n\n\t\tpublic int size() { return hull.size(); }\n\n\t\tstatic class Line {\n\t\t\tdouble m, b; double left = Long.MIN_VALUE;\n\t\t\tint id;\n\t\t\tpublic Line(double mm, double bb, int ii) { m = mm; b = bb; id = ii;}\n\t\t\tpublic Line(double mm, double bb) { m = mm; b = bb; }\n\t\t\tpublic double eval(double x) { return m * x + b; }\n\t\t\tpublic double inter(Line x) {\n\t\t\t\treturn (double) (x.b - this.b) / (double) (this.m - x.m);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tstatic class FS{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FS() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\t\tString next() {\n\t\t\twhile(st == null || !st.hasMoreElements()) {\n\t\t\t\ttry { st = new StringTokenizer(br.readLine());}\n\t\t\t\tcatch(Exception e) { throw null;}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tint nextInt() { return Integer.parseInt(next());}\n\t\tdouble nextDouble() { return Double.parseDouble(next());}\n\t\tlong nextLong() { return Long.parseLong(next());}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4ce92c53921fedd97dd62f0e65e01217", "src_uid": "64e378664209cf1933cf082493a0875c", "difficulty": 3100.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class G {\n\tint oo = (int)1e8;\n\t\n\tpublic static void main(String[] args) {\n\t\tnew G();\n\t}\n\n\tint SQRT;\n\tint[] minTandemStart, minTandemEnd, sa, rsa, lcp;\n\tboolean[] primes;\n\tRMQ query3RMQ, lcpRMQ;\n\tString str;\n\t\n\tpublic G() {\n\t\tFastScanner fs = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tSystem.err.println(\"\");\n\n\t\tdoPrimes();\n\t\t\n\t\tint n = fs.nextInt();\n\t\tSQRT = (int)Math.sqrt(n);\n\t\tstr = fs.next();\n\t\tFastSuffixArray fsa = new FastSuffixArray();\n\t\tsa = fsa.suffixArray(str.toCharArray());\n\t\trsa = new int[sa.length];\n\t\tlcp = fsa.lcp(sa, str.toCharArray());\n\t\tlcpRMQ = new RMQ(lcp);\n\t\tfor(int i = 0; i < sa.length; i++) rsa[sa[i]] = i;\n\t\t\n\t\tTandemRepeats tr = new TandemRepeats(str);\n\t\tminTandemStart = tr.min;\n\t\tTandemRepeats tr2 = new TandemRepeats(reverse(str));\n\t\tminTandemEnd = reverse(tr2.min);\n\t\t\n//\t\tSystem.out.println(Arrays.toString(minTandemStart));\n//\t\tSystem.out.println(Arrays.toString(minTandemEnd));\n//\t\tSystem.out.println();\n\t\t\n\t\tint[] query3Values = new int[n];\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tquery3Values[i] = i+2*minTandemStart[i];\n\t\t}\n\t\tquery3RMQ = new RMQ(query3Values);\n\t\t\n\t\tint[][] pref = new int[26][n];\n\t\tfor(int i = n-1; i >= 0; i--) {\n\t\t\tfor(int j = 0; j < 26 && i+1 < n; j++) pref[j][i] = pref[j][i+1];\n\t\t\tpref[str.charAt(i)-'a'][i]++;\n\t\t}\n\t\t\n\t\tint Q = fs.nextInt();\n\t\tfor(int qq = 1; qq <= Q; qq++) {\n\t\t\tint L = fs.nextInt()-1, R = fs.nextInt()-1;\n\t\t\t\n\t\t\t//case -1\n\t\t\tboolean good = false;\n\t\t\tfor(int i = 0; i < 26; i++) {\n\t\t\t\tint sum = pref[i][L];\n\t\t\t\tif(R + 1 < n) sum -= pref[i][R+1];\n\t\t\t\tif(sum > 1) good = true;\n\t\t\t}\n\t\t\tif(!good) {\n\t\t\t\tout.println(-1);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\t//case 1:\n\t\t\tboolean ans1 = false;\n\t\t\tint N = R-L+1;\n\t\t\tfor(int div = 1; div * div <= N; div++) {\n\t\t\t\tif(N % div != 0) continue;\n\t\t\t\tif(!primes[N/div]) continue;\n\t\t\t\t\n\t\t\t\tif(check(L, R, div)) ans1 = true;\n\t\t\t\telse if(primes[div] && check(L, R, N/div)) ans1 = true;\n\t\t\t\tif(ans1) break;\n\t\t\t}\n\t\t\tif(ans1) {\n\t\t\t\tout.println(1);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\t//case 2:\n\t\t\tboolean ans2 = false;\n\t\t\tif(minTandemStart[L] != oo && L+minTandemStart[L]*2-1 <= R) {\n\t\t\t\tans2 = true;\n\t\t\t}\n\t\t\tif(minTandemEnd[R] != oo && R-minTandemEnd[R]*2+1 >= L) {\n\t\t\t\tans2 = true;\n\t\t\t}\n\t\t\tif(isBorder(L, R)) {\n\t\t\t\tans2 = true;\n\t\t\t}\n\t\t\tif(ans2) {\n\t\t\t\tout.println(2);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\t//case 3:\n\t\t\tboolean ans3 = false;\n\t\t\t{ //first character\n\t\t\t\tint idx = str.charAt(L)-'a';\n\t\t\t\tint sum = pref[idx][L];\n\t\t\t\tif(R+1 < n) sum -= pref[idx][R+1];\n\t\t\t\tif(sum > 1) ans3 = true;\n\t\t\t}\n\t\t\t{ //last character\n\t\t\t\tint idx = str.charAt(R)-'a';\n\t\t\t\tint sum = pref[idx][L];\n\t\t\t\tif(R+1 < n) sum -= pref[idx][R+1];\n\t\t\t\tif(sum > 1) ans3 = true;\n\t\t\t}\n\t\t\t{ //BAAC\n\t\t\t\tint min = query3RMQ.query(L, R);\n\t\t\t\tif(min <= R) ans3 = true;\n\t\t\t}\n\t\t\tif(ans3) {\n\t\t\t\tout.println(3);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\tout.println(4);\n\t\t}\n\n\t\tout.close();\n\t}\n\t\n\tboolean check(int L, int R, int div) {\n\t\tint minPos = rsa[L], maxPos = rsa[L];\n\t\tfor(int j = L+div; j <= R; j += div) {\n\t\t\tminPos = Math.min(minPos, rsa[j]);\n\t\t\tmaxPos = Math.max(maxPos, rsa[j]);\n\t\t}\n\t\tint lcp = lcpRMQ.query(minPos, maxPos-1);\n\t\tif(lcp >= div) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\t\n\tboolean isBorder(int L, int R) {\n\t\tfor(int len = 1; len < SQRT; len++) {\n\t\t\tint ptsTo = R-len+1;\n\t\t\tif(ptsTo <= L+len-1) continue;\n\t\t\tint min = Math.min(rsa[L], rsa[ptsTo]);\n\t\t\tint max = Math.max(rsa[L], rsa[ptsTo]);\n\t\t\tint lcp = lcpRMQ.query(min, max-1);\n\t\t\tif(lcp >= len) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\tint st = Math.max(0, rsa[L]-SQRT-1);\n\t\tint en = Math.min(sa.length-1, rsa[L]+SQRT+1);\n\t\tint him = rsa[L];\n\t\t\n\t\tfor(int i = st; i <= en; i++) {\n\t\t\tint idx = sa[i];\n\t\t\tif(L <= idx && idx <= R) {}\n\t\t\telse continue;\n\t\t\tint min = Math.min(i, him);\n\t\t\tint max = Math.max(i, him);\n\t\t\tint lcp = lcpRMQ.query(min, max-1);\n\t\t\tif(lcp < SQRT) continue;\n\t\t\t\n\t\t\tif(idx+lcp-1 < R) continue;\n\t\t\tint size = R-idx+1;\n\t\t\tif(L+size-1 >= idx) continue;\n\t\t\treturn true;\n\t\t}\n\t\t\n\t\treturn false;\n\t}\n\t\n\tclass RMQ {\n\t\tint[] vs;\n\t\tint[][] lift;\n\n\t\tpublic RMQ(int[] vs) {\n\t\t\tthis.vs = vs;\n\t\t\tint n = vs.length;\n\t\t\tint maxlog = Integer.numberOfTrailingZeros(Integer.highestOneBit(n)) + 2;\n\t\t\tlift = new int[maxlog][n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tlift[0][i] = vs[i];\n\t\t\tint lastRange = 1;\n\t\t\tfor (int lg = 1; lg < maxlog; lg++) {\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tlift[lg][i] = Math.min(lift[lg - 1][i], lift[lg - 1][Math.min(i + lastRange, n - 1)]);\n\t\t\t\t}\n\t\t\t\tlastRange *= 2;\n\t\t\t}\n\t\t}\n\n\t\tpublic int query(int low, int hi) {\n\t\t\tif(hi < low) return 0;\n\t\t\tint range = hi - low + 1;\n\t\t\tint exp = Integer.highestOneBit(range);\n\t\t\tint lg = Integer.numberOfTrailingZeros(exp);\n\t\t\treturn Math.min(lift[lg][low], lift[lg][hi - exp + 1]);\n\t\t}\n\t}\n\n\tclass FastSuffixArray {\n\t\tpublic int[] suffixArray(char[] S) {\n\t\t\tint n = S.length;\n\t\t\tInteger[] order = new Integer[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\torder[i] = n - 1 - i;\n\n\t\t\tArrays.sort(order, (a, b) -> Character.compare(S[a], S[b]));\n\n\t\t\tint[] sa = new int[n];\n\t\t\tint[] classes = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tsa[i] = order[i];\n\t\t\t\tclasses[i] = S[i];\n\t\t\t}\n\n\t\t\tfor (int len = 1; len < n; len *= 2) {\n\t\t\t\tint[] c = classes.clone();\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tclasses[sa[i]] = i > 0 && c[sa[i - 1]] == c[sa[i]] && sa[i - 1] + len < n && c[sa[i - 1] + len / 2] == c[sa[i] + len / 2] ? classes[sa[i - 1]] : i;\n\t\t\t\t}\n\t\t\t\tint[] cnt = new int[n];\n\t\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\t\tcnt[i] = i;\n\t\t\t\tint[] s = sa.clone();\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tint s1 = s[i] - len;\n\t\t\t\t\tif (s1 >= 0)\n\t\t\t\t\t\tsa[cnt[classes[s1]]++] = s1;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn sa;\n\t\t}\n\n\t\tpublic int[] lcp(int[] sa, char[] s) {\n\t\t\tint n = sa.length;\n\t\t\tint[] rank = new int[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\trank[sa[i]] = i;\n\t\t\tint[] lcp = new int[n - 1];\n\t\t\tfor (int i = 0, h = 0; i < n; i++) {\n\t\t\t\tif (rank[i] < n - 1) {\n\t\t\t\t\tfor (int j = sa[rank[i] + 1]; Math.max(i, j) + h < s.length && s[i + h] == s[j + h]; ++h)\n\t\t\t\t\t\t;\n\t\t\t\t\tlcp[rank[i]] = h;\n\t\t\t\t\tif (h > 0)\n\t\t\t\t\t\t--h;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn lcp;\n\t\t}\n\t}\n\n\tclass TandemRepeats {\n\t\tint[] min;\n\t\tTandemRepeats(String str) {\n\t\t\tlist = new ArrayList<>();\n\t\t\tfindRepetitions(str, 0, str.length()-1);\n\t\t\tCollections.sort(list);\n\t\t\tmin = new int[str.length()];\n\t\t\tArrays.fill(min, oo);\n\n\t\t\tTreeMap map = new TreeMap<>();\n\t\t\tint ptr = 0;\n\t\t\tfor(int i = 0; i < str.length(); i++) {\n\t\t\t\twhile(ptr < list.size()) {\n\t\t\t\t\tEvent now = list.get(ptr);\n\t\t\t\t\tif(now.pos <= i) {\n\t\t\t\t\t\tif(now.type == 0) add(map, now.val);\n\t\t\t\t\t\telse rem(map, now.val);\n\t\t\t\t\t\tptr++;\n\t\t\t\t\t} else break;\n\t\t\t\t}\n\t\t\t\tif(!map.isEmpty())\n\t\t\t\t\tmin[i] = Math.min(min[i], map.firstKey());\n\t\t\t}\n\t\t}\n\n\t\tArrayList list;\n\t\t//Main-Lorentz algorithm\n\t\tvoid findRepetitions(String str, int L, int R) {\n\t\t\tint n = R-L+1;\n\t\t\tif(n < 2 || R < L) return;\n\n\t\t\tString u = str.substring(0, n/2);\n\t\t\tString v = str.substring(n/2);\n\t\t\tfindRepetitions(u, L, L+u.length()-1); findRepetitions(v, L+u.length(), R);\n\n\t\t\tint[] z1 = zValues(reverse(u));\n\t\t\tint[] z2 = zValues(v + \"#\" + u);\n\t\t\tint[] z3 = zValues(reverse(u) + \"#\" + reverse(v));\n\t\t\tint[] z4 = zValues(v);\n\n\t\t\tint uLen = u.length(), vLen = v.length();\n\t\t\tfor(int cntr = 0; cntr < n; cntr++) {\n\t\t\t\tint totLen, k1, k2;\n\t\t\t\tif(cntr < uLen) {\n\t\t\t\t\ttotLen = uLen-cntr;\n\t\t\t\t\tk1 = getIdx(z1, uLen-cntr);\n\t\t\t\t\tk2 = getIdx(z2, vLen+1+cntr);\n\n\t\t\t\t\tif(k1+k2 >= totLen) {\n\t\t\t\t\t\tint min = find(k1, k2, totLen, true, 0);\n\t\t\t\t\t\tint max = find(k1, k2, totLen, false, 0);\n\t\t\t\t\t\tint start = Math.max(L, L+cntr-max);\n\t\t\t\t\t\tint end = Math.min(L+cntr-1, L+cntr-min);\n\n\t\t\t\t\t\tif(start <= end) {\n\t\t\t\t\t\t\tlist.add(new Event(0, start, totLen));\n\t\t\t\t\t\t\tlist.add(new Event(1, end+1, totLen));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\ttotLen = cntr-uLen+1;\n\t\t\t\t\tk1 = getIdx(z3, uLen + 1 + vLen - 1 - (cntr - uLen));\n\t\t\t\t\tk2 = getIdx(z4, (cntr - uLen) + 1);\n\n\t\t\t\t\tif(k1+k2 >= totLen) {\n\t\t\t\t\t\tint max = find(k1, k2, totLen, false, 1);\n\t\t\t\t\t\tint min = find(k1, k2, totLen, true, 1);\n\t\t\t\t\t\tint start = Math.max(L, L+n/2-1 - max + 1);\n\t\t\t\t\t\tint end = Math.min(L+n/2-1, L+n/2-1-min+1);\n\n\t\t\t\t\t\tif(start <= end) {\n\t\t\t\t\t\t\tlist.add(new Event(0, start, totLen));\n\t\t\t\t\t\t\tlist.add(new Event(1, end+1, totLen));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\n\t\t\t\t}\n\t\t\t}\n\n\t\t}\n\n\t\tint find(int k1, int k2, int len, boolean small, int lim) {\n\t\t\tint lo = lim, hi = k1, res = 0;\n\t\t\tfor(int bs = 0; bs < 50 && lo <= hi; bs++) {\n\t\t\t\tint mid = (lo+hi)/2;\n\t\t\t\tint v = len-mid;\n\t\t\t\tif(v < 0) { //too much\n\t\t\t\t\thi = mid-1;\n\t\t\t\t}\n\t\t\t\telse if(v > k2) { //too little\n\t\t\t\t\tlo = mid+1;\n\t\t\t\t}\n\t\t\t\telse { //great\n\t\t\t\t\tres = mid;\n\t\t\t\t\tif(small) hi = mid-1;\n\t\t\t\t\telse lo = mid+1;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\n\t\tclass Event implements Comparable {\n\t\t\tint type, pos, val;\n\t\t\tEvent(int t, int p, int v) {\n\t\t\t\ttype = t; val = v;\n\t\t\t\tpos = p;\n\t\t\t}\n\t\t\tpublic int compareTo(Event e) {\n\t\t\t\tint comp = Integer.compare(pos, e.pos);\n\t\t\t\tif(comp == 0) comp = Integer.compare(e.type, type);\n\t\t\t\treturn comp;\n\t\t\t}\n\t\t\tpublic String toString() {\n\t\t\t\treturn String.format(\"Pos = %d Type = %d V = %d\", pos, type, val);\n\t\t\t}\n\t\t}\n\n\t\tint getIdx(int[] a, int i) {\n\t\t\tif(i >= 0 && i < a.length) return a[i];\n\t\t\treturn 0;\n\t\t}\n\n\t\tint[] zValues(String string) {\n\t\t\tint n = string.length(); char[] s = string.toCharArray();\n\t\t\tint[] z = new int[n]; z[0] = n;\n\t\t\tint L = 0, R = 0;\n\t\t\tint[] left = new int[n], right = new int[n];\n\t\t\tfor(int i = 1; i < n; ++i) {\n\t\t\t\tif(i > R) {\n\t\t\t\t\tL = R = i;\n\t\t\t\t\twhile(R < n && s[R-L] == s[R]) R++;\n\t\t\t\t\tz[i] = R - L; R--;\n\t\t\t\t} else {\n\t\t\t\t\tint k = i-L;\n\t\t\t\t\tif(z[k] < R-i+1) z[i] = z[k];\n\t\t\t\t\telse {\n\t\t\t\t\t\tL = i;\n\t\t\t\t\t\twhile(R < n && s[R-L] == s[R]) R++;\n\t\t\t\t\t\tz[i] = R - L; R--;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tleft[i] = L; right[i] = R;\n\t\t\t}\n\t\t\treturn z;\n\t\t}\n\n\n\t\tvoid add(TreeMap map, int x) {\n\t\t\tmap.put(x, map.getOrDefault(x, 0)+1);\n\t\t}\n\t\tvoid rem(TreeMap map, int x) {\n\t\t\tint fr = map.get(x)-1;\n\t\t\tif(fr == 0) map.remove(x);\n\t\t\telse map.put(x, fr);\n\t\t}\n\t}\n\t\n\tvoid doPrimes() {\n\t\tprimes = new boolean[200200];\n\t\tArrays.fill(primes, true);\n\t\tprimes[0] = primes[1] = false;\n\t\tfor(int i = 2; i < primes.length; i++) {\n\t\t\tif(!primes[i]) continue;\n\t\t\tfor(int j = i+i; j < primes.length; j += i) primes[j] = false;\n\t\t}\n\t}\n\t\n\tString reverse(String s) {\n\t\treturn new StringBuilder(s).reverse().toString();\n\t}\n\tint[] reverse(int[] a) {\n\t\tint n = a.length;\n\t\tint[] res = new int[n];\n\t\tfor(int i = 0, j = n-1; i < n; i++, j--) {\n\t\t\tres[i] = a[j];\n\t\t}\n\t\treturn res;\n\t}\n\n\tclass FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FastScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tst = new StringTokenizer(\"\");\n\t\t}\n\t\tString next() {\n\t\t\tif(st.hasMoreTokens()) return st.nextToken();\n\t\t\ttry { st = new StringTokenizer(br.readLine()); } catch (Exception e) {}\n\t\t\treturn next();\n\t\t}\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "757773091359f6e7f8fc85d16271e083", "src_uid": "bc839e9a025a5d83e2c85fb1e224c175", "difficulty": 3500.0} {"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.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author AlexFetisov\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskD_EgorAndCaves solver = new TaskD_EgorAndCaves();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskD_EgorAndCaves {\n public static final int MOD = (int)1e9 + 7;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int m = in.nextInt();\n\n if (m < 2) {\n out.println(0);\n return;\n }\n long[][] dp = new long[n+1][m+1];\n long[][] lastRow = new long[n+1][m+1];\n\n for (int width = 2; width <= m; ++width) {\n dp[0][width] = 1;\n }\n for (int row = 1; row < n; ++row) {\n for (int width = 2; width <= m; ++width) {\n dp[row][width] = 1;\n lastRow[row][width] = 0;\n for (int prevWidth = 2; prevWidth <= width; ++prevWidth) {\n dp[row][width] += (dp[row-1][prevWidth] * (width - prevWidth + 1)) % MOD;\n if (prevWidth < width) {\n lastRow[row][width] += (dp[row - 1][prevWidth] * (width - prevWidth + 1)) % MOD;\n }\n if (lastRow[row][width] >= MOD) {\n lastRow[row][width] -= MOD;\n }\n if (dp[row][width] >= MOD) {\n dp[row][width] -= MOD;\n }\n }\n }\n }\n\n long res = 0;\n for (int t = 0; t < n; ++t) {\n for (int width = 2; width <= m; ++width) {\n res += ((dp[t][width]) % MOD) * (m - width + 1) % MOD;\n if (res >= MOD) {\n res -= MOD;\n }\n res += ((dp[t][width] * lastRow[n - t - 1][width]) % MOD) * (m - width + 1) % MOD;\n if (res >= MOD) {\n res -= MOD;\n }\n }\n }\n out.println(res);\n }\n}\n\nclass InputReader {\n private BufferedReader reader;\n private StringTokenizer stt;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n }\n\n public String nextLine() {\n try {\n return reader.readLine();\n } catch (IOException e) {\n return null;\n }\n }\n\n public String nextString() {\n while (stt == null || !stt.hasMoreTokens()) {\n stt = new StringTokenizer(nextLine());\n }\n return stt.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(nextString());\n }\n\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "88846f88aa4616fa138053fbbdd7192f", "src_uid": "9ca1ad2fa16ca81e9ab5eba220b162c1", "difficulty": 2400.0} {"lang": "Java 7", "source_code": "import java.util.Map;\nimport java.io.IOException;\nimport java.util.HashMap;\nimport java.io.PrintStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Random;\nimport java.util.NoSuchElementException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author ogiekako\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\tMyScanner in = new MyScanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskC solver = new TaskC();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskC {\n long[] fib;\n Map map;\n\n public void solve(int testNumber, MyScanner in, PrintWriter out) {\n int t = in.nextInt();\n int n = in.nextInt();\n long[] u = new long[t];\n long[] v = new long[t];\n for (int i = 0; i < t; i++){\n u[i] = in.nextInt();\n v[i] = in.nextInt();\n }\n long[] res= solve(u,v,n);\n for(long r:res)out.println(r);\n }\n private long[] solve(long[] u, long[] v, int n){\n n = Math.min(n, 85);\n fib = new long[n + 1];\n for (int i = 0; i <= n; i++) {\n fib[i] = i <= 1 ? i + 1 : fib[i - 1] + fib[i - 2];\n }\n// map = new TreeMap();\n map = new HashMap();\n long[]res =new long[u.length];\n for (int i = 0; i < u.length; i++) {\n map.clear();\n if(i%1000==0) System.err.println(i);\n res[i] = solve(u[i],v[i],n);\n }\n return res;\n }\n\n class State implements Comparable {\n State(long i, long j, int n) {\n this.i = i;\n this.j = j;\n this.n = n;\n }\n\n long i, j;\n int n;\n\n public int compareTo(State o) {\n if (i != o.i) return Long.compare(i, o.i);\n if (j != o.j) return Long.compare(j, o.j);\n return Integer.compare(n, o.n);\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 State state = (State) o;\n\n if (i != state.i) return false;\n if (j != state.j) return false;\n if (n != state.n) return false;\n\n return true;\n }\n\n public int hashCode() {\n int result = (int) (i ^ (i >>> 32));\n result = 31 * result + (int) (j ^ (j >>> 32));\n result = 31 * result + n;\n return result;\n }\n }\n\n private long solve(long i, long j, int n) {\n if (i > j) return solve(j, i, n);\n if (j > fib[n]) throw new AssertionError();\n if (n == 0) return 0;\n if (n == 1) return i != j ? 1 : 0;\n State cur = new State(i, j, n);\n Long res = map.get(cur);\n if (res != null) return res;\n if (j <= fib[n - 1]) res = Math.min(\n solve(i, j, n - 1),\n Math.min(\n solve(i, 1, n - 1) + solve(j, fib[n - 1], n - 1) + 2,\n solve(i, fib[n - 1], n - 1) + solve(j, 1, n - 1) + 2\n )\n );\n else if (i <= fib[n - 1]) res = Math.min(\n solve(i, 1, n - 1) + solve(1, j - fib[n - 1], n - 2) + 1,\n solve(i, fib[n - 1], n - 1) + solve(1, j - fib[n - 1], n - 2) + 1\n );\n else res = solve(i - fib[n - 1], j - fib[n - 1], n - 2);\n map.put(cur, res);\n return res;\n }\n\n }\n\nclass MyScanner {\n private final InputStream in;\n public MyScanner(InputStream in){\n this.in = in;\n }\n\n public int nextInt(){\n\t\ttry{\n\t\t\tint c=in.read();\n\t\t\tif(c==-1) return c;\n\t\t\twhile(c!='-'&&(c<'0'||'9' asdf)\n\t\t\tval = fivepower(n-asdf, 1000000007);\n\t\tsp = br.readLine().split(\" \");\n\t\tint q = Integer.parseInt(sp[0]);\n\t\tfor (i = 0; i < q; i++)\t{\n\t\t\tsp = br.readLine().split(\" \");\n\t\t\tString t = sp[0];\n\t\t\tint[] result = new int[m];\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tresult[j] = (int) t.charAt(j) - 97;\n\t\t\t}\n\t\t\tfor (int k = 0; k < asdf; k++) {\n\t\t\t\tint u = result[firstnonzero[k]];\n\t\t\t\tfor (int l = firstnonzero[k]; l < m; l++) {\n\t\t\t\t\tresult[l] -= u*matrix[k][l]*matrix[k][firstnonzero[k]]*matrix[k][firstnonzero[k]]*matrix[k][firstnonzero[k]];\n\t\t\t\t\tresult[l] = (result[l]+2000)%5;\n\t\t\t\t}\n\t\t\t}\n\t\t\tboolean bool = true;\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tif (result[j] != 0)\n\t\t\t\t\tbool = false;\n\t\t\t}\n\t\t\tif (bool)\n\t\t\t\tSystem.out.println(val);\n\t\t\telse\n\t\t\t\tSystem.out.println(0);\n\t\t}\n\t\t\n\t\t\n\t}\n\t\n\tpublic static int fivepower(int n, int mod) {\n\t\tlong a = 5;\n\t\twhile (n > 0) {\n\t\t\tif (n%2 == 1) {\n\t\t\t\tn /= 2;\n\t\t\t\ta = (5*a*a)%mod;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tn /= 2;\n\t\t\t\ta = (a*a)%mod;\n\t\t\t}\n\t\t}\n\t\treturn (int) a;\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b48534a8ee651baa3bdbeda486f17d5d", "src_uid": "5cb18864c88b7fdec4a85718df67333e", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.awt.*;\nimport java.io.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.util.List;\n\nimport static java.lang.Math.max;\nimport static java.lang.Math.min;\n\n\npublic class C implements Runnable{\n\n // SOLUTION!!!\n // HACK ME PLEASE IF YOU CAN!!!\n // PLEASE!!!\n // PLEASE!!!\n // PLEASE!!!\n\n private final static Random rnd = new Random();\n private final static String fileName = \"\";\n\n private void solve() {\n int n = readInt();\n int[] a = readIntArray(n);\n\n Point minMax = getMinMax(a);\n\n int answer = a[minMax.y] ^ a[n - 1];\n out.println(answer);\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private final static boolean FIRST_INPUT_STRING = false;\n private final static boolean MULTIPLE_TESTS = true;\n private final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\n private final static int MAX_STACK_SIZE = 128;\n\n private final static boolean OPTIMIZE_READ_NUMBERS = false;\n\n /////////////////////////////////////////////////////////////////////\n\n public void run(){\n try{\n timeInit();\n Locale.setDefault(Locale.US);\n\n init();\n\n if (ONLINE_JUDGE) {\n solve();\n } else {\n do {\n try {\n timeInit();\n solve();\n time();\n\n out.println();\n } catch (NumberFormatException e) {\n break;\n } catch (NullPointerException e) {\n if (FIRST_INPUT_STRING) break;\n else throw e;\n }\n } while (MULTIPLE_TESTS);\n }\n\n out.close();\n time();\n }catch (Exception e){\n e.printStackTrace(System.err);\n System.exit(-1);\n }\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private BufferedReader in;\n private OutputWriter out;\n private StringTokenizer tok = new StringTokenizer(\"\");\n\n public static void main(String[] args){\n new Thread(null, new C(), \"\", MAX_STACK_SIZE * (1L << 20)).start();\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private void init() throws FileNotFoundException{\n Locale.setDefault(Locale.US);\n\n if (ONLINE_JUDGE){\n if (fileName.isEmpty()) {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new OutputWriter(System.out);\n } else {\n in = new BufferedReader(new FileReader(fileName + \".in\"));\n out = new OutputWriter(fileName + \".out\");\n }\n }else{\n in = new BufferedReader(new FileReader(\"input.txt\"));\n out = new OutputWriter(\"output.txt\");\n }\n }\n\n ////////////////////////////////////////////////////////////////\n\n private long timeBegin;\n\n private void timeInit() {\n this.timeBegin = System.currentTimeMillis();\n }\n\n private void time(){\n long timeEnd = System.currentTimeMillis();\n System.err.println(\"Time = \" + (timeEnd - timeBegin));\n }\n\n private void debug(Object... objects){\n if (ONLINE_JUDGE){\n for (Object o: objects){\n System.err.println(o.toString());\n }\n }\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private String delim = \" \";\n\n private String readLine() {\n try {\n return in.readLine();\n } catch (IOException e) {\n throw new RuntimeIOException(e);\n }\n }\n\n private String readString() {\n try {\n while(!tok.hasMoreTokens()){\n tok = new StringTokenizer(readLine());\n }\n\n return tok.nextToken(delim);\n } catch (NullPointerException e) {\n return null;\n }\n }\n\n /////////////////////////////////////////////////////////////////\n\n private final char NOT_A_SYMBOL = '\\0';\n\n private char readChar() {\n try {\n int intValue = in.read();\n\n if (intValue == -1){\n return NOT_A_SYMBOL;\n }\n\n return (char) intValue;\n } catch (IOException e) {\n throw new RuntimeIOException(e);\n }\n }\n\n private char[] readCharArray() {\n return readLine().toCharArray();\n }\n\n private char[][] readCharField(int rowsCount) {\n char[][] field = new char[rowsCount][];\n for (int row = 0; row < rowsCount; ++row) {\n field[row] = readCharArray();\n }\n\n return field;\n }\n\n /////////////////////////////////////////////////////////////////\n\n private long optimizedReadLong() {\n int sign = 1;\n long result = 0;\n boolean started = false;\n while (true) {\n try {\n int j = in.read();\n if (-1 == j) {\n if (started) return sign * result;\n throw new NumberFormatException();\n }\n\n if (j == '-') {\n if (started) throw new NumberFormatException();\n sign = -sign;\n }\n\n if ('0' <= j && j <= '9') {\n result = result * 10 + j - '0';\n started = true;\n } else if (started) {\n return sign * result;\n }\n } catch (IOException e) {\n throw new RuntimeIOException(e);\n }\n }\n }\n\n private int readInt() {\n\n if (!OPTIMIZE_READ_NUMBERS) {\n return Integer.parseInt(readString());\n } else {\n return (int) optimizedReadLong();\n }\n }\n\n private int[] readIntArray(int size) {\n int[] array = new int[size];\n\n for (int index = 0; index < size; ++index){\n array[index] = readInt();\n }\n\n return array;\n }\n\n private int[] readSortedIntArray(int size) {\n Integer[] array = new Integer[size];\n\n for (int index = 0; index < size; ++index) {\n array[index] = readInt();\n }\n Arrays.sort(array);\n\n int[] sortedArray = new int[size];\n for (int index = 0; index < size; ++index) {\n sortedArray[index] = array[index];\n }\n\n return sortedArray;\n }\n\n private int[] readIntArrayWithDecrease(int size) {\n int[] array = readIntArray(size);\n\n for (int i = 0; i < size; ++i) {\n array[i]--;\n }\n\n return array;\n }\n\n ///////////////////////////////////////////////////////////////////\n\n private int[][] readIntMatrix(int rowsCount, int columnsCount) {\n int[][] matrix = new int[rowsCount][];\n\n for (int rowIndex = 0; rowIndex < rowsCount; ++rowIndex) {\n matrix[rowIndex] = readIntArray(columnsCount);\n }\n\n return matrix;\n }\n\n private int[][] readIntMatrixWithDecrease(int rowsCount, int columnsCount) {\n int[][] matrix = new int[rowsCount][];\n\n for (int rowIndex = 0; rowIndex < rowsCount; ++rowIndex) {\n matrix[rowIndex] = readIntArrayWithDecrease(columnsCount);\n }\n\n return matrix;\n }\n\n ///////////////////////////////////////////////////////////////////\n\n private long readLong() {\n if (!OPTIMIZE_READ_NUMBERS) {\n return Long.parseLong(readString());\n } else {\n return optimizedReadLong();\n }\n }\n\n private long[] readLongArray(int size) {\n long[] array = new long[size];\n\n for (int index = 0; index < size; ++index){\n array[index] = readLong();\n }\n\n return array;\n }\n\n ////////////////////////////////////////////////////////////////////\n\n private double readDouble() {\n return Double.parseDouble(readString());\n }\n\n private double[] readDoubleArray(int size) {\n double[] array = new double[size];\n\n for (int index = 0; index < size; ++index){\n array[index] = readDouble();\n }\n\n return array;\n }\n\n ////////////////////////////////////////////////////////////////////\n\n private BigInteger readBigInteger() {\n return new BigInteger(readString());\n }\n\n private BigDecimal readBigDecimal() {\n return new BigDecimal(readString());\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private Point readPoint() {\n int x = readInt();\n int y = readInt();\n return new Point(x, y);\n }\n\n private Point[] readPointArray(int size) {\n Point[] array = new Point[size];\n\n for (int index = 0; index < size; ++index){\n array[index] = readPoint();\n }\n\n return array;\n }\n\n /////////////////////////////////////////////////////////////////////\n\n @Deprecated\n private List[] readGraph(int vertexNumber, int edgeNumber) {\n @SuppressWarnings(\"unchecked\")\n List[] graph = new List[vertexNumber];\n\n for (int index = 0; index < vertexNumber; ++index){\n graph[index] = new ArrayList<>();\n }\n\n while (edgeNumber-- > 0){\n int from = readInt() - 1;\n int to = readInt() - 1;\n\n graph[from].add(to);\n graph[to].add(from);\n }\n\n return graph;\n }\n\n private static class GraphBuilder {\n\n final int size;\n final List[] edges;\n\n static GraphBuilder createInstance(int size) {\n List[] edges = new List[size];\n for (int v = 0; v < size; ++v) {\n edges[v] = new ArrayList<>();\n }\n\n return new GraphBuilder(edges);\n }\n\n private GraphBuilder(List[] edges) {\n this.size = edges.length;\n this.edges = edges;\n }\n\n public void addEdge(int from, int to) {\n addDirectedEdge(from, to);\n addDirectedEdge(to, from);\n }\n\n public void addDirectedEdge(int from, int to) {\n edges[from].add(to);\n }\n\n public int[][] build() {\n int[][] graph = new int[size][];\n for (int v = 0; v < size; ++v) {\n List vEdges = edges[v];\n graph[v] = castInt(vEdges);\n }\n\n return graph;\n }\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static class IntIndexPair {\n\n static Comparator increaseComparator = new Comparator() {\n\n @Override\n public int compare(C.IntIndexPair indexPair1, C.IntIndexPair indexPair2) {\n int value1 = indexPair1.value;\n int value2 = indexPair2.value;\n\n if (value1 != value2) return value1 - value2;\n\n int index1 = indexPair1.index;\n int index2 = indexPair2.index;\n\n return index1 - index2;\n }\n };\n\n static Comparator decreaseComparator = new Comparator() {\n\n @Override\n public int compare(C.IntIndexPair indexPair1, C.IntIndexPair indexPair2) {\n int value1 = indexPair1.value;\n int value2 = indexPair2.value;\n\n if (value1 != value2) return -(value1 - value2);\n\n int index1 = indexPair1.index;\n int index2 = indexPair2.index;\n\n return index1 - index2;\n }\n };\n\n static IntIndexPair[] from(int[] array) {\n IntIndexPair[] iip = new IntIndexPair[array.length];\n for (int i = 0; i < array.length; ++i) {\n iip[i] = new IntIndexPair(array[i], i);\n }\n\n return iip;\n }\n\n int value, index;\n\n IntIndexPair(int value, int index) {\n super();\n this.value = value;\n this.index = index;\n }\n\n int getRealIndex() {\n return index + 1;\n }\n }\n\n private IntIndexPair[] readIntIndexArray(int size) {\n IntIndexPair[] array = new IntIndexPair[size];\n\n for (int index = 0; index < size; ++index) {\n array[index] = new IntIndexPair(readInt(), index);\n }\n\n return array;\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static class OutputWriter extends PrintWriter {\n\n final int DEFAULT_PRECISION = 12;\n\n private int precision;\n private String format, formatWithSpace;\n\n {\n precision = DEFAULT_PRECISION;\n\n format = createFormat(precision);\n formatWithSpace = format + \" \";\n }\n\n OutputWriter(OutputStream out) {\n super(out);\n }\n\n OutputWriter(String fileName) throws FileNotFoundException {\n super(fileName);\n }\n\n int getPrecision() {\n return precision;\n }\n\n void setPrecision(int precision) {\n precision = max(0, precision);\n this.precision = precision;\n\n format = createFormat(precision);\n formatWithSpace = format + \" \";\n }\n\n String createFormat(int precision){\n return \"%.\" + precision + \"f\";\n }\n\n @Override\n public void print(double d){\n printf(format, d);\n }\n\n void printWithSpace(double d){\n printf(formatWithSpace, d);\n }\n\n void printAll(double...d){\n for (int i = 0; i < d.length - 1; ++i){\n printWithSpace(d[i]);\n }\n\n print(d[d.length - 1]);\n }\n\n @Override\n public void println(double d){\n printlnAll(d);\n }\n\n void printlnAll(double... d){\n printAll(d);\n println();\n }\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static class RuntimeIOException extends RuntimeException {\n\n /**\n *\n */\n private static final long serialVersionUID = -6463830523020118289L;\n\n RuntimeIOException(Throwable cause) {\n super(cause);\n }\n }\n\n /////////////////////////////////////////////////////////////////////\n //////////////// Some useful constants and functions ////////////////\n /////////////////////////////////////////////////////////////////////\n\n private static final int[][] steps = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};\n private static final int[][] steps8 = {\n {-1, 0}, {1, 0}, {0, -1}, {0, 1},\n {-1, -1}, {1, 1}, {1, -1}, {-1, 1}\n };\n\n private static boolean checkCell(int row, int rowsCount, int column, int columnsCount) {\n return checkIndex(row, rowsCount) && checkIndex(column, columnsCount);\n }\n\n private static boolean checkIndex(int index, int lim){\n return (0 <= index && index < lim);\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static boolean checkBit(int mask, int bit){\n return (mask & (1 << bit)) != 0;\n }\n private static boolean checkBit(long mask, int bit){\n return (mask & (1L << bit)) != 0;\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static long getSum(int[] array) {\n long sum = 0;\n for (int value: array) {\n sum += value;\n }\n\n return sum;\n }\n\n private static Point getMinMax(int[] array) {\n int min = array[0];\n int max = array[0];\n\n for (int index = 0, size = array.length; index < size; ++index, ++index) {\n int value = array[index];\n\n if (index == size - 1) {\n min = min(min, value);\n max = max(max, value);\n } else {\n int otherValue = array[index + 1];\n\n if (value <= otherValue) {\n min = min(min, value);\n max = max(max, otherValue);\n } else {\n min = min(min, otherValue);\n max = max(max, value);\n }\n }\n }\n\n return new Point(min, max);\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static int[] getPrimes(int n) {\n boolean[] used = new boolean[n];\n used[0] = used[1] = true;\n\n int size = 0;\n for (int i = 2; i < n; ++i) {\n if (!used[i]) {\n ++size;\n for (int j = 2 * i; j < n; j += i) {\n used[j] = true;\n }\n }\n }\n\n int[] primes = new int[size];\n for (int i = 0, cur = 0; i < n; ++i) {\n if (!used[i]) {\n primes[cur++] = i;\n }\n }\n\n return primes;\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static long lcm(long a, long b) {\n return a / gcd(a, b) * b;\n }\n\n private static long gcd(long a, long b) {\n return (a == 0 ? b : gcd(b % a, a));\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static class MultiSet {\n\n public static MultiSet createMultiSet() {\n Map multiset = new HashMap<>();\n return new MultiSet<>(multiset);\n }\n\n private final Map multiset;\n private int size;\n\n public MultiSet(Map multiset) {\n this.multiset = multiset;\n this.size = 0;\n }\n\n public int size() {\n return size;\n }\n\n public void inc(ValueType value) {\n int count = get(value);\n multiset.put(value, count + 1);\n\n ++size;\n }\n\n public void dec(ValueType value) {\n int count = get(value);\n if (count == 0) return;\n\n if (count == 1) multiset.remove(value);\n else multiset.put(value, count - 1);\n\n --size;\n }\n\n public int get(ValueType value) {\n Integer count = multiset.get(value);\n return (count == null ? 0 : count);\n }\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static class IdMap extends HashMap {\n\n /**\n *\n */\n private static final long serialVersionUID = -3793737771950984481L;\n\n public IdMap() {\n super();\n }\n\n int getId(KeyType key) {\n Integer id = super.get(key);\n if (id == null) {\n super.put(key, id = size());\n }\n\n return id;\n }\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static int[] castInt(List list) {\n int[] array = new int[list.size()];\n for (int i = 0; i < array.length; ++i) {\n array[i] = list.get(i);\n }\n\n return array;\n }\n\n private static long[] castLong(List list) {\n long[] array = new long[list.size()];\n for (int i = 0; i < array.length; ++i) {\n array[i] = list.get(i);\n }\n\n return array;\n }\n\n /////////////////////////////////////////////////////////////////////\n\n /**\n * Generates list with values 0.. order(int n) {\n List sequence = new ArrayList<>();\n for (int i = 0; i < n; ++i) {\n sequence.add(i);\n }\n\n return sequence;\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1962aa6ab4d9a05fbe21ed654aa35173", "src_uid": "f45c769556ac3f408f5542fa71a67d98", "difficulty": 1800.0} {"lang": "Java 8", "source_code": "//package round588;\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 E1 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tint Q;\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni();\n\t\tint[][] ps = new int[n][];\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tps[i] = na(n);\n\t\t}\n\t\t\n\t\tif(n % 2 == 1){\n\t\t\tn++;\n\t\t\tint[][] nps = new int[n][n];\n\t\t\tnps[n-1][n-1] = 100;\n\t\t\tfor(int i = 0;i < n-1;i++){\n\t\t\t\tfor(int j = 0;j < n-1;j++){\n\t\t\t\t\tnps[i][j] = ps[i][j];\n\t\t\t\t}\n\t\t\t}\n\t\t\tps = nps;\n\t\t}\n\t\t\n\t\tif(n == 6)Q = 20;\n\t\tif(n == 4)Q = 6;\n\t\tif(n == 2)Q = 2;\n\t\t\n\t\tlong ih = invl(100, mod);\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tfor(int j = 0;j < n;j++){\n\t\t\t\tps[i][j] = (int)(ps[i][j] * ih % mod);\n\t\t\t}\n\t\t}\n\t\t\n\t\tint h = n/2;\n\t\tlong[] l = go(Arrays.copyOfRange(ps, 0, h));\n\t\tlong[] r = go(Arrays.copyOfRange(ps, h, n));\n\t\tlong[] nl = new long[l.length];\n\t\tfor(int i = 0;i < l.length;i++){\n\t\t\tint ii = i;\n\t\t\tfor(int j = 0, k = Q-1;j < k;j++,k--){\n\t\t\t\tif((i>>>j&1) != (i>>>k&1)){\n\t\t\t\t\tii ^= 1< 0) {\n\t\t\tlong c = a / b;\n\t\t\tlong d;\n\t\t\td = a;\n\t\t\ta = b;\n\t\t\tb = d % b;\n\t\t\td = p;\n\t\t\tp = q;\n\t\t\tq = d - c * q;\n\t\t}\n\t\treturn p < 0 ? p + mod : p;\n\t}\n\n\t\n\tpublic long[] zetaTransform(long[] f)\n\t{\n\t\tint H = Integer.numberOfTrailingZeros(f.length);\n\t\tfor(int i = 0;i < H;i++){\n\t\t\tfor(int j = 0;j < 1<=0){\n\t\t\t\t\tf[j] += f[j|1<= mod)f[j] -= mod;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn f;\n\t}\n\t\n\tpublic long[] inverseZetaTransform(long[] f)\n\t{\n\t\tint H = Integer.numberOfTrailingZeros(f.length);\n\t\tfor(int i = 0;i < H;i++){\n\t\t\tfor(int j = 0;j < 1<=0){\n\t\t\t\t\tf[j] -= f[j|1<=0)continue inner;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tptn |= 1<= mod)l[ptn] -= mod;\n\t\t}\n\t\treturn l;\n\t}\n\t\n\tpublic static int[] toArray(long x)\n\t{\n\t\tint[] ret = new int[5];\n\t\tint p = 0;\n\t\tfor(;x != 0;x &= x-1){\n\t\t\tret[p++] = Long.numberOfTrailingZeros(x);\n\t\t}\n\t\treturn Arrays.copyOf(ret, p);\n\t}\n\t\n\tpublic static boolean nextPermutation(int[] a) {\n\t\tint n = a.length;\n\t\tint i;\n\t\tfor (i = n - 2; i >= 0 && a[i] >= a[i + 1]; i--)\n\t\t\t;\n\t\tif (i == -1)\n\t\t\treturn false;\n\t\tint j;\n\t\tfor (j = i + 1; j < n && a[i] < a[j]; j++)\n\t\t\t;\n\t\tint d = a[i];\n\t\ta[i] = a[j - 1];\n\t\ta[j - 1] = d;\n\t\tfor (int p = i + 1, q = n - 1; p < q; p++, q--) {\n\t\t\td = a[p];\n\t\t\ta[p] = a[q];\n\t\t\ta[q] = d;\n\t\t}\n\t\treturn true;\n\t}\n\n\t\n\tvoid run() throws Exception\n\t{\n//\t\tint n = 6, m = 99999;\n//\t\tRandom gen = new Random();\n//\t\tStringBuilder sb = new StringBuilder();\n//\t\tsb.append(n + \" \");\n//\t\tfor (int i = 0; i < n*n; i++) {\n//\t\t\tsb.append(i + \" \");\n//\t\t}\n//\t\tINPUT = sb.toString();\n\n\t\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 E1().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", "compilation_error": false, "code_uid": "c9a12174c4910ae9e1e60b5bb186fa87", "src_uid": "906d4e49566e63fddaf8eac7384c6284", "difficulty": 3100.0} {"lang": "Java 8", "source_code": "\nimport java.io.*;\nimport java.lang.reflect.Array;\nimport java.math.*;\nimport java.text.DecimalFormat;\nimport java.util.*;\n\n\n\n\npublic class Main {\n\n private static int [] A,pref;\n private static int [] [] W;\n private static int n;\n private static Integer [] [] [] [] dp;\n\n private static int getLeft(int lev,int scale) {\n return scale;\n }\n private static int getRight(int lev,int scale) {\n return scale + lev;\n }\n private static int solve(int lev,int scale,int l,int r) {\n l = Math.max(l,getLeft(lev,scale));\n r = Math.min(r,getRight(lev,scale));\n if (l > r) return 0;\n if (lev == 0) return (A[scale] >= W[lev][scale]) ? A[scale] : 0;\n if (dp[lev][scale][l][r] != null) return dp[lev][scale][l][r];\n int ret = 0;\n for (int k = l-1;k <= r;k++)\n ret = Math.max(ret ,solve(lev-1,scale,l,k) + solve(lev-1,scale+1,k+1,r));\n if (ret < W[lev][scale]) ret = 0;\n return dp[lev][scale][l][r] = ret;\n }\n public static void main(String[] args) throws Exception{\n IO io = new IO(null,null);\n n = io.getNextInt();\n A = new int[n];\n pref = new int[n+1];\n W = new int[n][n];\n dp = new Integer[n][n][n][n];\n for (int i = 0;i < n;i++) {\n A[i] = io.getNextInt();\n pref[i + 1] = pref[i] + A[i];\n }\n for (int i = 0;i < n;i++)\n for (int j = 0;j < n-i;j++)\n W[i][j] = io.getNextInt();\n\n if (solve(n-1,0,0,n-1) != 0) io.println(\"Cerealguy\");\n else io.println(\"Fat Rat\");\n io.close();\n }\n}\n\n\n\nclass IO{\n private BufferedReader br;\n private StringTokenizer st;\n private PrintWriter writer;\n private String inputFile,outputFile;\n\n public boolean hasMore() throws IOException{\n if(st != null && st.hasMoreTokens()) return true;\n if(br != null && br.ready()) return true;\n return false;\n }\n public String getNext() throws FileNotFoundException, IOException{\n while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n public String getNextLine() throws FileNotFoundException, IOException{\n return br.readLine().trim();\n }\n\n public int getNextInt() throws FileNotFoundException, IOException{\n return Integer.parseInt(getNext());\n }\n public long getNextLong() throws FileNotFoundException, IOException{\n return Long.parseLong(getNext());\n }\n\n public void print(double x,int num_digits) throws IOException{\n writer.printf(\"%.\" + num_digits + \"f\" ,x);\n }\n public void println(double x,int num_digits) throws IOException{\n writer.printf(\"%.\" + num_digits + \"f\\n\" ,x);\n }\n public void print(Object o) throws IOException{\n writer.print(o.toString());\n }\n\n public void println(Object o) throws IOException{\n writer.println(o.toString());\n }\n public IO(String x,String y) throws FileNotFoundException, IOException{\n inputFile = x;\n outputFile = y;\n if(x != null) br = new BufferedReader(new FileReader(inputFile));\n else br = new BufferedReader(new InputStreamReader(System.in));\n if(y != null) writer = new PrintWriter(new BufferedWriter(new FileWriter(outputFile)));\n else writer = new PrintWriter(new OutputStreamWriter(System.out));\n }\n\n protected void close() throws IOException{\n br.close();\n writer.close();\n }\n public void outputArr(Object [] A) throws IOException{\n int L = A.length;\n for (int i = 0;i < L;i++) {\n if(i > 0) writer.print(\" \");\n writer.print(A[i]);\n }\n writer.print(\"\\n\");\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7a7267c1214035ddc9b90cf284917c1d", "src_uid": "0a77937c01ac69490f8b478eae77de1d", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF1202F extends PrintWriter {\n\tCF1202F() { super(System.out, true); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1202F o = new CF1202F(); o.main(); o.flush();\n\t}\n\n\tvoid main() {\n\t\tint a = sc.nextInt();\n\t\tint b = sc.nextInt();\n\t\tif (a > b) {\n\t\t\tint tmp = a; a = b; b = tmp;\n\t\t}\n\t\tint ab = a + b;\n\t\tdouble x = (double) a / ab;\n\t\tint upper = 10000000;\n\t\tif (upper > ab)\n\t\t\tupper = ab;\n\t\tint ans = ab - upper;\n\t\tfor (int cd = 2; cd <= upper; cd++) {\n\t\t\tint c = (int) (cd * x + 0.5);\n\t\t\tif (c == 0)\n\t\t\t\tc = 1;\n\t\t\tint d = cd - c;\n\t\t\tif (d > b)\n\t\t\t\tcontinue;\n\t\t\tint k = a / c, l = b / d;\n\t\t\tif (k == l || k == l + 1 && a % c == 0 || k == l - 1 && b % d == 0)\n\t\t\t\tans++;\n\t\t}\n\t\tprintln(ans);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "29f0145af82ac383c00d82a6070a6012", "src_uid": "0e6a204565fef118ea99d2fa1e378dd0", "difficulty": 2700.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.LinkedList;\nimport java.util.Locale;\nimport java.util.Queue;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\npublic class Solution implements Runnable {\n\t\n\tpublic static void main(String[] args) {\n\t\t(new Thread(new Solution())).start();\n\t}\n\t\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st;\n\t\n\tString nextToken() throws IOException {\n\t\twhile (st == null || !st.hasMoreTokens()) st = new StringTokenizer(in.readLine());\n\t\treturn st.nextToken();\n\t}\n\t\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\t\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\t\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\t\n\tBigInteger nextBigInteger() throws IOException {\n\t\treturn new BigInteger(nextToken());\n\t}\n\t\n\tclass Point {\n\t\tint x, y;\n\t\tPoint(int a, int b) {\n\t\t\tx = a; y = b;\n\t\t}\n\t}\n\t\n\tPoint[] a;\n\t\n\tdouble dist(int q, int w) {\n\t\treturn Math.sqrt((double)(a[q].x - a[w].x) * (a[q].x - a[w].x) + (double)(a[q].y - a[w].y) * (a[q].y - a[w].y));\n\t}\n\t\n\tvoid solve() throws Exception {\n\t\tint n = nextInt();\n\t\tint k = nextInt() - 1;\n\t\ta = new Point[n + 1];\n\t\tfor (int i = 0; i < n; i++) a[i] = new Point(nextInt(), 0);\n\t\ta[n] = new Point(nextInt(), nextInt());\n\t\tint kk = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (a[i].x < a[k].x) kk++;\n\t\t}\n\t\tif (k < n) k = kk;\n\t\tArrays.sort(a, 0, n, new Comparator() {\n\t\t\tpublic int compare(Point o1, Point o2) {\n\t\t\t\treturn o1.x - o2.x;\n\t\t\t}\n\t\t});\n\t\tdouble ans;\n\t\tif (k == n) {\n\t\t\tans = Math.min(dist(0, n), dist(n - 1, n)) + dist(0, n - 1);\n\t\t} else {\n\t\t\tdouble qq;\n\t\t\tif (n > 1) {\n\t\t\t\tqq = dist(0, n) + dist(1, n) - dist(0, 1);\n\t\t\t\tfor (int i = 1; i < n - 1; i++) {\n\t\t\t\t\tif (dist(i, n) + dist(i + 1, n) - dist(i, i + 1) < qq) qq = dist(i, n) + dist(i + 1, n) - dist(i, i + 1);\n\t\t\t\t}\n\t\t\t} else qq = dist(0, 1);\n\t\t\tqq += dist(0, n - 1);\n\t\t\tans = Math.min(dist(0, k), dist(n - 1, k)) + qq;\n\t\t\tif (k < n - 1) {\n\t\t\t\tdouble tmp = dist(0, k) + dist(0, n) + Math.min(dist(n, k + 1), dist(n - 1, n)) + dist(k + 1, n - 1);\n\t\t\t\tans = Math.min(ans, tmp);\n\t\t\t}\n\t\t\tif (k > 0) {\n\t\t\t\tdouble tmp = dist(n - 1, k) + dist(n - 1, n) + Math.min(dist(n, k - 1), dist(0, n)) + dist(k - 1, 0);\n\t\t\t\tans = Math.min(ans, tmp);\n\t\t\t}\n\t\t\tans = Math.min(ans, dist(0, n - 1) + Math.min(dist(k, 0) + dist(n - 1, n), dist(k, n - 1) + dist(0, n)));\n\t\t}\n\t\tout.printf(\"%.7f\", ans);\n\t}\n\t \n\tpublic void run() {\n\t\ttry {\n\t\t\tLocale.setDefault(Locale.US);\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n//\t\t\tin = new BufferedReader(new FileReader(new File(\"input.txt\")));\n//\t\t\tout = new PrintWriter(\"output.txt\");\n\t\t\tsolve();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t\tout.flush();\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "56ea05b6ad18b044dba12f7aaa30a309", "src_uid": "f9ed5faca211e654d9d4e0a7557616f4", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.HashMap;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.util.Map;\nimport java.util.Map.Entry;\nimport java.io.BufferedReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n AmusementPark solver = new AmusementPark();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class AmusementPark {\n int[] prefMask = new int[20];\n int MOD = 988244353;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int N = in.nextInt();\n int M = in.nextInt();\n boolean[][] connect = new boolean[N][N];\n int[] linked = new int[N];\n for (int i = 0; i < prefMask.length; i++) {\n prefMask[i] = (1 << i) - 1;\n }\n int[] base = new int[N];\n for (int i = 0; i < N; i++) {\n base[i] = i;\n }\n for (int i = 0; i < M; i++) {\n int a = in.nextInt() - 1;\n int b = in.nextInt() - 1;\n linked[a] |= (1 << b);\n linked[b] |= (1 << a);\n connect[a][b] = true;\n }\n CountMap[] maps = new CountMap[(1 << N)];\n for (int i = 0; i < (1 << N); i++) {\n maps[i] = new CountMap();\n }\n maps[0].add((1 << N) - 1, 1);\n long ans = 0;\n for (int i = 0; i < (1 << N); i++) {\n for (Map.Entry mask : maps[i].count.entrySet()) {\n int nmask = 0;\n for (int j = 0; j < N; j++) {\n if (isSet(mask.getKey(), j)) {\n maps[i | (1 << j)].add(nmask | ((~i) & (linked[j])), mask.getValue());\n nmask |= (1 << j);\n }\n }\n ans = Math.max(ans, mask.getValue());\n }\n }\n out.println(((ans * MathUtils.inverse(2, MOD) % MOD) * M) % MOD);\n }\n\n boolean isSet(int mask, int bit) {\n return ((mask & (1 << bit)) > 0);\n }\n\n class CountMap {\n HashMap count = new HashMap<>();\n\n void add(int val, int c) {\n Integer x = count.putIfAbsent(val, c);\n if (x != null) {\n x += c;\n while (x >= MOD) {\n x -= MOD;\n }\n count.replace(val, x);\n }\n }\n\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String 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 static class MathUtils {\n public static long inverse(long a, long mod) {\n long[] inv = extended_gcd(a, mod);\n if (inv[0] != 1) {\n return 0;\n } else {\n return (inv[1] + 2 * mod) % mod;\n }\n }\n\n public static long[] extended_gcd(long a, long b) {\n //three numbers, first is gcd, second is x, third is y\n if (a == 0) {\n return new long[]{b, 0, 1};\n }\n long[] next = extended_gcd(b % a, a);\n long tempX = next[1];\n next[1] = next[2] - (b / a) * next[1];\n next[2] = tempX;\n return next;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5b2dac21075f27af20788ad29e12d580", "src_uid": "ed962f0ef1a1a92cdaeee06c508f8c10", "difficulty": null} {"lang": "Java 7", "source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.Comparator;\nimport java.util.SortedSet;\nimport java.util.TreeSet;\n\npublic class E {\n\n\n static class cup {\n int x, i, i0;\n \n cup(int i, int i0) {\n this.i=i; this.i0=i0;\n }\n }\n \n static cup find_cup(TreeSet t, int y, int lo, int hi) {\n cup aux=new cup(0, 0);\n while(lo<=hi) {\n int mid=(lo+hi)>>1;\n aux.i=mid;\n SortedSet sub=t.headSet(aux);\n if(sub.size()==y) {\n return sub.last();\n } else if(sub.size() t=new TreeSet(new Comparator() {\n public int compare(cup o1, cup o2) {\n return o1.i-o2.i;\n }\n });\n \n for (int i=0; i0&&c.x!=x) {\n System.out.println(\"-1\");\n return;\n } else {\n c.x=x;\n }\n t.remove(c);\n c.i=m-i;\n t.add(c);\n }\n \n int[] out=new int[n];\n boolean[] b=new boolean[n+1]; int j=1;\n for (cup c: t) {\n if(c.x==0) {\n while(b[j]) {\n j++;\n }\n c.x=j;\n }\n if(b[c.x]) {\n System.out.println(\"-1\");\n return;\n }\n b[c.x]=true;\n out[c.i0]=c.x;\n }\n \n StringBuilder sb=new StringBuilder();\n for (int i=0; i 0 && i>0 && mas[i-1][j] == 0) ? 1 : 0;\n masD[i][j] = (mas[i][j] > 0 && i 0 && j>0 && mas[i][j-1] == 0) ? 1 : 0;\n masR[i][j] = (mas[i][j] > 0 && i> i) & 1));\n }\n }\n \n void print() {\n for(int i = 0; i 0)?1:0)<=0; j--) {\n\n int need = (1 << 31) & mas[i*msize + j];\n mas[i*msize + j] <<= 1;\n mas[i*msize + j] |= take;\n take = need > 0 ? 1 : 0;\n }\n }\n return this;\n }\n\n bitmas shiftRight() {\n for(int i = 0; i>= 1;\n mas[i*msize + j] |= (take << 31);\n take = need > 0 ? (1 << 31) : 0;\n }\n }\n return this;\n }\n\n bitmas shiftDown() {\n for(int j = 0; j=0; i--) {\n int last = (mas[i*msize + j]);\n mas[i*msize + j] = take;\n take = last;\n }\n }\n\n return this;\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d3228c718c56e57c7dcf54edae6d6bf8", "src_uid": "70ab617d9b8813ddf3039c6fb137d817", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n/**\n * @author Don Li\n */\npublic class DZYLovesFFT {\n \n int n, d, x;\n int[] a, b;\n \n void solve() {\n n = in.nextInt();\n d = in.nextInt();\n x = in.nextInt();\n a = new int[n];\n b = new int[n];\n \n initAB();\n \n int[] inv = new int[n + 1];\n for (int i = 0; i < n; i++) inv[a[i]] = i;\n \n int[] pos = new int[d];\n for (int i = 0, j = 0; i < n; i++) if (b[i] > 0) pos[j++] = i;\n \n int s = 30;\n \n for (int i = 0; i < n; i++) {\n int ans = 0;\n for (int v = n; v >= n - s; v--) {\n if (v > 0 && inv[v] <= i && b[i - inv[v]] > 0) {\n ans = v;\n break;\n }\n }\n if (ans == 0) {\n for (int j = 0; j < d && pos[j] <= i; j++) {\n ans = Math.max(ans, a[i - pos[j]]);\n }\n }\n out.println(ans);\n }\n }\n \n int getNextX() {\n x = (int) ((x * 37L + 10007) % 1000000007);\n return x;\n }\n \n void initAB() {\n for (int i = 0; i < n; i = i + 1) {\n a[i] = i + 1;\n }\n for (int i = 0; i < n; i = i + 1) {\n swap(a, i, getNextX() % (i + 1));\n }\n for (int i = 0; i < n; i = i + 1) {\n if (i < d)\n b[i] = 1;\n else\n b[i] = 0;\n }\n for (int i = 0; i < n; i = i + 1) {\n swap(b, i, getNextX() % (i + 1));\n }\n }\n \n void swap(int[] a, int i, int j) {\n int tmp = a[i];\n a[i] = a[j];\n a[j] = tmp;\n }\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 DZYLovesFFT().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", "compilation_error": false, "code_uid": "5c321e7715bb1159792f86f4d765bd90", "src_uid": "948ae7a0189ada07c8c67a1757f691f0", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\npublic class Solution {\n static final FS sc = new FS();\n static final PrintWriter pw = new PrintWriter(System.out);\n static int alp = 20;\n static List> G;\n public static void main(String[] args) {\n int t = sc.nextInt();\n while (t-- > 0) {\n int n = sc.nextInt();\n char[] a = sc.next().toCharArray();\n char[] b = sc.next().toCharArray();\n G = new ArrayList<>();\n for(int i = 0;i < alp;i++) {\n G.add(new ArrayList<>());\n }\n int[] adj = new int[alp];\n for(int i = 0;i < n;i++) {\n if (a[i] != b[i]) {\n G.get(a[i] - 'a').add(b[i] - 'a');\n G.get(b[i] - 'a').add(a[i] - 'a');\n adj[a[i] - 'a'] |= 1 << (b[i] - 'a');\n }\n }\n int components = 0;\n boolean[] vis = new boolean[alp];\n for (int i = 0;i < alp;i++) {\n if (!vis[i]) {\n dfs(i, vis);\n components++;\n }\n }\n int ans = 0;\n boolean[] dp = new boolean[1 << alp];\n dp[0] = true;\n for (int mask = 0;mask < 1 << alp;mask++) {\n if (dp[mask]) {\n ans = Math.max(ans, Integer.bitCount(mask));\n for (int u = 0;u < alp;u++) {\n if ((~mask >> u & 1) == 1 && (adj[u] & mask) == 0) {\n dp[mask | 1 << u] = true;\n }\n }\n }\n }\n pw.println(2 * alp - components - ans);\n }\n pw.flush();\n }\n\n private static void dfs(int u, boolean[] vis) {\n vis[u] = true;\n for (Integer v : G.get(u)) {\n if (!vis[v]) {\n dfs(v, vis);\n }\n }\n }\n\n static class FS {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer st = new StringTokenizer(\"\");\n String next() {\n while(!st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch(Exception ignored) {}\n }\n return st.nextToken();\n }\n int[] nextArray(int n) {\n int[] a = new int[n];\n for(int i = 0;i < n;i++) {\n a[i] = nextInt();\n }\n return a;\n }\n int nextInt() {\n return Integer.parseInt(next());\n }\n long nextLong() {\n return Long.parseLong(next());\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "93ef04a899f9dd0cf272a7cdadc10bda", "src_uid": "d0735a763e2a40bfc94085019cd646f0", "difficulty": 3100.0} {"lang": "Java 8", "source_code": "public class CodeForces1April2019E {\n public static void main(String[] args) {\n for (int i = 0; i < 5; i++) {\n// System.out.print(\"0\\n1\\n1\\n0\\n1\\n0\\n\");\n System.out.print(\"1\\n0\\n0\\n1\\n1\\n0\\n\");\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "be453540734f80624b92cd14865a4ac7", "src_uid": "4bda04e64ff661336a93464563f1b550", "difficulty": null} {"lang": "Java 7", "source_code": "\nimport java.util.*;\nimport java.io.*;\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 (System.out);\n\t\tTaskD solver = new TaskD();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskD {\n\tint[][] ans;\n\tint tot;\n\tclass Line {\n\t\tint a,b,c,id;\n\t};\n\t\n\tpublic void solve (int TestNumber, InputReader in, PrintWriter out) {\n\t\tint n = in.nextInt();\n\t\tint k = in.nextInt();\n\t\tLine[] road = new Line[n];\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\troad[i] = new Line();//initialize is necessary\n\t\t\troad[i].a = in.nextInt();\n\t\t\troad[i].b = in.nextInt();\n\t\t\troad[i].c = in.nextInt();\n\t\t\troad[i].id = i+1;\n\t\t}\n\t\tans = new int[k][2];\n\t\ttot = -1;\n\t\tcalc(road, k);\n\t\tif (tot == -1) {\n\t\t\tout.println(\"NO\");\n\t\t\treturn;\n\t\t}\n\t\tout.println(\"YES\");\n\t\tout.println(k-tot);\n\t\tfor (int i = tot; i < k; ++i) {\n\t\t\tout.println(ans[i][0] + \" \" + ans[i][1]);\n\t\t}\n\t}\n\t//Java \u7279\u70b9\uff0c\u6709\u4e86.length,\u5c31\u4e0d\u7528\u8bb0\u5f55\u6570\u7ec4\u957f\u5ea6\u4e86\uff1b\u6709\u4e86for each: \u5c31\u4e0d\u7528\u679a\u4e3e\u4e0b\u6807\u4e86\n\tprivate void calc(Line[] road, int k) {\n\t\tif (road.length > k*k) {\n\t\t\tif (k == 0) return;\n\t\t\tdouble pr = 1.0 - getPr(road.length,k);\n\t\t\tint cnt = 1;\n\t\t\tdouble s = pr;\n\t\t\twhile (s > 1e-10) {\n\t\t\t\t++cnt;\n\t\t\t\ts *= pr;\n\t\t\t}\n\t\t\tRandom rand = new Random(19950315L + System.currentTimeMillis());\n\t\t\tfor ( ;cnt > 0; --cnt) {\n\t\t\t\tLine p = road[rand.nextInt(road.length)];\n\t\t\t\tLine q = road[rand.nextInt(road.length)];\n\t\t\t\tint denom = p.a*q.b-p.b*q.a;\n\t\t\t\tif (denom == 0) continue;\n\t\t\t\tint x = -(p.c*q.b-p.b*q.c);\n\t\t\t\tint y = -(p.a*q.c-p.c*q.a);\n\t\t\t\t\n\t\t\t\tint num = 0;\n\t\t\t\tfor (Line r : road) {\n\t\t\t\t\tif (r.a*x+r.b*y+r.c*denom == 0) ++num;\n\t\t\t\t}\n\t\t\t\tif (num > k) {\n\t\t\t\t\tans[k-1][0] = p.id; \n\t\t\t\t\tans[k-1][1] = q.id;\n\t\t\t\t\tint t_tot = 0;\n\t\t\t\t\tLine[] n_road = new Line[road.length - num];\n\t\t\t\t\tfor (Line r : road) {\n\t\t\t\t\t\tif (r.a*x+r.b*y+r.c*denom != 0) {\n\t\t\t\t\t\t\tn_road[t_tot++] = r;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tcalc(n_road, k-1);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse if (road.length == 0) {\n\t\t\ttot = k;\n\t\t}\n\t\telse {\n\t\t\tRandom rand = new Random(19950315L + System.currentTimeMillis());\n\t\t\tLine p = road[rand.nextInt(road.length)];\n\t\t\tboolean[] mark = new boolean[road.length];\n\t\t\tArrays.fill(mark, false);\n\t\t\tboolean any = false;\n\t\t\tfor (int i = 0; i < road.length; ++i) {\n\t\t\t\tif (mark[i]) continue;\n\t\t\t\tLine q = road[i];\n\t\t\t\tint denom = p.a*q.b-p.b*q.a;\n\t\t\t\tif (denom == 0) continue;\n\t\t\t\tany = true;\n\t\t\t\tint x = -(p.c*q.b-p.b*q.c);\n\t\t\t\tint y = -(p.a*q.c-p.c*q.a);\n\t\t\t\t\n\t\t\t\tint num = 0;\n\t\t\t\tfor (int j = 0; j < road.length; ++j) {\n\t\t\t\t\tLine r = road[j];\n\t\t\t\t\tif (r.a*x+r.b*y+r.c*denom == 0) {\n\t\t\t\t\t\t++num;\n\t\t\t\t\t\tmark[j] = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tLine[] n_road = new Line[road.length - num];\n\t\t\t\tans[k-1][0] = p.id; \n\t\t\t\tans[k-1][1] = q.id;\n\t\t\t\tint n_tot = 0;\n\t\t\t\tfor (Line r : road) {\n\t\t\t\t\tif (r.a*x+r.b*y+r.c*denom != 0) {\n\t\t\t\t\t\tn_road[n_tot++] = r;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcalc(n_road, k-1);\n\t\t\t\tif (tot > -1) return;\n\t\t\t}\n\t\t\tif (!any) {\n\t\t\t\tans[k-1][0] = p.id; \n\t\t\t\tans[k-1][1] = -1;\n\t\t\t\tLine[] n_road = new Line[road.length - 1];\n\t\t\t\tint n_tot = 0;\n\t\t\t\tfor (Line r : road) {\n\t\t\t\t\tif (r != p) {\n\t\t\t\t\t\tn_road[n_tot++] = r;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcalc(n_road, k-1);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tprivate double getPr(int n, int k) {\n\t\tlong ret = Long.MAX_VALUE;\n\t\tfor (int small = 0; small < k; ++small) {\n\t\t\tint rem = n - small * k;\n\t\t\tint big = k - small; \t\n\t\t\tlong pair = 0;\n\t\t\tfor (int id = 0; id < big; ++id) {\n\t\t\t\tlong size = rem / big;//size \u5f97 long\u4e0d\u80fd int\n\t\t\t\tif (rem % big > id) ++size;\n\t\t\t\tpair += size*(size-1);\n\t\t\t}\n\t\t\tret = Math.min(ret, pair);\n\t\t}\n\t\treturn (double)ret/n/n;\n\t}\n}\n\nclass InputReader {\n\tBufferedReader reader;\n\tStringTokenizer tokenizer;\n\t\n\tpublic InputReader (InputStream stream) {\n\t\treader = new BufferedReader (new InputStreamReader(stream), 32768);\n\t\ttokenizer = null;\n\t}\n\t\n\tpublic String next() {\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\ttokenizer = new StringTokenizer (reader.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException (e);\n\t\t\t}\n\t\t}\n\t\treturn tokenizer.nextToken();\n\t}\n\t\n\tpublic int nextInt() {\n\t\treturn Integer.parseInt(next());\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "7553c63dd4534db3278ae87b4d4b470b", "src_uid": "dea5c9eded04f1a900c37571d20b34e2", "difficulty": 2800.0} {"lang": "Java 6", "source_code": "import java.math.BigInteger;\nimport java.util.*;\n\npublic class Main {\n static final int MOD = 1000000007;\n\n public static int count(int height , int width) {\n boolean[][] field = new boolean[height][width];\n int[][][][] res = new int[2][2][width][width];\n int tR = 0;\n for (int row = 0; row < height; ++row) {\n int[][][][] newRes = new int[2][2][width][width];\n for (int fD = 0; fD < 2; ++fD)\n for (int lD = 0; lD < 2; ++lD)\n for (int fC = 0; fC < width; ++fC)\n for (int lC = fC; lC < width; ++lC) {\n int cur = res[fD][lD][fC][lC];\n if (cur == 0) continue;\n for (int newfD = fD; newfD < 2; ++newfD)\n for (int newlD = lD; newlD < 2; ++newlD) {\n int newfC;\n if (newfD == 0)\n newfC = fC;\n else if (fD == 0)\n newfC = fC + 1;\n else\n newfC = fC;\n int nL;\n if (newlD == 0)\n nL = lC;\n else if (lD == 0)\n nL = lC - 1;\n else\n nL = lC;\n if (newfC > nL)\n continue;\n int[] arr = newRes[newfD][newlD][newfC];\n arr[nL] += cur;\n if (arr[nL] >= MOD) arr[nL] -= MOD;\n }\n }\n\n for (int fD = 0; fD < 2; ++fD)\n for (int lD = 0; lD < 2; ++lD) {\n int[][] arr = newRes[fD][lD];\n if (fD == 0 && lD == 1) {\n {\n int lD = lD == 0 ? 1 : -1;\n int lastMin = lD == 1 ? 0 : width - 1;\n int lastMax = lD == 1 ? width : -1;\n for (int lC = lastMin; lC != lastMax; lC += lD) {\n for (int fC = 0; fC <= lC; ++fC) {\n int cur = arr[fC][lC];\n if (cur == 0) continue;\n int nL = lC + lD;\n if (nL >= fC && nL < width) {\n arr[fC][nL] += cur;\n if (arr[fC][nL] >= MOD) arr[fC][nL] -= MOD;\n }\n }\n }\n }\n {\n int fD = fD == 0 ? -1 : 1;\n int fM = fD == 1 ? 0 : width - 1;\n int firstMax = fD == 1 ? width : -1;\n for (int fC = fM; fC != firstMax; fC += fD) {\n for (int lC = fC; lC < width; ++lC) {\n int cur = arr[fC][lC];\n if (cur == 0) continue;\n int newfC = fC + fD;\n if (newfC >= 0 && newfC <= lC) {\n arr[newfC][lC] += cur;\n if (arr[newfC][lC] >= MOD) arr[newfC][lC] -= MOD;\n }\n }\n }\n }\n } else {\n {\n int fD = fD == 0 ? -1 : 1;\n int fM = fD == 1 ? 0 : width - 1;\n int firstMax = fD == 1 ? width : -1;\n for (int fC = fM; fC != firstMax; fC += fD) {\n for (int lC = fC; lC < width; ++lC) {\n int cur = arr[fC][lC];\n if (cur == 0) continue;\n int newfC = fC + fD;\n if (newfC >= 0 && newfC <= lC) {\n arr[newfC][lC] += cur;\n if (arr[newfC][lC] >= MOD) arr[newfC][lC] -= MOD;\n }\n }\n }\n }\n {\n int lD = lD == 0 ? 1 : -1;\n int lastMin = lD == 1 ? 0 : width - 1;\n int lastMax = lD == 1 ? width : -1;\n for (int lC = lastMin; lC != lastMax; lC += lD) {\n for (int fC = 0; fC <= lC; ++fC) {\n int cur = arr[fC][lC];\n if (cur == 0) continue;\n int nL = lC + lD;\n if (nL >= fC && nL < width) {\n arr[fC][nL] += cur;\n if (arr[fC][nL] >= MOD) arr[fC][nL] -= MOD;\n }\n }\n }\n }\n }\n }\n\n for (int fC = 0; fC < width; ++fC) {\n boolean ok = true;\n for (int lC = fC; lC < width; ++lC) {\n if (field[row][lC])\n ok = false;\n if (!ok) {\n for (int fD = 0; fD < 2; ++fD)\n for (int lD = 0; lD < 2; ++lD)\n newRes[fD][lD][fC][lC] = 0;\n } else {\n newRes[0][0][fC][lC] += 1;\n if (newRes[0][0][fC][lC] >= MOD) newRes[0][0][fC][lC] -= MOD;\n }\n }\n }\n\n res = newRes;\n for (int fD = 0; fD < 2; ++fD)\n for (int lD = 0; lD < 2; ++lD)\n for (int fC = 0; fC < width; ++fC)\n for (int lC = fC; lC < width; ++lC) {\n tR += res[fD][lD][fC][lC];\n if (tR >= MOD) tR -= MOD;\n }\n }\n return tR;\n }\n public static void main(String[] args){\n Scanner cin = new Scanner(System.in);\n int n = cin.nextInt() , m = cin.nextInt();\n System.out.println(count(n, m));\n }\n}\n", "lang_cluster": "Java", "compilation_error": true, "code_uid": "e0f0912ca7c373ace359ee1fdfb37f5f", "src_uid": "740eceed59d3c6ac55c1bf9d3d4160c7", "difficulty": 2400.0} {"lang": "Java 11", "source_code": "//package ecr104;\r\nimport java.io.*;\r\nimport java.util.ArrayDeque;\r\nimport java.util.Arrays;\r\nimport java.util.InputMismatchException;\r\nimport java.util.Queue;\r\n\r\npublic class G2 {\r\n\tInputStream is;\r\n\tFastWriter out;\r\n\tString INPUT = \"\";\r\n\r\n\tvoid solve()\r\n\t{\r\n\t\tfinal int mod = 998244353;\r\n\t\tint n = ni();\r\n\t\tint[] a = na(26);\r\n\t\tlong all = 26 * 26 * pow(25, n-2, mod) % mod;\r\n\r\n\t\tlong[][][] dp = new long[n+1][n+1][3];\r\n\t\tdp[1][0][0] = 1;\r\n\t\tdp[0][1][1] = 1;\r\n\t\tdp[0][0][2] = 1;\r\n\t\tfor(int i = 1;i < n;i++){\r\n\t\t\tlong[][][] ndp = new long[n+1][n+1][3];\r\n\t\t\tif(i == (n+1)/2-1){\r\n\t\t\t\tfor (int j = 0; j <= n; j++) {\r\n\t\t\t\t\tfor (int k = 0; j+k <= n; k++) {\r\n\t\t\t\t\t\tif (j + 1 <= n) {\r\n\t\t\t\t\t\t\tndp[j + 1][k][0] += dp[j][k][0] + dp[j][k][1] + dp[j][k][2] * 24;\r\n\t\t\t\t\t\t\tndp[j + 1][k][0] %= mod;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (k + 1 <= n) {\r\n\t\t\t\t\t\t\tndp[j][k + 1][1] += dp[j][k][0] + dp[j][k][1] + dp[j][k][2] * 24;\r\n\t\t\t\t\t\t\tndp[j][k + 1][1] %= mod;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tndp[j][k][2] += dp[j][k][0] + dp[j][k][1] + dp[j][k][2] * 24;\r\n\t\t\t\t\t\tndp[j][k][2] %= mod;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}else {\r\n\t\t\t\tfor (int j = 0; j <= n; j++) {\r\n\t\t\t\t\tfor (int k = 0; j+k <= n; k++) {\r\n\t\t\t\t\t\tif (j + 1 <= n) {\r\n\t\t\t\t\t\t\tndp[j + 1][k][0] += dp[j][k][1] + dp[j][k][2] * 24;\r\n\t\t\t\t\t\t\tndp[j + 1][k][0] %= mod;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (k + 1 <= n) {\r\n\t\t\t\t\t\t\tndp[j][k + 1][1] += dp[j][k][0] + dp[j][k][2] * 24;\r\n\t\t\t\t\t\t\tndp[j][k + 1][1] %= mod;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tndp[j][k][2] += dp[j][k][0] + dp[j][k][1] + dp[j][k][2] * 23;\r\n\t\t\t\t\t\tndp[j][k][2] %= mod;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tdp = ndp;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tlong[] sdp = new long[n+1];\r\n\t\tfor(int i = 0;i <= n;i++){\r\n\t\t\tfor(int j = 0;j <= n;j++){\r\n\t\t\t\tsdp[i] += dp[i][j][0] + dp[i][j][1] + dp[i][j][2] * 24;\r\n\t\t\t}\r\n\t\t\tsdp[i] %= mod;\r\n\t\t}\r\n\r\n\t\tfor(int i = 0;i < 26;i++){\r\n\t\t\tfor(int k = a[i]+1;k <= n;k++){\r\n\t\t\t\tall -= sdp[k];\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tfor(int i = 0;i < 26;i++){\r\n\t\t\tfor(int j = i+1;j < 26;j++){\r\n\t\t\t\tfor(int k = a[i]+1;k <= n;k++){\r\n\t\t\t\t\tfor(int l = a[j]+1;l+k <= n;l++){\r\n\t\t\t\t\t\tall += dp[k][l][0] + dp[k][l][1] + dp[k][l][2] * 24;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tall %= mod;\r\n\t\t\t}\r\n\t\t}\r\n\t\tall %= mod;\r\n\r\n\t\tif(all < 0)all += mod;\r\n\t\tout.println(all);\r\n\t}\r\n\r\n\tpublic static long pow(long a, long n, long mod) {\r\n\t\t//\t\ta %= mod;\r\n\t\tlong ret = 1;\r\n\t\tint x = 63 - Long.numberOfLeadingZeros(n);\r\n\t\tfor (; x >= 0; x--) {\r\n\t\t\tret = ret * ret % mod;\r\n\t\t\tif (n << 63 - x < 0) ret = ret * a % mod;\r\n\t\t}\r\n\t\treturn ret;\r\n\t}\r\n\r\n\r\n\tpublic static long invl(long a, long mod) {\r\n\t\tlong b = mod;\r\n\t\tlong p = 1, q = 0;\r\n\t\twhile (b > 0) {\r\n\t\t\tlong c = a / b;\r\n\t\t\tlong d;\r\n\t\t\td = a;\r\n\t\t\ta = b;\r\n\t\t\tb = d % b;\r\n\t\t\td = p;\r\n\t\t\tp = q;\r\n\t\t\tq = d - c * q;\r\n\t\t}\r\n\t\treturn p < 0 ? p + mod : p;\r\n\t}\r\n\r\n\r\n\tpublic static long C(int n, int r, int mod, int[][] fif) {\r\n\t\tif (n < 0 || r < 0 || r > n) return 0;\r\n\t\treturn (long) fif[0][n] * fif[1][r] % mod * fif[1][n - r] % mod;\r\n\t}\r\n\r\n\r\n\tpublic static int[][] enumFIF(int n, int mod) {\r\n\t\tint[] f = new int[n + 1];\r\n\t\tint[] invf = new int[n + 1];\r\n\t\tf[0] = 1;\r\n\t\tfor (int i = 1; i <= n; i++) {\r\n\t\t\tf[i] = (int) ((long) f[i - 1] * i % mod);\r\n\t\t}\r\n\t\tlong a = f[n];\r\n\t\tlong b = mod;\r\n\t\tlong p = 1, q = 0;\r\n\t\twhile (b > 0) {\r\n\t\t\tlong c = a / b;\r\n\t\t\tlong d;\r\n\t\t\td = a;\r\n\t\t\ta = b;\r\n\t\t\tb = d % b;\r\n\t\t\td = p;\r\n\t\t\tp = q;\r\n\t\t\tq = d - c * q;\r\n\t\t}\r\n\t\tinvf[n] = (int) (p < 0 ? p + mod : p);\r\n\t\tfor (int i = n - 1; i >= 0; i--) {\r\n\t\t\tinvf[i] = (int) ((long) invf[i + 1] * (i + 1) % mod);\r\n\t\t}\r\n\t\treturn new int[][]{f, invf};\r\n\t}\r\n\r\n\r\n\tvoid run() throws Exception\r\n\t{\r\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\r\n\t\tout = new FastWriter(System.out);\r\n\t\t\r\n\t\tlong s = System.currentTimeMillis();\r\n\t\tsolve();\r\n\t\tout.flush();\r\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) throws Exception { new G2().run(); }\r\n\t\r\n\tprivate byte[] inbuf = new byte[1024];\r\n\tpublic int lenbuf = 0, ptrbuf = 0;\r\n\t\r\n\tprivate int readByte()\r\n\t{\r\n\t\tif(lenbuf == -1)throw new InputMismatchException();\r\n\t\tif(ptrbuf >= lenbuf){\r\n\t\t\tptrbuf = 0;\r\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\r\n\t\t\tif(lenbuf <= 0)return -1;\r\n\t\t}\r\n\t\treturn inbuf[ptrbuf++];\r\n\t}\r\n\t\r\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\r\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\r\n\t\r\n\tprivate double nd() { return Double.parseDouble(ns()); }\r\n\tprivate char nc() { return (char)skip(); }\r\n\t\r\n\tprivate String ns()\r\n\t{\r\n\t\tint b = skip();\r\n\t\tStringBuilder sb = new StringBuilder();\r\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\r\n\t\t\tsb.appendCodePoint(b);\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t\treturn sb.toString();\r\n\t}\r\n\t\r\n\tprivate char[] ns(int n)\r\n\t{\r\n\t\tchar[] buf = new char[n];\r\n\t\tint b = skip(), p = 0;\r\n\t\twhile(p < n && !(isSpaceChar(b))){\r\n\t\t\tbuf[p++] = (char)b;\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\r\n\t}\r\n\r\n\tprivate int[] na(int n)\r\n\t{\r\n\t\tint[] a = new int[n];\r\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\r\n\t\treturn a;\r\n\t}\r\n\r\n\tprivate long[] nal(int n)\r\n\t{\r\n\t\tlong[] a = new long[n];\r\n\t\tfor(int i = 0;i < n;i++)a[i] = nl();\r\n\t\treturn a;\r\n\t}\r\n\r\n\tprivate char[][] nm(int n, int m) {\r\n\t\tchar[][] map = new char[n][];\r\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\r\n\t\treturn map;\r\n\t}\r\n\r\n\tprivate int[][] nmi(int n, int m) {\r\n\t\tint[][] map = new int[n][];\r\n\t\tfor(int i = 0;i < n;i++)map[i] = na(m);\r\n\t\treturn map;\r\n\t}\r\n\r\n\tprivate int ni() { return (int)nl(); }\r\n\r\n\tprivate long nl()\r\n\t{\r\n\t\tlong num = 0;\r\n\t\tint b;\r\n\t\tboolean minus = false;\r\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\r\n\t\tif(b == '-'){\r\n\t\t\tminus = true;\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\r\n\t\twhile(true){\r\n\t\t\tif(b >= '0' && b <= '9'){\r\n\t\t\t\tnum = num * 10 + (b - '0');\r\n\t\t\t}else{\r\n\t\t\t\treturn minus ? -num : num;\r\n\t\t\t}\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic static class FastWriter\r\n\t{\r\n\t\tprivate static final int BUF_SIZE = 1<<13;\r\n\t\tprivate final byte[] buf = new byte[BUF_SIZE];\r\n\t\tprivate final OutputStream out;\r\n\t\tprivate int ptr = 0;\r\n\r\n\t\tprivate FastWriter(){out = null;}\r\n\r\n\t\tpublic FastWriter(OutputStream os)\r\n\t\t{\r\n\t\t\tthis.out = os;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter(String path)\r\n\t\t{\r\n\t\t\ttry {\r\n\t\t\t\tthis.out = new FileOutputStream(path);\r\n\t\t\t} catch (FileNotFoundException e) {\r\n\t\t\t\tthrow new RuntimeException(\"FastWriter\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(byte b)\r\n\t\t{\r\n\t\t\tbuf[ptr++] = b;\r\n\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(char c)\r\n\t\t{\r\n\t\t\treturn write((byte)c);\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(char[] s)\r\n\t\t{\r\n\t\t\tfor(char c : s){\r\n\t\t\t\tbuf[ptr++] = (byte)c;\r\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(String s)\r\n\t\t{\r\n\t\t\ts.chars().forEach(c -> {\r\n\t\t\t\tbuf[ptr++] = (byte)c;\r\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\t});\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tprivate static int countDigits(int l) {\r\n\t\t\tif (l >= 1000000000) return 10;\r\n\t\t\tif (l >= 100000000) return 9;\r\n\t\t\tif (l >= 10000000) return 8;\r\n\t\t\tif (l >= 1000000) return 7;\r\n\t\t\tif (l >= 100000) return 6;\r\n\t\t\tif (l >= 10000) return 5;\r\n\t\t\tif (l >= 1000) return 4;\r\n\t\t\tif (l >= 100) return 3;\r\n\t\t\tif (l >= 10) return 2;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(int x)\r\n\t\t{\r\n\t\t\tif(x == Integer.MIN_VALUE){\r\n\t\t\t\treturn write((long)x);\r\n\t\t\t}\r\n\t\t\tif(ptr + 12 >= BUF_SIZE)innerflush();\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite((byte)'-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tint d = countDigits(x);\r\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\r\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\r\n\t\t\t\tx /= 10;\r\n\t\t\t}\r\n\t\t\tptr += d;\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tprivate static int countDigits(long l) {\r\n\t\t\tif (l >= 1000000000000000000L) return 19;\r\n\t\t\tif (l >= 100000000000000000L) return 18;\r\n\t\t\tif (l >= 10000000000000000L) return 17;\r\n\t\t\tif (l >= 1000000000000000L) return 16;\r\n\t\t\tif (l >= 100000000000000L) return 15;\r\n\t\t\tif (l >= 10000000000000L) return 14;\r\n\t\t\tif (l >= 1000000000000L) return 13;\r\n\t\t\tif (l >= 100000000000L) return 12;\r\n\t\t\tif (l >= 10000000000L) return 11;\r\n\t\t\tif (l >= 1000000000L) return 10;\r\n\t\t\tif (l >= 100000000L) return 9;\r\n\t\t\tif (l >= 10000000L) return 8;\r\n\t\t\tif (l >= 1000000L) return 7;\r\n\t\t\tif (l >= 100000L) return 6;\r\n\t\t\tif (l >= 10000L) return 5;\r\n\t\t\tif (l >= 1000L) return 4;\r\n\t\t\tif (l >= 100L) return 3;\r\n\t\t\tif (l >= 10L) return 2;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(long x)\r\n\t\t{\r\n\t\t\tif(x == Long.MIN_VALUE){\r\n\t\t\t\treturn write(\"\" + x);\r\n\t\t\t}\r\n\t\t\tif(ptr + 21 >= BUF_SIZE)innerflush();\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite((byte)'-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tint d = countDigits(x);\r\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\r\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\r\n\t\t\t\tx /= 10;\r\n\t\t\t}\r\n\t\t\tptr += d;\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(double x, int precision)\r\n\t\t{\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite('-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tx += Math.pow(10, -precision)/2;\r\n\t\t\t//\t\tif(x < 0){ x = 0; }\r\n\t\t\twrite((long)x).write(\".\");\r\n\t\t\tx -= (long)x;\r\n\t\t\tfor(int i = 0;i < precision;i++){\r\n\t\t\t\tx *= 10;\r\n\t\t\t\twrite((char)('0'+(int)x));\r\n\t\t\t\tx -= (int)x;\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(char c){\r\n\t\t\treturn write(c).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(int x){\r\n\t\t\treturn write(x).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(long x){\r\n\t\t\treturn write(x).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(double x, int precision){\r\n\t\t\treturn write(x, precision).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(int... xs)\r\n\t\t{\r\n\t\t\tboolean first = true;\r\n\t\t\tfor(int x : xs) {\r\n\t\t\t\tif (!first) write(' ');\r\n\t\t\t\tfirst = false;\r\n\t\t\t\twrite(x);\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(long... xs)\r\n\t\t{\r\n\t\t\tboolean first = true;\r\n\t\t\tfor(long x : xs) {\r\n\t\t\t\tif (!first) write(' ');\r\n\t\t\t\tfirst = false;\r\n\t\t\t\twrite(x);\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln()\r\n\t\t{\r\n\t\t\treturn write((byte)'\\n');\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(int... xs)\r\n\t\t{\r\n\t\t\treturn write(xs).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(long... xs)\r\n\t\t{\r\n\t\t\treturn write(xs).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(char[] line)\r\n\t\t{\r\n\t\t\treturn write(line).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(char[]... map)\r\n\t\t{\r\n\t\t\tfor(char[] line : map)write(line).writeln();\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(String s)\r\n\t\t{\r\n\t\t\treturn write(s).writeln();\r\n\t\t}\r\n\r\n\t\tprivate void innerflush()\r\n\t\t{\r\n\t\t\ttry {\r\n\t\t\t\tout.write(buf, 0, ptr);\r\n\t\t\t\tptr = 0;\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\tthrow new RuntimeException(\"innerflush\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void flush()\r\n\t\t{\r\n\t\t\tinnerflush();\r\n\t\t\ttry {\r\n\t\t\t\tout.flush();\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\tthrow new RuntimeException(\"flush\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic FastWriter print(byte b) { return write(b); }\r\n\t\tpublic FastWriter print(char c) { return write(c); }\r\n\t\tpublic FastWriter print(char[] s) { return write(s); }\r\n\t\tpublic FastWriter print(String s) { return write(s); }\r\n\t\tpublic FastWriter print(int x) { return write(x); }\r\n\t\tpublic FastWriter print(long x) { return write(x); }\r\n\t\tpublic FastWriter print(double x, int precision) { return write(x, precision); }\r\n\t\tpublic FastWriter println(char c){ return writeln(c); }\r\n\t\tpublic FastWriter println(int x){ return writeln(x); }\r\n\t\tpublic FastWriter println(long x){ return writeln(x); }\r\n\t\tpublic FastWriter println(double x, int precision){ return writeln(x, precision); }\r\n\t\tpublic FastWriter print(int... xs) { return write(xs); }\r\n\t\tpublic FastWriter print(long... xs) { return write(xs); }\r\n\t\tpublic FastWriter println(int... xs) { return writeln(xs); }\r\n\t\tpublic FastWriter println(long... xs) { return writeln(xs); }\r\n\t\tpublic FastWriter println(char[] line) { return writeln(line); }\r\n\t\tpublic FastWriter println(char[]... map) { return writeln(map); }\r\n\t\tpublic FastWriter println(String s) { return writeln(s); }\r\n\t\tpublic FastWriter println() { return writeln(); }\r\n\t}\r\n\r\n\tpublic void trnz(int... o)\r\n\t{\r\n\t\tfor(int i = 0;i < o.length;i++)if(o[i] != 0)System.out.print(i+\":\"+o[i]+\" \");\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\t// print ids which are 1\r\n\tpublic void trt(long... o)\r\n\t{\r\n\t\tQueue stands = new ArrayDeque<>();\r\n\t\tfor(int i = 0;i < o.length;i++){\r\n\t\t\tfor(long x = o[i];x != 0;x &= x-1)stands.add(i<<6|Long.numberOfTrailingZeros(x));\r\n\t\t}\r\n\t\tSystem.out.println(stands);\r\n\t}\r\n\r\n\tpublic void tf(boolean... r)\r\n\t{\r\n\t\tfor(boolean x : r)System.out.print(x?'#':'.');\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\tpublic void tf(boolean[]... b)\r\n\t{\r\n\t\tfor(boolean[] r : b) {\r\n\t\t\tfor(boolean x : r)System.out.print(x?'#':'.');\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\tpublic void tf(long[]... b)\r\n\t{\r\n\t\tif(INPUT.length() != 0) {\r\n\t\t\tfor (long[] r : b) {\r\n\t\t\t\tfor (long x : r) {\r\n\t\t\t\t\tfor (int i = 0; i < 64; i++) {\r\n\t\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tSystem.out.println();\r\n\t\t\t}\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic void tf(long... b)\r\n\t{\r\n\t\tif(INPUT.length() != 0) {\r\n\t\t\tfor (long x : b) {\r\n\t\t\t\tfor (int i = 0; i < 64; i++) {\r\n\t\t\t\t\tSystem.out.print(x << ~i < 0 ? '#' : '.');\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tSystem.out.println();\r\n\t\t}\r\n\t}\r\n\r\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\r\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "958c1cd86d70d7e55188a49f5e6c5c3a", "src_uid": "1f012349f4b229dc98faadf1ca732355", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\nimport static java.lang.Math.random;\n\n/**\n * @author Don Li\n */\npublic class PointsLinesTitles {\n \n int N = (int) 1e5 + 10;\n int MOD = (int) 1e9 + 7;\n \n int n;\n int[][] p;\n List[] G;\n \n boolean[] used = new boolean[N];\n Set uniqueX = new HashSet<>(), uniqueY = new HashSet<>();\n long sumDegree = 0, numNode = 0;\n \n void solve() {\n n = in.nextInt();\n \n p = new int[n][2];\n for (int i = 0; i < n; i++) {\n p[i][0] = in.nextInt();\n p[i][1] = in.nextInt();\n }\n \n int[] x = new int[n], y = new int[n];\n for (int i = 0; i < n; i++) {\n x[i] = p[i][0];\n y[i] = p[i][1];\n }\n sort(x);\n sort(y);\n for (int i = 0; i < n; i++) {\n p[i][0] = lowerBound(x, p[i][0]);\n p[i][1] = lowerBound(y, p[i][1]);\n }\n \n G = new List[n];\n for (int i = 0; i < n; i++) G[i] = new ArrayList<>();\n \n List[] ver = new List[n], hor = new List[n];\n for (int i = 0; i < n; i++) {\n ver[i] = new ArrayList<>();\n hor[i] = new ArrayList<>();\n }\n for (int i = 0; i < n; i++) {\n ver[p[i][0]].add(i);\n hor[p[i][1]].add(i);\n }\n for (int i = 0; i < n; i++) {\n ver[i].sort(Comparator.comparingInt(a -> p[a][1]));\n for (int j = 1; j < ver[i].size(); j++) {\n int u = ver[i].get(j - 1), v = ver[i].get(j);\n addNeighbors(u, v);\n }\n hor[i].sort(Comparator.comparingInt(a -> p[a][0]));\n for (int j = 1; j < hor[i].size(); j++) {\n int u = hor[i].get(j - 1), v = hor[i].get(j);\n addNeighbors(u, v);\n }\n }\n \n long ans = 1;\n for (int i = 0; i < n; i++) {\n if (!used[i]) {\n uniqueX.clear();\n uniqueY.clear();\n sumDegree = 0; numNode = 0;\n dfs(i);\n long ways = mpow(2, uniqueX.size() + uniqueY.size());\n if (sumDegree / 2 == numNode - 1) ways--;\n ans = ans * ways % MOD;\n }\n }\n out.println(ans);\n }\n \n void dfs(int u) {\n used[u] = true;\n uniqueX.add(p[u][0]);\n uniqueY.add(p[u][1]);\n numNode++;\n sumDegree += G[u].size();\n for (int v : G[u]) {\n if (!used[v]) dfs(v);\n }\n }\n \n long mpow(int a, int n) {\n long res = 1;\n while (n > 0) {\n if ((n & 1) > 0) res = res * a % MOD;\n a = a * a % MOD;\n n >>= 1;\n }\n return res;\n }\n \n void addNeighbors(int u, int v) {\n G[u].add(v);\n G[v].add(u);\n }\n \n void sort(int[] a) {\n int n = a.length;\n for (int i = 0; i < n; i++) {\n int j = (int) (i + random() * (n - i));\n int tmp = a[i];\n a[i] = a[j];\n a[j] = tmp;\n }\n Arrays.sort(a);\n }\n \n int lowerBound(int[] a, int k) {\n int lb = -1, ub = a.length;\n while (ub - lb > 1) {\n int m = (lb + ub) >> 1;\n if (a[m] >= k) ub = m;\n else lb = m;\n }\n return ub;\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 PointsLinesTitles().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", "compilation_error": false, "code_uid": "104ef79e273130a5692059b6a07d1c2d", "src_uid": "8781003d9eea51a509145bc6db8b609c", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Iterator;\nimport java.io.BufferedWriter;\nimport java.util.AbstractSet;\nimport java.util.Set;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.Random;\nimport java.util.AbstractMap;\nimport java.util.Map;\nimport java.io.Writer;\nimport java.util.Map.Entry;\nimport java.io.OutputStreamWriter;\nimport java.util.NoSuchElementException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Egor Kulikov (egor@egork.net)\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskG solver = new TaskG();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskG {\n Map[][] result = new Map[51][51];\n long[][] max = new long[51][51];\n\n {\n for (int i = 0; i < 51; i++) {\n for (int j = 0; j < 51; j++) {\n result[i][j] = new EHashMap<>();\n max[i][j] = (1L << i) - 1 - i + (1L << j) - 1 - j;\n }\n }\n }\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n long s = in.readLong();\n long answer = 0;\n for (int i = 0; (1L << (i + 1)) - 2 <= s; i++) {\n for (int j = 0; (1L << (j + 1)) + (1L << (i + 1)) - 3 <= s; j++) {\n long maxDelta = max[i][j];\n long by = (1L << (i + 1)) + (1L << (j + 1)) - 3;\n for (long v = s / by; v > 0; v--) {\n long remaining = s - v * by - ((1L << j) - 1);\n if (remaining < 0) {\n continue;\n }\n if (remaining > maxDelta) {\n break;\n }\n answer += query(Math.max(Math.max(i, j) - 1, 0), Math.max(Math.min(i, j) - 1, 0), remaining);\n }\n }\n }\n out.printLine(answer);\n }\n\n private long query(int mx, int mn, long val) {\n if (val > max[mx][mn]) {\n return 0;\n }\n if (mx == 0) {\n return 1;\n }\n if (result[mx][mn].containsKey(val)) {\n return result[mx][mn].get(val);\n }\n long by = (1L << mx) - 1;\n if (mx == mn) {\n long result = query(mx - 1, mn - 1, val);\n if (val >= by) {\n result += query(mx - 1, mn - 1, val - by) * 2;\n }\n if (val >= 2 * by) {\n result += query(mx - 1, mn - 1, val - 2 * by);\n }\n this.result[mx][mn].put(val, result);\n return result;\n }\n long result = query(mx - 1, mn, val);\n if (val >= by) {\n result += query(mx - 1, mn, val - by);\n }\n this.result[mx][mn].put(val, result);\n return result;\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void printLine(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 readLong() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public 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 EHashMap extends AbstractMap {\n private static final int[] shifts = new int[10];\n private int size;\n private EHashMap.HashEntry[] data;\n private int capacity;\n private Set> entrySet;\n\n static {\n Random random = new Random(System.currentTimeMillis());\n for (int i = 0; i < 10; i++) {\n shifts[i] = 1 + 3 * i + random.nextInt(3);\n }\n }\n\n public EHashMap() {\n this(4);\n }\n\n private void setCapacity(int size) {\n capacity = Integer.highestOneBit(4 * size);\n //noinspection unchecked\n data = new EHashMap.HashEntry[capacity];\n }\n\n public EHashMap(int maxSize) {\n setCapacity(maxSize);\n entrySet = new AbstractSet>() {\n\n public Iterator> iterator() {\n return new Iterator>() {\n private EHashMap.HashEntry last = null;\n private EHashMap.HashEntry current = null;\n private EHashMap.HashEntry base = null;\n private int lastIndex = -1;\n private int index = -1;\n\n public boolean hasNext() {\n if (current == null) {\n for (index++; index < capacity; index++) {\n if (data[index] != null) {\n base = current = data[index];\n break;\n }\n }\n }\n return current != null;\n }\n\n public Entry next() {\n if (!hasNext()) {\n throw new NoSuchElementException();\n }\n last = current;\n lastIndex = index;\n current = current.next;\n if (base.next != last) {\n base = base.next;\n }\n return last;\n }\n\n public void remove() {\n if (last == null) {\n throw new IllegalStateException();\n }\n size--;\n if (base == last) {\n data[lastIndex] = last.next;\n } else {\n base.next = last.next;\n }\n }\n };\n }\n\n\n public int size() {\n return size;\n }\n };\n }\n\n public EHashMap(Map map) {\n this(map.size());\n putAll(map);\n }\n\n\n public Set> entrySet() {\n return entrySet;\n }\n\n\n public void clear() {\n Arrays.fill(data, null);\n size = 0;\n }\n\n private int index(Object o) {\n return getHash(o.hashCode()) & (capacity - 1);\n }\n\n private int getHash(int h) {\n int result = h;\n for (int i : shifts) {\n result ^= h >>> i;\n }\n return result;\n }\n\n\n public V remove(Object o) {\n if (o == null) {\n return null;\n }\n int index = index(o);\n EHashMap.HashEntry current = data[index];\n EHashMap.HashEntry last = null;\n while (current != null) {\n if (current.key.equals(o)) {\n if (last == null) {\n data[index] = current.next;\n } else {\n last.next = current.next;\n }\n size--;\n return current.value;\n }\n last = current;\n current = current.next;\n }\n return null;\n }\n\n\n public V put(E e, V value) {\n if (e == null) {\n return null;\n }\n int index = index(e);\n EHashMap.HashEntry current = data[index];\n if (current != null) {\n while (true) {\n if (current.key.equals(e)) {\n V oldValue = current.value;\n current.value = value;\n return oldValue;\n }\n if (current.next == null) {\n break;\n }\n current = current.next;\n }\n }\n if (current == null) {\n data[index] = new EHashMap.HashEntry(e, value);\n } else {\n current.next = new EHashMap.HashEntry(e, value);\n }\n size++;\n if (2 * size > capacity) {\n EHashMap.HashEntry[] oldData = data;\n setCapacity(size);\n for (EHashMap.HashEntry entry : oldData) {\n while (entry != null) {\n EHashMap.HashEntry next = entry.next;\n index = index(entry.key);\n entry.next = data[index];\n data[index] = entry;\n entry = next;\n }\n }\n }\n return null;\n }\n\n\n public V get(Object o) {\n if (o == null) {\n return null;\n }\n int index = index(o);\n EHashMap.HashEntry current = data[index];\n while (current != null) {\n if (current.key.equals(o)) {\n return current.value;\n }\n current = current.next;\n }\n return null;\n }\n\n\n public boolean containsKey(Object o) {\n if (o == null) {\n return false;\n }\n int index = index(o);\n EHashMap.HashEntry current = data[index];\n while (current != null) {\n if (current.key.equals(o)) {\n return true;\n }\n current = current.next;\n }\n return false;\n }\n\n\n public int size() {\n return size;\n }\n\n private static class HashEntry implements Entry {\n private final E key;\n private V value;\n private EHashMap.HashEntry next;\n\n private HashEntry(E key, V value) {\n this.key = key;\n this.value = value;\n }\n\n public E getKey() {\n return key;\n }\n\n public V getValue() {\n return value;\n }\n\n public V setValue(V value) {\n V oldValue = this.value;\n this.value = value;\n return oldValue;\n }\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "414a5f35567198122454da478ce30a94", "src_uid": "c142f8bc5252e739035992926545c251", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport static java.lang.Math.*;\n\npublic class E {\n static void p(Object ...args) {System.out.println(Arrays.deepToString(args));}\n static long MOD = 1_000_000_007;\n\n /*static int score(int a, int k) {\n int ans = 0;\n while( a > 0) {\n ans += a % k;\n a /= k;\n }\n return ans % k;\n }\n\n public static long slow(int N, int K) {\n long[] V = new long[N+1];\n for (int i = 0; i <= N; i++)\n V[i] = score(i, K);\n long[] dp = new long[N+1];\n for (int i = 0; i <= N; i++) {\n for (int j = 0; j < K; j++) {\n for (int a = i - 1; a >= 0; a--) {\n if (V[a] == j) {\n dp[i] += dp[a];\n break;\n }\n }\n }\n dp[i] += 1;\n dp[i] %= MOD;\n }\n return dp[N];\n }*/\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n long N = in.nextLong();\n int K = in.nextInt();\n\n long[][][] M = new long[70][][];\n for (int i = 2; i < M.length; i++)\n M[i] = makeMatrix(K, i);\n\n /*p(\"M[2]\");\n for (int i = 0; i < M[2].length; i++)\n p(M[2][i]);\n p(\"M[3]\");\n for (int i = 0; i < M[3].length; i++)\n p(M[3][i]);*/\n\n long[][][] moveBy = new long[70][][];\n long[][][] moveByK = new long[70][][];\n for (int i = 1; i < moveBy.length - 1; i++) {\n long[][] ans = new long[K+1][K+1];\n for (int j = 0; j < ans.length; j++)\n ans[j][j] = 1;\n for (int j = i - 1; j >= 1; j--)\n ans = multiply(ans, moveByK[j]);\n\n ans = multiply(ans, M[i+1]);\n moveBy[i] = ans;\n moveByK[i] = new long[K+1][K+1];\n for (int j = 0; j <= K; j++)\n moveByK[i][j][j] = 1;\n for (int j = 0; j < K-1; j++)\n moveByK[i] = multiply(moveByK[i], moveBy[i]);\n }\n /*p(\"moveBy[2]\");\n for (int i = 0; i <= K; i++)\n p(moveBy[2][i]);*/\n\n long at = 0;\n long[][] f = new long[K+1][K+1];\n for (int i = 0; i < f.length; i++)\n f[i][i] = 1;\n //f = multiply(f, M[2]);\n //f = multiply(f, M[3]);\n long temp = N / K;\n for (int i = 1; temp > 0; i++) {\n for (int j = 0; j < temp % K; j++) {\n //p(\"mult by\", i);\n f = multiply(moveBy[i], f);\n }\n temp /= K;\n }\n /*p(\"f\");\n for (int i = 0; i < K+1; i++)\n p(f[i]);*/\n long[] start = new long[K+1];\n for (int i = 0; i < start.length; i++)\n start[i] = (1L<<(i)) % MOD;\n start[K] = 1;\n\n int position = (int)(N % K);\n //p(\"taking: \", position);\n long ans = 0;\n for (int i = 0; i < start.length; i++)\n ans += (start[i] * f[i][position]) % MOD;\n ans %= MOD;\n\n /*long a2 = slow((int)N, K);\n if (ans != a2) {\n p(ans, a2);\n throw new RuntimeException();\n }*/\n System.out.println(ans);\n }\n static long[][] makeMatrix(int K, int a) {\n long[][] res = new long[K+1][K+1];\n\n int[] v = new int[2*K];\n v[2*K-1] = 0;\n for (int i = 2*K-2; i >= 0; i--) {\n if (i == K-1) {\n v[i] = (K + (K-a + v[i+1]) % K) % K;\n } else {\n v[i] = (K + (K-1 + v[i+1]) % K) % K;\n }\n }\n /*if (a == 2 || a == 3) {\n p(a, v);\n }*/\n for (int i = 0; i <= K; i++)\n res[K][i]++;\n for (int c = 0; c < K; c++) {\n for (int i = 0; i < K; i++) {\n boolean found = false;\n for (int j = c - 1 + K; j >= 0; j--) {\n if (v[j] == i) {\n found = true;\n if (j < K) {\n res[j][c] += 1;\n } else {\n for (int b = 0; b <= K; b++)\n res[b][c] += res[b][j-K];\n }\n break;\n }\n }\n if (!found) {\n p(c, i, v);\n throw new RuntimeException();\n }\n }\n }\n return res;\n }\n static long[][] multiply(long[][] A, long[][] B) {\n long[][] res = new long[A.length][A.length];\n for (int r = 0; r < A.length; r++) \n for (int c = 0; c < A.length; c++) {\n for (int i = 0; i < A.length; i++)\n res[r][c] += (A[r][i] * B[i][c]) % MOD;\n res[r][c] %= MOD;\n }\n return res;\n }\n }\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "064d14ea71161a429e69f5379c5e0fd2", "src_uid": "175ce134da7cc5af9c8457e7bd9a40a2", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class Main extends PrintWriter {\n BufferedReader in;\n StringTokenizer stok;\n final Random rand = new Random(31);\n final int inf = (int) 1e9;\n final long linf = (long) 1e18;\n\n public void solve() throws IOException {\n int n = nextInt();\n char[][] a = new char[n][];\n for (int i = 0; i < n; i++) {\n a[i] = next().toCharArray();\n }\n int m = a[0].length;\n long[] d1 = new long[1 << m];\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n if (i != j) {\n int x = 0;\n for (int k = 0; k < m; k++) {\n if (a[i][k] == a[j][k]) {\n x |= (1 << k);\n }\n }\n d1[x] |= (1 << i);\n d1[x] |= (1 << j);\n }\n }\n }\n for (int i = (1 << m) - 1; i >= 0; i--) {\n for (int j = 0; j < m; j++) {\n d1[i] |= d1[i | (1 << j)];\n }\n }\n double[] d = new double[1 << m];\n d[0] = 1;\n for (int mask = 0; mask < (1 << m); mask++) {\n double bc = Integer.bitCount(mask);\n int bc1 = Long.bitCount(d1[mask]);\n if (bc1 == 0) {\n continue;\n }\n for (int i = 0; i < m; i++) {\n if ((mask & (1 << i)) == 0) {\n int nmask = mask | (1 << i);\n double nbc1 = Long.bitCount(d1[nmask]);\n d[nmask] += d[mask] * (nbc1 / bc1) / (m - bc);\n }\n }\n }\n double ans = 0;\n for (int mask = 0; mask < (1 << m); mask++) {\n double finish = 0;\n int bc1 = Long.bitCount(d1[mask]);\n int bc = Long.bitCount(mask);\n for (int i = 0; i < m; i++) {\n if ((mask & (1 << i)) > 0) {\n int nmask = mask & ~(1 << i);\n int nbc1 = Long.bitCount(d1[nmask]);\n if (nbc1 == 0) {\n continue;\n }\n int nbc = Long.bitCount(nmask);\n finish += d[nmask] * (nbc1 - bc1) / nbc1 / (m - nbc);\n }\n }\n ans += bc * finish;\n }\n printf(\"%.11f\", ans);\n }\n\n public void run() {\n try {\n solve();\n close();\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(abs(-1));\n }\n }\n\n Main() throws IOException {\n super(System.out);\n in = new BufferedReader(new InputStreamReader(System.in));\n }\n\n Main(String s) throws IOException {\n super(\"\".equals(s) ? \"output.txt\" : (s + \".out\"));\n in = new BufferedReader(new FileReader(\"\".equals(s) ? \"input.txt\" : (s + \".in\")));\n }\n\n public static void main(String[] args) throws IOException {\n try {\n Locale.setDefault(Locale.US);\n } catch (Exception ignored) {\n }\n new Main().run();\n }\n\n String next() throws IOException {\n while (stok == null || !stok.hasMoreTokens()) {\n String s = in.readLine();\n if (s == null) {\n return null;\n }\n stok = new StringTokenizer(s);\n }\n return stok.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n int[] nextIntArray(int len) throws IOException {\n int[] a = new int[len];\n for (int i = 0; i < len; i++) {\n a[i] = nextInt();\n }\n return a;\n }\n\n void shuffle(int[] a) {\n for (int i = 1; i < a.length; i++) {\n int x = rand.nextInt(i + 1);\n int t = a[i];\n a[i] = a[x];\n a[x] = t;\n }\n }\n\n boolean nextPerm(int[] p) {\n for (int a = p.length - 2; a >= 0; --a)\n if (p[a] < p[a + 1])\n for (int b = p.length - 1; ; --b)\n if (p[b] > p[a]) {\n int t = p[a];\n p[a] = p[b];\n p[b] = t;\n for (++a, b = p.length - 1; a < b; ++a, --b) {\n t = p[a];\n p[a] = p[b];\n p[b] = t;\n }\n return true;\n }\n return false;\n }\n\n List[] createAdjacencyList(int countVertex) {\n List[] res = new List[countVertex];\n for (int i = 0; i < countVertex; i++) {\n res[i] = new ArrayList();\n }\n return res;\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "08d4fbc971ed227ac5fe24fa92716300", "src_uid": "a95d9aef6a64c30e46330dcc8e6d4a67", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class B {\n\n long n, c0, c1;\n\n public void solve() {\n n = in.nextInt() - 1;\n c0 = in.nextInt();\n c1 = in.nextInt();\n if (c0 > c1) {\n long tmp = c0;\n c0 = c1;\n c1 = tmp;\n }\n\n if (c0 == 0) {\n out.println(1L * n * (c0 + c1));\n return;\n }\n\n long left = 0, right = (long) 5e17;\n\n while (left < right - 1) {\n long mid = (left + right) >>> 1;\n\n long[] calc = calc(mid);\n if (calc[0] < n) {\n left = mid;\n } else {\n right = mid;\n }\n }\n System.err.println(left);\n long[] calc2 = calc(left);\n\n long result = calc2[1] + (n - calc2[0]) * (left + 1);\n result += 1L * n * (c0 + c1);\n out.println(result);\n }\n\n long[] calc(long x) {\n long count = 0, sum = 0;\n for (long j = 0; c1 * j <= x; j++) {\n long maxI = (x - c1 * j) / c0;\n if (j == 0) {\n count += (maxI + 1);\n sum += c0 * maxI * (maxI + 1) / 2;\n } else {\n long curChoose = 1;\n for (long i = 0; i * c0 + j * c1 <= x; i++) {\n if (i > 0) {\n curChoose *= (i + j);\n curChoose /= i;\n }\n count += curChoose;\n sum += curChoose * (i * c0 + j * c1);\n if (count >= n) {\n return new long[]{count, sum};\n }\n }\n }\n }\n return new long[]{count, sum};\n }\n\n public void run() {\n in = new FastScanner();\n out = new PrintWriter(System.out);\n solve();\n out.close();\n }\n\n FastScanner in;\n PrintWriter out;\n\n class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(String fileName) {\n try {\n br = new BufferedReader(new FileReader(fileName));\n } catch (FileNotFoundException e) {\n }\n }\n\n public FastScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String nextToken() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() {\n return Double.parseDouble(nextToken());\n }\n }\n\n public static void main(String[] args) {\n new B().run();\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c4427c72bd890c28265d319163e2a0c2", "src_uid": "39b824b740a40f68bae39b8d9f0adcbe", "difficulty": 2700.0} {"lang": "Java 6", "source_code": "//package round102;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\n\npublic class D {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\"; \n\tboolean[][] g = new boolean[101][101];\n\tboolean[][] d = new boolean[101][101];\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni(), m = ni(), k = ni();\n\t\tint two = 0;\n\t\tint three = 0;\n\t\tboolean f1 = false;\n\t\tboolean f2 = false;\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tchar[] str = ns(m);\n\t\t\tint r = -1, g = -1;\n\t\t\tfor(int j = 0;j < m;j++){\n\t\t\t\tif(str[j] == 'R')r = j;\n\t\t\t\tif(str[j] == 'G')g = j;\n\t\t\t}\n\t\t\tif(r == -1 && g >= 0 && m > 1)f1 = true;\n\t\t\tif(g == -1 && r >= 0 && m > 1)f2 = true;\n\t\t\tif(r >= 0 && g >= 0){\n\t\t\t\tint dist = Math.abs(r-g);\n\t\t\t\tif(dist == 2){\n\t\t\t\t\ttwo++;\n\t\t\t\t}else if(dist >= 3){\n\t\t\t\t\tthree++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif(f1 && f2){\n\t\t\tout.println(\"Draw\");\n\t\t}else if(f1){\n\t\t\tout.println(\"First\");\n\t\t}else if(f2){\n\t\t\tout.println(\"Second\");\n\t\t}else{\n\t\t\tboolean jud = rec(two, three, k);\n\t\t\tif(jud){\n\t\t\t\tout.println(\"First\");\n\t\t\t}else{\n\t\t\t\tout.println(\"Second\");\n\t\t\t}\n\t\t}\n\t}\n\t\n\tboolean rec(int b, int c, int k)\n\t{\n\t\tif(d[b][c])return g[b][c];\n\t\td[b][c] = true;\n\t\tif(b == 0 && c == 0){\n\t\t\treturn g[b][c] = false;\n\t\t}\n\t\tfor(int i = 0;i <= k;i++){\n\t\t\tfor(int j = 0;i+j <= k;j++){\n\t\t\t\tfor(int l = 0;i+j+l <= k;l++){\n\t\t\t\t\tif(i == 0 && j == 0 && l == 0)continue;\n\t\t\t\t\tif(b-i >= 0 && c-j-l >= 0 && !rec(b-i+j, c-j-l, k)){\n\t\t\t\t\t\treturn g[b][c] = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn g[b][c] = false;\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tnew D().run();\n\t}\n\t\n\tpublic int ni()\n\t{\n\t\ttry {\n\t\t\tint num = 0;\n\t\t\tboolean minus = false;\n\t\t\twhile((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));\n\t\t\tif(num == '-'){\n\t\t\t\tnum = 0;\n\t\t\t\tminus = true;\n\t\t\t}else{\n\t\t\t\tnum -= '0';\n\t\t\t}\n\t\t\t\n\t\t\twhile(true){\n\t\t\t\tint b = is.read();\n\t\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t}else{\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic long nl()\n\t{\n\t\ttry {\n\t\t\tlong num = 0;\n\t\t\tboolean minus = false;\n\t\t\twhile((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));\n\t\t\tif(num == '-'){\n\t\t\t\tnum = 0;\n\t\t\t\tminus = true;\n\t\t\t}else{\n\t\t\t\tnum -= '0';\n\t\t\t}\n\t\t\t\n\t\t\twhile(true){\n\t\t\t\tint b = is.read();\n\t\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t}else{\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tpublic String ns()\n\t{\n\t\ttry{\n\t\t\tint b = 0;\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\twhile((b = is.read()) != -1 && (b == '\\r' || b == '\\n' || b == ' '));\n\t\t\tif(b == -1)return \"\";\n\t\t\tsb.append((char)b);\n\t\t\twhile(true){\n\t\t\t\tb = is.read();\n\t\t\t\tif(b == -1)return sb.toString();\n\t\t\t\tif(b == '\\r' || b == '\\n' || b == ' ')return sb.toString();\n\t\t\t\tsb.append((char)b);\n\t\t\t}\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn \"\";\n\t}\n\t\n\tpublic char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\ttry{\n\t\t\tint b = 0, p = 0;\n\t\t\twhile((b = is.read()) != -1 && (b == ' ' || b == '\\r' || b == '\\n'));\n\t\t\tif(b == -1)return null;\n\t\t\tbuf[p++] = (char)b;\n\t\t\twhile(p < n){\n\t\t\t\tb = is.read();\n\t\t\t\tif(b == -1 || b == ' ' || b == '\\r' || b == '\\n')break;\n\t\t\t\tbuf[p++] = (char)b;\n\t\t\t}\n\t\t\treturn Arrays.copyOf(buf, p);\n\t\t} catch (IOException e) {\n\t\t}\n\t\treturn null;\n\t}\n\t\n\t\n\tdouble nd() { return Double.parseDouble(ns()); }\n\tboolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tvoid tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "6450185ef3fc84e49decf3fe85f6332f", "src_uid": "69062f7c9b834e925ab23ebc2da96b52", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.StringTokenizer;\nimport java.util.Collections;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Vadim Semenov\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream), 1 << 20));\n TaskF solver = new TaskF();\n solver.solve(1, in, out);\n out.close();\n }\n\n static final class TaskF {\n public void solve(int __, InputReader in, PrintWriter out) {\n String s = in.next();\n String t = in.next();\n int[][] result = solve(s.toCharArray(), t.toCharArray());\n out.println(result.length);\n for (int[] pair : result) {\n out.print(pair[0]);\n out.print(' ');\n out.println(pair[1]);\n }\n }\n\n private int[][] solve(char[] s, char[] t) {\n int[][] result = solveInternal(s, t);\n int[][] anotherResult = solveInternal(t, s);\n if (anotherResult.length < result.length) {\n result = anotherResult;\n for (int[] pair : result) {\n ArrayUtils.swap(pair, 0, 1);\n }\n }\n return result;\n }\n\n private int[][] solveInternal(char[] s, char[] t) {\n List sChangings = getChangings(s, 0, s.length, s, 0, 0, 'a');\n List tChangings = getChangings(t, 0, t.length, t, 0, 0, 'b');\n int[][] result = solveGreedy(s, 0, s.length, s, 0, 0, t, 0, t.length, t, 0, 0, 0, Integer.MAX_VALUE);\n assert result != null;\n int balance = (sChangings.size() - tChangings.size()) / 2;\n for (int i = 0; i < 3; ++i) {\n for (int j = 0; j < 3; ++j) {\n int sp = (balance > 0 ? balance : 0) + i;\n int tp = (balance < 0 ? -balance : 0) + j;\n if ((sp != 0 && sp >= sChangings.size()) || (tp != 0 && tp >= tChangings.size())) continue;\n int sSep = sp < sChangings.size() ? sChangings.get(sp) : 0;\n int tSep = tp < tChangings.size() ? tChangings.get(tp) : 0;\n int[][] current = solveGreedy(t, 0, tSep, s, sSep, s.length, s, 0, sSep, t, tSep, t.length, 1, result.length);\n if (current != null) {\n result = current;\n current[0][0] = sSep;\n current[0][1] = tSep;\n }\n }\n }\n return result;\n }\n\n private int[][] solveGreedy(char[] s1, int s1from, int s1to,\n char[] s2, int s2from, int s2to,\n char[] t1, int t1from, int t1to,\n char[] t2, int t2from, int t2to,\n int offset, int limit) {\n List ss = getChangings(s1, s1from, s1to, s2, s2from, s2to, 'a');\n List tt = getChangings(t1, t1from, t1to, t2, t2from, t2to, 'b');\n int length = Math.max(ss.size(), tt.size());\n if (offset + length >= limit) {\n return null;\n }\n int[][] result = new int[offset + length][2];\n for (int i = 0; i < length; ++i) {\n result[offset + i][0] = pop(ss);\n result[offset + i][1] = pop(tt);\n List tmp = ss;\n ss = tt;\n tt = tmp;\n }\n return result;\n }\n\n private List getChangings(char[] s1, int s1from, int s1to, char[] s2, int s2from, int s2to, char target) {\n List changings = new ArrayList<>();\n for (int i = s2to; i-- > s2from; ) {\n char current = s2[i];\n if (current != target) {\n changings.add(s1to - s1from + i - s2from + 1);\n target = current;\n }\n }\n for (int i = s1to; i-- > s1from; ) {\n char current = s1[i];\n if (current != target) {\n changings.add(i - s1from + 1);\n target = current;\n }\n }\n Collections.reverse(changings);\n return changings;\n }\n\n private static int pop(List stack) {\n return stack.isEmpty() ? 0 : stack.remove(stack.size() - 1);\n }\n\n }\n\n static class InputReader {\n private final BufferedReader reader;\n private StringTokenizer tokenizer;\n\n public InputReader(InputStream in) {\n reader = new BufferedReader(new InputStreamReader(in));\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(readLine());\n }\n return tokenizer.nextToken();\n }\n\n public String readLine() {\n String line;\n try {\n line = reader.readLine();\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n return line;\n }\n\n }\n\n static class ArrayUtils {\n private ArrayUtils() {\n }\n\n public static void swap(int[] array, int i, int j) {\n int tmp = array[i];\n array[i] = array[j];\n array[j] = tmp;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a411706c5dfe4f2406f285071b65be12", "src_uid": "4a50c4147becea13946272230f3dde6d", "difficulty": 2800.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.LinkedList;\nimport java.util.Locale;\nimport java.util.Queue;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\npublic class Solution implements Runnable {\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st;\n\n\tString nextToken() throws Exception {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tint nextInt() throws Exception {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws Exception {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws Exception {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\t\n\tString s;\n\tint q;\n\t\n\tint f(int q, int t) {\n\t\tif (t == 0 || q > 1) return q;\n\t\treturn 1 - q;\n\t}\n\t\n\tint token() {\n\t\tif (s.charAt(q) == '(') {\n\t\t\tq++;\n\t\t\tint t1 = token();\n\t\t\tchar op = s.charAt(q++);\n\t\t\tint t2 = token();\n\t\t\tq++;\n\t\t\tswitch (op) {\n\t\t\tcase '&':\n\t\t\t\tif (t1 == 0 || t2 == 0) return 0;\n\t\t\t\tif (t1 == 1) return t2;\n\t\t\t\tif (t2 == 1) return t1;\n\t\t\t\tif (t1 == 2 && t2 == 2) return 2;\n\t\t\t\treturn 3;\n\t\t\tcase '|':\n\t\t\t\tif (t1 == 1 || t2 == 1) return 1;\n\t\t\t\tif (t1 == 0) return t2;\n\t\t\t\tif (t2 == 0) return t1;\n\t\t\t\tif (t1 == 2 && t2 == 2) return 2;\n\t\t\t\treturn 3;\n\t\t\tcase '^':\n\t\t\t\tif (t1 < 2) return f(t2, t1);\n\t\t\t\tif (t2 < 2) return f(t1, t2);\n\t\t\t\tif (t1 == t2) return 2;\n\t\t\t\treturn 3;\n\t\t\t}\n\t\t\treturn -1;\n\t\t} else {\n\t\t\tif (s.charAt(q) == '?') {\n\t\t\t\tq++;\n\t\t\t\treturn 3;\n\t\t\t}\n\t\t\treturn s.charAt(q++) - '0';\n\t\t}\n\t}\n\t\n\tvoid solve() throws Exception {\n\t\tint n = nextInt();\n\t\ts = nextToken();\n\t\tq = 0;\n\t\tint res = token();\n\t\tout.println(res != 3? \"NO\" : \"YES\");\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\t// Locale.setDefault(Locale.UK);\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t// in = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\t// out = new PrintWriter(\"output.txt\");\n\t\t\tsolve();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t} finally {\n\t\t\tout.close();\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\t// new Thread(null, new Solution(), \"1\", 1 << 28).start();\n\t\t(new Solution()).run();\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c7b7b98ddb40376cf3fe19cbd5bed0de", "src_uid": "e060d26dc3b9ffb628f2380781d1cbe9", "difficulty": 2600.0} {"lang": "Java 6", "source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class Main {\n public static void main(String[] args) {\n Scanner cin = new Scanner(System.in);\n int N = cin.nextInt();\n int K = cin.nextInt();\n long ans = (new Solver(N, K)).solve();\n System.out.println(ans);\n }\n}\n\nclass Solver {\n int N, K;\n long[][][] big, small; \n static long[][] comb;\n static final int Mod = 1000000000 + 7;\n static {\n comb = new long[13][13];\n for (int i = 0; i <= 12; ++i) {\n for (int j = 0; j <= i; ++j) {\n if (j == 0 || j == i) {\n comb[i][j] = 1;\n }\n else {\n comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % Mod;\n }\n }\n }\n }\n Solver(int N, int K) {\n this.N = N;\n this.K = K;\n big = new long[N + 1][K + 1][1 << 4];\n small = new long[N + 1][K + 1][1 << 4];\n for (int i = 0; i <= N; ++i) {\n for (int j = 0; j <= K; ++j) {\n for (int k = 0; k < 16; ++k) {\n big[i][j][k] = small[i][j][k] = -1;\n }\n }\n }\n }\n long solve() {\n long res = calcBig(N, K, 15);\n for (int i = K; i >= 1; --i) {\n res = res * i % Mod;\n }\n return res;\n }\n long calcBig(int size, int count, int mask) {\n if (count < 0) {\n return 0;\n }\n if (big[size][count][mask] != -1) {\n return big[size][count][mask];\n }\n long res = 0;\n if (mask == 15) {\n res += 2 * calcBig(0, count - 2, 0);\n }\n for (int i = 0; i < 4; ++i) {\n int j = (i + 1) & 3;\n if ((mask >> i & 1) == 1 && (mask >> j & 1) == 1) {\n int nxt = mask ^ (1 << i) ^ (1 << j);\n for (int k = nxt; ; k = (k - 1) & nxt) {\n res += calcSmall(size, count - 1 - Integer.bitCount(k), nxt - k);\n if (k == 0) {\n break;\n }\n }\n }\n }\n int nxt = mask;\n for (int k = nxt; ; k = (k - 1) & nxt) {\n res += calcSmall(size, count - Integer.bitCount(k), nxt - k);\n if (k == 0) {\n break;\n }\n }\n return big[size][count][mask] = res % Mod;\n }\n long calcSmall(int size, int count, int mask) {\n if (count < 0) {\n return 0;\n }\n if (small[size][count][mask] != -1) {\n return small[size][count][mask];\n }\n if (size == 0) {\n return count == 0 ? 1 : 0;\n }\n long res = 0;\n int maxCount = Integer.bitCount(mask) * 3;\n int pairCount = 0;\n for (int i = 0; i < 4; ++i) {\n int j = (i + 1) & 3;\n if ((mask >> i & 1) == 1 && (mask >> j & 1) == 1) {\n pairCount++;\n }\n }\n for (int i = 0; i <= pairCount; ++i) {\n for (int j = 0; j <= maxCount - i * 2; ++j) {\n res += calcBig(size - 1, count - i - j, mask) * comb[pairCount][i] % Mod * comb[maxCount - i * 2][j] % Mod;\n }\n }\n return small[size][count][mask] = res % Mod;\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c8b15d56c052bcfe8f2485292747db28", "src_uid": "fa649fed687d72b1431ac82bc7288116", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.io.OutputStreamWriter;\nimport java.util.NoSuchElementException;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Iterator;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.Writer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author aryssoncf\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 FLongNumber solver = new FLongNumber();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class FLongNumber {\n final int MOD = MiscUtils.MOD7;\n\n long parse(char[] str, int mod) {\n long res = 0;\n for (char c : str) {\n res = (10 * res + c - '0') % mod;\n }\n return res;\n }\n\n char[] subArray(char[] str, int begin, int end) {\n return (new String(str, begin, end - begin)).toCharArray();\n }\n\n long magic(long a, long len, long n7, long n6) {\n long q = IntegerUtils.power(10, len, MOD);\n if (q == 1) {\n throw new ArithmeticException();\n }\n long q2n = IntegerUtils.power(q, n6, MOD);\n long num = a * q2n % MOD * q % MOD + (1 - a) * q2n % MOD - (a + n7) * q % MOD + a + n7 - 1;\n num = IntegerUtils.trueMod(num, MOD);\n long den = IntegerUtils.trueMod((q - 1) * (q - 1), MOD);\n return num * IntegerUtils.reverse(den, MOD) % MOD;\n }\n\n Number interval(char[] A, char[] B) {\n long value = 0, pow10 = 1;\n for (int len = A.length; len <= B.length; len++) {\n long a7 = len == A.length ? parse(A, MOD) : IntegerUtils.power(10, len - 1, MOD);\n long a6 = len == A.length ? parse(A, MOD - 1) : IntegerUtils.power(10, len - 1, MOD - 1);\n long b7 = len == B.length ? parse(B, MOD) : (IntegerUtils.power(10, len, MOD) - 1 + MOD) % MOD;\n long b6 = len == B.length ? parse(B, MOD - 1) : (IntegerUtils.power(10, len, MOD - 1) + MOD - 2) % (MOD - 1);\n long n7 = (b7 - a7 + 1 + MOD) % MOD, n6 = (b6 - a6 + MOD) % (MOD - 1);\n long mult = IntegerUtils.power(10, len * n6, MOD);\n value = (value * mult % MOD + magic(a7, len, n7, n6)) % MOD;\n pow10 = pow10 * mult % MOD;\n }\n return new Number(value, pow10);\n }\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n char[] str = in.readString().toCharArray();\n IntList[] plus = new IntList[str.length + 1];\n Arrays.setAll(plus, i -> new IntArrayList());\n int deep = 0;\n for (int i = 0; i < str.length; i++) {\n if (str[i] == '(') {\n deep++;\n } else if (str[i] == ')') {\n deep--;\n } else if (str[i] == '+') {\n plus[deep].add(i);\n }\n }\n long res = parseExpression(str, 0, str.length, plus, 0).value;\n out.printLine(res);\n }\n\n Number parseExpression(char[] str, int begin, int end, IntList[] plus, int height) {\n int idx = MiscUtils.binarySearchInt(0, plus[height].size(), i -> i == plus[height].size() || plus[height].get(i) >= begin);\n if (idx < plus[height].size() && plus[height].get(idx) < end) {\n int pos = plus[height].get(idx);\n return parseTerm(str, begin, pos, plus, height).concat(parseExpression(str, pos + 1, end, plus, height));\n }\n return parseTerm(str, begin, end, plus, height);\n }\n\n Number parseTerm(char[] str, int begin, int end, IntList[] plus, int height) {\n for (int i = begin; i < end; i++) {\n if (str[i] == '(') {\n return parseExpression(str, i + 1, end - 1, plus, height + 1).exp(subArray(str, begin, i));\n }\n }\n for (int i = begin; i < end; i++) {\n if (str[i] == '-') {\n return interval(subArray(str, begin, i), subArray(str, i + 1, end));\n }\n }\n return new Number(parse(subArray(str, begin, end), MOD), IntegerUtils.power(10, end - begin, MOD));\n }\n\n class Number {\n long value;\n long pow10;\n\n Number(char ch) {\n value = ch - '0';\n pow10 = 10;\n }\n\n Number(long value, long pow10) {\n this.value = value;\n this.pow10 = pow10;\n }\n\n Number concat(Number other) {\n return new Number((value * other.pow10 + other.value) % MOD, pow10 * other.pow10 % MOD);\n }\n\n Number exp(char[] n) {\n long ratio = pow10;\n long ratio2n = IntegerUtils.power(ratio, parse(n, MOD - 1), MOD);\n long ratio_1 = (ratio + MOD - 1) % MOD;\n if (ratio == 1) {\n return new Number(value * parse(n, MOD), ratio2n);\n }\n long inv = IntegerUtils.reverse(ratio_1, MOD);\n return new Number(value * (ratio2n + MOD - 1) % MOD * inv % MOD, ratio2n);\n }\n\n }\n\n }\n\n static abstract class IntAbstractStream implements IntStream {\n public String toString() {\n StringBuilder builder = new StringBuilder();\n boolean first = true;\n for (IntIterator it = intIterator(); it.isValid(); it.advance()) {\n if (first) {\n first = false;\n } else {\n builder.append(' ');\n }\n builder.append(it.value());\n }\n return builder.toString();\n }\n\n public boolean equals(Object o) {\n if (!(o instanceof IntStream)) {\n return false;\n }\n IntStream c = (IntStream) o;\n IntIterator it = intIterator();\n IntIterator jt = c.intIterator();\n while (it.isValid() && jt.isValid()) {\n if (it.value() != jt.value()) {\n return false;\n }\n it.advance();\n jt.advance();\n }\n return !it.isValid() && !jt.isValid();\n }\n\n public int hashCode() {\n int result = 0;\n for (IntIterator it = intIterator(); it.isValid(); it.advance()) {\n result *= 31;\n result += it.value();\n }\n return result;\n }\n\n }\n\n 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 String readString() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n if (Character.isValidCodePoint(c)) {\n res.appendCodePoint(c);\n }\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n boolean isSpaceChar(int ch);\n\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void printLine(long i) {\n writer.println(i);\n }\n\n }\n\n static interface IntStream extends Iterable, Comparable {\n IntIterator intIterator();\n\n default Iterator iterator() {\n return new Iterator() {\n private IntIterator it = intIterator();\n\n public boolean hasNext() {\n return it.isValid();\n }\n\n public Integer next() {\n int result = it.value();\n it.advance();\n return result;\n }\n };\n }\n\n default int compareTo(IntStream c) {\n IntIterator it = intIterator();\n IntIterator jt = c.intIterator();\n while (it.isValid() && jt.isValid()) {\n int i = it.value();\n int j = jt.value();\n if (i < j) {\n return -1;\n } else if (i > j) {\n return 1;\n }\n it.advance();\n jt.advance();\n }\n if (it.isValid()) {\n return 1;\n }\n if (jt.isValid()) {\n return -1;\n }\n return 0;\n }\n\n }\n\n static interface IntFilter {\n public boolean accept(int value);\n\n }\n\n static interface IntReversableCollection extends IntCollection {\n }\n\n static interface IntList extends IntReversableCollection {\n public abstract int get(int index);\n\n public abstract void addAt(int index, int value);\n\n public abstract void removeAt(int index);\n\n default public IntIterator intIterator() {\n return new IntIterator() {\n private int at;\n private boolean removed;\n\n public int value() {\n if (removed) {\n throw new IllegalStateException();\n }\n return get(at);\n }\n\n public boolean advance() {\n at++;\n removed = false;\n return isValid();\n }\n\n public boolean isValid() {\n return !removed && at < size();\n }\n\n public void remove() {\n removeAt(at);\n at--;\n removed = true;\n }\n };\n }\n\n default public void add(int value) {\n addAt(size(), value);\n }\n\n }\n\n static final class PrimitiveHashCalculator {\n private PrimitiveHashCalculator() {\n }\n\n public static int getHash(long x) {\n return (int) x ^ (int) (x >>> 32);\n }\n\n }\n\n static class IntArrayList extends IntAbstractStream implements IntList {\n private int size;\n private int[] data;\n\n public IntArrayList() {\n this(3);\n }\n\n public IntArrayList(int capacity) {\n data = new int[capacity];\n }\n\n public IntArrayList(IntCollection c) {\n this(c.size());\n addAll(c);\n }\n\n public IntArrayList(IntStream c) {\n this();\n if (c instanceof IntCollection) {\n ensureCapacity(((IntCollection) c).size());\n }\n addAll(c);\n }\n\n public IntArrayList(IntArrayList c) {\n size = c.size();\n data = c.data.clone();\n }\n\n public IntArrayList(int[] arr) {\n size = arr.length;\n data = arr.clone();\n }\n\n public int size() {\n return size;\n }\n\n public int get(int at) {\n if (at >= size) {\n throw new IndexOutOfBoundsException(\"at = \" + at + \", size = \" + size);\n }\n return data[at];\n }\n\n private void ensureCapacity(int capacity) {\n if (data.length >= capacity) {\n return;\n }\n capacity = Math.max(2 * data.length, capacity);\n data = Arrays.copyOf(data, capacity);\n }\n\n public void addAt(int index, int value) {\n ensureCapacity(size + 1);\n if (index > size || index < 0) {\n throw new IndexOutOfBoundsException(\"at = \" + index + \", size = \" + size);\n }\n if (index != size) {\n System.arraycopy(data, index, data, index + 1, size - index);\n }\n data[index] = value;\n size++;\n }\n\n public void removeAt(int index) {\n if (index >= size || index < 0) {\n throw new IndexOutOfBoundsException(\"at = \" + index + \", size = \" + size);\n }\n if (index != size - 1) {\n System.arraycopy(data, index + 1, data, index, size - index - 1);\n }\n size--;\n }\n\n }\n\n static class IntegerUtils {\n public static long trueMod(long a, long b) {\n a %= b;\n a += b;\n a %= b;\n return a;\n }\n\n public static long power(long base, long exponent, long mod) {\n if (base >= mod) {\n base %= mod;\n }\n if (exponent == 0) {\n return 1 % mod;\n }\n long result = power(base, exponent >> 1, mod);\n result = result * result % mod;\n if ((exponent & 1) != 0) {\n result = result * base % mod;\n }\n return result;\n }\n\n public static long reverse(long number, long modulo) {\n return trueMod(extGcd(number, modulo).first, modulo);\n }\n\n public static EzLongLongLongTriple extGcd(long a, long b) {\n long x2 = 1, y2 = 0, x1 = 0, y1 = 1, x, y, r2, r1, q, r;\n for (r2 = a, r1 = b; r1 != 0; r2 = r1, r1 = r, x2 = x1, y2 = y1, x1 = x, y1 = y) {\n q = r2 / r1;\n r = r2 % r1;\n x = x2 - q * x1;\n y = y2 - q * y1;\n }\n return new EzLongLongLongTriple(x2, y2, r2);\n }\n\n }\n\n static class MiscUtils {\n public static final int MOD7 = (int) (1e9 + 7);\n\n public static int binarySearchInt(int from, int to, IntFilter function) {\n while (from < to) {\n int argument = from + ((to - from) >> 1);\n if (function.accept(argument)) {\n to = argument;\n } else {\n from = argument + 1;\n }\n }\n return from;\n }\n\n }\n\n static class EzLongLongLongTriple implements Comparable {\n private static final int HASHCODE_INITIAL_VALUE = 0x811c9dc5;\n private static final int HASHCODE_MULTIPLIER = 0x01000193;\n public long first;\n public long second;\n public long third;\n\n public EzLongLongLongTriple(long first, long second, long third) {\n this.first = first;\n this.second = second;\n this.third = third;\n }\n\n public boolean equals(Object o) {\n if (this == o) return true;\n if (o == null || getClass() != o.getClass()) return false;\n EzLongLongLongTriple that = (EzLongLongLongTriple) o;\n\n return first == that.first && second == that.second && third == that.third;\n }\n\n public int hashCode() {\n int hash = HASHCODE_INITIAL_VALUE;\n hash = (hash ^ PrimitiveHashCalculator.getHash(first)) * HASHCODE_MULTIPLIER;\n hash = (hash ^ PrimitiveHashCalculator.getHash(second)) * HASHCODE_MULTIPLIER;\n hash = (hash ^ PrimitiveHashCalculator.getHash(third)) * HASHCODE_MULTIPLIER;\n return hash;\n }\n\n public int compareTo(EzLongLongLongTriple o) {\n int res = Long.compare(first, o.first);\n if (res == 0) {\n res = Long.compare(second, o.second);\n if (res == 0) {\n res = Long.compare(third, o.third);\n }\n }\n return res;\n }\n\n public String toString() {\n return \"(\" + first + \", \" + second + \", \" + third + \")\";\n }\n\n }\n\n static interface IntIterator {\n public int value() throws NoSuchElementException;\n\n public boolean advance();\n\n public boolean isValid();\n\n }\n\n static interface IntCollection extends IntStream {\n public int size();\n\n default public void add(int value) {\n throw new UnsupportedOperationException();\n }\n\n default public IntCollection addAll(IntStream values) {\n for (IntIterator it = values.intIterator(); it.isValid(); it.advance()) {\n add(it.value());\n }\n return this;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "eff291af91b2ef932b9f262fbeb2c6ba", "src_uid": "0617f1ffa520d5b96232a4cfd9a15d0c", "difficulty": 3400.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class R2_D2_D\n\n{\n static double epsilon = 1e-9;\n\n public static void main(String[] args) throws IOException {\n InputReader in = new InputReader(System.in);\n int n = in.readInt();\n int k = in.readInt();\n int h = in.readInt();\n int[] hs = new int[k];\n for (int i = 0; i < hs.length; i++) {\n hs[i] = (i + 1) * h;\n }\n p[] all = new p[n];\n for (int i = 0; i < n; i++) {\n all[i] = new p(in.readInt(), 0);\n all[i].id = i + 1;\n }\n for (int i = 0; i < n; i++) {\n all[i].v = in.readInt();\n }\n Arrays.sort(all);\n double lo = 0;\n double hi = 10000000000.0;\n ArrayList out = new ArrayList();\n ArrayList res = new ArrayList();\n int m = 0;\n double result = 0;\n while (m < 100) {\n out = new ArrayList();\n m++;\n double t = (hi + lo) / 2;\n int limit = 0;\n boolean flag1 = true;\n for (int i = k - 1; i >= 0; i--) {\n double v = hs[i] / t;\n boolean flag = false;\n for (int j = limit; j < n; j++) {\n if (all[j].v - v > epsilon) {\n limit = j + 1;\n out.add(all[j].id);\n flag = true;\n break;\n }\n }\n if (!flag) {\n flag1 = false;\n break;\n }\n }\n if (flag1) {\n result = t;\n res = out;\n hi = t;\n } else {\n lo = t;\n }\n }\n System.out.println(res.get(res.size()-1));\n for (int i = res.size() - 2; i >= 0; i--)\n System.out.print(\" \"+res.get(i));\n }\n\n static class p implements Comparable

{\n int w;\n int v;\n int id;\n\n public p(int a, int b) {\n w = a;\n v = b;\n }\n\n public int compareTo(p o) {\n if (w < o.w)\n return 1;\n if (w > o.w)\n return -1;\n return o.v - v;\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1000];\n private int curChar, numChars;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n private int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int readInt() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public long readLong() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public String readString() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuffer res = new StringBuffer();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n private boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n private String readLine0() {\n StringBuffer buf = new StringBuffer();\n int c = read();\n while (c != '\\n' && c != -1) {\n buf.appendCodePoint(c);\n c = read();\n }\n return buf.toString();\n }\n\n public String readLine() {\n String s = readLine0();\n while (s.trim().length() == 0)\n s = readLine0();\n return s;\n }\n\n public String readLine(boolean ignoreEmptyLines) {\n if (ignoreEmptyLines)\n return readLine();\n else\n return readLine0();\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\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4b722c11a5e98779ae92cbb81c142a1e", "src_uid": "6861128fcd83c752b0ea0286869901c2", "difficulty": 2000.0} {"lang": "Java 11", "source_code": "\r\nimport java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\nimport java.util.ArrayList;\r\nimport java.util.HashMap;\r\nimport java.util.StringTokenizer;\r\n\r\npublic class GTest {\r\n\t/*\r\n\r\noooooooooooooooooooooooooooooooooooooooooooooooooddxxxxxxxkxxxxddoooooddxdddddddoodddddddddddddddddddxdddddooolllllllllllllllllllllooooolllllllllclllllllcccccccllloodddddddddddddddddxxxdoooooooooooodddooollllllllllllllccllllllllllllllllllllllllllllllllllllllllllloodddddxxddddoooooddxxxxxdddooooooooo\r\nooooooooooooooooooooooooooooooooooooooooooodddddddxxkkxxkkkxxxxddooooddxxxxxxxxddddxxxxxxxxxddxxxxxxxxxxxxxxxddooooooolllllllllllooooooooooooooolllllllllllllllllooddxxxxxxxxxxxxxxxxxkkxxdooooooooooodddoooooooooooooolllllllllllllllllllllllllllllllllllloodddddddoooddxxxxkkkxxxxddodddxxkkkkxxxddddddddd\r\ndddddddddddddddddddddddddddddddddddddddddxxxxxxxxxkkkkOOkkxxxdddddddoddxxxkkkkkxxxxxkkxxxkkkxxkkkkkkkkkkkkkkkkxddooooooooooollloodddddddddddddddooollllllllllooodddxxxxxxxxxkxxxkkkkkkkkkkxxdddddddddddddooddddddddxxxdddddoolllllllllllllllllooooodddddddddxxxxxxxxxxxxxxkkkkkkkkkkxxdddxxkkkOkkkkkkxxddddd\r\nddddddddddddddddddddddddddddddddddddddxxkkkkkkkkkkkkkkkkkxxddddddddddddxxkkkkkxxxxxxkkkxxkkkkkkkkkkkkkkkkkkkkkxddddoooooooooooooooddxxxxxxxxxxdddoooooooloodddddxxxxxxkkxxxkkkxkkkkkxkkkkkkkkxxxxxddddddddddxxxxxxxxxxdddxxdooooooooooooooooooddxxxxxxxxxxxxxxxxxkkkkkkxxkkkOOOkkOOOkkxxxxxkkOOOOOOOOOkxxxxx\r\nddddxddddddddddddddddddddddddddddddxxkkkkkkkOOOkkkkOOOkxxxxxddddddddxxxxkkkkkkkxxkkkkkkkkkkkkkkOOOOOkkOOOOkkkxxdddddddooooooooooooddddodddddddddddoooooooodxdddxkkkkkkOOkkkOOOkOOOOOkOOOOOOOOOkkkkkxdddddddxxxkxxkkxxxxxxxxddoooooooooooooooddxxxxkkkkkkkkkkkkxxkkkkkkkkkkOOOOOOOOOOOkkxxxxkkOO00OOOOOkxxxxx\r\nxxxxxxxxdddddddddddddddddxxxxdxxxxxxkkOOOOkkOOkkkkOOOOkkxxxxxddxxxkkkkkkkkOOOkkkkkkkOOOOOOOOOOOOOOOOOOOOOOkkxxdddddddddooooooooooddoolc::::ccclooooooooodddxxdxxkkkxkkkkkkkOOkkkOOOkkOOOOOOOOOkkkOOkxdddddxxkkkkkkkkkkxxxxddoooooooooooooooooddxxxxxkkkxxkkkkxxkkkkkkOkkkkOOOOO00000OkkkkkxkkkOOOO00OOkkkkkk\r\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxkkOOOOOOOkkkkOOOOkxxxxxdxxkkkkkkOOOOOOOOOkxkkkkkkOOOOOOOOOOOOOOOOOOkkxxxdddddddddoooooddddddolooc:;,,,,;:::::::cccccclooddxkkkkkkkkkkkOOkkkOOOkkkOOOOOOOkkkkOkkxddddxxkkkkxxkkkkxxxxxddooooooooooooooooooddxxkkkkkkkkkkkkkkkkkkOOOkkOO00OOO00OOkkkkkkkkxxkkkOO00OOOOOOO\r\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxkkkOOkkkOOOOkkxxxxxdxkkkkkkOOOOOOOOOOkkkkOOOOOOOOOOOOOOOkkkkkxxxxxxddxxdddddooooodollol:;;::;;;,'''',''''''',,,'',;;:cloxkkkOOOkOOOOOOOOOOOOOOOOOOOOOkkOOOkxdddxxxkkkkkkkkkxxxxxxddoooooooooooooooooodddxkkkkkkkkkkkkkkOOOOOOOOOO00000000OOkkkkkkxxxxxxxxkkOOOOO000\r\nxxxxxxxxxxxxxxxxxxxxxxxxxxxkkkkkxxxxxxxxxxxxkkkkkOOOkkxxxxxxxxxkkOOOOOOOOOOOOOOkkkOOOOOOOOOOOOOkxxxxxxxxxxxxxxkkxdoooodddoc:;;;;,'''','''.....'..'''''''''',,;;;:coxkkkkkkkOOOkOOOOOkOOOOOOOOOkkkkxxddddddxxxxxxxxxdddddddooooddddoooooooooooooddddxxxkkkkkkkkkkkkkOOOOkkO000000000OOOOkkkxxxxxxxxxkOOOOO000\r\nxxxxxxxxxxxxxxxxxxxxxxxxkkOOOOOOkkxxxxxxxxxxxxkkkkOkkxxxxxxdxxxkkOkkkkkOOOOOOOOkkkOOOOOOOOOOkkkxxxxxxxxxxxxxxkkkdoooooool:,'''',''''''..'.......''''',,,''',,,;;;;:lxkkkkkkOOkkkOOOkkkkkkkkkkxxxxxxddddddddddddddddddooooooodddxddoooooooooooooooooddddxxxxxkkkkkkOOOOOkOOOOOO000000000OOOkkxxxxxxxkOOOOOO00\r\nxxxxxxxxxxxxxxxxxxxxxxkkOO00OO000OOkkxxxxxxxxxxxxxxxxxxxxxddxxxkkOOkkkOOOOOOOOkkkkOOOOOOOOOkxxxxxxxxxxxxxxkkkkkxdooolllc:;,''....................'''',,,,'..'',,,,;cdkOOkkOOOOOOOOOOOOOOOkxxxxxxxxxdddddddddddddddddddooooodxxxxxddddooooooooddooooooooodddddxkkkkOOOOOOOOOOO0000O00000000OkkxxxxxxkkOOOOOO0\r\nxxxxxxxxxxxxxxxxxxxxkkkOOOOOOOOOOOkkkkxxxxxxxddxxxxxddddddxxxxkkkkOOOOOOOOkkkkkkkkxxxkxxxxxxxxxxxxxxxxxxxkOOkxddoolllll:;;;,,''...............''...'''''''....'''',:oxkkkkkOOOOOOOOOkkOOOkkxxxxxdxxdddxxxxxxxddddddddddooddxxxkkxddddoooooooddxddoooooooooodddxxkkkOkkOOkkOOO0000000000000OOkxxxxxxxkkOOOO00\r\nxxxxxxxxxxxxxxxxxxkOOOOOOOOOOOOOOOOOOOkxxxxxxdxxxxxxddxxxxxxkkOOOOOOOOOkOOOOOOkkxxxxxxxxxxxxxxxxxxxxxxxkkkkxdllloool:;,'''''''''...........''''''''''..........''',:oxkkkkkOOOOOOOOOkOOOOkkxxxxxxxxxxxkkOOOkkkkkxxdddddoooddxxkkxddooooooooddxxxxdddddooooooooddxkkkkOOOkkkOOO000000OOOO000OkkxxxxxxxkkOOO0O\r\nxxxxxxxxxxxxxxxxxkOO000000000000000000OkxxxxxxxxxxxxxxxxxxkkOO00OOOOOOOOO000OOkxxxxxxxxxxxxxxxxxxxxxdxkkkkxdooolc:,''.....''''''............'''''''..........''',,;coxxkkkOOOOOOOOOOOOOOOkxxxxxxxxxxxkkOOOkkkOOkkkxxddooooooddxxxdoooooooooddxxkkkxddddddoooooddddxxxxxkxxkkOOOOOOO0000000OOkkxxxxxxxxkkkkkk\r\nxxxxxxxxxxxxxxxxxkOO0OOOOO0O0000OOO00OOkxxxxxxxxxxxxxxxxxkOOOOOOOOOOO00OOOOkkkxxxxxxxxxxxxxxxxxxxxxxxxkkkkxddo:,''.........'''''''.......'''''''''''''''..'''',,,;coddxxxkkOOOOOOOOOOOOkxxxxxxxxxxkkOOOOOOOkOOOkkkkkkxddoooooodddddoooooooodddxxxxxxdddodddoooooooodddddddxkkOOOOOOOOOO000Okkxxxxxxxxxxxxxxx\r\nxxxxxxxxxxxxxxkkkOO00OOOOOOOO00OOOOOOOOkkkxxxxxxxxxxxxxxkOOOOOOOOOOO000Okkxxxxxxxxxxkkkkxxxxxxxxxxxxxxkkkxddl:,''...........'''''''''''''''''''''''''''''''''',;cldddddddxxxkkOOOOkkkxxxxxxxxxxxkOOOOOOO0OOOOOOOOOOOOkxdooooooddddddoooooddddxxkkkkkkxdddddddddddooddddddddxkkOOOOOOOOOOOOOOOkkxxxxxxxxxxxxx\r\nxxxxxxxxxxkkkkOOO000000000000000000000OO0OOkkxxxxxxxxxxxkOOOOOOO00000OOkkxxxxxxxxxkkOOOOOOkkxxxxxxxxxxxkxol:,'''.........'''''''',,,,,,,,,,,,;;;;;;;;;;;;;,,,,;coxxdddddddxxxkkOOkkxxxxxxxxxxkkkkOO0OOOOOOOOOOOkkkkkkkxddooooooddddooodooooddxxkkkkkkkxdddddddddddddddddddddxxkOOO000000000000Okkxxxxxxxxxxx\r\nxxxxxxxkkkkkkOOOOO00OOOOOOOO000OOOOOOOOOOOOOkkxxxxxxxxxxkOO0000000OOOkkxxxxxxxxxxxkOOOOOOOOOkxxxxxddddxdoc;''''''.....'''''''''''',,;;;;:::ccccclllllloolllccccldkkkxkxxxddxxxxxxxxxxxxxxkkkOOOOOO00OOOOOOOOOOOkkkkkkkxxxxxdddddddddddddddoddxkkkkkkkkxddddddddddddddddddddddddxxkkOO000O000000OOkxxxxxxxxxd\r\nxxxxxkkOOOOkkOOOOO00OOOOOOOO000OOOO0OOOOOOOOkkkkkxxxxxxxkOO000OOOkkkxxxxxxxxxxxxxxkOOOOOOOOOOOOkkxxdddddol:,'''''.....''''''''''',,;;::ccllllllooooooooodddooooodxkkkkkkxxxxxxxxxddxxxkkOOOOOOOkOOOOOOOOOOOOOOOOkkkOkkkkkkkxxdddddddooooddoddxxkkkkkkxxddddddddddxxkkxxxddddddddddxkOO00000000000Okxxxxxxxdd\r\nxxxxxkOOOOOOOOOOO0000O000000000000000000000OOOOOOkxxxxxxxkkkkkxxxxxxxdddxxxxxxxxkkOOOOOOOOOOkOOOOkxxdddooc,'''.......''''''''''',,;:ccccllllllllooooooooooddooooodxkkkkkxxdddddxxddddxxkkkkkOOkkkkOOOkkkkkkkkkkkkkkkkkxxkkkxxxddddddooooddddddxkkkOOkxdddddddddxxkkkkkkxxdddddddddxxkOOOO00000000Okxxxxxxddd\r\nxxxxkkOOOOOkOOOOOO0OOOOOOOOO0000O0000OO000OOOOOOkkxxxxxxxxxxxxdddddxxdddxxxdxxxkkOOOOOOOOOOkkOOOOkxxddool;,''.......'''''''''',,,;::ccccclllllllllooooooooooooooooxkkOOOkxxxddddddxxxxkOOOOOOOOkkOOOOOOOOOkkkkOkkkkkkkkkkkkxxxddddddooooddooddxkkkkkxddddddxxxxxkkkkkkkkxddddddddddxxxkkO00000000Okxxxxddddx\r\nxxxxxkOOOOkkOOOOOO0OOOOOOOOO00OOOO00OOOOOOOOkkkkkxxxxxxxxxxxxxxxxxddddxxxxxxxxkkOOOkOOOOOOOOOOOOkkxdddoo:,''.........'''''''',,,;;::cccccllllllooooooooooooooooooodkkOOOkkkkxddddxxkkkOOOOOOOOOkkOOOOOOOOOkkkOOOkkkOOkkkkkkkxxddddddooooodooddxkkkxxdddddxxxxxxxxkkkkkkxxddddddddddddxxxkkOOO0000Okxxxddddxx\r\nxxxxxkOO0OOOOO0O00000000O000000000000000000OOkkkxxxxxxxxxxxxxxxxxkkkkkxxxxxxxxkkOOOOOOOOOOOOOkxxxxdddddl:,''.........'''''''',,,;;;::ccccccllllooooooooooooooooooodkkOOOkkkkxxdxxxkkkkOOOOOOOOOkkkOOkkkkkkkkkkkkkkkkkkkkkkxxddoooddoooooooooddxkkxddddddddxxkkxxxkkkkkkkxxxxxdddddddddxxxxxxkkkOkkxxddddddxk\r\nxxxxxkkOOOOOOOOO0000OO0OO00000000000000000OOOkxxxxxxxxxxxxxdxxxxkkOOOOOkkkxxxxxxkkkOOOOOOOOOkkxxxxxxxddl:,''.........'''''''',,,,;;::ccccccclllloooooooooooooooooodkkOOkkxxxxxxxxxxxxkkOOOOOOOOkkkOOkkkkOkkkkOOOkkkkOkkkkkkxdddddddddoooooooddddddoodddooddxxxxxkkkkkkkxxxxxxxddddddddddxxxxxxxxxdddddddddxk\r\nxxxxxkkOOOkkOOOOO00OOOOOOOOO000OO00OOOO00OOOkkxxxxxxxxxxxxxxddxxxkOOOOOOOOOkxxxxxxxxkkOOOOOOkxxxxxxxxxdc;,'...........'''''''',,;;:::ccccccclllllllllllllloooooooooxkkkkxxddxxxddxxddxkkOOOOOOOkkkOOOkkkOOkkkOOOOOOOOOkkkkkkxxdddddddooooooddddoooddxxddddddddxxkkkkkkkkxxxxkxdddddddddddxxxxdddddddddddddxx\r\nxxxxkkOOOOOOOOOO00000000000000000000000000OOOkkkxxxxxxxxkkkxxdxxxxkkOOOOOOOkxxxxxxxxxkkkOOOkxxxxxxxkkdl:,'''...........'''''',,;;:::ccccccc:cccc::::::::::ccllllccclxkkxxdddddddddxdxxkkkkkkOOkkxkkkkkkkkkkkkkOkkkkkkkkkkkkkkxxddddddoooddddddddddxxxxxddddddddxxkxxxkkkxxxxxddddddxxxkkxxxddddddddddddddddx\r\nxxxkkOOOOOkOOOOO000000000O0000000000O0000OOOOOOkxxxxxxxkkOOOkxxxxxxkkOOOO0OkkxxxxxxxxxxxxkkxxxxxxkkOkxl;,'''..........'''''',,;;::ccccc:::::::ccccllcccccccclllcc:codxxxddddxxxxxxdddxxxkkkOOOOkkkkkkkkkOOkkkkOkkkkkOkkkkkkkxxxddddddoooddddddddddxkkkkxxddddddxxkkkkkxxdddddodddxxkkkkkkxxddddddddddddddddx\r\nxxxkOOOOOkkOOOOOO0OOOOOOOOOOOOOOOOOOOOOOOOOOkkOkkxxxxxxkkOOOkkxxxxxxkkOOOOkkxxxkkxxxxxxxxxxxxxkkOOO0Oxo;''''..'''''''...''''',;;:::ccccccccccccccc:::ccllllllllc:coddddddddxxkkkkxxddddddxxxxkkxxkkOkkkOOOOkOOOOOkOOOOkkkkkkkxddddddddoooddddddddxkkkkkkxdddddddxxkkkxxdddddddddxkkkkkkOkxxddddddddddddddddd\r\nxxxkOOOOOOkOOOO0000000OOOO0000OO000OOO000OOOOOOOkxxxxxkkOOOOOkxxxxxxxxkkOkxxxxkkkkkkkkxxxxxxxxkkOOOOOxo:,''''',;::::;;,,''',,,;;::cccccccllllllcccccllloolllllllloddddddxxkkOOkkkkkxddddddddddddxxkkkkkkkkkkkkkkkkkkkkkkkkkxdddddddddoodoodddddxkkkkkkkkkkxdddddddddddddddodddddxkkkkkkkxxdddddxxxdddddddddx\r\nxxxkOOOOOkkOOOOO000OOOOOOO0000OO000OOO00OOOOOOkkxxxxxxkkOO00OOkxxxxxxxxxxxxxxxkOOOOOOOkxxxxxxxkkOOOOOkxl;,''';:::c::::::;,,,,;;:::ccccccllllllolooooooooolllllllodddddxkkkOOOOOOOOOOkxxddddddddddddxxkkkOOkkkkOkkkkkkkxxddddoooooddddoooooddddxkkOOOkkOOOOkkxdddddddoodddddddoddxkkkkkkxdddddxxkkkxddddddddx\r\nxxxxkkOOkkkOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOkkkxxxxddddxxkOOOOOkkxxxxxxxxxxxxxxxkOOOOOOOOOOOkxxxkkO000OOkdl;,',::::cc:::cc::;;;;::::ccccccccllllloooooooooollllllllodddxkkkkOOOOOOOOOOOkkkxddddddddddddxxkkOkkkOOOOkOOOOkxddddooodddddooodddddddxxkkkkkkkOkkkkkxdddddddddxxxdddddddxkkkxddddddxxkkkxxxdddddddx\r\nxxxxxxkkkkkOOOOOOOOOOOOOOO000OOOOOOOOOOOkkkxxxddddxxxkkOOOOOOOOOkkxxxxddxxxxxxkOOOOOO0000OOkxxkkOOOOOOkxoc;,,:::ccc:::::c::::::::::::cccccclllllooooooooollcccclllddxxkkkkkOOOkkOOOkkkkkkxdddddddddddddxxkkkkkkkkkkkkkxddddoooddxxddoooooodoodxxkkOOkkOOOOOOkxddddddxxkkkkxxddddddxxxdddddddxkkkkkkkxddddddx\r\nxxxxxxxxxxxxxxkOOOOOOOOOOOOOOOOOOOkkxxxxxxxxddddxxkkOOOOOOOOOOOOOkkkkxxddxxxxkOOOOOOOOOOOOOkxxxkkOOOOOkkxoc;,;::ccccc:::cc:::::::::::::ccccccllllooooooollccccllllodxxkkkkkOOOOkOOOOOOOOkkddddddddddoodddxxkkkkkkkkkxxdddooooddxxddooodooooooddxkOOkkkOOOOOOkxdddxkkOOOkkkkxxdddddddddddddddxkkkkOOkxddddddx\r\nxxxxxxxxxxxxxxkkOOOOOOOOOOOOOOOOOkxxdxxxddddddddxxkkkkkkkkkOOOOOOOOOOkxxxxxxxkOOOOOOOO0000OOkxxxkOOOOOOOkxl:,,,;:cccccc::c::::::::::::::cccccclllllooooolc:cc::::codxkkkkkkOOOkkkOOOkkkOkkxdddddoooooooddxxkkkkkkxxddddoooddxxkkkxdddddddddddddxkkkkkkkkkkkkxdddxkkOOOOOkkkxxxdddddddddddddxkkkkkkkxdddddddd\r\nxxxxxxxxxxxxxxkkOOOOOOOOOOOOOOOOOkxxxxxxdddddddddxxxxxxdddxxkkkkkkkkkxxxddxxxxkOOOOOOO0000OOkxxxkOOOOOOOOkdl:,,,;::ccclccc::::::::::::::cccccclllllooooollcccc:ccodxxkkkkkkkkkkkkkkkkkkkkkxxkkxdddddooooodddddddddoooooooddxxxxkkxddoodddddddddxkkkkkkOOOOOkxddxxkkkOOOOOOkkkkxdddddddddxxkkOOOkkOOkxddddddd\r\nxxxxxxxxxxxxxxxkkOOOOOOOOOOOOOOkkxxxxxxddddddddddddddddddddddddxxddddddddddddxxkOOOOOOOOOOOOOkxxkkOOOOOOOOkdl;,,;:::ccccc::::::::::::::ccccccclllllooooooolooooooxkxxkkkkkkOOOOOOOOkkkkkkkkkkkkxxxkkxdooooooooodoooooooooddddxxkkxddooooddoooddxkkkkkkOOOOOkxddxkkOOOOkOOOkkOOOxxddddxxkkkkOOOOOkOOOkkxxdddd\r\nxxxxxxxxxxxxxxxxxkkOOOOOOOOOkkxxxxdddxxxddddddddddddddddddddddddddddddddddddddxxkOOOOOOOOOO0OkxxxkOOOOOOOOOkdc;;:::::::::::::::::::::::ccccccclllllllllllooooooodxxxxkkkkkkOOOkOOOOOkkkkkkkkkkkxxxkkkxdoooooodddddddooooooooooddxxxdooooooododdxkkkkkkkkkkkxdddxkkOOOOOOOOOkOOkxxdddxxkkOOOkkkkkkxkkkkkkxddd\r\nxxxxxxxxxxxxxxxxxxxkkOOOOOOkxxxxxdddddddxddddddddddddddddddddddddddddddddddddddxxkkOOOOOOOOOOkxxxkkOOOOOOOOOkocc::::::::::::::::::::::::ccccccllllllcccccllllllodxxxxxxxxxkkkkkkkkkkkkkkkxxxkkkxxxkkkxddoodddxxxxxxxxddoooooooooddddoooooooooodxkkkkkkkOOOkxddxxkkOOOOO000Okkxxxddddddxxxxkkxxxdddddddxddddd\r\nxxxxkkkkxkkkkxxxxxxxxkOOkkxxxxxxxxxxxxxxkxxxdddddddxxxkkkkxxxxxxxdddddddxxxxddddxxkOOOOkOOOOOkxxxxkkOOOOkOOkkxolc:::::::::::::::::::::::ccccccclllllcccccccccccodxxxkkkkkkkkOkkkkkkkkkkkkkkkkkkxxxkkkxdddddxxkkkkkkOkkxxdddooooooooooooooooooddxkkOOkOOOOOkxddxkOOOOOOOOO0Okkxxxxddddddddddddddddddddddddddd\r\nkkkkkkkkkkOOOkkkxxxxxxkkxxdddxxxxkkkkOOOkkkkkkkxxxxxkkOOOOkkkkkkkxdddxxxxkkxdddddxxkkOOkkOOOOOkxxxkOOOOOOOOOkxdocc::::::::::::::::::::::::cccccclloollllllllllodxkkxkkkkkkkkkkkkkOOkkkkOkkkkkkkxxkkOkxdddddxkkkkkkkOkkkkkxxdooooooooooooooodoodxxkkkkkkkkkxdddxkOOOOOOOOOOkkxxxxxxdddddddddddddddddddddddddd\r\nOOkkkkkkkOOOOkOOkxxxxxxxxxdxxxkkkkkOOOOOkkxkkkOOkkkkkkOOOkkkkkkxxdddxxkkkkkkxdddddxxkkOOOOOOOOkkxxxkOOOOOOOOkxdolcc::::::::::::::::::::::::ccccclllllllllllllloxxxxxxkkkxxkkkkkkkkkkkkkkkkkkkOkxxxxxdddddddxkkOOOOOOkkkOOOkxddooodddddoooooooodxxkkkkkkkkxdddxxkkOOOOO000Okxxxxxxxxddddddddddddddddddddddddx\r\nkkOOOOkkkkOOOOOOkkxxxxxxxddxxkkkkkkOOOOOkkkkkkkkkOOOOkkkkOOOOkkxddddxkkOkkkkxdddddddxkOOOOOOOOkkxxxxxkkkkxxxxddoccc::::::::::::::::::::::::ccccccllllooooooooodddddddxxxxxkkkkkkkkkkkkkkkkxxxxxxdddddddddddxxkOOOOOkkkkOOkkxdddooodddooooodddddxkkkkkkOOkxdddxkkOOkOOOOOOkxxxxxkkkkxxddddxxkkxxkkkkkkxddddxx\r\nOOOOOOkkkkOOOOOOkxxxxddddddxxkkOOOOkkkkOOkkkkkkkkOOOOkkkkkkkkkxxddddxkkkkkkxxxxddddddxkkkkkkOOkxxdxxdxxxdodxdddlccc:::::::::::::::::::::::::::ccccllloooooooodddoooodxxxxkkkkkkkkkkkkkkkkkxdddddddddddddddddxxkkkkOOOOkkkkkkxxxddooooooodddddddxkkkkkkkkkxdddxkOOOOOOOOkkxxxxxxkOkkkkxddddxkkkkkkOOOOkkxxxkk\r\nOOOOOOkkkOOOOOOkkxxddddddddxxkkOOOOkkkkkkkkkkOOOkkkkOOOOkkkkkxxdddddxxkkkkxxkkkxxdddddxkkkkkkxxddddddddlcoxdoolccc:::::::::::::::::::::::::;;:::::cccllllllloddooooddxxxxxkkkkkkkkkkkkkkkkxdddddddddddddddddddxxxxkkOOkkkkkkkkkkxddoddoddddddddxxkkkxxxddddddxkkOOOO0OOkxxxxxxkOOOOOOkxxddxxkkkOOOOOOOOOOOOO\r\nOOOOkkkkkOOkkkkkkxdddddddddxkkkkkkkkOOkkkkkkkOOkkkkkkOOOkkkxddddddddxkkkkkxxkkkkkxdddddxkkkxdddddxxxdol::ldoccc::::::::::::::::::::::::::::;;;;;:::::cccclloodooooooddxxxxkkkkkkkkkkxxkkxxdodddddddddxxxxddddddddddxkkkkkkkkkkkkkxddddoodddddddxxxxxdddoooddddxkkkkOOkkxxxxxxxkOOOOOOOkxdddxxkkOOOkkOOOOOOOO\r\nOOOOOkkkkkOkkkkxxddddddddddxxkkkkkkkOkkkkkkkkkkkkkkkkkkkkkkxdddddddxxkkkkkxxxkxxxdddddddddddddddxxdol:;,,:ool:::::::::::::::::cccccccc::::::;;:coddddddddxxddooooooooddxxxkkkkkkkkkkkkkkxdoodddddddxxkkkkkxddddddddxkkOkkkkkkkkkkkxddddddddddddddddooooddddoodxxkkOOkxxxxxxxxkOOOOOOOkxdddddxkkkkkOOOOOOOOOO\r\nkOOOOkkkkkkOOkxxdddddddddddddxxkkkkkkkkOkkkkkkkkkkkkkkkkkkkxdddddddxxkkkkxxddddooooooooooodddddddoc;,'''.,colc::::::::::::::::cccccccccc::::::cldxkkkkkkkkkxdddddoooooodddxxxkkkkkkkxxdddooooodddxxkOOOOOOkxxdddddddxkkkkkkkkkkkkxdddddddoooooooooooddddxxddddddxkkkkxxxxxkkkOO0OOOOOkxddddddxxkkkOOOOOOOOOO\r\nOOkkkkkkkkkkkkxxxddddddddddddxxkkkkkkkkkkkkkkkkkkkkkkkkkkxxxddddodddxxxdddoooooooooooooooooooolc:;,'.....';lol::::::::::::ccccccccccccccclllllllodxxxxxxkkxxxdxxddoooooooooddxxxxxdddooooooooddxxxkOOOOOOOOOkxdddddddxkkkkkkkkkkxddddooooooodddddddddxxxxxxxddddddxxxdddxxxkkOOOO000OOkxdddddddxxkkkkkkOOOOO\r\nOkkkkkkkkkkkkkkkkxddddddddxxxkkkkkkkkkkkxxxkkkkkkkkkkkkkkkxxdoooooooooooooooooooooooooooollc:;,'..........,coolc:::::::::cccccccccccccclllllllllodolcoddolodddxxddddddooooooodddddooooooooooodxxxxkkOOkkOOOOkxxdddddddxxkkkkkkxddoooooooooooooooddxxxkkkkkkkxxdddddddddddxxxxxkkkOOOOOkxdddddddxxkkkkkkOOOOO\r\nkkkkkkkkkkkkkkkkkkxddddddxkkkkkkkkkkkkkkxxxkkkkkkkkkkkkkkkkxddooooooooooooooooooooooolc:;,'''.............':lddoc:::::::::ccclcccccccccclllllllllddl,,;;;:cclllllllooodoooooooooooooooooooooddxkxxkOOOOOOOOOOkkxddddddddxxxxxxdooooooooooooooooddxkkkkkkkkkkxddddddddddddddddxxxxxxkkkkxxddddddxxkkkkkkOOOOO\r\nkkkOkkxxkkkkkkkkkxxdddddxkkkkkkkkkkkkkkkkxxxxkkkkkkkxxxxkxxddoooooooooddddoooooollc:;,''...................,coddoc::::::::cccllcccccccccllllllclodxo;'',,;::::;;;;:::lddooooooooooooooooodddxxkkxxkOOOOOOOOOOOkxddddddoddxxxdoooooooooooooooooodxxkkkkkkkkkkkxddddddddddxxxddddddddddddddddddddxxxkkOOOOOOOO\r\nkkkkkxxxkkkkkkkxxxxdddddxxxxkkkkkkxxxxxxxxxxxxxxxxxxxxxxdddooooooooooddxxddollc:;,''.......................';loddolc::::::cclllccccccclllllllcclodxdc,',;;;;:::::;:::ldddddoooooooooddxxxxxxkkkkxxkkOOkOOOOOOOkxdddddooodddoooooddddoooooooooooddxkkkkkkkkkOOkkxdddddddddxxxxxdddddddddddddddddxxkkkkOOOOOOO\r\nxxkkkxxkkkkkkkkkkxxdddddxxkkkkkkkkkkkxxxxdxxxxxxxxxxxxddooooooooooooddoolc:;;,''............................,:lodddlc:::::ccllllcccccccllllc::coddxxl,',;;;;:;;:::::cll::clloooooooddxxkkkkkkOOkxkkOOOOOOOOOOOOkkxddooooooooooooddxddooooooooooddxkkkkxxkkkkkkkxddddddddxxxxkkkkxxxxddddddddddddxkkkkkkOOOOO\r\ndxxkkkkkkkkkkkkkkxdddddxxkkkkkkkkkkkkkxddddddddddddddooooooooooooooolc:;;,''.................................;coodddoc::::ccclllccccccllllc:;:loddxxo;,;:;;;;;;;::::coc,''',;:clooddxxxxxxxxkkkxxxkOOOOOOOOOOOOOkkxxdooooooooooooodooooooooooooddxkkkkkkkkkkkxddddddddddddxxxkkOOOOOkxxddddddddddxkkkkOOOOOO\r\ndddxxxxxkkkkkkkkkxdddddxxkkkkkkkkkkkxddddoooooooooooooooooooooollc:;,,''.....................................,cloddddolc:::cclllccccccllc:;,;codddddo:,;:;;;;;;::;::cl:'.......',;clodxxxxxxxxxxdxxkkkkkkkkkkkkkkkkkxdoooooooooooooooooooooooooodxxxxxxxkkkkxdddddddddddddddxxkkkkkkkkxdddddoddddddxxkkkkkkk\r\ndddddddddxxxkkkkxdddddddxxkkkxxxdddddoooooooooooooooooooooollc:;,''..........................................;clooddxddoc:::clllllccclcc:;,;:lddxxddoc;::;;;;;;::;::cl;'...........',:codxxkkkkxxxkkkkkkkkkkkkkkkxkkxdoooooddddooooooooooooooooddxkkxxxxxkkxxddddddddddddddddxxkkkkkOkkxxddoooooddddddxxxxxk\r\ndddddddddddddxxxxdddddddxxdddddooooooooooooooooooooooolcc:;;,''.............................................':llooodddddolcccllllllclc::;,;:lodddddxdl::;;;;;;;;;;::cl;'..............'',:coxkkxxxkkOOOOOOOOOOOOkkkkxdooooddxxxddooooooooooooooddxkkkkxkkkxxdoodddddddddddddddxkkkkOOOOkkxxddddddddddddddddd\r\ndddddddddddddddddddddddddddoooooooooooooooooodoooooooc;,'...................................................';loooddddddddolllloollcc::;;:codddddddddlc:;;;;;;;;;;::cl;'..................',:oxxdxxkkkkOOOOkOOOOkkkxddoooodxxxxxddoooooooooooooodxxkkxkkkkxxdddddddddxxxddddddxkkkkkkkkkkkkkkxxddddddddddddd\r\nxxxxxxxxdddddddddddddddooooooooooddddddddddxxxddooolc;'......................................................,coooddddxxdddddooolllc::::clodddddddddoc::;;;;;;;;;;::cc;'....................';ldddxxkkkkkkkkkkxxxdddoooooodxxxxxxxdooooooooooooodxxxxxkkkxxddddddddxxkkkxddddddxkkkkkkkkkkOOOOkkkxdddddddddd\r\nkkkkkxkkxdddddddddddddoooooooooodxxxxxxddxxxxxxxddoc;'........................................................;loddddddxdddddddolc:::clloddddddddddl;,,;;;;;;;;;;;:::c;'.....................';odxxkkkkkkkkkxddddooooooooodxxxxxxxdooooooooooooodxxkxxkkxddoddddddddxkkkkxdooddxkkkkkOOOOOOOOOOOOOkxdddddddd\r\nkkkkxkkkxddddddddddddoooooooooodxxxxxxxdxxxxxxxxxdc;'.........................................................':oddddddddddddoooollloddddddddddddoc,'',,,,;;;;;;;;::::,.......................,cdxxxkkkkkkkxxddoooooooooooddxxxxxdoooooooooooooodxxkkkkkxdddddddddddxxkkkxdoooddxkkkkOOOOOOOOOOOOOkxxdddddxx\r\nkkkxxxkkkkxxxdddddodoooooddddddxxxxxdddddxxxxxxxdl;'...........................................................';:::cc:;;;;::cclllllloodddddddddoc,'.'',;;::;;:::ccll:,.......................';oxxxxxkkkxxddoooooooooooooddxxxxddoooooooooooooodxxkkkkxddooooooooddxxkkkkxdooddxkkkkkOOOOOOOOOOOOOkxxdddxxk\r\nkkkkxkkOOkkkkxxdddooooodddxxxxkkkxxxxxddddddxxxdo:,'................................................................,:cc:;;;,,,;;:ccccccclodddddc,'...''''',,,,,,,;,,'.........................,cdxxxxxkxxdoooooooooooooodxxxxxxxdooooooooooooooddxxxxxddoooooooodxxkkkkkkxddodddxkkkkOOOOOO0000OOOOkxddxxkk\r\nkkkkkkkkkkkkkkxxddodooddxxxxxkkkxxxxxxxdddxxxdddc,'.................................................................';:cllooolc::;;,,,,'''',;cc:'..........',;::::;'...........................':oxxxxxxddoooooooooooooooddxxxxddoooooooooooooooddxxxxxdooooooooodxkkkkkkkxddooddxkkkOOOOOOOOOOOOOOkxxdddxkk\r\nkkkkkkkkkkkkxxxxdoooodddxxxxxxxxxxxxxxxdxxxxxxdo;'....................................................................'',;;;;::cccccccc:::::;;;,...........,:cllllc,............................,cdxxxdoooooooodddoooooooddxxddoooooooooooooooooddxxxxddooooooooodxxkxxkkkkxddoddxxkkkkOOOOOOOOOOkkxxddddxkk\r\nkkxxxkkkkkkkkkxxddoodddxxxxxxxxxxxxxddddxxxxxxdc,....................................................................';cclllc::;;,,,,,;;::cllloc;'.........':cccccc,............................':odddoooooooddxxddooooooodddooooodoooooooooooooddxxddoooooddooooddxkkkkkkkkxdddddxkkkkOOOOOOOOOkkxxxxdddxxk\r\nkkkkkkkkkkkkkxxddoooooddxxxkkxxxkkxxxxdddddddddc'.....................................................................',,;;:cloooollc::;,,''''''...........,cllllll;.............................;oddoooooooddxxxxddoooooooooooodddoooooooooooooodxxddooooddddoooooddxxxkkkkxddoddxkkOOOOOOOOkkxxxxxxxddxxkk\r\nkkkkkkkkkkkxxdddooooooooddxxxxxxxxxxxxddxxxxxxd:'......................................................................',,,',,,;;::clloooollc:;,..........';loooooc,.............................;ldddoooddddxxxddoooooooooooooddddoooooooooooooodxxdooooddxxdooooooooddxxkkxddodddxkkOOOOOOOkxxxxxxxxxxxkOO\r\nkkkxkkkkxxdddoooooooooooooooddxxxxxxxxddxxxxxdo:.......................................................................,:llllllcc:;,,,,,,;;:ccc;'.........';lollllc,.............................,cddddddxxxxxxdooooooooooooooddddddooooooooooooodddooooddxkxxdooooooodxxkkkkxdddddxkkkOOOOOOOkxxxxxxxxxxkOO\r\nkkxxkkkkxddddoooooooooooooooodddxxxxddddddddodo:'.......................................................................'',,,;:clloollcc:;,,''............':llloooc'.............................':oddddxxxxxxddooooooooooooooddxxxxddoooooooooooddooooodxxxxdooooooooddxkkkkkxddddxkkOOOO00OOkxxxxxxxxxxkkO\r\nkkxkkkkxddddooooooooooooooooodxxxxxxxxdddddoooo:.........................................................................,::;,,'',,;;:cllloolc:,..........':oooooo:'.............................';odddxxxxdddooooooddddooooooodxxxxddoooooooooooooooooddxxdoooooooooooddxxkkkxddddxxkOOOOOOkkxxxxxxxxxxxxkk\r\nkkxxxxxddddooooodddddoooooooooddxxxxxxddddoodoc;.........................................................................,clllccccc:;;,,,,,;;;;,..........':odddoo:'..............................,ldddddddooooooodddxxxdoooooodddxxddoooooooooooooooooooooooooddddoooooooddxxxdddddxkOOOkxxxxxxxxxkkxxxxxxx\r\nxxxddddddddddddddddddddoooooooooodddxddooooooc;,...........................................................................'',,,;:clooolcc:;,'............':ododoo:'..............................,cddddddoooooodddxxxxxdddooooooddxddoooooooooooooooooooooooddxxxddooooooooodddddddxxkkxxxxxxxxkkOOOkkxxxxx\r\ndddddddddddddxxxxxxxxxxddoooooooooooodooooool;''..........................................................................';::;,'''',,;:clllll:,..........';ccclol:'..............................'cdddddddooodddxxxxxxxxxxxdoooooodoooooooooooooooooooooooddxxxxxxxxxxdoooooooodddddxxxxxxxxxkOOOOOOOkkxxxx\r\nddddddddddddxxxxxxxxxxxddooooooooooooooooodo;'............................................................................';clllcc:::;;,,'',,,,'...........',;;cc:,...............................':oddddddddddddxxxxxxxxxxxddooooooooooooooooooooooooooooddxxxxxxkkkkkkxddoddddddddddddxxxxxkO00OOOOOOOOkxx\r\nddddddxxxxxxkkxxxxxxxxxxxdddddooooooooooodo:'...............................................................................''',,,;:cloollcc:;'.............',,;,'................................';oddddddddddddxxxxxxxxxxxdoooooooooooooooooooooooooooooddxxxxxkkkkkkkxdddddddddddddxxxxxxkkO0000000000Okx\r\ndddddxxxxxxxkxxxxxxxxxxxxxxxxddoooooooooddc,................................................................................,::;,''.'',;;:cclc:,............',,;,..................................;odddddddddxxxxxxxxxxxxxxddooooooooooooooooooooooooooddxxkkxxxxxkkkOOkxddddddddddxxxxxxxxkkOOOOO00000OOOk\r\ndddddxxxxxxxxxdddddddddddddddxddoooooodddl;'................................................................................';cllcc:;;;,,,''''..............',;;,..................................;lddddxxxxxxxxxxxxxxxxxxxxxxddddooooooooooooooooooddxxkkkkkkkxxkkkkkOOkkxxxddddddxxxxxxkkOO0000000000000O\r\nddddddddddooooooooooooooooooooooooooooddoc'...................................................................................',,,,;;:clllllc;,.............',;;,..................................,ldddxxxxxxxxxxxxxxxxxxxxxxxxxdddoooooooooooooooodxxxxkkkkkkkkkkkOkkkkkOOOkxxddddxxxxkkOOO00000OOOOO0000O\r\ndddddxxxxxxxxdddddddddddddddddooooooooool,....................................................................................,::;,'..'',;::cc:'............',;;,..................................,lddddddddddddddddddddddddddddddooooooooooooooooodddxdddxxxxxxxkkkkkkkkkOkkkxdddxxxxkOOOOOO0000000OOOO000\r\ndddddxkkkkkkkxxxxxxxxxxxxxxxxxdooooooodl;......................................................................................,:ccc:;;,,''''...............',;;,..................................,lddddxxxxddxxxxxxxxxdddddddddddddooooooooooooooooddddddddddxxxxxxxxxxxkkxxxxxddxxxxxxkkkkkkkkkxkkxxxkkkk\r\ndddddxkxxxkkxxxxxxxxxxxxxxxxxxdoooooodo:'.......................................................................................,;;,,;::ccccc:,.............',;;,..................................'cddxxxxxxxxxxxxxxxxxxxxxxxxxxxxddddooooooooooooodxxxxxxxkkkkkkOOOOOOOOOOOOkxxxxxxxxxxxkkkkkkkxxxxxxxxxxx\r\nddddxxkxxkkkxxxxxxxxxxxxxxxxxxdoooooddl;........................................................................................;c:,'...'',;;:;.............',;;,..................................':oddxxxxxxxxxxxxxxxxxxxxxxxxxddddddoooooooooooooddxxxxxkkxkkkkkOOOOOOOOOOOOkxxxxxxxxkOOOOO000OO000OOO00O\r\nddddxkkkkkkkkxxxxxxxxxxxxxxxxxdoooodddc,.........................................................................................';:::;,,''.................',;;,...................................;oddddddxxxxxxxxdxxxxxxxxxddddoodddoooooooooooooooddddxxxkxxxxkkkOOOOOOOkkkxxxxxxxxxkOOOOO0000O0000O0000\r\nddddxkkkxkkkxxxxxxxxxxxxxxxxxxdooooodo:'..........................................................................................',;,,,;;:;;,'.............',;;,...................................,cdooooodddxxxxxxxxxxxxddddooooodddooooooooooooooooooooodxxxxxxkkOOOOkxxxxxdddddxxxxkkOOOOOOOOOOOOOOOO00\r\nddddxxxxxxkxxxxxxxxxxxxxxxxxxddooooodl;..........................................................................................';::;'..'',;:;'............',;;,...................................':odooooodddxxxxxxxxxxdddoooooodddddooooooooooooooooooooddxxxkkkkkOkkxxdddxxxxxxxxxxkkOOOO0000O000000000\r\nddddxkkxxkkkxxxxxxxxxxxxxxxxxddoooodoc,............................................................................................',;;;,,,;;;;,'...........',;;,....................................,loooooodddxxxxxxxxxxdddoooooooddddooooooooooooooooooooddxxxkkkkOOOkxxdddxxxxxxxxxxkkOOOO00000000000000\r\nddddxxxxxxkxxxxxxxxxxxxxxxxxxddoooodo;'...........................................................................................'',,;;;;::::;;,,,''.......',;;,....................................':odoooddddddxxxxxdddddooooooooddddoooooooooooooooooooooddxxkkkkkkkxxddxxxxddddxxxxxkOOOOO000O000000000\r\nddddxxxxxxkxxxxxxxxxxxxxxxxxxddoooool,........................................................................................'',;;;::::::::::::::::;,'.....',;;,.....................................;oddddddddddddxxddddddooodddddddddooooooooooooooooooooooodxkkkkxxdddddxxxxxddddddxxkOOOOOOOOOO0000O000\r\nddddxxxxxxxxxxxxxxxdxxxxdddxxddooodoc'............................................ .......................................'',;;;:::ccccccccc::ccccc:;,'....',;;,.....................................'cdddoododddddddddddddoddddddddddddoooooooooodddddoooooooodddxddddddddxxxxxddddddxxkOOOOO00OOO00000000\r\nddddxkkxxkkxxxxxxxxxxxxxxxxxxdoooodo:'........................................... ..................................',,,;;;;:ccccccc::::::::::::,,'....',;;'.....................................':oxddddoooddddddddddddddddddddddddooooooooooddddddooooooooodddddddddxxxkxxdddddddxkOOOOOOOOOO00000000\r\nddddxxxxxkxxxxxxxxxxxxxxxxxxxdoooddl,....................................... .. ................................'',,,,,;;;;:ccccc:::::;;;:::::;'......',,;'......................................;oxxxdddddddddddddddddddddddddddddoooooooooodddxxxddooooooddddddddxxkkkkxxxddddddxkOOOOOOOOOO0000O000\r\nddddxxxxxxxxddxxxxddxxxxxxxxxdooodoc,.............................................. ................................',,,;;;;;;;;::cccccc::::::::cc:;.......',,;'......................................,ldxxxxxdddddddddddddddxxxxxdddddddooooooooooddxxxxdddooooodddddxxkkkOOOkkxxdxdddxkkOOOOOOOOOO000OO00\r\nddddxxxxxxxddddxxdddxxxxxdxxddooooo:'...............................................................................',,,;;;;;;;;;::ccccccccccccccc::,.......',;;'......................................'cdxxxxxxddddddddddddddxxxxxdddddddooooooooooddxxxdxxxdddddddddxxkkkkOOOOkxddddddxkkOOOOOOOOOO0000000\r\nooddxxddxxxddddxxddddxxdddxxdoooodl;'...............................................................................',,,;;;;;;;;;;::ccccccc:::c:::;,........',;;'......................................;odxxxxxxddddddddddddddddxxxdddddddooooooooodddxdddxxxxxxddddddxxkkkkkkkkxxddddddxxkOOOOOOOOOO00OOO00\r\nodddxxdxxxxddddddddddddddddddooodoc,................................................................................',,,;;;;;;;;;;:::cccc:::cccc:;'.........',;;'......................................;ldxxxxxxxddddddddddddddddxdddddddddodoooooodddddddddxxxxddddddxxkkkkkkkkxxddddddxxkkkkOOOOOOOOOOOOOO\r\nooodddoddddooooooooooooooooooooodl;..................................................................................,,,,;;;;;;;;;::cccccccccccc:,..........',;;'......................................'cdxdxxxdddddddddddddddddddddddddddddddddooddddxxdddddxddoooodddxkkkkkkkkxxdddddddxkkkkkkOOOOOOOOOOOO\r\ndddddddddddoooooooooooooodddddoooc'..................................................................................',,,,,,;;;,;;:ccccccc::::::;'..........',;;'......................................'cdxxxxdddddddddddddddxxxddddddddddddddddddddddxxxxxxdddoooooddddxxkkOOkkxxdddddddxxkkkkkkkkkkkkkkkkk\r\nddddddddddddddddooooodddddxxddddoc'..................................................................................',,,,,,,,,,,;::cccc::::::::,...........',;,'......................................'codddddddddddddddddddddddddddddddddddddoooodddxxddddoooooooooodddddxkkkkxdddddddddxxxxxxxxxxxxxxxxxx\r\nddddddddddddddddooooddddddxxxddddl,.......................................................... .......................',,,,,,,,,,,;;::ccc:::::::;'...........',;,........................................';codddddddddddddddddddddddddddddddddddoooodddddddooooooooooooddddddxkkkkxdddddddxxkkkkkkkxxxxkkxxxx\r\noddddddddddddddddoooodddddddddoodo:'.................................................................................',,,,,,,,;;;;;::::::::::;;'............',,,...........................................,:looddddddddddddddddddddddddddddddddddddddxxddoooooooddddooddddddxkkkxddddddxxkkkkkkOkkkkkOOkkkO\r\noddddddxxxxddddxddooooooddddddooodl,.................................................................................'',,,,,,,,,,,;;;;;;;,,,,'..............',,,..............................................',;:cloddddddddddddddddddddddddddddddddddddoooooooddxxxdddddddddxxxxddddddxxkkkkkkkkkkkkkkkkkk\r\nodddddxxxxxxxxxxxdddddddddxxddooodoc'.................................................................................''''''''''''''''......................',,,....................................................,;clddddddddddddolcccclodddddddddddddooooodddxxxxxxxdddddddddddddddddxkkkkkkkkkkkkkkxxxk\r\nodddddxxxxxxxxxxxxddddddddddddoooodo;................................................................................................... ...................',,'....................... ..............................,;codddddolc:;,,,;:lodddddddddddddooooddxxxxxxkkkxddddddddddddddddxkkkkkkkkkkkkkkxxxk\r\nodddddxxxxxxxxxxxddddddddddddoooooool,................................................................................ ................ ..................',,'....................... .................................,;:cc:;,,,,,,;;:clloooooddddddddodddxxxxxxxxkkkxddddoooooooooddxxkkkkkkkkxkkkxxxxk\r\nddddxxxxxxxxxxxxxxdddddddddddooooooooc,.............................................................................. .. ........... ..................',,'...................... ............... ... .... .........'''',,,,;;:::::ccccccclllooodddddxxxxxxxxxxxdooooooooooooooddxxxxxkkkxxxxxxxxxk\r\noddddxxxxxxxxxxxxxxddddddxdddoooooooddl;'..............................................................'.................. ..............''..............',,'...................... ............. .. .. ........'',,,,;;;::cccc:::::::::::::cllooddxxxxxxxxxddooooooooooooooodxxxxxxxxxxxxxdxxxx\r\nodddddxxxxxxxxxxxddddddddddddooooooodddo:,...........................................................','.................. ..............................',,'..................... ............ .......''',,,;;;::::::::;;;;;;;;;;;;;::clloddxxxxxxxxxxddddoooooooooodxxxxxxxxxxxxxxxxxx\r\noddddddddddddddddoooooooooooooooooooddddolc;,'........................................................'.................. .............................',,'..................... ........... .....''',,,;;;;;;;;;;;;;;;;;;;;;::cccccccclooddxxxxxxdddddoooooooooddxxxxxxxxxxddxxxdd\r\nodddddddddooooooooooooooooooooooooooooddddddoollc::;;,,,,'''............................................. ... ....... ............... .. .......',,'..................... ..... ......''',,,,;;;;;;;;;;;;;;;;;::::clloooollllloddxxddddddddoooooooooodddddddddddddddddo\r\nodddddddddoooooooooooooooooooooooooooodddddddddddddddddooooolllllllccc;'.......................... . ......... ............... ...........',,'.................... ..... .......''',,,,;;;;;;;;;;;;;;;;;;;:::::::cclooddddddddddddooooooooooooooooooooooooooooooo\r\nooododddoooooooooooooooooooooooooooooodddddddddddddddddddddddddddoooddl,............................ ...... . .......... ................ ...........',,'....................... .... ..... .......'',,,,,;;;;;;::::;;;;;;;;;;::cccc:::ccloddddddddddddddooooooooodddddddddooooooooo\r\nooooooooooooooooooooooooooooooooooooooddddddddddddddddddddddddddooooodl;.................................. ............... ............... ...........',,'....................';;'..... ......................'',,,,;;;;;;;:::::::::;;;;::::cclllcccloodddddddddddddoooooooooddddddddddddoooooo\r\noodddddddooooooooooooooooooooooooooooooodddddddddddddddddddddddoooooool;..................................................... ..........................',,'....................,loolc:,...................... ......'',,,,;;;;;;;;;;::::;;::::::;;;;;::clloddddddddddddddooooooooodddddddddddddddddd\r\nooddddddoooooooooooooooooooooooooooooooodddddddddddddddddddddddoooooooo;'..................................................... ...........',''''''''''...',,,....................,coddddolc:,'.................. ..........',,,,;;;;;;;;;;;;;;;::cloolc:;;;:clodddddddddddddddoooooooooddddddddddddddoodd\r\noooooooooooooooooooooooooooooooooooooooodddddddddddddddddddddddoooooooo;'..................................................... .........';;;;;,,,,,''...',,,....................':oddddddddolc:,'............................'',,;;;;;;;;;;;;;;::cloddoollloodddddddddddddddddoooooooodddddddddddddddooo\r\nooooooooooooooooooooooooooooooooooooooooooodddddddddddddddddooooooooool;....................................................... ........';:;;;,,,,,,''..',,,.....................;oddddddddddddoll:;,..............................',;::cc:::::;;;:cloddddddddddddddddddddddddoooooooodddddddddddddddddd\r\nooooooooooooooooooooooooooooooooooooooooddddddddddddddddddooooooooooool;....................................................... ........;:::;;,,,,,,'''',;,.....................,ldddddddddddddddddolc:,'..........................':lddddddolc:::cloddxdddddddddddddddddddddoooooooodddddddddddddddooo\r\noooooooooooooooooooooooooooooooooooooooddddddddddddddddddddoooooooooooc;...................................................... ........,:::;;,,,,,,,'',,;,.....................':odddddddddddddddddddddol:;,'.....................;lddxxxddddolllooddddddddddddddddddddddddddddddddddddddddddddddddooo\r\nooooooooooooooooooooooooooooooooooooooooooodddddddddddddddooooooooooolc,....................................................... .......,:::;;;;,,,,,'',,;,......................,ldddddddddddddddddddddddddool:;,'...............';ldxxddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\r\noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooool:,........................................................ .....,::::;;;;,,,,,,,,;'.......................;ldddddddddddddddddddddddddddddoolc:;,'.........;lodxxddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\r\noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooc;'......................................................... ....,:::::;;;;,,,,,,,;'.......................':oddddddddddddddddddddddddddddddddddolc:;,''',:lddxxdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\r\nooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo:'.......................................................... ....,:::::;;;,,,,,,,,;'........................;oddddddddddddddddddddddddddddddddddddddddoooodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\r\nooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooool;'.......................................................... ...,::::::;;,,,,;,,,,'........................;ldddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\r\nooooooooloolooooloolloooooooooooooooooooooooooooooooooooooooooooooool;....................................................... ..';:::::;;,,,;;,,,,'........................,loddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\r\nllllllllllllllllllllllllllllllllllloooooooooooooooooooooooooooooooool,.................................................. ..';:::::;;,,,,,,,,,'........................,cooodddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddoooooooooooooooooooooooo\r\nllllllllllllllllllllllllllllllllllllllllllllllloooooooooooooooooooooc,............................................ .';:::::;;,,,,,,,,,'........ . .........'coooooooooodddddddddddddddddddddddddddddddddddddddddooooooooooooooodooooooooooooooooooooooooooooooooooooooooooooooo\r\nlllllllllllllllllllllllllllllllllllllllllllllllllllllllllllloollooolc'.......................................... .';;::::;;;,,,,,',,,............ .. ....':looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\r\nccccccccccccccccccccccccccccccccccclllllllllllllllllllllllllllllllll:'......................................... .',;;;;;;;;,,,,''','........''... ...':llllloooooooooooooooooooooooooooooooooooooooooooollllllllllllllllllllllllllllllllllllllollllllllllllllllllllllllll\r\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccclllllllllc;................................... .. ..,;;;;;;;;,,,,''',''.......''.. ....;clllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll\r\n\r\n\t */\r\n\r\n\tpublic static void main(String[] args) throws IOException {\r\n\t\tFastScanner fs=new FastScanner();\r\n\t\tint ind=0;\r\n\t\tArrayList chars=new ArrayList<>();\r\n\t\t\t\t//A\r\n\t\t\t\tchars.add(new String[]{\r\n\t\t\t\t\t\"x \",\r\n\t\t\t\t\t\" \",\r\n\t\t\t\t\t\" \",\r\n\t\t\t\t});\r\n\t\t\t\t//B\r\n\t\t\t\tchars.add(new String[]{\r\n\t\t\t\t\t\"x \",\r\n\t\t\t\t\t\"x \",\r\n\t\t\t\t\t\" \",\r\n\t\t\t\t});\r\n\t\t\t\t//C\r\n\t\t\t\tchars.add(new String[]{\r\n\t\t\t\t\t\"xx\",\r\n\t\t\t\t\t\" \",\r\n\t\t\t\t\t\" \",\r\n\t\t\t\t});\r\n\t\t\t\t//D\r\n\t\t\t\tchars.add(new String[]{\r\n\t\t\t\t\t\"xx\",\r\n\t\t\t\t\t\" x\",\r\n\t\t\t\t\t\" \",\r\n\t\t\t\t});\r\n\t\t\t\t//E\r\n\t\t\t\tchars.add(new String[]{\r\n\t\t\t\t\t\"x \",\r\n\t\t\t\t\t\" x\",\r\n\t\t\t\t\t\" \",\r\n\t\t\t\t});\r\n\t\t\t\t//F\r\n\t\t\t\tchars.add(new String[]{\r\n\t\t\t\t\t\"xx\",\r\n\t\t\t\t\t\"x \",\r\n\t\t\t\t\t\" \",\r\n\t\t\t\t});\r\n\t\t\t\t//G\r\n\t\t\t\tchars.add(new String[]{\r\n\t\t\t\t\t\"xx\",\r\n\t\t\t\t\t\"xx\",\r\n\t\t\t\t\t\" \",\r\n\t\t\t\t});\r\n\t\t\t\t//H\r\n\t\t\t\tchars.add(new String[]{\r\n\t\t\t\t\t\"x \",\r\n\t\t\t\t\t\"xx\",\r\n\t\t\t\t\t\" \",\r\n\t\t\t\t});\r\n\t\t\t\t//I\r\n\t\t\t\tchars.add(new String[]{\r\n//\t\t\t\t\t\" x\",\r\n//\t\t\t\t\t\"x \",\r\n//\t\t\t\t\t\" \",\r\n\t\t\t\t\t\"AA\",\r\n\t\t\t\t\t\"AA\",\r\n\t\t\t\t\t\"AA\",\r\n\t\t\t\t});\r\n\t\t\t\t//J\r\n\t\t\t\tchars.add(new String[]{\r\n\t\t\t\t\t\" x\",\r\n\t\t\t\t\t\"xx\",\r\n\t\t\t\t\t\" \",\r\n\t\t\t\t});\r\n\t\t\t\t//K\r\n\t\t\t\tchars.add(new String[]{\r\n\t\t\t\t\t\"x \",\r\n\t\t\t\t\t\" \",\r\n\t\t\t\t\t\"x \",\r\n\t\t\t\t});\r\n\t\t\t\t//L\r\n\t\t\t\tchars.add(new String[]{\r\n\t\t\t\t\t\"x \",\r\n\t\t\t\t\t\"x \",\r\n\t\t\t\t\t\"x \",\r\n\t\t\t\t});\r\n\t\t\t\t//M\r\n\t\t\t\tchars.add(new String[]{\r\n\t\t\t\t\t\"xx\",\r\n\t\t\t\t\t\" \",\r\n\t\t\t\t\t\"x \",\r\n\t\t\t\t});\r\n\t\t\t\t//N\r\n\t\t\t\tchars.add(new String[]{\r\n\t\t\t\t\t\"xx\",\r\n\t\t\t\t\t\" x\",\r\n\t\t\t\t\t\"x \",\r\n\t\t\t\t});\r\n\t\t\t\t//O\r\n\t\t\t\tchars.add(new String[]{\r\n\t\t\t\t\t\"x \",\r\n\t\t\t\t\t\" x\",\r\n\t\t\t\t\t\"x \",\r\n\t\t\t\t});\r\n\t\t\t\t//P\r\n\t\t\t\tchars.add(new String[]{\r\n\t\t\t\t\t\"xx\",\r\n\t\t\t\t\t\"x \",\r\n\t\t\t\t\t\"x \",\r\n\t\t\t\t});\r\n\t\t\t\t//Q\r\n\t\t\t\tchars.add(new String[]{\r\n\t\t\t\t\t\"xx\",\r\n\t\t\t\t\t\"xx\",\r\n\t\t\t\t\t\"x \",\r\n\t\t\t\t});\r\n\t\t\t\t//R\r\n\t\t\t\tchars.add(new String[]{\r\n\t\t\t\t\t\"x \",\r\n\t\t\t\t\t\"xx\",\r\n\t\t\t\t\t\"x \",\r\n\t\t\t\t});\r\n\t\t\t\t//S\r\n\t\t\t\tchars.add(new String[]{\r\n//\t\t\t\t\t\" x\",\r\n//\t\t\t\t\t\"x \",\r\n//\t\t\t\t\t\"x \",\r\n\t\t\t\t\t\"AA\",\r\n\t\t\t\t\t\"AA\",\r\n\t\t\t\t\t\"AA\",\r\n\t\t\t\t});\r\n\t\t\t\t//T\r\n\t\t\t\tchars.add(new String[]{\r\n\t\t\t\t\t\" x\",\r\n\t\t\t\t\t\"xx\",\r\n\t\t\t\t\t\"x \",\r\n\t\t\t\t});\r\n\t\t\t\t//U\r\n\t\t\t\tchars.add(new String[]{\r\n\t\t\t\t\t\"x \",\r\n\t\t\t\t\t\" \",\r\n\t\t\t\t\t\"xx\",\r\n\t\t\t\t});\r\n\t\t\t\t//V\r\n\t\t\t\tchars.add(new String[]{\r\n\t\t\t\t\t\"x \",\r\n\t\t\t\t\t\"x \",\r\n\t\t\t\t\t\"xx\",\r\n\t\t\t\t});\r\n\t\t\t\t//W\r\n\t\t\t\tchars.add(new String[]{\r\n\t\t\t\t\t\" x\",\r\n\t\t\t\t\t\"xx\",\r\n\t\t\t\t\t\" x\",\r\n\t\t\t\t});\r\n\t\t\t\t//X\r\n\t\t\t\tchars.add(new String[]{\r\n\t\t\t\t\t\"xx\",\r\n\t\t\t\t\t\" \",\r\n\t\t\t\t\t\"xx\",\r\n\t\t\t\t});\r\n\t\t\t\t//Y\r\n\t\t\t\tchars.add(new String[]{\r\n\t\t\t\t\t\"xx\",\r\n\t\t\t\t\t\" x\",\r\n\t\t\t\t\t\"xx\",\r\n\t\t\t\t});\r\n\t\t\t\t//Z\r\n\t\t\t\tchars.add(new String[]{\r\n\t\t\t\t\t\"x \",\r\n\t\t\t\t\t\" x\",\r\n\t\t\t\t\t\"xx\",\r\n\t\t\t\t});\r\n\t\tHashMap count=new HashMap<>();\r\n\t\tif (chars.size()!=26) throw null;\r\n\t\tfor (int i=0; i<26; i++) {\r\n\t\t\tint[] rowCounts=new int[3], colCounts=new int[2];\r\n\t\t\tString[] grid=chars.get(i);\r\n\t\t\tfor (int y=0; y<3; y++) {\r\n\t\t\t\tint x=0;\r\n\t\t\t\tfor (char c:grid[y].toCharArray()) {\r\n\t\t\t\t\tcolCounts[x]+=c=='x'?1:0;\r\n\t\t\t\t\trowCounts[y]+=c=='x'?1:0;\r\n\t\t\t\t\tx++;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tString res=rowCounts[0]+\" \"+rowCounts[1]+\" \"+rowCounts[2]+\" \"+colCounts[0]+\" \"+colCounts[1];\r\n\t\t\tcount.put(res, (char)('a'+i));\r\n\t\t}\r\n\t\tSystem.err.println(count.size());\r\n\t\tint n=fs.nextInt();\r\n\t\tfor (int i=0; i gcdFactorization[i]) {\n primes[primesQty] = primes[i];\n lcmFactorization[primesQty] = lcmFactorization[i];\n gcdFactorization[primesQty] = gcdFactorization[i];\n ++primesQty;\n }\n }\n if (primesQty < primes.length) {\n primes = Arrays.copyOfRange(primes, 0, primesQty);\n lcmFactorization = Arrays.copyOfRange(lcmFactorization, 0, primesQty);\n gcdFactorization = Arrays.copyOfRange(gcdFactorization, 0, primesQty);\n }\n boolean[] possibleGcd = new boolean[qty];\n boolean[] possibleLcm = new boolean[qty];\n int[] maskGcd = new int[qty];\n int[] maskLcm = new int[qty];\n for (int i = 0; i < qty; ++i) {\n long rang = rangs[i];\n possibleGcd[i] = rang % targetGcd == 0;\n possibleLcm[i] = targetLcm % rang == 0;\n if (!possibleGcd[i] && !possibleLcm[i]) continue;\n int[] factorization = factorize(rang, primes);\n for (int j = 0; j < primes.length; ++j) {\n if (factorization[j] > gcdFactorization[j]) {\n maskGcd[i] |= 1 << j;\n }\n if (factorization[j] < lcmFactorization[j]) {\n maskLcm[i] |= 1 << j;\n }\n }\n }\n int totalMask = (1 << primes.length) - 1;\n int[] count = new int[totalMask + 1];\n for (int i = 0; i < qty; ++i) {\n if (possibleGcd[i]) {\n count[maskGcd[i]]++;\n }\n }\n for (int mask = totalMask; mask > 0; --mask) {\n for (int subMask = (mask - 1) & mask; subMask > 0; subMask = (subMask - 1) & mask) {\n count[mask] += count[subMask];\n }\n count[mask] += count[0];\n }\n long answer = 0;\n for (int i = 0; i < qty; ++i) {\n if (possibleLcm[i]) {\n answer += count[totalMask ^ maskLcm[i]];\n }\n }\n out.println(answer);\n }\n\n private int[] factorize(long number, long[] primes) {\n int[] powers = new int[primes.length];\n for (int i = 0; i < primes.length; ++i) {\n while (number % primes[i] == 0) {\n powers[i]++;\n number /= primes[i];\n }\n }\n return powers;\n }\n\n private long[] getPrimes(long number, long[] rangs) {\n List primes = new ArrayList<>();\n for (int p = 2; p <= Math.min(1_000_000, 10 + Math.sqrt(number)); ++p) {\n if (number % p == 0) {\n primes.add((long) p);\n while (number % p == 0) {\n number /= p;\n }\n }\n }\n if (number > 1) {\n for (long rang : rangs) {\n long gcd = gcd(rang, number);\n if (gcd != 1 && gcd != number) {\n long div = number / gcd;\n primes.add(Math.min(gcd, div));\n if (gcd != div) {\n primes.add(Math.max(gcd, div));\n }\n }\n }\n }\n long[] result = new long[primes.size()];\n for (int i = 0; i < primes.size(); ++i) {\n result[i] = primes.get(i);\n }\n return result;\n }\n\n private static long gcd(long a, long b) {\n while (b != 0) {\n long tmp = a % b;\n a = b;\n b = tmp;\n }\n return a;\n }\n\n }\n\n static class InputReader {\n private final BufferedReader reader;\n private StringTokenizer tokenizer;\n\n public InputReader(InputStream in) {\n reader = new BufferedReader(new InputStreamReader(in));\n }\n\n public long[] nextLongArray(int size) {\n long[] array = new long[size];\n for (int i = 0; i < size; ++i) {\n array[i] = nextLong();\n }\n return array;\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(readLine());\n }\n return tokenizer.nextToken();\n }\n\n public String readLine() {\n String line;\n try {\n line = reader.readLine();\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n return line;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "40768f79e584ebbe61534a4d0c60fec9", "src_uid": "8d43a542d5bf79d15926c4a6a5ff608f", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class d {\n\tpublic static void main(String[] arg) {\n\t\tnew d();\n\t}\n\tpublic d() {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tint[] smallestPrime = new int[n+1];\n\t\tboolean[] isPrime = new boolean[n+1];\n\t\tArrays.fill(isPrime, true);\n\t\tisPrime[0] = isPrime[1] = false;\n\t\tfor(int i = 2; i < isPrime.length; i++) {\n\t\t\tif(isPrime[i]) {\n\t\t\t\tsmallestPrime[i] = i;\n\t\t\t\tfor(int j = i+i; j < isPrime.length; j+=i) {\n\t\t\t\t\tisPrime[j] = false;\n\t\t\t\t\tif(smallestPrime[j] == 0) smallestPrime[j] = i;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong[] numP = new long[n+1];\n\t\tfor(int i = 2; i <= n; i++) {\n\t\t\tnumP[smallestPrime[i]]++; \n\t\t}\n\t\tlong[] cum = new long[n+1];\n\t\tcum[0] = numP[0];\n\t\tfor(int i = 1; i <= n; i++) {\n\t\t\tcum[i] += cum[i-1]+numP[i];\n\t\t}\n\t\tlong count2 = 1L * n * (n - 1) / 2 - (n - 1);\n\t\tlong ans = 0;\n\t\t/*\n\t\tfor(int i = 2; i <= n; i++) {\n\t\t\tint p = smallestPrime[i];\n\t\t\tint other = i/p;\n\t\t\tif(isPrime[other] && other > p) {\n//\t\t\t\tSystem.out.println(i + \" \" + other + \" \" + numP[p] + \" \" + numP[other]);\n\t\t\t\tlong temp = numP[p]*numP[other];\n\t\t\t\tfor(int j = p; j <= n; j+=p) {\n\t\t\t\t\tif(j % other == 0 && smallestPrime[j] == p)\n\t\t\t\t\t\ttemp -= numP[other];\n\t\t\t\t}\n\t\t\t\tans += 2*temp;\n\t\t\t}\n\t\t}*/\n\t\touter:\n\t\tfor(int i = 2; i <= n; i++) {\n\t\t\tlong count = 0;\n\t\t\tint sign = -1;\n\t\t\tint x = i;\n\t\t\twhile(x > 1) {\n\t\t\t\tint y = smallestPrime[x];\n\t\t\t\tx /= y;\n\t\t\t\tif(smallestPrime[x] == y) {\n\t\t\t\t\tcontinue outer;\n\t\t\t\t}\n\t\t\t\tsign *= -1;\n\t\t\t}\n\t\t\tfor(int j = i; j <= n; j += i) {\n\t\t\t\tcount++;\n\t\t\t}\n\t\t\tcount2 -= sign*(count*(count-1)/2);\n\t\t\tans += sign*(count*(count-1)/2);\n\t\t}\n\t\tfor(int i = 2; i <= n; i++) {\n\t\t\tif(!isPrime[i]) continue;\n\t\t\tif(n / 2 <= i) continue;\n\t\t\tlong c = cum[n / 2];\n\t\t\tc -= cum[Math.max(n / i, i)];\n\t\t\tans += numP[i]*c*3;\n\t\t\tcount2 -= numP[i]*c;\n\t\t}\n\t\t//System.err.println(count2);\n\t\tlong numSpec = 0;\n\t\tfor (int i = 2; i <= n; i++) {\n\t\t\tif (smallestPrime[i] * 2 > n) {\n\t\t\t\tnumSpec++;\n\t\t\t}\n\t\t}\n\t\tcount2 -= (n - 2) * numSpec;\n\t\tcount2 += numSpec * (numSpec - 1) / 2;\n\t\t//System.err.println(count2);\n\t\tans += count2 * 2;\n\t\tSystem.out.println(ans);\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ba53f5fdd986eeeb031dbbd9eccba34a", "src_uid": "bb1bd5d8bab7d79e514281230d484996", "difficulty": 2700.0} {"lang": "Java 6", "source_code": "\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\n\npublic class E {\n static long mod = 1000000007;\n static long[][] ways = new long[1001][1001];\n static int k;\n\n public static long getTotal(String x) {\n long ans = 0;\n for (int i = 0; i < x.length(); i++)\n ans = (10 * ans + x.charAt(i) - '0') % mod;\n return ans;\n }\n\n public static long get(String x, int index, int cantPut47) {\n if (index == x.length())\n return 1;\n int maxDigit = x.charAt(index) - '0';\n long ans = 0;\n for (int i = 0; i <= maxDigit; i++) {\n if ((i == 4 || i == 7) && cantPut47 > 0)\n continue;\n if (i == 4 || i == 7)\n if (i < maxDigit)\n ans = (ans + ways[x.length() - index - 1][k]) % mod;\n else\n ans = (ans + get(x, index + 1, k)) % mod;\n else if (i < maxDigit)\n ans = (ans + ways[x.length() - index - 1][Math.max(\n cantPut47 - 1, 0)]) % mod;\n else\n ans = (ans + get(x, index + 1, Math.max(cantPut47 - 1, 0)))\n % mod;\n }\n return ans;\n }\n\n public static void main(String[] args) throws IOException {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n String[] S = in.readLine().split(\" \");\n int t = Integer.parseInt(S[0]);\n k = Integer.parseInt(S[1]);\n for (int i = 0; i < 1001; i++)\n ways[0][i] = 1;\n for (int i = 1; i < 1001; i++)\n for (int j = 0; j < 1001; j++)\n if (j == 0)\n ways[i][j] = (8 * ways[i - 1][0] + 2 * ways[i - 1][k])\n % mod;\n else\n ways[i][j] = (8 * ways[i - 1][j - 1]) % mod;\n for (int i = 0; i < t; i++) {\n S = in.readLine().split(\" \");\n String left = \"\" + (new BigInteger(S[0]).subtract(BigInteger.ONE));\n String right = S[1];\n long tot = (getTotal(right) - getTotal(left) + mod) % mod;\n long bad = (get(right, 0, 0) - get(left, 0, 0) + mod) % mod;\n long ans = (tot - bad + mod) % mod;\n System.out.println(ans);\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5d0e496879e31bfdfa64aaf8a11fc414", "src_uid": "5517efa2fc9362fdf342d32adac889f4", "difficulty": 2500.0} {"lang": "Java 7", "source_code": "import java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author George Marcus\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n char[][] A;\n int[] ans;\n ArrayList[] B;\n int[] inGroup;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int N = in.nextInt();\n A = new char[N][];\n for (int i = 0; i < N; i++) {\n A[i] = in.nextString().toCharArray();\n }\n\n ans = new int[N + 1];\n B = new ArrayList[N];\n for (int i = 0; i < N; i++) {\n B[i] = new ArrayList();\n for (int j = 0; j < N; j++) {\n if (A[i][j] == '1') {\n B[i].add(j);\n }\n }\n }\n\n ArrayList rows = new ArrayList();\n ArrayList cols = new ArrayList();\n for (int i = 0; i < N; i++) {\n if (!B[i].isEmpty()) {\n rows.add(i);\n }\n cols.add(i);\n }\n\n inGroup = new int[N];\n if (go(rows, cols)) {\n out.println(\"YES\");\n for (int i = 0; i < N; i++) {\n for (int j = 1; j <= N; j++) {\n out.print(A[i][ans[j]]);\n }\n out.println();\n }\n }\n else {\n out.println(\"NO\");\n }\n }\n\n private boolean go(ArrayList rows, ArrayList cols) {\n if (rows.isEmpty()) {\n for (int col : cols) {\n ans[++ans[0]] = col;\n }\n return true;\n }\n\n int pmax = 0;\n for (int i = 1; i < rows.size(); i++) {\n if (B[rows.get(i)].size() > B[rows.get(pmax)].size()) {\n pmax = i;\n }\n }\n rows.remove(pmax);\n\n ArrayList> groups = new ArrayList>();\n ArrayList ones = new ArrayList();\n ArrayList zeros = new ArrayList();\n split(pmax, cols, ones, zeros);\n groups.add(ones);\n groups.add(zeros);\n\n if (rows.isEmpty()) {\n for (ArrayList gcols : groups) {\n for (int gcol : gcols) {\n ans[++ans[0]] = gcol;\n }\n }\n return true;\n }\n if (ones.isEmpty() || zeros.isEmpty()) {\n return go(rows, cols);\n }\n\n int p = -1;\n int special = groups.get(groups.size() - 1).size();\n while ((p = find(groups, rows)) != -1) {\n rows.remove((Integer) p);\n\n int state = 0;\n boolean maybe = false;\n ArrayList> ngroups = new ArrayList>();\n for (int i = 0; i < groups.size(); i++) {\n ArrayList group = groups.get(i);\n ones = new ArrayList();\n zeros = new ArrayList();\n split(p, group, ones, zeros);\n\n if (state == 0) {\n if (!zeros.isEmpty()) ngroups.add(zeros);\n if (!ones.isEmpty()) {\n ngroups.add(ones);\n state = 1;\n }\n }\n else if (state == 1) {\n if (!ones.isEmpty()) ngroups.add(ones);\n if (!zeros.isEmpty()) {\n ngroups.add(zeros);\n state = 2;\n }\n }\n else if (state == 2) {\n if (!zeros.isEmpty()) ngroups.add(zeros);\n if (!ones.isEmpty()) {\n if (i + 1 < groups.size() || special == 0) {\n return false;\n }\n else {\n maybe = true;\n }\n }\n }\n if (i == groups.size() - 1) {\n special -= ones.size();\n }\n }\n\n if (maybe) {\n ngroups = new ArrayList>();\n state = 0;\n for (int i = 0; i < groups.size(); i++) {\n ArrayList group = groups.get(i);\n ones = new ArrayList();\n zeros = new ArrayList();\n split(p, group, ones, zeros);\n\n if (i == groups.size() - 1) {\n if (!ones.isEmpty()) ngroups.add(0, ones);\n if (!zeros.isEmpty()) ngroups.add(zeros);\n continue;\n }\n if (!ones.isEmpty()) {\n if (state == 1) return false;\n ngroups.add(ones);\n }\n if (!zeros.isEmpty()) {\n if (state == 0) state = 1;\n ngroups.add(zeros);\n }\n }\n }\n\n groups = ngroups;\n }\n\n ArrayList[] groupRows = new ArrayList[groups.size()];\n for (int i = 0; i < groups.size(); i++) {\n groupRows[i] = new ArrayList();\n }\n for (int r : rows) {\n int f = B[r].get(0);\n int g = inGroup[f];\n groupRows[g].add(r);\n }\n for (int i = 0; i < groups.size(); i++) {\n ArrayList group = groups.get(i);\n if (!go(groupRows[i], group)) {\n return false;\n }\n }\n return true;\n }\n\n private int find(ArrayList> groups, ArrayList rows) {\n for (int i = 0; i < groups.size(); i++) {\n ArrayList group = groups.get(i);\n for (int col : group) {\n inGroup[col] = i;\n }\n }\n for (int r : rows) {\n for (int j = 1; j < B[r].size(); j++) {\n if (inGroup[ B[r].get(j - 1) ] != inGroup[ B[r].get(j) ]) {\n return r;\n }\n }\n }\n return -1;\n }\n\n private void split(int row, ArrayList cols, ArrayList ones, ArrayList zeros) {\n for (int col : cols) {\n if (A[row][col] == '1') {\n ones.add(col);\n }\n else {\n zeros.add(col);\n }\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\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 nextInt() {\n return Integer.parseInt(nextString());\n }\n\n public String nextString() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuffer res = new StringBuffer();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n\n return res.toString();\n }\n\n private boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "238777b3aac9de4983f013462d258a98", "src_uid": "af8d46722e1bd8f7392e5596eaf4def8", "difficulty": 3000.0} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.PriorityQueue;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\n\npublic class magic2 {\n\tpublic static void main(String[] args) throws Exception{\n\t\tFastScanner sc = new FastScanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint N = sc.nextInt();\n\t\tif(N<2000)out.println(\"1\");\n\t\telse if(N<=3000)out.println(\"2\");\n\t\telse out.println(\"3\");\n\t\tout.close();\n\t}\n\t\n\tstatic class FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\t\n\t\tpublic FastScanner(InputStream in) throws Exception{\n\t\t\tbr = new BufferedReader(new InputStreamReader(in));\n\t\t\tst = new StringTokenizer(br.readLine().trim());\n\t\t}\n\t\tpublic int numTokens() throws Exception {\n\t\t\tif(!st.hasMoreTokens()){\n\t\t\t\tst = new StringTokenizer(br.readLine().trim());\n\t\t\t\treturn numTokens();\n\t\t\t}\n\t\t\treturn st.countTokens();\n\t\t}\n\t\tpublic boolean hasNext() throws Exception{\n\t\t\tif(!st.hasMoreTokens()){\n\t\t\t\tst = new StringTokenizer(br.readLine().trim());\n\t\t\t\treturn hasNext();\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t\tpublic String next() throws Exception {\n\t\t\tif(!st.hasMoreTokens()){\n\t\t\t\tst = new StringTokenizer(br.readLine().trim());\n\t\t\t\treturn next();\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tpublic double nextDouble() throws Exception{\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\tpublic float nextFloat() throws Exception{\n\t\t\treturn Float.parseFloat(next());\n\t\t}\n\t\tpublic long nextLong() throws Exception{\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\tpublic int nextInt() throws Exception{\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tpublic String nextLine() throws Exception{\n\t\t\treturn br.readLine();\n\t\t}\n\t}\n\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "fd3b2e0218c79a4e90016dec2c7b77bc", "src_uid": "d163975cdad000ce89ee251ef9129779", "difficulty": 2000.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n/**\n * @author Don Li\n */\npublic class UnavoidableDetourForHome2 {\n \n int N = 51;\n int MOD = (int) 1e9 + 7;\n \n void solve() {\n int n = in.nextInt();\n int[] d = new int[n];\n for (int i = 0; i < n; i++) d[i] = in.nextInt();\n \n long[][][] ways = new long[N][N][N];\n ways[0][0][0] = 1;\n for (int c0 = 0; c0 <= n; c0++) {\n for (int c2 = 0; c2 <= n; c2++) {\n for (int c1 = 0; c1 + c2 <= n; c1++) {\n if (c1 + c2 > 0) {\n if (c2 > 0) {\n if (c0 > 1)\n ways[c0][c1][c2] = add(ways[c0][c1][c2], ways[c0 - 2][c1][c2 - 1] * c0 * (c0 - 1) / 2);\n if (c2 > 1 && c0 > 0)\n ways[c0][c1][c2] = add(ways[c0][c1][c2], ways[c0 - 1][c1 + 1][c2 - 2] * (c2 - 1) * c0);\n if (c2 > 2)\n ways[c0][c1][c2] = add(ways[c0][c1][c2], ways[c0][c1 + 2][c2 - 3] * (c2 - 1) * (c2 - 2) / 2);\n if (c1 > 0 && c2 > 1)\n ways[c0][c1][c2] = add(ways[c0][c1][c2], ways[c0][c1][c2 - 2] * c1 * (c2 - 1));\n if (c0 > 0 && c1 > 0)\n ways[c0][c1][c2] = add(ways[c0][c1][c2], ways[c0 - 1][c1 - 1][c2 - 1] * c0 * c1);\n if (c1 > 1)\n ways[c0][c1][c2] = add(ways[c0][c1][c2], ways[c0][c1 - 2][c2 - 1] * c1 * (c1 - 1) / 2);\n } else {\n if (c0 > 0)\n ways[c0][c1][c2] = add(ways[c0][c1][c2], ways[c0 - 1][c1 - 1][c2] * c0);\n if (c1 > 1)\n ways[c0][c1][c2] = add(ways[c0][c1][c2], ways[c0][c1 - 2][c2] * (c1 - 1));\n }\n }\n }\n }\n }\n \n int[] sum = new int[N];\n for (int i = 0; i < n; i++) sum[i + 1] = sum[i] + d[i];\n \n long[][] dp = new long[N][N];\n dp[n][n - 1] = 1;\n for (int l = n - 1; l > 0; l--) {\n for (int r = l; r < n; r++) {\n int cnt2 = (sum[r + 1] - sum[l]) - (r - l + 1) * 2;\n int cnt1 = (r - l + 1) - cnt2;\n for (int nxt = 0; nxt <= 2 * cnt2 + cnt1 && nxt <= n && r + nxt < n; nxt++) {\n dp[l][r] = add(dp[l][r], dp[r + 1][r + nxt] * ways[nxt][cnt1][cnt2] % MOD);\n }\n }\n }\n \n if (d[0] + 1 > n) {\n out.println(0);\n return;\n }\n out.println(dp[1][d[0]]);\n }\n \n long add(long a, long b) {\n return (a + b) % MOD;\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 UnavoidableDetourForHome2().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", "compilation_error": false, "code_uid": "ca2f2b606557a304f95ee3f6e10e1399", "src_uid": "db884d679d9cfb1dc4bc511f83beedda", "difficulty": 2600.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.util.Collection;\nimport java.io.IOException;\nimport java.util.Deque;\nimport java.util.ArrayList;\nimport java.io.UncheckedIOException;\nimport java.util.List;\nimport java.io.Closeable;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.ArrayDeque;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, new TaskAdapter(), \"\", 1 << 27);\n thread.start();\n thread.join();\n }\n\n static class TaskAdapter implements Runnable {\n @Override\n public void run() {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastInput in = new FastInput(inputStream);\n FastOutput out = new FastOutput(outputStream);\n FWrapAround solver = new FWrapAround();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class FWrapAround {\n ACAutomaton.Node end;\n ACAutomaton.Node begin;\n int n;\n char[] s;\n ACAutomaton.Node[] nodes;\n ACAutomaton at;\n\n public void solve(int testNumber, FastInput in, FastOutput out) {\n n = in.readInt();\n s = in.readString().toCharArray();\n at = new ACAutomaton('0', '1');\n at.beginBuilding();\n for (char c : s) {\n at.build(c);\n }\n at.endBuilding();\n end = at.getBuildLast();\n nodes = at.getAllNodes().toArray(new ACAutomaton.Node[0]);\n begin = nodes[0];\n\n long ans = 0;\n for (int i = 0; i < n; i++) {\n ans += way(i);\n }\n\n out.println(ans);\n }\n\n public long pow(long x, long n) {\n if (n == 0) {\n return 1;\n }\n long ans = pow(x, n / 2);\n ans *= ans;\n if (n % 2 == 1) {\n ans *= x;\n }\n return ans;\n }\n\n public long way(int offset) {\n char[] data = new char[1 + 2 * n];\n for (int i = 0; i < s.length; i++) {\n data[1 + i + offset] = s[i];\n data[1 + (i + offset) % n] = s[i];\n }\n int dpLen = offset + s.length;\n long[][] dp = new long[dpLen + 1][nodes.length];\n dp[0][begin.getId()] = 1;\n for (int i = 0; i < dpLen; i++) {\n for (int j = 0; j < nodes.length; j++) {\n if (dp[i][j] == 0 || j == end.getId()) {\n continue;\n }\n if (data[i + 1] == 0) {\n dp[i + 1][nodes[j].next[0].getId()] += dp[i][j];\n dp[i + 1][nodes[j].next[1].getId()] += dp[i][j];\n } else {\n dp[i + 1][nodes[j].next[data[i + 1] - '0'].getId()] += dp[i][j];\n }\n }\n }\n long ans = dp[dpLen][end.getId()];\n if (offset + s.length < n) {\n ans *= pow(2, n - offset - s.length);\n }\n return ans;\n }\n\n }\n\n static class FastOutput implements AutoCloseable, Closeable {\n private StringBuilder cache = new StringBuilder(10 << 20);\n private final Writer os;\n\n public FastOutput(Writer os) {\n this.os = os;\n }\n\n public FastOutput(OutputStream os) {\n this(new OutputStreamWriter(os));\n }\n\n public FastOutput println(long c) {\n cache.append(c);\n println();\n return this;\n }\n\n public FastOutput println() {\n cache.append(System.lineSeparator());\n return this;\n }\n\n public FastOutput flush() {\n try {\n os.append(cache);\n os.flush();\n cache.setLength(0);\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n return this;\n }\n\n public void close() {\n flush();\n try {\n os.close();\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n public String toString() {\n return cache.toString();\n }\n\n }\n\n static class FastInput {\n private final InputStream is;\n private StringBuilder defaultStringBuf = new StringBuilder(1 << 13);\n private byte[] buf = new byte[1 << 13];\n private int bufLen;\n private int bufOffset;\n private int next;\n\n public FastInput(InputStream is) {\n this.is = is;\n }\n\n private int read() {\n while (bufLen == bufOffset) {\n bufOffset = 0;\n try {\n bufLen = is.read(buf);\n } catch (IOException e) {\n bufLen = -1;\n }\n if (bufLen == -1) {\n return -1;\n }\n }\n return buf[bufOffset++];\n }\n\n public void skipBlank() {\n while (next >= 0 && next <= 32) {\n next = read();\n }\n }\n\n public int readInt() {\n int sign = 1;\n\n skipBlank();\n if (next == '+' || next == '-') {\n sign = next == '+' ? 1 : -1;\n next = read();\n }\n\n int val = 0;\n if (sign == 1) {\n while (next >= '0' && next <= '9') {\n val = val * 10 + next - '0';\n next = read();\n }\n } else {\n while (next >= '0' && next <= '9') {\n val = val * 10 - next + '0';\n next = read();\n }\n }\n\n return val;\n }\n\n 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 }\n\n static class ACAutomaton {\n private final int MIN_CHARACTER;\n private final int MAX_CHARACTER;\n private final int RANGE;\n private ACAutomaton.Node root;\n private ACAutomaton.Node buildLast;\n private List allNodes = new ArrayList();\n\n public ACAutomaton.Node getBuildLast() {\n return buildLast;\n }\n\n public List getAllNodes() {\n return allNodes;\n }\n\n private ACAutomaton.Node addNode() {\n ACAutomaton.Node node = new ACAutomaton.Node(RANGE);\n node.id = allNodes.size();\n allNodes.add(node);\n return node;\n }\n\n public ACAutomaton(int minCharacter, int maxCharacter) {\n MIN_CHARACTER = minCharacter;\n MAX_CHARACTER = maxCharacter;\n RANGE = maxCharacter - minCharacter + 1;\n root = addNode();\n }\n\n public void beginBuilding() {\n buildLast = root;\n }\n\n public void endBuilding() {\n Deque deque = new ArrayDeque(allNodes.size());\n for (int i = 0; i < RANGE; i++) {\n if (root.next[i] != null) {\n deque.addLast(root.next[i]);\n }\n }\n\n while (!deque.isEmpty()) {\n ACAutomaton.Node head = deque.removeFirst();\n ACAutomaton.Node fail = visit(head.father.fail, head.index);\n if (fail == null) {\n head.fail = root;\n } else {\n head.fail = fail.next[head.index];\n }\n head.preSum = head.cnt + head.fail.preSum;\n for (int i = 0; i < RANGE; i++) {\n if (head.next[i] != null) {\n deque.addLast(head.next[i]);\n }\n }\n }\n\n for (int i = 0; i < RANGE; i++) {\n if (root.next[i] != null) {\n deque.addLast(root.next[i]);\n } else {\n root.next[i] = root;\n }\n }\n while (!deque.isEmpty()) {\n ACAutomaton.Node head = deque.removeFirst();\n for (int i = 0; i < RANGE; i++) {\n if (head.next[i] != null) {\n deque.addLast(head.next[i]);\n } else {\n head.next[i] = head.fail.next[i];\n }\n }\n }\n }\n\n public ACAutomaton.Node visit(ACAutomaton.Node trace, int index) {\n while (trace != null && trace.next[index] == null) {\n trace = trace.fail;\n }\n return trace;\n }\n\n public void build(char c) {\n int index = c - MIN_CHARACTER;\n if (buildLast.next[index] == null) {\n ACAutomaton.Node node = addNode();\n node.father = buildLast;\n node.index = index;\n buildLast.next[index] = node;\n }\n buildLast = buildLast.next[index];\n }\n\n public static class Node {\n public ACAutomaton.Node[] next;\n ACAutomaton.Node fail;\n ACAutomaton.Node father;\n int index;\n int id;\n int cnt;\n int preSum;\n\n public int getId() {\n return id;\n }\n\n public Node(int range) {\n next = new ACAutomaton.Node[range];\n }\n\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "1541999242fa4b2eeeb678b34ff44df8", "src_uid": "0034806908c9794086736a2d07fc654c", "difficulty": 2900.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class cf401e {\n static FastIO in = new FastIO(), out = in;\n\n static double EPS = 1e-9;\n static int MAX = 100100;\n static long n,m,l,r,p;\n public static void main(String[] args) {\n boolean[] isPrime = new boolean[MAX];\n int[] mu = new int[MAX];\n Arrays.fill(isPrime, true);\n Arrays.fill(mu, 1);\n mu[0] = 0;\n isPrime[0] = isPrime[1] = false;\n for(int i=0; i ts = new TreeSet();\n for(int n = 0; n < N; n++) {\n String w = in.readLine();\n if(ts.contains(reverse(w))) continue;\n ts.add(w);\n int a = charToInt(w.charAt(0));\n int b = charToInt(w.charAt(w.length()-1));\n words[w.length()][a][b]++;\n if(!isPal(w)) words[w.length()][b][a]++;\n }\n\n long sum = 0;\n \n for(int LEN = 3; LEN <= 10; LEN++) {\n long[][][] dyn = new long[SIZE][SIZE][SIZE];\n for(int a = 0; a < SIZE; a++) {\n for(int b = a; b < SIZE; b++) {\n for(int c = b; c < SIZE; c++) {\n for(int x = 0; x < SIZE; x++) {\n long add = (words[LEN][a][x]*words[LEN][b][x])%MOD;\n add = (add*words[LEN][c][x])%MOD;\n dyn[a][b][c] += add;\n dyn[a][b][c] %= MOD;\n }\n dyn[a][c][b] = dyn[a][b][c];\n dyn[b][a][c] = dyn[a][b][c];\n dyn[b][c][a] = dyn[a][b][c];\n dyn[c][a][b] = dyn[a][b][c];\n dyn[c][b][a] = dyn[a][b][c];\n }}}\n for(int a = 0; a < SIZE; a++) {\n for(int b = a; b < SIZE; b++) {\n for(int c = b; c < SIZE; c++) {\n for(int d = c; d < SIZE; d++) {\n long add = (dyn[a][b][c]*dyn[b][c][d])%MOD;\n add *= (dyn[a][c][d]*dyn[a][b][d])%MOD;\n add %= MOD;\n //if(add > 0) {\n // System.err.print(a+\", \"+b+\", \"+c+\", \"+d+\" \");\n // System.err.print(add+\" -> \");\n //}\n if(a == b && b == c && c == d)\n add *= 1;\n else if((a == b && b == c) || // d\n (a == b && b == d) || // c\n (a == c && c == d) || // b\n (b == c && c == d)) // a\n add *= 4;\n else if(a == b || b == c || c == d) {\n if(c == d)\n add *= 6;\n else\n add *= 12;\n }\n else\n add *= 24;\n //if(add > 0)\n // System.err.println(add);\n sum += add;\n sum %= MOD;\n }}}}\n \n }\n\n System.out.println(sum);\n\n in.close();\n }\n\n static int charToInt(char c) {\n if('a' <= c && c <= 'z')\n return c-'a';\n else if('A' <= c && c <= 'Z')\n return (SIZE==62 ? 26 : 16) + c-'A';\n else\n return 2*26+c-'0';\n }\n\n static boolean isPal(String s) {\n int n = s.length();\n for(int i = 0; i <= n/2; i++)\n if(s.charAt(i) != s.charAt(n-1-i))\n return false;\n return true;\n }\n\n static String reverse(String s) {\n StringBuilder sb = new StringBuilder();\n for(int i = s.length()-1; i >= 0; i--)\n sb.append(s.charAt(i));\n return sb.toString();\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "dd6ddd41360d92767048be098b8e8c67", "src_uid": "92ed1015b43f4b610cd7956db8588a9e", "difficulty": null} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main implements Runnable{\n public static void main(String[] args){\n //new Thread(null,new Main(),\"Thread-1\",1024*1024*10).start();\n new Main().run();\n }\n int mod=1000000007;\n int n,k,m;\n private void solve() throws Exception {\n InputReader in = new InputReader(System.in);\n PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n n=in.nextInt();k=in.nextInt();m=in.nextInt();\n int[][]ma=new int[(k+1)*(1<>1)][trans(i,j)]=1;\n if(i>1|(1<0){\n if((b&1)==1)\n ans=modMul(ans,a);\n a=modMul(a,a);\n b>>=1;\n }\n return ans;\n }\n public int[][] modMul(int[][]a,int[][]b){\n int row=a.length,column=b[0].length;\n int len=b.length;\n int[][] ans=new int[row][column];\n for(int i=0;il+1; i--) {\n int j=rnd.nextInt(i),tmp=a[j];\n a[j]=a[i-1];\n a[i-1]=tmp;\n }\n }\n void shuffle(Object[]a,int l,int r){\n Random rnd=new Random();\n for (int i=r; i>l+1; i--) {\n int j=rnd.nextInt(i);\n Object tmp=a[j];\n a[j]=a[i-1];\n a[i-1]=tmp;\n }\n }\n void shuffle(long[]a,int l,int r){\n Random rnd=new Random();\n for (int i=r; i>l+1; i--) {\n int j=rnd.nextInt(i);\n long tmp=a[j];\n a[j]=a[i-1];\n a[i-1]=tmp;\n }\n }\n class InputReader{\n StreamTokenizer tokenizer;\n public InputReader(InputStream stream){\n tokenizer=new StreamTokenizer(new BufferedReader(new InputStreamReader(stream)));\n tokenizer.ordinaryChars(33,126);\n tokenizer.wordChars(33,126);\n }\n public String next() throws IOException {\n tokenizer.nextToken();\n return tokenizer.sval;\n }\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n public boolean hasNext() throws IOException {\n int res=tokenizer.nextToken();\n tokenizer.pushBack();\n return res!=tokenizer.TT_EOF;\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f9a09c6cfe2a3cc360f11f77971333bd", "src_uid": "87931a8ae9a76d85bd2a2b4bba93303d", "difficulty": 3000.0} {"lang": "Java 11", "source_code": "// package c1626;\n\nimport java.io.File;\nimport java.lang.invoke.MethodHandles;\nimport java.util.Arrays;\nimport java.util.Random;\nimport java.util.Scanner;\nimport java.util.TreeSet;\n\n//\n// Educational Codeforces Round 121 (Rated for Div. 2) 2022-01-16 06:35\n// F. A Random Code Problem\n// https://codeforces.com/contest/1626/problem/F\n// time limit per test 3 seconds; memory limit per test 512 megabytes\n// public class Pseudo for 'Source should satisfy regex [^{}]*public\\s+(final)?\\s*class\\s+(\\w+).*'\n//\n// You are given an integer array a_0, a_1, ..., a_{n - 1}, and an integer k. You perform the\n// following code with it:

        
\n//\n// Your task is to calculate the expected value of the variable ans after performing this code.\n//\n// Note that the input is generated according to special rules (see the input format section).\n//\n// Input\n//\n// The only line contains six integers n, a_0, x, y, k and M (1 <= n <= 10^7; 1 <= a_0, x, y < M <=\n// 998244353; 1 <= k <= 17).\n//\n// The array a in the input is constructed as follows:\n// * a_0 is given in the input;\n// * for every i from 1 to n - 1, the value of a_i can be calculated as a_i = (a_{i - 1} * x + y)\n// mod M.\n//\n// Output\n//\n// Let the expected value of the variable ans after performing the code be E. It can be shown that E\n// * n^k is an integer. You have to output this integer modulo 998244353.\n//\n// Example\n/*\ninput:\n3 10 3 5 13 88\n\noutput:\n382842030\n\ninput:\n2 15363 270880 34698 17 2357023\n\noutput:\n319392398\n*/\n// Note\n//\n// The array in the first example test is [10, 35, 22]. In the second example, it is [15363,\n// 1418543].\n//\npublic class C1626F {\n static final int MOD = 998244353;\n static final Random RAND = new Random();\n\n static int solve(int[] a, int k) {\n int n = a.length;\n // We are asked to compute the sum of ans across all n^k cases ---\n // make k idx selections each time from [0,n).\n // i = 1: Total n^1 cases at the level with each a[idx] added into ans n^0 times,\n // contribute to n^(k-1) final cases. Then a[idx] remains the same.\n // i = 2: Total n^2 cases at the level with each a[idx] added into ans n^1 times\n // contribute to n^(k-2) final cases. Then a[idx] is trimmed to be even.\n // i = 3: Total n^3 cases at the level with each a[idx] added into ans n^2 times,\n // contribute to n^(k-3) final cases. Then a[idx] is trimmed to be multiple of 3.\n // ...\n // i = k: Total n^k cases at the level with each a[idx] added into ans n^0 times,\n // contribute to n^0 final cases. Then a[idx] is trimmed to be multiple of k.\n\n // Compute pows[i] = (n^i % MOD)\n long[] pows = new long[k+1];\n pows[0] = 1;\n for (int i = 1; i <= k; i++) {\n pows[i] = (pows[i-1] * n) % MOD;\n }\n\n //\n // To be efficient, here we use array instead of Map.\n // For k = 17, the largest value range observed is 110, like for 59980733.\n final int[] mrs = {0, 1, 2, 4, 6, 10, 12, 18, 24, 30, 38, 48, 54, 66, 78, 84, 94, 110};\n final int maxRange = mrs[k] + 1;\n long[] curr = new long[maxRange];\n long[] next = new long[maxRange];\n\n long ans = 0;\n for (long v : a) {\n Arrays.fill(curr, 0L);\n curr[0] = 1L;\n for (int i = 1; i <= k; i++) {\n // For each incidence of cv, it is chosen once and not chosen n - 1 times.\n // Once chosen it contribute to ans n^(k-i) times.\n Arrays.fill(next, 0L);\n for (int d = 0; d < maxRange; d++) {\n if (curr[d] == 0) {\n continue;\n }\n // current value and count\n long cv = v - d;\n long count = curr[d] % MOD;\n\n // chosen once:\n ans = (ans + ((cv * count) % MOD) * pows[k-i]) % MOD;\n long nv = cv - cv % i;\n if (nv != 0) {\n myAssert(v - nv < maxRange);\n next[(int) (v-nv)] += count;\n }\n\n // not chose (n-1) times:\n long nc = (count * (n-1)) % MOD;\n if (nc != 0) {\n next[d] += nc;\n }\n }\n long[] tmp = curr;\n curr = next;\n next = tmp;\n }\n }\n return (int) ans;\n }\n\n public static int modInverse(long a, int p) {\n return power(a, p - 2, p);\n }\n\n // To compute x^y modulo m\n public static int power(long x, long y, int p) {\n x %= p;\n if (y == 0) {\n return 1;\n }\n long w = power(x, y / 2, p);\n w = (w * w) % p;\n return (int) (y % 2 == 0 ? w : (w * x) % p);\n }\n\n static int solveNaive(int[] a, int k) {\n // System.out.format(\"%s %d\\n\", Arrays.toString(a), k);\n // Note that the problem asks (E * n^k) % MOD, not E itself\n int n = a.length;\n int[] pows = new int[k+1];\n pows[0] = 1;\n for (int i = 1; i <= k; i++) {\n pows[i] = (pows[i-1] * n) % MOD;\n }\n return solveNaive(a, k, 1, pows);\n }\n\n static int index = 0;\n static int solveNaive(int[] a, int k, int i, int[] pows) {\n if (i > k) {\n return 0;\n }\n long sum = 0;\n for (int v : a) {\n sum += v;\n }\n // System.out.format(\" %7d i:%2d %s\\n\", ++index, i, Arrays.toString(a));\n int n = a.length;\n // Each number at this level contribute to pows[k - i] overall cases\n long ans = ((sum % MOD) * pows[k - i]) % MOD;\n\n // Each idx in [0,n-1] has equal probability to be chosen\n for (int idx = 0; idx < n; idx++) {\n int[] b = new int[n];\n System.arraycopy(a, 0, b, 0, n);\n b[idx] -= b[idx] % i;\n ans = (ans + solveNaive(b, k, i + 1, pows)) % MOD;\n }\n\n return (int) (ans % MOD);\n }\n\n static void doTest() {\n long t0 = System.currentTimeMillis();\n // show maxRange of around 110\n if (\"show\".isEmpty()) {\n int[] maxes = new int[18];\n for (int k = 1; k <= 17; k++) {\n int max = 0;\n for (int t = 0; t < 1000000; t++) {\n int v = 1 + RAND.nextInt(MOD);\n TreeSet curr = new TreeSet<>();\n curr.add(v);\n for (int i = 1; i <= k; i++) {\n TreeSet next = new TreeSet<>();\n for (int w : curr) {\n next.add(w);\n next.add(w - w % i);\n }\n curr = next;\n }\n int len = v - curr.first() + 1;\n if (len > max) {\n // System.out.format(\" %9d -> %3d %s\\n\", v, len, Utils.traceCollInt(curr));\n max = Math.max(max, len);\n }\n }\n maxes[k] = max;\n System.out.format(\" k:%2d max:%d\\n\", k, max);\n }\n System.out.format(\"maxes: %s\\n\", Arrays.toString(maxes));\n System.exit(0);\n }\n {\n // 10000000 235 125 236 2 2356723\n int n = 10000000;\n int[] a = new int[n];\n a[0] = 235;\n int x = 125;\n int y = 236;\n int k = 2;\n int M = 2356723;\n for (int i = 1; i < n; i++) {\n a[i] = (int) (((long)a[i - 1] * x + y) % M);\n }\n System.out.format(\"%d msec\\n\", System.currentTimeMillis() - t0);\n int ans = solve(a, k);\n System.out.println(ans);\n System.out.format(\"%d msec\\n\", System.currentTimeMillis() - t0);\n System.exit(0);\n }\n\n int[] a = {10, 35, 22};\n // int[] a = {432859723, 9873427};\n for (int k = 1; k <= 17; k++) {\n int ans = solve(a, k);\n int n = a.length;\n if (n < 4 || (n < 10 && k < 6)) {\n int exp = solveNaive(a, k);\n System.out.format(\"a:%s k:%2d -> %9d%s\\n\",\n Arrays.toString(a), k, ans, exp == ans ? \"\":\" Expected \" + exp);\n } else {\n System.out.format(\"a:%s k:%2d -> %9d\\n\", Arrays.toString(a), k, ans);\n }\n }\n System.out.println(Arrays.toString(a));\n System.out.format(\"%d msec\\n\", System.currentTimeMillis() - t0);\n System.exit(0);\n }\n\n public static void main(String[] args) {\n // doTest();\n Scanner in = getInputScanner();\n int n = in.nextInt();\n int[] a = new int[n];\n a[0] = in.nextInt();\n int x = in.nextInt();\n int y = in.nextInt();\n int k = in.nextInt();\n int M = in.nextInt();\n\n for (int i = 1; i < n; i++) {\n a[i] = (int) (((long)a[i - 1] * x + y) % M);\n }\n int ans = solve(a, k);\n System.out.println(ans);\n in.close();\n }\n\n static Scanner getInputScanner() {\n try {\n final String USERDIR = System.getProperty(\"user.dir\");\n final String CNAME = MethodHandles.lookup().lookupClass().getSimpleName();\n final File fin = new File(USERDIR + \"/io/c\" + CNAME.substring(1,5) + \"/\" + CNAME + \".in\");\n return fin.exists() ? new Scanner(fin) : new Scanner(System.in);\n } catch (Exception e) {\n return new Scanner(System.in);\n }\n }\n\n static void output(int[] a) {\n if (a == null) {\n System.out.println(\"-1\");\n return;\n }\n StringBuilder sb = new StringBuilder();\n for (int v : a) {\n sb.append(v);\n sb.append(' ');\n if (sb.length() > 500) {\n System.out.print(sb.toString());\n sb.setLength(0);\n }\n }\n System.out.println(sb.toString());\n }\n\n static void myAssert(boolean cond) {\n if (!cond) {\n throw new RuntimeException(\"Unexpected\");\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "d19199f5cb894d53311e583e43a74e09", "src_uid": "1d45491e28d24e2b318605cd328d6ecf", "difficulty": 2800.0} {"lang": "Java 6", "source_code": "import java.awt.AWTPermission;\nimport java.io.*;\nimport java.util.*;\n\npublic class E {\n\n public static void main(String[] args) throws Exception {\n reader = new MyReader(System.in);\n writer = System.out;\n new E().go();\n }\n\n static MyReader reader;\n static PrintStream writer;\n\n void go() {\n int n = reader.readInt();\n int k = reader.readInt();\n circles = new Circle[n];\n for(int i=0;i angles = new ArrayList();\n int cnt = 1;\n int best = 1;\n for(int b=0;b a2) ++cnt;\n if(b1>b2) ++cnt;\n angles.add(new Angle(a1, 1));\n angles.add(new Angle(a2, -1));\n angles.add(new Angle(b1, 1));\n angles.add(new Angle(b2, -1));\n }\n Collections.sort(angles);\n for(Angle angle : angles) {\n cnt += angle.d;\n best = Math.max(best, cnt);\n }\n return best;\n }\n \n private static double modulo(double a) {\n while(a>2*Math.PI) a -= 2*Math.PI;\n while(a<0) a += 2*Math.PI;\n return a;\n }\n \n private static class Angle implements Comparable {\n double a;\n int d;\n Angle(double a, int d) { this.a = a; this.d = d; }\n public int compareTo(Angle o) {\n if(a < o.a) return -1;\n else if(a > o.a) return 1;\n else return 0;\n }\n }\n\n private Circle readCircle() {\n Circle c = new Circle();\n c.x = reader.readInt();\n c.y = reader.readInt();\n c.r = reader.readInt();\n return c;\n }\n\n Circle[] circles;\n \n private static class Circle {\n int x,y,r;\n }\n \n \n private static class MyReader {\n private InputStream in;\n private byte[] buf;\n private int bufSize,bufPos;\n private int nextChar;\n \n public MyReader(InputStream in) {\n this.in = in;\n buf = new byte[16<<10];\n bufSize=0;\n bufPos=0;\n move();\n }\n \n private void move() {\n if (bufPos==bufSize) {\n try {\n bufSize = in.read(buf);\n } catch(IOException ex) {\n throw new RuntimeException(ex);\n }\n bufPos = 0;\n if (bufSize == -1) {\n nextChar = -1;\n return;\n }\n }\n nextChar = buf[bufPos++];\n }\n \n public int readInt() {\n skipWhitespace();\n int res = 0;\n while(nextChar >= '0' && nextChar <= '9') {\n res = 10*res + (nextChar-'0');\n move();\n }\n return res;\n }\n \n public long readLong() {\n skipWhitespace();\n long res = 0;\n while(nextChar >= '0' && nextChar <= '9') {\n res = 10*res + (nextChar-'0');\n move();\n }\n return res;\n }\n \n public String readString() {\n StringBuilder b = new StringBuilder();\n skipWhitespace();\n while(nextChar >= 33) {\n b.append((char)nextChar);\n move();\n }\n return b.toString();\n }\n \n public void skipWhitespace() {\n while(nextChar==' ' || nextChar=='\\n' || nextChar=='\\t' || nextChar=='\\r') move();\n }\n }\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "70dc65bbc0037cc837734e84c55a9924", "src_uid": "06ec7e481c963e635a6303503ffccc8b", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.io.*;\npublic class F2 {\n\n\tstatic long mod = 998244353; \n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\t\n\t\tString[] s = new String[n];\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\ts[i] = sc.next();\n\t\t}\t\n\t\t\n\t\tHashSet suffs = new HashSet<>();\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tfor(int j = 1; j < s[i].length(); j++){\n\t\t\t\tsuffs.add(s[i].substring(j));\n\t\t\t}\n\t\t}\n\t\tsuffs.add(\"\");\n\t\tHashSet nodes = new HashSet<>();\n\t\tfor(String a: suffs){\n\t\t\tfor(String b: suffs){\n\t\t\t\tif(isPref(a, b)) {\n\t\t\t\t\tnodes.add(new Pair(a, b));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint N = nodes.size();\n//\t\tSystem.out.println(N);\n\t\tHashMap code = new HashMap<>();\n\t\tPair[] decode = new Pair[N];\n\t\tint count = 0;\n\t\tfor(Pair p: nodes) {\n\t\t\tdecode[count] = p;\n\t\t\tcode.put(p, count++);\n\t\t}\n\t\tint[][] aut = new int[N][N];\n\t\tPair p0 = new Pair(\"\",\"\");\n\t\tfor(String t: s) {\n\t\t\tfor(String u: s) {\n\t\t\t\tif(isPref(t, u)) {\n\t\t\t\t\tString a = t.substring(1);\n\t\t\t\t\tString b = u.substring(1);\n\t\t\t\t\tPair p = new Pair(a, b);\n\t\t\t\t\taut[code.get(p0)][code.get(p)]++;\n\t\t\t\t}\n\t\t\t\telse if(isPref(u, t)) {\n\t\t\t\t\tString a = u.substring(1);\n\t\t\t\t\tString b = t.substring(1);\n\t\t\t\t\tPair p = new Pair(a, b);\n\t\t\t\t\taut[code.get(p0)][code.get(p)]++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor(Pair p: nodes) {\n\t\t\tPair q = next(p);\n\t\t\tif(p.equals(p0)){\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\telse if(q != null) {\n\t\t\t\taut[code.get(p)][code.get(q)]++;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tfor(String t: s) {\n\t\t\t\t\tq = next(p, t);\n\t\t\t\t\tif(q != null && nodes.contains(q)) {\n\t\t\t\t\t\taut[code.get(p)][code.get(q)]++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tMatrix mat = new Matrix(aut);\n\t\tMatrix matp = pow(mat, m);\n\t\tSystem.out.println(matp.mat[code.get(p0)][code.get(p0)]);\n\t}\n\tstatic Pair next(Pair p, String s) {\n\t\tif(p.a.equals(\"\")) {\n\t\t\tif(isPref(s, p.b)) {\n\t\t\t\tString a = s.substring(1);\n\t\t\t\tString b = p.b.substring(1);\n\t\t\t\treturn new Pair(a, b);\n\t\t\t}\n\t\t\telse if(isPref(p.b, s)) {\n\t\t\t\tString a = p.b.substring(1);\n\t\t\t\tString b = s.substring(1);\n\t\t\t\treturn new Pair(a, b);\n\t\t\t}\n\t\t\telse return null;\n\t\t}\n\t\telse return null;\n\t}\n\tstatic Pair next(Pair p) {\n\t\tif(p.a.equals(\"\")) return null;\n\t\tString a = p.a.substring(1);\n\t\tString b = p.b.substring(1);\n\t\treturn new Pair(a, b);\n\t}\n\tstatic boolean isPref(String a, String b) { //a of b\n\t\tif(a.length() > b.length()) return false;\n\t\telse return b.substring(0, a.length()).equals(a);\n\t}\n\tstatic class Pair {\n\t\tString a, b;\n\t\tpublic Pair(String a, String b) {\n\t\t\tthis.a = a; this.b = b;\n\t\t}\n\t\t@Override\n\t\tpublic int hashCode() {\n\t\t\treturn a.hashCode() + b.hashCode();\n\t\t}\n\t\t@Override\n\t\tpublic boolean equals(Object o) {\n\t\t\tPair p = (Pair)o;\n\t\t\treturn a.equals(p.a) && b.equals(p.b);\n\t\t}\n\t\tpublic String toString() {\n\t\t\treturn \"'\"+a+\"' '\"+b;\n\t\t}\n\t}\n\t\n\tstatic Matrix pow(Matrix m, int exp) {\n\t\tMatrix res = new Matrix(m.n);\n\t\tMatrix mapow = m;\n\t\twhile(exp > 0) {\n\t\t\tif((exp & 1) == 1) {\n\t\t\t\tres = res.mult(mapow);\n\t\t\t}\n\t\t\tmapow = mapow.mult(mapow);\n\t\t\texp >>= 1;\n\t\t}\n\t\treturn res;\n\t}\n\tstatic class Matrix{\n\t\tint[][] mat; int n;\n\t\tpublic Matrix(int[][] mat) {\n\t\t\tn = mat.length;\n\t\t\tthis.mat = mat;\n\t\t}\n\t\tpublic Matrix(int n) {\n\t\t\tmat = new int[n][n];\n\t\t\tthis.n = n;\n\t\t\tfor(int i = 0; i < n; i++) mat[i][i] = 1;\n\t\t}\n\t\tMatrix mult(Matrix m) {\n\t\t\tint[][] res = new int[n][n];\n\t\t\tfor(int k = 0; k < n; k++) {\n\t\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\t\tfor(int j = 0; j < n; j++) {\n\t\t\t\t\t\tlong a = mat[i][k];\n\t\t\t\t\t\tlong b = m.mat[k][j];\n\t\t\t\t\t\tlong c = res[i][j];\n\t\t\t\t\t\tres[i][j] = (int)((c + a*b%mod)%mod);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn new Matrix(res);\n\t\t}\n\t\tpublic String toString(){\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\tsb.append(Arrays.toString(mat[i])+\"\\n\");\n\t\t\t}\n\t\t\treturn sb.toString();\n\t\t}\n\t}\n\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "32c70bb943e82c9aa5dd2a369040af07", "src_uid": "711d15e11016d0164fb2b0c3756e4857", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\npublic class SlimeCombiningLinear {\n private static InputReader in;\n private static PrintWriter out;\n public static double EPS = 1e-15;\n public static int maxp = 50;\n \n public static void main (String[] args) {\n in = new InputReader(System.in);\n out = new PrintWriter(System.out, true);\n \n int n = in.nextInt();\n int p = in.nextInt();\n \n double p2 = p / 1000000000., p4 = 1 - p2;\n double[][] a = new double[maxp][maxp];\n double[][] b = new double[maxp][maxp];\n for (int len = 1; len < maxp; len++) { \n for (int pow = 1; pow < maxp; pow++) {\n if (pow == 1) a[len][pow] += p2;\n if (pow == 2) {\n a[len][pow] += p4;\n b[len][pow] += p4;\n }\n a[len][pow] += a[len-1][pow-1] * a[len][pow-1];\n b[len][pow] += a[len-1][pow-1] * b[len][pow-1];\n }\n }\n for (int len = maxp - 1; len >= 1; len--) {\n for (int pow = 1; pow < maxp; pow++) {\n a[len][pow] *= 1 - a[len-1][pow];\n b[len][pow] *= 1 - a[len-1][pow];\n }\n }\n \n // value of a slime that has been merged i times\n long[] vals = new long[maxp];\n for (int i = 0; i < maxp; i++) vals[i] = i;//1l << i;\n // manually do first few cases\n int maxn = 1000;\n double[][] dp = new double[maxn][maxp];\n double[][] sum = new double[maxn][maxp];\n for (int cur = 1; cur < maxp; cur++)\n dp[maxn-1][cur] = vals[cur];\n \n // manual dp\n for (int i = maxn-2; i >= 0; i--) {\n for (int cur = 1; cur < maxp; cur++) {\n for (int next = 1; next < maxp; next++) {\n if (cur == next) continue;\n if (cur == 1) {\n int id = Math.min(maxp-1, maxn-i-1);\n dp[i][cur] += b[id][next] * dp[i+1][next];\n sum[i][cur] += b[id][next];\n } else {\n if (cur < next) continue;\n int id = Math.min(maxp-1, maxn-i-1);\n dp[i][cur] += a[id][next] * dp[i+1][next];\n sum[i][cur] += a[id][next];\n }\n }\n }\n for (int cur = 1; cur < maxp; cur++) {\n dp[i][cur] = vals[cur] + dp[i][cur] / sum[i][cur];\n }\n }\n if (n <= maxn) {\n int k = (int)n;\n int w = Math.min(maxp-1, k);\n double exp = 0;\n for (int i = 1; i < maxp; i++) {\n exp += a[w][i] * dp[maxn-k][i];\n }\n out.printf(\"%.15f\\n\", exp);\n out.close();\n System.exit(0);\n }\n\n double exp1 = 0;\n double exp2 = 0;\n for (int i = 1; i < maxp; i++) {\n exp1 += a[maxp-1][i] * dp[0][i];\n exp2 += a[maxp-1][i] * dp[1][i];\n }\n out.printf(\"%.15f\\n\", exp2 + (exp1 - exp2) * (long)(n - maxn + 1));\n out.close();\n System.exit(0);\n }\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "cb9051f96096338deae640f571fa897b", "src_uid": "0aaf5fefed8b572b59bfce73dbbcde66", "difficulty": 3300.0} {"lang": "Java 11", "source_code": "//package com.company;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n public static class Task {\n boolean[] on;\n\n int gcd(int x, int y) {\n return y == 0 ? x: gcd(y, x % y);\n }\n long lcm(int x, int y) {\n int g = gcd(x, y);\n return (long) x * y / g;\n }\n\n public void solve(Scanner sc, PrintWriter pw) throws IOException {\n int N = 100000;\n on = new boolean[N + 1];\n Arrays.fill(on, true);\n int n = sc.nextInt();\n int[] a = new int[n];\n for (int i = 0; i < n; i++) {\n a[i] = sc.nextInt();\n }\n Arrays.sort(a);\n List alive = new ArrayList<>();\n for (int i = n - 1; i >= 0; i--) {\n int x = a[i];\n if (!on[x] || (i < n - 1 && a[i + 1] == x)) continue;\n alive.add(x);\n for (int j = 1; j * j <= x; j++) {\n if (x % j == 0) {\n on[j] = on[x / j] = false;\n }\n }\n }\n Collections.reverse(alive);\n long m = 0;\n if (alive.size() > 2000) {\n Collections.shuffle(alive);\n for (int i = 0; i < 1000; i++) {\n for (int j = i + 1; j < 2000; j++) {\n m = Math.max(m, lcm(alive.get(i), alive.get(j)));\n }\n }\n Collections.sort(alive);\n }\n int commonGcd = 0;\n for (int i = alive.size() - 1; i >= 0; i--) {\n int x = alive.get(i);\n commonGcd = gcd(x, commonGcd);\n m = Math.max(m, x);\n int lo = i + 1, hi = alive.size() - 1;\n while (lo < hi) {\n int mid = (lo + hi) >> 1;\n if ((long) x * alive.get(mid) <= (long) m * commonGcd) {\n lo = mid + 1;\n } else {\n hi = mid;\n }\n }\n for (int j = lo; j < alive.size(); j++) {\n m = Math.max(m, lcm(x, alive.get(j)));\n }\n }\n pw.println(m);\n }\n }\n\n static long TIME_START, TIME_END;\n\n public static void main(String[] args) throws IOException {\n Scanner sc = new Scanner(System.in);\n// Scanner sc = new Scanner(new FileInputStream(\"input\"));\n PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));\n// PrintWriter pw = new PrintWriter(new FileOutputStream(\"input\"));\n\n Runtime runtime = Runtime.getRuntime();\n long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();\n TIME_START = System.currentTimeMillis();\n Task t = new Task();\n t.solve(sc, pw);\n TIME_END = System.currentTimeMillis();\n long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();\n pw.close();\n System.err.println(\"Memory increased: \" + (usedMemoryAfter - usedMemoryBefore) / 1000000);\n System.err.println(\"Time used: \" + (TIME_END - TIME_START) + \".\");\n }\n\n static class Scanner {\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(InputStream s) {\n br = new BufferedReader(new InputStreamReader(s));\n }\n\n public Scanner(FileReader s) throws FileNotFoundException {\n br = new BufferedReader(s);\n }\n\n public String next() throws IOException {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public String nextLine() throws IOException {\n return br.readLine();\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n public boolean ready() throws IOException {\n return br.ready();\n }\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ec06c7eb1397077b8605a2de11423b86", "src_uid": "40002052843ca0357dbd3158b16d59f4", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.io.*; \nimport java.math.BigInteger;\nimport java.util.*;\n \npublic class Main {\n\tstatic final long MOD = 998244353;\n\tstatic int[] primes;\n\tstatic int P;\n public static void main(String[] args) throws IOException {\n FastScanner sc=new FastScanner();\n int N = sc.nextInt();\n int K = sc.nextInt();\n primes = new int[78498];\n primes[0] = 2;\n P = 1;\n long t1 = System.currentTimeMillis();\n for (int num = 3; num <= N; num++) {\n \tboolean prime = true;\n \tfor (int i = 0; i < P; i++) {\n \t\tif (num % primes[i] == 0) {\n \t\t\tprime = false;\n \t\t\tbreak;\n \t\t}\n \t\tif (primes[i]*primes[i] > num) {\n \t\t\tbreak;\n \t\t}\n \t}\n \tif (prime) {\n \t\tprimes[P] = num;\n \t\tP++;\n \t}\n }\n long t2 = System.currentTimeMillis();\n int[][] totients = new int[N+1][2];\n HashMap getT = new HashMap();\n getT.put(1,1);\n getT.put(2,1);\n for (int i = 0; i <= N; i++) {\n \tif (i < 3) {\n \t\ttotients[i][0] = Integer.MAX_VALUE;\n \t\tcontinue;\n \t}\n \ttotients[i][0] = totient(i);\n \ttotients[i][1] = i;\n \tgetT.put(i,totients[i][0]);\n }\n long t3 = System.currentTimeMillis();\n Arrays.sort(totients, new Comparator() {\n \t @Override\n \t public int compare(int[] arr1, int[] arr2) {\n \t return arr1[0]-arr2[0];\n \t //Ascending order.\n \t }\n });\n long t4 = System.currentTimeMillis();\n HashSet divisors = new HashSet();\n long iterations = 0;\n for (int i = 0; i < K; i++) {\n \tfor (int factor = 1; factor * factor <= N; factor++) {\n \t\titerations++;\n \t\tif (totients[i][1] % factor == 0) {\n \t\t\tdivisors.add(factor);\n \t\t\tdivisors.add(totients[i][1]/factor);\n \t\t}\n \t}\n }\n System.out.println(\"Iterations:\" + iterations);\n long t5 = System.currentTimeMillis();\n long ans = 0;\n for (int div: divisors) {\n \tans += getT.get(div);\n }\n System.out.println(ans);\n long t6 = System.currentTimeMillis();\n System.out.println(t2-t1);\n System.out.println(t3-t2);\n System.out.println(t4-t3);\n System.out.println(t5-t4);\n System.out.println(t6-t5);\n }\n \n public static int totient(int n) {\n \t//From Geeks4Geeks\n int result = n; \n for (int p: primes) {\n \tif (p == 0 || p * p > n) {\n \t\tbreak;\n \t}\n if (n % p == 0) { \n while (n % p == 0) \n n /= p; \n result -= result / p; \n } \n }\n if (n > 1) \n result -= result / n; \n return result; \n }\n \n static class FastScanner { \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\nclass Node {\n\tpublic int n;\n\tpublic HashSet children;\n\t\n\tpublic Node(int n) {\n\t\tthis.n = n;\n\t\tchildren = new HashSet();\n\t}\n\t\n\tpublic void addChild(Node node) {\n\t\tchildren.add(node);\n\t}\n\t\n\tpublic void removeChild(Node node) {\n\t\tchildren.remove(node);\n\t}\n}\n\nclass BinaryIndexedTree {\n\t public long[] arr;\n\n\t public BinaryIndexedTree (int N) {\n\t arr = new long[N+1];\n\t arr[0] = 0;\n\t }\n\n\t //add k to the i-th element.\n\t public void add(long k, int i) {\n\t int node = i+1;\n\t while (node < arr.length) {\n\t arr[node] += k;\n\t node += node & (-node);\n\t }\n\t }\n\n\t //sum up the elements from input[s_i] to input[e_i], from [s_i,e_i).\n\t public long sum(int s_i, int e_i) {\n\t return sum(e_i) - sum(s_i);\n\t }\n\n\t public long sum(int i) {\n\t long total = 0;\n\t int node = i;\n\t while (node > 0) {\n\t total += arr[node];\n\t node -= node & (-node);\n\t }\n\t return total;\n\t }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "247e9da0b5329dd382f053c4404f9f2b", "src_uid": "c2f7012082c84d773c2f4b1858c17110", "difficulty": 2800.0} {"lang": "Java 7", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tnew Main().run();\n\t}\n\n\tfinal static int PERIOD = 60;\n\tfinal static int POWER = 13;\n\n\tlong fib(long n, long mod) {\n\t\tlong[][] mat = new long[2][2];\n\t\tmat[0][1] = mat[1][0] = mat[1][1] = 1;\n\t\tMatrix v = new Matrix(mat);\n\t\tv = v.power(n, mod);\n\t\treturn v.mat[0][1];\n\t}\n\n\tvoid run() {\n\t\tInputReader in = new InputReader(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\n\t\tlong num = in.nextInt(), mod = 10, per = PERIOD;\n\t\tArrayList valid = new ArrayList();\n\t\tfor (int i = 0; i < PERIOD; ++i)\n\t\t\tif (fib(i, mod) == num % mod)\n\t\t\t\tvalid.add((long)i);\n\n\t\tfor (int i = 1; i < POWER; ++i) {\n\t\t\tmod *= 10;\n\t\t\tlong rem = num % mod;\n\t\t\tArrayList nv = new ArrayList();\n\t\t\tfor (int j = 0; j < 10; ++j)\n\t\t\t\tfor (int k = 0; k < valid.size(); ++k) {\n\t\t\t\t\tif (fib(j * per + valid.get(k), mod) == rem)\n\t\t\t\t\t\tnv.add(j * per + valid.get(k));\n\t\t\t\t}\n\t\t\tvalid = nv;\n\t\t\tper *= 10;\n\t\t}\n\n\t\tif (valid.size() == 0)\n\t\t\tout.println(-1);\n\t\telse\n\t\t\tout.println(valid.get(0));\n\t\tout.close();\n\t}\n}\n\nclass Matrix {\n\tlong[][] mat;\n\tfinal static Matrix ONE = new Matrix(new long[][] {{1, 0}, {0, 1}});\n\tMatrix(long[][] mat) {\n\t\tthis.mat = mat;\n\t}\n\tlong add(long a, long b, long mod) {\n\t\tif (a + b >= mod)\n\t\t\treturn a + b - mod;\n\t\treturn a + b;\n\t}\n\tlong multiply(long a, long b, long mod) {\n\t\tlong ret = 0;\n\t\twhile (a > 0) {\n\t\t\tif ((a & 1) == 1)\n\t\t\t\tret = add(ret, b, mod);\n\t\t\tb = add(b, b, mod);\n\t\t\ta >>= 1;\n\t\t}\n\t\treturn ret;\n\t}\n\tMatrix multiply(Matrix o, long mod) {\n\t\tlong[][] ret = new long[2][2];\n\t\tfor (int i = 0; i < 2; ++i)\n\t\t\tfor (int j = 0; j < 2; ++j)\n\t\t\t\tfor (int k = 0; k < 2; ++k)\n\t\t\t\t\tret[i][j] = add(ret[i][j], multiply(mat[i][k], o.mat[k][j], mod), mod);\n\t\treturn new Matrix(ret);\n\t}\n\tMatrix power(long p, long mod) {\n\t\tif (p == 0) {\n\t\t\treturn Matrix.ONE;\n\t\t}\n\t\tMatrix ret = power(p / 2, mod);\n\t\tret = ret.multiply(ret, mod);\n\t\tif ((p & 1) == 1)\n\t\t\tret = ret.multiply(this, mod);\n\t\treturn ret;\n\t}\n}\n\nclass InputReader {\n\tBufferedReader buff;\n\tStringTokenizer tokenizer;\n\n\tInputReader(InputStream stream) {\n\t\tbuff = new BufferedReader(new InputStreamReader(stream));\n\t\ttokenizer = null;\n\t}\n\tboolean hasNext() {\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens())\n\t\t\ttry {\n\t\t\t\ttokenizer = new StringTokenizer(buff.readLine());\n\t\t\t}\n\t\t\tcatch (Exception e) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\treturn true;\n\t}\n\tString next() {\n\t\tif (!hasNext())\n\t\t\tthrow new RuntimeException();\n\t\treturn tokenizer.nextToken();\n\t}\n\tint nextInt() { return Integer.parseInt(next()); }\n\tlong nextLong() { return Long.parseLong(next()); }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "9aef22048ee712b1dc9d16e10db04d36", "src_uid": "cbf786abfceeb8df29732c8a872f7f8a", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintStream;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.io.UncheckedIOException;\nimport java.io.Closeable;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, new TaskAdapter(), \"\", 1 << 27);\n thread.start();\n thread.join();\n }\n\n static class TaskAdapter implements Runnable {\n @Override\n public void run() {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastInput in = new FastInput(inputStream);\n FastOutput out = new FastOutput(outputStream);\n DSingerHouse solver = new DSingerHouse();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class DSingerHouse {\n Debug debug = new Debug(true);\n\n public void solve(int testNumber, FastInput in, FastOutput out) {\n int n = in.readInt();\n int m = n + 2;\n int[][] dp = new int[n + 1][m + 1];\n\n Modular mod = new Modular(1e9 + 7);\n Combination comb = new Combination(10000, mod);\n\n dp[0][0] = 1;\n for (int i = 1; i <= n; i++) {\n for (int j = 0; j <= m; j++) {\n if (dp[i - 1][j] == 0) {\n continue;\n }\n for (int k = 0; k <= m; k++) {\n if (dp[i - 1][k] == 0) {\n continue;\n }\n int way = mod.mul(dp[i - 1][j], dp[i - 1][k]);\n if (j + k <= m) {\n //not appear\n int next = j + k;\n dp[i][next] = mod.plus(dp[i][next], way);\n }\n if (j + k - 1 <= m && j + k - 1 >= 0) {\n //appear, and concatenate\n int next = j + k - 1;\n int local = mod.mul(way, (j + k) * (j + k - 1));\n dp[i][next] = mod.plus(dp[i][next], local);\n }\n// if (j + k - 1 <= m && j >= 1) {\n// //appear, and concatenate left side\n// int next = j - 1 + k;\n// int local = mod.mul(way, j);\n// local = mod.mul(local, j);\n// dp[i][next] = mod.plus(dp[i][next], local);\n// }\n// if (j + k - 1 <= m && k >= 1) {\n// //appear, and concatenate right side\n// int next = j - 1 + k;\n// int local = mod.mul(way, k);\n// local = mod.mul(local, k);\n// dp[i][next] = mod.plus(dp[i][next], local);\n// }\n if (j + k <= m) {\n //appear, but only appear on one side\n int next = j + k;\n int local = mod.mul(way, 2 * (j + k));\n dp[i][next] = mod.plus(dp[i][next], local);\n }\n if (j + k + 1 <= m) {\n //appear, with new in/out\n int next = j + k + 1;\n dp[i][next] = mod.plus(dp[i][next], way);\n }\n }\n }\n dp[i][0] = 1;\n }\n\n debug.debug(\"dp\", dp);\n int ans = dp[n][1];\n out.println(ans);\n }\n\n }\n\n static class Debug {\n private boolean offline;\n private PrintStream out = System.err;\n static int[] empty = new int[0];\n\n public Debug(boolean enable) {\n offline = enable && System.getSecurityManager() == null;\n }\n\n public Debug debug(String name, Object x) {\n return debug(name, x, empty);\n }\n\n public Debug debug(String name, Object x, int... indexes) {\n if (offline) {\n if (x == null || !x.getClass().isArray()) {\n out.append(name);\n for (int i : indexes) {\n out.printf(\"[%d]\", i);\n }\n out.append(\"=\").append(\"\" + x);\n out.println();\n } else {\n indexes = Arrays.copyOf(indexes, indexes.length + 1);\n if (x instanceof byte[]) {\n byte[] arr = (byte[]) x;\n for (int i = 0; i < arr.length; i++) {\n indexes[indexes.length - 1] = i;\n debug(name, arr[i], indexes);\n }\n } else if (x instanceof short[]) {\n short[] arr = (short[]) x;\n for (int i = 0; i < arr.length; i++) {\n indexes[indexes.length - 1] = i;\n debug(name, arr[i], indexes);\n }\n } else if (x instanceof boolean[]) {\n boolean[] arr = (boolean[]) x;\n for (int i = 0; i < arr.length; i++) {\n indexes[indexes.length - 1] = i;\n debug(name, arr[i], indexes);\n }\n } else if (x instanceof char[]) {\n char[] arr = (char[]) x;\n for (int i = 0; i < arr.length; i++) {\n indexes[indexes.length - 1] = i;\n debug(name, arr[i], indexes);\n }\n } else if (x instanceof int[]) {\n int[] arr = (int[]) x;\n for (int i = 0; i < arr.length; i++) {\n indexes[indexes.length - 1] = i;\n debug(name, arr[i], indexes);\n }\n } else if (x instanceof float[]) {\n float[] arr = (float[]) x;\n for (int i = 0; i < arr.length; i++) {\n indexes[indexes.length - 1] = i;\n debug(name, arr[i], indexes);\n }\n } else if (x instanceof double[]) {\n double[] arr = (double[]) x;\n for (int i = 0; i < arr.length; i++) {\n indexes[indexes.length - 1] = i;\n debug(name, arr[i], indexes);\n }\n } else if (x instanceof long[]) {\n long[] arr = (long[]) x;\n for (int i = 0; i < arr.length; i++) {\n indexes[indexes.length - 1] = i;\n debug(name, arr[i], indexes);\n }\n } else {\n Object[] arr = (Object[]) x;\n for (int i = 0; i < arr.length; i++) {\n indexes[indexes.length - 1] = i;\n debug(name, arr[i], indexes);\n }\n }\n }\n }\n return this;\n }\n\n }\n\n static interface IntCombination {\n }\n\n static class Modular {\n int m;\n\n public int getMod() {\n return m;\n }\n\n public Modular(int m) {\n this.m = m;\n }\n\n public Modular(long m) {\n this.m = (int) m;\n if (this.m != m) {\n throw new IllegalArgumentException();\n }\n }\n\n public Modular(double m) {\n this.m = (int) m;\n if (this.m != m) {\n throw new IllegalArgumentException();\n }\n }\n\n public int valueOf(int x) {\n x %= m;\n if (x < 0) {\n x += m;\n }\n return x;\n }\n\n public int valueOf(long x) {\n x %= m;\n if (x < 0) {\n x += m;\n }\n return (int) x;\n }\n\n public int mul(int x, int y) {\n return valueOf((long) x * y);\n }\n\n public int plus(int x, int y) {\n return valueOf(x + y);\n }\n\n public String toString() {\n return \"mod \" + m;\n }\n\n }\n\n static class Factorial {\n int[] fact;\n int[] inv;\n Modular modular;\n\n public Modular getModular() {\n return modular;\n }\n\n public Factorial(int[] fact, int[] inv, InverseNumber in, int limit, Modular modular) {\n this.modular = modular;\n this.fact = fact;\n this.inv = inv;\n fact[0] = inv[0] = 1;\n for (int i = 1; i <= limit; i++) {\n fact[i] = modular.mul(fact[i - 1], i);\n inv[i] = modular.mul(inv[i - 1], in.inv[i]);\n }\n }\n\n public Factorial(int limit, Modular modular) {\n this(new int[limit + 1], new int[limit + 1], new InverseNumber(limit, modular), limit, modular);\n }\n\n }\n\n static class Combination implements IntCombination {\n final Factorial factorial;\n final Modular modular;\n\n public Combination(Factorial factorial) {\n this.factorial = factorial;\n this.modular = factorial.getModular();\n }\n\n public Combination(int limit, Modular modular) {\n this(new Factorial(limit, modular));\n }\n\n }\n\n static class InverseNumber {\n int[] inv;\n\n public InverseNumber(int[] inv, int limit, Modular modular) {\n this.inv = inv;\n inv[1] = 1;\n int p = modular.getMod();\n for (int i = 2; i <= limit; i++) {\n int k = p / i;\n int r = p % i;\n inv[i] = modular.mul(-k, inv[r]);\n }\n }\n\n public InverseNumber(int limit, Modular modular) {\n this(new int[limit + 1], limit, modular);\n }\n\n }\n\n static class FastOutput implements AutoCloseable, Closeable, Appendable {\n private StringBuilder cache = new StringBuilder(10 << 20);\n private final Writer os;\n\n public FastOutput append(CharSequence csq) {\n cache.append(csq);\n return this;\n }\n\n public FastOutput append(CharSequence csq, int start, int end) {\n cache.append(csq, start, end);\n return this;\n }\n\n public FastOutput(Writer os) {\n this.os = os;\n }\n\n public FastOutput(OutputStream os) {\n this(new OutputStreamWriter(os));\n }\n\n public FastOutput append(char c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput append(int c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput println(int c) {\n return append(c).println();\n }\n\n public FastOutput println() {\n cache.append(System.lineSeparator());\n return this;\n }\n\n public FastOutput flush() {\n try {\n os.append(cache);\n os.flush();\n cache.setLength(0);\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n return this;\n }\n\n public void close() {\n flush();\n try {\n os.close();\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n public String toString() {\n return cache.toString();\n }\n\n }\n\n static class FastInput {\n private final InputStream is;\n private byte[] buf = new byte[1 << 13];\n private int bufLen;\n private int bufOffset;\n private int next;\n\n public FastInput(InputStream is) {\n this.is = is;\n }\n\n private int read() {\n while (bufLen == bufOffset) {\n bufOffset = 0;\n try {\n bufLen = is.read(buf);\n } catch (IOException e) {\n bufLen = -1;\n }\n if (bufLen == -1) {\n return -1;\n }\n }\n return buf[bufOffset++];\n }\n\n public void skipBlank() {\n while (next >= 0 && next <= 32) {\n next = read();\n }\n }\n\n public int readInt() {\n int sign = 1;\n\n skipBlank();\n if (next == '+' || next == '-') {\n sign = next == '+' ? 1 : -1;\n next = read();\n }\n\n int val = 0;\n if (sign == 1) {\n while (next >= '0' && next <= '9') {\n val = val * 10 + next - '0';\n next = read();\n }\n } else {\n while (next >= '0' && next <= '9') {\n val = val * 10 - next + '0';\n next = read();\n }\n }\n\n return val;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "60742be62431f741e1cb300c3b154660", "src_uid": "fda761834f7b5800f540178ac1c79fca", "difficulty": 2800.0} {"lang": "Java 8", "source_code": "\n// submission outside of the contest found in editorial:\n// http://codeforces.com/blog/entry/51685\n\n// this is the only code I've found that passes all test cases\n\n// http://codeforces.com/contest/793/submission/26669894\n// ext .cpp to increase idea compilation time\n\nimport static java.lang.Double.parseDouble;\nimport static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.System.exit;\nimport static java.util.Arrays.fill;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class GFast {\n\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n\n\tstatic int n, len;\n\tstatic long edges[][];\n\tstatic int matchingL[], matchingR[];\n\tstatic int hkQueue[];\n\tstatic long hkSet[], hkSet2[][];\n\n\tstatic final int BIT_INDEX[] = {\n\t\t0, 1, 2, 7, 3, 13, 8, 19, 4, 25, 14, 28, 9, 34, 20, 40,\n\t\t5, 17, 26, 38, 15, 46, 29, 48, 10, 31, 35, 54, 21, 50, 41, 57,\n\t\t63, 6, 12, 18, 24, 27, 33, 39, 16, 37, 45, 47, 30, 53, 49, 56,\n\t\t62, 11, 23, 32, 36, 44, 52, 55, 61, 22, 43, 51, 60, 42, 59, 58};\n\n\tstatic int bitIndex(long x) {\n\t\treturn BIT_INDEX[(int) ((x * 0x218a392cd3d5dbfL) >>> 58)];\n\t}\n\n\tstatic int hopcroftKarp() {\n\t\tfill(matchingL, -1);\n\t\tfill(matchingR, -1);\n\t\tint size = 0;\n\t\twhile (true) {\n\t\t\tfill(hkSet, -1L);\n\t\t\tint queueHead = 0, queueTail = 0;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (matchingL[i] < 0) {\n\t\t\t\t\thkQueue[queueTail++] = i;\n\t\t\t\t\thkQueue[queueTail++] = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tint resDist = -1;\n\t\t\twhile (queueHead < queueTail) {\n\t\t\t\tint cur = hkQueue[queueHead++];\n\t\t\t\tint cdist = hkQueue[queueHead++];\n\t\t\t\tif ((cdist + Integer.MIN_VALUE) > (resDist + Integer.MIN_VALUE)) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tlong ecur[] = edges[cur], curSet2[] = hkSet2[cdist];\n\t\t\t\tfor (int nextBlock = 0; nextBlock < len; nextBlock++) {\n\t\t\t\t\tlong v = hkSet[nextBlock], w = ecur[nextBlock] & v;\n\t\t\t\t\tif (w == 0) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\thkSet[nextBlock] = v ^ w;\n\t\t\t\t\tcurSet2[nextBlock] |= w;\n\t\t\t\t\tdo {\n\t\t\t\t\t\tlong x = w & -w;\n\t\t\t\t\t\tw ^= x;\n\t\t\t\t\t\tint next = (nextBlock << 6) + bitIndex(x);\n\t\t\t\t\t\tint next2 = matchingR[next];\n\t\t\t\t\t\tif (next2 < 0) {\n\t\t\t\t\t\t\tresDist = cdist;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\thkQueue[queueTail++] = next2;\n\t\t\t\t\t\t\thkQueue[queueTail++] = cdist + 1;\n\t\t\t\t\t\t}\n\t\t\t\t\t} while (w != 0);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (resDist == -1) {\n\t\t\t\treturn size;\n\t\t\t}\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (matchingL[i] < 0 && hopcroftKarpDfs(i, 0)) {\n\t\t\t\t\t++size;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int i = 0; i <= resDist; i++) {\n\t\t\t\tfill(hkSet2[i], 0);\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic boolean hopcroftKarpDfs(int cur, int cdist) {\n\t\tlong ecur[] = edges[cur], curSet2[] = hkSet2[cdist];\n\t\tfor (int nextBlock = 0; nextBlock < len; nextBlock++) {\n\t\t\tlong v = curSet2[nextBlock], w = ecur[nextBlock] & v;\n\t\t\tif (w == 0) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tv ^= w;\n\t\t\tdo {\n\t\t\t\tlong x = w & -w;\n\t\t\t\tw ^= x;\n\t\t\t\tint next = (nextBlock << 6) + bitIndex(x);\n\t\t\t\tint next2 = matchingR[next];\n\t\t\t\tif (next2 < 0 || hopcroftKarpDfs(next2, cdist + 1)) {\n\t\t\t\t\tmatchingR[next] = cur;\n\t\t\t\t\tmatchingL[cur] = next;\n\t\t\t\t\tcurSet2[nextBlock] = v ^ w;\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t} while (w != 0);\n\t\t\tcurSet2[nextBlock] = v;\n\t\t}\n\t\treturn false;\n\t}\n\n\tstatic void solve() throws Exception {\n\t\tn = nextInt();\n\t\tint q = nextInt();\n\t\tlen = (n + 63) >> 6;\n\t\tedges = new long[n][len];\n\t\tmatchingL = new int[n];\n\t\tmatchingR = new int[n];\n\t\thkQueue = new int[2 * n];\n\t\thkSet = new long[len];\n\t\thkSet2 = new long[n][len];\n\t\tfor (int x = 0; x < n; x++) {\n\t\t\tfor (int y = 0; y < n >> 6; y++) {\n\t\t\t\tedges[x][y] = -1L;\n\t\t\t}\n\t\t\tif ((n & 63) != 0) {\n\t\t\t\tedges[x][n >> 6] = (1L << n) - 1;\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < q; i++) {\n\t\t\tint x1 = nextInt() - 1;\n\t\t\tint y1 = nextInt() - 1;\n\t\t\tint x2 = nextInt();\n\t\t\tint y2 = nextInt();\n\t\t\tif (y1 >> 6 == y2 >> 6) {\n\t\t\t\tlong mask = ~((1L << y2) - (1L << y1));\n\t\t\t\tfor (int x = x1; x < x2; x++) {\n\t\t\t\t\tedges[x][y1 >> 6] &= mask;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (int x = x1; x < x2; x++) {\n\t\t\t\t\tedges[x][y1 >> 6] &= ~(-1L << y1);\n\t\t\t\t\tfor (int y = (y1 >> 6) + 1; y < y2 >> 6; y++) {\n\t\t\t\t\t\tedges[x][y] = 0;\n\t\t\t\t\t}\n\t\t\t\t\tif ((y2 & 63) != 0) {\n\t\t\t\t\t\tedges[x][y2 >> 6] &= -1L << y2;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.print(hopcroftKarp());\n\t}\n\n\tstatic int nextInt() throws IOException {\n\t\treturn parseInt(next());\n\t}\n\n\tstatic long nextLong() throws IOException {\n\t\treturn parseLong(next());\n\t}\n\n\tstatic double nextDouble() throws IOException {\n\t\treturn parseDouble(next());\n\t}\n\n\tstatic String next() throws IOException {\n\t\twhile (tok == null || !tok.hasMoreTokens()) {\n\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(new OutputStreamWriter(System.out));\n\t\t\tsolve();\n\t\t\tin.close();\n\t\t\tout.close();\n\t\t} catch (Throwable e) {\n\t\t\te.printStackTrace();\n\t\t\texit(1);\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "eb023514b97ecf78d36ae460a7a40384", "src_uid": "d662ef3f9a70a5afaa2f0f68327a457f", "difficulty": 3400.0} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\n\npublic class E {\n \n static double e = 1e-8, R, phi0;\n static int x,y,r,v,vp; \n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int xp = sc.nextInt();\n int yp = sc.nextInt();\n vp = sc.nextInt();\n x = sc.nextInt();\n y = sc.nextInt();\n v = sc.nextInt();\n r = sc.nextInt();\n R = Math.sqrt(xp*xp+yp*yp);\n phi0 = Math.acos(xp / R);\n double left = 0, right = 1e9;\n for(;;) {\n double middle = (left+right) / 2;\n if (reache(middle) && !reache(middle-e)) {\n System.out.println(middle);\n return;\n }\n if (reache(middle))\n right = middle-e;\n else\n left = middle+e;\n }\n }\n\n private static boolean reache(double t) {\n double x2 = R*Math.cos(vp/R*t+phi0);\n double y2 = R*Math.sin(vp/R*t+phi0);\n double x1 = x, y1 = y;\n double a = y1-y2, b = x2-x1, c = x1*y2-x2*y1;\n double d = Math.abs(c)/Math.sqrt(a*a+b*b);\n double reach_time = 0;\n a = dis(x1, y1, 0, 0);\n b = dis(x2, y2, 0, 0);\n c = dis(x1, y1, x2, y2);\n if (d >= r || Math.abs(Math.sqrt(a*a-d*d)+Math.sqrt(b*b-d*d)-c) > e) {\n reach_time = c / v;\n }\n else {\n double alfa = Math.acos((x1*x2+y1*y2) / (a*b))-Math.acos(r/a)-Math.acos(r/b);\n reach_time = (r*alfa+Math.sqrt(a*a-r*r)+Math.sqrt(b*b-r*r)) / v;\n }\n return reach_time <= t;\n }\n\n private static double dis(double x1, double y1, double x2, double y2) {\n return Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));\n }\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "b005889a524bc3df0a6c0b12c3f8b976", "src_uid": "e8471556906e5fa3a701842570fa4ee2", "difficulty": 2400.0} {"lang": "Java 7", "source_code": "import java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.io.PrintStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Random;\nimport java.io.Writer;\nimport java.util.Collection;\nimport java.util.List;\nimport java.util.BitSet;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.ArrayList;\nimport java.util.NoSuchElementException;\nimport java.util.TreeSet;\nimport java.math.BigInteger;\nimport java.util.Collections;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author ogiekako\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\tMyScanner in = new MyScanner(inputStream);\n\t\tMyPrintWriter out = new MyPrintWriter(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 int MOD = 777777777;\n long[][] C = MathUtils.generateCombination(257, MOD);\n public void solve(int testNumber, MyScanner in, MyPrintWriter out) {\n int n = in.nextInt(), k = in.nextInt();\n long[][] dp = new long[k+1][n-k+1];\n dp[0][0] = 1;\n for(int i=1;i<=n;i++){\n long[][] nxt = new long[k+1][n-k+1];\n for(int lie=0;lie0){\n int rest = n - lie - hon;\n for(int use=0;use<=rest;use++){\n if(use==i && hon + use < n-k+1){\n nxt[lie][hon+use] = (nxt[lie][hon+use] + dp[lie][hon] * C[rest][use]) % MOD;\n }else if(use!=i && lie+use= modulus) C[i][j] -= modulus;\n }\n return C;\n }\n\n }\n\nclass MyScanner {\n private final InputStream in;\n\n public MyScanner(InputStream in) {\n this.in = in;\n }\n\n int bufLen;\n int bufPtr;\n byte[] buf = new byte[1024];\n\n public int read() {\n if (bufLen == -1)\n throw new InputMismatchException();\n if (bufPtr >= bufLen) {\n bufPtr = 0;\n try {\n bufLen = in.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (bufLen <= 0)\n return -1;\n }\n return buf[bufPtr++];\n }\n\n public int nextInt() {\n try {\n int c = read();\n if (c == -1) return c;\n while (c != '-' && (c < '0' || '9' < c)) {\n c = read();\n if (c == -1) return c;\n }\n if (c == '-') return -nextInt();\n int res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = read();\n } while ('0' <= c && c <= '9');\n return res;\n } catch (Exception e) {\n return -1;\n }\n }\n\n\n }\n\nclass MyPrintWriter {\n PrintWriter out;\n\n public MyPrintWriter(OutputStream outputStream) {\n out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public MyPrintWriter(Writer writer) {\n out = new PrintWriter(writer);\n }\n\n public void println(Object... os) {\n for (int i = 0; i < os.length - 1; i++) {\n out.print(os[i]);\n out.print(' ');\n }\n out.println(os[os.length - 1]);\n }\n\n public void close() {\n out.close();\n }\n\n }\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "4c139cfd62d3c0b7602fe8e8150155b4", "src_uid": "cfe19131644e5925e32084a581e23286", "difficulty": 2700.0} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main {\n static boolean f = false,flag = false;\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n String a = \"\", c = \"\";\n\n String s = scan.next();\n char[] sArray = s.toCharArray();\n if (sArray.length < 100) {\n\n\n if (sArray.length % 2 != 0) {\n for (int i = sArray.length / 2 + 1; i < sArray.length; i++) {\n for (int y = 0; y < i; y++) {\n c = c + sArray[y];\n a = sArray[sArray.length - 1 - y] + a;\n }\n if (a.equals(c)) {\n f = true;\n break;\n }\n }\n }\n if (sArray.length % 2 == 0) {\n for (int i = sArray.length / 2 ; i < sArray.length - 1 ; i++) {\n for (int y = 0; y < i + 1; y++) {\n a = a + sArray[y];\n }\n for (int y = sArray.length - i - 1; y < sArray.length ;y++){\n c = c + sArray[y];\n }\n if (a.equals(c)) {\n f = true;break;\n }\n a = \"\";\n c = \"\";\n\n }\n\n }\n\n {\n String m = c;\n c = \"\";\n a = \"\";\n for (int y = sArray.length / 2; y < sArray.length; y++) {\n c = c + sArray[y];\n a = sArray[sArray.length - 1 - y] + a;\n\n }\n if (a.equals(c)) {\n flag = true;\n\n }\n if ((!f && !flag) || (!f && flag)){\n System.out.print(\"NO\");\n }\n if ((f) || (f && !flag)){\n System.out.print(\"YES\\n\" + m);\n\n }\n }\n }\n }\n }\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "62e9e0d02b3d40cff7fc65324ad196b8", "src_uid": "bfa78f72af4875f670f7adc5ed127033", "difficulty": 1500.0} {"lang": "Java 8", "source_code": "import java.lang.*;\nimport java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class PE{\n\tfinal static long MOD=1000000007L;\n\tstatic long v[], k, w;\n\tstatic Scanner sc=new Scanner(System.in);\n\tstatic {\n\t\tv=new long[1000001];\n\t\tv[0] = 0; v[1] = 1;\n\t\t//for(int i=2; i <= 1000000; i++) v[i]=modPow(i,MOD-2);\n\t\tfor(int i=2; i <= 1000000; i++) v[i]=v[(int)MOD%i]*(MOD-MOD/i)%MOD;\n\t}\n\tstatic long modPow(long a, long x) // a^x\n\t{\n\t\tlong ret = 1L;\n\t\tfor(; x>0; x>>=1, a=a*a%MOD) if(1==(x&1))ret=ret*a%MOD;\n\t\treturn ret;\n\t}\n\tstatic long f(long x)\n\t{\n\t\tlong ret=0L, s=modPow(k,x);\n\t\tfor(int i = 0; i < k; i++)\n\t\t{\n\t\t\tret=(ret+s)%MOD;\n\t\t\ts=s*v[(int)k+(int)(x>i+2?0L:x-i-2)]%MOD*(k-i-1)%MOD*(k-i-1)%MOD;\n\t\t}\n\t\treturn ret;\n\t}\n\tpublic static void main(String args[]) throws Exception\n\t{\n//\t\tint ncases=sc.nextInt();\n//\t\twhile(ncases-->0)\n\t\t{\n\t\t\tk=sc.nextLong();\n\t\t\tw=sc.nextLong();\n\t\t\tSystem.out.println((f(w+1)-f(w)+MOD+modPow(k,w))%MOD);\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "24b4ff876e72b949f5770dd3049494de", "src_uid": "b715f0fdc83ec539eb3ae2b0371ee130", "difficulty": 3000.0} {"lang": "Java 8", "source_code": "/*\r\nI am dead inside\r\nDo you like NCT, sKz, BTS?\r\n5 4 3 2 1 Moonwalk\r\nImma knock it down like domino\r\nIs this what you want? Is this what you want?\r\nLet's ttalkbocky about that\r\n */\r\nimport static java.lang.Math.*;\r\nimport java.util.*;\r\nimport java.io.*;\r\nimport java.math.*;\r\n\r\npublic class lolE\r\n{\r\n static String target = \"theseus\";\r\n static String reverse = \"sueseth\";\r\n //static int[] dx = {-1, 1, 0, 0, -1, -1, 1, 1};\r\n //static int[] dy = {0, 0, -1, 1, -1, 1, -1, 1};\r\n //static int[] dx = {0, 1, 1};\r\n //static int[] dy = {1, 0, 1};\r\n public static void main(String omkar[]) throws Exception\r\n {\r\n BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));\r\n StringTokenizer st = new StringTokenizer(infile.readLine());\r\n int N = Integer.parseInt(st.nextToken());\r\n char[][] grid = new char[N][N];\r\n for(int r=0; r < N; r++)\r\n grid[r] = infile.readLine().trim().toCharArray();\r\n String res = \"NO\";\r\n for(int r=0; r < N; r++)\r\n for(int c=0; c < N-6; c++)\r\n {\r\n String temp = \"\";\r\n for(int i=c; i < c+7; i++)\r\n temp += grid[r][i];\r\n if(temp.equals(target))\r\n res = \"YES\";\r\n }\r\n for(int c=0; c < N; c++)\r\n for(int r=0; r < N-6; r++)\r\n {\r\n String temp = \"\";\r\n for(int i=r; i < r+7; i++)\r\n temp += grid[i][c];\r\n if(temp.equals(target))\r\n res = \"YES\";\r\n }\r\n //diagonals\r\n for(int r=0; r < N; r++)\r\n for(int c=0; c < N; c++)\r\n {\r\n String temp = \"\";\r\n int lol = 0;\r\n while(temp.length() < 7)\r\n {\r\n if(max(r, c)+lol >= N)\r\n break;\r\n temp += grid[r+lol][c+lol];\r\n lol++;\r\n }\r\n if(temp.equals(target))\r\n res = \"YES\";\r\n }\r\n System.out.println(res);\r\n }\r\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "c36c384a1f38360ab805d4403c0044db", "src_uid": "efb72baf6759f7bc5ac0f3099b7177d0", "difficulty": -1.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class E {\n\tFastScanner in;\n\tPrintWriter out;\n\n\tfinal int mod = (int) 1e9 + 7;\n\n\tvoid solve() {\n\t\tint n = in.nextInt();\n\t\tint[] a = new int[n - 1];\n\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\ta[i] = in.nextInt();\n\t\t}\n\t\tint[] b = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tb[i] = in.nextInt();\n\t\t}\n\t\tBigInteger need = new BigInteger(in.next());\n\t\tint[] needA = new int[n];\n\t\tfor (int i = 0; i + 1 < n; i++) {\n\t\t\tif (a[i] != 1) {\n\t\t\t\tneedA[i] = need.mod(BigInteger.valueOf(a[i])).intValue();\n\t\t\t\tneed = need.divide(BigInteger.valueOf(a[i]));\n\t\t\t}\n\t\t}\n\t\tif (need.compareTo(BigInteger.valueOf((int) 1e9)) > 0) {\n\t\t\tout.println(0);\n\t\t\treturn;\n\t\t}\n\t\tneedA[n - 1] = need.intValue();\n\t\tint[] cnt = new int[] { 1 };\n\t\tint[] sum = new int[] { 1 };\n\t\tfor (int i = 0; i < n;) {\n\t\t\tint j = i;\n\t\t\tint sumBI = 1 + b[i];\n\t\t\twhile (j != n - 1 && a[j] == 1) {\n\t\t\t\tj++;\n\t\t\t\tsumBI += b[j];\n\t\t\t}\n\t\t\tint div = i == 0 ? 1 : a[i - 1];\n\t\t\tsumBI += (1 + sum.length / div);\n\t\t\tint[] nextSum = new int[sumBI];\n\t\t\tint[] nextCnt = new int[sumBI];\n\t\t\tint beforeNeed = i == 0 ? 0 : needA[i - 1];\n\t\t\tint it = 0;\n\t\t\tfor (int k = beforeNeed; k < cnt.length; k += div) {\n\t\t\t\tnextCnt[it++] = cnt[k];\n\t\t\t}\n\t\t\tupdateSum(nextCnt, nextSum);\n\t\t\tfor (int k = i; k <= j; k++) {\n\t\t\t\tint how = b[k];\n\t\t\t\tfor (int l = 0; l < nextCnt.length; l++) {\n\t\t\t\t\tnextCnt[l] = nextSum[l];\n\t\t\t\t\tif (l - how - 1 >= 0) {\n\t\t\t\t\t\tnextCnt[l] -= nextSum[l - how - 1];\n\t\t\t\t\t\tif (nextCnt[l] < 0) {\n\t\t\t\t\t\t\tnextCnt[l] += mod;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tupdateSum(nextCnt, nextSum);\n\t\t\t}\n\t\t\ti = j + 1;\n\t\t\tsum = nextSum;\n\t\t\tcnt = nextCnt;\n\t\t}\n\t\tif (needA[n - 1] >= cnt.length) {\n\t\t\tout.println(0);\n\t\t} else {\n\t\t\tout.println(cnt[needA[n - 1]]);\n\t\t}\n\t}\n\n\tvoid updateSum(int[] val, int[] sum) {\n\t\tsum[0] = val[0];\n\t\tfor (int i = 1; i < sum.length; i++) {\n\t\t\tsum[i] = sum[i - 1] + val[i];\n\t\t\tif (sum[i] >= mod) {\n\t\t\t\tsum[i] -= mod;\n\t\t\t}\n\t\t}\n\t}\n\n\tvoid run() {\n\t\ttry {\n\t\t\tin = new FastScanner(new File(\"object.in\"));\n\t\t\tout = new PrintWriter(new File(\"object.out\"));\n\n\t\t\tsolve();\n\n\t\t\tout.close();\n\t\t} catch (FileNotFoundException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\n\tvoid runIO() {\n\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\n\tpublic static void main(String[] args) {\n\t\tnew E().runIO();\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "3d68db2e3c6505a47a798671b7983ab6", "src_uid": "71b23bc529ee1484d9dcea84def45d53", "difficulty": 3200.0} {"lang": "Java 8", "source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.Locale;\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\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n static class Query {\n int kind;\n Vertex v;\n Vertex u;\n int t;\n }\n\n static class Vertex {\n long s;\n long subtreeSize;\n boolean hasInterestingInSubtree = false;\n long subtreeAnswer;\n long childSquareSum;\n Vertex parent;\n Vertex firstChild;\n Vertex nextSibling;\n Vertex interestingParent;\n Vertex firstInterestingChild;\n Vertex nextInterestingSibling;\n long multiplierForIntermediates;\n long constantForIntermediates;\n long intermediatesSize;\n long boringChildrenSize;\n long boringChildrenSquareSum;\n long boringChildrenAnswer;\n boolean interesting;\n\n void propagateInteresting() {\n Vertex v = firstChild;\n int numIntChild = 0;\n while (v != null) {\n v.propagateInteresting();\n if (v.hasInterestingInSubtree) ++numIntChild;\n v = v.nextSibling;\n }\n if (numIntChild >= 2) interesting = true;\n if (interesting || numIntChild >= 1) hasInterestingInSubtree = true;\n }\n\n void init() {\n subtreeSize = 1;\n subtreeAnswer = 0;\n childSquareSum = 0;\n boringChildrenSize = 0;\n boringChildrenAnswer = 0;\n boringChildrenSquareSum = 0;\n Vertex v = firstChild;\n while (v != null) {\n v.init();\n subtreeSize += v.subtreeSize;\n subtreeAnswer += v.subtreeAnswer;\n childSquareSum += v.subtreeSize * (long) v.subtreeSize;\n if (interesting && !v.hasInterestingInSubtree) {\n boringChildrenSize += v.subtreeSize;\n boringChildrenAnswer += v.subtreeAnswer;\n boringChildrenSquareSum += v.subtreeSize * (long) v.subtreeSize;\n }\n v = v.nextSibling;\n }\n subtreeAnswer += (subtreeSize * (long) subtreeSize - childSquareSum) * s;\n }\n\n public void interestingInit() {\n subtreeSize = 1 + boringChildrenSize;\n subtreeAnswer = boringChildrenAnswer;\n childSquareSum = boringChildrenSquareSum;\n Vertex v = firstInterestingChild;\n while (v != null) {\n v.interestingInit();\n long childSize = v.subtreeSize + v.intermediatesSize;\n subtreeSize += childSize;\n subtreeAnswer += v.subtreeAnswer;\n subtreeAnswer += v.multiplierForIntermediates * v.subtreeSize + v.constantForIntermediates;\n childSquareSum += childSize * (long) childSize;\n v = v.nextInterestingSibling;\n }\n subtreeAnswer += (subtreeSize * (long) subtreeSize - childSquareSum) * s;\n }\n\n public void initIntermediates() {\n Vertex tmp = this;\n intermediatesSize = 0;\n multiplierForIntermediates = 0;\n constantForIntermediates = 0;\n while (!tmp.parent.interesting) {\n long curExtra = tmp.parent.subtreeSize - tmp.subtreeSize;\n intermediatesSize += curExtra;\n multiplierForIntermediates += 2 * curExtra * (long) tmp.parent.s;\n constantForIntermediates += tmp.parent.subtreeAnswer - tmp.subtreeAnswer - 2 * subtreeSize * (long) (tmp.parent.subtreeSize - tmp.subtreeSize) * tmp.parent.s;\n tmp = tmp.parent;\n }\n interestingParent = tmp.parent;\n }\n }\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n /*char[] buf = new char[100000];\n int size;\n try {\n size = in.reader.read(buf);\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n if (size == buf.length) throw new RuntimeException();\n String input = new String(buf, 0, size);\n StringWriter sw1 = new StringWriter();\n PrintWriter pw1 = new PrintWriter(sw1);\n doit(new InputReader(new StringInputStream(input)), pw1, 1);\n pw1.close();\n StringWriter sw2 = new StringWriter();\n PrintWriter pw2 = new PrintWriter(sw2);\n doit(new InputReader(new StringInputStream(input)), pw2, 500);\n pw2.close();\n String s1 = sw1.toString();\n String s2 = sw2.toString();\n if (!s1.equals(s2)) throw new RuntimeException();\n out.print(s1);*/\n doit(in, out, 500);\n }\n\n private void doit(InputReader in, PrintWriter out, int BUBEN) {\n Locale.setDefault(Locale.US);\n int n = in.nextInt();\n Vertex[] vs = new Vertex[n];\n for (int i = 0; i < n; ++i) vs[i] = new Vertex();\n for (int i = 1; i < n; ++i) {\n vs[i].parent = vs[in.nextInt() - 1];\n }\n for (int i = 0; i < n; ++i) {\n vs[i].s = in.nextInt();\n }\n Vertex root = vs[0];\n int numQueries = in.nextInt();\n Query[] queries = new Query[numQueries];\n for (int i = 0; i < numQueries; ++i) {\n Query query = new Query();\n String ss = in.next();\n if (ss.equals(\"P\")) query.kind = 1; else if (ss.equals(\"V\")) query.kind = 2; else throw new RuntimeException();\n if (query.kind == 1) {\n query.v = vs[in.nextInt() - 1];\n query.u = vs[in.nextInt() - 1];\n } else {\n query.v = vs[in.nextInt() - 1];\n query.t = in.nextInt();\n }\n queries[i] = query;\n }\n double mult = 1.0 / n / n;\n Vertex[] inters = new Vertex[n];\n for (int blockFirst = 0; blockFirst < numQueries; blockFirst += BUBEN) {\n int blockLast = Math.min(numQueries, blockFirst + BUBEN);\n for (Vertex vv : vs) {\n vv.interesting = false;\n vv.hasInterestingInSubtree = false;\n }\n root.interesting = true;\n for (int qid = blockFirst; qid < blockLast; ++qid) {\n Query query = queries[qid];\n if (query.kind == 1) {\n query.v.interesting = true;\n if (query.v.parent != null) query.v.parent.interesting = true;\n query.u.interesting = true;\n if (query.u.parent != null) query.u.parent.interesting = true;\n } else {\n query.v.interesting = true;\n }\n }\n for (Vertex vv : vs) {\n vv.firstChild = null;\n vv.nextSibling = null;\n }\n for (Vertex vv : vs) {\n if (vv.parent != null) {\n vv.nextSibling = vv.parent.firstChild;\n vv.parent.firstChild = vv;\n }\n }\n root.propagateInteresting();\n int ninters = 0;\n for (Vertex vv : vs) if (vv.interesting) {\n inters[ninters++] = vv;\n }\n root.init();\n for (int i = 0; i < ninters; ++i) {\n Vertex vv = inters[i];\n if (vv.parent != null) vv.initIntermediates();\n }\n if (blockFirst == 0) {\n out.println(String.format(\"%.12f\", root.subtreeAnswer * mult));\n }\n for (int qid = blockFirst; qid < blockLast; ++qid) {\n Query query = queries[qid];\n if (query.kind == 1) {\n Vertex tmp = query.u;\n while (tmp != null && tmp != query.v) tmp = tmp.interestingParent;\n if (tmp == null) {\n query.v.parent = query.u;\n query.v.interestingParent = query.u;\n } else {\n query.u.parent = query.v;\n query.u.interestingParent = query.v;\n }\n } else {\n query.v.s = query.t;\n }\n for (int i = 0; i < ninters; ++i) {\n Vertex vv = inters[i];\n vv.firstInterestingChild = null;\n vv.nextInterestingSibling = null;\n }\n for (int i = 0; i < ninters; ++i) {\n Vertex vv = inters[i];\n if (vv.interestingParent != null) {\n vv.nextInterestingSibling = vv.interestingParent.firstInterestingChild;\n vv.interestingParent.firstInterestingChild = vv;\n }\n }\n root.interestingInit();\n out.println(String.format(\"%.12f\", root.subtreeAnswer * mult));\n }\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), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n}\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ed9f6687e7e0a745f23f4e4768c3612d", "src_uid": "013df41c0042f752a995bdcf16b28c7e", "difficulty": 3200.0} {"lang": "Java 17", "source_code": "import java.util.*;\r\nimport java.util.function.*;\r\nimport java.io.*;\r\n\r\n// you can compare with output.txt and expected out\r\npublic class RoundEdu132F {\t\r\n\tMyPrintWriter out;\r\n\tMyScanner in;\r\n\t\r\n//\tfinal static long FIXED_RANDOM;\r\n//\tstatic {\r\n//\t\tFIXED_RANDOM = System.currentTimeMillis();\r\n//\t}\r\n\tfinal static String IMPOSSIBLE = \"IMPOSSIBLE\";\r\n\tfinal static String POSSIBLE = \"POSSIBLE\";\r\n\tfinal static String YES = \"YES\";\r\n\tfinal static String NO = \"NO\";\r\n\t\r\n private void initIO(boolean isFileIO) {\r\n if (System.getProperty(\"ONLINE_JUDGE\") == null && isFileIO) {\r\n \ttry{\r\n\t in = new MyScanner(new FileInputStream(\"input.txt\"));\r\n\t out = new MyPrintWriter(new FileOutputStream(\"output.txt\"));\r\n \t}\r\n \tcatch(FileNotFoundException e){\r\n \t\te.printStackTrace();\r\n \t}\r\n }\r\n else{\r\n \t\tin = new MyScanner(System.in);\r\n \t out = new MyPrintWriter(new BufferedOutputStream(System.out));\r\n }\r\n }\r\n\t\r\n\tpublic static void main(String[] args){\r\n//\t\tScanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\r\n\t\t\r\n\t\tRoundEdu132F sol = new RoundEdu132F();\r\n\t\tsol.run();\r\n }\r\n\t\r\n\tprivate void run() {\r\n\t\tboolean isDebug = false;\r\n\t\tboolean isFileIO = true;\r\n\t\tboolean hasMultipleTests = false;\r\n\t\t\r\n\t\tinitIO(isFileIO);\r\n\t\r\n\t\tint t = hasMultipleTests? in.nextInt() : 1;\r\n\t \r\n\t for (int i = 1; i <= t; ++i) {\r\n\t \tif(isDebug){\r\n\t\t \tout.printf(\"Test %d\\n\", i);\r\n\t \t}\r\n\r\n\t \tgetInput();\r\n\r\n\t \tans = solve();\r\n\t \t\r\n\t \tprintOutput();\r\n\t }\r\n\t \r\n\t in.close();\r\n\t out.close();\r\n\t}\r\n\t\r\n\tint n, k, f;\r\n\tvoid getInput() {\r\n\t\tn = in.nextInt(); \r\n\t\tk = in.nextInt();\r\n\t\tf = in.nextInt();\r\n\t}\r\n\t\r\n\tvoid printOutput() {\r\n\t\tout.printlnAns(ans);\r\n\t}\r\n\t\r\n\tstatic final long MOD = 998244353;\r\n\tint ans;\r\n\tint solve(){\r\n\t\tlong ans = 0;\r\n\t\t\r\n\t\t// for each binary string s,\r\n\t\t// consider binary strings t of length n, where s is a prefix of t\r\n\t\t// we can have <= c_s among t\r\n\t\t\r\n\t\t// it's a full binary tree\r\n\t\t// where each vertex contains # of records in its subtree\r\n\t\t// and all records are at depth n\r\n\t\t\r\n\t\t// from each leaf, go up again, update each vertex to min(val, val(child1) + val(child2))\r\n\t\t// then the val(root) must be exactly f\r\n\t\t// where root is null string\r\n\r\n\t\t// the problem in this counting is we would have to use inclusion-exclusion due to duplicate cases\r\n\t\t// so we choose vertices representing disjoint subtrees\r\n\t\t// whose union can represent the whole tree\r\n\t\t// and whose sum is exactly f\r\n\t\t\r\n\t\t// for vertices under the subtrees, we can freely choose val\r\n\t\t// so that sum of siblings in each subtree >= val of root of subtree \r\n\t\t// for vertices above the subtrees, we can freely choose val between sum and k\r\n\r\n\t\t\r\n\t\t// so another approach:\r\n\t\t// for each vertex v of depth h\r\n\t\t// find # of ways to make sum exactly x\r\n\t\t// case 1: val(v) = x\r\n\t\t// add up ways(l, y)*ways(r, z) where y+z >= x\r\n\t\t// case 2: val(v) >= x+1\r\n\t\t// add up ways(l, y)*ways(r, z) where y+z = x\r\n\t\t\r\n\t\t// 2 1 1\r\n\t\t// case 1: c_0 = 1, c_1 = 0\r\n\t\t// 00 01 10 11\r\n\t\t// 1 0 0/1 0/1\r\n\t\t// 0 1 0/1 0/1\r\n\t\t// 1 1 0/1 0/1\r\n\t\t// -> 12\r\n\t\t\r\n\t\t// case 2: c_0 = 0, c_1 = 1\r\n\t\t// -> 12\r\n\t\t\r\n\t\t// case 3: c_0 = 1, c_1 = 1\r\n\t\t// 1 0 0 0\r\n\t\t// 0 1 0 0\r\n\t\t// 1 1 0 0\r\n\t\t// 0 0 1 0\r\n\t\t// 0 0 0 1\r\n\t\t// 0 0 1 1\r\n\t\t// -> 6\r\n\t\t\r\n\t\t// subtree_0 = 1 -> 3\r\n\t\t// c_0 = 1 -> 1 0, 0 1, 1 1\r\n\t\t\r\n\t\t// subtree_0 = 0 -> 5\r\n\t\t// c_0 = 0 -> 0/1, 0/1 -> 4\r\n\t\t// c_0 = 1 -> 0, 0 -> 1\r\n\t\t// 3*5 + 3*5 = 30\r\n\t\t\r\n\t\t// subtree_l = 0 -> 1 \r\n\t\t// subtree_l = 1 -> 1\r\n\t\t\r\n\t\t// long[] ways = new long[f+2];\r\n\t\tint len = 1;\r\n\t\twhile (len < f+2 + f+2) \r\n\t len <<= 1;\r\n\t\tlong[] ways = new long[len];\r\n\t\tlong[] suffix = new long[f+2];\r\n\t\t\r\n\t\tfor(int i=0; i<=k && i<=f; i++)\r\n\t\t\tways[i] = 1;\r\n\t\tways[f+1] = Math.max(0, k-f);\r\n\t\t\r\n\t\tfor(int i=0; i=f+1; j--)\r\n\t\t\t\t\t\tval += ways[j];\r\n\t\t\t\t\tval %= MOD;\r\n\t\t\t\t\tsuffix[f+1] = val;\r\n\t\t\t\t}\r\n\t\t\t\tfor(int j=f; j>=0; j--){\r\n\t\t\t\t\tlong val = suffix[j+1] + ways[j];\r\n\t\t\t\t\tval = val>=MOD? val-MOD: val;\r\n\t\t\t\t\tsuffix[j] = val;\r\n\t\t\t\t}\r\n\t\t\t\r\n\t\t\t\tfor(int j=0; j <= k && j<=f; j++) {\r\n\t\t\t\t\tlong val = suffix[j]; // c_curr = j\r\n\t\t\t\t\tval += ways[j]*(k-j); // j+1 ~ k\r\n\t\t\t\t\tval %= MOD;\r\n\t\t\t\t\tways[j] = val;\r\n\t\t\t\t}\r\n\t\t\t\t{\r\n\t\t\t\t\tlong val = suffix[f+1]*Math.max(0, k-f);\r\n\t\t\t\t\tval %= MOD;\r\n\t\t\t\t\tways[f+1] = val;\r\n\t\t\t\t}\r\n\t\t\t\tArrays.fill(ways, f+2, ways.length, 0);\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tfor(int j=0; j<=f; j++)\r\n\t\t\t\t\tans += ways[j]*ways[f-j] % MOD;\r\n\t\t\t\tans %= MOD;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\treturn (int)ans;\r\n\t}\r\n\t\r\n\tstatic long pow(int a, int k, long p) {\r\n\t\tlong m = k;\r\n\t\tlong ans = 1;\r\n\r\n\t\t// curr = k^(2^i)\r\n\t\tlong curr = a;\r\n\r\n\t\t// k^(2x+1) = (k^x)^2 * k\r\n\t\twhile(m > 0) {\r\n\t\t\tif( (m&1) == 1 ) {\r\n\t\t\t\tans *= curr;\r\n\t\t\t\tans %= p;\r\n\t\t\t}\r\n\t\t\tm >>= 1;\r\n\t\t\tcurr *= curr;\r\n\t\t\tcurr %= p;\r\n\t\t}\r\n\t\treturn ans;\t\t\r\n\t}\r\n\t\r\n\t// computes a^(p-2)\r\n\tstatic long inverse(int a, long p) {\r\n\t\treturn pow(a, (int)(p-2), p);\r\n\t}\r\n\t\r\n\t// static final long MOD = 998_244_353; // = 1 + 7*17*2^23\r\n\t// primitive root is 3, i.e., the order of 3 is MOD-1\r\n\t// we have to find the 1<<23-th root\r\n\tstatic final int ROOT = (int) pow(3, 7*17, MOD);\r\n\tstatic final int ROOT_INV = (int) pow(ROOT, (int)MOD - 2, MOD);\r\n\tstatic final int ORDER = 1 << 23;\r\n\r\n\tstatic void swap(long[] a, int i, int j) {\r\n\t\tlong temp = a[i];\r\n\t\ta[i] = a[j];\r\n\t\ta[j] = temp;\r\n\t}\r\n\tstatic void fft(long[] a, boolean isInvertedFFT) {\r\n\t int n = a.length;\r\n\r\n\t for (int i = 1, j = 0; i < n; i++) {\r\n\t int bit = n >> 1;\r\n\t for (; (j & bit) > 0; bit >>= 1)\r\n\t j ^= bit;\r\n\t j ^= bit;\r\n\r\n\t if (i < j) {\r\n\t \tswap(a, i, j);\r\n\t }\r\n\t }\r\n\r\n\t for (int len = 2; len <= n; len <<= 1) {\r\n\t long wlen = isInvertedFFT ? ROOT_INV : ROOT;\r\n\t for (int i = len; i < ORDER; i <<= 1)\r\n\t wlen = wlen * wlen % MOD;\r\n\r\n\t for (int i = 0; i < n; i += len) {\r\n\t \tlong w = 1;\r\n\t for (int j = 0; j < len / 2; j++) {\r\n\t long u = a[i+j];\r\n\t long v = a[i+j+len/2] * w % MOD;\r\n\t a[i+j] = u + v < MOD ? u + v : u + v - MOD;\r\n\t a[i+j+len/2] = u - v >= 0 ? u - v : u - v + MOD;\r\n\t w = w * wlen % MOD;\r\n\t }\r\n\t }\r\n\t }\r\n\r\n\t if (isInvertedFFT) {\r\n\t long inv = inverse(n, MOD);\r\n\t for(int i=0; i 0){\r\n\t\t\t\tprint(arr[0]);\r\n\t\t\t\tfor(int i=1; i 0){\r\n\t\t\t\tprint(arr[0]);\r\n\t\t\t\tfor(int i=1; i void printAns(ArrayList arr){\r\n\t\t\tif(arr != null && arr.size() > 0){\r\n\t\t\t\tprint(arr.get(0));\r\n\t\t\t\tfor(int i=1; i void printlnAns(ArrayList arr){\r\n\t\t\tprintAns(arr);\r\n\t\t\tprintln();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printAns(int[] arr, int add){\r\n\t\t\tif(arr != null && arr.length > 0){\r\n\t\t\t\tprint(arr[0]+add);\r\n\t\t\t\tfor(int i=1; i arr, int add) {\r\n\t\t\tif(arr != null && arr.size() > 0){\r\n\t\t\t\tprint(arr.get(0)+add);\r\n\t\t\t\tfor(int i=1; i arr, int add){\r\n\t\t\tprintAns(arr, add);\r\n\t\t\tprintln();\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printlnAnsSplit(long[] arr, int split){\r\n\t\t\tif(arr != null){\r\n\t\t\t\tfor(int i=0; i void printlnAnsSplit(ArrayList arr, int split){\r\n\t\t\tif(arr != null && !arr.isEmpty()){\r\n\t\t\t\tfor(int i=0; i\" + e[i][1] + \";\");\r\n\t\t}\r\n\t\tout2.println(\"}\");\r\n\t\tout2.close();\r\n\t}\r\n\t\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "e0ae9643b377646d61c20093482daa25", "src_uid": "4b8161259545e44c7d1046be2e4fe014", "difficulty": 2500.0} {"lang": "Java 11", "source_code": "// practice with rainboy\n// https://codeforces.com/blog/entry/58519\nimport java.io.*;\nimport java.util.*;\n\npublic class CF954H extends PrintWriter {\n\tCF954H() { super(System.out, true); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF954H o = new CF954H(); o.main(); o.flush();\n\t}\n\n\tstatic final int MD = 1000000007, INV2 = 500000004;\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tint[] aa = new int[n - 1];\n\t\tfor (int h = 0; h < n - 1; h++)\n\t\t\taa[h] = sc.nextInt();\n\t\tint[][] pp = new int[n][n * 2];\n\t\tfor (int h = 0; h < n; h++)\n\t\t\tpp[h][0] = 1;\n\t\tfor (int k = 1; k < n; k++)\n\t\t\tfor (int h = n - k - 1; h >= 0; h--)\n\t\t\t\tpp[h][k] = (int) ((long) aa[h] * pp[h + 1][k - 1] % MD);\n\t\tint[][] qq = new int[n][n * 2];\n\t\tfor (int h = 0; h < n; h++)\n\t\t\tqq[h][0] = 1;\n\t\tfor (int k = 1; k < n * 2; k++)\n\t\t\tfor (int h = 1; h < n; h++) {\n\t\t\t\tlong x = qq[h - 1][k - 1];\n\t\t\t\tif (k >= 2)\n\t\t\t\t\tx = (x + (long) (aa[h - 1] - 1) * pp[h][k - 2]) % MD;\n\t\t\t\tqq[h][k] = (int) x;\n\t\t\t}\n\t\tfor (int k = 1; k < n * 2 - 1; k++) {\n\t\t\tlong x = 0;\n\t\t\tfor (int h = 0; h < n; h++)\n\t\t\t\tx = (x + (long) pp[0][h] * (pp[h][k] + qq[h][k])) % MD;\n\t\t\tprint(x * INV2 % MD + \" \");\n\t\t}\n\t\tprintln();\n\t}\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "ba0b119412176623ffbb4320c10589da", "src_uid": "3b86dfd0d077bc857ae3de70f026a409", "difficulty": 2500.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n public static void main(String[] args) throws IOException {\n\n Scanner sc = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n\n int n = sc .nextInt();\n long[] a = new long[n];\n for(int i = 0; i < n; ++i)\n a[i] = sc.nextLong();\n ArrayList b = new ArrayList<>();\n ArrayList c = new ArrayList<>();\n ArrayList d = new ArrayList<>();\n int idx = 0;\n long curPower = 1;\n for(long x: a)\n if (x == 1) {\n b.add(1l);\n d.add(1);\n } else if ((x & x - 1) == 0) {\n if (x != curPower) {\n curPower = x;\n idx = 0;\n }\n if (idx < b.size()) {\n b.set(idx, x);\n d.set(idx, d.get(idx) + 1);\n ++idx;\n }\n else\n c.add(x);\n } else {\n c.add(x);\n }\n int open = b.size();\n boolean possible = b.size() >= c.size();\n if(possible) for(int i = c.size() - 1, j = 0; i >= 0; --i, ++j) {\n if(c.get(i) <= 2 * b.get(j)) --open;\n else {\n possible = false;\n break;\n }\n }\n ArrayList ans = new ArrayList<>();\n if (possible) {\n ans.add(b.size());\n int free = 0;\n for(int i = b.size() - 1; i >= 0; --i) {\n open--;\n free += d.get(i);\n if (open >= free)\n ans.add(i);\n else\n break;\n }\n Collections.reverse(ans);\n for(int x: ans)\n out.print(x + \" \");\n } else {\n out.println(-1);\n }\n out.close();\n }\n\n static class Scanner\n {\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(InputStream s){\tbr = new BufferedReader(new InputStreamReader(s));}\n\n public String next() throws IOException\n {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n public int nextInt() throws IOException {return Integer.parseInt(next());}\n\n public long nextLong() throws IOException {return Long.parseLong(next());}\n\n public String nextLine() throws IOException {return br.readLine();}\n\n public boolean ready() throws IOException {return br.ready();}\n\n\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "28d9c34875257b2c3d77cdd87a588ef4", "src_uid": "fc29e8c1a9117c1dd307131d852b6088", "difficulty": 2200.0} {"lang": "Java 8", "source_code": "//package educational.round68;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n \npublic class G3 {\n\tInputStream is;\n\tPrintWriter out;\n//\tString INPUT = \"42\";\n\tString INPUT = \"\";\n\t\n\tpublic static void trnz(long... o)\n\t{\n\t\tfor(int i = 0;i < o.length;i++)if(o[i] != 0)System.out.print(i+\":\"+o[i]+\" \");\n\t\tSystem.out.println();\n\t}\n \n\t\n\tvoid solve()\n\t{\n\t\tBigInteger n = new BigInteger(ns());\n\t\tlong ans = 0;\n\t\tfor(int i = 1;i <= 9;i++){\n\t\t\tfor(int j = 1;j <= i;j++){\n\t\t\t\tif(gcd(i, j) == 1){\n\t\t\t\t\tif(i == 1){\n\t\t\t\t\t\tans += n.mod(BigInteger.valueOf(998244353L)).longValue();\n\t\t\t\t\t}else{\n\t\t\t\t\t\tlong lans = count(n, i, j);\n\t\t\t\t\t\tif(i != j){\n\t\t\t\t\t\t\tans += lans*2;\n\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\tans += lans;\n\t\t\t\t\t\t}\n//\t\t\t\t\t\tif(lans > 0)tr(i, j, lans, ans);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(ans % 998244353);\n\t}\n\t\n\tlong count(BigInteger N, int u, int v)\n\t{\n\t\tchar[] s = (\"0\" + N.divide(BigInteger.valueOf(u)).add(BigInteger.ONE).toString()).toCharArray();\n\t\t\n\t\tint n = s.length;\n\t\t// u:2 v:1\n\t\t// u\u500d\u3057\u305f\u3068\u304d\u306bt*u\u3092\u542b\u3093\u3067\u3044\u308b\u304b\n\t\t// v\u500d\u3057\u305f\u3068\u304d\u306bt*v\u3092\u542b\u3093\u3067\u3044\u308b\u304b\n\t\tint w = 9/u;\n\t\tlong[][][][] dp = new long[1<= 0;i--){\n\t\t\tlong[][][][] ndp = new long[1<= mod)ndp[nj][nk][nl][nm] -= mod;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tfor(int j = 0;j < 1<= mod)nep[nj][nk][nl][nm] -= mod;\n\t\t\t\t\t\t\t\tif(d < s[i]-'0'){\n\t\t\t\t\t\t\t\t\tndp[nj][nk][nl][nm] += ep[j][k][l][m];\n\t\t\t\t\t\t\t\t\tif(ndp[nj][nk][nl][nm] >= mod)ndp[nj][nk][nl][nm] -= mod;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tdp = ndp;\n\t\t\tep = nep;\n\t\t}\n\t\t\n\t\tlong ret = 0;\n\t\tfor(int i = 0;i < 1< 0) {\n\t\t\tint c = a;\n\t\t\ta = b;\n\t\t\tb = c % b;\n\t\t}\n\t\treturn a;\n\t}\n\t\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception { new G3().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}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "440f51d1f1345d5f38299428033d0b05", "src_uid": "b6f2061e2ca174c2385bf4520d232aaf", "difficulty": 2700.0} {"lang": "Java 6", "source_code": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.Iterator;\nimport java.util.LinkedList;\nimport java.util.Locale;\nimport java.util.Queue;\nimport java.util.Random;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\npublic class Solution implements Runnable {\n\n\tpublic static void main(String[] args) {\n\t\t(new Thread(new Solution())).start();\n\t}\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st;\n\n\tString nextToken() throws IOException {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\tString r = in.readLine();\n\t\t\tif (r == null) return null;\n\t\t\tst = new StringTokenizer(r);\n\t\t}\n\t\treturn st.nextToken();\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\t\n\tclass Edge {\n\t\tint b, e, n;\n\t\tEdge pr, nt, r;\n\t\tEdge(int bb, int ee, int nn, Edge rr, Edge tt) {\n\t\t\tb = bb; e = ee; n = nn; pr = rr; nt = tt;\n\t\t\tr = null;\n\t\t}\n\t}\n\t\n\tEdge[] v;\n\tEdge cycleEdge;\n\tint[] ss;\n\t\n\tvoid addedge(int b, int e, int n) {\n\t\tEdge r = new Edge(b, e, n, null, v[b]);\n\t\tif (v[b] == null) v[b] = r; else v[b] = v[b].pr = r;\n\t\tr = new Edge(e, b, n, null, v[e]);\n\t\tif (v[e] == null) v[e] = r; else v[e] = v[e].pr = r; \n\t\tv[b].r = v[e]; v[e].r = v[b];\n\t\tif (get(b) != get(e)) uni(b, e); else cycleEdge = v[e];\n\t\tss[b]++; ss[e]++;\n\t}\n\t\n\tint[] dsu;\n\tint[] rank;\n\tQueue cc, cp, anss;\n\n\tint get(int q) {\n\t\tif (dsu[q] != q) return dsu[q] = get(dsu[q]); else return q;\n\t}\n\t\n\tvoid uni(int a, int b) {\n\t\ta = get(a); b = get(b);\n\t\tif (rank[a] == rank[b]) rank[a]++;\n\t\tif (rank[a] > rank[b]) dsu[b] = a; else dsu[a] = b;\n\t}\n\t\n\tint[] w;\n\tboolean[] ww;\n\t\n\tvoid ansprint() {\n\t\tout.print(anss.size() + \" \");\n\t\twhile (!anss.isEmpty()) out.print(anss.poll() + \" \");\n\t\tout.println();\n\t}\n\t\n\tvoid changeEdge(Edge r, int b, int e) {\n\t\tif (r.b != b) changeEdge(r.r, b, e); else {\n\t\t\tansprint();\n\t\t\tout.println(r.n + \" \" + b + \" \" + e);\n\t\t\tr.e = e;\n\t\t\tif (r.r.pr == null) {\n\t\t\t\tv[r.r.b] = r.r.nt; \n\t\t\t} else {\n\t\t\t\tr.r.pr.nt = r.r.nt;\n\t\t\t}\n\t\t\tif (r.r.nt != null) r.r.nt.pr = r.r.pr;\n\t\t\tr.r.b = b;\n\t\t\tr.r.nt = v[b];\n\t\t\tr.r.pr = null;\n\t\t\tv[b] = v[b].pr = r.r;\n\t\t}\n\t}\n\t\n\tvoid dfs(int q, int rr) {\n\t\tw[q] = 1;\n\t\tww[get(q)] = true;\n\t\tanss.add(q);\n\t\tQueue obr = new LinkedList();\n\t\tfor (Edge r = v[q]; r != null; r = r.nt) {\n\t\t\tif (r.n != rr) {\n\t\t\t\tif (w[r.e] == 0) {\n\t\t\t\t\tdfs(r.e, r.n);\n\t\t\t\t\tanss.add(q);\n\t\t\t\t}\n\t\t\t\tobr.add(r);\n\t\t\t}\n\t\t}\n\t\twhile (!obr.isEmpty()) {\n\t\t\tint qq = -1;\n\t\t\twhile (!cc.isEmpty() && ww[cc.peek()]) cc.poll();\n\t\t\tif (cc.isEmpty()) {\n\t\t\t\twhile (!cp.isEmpty() && ww[cp.peek()]) cp.poll();\n\t\t\t\tif (!cp.isEmpty()) qq = cp.poll();\n\t\t\t} else qq = cc.poll();\n\t\t\tif (qq == -1) break;\n\t\t\tEdge r = obr.poll();\n\t\t\tchangeEdge(r, q, qq);\n\t\t\tdfs(qq, r.n);\n\t\t\tanss.add(q);\n\t\t}\n\t\tw[q] = 2;\n\t}\n\t\n\tvoid solve() throws Exception {\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\t\tv = new Edge[n + 1];\n\t\tdsu = new int[n + 1];\n\t\trank = new int[n + 1];\n\t\tss = new int[n + 1];\n\t\tfor (int i = 1; i <= n; i++) dsu[i] = i;\n\t\tfor (int i = 1; i <= m; i++) {\n\t\t\taddedge(nextInt(), nextInt(), i);\n\t\t}\n\t\tcc = new LinkedList();\n\t\tcp = new LinkedList();\n\t\tint cs = 0;\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\tif (dsu[i] == i && i != get(1)) {\n\t\t\t\tcs++;\n\t\t\t\tif (rank[i] == 0) cp.add(i); else cc.add(i);\n\t\t\t}\n\t\tif (cs > m || cs == m && cycleEdge == null && ss[1] == 0) {\n\t\t\tout.println(\"NO\");\n\t\t} else {\n\t\t\tout.println(\"YES\");\n\t\t\tww = new boolean[n + 1];\n\t\t\tw = new int[n + 1];\n\t\t\tanss = new LinkedList();\n\t\t\tif (ss[1] == 0) {\n\t\t\t\tanss.add(1);\n\t\t\t\tif (cycleEdge != null) {\n\t\t\t\t\tchangeEdge(cycleEdge, 1, cycleEdge.e);\n\t\t\t\t} else {\n\t\t\t\t\tint j = 2;\n\t\t\t\t\twhile (ss[j] != 1) j++;\n\t\t\t\t\tchangeEdge(v[j], 1, v[j].e);\n\t\t\t\t\tcp.add(j);\n\t\t\t\t\tcs++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tout.println(cs);\n\t\t\tdfs(1, 0);\n\t\t\tansprint();\n\t\t}\n\t}\n\t\n\tpublic void run() {\n\t\tLocale.setDefault(Locale.UK);\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t} finally {\n\t\t\tout.flush();\n\t\t}\n\t}\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "5d8517132df72ae5825a73cfda467df8", "src_uid": "35a3513c8fe730a64f30c5daec27df05", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class F946{\n\n long[] fibpow;\n char[] chs;\n long mod = 1000000007L;\n long modpow = mod-1L;\n long[][][] memo;\n\n long pow(long m, long n){\n long res = 1;\n while(n > 0){\n if(n % 2 == 1)res = (res*m)%mod;\n m = (m*m)%mod;\n n = n/2;\n }\n return res;\n }\n\n\n private void solve() throws Exception {\n int n = nextInt();\n int x = nextInt();\n chs = nextToken().toCharArray();\n memo = new long[n][n][x+1];\n for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) Arrays.fill(memo[i][j], -1);\n fibpow = new long[x+1];\n if(x > 0) fibpow[1] = 1L;\n for(int i = 2; i <= x; i++) fibpow[i] = (fibpow[i-1]+ fibpow[i-2])%modpow;\n for(int i = 0; i <= x; i++) fibpow[i] = pow(2, fibpow[i]);\n out.println(doit(0,n-1,x));\n }\n\n long doit(int i, int j, int x) {\n if (x < 2 && i == j && chs[i]-'0' == x) return 1L;\n else if (x < 2 && i == j && chs[i]-'0' != x) return 0L;\n else if(x < 2 && i < j) return 0L;\n else if(memo[i][j][x] < 0){\n long res = 0L;\n res = (res + ((i==0?fibpow[x]:(1L)) * doit(i,j, x-2))%mod)%mod;\n for(int t = i; t < j; t++) res = (res + (doit(i,t,x-1) * doit(t+1,j, x-2))%mod)%mod;\n res = (res + (doit(i,j,x-1) * (j==chs.length-1? fibpow[x-1]:(1L)))%mod)%mod;\n memo[i][j][x] = res;\n }\n return memo[i][j][x];\n }\n\n\n public static void main(String[] args) {\n (new F946()).run();\n }\n\n private BufferedReader in;\n private PrintWriter out;\n private StringTokenizer tokenizer;\n\n public void run() {\n try {\n in = new BufferedReader(new InputStreamReader(System.in));\n tokenizer = null;\n out = new PrintWriter(System.out);\n solve();\n in.close();\n out.close();\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(1);\n }\n }\n\n private int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n private long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n private float nextFloat() throws IOException {\n return Float.parseFloat(nextToken());\n }\n\n private String nextLine() throws IOException {\n return new String(in.readLine());\n }\n\n private String nextToken() throws IOException {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(in.readLine());\n }\n return tokenizer.nextToken();\n }\n\n\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "a2ede288837730755d6da976969674e1", "src_uid": "52c6aa73ff4460799402c646c6263630", "difficulty": 2400.0} {"lang": "Java 8", "source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n/*\n4\n1 2 3 4 \n2 1 4 3 \n1 2 3 4 \n3 1 4 2 \n>> 3\n\n\n1 2 3 4 \n2 1 4 3 \n1 2 3 4 \n2 1 4 3 \n\n1 2 3 4 \n2 1 4 3 \n1 2 3 4 \n2 3 4 1 \n\n1 2 3 4 \n2 1 4 3 \n1 2 3 4 \n2 4 1 3 \n\n1 2 3 4 \n2 1 4 3 \n1 2 3 4 \n3 1 4 2\n */\npublic class E3 {\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\n\tstatic int MAX = 2005;\n\tstatic long mod = 998_244_353L;\n\tstatic long fact[];\n\tstatic long dp[][];\n\t\n\tstatic int N;\n\tstatic int mat[][];\n\tpublic static void main(String[] args) {\n\t\tFS in = new FS();\n\t\tfact = new long[MAX];\n\t\tfact[0] = 1;\n\t\tfor(int i = 1; i < MAX; i++) fact[i] = (fact[i-1]*i)%mod;\n\t\tdp = new long[MAX][MAX];\n\t\tfor(long a[] : dp) Arrays.fill(a, -1);\n\t\t\n\t\tN = in.nextInt();\n\t\tmat = new int[N][N];\n\t\tfor(int i = 0; i < N; i++)\n\t\t\tfor(int j = 0; j < N; j++)\n\t\t\t\tmat[i][j] = in.nextInt()-1;\n\t\t\n\t\tlong whenFree = go(N, N);\n\t\tlong freePow[] = new long[N+1];\n\t\tfreePow[0] = 1;\n\t\tfor(int i = 1; i <= N; i++) {\n\t\t\tfreePow[i] = (whenFree * freePow[i-1])%mod;\n\t\t}\n\t\t\n//\t\tfor(int i = 1; i <= N; i++) {\n//\t\t\tfor(int j = 0; j <= i; j++) {\n//\t\t\t\tSystem.out.println(\"n=\"+i+\" ab=\"+j+\" res = \"+go(i,j));\n//\t\t\t}\n//\t\t}\n//\t\t\n//\t\tSystem.out.println(\"FP = \"+whenFree);\n\t\t\n\t\tlong res = 0;\n\t\tfor(int i = 0; i < N; i++) {\n\t\t\tint sz = N;\n\t\t\tBIT have = new BIT(N);\n\t\t\tBIT both = new BIT(N);\n\t\t\tfor(int j = 0; j < N; j++) have.update(j, 1);\n\t\t\tfor(int j = 0; j < N; j++) both.update(j, 1);\n\t\t\t\n\t\t\tboolean usedCur[] = new boolean[N];\n\t\t\tboolean usedPrev[] = new boolean[N];\n\t\t\t\n\t\t\tint numEq = N;\n\t\t\t\n\t\t\tfor(int j = 0; j < N; j++) {\n\t\t\t\tsz--;\n\t\t\t\t// place something less than it\n\t\t\t\tlong areLess = have.sum(0, mat[i][j]-1);\n\t\t\t\tif(i > 0 && mat[i-1][j] < mat[i][j]) areLess -= have.sum(mat[i-1][j], mat[i-1][j]);\n\t\t\t\t\n\t\t\t\tlong lessAndBoth = i == 0 ? 0 : both.sum(0, mat[i][j]-1);\n\t\t\t\tif(i > 0 && mat[i-1][j] < mat[i][j]) lessAndBoth -= both.sum(mat[i-1][j], mat[i-1][j]);\n\t\t\t\t\n\t\t\t\tlong willDeqEq = lessAndBoth;\n\t\t\t\tlong willNotDeqEq = areLess - lessAndBoth;\n\t\t\t\t\n\t\t\t\tint subAgain = i > 0 && !usedCur[mat[i-1][j]] ? 1 : 0;\n\t\t\t\t// Now see if what we are placing will dec numEq or not\n\t\t\t\t\n\t\t\t\tres = add(res, mult(freePow[N-i-1], mult(willNotDeqEq, go(sz, (i == 0 ? 0 : numEq-subAgain)))));\n\t\t\t\tres = add(res, mult(freePow[N-i-1], mult(willDeqEq, go(sz, (i == 0 ? 0 : numEq-1-subAgain)))));\n\t\t\t\t\n//\t\t\t\tSystem.out.println(i+\" \"+j+\" less = \"+areLess+\" sz = \"+sz+\" res = \"+res+\" Eq = \"+numEq+\" deq = \"+willDeqEq+\" not = \"+willNotDeqEq);\n\t\t\t\t\n\t\t\t\t// place the current element and continue\n\t\t\t\thave.update(mat[i][j], -1);\n\t\t\t\t// subtract 1 from numEq if this is the first\n\t\t\t\t// time removing a number\n\t\t\t\tif(!usedPrev[mat[i][j]]) {\n\t\t\t\t\tnumEq--;\n\t\t\t\t\tboth.update(mat[i][j], -1);\n\t\t\t\t}\n\t\t\t\tif(i > 0 && !usedCur[mat[i-1][j]]) { \n\t\t\t\t\tnumEq--;\n\t\t\t\t\tboth.update(mat[i-1][j], -1);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t\n\t\t\t\tif(i > 0) usedPrev[mat[i-1][j]] = true;\n\t\t\t\tusedCur[mat[i][j]] = true;\n\t\t\t}\n\t\t}\n\t\tout.println(res);\n\t\tout.close();\n\t}\n\t\n\tstatic long go(int n, int above) {\n\t\tif(n <= 0 || above < 0) return 0;\n\t\tif(n == 1) return above == 1 ? 0 : 1;\n\t\tif(above == 0) return fact[n];\n\t\tif(dp[n][above] != -1) return dp[n][above];\n\t\tlong free = n-above;\n\t\tlong notFree = above-1;\n\t\tlong res = 0;\n\t\tres += (free * go(n-1, above-1));\n\t\tres += (notFree * go(n-1, above-2));\n\t\treturn dp[n][above] = res%mod;\n\t}\n\t\n\tstatic long add(long a, long b) {\n\t\tlong x = a+b;\n\t\treturn x >= mod ? x-mod : x;\n\t}\n\tstatic long mult(long a, long b) {\n\t\tlong x = a*b;\n\t\treturn x >= mod ? x%mod : x;\n\t}\n\t\n\t\n\tstatic class BIT {\n\t\tint n;\n\t\tint[] tree;\n\t\t\n\t\tpublic BIT(int n) {\n\t\t\tthis.n = n;\n\t\t\ttree = new int[n + 2];\n\t\t}\n\t\t\n\t\tint read(int i) {\n\t\t\ti++;\n\t\t\tint sum = 0;\n\t\t\twhile (i > 0) {\n\t\t\t\tsum += tree[i];\n\t\t\t\ti -= i & -i;\n\t\t\t}\n\t\t\treturn sum;\n\t\t}\n\t\t\n\t\tint sum(int a, int b) {\n\t\t\tif(a > b) return 0;\n\t\t\treturn read(b) - (a == 0 ? 0 : read(a-1));\n\t\t}\n\t\t\n\t\tvoid update(int i, int val) {\n\t\t\ti++;\n\t\t\twhile (i <= n) {\n\t\t\t\ttree[i] += val;\n\t\t\t\ti += i & -i;\n\t\t\t}\n\t\t}\n\n\t\t// if the BIT is a freq array, returns the\n\t\t// index of the kth item, or n if there are fewer\n\t\t// than k items.\n\t\tint getKth(int k) {\n\t\t\tint e=Integer.highestOneBit(n), o=0;\n\t\t\tfor (; e!=0; e>>=1) {\n\t\t\t\tif (e+o<=n && tree[e+o]<=k) {\n\t\t\t\t\tk-=tree[e+o];\n\t\t\t\t\to+=e;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn o;\n\t\t}\n\t\t\n\t}\n\t\n\tstatic class FS{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FS() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\t\tString next() {\n\t\t\twhile(st == null || !st.hasMoreElements()) {\n\t\t\t\ttry {st = new StringTokenizer(br.readLine());}\n\t\t\t\tcatch(Exception e) { throw null;}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tint nextInt() { return Integer.parseInt(next());}\n\t\tdouble nextDouble() { return Double.parseDouble(next());}\n\t\tlong nextLong() { return Long.parseLong(next());}\n\t\tint[] NIA(int n) {\n\t\t\tint r[] = new int[n];\n\t\t\tfor(int i = 0; i < n; i++) r[i] = nextInt();\n\t\t\treturn r;\n\t\t}\n\t\tlong[] NLA(int n) {\n\t\t\tlong r[] = new long[n];\n\t\t\tfor(int i = 0; i < n; i++) r[i] = nextLong();\n\t\t\treturn r;\n\t\t}\n\t\tchar[][] grid(int r, int c){\n\t\t\tchar res[][] = new char[r][c];\n\t\t\tfor(int i = 0; i < r; i++) {\n\t\t\t\tchar l[] = next().toCharArray();\n\t\t\t\tfor(int j = 0; j < c; j++) {\n\t\t\t\t\tres[i][j] = l[j];\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\t}\n\t\n}\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "27bb4038bcd830fc6834461e413a6d4c", "src_uid": "46253becfda9a45ce670dc7d835beaf3", "difficulty": 2900.0} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n private static myScanner sc;\n private static PrintWriter pw;\n\n private static final boolean defaultInAndOutPut = true;\n\n private static final int numberOfTests = 1;\n\n private static final String nameOfInAndOutFile = \"\";\n private static final String fullNameInputFile = nameOfInAndOutFile + \".in\";\n private static final String fullNameOutputFile = nameOfInAndOutFile + \".out\";\n\n public static void main(String[] args) throws IOException {\n if (defaultInAndOutPut) {\n setDefaultInAndOutPut();\n } else {\n setInAndOutPutFromFile();\n }\n for (int test = 1; test <= numberOfTests; test++) {\n solve();\n pw.flush();\n }\n\n pw.close();\n }\n\n private static void setDefaultInAndOutPut() {\n sc = new myScanner(new BufferedReader(new InputStreamReader(System.in)));\n pw = new PrintWriter(System.out);\n }\n\n private static void setInAndOutPutFromFile() throws IOException {\n sc = new myScanner(new BufferedReader(new FileReader(new File(fullNameInputFile))));\n pw = new PrintWriter(new File(fullNameOutputFile));\n }\n\n private static final int intINF = Integer.MAX_VALUE;\n private static final long longINF = Long.MAX_VALUE;\n\n private static void solve() {\n int n = sc.nextInt();\n long k =sc.nextLong();\n long[] a = new long[n];\n TreeSet set = new TreeSet<>();\n for (int i=0;i 0;\n }\n\n private void loadBuffer() {\n pos = 0;\n try {\n for (int i; (i = reader.read()) != -1; ) {\n char c = (char) i;\n if (c != ' ' && c != '\\n' && c != '\\t' && c != '\\r' && c != '\\f') {\n if (pos == buffer.length) buffer = Arrays.copyOf(buffer, 2 * pos);\n buffer[pos++] = c;\n } else if (pos != 0) break;\n }\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n public String current() {\n return String.copyValueOf(buffer, 0, pos);\n }\n\n\n public String next() {\n loadBuffer();\n return current();\n }\n\n\n public String nextLine() {\n try {\n return reader.readLine();\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n\n public int nextInt() {\n return nextInt(10);\n }\n\n public long nextLong() {\n return nextLong(10);\n }\n\n public int nextInt(int radix) {\n loadBuffer();\n int result = 0;\n int i = buffer[0] == '-' || buffer[0] == '+' ? 1 : 0;\n for (checkValidNumber(pos > i); i < pos; i++) {\n int digit = buffer[i] - '0';\n checkValidNumber(0 <= digit && digit <= radix - 1);\n result = result * radix + digit;\n }\n return buffer[0] == '-' ? -result : result;\n }\n\n public long nextLong(int radix) {\n loadBuffer();\n long result = 0;\n int i = buffer[0] == '-' || buffer[0] == '+' ? 1 : 0;\n for (checkValidNumber(pos > i); i < pos; i++) {\n int digit = buffer[i] - '0';\n checkValidNumber(0 <= digit && digit <= radix - 1);\n result = result * radix + digit;\n }\n return buffer[0] == '-' ? -result : result;\n }\n\n public int[] nextArrayInts(int size) {\n int[] input = new int[size];\n for (int i = 0; i < size; i++) input[i] = nextInt();\n return input;\n }\n\n public long[] nextArrayLongs(int size) {\n long[] input = new long[size];\n for (int i = 0; i < size; i++) input[i] = nextLong();\n return input;\n }\n\n public double nextDouble() {\n loadBuffer();\n long result = 0;\n int i = buffer[0] == '-' || buffer[0] == '+' ? 1 : 0;\n long round = 1;\n final int radix = 10;\n boolean hasPoint = false;\n for (checkValidNumber(pos > i); i < pos; i++) {\n int digit = buffer[i] - '0';\n checkValidNumber((0 <= digit && digit <= radix - 1) || (!hasPoint && digit == -2));\n if (digit == -2) hasPoint = true;\n else {\n if (hasPoint) round *= radix;\n result = result * radix + digit;\n }\n\n }\n return buffer[0] == '-' ? -result / (1.0 * round) : result / (1.0 * round);\n }\n\n private void checkValidNumber(boolean condition) {\n if (!condition) throw new NumberFormatException(current());\n }\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "2f474f6b55abb91f47b25830ccb5fbc9", "src_uid": "2e1ab01d4d4440f33c840c4564a20a60", "difficulty": 2300.0} {"lang": "Java 8", "source_code": "//package prac;\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\n\npublic class ECR66G2 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tint[] a;\n\t\n\t/*\n[[0, 9777, 29196, 45342, 70884, 89350, 107220, 132692, 151648, 170604, 189560]]\n[[0, 9777, 24375, 40005, 62940, 81082, 97682, 121166, 140122, 159078, 178034]]\n[[0, 9777, 24375, 39489, 57726, 75745, 89414, 115829, 133894, 153741, 169269]]\n\t */\n\tvoid solve()\n\t{\n\t\tint n = ni(), K = ni();\n\t\ta = na(n);\n\t\t\n\t\tlong[] dp = new long[n+1];\n\t\tArrays.fill(dp, Long.MAX_VALUE / 100000);\n\t\tdp[0] = 0;\n\t\tfor(int i = 1;i <= K;i++) {\n\t\t\tdp = go(dp);\n\t\t}\n\t\tout.println(dp[n]);\n\t}\n\t\n\tlong[] go(long[] dp)\n\t{\n\t\tint n = dp.length-1;\n\t\tlong[] ret = new long[n+1];\n\t\tint[] stack = new int[n+1];\n\t\tint[] times = new int[n+1];\n\t\tLiChaoTreeWithNode[] lcts = new LiChaoTreeWithNode[n+1];\n\t\tPersistentLiChaoTree plct = new PersistentLiChaoTree(n+1, 0, 17);\n\t\tint sp = 0;\n\t\t\n\t\t// max * (i-j) + dp[j]\n\t\t// max * i + max*(-j) + dp[j]\n\t\tfor(int i = 0;i < n;i++) {\n\t\t\tlcts[i] = new LiChaoTreeWithNode(0, 17);\n\t\t\tlcts[i].add(new LiChaoTreeWithNode.Node(-i, dp[i]));\n\t\t\t\n\t\t\twhile(sp > 0 && a[i] > a[stack[sp-1]]){\n\t\t\t\tlcts[i] = merge(lcts[i], lcts[stack[sp-1]]);\n\t\t\t\tlcts[stack[sp-1]] = null;\n\t\t\t\tsp--;\n\t\t\t}\n\t\t\t// x+4\n\t\t\t\n\t\t\tplct.add(sp == 0 ? 0 : times[sp-1], a[i], lcts[i].f(a[i]));\n\t\t\tstack[sp] = i;\n\t\t\ttimes[sp] = plct.last();\n\t\t\tsp++;\n\t\t\tret[i+1] = plct.f(plct.last(), i+1);\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tLiChaoTreeWithNode merge(LiChaoTreeWithNode a, LiChaoTreeWithNode b)\n\t{\n\t\tif(b.num > a.num) {\n\t\t\tLiChaoTreeWithNode d = a; a = b; b = d;\n\t\t}\n\t\tadds(b.root, a);\n\t\treturn a;\n\t}\n\t\n\tvoid adds(LiChaoTreeWithNode.Node x, LiChaoTreeWithNode a)\n\t{\n\t\tif(x == null)return;\n\t\ta.add(new LiChaoTreeWithNode.Node(x.a, x.b));\n\t\tadds(x.left, a);\n\t\tadds(x.right, a);\n\t}\n\t\n\tpublic static class LiChaoTreeWithNode {\n\t\t\n\t\tpublic static class Node\n\t\t{\n\t\t\tpublic long a, b;\n\t\t\tpublic Node left, right;\n\t\t\t\n\t\t\tpublic long f(long x)\n\t\t\t{\n\t\t\t\treturn a*x+b;\n\t\t\t}\n\n\t\t\tpublic Node(long a, long b) {\n\t\t\t\tthis.a = a;\n\t\t\t\tthis.b = b;\n\t\t\t}\n\n\t\t\t@Override\n\t\t\tpublic String toString() {\n\t\t\t\treturn \"Node [a=\" + a + \", b=\" + b + \", \" + (left != null ? \"left=\" + left + \", \" : \"\")\n\t\t\t\t\t\t+ (right != null ? \"right=\" + right : \"\") + \"]\";\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic long L, D;\n\t\tpublic Node root;\n\t\tpublic int num;\n\t\t\n\t\t// [L, L+(1<= 0 && cur != null;m--){\n\t\t\t\tmin = Math.min(min, cur.f(x));\n\t\t\t\tif(x-L<<~m<0){\n\t\t\t\t\tcur = cur.right;\n\t\t\t\t}else{\n\t\t\t\t\tcur = cur.left;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn min;\n\t\t}\n\t}\n\t\n\tpublic static int lowerBound(int[] a, int v){ return lowerBound(a, 0, a.length, v); }\n\tpublic static int lowerBound(int[] a, int l, int r, int v)\n\t{\n\t\tif(l > r || l < 0 || r > a.length)throw new IllegalArgumentException();\n\t\tint low = l-1, high = r;\n\t\twhile(high-low > 1){\n\t\t\tint h = high+low>>>1;\n\t\t\tif(a[h] >= v){\n\t\t\t\thigh = h;\n\t\t\t}else{\n\t\t\t\tlow = h;\n\t\t\t}\n\t\t}\n\t\treturn high;\n\t}\n\t\n\tpublic static class PersistentLiChaoTree {\n\t\t\n\t\t// parameters of function\n\t\tpublic long[] as;\n\t\tpublic long[] bs;\n\t\t\n\t\tpublic int gen;\n\t\tpublic long L, D;\n\t\tpublic int[] lefts, rights;\n\t\t\n\t\tpublic int[] entries;\n\t\tpublic int egen;\n\t\t\n\t\t// [L, L+(1<= 0 && cur != -1;m--){\n\t\t\t\tmin = Math.min(min, f(x, as[cur], bs[cur]));\n\t\t\t\tif(m == 0)break;\n\t\t\t\tif(x-L<<~(m-1)<0){\n\t\t\t\t\tcur = rights[cur];\n\t\t\t\t}else{\n\t\t\t\t\tcur = lefts[cur];\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn min;\n\t\t}\n\t\t\n\t\tpublic static long f(long x, long a, long b)\n\t\t{\n\t\t\treturn a*x+b;\n\t\t}\n\t}\n\n\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 ECR66G2().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", "compilation_error": false, "code_uid": "6744ecf7e700e23edaebbc3bc7cb38bd", "src_uid": "f42faaaa88628748a8da49111936be00", "difficulty": 3000.0} {"lang": "Java 6", "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\tTaskD solver = new TaskD();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskD {\n static class Point {\n int x;\n int y;\n int z;\n\n Point(int x, int y, int z) {\n this.x = x;\n this.y = y;\n this.z = z;\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 Point point = (Point) o;\n\n if (x != point.x) return false;\n if (y != point.y) return false;\n if (z != point.z) return false;\n\n return true;\n }\n\n public int hashCode() {\n int result = x;\n result = 31 * result + y;\n result = 31 * result + z;\n return result;\n }\n }\n \n\tpublic void solve(int testNumber, InputReader in, PrintWriter out) {\n Point[][] ans = new Point[51][];\n ans[1] = new Point[]{new Point(0, 0, 0)};\n ans[2] = new Point[]{new Point(0, 0, 0), new Point(0, 1, 0), new Point(1, 1, 0), new Point(1, 0, 0), new Point(1, 0, 1), new Point(1, 1, 1), new Point(0, 1, 1), new Point(0, 0, 1)};\n for (int n = 3; n < ans.length; ++n) {\n Point[] prev = ans[n - 1];\n int prevSize = (n - 1) * (n - 1) * (n - 1);\n if (prev.length != prevSize) throw new RuntimeException();\n int sideSize = (n - 1) * (n - 1);\n if (!prev[prevSize - sideSize - 1].equals(new Point(n - 2, 0, n - 3))) throw new RuntimeException();\n if (!prev[prevSize - sideSize].equals(new Point(n - 2, 0, n - 2))) throw new RuntimeException();\n if (!prev[prevSize - 1].equals(new Point(0, 0, n - 2))) throw new RuntimeException();\n if (!prev[0].equals(new Point(0, 0, 0))) throw new RuntimeException();\n Point[] cur = new Point[n * n * n];\n ans[n] = cur;\n int curPtr = 0;\n for (int i = 0; i < sideSize; ++i) {\n Point old = prev[prevSize - 1 - i];\n cur[curPtr++] = new Point(old.x, old.y, 0);\n }\n for (int i = 0; i < prevSize; ++i) {\n Point old = prev[i];\n cur[curPtr++] = new Point(n - 2 - old.x, old.y, old.z + 1);\n }\n Point[] rect = getRectangleTraversal(n - 1, n);\n for (int i = 0; i < rect.length; ++i) {\n cur[curPtr++] = new Point(n - 1, rect[i].x, rect[i].y);\n }\n rect = getRectangleTraversal2(n);\n for (int i = 0; i < rect.length; ++i) {\n cur[curPtr++] = new Point(rect[i].x, n - 1, rect[i].y);\n }\n if (curPtr != cur.length) throw new RuntimeException();\n for (int i = 0; i < cur.length; ++i) {\n int tmp = cur[i].y;\n cur[i].y = cur[i].z;\n cur[i].z = tmp;\n }\n }\n int n = in.nextInt();\n int[][][] field = new int[n][n][n];\n Point prev = null;\n int at = 0;\n for (Point p : ans[n]) {\n if (prev != null) {\n int d = Math.abs(p.x - prev.x) + Math.abs(p.y - prev.y) + Math.abs(p.z - prev.z);\n if (d != 1) throw new RuntimeException();\n }\n prev = p;\n ++at;\n if (field[p.x][p.y][p.z] != 0) throw new RuntimeException();\n field[p.x][p.y][p.z] = at;\n }\n boolean xf = true;\n for (int[][] x : field) {\n if (xf) xf = false; else out.println();\n for (int[] y : x) {\n boolean zf = true;\n for (int z : y) {\n if (zf) zf = false; else out.print(\" \");\n if (z == 0) throw new RuntimeException();\n out.print(z);\n }\n out.println();\n }\n }\n\t}\n\n private Point[] getRectangleTraversal2(int n) {\n int sx = n;\n int sy = n; \n Point[] res = new Point[sx * sy];\n int resPtr = 0;\n if (sy % 2 == 0) {\n for (int y = sy - 1; y >= 0; --y) {\n if (y % 2 != 0) {\n for (int x = 0; x < sx; ++x)\n res[resPtr++] = new Point(y, x, 0);\n } else {\n for (int x = sx - 1; x >= 0; --x)\n res[resPtr++] = new Point(y, x, 0);\n }\n }\n } else {\n for (int y = sy - 1; y >= 2; --y) {\n if (y % 2 == 0) {\n for (int x = 0; x < sx; ++x)\n res[resPtr++] = new Point(y, x, 0);\n } else {\n for (int x = sx - 1; x >= 0; --x)\n res[resPtr++] = new Point(y, x, 0);\n }\n }\n for (int x = sx - 1; x >= 0; --x) {\n if (x % 2 == 0) {\n res[resPtr++] = new Point(1, x, 0);\n res[resPtr++] = new Point(0, x, 0);\n } else {\n res[resPtr++] = new Point(0, x, 0);\n res[resPtr++] = new Point(1, x, 0);\n }\n }\n }\n if (resPtr != res.length) throw new RuntimeException();\n return res;\n }\n\n private Point[] getRectangleTraversal(int sx, int sy) {\n Point[] res = new Point[sx * sy];\n int resPtr = 0;\n if (sy % 2 != 0) {\n for (int y = sy - 1; y >= 0; --y) {\n if (y % 2 == 0) {\n for (int x = 0; x < sx; ++x)\n res[resPtr++] = new Point(x, y, 0);\n } else {\n for (int x = sx - 1; x >= 0; --x)\n res[resPtr++] = new Point(x, y, 0);\n }\n }\n } else {\n for (int y = sy - 1; y >= 2; --y) {\n if (y % 2 != 0) {\n for (int x = 0; x < sx; ++x)\n res[resPtr++] = new Point(x, y, 0);\n } else {\n for (int x = sx - 1; x >= 0; --x)\n res[resPtr++] = new Point(x, y, 0);\n }\n }\n for (int x = 0; x < sx; ++x) {\n if (x % 2 == 0) {\n res[resPtr++] = new Point(x, 1, 0);\n res[resPtr++] = new Point(x, 0, 0);\n } else {\n res[resPtr++] = new Point(x, 0, 0);\n res[resPtr++] = new Point(x, 1, 0);\n }\n }\n }\n if (resPtr != res.length) throw new RuntimeException();\n return res;\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 }\n\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "f77caa2394b0cf132653c9739b90f1d9", "src_uid": "e652ba0901b39f0d01ac152babc06b88", "difficulty": 2700.0} {"lang": "Java 11", "source_code": "\r\n\r\nimport java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\nimport java.io.StreamTokenizer;\r\n\r\npublic class CF1528E {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n StreamTokenizer st = new StreamTokenizer(br);\r\n\r\n final int N = (int) (1e6 + 10);\r\n final int M = 998244353;\r\n\r\n long[] dp = new long[N], dp1 = new long[N], dp2 = new long[N];\r\n\r\n private long readLong() throws IOException {\r\n st.nextToken();\r\n return (long) st.nval;\r\n }\r\n\r\n private int readInt() throws IOException {\r\n st.nextToken();\r\n return (int) st.nval;\r\n }\r\n\r\n private String readString() throws Exception {\r\n st.nextToken();\r\n return st.sval;\r\n }\r\n\r\n public static void main(String[] args) throws Exception {\r\n new CF1528E().run();\r\n }\r\n\r\n long inv(long a) {\r\n return inv(a, M);\r\n }\r\n\r\n public long inv(long a, long mod) {\r\n long b = mod;\r\n long p = 1, q = 0;\r\n while (b > 0) {\r\n long c = a / b;\r\n long d;\r\n d = a;\r\n a = b;\r\n b = d % b;\r\n d = p;\r\n p = q;\r\n q = d - c * q;\r\n }\r\n return p < 0 ? p + mod : p;\r\n }\r\n\r\n long g(int n) {\r\n if (n < 0)\r\n return 0;\r\n long t = dp[n];\r\n long res = (t * (t + 1)) % M;\r\n res = (res * (t + 5)) % M;\r\n res = (res * inv(3)) % M;\r\n return (res + M) % M;\r\n }\r\n\r\n\r\n private void run() throws Exception {\r\n int n = readInt();\r\n dp[0] = dp1[0] = dp2[0] = 1;\r\n\r\n for (int i = 1; i <= n; i++) {\r\n dp[i] = ((dp[i - 1] + 1) * (dp[i - 1] + 2) / 2) % M;\r\n dp1[i] = dp[i] - dp[i - 1];\r\n dp2[i] = dp1[i] - dp1[i - 1];\r\n }\r\n long res = (g(n - 1) - g(n - 2)) % M;\r\n for (int i = 0; i < n; i++)\r\n res = (res + dp2[i] * dp1[n - 1 - i]) % M;\r\n\r\n System.out.println(res);\r\n }\r\n}\r\n", "lang_cluster": "Java", "compilation_error": false, "code_uid": "eac60e2472dcde350f64606ef92e94b0", "src_uid": "92939054045c089cd25c8f4e7b9ffcf2", "difficulty": 2900.0} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class Polykarp {\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tint k = in.nextInt();\n\t\tint a = in.nextInt() - 1;\n\t\tint b = in.nextInt() - 1;\n\t\t\n\t\tint ap = a/(m*k);\n\t\tint ae = (a%(m*k)) / k;\n\t\t\n\t\tint bp = b/(m*k);\n\t\tint be = (b%(m*k)) / k;\n\t\t\n\t\tint t = 0;\n\t\t\n\t\tif (ap == bp) {\n\t\t\tif (ae != be) {\n\t\t\t\tt = min(abs(ae - be)*5, 10 + abs(ae - be));\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tt += min(ae*5, 10 + ae);\n\t\t\tt += min(mod(ap - bp, n), mod(bp - ap, n)) * 15;\n\t\t\tt += min(be*5, be + 10);\n\t\t}\n\t\t\n\t\tSystem.out.print(t);\n\t\tin.close();\n\t}\n\t\n\t\n\tpublic static int min(int a, int b) {\n\t\tif (a < b) {\n\t\t\treturn a;\n\t\t}\n\t\telse {\n\t\t\treturn b;\n\t\t}\n\t}\n\t\n\tpublic static int abs(int a) {\n\t\tif (a >=0) {\n\t\t\treturn a;\n\t\t}\n\t\telse {\n\t\t\treturn -a;\n\t\t}\n\t}\n\t\n\tpublic static int mod(int a, int n) {\n\t\twhile (a < 0) {\n\t\t\ta += n;\n\t\t}\n\t\treturn a%n;\n\t}\n}", "lang_cluster": "Java", "compilation_error": false, "code_uid": "0f5d33637a17e2df074ba6be3222b149", "src_uid": "c37b46851abcf7eb472869bd1ab9f793", "difficulty": 1400.0}