{"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class RevEncrypt {\n\tpublic static void main(String[] args) {\n\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt(), i, j;\n\t\tString t = in.next(), s = \"\";\n\t\tin.close();\n\n\t\tfor (i = 2; i <= n; i++)\n\t\t\tif (n % i == 0) {\n\t\t\t\tfor (j = i - 1; j >= 0; j--)\n\t\t\t\t\ts += t.charAt(j);\n\t\t\t\t\n\t\t\t\ts += t.substring(i);\n\t\t\t\tt = s;\n\t\t\t\ts = \"\";\n\t\t\t}\n\t\tSystem.out.println(t);\n\t}\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "1ee6d560c74fa0a059b8abf9c4b047f7", "src_uid": "1b0b2ee44c63cb0634cb63f2ad65cdd3", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.StringTokenizer;\n\n//solution classes here\n\npublic class Code {\n\n //main solution here\n\n static Scanner sc = new Scanner(System.in);\n static PrintWriter out = new PrintWriter(System.out);\n static long mod = 998244353;\n static long MOD = (long)1e9+7;\n //static ArrayList list[] = new ArrayList[(int)1e6+1];\n //static int color[] = new int[(int)1e6+1];\n //static int visit[] = new int[(int)1e5+1];\n //static Deque q = new ArrayDeque<>();\n public static void main(String[] args) throws IOException {\n int n = sc.nextInt();\n if(n%2==0) {\n out.println(\"white\");\n out.print(\"1 2\");\n }\n else {\n out.print(\"black\");\n }\n\n out.flush();\n out.close();\n }\n //solution functions here\n\n static class Scanner {\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(InputStream s) {\n br = new BufferedReader(new InputStreamReader(s));\n }\n\n public Scanner(FileReader fileReader) {\n br = new BufferedReader(fileReader);\n }\n\n public String next() throws IOException {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public String nextLine() throws IOException {\n return br.readLine();\n }\n\n public boolean ready() throws IOException {\n return br.ready();\n }\n }\n}\n\n/* *****************************************************************************************************************************\n * I'M NOT IN DANGER, I'M THE DANGER!!!\n * *****************************************************************************************************************************\n */", "lang_cluster": "Java", "tags": ["math", "constructive algorithms", "games"], "code_uid": "75fb60511428258085bc0ed79c23d7b2", "src_uid": "52e07d176aa1d370788f94ee2e61df93", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\nimport java.util.Map.Entry;\nimport java.io.*;\nimport java.awt.Point;\nimport java.math.BigInteger;\n\nimport static java.lang.Math.*;\n\npublic class CodeforcesC implements Runnable {\n\n final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\n BufferedReader in;\n PrintWriter out;\n StringTokenizer tok = new StringTokenizer(\"\");\n\n void init() throws FileNotFoundException {\n if (ONLINE_JUDGE) {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n } else {\n in = new BufferedReader(new FileReader(\"input.txt\"));\n out = new PrintWriter(\"output.txt\");\n }\n }\n\n String readString() throws IOException {\n while (!tok.hasMoreTokens()) {\n try {\n tok = new StringTokenizer(in.readLine());\n } catch (Exception e) {\n return null;\n }\n }\n return tok.nextToken();\n }\n\n int readInt() throws IOException {\n return Integer.parseInt(readString());\n }\n\n long readLong() throws IOException {\n return Long.parseLong(readString());\n }\n\n double readDouble() throws IOException {\n return Double.parseDouble(readString());\n }\n\n public static void main(String[] args) {\n new Thread(null, new CodeforcesC(), \"\", 128 * (1L << 20)).start();\n }\n\n long timeBegin, timeEnd;\n\n void time() {\n timeEnd = System.currentTimeMillis();\n System.err.println(\"Time = \" + (timeEnd - timeBegin));\n }\n\n long memoryTotal, memoryFree;\n\n void memory() {\n memoryFree = Runtime.getRuntime().freeMemory();\n System.err.println(\"Memory = \" + ((memoryTotal - memoryFree) >> 10)\n + \" KB\");\n }\n\n void debug(Object... objects) {\n if (DEBUG) {\n for (Object o : objects) {\n System.err.println(o.toString());\n }\n }\n }\n\n int[] readIntArray(int n) throws IOException {\n int[] array = new int[n];\n for (int i = 0; i < n; i++)\n array[i] = readInt();\n return array;\n }\n\n public void run() {\n try {\n timeBegin = System.currentTimeMillis();\n memoryTotal = Runtime.getRuntime().freeMemory();\n init();\n solve();\n out.close();\n time();\n memory();\n } catch (Exception e) {\n e.printStackTrace(System.err);\n System.exit(-1);\n }\n }\n\n boolean DEBUG = false;\n\n void solve() throws IOException {\n\n int l = readInt();\n int r = readInt();\n\n int n = 9;\n int[] ten = new int[n + 1];\n\n ten[0] = 1;\n\n for (int i = 1; i <= n; i++)\n ten[i] = 10 * ten[i - 1];\n\n long answer = 0;\n\n List luckyNumbers = new ArrayList();\n \n for (int length = 1; length <= n; length++) {\n for (int cur = 0; cur < (1 << length); cur++) {\n int value = 0;\n for (int j = 0; j < length; j++) {\n if (((1 << j) & cur) == (1 << j))\n value += ten[j] * 7;\n else\n value += ten[j] * 4;\n }\n //out.println(value);\n luckyNumbers.add(1l * value);\n }\n }\n \n luckyNumbers.add(4444444444l);\n \n long lastNumber = l;\n \n for (long luckyNumber : luckyNumbers) {\n if (luckyNumber > r) {\n answer += 1l * (r - lastNumber + 1) * luckyNumber;\n break;\n }\n if (luckyNumber >= l) {\n answer += 1l * (luckyNumber - lastNumber + 1) * luckyNumber;\n lastNumber = luckyNumber + 1;\n }\n }\n \n out.println(answer);\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "math"], "code_uid": "99d52e6a3dcde50234757f8ff4640e6b", "src_uid": "8a45fe8956d3ac9d501f4a13b55638dd", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.PrintWriter;\nimport java.util.Scanner;\n\n\npublic class TaskB {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tnew TaskB().solve(in, out);\n\t\tin.close();\n\t\tout.close();\n\t}\n\t\n\tprivate void solve(Scanner in, PrintWriter out) {\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tif (m < n) {\n\t\t\tn += m;\n\t\t\tm = n - m;\n\t\t\tn -= m;\n\t\t}\n\t\tint g = 0, f = 0;\n\t\tf += n;\n\t\tg += m - 1;\n\t\tout.println(g + \" \" + f);\n\t}\n\n}\n", "lang_cluster": "Java", "tags": ["greedy", "implementation", "games"], "code_uid": "a4e1f9c94232ebf3335f36e3845632be", "src_uid": "c8378e6fcaab30d15469a55419f38b39", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n\npublic class eduA {\npublic static void main(String[] args) throws IOException {\n\tBufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n\tString [] s = bf.readLine().split(\" \");\n\tString [] s1 = bf.readLine().split(\" \") ; \n\tint n [] = new int [4] ; \n\tn[0] = Integer.parseInt(s[0]) ; \n\tn[1] = Integer.parseInt(s1[0]) ; \n\tn[2] = Integer.parseInt(s[1]);\n\tn[3] = Integer.parseInt(s1[1]) ; \n\tint n1 = Math.abs(n[1]- n[0]) ; \n\t\n\tint n2 = Math.abs(n[3]- n[2]);\n\t\n\t\t\tint answer = Math.max(n1, n2) ;\n\t\t\tSystem.out.println(answer);\n}\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "d89f92acdb596387098027beb4fcdc30", "src_uid": "a6e9405bc3d4847fe962446bc1c457b4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n FScanner in = new FScanner();\n PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out), true);\n\n void run() {\n int n = in.nextInt();\n int[] a = new int[n];\n for (int i = 0; i < n; i++) {\n int x = in.nextInt();\n a[i] = x;\n }\n out.print(a[0] % 2 != 0 && a[n - 1] % 2 != 0 && n % 2 == 1 ? \n \"Yes\" :\n \"No\");\n out.close();\n }\n\n public static void main(String[] args) {\n new A().run();\n }\n\n static class FScanner {\n BufferedReader br;\n StringTokenizer st;\n\n FScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n\n String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n\n char[][] nextCharArray(int n, int m) {\n char[][] g = new char[n][m];\n for (int i = 0; i < n; i++)\n g[i] = next().toCharArray();\n return g;\n }\n\n double[] nextDoubleArray(int n) {\n double[] a = new double[n];\n for (int i = 0; i < n; i++)\n a[i] = nextDouble();\n return a;\n }\n\n int[] nextIntArray(int n) {\n int[] a = new int[n];\n for (int i = 0; i < n; i++)\n a[i] = nextInt();\n return a;\n }\n\n long[] nextLongArray(int n) {\n long[] a = new long[n];\n for (int i = 0; i < n; i++)\n a[i] = nextLong();\n return a;\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "17bab6a8bcc9f43b5cece555495a74b7", "src_uid": "2b8c2deb5d7e49e8e3ededabfd4427db", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\npublic class MyClass {\n\n static int c, d, n, m, k, commonParty, must;\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n\n c = sc.nextInt();\n d = sc.nextInt();\n n = sc.nextInt();\n m = sc.nextInt();\n k = sc.nextInt();\n commonParty = n * m;\n must = commonParty - k;\n\n if (must > 0) {\n \n int algC = algC();\n int algD = algD();\n\n int algJoint = algC - c;\n int partyCMinusRound = (algJoint / c) * n;\n\n int i = (must - partyCMinusRound);\n while (i > 0) {\n i -= 1;\n algJoint += d;\n }\n\n System.out.println(min(algC, algD, algJoint));\n } else {\n System.out.println(0);\n }\n\n }\n\n public static int algC() {\n int tempCommonParty = must;\n int sumTask = 0;\n while (tempCommonParty > 0) {\n tempCommonParty -= n;\n sumTask += c;\n }\n return sumTask;\n }\n\n public static int algD() {\n int tempCommonParty = must;\n int sumTask = 0;\n while (tempCommonParty > 0) {\n tempCommonParty -= 1;\n sumTask += d;\n }\n return sumTask;\n }\n\n public static int algFull() {\n //int tempCommonParty = must;\n int algC = algC();\n int algD = algD();\n\n int sumTask = algC - n;\n int partyCMinusRound = algC * (n - 1);\n\n int i = (must - partyCMinusRound);\n while (i > 0) {\n i -= 1;\n sumTask += d;\n }\n\n return min(algC, algD, sumTask);\n }\n\n public static int min(int... numbers) {\n int minNumber = Integer.MAX_VALUE;\n\n for (int number : numbers) {\n minNumber = (number < minNumber) ? number : minNumber;\n }\n\n return minNumber;\n }\n}", "lang_cluster": "Java", "tags": ["math", "dp", "implementation"], "code_uid": "6b03e397f6a968312aba0264d805258f", "src_uid": "c6ec932b852e0e8c30c822a226ef7bcb", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n\n\nimport java.util.Scanner;\n\n/**\n *\n * @author atheeralharbi\n */\npublic class JavaApplication29 {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n // TODO code application logic here\n \n Scanner read = new Scanner(System.in);\n String s3 = read.next();\n String s4 = read.next();\n \n s3 = s3.toUpperCase();\n\t\ts4 = s4.toUpperCase();\n \n \n for (int i = 0 ; i s4.charAt(i)){\n \n System.out.println(1);\n break;\n }\n if (s3.charAt(i) < s4.charAt(i)){\n \n System.out.println(-1);\n break;\n }\n \n \n \n }\n }\n \n}\n", "lang_cluster": "Java", "tags": ["strings", "implementation"], "code_uid": "e023f404ad9d824e0b618bfe08f9bc71", "src_uid": "ffeae332696a901813677bd1033cf01e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Pascal {\n\n static PrintWriter out = new PrintWriter(System.out);\n static BufferedReader br;\n static StringTokenizer st;\n\n\n public static void main(String[] args) throws IOException {\n br = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter out = new PrintWriter(System.out);\n int n = nextInt();\n int k = nextInt();\n int min = Integer.MAX_VALUE;\n for (int i = 1; i < k; i++) {\n if (n % i == 0) {\n int x = (n / (i % k)) * k + i;\n if(x < min) min = x;\n }\n }\n out.print(min);\n out.close();\n }\n\n static int nextInt() throws IOException {\n if (st == null || !st.hasMoreElements()) st = new StringTokenizer(br.readLine());\n return Integer.parseInt(st.nextToken());\n }\n\n static long nextLong() throws IOException {\n if (st == null || !st.hasMoreElements()) st = new StringTokenizer(br.readLine());\n return Long.parseLong(st.nextToken());\n }\n\n static String next() throws IOException {\n if (st == null || !st.hasMoreElements()) st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n}\n\n", "lang_cluster": "Java", "tags": ["math"], "code_uid": "49013fa3fea701a5c49bd1a4d423301f", "src_uid": "ed0ebc1e484fcaea875355b5b7944c57", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\n\npublic class A {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n char[][][] cs = new char[20][8][8];\n for(int i = 0; i < 8; i++) {\n cs[0][i] = sc.next().toCharArray();\n }\n \n for(int i = 0; i < 19; i++) {\n for(int y = 0; y < 8; y++)\n for(int x = 0; x < 8; x++)\n if(cs[i][y][x] == 'M')\n for(int dy = -1; dy <= 1; dy++)\n for(int dx = -1; dx <= 1; dx++) {\n final int xx = x+dx;\n final int yy = y+dy;\n if(0 <= xx && xx < 8 && 0 <= yy && yy < 8 && cs[i][yy][xx] != 'S')\n cs[i+1][yy][xx] = 'M';\n }\n \n for(int y = 6; y >= 0; y--)\n for(int x = 0; x < 8; x++)\n if(cs[i][y][x] == 'S')\n cs[i+1][y+1][x] = 'S';\n }\n \n String res = \"LOSE\";\n for(int y = 0; y < 8; y++)\n for(int x = 0; x < 8; x++)\n if(cs[19][y][x] == 'M')\n res = \"WIN\";\n System.out.println(res);\n }\n}\n", "lang_cluster": "Java", "tags": ["dfs and similar"], "code_uid": "e8f39831e08ad1e169360d51b0c13407", "src_uid": "f47e4ab041288ba9567c19930eb9a090", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.Scanner;\n\n/**\n *\n * @author Annie\n */\npublic class Sticks {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n // TODO code application logic here\n Scanner s = new Scanner(System.in);\n int a[] = new int[6];\n int y=0,no=0;\n for(int i=0;i<6;i++){\n a[i]=s.nextInt();\n }\n \n int b[] = new int[10];\n \n for(int i=0;i<6;i++){\n int x = a[i];\n b[x]++; \n }\n \n \n for(int i=1;i<10;i++){\n if(b[i]==4){\n \n for(int j=1;j<10;j++){\n if(b[j]==2){\n y++;\n }\n else{\n int x=1;\n }\n }\n \n }//if closed\n \n \n else if(b[i]>4){\n if(b[i]==6){\n y++;\n }\n else{\n int x=1;\n }\n }\n \n \n else{\n no++;\n }\n \n \n \n }//for closed\n \n \n \n if(no==9){\n \n System.out.println(\"Alien\");\n }\n else{\n if(y==1){\n System.out.println(\"Elephant\");\n }\n else{\n System.out.println(\"Bear\");\n }\n \n }\n \n \n \n }\n \n}\n", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "738ce7e4af2bc0a07f7526b758edede6", "src_uid": "43308fa25e8578fd9f25328e715d4dd6", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Scanner;\n\npublic class Main {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n long n = sc.nextLong();\n long res = (n / 2) + (n / 3) - (n / 6) + (n / 42)\n +(n / 5) + (n / 7) + (n/ 30) + (n / 70) + (n / 105)\n -(n / 10) - (n / 15) - (n / 14) - (n / 21) - (n / 35) - (n / 210);\n System.out.println(n - res);\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "number theory"], "code_uid": "80db3d064f45537bd7563130c38d4494", "src_uid": "e392be5411ffccc1df50e65ec1f5c589", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.lang.*;\nimport java.util.*;\n\npublic class Luckysubstring {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n String input = in.nextLine();\n int count4 = 0;\n int count7 = 0;\n in.close();\n if (input.contains(\"4\") || input.contains(\"7\")) {\n for (int i = 0; i < input.length(); i++) {\n if (input.charAt(i) == '4') {\n count4++;\n } else if (input.charAt(i) == '7') {\n count7++;\n }\n }\n if (count4 >= count7) {\n System.out.println(4);\n } else {\n System.out.println(7);\n }\n } else {\n System.out.println(-1);\n }\n\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "implementation"], "code_uid": "8d74bb2651d1a145ef41e02e6f589547", "src_uid": "639b8b8d0dc42df46b139f0aeb3a7a0a", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.*;\n\npublic class A {\npublic static void main(String args[]) {\n\tScanner in = new Scanner(System.in);\n\tint n=in.nextInt(),x=in.nextInt(),y=in.nextInt();\n\tdouble ans = y*n/100.0 - x;\n\tif (ans<0) ans =0;\n\tif (ans==(long)ans) System.out.println((int)ans); else System.out.println((long)ans+1);\n\t\n\t\n }\n}\n", "lang_cluster": "Java", "tags": ["math", "implementation"], "code_uid": "47635394b2ddd25cb69f56e5367b97fc", "src_uid": "7038d7b31e1900588da8b61b325e4299", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class Test {\n InputStream is;\n PrintWriter out;\n String INPUT = \"\";\n long[] F;\n\n void solve()\n {\n F = new long[17];\n F[0] = 1;\n for(int i = 1;i <= 16;i++)F[i] = F[i-1] * i;\n\n long K = nl();\n int t = ni();\n K--;\n gouter:\n for(int len = 1;;len++){\n long ret = 0;\n int[] rem = new int[16];\n Arrays.fill(rem, t);\n outer:\n for(int i = 0;i < len;i++){\n for(int j = i == 0 ? 1 : 0;j < 16;j++){\n rem[j]--;\n long count = count(rem, len-1-i);\n if(K < count){\n ret = ret * 16 + j;\n continue outer;\n }else{\n K -= count;\n }\n rem[j]++;\n }\n continue gouter;\n }\n out.println(Long.toHexString(ret));\n return;\n }\n }\n\n long count(int[] rem, int len)\n {\n long[] dp = new long[len+1];\n dp[0] = F[len];\n for(int x : rem){\n if(x < 0)return 0;\n if(x == 0)continue;\n for(int i = len;i >= 0;i--){\n for (int j = 1; j <= x; j++) {\n if ((i - j) < 0) break;\n dp[i] += dp[i - j] / F[j];\n }\n }\n }\n return dp[len];\n }\n\n void run() throws Exception\n {\n is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n out = new PrintWriter(System.out);\n\n long s = System.currentTimeMillis();\n solve();\n out.flush();\n tr(System.currentTimeMillis()-s+\"ms\");\n }\n\n public static void main(String[] args) throws Exception { new Test().run(); }\n\n private byte[] inbuf = new byte[1024];\n private int lenbuf = 0, ptrbuf = 0;\n\n private int readByte()\n {\n if(lenbuf == -1)throw new InputMismatchException();\n if(ptrbuf >= lenbuf){\n ptrbuf = 0;\n try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n if(lenbuf <= 0)return -1;\n }\n return inbuf[ptrbuf++];\n }\n\n private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\n private double nd() { return Double.parseDouble(ns()); }\n private char nc() { return (char)skip(); }\n\n private String ns()\n {\n int b = skip();\n StringBuilder sb = new StringBuilder();\n while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n sb.appendCodePoint(b);\n b = readByte();\n }\n return sb.toString();\n }\n\n private char[] ns(int n)\n {\n char[] buf = new char[n];\n int b = skip(), p = 0;\n while(p < n && !(isSpaceChar(b))){\n buf[p++] = (char)b;\n b = readByte();\n }\n return n == p ? buf : Arrays.copyOf(buf, p);\n }\n\n private char[][] nm(int n, int m)\n {\n char[][] map = new char[n][];\n for(int i = 0;i < n;i++)map[i] = ns(m);\n return map;\n }\n\n private int[] na(int n)\n {\n int[] a = new int[n];\n for(int i = 0;i < n;i++)a[i] = ni();\n return a;\n }\n\n private int ni()\n {\n int num = 0, b;\n boolean minus = false;\n while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n if(b == '-'){\n minus = true;\n b = readByte();\n }\n\n while(true){\n if(b >= '0' && b <= '9'){\n num = num * 10 + (b - '0');\n }else{\n return minus ? -num : num;\n }\n b = readByte();\n }\n }\n\n private long nl()\n {\n long num = 0;\n int b;\n boolean minus = false;\n while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n if(b == '-'){\n minus = true;\n b = readByte();\n }\n\n while(true){\n if(b >= '0' && b <= '9'){\n num = num * 10 + (b - '0');\n }else{\n return minus ? -num : num;\n }\n b = readByte();\n }\n }\n\n private boolean oj = true;//System.getProperty(\"ONLINE_JUDGE\") != null;\n private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}", "lang_cluster": "Java", "tags": ["brute force", "math", "dp", "combinatorics"], "code_uid": "ab89f6444d812168e7919f36912060e1", "src_uid": "cbfc354cfa392cd021d9fe899a745f0e", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "\nimport java.util.Scanner;\n\npublic class Main \n{\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner input = new Scanner (System.in);\n\t\tint N;\n\t\twhile(input.hasNext())\n\t\t{\n\t\t\tN = input.nextInt();\n\t\t\tint ans = (N/7)*2;\n\t\t\tint Mod = N%7;\n\t\t\tif(Mod == 0)\n\t\t\t\tSystem.out.printf(\"%d %d\\n\",ans, ans);\n\t\t\telse if(Mod == 1)\n\t\t\t\tSystem.out.printf(\"%d %d\\n\",ans, ans+1);\n\t\t\telse if(Mod >= 2 && Mod <= 5)\n\t\t\t\tSystem.out.printf(\"%d %d\\n\",ans, ans+2);\n\t\t\telse\n\t\t\t\tSystem.out.printf(\"%d %d\\n\",ans+1, ans+2);\n\t\t}\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "greedy", "constructive algorithms", "brute force"], "code_uid": "282091f1ef3ede3e84cf3a05737ff1a2", "src_uid": "8152daefb04dfa3e1a53f0a501544c35", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Java 6", "source_code": "import java.util.Scanner;\n\npublic class Third {\n\n public static void main(String[] args) {\n Scanner input = new Scanner (System.in);\n int n = input.nextInt();\n int o = n+1;\n int array [] = new int [n];\n for (int i = 0; i= MOD) aa -= MOD;\n\t\tif(b >= MOD) b -= MOD;\n\t\taa *= b;\n\t\tif(aa >= MOD) aa %= MOD;\n\t\treturn (int)aa;\n\t}\n\t\n\tint add(int a, int b) {\n\t\tif(a >= MOD) a -= MOD;\n\t\tif(b >= MOD) b -= MOD;\n\t\ta += b;\n\t\tif(a >= MOD) a-= MOD;\n\t\treturn a;\n\t}\n\n\tvoid sort (int[] a) {\n\t\tint n = a.length;\n\t\tfor(int i = 0; i < 50; i++) {\n\t\t\tRandom r = new Random();\n\t\t\tint x = r.nextInt(n), y = r.nextInt(n);\n\t\t\tint temp = a[x];\n\t\t\ta[x] = a[y];\n\t\t\ta[y] = temp;\n\t\t}\n\t\tArrays.sort(a);\n\t}\n\n\tclass FastScanner {\n\t\tpublic int BS = 1<<16;\n\t\tpublic char NC = (char)0;\n\t\tbyte[] buf = new byte[BS];\n\t\tint bId = 0, size = 0;\n\t\tchar c = NC;\n\t\tdouble num = 1;\n\t\tBufferedInputStream in;\n\n\t\tpublic FastScanner() {\n\t\t\tin = new BufferedInputStream(System.in, BS);\n\t\t}\n\n\t\tpublic FastScanner(String s) throws FileNotFoundException {\n\t\t\tin = new BufferedInputStream(new FileInputStream(new File(s)), BS);\n\t\t}\n\n\t\tpublic char nextChar(){\n\t\t\twhile(bId==size) {\n\t\t\t\ttry {\n\t\t\t\t\tsize = in.read(buf);\n\t\t\t\t}catch(Exception e) {\n\t\t\t\t\treturn NC;\n\t\t\t\t} \n\t\t\t\tif(size==-1)return NC;\n\t\t\t\tbId=0;\n\t\t\t}\n\t\t\treturn (char)buf[bId++];\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn (int)nextLong();\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\tnum=1;\n\t\t\tboolean neg = false;\n\t\t\tif(c==NC)c=nextChar();\n\t\t\tfor(;(c<'0' || c>'9'); c = nextChar()) {\n\t\t\t\tif(c=='-')neg=true;\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tfor(; c>='0' && c <='9'; c=nextChar()) {\n\t\t\t\tres = (res<<3)+(res<<1)+c-'0';\n\t\t\t\tnum*=10;\n\t\t\t}\n\t\t\treturn neg?-res:res;\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\tdouble cur = nextLong();\n\t\t\treturn c!='.' ? cur:cur+nextLong()/num;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\twhile(c<=32)c=nextChar();\n\t\t\twhile(c>32) {\n\t\t\t\tres.append(c);\n\t\t\t\tc=nextChar();\n\t\t\t}\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\twhile(c<=32)c=nextChar();\n\t\t\twhile(c!='\\n') {\n\t\t\t\tres.append(c);\n\t\t\t\tc=nextChar();\n\t\t\t}\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic boolean hasNext() {\n\t\t\tif(c>32)return true;\n\t\t\twhile(true) {\n\t\t\t\tc=nextChar();\n\t\t\t\tif(c==NC)return false;\n\t\t\t\telse if(c>32)return true;\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic int[] nextIntArray(int n) {\n\t\t\tint[] res = new int[n];\n\t\t\tfor(int i = 0; i < n; i++) res[i] = nextInt();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t}\n\n}", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics"], "code_uid": "786ac311c01bc6f5835ac375de33ede2", "src_uid": "77177b1a2faf0ba4ca1f4d77632b635b", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\n\npublic class a {\npublic static void main(String[] args){\nScanner in = new Scanner(System.in);\nin.next();\nString str = in.next();\nif(str.contains(\"CC\")||str.contains(\"YY\")||str.contains(\"MM\")){\nSystem.out.println(\"No\");\nreturn;\n}\n\nif(str.startsWith(\"?\")||str.endsWith(\"?\")||str.contains(\"??\")||str.contains(\"C?C\")||str.contains(\"Y?Y\")||str.contains(\"M?M\"))\nSystem.out.println(\"Yes\");\nelse\nSystem.out.println(\"No\");\n\n}\n}", "lang_cluster": "Java", "tags": ["implementation"], "code_uid": "9453132b10bd3de6df5d0e7dca4aff9a", "src_uid": "f8adfa0dde7ac1363f269dbdf00212c3", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\npublic\nclass TaskA{\n //static variable\n static final int mod = (int) 1e9 + 7;\n static final double eps = 1e-6;\n static final double pi = Math.PI;\n static final long inf = Long.MAX_VALUE / 2;\n\n\n\n BufferedReader br;\n void main1() throws IOException {\n br=new BufferedReader(new InputStreamReader(System.in));\n int t=ii();\n int[] aa=new int[t];\n for (int i = 0; i availableBooks = new HashSet<>(k);\n int[] access = new int[81];\n int removable = -1;\n for (int i = 0; i < n; i++) {\n access[query[i]]++;\n }\n for (int i = 0; i < n; i++) {\n int currentBook = query[i];\n boolean doesNotContain = !availableBooks.contains(currentBook);\n if (doesNotContain) {\n cost++;\n }\n if (removable != -1) {\n availableBooks.remove(removable);\n removable = -1;\n } else if (availableBooks.size() == k && doesNotContain) {\n int removableBook = -1;\n int count = k;\n Set known = new HashSet<>();\n for (int j = i + 1; j < n && count > 0; j++) {\n if (availableBooks.contains(query[j]) && !known.contains(query[j])) {\n count--;\n known.add(query[j]);\n removableBook = query[j];\n }\n }\n if (removableBook != -1) {\n availableBooks.remove(removableBook);\n } else {\n availableBooks.remove(availableBooks.iterator().next());\n }\n }\n availableBooks.add(currentBook);\n if (--access[currentBook] == 0) {\n removable = currentBook;\n }\n }\n out.println(cost);\n }\n\n }\n\n static class FastIO {\n\n final private int BUFFER_SIZE = 1 << 16;\n private InputStream din;\n private byte[] buffer;\n private int bufferPointer;\n private int bytesRead;\n\n public FastIO() {\n buffer = new byte[BUFFER_SIZE];\n bufferPointer = bytesRead = 0;\n }\n\n public FastIO(InputStream inputStream) {\n this();\n din = new DataInputStream(inputStream);\n }\n\n public FastIO(String file_name) {\n try {\n din = new DataInputStream(new FileInputStream(file_name));\n buffer = new byte[BUFFER_SIZE];\n bufferPointer = bytesRead = 0;\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n\n public int nextInt() {\n int ret = 0;\n try {\n byte c = read();\n while (c <= ' ') {\n c = read();\n }\n boolean neg = (c == '-');\n if (neg) {\n c = read();\n }\n do {\n ret = ret * 10 + c - '0';\n } while ((c = read()) >= '0' && c <= '9');\n\n if (neg) {\n return -ret;\n }\n } catch (Exception e) {\n e.printStackTrace();\n }\n return ret;\n }\n\n public int[] nextIntArray(int n) {\n int[] arr = new int[n];\n for (int i = 0; i < n; i++) {\n arr[i] = nextInt();\n }\n return arr;\n }\n\n private void fillBuffer() {\n try {\n bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n if (bytesRead == -1) {\n buffer[0] = -1;\n }\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n\n private byte read() {\n if (bufferPointer == bytesRead) {\n fillBuffer();\n }\n return buffer[bufferPointer++];\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["greedy"], "code_uid": "85af70e9511d21e0424665fe4aa66c3b", "src_uid": "956228e31679caa9952b216e010f9773", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.*;\npublic class gg{\n\tstatic int special(int u, int k,int []a){\n\t\tif(a[u]==1)\n\t\t\treturn k-u;\n\t\tif(a[k]==1000)\n\t\t\treturn k-u;\n\t\telse\n\t\t\treturn k-u-1;\n\t}\n\tpublic static void main(String[] args) {\n\t\tScanner sc=new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\tint a[]=new int[n];\n\t\tint i,max=0;\n\t\tfor(i=0;imax)\n\t\t\t\t\tmax=l;\n\t\t\t\t//c=c+l;\n\t\t\t\t//if(l!=0)\n\t\t\t\t//break;\n\t\t\t}\n\t\t}\n\t\tif(!g)\n\t\t{\n\t\t\tk=n-1;\n\t\t\tl=special(u,k,a);\n\t\t\tif(l>max)\n\t\t\tmax=l;\n\t\t}\n\t\t//System.out.println(u+\" \"+k);\n\t\tSystem.out.println(max);\n\t}\n}", "lang_cluster": "Java", "tags": ["greedy", "implementation"], "code_uid": "e2c6ab3538d7206f5f3938d5cedf58c2", "src_uid": "858b5e75e21c4cba6d08f3f66be0c198", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.* ;\npublic class contes\n{\n public static void main(String ar[])\n {\n Scanner sc = new Scanner(System.in) ;\n int n = sc.nextInt() ;\n int m = sc.nextInt() ;\n int max = 0 ;\n int sum = 0 ;\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 = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public long nextLong() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public int[] nextIntArray(int n) {\n int a[] = new int[n];\n for (int i = 0; i < n; i++) {\n a[i] = nextInt();\n }\n return a;\n }\n\n public String readString() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public String nextLine() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isEndOfLine(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n private boolean isEndOfLine(int c) {\n return c == '\\n' || c == '\\r' || c == -1;\n }\n }\n\n public static void main(String[] args) throws IOException {\n InputReader in = new InputReader(System.in);\n int n = in.nextInt();\n int m = in.nextInt();\n int a[] = new int[101];\n\n for (int i = 0; i < m; i++) {\n int b = in.nextInt();\n a[b]++;\n }\n for(int i=m;i>=1;i--){\n int k = 0;\n for(int j = 1;j<101;j++){\n k+=a[j]/i;\n }\n if(k>=n){\n System.out.println(i);\n return;\n }\n }\n System.out.println(0);\n }\n\n static class sort implements Comparator> {\n\n @Override\n public int compare(ArrayList o1, ArrayList o2) {\n int c = o1.get(0).compareTo(o2.get(0));\n return c;\n }\n\n }\n}", "lang_cluster": "Java", "tags": ["brute force", "implementation", "binary search"], "code_uid": "dbb6cc234e865a381a2d72329c1f6687", "src_uid": "b7ef696a11ff96f2e9c31becc2ff50fe", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.DataInputStream;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.Scanner;\n\npublic class b {\n\t\n\n\t\n\tpublic static void main(String[] rgs)\n\t{\n\t\tScanner s=new Scanner(System.in);\n\n\n\t\tchar[] arr=s.next().toCharArray();\n\t\tchar[] brr=s.next().toCharArray();\n\t\tint ans=0;\n\t\tint n=arr.length;\n\t\tfor(int i=0;ij) {\n\t\t\t\t\t\tif(count calculatedNumbers;\n\n\tpublic Fibonacci(long mod){\n\t\tcalculatedNumbers = new TreeMap<>();\n\t\tcalculatedNumbers.put(0l, 1l);\n\t\tcalculatedNumbers.put(1l, 1l);\n\t\tthis.mod = mod;\n\t}\n\n\tpublic long fib(long n){\n\t\tif(calculatedNumbers.containsKey(n)) return calculatedNumbers.get(n);\n\t\t\n\t\tlong k = n/2, res;\n\t\tif(n%2 == 0){\n\t\t\tres = (fib(k)*fib(k)+fib(k-1)*fib(k-1))%mod;\n\t\t}else{\n\t\t\tres = (fib(k)*fib(k+1)+fib(k-1)*fib(k))%mod;\n\t\t}\n\t\tcalculatedNumbers.put(n, res);\n\t\treturn res;\n\t}\n}\n\nclass Exponentation{\n\t//a^b mod m\n\tpublic static long calc(long a, long b, long m){\n\t\tif(b == 0) return 1;\n\t\tif(b == 1) return a;\n\t\tif(b%2 == 0) return calc(a*a%m, b/2, m);\n\t\telse return a*calc((a*a%m), (b-1)/2, m)%m;\n\t}\n}\n\nclass Solver{\n\tlong n, k, l, MOD;\n\n\tvoid read(InputReader in){\n\t\tn = in.nextLong();\n\t\tk = in.nextLong();\n\t\tl = in.nextLong();\n\t\tMOD = in.nextLong();\n\t}\n\n\tpublic void solve(InputReader in, PrintWriter out){\n\t\tread(in);\n\t\tif(l != 64 && (1l << l)-1 < k){\n\t\t\tout.println(0);\n\t\t\treturn;\n\t\t}\n\n\t\tlong zeroPos = new Fibonacci(MOD).fib(n+1);\n\t\tlong onePos = Exponentation.calc(2, n, MOD)-zeroPos;\n\t\twhile(onePos < 0) onePos += MOD;\n\n\t\tlong res = 1;\n\t\tfor(int i=0; i= currentLine.length) {\n\t\t\ttry {\n\t\t\t\tcurrentLine = reader.readLine().split(\"\\\\s+\");\n\t\t\t\ttoken = 0;\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\t\treturn currentLine[token++];\n\t}\n\n\tpublic int nextInt() {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tpublic long nextLong(){\n\t\treturn Long.parseLong(next());\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "combinatorics", "matrices", "implementation", "number theory"], "code_uid": "5316e588f5731269b4a741a2a8c2011e", "src_uid": "2163eec2ea1eed5da8231d1882cb0f8e", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.util.*;\nimport java.io.*;\n\n// PROBLEM : Can teleport between cells corresponding to the same string\npublic class B {\n static int n;\n static char[][] G;\n public static void main(String[] args) throws Exception {\n Scanner in = new Scanner(System.in);\n n = in.nextInt();\n G = new char[n][n];\n F = new HashMap();\n for(int r=0; r 0) System.out.println(\"FIRST\");\n if(ans < 0) System.out.println(\"SECOND\");\n if(ans == 0) System.out.println(\"DRAW\");\n }\n \n static int ch_to_val(char ch, boolean first) {\n if(ch=='a') return first ? 1 : -1;\n if(ch=='b') return first ? -1 : 1;\n return 0;\n }\n\n static long hash(int sum, boolean[] R) {\n long hash = sum;\n for(int i=0; i F;\n static int f(int sum, boolean[] R, boolean first) {\n long key = hash(sum, R);\n if(F.containsKey(key)) return F.get(key);\n if(sum == 2*(n-1)) return 0;\n\n int ans = -1000;\n int ns = sum+1;\n Character[] CH = new Character[ns+1];\n for(int r=0; r<=sum+1; r++) {\n boolean can_see = (r=0 && R[r-1]);\n if(!can_see) continue;\n int c = ns-r;\n if(c<0 || c>=n || r<0 || r>=n) continue;\n CH[r] = G[r][c];\n }\n\n for(int r=0; r<=sum+1; r++) {\n if(CH[r] != null) {\n char ch = CH[r];\n boolean[] NR = new boolean[ns+1];\n for(int rr=0; rr<=sum+1; rr++)\n if(CH[rr]!=null && CH[rr] == ch) {\n NR[rr] = true;\n CH[rr] = null;\n }\n ans = Math.max(ans, ch_to_val(ch,first) - f(ns, NR, !first));\n }\n }\n F.put(key, ans);\n return ans;\n }\n}\n", "lang_cluster": "Java", "tags": ["games", "dp", "bitmasks"], "code_uid": "254b34dbb9d81231c0a2668759e02920", "src_uid": "d803fe167a96656f8debdc21edd988e4", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF1342E extends PrintWriter {\n\tCF1342E() { super(System.out, true); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1342E o = new CF1342E(); o.main(); o.flush();\n\t}\n\n\tstatic final int MD = 998244353;\n\tint[] ff, gg;\n\tlong power(int a, int k) {\n\t\tif (k == 0)\n\t\t\treturn 1;\n\t\tlong p = power(a, k >> 1);\n\t\tp = p * p % MD;\n\t\tif ((k & 1) == 1)\n\t\t\tp = p * a % MD;\n\t\treturn p;\n\t}\n\tlong ch(int n, int k) {\n\t\treturn (long) ff[n] * gg[k] % MD * gg[n - k] % MD;\n\t}\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tlong k_ = sc.nextLong();\n\t\tif (k_ >= n) {\n\t\t\tprintln(0);\n\t\t\treturn;\n\t\t}\n\t\tint c = n - (int) k_;\n\t\tff = new int[n + n];\n\t\tgg = new int[n + n];\n\t\tfor (int f = 1, i = 0; i < n + n; i++) {\n\t\t\tgg[i] = (int) power(ff[i] = f, MD - 2);\n\t\t\tf = (int) ((long) f * (i + 1) % MD);\n\t\t}\n\t\tlong ans = 0;\n\t\tfor (int a = 1; a <= c; a++) {\n\t\t\tlong x = power(a, n) * ch(c, a) % MD;\n\t\t\tans += (c - a) % 2 == 0 ? x : -x;\n\t\t}\n\t\tif ((ans %= MD) < 0)\n\t\t\tans += MD;\n\t\tans = ans * ch(n, c) % MD;\n\t\tif (k_ > 0)\n\t\t\tans = ans * 2 % MD;\n\t\tprintln(ans);\n\t}\n}\n", "lang_cluster": "Java", "tags": ["math", "combinatorics", "fft"], "code_uid": "36737aa9f67a12a7762fc7250dda7c95", "src_uid": "6c1a9aaa7bdd7de97220b8c6d35740cc", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.util.StringTokenizer;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n Parser in = new Parser(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n}\n\nclass TaskC {\n int mod = 1000000007;\n\n public void solve(int testNumber, Parser in, OutputWriter out) {\n long n = in.nextLong();\n int k = in.nextInt();\n\n long[][] pas = MathUtils.pas(41, mod);\n Matrix a = new Matrix(83);\n\n a.a[0][0] = 1;\n a.a[0][k+1] = 1;\n\n for (int pot = 0; pot <= 40; pot++) {\n for (int coef = 0; coef <= pot; coef++) {\n a.a[pot+1][coef+1] = pas[pot][coef];\n a.a[pot+1][coef+42] = (pas[pot][coef] * ((1L << (pot-coef)) % mod)) % mod;\n }\n }\n\n for (int pot = 0; pot <= 40; pot++) {\n a.a[pot+42][pot+1] = 1;\n }\n\n Matrix b = new Matrix(83);\n for (int i = 1; i <= 42; i++) b.a[i][0] = 1;\n\n a = a.modpow(n, mod);\n a = a.multiply(b, mod);\n /*for (int i = 0; i < 83; i++) {\n System.out.println(\"i \" + i + \" elem: \" + a.a[i][0]);\n }*/\n\n out.println(a.a[0][0]);\n }\n}\n\nclass Parser\n{\n private BufferedReader din;\n private StringTokenizer tokenizer;\n\n public Parser(InputStream in)\n {\n din = new BufferedReader(new InputStreamReader(in));\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(din.readLine());\n } catch (Exception e) {\n throw new UnknownError();\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt()\n {\n return Integer.parseInt(next());\n }\n\n public long nextLong()\n {\n return Long.parseLong(next());\n }\n\n }\n\nclass OutputWriter extends PrintWriter {\n public OutputWriter(Writer out) {\n super(out);\n }\n\n public OutputWriter(OutputStream out) {\n super(out);\n }\n\n }\n\nclass MathUtils {\n\n public static long[][] pas(int n, int mod) {\n long[][] ret = new long[n+1][n+1];\n\n for (int i = 0; i <= n; i++) {\n ret[i][0] = 1;\n for (int j = 1; j <= i; j++) {\n ret[i][j] = (ret[i-1][j-1] + ret[i-1][j]) % mod;\n }\n }\n\n return ret;\n }\n\n }\n\nclass Matrix {\n int n;\n long a[][];\n\n public Matrix(int n) {\n this.n = n;\n a = new long[n][n];\n }\n\n public static Matrix identity(int n) {\n Matrix ret = new Matrix(n);\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n ret.a[i][j] = 0;\n }\n ret.a[i][i] = 1;\n }\n\n return ret;\n }\n\n Matrix multiply(Matrix b, long mod) {\n Matrix resp = new Matrix(n);\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n resp.a[i][j] = 0;\n for (int k = 0; k < n; k++) {\n resp.a[i][j] = (resp.a[i][j] + a[i][k] * b.a[k][j]) % mod;\n }\n }\n }\n\n return resp;\n }\n\n Matrix modpow(long exp, long mod) {\n if (exp == 0) return identity(n);\n if (exp == 1) return this;\n\n Matrix h = modpow(exp/2, mod);\n h = h.multiply(h, mod);\n if (exp % 2 == 1) h = h.multiply(this, mod);\n\n return h;\n }\n\n }\n", "lang_cluster": "Java", "tags": ["math", "matrices", "combinatorics"], "code_uid": "40b2d53497644cf73102cf5048663d85", "src_uid": "14f50a111db268182e5927839a993118", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Java 7", "source_code": "import static java.lang.Math.*;\nimport static java.math.BigInteger.*;\nimport static java.util.Arrays.*;\nimport static java.util.Collections.*;\n\nimport java.io.*;\nimport java.lang.reflect.*;\nimport java.util.*;\n\npublic class D {\n\n\tfinal static boolean autoflush = false;\n\t\n\tfinal static int MOD = (int) 1e9 + 7;\n\tfinal static double eps = 1e-9;\n\tfinal static int INF = (int) 1e9;\n\t\n\tInteger [] A;\n\tint N; int [] Q; int [][] R;\n\t\n\tpublic D () {\n\t\tN = sc.nextInt();\n\t\tA = sc.nextInts();\n\t\t\n\t\tif (N == 1)\n\t\t\texit(1);\n\t\t\n\t\tnext: for (int i : rep(1, N)) {\n\t\t\tfor (int j : rep(i)) \n\t\t\t\tfor (int k : rep(i))\n\t\t\t\t\tif (A[j] + A[k] == A[i])\n\t\t\t\t\t\tcontinue next;\n\t\t\texit(-1);\n\t\t}\n\t\t\n\t\tMap M = new TreeMap();\n\t\tfor (int i : rep(N))\n\t\t\tM.put(A[i], i);\n\n\t\tQ = new int [N];\n\t\tR = new int [N][N];\n\t\t\n\t\tfor (int i : rep(N))\n\t\t\tfor (int j : rep(i))\n\t\t\t\tif (M.containsKey(A[i] - A[j])) {\n\t\t\t\t\tint k = M.get(A[i] - A[j]);\n\t\t\t\t\tQ[i] |= (1 << j);\n\t\t\t\t\tR[i][j] = k;\n\t\t\t\t}\n\n\t\tH = new int [1 << (N-1)]; fill(H, -1);\n\t\t\n\t\tint res = solve(1, 1);\n\t\tassert res <= N;\n\t\texit(res);\n\t}\n\t\t\n\tint [] H;\n\t\n\tint solve(int X, int J) {\n\t\tint B = (X & Q[J]);\n\t\tif (B == 0)\n\t\t\treturn H[X] = INF;\n\t\t\n\t\tfor (int i = 0; i < J; ++i) {\n\t\t\tint U = (1 << i), V = (1 << R[J][i]);\n\t\t\tif ((B&U) != 0 && (B&V) != 0)\n\t\t\t\tbreak;\n\t\t\tif (i == J-1)\n\t\t\t\treturn H[X] = INF;\n\t\t}\n\t\t\n\t\tif (J == N-1)\n\t\t\treturn H[X] = Integer.bitCount(X);\n\t\t\n\t\tint Y = (X | (1 << J)), res = INF;\n\t\tfor (int j = 0; j < J; ++j) {\n\t\t\tint W = (1 << j);\n\t\t\tif ((Y & W) != 0) {\n\t\t\t\tint V = Y & (~W), R = H[V] == -1 ? solve(V, J+1) : H[V];\n\t\t\t\tres = min(res, R);\n\t\t\t}\n\t\t}\n\t\tint R = H[Y] == -1 ? solve(Y, J+1) : H[Y];\n\t\tres = min(res, R);\n\t\treturn H[X] = res;\t\t\n\t}\n\n\t////////////////////////////////////////////////////////////////////////////////////\n\n\tstatic int [] rep(int N) { return rep(0, N); }\n\tstatic int [] rep(int S, int T) { int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }\n\tstatic int [] req(int S, int T) { return rep(S, T+1); }\t\n\n\t////////////////////////////////////////////////////////////////////////////////////\n\n\t/* Dear hacker, don't bother reading below this line, unless you want to help me debug my I/O routines :-) */\n\t\n\tfinal static MyScanner sc = new MyScanner();\n\t\n\tstatic class MyScanner {\n\t\tpublic String next() {\n\t\t\tnewLine();\n\t\t\treturn line[index++];\n\t\t}\n\t\t\n\t\tpublic char nextChar() {\n\t\t\treturn next().charAt(0);\n\t\t}\n\t\t\t\t\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\t\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\t\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\t\n\t\tpublic String nextLine() {\n\t\t\tline = null;\n\t\t\treturn readLine();\n\t\t}\n\t\t\n\t\tpublic String [] nextStrings() {\n\t\t\tline = null;\n\t\t\treturn readLine().split(\" \");\n\t\t}\n\t\t\n\t\tpublic char [] nextChars() {\n\t\t\treturn next ().toCharArray ();\n\t\t}\n\n\t\tpublic Integer [] nextInts() {\n\t\t\tString [] L = nextStrings();\n\t\t\tInteger [] res = new Integer [L.length];\n\t\t\tfor (int i : rep(L.length))\n\t\t\t\tres[i] = Integer.parseInt(L[i]);\n\t\t\treturn res;\n\t\t}\t\n\t\t\n\t\tpublic Long [] nextLongs() {\n\t\t\tString [] L = nextStrings();\n\t\t\tLong [] res = new Long [L.length];\n\t\t\tfor (int i : rep(L.length))\n\t\t\t\tres[i] = Long.parseLong(L[i]);\n\t\t\treturn res;\n\t\t}\n\n\t\tpublic Double [] nextDoubles() {\n\t\t\tString [] L = nextStrings();\n\t\t\tDouble [] res = new Double [L.length];\n\t\t\tfor (int i : rep(L.length))\n\t\t\t\tres[i] = Double.parseDouble(L[i]);\n\t\t\treturn res;\n\t\t}\n\n\t\tpublic String [] next (int N) {\n\t\t\tString [] res = new String [N];\n\t\t\tfor (int i : rep(N))\n\t\t\t\tres[i] = sc.next();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic Integer [] nextInt (int N) {\n\t\t\tInteger [] res = new Integer [N];\n\t\t\tfor (int i : rep(N))\n\t\t\t\tres[i] = sc.nextInt();\n\t\t\treturn res;\n\t\t}\t\t\n\t\t\n\t\tpublic Long [] nextLong (int N) {\n\t\t\tLong [] res = new Long [N];\n\t\t\tfor (int i : rep(N))\n\t\t\t\tres[i] = sc.nextLong();\n\t\t\treturn res;\n\t\t}\t\t\n\t\t\n\t\tpublic Double [] nextDouble (int N) {\n\t\t\tDouble [] res = new Double [N];\n\t\t\tfor (int i : rep(N))\n\t\t\t\tres[i] = sc.nextDouble();\n\t\t\treturn res;\n\t\t}\t\t\n\t\t\n\t\tpublic String [][] nextStrings (int N) {\n\t\t\tString [][] res = new String [N][];\n\t\t\tfor (int i : rep(N))\n\t\t\t\tres[i] = sc.nextStrings();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic Integer [][] nextInts (int N) {\n\t\t\tInteger [][] res = new Integer [N][];\n\t\t\tfor (int i : rep(N))\n\t\t\t\tres[i] = sc.nextInts();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic Long [][] nextLongs (int N) {\n\t\t\tLong [][] res = new Long [N][];\n\t\t\tfor (int i : rep(N))\n\t\t\t\tres[i] = sc.nextLongs();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic Double [][] nextDoubles (int N) {\n\t\t\tDouble [][] res = new Double [N][];\n\t\t\tfor (int i : rep(N))\n\t\t\t\tres[i] = sc.nextDoubles();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\t//////////////////////////////////////////////\n\t\t\n\t\tprivate boolean eol() {\n\t\t\treturn index == line.length;\n\t\t}\n\n\t\tprivate String readLine() {\n\t\t\ttry {\n\t\t\t\treturn r.readLine();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new Error (e);\n\t\t\t}\n\t\t}\n\t\tprivate final BufferedReader r;\n\n\t\tMyScanner () {\n\t\t\tthis(new BufferedReader(new InputStreamReader(System.in)));\n\t\t}\n\t\t\n\t\tMyScanner (BufferedReader r) {\n\t\t\ttry {\n\t\t\t\tthis.r = r;\n\t\t\t\twhile (!r.ready())\n\t\t\t\t\tThread.sleep(1);\n\t\t\t\tstart();\n\t\t\t} catch (Exception e) {\n\t\t\t\tthrow new Error(e);\n\t\t\t}\n\t\t}\n\t\t\n\t\tprivate String [] line;\n\t\tprivate int index;\n\n\t\tprivate void newLine() {\n\t\t\tif (line == null || eol()) {\n\t\t\t\tline = readLine().split(\" \");\n\t\t\t\tindex = 0;\n\t\t\t}\n\t\t}\t\t\n\t}\n\t\n\tstatic void print (Object o, Object... a) {\n\t\tprintDelim(\" \", o, a);\n\t}\n\t\n\tstatic void cprint (Object o, Object... a) {\n\t\tprintDelim(\"\", o, a);\n\t}\n\t\n\tstatic void printDelim (String delim, Object o, Object... a) {\n\t\tpw.println(build(delim, o, a));\n\t}\n\n\tstatic void exit (Object o, Object... a) {\n\t\tprint(o, a);\n\t\texit();\n\t}\n\n\tstatic void exit() {\n\t\tpw.close();\n\t\tSystem.out.flush();\n\t\tSystem.err.println(\"------------------\");\n\t\tSystem.err.println(\"Time: \" + ((millis() - t) / 1000.0));\n\t\tSystem.exit(0);\n\t}\n\t\n\tstatic void NO() {\n\t\tthrow new Error(\"NO!\");\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////////////////////\n\t\n\tstatic String build (String delim, Object o, Object... a) {\n\t\tStringBuilder b = new StringBuilder();\n\t\tappend(b, o, delim);\n\t\tfor (Object p : a)\n\t\t\tappend(b, p, delim);\n\t\treturn b.toString().trim();\t\t\n\t}\n\t\n\tstatic void append(StringBuilder b, Object o, String delim) {\n\t\tif (o.getClass().isArray()) {\n\t\t\tint L = Array.getLength(o);\n\t\t\tfor (int i : rep(L))\n\t\t\t\tappend(b, Array.get(o, i), delim);\n\t\t} else if (o instanceof Iterable) {\n\t\t\tfor (Object p : (Iterable)o)\n\t\t\t\tappend(b, p, delim);\n\t\t} else\n\t\t\tb.append(delim).append(o);\t\t\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////////////////////\n\t\n\tstatic void statics() {\n\t\tabs(0);\n\t\tvalueOf(0);\n\t\tasList(new Object [0]);\n\t\treverseOrder();\n\t}\n\t\n\tpublic static void main (String[] args) {\n\t\tnew D();\n\t\texit();\n\t}\n\n\tstatic void start() {\n\t\tt = millis();\n\t}\n\n\tstatic PrintWriter pw = new PrintWriter(System.out, autoflush);\n\t\n\tstatic long t;\n\t\n\tstatic long millis() {\n\t\treturn System.currentTimeMillis();\n\t}\t\n}\n", "lang_cluster": "Java", "tags": ["dp", "bitmasks"], "code_uid": "c63bf281d4e876c6641a10eecec4fbe3", "src_uid": "359f5d1264ce16c5c5293fd59db95628", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "//package com.company;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Main {\n\n public static void main(String[] args) throws IOException {\n InputStreamReader input = new InputStreamReader(System.in);\n BufferedReader in = new BufferedReader(input);\n\n String s = in.readLine();\n String ss[] = s.split(\" \");\n\n int n = Integer.parseInt(ss[0]);\n int k = Integer.parseInt(ss[1]);\n\n String number = in.readLine();\n if (k == 0)\n {\n System.out.println(number);\n }\n else if(n == 1)\n {\n System.out.println(\"0\");\n }\n else\n {\n StringBuffer tmp = new StringBuffer();\n tmp.append(\"1\");\n\n if(number.charAt(0) != '1')\n k--;\n\n int counter = 1;\n while(k > 0 && counter < n)\n {\n if(number.charAt(counter) != '0')\n {\n k--;\n }\n counter++;\n tmp.append(\"0\");\n }\n\n if(counter < n)\n tmp.append(number.substring(counter));\n\n System.out.println(tmp.toString());\n }\n }\n}\n", "lang_cluster": "Java", "tags": ["greedy", "implementation"], "code_uid": "a0422939050a857cb3eea03c26be0df1", "src_uid": "0515ac888937a4dda30cad5e2383164f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author dmytro.prytula\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n DTriFiguri solver = new DTriFiguri();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class DTriFiguri {\n static int N;\n int M = 305;\n int INF = (int) 1e9;\n DTriFiguri.Point[] possibleKnight = new DTriFiguri.Point[]{\n DTriFiguri.Point.of(2, 1),\n DTriFiguri.Point.of(-2, 1),\n DTriFiguri.Point.of(2, -1),\n DTriFiguri.Point.of(-2, -1),\n DTriFiguri.Point.of(1, 2),\n DTriFiguri.Point.of(-1, 2),\n DTriFiguri.Point.of(1, -2),\n DTriFiguri.Point.of(-1, -2)\n };\n DTriFiguri.Point[][] dist = new DTriFiguri.Point[M][M];\n\n {\n\n\n }\n\n private boolean in(DTriFiguri.Point p) {\n return 0 <= p.x && p.x < N && 0 <= p.y && p.y < N;\n }\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n\n N = in.nextInt();\n DTriFiguri.Point[] pos = new DTriFiguri.Point[N * N];\n int[][] A = new int[N][N];\n for (int x = 0; x < N; x++) {\n for (int y = 0; y < N; y++) {\n A[x][y] = in.nextInt() - 1;\n pos[A[x][y]] = DTriFiguri.Point.of(x, y);\n\n }\n }\n\n for (int i = 0; i < M; i++) {\n for (int j = 0; j < M; j++) {\n// Arrays.fill(dist[i], Point.of(INF, INF));\n dist[i][j] = DTriFiguri.Point.of(INF, INF);\n }\n }\n for (int i = 0; i < M; i++)\n// for (int j = 0; j < M; j++)\n// if (i == j)\n dist[i][i] = DTriFiguri.Point.of(0, 0);\n\n\n for (int x = 0; x < N; x++) {\n for (int y = 0; y < N; y++) {\n //knight\n for (int i = 0; i < possibleKnight.length; i++) {\n int nx = x + possibleKnight[i].x;\n int ny = y + possibleKnight[i].y;\n if (in(DTriFiguri.Point.of(nx, ny))) {\n dist[DTriFiguri.Point.hash(x, y, 0)][DTriFiguri.Point.hash(nx, ny, 0)] = DTriFiguri.Point.of(1, 0);\n }\n }\n //bishop\n for (int i = -N + 1; i <= N - 1; i++) {\n int nx = x + i;\n int ny = y + i;\n if (in(DTriFiguri.Point.of(nx, ny)))\n dist[DTriFiguri.Point.hash(x, y, 1)][DTriFiguri.Point.hash(nx, ny, 1)] = DTriFiguri.Point.of(1, 0);\n\n ny = y - i;\n if (in(DTriFiguri.Point.of(nx, ny)))\n dist[DTriFiguri.Point.hash(x, y, 1)][DTriFiguri.Point.hash(nx, ny, 1)] = DTriFiguri.Point.of(1, 0);\n }\n\n //rook\n for (int i = 0; i < N; i++) {\n int nx = i;\n int ny = y;\n// if (in(Point.of(nx, ny)))\n dist[DTriFiguri.Point.hash(x, y, 2)][DTriFiguri.Point.hash(nx, ny, 2)] = DTriFiguri.Point.of(1, 0);\n nx = x;\n ny = i;\n// if (in(Point.of(nx, ny)))\n dist[DTriFiguri.Point.hash(x, y, 2)][DTriFiguri.Point.hash(nx, ny, 2)] = DTriFiguri.Point.of(1, 0);\n\n }\n\n for (int i = 0; i < 3; i++) {\n for (int j = 0; j < 3; j++) {\n if (i != j) {\n dist[DTriFiguri.Point.hash(x, y, i)][DTriFiguri.Point.hash(x, y, j)] = DTriFiguri.Point.of(1, 1);\n }\n }\n }\n\n\n }\n }\n\n for (int k = 0; k < M; k++) {\n for (int i = 0; i < M; i++) {\n for (int j = 0; j < M; j++) {\n dist[i][j] = DTriFiguri.Point.min(dist[i][j], DTriFiguri.Point.sum(dist[i][k], dist[k][j]));\n }\n }\n }\n\n DTriFiguri.Point[][] dp = new DTriFiguri.Point[N * N][3];\n for (int i = 0; i < N * N; i++) {\n for (int j = 0; j < 3; j++) {\n dp[i][j] = DTriFiguri.Point.of(INF, INF);\n }\n }\n\n dp[0][0] = dp[0][1] = dp[0][2] = DTriFiguri.Point.of(0, 0);\n\n\n for (int i = 0; i < N * N - 1; i++)\n for (int j = 0; j < 3; j++)\n for (int k = 0; k < 3; k++)\n dp[i + 1][k] = DTriFiguri.Point.min(\n dp[i + 1][k],\n DTriFiguri.Point.sum(dp[i][j], dist[DTriFiguri.Point.hash(pos[i].x, pos[i].y, j)][DTriFiguri.Point.hash(pos[i + 1].x, pos[i + 1].y, k)])\n );\n\n\n DTriFiguri.Point ans = DTriFiguri.Point.of(INF, INF);\n ans = DTriFiguri.Point.min(ans, dp[N * N - 1][0]);\n ans = DTriFiguri.Point.min(ans, dp[N * N - 1][1]);\n ans = DTriFiguri.Point.min(ans, dp[N * N - 1][2]);\n\n\n out.print(ans.toString());\n }\n\n private static class Point {\n int x;\n int y;\n\n private Point(int x, int y) {\n this.x = x;\n this.y = y;\n }\n\n public static DTriFiguri.Point of(int x, int y) {\n return new DTriFiguri.Point(x, y);\n }\n\n public static int hash(int x, int y, int p) {\n return x * N * 3 + y * 3 + p;\n }\n\n public static DTriFiguri.Point min(DTriFiguri.Point a, DTriFiguri.Point b) {\n if (a.x == b.x) {\n return a.y < b.y ? a : b;\n }\n return a.x < b.x ? a : b;\n }\n\n public static DTriFiguri.Point sum(DTriFiguri.Point point1, DTriFiguri.Point point) {\n return DTriFiguri.Point.of(point1.x + point.x, point1.y + point.y);\n }\n\n public String toString() {\n return x + \" \" + y;\n }\n\n }\n\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String nextToken() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(nextToken());\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["dfs and similar", "dp", "shortest paths"], "code_uid": "67703a4675ba34d0a4940ebf13e267ac", "src_uid": "5fe44b6cd804e0766a0e993eca1846cd", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class LuckyTickets {\n // 2^23*7*17+1\n private static final int MOD = 998244353;\n // ROOT^(2^23)=1 & ROOT^(2^22)!=1\n private static final int ROOT = 15311432;\n private static final int INVROOT = 469870224;\n\n private static int bitReverse(int n, int k) {\n return Integer.reverse(n) >>> (32 - k);\n }\n\n private static long modInv(int a) {\n return modPow(a, MOD - 2);\n }\n\n private static long modPow(int a, int p) {\n if (p == 0) {\n return 1;\n }\n long half = modPow(a, p / 2);\n long ans = (half * half) % MOD;\n if (p % 2 == 1) {\n ans = (ans * a) % MOD;\n }\n return ans;\n }\n\n // my first fft, LETS DO THIS!!\n // coef.length = 2^k\n private static void numberTheoreticTransform(long[] coef, int k, boolean inverse) {\n int baseRoot = inverse ? INVROOT : ROOT;\n long root = modPow(baseRoot, (int) modPow(2, 23 - k));\n long[] roots = new long[k];\n roots[k - 1] = root;\n for (int i = k - 1; i > 0; i--) {\n roots[i - 1] = (roots[i] * roots[i]) % MOD;\n }\n for (int s = 0; s < k; s++) {\n int len = 1 << s;\n for (int st = 0; st < coef.length; st += 2 * len) {\n // combine the vectors starting at st and st + len\n long curRoot = 1;\n for (int j = st; j < st + len; j++) {\n long t = (curRoot * coef[j + len]) % MOD;\n long u = coef[j];\n coef[j] = (u + t) % MOD;\n coef[j + len] = (u - t) % MOD;\n curRoot = (roots[s] * curRoot) % MOD;\n }\n }\n }\n return;\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt() / 2;\n int m = sc.nextInt();\n int[] nums = new int[m];\n for (int i = 0; i < m; i++) {\n nums[i] = sc.nextInt();\n }\n Arrays.sort(nums);\n int min_size = n * nums[m - 1] + 2;\n int k = 0;\n int size = 1;\n while (size < min_size) {\n size *= 2;\n k++;\n }\n long[] a = new long[size];\n for (int i = 0; i < nums.length; i++) {\n a[bitReverse(nums[i], k)] = 1;\n }\n numberTheoreticTransform(a, k, false);\n for (int i = 0; i < size; i++) {\n a[i] = modPow((int) a[i], n);\n }\n long[] temp = new long[size];\n for (int i = 0; i < size; i++) {\n temp[bitReverse(i, k)] = (a[i]) % MOD;\n }\n a = temp;\n numberTheoreticTransform(a, k, true);\n long ans = 0;\n for (int i = 0; i < size; i++) {\n ans = (ans + a[i] * a[i]) % MOD;\n }\n long multiplier = modInv(size);\n System.out.println((((ans * multiplier) % MOD) * multiplier) % MOD);\n }\n}\n", "lang_cluster": "Java", "tags": ["divide and conquer", "dp", "fft"], "code_uid": "1afca2c9f77d6b58561fa8dd1eb0e719", "src_uid": "279f1f7d250a4be6406c6c7bfc818bbf", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "/*\nIf you want to aim high, aim high\nDon't let that studying and grades consume you\nJust live life young\n******************************\nIf I'm the sun, you're the moon\nBecause when I go up, you go down\n*******************************\nI'm working for the day I will surpass you\nhttps://www.a2oj.com/Ladder16.html\n*/\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\n\n public class x1204E\n {\n static long MOD = 998244853L;\n public static void main(String omkar[]) throws Exception\n {\n BufferedReader infile = new BufferedReader(new InputStreamReader(System.in)); \n StringTokenizer st = new StringTokenizer(infile.readLine());\n int N = Integer.parseInt(st.nextToken());\n int M = Integer.parseInt(st.nextToken());\n fac = new long[4001];\n invfac = new long[4001];\n fac[0] = invfac[0] = 1L;\n for(int i=1; i <= 4000; i++)\n {\n fac[i] = (fac[i-1]*i)%MOD;\n invfac[i] = power(fac[i], MOD-2, MOD);\n }\n long[][] zero = new long[N+1][M+1];\n Arrays.fill(zero[0], 1L);\n for(int a=1; a <= N; a++)\n for(int b=a; b <= M; b++)\n zero[a][b] = (zero[a-1][b]+zero[a][b-1])%MOD;\n long[][] dp = new long[N+1][M+1];\n for(int a=0; a <= N; a++)\n dp[a][0] = a;\n for(int a=1; a <= N; a++)\n for(int b=1; b <= M; b++)\n {\n long temp = (dp[a-1][b]+dp[a][b-1])%MOD;\n temp = (temp+cnt(a-1,b)-cnt(a,b-1)+MOD)%MOD;\n dp[a][b] = (temp+zero[a][b-1])%MOD;\n }\n System.out.println(dp[N][M]);\n }\n static long fac[];\n static long invfac[];\n public static long cnt(int a, int b)\n {\n long val = fac[a+b];\n val = (val*invfac[a])%MOD;\n return (val*invfac[b])%MOD;\n }\n public static long power(long x, long y, long p) \n { \n long res = 1L; \n x = x % p; \n while (y > 0) \n { \n if((y & 1)==1) \n res = (res * x) % p; \n y = y >> 1; \n x = (x * x) % p; \n } \n return res; \n } \n }", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics", "number theory"], "code_uid": "4234fe35723e947ce516646bd9ac5046", "src_uid": "a2fcad987e9b2bb3e6395654cd4fcfbb", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "import java.util.Arrays;\r\nimport java.util.Scanner;\r\n\r\npublic class F {\r\n public static void main(String[] args) {\r\n Scanner s = new Scanner(System.in);\r\n\r\n\r\n solve(s.nextInt(), s.nextInt(), s.nextInt(), s.nextInt(), s.nextInt(), s.nextInt());\r\n }\r\n\r\n public static void init(long n, int k) {\r\n pow = new long[k];\r\n pow[0] = 1;\r\n for (int i = 1; i < k; i++) {\r\n pow[i] = (n * pow[i - 1]) % mod;\r\n }\r\n }\r\n\r\n\r\n static long mod = 998244353;\r\n static long[] pow;\r\n public static void solve(int n, long a, long x, long y, int k, long M) {\r\n init(n, k);\r\n\r\n int gcdR = gcdRange(k - 1);\r\n\r\n long[][] r = new long[gcdR][k + 1];\r\n\r\n for (int i = 1; i <= k; i++) {\r\n for (int j = 0; j < gcdR; j++) {\r\n int jump = j - (j % (k + 1 - i));\r\n r[j][i] = (((n - 1) * r[j][i - 1]) + (r[jump][i - 1] + j * pow[i - 1])) % mod;\r\n }\r\n }\r\n\r\n long sum = 0;\r\n for (int i = 0; i < n; i++) {\r\n sum += r[(int)(a % gcdR)][k] + ((((a / gcdR) * gcdR * k) % mod) * pow[k - 1]) % mod;\r\n sum %= mod;\r\n a = (a * x + y) % M;\r\n }\r\n\r\n System.out.println(sum);\r\n }\r\n\r\n\r\n public static int gcdRange(long n) {\r\n int gcd = 1;\r\n for (int i = 1; i <= n; i++) gcd = (int) gcd(gcd, i);\r\n return gcd;\r\n }\r\n\r\n public static long gcd(long a, long b) {\r\n return a * b / ggt(a, b);\r\n }\r\n\r\n public static long ggt(long a, long b) {\r\n if (a < b) return ggt(b, a);\r\n if (b == 0) return a;\r\n return ggt(b, a % b);\r\n }\r\n}\r\n", "lang_cluster": "Java", "tags": ["math", "dp", "combinatorics", "probabilities", "number theory"], "code_uid": "b0ef8a5dc656dbb2fe20009e86f5ba33", "src_uid": "1d45491e28d24e2b318605cd328d6ecf", "difficulty": 2800.0, "exec_outcome": "PASSED"} {"lang": "Java 8", "source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.UncheckedIOException;\nimport java.io.Closeable;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, new TaskAdapter(), \"\", 1 << 27);\n thread.start();\n thread.join();\n }\n\n static class TaskAdapter implements Runnable {\n @Override\n public void run() {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastInput in = new FastInput(inputStream);\n FastOutput out = new FastOutput(outputStream);\n G2PlaylistForPolycarpHardVersion solver = new G2PlaylistForPolycarpHardVersion();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class G2PlaylistForPolycarpHardVersion {\n Modular mod = new Modular(1e9 + 7);\n\n public void solve(int testNumber, FastInput in, FastOutput out) {\n int n = in.readInt();\n int m = in.readInt();\n int[][] musics = new int[n][2];\n int[] cnts = new int[4];\n for (int i = 0; i < n; i++) {\n musics[i][0] = in.readInt();\n musics[i][1] = in.readInt();\n cnts[musics[i][1]]++;\n }\n\n int c1 = cnts[1];\n int c2 = cnts[2];\n int c3 = cnts[3];\n\n int[][][][] comp = new int[c1 + 1][c2 + 1][c3 + 1][4];\n for (int i = 0; i <= c1; i++) {\n for (int j = 0; j <= c2; j++) {\n for (int k = 0; k <= c3; k++) {\n for (int t = 0; t < 4; t++) {\n if (i == 0 && j == 0 && k == 0) {\n comp[i][j][k][t] = 1;\n continue;\n }\n if (i > 0 && t != 1) {\n comp[i][j][k][t] = mod.plus(comp[i][j][k][t], mod.mul(comp[i - 1][j][k][1], i));\n }\n if (j > 0 && t != 2) {\n comp[i][j][k][t] = mod.plus(comp[i][j][k][t], mod.mul(comp[i][j - 1][k][2], j));\n }\n if (k > 0 && t != 3) {\n comp[i][j][k][t] = mod.plus(comp[i][j][k][t], mod.mul(comp[i][j][k - 1][3], k));\n }\n }\n }\n }\n }\n\n int[][][][] last = new int[c1 + 1][c2 + 1][c3 + 1][m + 1];\n int[][][][] next = new int[c1 + 1][c2 + 1][c3 + 1][m + 1];\n\n last[0][0][0][0] = 1;\n int t1 = 0;\n int t2 = 0;\n int t3 = 0;\n for (int[] music : musics) {\n int m1 = music[1];\n int m0 = music[0];\n if (m1 == 1) {\n t1++;\n } else if (m1 == 2) {\n t2++;\n } else {\n t3++;\n }\n for (int i = 0; i <= t1; i++) {\n for (int j = 0; j <= t2; j++) {\n for (int k = 0; k <= t3; k++) {\n for (int t = 0; t <= m; t++) {\n next[i][j][k][t] = last[i][j][k][t];\n if (t < m0) {\n continue;\n }\n if (m1 == 1 && i > 0) {\n next[i][j][k][t] = mod.plus(next[i][j][k][t], last[i - 1][j][k][t - m0]);\n } else if (m1 == 2 && j > 0) {\n next[i][j][k][t] = mod.plus(next[i][j][k][t], last[i][j - 1][k][t - m0]);\n } else if (m1 == 3 && k > 0) {\n next[i][j][k][t] = mod.plus(next[i][j][k][t], last[i][j][k - 1][t - m0]);\n }\n }\n }\n }\n }\n\n int[][][][] tmp = last;\n last = next;\n next = tmp;\n }\n\n int ans = 0;\n for (int i = 0; i <= c1; i++) {\n for (int j = 0; j <= c2; j++) {\n for (int k = 0; k <= c3; k++) {\n ans = mod.plus(ans, mod.mul(last[i][j][k][m], comp[i][j][k][0]));\n }\n }\n }\n\n out.println(ans);\n }\n\n }\n\n static class Modular {\n int m;\n\n public Modular(int m) {\n this.m = m;\n }\n\n public Modular(long m) {\n this.m = (int) m;\n if (this.m != m) {\n throw new IllegalArgumentException();\n }\n }\n\n public Modular(double m) {\n this.m = (int) m;\n if (this.m != m) {\n throw new IllegalArgumentException();\n }\n }\n\n public int valueOf(int x) {\n x %= m;\n if (x < 0) {\n x += m;\n }\n return x;\n }\n\n public int valueOf(long x) {\n x %= m;\n if (x < 0) {\n x += m;\n }\n return (int) x;\n }\n\n public int mul(int x, int y) {\n return valueOf((long) x * y);\n }\n\n public int plus(int x, int y) {\n return valueOf(x + y);\n }\n\n public String toString() {\n return \"mod \" + m;\n }\n\n }\n\n static class FastOutput implements AutoCloseable, Closeable {\n private StringBuilder cache = new StringBuilder(10 << 20);\n private final Writer os;\n\n public FastOutput(Writer os) {\n this.os = os;\n }\n\n public FastOutput(OutputStream os) {\n this(new OutputStreamWriter(os));\n }\n\n public FastOutput println(int c) {\n cache.append(c).append('\\n');\n return this;\n }\n\n public FastOutput flush() {\n try {\n os.append(cache);\n os.flush();\n cache.setLength(0);\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n return this;\n }\n\n public void close() {\n flush();\n try {\n os.close();\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n public String toString() {\n return cache.toString();\n }\n\n }\n\n static class FastInput {\n private final InputStream is;\n private byte[] buf = new byte[1 << 13];\n private int bufLen;\n private int bufOffset;\n private int next;\n\n public FastInput(InputStream is) {\n this.is = is;\n }\n\n private int read() {\n while (bufLen == bufOffset) {\n bufOffset = 0;\n try {\n bufLen = is.read(buf);\n } catch (IOException e) {\n bufLen = -1;\n }\n if (bufLen == -1) {\n return -1;\n }\n }\n return buf[bufOffset++];\n }\n\n public void skipBlank() {\n while (next >= 0 && next <= 32) {\n next = read();\n }\n }\n\n public int readInt() {\n int sign = 1;\n\n skipBlank();\n if (next == '+' || next == '-') {\n sign = next == '+' ? 1 : -1;\n next = read();\n }\n\n int val = 0;\n if (sign == 1) {\n while (next >= '0' && next <= '9') {\n val = val * 10 + next - '0';\n next = read();\n }\n } else {\n while (next >= '0' && next <= '9') {\n val = val * 10 - next + '0';\n next = read();\n }\n }\n\n return val;\n }\n\n }\n}\n\n", "lang_cluster": "Java", "tags": ["dp", "combinatorics"], "code_uid": "4feccd4feffa6bd9bf743fab53e1de25", "src_uid": "ed5f913afe829c65792b54233a256757", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "Java 11", "source_code": "/*\n Author: Anthony Ngene\n Created: 04/10/2020 - 12:56\n*/\n\nimport java.io.*;\nimport java.util.*;\n\npublic class F {\n// checks: 1. edge cases 2. overflow 3. possible errors (e.g 1/0, arr[out]) 4. time/space complexity\n int n;\n int m;\n int[] arr;\n int required;\n HashMap> typeDays;\n void solver() throws IOException {\n n = in.intNext(); m = in.intNext();\n arr = in.nextIntArray(n);\n required = sum(arr);\n typeDays = new HashMap<>();\n for (int i = 0; i < m; i++) {\n int d = in.intNext(), typ = in.intNext();\n if (arr[typ - 1] <= 0) continue;\n if (!typeDays.containsKey(typ)) typeDays.put(typ, new TreeSet<>());\n typeDays.get(typ).add(d);\n }\n\n int lo = required;\n int hi = 2 * required;\n int valid = hi;\n while (lo <= hi) {\n int mid = (lo + hi) / 2;\n if (isEnough(mid)) {\n valid = mid;\n hi = mid - 1;\n } else\n lo = mid + 1;\n }\n out.println(valid);\n }\n\n boolean isEnough(int day) {\n int totalCoin = day;\n int req = required;\n\n int[] ddays = new int[day + 1];\n for (int typ : typeDays.keySet()) {\n Integer lastDay = typeDays.get(typ).floor(day);\n if (lastDay == null) continue;\n ddays[lastDay] += arr[typ - 1];\n }\n// out.println(ddays);\n int removed = 0;\n for (int i = 1; i < day + 1; i++) {\n int coins = i - removed;\n int toRemove = min(coins, ddays[i]);\n removed += toRemove;\n totalCoin -= toRemove;\n req -= toRemove;\n }\n// out.pp(req, totalCoin);\n return req * 2 <= totalCoin;\n }\n\n\n// Generated Code Below:\nprivate static final FastWriter out = new FastWriter();\nprivate static FastScanner in;\nstatic ArrayList[] adj;\nprivate static long e97 = (long)1e9 + 7;\npublic static void main(String[] args) throws IOException {\n in = new FastScanner();\n new F().solver();\n out.close();\n}\n\nstatic class FastWriter {\n private static final int IO_BUFFERS = 128 * 1024;\n private final StringBuilder out;\n public FastWriter() { out = new StringBuilder(IO_BUFFERS); }\n public FastWriter p(Object object) { out.append(object); return this; }\n public FastWriter p(String format, Object... args) { out.append(String.format(format, args)); return this; }\n public FastWriter pp(Object... args) { for (Object ob : args) { out.append(ob).append(\" \"); } out.append(\"\\n\"); return this; }\n public FastWriter pp(int[] args) { for (int ob : args) { out.append(ob).append(\" \"); } out.append(\"\\n\"); return this; }\n public FastWriter pp(long[] args) { for (long ob : args) { out.append(ob).append(\" \"); } out.append(\"\\n\"); return this; }\n public FastWriter pp(char[] args) { for (char ob : args) { out.append(ob).append(\" \"); } out.append(\"\\n\"); return this; }\n public void println(long[] arr) { for(long e: arr) out.append(e).append(\" \"); out.append(\"\\n\"); }\n public void println(int[] arr) { for(int e: arr) out.append(e).append(\" \"); out.append(\"\\n\"); }\n public void println(char[] arr) { for(char e: arr) out.append(e).append(\" \"); out.append(\"\\n\"); }\n public void println(double[] arr) { for(double e: arr) out.append(e).append(\" \"); out.append(\"\\n\"); }\n public void println(boolean[] arr) { for(boolean e: arr) out.append(e).append(\" \"); out.append(\"\\n\"); }\n public void println(T[] arr) { for(T e: arr) out.append(e).append(\" \"); out.append(\"\\n\"); }\n public void println(long[][] arr) { for (long[] row: arr) out.append(Arrays.toString(row)).append(\"\\n\"); }\n public void println(int[][] arr) { for (int[] row: arr) out.append(Arrays.toString(row)).append(\"\\n\"); }\n public void println(char[][] arr) { for (char[] row: arr) out.append(Arrays.toString(row)).append(\"\\n\"); }\n public void println(double[][] arr) { for (double[] row: arr) out.append(Arrays.toString(row)).append(\"\\n\"); }\n public void println(T[][] arr) { for (T[] row: arr) out.append(Arrays.toString(row)).append(\"\\n\"); }\n public FastWriter println(Object object) { out.append(object).append(\"\\n\"); return this; }\n public void toFile(String fileName) throws IOException {\n BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));\n writer.write(out.toString());\n writer.close();\n }\n public void close() throws IOException { System.out.print(out); }\n}\nstatic class FastScanner {\n private InputStream sin = System.in;\n private final byte[] buffer = new byte[1024];\n private int ptr = 0;\n private int buflen = 0;\n public FastScanner(){}\n public FastScanner(String filename) throws FileNotFoundException {\n File file = new File(filename);\n sin = new FileInputStream(file);\n }\n private boolean hasNextByte() {\n if (ptr < buflen) {\n return true;\n }else{\n ptr = 0;\n try {\n buflen = sin.read(buffer);\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (buflen <= 0) {\n return false;\n }\n }\n return true;\n }\n private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}\n private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}\n public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}\n public String next() {\n if (!hasNext()) throw new NoSuchElementException();\n StringBuilder sb = new StringBuilder();\n int b = readByte();\n while(isPrintableChar(b)) {\n sb.appendCodePoint(b);\n b = readByte();\n }\n return sb.toString();\n }\n public long longNext() {\n if (!hasNext()) throw new NoSuchElementException();\n long n = 0;\n boolean minus = false;\n int b = readByte();\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n if (b < '0' || '9' < b) {\n throw new NumberFormatException();\n }\n while(true){\n if ('0' <= b && b <= '9') {\n n *= 10;\n n += b - '0';\n }else if(b == -1 || !isPrintableChar(b) || b == ':'){\n return minus ? -n : n;\n }else{\n throw new NumberFormatException();\n }\n b = readByte();\n }\n }\n public int intNext() {\n long nl = longNext();\n if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();\n return (int) nl;\n }\n public double doubleNext() { return Double.parseDouble(next());}\n public long[] nextLongArray(final int n){\n final long[] a = new long[n];\n for (int i = 0; i < n; i++)\n a[i] = longNext();\n return a;\n }\n public int[] nextIntArray(final int n){\n final int[] a = new int[n];\n for (int i = 0; i < n; i++)\n a[i] = intNext();\n return a;\n }\n public double[] nextDoubleArray(final int n){\n final double[] a = new double[n];\n for (int i = 0; i < n; i++)\n a[i] = doubleNext();\n return a;\n }\n public ArrayList[] getAdj(int n) {\n ArrayList[] adj = new ArrayList[n + 1];\n for (int i = 1; i <= n; i++) adj[i] = new ArrayList<>();\n return adj;\n }\n public ArrayList[] adjacencyList(int nodes, int edges) throws IOException {\n return adjacencyList(nodes, edges, false);\n }\n public ArrayList[] adjacencyList(int nodes, int edges, boolean isDirected) throws IOException {\n adj = getAdj(nodes);\n for (int i = 0; i < edges; i++) {\n int a = intNext(), b = intNext();\n adj[a].add(b);\n if (!isDirected) adj[b].add(a);\n }\n return adj;\n }\n}\nstatic class u {\n public static int upperBound(long[] array, long obj) {\n int l = 0, r = array.length - 1;\n while (r - l >= 0) {\n int c = (l + r) / 2;\n if (obj < array[c]) {\n r = c - 1;\n } else {\n l = c + 1;\n }\n }\n return l;\n }\n public static int upperBound(ArrayList array, long obj) {\n int l = 0, r = array.size() - 1;\n while (r - l >= 0) {\n int c = (l + r) / 2;\n if (obj < array.get(c)) {\n r = c - 1;\n } else {\n l = c + 1;\n }\n }\n return l;\n }\n public static int lowerBound(long[] array, long obj) {\n int l = 0, r = array.length - 1;\n while (r - l >= 0) {\n int c = (l + r) / 2;\n if (obj <= array[c]) {\n r = c - 1;\n } else {\n l = c + 1;\n }\n }\n return l;\n }\n public static int lowerBound(ArrayList array, long obj) {\n int l = 0, r = array.size() - 1;\n while (r - l >= 0) {\n int c = (l + r) / 2;\n if (obj <= array.get(c)) {\n r = c - 1;\n } else {\n l = c + 1;\n }\n }\n return l;\n }\n static T[][] deepCopy(T[][] matrix) { return Arrays.stream(matrix).map(el -> el.clone()).toArray($ -> matrix.clone()); }\n static int[][] deepCopy(int[][] matrix) { return Arrays.stream(matrix).map(int[]::clone).toArray($ -> matrix.clone()); }\n static long[][] deepCopy(long[][] matrix) { return Arrays.stream(matrix).map(long[]::clone).toArray($ -> matrix.clone()); }\n private static void sort(int[][] arr){ Arrays.sort(arr, Comparator.comparingDouble(o -> o[0])); }\n private static void sort(long[][] arr){ Arrays.sort(arr, Comparator.comparingDouble(o -> o[0])); }\n private static void rSort(T[] arr) { Arrays.sort(arr, Collections.reverseOrder()); }\n private static void customSort(int[][] arr) {\n Arrays.sort(arr, new Comparator() {\n public int compare(int[] a, int[] b) {\n if (a[0] == b[0]) return Integer.compare(a[1], b[1]);\n return Integer.compare(a[0], b[0]);\n }\n });\n }\n public static int[] swap(int[] arr, int left, int right) {\n int temp = arr[left];\n arr[left] = arr[right];\n arr[right] = temp;\n return arr;\n }\n public static char[] swap(char[] arr, int left, int right) {\n char temp = arr[left];\n arr[left] = arr[right];\n arr[right] = temp;\n return arr;\n }\n public static int[] reverse(int[] arr, int left, int right) {\n while (left < right) {\n int temp = arr[left];\n arr[left++] = arr[right];\n arr[right--] = temp;\n }\n return arr;\n }\n public static boolean findNextPermutation(int[] data) {\n if (data.length <= 1) return false;\n int last = data.length - 2;\n while (last >= 0) {\n if (data[last] < data[last + 1]) break;\n last--;\n }\n if (last < 0) return false;\n int nextGreater = data.length - 1;\n for (int i = data.length - 1; i > last; i--) {\n if (data[i] > data[last]) {\n nextGreater = i;\n break;\n }\n }\n data = swap(data, nextGreater, last);\n data = reverse(data, last + 1, data.length - 1);\n return true;\n }\n public static int biSearch(int[] dt, int target){\n int left=0, right=dt.length-1;\n int mid=-1;\n while(left<=right){\n mid = (right+left)/2;\n if(dt[mid] == target) return mid;\n if(dt[mid] < target) left=mid+1;\n else right=mid-1;\n }\n return -1;\n }\n public static int biSearchMax(long[] dt, long target){\n int left=-1, right=dt.length;\n int mid=-1;\n\n while((right-left)>1){\n mid = left + (right-left)/2;\n if(dt[mid] <= target) left=mid;\n else right=mid;\n }\n return left;\n }\n public static int biSearchMaxAL(ArrayList dt, long target){\n int left=-1, right=dt.size();\n int mid=-1;\n\n while((right-left)>1){\n mid = left + (right-left)/2;\n if(dt.get(mid) <= target) left=mid;\n else right=mid;\n }\n return left;\n }\n private static void fill(T[][] ob, T res){for(int i=0;ivoid fill(T[][][] ob,T res){for(int i=0;i0; i--){ ans*=i; }\n return ans;\n }\n private static long facMod(int n, long mod) {\n long ans=1;\n for(long i=n; i>0; i--) ans = (ans * i) % mod;\n return ans;\n }\n private static long lcm(long m, long n){\n long ans = m/gcd(m,n);\n ans *= n;\n return ans;\n }\n private static long gcd(long m, long n) {\n if(m < n) return gcd(n, m);\n if(n == 0) return m;\n return gcd(n, m % n);\n }\n private static boolean isPrime(long a){\n if(a==1) return false;\n for(int i=2; i<=Math.sqrt(a); i++){ if(a%i == 0) return false; }\n return true;\n }\n static long modInverse(long a, long mod) {\n /* Fermat's little theorem: a^(MOD-1) => 1\n Therefore (divide both sides by a): a^(MOD-2) => a^(-1) */\n return binpowMod(a, mod - 2, mod);\n }\n static long binpowMod(long a, long b, long mod) {\n long res = 1;\n while (b > 0) {\n if (b % 2 == 1) res = (res * a) % mod;\n a = (a * a) % mod;\n b /= 2;\n }\n return res;\n }\n private static int getDigit2(long num){\n long cf = 1; int d=0;\n while(num >= cf){ d++; cf = 1<= cf){ d++; cf*=10; }\n return d;\n }\n private static boolean isInArea(int y, int x, int h, int w){\n if(y<0) return false;\n if(x<0) return false;\n if(y>=h) return false;\n if(x>=w) return false;\n return true;\n }\n private static ArrayList generatePrimes(int n) {\n int[] lp = new int[n + 1];\n ArrayList pr = new ArrayList<>();\n for (int i = 2; i <= n; ++i) {\n if (lp[i] == 0) {\n lp[i] = i;\n pr.add(i);\n }\n for (int j = 0; j < pr.size() && pr.get(j) <= lp[i] && i * pr.get(j) <= n; ++j) {\n lp[i * pr.get(j)] = pr.get(j);\n }\n }\n return pr;\n }\n static long nPrMod(int n, int r, long MOD) {\n long res = 1;\n for (int i = (n - r + 1); i <= n; i++) {\n res = (res * i) % MOD;\n }\n return res;\n }\n static long nCr(int n, int r) {\n if (r > (n - r))\n r = n - r;\n long ans = 1;\n for (int i = 1; i <= r; i++) {\n ans *= n;\n ans /= i;\n n--;\n }\n return ans;\n }\n static long nCrMod(int n, int r, long MOD) {\n long rFactorial = nPrMod(r, r, MOD);\n long first = nPrMod(n, r, MOD);\n long second = binpowMod(rFactorial, MOD-2, MOD);\n return (first * second) % MOD;\n }\n static void printBitRepr(int n) {\n StringBuilder res = new StringBuilder();\n for (int i = 0; i < 32; i++) {\n int mask = (1 << i);\n res.append((mask & n) == 0 ? \"0\" : \"1\");\n }\n out.println(res);\n }\n static String bitString(int n) {return Integer.toBinaryString(n);}\n static int setKthBitToOne(int n, int k) { return (n | (1 << k)); } // zero indexed\n static int setKthBitToZero(int n, int k) { return (n & ~(1 << k)); }\n static int invertKthBit(int n, int k) { return (n ^ (1 << k)); }\n static boolean isPowerOfTwo(int n) { return (n & (n - 1)) == 0; }\n static HashMap counts(String word) {\n HashMap counts = new HashMap<>();\n for (int i = 0; i < word.length(); i++) counts.merge(word.charAt(i), 1, Integer::sum);\n return counts;\n }\n static HashMap counts(int[] arr) {\n HashMap counts = new HashMap<>();\n for (int value : arr) counts.merge(value, 1, Integer::sum);\n return counts;\n }\n static HashMap counts(long[] arr) {\n HashMap counts = new HashMap<>();\n for (long l : arr) counts.merge(l, 1, Integer::sum);\n return counts;\n }\n static HashMap counts(char[] arr) {\n HashMap counts = new HashMap<>();\n for (char c : arr) counts.merge(c, 1, Integer::sum);\n return counts;\n }\n static long hash(int x, int y) {\n return x* 1_000_000_000L +y;\n }\n static final Random random = new Random();\n static void sort(int[] a) {\n int n = a.length;// shuffle, then sort\n for (int i = 0; i < n; i++) {\n int oi = random.nextInt(n), temp = a[oi];\n a[oi] = a[i];\n a[i] = temp;\n }\n Arrays.sort(a);\n }\n static void sort(long[] arr) {\n shuffleArray(arr);\n Arrays.sort(arr);\n }\n static void shuffleArray(long[] arr) {\n int n = arr.length;\n for(int i=0; i {\n int a;\n int b;\n int c;\n public Tuple(int a, int b) {\n this.a = a;\n this.b = b;\n this.c = 0;\n }\n public Tuple(int a, int b, int c) {\n this.a = a;\n this.b = b;\n this.c = c;\n }\n public int getA() { return a; }\n public int getB() { return b; }\n public int getC() { return c; }\n public int compareTo(Tuple other) {\n if (this.a == other.a) {\n if (this.b == other.b) return Long.compare(this.c, other.c);\n return Long.compare(this.b, other.b);\n }\n return Long.compare(this.a, other.a);\n }\n @Override\n public int hashCode() { return Arrays.deepHashCode(new Integer[]{a, b, c}); }\n @Override\n public boolean equals(Object o) {\n if (!(o instanceof Tuple)) return false;\n Tuple pairo = (Tuple) o;\n return (this.a == pairo.a && this.b == pairo.b && this.c == pairo.c);\n }\n @Override\n public String toString() { return String.format(\"(%d %d %d) \", this.a, this.b, this.c); }\n}\nprivate static int abs(int a){ return (a>=0) ? a: -a; }\nprivate static int min(int... ins){ int min = ins[0]; for(int i=1; i max) max = ins[i]; } return max; }\nprivate static int sum(int... ins){ int total = 0; for (int v : ins) { total += v; } return total; }\nprivate static long abs(long a){ return (a>=0) ? a: -a; }\nprivate static long min(long... ins){ long min = ins[0]; for(int i=1; i max) max = ins[i]; } return max; }\nprivate static long sum(long... ins){ long total = 0; for (long v : ins) { total += v; } return total; }\nprivate static double abs(double a){ return (a>=0) ? a: -a; }\nprivate static double min(double... ins){ double min = ins[0]; for(int i=1; i max) max = ins[i]; } return max; }\nprivate static double sum(double... ins){ double total = 0; for (double v : ins) { total += v; } return total; }\n\n}\n", "lang_cluster": "Java", "tags": ["greedy", "binary search"], "code_uid": "258f7a3ddf1d43ec0b7e14c602788767", "src_uid": "2eb101dcfcc487fe6e44c9b4c0e4024d", "difficulty": 2000.0, "exec_outcome": "PASSED"}