{"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 esteban\n */\npublic class Codeforces_131A {\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 String c= sc.next();\n String [] parts= c.split(\"\");\n int f=-1;\n int d=1;\n for (int i = 0; i < parts.length; i++) {\n \n \n if(parts[0].equals(parts[0].toUpperCase()) && i==0){ // si la primera letra es mayuscula\n f=1;\n }else if (parts[0].equals(parts[0].toLowerCase()) && i==0){ // si la segunda letra es minuscula\n f=2;\n }\n \n if(parts[i].equals(parts[i].toLowerCase()) && i!=0){\n d=-1;\n \n }\n }\n \n \n if(f==1 && d==1){\n \n System.out.println(c.toLowerCase());\n }\n \n else if(f==2 && d==1){\n for (int i = 0; i < parts.length; i++) {\n if(i==0)System.out.print(parts[0].toUpperCase());\n else System.out.print(parts[i].toLowerCase());\n }\n System.out.println(\" \");\n }else if(c.length()!=1 && d!=1){\n \n System.out.println(c);\n }else if(c.length()==1){\n System.out.println(c.toUpperCase()); \n \n }\n \n }\n \n}\n", "src_uid": "db0eb44d8cd8f293da407ba3adee10cf"} {"source_code": "import java.util.*;\n\npublic class Solution {\n public static void main(String[] args) {\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n System.out.println(2 * n * (n - 1) + 1 );\n }\n\n\n }\n", "src_uid": "758d342c1badde6d0b4db81285be780c"} {"source_code": "import java.util.Scanner;\n\n\npublic class D {\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 m = sc.nextInt();\n int vx = sc.nextInt();\n int vy = sc.nextInt();\n int vz = sc.nextInt();\n double time = (double)m/(-vy);\n double dz = time*vz, dx = Math.abs(time*vx);\n double x0 = 0, z0 = 0;\n if (vx==0)\n x0 = a/2.0;\n else {\n if (vx > 0) {\n for (int i = 0; ; i += 2) {\n if (dx >= (2*i-1)*a/2.0 && dx <= (2*i+1)*a/2.0) {\n x0 = dx-(2*i-1)*a/2.0;\n break;\n }\n if (dx >= (2*i+1)*a/2.0 && dx <= (2*i+3)*a/2.0) {\n x0 = a-(dx-(2*i+1)*a/2.0);\n break;\n }\n }\n }\n else {\n for (int i = 0; ; i += 2) {\n if (dx >= (2*i-1)*a/2.0 && dx <= (2*i+1)*a/2.0) {\n x0 = a-(dx-(2*i-1)*a/2.0);\n break;\n }\n if (dx >= (2*i+1)*a/2.0 && dx <= (2*i+3)*a/2.0) {\n x0 = dx-(2*i+1)*a/2.0;\n break;\n }\n }\n }\n }\n for (int i = 0; ; i += 2) {\n if (dz >= i*b && dz <= (i+1)*b) {\n z0 = dz-i*b;\n break;\n }\n if (dz >= (i+1)*b && dz <= (i+2)*b) {\n z0 = b-(dz-(i+1)*b);\n break;\n }\n }\n System.out.println(x0+\" \"+z0);\n }\n\n}\n", "src_uid": "84848b8bd92fd2834db1ee9cb0899cff"} {"source_code": "import java.util.Scanner;\n\n\npublic class Main{\n public static void main(String args[])\n {\n \tint n,c;\n \tint p[]=new int[10000];\n \tint t[]=new int[10000];\n \tScanner cin=new Scanner(System.in);\n \tn=cin.nextInt();\n \tc=cin.nextInt();\n \tint ans1=0,ans2=0;\n \tint tsum1=0,tsum2=0;\n \tfor(int i=0;i<n;i++)\n \t{\n \t\tp[i]=cin.nextInt();\n \t}\n \tfor(int i=0;i<n;i++)\n \t{\n \t\tt[i]=cin.nextInt();\n \t}\n \tfor(int i=0;i<n;i++)\n \t{\n \t\ttsum1+=t[i];\n \t\tint M=Max(0,p[i]-c*tsum1);\n \t\tans1+=M;\n \t}\n \tfor(int i=n-1;i>=0;i--)\n \t{\n \t\ttsum2+=t[i];\n \t\tint M=Max(0,p[i]-c*tsum2);\n \t\tans2+=M;\n \t}\n \tif(ans1>ans2)\n \t\tSystem.out.println(\"Limak\");\n \telse if(ans2>ans1)\n \t\tSystem.out.println(\"Radewoosh\");\n \telse \n \t\tSystem.out.println(\"Tie\");\n \t\n }\n public static int Max(int a,int b)\n {\n \tif(a>b)\n \t\treturn a;\n \telse\n \t\treturn b;\n }\n}\n", "src_uid": "8c704de75ab85f9e2c04a926143c8b4a"} {"source_code": "import java.io.IOException;\nimport java.util.ArrayList;\nimport java.util.Scanner;\nimport java.util.Vector;\n\npublic class B {\n static Vector<Integer> primes;\n\n public static void main(String[] args) throws IOException {\n Scanner myScanner = new Scanner(System.in);\n int n = myScanner.nextInt(), nn = n;\n int[] dig = new int[10];\n while (nn > 0) {\n dig[nn % 10] = 1;\n nn /= 10;\n }\n int cnt = 0;\n for (long i = 1; i * i <= n; i++) {\n if (n % i == 0) {\n nn = (int) i;\n while (nn > 0) {\n if (dig[nn % 10] == 1) {\n cnt++;\n break;\n }\n nn /= 10;\n }\n nn = (int) (n / i);\n if (nn != i)\n while (nn > 0) {\n if (dig[nn % 10] == 1) {\n cnt++;\n break;\n }\n nn /= 10;\n }\n }\n }\n System.out.println(cnt);\n\n }\n}\n ", "src_uid": "ada94770281765f54ab264b4a1ef766e"} {"source_code": "import java.util.StringTokenizer;\r\nimport java.io.InputStreamReader;\r\nimport java.lang.reflect.Array;\r\nimport java.io.IOException;\r\nimport java.io.BufferedReader;\r\nimport java.math.BigInteger;\r\nimport java.util.Arrays;\r\nimport java.util.Collections;\r\nimport java.util.ArrayList;\r\n\r\npublic class p4_2\r\n{\r\n\tstatic class FastReader {\r\n\t\tBufferedReader br;\r\n\t\tStringTokenizer st;\r\n\r\n\t\tpublic FastReader()\r\n\t\t{\r\n\t\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\r\n\t\t}\r\n\r\n\t\tString next()\r\n\t\t{\r\n\t\t\t\twhile (st == null || !st.hasMoreElements()) {\r\n\t\t\t\t\t\ttry {\r\n\t\t\t\t\t\t\t\tst = new StringTokenizer(br.readLine());\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcatch (IOException e) {\r\n\t\t\t\t\t\t\t\te.printStackTrace();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\treturn st.nextToken();\r\n\t\t}\r\n\r\n\t\tint nextInt() { return Integer.parseInt(next()); }\r\n\r\n\t\tbyte nextByte() { return Byte.parseByte(next()); }\r\n\r\n\t\tshort nextShort() { return Short.parseShort(next()); }\r\n\r\n\t\tlong nextLong() { return Long.parseLong(next()); }\r\n\r\n\t\tdouble nextDouble()\t{\treturn Double.parseDouble(next());\t}\r\n\r\n\t\tString nextLine()\r\n\t\t{\r\n\t\t\t\tString str = \"\";\r\n\t\t\t\ttry {\r\n\t\t\t\t\t\tstr = br.readLine();\r\n\t\t\t\t}\r\n\t\t\t\tcatch (IOException e) {\r\n\t\t\t\t\t\te.printStackTrace();\r\n\t\t\t\t}\r\n\t\t\t\treturn str;\r\n\t\t}\r\n\t}\r\n\r\n\tpublic static void main(String[] args)\r\n\t{\r\n\t\tFastReader fr=new FastReader();\r\n\r\n\t\tint n=fr.nextInt();\r\n\t\t// int n=100;\r\n\t\tint mod=998244353;\r\n\t\tshort fac[]=new short[1000001];\r\n\t\tfac[1]=-1;\r\n\t\t// int steps=0;\r\n\r\n\t\tfor(int i=2;i<1001;i++)\r\n\t\t{\r\n\t\t\tfor(int j=i*i;j<1000001;j+=i)\r\n\t\t\t{\r\n\t\t\t\tfac[j]+=2;\r\n\t\t\t\t// if(fac[j]>125)\r\n\t\t\t\t// \tSystem.out.println(j+\" \"+i);\r\n\t\t\t\t// steps++;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tfac[i*i]--;\r\n\t\t}\r\n\r\n\t\t// System.out.println(steps);\r\n\t\tint ans=0,sum=0;\r\n\t\tfor(int i=-1;++i<n;)\r\n\t\t{\r\n\t\t\tint f=fac[i+1]+2;\r\n\t\t\tans=sum+f;\r\n\t\t\tans%=mod;\r\n\t\t\tsum+=ans;\r\n\t\t\tsum%=mod;\r\n\t\t}\r\n\t\tSystem.out.println(ans);\r\n\t}\r\n}", "src_uid": "09be46206a151c237dc9912df7e0f057"} {"source_code": "import java.lang.reflect.Array;\nimport java.math.BigInteger;\nimport java.util.*;\n\n\npublic class E {\n\n public static ArrayList<Long> getDividers(long n) {\n ArrayList<Long> result = new ArrayList<Long>();\n for (int i = 2; i <= Math.ceil(Math.sqrt(n)) + 1; ++i) {\n while (n % i == 0) {\n n = n / i;\n result.add((long)i);\n }\n }\n if (n > 1)\n result.add(n);\n\n return result;\n }\n\n public static long f(long a, long b, ArrayList<Long> primes) {\n if (b <= 1)\n return b;\n\n ArrayList<Long> wasPrimes = new ArrayList<Long>();\n\n boolean divides = false;\n long gcd = 1;\n long lastB = b;\n\n for (Long prime : primes) {\n if (b % prime == 0) {\n divides = true;\n b = b / prime;\n wasPrimes.add(prime);\n gcd *= prime;\n }\n }\n if (divides) {\n for (Long prime : wasPrimes)\n primes.remove(prime);\n\n long inResult = f(a / gcd, lastB / gcd - 1, primes) + 1;\n //System.out.println(\"divides\" + gcd + \" \" + a + \" \" + lastB + \" \" + inResult);\n return inResult;\n }\n\n long next = 0;\n for (long prime : primes) {\n long nextDiv = b - b % prime;\n next = Math.max(next, nextDiv);\n }\n\n long result = f(a, next, primes) + b - next;\n //System.out.println(a + \" \" + b + \" \" + result);\n\n return result;\n }\n\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n\n long a = scan.nextLong();\n long b = scan.nextLong();\n\n ArrayList<Long> primes = getDividers(a);\n\n long result = f(a, b, primes);\n\n System.out.println(result);\n }\n\n}\n", "src_uid": "ea92cd905e9725e7fcb87b9ed4f64c2e"} {"source_code": "\n\nimport java.util.*;\n\npublic class A_Beautiful_Matrix {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int[][] a = new int[5][5];\n int x = 0, y = 0,ans=0;\n for (int i = 0; i < 5; i++) {\n for (int j = 0; j < 5; j++) {\n a[i][j] = in.nextInt();\n if (a[i][j] == 1) {\n x = i;\n y = j;\n }\n }\n }\n // System.out.println(\"x=\"+x +\" y=\"+y);\n ans = Math.abs(x-2)+Math.abs(y-2);\n System.out.println(ans);\n }\n\n}\n", "src_uid": "8ba7cedc3f6ae478a0bb3f902440c8e9"} {"source_code": " import java.util.*;\n\n public class B\n {\n public static void main(String[] args)\n {\n new B(new Scanner(System.in));\n }\n \n public B(Scanner in)\n {\n int ma = in.nextInt();\n int mb = in.nextInt();\n int mod = in.nextInt();\n \n\n TreeSet<Integer> ts = new TreeSet<Integer>();\n for (int x=1; x<=ma; x++)\n {\n int rr = (int)((1000000000L*x)%mod);\n if (rr == 0)\n break;\n \n if (rr < (mod-mb))\n {\n System.out.printf(\"1 %09d%n\", x);\n return;\n }\n }\n \n\n System.out.println(\"2\");\n }\n }\n", "src_uid": "8b6f633802293202531264446d33fee5"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class C {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tstatic long[] ONES = new long[17];\n\tstatic {\n\t\tONES[1] = 1;\n\t\tfor (int i = 2; i < 17; i++) {\n\t\t\tONES[i] = 10 * ONES[i - 1] + 1;\n\t\t}\n\t}\n\n\tlong go(long x, int len) {\n\t\tx = Math.abs(x);\n//\t\tSystem.err.println(x + \" \" + len);\n\t\tif (x % ONES[len] == 0) {\n\t\t\treturn x / ONES[len] * len;\n\t\t}\n\t\tlong low = x / ONES[len];\n\t\tlong high = low + 1;\n\n\t\tlong ret1 = low * len + go(x - low * ONES[len], len - 1);\n\t\tlong ret2 = high * len + go(high * ONES[len] - x, len - 1);\n\t\treturn Math.min(ret1, ret2);\n\t}\n\n\tlong solve(long x) {\n\t\treturn go(x, 16);\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\tout.println(solve(nextLong()));\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}", "src_uid": "1b17a7b3b41077843ee1d6e0607720d6"} {"source_code": "import java.util.*;\nimport java.io.*;\n\npublic class codeforces{\n\tpublic static void main(String[] args) throws IOException{\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tString[] s = br.readLine().split(\" \");\n\t\tint a = Integer.parseInt(s[0]);\n\t\tint b = Integer.parseInt(s[1]);\n\t\t\n\t\tint count = a, c2 = 0;\n\t\tint r = 0;\n\t\twhile(a >= b){\n\t\t\tcount += a/b;\n\t\t\tr = a % b;\n\t\t\ta = r + a/b;\n\t\t}\n\t\t\n\t\n\t\tSystem.out.println(count);\n\t\t\n\t}\n}", "src_uid": "a349094584d3fdc6b61e39bffe96dece"} {"source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class E implements Runnable {\n\n\tvoid solve() {\n\t\tint n = nextInt();\n\t\tint t = nextInt();\n\t\tchar[][] c = new char[n][];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tc[i] = nextToken().toCharArray();\n\t\t}\n\t\tint[][] infectTime = new int[n][n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tArrays.fill(infectTime[i], Integer.MAX_VALUE);\n\t\t}\n\t\tQueue<State> q = new ArrayDeque<State>();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tif (c[i][j] == 'Z') {\n\t\t\t\t\tq.add(new State(i, j));\n\t\t\t\t\tinfectTime[i][j] = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twhile (!q.isEmpty()) {\n\t\t\tState state = q.poll();\n\t\t\tfor (int dir = 0; dir < 4; dir++) {\n\t\t\t\tint x = state.x + DX[dir];\n\t\t\t\tint y = state.y + DY[dir];\n\t\t\t\tif (x < 0 || y < 0 || x >= n || y >= n || c[x][y] == 'Y'\n\t\t\t\t\t\t|| infectTime[x][y] != Integer.MAX_VALUE) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tinfectTime[x][y] = infectTime[state.x][state.y] + 1;\n\t\t\t\tq.add(new State(x, y));\n\t\t\t}\n\t\t}\n\t\tint[][][][] dist = new int[n][n][][];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\t// System.err.println(Arrays.toString(infectTime[i]));\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tdist[i][j] = findDists(n, c, i, j, infectTime);\n\t\t\t}\n\t\t}\n\t\tGraph g = new Graph(1 + n * n + n * n + 1);\n\t\tint sink = 1 + 2 * n * n;\n\t\tint shiftCapsule = 1 + n * n;\n\t\tint shiftMen = 1;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tif (c[i][j] != '0' && c[i][j] != 'Y' && c[i][j] != 'Z') {\n\t\t\t\t\tg.addEdge(0, i * n + j + shiftMen, 0, c[i][j] - '0');\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tchar[][] capsule = new char[n][];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tcapsule[i] = nextToken().toCharArray();\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\tif (capsule[i][j] != '0' && capsule[i][j] != 'Y'\n\t\t\t\t\t\t&& capsule[i][j] != 'Z') {\n\t\t\t\t\tg.addEdge(i * n + j + shiftCapsule, sink, 0,\n\t\t\t\t\t\t\tcapsule[i][j] - '0');\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tfor (int k = 0; k < n; k++) {\n\t\t\t\t\tfor (int k2 = 0; k2 < n; k2++) {\n\t\t\t\t\t\tif (dist[i][j][k][k2] <= t) {\n\t\t\t\t\t\t\tg.addEdge(i * n + j + shiftMen, k * n + k2\n\t\t\t\t\t\t\t\t\t+ shiftCapsule, 0, 1 << 20);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t// System.err.println(Arrays.toString(dist[i][j][k]));\n\t\t\t\t}\n\t\t\t\t// System.err.println();\n\t\t\t}\n\t\t}\n\t\tout.println(g.getMaxFlow(0, sink));\n\t}\n\n\tstatic int[][] findDists(int n, char[][] c, int startX, int startY,\n\t\t\tint[][] infectTime) {\n\t\tif (c[startX][startY] == 'Y' || c[startX][startY] == 'Z') {\n\t\t\treturn new int[n][n];\n\t\t}\n\t\tQueue<State> q = new ArrayDeque<State>();\n\t\tint[][] d = new int[n][n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tArrays.fill(d[i], Integer.MAX_VALUE);\n\t\t}\n\t\tq.add(new State(startX, startY));\n\t\td[startX][startY] = 0;\n\t\twhile (!q.isEmpty()) {\n\t\t\tState state = q.poll();\n\t\t\tfor (int dir = 0; dir < 4; dir++) {\n\t\t\t\tint x = state.x + DX[dir];\n\t\t\t\tint y = state.y + DY[dir];\n\t\t\t\tint newD = d[state.x][state.y] + 1;\n\t\t\t\tif (x < 0 || y < 0 || x >= n || y >= n || c[x][y] == 'Y'\n\t\t\t\t\t\t|| c[x][y] == 'Z' || d[x][y] != Integer.MAX_VALUE\n\t\t\t\t\t\t|| newD >= infectTime[x][y]) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\td[x][y] = newD;\n\t\t\t\tq.add(new State(x, y));\n\t\t\t}\n\t\t}\n\t\tint[][] e = new int[n][];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\te[i] = d[i].clone();\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\tif (d[i][j] == Integer.MAX_VALUE) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tfor (int dir = 0; dir < 4; dir++) {\n\t\t\t\t\tint x = i + DX[dir];\n\t\t\t\t\tint y = j + DY[dir];\n\t\t\t\t\tif (x < 0 || y < 0 || x >= n || y >= n || c[x][y] == 'Y'\n\t\t\t\t\t\t\t|| c[x][y] == 'Z') {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif (d[i][j] + 1 == infectTime[x][y]\n\t\t\t\t\t\t\t&& d[i][j] + 1 < e[x][y]) {\n\t\t\t\t\t\te[x][y] = d[i][j] + 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn e;\n\t}\n\n\tstatic int[] DX = { 1, 0, -1, 0 };\n\tstatic int[] DY = { 0, 1, 0, -1 };\n\n\tstatic class State {\n\t\tint x;\n\t\tint y;\n\n\t\tpublic State(int x, int y) {\n\t\t\tsuper();\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\n\t}\n\n\tstatic class Edge {\n\t\tint from;\n\t\tint to;\n\t\tint flow;\n\t\tint cap;\n\t\tEdge rev;\n\n\t\tpublic Edge(int from, int to, int flow, int cap) {\n\t\t\tsuper();\n\t\t\tthis.from = from;\n\t\t\tthis.to = to;\n\t\t\tthis.flow = flow;\n\t\t\tthis.cap = cap;\n\t\t}\n\n\t}\n\n\tstatic class Graph {\n\t\tArrayList<Edge>[] edges;\n\t\tint[] cur;\n\t\tint[] q;\n\t\tint[] d;\n\t\tint n;\n\n\t\tpublic Graph(int n) {\n\t\t\tedges = new ArrayList[n];\n\t\t\tthis.n = n;\n\t\t\tfor (int i = 0; i < edges.length; i++) {\n\t\t\t\tedges[i] = new ArrayList<Edge>();\n\t\t\t}\n\t\t}\n\n\t\tvoid addEdge(int from, int to, int flow, int cap) {\n\t\t\tEdge e1 = new Edge(from, to, flow, cap);\n\t\t\tEdge e2 = new Edge(to, from, -flow, 0);\n\t\t\te1.rev = e2;\n\t\t\te2.rev = e1;\n\t\t\tedges[from].add(e1);\n\t\t\tedges[to].add(e2);\n\t\t}\n\n\t\tboolean bfs(int source, int target) {\n\t\t\tint head = 0;\n\t\t\tint tail = 1;\n\t\t\tArrays.fill(d, Integer.MAX_VALUE);\n\t\t\td[source] = 0;\n\t\t\tq[0] = source;\n\t\t\twhile (head < tail) {\n\t\t\t\tint x = q[head++];\n\t\t\t\tfor (Edge e : edges[x]) {\n\t\t\t\t\tif (e.cap - e.flow > 0 && d[e.to] == Integer.MAX_VALUE) {\n\t\t\t\t\t\td[e.to] = d[x] + 1;\n\t\t\t\t\t\tq[tail++] = e.to;\n\t\t\t\t\t\tif (e.to == target) {\n\t\t\t\t\t\t\treturn true;\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\treturn false;\n\t\t}\n\n\t\tint dfs(int x, int target, int cMin) {\n\t\t\tif (x == target) {\n\t\t\t\treturn cMin;\n\t\t\t}\n\t\t\tfor (int i = cur[x]; i < edges[x].size(); cur[x] = ++i) {\n\t\t\t\tEdge e = edges[x].get(i);\n\t\t\t\tif (d[e.to] != d[x] + 1 || e.cap - e.flow == 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tint add = dfs(e.to, target, Math.min(cMin, e.cap - e.flow));\n\t\t\t\tif (add == 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\te.flow += add;\n\t\t\t\te.rev.flow -= add;\n\t\t\t\treturn add;\n\t\t\t}\n\t\t\treturn 0;\n\t\t}\n\n\t\tlong getMaxFlow(int source, int target) {\n\t\t\tcur = new int[n];\n\t\t\tq = new int[n];\n\t\t\td = new int[n];\n\t\t\tlong flow = 0;\n\t\t\twhile (bfs(source, target)) {\n\t\t\t\tArrays.fill(cur, 0);\n\t\t\t\twhile (true) {\n\t\t\t\t\tint add = dfs(source, target, Integer.MAX_VALUE);\n\t\t\t\t\tif (add == 0) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tflow += add;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn flow;\n\t\t}\n\t}\n\n\tFastScanner sc;\n\tPrintWriter out;\n\n\tpublic void run() {\n\t\tLocale.setDefault(Locale.US);\n\t\ttry {\n\t\t\tsc = new FastScanner(System.in);\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t\tsc.close();\n\t\t\tout.close();\n\t\t} catch (Throwable e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n\n\tint nextInt() {\n\t\treturn sc.nextInt();\n\t}\n\n\tString nextToken() {\n\t\treturn sc.nextToken();\n\t}\n\n\tlong nextLong() {\n\t\treturn sc.nextLong();\n\t}\n\n\tdouble nextDouble() {\n\t\treturn sc.nextDouble();\n\t}\n\n\tBigInteger nextBigInteger() {\n\t\treturn sc.nextBigInteger();\n\t}\n\n\tclass FastScanner extends BufferedReader {\n\t\tStringTokenizer st;\n\t\tboolean eof;\n\t\tString buf;\n\t\tString curLine;\n\t\tboolean createST;\n\n\t\tpublic FastScanner(String fileName) throws FileNotFoundException {\n\t\t\tthis(fileName, true);\n\t\t}\n\n\t\tpublic FastScanner(String fileName, boolean createST)\n\t\t\t\tthrows FileNotFoundException {\n\t\t\tsuper(new FileReader(fileName));\n\t\t\tthis.createST = createST;\n\t\t\tnextToken();\n\t\t}\n\n\t\tpublic FastScanner(InputStream stream) {\n\t\t\tthis(stream, true);\n\t\t}\n\n\t\tpublic FastScanner(InputStream stream, boolean createST) {\n\t\t\tsuper(new InputStreamReader(stream));\n\t\t\tthis.createST = createST;\n\t\t\tnextToken();\n\t\t}\n\n\t\tString nextLine() {\n\t\t\tString ret = curLine;\n\t\t\tif (createST) {\n\t\t\t\tst = null;\n\t\t\t}\n\t\t\tnextToken();\n\t\t\treturn ret;\n\t\t}\n\n\t\tString nextToken() {\n\t\t\tif (!createST) {\n\t\t\t\ttry {\n\t\t\t\t\tcurLine = readLine();\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\teof = true;\n\t\t\t\t}\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tcurLine = readLine();\n\t\t\t\t\tst = new StringTokenizer(curLine);\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\teof = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tString ret = buf;\n\t\t\tbuf = eof ? \"-1\" : st.nextToken();\n\t\t\treturn ret;\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(nextToken());\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(nextToken());\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(nextToken());\n\t\t}\n\n\t\tBigInteger nextBigInteger() {\n\t\t\treturn new BigInteger(nextToken());\n\t\t}\n\n\t\tpublic void close() {\n\t\t\ttry {\n\t\t\t\tbuf = null;\n\t\t\t\tst = null;\n\t\t\t\tcurLine = null;\n\t\t\t\tsuper.close();\n\t\t\t} catch (Exception e) {\n\n\t\t\t}\n\t\t}\n\n\t\tboolean isEOF() {\n\t\t\treturn eof;\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew E().run();\n\t}\n}", "src_uid": "544de9c3729a35eb08c143b1cb9ee085"} {"source_code": "\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main {\n static int [][] M;\n static Scanner sc = new Scanner(System.in);\n static int [][] dp = new int[1001][11];\n static int N;\n \n public static int solve(int n, int i, int d, int a, String s) {\n if(i == N) {\n return d + M[i][3] * (n / M[i][2]);\n }\n if(dp[n][i] != -1) {\n return dp[n][i];\n }\n int r = 0;\n if(M[i][2] <= n && a >= M[i][1]) {\n //System.out.println(i + \" \" + (n - M[i][2]));\n r = solve(n - M[i][2], i, d + M[i][3], a - M[i][1], s + \" \" + i);\n }\n int b = solve(n, i + 1, d, M[i + 1][0], s);\n r = Math.max(r, b);\n //System.out.println(s);\n dp[n][i] = r;\n return r;\n }\n\n public static int r() {\n return sc.nextInt();\n }\n\n \n public static void main(String [] args) {\n int n = r(), m = r(), c0 = r(), d0 = r();\n M = new int[m + 1][4];\n for(int i = 1; i <= m; i++) {\n M[i][0] = r(); M[i][1] = r(); M[i][2] = r(); M[i][3] = r();\n }\n dp = new int[n + 1][m + 1];\n for(int i = 0; i <= n; i++) {\n Arrays.fill(dp[i], 0);\n }\n for(int i = 1; i <= n; i++) {\n for(int j = 1; j <= m; j++) {\n int K = M[j][0] / M[j][1];\n K = Math.min(K, i / M[j][2]);\n for(int k = 0; k <= K; k++) {\n //System.out.println(M[j][3]);\n dp[i][j] = Math.max(dp[i][j], M[j][3] * k + dp[i - M[j][2] * k][j-1]);\n }\n }\n }\n int max = 0;\n for(int i = 0; i <= n; i++) {\n max = Math.max(max, dp[i][m] + ((n-i)/c0)*d0);\n }\n System.out.println(max);\n //System.out.println(solve(n, 0, 0, M[0][0], \"\"));\n }\n}\n", "src_uid": "4e166b8b44427b1227e0f811161d3a6f"} {"source_code": "// -*- coding: utf-8 -*-\n//import java.awt.*;\nimport java.io.*;\nimport java.math.*;\nimport java.text.*;\nimport java.util.*;\n\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream;\n if (args.length > 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 TaskE solver = new TaskE();\n solver.solve(1, in, out);\n out.close();\n }\n \n static class TaskE { \n int n;\n int[] color, r, b, cr, cb;\n int[][][] state;\n \n void solve(int testNumber, InputReader in, PrintWriter out) {\n n = in.nextInt();\n color = new int[n];\n r = new int[n];\n b = new int[n];\n int base = 0; // count of obligatory token-collecting turns\n int needred = 0; // count of obligatory red tokens to collect\n int needblue = 0; // count of obligatory blue tokens to collect\n for (int i = 0; i < n; ++i) {\n color[i] = in.next().charAt(0) == 'R' ? 0 : 1;\n r[i] = in.nextInt();\n b[i] = in.nextInt();\n needred += Math.max(0, r[i] - n);\n needblue += Math.max(0, b[i] - n);\n r[i] = Math.min(n, r[i]);\n b[i] = Math.min(n, b[i]);\n }\n base = Math.max(needred, needblue);\n cr = new int[1 << n]; // count of red cards after completing a given set S of cards\n cb = new int[1 << n]; // count of blue cards after completing a given set S of cards;\n for (int i = 1; i < 1 << n; ++i) {\n cr[i] = cr[i ^ (i & -i)];\n cb[i] = cb[i ^ (i & -i)];\n cr[i] += color[Integer.numberOfTrailingZeros(i & -i)] ^ 1;\n cb[i] += color[Integer.numberOfTrailingZeros(i & -i)];\n }\n state = new int[2][n * n + 1][1 << n];\n for (int[][] i : state) {\n for (int[] j : i) {\n Arrays.fill(j, -1);\n }\n }\n int ans = base + (needred < needblue ? go(0, 0, Math.min(n * n, needblue - needred)) : go(0, 1, Math.min(n * n, needred - needblue))) + n;\n out.println(ans);\n }\n \n int go(int mask, int redempty, int other) {\n if (mask == (1 << n) - 1) {\n return 0;\n }\n if (state[redempty][other][mask] != -1) {\n return state[redempty][other][mask];\n }\n int ret = Integer.MAX_VALUE / 2;\n for (int i = 0; i < n; ++i) {\n if ((mask & 1 << i) != 0) {\n continue;\n }\n int nextmask = mask | 1 << i;\n int remtokenred = (redempty ^ 1) * other;\n int remtokenblue = redempty * other;\n int cardred = cr[mask];\n int cardblue = cb[mask];\n int nred = Math.max(0, r[i] - (cardred + remtokenred)); // attempt to buy new red tokens saving as much new turns as possible\n int nblue = Math.max(0, b[i] - (cardblue + remtokenblue)); // attempt to buy new blue tokens saving as much new turns as possible\n int needmoves = Math.max(nred, nblue); // turns to do after saves\n int nextred = Math.min(n * n, remtokenred + needmoves - Math.max(0, r[i] - cardred)); // red tokens remaining, with clamping\n int nextblue = Math.min(n * n, remtokenblue + needmoves - Math.max(0, b[i] - cardblue)); // red tokens remaining, with clamping\n if (nextred == 0) {\n ret = Math.min(ret, go(nextmask, 1, nextblue) + needmoves);\n }\n if (nextblue == 0) {\n ret = Math.min(ret, go(nextmask, 0, nextred) + needmoves);\n }\n }\n state[redempty][other][mask] = ret;\n return ret;\n }\n \n int i(long x) {\n return (int) x;\n }\n \n <T> void heapsort(T[] a, int s, int e) {\n Queue<T> 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}", "src_uid": "25a77f2b7cb281ff3c7800a20b3e5969"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class C {\n private FastScanner in;\n private PrintWriter out;\n\n private void solve() {\n int input = in.nextInt();\n while(input%10 == 0){\n \tinput/=10;\n }\n String input2 = input+\"\";\n boolean pal = true;\n for(int i = 0; i<input2.length()/2;i++){\n if(input2.charAt(i)!=input2.charAt(input2.length()-i-1)){\n pal = false; \n break;\n }\n }\n if(pal == true)\n out.println(\"YES\");\n else \n out.println(\"NO\");\n }\n\n private void run() {\n try {\n in = new FastScanner(new File(\"A.in\"));\n out = new PrintWriter(new File(\"A.out\"));\n\n solve();\n\n out.close();\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n\n private void runIO() {\n in = new FastScanner(System.in);\n out = new PrintWriter(System.out);\n\n solve();\n\n out.close();\n }\n\n private class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n FastScanner(File f) {\n try {\n br = new BufferedReader(new FileReader(f));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n\n FastScanner(InputStream f) {\n br = new BufferedReader(new InputStreamReader(f));\n }\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return null;\n st = new StringTokenizer(s);\n }\n return st.nextToken();\n }\n\n boolean hasMoreTokens() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return false;\n st = new StringTokenizer(s);\n }\n return true;\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n\n public static void main(String[] args) {\n new C().runIO();\n }\n}", "src_uid": "d82278932881e3aa997086c909f29051"} {"source_code": "import java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.PrintWriter;\nimport java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\n\nimport javax.xml.bind.ParseConversionEvent;\n\npublic class task {\n\n\tpublic static void main(String[] args) {\n\t\tScanner in=new Scanner(System.in);\n\t\tint vp, vd, t, f, c, ans = 0;\n\t\tvp = in.nextInt();\n\t\tvd = in.nextInt();\n\t\tt = in.nextInt();\n\t\tf = in.nextInt();\n\t\tc = in.nextInt();\n\t\tdouble x = vp * t;\n\t\tdouble T;\n\t\twhile((x < c) && (vp < vd))\n\t\t{\n\t\t\tT = x / (double)(vd - vp);\n\t\t\tx += (double)vp * T;\n\t\t\tif(x < c)\n\t\t\t{\n\t\t\t\tans++;\n\t\t\t\tx += f * vp;\n\t\t\t\tx += T * vp; \n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}\n", "src_uid": "c9c03666278acec35f0e273691fe0fff"} {"source_code": "import java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.OutputStreamWriter;\nimport java.io.IOException;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.util.stream.Stream;\n\n\n/**\n *\n * @author Pradyumn Agrawal coderbond007\n */\npublic class B{\n public static InputStream inputStream = System.in;\n public static FastReader in = new FastReader(inputStream);\n public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n \n public static void main(String[] args)throws java.lang.Exception\n {\n new B().run();\n out.close();\n }\n void run() throws java.lang.Exception\n {\n \tchar[] s = ns().toCharArray();\n \tint n = s.length;\n \tint k = ni();\n \tint ct = 0;\n \tint ans = 0;\n \tfor(int i = n - 1;i >= 0; i--){\n \t\tif(s[i] == '0'){\n \t\t\tct++;\n \t\t} else {\n \t\t\tans++;\n \t\t}\n \t\tif(ct == k){\n \t\t\tbreak;\n \t\t}\n \t}\n \tif(ct == k){\n \t\tout.println(ans);\n \t} else {\n \t\tout.println(n - 1);\n \t}\n }\n private static int ni(){ \n return in.nextInt();\n }\n private static long nl(){\n return in.nextLong();\n }\n private static String ns(){\n return in.nextString();\n }\n private static char nc(){\n return in.nextCharacter();\n }\n private static double nd(){\n return in.nextDouble();\n }\n\n private static char[] ns(int n)\n {\n char[] a = new char[n];\n for(int i=0;i<n;i++) a[i] = nc();\n return a;\n }\n\n private static 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 static 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 static long[] nal(int n)\n {\n long[] a = new long[n];\n for(int i=0;i<n;i++) a[i] = nl();\n return a;\n }\n //private void tr(Object... o) { if(o.length() > 0)System.out.println(Arrays.deepToString(o)); }\n}\n\nclass FastReader{\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 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}", "src_uid": "7a8890417aa48c2b93b559ca118853f9"} {"source_code": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class Main extends PrintWriter {\n final Random rand = new Random(31);\n final int inf = (int) 1e9;\n final long linf = (long) 1e18;\n\n final static String IO = \"_std\";\n\n class Edge {\n int to, f, c, cost;\n\n public Edge(int to, int c, int cost) {\n this.to = to;\n this.c = c;\n this.cost = cost;\n this.f = 0;\n }\n }\n\n List<Edge> edges = new ArrayList<>();\n List<Integer>[] g;\n\n void addEdge(int from, int to, int cap, int cost) {\n g[from].add(edges.size());\n edges.add(new Edge(to, cap, cost));\n g[to].add(edges.size());\n edges.add(new Edge(from, 0, -cost));\n }\n\n class QItem implements Comparable<QItem> {\n int d, id;\n\n public QItem(int d, int id) {\n this.d = d;\n this.id = id;\n }\n\n @Override\n public int compareTo(QItem o) {\n return Integer.compare(d, o.d);\n }\n }\n\n void solve() throws IOException {\n int n = nextInt();\n int m = nextInt();\n int[][] a = new int[n][];\n for (int i = 0; i < n; i++) {\n a[i] = nextIntArray(m);\n }\n\n int s = 0;\n int t = n * m + 1;\n g = createAdjacencyList(n * m + 2);\n int[] dx = new int[] {-1, 1, 0, 0};\n int[] dy = new int[] {0, 0, 1, -1};\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < m; j++) {\n if (((i + j) & 1) == 0) {\n addEdge(0, i * m + j + 1, 1, 0);\n for (int k = 0; k < 4; k++) {\n int x = i + dx[k];\n int y = j + dy[k];\n if (x < 0 || x >= n || y < 0 || y >= m) {\n continue;\n }\n addEdge(i * m + j + 1, x * m + y + 1, 1, a[i][j] == a[x][y] ? 0 : 1);\n }\n } else {\n addEdge(i * m + j + 1, t, 1, 0);\n }\n }\n }\n\n int flow = 0;\n int cost = 0;\n n = n * m + 2;\n int[] d = new int[n];\n int[] p = new int[n];\n int[] phi = new int[n];\n int[] f = new int[n];\n f[s] = inf;\n Queue<QItem> q = new PriorityQueue<>();\n boolean[] done = new boolean[n];\n\n while (true) {\n Arrays.fill(d, inf);\n Arrays.fill(p, -1);\n d[s] = 0;\n Arrays.fill(done, false);\n\n q.add(new QItem(0, s));\n\n while (!q.isEmpty()) {\n int v = q.poll().id;\n if (done[v]) {\n continue;\n }\n done[v] = true;\n for (int i : g[v]) {\n Edge e = edges.get(i);\n if (e.f == e.c) {\n continue;\n }\n int c = d[v] + e.cost + phi[v] - phi[e.to];\n if (d[e.to] > c) {\n d[e.to] = c;\n q.add(new QItem(d[e.to], e.to));\n p[e.to] = i;\n f[e.to] = min(f[v], e.c - e.f);\n }\n }\n }\n\n if (p[t] == -1) {\n break;\n }\n\n int cf = f[t];\n int x = t;\n int cc = 0;\n while (p[x] != -1) {\n Edge e = edges.get(p[x]);\n e.f += cf;\n cc += e.cost;\n e = edges.get(p[x] ^ 1);\n e.f -= cf;\n x = e.to;\n }\n\n flow += cf;\n cost += cf * cc;\n\n for (int i = 0; i < n; i++) {\n if (d[i] != inf) {\n phi[i] += d[i] - d[t];\n }\n }\n }\n\n println(cost);\n }\n\n BufferedReader in;\n StringTokenizer stok;\n\n Main() {\n super(System.out);\n in = new BufferedReader(new InputStreamReader(System.in));\n }\n\n Main(String fileIn, String fileOut) throws IOException {\n super(fileOut);\n in = new BufferedReader(new FileReader(fileIn));\n }\n\n public static void main(String[] args) throws IOException {\n Main main;\n if (\"_std\".equals(IO)) {\n main = new Main();\n } else if (\"_iotxt\".equals(IO)) {\n main = new Main(\"input.txt\", \"output.txt\");\n } else {\n main = new Main(IO + \".in\", IO + \".out\");\n }\n main.solve();\n main.close();\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 int[] nextIntArraySorted(int len) throws IOException {\n int[] a = nextIntArray(len);\n shuffle(a);\n Arrays.sort(a);\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 _ = a[i];\n a[i] = a[x];\n a[x] = _;\n }\n }\n\n void shuffleAndSort(int[] a) {\n shuffle(a);\n Arrays.sort(a);\n }\n\n boolean nextPermutation(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 }\n return false;\n }\n\n <T> List<T>[] createAdjacencyList(int n) {\n List<T>[] res = new List[n];\n for (int i = 0; i < n; i++) {\n res[i] = new ArrayList<>();\n }\n return res;\n }\n\n void println(Object... a) {\n for (int i = 0; i < a.length; i++) {\n if (i != 0) {\n print(\" \");\n }\n print(a[i]);\n }\n println();\n }\n}", "src_uid": "1f0e8bbd5bf4fcdea927fbb505a8949b"} {"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 Bisoye\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n Scanner in = new Scanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n AEatingSoup solver = new AEatingSoup();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class AEatingSoup {\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n int n = in.nextInt(), m = in.nextInt();\n\n out.println(m == 0 ? 1 : Math.min(m, n - m));\n }\n\n }\n}\n\n", "src_uid": "c05d0a9cabe04d8fb48c76d2ce033648"} {"source_code": "import java.util.*;\n\npublic class Solution {\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n = scan.nextInt();\n\t\tint sum = 0;\n\t\tint maxA = 0;\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tint ai = scan.nextInt();\n\t\t\tsum += ai;\n\t\t\tmaxA = Math.max(maxA, ai);\n\t\t}\n\t\tint s = 2*sum;\n\t\tint r = (2*sum)/n + 1;\n\t\tint result = Math.max(maxA, r);\n\t\tSystem.out.println(result);\n\t}\n}", "src_uid": "d215b3541d6d728ad01b166aae64faa2"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class E implements Runnable {\n\n\tfinal long[][] E = { { 1, 0, 0, 0, 0, 0 }, { 0, 1, 0, 0, 0, 0 }, { 0, 0, 1, 0, 0, 0}, { 0, 0, 0, 1, 0, 0 }, { 0, 0, 0, 0, 1, 0 }, { 0, 0, 0, 0, 0, 1 } };\n\t\n\tprivate void solve() throws IOException {\n\t\tlong n = nextLong(), sx = nextLong() - 1, sy = nextLong() - 1;\n\t\tlong dx = ((nextLong() % n) + n) % n, dy = ((nextLong() % n) + n) % n, t = nextLong();\n\t\tlong[][] start = { { sx, sy, dx, dy, 0, 1 } };\n\t\tlong[][] next = { { 2, 1, 1, 1, 0, 0 }, { 1, 2, 1, 1, 0, 0 }, { 1, 0, 1, 0, 0, 0 }, { 0, 1, 0, 1, 0, 0 }, { 1, 1, 1, 1, 1, 0 }, { 2, 2, 2, 2, 1, 1 } };\n\t\tlong[][] end = matrixMultiplication(start, binaryMatrixPower(next, t, n), n);\n\t\tprint(end[0][0] + 1, end[0][1] + 1);\n\t}\n\n\tlong[][] binaryMatrixPower(long[][] a, long pow, long MOD) {\n\t\tif (pow == 0) return E;\n\t\tif ((pow & 1) == 0) {\n\t\t\tlong[][] res = binaryMatrixPower(a, pow >> 1, MOD);\n\t\t\treturn matrixMultiplication(res, res, MOD);\n\t\t} else {\n\t\t\tlong[][] res = binaryMatrixPower(a, pow - 1, MOD);\n\t\t\treturn matrixMultiplication(res, a, MOD);\n\t\t}\n\t}\n\n\tlong[][] matrixMultiplication(long[][] a, long[][] b, long MOD) {\n\t\tint n = a.length, m = a[0].length, q = b.length, p = b[0].length;\n\t\tlong[][] res = new long[n][p];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tfor (int j = 0; j < p; j++)\n\t\t\t\tfor (int k = 0; k < m; k++) {\n\t\t\t\t\tres[i][j] += a[i][k] * b[k][j];\n\t\t\t\t\tres[i][j] %= MOD;\n\t\t\t\t}\n\t\treturn res;\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew E().run();\n\t}\n\n\tBufferedReader reader;\n\tStringTokenizer tokenizer;\n\tPrintWriter writer;\n\n\tpublic 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\twriter.close();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(261);\n\t\t}\n\t}\n\n\tvoid halt() {\n\t\twriter.close();\n\t\tSystem.exit(0);\n\t}\n\n\tvoid print(Object... objects) {\n\t\tfor (int i = 0; i < objects.length; i++) {\n\t\t\tif (i != 0)\n\t\t\t\twriter.print(' ');\n\t\t\twriter.print(objects[i]);\n\t\t}\n\t}\n\n\tvoid println(Object... objects) {\n\t\tprint(objects);\n\t\twriter.println();\n\t}\n\n\tString nextLine() throws IOException {\n\t\treturn reader.readLine();\n\t}\n\n\tString nextToken() throws IOException {\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens())\n\t\t\ttokenizer = new StringTokenizer(nextLine());\n\t\treturn tokenizer.nextToken();\n\t}\n\n\tint nextInt() throws NumberFormatException, IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws NumberFormatException, IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws NumberFormatException, IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}\n", "src_uid": "ee9fa8be2ae05a4e831a4f608c0cc785"} {"source_code": "import java.io.*;\nimport java.util.Scanner;\npublic class gaurav\n{\n\tpublic static void main(String[] args)throws IOException \n\t{\n\t\tint[] A=new int[50];\n\t\tint[] B=new int[50];\n\t\tint[] C=new int[200];\n\t\tint n,L,i=0,j=0,x,count=0;\n\t\tScanner sc=new Scanner(System.in);\n\t\tn=sc.nextInt();\n\t\tL=sc.nextInt();\n\t\tfor(i=0;i<n;i++)\n\t\t{\n\t\t\tx=sc.nextInt();\n\t\t\tC[x]=1;\n\t\t\tC[L+x]=1;\n\t\t}\n/*for(int k:C)\nSystem.out.print(k+\" \");*/\n\t\tfor(j=0;j<n;j++)\n\t\t{\n\t\t\tB[j]=sc.nextInt();\n\t\t}\n/*for(int k:B)\nSystem.out.print(k+\" \");*/\n\t\tx=B[0];\n\t\ti=0;j=0;\n\t\t/*System.out.println(\"i=\"+i);*/\n\t\twhile(i<L)\n\t\t{\n\t\t\t//System.out.println(\"i=\"+i);\n/*System.out.println(\"j=\"+j);\nSystem.out.println(\"x=\"+x);\nSystem.out.println(\"n=\"+n);*/\n\t\t\tif((C[i+x]==1) && (count<=n))\n\t\t\t{\n\t\t\t\tcount++;\n\t\t\t\t/*System.out.println(\"count=\"+count);*/\n\t\t\t\tif(count==n)\n\t\t\t\t{\n\t\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\t\tSystem.exit(0);\n\t\t\t\t}\n\n\t\t\t\tx=B[++j];\n\t\t\t\t/*System.out.println(\"x=\"+x);*/\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tcount=0;j=0;x=B[j];\n\t\t\t\ti++;\n\t\t\t}\n\t\t}\n\t\tif(count<n)\n\t\t{\n\t\t\tSystem.out.println(\"NO\");\n\t\t}\n\t}\n}", "src_uid": "3d931684ca11fe6141c6461e85d91d63"} {"source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\n public class Codechef\n{\n static boolean isdistinct(String s){\n Set<Character>set=new HashSet<Character>(); \n for(int i=0;i<s.length();i++){\n set.add(s.charAt(i));\n }\n if(set.size()==s.length())\n return true;\n return false;\n }\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t\t// your code goes here\n\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\tBufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));\n\t\tString s=(br.readLine());\n\t\tint n=Integer.parseInt(s);\n\t\tn++;\n\t\tint f=0;\n\t\twhile(f==0){\n\t\t String s1=n+\" \";\n\t\t if(isdistinct(s1)){\n\t\t bw.write(s1+\"\\n\");\n\t\t \n\t\t break;\n\t\t \n\t\t \n\t\t }\n\t\t n++;\n\t\t}\n\t\tbw.flush();\n\t\n\t\t \n\t}\n}", "src_uid": "d62dabfbec52675b7ed7b582ad133acd"} {"source_code": "\n\nimport java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class elements {\n\t\n\tpublic static HashSet<String> elements;\n\t\n public static void main(String[] args) throws IOException {\n Scanner scan = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n \n elements = new HashSet<String>();\n \n String temp = \"H He Li Be B C N O F Ne Na Mg Al Si P S Cl Ar K Ca Sc Ti V Cr Mn Fe Co Ni Cu Zn Ga Ge As Se Br Kr Rb Sr Y Zr Nb Mo Tc Ru Rh Pd Ag Cd In Sn Sb Te I Xe Cs Ba La Ce Pr Nd Pm Sm Eu Gd Tb Dy Ho Er Tm Yb Lu Hf Ta W Re Os Ir Pt Au Hg Tl Pb Bi Po At Rn Fr Ra Ac Th Pa U Np Pu Am Cm Bk Cf Es Fm Md No Lr Rf Db Sg Bh Hs Mt Ds Rg Cn Nh Fl Mc Lv Ts Og\";\n \n String[] ele = temp.split(\" \");\n \n for (String e : ele) {\n \telements.add(e.toUpperCase());\n }\n \n String s = scan.nextLine();\n //elements.add(\"H\");\n \n if (possible(0, s)) {\n \tSystem.out.println(\"YES\");\n }\n else {\n \tSystem.out.println(\"NO\");\n }\n \n //out.close();\n }\n \n public static boolean possible(int index, String s) {\n \tint n = s.length();\n \t\n \tboolean f = false;\n \t\n \tif (index >= n)\n \t\treturn true;\n \t\n \tString find = \"\" + s.charAt(index);\n \t\n \tif (elements.contains(find)) {\n \t\tf|=possible(index+1, s);\n \t}\n \t\n \tif (index + 1 < n) {\n \t\tfind += s.charAt(index+1);\n \t\tif (elements.contains(find)) {\n \t\t\tf|=possible(index+2, s);\n \t\t}\n \t\tif (index + 2 < n) {\n \t\t\tfind += s.charAt(index+2);\n \t\t\tif (elements.contains(find)) {\n \t\t\t\tf|=possible(index+3, s);\n \t\t\t}\n \t\t}\n \t}\n \t\n \treturn f;\n }\n \n \n \n \n \n \n \n \n}", "src_uid": "d0ad35798119f98320967127c43ae88d"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class Genetic implements Runnable {\n private void solve() throws IOException {\n int n = nextInt();\n int m = nextInt();\n Set<String> all = new HashSet<String>();\n Set<String> finish = new HashSet<String>();\n all.add(\"\");\n int maxLength = 1;\n for (int i = 0; i < m; ++i) {\n String s = nextToken();\n maxLength = Math.max(maxLength, s.length());\n finish.add(s);\n for (int j = 0; j < s.length(); ++j)\n all.add(s.substring(0, j + 1));\n }\n Map<String, Integer> index = new HashMap<String, Integer>();\n int last = 0;\n for (String st : all) {\n index.put(st, last++);\n }\n int[] isFinish = new int[last];\n int[][] next = new int[last][4];\n for (String s : all)\n for (String t : finish)\n if (s.endsWith(t))\n isFinish[index.get(s)] = Math.max(isFinish[index.get(s)], t.length());\n for (String s : all) {\n int start = index.get(s);\n for (int ch = 0; ch < 4; ++ch) {\n String t = s + \"ACGT\".charAt(ch);\n while (!all.contains(t))\n t = t.substring(1);\n next[start][ch] = index.get(t);\n }\n }\n int[][] cnt = new int[last][maxLength];\n cnt[index.get(\"\")][0] = 1;\n for (int len = 0; len < n; ++len) {\n cnt = oneStep(cnt, maxLength, last, isFinish, next);\n }\n int res = 0;\n for (int state = 0; state < last; ++state) {\n res += cnt[state][0];\n if (res >= MODULO)\n res -= MODULO;\n }\n writer.println(res);\n }\n\n static final int MODULO = 1000000009;\n\n private int[][] oneStep(int[][] cnt, int maxLength, int last, int[] finish, int[][] next) {\n int[][] newCnt = new int[last][maxLength];\n for (int oldState = 0; oldState < last; ++oldState)\n for (int oldNeed = 0; oldNeed < maxLength; ++oldNeed) {\n for (int ch = 0; ch < 4; ++ch) {\n int newState = next[oldState][ch];\n int newNeed = oldNeed + 1;\n if (newNeed <= finish[newState])\n newNeed = 0;\n if (newNeed >= maxLength)\n continue;\n newCnt[newState][newNeed] += cnt[oldState][oldNeed];\n if (newCnt[newState][newNeed] >= MODULO) {\n newCnt[newState][newNeed] -= MODULO;\n }\n }\n }\n return newCnt;\n }\n\n public static void main(String[] args) {\n new Genetic().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}\n", "src_uid": "3f053c07deaac55c2c51df6147080340"} {"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 */\npublic class CircleOfNumbers {\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 TaskG solver = new TaskG();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskG {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n String s = in.next();\n int[] primes = new int[100];\n int nprimes = 0;\n int rem = n;\n for (int p = 2; p <= rem; ++p)\n if (rem % p == 0) {\n while (rem % p == 0) rem /= p;\n primes[nprimes++] = p;\n }\n primes = Arrays.copyOf(primes, nprimes);\n int prod = 1;\n for (int x : primes) prod *= x;\n int indep = n / prod;\n long[] a = new long[prod];\n for (int i = 0; i < indep; ++i) {\n for (int j = 0; j < prod; ++j) {\n a[j] = s.charAt(i + j * indep) - '0';\n }\n if (!can(primes, a)) {\n out.println(\"NO\");\n return;\n }\n }\n out.println(\"YES\");\n }\n\n private boolean can(int[] primes, long[] a) {\n long[] b = new long[a.length];\n for (int p : primes) {\n for (int i = 0; i < a.length; ++i) {\n b[i] = a[i] - a[(i + a.length / p) % a.length];\n }\n long[] t = a;\n a = b;\n b = t;\n boolean allzeo = true;\n for (long x : a) if (x != 0) allzeo = false;\n if(allzeo) return true;\n }\n return false;\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}", "src_uid": "63c00c5ea7aee792e8a30dc2c330c3f7"} {"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<String>\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\tint n=in.nextInt();\n\t\t\tint k=in.nextInt();\n\t\t\tString s=in.nextLine();\n\t\t\tchar c[]=s.toCharArray();\n\t\t\tArrays.sort(c);\n\t\t\tint k1=1,m=0,sum=c[0]-'a'+1;\n\t\t\tint j=0;\n\t\t\t\n\t\t\t//pw.println(\"\");\n\t\t\tif(k!=k1)\n\t\t\t{\n\t\t\tfor(int i=1;i<n;i++)\n\t\t\t {\n\t\t\t\tif(c[i]-c[j]>1)\n\t\t\t\t{\n\t\t\t\t\tsum=sum+(c[i]-'a')+1;\n\t\t\t\t\tj=i;\n\t\t\t\t\tk1++;\n\t\t\t\t\tif(k1==k)\n\t\t\t\t\t{\n\t\t\t\t\t\tm=1;\n\t\t\t\t\t\t\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\t//pw.println(sum+\" \"+k1+\" \"+c[i]);\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t\t\n\t\t\t }\n\t\t\t}\n\t\t\tif(k1==k)\n\t\t\t{\n\t\t\t\tpw.print(sum);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tpw.print(-1);\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t \n\t\t\t\n\t\t\n\t\t\t\n\t\t\t\n pw.flush();\n\t\t\tpw.close();\n\t\t\t\n\t}\n\t\t\n}\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t", "src_uid": "56b13d313afef9dc6c6ba2758b5ea313"} {"source_code": "\n\n\nimport java.util.Scanner;\npublic class CodeForce {\n\n\tpublic static void main(String[] args) {\n\t\t\n\t\tScanner input = new Scanner(System.in);\n\t\tString palindrome = input.next();\n\t\t\n\t\tint count=0;\n\t\tint i=0;\n\t\tString asal=\"\";\n\t\tfor(int j=palindrome.length()-1;j>=0;j--)\n\t\t\tasal += palindrome.charAt(j);\n\t\twhile(i<palindrome.length())\n\t\t{\n\t\t\tfor(int j=0;j<asal.length();j++)\n\t\t\t{\n\t\t\t\tif(palindrome.charAt(i)!=asal.charAt(j))\n\t\t\t\t{\n\t\t\t\t\tcount++;\n\t\t\t\t}\n\t\t\t\ti++;\n\t\t\t}\n\t\t}\n\t\tif(count==0&&palindrome.length()%2!=0)\n\t\t\tSystem.out.println(\"YES\");\n\t\telse if(count==1||count/2==1)\n\t\t\tSystem.out.println(\"YES\");\n\t\telse\n\t\t\tSystem.out.println(\"NO\");\n\t\n\t\n\t}\n}\n", "src_uid": "fe74313abcf381f6c5b7b2057adaaa52"} {"source_code": "import java.util.*;\npublic class Main{\npublic static void main(String[] args) {\n\nScanner scn = new Scanner(System.in);\nint n = scn.nextInt();\nint []arr = new int[n];\nlong sum = 0;\nfor(int i=0;i<n;i++){\n arr[i] = scn.nextInt();\n if(arr[i]<0){\n sum+= Math.abs(arr[i]);\n }\n else{\n sum+= arr[i];\n }\n}\nSystem.out.println(sum);\n }\n}", "src_uid": "4b5d14833f9b51bfd336cc0e661243a5"} {"source_code": "import java.io.*;\nimport java.util.NoSuchElementException;\n\n\npublic class Main_1184A1 {\n\n\tprivate static Scanner sc;\n\tprivate static Printer pr;\n\n\tprivate static void solve() {\n\t\tlong r = sc.nextLong();\n\n\t\tif (r < 5 || r % 2 == 0) {\n\t\t\tpr.println(\"NO\");\n\t\t} else {\n\t\t\tpr.printLongs(1, (r - 3) / 2);\n\t\t}\n\t}\n\n\t// ---------------------------------------------------\n\tpublic static void main(String[] args) {\n\t\tsc = new Scanner(System.in);\n\t\tpr = new Printer(System.out);\n\t\t\t\n\t\tsolve();\n\t\t\t\n\t\tpr.close();\n\t\tsc.close();\n\t}\n\n\tstatic class Scanner {\n\t\tBufferedReader br;\n\n\t\tScanner (InputStream in) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(in));\n\t\t}\n\n\t\tprivate boolean isPrintable(int ch) {\n\t\t\treturn ch >= '!' && ch <= '~';\n\t\t}\n\n\t\tprivate boolean isCRLF(int ch) {\n\t\t\treturn ch == '\\n' || ch == '\\r' || ch == -1;\n\t\t}\n\n\t\tprivate int nextPrintable() {\n\t\t\ttry {\n\t\t\t\tint ch;\n\t\t\t\twhile (!isPrintable(ch = br.read())) {\n\t\t\t\t\tif (ch == -1) {\n\t\t\t\t\t\tthrow new NoSuchElementException();\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn ch;\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new NoSuchElementException();\n\t\t\t}\n\t\t}\n\n\t\tString next() {\n\t\t\ttry {\n\t\t\t\tint ch = nextPrintable();\n\t\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\t\tdo {\n\t\t\t\t\tsb.appendCodePoint(ch);\n\t\t\t\t} while (isPrintable(ch = br.read()));\n\n\t\t\t\treturn sb.toString();\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new NoSuchElementException();\n\t\t\t}\n\t\t}\n\n\t\tint nextInt() {\n\t\t\ttry {\n\t\t\t\t// parseInt from Integer.parseInt()\n\t\t\t\tboolean negative = false;\n\t\t\t\tint res = 0;\n\t\t\t\tint limit = -Integer.MAX_VALUE;\n\t\t\t\tint radix = 10;\n\n\t\t\t\tint fc = nextPrintable();\n\t\t\t\tif (fc < '0') {\n\t\t\t\t\tif (fc == '-') {\n\t\t\t\t\t\tnegative = true;\n\t\t\t\t\t\tlimit = Integer.MIN_VALUE;\n\t\t\t\t\t} else if (fc != '+') {\n\t\t\t\t\t\tthrow new NumberFormatException();\n\t\t\t\t\t}\n\t\t\t\t\tfc = br.read();\n\t\t\t\t}\n\t\t\t\tint multmin = limit / radix;\n\n\t\t\t\tint ch = fc;\n\t\t\t\tdo {\n\t\t\t\t\tint digit = ch - '0';\n\t\t\t\t\tif (digit < 0 || digit >= radix) {\n\t\t\t\t\t\tthrow new NumberFormatException();\n\t\t\t\t\t}\n\t\t\t\t\tif (res < multmin) {\n\t\t\t\t\t\tthrow new NumberFormatException();\n\t\t\t\t\t}\n\t\t\t\t\tres *= radix;\n\t\t\t\t\tif (res < limit + digit) {\n\t\t\t\t\t\tthrow new NumberFormatException();\n\t\t\t\t\t}\n\t\t\t\t\tres -= digit;\n\n\t\t\t\t} while (isPrintable(ch = br.read()));\n\n\t\t\t\treturn negative ? res : -res;\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new NoSuchElementException();\n\t\t\t}\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\ttry {\n\t\t\t\t// parseLong from Long.parseLong()\n\t\t\t\tboolean negative = false;\n\t\t\t\tlong res = 0;\n\t\t\t\tlong limit = -Long.MAX_VALUE;\n\t\t\t\tint radix = 10;\n\n\t\t\t\tint fc = nextPrintable();\n\t\t\t\tif (fc < '0') {\n\t\t\t\t\tif (fc == '-') {\n\t\t\t\t\t\tnegative = true;\n\t\t\t\t\t\tlimit = Long.MIN_VALUE;\n\t\t\t\t\t} else if (fc != '+') {\n\t\t\t\t\t\tthrow new NumberFormatException();\n\t\t\t\t\t}\n\t\t\t\t\tfc = br.read();\n\t\t\t\t}\n\t\t\t\tlong multmin = limit / radix;\n\n\t\t\t\tint ch = fc;\n\t\t\t\tdo {\n\t\t\t\t\tint digit = ch - '0';\n\t\t\t\t\tif (digit < 0 || digit >= radix) {\n\t\t\t\t\t\tthrow new NumberFormatException();\n\t\t\t\t\t}\n\t\t\t\t\tif (res < multmin) {\n\t\t\t\t\t\tthrow new NumberFormatException();\n\t\t\t\t\t}\n\t\t\t\t\tres *= radix;\n\t\t\t\t\tif (res < limit + digit) {\n\t\t\t\t\t\tthrow new NumberFormatException();\n\t\t\t\t\t}\n\t\t\t\t\tres -= digit;\n\n\t\t\t\t} while (isPrintable(ch = br.read()));\n\n\t\t\t\treturn negative ? res : -res;\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new NoSuchElementException();\n\t\t\t}\n\t\t}\n\n\t\tfloat nextFloat() {\n\t\t\treturn Float.parseFloat(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\ttry {\n\t\t\t\tint ch;\n\t\t\t\twhile (isCRLF(ch = br.read())) {\n\t\t\t\t\tif (ch == -1) {\n\t\t\t\t\t\tthrow new NoSuchElementException();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\t\tdo {\n\t\t\t\t\tsb.appendCodePoint(ch);\n\t\t\t\t} while (!isCRLF(ch = br.read()));\n\n\t\t\t\treturn sb.toString();\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new NoSuchElementException();\n\t\t\t}\n\t\t}\n\t\t\n\t\tint[] nextIntArray(int n) {\n\t\t\tint[] ret = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tret[i] = sc.nextInt();\n\t\t\t}\n\t\t\t\n\t\t\treturn ret;\n\t\t}\n\n\t\tlong[] nextLongArray(int n) {\n\t\t\tlong[] ret = new long[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tret[i] = sc.nextLong();\n\t\t\t}\n\t\t\t\n\t\t\treturn ret;\n\t\t}\n\n\t\tint[][] nextIntArrays(int n, int m) {\n\t\t\tint[][] ret = new int[m][n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\t\tret[j][i] = sc.nextInt();\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\treturn ret;\n\t\t}\n\n\t\tvoid close() {\n\t\t\ttry {\n\t\t\t\tbr.close();\n\t\t\t} catch (IOException e) {\n//\t\t\t\tthrow new NoSuchElementException();\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic class Printer extends PrintWriter {\n\t\tPrinter(OutputStream out) {\n\t\t\tsuper(out);\n\t\t}\n\t\t\n\t\tvoid printInts(int... a) {\n\t\t\tStringBuilder sb = new StringBuilder(32);\n\t\t\tfor (int i = 0, size = a.length; i < size; i++) {\n\t\t\t\tif (i > 0) {\n\t\t\t\t\tsb.append(' ');\n\t\t\t\t}\n\t\t\t\tsb.append(a[i]);\n\t\t\t}\n\n\t\t\tprintln(sb);\n\t\t}\n\t\t\n\t\tvoid printLongs(long... a) {\n\t\t\tStringBuilder sb = new StringBuilder(64);\n\t\t\tfor (int i = 0, size = a.length; i < size; i++) {\n\t\t\t\tif (i > 0) {\n\t\t\t\t\tsb.append(' ');\n\t\t\t\t}\n\t\t\t\tsb.append(a[i]);\n\t\t\t}\n\n\t\t\tprintln(sb);\n\t\t}\n\t\t\n\t\tvoid printStrings(String... a) {\n\t\t\tStringBuilder sb = new StringBuilder(32);\n\t\t\tfor (int i = 0, size = a.length; i < size; i++) {\n\t\t\t\tif (i > 0) {\n\t\t\t\t\tsb.append(' ');\n\t\t\t\t}\n\t\t\t\tsb.append(a[i]);\n\t\t\t}\n\n\t\t\tprintln(sb);\n\t\t}\n\t}\n}\n", "src_uid": "3ff1c25a1026c90aeb14d148d7fb96ba"} {"source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.lang.reflect.Constructor;\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collection;\nimport java.util.HashMap;\nimport java.util.StringTokenizer;\n\npublic class CodeJ \n{\n\tstatic class Scanner\n\t{\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(\"\");\n\t\t\n\t\tpublic String nextLine()\n\t\t{\n\t\t\ttry\n\t\t\t{\n\t\t\t\treturn br.readLine();\n\t\t\t}\n\t\t\tcatch(Exception e)\n\t\t\t{\n\t\t\t\tthrow(new RuntimeException());\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic String next()\n\t\t{\n\t\t\twhile(!st.hasMoreTokens())\n\t\t\t{\n\t\t\t\tString l = nextLine();\n\t\t\t\tif(l == null)\n\t\t\t\t\treturn null;\n\t\t\t\tst = new StringTokenizer(l);\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\t\n\t\tpublic int nextInt()\n\t\t{\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\t\n\t\tpublic long nextLong()\n\t\t{\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\t\n\t\tpublic double nextDouble()\n\t\t{\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\t\n\t\tpublic int[] nextIntArray(int n)\n\t\t{\n\t\t\tint[] res = new int[n];\n\t\t\tfor(int i = 0; i < res.length; i++)\n\t\t\t\tres[i] = nextInt();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic long[] nextLongArray(int n)\n\t\t{\n\t\t\tlong[] res = new long[n];\n\t\t\tfor(int i = 0; i < res.length; i++)\n\t\t\t\tres[i] = nextLong();\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tpublic double[] nextDoubleArray(int n)\n\t\t{\n\t\t\tdouble[] res = new double[n];\n\t\t\tfor(int i = 0; i < res.length; i++)\n\t\t\t\tres[i] = nextDouble();\n\t\t\treturn res;\n\t\t}\n\t\tpublic void sortIntArray(int[] array)\n\t\t{\n\t\t\tInteger[] vals = new Integer[array.length];\n\t\t\tfor(int i = 0; i < array.length; i++)\n\t\t\t\tvals[i] = array[i];\n\t\t\tArrays.sort(vals);\n\t\t\tfor(int i = 0; i < array.length; i++)\n\t\t\t\tarray[i] = vals[i];\n\t\t}\n\t\t\n\t\tpublic void sortLongArray(long[] array)\n\t\t{\n\t\t\tLong[] vals = new Long[array.length];\n\t\t\tfor(int i = 0; i < array.length; i++)\n\t\t\t\tvals[i] = array[i];\n\t\t\tArrays.sort(vals);\n\t\t\tfor(int i = 0; i < array.length; i++)\n\t\t\t\tarray[i] = vals[i];\n\t\t}\n\t\t\n\t\tpublic void sortDoubleArray(double[] array)\n\t\t{\n\t\t\tDouble[] vals = new Double[array.length];\n\t\t\tfor(int i = 0; i < array.length; i++)\n\t\t\t\tvals[i] = array[i];\n\t\t\tArrays.sort(vals);\n\t\t\tfor(int i = 0; i < array.length; i++)\n\t\t\t\tarray[i] = vals[i];\n\t\t}\n\n\t\tpublic String[] nextStringArray(int n) \n\t\t{\t\n\t\t\tString[] vals = new String[n];\n\t\t\tfor(int i = 0; i < n; i++)\n\t\t\t\tvals[i] = next();\n\t\t\treturn vals;\n\t\t}\n\t\t\n\t\tpublic Integer nextInteger()\n\t\t{\n\t\t\tString s = next();\n\t\t\tif(s == null)\n\t\t\t\treturn null;\n\t\t\treturn Integer.parseInt(s);\n\t\t}\n\t\t\n\t\tpublic int[][] nextIntMatrix(int n, int m)\n\t\t{\n\t\t\tint[][] ans = new int[n][];\n\t\t\tfor(int i = 0; i < n; i++)\n\t\t\t\tans[i] = nextIntArray(m);\n\t\t\treturn ans;\n\t\t}\n\t\t\n\t\tpublic char[][] nextGrid(int r) \n\t\t{\n\t\t\tchar[][] grid = new char[r][];\n\t\t\tfor(int i = 0; i < r; i++)\n\t\t\t\tgrid[i] = next().toCharArray();\n\t\t\treturn grid;\n\t\t}\n\t\t\n\t\tpublic static <T> T fill(T arreglo, int val)\n\t\t{\n\t\t\tif(arreglo instanceof Object[])\n\t\t\t{\n\t\t\t\tObject[] a = (Object[]) arreglo;\n\t\t\t\tfor(Object x : a)\n\t\t\t\t\tfill(x, val);\n\t\t\t}\n\t\t\telse if(arreglo instanceof int[])\n\t\t\t\tArrays.fill((int[]) arreglo, val);\n\t\t\telse if(arreglo instanceof double[])\n\t\t\t\tArrays.fill((double[]) arreglo, val);\n\t\t\telse if(arreglo instanceof long[])\n\t\t\t\tArrays.fill((long[]) arreglo, val);\n\t\t\treturn arreglo;\n\t\t}\n\t\t\n\t\t<T> T[] nextObjectArray(Class <T> clazz, int size)\n\t\t{\n\t\t\t@SuppressWarnings(\"unchecked\")\n\t\t\tT[] result = (T[]) java.lang.reflect.Array.newInstance(clazz, size);\n\t\t\tfor(int c = 0; c < 3; c++)\n\t\t\t{\n\t\t\t\tConstructor <T> constructor;\n\t\t\t\ttry \n\t\t\t\t{\n\t\t\t\t\tif(c == 0)\n\t\t\t\t\t\tconstructor = clazz.getDeclaredConstructor(Scanner.class, Integer.TYPE);\n\t\t\t\t\telse if(c == 1)\n\t\t\t\t\t\tconstructor = clazz.getDeclaredConstructor(Scanner.class);\n\t\t\t\t\telse\n\t\t\t\t\t\tconstructor = clazz.getDeclaredConstructor();\n\t\t\t\t} \n\t\t\t\tcatch(Exception e)\n\t\t\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\ttry\n\t\t\t\t{\n\t\t\t\t\tfor(int i = 0; i < result.length; i++)\n\t\t\t\t\t{\n\t\t\t\t\t\tif(c == 0)\n\t\t\t\t\t\t\tresult[i] = constructor.newInstance(this, i);\n\t\t\t\t\t\telse if(c == 1)\n\t\t\t\t\t\t\tresult[i] = constructor.newInstance(this);\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tresult[i] = constructor.newInstance();\t\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcatch(Exception e)\n\t\t\t\t{\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t\treturn result;\n\t\t\t}\n\t\t\tthrow new RuntimeException(\"Constructor not found\");\n\t\t}\n\t\t\n\t\tpublic void printLine(int... vals)\n\t\t{\n\t\t\tif(vals.length == 0)\n\t\t\t\tSystem.out.println();\n\t\t\telse\n\t\t\t{\n\t\t\t\tSystem.out.print(vals[0]);\n\t\t\t\tfor(int i = 1; i < vals.length; i++)\n\t\t\t\t\tSystem.out.print(\" \".concat(String.valueOf(vals[i])));\n\t\t\t\tSystem.out.println();\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic void printLine(long... vals)\n\t\t{\n\t\t\tif(vals.length == 0)\n\t\t\t\tSystem.out.println();\n\t\t\telse\n\t\t\t{\n\t\t\t\tSystem.out.print(vals[0]);\n\t\t\t\tfor(int i = 1; i < vals.length; i++)\n\t\t\t\t\tSystem.out.print(\" \".concat(String.valueOf(vals[i])));\n\t\t\t\tSystem.out.println();\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic void printLine(double... vals)\n\t\t{\n\t\t\tif(vals.length == 0)\n\t\t\t\tSystem.out.println();\n\t\t\telse\n\t\t\t{\n\t\t\t\tSystem.out.print(vals[0]);\n\t\t\t\tfor(int i = 1; i < vals.length; i++)\n\t\t\t\t\tSystem.out.print(\" \".concat(String.valueOf(vals[i])));\n\t\t\t\tSystem.out.println();\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic void printLine(int prec, double... vals)\n\t\t{\n\t\t\tif(vals.length == 0)\n\t\t\t\tSystem.out.println();\n\t\t\telse\n\t\t\t{\n\t\t\t\tSystem.out.printf(\"%.\" + prec + \"f\", vals[0]);\n\t\t\t\tfor(int i = 1; i < vals.length; i++)\n\t\t\t\t\tSystem.out.printf(\" %.\" + prec + \"f\", vals[i]);\n\t\t\t\tSystem.out.println();\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic Collection <Integer> wrap(int[] as)\n\t\t{\n\t\t\tArrayList <Integer> ans = new ArrayList <Integer> ();\n\t\t\tfor(int i : as)\n\t\t\t\tans.add(i);\n\t\t\treturn ans;\n\t\t}\n\t}\n\t\n\tstatic int k;\n\t\n\t\n\tstatic int distance(long b, long a)\n\t{\n\t\tint[] visited = new int[(int) (b - a + 1)];\n\t\tArrays.fill(visited, Integer.MAX_VALUE);\n\t\tArrayDeque <Long> queue = new ArrayDeque <Long> ();\n\t\tvisited[(int) (b - a)] = 0;\n\t\tqueue.add(b);\n\t\twhile(true)\n\t\t{\n\t\t\tlong head = queue.pollFirst();\n\t\t\tint currentDistance = visited[(int) (head - a)];\n\t\t\tif(head == a) return currentDistance;\n\t\t\tfor(int i = 1; i <= k; i++)\n\t\t\t{\n\t\t\t\tlong mod = head % i;\n\t\t\t\tif(i == 1) mod = 1;\n\t\t\t\tif(mod != 0)\n\t\t\t\t{\n\t\t\t\t\tlong possibleNext = head - mod;\n\t\t\t\t\tif(possibleNext >= a && visited[(int) (possibleNext - a)] == Integer.MAX_VALUE)\n\t\t\t\t\t{\n\t\t\t\t\t\tvisited[(int) (possibleNext - a)] = currentDistance + 1;\n\t\t\t\t\t\tqueue.add(possibleNext);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n\tstatic int gcd(int a, int b)\n\t{\n\t\tif(b == 0) return a;\n\t\telse return gcd(b, a % b);\n\t}\n\t\n\tstatic int lcm(int a, int b)\n\t{\n\t\treturn (a * b) / gcd(a, b);\n\t}\n\t\n\tstatic int lcm(int a, int b, int currentLcm)\n\t{\n\t\tcurrentLcm = lcm(currentLcm, a);\n\t\tif(a == b) return currentLcm;\n\t\treturn lcm(a + 1, b, currentLcm);\n\t}\n\t\n\tpublic static void main(String[] args)\n\t{\n\t\tScanner sc = new Scanner();\n\t\tlong b = sc.nextLong();\n\t\tlong a = sc.nextLong();\n\t\tk = sc.nextInt();\n\t\tlong lcm = lcm(2, k, 1);\n\t\tlong times = (b - a) / lcm;\n\t\tif(times == 0)\n\t\t\tSystem.out.println(distance(b, a));\n\t\telse if(times == 1)\n\t\t\tSystem.out.println(distance(b, b - b % lcm) + distance(b - b % lcm, a));\n\t\telse\n\t\t{\n\t\t\tlong nextA = a / lcm;\n\t\t\tnextA += 1;\n\t\t\tnextA *= lcm;\n\t\t\tlong nextB = b - b % lcm;\n\t\t\ttimes = (nextB - nextA) / lcm;\n\t\t\tSystem.out.println(distance(b, b - b % lcm) + distance(lcm, 0) * times + distance(nextA, a));\n\t\t}\n\t}\n}", "src_uid": "bd599d76c83cc1f30c1349ffb51b4273"} {"source_code": "/* package codechef; // don't place package name! */\n\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Codechef\n{\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{ int i,j,x;\n\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\tString s[]=br.readLine().split(\" \");\n\t\tint n=Integer.parseInt(s[0]);\n\t\tint k=Integer.parseInt(s[1]);\n\t\tlong ans=100000000000l;\n\t\tfor(i=1;i<=Math.sqrt(n)+1;i++)\n\t\t{ if(n%i==0)\n\t\t {\n\t\t int a=n/i;\n\t\t int b=i;\n\t\t if(b<k)\n\t\t ans=Math.min(a*k+b,ans);\n\t\t if(a<k) \n\t\t ans=Math.min(b*k+a,ans);\n\t\t }\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}", "src_uid": "ed0ebc1e484fcaea875355b5b7944c57"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n BufferedReader br;\n PrintWriter out;\n StringTokenizer st;\n boolean eof;\n\n static final int Mod = 1000000007;\n\n void solve() throws IOException {\n int a = nextInt();\n int b = nextInt();\n int c = nextInt();\n int x = nextInt();\n int y = nextInt();\n int z = nextInt();\n int left = 0;\n if (a > x) left += (a - x) / 2;\n if (b > y) left += (b - y) / 2;\n if (c > z) left += (c - z) / 2;\n if (x > a) left -= (x - a);\n if (y > b) left -= (y - b);\n if (z > c) left -= (z - c);\n if (left >= 0) out.println(\"Yes\");\n else out.println(\"No\");\n }\n\n Solution() 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 Solution();\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}", "src_uid": "1db4ba9dc1000e26532bb73336cf12c3"} {"source_code": "import static java.lang.System.in;\nimport static java.lang.System.out;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class C333luckyTickets {\n\tstatic final double EPS = 1e-10;\n\tstatic final double INF = 1 << 31;\n\tstatic final double PI = Math.PI;\n\n\tpublic static Scanner sc = new Scanner(in);\n\tstatic StringBuilder sb = new StringBuilder();\n\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\tArrayList<Set<Integer>> way = new ArrayList<Set<Integer>>();\n\tint d1,d2,d3,d4;\n\tpublic void put(int x){\n\t\tif (x<0) x = 10000-x;\n\t\tway.get(x).add(Math.abs(d1)*1000 + d2*100 + d3*10 + d4);\n\t}\n\n\tpublic void run() throws IOException {\n\t\tString input;\n\t\tString[] inputArray;\n\t\tinput = br.readLine();\n\t\tinputArray = input.split(\" \");\n\n\t\tint k = Integer.valueOf(inputArray[0]);\n\t\tint m = Integer.valueOf(inputArray[1]);\n\t\tfor (int i=0; i<20000; i++)\n\t\t\tway.add(new HashSet<Integer>());\n\t\tint x;\n\t\tfor ( d1 = -9; d1<10; d1++){\n\t\t\tfor ( d2 = 0; d2<10; d2++){\n\t\t\t\tfor ( d3 = 0; d3<10; d3++){\n\t\t\t\t\tfor ( d4 = 0; d4<10; d4++){\n\t\t\t\t\t\tfor (int s1 = 0; s1<3; s1++)\n\t\t\t\t\t\t\tfor (int s2 = 0; s2<3; s2++)\n\t\t\t\t\t\t\t\tfor (int s3 = 0; s3<3; s3++){\n\t\t\t\t\t\t\t\t\tx = op(op(op(d1,s1,d2),s2,d3),s3,d4);\n\t\t\t\t\t\t\t\t\tif (x<0) x = 10000-x;\n\t\t\t\t\t\t\t\t\tway.get(x).add(Math.abs(d1)*1000 + d2*100 + d3*10 + d4);\n\t\t\t\t\t\t\t\t\tx = op(op(d1,s1,d2),s2,op(d3,s3,d4));\n\t\t\t\t\t\t\t\t\tif (x<0) x = 10000-x;\n\t\t\t\t\t\t\t\t\tway.get(x).add(Math.abs(d1)*1000 + d2*100 + d3*10 + d4);\n\t\t\t\t\t\t\t\t\tx = op(op(d1,s1,op(d2,s2,d3)),s3,d4);\n\t\t\t\t\t\t\t\t\tif (x<0) x = 10000-x;\n\t\t\t\t\t\t\t\t\tway.get(x).add(Math.abs(d1)*1000 + d2*100 + d3*10 + d4);\n\t\t\t\t\t\t\t\t\tx = op(d1,s1,op(op(d2,s2,d3),s3,d4));\n\t\t\t\t\t\t\t\t\tif (x<0) x = 10000-x;\n\t\t\t\t\t\t\t\t\tway.get(x).add(Math.abs(d1)*1000 + d2*100 + d3*10 + d4);\n\t\t\t\t\t\t\t\t\tx = op(d1,s1,op(d2,s2,op(d3,s3,d4)));\n\t\t\t\t\t\t\t\t\tif (x<0) x = 10000-x;\n\t\t\t\t\t\t\t\t\tway.get(x).add(Math.abs(d1)*1000 + d2*100 + d3*10 + d4);\n\t\t\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//ln(\"EYS\");\n\t\tfor (int c = 0; c<m;){\n\t\t\tif (k<10000){\n\t\t\t\tfor (int j: way.get(0)){\n\t\t\t\t\tc++;\n\t\t\t\t\tprint(j);\n\t\t\t\t\tprint(k);\n\t\t\t\t\tsb.append(\"\\n\");\n\t\t\t\t\tif (c==m) return;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int i=1; i<k; i++)\n\t\t\t\tfor (int j: way.get(i)){\n\t\t\t\t\tc++;\n\t\t\t\t\tprint(j);\n\t\t\t\t\tprint(k-i);\n\t\t\t\t\tsb.append(\"\\n\");\n\t\t\t\t\tif (c==m) return;\n\t\t\t\t}\n\t\t\tfor (int i=1; k+i<10000; i++)\n\t\t\t\tfor (int j: way.get(10000+i)){\n\t\t\t\t\tc++;\n\t\t\t\t\tprint(j);\n\t\t\t\t\tprint(k+i);\n\t\t\t\t\tsb.append(\"\\n\");\n\t\t\t\t\tif (c==m) return;\n\t\t\t\t}\n\t\t}\n\t}\n\n\tprivate void print(int x) {\n\t\tsb.append(x/1000 + \"\");\n\t\tx%=1000;\n\t\tsb.append(x/100 + \"\");\n\t\tx%=100;\n\t\tsb.append(x/10 + \"\");\n\t\tx%=10;\n\t\tsb.append(x+ \"\");\n\t}\n\n\tprivate int op(int d1, int s1, int d2) {\n\t\tswitch (s1) {\n\t\t\tcase 0 : return d1+d2;\n\t\t\tcase 1 : return d1-d2;\n\t\t\tcase 2 : return d1*d2;\n\t\t\tcase 3 : {\n\t\t\t\tint x=1;\n\t\t\t\tfor (;x<d2; x*=10);\n\t\t\t\treturn d1*x+d2;\n\t\t\t}\n\t\t}\n\t\treturn 0;\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew C333luckyTickets().run();\n\t\tout.print(sb);\n\t}\n\tpublic static void ln(Object obj) {\n\t\tout.println(obj);\n\t}\n\n}\n", "src_uid": "4720ca1d2f4b7a0e553a3ea07a76943c"} {"source_code": "import java.util.Scanner;\n\n\npublic class Main {\n public static void main(String[] args) {\n Scanner input= new Scanner(System.in);\n int n,a=0,b,c;\n String s;\n \n s=input.nextLine();\n n=input.nextInt();\n \n if(null!=s)\n switch (s) {\n case \"February\":\n a=2;\n break;\n case \"January\":\n a = 1;\n break;\n case \"March\":\n a=3;\n break;\n case \"April\":\n a=4;\n break;\n case \"May\":\n a=5;\n break;\n case \"June\":\n a=6;\n break;\n case \"July\":\n a=7;\n break;\n case \"August\":\n a=8;\n break;\n case \"September\":\n a=9;\n break;\n case \"October\":\n a=10;\n break;\n case \"November\":\n a=11;\n break;\n case \"December\":\n a=12;\n break;\n default:\n break;\n }\n\nc=(a+n)%12;\n switch (c) {\n case 1:\n System.out.println(\"January\");\n break;\n case 2:\n System.out.println(\"February\");\n break;\n case 3:\n System.out.println(\"March\");\n break;\n case 4:\n System.out.println(\"April\");\n break;\n case 5:\n System.out.println(\"May\");\n break;\n case 6:\n System.out.println(\"June\");\n break;\n case 7:\n System.out.println(\"July\");\n break;\n case 8:\n System.out.println(\"August\");\n break;\n case 9:\n System.out.println(\"September\");\n break;\n case 10:\n System.out.println(\"October\");\n break;\n case 11:\n System.out.println(\"November\");\n break;\n case 0:\n System.out.println(\"December\");\n break;\n default:\n break;\n }\n}\n \n}", "src_uid": "a307b402b20554ce177a73db07170691"} {"source_code": "\nimport java.io.BufferedReader;\nimport java.io.Closeable;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class CollectiveMindsetsMedium implements Closeable {\n\n private InputReader in = new InputReader(System.in);\n private PrintWriter out = new PrintWriter(System.out);\n\n public void solve() {\n int n = in.ni();\n if (n % 2 == 1) {\n out.println((n - 1) / 2);\n } else {\n int t = 1;\n while (2 * t <= n) {\n t *= 2;\n } \n out.println((n - t) / 2);\n }\n }\n\n @Override\n public void close() throws IOException {\n in.close();\n out.close();\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int ni() {\n return Integer.parseInt(next());\n }\n\n public long nl() {\n return Long.parseLong(next());\n }\n\n public void close() throws IOException {\n reader.close();\n }\n }\n\n public static void main(String[] args) throws IOException {\n try (CollectiveMindsetsMedium instance = new CollectiveMindsetsMedium()) {\n instance.solve();\n }\n }\n}\n", "src_uid": "422abdf2f705c069e540d4f5c09a4948"} {"source_code": "import java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\n\r\npublic class F {\r\n \r\n static int N = 250;\r\n static int M = 28;\r\n static int INF = (int) 1e9;\r\n static int[][][][] dp = new int[2][M * 2 + 1][N][N];\r\n \r\n public static void main(String[] args) throws IOException {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n StringBuilder sb = new StringBuilder(br.readLine());\r\n String s = sb.reverse().append(\"0\").toString(); \r\n \r\n for (int carry = 0; carry < M * 2 + 1; carry++) {\r\n for (int cp = 0; cp < N; cp++) {\r\n for (int cn = 0; cn < N; cn++) {\r\n dp[0][carry][cp][cn] = INF;\r\n }\r\n }\r\n }\r\n dp[0][M][N - 1][N - 1] = 0;\r\n \r\n for (int i = 0; i < s.length(); i++) {\r\n for (int carry = 0; carry < M * 2 + 1; carry++) {\r\n for (int cp = 0; cp < N; cp++) {\r\n for (int cn = 0; cn < N; cn++) {\r\n dp[1][carry][cp][cn] = INF;\r\n }\r\n }\r\n }\r\n for (int carry = 0; carry < M * 2 + 1; carry++) {\r\n for (int cp = N - 1; cp >= 0; cp--) {\r\n for (int cn = N - 1; cn >= 0; cn--) {\r\n if (dp[0][carry][cp][cn] != INF) {\r\n if (cp > 0) {\r\n dp[0][carry][cp - 1][cn] = Math.min(dp[0][carry][cp - 1][cn], dp[0][carry][cp][cn]);\r\n }\r\n if (cn > 0) {\r\n dp[0][carry][cp][cn - 1] = Math.min(dp[0][carry][cp][cn - 1], dp[0][carry][cp][cn]);\r\n }\r\n int rcarry = carry - M;\r\n int val = rcarry + cp - cn;\r\n int digit = val % 10;\r\n if (digit < 0) {\r\n digit += 10;\r\n }\r\n int ncarry = val / 10;\r\n if (val < 0 && digit != 0) {\r\n --ncarry;\r\n }\r\n if (digit == s.charAt(i) - '0') {\r\n dp[1][ncarry + M][cp][cn] = Math.min(dp[1][ncarry + M][cp][cn],\r\n dp[0][carry][cp][cn] + cp + cn);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n int[][][] tmp = dp[0];\r\n dp[0] = dp[1];\r\n dp[1] = tmp;\r\n }\r\n \r\n int ans = INF;\r\n for (int i = 0; i < N; i++) {\r\n for (int j = 0; j < N; j++) {\r\n ans = Math.min(ans, dp[0][M][i][j]);\r\n }\r\n }\r\n System.out.println(ans);\r\n }\r\n \r\n}", "src_uid": "1961e7c9120ff652b15cad5dd5ca0907"} {"source_code": "//package coding2;\n\nimport java.util.Scanner;\n\npublic class A378 {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\t\t\n\t\tScanner sc = new Scanner(System.in);\n\t\tString s = sc.next();\n\t\tint len=-1;\n\t\tint max = Integer.MIN_VALUE;\n\t\tfor(int i=0;i<s.length();i++)\n\t\t{\n\t\t\tif(s.charAt(i)=='A'||s.charAt(i)=='E'||s.charAt(i)=='I'||s.charAt(i)=='O'||s.charAt(i)=='U'||s.charAt(i)=='Y')\n\t\t\t{\n\t\t\t\tlen=i-len;\n\t\t\t\tif(max<len)\n\t\t\t\t\tmax=len;\n\t\t\t\tlen=i;\n\t\t\t}\n\t\t\telse\n\t\t\t\tif(i==s.length()-1)\n\t\t\t\t{\n\t\t\t\t\tlen = i-len+1;\n\t\t\t\t\tif(max<len)\n\t\t\t\t\t\tmax = len;\n\t\t\t\t}\n\t\t\t\n\t\t}\n\t\tif(max<0)\n\t\t\tmax = s.length()+1;\n\t\tSystem.out.println(max);\n\t}\n\n}\n", "src_uid": "1fc7e939cdeb015fe31f3cf1c0982fee"} {"source_code": "import java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.Comparator;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.util.List;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.ArrayList;\nimport java.util.NoSuchElementException;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Egor Kulikov (egor@egork.net)\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tOutputWriter out = new OutputWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n\tstatic final long MOD = 1000000007;\n\n\tlong[][][] result;\n\tlong[][][] resultSmall;\n\tlong[][] c = IntegerUtils.generateBinomialCoefficients(13);\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n\t\tint size = in.readInt();\n\t\tint count = in.readInt();\n\t\tresult = new long[size + 1][count + 1][16];\n\t\tresultSmall = new long[size + 1][count + 1][16];\n\t\tArrayUtils.fill(result, -1);\n\t\tArrayUtils.fill(resultSmall, -1);\n\t\tlong answer = calculate(size, count, 0);\n\t\tanswer *= IntegerUtils.factorial(count, MOD);\n\t\tanswer %= MOD;\n\t\tout.printLine(answer);\n }\n\n\tprivate long calculate(int size, int count, int mask) {\n\t\tif (count < 0)\n\t\t\treturn 0;\n\t\tif (result[size][count][mask] != -1)\n\t\t\treturn result[size][count][mask];\n\t\tlong current = 0;\n\t\tif (mask == 0)\n\t\t\tcurrent += 2 * calculate(0, count - 2, 15);\n\t\tfor (int i = 0; i < 4; i++) {\n\t\t\tint j = (i + 1) & 3;\n\t\t\tif ((mask >> i & 1) != 0 || (mask >> j & 1) != 0)\n\t\t\t\tcontinue;\n\t\t\tint remaining = 15 - mask - (1 << i) - (1 << j);\n\t\t\tfor (int k = remaining; ; k = (k - 1) & remaining) {\n\t\t\t\tcurrent += calculateSmall(size, count - 1 - Integer.bitCount(k), mask + (1 << i) + (1 << j) + k);\n\t\t\t\tif (k == 0)\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tint remaining = 15 - mask;\n\t\tfor (int k = remaining; ; k = (k - 1) & remaining) {\n\t\t\tcurrent += calculateSmall(size, count - Integer.bitCount(k), mask + k);\n\t\t\tif (k == 0)\n\t\t\t\tbreak;\n\t\t}\n\t\treturn result[size][count][mask] = current % MOD;\n\t}\n\n\tprivate long calculateSmall(int size, int count, int mask) {\n\t\tif (count < 0)\n\t\t\treturn 0;\n\t\tif (resultSmall[size][count][mask] != -1)\n\t\t\treturn resultSmall[size][count][mask];\n\t\tif (size == 0)\n\t\t\treturn resultSmall[size][count][mask] = count == 0 ? 1 : 0;\n\t\tint max = 3 * Integer.bitCount(15 - mask);\n\t\tint pairCount = 0;\n\t\tfor (int i = 0; i < 4; i++) {\n\t\t\tint j = (i + 1) & 3;\n\t\t\tif ((mask >> i & 1) == 0 && ((mask >> j & 1) == 0))\n\t\t\t\tpairCount++;\n\t\t}\n\t\tlong current = 0;\n\t\tfor (int j = 0; j <= pairCount; j++) {\n\t\t\tfor (int i = 0; i <= max - 2 * j; i++)\n\t\t\t\tcurrent += calculate(size - 1, count - i - j, mask) * c[max - 2 * j][i] * c[pairCount][j];\n\t\t}\n\t\treturn resultSmall[size][count][mask] = current % MOD;\n\t}\n}\n\nclass IntegerUtils {\n\n public static long[][] generateBinomialCoefficients(int n) {\n\t\tlong[][] result = new long[n + 1][n + 1];\n\t\tfor (int i = 0; i <= n; i++) {\n\t\t\tresult[i][0] = 1;\n\t\t\tfor (int j = 1; j <= i; j++)\n\t\t\t\tresult[i][j] = result[i - 1][j - 1] + result[i - 1][j];\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static long factorial(int n, long mod) {\n\t\tlong result = 1;\n\t\tfor (int i = 2; i <= n; i++)\n\t\t\tresult = result * i % mod;\n\t\treturn result % mod;\n\t}\n\n\t}\n\nclass InputReader {\n\n\tprivate InputStream stream;\n\tprivate byte[] buf = new byte[1024];\n\tprivate int curChar;\n\tprivate int numChars;\n\tprivate SpaceCharFilter filter;\n\n\tpublic InputReader(InputStream stream) {\n\t\tthis.stream = stream;\n\t}\n\n\tpublic int read() {\n\t\tif (numChars == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (curChar >= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n\n\tpublic int readInt() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tint res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tpublic boolean isSpaceChar(int c) {\n\t\tif (filter != null)\n\t\t\treturn filter.isSpaceChar(c);\n\t\treturn isWhitespace(c);\n\t}\n\n\tpublic static boolean isWhitespace(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n\n\tpublic interface SpaceCharFilter {\n\t\tpublic boolean isSpaceChar(int ch);\n\t}\n}\n\nclass OutputWriter {\n\tprivate final PrintWriter writer;\n\n\tpublic OutputWriter(OutputStream outputStream) {\n\t\twriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n\t}\n\n\tpublic OutputWriter(Writer writer) {\n\t\tthis.writer = new PrintWriter(writer);\n\t}\n\n\tpublic void print(Object...objects) {\n\t\tfor (int i = 0; i < objects.length; i++) {\n\t\t\tif (i != 0)\n\t\t\t\twriter.print(' ');\n\t\t\twriter.print(objects[i]);\n\t\t}\n\t}\n\n public void printLine(Object...objects) {\n\t\tprint(objects);\n\t\twriter.println();\n\t}\n\n\tpublic void close() {\n\t\twriter.close();\n\t}\n\n\t}\n\nclass ArrayUtils {\n\n\tpublic static void fill(long[][] array, long value) {\n\t\tfor (long[] row : array)\n\t\t\tArrays.fill(row, value);\n\t}\n\n\tpublic static void fill(long[][][] array, long value) {\n\t\tfor (long[][] row : array)\n\t\t\tfill(row, value);\n\t}\n\n\t}\n\n", "src_uid": "fa649fed687d72b1431ac82bc7288116"} {"source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Codeforces implements Runnable {\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tRandom rnd;\n\t\n\tint[] colors;\n\tArrayList<Integer>[] gMain, gRev;\n\tboolean[] usedFirst, reachFirst;\n\tboolean[] usedSecond, reachSecond;\n\t\n\tvoid bfsFirst(int n) {\n\t\tQueue<Integer> q = new ArrayDeque<Integer>();\n\t\t\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tif(colors[i] == 1) {\n\t\t\t\tq.add(i);\n\t\t\t\tusedFirst[i] = reachFirst[i] = true;\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t\twhile(q.size() > 0) {\n\t\t\tint u = q.poll();\n\t\t\t\n\t\t\tfor(int v : gMain[u]) {\n\t\t\t\tif(!usedFirst[v]) {\n\t\t\t\t\tq.add(v);\n\t\t\t\t\tusedFirst[v] = true;\n\t\t\t\t\treachFirst[v] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n\tvoid bfsSecond(int n) {\n\t\tQueue<Integer> q = new ArrayDeque<Integer>();\n\t\t\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tif(colors[i] == 2) {\n\t\t\t\tq.add(i);\n\t\t\t\tusedSecond[i] = reachSecond[i] = true;\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t\twhile(q.size() > 0) {\n\t\t\tint u = q.poll();\n\t\t\t\n\t\t\tif(colors[u] == 1) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t\tfor(int v : gRev[u]) {\n\t\t\t\tif(!usedSecond[v]) {\n\t\t\t\t\tq.add(v);\n\t\t\t\t\tusedSecond[v] = true;\n\t\t\t\t\treachSecond[v] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n\tvoid solve() throws IOException {\n\t\tint n = nextInt(), m = nextInt();\n\t\t\n\t\tgMain = new ArrayList[n];\n\t\tgRev = new ArrayList[n];\n\t\tcolors = new int[n];\n\t\tusedFirst = new boolean[n];\n\t\treachFirst = new boolean[n];\n\t\tusedSecond = new boolean[n];\n\t\treachSecond = new boolean[n];\n\t\t\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tcolors[i] = nextInt();\n\t\t}\n\t\t\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tgMain[i] = new ArrayList<Integer>();\n\t\t\tgRev[i] = new ArrayList<Integer>();\n\t\t}\n\t\t\n\t\tfor(int i = 0; i < m; i++) {\n\t\t\tint u = nextInt() - 1, v = nextInt() - 1;\n\t\t\tgMain[u].add(v);\n\t\t\tgRev[v].add(u);\n\t\t}\n\t\t\n\t\tbfsFirst(n);\n\t\tbfsSecond(n);\n\t\t\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tif(reachFirst[i] && reachSecond[i]) {\n\t\t\t\tout.println(1);\n\t\t\t} else {\n\t\t\t\tout.println(0);\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew Codeforces().run();\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\n\t\t\trnd = new Random();\n\n\t\t\tsolve();\n\n\t\t\tout.close();\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(42);\n\t\t}\n\t}\n\n\tString nextToken() throws IOException {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\tString line = in.readLine();\n\n\t\t\tif (line == null) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tst = new StringTokenizer(line);\n\t\t}\n\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}", "src_uid": "87d869a0fd4a510c5e7e310886b86a57"} {"source_code": "//package tinkoff2017.e;\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 E2 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni();\n\t\tint[] a = na(4);\n\t\tfor(int i = 0;i < 4;i++){\n\t\t\ta[i]--;\n\t\t}\n\t\tint[] par = new int[n];\n\t\tpar[0] = -1;\n\t\tfor(int i = 1;i <n;i++){\n\t\t\tpar[i] = ni()-1;\n\t\t}\n\t\tint[][] g = parentToG(par);\n\t\t\n\t\tint[][] pars = parents3(g, 0);\n\t\tint[] ord = pars[1];\n\t\tboolean[][] dp = new boolean[n][];\n\t\tint[] dom = new int[n];\n\t\tArrays.fill(dom, -1);\n\t\tint[] nl = new int[n];\n\t\touter:\n\t\tfor(int i = n-1;i >= 1;i--){\n\t\t\tint cur = ord[i];\n\t\t\tif(g[cur].length == 1){\n\t\t\t\tnl[cur]++;\n\t\t\t}\n\t\t\tnl[par[cur]] += nl[cur];\n\t\t\tfor(int j = 0;j < 4;j++){\n\t\t\t\tif(a[j] == cur){\n\t\t\t\t\tdom[cur] = j;\n\t\t\t\t\tdp[cur] = new boolean[]{true};\n\t\t\t\t\tcontinue outer;\n\t\t\t\t}\n\t\t\t}\n\t\t\tint dome = -1;\n\t\t\tfor(int e : g[cur]){\n\t\t\t\tif(par[cur] == e)continue;\n\t\t\t\tif(dom[e] != -1){\n\t\t\t\t\tdom[cur] = dom[e];\n\t\t\t\t\tdome = e;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(dom[cur] == -1)continue;\n\t\t\tdp[cur] = Arrays.copyOf(dp[dome], nl[cur]);\n\t\t\tfor(int e : g[cur]){\n\t\t\t\tif(par[cur] == e)continue;\n\t\t\t\tif(dome == e)continue;\n\t\t\t\tfor(int j = dp[cur].length-1-nl[e];j >= 0;j--){\n\t\t\t\t\tdp[cur][j+nl[e]] |= dp[cur][j];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n//\t\ttr(dom);\n\t\tif(nl[0] % 2 != 0){\n\t\t\tout.println(\"NO\");\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tboolean[] ep = new boolean[n+1];\n\t\tep[0] = true;\n\t\tboolean[][] dps = new boolean[4][];\n\t\tint[] fa = new int[4];\n\t\tfor(int e : g[0]){\n\t\t\tif(dom[e] == -1){\n\t\t\t\tfor(int j = n;j >= nl[e];j--){\n\t\t\t\t\tep[j] |= ep[j-nl[e]];\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tdps[dom[e]] = dp[e];\n\t\t\t\tfa[dom[e]] = dp[e].length;\n//\t\t\t\ttr(dom[e]);\n//\t\t\t\ttf(dp[e]);\n\t\t\t}\n\t\t}\n//\t\ttf(ep);\n\t\t// a c b d\n\t\t{\n\t\t\tboolean[] canab = new boolean[n+1];\n\t\t\tfor(int i = 0;i < dps[0].length;i++){\n\t\t\t\tfor(int j = 0;j < dps[1].length;j++){\n\t\t\t\t\tif(dps[0][i] && dps[1][j]){\n\t\t\t\t\t\tint len = nl[0]/2-1-(dps[0].length-i-1 + j) - fa[2];\n\t\t\t\t\t\tif(len >= 0)canab[len] = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tboolean[] cancd = new boolean[n+1];\n\t\t\tfor(int i = 0;i < dps[2].length;i++){\n\t\t\t\tfor(int j = 0;j < dps[3].length;j++){\n\t\t\t\t\tif(dps[2][i] && dps[3][j]){\n\t\t\t\t\t\tint len = nl[0]/2-1-(dps[2].length-i-1 + j) - fa[1];\n\t\t\t\t\t\tif(len >= 0)cancd[len] = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor(int i = 0;i <= n;i++){\n\t\t\t\tfor(int j = 0;j <= n;j++){\n\t\t\t\t\tif(ep[i] && ep[j] && canab[i] && cancd[j]){\n\t\t\t\t\t\tout.println(\"YES\");\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t{\n\t\t\tboolean[] canab = new boolean[n+1];\n\t\t\tfor(int i = 0;i < dps[0].length;i++){\n\t\t\t\tfor(int j = 0;j < dps[1].length;j++){\n\t\t\t\t\tif(dps[0][i] && dps[1][j]){\n\t\t\t\t\t\tint len = nl[0]/2-1-(dps[0].length-i-1 + j) - fa[3];\n\t\t\t\t\t\tif(len >= 0)canab[len] = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tboolean[] cancd = new boolean[n+1];\n\t\t\tfor(int i = 0;i < dps[3].length;i++){\n\t\t\t\tfor(int j = 0;j < dps[2].length;j++){\n\t\t\t\t\tif(dps[3][i] && dps[2][j]){\n\t\t\t\t\t\tint len = nl[0]/2-1-(dps[3].length-i-1 + j) - fa[1];\n\t\t\t\t\t\tif(len >= 0)cancd[len] = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor(int i = 0;i <= n;i++){\n\t\t\t\tfor(int j = 0;j <= n;j++){\n\t\t\t\t\tif(ep[i] && ep[j] && canab[i] && cancd[j]){\n\t\t\t\t\t\tout.println(\"YES\");\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(\"NO\");\n\t}\n\t\n\tpublic static void tf(boolean... r)\n\t{\n\t\tfor(boolean x : r)System.out.print(x?'#':'.');\n\t\tSystem.out.println();\n\t}\n\n\t\n\tpublic static int[][] parents3(int[][] g, int root) {\n\t\tint n = g.length;\n\t\tint[] par = new int[n];\n\t\tArrays.fill(par, -1);\n\n\t\tint[] depth = new int[n];\n\t\tdepth[0] = 0;\n\n\t\tint[] q = new int[n];\n\t\tq[0] = root;\n\t\tfor (int p = 0, r = 1; p < r; p++) {\n\t\t\tint cur = q[p];\n\t\t\tfor (int nex : g[cur]) {\n\t\t\t\tif (par[cur] != nex) {\n\t\t\t\t\tq[r++] = nex;\n\t\t\t\t\tpar[nex] = cur;\n\t\t\t\t\tdepth[nex] = depth[cur] + 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn new int[][] { par, q, depth };\n\t}\n\n\t\n\tpublic static int[][] parentToG(int[] par)\n\t{\n\t\tint n = par.length;\n\t\tint[] ct = new int[n];\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tif(par[i] >= 0){\n\t\t\t\tct[i]++;\n\t\t\t\tct[par[i]]++;\n\t\t\t}\n\t\t}\n\t\tint[][] g = new int[n][];\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tg[i] = new int[ct[i]];\n\t\t}\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tif(par[i] >= 0){\n\t\t\t\tg[par[i]][--ct[par[i]]] = i;\n\t\t\t\tg[i][--ct[i]] = par[i];\n\t\t\t}\n\t\t}\n\t\treturn g;\n\t}\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 E2().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", "src_uid": "87db879f0ca422020125a3e4d99d3c23"} {"source_code": "import java.util.*;\npublic class BullsCows {\n\tpublic static void main (String [] arg) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint N = sc.nextInt();\n\t\tGuess [] G = new Guess[N];\n\t\tfor (int i = 0; i<N; ++i) G[i] = new Guess(sc.next(), sc.nextInt(), sc.nextInt());\n\t\tString ans = \"Incorrect data\";\n\t\tint anscnt = 0;\n\t\tfor (int i = 0; i<=9999; ++i) {\n\t\t\tString s = Integer.toString(i);\n\t\t\tif (s.length() < 4) s = (\"0000\"+s).substring(s.length(), 4+s.length());\n\t\t\tGuess g = new Guess(s,4,0);\n\t\t\tboolean works = true;\n\t\t\tfor (int j = 0; j<G.length && works; ++j) if (!G[j].works(g)) works = false;\n\t\t\tif (works) ans = (anscnt++ == 0) ? s : \"Need more data\";\n\t\t}\n\t\tSystem.out.println(ans);\n\t\t\n\t}\n\tstatic class Guess {\n\t\tString n;\n\t\tint pos, num;\n\t\tint [] cnt = new int [10];\n\t\tboolean valid = true;\n\t\tpublic Guess (String n, int p, int nu) {\n\t\t\tthis.n = n;\n\t\t\tpos = p;\n\t\t\tnum = nu;\n\t\t\tfor (int i = 0; i<n.length(); ++i) {\n\t\t\t\tcnt[n.charAt(i)-'0']++;\n\t\t\t\tif (cnt[n.charAt(i)-'0'] > 1) valid = false;\n\t\t\t}\n\t\t}\n\t\tpublic boolean works (Guess t) {\n\t\t\tif (!t.valid || !this.valid) return false;\n\t\t\tint [] cnt2 = new int [10];\n\t\t\tint ddif2 = 0;\n\t\t\tfor (int i = 0; i<4; ++i) {\n\t\t\t\tif (n.charAt(i) != t.n.charAt(i)) ++ddif2;\n\t\t\t\telse cnt2[n.charAt(i)-'0']++;\n\t\t\t}\n\t\t\tif (ddif2 != 4-pos) return false;\n\t\t\tddif2 = 0;\n\t\t\tfor (int i = 0; i<10; ++i) if (cnt2[i] == 0 && cnt[i] == t.cnt[i] && cnt[i] == 1) ddif2++;\n\t\t\treturn (ddif2 == num);\n\t\t}\n\t}\n}", "src_uid": "142e5f2f08724e53c234fc2379216b4c"} {"source_code": "import java.util.*;\nimport java.io.*;\nimport static java.lang.Math.*;\n\n\npublic class Solution {\n\n public static void main(String[] args) {\n\n Scanner in = new Scanner(System.in);\n int n = in.nextInt(), x = in.nextInt(), a = in.nextInt(), y = in.nextInt(),b = in.nextInt();\n\n for(int i = 0; i<=100; i++){\n x++;\n x%=n;\n y--;\n y%=n;\n if(y<=0) y = n;\n if(x==0) x = n;\n\n\n if(x==y){\n System.out.println(\"YES\");\n return;\n }\n\n if(x==a || y==b) break;\n\n }\n System.out.println(\"NO\");\n\n\n\n }\n\n}", "src_uid": "5b889751f82c9f32f223cdee0c0095e4"} {"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 if (m == 1) {\n\t\t out.print(n + 1);\n\t\t return;\n\t }\n\t long dp[] = new long[n + 1];\n\t dp[0] = 1;\n\t long sum = 1;\n\t for (int i = 1; i <= n; i++) {\n\t\t dp[i] = sum;\n\t\t dp[i] = dp[i] * m % MOD * pow(m - 1, MOD - 2) % MOD;\n\t\t sum = add(sum, dp[i]);\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 * pow(m - 1, 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}", "src_uid": "5b775f17b188c1d8a4da212ebb3a525c"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n public static void main(String[] args) {\n InputReader in = new InputReader(System.in);\n OutputWriter out = new OutputWriter(System.out);\n TaskC solver = new TaskC(in, out);\n solver.solve();\n out.close();\n }\n\n static class TaskC {\n\n static int n;\n static int m;\n\n static int[] inv;\n static int[] fact;\n static int[] invfact;\n\n static int[] powN;\n static int[] powM;\n\n InputReader in;\n OutputWriter out;\n\n TaskC(InputReader in, OutputWriter out) {\n this.in = in;\n this.out = out;\n }\n\n private void solve() {\n n = in.readInt();\n m = in.readInt();\n precalc();\n int ans = 0;\n int choosePath = 1;\n for(int k = 1; k < n; ++k) {\n if (k > m) break;\n int cur = MathUtil.mul(choosePath, cayley(n, k + 1));\n cur = MathUtil.mul(cur, binom(m - 1, k - 1));\n cur = MathUtil.mul(cur, powM[n - k - 1]);\n choosePath = MathUtil.mul(choosePath, n - k - 1);\n ans = MathUtil.sum(ans, cur);\n }\n out.print(ans);\n }\n\n private int cayley(int n, int k) {\n if (n - k - 1 < 0) {\n return MathUtil.mul(k, MathUtil.binPow(n, MathUtil.mod - 2));\n }\n return MathUtil.mul(k, powN[n - k - 1]);\n }\n\n private int binom(int n, int k) {\n return MathUtil.mul(fact[n], MathUtil.mul(invfact[k], invfact[n - k]));\n }\n\n private void precalc() {\n powN = new int[n + 1];\n powM = new int[n + 1];\n powN[0] = 1;\n powM[0] = 1;\n for(int i = 1; i <= n; ++i) {\n powN[i] = MathUtil.mul(powN[i - 1], n);\n powM[i] = MathUtil.mul(powM[i - 1], m);\n }\n\n inv = new int[m + 1];\n fact = new int[m + 1];\n invfact = new int[m + 1];\n inv[0] = inv[1] = 1;\n fact[0] = fact[1] = 1;\n invfact[0] = invfact[1] = 1;\n for(int i = 2; i <= m; ++i) {\n inv[i] = MathUtil.mul(inv[MathUtil.mod % i], MathUtil.mod - MathUtil.mod / i);\n fact[i] = MathUtil.mul(fact[i - 1], i);\n invfact[i] = MathUtil.mul(invfact[i - 1], inv[i]);\n }\n }\n }\n static class MathUtil {\n private static final int mod = 1_000_000_007;\n\n static int binPow(int a, int n) {\n int result = 1;\n while (n > 0) {\n if (n % 2 == 1) {\n result = mul(result, a);\n }\n n /= 2;\n a = mul(a, a);\n }\n return result;\n }\n\n static int mul(int a, int b) {\n return (int)((long)a * b % mod);\n }\n\n static int sum(int a, int b) {\n int result = a + b;\n if (result >= mod) result -= mod;\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 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 writer.println();\n }\n\n public void close() {\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 } 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 double readDouble() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n double res = 0;\n while (!isSpaceChar(c) && c != '.') {\n if (c == 'e' || c == 'E') {\n return res * Math.pow(10, readInt());\n }\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n }\n if (c == '.') {\n c = read();\n double m = 1;\n while (!isSpaceChar(c)) {\n if (c == 'e' || c == 'E') {\n return res * Math.pow(10, readInt());\n }\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n m /= 10;\n res += (c - '0') * m;\n c = read();\n }\n }\n return res * sgn;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n\n }\n}\n ", "src_uid": "728fe302b8b18e33f15f6e702e332cde"} {"source_code": "import java.util.*;\npublic class A602 {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int base = in.nextInt();\n long a = 0;\n for (int i = n - 1; i >= 0; i--) {\n int tmp = in.nextInt();\n a += (tmp* Math.pow(base, i));\n }\n int m = in.nextInt();\n base = in.nextInt();\n long b = 0;\n for (int i = m - 1; i >= 0; i--) {\n int tmp = in.nextInt();\n b += (tmp * Math.pow(base, i));\n }\n if(a > b)\n System.out.println(\">\");\n else if(a < b)\n System.out.println(\"<\");\n else\n System.out.println(\"=\");\n\n }\n\n}", "src_uid": "d6ab5f75a7bee28f0af2bf168a0b2e67"} {"source_code": "\n\nimport java.util.Scanner;\n\npublic class A {\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 int sqrt = (int) (Math.sqrt(x * x + y * y));\n if (sqrt * sqrt == x * x + y * y)\n System.out.println(\"black\");\n else {\n String[] ans = { \"black\", \"white\" };\n int start = sqrt;\n if (x * y < 0)\n start++;\n System.out.println(ans[start % 2]);\n }\n }\n}\n", "src_uid": "8c92aac1bef5822848a136a1328346c6"} {"source_code": "import java.util.*;\nimport java.io.*;\npublic class code{\n public static void main(String[] args)throws IOException{\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n char[] c = sc.next().toCharArray();\n int[] d = new int[n];\n for(int i=0;i<n;i++) d[i] = (int)c[i];\n Coloring col = new Coloring(n,d);\n int res = col.get(0,n);\n System.out.println(res);\n }\n \n \n \n public static class Coloring{\n int[] tab;\n int[][] dp;\n int[] q;\n int n;\n int[] c;\n Coloring(int n,int[] tab){\n this.tab = tab;\n buildColor(n);\n n = this.n;\n dp = new int[n][n];\n for(int i=0;i<n;i++) dp[i][i] = 1;\n for(int i=1;i<n;i++){\n for(int j=0;j<n-i;j++){\n regle(dp,j,j+i);\n }\n }\n }\n void buildColor(int n){\n int[] d = new int[n];\n q = new int[n];\n int cnt = 0;\n int l = 1;\n d[0] = tab[0];\n for(int i=1;i<n;i++){\n q[i] = i-cnt;\n if(tab[i]==tab[i-1]){\n cnt++;\n q[i]--;\n continue;\n }\n d[l] = tab[i];\n l++;\n }\n this.n = l;\n c = new int[l];\n for(int i=0;i<l;i++) c[i] = d[i];\n }\n void regle(int[][] dp,int l,int r){\n dp[l][r] = Math.min(dp[l][r-1]+1,dp[l+1][r]+1);\n if(c[l]==c[l+1]||c[l]==c[r]) dp[l][r] = Math.min(dp[l][r],dp[l+1][r]);\n if(c[r]==c[r-1]||c[r]==c[l]) dp[l][r] = Math.min(dp[l][r],dp[l][r-1]);\n for(int i=l+2;i<r;i++){\n if(c[l]==c[i]){\n dp[l][r] = Math.min(dp[l][r],dp[l+1][i]+dp[i+1][r]);\n }\n }\n for(int i=r-2;i>l;i--){\n if(c[r]==c[i]){\n dp[l][r] = Math.min(dp[l][r],dp[l][i-1]+dp[i][r-1]);\n }\n }\n }\n int get(int l,int r){\n return dp[q[l]][q[r-1]];\n }\n }\n\n}", "src_uid": "516a89f4d1ae867fc1151becd92471e6"} {"source_code": "// practice with kaiboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF626C extends PrintWriter {\n\tCF626C() { super(System.out, true); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF626C o = new CF626C(); o.main(); o.flush();\n\t}\n\n\tvoid main() {\n\t\t// x / 2 >= n\n\t\t// x / 3 >= m\n\t\t// x / 2 + x / 3 - x / 6 >= n + m\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tint lower = Math.max(n * 2, m * 3) - 1, upper = n * 2 + m * 3;\n\t\twhile (upper - lower > 1) {\n\t\t\tint x = (lower + upper) / 2;\n\t\t\tif (x / 2 + x / 3 - x / 6 >= n + m)\n\t\t\t\tupper = x;\n\t\t\telse\n\t\t\t\tlower = x;\n\t\t}\n\t\tprintln(upper);\n\t}\n}\n", "src_uid": "23f2c8cac07403899199abdcfd947a5a"} {"source_code": "import java.util.*;\nimport java.io.*;\npublic class Chords\n{\n\n\t/************************ SOLUTION STARTS HERE ************************/\n\t\n\tprivate static boolean checkMajor(int i,int j,int k,int len)\n\t{\n\t\treturn ((i+4)%len == j) && ((j+3)%len == k);\n\t}\n\tprivate static boolean checkMinor(int i,int j,int k,int len)\n\t{\n\t\treturn ((i+3)%len == j) && ((j+4)%len == k);\t\n\t}\n\tprivate static void solve(FastScanner s1, FastWriter out){\n\n\t\tString in[] = {\"C\", \"C#\", \"D\", \"D#\", \"E\", \"F\", \"F#\", \"G\", \"G#\", \"A\", \"B\", \"H\"};\n\t\tArrayList<String> arl = new ArrayList<>();\n\t\tfor(String s:in)\n\t\t\tarl.add(s);\n\t\tString arr[] = s1.nextLine().split(\" \");\n\t\tint index[] = new int[3];\n\t\tfor(int i=0;i<3;i++)index[i] = arl.indexOf(arr[i]);\n\t\tArrays.sort(index);\n\t\tint len = in.length;\n\t\tif(checkMajor(index[0], index[1], index[2], len) || checkMajor(index[1], index[2], index[0], len) || checkMajor(index[2], index[0], index[1], len))\n\t\t\tout.print(\"major\");\n\t\telse if(checkMinor(index[0], index[1], index[2], len) || checkMinor(index[1], index[2], index[0], len) || checkMinor(index[2], index[0], index[1], len))\n\t\t\tout.print(\"minor\");\n\t\telse\n\t\t\tout.print(\"strange\");\t\n\t}\n\n\t/************************ SOLUTION ENDS HERE ************************/\n\n\n\n\t/************************ TEMPLATE STARTS HERE ************************/\n\n\tpublic static void main(String []args) throws IOException {\n\t\tFastScanner in = new FastScanner(System.in);\n\t\tFastWriter out = new FastWriter(System.out);\n\t\tsolve(in, out);\n\t\tin.close();\n\t\tout.close();\n\t} \n\n\tstatic class FastScanner{\n\t\tpublic BufferedReader reader;\n\t\tpublic StringTokenizer st;\n\t\tpublic FastScanner(InputStream stream){\n\t\t\treader = new BufferedReader(new InputStreamReader(stream));\n\t\t\tst = null;\n\t\t}\n\t\tpublic String next(){\n\t\t\twhile(st == null || !st.hasMoreTokens()){\n\t\t\t\ttry{\n\t\t\t\t\tString line = reader.readLine();\n\t\t\t\t\tif(line == null) return null;\n\t\t\t\t\tst = new StringTokenizer(line);\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\t\tpublic String nextLine(){\n\t\t\tString str = null;\n\t\t\ttry {\n\t\t\t\tstr = reader.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\t\tpublic int nextInt(){\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tpublic long nextLong(){\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\tpublic double nextDouble(){\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\tint[] 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\tlong[] 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\t\tpublic void close(){\t\n\t\t\ttry{ reader.close(); } catch(IOException e){e.printStackTrace();}\n\t\t}\n\t}\n\tstatic class FastWriter{\n\t\tBufferedWriter writer;\n\t\tpublic FastWriter(OutputStream stream){\n\t\t\twriter = new BufferedWriter(new OutputStreamWriter(stream));\n\t\t}\n\t\tpublic void print(int i) {\n\t\t\tprint(Integer.toString(i));\n\t\t}\n\t\tpublic void println(int i) {\n\t\t\tprint(Integer.toString(i));\n\t\t\tprint('\\n');\n\t\t}\n\t\tpublic void print(long i) {\n\t\t\tprint(Long.toString(i));\n\t\t}\n\t\tpublic void println(long i) {\n\t\t\tprint(Long.toString(i));\n\t\t\tprint('\\n');\n\t\t}\n\t\tpublic void print(double i) {\n\t\t\tprint(Double.toString(i));\n\t\t}\n\t\tpublic void print(boolean i) {\n\t\t\tprint(Boolean.toString(i));\n\t\t}\n\t\tpublic void print(Object o){\n\t\t\tprint(o.toString());\n\t\t}\n\t\tpublic void println(Object o){\n\t\t\tprint(o.toString());\n\t\t\tprint('\\n');\n\t\t}\n\t\tpublic void print(char i) {\n\t\t\ttry{writer.write(i);} catch(IOException e){e.printStackTrace();}\n\t\t}\n\t\tpublic void print(String s){\n\t\t\ttry{writer.write(s);} catch(IOException e){e.printStackTrace();}\n\t\t}\n\t\tpublic void println(String s){\n\t\t\ttry{writer.write(s);writer.write('\\n');} catch(IOException e){e.printStackTrace();}\n\t\t}\n\t\tpublic void println(){\n\t\t\ttry{writer.write('\\n');} catch(IOException e){e.printStackTrace();}\n\t\t}\n\t\tpublic void print(int arr[])\n\t\t{\n\t\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\t\tprint(arr[i]);\n\t\t\t\tprint(' ');\n\t\t\t}\n\t\t}\n\t\tpublic void close(){\n\t\t\ttry{writer.close();} catch(IOException e){e.printStackTrace();}\n\t\t}\n\t}\n\n\t/************************ TEMPLATE ENDS HERE ************************/\n}\n", "src_uid": "6aa83c2f6e095848bc63aba7d013aa58"} {"source_code": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class Task259A {\n\n\tpublic static void main(String... args) throws NumberFormatException,\n\t\t\tIOException {\n\t\tSolution.main(System.in, System.out);\n\t}\n\n\tstatic class Solution {\n\t\tpublic static void main(InputStream is, OutputStream os)\n\t\t\t\tthrows NumberFormatException, IOException {\n\t\t\tPrintWriter pw = new PrintWriter(os);\n\t\t\tScanner s = new Scanner(is);\n\n\t\t\tboolean retVal = true;\n\n\t\t\tfor (int i = 0; i < 8; i++) {\n\t\t\t\tString tmp = s.next();\n\t\t\t\tif(!\"BWBWBWBW\".equals(tmp) && !\"WBWBWBWB\".equals(tmp)){\n\t\t\t\t\tretVal = false;\n\t\t\t\t}\n\t\t\t}\n\t\t\tpw.write(retVal ? \"YES\" : \"NO\");\n\t\t\tpw.flush();\n\t\t\ts.close();\n\t\t}\n\t}\n\n}\n", "src_uid": "ca65e023be092b2ce25599f52acc1a67"} {"source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Codeforces {\n\n static int highestPowerof2(int n)\n {\n int p = (int)(Math.log(n) /\n Math.log(2));\n return (int)Math.pow(2, p);\n }\n public static int binsearch(long[] a,long x){\n int l = 0;\n int r = a.length;\n while (l <= r){\n int mid = l + (r-l)/2;\n if (a[mid]==x)\n return 1;\n else if (a[mid] < x)\n l = mid+1;\n else\n r = mid-1;\n }\n return 0;\n }\n public static int upperbound(long arr[],long key){\n int start=0;int end=arr.length-1;\n int idx=-1;\n int mid;\n while(start<=end){\n int i=(start+end)/2;\n if(arr[i]<key){\n start=i+1;\n }\n else if(arr[i]>key){\n end=i-1;\n }\n else{\n idx=i;\n start=i+1;\n }\n }\n\n return idx; }\n public static int lowerbound(long arr[],long key){\n int start=0;int end=arr.length-1;\n int idx=-1;\n int mid;\n while(start<=end){\n int i=(start+end)/2;\n if(arr[i]<key){\n start=i+1;\n }\n else if(arr[i]>key){\n end=i-1;\n }\n else{\n idx=i;\n end=i-1;\n }\n }\n return idx;\n }\n public static int searchInsert(long[] nums, long target) {\n int s=0,e=nums.length-1;\n int mid;\n if(target<nums[0]){\n return 0;\n }\n while(s<=e){\n mid=(s+e)/2;\n if(nums[mid]>target){\n e=mid-1;\n }\n else if(nums[mid]==target){\n return mid;\n }\n else{\n s=mid+1;\n }\n }\n return s;\n }\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//\n// }\n int n = sc.nextInt();\n int d = sc.nextInt();\n String s = sc.next();\n int[] dp = new int[n+200];\n Arrays.fill(dp,-1);\n int ans = solve(n-1,d,s,0,dp);\n if (ans >= Integer.MAX_VALUE/2)\n ans = -1;\n System.out.println(ans);\n }\n\n private static int solve(int n, int d, String s,int i,int[] dp) {\n if (s.charAt(i) == '1' && n-i<=d){\n return 1;\n }\n if (dp[i] != -1)\n return dp[i];\n int ans = Integer.MAX_VALUE/2;\n for (int j=1;j<=d;j++){\n if (s.charAt(i+j) == '1'){\n ans = Math.min(ans,1 + solve(n,d,s,i+j,dp));\n }\n }\n return dp[i] = ans;\n }\n}\n\n", "src_uid": "c08d2ecdfc66cd07fbbd461b1f069c9e"} {"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 VK16_3F {\n\n\tstatic int B;\n\tstatic int P;\n\tstatic int Q;\n\n\tstatic long[] iFact;\n\tstatic long[] iFact2;\n\n\tpublic static void main0(String[] args) {\n\t\tSystem.out.println(Integer.toUnsignedString(inv(7)));\n\t}\n\n\tstatic int[] numF;\n\tstatic int[] numFP;\n\tstatic int[] iNumF;\n\n\tstatic int[] denF;\n\tstatic int[] denFP;\n\tstatic int[] iDenF;\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\tStringTokenizer inputData = new StringTokenizer(reader.readLine());\n\n\t\tB = Integer.parseInt(inputData.nextToken());\n\t\tP = Integer.parseInt(inputData.nextToken());\n\t\tP = Math.min(P, B);\n\t\tQ = Integer.parseInt(inputData.nextToken());\n\n\t\tnumF = new int[P * 2 + 1];\n\t\tnumF[0] = 1;\n\t\tnumFP = new int[P * 2 + 1];\n\n\t\tiNumF = new int[P * 2 + 1];\n\n\t\tfor (int i = 1; i <= P * 2; i++) {\n\t\t\tint cPow = Integer.numberOfTrailingZeros(B - i + 1);\n\t\t\tnumF[i] = numF[i - 1] * ((B - i + 1) >> cPow);\n\t\t\tnumFP[i] = numFP[i - 1] + cPow;\n\t\t}\n\n\t\tfor (int i = 0; i <= P * 2; i++) {\n\t\t\tiNumF[i] = inv(numF[i]);\n\t\t}\n\n\t\tdenF = new int[P * 2 + 1];\n\t\tdenF[0] = 1;\n\t\tdenFP = new int[P * 2 + 1];\n\n\t\tiDenF = new int[P * 2 + 1];\n\n\t\tfor (int i = 1; i <= P * 2; i++) {\n\t\t\tint cPow = Integer.numberOfTrailingZeros(i);\n\t\t\tdenF[i] = denF[i - 1] * (i >> cPow);\n\t\t\tdenFP[i] = denFP[i - 1] + cPow;\n\t\t}\n\n\t\tfor (int i = 0; i <= P * 2; i++) {\n\t\t\tiDenF[i] = inv(denF[i]);\n\t\t}\n\n\t\tint ans = 0;\n\t\tfor (int n = 1; n <= Q; n++) {\n\t\t\tans ^= n * calculate(n);\n\t\t}\n\t\tprinter.println(Integer.toUnsignedString(ans));\n\t\tprinter.close();\n\t}\n\n\tstatic int calculate(int n) {\n\t\tint cPow = 1;\n\t\tint sum = 0;\n\t\tint endI = Math.min(P, B - 1);\n\t\tfor (int i = 0; i <= endI; i++) {\n\t\t\tsum += comb(B, i) * cPow;\n\t\t\tcPow *= n;\n\t\t}\n\t\treturn sum;\n\t}\n\n\tstatic int comb(int n, int k) {\n\t\tint off = B - n;\n\t\tint cNumF = numF[k + off] * iNumF[off];\n\t\tint cNumP = numFP[k + off] - numFP[off];\n\t\treturn (cNumF * iDenF[k]) << (cNumP - denFP[k]);\n\t}\n\n\tstatic int inv(int n) {\n\t\tint x = 1;\n\t\tx = x * (2 - x * n); /* Newton's method */\n\t\tx = x * (2 - x * n); /* 5 steps enough for 32 bits */\n\t\tx = x * (2 - x * n);\n\t\tx = x * (2 - x * n);\n\t\tx = x * (2 - x * n);\n\t\treturn x;\n\t}\n}\n", "src_uid": "28cf4ff955d089318ea08d17bc4f43da"} {"source_code": "import java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int x = in.nextInt();\n int sum = 0;\n for(int i = 0; i<=x; i++){\n sum += Math.pow(2, i);\n if (sum >= x){\n System.out.println(i + 1);\n break;\n }\n }\n }\n }\n", "src_uid": "95cb79597443461085e62d974d67a9a0"} {"source_code": "import java.util.Scanner;\npublic class Main {\n public static void main(String[] args){\n Scanner in = new Scanner(System.in);\n String s =in.next();\n s=s.replaceAll((\"/+\"), \"/\");\n System.out.println((s.endsWith(\"/\")&&s.length()>1)?new StringBuilder(s).deleteCharAt(s.length()-1):s); \n }\n}", "src_uid": "6c2e658ac3c3d6b0569dd373806fa031"} {"source_code": "import java.util.Scanner;\n \npublic class codeforce{\n \n\tpublic static void main(String[] args) {\n\t\tScanner s=new Scanner(System.in);\n\t\tint a1=s.nextInt();\n\t\tint a2=s.nextInt();\n\t\tint ans=0;\n\t\twhile(a1>0 && a2>0){\n\t\t\tif(a1>a2){\n\t\t\t\ta1-=2;\n\t\t\t\ta2+=1;\n\t\t\t}else{\n\t\t\t\ta2-=2;\n\t\t\t\ta1+=1;\n\t\t\t}\n\t\t\tans+=1;\n\t\t}\n\t\tif(a1<0 || a2<0) ans-=1;\n\t\tSystem.out.println(ans);\n\t}\n \n}", "src_uid": "ba0f9f5f0ad4786b9274c829be587961"} {"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", "src_uid": "d662ef3f9a70a5afaa2f0f68327a457f"} {"source_code": "\nimport java.util.Scanner;\n\npublic class lz77 {\n\npublic static void main(String args[])\n\n\n {\n\tint segment[]=new int [10];\n\tsegment[0]=6;\n\tsegment[1]=2;\n\tsegment[2]=5;\n\tsegment[3]=5;\n\tsegment[4]=4;\n\tsegment[5]=5;\n\tsegment[6]=6;\n\tsegment[7]=3;\n\tsegment[8]=7;\n\tsegment[9]=6;\n\tScanner in=new Scanner(System.in);\n\tString first;\n\tString last;\n\tfirst=in.next();\n\tint sum=0;\n\tlast=in.next();\n\twhile(true)\n\t{\n\t\tfor (int i=0;i<first.length();i++)\n\t\t{\n\t\t\tString s=Character.toString(first.charAt(i));\n\t\t\tsum+=segment[Integer.parseInt(s)];\n\t\t}\n\t\tif(last.equals(first))\n\t\t\tbreak;\n\t\tfirst=Integer.toString((Integer.parseInt(first)+1));\n\t}\n\tSystem.out.println(sum);\n\t}\n\t\n}", "src_uid": "1193de6f80a9feee8522a404d16425b9"} {"source_code": "//package acm;\n\nimport java.util.*;\nimport java.io.*;\n\npublic class first {\n\tstatic PrintWriter out;\n\n\tpublic static boolean isvalid(int x, int v, int k) {\n\t\tint sum = v;\n\t\tint mul=k;\n\t\twhile (v / k >= 1) {\n\t\t\tsum += v / k;\n\t\t\tk = k *mul;\n\t\t}\n\t\tif (sum >= x)\n\t\t\treturn true;\n\t\telse\n\t\t\treturn false;\n\t}\n\n\tpublic static void main(String[] args) throws IOException, InterruptedException {\n\t\tout = new PrintWriter(System.out);\n\t\tScanner sc = new Scanner(System.in);\n\t\t//int c = 1;\n\t\tint ans = 0;\n\t\tint n = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\t// out.println(k);\n\t\tif (k <= n) {\n\t\t\t\n\t\t\tint min = 0;\n\t\t\tint max = n;\n\t\t\tans = 0;\n\t\t\t//System.out.println(isvalid(n,376,k));\n\t\t\tfor (int i = 0; i < 100; i++) {\n\t\t\t\tint mid = (min + max) / 2;\n\t\t\t\tif (isvalid(n, mid, k)) {\n\t\t\t\t\tans = mid;\n\t\t\t\t\tmax = mid-1;\n\t\t\t\t} else {\n\t\t\t\t\tmin = mid+1;\n\t\t\t\t}\n\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tans=n;\n\t\t}\n\t\tout.println(ans);\n\t\tout.flush();\n\t\tout.close();\n\t}\n\n\tstatic class Scanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(s));\n\t\t}\n\n\t\tpublic Scanner(FileReader r) {\n\t\t\tbr = new BufferedReader(r);\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic String nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic boolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t}\n}", "src_uid": "41dfc86d341082dd96e089ac5433dc04"} {"source_code": "import java.util.Scanner;\npublic class Pasha\n{\n public static void main(String args[])\n {\n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n if(n%2!=0)\n System.out.println(0);\n else\n System.out.println(n%4==0?n/4-1:n/4);\n }\n}", "src_uid": "32b59d23f71800bc29da74a3fe2e2b37"} {"source_code": "import java.util.Scanner;\n\npublic class downSsapmling {\n\t\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner sc=new Scanner (System.in);\n\t\tint n=sc.nextInt()-1;\n\t\tint a=sc.nextInt();\n\t\tint b=sc.nextInt();\n\t\tint c=sc.nextInt();\n\t\tint s=Math.min(a, b);\n\t\tint r=0;\n\t\tif(n==0)\n\t\t\tr=0;\n\t\telse\n\t\t\t\n\t\tif(s<=c)\n\t\t\tr=n*s;\n\t\telse\n\t\t\tr=s+ c*(n-1);\n\t\t\nSystem.out.println(r);\n}\n}", "src_uid": "6058529f0144c853e9e17ed7c661fc50"} {"source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class PaintTheNumbers {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int n = scan.nextInt();\n int[] arr = new int[n];\n for (int i = 0; i < n; i++) {\n arr[i] = scan.nextInt();\n }\n int count = 0;\n Arrays.sort(arr);\n int b = 0;\n int countne = 0;\n for (int i = 0; i < arr.length; i++) {\n countne = 0;\n if (arr[i] == -1) {\n continue;\n }\n for (int j = i + 1; j < arr.length; j++) {\n if (arr[j] % arr[i] == 0 && arr[j] != -1 && arr[i] != -1) {\n arr[j] = -1;\n }\n }\n count++;\n arr[i] = -1;\n for (int j = 0; j < arr.length; j++) {\n if (arr[j] == -1) {\n countne++;\n }\n }\n if (countne == arr.length) {\n b++;\n }\n if (b > 0) {\n break;\n }\n }\n System.out.println(count);\n }\n}\n", "src_uid": "63d9b7416aa96129c57d20ec6145e0cd"} {"source_code": "import java.util.*;\npublic class CF675A{\n public static void main(String [] args){\n Scanner input = new Scanner(System.in);\n long n = input.nextLong();\n long f = input.nextLong();\n long diff = input.nextLong();\n long k = f - n ;\n \n System.out.println((k==0)||(diff!=0 && k/diff>=0 && k%diff==0)? \"YES\":\"NO\");\n }\n \n}", "src_uid": "9edf42c20ddf22a251b84553d7305a7d"} {"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\tTaskC solver = new TaskC();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskC {\n\tpublic void solve(int testNumber, InputReader in, PrintWriter out) {\n int xp = in.nextInt();\n int yp = in.nextInt();\n int vp = in.nextInt();\n int x = in.nextInt();\n int y = in.nextInt();\n int v = in.nextInt();\n int r = in.nextInt();\n double R = Math.sqrt(xp * xp + yp * yp);\n double left = 0;\n double right = 1e7;\n while ((right - left) / right > 1e-10) {\n double middle = (left + right) / 2;\n double alpha = middle / (R / vp);\n double nx = xp * Math.cos(alpha) - yp * Math.sin(alpha);\n double ny = xp * Math.sin(alpha) + yp * Math.cos(alpha);\n double a = ny - y;\n double b = x - nx;\n double c = -(a * x + b * y);\n double z = Math.sqrt(a * a + b * b);\n a /= z;\n b /= z;\n c /= z;\n double need;\n if (Math.abs(c) < r - 1e-8) {\n double mx = a * (-c);\n double my = b * (-c);\n if (dist(x, y, mx, my) + dist(mx, my, nx, ny) > dist(x, y, nx, ny) + 1e-8) {\n need = dist(x, y, nx, ny);\n } else {\n need = catet(dist(x, y, 0, 0), r) + catet(dist(nx, ny, 0, 0), r);\n double alp = Math.abs(Math.atan2(y, x) - Math.atan2(ny, nx));\n if (alp > Math.PI) alp = 2 * Math.PI - alp;\n alp -= Math.acos(Math.min(1.0, r / dist(x, y, 0, 0)));\n alp -= Math.acos(Math.min(1.0, r / dist(nx, ny, 0, 0)));\n need += alp * r;\n }\n } else {\n need = dist(x, y, nx, ny);\n }\n if (need / v <= middle)\n right = middle;\n else\n left = middle;\n }\n out.println(right);\n\t}\n\n private double catet(double a, int b) {\n double z = a * a - b * b;\n if (z < 1e-12) z = 0;\n return Math.sqrt(z);\n }\n\n private double dist(double x1, double y1, double x2, double y2) {\n double dx = x1 - x2;\n double dy = y1 - y2;\n return Math.sqrt(dx * dx + dy * dy);\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", "src_uid": "e8471556906e5fa3a701842570fa4ee2"} {"source_code": "/**\n * Created by IntelliJ IDEA.\n * User: luyi0619\n * Date: 11-11-26\n * Time: \u4e0b\u53487:49\n * To change this template use File | Settings | File Templates.\n */\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class GameswithRectangle implements Runnable\n{\n final int N = 2010;\n final long Mod = 1000000007;\n long[][] dp = new long[N][N];\n\n void init()\n {\n for(int i = 0 ;i < N ; i++)\n for(int j = 0 ; j< N ;j ++)\n dp[i][j] = 0;\n dp[0][0] = 1;\n dp[1][0] = dp[1][1] = 1;\n\n for (int i = 1; i < N; i++)\n {\n dp[i][0] = 1;\n for (int j = 1; j <= i; j++)\n dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % Mod;\n }\n }\n\n private void solve() throws IOException\n {\n init();\n int n = nextInt(), m = nextInt(), k = nextInt();\n writer.println(dp[n - 1][2 * k] * dp[m - 1][2 * k] % Mod);\n }\n\n public static void main(String[] args)\n {\n new GameswithRectangle().run();\n }\n\n BufferedReader reader;\n StringTokenizer tokenizer;\n PrintWriter writer;\n\n public void run()\n {\n try\n {\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 {\n e.printStackTrace();\n System.exit(1);\n }\n }\n\n int nextInt() throws IOException\n {\n return Integer.parseInt(nextToken());\n }\n\n long nextLong() throws IOException\n {\n return Long.parseLong(nextToken());\n }\n\n double nextDouble() throws IOException\n {\n return Double.parseDouble(nextToken());\n }\n\n String nextToken() throws IOException\n {\n while (tokenizer == null || !tokenizer.hasMoreTokens())\n {\n tokenizer = new StringTokenizer(reader.readLine());\n }\n return tokenizer.nextToken();\n }\n}\n", "src_uid": "309d2d46086d526d160292717dfef308"} {"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.Arrays;\nimport java.util.Scanner;\n\n/**\n *\n * @author yashvi1902\n */\npublic class sockets {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int m = sc.nextInt();\n int k = sc.nextInt();\n int arr[] = new int[n];\n for(int i=0;i<arr.length;i++){\n arr[i] = sc.nextInt();\n }\n Arrays.sort(arr);\n \n int sum=k,count=0;\n \n for(int i=n-1;i>=0;i--){\n if(sum<m){\n sum += arr[i]-1;\n count++;\n }\n }\n \n if(sum>=m){\n System.out.println(count);\n }\n else{\n System.out.println(\"-1\");\n }\n \n }\n \n}\n", "src_uid": "b32ab27503ee3c4196d6f0d0f133d13c"} {"source_code": "import java.io.BufferedInputStream;\nimport java.util.*;\n\npublic class Main {\n\n\tpublic static Scanner cin = new Scanner(new BufferedInputStream(System.in));\n\t\n\tpublic static void main(String[] args) {\n\t\t\n\t\twhile (cin.hasNext()) {\n\t\t\tint n = cin.nextInt();\n\t\t\tint k = cin.nextInt();\n\t\t\tint[] a = new int[k];\n\t\t\tfor(int i = 0; i < k; i++) {\n\t\t\t\ta[i] = cin.nextInt();\n\t\t\t}\n\t\t\tint s4 = n, s2 = n * 2;\n\t\t\tfor (int i = 0; i < k; i++) {\n\t\t\t\tint d = Math.min(s4, a[i]/4);\n\t\t\t\ts4 -= d;\n\t\t\t\ta[i] -= d*4;\n\t\t\t}\n\t\t\ts2 += s4;\n\t\t\tfor (int i = 0; i < k; i++) {\n\t\t\t\tint d = Math.min(s2, a[i]/2);\n\t\t\t\ts2 -= d;\n\t\t\t\ta[i] -= d*2;\n\t\t\t}\n\t\t\ts2 += s4;\n\t\t\tfor (int i = 0; i < k; i++) {\n\t\t\t\ts2 -= a[i];\n\t\t\t}\n\t\t\tif (s2 < 0) System.out.println(\"NO\");\n\t\t\telse System.out.println(\"YES\");\n\t\t}\n\t\tcin.close();\n\t}\n\t\n}\n", "src_uid": "d1f88a97714d6c13309c88fcf7d86821"} {"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 DPC {\npublic static void main(String[] args) throws IOException {\n\tBufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\nint n =Integer.parseInt(bf.readLine());\nif(n<=2) {\n\tSystem.out.println(-1);\n}else {\n\tfor(int i=n;i>0;i--) {\n\t\tSystem.out.println(i+\" \");\n\t}\n}\n\n}\n}\n", "src_uid": "fe8a0332119bd182a0a5b7758716317e"} {"source_code": "import java.io.*;\nimport java.util.*;\nimport java.lang.StringBuilder;\n\npublic class Solution366A {\n\n\n\tpublic static void main(String[] args) {\n\n\t\t//Scanner sc = new Scanner(System.in);\n\t\tMyScanner sc = new MyScanner();\n\t\tint n = sc.nextInt();\n\n\t\tboolean result = false;\n\t\tfor (int i = 1 ; i <= 4 ; i++) {\n\t\t\tint cho1 = sc.nextInt();\n\t\t\tint ju1 = sc.nextInt();\t\t\t\n\t\t\tint cho2 = sc.nextInt();\n\t\t\tint ju2 = sc.nextInt();\n\n\t\t\tcho1 = Math.min(cho1, ju1);\n\t\t\tcho2 = Math.min(cho2, ju2);\n\n\t\t\tif(cho1 + cho2 <= n){\n\t\t\t\tSystem.out.println(i + \" \" + cho1 + \" \" + (n-cho1));\n\t\t\t\tresult = true;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t}\n\n\t\tif(!result)\n\t\t\tSystem.out.println(-1);\n\t}\n}\n\n\n\nclass MyScanner {\n\tBufferedReader br;\n\tStringTokenizer st;\n \n public MyScanner() {\n \tbr = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String next() {\n \twhile (st == null || !st.hasMoreElements()) {\n \t\ttry {\n \t\t\tst = new StringTokenizer(br.readLine());\n \t\t} catch (IOException e) {\n \t\t\te.printStackTrace();\n \t\t}\n \t}\n \treturn st.nextToken();\n }\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 \t\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}", "src_uid": "6e7ee0da980beb99ca49a5ddd04089a5"} {"source_code": "import java.util.*;\npublic class Q2\n{\n\tpublic static void main(String args[])\n\t{\n\t\tScanner s=new Scanner(System.in);\n\t\tlong n,k,ss,ll;\n\t\tn=s.nextLong();\n\t\tk=s.nextLong();\n\t\tlong n1=0,x=1;\n\t\tss=n;\n\t\twhile(true)\n\t\t{\n\t\t\tx=x*2;\n\t\t\tif(x>n)\n\t\t\t\tbreak;\n\t\t\tn1++;\n\t\t}\n\tx=x/2l;\n\tn1++;\n\tll=(long)Math.pow(2,n1)-1;\n\tk--;\n\tif(k==0)\n\tSystem.out.println(ss);\n else\n\t\tSystem.out.println(ll);\n\t}\n}", "src_uid": "16bc089f5ef6b68bebe8eda6ead2eab9"} {"source_code": "import java.util.Scanner;\n\n\npublic class Password {\n\tpublic static void main(String args[])\n\t{\n\t\tScanner scan = new Scanner(System.in);\n\t\tString password = null;\n\t\tpassword= scan.next();\n\t\t//System.out.println(password);\n\t\tboolean hasUppercase = !password.equals(password.toLowerCase());\n\t\tboolean hasLowerCase = !password.equals(password.toUpperCase());\n\t\tboolean hasDigit = password.matches(\".*\\\\d.*\");\n\t\tboolean length = (password.length() >= 5 ? true : false);\n\t\t//Arupassword.contains(arg0)\n\t\t\n\t\t//System.out.println(hasUppercase+\" \"+hasLowerCase+\" \"+hasDigit+\" \"+length);\n\t\tif(hasUppercase && hasLowerCase && hasDigit && length)\n\t\t{\n\t\t\tSystem.out.println(\"Correct\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\tSystem.out.println(\"Too weak\");\n\t\t}\n\t\t\n\t\t\n\t}\n\n}\n", "src_uid": "42a964b01e269491975965860ec92be7"} {"source_code": "import java.util.*;\nimport java.io.*;\npublic class Monster_and_Squirrel\n{\n\tpublic static void main(String args[]) throws Exception\n\t{\n\t\tBufferedReader f=new BufferedReader(new InputStreamReader(System.in));\n\t\tlong num=Integer.parseInt(f.readLine());\n\t\tif(num==2)\n\t\t\tSystem.out.println(2);\n\t\telse\n\t\t\tSystem.out.println((num-2)*(num-2));\n\t}\n}", "src_uid": "efa8e7901a3084d34cfb1a6b18067f2b"} {"source_code": "import java.util.*;\n\npublic class Main {\n\n public static void main(String[] args) {\n\n Scanner in = new Scanner(System.in);\n long n = in.nextLong(), m = n, max = 1, r = n;\n int count = 0;\n\n while (m > 0) {\n max *= m % 10;\n m /= 10;\n }\n\n while (n > 9) {\n count++;\n n /= 10;\n n--;\n String s = \"\" + n;\n s += ((int) Math.pow(10, count) - 1);\n long pm = 1;\n m = Long.parseLong(s);\n while (m > 0) {\n pm *= m % 10;\n m /= 10;\n }\n max = Math.max(pm, max);\n }\n System.out.println(r < 10 ? r : r < 20 ? 9 : max);\n }\n}\n\n", "src_uid": "38690bd32e7d0b314f701f138ce19dfb"} {"source_code": "import java.util.*;\nimport java.awt.Point;\npublic class Main {\n\tstatic boolean check=true;\npublic static boolean checkF(Point array[])\t{\n\tboolean temp1=false;\n\tboolean temp2=false;\n\tif(array[1].x > array[3].y && array[2].y > array[4].x && array[2].y > array[3].x && array[1].x > array[4].y)\n\t\treturn true;\n\tif(array[1].y > array[3].x && array[2].x > array[4].y && array[1].y > array[4].x && array[2].x > array[3].y)\n\t\treturn true;\n\tif(array[1].x < array[3].y && array[2].y < array[4].x || array[2].y < array[3].x && array[1].x < array[4].y)\n\t\ttemp1=true;\n\tif(array[1].y < array[3].x && array[2].x < array[4].y || array[1].y < array[4].x && array[2].x < array[3].y)\n\t\ttemp2=true;\n\t\tif(temp1 && temp2)\n\t\treturn false;\n\t\tSystem.out.print(\"Draw\");\n\t\tcheck=false;\n\t\treturn true;\n\t\t\t}\n public static void main(String [] args){\n Scanner in=new Scanner(System.in);\n Point array[]=new Point[5];\n for(int i=1;i<=4;i++)array[i]=new Point(in.nextInt(),in.nextInt());\n boolean flagF=checkF(array);\n if(flagF && check)System.out.print(\"Team 1\");\n if(!flagF && check)System.out.print(\"Team 2\");\n }\n }", "src_uid": "1a70ed6f58028a7c7a86e73c28ff245f"} {"source_code": "import java.io.*;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class Main {\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\n\t\tint a = Math.max(play(n, m), play(m, n));\n\t\tout.println(a + \" \" + (n + m - 1 - a));\n\t\tout.close();\n\t}\n\n\tstatic int play(int R, int B)\n\t{\n\t\tint ret = -1, c = 0, t = 0;\n\t\twhile(R + B > 0)\n\t\t{\n\t\t\tint nc;\n\t\t\tif(R == 0 || B == 0)\n\t\t\t\tnc = R == 0 ? 1 : 0;\n\t\t\telse\n\t\t\t\tnc = t ^ c;\n\t\t\tif(nc == c)\n\t\t\t\t++ret;\n\t\t\tif(nc == 0)\n\t\t\t\t--R;\n\t\t\telse\n\t\t\t\t--B;\n\t\t\tc = nc;\n\t\t\tt ^= 1;\n\t\t}\n\t\treturn ret;\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(String s) throws FileNotFoundException {\tbr = new BufferedReader(new FileReader(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}", "src_uid": "c8378e6fcaab30d15469a55419f38b39"} {"source_code": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\nimport java.util.*;\nimport java.math.*;\nimport java.io.*;\nimport java.text.DecimalFormat;\nimport java.text.SimpleDateFormat;\n\n/**\n *\n * @author magzhankairanbay\n */\npublic class Main {\n \n public static int sqr(int x) {\n return x * x;\n }\n \n public static double d(int x1, int y1, int x2, int y2) {\n return Math.sqrt(sqr(x1 - x2) + sqr(y1 - y2) + 0.0);\n }\n \n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n // TODO code application logic here\n try {\n \n Scanner in = new Scanner(System.in);\n \n BigInteger n = in.nextBigInteger();\n BigInteger p = n.divide(BigInteger.valueOf(2520));\n System.out.println(p);\n \n } catch(Exception ex) {\n \n System.out.println(ex.toString());\n }\n }\n \n}", "src_uid": "8551308e5ff435e0fc507b89a912408a"} {"source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.lang.Math.*;\n/**\n * Created by Rishav on 28-08-2017.\n */\npublic class A215 {\n public static void main(String[] args)throws Exception\n {\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n String s[]=(br.readLine()).split(\" \");\n int n=Integer.parseInt(s[0]);\n int d=Integer.parseInt(s[1]);\n String s2[]=(br.readLine()).split(\" \");\n int s1[]=new int[n];\n for(int i=0;i<n;i++)\n s1[i]=Integer.parseInt(s2[i]);\n Arrays.sort(s1);\n // for(int i=0;i<n;i++)\n // System.out.println(s1[i]+\" \");\n int m=Integer.parseInt(br.readLine());\n int sum=0;int count=0;\n for(int i=0;i<Min.min(m,n);i++)\n {\n\n sum=sum+s1[i];\n // System.out.println(count+++\" \"+s1[i]+\" \"+sum);\n }\n if(m>n) {\n sum=sum-((m-n)*d);\n }\n System.out.println(sum);\n }\n}\nclass Min\n{\n public static int min(int m,int n)\n {\n if(m>n)return n;\n else return m;\n }\n}\n", "src_uid": "5c21e2dd658825580522af525142397d"} {"source_code": "import java.io.*;\nimport java.text.DecimalFormat;\nimport java.util.*;\n\npublic class Main {\n static int mod = (int)1e9+7;\n static int N = (int)1e5+10;\n int x, k, p;\n double[][] dp = new double[2][410];\n void work() throws Exception {\n //in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n //\n Scanner cin = new Scanner(System.in);\n /////////////////////////////////////////\n \n x = cin.nextInt();\n k = cin.nextInt();\n p = cin.nextInt();\n Arrays.fill(dp[0], 0);\n Arrays.fill(dp[1], 0);\n double P = p/100.0;\n for (int i = 0; i <= k; ++i) {\n int tmp = x+i;\n while(tmp%2==0) {\n tmp >>= 1;\n dp[0][i] += 1.0;\n }\n }\n int now = 0; \n for(int i = 0; i < k; i++) { \n Arrays.fill(dp[now^1], 0);\n for(int j = 0; j <= k; j++) { \n dp[now^1][j << 1] += (dp[now][j] + 1)*P; \n dp[now^1][j] += dp[now][j + 1]*(1 - P); \n } \n now ^= 1; \n } \n out.println(df.format(dp[now][0])); \n }\n // BufferedReader in;\n // StringTokenizer str = null;\n static PrintWriter out;\n// private String next() throws Exception{\n// while (str == null || !str.hasMoreElements())\n// str = new StringTokenizer(in.readLine());\n// return str.nextToken();\n// } \n// private int nextInt() throws Exception{\n// return Integer.parseInt(next());\n// }\n// private long nextLong() throws Exception{\n// return Long.parseLong(next());\n// }\n static int dx[] = {0,1,0,-1};\n static int dy[] = {1,0,-1,0};\n class pair implements Comparable<pair>{\n int first, second;\n pair(int x, int y) {\n first = x;\n second = y;\n }\n public int compareTo(pair o) {\n // TODO auto-generated method stub\n if(first != o.first) return ((Integer)first).compareTo(o.first);\n else return ((Integer)second).compareTo(o.second); \n }\n }\n DecimalFormat df=new DecimalFormat(\"0.000000\");\n public static void main(String[] args) throws Exception{\n Main wo = new Main();\n wo.work();\n out.close();\n }\n}", "src_uid": "c9274249c26b1a85c19ab70d91c1c3e0"} {"source_code": "import java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.math.MathContext;\nimport java.math.RoundingMode;\nimport java.util.Scanner;\n\nimport javax.swing.plaf.basic.BasicInternalFrameTitlePane.MaximizeAction;\n\n\npublic class Main {\n public static void main (String[] args) throws java.lang.Exception\n {\n Scanner sc = new Scanner(System.in);\n String m=sc.next();\n String n=sc.next();\n int base=0;\n for(int i=0;i<m.length();i++){\n base=Math.max(base, (int)(m.charAt(i)-'0'));\n }\n for(int i=0;i<n.length();i++){\n base=Math.max(base, (int)(n.charAt(i)-'0'));\n }\n base++;\n BigInteger p1,p2;\n int ans=0;\n p1=new BigInteger(m,base);\n p2=new BigInteger(n,base);\n for(int i=base;i<=1000;i++){\n BigInteger p3=p1.add(p2);\n ans=Math.max(ans, p3.toString(i).length() );\n }\n System.out.println(ans);\n }\n}\n", "src_uid": "8ccfb9b1fef6a992177cc49bd56fab7b"} {"source_code": "import java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.PrintStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\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 ilyakor\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n}\n\nclass TaskC {\n static final int[] POPCOUNT16 = new int[1 << 16];\n static {\n for (int i = 0; i < (1 << 16); ++i) {\n int x = i, cnt = 0;\n while (x > 0) {\n cnt += x % 2;\n x /= 2;\n }\n POPCOUNT16[i] = cnt;\n }\n }\n\n int popcount(long x) {\n int mask = (1 << 16) - 1;\n return POPCOUNT16[((int) (x & mask))] + POPCOUNT16[((int) ((x >> 16) & mask))] + POPCOUNT16[((int) ((x >> 32) & mask))] + POPCOUNT16[((int) ((x >> 48) & mask))];\n }\n\n long[][] A;\n long[][] curMasks;\n double[] d;\n int k, n;\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n n = in.nextInt();\n String[] a = new String[n];\n for (int i = 0; i < n; ++i)\n a[i] = in.nextToken();\n k = a[0].length();\n A = new long[k][n];\n for (int i = 0; i < k; ++i)\n for (int j = 0; j < n; ++j)\n for (int t = 0; t < n; ++t)\n if (a[j].charAt(i) == a[t].charAt(i))\n A[i][j] |= ((long) 1L << (long) t);\n curMasks = new long[k + 1][n];\n Arrays.fill(curMasks[0], ((long) 1L << (long) n) - 1L);\n d = new double[1 << k];\n Arrays.fill(d, -1.0);\n System.err.println(\"Start\");\n double res = calc(0, 0, ((long) 1L << (long) n) - 1L);\n res /= n;\n out.printLine(String.format(\"%.20f\", res));\n }\n\n private double calc(int mask, int depth, long alive) {\n if (d[mask] > -0.5) return d[mask];\n for (int i = 0; i < n; ++i) {\n if ((alive >> i) % 2 == 0) continue;\n int val = popcount(curMasks[depth][i]);\n if (val <= 1) alive ^= (1L << (long) i);\n }\n if (alive == 0L) return 0.0;\n double weight = popcount(alive);\n double num = 0.0, den = 0.0;\n for (int i = 0; i < k; ++i) {\n if ((mask >> i) % 2 == 1) continue;\n if (d[mask ^ (1 << i)] < -0.5) {\n for (int j = 0; j < n; ++j) {\n curMasks[depth + 1][j] = (curMasks[depth][j] & A[i][j]);\n }\n }\n den += 1.0;\n num += weight + calc(mask ^ (1 << i), depth + 1, alive);\n }\n d[mask] = num / den;\n return d[mask];\n }\n\n}\n\nclass InputReader {\n private InputStream stream;\n private byte[] buffer = new byte[10000];\n private int cur;\n private int count;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public static boolean isSpace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public int read() {\n if (count == -1) {\n throw new InputMismatchException();\n }\n try {\n if (cur >= count) {\n cur = 0;\n count = stream.read(buffer);\n if (count <= 0)\n return -1;\n }\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n return buffer[cur++];\n }\n\n public int readSkipSpace() {\n int c;\n do {\n c = read();\n } while (isSpace(c));\n return c;\n }\n\n public String nextToken() {\n int c = readSkipSpace();\n StringBuilder sb = new StringBuilder();\n while (!isSpace(c)) {\n sb.append((char) c);\n c = read();\n }\n return sb.toString();\n }\n\n public int nextInt() {\n int sgn = 1;\n int c = readSkipSpace();\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 = res * 10 + c - '0';\n c = read();\n } while (!isSpace(c));\n res *= sgn;\n return res;\n }\n\n}\n\nclass OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void print(Object... objects) {\n for (int i = 0; i < objects.length; i++) {\n if (i != 0) {\n writer.print(' ');\n }\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}", "src_uid": "a95d9aef6a64c30e46330dcc8e6d4a67"} {"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.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 TaskD solver = new TaskD();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskD {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n double p = in.nextDouble();\n int t = in.nextInt();\n double[][] dp = new double[t + 1][n];\n double curP = p;\n int end = Math.min(t, n);\n for (int i = 0; i < end; i++) {\n dp[i + 1][i] = curP;\n curP *= p;\n }\n for (int i = 2; i <= t; i++) {\n dp[i][0] = 1 - (1 - dp[i - 1][0]) * (1 - p);\n }\n for (int i = 3; i <= t; i++) {\n for (int j = 1; j <= Math.min(i - 2, n - 1); j++) {\n dp[i][j] = p * dp[i - 1][j - 1] + (1 - p) * dp[i - 1][j];\n }\n }\n double ans = 0;\n for (int i = 0; i < n; i++) ans += dp[t][i];\n out.println(ans);\n }\n\n }\n\n static class InputReader {\n private StringTokenizer tokenizer;\n private BufferedReader reader;\n\n public InputReader(InputStream inputStream) {\n reader = new BufferedReader(new InputStreamReader(inputStream));\n }\n\n private void fillTokenizer() {\n if (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (Exception e) {\n throw new RuntimeException(e);\n }\n }\n }\n\n public String next() {\n fillTokenizer();\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n }\n}\n\n", "src_uid": "20873b1e802c7aa0e409d9f430516c1e"} {"source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\n\npublic final class Main\n{\n private static final int MOD = 1000000007;\n\n private static final int[] readInts(BufferedReader in, int N) throws IOException\n {\n String line = in.readLine();\n int[] out = new int[N];\n if (line.equals(\"\"))\n return out;\n String[] fields = line.split(\" \");\n for (int i = 0; i < fields.length; i++)\n out[i] = Integer.parseInt(fields[i]);\n return out;\n }\n\n public static void main(String[] args) throws IOException\n {\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n int N = Integer.parseInt(in.readLine());\n int[] a = readInts(in, N); a[N - 1] = 1;\n int[] b = readInts(in, N);\n BigInteger M = new BigInteger(in.readLine());\n int[] L = new int[N];\n int limit = 0;\n for (int i = 0; i < N - 1; i++)\n {\n limit = (limit + b[i]) / a[i];\n L[i + 1] = limit;\n }\n long[] r = new long[N];\n for (int i = 0; i < N - 1; i++)\n {\n if (a[i] > 1)\n {\n BigInteger[] divmod = M.divideAndRemainder(BigInteger.valueOf(a[i]));\n M = divmod[0];\n r[i] = divmod[1].longValue();\n }\n }\n try\n {\n r[N - 1] = M.longValueExact();\n }\n catch (ArithmeticException e)\n {\n r[N - 1] = Long.MAX_VALUE / 2;\n }\n r[N - 1] = Math.min(r[N - 1], Long.MAX_VALUE / 2);\n long[] dp = new long[1];\n dp[0] = 1;\n for (int i = N - 1; i >= 0; i--)\n {\n long[] acc = new long[dp.length + 1];\n for (int j = 0; j < dp.length; j++)\n acc[j + 1] = acc[j] + dp[j];\n long scale = a[i];\n long[] dp2 = new long[L[i] + 1];\n for (int j = 0; j <= L[i]; j++)\n {\n int klo = (int) (Math.max(j - r[i] + scale - 1, 0) / scale);\n if (b[i] + j - r[i] < 0)\n continue;\n int khi = (int) Math.min((b[i] + j - r[i]) / scale + 1, dp.length);\n if (klo < khi)\n dp2[j] = (acc[khi] - acc[klo]) % MOD;\n }\n dp = dp2;\n }\n System.out.println(dp[0]);\n }\n}\n", "src_uid": "71b23bc529ee1484d9dcea84def45d53"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class A implements Runnable{\n\tpublic static void main (String[] args) {new Thread(null, new A(), \"_cf\", 1 << 28).start();}\n\n\tint ptr, append[];\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\n\t\tappend = new int[1000]; ptr = 0;\n\t\tint n = fs.nextInt();\n\t\tint m = fs.nextInt();\n\t\tMaxFlowDinic mfd = new MaxFlowDinic();\n\t\tST st = new ST(m);\n\t\tint nodes = 2 + n + st.n;\n\t\tArrayList<Edge>[] graph = mfd.createGraph(nodes);\n\t\tint src = n + st.n, snk = src+1;\n\t\t\n\t\tint[][] data = new int[n][];\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tint type = fs.nextInt();\n\t\t\tif(type == 0) { //list of k people they can hit\n\t\t\t\tint k = fs.nextInt();\n\t\t\t\tdata[i] = new int[k+1];\n\t\t\t\tdata[i][0] = type;\n\t\t\t\tfor(int j = 1; j < data[i].length; j++) {\n\t\t\t\t\tdata[i][j] = fs.nextInt()-1;\n\t\t\t\t\tmfd.addEdge(graph, i, n + st.loc[data[i][j]], 1);\n\t\t\t\t}\n\t\t\t\tmfd.addEdge(graph, src, i, 1);\n\t\t\t\t\n\t\t\t}\n\t\t\telse if(type == 1) { //range of [l, r] people they can hit\n\t\t\t\tdata[i] = new int[3];\n\t\t\t\tdata[i][0] = type;\n\t\t\t\tdata[i][1] = fs.nextInt()-1;\n\t\t\t\tdata[i][2] = fs.nextInt()-1;\n\t\t\t\t\n\t\t\t\tmfd.addEdge(graph, src, i, 1);\n\t\t\t\t\n\t\t\t\tptr = 0;\n\t\t\t\tst.find(1, data[i][1], data[i][2]);\n\t\t\t\tfor(int j = 0; j < ptr; j++) {\n\t\t\t\t\tmfd.addEdge(graph, i, n + append[j], 1);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse { //can hit exactly 0/2 people.\n\t\t\t\tdata[i] = new int[4];\n\t\t\t\tdata[i][0] = type;\n\t\t\t\tfor(int j = 1; j < 4; j++) {\n\t\t\t\t\tdata[i][j] = fs.nextInt()-1;\n\t\t\t\t\tmfd.addEdge(graph, i, n + st.loc[data[i][j]], 1);\n\t\t\t\t}\n\t\t\t\tmfd.addEdge(graph, src, i, 2);\n\t\t\t}\n\t\t}\n\t\t\n\t\tint oo = (int)1e4;\n\t\tfor(int i = 1; i < st.n; i++) {\n\t\t\tif(st.left[i] == -1) continue;\n\t\t\tif(st.left[i] == st.right[i]) {\n\t\t\t\tmfd.addEdge(graph, n + i, snk, 1);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tmfd.addEdge(graph, n+i, n+st.left(i), oo);\n\t\t\t\tmfd.addEdge(graph, n+i, n+st.right(i), oo);\n\t\t\t}\n\t\t}\n\t\t\n\t\tint flow = mfd.maxFlow(graph, src, snk);\n\t\tout.println(flow);\n\t\tboolean[] hit = new boolean[m];\n\t\tfor(int i = 1; i < st.n; i++) {\n\t\t\tif(st.left[i] == st.right[i] && st.left[i] != -1) {\n\t\t\t\tfor(Edge e : graph[n + i]) if(e.t == snk && e.f > 0) {\n\t\t\t\t\thit[ st.left[i] ] = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint[] id = new int[m]; Arrays.fill(id, -1);\n\t\tint[] gets = new int[3];\n\t\tfor(int i = 0; i < n; i++) if(data[i][0] == 2) {\n\t\t\tint got = 0;\n\t\t\tptr = 0; gets[0] = gets[1] = gets[2] = -1;\n\t\t\tfor(Edge e : graph[i]) if(e.t != src) {\n\t\t\t\tif(e.f > 0) {\n\t\t\t\t\tgot++;\n\t\t\t\t\tint it = e.t - n;\n\t\t\t\t\tid[st.left[it]] = i+1;\n\t\t\t\t}\n\t\t\t\telse if(hit[st.left[e.t-n]]) {\n\t\t\t\t\tgets[ptr++] = e.t;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(got == 1) {\n\t\t\t\tid[ st.left[gets[0] - n] ] = i+1;\n\t\t\t}\n\t\t}\n\t\tfor(int i = 0; i < n; i++) if(data[i][0] == 0) {\n\t\t\tfor(Edge e : graph[i]) if(e.t != src && e.f>0) {\n\t\t\t\tif(id[st.left[e.t-n]] == -1)\n\t\t\t\t\tid[st.left[e.t-n]] = i+1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tfor(int i = 0; i < n; i++) if(data[i][0] == 1) {\n\t\t\tint at = i;\n\t\t\twhile(true) {\n\t\t\t\tint someone = -1;\n\t\t\t\tfor(Edge e : graph[at]) if(e.f>0) {\n\t\t\t\t\te.f--;\n\t\t\t\t\tat = e.t;\n\t\t\t\t\tsomeone = at;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif(someone == -1) break;\n\t\t\t\tif(at >= n && st.left[at-n] == st.right[at-n]) {\n\t\t\t\t\tif(id[st.left[at-n]] == -1) {\n\t\t\t\t\t\tid[st.left[at-n]] = i+1;\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 i = 0; i < m; i++) if(id[i] != -1) {\n\t\t\tout.printf(\"%d %d\\n\", id[i], i+1);\n\t\t}\n\t\tout.close();\n\t}\n\t\n\tclass ST {\n\t\tint[] left, right;\n\t\tint[] loc;\n\t\tint n, nn;\n\t\tST(int a) {\n\t\t\tnn = a;\n\t\t\tn = 4*a+100;\n\t\t\tleft = new int[n];\n\t\t\tright = new int[n];\n\t\t\tArrays.fill(left, -1); Arrays.fill(right, -1);\n\t\t\tloc = new int[nn];\n\t\t\tinit(1, 0, a-1);\n\t\t}\n\t\tint left(int p) { return p << 1; }\n\t\tint right(int p) { return (p << 1)+1; }\n\t\tvoid init(int p, int ll, int rr) {\n\t\t\tleft[p] = ll; right[p] = rr;\n\t\t\tif(ll == rr) {\n\t\t\t\tloc[ll] = p;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tint mid = (ll + rr) / 2;\n\t\t\tinit(left(p), ll, mid);\n\t\t\tinit(right(p), mid+1, rr);\n\t\t}\n\t\tvoid find(int p, int ll, int rr) {\n\t\t\tif(rr < left[p] || ll > right[p]) return;\n//\t\t\tSystem.out.printf(\"Finding on %d [%d, %d] Looking for (%d, %d)\\n\", p, left[p], right[p], ll, rr);\n\t\t\tif(ll <= left[p] && right[p] <= rr) {\n//\t\t\t\tSystem.out.println(\" Back\");\n\t\t\t\tappend[ptr++] = p;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif(left[p] == right[p]) return;\n\t\t\tfind(left(p), ll, rr);\n\t\t\tfind(right(p), ll, rr);\n\t\t}\n\t}\n\t\n\tclass Edge {\n\t\tint t, rev, cap, f;\n\t\tpublic Edge(int t, int rev, int cap) {\n\t\t\tthis.t = t;\n\t\t\tthis.rev = rev;\n\t\t\tthis.cap = cap;\n\t\t}\n\t}\n\n\tclass MaxFlowDinic {\n\t\tArrayList<Edge>[] createGraph(int nodes) {\n\t\t\tArrayList<Edge>[] graph = new ArrayList[nodes];\n\t\t\tfor (int i = 0; i < nodes; i++)\n\t\t\t\tgraph[i] = new ArrayList<>();\n\t\t\treturn graph;\n\t\t}\n\n\t\tvoid addEdge(List<Edge>[] graph, int s, int t, int cap) {\n\t\t\tgraph[s].add(new Edge(t, graph[t].size(), cap));\n\t\t\tgraph[t].add(new Edge(s, graph[s].size() - 1, 0));\n\t\t}\n\n\t\tboolean dinicBfs(List<Edge>[] graph, int src, int dest, int[] dist) {\n\t\t\tArrays.fill(dist, -1);\n\t\t\tdist[src] = 0;\n\t\t\tint[] Q = new int[graph.length];\n\t\t\tint sizeQ = 0;\n\t\t\tQ[sizeQ++] = src;\n\t\t\tfor (int i = 0; i < sizeQ; i++) {\n\t\t\t\tint u = Q[i];\n\t\t\t\tfor (Edge e : graph[u]) {\n\t\t\t\t\tif (dist[e.t] < 0 && e.f < e.cap) {\n\t\t\t\t\t\tdist[e.t] = dist[u] + 1;\n\t\t\t\t\t\tQ[sizeQ++] = e.t;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn dist[dest] >= 0;\n\t\t}\n\n\t\tint dinicDfs(List<Edge>[] graph, int[] ptr, int[] dist, int dest, int u, int f) {\n\t\t\tif (u == dest)\n\t\t\t\treturn f;\n\t\t\tfor (; ptr[u] < graph[u].size(); ++ptr[u]) {\n\t\t\t\tEdge e = graph[u].get(ptr[u]);\n\t\t\t\tif (dist[e.t] == dist[u] + 1 && e.f < e.cap) {\n\t\t\t\t\tint df = dinicDfs(graph, ptr, dist, dest, e.t, Math.min(f, e.cap - e.f));\n\t\t\t\t\tif (df > 0) {\n\t\t\t\t\t\te.f += df;\n\t\t\t\t\t\tgraph[e.t].get(e.rev).f -= df;\n\t\t\t\t\t\treturn df;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn 0;\n\t\t}\n\n\t\tint maxFlow(List<Edge>[] graph, int src, int dest) {\n\t\t\tint flow = 0;\n\t\t\tint[] dist = new int[graph.length];\n\t\t\twhile (dinicBfs(graph, src, dest, dist)) {\n\t\t\t\tint[] ptr = new int[graph.length];\n\t\t\t\twhile (true) {\n\t\t\t\t\tint df = dinicDfs(graph, ptr, dist, dest, src, Integer.MAX_VALUE);\n\t\t\t\t\tif (df == 0)\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tflow += df;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn flow;\n\t\t}\n\t}\n\n\tclass FastScanner {\n\t\tpublic int BS = 1<<16;\n\t\tpublic char NC = (char)0;\n\t\tbyte[] buf = new byte[BS];\n\t\tint bId = 0, size = 0;\n\t\tchar c = NC;\n\t\tdouble num = 1;\n\t\tBufferedInputStream in;\n\n\t\tpublic FastScanner() {\n\t\t\tin = new BufferedInputStream(System.in, BS);\n\t\t}\n\n\t\tpublic FastScanner(String s) throws FileNotFoundException {\n\t\t\tin = new BufferedInputStream(new FileInputStream(new File(s)), BS);\n\t\t}\n\n\t\tpublic char nextChar(){\n\t\t\twhile(bId==size) {\n\t\t\t\ttry {\n\t\t\t\t\tsize = in.read(buf);\n\t\t\t\t}catch(Exception e) {\n\t\t\t\t\treturn NC;\n\t\t\t\t} \n\t\t\t\tif(size==-1)return NC;\n\t\t\t\tbId=0;\n\t\t\t}\n\t\t\treturn (char)buf[bId++];\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn (int)nextLong();\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\tnum=1;\n\t\t\tboolean neg = false;\n\t\t\tif(c==NC)c=nextChar();\n\t\t\tfor(;(c<'0' || c>'9'); c = nextChar()) {\n\t\t\t\tif(c=='-')neg=true;\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tfor(; c>='0' && c <='9'; c=nextChar()) {\n\t\t\t\tres = (res<<3)+(res<<1)+c-'0';\n\t\t\t\tnum*=10;\n\t\t\t}\n\t\t\treturn neg?-res:res;\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\tdouble cur = nextLong();\n\t\t\treturn c!='.' ? cur:cur+nextLong()/num;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\twhile(c<=32)c=nextChar();\n\t\t\twhile(c>32) {\n\t\t\t\tres.append(c);\n\t\t\t\tc=nextChar();\n\t\t\t}\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\twhile(c<=32)c=nextChar();\n\t\t\twhile(c!='\\n') {\n\t\t\t\tres.append(c);\n\t\t\t\tc=nextChar();\n\t\t\t}\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic boolean hasNext() {\n\t\t\tif(c>32)return true;\n\t\t\twhile(true) {\n\t\t\t\tc=nextChar();\n\t\t\t\tif(c==NC)return false;\n\t\t\t\telse if(c>32)return true;\n\t\t\t}\n\t\t}\n\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}", "src_uid": "429a94c8e3f28100c8c532e948cc36e3"} {"source_code": "import java.util.Scanner;\npublic class Problems {\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[][] points = new int[n][5];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < 5; j++)\n\t\t\t\tpoints[i][j] = sc.nextInt();\n\t\t}\n\t\t\n\t\t\n\t\tint count = 0;\n\t\tint temp = 0;\n\t\tboolean[] arr = new boolean[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ttemp = 0;\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tfor (int k = j; k < n; k++) {\n\t\t\t\t\tif (i != j && i != k && j != k) {\n\t\t\t\t\t\tint[] ab = new int[5];\n\t\t\t\t\t\tint[] ac = new int[5];\n\t\t\t\t\t\tfor (int q = 0; q < 5; q++) {\n\t\t\t\t\t\t\tab[q] = points[j][q] - points[i][q];\n\t\t\t\t\t\t\tac[q] = points[k][q] - points[i][q];\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\tint dotP = dot(ab,ac);\n\t\t\t\t\t\tif (0 < dotP)\n\t\t\t\t\t\t\ttemp++;\n\t\t\t\t\t\t\n\t\t\t\t\t\tif (temp != 0) break;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (temp != 0 ) break;\n\t\t\t}\n\t\t\t\n\t\t\tif (temp == 0) {\n\t\t\t\tcount++;\n\t\t\t\tarr[i] = true;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(count);\n\t\tfor (int i = 0 ; i < n; i++) {\n\t\t\tif (arr[i])\n\t\t\t\tSystem.out.println(i+1);\n\t\t}\n\t\t\n\t}\n\t\n\tpublic static int dot (int[] a, int [] b) {\n\t\tint ans = 0;\n\t\tfor (int i = 0; i < 5; i++)\n\t\t\tans+=a[i]*b[i];\n\t\treturn ans;\n\t}\n\t\n}\n", "src_uid": "c1cfe1f67217afd4c3c30a6327e0add9"} {"source_code": "import java.util.Scanner;\n\npublic class B_69 {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n String line = in.next();\n double h = Double.parseDouble(line.substring(0, 2));\n double m = Double.parseDouble(line.substring(3, 5));\n if (h >= 12)\n h = h - 12;\n double rm = (m / 60) * 360;\n double rh = ((m / 60) + h) * 30;\n System.out.println(rh + \" \" + rm);\n }\n\n}\n", "src_uid": "175dc0bdb5c9513feb49be6644d0d150"} {"source_code": "import java.util.*;\npublic class MainClasses{\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n String[] s = {\"Sheldon\", \"Leonard\", \"Penny\", \"Rajesh\", \"Howard\"};\n int n = in.nextInt();\n while(n>5){\n n=n-5;\n n=(n+1)/2;\n }\n System.out.println(s[n-1]);\n }\n}", "src_uid": "023b169765e81d896cdc1184e5a82b22"} {"source_code": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Set;\nimport java.util.StringTokenizer;\n\n/**\n * Created by peacefrog on 2/10/16.\n * 12:12 PM\n */\npublic class CF {\n final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n PrintWriter out;\n long timeBegin, timeEnd;\n\n public void runIO() throws IOException {\n timeBegin = System.currentTimeMillis();\n\n InputStream inputStream;\n OutputStream outputStream;\n\n if (ONLINE_JUDGE) {\n inputStream = System.in;\n Reader.init(inputStream);\n outputStream = System.out;\n\n out = new PrintWriter(outputStream);\n } else {\n inputStream = new FileInputStream(\"/home/peacefrog/Dropbox/IdeaProjects/Problem Solving/input\");\n Reader.init(inputStream);\n out = new PrintWriter(System.out);\n }\n solve();\n out.flush();\n out.close();\n timeEnd = System.currentTimeMillis();\n System.err.println(\"Time = \" + (timeEnd - timeBegin));\n }\n\n\t/*\n * Start Solution Here\n\t */\n\n private void solve() throws IOException {\n int n = Reader.nextInt() ;\n long[] arr = Reader.nextLongArray(n);\n long cnt = 0 ;\n Set<Long> taken = new HashSet<>();\n Arrays.sort(arr);\n\n for (int i = n-1; i >= 0; i--) {\n if(!taken.contains(arr[i])){\n taken.add(arr[i]);\n cnt+=arr[i];\n }\n else{\n long temp = arr[i];\n while (--temp>0)\n {\n if(!taken.contains(temp)){\n taken.add(temp);\n cnt+=temp;\n break;\n }\n }\n }\n }\n\n out.println(cnt);\n }\n\n public static void main(String[] args) throws IOException {\n new CF().runIO();\n }\n\n static class Reader {\n static BufferedReader reader;\n static StringTokenizer tokenizer;\n\n /**\n * call this method to initialize reader for InputStream\n */\n static void init(InputStream input) {\n reader = new BufferedReader(new InputStreamReader(input));\n tokenizer = new StringTokenizer(\"\");\n }\n\n /**\n * get next word\n */\n static String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n static String nextLine() {\n try {\n return reader.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return \"\";\n }\n\n static int nextChar() throws IOException {\n return reader.read();\n }\n\n static int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n static long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n static double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n static long[] nextLongArray(int n) throws IOException {\n long[] arr = new long[n];\n for (int i = 0; i < n; i++) {\n arr[i] = nextLong();\n }\n\n return arr;\n }\n\n static int[] nextIntArray(int n) throws IOException {\n int[] arr = new int[n];\n for (int i = 0; i < n; i++) {\n arr[i] = nextInt();\n }\n return arr;\n }\n }\n}", "src_uid": "3c4b2d1c9440515bc3002eddd2b89f6f"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class R1C\n{\n public static StringTokenizer st;\n public static void nextLine(BufferedReader br) throws IOException\n {\n st = new StringTokenizer(br.readLine());\n }\n \n public static String next()\n {\n return st.nextToken();\n }\n \n public static int nextInt()\n {\n return Integer.parseInt(st.nextToken());\n }\n \n public static long nextLong()\n {\n return Long.parseLong(st.nextToken());\n }\n \n public static double nextDouble()\n {\n return Double.parseDouble(st.nextToken());\n }\n \n static String s;\n static int[] dp, next;\n \n public static void main(String[] args) throws IOException\n {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n nextLine(br);\n int n = nextInt();\n int k = nextInt();\n int[] p = new int[n];\n int[] e = new int[n];\n ArrayList<Integer> points = new ArrayList<Integer>();\n int maxp = 0;\n for (int i = 0; i < n; i++)\n {\n nextLine(br);\n p[i] = nextInt();\n e[i] = nextInt();\n points.add(p[i]);\n maxp = Math.max(maxp, p[i]);\n }\n \n if (k == n + 1)\n {\n System.out.println(0);\n return;\n }\n Collections.sort(points);\n int kpts = points.get(n - k);\n if (kpts > n)\n {\n System.out.println(-1);\n return;\n }\n ArrayList<Integer> pool1 = new ArrayList<Integer>();\n ArrayList<Integer> pool2 = new ArrayList<Integer>();\n ArrayList<Integer> pool3 = new ArrayList<Integer>();\n ArrayList<Integer> pool4 = new ArrayList<Integer>();\n int plow = 0, plt = 0, peq = 0, pgt = 0, phigh = 0;\n for (int i = 0; i < n; i++)\n {\n if (p[i] + 1 < kpts)\n {\n pool1.add(e[i]);\n plow++;\n }\n else if (p[i] > kpts + 1)\n {\n pool1.add(e[i]);\n phigh++;\n }\n else if (p[i] == kpts + 1)\n {\n pool4.add(e[i]);\n pgt++;\n }\n else if (p[i] + 1 == kpts)\n {\n pool2.add(e[i]);\n plt++;\n }\n else \n {\n pool3.add(e[i]);\n peq++;\n }\n }\n \n ArrayList<Integer> cmlist1 = new ArrayList<Integer>();\n cmlist1.addAll(pool2);\n cmlist1.addAll(pool3);\n Collections.sort(cmlist1);\n ArrayList<Integer> cmlistx = new ArrayList<Integer>();\n cmlistx.addAll(pool1);\n cmlistx.addAll(pool4);\n Collections.sort(cmlistx);\n \n int mb1 = (n - k + 1) - plow;\n long score1 = 0;\n if (mb1 <= kpts)\n {\n for (int i = 0; i < mb1; i++)\n {\n score1 += cmlist1.get(i);\n }\n int tt = Math.min(cmlistx.size(), kpts - mb1);\n for (int i = 0; i < tt; i++)\n {\n score1 += cmlistx.get(i);\n }\n for (int i = 0; i < kpts - mb1 - tt; i++)\n {\n score1 += cmlist1.get(mb1 + i);\n }\n int pt = kpts - tt;\n long val1 = score1;\n while (tt > 0 && pt < cmlist1.size())\n {\n val1 -= cmlistx.get(tt - 1);\n val1 += cmlist1.get(pt);\n if (val1 < score1) score1 = val1;\n tt--;\n pt++;\n }\n }\n else score1 = Long.MAX_VALUE;\n \n int mb2 = (n - k + 1) - plow - plt;\n long score2 = 0;\n ArrayList<Integer> cmlist2 = new ArrayList<Integer>();\n cmlist2.addAll(pool1);\n cmlist2.addAll(pool2);\n Collections.sort(cmlist2);\n cmlistx.clear();\n cmlistx.addAll(pool3);\n cmlistx.addAll(pool4);\n Collections.sort(cmlistx);\n if (mb2 <= kpts + 1 && kpts + 1 <= n)\n {\n for (int i = 0; i < mb2; i++)\n {\n score2 += cmlistx.get(i);\n }\n int tt = Math.min(cmlist2.size(), kpts + 1 - mb2);\n for (int i = 0; i < tt; i++)\n {\n score2 += cmlist2.get(i);\n }\n for (int i = 0; i < kpts + 1 - mb2 - tt; i++)\n {\n score2 += cmlistx.get(mb2 + i);\n }\n int pt = kpts + 1 - tt;\n long val2 = score2;\n while (tt > 0 && pt < cmlistx.size())\n {\n val2 -= cmlist2.get(tt - 1);\n val2 += cmlistx.get(pt);\n if (val2 < score2) score2 = val2;\n tt--;\n pt++;\n }\n }\n else score2 = Long.MAX_VALUE;\n \n cmlistx.addAll(cmlist2);\n Collections.sort(cmlistx);\n long score3 = 0;\n if (kpts + 2 <= n)\n {\n for (int i = 0; i < kpts + 2; i++)\n {\n score3 += cmlistx.get(i);\n }\n }\n else score3 = Long.MAX_VALUE;\n \n long ans = Math.min(score1, Math.min(score2, score3));\n if (ans == Long.MAX_VALUE) System.out.println(-1);\n else System.out.println(ans);\n }\n}\n", "src_uid": "19a098cef100fc3652c59abf7c373814"} {"source_code": "\nimport java.util.*;\n\npublic class airplane {\n public static void main(String args[]) {\n Scanner in = new Scanner(System.in);\n int k=in.nextInt();\n int n=in.nextInt();\n int s=in.nextInt();\n int p=in.nextInt();\n\n int sheet=n/s;\n if (n%s!=0)\n sheet++;\n\n int total=sheet*k;\n\n int ans=total/p;\n if (total%p!=0)\n ans++;\n\n System.out.println(ans);\n }\n}", "src_uid": "73f0c7cfc06a9b04e4766d6aa61fc780"} {"source_code": "import java.util.*;\nimport java.io.*;\n\npublic class A {\n public static void main(String[] args) throws IOException {\n\tBufferedReader in =\n\t new BufferedReader(new InputStreamReader(System.in));\n\tString[] nbp = in.readLine().split(\" \");\n\tint n = Integer.parseInt(nbp[0]);\n\tint b = Integer.parseInt(nbp[1]);\n\tint p = Integer.parseInt(nbp[2]);\n\tint numTowels = p*n;\n\tint numBottles = 0;\n\twhile (n > 1) {\n\t int pow2 = 1;\n\t while (pow2 <= n) pow2 *= 2;\n\t pow2 /= 2;\n\t numBottles += pow2*b;\n\t numBottles += pow2/2;\n\t n -= pow2/2;\n\t}\n\tSystem.out.println(numBottles+\" \"+numTowels);\n }\n}\n", "src_uid": "eb815f35e9f29793a120d120968cfe34"} {"source_code": "import java.util.ArrayList;\nimport java.util.Scanner;\n\n\npublic class Main3 {\n\t\n\tstatic class intervalo{\n\t\tint a; \n\t\tint b;\n\t\t\n\t\tboolean intersectan(intervalo Ix){\n\t\t\tboolean intersect=false;\n\t\t\tif(Ix.b>this.b && this.a<Ix.a && this.b>Ix.a){\n\t\t\t\tintersect=true;\n\t\t\t\treturn intersect;\n\t\t\t}\n\t\t\tif(Ix.a<this.a && this.a<Ix.b && this.b>Ix.b){\n\t\t\t\tintersect=true;\n\t\t\t\treturn intersect;\n\t\t\t}\n\t\t\treturn intersect;\n\t\t}\n\t\t\n\t\tpublic intervalo(int a, int b){\n\t\t\tif(a<b){\n\t\t\t\tthis.a=a;\n\t\t\t\tthis.b=b;\n\t\t\t}\n\t\t\tif(b<a){\n\t\t\t\tthis.a=b;\n\t\t\t\tthis.b=a;\n\t\t\t}\n\t\t\t\n\t\t}\n\t}\n\n\t\n\t\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner s = new Scanner(System.in);\n\t\tint n= s.nextInt();\n\t\tint[] puntos = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tpuntos[i]=s.nextInt();\n\t\t}\n\t\tArrayList<intervalo> listOfIs= new ArrayList<>();\n\t\t\n\t\t\n\t\tfor (int i = 0; i < n-1; i++) {\n\t\t\t\n\t\t\tintervalo I=new intervalo(puntos[i], puntos[i+1]);\n\n\t\t\tlistOfIs.add(I);\n\n\t\t\t\n\t\t\t\n\t\t}\n\t\tboolean resultado = false;\n\t\tciclo1:for (int j = n-2; j > 0; j--) {\n\t\t\t\n\t\t\tfor (int i = j; i >= 0; i--) {\n\t\t\t\t\n\t\t\t\tif(listOfIs.get(j).intersectan(listOfIs.get(i))){\n\t\t\t\t\tresultado = true;\n\t\t\t\t\tSystem.out.println(\"yes\");\t\t\t\t\t\n\t\t\t\t\tbreak ciclo1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif(resultado==false){\n\t\t\tSystem.out.println(\"no\");\n\t\t}\n\t\t\n\t\t\n\t}\n\n}\n", "src_uid": "f1b6b81ebd49f31428fe57913dfc604d"} {"source_code": "import java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int m = in.nextInt();\n int k = in.nextInt();\n if (n>m||n>k) {\n System.out.println(\"No\");\n } else {\n System.out.println(\"Yes\");\n\n }\n }\n}", "src_uid": "6cd07298b23cc6ce994bb1811b9629c4"} {"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<Point> all = new TreeSet<>();\n for (int i = 0; i < n; i++) {\n for (int j = i + 1; j < n; j++) {\n List<Point> inter = intersect(circles[i], circles[j]);\n if (inter == null) {\n continue;\n }\n all.addAll(inter);\n }\n }\n\n Map<Point, Integer> pointId = new TreeMap<>();\n List<Set<Integer>> adj = new ArrayList<>();\n for (int i = 0; i < n; i++) {\n List<Double> 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<Set<Integer>> 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<Point, Integer> pointId, List<Set<Integer>> 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<Point> 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<Point> 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<Point> {\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", "src_uid": "bda5879e94a82c6fd499796f258c4691"} {"source_code": "import java.io.*;\nimport java.util.*;\n\n\npublic class Main{\n\tstatic class base implements Comparable<base>{\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 long inf=(long)1e15+7;\n\tstatic long[][]adj;\n\t\n\tstatic int V, s, t;\n\tstatic long res[][];\t\t\t//input\n\tstatic ArrayList<Integer>[] 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<Integer> q = new LinkedList<Integer>();\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 long[n][n];\n\t\tfor(long []i:adj)Arrays.fill(i, inf);\n\t\tfor(int i=0;i<m;i++) {\n\t\t\tint x=sc.nextInt()-1,y=sc.nextInt()-1;\n\t\t\tadj[x][y]=1;\n\t\t\tadj[y][x]=1;\n\t\t}\n\t\tfor(int i=0;i<n;i++)adj[i][i]=0;\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\tadj[i][j]=Math.min(adj[i][j], adj[i][k]+adj[k][j]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint ss=sc.nextInt(),b=sc.nextInt(),k=sc.nextInt();\n\t\tint[][]spaceShips=new int[ss][5];\n\t\tfor(int i=0;i<ss;i++) {\n\t\t\tfor(int j=0;j<4;j++) {\n\t\t\t\tspaceShips[i][j]=sc.nextInt();\n\t\t\t}\n\t\t\tspaceShips[i][0]--;\n\t\t\tspaceShips[i][4]=i;\n\t\t}\n\t\tArrays.sort(spaceShips,(x,y) -> x[1]-y[1]);\n\t\t\n\t\tTreeSet<base>[]planets=new TreeSet[n];\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tplanets[i]=new TreeSet<base>();\n\t\t}\n\t\tfor(int i=0;i<b;i++) {\n\t\t\tplanets[sc.nextInt()-1].add(new base(sc.nextInt(), sc.nextInt()));\n\t\t}\n\t\t\n\t\tlong[]maxProfit=new long[ss];\n\t\tlong[]maxSoFar=new long[n];\n\t\tArrays.fill(maxSoFar, -inf);\n\t\tfor(int i=0;i<ss;i++) {\n\t\t\tint curAtt=spaceShips[i][1],curFuel=spaceShips[i][2],curPrice=spaceShips[i][3],curLoc=spaceShips[i][0];\n\t\t\tlong profit=-inf;\n\t\t\tfor(int p=0;p<n;p++) {\n\t\t\t\tlong dist=adj[curLoc][p];\n\t\t\t\tif(dist>curFuel)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]]=Math.max(-inf, profit*1l-curPrice);\n\t\t}\n\t\tlong ans=0;\n\t\t\n\t\tHashSet<Integer>dep=new HashSet<Integer>();\n\t\tint[][]depend=new int[k][2];\n\t\tfor(int i=0;i<k;i++) {\n\t\t\tint x=sc.nextInt()-1,y=sc.nextInt()-1;\n\t\t\tdep.add(x);dep.add(y);\n\t\t\tdepend[i][0]=x;depend[i][1]=y;\n\t\t}\n\t\t\n\t\t\n\t\tV=dep.size()+2;\n\t\tres=new long[V][V];\n\t\tadjList=new ArrayList[V];\n\t\tfor(int i=0;i<V;i++)adjList[i]=new ArrayList<Integer>();\n\t\t\n\t\tt=V-1;\n\t\tHashMap<Integer, Integer>ids=new HashMap<Integer,Integer>();\n\t\tint id=1;\n\t\t\n\t\tfor(int i=0;i<k;i++) {\n\t\t\tint x=depend[i][0],y=depend[i][1];\n\t\t\tint idx,idy;\n\t\t\tif(ids.containsKey(x)) {\n\t\t\t\tidx=ids.get(x);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tidx=id++;\n\t\t\t\tids.put(x, idx);\n\t\t\t}\n\t\t\tif(ids.containsKey(y)) {\n\t\t\t\tidy=ids.get(y);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tidy=id++;\n\t\t\t\tids.put(y, idy);\n\t\t\t}\n\t\t\t\n\t\t\tadjList[idx].add(idy);\n\t\t\tadjList[idy].add(idx);\n\t\t\tres[idx][idy]=inf;\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t}\n\t\t\n\t\tfor(int i=0;i<ss;i++) {\n\t\t\tif(dep.contains(i)) {\n\t\t\t\tint curID=ids.get(i);\n\t\t\t\tif(maxProfit[i]>=0) {\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\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<n;i++)in[i]=nextInt();\n\t return in;\n\t\t}\n\t\tpublic long[] longArr(int n) throws IOException {\n\t long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();\n\t return in;\n\t\t}\n\t\tpublic int[] intSortedArr(int n) throws IOException {\n\t int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();\n\t shuffle(in);\n\t Arrays.sort(in);\n\t return in;\n\t\t}\n\t\tpublic long[] longSortedArr(int n) throws IOException {\n\t long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();\n\t shuffle(in);\n\t Arrays.sort(in);\n\t return in;\n\t\t}\n\t\tstatic void shuffle(int[]in) {\n\t\t\tfor(int i=0;i<in.length;i++) {\n\t\t\t\tint idx=(int)(Math.random()*in.length);\n\t\t\t\tint tmp=in[i];\n\t\t\t\tin[i]=in[idx];\n\t\t\t\tin[idx]=tmp;\n\t\t\t}\n\t\t}\n\t\tstatic void shuffle(long[]in) {\n\t\t\tfor(int i=0;i<in.length;i++) {\n\t\t\t\tint idx=(int)(Math.random()*in.length);\n\t\t\t\tlong tmp=in[i];\n\t\t\t\tin[i]=in[idx];\n\t\t\t\tin[idx]=tmp;\n\t\t\t}\n\t\t}\n\t\tpublic Integer[] IntegerArr(int n) throws IOException {\n\t Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();\n\t return in;\n\t\t}\n\t\tpublic Long[] LongArr(int n) throws IOException {\n\t Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();\n\t return in;\n\t\t}\n\t\tpublic String nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n \n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n \n\t\tpublic double nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n \n\t\tpublic char nextChar() throws IOException {\n\t\t\treturn next().charAt(0);\n\t\t}\n \n\t\tpublic Long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n \n\t\tpublic boolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n \n\t\tpublic void waitForInput() throws InterruptedException {\n\t\t\tThread.sleep(3000);\n\t\t}\n\t}\n\tstatic void addX(int[]in,int x) {\n\t\tfor(int i=0;i<in.length;i++)in[i]+=x;\n\t}\n\tstatic void addX(long[]in,int x) {\n\t\tfor(int i=0;i<in.length;i++)in[i]+=x;\n\t}\n}", "src_uid": "dd4f9570b62ed012ad0706cbd805ea4b"} {"source_code": "import java.util.*;\n\npublic class B8 {\n\tpublic static void main(String[] args) {\n\t\tString path = new Scanner(System.in).next();\n\t\t\n\t\tboolean blocked[][] = new boolean[300][300];\n\t\tint x = 150, y = 150, len = path.length();\n\t\t\n\t\tfor (int i = 0; i < 300; i++) Arrays.fill(blocked[i], true);\n\t\tblocked[x][y] = false;\n\t\t\n\t\tfor (int i = 0; i < len; i++) {\n\t\t\tchar c = path.charAt(i);\n\t\t\tif (c == 'R') {\n\t\t\t\tx++;\n\t\t\t\t/*\n\t\t\t\tint temp = dx;\n\t\t\t\tdx = dy;\n\t\t\t\tdy = -temp;*/\n\t\t\t} else if (c == 'L') {\n\t\t\t\tx--;\n\t\t\t\t/*\n\t\t\t\tint temp = dy;\n\t\t\t\tdy = dx;\n\t\t\t\tdx = -temp;*/\n\t\t\t} else if (c == 'D') {\n\t\t\t\ty--;\n\t\t\t\t/*\n\t\t\t\tdx = -dx;\n\t\t\t\tdy = -dy;*/\n\t\t\t} else y++;\n\t\t\tblocked[x][y] = false;\n\t\t\t//System.out.println(\"Not blocked: \" + x + \" \" + y);\n\t\t}\n\t\t\n\t\tint fx = x, fy = y;\n\t\t//System.out.println(fx + \" \" + fy);\n\t\t\n\t\tboolean visited[][] = new boolean[300][300];\n\t\tx = 150;\n\t\ty = 150;\n\t\t\n\t\tLinkedList<int[]> q = new LinkedList<int[]>(); /* x, y, dist */\n\t\tq.add(new int[]{x, y, 0});\n\t\t\n\t\tint dist = 1 << 25;\n\t\twhile (q.size() != 0) {\n\t\t\tint[] pt = q.remove();\n\t\t\tint xp = pt[0], yp = pt[1], d = pt[2];\n\t\t\t\n\t\t\tvisited[xp][yp] = true;\n\t\t\t\n\t\t\t/*\n\t\t\tif (xp == 148 && yp == 153) {\n\t\t\t\tSystem.out.println(blocked[149][153]);\n\t\t\t\tSystem.out.println(visited[149][153]);\n\t\t\t}*/\n\t\t\t\n\t\t\tif (xp == fx && yp == fy) {\n\t\t\t\tdist = d;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tif (xp >= 1 && !visited[xp - 1][yp] && !blocked[xp - 1][yp]) q.add(new int[]{xp - 1, yp, d + 1});\n\t\t\tif (xp < 299 && !visited[xp + 1][yp] && !blocked[xp + 1][yp]) q.add(new int[]{xp + 1, yp, d + 1});\n\t\t\tif (yp >= 1 && !visited[xp][yp - 1] && !blocked[xp][yp - 1]) q.add(new int[]{xp, yp - 1, d + 1});\n\t\t\tif (yp < 299 && !visited[xp][yp + 1] && !blocked[xp][yp + 1]) q.add(new int[]{xp, yp + 1, d + 1});\n\t\t}\n\t\t\n\t\t//System.out.println(dist + \" \" + len);\n\t\tSystem.out.println((dist == len) ? \"OK\" : \"BUG\");\n\t}\n}\n", "src_uid": "bb7805cc9d1cc907b64371b209c564b3"} {"source_code": "import java.io.IOException;\r\nimport java.io.InputStream;\r\nimport java.io.PrintWriter;\r\nimport java.util.Arrays;\r\nimport java.util.NoSuchElementException;\r\n\r\npublic class Main {\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\tnew Main().run();\r\n\t}\r\n\r\n\tvoid run() {\r\n\t\tsolve();\r\n\t}\r\n\t\r\n\tfinal long mod=998244353;\r\n\t\r\n\tlong pow(long a, long n) {\r\n\t\tif (n==0) return 1;\r\n\t\treturn pow(a*a%mod, n/2) * (n%2==1 ? a : 1) % mod;\r\n\t}\r\n\t\r\n\tlong inv(long a) {\r\n\t\treturn pow(a, mod-2);\r\n\t}\r\n\t\r\n\tint MAX=100000;\r\n\tlong[] fac=new long[MAX];\r\n\tlong[] ifac=new long[MAX];\r\n\tlong[] inv=new long[MAX];\r\n\t{\r\n\t\tfac[0]=fac[1]=ifac[0]=ifac[1]=inv[0]=inv[1]=1;\r\n\t\tfor (int i=2;i<MAX;++i) {\r\n\t\t\tfac[i]=i*fac[i-1]%mod;\r\n\t\t\tinv[i]=mod-(mod/i)*inv[(int)(mod%i)]%mod;\r\n\t\t\tifac[i]=inv[i]*ifac[i-1]%mod;\r\n\t\t}\r\n\t}\r\n\t\r\n\tlong c(int n, int k) {\r\n\t\tif (n<0||k<0||n-k<0) return 0;\r\n\t\treturn fac[n]*ifac[n-k]%mod*ifac[k]%mod;\r\n\t}\r\n\t\r\n\tvoid solve() {\r\n\t\tFastScanner sc=new FastScanner();\r\n\t\tPrintWriter pw=new PrintWriter(System.out);\r\n\t\t\r\n\t\tint N=sc.nextInt();\r\n\t\tint K=sc.nextInt();\r\n\t\t\r\n\t\tlong[] dp=new long[N];\r\n\t\tdp[0]=1;\r\n\t\tfor (int i=0;i<K;++i) {\r\n\t\t\tlong[] ndp=dp.clone();\r\n\t\t\tfor (int n=0;n<N;++n) {\r\n\t\t\t\tfor (int add=1;add+n<=N-1;++add) {\r\n\t\t\t\t\tint nn=n+add;\r\n\t\t\t\t\tndp[nn]+=dp[n]*pow(K-i, n*add+add*(add-1)/2)%mod*c(N-1-n, add)%mod;\r\n\t\t\t\t\tndp[nn]%=mod;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tdp=ndp;\r\n\t\t}\r\n\t\tSystem.out.println(dp[N-1]);\r\n\t\tpw.close();\r\n\t}\r\n\t\r\n\t\r\n\tstatic void tr(Object...objects) {\r\n\t\tSystem.out.println(Arrays.deepToString(objects));\r\n\t}\r\n\t\r\n}\r\n\r\n\r\nclass FastScanner {\r\n private final InputStream in = System.in;\r\n private final byte[] buffer = new byte[1024];\r\n private int ptr = 0;\r\n private int buflen = 0;\r\n private boolean hasNextByte() {\r\n if (ptr < buflen) {\r\n return true;\r\n }else{\r\n ptr = 0;\r\n try {\r\n buflen = in.read(buffer);\r\n } catch (IOException e) {\r\n e.printStackTrace();\r\n }\r\n if (buflen <= 0) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n }\r\n private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}\r\n private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}\r\n private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}\r\n public boolean hasNext() { skipUnprintable(); return hasNextByte();}\r\n public String next() {\r\n if (!hasNext()) throw new NoSuchElementException();\r\n StringBuilder sb = new StringBuilder();\r\n int b = readByte();\r\n while(isPrintableChar(b)) {\r\n sb.appendCodePoint(b);\r\n b = readByte();\r\n }\r\n return sb.toString();\r\n }\r\n public long nextLong() {\r\n if (!hasNext()) throw new NoSuchElementException();\r\n long n = 0;\r\n boolean minus = false;\r\n int b = readByte();\r\n if (b == '-') {\r\n minus = true;\r\n b = readByte();\r\n }\r\n if (b < '0' || '9' < b) {\r\n throw new NumberFormatException();\r\n }\r\n while(true){\r\n if ('0' <= b && b <= '9') {\r\n n *= 10;\r\n n += b - '0';\r\n }else if(b == -1 || !isPrintableChar(b)){\r\n return minus ? -n : n;\r\n }else{\r\n throw new NumberFormatException();\r\n }\r\n b = readByte();\r\n }\r\n }\r\n public int nextInt() {\r\n \treturn (int)nextLong();\r\n }\r\n}", "src_uid": "b2d7ac8e75cbdb828067aeafd803ac62"} {"source_code": "import java.util.Scanner;\nimport java.util.*;\npublic class project{\n public static void main(String[]args)\n {\n\tScanner s = new Scanner(System.in);\n\n\tint n =s.nextInt(), k=s.nextInt();\n\n\n String str = s.next();\n str='Y'+str;\n str+='Y';\n char[] x = str.toCharArray();\n\n\n int cur =0 ,ans = 0;\n boolean t=false;\n for(int i=1;i<=n;i++)\n {\n if(t && x[i]=='N')\n {\n cur++;\n }\n if(!t && x[i]=='N')\n {\n t=true;\n cur++;\n }\n if(x[i]!='N')\n {\n if (ans < cur)\n ans = cur;\n\n t=false;\n cur=0;\n }\n }\n\n if (ans < cur) ans = cur;\n if(ans>k)\n {\n System.out.println(\"NO\");\n\n }\n else\n {\n boolean vyv = false;\n for(int i=1;i<=n-k+1;i++)\n {\n if((x[i-1]=='Y' || x[i-1]=='?') && (x[i+k]=='Y' || x[i+k]=='?'))\n {\n t=true;\n for(int j=i;j<k+i;j++)\n {\n if(x[j]=='Y')\n t=false;\n }\n if(t)\n {\n System.out.println(\"YES\");\n vyv = true;\n break;\n }\n }\n }\n if (!vyv)\n System.out.println(\"NO\");\n }\n }\n}", "src_uid": "5bd578d3da5837c259b222336a194d12"} {"source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Solution {\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st;\n\t\n\tString nextToken() throws Exception {\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 Exception {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\t\n\tlong nextLong() throws Exception {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\t\n\tMap<Long, Long> memo = new TreeMap<Long, Long>();\n\t\n\tint cd(long q) {\n\t\tint res = 0;\n\t\tfor (; q > 0; q /= 10) {\n\t\t\tif (q % 10 == 4 || q % 10 == 7) res++;\n\t\t}\n\t\treturn res;\n\t}\n\t\n\tlong dp(int m, int d) {\n\t\tif (memo.containsKey((long)m * 10 + d)) return memo.get((long)m * 10 + d);\n\t\tif (m == 0) return (d == 0)? 1 : 0;\n\t\tlong res = 0;\n\t\tif (d > 0) {\n\t\t\tres = dp(m / 10, d - 1) * 2;\n\t\t\tif (cd(m / 10) == d - 1) {\n\t\t\t\tif (m % 10 < 7) res--;\n\t\t\t\tif (m % 10 < 4) res--;\n\t\t\t}\n\t\t}\n\t\tres += dp(m / 10, d) * 8;\n\t\tif (cd(m / 10) == d) {\n\t\t\tres -= 8;\n\t\t\tif (m % 10 < 4) res += (m % 10 + 1); else\n\t\t\t\tif (m % 10 < 7) res += (m % 10); else\n\t\t\t\t\tres += (m % 10 - 1);\n\t\t}\n\t\tmemo.put((long)m * 10 + d, res);\n\t\treturn res;\n\t}\n\t\n\tlong[] a = new long[10];\n\tint[] w = new int[10];\n\tlong ans = 0;\n\tlong modd = 1000000007;\n\tint g0 = -1, sumg = 0;\n\n\tvoid rek(int q, long cur) {\n\t\tif (q == 7) {\n\t\t\tif (g0 > sumg) {\n\t\t\t\tans = (ans + cur) % modd;\n\t\t\t}\n\t\t} else {\n\t\t\tfor (int i = 0; i < 10; i++) {\n\t\t\t\tif (w[i] < a[i]) {\n\t\t\t\t\tlong cc = (cur * (a[i] - w[i])) % modd;\n\t\t\t\t\tw[i]++;\n\t\t\t\t\tif (q == 0) g0 = i; else sumg += i;\n\t\t\t\t\trek(q + 1, cc);\n\t\t\t\t\tif (q == 0) g0 = -1; else sumg -= i;\n\t\t\t\t\tw[i]--;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tvoid solve() throws Exception {\n\t\tint m = nextInt();\n\t\tfor (int i = 0; i <= 9; i++) a[i] = dp(m, i);\n\t\ta[0]--;\n//\t\tfor (int i = 0; i < 10; i++) out.print(a[i] + \" \");\n\t\trek(0, 1);\n\t\tout.println(ans);\n\t}\n\t\n\tvoid 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\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\t\n\tpublic static void main(String[] args) {\n\t\tnew Solution().run();\n\t}\n\n}", "src_uid": "656ed7b1b80de84d65a253e5d14d62a9"} {"source_code": "\nimport java.util.Scanner;\n\n/**\n *\n * @author RezaM\n */\npublic class B2 {\n\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n int x = scan.nextInt();\n int m = scan.nextInt();\n\n int remind = x % m;\n\n for (int i = 0; i < m && remind!=0; i++) {\n remind = (remind * 2) % m;\n }\n if (remind==0) {\n System.out.println(\"Yes\");\n } else {\n System.out.println(\"No\");\n }\n }\n\n}\n", "src_uid": "f726133018e2149ec57e113860ec498a"} {"source_code": "import java.util.Scanner;\r\n\r\npublic class A_Accumulation_of_Dominoes {\r\n\t\r\n\tstatic Scanner in = new Scanner(System.in);\r\n\t\r\n\tstatic long n, m;\r\n\t\r\n\tstatic void solve() {\r\n\t\t\r\n\t\tif(m == 1) {\r\n\t\t\t\r\n\t\t\tSystem.out.println(n - 1);\r\n\t\t\treturn;\r\n\t\t\t\r\n\t\t}\r\n\t\t\r\n\t\tlong ans = (m - 1) * n;\r\n\t\t\r\n\t\tSystem.out.println(ans);\r\n\t\t\r\n\t}\r\n\t\r\n\tpublic static void main(String [] amit) {\r\n\t\t\r\n\t\tn = in.nextLong();\r\n\t\tm = in.nextLong();\r\n\t\t\r\n\t\tsolve();\r\n\t\t\r\n\t}\r\n\t\r\n}", "src_uid": "a91aab4c0618d036c81022232814ef44"} {"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 AT THE TOP OF CODE!!!\n // HACK ME PLEASE IF YOU CAN!!!\n // PLEASE!!!\n // PLEASE!!!\n // PLEASE!!!\n\n @SuppressWarnings(\"unused\")\n private final static Random rnd = new Random();\n private final static String fileName = \"\";\n\n private final static long MODULO = 1000 * 1000 * 1000 + 7;\n\n // THERE SOLUTION STARTS!!!\n private void solve() {\n long la = readInt();\n long ra = readInt();\n long ta = readInt();\n\n long lb = readInt();\n long rb = readInt();\n long tb = readInt();\n\n if (ta > tb) {\n long tmp = la;\n la = lb;\n lb = tmp;\n\n tmp = ra;\n ra = rb;\n rb = tmp;\n\n tmp = ta;\n ta = tb;\n tb = tmp;\n }\n\n long gcd = gcd(ta, tb);\n\n long lDelta = lb - la;\n\n long reminder = lDelta % gcd;\n if (reminder < 0) reminder += gcd;\n\n long answer = 0;\n\n {\n long sa = (lb + gcd - reminder) % (3 * tb);\n long ea = (lb + (ra - la) + gcd - reminder) % (3 * tb);\n\n long start = max(sa, lb);\n long end = min(ea, rb);\n\n answer = max(answer, end - start + 1);\n\n sa = (lb - reminder + 3 * tb) % (3 * tb);\n ea = (lb + (ra - la) - reminder + 3 * tb) % (3 * tb);\n\n start = max(sa, lb);\n end = min(ea, rb);\n\n answer = max(answer, end - start + 1);\n }\n\n out.println(answer);\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private final static boolean MULTIPLE_TESTS = true;\n private final boolean ONLINE_JUDGE = !new File(\"input.txt\").exists();\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 @SuppressWarnings(\"unused\")\n private static long inverse(long x) {\n return binpow(x, MODULO - 2);\n }\n\n private static long binpow(long base, long power) {\n if (power == 0) return 1;\n if ((power & 1) == 0) {\n long half = binpow(base, power >> 1);\n return mult(half, half);\n } else {\n long prev = binpow(base, power - 1);\n return mult(prev, base);\n }\n }\n\n private static long add(long a, long b) { return (a + b) % MODULO; }\n\n @SuppressWarnings(\"unused\")\n private static long subtract(long a, long b) { return add(a, MODULO - b % MODULO); }\n\n private static long mult(long a, long b) { return (a * b) % MODULO; }\n\n /////////////////////////////////////////////////////////////////////\n\n @SuppressWarnings(\"unused\")\n void yesNo(boolean yes) {\n out.println(yes ? \"YES\" : \"NO\");\n }\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 out.flush();\n } catch (NumberFormatException | EOFException e) {\n break;\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 @SuppressWarnings(\"unused\")\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 readNullableLine() {\n try {\n return in.readLine();\n } catch (IOException e) {\n throw new RuntimeIOException(e);\n }\n }\n\n private String readLine() {\n String line = readNullableLine();\n if (null == line) throw new EOFException();\n return line;\n }\n\n private String readString() {\n while(!tok.hasMoreTokens()){\n tok = new StringTokenizer(readLine(), delim);\n }\n\n return tok.nextToken(delim);\n }\n\n /////////////////////////////////////////////////////////////////\n\n private final char NOT_A_SYMBOL = '\\0';\n\n @SuppressWarnings(\"unused\")\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 @SuppressWarnings(\"unused\")\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 @SuppressWarnings(\"unused\")\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 @SuppressWarnings(\"unused\")\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 @SuppressWarnings(\"unused\")\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 @SuppressWarnings(\"unused\")\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 @SuppressWarnings(\"unused\")\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 @SuppressWarnings(\"unused\")\n private BigInteger readBigInteger() {\n return new BigInteger(readString());\n }\n\n @SuppressWarnings(\"unused\")\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 @SuppressWarnings(\"unused\")\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 @SuppressWarnings(\"unused\")\n private List<Integer>[] readGraph(int vertexNumber, int edgeNumber) {\n @SuppressWarnings(\"unchecked\")\n List<Integer>[] 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<Integer>[] edges;\n\n static GraphBuilder createInstance(int size) {\n @SuppressWarnings(\"unchecked\")\n List<Integer>[] 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<Integer>[] 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<Integer> vEdges = edges[v];\n graph[v] = castInt(vEdges);\n }\n\n return graph;\n }\n }\n\n @SuppressWarnings(\"unused\")\n private final static int ZERO_INDEXATION = 0, ONE_INDEXATION = 1;\n\n @SuppressWarnings(\"unused\")\n private int[][] readUnweightedGraph(int vertexNumber, int edgesNumber) {\n return readUnweightedGraph(vertexNumber, edgesNumber, ONE_INDEXATION, false);\n }\n\n private int[][] readUnweightedGraph(int vertexNumber, int edgesNumber,\n int indexation, boolean directed\n ) {\n GraphBuilder graphBuilder = GraphBuilder.createInstance(vertexNumber);\n for (int i = 0; i < edgesNumber; ++i) {\n int from = readInt() - indexation;\n int to = readInt() - indexation;\n\n if (directed) graphBuilder.addDirectedEdge(from, to);\n else graphBuilder.addEdge(from, to);\n }\n\n return graphBuilder.build();\n }\n\n private static class Edge {\n int to;\n int w;\n\n Edge(int to, int w) {\n this.to = to;\n this.w = w;\n }\n }\n\n @SuppressWarnings(\"unused\")\n private Edge[][] readWeightedGraph(int vertexNumber, int edgesNumber) {\n return readWeightedGraph(vertexNumber, edgesNumber, ONE_INDEXATION, false);\n }\n\n private Edge[][] readWeightedGraph(int vertexNumber, int edgesNumber,\n int indexation, boolean directed) {\n @SuppressWarnings(\"unchecked\")\n List<Edge>[] graph = new List[vertexNumber];\n for (int v = 0; v < vertexNumber; ++v) {\n graph[v] = new ArrayList<>();\n }\n\n while (edgesNumber --> 0) {\n int from = readInt() - indexation;\n int to = readInt() - indexation;\n int w = readInt();\n\n graph[from].add(new Edge(to, w));\n if (!directed) graph[to].add(new Edge(from, w));\n }\n\n Edge[][] graphArrays = new Edge[vertexNumber][];\n for (int v = 0; v < vertexNumber; ++v) {\n graphArrays[v] = graph[v].toArray(new Edge[0]);\n }\n\n return graphArrays;\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static class IntIndexPair {\n\n @SuppressWarnings(\"unused\")\n static Comparator<IntIndexPair> increaseComparator = new Comparator<C.IntIndexPair>() {\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 @SuppressWarnings(\"unused\")\n static Comparator<IntIndexPair> decreaseComparator = new Comparator<C.IntIndexPair>() {\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 @SuppressWarnings(\"unused\")\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 @SuppressWarnings(\"unused\")\n int getRealIndex() {\n return index + 1;\n }\n }\n\n @SuppressWarnings(\"unused\")\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 @Override\n public void println(double d){\n print(d);\n println();\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 @SuppressWarnings(\"unused\")\n void printlnAll(double... d){\n printAll(d);\n println();\n }\n \n void printAll(int... array) {\n \tfor (int value : array) {\n \t\tprint(value + \" \");\n \t}\n }\n\n @SuppressWarnings(\"unused\")\n void printlnAll(int... array) {\n \tprintAll(array);\n \tprintln();\n }\n \n void printAll(long... array) {\n \tfor (long value : array) {\n \t\tprint(value + \" \");\n \t}\n }\n\n @SuppressWarnings(\"unused\")\n void printlnAll(long... array) {\n \tprintAll(array);\n \tprintln();\n }\n }\n\n /////////////////////////////////////////////////////////////////////\n\n private static class EOFException extends RuntimeException {\n\n EOFException() {\n super();\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 andTo functions ////////////////\n /////////////////////////////////////////////////////////////////////\n\n private static void swap(int[] array, int i, int j) {\n if (i != j) {\n int tmp = array[i];\n array[i] = array[j];\n array[j] = tmp;\n }\n }\n\n private static <T> void swap(T[] array, int i, int j) {\n if (i != j) {\n T tmp = array[i];\n array[i] = array[j];\n array[j] = tmp;\n }\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 @SuppressWarnings(\"unused\")\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 int getBit(long mask, int bit) { return (int)((mask >> bit) & 1); }\n\n @SuppressWarnings(\"unused\")\n private static boolean checkBit(long mask, int bit){\n return getBit(mask, bit) != 0;\n }\n\n /////////////////////////////////////////////////////////////////////\n\n @SuppressWarnings(\"unused\")\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 @SuppressWarnings(\"unused\")\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 @SuppressWarnings(\"unused\")\n private static boolean isPrime(int x) {\n if (x < 2) return false;\n for (int d = 2; d * d <= x; ++d) {\n if (x % d == 0) return false;\n }\n\n return true;\n }\n\n @SuppressWarnings(\"unused\")\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 @SuppressWarnings(\"unused\")\n int[] getDivisors(int value) {\n List<Integer> divisors = new ArrayList<>();\n for (int divisor = 1; divisor * divisor <= value; ++divisor) {\n if (value % divisor == 0) {\n divisors.add(divisor);\n if (divisor * divisor != value) {\n divisors.add(value / divisor);\n }\n }\n }\n\n return castInt(divisors);\n }\n\n @SuppressWarnings(\"unused\")\n long[] getDivisors(long value) {\n List<Long> divisors = new ArrayList<>();\n for (long divisor = 1; divisor * divisor <= value; ++divisor) {\n if (value % divisor == 0) {\n divisors.add(divisor);\n if (divisor * divisor != value) {\n divisors.add(value / divisor);\n }\n }\n }\n\n return castLong(divisors);\n }\n\n /////////////////////////////////////////////////////////////////////\n\n @SuppressWarnings(\"unused\")\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 int[] castInt(List<Integer> 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 @SuppressWarnings(\"unused\")\n private static long[] castLong(List<Long> 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 keys 0..<n\n * @param n - exclusive limit of sequence\n */\n @SuppressWarnings(\"unused\")\n private static List<Integer> order(int n) {\n List<Integer> sequence = new ArrayList<>();\n for (int i = 0; i < n; ++i) {\n sequence.add(i);\n }\n\n return sequence;\n }\n\n @SuppressWarnings(\"unused\")\n private static List<Integer> shuffled(List<Integer> list) {\n Collections.shuffle(list, rnd);\n return list;\n }\n}", "src_uid": "faa75751c05c3ff919ddd148c6784910"} {"source_code": "import java.util.Scanner;\n\npublic class Coding {\n\n public static void main(String[] args) {\n Scanner in=new Scanner(System.in); \n long a = in.nextLong(); \n long b= a%10 ; \n ; \n if(b==0) System.out.println(a);\n if(b<=5&&b!=0){\n \n System.out.println(a-b);\n }\n if(b>5){\n long c=10-b ;\n System.out.println(a+c);\n }\n \n }\n}", "src_uid": "29c4d5fdf1328bbc943fa16d54d97aa9"} {"source_code": "import java.io.*;\r\nimport java.lang.Math;\r\nimport java.lang.reflect.Array;\r\nimport java.util.*;\r\nimport javax.swing.text.DefaultStyledDocument.ElementSpec;\r\n\r\npublic final class Solution {\r\n\r\n static BufferedReader br = new BufferedReader(\r\n new InputStreamReader(System.in)\r\n );\r\n static BufferedWriter bw = new BufferedWriter(\r\n new OutputStreamWriter(System.out)\r\n );\r\n static StringTokenizer st;\r\n\r\n /*write your constructor and global variables here*/\r\n\r\n static class sortCond implements Comparator<Pair<Integer, Integer>> {\r\n\r\n @Override\r\n public int compare(Pair<Integer, Integer> p1, Pair<Integer, Integer> p2) {\r\n if (p1.a <= p2.a) {\r\n return -1;\r\n } else {\r\n return 1;\r\n }\r\n }\r\n }\r\n\r\n static class Rec {\r\n\r\n int a;\r\n int b;\r\n long c;\r\n\r\n Rec(int a, int b, long c) {\r\n this.a = a;\r\n this.b = b;\r\n this.c = c;\r\n }\r\n }\r\n\r\n static class Pair<f, s> {\r\n\r\n f a;\r\n s b;\r\n\r\n Pair(f a, s b) {\r\n this.a = a;\r\n this.b = b;\r\n }\r\n }\r\n\r\n interface modOperations {\r\n int mod(int a, int b, int mod);\r\n }\r\n\r\n static int findBinaryExponentian(int a, int pow, int mod) {\r\n if (pow == 1) {\r\n return a;\r\n } else if (pow == 0) {\r\n return 1;\r\n } else {\r\n int retVal = findBinaryExponentian(a, (int) pow / 2, mod);\r\n int val = (pow % 2 == 0) ? 1 : a;\r\n return modMul.mod(modMul.mod(retVal, retVal, mod), val, mod);\r\n }\r\n }\r\n\r\n static int findPow(int a, int b, int mod) {\r\n if (b == 1) {\r\n return a % mod;\r\n } else if (b == 0) {\r\n return 1;\r\n } else {\r\n int res = findPow(a, (int) b / 2, mod);\r\n return modMul.mod(res, modMul.mod(res, (b % 2 == 1 ? a : 1), mod), mod);\r\n }\r\n }\r\n\r\n static int bleft(long ele, ArrayList<Long> sortedArr) {\r\n int l = 0;\r\n int h = sortedArr.size() - 1;\r\n int ans = -1;\r\n while (l <= h) {\r\n int mid = l + (int) (h - l) / 2;\r\n if (sortedArr.get(mid) < ele) {\r\n l = mid + 1;\r\n } else if (sortedArr.get(mid) >= ele) {\r\n ans = mid;\r\n h = mid - 1;\r\n }\r\n }\r\n return ans;\r\n }\r\n\r\n static int gcd(int a, int b) {\r\n int div = b;\r\n int rem = a % b;\r\n while (rem != 0) {\r\n int temp = rem;\r\n rem = div % rem;\r\n div = temp;\r\n }\r\n return div;\r\n }\r\n\r\n static long[] log(long no, long n) {\r\n long i = 1;\r\n int cnt = 0;\r\n long sum = 0l;\r\n long arr[] = new long[2];\r\n while (i < no) {\r\n sum += i;\r\n cnt++;\r\n if (sum == n) {\r\n arr[0] = 1l * cnt;\r\n arr[1] = sum;\r\n break;\r\n }\r\n i *= 2l;\r\n }\r\n if (arr[0] == 0) {\r\n arr[0] = cnt;\r\n arr[1] = sum;\r\n }\r\n return arr;\r\n }\r\n\r\n static modOperations modAdd = (int a, int b, int mod) -> {\r\n return (a % mod + b % mod) % mod;\r\n };\r\n static modOperations modSub = (int a, int b, int mod) -> {\r\n return (int) ((1l * a % mod - 1l * b % mod + 1l * mod) % mod);\r\n };\r\n static modOperations modMul = (int a, int b, int mod) -> {\r\n return (int) ((1l * (a % mod) * 1l * (b % mod)) % (1l * mod));\r\n };\r\n static modOperations modDiv = (int a, int b, int mod) -> {\r\n return modMul.mod(a, findBinaryExponentian(b, mod - 1, mod), mod);\r\n };\r\n\r\n static HashSet<Integer> primeList(int MAXI) {\r\n int[] prime = new int[MAXI + 1];\r\n HashSet<Integer> obj = new HashSet<>();\r\n for (int i = 2; i <= (int) Math.sqrt(MAXI) + 1; i++) {\r\n if (prime[i] == 0) {\r\n obj.add(i);\r\n for (int j = i * i; j <= MAXI; j += i) {\r\n prime[j] = 1;\r\n }\r\n }\r\n }\r\n for (int i = (int) Math.sqrt(MAXI) + 1; i <= MAXI; i++) {\r\n if (prime[i] == 0) {\r\n obj.add(i);\r\n }\r\n }\r\n return obj;\r\n }\r\n\r\n static int[] factorialList(int MAXI, int mod) {\r\n int[] factorial = new int[MAXI + 1];\r\n factorial[2] = 1;\r\n for (int i = 3; i < MAXI + 1; i++) {\r\n factorial[i] = modMul.mod(factorial[i - 1], i, mod);\r\n }\r\n return factorial;\r\n }\r\n\r\n static void put(HashMap<Integer, Integer> cnt, int key) {\r\n if (cnt.containsKey(key)) {\r\n cnt.replace(key, cnt.get(key) + 1);\r\n } else {\r\n cnt.put(key, 1);\r\n }\r\n }\r\n\r\n static long arrSum(ArrayList<Long> arr) {\r\n long tot = 0;\r\n for (int i = 0; i < arr.size(); i++) {\r\n tot += arr.get(i);\r\n }\r\n return tot;\r\n }\r\n\r\n static int ord(char b) {\r\n return (int) b - (int) 'a';\r\n }\r\n\r\n static int optimSearch(int[] cnt, int lower_bound, int pow, int n) {\r\n int l = lower_bound + 1;\r\n int h = n;\r\n int ans = 0;\r\n while (l <= h) {\r\n int mid = l + (h - l) / 2;\r\n if (cnt[mid] - cnt[lower_bound] == pow) {\r\n return mid;\r\n } else if (cnt[mid] - cnt[lower_bound] < pow) {\r\n ans = mid;\r\n l = mid + 1;\r\n } else {\r\n h = mid - 1;\r\n }\r\n }\r\n return ans;\r\n }\r\n\r\n static Pair<Long, Integer> ret_ans(ArrayList<Integer> ans) {\r\n int size = ans.size();\r\n int mini = 1000000000 + 1;\r\n long tit = 0l;\r\n for (int i = 0; i < size; i++) {\r\n tit += 1l * ans.get(i);\r\n mini = Math.min(mini, ans.get(i));\r\n }\r\n return new Pair<>(tit - mini, mini);\r\n }\r\n\r\n static int factorList(\r\n HashMap<Integer, Integer> maps,\r\n int no,\r\n int maxK,\r\n int req\r\n ) {\r\n int i = 1;\r\n while (i * i <= no) {\r\n if (no % i == 0) {\r\n if (i != no / i) {\r\n put(maps, no / i);\r\n }\r\n put(maps, i);\r\n if (maps.get(i) == req) {\r\n maxK = Math.max(maxK, i);\r\n }\r\n if (maps.get(no / i) == req) {\r\n maxK = Math.max(maxK, no / i);\r\n }\r\n }\r\n i++;\r\n }\r\n return maxK;\r\n }\r\n\r\n static ArrayList<Integer> getKeys(HashMap<Integer, Integer> maps) {\r\n ArrayList<Integer> vals = new ArrayList<>();\r\n for (Map.Entry<Integer, Integer> map : maps.entrySet()) {\r\n vals.add(map.getKey());\r\n }\r\n return vals;\r\n }\r\n\r\n static ArrayList<Integer> getValues(HashMap<Integer, Integer> maps) {\r\n ArrayList<Integer> vals = new ArrayList<>();\r\n for (Map.Entry<Integer, Integer> map : maps.entrySet()) {\r\n vals.add(map.getValue());\r\n }\r\n return vals;\r\n }\r\n\r\n /*write your methods here*/\r\n static int getMax(ArrayList<Integer> arr) {\r\n int max = arr.get(0);\r\n for (int i = 1; i < arr.size(); i++) {\r\n if (arr.get(i) > max) {\r\n max = arr.get(i);\r\n }\r\n }\r\n return max;\r\n }\r\n\r\n static int getMin(ArrayList<Integer> arr) {\r\n int max = arr.get(0);\r\n for (int i = 1; i < arr.size(); i++) {\r\n if (arr.get(i) < max) {\r\n max = arr.get(i);\r\n }\r\n }\r\n return max;\r\n }\r\n\r\n static int list[][] = { { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 } };\r\n\r\n public static void main(String[] args) throws IOException {\r\n int h;\r\n h = Integer.parseInt(br.readLine());\r\n if (h == 1) {\r\n bw.write(\"6\\n\");\r\n } else {\r\n long tot = 16l;\r\n long mod = (long) Math.pow(10, 9) + 7;\r\n long las = 16l;\r\n for (int i = 3; i <= h; i++) {\r\n tot *= (las * las) % mod;\r\n las = (las * las) % mod;\r\n tot = tot % mod;\r\n }\r\n tot = (tot * 6) % mod;\r\n\r\n bw.write(Long.toString(tot) + \"\\n\");\r\n }\r\n bw.flush();\r\n }\r\n}\r\n", "src_uid": "5144b9b281ea4087d8334d91c3c8bda4"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n\n void solve() {\n long a = in.nextInt();\n long b = in.nextInt();\n long c = in.nextInt();\n long d = in.nextInt();\n if (d == b) {\n out.println(b);\n return;\n }\n long res = -1;\n HashSet<Long> was = new HashSet<>();\n was.add(b);\n was.add(d);\n for (int i = 0; i < (int)1e5; i++) {\n b += a;\n d += c;\n if (was.contains(b)) {\n res = b;\n break;\n }\n was.add(b);\n if (was.contains(d)){\n res = d;\n break;\n }\n was.add(d);\n }\n out.println(res);\n }\n\n FastScanner in;\n PrintWriter out;\n\n void run() {\n try {\n in = new FastScanner(new File(\"B.in\"));\n out = new PrintWriter(new File(\"B.out\"));\n\n solve();\n\n out.close();\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n\n void runIO() {\n\n in = new FastScanner(System.in);\n out = new PrintWriter(System.out);\n\n solve();\n\n out.close();\n }\n\n class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(File f) {\n try {\n br = new BufferedReader(new FileReader(f));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n\n public FastScanner(InputStream f) {\n br = new BufferedReader(new InputStreamReader(f));\n }\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return null;\n st = new StringTokenizer(s);\n }\n return st.nextToken();\n }\n\n boolean hasMoreTokens() {\n while (st == null || !st.hasMoreTokens()) {\n String s = null;\n try {\n s = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (s == null)\n return false;\n st = new StringTokenizer(s);\n }\n return true;\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n\n public static void main(String[] args) {\n new A().runIO();\n }\n}", "src_uid": "158cb12d45f4ee3368b94b2b622693e7"} {"source_code": "import java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.List;\n\npublic class Test {\n\n static PrintWriter writer =\n new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\n public static void main(String[] args) {\n Test te = new Test();\n te.start();\n writer.flush();\n }\n\n 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 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 String readLine() {\n StringBuilder b = new StringBuilder();\n try {\n for (int c = 0; (c = System.in.read()) != -1; ) {\n if (c == '\\n') {\n break;\n } else {\n b.append((char) (c));\n }\n }\n } catch (IOException e) {\n }\n return b.toString().trim();\n }\n\n void start() {\n int n = readInt();\n long k = readLong();\n int[] a = new int[n];\n long sum = 0;\n for (int i = 0; i < n; sum += a[i], i++) a[i] = readInt();\n List<Long> seg = new ArrayList<>();\n for (int i = 0; i < n; i++) {\n for (int j = 1; j*j <= a[i]; j++) {\n seg.add((long)j);\n seg.add((long)(a[i] + j - 1)/j);\n }\n }\n seg.add(sum/n);\n Collections.sort(seg);\n long p = -1;\n for (int i = seg.size() - 1; i >= 0; i--) {\n long v = seg.get(i);\n if (v == p) continue;\n p = v;\n long c = 0;\n for (int j = 0; j < n; j++) c += (a[j] + v - 1) / v;\n if (c*v - sum > k) continue;\n long x = (sum + k) / c;\n writer.println(x);\n break;\n }\n }\n}\n", "src_uid": "2e1ab01d4d4440f33c840c4564a20a60"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class F implements Runnable{\n\tpublic static void main (String[] args) {new Thread(null, new F(), \"_cf\", 1 << 28).start();}\n\n\tpublic void run() {\n\t\tFastScanner fs = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\n\t\tint oo = (int)2e9;\n\t\tint n = fs.nextInt();\n\t\tint k = fs.nextInt();\n\t\tint[] dp = new int[n + 1], tdp = new int[n + 1];\n\t\tArrays.fill(dp, oo);\n\t\tdp[0] = 0;\n\t\twhile(k-->0) {\n\t\t\tint l = fs.nextInt(), r = fs.nextInt(), len = r - l;\n\t\t\tfor(int i = 0; i <= n; i++) tdp[i] = dp[i];\n\t\t\tArrayDeque<Integer> minQueue = new ArrayDeque<>();\n\t\t\tfor(int i = 0; i <= n; i++) {\n\t\t\t\tpush(minQueue, i, dp);\n\t\t\t\ttdp[i] = Math.min(tdp[i], best(minQueue, dp) + 2);\n\t\t\t\tif(r - i >= 0 && r - i <= n) tdp[r - i] = Math.min(tdp[r - i], best(minQueue, dp) + 1);\n\t\t\t\tpop(minQueue, i - len);\n\t\t\t}\n\t\t\tfor(int i = 0; i <= n; i++) dp[i] = tdp[i];\n\t\t}\n\t\t\n\t\tif(dp[n] >= oo) out.println(\"Hungry\");\n\t\telse out.printf(\"Full\\n%d\\n\", dp[n]);\n\n\t\tout.close();\n\t}\n\t\n\tvoid pop(ArrayDeque<Integer> minQueue, int idx) {\n\t\tif(!minQueue.isEmpty() && minQueue.peekFirst() == idx) minQueue.pollFirst();\n\t}\n\t\n\tint best(ArrayDeque<Integer> minQueue, int[] dp) {\n\t\tif(minQueue.isEmpty()) return (int)2e9;\n\t\treturn dp[minQueue.peekFirst()];\n\t}\n\t\n\tvoid push(ArrayDeque<Integer> minQueue, int p, int[] dp) {\n\t\twhile(!minQueue.isEmpty() && dp[minQueue.getLast()] >= dp[p]) minQueue.pollLast();\n\t\tminQueue.addLast(p);\n\t}\n\t\n\t/*\n\t * dp[i][j] means the minimum number of moves to cook the cutlet on one side\n\t for j seconds after processing i intervals (do iterative space saving)\n\t * The length of the interval is known and so we'll build up time j with the\n\t previous length values (including j) all from the previous state. It'll take\n\t an extra 2 flips to so:\n\t if we know the number of flips to get the cutlet to exactly t seconds and we\n\t want to get it to j seconds in the current interval being processed, then we'll\n\t need to flip it after it gets to t seconds in the other interval (to prevent overcooking)\n\t and then flip it again when it needs to cook in our interval to get it to the desired j.\n\t * There's also a case where we can just flip it once based off of the previous states.\n\t The main idea for some time j, is we want the cutlet to get to its jth second of cooking\n\t during our current interval (so we can do a flip if necessary). So what happens is we take\n\t the min of the dp values that are allowed in our current range and use that value to calculate\n\t (right - j)'s best value by taking that minimum and I guess not flipping it and instead letting\n\t it cook. Still a bit hazy but it makes sense when doing the second sample by hand (especially\n\t when we update times 10 and 8).\n\t * Definitely had to study someone else's solution because the editorial is very obscure and\n\t doesn't actually explain the important part of the problem (how to derive the +1 and +2 jumps).\n\t */\n\n\tclass FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FastScanner() {\n\t\t\ttry\t{\n\t\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t\t// br = new BufferedReader(new FileReader(\"testdata.out\"));\n\t\t\t\tst = new StringTokenizer(\"\");\n\t\t\t} catch (Exception e){e.printStackTrace();}\n\t\t}\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\t\tpublic int nextInt() {return Integer.parseInt(next());}\n\t\tpublic long nextLong() {return Long.parseLong(next());}\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\t\tpublic Integer[] nextIntegerArray(int n) {\n\t\t\tInteger[] a = new Integer[n];\n\t\t\tfor(int i = 0; i < n; i++) a[i] = nextInt();\n\t\t\treturn a;\n\t\t}\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\t\tpublic char[] nextCharArray() {return nextLine().toCharArray();}\n\t}\n\n}", "src_uid": "2e0d1b1f1a7b8df2d2598c3cb2c869d5"} {"source_code": "import java.io.*;\nimport java.math.*;\nimport java.security.*;\nimport java.text.*;\nimport java.util.*;\nimport java.util.concurrent.*;\nimport java.util.regex.*;\nimport java.util.Arrays;\nimport java.util.ArrayList;\nimport java.lang.Math; \n \n \n \npublic class project \n{ \n static class FastReader \n { \n BufferedReader br; \n StringTokenizer st; \n \n public FastReader() \n { \n br = new BufferedReader(new\n InputStreamReader(System.in)); \n } \n \n String next() \n { \n while (st == null || !st.hasMoreElements()) \n { \n try\n { \n st = new StringTokenizer(br.readLine()); \n } \n catch (IOException e) \n { \n e.printStackTrace(); \n } \n } \n return st.nextToken(); \n } \n \n int nextInt() \n { \n return Integer.parseInt(next()); \n } \n \n long nextLong() \n { \n return Long.parseLong(next()); \n } \n \n double nextDouble() \n { \n return Double.parseDouble(next()); \n } \n \n \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 \n\n static int binarySearch(long a[],long k,int l,int h){\n int min = Integer.MAX_VALUE;\n while(l<=h){\n int mid = (l+h)/2;\n if(a[mid]==k) return mid;\n else if(a[mid]>k) h=mid-1;\n else if(a[mid]<k) l =mid+1;\n }\n \n return min;\n }\n\n static String reverse(String input) \n { \n char[] a = input.toCharArray(); \n int l, r = 0; \n r = a.length - 1; \n \n for (l = 0; l < r; l++, r--) \n { \n // Swap values of l and r \n char temp = a[l]; \n a[l] = a[r]; \n a[r] = temp; \n } \n return String.valueOf(a); \n } \n \n \n\n public static void main(String[] args) throws Exception \n { \n \n OutputStream outputStream = System.out;\n PrintWriter w = new PrintWriter(outputStream);\n FastReader sc = new FastReader();\n int i,j;\n String s1 = sc.nextLine();\n String a[] = {\"00\",\"01\",\"02\",\"03\",\"04\",\"05\",\"10\",\"11\",\"12\",\"13\",\"14\",\"15\",\"20\",\"21\",\"22\",\"23\"};\n\n String s = s1.substring(0,2);\n String p = s1.substring(3);\n \n \n int l =0, r=15 , mid=-1;\n\n while(l<=r){\n\n mid = (l+r)/2;\n if(a[mid].compareTo(s)==0) break;\n else if(a[mid].compareTo(s)>0) r=mid-1; \n else l = mid+1;\n }\n String ans = \"\";\n String rev;\n if(s.compareTo(a[mid]) < 0){\n rev = reverse(a[mid]);\n ans += a[mid] +\":\"+ rev;\n }\n else{\n rev = reverse(a[mid]);\n if(p.compareTo(rev) < 0) ans += a[mid] +\":\"+ rev;\n else{\n rev = reverse(a[(mid+1)%16]);\n ans += a[(mid+1)%16] +\":\"+ rev;\n }\n }\n w.print(ans);\n \n\n w.close();\n }\n\n \n}\n\n\n\n// System.out.println();\n\n \n \n \n\n", "src_uid": "158eae916daa3e0162d4eac0426fa87f"} {"source_code": "import java.math.*;\nimport java.io.*;\nimport java.util.*;\n\npublic class Main{\n\tpublic static void main(String[] args ) throws IOException{\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n\t\tchar[] x = br.readLine().toCharArray();\n\t\tchar[] y = br.readLine().toCharArray();\n\t\tint n = x.length;\n\t\tboolean pos = true;\n\t\tfor( int i = 0; i < n; i++){\n\t\t\tif(x[i] < y[i])pos = false;\n\t\t\t\n\t\t}\n\t\tif(!pos){\n\t\t\tSystem.out.println(-1);\n\t\t\treturn;\n\t\t}\n\t\tSystem.out.println(y);\n\n\n\t}\n\n}\n", "src_uid": "ce0cb995e18501f73e34c76713aec182"} {"source_code": "import java.util.*;\nimport java.math.*;\nimport java.io.*;\nimport java.text.*;\nimport java.awt.Point;\n\nimport static java.util.Arrays.*;\nimport static java.lang.Integer.*;\nimport static java.lang.Double.*;\nimport static java.lang.Long.*;\nimport static java.lang.Short.*;\nimport static java.lang.Math.*;\nimport static java.math.BigInteger.*;\nimport static java.util.Collections.*;\n\npublic class Main {\n\n\tprivate Scanner in;\n\tprivate StringTokenizer st;\n\tprivate PrintWriter out;\n\n\tprivate DecimalFormat fmt = new DecimalFormat(\"0.0000000000\");\n\n\tpublic void solve() throws Exception {\n\t\tlong n = in.nextLong();\n\t\tlong a = in.nextLong();\n\t\tlong b = in.nextLong();\n\n\t\tlong target = n * 6;\n\t\tif (a * b < target) {\n\t\t\tlong small = min(a, b);\n\t\t\tlong large = max(a, b);\n\n\t\t\tlong best = Integer.MAX_VALUE;\n\t\t\tfor(int i= (int) small; i<sqrt(target); i++) {\n\t\t\t\tlong tmp = (long) ceil((double)target/i);\n\n\t\t\t\tif (best > abs(target - i * tmp) && tmp >= max(a, b) && i * tmp >= target) {\n\t\t\t\t\tsmall = i;\n\t\t\t\t\tlarge = tmp;\n\t\t\t\t\tbest = abs(target - i * tmp);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (a < b) {\n\t\t\t\ta = small;\n\t\t\t\tb = large;\n\t\t\t} else {\n\t\t\t\tb = small;\n\t\t\t\ta = large;\n\t\t\t}\n\t\t}\n\t\tout.println(a * b);\n\t\tout.println(a + \" \" + b);\n\t}\n\n\tpublic Main() {\n\t\tthis.in = new Scanner(System.in);\n\t\tthis.out = new PrintWriter(System.out);\n\t}\n\n\tpublic void end() {\n\t\ttry {\n\t\t\tthis.out.flush();\n\t\t\tthis.out.close();\n\t\t\tthis.in.close();\n\t\t} catch (Exception e){\n\t\t\t//do nothing then :)\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tMain solver = new Main();\n\t\tsolver.solve();\n\t\tsolver.end();\n\t}\n}\n", "src_uid": "6a2a584d36008151d18e5080aea5029c"} {"source_code": "\n\nimport java.util.Scanner;\n\npublic class Pizza {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n long n = sc.nextLong();\n n++;\n if(n==1){\n System.out.println(\"0\");\n }else\n if(n%2==0)\n System.out.println(n/2);\n else\n System.out.println(n);\n }\n \n}\n", "src_uid": "236177ff30dafe68295b5d33dc501828"} {"source_code": "//45G\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class PrimeProblem {\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\t\n\t\tint n = Integer.parseInt(br.readLine());\n\t\tint s = n*(n+1)/2;\n\t\t\n\t\tif (n == 2) {\n\t\t\tSystem.out.println(\"1 1\");\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tboolean[] sieve = new boolean[s+1];\n\t\tsieve[0] = sieve[1] = true;\n\t\tfor (int j = 4; j < sieve.length; j += 2) {\n\t\t\tsieve[j] = true;\n\t\t}\n\t\tfor (int i = 3; i < sieve.length; i += 2) {\n\t\t\tif (!sieve[i]) {\n\t\t\t\tfor (int j = 3*i; j < sieve.length; j += i<<1) {\n\t\t\t\t\tsieve[j] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint i;\n\t\tfor (i = 2; i <= s/2; i++) {\n\t\t\tif (!sieve[i] && !sieve[s-i])\n\t\t\t\tbreak;\n\t\t}\n\t\tif (i > s/2) {\n\t\t\tfor (i = 2; i <= (s-3)/2; i++) {\n\t\t\t\tif (!sieve[i] && !sieve[s-3-i])\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tint j;\n\t\t\tfor (j = 0; i > n-j; j++) {\n\t\t\t\ti -= n-j;\n\t\t\t}\n\t\t\tswitch (i) {\n\t\t\tcase '1':\n\t\t\t\tSystem.out.print(\"2 1 3\");\n\t\t\t\tfor (int k = 3; k < n-j; k++) {\n\t\t\t\t\tSystem.out.print(\" 1\");\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase '2':\n\t\t\t\tSystem.out.print(\"1 2 3\");\n\t\t\t\tfor (int k = 3; k < n-j; k++) {\n\t\t\t\t\tSystem.out.print(\" 1\");\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase '3':\n\t\t\t\tSystem.out.print(\"2 2 3\");\n\t\t\t\tfor (int k = 3; k < n-j; k++) {\n\t\t\t\t\tSystem.out.print(\" 1\");\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tSystem.out.print(\"1 1 3 \");\n\t\t\t\tfor (int k = 3; k < i-1; k++) {\n\t\t\t\t\tSystem.out.print(\"1 \");\n\t\t\t\t}\n\t\t\t\tSystem.out.print(\"2\");\n\t\t\t\tfor (int k = i; k < n-j; k++) {\n\t\t\t\t\tSystem.out.print(\" 1\");\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tfor (int k = n-j; k < n; k++) {\n\t\t\t\tSystem.out.print(\" 2\");\n\t\t\t}\n\t\t\tSystem.out.println();\n\t\t}\n\t\telse {\n\t\t\tint j;\n\t\t\tfor (j = 0; i > n-j; j++) {\n\t\t\t\ti -= n-j;\n\t\t\t}\n\t\t\tfor (int k = 0; k < i-1; k++) {\n\t\t\t\tSystem.out.print(\"1 \");\n\t\t\t}\n\t\t\tSystem.out.print(\"2\");\n\t\t\tfor (int k = i; k < n-j; k++) {\n\t\t\t\tSystem.out.print(\" 1\");\n\t\t\t}\n\t\t\tfor (int k = n-j; k < n; k++) {\n\t\t\t\tSystem.out.print(\" 2\");\n\t\t\t}\n\t\t\tSystem.out.println();\n\t\t}\n\t}\n}\n", "src_uid": "94ef0d901f21e1945849fd5bfc2d1449"} {"source_code": "import java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.LinkedList;\nimport java.util.Scanner;\n\n\npublic class haha {\n\n\tpublic static void main(String[] args) {\n\t\t\n\t\tScanner in = new Scanner(System.in) ; \n\t\tint n = in.nextInt() ; \n\t\tArrayList<Integer> arr = new ArrayList<Integer>() ;\n\t\tfor(int i = 0 ; i < n ; ++i) {\n\t\t\tarr.add(in.nextInt()) ; \n\t\t}\n\t\tCollections.sort(arr) ;\n\t\tSystem.out.println(arr.get(n/2)) ; \n\t}\n}\n", "src_uid": "f03773118cca29ff8d5b4281d39e7c63"} {"source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\npublic class incARG \n{\n public static void main(String[] args) throws IOException\n {\n //Locale.setDefault (Locale.US);\n Reader in = new Reader();\n StringBuilder out = new StringBuilder();\n \n int n = in.nextInt();\n char[] bits = new char[n];\n String bitz = out.append(in.next().trim()).reverse().toString();\n for (int i = 0; i < bits.length; i++) \n bits[i]=bitz.charAt(i);\n \n BigInteger tn, bn = new BigInteger(bitz, 2);\n bn = bn.add(BigInteger.ONE);\n //System.out.println(bn+\" \"+bn.bitLength());\n \n String bites = bn.toString(2);\n if(bites.length() < bitz.length())\n {\n int c = bitz.length()-bites.length();\n bites = \"\";\n for (int u = 0; u < c; u++) \n bites += \"0\";\n bites += bn.toString(2);\n }\n //System.out.println(bites);\n //if(bn.bitLength() > n)\n int diff = 0;\n for (int i = 0, j = bites.length()-n; i < bitz.length(); i++, j++) \n if(bites.charAt(j)!=bitz.charAt(i))\n diff++;\n \n \n /*for (int i = 0; i < bitz.length()-bn.bitLength(); i++) \n bites += \"0\";\n bites += bn.toString();\n int diff = 0;\n for (int i = 0; i < bites.length(); i++) {\n if(bites.charAt(i)!=bitz.charAt(i))\n diff++;\n }*/\n System.out.println(diff);\n }\n static class Reader \n {\n BufferedReader br;\n StringTokenizer st;\n Reader() { // To read from the standard input\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n Reader(int i) throws IOException { // To read from a file\n br = new BufferedReader(new FileReader(\"Sample Input.txt\"));\n }\n String next() throws IOException {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n int nextInt() throws IOException { return Integer.parseInt(next()); }\n long nextLong() throws IOException { return Long.parseLong(next()); }\n double nextDouble() throws IOException { return Double.parseDouble(next()); }\n String nextLine() throws IOException { return br.readLine(); }\n }\n\n}", "src_uid": "54cb2e987f2cc06c02c7638ea879a1ab"} {"source_code": "\t\timport java.io.*;\nimport java.util.*;\n\t\tpublic class TreeMapDemo {\n\t\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader k=new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer str=new StringTokenizer(k.readLine(),\":\");\n\t\tString hour=str.nextToken();\n\t\tString mint=str.nextToken();\n\t\tboolean flag=true;\n\t\tint max=0;\n\t\tfor (int i = 0; i < hour.length(); i++) {\n\t\t\tif (hour.charAt(i)>='A'&&hour.charAt(i)<='Z') {\n\t\t\t\tif (max<hour.charAt(i)-'A'+10) {\n\t\t\t\t\tmax=hour.charAt(i)-'A'+10;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (max<hour.charAt(i)-'0') {\n\t\t\t\tmax=hour.charAt(i)-'0';\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < mint.length(); i++) {\n\t\t\tif (mint.charAt(i)>='A'&&mint.charAt(i)<='Z') {\n\t\t\t\tif (max<mint.charAt(i)-'A'+10) {\n\t\t\t\t\tmax=mint.charAt(i)-'A'+10;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (max<mint.charAt(i)-'0') {\n\t\t\t\tmax=mint.charAt(i)-'0';\n\t\t\t}\n\t\t}\n\t\tmax++;\n\t\tif (max==1) {\n\t\t\tSystem.out.println(-1);\n\t\t\treturn;\n\t\t}\n\t\tString base=\"\";\n\t\tint count=0;\n\t\twhile (max<61) {\n\t\t\tlong x=0,y=0;\n\t\t\tif (max>=37) {\n\t\t\t\t x=getvalue(hour, max);\n\t\t\t\t y=getvalue(mint, max);\n\t\t\t}\n\t\t\telse{\n\t\t\t x=Long.parseLong(hour,max);\n\t\t\t y=Long.parseLong(mint,max);\n\t\t\t}\n\t\t\tif (x<24&&y<60) {\n\t\t\t\tbase+=max+\" \";\n\t\t\t\tmax++;\n\t\t\t\tcount++;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tflag=false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (flag) {\n\t\t\tSystem.out.println(-1);\n\t\t}\n\t\telse if (count==0) {\n\t\t\tSystem.out.println(0);\n\t\t}\n\t\telse {\n\t\t\tSystem.out.println(base);\n\t\t}\n\t\t\n\t\t}\n\t\tpublic static long getvalue(String num,int base){\n\t\t\tint counter=0;\n\t\t\tlong x=0;\n\t\t\tfor (int i = num.length()-1; i >= 0; i--) {\n\t\t\t\tif (num.charAt(i)>='A'&&num.charAt(i)<'Z') {\n\t\t\t\t\tx+=(num.charAt(i)-'A'+10)*Math.pow(base, counter);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tx+=(num.charAt(i)-'0')*Math.pow(base, counter);\n\t\t\t\t}\n\t\t\t\tcounter++;\n\t\t\t}\n\t\t\treturn x;\n\t\t\t\n\t\t\t\n\t\t}\n\t\t}", "src_uid": "c02dfe5b8d9da2818a99c3afbe7a5293"} {"source_code": "\nimport javax.print.DocFlavor;\nimport javax.swing.*;\nimport java.lang.reflect.Array;\nimport java.util.*;\nimport java.io.*;\npublic class Main {\n static int max;\n static int min;\n static int d;\n static void combinations(int[] arr,int index,ArrayList<ArrayList<Integer>> ans,ArrayList<Integer> al){\n if(al.size()>=2) {\n int sum = 0;\n for (int i = 0; i < al.size(); i++) {\n sum += al.get(i);\n }\n if (sum >= min && sum <= max && al.get(al.size() - 1)-al.get(0)>=d) {\n ans.add(new ArrayList<>(al));\n }\n }\n\n for(int i=index;i<arr.length;i++){\n al.add(arr[i]);\n combinations(arr,i+1,ans,al);\n al.remove(al.size()-1);\n }\n }\n public static void main(String[] args) throws IOException {\n //Code starts\n FastReader ip = new FastReader();\n OutputStream output = System.out;\n PrintWriter out = new PrintWriter(output);\n int n=ip.nextInt();\n min=ip.nextInt();\n max=ip.nextInt();\n d=ip.nextInt();\n int[] arr=new int[n];\n for(int i=0;i<n;i++){\n arr[i]=ip.nextInt();\n }\n Arrays.sort(arr);\n ArrayList<ArrayList<Integer>> ans=new ArrayList<>();\n ArrayList<Integer> al=new ArrayList<>();\n combinations(arr,0,ans,al);\n out.print(ans.size());\n out.close();\n //Code ends\n }\n\n static class FastReader {\n BufferedReader br;\n StringTokenizer st;\n FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); }\n String next() { while (st == null || !st.hasMoreElements()) {\n try { st = new StringTokenizer(br.readLine()); }\n catch (IOException e) { e.printStackTrace(); } }\n return st.nextToken();\n }\n\n int nextInt() { return Integer.parseInt(next()); }\n long nextLong() { return Long.parseLong(next()); }\n double nextDouble() { return Double.parseDouble(next()); }\n\n String nextLine() {\n String str = \"\";\n try { str = br.readLine(); }\n catch (IOException e) { e.printStackTrace(); }\n return str;\n }\n }\n\n}", "src_uid": "0d43104a0de924cdcf8e4aced5aa825d"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Test{\n public static void main(String args[]){\n \n Scanner sc = new Scanner(System.in);\n \n long l1 = sc.nextLong();\n long r1 = sc.nextLong();\n long l2 = sc.nextLong();\n long r2 = sc.nextLong();\n long k = sc.nextLong();\n \n long p = Math.max(l1,l2);//System.out.println(q);\n long q = Math.min(r1,r2);//System.out.println(p);\n \n long ans =0;\n if(k<=q && k>=p)\n ans=q-p;\n else\n ans = q-p+1;\n \n \n if(ans>0)\n System.out.println(ans);\n else System.out.println(0);\n \n }\n}", "src_uid": "9a74b3b0e9f3a351f2136842e9565a82"} {"source_code": "import java.util.*;\n \npublic class TV1 {\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 ans = 0;\n\t\tint a[] = new int[3];\n\t\tfor(int i = 0 ;i<3;i++) {\n\t\t\t\n\t\t\ta[i] = sc.nextInt();\n\t\t}\n\t\tArrays.sort(a);\n\t\tint d = sc.nextInt();\n\t\tint sum = 0;\n\t\t\n\t\tint p = a[2]-a[1];\n\t\tint q = a[1]-a[0];\n\t\t\n\t\tif(p<d) {\n\t\t\t\n\t\t\tans = ans + d-p;\t\n\t\t}\n\t\tif(q<d) {\n\t\t\t\n\t\t\tans = ans + d-q;\n\t\t}\n\t\t\n\t\tSystem.out.println(ans);\n\t}\n \n}", "src_uid": "47c07e46517dbc937e2e779ec0d74eb3"} {"source_code": "import java.io.*;\nimport java.util.*;\n\n\npublic class Main {\n\n static StringBuilder data = new StringBuilder();\n final static FastReader in = new FastReader();\n\n\n public static void main(String[] args) {\n int n=in.nextInt();\n int []a = new int[1000*1000+1];\n for (int i = 2; i < a.length; i++) {\n for (int j = i+i; j < a.length; j+=i) {\n a[j]=1;\n }\n\n }\n for (int i = 1; i < a.length; i++) {\n if(a[n*i+1]==1){\n System.out.println(i);\n break;\n }\n }\n\n }\n\n\n static void fileOut(String s) {\n File out = new File(\"output.txt\");\n try {\n FileWriter fw = new FileWriter(out);\n fw.write(s);\n fw.flush();\n fw.close();\n } catch (IOException e) {\n e.printStackTrace();\n }\n\n }\n\n static class FastReader {\n BufferedReader br;\n StringTokenizer st;\n\n public FastReader() {\n br = new BufferedReader(new\n InputStreamReader(System.in));\n }\n\n public FastReader(String path) {\n try {\n br = new BufferedReader(new\n InputStreamReader(new FileInputStream(path)));\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n float nextFloat() {\n return Float.parseFloat(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n\n 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}", "src_uid": "5c68e20ac6ecb7c289601ce8351f4e97"} {"source_code": "import java.util.Scanner;\n\npublic class Draw\n{\n\n public static void main (String[] args) throws java.lang.Exception\n {\n Scanner myScanner = new Scanner(System.in);\n\n int n = myScanner.nextInt();\n \n System.out.println(n*3/2);\n \n myScanner.close();\n }\n}", "src_uid": "031e53952e76cff8fdc0988bb0d3239c"} {"source_code": "import java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.util.Comparator;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Egor Kulikov (egor@egork.net)\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tOutputWriter out = new OutputWriter(outputStream);\n\t\tTaskC solver = new TaskC();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskC {\n\tpublic void solve(int testNumber, InputReader in, OutputWriter out) {\n\t\tchar[] s = in.readString().toCharArray();\n\t\tlong[][] answer = new long[2][2];\n\t\tlong[][] next = new long[2][2];\n\t\tanswer[0][0] = answer[1][1] = 1;\n\t\tfor (int i = 1; i <= s.length; i++) {\n\t\t\tint currentLetter = s[i - 1] - 'A';\n\t\t\tint nextLetter = s[i % s.length] - 'A';\n\t\t\tArrayUtils.fill(next, 0);\n\t\t\tif (currentLetter == 0) {\n\t\t\t\tif (nextLetter == 0) {\n\t\t\t\t\tfor (int j = 0; j < 2; j++) {\n\t\t\t\t\t\tnext[j][0] = answer[j][1] + answer[j][0];\n\t\t\t\t\t\tnext[j][1] = 0;\n\t\t\t\t\t}\n\t\t\t\t} else if (nextLetter == 1) {\n\t\t\t\t\tfor (int j = 0; j < 2; j++) {\n\t\t\t\t\t\tnext[j][0] = answer[j][1] + answer[j][0];\n\t\t\t\t\t\tnext[j][1] = answer[j][1];\n\t\t\t\t\t}\t\t\t\t\t\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (nextLetter == 0) {\n\t\t\t\t\tfor (int j = 0; j < 2; j++) {\n\t\t\t\t\t\tnext[j][0] = answer[j][1];\n\t\t\t\t\t\tnext[j][1] = answer[j][0];\n\t\t\t\t\t}\n\t\t\t\t} else if (nextLetter == 1) {\n\t\t\t\t\tfor (int j = 0; j < 2; j++) {\n\t\t\t\t\t\tnext[j][0] = answer[j][1];\n\t\t\t\t\t\tnext[j][1] = answer[j][1];\n\t\t\t\t\t}\t\t\t\t\t\n\t\t\t\t}\t\t\t\t\n\t\t\t}\n\t\t\tlong[][] temp = next;\n\t\t\tnext = answer;\n\t\t\tanswer = temp;\n\t\t}\n\t\tlong result = answer[0][0] + answer[1][1];\n\t\tout.printLine(result);\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\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 String readString() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tStringBuffer res = new StringBuffer();\n\t\tdo {\n\t\t\tres.appendCodePoint(c);\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res.toString();\n\t}\n\n\tpublic static boolean isSpaceChar(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n\n\t}\n\nclass OutputWriter {\n\tprivate final PrintWriter writer;\n\n\tpublic OutputWriter(OutputStream outputStream) {\n\t\twriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n\t}\n\n\tpublic OutputWriter(Writer writer) {\n\t\tthis.writer = new PrintWriter(writer);\n\t}\n\n\tpublic void print(Object...objects) {\n\t\tfor (int i = 0; i < objects.length; i++) {\n\t\t\tif (i != 0)\n\t\t\t\twriter.print(' ');\n\t\t\twriter.print(objects[i]);\n\t\t}\n\t}\n\n\tpublic void printLine(Object...objects) {\n\t\tprint(objects);\n\t\twriter.println();\n\t}\n\n\tpublic void close() {\n\t\twriter.close();\n\t}\n\n\t}\n\nclass ArrayUtils {\n\n\tpublic static void fill(long[][] array, long value) {\n\t\tfor (long[] row : array)\n\t\t\tArrays.fill(row, value);\n\t}\n\n\t}\n\n", "src_uid": "ad27d991516054ea473b384bb2563b38"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class E implements Runnable {\n\n\tprivate void solve() throws IOException {\n\t\tint n = nextInt();\n\t\tString s = nextToken();\n\t\tint[] digits = new int[2 * n];\n\t\tfor (int i = 0; i < 2 * n; i++) {\n\t\t\tdigits[i] = s.charAt(2 * n - 1 - i) - '0';\n\t\t}\n\t\tlong[] pows = new long[n];\n\t\tpows[0] = 1;\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\tpows[i] = pows[i - 1] * 10;\n\t\t}\n\t\tlong[][] d = new long[n + 1][n + 1];\n\t\td[0][0] = 0;\n\t\tfor (int sum = 1; sum <= 2 * n; sum++) {\n\t\t\tfor (int i = Math.max(sum - n, 0); i <= Math.min(sum, n); i++) {\n\t\t\t\tint j = sum - i;\n\t\t\t\tif (i > 0)\n\t\t\t\t\td[i][j] = Math.max(d[i][j], d[i - 1][j] + digits[sum - 1]\n\t\t\t\t\t\t\t* pows[i - 1]);\n\t\t\t\tif (j > 0)\n\t\t\t\t\td[i][j] = Math.max(d[i][j], d[i][j - 1] + digits[sum - 1]\n\t\t\t\t\t\t\t* pows[j - 1]);\n\t\t\t}\n\t\t}\n\n\t\tboolean[] res = new boolean[2 * n];\n\t\tint c1 = n, c2 = n;\n\t\twhile (c1 + c2 > 0) {\n\t\t\tint sum = c1 + c2;\n\t\t\tif (c1 > 0\n\t\t\t\t\t&& d[c1][c2] == d[c1 - 1][c2] + digits[sum - 1]\n\t\t\t\t\t\t\t* pows[c1 - 1]) {\n\t\t\t\tres[sum - 1] = true;\n\t\t\t\tc1--;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (c2 > 0\n\t\t\t\t\t&& d[c1][c2] == d[c1][c2 - 1] + digits[sum - 1]\n\t\t\t\t\t\t\t* pows[c2 - 1]) {\n\t\t\t\tres[sum - 1] = false;\n\t\t\t\tc2--;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tboolean t = res[i];\n\t\t\tres[i] = res[2 * n - 1 - i];\n\t\t\tres[2 * n - 1 - i] = t;\n\t\t}\n\n\t\tfor (int i = 0; i < 2 * n; i++) {\n\t\t\tout.print(res[i] ? 'H' : 'M');\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new E()).start();\n\t}\n\n\tBufferedReader br;\n\tStringTokenizer st;\n\tPrintWriter out;\n\tboolean eof = false;\n\n\tpublic void run() {\n\t\tLocale.setDefault(Locale.US);\n\t\ttry {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsolve();\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\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 \"0\";\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\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}", "src_uid": "98489fe54488dcfb45f8ae7b5c473d88"} {"source_code": "import java.util.*;\nimport java.io.*;\n\npublic class R554D\n{\n\t\n\tstatic long mod = (long)(1e9)+7;\n\tstatic long[] fact = new long[3000];\n\tstatic int n;\n\tstatic long[][][] memo;\n\t\n\t\n public static void main (String[] args) \n { \n JS scan = new JS();\n n = scan.nextInt();\n memo = new long[2][n+1][n+1];\n for(int i = 0; i < 2; i++){\n \tfor(int j = 0; j <= n; j++){\n \t\tArrays.fill(memo[i][j], -1);\n \t}\n }\n System.out.println(solve(0, 0, 0)); //DON'T SUBMIT BEFORE YOU MOD\n }\n \n static long solve(int cant, int i, int j){\n \tif(memo[cant][i][j] != -1) return memo[cant][i][j];\n \tlong resNoTake = 0;\n \tif(i < n) resNoTake += solve(0, i+1, j);\n \tif(j < i) resNoTake += solve(0, i, j+1);\n \tresNoTake %= mod;\n \tif(cant == 1) return memo[cant][i][j] = resNoTake;\n \t\n \tlong resTake = 0;\n \tlong op1 = 0;\n \tlong op2 = 0;\n \tif(i < n){\n \t\top1 = 1+solve(1, i+1, j);\n \t\tif(j < i){\n \t\t\top1 += solve(0, i, j+1);\n \t\t}\n \t\top1 %= mod;\n \t}\n \tif(j < i){\n \t\top2 = 1+solve(1, i, j+1);\n \t\tif(i < n){\n \t\t\top2 += solve(0, i+1, j);\n \t\t}\n \t\top2 %= mod;\n \t}\n \tresTake = Math.max(op1, op2);\n \t\n \treturn memo[cant][i][j] = Math.max(resTake, resNoTake);\n }\n \n \n static long power(long x, long y, long p) \n { \n // Initialize result \n \tlong res = 1; \n \n // Update x if it is more than or \n // equal to p \n x = x % p; \n \n while (y > 0) \n { \n \n // If y is odd, multiply x \n // with result \n if (y % 2 == 1) \n res = (res * x) % p; \n \n // y must be even now \n y = y >> 1; // y = y/2 \n x = (x * x) % p; \n } \n return res; \n } \n \n // Returns n^(-1) mod p \n static long modInverse(long n, long p) \n { \n return power(n, p-2, p); \n } \n\t\n\tstatic void _printParenthesis(char str[], int pos, int n, int open, int close) \n { \n if(close == n) \n { \n // print the possible combinations \n for(int i=0;i<str.length;i++) \n System.out.print(str[i]); \n System.out.println(); \n return; \n } \n else\n { \n if(open > close) { \n str[pos] = '}'; \n _printParenthesis(str, pos+1, n, open, close+1); \n } \n if(open < n) { \n str[pos] = '{'; \n _printParenthesis(str, pos+1, n, open+1, close); \n } \n } \n } \n \n // Wrapper over _printParenthesis() \n static void printParenthesis(char str[], int n) \n { \n if(n > 0) \n _printParenthesis(str, 0, n, 0, 0); \n return; \n } \n \n \n\n\t\n\tstatic class JS{\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 JS() {\n\t\t\tin = new BufferedInputStream(System.in, BS);\n\t\t}\n\n\t\tpublic JS(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}\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}\n}\n", "src_uid": "8218255989e5eab73ac7107072c3b2af"} {"source_code": "import java.io.*;\npublic class Lucky_Numbers {\npublic static void main(String ar[])throws IOException\n{\n\tlong n;\n\tlong sum=0;\n\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\tn=Long.parseLong(br.readLine());\n\tSystem.out.println(((long)Math.pow(2,n)-1)*2);\n}\n}\n", "src_uid": "f1b43baa14d4c262ba616d892525dfde"} {"source_code": "\nimport java.io.FileInputStream;\nimport java.io.IOException;\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\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 c[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}", "src_uid": "d1e381b72a6c09a0723cfe72c0917372"} {"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.FileReader;\nimport java.io.InputStreamReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author zodiacLeo\n */\npublic class Main\n{\n public static void main(String[] args)\n {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastScanner in = new FastScanner(inputStream);\n 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 {\n private int[] rx;\n private int[] ry;\n private int[] dx;\n private int[] dy;\n\n public void solve(int testNumber, FastScanner in, PrintWriter out)\n {\n int n = in.nextInt();\n dx = new int[n];\n dy = new int[n];\n rx = new int[n];\n ry = new int[n];\n String ns = in.next();\n for (int i = 0; i < n; i++)\n {\n int num = ns.charAt(i) - '0';\n //out.println(num);\n if (num == 0)\n {\n rx[i] = 3;\n ry[i] = 1;\n } else\n {\n rx[i] = (num - 1) / 3;\n ry[i] = (num - 1) % 3;\n }\n if (i > 0)\n {\n dx[i] = rx[i] - rx[i - 1];\n dy[i] = ry[i] - ry[i - 1];\n }\n }\n\n for (int i = 0; i < 3; i++)\n {\n for (int j = 0; j < 3; j++)\n {\n if (i == rx[0] && j == ry[0])\n {\n continue;\n }\n if (move(i, j))\n {\n out.println(\"NO\");\n return;\n }\n }\n }\n if (rx[0] != 3 || ry[0] != 1)\n {\n if (move(3, 1))\n {\n out.println(\"NO\");\n } else\n {\n out.println(\"YES\");\n }\n } else\n {\n out.println(\"YES\");\n }\n }\n\n public boolean move(int r1, int c1)\n {\n for (int i = 1; i < dx.length; i++)\n {\n int r2 = r1 + dx[i];\n int c2 = c1 + dy[i];\n if (r2 == 3 && c2 == 1)\n {\n r1 = r2;\n c1 = c2;\n continue;\n }\n if (r2 >= 0 && r2 <= 2 && c2 >= 0 && c2 <= 2)\n {\n r1 = r2;\n c1 = c2;\n continue;\n }\n return false;\n }\n return true;\n }\n\n }\n\n static class FastScanner\n {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(InputStream is)\n {\n br = new BufferedReader(new InputStreamReader(is));\n }\n\n public FastScanner(File f)\n {\n try\n {\n br = new BufferedReader(new FileReader(f));\n } catch (FileNotFoundException e)\n {\n e.printStackTrace();\n }\n }\n\n public String next()\n {\n while (st == null || !st.hasMoreElements())\n {\n String s = null;\n try\n {\n s = br.readLine();\n } catch (IOException e)\n {\n e.printStackTrace();\n }\n if (s == null)\n return null;\n st = new StringTokenizer(s);\n }\n return st.nextToken();\n }\n\n public int nextInt()\n {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "src_uid": "d0f5174bb0bcca5a486db327b492bf33"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class C {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\t\n\tstatic final int MOD = 1_000_000_009;\n\t\n\tint[] fact, invFact;\n\t\n\tint pow(int a, int b) {\n\t\tint res = 1;\n\t\twhile (b != 0) {\n\t\t\tif ((b & 1) == 1) {\n\t\t\t\tres = (int)((long) res * a % MOD);\n\t\t\t}\n\t\t\ta = (int)((long)a * a % MOD);\n\t\t\tb >>= 1;\n\t\t}\n\t\treturn res;\n\t}\n\t\n\tint C(int n, int k) {\n\t\tif (n < 0 || k < 0 || k > n)\n\t\t\treturn 0;\n\t\treturn (int)((long)fact[n] * invFact[k] % MOD * invFact[n - k] % MOD);\n\t}\n\n\tvoid solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint w = nextInt();\n\t\tint b = nextInt();\n\t\t\n\t\tfact = new int[n + Math.max(w, b)];\n\t\tinvFact = new int[fact.length];\n\t\t\n\t\tfact[0] = invFact[0] = 1;\n\t\tfor (int i = 1; i < fact.length; i++) {\n\t\t\tfact[i] = (int)((long)fact[i - 1] * i % MOD);\n\t\t\tinvFact[i] = pow(fact[i], MOD - 2);\n\t\t}\n\t\t\n\t\tint ans = 0;\n\t\t\n\t\tfor (int lenB = 1; lenB <= n - 2 && lenB <= b; lenB++) {\n\t\t\tint ways = (int)((long)(n - 1 - lenB) * C(b - 1, lenB - 1) % MOD * C(w - 1, n - lenB - 1) % MOD);\n//\t\t\tSystem.err.println(b + \" \" + lenB);\n//\t\t\tSystem.err.println(w + \" \" + (n - lenB));\n\t\t\tans += ways;\n\t\t\tif (ans >= MOD)\n\t\t\t\tans -= MOD;\n\t\t}\n\t\t\n\t\tans = (int)((long)ans * fact[b] % MOD * fact[w] % MOD);\n\t\tout.println(ans);\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}", "src_uid": "63e93a161bbff623323e66c98d5e20ac"} {"source_code": "import java.lang.*;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n/**\n *\n * @author Mido\n */\npublic class Test {\n\n /**\n * @param args the command\n */\n public static int weight(char c)\n {\n c=Character.toLowerCase(c);\n switch(c)\n {\n case 'q': return 9;\n case 'r': return 5;\n case 'b': return 3;\n case 'n': return 3;\n case 'p': return 1;\n case 'k':\n break;\n }\n return 0;\n }\n public static void main(String[] args) {\n int j,i,w,b;\n String ans;\n char c;\n String []a=new String[8];\n Scanner sc=new Scanner(System.in);\n w=b=0;\n for(i=0;i<8;i++) a[i]=sc.next();\n for(i=0;i<8;i++) \n {\n for(j=0;j<8;j++) \n {\n c=a[i].charAt(j);\n \n if(c!='.')\n {\n if(c>='a'&&c<='z')b+=weight(c);\n else w+=weight(c);\n }\n }\n }\n if(w>b)System.out.println(\"White\");\n else if(w<b)System.out.println(\"Black\");\n else System.out.println(\"Draw\");\n } \n\n \n}\n", "src_uid": "44bed0ca7a8fb42fb72c1584d39a4442"} {"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 and_so_on\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n Scanner in = new Scanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskA solver = new TaskA();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskA {\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n\n int n = in.nextInt();\n String home = in.next();\n int count = 0;\n for (int i = 0; i < n; i++) {\n count++;\n }\n\n if (count % 2 == 0) {\n out.println(\"home\");\n } else {\n out.println(\"contest\");\n }\n }\n\n }\n}\n\n", "src_uid": "51d1c79a52d3d4f80c98052b6ec77222"} {"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 Sparsh Sanchorawala\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n FCards solver = new FCards();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class FCards {\n long mod = 998244353;\n\n long modExp(long x, long y) {\n if (y == 0)\n return 1;\n if (y == 1)\n return x;\n long ret = modExp(x, y >> 1);\n ret = ret * ret % mod;\n if ((y & 1) == 1)\n ret = ret * x % mod;\n return ret;\n }\n\n public void solve(int testNumber, InputReader s, PrintWriter w) {\n int n = s.nextInt(), m = s.nextInt(), k = s.nextInt();\n //dp[tuple size][number of distinct elements] = number of such tuples\n long[][] dp = new long[k + 1][Math.min(n, k) + 1];\n dp[0][0] = 1;\n for (int i = 1; i <= k; i++) {\n for (int j = 1; j <= Math.min(n, k); j++) {\n dp[i][j] = (dp[i][j] + dp[i - 1][j] * j % mod) % mod;\n dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] * (n - j + 1) % mod) % mod;\n }\n }\n long invm = modExp(m, mod - 2);\n long res = 0;\n long prob = 1;\n for (int i = 0; i <= Math.min(n, k); i++) {\n res = (res + dp[k][i] * prob % mod) % mod;\n prob = prob * invm % mod;\n }\n w.println(res);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "src_uid": "e6b3e559b5fd4e05adf9f1cd1b22126b"} {"source_code": "\nimport java.io.*;\npublic class Eqn {\n\tpublic static void main(String[] args)throws IOException {\n\t\tBufferedReader ob=new BufferedReader(new InputStreamReader(System.in));\n\t\tString s[]=ob.readLine().split(\" \");\n\t\tint n=Integer.parseInt(s[0]);\n\t\tint m=Integer.parseInt(s[1]);\n\t\tint c=0;\n\t\tfor(int i=0;i<=1000;i++) {\n\t\t\tfor(int j=0;j<=1000;j++) {\n\t\t\t\tint x=i*i + j;\n\t\t\t\tint y=j*j + i;\n\t\t\t\tif(x==n && y==m)\n\t\t\t\t\tc++;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(c);\n\t}\n\n}\n", "src_uid": "03caf4ddf07c1783e42e9f9085cc6efd"} {"source_code": "import java.util.Scanner;\n\n\npublic class muhandstick {\n\n public static void main(String[] args) {\n \n Scanner s = new Scanner(System.in);\n int [] c=new int[6]; int op=0;\n int [] c1=new int[6];\n int count=0,k=-1,k1=-1;\n for(int i=0;i<6;i++)\n {\n c[i]=s.nextInt();\n }\n int p=1;\n for(int i=0;i<6;i++)\n {count=0;\n p=0;\n for(int j=0;j<6;j++)\n {\n if(c[i]==c[j])\n {\n count++;\n if(count==4)\n {p=c[j];\n op=1;\n break;\n }\n }\n \n }\n if(count==4)\n {\n \n break;\n }\n }\n \n if(count==4)\n {\n for(int i=0;i<6;i++)\n {\n if(c[i]!=p)\n \n {\n \n if(k!=-1)\n {\n k1=c[i];\n break;\n }\n k=c[i];\n }\n }\n \n if(k==k1)\n {\n System.out.println(\"Elephant\");\n }\n else\n System.out.println(\"Bear\");\n \n }\n else\n {\n System.out.println(\"Alien\");\n }\n }\n \n}\n \n", "src_uid": "43308fa25e8578fd9f25328e715d4dd6"} {"source_code": "import java.util.*;\npublic class C {\n\tScanner sc = new Scanner(System.in);\n\n\tvoid doIt()\n\t{\n\t\tint n = sc.nextInt();\n\t\tUnionFindTree uft = new UnionFindTree(n);\n\t\tint k = sc.nextInt();\n\t\tfor(int i = 0; i < k; i++) {\n\t\t\tint u = sc.nextInt()-1, v = sc.nextInt()-1;\n\t\t\tuft.unite(u, v);\n\t\t}\n\t\tHashMap<Integer, Integer> grp = new HashMap<Integer, Integer>();\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tint root = uft.find(i);\n\t\t\tif(grp.containsKey(root)) {\n\t\t\t\tgrp.put(root, grp.get(root)+1);\n\t\t\t} else {\n\t\t\t\tgrp.put(root, 1);\n\t\t\t}\n\t\t}\n\t\tint m = sc.nextInt();\n\t\tfor(int i = 0; i < m; i++) {\n\t\t\tint u = sc.nextInt()-1, v = sc.nextInt()-1;\n\t\t\tint r1 = uft.find(u), r2 = uft.find(v);\n\t\t\tif(r1 == r2) grp.put(r1, 0);\n\t\t}\n\t\tint ans = 0;\n\t\tfor(Integer key: grp.keySet()) {\n\t\t\t//System.out.println(key + \" \" + grp.get(key));\n\t\t\tans = Math.max(ans, grp.get(key));\n\t\t}\n\t\tif(ans <= 0) ans = 0;\n\t\tSystem.out.println(ans);\n\t\t\n\t}\n\tpublic static void main(String[] args) {\n\t\tnew C().doIt();\n\t}\n\tclass UnionFindTree\n\t{\n\t\tint [] par, rank;\n\t\tUnionFindTree(int n)\n\t\t{\n\t\t\tpar = new int [n];\n\t\t\trank = new int [n];\n\t\t\tfor(int i = 0; i < n; i++) par[i] = i;\n\t\t}\n\t\tint find (int x) {\n\t\t\tif(par[x] == x) {\n\t\t\t\treturn x;\n\t\t\t} else {\n\t\t\t\treturn par[x] = find(par[x]);\n\t\t\t}\n\t\t}\n\t\tvoid unite(int x, int y)\n\t\t{\n\t\t\tx = find(x);\n\t\t\ty = find(y);\n\t\t\tif( x == y) return;\n\t\t\t\n\t\t\tif(rank[x] < rank[y]) {\n\t\t\t\tpar[x] = y;\n\t\t\t} else {\n\t\t\t\tpar[y] = x;\n\t\t\t\tif (rank[x] == rank[y]) rank[x]++;\n\t\t\t}\n\t\t}\n\t\tboolean same(int x, int y)\n\t\t{\n\t\t\treturn find(x) == find(y);\n\t\t}\n\t}\n}\n", "src_uid": "e1ebaf64b129edb8089f9e2f89a0e1e1"} {"source_code": "//package com.codeforce.challenge;\n\nimport java.util.Scanner;\n\npublic class CodeForce {\n\n\tpublic static void main(String[] args) {\n\n\t\tScanner sc = new Scanner(System.in);\n\n\t\tint a = sc.nextInt();\n\t\tint b = sc.nextInt();\n\n\t\tint c = 0;\n\t\t\n\t\twhile (a <= b) {\n\t\t\ta *= 3;\n\t\t\tb *= 2;\n\t\t\tc++;\n\n\t\t};\n\n\t\tSystem.out.println(c);\n\t}\n}\n", "src_uid": "a1583b07a9d093e887f73cc5c29e444a"} {"source_code": " \nimport java.util.Scanner;\npublic class Main {\n Scanner input=new Scanner(System.in);\n \n\tpublic static void main(String[] args) {\n\t\tScanner input=new Scanner(System.in);\n\t\tint n=input.nextInt();\n String arr=input.next();\n int count=0;\n for(int i=0;i<arr.length()-1;i++) {\n \tif((arr.charAt(i)=='U'&&arr.charAt(i+1)=='R')||(arr.charAt(i)=='R'&&arr.charAt(i+1)=='U')) {\n \t\tcount++;\n \t\ti=i+1;\n \t}\n }\n System.out.print(arr.length()-count);\n\t}\n\n}", "src_uid": "986ae418ce82435badadb0bd5588f45b"} {"source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.TreeSet;\nimport java.io.BufferedOutputStream;\nimport java.util.StringTokenizer;\nimport java.io.Writer;\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 An Almost Retired Guy\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 MogohuReaIdol solver = new MogohuReaIdol();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class MogohuReaIdol {\n void add(TreeSet<Point> set, Point point) {\n Point l = set.lower(point);\n if (l == null) set.add(point);\n else {\n Point r = set.higher(point);\n if (r == null || l.ccw(point, r)) set.add(point);\n else return;\n }\n l = set.lower(point);\n if (l != null) while (true) {\n Point ll = set.lower(l);\n if (ll == null || ll.ccw(l, point)) break;\n set.remove(l);\n l = ll;\n }\n Point r = set.higher(point);\n if (r == null) return;\n while (true) {\n Point rr = set.higher(r);\n if (rr == null || point.ccw(r, rr)) break;\n set.remove(r);\n r = rr;\n }\n }\n\n boolean test(TreeSet<Point> set, Point point) {\n if (set.contains(point)) return true;\n Point l = set.lower(point);\n if (l == null) return false;\n Point r = set.higher(point);\n if (r == null) return false;\n return !l.ccw(point, r);\n }\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n Point[] sum = minkowskiSum(minkowskiSum(readPolygon(in), readPolygon(in)), readPolygon(in));\n Point[] query = readPolygon(in);\n for (int i = 0; i < query.length; i++) query[i] = query[i].mul(3);\n TreeSet<Point> lower = new TreeSet<>(), upper = new TreeSet<>((i, j) -> j.compareTo(i));\n for (Point P : sum) {\n add(lower, P);\n add(upper, P);\n }\n for (Point P : query) {\n boolean ans = test(lower, P) && test(upper, P);\n out.println(ans ? \"YES\" : \"NO\");\n }\n }\n\n Point[] minkowskiSum(Point[] A, Point[] B) {\n int idxA = 0, idxB = 0;\n for (int i = 1; i < A.length; i++) if (A[i].compareTo(A[idxA]) < 0) idxA = i;\n for (int i = 1; i < B.length; i++) if (B[i].compareTo(B[idxB]) < 0) idxB = i;\n Point[] ans = new Point[A.length + B.length];\n Point P = A[idxA].add(B[idxB]);\n for (int i = 0, j = 0; i < A.length || j < B.length; ) {\n ans[i + j] = P;\n int I = idxA + i, J = idxB + j;\n Point U = new Point(A[I % A.length], A[(I + 1) % A.length]), V = new Point(B[J % B.length], B[(J + 1) % B.length]);\n if (j == B.length || (i < A.length && U.cross(V) >= 0)) {\n P = P.add(U);\n i++;\n } else {\n P = P.add(V);\n j++;\n }\n }\n return ans;\n }\n\n Point[] readPolygon(InputReader in) {\n int n = in.nextInt();\n Point[] ans = new Point[n];\n for (int i = 0; i < n; i++) ans[i] = new Point(in.nextInt(), in.nextInt());\n return ans;\n }\n\n class Point extends ConvexHull.Point implements Comparable<Point> {\n Point(int x, int y) {\n super(x, y);\n }\n\n Point(Point A, Point B) {\n this(B.x - A.x, B.y - A.y);\n }\n\n\n public int compareTo(Point that) {\n int cmp = Integer.compare(this.x, that.x);\n if (cmp != 0) return cmp;\n return Integer.compare(this.y, that.y);\n }\n\n long cross(Point that) {\n return (long) this.x * that.y - (long) this.y * that.x;\n }\n\n Point add(Point that) {\n return new Point(this.x + that.x, this.y + that.y);\n }\n\n Point mul(int factor) {\n return new Point(x * factor, y * factor);\n }\n\n boolean ccw(Point A, Point B) {\n Point U = new Point(A.x - x, A.y - y), V = new Point(B.x - x, B.y - y);\n long cross = (long) U.x * V.y - (long) U.y * V.x;\n return cross > 0;\n }\n\n }\n\n }\n\n static class ConvexHull {\n public static class Point {\n public final int x;\n public final int y;\n\n public Point(int x, int y) {\n this.x = x;\n this.y = y;\n }\n\n }\n\n }\n\n static class OutputWriter extends PrintWriter {\n public OutputWriter(OutputStream outputStream) {\n super(new BufferedOutputStream(outputStream));\n }\n\n public OutputWriter(Writer writer) {\n super(writer);\n }\n\n public void close() {\n super.close();\n }\n\n }\n\n static class InputReader {\n BufferedReader br;\n StringTokenizer st;\n\n public InputReader(InputStream inputStream) {\n br = new BufferedReader(new InputStreamReader(inputStream));\n }\n\n public String next() {\n while (st == null || !st.hasMoreElements()) {\n st = new StringTokenizer(nextLine());\n }\n return st.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public String nextLine() {\n try {\n return br.readLine();\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n\n }\n}\n\n", "src_uid": "a764daf8e19e48a0735811a4f67485c3"} {"source_code": "import java.io.*;\nimport java.util.StringTokenizer;\n\n\npublic class Main {\n static final int mod = (int) 1e9 + 7;\n\n public static void main(String[] args) throws IOException {\n Scanner sc = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n int a = sc.nextInt(), b = sc.nextInt(), n = sc.nextInt();\n int[] fac = new int[n + 1];\n fac[0] = 1;\n for (int i = 1; i <= n; i++)\n fac[i] = (int) ((1l*fac[i - 1] * i) % mod);\n int ans = 0;\n for (int as = 0; as <= n; as++) {\n int bs = n - as;\n int sum = as * a + bs * b;\n if (!checkGood(sum, a, b)) continue;\n ans = (int) ((ans + ((1l * fac[n] * modInverse(fac[as])) % mod * modInverse(fac[bs]))) % mod);\n }\n out.println(ans);\n out.close();\n out.flush();\n }\n\n static boolean checkGood(int n, int a, int b) {\n while (n != 0) {\n int cur = n % 10;\n if (cur != a && cur != b) return false;\n n /= 10;\n }\n return true;\n }\n\n static int modInverse(int n) {\n int res = 1;\n int e = mod - 2;\n while (e > 0) {\n if ((e & 1) == 1) res = (int) ((1l*res * n) % mod);\n n = (int) ((1l * n * n) % mod);\n e >>= 1;\n }\n return (res % mod);\n }\n\n\n static class Scanner {\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner(InputStream system) {\n br = new BufferedReader(new InputStreamReader(system));\n }\n\n\n public String next() throws IOException {\n while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n public String nextLine() throws IOException {\n return br.readLine();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n public char nextChar() throws IOException {\n return next().charAt(0);\n }\n\n public Long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public boolean ready() throws IOException {\n return br.ready();\n }\n\n\n public int[] nextIntArray(int n) throws IOException {\n int[] a = new int[n];\n for (int i = 0; i < n; i++)\n a[i] = nextInt();\n return a;\n }\n\n public long[] nextLongArray(int n) throws IOException {\n long[] a = new long[n];\n for (int i = 0; i < n; i++)\n a[i] = nextLong();\n return a;\n }\n\n\n public Integer[] nextIntegerArray(int n) throws IOException {\n Integer[] a = new Integer[n];\n for (int i = 0; i < n; i++)\n a[i] = nextInt();\n return a;\n }\n\n public double[] nextDoubleArray(int n) throws IOException {\n double[] ans = new double[n];\n for (int i = 0; i < n; i++)\n ans[i] = nextDouble();\n return ans;\n }\n\n public short nextShort() throws IOException {\n return Short.parseShort(next());\n }\n\n }\n\n}", "src_uid": "d3e3da5b6ba37c8ac5f22b18c140ce81"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class c {\n\tpublic static void main(String[] args) { new c(); }\n\tFS in = new FS();\n\tPrintWriter out = new PrintWriter(System.out);\n\n\tint n, e, o;\n\tint[] p;\n\tboolean[] has;\n\tint[][][][] dp;\n\t\n\tc() {\n\t\tn = in.nextInt();\n\t\tp = new int[n + 1];\n\t\thas = new boolean[n + 1];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\thas[p[i] = in.nextInt()] = true;\n\n\t\te = 0; o = 0;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tif (has[i]) continue;\n\t\t\tif ((i & 1) == 0) e++;\n\t\t\telse o++;\n\t\t}\n\n\t\t// dp(idx, parity of idx - 1, o, e)\n\t\tdp = new int[2][e + 1][o + 1][n];\n\t\tfor (int i = 0; i < 2; i++)\n\t\t\tfor (int j = 0; j <= e; j++)\n\t\t\t\tfor (int k = 0; k <= o; k++)\n\t\t\t\t\tArrays.fill(dp[i][j][k], -1);\n\n\t\tout.println(dp(0, e, o, 0));\n\n\t\tout.close();\n\t}\n\n\tint dp(int par, int remE, int remO, int idx) {\n\t\tif (idx == n) return 0;\n\t\tif (dp[par][remE][remO][idx] != -1)\n\t\t\treturn dp[par][remE][remO][idx];\n\n\t\tint ans = n + 1;\n\t\tif (p[idx] != 0) {\n\t\t\tint pd = (p[idx] & 1);\n\t\t\tif (idx == 0) ans = dp(pd, remE, remO, idx + 1);\n\t\t\telse if (pd == par) ans = dp(pd, remE, remO, idx + 1);\n\t\t\telse ans = 1 + dp(pd, remE, remO, idx + 1);\n\t\t}\n\t\telse {\n\t\t\tif (remE > 0) {\n\t\t\t\tif (idx == 0) ans = min(ans, dp(0, remE - 1, remO, idx + 1));\n\t\t\t\telse if (par == 0) ans = min(ans, dp(0, remE - 1, remO, idx + 1));\n\t\t\t\telse ans = min(ans, 1 + dp(0, remE - 1, remO, idx + 1));\n\t\t\t}\n\t\t\tif (remO > 0) {\n\t\t\t\tif (idx == 0) ans = min(ans, dp(1, remE, remO - 1, idx + 1));\n\t\t\t\telse if (par == 1) ans = min(ans, dp(1, remE, remO - 1, idx + 1));\n\t\t\t\telse ans = min(ans, 1 + dp(1, remE, remO - 1, idx + 1));\n\t\t\t}\n\t\t}\n\n\t\treturn dp[par][remE][remO][idx] = ans;\n\t}\n\t\n\tint abs(int x) { if (x < 0) return -x; return x; }\n\tlong abs(long x) { if (x < 0) return -x; return x; }\n\tint max(int x, int y) { if (x < y) return y; return x; }\n\tint min(int x, int y) { if (x > y) return y; return x; }\n\tlong max(long x, long y) { if (x < y) return y; return x; }\n\tlong min(long x, long y) { if (x > y) return y; return x; }\n\n\tclass FS {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(\"\");\n\t\tString next() {\n\t\t\twhile (!st.hasMoreTokens()) {\n\t\t\t\ttry { st = new StringTokenizer(br.readLine()); }\n\t\t\t\tcatch (Exception e) {}\n\t\t\t} return st.nextToken();\n\t\t}\n\t\tint nextInt() { return Integer.parseInt(next()); }\n\t\tlong nextLong() { return Long.parseLong(next()); }\n\t\tdouble nextDouble() { return Double.parseDouble(next()); }\n\n\t\tvoid intArr(int sz, int[] x) { for (int i = 0; i < sz; i++) x[i] = nextInt(); }\n\t\tvoid longArr(int sz, long[] x) { for (int i = 0; i < sz; i++) x[i] = nextLong(); }\n\t\tvoid doubleArr(int sz, double[] x) { for (int i = 0; i < sz; i++) x[i] = nextDouble(); }\n\t}\n}\n\n", "src_uid": "90db6b6548512acfc3da162144169dba"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\n\npublic class H {\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tint n = Integer.parseInt(br.readLine());\n\t\tBigInteger N = BigInteger.valueOf(n);\n\t\tBigInteger ret = BigInteger.ONE;\n\t\tfor (int i = 0; i < 5; i++) {\n\t\t\tret = ret.multiply(N.subtract(BigInteger.valueOf(i)));\n\t\t\tret = ret.multiply(N.subtract(BigInteger.valueOf(i)));\n\t\t}\n\t\tBigInteger divide = ret.divide(BigInteger.valueOf(120));\n\t\tSystem.out.println(divide);\n\t}\n}\n", "src_uid": "92db14325cd8aee06b502c12d2e3dd81"} {"source_code": "import java.util.Scanner;\n\n\npublic class Panoramixs_Prediction {\n\n public static void main(String[] args) {\n // TODO Auto-generated method stub\n\n Scanner in=new Scanner(System.in);\n int a[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,51};\n int n=in.nextInt();\n int m=in.nextInt();\n int i;\n for( i=0;a[i]!=n;i++);\n if(a[i+1]==m)\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n \n }}", "src_uid": "9d52ff51d747bb59aa463b6358258865"} {"source_code": "import java.util.Scanner;\n\npublic class Nineteen {\n\n\tpublic static void main(String[] args) {\n\t\tint n_nineteens, nineteen[];// 0-n, 1-i, 2-e, 3-t\n\t\tString in;\n\t\tScanner keyboard = new Scanner(System.in);\n\t\tin = keyboard.nextLine();\n\t\tnineteen = new int[4];\n\t\tfor (int i = 0; i < in.length(); i++) {\n\t\t\tswitch (in.charAt(i)) {\n\t\t\tcase 'n':\n\t\t\t\tnineteen[0]++;\n\t\t\t\tbreak;\n\t\t\tcase 'i':\n\t\t\t\tnineteen[1]++;\n\t\t\t\tbreak;\n\t\t\tcase 'e':\n\t\t\t\tnineteen[2]++;\n\t\t\t\tbreak;\n\t\t\tcase 't':\n\t\t\t\tnineteen[3]++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tn_nineteens = nineteen[3]; // Number of 't's\n\t\tif (nineteen[2] / 3 < n_nineteens) // Number of 'e's\n\t\t\tn_nineteens = nineteen[2] / 3;\n\t\tif (nineteen[1] < n_nineteens) // Number of 'i's\n\t\t\tn_nineteens = nineteen[1];\n\t\tif ((nineteen[0] - 1) / 2 < n_nineteens) // Number of 't's\n\t\t\tn_nineteens = (nineteen[0] - 1) / 2;\n\t\tSystem.out.println(n_nineteens);\n\n\t\tkeyboard.close();\n\t}\n\n}\n", "src_uid": "bb433cdb8299afcf46cb2797cbfbf724"} {"source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Solution {\n public static void main(String [] args) {\n Scanner scan = new Scanner(System.in);\n String line = scan.nextLine();\n String[] parts = line.split(\" \");\n int n = Integer.parseInt(parts[0]);\n int k = Integer.parseInt(parts[1]);\n String path = scan.nextLine();\n int grassIndex = 0; \n int treasureIndex = 0; \n for(int i = 0; i < n; i++) {\n char c = path.charAt(i);\n if(c == 'G') {\n grassIndex = i; \n }\n else if(c == 'T') {\n treasureIndex = i; \n }\n }\n String s = helper(path, grassIndex, treasureIndex, k);\n System.out.println(s);\n }\n private static String helper(String path, int index, int indexTwo, int k) {\n int curIndex = index; \n int destIndex = indexTwo; \n if(curIndex < destIndex) {\n while(curIndex + k < path.length()) {\n curIndex += k; \n char c = path.charAt(curIndex);\n if(c == '#') {\n return \"NO\";\n }\n else if(c == 'T') {\n return \"YES\";\n }\n }\n }\n else {\n while(curIndex - k >= 0) {\n curIndex -= k; \n char c = path.charAt(curIndex);\n if(c == '#') {\n return \"NO\";\n }\n else if(c == 'T') {\n return \"YES\";\n }\n }\n }\n return \"NO\";\n }\n}", "src_uid": "189a9b5ce669bdb04b9d371d74a5dd41"} {"source_code": "import java.util.*;\n\n/**\n * Created by mcl on 2017/12/2.\n */\npublic class Main {\n\n public static void main(String[] args) {\n new Main().cal();\n }\n\n int n;\n int p;\n int left;\n int right;\n long[][] fact = null;\n List<Integer[]> list = new ArrayList<>();\n\n\n void cal() {\n Scanner in = new Scanner(System.in);\n n = in.nextInt();\n p = in.nextInt();\n left = in.nextInt();\n right = in.nextInt();\n if (p == 1) {\n System.out.println(0);\n return;\n }\n int remain = p;\n for (int i = 2; i * i <= remain; ++ i) {\n if (remain % i == 0) {\n int s = 1;\n while (remain % i == 0) {\n remain /= i;\n s *= i;\n }\n list.add(new Integer[]{i, s});\n }\n }\n if (remain > 1) {\n list.add(new Integer[]{remain, remain});\n }\n fact = new long[list.size()][n + 1];\n for (int i = 0; i < list.size(); ++ i) {\n int mod = list.get(i)[1];\n int prime = list.get(i)[0];\n fact[i][0] = 1;\n for (int j = 1; j <= n; ++ j) {\n fact[i][j] = fact[i][j - 1];\n int t = j;\n while (t % prime == 0) {\n t /= prime;\n }\n fact[i][j] = fact[i][j] * t % mod;\n }\n }\n long result = 0;\n for (int cNum = 0; cNum <= n; ++ cNum) {\n long t = calculate(cNum, (cNum + left + 1) / 2) - calculate(cNum, (cNum + right) / 2 + 1);\n t %= p;\n t *= calculate(n, cNum);\n t %= p;\n result += t;\n result %= p;\n }\n if (result < 0) {\n result += p;\n }\n System.out.println(result);\n }\n\n long calculate(int n, int m) {\n if (m < 0 || m > n) {\n return 0;\n }\n if (m == 0 || m == n) {\n return 1;\n }\n long[] A = new long[list.size()];\n long[] M = new long[list.size()];\n for (int i = 0; i < list.size(); ++ i) {\n M[i] = list.get(i)[1];\n int t = list.get(i)[0];\n int cnt = count(n, t) - count(m, t) - count(n - m, t);\n A[i] = fact[i][n] * reverse(fact[i][m] * fact[i][n - m] % M[i], M[i]) % M[i]\n * Pow(t, cnt, M[i]) % M[i];\n }\n return modular(A, M)[1];\n }\n\n static int count(int n, int p) {\n int cnt = 0;\n while (n > 0) {\n cnt += n / p;\n n /= p;\n }\n return cnt;\n }\n\n static long Pow(long a, long b, long mod) {\n long result = 1;\n while (b > 0) {\n if (b % 2 == 1) {\n result = result * a % mod;\n }\n a = a * a % mod;\n b >>= 1;\n }\n return result;\n }\n\n static long[] modular(long[] a,long[] m)\n {\n long cura = a[0];\n long curm = m[0];\n\n for(int i = 1; i < a.length; ++ i)\n {\n long[] result = exGcd(curm, m[i]);\n long d = result[0];\n long x = result[1];\n long c=a[i]-cura;\n if (c % d != 0) {\n return new long[]{0, 0};\n }\n long t = m[i] / d;\n x = (c / d * x % t + t) % t;\n cura = curm * x + cura;\n curm = curm * m[i] / d;\n }\n return new long[]{1, cura};\n }\n\n static long reverse(long a, long b)\n {\n long[] r = exGcd(a,b);\n return (r[1] % b + b) % b;\n }\n\n static long[] exGcd(long a,long b)\n {\n if (b == 0)\n {\n return new long[]{a, 1, 0};\n }\n long[] result = exGcd(b, a % b);\n return new long[]{result[0], result[2], result[1] - a / b * result[2]};\n }\n\n\n}", "src_uid": "6ddc487029785738679007443fc08463"} {"source_code": "/*\r\nSetting up my ambitions\r\nCheck 'em one at a time, yeah, I made it\r\nNow it's time for ignition\r\nI'm the start, heat it up\r\nThey follow, burning up a chain reaction, oh-oh-oh\r\nGo fire it up, oh, oh, no\r\nAssemble the crowd now, now\r\nLine 'em up on the ground\r\nNo leaving anyone behind\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 x1606E\r\n{\r\n static final long MOD = 998244353L;\r\n public static void main(String hi[]) throws Exception\r\n {\r\n fac = new long[1000];\r\n invfac = new long[1000];\r\n fac[0] = invfac[0] = 1L;\r\n for(int i=1; i < 1000; i++)\r\n {\r\n fac[i] = (fac[i-1]*i)%MOD;\r\n invfac[i] = power(fac[i], MOD-2, MOD);\r\n }\r\n long[][] calc = new long[501][501];\r\n for(int a=0; a <= 500; a++)\r\n for(int b=0; b <= a; b++)\r\n calc[a][b] = nCr(a, b);\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 int K = Integer.parseInt(st.nextToken());\r\n long[][] dp = new long[N+1][K+1];\r\n dp[N][0] = 1L;\r\n for(int i=N; i >= 2; i--)\r\n for(int x=0; x < K; x++)\r\n {\r\n int d = x+i-1;\r\n d = min(d, K);\r\n int lb = x+1;\r\n int ub = min(K, x+i-1);\r\n long ways = max(0, ub-lb+1);\r\n long invWay = power(ways, MOD-2, MOD);\r\n ways = power(ways, i, MOD);\r\n for(int j=0; j <= i; j++)\r\n {\r\n long temp = (ways*calc[i][j])%MOD;\r\n temp = (temp*dp[i][x])%MOD;\r\n dp[j][d] += temp;\r\n if(dp[j][d] >= MOD)\r\n dp[j][d] -= MOD;\r\n ways = (ways*invWay)%MOD;\r\n }\r\n }\r\n long res = 0L;\r\n for(int k=1; k <= K; k++)\r\n res += dp[0][k];\r\n System.out.println(res%MOD);\r\n }\r\n static long[] fac;\r\n static long[] invfac;\r\n public static long nCr(int a, int b)\r\n {\r\n long res = (fac[a]*invfac[b])%MOD;\r\n return (res*invfac[a-b])%MOD;\r\n }\r\n public static long power(long x, long y, long p)\r\n {\r\n //0^0 = 1\r\n long res = 1L;\r\n x = x%p;\r\n while(y > 0)\r\n {\r\n if((y&1)==1)\r\n res = (res*x)%p;\r\n y >>= 1;\r\n x = (x*x)%p;\r\n }\r\n return res;\r\n }\r\n}\r\n/*\r\ndp[i][x] = i currently alive, each taken x damage, and n-i dead (need to be assigned)\r\ndp[j <= i][d == x+i-1] += dp[i][x]*nCr(i, j)*(# of values such that j+1 <= v <= i-1)^(i-j)\r\n */", "src_uid": "1908d1c8c6b122a4c6633a7af094f17f"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tlong time = System.nanoTime();\n\n\t\tint n = next();\n\t\tint k = next();\n\n\t\tint mod = 1000000007;\n\n\t\tint[] d = new int[k];\n\t\tint count = 0;\n\t\tint kol = 1;\n\t\tfor (int i = 0; i < k; i++) kol *= k;\n\t\tfor (int i = 0; i < kol; i++) {\n//\t\t\tfor (int j = 0; j < k; j++) System.out.print(d[j] + \" \");\n//\t\t\tSystem.out.println();\n\t\t\tint t = k - 1;\n\t\t\twhile (t >= 0 && d[t] == k - 1) {\n\t\t\t\td[t] = 0;\n\t\t\t\tt--;\n\t\t\t}\n\t\t\tif (t >= 0) d[t]++;\n\n\t\t\tboolean flag = true;\n\t\t\tfor (int j = 0; j < k && flag; j++) {\n//\t\t\t\tSystem.out.println(j);\n\t\t\t\tint x = d[j];\n\t\t\t\tboolean[] w = new boolean[k];\n\t\t\t\twhile (x != 0 && !w[x]) {\n\t\t\t\t\tw[x] = true;\n\t\t\t\t\tx = d[x];\n\t\t\t\t}\n\t\t\t\tif (x != 0) flag = false;\n\t\t\t}\n\t\t\tif (flag) count++;\n\t\t}\n\t\tfor (int i = k; i < n; i++) count = (int)(1L * count * (n - k) % mod);\n\n\t\tout.println(count);\n\t\t\n//\t\tSystem.out.println((System.nanoTime() - time)* 1e-9);\n\t\tout.close();\n\t}\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\t\n\tstatic BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in));\n\tstatic StringTokenizer in = new StringTokenizer(\"\");\n\n\tstatic String nextToken() throws Exception {\n\t\tif (!in.hasMoreTokens()) in = new StringTokenizer(bufferedreader.readLine());\n\t\treturn in.nextToken();\n\t}\n\n\tstatic int next() throws Exception {return Integer.parseInt(nextToken());};\n\tstatic int[] next(int n) throws Exception {\n\t\tint[] x = new int[n];\n\t\tfor (int i = 0; i < n; i++) x[i] = next();\n\t\treturn x;\n\t}\n\tstatic int[][] next(int n, int m) throws Exception {\n\t\tint[][] x = new int[n][];\n\t\tfor (int i = 0; i < n; i++) x[i] = next(m);\n\t\treturn x;\n\t}\n\n\tstatic long nextl() throws Exception {return Long.parseLong(nextToken());};\n\tstatic long[] nextl(int n) throws Exception {\n\t\tlong[] x = new long[n];\n\t\tfor (int i = 0; i < n; i++) x[i] = nextl();\n\t\treturn x;\n\t}\n\tstatic long[][] nextl(int n, int m) throws Exception {\n\t\tlong[][] x = new long[n][];\n\t\tfor (int i = 0; i < n; i++) x[i] = nextl(m);\n\t\treturn x;\n\t}\n\n\tstatic double nextd() throws Exception {return Double.parseDouble(nextToken());};\n\tstatic double[] nextd(int n) throws Exception {\n\t\tdouble[] x = new double[n];\n\t\tfor (int i = 0; i < n; i++) x[i] = nextd();\n\t\treturn x;\n\t}\n\tstatic double[][] nextd(int n, int m) throws Exception {\n\t\tdouble[][] x = new double[n][];\n\t\tfor (int i = 0; i < n; i++) x[i] = nextd(m);\n\t\treturn x;\n\t}\n\n\tstatic String nextline() throws Exception {\n\t\tin = new StringTokenizer(\"\");\n\t\treturn bufferedreader.readLine();\n\t}\n\n}", "src_uid": "cc838bc14408f14f984a349fea9e9694"} {"source_code": "/*\n * Code Author: Akshay Miterani\n * DA-IICT\n */\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.math.RoundingMode;\nimport java.text.DecimalFormat;\nimport java.util.*;\n\npublic class Main {\n\n\tstatic double eps=(double)1e-7;\n\tstatic long mod=(int)1e9+7;\n\tpublic static void main(String args[]) throws FileNotFoundException, UnsupportedEncodingException{\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-----------------\n\t\tlong m=in.nextLong();\n\t\tlong l=0,r=(long)1e17;\n\t\tlong mid=-1;\n\t\twhile(l<=r){\n\t\t\tmid=(l+r)/2;\n\t\t\tdouble val=check(mid);\n\t\t\tif(val>=m){\n\t\t\t\tr=mid-1;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tl=mid+1;\n\t\t\t}\n\t\t}\n\t\tif(Math.abs(check(l)-m)<eps){\n\t\t\tout.println((long)l);\n\t\t}\n\t\telse{\n\t\t\tout.println(\"-1\");\n\t\t}\n\t\tout.close();\n\t\t//---------------The End------------------\n\n\t}\n\tstatic long check(double m){\n\t\tlong count=0;\n\t\tfor(long i=2;i<=1000000;i++){\n\t\t\tdouble v=(Math.pow(i, 3));\n\t\t\tif(v>m){\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdouble tmp=m/v;\n\t\t\tlong add=(long)Math.floor(tmp);\n\t\t\tcount+=add;\n\t\t}\n\t\treturn count;\n\t}\n\tstatic class Pair implements Comparable<Pair> {\n\t\tint u;\n\t\tint v;\n\n\t\tpublic Pair(int u, int v) {\n\t\t\tthis.u = u;\n\t\t\tthis.v = v;\n\t\t}\n\n\t\tpublic int hashCode() {\n\t\t\tint hu = (int) (u ^ (u >>> 32));\n\t\t\tint hv = (int) (v ^ (v >>> 32));\n\t\t\treturn 31 * hu + hv;\n\t\t}\n\n\t\tpublic boolean equals(Object o) {\n\t\t\tPair other = (Pair) o;\n\t\t\treturn u == other.u && v == other.v;\n\t\t}\n\n\t\tpublic int compareTo(Pair other) {\n\t\t\treturn Long.compare(u, other.u) != 0 ? Long.compare(u, other.u) : Long.compare(v, other.v);\n\t\t}\n\n\t\tpublic String toString() {\n\t\t\treturn \"[u=\" + u + \", v=\" + v + \"]\";\n\t\t}\n\t}\n\tpublic static void debug(Object... o) {\n\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n\tstatic long modulo(long a,long b,long c) {\n\t\tlong x=1;\n\t\tlong y=a;\n\t\twhile(b > 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\tstatic long gcd(long x, long y)\n\t{\n\t\tif(x==0)\n\t\t\treturn y;\n\t\tif(y==0)\n\t\t\treturn x;\n\t\tlong r=0, a, b;\n\t\ta = (x > y) ? x : y; // a is greater number\n\t\tb = (x < y) ? x : y; // b is smaller number\n\t\tr = b;\n\t\twhile(a % b != 0)\n\t\t{\n\t\t\tr = a % b;\n\t\t\ta = b;\n\t\t\tb = r;\n\t\t}\n\t\treturn r;\n\t}\n\tstatic class InputReader {\n\t\tpublic BufferedReader reader;\n\t\tpublic StringTokenizer tokenizer;\n\n\t\tpublic InputReader(InputStream inputstream) {\n\t\t\treader = new BufferedReader(new InputStreamReader(inputstream));\n\t\t\ttokenizer = null;\n\t\t}\n\n\t\tpublic String nextLine(){\n\t\t\tString fullLine=null;\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tfullLine=reader.readLine();\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t\treturn fullLine;\n\t\t\t}\n\t\t\treturn fullLine;\n\t\t}\n\t\tpublic String next() {\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t}\n} ", "src_uid": "602deaad5c66e264997249457d555129"} {"source_code": "\nimport java.util.Scanner;\n\npublic class Main {\n public static void main(String[] args) {\n Scanner read = new Scanner(System.in);\n String sticks = read.nextLine();\n int a = sticks.split(\"\\\\+\")[0].length();\n int b = sticks.split(\"\\\\+\")[1].split(\"=\")[0].length();\n int c = sticks.split(\"=\")[1].length();\n\n if (a+b+1 == c-1 || a+b-1 == c+1 || a+b==c) {\n if (a+b > c) {\n while (a+b > c) {\n if (a > 1) a--;\n else if (b > 1) b--;\n c++;\n }\n } else {\n while (a+b < c) {\n a++;\n c--;\n }\n }\n printSticks(a,b,c);\n } else {\n System.out.println(\"Impossible\");\n }\n }\n\n private static void printSticks(int a, int b, int c) {\n StringBuilder s = new StringBuilder();\n for (int i = 0; i < a; i++) {\n s.append(\"|\");\n }\n s.append(\"+\");\n for (int i = 0; i < b; i++) {\n s.append(\"|\");\n }\n s.append(\"=\");\n for (int i = 0; i < c; i++) {\n s.append(\"|\");\n }\n System.out.println(s);\n }\n}\n", "src_uid": "ee0aaa7acf127e9f3a9edafc58f4e2d6"} {"source_code": "import java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\npublic class cf1081c {\n\n public static void main(String[] args) throws IOException {\n int n = rni(), m = ni(), k = ni(), dp[][] = new int[n][k + 1];\n dp[0][0] = m;\n for (int i = 1; i < n; ++i) {\n dp[i][0] = m;\n for (int j = 1; j <= k; ++j) {\n dp[i][j] = madd(dp[i - 1][j], mmul(m - 1, dp[i - 1][j - 1]));\n }\n }\n prln(dp[n - 1][k]);\n close();\n }\n\n static int mmod = 998244353;\n\n static int madd(int a, int b) {\n return (a + b) % mmod;\n }\n\n static int madd(int... a) {\n int ans = a[0];\n for (int i = 1; i < a.length; ++i) {\n ans = madd(ans, a[i]);\n }\n return ans;\n }\n\n static int msub(int a, int b) {\n return (a - b + mmod) % mmod;\n }\n\n static int mmul(int a, int b) {\n return (int) ((long) a * b % mmod);\n }\n\n static int mmul(int... a) {\n int ans = a[0];\n for (int i = 1; i < a.length; ++i) {\n ans = mmul(ans, a[i]);\n }\n return ans;\n }\n\n static int minv(int x) {\n return mpow(x, mmod - 2);\n }\n\n static int mpow(int a, int b) {\n if (a == 0) {\n return 0;\n }\n int ans = 1;\n while (b > 0) {\n if ((b & 1) > 0) {\n ans = mmul(ans, a);\n }\n a = mmul(a, a);\n b >>= 1;\n }\n return ans;\n }\n\n static BufferedReader __in = new BufferedReader(new InputStreamReader(System.in));\n static PrintWriter __out = new PrintWriter(new OutputStreamWriter(System.out));\n static StringTokenizer input;\n static Random __rand = new Random();\n\n // references\n // IBIG = 1e9 + 7\n // IMAX ~= 2e9\n // LMAX ~= 9e18\n \n // constants\n static final int IBIG = 1000000007;\n static final int IMAX = 2147483647;\n static final int IMIN = -2147483648;\n static final long LMAX = 9223372036854775807L;\n static final long LMIN = -9223372036854775808L;\n // math util\n static int minof(int a, int b, int c) {return min(a, min(b, c));}\n static int minof(int... x) {if(x.length == 1) return x[0]; if(x.length == 2) return min(x[0], x[1]); if(x.length == 3) return min(x[0], min(x[1], x[2])); int min = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] < min) min = x[i]; return min;}\n static long minof(long a, long b, long c) {return min(a, min(b, c));}\n static long minof(long... x) {if(x.length == 1) return x[0]; if(x.length == 2) return min(x[0], x[1]); if(x.length == 3) return min(x[0], min(x[1], x[2])); long min = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] < min) min = x[i]; return min;}\n static int maxof(int a, int b, int c) {return max(a, max(b, c));}\n static int maxof(int... x) {if(x.length == 1) return x[0]; if(x.length == 2) return max(x[0], x[1]); if(x.length == 3) return max(x[0], max(x[1], x[2])); int max = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] > max) max = x[i]; return max;}\n static long maxof(long a, long b, long c) {return max(a, max(b, c));}\n static long maxof(long... x) {if(x.length == 1) return x[0]; if(x.length == 2) return max(x[0], x[1]); if(x.length == 3) return max(x[0], max(x[1], x[2])); long max = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] > max) max = x[i]; return max;}\n static int powi(int a, int b) {if(a == 0) return 0; int ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}\n static long powl(long a, int b) {if(a == 0) return 0; long ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}\n static int fli(double d) {return (int)d;}\n static int cei(double d) {return (int)ceil(d);}\n static long fll(double d) {return (long)d;}\n static long cel(double d) {return (long)ceil(d);}\n static int gcf(int a, int b) {return b == 0 ? a : gcf(b, a % b);}\n static long gcf(long a, long b) {return b == 0 ? a : gcf(b, a % b);}\n static int lcm(int a, int b) {return a * b / gcf(a, b);}\n static long lcm(long a, long b) {return a * b / gcf(a, b);}\n static int randInt(int min, int max) {return __rand.nextInt(max - min + 1) + min;}\n static long hash(long x) {x += 0x9e3779b97f4a7c15L; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9L; x = (x ^ (x >> 27)) * 0x94d049bb133111ebL; return x ^ (x >> 31);}\n // array util\n static void reverse(int[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {int swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}}\n static void reverse(long[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {long swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}}\n static void reverse(char[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {char swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}}\n static void shuffle(int[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); int swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}\n static void shuffle(long[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); long swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}\n static void rsort(int[] a) {shuffle(a); sort(a);}\n static void rsort(long[] a) {shuffle(a); sort(a);}\n static int[] copy(int[] a) {int[] ans = new int[a.length]; for(int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans;}\n static long[] copy(long[] a) {long[] ans = new long[a.length]; for(int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans;}\n static char[] copy(char[] a) {char[] ans = new char[a.length]; for(int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans;}\n // graph util\n static List<List<Integer>> g(int n) {List<List<Integer>> g = new ArrayList<>(); for(int i = 0; i < n; ++i) g.add(new ArrayList<>()); return g;}\n static List<Set<Integer>> sg(int n) {List<Set<Integer>> g = new ArrayList<>(); for(int i = 0; i < n; ++i) g.add(new HashSet<>()); return g;}\n static void c(List<? extends Collection<Integer>> g, int u, int v) {g.get(u).add(v); g.get(v).add(u);}\n static void cto(List<? extends Collection<Integer>> g, int u, int v) {g.get(u).add(v);}\n static void dc(List<? extends Collection<Integer>> g, int u, int v) {g.get(u).remove(v); g.get(v).remove(u);}\n static void dcto(List<? extends Collection<Integer>> g, int u, int v) {g.get(u).remove(v);}\n // input\n static void r() throws IOException {input = new StringTokenizer(__in.readLine());}\n static int ri() throws IOException {return Integer.parseInt(__in.readLine());}\n static long rl() throws IOException {return Long.parseLong(__in.readLine());}\n static int[] ria(int n) throws IOException {int[] a = new int[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Integer.parseInt(input.nextToken()); return a;}\n static int[] riam1(int n) throws IOException {int[] a = new int[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Integer.parseInt(input.nextToken()) - 1; return a;}\n static long[] rla(int n) throws IOException {long[] a = new long[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Long.parseLong(input.nextToken()); return a;}\n static char[] rcha() throws IOException {return __in.readLine().toCharArray();}\n static String rline() throws IOException {return __in.readLine();}\n static int rni() throws IOException {input = new StringTokenizer(__in.readLine()); return Integer.parseInt(input.nextToken());}\n static int ni() {return Integer.parseInt(input.nextToken());}\n static long rnl() throws IOException {input = new StringTokenizer(__in.readLine()); return Long.parseLong(input.nextToken());}\n static long nl() {return Long.parseLong(input.nextToken());}\n static List<List<Integer>> rg(int n, int m) throws IOException {List<List<Integer>> g = g(n); for(int i = 0; i < m; ++i) c(g, rni() - 1, ni() - 1); return g;}\n static void rg(List<List<Integer>> g, int m) throws IOException {for(int i = 0; i < m; ++i) c(g, rni() - 1, ni() - 1);}\n static List<List<Integer>> rdg(int n, int m) throws IOException {List<List<Integer>> g = g(n); for(int i = 0; i < m; ++i) cto(g, rni() - 1, ni() - 1); return g;}\n static void rdg(List<List<Integer>> g, int m) throws IOException {for(int i = 0; i < m; ++i) cto(g, rni() - 1, ni() - 1);}\n static List<Set<Integer>> rsg(int n, int m) throws IOException {List<Set<Integer>> g = sg(n); for(int i = 0; i < m; ++i) c(g, rni() - 1, ni() - 1); return g;}\n static void rsg(List<Set<Integer>> g, int m) throws IOException {for(int i = 0; i < m; ++i) c(g, rni() - 1, ni() - 1);}\n static List<Set<Integer>> rdsg(int n, int m) throws IOException {List<Set<Integer>> g = sg(n); for(int i = 0; i < m; ++i) cto(g, rni() - 1, ni() - 1); return g;}\n static void rdsg(List<Set<Integer>> g, int m) throws IOException {for(int i = 0; i < m; ++i) cto(g, rni() - 1, ni() - 1);}\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 <T> void prln(Collection<T> c) {int n = c.size() - 1; Iterator<T> iter = c.iterator(); for(int i = 0; i < n; __out.print(iter.next()), __out.print(' '), ++i); if(n >= 0) __out.println(iter.next()); else __out.println();}\n static void h() {__out.println(\"hlfd\");}\n static void flush() {__out.flush();}\n static void close() {__out.close();}\n}", "src_uid": "b2b9bee53e425fab1aa4d5468b9e578b"} {"source_code": "import java.io.*;\nimport java.util.StringTokenizer;\n\n/**\n * Created by sbabkin on 9/14/2015.\n */\npublic class SolverE {\n\n public static void main(String[] args) throws IOException {\n new SolverE().Run();\n }\n\n BufferedReader br;\n PrintWriter pw;\n StringTokenizer stok;\n\n private String nextToken() throws IOException {\n while (stok==null || !stok.hasMoreTokens()){\n stok = new StringTokenizer(br.readLine());\n }\n return stok.nextToken();\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 double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n private void Run() throws IOException {\n// br=new BufferedReader(new FileReader(\"input.txt\"));\n// pw=new PrintWriter(\"output.txt\");\n br=new BufferedReader(new InputStreamReader(System.in));\n pw=new PrintWriter(new OutputStreamWriter(System.out));\n\n solve();\n pw.flush();\n pw.close();\n }\n\n private void solve() throws IOException {\n long x=nextLong();\n long y=nextLong();\n if (gcd(x,y)>1) {\n pw.println(\"Impossible\");\n return;\n }\n while (x>1 || y>1) {\n if (x>y) {\n long del=x/y;\n if (y==1) {\n del--;\n }\n pw.print(del+\"A\");\n x-=y*del;\n } else {\n long del=y/x;\n if (x==1) {\n del--;\n }\n pw.print(del+\"B\");\n y-=x*del;\n }\n }\n pw.println();\n }\n\n private long gcd(long x, long y) {\n while (y>0) {\n x=x%y;\n long buf=x;\n x=y;\n y=buf;\n }\n return x;\n }\n\n}\n", "src_uid": "6a9ec3b23bd462353d985e0c0f2f7671"} {"source_code": "import java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class B {\n\n\n\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\t\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\n\n\t\tchar[] c = sc.next().toCharArray();\n\t\tint n = c.length;\n\n\t\tint cur = 0;\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tcur += (c[i] - '0');\n\t\t}\n\n\t\tchar[] ans = c.clone();\n\n\t\tfor (int i = n - 1; i >= 0; i--) {\n\t\t\tchar[] curA = c.clone();\n\n\t\t\tint curC = 0;\n\n\t\t\tif(c[i] == 0)\n\t\t\t\tcontinue;\n\n\t\t\tcurA[i]--;\n\t\t\tfor (int j = i + 1; j < n; j++) {\n\t\t\t\tcurA[j] = '9';\n\t\t\t}\n\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tcurC += curA[j] - '0';\n\t\t\t}\n\n\t\t\tif(curC > cur) {\n\t\t\t\tans = curA;\n\t\t\t\tcur = curC;\n\t\t\t}\n\t\t}\n\n\n\t\tif(ans[0] != '0')\n\t\t\tout.print(ans[0]);\n\t\tfor (int i = 1; i < n; i++) \n\t\t\tout.print(ans[i]);\n\t\tout.println();\n\n\n\t\tout.flush();\n\t\tout.close();\n\t}\n\n\n\tstatic class Scanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(s));\n\t\t}\n\t\tpublic Scanner(String file) throws FileNotFoundException{\tbr = new BufferedReader(new FileReader(file));}\n\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 NumberFormatException, IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tpublic long nextLong() throws NumberFormatException, 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 double nextDouble() throws IOException\n\t\t{\n\t\t\tString x = next();\n\t\t\tStringBuilder sb = new StringBuilder(\"0\");\n\t\t\tdouble res = 0, f = 1;\n\t\t\tboolean dec = false, neg = false;\n\t\t\tint start = 0;\n\t\t\tif(x.charAt(0) == '-')\n\t\t\t{\n\t\t\t\tneg = true;\n\t\t\t\tstart++;\n\t\t\t}\n\t\t\tfor(int i = start; i < x.length(); i++)\n\t\t\t\tif(x.charAt(i) == '.')\n\t\t\t\t{\n\t\t\t\t\tres = Long.parseLong(sb.toString());\n\t\t\t\t\tsb = new StringBuilder(\"0\");\n\t\t\t\t\tdec = true;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tsb.append(x.charAt(i));\n\t\t\t\t\tif(dec)\n\t\t\t\t\t\tf *= 10;\n\t\t\t\t}\n\t\t\tres += Long.parseLong(sb.toString()) / f;\n\t\t\treturn res * (neg?-1:1);\n\t\t}\n\n\t}\n\n}\n\n", "src_uid": "e55b0debbf33c266091e6634494356b8"} {"source_code": "import java.util.*;\nimport java.lang.Math;\npublic class tab\n{\npublic static void main(String[] args)\n{\nint n,pos,l,r;\nScanner sc=new Scanner(System.in);\nn=sc.nextInt();\npos=sc.nextInt();\nl=sc.nextInt();\nr=sc.nextInt();\nint sum;\nint a=(n-r)+(l-1);\nif((Math.abs(pos-l)<Math.abs(r-pos))&&a!=0)\n{\n if(l!=1)\n {sum=Math.abs(pos-l);\n sum++;\n if(r!=n)\n sum+=(r-l)+1;\n }\n else\n sum=Math.abs(r-pos)+1;\n}\nelse if(a==0)\n sum=0; \nelse\n{\n if(r!=n)\n { sum=Math.abs(r-pos);\n sum++;\n if(l!=1) \n sum+=(r-l)+1;\n }\n else\n sum=Math.abs(pos-l)+1;\n}\nSystem.out.println(sum);\n}}", "src_uid": "5deaac7bd3afedee9b10e61997940f78"} {"source_code": "import java.awt.Point;\nimport java.io.*;\nimport java.util.*;\nimport java.math.BigInteger;\n\npublic class WinFreeze {\n static class Solver {\n public void solve(MyReader in, PrintWriter out) {\n long org = in.nextLong();\n long n = org;\n\n List<Long> div = new ArrayList<>();\n\n out:\n for(long i = 2;i*i <= n;i++){\n while (n%i == 0){\n div.add(i);\n n/=i;\n if(div.size() >= 2)break out;\n }\n }\n\n if(n!= 1 && n!=org)div.add(n);\n\n// out.println(div);\n if(div.isEmpty()){\n out.println(\"1\\n0\");\n }\n else if(div.size() == 1 || div.get(0)*div.get(1) == org){\n out.println(2);\n }\n else{\n out.println(\"1\");\n out.println(div.get(0)*div.get(1));\n }\n\n }\n\n\n }\n\n public static void main(String[] args) {\n MyReader mr = new MyReader();\n PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n new Solver().solve(mr, out);\n out.close();\n }\n\n // static int[][] dir = {{0,1}, {1,0},{-1,0}, {0,-1}};\n// static int[][] dir = {{0,1}, {1,0},{-1,0}, {0,-1}, {-1,-1},{-1,1}, {1,1}, {1,-1}};\n static class MyReader {\n BufferedReader br;\n StringTokenizer st;\n\n MyReader() {\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 (Exception e) {\n e.printStackTrace();\n }\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 res = \"\";\n try {\n res = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n\n return res;\n }\n\n int[] nextIntArray(int n) {\n int[] arr = new int[n];\n for (int i = 0; i < n; i++) {\n arr[i] = nextInt();\n }\n\n return arr;\n }\n\n Integer[] nextIntegerArray(int n) {\n Integer[] arr = new Integer[n];\n for (int i = 0; i < n; i++) {\n arr[i] = nextInt();\n }\n\n return arr;\n }\n\n Long[] nextLongArray(int n) {\n Long[] arr = new Long[n];\n for (int i = 0; i < n; i++) {\n arr[i] = nextLong();\n }\n\n return arr;\n }\n\n String[] nextStringArray(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\n static void swap(int[] arr, int i, int j) {\n int tmp = arr[i];\n arr[i] = arr[j];\n arr[j] = tmp;\n }\n\n}\n\n\n", "src_uid": "f0a138b9f6ad979c5ca32437e05d6f43"} {"source_code": "import java.io.*;\nimport java.util.*;\n\n\npublic class Solution {\n private BufferedReader in;\n private StringTokenizer line;\n private PrintWriter out;\n\n private static final int mm = 1000000007;\n\n private static int MAX_DEPTH = 38;\n\n public void solve() throws IOException {\n int q = nextInt();\n A[] a = new A[q + 1];\n a[0] = new A(null);\n int n = 1;\n for (int i = 0; i < q; i++) {\n int qt = nextInt();\n int v = nextInt() - 1;\n if (qt == 1) {\n a[n++] = new A(a[v]);\n a[v].cnt++;\n recalc(a[n - 1], null, null, 0);\n } else {\n double res = 0;\n for (int j = 0; j < MAX_DEPTH - 1; j++) {\n res += j * (a[v].a[j] - a[v].a[j + 1]);\n }\n out.println(String.format(Locale.ENGLISH, \"%.8f\", res));\n }\n }\n }\n\n private static double[] p2 = new double[MAX_DEPTH + 13];\n\n static {\n p2[0] = 1;\n for (int i = 1; i < p2.length; i++) {\n p2[i] = p2[i - 1] / 2.0;\n }\n }\n\n private void recalc(A b, A p, double[] prev, int depth) {\n if (b == null) return;\n if (depth == MAX_DEPTH) return;\n double[] bprev = Arrays.copyOf(b.a, MAX_DEPTH);\n\n double[] bcurr = b.a;\n if (p != null) {\n for (int i = 2; i < MAX_DEPTH; i++) {\n bcurr[i] = 1 - (1 - bcurr[i]) / (2 - prev[i - 1]) * (2 - p.a[i - 1]);\n }\n if (b.cnt > MAX_DEPTH) {\n bcurr[1] = 1;\n } else {\n bcurr[1] = 1 - p2[b.cnt];\n }\n }\n\n recalc(b.p, b, bprev, depth + 1);\n }\n\n\n private static class A {\n private double[] a;\n private A p;\n private int cnt;\n\n public A(A p) {\n this.p = p;\n this.a = new double[MAX_DEPTH];\n this.a[0] = 1;\n this.cnt = 0;\n }\n }\n\n public static void main(String[] args) throws IOException {\n new Solution().run(args);\n }\n\n public void run(String[] args) throws IOException {\n if (args.length > 0 && \"DEBUG_MODE\".equals(args[0])) {\n in = new BufferedReader(new InputStreamReader(new FileInputStream(\"input.txt\")));\n } else {\n in = new BufferedReader(new InputStreamReader(System.in));\n }\n out = new PrintWriter(System.out);\n// out = new PrintWriter(\"output.txt\");\n\n// int t = nextInt();\n int t = 1;\n for (int i = 0; i < t; i++) {\n// out.print(\"Case #\" + (i + 1) + \": \");\n solve();\n }\n\n in.close();\n out.flush();\n out.close();\n }\n\n private int[] nextIntArray(int n) throws IOException {\n int[] res = new int[n];\n for (int i = 0; i < n; i++) {\n res[i] = nextInt();\n }\n return res;\n }\n\n private long[] nextLongArray(int n) throws IOException {\n long[] res = new long[n];\n for (int i = 0; i < n; i++) {\n res[i] = nextInt();\n }\n return res;\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 double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n private String nextToken() throws IOException {\n while (line == null || !line.hasMoreTokens()) {\n line = new StringTokenizer(in.readLine());\n }\n return line.nextToken();\n }\n\n private static class Pii {\n private int key;\n private int value;\n\n public Pii(int key, int value) {\n this.key = key;\n this.value = value;\n }\n\n @Override\n public boolean equals(Object o) {\n if (this == o) return true;\n if (o == null || getClass() != o.getClass()) return false;\n\n Pii pii = (Pii) o;\n\n if (key != pii.key) return false;\n return value == pii.value;\n\n }\n\n @Override\n public int hashCode() {\n int result = key;\n result = 31 * result + value;\n return result;\n }\n }\n\n private static class Pair<K, V> {\n private K key;\n private V value;\n\n public Pair(K key, V value) {\n this.key = key;\n this.value = value;\n }\n\n public K getKey() {\n return key;\n }\n\n public V getValue() {\n return value;\n }\n\n @Override\n public boolean equals(Object o) {\n if (this == o) return true;\n if (o == null || getClass() != o.getClass()) return false;\n\n Pair<?, ?> pair = (Pair<?, ?>) o;\n\n if (key != null ? !key.equals(pair.key) : pair.key != null) return false;\n return !(value != null ? !value.equals(pair.value) : pair.value != null);\n\n }\n\n @Override\n public int hashCode() {\n int result = key != null ? key.hashCode() : 0;\n result = 31 * result + (value != null ? value.hashCode() : 0);\n return result;\n }\n }\n}", "src_uid": "55affe752cb214d1e4031a9e3972597b"} {"source_code": "import java.util.*;\r\npublic class XenolithHippodrome {\r\n public static void main(String[] args) {\r\n Scanner sc=new Scanner(System.in);\r\n int n=sc.nextInt();\r\n int m=sc.nextInt();\r\n HashSet h=new HashSet<>();\r\n boolean f=true;\r\n while (n>0){\r\n int k=n%m;\r\n if(h.contains(k)){\r\n f=false;\r\n break;\r\n }\r\n else {\r\n h.add(k);\r\n n/=m;\r\n }\r\n }\r\n if(f){\r\n System.out.println(\"YES\");\r\n }\r\n else {\r\n System.out.println(\"NO\");\r\n }\r\n }\r\n}\r\n", "src_uid": "a8945bb1082fefe70e6898a8bec1ce3f"} {"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\tlong[] ways2 = Arrays.copyOf(ways, f+2);\r\n\t\t\r\n\t\tfor(int i=0; i<n; i++) {\r\n\t\t\tif(i < n-1) {\r\n\t\t\t\tsquare(ways);\r\n\t\t\t\t{\r\n\t\t\t\t\tlong val = 0;\r\n\t\t\t\t\tfor(int j=ways.length-1; j>=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\tfor(int j=k+1; j<f+2; j++)\r\n\t\t\t\t\tways[j] = 0;\r\n\t\t\t\tArrays.fill(ways, f+2, ways.length, 0);\r\n\t\t\t\t\r\n//\t\t\t\tlong[] mult = multiplyPolynomial(ways2, ways2);\r\n//\t\t\t\t{\r\n//\t\t\t\t\tlong val = 0;\r\n//\t\t\t\t\tfor(int j=mult.length-1; j>=f+1; j--)\r\n//\t\t\t\t\t\tval += mult[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] + mult[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\tif(i < n-1) {\r\n//\t\t\t\t\tfor(int j=0; j <= k && j<=f; j++) {\r\n//\t\t\t\t\t\tlong val = suffix[j]; // c_curr = j\r\n//\t\t\t\t\t\tval += mult[j]*(k-j); // j+1 ~ k\r\n//\t\t\t\t\t\tval %= MOD;\r\n//\t\t\t\t\t\tways2[j] = val;\r\n//\t\t\t\t\t}\r\n//\t\t\t\t\t{\r\n//\t\t\t\t\t\tlong val = suffix[f+1]*Math.max(0, k-f);\r\n//\t\t\t\t\t\tval %= MOD;\r\n//\t\t\t\t\t\tways2[f+1] = val;\r\n//\t\t\t\t\t}\r\n//\t\t\t\t}\r\n//\t\t\t\tif(!Arrays.equals(Arrays.copyOf(ways, f+2), ways2)) {\r\n//\t\t\t\t\tfor(int j=0; j<f+2; j++)\r\n//\t\t\t\t\t\tif(ways[j] != ways2[j])\r\n//\t\t\t\t\t\t\tways = ways;\r\n//\t\t\t\t}\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<a.length; i++)\r\n\t \ta[i] = a[i]*inv%MOD;\r\n\t }\r\n\t}\r\n\t\r\n\tstatic void square(long[] a) {\r\n\t fft(a, false);\r\n\t for (int i = 0; i < a.length; i++)\r\n\t a[i] = a[i]*a[i] % MOD;\r\n\t fft(a, true);\r\n\t}\r\n\t\r\n\tstatic long[] multiplyPolynomial(long[] a, long[] b) {\r\n\t int n = 1;\r\n\t while (n < a.length + b.length) \r\n\t n <<= 1;\r\n\t\tlong[] fa = Arrays.copyOf(a, n);\r\n\t\tlong[] fb = Arrays.copyOf(b, n);\r\n\r\n\t fft(fa, false);\r\n\t fft(fb, false);\r\n\t for (int i = 0; i < n; i++)\r\n\t fa[i] = fa[i]*fb[i] % MOD;\r\n\t fft(fa, true);\r\n\t \r\n\t return fa;\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<n-1; i++){\r\n\t\t\t\te[i][0] = nextInt()+offset;\r\n\t\t\t\te[i][1] = nextInt()+offset;\r\n\t\t\t}\r\n\t\t\treturn e;\t\t\t\r\n\t\t}\r\n\t\t\r\n\t\tint[][] nextMatrix(int n, int m) {\r\n\t\t\treturn nextMatrix(n, m, 0);\r\n\t\t}\r\n\t\t\r\n\t\tint[][] nextMatrix(int n, int m, int offset) {\r\n\t\t\tint[][] mat = new int[n][m];\r\n\t\t\tfor(int i=0; i<n; i++) {\r\n\t\t\t\tfor(int j=0; j<m; j++) {\r\n\t\t\t\t\tmat[i][j] = nextInt()+offset;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn mat;\r\n\t\t}\r\n\t\t\r\n\t\tint[][] nextPairs(int n){\r\n\t\t\treturn nextPairs(n, 0);\r\n\t\t}\r\n\t\t\r\n\t\tint[][] nextPairs(int n, int offset) {\r\n\t\t\tint[][] xy = new int[2][n];\r\n\t\t\tfor(int i=0; i<n; i++) {\r\n\t\t\t\txy[0][i] = nextInt() + offset;\r\n\t\t\t\txy[1][i] = nextInt() + offset;\r\n\t\t\t}\r\n\t\t\treturn xy;\r\n\t\t}\r\n\r\n\t\tint[][] nextGraphEdges(){\r\n\t\t\treturn nextGraphEdges(0);\r\n\t\t}\r\n\t\t\r\n\t\tint[][] nextGraphEdges(int offset) {\r\n\t\t\tint m = nextInt();\r\n\t\t\tint[][] e = new int[m][2];\r\n\t\t\tfor(int i=0; i<m; i++){\r\n\t\t\t\te[i][0] = nextInt()+offset;\r\n\t\t\t\te[i][1] = nextInt()+offset;\r\n\t\t\t}\r\n\t\t\treturn e;\r\n\t\t}\r\n\t\t\r\n\t\tint[] nextIntArray(int len) {\r\n\t\t\treturn nextIntArray(len, 0);\r\n\t\t}\r\n\t\tint[] nextIntArray(int len, int offset){\r\n\t \tint[] a = new int[len];\r\n\t\t\tfor(int j=0; j<len; j++)\r\n\t \t\ta[j] = nextInt()+offset;\r\n\t \treturn a;\r\n\t\t}\r\n\t\t\r\n\t\tlong[] nextLongArray(int len) {\r\n\t\t\treturn nextLongArray(len, 0);\r\n\t\t}\r\n\t\tlong[] nextLongArray(int len, int offset){\r\n\t \tlong[] a = new long[len];\r\n\t\t\tfor(int j=0; j<len; j++)\r\n\t \t\ta[j] = nextLong()+offset;\r\n\t \treturn a;\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic static class MyPrintWriter extends PrintWriter{\r\n\t\tpublic MyPrintWriter(OutputStream os) {\r\n\t\t\tsuper(os);\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printlnAns(long ans) {\r\n\t\t\tprintln(ans);\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printlnAns(int ans) {\r\n\t\t\tprintln(ans);\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printlnAns(boolean ans) {\r\n\t\t\tif(ans)\r\n\t\t\t\tprintln(YES);\r\n\t\t\telse\r\n\t\t\t\tprintln(NO);\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printAns(long[] arr){\r\n\t\t\tif(arr != null && arr.length > 0){\r\n\t\t\t\tprint(arr[0]);\r\n\t\t\t\tfor(int i=1; i<arr.length; i++){\r\n\t\t\t\t\tprint(\" \");\r\n\t\t\t\t\tprint(arr[i]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tpublic void printlnAns(long[] arr){\r\n\t\t\tprintAns(arr);\r\n\t\t\tprintln();\r\n\t\t}\r\n\r\n\t\tpublic void printAns(int[] arr){\r\n\t\t\tif(arr != null && arr.length > 0){\r\n\t\t\t\tprint(arr[0]);\r\n\t\t\t\tfor(int i=1; i<arr.length; i++){\r\n\t\t\t\t\tprint(\" \");\r\n\t\t\t\t\tprint(arr[i]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tpublic void printlnAns(int[] arr){\r\n\t\t\tprintAns(arr);\r\n\t\t\tprintln();\r\n\t\t}\r\n\t\t\r\n\t\tpublic <T> void printAns(ArrayList<T> 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<arr.size(); i++){\r\n\t\t\t\t\tprint(\" \");\r\n\t\t\t\t\tprint(arr.get(i));\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tpublic <T> void printlnAns(ArrayList<T> 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.length; i++){\r\n\t\t\t\t\tprint(\" \");\r\n\t\t\t\t\tprint(arr[i]+add);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tpublic void printlnAns(int[] 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 printAns(ArrayList<Integer> 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.size(); i++){\r\n\t\t\t\t\tprint(\" \");\r\n\t\t\t\t\tprint(arr.get(i)+add);\r\n\t\t\t\t}\r\n\t\t\t}\t\t\t\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printlnAns(ArrayList<Integer> 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<arr.length; i+=split){\r\n\t\t\t\t\tprint(arr[i]);\r\n\t\t\t\t\tfor(int j=i+1; j<i+split; j++){\r\n\t\t\t\t\t\tprint(\" \");\r\n\t\t\t\t\t\tprint(arr[j]);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tprintln();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tpublic void printlnAnsSplit(int[] arr, int split){\r\n\t\t\tif(arr != null){\r\n\t\t\t\tfor(int i=0; i<arr.length; i+=split){\r\n\t\t\t\t\tprint(arr[i]);\r\n\t\t\t\t\tfor(int j=i+1; j<i+split; j++){\r\n\t\t\t\t\t\tprint(\" \");\r\n\t\t\t\t\t\tprint(arr[j]);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tprintln();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tpublic <T> void printlnAnsSplit(ArrayList<T> arr, int split){\r\n\t\t\tif(arr != null && !arr.isEmpty()){\r\n\t\t\t\tfor(int i=0; i<arr.size(); i+=split){\r\n\t\t\t\t\tprint(arr.get(i));\r\n\t\t\t\t\tfor(int j=i+1; j<i+split; j++){\r\n\t\t\t\t\t\tprint(\" \");\r\n\t\t\t\t\t\tprint(arr.get(j));\r\n\t\t\t\t\t}\r\n\t\t\t\t\tprintln();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\r\n\tstatic private void permutateAndSort(long[] a) {\r\n\t\tint n = a.length;\r\n\t\tRandom R = new Random(System.currentTimeMillis());\r\n\t\tfor(int i=0; i<n; i++) {\r\n\t\t\tint t = R.nextInt(n-i);\r\n\t\t\tlong temp = a[n-1-i];\r\n\t\t\ta[n-1-i] = a[t];\r\n\t\t\ta[t] = temp;\r\n\t\t}\r\n\t\tArrays.sort(a);\t\t\r\n\t}\r\n\t\r\n\tstatic private void permutateAndSort(int[] a) {\r\n\t\tint n = a.length;\r\n\t\tRandom R = new Random(System.currentTimeMillis());\r\n\t\tfor(int i=0; i<n; i++) {\r\n\t\t\tint t = R.nextInt(n-i);\r\n\t\t\tint temp = a[n-1-i];\r\n\t\t\ta[n-1-i] = a[t];\r\n\t\t\ta[t] = temp;\r\n\t\t}\r\n\t\tArrays.sort(a);\r\n\t}\r\n\t\r\n\tstatic private int[][] constructChildren(int n, int[] parent, int parentRoot){\r\n\t\tint[][] childrens = new int[n][];\r\n\t\t\r\n\t\tint[] numChildren = new int[n];\r\n\t\tfor(int i=0; i<parent.length; i++) {\r\n\t\t\tif(parent[i] != parentRoot)\r\n\t\t\t\tnumChildren[parent[i]]++;\r\n\t\t}\r\n\t\t\r\n\t\tfor(int i=0; i<n; i++) {\r\n\t\t\tchildrens[i] = new int[numChildren[i]];\r\n\t\t}\r\n\t\t\r\n\r\n\t\tint[] idx = new int[n];\r\n\t\tfor(int i=0; i<parent.length; i++) {\r\n\t\t\tif(parent[i] != parentRoot)\r\n\t\t\t\tchildrens[parent[i]][idx[parent[i]]++] = i;\r\n\t\t}\r\n\r\n\t\treturn childrens;\r\n\t}\r\n\t\r\n\tstatic private int[][][] constructDirectedNeighborhood(int n, int[][] e){\r\n\t\tint[] inDegree = new int[n];\r\n\t\tint[] outDegree = new int[n];\r\n\t\tfor(int i=0; i<e.length; i++) {\r\n\t\t\tint u = e[i][0];\r\n\t\t\tint v = e[i][1];\r\n\t\t\toutDegree[u]++;\r\n\t\t\tinDegree[v]++;\r\n\t\t}\r\n\t\t\r\n\t\tint[][] inNeighbors = new int[n][];\r\n\t\tint[][] outNeighbors = new int[n][];\r\n\t\tfor(int i=0; i<n; i++) {\r\n\t\t\tinNeighbors[i] = new int[inDegree[i]];\r\n\t\t\toutNeighbors[i] = new int[outDegree[i]];\r\n\t\t}\r\n\t\t\r\n\t\tint[] inIdx = new int[n];\r\n\t\tint[] outIdx = new int[n];\r\n\t\tfor(int i=0; i<e.length; i++) {\r\n\t\t\tint u = e[i][0];\r\n\t\t\tint v = e[i][1];\r\n\t\t\toutNeighbors[u][outIdx[u]++] = v;\r\n\t\t\tinNeighbors[v][inIdx[v]++] = u;\r\n\t\t}\r\n\t\t\r\n\t\treturn new int[][][] {inNeighbors, outNeighbors};\r\n\t}\r\n\t\r\n\tstatic private int[][] constructNeighborhood(int n, int[][] e) {\r\n\t\tint[] degree = new int[n];\r\n\t\tfor(int i=0; i<e.length; i++) {\r\n\t\t\tint u = e[i][0];\r\n\t\t\tint v = e[i][1];\r\n\t\t\tdegree[u]++;\r\n\t\t\tdegree[v]++;\r\n\t\t}\r\n\t\t\r\n\t\tint[][] neighbors = new int[n][];\r\n\t\tfor(int i=0; i<n; i++)\r\n\t\t\tneighbors[i] = new int[degree[i]];\r\n\t\t\r\n\t\tint[] idx = new int[n];\r\n\t\tfor(int i=0; i<e.length; i++) {\r\n\t\t\tint u = e[i][0];\r\n\t\t\tint v = e[i][1];\r\n\t\t\tneighbors[u][idx[u]++] = v;\r\n\t\t\tneighbors[v][idx[v]++] = u;\r\n\t\t}\r\n\t\t\r\n\t\treturn neighbors;\r\n\t}\r\n\t\r\n\tstatic private void drawGraph(int[][] e) {\r\n\t\tmakeDotUndirected(e);\r\n\t\ttry {\r\n\t\t\tfinal Process process = new ProcessBuilder(\"dot\", \"-Tpng\", \"graph.dot\")\r\n\t\t\t\t\t.redirectOutput(new File(\"graph.png\"))\r\n\t\t\t\t\t.start();\r\n\t\t} catch (IOException e1) {\r\n\t\t\t// TODO Auto-generated catch block\r\n\t\t\te1.printStackTrace();\r\n\t\t}\r\n\t\t\r\n\t}\r\n\t\r\n\tstatic private void makeDotUndirected(int[][] e) {\r\n\t\tMyPrintWriter out2 = null;\r\n\t\t try {\r\n\t\t\tout2 = new MyPrintWriter(new FileOutputStream(\"graph.dot\"));\r\n\t\t} catch (FileNotFoundException e1) {\r\n\t\t\t// TODO Auto-generated catch block\r\n\t\t\te1.printStackTrace();\r\n\t\t}\r\n\t\tout2.println(\"strict graph {\");\r\n\t\tfor(int i=0; i<e.length; i++){\r\n\t\t\tout2.println(e[i][0] + \"--\" + 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\tstatic private void makeDotDirected(int[][] e) {\r\n\t\tMyPrintWriter out2 = null;\r\n\t\t try {\r\n\t\t\tout2 = new MyPrintWriter(new FileOutputStream(\"graph.dot\"));\r\n\t\t} catch (FileNotFoundException e1) {\r\n\t\t\t// TODO Auto-generated catch block\r\n\t\t\te1.printStackTrace();\r\n\t\t}\r\n\t\tout2.println(\"strict digraph {\");\r\n\t\tfor(int i=0; i<e.length; i++){\r\n\t\t\tout2.println(e[i][0] + \"->\" + 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", "src_uid": "4b8161259545e44c7d1046be2e4fe014"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class C {\n\n BufferedReader br;\n PrintWriter out;\n StringTokenizer st;\n boolean eof;\n \n final int MOD = 1000000007;\n \n int fact[];\n int inv[];\n \n int c(int n, int k) {\n return (int)((long)fact[n] * inv[k] % MOD * inv[n - k] % MOD);\n }\n \n int binPow(int a, int b) {\n int res = 1;\n while (b != 0) {\n if ((b & 1) == 1)\n res = (int)((long)res * a % MOD);\n a = (int)((long)a * a % MOD);\n b >>= 1;\n }\n return res;\n }\n\n void solve() throws IOException {\n int n = nextInt();\n \n fact = new int[2 * n];\n inv = new int[2 * n];\n \n fact[0] = 1;\n for (int i = 1; i < 2 * n; i++)\n fact[i] = (int)((long)fact[i - 1] * i % MOD);\n \n for (int i = 0; i < 2 * n; i++)\n inv[i] = binPow(fact[i], MOD - 2);\n \n \n //int res = n;\n \n int res = 0;\n for (int i = 1; i <= n; i++) {\n res += c(2 * n - i - 1, n - 1);\n if (res >= MOD)\n res -= MOD;\n }\n \n res += res;\n if (res >= MOD)\n res -= MOD;\n \n res -= n;\n if (res < 0)\n res += MOD;\n \n out.print(res);\n \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 C().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", "src_uid": "13a9ffe5acaa79d97df88a069fc520b9"} {"source_code": "import java.util.*;\nimport java.io.*;\n//267630EY\npublic class Main236B2\n{\n static PrintWriter out=new PrintWriter(System.out);\n \n \n public static void main(String[] args) throws IOException\n {\n Scanner sc=new Scanner(System.in);\n \n int a=sc.nextInt();\n int b=sc.nextInt();\n int c=sc.nextInt();\n \n int[] div=new int[a*b*c+1];\n for(int i=1;i<=a*b*c;i++)\n {\n for(int j=i;j<=a*b*c;j+=i)\n {\n div[j]++;\n }\n }\n long ans=0;\n long f=1073741824;\n for(int i=1;i<=a;i++)\n {\n for(int j=1;j<=b;j++)\n {\n for(int k=1;k<=c;k++)\n {\n ans=(ans+div[i*j*k])%f;\n }\n }\n }\n out.println(ans);\n out.flush();\n \n \n \n \n \n \n \n \n \n }\n \n static class Scanner\n {\n BufferedReader br;\n StringTokenizer tk=new StringTokenizer(\"\");\n public Scanner(InputStream is) \n {\n br=new BufferedReader(new InputStreamReader(is));\n }\n public int nextInt() throws IOException\n {\n if(tk.hasMoreTokens())\n return Integer.parseInt(tk.nextToken());\n tk=new StringTokenizer(br.readLine());\n return nextInt();\n }\n public long nextLong() throws IOException\n {\n if(tk.hasMoreTokens())\n return Long.parseLong(tk.nextToken());\n tk=new StringTokenizer(br.readLine());\n return nextLong();\n }\n public String next() throws IOException\n {\n if(tk.hasMoreTokens())\n return (tk.nextToken());\n tk=new StringTokenizer(br.readLine());\n return next();\n }\n public String nextLine() throws IOException\n {\n tk=new StringTokenizer(\"\");\n return br.readLine();\n }\n public double nextDouble() throws IOException\n {\n if(tk.hasMoreTokens())\n return Double.parseDouble(tk.nextToken());\n tk=new StringTokenizer(br.readLine());\n return nextDouble();\n }\n public char nextChar() throws IOException\n {\n if(tk.hasMoreTokens())\n return (tk.nextToken().charAt(0));\n tk=new StringTokenizer(br.readLine());\n return nextChar();\n }\n public int[] nextIntArray(int n) throws IOException\n {\n int a[]=new int[n];\n for(int i=0;i<n;i++)\n a[i]=nextInt();\n return a;\n }\n public long[] nextLongArray(int n) throws IOException\n {\n long a[]=new long[n];\n for(int i=0;i<n;i++)\n a[i]=nextLong();\n return a;\n }\n public int[] nextIntArrayOneBased(int n) throws IOException\n {\n int a[]=new int[n+1];\n for(int i=1;i<=n;i++)\n a[i]=nextInt();\n return a;\n }\n public long[] nextLongArrayOneBased(int n) throws IOException\n {\n long a[]=new long[n+1];\n for(int i=1;i<=n;i++)\n a[i]=nextLong();\n return a;\n }\n }\n}\n\n", "src_uid": "4fdd4027dd9cd688fcc70e1076c9b401"} {"source_code": "import java.io.*;\nimport java.util.StringTokenizer;\n \npublic class Main{\npublic static void main(String[] args) throws IOException{\nBufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));\nString x = buffer.readLine();\nint n=Integer.parseInt(x);\nif(n==0)\n{System.out.println(\"0\"); System.exit(0);}\nif (n<10)\n{System.out.println(\"1\"); System.exit(0);}\nint count=0;\nwhile(n>9){\n\nint max=0;\nfor(int i=0; i<x.length(); i++)\n{String a=\"\"+x.charAt(i);\nint temp=Integer.parseInt(a);\nif (temp>max)\nmax=temp;\n}\nn=n-max;\nx=\"\"+n;\ncount++;\n}\nSystem.out.println(count+1);\n}}", "src_uid": "fc5765b9bd18dc7555fa76e91530c036"} {"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(), b = sc.nextInt(), c = sc.nextInt();\n int a1 = sc.nextInt(), b1 = sc.nextInt(), c1 = sc.nextInt();\n System.out.println((a1 != a && b1 != b && c1 != c) ? \"NO\" : \"YES\");\n }\n}\n", "src_uid": "91c9dbbceb467d5fd420e92c2919ecb6"} {"source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Olimp {\n public static void main(String[] args) throws IOException {\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 max=Math.max(a*d, b*c);\n int min=Math.min(a*d, b*c);\n min=max-min;\n int g=gcd(max, min);\n System.out.println(min/g+\"/\"+max/g);\n \n }\n public static int gcd(int a, int b){\n if(b==0) return a;\n return gcd(b, a%b);\n }\n}", "src_uid": "b0f435fc2f7334aee0d07524bc37cb1e"} {"source_code": "import java.util.PriorityQueue;\nimport java.util.Scanner;\n\npublic class d {\t\n\tpublic static void main(String[] args) {\n\t\tScanner stdin = new Scanner(System.in);\n\t\t\n\t\tint n = stdin.nextInt();\n\t\tint k = stdin.nextInt();\n\t\t\n\t\tPriorityQueue<Integer>[] arr = new PriorityQueue[200_001];\n\t\tfor (int i = 0; i < 200_001; i ++) arr[i] = new PriorityQueue<>();\n\t\t\n\t\tfor (int i = 0; i < n; i ++) {\n\t\t\tint in = stdin.nextInt();\n\t\t\tarr[in].add(0);\n\t\t\tint count = 0;\n\t\t\twhile (in >= 1) {\n\t\t\t\tin /= 2;\n\t\t\t\tarr[in].add(++count);\n\t\t\t}\n\t\t}\n\t\t\n//\t\tfor (int i = 1; i < 3; i ++) for (int j = 0; j < arr[i].size(); j ++) System.out.println(arr[i].poll());\n\t\t\n\t\tint min = 1_000_000_000;\n\t\t\n\t\tfor (int i = 0; i < 200_001; i++) {\n\t\t\tint taken = 0, sum = 0;\n\t\t\twhile (!arr[i].isEmpty() && taken < k) {\n\t\t\t\tsum += arr[i].poll();\n\t\t\t\ttaken ++;\n\t\t\t\tif (taken == k) min = Math.min(min, sum);\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(min);\n\t}\n}\n", "src_uid": "ed1a2ae733121af6486568e528fe2d84"} {"source_code": "import java.util.Scanner;\n\npublic class RemoveAdjacent {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int length = in.nextInt();\n String s = in.next();\n\n if (length == 1) {\n System.out.println(0);\n return;\n }\n\n int output = 0;\n // Assumes s has length at least 2\n for (int i = 0; i < length; i++) {\n for (int k = 122; k > 97; k--) { // ascii range for \"b\" through \"z\", note \"a\" can never be removed so it is excluded\n boolean nextIteration = false;\n for (int j = 0; j < s.length(); j++) {\n if (s.length() == 1) {\n nextIteration = false;\n break;\n }\n if (s.charAt(j) == k) {\n if (j == 0 && s.charAt(j + 1) == k - 1) {\n s = remove(s, j);\n output++;\n nextIteration = true;\n break;\n }\n else if (j == s.length() - 1 && s.charAt(j - 1) == k - 1) {\n s = remove(s, j);\n output++;\n nextIteration = true;\n break;\n }\n else if (j != 0 && j != s.length() - 1 && (s.charAt(j + 1) == k - 1 || s.charAt(j - 1) == k - 1)) {\n s = remove(s, j);\n output++;\n nextIteration = true;\n break;\n }\n }\n }\n\n if (nextIteration) break;\n }\n }\n\n System.out.println(output);\n }\n\n public static String remove(String s, int index) {\n // System.out.println(\"before:\" + s + \", after: \" + s.substring(0, index) + s.substring(index + 1));\n return s.substring(0, index) + s.substring(index + 1);\n }\n}\n", "src_uid": "9ce37bc2d361f5bb8a0568fb479b8a38"} {"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<Position> queue = new ArrayDeque<E.Position>();\n\tstatic HashSet<Position> visited = new HashSet<E.Position>();\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\treturn array[0] == i || array[1] == i || array[2] == i;\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 + 1)) {\n\t\t\t\t\tif (bit(temp.movesMask, (3 * manMoving))) {\n\t\t\t\t\t\tbest = max(best, pos + moveDistance[manMoving]);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\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}", "src_uid": "a14739b86d1fd62a030226263cdc1afc"} {"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\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n String s=scan.next();\n int i=0;\n int level1=0;\n while(i<s.length()){\n \n if(s.charAt(i)=='A'){\n if(i<s.length()-2 && s.charAt(i+1)=='B'){\n if(s.charAt(i+2)=='C')\n {\n System.out.println(\"YES\");\n level1=1;\n break;\n }\n \n }\n else if(i<s.length()-2 && s.charAt(i+1)=='C'){\n if(s.charAt(i+2)=='B')\n {\n System.out.println(\"YES\");\n level1=1;\n break;\n }\n \n }\n i++;\n }\n \n else if(s.charAt(i)=='B'){\n if(i<s.length()-2 && s.charAt(i+1)=='A'){\n if(s.charAt(i+2)=='C')\n {\n System.out.println(\"YES\");\n level1=1;\n break;\n }\n \n }\n else if(i<s.length()-2 && s.charAt(i+1)=='C'){\n if(s.charAt(i+2)=='A')\n {\n System.out.println(\"YES\");\n level1=1;\n break;\n }\n }\n i++;\n }\n else if(s.charAt(i)=='C'){\n if(i<s.length()-2 && s.charAt(i+1)=='B'){\n if(s.charAt(i+2)=='A')\n {\n System.out.println(\"YES\");\n level1=1;\n break;\n }\n \n }\n else if(i<s.length()-2 && s.charAt(i+1)=='A'){\n if(s.charAt(i+2)=='B')\n {\n System.out.println(\"YES\");\n level1=1;\n break;\n }\n }\n i++;\n }\n else{\n i++;\n }\n \n }\n if(level1==0)\n System.out.println(\"NO\");\n }\n}\n", "src_uid": "ba6ff507384570152118e2ab322dd11f"} {"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 Main\n{\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t\tScanner in = new Scanner(System.in);\n \n\t\tlong n = in.nextLong();\n\t\tlong k = in.nextLong();\n \n \t\tint sasha = 0;\n \t\tint lena = 0;\n \t\t\n\t\tif (n / k % 2 == 0) System.out.println(\"NO\");\n\t\telse System.out.println(\"YES\");\n\t}\n}", "src_uid": "05fd61dd0b1f50f154eec85d8cfaad50"} {"source_code": "\n\nimport java.util.HashSet;\nimport java.util.Scanner;\nimport java.util.Set;\n\npublic class NeatWords {\n public static void main(String[] args) {\n\n char[] neat={'W', 'E' ,'T','Y','I','A','F','H','K','L','Z','X','V','N','M'};\n Set<Character> x=new HashSet<Character>();\n for (int i = 0; i < neat.length; i++) {\n x.add(neat[i]);\n }\n Scanner sc = new Scanner(System.in);\n String s = sc.next();\n char[] inp=s.toCharArray();\n Set<Character> y=new HashSet<Character>();\n int count=0;\n for (int i = 0; i < inp.length; i++) {\n if( !x.contains(inp[i]) ){\n count++;\n }\n }\n if(count==0 || count==inp.length) {\n System.out.println(\"YES\");\n }\n else {\n System.out.println(\"NO\");\n }\n }\n}\n", "src_uid": "15008dcb8dc8506c39aef0e3d8fca70c"} {"source_code": "import java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Scanner;\n\npublic class Main {\n\tpublic static final int[] primes = new int[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59 };\n\tpublic static int[][] dp, last;\n\tpublic static int[] masking;\n\tpublic static int[] a;\n\tpublic static int N;\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tdp = new int[105][1 << 17];\n\t\tfor (int i = 0; i < 105; i++) {\n\t\t\tArrays.fill(dp[i], 1 << 29);\n\t\t}\n\t\tlast = new int[105][1 << 17];\n\t\tdp[0][0] = 0;\n\t\tN = sc.nextInt();\n\t\ta = new int[N + 1];\n\t\tfor (int i = 1; i <= N; i++) {\n\t\t\ta[i] = sc.nextInt();\n\t\t}\n\t\tinit();\n\t\tfor (int i = 1; i <= N; i++) {\n\t\t\tfor (int j = 1; j < 60; j++) {\n\t\t\t\tint x = (~masking[j]) & ((1 << 17) - 1);\n\t\t\t\tfor (int s = x;; s = (s - 1) & x) {\n\t\t\t\t\tif (Math.abs(j - a[i]) + dp[i - 1][s] < dp[i][s | masking[j]]) {\n\t\t\t\t\t\tdp[i][s | masking[j]] = Math.abs(j - a[i]) + dp[i - 1][s];\n\t\t\t\t\t\tlast[i][s | masking[j]] = j;\n\t\t\t\t\t}\n\t\t\t\t\tif (s == 0)\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint res = 1 << 29;\n\t\tint curr = -1;\n\t\tint cmask = -1;\n\t\tfor (int mask = 0; mask < (1 << 17); mask++) {\n\t\t\tif (dp[N][mask] < res) {\n\t\t\t\tres = dp[N][mask];\n\t\t\t\tcurr = last[N][mask];\n\t\t\t\tcmask = mask;\n\t\t\t}\n\t\t}\n\t\tArrayList<Integer> list = new ArrayList<Integer>();\n\t\tfor (int i = N; i > 0; i--) {\n\t\t\tlist.add(curr);\n\t\t\tcmask = cmask & (~masking[curr]);\n\t\t\tcurr = last[i - 1][cmask];\n\t\t}\n\t\tCollections.reverse(list);\n\t\tfor (int i : list) {\n\t\t\tSystem.out.print(i + \" \");\n\t\t}\n\t}\n\n\tpublic static void init() {\n\t\tmasking = new int[60];\n\t\tfor (int i = 1; i < 60; i++) {\n\t\t\tfor (int k = 0; k < 17; k++) {\n\t\t\t\tif (i % primes[k] == 0) {\n\t\t\t\t\tmasking[i] |= (1 << k);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}", "src_uid": "f26c74f27bbc723efd69c38ad0e523c6"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\n\n\npublic class A {\n\n\n\n\n\n\tstatic IR in = new IR(System.in);\n\tstatic double L,v1,v2;\n\tstatic double d;\n\t\n\t\n\tpublic static boolean can(double s)\n\t{\n\t\tdouble d0 = v1*s;\n\t\tdouble d1 = v2*s;\n\t\t\n\t\tif(Math.abs(d1-d0) > d) return true;\n\t\telse return false;\n\t}\n\tpublic static void main(String[]args)throws Throwable\n\t{\n\t\td = in.d(); L = in.d(); v1 = in.d(); v2 = in.d();\n\n\n\t double res = (double)(L-d)/(double)(Math.abs(v2+v1));\n\t System.out.printf(\"%.9f\",res);\n\t}\n\n\n\n\n\n\n\n\n\n\n\n\tstatic class IR{\n\t\tpublic BufferedReader reader;\n\t\tpublic StringTokenizer tokenizer;\n\n\t\tpublic IR(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\t\tpublic long ll()\n\t\t{\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic int j() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic double d()\n\t\t{\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\n\t}\n}\n", "src_uid": "f34f3f974a21144b9f6e8615c41830f5"} {"source_code": "\n\nimport java.util.Scanner;\n\npublic class Sleuth {\n\n\tpublic static void main(String[] args) {\n\n\t\tScanner scan = new Scanner(System.in);\n\t\tString str = scan.nextLine();\n\t\tint flag = 0;\n\t\tString str2 = str.replaceAll(\" \", \"\");\n\t\tString str3 = str2.toLowerCase();\n\t\tchar arr[] = { 'a', 'e', 'i', 'o', 'u', 'y' };\n\t\tchar lasChar = str3.charAt(str3.length() - 2);\n\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\tif (lasChar == arr[i]) {\n\t\t\t\tflag = 1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tif (flag == 1) {\n\t\t\tSystem.out.println(\"YES\");\n\t\t} else {\n\t\t\tSystem.out.println(\"NO\");\n\t\t}\n\n\t}\n\n}\n", "src_uid": "dea7eb04e086a4c1b3924eff255b9648"} {"source_code": "import java.util.Scanner;\npublic class Main {\n\tprivate static int[] ans=new int[1000001];\n\tpublic static void main(String[] args){\n\t\tScanner cin=new Scanner(System.in);\n\t\tlong x=cin.nextLong();\n\t\tlong max=0;\n\t\tif(check(x)||x==1) {\n\t\t\tSystem.out.println(1+\" \"+x);\n\t\t\treturn;\n\t\t}\n\t\tfor(long i=1;i*i<=x;i++) {\n\t\t\tif(lcm(i,x/i)==x&&gcd(i,x/i)==1) {\n\t\t\t\tmax=Math.max(max, i);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(max+\" \"+x/max);\n\t}\n\tpublic static long gcd(long m,long n) {\n\t\treturn m%n==0?n:gcd(n,m%n);\n\t}\n\tpublic static long lcm(long m,long n) {\n\t\treturn m*n/gcd(m,n);\n\t}\n\tpublic static boolean check(long n) {\n\t\tif(n<2) return false;\n\t\tfor(int i=2;i<=Math.sqrt(n);i++) {\n\t\t\tif(n%i==0) return false;\n\t\t}\n\t\treturn true;\n\t}\n}", "src_uid": "e504a04cefef3da093573f9df711bcea"} {"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 r = sc.nextInt();\n int g = sc.nextInt();\n int b = sc.nextInt();\n int time=29;\n if(r==0&&g==0&&b==0)System.out.print(0);\n else{\n while(r>0||g>0||b>0){\n r-=2;\n time++;\n if(r<1&&g<1&&b<1)break;\n g-=2;\n time++;\n if(r<1&&g<1&&b<1)break;\n b-=2;\n time++;\n }\n System.out.print(time);}\n System.exit(0);\n }\n \n\n}\n", "src_uid": "a45daac108076102da54e07e1e2a37d7"} {"source_code": "import java.util.*;\n\npublic class Solution {\n public static void main(String[] args) {\n Scanner scan = new Scanner(System.in);\n StringBuilder s1 = new StringBuilder(scan.nextLine());\n String s2 = scan.nextLine();\n StringBuilder s3 = new StringBuilder(scan.nextLine());\n \n s1.append(s2.charAt(0));\n s3.insert(0, s2.charAt(2));\n \n boolean res = true;\n for(int i = 0; i<4; i++) {\n if(s1.charAt(i) != s3.charAt(3-i)) {\n res = false;\n break;\n }\n }\n System.out.println(res ? \"YES\" : \"NO\");\n }\n}\n", "src_uid": "6a5fe5fac8a4e3993dc3423180cdd6a9"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Sol {\n public static void main(String[] args) {\n Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n long n = in.nextLong();\n System.out.println(solve(n));\n }\n\n private static long solve(long n) {\n if(n == 1) return 1;\n List<Long> divisor = primeFactors(n);\n if(divisor.size() == 1) return divisor.get(0);\n return 1;\n }\n\n static List<Long> primeFactors(long n) {\n Set<Long> res = new HashSet<>();\n if(n%2==0) res.add(2l);\n for(long i = 2; i < (long)Math.sqrt(n)+1; i++) {\n while(n%i == 0) {\n res.add(i);\n n = n/i;\n }\n }\n if(n > 2) res.add(n);\n return new ArrayList<>(res);\n }\n}", "src_uid": "f553e89e267c223fd5acf0dd2bc1706b"} {"source_code": "import java.util.*;\nimport java.io.*;\n\n\n\npublic class Main\n{\n public static void main(String args[])\n {\n // String s=fs.next();\n //char c[]=s.toCharArray();\n //int len=s.length();\n InputStream in=System.in;\n FastScanner fs=new FastScanner(in);\n PrintWriter out=new PrintWriter(System.out);\n int t=fs.nextInt();\n \n \n int x=fs.nextInt();\n int y=fs.nextInt();\n int tr=0;\n\n \n for(int i=0;i<=x;i++)\n {\n long n=(long)t-((long)y*(long)i);\n if(n<0)\n break;\n if(n%x==0)\n {\n tr=1;\n x=(int)n/x;\n y=i;\n break;\n }\n }\n \n\n\n \n if(tr==1)\n { out.println(\"YES\"); \n out.println(x+\" \"+y);\n }\n else \n out.println(\"NO\");\n out.close();\n \n\n \n }\n static class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n FastScanner(InputStream f) {\n try {\n br = new BufferedReader(new InputStreamReader(f));\n } catch (Exception e) {\n e.printStackTrace();\n }\n }\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n char [] charArray()\n {\n return next().toCharArray();\n }\n \n\n\n\n \n }\n\n}\n\n", "src_uid": "b031daf3b980e03218167f40f39e7b01"} {"source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author prakharjain\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n EBeautifulMatrix solver = new EBeautifulMatrix();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class EBeautifulMatrix {\n long[] fac;\n int mod = 998244353;\n long[][] dp;\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int n = in.nextInt();\n\n int[][] a = new int[n][n];\n\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n a[i][j] = in.nextInt() - 1;\n }\n }\n\n fac = new long[2001];\n\n fac[0] = 1;\n\n for (int i = 1; i <= 2000; i++) {\n fac[i] = (i * fac[i - 1]) % mod;\n }\n\n long[] rank = new long[n];\n\n rank[0] = calRank(a[0], n);\n\n long tot = calTot(n);\n for (int i = 1; i < n; i++) {\n rank[i] = calDel(a[i - 1], a[i], n);\n }\n\n long ans = rank[0];\n\n for (int i = 1; i < n; i++) {\n ans *= tot;\n ans %= mod;\n\n ans += rank[i];\n ans %= mod;\n }\n\n out.println(ans);\n }\n\n long calRank(int[] a, int n) {\n long rank = 0;\n\n BinaryIndexedTree bit = new BinaryIndexedTree(n);\n for (int i = 0; i < n; i++) {\n int num = a[i];\n\n int prev = 0;\n if (num > 0) {\n prev = num - bit.sum(num - 1);\n }\n\n if (prev > 0) {\n rank += prev * fac[n - 1 - i];\n rank %= mod;\n }\n\n bit.update(num, 1);\n }\n\n return rank;\n }\n\n long calTot(int n) {\n\n dp = new long[n + 1][n + 1];\n\n dp[0][0] = 1;\n dp[1][0] = 1;\n\n for (int i = 2; i <= n; i++) {\n for (int j = 0; j <= i; j++) {\n if (i > j) {\n if (j > 0) {\n dp[i][j] += j * dp[i - 1][j - 1];\n dp[i][j] %= mod;\n }\n dp[i][j] += (i - j) * dp[i - 1][j];\n dp[i][j] %= mod;\n } else {\n dp[i][j] += (i - 1) * dp[i - 1][j - 2];\n dp[i][j] %= mod;\n }\n }\n }\n\n return dp[n][n];\n }\n\n long calDel(int[] pa, int[] a, int n) {\n\n long rank = 0;\n\n BinaryIndexedTree sbit = new BinaryIndexedTree(n);\n BinaryIndexedTree nsbit = new BinaryIndexedTree(n);\n\n for (int i = 0; i < n; i++) {\n sbit.update(i, 1);\n }\n\n int totsame = n;\n\n for (int i = 0; i < n; i++) {\n int same = sbit.sum(a[i] - 1);\n int usame = nsbit.sum(a[i] - 1);\n\n if (pa[i] < a[i]) {\n int val = sbit.value(pa[i]);\n\n same -= val;\n }\n\n if (sbit.value(pa[i]) == 1) {\n if (totsame > 1)\n rank += same * dp[n - 1 - i][totsame - 2];\n rank %= mod;\n if (totsame > 0)\n rank += usame * dp[n - 1 - i][totsame - 1];\n\n sbit.update(pa[i], -1);\n nsbit.update(pa[i], 1);\n\n totsame--;\n } else {\n if (totsame > 0)\n rank += same * dp[n - 1 - i][totsame - 1];\n rank %= mod;\n rank += usame * dp[n - 1 - i][totsame];\n }\n\n if (sbit.value(a[i]) == 1) {\n sbit.update(a[i], -1);\n totsame--;\n } else {\n nsbit.update(a[i], -1);\n }\n\n rank %= mod;\n }\n\n return rank;\n }\n\n class BinaryIndexedTree {\n int n;\n int[] tree;\n\n public BinaryIndexedTree(int n) {\n super();\n this.n = n;\n this.tree = new int[n + 1];\n }\n\n public int sum(int idx) {\n idx++;\n\n int sum = 0;\n\n while (idx > 0) {\n sum += tree[idx];\n idx -= (idx & -idx);\n }\n\n return sum;\n }\n\n public void update(int idx, int v) {\n idx++;\n\n while (idx <= n) {\n tree[idx] += v;\n idx += (idx & -idx);\n }\n }\n\n public int value(int i) {\n int val = sum(i);\n\n if (i > 0) {\n val -= sum(i - 1);\n }\n\n return val;\n }\n\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void println(long i) {\n writer.println(i);\n }\n\n }\n}\n\n", "src_uid": "46253becfda9a45ce670dc7d835beaf3"} {"source_code": "import java.util.*;\npublic class TicTacToe {\n\t\n\tstatic int flag=0;\n\tstatic int a[][];\n\tstatic void check(int x1,int x2,int y1,int y2)\n\t{\n\t\tint cnt=0;\n\t\tfor(int i=x1;i<=x2;i++)\n\t\t{\n\t\t\tfor(int j=y1;j<=y2;j++)\n\t\t\t{\n\t\t\t\tif(a[i][j]!=46)\n\t\t\t\t\tcnt++;\n\t\t\t}\n\t\t}\n\t\tif(cnt==9)\n\t\t\tflag=1;\n\t}\n\tpublic static void main(String args[])\n\t{\n\t\tScanner sc=new Scanner(System.in);\n\t\ta=new int[9][9];\n\t\tString s[]=new String[11];\n\t\tfor(int i=0;i<11;i++)\n\t\t{\n\t\t\ts[i]=sc.nextLine();\n\t\t}\n\t\tint x=0,y=0;\n\t\tfor(int i=0;i<11;i++)\n\t\t{\n\t\t\tfor(int j=0;j<s[i].length();j++)\n\t\t\t{\n\t\t\t\tif(s[i].charAt(j)=='.')\n\t\t\t\t\ta[x][y++]=46;\n\t\t\t\t\n\t\t\t\telse if(s[i].charAt(j)=='x')\n\t\t\t\t\ta[x][y++]=120;\n\t\t\t\telse if(s[i].charAt(j)=='o')\n\t\t\t\t\ta[x][y++]=111;\n\t\t\t\t\n\t\t\t\tif(j+1==3 || j+1==7)\n\t\t\t\t\tj++;\n\t\t\t}\n\t\t\tx++;\n\t\t\ty=0;\n\t\t\tif(i+1==3 || i+1==7)\n\t\t\t\ti++;\n\t\t}\n\t\t\n\t\t\n\t\tx=sc.nextInt();\n\t\ty=sc.nextInt();\n\t\tx=x%3;\n\t\ty=y%3;\n\t\tif(x==0)\n\t\t\tx=3;\n\t\tif(y==0)\n\t\t\ty=3;\n\t\t\n\t\tint b=0,c=0,d=0,e=0;\n\t\t\n\t\tif(x==1 & y==1)\n\t\t{\n\t\t\tb=0;\n\t\t\tc=2;\n\t\t\td=0;\n\t\t\te=2;\n\t\t\tcheck(0,2,0,2);\n\t\t}\n\t\telse if(x==1 & y==2)\n\t\t{\n\t\t\tb=0;\n\t\t\tc=2;\n\t\t\td=3;\n\t\t\te=5;\n\t\t\tcheck(0,2,3,5);\n\t\t}\n\t\telse if(x==1 & y==3)\n\t\t{\n\t\t\tb=0;\n\t\t\tc=2;\n\t\t\td=6;\n\t\t\te=8;\n\t\t\tcheck(0,2,6,8);\n\t\t}\n\t\telse if(x==2 & y==1)\n\t\t{\n\t\t\tb=3;\n\t\t\tc=5;\n\t\t\td=0;\n\t\t\te=2;\n\t\t\tcheck(3,5,0,2);\n\t\t}\n\t\telse if(x==2 & y==2)\n\t\t{\n\t\t\tb=3;\n\t\t\tc=5;\n\t\t\td=3;\n\t\t\te=5;\n\t\t\tcheck(3,5,3,5);\n\t\t}\n\t\telse if(x==2 & y==3)\n\t\t{\n\t\t\tb=3;\n\t\t\tc=5;\n\t\t\td=6;\n\t\t\te=8;\n\t\t\tcheck(3,5,6,8);\n\t\t}\n\t\telse if(x==3 & y==1)\n\t\t{\n\t\t\tb=6;\n\t\t\tc=8;\n\t\t\td=0;\n\t\t\te=2;\n\t\t\tcheck(6,8,0,2);\n\t\t}\n\t\telse if(x==3 & y==2)\n\t\t{\n\t\t\tb=6;\n\t\t\tc=8;\n\t\t\td=3;\n\t\t\te=5;\n\t\t\tcheck(6,8,3,5);\n\t\t}\n\t\telse if(x==3 & y==3)\n\t\t{\n\t\t\tb=6;\n\t\t\tc=8;\n\t\t\td=6;\n\t\t\te=8;\n\t\t\tcheck(6,8,6,8);\n\t\t}\n\t\t\n\t\tif(flag==1)\n\t\t{\n\t\t\tfor(int i=0;i<9;i++)\n\t\t\t{\n\t\t\t\tif(i==3 || i==6)\n\t\t\t\tSystem.out.println();\n\t\t\t\tfor(int j=0;j<9;j++)\n\t\t\t\t{\n\t\t\t\t\tif(j==3 || j==6)\n\t\t\t\t\t\tSystem.out.print(\" \");\n\t\t\t\t\t\n\t\t\t\t\tif(a[i][j]==46)\n\t\t\t\t\t\tSystem.out.print(\"!\");\n\t\t\t\t\tif(a[i][j]==120)\n\t\t\t\t\t\tSystem.out.print(\"x\");\n\t\t\t\t\t\n\t\t\t\t\tif(a[i][j]==111)\n\t\t\t\t\t\tSystem.out.print(\"o\");\n\t\t\t\t}\n\t\t\t\tSystem.out.println();\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tfor(int i=0;i<9;i++)\n\t\t\t{\n\t\t\t\tif(i==3 || i==6)\n\t\t\t\tSystem.out.println();\n\t\t\t\tfor(int j=0;j<9;j++)\n\t\t\t\t{\n\t\t\t\t\tif(j==3 || j==6)\n\t\t\t\t\t\tSystem.out.print(\" \");\n\t\t\t\t\tif(a[i][j]==46)\n\t\t\t\t\t{\n\t\t\t\t\tif(i>=b & i<=c & j>=d && j<=e)\n\t\t\t\t\t\tSystem.out.print(\"!\");\n\t\t\t\t\telse \n\t\t\t\t\t\tSystem.out.print(\".\");\n\t\t\t\t\t}\n\t\t\t\t\tif(a[i][j]==120)\n\t\t\t\t\t\tSystem.out.print(\"x\");\n\t\t\t\t\t\n\t\t\t\t\tif(a[i][j]==111)\n\t\t\t\t\t\tSystem.out.print(\"o\");\n\t\t\t\t}\n\t\t\t\tSystem.out.println();\n\t\t\t}\n\t\t}\n\t\tsc.close();\n\t}\n}\n", "src_uid": "8f0fad22f629332868c39969492264d3"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class A {\n\n BufferedReader br;\n PrintWriter out;\n StringTokenizer st;\n boolean eof;\n\n void solve() throws IOException {\n int n = nextInt();\n int m = nextInt();\n int a = nextInt() - 1;\n int b = nextInt() - 1;\n \n \n int r1 = a / m;\n int c1 = a - r1 * m;\n \n int r2 = b / m;\n int c2 = b - r2 * m;\n \n if (a == 0 && b == n - 1) {\n out.print(1);\n return;\n }\n \n if (r1 == r2) {\n out.print(1);\n return;\n }\n \n if (c1 == 0 && c2 == m - 1) {\n out.print(1);\n return;\n }\n \n if (c1 == 0 && b == n - 1) {\n out.print(1);\n return;\n }\n \n if (c1 == 0 || c2 == m - 1) {\n out.print(2);\n return;\n }\n \n if (c1 == c2 + 1) {\n out.print(2);\n return;\n }\n \n if (r2 == r1 + 1) {\n out.print(2);\n return;\n }\n \n if (b == n - 1) {\n out.print(2);\n return;\n }\n \n out.print(3);\n \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 A().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", "src_uid": "f256235c0b2815aae85a6f9435c69dac"} {"source_code": "\nimport java.util.Arrays;\nimport java.util.Scanner;\npublic class A {\n\n\tpublic static void main(String[] args) {\n \tScanner scan=new Scanner(System.in);\n \tint [] studenti=new int[6];\n \tString otvet=\"\";\n \tfor (int i = 0; i < 6; i++) {\n studenti[i] = scan.nextInt();\n }\n for (int i=3;i<6;i++)\n {\n\t if (studenti [0]+studenti[1]+studenti[2]==studenti [3]+studenti[4]+studenti[5])\n\t {\n\t \totvet=\"YES\";\n\t \tbreak;\n }\n\t int per=studenti[0];\n\t studenti[0]=studenti[i];\n\t studenti[i]=per;\n\t for (int j=3;j<6;j++)\n\t {\n\t\t if (studenti [0]+studenti[1]+studenti[2]==studenti [3]+studenti[4]+studenti[5])\n\t\t {\n\t\t \totvet=\"YES\";\n\t\t \tbreak;\n\t }\n\t\t int per1=studenti[1];\n\t\t studenti[1]=studenti[j];\n\t\t studenti[j]=per1;\n\t\t for (int k=3;k<6;k++)\n\t\t {\n\t\t\t if (studenti [0]+studenti[1]+studenti[2]==studenti [3]+studenti[4]+studenti[5])\n\t\t\t {\n\t\t\t \totvet=\"YES\";\n\t\t\t \tbreak;\n\t\t\t }\n\t\t\t int per2=studenti[2];\n\t\t\t studenti[2]=studenti[k];\n\t\t\t studenti[k]=per2;\n\t\t }\n\t }\n }\n\n \n if (otvet==\"YES\")\n {\n\t System.out.println(otvet);\n }\n \n else{\n\t System.out.println(\"NO\");\n }\n \t\n \t\n\t}\n}\n", "src_uid": "2acf686862a34c337d1d2cbc0ac3fd11"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class B {\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 k = nextInt();\n\t\t\n\t\tk = Math.min(k, n / 2);\n\t\t\n\t\tlong res = (long)k * (k - 1); // first and last\n\t\tres += (long)k * k; // first to last\n\t\tres += (long)(n - 2 * k) * 2 * k; // mid to rest\n\t\t\n\t\tout.println(res);\n\t}\n\n\tB() 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 B();\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}", "src_uid": "ea36ca0a3c336424d5b7e1b4c56947b0"} {"source_code": "import java.util.Scanner;\n\npublic class ProblemB {\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 = scan.nextLong();\n\t\tscan.close();\n\t\tlong m;\n\t\tif(k % 2 == 0) {\n\t\t\tm = k / 2 - 1;\n\t\t}else {\n\t\t\tm = k / 2;\n\t\t}\n\t\tif(n >= k) {\n\t\t\tSystem.out.println(m);\n\t\t}else {\n\t\t\tif(2 * n - 1 < k) {\n\t\t\t\tSystem.out.println(0);\n\t\t\t}else {\n\t\t\t\tlong ans = (2 * n - k + 1) / 2;\n\t\t\t\tSystem.out.println(ans);\n\t\t\t}\n\t\t}\n\n\t}\n}", "src_uid": "98624ab2fcd2a50a75788a29e04999ad"} {"source_code": "import java.util.Scanner;\n\n\npublic class SolutionA {\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 if (!(a==0&&b==0)&&(a == b || a + 1 == b || b + 1 == a)) {\n System.out.println(\"YES\");\n } else {\n System.out.println(\"NO\");\n }\n\n }\n}\n", "src_uid": "ec5e3b3f5ee6a13eaf01b9a9a66ff037"} {"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.StringTokenizer;\nimport java.io.InputStream;\nimport java.util.Arrays;\n\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskA solver = new TaskA();\n solver.solve(1, in, out);\n out.close();\n }\n}\n\nclass TaskA {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int [] lengths = {\n in.next().substring(2).length(),\n in.next().substring(2).length(),\n in.next().substring(2).length(),\n in.next().substring(2).length()\n };\n \n int [] buf, buf2;\n \n int numberOfGreater = 0, numberOfLess = 0;\n \n int max_ind = getMax(lengths);\n int min_ind = getMin(lengths);\n \n buf = Arrays.copyOf(lengths, 4);\n for(int item:buf)\n if(item/lengths[min_ind] >= 2)\n numberOfGreater++;\n \n buf2 = Arrays.copyOf(lengths, 4);\n for(int item:buf2)\n if(item*2 <= lengths[max_ind])\n numberOfLess++;\n \n int indx = 0;\n if(numberOfGreater == 3 && numberOfLess == 3)\n indx = 2;\n else if(numberOfGreater == 3)\n indx = min_ind;\n else if(numberOfLess == 3)\n indx = max_ind;\n else\n indx = 2;\n \n out.println(\"ABCD\".charAt(indx));\n }\n \n public int getMin(int [] items){\n int min = 101;\n int index = 0;\n for(int i = 0; i<items.length; i++)\n if(items[i] < min){\n min = items[i];\n index = i;\n }\n return index;\n }\n \n public int getMax(int [] items){\n int max = 0;\n int index = 0;\n for(int i = 0; i<items.length; i++)\n if(items[i] > max){\n max = items[i];\n index = i;\n }\n return index;\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}", "src_uid": "30725e340dc07f552f0cce359af226a4"} {"source_code": "/*\njavac f.java && java f\n*/\n\nimport java.io.*;\nimport java.util.*;\n\npublic class f {\n\tpublic static void main(String[] args) { new f(); }\n\tFS in = new FS();\n\tPrintWriter out = new PrintWriter(System.out);\n\n\tint n;\n\tlong[] a;\n\n\tint MAX = 5001;\n\tint pcnt, pr[];\n\tint[][] vp, cs;\n\tboolean[] isnt;\n\n\tf() {\n\t\tpcnt = 0;\n\t\tisnt = new boolean[MAX];\n\t\tisnt[0] = true; isnt[1] = true;\n\t\tfor (int i = 2; i < MAX; i++)\n\t\t\tif (!isnt[i]) {\n\t\t\t\tpcnt++;\n\t\t\t\tfor (int j = (i << 1); j < MAX; j += i)\n\t\t\t\t\tisnt[j] = true;\n\t\t\t}\n\t\tpr = new int[pcnt]; pcnt = 0;\n\t\tfor (int i = 0; i < MAX; i++)\n\t\t\tif (!isnt[i])\n\t\t\t\tpr[pcnt++] = i;\n\n\t\t/*\n\t\tlong ops = 0, gap3 = 0;\n\t\tfor (int i = 0; i < pcnt; i++) {\n\t\t\tlong del = i == 0 ? 1 : pr[i] - pr[i - 1];\n\t\t\tout.printf(\"del = %d | p = %d%n\", del, pr[i]);\n\t\t\tops += (del * del * del);\n\t\t\tgap3 = max(gap3, del * del * del);\n\t\t}\n\t\tout.println(\"--> \" + ops + \" OW3 \" + gap3);\n\t\t*/\n\n\t\tvp = new int[MAX][pcnt];\n\t\tfor (int i = 2; i < MAX; i++)\n\t\t\tfor (int j = 0; j < pcnt; j++) {\n\t\t\t\tint k = i;\n\t\t\t\twhile (k > 0) {\n\t\t\t\t\tvp[i][j] += (k / pr[j]);\n\t\t\t\t\tk /= pr[j];\n\t\t\t\t}\n\t\t\t}\n\t\tcs = new int[MAX][pcnt + 1];\n\t\tfor (int i = 2; i < MAX; i++)\n\t\t\tfor (int j = 1; j <= pcnt; j++)\n\t\t\t\tcs[i][j] = vp[i][j - 1] + cs[i][j - 1];\n\t\t\n\t\tn = in.nextInt();\n\t\ta = new long[MAX];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint x = in.nextInt();\n\t\t\tif (x == 0) x++;\n\t\t\ta[x]++;\n\t\t}\n\t\tlong[] f = new long[MAX + 1];\n\t\tfor (int i = 1; i <= MAX; i++)\n\t\t\tf[i] = f[i - 1] + a[i - 1];\n\n\t\tlong[] dist = new long[MAX + 1];\n\t\tfor (int i = 1; i <= MAX; i++)\n\t\t\tdist[i] = dist[i - 1] + a[i - 1] * cs[i - 1][pcnt];\n\n\t\t// F I X T H I S\n\t\tlong ans = dist[MAX];\n\t\tint l = 2, r; \n\t\tfor (int i = 0; i < pcnt; i++) {\n\t\t\tr = i == pcnt - 1 ? MAX - 1 : pr[i + 1] - 1;\n\t\t\t// everybody outside this range of highest prime must travel to 1 first\n\t\t\t// then travel up to the lca we're trying at each step\n\t\t\tlong blw = dist[MAX] - (dist[r + 1] - dist[l]);\n\t\t\t// so when trying lca(j, k) we need to know how many primes are on in it\n\t\t\t// and how far every person in the range [l, r] will need to travel\n\t\t\tfor (int x = r; x >= l; x--)\n\t\t\t\tfor (int y = x; y >= l; y--) {\n\t\t\t\t\t// lca will be gotten as (pIDX, cnt)\n\t\t\t\t\tint[] lca = {-1, 0};\n\t\t\t\t\tfor (int z = i; z >= 0; z--)\n\t\t\t\t\t\tif (vp[x][z] != vp[y][z]) {\n\t\t\t\t\t\t\tlca[0] = z;\n\t\t\t\t\t\t\tlca[1] = min(vp[x][z], vp[y][z]);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\n\t\t\t\t\tlong up = lca[1] + cs[x][pcnt] - cs[x][lca[0] + 1];\n\t\t\t\t\tup *= (f[MAX] - f[r + 1] + f[l]);\n\n\t\t\t\t\tlong abv = 0;\n\t\t\t\t\tfor (int z = r; z >= l; z--) {\n\t\t\t\t\t\tif (x == z && y == z) continue;\n\t\t\t\t\t\t// given lca(x, y) = {w, cnt}\n\t\t\t\t\t\t// if we get to w add in prefix of other primes in a[z] * cs[w - 1]\n\t\t\t\t\t\t// add a[z] * [abs(cnt - cnt[z]) to abv\n\t\t\t\t\t\t// if we dont get to w before they differ\n\t\t\t\t\t\t// add a[z] * (diff to here + here up)\n\t\t\t\t\t\tfor (int w = i; w >= lca[0]; w--) {\n\t\t\t\t\t\t\tif (w == lca[0]) {\n\t\t\t\t\t\t\t\tabv += a[z] * cs[z][w]; \n\t\t\t\t\t\t\t\tabv += a[z] * abs(vp[z][w] - lca[1]);\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (vp[z][w] != vp[x][w]) {\n\t\t\t\t\t\t\t\tabv += a[z] * cs[z][w];\n\t\t\t\t\t\t\t\tabv += a[z] * abs(vp[z][w] - vp[x][w]);\n\t\t\t\t\t\t\t\tabv += a[z] * (cs[x][w] - cs[x][lca[0] + 1]);\n\t\t\t\t\t\t\t\tabv += a[z] * lca[1];\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\tans = min(ans, abv + blw + up);\n\t\t\t\t}\n\t\t\tl = r + 1;\n\t\t}\n\n\t\tout.println(ans);\n\t\tout.close();\n\t}\n\t\n\tint abs(int x) { if (x < 0) return -x; return x; }\n\tlong abs(long x) { if (x < 0) return -x; return x; }\n\tint max(int x, int y) { if (x < y) return y; return x; }\n\tint min(int x, int y) { if (x > y) return y; return x; }\n\tlong max(long x, long y) { if (x < y) return y; return x; }\n\tlong min(long x, long y) { if (x > y) return y; return x; }\n\tint gcd(int x, int y) { while (y != 0) { x = y^(x^(y = x)); y %= x; } return x; }\n\tlong gcd(long x, long y) { while (y != 0) { x = y^(x^(y = x)); y %= x; } return x; }\n\tlong lcm(int x, int y) { long xy = x; xy *= y; return xy / gcd(x, y); }\n\tlong lcm(long x, long y) { return (x * y) / gcd(x, y); }\n\n\tclass FS {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(\"\");\n\t\tString next() {\n\t\t\twhile (!st.hasMoreTokens()) {\n\t\t\t\ttry { st = new StringTokenizer(br.readLine()); }\n\t\t\t\tcatch (Exception e) {}\n\t\t\t} return st.nextToken();\n\t\t}\n\t\tint nextInt() { return Integer.parseInt(next()); }\n\t\tlong nextLong() { return Long.parseLong(next()); }\n\t\tdouble nextDouble() { return Double.parseDouble(next()); }\n\n\t\tvoid intArr(int sz, int[] x) { for (int i = 0; i < sz; i++) x[i] = nextInt(); }\n\t\tvoid longArr(int sz, long[] x) { for (int i = 0; i < sz; i++) x[i] = nextLong(); }\n\t\tvoid doubleArr(int sz, double[] x) { for (int i = 0; i < sz; i++) x[i] = nextDouble(); }\n\t}\n}\n\n", "src_uid": "40002052843ca0357dbd3158b16d59f4"} {"source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.HashMap;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n public static void main(String[] args) {\n FastReader in = new FastReader();\n String s = in.next();\n boolean flag = true;\n char c[] = new char[s.length()];\n if (s.charAt(0) == 'a') {\n c[0] = 'a';\n for (int i = 1; i < s.length(); i++) {\n for (int j = 0; j < s.length(); j++) {\n if (s.charAt(i) == c[j] || s.charAt(i) - c[j] == 1) {\n c[i] = s.charAt(i);\n break;\n }\n }\n }\n for (int i = 0; i < s.length(); i++) {\n if (s.charAt(i) != c[i]) {\n flag = false;\n }\n }\n if (flag == true) {\n System.out.println(\"YES\");\n } else {\n System.out.println(\"NO\");\n }\n \n } else {\n System.out.println(\"NO\");\n }\n\n }\n}\n\nclass FastReader {\n\n BufferedReader br;\n StringTokenizer st;\n\n public FastReader() {\n InputStreamReader inr = new InputStreamReader(System.in);\n br = new BufferedReader(inr);\n\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n\n }\n\n long nextLong() {\n return Long.parseLong(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", "src_uid": "c4551f66a781b174f95865fa254ca972"} {"source_code": "import java.util.*;\npublic class Main {\npublic static void main(String [] args){\n\tScanner in=new Scanner(System.in);\n\tint xp=in.nextInt();\n\tint yp=in.nextInt();\n\tint xv=in.nextInt();\n\tint yv=in.nextInt();\n\tif(xp <= xv && yp <=yv || xp + yp <= Math.max(xv,yv)){\n\t\tSystem.out.print(\"Polycarp\");\n\t\treturn;\n\t}\n System.out.print(\"Vasiliy\");\n}\n}", "src_uid": "2637d57f7809ff8f922549c617709074"} {"source_code": "import java.util.InputMismatchException;\nimport java.io.*;\nimport java.util.*;\n\n/**\n * Generated by Contest helper plug-in\n * Actual solution is at the bottom\n */\npublic class Main {\n public static void main(String[] args) {\n InputReader in = new StreamInputReader(System.in);\n PrintWriter out = new PrintWriter(System.out);\n run(in, out);\n }\n\n public static void run(InputReader in, PrintWriter out) {\n Solver solver = new Move();\n solver.solve(1, in, out);\n Exit.exit(in, out);\n }\n}\n\nclass StreamInputReader extends InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar, numChars;\n\n public StreamInputReader(InputStream stream) {\n this.stream = stream;\n curChar = 0;\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 @Override\n public void close() {\n try {\n stream.close();\n } catch (IOException ignored) {\n }\n }\n}\n\nabstract class InputReader {\n private boolean finished = false;\n\n public abstract int read();\n\n\n public String nextToken() {\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 private boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public void setFinished(boolean finished) {\n this.finished = finished;\n }\n\n public abstract void close();\n}\n\ninterface Solver {\n public void solve(int testNumber, InputReader in, PrintWriter out);\n}\n\nclass Exit {\n private Exit() {\n }\n\n public static void exit(InputReader in, PrintWriter out) {\n in.setFinished(true);\n in.close();\n out.close();\n }\n}\n\nclass Move implements Solver {\n\n\n Vector<String> ans ;\n\n void print(int i0, int j0, int i1, int j1) {\n if (i0 == i1) {\n int mn = Math.min(j0, j1);\n String p[] = H.split(\" \");\n for (int j = 0; j < p.length; ++j) {\n if (p[j].equals(\"D\")) {\n ans.add(\"D\"+(mn+1));\n } else {\n ans.add(p[j]+(i0+1));\n }\n }\n } else {\n int mx = Math.max(i0, i1);\n String p[] = V.split(\" \");\n for (int j = 0; j < p.length; ++j) {\n if (p[j].equals(\"R\")) {\n ans.add(\"R\"+(mx+1));\n } else {\n ans.add(p[j]+(j0+1));\n }\n }\n }\n }\n static final String H = \"D L D R D L D R D L D R D\";\n static final String V = \"R D R U R D R U R D R U R\";\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n\n String H = \"D L D R D L D R D L D R D\";//swap, (i, j) -> (i, j + 1)/\n\n //\n // // Uj Li Ri\n String V = \"R D R U R D R U R D R U R\"; // swap (i, j) (i + 1, j)\n // R(i+1), Down up -> j\n\n ans = new Vector<String> () ;\n //build();\n char s[] = new char[36];\n for (int i = 0; i <= 9; ++i) {\n s[i] = (char)(i + '0');\n }\n for (int i = 0; i < 26; ++i) {\n s[i + 10] = (char)(i + 'A');\n }\n char tmp[][] = new char[6][6];\n int p = 0;\n for (int i = 0; i < s.length; ++i) {\n tmp[p / 6][p % 6] = s[i];\n p ++ ;\n }\n State start = new State(tmp);\n\n char r[][] = new char[6][];\n for (int i =0 ; i < 6; ++i)\n r[i] = in.nextToken().toCharArray();\n State cur = new State(r);\n\n\n HashMap<Character, P> pointer = new HashMap<Character, P> ();\n for (int i = 0; i < 6; ++i)\n for (int j = 0; j < 6; ++j)\n pointer.put(cur.s[i][j], new P(j, i));\n\n while (!start.equals(cur)) {\n for (int i = 0; i < 6; ++i)\n for (int j = 0; j < 6; ++j) {\n if (start.s[i][j] != cur.s[i][j]) {\n while (start.s[i][j] != cur.s[i][j]) {\n P tt = pointer.get(start.s[i][j]);\n int pi = tt.y;\n int pj = tt.x;\n int dj = (j - pj == 0 ? 0 : (j - pj) / Math.abs(j - pj));\n int di = (i - pi == 0 ? 0 : (i - pi) / Math.abs(i - pi));\n int npi = -1, npj = -1;\n if (di != 0) {\n npi = pi + di;\n npj = pj ;\n } else if (dj != 0) {\n npi = pi;\n npj = pj + dj;\n } else throw new RuntimeException();\n print(npi, npj, pi, pj);\n char ch = cur.s[npi][npj];\n cur.s[npi][npj] = cur.s[pi][pj];\n cur.s[pi][pj] = ch;\n pointer.put(cur.s[npi][npj], new P(npj, npi));\n pointer.put(cur.s[pi][pj], new P(pj, pi));\n }\n }\n }\n }\n\n cur = new State(r);\n out.print(ans.size() + \"\\n\");\n for (String str : ans) {\n out.println(str);\n /* char ch = str.charAt(0);\n int dig = str.charAt(1) - '1';\n if (ch == 'D') cur = cur.rotateDown(dig);\n else if (ch == 'U') cur = cur.rotateUp(dig);\n else if (ch == 'R') cur = cur.rotateRight(dig);\n else if (ch == 'L') cur = cur.rotateLeft(dig);*/\n }\n // out.print(\"res : \\n\");\n // out.print(cur);\n\n }\n class P {\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 boolean equals(Object o) {\n if (this == o) return true;\n if (!(o instanceof P)) return false;\n\n P p = (P) o;\n\n if (x != p.x) return false;\n if (y != p.y) return false;\n\n return true;\n }\n\n @Override\n public int hashCode() {\n int result = x;\n result = 31 * result + y;\n return result;\n }\n }\n\n\n\n class State {\n char s[][] ;\n\n\n State(char[][] s) {\n this.s = new char[s.length][];\n for (int i = 0; i < s.length; ++i)\n this.s[i] = s[i].clone();\n }\n\n @Override\n public boolean equals(Object o) {\n if (this == o) return true;\n\n State tmp = (State) o;\n for (int i =0 ; i < 6; ++i)\n for (int j =0 ; j < 6; ++j)\n if (this.s[i][j] != tmp.s[i][j]) return false;\n return true;\n }\n\n @Override\n public int hashCode() {\n int r = 1;\n for (int i = 0; i < 6; ++i)\n for (int j = 0; j < 6; ++j)\n r = 31 * r + (s[i][j] - '0' + 1);\n return r;\n }\n\n @Override\n public String toString() {\n String tmp = \"\";\n for (int i =0 ; i < 6; ++i) {\n tmp += Arrays.toString(this.s[i]) + \"\\n\";\n }\n return tmp;\n }\n }\n}\n", "src_uid": "10b2c1c53580dd382c41a56f7413e709"} {"source_code": "\n\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.util.Arrays;\npublic class Cards {\n\tpublic static void main(String[]args)throws IOException,NumberFormatException{\n\t\tBufferedReader bf =new BufferedReader(new InputStreamReader(System.in));\n\t\tint n=Integer.parseInt(bf.readLine());\n\t\tString s=bf.readLine();\n\t\tString[]sa=s.split(\" \");\n\t\tint[]a=new int[n];\n\t\tfor(int i=0;i<n;i++){\n\t\t\ta[i]=Integer.parseInt(sa[i]);\n\t\t}\n\t\tboolean[]v=new boolean[n];\n\t\tfor(int i=0;i<n/2;i++){\n\t\t\tint min=Integer.MAX_VALUE;\n\t\t\tint max=0;\n\t\t\tint minp=0;\n\t\t\tint maxp=0;\n\t\t\tfor(int j=0;j<n;j++){\n\t\t\t\tif(!v[j]){\n\t\t\t\t\tif(a[j]>=max){\n\t\t\t\t\t\tmax=a[j];\n\t\t\t\t\t\tmaxp=j;\n\t\t\t\t\t}\n\t\t\t\t\tif(a[j]<min){\n\t\t\t\t\t\tmin=a[j];\n\t\t\t\t\t\tminp=j;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tv[maxp]=true;\n\t\t\tv[minp]=true;\n\t\t\tSystem.out.println((minp+1)+\" \"+(maxp+1));\n\t\t}\n\t}\n}\n", "src_uid": "6e5011801ceff9d76e33e0908b695132"} {"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 <br>\n\t\t * pos1 <= pos2 = going down <br>\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[] 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\tNode root;\n\t\tint n;\n\n\t\tpublic SegTree(int n) {\n\t\t\troot = new Node(0, n);\n\t\t\tthis.n = 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\tNode.ql = ql;\n\t\t\tNode.qr = qr;\n\t\t\tNode.delta = delta;\n\t\t\troot.add(0, n);\n\t\t}\n\n\t\tpublic void addPoint(int idx, long delta) {\n\t\t\tNode.ql = idx;\n\t\t\tNode.delta = delta;\n\t\t\troot.addPoint(0, n);\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\tNode.ql = ql;\n\t\t\tNode.qr = qr;\n\t\t\treturn root.get(0, n);\n\t\t}\n\n\t\tpublic void setPoint(int idx, long val) {\n\t\t\tNode.ql = idx;\n\t\t\tNode.delta = val;\n\t\t\troot.setPoint(0, n);\n\t\t}\n\n\t\tpublic long getPoint(int idx) {\n\t\t\tNode.ql = idx;\n\t\t\treturn root.getPoint(0, n);\n\t\t}\n\n\t\tpublic int maxPos() {\n\t\t\treturn root.maxPos(0, n);\n\t\t}\n\n\t\tstatic class Node {\n\t\t\tstatic int ql, qr;\n\t\t\tstatic long delta;\n\t\t\t\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\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(int l, int r) {\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\tint m = (l + r) >> 1;\n\t\t\t\tleft.add(l, m);\n\t\t\t\tright.add(m, r);\n\t\t\t\tmax = Math.max(left.getMax(), right.getMax());\n\t\t\t}\n\n\t\t\tlong get(int l, int r) {\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\tint m = (l + r) >> 1;\n\t\t\t\treturn Math.max(left.get(l, m), right.get(m, r)) + add;\n\t\t\t}\n\n\t\t\tint maxPos(int l, int r) {\n\t\t\t\tif (r - l == 1) {\n\t\t\t\t\treturn l;\n\t\t\t\t}\n\t\t\t\tint m = (l + r) >> 1;\n\t\t\t\treturn left.getMax() > right.getMax() ? left.maxPos(l, m) : right.maxPos(m, r);\n\t\t\t}\n\n\t\t\tvoid setPoint(int l, int r) {\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\tint m = (l + r) >> 1;\n\t\t\t\tif (ql < m) {\n\t\t\t\t\tleft.setPoint(l, m);\n\t\t\t\t} else {\n\t\t\t\t\tright.setPoint(m, r);\n\t\t\t\t}\n\t\t\t\tmax = Math.max(left.getMax(), right.getMax());\n\t\t\t}\n\t\t\t\n\t\t\tvoid addPoint(int l, int r) {\n\t\t\t\tif (r - l == 1) {\n\t\t\t\t\tadd += delta;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tint m = (l + r) >> 1;\n\t\t\t\tif (ql < m) {\n\t\t\t\t\tleft.addPoint(l, m);\n\t\t\t\t} else {\n\t\t\t\t\tright.addPoint(m, r);\n\t\t\t\t}\n\t\t\t\tmax = Math.max(left.getMax(), right.getMax());\n\t\t\t}\n\t\t\t\n\t\t\tlong getPoint(int l, int r) {\n\t\t\t\tif (r - l == 1) {\n\t\t\t\t\treturn getMax();\n\t\t\t\t}\n\t\t\t\tint m = (l + r) >> 1;\n\t\t\t\treturn (ql < m ? left.getPoint(l, m) : right.getPoint(m, r)) + add;\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}", "src_uid": "2c7349bc99e56b86a5c11b8c683b2b6c"} {"source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.Random;\n\npublic class E {\n \n static boolean DEBUG=false;\n static int N=4;\n \n static class bits {\n int d,cnt;\n bits(int d, int cnt) {\n this.d=d; this.cnt=cnt;\n }\n long h(bits b) {\n if(d==b.d) {\n return Math.abs(cnt-b.cnt);\n } else {\n return (long)Math.min(cnt, b.cnt)+(long)Math.min(N-cnt, N-b.cnt);\n }\n }\n public String toString() {\n return d+\":\"+cnt;\n }\n }\n \n static long h(bits a, bits b, bits c) {\n return a.h(b)+b.h(c)+c.h(a);\n }\n \n static long maxh(bits[] in, int l, int r) {\n bits lb=in[l], rb=in[r];\n long max=-1;\n \n for (int i=0; i<in.length; i++) {\n if(i!=l&&i!=r) {\n long h=h(lb,rb,in[i]);\n if(h>max) {\n max=h;\n }\n }\n }\n \n return max;\n }\n \n static long cnt_between(bits[] in, int ll, int rr, long max) {\n int lr=ll, rl=rr;\n while (lr+1<=rr&&in[lr+1].cnt==in[ll].cnt) {\n lr++;\n }\n //at this point lr points to rightmost position s.t. in[lr].cnt==in[ll].cnt\n \n while (rl-1>=ll&&in[rl-1].cnt==in[rr].cnt) {\n rl--;\n }\n //at this point rl points to leftmost position s.t. in[rl].cnt==in[rr].cnt\n \n if(lr>=rl) {\n //all numbers [ll,rr] are the same, (rr-ll+1) take 3...\n long k=(rr-ll+1);\n return max==0? k*(k-1)*(k-2)/6: 0;\n }\n\n long ret=0;\n //here we count triples (i,j,k) where ll<=i<=lr && lr<j<rl && rl<=k<=rr\n for (int i=lr+1; i<rl; i++) {\n long v=(long)(lr-ll+1)*(long)(rr-rl+1);\n if(h(in[ll],in[rr],in[i])==max) {\n ret+=v;\n if(DEBUG) {\n System.out.println(\"added \"+v+\" for \"+i+\" in[\"+ll+\",\"+rr+\"]\");\n }\n }\n }\n\n //here we count triples (i,j,k) where ll<=i,j<=lr && rl<=k<=rr || ll<=i<=lr && rl<=j,k<=rr\n if(max==2*in[ll].h(in[rr])) {\n long l=lr-ll+1, r=rr-rl+1;\n ret+=(l*(l-1)*r + r*(r-1)*l)/2;\n }\n return ret;\n }\n \n static long cnt_pairs(int ll, int lr, int rl, int rr) {\n if(lr<rl) {\n long l=lr-ll+1, r=rr-rl+1;\n return l*r;\n } else {\n long rl_lr=lr-rl+1, ll_rl=rl-ll, lr_rr=rr-lr;\n \n return \n ll_rl*lr_rr+\n rl_lr*lr_rr+\n ll_rl*rl_lr+\n rl_lr*(rl_lr-1)/2;\n }\n }\n \n static long solve(bits[] in) {\n int n=in.length;\n Arrays.sort(in, new Comparator<bits>() {\n @Override\n public int compare(bits o1, bits o2) {\n int ret=o1.d-o2.d;\n if(ret==0) {\n ret=o1.d==1? o1.cnt-o2.cnt: o2.cnt-o1.cnt;\n }\n return ret;\n }});\n \n int max0=-1;\n for (int i=0; i<n; i++) {\n if(in[i].d==0) {\n max0=i;\n }\n }\n \n if(max0<0||max0==n-1) {\n long maxh=maxh(in,0,n-1);\n return cnt_between(in, 0, n-1, maxh);\n } else {\n long maxh=Math.max(maxh(in,0,max0), maxh(in,max0+1,n-1));\n if(DEBUG) {\n System.out.println(\"maxh: \"+maxh);\n }\n long ret=cnt_between(in, 0, max0, maxh);\n ret+=cnt_between(in, max0+1, n-1, maxh);\n \n int lo=n-2, hi=n-1;\n for (int i=0; i<=max0; i++) {\n if(h(in[max0+1],in[n-1],in[i])==maxh) {\n while(h(in[lo],in[n-1],in[i])<h(in[max0+1],in[n-1],in[i])) {\n lo--;\n }\n\n while(hi-1>max0+1&&h(in[max0+1],in[hi-1],in[i])==h(in[max0+1],in[n-1],in[i])) {\n hi--;\n }\n \n long v=cnt_pairs(max0+1, lo, hi, n-1);\n ret+=v;\n if(DEBUG) {\n System.out.println(\"added \"+v+\" for \"+i+\" out[\"+(max0+1)+\",\"+(n-1)+\"]\");\n }\n }\n }\n\n lo=0; hi=1;\n for (int i=n-1; i>=max0+1; i--) {\n if(h(in[0],in[max0],in[i])==maxh) {\n while(lo+1<max0&&h(in[lo+1],in[max0],in[i])==h(in[0],in[max0],in[i])) {\n lo++;\n }\n \n while(h(in[0],in[hi],in[i])<h(in[0],in[max0],in[i])) {\n hi++;\n }\n \n long v=cnt_pairs(0, lo, hi, max0);\n ret+=v;\n if(DEBUG) {\n System.out.println(\"added \"+v+\" for \"+i+\" out[0,\"+max0+\"]\");\n }\n }\n }\n return ret;\n }\n }\n\n \n \n \n \n static void run_stream(InputStream ins) throws IOException {\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n String[] nm=br.readLine().split(\" \");\n N=Integer.parseInt(nm[0]);\n \n bits[] in=new bits[Integer.parseInt(nm[1])];\n for (int i=0; i<in.length; i++) {\n String l=br.readLine();\n \n in[i]=new bits(\n Integer.parseInt(l.substring(0, 1)),\n Integer.parseInt(l.substring(2)));\n }\n \n System.out.println(solve(in));\n //System.out.println(baseline(in));\n }\n\n public static void main(String[] args) throws IOException {\n run_stream(System.in);\n \n //run_random();\n //run();\n }\n \n static void run_random() {\n Random r=new Random();\n\n int n=100;\n bits[] in=new bits[n];\n \n for (int j=0; j<100; j++) {\n for (int i=0; i<n; i++) {\n int d=r.nextBoolean()? 1: 0;\n in[i]=new bits(d, d==0? N: r.nextInt(N)+1);\n }\n \n run(in);\n }\n }\n\n static void run() {\n DEBUG=true;\n bits[] in=new bits[] {new bits(0,4),new bits(0,4),new bits(0,4),new bits(0,4), new bits(0,4),new bits(1,1),new bits(1,1),new bits(1,1),new bits(1,1),new bits(1,2)};\n run(in);\n }\n \n static void run(bits[] in) {\n long ret1=solve(in);\n long ret2=baseline(in);\n \n if(ret1!=ret2) {\n System.out.println(\"expected: \"+ret2+\" got \"+ret1);\n System.out.println(Arrays.deepToString(in));\n } else {\n System.out.println(\"all good\");\n }\n }\n \n static long baseline(bits[] in) {\n int n=in.length; \n long max=-1, ret=0;\n for (int i=0; i<n; i++) {\n for (int j=i+1; j<n; j++) {\n for (int k=j+1; k<n; k++) {\n if(h(in[i],in[j],in[k])>max) {\n max=h(in[i],in[j],in[k]);\n ret=1;\n if(DEBUG&&max==4) {\n System.out.println(i+\",\"+j+\",\"+k);\n }\n } else if(h(in[i],in[j],in[k])==max) {\n ret++;\n if(DEBUG&&max==4) {\n System.out.println(i+\",\"+j+\",\"+k);\n }\n }\n }\n }\n }\n \n if(DEBUG) {\n System.out.println(\"maxh: \"+max);\n }\n return ret;\n }\n}\n", "src_uid": "bfc61d3e967fc28e1ab5b9028856125b"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class Main\n{\n\tpublic static void main(String[] args) {\n\t\tnew Thread(null, new Runnable() {\n\t\t\tpublic void run() {\n solve();\n }\n }, \"1\", 1 << 26).start();\n\t}\n\tstatic void solve () {\n\t\tFastReader fr =new FastReader();\tPrintWriter op =new PrintWriter(System.out);\n \n \t\tint t =fr.nextInt() ,n ,k ,l ,m ,tx[][] ,i ,j ;\n \t\tboolean psbl[][] ,dm ;\n\n \t\twhile (t-- > 0) {\n \t\t\tn =fr.nextInt() ;\tk =fr.nextInt() ;\tl =fr.nextInt() ;\n\n \t\t\ttx =new int[2*k][n+1] ;\tpsbl =new boolean[2*k][n+1] ;\n\n \t\t\tfor (i =1 ; i<=n ; ++i)\ttx[0][i] =fr.nextInt() ;\n\n \t\t\tfor (i =1 ; i<=k ; ++i)\t{\n \t\t\t\tfor (j =1 ; j<=n ; ++j)\ttx[i][j] =tx[0][j] + i ;\n \t\t\t}\n \t\t\tfor (; i<2*k ; ++i) {\n \t\t\t\tfor (j =1 ; j<=n ; ++j)\ttx[i][j] =tx[k][j] - (i-k) ;\n \t\t\t}\n\n \t\t\tfor (i =0 ; i<2*k ; ++i) {\n \t\t\t\tif (tx[i][n] <= l)\tpsbl[i][n] =true ;\n \t\t\t}\n\n \t\t\tfor (i =n-1 ; i>0 ; --i) {\n \t\t\t\tfor (j =0 ; j<2*k ; ++j) {\n \t\t\t\t\tdm =false ;\n \t\t\t\t\tfor (m =0 ; m<2*k ; ++m) {\n \t\t\t\t\t\tif (tx[(j+m)%(2*k)][i] > l)\tbreak;\n\n \t\t\t\t\t\tdm |= psbl[(j+m+1)%(2*k)][i+1] ;\n \t\t\t\t\t}\n \t\t\t\t\tpsbl[j][i] =dm ;\n \t\t\t\t}\n \t\t\t}\n\n \t\t\tdm =false ;\n \t\t\tfor (i =0 ; i<2*k ; ++i)\tdm |= psbl[i][1] ;\n \t\t\tif (dm)\top.println(\"Yes\") ;\n \t\t\telse \top.println(\"No\") ;\n \t\t}\n\t\top.flush();\top.close();\n\t}\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\tString next() {\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\t\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tString nextLine() {\n\t\t\tString str =\"\";\n\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\n\t\t\treturn str;\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\t}\n}", "src_uid": "4941b0a365f86b2e2cf686cdf5d532f8"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class E_new {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tstatic final int P = 1_000_000_007;\n\tstatic final long P2 = (long) P * P;\n\n\tint[] oneCol(int[] dp, int h, int prevH) {\n\n\t\tfor (int j = 0; j < h; j++) {\n\t\t\tint[] next = new int[1 << h];\n\t\t\tboolean canDown = j != 0;\n\t\t\tboolean canLeft = j < prevH;\n\t\t\tfor (int was = 0; was < (1 << h); was++) {\n\t\t\t\tif (dp[was] == 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tboolean needLeft = (was & 1) == 1;\n\t\t\t\tif (needLeft && !canLeft) {\n\t\t\t\t\tthrow new AssertionError();\n\t\t\t\t}\n\t\t\t\t// down and left\n\t\t\t\tif (canDown && canLeft) {\n\t\t\t\t\tint tmp = clear(was, h - 1) >> 1;\n\t\t\t\t\tnext[tmp] += dp[was];\n\t\t\t\t\tif (next[tmp] >= P) {\n\t\t\t\t\t\tnext[tmp] -= P;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// down\n\t\t\t\tif (canDown && !needLeft) {\n\t\t\t\t\tint tmp = clear(was, h - 1) >> 1;\n\t\t\t\t\tnext[tmp] += dp[was];\n\t\t\t\t\tif (next[tmp] >= P) {\n\t\t\t\t\t\tnext[tmp] -= P;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// left\n\t\t\t\tif (canLeft) {\n\t\t\t\t\tint tmp = was >> 1;\n\t\t\t\t\tnext[tmp] += dp[was];\n\t\t\t\t\tif (next[tmp] >= P) {\n\t\t\t\t\t\tnext[tmp] -= P;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// nothing\n\t\t\t\tif (!needLeft) {\n\t\t\t\t\tint tmp = set(was >> 1, h - 1);\n\t\t\t\t\tnext[tmp] += dp[was];\n\t\t\t\t\tif (next[tmp] >= P) {\n\t\t\t\t\t\tnext[tmp] -= P;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t}\n\t\t\tdp = next;\n\t\t}\n\t\treturn dp;\n\t}\n\n\tvoid solve() throws IOException {\n\t\tint[] ws = new int[7];\n\t\tfor (int i = 0; i < 7; i++) {\n\t\t\tws[i] = nextInt();\n\t\t}\n\n\t\tint[] dp = new int[1];\n\t\tdp[0] = 1;\n\t\tint prevH = 0;\n\n\t\tfor (int h = 1; h <= 7; h++) {\n\t\t\tint w = ws[h - 1];\n\t\t\tif (w == 0) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tdp = Arrays.copyOf(dp, 1 << h);\n\t\t\tdp = oneCol(dp, h, prevH);\n\t\t\tprevH = h;\n\t\t\tint[][] m = new int[1 << h][];\n\t\t\tint[] tmp = new int[1 << h];\n\t\t\tfor (int i = 0; i < 1 << h; i++) {\n\t\t\t\ttmp[i] = 1;\n\t\t\t\tif (i > 0) {\n\t\t\t\t\ttmp[i - 1] = 0;\n\t\t\t\t}\n\t\t\t\tm[i] = oneCol(tmp, h, h);\n\t\t\t}\n//\t\t\tSystem.err.println(Arrays.toString(dp));\n//\t\t\tSystem.err.println(Arrays.deepToString(m));\n\t\t\tm = pow(m, w - 1);\n\n\t\t\tint[] next = new int[1 << h];\n\t\t\tfor (int i = 0; i < (1 << h); i++) {\n\t\t\t\tfor (int j = 0; j < (1 << h); j++) {\n\t\t\t\t\tnext[j] += (int) ((long) dp[i] * m[i][j] % P);\n\t\t\t\t\tnext[j] %= P;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdp = next;\n\n\t\t}\n\n\t\tout.println(dp[0]);\n\t}\n\n\tstatic int[][] mul(int[][] a, int[][] b) {\n\t\tint n = a.length;\n\t\tint[][] c = new int[n][n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint[] A = a[i];\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tlong tmp = 0;\n\t\t\t\tfor (int k = 0; k < n; k++) {\n\t\t\t\t\ttmp += (long) A[k] * b[k][j];\n\t\t\t\t\tif (tmp >= P2) {\n\t\t\t\t\t\ttmp -= P2;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tc[i][j] = (int) (tmp % P);\n\t\t\t}\n\t\t}\n\t\treturn c;\n\t}\n\n\tstatic int[][] pow(int[][] a, int b) {\n\t\tint[][] ret = new int[a.length][a.length];\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tret[i][i] = 1;\n\t\t}\n\t\tfor (; b > 0; b >>= 1) {\n\t\t\tif ((b & 1) == 1) {\n\t\t\t\tret = mul(ret, a);\n\t\t\t}\n\t\t\ta = mul(a, a);\n\t\t}\n\t\treturn ret;\n\t}\n\n\tint clear(int mask, int i) {\n\t\treturn mask & ~(1 << i);\n\t}\n\n\tint set(int mask, int i) {\n\t\treturn mask | (1 << i);\n\t}\n\n\tE_new() 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_new();\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}", "src_uid": "a4bda63b95dc14185c47a08652fe41bd"} {"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.util.Collections;\nimport java.util.ArrayList;\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 ArrayList<Integer> al = new ArrayList<>();\n for (int i = n; i > n - 85 && i > 0; i--) {\n if (i + digitsum(i) == n) {\n al.add(i);\n }\n }\n out.println(al.size());\n Collections.sort(al);\n for (Integer ii : al) {\n out.println(ii);\n }\n }\n\n public int digitsum(int n) {\n String[] p = Integer.toString(n).split(\"\");\n int sum = 0;\n for (String ll : p) {\n sum += Integer.parseInt(ll);\n }\n return sum;\n }\n\n }\n\n static class InputReader {\n public byte[] buf = new byte[8000];\n public int index;\n public int total;\n public 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 int nextInt() {\n int 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\n", "src_uid": "ae20ae2a16273a0d379932d6e973f878"} {"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 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 long t=in.nextLong();\n int l=in.nextInt();\n int r=in.nextInt();\n long[] ans=new long[r+1];\n Arrays.fill(ans, -1);\n long[] min=new long[r+1];\n Arrays.fill(min, -1);\n int sqr=(int)Math.sqrt(r);\n for(int i=2;i<=sqr;i++){\n if(min[i]==-1){\n min[i]=i;\n for(int j=i*i;j<=r;j+=i){\n if(min[j]==-1){\n min[j]=i;\n }\n }\n }\n }\n ans[1]=0;\n for(int i=2;i<=r;i++){\n if(min[i]==-1)\n min[i]=i;\n long x=((long)i/min[i])*(min[i]*(min[i]-1))/2;\n ans[i]=(x+ans[(int) (i/min[i])])%mod;\n }\n //for(int i=2;i<=r;i++)\n //System.out.println(ans[i]);\n long ans1=0;\n long pow=1;\n for(int i=l;i<=r;i++){\n //System.out.println(ans[i]);\n ans1=(ans1+(pow*ans[i])%mod)%mod;\n pow=(pow*t)%mod;\n }\n out.println(ans1);\n\n\t out.close();\n\t}\n\t\n\tstatic long gcd(long a, long b) {\n\t\tif (a == 0 || b == 0)\n\t\t\treturn a + b;\n\t\treturn gcd(b, a % b);\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 // 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<Integer> 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<Integer>();\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<Integer> 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 static HashMap<Long,Long> primeFactors(long n){\n HashMap<Long,Long> ans=new HashMap<Long,Long>();\n \t// Print the number of 2s that divide n\n while (n%2L==0L)\n {\n if(ans.containsKey(2L)){\n \tans.put(2L,ans.get(2L)+1L);\n }else{\n \tans.put(2L,1L);\n }\n n /= 2L;\n }\n \n // n must be odd at this point. So we can\n // skip one element (Note i = i +2)\n for (long i = 3; i <= Math.sqrt(n); i+= 2L)\n {\n // While i divides n, print i and divide n\n while (n%i == 0)\n {\n \tif(ans.containsKey(i)){\n \tans.put(i,ans.get(i)+1L);\n }else{\n \tans.put(i,1L);\n }\n n /= i;\n }\n }\n \n // This condition is to handle the case whien\n // n is a prime number greater than 2\n if (n > 2)\n ans.put(n,1L);\n return ans;\n }\n \n //for marking all prime numbers greater than 1 and less than equal to N\n static boolean[] sieveOfEratosthenes(int n) {\n\n\t\tboolean prime[] = new boolean[n];\n\t\t// Create a boolean array \"prime[0..n]\" and initialize\n\t\t// all entries it as true. A value in prime[i] will\n\t\t// finally be false if i is Not a prime, else true.\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tprime[i] = true;\n\n\t\tfor (int p = 2; p * p <= n; p++) {\n\t\t\t// If prime[p] is not changed, then it is a prime\n\t\t\tif (prime[p] == true) {\n\t\t\t\t// Update all multiples of p\n\t\t\t\tfor (int i = p * 2; i <= n; i += p)\n\t\t\t\t\tprime[i] = false;\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn prime;\n\t}\n \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 // isPrime\n\tstatic boolean isPrime(long n) {\n\t\tif(n < 2L) return false;\n\t\tif(n == 2L || n == 3L) return true;\n\t\tif(n%2L == 0 || n%3L == 0) return false;\t\n\t\tlong sqrtN = (long)Math.sqrt(n)+1L;\n\t\tfor(long i = 6L; i <= sqrtN; i += 6L) {\n\t\t\tif(n%(i-1) == 0 || n%(i+1) == 0) return false;\n\t\t}\n\t\treturn true;\n\t}\n\t\n\t// Nth fibonacci number%mod in log(n)\n\tstatic class fibonacci {\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}\n\n\t//minimum prime factor of all the numbers less than n\n static int minPrime[];\n\tstatic void minimumPrime(int n){\n\t\tminPrime=new int[n+1];\n\t\tminPrime[1]=1;\n for (int i = 2; i * i <= n; ++i) {\n if (minPrime[i] == 0) { //If i is prime\n for (int j = i * i; j <= n; j += i) {\n if (minPrime[j] == 0) {\n minPrime[j] = i;\n }\n }\n }\n }\n for (int i = 2; i <= n; ++i) {\n if (minPrime[i] == 0) {\n minPrime[i] = i;\n }\n }\n\t}\n\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}", "src_uid": "c9d45dac4a22f8f452d98d05eca2e79b"} {"source_code": "import java.util.Scanner;\n\npublic class AntonDigits {\n\n\tpublic static void main(String[] args) {\n\t\tScanner s = new Scanner(System.in);\n\t\tint val2 = s.nextInt();\n\t\tint val3 = s.nextInt();\n\t\tint val5 = s.nextInt();\n\t\tint val6 = s.nextInt();\n\t\tSystem.out.println(mAntonDigits(val2, val3, val5, val6));\n\t\ts.close();\n\n\t}\n\n\tpublic static int mAntonDigits(int n2, int n3, int n5, int n6) {\n\t\tint maxSum = 0;\n\n\t\tint l = least(n2, n5, n6);\n\t\tn2 -= l;\n\t\tn5 -= l;\n\t\tn6 -= l;\n\n\t\tmaxSum += (256 * l);\n\n\t\tl = least(n2, n3);\n\n\t\tmaxSum += (32 * l);\n\n\t\treturn maxSum;\n\t}\n\n\tpublic static int least(int n1, int n2, int n3) {\n\t\tint least = n1;\n\t\t\n\t\tif (least > n2) {\n\t\t\tleast = n2;\n\t\t}\n\t\t\n\t\tif (least > n3) {\n\t\t\tleast = n3;\n\t\t}\n\t\t\n\t\treturn least;\n\n\t}\n\n\tpublic static int least(int n1, int n2) {\n\t\tint least = n1;\n\t\tif (least > n2) {\n\t\t\treturn n2;\n\t\t}\n\t\treturn least;\n\n\t}\n\n}\n", "src_uid": "082b31cc156a7ba1e0a982f07ecc207e"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF166E_Tetrahedron {\n private void solve() {\n int n = readInt();\n long total = n % 2 == 0 ? 3 : 6;\n long factor = n % 2 == 0 ? 2 : 6;\n if(n == 0 || n == 1)\n out.print(0);\n else\n {\n n /= 2;\n n--;\n for (int i = 0; i != n; i++)\n {\n factor *= 9;\n factor %= 1000000007;\n total += factor;\n total %= 1000000007;\n }\n\n out.print(total);\n }\n\n out.close();\n }\n\n public static void main(String[] args) {\n new CF166E_Tetrahedron().run();\n }\n\n private void run() {\n try {\n init();\n solve();\n out.close();\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(-1);\n }\n }\n\n BufferedReader in;\n PrintWriter out;\n StringTokenizer tok = new StringTokenizer(\"\");\n\n private void init() throws IOException {\n String filename = \"\";\n if (filename.isEmpty()) {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n } else {\n in = new BufferedReader(new FileReader(filename + \".in\"));\n out = new PrintWriter(new FileWriter(filename + \".out\"));\n }\n }\n\n private String readString() {\n while (!tok.hasMoreTokens()) {\n try {\n tok = new StringTokenizer(in.readLine());\n } catch (Exception e) {\n return null;\n }\n }\n\n return tok.nextToken();\n }\n\n private int readInt() {\n return Integer.parseInt(readString());\n }\n\n private long readLong() {\n return Long.parseLong(readString());\n }\n\n private double readDouble() {\n return Double.parseDouble(readString());\n }\n}", "src_uid": "77627cc366a22e38da412c3231ac91a8"} {"source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.util.stream.IntStream;\nimport java.util.Arrays;\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.io.UncheckedIOException;\nimport java.math.BigDecimal;\nimport java.util.List;\nimport java.util.stream.Stream;\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 << 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 GCowAndExercise solver = new GCowAndExercise();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class GCowAndExercise {\n public void solve(int testNumber, FastInput in, FastOutput out) {\n int n = in.readInt();\n int m = in.readInt();\n int[][] edges = new int[m][3];\n for (int i = 0; i < m; i++) {\n for (int j = 0; j < 3; j++) {\n edges[i][j] = in.readInt();\n }\n }\n List<IntegerCostFlowEdge>[] g = IntegerFlow.createCostFlow(n);\n for (int[] e : edges) {\n int u = e[0] - 1;\n int v = e[1] - 1;\n int w = e[2];\n IntegerFlow.addCostEdge(g, u, v, 1, w);\n }\n\n List<LinearFunction> list = new ArrayList<>();\n IntegerAugmentCallback callback = new IntegerAugmentCallback() {\n int sumFlow = 0;\n int sumCost = 0;\n\n\n public void callback(int flow, int pathCost) {\n sumFlow += flow;\n sumCost += flow * pathCost;\n\n if (!list.isEmpty() && list.get(list.size() - 1).l == pathCost) {\n list.remove(list.size() - 1);\n }\n LinearFunction func = new LinearFunction(pathCost, sumFlow, -sumCost);\n list.add(func);\n }\n };\n IntegerDijkstraV2MinimumCostFlow mcf = new IntegerDijkstraV2MinimumCostFlow(n);\n mcf.setCallback(callback);\n mcf.apply(g, 0, n - 1, (int) 1e8);\n LinearFunction[] fs = list.toArray(new LinearFunction[0]);\n\n\n int q = in.readInt();\n Query[] qs = new Query[q];\n for (int i = 0; i < q; i++) {\n qs[i] = new Query();\n qs[i].x = in.readInt();\n }\n\n Query[] sortedQs = qs.clone();\n Arrays.sort(sortedQs, (a, b) -> Integer.compare(a.x, b.x));\n int cur = -1;\n for (Query query : sortedQs) {\n while (cur + 1 < fs.length && fs[cur + 1].getL() <= query.x) {\n cur++;\n }\n query.ans = fs[cur].getX(query.x);\n }\n\n for (Query query : qs) {\n out.println(query.ans);\n }\n }\n\n }\n\n static class Query {\n int x;\n double ans;\n\n }\n\n static interface IntegerDeque extends IntegerStack {\n int removeFirst();\n\n }\n\n static class IntegerDijkstraV2MinimumCostFlow implements IntegerMinimumCostFlow {\n private int m;\n private int[] lastDist;\n private int[] curDist;\n private IntegerCostFlowEdge[] prev;\n private boolean[] inq;\n private IntegerDeque dq;\n private static final int INF = Integer.MAX_VALUE / 4;\n private List<IntegerCostFlowEdge>[] g;\n private IntegerAugmentCallback callback = IntegerAugmentCallback.NIL;\n\n public void setCallback(IntegerAugmentCallback callback) {\n this.callback = callback;\n }\n\n public IntegerDijkstraV2MinimumCostFlow(int m) {\n this.m = m - 1;\n lastDist = new int[m];\n curDist = new int[m];\n prev = new IntegerCostFlowEdge[m];\n inq = new boolean[m];\n dq = new IntegerDequeImpl(m);\n }\n\n private void bf(int s) {\n int n = g.length;\n dq.clear();\n for (int i = 0; i < n; i++) {\n lastDist[i] = INF;\n inq[i] = false;\n }\n lastDist[s] = 0;\n inq[s] = true;\n dq.addLast(s);\n while (!dq.isEmpty()) {\n int head = dq.removeFirst();\n inq[head] = false;\n for (IntegerCostFlowEdge e : g[head]) {\n if (DigitUtils.equal(e.rev.flow, 0) || lastDist[e.to] <= lastDist[head] + e.cost) {\n continue;\n }\n lastDist[e.to] = lastDist[head] + e.cost;\n if (!inq[e.to]) {\n inq[e.to] = true;\n dq.addLast(e.to);\n }\n }\n }\n }\n\n private void dijkstra(int s) {\n int n = g.length;\n for (int i = 0; i < n; i++) {\n curDist[i] = INF;\n prev[i] = null;\n inq[i] = false;\n }\n curDist[s] = 0;\n\n for (int i = 0; i < n; i++) {\n int head = -1;\n for (int j = 0; j < n; j++) {\n if (!inq[j] && (head == -1 || curDist[j] < curDist[head])) {\n head = j;\n }\n }\n if (curDist[head] >= INF) {\n break;\n }\n inq[head] = true;\n for (IntegerCostFlowEdge e : g[head]) {\n int dist;\n if (e.rev.flow == 0 || curDist[e.to] <= (dist = curDist[head] + e.cost - lastDist[e.to] + lastDist[head])) {\n continue;\n }\n prev[e.to] = e.rev;\n curDist[e.to] = dist;\n }\n }\n\n for (int i = 0; i < n; i++) {\n lastDist[i] = Math.min(curDist[i] + lastDist[i], INF);\n }\n }\n\n public int[] apply(List<IntegerCostFlowEdge>[] net, int s, int t, int send) {\n this.g = net;\n bf(s);\n int flow = 0;\n int cost = 0;\n while (flow < send) {\n dijkstra(s);\n if (prev[t] == null) {\n break;\n }\n int remain = send - flow;\n for (IntegerCostFlowEdge trace = prev[t]; trace != null; trace = prev[trace.to]) {\n remain = Math.min(remain, trace.flow);\n }\n int sumOfCost = 0;\n for (IntegerCostFlowEdge trace = prev[t]; trace != null; trace = prev[trace.to]) {\n sumOfCost -= trace.cost;\n IntegerFlow.send(trace, -remain);\n }\n cost += sumOfCost * -remain;\n flow += remain;\n callback.callback(remain, sumOfCost);\n }\n return new int[]{flow, cost};\n }\n\n }\n\n static interface IntegerStack {\n void addLast(int x);\n\n boolean isEmpty();\n\n void clear();\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 interface IntegerMinimumCostFlow {\n }\n\n static class IntegerCostFlowEdge extends IntegerFlowEdge<IntegerCostFlowEdge> {\n public int cost;\n\n public IntegerCostFlowEdge(int to, int flow, boolean real, int cost) {\n super(to, flow, real);\n this.cost = cost;\n }\n\n }\n\n static class IntegerDequeImpl implements IntegerDeque {\n private int[] data;\n private int bpos;\n private int epos;\n private static final int[] EMPTY = new int[0];\n private int n;\n\n public IntegerDequeImpl(int cap) {\n if (cap == 0) {\n data = EMPTY;\n } else {\n data = new int[cap];\n }\n bpos = 0;\n epos = 0;\n n = cap;\n }\n\n private void expandSpace(int len) {\n while (n < len) {\n n = Math.max(n + 10, n * 2);\n }\n int[] newData = new int[n];\n if (bpos <= epos) {\n if (bpos < epos) {\n System.arraycopy(data, bpos, newData, 0, epos - bpos);\n }\n } else {\n System.arraycopy(data, bpos, newData, 0, data.length - bpos);\n System.arraycopy(data, 0, newData, data.length - bpos, epos);\n }\n epos = size();\n bpos = 0;\n data = newData;\n }\n\n public IntegerIterator iterator() {\n return new IntegerIterator() {\n int index = bpos;\n\n\n public boolean hasNext() {\n return index != epos;\n }\n\n\n public int next() {\n int ans = data[index];\n index = IntegerDequeImpl.this.next(index);\n return ans;\n }\n };\n }\n\n public int removeFirst() {\n int ans = data[bpos];\n bpos = next(bpos);\n return ans;\n }\n\n public void addLast(int x) {\n ensureMore();\n data[epos] = x;\n epos = next(epos);\n }\n\n public void clear() {\n bpos = epos = 0;\n }\n\n private int next(int x) {\n return x + 1 >= n ? 0 : x + 1;\n }\n\n private void ensureMore() {\n if (next(epos) == bpos) {\n expandSpace(n + 1);\n }\n }\n\n public int size() {\n int ans = epos - bpos;\n if (ans < 0) {\n ans += data.length;\n }\n return ans;\n }\n\n public boolean isEmpty() {\n return bpos == epos;\n }\n\n public String toString() {\n StringBuilder builder = new StringBuilder();\n for (IntegerIterator iterator = iterator(); iterator.hasNext(); ) {\n builder.append(iterator.next()).append(' ');\n }\n return builder.toString();\n }\n\n }\n\n static interface IntegerAugmentCallback {\n public static IntegerAugmentCallback NIL = (a, b) -> {\n };\n\n public void callback(int flow, int pathCost);\n\n }\n\n static class DigitUtils {\n private DigitUtils() {\n }\n\n public static boolean equal(int a, int b) {\n return a == b;\n }\n\n }\n\n static class DirectedEdge {\n public int to;\n\n public DirectedEdge(int to) {\n this.to = to;\n }\n\n public String toString() {\n return \"->\" + to;\n }\n\n }\n\n static class IntegerFlow {\n public static <T extends IntegerFlowEdge> void send(T edge, int flow) {\n edge.flow += flow;\n edge.rev.flow -= flow;\n }\n\n public static IntegerCostFlowEdge addCostEdge(List<IntegerCostFlowEdge>[] g, int s, int t, int cap, int cost) {\n IntegerCostFlowEdge real = new IntegerCostFlowEdge(t, 0, true, cost);\n IntegerCostFlowEdge virtual = new IntegerCostFlowEdge(s, cap, false, -cost);\n real.rev = virtual;\n virtual.rev = real;\n g[s].add(real);\n g[t].add(virtual);\n return real;\n }\n\n public static List<IntegerCostFlowEdge>[] createCostFlow(int n) {\n return createGraph(n);\n }\n\n private static List[] createGraph(int n) {\n return IntStream.range(0, n).mapToObj(i -> new ArrayList<>()).toArray(i -> new List[i]);\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(double c) {\n cache.append(new BigDecimal(c).toPlainString());\n return this;\n }\n\n public FastOutput println(double 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 LinearFunction {\n int l;\n long a;\n long b;\n\n public LinearFunction(int l, long a, long b) {\n this.l = l;\n this.a = a;\n this.b = b;\n }\n\n long getL() {\n return a * l + b;\n }\n\n double getX(double y) {\n return (y - b) / a;\n }\n\n }\n\n static class IntegerFlowEdge<T extends IntegerFlowEdge<T>> extends DirectedEdge {\n public int flow;\n public boolean real;\n public T rev;\n\n public IntegerFlowEdge(int to, int flow, boolean real) {\n super(to);\n this.flow = flow;\n this.real = real;\n }\n\n public String toString() {\n return rev.to + \"-[\" + flow + \"/\" + (flow + rev.flow) + \"]->\" + to;\n }\n\n }\n\n static interface IntegerIterator {\n boolean hasNext();\n\n int next();\n\n }\n}\n\n", "src_uid": "b0751071e12f729f6700586c5a8eed23"} {"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 HappyNumbers implements Runnable {\n private void solve() throws IOException {\n /*for (long l = 1; l <= 1000; ++l) {\n System.out.println(l);\n for (long a = 1; a <= 1000; ++a) {\n if (doit(a, l) != doit2(a, l))\n throw new RuntimeException(a + \" \" + l);\n }\n }*/\n long a = nextLong();\n long l = nextLong();\n System.out.println(doit(a, l));\n }\n\n /*private long doit2(long a, long l) {\n for (long b = a + 1;; ++b) {\n boolean ok = true;\n for (int i = 0; i < l; ++i)\n if (countLucky(a + i) != countLucky(b + i)) {\n ok = false;\n break;\n }\n if (ok)\n return b;\n }\n }*/\n\n private long doit(long a, long l) {\n if (l >= 10) {\n long first = a;\n long last = a + l - 1;\n return doit(first / 10, last / 10 - first / 10 + 1) * 10 + first % 10;\n } else {\n int[] cnts = new int[(int) l];\n for (int i = 0; i < l; ++i)\n cnts[i] = countLucky(a + i);\n return doitFrom(cnts, a + 1);\n }\n }\n\n private long doitFrom(int[] cnts, long min) {\n if (cnts.length == 1) {\n return doitOne(cnts[0], min);\n } else if (cnts.length == 2 && min <= 1) {\n return doitTwoSimple(cnts[0], cnts[1], min);\n }\n long res = Long.MAX_VALUE;\n for (int lastDigit = 0; lastDigit < 10; ++lastDigit) {\n int max = lastDigit + cnts.length - 1;\n int[] ncnts = new int[max / 10 + 1];\n Arrays.fill(ncnts, -1);\n boolean ok = true;\n for (int i = 0; i < cnts.length; ++i) {\n int cur = lastDigit + i;\n int need = cnts[i];\n if (cur % 10 == 4 || cur % 10 == 7)\n --need;\n if (need < 0) {\n ok = false;\n break;\n }\n if (ncnts[cur / 10] < 0 || ncnts[cur / 10] == need) {\n ncnts[cur / 10] = need;\n } else {\n ok = false;\n break;\n }\n }\n if (!ok) continue;\n long newMin = min / 10 - 3;\n while (newMin * 10 + lastDigit < min)\n ++newMin;\n long tmp = doitFrom(ncnts, newMin) * 10 + lastDigit;\n res = Math.min(res, tmp);\n }\n return res;\n }\n\n private long doitTwoSimple(int cntFirst, int cntSecond, long min) {\n if (cntFirst == 0 && cntSecond == 0)\n return min;\n if (cntFirst == cntSecond) {\n long res = 0;\n for (int i = 0; i < cntFirst; ++i)\n res = res * 10 + 4;\n return res * 10;\n } else if (cntFirst == cntSecond + 1) {\n long res = 0;\n for (int i = 0; i < cntFirst; ++i)\n res = res * 10 + 4;\n return res;\n } else if (cntFirst + 1 == cntSecond) {\n long res = 0;\n for (int i = 0; i < cntSecond; ++i)\n res = res * 10 + 4;\n return res - 1;\n } else {\n return Long.MAX_VALUE;\n }\n }\n\n private long doitOne(int cnt, long min) {\n long p10 = 1;\n int pow = 0;\n while (p10 <= min) {\n p10 *= 10;\n ++pow;\n }\n p10 *= 100;\n pow += 2;\n while (pow < cnt + 2) {\n p10 *= 10;\n ++pow;\n }\n long res = 0;\n while (true) {\n for (int curDigit = 0; curDigit < 10; ++curDigit) {\n int curCnt = 0;\n if (curDigit == 4 || curDigit == 7) curCnt = 1;\n if (possible(res, p10, pow, cnt - curCnt, min)) {\n cnt -= curCnt;\n break;\n }\n res += p10;\n if (curDigit == 9)\n throw new RuntimeException();\n }\n if (p10 == 1) break;\n p10 /= 10;\n --pow;\n }\n return res;\n }\n\n private boolean possible(long res, long p10, int pow, int needLucky, long min) {\n if (needLucky > pow || needLucky < 0)\n return false;\n long cur = 0;\n for (int i = 0; i < pow - needLucky; ++i)\n cur = cur * 10 + 9;\n for (int i = 0; i < needLucky; ++i)\n cur = cur * 10 + 7;\n return res + cur >= min;\n }\n\n private int countLucky(long x) {\n int res = 0;\n while (x > 0) {\n long dig = x % 10;\n x /= 10;\n if (dig == 4 || dig == 7) ++res;\n }\n return res;\n }\n\n public static void main(String[] args) {\n new HappyNumbers().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}\n", "src_uid": "649e9f477b97c1f72b05d409b4a99d59"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class C {\n\n\tstatic final int P = 1_000_000_007;\n\n\tstatic boolean nextPermutation(int[] a) {\n\t\tint n = a.length;\n\t\tint ptr = n - 1;\n\t\twhile (ptr > 0 && a[ptr - 1] >= a[ptr]) {\n\t\t\tptr--;\n\t\t}\n\n\t\tfor (int i = ptr, j = n - 1; i < j; i++, j--) {\n\t\t\tint tmp = a[i];\n\t\t\ta[i] = a[j];\n\t\t\ta[j] = tmp;\n\t\t}\n\n\t\tif (ptr == 0) {\n\t\t\treturn false;\n\t\t}\n\n\t\tfor (int i = ptr;; i++) {\n\t\t\tif (a[ptr - 1] < a[i]) {\n\t\t\t\tint tmp = a[ptr - 1];\n\t\t\t\ta[ptr - 1] = a[i];\n\t\t\t\ta[i] = tmp;\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\n\tint slow(int n, int k) {\n\t\tint[] p = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tp[i] = i;\n\t\t}\n\t\tint ans = 0;\n\t\tdo {\n\t\t\tint m = 0;\n\t\t\tint offset = 0;\n\t\t\tfor (int i = 0; i < n; ++i)\n\t\t\t\tif (m < p[i]) {\n\t\t\t\t\tm = p[i];\n\t\t\t\t\toffset = 0;\n\t\t\t\t} else {\n\t\t\t\t\toffset = offset + 1;\n\t\t\t\t\tif (offset == k)\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\tans += m == n - 1 ? 1 : 0;\n\t\t} while (nextPermutation(p));\n\t\treturn ans;\n\t}\n\n\tvoid submit() {\n\t\tint n = nextInt();\n\t\tint k = nextInt();\n\t\tint[] a = new int[n + 1];\n\t\ta[0] = 1;\n\t\tfor (int i = 1; i <= k && i <= n; i++) {\n\t\t\ta[i] = (int) ((long) (i + 1) * a[i - 1] % P);\n\t\t}\n\n\t\tif (n <= k) {\n\t\t\tout.println(0);\n\t\t\treturn;\n\t\t}\n\n\t\tint mult = a[k - 1];\n\n\t\tfor (int i = k + 1; i <= n; i++) {\n\t\t\ta[i] = (int) ((long) (i + 1) * a[i - 1] % P);\n\t\t\ta[i] -= (int) ((long) mult * a[i - k - 1] % P);\n\t\t\tif (a[i] < 0) {\n\t\t\t\ta[i] += P;\n\t\t\t}\n\n\t\t\tmult = (int) ((long) mult * i % P * inv(i - k) % P);\n\t\t}\n\n\t\tint fact = 1;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tfact = (int) ((long) fact * i % P);\n\t\t}\n\t\t\n\t\tn--;\n\n\t\tfact -= a[n];\n\t\tif (fact < 0) {\n\t\t\tfact += P;\n\t\t}\n\n\t\tout.println(fact);\n\t}\n\n\tint inv(int x) {\n\t\treturn x == 1 ? 1 : (P - (int) ((long) (P / x) * inv(P % x) % P));\n\t}\n\n\tvoid preCalc() {\n\n\t}\n\n\tvoid stress() {\n\n\t}\n\n\tvoid test() {\n\t\tint[] a = new int[11];\n\t\ta[0] = 1;\n\t\ta[1] = 2;\n\t\ta[2] = 6;\n\t\tfor (int i = 3; i < a.length; i++) {\n\t\t\ta[i] = (i + 1) * a[i - 1] - (i - 1) * (i - 2) * a[i - 3];\n\t\t}\n\t\tSystem.err.println(Arrays.toString(a));\n\n\t\ta[0] = 1;\n\t\ta[1] = 2;\n\t\ta[2] = 6;\n\t\ta[3] = 24;\n\t\tfor (int i = 4; i < a.length; i++) {\n\t\t\ta[i] = (i + 1) * a[i - 1] - (i - 1) * (i - 2) * (i - 3) * a[i - 4];\n\t\t}\n\t\tSystem.err.println(Arrays.toString(a));\n\n\t\tfor (int n = 1; n <= 11; n++) {\n\t\t\tSystem.err.println(slow(n, 2) + \" \" + a[n]);\n\t\t}\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\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 C();\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", "src_uid": "0644605611a2cd10ab3a9f12f18d7ae4"} {"source_code": "import java.util.*;\n\n/**\n *\n * @author greggy\n */\npublic class IQTest176 {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n char[][] grid = new char[4][4];\n boolean ans = false;\n\n for (int i = 0; i < 4; i++) {\n String color = in.nextLine();\n grid[i] = color.toCharArray();\n }\n\n for (int i = 1; i < 4; i++) {\n for (int j = 1; j < 4; j++) {\n if ((grid[i - 1][j - 1] == grid[i - 1][j] && grid[i - 1][j - 1] == grid[i][j - 1]) || (grid[i][j] == grid[i - 1][j - 1] && grid[i - 1][j - 1] == grid[i][j - 1]) || (grid[i][j] == grid[i - 1][j] && grid[i - 1][j] == grid[i][j - 1])) {\n ans = true;\n break;\n }\n }\n }\n if (ans == true) {\n System.out.println(\"YES\");\n } else {\n System.out.println(\"NO\");\n }\n\n }\n\n}", "src_uid": "01b145e798bbdf0ca2ecc383676d79f3"} {"source_code": "\timport java.io.*;\nimport java.util.*;\n \n\t \n\t \n\tpublic class CODEFORCES {\n\t\tprivate InputStream is;\n\t\tprivate PrintWriter out;\n\t\tint time = 0, val[][], dp[][], DP[], start[], end[], dist[], black[], MOD = (int)(1e9+7), arr[], weight[][], x[], y[], parent[];\n\t\tint MAX = 800000, N, K;\n\t\tlong red[];\n\t\tArrayList<Integer>[] amp;\n\t\t//boolean b[], boo[][];\n\t\tPair prr[];\n\t\tHashSet<Integer> hs = new HashSet<>();\n\t\tlong Dp[][][][] = new long[110][110][12][12];\n\t\tvoid soln() {\n\t\t\tis = System.in;\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tlong s = System.currentTimeMillis();\n\t\t\tsolve();\n\t\t\t//out.close();\n\t\t\tout.flush();\n\t\t\t//tr(System.currentTimeMillis() - s + \"ms\");\n\t\t}\n\t\tpublic static void main(String[] args) throws Exception {\n\t\t\tnew Thread(null, new Runnable() {\n\t\t\tpublic void run() {\n\t\t\t\ttry {\n\t \n\t\t\t//new CODEFORCES().soln();\n\t\t\t} catch (Exception e) {\n\t\t\t\t\tSystem.out.println(e);\n\t\t\t\t}\n\t\t\t}\n\t\t}, \"1\", 1 << 26).start();\n\t\t\tnew CODEFORCES().soln();\n\t\t}\n\t\tint a,b;\n\t\tvoid solve() {\n\t\t\tint n=ni(),k=ni(),i,c=0;\n\t\t\tfor(i=1;i<=n;i++){\n\t\t\t\tint x=ni()+c;\n\t\t\t\tk-=Math.min(x, 8);\n\t\t\t\tc=x-Math.min(x, 8);\n\t\t\t\tif(k<=0)\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif(i<=n)\n\t\t\t\tSystem.out.println(i);\n\t\t\telse\n\t\t\t\tSystem.out.println(-1);\n\t\t}\t\n\t\tboolean check(int ans){\n\t\t\twhile(ans>0){\n\t\t\t\tint c = ans%10;\n\t\t\t\tif(!(c==a||c==b)) return false; \n\t\t\t\tans/=10;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t\tlong npr(long[] power, int n,int r){\n\t\t\tif(r>n) return 0;\n\t\t\treturn (((power[n]*power(power[r], MOD-2, MOD))%MOD)*power(power[n-r], MOD-2, MOD))%MOD;\n\t\t}\n\t\t\n\t\tclass Pair implements Comparable<Pair>{\n\t\t\tint u, v, i;\n\t\t\tPair(int u, int v){\n\t\t\t\tthis.u = u;\n\t\t\t\tthis.v = v;\n\t\t\t}\n\t\t\tPair(int u, int v, int i){\n\t\t\t\tthis.u = u;\n\t\t\t\tthis.v = v;\n\t\t\t\tthis.i = i;\n\t\t\t}\n\t\t\tpublic int hashCode() {\n\t\t\t\treturn Objects.hash();\n\t\t\t}\n\t\t\t/*public boolean equals(Object o) {\n\t\t\t\tPair other = (Pair) o;\n\t\t\t\treturn ((u == other.u && v == other.v) || (v == other.u && u == other.v));\n\t\t\t}*/\n\t\t\tpublic int compareTo(Pair other) {\n\t\t\t\t//return Integer.compare(val, other.val);\n\t\t\t\treturn Long.compare(u, other.u) != 0 ? (Long.compare(u, other.u)) : (Long.compare(v,other.v));\n\t\t\t}\n\t\t\tpublic String toString(){\n\t\t\t\treturn this.u +\" \" + this.v;\n\t\t\t}\n\t\t}\n\t\tint max(int a, int b){\n\t\t\tif(a>b) return a;\n\t\t\treturn b;\n\t\t}\n\t\t\n\t\tvoid buildGraph(int n){\n\t\t\tfor(int i = 0; i<n ;i++){\n\t\t\t\tint x1 = ni() -1, y1 = ni()-1;\n\t\t\t\tamp[x1].add(y1);\n\t\t\t\tamp[y1].add(x1);\n\t\t\t\tx[i] = x1; y[i] = y1;\n\t\t\t}\n\t\t}\n\t\tlong modInverse(long a, long mOD2){\n\t return power(a, mOD2-2, mOD2);\n\t\t}\n\t\tlong power(long x, long y, long m)\n\t\t{\n\t\t\tif (y == 0)\n\t return 1;\n\t\tlong p = power(x, y/2, m) % m;\n\t\tp = (p * p) % m;\n\t \n\t\treturn (y%2 == 0)? p : (x * p) % m;\n\t\t}\n\t\tpublic long gcd(long a, long b){\n\t\t\tif(b==0) return a;\n\t\t\treturn gcd(b,a%b);\n\t\t}\n\t\tstatic class ST1{\n\t\t\tint arr[], st[], size;\n\t\t\tST1(int a[]){\n\t\t\t\tarr = a.clone();\n\t\t\t\tsize = 10*arr.length;\n\t\t\t\tst = new int[size];\n\t\t\t\tbuild(0,arr.length-1,1);\n\t\t\t}\n\t\t\tvoid build(int ss, int se, int si){\n\t\t\t\tif(ss==se){\n\t\t\t\t\tst[si] = arr[ss];\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tint mid = (ss+se)/2;\n\t\t\t\tint val = 2*si;\n\t\t\t\tbuild(ss,mid,val); build(mid+1,se,val+1);\n\t\t\t\tst[si] = Math.min(st[val], st[val+1]);\n\t\t\t}\n\t\t\tint get(int ss, int se, int l, int r, int si){\n\t\t\t\tif(l>se || r<ss || l>r) return Integer.MAX_VALUE;\n\t\t\t\tif(l<=ss && r>=se) return st[si];\n\t\t\t\tint mid = (ss+se)/2;\n\t\t\t\tint val = 2*si;\n\t\t\t\treturn Math.min(get(ss,mid,l,r,val), get(mid+1,se,l,r,val+1));\n\t\t\t}\n\t\t}\n\t\tstatic class ST{\n\t\t\tint arr[],lazy[],n;\n\t\t\tST(int a){\n\t\t\t\tn = a;\n\t\t\t\tarr = new int[10*n];\n\t\t\t\tlazy = new int[10*n];\n\t\t\t}\n\t\t\tvoid up(int l,int r,int val){\n\t\t\t\tupdate(0,n-1,0,l,r,val);\n\t\t\t}\n\t\t\tvoid update(int l,int r,int c,int x,int y,int val){\n\t\t\t\tif(lazy[c]!=0){\n\t\t\t\t\tlazy[2*c+1]+=lazy[c];\n\t\t\t\t\tlazy[2*c+2]+=lazy[c];\n\t\t\t\t\tif(l==r)\n\t\t\t\t\t\tarr[c]+=lazy[c];\n\t\t\t\t\tlazy[c] = 0;\n\t\t\t\t}\n\t\t\t\tif(l>r||x>y||l>y||x>r)\n\t\t\t\t\treturn;\n\t\t\t\tif(x<=l&&y>=r){\n\t\t\t\t\tlazy[c]+=val;\n\t\t\t\t\treturn ;\n\t\t\t\t}\n\t\t\t\tint mid = l+r>>1;\n\t\t\t\tupdate(l,mid,2*c+1,x,y,val);\n\t\t\t\tupdate(mid+1,r,2*c+2,x,y,val);\n\t\t\t\tarr[c] = Math.max(arr[2*c+1], arr[2*c+2]);\n\t\t\t}\n\t\t\tint an(int ind){\n\t\t\t\treturn ans(0,n-1,0,ind);\n\t\t\t}\n\t\t\tint ans(int l,int r,int c,int ind){\n\t\t\t\tif(lazy[c]!=0){\n\t\t\t\t\tlazy[2*c+1]+=lazy[c];\n\t\t\t\t\tlazy[2*c+2]+=lazy[c];\n\t\t\t\t\tif(l==r)\n\t\t\t\t\t\tarr[c]+=lazy[c];\n\t\t\t\t\tlazy[c] = 0;\n\t\t\t\t}\n\t\t\t\tif(l==r)\n\t\t\t\t\treturn arr[c];\n\t\t\t\tint mid = l+r>>1;\n\t\t\t\tif(mid>=ind)\n\t\t\t\t\treturn ans(l,mid,2*c+1,ind);\n\t\t\t\treturn ans(mid+1,r,2*c+2,ind);\n\t\t\t}\n\t\t}\n\t\tpublic static int[] shuffle(int[] a, Random gen){\n\t\t\tfor(int i = 0, n = a.length;i < n;i++)\n\t\t\t{ \n\t\t\t\tint ind = gen.nextInt(n-i)+i; \n\t\t\t\tint d = a[i]; \n\t\t\t\ta[i] = a[ind];\n\t\t\t\ta[ind] = d; \n\t\t\t} \n\t\treturn a; \n\t\t}\n\t\tlong power(long x, long y, int mod){\n\t\t\tlong ans = 1;\n\t\t\twhile(y>0){\n\t\t\t\tif(y%2==0){\n\t\t\t\t\tx = (x*x)%mod;\n\t\t\t\t\ty/=2;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tans = (x*ans)%mod;\n\t\t\t\t\ty--;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn ans;\n\t\t}\n\t \n\t \n\t\t// To Get Input\n\t\t// Some Buffer Methods\n\t\tprivate 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\t\t;\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\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\t\t\t\t\t\t\t// ')\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\t\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t \n\t\tprivate void tr(Object... o) {\n\t\t\tif (!oj)\n\t\t\t\tSystem.out.println(Arrays.deepToString(o));\n\t\t}\n\t} ", "src_uid": "24695b6a2aa573e90f0fe661b0c0bd3a"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n public static void main(String args[]) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader inputReader = new InputReader(inputStream);\n PrintWriter printWriter = new PrintWriter(outputStream);\n TaskSolver solver = new TaskSolver(inputReader, printWriter);\n solver.solve();\n printWriter.close();\n }\n}\n\nclass TaskSolver {\n private InputReader in;\n private PrintWriter out;\n\n public TaskSolver(InputReader inputReader, PrintWriter printWriter) {\n in = inputReader;\n out = printWriter;\n }\n\n public void solve() {\n int a = in.nextInt();\n int b = in.nextInt();\n int m = in.nextInt();\n int r0 = in.nextInt();\n int[] r = new int[ (int) 1e+6];\n int[] check = new int[ (int) 1e+6];\n Arrays.fill(check, -1);\n r[0] = (a * r0 + b) % m;\n check[r[0]] = 0;\n int res = 0;\n for (int i = 1; ; i++) {\n r[i] = (a * r[i - 1] + b) % m;\n if (check[r[i]] == -1) {\n check[r[i]] = i;\n } else {\n res = i - check[r[i]];\n break;\n }\n }\n out.print(res);\n }\n}\n\nclass InputReader {\n private BufferedReader reader;\n private StringTokenizer tokenizer;\n\n public InputReader(InputStream inputStream) {\n reader = new BufferedReader(new InputStreamReader(inputStream));\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (Exception e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n}\n", "src_uid": "9137197ee1b781cd5cc77c46f50b9012"} {"source_code": "\nimport java.util.ArrayList;\nimport java.util.HashSet;\nimport java.util.Scanner;\n\npublic class Round139_B {\n\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\n\t\tint s = in.nextInt();\n\t\tint k = in.nextInt();\n\t\tint MAX = 50;\n\t\tlong[] a = new long[MAX];\n\t\tint maxl = Math.min(MAX, k);\n\t\ta[0] = 1;\n\t\tlong sum = 1;\n\t\tboolean done = true;\n\t\tint lasto = 0;\n\t\tfor (int i = 1; i < maxl; i++) {\n\t\t\ta[i] = sum;\n\t\t\tsum += sum;\n\t\t\tif (done && a[i] < 1000000100)\n\t\t\t\tlasto = i;\n\t\t\telse\n\t\t\t\tdone = false;\n\t\t}\n\n\t\tfor (int i = maxl; i < MAX; i++) {\n\t\t\ta[i] = 2 * a[i - 1] - (((i - (k + 1)) > -1) ? a[i - (k + 1)] : 0);\n\t\t\tif (done && a[i] < 1000000100)\n\t\t\t\tlasto = i;\n\t\t\telse\n\t\t\t\tdone = false;\n\t\t}\n\n\t\tStringBuffer ans = new StringBuffer(\"\");\n\t\tint tmp = s;\n\t\tint count = lasto;\n\t\tArrayList<Long> fin = null;\n\t\t\n\t\twhile (count > -1) {\n\t\t\tfin = new ArrayList<Long>();\n\t\t\tHashSet<Integer> hash = new HashSet<Integer>();\n\t\t\ttmp = s;\n\t\t\tfor (int j = count; j > -1; j--) {\n\t\t\t\tif (a[j] <= tmp) {\n\t\t\t\t\t\n\t\t\t\t\tif (hash.contains((int) a[j]))\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\ttmp -= a[j];\n\t\t\t\t\tfin.add(a[j]);\n\t\t\t\t\thash.add((int) a[j]);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (tmp == 0)\n\t\t\t\tbreak;\n\t\t\tcount--;\n\t\t}\n\t\tif (fin.size() == 1)\n\t\t\tfin.add((long)0);\n\t\tint m = fin.size();\n\t\tSystem.out.println(m);\n\t\tif (m != 0)\n\t\t\tans.append(fin.get(0));\n\t\tfor (int i = 1; i < m; i++)\n\t\t\tans.append(\" \" + fin.get(i));\n\t\tSystem.out.println(ans.toString());\n\t}\n}\n", "src_uid": "da793333b977ed179fdba900aa604b52"} {"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.*;\n \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<Integer> primes;\n static long factorial[],invFactorial[];\n static ArrayList<Pair> graph[];\n static boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\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 public static void main(String[] args) throws Exception{\n String st[]=nl();\n int n=pi(st[0]);\n long k=pl(st[1]);\n fact(100000);\n long ans=0;\n for(int i=0;i<=n;i++){\n for(int j=0;j<=n;j++){\n long sgn=1;\n if((i+j)%2==1){\n sgn=-1;\n }\n long yy=(ncr(n,i)*ncr(n,j))%mod;\n long aa=(modulo(k,n*n-n*(i+j)+i*j,mod)*modulo(k-1,n*(i+j)-i*j,mod))%mod;\n yy=(yy*aa)%mod;\n yy=yy*sgn;\n ans+=yy;\n ans%=mod;\n ans+=mod;\n ans%=mod;\n }\n }\n out.println(ans);\n/****************************************Solutions Ends**************************************************/\n out.flush();\n out.close();\n }\n/****************************************Template Begins************************************************/\n static String[] nl() throws Exception{\n return br.readLine().split(\" \");\n }\n static String[] nls() throws Exception{\n return br.readLine().split(\"\");\n }\n static int pi(String str) {\n return Integer.parseInt(str);\n }\n static long pl(String str){\n return Long.parseLong(str);\n }\n static double pd(String str){\n return Double.parseDouble(str);\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 if(mask%2==1){\n ans++;\n }\n mask/=2;\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;i++){\n graph[i]=new ArrayList<>();\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 PairComp implements Comparator<Pair>{\n public int compare(Pair p1,Pair p2){\n if(p1.u!=p2.u)\n return p1.u-p2.u;\n else\n return p1.v-p2.v;\n }\n }\n static class Pair implements Comparable<Pair> {\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 PairCompL implements Comparator<Pairl>{\n public int compare(Pairl p1,Pairl p2){\n long a=p1.u*p2.v;\n long b=p2.u*p1.v;\n if(a>b){\n return -1;\n }\n else if(a<b){\n return 1;\n }\n else{\n return 0;\n }\n }\n }\n static class Pairl implements Comparable<Pairl> {\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 \n public int hashCode() {\n int hu = (int) (u ^ (u >>> 32));\n int hv = (int) (v ^ (v >>> 32));\n return 31 * hu + hv;\n }\n \n public boolean equals(Object o) {\n Pairl other = (Pairl) o;\n return u == other.u && v == other.v;\n }\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 \n public String toString() {\n return \"[u=\" + u + \", v=\" + v + \"]\";\n }\n }\n/*****************************************DEBUG***********************************************************/\n public static void debug(Object... o) {\n if(!oj)\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 {\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 {\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;i++){\n if(sieve[i]){\n for(int j=i*i;j<n;j+=i){\n sieve[j]=false;\n }\n }\n }\n primes=new ArrayList<Integer>();\n for(int i=0;i<n;i++){\n if(sieve[i]){\n primes.add(i);\n }\n } \n }\n/********************************************End***********************************************************/\n}\n", "src_uid": "f67173c973c6f83e88bc0ddb0b9bfa93"} {"source_code": "import java.util.Scanner;\n\npublic class Suits {\n\n\tpublic static void main(String[] args) {\n\t\tScanner scan= new Scanner(System.in);\n\t\tint a =scan.nextInt();\n\t\tint b=scan.nextInt();\n\t\tint c=scan.nextInt();\n\t\tint d=scan.nextInt();\n\t\tint e=scan.nextInt();\n\t\tint f=scan.nextInt();\n\t\tif(f>e)\n\t\t{\n\t\t\tint n=Math.min(b,c);\n\t\t\tint m=Math.min(n, d);\n\t\t\td=d-m;\n\t\t\td=Math.min(d, a);\n\t\t\tSystem.out.println(m*f+d*e);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tint n=Math.min(a, d);\n\t\t\tint m=Math.min(b, c);\n\t\t\td=d-n;\n\t\t\td=Math.min(d,m);\n\t\t\tSystem.out.println(n*e+d*f);\n\t\t\t\n\t\t}\n\n\t}\n\n}\n", "src_uid": "84d9e7e9c9541d997e6573edb421ae0a"} {"source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\nimport static java.lang.Math.*;\n\npublic class D implements Runnable {\n\t\n\tstatic class BitSet {\n\t\tstatic final int MOD = 63;\n\t\tlong [] a;\n\n\t\tBitSet(int n) {\n\t\t\ta = new long[(n >> 6) + 1];\n\t\t}\n\n\t\tBitSet(long [] a) {\n\t\t\tthis.a = a;\n\t\t}\n\n\t\tvoid set(int bit) {\n\t\t\tint i = bit >> 6;\n\t\t\ta[i] |= 1L << (bit & MOD);\t\n\t\t}\n\n\t\tboolean isSet(int bit) {\n\t\t\treturn (a[bit >> 6] & (1L << (bit & MOD))) != 0;\n\t\t}\n\n\t\tboolean isEmpty() {\n\t\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\t\tif (a[i] != 0) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\t\n\t\t\treturn true;\n\t\t}\n\n\t\tint size() {\n\t\t\tint ret = 0;\n\t\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\t\tret += Long.bitCount(a[i]);\n\t\t\t}\n\t\t\treturn ret;\n\t\t}\n\n\t\tpublic BitSet clone() {\n\t\t\tlong [] na = new long[a.length];\n\t\t\tSystem.arraycopy(a, 0, na, 0, a.length);\n\t\t\treturn new BitSet(na);\n\t\t}\n\n\t\t\n\t\tstatic long [] tmp = new long[3];\n\n\t\tvoid shiftLeft(long [] a) {\n\t\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\t\ttmp[i] = a[i] >>> 1;\n\t\t\t\tif (i < a.length - 1) {\n\t\t\t\t\ttmp[i] |= (a[i + 1] & 1) << 63;\n\t\t\t\t}\n\t\t\t}\t\t\t\n\t\t}\n\n\t\tvoid shiftRight(long [] a) {\n\t\t\ttmp[0] = tmp[1] = tmp[2] = 0;\n\t\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\t\ttmp[i] |= a[i] << 1;\n\t\t\t\tif (i < a.length - 1) {\n\t\t\t\t\ttmp[i + 1] |= (a[i] & (1L << MOD)) >>> MOD;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tvoid moveRight(long [] row, long [] notL) {\n\t\t\tshiftRight(a);\n\t\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\t\ta[i] = (tmp[i] & row[i]) | (a[i] & notL[i]);\n\t\t\t}\t\t\t\t\t\t\t\t\t\t\t\n\t\t}\n\n\t\tvoid moveLeft(long [] row, long [] notR) {\n\t\t\tshiftLeft(a);\n\t\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\t\ta[i] = (tmp[i] & row[i]) | (a[i] & notR[i]);\n\t\t\t}\n\t\t}\n\n\t\tvoid moveUp(long [] row, long [] weLow, long [] notUp) {\n\t\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\t\ta[i] = (row[i] & weLow[i]) | (a[i] & notUp[i]);\n\t\t\t}\t\n\t\t}\n\n\t\tvoid moveDown(long [] row, long [] weUp, long [] notLow) {\n\t\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\t\ta[i] = (row[i] & weUp[i]) | (a[i] & notLow[i]);\n\t\t\t}\n\t\t}\n\t}\n\n\tint exitX, exitY;\n\n\tvoid solve() throws Exception {\n\t\tint n = nextInt(), m = nextInt(), k = nextInt();\n\t\tBitSet [][] row = new BitSet[2][n];\n\t\tBitSet [][] rowL = new BitSet[2][n];\n\t\tBitSet [][] rowR = new BitSet[2][n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int q = 0; q < 2; q++) {\n\t\t\t\trow[q][i] = new BitSet(m);\n\t\t\t\trowL[q][i] = new BitSet(m);\n\t\t\t\trowR[q][i] = new BitSet(m);\n\t\t\t}\n\t\t\tchar [] b = nextToken().toCharArray();\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\tint q = b[j] == '#' ? 1 : 0;\n\t\t\t\trow[q][i].set(j);\n\t\t\t\tif (j < m - 1) rowR[q][i].set(j + 1);\n\t\t\t\tif (j > 0) rowL[q][i].set(j - 1);\n\t\t\t\tif (b[j] == 'E') {\n\t\t\t\t\texitX = j;\n\t\t\t\t\texitY = i;\t\n\t\t\t\t}\n\t\t\t} \t\t\n\t\t}\n\n\t\tBitSet [] we = new BitSet[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\twe[i] = (BitSet)row[0][i].clone();\n\t\t}\n\t\t\n\t\tchar [] seq = nextToken().toCharArray();\n\t\tfor (int step = 0; step <= seq.length; step++) {\n\t\t\tboolean done = true;\n\t\t\tfor (int i = 0; i < n; i++) {\n \t\t\t\tif (i != exitY) {\n \t\t\t\t\tif (!we[i].isEmpty()) {\n \t\t\t\t\t\tdone = false;\n \t\t\t\t\t\tbreak;\n \t\t\t\t\t}\n \t\t\t\t} else {\n \t\t\t\t\tif (!we[i].isSet(exitX) || !(we[i].size() == 1)) {\n \t\t\t\t\t\tdone = false;\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\tif (done) {\n\t\t\t\tout.println(step);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (step == seq.length) {\n\t\t\t\tout.println(-1);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tchar c = seq[step];\n \t\t\tif (c == 'R') {\n \t\t\t\tfor (int i = 0; i < n; i++) {\n \t\t\t\t\twe[i].moveRight(row[0][i].a, rowL[1][i].a);\n \t\t\t\t}\n \t\t\t}\n \t\t\tif (c == 'L') {\n \t\t\t\tfor (int i = 0; i < n; i++) {\n \t\t\t\t\twe[i].moveLeft(row[0][i].a, rowR[1][i].a);\n \t\t\t\t}\n \t\t\t}\n \t\t\tif (c == 'U') {\n \t\t\t\tfor (int i = 1; i < n - 1; i++) {\n \t\t\t\t\twe[i].moveUp(row[0][i].a, we[i + 1].a, row[1][i - 1].a);\n \t\t\t\t}\n \t\t\t}\n \t\t\tif (c == 'D') {\n \t\t\t\tfor (int i = n - 2; i > 0; i--) {\n \t\t\t\t\twe[i].moveDown(row[0][i].a, we[i - 1].a, row[1][i + 1].a);\n \t\t\t\t}\n \t\t\t}\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew Thread(new D()).start();\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tLocale.setDefault(Locale.US);\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsTime();\n\t\t\tsolve();\n\t\t\tdebug(\"Time consumed: \" + gTime());\n\n\t\t\tout.close();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n\n\t\n\tStringTokenizer tokenizer = new StringTokenizer(\"\");\n\tBufferedReader in;\n\tPrintWriter out;\n\tlong time;\n\n\tvoid sTime() {\n\t\ttime = System.currentTimeMillis();\n\t}\n\n\tlong gTime() {\n\t\treturn System.currentTimeMillis() - time;\n\t}\n\n\tvoid gMemory() {\n\t\tdebug(\"Memory: \" + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1000 + \" kb\");\n\t}\n\n\tpublic void debug(Object o) {\n\t\tSystem.err.println(o);\n\t}\n\t\n\tboolean seekForToken() {\n\t\twhile (!tokenizer.hasMoreTokens()) {\n\t\t\tString s = null;\n\t\t\ttry {\n\t\t\t\ts = in.readLine();\n\t\t\t} catch (Exception e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\tif (s == null)\n\t\t\t\treturn false;\n\t\t\ttokenizer = new StringTokenizer(s);\n\t\t}\n\t\treturn true;\n\t}\n\n\tString nextToken() {\n\t\treturn seekForToken() ? tokenizer.nextToken() : null;\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\tBigInteger nextBig() {\n\t\treturn new BigInteger(nextToken());\n\t}\n}\n", "src_uid": "70ab617d9b8813ddf3039c6fb137d817"} {"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.ArrayList;\nimport java.util.List;\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 */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastScanner in = new FastScanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskD solver = new TaskD();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n\n\tstatic class TaskD {\n\t\tfinal int MOD = (int) (1e9 + 7);\n\n\t\tpublic void solve(int testNumber, FastScanner in, PrintWriter out) {\n\t\t\tlong n = in.nextLong();\n\t\t\tint k = in.nextInt();\n\t\t\tlong ans = 1;\n\t\t\tint[] inv = new int[100];\n\t\t\tfor (int i = 1; i < inv.length; i++) {\n\t\t\t\tinv[i] = BigInteger.valueOf(i).modInverse(BigInteger.valueOf(MOD)).intValue();\n\t\t\t}\n\t\t\tfor (Factor f : factorize(n)) {\n\t\t\t\tlong p = f.p;\n\t\t\t\tint s = f.s;\n\t\t\t\tint[] d = new int[s + 1];\n\t\t\t\tint[] nd = new int[s + 1];\n\t\t\t\td[s] = 1;\n\t\t\t\tfor (int step = 0; step < k; step++) {\n\t\t\t\t\tArrays.fill(nd, 0);\n\n\t\t\t\t\tfor (int i = 0; i <= s; i++) {\n\t\t\t\t\t\tlong prob = inv[i + 1];\n\t\t\t\t\t\tfor (int j = 0; j <= i; j++) {\n\t\t\t\t\t\t\tnd[j] = (int) ((nd[j] + d[i] * prob) % MOD);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tint[] t = d;\n\t\t\t\t\td = nd;\n\t\t\t\t\tnd = t;\n\t\t\t\t}\n\n\t\t\t\tlong cur = 0;\n\t\t\t\tlong curP = 1;\n\t\t\t\tfor (int i = 0; i <= s; i++) {\n\t\t\t\t\tcur = (cur + curP * d[i]) % MOD;\n\t\t\t\t\tcurP = curP * p % MOD;\n\t\t\t\t}\n\t\t\t\tans = ans * cur % MOD;\n\t\t\t}\n\t\t\tout.println(ans);\n\t\t}\n\n\t\tprivate List<Factor> factorize(long n) {\n\t\t\tList<Factor> fs = new ArrayList<>();\n\t\t\tfor (long p = 2; p * p <= n; p++) {\n\t\t\t\tif (n % p == 0) {\n\t\t\t\t\tFactor f = new Factor();\n\t\t\t\t\tf.p = p;\n\t\t\t\t\twhile (n % p == 0) {\n\t\t\t\t\t\tn /= p;\n\t\t\t\t\t\t++f.s;\n\t\t\t\t\t}\n\t\t\t\t\tfs.add(f);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (n > 1) {\n\t\t\t\tFactor f = new Factor();\n\t\t\t\tf.p = n;\n\t\t\t\tf.s = 1;\n\t\t\t\tfs.add(f);\n\t\t\t}\n\t\t\treturn fs;\n\t\t}\n\n\t\tclass Factor {\n\t\t\tlong p;\n\t\t\tint s;\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\tString rl = in.readLine();\n\t\t\t\t\tif (rl == null) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\tst = new StringTokenizer(rl);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t}\n}\n\n", "src_uid": "dc466d9c24b7dcb37c0e99337b4124d2"} {"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 Alex\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskF solver = new TaskF();\n solver.solve(1, in, out);\n out.close();\n }\n static class TaskF {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int index = 0;\n String s = in.next();\n int res = 0;\n while(index < s.length()) {\n int val = (s.charAt(index) - '0');\n if(val == 1) {\n res += 10;\n index++;\n } else {\n if(s.charAt(index) == 'A')\n res += 1;\n else\n res += val;\n }\n index++;\n }\n out.printLine(res);\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 SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if(numChars == -1)\n throw new InputMismatchException();\n if(curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch(IOException e) {\n throw new InputMismatchException();\n }\n if(numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public String readString() {\n int c = read();\n while(isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n if(Character.isValidCodePoint(c))\n res.appendCodePoint(c);\n c = read();\n } while(!isSpaceChar(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n if(filter != null)\n return filter.isSpaceChar(c);\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n 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 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\n", "src_uid": "47287f8bc61fec72d729638d5e0e67f5"} {"source_code": "import java.io.IOException;\nimport java.io.InputStreamReader;\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 sheep\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskD solver = new TaskD();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskD {\n private static final int MOD = 1000000007;\n private long odd(int x) {\n if (x == 0) {\n return 0;\n }\n return (1 << (x - 1));\n }\n private long even(int x) {\n return (1 << (x)) - odd(x);\n }\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int k = in.nextInt();\n // dp[full set][num]\n int[][] dp = new int[2][35];\n dp[1][0] = 1;\n for (int i = 30; i >= 0; --i) {\n int[][] next = new int[2][35];\n int bit = (k >> i) % 2;\n if (bit == 0) {\n for (int num = 0; num < 32; ++num) {\n next[1][num] = (int) ((next[1][num] + dp[1][num] * even(num)) % MOD);\n }\n } else {\n for (int num = 0; num < 32; ++num) {\n next[1][num] = (int) ((next[1][num] + dp[1][num] * odd(num)) % MOD);\n next[0][num] = (int) ((next[0][num] + dp[1][num] * even(num)) % MOD);\n }\n\n for (int num = 0; num < 32; ++num) {\n next[1][num + 1] = (int) ((next[1][num + 1] + dp[1][num]) % MOD);\n }\n }\n\n for (int num = 0; num < 32; ++num) {\n next[0][num + 1] = (int) ((next[0][num + 1] + dp[0][num]) % MOD);\n next[0][num] = (int) ((next[0][num] + dp[0][num] * (1L << (long) num)) % MOD);\n }\n\n dp = next;\n// print(dp);\n// System.err.println(\"====\");\n }\n\n long answer = 0;\n for (int i = 0; i < 32; ++i) {\n answer = (answer + dp[0][i] + (long) dp[1][i]) % MOD;\n }\n\n out.println(answer);\n }\n}\n\nclass InputReader {\n BufferedReader reader;\n StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (Exception e) {\n throw new UnknownError();\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n", "src_uid": "ead64d8e3134fa8f29881cb487e52f60"} {"source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n\tpublic static final int MAX = 1000002;\n\t\n\tpublic static void main(String[] args) throws Exception {\n\t\tScanner in = new Scanner(System.in);\n\t\t\n\t\tint a1 = in.nextInt();\n\t\tint b1 = in.nextInt();\n\t\t\n\t\tint a2 = in.nextInt();\n\t\tint b2 = in.nextInt();\n\t\t\n\t\tint a3 = in.nextInt();\n\t\tint b3 = in.nextInt();\n\t\t\n\t\tboolean result = false;\n\t\t\n\t\tresult |= test(a1, b1, a2, b2, a3, b3);\n\t\tresult |= test(a1, b1, b2, a2, a3, b3);\n\t\tresult |= test(a1, b1, a2, b2, b3, a3);\n\t\tresult |= test(a1, b1, b2, a2, b3, a3);\n\t\t\n\t\tif (result) {\n\t\t\tSystem.out.println(\"YES\");\n\t\t} else {\n\t\t\tSystem.out.println(\"NO\");\n\t\t}\n\t}\n\t\n\tpublic static boolean test(int a1, int b1, int a2, int b2, int a3, int b3) {\n\t\t\n\t\tif (a2 + a3 <= a1) {\n\t\t\treturn Math.max(b2, b3) <= b1;\n\t\t} else if (Math.max(a2, a3) <= a1) {\n\t\t\treturn b2 + b3 <= b1;\n\t\t} else {\n\t\t\treturn false;\n\t\t}\n\t}\n}", "src_uid": "2ff30d9c4288390fd7b5b37715638ad9"} {"source_code": "import java.util.*;\n\npublic class RPS{\n\tpublic static void main(String[] args){\n\t\tScanner scan = new Scanner(System.in);\n\t\tint f = moveValue(scan.next());\n\t\tint m = moveValue(scan.next());\n\t\tint s = moveValue(scan.next());\n\n\t\tif((f == m && m == s) || (f != m && f != s && m != s)){\n\t\t\tSystem.out.println(\"?\");\n\t\t}else{\n\t\t\tif(f == m){\n\t\t\t\tif(compare(s, f)){\n\t\t\t\t\tSystem.out.println(\"S\");\n\t\t\t\t}else{\n\t\t\t\t\tSystem.out.println(\"?\");\n\t\t\t\t}\n\t\t\t}else if(m == s){\n\t\t\t\tif(compare(f, m)){\n\t\t\t\t\tSystem.out.println(\"F\");\n\t\t\t\t}else{\n\t\t\t\t\tSystem.out.println(\"?\");\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tif(compare(m, s)){\n\t\t\t\t\tSystem.out.println(\"M\");\n\t\t\t\t}else{\n\t\t\t\t\tSystem.out.println(\"?\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t}\n\n\t// rock = 0, scissors = 1, paper = 2\n\tpublic static int moveValue(String move){\n\t\tif(move.equals(\"rock\")){\n\t\t\treturn 0;\n\t\t}else if(move.equals(\"scissors\")){\n\t\t\treturn 1;\n\t\t}else{\n\t\t\treturn 2;\n\t\t}\n\t}\n\n\t// Returns true if a beats b\n\tpublic static boolean compare(int a, int b){\n\t\treturn (a + 1) % 3 == b;\n\t}\n}", "src_uid": "072c7d29a1b338609a72ab6b73988282"} {"source_code": "import java.io.*;\nimport java.util.*;\n\n\npublic class Main {\n static int inf = (int) (1e9 + 7);\n static int n, root = -1;\n static ArrayList<Integer> gr[];\n static ArrayList<triple> res = new ArrayList<>();\n static int sz[];\n\n static void build_sz(int v, int pr) {\n sz[v] = 1;\n for(int to : gr[v]) {\n if (to == pr) continue;\n build_sz(to, v);\n sz[v] += sz[to];\n }\n }\n\n static void find_centre(int v, int pr) {\n for(int to : gr[v]) {\n if (to != pr && sz[to] > n / 2) find_centre(to, v);\n }\n if (root == -1) root = v;\n }\n\n static void f(int v, int pr, int mul) {\n int cnt = 0;\n for(int to : gr[v]) {\n if (to == pr) continue;\n res.add(new triple(v, to, (1 + cnt) * mul));\n f(to, v, mul);\n cnt += sz[to];\n }\n }\n\n static void solve() throws IOException {\n n = sc.nextInt();\n gr = new ArrayList[n];\n for(int i = 0;i < n;i++) gr[i] = new ArrayList<>();\n sz = new int [n];\n\n for(int i = 0;i < n - 1;i++) {\n int v1 = sc.nextInt() - 1;\n int v2 = sc.nextInt() - 1;\n gr[v1].add(v2);\n gr[v2].add(v1);\n }\n\n build_sz(0, -1);\n find_centre(0, -1);\n build_sz(root, -1);\n\n\n ArrayList<Integer> to = new ArrayList<>();\n for(int i : gr[root]) to.add(i);\n Collections.sort(to, new Comparator<Integer>() {\n @Override\n public int compare(Integer o1, Integer o2) {\n return Integer.compare(sz[o1], sz[o2]);\n }\n });\n\n int cnt1 = 0;\n int cnt2 = 0;\n for(int i : to) {\n if (cnt1 >= (n + 2) / 3) {\n res.add(new triple(root, i, (cnt2 + 1) * (cnt1 + 1)));\n f(i, root, cnt1 + 1);\n cnt2 += sz[i];\n }else{\n res.add(new triple(root, i, cnt1 + 1));\n f(i, root, 1);\n cnt1 += sz[i];\n }\n }\n\n for(triple i : res) {\n pw.println((i.a + 1) + \" \" + (i.b + 1) + \" \" + i.x);\n }\n }\n\n\n\n\n public static void main(String[] args) throws IOException {\n sc = new Scanner(System.in);\n pw = new PrintWriter(System.out);\n solve();\n pw.close();\n }\n\n static Scanner sc;\n static PrintWriter pw;\n\n static class Scanner {\n BufferedReader br;\n StringTokenizer st = new StringTokenizer(\"\");\n\n Scanner(InputStream in) throws FileNotFoundException {\n br = new BufferedReader(new InputStreamReader(in));\n }\n\n Scanner(String in) throws FileNotFoundException {\n br = new BufferedReader(new FileReader(in));\n }\n\n String next() throws IOException {\n while (!st.hasMoreTokens()) st = new StringTokenizer(br.readLine());\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\n}\n\nclass triple {\n int a, b, x;\n triple(int a, int b, int x) {\n this.a = a;\n this.b = b;\n this.x = x;\n }\n\n triple() {}\n}", "src_uid": "87d755df6ee27b381122062659c4a432"} {"source_code": "import java.util.Scanner ;\nimport java.math.*;\nimport java.util.*;\npublic class Hi {\n\n\tpublic static void main(String[] args) {\n\t\tScanner input = new Scanner(System.in);\n\t\tint a = input.nextInt();\n\t\tint b= input.nextInt();\n\t\tint ans =1 ; \n\t\t//System.out.print(gcd(3,6));\n\t\tans+= 6 - Math.max(a, b);\n\t\t//System.out.print(ans);\n\t\tint num = ans / gcd(ans,6);\n\t\tint dum = 6/gcd(ans,6);\n\t\tSystem.out.printf(\"%d/%d\",num,dum);\n\t\t\n\t\t\t\n\t\t}\n\t\n\tpublic static int gcd(int x, int y ){\n\t\tif(x==0)\n\t\t\treturn y ;\n\t\tif(y==0)\n\t\t\treturn x ;\n\t\telse{\n\t\t\treturn (x>y)?gcd(x%y, y):gcd(x,y%x);\n\t\t}\n\t}\n\n\t\t\n\n\t\t\n\t\t\n\t\t\n\t\t\t\t\t\t\t\n\t}\n\n\t\n\n\n\t\n\n\t\t\n\t\n\t\t\n\t\n\n\n\t\t\t\n\t\t\n\t\t\n\t\t\t\n\n\t\t\n\t\t\n\n\n", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414"} {"source_code": "import java.util.*;\n\npublic class Boser {\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 input = new Scanner(System.in);\n String s = input.next();\n char b[] = s.toCharArray();\n for (int i = 0; i < b.length; i++) {\n if (b[i] == '.') {\n System.out.print(0);\n }\n if (b[i] == '-' && b[i + 1] == '.') {\n System.out.print(1);\n i++;\n }\n if (b[i] == '-' && b[i + 1] == '-') {\n System.out.print(2);\n i++;\n }\n }\n System.out.println();\n }\n}\n", "src_uid": "46b5a1cd1bd2985f2752662b7dbb1869"} {"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 FreeMarket2 {\n \n int V = (int) 5e5 + 10;\n \n void solve() {\n int n = in.nextInt(), d = in.nextInt();\n int[] c = new int[n];\n for (int i = 0; i < n; i++) c[i] = in.nextInt();\n \n int[] dp = new int[V];\n dp[0] = 1;\n for (int i = 0; i < n; i++) {\n for (int j = V - 1; j >= c[i]; j--) {\n dp[j] |= dp[j - c[i]];\n }\n }\n \n int cnt = 0;\n for (int i = 0; i < V; i++) if (dp[i] > 0) cnt++;\n int[] sta = new int[cnt];\n for (int i = 0, j = 0; i < V; i++) if (dp[i] > 0) sta[j++] = i;\n \n int days = 0, p = 0;\n while (p < cnt) {\n int q = p;\n while (q + 1 < cnt && sta[q + 1] <= sta[p] + d) q++;\n if (p < q) {\n days++;\n p = q;\n } else {\n break;\n }\n }\n out.printf(\"%d %d%n\", sta[p], days);\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 FreeMarket2().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", "src_uid": "65699ddec8d0db2f58b83a0f64de6f6f"} {"source_code": "import java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.Reader;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\n\n/**\n * Created by yash on 04/06/17.\n */\npublic class A {\n public static void main(String[] args) throws IOException {\n Reader reader = new InputStreamReader(System.in);\n BufferedReader br = new BufferedReader(reader);\n BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));\n Solver solver = new Solver();\n solver.solve(br, bw);\n br.close();\n bw.close();\n }\n\n static class Solver {\n\n Utils utils;\n\n Solver() {\n utils = new Utils();\n }\n\n void solve(BufferedReader br, BufferedWriter bw) throws IOException {\n int[] args = new int[2];\n utils.getIntArray(br.readLine(), args, \":\");\n int h = args[0];\n int m = args[1];\n int ans = 0;\n\n while (true) {\n int revh = rev(h);\n if (revh < 60 && m <= revh) {\n ans += revh - m;\n break;\n } else {\n h = (h + 1) % 24;\n ans += 60 - m;\n m = 0;\n }\n }\n bw.write(ans + \"\\n\");\n }\n\n int rev(int n) {\n int ans = 0;\n if (n < 10)\n return n * 10;\n\n while (n > 0) {\n ans = ans * 10;\n ans += n % 10;\n n /= 10;\n }\n return ans;\n }\n }\n\n static class Utils {\n\n void getLongArray(String s, long a[]) {\n String[] temp = s.split(\" \");\n for (int i = 0; i < temp.length; i++) {\n a[i] = getLong(temp[i]);\n }\n }\n\n void getIntArray(String s, int a[]) {\n String[] temp = s.split(\" \");\n for (int i = 0; i < temp.length; i++) {\n a[i] = getInt(temp[i]);\n }\n }\n\n void getIntArray(String s, int a[], String regex) {\n String[] temp = s.split(regex);\n for (int i = 0; i < temp.length; i++) {\n a[i] = getInt(temp[i]);\n }\n }\n\n int getInt(String s) {\n return Integer.parseInt(s);\n }\n\n long getLong(String s) {\n return Long.parseLong(s);\n }\n\n void printArray(int[] a) {\n for (int i = 0; i < a.length; i++) {\n System.out.print(a[i] + \" \");\n }\n System.out.println();\n }\n\n void printArray(long[] a) {\n for (int i = 0; i < a.length; i++) {\n System.out.print(a[i] + \" \");\n }\n System.out.println();\n }\n\n void printArray(float[] a) {\n for (int i = 0; i < a.length; i++) {\n System.out.print(a[i] + \" \");\n }\n System.out.println();\n }\n\n void printArray(double[] a) {\n for (int i = 0; i < a.length; i++) {\n System.out.print(a[i] + \" \");\n }\n System.out.println();\n }\n\n void print2DArray(int[][] a) {\n for (int i = 0; i < a.length; i++) {\n for (int j = 0; j < a[0].length; j++) {\n System.out.print(a[i][j] + \" \");\n }\n System.out.println();\n }\n System.out.println();\n }\n\n void print2DArray(Object[][] a) {\n for (int i = 0; i < a.length; i++) {\n for (int j = 0; j < a[0].length; j++) {\n System.out.print(a[i][j] + \" \");\n }\n System.out.println();\n }\n System.out.println();\n }\n\n }\n}", "src_uid": "3ad3b8b700f6f34b3a53fdb63af351a5"} {"source_code": "\nimport java.util.*;\nimport java.util.Collections;\n\npublic class Contest\n{\n\tpublic static void main(String args[])\n\t{\n\t\t\n\t\tScanner sc=new Scanner(System.in);\n\n\t\tint mp,vp,c,d;\n\t\tint misha,vasya;\n\t\t\n\t\tmp=sc.nextInt();\n\t\tvp=sc.nextInt();\n\t\tc=sc.nextInt();\n\t\td=sc.nextInt();\n\t\t\n\t\tmisha=Math.max((3*mp)/10, mp-(mp*c)/250);\n\t\t\n\t\tvasya=Math.max((3*vp)/10, vp-(vp*d)/250);\n\t\t\n\t\tif(misha>vasya)\n\t\t\tSystem.out.println(\"Misha\");\n\t\telse if(vasya>misha)\n\t\t\tSystem.out.println(\"Vasya\" );\n\t\telse\n\t\t\tSystem.out.println(\"Tie\" );\n\n\t\tsc.close();\n\t}\n}\n", "src_uid": "95b19d7569d6b70bd97d46a8541060d0"} {"source_code": "//package All_in_all;\n\n\nimport java.io.*;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.StringTokenizer;\n\nimport static java.lang.Math.abs;\nimport static java.lang.Math.round;\n\n/**\n * Created by nikitos on 23.08.17.\n */\n\npublic class otrezok {\n\n public StreamTokenizer t;\n\n public int nextInt() throws IOException {\n t.nextToken();\n return (int) t.nval;\n }\n\n public String nextString() throws IOException {\n t.nextToken();\n return t.sval;\n }\n\n public void start() throws IOException {\n BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));\n\n int n = Integer.parseInt(buf.readLine());\n\n for (int i = 0; i < n; i++) {\n String[] lit = buf.readLine().split(\" \");\n long a = Long.parseLong(lit[0]);\n long b = Long.parseLong(lit[1]);\n\n if (a - b != 1) {\n System.out.println(\"NO\");\n } else {\n long c = a + b;\n System.out.println(checkIsItANaturalNumber(c)? \"YES\" : \"NO\");\n }\n }\n }\n\n\n private boolean checkIsItANaturalNumber(long n) {\n for (int i = 2; i <= Math.sqrt(n) + 1; i++) {\n if (n % i == 0) {\n return false;\n }\n }\n\n return true;\n }\n\n public static void main(String[] args) throws IOException {\n new otrezok().start();\n }\n\n}\n", "src_uid": "5a052e4e6c64333d94c83df890b1183c"} {"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<<m)][(k+1)*(1<<m)];\n for(int i=0;i<=k;i++) {\n for (int j = 0; j < (1 << m); j++) {\n ma[trans(i,j>>1)][trans(i,j)]=1;\n if(i<k)ma[trans(i+1,j>>1|(1<<m-1))][trans(i,j)]=Integer.bitCount(j)+1;\n }\n }\n ma=FastPowMod(ma,n);\n long ans=0;\n for(int i=trans(k,0);i<ma.length;i++)ans+=ma[i][0];\n out.println(ans%mod);\n out.flush();\n }\n public int[][] FastPowMod(int[][] a,int b){\n int[][] ans=new int[a.length][a.length];\n for(int i=0;i<a.length;i++)ans[i][i]=1;\n while(b>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;i<row;i++){\n for(int j=0;j<len;j++){\n //if(a[i][j]==0)continue;//\u7a00\u758f\u77e9\u9635\u4f18\u5316\n for(int k=0;k<column;k++){\n ans[i][k]+=(long)a[i][j]*b[j][k]%mod;\n ans[i][k]%=mod;\n }\n }\n }\n return ans;\n }\n\n int trans(int x,int y){\n return x*(1<<m)+y;\n }\n @Override\n public void run() {\n try {\n solve();\n } catch (Exception e) {\n e.printStackTrace();\n }\n }\n void shuffle(int[]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),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}", "src_uid": "87931a8ae9a76d85bd2a2b4bba93303d"} {"source_code": "import java.util.*;\nimport java.io.DataInputStream;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\nimport java.util.*;\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 static void p(String s){\n System.out.println(s);\n }\n static void p(int s){\n System.out.println(s);\n }\n static void p(long s){\n System.out.println(s);\n }\n static void p(int[] s){\n System.out.println(Arrays.toString(s));\n }\n static void p2(String s){\n System.out.print(s);\n }\n\n public static void main(String[] args) throws IOException {\n Scanner s = new Scanner(System.in);\n char[] str = (s.next()).toCharArray();\n Set<Character> v = new HashSet<>();\n v.add('u');\n v.add('o');\n v.add('i');\n v.add('e');\n v.add('a');\n v.add('n');\n for(int i = 0;i<str.length-1;i++){\n if(!v.contains(str[i]) && str[i+1] == 'n'){\n p(\"NO\");\n return;\n }\n if(v.contains(str[i])) continue;\n if(v.contains(str[i+1])) continue;\n p(\"NO\");\n return;\n }\n if(!v.contains(str[str.length-1])){\n p(\"NO\");\n return;\n }\n p(\"YES\");\n }\n}", "src_uid": "a83144ba7d4906b7692456f27b0ef7d4"} {"source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.awt.Point;\n\n// SHIVAM GUPTA :\n//NSIT\n//decoder_1671\n//BEING PERFECTIONIST IS NOT AN OPTION.\n// YOUR LOVE MAKE ME STRONGER BUT UR HATE MAKES ME STRONGEST ... NOW ITS UR CHOICE..........\n// STOP NOT TILL IT IS DONE OR U DIE .\n//EITHER MAKE IT OR BREAK IT.\n//NEVER UNDERESTIMATE URSELF.\n// U KNOW THAT IF THIS DAY WILL BE URS THEN NO ONE CAN DEFEAT U HERE................\n// REST ..HAVE FAITH ON DESTINY\n//MIRACLE HAPPENS RARELY .....BUT IT HAPPENS ...\n\n\n// ASCII = 48 + i ;\n\n\n// 2^28 = 268,435,456 > 2* 10^8 \n\n// log 10 base 2 = 3.3219 \n\n// odd:: (x^2+1)/2 , (x^2-1)/2 ; x>=3\n\n// even:: (x^2/4)+1 ,(x^2/4)-1 x >=4 \n\n// FOR ANY ODD NO N : N,N-1,N-2\n//ALL ARE PAIRWISE COPRIME \n//THEIR COMBINED LCM IS PRODUCT OF ALL THESE NOS\n\n// two consecutive odds are always coprime to each other\n\n// two consecutive even have always gcd = 2 ;\n\n\n/* Name of the class has to be \"Main\" only if the class is public. */\n\n\n\npublic class Main\n{\n \n // static int[] arr = new int[100002] ; \n // static int[] dp = new int[100002] ; \n \n static PrintWriter out;\n \n\tstatic class FastReader{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FastReader(){\n\t\t\tbr=new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout=new PrintWriter(System.out);\n\t\t}\n\t\tString next(){\n\t\t\twhile(st==null || !st.hasMoreElements()){\n\t\t\t\ttry{\n\t\t\t\t\tst= new StringTokenizer(br.readLine());\n\t\t\t\t}\n\t\t\t\tcatch (IOException e){\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tint nextInt(){\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tlong nextLong(){\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\tdouble nextDouble(){\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\tString nextLine(){\n\t\t\tString str = \"\";\n\t\t\ttry{\n\t\t\t\tstr=br.readLine();\n\t\t\t}\n\t\t\tcatch(IOException e){\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\t}\n\t\n\n\n////////////////////////////////////////////////////////////////////////////////////\n public static int countDigit(long n) \n { \n return (int)Math.floor(Math.log10(n) + 1); \n } \n\n///////////////////////////////////////////////////////////////////////////////////////// \n \n public static int sumOfDigits(long n)\n {\n \n if( n< 0)return -1 ;\n \n int sum = 0;\n \n while( n > 0)\n {\n sum = sum + (int)( n %10) ;\n \n n /= 10 ;\n }\n \n return sum ; \n \n \n \n }\n \n //////////////////////////////////////////////////////////////////////////////////////////////////\n\npublic static long arraySum(int[] arr , int start , int end)\n{\n long ans = 0 ;\n \n for(int i = start ; i <= end ; i++)ans += arr[i] ;\n \n return ans ;\n}\n\n/////////////////////////////////////////////////////////////////////////////////\n\npublic static int mod(int x)\n{\n if(x <0)return -1*x ;\n else return x ;\n}\npublic static long mod(long x)\n{\n if(x <0)return -1*x ;\n else return x ;\n}\n\n////////////////////////////////////////////////////////////////////////////////\n\npublic static void swapArray(int[] arr , int start , int end)\n{\n while(start < end)\n {\n int temp = arr[start] ;\n arr[start] = arr[end];\n arr[end] = temp;\n start++ ;end-- ;\n }\n}\n\n\n//////////////////////////////////////////////////////////////////////////////////\n\n\npublic static int[][] rotate(int[][] input){\n\nint n =input.length;\nint m = input[0].length ;\nint[][] output = new int [m][n];\n\nfor (int i=0; i<n; i++)\n\tfor (int j=0;j<m; j++)\n\t\toutput [j][n-1-i] = input[i][j];\nreturn output;\n}\n///////////////////////////////////////////////////////////////////////////////////////////////////////\n\npublic static int countBits(long n) \n { \n int count = 0; \n while (n != 0) \n { \n count++; \n n = (n) >> (1L) ;\n } \n \n return count; \n \n } \n/////////////////////////////////////////// //////////////////////////////////////////////// \n\npublic static boolean isPowerOfTwo(long n) \n{ \n if(n==0) \n return false; \n \nif(((n ) & (n-1)) == 0 ) return true ;\nelse return false ;\n\n} \n\n/////////////////////////////////////////////////////////////////////////////////////\n\npublic static int min(int a ,int b , int c, int d)\n{\n int[] arr = new int[4] ;\n arr[0] = a;arr[1] = b ;arr[2] = c;arr[3] = d;Arrays.sort(arr) ;\n \n return arr[0];\n}\n /////////////////////////////////////////////////////////////////////////////\npublic static int max(int a ,int b , int c, int d)\n{\n int[] arr = new int[4] ;\n arr[0] = a;arr[1] = b ;arr[2] = c;arr[3] = d;Arrays.sort(arr) ;\n \n return arr[3];\n}\n \n/////////////////////////////////////////////////////////////////////////////////// \n\npublic static String reverse(String input)\n{\n StringBuilder str = new StringBuilder(\"\") ;\n \n for(int i =input.length()-1 ; i >= 0 ; i-- )\n {\n str.append(input.charAt(i));\n }\n \nreturn str.toString() ;\n}\n///////////////////////////////////////////////////////////////////////////////////////////\n\npublic static boolean sameParity(long a ,long b )\n{\n long x = a% 2L; long y = b%2L ;\n if(x==y)return true ;\n else return false ;\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////\npublic static boolean isPossibleTriangle(int a ,int b , int c)\n{\n if( a + b > c && c+b > a && a +c > b)return true ;\n else return false ;\n}\n\n\n////////////////////////////////////////////////////////////////////////////////////////////\nstatic long xnor(long num1, long num2) {\n\t\tif (num1 < num2) {\n\t\t\tlong temp = num1;\n\t\t\tnum1 = num2;\n\t\t\tnum2 = temp;\n\t\t}\n\t\tnum1 = togglebit(num1);\n\t\treturn num1 ^ num2;\n\t}\n\n\tstatic long togglebit(long n) {\n\t\tif (n == 0)\n\t\t\treturn 1;\n\t\tlong i = n;\n\t\tn |= n >> 1;\n\t\tn |= n >> 2;\n\t\tn |= n >> 4;\n\t\tn |= n >> 8;\n\t\tn |= n >> 16;\n\t\treturn i ^ n;\n\t}\n\n///////////////////////////////////////////////////////////////////////////////////////////////\n\npublic static int xorOfFirstN(int n)\n{\n \n \n if( n % 4 ==0)return n ;\n \n else if( n % 4 == 1)return 1 ;\n \n else if( n % 4 == 2)return n+1 ;\n \n else return 0 ;\n \n \n}\n//////////////////////////////////////////////////////////////////////////////////////////////\n\npublic static int gcd(int a, int b )\n{\n\nif(b==0)return a ;\n\nelse return gcd(b,a%b) ; \n\n}\n\n\npublic static long gcd(long a, long b )\n{\n\nif(b==0)return a ;\n\nelse return gcd(b,a%b) ; \n\n}\n\n////////////////////////////////////////////////////////////////////////////////////\n\npublic static int lcm(int a, int b ,int c , int d )\n{\n\nint temp = lcm(a,b , c) ;\n\n\n \n int ans = lcm(temp ,d ) ;\n\nreturn ans ;\n\n\n}\n\n///////////////////////////////////////////////////////////////////////////////////////////\n\npublic static int lcm(int a, int b ,int c )\n{\n\nint temp = lcm(a,b) ;\n\nint ans = lcm(temp ,c) ;\n\nreturn ans ;\n\n\n}\n\n////////////////////////////////////////////////////////////////////////////////////////\n \npublic static int lcm(int a , int b )\n{\n\nint gc = gcd(a,b);\n\nreturn (a*b)/gc ;\n}\n\n///////////////////////////////////////////////////////////////////////////////////////////\nstatic boolean isPrime(long n)\n{\n if(n==1)\n {\n return false ;\n }\n \n boolean ans = true ;\n \n for(long i = 2L; i*i <= n ;i++)\n {\n if(n% i ==0)\n {\n ans = false ;break ;\n }\n }\n \n \n return ans ;\n} \n///////////////////////////////////////////////////////////////////////////\n\nstatic int sieve = 1000000 ;\n\n \nstatic boolean[] prime = new boolean[sieve + 1] ;\n\npublic static void sieveOfEratosthenes() \n { \n // FALSE == prime\n \n // TRUE == COMPOSITE\n \n // FALSE== 1\n \n \n // time complexity = 0(NlogLogN)== o(N)\n \n // gives prime nos bw 1 to N\n \n for(int i = 4; i<= sieve ; i++)\n {\n prime[i] = true ;\n i++ ;\n }\n \n for(int p = 3; p*p <= sieve; p++) \n { \n \n if(prime[p] == false) \n { \n \n for(int i = p*p; i <= sieve; i += p) \n prime[i] = true; \n } \n \n p++ ;\n } \n \n \n \n \n } \n \n///////////////////////////////////////////////////////////////////////////////////\n\n\npublic static void sortD(int[] arr , int s , int e)\n{\n sort(arr ,s , e) ;\n \n int i =s ; int j = e ;\n \n while( i < j)\n {\n int temp = arr[i] ;\n arr[i] =arr[j] ;\n arr[j] = temp ;\n i++ ; j-- ;\n }\n \n \n \n return ;\n}\n\n\n/////////////////////////////////////////////////////////////////////////////////////////\n\npublic static long countSubarraysSumToK(long[] arr ,long sum )\n {\n HashMap<Long,Long> map = new HashMap<>() ;\n \n int n = arr.length ;\n \n long prefixsum = 0 ;\n \n long count = 0L ;\n for(int i = 0; i < n ; i++)\n {\n prefixsum = prefixsum + arr[i] ;\n \n if(sum == prefixsum)count = count+1 ;\n \n if(map.containsKey(prefixsum -sum))\n {\n count = count + map.get(prefixsum -sum) ;\n }\n \n \n if(map.containsKey(prefixsum ))\n {\n map.put(prefixsum , map.get(prefixsum) +1 );\n }\n \n else{\n map.put(prefixsum , 1L );\n }\n \n \n }\n \n \n \n return count ; \n \n }\n\n///////////////////////////////////////////////////////////////////////////////////////////////\n\n\n// KMP ALGORITHM : TIME COMPL:O(N+M) \n// FINDS THE OCCURENCES OF PATTERN AS A SUBSTRING IN STRING\n//RETURN THE ARRAYLIST OF INDEXES \n// IF SIZE OF LIST IS ZERO MEANS PATTERN IS NOT PRESENT IN STRING\n\n\npublic static ArrayList<Integer> kmpAlgorithm(String str , String pat)\n {\n ArrayList<Integer> list =new ArrayList<>();\n \n int n = str.length() ;\n int m = pat.length() ;\n \n String q = pat + \"#\" + str ;\n \n int[] lps =new int[n+m+1] ;\n \n longestPefixSuffix(lps, q,(n+m+1)) ;\n \n \n for(int i =m+1 ; i < (n+m+1) ; i++ )\n {\n if(lps[i] == m)\n {\n list.add(i-2*m) ;\n }\n }\n \n return list ; \n \n \n }\n \n\npublic static void longestPefixSuffix(int[] lps ,String str , int n)\n {\n lps[0] = 0 ;\n \n for(int i = 1 ; i<= n-1; i++)\n {\n int l = lps[i-1] ;\n \n while( l > 0 && str.charAt(i) != str.charAt(l))\n {\n l = lps[l-1] ;\n }\n \n if(str.charAt(i) == str.charAt(l))\n {\n l++ ;\n }\n \n \n lps[i] = l ; \n }\n \n }\n \n \n\n///////////////////////////////////////////////////////////////////////////////////////////////////\n///////////////////////////////////////////////////////////////////////////////////////////////////\n\n // CALCULATE TOTIENT Fn FOR ALL VALUES FROM 1 TO n\n // TOTIENT(N) = count of nos less than n and grater than 1 whose gcd with n is 1 \n // or n and the no will be coprime in nature\n //time : O(n*(log(logn)))\n \n public static void eulerTotientFunction(int[] arr ,int n )\n {\n \n for(int i = 1; i <= n ;i++)arr[i] =i ;\n \n \n for(int i= 2 ; i<= n ;i++)\n {\n if(arr[i] == i)\n {\n arr[i] =i-1 ;\n \n for(int j =2*i ; j<= n ; j+= i )\n {\n arr[j] = (arr[j]*(i-1))/i ;\n }\n \n }\n }\n \n return ; \n \n }\n\t\n/////////////////////////////////////////////////////////////////////////////////////////////\npublic static long nCr(int n,int k)\n{\n long ans=1L;\n k=k>n-k?n-k:k;\n int j=1;\n for(;j<=k;j++,n--)\n {\n if(n%j==0)\n {\n ans*=n/j;\n }else\n if(ans%j==0)\n {\n ans=ans/j*n;\n }else\n {\n ans=(ans*n)/j;\n }\n }\n return ans;\n}\n\n///////////////////////////////////////////////////////////////////////////////////////////\n\npublic static ArrayList<Integer> allFactors(int n)\n{ \n ArrayList<Integer> list = new ArrayList<>() ;\n \n for(int i = 1; i*i <= n ;i++)\n {\n if( n % i == 0)\n {\n if(i*i == n)\n {\n list.add(i) ;\n }\n else{\n list.add(i) ;\n list.add(n/i) ;\n \n }\n }\n }\n \n return list ; \n \n \n}\n\n\npublic static ArrayList<Long> allFactors(long n)\n{ \n ArrayList<Long> list = new ArrayList<>() ;\n \n for(long i = 1L; i*i <= n ;i++)\n {\n if( n % i == 0)\n {\n if(i*i == n)\n {\n list.add(i) ;\n }\n else{\n list.add(i) ;\n list.add(n/i) ;\n \n }\n }\n }\n \n return list ; \n \n \n}\n////////////////////////////////////////////////////////////////////////////////////////////////////\n\n static final int MAXN = 10000001; \n \n \n static int spf[] = new int[MAXN]; \n \n static void sieve() \n { \n spf[1] = 1; \n for (int i=2; i<MAXN; i++) \n \n \n spf[i] = i; \n \n \n for (int i=4; i<MAXN; i+=2) \n spf[i] = 2; \n \n for (int i=3; i*i<MAXN; i++) \n { \n \n if (spf[i] == i) \n { \n \n for (int j=i*i; j<MAXN; j+=i) \n \n if (spf[j]==j) \n spf[j] = i; \n } \n } \n } \n \n// The above code works well for n upto the order of 10^7.\n// Beyond this we will face memory issues.\n\n// Time Complexity: The precomputation for smallest prime factor is done in O(n log log n)\n// using sieve.\n// Where as in the calculation step we are dividing the number every time by \n// the smallest prime number till it becomes 1.\n// So, let\u2019s consider a worst case in which every time the SPF is 2 .\n// Therefore will have log n division steps.\n\n\n// Hence, We can say that our Time Complexity will be O(log n) in worst case.\n\n\n static Vector<Integer> getFactorization(int x) \n { \n Vector<Integer> ret = new Vector<>(); \n while (x != 1) \n { \n ret.add(spf[x]); \n x = x / spf[x]; \n } \n return ret; \n } \n \n //////////////////////////////////////////////////////////////////////////////////////////////////\n //////////////////////////////////////////////////////////////////////////////////////////////////\n \npublic static void merge(int arr[], int l, int m, int r)\n {\n // Find sizes of two subarrays to be merged\n int n1 = m - l + 1;\n int n2 = r - m;\n \n /* Create temp arrays */\n int L[] = new int[n1];\n int R[] = new int[n2];\n \n /*Copy data to temp arrays*/\n for (int i=0; i<n1; ++i)\n L[i] = arr[l + i];\n for (int j=0; j<n2; ++j)\n R[j] = arr[m + 1+ j];\n \n \n /* Merge the temp arrays */\n \n // Initial indexes of first and second subarrays\n int i = 0, j = 0;\n \n // Initial index of merged subarry array\n int k = l;\n while (i < n1 && j < n2)\n {\n if (L[i] <= R[j])\n {\n arr[k] = L[i];\n i++;\n }\n else\n {\n arr[k] = R[j];\n j++;\n }\n k++;\n }\n \n /* Copy remaining elements of L[] if any */\n while (i < n1)\n {\n arr[k] = L[i];\n i++;\n k++;\n }\n \n /* Copy remaining elements of R[] if any */\n while (j < n2)\n {\n arr[k] = R[j];\n j++;\n k++;\n }\n }\n \n // Main function that sorts arr[l..r] using\n // merge()\n public static void sort(int arr[], int l, int r)\n {\n if (l < r)\n {\n // Find the middle point\n int m = (l+r)/2;\n \n // Sort first and second halves\n sort(arr, l, m);\n sort(arr , m+1, r);\n \n // Merge the sorted halves\n merge(arr, l, m, r);\n }\n }\n\npublic static void sort(long arr[], int l, int r)\n {\n if (l < r)\n {\n // Find the middle point\n int m = (l+r)/2;\n \n // Sort first and second halves\n sort(arr, l, m);\n sort(arr , m+1, r);\n \n // Merge the sorted halves\n merge(arr, l, m, r);\n }\n }\n\n\npublic static 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<n1; ++i)\n L[i] = arr[l + i];\n for (int j=0; j<n2; ++j)\n R[j] = arr[m + 1+ j];\n \n \n /* Merge the temp arrays */\n \n // Initial indexes of first and second subarrays\n int i = 0, j = 0;\n \n // Initial index of merged subarry array\n int k = l;\n while (i < n1 && j < n2)\n {\n if (L[i] <= R[j])\n {\n arr[k] = L[i];\n i++;\n }\n else\n {\n arr[k] = R[j];\n j++;\n }\n k++;\n }\n \n /* Copy remaining elements of L[] if any */\n while (i < n1)\n {\n arr[k] = L[i];\n i++;\n k++;\n }\n \n /* Copy remaining elements of R[] if any */\n while (j < n2)\n {\n arr[k] = R[j];\n j++;\n k++;\n }\n }\n \n\n /////////////////////////////////////////////////////////////////////////////////////////\n \n\tpublic static long knapsack(int[] weight,long value[],int maxWeight){\n\n \n int n= value.length ;\n \n\t\n\t//dp[i] stores the profit with KnapSack capacity \"i\" \n long []dp = new long[maxWeight+1]; \n \n //initially profit with 0 to W KnapSack capacity is 0 \n Arrays.fill(dp, 0); \n \n // iterate through all items \n for(int i=0; i < n; i++) \n \n //traverse dp array from right to left \n for(int j = maxWeight; j >= weight[i]; j--) \n dp[j] = Math.max(dp[j] , value[i] + dp[j - weight[i]]); \n \n /*above line finds out maximum of dp[j](excluding ith element value) \n and val[i] + dp[j-wt[i]] (including ith element value and the \n profit with \"KnapSack capacity - ith element weight\") */\n return dp[maxWeight]; \n\t}\n\n///////////////////////////////////////////////////////////////////////////////////////////\n//////////////////////////////////////////////////////////////////////////////////////////\n\n\n// to return max sum of any subarray in given array\npublic static long kadanesAlgorithm(long[] arr)\n{\n long[] dp = new long[arr.length] ;\n \n dp[0] = arr[0] ;\n long max = dp[0] ;\n \n \n for(int i = 1; i < arr.length ; i++)\n {\n if(dp[i-1] > 0)\n {\n dp[i] = dp[i-1] + arr[i] ;\n }\n else{\n dp[i] = arr[i] ;\n }\n \n if(dp[i] > max)max = dp[i] ;\n \n }\n \n return max ;\n \n}\n/////////////////////////////////////////////////////////////////////////////////////////////\npublic static long kadanesAlgorithm(int[] arr)\n{\n long[] dp = new long[arr.length] ;\n \n dp[0] = arr[0] ;\n long max = dp[0] ;\n \n \n for(int i = 1; i < arr.length ; i++)\n {\n if(dp[i-1] > 0)\n {\n dp[i] = dp[i-1] + arr[i] ;\n }\n else{\n dp[i] = arr[i] ;\n }\n \n if(dp[i] > max)max = dp[i] ;\n \n }\n \n return max ;\n \n}\n\n \n///////////////////////////////////////////////////////////////////////////////////////\n\n\n\n/////////////////////////////////////////////////////////////////////////////////////////\n\npublic static long binarySerachGreater(int[] arr , int start , int end , int val)\n{\n \n // fing total no of elements strictly grater than val in sorted array arr \n \n \n if(start > end)return 0 ; //Base case\n \n \n int mid = (start + end)/2 ;\n \n if(arr[mid] <=val)\n {\n return binarySerachGreater(arr,mid+1, end ,val) ; \n \n }\n else{\n \n return binarySerachGreater(arr,start , mid -1,val) + end-mid+1 ; \n \n }\n \n \n}\n\n//////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////\n\n//TO GENERATE ALL(DUPLICATE ALSO EXIST) PERMUTATIONS OF A STRING\n\n\n// JUST CALL generatePermutation( str, start, end) start :inclusive ,end : exclusive \n\n//Function for swapping the characters at position I with character at position j \n public static String swapString(String a, int i, int j) { \n char[] b =a.toCharArray(); \n char ch; \n ch = b[i]; \n b[i] = b[j]; \n b[j] = ch; \n return String.valueOf(b); \n } \n \n//Function for generating different permutations of the string \n public static void generatePermutation(String str, int start, int end) \n { \n //Prints the permutations \n if (start == end-1) \n System.out.println(str); \n else \n { \n for (int i = start; i < end; i++) \n { \n //Swapping the string by fixing a character \n str = swapString(str,start,i); \n //Recursively calling function generatePermutation() for rest of the characters \n generatePermutation(str,start+1,end); \n //Backtracking and swapping the characters again. \n str = swapString(str,start,i); \n } \n } \n } \n\n\n\n////////////////////////////////////////////////////////////////////////////////////////////////////\n//////////////////////////////////////////////////////////////////////////////////////////////////////\n\npublic static long factMod(long n, long mod) {\n if (n <= 1) return 1;\n long ans = 1;\n for (int i = 1; i <= n; i++) {\n ans = (ans * i) % mod;\n }\n return ans;\n }\n\n\n/////////////////////////////////////////////////////////////////////////////////////////////\n//////////////////////////////////////////////////////////////////////////////////////////////////\n\npublic static long power(int x ,int n)\n {\n //time comp : o(logn) \n \n if(n==0)return 1 ;\n if(n==1)return x;\n \n long ans =1L ;\n \n while(n>0)\n {\n if(n % 2 ==1)\n {\n ans = ans *x ;\n }\n \n n /= 2 ;\n \n x = x*x ;\n \n }\n \n return ans ;\n }\n\n////////////////////////////////////////////////////////////////////////////////////////////////////\npublic static long powerMod(long x, long n, long mod) {\n //time comp : o(logn)\n \n if(n==0)return 1L ;\n if(n==1)return x;\n \n \n long ans = 1;\n while (n > 0) {\n if (n % 2 == 1) ans = (ans * x) % mod;\n x = (x * x) % mod;\n n /= 2;\n }\n return ans;\n }\n \n//////////////////////////////////////////////////////////////////////////////////\n\n/////////////////////////////////////////////////////////////////////////////////\n\n/*\nlowerBound - finds largest element equal or less than value paased\nupperBound - finds smallest element equal or more than value passed\n\nif not present return -1;\n\n*/\n\npublic static long lowerBound(long[] arr,long k)\n\t{\n\t\tlong ans=-1;\n\t\t\n\t\tint start=0;\n\t\tint end=arr.length-1;\n\t\t\n\t\twhile(start<=end)\n\t\t{\n\t\t\tint mid=(start+end)/2;\n\t\t\t\n\t\t\tif(arr[mid]<=k)\n\t\t\t{\n\t\t\t\tans=arr[mid];\n\t\t\t\tstart=mid+1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tend=mid-1;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\treturn ans;\n\t\t\n\t}\n\t\n\tpublic static int lowerBound(int[] arr,int k)\n\t{\n\t\tint ans=-1;\n\t\t\n\t\tint start=0;\n\t\tint end=arr.length-1;\n\t\t\n\t\twhile(start<=end)\n\t\t{\n\t\t\tint mid=(start+end)/2;\n\t\t\t\n\t\t\tif(arr[mid]<=k)\n\t\t\t{\n\t\t\t\tans=arr[mid];\n\t\t\t\tstart=mid+1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tend=mid-1;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\treturn ans;\n\t\t\n\t}\n\t\n\t\n\tpublic static long upperBound(long[] arr,long k)\n\t{\n\t\tlong ans=-1;\n\t\t\n\t\tint start=0;\n\t\tint end=arr.length-1;\n\t\t\n\t\twhile(start<=end)\n\t\t{\n\t\t\tint mid=(start+end)/2;\n\t\t\t\n\t\t\tif(arr[mid]>=k)\n\t\t\t{\n\t\t\t\tans=arr[mid];\n\t\t\t\tend=mid-1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tstart=mid+1;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\treturn ans;\n\t}\n\t\n\t\n\tpublic static int upperBound(int[] arr,int k)\n\t{\n\t\tint ans=-1;\n\t\t\n\t\tint start=0;\n\t\tint end=arr.length-1;\n\t\t\n\t\twhile(start<=end)\n\t\t{\n\t\t\tint mid=(start+end)/2;\n\t\t\t\n\t\t\tif(arr[mid]>=k)\n\t\t\t{\n\t\t\t\tans=arr[mid];\n\t\t\t\tend=mid-1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tstart=mid+1;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\treturn ans;\n\t}\n\t\n\n//////////////////////////////////////////////////////////////////////////////////////////\n\npublic static void printArray(int[] arr)\n{\n for(int i = 0 ; i < arr.length ; i++)\n {\n out.print(arr[i] +\" \") ;\n }\n out.println() ;\n}\n\n\npublic static void printArray(long[] arr)\n{\n for(int i = 0 ; i < arr.length ; i++)\n {\n out.print(arr[i] +\" \") ;\n }\n out.println() ;\n}\n\n\n/////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////\n\nstatic ArrayList<Integer>[] tree ;\nstatic long[] child;\nstatic int mod= 1000000007 ;\nstatic int[][] pre = new int[3001][3001];\nstatic int[][] suf = new int[3001][3001] ;\n\n//program to calculate noof nodes in subtree for every vertex including itself \n\n// static void dfs(int sv)\n// {\n// child[sv] = 1L; \n \n \n// for(Integer x : tree[sv])\n// {\n// if(child[x] == 0)\n// {\n \n// dfs(x) ;\n \n// child[sv] += child[x] ;\n// }\n// }\n// }\n\n\n/////////////////////////////////////////////////////////////////////////////////////////////////\n/////////////////////////////////////////////////////////////////////////////////////////////\n//////////////////////////////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////////////////////////////////\n\npublic static void solve()\n{\nFastReader scn = new FastReader() ;\n\n//int[] store = {2 ,3, 5 , 7 ,11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 } ;\n\n// product of first 11 prime nos is gre ater than 10 ^ 12;\n\nArrayList<Integer> list = new ArrayList<>() ;\nArrayList<Long> listl = new ArrayList<>() ;\n//ArrayList<Integer> lista = new ArrayList<>() ;\n//ArrayList<Integer> listb = new ArrayList<>() ;\n//ArrayList<String> lists = new ArrayList<>() ;\n\nHashMap<Integer,Integer> map = new HashMap<>() ;\n//HashMap<Long,Long> map = new HashMap<>() ;\nHashMap<Integer,Integer> map1 = new HashMap<>() ;\nHashMap<Integer,Integer> map2 = new HashMap<>() ;\n//HashMap<String,Integer> maps = new HashMap<>() ;\n//HashMap<Integer,Boolean> mapb = new HashMap<>() ;\n//HashMap<Point,Integer> point = new HashMap<>() ; \n\n Set<Integer> set = new HashSet<>() ;\n Set<Integer> setx = new HashSet<>() ;\n Set<Integer> sety = new HashSet<>() ;\n\nStringBuilder sb =new StringBuilder(\"\") ;\n\n//Collections.sort(list);\n\n//if(map.containsKey(arr[i]))map.put(arr[i] , map.get(arr[i]) +1 ) ;\n//else map.put(arr[i],1) ;\n\n// if(map.containsKey(temp))map.put(temp , map.get(temp) +1 ) ;\n// else map.put(temp,1) ;\n\n//int bit =Integer.bitCount(n);\n// gives total no of set bits in n;\n\n// Arrays.sort(arr, new Comparator<Pair>() {\n// \t\t\t@Override\n// \t\t\tpublic int compare(Pair a, Pair b) {\n// \t\t\t\tif (a.first != b.first) {\n// \t\t\t\t\treturn a.first - b.first; // for increasing order of first\n// \t\t\t\t}\n// \t\t\t\treturn a.second - b.second ; //if first is same then sort on second basis\n// \t\t\t}\n// \t\t});\n\n\n\nint testcase = 1; \n\n // testcase = scn.nextInt() ;\n\nwhile(testcase-- > 0)\n{\n \n //if(map.containsKey(arr[i]))map.put(arr[i],map.get(arr[i])+1) ;else map.put(arr[i],1) ;\n //if(map.containsKey(temp))map.put(temp,map.get(temp)+1) ;else map.put(temp,1) ;\n \n// tree = new ArrayList[n] ;\n\n// child = new long[n] ;\n\n// for(int i = 0; i< n; i++)\n// {\n// tree[i] = new ArrayList<Integer>();\n// }\n//long[] arr = new long[n] ;for(int i = 0 ; i < n ;i++)arr[i] = scn.nextLong() ;\n//int[] arr = new int[n] ; for(int i = 0 ; i < n ;i++)arr[i] = scn.nextInt() ;\n \n // int n = scn.nextInt() ; \n // int m = scn.nextInt() ; int k = scn.nextInt() ;\n // int a = scn.nextInt() ; int b = scn.nextInt() ;\n // long n = scn.nextLong() ;// long b = scn.nextLong() ; long n = scn.nextLong() ;\n \n \nlong[] arr = new long[6] ;\n for(int i = 0 ; i< 6 ; i++)arr[i] = scn.nextLong() ;\n \n long triarea = (arr[0]+arr[1]+arr[2])*(arr[0]+arr[1]+arr[2]) ;\n \n long ans = triarea - arr[0]*arr[0] -arr[2]*arr[2] -arr[4]*arr[4] ;\n \n out.println(ans) ;\n \n \n \n \n \n \n \n \n \n \n \n \n//out.println(ans) ;\n\n\n//out.println(ans) ;\n\n//out.println() ;\n\n//for(int i = 0; i < n; i++)out.print(arr[i]+ \" \") ;\n\n// for(int i = 0; i < arr.length ; i++)\n// {\n// for(int j = 0; j < arr[0].length ; j ++)\n// {\n// out.print(arr[i][j] +\" \");\n// }\n// out.println() ;\n// }\n\n\n\nsb.delete(0 , sb.length()) ;\nlist.clear() ;\nmap.clear() ;\nmap1.clear() ;\nmap2.clear() ;\nset.clear() ;\n\n} // test case end loop\n\n\nout.flush() ; \n} // solve fn ends\n\n\npublic static void main (String[] args) throws java.lang.Exception\n{\n \n\nsolve() ;\n \n}\n\n\n}\n \n class Pair \n{\n int first ;\n \n int second ;\n \n \n \n \n \n@Override\n\tpublic String toString() {\n\t\n\tString ans = \"\" ;\n\tans += this.first ;\n\tans += \" \";\n\tans += this.second ;\n\t\n\treturn ans ;\n\t}\n\n\n\n}\n\n\n", "src_uid": "382475475427f0e76c6b4ac6e7a02e21"} {"source_code": "//Educational Codeforces Round 22\nimport java.io.*;\nimport java.util.*;\n\npublic class TaskB {\n\n public static void main (String[] args) {\n Scanner sc = new Scanner(System.in);\n PrintWriter pw = new PrintWriter(System.out);\n\n long x = sc.nextLong();\n long y = sc.nextLong();\n long l = sc.nextLong();\n long r = sc.nextLong();\n long xx = 1;\n long mx = r / x;\n long my = r / y;\n TreeSet<Long> t = new TreeSet<Long>();\n while (true) {\n long yy = 1;\n long m = r - xx; \n while (true) {\n if (yy > m) break;\n t.add(xx+yy);\n if (yy > my) break; \n yy *= y;\n }\n if (xx > mx) break;\n xx *= x;\n }\n long mm = 0;\n if (l == r) {\n if (!t.contains(l)) {\n mm = 1;\n }\n } else {\n boolean cl = t.contains(l);\n boolean cr = t.contains(r);\n t.add(l);\n t.add(r); \n long p = 0;\n boolean f = true; \n for (Long q: t) {\n if (!f && l <= p && q <= r) {\n long d = q - p - 1;\n if (p == l && !cl) d++;\n if (q == r && !cr) d++;\n if (mm < d) mm = d;\n }\n f = false;\n p = q;\n }\n }\n pw.println(mm);\n pw.close();\n }\n}", "src_uid": "68ca8a8730db27ac2230f9fe9b120f5f"} {"source_code": "import java.util.Scanner;\nimport java.io.PrintStream;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.io.PrintWriter;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Bunyod Xalilov\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 TaskF solver = new TaskF();\n solver.solve(1, in, out);\n out.close();\n }\n}\n\nclass TaskF {\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n boolean[] prime = new boolean[1000001];\n Arrays.fill(prime, true);\n int n = (int) 1e6;\n for (int i = 2; i * i <= n; i++) {\n if (prime[i]) {\n for (int j = i * i; j <= n; j += i) {\n prime[j] = false;\n }\n }\n }\n int d = in.nextInt();\n for (int i = 2; i <= n; i++) {\n if (prime[i]) {\n int r = Integer.parseInt(new StringBuffer(i + \"\").reverse().toString());\n if (r != i && prime[r]) {\n d--;\n }\n if (d == 0) {\n System.out.println(i);\n return;\n }\n }\n }\n }\n}\n", "src_uid": "53879e79cccbacfa6586d40cf3436657"} {"source_code": "import static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.Math.max;\nimport static java.lang.System.arraycopy;\nimport static java.lang.System.exit;\nimport static java.util.Arrays.copyOf;\n\nimport 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.NoSuchElementException;\nimport java.util.StringTokenizer;\n\npublic class G {\n\n\tstatic class IntList {\n\n\t\tint data[] = new int[3];\n\t\tint size = 0;\n\n\t\tboolean isEmpty() {\n\t\t\treturn size == 0;\n\t\t}\n\n\t\tint size() {\n\t\t\treturn size;\n\t\t}\n\n\t\tint get(int index) {\n\t\t\tif (index < 0 || index >= size) {\n\t\t\t\tthrow new IndexOutOfBoundsException();\n\t\t\t}\n\t\t\treturn data[index];\n\t\t}\n\n\t\tvoid clear() {\n\t\t\tsize = 0;\n\t\t}\n\n\t\tvoid set(int index, int value) {\n\t\t\tif (index < 0 || index >= size) {\n\t\t\t\tthrow new IndexOutOfBoundsException();\n\t\t\t}\n\t\t\tdata[index] = value;\n\t\t}\n\n\t\tvoid expand() {\n\t\t\tif (size >= data.length) {\n\t\t\t\tdata = copyOf(data, (data.length << 1) + 1);\n\t\t\t}\n\t\t}\n\n\t\tvoid insert(int index, int value) {\n\t\t\tif (index < 0 || index > size) {\n\t\t\t\tthrow new IndexOutOfBoundsException();\n\t\t\t}\n\t\t\texpand();\n\t\t\tarraycopy(data, index, data, index + 1, size++ - index);\n\t\t\tdata[index] = value;\n\t\t}\n\n\t\tint delete(int index) {\n\t\t\tif (index < 0 || index >= size) {\n\t\t\t\tthrow new IndexOutOfBoundsException();\n\t\t\t}\n\t\t\tint value = data[index];\n\t\t\tarraycopy(data, index + 1, data, index, --size - index);\n\t\t\treturn value;\n\t\t}\n\n\t\tvoid push(int value) {\n\t\t\texpand();\n\t\t\tdata[size++] = value;\n\t\t}\n\n\t\tint pop() {\n\t\t\tif (size == 0) {\n\t\t\t\tthrow new NoSuchElementException();\n\t\t\t}\n\t\t\treturn data[--size];\n\t\t}\n\n\t\tvoid unshift(int value) {\n\t\t\texpand();\n\t\t\tarraycopy(data, 0, data, 1, size++);\n\t\t\tdata[0] = value;\n\t\t}\n\n\t\tint shift() {\n\t\t\tif (size == 0) {\n\t\t\t\tthrow new NoSuchElementException();\n\t\t\t}\n\t\t\tint value = data[0];\n\t\t\tarraycopy(data, 1, data, 0, --size);\n\t\t\treturn value;\n\t\t}\n\t}\n\n\tstatic class IntIntMap {\n\n\t\tstatic final int EMPTY = Integer.MIN_VALUE;\n\n\t\tint data[] = new int[4];\n\t\t{\n\t\t\tdata[0] = EMPTY;\n\t\t\tdata[2] = EMPTY;\n\t\t}\n\t\tint size = 0;\n\n\t\tboolean isEmpty() {\n\t\t\treturn size == 0;\n\t\t}\n\n\t\tint size() {\n\t\t\treturn size;\n\t\t}\n\n\t\tvoid clear() {\n\t\t\tfor (int i = 0; i < data.length; i += 2) {\n\t\t\t\tdata[i] = EMPTY;\n\t\t\t}\n\t\t\tsize = 0;\n\t\t}\n\n\t\tstatic int hash(int key) {\n\t\t\tint hash = key * 1000000007;\n\t\t\thash ^= hash >> 16;\n\t\t\thash ^= hash >> 24;\n\t\t\treturn hash;\n\t\t}\n\n\t\tboolean have(int key) {\n\t\t\tif (key == EMPTY) {\n\t\t\t\tthrow new IllegalArgumentException();\n\t\t\t}\n\t\t\tfor (int mask = data.length - 2, i = hash(key) & mask;; i = (i - 1) & mask) {\n\t\t\t\tint cur = data[i];\n\t\t\t\tif (cur == key) {\n\t\t\t\t\treturn true;\n\t\t\t\t} else if (cur == EMPTY) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint get(int key, int default_) {\n\t\t\tif (key == EMPTY) {\n\t\t\t\tthrow new IllegalArgumentException();\n\t\t\t}\n\t\t\tfor (int mask = data.length - 2, i = hash(key) & mask;; i = (i - 1) & mask) {\n\t\t\t\tint cur = data[i];\n\t\t\t\tif (cur == key) {\n\t\t\t\t\treturn data[i + 1];\n\t\t\t\t} else if (cur == EMPTY) {\n\t\t\t\t\treturn default_;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tstatic int[] resize(int data[], int newCapacity) {\n\t\t\tint oldCapacity = data.length;\n\t\t\tint ndata[] = new int[newCapacity];\n\t\t\tfor (int i = 0; i < newCapacity; i += 2) {\n\t\t\t\tndata[i] = EMPTY;\n\t\t\t}\n\t\t\tfor (int mask = newCapacity - 2, i = 0; i < oldCapacity; i += 2) {\n\t\t\t\tint cur = data[i];\n\t\t\t\tif (cur == EMPTY) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tfor (int j = hash(cur) & mask;; j = (j - 1) & mask) {\n\t\t\t\t\tif (ndata[j] == EMPTY) {\n\t\t\t\t\t\tndata[j] = cur;\n\t\t\t\t\t\tndata[j + 1] = data[i + 1];\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn ndata;\n\t\t}\n\n\t\tvoid set(int key, int value) {\n\t\t\tif (key == EMPTY) {\n\t\t\t\tthrow new IllegalArgumentException();\n\t\t\t}\n\t\t\tint data[] = this.data;\n\t\t\tfor (int capacity = data.length, mask = capacity - 2, i = hash(key) & mask;; i = (i - 1) & mask) {\n\t\t\t\tint cur = data[i];\n\t\t\t\tif (cur == key) {\n\t\t\t\t\tdata[i + 1] = value;\n\t\t\t\t\treturn;\n\t\t\t\t} else if (cur == EMPTY) {\n\t\t\t\t\tdata[i] = key;\n\t\t\t\t\tdata[i + 1] = value;\n\t\t\t\t\tif (++size > capacity >> 2) {\n\t\t\t\t\t\tthis.data = resize(data, capacity << 1);\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tvoid delete(int key) {\n\t\t\tif (key == EMPTY) {\n\t\t\t\tthrow new IllegalArgumentException();\n\t\t\t}\n\t\t\tint data[] = this.data;\n\t\t\tfor (int capacity = data.length, mask = capacity - 2, i = hash(key) & mask;; i = (i - 1) & mask) {\n\t\t\t\tint cur = data[i];\n\t\t\t\tif (cur == key) {\n\t\t\t\t\tfor (int j = i;;) {\n\t\t\t\t\t\tcur = data[j = (j - 1) & mask];\n\t\t\t\t\t\tif (cur == EMPTY) {\n\t\t\t\t\t\t\tdata[i] = EMPTY;\n\t\t\t\t\t\t\t--size;\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tint k = hash(cur) & mask;\n\t\t\t\t\t\tif ((k >= i) ^ (k < j) ^ (i < j)) {\n\t\t\t\t\t\t\tdata[i] = cur;\n\t\t\t\t\t\t\tdata[i + 1] = data[j + 1];\n\t\t\t\t\t\t\ti = j;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else if (cur == EMPTY) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tvoid expand(int newCapacity) {\n\t\t\tint data[] = this.data;\n\t\t\tint oldCapacity = data.length;\n\t\t\tif (oldCapacity >> 2 < newCapacity) {\n\t\t\t\tthis.data = resize(data, Integer.highestOneBit(newCapacity - 1) << 3);\n\t\t\t}\n\t\t}\n\n\t\tvoid shrink() {\n\t\t\tint data[] = this.data;\n\t\t\tint oldCapacity = data.length;\n\t\t\tif (oldCapacity > 4 && oldCapacity >> 3 >= size) {\n\t\t\t\tthis.data = resize(data, max(Integer.highestOneBit(size - 1) << 3, 4));\n\t\t\t}\n\t\t}\n\n\t\tstatic class Iterator {\n\n\t\t\tfinal int data[];\n\t\t\tint position = -2;\n\n\t\t\tIterator(int data[]) {\n\t\t\t\tthis.data = data;\n\t\t\t\tadvance();\n\t\t\t}\n\n\t\t\tboolean hasNext() {\n\t\t\t\treturn position < data.length;\n\t\t\t}\n\n\t\t\tint getKey() {\n\t\t\t\treturn data[position];\n\t\t\t}\n\n\t\t\tint getValue() {\n\t\t\t\treturn data[position + 1];\n\t\t\t}\n\n\t\t\tvoid advance() {\n\t\t\t\tdo {\n\t\t\t\t\tposition += 2;\n\t\t\t\t} while (position < data.length && data[position] == EMPTY);\n\t\t\t}\n\t\t}\n\n\t\tIterator iterator() {\n\t\t\treturn new Iterator(data);\n\t\t}\n\t}\n\n\tstatic final List<IntList> freeLists = new ArrayList<>();\n\n\tstatic IntList takeList() {\n\t\tif (freeLists.isEmpty()) {\n\t\t\treturn new IntList();\n\t\t} else {\n\t\t\treturn freeLists.remove(freeLists.size() - 1);\n\t\t}\n\t}\n\n\tstatic void putList(IntList list) {\n\t\tlist.clear();\n\t\tfreeLists.add(list);\n\t}\n\n\tstatic int n, m;\n\n\tstatic IntList solve(int from, int to) {\n\t\tIntList res;\n\t\tif (from + 1 == to) {\n\t\t\tres = takeList();\n\t\t\tres.push(from);\n\t\t\tif (from + m > n) {\n\t\t\t\tres.push(n - from);\n\t\t\t\tres.push(from - n);\n\t\t\t}\n\t\t\tres.push(m);\n\t\t\tif (from > m) {\n\t\t\t\tres.push(n - from);\n\t\t\t\tres.push(from);\n\t\t\t}\n\t\t\tres.push(-from);\n\t\t} else {\n\t\t\tint mid = (from + to) >> 1;\n\t\t\tIntList a = solve(from, mid), b = solve(mid, to);\n\t\t\tres = takeList();\n\t\t\tint aSize = a.size, bSize = b.size;\n\t\t\tint aData[] = a.data, bData[] = b.data;\n\t\t\tfor (int i = 0;; i += 2) {\n\t\t\t\tint bFrom = i == 0 ? 0 : bData[i - 1];\n\t\t\t\tint bTo = i == bSize - 1 ? n : bData[i + 1];\n\t\t\t\tint bShift = bData[i];\n\t\t\t\tint aFrom = bFrom + bShift;\n\t\t\t\tint aTo = bTo + bShift;\n\t\t\t\tint l = 0, r = aSize - 1;\n\t\t\t\twhile (l < r) {\n\t\t\t\t\tint m = (((l + r) >> 2) << 1) + 1;\n\t\t\t\t\tif (aData[m] <= aFrom) {\n\t\t\t\t\t\tl = m + 1;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tr = m - 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tint cur = l;\n\t\t\t\twhile (true) {\n\t\t\t\t\tres.push(bShift + aData[cur]);\n\t\t\t\t\t++cur;\n\t\t\t\t\tif (cur == aSize) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tint pos = aData[cur];\n\t\t\t\t\tif (pos >= aTo) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tres.push(pos - bShift);\n\t\t\t\t\t++cur;\n\t\t\t\t}\n\t\t\t\tif (i == bSize - 1) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tres.push(bTo);\n\t\t\t}\n\t\t\tputList(a);\n\t\t\tputList(b);\n\t\t}\n\t\treturn res;\n\t}\n\n\tstatic void solve() throws Exception {\n\t\tn = scanInt();\n\t\tm = scanInt();\n\t\tint s = scanInt() - 1;\n\t\tlong t = scanLong();\n\t\tfor (int ct = (int) (t % n); ct != 0; ct--) {\n\t\t\tif (s < m) {\n\t\t\t\ts += ct;\n\t\t\t\tif (s >= n) {\n\t\t\t\t\ts -= n;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\ts -= ct;\n\t\t\t\tif (s < 0) {\n\t\t\t\t\ts += n;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong cycles = t / n;\n\t\tif (cycles > 0) {\n\t\t\tIntList cycleSolve = solve(0, n);\n\t\t\tint csSize = cycleSolve.size, csData[] = cycleSolve.data;\n\t\t\tIntList cycleList = takeList();\n\t\t\tIntIntMap cycleMap = new IntIntMap();\n\t\t\tfor (int it = 0;; it++) {\n\t\t\t\tif (it == cycles) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tint prev = cycleMap.get(s, -1);\n\t\t\t\tif (prev >= 0) {\n\t\t\t\t\ts = cycleList.get(prev + (int) ((cycles - prev) % (it - prev)));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcycleList.push(s);\n\t\t\t\tcycleMap.set(s, it);\n\t\t\t\tint l = 0, r = csSize - 1;\n\t\t\t\twhile (l < r) {\n\t\t\t\t\tint m = (((l + r) >> 2) << 1) + 1;\n\t\t\t\t\tif (csData[m] <= s) {\n\t\t\t\t\t\tl = m + 1;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tr = m - 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ts += csData[l];\n\t\t\t}\n\t\t}\n\t\tout.print(s + 1);\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}", "src_uid": "e743242f0cc9e17619e1fe4935d9fbd0"} {"source_code": "import java.util.Scanner;\n\npublic class Straight_A {\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\n int sum = 0;\n for (int i = 0; i < n; i++) {\n int a = sc.nextInt();\n sum += a;\n }\n\n int c = 0;\n while (Math.round((double) sum / (n + c)) < k) {\n sum += k;\n c++;\n }\n System.out.println(c);\n\n }\n\n}\n\n", "src_uid": "f22267bf3fad0bf342ecf4c27ad3a900"} {"source_code": "//package april2021;\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 G {\r\n\tInputStream is;\r\n\tFastWriter out;\r\n\tString INPUT = \"10\\n\" +\r\n\t\t\t\"2 0 0 1 1\\n\" +\r\n\t\t\t\"1 1 1 2 1\\n\" +\r\n\t\t\t\"2 1 0 1 2\\n\" +\r\n\t\t\t\"1 1 0 1 1\\n\" +\r\n\t\t\t\"2 1 0 2 1\\n\" +\r\n\t\t\t\"1 1 1 2 1\\n\" +\r\n\t\t\t\"1 2 1 3 1\\n\" +\r\n\t\t\t\"2 0 0 1 1\\n\" +\r\n\t\t\t\"1 1 0 1 1\\n\" +\r\n\t\t\t\"1 1 2 2 2\\n\";\r\n\r\n\tint[][] es = {\r\n\t\t\t{1, 0, 0, 1, 0},\r\n\t\t\t{1, 1, 0, 2, 0},\r\n\t\t\t{2, 0, 0, 1, 1},\r\n\t\t\t{2, 1, 0, 1, 2},\r\n\t\t\t{1, 1, 0, 1, 1},\r\n\t\t\t{2, 1, 0, 2, 1},\r\n\t\t\t{2, 2, 0, 2, 2},\r\n\t\t\t{1, 2, 0, 2, 1},\r\n\t\t\t{1, 1, 0, 1, 1},\r\n\t\t\t{1, 2, 0, 1, 2},\r\n\r\n\t\t\t{1, 0, 1, 2, 0},\r\n\t\t\t{1, 1, 1, 3, 0},\r\n\t\t\t{2, 0, 1, 2, 1},\r\n\t\t\t{2, 1, 1, 2, 2},\r\n\t\t\t{1, 1, 1, 2, 1},\r\n\t\t\t{2, 1, 1, 3, 1},\r\n\t\t\t{2, 2, 1, 3, 2},\r\n\t\t\t{1, 2, 1, 3, 1},\r\n\t\t\t{1, 1, 1, 2, 1},\r\n\t\t\t{1, 2, 1, 2, 2},\r\n\t\t\t{1, 0, 2, 2, 1},\r\n\t\t\t{1, 1, 2, 3, 1},\r\n\t\t\t{1, 2, 1, 1, 3},\r\n\t\t\t{2, 0, 2, 2, 2},\r\n\t\t\t{2, 1, 2, 2, 3},\r\n\t\t\t{1, 1, 2, 2, 2}\r\n\t};\r\n\r\n\tvoid solve()\r\n\t{\r\n\t\tint n = ni();\r\n\t\tfor(int i = 0;i < n;i++){\r\n\t\t\tint[] a = na(5);\r\n\t\t\tfor(int j = 0;j < 26;j++){\r\n\t\t\t\tif(Arrays.equals(a, es[j])){\r\n\t\t\t\t\tout.print((char)('a'+j));\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tout.println();\r\n\t}\r\n\t\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 G().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<Integer> 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", "src_uid": "a3603f5ed0d8bdb7fe829342991b78e6"} {"source_code": "import java.io.BufferedReader;\n import java.io.IOException;\n import java.io.InputStreamReader;\n\npublic class Nastya_Studies_Informatics {\n public static long pow(long a,long n)\n {\n long mod=1000000007;\n a=a%mod;\n long res=1;\n while(n>0)\n {\n if((n&1)==1)\n res=((res%mod)*(a%mod))%mod;\n n=n>>1;\n a=((a%mod)*(a%mod))%mod;\n }\n return res%mod;\n }\n public static void main(String[] args) throws IOException {\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n String str[]=br.readLine().split(\" \");\n long a=Long.parseLong(str[0]);\n long k=Long.parseLong(str[1]);\n if(a>0) {\n long mod = 1000000007;\n long value = (((a % mod) * (pow(2, k ) % mod)) % mod) + ((((pow(2, k) % mod) *((a- 1)%mod)) % mod)+1)%mod;\n System.out.println(value%mod);\n }\n else System.out.println(\"0\");\n }\n}\n", "src_uid": "e0e017e8c8872fc1957242ace739464d"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class F2 {\n\n int mod = 1000000007;\n int[][] prob;\n\n public static int invInt(int a, int mod) {\n int res = 1;\n int b = mod - 2;\n while (b > 0) {\n if ((b & 1) != 0) {\n res = (int) ((long) res * a % mod);\n }\n a = (int) ((long) a * a % mod);\n b >>>= 1;\n }\n return res;\n }\n\n class State {\n BitSet bset;\n\n public State() {\n bset = new BitSet(128);\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 State state = (State) o;\n return bset.equals(state.bset);\n }\n\n @Override\n public int hashCode() {\n return Objects.hash(bset);\n }\n\n void add(int mask) {\n bset.set(mask);\n }\n }\n\n void solve() {\n int n = in.nextInt();\n int inv100 = invInt(100, mod);\n prob = new int[n][n];\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n prob[i][j] = (int) ((long) in.nextInt() * inv100 % mod);\n }\n }\n long time = System.currentTimeMillis();\n Map<State, Integer> ans = new HashMap<>();\n {\n State s = new State();\n s.add(0);\n ans.put(s, 1);\n }\n for (int left = 0; left < n; left++) {\n Map<State, Integer> newAns = new HashMap<>();\n for (int mask = 0; mask < 1 << n; mask++) {\n long mul = 1;\n for (int i = 0; i < n; i++) {\n if ((mask & (1 << i)) != 0) {\n mul = mul * prob[left][i] % mod;\n } else {\n mul = mul * (mod + 1 - prob[left][i]) % mod;\n }\n }\n\n for (Map.Entry<State, Integer> entry : ans.entrySet()) {\n int newProb = (int) (mul * entry.getValue() % mod);\n State newState = new State();\n BitSet bs = entry.getKey().bset;\n for (int ma = bs.nextSetBit(0); ma >= 0; ma = bs.nextSetBit(ma + 1)) {\n for (int i = 0; i < n; i++) {\n if ((mask & (1 << i)) != 0 && ((ma >> i) & 1) == 0) {\n newState.add(ma | (1 << i));\n }\n }\n }\n if (newState.bset.cardinality() == 0) {\n continue;\n }\n Integer cur = newAns.get(newState);\n if (cur == null) {\n newAns.put(newState, newProb);\n } else {\n newAns.put(newState, (newProb + cur) % mod);\n }\n }\n }\n ans = newAns;\n }\n out.println(ans.values().iterator().next());\n System.err.println(System.currentTimeMillis() - time);\n }\n\n FastScanner in;\n PrintWriter out;\n\n void run() {\n in = new FastScanner(System.in);\n out = new PrintWriter(System.out);\n\n solve();\n out.close();\n }\n\n class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(InputStream in) {\n br = new BufferedReader(new InputStreamReader(in));\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public boolean hasMoreTokens() {\n while (st == null || !st.hasMoreElements()) {\n String line = null;\n try {\n line = br.readLine();\n } catch (IOException e) {\n return false;\n }\n if (line == null) {\n return false;\n }\n st = new StringTokenizer(line);\n }\n return true;\n }\n\n public String next() {\n while (st == null || !st.hasMoreElements()) {\n String line = null;\n try {\n line = br.readLine();\n } catch (IOException e) {\n }\n st = new StringTokenizer(line);\n }\n return st.nextToken();\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 int[] nextIntArray(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 public long[] nextLongArray(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\n\n public static void main(String[] args) throws Exception {\n new F2().run();\n }\n}\n", "src_uid": "906d4e49566e63fddaf8eac7384c6284"} {"source_code": "import java.util.*;\nimport java.io.*;\npublic class TestClass \n{\n\tpublic static void main(String[] args) throws IOException\n\t{\n\t\tScanner sc=new Scanner(System.in);\n\t\tint a1=sc.nextInt();\n\t\tint b1=sc.nextInt();\n\t\tint c1=sc.nextInt();\n\t\tint a2=sc.nextInt();\n\t\tint b2=sc.nextInt();\n\t\tint c2=sc.nextInt();\n\t\t\n\t\tif(a1==0 && b1==0 && c1!=0)\n\t\t\tSystem.out.println(0);\n\t\telse if(a2==0 && b2==0 && c2!=0)\n\t\t\tSystem.out.println(0);\n\t\telse if( (a1*b2)!=(b1*a2) )\n\t\t\tSystem.out.println(\"1\");\n\t\telse if( (a1*b2)==(b1*a2) && (a1*c2)==(c1*a2) && (b1*c2==c1*b2) )\n\t\t\tSystem.out.println(\"-1\");\n\t\telse\n\t\t\tSystem.out.println(\"0\");\n\t}\n}", "src_uid": "c8e869cb17550e888733551c749f2e1a"} {"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<Point> byAngle = new Comparator<E.Point>() {\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\tstatic Comparator<Point> byAngleRev = new Comparator<E.Point>() {\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\t\t\n\t\tPoint[] a;\n\t\t\n\t\t{\n\t\t\ta = 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, false);\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 ((long) a[i].x * a[i + 1].y != (long) a[i].y * a[i + 1].x) {\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, byAngleRev, true);\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, byAngleRev);\n\t\t\t}\n\t\t}\n\n\t\tint ptr = 0;\n\n\t\tdown = 1;\n\t\twhile (down < n) {\n\t\t\tdown <<= 1;\n\t\t}\n\t\t\n\t\ttree = new int[2 * down - 1];\n\t\tArrays.fill(tree, Integer.MAX_VALUE);\n\t\t\n\t\tfor (int i = 0; i < q; i++) {\n\t\t\tif (qs[i][0] == 1) {\n\t\t\t\trootSet(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\trootSet(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\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\tif (isInside(px[qx], py[qy])) {\n\t\t\t\t\tout.println(\"NO\");\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\trootSet(treeXIdx[p1], Integer.MAX_VALUE);\n\t\t\t\trootSet(treeXIdx[p2], Integer.MAX_VALUE);\n\n\t\t\t\tout.println(rootGet(0, askX[qx] - 1) > qy ? \"YES\" : \"NO\");\n\n\t\t\t\trootSet(treeXIdx[p1], ys[p1]);\n\t\t\t\trootSet(treeXIdx[p2], ys[p2]);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tint[] tree;\n\tint down;\n\t\n\tvoid rootSet(int pos, int val) {\n\t\tpos += down - 1;\n\t\ttree[pos] = val;\n\t\twhile (pos > 0) {\n\t\t\tpos = (pos - 1) >> 1;\n\t\t\ttree[pos] = Math.min(tree[(pos << 1) + 1], tree[(pos << 1) + 2]);\n\t\t}\n\t}\n\t\n\tint rootGet(int from, int to) {\n\t\tfrom += down - 1;\n\t\tto += down - 1;\n\t\tint ret = Integer.MAX_VALUE;\n\t\twhile (from < to) {\n\t\t\tif ((from & 1) == 0) {\n\t\t\t\tret = Math.min(ret, tree[from]);\n\t\t\t\tfrom++;\n\t\t\t}\n\t\t\tif ((to & 1) == 1) {\n\t\t\t\tret = Math.min(ret, tree[to]);\n\t\t\t\tto--;\n\t\t\t}\n\t\t\tfrom = (from - 1) >> 1;\n\t\t\tto = (to - 1) >> 1;\n\t\t}\n\t\tif (from == to) {\n\t\t\tret = Math.min(ret, tree[from]);\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tboolean isInside(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<Point> cmp, boolean doSort) {\n\t\ta = a.clone();\n\t\tif (doSort) {\n\t\t\tArrays.sort(a, cmp);\n\t\t}\n\t\t\n\t\tint sz = 1;\n\t\tfor (int i = 1; i < a.length; i++) {\n\t\t\tif ((long) a[i].x * a[sz - 1].y != (long) a[i].y * a[sz - 1].x) {\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\tSystem.err.println((-1) >> 1);\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", "src_uid": "775761bcba74d78b833c295290a2195c"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n private IO io;\n \n public static void main(String[] args) throws IOException {\n new Main().run();\n }\n \n void init() throws IOException {\n io = new IO(System.getProperty(\"ONLINE_JUDGE\")!=null);\n }\n\n void run() throws IOException {\n init();\n solve();\n io.flush();\n }\n \n void solve() throws IOException{\n int n=io.nI(), x1=io.nI(), y1=io.nI(), x2=io.nI(), y2=io.nI(), l=0, r=0;\n if(Math.abs(x1-x2)==n)\n if(n+y1+y2>3*n-y1-y2)io.wln(3*n-y1-y2);else io.wln(n+y1+y2);else\n if(Math.abs(y1-y2)==n)if(n+x1+x2>3*n-x1-x2)io.wln(3*n-x1-x2);else io.wln(n+x1+x2);else\n io.wln(Math.abs(x2-x1)+Math.abs(y2-y1));\n }\n \n @SuppressWarnings(\"unused\")\n private class IO{\n StreamTokenizer in; PrintWriter out; BufferedReader br; Reader reader; Writer writer;\n public IO(boolean oj) throws IOException{\n Locale.setDefault(Locale.US);\n reader = oj ? new InputStreamReader(System.in) : new FileReader(\"input.txt\");\n writer = oj ? new OutputStreamWriter(System.out) : new FileWriter(\"output.txt\");\n br = new BufferedReader(reader);\n in = new StreamTokenizer(br);\n out = new PrintWriter(writer);\n }\n public void wln(){out.println();}\n public void wln(int arg){out.println(arg);}\n public void wln(long arg){out.println(arg);}\n public void wln(double arg){out.println(arg);}\n public void wln(String arg){out.println(arg);}\n public void wln(boolean arg){out.println(arg);}\n public void wln(char arg){out.println(arg);}\n public void wln(float arg){out.println(arg);}\n public void wln(Object arg){out.println(arg);}\n public void w(int arg){out.print(arg);}\n public void w(long arg){out.print(arg);}\n public void w(double arg){out.print(arg);}\n public void w(String arg){out.print(arg);}\n public void w(boolean arg){out.print(arg);}\n public void w(char arg){out.print(arg);}\n public void w(float arg){out.print(arg);}\n public void w(Object arg){out.print(arg);}\n public void wf(String format, Object...args){out.printf(format, args);}\n public void flush(){out.flush();}\n public int nI() throws IOException {in.nextToken(); return(int)in.nval;}\n public long nL() throws IOException {in.nextToken(); return(long)in.nval;}\n public String nS() throws IOException {in.nextToken(); return in.sval;}\n public double nD() throws IOException {in.nextToken(); return in.nval;}\n public float nF() throws IOException {in.nextToken(); return (float)in.nval;}\n }\n}", "src_uid": "685fe16c217b5b71eafdb4198822250e"} {"source_code": "public class cf207d4 {\n public static void main(String[] args) {\n System.out.println(3);\n }\n}", "src_uid": "d163975cdad000ce89ee251ef9129779"} {"source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n\n\n\n public static void main(String[] args) {\n\n InputReader in = new InputReader(System.in);\n OutputWriter out = new OutputWriter(System.out);\n int y = in.nextInt();\n int p = in.nextInt();\n boolean h = true;\n for (int i =p;i>y;i--)\n {\n if (getFactor(i)>y)\n {\n h= false;\n out.printLine(i);\n break;\n }\n }\n if (h)\n out.printLine(-1);\n out.flush();\n\n }\n static int getFactor(int a)\n {\n\n for (int i=2;i<=Math.sqrt(a);i++)\n if (a%i==0)\n return i;\n return a;\n }\n\n}\n\n\nclass Graph {\n\n\n int n;\n LinkedList<Integer>[] adjList;\n\n public Graph(int n) {\n this.n = n;\n adjList = new LinkedList[n];\n for (int i = 0; i < n; i++)\n adjList[i] = new LinkedList<>();\n }\n\n}\n\n\nclass InputReader {\n\n private final InputStream stream;\n private final byte[] buf = new byte[8192];\n private int curChar, snumChars;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (snumChars == -1)\n throw new InputMismatchException();\n if (curChar >= snumChars) {\n curChar = 0;\n try {\n snumChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (snumChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public long nextLong() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public int[] nextIntArray(int n) {\n int a[] = new int[n];\n for (int i = 0; i < n; i++) {\n a[i] = nextInt();\n }\n return a;\n }\n\n public String readString() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public String nextLine() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isEndOfLine(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n private boolean isEndOfLine(int c) {\n return c == '\\n' || c == '\\r' || c == -1;\n }\n\n}\n\nclass OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void print(Object... objects) {\n for (int i = 0; i < objects.length; i++) {\n if (i != 0)\n writer.print(' ');\n writer.print(objects[i]);\n }\n }\n\n public void printLine(Object... objects) {\n print(objects);\n writer.println();\n }\n\n public void close() {\n writer.close();\n }\n\n public void flush() {\n writer.flush();\n }\n\n}", "src_uid": "b533203f488fa4caf105f3f46dd5844d"} {"source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.util.Arrays;\nimport java.util.Deque;\nimport java.util.function.Supplier;\nimport java.io.OutputStreamWriter;\nimport java.math.BigInteger;\nimport java.io.OutputStream;\nimport java.util.Collection;\nimport java.io.IOException;\nimport java.io.UncheckedIOException;\nimport java.util.function.Consumer;\nimport java.io.Closeable;\nimport java.io.Writer;\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 FastOutput out = new FastOutput(outputStream);\n ETransformingSequence solver = new ETransformingSequence();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class ETransformingSequence {\n int mod = (int) 1e9 + 7;\n IntPoly poly = new IntPolyFFT(mod);\n Factorial fact = new Factorial((int) 1e5, mod);\n CachedPow pow = new CachedPow(2, mod);\n Combination comb = new Combination(fact);\n\n public void solve(int testNumber, FastInput in, FastOutput out) {\n long n = in.readLong();\n int k = in.readInt();\n if (n > k) {\n out.println(0);\n return;\n }\n\n int[] x = new int[k + 1];\n Arrays.fill(x, 1, k + 1, 1);\n int[] ans = pow(x, (int) n);\n long sum = 0;\n for (int i = 0; i <= k; i++) {\n sum += (long) ans[i] * comb.combination(k, i) % mod;\n }\n sum %= mod;\n out.println(sum);\n }\n\n public int[] mul(int[] dpL, int[] dpR, int l, int r) {\n int n = dpL.length;\n int[] f = PrimitiveBuffers.allocIntPow2(n);\n int[] g = PrimitiveBuffers.allocIntPow2(n);\n for (int i = 0; i < n; i++) {\n f[i] = (int) ((long) dpL[i] * fact.invFact(i) % mod * pow.pow((long) r * i) % mod);\n g[i] = (int) ((long) dpR[i] * fact.invFact(i) % mod);\n }\n int[] ans = poly.convolution(f, g);\n int[] ret = Arrays.copyOf(ans, n);\n for (int i = 0; i < n; i++) {\n ret[i] = (int) ((long) ret[i] * fact.fact(i) % mod);\n }\n PrimitiveBuffers.release(f, g, ans);\n return ret;\n }\n\n public int[] pow(int[] x, int n) {\n if (n == 0) {\n int[] ans = new int[x.length];\n ans[0] = 1;\n return ans;\n }\n int[] ans = pow(x, n / 2);\n ans = mul(ans, ans, n / 2, n / 2);\n if (n % 2 == 1) {\n ans = mul(ans, x, n - 1, 1);\n }\n return ans;\n }\n\n }\n\n static class Log2 {\n public static int ceilLog(int x) {\n if (x <= 0) {\n return 0;\n }\n return 32 - Integer.numberOfLeadingZeros(x - 1);\n }\n\n }\n\n static class IntPoly {\n protected int mod;\n protected Power power;\n\n public IntPoly(int mod) {\n this.mod = mod;\n this.power = new Power(mod);\n }\n\n public int[] convolution(int[] a, int[] b) {\n return mulBF(a, b);\n }\n\n public int rankOf(int[] p) {\n int r = p.length - 1;\n while (r >= 0 && p[r] == 0) {\n r--;\n }\n return Math.max(0, r);\n }\n\n public int[] mulBF(int[] a, int[] b) {\n int rA = rankOf(a);\n int rB = rankOf(b);\n if (rA > rB) {\n {\n int tmp = rA;\n rA = rB;\n rB = tmp;\n }\n {\n int[] tmp = a;\n a = b;\n b = tmp;\n }\n }\n int[] c = PrimitiveBuffers.allocIntPow2(rA + rB + 1);\n for (int i = 0; i <= rA; i++) {\n for (int j = 0; j <= rB; j++) {\n c[i + j] = (int) ((c[i + j] + (long) a[i] * b[j]) % mod);\n }\n }\n return c;\n }\n\n }\n\n static class Factorial {\n int[] fact;\n int[] inv;\n int mod;\n\n public int getMod() {\n return mod;\n }\n\n public Factorial(int[] fact, int[] inv, int mod) {\n this.mod = mod;\n this.fact = fact;\n this.inv = inv;\n fact[0] = inv[0] = 1;\n int n = Math.min(fact.length, mod);\n for (int i = 1; i < n; i++) {\n fact[i] = i;\n fact[i] = (int) ((long) fact[i] * fact[i - 1] % mod);\n }\n inv[n - 1] = BigInteger.valueOf(fact[n - 1]).modInverse(BigInteger.valueOf(mod)).intValue();\n for (int i = n - 2; i >= 1; i--) {\n inv[i] = (int) ((long) inv[i + 1] * (i + 1) % mod);\n }\n }\n\n public Factorial(int limit, int mod) {\n this(new int[limit + 1], new int[limit + 1], mod);\n }\n\n public int fact(int n) {\n return fact[n];\n }\n\n public int invFact(int n) {\n return inv[n];\n }\n\n }\n\n static 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 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 DigitUtils {\n private DigitUtils() {\n }\n\n public static int mod(long x, int mod) {\n if (x < -mod || x >= mod) {\n x %= mod;\n }\n if (x < 0) {\n x += mod;\n }\n return (int) x;\n }\n\n public static int mod(int x, int mod) {\n if (x < -mod || x >= mod) {\n x %= mod;\n }\n if (x < 0) {\n x += mod;\n }\n return x;\n }\n\n }\n\n static class Power implements InverseNumber {\n int mod;\n\n public Power(Modular modular) {\n this.mod = modular.getMod();\n }\n\n public Power(int mod) {\n this(new Modular(mod));\n }\n\n }\n\n static interface IntCombination {\n }\n\n static class FastOutput implements AutoCloseable, Closeable, Appendable {\n private static final int THRESHOLD = 1 << 13;\n private final Writer os;\n private StringBuilder cache = new StringBuilder(THRESHOLD * 2);\n\n public FastOutput append(CharSequence csq) {\n cache.append(csq);\n return this;\n }\n\n public FastOutput append(CharSequence csq, int start, int end) {\n cache.append(csq, start, end);\n return this;\n }\n\n private void afterWrite() {\n if (cache.length() < THRESHOLD) {\n return;\n }\n flush();\n }\n\n public FastOutput(Writer os) {\n this.os = os;\n }\n\n public FastOutput(OutputStream os) {\n this(new OutputStreamWriter(os));\n }\n\n public FastOutput append(char c) {\n cache.append(c);\n afterWrite();\n return this;\n }\n\n public FastOutput append(int c) {\n cache.append(c);\n afterWrite();\n return this;\n }\n\n public FastOutput append(long c) {\n cache.append(c);\n afterWrite();\n return this;\n }\n\n public FastOutput append(String c) {\n cache.append(c);\n afterWrite();\n return this;\n }\n\n public FastOutput println(int c) {\n return append(c).println();\n }\n\n public FastOutput println(long c) {\n return append(c).println();\n }\n\n public FastOutput println() {\n return append(System.lineSeparator());\n }\n\n public FastOutput flush() {\n try {\n os.append(cache);\n os.flush();\n cache.setLength(0);\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n return this;\n }\n\n public void close() {\n flush();\n try {\n os.close();\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n public String toString() {\n return cache.toString();\n }\n\n }\n\n static class CachedPow {\n private int[] first;\n private int[] second;\n private int mod;\n private int powMod;\n private static int step = 16;\n private static int limit = 1 << step;\n private static int mask = limit - 1;\n\n public CachedPow(int x, int mod) {\n this.mod = mod;\n this.powMod = mod - 1;\n first = new int[limit];\n second = new int[Integer.MAX_VALUE / limit + 1];\n first[0] = 1;\n for (int i = 1; i < first.length; i++) {\n first[i] = (int) ((long) x * first[i - 1] % mod);\n }\n second[0] = 1;\n long step = (long) x * first[first.length - 1] % mod;\n for (int i = 1; i < second.length; i++) {\n second[i] = (int) (second[i - 1] * step % mod);\n }\n }\n\n public int pow(int exp) {\n return (int) ((long) first[exp & mask] * second[exp >> step] % mod);\n }\n\n public int pow(long exp) {\n return pow(DigitUtils.mod(exp, powMod));\n }\n\n }\n\n static class Combination implements IntCombination {\n final Factorial factorial;\n int modVal;\n\n public Combination(Factorial factorial) {\n this.factorial = factorial;\n this.modVal = factorial.getMod();\n }\n\n public Combination(int limit, int mod) {\n this(new Factorial(limit, mod));\n }\n\n public int combination(int m, int n) {\n if (n > m || n < 0) {\n return 0;\n }\n return (int) ((long) factorial.fact(m) * factorial.invFact(n) % modVal * factorial.invFact(m - n) % modVal);\n }\n\n }\n\n static class 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 String toString() {\n return \"mod \" + m;\n }\n\n }\n\n static class PrimitiveBuffers {\n public static Buffer<int[]>[] intPow2Bufs = new Buffer[30];\n public static Buffer<double[]>[] doublePow2Bufs = new Buffer[30];\n\n static {\n for (int i = 0; i < 30; i++) {\n int finalI = i;\n intPow2Bufs[i] = new Buffer<>(() -> new int[1 << finalI], x -> Arrays.fill(x, 0));\n doublePow2Bufs[i] = new Buffer<>(() -> new double[1 << finalI], x -> Arrays.fill(x, 0));\n }\n }\n\n public static int[] allocIntPow2(int n) {\n return intPow2Bufs[Log2.ceilLog(n)].alloc();\n }\n\n public static void release(int[] data) {\n intPow2Bufs[Log2.ceilLog(data.length)].release(data);\n }\n\n public static void release(int[] a, int[] b, int[] c) {\n release(a);\n release(b);\n release(c);\n }\n\n public static double[] allocDoublePow2(int n) {\n return doublePow2Bufs[Log2.ceilLog(n)].alloc();\n }\n\n public static double[] allocDoublePow2(double[] data, int newLen) {\n double[] ans = allocDoublePow2(newLen);\n System.arraycopy(data, 0, ans, 0, Math.min(data.length, newLen));\n return ans;\n }\n\n public static void release(double[] data) {\n doublePow2Bufs[Log2.ceilLog(data.length)].release(data);\n }\n\n public static void release(double[]... data) {\n for (double[] x : data) {\n release(x);\n }\n }\n\n }\n\n static interface InverseNumber {\n }\n\n static class FastFourierTransform {\n private static double[][] realLevels = new double[30][];\n private static double[][] imgLevels = new double[30][];\n\n private static void prepareLevel(int i) {\n if (realLevels[i] == null) {\n realLevels[i] = new double[1 << i];\n imgLevels[i] = new double[1 << i];\n for (int j = 0, s = 1 << i; j < s; j++) {\n realLevels[i][j] = Math.cos(Math.PI / s * j);\n imgLevels[i][j] = Math.sin(Math.PI / s * j);\n }\n }\n }\n\n public static void fft(double[][] p, boolean inv) {\n int m = Log2.ceilLog(p[0].length);\n int n = 1 << m;\n int shift = 32 - Integer.numberOfTrailingZeros(n);\n for (int i = 1; i < n; i++) {\n int j = Integer.reverse(i << shift);\n if (i < j) {\n SequenceUtils.swap(p[0], i, j);\n SequenceUtils.swap(p[1], i, j);\n }\n }\n\n double[][] t = new double[2][1];\n for (int d = 0; d < m; d++) {\n int s = 1 << d;\n int s2 = s << 1;\n prepareLevel(d);\n for (int i = 0; i < n; i += s2) {\n for (int j = 0; j < s; j++) {\n int a = i + j;\n int b = a + s;\n mul(realLevels[d][j], imgLevels[d][j], p[0][b], p[1][b], t, 0);\n sub(p[0][a], p[1][a], t[0][0], t[1][0], p, b);\n add(p[0][a], p[1][a], t[0][0], t[1][0], p, a);\n }\n }\n }\n\n if (inv) {\n for (int i = 0, j = 0; i <= j; i++, j = n - i) {\n double a = p[0][j];\n double b = p[1][j];\n div(p[0][i], p[1][i], n, p, j);\n if (i != j) {\n div(a, b, n, p, i);\n }\n }\n }\n }\n\n public static void add(double r1, double i1, double r2, double i2, double[][] r, int i) {\n r[0][i] = r1 + r2;\n r[1][i] = i1 + i2;\n }\n\n public static void sub(double r1, double i1, double r2, double i2, double[][] r, int i) {\n r[0][i] = r1 - r2;\n r[1][i] = i1 - i2;\n }\n\n public static void mul(double r1, double i1, double r2, double i2, double[][] r, int i) {\n r[0][i] = r1 * r2 - i1 * i2;\n r[1][i] = r1 * i2 + i1 * r2;\n }\n\n public static void div(double r1, double i1, double r2, double[][] r, int i) {\n r[0][i] = r1 / r2;\n r[1][i] = i1 / r2;\n }\n\n }\n\n static class SequenceUtils {\n public static void swap(double[] data, int i, int j) {\n double tmp = data[i];\n data[i] = data[j];\n data[j] = tmp;\n }\n\n }\n\n static class Buffer<T> {\n private Deque<T> deque;\n private Supplier<T> supplier;\n private Consumer<T> cleaner;\n private int allocTime;\n private int releaseTime;\n\n public Buffer(Supplier<T> supplier) {\n this(supplier, (x) -> {\n });\n }\n\n public Buffer(Supplier<T> supplier, Consumer<T> cleaner) {\n this(supplier, cleaner, 0);\n }\n\n public Buffer(Supplier<T> supplier, Consumer<T> cleaner, int exp) {\n this.supplier = supplier;\n this.cleaner = cleaner;\n deque = new ArrayDeque<>(exp);\n }\n\n public T alloc() {\n allocTime++;\n return deque.isEmpty() ? supplier.get() : deque.removeFirst();\n }\n\n public void release(T e) {\n releaseTime++;\n cleaner.accept(e);\n deque.addLast(e);\n }\n\n }\n\n static class IntPolyFFT extends IntPoly {\n private static final int FFT_THRESHOLD = 50;\n\n public IntPolyFFT(int mod) {\n super(mod);\n }\n\n public int[] convolution(int[] a, int[] b) {\n if (a != b) {\n return multiplyMod(a, b);\n } else {\n return pow2(a);\n }\n }\n\n public int[] pow2(int[] a) {\n int rA = rankOf(a);\n if (rA < FFT_THRESHOLD) {\n return mulBF(a, a);\n }\n\n int need = rA * 2 + 1;\n\n double[] aReal = PrimitiveBuffers.allocDoublePow2(need);\n double[] aImag = PrimitiveBuffers.allocDoublePow2(need);\n int n = aReal.length;\n\n for (int i = 0; i <= rA; i++) {\n int x = DigitUtils.mod(a[i], mod);\n aReal[i] = x & ((1 << 15) - 1);\n aImag[i] = x >> 15;\n }\n FastFourierTransform.fft(new double[][]{aReal, aImag}, false);\n\n double[] bReal = PrimitiveBuffers.allocDoublePow2(aReal, aReal.length);\n double[] bImag = PrimitiveBuffers.allocDoublePow2(aImag, bReal.length);\n\n\n for (int i = 0, j = 0; i <= j; i++, j = n - i) {\n double ari = aReal[i];\n double aii = aImag[i];\n double bri = bReal[i];\n double bii = bImag[i];\n double arj = aReal[j];\n double aij = aImag[j];\n double brj = bReal[j];\n double bij = bImag[j];\n\n double a1r = (ari + arj) / 2;\n double a1i = (aii - aij) / 2;\n double a2r = (aii + aij) / 2;\n double a2i = (arj - ari) / 2;\n\n double b1r = (bri + brj) / 2;\n double b1i = (bii - bij) / 2;\n double b2r = (bii + bij) / 2;\n double b2i = (brj - bri) / 2;\n\n aReal[i] = a1r * b1r - a1i * b1i - a2r * b2i - a2i * b2r;\n aImag[i] = a1r * b1i + a1i * b1r + a2r * b2r - a2i * b2i;\n bReal[i] = a1r * b2r - a1i * b2i + a2r * b1r - a2i * b1i;\n bImag[i] = a1r * b2i + a1i * b2r + a2r * b1i + a2i * b1r;\n\n if (i != j) {\n a1r = (arj + ari) / 2;\n a1i = (aij - aii) / 2;\n a2r = (aij + aii) / 2;\n a2i = (ari - arj) / 2;\n\n b1r = (brj + bri) / 2;\n b1i = (bij - bii) / 2;\n b2r = (bij + bii) / 2;\n b2i = (bri - brj) / 2;\n\n aReal[j] = a1r * b1r - a1i * b1i - a2r * b2i - a2i * b2r;\n aImag[j] = a1r * b1i + a1i * b1r + a2r * b2r - a2i * b2i;\n bReal[j] = a1r * b2r - a1i * b2i + a2r * b1r - a2i * b1i;\n bImag[j] = a1r * b2i + a1i * b2r + a2r * b1i + a2i * b1r;\n }\n }\n\n FastFourierTransform.fft(new double[][]{aReal, aImag}, true);\n FastFourierTransform.fft(new double[][]{bReal, bImag}, true);\n\n int[] ans = PrimitiveBuffers.allocIntPow2(need);\n for (int i = 0; i < need; i++) {\n long aa = DigitUtils.mod(Math.round(aReal[i]), mod);\n long bb = DigitUtils.mod(Math.round(bReal[i]), mod);\n long cc = DigitUtils.mod(Math.round(aImag[i]), mod);\n ans[i] = DigitUtils.mod(aa + (bb << 15) + (cc << 30), mod);\n }\n\n PrimitiveBuffers.release(aReal, bReal, aImag, bImag);\n return ans;\n }\n\n private int[] multiplyMod(int[] a, int[] b) {\n int rA = rankOf(a);\n int rB = rankOf(b);\n if (Math.min(rA, rB) < FFT_THRESHOLD) {\n return mulBF(a, b);\n }\n\n int need = rA + rB + 1;\n\n double[] aReal = PrimitiveBuffers.allocDoublePow2(need);\n double[] aImag = PrimitiveBuffers.allocDoublePow2(need);\n int n = aReal.length;\n\n for (int i = 0; i <= rA; i++) {\n int x = DigitUtils.mod(a[i], mod);\n aReal[i] = x & ((1 << 15) - 1);\n aImag[i] = x >> 15;\n }\n FastFourierTransform.fft(new double[][]{aReal, aImag}, false);\n\n double[] bReal = PrimitiveBuffers.allocDoublePow2(need);\n double[] bImag = PrimitiveBuffers.allocDoublePow2(need);\n for (int i = 0; i <= rB; i++) {\n int x = DigitUtils.mod(b[i], mod);\n bReal[i] = x & ((1 << 15) - 1);\n bImag[i] = x >> 15;\n }\n FastFourierTransform.fft(new double[][]{bReal, bImag}, false);\n\n\n for (int i = 0, j = 0; i <= j; i++, j = n - i) {\n double ari = aReal[i];\n double aii = aImag[i];\n double bri = bReal[i];\n double bii = bImag[i];\n double arj = aReal[j];\n double aij = aImag[j];\n double brj = bReal[j];\n double bij = bImag[j];\n\n double a1r = (ari + arj) / 2;\n double a1i = (aii - aij) / 2;\n double a2r = (aii + aij) / 2;\n double a2i = (arj - ari) / 2;\n\n double b1r = (bri + brj) / 2;\n double b1i = (bii - bij) / 2;\n double b2r = (bii + bij) / 2;\n double b2i = (brj - bri) / 2;\n\n aReal[i] = a1r * b1r - a1i * b1i - a2r * b2i - a2i * b2r;\n aImag[i] = a1r * b1i + a1i * b1r + a2r * b2r - a2i * b2i;\n bReal[i] = a1r * b2r - a1i * b2i + a2r * b1r - a2i * b1i;\n bImag[i] = a1r * b2i + a1i * b2r + a2r * b1i + a2i * b1r;\n\n if (i != j) {\n a1r = (arj + ari) / 2;\n a1i = (aij - aii) / 2;\n a2r = (aij + aii) / 2;\n a2i = (ari - arj) / 2;\n\n b1r = (brj + bri) / 2;\n b1i = (bij - bii) / 2;\n b2r = (bij + bii) / 2;\n b2i = (bri - brj) / 2;\n\n aReal[j] = a1r * b1r - a1i * b1i - a2r * b2i - a2i * b2r;\n aImag[j] = a1r * b1i + a1i * b1r + a2r * b2r - a2i * b2i;\n bReal[j] = a1r * b2r - a1i * b2i + a2r * b1r - a2i * b1i;\n bImag[j] = a1r * b2i + a1i * b2r + a2r * b1i + a2i * b1r;\n }\n }\n\n FastFourierTransform.fft(new double[][]{aReal, aImag}, true);\n FastFourierTransform.fft(new double[][]{bReal, bImag}, true);\n\n int[] ans = PrimitiveBuffers.allocIntPow2(need);\n for (int i = 0; i < need; i++) {\n long aa = DigitUtils.mod(Math.round(aReal[i]), mod);\n long bb = DigitUtils.mod(Math.round(bReal[i]), mod);\n long cc = DigitUtils.mod(Math.round(aImag[i]), mod);\n ans[i] = DigitUtils.mod(aa + (bb << 15) + (cc << 30), mod);\n }\n\n PrimitiveBuffers.release(aReal, bReal, aImag, bImag);\n return ans;\n }\n\n }\n}\n\n", "src_uid": "295baf6ccbfc3a7d098989a0701d2018"} {"source_code": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class PartyLemonade {\n InputStream is;\n PrintWriter pw;\n String INPUT = \"\";\n long L_INF = (1L << 60L);\n\n void solve() {\n long n = ni(), l = ni();\n long c[] = new long[(int) n];\n for (int i = 0; i < n; i++) {\n c[i] = ni();\n }\n for (int i = 1; i < n; i++) {\n c[i] = Math.min(c[i], 2 * c[i - 1]);\n }\n long cost = L_INF, sum = 0;\n for (long i = n - 1; i >= 0; i--) {\n long need = l / (1 << i);\n sum += need * c[(int) i];\n l -= need << i;\n cost = Math.min(cost, (l > 0 ? c[(int) i] : 0) + sum);\n }\n pw.println(cost);\n }\n\n void run() throws Exception {\n //\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n is = System.in;\n pw = new PrintWriter(System.out);\n\n long s = System.currentTimeMillis();\n// int t = ni();\n// while (t-- > 0)\n solve();\n pw.flush();\n tr(System.currentTimeMillis() - s + \"ms\");\n }\n\n public static void main(String[] args) throws Exception {\n new PartyLemonade().run();\n }\n\n private byte[] inbuf = new byte[1024];\n private int lenbuf = 0, ptrbuf = 0;\n\n private int readByte() {\n if (lenbuf == -1) throw new InputMismatchException();\n if (ptrbuf >= lenbuf) {\n ptrbuf = 0;\n try {\n lenbuf = is.read(inbuf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (lenbuf <= 0) return -1;\n }\n return inbuf[ptrbuf++];\n }\n\n private boolean isSpaceChar(int c) {\n return !(c >= 33 && c <= 126);\n }\n\n private int skip() {\n int b;\n while ((b = readByte()) != -1 && isSpaceChar(b)) ;\n return b;\n }\n\n private double nd() {\n return Double.parseDouble(ns());\n }\n\n private char nc() {\n return (char) skip();\n }\n\n private String ns() {\n int b = skip();\n StringBuilder sb = new StringBuilder();\n while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')\n sb.appendCodePoint(b);\n b = readByte();\n }\n return sb.toString();\n }\n\n private char[] ns(int n) {\n char[] buf = new char[n];\n int b = skip(), p = 0;\n while (p < n && !(isSpaceChar(b))) {\n buf[p++] = (char) b;\n b = readByte();\n }\n return n == p ? buf : Arrays.copyOf(buf, p);\n }\n\n private char[][] nm(int n, int m) {\n char[][] map = new char[n][];\n for (int i = 0; i < n; i++) map[i] = ns(m);\n return map;\n }\n\n private int[] na(int n) {\n int[] a = new int[n];\n for (int i = 0; i < n; i++) a[i] = ni();\n return a;\n }\n\n private int ni() {\n int num = 0, b;\n boolean minus = false;\n while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n\n while (true) {\n if (b >= '0' && b <= '9') {\n num = num * 10 + (b - '0');\n } else {\n return minus ? -num : num;\n }\n b = readByte();\n }\n }\n\n private long nl() {\n long num = 0;\n int b;\n boolean minus = false;\n while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n\n while (true) {\n if (b >= '0' && b <= '9') {\n num = num * 10 + (b - '0');\n } else {\n return minus ? -num : num;\n }\n b = readByte();\n }\n }\n\n private boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\n private void tr(Object... o) {\n if (!oj) System.out.println(Arrays.deepToString(o));\n }\n}\n", "src_uid": "04ca137d0383c03944e3ce1c502c635b"} {"source_code": "//package march;\n\nimport java.io.BufferedOutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.HashMap;\nimport java.util.InputMismatchException;\nimport java.util.Scanner;\n\npublic class codeforces {\n\tpublic static PrintWriter out;\n\tpublic static void main(String[] args) throws IOException {\n\t\tout = new PrintWriter(new BufferedOutputStream(System.out));\n\t\tScanner scnr=new Scanner(System.in);\n\t\t//Scan scnr=new Scan();\n\t\tString str=scnr.next();\n\t\tint ctr=0;\n\t\tHashMap<String,Integer> hm=new HashMap<>();\n\tfor(int i=0;i<str.length()+1;i++){\n\t\tstr=str.charAt(str.length()-1)+str.substring(0,str.length()-1);\n\t\tif(!hm.containsKey(str)){\n\t\t\thm.put(str, 1);\n\t\t\tctr++;\n\t\t}\n\t\telse{\n\t\t\t\n\t\t}\n\t\t\n\t}\n\tSystem.out.println(ctr);\n\t\t//m--;\n\t\n\t\t\n\t\tout.close();\n\t}\n\n}\nclass Scan {\n\tprivate byte[] buf = new byte[1024];\n\tprivate int index;\n\tprivate InputStream in;\n\tprivate int total;\n\n\tpublic Scan() {\n\t\tin = System.in;\n\t}\n\n\tpublic int scan() throws IOException {\n\t\tif (total < 0)\n\t\t\tthrow new InputMismatchException();\n\t\tif (index >= total) {\n\t\t\tindex = 0;\n\t\t\ttotal = in.read(buf);\n\t\t\tif (total <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[index++];\n\t}\n\n\tpublic int scanInt() throws IOException {\n\t\tint integer = 0;\n\t\tint n = scan();\n\t\twhile (isWhiteSpace(n))\n\t\t\tn = scan();\n\t\tint neg = 1;\n\t\tif (n == '-') {\n\t\t\tneg = -1;\n\t\t\tn = scan();\n\t\t}\n\t\twhile (!isWhiteSpace(n)) {\n\t\t\tif (n >= '0' && n <= '9') {\n\t\t\t\tinteger *= 10;\n\t\t\t\tinteger += n - '0';\n\t\t\t\tn = scan();\n\t\t\t} else\n\t\t\t\tthrow new InputMismatchException();\n\t\t}\n\t\treturn neg * integer;\n\t}\n\n\tpublic double scanDouble() throws IOException {\n\t\tdouble doub = 0;\n\t\tint n = scan();\n\t\twhile (isWhiteSpace(n))\n\t\t\tn = scan();\n\t\tint neg = 1;\n\t\tif (n == '-') {\n\t\t\tneg = -1;\n\t\t\tn = scan();\n\t\t}\n\t\twhile (!isWhiteSpace(n) && n != '.') {\n\t\t\tif (n >= '0' && n <= '9') {\n\t\t\t\tdoub *= 10;\n\t\t\t\tdoub += n - '0';\n\t\t\t\tn = scan();\n\t\t\t} else\n\t\t\t\tthrow new InputMismatchException();\n\t\t}\n\t\tif (n == '.') {\n\t\t\tn = scan();\n\t\t\tdouble temp = 1;\n\t\t\twhile (!isWhiteSpace(n)) {\n\t\t\t\tif (n >= '0' && n <= '9') {\n\t\t\t\t\ttemp /= 10;\n\t\t\t\t\tdoub += (n - '0') * temp;\n\t\t\t\t\tn = scan();\n\t\t\t\t} else\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t}\n\t\treturn doub * neg;\n\t}\n\n\tpublic String scanString() throws IOException {\n\t\tStringBuilder sb = new StringBuilder();\n\t\tint n = scan();\n\t\twhile (isWhiteSpace(n))\n\t\t\tn = scan();\n\t\twhile (!isWhiteSpace(n)) {\n\t\t\tsb.append((char) n);\n\t\t\tn = scan();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tprivate boolean isWhiteSpace(int n) {\n\t\tif (n == ' ' || n == '\\n' || n == '\\r' || n == '\\t' || n == -1)\n\t\t\treturn true;\n\t\treturn false;\n\t}\n}\n", "src_uid": "8909ac99ed4ab2ee4d681ec864c7831e"} {"source_code": "import java.util.Scanner;\n\npublic class TaskD {\n\n\tpublic static Scanner in = new Scanner(System.in);\n\n public static int MODUL = 1000000007;\n\n\tpublic static void main(String[] args) {\n\t int n = in.nextInt();\n\n int[][] c = new int[n + 1][];\n c[0] = new int[] { 1 };\n for (int i = 1; i <= n; i++) {\n c[i] = new int[i + 1];\n for (int j = 0; j <= i; j++) {\n if (j == 0 || j == i) {\n c[i][j] = 1;\n } else {\n c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % MODUL;\n }\n }\n }\n\n int[] dp = new int[n];\n dp[0] = 1;\n for (int j = 1; j < n; j++) {\n dp[j] = 0;\n for (int k = 0; k <= j - 1; k++) {\n dp[j] = (int)((dp[j] + (long)(c[j - 1][k]) * (long)(dp[j - k - 1])) % MODUL);\n }\n }\n\n int result = 0;\n for (int i = 0; i < n; i++) {\n result = (int)((result + (long)(c[n][i]) * (long)(dp[i])) % MODUL);\n }\n System.out.println(result);\n }\n\n}", "src_uid": "aa2c3e94a44053a0d86f61da06681023"} {"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 Toni Rajkovski\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastReader in = new FastReader(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, FastReader in, PrintWriter out) {\n int n = in.nextInt();\n int m = in.nextInt();\n\n int min = Math.min(n, m);\n int max = Math.max(n, m);\n\n if (min == 1) out.println(max);\n else if (min == 2) {\n if (max < 4) out.println(4);\n else if (max % 2 == 1) out.println(max + 1);\n else out.println((max + 3) / 4 * 4);\n } else if (m % 2 == 0 || n % 2 == 0) out.println(n * m / 2);\n else out.println((n * m + 1) / 2);\n }\n\n }\n\n static class FastReader {\n BufferedReader br;\n StringTokenizer st;\n\n public FastReader() {\n br = new BufferedReader(new\n InputStreamReader(System.in));\n }\n\n public FastReader(InputStream is) {\n br = new BufferedReader(new\n InputStreamReader(is));\n }\n\n public String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "src_uid": "e858e7f22d91aaadd7a48a174d7b2dc9"} {"source_code": "import java.util.Scanner;\n\npublic class VityaInTheCountrySide{\n\n\tpublic static void main(String[] args){\n\t\tScanner input = new Scanner(System.in);\n\t\tint n = input.nextInt();\n\t\tint a[] = new int[100];\n\t\t\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\ta[i] = input.nextInt();\n\t\t}\n\t\t\n\t\tif (a[n-1] == 15){ \n\t\t\tSystem.out.println(\"DOWN\");\n\t\t\t\n\t\t}else if (a[n-1] == 0){\n\t\t\t System.out.println(\"UP\");\n\t\t\t \n\t\t}else if (n == 1){\n\t\t\t System.out.println(\"-1\");\n\t\t\n\t\t}else if (a[n-2] > a[n-1]){\n\t\t\t System.out.println(\"DOWN\");\n\t\t\n\t\t}else{\n\t\t\t System.out.println(\"UP\");\n\t\t\n\t\tinput.close();\n\t}\n}\n}", "src_uid": "8330d9fea8d50a79741507b878da0a75"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\n\npublic class Main {\n public static void main(String[] args) throws NumberFormatException, IOException {\n BufferedReader in=new BufferedReader(new InputStreamReader(System.in));\n PrintWriter out=new PrintWriter(System.out);\n String[] s=in.readLine().split(\" \");\n long p=Long.parseLong(s[0]);\n long d=Long.parseLong(s[1]);\n long res=p;\n long min=p-d;\n long x=0;\n long y=0;\n for(int j=1; j<=s[0].length(); j++){\n long multi=(long)Math.pow(10, j);\n x=p/multi;\n y=x*multi+multi-1;\n if(y>p)\n y=(x-1)*multi+multi-1;\n if(y>=min)\n res=y;\n }\n out.println(res);\n \n out.close();\n }\n}\n", "src_uid": "c706cfcd4c37fbc1b1631aeeb2c02b6a"} {"source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.lang.*;\n \nimport static java.lang.Math.*;\n \npublic class Solution implements Runnable \n{\n\tstatic class InputReader \n\t{\n\t\tprivate InputStream stream;private byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n\t\tprivate SpaceCharFilter filter;\n\t\tprivate BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n public InputReader(InputStream stream){this.stream = stream;}\n\t\tpublic int read(){if (numChars==-1) throw new InputMismatchException();if (curChar >= numChars){curChar = 0;try{numChars = stream.read(buf);}catch (IOException e){throw new InputMismatchException();\t}if(numChars <= 0)return -1;}return buf[curChar++];}\n \tpublic String nextLine(){String str = \"\";try{str = br.readLine();}catch (IOException e){e.printStackTrace();}return str;}\n\t\tpublic int nextInt(){int c = read();\twhile(isSpaceChar(c))c = read();\tint sgn = 1; if (c == '-'){sgn = -1;c = read();\t}int res = 0;do{if(c<'0'||c>'9') throw new InputMismatchException();res *= 10;res += c - '0';c = read();}while (!isSpaceChar(c));return res * sgn;}\n public long nextLong(){int c = read();while (isSpaceChar(c))c = read();int sgn = 1;if (c == '-'){sgn = -1;c = read();}long res = 0;do{if (c < '0' || c > '9')throw new InputMismatchException();res *= 10;res += c - '0';c = read();}while (!isSpaceChar(c));return res * sgn;}\n\t\tpublic double nextDouble(){int c = read();while (isSpaceChar(c))c = read();int sgn = 1;if (c == '-'){sgn = -1;c = read();}double res = 0;while (!isSpaceChar(c) && c != '.'){if (c == 'e' || c == 'E')return res * Math.pow(10, nextInt());if (c < '0' || c > '9')\n\t\tthrow new InputMismatchException();res *= 10;res += c - '0';c = read();}if (c == '.'){c = read();double m = 1;while (!isSpaceChar(c)){if (c == 'e' || c == 'E')return res * Math.pow(10, nextInt());if (c < '0' || c > '9')throw new InputMismatchException();m /= 10;res += (c - '0') * m;c = read();}}return res * sgn;}\n public String readString(){int c = read();while (isSpaceChar(c))c = read();StringBuilder res = new StringBuilder();do{res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();}\n\t\tpublic boolean isSpaceChar(int c){if (filter != null)return filter.isSpaceChar(c);return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;}\n\t\tpublic String next(){return readString();}\n public interface SpaceCharFilter{public boolean isSpaceChar(int ch);}\n\t}\n\t\t\n\tpublic static void main(String args[]) throws Exception{new Thread(null, new Solution(),\"Main\",1<<27).start();}\n\n\tpublic static int gcd(int a, int b) { \tif (a == 0) return b; return gcd(b % a, a);} \n \n\tpublic static int findGCD(int arr[], int n) { \tint result = arr[0]; for (int i = 1; i < n; i++) result = gcd(arr[i], result);return result; }\t \n\t\n\tstatic void sortbycolomn(long arr[][], int col)\n { \n Arrays.sort(arr, new Comparator<long[]>() { \n @Override \n public int compare(final long[] entry1,final long[] entry2) { \n if (entry1[col] > entry2[col])return 1; \n else return -1; \n } \n }); \n }\n static long fii(int a,long[] fibo){\n if(fibo[a]!=0)\n return fibo[a];\n \n fibo[a]=(long)(fii(a-1,fibo)%1000000007 + fii(a-2,fibo)%1000000007);\n return fibo[a];\n }\n\tpublic void run()\n {\n InputReader in = new InputReader(System.in);\n PrintWriter w = new PrintWriter(System.out);\n\t\t\n int t=in.nextInt();\n while(t--!=0){\n int n=in.nextInt();\n int k=in.nextInt();\n int d=in.nextInt();\n int[] arr=new int[n];\n for(int i=0;i<n;i++) arr[i]=in.nextInt();\n //ArrayList<Integer> a=new ArrayList<>();\n if(d==1){\n w.println(\"1\");\n continue;\n }\n int count=0;\n int[] has=new int[k+1];\n for(int i=0;i<d;i++){\n if(has[arr[i]]==0){\n has[arr[i]]++;\n count++;\n //a.add(arr[i]);\n continue;\n }\n has[arr[i]]++;\n }\n int min=count;\n for(int i=1;i<=n-d;i++){\n if(has[arr[i-1]]==1){\n has[arr[i-1]]--;\n count--;\n //a.remove(new Integer(arr[i-1]));\n }\n else has[arr[i-1]]--;\n \n if(has[arr[i+d-1]]==0){\n has[arr[i+d-1]]++;\n count++;\n //a.add(arr[i+d-1]);\n }\n else has[arr[i+d-1]]++;\n \n min=Math.min(min,count);\n if(min==1)\n break;\n }\n w.println(min);\n }\n\t w.flush();\n w.close();\n }\n}", "src_uid": "56da4ec7cd849c4330d188d8c9bd6094"} {"source_code": "import java.util.*;\nimport java.io.*;\npublic class Kayaking{\n public static void main(String[]args) throws IOException\n {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter pw = new PrintWriter(System.out);\n int n = 2*Integer.parseInt(br.readLine());\n Integer[]weight = new Integer[n];\n StringTokenizer stk = new StringTokenizer(br.readLine());\n for(int i = 0; i < n; i ++)\n {\n weight[i] = Integer.parseInt(stk.nextToken());\n }\n Arrays.sort(weight);\n int ans = 10000000;\n for (int i = 0; i < n; i++) {\n for (int j = i+1; j < n ; j++) {\n Integer[] temp = Arrays.copyOf(weight, n);\n temp[i] = temp[j] = -1;\n Arrays.sort(temp);\n int sum = 0;\n for (int k = 1; 2*k+1 < n; k++) {\n sum+=temp[2*k+1] - temp[2*k];\n }\n ans = Math.min(sum, ans);\n }\n }\n pw.print(ans);\n pw.close();\n }\n}", "src_uid": "76659c0b7134416452585c391daadb16"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Random;\nimport java.util.StringTokenizer;\n\npublic class Solution{\n\t\n\tstatic final int maxn = 5005;\n\t\n public static void main(String[] args) {\n \n \tFastScanner fs = new FastScanner();\n \tPrintWriter out = new PrintWriter(System.out);\n \t\t\n \t\t\n \tint tt = 1;\n \twhile(tt-->0) {\n \t\t\t\n \t\tint n = fs.nextInt(), k = fs.nextInt(), m = fs.nextInt();\n \t\t\n \t\tint sum = 0;\n \t\tint[] a = new int[k];\n \t\tfor(int i=0;i<k;i++) {\n \t\t\ta[i] = fs.nextInt();\n \t\t\tsum += a[i];\n \t\t}\n \t\t\n \t\truffleSort(a);\n \t\t\n \t\tint lim = Math.min(n, m/sum);\n \t\t\n \t\tint max = 0;\n \t\t\n \t\tfor(int i=0;i<=lim;i++) {\n \t\t\tint cur = 0;\n \t\t\tcur += i*(k+1);\n \t\t\tint tleft = m - i*(sum);\n \t\t\tint nleft = n-i;\n \t\t\t\n \t\t\tfor(int j=0;j<k && tleft>0;j++) {\n \t\t\t\tint x = Math.min(nleft, tleft/a[j]);\n \t\t\t\tcur += x;\n \t\t\t\ttleft -= x*(a[j]);\n \t\t\t}\n \t\t\t\n \t\t\t\n \t\t\tmax = Math.max(max, cur);\n \t\t\t\n \t\t\t\n \t\t}\n \t\t\n \t\tout.println(max);\n \t\t\n \t}\n \t\t\n \tout.close();\n \t\t\n }\n \n \n \n \n \n \n \n \n static final Random random=new Random();\n \t\n static void ruffleSort(int[] a) {\n \tint n=a.length;//shuffle, then sort \n \tfor (int i=0; i<n; i++) {\n \t\tint oi=random.nextInt(n); int temp=a[oi];\n \t\ta[oi]=a[i]; a[i]=temp;\n \t}\n \tArrays.sort(a);\n }\n \n \n \n \t\n \t\n static class FastScanner{\n \tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n \tStringTokenizer st = new StringTokenizer(\"\");\n \n \tpublic String next(){\n \t\twhile(!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 \t\t\n \tpublic String nextLine() throws IOException {\n \t\treturn br.readLine();\n \t}\n \t\t\n \tpublic int nextInt(){\n \t\treturn Integer.parseInt(next());\n \t}\n \n \tpublic int[] readArray(int n){\n \t\tint[] a = new int[n];\n \t\tfor(int i=0;i<n;i++)\n \t\t\ta[i] = nextInt();\n \t\treturn a;\n \t}\n \t\t\n \tpublic long nextLong() {\n \t\treturn Long.parseLong(next());\n \t}\n \t\t\n \tpublic char nextChar() {\n \t\treturn next().toCharArray()[0];\n \t}\n }\n \t\n}", "src_uid": "d659e92a410c1bc836be64fc1c0db160"} {"source_code": "import java.util.*;\npublic class Program\n{\n public static void main(String[] args) {\n Scanner sc= new Scanner(System.in);\n \n String[] arr= new String[3];\n \n for(int i=0; i<3; i++) \n {\n arr[i]= sc.next();\n }\n \n String[] arr2 = new String[3];\n \n for(int i=0; i<3; i++){\n \n if(arr[i].contains(\"A\") && arr[i].contains(\"B\")) \n arr2[0]= arr[i];\nelse if(arr[i].contains(\"B\") && arr[i].contains(\"C\")) \n arr2[1]= arr[i];\nelse \n arr2[2]= arr[i];\n \n }\n \n \n if(arr2[0].equals(\"A<B\") || arr2[0].equals(\"B>A\")){\n \n if((arr2[1].equals(\"C<B\") || arr2[1].equals( \"B>C\")) && ((arr2[2].equals(\"C<A\") || arr2[2].equals(\"A>C\"))))\n System.out.println(\"CAB\");\n \n \n else if((arr2[1].equals(\"C<B\") || arr2[1].equals( \"B>C\")) && ((arr2[2].equals(\"C>A\")|| arr2[2].equals(\"A<C\"))))\n System.out.println(\"ACB\");\n \n \n else if((arr2[1].equals(\"C>B\") || arr2[1].equals(\"B<C\")) && ((arr2[2].equals(\"C>A\")|| arr2[2].equals(\"A<C\"))))\n System.out.println(\"ABC\");\n \n else \n System.out.println(\"Impossible\");\n }\n \n \n \n \n else if(arr2[0].equals(\"A>B\") || arr2[0].equals(\"B<A\")){\n \n if((arr2[1].equals(\"C<B\") || arr2[1].equals( \"B>C\")) && ((arr2[2].equals(\"C<A\")|| arr2[2].equals(\"A>C\"))))\n System.out.println(\"CBA\");\n \n \n else if((arr2[1].equals(\"C>B\") || arr2[1].equals( \"B<C\")) && ((arr2[2].equals(\"C<A\")|| arr2[2].equals(\"A>C\"))))\n System.out.println(\"BCA\");\n \n \n else if((arr2[1].equals(\"C>B\") || arr2[1].equals(\"B<C\")) && ((arr2[2].equals(\"C>A\")|| arr2[2].equals(\"A<C\"))))\n System.out.println(\"BAC\");\n \n else \n System.out.println(\"Impossible\");\n } \n }\n}", "src_uid": "97fd9123d0fb511da165b900afbde5dc"} {"source_code": "import java.util.*;\n\npublic class Solution \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\t\n\t\tint inch=n/3+(n%3==2?1:0);\n\t\tint feet=inch/12;\n\t\tinch=inch-feet*12;\n\t\t\n\t\tSystem.out.println(feet+\" \"+inch);\n\t}\n}", "src_uid": "5d4f38ffd1849862623325fdbe06cd00"} {"source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tOutputWriter out = new OutputWriter(outputStream);\n\t\tTask solver = new Task();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass Task {\n\n\tlong[][][] dp;\n\tlong[] pk, pm;\n\tint k, m, n;\n\t\n\tpublic void solve(int testNumber, InputReader in, OutputWriter out) {\n\t\tn=in.readInt();\n\t\tk=in.readInt();\n\t\tm=in.readInt();\n\t\tdp=new long[n+1][k][2];\n\t\tpk=IntegerUtils.generatePowers(10, n+1, k);\n\t\tpm=IntegerUtils.generatePowers(10, n+1, m);\n\t\tfor (long[][] i: dp) for (long[] j: i) Arrays.fill(j, -1);\n\t\tout.printLine(dp(0, 0, 0));\n\t}\n\t\n\tlong dp(int idx, int mod, int flag) {\n\t\tlong memo=dp[idx][mod][flag];\n\t\tif (memo!=-1) return memo;\n//\t\tSystem.out.println(idx+\" \"+mod+\" \"+flag);\n\t\tif (mod==0 && flag==1) return dp[idx][mod][flag]=(idx==n?1:pm[n-idx-1]*9%m);\n\t\tif (idx==n) return dp[idx][mod][flag]=0;\n\t\tmemo=0;\n\t\tfor (int i=0; i<10; i++) {\n\t\t\tmemo+=dp(idx+1, (int)((pk[idx]*i+mod)%k), flag|(i!=0?1:0));\n\t\t\tmemo%=m;\n\t\t}\n\t\treturn dp[idx][mod][flag]=memo;\n\t}\n}\n\nclass InputReader {\n\tprivate InputStream stream;\n\tprivate byte[] buf = new byte[1024];\n\tprivate int curChar;\n\tprivate int numChars;\n\tprivate SpaceCharFilter filter;\n\n\tpublic InputReader(InputStream stream) {\n\t\tthis.stream = stream;\n\t}\n\n\tpublic int read() {\n\t\tif (numChars == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (curChar >= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n\n\tpublic int peek() {\n\t\tif (numChars == -1)\n\t\t\treturn -1;\n\t\tif (curChar >= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar];\n\t}\n\n\tpublic int readInt() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tint res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tpublic long readLong() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tlong res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tpublic String readString() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tStringBuilder res = new StringBuilder();\n\t\tdo {\n\t\t\tif (Character.isValidCodePoint(c))\n\t\t\t\tres.appendCodePoint(c);\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res.toString();\n\t}\n\n\tpublic boolean isSpaceChar(int c) {\n\t\tif (filter != null)\n\t\t\treturn filter.isSpaceChar(c);\n\t\treturn isWhitespace(c);\n\t}\n\n\tpublic static boolean isWhitespace(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n\n\tprivate String readLine0() {\n\t\tStringBuilder buf = new StringBuilder();\n\t\tint c = read();\n\t\twhile (c != '\\n' && c != -1) {\n\t\t\tif (c != '\\r')\n\t\t\t\tbuf.appendCodePoint(c);\n\t\t\tc = read();\n\t\t}\n\t\treturn buf.toString();\n\t}\n\n\tpublic String readLine() {\n\t\tString s = readLine0();\n\t\twhile (s.trim().length() == 0)\n\t\t\ts = readLine0();\n\t\treturn s;\n\t}\n\n\tpublic String readLine(boolean ignoreEmptyLines) {\n\t\tif (ignoreEmptyLines)\n\t\t\treturn readLine();\n\t\telse\n\t\t\treturn readLine0();\n\t}\n\n\tpublic BigInteger readBigInteger() {\n\t\ttry {\n\t\t\treturn new BigInteger(readString());\n\t\t} catch (NumberFormatException e) {\n\t\t\tthrow new InputMismatchException();\n\t\t}\n\t}\n\n\tpublic char readCharacter() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\treturn (char) c;\n\t}\n\n\tpublic double readDouble() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tdouble res = 0;\n\t\twhile (!isSpaceChar(c) && c != '.') {\n\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\treturn res * Math.pow(10, readInt());\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t}\n\t\tif (c == '.') {\n\t\t\tc = read();\n\t\t\tdouble m = 1;\n\t\t\twhile (!isSpaceChar(c)) {\n\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\treturn res * Math.pow(10, readInt());\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tm /= 10;\n\t\t\t\tres += (c - '0') * m;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t}\n\t\treturn res * sgn;\n\t}\n\n\tpublic boolean isExhausted() {\n\t\tint value;\n\t\twhile (isSpaceChar(value = peek()) && value != -1)\n\t\t\tread();\n\t\treturn value == -1;\n\t}\n\n\tpublic String next() {\n\t\treturn readString();\n\t}\n\n\tpublic SpaceCharFilter getFilter() {\n\t\treturn filter;\n\t}\n\n\tpublic void setFilter(SpaceCharFilter filter) {\n\t\tthis.filter = filter;\n\t}\n\n\tpublic interface SpaceCharFilter {\n\t\tpublic boolean isSpaceChar(int ch);\n\t}\n}\n\nclass OutputWriter {\n\tprivate final PrintWriter writer;\n\n\tpublic OutputWriter(OutputStream outputStream) {\n\t\twriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(\n\t\t\t\toutputStream)));\n\t}\n\n\tpublic OutputWriter(Writer writer) {\n\t\tthis.writer = new PrintWriter(writer);\n\t}\n\n\tpublic void print(char[] array) {\n\t\twriter.print(array);\n\t}\n\n\tpublic void print(Object... objects) {\n\t\tfor (int i = 0; i < objects.length; i++) {\n\t\t\tif (i != 0)\n\t\t\t\twriter.print(' ');\n\t\t\twriter.print(objects[i]);\n\t\t}\n\t}\n\n\tpublic void print(int[] array) {\n\t\tfor (int i = 0; i < array.length; i++) {\n\t\t\tif (i != 0)\n\t\t\t\twriter.print(' ');\n\t\t\twriter.print(array[i]);\n\t\t}\n\t}\n\n\tpublic void print(long[] array) {\n\t\tfor (int i = 0; i < array.length; i++) {\n\t\t\tif (i != 0)\n\t\t\t\twriter.print(' ');\n\t\t\twriter.print(array[i]);\n\t\t}\n\t}\n\n\tpublic void printLine(int[] array) {\n\t\tprint(array);\n\t\twriter.println();\n\t}\n\n\tpublic void printLine(long[] array) {\n\t\tprint(array);\n\t\twriter.println();\n\t}\n\n\tpublic void printLine() {\n\t\twriter.println();\n\t}\n\n\tpublic void printLine(Object... objects) {\n\t\tprint(objects);\n\t\twriter.println();\n\t}\n\n\tpublic void print(char i) {\n\t\twriter.print(i);\n\t}\n\n\tpublic void printLine(char i) {\n\t\twriter.println(i);\n\t}\n\n\tpublic void printLine(char[] array) {\n\t\twriter.println(array);\n\t}\n\n\tpublic void printFormat(String format, Object... objects) {\n\t\twriter.printf(format, objects);\n\t}\n\n\tpublic void close() {\n\t\twriter.close();\n\t}\n\n\tpublic void flush() {\n\t\twriter.flush();\n\t}\n\n\tpublic void print(long i) {\n\t\twriter.print(i);\n\t}\n\n\tpublic void printLine(long i) {\n\t\twriter.println(i);\n\t}\n\n\tpublic void print(int i) {\n\t\twriter.print(i);\n\t}\n\n\tpublic void printLine(int i) {\n\t\twriter.println(i);\n\t}\n}\n\nclass IOUtils {\n\n\tpublic static int[] readIntArray(InputReader in, int size) {\n\t\tint[] array = new int[size];\n\t\tfor (int i = 0; i < size; i++)\n\t\t\tarray[i] = in.readInt();\n\t\treturn array;\n\t}\n\n\tpublic static long[] readLongArray(InputReader in, int size) {\n\t\tlong[] array = new long[size];\n\t\tfor (int i = 0; i < size; i++)\n\t\t\tarray[i] = in.readLong();\n\t\treturn array;\n\t}\n\n\tpublic static double[] readDoubleArray(InputReader in, int size) {\n\t\tdouble[] array = new double[size];\n\t\tfor (int i = 0; i < size; i++)\n\t\t\tarray[i] = in.readDouble();\n\t\treturn array;\n\t}\n\n\tpublic static String[] readStringArray(InputReader in, int size) {\n\t\tString[] array = new String[size];\n\t\tfor (int i = 0; i < size; i++)\n\t\t\tarray[i] = in.readString();\n\t\treturn array;\n\t}\n\n\tpublic static char[] readCharArray(InputReader in, int size) {\n\t\tchar[] array = new char[size];\n\t\tfor (int i = 0; i < size; i++)\n\t\t\tarray[i] = in.readCharacter();\n\t\treturn array;\n\t}\n\n\tpublic static void readIntArrays(InputReader in, int[]... arrays) {\n\t\tfor (int i = 0; i < arrays[0].length; i++) {\n\t\t\tfor (int j = 0; j < arrays.length; j++)\n\t\t\t\tarrays[j][i] = in.readInt();\n\t\t}\n\t}\n\n\tpublic static void readLongArrays(InputReader in, long[]... arrays) {\n\t\tfor (int i = 0; i < arrays[0].length; i++) {\n\t\t\tfor (int j = 0; j < arrays.length; j++)\n\t\t\t\tarrays[j][i] = in.readLong();\n\t\t}\n\t}\n\n\tpublic static void readDoubleArrays(InputReader in, double[]... arrays) {\n\t\tfor (int i = 0; i < arrays[0].length; i++) {\n\t\t\tfor (int j = 0; j < arrays.length; j++)\n\t\t\t\tarrays[j][i] = in.readDouble();\n\t\t}\n\t}\n\n\tpublic static char[][] readTable(InputReader in, int rowCount,\n\t\t\tint columnCount) {\n\t\tchar[][] table = new char[rowCount][];\n\t\tfor (int i = 0; i < rowCount; i++)\n\t\t\ttable[i] = readCharArray(in, columnCount);\n\t\treturn table;\n\t}\n\n\tpublic static int[][] readIntTable(InputReader in, int rowCount,\n\t\t\tint columnCount) {\n\t\tint[][] table = new int[rowCount][];\n\t\tfor (int i = 0; i < rowCount; i++)\n\t\t\ttable[i] = readIntArray(in, columnCount);\n\t\treturn table;\n\t}\n\n\tpublic static double[][] readDoubleTable(InputReader in, int rowCount,\n\t\t\tint columnCount) {\n\t\tdouble[][] table = new double[rowCount][];\n\t\tfor (int i = 0; i < rowCount; i++)\n\t\t\ttable[i] = readDoubleArray(in, columnCount);\n\t\treturn table;\n\t}\n\n\tpublic static long[][] readLongTable(InputReader in, int rowCount,\n\t\t\tint columnCount) {\n\t\tlong[][] table = new long[rowCount][];\n\t\tfor (int i = 0; i < rowCount; i++)\n\t\t\ttable[i] = readLongArray(in, columnCount);\n\t\treturn table;\n\t}\n\n\tpublic static String[][] readStringTable(InputReader in, int rowCount,\n\t\t\tint columnCount) {\n\t\tString[][] table = new String[rowCount][];\n\t\tfor (int i = 0; i < rowCount; i++)\n\t\t\ttable[i] = readStringArray(in, columnCount);\n\t\treturn table;\n\t}\n\n\tpublic static String readText(InputReader in) {\n\t\tStringBuilder result = new StringBuilder();\n\t\twhile (true) {\n\t\t\tint character = in.read();\n\t\t\tif (character == '\\r')\n\t\t\t\tcontinue;\n\t\t\tif (character == -1)\n\t\t\t\tbreak;\n\t\t\tresult.append((char) character);\n\t\t}\n\t\treturn result.toString();\n\t}\n\n\tpublic static void readStringArrays(InputReader in, String[]... arrays) {\n\t\tfor (int i = 0; i < arrays[0].length; i++) {\n\t\t\tfor (int j = 0; j < arrays.length; j++)\n\t\t\t\tarrays[j][i] = in.readString();\n\t\t}\n\t}\n\n\tpublic static void printTable(OutputWriter out, char[][] table) {\n\t\tfor (char[] row : table)\n\t\t\tout.printLine(new String(row));\n\t}\n}\n\nclass SumIntervalTree extends LongIntervalTree {\n\tpublic SumIntervalTree(int size) {\n\t\tsuper(size);\n\t}\n\n\t@Override\n\tprotected long joinValue(long left, long right) {\n\t\treturn left + right;\n\t}\n\n\t@Override\n\tprotected long joinDelta(long was, long delta) {\n\t\treturn was + delta;\n\t}\n\n\t@Override\n\tprotected long accumulate(long value, long delta, int length) {\n\t\treturn value + delta * length;\n\t}\n\n\t@Override\n\tprotected long neutralValue() {\n\t\treturn 0;\n\t}\n\n\t@Override\n\tprotected long neutralDelta() {\n\t\treturn 0;\n\t}\n}\n\nabstract class IntervalTree {\n\tprotected int size;\n\n\tprotected IntervalTree(int size) {\n\t\tthis(size, true);\n\t}\n\n\tpublic IntervalTree(int size, boolean shouldInit) {\n\t\tthis.size = size;\n\t\tint nodeCount = Math.max(1, Integer.highestOneBit(size) << 2);\n\t\tinitData(size, nodeCount);\n\t\tif (shouldInit)\n\t\t\tinit();\n\t}\n\n\tprotected abstract void initData(int size, int nodeCount);\n\n\tprotected abstract void initAfter(int root, int left, int right, int middle);\n\n\tprotected abstract void initBefore(int root, int left, int right, int middle);\n\n\tprotected abstract void initLeaf(int root, int index);\n\n\tprotected abstract void updatePostProcess(int root, int left, int right,\n\t\t\tint from, int to, long delta, int middle);\n\n\tprotected abstract void updatePreProcess(int root, int left, int right,\n\t\t\tint from, int to, long delta, int middle);\n\n\tprotected abstract void updateFull(int root, int left, int right, int from,\n\t\t\tint to, long delta);\n\n\tprotected abstract long queryPostProcess(int root, int left, int right,\n\t\t\tint from, int to, int middle, long leftResult, long rightResult);\n\n\tprotected abstract void queryPreProcess(int root, int left, int right,\n\t\t\tint from, int to, int middle);\n\n\tprotected abstract long queryFull(int root, int left, int right, int from,\n\t\t\tint to);\n\n\tprotected abstract long emptySegmentResult();\n\n\tpublic void init() {\n\t\tif (size == 0)\n\t\t\treturn;\n\t\tinit(0, 0, size - 1);\n\t}\n\n\tprivate void init(int root, int left, int right) {\n\t\tif (left == right) {\n\t\t\tinitLeaf(root, left);\n\t\t} else {\n\t\t\tint middle = (left + right) >> 1;\n\t\t\tinitBefore(root, left, right, middle);\n\t\t\tinit(2 * root + 1, left, middle);\n\t\t\tinit(2 * root + 2, middle + 1, right);\n\t\t\tinitAfter(root, left, right, middle);\n\t\t}\n\t}\n\n\tpublic void update(int from, int to, long delta) {\n\t\tupdate(0, 0, size - 1, from, to, delta);\n\t}\n\n\tprotected void update(int root, int left, int right, int from, int to,\n\t\t\tlong delta) {\n\t\tif (left > to || right < from)\n\t\t\treturn;\n\t\tif (left >= from && right <= to) {\n\t\t\tupdateFull(root, left, right, from, to, delta);\n\t\t\treturn;\n\t\t}\n\t\tint middle = (left + right) >> 1;\n\t\tupdatePreProcess(root, left, right, from, to, delta, middle);\n\t\tupdate(2 * root + 1, left, middle, from, to, delta);\n\t\tupdate(2 * root + 2, middle + 1, right, from, to, delta);\n\t\tupdatePostProcess(root, left, right, from, to, delta, middle);\n\t}\n\n\tpublic long query(int from, int to) {\n\t\treturn query(0, 0, size - 1, from, to);\n\t}\n\n\tprotected long query(int root, int left, int right, int from, int to) {\n\t\tif (left > to || right < from)\n\t\t\treturn emptySegmentResult();\n\t\tif (left >= from && right <= to)\n\t\t\treturn queryFull(root, left, right, from, to);\n\t\tint middle = (left + right) >> 1;\n\t\tqueryPreProcess(root, left, right, from, to, middle);\n\t\tlong leftResult = query(2 * root + 1, left, middle, from, to);\n\t\tlong rightResult = query(2 * root + 2, middle + 1, right, from, to);\n\t\treturn queryPostProcess(root, left, right, from, to, middle,\n\t\t\t\tleftResult, rightResult);\n\t}\n}\n\nabstract class LongIntervalTree extends IntervalTree {\n\tprotected long[] value;\n\tprotected long[] delta;\n\n\tprotected LongIntervalTree(int size) {\n\t\tthis(size, true);\n\t}\n\n\tpublic LongIntervalTree(int size, boolean shouldInit) {\n\t\tsuper(size, shouldInit);\n\t}\n\n\t@Override\n\tprotected void initData(int size, int nodeCount) {\n\t\tvalue = new long[nodeCount];\n\t\tdelta = new long[nodeCount];\n\t}\n\n\tprotected abstract long joinValue(long left, long right);\n\n\tprotected abstract long joinDelta(long was, long delta);\n\n\tprotected abstract long accumulate(long value, long delta, int length);\n\n\tprotected abstract long neutralValue();\n\n\tprotected abstract long neutralDelta();\n\n\tprotected long initValue(int index) {\n\t\treturn neutralValue();\n\t}\n\n\t@Override\n\tprotected void initAfter(int root, int left, int right, int middle) {\n\t\tvalue[root] = joinValue(value[2 * root + 1], value[2 * root + 2]);\n\t\tdelta[root] = neutralDelta();\n\t}\n\n\t@Override\n\tprotected void initBefore(int root, int left, int right, int middle) {\n\t}\n\n\t@Override\n\tprotected void initLeaf(int root, int index) {\n\t\tvalue[root] = initValue(index);\n\t\tdelta[root] = neutralDelta();\n\t}\n\n\t@Override\n\tprotected void updatePostProcess(int root, int left, int right, int from,\n\t\t\tint to, long delta, int middle) {\n\t\tvalue[root] = joinValue(value[2 * root + 1], value[2 * root + 2]);\n\t}\n\n\t@Override\n\tprotected void updatePreProcess(int root, int left, int right, int from,\n\t\t\tint to, long delta, int middle) {\n\t\tpushDown(root, left, middle, right);\n\t}\n\n\tprotected void pushDown(int root, int left, int middle, int right) {\n\t\tvalue[2 * root + 1] = accumulate(value[2 * root + 1], delta[root],\n\t\t\t\tmiddle - left + 1);\n\t\tvalue[2 * root + 2] = accumulate(value[2 * root + 2], delta[root],\n\t\t\t\tright - middle);\n\t\tdelta[2 * root + 1] = joinDelta(delta[2 * root + 1], delta[root]);\n\t\tdelta[2 * root + 2] = joinDelta(delta[2 * root + 2], delta[root]);\n\t\tdelta[root] = neutralDelta();\n\t}\n\n\t@Override\n\tprotected void updateFull(int root, int left, int right, int from, int to,\n\t\t\tlong delta) {\n\t\tvalue[root] = accumulate(value[root], delta, right - left + 1);\n\t\tthis.delta[root] = joinDelta(this.delta[root], delta);\n\t}\n\n\t@Override\n\tprotected long queryPostProcess(int root, int left, int right, int from,\n\t\t\tint to, int middle, long leftResult, long rightResult) {\n\t\treturn joinValue(leftResult, rightResult);\n\t}\n\n\t@Override\n\tprotected void queryPreProcess(int root, int left, int right, int from,\n\t\t\tint to, int middle) {\n\t\tpushDown(root, left, middle, right);\n\t}\n\n\t@Override\n\tprotected long queryFull(int root, int left, int right, int from, int to) {\n\t\treturn value[root];\n\t}\n\n\t@Override\n\tprotected long emptySegmentResult() {\n\t\treturn neutralValue();\n\t}\n}\n\nclass IntPair implements Comparable<IntPair> {\n\tpublic final int first, second;\n\n\tpublic IntPair(int first, int second) {\n\t\tthis.first = first;\n\t\tthis.second = second;\n\t}\n\n\t@Override\n\tpublic String toString() {\n\t\treturn \"(\" + first + \",\" + second + \")\";\n\t}\n\n\t@Override\n\tpublic boolean equals(Object o) {\n\t\tif (this == o)\n\t\t\treturn true;\n\t\tif (o == null || getClass() != o.getClass())\n\t\t\treturn false;\n\n\t\tIntPair intPair = (IntPair) o;\n\n\t\treturn first == intPair.first && second == intPair.second;\n\n\t}\n\n\t@Override\n\tpublic int hashCode() {\n\t\tint result = first;\n\t\tresult = 31 * result + second;\n\t\treturn result;\n\t}\n\n\tpublic int compareTo(IntPair o) {\n\t\tif (first < o.first)\n\t\t\treturn -1;\n\t\tif (first > o.first)\n\t\t\treturn 1;\n\t\tif (second < o.second)\n\t\t\treturn -1;\n\t\tif (second > o.second)\n\t\t\treturn 1;\n\t\treturn 0;\n\t}\n}\n\nclass Matrix {\n\tpublic static long mod = Long.MAX_VALUE;\n\tpublic final long[][] data;\n\tpublic final int rowCount;\n\tpublic final int columnCount;\n\n\tpublic Matrix(int rowCount, int columnCount) {\n\t\tthis.rowCount = rowCount;\n\t\tthis.columnCount = columnCount;\n\t\tthis.data = new long[rowCount][columnCount];\n\t}\n\n\tpublic Matrix(long[][] data) {\n\t\tthis.rowCount = data.length;\n\t\tthis.columnCount = data[0].length;\n\t\tthis.data = data;\n\t}\n\n\tpublic static Matrix add(Matrix first, Matrix second) {\n\t\tMatrix result = new Matrix(first.rowCount, first.columnCount);\n\t\tfor (int i = 0; i < result.rowCount; i++) {\n\t\t\tfor (int j = 0; j < result.columnCount; j++) {\n\t\t\t\tresult.data[i][j] = first.data[i][j] + second.data[i][j];\n\t\t\t\tif (result.data[i][j] >= mod)\n\t\t\t\t\tresult.data[i][j] -= mod;\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static Matrix multiply(Matrix first, Matrix second) {\n\t\tMatrix result = new Matrix(first.rowCount, second.columnCount);\n\t\tfor (int i = 0; i < first.rowCount; i++) {\n\t\t\tfor (int j = 0; j < second.rowCount; j++) {\n\t\t\t\tfor (int k = 0; k < second.columnCount; k++)\n\t\t\t\t\tresult.data[i][k] = (result.data[i][k] + first.data[i][j]\n\t\t\t\t\t\t\t* second.data[j][k])\n\t\t\t\t\t\t\t% mod;\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static Matrix fastMultiply(Matrix first, Matrix second) {\n\t\tMatrix result = new Matrix(first.rowCount, second.columnCount);\n\t\tfor (int i = 0; i < first.rowCount; i++) {\n\t\t\tfor (int j = 0; j < second.rowCount; j++) {\n\t\t\t\tfor (int k = 0; k < second.columnCount; k++)\n\t\t\t\t\tresult.data[i][k] += first.data[i][j] * second.data[j][k];\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < first.rowCount; i++) {\n\t\t\tfor (int j = 0; j < second.columnCount; j++)\n\t\t\t\tresult.data[i][j] %= mod;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static Matrix identityMatrix(int size) {\n\t\tMatrix result = new Matrix(size, size);\n\t\tfor (int i = 0; i < size; i++)\n\t\t\tresult.data[i][i] = 1;\n\t\treturn result;\n\t}\n\n\tpublic static long[] convert(long[][] matrix) {\n\t\tlong[] result = new long[matrix.length * matrix.length];\n\t\tfor (int i = 0; i < matrix.length; i++) {\n\t\t\tfor (int j = 0; j < matrix.length; j++)\n\t\t\t\tresult[i * matrix.length + j] = matrix[i][j];\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static long[] sumPowers(long[] matrix, long exponent, long mod,\n\t\t\tint side) {\n\t\tlong[] result = new long[matrix.length];\n\t\tlong[] power = new long[matrix.length];\n\t\tlong[] temp = new long[matrix.length];\n\t\tlong[] temp2 = new long[matrix.length];\n\t\tsumPowers(matrix, result, power, temp, temp2, exponent + 1, mod, side);\n\t\treturn result;\n\t}\n\n\tprivate static void sumPowers(long[] matrix, long[] result, long[] power,\n\t\t\tlong[] temp, long[] temp2, long exponent, long mod, int side) {\n\t\tif (exponent == 0) {\n\t\t\tfor (int i = 0; i < matrix.length; i += side + 1)\n\t\t\t\tpower[i] = 1 % mod;\n\t\t\treturn;\n\t\t}\n\t\tif ((exponent & 1) == 0) {\n\t\t\tsumPowers(matrix, result, temp, power, temp2, exponent >> 1, mod,\n\t\t\t\t\tside);\n\t\t\tmultiply(temp2, result, temp, mod, side);\n\t\t\tadd(result, temp2, mod, side);\n\t\t\tmultiply(power, temp, temp, mod, side);\n\t\t} else {\n\t\t\tsumPowers(matrix, result, temp, power, temp2, exponent - 1, mod,\n\t\t\t\t\tside);\n\t\t\tadd(result, temp, mod, side);\n\t\t\tmultiply(power, temp, matrix, mod, side);\n\t\t}\n\t}\n\n\tpublic static long[][] convert(long[] matrix, int side) {\n\t\tlong[][] result = new long[side][side];\n\t\tfor (int i = 0; i < side; i++) {\n\t\t\tfor (int j = 0; j < side; j++)\n\t\t\t\tresult[i][j] = matrix[i * side + j];\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static long[] power(long[] matrix, long exponent, long mod, int side) {\n\t\tlong[] result = new long[matrix.length];\n\t\tlong[] temp = new long[result.length];\n\t\tpower(matrix, result, temp, exponent, mod, side);\n\t\treturn result;\n\t}\n\n\tprivate static void power(long[] matrix, long[] result, long[] temp,\n\t\t\tlong exponent, long mod, int side) {\n\t\tif (exponent == 0) {\n\t\t\tfor (int i = 0; i < matrix.length; i += side + 1)\n\t\t\t\tresult[i] = 1 % mod;\n\t\t\treturn;\n\t\t}\n\t\tif ((exponent & 1) == 0) {\n\t\t\tpower(matrix, temp, result, exponent >> 1, mod, side);\n\t\t\tmultiply(result, temp, temp, mod, side);\n\t\t} else {\n\t\t\tpower(matrix, temp, result, exponent - 1, mod, side);\n\t\t\tmultiply(result, temp, matrix, mod, side);\n\t\t}\n\t}\n\n\tpublic static void multiply(long[] c, long[] a, long[] b, long mod, int side) {\n\t\tArrays.fill(c, 0);\n\t\tfor (int i = 0; i < side; i++) {\n\t\t\tfor (int j = 0; j < side; j++) {\n\t\t\t\tfor (int k = 0; k < side; k++) {\n\t\t\t\t\tc[i * side + k] += a[i * side + j] * b[j * side + k];\n\t\t\t\t\tif ((j & 3) == 3) {\n\t\t\t\t\t\tc[i * side + k] %= mod;\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 < c.length; i++)\n\t\t\tc[i] %= mod;\n\t}\n\n\tpublic static void add(long[] c, long[] a, long mod, int side) {\n\t\tfor (int i = 0; i < side; i++) {\n\t\t\tfor (int j = 0; j < side; j++) {\n\t\t\t\tc[i * side + j] += a[i * side + j];\n\t\t\t\tif (c[i * side + j] >= mod)\n\t\t\t\t\tc[i * side + j] -= mod;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static long[] fastPower(long[] matrix, long exponent, long mod,\n\t\t\tint side) {\n\t\tlong[] result = new long[matrix.length];\n\t\tlong[] temp = new long[result.length];\n\t\tfastPower(matrix, result, temp, exponent, mod, side);\n\t\treturn result;\n\t}\n\n\tprivate static void fastPower(long[] matrix, long[] result, long[] temp,\n\t\t\tlong exponent, long mod, int side) {\n\t\tif (exponent == 0) {\n\t\t\tfor (int i = 0; i < matrix.length; i += side + 1)\n\t\t\t\tresult[i] = 1;\n\t\t\treturn;\n\t\t}\n\t\tif ((exponent & 1) == 0) {\n\t\t\tfastPower(matrix, temp, result, exponent >> 1, mod, side);\n\t\t\tfastMultiply(result, temp, temp, mod, side);\n\t\t} else {\n\t\t\tpower(matrix, temp, result, exponent - 1, mod, side);\n\t\t\tfastMultiply(result, temp, matrix, mod, side);\n\t\t}\n\t}\n\n\tpublic static void fastMultiply(long[] c, long[] a, long[] b, long mod,\n\t\t\tint side) {\n\t\tArrays.fill(c, 0);\n\t\tfor (int i = 0; i < side; i++) {\n\t\t\tfor (int j = 0; j < side; j++) {\n\t\t\t\tfor (int k = 0; k < side; k++)\n\t\t\t\t\tc[i * side + k] += a[i * side + j] * b[j * side + k];\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < c.length; i++)\n\t\t\tc[i] %= mod;\n\t}\n\n\tpublic Matrix power(long exponent) {\n\t\tif (exponent == 0)\n\t\t\treturn identityMatrix(rowCount);\n\t\tif (exponent == 1)\n\t\t\treturn this;\n\t\tMatrix result = power(exponent >> 1);\n\t\tresult = multiply(result, result);\n\t\tif ((exponent & 1) == 1)\n\t\t\tresult = multiply(result, this);\n\t\treturn result;\n\t}\n\n\tpublic Matrix fastPower(long exponent) {\n\t\tif (exponent == 0)\n\t\t\treturn identityMatrix(rowCount);\n\t\tif (exponent == 1)\n\t\t\treturn this;\n\t\tMatrix result = power(exponent >> 1);\n\t\tresult = fastMultiply(result, result);\n\t\tif ((exponent & 1) == 1)\n\t\t\tresult = fastMultiply(result, this);\n\t\treturn result;\n\t}\n}\n\nclass MiscUtils {\n\tpublic static final int[] DX4 = { 1, 0, -1, 0 };\n\tpublic static final int[] DY4 = { 0, -1, 0, 1 };\n\tpublic static final int[] DX8 = { 1, 1, 1, 0, -1, -1, -1, 0 };\n\tpublic static final int[] DY8 = { -1, 0, 1, 1, 1, 0, -1, -1 };\n\tpublic static final int[] DX_KNIGHT = { 2, 1, -1, -2, -2, -1, 1, 2 };\n\tpublic static final int[] DY_KNIGHT = { 1, 2, 2, 1, -1, -2, -2, -1 };\n\n\tprivate static final String[] ROMAN_TOKENS = { \"M\", \"CM\", \"D\", \"CD\", \"C\",\n\t\t\t\"XC\", \"L\", \"XL\", \"X\", \"IX\", \"V\", \"IV\", \"I\" };\n\tprivate static final int[] ROMAN_VALUES = { 1000, 900, 500, 400, 100, 90,\n\t\t\t50, 40, 10, 9, 5, 4, 1 };\n\n\tpublic static long josephProblem(long n, int k) {\n\t\tif (n == 1)\n\t\t\treturn 0;\n\t\tif (k == 1)\n\t\t\treturn n - 1;\n\t\tif (k > n)\n\t\t\treturn (josephProblem(n - 1, k) + k) % n;\n\t\tlong count = n / k;\n\t\tlong result = josephProblem(n - count, k);\n\t\tresult -= n % k;\n\t\tif (result < 0)\n\t\t\tresult += n;\n\t\telse\n\t\t\tresult += result / (k - 1);\n\t\treturn result;\n\t}\n\n\tpublic static boolean isValidCell(int row, int column, int rowCount,\n\t\t\tint columnCount) {\n\t\treturn row >= 0 && row < rowCount && column >= 0\n\t\t\t\t&& column < columnCount;\n\t}\n\n\tpublic static long maximalRectangleSum(long[][] array) {\n\t\tint n = array.length;\n\t\tint m = array[0].length;\n\t\tlong[][] partialSums = new long[n + 1][m + 1];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tlong rowSum = 0;\n\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t\trowSum += array[i][j];\n\t\t\t\tpartialSums[i + 1][j + 1] = partialSums[i][j + 1] + rowSum;\n\t\t\t}\n\t\t}\n\t\tlong result = Long.MIN_VALUE;\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tfor (int j = i; j < m; j++) {\n\t\t\t\tlong minPartialSum = 0;\n\t\t\t\tfor (int k = 1; k <= n; k++) {\n\t\t\t\t\tlong current = partialSums[k][j + 1] - partialSums[k][i];\n\t\t\t\t\tresult = Math.max(result, current - minPartialSum);\n\t\t\t\t\tminPartialSum = Math.min(minPartialSum, current);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int parseIP(String ip) {\n\t\tString[] components = ip.split(\"[.]\");\n\t\tint result = 0;\n\t\tfor (int i = 0; i < 4; i++)\n\t\t\tresult += (1 << (24 - 8 * i)) * Integer.parseInt(components[i]);\n\t\treturn result;\n\t}\n\n\tpublic static String buildIP(int mask) {\n\t\tStringBuilder result = new StringBuilder();\n\t\tfor (int i = 0; i < 4; i++) {\n\t\t\tif (i != 0)\n\t\t\t\tresult.append('.');\n\t\t\tresult.append(mask >> (24 - 8 * i) & 255);\n\t\t}\n\t\treturn result.toString();\n\t}\n\n\tpublic static <T> boolean equals(T first, T second) {\n\t\treturn first == null && second == null || first != null\n\t\t\t\t&& first.equals(second);\n\t}\n\n\tpublic static boolean isVowel(char ch) {\n\t\tch = Character.toUpperCase(ch);\n\t\treturn ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U'\n\t\t\t\t|| ch == 'Y';\n\t}\n\n\tpublic static boolean isStrictVowel(char ch) {\n\t\tch = Character.toUpperCase(ch);\n\t\treturn ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U';\n\t}\n\n\tpublic static String convertToRoman(int number) {\n\t\tStringBuilder result = new StringBuilder();\n\t\tfor (int i = 0; i < ROMAN_TOKENS.length; i++) {\n\t\t\twhile (number >= ROMAN_VALUES[i]) {\n\t\t\t\tnumber -= ROMAN_VALUES[i];\n\t\t\t\tresult.append(ROMAN_TOKENS[i]);\n\t\t\t}\n\t\t}\n\t\treturn result.toString();\n\t}\n\n\tpublic static int convertFromRoman(String number) {\n\t\tint result = 0;\n\t\tfor (int i = 0; i < ROMAN_TOKENS.length; i++) {\n\t\t\twhile (number.startsWith(ROMAN_TOKENS[i])) {\n\t\t\t\tnumber = number.substring(ROMAN_TOKENS[i].length());\n\t\t\t\tresult += ROMAN_VALUES[i];\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int distance(int x1, int y1, int x2, int y2) {\n\t\tint dx = x1 - x2;\n\t\tint dy = y1 - y2;\n\t\treturn dx * dx + dy * dy;\n\t}\n\n\tpublic static <T extends Comparable<T>> T min(T first, T second) {\n\t\tif (first.compareTo(second) <= 0)\n\t\t\treturn first;\n\t\treturn second;\n\t}\n\n\tpublic static <T extends Comparable<T>> T max(T first, T second) {\n\t\tif (first.compareTo(second) <= 0)\n\t\t\treturn second;\n\t\treturn first;\n\t}\n\n\tpublic static void decreaseByOne(int[]... arrays) {\n\t\tfor (int[] array : arrays) {\n\t\t\tfor (int i = 0; i < array.length; i++)\n\t\t\t\tarray[i]--;\n\t\t}\n\t}\n\n\tpublic static int[] getIntArray(String s) {\n\t\tString[] tokens = s.split(\" \");\n\t\tint[] result = new int[tokens.length];\n\t\tfor (int i = 0; i < result.length; i++)\n\t\t\tresult[i] = Integer.parseInt(tokens[i]);\n\t\treturn result;\n\t}\n}\n\nclass Graph {\n\tpublic static final int REMOVED_BIT = 0;\n\n\tprotected int vertexCount;\n\tprotected int edgeCount;\n\n\tprivate int[] firstOutbound;\n\tprivate int[] firstInbound;\n\n\tprivate Edge[] edges;\n\tprivate int[] nextInbound;\n\tprivate int[] nextOutbound;\n\tprivate int[] from;\n\tprivate int[] to;\n\tprivate long[] weight;\n\tpublic long[] capacity;\n\tprivate int[] reverseEdge;\n\tprivate int[] flags;\n\n\tpublic Graph(int vertexCount) {\n\t\tthis(vertexCount, vertexCount);\n\t}\n\n\tpublic Graph(int vertexCount, int edgeCapacity) {\n\t\tthis.vertexCount = vertexCount;\n\t\tfirstOutbound = new int[vertexCount];\n\t\tArrays.fill(firstOutbound, -1);\n\n\t\tfrom = new int[edgeCapacity];\n\t\tto = new int[edgeCapacity];\n\t\tnextOutbound = new int[edgeCapacity];\n\t\tflags = new int[edgeCapacity];\n\t}\n\n\tpublic static Graph createGraph(int vertexCount, int[] from, int[] to) {\n\t\tGraph graph = new Graph(vertexCount, from.length);\n\t\tfor (int i = 0; i < from.length; i++)\n\t\t\tgraph.addSimpleEdge(from[i], to[i]);\n\t\treturn graph;\n\t}\n\n\tpublic static Graph createWeightedGraph(int vertexCount, int[] from,\n\t\t\tint[] to, long[] weight) {\n\t\tGraph graph = new Graph(vertexCount, from.length);\n\t\tfor (int i = 0; i < from.length; i++)\n\t\t\tgraph.addWeightedEdge(from[i], to[i], weight[i]);\n\t\treturn graph;\n\t}\n\n\tpublic static Graph createFlowGraph(int vertexCount, int[] from, int[] to,\n\t\t\tlong[] capacity) {\n\t\tGraph graph = new Graph(vertexCount, from.length * 2);\n\t\tfor (int i = 0; i < from.length; i++)\n\t\t\tgraph.addFlowEdge(from[i], to[i], capacity[i]);\n\t\treturn graph;\n\t}\n\n\tpublic static Graph createFlowWeightedGraph(int vertexCount, int[] from,\n\t\t\tint[] to, long[] weight, long[] capacity) {\n\t\tGraph graph = new Graph(vertexCount, from.length * 2);\n\t\tfor (int i = 0; i < from.length; i++)\n\t\t\tgraph.addFlowWeightedEdge(from[i], to[i], weight[i], capacity[i]);\n\t\treturn graph;\n\t}\n\n\tpublic static Graph createTree(int[] parent) {\n\t\tGraph graph = new Graph(parent.length + 1, parent.length);\n\t\tfor (int i = 0; i < parent.length; i++)\n\t\t\tgraph.addSimpleEdge(parent[i], i + 1);\n\t\treturn graph;\n\t}\n\n\tpublic int addEdge(int fromID, int toID, long weight, long capacity,\n\t\t\tint reverseEdge) {\n\t\tensureEdgeCapacity(edgeCount + 1);\n\t\tif (firstOutbound[fromID] != -1)\n\t\t\tnextOutbound[edgeCount] = firstOutbound[fromID];\n\t\telse\n\t\t\tnextOutbound[edgeCount] = -1;\n\t\tfirstOutbound[fromID] = edgeCount;\n\t\tif (firstInbound != null) {\n\t\t\tif (firstInbound[toID] != -1)\n\t\t\t\tnextInbound[edgeCount] = firstInbound[toID];\n\t\t\telse\n\t\t\t\tnextInbound[edgeCount] = -1;\n\t\t\tfirstInbound[toID] = edgeCount;\n\t\t}\n\t\tthis.from[edgeCount] = fromID;\n\t\tthis.to[edgeCount] = toID;\n\t\tif (capacity != 0) {\n\t\t\tif (this.capacity == null)\n\t\t\t\tthis.capacity = new long[from.length];\n\t\t\tthis.capacity[edgeCount] = capacity;\n\t\t}\n\t\tif (weight != 0) {\n\t\t\tif (this.weight == null)\n\t\t\t\tthis.weight = new long[from.length];\n\t\t\tthis.weight[edgeCount] = weight;\n\t\t}\n\t\tif (reverseEdge != -1) {\n\t\t\tif (this.reverseEdge == null) {\n\t\t\t\tthis.reverseEdge = new int[from.length];\n\t\t\t\tArrays.fill(this.reverseEdge, 0, edgeCount, -1);\n\t\t\t}\n\t\t\tthis.reverseEdge[edgeCount] = reverseEdge;\n\t\t}\n\t\tif (edges != null)\n\t\t\tedges[edgeCount] = createEdge(edgeCount);\n\t\treturn edgeCount++;\n\t}\n\n\tprotected final GraphEdge createEdge(int id) {\n\t\treturn new GraphEdge(id);\n\t}\n\n\tpublic final int addFlowWeightedEdge(int from, int to, long weight,\n\t\t\tlong capacity) {\n\t\tif (capacity == 0) {\n\t\t\treturn addEdge(from, to, weight, 0, -1);\n\t\t} else {\n\t\t\tint lastEdgeCount = edgeCount;\n\t\t\taddEdge(to, from, -weight, 0, lastEdgeCount + entriesPerEdge());\n\t\t\treturn addEdge(from, to, weight, capacity, lastEdgeCount);\n\t\t}\n\t}\n\n\tprotected int entriesPerEdge() {\n\t\treturn 1;\n\t}\n\n\tpublic final int addFlowEdge(int from, int to, long capacity) {\n\t\treturn addFlowWeightedEdge(from, to, 0, capacity);\n\t}\n\n\tpublic final int addWeightedEdge(int from, int to, long weight) {\n\t\treturn addFlowWeightedEdge(from, to, weight, 0);\n\t}\n\n\tpublic final int addSimpleEdge(int from, int to) {\n\t\treturn addWeightedEdge(from, to, 0);\n\t}\n\n\tpublic final int vertexCount() {\n\t\treturn vertexCount;\n\t}\n\n\tpublic final int edgeCount() {\n\t\treturn edgeCount;\n\t}\n\n\tprotected final int edgeCapacity() {\n\t\treturn from.length;\n\t}\n\n\tpublic final Edge edge(int id) {\n\t\tinitEdges();\n\t\treturn edges[id];\n\t}\n\n\tpublic final int firstOutbound(int vertex) {\n\t\tint id = firstOutbound[vertex];\n\t\twhile (id != -1 && isRemoved(id))\n\t\t\tid = nextOutbound[id];\n\t\treturn id;\n\t}\n\n\tpublic final int nextOutbound(int id) {\n\t\tid = nextOutbound[id];\n\t\twhile (id != -1 && isRemoved(id))\n\t\t\tid = nextOutbound[id];\n\t\treturn id;\n\t}\n\n\tpublic final int firstInbound(int vertex) {\n\t\tinitInbound();\n\t\tint id = firstInbound[vertex];\n\t\twhile (id != -1 && isRemoved(id))\n\t\t\tid = nextInbound[id];\n\t\treturn id;\n\t}\n\n\tpublic final int nextInbound(int id) {\n\t\tinitInbound();\n\t\tid = nextInbound[id];\n\t\twhile (id != -1 && isRemoved(id))\n\t\t\tid = nextInbound[id];\n\t\treturn id;\n\t}\n\n\tpublic final int source(int id) {\n\t\treturn from[id];\n\t}\n\n\tpublic final int destination(int id) {\n\t\treturn to[id];\n\t}\n\n\tpublic final long weight(int id) {\n\t\tif (weight == null)\n\t\t\treturn 0;\n\t\treturn weight[id];\n\t}\n\n\tpublic final long capacity(int id) {\n\t\tif (capacity == null)\n\t\t\treturn 0;\n\t\treturn capacity[id];\n\t}\n\n\tpublic final long flow(int id) {\n\t\tif (reverseEdge == null)\n\t\t\treturn 0;\n\t\treturn capacity[reverseEdge[id]];\n\t}\n\n\tpublic final void pushFlow(int id, long flow) {\n\t\tif (flow == 0)\n\t\t\treturn;\n\t\tif (flow > 0) {\n\t\t\tif (capacity(id) < flow)\n\t\t\t\tthrow new IllegalArgumentException(\"Not enough capacity\");\n\t\t} else {\n\t\t\tif (flow(id) < -flow)\n\t\t\t\tthrow new IllegalArgumentException(\"Not enough capacity\");\n\t\t}\n\t\tcapacity[id] -= flow;\n\t\tcapacity[reverseEdge[id]] += flow;\n\t}\n\n\tpublic int transposed(int id) {\n\t\treturn -1;\n\t}\n\n\tpublic final int reverse(int id) {\n\t\tif (reverseEdge == null)\n\t\t\treturn -1;\n\t\treturn reverseEdge[id];\n\t}\n\n\tpublic final void addVertices(int count) {\n\t\tensureVertexCapacity(vertexCount + count);\n\t\tArrays.fill(firstOutbound, vertexCount, vertexCount + count, -1);\n\t\tif (firstInbound != null)\n\t\t\tArrays.fill(firstInbound, vertexCount, vertexCount + count, -1);\n\t\tvertexCount += count;\n\t}\n\n\tprotected final void initEdges() {\n\t\tif (edges == null) {\n\t\t\tedges = new Edge[from.length];\n\t\t\tfor (int i = 0; i < edgeCount; i++)\n\t\t\t\tedges[i] = createEdge(i);\n\t\t}\n\t}\n\n\tpublic final void removeVertex(int vertex) {\n\t\tint id = firstOutbound[vertex];\n\t\twhile (id != -1) {\n\t\t\tremoveEdge(id);\n\t\t\tid = nextOutbound[id];\n\t\t}\n\t\tinitInbound();\n\t\tid = firstInbound[vertex];\n\t\twhile (id != -1) {\n\t\t\tremoveEdge(id);\n\t\t\tid = nextInbound[id];\n\t\t}\n\t}\n\n\tprivate void initInbound() {\n\t\tif (firstInbound == null) {\n\t\t\tfirstInbound = new int[firstOutbound.length];\n\t\t\tArrays.fill(firstInbound, 0, vertexCount, -1);\n\t\t\tnextInbound = new int[from.length];\n\t\t\tfor (int i = 0; i < edgeCount; i++) {\n\t\t\t\tnextInbound[i] = firstInbound[to[i]];\n\t\t\t\tfirstInbound[to[i]] = i;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic final boolean flag(int id, int bit) {\n\t\treturn (flags[id] >> bit & 1) != 0;\n\t}\n\n\tpublic final void setFlag(int id, int bit) {\n\t\tflags[id] |= 1 << bit;\n\t}\n\n\tpublic final void removeFlag(int id, int bit) {\n\t\tflags[id] &= -1 - (1 << bit);\n\t}\n\n\tpublic final void removeEdge(int id) {\n\t\tsetFlag(id, REMOVED_BIT);\n\t}\n\n\tpublic final void restoreEdge(int id) {\n\t\tremoveFlag(id, REMOVED_BIT);\n\t}\n\n\tpublic final boolean isRemoved(int id) {\n\t\treturn flag(id, REMOVED_BIT);\n\t}\n\n\tpublic final Iterable<Edge> outbound(final int id) {\n\t\tinitEdges();\n\t\treturn new Iterable<Edge>() {\n\t\t\tpublic Iterator<Edge> iterator() {\n\t\t\t\treturn new EdgeIterator(id, firstOutbound, nextOutbound);\n\t\t\t}\n\t\t};\n\t}\n\n\tpublic final Iterable<Edge> inbound(final int id) {\n\t\tinitEdges();\n\t\tinitInbound();\n\t\treturn new Iterable<Edge>() {\n\t\t\tpublic Iterator<Edge> iterator() {\n\t\t\t\treturn new EdgeIterator(id, firstInbound, nextInbound);\n\t\t\t}\n\t\t};\n\t}\n\n\tprotected void ensureEdgeCapacity(int size) {\n\t\tif (from.length < size) {\n\t\t\tint newSize = Math.max(size, 2 * from.length);\n\t\t\tif (edges != null)\n\t\t\t\tedges = resize(edges, newSize);\n\t\t\tfrom = resize(from, newSize);\n\t\t\tto = resize(to, newSize);\n\t\t\tnextOutbound = resize(nextOutbound, newSize);\n\t\t\tif (nextInbound != null)\n\t\t\t\tnextInbound = resize(nextInbound, newSize);\n\t\t\tif (weight != null)\n\t\t\t\tweight = resize(weight, newSize);\n\t\t\tif (capacity != null)\n\t\t\t\tcapacity = resize(capacity, newSize);\n\t\t\tif (reverseEdge != null)\n\t\t\t\treverseEdge = resize(reverseEdge, newSize);\n\t\t\tflags = resize(flags, newSize);\n\t\t}\n\t}\n\n\tprivate void ensureVertexCapacity(int size) {\n\t\tif (firstOutbound.length < size) {\n\t\t\tint newSize = Math.max(size, 2 * from.length);\n\t\t\tfirstOutbound = resize(firstOutbound, newSize);\n\t\t\tif (firstInbound != null)\n\t\t\t\tfirstInbound = resize(firstInbound, newSize);\n\t\t}\n\t}\n\n\tprotected final int[] resize(int[] array, int size) {\n\t\tint[] newArray = new int[size];\n\t\tSystem.arraycopy(array, 0, newArray, 0, array.length);\n\t\treturn newArray;\n\t}\n\n\tprivate long[] resize(long[] array, int size) {\n\t\tlong[] newArray = new long[size];\n\t\tSystem.arraycopy(array, 0, newArray, 0, array.length);\n\t\treturn newArray;\n\t}\n\n\tprivate Edge[] resize(Edge[] array, int size) {\n\t\tEdge[] newArray = new Edge[size];\n\t\tSystem.arraycopy(array, 0, newArray, 0, array.length);\n\t\treturn newArray;\n\t}\n\n\tpublic final boolean isSparse() {\n\t\treturn vertexCount == 0 || edgeCount * 20 / vertexCount <= vertexCount;\n\t}\n\n\tprotected class GraphEdge implements Edge {\n\t\tprotected int id;\n\n\t\tprotected GraphEdge(int id) {\n\t\t\tthis.id = id;\n\t\t}\n\n\t\tpublic int getSource() {\n\t\t\treturn source(id);\n\t\t}\n\n\t\tpublic int getDestination() {\n\t\t\treturn destination(id);\n\t\t}\n\n\t\tpublic long getWeight() {\n\t\t\treturn weight(id);\n\t\t}\n\n\t\tpublic long getCapacity() {\n\t\t\treturn capacity(id);\n\t\t}\n\n\t\tpublic long getFlow() {\n\t\t\treturn flow(id);\n\t\t}\n\n\t\tpublic void pushFlow(long flow) {\n\t\t\tGraph.this.pushFlow(id, flow);\n\t\t}\n\n\t\tpublic boolean getFlag(int bit) {\n\t\t\treturn flag(id, bit);\n\t\t}\n\n\t\tpublic void setFlag(int bit) {\n\t\t\tGraph.this.setFlag(id, bit);\n\t\t}\n\n\t\tpublic void removeFlag(int bit) {\n\t\t\tGraph.this.removeFlag(id, bit);\n\t\t}\n\n\t\tpublic int getTransposedID() {\n\t\t\treturn transposed(id);\n\t\t}\n\n\t\tpublic Edge getTransposedEdge() {\n\t\t\tint reverseID = getTransposedID();\n\t\t\tif (reverseID == -1)\n\t\t\t\treturn null;\n\t\t\tinitEdges();\n\t\t\treturn edge(reverseID);\n\t\t}\n\n\t\tpublic int getReverseID() {\n\t\t\treturn reverse(id);\n\t\t}\n\n\t\tpublic Edge getReverseEdge() {\n\t\t\tint reverseID = getReverseID();\n\t\t\tif (reverseID == -1)\n\t\t\t\treturn null;\n\t\t\tinitEdges();\n\t\t\treturn edge(reverseID);\n\t\t}\n\n\t\tpublic int getID() {\n\t\t\treturn id;\n\t\t}\n\n\t\tpublic void remove() {\n\t\t\tremoveEdge(id);\n\t\t}\n\n\t\tpublic void restore() {\n\t\t\trestoreEdge(id);\n\t\t}\n\t}\n\n\tpublic class EdgeIterator implements Iterator<Edge> {\n\t\tprivate int edgeID;\n\t\tprivate final int[] next;\n\t\tprivate int lastID = -1;\n\n\t\tpublic EdgeIterator(int id, int[] first, int[] next) {\n\t\t\tthis.next = next;\n\t\t\tedgeID = nextEdge(first[id]);\n\t\t}\n\n\t\tprivate int nextEdge(int id) {\n\t\t\twhile (id != -1 && isRemoved(id))\n\t\t\t\tid = next[id];\n\t\t\treturn id;\n\t\t}\n\n\t\tpublic boolean hasNext() {\n\t\t\treturn edgeID != -1;\n\t\t}\n\n\t\tpublic Edge next() {\n\t\t\tif (edgeID == -1)\n\t\t\t\tthrow new NoSuchElementException();\n\t\t\tlastID = edgeID;\n\t\t\tedgeID = nextEdge(next[lastID]);\n\t\t\treturn edges[lastID];\n\t\t}\n\n\t\tpublic void remove() {\n\t\t\tif (lastID == -1)\n\t\t\t\tthrow new IllegalStateException();\n\t\t\tremoveEdge(lastID);\n\t\t\tlastID = -1;\n\t\t}\n\t}\n\n}\n\nclass MaxFlow {\n\tprivate final Graph graph;\n\tprivate int source;\n\tprivate int destination;\n\tprivate int[] queue;\n\tprivate int[] distance;\n\tprivate int[] nextEdge;\n\n\tprivate MaxFlow(Graph graph, int source, int destination) {\n\t\tthis.graph = graph;\n\t\tthis.source = source;\n\t\tthis.destination = destination;\n\t\tint vertexCount = graph.vertexCount();\n\t\tqueue = new int[vertexCount];\n\t\tdistance = new int[vertexCount];\n\t\tnextEdge = new int[vertexCount];\n\t}\n\n\tpublic static long dinic(Graph graph, int source, int destination) {\n\t\treturn new MaxFlow(graph, source, destination).dinic();\n\t}\n\n\tprivate long dinic() {\n\t\tlong totalFlow = 0;\n\t\twhile (true) {\n\t\t\tedgeDistances();\n\t\t\tif (distance[destination] == -1)\n\t\t\t\tbreak;\n\t\t\tArrays.fill(nextEdge, -2);\n\t\t\ttotalFlow += dinicImpl(source, Long.MAX_VALUE);\n\t\t}\n\t\treturn totalFlow;\n\t}\n\n\tprivate void edgeDistances() {\n\t\tArrays.fill(distance, -1);\n\t\tdistance[source] = 0;\n\t\tint size = 1;\n\t\tqueue[0] = source;\n\t\tfor (int i = 0; i < size; i++) {\n\t\t\tint current = queue[i];\n\t\t\tint id = graph.firstOutbound(current);\n\t\t\twhile (id != -1) {\n\t\t\t\tif (graph.capacity(id) != 0) {\n\t\t\t\t\tint next = graph.destination(id);\n\t\t\t\t\tif (distance[next] == -1) {\n\t\t\t\t\t\tdistance[next] = distance[current] + 1;\n\t\t\t\t\t\tqueue[size++] = next;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tid = graph.nextOutbound(id);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate long dinicImpl(int source, long flow) {\n\t\tif (source == destination)\n\t\t\treturn flow;\n\t\tif (flow == 0 || distance[source] == distance[destination])\n\t\t\treturn 0;\n\t\tint id = nextEdge[source];\n\t\tif (id == -2)\n\t\t\tnextEdge[source] = id = graph.firstOutbound(source);\n\t\tlong totalPushed = 0;\n\t\twhile (id != -1) {\n\t\t\tint nextDestinationID = graph.destination(id);\n\t\t\tif (graph.capacity(id) != 0\n\t\t\t\t\t&& distance[nextDestinationID] == distance[source] + 1) {\n\t\t\t\tlong pushed = dinicImpl(nextDestinationID,\n\t\t\t\t\t\tMath.min(flow, graph.capacity(id)));\n\t\t\t\tif (pushed != 0) {\n\t\t\t\t\tgraph.pushFlow(id, pushed);\n\t\t\t\t\tflow -= pushed;\n\t\t\t\t\ttotalPushed += pushed;\n\t\t\t\t\tif (flow == 0)\n\t\t\t\t\t\treturn totalPushed;\n\t\t\t\t}\n\t\t\t}\n\t\t\tnextEdge[source] = id = graph.nextOutbound(id);\n\t\t}\n\t\treturn totalPushed;\n\t}\n}\n\ninterface Edge {\n\tpublic int getSource();\n\n\tpublic int getDestination();\n\n\tpublic long getWeight();\n\n\tpublic long getCapacity();\n\n\tpublic long getFlow();\n\n\tpublic void pushFlow(long flow);\n\n\tpublic boolean getFlag(int bit);\n\n\tpublic void setFlag(int bit);\n\n\tpublic void removeFlag(int bit);\n\n\tpublic int getTransposedID();\n\n\tpublic Edge getTransposedEdge();\n\n\tpublic int getReverseID();\n\n\tpublic Edge getReverseEdge();\n\n\tpublic int getID();\n\n\tpublic void remove();\n\n\tpublic void restore();\n}\n\nclass Point {\n\tpublic static final Point ORIGIN = new Point(0, 0);\n\tpublic final double x;\n\tpublic final double y;\n\n\t@Override\n\tpublic String toString() {\n\t\treturn \"(\" + x + \", \" + y + \")\";\n\t}\n\n\tpublic Point(double x, double y) {\n\t\tthis.x = x;\n\t\tthis.y = y;\n\t}\n\n\tpublic Line line(Point other) {\n\t\tif (equals(other))\n\t\t\treturn null;\n\t\tdouble a = other.y - y;\n\t\tdouble b = x - other.x;\n\t\tdouble c = -a * x - b * y;\n\t\treturn new Line(a, b, c);\n\t}\n\n\t@Override\n\tpublic boolean equals(Object o) {\n\t\tif (this == o)\n\t\t\treturn true;\n\t\tif (o == null || getClass() != o.getClass())\n\t\t\treturn false;\n\n\t\tPoint point = (Point) o;\n\n\t\treturn Math.abs(x - point.x) <= GeometryUtils.epsilon\n\t\t\t\t&& Math.abs(y - point.y) <= GeometryUtils.epsilon;\n\t}\n\n\t@Override\n\tpublic int hashCode() {\n\t\tint result;\n\t\tlong temp;\n\t\ttemp = x != +0.0d ? Double.doubleToLongBits(x) : 0L;\n\t\tresult = (int) (temp ^ (temp >>> 32));\n\t\ttemp = y != +0.0d ? Double.doubleToLongBits(y) : 0L;\n\t\tresult = 31 * result + (int) (temp ^ (temp >>> 32));\n\t\treturn result;\n\t}\n\n\tpublic double distance(Point other) {\n\t\treturn GeometryUtils.fastHypot(x - other.x, y - other.y);\n\t}\n\n\tpublic double distance(Line line) {\n\t\treturn Math.abs(line.a * x + line.b * y + line.c);\n\t}\n\n\tpublic double value() {\n\t\treturn GeometryUtils.fastHypot(x, y);\n\t}\n\n\tpublic double angle() {\n\t\treturn Math.atan2(y, x);\n\t}\n\n\tpublic static Point readPoint(InputReader in) {\n\t\tdouble x = in.readDouble();\n\t\tdouble y = in.readDouble();\n\t\treturn new Point(x, y);\n\t}\n\n\tpublic Point rotate(double angle) {\n\t\tdouble nx = x * Math.cos(angle) - y * Math.sin(angle);\n\t\tdouble ny = y * Math.cos(angle) + x * Math.sin(angle);\n\t\treturn new Point(nx, ny);\n\t}\n}\n\nclass Line {\n\tpublic final double a;\n\tpublic final double b;\n\tpublic final double c;\n\n\tpublic Line(Point p, double angle) {\n\t\ta = Math.sin(angle);\n\t\tb = -Math.cos(angle);\n\t\tc = -p.x * a - p.y * b;\n\t}\n\n\tpublic Line(double a, double b, double c) {\n\t\tdouble h = GeometryUtils.fastHypot(a, b);\n\t\tthis.a = a / h;\n\t\tthis.b = b / h;\n\t\tthis.c = c / h;\n\t}\n\n\tpublic Point intersect(Line other) {\n\t\tif (parallel(other))\n\t\t\treturn null;\n\t\tdouble determinant = b * other.a - a * other.b;\n\t\tdouble x = (c * other.b - b * other.c) / determinant;\n\t\tdouble y = (a * other.c - c * other.a) / determinant;\n\t\treturn new Point(x, y);\n\t}\n\n\tpublic boolean parallel(Line other) {\n\t\treturn Math.abs(a * other.b - b * other.a) < GeometryUtils.epsilon;\n\t}\n\n\tpublic boolean contains(Point point) {\n\t\treturn Math.abs(value(point)) < GeometryUtils.epsilon;\n\t}\n\n\tpublic Line perpendicular(Point point) {\n\t\treturn new Line(-b, a, b * point.x - a * point.y);\n\t}\n\n\tpublic double value(Point point) {\n\t\treturn a * point.x + b * point.y + c;\n\t}\n\n\tpublic double distance(Point center) {\n\t\treturn Math.abs(value(center));\n\t}\n\n\t@Override\n\tpublic boolean equals(Object o) {\n\t\tif (this == o)\n\t\t\treturn true;\n\t\tif (o == null || getClass() != o.getClass())\n\t\t\treturn false;\n\n\t\tLine line = (Line) o;\n\n\t\tif (!parallel(line))\n\t\t\treturn false;\n\t\tif (Math.abs(a * line.c - c * line.a) > GeometryUtils.epsilon\n\t\t\t\t|| Math.abs(b * line.c - c * line.b) > GeometryUtils.epsilon)\n\t\t\treturn false;\n\n\t\treturn true;\n\t}\n}\n\nclass GeometryUtils {\n\tpublic static double epsilon = 1e-8;\n\n\tpublic static double fastHypot(double... x) {\n\t\tif (x.length == 0)\n\t\t\treturn 0;\n\t\telse if (x.length == 1)\n\t\t\treturn Math.abs(x[0]);\n\t\telse {\n\t\t\tdouble sumSquares = 0;\n\t\t\tfor (double value : x)\n\t\t\t\tsumSquares += value * value;\n\t\t\treturn Math.sqrt(sumSquares);\n\t\t}\n\t}\n\n\tpublic static double fastHypot(double x, double y) {\n\t\treturn Math.sqrt(x * x + y * y);\n\t}\n\n\tpublic static double fastHypot(double[] x, double[] y) {\n\t\tif (x.length == 0)\n\t\t\treturn 0;\n\t\telse if (x.length == 1)\n\t\t\treturn Math.abs(x[0] - y[0]);\n\t\telse {\n\t\t\tdouble sumSquares = 0;\n\t\t\tfor (int i = 0; i < x.length; i++) {\n\t\t\t\tdouble diff = x[i] - y[i];\n\t\t\t\tsumSquares += diff * diff;\n\t\t\t}\n\t\t\treturn Math.sqrt(sumSquares);\n\t\t}\n\t}\n\n\tpublic static double fastHypot(int[] x, int[] y) {\n\t\tif (x.length == 0)\n\t\t\treturn 0;\n\t\telse if (x.length == 1)\n\t\t\treturn Math.abs(x[0] - y[0]);\n\t\telse {\n\t\t\tdouble sumSquares = 0;\n\t\t\tfor (int i = 0; i < x.length; i++) {\n\t\t\t\tdouble diff = x[i] - y[i];\n\t\t\t\tsumSquares += diff * diff;\n\t\t\t}\n\t\t\treturn Math.sqrt(sumSquares);\n\t\t}\n\t}\n\n\tpublic static double missileTrajectoryLength(double v, double angle,\n\t\t\tdouble g) {\n\t\treturn (v * v * Math.sin(2 * angle)) / g;\n\t}\n\n\tpublic static double sphereVolume(double radius) {\n\t\treturn 4 * Math.PI * radius * radius * radius / 3;\n\t}\n\n\tpublic static double triangleSquare(double first, double second,\n\t\t\tdouble third) {\n\t\tdouble p = (first + second + third) / 2;\n\t\treturn Math.sqrt(p * (p - first) * (p - second) * (p - third));\n\t}\n\n\tpublic static double canonicalAngle(double angle) {\n\t\twhile (angle > Math.PI)\n\t\t\tangle -= 2 * Math.PI;\n\t\twhile (angle < -Math.PI)\n\t\t\tangle += 2 * Math.PI;\n\t\treturn angle;\n\t}\n\n\tpublic static double positiveAngle(double angle) {\n\t\twhile (angle > 2 * Math.PI - GeometryUtils.epsilon)\n\t\t\tangle -= 2 * Math.PI;\n\t\twhile (angle < -GeometryUtils.epsilon)\n\t\t\tangle += 2 * Math.PI;\n\t\treturn angle;\n\t}\n}\n\nclass IntegerUtils {\n\tpublic static long gcd(long a, long b) {\n\t\ta = Math.abs(a);\n\t\tb = Math.abs(b);\n\t\twhile (b != 0) {\n\t\t\tlong temp = a % b;\n\t\t\ta = b;\n\t\t\tb = temp;\n\t\t}\n\t\treturn a;\n\t}\n\n\tpublic static int gcd(int a, int b) {\n\t\ta = Math.abs(a);\n\t\tb = Math.abs(b);\n\t\twhile (b != 0) {\n\t\t\tint temp = a % b;\n\t\t\ta = b;\n\t\t\tb = temp;\n\t\t}\n\t\treturn a;\n\t}\n\n\tpublic static boolean[] generatePrimalityTable(int upTo) {\n\t\tboolean[] isPrime = new boolean[upTo];\n\t\tif (upTo < 2)\n\t\t\treturn isPrime;\n\t\tArrays.fill(isPrime, true);\n\t\tisPrime[0] = isPrime[1] = false;\n\t\tfor (int i = 2; i * i < upTo; i++) {\n\t\t\tif (isPrime[i]) {\n\t\t\t\tfor (int j = i * i; j < upTo; j += i)\n\t\t\t\t\tisPrime[j] = false;\n\t\t\t}\n\t\t}\n\t\treturn isPrime;\n\t}\n\n\tpublic static int[] generateBitPrimalityTable(int upTo) {\n\t\tint[] isPrime = new int[(upTo + 31) >> 5];\n\t\tif (upTo < 2)\n\t\t\treturn isPrime;\n\t\tArrays.fill(isPrime, -1);\n\t\tisPrime[0] &= -4;\n\t\tfor (int i = 2; i * i < upTo; i++) {\n\t\t\tif ((isPrime[i >> 5] >>> (i & 31) & 1) == 1) {\n\t\t\t\tfor (int j = i * i; j < upTo; j += i)\n\t\t\t\t\tisPrime[j >> 5] &= -1 - (1 << (j & 31));\n\t\t\t}\n\t\t}\n\t\treturn isPrime;\n\t}\n\n\tpublic static int[] generateDivisorTable(int upTo) {\n\t\tint[] divisor = new int[upTo];\n\t\tfor (int i = 1; i < upTo; i++)\n\t\t\tdivisor[i] = i;\n\t\tfor (int i = 2; i * i < upTo; i++) {\n\t\t\tif (divisor[i] == i) {\n\t\t\t\tfor (int j = i * i; j < upTo; j += i)\n\t\t\t\t\tdivisor[j] = i;\n\t\t\t}\n\t\t}\n\t\treturn divisor;\n\t}\n\n\tpublic static long powerInFactorial(long n, long p) {\n\t\tlong result = 0;\n\t\twhile (n != 0) {\n\t\t\tresult += n /= p;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static int sumDigits(CharSequence number) {\n\t\tint result = 0;\n\t\tfor (int i = number.length() - 1; i >= 0; i--)\n\t\t\tresult += digitValue(number.charAt(i));\n\t\treturn result;\n\t}\n\n\tpublic static int digitValue(char digit) {\n\t\tif (Character.isDigit(digit))\n\t\t\treturn digit - '0';\n\t\tif (Character.isUpperCase(digit))\n\t\t\treturn digit + 10 - 'A';\n\t\treturn digit + 10 - 'a';\n\t}\n\n\tpublic static int longCompare(long a, long b) {\n\t\tif (a < b)\n\t\t\treturn -1;\n\t\tif (a > b)\n\t\t\treturn 1;\n\t\treturn 0;\n\t}\n\n\tpublic static long[][] generateBinomialCoefficients(int n) {\n\t\tlong[][] result = new long[n + 1][n + 1];\n\t\tfor (int i = 0; i <= n; i++) {\n\t\t\tresult[i][0] = 1;\n\t\t\tfor (int j = 1; j <= i; j++)\n\t\t\t\tresult[i][j] = result[i - 1][j - 1] + result[i - 1][j];\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static long[][] generateBinomialCoefficients(int n, long module) {\n\t\tlong[][] result = new long[n + 1][n + 1];\n\t\tif (module == 1)\n\t\t\treturn result;\n\t\tfor (int i = 0; i <= n; i++) {\n\t\t\tresult[i][0] = 1;\n\t\t\tfor (int j = 1; j <= i; j++) {\n\t\t\t\tresult[i][j] = result[i - 1][j - 1] + result[i - 1][j];\n\t\t\t\tif (result[i][j] >= module)\n\t\t\t\t\tresult[i][j] -= module;\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static long[] generateBinomialRow(int n, long module) {\n\t\tlong[] result = generateReverse(n + 1, module);\n\t\tresult[0] = 1;\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\tresult[i] = result[i - 1] * (n - i + 1) % module * result[i]\n\t\t\t\t\t% module;\n\t\treturn result;\n\t}\n\n\tpublic static int[] representationInBase(long number, int base) {\n\t\tlong basePower = base;\n\t\tint exponent = 1;\n\t\twhile (number >= basePower) {\n\t\t\tbasePower *= base;\n\t\t\texponent++;\n\t\t}\n\t\tint[] representation = new int[exponent];\n\t\tfor (int i = 0; i < exponent; i++) {\n\t\t\tbasePower /= base;\n\t\t\trepresentation[i] = (int) (number / basePower);\n\t\t\tnumber %= basePower;\n\t\t}\n\t\treturn representation;\n\t}\n\n\tpublic static int trueDivide(int a, int b) {\n\t\treturn (a - trueMod(a, b)) / b;\n\t}\n\n\tpublic static long trueDivide(long a, long b) {\n\t\treturn (a - trueMod(a, b)) / b;\n\t}\n\n\tpublic static int trueMod(int a, int b) {\n\t\ta %= b;\n\t\ta += b;\n\t\ta %= b;\n\t\treturn a;\n\t}\n\n\tpublic static long trueMod(long a, long b) {\n\t\ta %= b;\n\t\ta += b;\n\t\ta %= b;\n\t\treturn a;\n\t}\n\n\tpublic static long factorial(int n) {\n\t\tlong result = 1;\n\t\tfor (int i = 2; i <= n; i++)\n\t\t\tresult *= i;\n\t\treturn result;\n\t}\n\n\tpublic static long factorial(int n, long mod) {\n\t\tlong result = 1;\n\t\tfor (int i = 2; i <= n; i++)\n\t\t\tresult = result * i % mod;\n\t\treturn result % mod;\n\t}\n\n\tpublic static long power(long base, long exponent) {\n\t\tif (exponent == 0)\n\t\t\treturn 1;\n\t\tlong result = power(base, exponent >> 1);\n\t\tresult = result * result;\n\t\tif ((exponent & 1) != 0)\n\t\t\tresult = result * base;\n\t\treturn result;\n\t}\n\n\tpublic static long power(long base, long exponent, long mod) {\n\t\tif (base >= mod)\n\t\t\tbase %= mod;\n\t\tif (exponent == 0)\n\t\t\treturn 1 % mod;\n\t\tlong result = power(base, exponent >> 1, mod);\n\t\tresult = result * result % mod;\n\t\tif ((exponent & 1) != 0)\n\t\t\tresult = result * base % mod;\n\t\treturn result;\n\t}\n\n\tpublic static long lcm(long a, long b) {\n\t\treturn a / gcd(a, b) * b;\n\t}\n\n\tpublic static long[] generateFibonacci(long upTo) {\n\t\tint count = 0;\n\t\tlong last = 0;\n\t\tlong current = 1;\n\t\twhile (current <= upTo) {\n\t\t\tlong next = last + current;\n\t\t\tlast = current;\n\t\t\tcurrent = next;\n\t\t\tcount++;\n\t\t}\n\t\treturn generateFibonacci(count, -1);\n\t}\n\n\tpublic static long[] generateFibonacci(int count, long module) {\n\t\tlong[] result = new long[count];\n\t\tif (module == -1) {\n\t\t\tif (count != 0)\n\t\t\t\tresult[0] = 1;\n\t\t\tif (count > 1)\n\t\t\t\tresult[1] = 1;\n\t\t\tfor (int i = 2; i < count; i++)\n\t\t\t\tresult[i] = result[i - 1] + result[i - 2];\n\t\t} else {\n\t\t\tif (count != 0)\n\t\t\t\tresult[0] = 1 % module;\n\t\t\tif (count > 1)\n\t\t\t\tresult[1] = 1 % module;\n\t\t\tfor (int i = 2; i < count; i++)\n\t\t\t\tresult[i] = (result[i - 1] + result[i - 2]) % module;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static long[] generateHappy(int digits) {\n\t\tlong[] happy = new long[(1 << (digits + 1)) - 2];\n\t\thappy[0] = 4;\n\t\thappy[1] = 7;\n\t\tint first = 0;\n\t\tint last = 2;\n\t\tfor (int i = 2; i <= digits; i++) {\n\t\t\tfor (int j = 0; j < last - first; j++) {\n\t\t\t\thappy[last + 2 * j] = 10 * happy[first + j] + 4;\n\t\t\t\thappy[last + 2 * j + 1] = 10 * happy[first + j] + 7;\n\t\t\t}\n\t\t\tint next = last + 2 * (last - first);\n\t\t\tfirst = last;\n\t\t\tlast = next;\n\t\t}\n\t\treturn happy;\n\t}\n\n\tpublic static long[] generateFactorial(int count, long module) {\n\t\tlong[] result = new long[count];\n\t\tif (module == -1) {\n\t\t\tif (count != 0)\n\t\t\t\tresult[0] = 1;\n\t\t\tfor (int i = 1; i < count; i++)\n\t\t\t\tresult[i] = result[i - 1] * i;\n\t\t} else {\n\t\t\tif (count != 0)\n\t\t\t\tresult[0] = 1 % module;\n\t\t\tfor (int i = 1; i < count; i++)\n\t\t\t\tresult[i] = (result[i - 1] * i) % module;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static long reverse(long number, long module) {\n\t\treturn power(number, module - 2, module);\n\t}\n\n\tpublic static boolean isPrime(long number) {\n\t\tif (number < 2)\n\t\t\treturn false;\n\t\tfor (long i = 2; i * i <= number; i++) {\n\t\t\tif (number % i == 0)\n\t\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tpublic static long[] generateReverse(int upTo, long module) {\n\t\tlong[] result = new long[upTo];\n\t\tif (upTo > 1)\n\t\t\tresult[1] = 1;\n\t\tfor (int i = 2; i < upTo; i++)\n\t\t\tresult[i] = (module - module / i * result[((int) (module % i))]\n\t\t\t\t\t% module)\n\t\t\t\t\t% module;\n\t\treturn result;\n\t}\n\n\tpublic static long[] generateReverseFactorials(int upTo, long module) {\n\t\tlong[] result = generateReverse(upTo, module);\n\t\tif (upTo > 0)\n\t\t\tresult[0] = 1;\n\t\tfor (int i = 1; i < upTo; i++)\n\t\t\tresult[i] = result[i] * result[i - 1] % module;\n\t\treturn result;\n\t}\n\n\tpublic static long[] generatePowers(long base, int count, long mod) {\n\t\tlong[] result = new long[count];\n\t\tif (count != 0)\n\t\t\tresult[0] = 1 % mod;\n\t\tfor (int i = 1; i < count; i++)\n\t\t\tresult[i] = result[i - 1] * base % mod;\n\t\treturn result;\n\t}\n\n\tpublic static long nextPrime(long from) {\n\t\tif (from <= 2)\n\t\t\treturn 2;\n\t\tfrom += 1 - (from & 1);\n\t\twhile (!isPrime(from))\n\t\t\tfrom += 2;\n\t\treturn from;\n\t}\n\n\tpublic static long binomialCoefficient(int n, int m, long mod) {\n\t\tif (m < 0 || m > n)\n\t\t\treturn 0;\n\t\tif (2 * m > n)\n\t\t\tm = n - m;\n\t\tlong result = 1;\n\t\tfor (int i = n - m + 1; i <= n; i++)\n\t\t\tresult = result * i % mod;\n\t\treturn result\n\t\t\t\t* BigInteger.valueOf(factorial(m, mod))\n\t\t\t\t\t\t.modInverse(BigInteger.valueOf(mod)).longValue() % mod;\n\t}\n\n\tpublic static boolean isSquare(long number) {\n\t\tlong sqrt = Math.round(Math.sqrt(number));\n\t\treturn sqrt * sqrt == number;\n\t}\n\n\tpublic static long findCommon(long aRemainder, long aMod, long bRemainder,\n\t\t\tlong bMod) {\n\t\tlong modGCD = gcd(aMod, bMod);\n\t\tlong gcdRemainder = aRemainder % modGCD;\n\t\tif (gcdRemainder != bRemainder % modGCD)\n\t\t\treturn -1;\n\t\taMod /= modGCD;\n\t\taRemainder /= modGCD;\n\t\tbMod /= modGCD;\n\t\tbRemainder /= modGCD;\n\t\tlong aReverse = BigInteger.valueOf(aMod)\n\t\t\t\t.modInverse(BigInteger.valueOf(bMod)).longValue();\n\t\tlong bReverse = BigInteger.valueOf(bMod)\n\t\t\t\t.modInverse(BigInteger.valueOf(aMod)).longValue();\n\t\tlong mod = aMod * bMod;\n\t\treturn BigInteger\n\t\t\t\t.valueOf(bReverse * aRemainder % mod)\n\t\t\t\t.multiply(BigInteger.valueOf(bMod))\n\t\t\t\t.add(BigInteger.valueOf(aReverse * bRemainder % mod).multiply(\n\t\t\t\t\t\tBigInteger.valueOf(aMod))).mod(BigInteger.valueOf(mod))\n\t\t\t\t.longValue()\n\t\t\t\t* modGCD + gcdRemainder;\n\t}\n\n\tpublic static long[] generatePowers(long base, long maxValue) {\n\t\tif (maxValue <= 0)\n\t\t\treturn new long[0];\n\t\tint size = 1;\n\t\tlong current = 1;\n\t\twhile (maxValue / base >= current) {\n\t\t\tcurrent *= base;\n\t\t\tsize++;\n\t\t}\n\t\treturn generatePowers(base, size, Long.MAX_VALUE);\n\t}\n}\n\nclass GraphAlgorithms {\n\tpublic static int[] topologicalSort(Graph graph) {\n\t\tint count = graph.vertexCount();\n\t\tint[] queue = new int[count];\n\t\tint[] degree = new int[count];\n\t\tint size = 0;\n\t\tfor (int i = 0; i < graph.edgeCount(); i++) {\n\t\t\tif (!graph.isRemoved(i))\n\t\t\t\tdegree[graph.destination(i)]++;\n\t\t}\n\t\tfor (int i = 0; i < count; i++) {\n\t\t\tif (degree[i] == 0)\n\t\t\t\tqueue[size++] = i;\n\t\t}\n\t\tfor (int i = 0; i < size; i++) {\n\t\t\tint current = queue[i];\n\t\t\tfor (int j = graph.firstOutbound(current); j != -1; j = graph\n\t\t\t\t\t.nextOutbound(j)) {\n\t\t\t\tint next = graph.destination(j);\n\t\t\t\tif (--degree[next] == 0)\n\t\t\t\t\tqueue[size++] = next;\n\t\t\t}\n\t\t}\n\t\tif (size != count)\n\t\t\treturn null;\n\t\treturn queue;\n\t}\n}", "src_uid": "656bf8df1e79499aa2ab2c28712851f0"} {"source_code": "import java.util.*;\npublic class BePositive {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint arr[] = new int[n];\n\t\tint pos = 0,zero = 0,neg = 0;\n\t\tfor(int i=0;i<n;++i)\n\t\t{\n\t\t\tarr[i] = sc.nextInt();\n\t\t\tif(arr[i]>0)\n\t\t\t\tpos++;\n\t\t\telse if(arr[i]==0)\n\t\t\t\tzero++;\n\t\t\telse\n\t\t\t\tneg++;\n\t\t}\n\n\t\tint con = (int)Math.ceil((double)n/2);\n\t\t\n\t\tif(pos>=con)\n\t\t\tSystem.out.println(\"2\");\n\t\telse if(neg>=con)\n\t\t\tSystem.out.println(\"-2\");\n\t\telse\n\t\t\tSystem.out.println(\"0\");\n\t}\n\n}\n", "src_uid": "a13cb35197f896cd34614c6c0b369a49"} {"source_code": "import java.util.*;\n\npublic class p47A {\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\n\t\tint n = in.nextInt();\n\n\t\tboolean found = false;\n\t\tfor(int i=1; i<=n+1; ++i) {\n\t\t\tif(i*(i-1)/2 == n) {\n\t\t\t\tfound = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tif(found == true) System.out.println(\"YES\");\n\t\telse System.out.println(\"NO\");\n\t}\n}", "src_uid": "587d4775dbd6a41fc9e4b81f71da7301"} {"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<n;++i) circles[i] = readCircle();\n long mc = maxCut();\n long res = n + k * (mc + mc + k - 1) / 2;\n System.out.println(res);\n }\n \n private int maxCut() {\n int res = 1;\n for(int i=0;i<circles.length;i++) res = Math.max(res, maxCut(i));\n return res;\n }\n\n private static final double EPSILON = 1e-10;\n \n private int maxCut(int a) {\n Circle A = circles[a];\n ArrayList<Angle> angles = new ArrayList<Angle>();\n int cnt = 1;\n int best = 1;\n for(int b=0;b<circles.length;b++) {\n if(b==a) continue;\n Circle B = circles[b];\n double alpha = Math.atan2(B.y - A.y, B.x - A.x);\n double beta = Math.asin((B.r - A.r) / Math.hypot(B.y-A.y, B.x-A.x)) - EPSILON;\n double gamma = Math.asin((B.r + A.r) / Math.hypot(B.y-A.y, B.x-A.x)) - EPSILON;\n double a1 = modulo(alpha-beta);\n double a2 = modulo(alpha+gamma);\n double b1 = modulo(alpha-gamma+Math.PI);\n double b2 = modulo(alpha+beta+Math.PI); \n if(a1 > 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<Angle> {\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 boolean minus = false;\n if(nextChar=='-') { minus=true; move(); } \n while(nextChar >= '0' && nextChar <= '9') {\n res = 10*res + (nextChar-'0');\n move();\n }\n if (minus) res = -res;\n return res;\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", "src_uid": "06ec7e481c963e635a6303503ffccc8b"} {"source_code": "import java.util.*;\n\npublic class Solution {\n\n public static void main(String[] args) throws java.lang.Exception {\n Scanner in = new Scanner(System.in);\n String ch = in.next();\n int s = 0;\n String[] ch2 = {\"Danil\", \"Olya\", \"Slava\", \"Ann\", \"Nikita\"};\n for (int i = 0; i < ch2.length; i++) {\n while (ch.contains(ch2[i])) {\n ch = ch.replaceFirst(ch2[i], \".\");\n s++;\n }\n }\n if (s == 1) {\n System.out.println(\"YES\");\n } else {\n System.out.println(\"NO\");\n }\n\n }\n}", "src_uid": "db2dc7500ff4d84dcc1a37aebd2b3710"} {"source_code": "import java.util.*;\n\npublic class problem {\n public static int[] need = new int[5];\n public static int[] a = new int[5];\n public static int[] p = new int[5];\n public static long r;\n public static long max( long a , long b ) {\n if ( a > b ) return a; else return b;\n }\n public static boolean check( long cake ) {\n long req = 0;\n long money = 0;\n for( int i = 1; i < 4; i ++ ) {\n req = cake * need[i] - a[i];\n money += max( req , 0 ) * p[i];\n //System.out.println( money );\n //System.out.println( cake );\n if ( money > r ) return false;\n }\n return true;\n }\n public static void main( String[] args ) {\n Scanner input = new Scanner( System.in );\n long res = 0;\n String s = input.nextLine();\n for( int i = 0; i < s.length(); i ++ ) {\n if ( s.charAt( i ) == 'B' ) need[1] ++;\n if ( s.charAt( i ) == 'S' ) need[2] ++;\n if ( s.charAt( i ) == 'C' ) need[3] ++;\n }\n for( int i = 1; i < 4; i ++ ) a[i] = input.nextInt();\n for( int i = 1; i < 4; i ++ ) p[i] = input.nextInt();\n r = input.nextLong();\n long low = 0; long high = (long)1E15;\n while ( low <= high ) {\n long mid = ( low + high ) / 2;\n if ( check( mid ) ) {\n low = mid + 1;\n //System.out.println( \"abcdef\" );\n res = mid;\n }\n else high = mid - 1;\n }\n System.out.println( res );\n }\n}\n", "src_uid": "8126a4232188ae7de8e5a7aedea1a97e"} {"source_code": "\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.Scanner;\n\npublic class Lentgh {\n\n static InputReader in = new InputReader(System.in);\n static PrintWriter out = new PrintWriter(System.out);\n\n public static void main(String[] args) {\n long num = in.nextLong();\n long num1=in.nextLong();\n long count=0;\n int i=1;\n while(i<=num){\n count=count+(num1+i)*1/5-i/5;\n i++;\n }\n System.out.println(count);\n \n }\n}\nclass InputReader {\n\n private final InputStream stream;\n private final byte[] buf = new byte[8192];\n private int curChar, snumChars;\n\n public InputReader(InputStream st) {\n this.stream = st;\n }\n\n public int read() {\n if (snumChars == -1) {\n throw new InputMismatchException();\n }\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 = 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 }\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}", "src_uid": "df0879635b59e141c839d9599abd77d2"} {"source_code": "import java.util.*;\n\npublic class A {\n\tstatic void tri(int tab[],int taille)\n\t{\n\t int i, j;\n\t for (i = 1; i < taille; ++i) {\n\t int elem = tab[i];\n\t for (j = i; j > 0 && tab[j-1] > elem; j--)\n\t tab[j] = tab[j-1];\n\t tab[j] = elem;\n\t }}\n\t\n\n\tpublic static void main(String[] args) {\n\t\tint c=0;\n\t\tScanner s=new Scanner (System.in);\n\t\tint n=s.nextInt();\n\t\tint d=s.nextInt();s.nextLine();\n\t\tint [] tab=new int[n];\n\t\tList<Integer> l=new ArrayList<>();\n\t\tfor (int i=0;i<n;i++) {\n\t\t\ttab[i]=s.nextInt();\n\t\t}\n\t\t\n\t\ttri(tab,n);\n\t\tif(n<=1) {\n\t\t\tSystem.out.println(0);\n\t\t\t}\n\t\telse {\n\t\tfor (int i=0;i<n-1;i++) {\n\t\t\tc=c+1;\n\t\t\tfor (int j=i+1;j<n;j++) {\n\t\t\t\t\n\t\t\t if(tab[j]-tab[i]<=d) {\n\t\t\t\tc=c+1;}}\n\t\t\t l.add(c);c=0;\n\t\t\t }Collections.sort(l);\n\t\t\t \n\t\t\t \n\t\t\t \n\t\t\t \n\t\tSystem.out.println(n-l.get(l.size()-1));}\n\t }}\n", "src_uid": "6bcb324c072f796f4d50bafea5f624b2"} {"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\tif (str == null || !str.hasMoreElements())\n\t\t\tstr = new StringTokenizer(in.readLine());\n\t\treturn str.nextToken();\n\t}\n\t\n\tprivate int nextInt() throws Exception{\n\t\treturn Integer.parseInt(next());\n\t}\n\t\n\tprivate long nextLong() throws Exception{\n\t\treturn Long.parseLong(next());\n\t}\n\t\n\tprivate double nextDouble() throws Exception{\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tint dx[] = new int[]{1, 0, -1, 0};\n\tint dy[] = new int[]{0, -1, 0, 1};\n\n\tint n,m;\n\tchar maze[][];\n\tint state[][];\n\n\tboolean used[][][];\n\tint d[][][];\n\t\n\tpublic void run() throws Exception{\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\n\t\tn = nextInt();\n\t\tm = nextInt();\n\n\t\tint sx = -1;\n\t\tint sy = -1;\n\n\t\tstate = new int[n][m];\n\n\t\tint treasure = 0;\n\t\tmaze = new char[n][m];\n\t\tfor(int i=0;i<n;i++){\n\t\t\tmaze[i] = next().toCharArray();\n\t\t\tfor(int j=0;j<m;j++){\n\t\t\t\tif (maze[i][j] == 'S') {\n\t\t\t\t\tsx = i;\n\t\t\t\t\tsy = j;\n\t\t\t\t\tmaze[i][j] = '.';\n\t\t\t\t}else if ('0' <= maze[i][j] && maze[i][j] <= '9') {\n\t\t\t\t\tint idx = maze[i][j] - '1';\n\t\t\t\t\tfor(int k=j+1;k<m;k++){\n\t\t\t\t\t\tstate[i][k]|=1<<idx;\n\t\t\t\t\t}\n\t\t\t\t\ttreasure++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint []a = new int[treasure];\n\t\tfor(int i=0;i<treasure;i++) a[i] = nextInt();\n\n\t\tint sum[] = new int[1<<10];\n\t\tfor(int i=0;i<1<<treasure;i++) {\n\t\t\tfor(int j=0;j<treasure;j++) {\n\t\t\t\tif ((i & (1<<j)) > 0) {\n\t\t\t\t\tsum[i]+=a[j];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tint bomb = treasure;\n\t\tfor(int i=0;i<n;i++){\n\t\t\tfor(int j=0;j<m;j++){\n\t\t\t\tif (maze[i][j] == 'B') {\n\t\t\t\t\tfor(int k=j+1;k<m;k++){\n\t\t\t\t\t\tstate[i][k]|=1<<bomb;\n\t\t\t\t\t}\n\t\t\t\t\tbomb++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tused = new boolean[n][m][1<<bomb];\n\t\td = new int[n][m][1<<bomb];\n\n\t\tbfs(sx, sy);\n\t\tint ans = 0;\n\t\tfor(int i=0;i<1<<treasure;i++){\n\t\t\tif (used[sx][sy][i]) {\n\t\t\t\tans = Math.max(ans, sum[i] - d[sx][sy][i]);\n\t\t\t}\n\t\t}\n\n\t\tout.println(ans);\n\t\tout.close();\n\t}\n\n\tQueue<int[]> q;\n\n\tprivate void bfs(int sx, int sy) {\n\t\tq = new LinkedList<int[]>();\n\t\tq.add(new int[]{sx, sy, 0});\n\t\tused[sx][sy][0] = true;\n\t\td[sx][sy][0] = 0;\n\n\t\twhile(q.size() > 0){\n\t\t\tint cur[] = q.poll();\n\t\t\tint x = cur[0], y = cur[1], nst = cur[2];\n\n\t\t\tfor(int i=0;i<4;i++){\n\t\t\t\tint nx = x + dx[i], ny = y + dy[i], nstate = nst;\n\t\t\t\tif (!can(nx, ny)) continue;\n\t\t\t\tif (dx[i] == 1) {\n\t\t\t\t\tnstate^=state[nx][ny];\n\t\t\t\t}else if (dx[i] == -1) {\n\t\t\t\t\tnstate^=state[x][y];\n\t\t\t\t}\n\n\t\t\t\tif (used[nx][ny][nstate]) continue;\n\t\t\t\tused[nx][ny][nstate] = true;\n\t\t\t\td[nx][ny][nstate] = d[x][y][nst] + 1;\n\t\t\t\tq.add(new int[]{nx, ny, nstate});\n\t\t\t}\n\t\t}\n\t}\n\t\t\n\tprivate boolean can(int x, int y) {\n\t\tif (x < 0 || y < 0) return false;\n\t\tif (x >=n || y >= m) return false;\n\t\tif (maze[x][y] != '.') return false;\n\t\treturn true;\n\t}\n\n\tpublic static void main(String[] args) throws Exception{\n\t\tnew Main().run();\n\t}\n}\n", "src_uid": "624a0d6cf305fcf67d3f1cdc1c5fef8d"} {"source_code": "import java.util.*;\nimport java.math.*;\npublic class chess\n{\npublic static void main(String[] args)\n{\nScanner input = new Scanner(System.in);\nString rook = input.next();\nString knight = input.next();\nint counter = 0;\nchar rowr = rook.substring(0,1).charAt(0);\nint colr = Integer.parseInt(rook.substring(1,2));\nchar rowk = knight.substring(0,1).charAt(0);\nint colk = Integer.parseInt(knight.substring(1,2));\nchar[] rows = new char[8];\nint[] cols = new int[8];\nfor(int i = 0; i < 8; i++)\n{\nrows[i] = (char)('a' + i);\ncols[i] = 1 + i;\n}\nfor(int i = 0; i < 8; i++)\n{\nfor(int j = 0; j < 8; j++)\n{\nBoolean legit = true;\nif((rows[i] == rowr) || (cols[j] == (colr)))\nlegit = false;\nelse if((Math.abs(rows[i]-rowk) + Math.abs(cols[j]-colk) == 3) && (Math.abs(rows[i]-rowk) < 3) && (Math.abs(cols[j]-colk) < 3))\nlegit = false;\nelse if((Math.abs(rows[i]-rowr) + Math.abs(cols[j]-colr) == 3) && (Math.abs(rows[i]-rowr) < 3) && (Math.abs(cols[j]-colr) < 3))\nlegit = false;\nelse if((rows[i]==rowk) && (cols[j]==colk))\nlegit = false;\nif(legit)\n{\ncounter++;\n}\n}\n}\nSystem.out.println(counter);\n}\n}", "src_uid": "073023c6b72ce923df2afd6130719cfc"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF {\n FastScanner in;\n PrintWriter out;\n\n int mod = (int) 1e15 + 7;\n int mul = 37;\n\n class Obj {\n int[] vals;\n int[] moves;\n\n public Obj(int[] vals, int[] moves) {\n super();\n this.vals = vals;\n this.moves = moves;\n }\n\n long hh() {\n long res = 0;\n for (int i = 0; i < vals.length; i++) {\n res = (vals[i] + res * mul) % mod;\n }\n return res;\n }\n\n long hh2() {\n long res = 0;\n for (int i = 0; i < vals.length; i++) {\n res = (vals[i] + res * mul) % mod;\n }\n for (int i = 0; i < vals.length; i++) {\n res = (moves[i] + res * mul) % mod;\n }\n return res;\n }\n }\n\n long getAns2(int x, int y) {\n /*\n if (x <= y) {\n long res = 1;\n for (int i = 1; i <= x + y; i++) {\n res *= i;\n res %= mod;\n }\n return res;\n }\n */\n long[] v1 = { 1, 1, 2, 4, 10, 26, 76, 232, 764, 2620, 9496, 35696,\n 140152, 568504, 2390480, 10349536, 46206736, 211799312,\n 997313824, 4809701440L, 23758664096L, 119952692896L };\n long res = v1[x];\n for (int i = 0; i < y; i++) {\n res = (res * (x + i + 1)) % mod;\n }\n return res;\n }\n\n long getAns(int x, int y) {\n if (x <= y) {\n long res = 1;\n for (int i = 1; i <= x + y; i++)\n res *= i;\n return res;\n }\n int n = x + y;\n int[] vals = new int[n];\n int[] moves = new int[n];\n for (int i = 0; i < n; i++) {\n vals[i] = i + 1;\n if (i < x) {\n moves[i] = 1;\n } else {\n moves[i] = 2;\n }\n }\n Obj o1 = new Obj(vals, moves);\n HashSet<Long> hs = new HashSet<>();\n HashSet<Long> hs2 = new HashSet<>();\n hs2.add(o1.hh2());\n ArrayList<Obj> ar = new ArrayList<>();\n ar.add(o1);\n int it = 0;\n while (it < ar.size()) {\n Obj o = ar.get(it);\n hs.add(o.hh());\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n if (i != j) {\n if (o.moves[i] > 0 && o.moves[j] > 0) {\n int[] vals1 = new int[n];\n int[] mov1 = new int[n];\n for (int k = 0; k < n; k++) {\n vals1[k] = o.vals[k];\n mov1[k] = o.moves[k];\n }\n mov1[i]--;\n mov1[j]--;\n int tmp = vals1[i];\n vals1[i] = vals1[j];\n vals1[j] = tmp;\n Obj next = new Obj(vals1, mov1);\n long hh = next.hh2();\n if (hs2.contains(hh))\n continue;\n hs2.add(hh);\n ar.add(next);\n }\n }\n }\n }\n it++;\n }\n\n return hs.size();\n }\n\n void solve() {\n /*\n * int n = 10; System.err.println(getAns2(3, 3)); for (int i = 0; i < n;\n * i++) { long last = 1; for (int j = 0; j < n; j++) { long nn =\n * getAns(i, j); System.out.print(nn / last + \" \"); last = nn; }\n * System.out.println(); }\n */\n\n int n = in.nextInt();\n int f = 0;\n for (int i = 0; i < n; i++) {\n if (in.nextInt() == 1) {\n f++;\n }\n }\n out.println(getAns2(f, n - f));\n\n }\n\n void run() {\n try {\n in = new FastScanner(new File(\"object.in\"));\n out = new PrintWriter(new File(\"object.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\n public static void main(String[] args) {\n new CF().runIO();\n }\n}", "src_uid": "91e8dbe94273e255182aca0f94117bb9"} {"source_code": "import java.util.*;\nimport java.io.*;\n\npublic class WhiteSheet {\n public static void main(String[] args) {\n FastScanner scanner = new FastScanner();\n PrintWriter out = new PrintWriter(System.out,false);\n int x1 = scanner.nextInt();\n int y1 = scanner.nextInt();\n int x2 = scanner.nextInt();\n int y2 = scanner.nextInt();\n int x3 = scanner.nextInt();\n int y3 = scanner.nextInt();\n int x4 = scanner.nextInt();\n int y4 = scanner.nextInt();\n int x5 = scanner.nextInt();\n int y5 = scanner.nextInt();\n int x6 = scanner.nextInt();\n int y6 = scanner.nextInt();\n if (x1 >= x3 && x2 <= x4 && y1 >= y3 && y2 <= y4) {\n out.println(\"NO\");\n }\n else if (x1 >= x5 && x2 <= x6 && y1 >= y5 && y2 <= y6) {\n out.println(\"NO\");\n }\n else if (x1 >= x5 && x2 <= x6 &&x1 >= x3 && x2 <= x4 &&y1>=y3 && y4>=y5 && y2 <= y6) {\n out.println(\"NO\");\n }\n else if (x1 >= x5 && x2 <= x6 &&x1 >= x3 && x2 <= x4 &&y1>=y5 && y6>=y3 && y2 <= y4) {\n out.println(\"NO\");\n }\n else if (y1 >= y5 && y2 <= y6 &&y1 >= y3 && y2 <= y4 &&x1>=x5 && x6>=x3 && x2 <= x4) {\n out.println(\"NO\");\n }\n else if (y1 >= y5 && y2 <= y6 &&y1 >= y3 && y2 <= y4 &&x1>=x3 && x4>=x5 && x2 <= x6) {\n out.println(\"NO\");\n }\n else out.println(\"YES\");\n out.flush();\n }\n \n public static class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n \n public FastScanner(Reader in) {\n br = new BufferedReader(in);\n }\n \n public FastScanner() {\n this(new InputStreamReader(System.in));\n }\n \n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n \n int nextInt() {\n return Integer.parseInt(next());\n }\n \n long nextLong() {\n return Long.parseLong(next());\n }\n \n double nextDouble() {\n return Double.parseDouble(next());\n }\n \n String readNextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n }\n}\n", "src_uid": "05c90c1d75d76a522241af6bb6af7781"} {"source_code": "//package round791;\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 F2 {\r\n\tInputStream is;\r\n\tFastWriter out;\r\n\tString INPUT = \"\";\r\n\t\r\n\tvoid solve()\r\n\t{\r\n\t\tint n = ni();\r\n\t\tboolean[][] g = new boolean[10][10];\r\n\t\tfor(int m = ni();m > 0;m--){\r\n\t\t\tint x = ni(), y = ni();\r\n\t\t\tg[x][y] = g[y][x] = true;\r\n\t\t}\r\n\t\tfor(int i = 0;i < 10;i++)g[i][i] = true;\r\n\r\n\t\tint[][] njs = new int[1<<9][10];\r\n\t\tfor(int j = 0;j < 1<<9;j++) {\r\n\t\t\tfor (int k = 0; k < 10; k++) {\r\n\t\t\t\tif (j << ~k >= 0) {\r\n\t\t\t\t\tint nj = j;\r\n\t\t\t\t\tfor (int l = 0; l < 10; l++) {\r\n\t\t\t\t\t\tif (g[k][l]) {\r\n\t\t\t\t\t\t\tif (k > l) {\r\n\t\t\t\t\t\t\t\tnj |= 1 << l;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\tnj &= ~(1 << l);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tnjs[j][k] = nj;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\r\n\t\tlong[] dp = new long[1<<9];\r\n\t\tdp[0] = 1;\r\n\t\tfor(int i = 1;i <= n;i++){\r\n\t\t\tlong[] ndp = new long[1<<9];\r\n\t\t\tfor(int j = 0;j < 1<<9;j++){\r\n\t\t\t\tfor(int k = 0;k < 10;k++){\r\n\t\t\t\t\tif (j << ~k >= 0) {\r\n\t\t\t\t\t\tint nj = njs[j][k];\r\n\t\t\t\t\t\tndp[nj] += dp[j];\r\n\t\t\t\t\t\tif(ndp[nj] >= mod)ndp[nj] -= mod;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tdp = ndp;\r\n\t\t}\r\n\t\tlong ans = sum(dp) % mod;\r\n\t\tout.println(ans);\r\n\t}\r\n\r\n\tpublic static long sum(long... a){long ret = 0; for(long v : a)ret += v; return ret;}\r\n\r\n\r\n\tpublic static final int mod = 998244353;\r\n\tpublic static final int G = 3;\r\n\r\n\t// only 998244353\r\n\tpublic static long[] mul(long[] a, long[] b)\r\n\t{\r\n\t\tif(a.length == 0 && b.length == 0)return new long[0];\r\n\t\tif(a.length + b.length >= 300) {\r\n\t\t\treturn Arrays.copyOf(NTTStockham998244353.convolve(a, b), a.length + b.length - 1);\r\n\t\t}else{\r\n\t\t\treturn mulnaive(a, b);\r\n\t\t}\r\n\t}\r\n\r\n\tpublic static long[] mul(long[] a, long[] b, int lim)\r\n\t{\r\n\t\tif(a.length + b.length >= 300) {\r\n\t\t\treturn Arrays.copyOf(NTTStockham998244353.convolve(a, b), lim);\r\n\t\t}else{\r\n\t\t\treturn mulnaive(a, b, lim);\r\n\t\t}\r\n\t}\r\n\r\n\t//\tpublic static final int mod = 1000000007;\r\n\t//\tpublic static long[] mul(long[] a, long[] b)\r\n\t//\t{\r\n\t//\t\tif(Math.max(a.length, b.length) >= 3000){\r\n\t//\t\t\treturn Arrays.copyOf(NTTCRT.convolve(a, b, 3, mod), a.length+b.length-1);\r\n\t//\t\t}else{\r\n\t//\t\t\treturn mulnaive(a, b);\r\n\t//\t\t}\r\n\t//\t}\r\n\r\n\t//\tpublic static long[] mul(long[] a, long[] b, int lim)\r\n\t//\t{\r\n\t//\t\tif(Math.max(a.length, b.length) >= 3000){\r\n\t//\t\t\treturn Arrays.copyOf(NTTCRT.convolve(a, b, 3, mod), lim);\r\n\t//\t\t}else{\r\n\t//\t\t\treturn mulnaive(a, b, lim);\r\n\t//\t\t}\r\n\t//\t}\r\n\r\n\tpublic static final long big = (Long.MAX_VALUE/mod/mod-1)*mod*mod;\r\n\r\n\tpublic static long[] mulnaive(long[] a, long[] b)\r\n\t{\r\n\t\tlong[] c = new long[a.length+b.length-1];\r\n\t\tfor(int i = 0;i < a.length;i++){\r\n\t\t\tfor(int j = 0;j < b.length;j++){\r\n\t\t\t\tc[i+j] += a[i]*b[j];\r\n\t\t\t\tif(c[i+j] >= big)c[i+j] -= big;\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(int i = 0;i < c.length;i++)c[i] %= mod;\r\n\t\treturn c;\r\n\t}\r\n\r\n\tpublic static long[] mulnaive(long[] a, long[] b, int lim)\r\n\t{\r\n\t\tlong[] c = new long[lim];\r\n\t\tfor(int i = 0;i < a.length;i++){\r\n\t\t\tfor(int j = 0;j < b.length && i+j < lim;j++){\r\n\t\t\t\tc[i+j] += a[i]*b[j];\r\n\t\t\t\tif(c[i+j] >= big)c[i+j] -= big;\r\n\t\t\t}\r\n\t\t}\r\n\t\tfor(int i = 0;i < c.length;i++)c[i] %= mod;\r\n\t\treturn c;\r\n\t}\r\n\r\n\r\n\tpublic static class NTTStockham998244353 {\r\n\t\tprivate static final int P = 998244353, mod = P, G = 3;\r\n\t\tprivate static long[] wps;\r\n\r\n\t\tpublic static long[] convolve(long[] a, long[] b)\r\n\t\t{\r\n\t\t\tint m = Math.max(2, Integer.highestOneBit(Math.max(a.length, b.length)-1)<<2);\r\n\r\n\t\t\twps = new long[m];\r\n\t\t\tlong unit = pow(G, (P-1)/m);\r\n\t\t\twps[0] = 1;\r\n\t\t\tfor(int p = 1;p < m;p++) {\r\n\t\t\t\twps[p] = wps[p-1] * unit % mod;\r\n\t\t\t}\r\n\r\n\t\t\tlong[] fa = go(a, m, false);\r\n\t\t\tlong[] fb = a == b ? fa : go(b, m, false);\r\n\t\t\tfor(int i = 0;i < m;i++){\r\n\t\t\t\tfa[i] = fa[i]*fb[i] % mod;\r\n\t\t\t}\r\n\t\t\tfa = go(fa, m, true);\r\n\t\t\tfor(int i = 1, j = m-1;i < j;i++,j--) {\r\n\t\t\t\tlong d = fa[i]; fa[i] = fa[j]; fa[j] = d;\r\n\t\t\t}\r\n\t\t\treturn fa;\r\n\t\t}\r\n\r\n\t\tprivate static void fft(long[] X, long[] Y)\r\n\t\t{\r\n\t\t\tint s = 1;\r\n\t\t\tboolean eo = false;\r\n\t\t\tfor(int n = X.length;n >= 4;n /= 2) {\r\n\t\t\t\tint m = n/2;\r\n\t\t\t\tfor(int p = 0;p < m;p++) {\r\n\t\t\t\t\tlong wp = wps[s*p];\r\n\t\t\t\t\tlong wk = (wp<<32)/P;\r\n\t\t\t\t\tfor(int q = 0;q < s;q++) {\r\n\t\t\t\t\t\tlong a = X[q + s*(p+0)];\r\n\t\t\t\t\t\tlong b = X[q + s*(p+m)];\r\n\t\t\t\t\t\tlong ndsts = a + b;\r\n\t\t\t\t\t\tif(ndsts >= 2*P)ndsts -= 2*P;\r\n\t\t\t\t\t\tlong T = a - b + 2*P;\r\n\t\t\t\t\t\tlong Q = wk*T>>>32;\r\n\t\t\t\t\t\tY[q + s*(2*p+0)] = ndsts;\r\n\t\t\t\t\t\tY[q + s*(2*p+1)] = wp*T-Q*P&(1L<<32)-1;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\ts *= 2;\r\n\t\t\t\teo = !eo;\r\n\t\t\t\tlong[] D = X; X = Y; Y = D;\r\n\t\t\t}\r\n\t\t\tlong[] z = eo ? Y : X;\r\n\t\t\tfor(int q = 0;q < s;q++) {\r\n\t\t\t\tlong a = X[q + 0];\r\n\t\t\t\tlong b = X[q + s];\r\n\t\t\t\tz[q+0] = (a+b) % P;\r\n\t\t\t\tz[q+s] = (a-b+2*P) % P;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t//\tprivate static void fft(long[] X, long[] Y)\r\n\t\t//\t{\r\n\t\t//\t\tint s = 1;\r\n\t\t//\t\tboolean eo = false;\r\n\t\t//\t\tfor(int n = X.length;n >= 4;n /= 2) {\r\n\t\t//\t\t\tint m = n/2;\r\n\t\t//\t\t\tfor(int p = 0;p < m;p++) {\r\n\t\t//\t\t\t\tlong wp = wps[s*p];\r\n\t\t//\t\t\t\tfor(int q = 0;q < s;q++) {\r\n\t\t//\t\t\t\t\tlong a = X[q + s*(p+0)];\r\n\t\t//\t\t\t\t\tlong b = X[q + s*(p+m)];\r\n\t\t//\t\t\t\t\tY[q + s*(2*p+0)] = (a+b) % P;\r\n\t\t//\t\t\t\t\tY[q + s*(2*p+1)] = (a-b+P) * wp % P;\r\n\t\t//\t\t\t\t}\r\n\t\t//\t\t\t}\r\n\t\t//\t\t\ts *= 2;\r\n\t\t//\t\t\teo = !eo;\r\n\t\t//\t\t\tlong[] D = X; X = Y; Y = D;\r\n\t\t//\t\t}\r\n\t\t//\t\tlong[] z = eo ? Y : X;\r\n\t\t//\t\tfor(int q = 0;q < s;q++) {\r\n\t\t//\t\t\tlong a = X[q + 0];\r\n\t\t//\t\t\tlong b = X[q + s];\r\n\t\t//\t\t\tz[q+0] = (a+b) % P;\r\n\t\t//\t\t\tz[q+s] = (a-b+P) % P;\r\n\t\t//\t\t}\r\n\t\t//\t}\r\n\r\n\t\tprivate static long[] go(long[] src, int n, boolean inverse)\r\n\t\t{\r\n\t\t\tlong[] dst = Arrays.copyOf(src, n);\r\n\t\t\tfft(dst, new long[n]);\r\n\t\t\tif(inverse){\r\n\t\t\t\tlong in = invl(n);\r\n\t\t\t\tfor(int i = 0;i < n;i++){\r\n\t\t\t\t\tdst[i] = dst[i] * in % mod;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\treturn dst;\r\n\t\t}\r\n\r\n\t\tprivate static long pow(long a, long n) {\r\n\t\t\t//\t\ta %= mod;\r\n\t\t\tlong ret = 1;\r\n\t\t\tint x = 63 - Long.numberOfLeadingZeros(n);\r\n\t\t\tfor (; x >= 0; x--) {\r\n\t\t\t\tret = ret*ret % mod;\r\n\t\t\t\tif (n<<~x<0)ret = ret*a%mod;\r\n\t\t\t}\r\n\t\t\treturn ret;\r\n\t\t}\r\n\r\n\t\tprivate static long invl(long a) {\r\n\t\t\tlong b = mod;\r\n\t\t\tlong p = 1, q = 0;\r\n\t\t\twhile (b > 0) {\r\n\t\t\t\tlong c = a / b;\r\n\t\t\t\tlong d;\r\n\t\t\t\td = a;\r\n\t\t\t\ta = b;\r\n\t\t\t\tb = d % b;\r\n\t\t\t\td = p;\r\n\t\t\t\tp = q;\r\n\t\t\t\tq = d - c * q;\r\n\t\t\t}\r\n\t\t\treturn p < 0 ? p + mod : p;\r\n\t\t}\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\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\tpublic static class DJSet {\r\n\t\tpublic int[] upper;\r\n\r\n\t\tpublic DJSet(int n) {\r\n\t\t\tupper = new int[n];\r\n\t\t\tArrays.fill(upper, -1);\r\n\t\t}\r\n\r\n\t\tpublic int root(int x) {\r\n\t\t\treturn upper[x] < 0 ? x : (upper[x] = root(upper[x]));\r\n\t\t}\r\n\r\n\t\tpublic boolean equiv(int x, int y) {\r\n\t\t\treturn root(x) == root(y);\r\n\t\t}\r\n\r\n\t\tpublic boolean unite(int x, int y) {\r\n\t\t\tx = root(x);\r\n\t\t\ty = root(y);\r\n\t\t\tif (x != y) {\r\n\t\t\t\tif (upper[y] < upper[x]) {\r\n\t\t\t\t\tint d = x;\r\n\t\t\t\t\tx = y;\r\n\t\t\t\t\ty = d;\r\n\t\t\t\t}\r\n\t\t\t\tupper[x] += upper[y];\r\n\t\t\t\tupper[y] = x;\r\n\t\t\t}\r\n\t\t\treturn x == y;\r\n\t\t}\r\n\r\n\t\tpublic int count() {\r\n\t\t\tint ct = 0;\r\n\t\t\tfor (int u : upper) if (u < 0) ct++;\r\n\t\t\treturn ct;\r\n\t\t}\r\n\r\n\t\tpublic int[][] toBucket() {\r\n\t\t\tint n = upper.length;\r\n\t\t\tint[][] ret = new int[n][];\r\n\t\t\tint[] rp = new int[n];\r\n\t\t\tfor (int i = 0; i < n; i++) if (upper[i] < 0) ret[i] = new int[-upper[i]];\r\n\t\t\tfor (int i = 0; i < n; i++) {\r\n\t\t\t\tint r = root(i);\r\n\t\t\t\tret[r][rp[r]++] = i;\r\n\t\t\t}\r\n\t\t\treturn ret;\r\n\t\t}\r\n\t}\r\n\r\n\r\n\tvoid run() throws Exception\r\n\t{\r\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\r\n\t\tout = new FastWriter(System.out);\r\n\t\t\r\n\t\tlong s = System.currentTimeMillis();\r\n\t\tsolve();\r\n\t\tout.flush();\r\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) throws Exception { new F2().run(); }\r\n\t\r\n\tprivate byte[] inbuf = new byte[1024];\r\n\tpublic int lenbuf = 0, ptrbuf = 0;\r\n\t\r\n\tprivate int readByte()\r\n\t{\r\n\t\tif(lenbuf == -1)throw new InputMismatchException();\r\n\t\tif(ptrbuf >= lenbuf){\r\n\t\t\tptrbuf = 0;\r\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\r\n\t\t\tif(lenbuf <= 0)return -1;\r\n\t\t}\r\n\t\treturn inbuf[ptrbuf++];\r\n\t}\r\n\t\r\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\r\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\r\n\t\r\n\tprivate double nd() { return Double.parseDouble(ns()); }\r\n\tprivate char nc() { return (char)skip(); }\r\n\t\r\n\tprivate String ns()\r\n\t{\r\n\t\tint b = skip();\r\n\t\tStringBuilder sb = new StringBuilder();\r\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\r\n\t\t\tsb.appendCodePoint(b);\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t\treturn sb.toString();\r\n\t}\r\n\t\r\n\tprivate char[] ns(int n)\r\n\t{\r\n\t\tchar[] buf = new char[n];\r\n\t\tint b = skip(), p = 0;\r\n\t\twhile(p < n && !(isSpaceChar(b))){\r\n\t\t\tbuf[p++] = (char)b;\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\r\n\t}\r\n\r\n\tprivate int[] na(int n)\r\n\t{\r\n\t\tint[] a = new int[n];\r\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\r\n\t\treturn a;\r\n\t}\r\n\r\n\tprivate long[] nal(int n)\r\n\t{\r\n\t\tlong[] a = new long[n];\r\n\t\tfor(int i = 0;i < n;i++)a[i] = nl();\r\n\t\treturn a;\r\n\t}\r\n\r\n\tprivate char[][] nm(int n, int m) {\r\n\t\tchar[][] map = new char[n][];\r\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\r\n\t\treturn map;\r\n\t}\r\n\r\n\tprivate int[][] nmi(int n, int m) {\r\n\t\tint[][] map = new int[n][];\r\n\t\tfor(int i = 0;i < n;i++)map[i] = na(m);\r\n\t\treturn map;\r\n\t}\r\n\r\n\tprivate int ni() { return (int)nl(); }\r\n\r\n\tprivate long nl()\r\n\t{\r\n\t\tlong num = 0;\r\n\t\tint b;\r\n\t\tboolean minus = false;\r\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\r\n\t\tif(b == '-'){\r\n\t\t\tminus = true;\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\r\n\t\twhile(true){\r\n\t\t\tif(b >= '0' && b <= '9'){\r\n\t\t\t\tnum = num * 10 + (b - '0');\r\n\t\t\t}else{\r\n\t\t\t\treturn minus ? -num : num;\r\n\t\t\t}\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic static class FastWriter\r\n\t{\r\n\t\tprivate static final int BUF_SIZE = 1<<13;\r\n\t\tprivate final byte[] buf = new byte[BUF_SIZE];\r\n\t\tprivate final OutputStream out;\r\n\t\tprivate int ptr = 0;\r\n\r\n\t\tprivate FastWriter(){out = null;}\r\n\r\n\t\tpublic FastWriter(OutputStream os)\r\n\t\t{\r\n\t\t\tthis.out = os;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter(String path)\r\n\t\t{\r\n\t\t\ttry {\r\n\t\t\t\tthis.out = new FileOutputStream(path);\r\n\t\t\t} catch (FileNotFoundException e) {\r\n\t\t\t\tthrow new RuntimeException(\"FastWriter\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(byte b)\r\n\t\t{\r\n\t\t\tbuf[ptr++] = b;\r\n\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(char c)\r\n\t\t{\r\n\t\t\treturn write((byte)c);\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(char[] s)\r\n\t\t{\r\n\t\t\tfor(char c : s){\r\n\t\t\t\tbuf[ptr++] = (byte)c;\r\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(String s)\r\n\t\t{\r\n\t\t\ts.chars().forEach(c -> {\r\n\t\t\t\tbuf[ptr++] = (byte)c;\r\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\t});\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tprivate static int countDigits(int l) {\r\n\t\t\tif (l >= 1000000000) return 10;\r\n\t\t\tif (l >= 100000000) return 9;\r\n\t\t\tif (l >= 10000000) return 8;\r\n\t\t\tif (l >= 1000000) return 7;\r\n\t\t\tif (l >= 100000) return 6;\r\n\t\t\tif (l >= 10000) return 5;\r\n\t\t\tif (l >= 1000) return 4;\r\n\t\t\tif (l >= 100) return 3;\r\n\t\t\tif (l >= 10) return 2;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(int x)\r\n\t\t{\r\n\t\t\tif(x == Integer.MIN_VALUE){\r\n\t\t\t\treturn write((long)x);\r\n\t\t\t}\r\n\t\t\tif(ptr + 12 >= BUF_SIZE)innerflush();\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite((byte)'-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tint d = countDigits(x);\r\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\r\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\r\n\t\t\t\tx /= 10;\r\n\t\t\t}\r\n\t\t\tptr += d;\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tprivate static int countDigits(long l) {\r\n\t\t\tif (l >= 1000000000000000000L) return 19;\r\n\t\t\tif (l >= 100000000000000000L) return 18;\r\n\t\t\tif (l >= 10000000000000000L) return 17;\r\n\t\t\tif (l >= 1000000000000000L) return 16;\r\n\t\t\tif (l >= 100000000000000L) return 15;\r\n\t\t\tif (l >= 10000000000000L) return 14;\r\n\t\t\tif (l >= 1000000000000L) return 13;\r\n\t\t\tif (l >= 100000000000L) return 12;\r\n\t\t\tif (l >= 10000000000L) return 11;\r\n\t\t\tif (l >= 1000000000L) return 10;\r\n\t\t\tif (l >= 100000000L) return 9;\r\n\t\t\tif (l >= 10000000L) return 8;\r\n\t\t\tif (l >= 1000000L) return 7;\r\n\t\t\tif (l >= 100000L) return 6;\r\n\t\t\tif (l >= 10000L) return 5;\r\n\t\t\tif (l >= 1000L) return 4;\r\n\t\t\tif (l >= 100L) return 3;\r\n\t\t\tif (l >= 10L) return 2;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(long x)\r\n\t\t{\r\n\t\t\tif(x == Long.MIN_VALUE){\r\n\t\t\t\treturn write(\"\" + x);\r\n\t\t\t}\r\n\t\t\tif(ptr + 21 >= BUF_SIZE)innerflush();\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite((byte)'-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tint d = countDigits(x);\r\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\r\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\r\n\t\t\t\tx /= 10;\r\n\t\t\t}\r\n\t\t\tptr += d;\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(double x, int precision)\r\n\t\t{\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite('-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tx += Math.pow(10, -precision)/2;\r\n\t\t\t//\t\tif(x < 0){ x = 0; }\r\n\t\t\twrite((long)x).write(\".\");\r\n\t\t\tx -= (long)x;\r\n\t\t\tfor(int i = 0;i < precision;i++){\r\n\t\t\t\tx *= 10;\r\n\t\t\t\twrite((char)('0'+(int)x));\r\n\t\t\t\tx -= (int)x;\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(char c){\r\n\t\t\treturn write(c).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(int x){\r\n\t\t\treturn write(x).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(long x){\r\n\t\t\treturn write(x).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(double x, int precision){\r\n\t\t\treturn write(x, precision).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(int... xs)\r\n\t\t{\r\n\t\t\tboolean first = true;\r\n\t\t\tfor(int x : xs) {\r\n\t\t\t\tif (!first) write(' ');\r\n\t\t\t\tfirst = false;\r\n\t\t\t\twrite(x);\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(long... xs)\r\n\t\t{\r\n\t\t\tboolean first = true;\r\n\t\t\tfor(long x : xs) {\r\n\t\t\t\tif (!first) write(' ');\r\n\t\t\t\tfirst = false;\r\n\t\t\t\twrite(x);\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln()\r\n\t\t{\r\n\t\t\treturn write((byte)'\\n');\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(int... xs)\r\n\t\t{\r\n\t\t\treturn write(xs).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(long... xs)\r\n\t\t{\r\n\t\t\treturn write(xs).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(char[] line)\r\n\t\t{\r\n\t\t\treturn write(line).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(char[]... map)\r\n\t\t{\r\n\t\t\tfor(char[] line : map)write(line).writeln();\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(String s)\r\n\t\t{\r\n\t\t\treturn write(s).writeln();\r\n\t\t}\r\n\r\n\t\tprivate void innerflush()\r\n\t\t{\r\n\t\t\ttry {\r\n\t\t\t\tout.write(buf, 0, ptr);\r\n\t\t\t\tptr = 0;\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\tthrow new RuntimeException(\"innerflush\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void flush()\r\n\t\t{\r\n\t\t\tinnerflush();\r\n\t\t\ttry {\r\n\t\t\t\tout.flush();\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\tthrow new RuntimeException(\"flush\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic FastWriter print(byte b) { return write(b); }\r\n\t\tpublic FastWriter print(char c) { return write(c); }\r\n\t\tpublic FastWriter print(char[] s) { return write(s); }\r\n\t\tpublic FastWriter print(String s) { return write(s); }\r\n\t\tpublic FastWriter print(int x) { return write(x); }\r\n\t\tpublic FastWriter print(long x) { return write(x); }\r\n\t\tpublic FastWriter print(double x, int precision) { return write(x, precision); }\r\n\t\tpublic FastWriter println(char c){ return writeln(c); }\r\n\t\tpublic FastWriter println(int x){ return writeln(x); }\r\n\t\tpublic FastWriter println(long x){ return writeln(x); }\r\n\t\tpublic FastWriter println(double x, int precision){ return writeln(x, precision); }\r\n\t\tpublic FastWriter print(int... xs) { return write(xs); }\r\n\t\tpublic FastWriter print(long... xs) { return write(xs); }\r\n\t\tpublic FastWriter println(int... xs) { return writeln(xs); }\r\n\t\tpublic FastWriter println(long... xs) { return writeln(xs); }\r\n\t\tpublic FastWriter println(char[] line) { return writeln(line); }\r\n\t\tpublic FastWriter println(char[]... map) { return writeln(map); }\r\n\t\tpublic FastWriter println(String s) { return writeln(s); }\r\n\t\tpublic FastWriter println() { return writeln(); }\r\n\t}\r\n\r\n\tpublic void trnz(int... o)\r\n\t{\r\n\t\tfor(int i = 0;i < o.length;i++)if(o[i] != 0)System.out.print(i+\":\"+o[i]+\" \");\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\t// print ids which are 1\r\n\tpublic void trt(long... o)\r\n\t{\r\n\t\tQueue<Integer> 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}", "src_uid": "60955fc2caa6ec99c7dcc1da5d36b1f8"} {"source_code": "/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n\n\nimport java.util.Scanner;\n\n/**\n *\n * @author Tue\n */\npublic class Main {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n solve();\n }\n\n public static void solve() {\n Scanner input = new Scanner(System.in);\n String add = input.nextLine();\n String result = \"\";\n if (add.startsWith(\"http\")) {\n result += \"http://\";\n if (add.substring(4, add.indexOf(\"ru\")).equals(\"\")) {\n result += add.substring(4, add.lastIndexOf(\"ru\"));\n result += \".ru\";\n if (!add.substring(add.lastIndexOf(\"ru\") + 2).equals(\"\")) {\n result += \"/\" + add.substring(add.lastIndexOf(\"ru\") + 2);\n }\n } else {\n result += add.substring(4, add.indexOf(\"ru\"));\n result += \".ru\";\n if (!add.substring(add.indexOf(\"ru\") + 2).equals(\"\")) {\n result += \"/\" + add.substring(add.indexOf(\"ru\") + 2);\n }\n }\n } else {\n result += \"ftp://\";\n if (add.substring(3, add.indexOf(\"ru\")).equals(\"\")) {\n result += add.substring(3, add.lastIndexOf(\"ru\"));\n result += \".ru\";\n if (!add.substring(add.lastIndexOf(\"ru\") + 2).equals(\"\")) {\n result += \"/\" + add.substring(add.lastIndexOf(\"ru\") + 2);\n }\n } else {\n result += add.substring(3, add.indexOf(\"ru\"));\n result += \".ru\";\n if (!add.substring(add.indexOf(\"ru\") + 2).equals(\"\")) {\n result += \"/\" + add.substring(add.indexOf(\"ru\") + 2);\n }\n }\n }\n System.out.println(result);\n }\n}\n", "src_uid": "4c999b7854a8a08960b6501a90b3bba3"} {"source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n/*public class TaskA {\n\n}\n */\npublic class TaskA implements Runnable {\n\t// based on Petr's template\n\tprivate void solve() throws IOException {\n\t\tint t1 = this.nextInt();\n\t\tint t2 = this.nextInt();\n\t\tint x1 = this.nextInt();\n\t\tint x2 = this.nextInt();\n\t\tint t0 = this.nextInt();\n\t\tif ( t0 == t2 ){\n\t\t\tif ( t0 == t1 )\n\t\t\t\tSystem.out.println( x1 + \" \" + x2 );\n\t\t\telse\n\t\t\t\tSystem.out.println( 0 + \" \" + x2 );\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tlong my1 = 0;\n\t\tlong my2 = x2;\n\t\tfor ( int y1 = 0; y1 <= x1; y1 ++ ){\n\t\t\tint div = t2 - t0;\n\t\t\tlong y2 = ( 1L * t0 * y1 - 1L * t1 * y1 + div - 1 ) / div;\n\t\t\tif ( y2 > x2 )\n\t\t\t\tcontinue;\n\t\t\tlong u = 1L * t1 * y1 + 1L * t2 * y2;\n\t\t\tlong d = y1 + y2;\n\t\t\tlong U = 1L * t1 *my1 + 1L * t2 *my2;\n\t\t\tlong D =my1 +my2;\n\t\t\tu -= d * t0;\n\t\t\tU -= D * t0;\n\t\t\tif ( u * D < U * d || ( u * D == U * d && y1 + y2 >= my1 + my2 ) ){\n\t\t\t\tmy1 = y1;\n\t\t\t\tmy2 = y2;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println( my1 + \" \" + my2 );\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew TaskA().run();\n\t}\n\n\tBufferedReader reader;\n\tStringTokenizer tokenizer;\n\tPrintWriter writer;\n\n\tpublic void run() {\n\t\ttry {\n\t\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\t\twriter = new PrintWriter(new OutputStreamWriter(System.out));\n\t\t\ttokenizer = null;\n\t\t\tsolve();\n\t\t\treader.close();\n\t\t\twriter.close();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n\n\tboolean hasNext() throws IOException {\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\tString nextLine = reader.readLine();\n\t\t\tif (nextLine == null)\n\t\t\t\treturn false;\n\t\t\ttokenizer = new StringTokenizer(nextLine);\n\t\t}\n\n\t\treturn true;\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\tString nextLine() throws IOException {\n\t\treturn reader.readLine();\n\t}\n\n\tString nextToken() throws IOException {\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t}\n\n\t\treturn tokenizer.nextToken();\n\t}\n\n\tBigInteger nextBigInteger() throws IOException {\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t}\n\n\t\treturn new BigInteger(tokenizer.nextToken());\n\t}\n}", "src_uid": "87a500829c1935ded3ef6e4e47096b9f"} {"source_code": "\n//comment the next imports before submitting\nimport java.io.File;\nimport java.io.PrintStream;\n//imports to be deleted ends here\n\nimport java.io.BufferedReader;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.StringTokenizer;\n\n//Problem URL here\n\npublic class Domino353A {\n\n public static void solve() {\n\n }\n\n public static void main(String[] args) throws IOException {\n\n FastReader reader = new FastReader();\n\n // int t = reader.nextInt();\n // while (t-- > 0) {\n int n = reader.nextInt();\n boolean uO = false;\n boolean lO = false;\n int uSum = 0;\n int lSum = 0;\n\n // Integer arr[] = new Integer[n];\n\n for (int i = 0; i < n; i++) {\n int u = reader.nextInt();\n int l = reader.nextInt();\n if (u % 2 != 0 && l % 2 == 0) {\n uO = true;\n } else if (u % 2 == 0 && l % 2 != 0) {\n lO = true;\n }\n uSum += u;\n lSum += l;\n }\n\n if (uSum % 2 == 0 && lSum % 2 == 0) {\n System.out.println(0);\n } else if (uSum % 2 != 0 && lSum % 2 == 0) {\n System.out.println(-1);\n } else if (uSum % 2 == 0 && lSum % 2 != 0) {\n System.out.println(-1);\n } else {\n if (lO || uO) {\n System.out.println(1);\n } else {\n System.out.println(-1);\n }\n }\n\n // Arrays.sort(arr, new Comparator<Integer>() {\n // public int compare(Integer i1, Integer i2) {\n // return i1 - i2;\n // }\n // });\n\n // System.out.println(Arrays.toString(arr));\n\n // solve();\n // }\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\n}\n", "src_uid": "f9bc04aed2b84c7dd288749ac264bb43"} {"source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n \npublic class Main{\n \n public static double s(int ax, int ay, int bx, int by, int cx, int cy) {\n double d = Math.abs(ax * (by - cy) + bx * (cy - ay) + cx * (ay - by)) / 2.0;\n return d;\n }\n \n public static void main(String[] args){\n try{\n \n// Scanner in = new Scanner(new File(\"C:\\\\Users\\\\VisionLab\\\\Downloads\\\\caffe-windows\\\\caffe-windows\\\\data\\\\aesthetics\\\\test.jpgl\"));\n// Scanner ava = new Scanner(new File(\"C:\\\\Users\\\\VisionLab\\\\Downloads\\\\caffe-windows\\\\caffe-windows\\\\data\\\\aesthetics\\\\sorted AVA.txt\"));\n// PrintWriter out = new PrintWriter(new File(\"C:\\\\Users\\\\VisionLab\\\\Downloads\\\\caffe-windows\\\\caffe-windows\\\\data\\\\aesthetics\\\\test.txt\"));\n// \n// int length = 255530;\n// \n// int[][] a = new int[length][3];\n// double[] d = new double[length];\n// int[] s = new int[length];\n// \n// int threshold = 5;\n// double delta = 0;\n// \n// for (int j = 0; j < length; j++) {\n// a[j][0] = ava.nextInt();\n// d[j] = ava.nextDouble();\n// a[j][1] = ava.nextInt();\n// a[j][2] = ava.nextInt();\n// if (d[j] <= threshold - delta) {\n// s[j] = 0;\n// } else if (d[j] > threshold + delta) {\n// s[j] = 1;\n// } else {\n// s[j] = -1;\n// }\n// } \n// \n// for (int i = 0; i < 20000; i++) {\n// int id = in.nextInt();\n// for (int j = 0; j < length; j++) { \n// if (a[j][0] == id) {\n// if (s[j] != -1) {\n// System.out.println(i);\n// out.println(\"/data/aesthetics/images/\" + Integer.toString(a[j][0]) + \".jpg \" + s[j]);\n// }\n// break;\n// }\n// } \n// }\n// \n// in.close();\n// out.close();\n// ava.close();\n\n Scanner in = new Scanner(System.in);\n\n int[] a = new int[5];\n int n = 110;\n int[] b = new int[n];\n \n int s = 0;\n \n for (int i = 0; i < 5; i++) {\n a[i] = in.nextInt();\n b[a[i]]++;\n s += a[i];\n }\n \n Vector<Integer> v = new Vector<Integer>();\n \n for (int i = 0; i < n; i++) {\n if (b[i] >= 2) {\n if (b[i] > 3) {\n b[i] = 3;\n }\n v.add(s - b[i] * i);\n }\n }\n \n if (v.isEmpty()) {\n System.out.println(s);\n } else {\n Collections.sort(v);\n System.out.println(v.elementAt(0));\n }\n \n } catch(Exception ex) {\n System.out.println(ex.toString());\n }\n }\n}", "src_uid": "a9c17ce5fd5f39ffd70917127ce3408a"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.text.ParseException;\nimport java.text.SimpleDateFormat;\nimport java.time.Duration;\nimport java.time.Instant;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.LinkedList;\nimport java.util.*;\nimport java.util.StringJoiner;\nimport java.util.StringTokenizer;\n\npublic class C {\n\n\tpublic static void main(String[] args) throws ParseException {\n\t\tFastScanner sc = new FastScanner();\n\t\tlong n=sc.nextLong(),m=sc.nextLong(),s=sc.nextLong();\n\t\t\n\t\tlong vert= ((n-1)%s +1 )*((n-1)/s+1)*((m-1)%s +1 )*((m-1)/s+1);\n\t\tSystem.out.println(vert);\n\t\t\n\n\t}\n\n\tstatic class FastScanner {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(\"\");\n\n\t\tString next() {\n\t\t\twhile (!st.hasMoreTokens())\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tint[] readArray(int n) {\n\t\t\tint[] a = new int[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\ta[i] = nextInt();\n\t\t\treturn a;\n\t\t}\n\n\t\tlong[] readLongArray(int n) {\n\t\t\tlong[] a = new long[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\ta[i] = nextLong();\n\t\t\treturn a;\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t}\n\n}\n", "src_uid": "e853733fb2ed87c56623ff9a5ac09c36"} {"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;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Stack;\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Erasyl Abenov\n * \n * \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 try (PrintWriter out = new PrintWriter(outputStream)) {\n TaskB solver = new TaskB();\n solver.solve(1, in, out);\n }\n }\n}\nclass TaskB {\n public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException{\n String s = in.next();\n int max = 0;\n for(int i = 0; i < s.length(); ++i){\n for(int j = s.length() - 1; j > i; --j){\n if(max < j - i){\n String find = s.substring(i, j);\n int last = s.lastIndexOf(find);\n int first = s.indexOf(find);\n if((last >= 0 && last != i) || (first >= 0 && first != i))\n max = j - i;\n }\n }\n }\n out.println(max);\n }\n}\nclass InputReader {\n private final BufferedReader reader;\n private StringTokenizer tokenizer;\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n tokenizer = null;\n }\n public String nextLine() {\n try {\n return reader.readLine();\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(nextLine());\n }\n return tokenizer.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(next());\n }\n public BigInteger nextBigInteger(){\n return new BigInteger(next());\n }\n public long nextLong() {\n return Long.parseLong(next());\n }\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n}", "src_uid": "13b5cf94f2fabd053375a5ccf3fd44c7"} {"source_code": "import java.lang.*;\nimport java.util.*;\npublic class easyproblem {\n public static void main(String [] args){\n Scanner sc = new Scanner(System.in);\n int length = sc.nextInt();\n int array[] = new int[length];\n int sum = 0;\n\n for(int i = 0; i < length; i++){\n array[i] = sc.nextInt();\n sum += array[i];\n }\n\n if(sum > 0){\n System.out.println(\"HARD\");\n }\n\n else{\n System.out.println(\"EASY\");\n }\n\n sc.close();\n }\n}", "src_uid": "060406cd57739d929f54b4518a7ba83e"} {"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\tTaskC solver = new TaskC();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskC {\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n String s = in.next();\n int len = s.length();\n boolean[] evalIfAllFalse = new boolean[len];\n boolean[] evalIfAllTrue = new boolean[len];\n boolean[] triggersOnEvery = new boolean[len];\n boolean[] constantOnEvery = new boolean[len];\n boolean[] canBeFalse = new boolean[len];\n boolean[] canBeTrue = new boolean[len];\n int[] numArgs = new int[len];\n int[] openStack = new int[len];\n int[] opStack = new int[len];\n int sp = 0;\n for (int i = 0; i < len; ++i) {\n char ch = s.charAt(i);\n if (ch == '(') {\n openStack[sp++] = i;\n } else if (ch == '|' || ch == '&' || ch == '^') {\n opStack[sp - 1] = i;\n } else if (ch == ')') {\n --sp;\n int a1 = opStack[sp] - 1;\n int a2 = i - 1;\n char op = s.charAt(opStack[sp]);\n numArgs[i] = numArgs[a1] + numArgs[a2];\n if (op == '|') {\n evalIfAllFalse[i] = evalIfAllFalse[a1] || evalIfAllFalse[a2];\n evalIfAllTrue[i] = evalIfAllTrue[a1] || evalIfAllTrue[a2];\n canBeFalse[i] = canBeFalse[a1] && canBeFalse[a2];\n canBeTrue[i] = canBeTrue[a1] || canBeTrue[a2];\n if (!canBeFalse[i]) {\n triggersOnEvery[i] = false;\n constantOnEvery[i] = true;\n } else if (!canBeTrue[a1]) {\n triggersOnEvery[i] = triggersOnEvery[a2];\n constantOnEvery[i] = constantOnEvery[a2];\n } else if (!canBeTrue[a2]) {\n triggersOnEvery[i] = triggersOnEvery[a1];\n constantOnEvery[i] = constantOnEvery[a1];\n } else {\n triggersOnEvery[i] = false;\n constantOnEvery[i] = constantOnEvery[a1] && constantOnEvery[a2];\n }\n } else if (op == '&') {\n evalIfAllFalse[i] = evalIfAllFalse[a1] && evalIfAllFalse[a2];\n evalIfAllTrue[i] = evalIfAllTrue[a1] && evalIfAllTrue[a2];\n canBeFalse[i] = canBeFalse[a1] || canBeFalse[a2];\n canBeTrue[i] = canBeTrue[a1] && canBeTrue[a2];\n if (!canBeTrue[i]) {\n triggersOnEvery[i] = false;\n constantOnEvery[i] = true;\n } else if (!canBeFalse[a1]) {\n triggersOnEvery[i] = triggersOnEvery[a2];\n constantOnEvery[i] = constantOnEvery[a2];\n } else if (!canBeFalse[a2]) {\n triggersOnEvery[i] = triggersOnEvery[a1];\n constantOnEvery[i] = constantOnEvery[a1];\n } else {\n triggersOnEvery[i] = false;\n constantOnEvery[i] = constantOnEvery[a1] && constantOnEvery[a2];\n }\n } else if (op == '^') {\n evalIfAllFalse[i] = evalIfAllFalse[a1] ^ evalIfAllFalse[a2];\n evalIfAllTrue[i] = evalIfAllTrue[a1] ^ evalIfAllTrue[a2];\n canBeTrue[i] = (canBeFalse[a1] && canBeTrue[a2]) || (canBeTrue[a1] && canBeFalse[a2]);\n canBeFalse[i] = (canBeFalse[a1] && canBeFalse[a2]) || (canBeTrue[a1] && canBeTrue[a2]);\n if ((triggersOnEvery[a1] && constantOnEvery[a2]) || (triggersOnEvery[a2] && constantOnEvery[a1])) {\n triggersOnEvery[i] = true;\n constantOnEvery[i] = false;\n } else if ((triggersOnEvery[a1] && triggersOnEvery[a2]) || (constantOnEvery[a1] && constantOnEvery[a2])) {\n triggersOnEvery[i] = false;\n constantOnEvery[i] = true;\n } else {\n triggersOnEvery[i] = false;\n constantOnEvery[i] = false;\n }\n } else throw new RuntimeException();\n } else if (ch == '0') {\n evalIfAllFalse[i] = false;\n evalIfAllTrue[i] = false;\n triggersOnEvery[i] = false;\n constantOnEvery[i] = true;\n canBeFalse[i] = true;\n canBeTrue[i] = false;\n numArgs[i] = 0;\n } else if (ch == '1') {\n evalIfAllFalse[i] = true;\n evalIfAllTrue[i] = true;\n triggersOnEvery[i] = false;\n constantOnEvery[i] = true;\n canBeFalse[i] = false;\n canBeTrue[i] = true;\n numArgs[i] = 0;\n } else if (ch == '?') {\n evalIfAllFalse[i] = false;\n evalIfAllTrue[i] = true;\n triggersOnEvery[i] = true;\n constantOnEvery[i] = false;\n canBeFalse[i] = true;\n canBeTrue[i] = true;\n numArgs[i] = 1;\n } else throw new RuntimeException();\n }\n if (sp != 0) throw new RuntimeException();\n if (!canBeFalse[len - 1] || !canBeTrue[len - 1]) {\n out.println(\"NO\");\n } else if (evalIfAllFalse[len - 1] != evalIfAllTrue[len - 1]) {\n out.println(\"YES\");\n } else if (constantOnEvery[len - 1]) {\n out.println(\"NO\");\n } else {\n out.println(\"YES\");\n }\n\t}\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", "src_uid": "e060d26dc3b9ffb628f2380781d1cbe9"} {"source_code": "//package round424;\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 D2 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni();\n\t\tlong[] enigma = {0, \n\t\t\t\t1, 9, 245, 126565, 54326037, 321837880, 323252721, 754868154, 328083248, 838314395, 220816781, 893672292, 166441208, 251255697, 114256285, 118775501, 482714697, 11784725, 460862131, 550384565, 106742050, 425241115, 626692854, 674266678, 320014275, 345949512, 527320049, 897822749, 137190263, 491039182, 810384961, 482023334, 658099864, 886790989, 845381174, 371433224, 278969124, 420088324, 696766322, 388302635, 141033366, 46387851, 932125021, 278342766, 371131134, 922501918, 110778457, 506223573, 806353719, 391845991, 923507761, 780307355, 109951115, 830090230, 605558495, 344686604, 988110893, 944684429, 715019947, 799898820, 384672708, 907325090, 758952329, 550672104, 368337206, 394915145, 401744167, 923781939, 831857516, 407845661, 329267374, 927004007, 891609656, 897919613, 481297880, 737337940, 651873737, 287246681, 973133651, 679864988, 784719328, 820504764, 875613823, 806512665, 164851642, 500228957, 951814419, 447763649, 273141670, 979349615, 964027956, 809510400, 276634497, 116631976, 426739449, 175282420, 885948162, 62270880, 974395255, 675165056, 759589968, 837957573, 931897605, 152352780, 585420109, 1772087, 333401718, 898833639, 745874265, 786209423, 691982338, 498790927, 473374639, 274302623, 971280670, 241671319, 13070005, 302088807, 550276351, 436592588, 631667314, 548656698, 730626984, 146295220, 674398632, 400383348, 454138904, 786220712, 118620797, 233440672, 217349271, 274853536, 310607544, 105221205, 769566615, 853585061, 800665807, 695377419, 924327065, 388199705, 551624811, 721435546, 501720515, 308465454, 825369234, 396065729, 451899519, 295058424, 142088952, 473485086, 378771634, 734511215, 462404399, 959198328, 337668263, 794122911, 38911400, 951992982, 472696081, 373904752, 105884826, 630251717, 28980684, 845136347, 353665773, 691661192, 19922354, 231463797, 757917231, 242739918, 979036950, 713722080, 234689388, 2243164, 209872853, 240808787, 539523346, 425797848, 913772061, 224613100, 421742777, 222232478, 92712941, 215137570, 949901408, 274827432, 15162482, 593145989, 274574232, 239282092, 762720192, 804146934, 500629424, 565985054, 81127381, 671811155, 655565571, 890331075, 237994348, 743647404, 667160634, 713914299, 668506729, 741341289, 277636808, 762781382, 14272789, 902864131, 567443405, 149113383, 648844381, 825489976, 933016723, 192288078, 734493315, 240985733, 861817693, 762711459, 525904609, 532463481, 377133989, 620711079, 772561562, 980733194, 227599811, 162774370, 209512798, 787116594, 3509258, 748795368, 378035466, 612938915, 802091952, 857679599, 481748937, 493370392, 358420805, 48301629, 412001241, 463126722, 509578422, 967799131, 994766554, 687287243, 863623583, 771554899, 690911527, 855314994, 923686429, 246862514, 192479791, 133487041, 703444043, 295281758, 801816257, 920762934, 749306433, 973004841, 848644684, 560026478, 952127278, 616654635, 839390326, 975154012, 409583672, 635350249, 343228425, 335331602, 223826406, 952341037, 589677800, 249747234, 555694261, 137143500, 628190328, 461598392, 431912756, 29349807, 759199489, 783281228, 781971312, 915823407, 388508707, 718062705, 27424111, 309999451, 963383322, 831185229, 132910888, 347028136, 850484840, 223055285, 142335980, 144754000, 772005560, 81796039, 167696020, 79454283, 172772542, 201056991, 484957644, 716630285, 763194701, 211505841, 903448791, 926964672, 257752668, 482951716, 411539070, 620249847, 592476107, 170473128, 814662613, 898000271, 57354872, 361106091, 488697643, 889007954, 138725767, 684860983, 36248116, 304610143, 137633385, 413715776, 99010024, 779653665, 100387568, 286328069, 564731826, 621740468, 943513219, 506666491, 249987886, 553719884, 769853086, 337485319, 702455584, 809637762, 755400257, 892290368, 502180086, 364275817, 118162370, 873374339, 261271695, 970132574, 744105500, 434447173, 117975095, 383088393, 625447969, 180281249, 545367713, 133236931, 360175662, 148087453, 806871297, 498529036, 886076476, 65645000, 465138299, 967109895, 331362616, 472283705, 796894900, 199697765, 503759892, 472807906, 187586706, 941198065, 782234442, 57693411, 18678611, 82626204, 395317191, 570588915, 152519440, 449852456, 63696518, 763741345, 878748386, 494317541, 444782633, 93316211, 929164666, 529288371, 165769871, 730546850, 955877127, 994202767, 492009567, 275683011, 415902127, 95725776, 718047399, 786963365, 73091278, 986172399, 174591541, 913259286, 713390153, 831617964}\n;\n\t\tout.println(enigma[n]);\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 D2().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", "src_uid": "fda761834f7b5800f540178ac1c79fca"} {"source_code": "import java.util.*;\npublic class MyClass {\n public static void main(String args[]) {\n \n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n int arr[]=new int[1000];\n int i;\n for(i=0;i<n;i++)\n arr[i]=sc.nextInt();\n \n int c=0;\n int max=0;\n int flag=0;\n int t=0;\n int r=0;\n if(arr[0]==1 && arr[1]==2)\n r=1;\n for(i=0;i<n-1;i++)\n {\n if(arr[i+1]==arr[i]+1)\n {\n c++;\n if(i==n-2)\n {\n t=1;\n }\n }\n else\n {\n if(c!=0 && flag==0)\n {\n if(r==1)\n max=c+1;\n else \n max=c;\n flag=1;\n }\n else\n {\n if(c>max)\n max=c;\n }\n c=0;\n \n }\n }\n if(t==1 && flag==0)\n {\n if(arr[0]==1 || arr[n-1]==1000)\n {\n \n System.out.println(c);\n System.exit(0);\n }\n }\n if(t==1)\n {\n \n if(c>=max && arr[n-1]==1000)\n {\n max=c+1;\n }\n if(c>=max && arr[n-1]!=1000)\n {\n \n max=c;\n }\n }\n if(max==0)\n System.out.println(0);\n else\n System.out.println(max-1);\n \n \n sc.close();\n \n }\n}", "src_uid": "858b5e75e21c4cba6d08f3f66be0c198"} {"source_code": "import java.util.Scanner;\n\npublic class KingShortestPath {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n String in1 = scanner.nextLine();\n int x1 = in1.charAt(0) - 'a';\n int y1 = in1.charAt(1) - '1';\n String in2 = scanner.nextLine();\n int x2 = in2.charAt(0) - 'a';\n int y2 = in2.charAt(1) - '1';\n StringBuilder sb = new StringBuilder();\n int count = 0;\n\n while (true) {\n if(x1 == x2 && y1 == y2) {\n break;\n }\n\n if(x1 < x2) {\n x1++;\n sb.append(\"R\");\n } else if(x1 > x2) {\n x1--;\n sb.append(\"L\");\n }\n\n if(y1 < y2) {\n y1++;\n sb.append(\"U\");\n } else if(y1 > y2) {\n y1--;\n sb.append(\"D\");\n }\n count++;\n\n sb.append(\"\\n\");\n }\n System.out.println(count);\n System.out.println(sb.toString());\n }\n}\n", "src_uid": "d25d454702b7755297a7a8e1f6f36ab9"} {"source_code": "import java.util.Arrays;\nimport java.util.PriorityQueue;\nimport java.util.Scanner;\n\npublic class Main {\n\t\n\tpublic static void main(String[] args) {\n\t\tnew Main().solve();\n\t}\n\t\n\tvoid solve(){\n\t\tScanner sc=new Scanner(System.in);\n\t\tint a=sc.nextInt();\n\t\tint b=sc.nextInt();\n\t\tint f=sc.nextInt();\n\t\tint k=sc.nextInt();\n\t\tint ans=0;\n\t\tint count=0;\n\t\tint dir=1;\n\t\tint tank=b;\n\t\t\n\t\twhile(count<k) {\n\t\t\tif(dir==1) {\n\t\t\t\tif(tank-f<0 || b-(a-f)<0) {\n\t\t\t\t\tans=-1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif(k-count==1) {\n\t\t\t\t\tif(tank-a<0) {\n\t\t\t\t\t\tans++;\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t}else {\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t}\n\t\t\t\t}else {\n\t\t\t\t\tif(tank-(2*a-f)<0) {\n\t\t\t\t\t\tans++;\n\t\t\t\t\t\ttank=b-(a-f);\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t}else {\n\t\t\t\t\t\ttank-=a;\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(dir==-1) {\n\t\t\t\tif(tank-(a-f)<0 || b-f<0) {\n\t\t\t\t\tans=-1;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif(k-count==1) {\n\t\t\t\t\tif(tank-a<0) {\n\t\t\t\t\t\tans++;\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t}else {\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t}\n\t\t\t\t}else {\n\t\t\t\t\tif(tank-(a+f)<0) {\n\t\t\t\t\t\tans++;\n\t\t\t\t\t\ttank=b-f;\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t}else {\n\t\t\t\t\t\ttank-=a;\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tdir*=-1;\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}\n", "src_uid": "283aff24320c6518e8518d4b045e1eca"} {"source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n \npublic class _400div2Q3\n{\n public static void main(String[] args) throws IOException\n {\n FastScanner obj = new FastScanner();\n out = new PrintWriter(new BufferedOutputStream(System.out));\n\t\tint n = obj.nextInt();\n\t\t\n\t\tint index = obj.nextInt();\n\t\t\n\t\tint moves = n%6;\n\t\tif(moves==0)\n\t\t\tmoves+=6;\n\t\tif(moves==1)\n\t\t{\n\t\t\tif(index==0)\n\t\t\t\tout.print(1);\n\t\t\telse if(index==1)\n\t\t\t\tout.print(0);\n\t\t\telse \n\t\t\t\tout.print(2);\n\t\t}\n\t\telse if(moves==2)\n\t\t{\n\t\t\tif(index==0)\n\t\t\t\tout.print(1);\n\t\t\telse if(index==1)\n\t\t\t\tout.print(2);\n\t\t\telse \n\t\t\t\tout.print(0);\n\t\t}\n\t\telse if(moves==3)\n\t\t{\n\t\t\tif(index==0)\n\t\t\t\tout.print(2);\n\t\t\telse if(index==1)\n\t\t\t\tout.print(1);\n\t\t\telse \n\t\t\t\tout.print(0);\n\t\t}\n\t\telse if(moves==4)\n\t\t{\n\t\t\tif(index==0)\n\t\t\t\tout.print(2);\n\t\t\telse if(index==1)\n\t\t\t\tout.print(0);\n\t\t\telse \n\t\t\t\tout.print(1);\n\t\t}\n\t\telse if(moves==5)\n\t\t{\n\t\t\tif(index==0)\n\t\t\t\tout.print(0);\n\t\t\telse if(index==1)\n\t\t\t\tout.print(2);\n\t\t\telse \n\t\t\t\tout.print(1);\n\t\t}\n\t\telse if(moves==6)\n\t\t{\n\t\t\tif(index==0)\n\t\t\t\tout.print(0);\n\t\t\telse if(index==1)\n\t\t\t\tout.print(1);\n\t\t\telse \n\t\t\t\tout.print(2);\n\t\t}\n\t\t\n out.close();\n }\n \n\n //-----------PrintWriter for faster output---------------------------------\n public static PrintWriter out;\n \n //-----------FastScanner class for faster input----------\n public static class FastScanner {\n BufferedReader br;\n StringTokenizer tokenizer;\n \n public FastScanner() throws IOException {\n br = new BufferedReader(new InputStreamReader(System.in));\n tokenizer = new StringTokenizer(br.readLine().trim());\n }\n \n String next() {\n while (tokenizer == null || !tokenizer.hasMoreElements()) {\n try {\n tokenizer = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return tokenizer.nextToken();\n }\n \n int nextInt() {\n return Integer.parseInt(next());\n }\n \n long nextLong() {\n return Long.parseLong(next());\n }\n \n double nextDouble() {\n return Double.parseDouble(next());\n }\n \n int[] nextIntArray() throws IOException {\n String[] line = br.readLine().trim().split(\" \");\n int[] out = new int[line.length];\n \n for (int i = 0; i < line.length; i++) {\n out[i] = Integer.valueOf(line[i]);\n }\n return out;\n }\n \n BigInteger nextBigInteger() throws IOException {\n return new BigInteger(next());\n }\n \n String nextLine(){\n String str = \"\";\n\t try {\n\t str = br.readLine();\n\t } catch (IOException e) {\n\t e.printStackTrace();\n\t }\n\t return str;\n }\n\n }\n //--------------------------------------------------------\n}", "src_uid": "7853e03d520cd71571a6079cdfc4c4b0"} {"source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.OutputStream;\nimport java.util.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 Pradyumn\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastReader in = new FastReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskE solver = new TaskE();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskE {\n Debug debug;\n\n public void solve(int testNumber, FastReader in, PrintWriter out) {\n debug = new Debug(out);\n long n = in.nextLong();\n out.println(rec(n - 1) / 2);\n }\n\n public static long rec(long n) {\n if (n == 0) return 0;\n if (n % 2 == 0)\n return 2 * rec(n >> 1) + n;\n return 2 * rec(n >> 1) + n + 1;\n }\n\n }\n\n static class Debug {\n PrintWriter out;\n boolean oj;\n boolean system;\n long timeBegin;\n Runtime runtime;\n\n public Debug(PrintWriter out) {\n oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n this.out = out;\n this.timeBegin = System.currentTimeMillis();\n this.runtime = Runtime.getRuntime();\n }\n\n public Debug() {\n system = true;\n oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n OutputStream outputStream = System.out;\n this.out = new PrintWriter(outputStream);\n this.timeBegin = System.currentTimeMillis();\n this.runtime = Runtime.getRuntime();\n }\n\n }\n\n static class FastReader {\n private InputStream stream;\n private byte[] buf = new byte[8192];\n private int curChar;\n private int pnumChars;\n\n public FastReader(InputStream stream) {\n this.stream = stream;\n }\n\n private int pread() {\n if (pnumChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= pnumChars) {\n curChar = 0;\n try {\n pnumChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (pnumChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public long nextLong() {\n int c = pread();\n while (isSpaceChar(c))\n c = pread();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = pread();\n }\n 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 = pread();\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\n", "src_uid": "a98f0d924ea52cafe0048f213f075891"} {"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.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 private int getIndex(int[][] data, int[] values) {\n for (int i = 0; i < data.length; ++i) {\n if (Arrays.equals(data[i], values)) {\n return i;\n }\n }\n throw new IllegalArgumentException();\n }\n\n private void generate(int index) {\n if (index == helper.length) {\n states[SIZE++] = helper.clone();\n } else {\n for (int value = 0; value < v[index]; ++value) {\n helper[index] = value;\n generate(index + 1);\n }\n }\n }\n\n private int[][] pow(int[][] src, long power) {\n int[][] result = new int[src.length][src.length];\n for (int i = 0; i < result.length; ++i) {\n result[i][i] = 1;\n }\n for (; power != 0; power >>= 1) {\n if ((power & 1) == 1) {\n result = multiply(result, src);\n }\n src = multiply(src, src);\n }\n return result;\n }\n\n private int[][] multiply(int[][] left, int[][] right) {\n int[][] result = new int[left.length][left.length];\n for (int i = 0; i < left.length; ++i) {\n for (int j = 0; j < left.length; ++j) {\n for (int k = 0; k < left.length; ++k) {\n result[i][j] += (left[i][k] * right[k][j]) % MODULO;\n }\n result[i][j] %= MODULO;\n }\n }\n return result;\n }\n\n private void solve() throws Throwable {\n long n = nextLong();\n int c = nextInt();\n l = new int[c];\n v = new int[c];\n boolean[] used = new boolean[AlPHABET_SIZE], good = new boolean[AlPHABET_SIZE];\n\n int total = 1;\n for (int i = 0; i < c; ++i) {\n l[i] = nextToken().charAt(0) - 'A';\n used[l[i]] = true;\n total *= (v[i] = nextInt());\n }\n states = new int[total][];\n helper = new int[c];\n generate(0);\n int[][] grid = new int[total][total];\n for (int current = 0; current < total; ++current) {\n for (int i = 0; i < AlPHABET_SIZE; ++i) {\n helper = states[current].clone();\n if (used[i]) {\n for (int ind = 0; ind < c; ++ind) {\n if (l[ind] == i) {\n helper[ind] = (helper[ind] + 1) % v[ind];\n }\n }\n grid[current][getIndex(states, helper)]++;\n }\n }\n }\n int[][] result = pow(grid, n);\n int answer = 0;\n for (int currentState = 0; currentState < total; ++currentState) {\n Arrays.fill(good, false);\n for (int i = 0; i < c; ++i) {\n good[l[i]] |= states[currentState][i] == 0;\n }\n boolean can = true;\n for (int i = 0; i < AlPHABET_SIZE; ++i) {\n if (used[i] && !good[i]) {\n can = false;\n break;\n }\n }\n if (can) {\n answer = (answer + result[0][currentState]) % MODULO;\n }\n }\n output.println(answer);\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 int[][] states;\n private int[] helper, l, v;\n private static int SIZE = 0;\n private static final int MODULO = 12345, AlPHABET_SIZE = 26;\n private BufferedReader input;\n private PrintWriter output;\n private StringTokenizer tokens = null;\n}\n", "src_uid": "76d4684d26dac380713a566a1e277c91"} {"source_code": "import java.util.*;\n\nimport java.io.*;\nimport java.lang.reflect.Array;\nimport java.math.BigInteger;\n\npublic class B {\n\tFastScanner in;\n\tPrintWriter out;\n\tboolean systemIO = true;\n\n\tpublic static void quickSort(int[] a, int from, int to) {\n\t\tif (to - from <= 1) {\n\t\t\treturn;\n\t\t}\n\t\tint i = from;\n\t\tint j = to - 1;\n\t\tint x = a[from + (new Random()).nextInt(to - from)];\n\t\twhile (i <= j) {\n\t\t\twhile (a[i] < x) {\n\t\t\t\ti++;\n\t\t\t}\n\t\t\twhile (a[j] > x) {\n\t\t\t\tj--;\n\t\t\t}\n\t\t\tif (i <= j) {\n\t\t\t\tint t = a[i];\n\t\t\t\ta[i] = a[j];\n\t\t\t\ta[j] = t;\n\t\t\t\ti++;\n\t\t\t\tj--;\n\t\t\t}\n\t\t}\n\t\tquickSort(a, from, j + 1);\n\t\tquickSort(a, j + 1, to);\n\t}\n\t\n\tpublic long gcd(long x, long y) {\n\t\tif (y == 0) {\n\t\t\treturn x;\n\t\t}\n\t\tif (x == 0) {\n\t\t\treturn y;\n\t\t}\n\t\treturn gcd(y, x % y);\n\t}\n\t\n\tpublic boolean prime(long x) {\n\t\tfor (int i = 2; i * i <= x; i++) {\n\t\t\tif (x % i == 0) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\t\n\t\n\tpublic void solve() {\n\t\tRandom random = new Random();\n\t\tlong mod = 1000000000 + random.nextInt(1000000);\n\t\twhile (!prime(mod)) {\n\t\t\tmod = 1000000000 + random.nextInt(1000000);\n\t\t}\n\t\tBigInteger bigMod = new BigInteger(mod + \"\");\n\t\tlong l = System.currentTimeMillis();\n\t\tint n = in.nextInt();\n\t\tint[] a = new int[101];\n\t\tint sum = 0;\n\t\tint number = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint x = in.nextInt();\n\t\t\ta[x]++;\n\t\t\tsum += x;\n\t\t\tif (a[x] == 1) {\n\t\t\t\tnumber++;\n\t\t\t}\n\t\t}\n\t\tif (number == 1) {\n\t\t\tout.println(n);\n\t\t\treturn;\n\t\t}\n\t\tboolean flag = number == 2;\n\t\tint s = 0;\n\t\tnumber = 0;\n\t\tlong[][] dp = new long[n + 1][sum + 1];\n\t\tdp[0][0] = 1;\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tfor (int j = 0; j < a[i]; j++) {\n\t\t\t\tfor (int x = number; x >= 0; x--) {\n\t\t\t\t\tfor (int y = s; y >= 0; y--) {\n\t\t\t\t\t\tdp[x + 1][y + i] += dp[x][y];\n\t\t\t\t\t\tdp[x + 1][y + i] %= mod;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ts += i;\n\t\t\t\tnumber++;\n\t\t\t}\n\t\t}\n\t\tlong[] fact = new long[101];\n\t\tlong[] defact = new long[101];\n\t\tfact[0] = 1;\n\t\tdefact[0] = 1;\n\t\tfor (int i = 1; i < fact.length; i++) {\n\t\t\tfact[i] = fact[i - 1] * i;\n\t\t\tfact[i] %= mod;\n\t\t\tBigInteger bigInt = new BigInteger(fact[i] + \"\");\n\t\t\tbigInt = bigInt.modInverse(bigMod);\n\t\t\tdefact[i] = bigInt.longValueExact();\n\t\t}\n\t\tint ans = 0;\n\t\tfor (int i = 0; i < a.length; i++) {\n\t\t\tfor (int j = 1; j <= a[i]; j++) {\n\t\t\t\tlong x = fact[a[i]] * defact[j];\n\t\t\t\tx %= mod;\n\t\t\t\tx *= defact[a[i] - j];\n\t\t\t\tx %= mod;\n\t\t\t\tif (x == dp[j][j * i]) {\n\t\t\t\t\tans = Math.max(ans, j);\n\t\t\t\t\tif (flag && j == a[i]) {\n\t\t\t\t\t\tans = n;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(ans);\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tif (systemIO) {\n\t\t\t\tin = new FastScanner(System.in);\n\t\t\t\tout = new PrintWriter(System.out);\n\t\t\t} else {\n\t\t\t\tin = new FastScanner(new File(\"input.txt\"));\n\t\t\t\tout = new PrintWriter(new File(\"output.txt\"));\n\t\t\t}\n\t\t\tsolve();\n\n\t\t\tout.close();\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\n\tclass FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tFastScanner(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\tFastScanner(InputStream f) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(f));\n\t\t}\n\n\t\tString nextLine() {\n\t\t\ttry {\n\t\t\t\treturn br.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\treturn null;\n\t\t\t}\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(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}\n\n\t// AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n\tpublic static void main(String[] arg) {\n\t\tnew B().run();\n\t}\n}", "src_uid": "ccc4b27889598266e8efe73b8aa3666c"} {"source_code": "import java.util.*;\nimport java.io.*;\n\npublic class L {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tint n = Integer.parseInt(st.nextToken());\n\t\tchar[] a = br.readLine().toCharArray();\n\t\tint[] b = new int[n];\n\t\tint max = -1;\n\t\tboolean f = true;\n\t\tfor (int i = 0; i < b.length; i++) {\n\t\t\tif ((a[i] - 'a') >= max) {\n\t\t\t\tmax = a[i] - 'a';\n\t\t\t} else {\n\t\t\t\tfor (int j = i - 1; j >= 0; j--) {\n\t\t\t\t\tif (a[j] > a[i] && b[j] == 1)\n\t\t\t\t\t\tf = false;\n\t\t\t\t}\n\t\t\t\tif (f)\n\t\t\t\t\tb[i] = 1;\n\t\t\t\telse\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif(f) {\n\t\t\tpw.println(\"YES\");\n\t\t\tfor (int i = 0; i < b.length; i++) {\n\t\t\t\tpw.print(b[i]);\n\t\t\t}\n\t\t}\n\t\telse\n\t\t\tpw.println(\"NO\");\n\n\t\tpw.flush();\n\t}\n\n}\n", "src_uid": "9bd31827cda83eacfcf5e46cdeaabe2b"} {"source_code": "import java.io.BufferedInputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.InputMismatchException;\nimport java.util.LinkedList;\nimport java.util.Map.Entry;\nimport java.util.Queue;\nimport java.util.Random;\nimport java.util.Set;\nimport java.util.SortedSet;\nimport java.util.Stack;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\npublic class Main\n{\t\n\tprivate final int SIZEN = 40;\n\t\n\tpublic void foo()\n\t{\n\t\tMyScanner scan = new MyScanner();\n\t\tint w = scan.nextInt();\n\t\tint m = scan.nextInt();\n\t\tint[] digit = new int[SIZEN];\n\t\tint cnt = 0;\n\t\twhile(m > 0)\n\t\t{\n\t\t\tdigit[cnt++] = m % w;\n\t\t\tm /= w;\n\t\t}\t\t\n\t\tfor(int i = 0;i < cnt;++i)\n\t\t{\n\t\t\tif(digit[i] >= w)\n\t\t\t{\n\t\t\t\tdigit[i] = 0;\n\t\t\t\t++digit[i + 1];\n\t\t\t}\n\t\t\tif(digit[i] <= 1)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\telse if(digit[i] == w - 1)\n\t\t\t{\n\t\t\t\t++digit[i + 1];\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(\"YES\");\n \t}\n\n\tpublic static void main(String[] args)\n\t{\n\t\tnew Main().foo();\n\t}\n\n\tclass MyScanner\n\t{\n\t private byte[] buf = new byte[1024];\n\t private int curChar;\n\t private int numChars;\n\t BufferedInputStream bis = new BufferedInputStream(System.in);\n\n\t public int read() \n\t {\n\t if (-1 == numChars)\n\t {\n\t \tthrow new InputMismatchException();\n\t }\n\t if (curChar >= numChars)\n\t {\n\t curChar = 0;\n\t try \n\t {\n\t numChars = bis.read(buf);\n\t }\n\t catch (IOException e)\n\t {\n\t throw new InputMismatchException();\n\t }\n\t if (numChars <= 0)\n\t {\n\t \treturn -1;\n\t }\n\t }\n\t return buf[curChar++];\n\t }\n\n\t public int nextInt() \n\t {\n\t int c = read();\n\t while (isSpaceChar(c))\n\t {\n\t \tc = read();\n\t }\n\t int sgn = 1;\n\t if (c == '-') \n\t {\n\t sgn = -1;\n\t c = read();\n\t }\n\t int res = 0;\n\t do \n\t {\n\t if (c < '0' || c > '9')\n\t {\n\t \tthrow new InputMismatchException();\n\t }\n\t res *= 10;\n\t res += c - '0';\n\t c = read();\n\t } while (!isSpaceChar(c));\n\t return res * sgn;\n\t }\n\t \n\t public long nextLong() \n\t {\n\t \tint c = read();\n\t \twhile (isSpaceChar(c))\n\t \t{\n\t \t\tc = read();\n\t \t}\n\t \tint sgn = 1;\n\t \tif (c == '-') \n\t \t{\n\t \t\tsgn = -1;\n\t \t\tc = read();\n\t \t}\n\t \tlong res = 0;\n\t \tdo \n\t \t{\n\t \t\tif (c < '0' || c > '9')\n\t \t\t{\n\t \t\t\tthrow new InputMismatchException();\n\t \t\t}\n\t \t\tres *= 10;\n\t \t\tres += c - '0';\n\t \t\tc = read();\n\t \t} while (!isSpaceChar(c));\n\t \treturn res * sgn;\n\t }\n\t \n\t public double nextDouble() \n\t {\n\t int c = read();\n\t while (isSpaceChar(c))\n\t {\n\t \tc = read();\n\t }\n\t int sgn = 1;\n\t if (c == '-')\n\t {\n\t sgn = -1;\n\t c = read();\n\t }\n\t double res = 0;\n\t while (!isSpaceChar(c) && c != '.') \n\t {\n\t if (c == 'e' || c == 'E')\n\t {\n\t \treturn res * Math.pow(10, nextInt());\n\t }\n\t if (c < '0' || c > '9')\n\t {\n\t \tthrow new InputMismatchException();\n\t }\n\t res *= 10;\n\t res += c & 15;\n\t c = read();\n\t }\n\t if (c == '.') \n\t {\n\t c = read();\n\t double m = 1;\n\t while (!isSpaceChar(c)) \n\t {\n\t if (c == 'e' || c == 'E')\n\t {\n\t \treturn res * Math.pow(10, nextInt());\n\t }\n\t if (c < '0' || c > '9')\n\t {\n\t \tthrow new InputMismatchException();\n\t }\n\t m /= 10;\n\t res += (c & 15) * m;\n\t c = read();\n\t }\n\t }\n\t return res * sgn;\n\t }\n\t \n\t public String next()\n\t {\n\t int c = read();\n\t while (isSpaceChar(c))\n\t {\n\t \tc = read();\n\t }\n\t StringBuilder res = new StringBuilder();\n\t do \n\t {\n\t res.appendCodePoint(c);\n\t c = read();\n\t } while (!isSpaceChar(c));\n\t return res.toString();\n\t }\n\n\t private boolean isSpaceChar(int c) \n\t {\n\t return ' ' == c || '\\n' == c || '\\r' == c || '\\t' == c || -1 == c;\n\t }\n\t}\n}", "src_uid": "a74adcf0314692f8ac95f54d165d9582"} {"source_code": "\nimport java.util.Scanner;\n\npublic class test011 {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint x = sc.nextInt();\n\t\tint y = sc.nextInt();\n\t\tif (y == 1 && x != 0 || y == 0) {\n\t\t\tSystem.out.println(\"NO\");\n\t\t\treturn;\n\t\t}\n\t\tint tmp = x - y + 1;\n\t\tif (tmp >= 0 && tmp % 2 == 0) {\n\t\t\tSystem.out.println(\"YES\");\n\t\t} else {\n\t\t\tSystem.out.println(\"NO\");\n\t\t}\n\n\t}\n}\n", "src_uid": "1527171297a0b9c5adf356a549f313b9"} {"source_code": "import java.util.Scanner;\n\npublic class _112B_PetyaAndSquare {\n \n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int a = sc.nextInt();\n int b = sc.nextInt();\n n /= 2;\n if ((a == n || a == n + 1) && (b == n || b == n + 1))\n System.out.println(\"NO\");\n else\n System.out.println(\"YES\");\n }\n}", "src_uid": "dc891d57bcdad3108dcb4ccf9c798789"} {"source_code": "import java.util.*;\nimport java.io.*;\npublic class Main {\n static class Scan {\n private byte[] buf=new byte[1024];\n private int index;\n private InputStream in;\n private int total;\n public Scan()\n {\n in=System.in;\n }\n public int scan()throws IOException\n {\n if(total<0)\n throw new InputMismatchException();\n if(index>=total)\n {\n index=0;\n total=in.read(buf);\n if(total<=0)\n return -1;\n }\n return buf[index++];\n }\n public int scanInt()throws IOException\n {\n int integer=0;\n int n=scan();\n while(isWhiteSpace(n))\n n=scan();\n int neg=1;\n if(n=='-')\n {\n neg=-1;\n n=scan();\n }\n while(!isWhiteSpace(n))\n {\n if(n>='0'&&n<='9')\n {\n integer*=10;\n integer+=n-'0';\n n=scan();\n }\n else throw new InputMismatchException();\n }\n return neg*integer;\n }\n public double scanDouble()throws IOException\n {\n double doub=0;\n int n=scan();\n while(isWhiteSpace(n))\n n=scan();\n int neg=1;\n if(n=='-')\n {\n neg=-1;\n n=scan();\n }\n while(!isWhiteSpace(n)&&n!='.')\n {\n if(n>='0'&&n<='9')\n {\n doub*=10;\n doub+=n-'0';\n n=scan();\n }\n else throw new InputMismatchException();\n }\n if(n=='.')\n {\n n=scan();\n double temp=1;\n while(!isWhiteSpace(n))\n {\n if(n>='0'&&n<='9')\n {\n temp/=10;\n doub+=(n-'0')*temp;\n n=scan();\n }\n else throw new InputMismatchException();\n }\n }\n return doub*neg;\n }\n public String scanString()throws IOException\n {\n StringBuilder sb=new StringBuilder();\n int n=scan();\n while(isWhiteSpace(n))\n n=scan();\n while(!isWhiteSpace(n))\n {\n sb.append((char)n);\n n=scan();\n }\n return sb.toString();\n }\n private boolean isWhiteSpace(int n)\n {\n if(n==' '||n=='\\n'||n=='\\r'||n=='\\t'||n==-1)\n return true;\n return false;\n }\n }\n \n public static void sort(int arr[],int l,int r) { //sort(arr,0,n-1);\n if(l==r) {\n return;\n }\n int mid=(l+r)/2;\n sort(arr,l,mid);\n sort(arr,mid+1,r);\n merge(arr,l,mid,mid+1,r);\n }\n public static void merge(int arr[],int l1,int r1,int l2,int r2) {\n int tmp[]=new int[r2-l1+1];\n int indx1=l1,indx2=l2;\n //sorting the two halves using a tmp array\n for(int i=0;i<tmp.length;i++) {\n if(indx1>r1) {\n tmp[i]=arr[indx2];\n indx2++;\n continue;\n }\n if(indx2>r2) {\n tmp[i]=arr[indx1];\n indx1++;\n continue;\n }\n if(arr[indx1]<arr[indx2]) {\n tmp[i]=arr[indx1];\n indx1++;\n continue;\n }\n tmp[i]=arr[indx2];\n indx2++;\n }\n //Copying the elements of tmp into the main array\n for(int i=0,j=l1;i<tmp.length;i++,j++) {\n arr[j]=tmp[i];\n }\n }\n \n public static void sort(long arr[],int l,int r) { //sort(arr,0,n-1);\n if(l==r) {\n return;\n }\n int mid=(l+r)/2;\n sort(arr,l,mid);\n sort(arr,mid+1,r);\n merge(arr,l,mid,mid+1,r);\n }\n public static void merge(long arr[],int l1,int r1,int l2,int r2) {\n long tmp[]=new long[r2-l1+1];\n int indx1=l1,indx2=l2;\n //sorting the two halves using a tmp array\n for(int i=0;i<tmp.length;i++) {\n if(indx1>r1) {\n tmp[i]=arr[indx2];\n indx2++;\n continue;\n }\n if(indx2>r2) {\n tmp[i]=arr[indx1];\n indx1++;\n continue;\n }\n if(arr[indx1]<arr[indx2]) {\n tmp[i]=arr[indx1];\n indx1++;\n continue;\n }\n tmp[i]=arr[indx2];\n indx2++;\n }\n //Copying the elements of tmp into the main array\n for(int i=0,j=l1;i<tmp.length;i++,j++) {\n arr[j]=tmp[i];\n }\n }\n \n public static void main(String args[]) throws IOException {\n Scan input=new Scan();\n StringBuilder ans=new StringBuilder(\"\");\n int test=1;\n for(int tt=1;tt<=test;tt++) {\n String str=input.scanString();\n int cnt=0,first=-1;\n for(int i=0;i<str.length();i++) {\n if(first==-1 && str.charAt(i)=='1') {\n first=i;\n }\n if(str.charAt(i)=='1') {\n cnt++;\n }\n }\n int fin=0;\n for(int i=0;i<str.length();i++) {\n if(first==-1) {\n break;\n }\n int indx=str.length()-i-1;\n if(indx%2==0 && i>first) {\n fin++;\n }\n if(indx%2==0 && i==first && cnt>1) {\n fin++;\n }\n }\n ans.append(fin+\"\\n\");\n }\n System.out.println(ans);\n }\n}\n", "src_uid": "d8ca1c83b431466eff6054d3b422ab47"} {"source_code": "import java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.OutputStreamWriter;\nimport java.io.IOException;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.util.stream.Stream;\n\n\n/**\n *\n * @author Pradyumn Agrawal coderbond007\n */\npublic class Codeforces{\n public static InputStream inputStream = System.in;\n public static FastReader in = new FastReader(inputStream);\n public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\n public static void main(String[] args)throws java.lang.Exception\n {\n new Codeforces().run();\n out.close();\n }\n void run() throws java.lang.Exception\n {\n int n = ni();\n int[] a = na(n);\n if(Arrays.stream(a).sum() != 0){\n out.println(\"YES\");\n out.println(1);\n out.println(1 + \" \" + n);\n }else if(Arrays.stream(a).allMatch(x -> x == 0)){\n out.println(\"NO\");\n }else{\n out.println(\"YES\");\n for(int i = 0;i < n;i++){\n if(a[i] != 0){\n out.println(2);\n out.println(1 + \" \" + (i+1));\n out.println((i+2) + \" \" + n);\n return;\n }\n }\n }\n }\n private static int ni(){ \n return in.nextInt();\n }\n private static long nl(){\n return in.nextLong();\n }\n private static String ns(){\n return in.nextString();\n }\n private static char nc(){\n return in.nextCharacter();\n }\n private static double nd(){\n return in.nextDouble();\n }\n\n private static char[] ns(int n)\n {\n char[] a = new char[n];\n for(int i=0;i<n;i++) a[i] = nc();\n return a;\n }\n\n private static 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 static 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 static long[] nal(int n)\n {\n long[] a = new long[n];\n for(int i=0;i<n;i++) a[i] = nl();\n return a;\n }\n //private void tr(Object... o) { if(o.length() > 0)System.out.println(Arrays.deepToString(o)); }\n}\n\nclass FastReader{\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 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}", "src_uid": "3a9258070ff179daf33a4515def9897a"} {"source_code": "import static java.lang.System.currentTimeMillis;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class D {\n\n static void solve() throws IOException {\n // while (true) {\n // testWithVsWithout();\n // if (false) {\n // break;\n // }\n // }\n // test();\n int n = nextInt(), m = nextInt();\n// long time = currentTimeMillis();\n long answer = solve(n, m);\n// System.err.println(currentTimeMillis() - time);\n out.println(answer);\n }\n\n static void test() {\n for (int n = 1; n < 100; n++) {\n for (int m = 0; 2 * m <= n; m++) {\n long got = solve(n, m);\n long stup = solveStupid(n, m);\n if (got != stup) {\n throw new AssertionError();\n }\n }\n }\n System.err.println(\"pass\");\n }\n\n static void testWithVsWithout() {\n Random rng = new Random();\n int n = rng.nextInt(32001);\n while (n < 5) {\n n = rng.nextInt(32001);\n }\n int m = rng.nextInt(n / 2);\n long got = solve(n, m);\n long stup = solveWithoutOptimizations(n, m);\n if (got != stup) {\n throw new AssertionError();\n }\n System.err.println(\"pass\");\n }\n\n private static long solve(int n, int m) {\n Point[] pointsLeft = new Point[n];\n Point[] pointsRight = new Point[n];\n for (int i = 0; i < n; i++) {\n pointsLeft[i] = new Point((i + 1) * 2, (i + 1) * 2);\n pointsRight[i] = new Point(4 * (n + 1) - (i + 1) * 2, (i + 1) * 2);\n // pointsLeft[i] = new Point((i+1) * 0.5, (i+1) * ok);\n // pointsRight[i] = new Point(n + 1 - (i+1) * 0.5, (i+1) * ok);\n }\n\n long answer = 0;\n\n int lastSegmentThing = m;\n\n int rightStop = n - m;\n\n for (int leftPointId = m; leftPointId + m < n; leftPointId++) {\n\n int segmentLeft = -1, segmentRight = -1;\n\n int xx, yy, theirDx, theirDy;\n long theirAbs, yyyy3;\n\n {\n int rightPointId = leftPointId;\n xx = pointsLeft[leftPointId].x + pointsRight[rightPointId].x >> 1;\n yy = pointsLeft[leftPointId].y + pointsRight[rightPointId].y >> 1;\n theirDx = xx - pointsLeft[leftPointId].x;\n theirDy = yy - pointsLeft[leftPointId].y;\n theirAbs = (long) theirDx * theirDx + (long) theirDy * theirDy\n * 3;\n\n yyyy3 = (long) yy * yy * 3;\n\n for (int low = lastSegmentThing; low + m < n; low++) {\n long lowX = 4 * (low + 1);\n long dx = xx - lowX;\n long abs = dx * dx + yyyy3;\n if (abs < theirAbs) {\n segmentLeft = low;\n break;\n }\n }\n }\n\n // timeFirst += currentTimeMillis();\n int yyyy3i = (int) yyyy3;\n int theirAbsi = (int) theirAbs;\n if (segmentLeft < 0) {\n break;\n }\n lastSegmentThing = segmentLeft;\n\n segmentRight = n - 1 - segmentLeft;\n\n answer += segmentRight - segmentLeft + 1;\n\n int dx;\n\n int yyyy3MinusTheirAbsi = yyyy3i - theirAbsi;\n\n int curAddInt = 0;\n\n for (int rightPointId = leftPointId + 1; rightPointId < rightStop; rightPointId++) {\n --xx;\n ++yy;\n // xx = pointsLeft[leftPointId].x + pointsRight[rightPointId].x\n // >> 1;\n // yy = pointsLeft[leftPointId].y + pointsRight[rightPointId].y\n // >> 1;\n --theirDx;\n ++theirDy;\n // theirDx = xx - pointsLeft[leftPointId].x;\n // theirDy = yy - pointsLeft[leftPointId].y;\n yyyy3MinusTheirAbsi += 2 * theirDx + 1;\n yyyy3MinusTheirAbsi -= 6 * theirDy - 3;\n // theirAbs = theirDx * theirDx + theirDy * theirDy * 3;\n yyyy3MinusTheirAbsi += 6 * yy - 3;\n // if (yyyy3 > Integer.MAX_VALUE) {\n // System.err.println(yyyy3);\n // }\n // long yyyy3 = yy * yy * 3;\n // if (segmentLeft < lastLeftForThisRight[rightPointId]) {\n // segmentLeft = lastLeftForThisRight[rightPointId];\n // }\n // if(segmentRight > lastRightForThisRight[rightPointId]) {\n // segmentRight = lastRightForThisRight[rightPointId];\n // }\n int lowX = 4 * (segmentLeft + 1);\n dx = xx - lowX;\n int abs = dx * dx + yyyy3MinusTheirAbsi;\n while (segmentLeft <= segmentRight) {\n // if (dx * dx > Integer.MAX_VALUE) {\n // System.err.println(dx * dx);\n // }\n if (abs < 0) {\n break;\n } else {\n ++segmentLeft;\n abs -= 8 * dx - 16;\n dx -= 4;\n }\n }\n\n lowX = 4 * (segmentRight + 1);\n dx = (xx - lowX);\n abs = dx * dx + yyyy3MinusTheirAbsi;\n\n while (segmentLeft <= segmentRight) {\n if (abs < 0) {\n break;\n } else {\n --segmentRight;\n abs += 8 * dx + 16;\n dx += 4;\n }\n }\n\n if (segmentLeft > segmentRight) {\n rightStop = rightPointId;\n break;\n }\n curAddInt += segmentRight - segmentLeft + 1;\n }\n answer += 2L * curAddInt;\n }\n\n // System.err.println(\"time first: \"+timeFirst);\n // System.err.println(\"time second: \"+timeSecond);\n return answer * 3L;\n }\n\n private static long solveWithoutOptimizations(int n, int m) {\n Point[] pointsLeft = new Point[n];\n Point[] pointsRight = new Point[n];\n for (int i = 0; i < n; i++) {\n pointsLeft[i] = new Point((i + 1) * 2, (i + 1) * 2);\n pointsRight[i] = new Point(4 * (n + 1) - (i + 1) * 2, (i + 1) * 2);\n }\n\n long answer = 0;\n\n int lastSegmentThing = m;\n\n for (int leftPointId = m; leftPointId + m < n; leftPointId++) {\n\n int segmentLeft = -1, segmentRight = -1;\n {\n int rightPointId = leftPointId;\n long xx = pointsLeft[leftPointId].x\n + pointsRight[rightPointId].x >> 1;\n long yy = pointsLeft[leftPointId].y\n + pointsRight[rightPointId].y >> 1;\n long theirDx = xx - pointsLeft[leftPointId].x;\n long theirDy = yy - pointsLeft[leftPointId].y;\n long theirAbs = theirDx * theirDx + (long) theirDy * theirDy\n * 3;\n\n for (int low = lastSegmentThing; low + m < n; low++) {\n long lowX = 4 * (low + 1);\n long dx = xx - lowX;\n long abs = dx * dx + yy * yy * 3;\n if (abs < theirAbs) {\n segmentLeft = low;\n break;\n }\n }\n }\n\n if (segmentLeft < 0) {\n break;\n }\n lastSegmentThing = segmentLeft;\n\n segmentRight = n - 1 - segmentLeft;\n\n answer += segmentRight - segmentLeft + 1;\n\n for (int rightPointId = leftPointId + 1; rightPointId < n - m; rightPointId++) {\n long xx = pointsLeft[leftPointId].x\n + pointsRight[rightPointId].x >> 1;\n long yy = pointsLeft[leftPointId].y\n + pointsRight[rightPointId].y >> 1;\n long theirDx = xx - pointsLeft[leftPointId].x;\n long theirDy = yy - pointsLeft[leftPointId].y;\n long theirAbs = theirDx * theirDx + theirDy * theirDy * 3;\n while (segmentLeft <= segmentRight) {\n long lowX = 4 * (segmentLeft + 1);\n long dx = xx - lowX;\n long abs = dx * dx + yy * yy * 3;\n if (abs < theirAbs) {\n break;\n } else {\n ++segmentLeft;\n }\n }\n\n while (segmentLeft <= segmentRight) {\n long lowX = 4 * (segmentRight + 1);\n long dx = xx - lowX;\n long abs = dx * dx + yy * yy * 3;\n if (abs < theirAbs) {\n break;\n } else {\n --segmentRight;\n }\n }\n\n if (segmentLeft > segmentRight) {\n break;\n }\n answer += 2 * (segmentRight - segmentLeft + 1);\n }\n }\n\n return answer * 3L;\n }\n\n static long solveStupid(int n, int m) {\n Point[] pointsLeft = new Point[n];\n Point[] pointsRight = new Point[n];\n // double ok = Math.sqrt(3) * 0.5;\n for (int i = 0; i < n; i++) {\n pointsLeft[i] = new Point((i + 1) * 2, (i + 1) * 2);\n pointsRight[i] = new Point(4 * (n + 1) - (i + 1) * 2, (i + 1) * 2);\n // pointsLeft[i] = new Point((i+1) * 0.5, (i+1) * ok);\n // pointsRight[i] = new Point(n + 1 - (i+1) * 0.5, (i+1) * ok);\n }\n\n long answer = 0;\n\n for (int leftPointId = m; leftPointId + m < n; leftPointId++) {\n\n for (int rightPointId = m; rightPointId + m < n; rightPointId++) {\n long xx = pointsLeft[leftPointId].x\n + pointsRight[rightPointId].x >> 1;\n long yy = pointsLeft[leftPointId].y\n + pointsRight[rightPointId].y >> 1;\n\n long theirDx = xx - pointsLeft[leftPointId].x;\n long theirDy = yy - pointsLeft[leftPointId].y;\n long theirAbs = theirDx * theirDx + theirDy * theirDy * 3;\n\n for (int low = m; low + m < n; low++) {\n long lowX = 4 * (low + 1);\n long dx = xx - lowX;\n long abs = dx * dx + yy * yy * 3;\n if (abs < theirAbs) {\n ++answer;\n }\n }\n }\n }\n\n return answer * 3L;\n }\n\n static class Point {\n final int x, y;\n\n public Point(int x, int y) {\n this.x = x;\n this.y = y;\n }\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(\"d.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", "src_uid": "355cc23d7a4addfc920c6e5e72a2bb64"} {"source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class test {\n\n\tstatic int INF = 1000000007;\n\n\tpublic static void main(String[] args) {\n//\t\tint test = fs.nextInt();\n\t\tint test = 1;\n\t\tfor (int cases = 0; cases < test; cases++) {\n\t\t\tint x1 = fs.nextInt();\n\t\t\tint x2 = fs.nextInt();\n\t\t\tint x3 = fs.nextInt();\n\t\t\tint y1 = fs.nextInt();\n\t\t\tint y2 = fs.nextInt();\n\t\t\tint y3 = fs.nextInt();\n\t\t\tint n = fs.nextInt();\n\t\t\tint z = x1 + x2 + x3;\n\t\t\tint q = y1 + y2 + y3;\n\t\t\tint a = (int) Math.ceil((double) z / 5);\n\t\t\tint b = (int) Math.ceil((double)q / 10);\n\t\t\tif (a + b <= n) {\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t} else {\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic class CPair {\n\t\tchar x;\n\t\tint y;\n\n\t\tCPair(char x, int y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\t}\n\n\tstatic class LongPair {\n\t\tlong first;\n\t\tlong second;\n\n\t\tLongPair(long a, long b) {\n\t\t\tthis.first = a;\n\t\t\tthis.second = b;\n\t\t}\n\n\t}\n\n\tstatic long power(long x, long y, long p) {\n\t\tlong res = 1;\n\t\tx = x % p;\n\t\twhile (y > 0) {\n\t\t\tif (y % 2 == 1)\n\t\t\t\tres = (res * x) % p;\n\t\t\ty = y >> 1;\n\t\t\tx = (x * x) % p;\n\t\t}\n\t\treturn res;\n\t}\n\n\tstatic long modInverse(long n, long p) {\n\t\treturn power(n, p - 2, p);\n\t}\n\n\tstatic long nCrModPFermat(long n, long r, long p) {\n\t\tlong ans1 = 1;\n\t\tlong i = n;\n\t\tlong k = r;\n\t\twhile (k > 0) {\n\t\t\tans1 = mul(ans1, i, p);\n\t\t\ti--;\n\t\t\tk--;\n\t\t}\n\t\tlong ans2 = 1;\n\t\twhile (r > 0) {\n\t\t\tans2 = mul(ans2, r, p);\n\t\t\tr--;\n\t\t}\n\t\tr = modInverse(ans2, p);\n\t\tans1 = mul(ans1, r, p);\n\t\treturn ans1;\n\t}\n\n\tstatic long facCalc(long total) {\n\t\tlong ans = 1;\n\t\tfor (long i = 2; i <= total; i++) {\n\t\t\tans = mul(ans, i, INF);\n\t\t}\n\t\treturn ans;\n\t}\n\n\tstatic long mul(long a, long b, long p) {\n\t\treturn ((a % p) * (b % p)) % p;\n\t}\n\n\tstatic void sieve() {\n\t\tboolean prime[] = new boolean[101];\n\t\tArrays.fill(prime, true);\n\t\tprime[1] = false;\n\t\tfor (int i = 2; i * i <= prime.length - 1; i++) {\n\t\t\tfor (int j = i * i; j <= prime.length - 1; j += i) {\n\t\t\t\tprime[j] = false;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static int[] radixSort(int[] f) {\n\t\treturn radixSort(f, f.length);\n\t}\n\n\tpublic static int[] radixSort(int[] f, int n) {\n\t\tint[] to = new int[n];\n\t\t{\n\t\t\tint[] b = new int[65537];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tb[1 + (f[i] & 0xffff)]++;\n\t\t\tfor (int i = 1; i <= 65536; i++)\n\t\t\t\tb[i] += b[i - 1];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tto[b[f[i] & 0xffff]++] = f[i];\n\t\t\tint[] d = f;\n\t\t\tf = to;\n\t\t\tto = d;\n\t\t}\n\t\t{\n\t\t\tint[] b = new int[65537];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tb[1 + (f[i] >>> 16)]++;\n\t\t\tfor (int i = 1; i <= 65536; i++)\n\t\t\t\tb[i] += b[i - 1];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tto[b[f[i] >>> 16]++] = f[i];\n\t\t\tint[] d = f;\n\t\t\tf = to;\n\t\t\tto = d;\n\t\t}\n\t\treturn f;\n\t}\n\n\tstatic void printArray(int ar[]) {\n\t\tSystem.out.println(Arrays.toString(ar));\n\t}\n\n\tstatic class Pair {\n\t\tint first, second;\n\n\t\tpublic Pair(int first, int second) {\n\t\t\tthis.first = first;\n\t\t\tthis.second = second;\n\t\t}\n\n\t}\n\n\tstatic class Pair2 {\n\t\tint first;\n\t\tPair second;\n\n\t\tpublic Pair2(int first, Pair second) {\n\t\t\tthis.first = first;\n\t\t\tthis.second = second;\n\t\t}\n\n\t}\n\n\tstatic long expmodulo(long a, long b, long c) {\n\t\tlong x = 1;\n\t\tlong y = a;\n\t\twhile (b > 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 (long) x % c;\n\t}\n\n\t// static int modInverse(int a, int m) {\n\t// int m0 = m;\n\t// int y = 0, x = 1;\n\t//\n\t// if (m == 1)\n\t// return 0;\n\t//\n\t// while (a > 1) {\n\t// int q = a / m;\n\t// int t = m;\n\t// m = a % m;\n\t// a = t;\n\t// t = y;\n\t// y = x - q * y;\n\t// x = t;\n\t// }\n\t// if (x < 0)\n\t// x += m0;\n\t// return x;\n\t// }\n\n\tstatic int gcd(int a, int b) {\n\t\tif (b == 0)\n\t\t\treturn a;\n\t\treturn gcd(b, a % b);\n\t}\n\n\tstatic void sortMyMapusingValues(HashMap<Integer, Integer> hm) {\n\n\t\tList<Map.Entry<Integer, Integer>> capitalList = new LinkedList<>(hm.entrySet());\n\n\t\tCollections.sort(capitalList, new Comparator<Map.Entry<Integer, Integer>>() {\n\t\t\tpublic int compare(Map.Entry<Integer, Integer> o1, Map.Entry<Integer, Integer> o2) {\n\t\t\t\treturn (o1.getValue()).compareTo(o2.getValue());\n\t\t\t}\n\t\t});\n\t\tHashMap<Integer, Integer> result = new HashMap<>();\n\t\tfor (Map.Entry<Integer, Integer> entry : capitalList) {\n\t\t\tresult.put(entry.getKey(), entry.getValue());\n\t\t}\n\t}\n\n\tstatic boolean ispowerof2(long num) {\n\t\tif ((num & (num - 1)) == 0)\n\t\t\treturn true;\n\t\treturn false;\n\t}\n\n\tstatic void primeFactors(int n) {\n\t\twhile (n % 2 == 0) {\n\t\t\tSystem.out.print(2 + \" \");\n\t\t\tn /= 2;\n\t\t}\n\t\tfor (int i = 3; i <= Math.sqrt(n); i += 2) {\n\t\t\twhile (n % i == 0) {\n\t\t\t\tSystem.out.print(i + \" \");\n\t\t\t\tn /= i;\n\t\t\t}\n\t\t}\n\t\tif (n > 2)\n\t\t\tSystem.out.print(n);\n\t}\n\n\tstatic boolean isPrime(long n) {\n\t\t// Corner cases\n\t\tif (n <= 1)\n\t\t\treturn false;\n\t\tif (n <= 3)\n\t\t\treturn true;\n\t\tif (n % 2 == 0 || n % 3 == 0)\n\t\t\treturn false;\n\n\t\tlong sq = (long) Math.sqrt(n);\n\t\tfor (int i = 5; i <= sq; 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\tstatic class Graph {\n\t\tHashMap<Integer, LinkedList<Integer>> hm = new HashMap<Integer, LinkedList<Integer>>();\n\n\t\tprivate void addVertex(int vertex) {\n\t\t\thm.put(vertex, new LinkedList<>());\n\t\t}\n\n\t\tprivate void addEdge(int source, int dest, boolean bi) {\n\t\t\tif (!hm.containsKey(source))\n\t\t\t\taddVertex(source);\n\t\t\tif (!hm.containsKey(dest))\n\t\t\t\taddVertex(dest);\n\t\t\thm.get(source).add(dest);\n\t\t\tif (bi) {\n\t\t\t\thm.get(dest).add(source);\n\t\t\t}\n\t\t}\n\n\t\tprivate boolean uniCycle(int i, HashSet<Integer> visited, int parent) {\n\t\t\tvisited.add(i);\n\t\t\tLinkedList<Integer> list = hm.get(i);\n\t\t\tIterator<Integer> it = list.iterator();\n\t\t\twhile (it.hasNext()) {\n\t\t\t\tInteger integer = (Integer) it.next();\n\t\t\t\tif (!visited.contains(integer)) {\n\t\t\t\t\tif (uniCycle(integer, visited, i))\n\t\t\t\t\t\treturn true;\n\t\t\t\t} else if (integer != parent) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\n\t\tprivate boolean uniCyclic() {\n\t\t\tHashSet<Integer> visited = new HashSet<Integer>();\n\t\t\tSet<Integer> set = hm.keySet();\n\t\t\tfor (Integer integer : set) {\n\t\t\t\tif (!visited.contains(integer)) {\n\t\t\t\t\tif (uniCycle(integer, visited, -1)) {\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\n\t\tprivate boolean isbiCycle(int i, HashSet<Integer> visited, HashSet<Integer> countered) {\n\t\t\tif (countered.contains(i))\n\t\t\t\treturn true;\n\t\t\tif (visited.contains(i))\n\t\t\t\treturn false;\n\t\t\tvisited.add(i);\n\t\t\tcountered.add(i);\n\t\t\tLinkedList<Integer> list = hm.get(i);\n\t\t\tIterator<Integer> it = list.iterator();\n\t\t\twhile (it.hasNext()) {\n\t\t\t\tInteger integer = (Integer) it.next();\n\t\t\t\tif (isbiCycle(integer, visited, countered)) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tcountered.remove(i);\n\t\t\treturn false;\n\t\t}\n\n\t\tBoolean isReachable(int s, int d, int k) {\n\t\t\tif (hm.isEmpty()) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tLinkedList<Integer> temp;\n\t\t\tboolean visited[] = new boolean[k];\n\t\t\tLinkedList<Integer> queue = new LinkedList<Integer>();\n\t\t\tvisited[s] = true;\n\t\t\tqueue.add(s);\n\t\t\tIterator<Integer> i;\n\t\t\twhile (queue.size() != 0) {\n\t\t\t\ts = queue.poll();\n\t\t\t\tint n;\n\t\t\t\ti = hm.get(s).listIterator();\n\n\t\t\t\t// Get all adjacent vertices of the dequeued vertex s\n\t\t\t\t// If a adjacent has not been visited, then mark it\n\t\t\t\t// visited and enqueue it\n\t\t\t\twhile (i.hasNext()) {\n\t\t\t\t\tn = i.next();\n\n\t\t\t\t\t// If this adjacent node is the destination node,\n\t\t\t\t\t// then return true\n\t\t\t\t\tif (n == d)\n\t\t\t\t\t\treturn true;\n\n\t\t\t\t\t// Else, continue to do BFS\n\t\t\t\t\tif (!visited[n]) {\n\t\t\t\t\t\tvisited[n] = true;\n\t\t\t\t\t\tqueue.add(n);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// If BFS is complete without visited d\n\t\t\treturn false;\n\t\t}\n\n\t\tprivate boolean isbiCyclic() {\n\t\t\tHashSet<Integer> visited = new HashSet<Integer>();\n\t\t\tHashSet<Integer> countered = new HashSet<Integer>();\n\t\t\tSet<Integer> set = hm.keySet();\n\t\t\tfor (Integer integer : set) {\n\t\t\t\tif (isbiCycle(integer, visited, countered)) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tstatic class Node {\n\t\tNode left, right;\n\t\tint data;\n\n\t\tpublic Node(int data) {\n\t\t\tthis.data = data;\n\t\t}\n\n\t\tpublic void insert(int val) {\n\t\t\tif (val <= data) {\n\t\t\t\tif (left == null) {\n\t\t\t\t\tleft = new Node(val);\n\t\t\t\t} else {\n\t\t\t\t\tleft.insert(val);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (right == null) {\n\t\t\t\t\tright = new Node(val);\n\t\t\t\t} else {\n\t\t\t\t\tright.insert(val);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tpublic boolean contains(int val) {\n\t\t\tif (data == val) {\n\t\t\t\treturn true;\n\t\t\t} else if (val < data) {\n\t\t\t\tif (left == null) {\n\t\t\t\t\treturn false;\n\t\t\t\t} else {\n\t\t\t\t\treturn left.contains(val);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (right == null) {\n\t\t\t\t\treturn false;\n\t\t\t\t} else {\n\t\t\t\t\treturn right.contains(val);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tpublic void inorder() {\n\t\t\tif (left != null) {\n\t\t\t\tleft.inorder();\n\t\t\t}\n\t\t\tSystem.out.print(data + \" \");\n\t\t\tif (right != null) {\n\t\t\t\tright.inorder();\n\t\t\t}\n\t\t}\n\n\t\tpublic int maxDepth() {\n\t\t\tif (left == null)\n\t\t\t\treturn 0;\n\t\t\tif (right == null)\n\t\t\t\treturn 0;\n\t\t\telse {\n\t\t\t\tint ll = left.maxDepth();\n\t\t\t\tint rr = right.maxDepth();\n\t\t\t\tif (ll > rr)\n\t\t\t\t\treturn (ll + 1);\n\t\t\t\telse\n\t\t\t\t\treturn (rr + 1);\n\t\t\t}\n\t\t}\n\n\t\tpublic int countNodes() {\n\t\t\tif (left == null)\n\t\t\t\treturn 1;\n\t\t\tif (right == null)\n\t\t\t\treturn 1;\n\t\t\telse {\n\t\t\t\treturn left.countNodes() + right.countNodes() + 1;\n\t\t\t}\n\t\t}\n\n\t\tpublic void preorder() {\n\t\t\tSystem.out.print(data + \" \");\n\t\t\tif (left != null) {\n\t\t\t\tleft.inorder();\n\t\t\t}\n\n\t\t\tif (right != null) {\n\t\t\t\tright.inorder();\n\t\t\t}\n\n\t\t}\n\n\t\tpublic void postorder() {\n\t\t\tif (left != null) {\n\t\t\t\tleft.inorder();\n\t\t\t}\n\n\t\t\tif (right != null) {\n\t\t\t\tright.inorder();\n\t\t\t}\n\t\t\tSystem.out.print(data + \" \");\n\n\t\t}\n\n\t\tpublic void levelorder(Node node) {\n\t\t\tLinkedList<Node> ll = new LinkedList<Node>();\n\t\t\tll.add(node);\n\t\t\tgetorder(ll);\n\n\t\t}\n\n\t\tpublic void getorder(LinkedList<Node> ll) {\n\t\t\twhile (!ll.isEmpty()) {\n\t\t\t\tNode node = ll.poll();\n\t\t\t\tSystem.out.print(node.data + \" \");\n\t\t\t\tif (node.left != null)\n\t\t\t\t\tll.add(node.left);\n\t\t\t\tif (node.right != null)\n\t\t\t\t\tll.add(node.right);\n\t\t\t}\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\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\tstatic class OutputWriter {\n\t\tprivate final PrintWriter writer;\n\n\t\tpublic OutputWriter(OutputStream outputStream) {\n\t\t\twriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(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\n\t\tpublic void flush() {\n\t\t\twriter.flush();\n\t\t}\n\n\t}\n\n\tprivate static final FastReader fs = new FastReader();\n\tprivate static final OutputWriter op = new OutputWriter(System.out);\n}", "src_uid": "fe6301816dea7d9cea1c3a06a7d1ea7e"} {"source_code": "import java.io.*;\nimport java.util.Arrays;\n\npublic class Main {\n static myScanner sc;\n static PrintWriter pw;\n\n public static void main(String[] args) throws IOException {\n BufferedReader input = new BufferedReader(new InputStreamReader(System.in));\n //BufferedReader input = new BufferedReader(new FileReader(new File(\"data.in\")));\n sc = new myScanner(input);\n\n //pw = new PrintWriter(new File(\"data.out\"));\n pw = new PrintWriter(System.out);\n\n solve();\n\n pw.flush();\n pw.close();\n }\n static void solve() {\n int n=sc.nextInt();\n int max=-99999999,k=0;\n for (int i=0;i<n-1;i++)if ((k=sc.nextInt())>max)max=k;\n int last = sc.nextInt();\n if (last>max)max=last;\n pw.print(max^last);\n }\n}\n\nclass myScanner {\n private char[] buffer = new char[1 << 8];\n private int pos = 1;\n\n private BufferedReader reader;\n\n public myScanner(BufferedReader reader) {\n this.reader = reader;\n }\n\n public boolean hasNext() {\n return pos > 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 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 double nextDouble() {\n loadBuffer();\n double 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 / round : result / round;\n }\n\n private void checkValidNumber(boolean condition) {\n if (!condition) throw new NumberFormatException(current());\n }\n}", "src_uid": "f45c769556ac3f408f5542fa71a67d98"} {"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 scanner = new Scanner(System.in);\n\t\tint inputNum = scanner.nextInt();\n\t\tint[] givenTemps = new int[inputNum];\n\t\tfor(int i = 0; i < inputNum; i++) {\n\t\t\tgivenTemps[i] = scanner.nextInt();\n\t\t}\n\t\tint numBetween = givenTemps[1] - givenTemps[0];\n\t\tfor(int j = 0; j < inputNum - 1; j++) {\n\t\t\tif(givenTemps[j+1] - givenTemps[j] != numBetween) {\n\t\t\t\tSystem.out.println(givenTemps[inputNum - 1]);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(givenTemps[inputNum - 1] + numBetween);\n\t\treturn;\t\n\t\t\n\t\t\n\t}\n\n}\n", "src_uid": "d04fa4322a1b300bdf4a56f09681b17f"} {"source_code": "import java.util.*;\npublic class LuckyNumber\n{\npublic static void main(String args[])\n{\n int n;\n Scanner in=new Scanner(System.in);\n n=in.nextInt();\n if((n%4==0)||(n%7==0)||(n%47==0)||(n%744==0)||(n%47==7))\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n}\n} ", "src_uid": "78cf8bc7660dbd0602bf6e499bc6bb0d"} {"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 * @author sheep\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n\n final int MOD = 1000000007;\n\n private int addMod(int x, int y) {\n int ret = x + y;\n if (ret < 0) ret += MOD;\n if (ret >= MOD) ret -= MOD;\n\n return ret;\n }\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int choose[][] = new int[200][200];\n for (int i = 0; i < choose.length; ++i) {\n choose[i][0] = choose[i][i] = 1;\n for (int j = 1; j < i; ++j) {\n choose[i][j] = choose[i - 1][j] + choose[i - 1][j - 1];\n }\n }\n\n int n = in.nextInt();\n int m = in.nextInt();\n int upper = in.nextInt();\n\n int dp[][][][] = new int[2][n + 1][upper + 1][upper + 1];\n for (int i = 1; i + i <= n; ++i) {\n dp[0][2 * i][1][i] = 1;\n }\n\n int ans = 0;\n\n for (int i = 0; i < m - 1; ++i) {\n int now = i & 1, next = now ^ 1;\n\n for (int j = 0; j <= n; ++j) {\n for (int k = 1; k <= upper; ++k) {\n for (int r = 1; r <= upper; ++r) {\n dp[next][j][k][r] = 0;\n }\n }\n }\n\n for (int j = 1; j * 2 <= n; ++j) {\n dp[next][2 * j][1][j] = 1;\n }\n\n for (int j = 0; j <= n; ++j) {\n for (int k = 1; k <= upper; ++k) {\n for (int r = 1; r <= upper; ++r) {\n if (0 == dp[now][j][k][r]) continue;\n if (j > 1) {\n ans = addMod(ans, dp[now][j][k][r]);\n }\n for (int delta = 1; j + 2 * delta <= n && delta <= upper; ++delta) {\n int nextPlan = k * choose[delta + r - 1][r - 1];\n if (nextPlan > upper) break;\n dp[next][j + 2 * delta][nextPlan][delta] = addMod(dp[next][j + 2 * delta][nextPlan][delta], dp[now][j][k][r]);\n }\n }\n }\n }\n }\n\n out.println(ans);\n }\n}\n\nclass InputReader {\n BufferedReader reader;\n StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (Exception e) {\n throw new UnknownError();\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n", "src_uid": "c6d275b1e1d5c9e39e2cf990a635fa6b"} {"source_code": "\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class Minimise {\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 public static void main(String[] args) {\n FastReader in = new FastReader();\n String[] s = in.nextLine().split(\" \");\n int p = Math.min(Integer.parseInt(s[0]),Integer.parseInt(s[1]));\n BigInteger bigInteger = new BigInteger(String.valueOf(p));\n BigInteger fact = BigInteger.ONE;\n while (p>1){\n fact = BigInteger.valueOf(p).multiply(fact);\n p--;\n }\n System.out.println(fact);\n }\n}", "src_uid": "7bf30ceb24b66d91382e97767f9feeb6"} {"source_code": "import java.util.Scanner;\npublic class many\n{\n\t\n\tpublic static void main(String [] args)\n\t{\n Scanner input = new Scanner(System.in);\n\t\t\n\t\tint c = input.nextInt();\n\t\tinput.nextLine();\n\t\tString s = input.nextLine();\n\t\tint arr[] = new int[10000];\n int\tintIndex = 0;\n String arrS[] = new String[10000];\n int stringIndex = 0;\t\t\n\t\tint max = 0;\n\t\t\n\t\tfor(int i =0; i< (s.length()-1) ; i++)\n\t\t{\n\t\t\tString s2 = Character.toString(s.charAt(i)) + Character.toString(s.charAt(i+1));\n\t\t\tarrS[stringIndex] = s2;\n\t\t\tstringIndex++;\n\t\t}\n\t\t\n\t\tfor(int i=0; i<stringIndex;i++)\n\t\t{\n\t\t\tint count =1;\n\t\t\tfor(int j=i+1; j<stringIndex;j++)\n\t\t\t{\n\t\t\t\tif(arrS[i] != null){\n\t\t\t\t if(arrS[i].equals(arrS[j])){\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t arrS[j] = null;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tarr[intIndex] = count;\n\t\t\tif(arr[intIndex] > arr[max])max = intIndex;\n\t\t\tintIndex++;\n\t\t\t\n\t\t} \n\t\t System.out.println(arrS[max]);\n\t\t \n\t\t\n\t\t\n\t}\n}", "src_uid": "e78005d4be93dbaa518f3b40cca84ab1"} {"source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.lang.reflect.Array;\nimport java.util.*;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\npublic class Main1 {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastReader in = new FastReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n Task solver = new Task();\n solver.solve(1, in, out);\n out.close();\n }\n static class Task {\n static char[] s;\n static int fun(char a,char b,String str){\n s=str.toCharArray();\n boolean m1,m2;\n m1=m2=false;\n int res=0;\n for(int i=s.length-1;i>=0;i--){\n if(s[i]==b){\n m1=true;\n for(int j=i;j<s.length-1;j++){\n swap(j,j+1);\n res++;\n }\n break;\n }\n }\n for(int i=s.length-2;i>=0;i--){\n if(s[i]==a){\n m2=true;\n for(int j=i;j<s.length-2;j++){\n swap(j,j+1);\n res++;\n }\n break;\n }\n }\n if(!m1||!m2) return Integer.MAX_VALUE;\n if(s[0]=='0'){\n for(int i=1;i<s.length-2;i++){\n if(s[i]!='0'){\n res+=i;\n break;\n }\n }\n }\n return res;\n }\n public void solve(int testNumber, FastReader in, PrintWriter out) {\n String str = in.next();\n int min = Integer.MAX_VALUE;\n min = Math.min(min, fun('2', '5', str));\n min = Math.min(min, fun('5', '0', str));\n min = Math.min(min, fun('7', '5', str));\n min = Math.min(min, fun('0', '0', str));\n out.println((min==Integer.MAX_VALUE)?\"-1\":min);\n }\n static void swap(int i, int j) {\n try {\n if (i != j) {\n char tmp = s[i];\n s[i] = s[j];\n s[j] = tmp;\n }\n } catch (ArrayIndexOutOfBoundsException e) {\n System.out.println(e.fillInStackTrace());\n }\n }\n }\n\n static class FastReader {\n BufferedReader br;\n StringTokenizer st;\n\n public FastReader(InputStream is) {\n br = new BufferedReader(new\n InputStreamReader(is));\n }\n\n public 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 public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public String nextLine() throws IOException {\n return br.readLine();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n }\n}\n\n", "src_uid": "ea1c737956f88be94107f2565ca8bbfd"} {"source_code": "import java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.BufferedReader;\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 Anirudh Rayabharam (anirudhrb@yandex.com)\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskC solver = new TaskC();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskC {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n long x = in.nextLong();\n\n long minHeight = 3 - x % 3;\n long sq = (long) Math.floor(Math.sqrt(1.0 + 24.0 * x));\n long maxHeight = (sq - 1) / 6;\n\n long ans = (maxHeight - minHeight + 3) / 3;\n out.println(ans);\n }\n}\n\nclass InputReader {\n public BufferedReader reader;\n private int tokenCount, nextTokenIndex;\n private String[] tokens;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n tokenCount = nextTokenIndex = 0;\n }\n\n public String next() {\n String nextLine;\n if (nextTokenIndex == tokenCount) {\n try {\n nextLine = reader.readLine();\n nextTokenIndex = 0;\n tokens = nextLine.split(\"\\\\s\");\n tokenCount = tokens.length;\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n\n return tokens[nextTokenIndex++];\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n}\n\n", "src_uid": "ab4f9cb3bb0df6389a4128e9ff1207de"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\tFastReader scn;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\n\tvoid solve() {\n\t\tint n = scn.nextInt();\n\t\tlong[] arr = new long[n + 1];\n\t\tfor(int i = 1; i <= n; i++) {\n\t\t\tarr[i] = scn.nextInt() + arr[i - 1];\n\t\t}\n\t\tint x = scn.nextInt(), y = scn.nextInt(), ans = 0;\n\t\t\n\t\tfor(int i = 1; i <= n; i++) {\n\t\t\tlong a = arr[i], b = arr[n] - arr[i];\n\t\t\tif(Math.min(a, b) >= x && Math.max(a, b) <= y) {\n\t\t\t\tans = i + 1;\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.println(ans);\n\t}\n\n\tvoid run() throws Exception {\n\t\tlong time = System.currentTimeMillis();\n\t\tboolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\tout = new PrintWriter(System.out);\n\t\tscn = new FastReader(oj);\n\t\tsolve();\n\t\tout.flush();\n\t\tif (!oj) {\n\t\t\tSystem.out.println(Arrays.deepToString(new Object[] { System.currentTimeMillis() - time + \" ms\" }));\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew Main().run();\n\t}\n\n\tclass FastReader {\n\t\tInputStream is;\n\n\t\tpublic FastReader(boolean onlineJudge) {\n\t\t\tis = onlineJudge ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\t}\n\n\t\tbyte[] inbuf = new byte[1024];\n\t\tpublic int lenbuf = 0, ptrbuf = 0;\n\n\t\tint readByte() {\n\t\t\tif (lenbuf == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (ptrbuf >= lenbuf) {\n\t\t\t\tptrbuf = 0;\n\t\t\t\ttry {\n\t\t\t\t\tlenbuf = is.read(inbuf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (lenbuf <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn inbuf[ptrbuf++];\n\t\t}\n\n\t\tboolean isSpaceChar(int c) {\n\t\t\treturn !(c >= 33 && c <= 126);\n\t\t}\n\n\t\tint skip() {\n\t\t\tint b;\n\t\t\twhile ((b = readByte()) != -1 && isSpaceChar(b))\n\t\t\t\t;\n\t\t\treturn b;\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tchar nextChar() {\n\t\t\treturn (char) skip();\n\t\t}\n\n\t\tString next() {\n\t\t\tint b = skip();\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\twhile (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\t\tsb.appendCodePoint(b);\n\t\t\t\tb = readByte();\n\t\t\t}\n\t\t\treturn sb.toString();\n\t\t}\n\n\t\tString nextLine() {\n\t\t\tint b = skip();\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\twhile ((!isSpaceChar(b) || b == ' ')) { // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\t\tsb.appendCodePoint(b);\n\t\t\t\tb = readByte();\n\t\t\t}\n\t\t\treturn sb.toString();\n\t\t}\n\n\t\tchar[] next(int n) {\n\t\t\tchar[] buf = new char[n];\n\t\t\tint b = skip(), p = 0;\n\t\t\twhile (p < n && !(isSpaceChar(b))) {\n\t\t\t\tbuf[p++] = (char) b;\n\t\t\t\tb = readByte();\n\t\t\t}\n\t\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t\t}\n\n\t\tint nextInt() {\n\t\t\tint num = 0, b;\n\t\t\tboolean minus = false;\n\t\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t\t;\n\t\t\tif (b == '-') {\n\t\t\t\tminus = true;\n\t\t\t\tb = readByte();\n\t\t\t}\n\n\t\t\twhile (true) {\n\t\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t} else {\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t\tb = readByte();\n\t\t\t}\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\tlong num = 0;\n\t\t\tint b;\n\t\t\tboolean minus = false;\n\t\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t\t;\n\t\t\tif (b == '-') {\n\t\t\t\tminus = true;\n\t\t\t\tb = readByte();\n\t\t\t}\n\n\t\t\twhile (true) {\n\t\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t} else {\n\t\t\t\t\treturn minus ? -num : num;\n\t\t\t\t}\n\t\t\t\tb = readByte();\n\t\t\t}\n\t\t}\n\n\t\tchar[][] nextMatrix(int n, int m) {\n\t\t\tchar[][] map = new char[n][];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tmap[i] = next(m);\n\t\t\treturn map;\n\t\t}\n\n\t\tint[] nextIntArray(int n) {\n\t\t\tint[] a = new int[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\ta[i] = nextInt();\n\t\t\treturn a;\n\t\t}\n\n\t\tlong[] nextLongArray(int n) {\n\t\t\tlong[] a = new long[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\ta[i] = nextLong();\n\t\t\treturn a;\n\t\t}\n\n\t\tint[][] next2DInt(int n, int m) {\n\t\t\tint[][] arr = new int[n][];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = nextIntArray(m);\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tlong[][] next2DLong(int n, int m) {\n\t\t\tlong[][] arr = new long[n][];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = nextLongArray(m);\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tint[] shuffle(int[] arr) {\n\t\t\tRandom r = new Random();\n\t\t\tfor (int i = 1, j; i < arr.length; i++) {\n\t\t\t\tj = r.nextInt(i);\n\t\t\t\tarr[i] = arr[i] ^ arr[j];\n\t\t\t\tarr[j] = arr[i] ^ arr[j];\n\t\t\t\tarr[i] = arr[i] ^ arr[j];\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\t}\n}", "src_uid": "e595a1d0c0e4bbcc99454d3148b4557b"} {"source_code": "\n\nimport java.util.Scanner;\n\npublic class Test {\n public static void main(String[] args) {\n\n Scanner in=new Scanner(System.in);\n Integer i=Integer.parseInt(in.nextLine());\n String str=in.nextLine();\n String []s=str.split(\" \");\n int max= 0;\n for (String x:s){\n int vol=0;\n for(int a=0;a<x.length();a++){\n int b=(int)x.charAt(a);\n if(b>=65 && b<=90) vol++;\n// System.out.println((int)x.charAt(a)); //65 - 90\n }\n max = Math.max(vol, max);\n }\n System.out.println(max);\n }\n}\n", "src_uid": "d3929a9acf1633475ab16f5dfbead13c"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\n\npublic class P656C_WithoutText {\n\tprivate static BufferedReader br;\n\tprivate static PrintWriter pw;\n\tpublic static void main(String[] args) throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tpw = new PrintWriter(System.out);\n\t\tString textLine = br.readLine();\n\t\t//String[] splitted = textLine.split(\"\\\\s+\");\n\t\tint n = textLine.length();\n\t\tlong result = 0;\n\t\t\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tchar c = textLine.charAt(i);\n\t\t\tint i1 = ('@' < c && '[' > c) ? 1 : 0;\n\t\t\tint i2 = ('`' < c && '{' > c) ? 1 : 0;\n\t\t\tint alphaIndex = c - (i2 == 0 ? 'A' : 'a') + 1;\n\t\t\t\n\t\t\tresult += alphaIndex * (i1 - i2);\n\t\t}\n\t\t\n\t\tpw.println(result);\n\t\tpw.close();\n\t}\n}", "src_uid": "d3fa5a3a008048dc4a9fbce1ebc61d67"} {"source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Duplicateelement {\n\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n long y = input.nextLong(), b = input.nextLong();\n long y1 = input.nextLong(), g = input.nextLong(), b1 = input.nextLong(), g1 = 0, g2 = 0;\n\n y = y - y1 * 2;\n b = b - b1 * 3;\n\n g1 = g - y;\n g2 = g - b;\n if (g1 >= 0 || g2 >= 0) {\n if (g1 >= 0 && g2 >= 0) {\n System.out.println(g1 + g2);\n } else if (g1 > 0 && g2 < 0) {\n System.out.println(g1);\n } else if (g1 < 0 && g2 > 0) {\n System.out.println(g2);\n }else{\n System.out.println(\"0\");\n }\n }else{\n System.out.println(\"0\");\n }\n\n }\n}", "src_uid": "35202a4601a03d25e18dda1539c5beba"} {"source_code": "import java.io.BufferedWriter;\nimport java.util.InputMismatchException;\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.util.HashMap;\nimport java.util.Map;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintStream;\nimport java.util.Set;\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\tTaskG solver = new TaskG();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskG {\n\n long INF= (long) 1e17;\n public void solve(int testNumber, MyScanner in, MyPrintWriter out) {\n long s = in.nextLong();\n out.println(solve(s));\n }\n public long solve(long s){\n long res = 0;\n for (int l = 0; l <= 55; l++)\n for (int r = 0; r <= 55; r++) {\n long L=0,R=INF;\n while(R-L>1){\nlong min=0;\n long max=0;\n long m = (R+L)/2;\n\n min += m;\n long v=m*2;\n for(int i=0;i<l;i++){\n min = Math.min(min + v, INF);\n v = Math.min(v * 2, INF);\n }\n v=m*2+1;\n for(int i=0;i<r;i++){\n min = Math.min(min + v, INF);\n v = Math.min(v * 2, INF);\n }\n\n max += m;\n v=m*2;\n for(int i=0;i<l;i++){\n max = Math.min(max + v, INF);\n v = Math.min(v * 2 + 1, INF);\n }\n v=m*2+1;\n for(int i=0;i<r;i++){\n max = Math.min(max + v, INF);\n v = Math.min(v * 2 + 1, INF);\n }\n if (s < min) {\n R = m;\n } else if (s > max) {\n L = m;\n } else {\n res += solve(s - min,l,r);\n break;\n }\n }\n }\n return res;\n }\n\n Map<Long, Long> cur = new HashMap<>();\n Map<Long, Long> nxt = new HashMap<>();\n private long solve(long s, int l, int r) {\nl = Math.max(l-1, 0);\n r = Math.max(r-1, 0);\n long[] cand = new long[l + r];\n for(int i=0;i<l;i++)cand[i] = (1L << i+1) - 1;\n for(int i=0;i<r;i++)cand[l + i] = (1L << i+1) - 1;\n Arrays.sort(cand);\n\n long rest = 0;\n for(int i=0;i<cand.length;i++)rest += cand[i];\n cur.clear();\n cur.put(0L, 1L);\n for(int i=cand.length-1;i>=0;i--) {\n nxt.clear();\n long c = cand[i];\n rest -= c;\n for(Map.Entry<Long, Long> e : cur.entrySet()) {\n long val = e.getKey();\n if (val + c <= s) {\n if(!nxt.containsKey(val+c)){\n nxt.put(val+c, e.getValue());\n } else{\n nxt.put(val+c, nxt.get(val+c) + e.getValue());\n }\n }\n if (val + rest >= s) {\n if(!nxt.containsKey(val)){\n nxt.put(val, e.getValue());\n } else{\n nxt.put(val, nxt.get(val) + e.getValue());\n }\n }\n }\n Map<Long, Long> tmp=cur;cur=nxt;nxt=tmp;\n }\n return cur.containsKey(s) ? cur.get(s) : 0;\n }\n\n}\n\nclass MyScanner {\n private final InputStream in;\n\n public MyScanner(InputStream in) {\n this.in = in;\n }\n\n private static final int BUFSIZE = 65536;\n int bufLen;\n int bufPtr;\n byte[] buf = new byte[BUFSIZE];\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 long nextLong() {\n int c = read();\n if (c == -1) throw new NoSuchElementException();\n while (c != '-' && (c < '0' || '9' < c)) {\n c = read();\n if (c == -1) throw new NoSuchElementException();\n }\n if (c == '-') return -nextLong();\n long res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = read();\n } while ('0' <= c && c <= '9');\n return res;\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 void println(Object... os) {\n if (os.length == 0) {\n out.println();\n return;\n }\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", "src_uid": "c142f8bc5252e739035992926545c251"} {"source_code": "import java.util.*;\n\npublic class aafef {\n\tpublic static void main(String[] args) {\n\t\tScanner scanny = new Scanner(System.in);\n\t\tint x = scanny.nextInt();\n\t\tint y = scanny.nextInt();\n\t\tif(x>=y) System.out.println(1);\n\t\telse if(y%x==0) System.out.println(y/x);\n\t\telse System.out.println((y/x)+1);\n\t}\n}", "src_uid": "04c067326ec897091c3dbcf4d134df96"} {"source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n \npublic class B\n{\n static void find_divisors(int n, ArrayList<Integer> li){\n\n for(int i = 1; i <= Math.sqrt(n); i++){\n if(n % i != 0)\n continue;\n li.add(i);\n\n if(n/i != i)\n li.add(n/i);\n }\n\n Collections.sort(li);\n }\n\n public static void process(int test_number)throws IOException\n {\n int n = ni(), k = ni();\n long dp[][] = new long[k + 1][n + 1]; \n dp[0][0] = 1l;\n dp[0][1] = 1l;\n\n ArrayList<Integer> l[] = new ArrayList[n + 1];\n for(int i = 0; i <= n; i++)\n l[i] = new ArrayList<Integer>();\n\n for(int i = 1; i <= n; i++){\n find_divisors(i, l[i]);\n //trace(i, l[i]);\n }\n\n for(int i = 1; i <= k; i++){\n for(int j = 1; j <= n; j++){\n\n for(int div : l[j]){ //trace(l[j]);\n dp[i][j] += dp[i - 1][div];\n dp[i][j] %= mod;\n }\n }\n }\n\n long res = 0l;\n for(int i = 1; i <= n; i++){\n res = (res + dp[k][i]) % mod; //trace(i, dp[k][i]);\n }\n\n pn(res);\n }\n \n static final long mod = (long)1e9+7l;\n \n static FastReader sc;\n static PrintWriter out;\n public static void main(String[]args)throws IOException\n {\n out = new PrintWriter(System.out);\n sc = new FastReader();\n \n long s = System.currentTimeMillis();\n int t = 1;\n //t = ni();\n for(int i = 1; i <= t; i++)\n process(i);\n \n out.flush();\n System.err.println(System.currentTimeMillis()-s+\"ms\");\n }\n\n static void trace(Object... o){ System.err.println(Arrays.deepToString(o)); };\n static void pn(Object o){ out.println(o); }\n static void p(Object o){ out.print(o); }\n static int ni()throws IOException{ return Integer.parseInt(sc.next()); }\n static long nl()throws IOException{ return Long.parseLong(sc.next()); }\n static double nd()throws IOException{ return Double.parseDouble(sc.next()); }\n static String nln()throws IOException{ return sc.nextLine(); }\n static long gcd(long a, long b)throws IOException{ return (b==0)?a:gcd(b,a%b);}\n static int gcd(int a, int b)throws IOException{ return (b==0)?a:gcd(b,a%b); }\n static int bit(long n)throws IOException{ return (n==0)?0:(1+bit(n&(n-1))); }\n \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{ st = new StringTokenizer(br.readLine()); } catch (IOException e){ e.printStackTrace(); } \n } \n return st.nextToken(); \n } \n \n String nextLine(){ \n String str = \"\"; \n try{ str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } \n return str; \n } \n } \n}\n", "src_uid": "c8cbd155d9f20563d37537ef68dde5aa"} {"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\tpublic void run() throws Exception{\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tint h1 = nextInt(), h2 = nextInt();\n\t\tint a = nextInt(), b = nextInt();\n\t\t\n\t\tif (h1 + a * 8 >= h2) {\n\t\t\tout.println(0);\n\t\t\tout.close();\n\t\t\treturn;\n\t\t}\n\t\tint progress = 12 * (a - b);\n\t\tif (progress <= 0) {\n\t\t\tout.println(-1);\n\t\t\tout.close();\n\t\t\treturn;\n\t\t}\n\n\t\tout.println((h2 - h1 - a * 8 + progress - 1) / progress);\n\t\tout.close();\n\t}\n\t\t\n\tpublic static void main(String[] args) throws Exception{\n\t\tnew Main().run();\n\t}\n}\n", "src_uid": "2c39638f07c3d789ba4c323a205487d7"} {"source_code": "import java.util.Scanner;\npublic class b146 {\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 for(int i=a+1;i<=177777;i++)\n if(ans(i)==b)\n {\n System.out.println(i);\n break;\n }\n }\nprivate static int ans(int a)\n{\n String b1=\"0\";\n String s=Integer.toString(a);\n for(int i=0;i<s.length();i++)\n if(s.charAt(i)=='4' || s.charAt(i)=='7')\n b1+=s.charAt(i);\n int c=Integer.parseInt(b1);\n return c;\n}\n}\n", "src_uid": "e5e4ea7a5bf785e059e10407b25d73fb"} {"source_code": "import java.util.Scanner;\n\npublic class SoldierAndBananas {\n\tpublic static void main(String[] args) {\n\t\tScanner scanner = new Scanner(System.in);\n\t\t//costFactor = cost for 1st banana\n\t\tint costFactor = scanner.nextInt();\n\t\tint initialMoney = scanner.nextInt();\n\t\tint numBananas = scanner.nextInt();\n\t\t//sum is 1 + 2 + 3 + ... + numBananas, the formula for general sequence is n(a1 + an) / 2.\n\t\tint sum = numBananas * (1 + numBananas) / 2 ;\n\t\t//calculate the total cost and print the money he needs (total cost of bananas - money he already has)\n\t\tint totalCost = sum * costFactor;\n\t\tint moneyNeeded = totalCost - initialMoney;\n\t\t//accounting for negative money (if he has more than enough he needs to borrow 0)\n\t\tif (moneyNeeded < 0) {\n\t\t\tmoneyNeeded = 0;\n\t\t}\n\t\tSystem.out.println(moneyNeeded);\n\t}\n}", "src_uid": "e87d9798107734a885fd8263e1431347"} {"source_code": "//import java.util.Scanner;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.PriorityQueue;\n\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\npublic class Main {\n\n\tpublic static void main(String[] args) throws IOException \n\t{\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\tint k=sc.nextInt();\n\t int arr[]=new int[n];\n\t for(int i=0;i<n;i++)\n\t \tarr[i]=sc.nextInt();\n\t int j=0,l=0;\n\t int count=0;\n\t int flag=0;\n\t for(int i=0;i<n;i++)\n\t {\n\t \tif(arr[i]<=k) {\n\t \t\tcount++;\n\t \t\t\n\t \t}\n\t \telse\n\t \t{\n\t \t\tflag=1;\n\t \t\tbreak;\n\t \t}\n\t }\n\t for(int i=n-1;i>0&&flag==1;i--)\n\t {\n\t \tif(arr[i]<=k) {\n\t \t\tcount++;\n\t \t}\n\t \telse\n\t \t{\n\t \t\tbreak;\n\t \t}\n\t }\n\t\t\t\n\t\t\tSystem.out.print(count);\n}\n}\n\tclass Scanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(s));\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {//lma ykon fe next token mesh hyd5ol fe while bs yrg3li l token elii wrah\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t//System.out.println(br.readLine());\n\t\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic String nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\tString x = next();\n\t\t\tStringBuilder sb = new StringBuilder(\"0\");\n\t\t\tdouble res = 0, f = 1;\n\t\t\tboolean dec = false, neg = false;\n\t\t\tint start = 0;\n\t\t\tif (x.charAt(0) == '-') {\n\t\t\t\tneg = true;\n\t\t\t\tstart++;\n\t\t\t}\n\t\t\tfor (int i = start; i < x.length(); i++)\n\t\t\t\tif (x.charAt(i) == '.') {\n\t\t\t\t\tres = Long.parseLong(sb.toString());\n\t\t\t\t\tsb = new StringBuilder(\"0\");\n\t\t\t\t\tdec = true;\n\t\t\t\t} else {\n\t\t\t\t\tsb.append(x.charAt(i));\n\t\t\t\t\tif (dec)\n\t\t\t\t\t\tf *= 10;\n\t\t\t\t}\n\t\t\tres += Long.parseLong(sb.toString()) / f;\n\t\t\treturn res * (neg ? -1 : 1);\n\t\t}\n\n\t\tpublic boolean ready() throws IOException {\n\t\t\treturn br.ready() || st.hasMoreTokens();//an br ready y3ni fe line tany w st 3ndha tokens (y3ni rg3ly next token bs mtd5olesh fe while)\n\t\t\n\t\t}}", "src_uid": "ecf0ead308d8a581dd233160a7e38173"} {"source_code": "// package CF;\n\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.Arrays;\nimport java.util.StringTokenizer;\n\npublic class F {\n\tstatic char [] num;\n\tstatic long [][][] memo;\n\tstatic int n;\n\tstatic long dp(int idx, int prev, int df){\n\t\tif(idx == n)\n\t\t\treturn df == 1?1:0;\n\t\tif(memo[idx][prev][df] != -1)\n\t\t\treturn memo[idx][prev][df];\n\t\tlong ans = 0;\n\t\tint dig = (prev + num[idx] - '0')/2;\n\t\tans += dp(idx+1, dig, df | (num[idx]-'0'==dig?0:1));\n\t\tint dig_c = (prev + num[idx] - '0' + 1)/2;\n\t\tif(dig_c != dig)\n\t\t\tans += dp(idx+1, dig_c, df | (num[idx]-'0'==dig_c?0:1));\n\t\treturn memo[idx][prev][df] = ans;\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\tnum = sc.next().toCharArray();\n\t\tn = num.length;\n\t\tmemo = new long[n+1][10][2];\n\t\tfor(long [][]i:memo)\n\t\t\tfor(long[]j:i)\n\t\t\tArrays.fill(j, -1);\n\t\tlong ans = 0;\n\t\tfor (int i = 0; i < 10; i++) {\n\t\t\tans += dp(1, i, num[0]-'0'==i?0:1);\n\t\t}\n\t\tout.println(ans);\n\t\tout.flush();\n\t\tout.close();\n\t}\n\n\tstatic class Scanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s)\n\t\t{\n\t\t\tbr = new BufferedReader(new InputStreamReader(s));\n\t\t}\n\n\t\tpublic Scanner(FileReader fileReader)\n\t\t{\n\t\t\tbr = new BufferedReader(fileReader);\n\t\t}\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\n\t\t{\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() throws IOException\n\t\t{\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic String nextLine() throws IOException\n\t\t{\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tpublic boolean ready() throws IOException\n\t\t{\n\t\t\treturn br.ready();\n\t\t}\n\t}\n}", "src_uid": "2dd8bb6e8182278d037aa3a59ca3517b"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Grep{\n\tpublic static void main(String[] args) throws IOException{\n\t\tBufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n List<Integer> nums = new ArrayList<>();\n String[] str = reader.readLine().split(\" \");\n\n for(String i : str){\n nums.add(Integer.parseInt(i));\n }\n\n List<Integer> list = new ArrayList<>();\n list.add(1);\n list.add(2);\n list.add(3);\n\n for(int i = 0; i < list.size(); i++){\n if(!nums.contains(list.get(i))){\n System.out.println(list.get(i));\n }\n }\n\t}\n}", "src_uid": "e167dc35a0d3b98c0414c66099e35920"} {"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.io.StreamTokenizer;\nimport java.util.Arrays;\n\n\npublic class A {\n\n\t\n\t\n\t\n\t// -- DEBUG switch --\n\tstatic final boolean DBG = true;\n\tstatic StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n\tstatic PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\n\n\tstatic int gcd(int a, int b) {\n\t\tif (b == 0)\n\t\t\treturn a;\n\t\treturn gcd(b, a%b);\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tlong ab = l(), ac = l(), bc = l();\n\t\tlong abc = (long)Math.sqrt(ab * ac * bc);\n\n\n\n\t\tpw.println(4*(abc/ab + abc/ac + abc/bc));\n\t\tpw.close();\n\t}\n\n\tstatic int i() throws IOException{\n\t\tst.nextToken();\n\t\treturn (int)st.nval;\n\t}\n\t\n\tstatic long l() throws IOException {\n\t\tst.nextToken();\n\t\treturn (long)st.nval;\n\t}\n\n\tstatic double d() throws IOException {\n\t\tst.nextToken();\n\t\treturn st.nval;\n\t}\n\tstatic String s() throws IOException{\n\t\tst.nextToken();\n\t\treturn st.sval;\n\t}\n}\n", "src_uid": "c0a3290be3b87f3a232ec19d4639fefc"} {"source_code": "import java.util.Scanner;\n\npublic class A {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n\n int n = sc.nextInt();\n int prev=0, cur=0, time=0;\n\n for(int i=0; i<n+1; i++) {\n if(i!=n) cur=sc.nextInt();\n else cur=90;\n if(cur-prev <= 15) {\n time+=cur-prev;\n }\n else {\n time+=15;\n break;\n }\n prev=cur;\n }\n\n\n System.out.println(time);\n }\n}\n", "src_uid": "5031b15e220f0ff6cc1dd3731ecdbf27"} {"source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n \npublic class M\n{\n static class Reader\n {\n final private int BUFFER_SIZE = 1 << 16;\n private DataInputStream din;\n private byte[] buffer;\n private int bufferPointer, bytesRead;\n \n public Reader()\n {\n din = new DataInputStream(System.in);\n buffer = new byte[BUFFER_SIZE];\n bufferPointer = bytesRead = 0;\n }\n \n public Reader(String file_name) throws IOException\n {\n din = new DataInputStream(new FileInputStream(file_name));\n buffer = new byte[BUFFER_SIZE];\n bufferPointer = bytesRead = 0;\n }\n \n public String readLine() throws IOException\n {\n byte[] buf = new byte[1024]; // 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\t\t\n\t\tpublic String next() throws IOException\n\t\t{\n\t\t\treturn readLine();\n\t\t}\n }\n\t\n\tstatic int root(int arr[] , int x)\n\t{\n\t\twhile(arr[x] != x)\n\t\t{\n\t\t\tarr[x] = arr[arr[x]];\n\t\t\tx = arr[x];\n\t\t}\n\t\treturn x;\n\t}\n\t\n\tstatic void union_find(int arr[] , int size[] , int x , int y)\n\t{\n\t\tint root_x = root(arr , x);\n\t\tint root_y = root(arr , y);\n\t\t\n\t\tif(root_x != root_y)\n\t\t{\n\t\t\tif(size[root_x] > size[root_y])\n\t\t\t{\n\t\t\t\tarr[root_y] = arr[root_x];\n\t\t\t\tsize[root_x] += size[root_y];\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tarr[root_x] = arr[root_y];\n\t\t\t\tsize[root_y] += size[root_x];\n\t\t\t}\n\t\t}\n\t}\n \n public static void main(String[] args) throws IOException\n {\n Scanner In = new Scanner(System.in);\n\t\t\n\t\tint a = In.nextInt();\n\t\tint b = In.nextInt();\n\t\tint c = In.nextInt();\n\t\t\t\t\n\t\tint ans = 0;\n\t\t\n\t\tif(b < a && c < a)\n\t\t\tSystem.out.println(\"-1\");\n\t\telse\n\t\t{\n\t\t\t/*int max = Math.max(b,c);\n\t\t\t\n\t\t\twhile(max >= a)\n\t\t\t{\n\t\t\t\tif(b == max)\n\t\t\t\t{\n\t\t\t\t\tb -= a;\n\t\t\t\t}\n\t\t\t\telse if(c == max)\n\t\t\t\t{\n\t\t\t\t\tc -= a;\n\t\t\t\t}\n\t\t\t\tmax = Math.max(b,c);\n\t\t\t\tans++;\n\t\t\t}*/\n\t\t\t\n\t\t\tif(b%a <= (c/a)*(a-1) && c%a <= (b/a)*(a-1))\n\t\t\t\tSystem.out.println(b/a + c/a);\n\t\t\telse\n\t\t\tSystem.out.println(\"-1\");\n\n\t\t}\n }\n}", "src_uid": "6e3b8193d1ca1a1d449dc7a4ad45b8f2"} {"source_code": "import java.io.*;\nimport java.util.*;\nimport java.util.function.Consumer;\n\npublic class Solution {\n\n\n static MyScanner sc;\n private static PrintWriter out;\n static long M2 = 1_000_000_000L + 7;\n\n public static void main(String[] s) throws Exception {\n StringBuilder stringBuilder = new StringBuilder();\n\n if (stringBuilder.length() == 0) {\n sc = new MyScanner(System.in);\n } else {\n sc = new MyScanner(new BufferedReader(new StringReader(stringBuilder.toString())));\n }\n\n out = new PrintWriter(new OutputStreamWriter(System.out));\n\n initData();\n solve();\n out.flush();\n }\n\n private static void initData() {\n\n }\n\n\n private static void solve() throws IOException {\n int[] zz = sc.na(24);\n\n int[][] mm1 = new int[][]{\n {5, 6, 17, 18, 21, 22, 13, 14},\n {2, 4, 6, 8, 10, 12, 23, 21},\n {3, 4, 17, 19, 10, 9, 16, 14}\n };\n\n for (int[] ll : mm1) {\n if (v(Arrays.copyOf(zz, 24), ll, 2) || v(Arrays.copyOf(zz, 24), ll, -2)) {\n out.println(\"yes\");\n return;\n }\n }\n\n\n out.println(\"no\");\n }\n\n private static boolean v(int[] ints, int[] ll, int k) {\n int[] rr = new int[8];\n for (int r = 0; r < 8; r++) {\n rr[r] = ints[ll[r] - 1];\n }\n for (int r = 0; r < 8; r++) {\n int ind = (r + k) % 8;\n if (ind < 0) ind += 8;\n ints[ll[ind] - 1] = rr[r];\n }\n\n return s(ints);\n }\n\n private static boolean s(int[] ints) {\n for (int r = 0; r < 6; r++) {\n if (Arrays.stream(Arrays.copyOfRange(ints, r * 4, r * 4 + 4)).distinct().count() != 1) {\n return false;\n }\n }\n return true;\n }\n\n private static boolean vv(int[] zz, int[] zz1, int[] zz2, int[] zz3) {\n return v1(zz, zz1, zz2, zz3) || v1(zz3, zz2, zz1, zz);\n }\n\n private static boolean v1(int[] zz, int[] zz1, int[] zz2, int[] zz3) {\n return false;\n }\n\n\n private static void xx(int[] zz, int[] zz1, int[] zz2, boolean[] res) {\n for (int t : zz)\n for (int k : zz1)\n for (int k1 : zz2) {\n res[t * 100 + k * 10 + k1] = true;\n }\n }\n\n private static void xx(int[] z1, int[] z2, boolean[] res) {\n for (int t1 : z1)\n for (int t2 : z2) {\n res[t1 * 10 + t2] = true;\n res[t2 * 10 + t1] = true;\n }\n }\n\n private static final class LogTreePar {\n\n private final int[] levels;\n private final int[][] parents;\n\n public LogTreePar(int n) {\n levels = new int[n];\n parents = new int[n][19];\n Arrays.fill(levels, -1);\n for (int[] x : parents) {\n Arrays.fill(x, -1);\n }\n }\n\n public boolean ispar(int f, int l) {\n if (levels[f] >= levels[l]) return false;\n int diff = levels[l] - levels[f];\n return up(l, diff) == f;\n }\n\n private int up(int item, int diff) {\n int r = 0;\n while (diff > 0 && item >= 0) {\n if (isset(diff, r)) {\n diff ^= 1 << r;\n item = parents[item][r];\n }\n r++;\n }\n return item;\n }\n\n\n public void add(int item, int parent) {\n parents[item][0] = parent;\n clt(item);\n }\n\n\n protected void clt(int item) {\n levels[item] = levels[parents[item][0]] + 1;\n for (int l = 1; l < 19; l++) {\n if (parents[item][l - 1] == -1) break;\n parents[item][l] = parents[parents[item][l - 1]][l - 1];\n }\n }\n\n public int lca(int f, int l) {\n if (levels[f] > levels[l]) {\n return lca(l, f);\n }\n return lca1(f, up(l, levels[l] - levels[f]));\n }\n\n private int lca1(int f1, int f2) {\n for (int r = 18; r >= 0 && f1 != f2; r--) {\n if (parents[f1][r] != parents[f2][r]) {\n f1 = parents[f1][r];\n f2 = parents[f2][r];\n }\n }\n return f1 == f2 ? f1 : parents[f1][0];\n }\n }\n\n\n private static class P {\n private boolean b;\n private final int ind;\n private final int parent;\n\n public P(int i, boolean b, int par) {\n this.ind = i;\n this.b = b;\n this.parent = par;\n\n }\n }\n\n private static void dfs(int start, int[][] neig, Consumer<int[]> onAdd, Consumer<int[]> onRemove) {\n ArrayList<P> toVisit = new ArrayList<P>(3000);\n toVisit.add(new P(start, true, -1));\n boolean[] vis = new boolean[neig.length];\n vis[start] = true;\n int[] level = new int[neig.length];\n while (toVisit.size() > 0) {\n P ppr = toVisit.remove(toVisit.size() - 1);\n if (!ppr.b) {\n onRemove.accept(new int[]{ppr.ind, level[ppr.ind], ppr.parent});\n continue;\n }\n ppr.b = false;\n int i = ppr.ind;\n toVisit.add(ppr);\n onAdd.accept(new int[]{ppr.ind, level[ppr.ind], ppr.parent});\n for (int kk : neig[i]) {\n if (!vis[kk]) {\n vis[kk] = true;\n level[kk] = level[i] + 1;\n toVisit.add(new P(kk, true, i));\n }\n }\n }\n\n\n }\n\n\n private static int[][] tr(int n) {\n int[][] x = new int[2][n - 1];\n for (int i = 0; i < n - 1; i++) {\n x[0][i] = sc.nextInt() - 1;\n x[1][i] = sc.nextInt() - 1;\n }\n return pn(x, n);\n }\n\n private static int[][] pn(int[][] x, int n) {\n int[] ct = new int[n];\n int[][] res = new int[n][];\n for (int v : x[0]) {\n ct[v]++;\n }\n for (int v : x[1]) {\n ct[v]++;\n }\n for (int l = 0; l < n; l++) {\n res[l] = new int[ct[l]];\n }\n for (int i = 0; i < x[0].length; i++) {\n res[x[0][i]][--ct[x[0][i]]] = x[1][i];\n res[x[1][i]][--ct[x[1][i]]] = x[0][i];\n }\n return res;\n }\n\n\n private static boolean isset(long i, int k) {\n return (i & (1 << k)) > 0;\n }\n\n private static void solveT() throws IOException {\n int t = sc.nextInt();\n while (t-- > 0) {\n solve();\n }\n }\n\n\n private static long gcd(long l, long l1) {\n if (l > l1) return gcd(l1, l);\n if (l == 0) return l1;\n return gcd(l1 % l, l);\n }\n\n private static long pow(long a, long b, long m) {\n if (b == 0) return 1;\n if (b == 1) return a;\n long pp = pow(a, b / 2, m);\n pp *= pp;\n pp %= m;\n return (pp * (b % 2 == 0 ? 1 : a)) % m;\n }\n\n\n static class MyScanner {\n BufferedReader br;\n StringTokenizer st;\n\n MyScanner(BufferedReader br) {\n this.br = br;\n }\n\n public MyScanner(InputStream in) {\n this(new BufferedReader(new InputStreamReader(in)));\n }\n\n void findToken() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n }\n\n String next() {\n findToken();\n return st.nextToken();\n }\n\n Integer[] nab(int n) {\n Integer[] k = new Integer[n];\n for (int i = 0; i < n; i++) {\n k[i] = sc.fi();\n }\n return k;\n }\n\n int[] na(int n) {\n int[] k = new int[n];\n for (int i = 0; i < n; i++) {\n k[i] = sc.fi();\n }\n return k;\n }\n\n long[] nl(int n) {\n long[] k = new long[n];\n for (int i = 0; i < n; i++) {\n k[i] = sc.nextLong();\n }\n return k;\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n int fi() {\n String t = next();\n int cur = 0;\n boolean n = t.charAt(0) == '-';\n for (int a = n ? 1 : 0; a < t.length(); a++) {\n cur = cur * 10 + t.charAt(a) - '0';\n }\n return n ? -cur : cur;\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n\n\n}", "src_uid": "881a820aa8184d9553278a0002a3b7c4"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class tmp{\n\tBufferedReader reader;\n\tStringTokenizer tokenizer;\n\tPrintWriter writer;\n\t\n\tvoid run(){\n\t\ttry{\n\t\t\treader=new BufferedReader(new InputStreamReader(System.in));\n\t\t\ttokenizer=null;\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(Exception e){\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n\t\n\tString 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\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\tvoid solve() throws IOException{\n\t\tint n=nextInt(),m=nextInt(),k=nextInt();\n\t\tString lines[]=new String[n];\n\t\tint nR=0,nG=0;\n\t\tfor(int i=0;i<n;i++){\n\t\t\tlines[i]=nextToken();\n\t\t\tfor(char c:lines[i].toCharArray()){\n\t\t\t\tif(c=='R') ++nR;\n\t\t\t\tif(c=='G') ++nG;\n\t\t\t}\n\t\t}\n\t\tif(nG==0 || m==1){\n\t\t\tSystem.out.println(\"Second\");\n\t\t\treturn;\n\t\t}\n\t\tboolean cantDieR=false,cantDieG=false;\n\t\tint xor[]=new int[10];\n\t\tfor(String line:lines){\n\t\t\tboolean hasR=(0<=line.indexOf('R'));\n\t\t\tboolean hasG=(0<=line.indexOf('G'));\n\t\t\tif(!hasR && !hasG) continue;\n\t\t\tif(hasR && hasG){\n\t\t\t\tif(0<=line.indexOf(\"RG\") || 0<=line.indexOf(\"GR\")) continue;\n\t\t\t\tint a=line.indexOf('R');\n\t\t\t\tint b=line.indexOf('G');\n\t\t\t\tint num=Math.abs(a-b)-1;\n\t\t\t\tfor(int i=0;i<10;i++){\n\t\t\t\t\txor[i]=(xor[i]+num%2)%(k+1);\n\t\t\t\t\tnum/=2;\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif(hasR && !line.equals(\"RR\")) cantDieR=true;\n\t\t\tif(hasG && !line.equals(\"GG\")) cantDieG=true;\n\t\t}\n\t\tif(cantDieR && cantDieG){\n\t\t\tSystem.out.println(\"Draw\");\n\t\t\treturn;\n\t\t}\n\t\tif(cantDieG){\n\t\t\tSystem.out.println(\"First\");\n\t\t\treturn;\n\t\t}\n\t\tif(cantDieR){\n\t\t\tSystem.out.println(\"Second\");\n\t\t\treturn;\n\t\t}\n\t\tfor(int i:xor){\n\t\t\tif(i!=0){\n\t\t\t\tSystem.out.println(\"First\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(\"Second\");\n\t}\n\t\n\tpublic static void main(String args[]){\n\t\tnew tmp().run();\n\t}\n}", "src_uid": "69062f7c9b834e925ab23ebc2da96b52"} {"source_code": "import java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Scanner;\nimport java.util.Set;\nimport java.util.TreeSet;\n\npublic class Game {\n\t\n\tpublic static void main (String[] args) {\n\t\tScanner sc = new Scanner (System.in);\n\t\t int n = sc.nextInt();\n\n\t ArrayList<Integer>[] c = new ArrayList[3];\n\t for(int i = 0; i < 3; ++i) c[i] = new ArrayList<Integer>();\n\t for(int i = 0; i < n; ++i) c[sc.nextInt() - 1].add(i);\n\n\t Set<Integer>[] before = new Set[n];\n\t for(int i = 0; i < n; ++i) before[i] = new TreeSet<Integer>();\n\t for(int i = 0; i < n; ++i) {\n\t int k = sc.nextInt();\n\t for(int j = 0; j < k; ++j) before[i].add(sc.nextInt() - 1);\n\t }\n\n\t int ans = Integer.MAX_VALUE;\n\t for(int i = 0; i < 3; ++i) {\n\t int[] need = new int[n];\n\t boolean[] executed = new boolean[n];\n\t Arrays.fill(executed, false);\n\t for(int j = 0; j < n; ++j) need[j] = before[j].size();\n\n\t int cur = i, cnt = 0, localans = 0;\n\t while(cnt < 3) {\n\t int task = -1;\n\t for(int j = 0; j < c[cur].size(); ++j) {\n\t if(executed[c[cur].get(j)] || need[c[cur].get(j)] != 0) continue;\n\t task = c[cur].get(j);\n\t break;\n\t }\n\t if(task == -1) {\n\t ++cnt; ++localans;\n\t cur = cur == 2 ? 0 : cur + 1;\n\t continue;\n\t }\n\t cnt = 0; ++localans;\n\t executed[task] = true;\n\t for(int j = 0; j < n; ++j) if(before[j].contains(task)) --need[j];\n\t }\n\t ans = Math.min(ans, localans - 3);\n\t }\n\t System.out.println(ans);\n\t }\n\t}", "src_uid": "be42e213ff43e303e475d77a9560367f"} {"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.util.Collections;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\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 Task1108B solver = new Task1108B();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class Task1108B {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n ArrayList<Integer> list = new ArrayList<>();\n for (int i = 0; i < n; i++) {\n list.add(in.nextInt());\n }\n Collections.sort(list);\n int max = list.get(list.size() - 1);\n int x = max;\n ArrayList<Integer> ll = divisor(x);\n int j = 0;\n// out.println(list);\n// out.println(ll);\n for (int i = 0; i < list.size(); i++) {\n if (ll.contains(list.get(i))) {\n list.remove(i);\n i--;\n ll.remove(j);\n// j++;\n }\n }\n// out.println(ll);\n out.println(max + \" \" + list.get(list.size() - 1));\n }\n\n public ArrayList<Integer> divisor(int n) {\n ArrayList<Integer> list = new ArrayList<>();\n for (int i = 1; i <= n; i++) {\n if (n % i == 0) {\n list.add(i);\n }\n }\n Collections.sort(list);\n return list;\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", "src_uid": "868407df0a93085057d06367aecaf9be"} {"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<maxX; x++)\n\t\t\tfor (int y=0; y<maxY; y++) {\n\t\t\t\thBonuses[x][y]=new BonusAtSquare();\n\t\t\t\tvBonuses[x][y]=new BonusAtSquare();\n\t\t\t}\n\t\t\n\t\tfor (int i=0; i<nRobots; i++) {\n\t\t\tint x=fs.nextInt(), y=fs.nextInt(), d=fs.nextInt(), t=fs.nextInt();\n\t\t\tlong killCost=fs.nextInt();\n\t\t\tprocessTransformer(x, y, d, t, killCost);\n\t\t}\n\t\tlong startTime=System.currentTimeMillis();\n\t\tdp=new long[2][2][maxY+1][511];\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\tfor (int k=0; k<dp[i][j].length; k++)\n\t\t\t\t\tArrays.fill(dp[i][j][k], -1);\n\t\tfor (int xAt=maxX-1; xAt>=0; xAt--) {\n\t\t\tfor (int j=0; j<dp[0].length; j++)\n\t\t\t\tfor (int k=0; k<dp[0][j].length; k++)\n\t\t\t\t\tArrays.fill(dp[(xAt&1)][j][k], -1);\n\t\t\t\n\t\t\tfor (int yAt=maxY-1; yAt>=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)][goingH][y][timesGoingStraight]!=-1) return dp[(x&1)][goingH][y][timesGoingStraight];\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<maxY?go(x, y+1, timesGoingStraight+1, 1):Long.MAX_VALUE;\n\t\t\tlong goV=x+1<maxX?go(x+1, y, 1, 0):Long.MAX_VALUE;\n\t\t\tbest=min(goH, goV)+curCost;\n\t\t}\n\t\telse {\n\t\t\tlong goH=y+1<maxY?go(x, y+1, 1, 1):Long.MAX_VALUE;\n\t\t\tlong goV=x+1<maxX?go(x+1, y, timesGoingStraight+1, 0):Long.MAX_VALUE;\n\t\t\tbest=min(goH, goV)+curCost;\n\t\t}\n//\t\tSystem.out.println(x+\" \"+y+\" \"+timesGoingStraight+\" \"+goingH);\n\t\treturn dp[(x&1)][goingH][y][timesGoingStraight]=best;\n\t}\n\tstatic long min(long a, long b) { return a < b ? a : b;}\n\t\n\t//have to process these in increasing straight distance\n\tstatic class BonusAtSquare {\n\t\tPriorityQueue<Bonus> 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<Bonus> {\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<Integer> xMatters=new ArrayList<>();\n\t\tArrayList<Integer> 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<t) return false;\n\t\tif ((t-x-y)%4!=0) return false;\n\t\treturn true;\n\t}\n\t\n\tstatic class FastScanner {\n\t\tBufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st=new StringTokenizer(\"\");\n\t\tpublic String next() {\n\t\t\twhile (!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\t// TODO Auto-generated catch block\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\t\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t}\n\n}\n", "src_uid": "b11cb0c2bf23bf4b4e6f6af61af9c290"} {"source_code": "import java.io.PrintWriter;\nimport java.util.ArrayDeque;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.List;\nimport java.util.Queue;\nimport java.util.Scanner;\n\npublic class test{\n Scanner in;\n PrintWriter out;\n boolean[] v;\n List<Integer>[] vec = new ArrayList[23]; \n boolean vis[] = new boolean[23];\n int[] deg = new int[23];\n int tp;\n \n void solve()\n {\n int n = in.nextInt();\n int m = in.nextInt();\n \n for(int i=1;i<=n;i++)\n vec[i] = new ArrayList<Integer>();\n \n for(int i=1;i<=m;i++){\n int ta,tb;\n ta = in.nextInt();\n tb = in.nextInt();\n if(ta==tb)\n continue;\n if(vec[ta].contains(tb))\n continue;\n \n vec[ta].add(tb);\n vec[tb].add(ta);\n deg[ta]++;deg[tb]++;\n }\n \n for(int i=1;i<=n;i++){\n Collections.sort(vec[i], new Comparator<Integer>() {\n @Override\n public int compare(Integer x, Integer y) {\n if(deg[x]==deg[y])\n return x-y;\n return deg[x]-deg[y];\n }\n });\n }\n \n for (int i=1;i<=n;i++){\n Arrays.fill(vis, false);\n tp=0;\n dfs(i);\n if (tp==n){\n out.print(\"Yes\");\n return;\n }\n }\n out.print(\"No\");\n \n }\n \n void dfs(int cur){\n vis[cur]=true;\n tp++;\n int vsize=vec[cur].size();\n for (int i=0;i<vsize;i++){\n int u=vec[cur].get(i);\n if (!vis[u]) \n {dfs(u);return;}\n }\n }\n \n \n void run() throws Exception\n {\n in = new Scanner(System.in);\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 boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}", "src_uid": "d023fc9b58268a36d7fb80deb338b09a"} {"source_code": "//coderadi\nimport java.io.*;\nimport java.util.*;\npublic class A {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tchar[] ar = sc.next().toCharArray();\n\t\tint[] ar2 = new int[ar.length];\n\t\tint max = 0;\n\t\tfor(int i=0; i<ar.length; i++){\n\t\t\tar2[i] = ar[i] - '0';\n\t\t\tmax = Math.max(max, ar2[i]);\n\t\t}\n\n\t\tSystem.out.println(max);\n\t\tboolean flag = true;\n\t\twhile(flag == true){\n\t\t\tflag = false;\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\tfor(int i=0; i<ar2.length; i++){\n\t\t\t\tif(ar2[i] > 0){\n\t\t\t\t\tsb.append(\"1\");\n\t\t\t\t\tar2[i]--;\n\t\t\t\t\tflag = true;\n\t\t\t\t}\n\t\t\t\telse if(ar2[i] <= 0 && flag){\n\t\t\t\t\tsb.append(\"0\");\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(flag)\n\t\t\tSystem.out.print(sb + \" \");\n\t\t}\n\t\tSystem.out.println();\n\t}\n}", "src_uid": "033068c5e16d25f09039e29c88474275"} {"source_code": "import java.util.Scanner;\n\n\npublic class r {\npublic static void main(String[] args) {\n Scanner sc=new Scanner(System.in);;\n System.out.println(sc.nextInt()+sc.nextInt());\n\n\n\n\n\n\n\n\n\n\n\n\n}\n}", "src_uid": "b6e3f9c9b124ec3ec20eb8fcea075add"} {"source_code": "import java.util.*;\nimport java.math.*;\npublic class MyClass {\n \n \n public static void main(String args[]) {\n \n int n,k,i,j,t,m=0;\n double a;\n \n \n Scanner x=new Scanner(System.in);\n n=x.nextInt();\n if(n%2!=0)\n {\n System.out.println(0);\n \n }\n else\n {\n k=n/2;\n a=Math.pow(2,k);\n j=(int)a;\n \n System.out.println(j);\n }\n \n }\n}", "src_uid": "4b7ff467ed5907e32fd529fb39b708db"} {"source_code": "import java.util.Scanner;\n\n/**\n * Contest: Educational Codeforces Round 52\n *\n * @author Arturs Licis\n */\npublic class ProblemB {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\n\t\tlong n = sc.nextLong();\n\t\tlong m = sc.nextLong();\n\n\t\tif (n == 1) {\n\t\t\tSystem.out.println(\"1 1\");\n\t\t\treturn;\n\t\t}\n\n\t\tif (n == 2) {\n\t\t\tif (m == 0) System.out.println(\"2 2\");\n\t\t\telse if (m == 1) System.out.println(\"0 0\");\n\t\t\treturn;\n\t\t}\n\n\t\tif (m == 0) {\n\t\t\tSystem.out.println(n + \" \" + n);\n\t\t\treturn;\n\t\t}\n\n\t\t// calc min\n\t\tlong edgesForMin = n / 2l + n % 2l;\n\t\tlong min = (m >= edgesForMin) ? 0 : n - m * 2;\n\n\t\t// calc max\n\t\tlong nn = 2;\n\t\twhile ((nn * (nn - 1l)) / 2l < m) nn++;\n\t\tlong max = n - nn;\n\t\tSystem.out.println(min + \" \" + max);\n\n\t\tSystem.out.flush();\n\t}\n}", "src_uid": "daf0dd781bf403f7c1bb668925caa64d"} {"source_code": "\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.StringTokenizer;\n\npublic class Counterexample {\n\tstatic Scanner sc;\n\tstatic PrintWriter out;\n\tpublic static void main(String[] args) throws Exception{\n\t\tsc = new Scanner(System.in);\n\t\tout = new PrintWriter(System.out);\n\t\tlong l=sc.nextLong(),r=sc.nextLong();\n\t\tif(r-l < 2 || (r-l==2&&l%2==1))\n\t\t{\n\t\t\tout.println(-1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tint rem = (int)(l%2);\n\t\t\tout.println((l+rem)+\" \"+(l+1+rem)+\" \"+(l+2+rem));\n\t\t}\n\t\tout.flush();\n\t\tout.close();\n\t}\n\n\tstatic class Scanner{\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\t\tpublic Scanner(InputStream system) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(system));\n\t\t}\n\t\tpublic Scanner(FileReader file) {\n\t\t\tbr = new BufferedReader(file);\n\t\t}\n\t\tpublic String next() throws IOException {\n\t\t\twhile(st == null || !st.hasMoreTokens())\n\t\t\t{\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tpublic String nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\t\tpublic int nextInt()throws IOException{\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tpublic double nextDouble()throws IOException{\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\tpublic char nextChar()throws IOException{\n\t\t\treturn next().charAt(0);\n\t\t}\n\t\tpublic long nextLong()throws IOException{\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\tpublic boolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\t\tpublic void waitForInput() throws InterruptedException {\n\t\t\tThread.sleep(5000);\n\t\t}\n\t}\n}\n", "src_uid": "6c1ad1cc1fbecff69be37b1709a5236d"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class enc\n{\n public static void main(String[] args) throws IOException\n {\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n int n=Integer.parseInt(br.readLine());\n\t\t//System.out.println(\"\\n\");\n String s=br.readLine();\n int k=1;\n int i=0;\n String str=\"\";\n while(k<n+1)\n {\n String ss=\"\";\n if(i<s.length()){\n ss=Character.toString(s.charAt(i));}\n str+=ss;\n i+=k;\n k++;\n }\n\t\tString se=str.trim();\n System.out.println(se);\n }\n}", "src_uid": "08e8c0c37b223f6aae01d5609facdeaf"} {"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<pair> ar = new ArrayList<pair>();\n\t\tlong sx = xx;\n\t\tlong sy = yy;\n\t\tar.add(new pair(sx,sy));\n\t\t\n\t\twhile(sx<xt||sy<yt) {\n\t\t\tsx = a1*sx+b1;\n\t\t\tsy = a2*sy+b2;\n\t\t\tar.add(new pair(sx,sy));\n\t\t}\n\t\t\n\t\tlong ans1 = 0;\n\t\tlong ans2 = 0;\n\t\t\n// \t\tpair p1 = ar.get(ar.size()-1);\n// \t\t//System.out.println(p1.x+\" \"+p1.y);\n// \t\tans1 = solve(p1,xx,yy,t,a1,a2,b1,b2,xt,yt);\n//\t\tlong x = p1.x;\n//\t\tlong y = p1.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}\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}", "src_uid": "d8a7ae2959b3781a8a4566a2f75a4e28"} {"source_code": "\nimport java.util.Scanner;\npublic class Main {\n\tstatic int x1,y1,x2,y2,x3,y3;\n\tpublic static void main(String[] args) {\n\t\tScanner input=new Scanner(System.in);\n\t\tx1=input.nextInt();\n\t\ty1=input.nextInt();\n\t\tx2=input.nextInt();\n\t\ty2=input.nextInt();\n\t\tx3=input.nextInt();\n\t\ty3=input.nextInt();\n\t\tif(is_triangle(x1,y1,x2,y2,x3,y3)) {\n\t\t\tSystem.out.println(\"RIGHT\");\n\t\t}\n\t\telse if(is_triangle(x1-1,y1,x2,y2,x3,y3)||is_triangle(x1+1,y1,x2,y2,x3,y3)) {\n\t\t\tSystem.out.println(\"ALMOST\");\n\t\t}\n\t\telse if(is_triangle(x1,y1-1,x2,y2,x3,y3)||is_triangle(x1,y1+1,x2,y2,x3,y3)) {\n\t\t\tSystem.out.println(\"ALMOST\");\n\t\t}\n\t\telse if(is_triangle(x1,y1,x2-1,y2,x3,y3)||is_triangle(x1,y1,x2+1,y2,x3,y3)) {\n\t\t\tSystem.out.println(\"ALMOST\");\n\t\t}\n\t\telse if(is_triangle(x1,y1,x2,y2-1,x3,y3)||is_triangle(x1,y1,x2,y2+1,x3,y3)) {\n\t\t\tSystem.out.println(\"ALMOST\");\n\t\t}\n\t\telse if(is_triangle(x1,y1,x2,y2,x3-1,y3)||is_triangle(x1,y1,x2,y2,x3+1,y3)) {\n\t\t\tSystem.out.println(\"ALMOST\");\n\t\t}\n\t\telse if(is_triangle(x1,y1,x2,y2,x3,y3-1)||is_triangle(x1,y1,x2,y2,x3,y3+1)) {\n\t\t\tSystem.out.println(\"ALMOST\");\n\t\t}\n\t\telse {\n\t\t\tSystem.out.println(\"NEITHER\");\n\t\t}\n\t}\n\tpublic static boolean is_triangle(int x1,int y1,int x2,int y2,int x3,int y3) {\n\t\tint a=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);\n\t\tint b=(x1-x3)*(x1-x3)+(y1-y3)*(y1-y3);\n\t\tint c=(x2-x3)*(x2-x3)+(y2-y3)*(y2-y3);\n\t\tif(a==0||b==0||c==0) {\n\t\t\treturn false;\n\t\t}\n\t\telse if(a+b==c||a+c==b||b+c==a) {\n\t\t\treturn true;\n\t\t}\n\t\telse {\n\t\t\treturn false;\n\t\t}\n\t}\n} ", "src_uid": "8324fa542297c21bda1a4aed0bd45a2d"} {"source_code": "//package arbuz;\n\nimport java.util.Scanner;\n\npublic class Arbuz {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n double ax, ay, bx, by, cx, cy, k, offset = 0;\n ax = sc.nextInt();\n ay = sc.nextInt();\n bx = sc.nextInt();\n by = sc.nextInt();\n cx = sc.nextInt();\n cy = sc.nextInt();\n if (bx == ax) {\n k = Integer.MAX_VALUE;\n } else {\n k = (by - ay) / (bx - ax);\n offset = ay - k * ax;\n }\n if (k == Integer.MAX_VALUE) {\n if (ax == cx) {\n System.out.print(\"TOWARDS\");\n } else {\n if ((by > ay && cx > ax) || (by < ay && cx < ax)) {\n System.out.println(\"RIGHT\");\n } else {\n System.out.println(\"LEFT\");\n }\n }\n } else {\n if (Math.abs(cy - k * cx - offset) < 0.0005) {\n System.out.println(\"TOWARDS\");\n } else {\n if ((cy > k * cx + offset && ax > bx) || (cy < k * cx + offset && ax < bx)) {\n System.out.println(\"RIGHT\");\n } else {\n System.out.println(\"LEFT\");\n }\n }\n }\n }\n}\n", "src_uid": "f6e132d1969863e9f28c87e5a44c2b69"} {"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 MOD = 1_000_000_007;\n\n\tboolean test(int mask, int i) {\n\t\treturn ((mask >> i) & 1) == 1;\n\t}\n\n\tvoid solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint k = nextInt();\n\n\t\tint[] fact = new int[n + 1];\n\t\tfact[0] = 1;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tfact[i] = (int) ((long) fact[i - 1] * i % MOD);\n\t\t}\n\t\t\n\t\tint[] invFact = new int[n + 1];\n\t\tfor (int i = 0; i <= n; i++)\n\t\t\tinvFact[i] = pow(fact[i], MOD - 2);\n\n\t\tint[][] dp = new int[n + 1][4];\n\t\tdp[0][0] = 1;\n\n\t\tfor (int pos = 0; pos < n; pos++) {\n\t\t\tint[][] next = new int[n + 1][4];\n\t\t\tfor (int good = 0; good < n; good++) {\n\t\t\t\tfor (int mask = 0; mask < 4; mask++) {\n\t\t\t\t\tif (dp[good][mask] != 0) {\n\t\t\t\t\t\t// put pos - 1\n\t\t\t\t\t\tif (pos != 0 && !test(mask, 0)) {\n\t\t\t\t\t\t\tnext[good + 1][mask >> 1] += dp[good][mask];\n\t\t\t\t\t\t\tif (next[good + 1][mask >> 1] >= MOD)\n\t\t\t\t\t\t\t\tnext[good + 1][mask >> 1] -= MOD;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// put pos + 1\n\t\t\t\t\t\tif (pos != n - 1) {\n\t\t\t\t\t\t\tnext[good + 1][(mask >> 1) | 2] += dp[good][mask];\n\t\t\t\t\t\t\tif (next[good + 1][(mask >> 1) | 2] >= MOD)\n\t\t\t\t\t\t\t\tnext[good + 1][(mask >> 1) | 2] -= MOD;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// put nothing\n\t\t\t\t\t\tnext[good][mask >> 1] += dp[good][mask];\n\t\t\t\t\t\tif (next[good][mask >> 1] >= MOD)\n\t\t\t\t\t\t\tnext[good][mask >> 1] -= MOD;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tdp = next;\n\t\t}\n\n\t\tint[] val = new int[n + 1];\n\t\tfor (int i = 0; i <= n; i++) {\n\t\t\tfor (int j = 0; j < 4; j++) {\n\t\t\t\tval[i] += dp[i][j];\n\t\t\t\tif (val[i] >= MOD)\n\t\t\t\t\tval[i] -= MOD;\n\t\t\t}\n\t\t\tval[i] = (int) ((long) val[i] * fact[n - i] % MOD);\n\t\t}\n\t\t\n\t\t//System.err.println(Arrays.toString(val));\n\n\t\tfor (int i = n; i >= 0; i--)\n\t\t\tfor (int j = i + 1; j <= n; j++) {\n\n\t\t\t\tint coef = (int) ((long) fact[j] * invFact[i] % MOD\n\t\t\t\t\t\t* invFact[j - i] % MOD);\n\n\t\t\t\tval[i] -= (int) ((long) val[j] * coef % MOD);\n\t\t\t\tif (val[i] < 0)\n\t\t\t\t\tval[i] += MOD;\n\t\t\t}\n\t\t\n\t\tout.println(val[k]);\n\t}\n\n\tint pow(int a, int b) {\n\t\tint res = 1;\n\t\twhile (b != 0) {\n\t\t\tif ((b & 1) == 1)\n\t\t\t\tres = (int)((long)res * a % MOD);\n\t\t\ta = (int)((long)a * a % MOD);\n\t\t\tb >>= 1;\n\t\t}\n\t\treturn res;\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}", "src_uid": "1243e98fe2ebd6e6d1de851984b96079"} {"source_code": "import java.util.ArrayList;\nimport java.util.List;\nimport java.util.Scanner;\n\n/**\n * Created by Hossein.A on 7/17/2017.\n */\npublic class codeforces1 {\n public static void main(String[] args) {\n ArrayList list = new ArrayList<>();\n Scanner input = new Scanner(System.in);\n int num = input.nextInt();\n for (int i = 0; i < num; i++) {\n list.add(input.nextInt());\n }\n int c1 = 0 , c2 = 0, c3 = 0;\n for (int i = 0; i < list.size()-1; i++) {\n if (Integer.valueOf((Integer) list.get(i)) < Integer.valueOf((Integer) list.get(i+1))){\n c1 = 1;\n if (c2 == 1 || c3 == 1){\n System.out.println(\"No\");\n return;\n }\n }\n else if (Integer.valueOf((Integer) list.get(i)) > Integer.valueOf((Integer) list.get(i+1))){\n c2 = 1;\n }\n else {\n c3 = 1;\n if (c2 == 1){\n System.out.println(\"No\");\n return;\n }\n }\n }\n System.out.println(\"Yes\");\n }\n}\n", "src_uid": "5482ed8ad02ac32d28c3888299bf3658"} {"source_code": "import java.io.*;\npublic class Solution {\n\n\tpublic static void main(String[] args)throws IOException {\n\t\tInputStreamReader read=new InputStreamReader(System.in);\n\t\tBufferedReader in=new BufferedReader(read);\n\t\tString str=in.readLine();\n\t\tString line[]=str.trim().split(\" \");\n\t\tint w=Integer.parseInt(line[0]);\n\t\tint h=Integer.parseInt(line[1]);\n\t\tint check=w+h;\n\t\tint ans=(int)pow(2,check,998244353);\n\t\tSystem.out.println(ans);\n\n\t}\nstatic long pow(long a,int b,int p)\n{\n\tlong res=1;\n\ta=a%p;\n\twhile(b>0)\n\t{\n\t\tif((b&1)==1)\n\t\t{\n\t\t\tres=(res*a)%p;\n\t\t}\n\t\tb=b>>1;\n\t\ta=((a%p)*(a%p))%p;\n\t}\n\treturn res;\n}\n}\n", "src_uid": "8b2a9ae21740c89079a6011a30cd6aee"} {"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.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\npublic class A implements Runnable {\n\tstatic String Y = \"YES\", N = \"NO\";\n\tstatic long inf = (long) 1e18;\n\n\tpublic static void main(String[] args) {\n\t\tnew Thread(null, new A(), \"Solver\", 1L << 26).start();\n\t}\n\n\tprivate FastScanner scan;\n\tprivate PrintWriter out;\n\n\tpublic A() {\n\t\tscan = new FastScanner(System.in);\n\t\tout = new PrintWriter(System.out);\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tsolve();\n\t\t\tout.close();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.out.println(1 / 0);\n\t\t}\n\t}\n\n\tstatic long ceilDiv(long n, long d) {\n\t\tif (n < 0 != d < 0) {\n\t\t\treturn (n / d) - (n % d == 0 ? 0 : 1);\n\t\t}\n\t\treturn (n / d) + (n % d == 0 ? 0 : 1);\n\t}\n\n\tvoid solve() throws IOException {\n\t\tint n = scan.nextInt();\n\t\tString str = scan.next();\n\t\tint sumLeft = 0;\n\t\tint sumRight = 0;\n\t\tboolean bad = false;\n\t\tfor(int i=0;i<str.length();i++) {\n\t\t\tif(str.charAt(i) != '4' && str.charAt(i) != '7')\n\t\t\t\tbad = true;\n\t\t\tif(i < str.length()/2) {\n\t\t\t\tsumLeft+=str.charAt(i)-'0';\n\t\t\t} else {\n\t\t\t\tsumRight += str.charAt(i)-'0';\n\t\t\t}\n\t\t}\n\t\tbad |= sumLeft != sumRight;\n\t\tif(bad) {\n\t\t\tout.println(\"NO\");\n\t\t} else {\n\t\t\tout.println(\"YES\");\n\t\t}\n\t\t\n\t}\n\tvoid print(int[] arr) {\n\t\tfor(int i=0;i<arr.length;i++) {\n\t\t\tout.print(arr[i]);\n\t\t\tif(i == arr.length-1) out.println();\n\t\t\telse out.print(\" \");\n\t\t}\n\t\n\t}\n\n\tstatic class Pair implements Comparable<Pair> {\n\t\tlong a, b;\n\n\t\tpublic Pair(long a, long b) {\n\t\t\tthis.a = a;\n\t\t\tthis.b = b;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Pair o) {\n\t\t\tif (a == o.a)\n\t\t\t\treturn Long.compare(b, o.b);\n\t\t\treturn Long.compare(a, o.a);\n\t\t}\n\t}\n\n\tstatic long max(long... ls) {\n\t\tlong max = ls[0];\n\t\tfor (long l : ls) {\n\t\t\tif (l > max)\n\t\t\t\tmax = l;\n\t\t}\n\t\treturn max;\n\t}\n\n\tstatic int max(int... ls) {\n\t\tint max = ls[0];\n\t\tfor (int l : ls) {\n\t\t\tif (l > max)\n\t\t\t\tmax = l;\n\t\t}\n\t\treturn max;\n\t}\n\n\tstatic double max(double... ls) {\n\t\tdouble max = ls[0];\n\t\tfor (double l : ls) {\n\t\t\tif (l > max)\n\t\t\t\tmax = l;\n\t\t}\n\t\treturn max;\n\t}\n\n\tstatic long min(long... ls) {\n\t\tlong min = ls[0];\n\t\tfor (long l : ls) {\n\t\t\tif (l < min)\n\t\t\t\tmin = l;\n\t\t}\n\t\treturn min;\n\t}\n\n\tstatic double min(double... ls) {\n\t\tdouble min = ls[0];\n\t\tfor (double l : ls) {\n\t\t\tif (l < min)\n\t\t\t\tmin = l;\n\t\t}\n\t\treturn min;\n\t}\n\n\tstatic int min(int... ls) {\n\t\tint min = ls[0];\n\t\tfor (int l : ls) {\n\t\t\tif (l < min)\n\t\t\t\tmin = l;\n\t\t}\n\t\treturn min;\n\t}\n\n\tstatic void yes(boolean a) {\n\t\tSystem.out.println(a ? Y : N);\n\t}\n\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\tstatic class FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner(InputStream in) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(in));\n\t\t\tst = new StringTokenizer(\"\");\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\twhile (!st.hasMoreTokens()) {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t}\n\n\tclass BPM {\n\t\tprivate Dinics d;\n\t\tprivate int leftCount;\n\t\tprivate int rightCount;\n\n\t\tpublic BPM(int leftCount, int rightCount) {\n\t\t\tthis.leftCount = leftCount;\n\t\t\tthis.rightCount = rightCount;\n\t\t\tthis.d = new Dinics(leftCount + rightCount + 2, 0, leftCount + rightCount + 1);\n\t\t\tfor (int i = 1; i <= leftCount; i++) {\n\t\t\t\td.addEdge(d.s, i, 1);\n\t\t\t}\n\t\t\tfor (int i = leftCount + 1; i <= leftCount + rightCount; i++) {\n\t\t\t\td.addEdge(i, d.t, 1);\n\t\t\t}\n\t\t}\n\n\t\tpublic void addMatching(int left, int right) {\n\t\t\td.addEdge(1 + left, 1 + leftCount + right, 1);\n\t\t}\n\t\t\n\t\tpublic int[] getMatchings() {\n\t\t\tthis.d.calculateFlow();\n\t\t\tint[] answer = new int[leftCount];\n\t\t\tArrays.fill(answer, -1);\n\t\t\tfor (edge e : this.d.e) {\n\t\t\t\tif (e.a == d.s || e.b == d.t)\n\t\t\t\t\tcontinue;\n\t\t\t\tif (e.flow != 1)\n\t\t\t\t\tcontinue;\n\t\t\t\tanswer[e.a - 1] = e.b - (leftCount + 1);\n\t\t\t}\n\t\t\treturn answer;\n\t\t}\n\t}\n\n\tclass Dinics {\n\t\tpublic static final int INF = 1000000000;\n\n\t\tpublic Dinics(int n, int s, int t) {\n\t\t\tthis.n = n;\n\t\t\tthis.g = new ArrayList[n];\n\t\t\tthis.s = s;\n\t\t\tthis.t = t;\n\t\t\tthis.q = new int[n];\n\t\t\tthis.d = new int[n];\n\t\t\tthis.ptr = new int[n];\n\t\t\tthis.intd = new int[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tg[i] = new ArrayList<Integer>();\n\t\t}\n\n\t\tint n, s, t;\n\t\tint[] intd;\n\t\tint[] ptr;\n\t\tint[] d;\n\t\tint[] q;\n\t\tArrayList<edge> e = new ArrayList<edge>();\n\t\tArrayList<Integer>[] g;\n\n\t\tvoid addEdge(int a, int b, int cap) {\n\t\t\tedge e1 = new edge(a, b, cap, 0);\n\t\t\tedge e2 = new edge(b, a, 0, 0);\n\t\t\tg[a].add((int) e.size());\n\t\t\te.add(e1);\n\t\t\tg[b].add((int) e.size());\n\t\t\te.add(e2);\n\t\t}\n\n\t\tboolean bfs() {\n\t\t\tint qh = 0, qt = 0;\n\t\t\tq[qt++] = s;\n\t\t\tArrays.fill(d, -1);\n\t\t\td[s] = 0;\n\t\t\twhile (qh < qt && d[t] == -1) {\n\t\t\t\tint v = q[qh++];\n\t\t\t\tfor (int i = 0; i < g[v].size(); ++i) {\n\t\t\t\t\tint id = g[v].get(i), to = e.get(id).b;\n\t\t\t\t\tif (d[to] == -1 && e.get(id).flow < e.get(id).cap) {\n\t\t\t\t\t\tq[qt++] = to;\n\t\t\t\t\t\td[to] = d[v] + 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn d[t] != -1;\n\t\t}\n\n\t\tint dfs(int v, int flow) {\n\t\t\tif (flow == 0)\n\t\t\t\treturn 0;\n\t\t\tif (v == t)\n\t\t\t\treturn flow;\n\t\t\tfor (; ptr[v] < (int) g[v].size(); ++ptr[v]) {\n\t\t\t\tint id = g[v].get(ptr[v]), to = e.get(id).b;\n\t\t\t\tif (d[to] != d[v] + 1)\n\t\t\t\t\tcontinue;\n\t\t\t\tint pushed = dfs(to, Math.min(flow, e.get(id).cap - e.get(id).flow));\n\t\t\t\tif (pushed != 0) {\n\t\t\t\t\te.get(id).flow += pushed;\n\t\t\t\t\te.get(id ^ 1).flow -= pushed;\n\t\t\t\t\treturn pushed;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn 0;\n\t\t}\n\n\t\tpublic int calculateFlow() {\n\t\t\tint flow = 0;\n\t\t\tfor (;;) {\n\t\t\t\tif (!bfs())\n\t\t\t\t\tbreak;\n\t\t\t\tArrays.fill(ptr, 0);\n\t\t\t\tint pushed;\n\t\t\t\twhile ((pushed = dfs(s, INF)) != 0)\n\t\t\t\t\tflow += pushed;\n\t\t\t}\n\t\t\treturn flow;\n\t\t}\n\n\t}\n\tstatic class edge {\n\t\tint a, b, cap, flow;\n\n\t\tpublic edge(int a, int b, int cap, int flow) {\n\t\t\tthis.a = a;\n\t\t\tthis.b = b;\n\t\t\tthis.cap = cap;\n\t\t\tthis.flow = flow;\n\t\t}\n\t}\n}", "src_uid": "435b6d48f99d90caab828049a2c9e2a7"} {"source_code": "import static java.lang.Double.parseDouble;\nimport static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.System.exit;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class A {\n\t\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n\t\n\tstatic void solve() throws Exception {\n\t\tlong sum = nextLong();\n\t\tlong xor = nextLong();\n\t\tif (sum < xor || ((sum ^ xor) & 1) != 0 || (((sum - xor) >> 1) & xor) != 0) {\n\t\t\tout.print(0);\n\t\t\treturn;\n\t\t}\n\t\tlong ans = 1L << Long.bitCount(xor);\n\t\tif (sum == xor) {\n\t\t\tans -= 2;\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}", "src_uid": "18410980789b14c128dd6adfa501aea5"} {"source_code": "//package goodbye2016;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class F3 {\n\tScanner in;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tint[][] g = new int[128][];\n\tint access = 0;\n\t\n\tint[] get(int x)\n\t{\n\t\tif(g[x] != null)return g[x];\n\t\tif(++access == 17){\n\t\t\tout.println(\"! \" + (x+1));\n\t\t\tout.flush();\n\t\t\tthrow new RuntimeException();\n\t\t}\n\t\tout.println(\"? \" + (x+1));\n\t\tout.flush();\n\t\tint n = ni();\n\t\tint[] ret = new int[n];\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tret[i] = ni()-1;\n\t\t}\n\t\tif(ret.length == 2){\n\t\t\tout.println(\"! \" + (x+1));\n\t\t\tout.flush();\n\t\t\tthrow new RuntimeException();\n\t\t}\n\t\treturn g[x] = ret;\n\t}\n\t\n\tint[] fall(int cur, int pre, int lim)\n\t{\n\t\tint step = 0;\n\t\twhile(true){\n\t\t\tint[] ne = get(cur);\n\t\t\tstep++;\n\t\t\tif(ne.length == 1)return new int[]{-1, step};\n\t\t\tif(--lim <= 0)return new int[]{-2, step};\n\t\t\tfor(int x : ne){\n\t\t\t\tif(x != pre){\n\t\t\t\t\tpre = cur;\n\t\t\t\t\tcur = x;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n\tvoid solve()\n\t{\n\t\tfor(int T = ni();T > 0;T--){\n\t\t\tg = new int[128][];\n\t\t\taccess = 0;\n\t\t\t\n\t\t\ttry{\n\t\t\t\tint h = ni();\n\t\t\t\tint[] f = get(0);\n\t\t\t\tint pre = -1, cur = -1, d = 0;\n\t\t\t\tif(f.length == 1){\n\t\t\t\t\tpre = 0;\n\t\t\t\t\tcur = f[0];\n\t\t\t\t\td = 1;\n\t\t\t\t}else{\n\t\t\t\t\tint[] s0 = fall(f[0], 0, 99);\n\t\t\t\t\tint[] s1 = fall(f[1], 0, 99);\n\t\t\t\t\td = Math.min(s0[1], s1[1]);\n\t\t\t\t\tpre = 0;\n\t\t\t\t\tif(s0[1] == d && s1[1] == d){\n\t\t\t\t\t\tcur = f[2];\n\t\t\t\t\t}else if(s0[1] == d){\n\t\t\t\t\t\tcur = f[1];\n\t\t\t\t\t}else{\n\t\t\t\t\t\tcur = f[0];\n\t\t\t\t\t}\n\t\t\t\t\td++;\n//\t\t\t\t\ttr(cur, f, s0, s1);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tint ste = 0;\n\t\t\t\twhile(true){\n//\t\t\t\t\ttr(\"cur\", cur);\n\t\t\t\t\tif(++ste == 20)throw new RuntimeException();\n\t\t\t\t\tint[] ne = get(cur);\n\t\t\t\t\tboolean ok = false;\n\t\t\t\t\tif(d < (h+1)/2){\n\t\t\t\t\t\tfor(int x : ne){\n\t\t\t\t\t\t\tif(x != pre){\n\t\t\t\t\t\t\t\tif(ok){\n\t\t\t\t\t\t\t\t\tpre = cur;\n\t\t\t\t\t\t\t\t\tcur = x;\n\t\t\t\t\t\t\t\t\td++;\n//\t\t\t\t\t\t\t\t\ttr(\"endd\", cur, x);\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\t\t\tint[] res = fall(x, cur, d);\n//\t\t\t\t\t\t\t\t\ttr(res, cur, x);\n\t\t\t\t\t\t\t\t\tif(res[0] == -1){\n\t\t\t\t\t\t\t\t\t\tok = true;\n\t\t\t\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\t\t\t\tpre = cur;\n\t\t\t\t\t\t\t\t\t\tcur = x;\n\t\t\t\t\t\t\t\t\t\td++;\n//\t\t\t\t\t\t\t\t\t\ttr(\"end\", res, cur, x);\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}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}else{\n\t\t\t\t\t\t// BFS\n\t\t\t\t\t\tint[] q = new int[128];\n\t\t\t\t\t\tint p = 0;\n\t\t\t\t\t\tq[p++] = cur;\n\t\t\t\t\t\tint[] ds = new int[128];\n\t\t\t\t\t\tArrays.fill(ds, 99999);\n\t\t\t\t\t\tds[cur] = d;\n\t\t\t\t\t\tfor(int r = 0;r < p;r++){\n\t\t\t\t\t\t\tint[] nex = get(q[r]);\n\t\t\t\t\t\t\tif(ds[q[r]] <= h-1){\n\t\t\t\t\t\t\t\tfor(int e : nex){\n\t\t\t\t\t\t\t\t\tif(e == pre)continue;\n\t\t\t\t\t\t\t\t\tif(ds[e] > ds[q[r]] + 1){\n\t\t\t\t\t\t\t\t\t\tds[e] = ds[q[r]] + 1;\n\t\t\t\t\t\t\t\t\t\tq[p++] = e;\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}catch(Exception e){\n//\t\t\t\te.printStackTrace();\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 F3().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 = true;//System.getProperty(\"ONLINE_JUDGE\") != null;\n\tvoid tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n//\tvoid tr(Object... o) { System.out.println(Arrays.deepToString(o)); }\n}\n", "src_uid": "5c0db518fa326b1e405479313216426a"} {"source_code": "import java.util.Scanner;\n\npublic class LinkAndPearls {\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner scn = new Scanner(System.in);\n\t\tString s = scn.nextLine();\n\t\t\n\t\t/*int pearl = 0;\n\t\tint link = 0;\n\t\tfor(int i=0;i<s.length();i++){\n\t\t\tif(s.charAt(i)=='o') pearl++;\n\t\t\telse link++;\n\t\t}*/\n\t\t\n\t\tlong pearl = s.chars().filter(ch -> ch=='o').count();\n\t\tlong link = s.chars().filter(ch -> ch=='-').count();\n\t\tSystem.out.println(pearl==0||link%pearl==0?\"YES\":\"NO\");\t\n\t\tscn.close();\n\t}\n\n}", "src_uid": "6e006ae3df3bcd24755358a5f584ec03"} {"source_code": "import java.util.*;\nimport java.io.*;\npublic class a {\npublic static void main(String[] args) throws IOException\n{\n PrintWriter out = new PrintWriter(System.out);\n input.init(System.in);\n \n int n = input.nextInt();\n int height = n;\n int res = 0;\n for(int i = 1; i<=n; i++)\n {\n int y = (int)Math.sqrt((long)n*n - (long)i*i);\n if(y == height) res++;\n else res += (height - y);\n height = y;\n }\n if(n == 0) out.println(1);\n else out.println(4*res);\n \n out.close();\n}\npublic static class input {\n static BufferedReader reader;\n static StringTokenizer tokenizer;\n\n /** call this method to initialize reader for InputStream */\n static void init(InputStream input) {\n reader = new BufferedReader(\n new InputStreamReader(input) );\n tokenizer = new StringTokenizer(\"\");\n }\n\n /** get next word */\n static String next() throws IOException {\n while ( ! tokenizer.hasMoreTokens() ) {\n //TODO add check for eof if necessary\n tokenizer = new StringTokenizer(\n reader.readLine() );\n }\n return tokenizer.nextToken();\n }\n\n static int nextInt() throws IOException {\n return Integer.parseInt( next() );\n }\n \n static double nextDouble() throws IOException {\n return Double.parseDouble( next() );\n }\n static long nextLong() throws IOException {\n return Long.parseLong( next() );\n }\n}\n}\n", "src_uid": "d87ce09acb8401e910ca6ef3529566f4"} {"source_code": "\nimport java.util.ArrayList;\nimport java.util.Scanner;\n\npublic class Main {\n private static Scanner scanner = new Scanner(System.in);\n private static int OO = (int) 1e5 + 9;\n private static int[] dx = {0, 0, 1, -1};\n private static int[] dy = {1, -1, 0, 0};\n\n public static void main(String[] args) {\n int n = scanner.nextInt(), ones = 0;\n int[] arr = new int[n];\n ArrayList<Integer> list = new ArrayList<>();\n for (int i = 0; i < n; i++) {\n arr[i] = scanner.nextInt();\n if (arr[i] == 1) {\n ones += 1;\n list.add(i);\n }\n }\n if (ones == 0) {\n System.out.println(0);\n } else if (ones == 1) {\n System.out.println(1);\n } else {\n long r = 1;\n for (int i = 0; i < list.size() - 1; i++) {\n r *= list.get(i + 1) - list.get(i);\n }\n System.out.println(r);\n }\n }\n}\n", "src_uid": "58242665476f1c4fa723848ff0ecda98"} {"source_code": "\nimport java.util.*;\npublic class Again{\n public static void main(String args[]){\n Scanner scn = new Scanner(System.in);\n int n = scn.nextInt(16);\n System.out.println(n%2);\n }\n}\n\n", "src_uid": "e52bc741bb72bb8e79cf392b2d15354f"} {"source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\n/*\n8 6\n\n46\n */\npublic class b\n{\n\tpublic static void main(String[] arg) throws Exception\n\t{\n\t\tnew b();\n\t}\n\t\n\tpublic b() throws Exception\n\t{\n\t\tFastScanner in = new FastScanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tString s = in.next();\n\t\tString ans = null;\n\t\tint best = 0;\n\t\tfor(int i = 0; i < s.length(); i++)\n\t\t{\n\t\t\tfor(int j = i; j < s.length(); j++)\n\t\t\t{\n\t\t\t\tString sub = s.substring(i, j+1);\n\t\t\t\tif(valid(sub))\n\t\t\t\t{\n\t\t\t\t\tint cnt = 0;\n\t\t\t\t\tfor(int k = 0; k < s.length(); k++)\n\t\t\t\t\t{\n\t\t\t\t\t\tif(k+sub.length() <= s.length())\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tString comp = s.substring(k, k+sub.length());\n\t\t\t\t\t\t\tif(sub.equals(comp)) cnt++;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif(cnt > best)\n\t\t\t\t\t{\n\t\t\t\t\t\tbest = cnt;\n\t\t\t\t\t\tans = sub;\n\t\t\t\t\t}\n\t\t\t\t\telse if(cnt == best)\n\t\t\t\t\t{\n\t\t\t\t\t\tif(sub.compareTo(ans) < 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tans = sub;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(best==0?\"-1\":ans);\n\t\tin.close(); out.close();\n\t}\n\tboolean valid(String s)\n\t{\n\t\tfor(int i = 0; i < s.length(); i++)\n\t\t{\n\t\t\tif(!(s.charAt(i) == '4' || s.charAt(i) == '7')) return false;\n\t\t}\n\t\treturn true;\n\t}\n\tclass FastScanner\n\t{\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tpublic FastScanner(InputStream in)\n\t\t{\n\t\t\tbr = new BufferedReader(new InputStreamReader(in));\n\t\t\tst = new StringTokenizer(\"\");\n\t\t}\n\t\tpublic String next() throws IOException\n\t\t{\n\t\t\twhile(!st.hasMoreTokens()) st = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\t\tpublic int nextInt() throws IOException\n\t\t{\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tpublic void close() throws IOException\n\t\t{\n\t\t\tbr.close();\n\t\t}\n\t\tpublic long nextLong() throws IOException\n\t\t{\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\tpublic double nextDouble() throws IOException\n\t\t{\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t}\n}", "src_uid": "639b8b8d0dc42df46b139f0aeb3a7a0a"} {"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.Collections;\nimport java.util.HashSet;\nimport java.util.Stack;\n\npublic class Main {\n \n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n String line = br.readLine();\n String[] values = line.split(\" \");\n int cnt1 = Integer.parseInt(values[0]);\n int cnt2 = Integer.parseInt(values[1]);\n int x = Integer.parseInt(values[2]);\n int y = Integer.parseInt(values[3]);\n long l = 1; long r = Long.MAX_VALUE;\n while (r>l) {\n long mid = (r+l) >> 1;\n long f1 = mid/x; long f2 = mid/y; long both = mid/(x*y);\n if (mid-(f1+f2)+both >= Math.max(cnt1-f2+both, 0) + Math.max(cnt2-f1 + both, 0)) r = mid;\n else l = mid+1;\n }\n System.out.println(l);\n }\n}\n\n", "src_uid": "ff3c39b759a049580a6e96c66c904fdc"} {"source_code": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n static int n, f[];\n static String s;\n static long ans, dp[][][];\n\n private static void build() {\n // build failure function F[i] = index of largest prefix/suffix with end < i = where to look if i doesn't match\n f[0] = -1;\n f[1] = 0;\n for(int i = 2; i <= s.length(); i++) {\n f[i] = f[i-1];\n while(f[i] != -1 && s.charAt(i-1) != s.charAt(f[i])) f[i] = f[f[i]];\n ++f[i]; // ++ because this is on the scale of i-2 and not i-1\n }\n }\n\n private static int getNext(int state, char val) {\n if(state == s.length()) return getNext(f[state], val);\n int nxt = state;\n while(nxt != -1 && s.charAt(nxt) != val) nxt = f[nxt];\n return nxt + 1;\n }\n\n private static long calc(int n, int curr, int start, int done) {\n if(curr == s.length()) done = 1;\n if(n == 0) return (curr == start && done == 1 ? 1 : 0);\n\n if(dp[n][curr][done] != -1) return dp[n][curr][done];\n dp[n][curr][done] = 0;\n int nxt0 = getNext(curr, '0');\n int nxt1 = getNext(curr, '1');\n dp[n][curr][done] += calc(n-1, nxt0, start, done);\n dp[n][curr][done] += calc(n-1, nxt1, start, done);\n return dp[n][curr][done];\n }\n\n private static long solve(int starting_state) {\n dp = new long[n + 1][s.length() + 1][2];\n for(long[][] r1: dp) {\n for (long[] r2 : r1)\n Arrays.fill(r2, -1);\n }\n return calc(n, starting_state, starting_state, 0);\n }\n\n public static void main(String[] args) {\n InputReader cin = new InputReader(System.in);\n n = cin.nextInt();\n s = cin.next();\n f = new int[s.length() + 1];\n ans = 0;\n\n build();\n for(int starting_state = 0; starting_state <= s.length(); starting_state++) {\n ans += solve(starting_state);\n }\n\n System.out.println(ans);\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", "src_uid": "0034806908c9794086736a2d07fc654c"} {"source_code": "\nimport java.io.*;\nimport java.util.*;\n\npublic class D {\n\n private void solution() throws IOException {\n int n = in.nextInt();\n int a = in.nextInt() - 1, b = in.nextInt() - 1;\n int[] g = new int[n - 1];\n for (int i = 0; i < n - 1; i++) {\n g[i] = in.nextInt();\n }\n int[] k = new int[n];\n for (int i = 0; i < n; i++) {\n k[i] = in.nextInt();\n }\n\n Map<Integer, Integer> mapL = new HashMap<>();\n Map<Integer, Integer> mapR = new HashMap<>();\n mapL.put(k[a], a);\n mapR.put(k[a], a);\n\n long[] s = new long[n];\n\n int l = a, r = a;\n int maxL = a, maxR = a;\n\n boolean move = true;\n while (move) {\n if (l == b) {\n out.println(s[l]);\n return;\n }\n if (r == b) {\n out.println(s[r]);\n return;\n }\n move = false;\n if (l - 1 >= 0) {\n if (mapL.containsKey(g[l - 1])) {\n l--;\n move = true;\n s[l] = s[l + 1] + 1;\n if (!mapL.containsKey(k[l])) {\n mapL.put(k[l], l);\n }\n } else if (mapR.containsKey(g[l - 1])) {\n l--;\n move = true;\n int p = mapR.get(g[l]);\n if (p > maxR) {\n maxR = p;\n }\n s[l] = s[maxR] + Math.abs(maxR - l);\n if (!mapL.containsKey(k[l])) {\n mapL.put(k[l], l);\n }\n }\n }\n if (r + 1 < n) {\n if (mapR.containsKey(g[r])) {\n r++;\n move = true;\n s[r] = s[r - 1] + 1;\n if (!mapR.containsKey(k[r])) {\n mapR.put(k[r], r);\n }\n } else if (mapL.containsKey(g[r])) {\n r++;\n move = true;\n int p = mapL.get(g[r - 1]);\n if (p < maxL) {\n maxL = p;\n }\n s[r] = s[maxL] + Math.abs(maxL - r);\n if (!mapR.containsKey(k[r])) {\n mapR.put(k[r], r);\n }\n }\n }\n }\n out.println(-1);\n }\n\n private void run() throws IOException {\n in = new Scanner(System.in);\n out = new PrintWriter(System.out);\n solution();\n in.close();\n out.close();\n }\n\n private Scanner in;\n private PrintWriter out;\n\n public static void main(String[] args) throws IOException {\n new D().run();\n }\n\n private class Scanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n private Scanner(InputStream is) {\n br = new BufferedReader(new InputStreamReader(is));\n }\n\n private String next() throws IOException {\n while (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(br.readLine());\n }\n return st.nextToken();\n }\n\n private Integer nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n private Long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n private Double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n private void close() throws IOException {\n st = null;\n br.close();\n }\n }\n}\n", "src_uid": "fbd994944cfa06e4921aac227d9eaf31"} {"source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main {\n static Scanner scanner = new Scanner(System.in);\n\n public static void main(String[] args) {\n int n=scanner.nextInt();\n int m=scanner.nextInt();\n m--;\n int max=scanner.nextInt();\n int a[]=new int[n];\n for (int i=0;i<n;i++){\n a[i]=scanner.nextInt();\n }\n int minR=-1;\n int minL=-1;\n for (int i=m;i<n;i++){\n if (a[i]!=0 && a[i]<=max){\n minR=i;\n break;\n }\n }\n for (int i=m;i>=0;i--){\n if (a[i]!=0 && a[i]<=max){\n minL=i;\n break;\n }\n }\n if (minR ==-1){\n System.out.println(Math.abs(minL-m)*10);\n }else if (minL ==-1){\n System.out.println(Math.abs(minR-m)*10);\n }else {\n System.out.println(Math.min(Math.abs(minR-m),Math.abs(minL-m))*10);\n }\n\n }\n}", "src_uid": "57860e9a5342a29257ce506063d37624"} {"source_code": "import java.util.Scanner;\n\npublic class C {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner in = new Scanner(System.in);\n\t\t\n\t\tint a=in.nextInt();\n\t\tint b=in.nextInt();\n\t\tint l=in.nextInt();\n\t\tint r=in.nextInt();\n\t\t\n\t\t\n\t\tSystem.out.println(fun(a,b,l,r));\n\t\t\n\t}\n\t\n\tstatic int fun(int a,int b,int l,int r){\n\t\tif ((r-l+1)>2*(a+b))\n\t\t\tif (a<=b)\n\t\t\t\treturn a+1;\n\t\t\telse\n\t\t\t\treturn (2*a-b);\n\t\t\n\t\tint[] flag = new int[3*(a+b)+1];\n\t\t\n\t\tint temp=0;\n\t\tfor (int i=1;i<=a;i++){\n\t\t\tflag[i]=i;\n\t\t\ttemp=i;\n\t\t}\n\t\t\n\t\tfor (int i=a+1;i<=a+b;i++){\n\t\t\tflag[i]=temp;\n\t\t}\n\t\t\n\t\tfor (int i=a+b+1;i<=a+b+a;i++){\n\t\t\tint tc=1;\n\t\t\twhile (in(flag,tc,a+b-a+1,i-1))\n\t\t\t\ttc++;\n\t\t\tflag[i]=tc;\n\t\t\ttemp=flag[i];\n\t\t}\n\t\tfor (int i=a+b+a+1;i<=a+b+a+b;i++){\n\t\t\tflag[i]=temp;\n\t\t}\n\t\tfor (int i=2*(a+b)+1;i<=3*(a+b);i++){\n\t\t\tflag[i]=flag[i-(a+b)];\n\t\t}\n\t\t\n\t\tint[] flagc = new int[25];\n\t\tint templ = l % (a+b);\n\t\tif (templ==0) templ+=a+b;\n\t\tint tempr = r - l + templ;\n\t\tif (tempr<templ) tempr+=a+b;\n\t\tfor (int i=templ;i<=tempr;i++){\n\t\t\tflagc[flag[i]]=1;\n\t\t}\t\n\t\t\n\t\tint res=0;\n\t\tfor (int i=1;i<=24;i++)\n\t\t\tres+=flagc[i];\n\t\t\n\t\treturn res;\n\t\t\n\t}\n\t\n\tstatic boolean in(int[] a,int b,int l,int r){\n\t\tfor (int i=l;i<=r;i++){\n\t\t\tif (a[i]==b)\n\t\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\t\n\n}\n", "src_uid": "d055b2a594ae7788ecafb3ef80f246ec"} {"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 neuivn\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskA solver = new TaskA();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskA {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n\n String s = in.nextLine();\n String t = in.nextLine();\n int id = 0;\n for (int i = 0; i < t.length(); ++i) {\n if (t.charAt(i) == s.charAt(id)) ++id;\n }\n out.println((id + 1));\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 nextLine() {\n try {\n return reader.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return null;\n }\n\n }\n}\n\n", "src_uid": "f5a907d6d35390b1fb11c8ce247d0252"} {"source_code": "import java.util.*;\nimport java.io.*;\nimport java.text.*;\npublic class Main{\n //SOLUTION BEGIN\n //Into the Hardware Mode\n void pre() throws Exception{}\n void solve(int TC)throws Exception{\n int n = ni(), k = ni();\n \n int[] phi = new int[1+n];\n \n for(int i = 1; i<= n; i++){\n phi[i] += i;\n for(int j = i+i; j<= n; j+= i)phi[j] -= phi[i];\n }\n int[][] pair = new int[n-2][];\n for(int i = 0; i< n-2; i++)pair[i] = new int[]{i+3, phi[i+3]};\n Arrays.sort(pair, (int[] i1, int[] i2) -> Integer.compare(i1[1], i2[1]));\n \n \n long ans1 = 1, ans2 = 2, cnt1 = 0, cnt2 = 0;\n for(int i = 0; i< n-2 && cnt1 < k; i++){\n if(pair[i][0]%2 == 0)continue;\n ans1 += pair[i][1];cnt1++;\n }\n for(int i = 0; i< n-2 && cnt2 < k; i++){\n ans2 += pair[i][1];cnt2++;\n }\n long ans = IINF;\n if(cnt1 == k)ans = ans1;\n if(cnt2 == k)ans = Math.min(ans, ans2);\n pn(ans);\n }\n void add(int[] cnt, int x, int b){\n if(cnt[x] > 2 || b < 0)return;\n add(cnt, x, b-1);\n if(((x>>b)&1)==1){\n int nx = x^(1<<b);\n cnt[nx]++;\n add(cnt, nx, b-1);\n }\n }\n //SOLUTION END\n void hold(boolean b)throws Exception{if(!b)throw new Exception(\"Hold right there, Sparky!\");}\n void exit(boolean b){if(!b)System.exit(0);}\n long IINF = (long)1e18, mod = (long)1e9+7;\n final int INF = (int)1e9, MX = (int)2e6+5;\n DecimalFormat df = new DecimalFormat(\"0.00000000\");\n double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-6;\n static boolean multipleTC = false, memory = false, fileIO = false;\n FastReader in;PrintWriter out;\n void run() throws Exception{\n if(fileIO){\n in = new FastReader(\"input.txt\");\n out = new PrintWriter(\"output.txt\");\n }else {\n in = new FastReader();\n out = new PrintWriter(System.out);\n }\n //Solution Credits: Taranpreet Singh\n int T = (multipleTC)?ni():1;\n pre();\n for(int t = 1; t<= T; t++)solve(t);\n out.flush();\n out.close();\n }\n public static void main(String[] args) throws Exception{\n if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, \"1\", 1 << 28).start();\n else new Main().run();\n }\n \n int digit(long s){int ans = 0;while(s>0){s/=10;ans++;}return ans;}\n long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}\n int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}\n int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}\n void p(Object o){out.print(o);}\n void pn(Object o){out.println(o);}\n void pni(Object o){out.println(o);out.flush();}\n String n()throws Exception{return in.next();}\n String nln()throws Exception{return in.nextLine();}\n int ni()throws Exception{return Integer.parseInt(in.next());}\n long nl()throws Exception{return Long.parseLong(in.next());}\n double nd()throws Exception{return Double.parseDouble(in.next());}\n \n class FastReader{\n BufferedReader br;\n StringTokenizer st;\n public FastReader(){\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n \n public FastReader(String s) throws Exception{\n br = new BufferedReader(new FileReader(s));\n }\n \n String next() throws Exception{\n while (st == null || !st.hasMoreElements()){\n try{\n st = new StringTokenizer(br.readLine());\n }catch (IOException e){\n throw new Exception(e.toString());\n }\n }\n return st.nextToken();\n }\n \n String nextLine() throws Exception{\n String str = \"\";\n try{ \n str = br.readLine();\n }catch (IOException e){\n throw new Exception(e.toString());\n } \n return str;\n }\n }\n}", "src_uid": "c2f7012082c84d773c2f4b1858c17110"} {"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 Tanzim Ibn Patowary\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n Scanner in = new Scanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskA solver = new TaskA();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskA {\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n for (int test = 0; test < testNumber; test++) {\n int a = in.nextInt();\n int b = in.nextInt();\n if (a == b) {\n out.println(a);\n } else {\n out.println(2);\n }\n }\n }\n\n }\n}\n\n", "src_uid": "a8d992ab26a528f0be327c93fb499c15"} {"source_code": "\n\nimport java.util.*;\nimport java.io.*;\n\n/*\n * author:yanghui\n */\npublic class B {\n\n\tclass FastIO {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\tPrintWriter out;\n\n\t\tpublic FastIO(File in, File o) {\n\t\t\ttry {\n\t\t\t\tbr = new BufferedReader(new FileReader(in));\n\t\t\t\tout = new PrintWriter(new FileWriter(o));\n\t\t\t} catch (Exception e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\teat(\"\");\n\t\t}\n\n\t\tpublic FastIO() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(new OutputStreamWriter(System.out));\n\t\t\teat(\"\");\n\t\t}\n\n\t\tpublic void eat(String s) {\n\t\t\tst = new StringTokenizer(s);\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\ttry {\n\t\t\t\treturn br.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new IOError(e);\n\t\t\t}\n\t\t}\n\n\t\tpublic boolean hasNext() {\n\t\t\twhile (!st.hasMoreTokens()) {\n\t\t\t\tString s = nextLine();\n\t\t\t\tif (s == null)\n\t\t\t\t\treturn false;\n\t\t\t\teat(s);\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\thasNext();\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\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic void print(String ans) {\n\t\t\tout.print(ans);\n\t\t\tout.flush();\n\t\t}\n\n\t\tpublic void print(int ans) {\n\t\t\tout.print(ans);\n\t\t\tout.flush();\n\t\t}\n\n\t\tpublic void print(long ans) {\n\t\t\tout.print(ans);\n\t\t\tout.flush();\n\t\t}\n\n\t\tpublic void print(double ans) {\n\t\t\tout.print(ans);\n\t\t\tout.flush();\n\t\t}\n\n\t\tpublic void println(String ans) {\n\t\t\tout.println(ans);\n\t\t\tout.flush();\n\t\t}\n\n\t\tpublic void println(int ans) {\n\t\t\tout.println(ans);\n\t\t\tout.flush();\n\t\t}\n\n\t\tpublic void println(long ans) {\n\t\t\tout.println(ans);\n\t\t\tout.flush();\n\t\t}\n\n\t\tpublic void println(double ans) {\n\t\t\tout.println(ans);\n\t\t\tout.flush();\n\t\t}\n\n\t\tpublic void println() {\n\t\t\tprintln(\"\");\n\t\t\tout.flush();\n\t\t}\n\n\t\tpublic void printf(String arg0, Object... arg1) {\n\t\t\tout.printf(arg0, arg1);\n\t\t\tout.flush();\n\t\t}\n\n\t\tpublic void println(int[] ans) {\n\t\t\tfor (int i = 0; i < ans.length; i++)\n\t\t\t\tprint(ans[i] + \" \");\n\t\t\tprintln();\n\t\t}\n\n\t\tpublic void println(long[] ans) {\n\t\t\tfor (int i = 0; i < ans.length; i++)\n\t\t\t\tprint(ans[i] + \" \");\n\t\t\tprintln();\n\t\t}\n\n\t\tpublic void println(double[] ans) {\n\t\t\tfor (int i = 0; i < ans.length; i++)\n\t\t\t\tprint(ans[i] + \" \");\n\t\t\tprintln();\n\t\t}\n\n\t\tpublic void println(Object... ans) {\n\t\t\tfor (Object cur : ans)\n\t\t\t\tprint(cur.toString() + \" \");\n\t\t\tprintln();\n\t\t}\n\n\t\tpublic void println(Object ans[][]) {\n\t\t\tfor (int i = 0; i < ans.length; i++) {\n\t\t\t\tprintln(ans[i]);\n\t\t\t}\n\t\t}\n\n\t\tpublic void println(int ans[][]) {\n\t\t\tfor (int i = 0; i < ans.length; i++) {\n\t\t\t\tprintln(ans[i]);\n\t\t\t}\n\t\t}\n\n\t\tpublic void println(long ans[][]) {\n\t\t\tfor (int i = 0; i < ans.length; i++) {\n\t\t\t\tprintln(ans[i]);\n\t\t\t}\n\t\t}\n\n\t\tpublic void println(double ans[][]) {\n\t\t\tfor (int i = 0; i < ans.length; i++) {\n\t\t\t\tprintln(ans[i]);\n\t\t\t}\n\t\t}\n\n\t\tpublic void println(List<Object> ans) {\n\t\t\tfor (Object i : ans) {\n\t\t\t\tprint(i.toString() + \" \");\n\t\t\t}\n\t\t\tprintln();\n\t\t}\n\n\t\tpublic void close() {\n\t\t\tout.flush();\n\t\t\tout.close();\n\t\t}\n\t}\n\n\tpublic static class ArrayUtils {\n\t\tpublic static void shuffleArray(int a[]) {\n\t\t\tint n = a.length;\n\t\t\tRandom rnd = new Random();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tint tmp = a[i];\n\t\t\t\tint randomPos = i + rnd.nextInt(n - i);\n\t\t\t\ta[i] = a[randomPos];\n\t\t\t\ta[randomPos] = tmp;\n\t\t\t}\n\t\t}\n\n\t\tpublic static void shuffleArray(long a[]) {\n\t\t\tint n = a.length;\n\t\t\tRandom rnd = new Random();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tlong tmp = a[i];\n\t\t\t\tint randomPos = i + rnd.nextInt(n - i);\n\t\t\t\ta[i] = a[randomPos];\n\t\t\t\ta[randomPos] = tmp;\n\t\t\t}\n\t\t}\n\n\t\tpublic static void shuffleArray(double a[]) {\n\t\t\tint n = a.length;\n\t\t\tRandom rnd = new Random();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tdouble tmp = a[i];\n\t\t\t\tint randomPos = i + rnd.nextInt(n - i);\n\t\t\t\ta[i] = a[randomPos];\n\t\t\t\ta[randomPos] = tmp;\n\t\t\t}\n\t\t}\n\n\t\tpublic static void shuffleArray(float a[]) {\n\t\t\tint n = a.length;\n\t\t\tRandom rnd = new Random();\n\t\t\tfor (int i = 0; i < n; ++i) {\n\t\t\t\tfloat tmp = a[i];\n\t\t\t\tint randomPos = i + rnd.nextInt(n - i);\n\t\t\t\ta[i] = a[randomPos];\n\t\t\t\ta[randomPos] = tmp;\n\t\t\t}\n\t\t}\n\n\t}\n\n//\tFastIO scan = new FastIO(new File(\"in\"), new File(\"out\"));\n\n\t FastIO scan = new FastIO();\n\n\tpublic void run() {\n\n\t\tString str = scan.next();\n\t\tint k = scan.nextInt();\n\t\tint len = str.length();\n\n\t\tint ans = 0;\n\n\t\tfor (int i = 0; i < len; i++) {\n\t\t\tfor (int j = i; j < len; j++) {\n\t\t\t\tint _len = j - i + 1;\n\t\t\t\tif (j + 1 + _len <= len) {\n\t\t\t\t\tString temp = str.substring(i, j + 1);\n\t\t\t\t\tString temp2 = str.substring(j + 1, j + 1 + _len);\n\t\t\t\t\tif (temp.equals(temp2))\n\t\t\t\t\t\tans = Math.max(ans, _len * 2);\n\t\t\t\t} else {\n\t\t\t\t\tint _len2 = j + 1 + _len - len;\n\t\t\t\t\tif (_len2 > k)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\telse {\n\t\t\t\t\t\t_len = (len - 1) - (j + 1) + 1;\n\t\t\t\t\t\tString temp = str.substring(i, i + _len);\n\t\t\t\t\t\tString temp2 = str.substring(j + 1);\n\t\t\t\t\t\tif (temp.equals(temp2))\n\t\t\t\t\t\t\tans = Math.max(ans, (j - i + 1) * 2);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tif(k >= len){\n\t\t\tans = Math.max(ans, (len+k)/2 * 2);\n\t\t}\n\t\t\n\t\tscan.println(ans);\n\n\t\tscan.close();\n\t}\n\n\tpublic static void main(String args[]) throws Exception {\n\t\tnew B().run();\n\t}\n}\n", "src_uid": "bb65667b65ff069a9c0c9e8fe31da8ab"} {"source_code": "import java.util.*;\n\npublic class Main{\n\n int n,m;\n String a[][];\n\n public void run(){\n\t\tScanner in = new Scanner(System.in);\n\t\tn = in.nextInt();\n\t\tm = in.nextInt();\n\t\n\t\ta = new String[n][m];\n\t\tfor(int i=0;i<n;i++)\n\t\t\tfor(int j=0;j<m;j++)\n\t\t\t\ta[i][j] = in.next();\n\t\n\t\tint cnt = 0;\n\t\tint i1 = -1, i2 = -1, j1 = -1, j2 = -1;\n\t\tfor(int i=0;i<n;i++)\n\t\t\tfor(int j=0;j<m;j++){\n\t\t\t\tif (a[i][j].equals(\"J1\")){\n\t\t\t\t\tcnt++;\n\t\t\t\t\ti1 = i;j1 = j;\n\t\t\t\t}else if (a[i][j].equals(\"J2\")){\n\t\t\t\t\ti2 = i;j2 = j;\n\t\t\t\t\tcnt++;\n\t\t\t\t}\n\t\t\t}\n\n\t\tif (cnt == 0){\n\t\t\tfor(int i=0;i<=n-3;i++){\n\t\t\t\tfor(int j=0;j<=m-3;j++){\n\t\t\t\t\tif (check(i, j)){\n\t\t\t\t\t\tfor(int k=0;k<=n-3;k++){\n\t\t\t\t\t\t\tfor(int l=0;l<=m-3;l++){\n\t\t\t\t\t\t\t\tif (isIn(i, j, k, l)) continue;\n\t\t\t\t\t\t\t\tif (check(k,l)){\n\t\t\t\t\t\t\t\t\tSystem.out.println(\"Solution exists.\");\n\t\t\t\t\t\t\t\t\tSystem.out.println(\"There are no jokers.\");\n\t\t\t\t\t\t\t\t\tSystem.out.println(\"Put the first square to (\" + (k + 1) + \", \" + (l + 1) + \").\");\n\t\t\t\t\t\t\t\t\tSystem.out.println(\"Put the second square to (\" + (i + 1) + \", \" + (j + 1) + \").\");\n\t\t\t\t\t\t\t\t\treturn;\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}else if (cnt == 1){\n\t\t\tHashSet<String> set = new HashSet<String>();\n\t\t\tString mast[] = new String[]{\"C\", \"D\", \"H\", \"S\"};\n\t\t\tString dost[] = new String[]{\"2\", \"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"T\",\"J\",\"Q\",\"K\",\"A\"};\n\t\t\tfor(int i=0;i<mast.length;i++)\n\t\t\t\tfor(int j=0;j<dost.length;j++)\n\t\t\t\t\tset.add(dost[j]+mast[i]); \n\n\t\t\tfor(int i=0;i<n;i++)\n\t\t\t for(int j=0;j<m;j++)\n\t\t\t\tset.remove(a[i][j]);\n\t\t\tif (i1 ==-1){\n\t\t\t\ti1 = i2;\n\t\t\t\tj1 = j2;\n\t\t\t}\n\t\t\tfor(String s1:set){\n\t\t\t\tString tmp = a[i1][j1];\n\t\t\t\ta[i1][j1] = s1;\n\t\t\t\tfor(int i=0;i<=n-3;i++){\n\t\t\t\t\tfor(int j=0;j<=m-3;j++){\n\t\t\t\t\t\tif (check(i,j)){\n\t\t\t\t\t\t\tfor(int k=0;k<=n-3;k++){\n\t\t\t\t\t\t\t\tfor(int l=0;l<=m-3;l++){\n\t\t\t\t\t\t\t\t\tif (isIn(i, j, k, l)) continue;\n\t\t\t\t\t\t\t\t \tif (check(k, l)){\n\t\t\t\t\t\t\t\t \t\tSystem.out.println(\"Solution exists.\");\n\t\t\t\t\t\t\t\t \t\tSystem.out.println(\"Replace \" + tmp + \" with \" + s1 + \".\");\n\t\t\t\t\t\t\t\t \t\tSystem.out.println(\"Put the first square to (\" + (k+1) + \", \" + (l + 1) + \").\");\n\t\t\t\t\t\t\t\t \t\tSystem.out.println(\"Put the second square to (\" + (i+1) + \", \" + (j + 1) + \").\");\n\t\t\t\t\t\t\t\t \t\treturn;\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\ta[i1][j1] = tmp;\n\t\t\t}\t\t \n\t\t}else{\n\t\t \tHashSet<String> set = new HashSet<String>();\n\t\t\tString mast[] = new String[]{\"C\", \"D\", \"H\", \"S\"};\n\t\t\tString dost[] = new String[]{\"2\", \"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"T\",\"J\",\"Q\",\"K\",\"A\"};\n\t\t\tfor(int i=0;i<mast.length;i++)\n\t\t\t\tfor(int j=0;j<dost.length;j++)\n\t\t\t\t\tset.add(dost[j]+mast[i]); \n\t\t\n\t\t\tfor(int i=0;i<n;i++)\n\t\t\t for(int j=0;j<m;j++)\n\t\t\t\tset.remove(a[i][j]);\n\t\t\t\t\n\t\t\tfor(String s1:set){\n\t\t\t\tfor(String s2:set){\n\t\t\t\t\tif (s1.equals(s2)) continue;\n\t\t\t\t\tString tmp1 = a[i1][j1];\n\t\t\t\t\tString tmp2 = a[i2][j2];\n\t\t\t\t\ta[i1][j1] = s1;a[i2][j2] = s2;\n\t\t\t\t\tfor(int i=0;i<=n-3;i++){\n\t\t\t\t\t\tfor(int j=0;j<=m-3;j++){\n\t\t\t\t\t\t\tif (check(i, j)){\n\t\t\t\t\t\t\t\tfor(int k=0;k<=n-3;k++)\n\t\t\t\t\t\t\t\t for(int l=0;l<=m-3;l++){\n\t\t\t\t\t\t\t\t \tif (isIn(i, j, k, l)) continue;\n\t\t\t\t\t\t\t\t \tif (check(k, l)){\n\t\t\t\t\t\t\t\t \t\tSystem.out.println(\"Solution exists.\");\n\t\t\t\t\t\t\t\t \t\tSystem.out.println(\"Replace J1 with \" + s1 + \" and J2 with \" + s2 + \".\");\n\t\t\t\t\t\t\t\t \t\tSystem.out.println(\"Put the first square to (\" + (k+1) + \", \" + (l + 1) + \").\");\n\t\t\t\t\t\t\t\t \t\tSystem.out.println(\"Put the second square to (\" + (i+1) + \", \" + (j + 1) + \").\");\n\t\t\t\t\t\t\t\t \t\treturn;\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\ta[i1][j1] = tmp1;a[i2][j2] = tmp2;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(\"No solution.\");\n }\n\n private boolean check(int x, int y){\n\t\tint cnt = 0;\n\t\tfor(int i=x;i<x+3;i++)\n\t\t\tfor(int j=y;j<y+3;j++)\n\t\t\tif (a[i][j].charAt(1) != a[x][y].charAt(1))\n\t\t\t\tcnt++;\n\t\n\t\tif (cnt == 9) return true;\n\t\tHashSet<String> set = new HashSet<String>();\n\t\tfor(int i=x;i<x+3;i++)\n\t\t\tfor(int j=y;j<y+3;j++)\n\t\t\t\tset.add(\"\"+a[i][j].charAt(0));\n\t\t\t\n\t\tif (set.size() == 9) return true;\n\t\treturn false;\n }\n\tprivate boolean isIn(int x1, int y1, int x2, int y2){\n\t\tif (x1 <= x2 && x2 <= x1 + 2 && y1 <= y2 && y2 <= y1 + 2) return true;\n\t\tif (x1 <= x2 + 2 && x2+2 <=x1 + 2 && y1 <= y2 && y2 <= y1 + 2) return true;\n\t\tif (x1 <= x2 && x2 <=x1 + 2 && y1 <= y2+2 && y2 +2<= y1 + 2) return true;\n\t\tif (x1 <= x2+2 && x2+2 <=x1 + 2 && y1 <= y2+2 && y2 +2<= y1 + 2) return true;\n\t\treturn false;\n\t}\n public static void main(String args[]){\n\t\tnew Main().run();\n }\n}\n", "src_uid": "b3f29d9c27cbfeadb96b6ac9ffd6bc8f"} {"source_code": "import java.util.*;\nimport java.io.*;\n\npublic class D {\n FastScanner in;\n PrintWriter out;\n\n public static void main(String[] args) {\n new D().run();\n }\n\n void solve() throws IOException {\n int n = in.nextInt();\n long m = 1; // one is bad number\n int[] primes = new int[n + 1];\n int[] primesMin = new int[n + 1];\n int primesCnt = 0;\n int[] sieve = new int[n + 1];\n for (int i = 2; i < n + 1; i++) {\n if (sieve[i] == 0) {\n primes[primesCnt++] = i;\n if (2 * i > n) {\n m++;\n }\n int cnt = 0;\n for (int j = i; j < n + 1; j += i) {\n if (sieve[j] == 0) {\n sieve[j] = i;\n cnt++;\n }\n }\n primesMin[primesCnt - 1] = cnt;\n }\n }\n int[] prefPrimesMin = new int[n + 1];\n for (int i = 0; i < primesCnt; i++) {\n prefPrimesMin[i + 1] = prefPrimesMin[i] + primesMin[i];\n } \n boolean[] squareFree = new boolean[n + 1];\n squareFree[1] = true;\n for (int i = 2; i < n + 1; i++) {\n int prev = i / sieve[i];\n squareFree[i] = prev % sieve[i] != 0 && squareFree[prev];\n// out.print(squareFree[i] + \" \");\n }\n// out.println();\n\n int[] countPrimeInDecomposition = new int[n + 1];\n for (int i = 2; i < n + 1; i++) {\n if (sieve[i] == 0) {\n countPrimeInDecomposition[i] = 1;\n } else {\n countPrimeInDecomposition[i] = 1 + countPrimeInDecomposition[i / sieve[i]];\n }\n }\n long sum1 = 0;\n for (int i = 2; i < n + 1; i++) {\n if (!squareFree[i]) continue;\n long cnt = n / i;\n cnt *= cnt;\n if (countPrimeInDecomposition[i] % 2 == 0) {\n sum1 -= cnt;\n } else {\n sum1 += cnt;\n }\n }\n long sum0 = 2 * (n - m) * m + m * (m - 1) + 1;\n// out.println(sum0);\n long sum3 = 0;\n int p1i = -1;\n for (int pi = 0; pi < primesCnt; pi++) {\n long p2 = primes[pi];\n if (p2 * 2 > n) {\n break;\n }\n if (p2 * p2 > n) {\n if (p1i == -1) {\n p1i = pi;\n }\n while (p1i >= 0 && primes[p1i] * p2 > n) {\n p1i--;\n }\n p1i++;\n sum3 += prefPrimesMin[pi] - prefPrimesMin[p1i];\n }\n }\n sum3 *= 2;\n long sum2 = (long) n * n - sum0 - sum1 - sum3;\n// out.println(m + \" \" + sum0 + \" \" + sum1 + \" \" + sum2 + \" \" + sum3);\n out.println((sum1 + sum2 * 2 + sum3 * 3 - (n - 1)) / 2);\n }\n\n void run() {\n try {\n in = new FastScanner(System.in);\n out = new PrintWriter(System.out);\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 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}", "src_uid": "bb1bd5d8bab7d79e514281230d484996"} {"source_code": "import java.util.Scanner;\n\npublic class Game23 {\n\n public static boolean pure(int m) {\n while(m > 1) {\n if(m % 2 != 0 && m % 3 != 0) return false;\n if(m % 2 == 0) m /= 2;\n else if(m % 3 == 0) m /= 3;\n }\n return true;\n }\n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n int n = s.nextInt();\n int m = s.nextInt();\n int moves = 0;\n if(!pure(m / n)) moves = -1;\n else if(m % n != 0) moves = -1;\n else {\n int value = m / n;\n while(value % 2 == 0) {\n moves++;\n value /= 2;\n }\n while(value % 3 == 0) {\n moves++;\n value /= 3;\n }\n }\n System.out.println(moves);\n }\n}\n", "src_uid": "3f9980ad292185f63a80bce10705e806"} {"source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class march15 {\n\n\tpublic static void main(String[] args) {\n\n\t\tScanner s=new Scanner(System.in);\n\t\t//System.out.println(\"enter elements\");\n\t\tint[] arr=new int[4];\n\t\tfor (int i = 0; i < arr.length; i++) \n\t\t{\n\t\t\tarr[i]=s.nextInt();\n\t\t}\n\t\tint count=1;\n\t\tArrays.sort(arr);\n\t\tfor(int i=0; i<3; i++)\n\t\t{\n\t\t\tif(arr[i]!=arr[i+1])\n\t\t\t\tcount++;\n\t\t}\n\t\tSystem.out.println(4-count);\n\t}\n}\n", "src_uid": "38c4864937e57b35d3cce272f655e20f"} {"source_code": "import java.util.*;\nimport java.math.*;\nimport java.io.*;\n\npublic class Main{\n\tstatic Scanner in;\t\n\tpublic static void main(String[] args) throws IOException{\n\t\tin = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tint k = in.nextInt();\n\n\t\tint arr[] = new int[n];\n\t\tfor(int i=0;i<n;i++){\n\t\t\tarr[i] = in.nextInt();\n\t\t}\n\n\t\tint div = n/k;\n\t\tint[][] store = new int[div+1][k];\n\t\tint ptr = 0;\n\t\tfor(int i=0;i<div;i++){\n\t\t\tfor(int j=0;j<k;j++){\n\t\t\t\tstore[i][j] = arr[ptr++];\n\t\t\t}\n\t\t}\n\t\t\n\t\tint a,b;\n\t\tfor(int i=0;i<k;i++){\n\t\t\ta = b = 0;\n\t\t\tfor(int j = 0;j<div;j++){\n\t\t\t\tif(store[j][i] == 1){\n\t\t\t\t\ta++;\n\t\t\t\t} else{\n\t\t\t\t\tb++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tstore[div][i] = Math.min(a,b);\n\t\t}\n\n\t\tint ans = 0;\n\t\tfor(int i=0;i<k;i++){\n\t\t\tans+=store[div][i];\n\t\t}\n\n\t\tSystem.out.println(ans);\n\t}\n}\n", "src_uid": "5f94c2ecf1cf8fdbb6117cab801ed281"} {"source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastScanner in = new FastScanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskD solver = new TaskD();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n\n\tstatic class TaskD {\n\t\tpublic void solve(int testNumber, FastScanner in, PrintWriter out) {\n\t\t\tlong n = in.nextLong();\n\t\t\tlong inputL = in.nextLong() - 1;\n\t\t\tlong inputR = in.nextLong() - 1;\n\t\t\tlong k = in.nextLong();\n\t\t\tlong d = dist(inputL, inputR, n);\n\n\t\t\tfinal long BIG = (long) 3e5;\n\t\t\tlong ans = -1;\n\t\t\tif (n >= BIG) {\n//\t\tif (true) {\n//\t\tif (false) {\n\t\t\t\t// c full circles.\n\t\t\t\tfor (long c = 0; n * c <= k; c++) {\n\t\t\t\t\tlong l = -1;\n\t\t\t\t\tlong r = n + 1;\n\t\t\t\t\twhile (r - l > 1) {\n\t\t\t\t\t\tlong m = l + (r - l) / 2;\n\t\t\t\t\t\tif (canLB(n, k, d, c, m)) {\n\t\t\t\t\t\t\tl = m;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tr = m;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (l >= 0 && canUB(n, k, d, c, l)) {\n\t\t\t\t\t\tans = Math.max(ans, l);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// s sweet lovers.\n\t\t\t\tfor (long s = 0; s <= n; s++) {\n\t\t\t\t\tlong minC = 0;\n\t\t\t\t\tlong maxC = 0;\n\t\t\t\t\t{\n\t\t\t\t\t\tlong b = Math.min(d, n - s);\n\t\t\t\t\t\tlong a = d - b;\n\t\t\t\t\t\tlong p = k - a - d;\n\t\t\t\t\t\tif (a > 0) {\n\t\t\t\t\t\t\t++p;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (p < 0) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tmaxC = p / (n + s);\n\t\t\t\t\t}\n\t\t\t\t\t{\n\t\t\t\t\t\tlong a = Math.min(d, s);\n\t\t\t\t\t\tlong b = d - a;\n\t\t\t\t\t\tlong p = k - a - d;\n\t\t\t\t\t\tp += n + s - 1;\n\t\t\t\t\t\tif (p < 0) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tminC = p / (n + s);\n\t\t\t\t\t}\n\t\t\t\t\tif (minC <= maxC) {\n\t\t\t\t\t\tans = Math.max(ans, s);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tout.println(ans);\n\t\t}\n\n\t\tprivate boolean canLB(long n, long k, long d, long c, long s) {\n\t\t\tlong minK = -1;\n\t\t\tlong b = Math.min(d, n - s);\n\t\t\tlong a = d - b;\n\t\t\tminK = (n + s) * c + d + a;\n\t\t\tif (a > 0 && minK > 0) {\n\t\t\t\t// Last \"a\" takes one.\n\t\t\t\t--minK;\n\t\t\t}\n\t\t\treturn k >= minK;\n\t\t}\n\n\t\tprivate boolean canUB(long n, long k, long d, long c, long s) {\n\t\t\tlong maxK = -1;\n\t\t\tlong a = Math.min(d, s);\n\t\t\tlong b = d - a;\n\t\t\tmaxK = (n + s) * c + d + a;\n\t\t\treturn k <= maxK;\n\t\t}\n\n\t\tprivate long dist(long l, long r, long n) {\n\t\t\twhile (r < l) {\n\t\t\t\tr += n;\n\t\t\t}\n\t\t\treturn r - l + 1;\n\t\t}\n\n\t}\n\n\tstatic class FastScanner {\n\t\tprivate BufferedReader in;\n\t\tprivate StringTokenizer st;\n\n\t\tpublic FastScanner(InputStream stream) {\n\t\t\tin = new BufferedReader(new InputStreamReader(stream));\n\t\t}\n\n\t\tpublic String next() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tString rl = in.readLine();\n\t\t\t\t\tif (rl == null) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\tst = new StringTokenizer(rl);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t}\n}\n\n", "src_uid": "f54cc281033591315b037a400044f1cb"} {"source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Scanner;\n\npublic class VanyaAndBooks {\n public static void main(String[]args) {\n Scanner s = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n String str=s.next();\n int n=Integer.parseInt(str);\n\n long cnt=0;\n for(int i=10;i>=0;i--) {\n if (n >= Math.pow(10, i)) {\n long diff = (long) (n - Math.pow(10, i) + 1);\n cnt += diff * str.length();\n n-=diff;\n str=String.valueOf(n);\n }\n }\n System.out.println(cnt);\n }\n}\n", "src_uid": "4e652ccb40632bf4b9dd95b9f8ae1ec9"} {"source_code": "import java.math.BigInteger;\nimport java.util.Scanner;\n\npublic class Main {\n public static void main(String[] args) {\n Scanner myObj = new Scanner(System.in);\n String a = myObj.nextLine();\n BigInteger in = BigInteger.valueOf(Long.parseLong(a));\n BigInteger two = BigInteger.valueOf(2);\n BigInteger onr = BigInteger.valueOf(1);\n BigInteger p = BigInteger.valueOf(-1);\n BigInteger zero = BigInteger.valueOf(0);\n if (in.mod(two)==zero) {\n System.out.println(in.divide(two));\n }\n else {\n System.out.println(((in.divide(two)).add(onr)).multiply(p));\n }\n }\n}\n\n\n", "src_uid": "689e7876048ee4eb7479e838c981f068"} {"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<List<Integer>> edges = new ArrayList<List<Integer>>();\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<Integer>());\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<Integer> ans = new ArrayList<Integer>();\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", "src_uid": "e13228fcdaa1c218581606ddfe186d52"} {"source_code": "import java.awt.image.BufferedImage;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class ProblemC {\n\n /**\n * @param args\n * @throws IOException\n */\n\n public static void main(String[] args) throws IOException {\n // TODO Auto-generated method stub\n Scanner sc = new Scanner(System.in);\n sc.nextInt();\n char[] num = Long.toString(sc.nextLong()).toCharArray();\n StringBuilder b = new StringBuilder();\n for (int i = 0; i < num.length; i++) {\n if (num[i] == '2') {\n b.append(\"2\");\n } else if (num[i] == '3') {\n b.append(\"3\");\n } else if (num[i] == '4') {\n b.append(\"223\");\n } else if (num[i] == '5') {\n b.append(\"5\");\n } else if (num[i] == '6') {\n b.append(\"35\");\n } else if (num[i] == '7') {\n b.append(\"7\");\n } else if (num[i] == '8') {\n b.append(\"2227\");\n } else if (num[i] == '9') {\n b.append(\"2337\");\n }\n }\n char[] needed = b.toString().toCharArray();\n Arrays.sort(needed);\n needed = reverse(needed);\n System.out.println(Arrays.toString(needed).replace(\"[\", \"\").replace(\"]\", \"\").replace(\",\", \"\").replace(\" \", \"\"));\n }\n\n private static char[] reverse(char[] needed) {\n // TODO Auto-generated method stub\n char [] opa = new char[needed.length];\n for (int i = 0; i < opa.length; i++) {\n opa[i]=needed[opa.length-i-1];\n }\n return opa;\n }\n\n}\n", "src_uid": "60dbfc7a65702ae8bd4a587db1e06398"} {"source_code": "\nimport java.util.Scanner;\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\n\n\n\n//********************************************************K.S.J_@@@@@@@@@@@@@@@@@@@@@@@@@****************************\n\npublic class kthDivisor{\n\tstatic BufferedReader reader;\n static StringTokenizer tokenizer;\n\t\n\tstatic void init(InputStream input) {reader = new BufferedReader(new InputStreamReader(input) );\n tokenizer = new StringTokenizer(\"\");\n }\n\tstatic String next() throws IOException {\n while (!tokenizer.hasMoreTokens() ) { tokenizer = new StringTokenizer(reader.readLine() );}\n return tokenizer.nextToken();\n }\n\tstatic String nextLine() throws IOException { return next();}\n\tstatic int nextInt() throws IOException {return Integer.parseInt( next() );}\n\tstatic double nextDouble() throws IOException {return Double.parseDouble( next() );}\n\tstatic long nextLong() throws IOException {return Long.parseLong( next() );}\n\tstatic BigInteger nextBigInteger() throws IOException {return new BigInteger(next()) ;}\n\n\tstatic void inputArrayInt(int arr[],int size)throws IOException{for(int i=0;i<size;i++)arr[i]=nextInt();}\n\tstatic void inputArrayDouble(double arr[],int size)throws IOException{for(int i=0;i<size;i++)arr[i]=nextDouble();}\n\tstatic void inputArrayLong(long arr[],int size)throws IOException{for(int i=0;i<size;i++)arr[i]=nextLong();}\n\tstatic void inputArrayString(String arr[],int size)throws IOException{for(int i=0;i<size;i++)arr[i]=nextLine();}\n\n\n\tpublic static void main(String args[]) throws IOException{\n\t\tinit(System.in);\n\t\t\tlong no=nextLong();\n\t\t\tint k=nextInt();\n\t\t\tint c=-1;\n\t\t\tlong sq=(long)Math.sqrt(no);\n\n\t\t\t\n\n\t\t\tArrayList<Long> Darr=new ArrayList<Long>();\n\t\t\tHashSet<Long> hs=new HashSet<Long>();\n\t\t\tif(sq==1){Darr.add((long)1);}\n\t\t\t\telse{\n\t\t\t\t\t\tfor(long i=1;i<=sq;i++){\n\t\t\t\t\t\t\tif(no%i==0 && !hs.contains(i)){Darr.add(i); hs.add(i);\n\t\t\t\t\t\t\t\tif(i<=sq && !hs.contains((long)no/i)){Darr.add((long)(no/i));}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tCollections.sort(Darr);}\n\t\t\t//Darr.add(no);\n\t\t\tint l=Darr.size();\n\t\t\t//System.out.println(Darr);\n\t\t\t//System.out.println(l);\n\t\t\tif(l<k){System.out.println(\"-1\");return;}\n\t\t\telse{System.out.println(Darr.get(k-1));}\n\t\t\t\n\n\n\t\t\t\n\t\t\t}\n\n}", "src_uid": "6ba39b428a2d47b7d199879185797ffb"} {"source_code": "// No sorcery shall prevail. // \nimport java.util.*;\nimport java.io.*;\npublic class _InVoker_ {\n\t//Variables\n\tstatic long mod = 1000000007;\n\tstatic long mod2 = 998244353;\n\tstatic FastReader inp= new FastReader();\n\tstatic PrintWriter out= new PrintWriter(System.out);\n\tpublic static void main(String args[]) {\t\t \t\n\t \t_InVoker_ g=new _InVoker_();\n\t \tg.main();\n\t \tout.close();\n\t}\n\t\n\tlong pref[];\n\t\n\t//Main\n\tvoid main() {\n\t\t\n\t\tint n=inp.nextInt();\n\t\tlong a[]=new long[n];\n\t\tinput(a,n);\n\t\tif(n>66) {\n\t\t\tout.println(1);\n\t\t\treturn;\n\t\t}\n\t\tpref=new long[n+1];\n\t\tpref[1]=a[0];\n\t\tfor(int i=1;i<n;i++) pref[i+1]=pref[i]^a[i];\n\t\tint gg=34;\n\t\tfor(int c=0;c<n-1;c++) {\n\t\t\tfor(int left=c;left>=0;left--) {\n\t\t\t\tfor(int right=c+1;right<n;right++) {\n\t\t\t\t\tif(xor(left,c)>xor(c+1,right)) gg=Math.min(gg, right-left-1);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(gg==34?-1:gg);\n\t\t\n\t}\n\t\n\tlong xor(int i, int j) {\n\t\treturn pref[j+1]^pref[i];\n\t}\n\t\n\t\n\t/*********************************************************************************************************************************************************************************************************\n\t * ti;. .:,:i: :,;;itt;. fDDEDDEEEEEEKEEEEEKEEEEEEEEEEEEEEEEE###WKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWWWWW#WWWWWKKKKKEE :,:. f::::. .,ijLGDDDDDDDEEEEEEE*\n\t *ti;. .:,:i: .:,;itt;: GLDEEGEEEEEEEEEEEEEEEEEEDEEEEEEEEEEE#W#WEKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWWWWWWWWKKKKKKG. .::. f:,...,ijLGDDDDDDDDEEEEEE *\n\t *ti;. .:,:i: :,;;iti, :fDDEEEEEEEEEEEEEEEKEEEEDEEEEEEEEEEEW##WEEEKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWWWWWWWWWKKKKKKEG .::. .f,::,ijLGDDDDDDDDEEEEEE *\n\t *ti;. .:,:i: .,,;iti;. LDDEEEEEEEEEEKEEEEWEEEDDEEEEEEEEEEE#WWWEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWWWWWKKKKKEDj .::. .:L;;ijfGDDDDDDDDDEEEEE *\n\t *ti;. .:,:i: .:,;;iii:LLDEEEEEEEEEEEKEEEEEEEEDEEEEEEEEEEEW#WWEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKWWKWWWWWWWWWWWWWWKKKKKKKEL .::. .:;LijLGGDDDDDDDDEEEEE *\n\t *ti;. .:,:;: :,;;ittfDEEEEEEEEEEEEEEEEKEEEGEEEEEEEEEEEKWWWEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWKKKKKKKELj .::. :,;jffGGDDDDDDDDDEEEE *\n\t *ti;. .:,:i: .,;;tGGDEEEEEEEEEEEKEEEKEEEDEEEEEEEEEEEEWWWEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWKWWWWWWKKKKKKKEEL .::. .:;itDGGDDDDDDDDDEEEE *\n\t *ti;. .:::;: :;ifDEEEEEEEEEEEEKEEEKEEEEEEEEEEEEEEEWWWEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKW#WWWKKKKKKKKEEf .::. :,itfGEDDDDDDDDDDDEE *\n\t *ti;. .:::;: :GGEEEEEEEEEEEKEKEEKEEEEEEEEEEEEEEEEWWEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKW#WKKKKKKKKKEEDG .::. .,;jfLGKDLDDDDDDEEDD *\n\t *ti;. .:::;: fDEEEEEEKKKKKKKKKEKEEEEEEEEEEEEEEE#WEEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKW#KKKKKKKKKKEEf .:::. .,;tfLGDEDDDDDDDDEEE *\n\t *ti;. :::;: fDEEEEEEKKKKKKKKKKWKEEEEEEEEEEEEEEEWKEEEEEEEEEEEEEEEEEEEEKEKKKKKKKKKKKKKKKKKKKKKKKKKKKKW##KKKKKKKKKEEft :::. .,;tfLGDDDKDDDDDDDDD *\n\t *ti;. .::;: fDEEEEEEKKKKKKKWKKKKKEEEEEEEEEEEEE#WEEWEEEEEDEEDEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKW#WKKKKKKKKEEGG :,:. .,;tfLGGDDDKDDDDDDDD *\n\t *ti;. .:.;: tGDEEEEKKKKKKKKKKKKKKKKKEEEEEEEEEEEWEEKWEEEEEEEDEEEEEEEEEEEEEEKEKKKKKKKKKKKKKKKKKKKKKKKKKKWWWKKKKKKKEEDf :::. .,;tfLGGDDDDEDDDDDDD *\n\t *ti;. .::;: fDEEEEEKKKKKKKKKKKWKKKKKKKKEEEEEEEWWEEWEEEEEEEEEEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKW##KKKKKKKEEEft.::. .,;tfLGGDDDDDDEDDDDD *\n\t *ti;. .:.;: tGDEEEKKKKKKKKKKKKKKKKKKKKKKEKEEEEE#EEWWEEEEEEEEEEEEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKW#WKKKKKKEEEGD:::. .,;tfLGGDDDDDDDEDDDD *\n\t *ti;. .:.,. LDEEEEKKKKKKKKKKWKWKKKKKKKKKKKKEEEKWEKW#EEEEEEEEEEEEEEEEKEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKW##KKKKKKEEEEf,,:. .,;tfLGGDDDDDDDDEDDD *\n\t *ti;. ..:.,. LGDEEEEKKKKKKKKKKWKKKKKKKKKKKKKKKKKWEEW#WEEEEEEEEEEEEEEEKEEEEEEEEEEEEEEEEEEEKEKKKKKKKKKKKKKKKK##KKKKKEEEEEfi;,. .,;tfLGGDDDDDDDDDKDD *\n\t *tt;. .:.,: jDEEEEKKKKKKKKKKWWKKKKKKKKKKKKKKKKKWKE#WWEEEEEEEEEEEEEEWEEEEEEEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKWWKKKKEEEEDfG;,: .,;tfLGGDDDDDDDDDDKD *\n\t *tii,. .:.,. tGDEEEEKKKKKKKKKKWWWKKKKKKKKKKKKKKKWKKWWWKEEEEEEEEEEEEEKEEEEEEEEEEEEEEEEEEEEEEEEEEEEEKKKKKKKKKKKW#KKKKEEEEDGGi;,. .,;tfLGGDDDDDDDDDDDE *\n\t *ti;;,:. .:.,: fDEEEEKKKKKKKKKKKWKKKKKKKKKKKKKKKKKWEK#WWKEEEEEEEEEEEEDEEEEEEEEEEEEEEGEEEEEEEEEEEEEEEEEEEKKKKKKKWWKKEEEEEEDDf;;;,. .,;tfLGGDDDDDDDDDDDD *\n\t *tii;,,:.. ...,. ;LEEEEEKKKKKKWKKKKWKKKKKKKKKKKKKKKKKEKKW#WEEEEEEEEEEEEEjEEEEEEEEEKEEEEGEEEEEEEEEKEEEEEEEEEEEEEEEEE#WKEEEEEEDDf;;;;,: .,itfLGGDDDDDDDDDDDD *\n\t *ti;,,,,,:. ...,. LDEEEEKKKKKKKKKKKWWWKKKKKKKKKKKKKKKWKK#W#WEEEEEEEEEEEDDLEEEEEEEEEWEEEEDEEEEEEEEEKEEEEEEEEEEEEEEEEEWWEEEEEEEDDfj,,,,,:. .,itfGGGDDDDDDDDDDDD *\n\t *tii,,,,::::. ...,: .fDEEEEKKKKKKWKKKKWWWKKKKKKKKKKKKKKKEKKW#WWEEEEEEEEEEEKiKEEKEEEEEEWEEEEDEEEEEEEEEEEEEEEEEEEEEEEEEEEWWEEEEEEEDDLD:::,,,:. .,ijfGGGDDDDDDDDDDDD *\n\t *ti;:::::::::.. .:.,: LDEEEEKKKKKKKWKKKKWWKKKKKKKKKKKKKKKKtKKWWWWKEEEEEEEEEDiiDEEEEEEEEWWEEEEEEDEEEEEEEEEEEEEEEEEEEEEEEEEEWKEEEEEDDDGL:. .:,,,: .,ijLGGGDDDDDDDDDDDD *\n\t *tt;. .::::::::.. ...,: :fDEEEKKKKKKKKKKKKWW#KKKKKKKKKKKKKKKKfKKWWWWKEEEEEEEEDti,DEKEEEEEEWWEEEDEEEEEEEEEKEEEEEEEEEEEEEDEEEEE#WEEEEEGGDGf:. .:,;,:. .,ijLGGDDDDDDDDDDDDD *\n\t *tt;. .:::::::.. ...,: GDEEEKKKKKKKKWKKKKWWWKKKWKKKKKKKWWWKDEKLWWWWKKEEEEEEDEi,LDEEEEEEEEWWEEEEEEEEEEEEEEEEEEEEEEEEEDEDEEEEEW#EEEEDDDDGf,. :,,,:...,ijLGGGDDDDDDDDDDDD *\n\t *tt;. .....::::.. ...,: fDEEEKKKKKKKKWKKKKWWWWKKKWKKKKKKKKKKfWKiWWW#KKEEEEEEEi;.EDfEEEDEEiWWEEEEEEEEEEEEDGKEEEEEEEEEEDEEEEEEEWWEEEEDDDGGLi. .,;,:::,ijLGGGDDDDDDDDDDDD *\n\t *tt;. ....:::::. ...,. iDEEEEKKKKKKKKWKKWKWWWWWKKWWWKKKKKKKKtWKt#WWWKKEEEEEDji..DDKDDEDEGiWKEEEEEEEEEEDDEjEEEEEEEEEEEDEEEEEEEKWKEEDDDDGGff. .:,;,,;ijLGGGDDDDDDDDDDDD *\n\t *tt;. ....::::.. .:.,: .LDEEEKKKKKKKKKKKKWWWWKWWWWWWWWWWKKKKWtKKiDWWWKKKEEEEKi:..DEDDDDDDiiWKEEEEEEEEEEDDEijDEEEEEKEEEEEEEEEEEEWWEEGDDDGGLG. .:,;;iijLGGGDDDDDDDDDDDD *\n\t *tt;. .....:::.. ...,. .fEEEEKKKKKKKKWKKKKWWWWWWWWWWWWWWKWKKKiKDiLWWWWKEEEEEi,..fD:DDDDDti;WEEEEEEEEEEKDDi:iDDEEEEWEEEEEEEEEEEE#WEEGDDDDGGG. :,iitjLGGGDDDDDDDDDDDD *\n\t *tti. .....:::.. ...,. GDEEEKKKKKKKKKWKKKWWW#WWWWWWWWWWWKWKKjiEjitWWWKKWEEEDi...DDLDDDDji;;WEEEEEEEEEEEDEj.iDDEEEEWEEEEEEEEEEEEWWEEDDDDDDGf. .,;tjfLGGDDDDDDDDDDDD *\n\t *tti. ....::::.. ...,. fEEEKKKKKKKKKKKKKKKW#WWWWWWWWWWWWWWWWtiEiiiWWWKKEWKEi....D.EDDDEi;.fWEEEEEEEEEEDDfL.;EDDEEEWEEEEEEEEEEEEWWEEEDDDDDGf. :;ijfLGGDDDDDDDDDDDD *\n\t *tti. ....::::.. ...,. LDEEEKKKKKKKKKKKKKKWWWWWWWWWWWWWWWW####WKiiiWWWKKKEEK,...:E:DDDEii..GWEEEEEEEEDWDDiL.,KDDEEEWEEEEEEEEEEEEWWKEEDDDDDGf: .,itfLGGDDDDDDDDDDDD *\n\t *tti. .....:::.. ...,. fDEEEKKKKKKKKKWKKKKWWWWWWWWWWWWW########WLiiWWWKKKEEjD...G,DDDDi;...EWEEEEEEEEDKDEii..LDDEEEWEEEEEEEEEEEEWWWEEDDDDDGfi .,;tfLGGGDDDDDDDDDDD *\n\t *tti. .....:::.. ...,. iGEEEKKKKKKKKKKWKKKKWWWWWWWWWWWW###########KiWWWKKEEE,.D..D.DDDii:...KKEEEEEEEEEDDj:...tEDEEEWEEEEEEEEEEEEWWWEEEDDDDDLL .,;tjLLGGDDDDDDDDDDD *\n\t *tti. ....::::......:. LEEEKKKKKKKKKKWWKKKWWW#KWWWWWWWW#####W####W##KWWKKEEL..:D.jjDDi;,....KKEEEEEEEDfDDi...:iKDEEEWKEEEEEEEEEEEWWWEEEEDDDDLG .,;tjLLGGDDDDDDDDDDD *\n\t *tti. ...::::::..,. :GEEEKKKKKKKKKKKKWWWWW##WWWWWWWWW##WKWK#W#W####WWKEEK.....G.DDti,.....KKEEEEEEDWGDf.,...iKDEEEWWEEEEEEEEEEEW#WEEEEEDDDGL .,;tjLLGGDDDDDDDDDDD *\n\t *tti. ....::::::,. GDEEKKKKKKKKKKKKKWWWW###WWWWWWWWWW#WWWK###W#####WKEKK.....jDDL;;......KKEEEEEEEEEDi.f...;KDEEEWWEEEEEEEEEEEWWWWEEEEEDDGf .,;tjLLGGDDDDDDDDDDD *\n\t *tti. ....:::,,. .LEEEKKKKKWKKKKKWWWWWW###WWWWWWWWWW#WWKW#WW##W#WWWKEKD:....:DD:;......;KEEEEEEEKiDD..f...,KKEEEWWEEEEEEEEEEEWWWWEEEEEDDDf .:;tjLLGGGDDDDDDDDDD *\n\t *tti. ...::,,,:. GDEEKKKKKKKKKKKKWWWWWWW#WWWWWWWWWWW#KjKWWWWWWWWWWWWEK.j,..;fD.;.......fKEEEEEDKG:Di..,....DKEEEWWEEEEEEKEKKKWWWWEEEEEEDDf .:;tjLLGGDDDDDDDDDDD *\n\t *jti. ...::,,,,:. .fEEEKKKKKWKKKKKKWWWWWWW#WWWWWWWWWWK#KKKWWWWWWWWWWWWWK..f:.:G.,:.......EKEEEEEKK;:E:.......fKEEEWWKEKEKKKKKKKW#WWEEEEEEDDf: .,;tfLLGGDDDDDDDDDDD *\n\t *tti. ...:,,,;;,: iDEEKKKKKWKKKKKKKWWWWWWW#WWWWWWWWWWK#WDKWWKKWWWWWWWWWE..;G:G..,........KKEEEEEKi.Gi..:.....tKEEKWWWKKKKKKKKKKW##WKEEEEEEDfi .,;tfLLGGGDDDDDDDDDD *\n\t *tti. ....::,,;;;,LEEKKKKKKWKKKKKWWWWWWW###WWWWWWWWWWKWWDKWEEEWKKWWWWWKKj.:LG..;.........EKEEEEKG;.G...;.....;KKEKWWWKKKKKKKKKKW##WWKEEEEEDfL .,;tfLGGGDDDDDDDDDDD *\n\t *jti. ...::::,;ijDEEKKKKKWKKKKKKWKWWWWW##WWWWWWWWWWWKK#KKGDGDWEEWKKWKKGE,.i;.:.........:EKEEEKE;.:L...j.....,KWEKWWWKKKKKKKKKK####WKKEEEEDLG .,;tfLGGGGDDDDDDDDDD *\n\t *jti. ...:...,,;GEEKKKKKWWKKKKKWWWWWWWW###WWWWWWWWWKKKWWKiLGGEDEDEKGKKiEG..;...........jKEEEKK;:.G....,.....:KKEWWWWKKKKKKKWKK####WKKKKEEEGL .,;tfLGGGGDDDDDDDDDD *\n\t *jti. ...:. .:,GEEKKKKKWKKKKKWWWWWWWW####WWWWWWWWWKKKWWKii;fDLGDK: EEi:E:.............EKEEKK;;..L...........KKKWWWWKKKKKKKWKK####WKKKWKEEDf .,;tfGGGGDDDDDDDDDDD *\n\t *jti. ...:. ,EEKKKKKWWKKKKKWWWWWWWWW###WWWWWWWWKKKKfWWLt;i,. fi EG..D:.............EKEKK;;..t....:.......KWKWWWWKKKKKKKWKK####WKKKWEEEDf:. .,;tfGGGGDDDDDDDDDDD *\n\t *jti. ...:. GEEKKKKKWKKKKKWWWWWWWWW####WWWWWWWKKKKKt;KKEfff .;t.................KKKKi;:..GtGGfG.......KWWWWWWKKKKKKKWKK###WWWKKKKEEEf,,: .,;tfGGGGDDDDDDDDDDD *\n\t *jti. ...:. GEKKKKKWWKKKKKWWWWWWWWWW##WWWWWWWKKKKKKt;EiKKKK, ...t................jEKKG;;..,.....,LGi....KWWWWWWKKKKKKWKKKW####WKKKKKEEL,,,:. .,;tfGGGDDDDDDDDDDDD *\n\t *jti. ...:. .GEEKKKKKWKKKKKWWWWWWWWWW###WWWWWWWKKKKKKtiE::tGG........................EEEj;;...,.........:D..DKWWWWWWKKKKK#KKW###W#WKKKKKEEfj:,,,:. .,;tfGGGDDDDDDDDDDDD *\n\t *jti. ...:. DEKKKKKWWKKKKKWWWWWWWWW####WWWWWWWKKKKKKiiE:::.::.......................EEi;;...j.....f......:iDKWWWWWWKKKKK#WW######WKKKKKEELG :,,,,:. .,;tfGGGDDDDDDDDDDDD *\n\t *jti. ...:. fEEKKKKWWKKKKWWWWWWWWWWW###WWWWWWWWKKKKKK;tE::..........................DD;.;,.::......;........EWWWWWWWKKKKW#WW#####WWKKKWKKELG .:,,,:::,;tfGGGDDDDDDDDDDDD *\n\t *jti. ...:. .DEKEKKKWWKKKKWWWWWWWWWWW###WWWWWWWWKKKKKE,iD::..........................D..,;.,;tLffi...........DWDWWWW#KKKWWWWW#####W#KKKWKEEGL .:,;,,,;tfGGGDDDDDDDDDDDD *\n\t *jti. ...:. ;EEKKKKWWKKKKKWWWWWW#WWWW####WWWWWWKKKKKEL:iD:..........................j ..;..;;:.....i,........DKtWWWWWKKWWWWWW#####WWWKKKEKEDf .:,;;;itfGGGDDDDDDDDDDDD *\n\t *jti. ...:. DEKKKKKWWKKKKWWWWWWW#WWWW####WWWWWWKKKKKEj:iG...............................:....................GKiWWWWWKKWW#WWW######WWKKKKKEEf .,;iitfGGGDDDDDDDDDDDD *\n\t *jti. ...:.:EKKKKKWWKKKKKWWWWWWW#WWW#####WWWWWKWKKKKEi:if:.................................iEKEKKKKKKDj......DKiWWWWWKWK##WW#######WWKKK:KEEL .:;itfGGGDDDDDDDDDDDD *\n\t *jji. ...:,DEEKKKWWWKWKKWWWWWWWWWWWW#####WWWWWWWKKKKEi:it..................................j. KKKKKKKKKKKf..DKiWWWWWKWW##WW#######WWKKK,KEEf .,;tfGGGDDDDDDDDDDDD *\n\t *jji. ..L:iDEEKKKWWKKKKKWWWWWWWWWWWW#####WWWWWKWKKKKKi.i;.................................. . KKKWWWWWWWWK..DGiWWWWWKK##WWW#####W#WWKKKjEKEL, .:;tfGGGDDDDDDDDDDDD *\n\t *jji. .f:::EEEKKKWWWKKKKKWWWWWWWWWWWW#####WWWWWKWKKKKK;.i,.................................:: KKEKWWWWWWfWK..EiiWWWWWKWW#WW##########KKKD,KELj .:;tfGGDDDDDDDDDDDDD *\n\t *jji. .t::::,DEEKKKWWKKKKWWWWWWWWW#WWWW#####WWWWKKWKKKEK;.i:.................................GDDEEEKKKWWWWWtWWD.E;iWWWWWW###WW#########WWKKK.EEDG .:;tfGGGDDDDDDDDDDDD *\n\t *jji. . j..::::EKEKKKWWWKKKKWWWWWWWWW#WWW######WWWWKKWKKKEK;.t:.................................ELLEDDEEEWWWWEtWK,.KiiWWWWWW###W##########WWKKK:EEEG .;tjfLLGDDDDDDDDDDDDDDD *\n\t *jji. i.::::::,EEEKKWWWKKKKKWWWWWWWWW#WWW#####WWWWWKWKKKKEE,.t..................................DfiEGDDDEEKKKttKWG.KiiWWWWW##WWW##########WWKKK:fEEL ,fGGGDDDDDDDDEEEDDDDDDDDDD *\n\t *jji. .;:..:::::DEEEKKWWWKKKKKWWWWWWWWW#WWWW####WWWWWWWKKKKED,.t..................................ifjDDGGEGDKK.ttKKE.DiWWWWW###WW##########WWWKKK:.KELiLGGGGDDDDDDDDDDDDEEEDDDDDDD *\n\t *jji. i.:.::::::,KEEKKWWWKKKKKKWWWWWWWWW#WWWW####WWWWWWWKKKKEL:.j..................................GGf,;ifLLED .iiKKi:fWWWWWW##W#W##########WWWKKK:.KKLGGDDDDDDDDDDDDDDDDEDDEEDDDDD *\n\t *jji. .j:.::::::::EEEKKKWWWKKKKKKWWWWWWWW##WWW#####WWWWWWWKKKKKf:.f..................................:EEfftf .,. ;iE,..jWWWWWWW###W############WWKKK,:KKGDDDDDDDDDDDDDDDDDDDDDDDEDDDD *\n\t *jji. .:.::::::::,,EEEKKWWWKKKKKKKWWWWWWWW##WWW#####WWWWWWWKKKKKt..G....................................EEELL; .j....tKWWWWWWW################WWWKKtfGKGEDDDDDDDDDDDDDDDDDDDDDDDEEDD *\n\t *jji. :...:::::::,,jEEKKWWWWKKKKKKWWWWWWWWW##KWW#####KWWWWWWKKKKEi..D....................................:jEEE.........;KKWWWWWWWW#WW##W##########WWKKDLGKEKDDDDDDDDDDDDDDDDDDDDDDDDDED *\n\t *jji. i:.::::::::,,,EEEKKWWWWKKKKKWWWWWWWWWW##WWW#####WWWWWWWKKKKKi..D......................................:::::......,KKKWWWWWWWWW#####W########WWWKKKGGKKEGGGGGGGGDDDDDDDDDDDDDDDDDDE *\n\t *jji. i..:::::::::,,tEEKKWWWWKKKKKWWWWWWWWWWW##WW######WWWWWWWKKKKKi..D......................................::::......:EKKKWWWWWWWWWWW##WW########W#WKKWGGKKGGGGGGGGGGGGGGGDDDDDDDDDDDDD *\n\t *jji. .:::::::::::,,,EEEKKWWWWKKKKKWWWWWWWWWWW##WW#####WWWWWWWWKKKKKi..D....................................:::::::::..tELii;KWWWWWWWWWW##WW######WWWWWWKWGGGKGGGGGGGGGGGGGGGGGGGGGGGGGGDG *\n\t *jjt. :.::::::::,,,,fEEKKWWWWKKKKKKWWWWWWWWWW###WW####WWWWWWW#WKKKKKi..D....................................:::::::.:.,;;;;;;,KKWWWWWWWWW#WW########WWWKKWGGGKGGGGGGGGGGGGGGGGGGGGGGGGGGGG *\n\t *jji. ;.::::::::,,,,;EEEKWWWWWKKKKKWWWWWWWWWWWW##WW###WKWWWWWK#WKKKKKi..G......................................:::::::,;;;;:...KKKWWWWWWWWWKWW#######WWWWKKGLGKDGGGGGGLLGGGGGGGGGGGGGGGGGGG *\n\t *jjt. f.:::::::::,,,,fEEKKWWWWWKKKKKWWWWWWWWWWW###WW##WKKWWWWWW#WKKKKK;.jt........i.............................:::::::;j;;....:E.KKKWWWWWWWKWW#####W#WWWWKKLLGWEEGGGGGLGGGGGGGGGGGGGGGGGGGG *\n\t *jjt. ...:::::::,,,,,;DEEKWWWWWKKKKKWWWWWWWWWWWW####WWWKKKWWWWWWWWKKKKK;.E;.........t.............................:::::ii;;.....D...KKWWWWWWWKWW#####WWEWWWKKGGGEKKGGGGGLGGGGGGGGGGGGGLGGGGGG *\n\t *fji. ;.:::::::,,,,,;LEEKKWWWWWKKKKKWWWWWWWWWWWW####KWKKKKWWWWWWWWKKKKKi.D;..........j.............................:::tt;,.....:.....KKWWWWWWKWWWW##WWWGWWWKKGGGGKEGGGGGGGGGGGGGGGGGGGLLGGGGL *\n\t *fji. t::::::::,,,,,,;EEEKWWWWWKKKKKKKWWWWWWWWWWW##WKWKKKKKWWWWWWWWKKKKKi:D;............j...........................::LL;,.............KKWWWWWKWWWWWWWWWGWWWKKGGGGKGGGGGGGGGGGGGGGGGGGGLLGGGGL *\n\t *fjt: .:::::::,,,,,,,DEEKWWWWWWKKKKKKKWWWWWWWWWWWWKKWKKKKKKWWWWK#WWKKKKWitE;........... ............................:G;;:...............KKKWWKKWWWWWWWWWGWWWKKGGGGWGGGGGGGGGGGGGGGGGGGGGGGGGGL *\n\t *fjji;:. .f:::::::,,,,,,,;EEEKWWWWWWKKKKKKWWWWWWWWWWWKKKKKKKKKKKWWKWWWWWKKKKWGKD;........................................L;;..................DKKWKKWWWWWWWWWGWWWKKDGGGKDGGGGGGGGGGGGGGGGGGGGGGGGGG *\n\t *fjjtii;,:. :::::::,,,,,,,;EEEKWWWWWWKKKKKKWWWWWWWWWWKKKKKKKKKKKKWWWWWW#WWKKKKWiEj;......................................:i,;....,...............;KKEKWWWWWWWWWGKWWKKDDGGDEGGGDGGGGGDGGGGGGGGGGGGGGGG *\n\t *fjtiiiii;;:. j::::::,,,,,,,;;EEEKWWWWW#KKKKKWWWWWWWWWKKKKKKWKKKKKKKWWWWWWWWWKKKKWtEL;:....................................;;;:...,;j................:KEEWWWWWWWWWDDWWKKDDDDDKDDDDDDDDDDDDDDDGGGGGGGGGGG *\n\t *fjti;;iiii;;,:::::::,,,,,,,,;EEEKWWWWWWWKKKKWWWWWWWWKKKKKKKWKKKKKKKWWWWWWW#W#KKKKWEEii;...................................f;:....,;L...................EEKWWWWWWWWDDWWKKDDDDDKEDDDDDDDDDDDDDDDDDDDDDGGGG *\n\t *fjt,,,;;;;ii;f::::::,,,,,,,;;EEKWWWWWWWKKKKKWWWKWWKKKKKKKKKKKKKKKKKWWWWWWW#W#KKKKWKEij;:...............................:G;,.....,;f....................:tKKWWWWWWWDDWWKKDDDDDKKDDDDDDDDDDDDDDDDDDDDDDDDD *\n\t *jjt. ..:,;;;;,::::,,,,,,,,;;GEEWWWWWWWWKKKKWKKWKKKKKKKKKKKKKKKKKKKKWWWWWWW#W#KKKKWEDi;j;............................,Li;L;;;..,;;f........................KKKKWWWKDDWWKKDDDGDKKGGGGGGGGDGDDDDDDDDDDDDDDD *\n\t *fjt. .:,,,:::::,,,,,,,;;;EEKWWWWWWWKKKKKKWKKKKKKKKKKKKKKKKKKKKKWKKKWKW##W#KKKKWEti;;G;........................tEEEL;;;;;;;;;;L..........................DKKKKKEDDWWKEDGftiLE;;;;itjLGGGGGGDDDDDDDDDDD *\n\t *fjt. .j::::,,,,,,,;;;DEEWWWWWWWWKKKKWKKKKKKKKKKKKKKKKKKKKKKKWKKWWWK##W#KKKKKEii;;;L;...................iDEEEEEEKKi;j;;;;jD.....:......................,KKKKDGGEKKE:::::;E::::::::::,tLGGDDDDDDDDDD *\n\t *fjt. .;:::,,,,,,,;;;;EEKWWWWWWWWKWKKKKKKKKKKKKKKKWKKKKKKKKKKWKKWWWW#WW#KKKKKKii;;;;f;.............:tDEEEEEKKKKKKKKEti;;;L...............................EEKf;:iKKE::::::E::::::::::::::ifDDDDDDDDD *\n\t *fjt: :::,,,,,,,,;;;DEEWWWWWWWWWEKKKKKKKKKKKKKKKKKKKKKKKKKKWWKKWWWW####KKKKKEiii;;;;f,.........iDEEEEKKKKKKKKKKKKKKKf;iG......i..........................fK::::KKE::::::E::::::::::::::::,tGGDDDDD *\n\t *fjt: t:::,,,,,,;;;;iDEKWWWWWWKEKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWKKWWWW####WKKKKLiii;;;;;L,....,Li;EDEEEEKKKKKKKKKKKKKKKKiG......;:...........................:i:::KKE:::::,E,::::::::::::::::::iGDDDD *\n\t *jjt. f::,,,,,,,;;;;GEEWWWWKEEKEKKKKKKKKKKKKKKKKWKKKKKKKKKKKWWKWWWWW###WWKKKKiii;;;;;;;G,;L;;iiEEEEEEEKKKKKKKKKKKKKWWKE......;t.........:....................j::KEE:,::,,D,,::::,,,,,,:::::::::tDDD *\n\t *fjt:. ,::,,,,,,,;;;;EEWWKEEEEEEKKKKKKKKKKKKKKKKWKKKKKKKKKKKWWKKWWWWW#W#KKKKKKiiiiii;;;;;i;;iiiEEKEEKKWKKKKKKKWKKKKKWWWGi;...;t......,;;;;,....................:,EEE,,,,,,D,,,,,,,,,,,,,,,,::,::::tG *\n\t *fjt:. ,::,,,,,,,;;;;DEKEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWW#W#KKKKKKiiiii;;i;;;;;iiiKKKEKKKKWWKWWWWWWKKKKWWWWW;;;:;L.....;;;;;;;;;....................,KEE,,,,,,E,,,,,,,,,,,,,,,,,,,,,,,,; *\n\t *fjt:. f:,,,,,,,;;;;jEDEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWW#W##KKKKKKiiiiiiii;i;;iiiEKKKKKKKKWKWWWWWWWWKKKWWWWWKi;;i.....,jEEfGi;;;;;...................EED,,,,,,E,,,,,,,,,,,,,,,,,,,,,,,,, *\n\t *fjt:. .f::,,,,,,;;jEEDEEEEEEEEEEKKKKKKKKKKKKKKKWKKKKKKKKKKKKKWWWKWWWWW###KKKKKLiiiiiiiiiiiiiiEEKKKKKKKKWWWWWWWWWWWWKWWWWWWGi;i;,..;jDDDKEGi;;;;;;:................EED,,,,,,D,,,,,,,,,,,,,,,,,,,,,,,,, *\n\t *fjt:. .. ;::,,,,,;;EDDEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWKKW#WW####KWKKKiiiiiiiiiiiiijKKKKKKKKKKWWWWWWWWWWWWWWWWWWWWWt;i;;;;i;DDDDDDGi;;;;;;;;:.............EDf;,,,;,G;;;;;;;;;;;;;;;,,,,,,,,,, *\n\t *fjt:......:,,,,,,;LDDDEEEEEEEEEEEKKKKKKKKKKKKKKKKWKKKKKKKKKKKKKWWWWKWWWW####KKKKKiiiiiiiiiiijKEKKWKKKKKKKWWWWWWWWWWWWWWWWWWWWWWiLiii;i;DEEEEDDE;i;;;;;;;;;:..........EDi,;;;;;L;;;;;;;;;;;;;;;;;;,,,,,,, *\n\t *fjt:......:,,,,,;EDDDEEKEEEEEEEEEKKKKKKKKKKKKKKKWKKKKKKKKKKKKKKWWWWKKWWW##W#KWKKWEiiiiiijGKKKKKWWKKKKKKKKWWWWWWWWWWWWWWWWWWWWWWKi;iiiiDDEEEEEEDEi;;;;;;;;;;;;;,:.....ED;;;;;;;j;;;;;;;;;;;;;;;;;;;;;;;,, *\n\t *fjt:.....t,,,,,;DDDDEEEKEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWWKKKWWWW##WKWKKWKiiiKKKKKKKKKWWKKKKKKKKWWWWWWWWWWWWWWW#WWWWWWWWWiiiiifLEEEEEEEEDi;i;;;;;;;;;;;;.....DD;;;;;;;i;;;;;;;;;;;;;;;;;;;;;;;;; *\n\t *fjt:.....G,,,,,GDDDEEEEEEEEEEEEKKKKKKKKKKKKKKKKWKKKKKKKKKKKKKKKWWWKKKWWW###WKWKKWKitKKKKKKKKKWKKKKKKKKKKWWWWWWWWWWWWWW###WWWWWWWWEiiiiiiiEEEEEEEEDGiiii;;;;;;;;;.....GD;;;;;;;i;;;;;;;;;;;;;;;;;;;;;;;;; *\n\t *fjt:.....L,,,,;GDDDEEEEEEEEEEKEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWDGWWW###KKWWKWKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWW####WWWWWWWWWiiiiiiiiEEEEEEEEEEDi;i;;;;;;;;.....Lj;;;;;;i;iiiiii;;;;;;ii;;;;;;;;;;; *\n\t ***********************************************************************************************************************************************************************************************************/\n\n\tvoid sort(int a[]) {\n\t\tArrayList<Integer> list=new ArrayList<>();\n\t\tfor(int x: a) list.add(x);\n\t\tCollections.sort(list);\n\t\tfor(int i=0;i<a.length;i++) a[i]=list.get(i);\n\t}\n\tvoid sort(long a[]) {\n\t\tArrayList<Long> list=new ArrayList<>();\n\t\tfor(long x: a) list.add(x);\n\t\tCollections.sort(list);\n\t\tfor(int i=0;i<a.length;i++) a[i]=list.get(i);\n\t}\n\tvoid ruffleSort(int a[]) {\n\t\tRandom rand=new Random();\n\t\tint n=a.length;\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tint j=rand.nextInt(n);\n\t\t\tint temp=a[i];\n\t\t\ta[i]=a[j];\n\t\t\ta[j]=temp;\n\t\t}\n\t\tArrays.sort(a);\n\t}\n\tvoid ruffleSort(long a[]) {\n\t\tRandom rand=new Random();\n\t\tint n=a.length;\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tint j=rand.nextInt(n);\n\t\t\tlong temp=a[i];\n\t\t\ta[i]=a[j];\n\t\t\ta[j]=temp;\n\t\t}\n\t\tArrays.sort(a);\n\t}\n\t\n static class FastReader { \n BufferedReader br; \n StringTokenizer st;\n public FastReader() { \n br = new BufferedReader(new InputStreamReader(System.in)); \n } \n String next() { \n while (st==null || !st.hasMoreElements()) { \n try { \n st = new StringTokenizer(br.readLine()); \n } \n catch (IOException e) { \n e.printStackTrace(); \n } \n } \n return st.nextToken(); \n } \n int nextInt() { \n return Integer.parseInt(next()); \n } \n long nextLong() { \n return Long.parseLong(next()); \n } \n double nextDouble() { \n return Double.parseDouble(next()); \n } \n String nextLine() { \n String s=\"\"; \n try { \n s=br.readLine(); \n } \n catch (IOException e) { \n e.printStackTrace(); \n } \n return s; \n } \n } \n \n\tlong fact[];\n\tlong invFact[];\n\tvoid init(int n) {\n\t\tfact=new long[n+1];\n\t\tinvFact=new long[n+1];\n\t\tfact[0]=1;\n\t\tfor(int i=1;i<=n;i++) {\n\t\t\tfact[i]=mul(i,fact[i-1]);\n\t\t}\n\t\tinvFact[n]=power(fact[n],mod-2);\n\t\tfor(int i=n-1;i>=0;i--) {\n\t\t\tinvFact[i]=mul(invFact[i+1],i+1);\n\t\t}\n\t}\n\tlong modInv(long x) {\n\t\treturn power(x,mod-2);\n\t}\n\t\n\tlong nCr(int n, int r) {\n\t\tif(n<r || r<0) return 0;\n\t\treturn mul(fact[n],mul(invFact[r],invFact[n-r]));\n\t}\n\t\n\tlong mul(long a, long b) {\n\t\treturn a*b%mod;\n\t}\n\tlong add(long a, long b) {\n\t\treturn (a+b)%mod;\n\t}\n\t\n\tlong power(long x, long y) {\n\t\tlong gg=1;\n\t\twhile(y>0) {\n\t\t\tif(y%2==1) gg=mul(gg,x);\n\t\t\tx=mul(x,x);\n\t\t\ty/=2;\n\t\t}\n\t\treturn gg;\n\t}\n \n // Functions\n\tstatic long gcd(long a, long b) { \n\t\treturn b==0?a:gcd(b,a%b);\n\t}\n\tstatic int gcd(int a, int b) { \n\t\treturn b==0?a:gcd(b,a%b);\n\t}\n\t\n\tvoid print(int a[]) {\n\t\tint n=a.length;\n\t\tfor(int i=0;i<n;i++) out.print(a[i]+\" \");\n\t\tout.println();\n\t}\n\t\n\tvoid print(long a[]) {\n\t\tint n=a.length;\n\t\tfor(int i=0;i<n;i++) out.print(a[i]+\" \");\n\t\tout.println();\n\t}\n \n //Input Arrays\n static void input(long a[], int n) {\n\t\tfor(int i=0;i<n;i++) {\n\t\t\ta[i]=inp.nextLong();\n\t\t}\n\t}\n\tstatic void input(int a[], int n) {\n\t\tfor(int i=0;i<n;i++) {\n\t\t\ta[i]=inp.nextInt();\n\t\t}\n\t}\t\n\tstatic void input(String s[],int n) {\n\t\tfor(int i=0;i<n;i++) {\n\t\t\ts[i]=inp.next();\n\t\t}\n\t}\n\tstatic void input(int a[][], int n, int m) {\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tfor(int j=0;j<m;j++) {\n\t\t\t\ta[i][j]=inp.nextInt();\n\t\t\t}\n\t\t}\n\t}\n\tstatic void input(long a[][], int n, int m) {\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tfor(int j=0;j<m;j++) {\n\t\t\t\ta[i][j]=inp.nextLong();\n\t\t\t}\n\t\t}\n\t}\n\t\t\n}\n", "src_uid": "51ad613842de8eff6226c97812118b61"} {"source_code": "import java.util.Scanner;\npublic class Main\n{\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint a =sc.nextInt(), b=sc.nextInt() , c=sc.nextInt(),d=sc.nextInt();\n\t if(a+b == c+d)\n\t System.out.print(\"YES\"); \n\t else\n\t if(a+c == b+d)\n\t System.out.print(\"YES\");\n\t else\n\t if(a+d == b+c )\n\t System.out.print(\"YES\");\n else\n if(a == b+c+d)\n System.out.print(\"YES\");\n else\n if(b == a+c+d)\n System.out.print(\"YES\");\n else\n if(c== a+b+d)\n System.out.print(\"YES\");\n else \n if(d == a+b+c)\n System.out.print(\"YES\");\n else\n System.out.print(\"NO\");\n\t \n\t}\n}\n", "src_uid": "5a623c49cf7effacfb58bc82f8eaff37"} {"source_code": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.StringTokenizer;\n\npublic class A {\n\n\t\n\tstatic int[] genLucky()\n\t{\n\t\tint[] c = new int[1022];\n\t\tQueue<Integer> q = new LinkedList<Integer>();\n\t\tint k = 0;\n\t\tq.add(4); q.add(7);\n\t\twhile(!q.isEmpty())\n\t\t{\n\t\t\tint x = c[k++] = q.remove();\n\t\t\tif(k == 1022)\n\t\t\t\tbreak;\n\t\t\tq.add(x * 10 + 4);\n\t\t\tq.add(x * 10 + 7);\n\t\t}\n\t\treturn c;\n\t}\n\t\n\tstatic double prob(int x, int y, int l, int r)\n\t{\n\t\tif(x < l) x = l;\n\t\tif(y > r) y = r;\n\t\tif(x > y) return 0;\n\t\treturn 1.0 * (y - x + 1) / (r - l + 1);\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException \n\t{\n\t\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t\n\t\tint pl = sc.nextInt(), pr = sc.nextInt(), vl = sc.nextInt(), vr = sc.nextInt(), k = sc.nextInt();\n\t\tint[] lucky = genLucky();\n\t\tdouble ans = 0;\n\t\tfor(int i = 0; i + k <= 1022; ++i)\n\t\t{\n\t\t\tint xl = i == 0 ? 1 : lucky[i - 1] + 1;\n\t\t\tint xr = lucky[i];\n\t\t\tint yl = lucky[i + k - 1];\n\t\t\tint yr = i + k == 1022 ? (int)1e9 : lucky[i + k] - 1;\n\t\t\tans += prob(xl, xr, pl, pr) * prob(yl, yr, vl, vr);\n\t\t\tans += prob(yl, yr, pl, pr) * prob(xl, xr, vl, vr);\n\t\t\tif(k == 1)\n\t\t\t\tans -= prob(xr, xr, pl, pr) * prob(xr, xr, vl, vr);\n\t\t}\n\t\tout.println(ans);\n\t\tout.close();\n\t}\n\t\n\tstatic class Scanner \n\t{\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s){\tbr = new BufferedReader(new InputStreamReader(s));}\n\t\t\n\t\tpublic Scanner(FileReader r){\tbr = new BufferedReader(r);}\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\n\n\t}\n}", "src_uid": "5d76ec741a9d873ce9d7c3ef55eb984c"} {"source_code": "import java.io.*;\nimport java.text.*;\nimport java.util.*;\nimport java.math.*;\npublic class template {\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew template().run();\n\t}\n\tpublic void run() throws Exception {\n\t\tFastScanner f = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t///\n\t\tint n = f.nextInt(), q = f.nextInt();\n\t\tint sz = 256;\n\t\tint[] arr = new int[n];\n\t\tint[][] orig = new int[(n-1)/sz+1][sz];\n\t\tint[] szs = new int[(n-1)/sz+1];\n\t\tint[][] val = new int[(n-1)/sz+1][sz];\n\t\tint[][][] id = new int[(n-1)/sz+1][][];\n\t\tArrays.fill(val[val.length-1], -1);\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tarr[i] = f.nextInt()-1;\n\t\t\tval[arr[i]/sz][szs[arr[i]/sz]] = arr[i];\n\t\t\torig[arr[i]/sz][szs[arr[i]/sz]] = ++cnt;\n\t\t\tszs[arr[i]/sz]++;\n\t\t}\n\t\tfor(int i = 0; i < sz; i++)\n\t\t\tif(val[val.length-1][i] == -1) val[val.length-1][i] = (val.length-1)*sz+i;\n\t\tadd1 = new ArrayList<>(22000000); add2 = new ArrayList<>(2200000);\n\t\taux = new int[9][2][][];\n\t\taux2 = new int[9][4][];\n\t\tfor(int i = 0; i <= 8; i++) {\n\t\t\taux[i][0] = new int[(1 << i)+1][(1 << i)+1];\n\t\t\taux[i][1] = new int[(1 << i)+1][(1 << i)+1];\n\t\t\taux2[i][0] = new int[(1 << i)];\n\t\t\taux2[i][1] = new int[(1 << i)];\n\t\t\taux2[i][2] = new int[(1 << i)];\n\t\t\taux2[i][3] = new int[(1 << i)];\n\t\t}\n\t\tfor(int i = 0; i < id.length; i++) {\n\t\t\tid[i] = new int[sz+1][sz+1];\n\t\t\taux2[8][0] = val[i];\n\t\t\taux2[8][1] = orig[i];\n\t\t\tgen(i*sz, 8, 0);\n\t\t\tfor(int a = 0; a <= sz; a++)\n\t\t\t\tfor(int b = a+1; b <= sz; b++) id[i][a][b] = aux[8][0][a][b];\n\t\t}\n\t\tif(n % 256 != 0) for(int i = n-n/sz*sz; i < sz; i++) orig[orig.length-1][i] = 2147483647;\n\t\tint[] ans = new int[q];\n\t\tfor(int i = 0; i < q; i++) {\n\t\t\tint l = f.nextInt(), r = f.nextInt()+1;\n\t\t\tfor(int b = 0; b < orig.length; b++) {\n\t\t\t\tint s = 0, e = 0;\n\t\t\t\t{\n\t\t\t\t\tint lo = 0, hi = sz;\n\t\t\t\t\twhile(lo < hi) {\n\t\t\t\t\t\tint m = (lo+hi)/2;\n\t\t\t\t\t\tif(orig[b][m] < l) lo = m+1;\n\t\t\t\t\t\telse hi = m;\n\t\t\t\t\t}\n\t\t\t\t\ts = lo;\n\t\t\t\t}\n\t\t\t\t{\n\t\t\t\t\tint lo = 0, hi = sz;\n\t\t\t\t\twhile(lo < hi) {\n\t\t\t\t\t\tint m = (lo+hi)/2;\n\t\t\t\t\t\tif(orig[b][m] < r) lo = m+1;\n\t\t\t\t\t\telse hi = m;\n\t\t\t\t\t}\n\t\t\t\t\te = lo;\n\t\t\t\t}\n\t\t\t\tans[i] = add(ans[i], id[b][s][e]);\n\t\t\t}\n\t\t}\n\t\tout.println(cnt);\n\t\tfor(int i = 0; i < add1.size(); i++) { out.println(add1.get(i) + \" \" + add2.get(i)); }\n\t\tfor(int i : ans) out.print(i + \" \");\n\t\tout.println();\n///\n\t\tout.flush();\n\t}\n\tArrayList<Integer> add1, add2;\n\tint cnt;\n\tint[][][][] aux;\n\tint[][][] aux2;\n\tpublic void gen(int st, int lvl1, int lvl2) {\n\t\tint n = 1 << lvl1;\n\t\tif(n == 1) {\n\t\t\taux[lvl1][lvl2][0][1] = aux2[lvl1][2*lvl2+1][0];\n\t\t\treturn;\n\t\t}\n\t\tint bb = 0, cc = 0;\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tif(aux2[lvl1][2*lvl2][i] < st + n/2) {\n\t\t\t\taux2[lvl1-1][0][bb] = aux2[lvl1][2*lvl2][i];\n\t\t\t\taux2[lvl1-1][1][bb] = aux2[lvl1][2*lvl2+1][i];\n\t\t\t\tbb++;\n\t\t\t} else {\n\t\t\t\taux2[lvl1-1][2][cc] = aux2[lvl1][2*lvl2][i];\n\t\t\t\taux2[lvl1-1][3][cc] = aux2[lvl1][2*lvl2+1][i];\n\t\t\t\tcc++;\n\t\t\t}\n\t\t}\n\t\tgen(st, lvl1-1, 0);\n\t\tgen(st+n/2, lvl1-1, 1);\n\t\tint[][] u = aux[lvl1-1][0];\n\t\tint[][] v = aux[lvl1-1][1];\n\t\tint[][] res = aux[lvl1][lvl2];\n\t\tint bs = 0, cs = 0;\n\t\tfor(int i = 0; i < n; i++) {\n\t\t\tint be = bs, ce = cs;\n\t\t\tfor(int j = i; j < n; j++) {\n\t\t\t\tif(aux2[lvl1][2*lvl2][j] < st+n/2) be++;\n\t\t\t\telse ce++;\n\t\t\t\tres[i][j+1] = add(u[bs][be],v[cs][ce]);\n\t\t\t}\n\t\t\tif(aux2[lvl1][2*lvl2][i] < st+n/2) bs++;\n\t\t\telse cs++;\n\t\t}\n\t}\n\tpublic int add(int u, int v) {\n\t\tif(u*v == 0) return u+v;\n\t\tadd1.add(u); add2.add(v);\n\t\treturn ++cnt;\n\t}\n///\n\tstatic class FastScanner {\n\t\tpublic BufferedReader reader;\n\t\tpublic StringTokenizer tokenizer;\n\t\tpublic FastScanner() {\n\t\t\treader = new BufferedReader(new InputStreamReader(System.in), 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\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\tpublic String nextLine() {\n\t\t\ttry {\n\t\t\t\treturn 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}\n}\n", "src_uid": "60cf596ad4853ebf3bbf9a96ef5d8791"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\n\n/**\n * Created by Derek on 2/10/2017.\n */\npublic class C489 {\n public static void main(String[] args) throws IOException{\n BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));\n String[] input = stdin.readLine().split(\" \");\n final int L = Integer.parseInt(input[0]);\n final int S = Integer.parseInt(input[1]);\n ArrayList<Integer> array = new ArrayList<>();\n array = findDigits(L, S, array);\n String min = \"\";\n String max = \"\";\n checkValid(L, S);\n for(int i:array){\n max+=i;\n }\n int size = array.size();\n if(size > L){\n System.out.println(\"-1 -1\");\n System.exit(0);\n }\n if(size > 1 && array.get(size-1) == 0){\n array.set(size-1,1);\n for(int i = size-2; i >= 0; i--){\n if(array.get(i)>0){\n array.set(i,array.get(i)-1);\n break;\n }\n }\n }\n for(int x = array.size()-1; x >= 0; x--){\n min+=array.get(x);\n }\n System.out.println(min + \" \" + max);\n\n\n }\n public static void checkValid(int L, int S){\n if( (S == 0 && L > 1) || (L < (S/9+(S%9 > 0 ? 1:0))) ){\n System.out.println(\"-1 -1\");\n System.exit(0);\n }\n }\n public static ArrayList<Integer> findDigits(int L , int S, ArrayList<Integer> array){\n if(L < 1){\n ArrayList<Integer> none = new ArrayList<>();\n none.add(-1);\n return(none);\n }\n else if(L == 1){\n array.add(S);\n return(array);\n }\n else if(S<10){\n for(int x = 9; x >= 0; x--){\n if(S-x >= 0 /*&& S-x >= ((L-1)/9+((L-1)%9 == 1 ? 1:0))*/){\n array.add(x);\n return(findDigits(L-1,S-x,array));\n }\n }\n }\n else{\n for(int x = 9; x >= 0; x--){\n if(S-x >= 0 /*&& S-x >= ((L-1)/9+((L-1)%9 == 1 ? 1:0))*/){\n array.add(x);\n return(findDigits(L-1,S-x,array));\n }\n }\n }\n return(array);\n }\n}\n", "src_uid": "75d062cece5a2402920d6706c655cad7"} {"source_code": "// practice with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF477A extends PrintWriter {\n\tCF477A() { super(System.out, true); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF477A o = new CF477A(); o.main(); o.flush();\n\t}\n\n\tstatic final int MD = 1000000007;\n\tvoid main() {\n\t\tlong a = sc.nextLong();\n\t\tlong b = sc.nextLong();\n\t\tprintln(((b * (b - 1) / 2) % MD) * ((b * (a * (a + 1) / 2 % MD) + a) % MD) % MD);\n\t}\n}\n", "src_uid": "cd351d1190a92d094b2d929bf1e5c44f"} {"source_code": "import java.util.Scanner;\n\npublic class InsomniaCure {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int[] dragons= new int[5];\n for(int i=0;i<5;i++)\n dragons[i] = sc.nextInt();\n boolean[] arr = new boolean[dragons[4]+1];\n for(int i=0;i<=dragons[4];i++)\n arr[i]=true;\n \n for(int i=0;i<dragons.length-1;i++){\n if(dragons[i]>dragons[4])\n break;\n if(arr[dragons[i]]== true){\n for(int j= dragons[i]; j<=dragons[4];j+=dragons[i])\n arr[j]=false;\n }\n }\n int count=0;\n for(int i=1;i<=dragons[4];i++){\n if(arr[i]==false)\n count++;\n //System.out.println(arr[i]);\n }\n System.out.println(count);\n sc.close();\n }\n}", "src_uid": "46bfdec9bfc1e91bd2f5022f3d3c8ce7"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n/**\n * @author shakhawat.hossain\n * @since 10/12/15.\n */\npublic class Schedule {\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n int n = Integer.parseInt(br.readLine().split(\" \")[0]);\n\n String[] inputPairs = br.readLine().split(\" \");\n\n int schoolPairCount = 0;\n\n int startIndex = 0;\n int lastIndex = inputPairs.length - 1;\n\n while (startIndex < inputPairs.length) {\n if (inputPairs[startIndex].equals(\"1\")) {\n break;\n }\n\n startIndex++;\n }\n\n while (lastIndex >= 0) {\n if (inputPairs[lastIndex].equals(\"1\")) {\n break;\n }\n\n lastIndex--;\n }\n\n for (int i = startIndex; i <= lastIndex; i++) {\n if (inputPairs[i].equals(\"1\")) {\n schoolPairCount++;\n } else if (inputPairs[i].equals(\"0\")) {\n\n if (i < lastIndex && inputPairs[i + 1].equals(\"0\")) {\n i++;\n while (i < lastIndex) {\n if (inputPairs[i+1].equals(\"1\")) {\n break;\n }\n i++;\n }\n } else {\n schoolPairCount++;\n }\n\n\n }\n }\n\n System.out.println(schoolPairCount);\n\n }\n}\n", "src_uid": "2896aadda9e7a317d33315f91d1ca64d"} {"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<Integer> nums = new ArrayList<Integer>();\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.size());\n\t\tif (nums.size() > 0)\n\t\t\tSystem.out.println(ans.substring(1));\n\t\t\n\t}\n\n}\n", "src_uid": "e4b3a2707ba080b93a152f4e6e983973"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.text.DecimalFormat;\nimport java.util.Scanner;\n\npublic class justForFun {\n\n\tstatic Scanner sc=new Scanner(System.in);\n\tstatic StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n\tstatic PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tlong x1,x2,y1,y2;\n\t\tx1=nextInt();\n\t\ty1=nextInt();\n\t\tx2=nextInt();\n\t\ty2=nextInt();\n\t\tlong s=((x2-x1)/2+1)*((y2-y1)/2+1)+(x2-x1)*(y2-y1)/4;\n\t\tout.println(s);\n\t\tout.flush();\n\t}\n\t\n\tstatic String next() throws IOException{\n\t\tin.nextToken();\n\t\treturn in.sval;\n\t}\n\n\tstatic int nextInt() throws IOException {\n\t\tin.nextToken();\n\t\treturn (int) in.nval;\n\t}\n\n\tstatic double nextDouble() throws IOException {\n\t\tin.nextToken();\n\t\treturn in.nval;\n\t}\n\n\tstatic long nextLong() throws IOException {\n\t\tin.nextToken();\n\t\treturn (long) in.nval;\n\t}\n\t\n\t\n}", "src_uid": "00cffd273df24d1676acbbfd9a39630d"} {"source_code": "import java.util.ArrayList;\nimport java.util.Scanner;\n\npublic class CF8E {\n static long[] rev;\n static long[] inv;\n static long[] two;\n\n private static void init(int n) {\n rev = new long[n + 1];\n inv = new long[n + 1];\n two = new long[n + 1];\n rev[0] = 1;\n rev[1] = 2;\n inv[0] = 1;\n inv[1] = 1;\n two[0] = 1;\n two[1] = 2;\n for (int i = 2; i <= n; i++) {\n two[i] = two[i - 1] * 2;\n rev[i] = rev[i - 2] * 2 + two[i - 2];\n inv[i] = inv[i - 2] * 2 + two[i - 2];\n }\n }\n\n private static long[] toNumber(ArrayList<Integer> prefix, int n) {\n int l = Math.min(prefix.size(), n - prefix.size());\n Integer[] list = new Integer[l];\n prefix.toArray(list);\n long[] res = new long[2];\n for (int i = 0; i < l; i++) {\n res[0] *= 2;\n res[0] += prefix.get(i);\n res[1] *= 2;\n res[1] += (1 - prefix.get(i));\n }\n return res;\n }\n\n private static int check(ArrayList<Integer> prefix, int l) {\n int res = 0;\n int i;\n for (i = l; i < prefix.size(); i++) {\n if (prefix.get(i) < prefix.get(prefix.size() - 1 - i + l)) {\n res++;\n break;\n } else if (prefix.get(i) > prefix.get(prefix.size() - 1 - i + l)) {\n break;\n }\n }\n if (i >= prefix.size()) {\n res++;\n }\n for (i = l; i < prefix.size(); i++) {\n if (prefix.get(i) < 1 - prefix.get(prefix.size() - 1 - i + l)) {\n res++;\n break;\n } else if (prefix.get(i) > 1 - prefix.get(prefix.size() - 1 - i + l)) {\n break;\n }\n }\n if (i >= prefix.size()) {\n res++;\n }\n return res;\n }\n\n private static long calc(ArrayList<Integer> prefix, int n) {\n int halfLen = n / 2;\n long[] num = toNumber(prefix, n);\n if (prefix.size() <= halfLen) {\n return (num[1] - num[0] - 1) * two[n - 2 * prefix.size()] + rev[n - 2 * prefix.size()]\n + inv[n - 2 * prefix.size()];\n } else {\n int l = n - prefix.size();\n return num[1] - num[0] - 1 + check(prefix, l);\n }\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n long k = sc.nextLong();\n sc.close();\n init(n);\n ArrayList<Integer> res = new ArrayList<>();\n for (int i = 0; i < n; i++) {\n res.add(0);\n long p = calc(res, n);\n if (p <= k && i == 0) {\n break;\n } else if (p <= k) {\n res.set(i, 1);\n k -= p;\n }\n }\n if (res.size() < n) {\n System.out.println(-1);\n } else {\n for (int i = 0; i < n; i++) {\n System.out.print(res.get(i));\n }\n }\n }\n}\n", "src_uid": "0a4a418dafaee71f1b31c928fc2ad24a"} {"source_code": "import java.util.*;\n\n public class Test {\n \tstatic int f = 1;\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n \tlong l = input.nextLong();\n \tlong r = input.nextLong();\n\n \t\tSystem.out.println(lucky(l,r));\n }\n \n public static long lucky(long l,long r){\n \tlong sum = 0;\n \tfor(long i = l ; i <= r ; i++){\n \t\tlong sk = numer(f,i);\n \t\t//long sk2 = numer(f+1,i);\n \t\tif(i <= 4){\n \t\t\tif(r <= 4){\n \t\t\t\tsum += (r-i+1)*4;\n \t\t\t\treturn sum;\n \t\t\t}else{\n \t\t\t\tsum += (4-i+1)*4;\n \t\t\t}\n \t\t\ti = 4;\n \t\t}else if(sk > r){\n \t\t\tsum += sk*(r-i+1);\n \t\ti = r;\n \t\t}else{\n \t\t\tsum += sk*(sk-i+1);\n \t\ti = sk;\n \t\t}\n \t}\n \treturn sum;\n }\n \n public static long numer(int l,long k){\n \tint sum = l;\n \tboolean isnt = false;\n \twhile(sum < 100000){\n \t\tString bin = numberToString(sum);\n \t\tString snum = new String();\n \t\tfor(int i = 0 ; i < bin.length() ; i++){\n \t\t\tif(bin.charAt(i) == '1'){\n \t\t\t\tsnum += \"4\";\n \t\t\t}else if(bin.charAt(i) == '2'){\n \t\t\t\tsnum += \"7\";\n \t\t\t}else{\n \t\t\t\tisnt = true;\n \t\t\t\tbreak;\n \t\t\t}\n \t\t}\n \t\tif(isnt == false){\n \t\t\tlong snumber = Long.parseLong(snum);\n \t\tif(k <= snumber){\n \t\t\tf = sum;\n \t\t\treturn snumber;\n \t\t}\n \t\t}\n \t\t\tsum++;\n \t\t\tisnt = false;\n \t}\n \treturn -1;\n } \t\n \n public static String numberToString(long n){ return n==0 ? \"\" : numberToString(n/3) + (n%3);}\n }", "src_uid": "8a45fe8956d3ac9d501f4a13b55638dd"} {"source_code": "import java.util.*;\n\npublic class cf78c {\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\tboolean winner = false;\n\t\tfor(int i=1; i*i<=m; i++)\n\t\t\tif(m%i==0)\n\t\t\t\tif((i>=k && m/i>1) || (m/i>=k && i>1))\n\t\t\t\t\twinner = true;\n\t\tif(n%2==0) winner = false;\n\t\tSystem.out.println(winner?\"Timur\":\"Marsel\");\n\t}\n}\n", "src_uid": "4a3767011ddac874efa021fff7c94432"} {"source_code": "import java.util.*;\n\npublic class Main {\n\tstatic int max(int x,int y) {\n\t\treturn x<y?y:x;\n\t}\n\tpublic static void main(String[] args) {\n\t\tScanner in=new Scanner(System.in);\n\t\tint n,k;\n\t\tn=in.nextInt();\n\t\tk=in.nextInt();\n\t\t\n\t\tString ss=in.next(),tt=in.next();\n\t\t\n\t\tchar[] s=new char[300],t=tt.toCharArray();\n\t\tfor(int i=0;i<n;++i)s[i+1]=ss.charAt(i);\n\n\t\tint[][][] dp=new int[300][300][300];\n\t\tfor(int i=0;i<300;++i)\n\t\t\tfor(int j=0;j<300;++j)\n\t\t\t\tArrays.fill(dp[i][j], -10000000);\n\t\tdp[0][0][0]=0;\n\t\tfor(int i=0;i<n;++i)\n\t\t\tfor(int j=0;j<=k;++j) \n\t\t\t\tfor(int cnt=0;cnt<=i;++cnt) {\n\t\t\t\t\tdp[i+1][j+1][cnt+1]=max(dp[i+1][j+1][cnt+1],dp[i][j][cnt]+(t[1]==t[0]?cnt:0));\n\t\t\t\t\tdp[i+1][j+1][cnt+(t[0]==t[1]?1:0)]=max(dp[i+1][j+1][cnt+(t[0]==t[1]?1:0)],dp[i][j][cnt]+cnt);\n\t\t\t\t\tdp[i+1][j][cnt+(s[i+1]==t[0]?1:0)]=max(dp[i+1][j][cnt+(s[i+1]==t[0]?1:0)],dp[i][j][cnt]+(s[i+1]==t[1]?cnt:0));\n\t\t\t\t}\n\t\tint ans=0;\n\t\tfor(int i=0;i<=k;++i)\n\t\t\tfor(int cnt=0;cnt<=n;++cnt)\n\t\t\t\tans=max(ans,dp[n][i][cnt]);\n\t\tSystem.out.printf(\"%d\",ans);\n\t\tin.close();\n\t}\n}\n", "src_uid": "9c700390ac13942cbde7c3428965b18a"} {"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}", "src_uid": "0aaf5fefed8b572b59bfce73dbbcde66"} {"source_code": "import java.awt.Point;\nimport java.io.BufferedReader;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class Contest {\n\tprivate static PrintWriter out = new PrintWriter(System.out);\n\n\tprivate static String helper(long n, char s) {\n\t\tStringBuilder str = new StringBuilder(\"\");\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tstr.append(s);\n\t\t}\n\t\treturn str.toString();\n\t}\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\n\t\t\tlong k = sc.nextLong();\n\t\t\tString str = \"codeforces\";\n\t\t\tlong[] v = new long[10];\n\t\t\t\n\t\t\tfor(int i = 0;true;i++) {\n\t\t\t\tint j = i % 10;\n\t\t\t\tv[j]++;\n\t\t\t\tlong count = 1;\n\t\t\t\tfor(long x : v) {\n\t\t\t\t\tcount *= x;\n\t\t\t\t}\n\t\t\t\tif(count >= k)\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tfor (int i = 0; i < v.length; i++) {\n\t\t\t\tout.print(helper(v[i], str.charAt(i)));\n\t\t\t}\n\t\t\t \n\t\t\tout.flush();\n\t\t\n\n\t}\n\n\tprivate static long sum(ArrayList<Long> r) {\n\t\tlong s = 0;\n\t\tfor (int i = 0; i < Math.min(10, r.size()); i++) {\n\t\t\ts += r.get(r.size() - 1 - i);\n\t\t}\n\t\t// System.out.println(\"s: \" + s);\n\t\tlong p = 1;\n\t\tfor (int i = 9; i < r.size(); i++)\n\t\t\tp *= r.get(r.size() - 1 - i);\n\t\tif (r.size() > 10)\n\t\t\treturn s - r.get(r.size() - 9 - 1) + p;\n\n\t\treturn s;\n\t}\n\n\tprivate static ArrayList<Long> factors(long k) {\n\t\tArrayList<Long> res = new ArrayList<>();\n\n\t\tfor (long i = 2; i * i <= k; i++) {\n\t\t\twhile (k % i == 0) {\n\t\t\t\tres.add(i);\n\t\t\t\tk /= i;\n\t\t\t}\n\t\t}\n\t\tif (k > 1)\n\t\t\tres.add(k);\n\t\treturn res;\n\t}\n\n\tprivate static class Scanner {\n\t\tpublic BufferedReader reader;\n\t\tpublic StringTokenizer st;\n\n\t\tpublic Scanner(InputStream stream) {\n\t\t\treader = new BufferedReader(new InputStreamReader(stream));\n\t\t\tst = null;\n\t\t}\n\n\t\tpublic String next() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tString line = reader.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} 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 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\n}\n", "src_uid": "8001a7570766cadcc538217e941b3031"} {"source_code": "import java.util.Scanner;\nimport java.util.Stack;\n\npublic class Code_For_1 {\n\t\n\tpublic static long findOnes(long num, long left, long right, long l, long r)\n\t{\n\t\tif(l>right || r<left || num==0)\n\t\t{\n\t\t\treturn 0;\n\t\t}\n\t\t\n\t\tif(num==1)\n\t\t{\n\t\t\treturn 1;\n\t\t}\n\t\t\n\t\tlong mid=left+countDigit(num/2);\n\t\tlong ones=findOnes(num/2,mid+1,right,l,r)+findOnes(num%2,mid,mid,l,r)+findOnes(num/2,left,mid-1,l,r);\n\t\t\n\t\treturn ones;\n\t\t\n\t}\n\t\n\tpublic static long countDigit(long num)\n\t{\n\t\tif(num<=1)\n\t\t{\n\t\t\treturn num;\n\t\t}\n\t\t\n\t\tlong digit=countDigit(num/2)*2+1;\n\t\treturn digit;\n\t}\n\t\n\t/*public static void populate(Stack<Integer> series, long num)\n\t{\n\t\tif(num<2)\n\t\t{\n\t\t\tseries.push((int) num);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tpopulate(series,num/2);\n\t\tseries.push((int) (num%2));\n\t\tpopulate(series,num/2);\n\t}*/\n\t\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner in=new Scanner(System.in);\n\t\tlong num=in.nextLong();\n\t\tlong l=in.nextLong();\n\t\tlong r=in.nextLong();\n\t\t\n\t\t/*Stack<Integer> series=new Stack<>();\n\t\t\n\t\tpopulate(series,num);\n\n\t\tint count=0;\n\t\t\n\t\tfor(int i=(int) (l-1);i<r;i++)\n\t\t{\n\t\t\tif(series.get(i)==1)\n\t\t\t{\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\n\t\tSystem.out.println(count);\n\t\t*/\n\t\t\n\t\tlong right=countDigit(num);\n\t\tlong left=1;\n\t\tlong result=findOnes(num,left,right,l,r);\n\t\t\n\t\tSystem.out.println(result);\n\t\t\n\t}\n\n}\n", "src_uid": "3ac61b1f8deee7911b1055c243f5eb6a"} {"source_code": "import java.lang.*;\nimport java.math.*;\nimport java.util.*;\nimport java.io.*;\n\npublic class Main {\n\n void solve() {\n int p=ni(),s=ni(),r=ni();\n precompute(100000);\n long ans=0;\n for(int i=r;i<=s;i++){\n for(int j=1;j<=p && i*1L*j<=s;j++){\n long d=mul(C[p-1][j-1],mul(inv[j],go(p-j,s-i*j,i)));\n // pw.println(C[p-1][j-1]+\" \"+inv[j]+\" \"+go(p-j,s-i*j,i));\n ans=add(ans,d);\n }\n }\n ans=mul(ans,fact[p-1]);\n ans=mul(ans,fact[s-r]);\n ans=mul(ans,modInverse(fact[s-r+p-1],M));\n pw.println(ans);\n\n\n\n\n\n }\n\n long go(int n,int m,int s){\n if(n==0) {\n if(m>0) return 0;\n else return 1;\n }\n if((s-1)*1L*n<m) return 0;\n\n long ans=0;\n for(int i=0;i<=n && s*1L*i<=m;i++){\n if(i%2==0)\n ans=add(ans,mul(C[n][i],C[m-s*i+n-1][n-1]));\n else ans=sub(ans,mul(C[n][i],C[m-s*i+n-1][n-1]));\n }\n return ans;\n }\n long fact[];\n int C[][];\n long inv[];\n void precompute(int n){\n C=new int[6001][6001];\n for(int i=0;i<=6000;i++) C[i][0]=1;\n for(int i=1;i<=6000;i++){\n for(int k=1;k<=i;k++) C[i][k]=(int)add(C[i-1][k-1],C[i-1][k]);\n }\n inv=new long[n+1];\n fact=new long[n+1];\n fact[0]=1;\n for(int i=1;i<=n;i++) fact[i]=mul(fact[i-1],i);\n inv[n]=modInverse(fact[n],M);\n for(int i=n-1;i>=0;i--) inv[i]=mul(inv[i+1],i+1);\n inv[1]=1;\n for(int i=2;i<=n;i++){\n inv[i]=mul(inv[i],fact[i-1]);\n }\n\n\n\n }\n\n\n long modpow(long a, long b)\n {\n long r=1;\n while(b>0)\n {\n if((b&1)>0) r=mul(r,a);\n a=mul(a,a);\n b>>=1;\n }\n return r;\n }\n long mul(long x,long y){\n x*=y;\n if(x>=M) x%=M;\n return x;\n }\n long add(long x,long y){\n x+=y;\n if(x>=M) x-=M;\n if(x<0) x+=M;\n return x;\n }\n long sub(long x,long y){\n x-=y;\n if(x<0) x+=M;\n return x;\n }\n long modInverse(long A, long M)\n {\n\n return modpow(A,M-2);\n }\n\n\n\n long M = 998244353;\n InputStream is;\n PrintWriter pw;\n String INPUT = \"\";\n\n void run() throws Exception {\n is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n pw = new PrintWriter(System.out);\n long s = System.currentTimeMillis();\n solve();\n pw.flush();\n if (!INPUT.isEmpty()) tr(System.currentTimeMillis() - s + \"ms\");\n\n }\n\n public static void main(String[] args) throws Exception {\n new Main().run();\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 String ns() {\n int b = skip();\n StringBuilder sb = new StringBuilder();\n while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')\n sb.appendCodePoint(b);\n b = readByte();\n }\n return sb.toString();\n }\n\n private char[] ns(int n) {\n char[] buf = new char[n];\n int b = skip(), p = 0;\n while (p < n && !(isSpaceChar(b))) {\n buf[p++] = (char) b;\n b = readByte();\n }\n return n == p ? buf : Arrays.copyOf(buf, p);\n }\n\n private char[][] nm(int n, int m) {\n char[][] map = new char[n][];\n for (int i = 0; i < n; i++) map[i] = ns(m);\n return map;\n }\n\n private int[] na(int n) {\n int[] a = new int[n];\n for (int i = 0; i < n; i++) a[i] = ni();\n return a;\n }\n\n private int ni() {\n int num = 0, b;\n boolean minus = false;\n while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n\n while (true) {\n if (b >= '0' && b <= '9') {\n num = num * 10 + (b - '0');\n } else {\n return minus ? -num : num;\n }\n b = readByte();\n }\n }\n\n private long nl() {\n long num = 0;\n int b;\n boolean minus = false;\n while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n\n while (true) {\n if (b >= '0' && b <= '9') {\n num = num * 10 + (b - '0');\n } else {\n return minus ? -num : num;\n }\n b = readByte();\n }\n }\n\n private boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\n private void tr(Object... o) {\n if (INPUT.length() > 0) System.out.println(Arrays.deepToString(o));\n }\n\n}", "src_uid": "609195ef4a970c62a8210dafe118580e"} {"source_code": "import java.util.Scanner;\n\n/**\n * Created by WiNDWAY on 6/9/2017.\n */\npublic class Codeforces_round_416_div_2_VladiskAndCourtesy {\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n int a = input.nextInt();\n int b = input.nextInt();\n int give = 1;\n while (a >= 0 && b >= 0) {\n if (give % 2 == 1) {\n if (a < give) {\n System.out.println(\"Vladik\");\n System.exit(0);\n }\n a -= give;\n } else {\n if (b < give) {\n System.out.println(\"Valera\");\n System.exit(0);\n }\n b -= give;\n }\n give++;\n }\n }\n}\n", "src_uid": "87e37a82be7e39e433060fd8cdb03270"} {"source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.text.*;\n\npublic class cf281b {\n\n static BufferedReader br;\n static Scanner sc;\n static PrintWriter out;\n\n public static void initA() {\n try {\n br = new BufferedReader(new InputStreamReader(System.in));\n //br = new BufferedReader(new FileReader(\"input.txt\"));\n sc = new Scanner(System.in);\n //out = new PrintWriter(\"output.txt\");\n out = new PrintWriter(System.out);\n } catch (Exception e) {\n }\n }\n\n public static void initB() {\n try {\n\n br = new BufferedReader(new FileReader(\"input.txt\"));\n sc = new Scanner(new FileReader(\"input.txt\"));\n out = new PrintWriter(\"output.txt\");\n\n } catch (Exception e) {\n }\n }\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 Long[] getLongArr() {\n try {\n StringTokenizer temp = new StringTokenizer(br.readLine());\n int n = temp.countTokens();\n Long temp2[] = new Long[n];\n for (int i = 0; i < n; i++) {\n temp2[i] = Long.parseLong(temp.nextToken());\n }\n return temp2;\n } catch (Exception e) {\n }\n return null;\n }\n\n public static String[] getStringArr() {\n try {\n StringTokenizer temp = new StringTokenizer(br.readLine());\n int n = temp.countTokens();\n String temp2[] = new String[n];\n for (int i = 0; i < n; i++) {\n temp2[i] = (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 void print(String s, Object... a) {\n out.printf(s, 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 void main(String[] ar) {\n initA();\n solve();\n out.flush();\n }\n\n public static void solve() {\n Long xxx[] = getLongArr();\n\n long x = xxx[0];\n long y = xxx[1];\n long n = xxx[2];\n\n\n if (y == 1) {\n print(\"%d/%d\\n\", x, y);\n return;\n }\n\n if (n == 1) {\n print(\"%d/%d\\n\", x / y, 1);\n\n return;\n }\n\n TreeMap<bil, bil> hehe = new TreeMap<bil, bil>(new Comparator<bil>() {\n\n @Override\n public int compare(bil o1, bil o2) {\n Long a = (o1.x * o2.y) ;\n Long b = (o2.x * o1.y);\n return a.compareTo(b);\n }\n });\n\n for (long i = n; i >= 1; i--) {\n\n long tete = i * x;\n long rateOfError = (tete % y);\n long rateOfError2 = (y - rateOfError);\n //print(\"tete=%d rateError1=%d\\n\",tete, tete%y);\n if (rateOfError <= rateOfError2) {\n //print(\"rateError=%d/%d %d/%d\\n\", rateOfError, i*y, (tete - rateOfError) / y, i);\n hehe.put(new bil(rateOfError, i*y), new bil((tete - rateOfError) / y, i));\n } else {\n //print(\"rateError2=%d/%d %d/%d\\n\", rateOfError2, i*y, (tete + rateOfError2) / y, i);\n hehe.put(new bil(rateOfError2, i*y), new bil((tete + rateOfError2) / y, i));\n }\n //print(i+\":\\t\"+rateOfError+\" \"+rateOfError2);\n\n }\n\n\n bil ou = hehe.get(hehe.firstKey());\n print(\"%d/%d\\n\", ou.x, ou.y);\n\n }\n\n private static class bil {\n\n long x, y;\n\n bil(long x, long y) {\n this.x = x;\n this.y = y;\n }\n }\n}", "src_uid": "827bc6f120aff6a6f04271bc84e863ee"} {"source_code": "import java .util.Scanner;\npublic class CodeForces10 {\npublic static void main(String[] args) {\n Scanner sc=new Scanner(System.in);\n String capital=sc.next();\n \n /*if(capital.charAt(0)>='A'&&capital.charAt(0)<='Z'){\n System.out.println(capital);\n }else {*/\n capital=(capital.charAt(0)+\"\").toUpperCase()+capital.substring(1);\n System.out.println(capital);\n }\n }\n \n", "src_uid": "29e0fc0c5c0e136ac8e58011c91397e4"} {"source_code": "import java.util.*;\nimport java.io.*;\npublic class Solution{\n static Scanner sc;\n static PrintWriter pw;\n \n public static void main(String args[]){\n sc = new Scanner(System.in);\n pw = new PrintWriter(System.out);\n \n int t = sc.nextInt();\n while(t-->0)\n solve();\n \n pw.flush();\n pw.close();\n }\n public static void solve(){\n long a = sc.nextLong(), b = sc.nextLong(), m = sc.nextLong();\n \n if(a == b){\n pw.println(+1+\" \"+Long.toString(a));\n return;\n }\n \n for(int i=1; i<=60; i++){\n long low = (long)Math.pow(2, i-1)*(a+1), high = (long)Math.pow(2, i-1)*(a+m);\n \n if(low <= b && b<= high){\n \n if(i == 1){\n pw.println(+2+\" \"+a+\" \"+b);\n return;\n }\n \n long k = b - (long)Math.pow(2, i-1)*(a+1);\n //System.out.println(+k+\" \"+i);\n \n long arr[] = new long[i+1], sum[] = new long[i+1], step[] = new long[i], fact[] = new long[i];\n arr[0] = a;\n \n fact[i-1] = 1;\n step[i-1] = 1;\n long q = 1;\n for(int j=i-2; j>=0; j--, q=q*2){\n step[j] = 1;\n fact[j] = q;\n }\n \n for(int j=0; j<i; j++){\n long p = Math.min(k/fact[j], m-1);\n step[j] += p;\n k -= fact[j]*p;\n }\n \n sum[0] = arr[0];\n for(int j=1; j<=i; j++){\n //System.out.println(+step[j-1]);\n arr[j] = sum[j-1] + step[j-1];\n sum[j] = sum[j-1] + arr[j];\n }\n \n pw.print(+(i+1)+\" \");\n for(long u: arr)\n pw.print(+u+\" \");\n pw.println();\n return;\n }\n else if(low > b)\n break;\n }\n pw.println(-1);\n }\n}", "src_uid": "c9d646762e2e78064bc0670ec7c173c6"} {"source_code": "import java.util.*;\npublic class Smallestnumber {\n\tstatic long currmin = Long.MAX_VALUE;\n\t List<Long> func2(List<Long> numbers,int op, int i,int j)\n\t{\n\t\tlong sum= 0;\n\t\tList<Long> newwNums = new ArrayList<>();\n\t\t\n\t\tif(op=='+')\n\t\t{\n\t\t\tsum = numbers.get(i)+numbers.get(j);\n\t\t}\n\t\telse\n\t\tif(op=='*')\n\t\t{\n\t\t\tsum = numbers.get(i)*numbers.get(j);\n\t\t}\n\t\t\n\t\tnewwNums.add(sum);\n\t\tfor(int p=0;p<numbers.size();p++)\n\t\t{\n\t\t\tif(p!=i && p!=j)\n\t\t\t{\n\t\t\t\tnewwNums.add(numbers.get(p));\n\t\t\t}\n\t\t}\n\t\treturn newwNums;\n\t}\n\n\tvoid func1(List<Long> numbers, char[] op,int index)\n\t{\n\t\tif(index==3)\n\t\t{\n\t\t\tcurrmin = Math.min(currmin, numbers.get(0));\n\t\t\treturn;\n\t\t}\n\t\tfor(int i=0;i<numbers.size();i++)\n\t\t{\n\t\t\tfor(int j=i+1;j<numbers.size();j++)\n\t\t\t{\n\t\t\t\tList<Long> newNums = func2(numbers,op[index],i,j);\n\t\t\t\tfunc1(newNums,op,index+1);\n\t\t\t}\n\t\t}\n\t}\n\t\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\tList<Long> numbers = new ArrayList<>();\n\t\tfor(int i=0;i<4;i++)\n\t\t{\n\t\t\tnumbers.add(scan.nextLong());\n\t\t}\n\t\tchar[] op = new char[3];\n\t\tfor(int i=0;i<3;i++)\n\t\t{\n\t\t\top[i] = scan.next().charAt(0);\n\t\t}\n\t\tSmallestnumber s = new Smallestnumber();\n\t\tint index=0;\n\t\ts.func1(numbers,op,index);\n\t\tSystem.out.println(currmin);\n\t}\n\n}\n\n", "src_uid": "7a66fae63d9b27e444d84447012e484c"} {"source_code": "import java.util.*;\npublic class SmallerArtemkaAndSurprise\n{\npublic static void main(String[] args)\n{\nScanner sc = new Scanner(System.in);\nint n = sc.nextInt();\nSystem.out.println(((n/3)*2) + (n % 3 != 0 ? 1 : 0));\n}\n}", "src_uid": "a993069e35b35ae158d35d6fe166aaef"} {"source_code": "import java.util.*;\n\npublic class Great {\n public static void main(String []av) {\n Scanner s = new Scanner(System.in);\n String L = s.nextLine();\n String R = s.nextLine();\n String t1wins = \"TEAM 1 WINS\";\n String t2wins = \"TEAM 2 WINS\";\n String tie = \"TIE\";\n int s1 = 0;\n int s2 = 0;\n\n for (int i = 0; i < L.length() - 1; i+=2) {\n String t1 = L.substring(i, i+2);\n String t2 = R.substring(i, i+2);\n if (t1.equals(t2)) {\n s1++;\n s2++;\n } else\n if (\"8<\".equals(t1) && \"[]\".equals(t2)) {\n s1++;\n } else\n if (\"[]\".equals(t1) && \"()\".equals(t2)) {\n s1++;\n } else\n if (\"()\".equals(t1) && \"8<\".equals(t2)) {\n s1++;\n } else\n s2++;\n } \n if (s1 == s2)\n System.out.println(tie);\n else\n if (s1 < s2)\n System.out.println(t2wins);\n else\n System.out.println(t1wins);\n }\n}", "src_uid": "bdf2e78c47d078b4ba61741b6fbb23cf"} {"source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Main {\n\n \n public static void main(String[] args) throws IOException {\n BufferedReader b= new BufferedReader(new InputStreamReader(System.in));\n String s1=b.readLine();\n String s2=b.readLine();\n StringBuilder sb= new StringBuilder(s1);\n sb.reverse();\n if(sb.toString().equalsIgnoreCase(s2))\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n }}", "src_uid": "35a4be326690b58bf9add547fb63a5a5"} {"source_code": "import java.util.Arrays;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.Random;\nimport java.util.HashMap;\nimport java.io.BufferedReader;\nimport java.util.Map;\nimport java.io.PrintStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.util.StringTokenizer;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n static final int MODULO = 10007;\n int magic;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n String s = in.next();\n int n = in.nextInt() + s.length();\n int[][][] ways = new int[s.length()][s.length() + 1][s.length() / 2 + 2];\n int[][] waysAll = new int[3][s.length() / 2 + 2];\n ways[0][s.length()][0] = 1;\n for (int start = 0; start < s.length(); ++start)\n for (int len = s.length() - start; len >= 1; --len) {\n int[] src = ways[start][len];\n if (s.charAt(start) == s.charAt(start + len - 1)) {\n int nlen = len - 2;\n int[] dest;\n if (nlen <= 0) {\n dest = waysAll[len];\n } else {\n dest = ways[start + 1][nlen];\n }\n for (int doubles = 0; doubles < src.length; ++doubles) if (src[doubles] != 0) {\n dest[doubles + 1] = (dest[doubles + 1] + src[doubles]) % MODULO;\n }\n } else {\n int nlen = len - 1;\n int[] dest = ways[start][nlen];\n for (int doubles = 0; doubles < src.length; ++doubles) if (src[doubles] != 0) {\n dest[doubles] = (dest[doubles] + src[doubles]) % MODULO;\n }\n dest = ways[start + 1][nlen];\n for (int doubles = 0; doubles < src.length; ++doubles) if (src[doubles] != 0) {\n dest[doubles] = (dest[doubles] + src[doubles]) % MODULO;\n }\n }\n }\n int steps = n / 2;\n int ret = 0;\n int maxSingles = s.length();\n int maxDoubles = waysAll[1].length - 1;\n int size = maxSingles + maxDoubles + maxDoubles;\n magic = maxDoubles + maxSingles;\n int[][] m = new int[size][size];\n for (int i = 0; i < maxSingles + maxDoubles + maxDoubles; ++i) {\n if (i + 1 < maxSingles + maxDoubles) m[i + 1][i] = 1;\n if (i >= maxSingles && i < maxSingles + maxDoubles) m[i + maxDoubles][i] = 1;\n m[i][i] = (i < maxSingles ? 24 : (i < maxSingles + maxDoubles ? 25 : 26));\n }\n m = pow(m, steps);\n for (int last = 1; last <= 2; ++last) {\n for (int doubles = 0; doubles < waysAll[last].length; ++doubles) {\n int w = waysAll[last][doubles];\n if (w != 0) {\n int singles = s.length() + (last == 1 ? 1 : 0) - 2 * doubles;\n if (n % 2 == 0) {\n ret = (int) ((ret + (long) w * m[maxSingles + maxDoubles + doubles - 1][maxSingles - singles]) % MODULO);\n } else {\n ret = (int) ((ret + (long) w * m[maxSingles + maxDoubles + doubles - 1][maxSingles - singles] * 26) % MODULO);\n if (last == 1) {\n ret = (int) ((ret + (long) w * m[maxSingles + doubles - 1][maxSingles - singles]) % MODULO);\n }\n }\n }\n }\n }\n out.println(ret);\n }\n\n private int[][] pow(int[][] m, int k) {\n int[][] res = new int[m.length][m.length];\n for (int i = 0; i < m.length; ++i) res[i][i] = 1;\n while (k > 0) {\n System.err.println(k + \" \" + m.length);\n if (k % 2 != 0) {\n res = mul(m, res);\n }\n k /= 2;\n m = mul(m, m);\n }\n return res;\n }\n\n private final int BIG = Integer.MAX_VALUE - Integer.MAX_VALUE % MODULO;\n\n private int[][] mul(int[][] a, int[][] b) {\n int n = a.length;\n int[][] c = new int[n][n];\n for (int i = 0; i < c.length; ++i) {\n for (int j = 0; j < magic; ++j) {\n int s = 0;\n for (int k = 0; k < magic; ++k) {\n s += a[i][k] * b[k][j];\n if (s < 0)\n s -= BIG;\n }\n if (i >= magic) {\n int k = i;\n s += a[i][k] * b[k][j];\n if (s < 0)\n s -= BIG;\n }\n c[i][j] = s % MODULO;\n }\n if (i >= magic) {\n int j = i;\n int s = 0;\n for (int k = 0; k < magic; ++k) {\n s += a[i][k] * b[k][j];\n if (s < 0)\n s -= BIG;\n }\n if (i >= magic) {\n int k = i;\n s += a[i][k] * b[k][j];\n if (s < 0)\n s -= BIG;\n }\n c[i][j] = s % MODULO;\n }\n }\n return c;\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", "src_uid": "2ae6f17e0dd0bc93090d939f4f49d7a8"} {"source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.FilterInputStream;\nimport java.io.BufferedInputStream;\nimport java.io.InputStream;\n\n/**\n * @author khokharnikunj8\n */\n\npublic class Main {\n public static void main(String[] args) {\n new Thread(null, new Runnable() {\n public void run() {\n new Main().solve();\n }\n }, \"1\", 1 << 26).start();\n }\n\n void solve() {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n ScanReader in = new ScanReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n D2WrongAnswerOnTest233HardVersion solver = new D2WrongAnswerOnTest233HardVersion();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class D2WrongAnswerOnTest233HardVersion {\n long mod = 998244353;\n long[] factorial;\n\n public long nCr(int n, int r) {\n return factorial[n] * (CodeHash.modInverse(factorial[n - r], mod) * CodeHash.modInverse(factorial[r], mod) % mod) % mod;\n }\n\n public void solve(int testNumber, ScanReader in, PrintWriter out) {\n int n = in.scanInt();\n long k = in.scanInt();\n long ans = 0;\n int[] ar = new int[n];\n for (int i = 0; i < n; i++) {\n ar[i] = in.scanInt();\n }\n factorial = new long[n + 1];\n factorial[0] = 1;\n for (int i = 1; i <= n; i++) factorial[i] = (factorial[i - 1] * i) % mod;\n int different = 0;\n for (int i = 0; i < n; i++) {\n if (ar[i] != ar[(i + 1) % n]) different++;\n }\n for (int i = 0; i <= different; i++) {\n long ways = nCr(different, i);\n int remaining = different - i;\n if (remaining % 2 == 0) {\n ways = (ways * ((CodeHash.pow(2, remaining, mod) - nCr(remaining, remaining / 2) + mod) % mod)) % mod;\n ways = (ways * CodeHash.modInverse(2, mod)) % mod;\n ways = (ways * CodeHash.pow(k - 2, i, mod)) % mod;\n } else {\n ways = (ways * CodeHash.pow(2, remaining - 1, mod)) % mod;\n ways = (ways * CodeHash.pow(k - 2, i, mod)) % mod;\n }\n ans = (ans + ways) % mod;\n }\n out.println((ans * CodeHash.pow(k, n - different, mod)) % mod);\n\n }\n\n }\n\n static class ScanReader {\n private byte[] buf = new byte[4 * 1024];\n private int index;\n private BufferedInputStream in;\n private int total;\n\n public ScanReader(InputStream inputStream) {\n in = new BufferedInputStream(inputStream);\n }\n\n private int scan() {\n if (index >= total) {\n index = 0;\n try {\n total = in.read(buf);\n } catch (Exception e) {\n e.printStackTrace();\n }\n if (total <= 0) return -1;\n }\n return buf[index++];\n }\n\n public int scanInt() {\n int integer = 0;\n int n = scan();\n while (isWhiteSpace(n)) n = scan();\n int neg = 1;\n if (n == '-') {\n neg = -1;\n n = scan();\n }\n while (!isWhiteSpace(n)) {\n if (n >= '0' && n <= '9') {\n integer *= 10;\n integer += n - '0';\n n = scan();\n }\n }\n return neg * integer;\n }\n\n private boolean isWhiteSpace(int n) {\n if (n == ' ' || n == '\\n' || n == '\\r' || n == '\\t' || n == -1) return true;\n else return false;\n }\n\n }\n\n static class CodeHash {\n public static long[] euclidExtended(long a, long b) {\n if (b == 0) {\n long ar[] = new long[]{1, 0};\n return ar;\n }\n long ar[] = euclidExtended(b, a % b);\n long temp = ar[0];\n ar[0] = ar[1];\n ar[1] = temp - (a / b) * ar[1];\n return ar;\n }\n\n public static long modInverse(long a, long m) {\n long ar[] = euclidExtended(a, m);\n return ((ar[0] % m) + m) % m;\n }\n\n public static long pow(long a, long b, long m) {\n long res = 1;\n a %= m;\n while (b > 0) {\n if ((b & 1) == 1) res = (res * a) % m;\n a = (a * a) % m;\n b >>= 1;\n }\n return res;\n }\n\n }\n}\n\n", "src_uid": "63c4006a0a6284f9825aaabfc4c28fd1"} {"source_code": "/**\n *\n * @author s3ood\n */\nimport java.io.IOException;\nimport java.util.Scanner;\n//import java.util.Scanner;\n\n\npublic class Restoring_Password {\n public static void main(String[] args) throws IOException\n {\n Scanner sc = new Scanner(System.in);\n String [] a = new String[10];\n String str = sc.next();\n String out = \"\";\n for (int i = 0 ; i<10 ; i++)\n {\n a[i]=\"\"+i+sc.next();\n }\n for (int j=0 ; j<=70 ; j=j+10)\n {\n if (j==70)\n out = out+match(str.substring(j),a);\n else\n out = out+match(str.substring(j, j+10),a);\n }\n System.out.println (out);\n }\n\n public static char match(String sd , String [] b)\n {\n char c=' ' ;\n for (int u = 0 ; u<b.length ;u++)\n {\n if (sd.matches(b[u].substring(1)))\n c=b[u].charAt(0);\n }\n return c ;\n\n }\n\n}", "src_uid": "0f4f7ca388dd1b2192436c67f9ac74d9"} {"source_code": "import java.util.Scanner;\n\npublic class B513 {\n\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tlong m = in.nextLong();\n\n\t\tint arr[] = new int[n];\n\t\tint l = 0;\n\t\tint r = n - 1;\n\t\tint z = n - 2;\n\t\tfor (int i = 1; i <= n; ++i) {\n\t\t\tlong mid = 1l << (z);\n\t\t\tz--;\n\t\t\tif (m > mid) {\n\t\t\t\tarr[r--] = i;\n\t\t\t\tm -= mid;\n\t\t\t} else {\n\n\t\t\t\tarr[l++] = i;\n\t\t\t}\n\n\t\t}\n\n\t\tfor (int i = 0; i < n - 1; ++i) {\n\t\t\tSystem.out.print(arr[i] + \" \");\n\t\t}\n\t\tSystem.out.println(arr[n - 1]);\n\n\t}\n}\n", "src_uid": "a8da7cbd9ddaec8e0468c6cce884e7a2"} {"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 FastReader in = new FastReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n APrimeMinister solver = new APrimeMinister();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class APrimeMinister {\n public void solve(int testNumber, FastReader s, PrintWriter out) {\n int n = s.nextInt();\n int[] arr = s.nextIntArray(n);\n int sum = 0;\n for (int i = 0; i < n; i++) {\n sum += arr[i];\n }\n\n int sumTillNow = arr[0];\n StringBuilder ans = new StringBuilder();\n\n int count = 1;\n for (int i = 0; i < n; i++) {\n if (arr[0] / arr[i] >= 2) {\n count++;\n }\n }\n\n ans.append(count).append(\"\\n\");\n ans.append(1).append(\" \");\n for (int i = 0; i < n; i++) {\n if (arr[0] / arr[i] >= 2) {\n sumTillNow += arr[i];\n ans.append(i + 1).append(\" \");\n }\n }\n\n\n if (sumTillNow < sum / 2 + 1) {\n out.println(0);\n } else {\n out.println(ans);\n }\n }\n\n }\n\n static class FastReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private FastReader.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 nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public int[] nextIntArray(int n) {\n int[] array = new int[n];\n for (int i = 0; i < n; ++i) array[i] = nextInt();\n return array;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "src_uid": "0a71fdaaf08c18396324ad762b7379d7"} {"source_code": "//package round563;\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 = \"1\";\n\t\n\t\n\t\n\t// 1 1 2 4\n\t// 2 240 151347172\n\t\n\t// 2 16 1536 14155776\n\t\n\tint[] lpf = enumLowestPrimeFactors(1000005);\n\tint mod = 1000000007;\n\tint N;\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni();\n\t\tif(n == 1){\n\t\t\tout.println(1);\n\t\t\treturn;\n\t\t}\n\t\tif(n == 3){\n\t\t\tout.println(4);\n\t\t\treturn;\n\t\t}\n\t\tN = n;\n\t\tint[] dist = new int[n+1];\n\t\tdist[1] = 1;\n\t\tint max = 1;\n\t\tfor(int i = 2;i <= n;i++){\n\t\t\tdist[i] = dist[i/lpf[i]] + 1;\n\t\t\tmax = Math.max(max, dist[i]);\n\t\t}\n\t\tlong ans = 0;\n\t\tfor(int i = 1;i <= n;i++){\n\t\t\tif(dist[i] == max){\n\t\t\t\tans += go(i);\n\t\t\t}\n\t\t}\n\t\tout.println(ans%mod);\n\t}\n\t\n\tlong go(int n)\n\t{\n\t\tint[][] f = factorFast(n, lpf);\n\t\tif(f.length == 1){\n\t\t\tassert f[0][0] == 2;\n\t\t\tlong[] dp = new long[f[0][1]+1];\n\t\t\tdp[f[0][1]] = 1;\n\t\t\tfor(int i = 1;i <= N-1;i++){\n\t\t\t\tlong[] ndp = new long[f[0][1]+1];\n\t\t\t\tfor(int j = 0;j <= f[0][1];j++){\n\t\t\t\t\tint nj = j-1;\n\t\t\t\t\tif(nj >= 0){\n\t\t\t\t\t\tlong can = (N>>>nj) - (N>>>nj+1);\n\t\t\t\t\t\tndp[nj] += dp[j] * can;\n\t\t\t\t\t\tndp[nj] %= mod;\n\t\t\t\t\t}\n\t\t\t\t\tndp[j] += dp[j] * ((N>>>j)-i);\n\t\t\t\t\tndp[j] %= mod;\n\t\t\t\t}\n\t\t\t\tdp = ndp;\n\t\t\t}\n\t\t\treturn dp[0];\n\t\t}\n\t\t\n\t\tassert f.length == 2;\n\t\tassert f[0][0] == 2;\n\t\tassert f[1][0] == 3;\n\t\tassert f[1][1] == 1;\n\t\tlong[][] dp = new long[2][f[0][1]+1];\n\t\tdp[1][f[0][1]] = 1;\n\t\tfor(int i = 1;i <= N-1;i++){\n\t\t\tlong[][] ndp = new long[2][f[0][1]+1];\n\t\t\tfor(int k = 0;k < 2;k++){\n\t\t\t\tfor(int j = 0;j <= f[0][1];j++){\n\t\t\t\t\tif(dp[k][j] == 0)continue;\n\t\t\t\t\tlong pre = 1<<j;\n\t\t\t\t\tfor(int l = 0;l < k;l++)pre *= 3;\n\t\t\t\t\tint nj = j-1;\n\t\t\t\t\tif(nj >= 0){\n\t\t\t\t\t\tlong nex = pre/2;\n\t\t\t\t\t\tlong can = N/nex - N/pre;\n\t\t\t\t\t\tndp[k][nj] += dp[k][j] * can;\n\t\t\t\t\t\tndp[k][nj] %= mod;\n\t\t\t\t\t}\n\t\t\t\t\tint nk = k-1;\n\t\t\t\t\tif(nk >= 0){\n\t\t\t\t\t\tlong nex = pre/3;\n\t\t\t\t\t\tlong can = N/nex - N/pre;\n\t\t\t\t\t\tndp[nk][j] += dp[k][j] * can;\n\t\t\t\t\t\tndp[nk][j] %= mod;\n\t\t\t\t\t}\n\t\t\t\t\tif(N/pre-i >= 0){\n\t\t\t\t\t\tndp[k][j] += dp[k][j] * (N/pre-i);\n\t\t\t\t\t\tndp[k][j] %= mod;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tdp = ndp;\n\t\t}\n\t\treturn dp[0][0];\n//\t\tdfs(n, f);\n\t}\n\n\t\n\tpublic static int[][] enumFIF(int n, int mod) {\n\t\tint[] f = new int[n + 1];\n\t\tint[] invf = new int[n + 1];\n\t\tf[0] = 1;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tf[i] = (int) ((long) f[i - 1] * i % mod);\n\t\t}\n\t\tlong a = f[n];\n\t\tlong b = mod;\n\t\tlong p = 1, q = 0;\n\t\twhile (b > 0) {\n\t\t\tlong c = a / b;\n\t\t\tlong d;\n\t\t\td = a;\n\t\t\ta = b;\n\t\t\tb = d % b;\n\t\t\td = p;\n\t\t\tp = q;\n\t\t\tq = d - c * q;\n\t\t}\n\t\tinvf[n] = (int) (p < 0 ? p + mod : p);\n\t\tfor (int i = n - 1; i >= 0; i--) {\n\t\t\tinvf[i] = (int) ((long) invf[i + 1] * (i + 1) % mod);\n\t\t}\n\t\treturn new int[][] { f, invf };\n\t}\n\n\tpublic static int[][] factorFast(int n, int[] lpf)\n\t{\n\t\tint[][] f = new int[9][];\n\t\tint q = 0;\n\t\twhile(lpf[n] > 0){\n\t\t\tint p = lpf[n];\n\t\t\tif(q == 0 || p != f[q-1][0]){\n\t\t\t\tf[q++] = new int[]{p, 1};\n\t\t\t}else{\n\t\t\t\tf[q-1][1]++;\n\t\t\t}\n\t\t\tn /= p;\n\t\t}\n\t\tif(n > 1){\n\t\t\t// big prime\n\t\t\treturn new int[][]{{n, 1}};\n\t\t}\n\t\treturn Arrays.copyOf(f, q);\n\t}\n\n\t\n\tpublic static int[] enumLowestPrimeFactors(int n) {\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++)\n\t\t\tlpf[i] = i;\n\t\tfor (int p = 2; p <= n; p++) {\n\t\t\tif (lpf[p] == p)\n\t\t\t\tprimes[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\n\t\n\tpublic static int[][] factor(int n, int[] primes)\n\t{\n\t\tint[][] ret = new int[9][2];\n\t\tint rp = 0;\n\t\tfor(int p : primes){\n\t\t\tif(p * p > n)break;\n\t\t\tint i;\n\t\t\tfor(i = 0;n % p == 0;n /= p, i++);\n\t\t\tif(i > 0){\n\t\t\t\tret[rp][0] = p;\n\t\t\t\tret[rp][1] = i;\n\t\t\t\trp++;\n\t\t\t}\n\t\t}\n\t\tif(n != 1){\n\t\t\tret[rp][0] = n;\n\t\t\tret[rp][1] = 1;\n\t\t\trp++;\n\t\t}\n\t\treturn Arrays.copyOf(ret, rp);\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 E().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "src_uid": "b2d59b1279d891dba9372a52364bced2"} {"source_code": "import java.util.*;\npublic class Main\n{\n\tpublic static void main(String[] args) {\n\t\tScanner sc=new Scanner(System.in);\n\t\tString s=sc.next();\n\t\tint n=s.length();\n\t\tSystem.out.println(26*(n+1)-n);\n\t}\n}\n", "src_uid": "556684d96d78264ad07c0cdd3b784bc9"} {"source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.Writer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\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\nclass TaskB {\n static final long mod = 1000000007;\n int[][][] can;\n int[] cnt;\n int[][] a;\n int n, m, k;\n int oq;\n\n long res = 0;\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n n = in.nextInt();\n m = in.nextInt();\n k = in.nextInt();\n if (k < n + m - 1) {\n out.printLine(0);\n return;\n }\n a = new int[n][m];\n cnt = new int[k];\n can = new int[n][m][k];\n for (int i = 0; i < n; ++i)\n for (int j = 0; j < m; ++j) {\n a[i][j] = in.nextInt();\n if (a[i][j] != 0) {\n if (can[i][j][a[i][j] - 1] > 0) {\n out.printLine(0);\n return;\n }\n ++cnt[a[i][j] - 1];\n for (int p = 0; p <= i; ++p)\n for (int q = 0; q <= j; ++q)\n can[p][q][a[i][j] - 1]++;\n for (int p = i; p < n; ++p)\n for (int q = j; q < m; ++q)\n can[p][q][a[i][j] - 1]++;\n }\n }\n oq = 0;\n for (int i = 0; i < k; ++i)\n if (cnt[i] != 0) ++oq;\n dfs(0, 0);\n res %= mod;\n// for (int i = 1; i <= k; ++i)\n// res = (res * (long) i) % mod;\n out.printLine(res);\n }\n\n void dfs(int x, int y) {\n if (x >= n) {\n long cur = 1;\n int cntt = 0;\n for (int i = 0; i < k; ++i) if (cnt[i] != 0) {\n ++cntt;\n }\n cntt -= oq;\n for (int i = 0; i < cntt; ++i)\n cur = (cur * (long)(k - oq - i)) % mod;\n res = (res + cur) % mod;\n return;\n }\n int xx = x, yy = y + 1;\n if (yy == m) {\n xx = x + 1;\n yy = 0;\n }\n if (a[x][y] != 0) {\n dfs(xx, yy);\n return;\n }\n boolean was0 = false;\n for (int c = 0; c < k; ++c) if (can[x][y][c] == 0) {\n if (cnt[c] == 0) {\n if (was0) continue;\n was0 = true;\n }\n ++cnt[c];\n for (int i = x; i < n; ++i)\n for (int j = y; j < m; ++j)\n ++can[i][j][c];\n dfs(xx, yy);\n for (int i = x; i < n; ++i)\n for (int j = y; j < m; ++j)\n --can[i][j][c];\n --cnt[c];\n }\n }\n}\n\nclass InputReader {\n private InputStream stream;\n private byte[] buffer = new byte[10000];\n private int cur;\n private int count;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public static boolean isSpace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public int read() {\n if (count == -1) {\n throw new InputMismatchException();\n }\n try {\n if (cur >= count) {\n cur = 0;\n count = stream.read(buffer);\n if (count <= 0)\n return -1;\n }\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n return buffer[cur++];\n }\n\n public int readSkipSpace() {\n int c;\n do {\n c = read();\n } while (isSpace(c));\n return c;\n }\n\n public int nextInt() {\n int sgn = 1;\n int c = readSkipSpace();\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 = res * 10 + c - '0';\n c = read();\n } while (!isSpace(c));\n res *= sgn;\n return res;\n }\n\n}\n\nclass OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void print(Object... objects) {\n for (int i = 0; i < objects.length; i++) {\n if (i != 0) {\n writer.print(' ');\n }\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", "src_uid": "5bb21f49d976cfa16a239593a95c53b5"} {"source_code": "\nimport java.util.Scanner;\n\n/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n\n/**\n *\n * @author \u0411\n */\npublic class Luba {\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 int max=0;\n int[] f=new int[n];\n int[] list= new int[n];\n for(int i=0;i<n;i++){\n list[i]=in.nextInt();\n }\n for(int i=0;i<n;i++){\n if(k%list[i]==0){\n f[i]=list[i];\n if(max<f[i]){\n max=f[i];\n }\n }\n }System.out.println(k/max);\n}\n \n}\n", "src_uid": "80520be9916045aca3a7de7bc925af1f"} {"source_code": "import java.io.PrintWriter;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.util.Random;\nimport java.util.StringTokenizer;\n\npublic class Task{\n\t\n\tstatic final boolean readFromFile = false;\n\tstatic final String fileInputName = \"input.txt\",\n\t\t\t\t\t\tfileOutputName = \"output.txt\";\n\t\n\tpublic static void main(String args[]){\n\t\tFileInputStream fileInputStream;\n\t\tFileOutputStream fileOutputStream;\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tif (readFromFile){\n\t\t\ttry{\n\t\t\t\tfileInputStream = new FileInputStream(new File(fileInputName));\n\t\t\t\tfileOutputStream = new FileOutputStream(new File(fileOutputName));\n\t\t\t}catch (FileNotFoundException e){\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\t\tPrintWriter out = new PrintWriter((readFromFile)?fileOutputStream:outputStream);\n\t\tInputReader in = new InputReader((readFromFile)?fileInputStream:inputStream);\n\t\t\n\t\tSolver s = new Solver(in, out);\n\t\ts.solve();\n\t\t\n\t\tout.close();\n\t}\n}\n\nclass Solver{\n\tprivate PrintWriter out;\n\tprivate InputReader in;\n\t\n\tpublic void solve(){\n\t\tint n =in.nextInt(),\n\t\t ans[] = {2,3,1,2,1};\n\t\tout.println(ans[n-1]);\n\t}\n\t\n\tSolver(InputReader in, PrintWriter out){\n\t\tthis.in = in;\n\t\tthis.out = out;\n\t}\n}\n\nclass InputReader{\n\tStringTokenizer tok;\n\tBufferedReader buf;\n\t\n\tInputReader(InputStream in){\n\t\ttok = null;\n\t\tbuf = new BufferedReader(new InputStreamReader(in));\n\t}\n\n\tInputReader(FileInputStream in){\n\t\ttok = null;\n\t\tbuf = new BufferedReader(new InputStreamReader(in));\n\t}\n\t\n\tpublic String next(){\n\t\twhile (tok==null || !tok.hasMoreTokens()){\n\t\t\ttry{\n\t\t\t\ttok = new StringTokenizer(buf.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 tok.nextToken();\n\t}\n\t\n\tpublic int nextInt(){\n\t\treturn Integer.parseInt(next());\n\t}\n\tpublic long nextLong(){\n\t\treturn Long.parseLong(next());\n\t}\n\tpublic double nextDouble(){\n\t\treturn Double.parseDouble(next());\n\t}\n\tpublic float nextFloat(){\n\t\treturn Float.parseFloat(next());\n\t}\n\tpublic String nextLine(){\n\t\ttry{\n\t\t\treturn buf.readLine();\n\t\t}catch (IOException e){\n\t\t\treturn null;\n\t\t}\n\t}\n}\n", "src_uid": "c702e07fed684b7741d8337aafa005fb"} {"source_code": "import java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\nimport static java.util.Arrays.fill;\nimport static java.util.Arrays.binarySearch;\nimport static java.util.Arrays.sort;\n\npublic class Main {\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Thread(null, new Runnable() {\n\t\t\tpublic void run() {\n\t\t\t\ttry {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tif (new File(\"input.txt\").exists())\n\t\t\t\t\t\t\tSystem.setIn(new FileInputStream(\"input.txt\"));\n\t\t\t\t\t} catch (SecurityException e) {}\n\t\t\t\t\tlong tm0 = System.currentTimeMillis();\n\t\t\t\t\tnew Main().run();\n\t\t\t\t\tlong tm1 = System.currentTimeMillis();\n\t\t\t\t\tSystem.err.println((tm1 - tm0) + \" ms\");\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}, \"1\", 1L << 24).start(); \n\t}\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer st = new StringTokenizer(\"\");\n\t\n\tint LCM = 5 * 7 * 8 * 9;\n\tint[] ind;\n\t\n\tint MAXL = 19;\n\tint MAXM = 48;\n\tlong[] pow10 = new long [MAXL + 1];\n\tint[] lcm = new int [MAXM];\n\tlong[] dp = new long [(MAXL + 1) * LCM * MAXM];\n\tlong[] cdp = new long [(MAXL + 1) * LCM * MAXM];\n\tlong[] count = new long [MAXL + 1];\n\tint[] nextRest = new int [(MAXL + 1) * LCM * 10];\n\tint[] nextInd = new int [MAXM << 4];\n\tint lcmCount = 0;\n\t\n\tint M1 = LCM * MAXM;\n\tint M2 = MAXM;\n\t\n\tint R1 = LCM * 10;\n\tint R2 = 10;\n\t\n\tvoid run() throws IOException {\n\t\tpow10[0] = 1L;\n\t\tfor (int l = 1; l < MAXL; l++)\n\t\t\tpow10[l] = pow10[l - 1] * 10L;\n\t\tind = new int [LCM + 1];\n\t\tfill(ind, -1);\n\t\tfor (int i = 0; i < 1024; i++)\n\t\t\tif (lcm(i) != 0)\n\t\t\t\tif (ind[lcm(i)] == -1) {\n\t\t\t\t\tlcm[lcmCount] = lcm(i);\n\t\t\t\t\tind[lcm(i)] = lcmCount++;\n\t\t\t\t}\n\t\tfor (int l = 0; l < MAXL; l++)\n\t\t\tfor (int r = 0; r < LCM; r++)\n\t\t\t\tfor (int d = 0; d < 10; d++)\n\t\t\t\t\tnextRest[(l + 1) * R1 + r * R2 + d] = (int) ((pow10[l] * d + r) % LCM);\n\t\tfor (int m = 0; m < MAXM; m++)\n\t\t\tfor (int d = 0; d < 10; d++)\n\t\t\t\tnextInd[(m << 4) | d] = d < 2 ? m : ind[lcm(lcm[m], d)];\n\t\tdp[0 * M1 + 0 * M2 + 0] = 1L;\n\t\tfor (int l = 0; l < MAXL; l++)\n\t\t\tfor (int r = 0; r < LCM; r++)\n\t\t\t\tfor (int m = 0; m < MAXM; m++)\n\t\t\t\t\tif (dp[l * M1 + r * M2 + m] != 0L)\n\t\t\t\t\t\tfor (int d = 0; d < 10; d++)\n\t\t\t\t\t\t\tdp[(l + 1) * M1 + nextRest[(l + 1) * R1 + r * R2 + d] * M2 + nextInd[(m << 4) | d]] += dp[l * M1 + r * M2 + m];\n\t\t\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tfor (int T = nextInt(); T --> 0; )\n\t\t\tout.println(solve(nextLong(), nextLong()));\n\t\t\n\t\tout.close();\n\t}\n\t\n\tlong solve(long l, long r) {\n\t\treturn count(r) - count(l - 1);\n\t}\n\n\tlong count(long x) {\n\t\tfill(cdp, 0L);\n\t\tcdp[0 * M1 + 0 * M2 + 0] = 1L;\n\t\tlong t = x;\n\t\tfor (int l = 0; l < MAXL && t > 0L; l++, t /= 10L) {\n\t\t\tint cd = (int) (t % 10L);\n\t\t\tfor (int r = 0; r < LCM; r++)\n\t\t\t\tfor (int m = 0; m < MAXM; m++) {\n\t\t\t\t\tif (dp[l * M1 + r * M2 + m] != 0L)\n\t\t\t\t\t\tfor (int d = 0; d < cd; d++)\n\t\t\t\t\t\t\tcdp[(l + 1) * M1 + nextRest[(l + 1) * R1 + r * R2 + d] * M2 + nextInd[(m << 4) | d]] += dp[l * M1 + r * M2 + m];\n\t\t\t\t\tif (cdp[l * M1 + r * M2 + m] != 0L)\n\t\t\t\t\t\tcdp[(l + 1) * M1 + nextRest[(l + 1) * R1 + r * R2 + cd] * M2 + nextInd[(m << 4) | cd]] += cdp[l * M1 + r * M2 + m];\n\t\t\t\t}\n\t\t}\n\t\tlong ret = 0L;\n\t\tint len = len(x);\n\t\tfor (int r = 0; r < LCM; r++)\n\t\t\tfor (int m = 0; m < MAXM; m++)\n\t\t\t\tif (m == 0 || r % lcm[m] == 0)\n\t\t\t\t\tret += cdp[len * M1 + r * M2 + m];\n\t\treturn ret;\n\t}\n\n\tint len(long x) {\n\t\tint ret = 0;\n\t\twhile (x > 0L) {\n\t\t\tret++;\n\t\t\tx /= 10L;\n\t\t}\n\t\treturn ret;\n\t}\n\n\tint[] lst = new int [10];\n\tint lcm(int mask) {\n\t\tint sz = 0;\n\t\tfor (int i = 0; i < 10; i++)\n\t\t\tif ((mask | (1 << i)) == mask)\n\t\t\t\tlst[sz++] = i;\n\t\tif (sz == 0)\n\t\t\treturn 0;\n\t\tint lcm = lst[0];\n\t\tfor (int i = 1; i < sz; i++)\n\t\t\tlcm = lcm(lcm, lst[i]);\n\t\treturn lcm;\n\t}\n\n\tint lcm(int a, int b) {\n\t\treturn a / gcd(a, b) * b;\n\t}\n\n\tint gcd(int a, int b) {\n\t\twhile (a > 0 && b > 0)\n\t\t\tif (a > b)\n\t\t\t\ta %= b;\n\t\t\telse\n\t\t\t\tb %= a;\n\t\treturn a + b;\n\t}\n\n\tString nextToken() throws IOException {\n\t\twhile (!st.hasMoreTokens()) {\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\t}\n\t\t\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}\n", "src_uid": "37feadce373f728ba2a560b198ca4bc9"} {"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, 200);\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", "src_uid": "013df41c0042f752a995bdcf16b28c7e"} {"source_code": "import static java.lang.Math.min;\n\nimport java.util.ArrayList;\nimport java.util.Scanner;\n\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tnew Main().run();\n\t}\n\n\tvoid run() {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = sc.nextInt();\n\n\n\n\n\t\tboolean[] visited = new boolean[1 << n];\n\t\tvisited[1] = true;\n\t\tint set = 0;\n\t\tfor (int i = 1; i < n; i++) {\n\n\t\t\tArrayList<Integer> comb = new ArrayList<Integer>();\n\t\t\tfor (int j = 0; j < i; j++) for (int k = 0; k <= j; k++) if (a[i] == a[j] + a[k]) {\n\t\t\t\tcomb.add(j);\n\t\t\t\tcomb.add(k);\n\t\t\t}\n\n\t\t\tfor (; set < (1 << i); ++set) if (visited[set]) {\n\t\t\t\tint b = set;\n\t\t\t\tfor (int s = 0; s < comb.size(); s += 2) {\n\t\t\t\t\tint j = comb.get(s);\n\t\t\t\t\tint k = comb.get(s+1);\n\t\t\t\t\tif ((b >> j & 1) == 1 && ((b >> k) & 1) == 1) {\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tint nb = b | (1 << i);\n\t\t\t\t\t\t\tvisited[nb] = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfor (int l = 0; l < n; l++) if ((b >> l & 1) == 1) {\n\t\t\t\t\t\t\tint nb = b | (1 << i);\n\t\t\t\t\t\t\tnb = nb ^ (1 << l);\n\t\t\t\t\t\t\tvisited[nb] = true;\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\tint best = n + 1;\n\t\tfor (; set < (1 << n); set++) if (visited[set]) {\n\t\t\tint b = set;\n\t\t\tbest = min(best, Integer.bitCount(b));\n\t\t}\n\t\tif (best >= n + 1)\n\t\t\tbest = -1;\n\t\tSystem.out.println(best);\n\n\t}\n}", "src_uid": "359f5d1264ce16c5c5293fd59db95628"} {"source_code": "import java.util.Scanner;\n\npublic class Main {\n\tpublic static boolean MyContain(String Input , String NextContian )\n\t{\n\t\tfor (int i =0;i<NextContian.length();i++)\n\t\t{\n\t\t\tif (!Input.contains(NextContian.substring(i, i+1)))\n\t\t\t{\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\telse \n\t\t\t{\n\t\t\t\tint index = Input.indexOf(NextContian.substring(i,i+1));\n\t\t\t\tInput = Input.substring(0, index) + Input.substring(index+1);\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\tpublic static void CheckExist(String Input ,int NextContian,String Number ) {\n\t\tif (Input.contains(Number)) //2\n\t\t{\n\t\t\tint IndexOfThis = Input.lastIndexOf(Number);\n\t\t\tboolean check = true ; \n\t\t\t//3\n\t\t\twhile (check) {\n\t\t\t\tif (String.valueOf(NextContian).length()> IndexOfThis)\n\t\t\t\t\tbreak;\n\t\t\t\tif (MyContain(Input.substring(0, IndexOfThis), String.valueOf(NextContian)))\n\t\t\t\t{\n\t\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\t\tSystem.out.println(String.valueOf(NextContian)+Number);\n\t\t\t\t\tSystem.exit(0);\n\t\t\t\t}\n\t\t\t\telse if (NextContian>=400)\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tNextContian+=4;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t}\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\t\n\t\tString Input = in.nextLine();\n\t\t\n\t\tif (Input.contains(\"0\"))\n\t\t{\n\t\t\tSystem.out.println(\"YES\");\n\t\t\tSystem.out.println(\"0\");\n\t\t\tSystem.exit(0);\n\t\t}\n\t\telse if (Input.contains(\"8\"))\n\t\t{\n\t\t\tSystem.out.println(\"YES\");\n\t\t\tSystem.out.println(\"8\");\n\t\t\tSystem.exit(0);\n\t\t}\n\t\t\n\t\tCheckExist(Input,3,\"2\");\n\t\tCheckExist(Input,2,\"4\");\n\t\tCheckExist(Input,1,\"6\");\n\t\tSystem.out.println(\"NO\");\n\t\t\n\t\t\n\t\tin.close();\n\t}\n\n}\n", "src_uid": "0a2a5927d24c70aca24fc17aa686499e"} {"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}", "src_uid": "dea5c9eded04f1a900c37571d20b34e2"} {"source_code": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n\npublic class B {\n\n\tstatic ArrayList<Edge>[] adjList;\n\tstatic int extra, f[], memo[][][];\n\n\tstatic int dp(int t, int u, int k)\n\t{\n\t\tif(k == 0)\n\t\t\treturn 0;\n\t\tif(memo[t][u][k] != -1)\n\t\t\treturn memo[t][u][k];\n\t\tint ret = 0;\n\t\tfor(Edge e: adjList[u])\n\t\t\tret = Math.max(ret, e.w + dp(t, e.v, k - 1));\n\t\tif(t == 0)\n\t\t\tret = Math.max(ret, f[u] * extra + dp(1, u, k));\n\t\treturn memo[t][u][k] = ret;\n\t}\n\n\tpublic static void main(String[] args) throws IOException \n\t{\n\t\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\n\t\tint n = sc.nextInt(), t = sc.nextInt(), A[] = new int[n];\n\t\tfor(int i = 0; i < n; ++i)\n\t\t\tA[i] = sc.nextInt();\n\t\tadjList = new ArrayList[301];\n\t\tfor(int i = 0; i <= 300; ++i)\n\t\t\tadjList[i] = new ArrayList<Edge>();\n\n\t\tf = new int[301];\n\t\tfor(int i = 0; i < n; ++i)\n\t\t\tif(f[A[i]]++ == 0)\n\t\t\t{\n\t\t\t\tint[] L = lis(A, n, A[i]);\n\t\t\t\tfor(int j = 0; j < n; ++j)\n\t\t\t\t\tif(L[j] != 0)\n\t\t\t\t\t\tadjList[A[i]].add(new Edge(A[j], L[j]));\n\t\t\t}\n\t\t\n\t\tmemo = new int[2][301][301];\n\t\tfor(int[][] x1: memo)\n\t\t\tfor(int[] x2: x1)\n\t\t\t\tArrays.fill(x2, -1);\n\t\tint ans = 0, p = Math.min(t, 300);\n\t\textra = t - p;\n\t\tfor(int x: A)\n\t\t\tans = Math.max(ans, dp(0, x, p));\n\t\tout.println(ans);\n\t\tout.flush();\n\t\tout.close();\n\t}\n\n\tstatic int[] lis(int[] A, int len, int lim)\n\t{\n\t\tint[] L = new int[len];\n\t\tfor(int i = 0; i < len; ++i)\n\t\t\tif(A[i] >= lim)\n\t\t\t{\n\t\t\t\tint curL = 1;\n\t\t\t\tfor(int j = 0; j < i; ++j)\n\t\t\t\t\tif(A[j] <= A[i] && L[j] + 1 > curL)\n\t\t\t\t\t\tcurL = L[j] + 1;\n\t\t\t\tL[i] = curL;\n\t\t\t}\n\t\treturn L;\n\t}\n\n\tstatic class Edge { int v, w; Edge(int a, int b) { v = a; w = b; } public String toString() { return v + \" \" + w; }}\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 r){\tbr = new BufferedReader(r);}\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\n\n\t}\n}", "src_uid": "26cf484fa4cb3dc2ab09adce7a3fc9b2"} {"source_code": "import java.io.*;\nimport java.util.Random;\nimport java.util.StringTokenizer;\n\npublic class A {\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\tlong big(long l) {\n\t\tif (l == 0)\n\t\t\treturn 9;\n\t\tlong res = 0;\n\t\twhile (l > 0) {\n\t\t\tres = res * 10 + 9;\n\t\t\tl /= 10;\n\t\t}\n\t\treturn res;\n\t}\n\n\tRandom st = new Random();\n\n\tvoid solve() throws IOException {\n\t\tlong l = nextLong();\n\t\tlong r = nextLong();\n\t\tlong res = Math.max(l * big(l) - l * l, r * big(r) - r * r);\n\t\tlong stp = 1;\n\t\tlong resul = 0;\n\t\tfor (int i = 0; i < 12; i++) {\n\t\t\tlong max = big(stp) / 2;\n\t\t\tif (stp > r)\n\t\t\t\tbreak;\n\t\t\tmax -= 100;\n\t\t\tfor (int j = 1; j <= 400; j++) {\n\t\t\t\tmax++;\n\t\t\t\tif ((max >= l) && (max <= r) && (max > stp)) {\n\t\t\t\t\tres = Math.max(res, max * (big(stp) - max));\n\t\t\t\t}\n\t\t\t}\n\t\t\tstp *= 10;\n\t\t}\n\t\tout.println(res);\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 A().run();\n\t}\n\n}\n", "src_uid": "2c4b2a162563242cb2f43f6209b59d5e"} {"source_code": "import java.util.*;\nimport java.io.*;\npublic class Main{\n\tstatic PrintWriter out=new PrintWriter(System.out);\n\tpublic static void main(String [] args) throws IOException{\n\t\tScanner sc=new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\tint m=sc.nextInt();\n\t\tint z=sc.nextInt();\n\t\tint a=0;\n\t\tint b=0;\n\t\tint d=0;\n\t\tfor(int i=1;i<=z;i++) {\n\t\t\tif(i%n==0)\n\t\t\t\ta+=n;\n\t\t\tif (i%m==0)\n\t\t\t\tb+=m;\n\t\t\tif(a==b&&a!=0&&b!=0) {\n\t\t\t\td++;\n\t\t\t\ta=0;\n\t\t\t\tb=0;\n\n\t\t\t}}\n\t\tout.println(d);\n\t\tout.flush();\n\n\t}\n\tstatic class Scanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(s));\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine(), \" \");\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\n\n\t\t}\n\n\t\tpublic long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic String nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tpublic boolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t}\n}", "src_uid": "e7ad55ce26fc8610639323af1de36c2d"} {"source_code": "import java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class BetaRound71_A implements Runnable {\n\n final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n BufferedReader in;\n PrintWriter out;\n StringTokenizer tok = new StringTokenizer(\"\");\n\n void init() throws IOException {\n if (ONLINE_JUDGE) {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n } else {\n in = new BufferedReader(new FileReader(\"input.txt\"));\n out = new PrintWriter(\"output.txt\");\n }\n }\n\n String readString() throws IOException {\n while (!tok.hasMoreTokens()) {\n tok = new StringTokenizer(in.readLine());\n }\n return tok.nextToken();\n }\n\n int readInt() throws IOException {\n return Integer.parseInt(readString());\n }\n\n @Override\n public void run() {\n try {\n long t1 = System.currentTimeMillis();\n init();\n Locale.setDefault(Locale.US);\n solve();\n out.close();\n long t2 = System.currentTimeMillis();\n System.err.println(\"Time = \" + (t2 - t1));\n } catch (Exception e) {\n e.printStackTrace(System.err);\n System.exit(-1);\n }\n }\n\n public static void main(String[] args) {\n new Thread(new BetaRound71_A()).start();\n }\n \n void solve() throws IOException {\n int x = readInt();\n int y = readInt();\n boolean Ciel = true;\n while (true) {\n boolean b = false;\n if (Ciel) {\n for (int d = 2; d >= 0; d--) {\n if (x < d) continue;\n if (d == 2) {\n if (y < 2) {\n out.print(\"Hanako\");\n return;\n } else {\n x -= 2;\n y -= 2;\n Ciel = !Ciel;\n b = true;\n break;\n }\n }\n if (d == 1) {\n if (y < 12) {\n out.print(\"Hanako\");\n return;\n } else {\n x--;\n y -= 12;\n Ciel = !Ciel;\n b = true;\n break;\n }\n }\n if (d == 0) {\n if (y < 22) {\n out.print(\"Hanako\");\n return;\n } else {\n y -= 22;\n Ciel = !Ciel;\n b = true;\n break;\n }\n }\n }\n } else {\n for (int d = 22; d >= 0; d -= 10) {\n if (y < d) continue;\n if (d == 22) {\n if (x < 0) {\n out.print(\"Ciel\");\n return;\n } else {\n y -= 22;\n Ciel = !Ciel;\n b = true;\n break;\n }\n }\n if (d == 12) {\n if (x < 1) {\n out.print(\"Ciel\");\n return;\n } else {\n x--;\n y -= 12;\n Ciel = !Ciel;\n b = true;\n break;\n }\n }\n if (d == 2) {\n if (x < 2) {\n out.print(\"Ciel\");\n return;\n } else {\n x -= 2;\n y -= 2;\n Ciel = !Ciel;\n b = true;\n break;\n }\n }\n }\n }\n if (!b) {\n if (Ciel) out.print(\"Hanako\"); else out.print(\"Ciel\");\n return;\n }\n }\n }\n \n}", "src_uid": "8ffee18bbc4bb281027f91193002b7f5"} {"source_code": "import java.lang.*;\nimport java.util.*;\npublic class A1\n{\n public static void main(String s[])\n {\n Scanner sc = new Scanner(System.in);\n int a = sc.nextInt();\n\t\t\n\t\tint x = 5;\n\t\tint ans = 0;\n\t\n\t\tans = ans+a/x;\n\t\ta = a%x;\n\t\n\t\tif(a==0)\n\t\tSystem.out.println(ans);\n\t\t\n\t\telse\n\t\tSystem.out.println(ans+1);\n\t\t\n }\n}", "src_uid": "4b3d65b1b593829e92c852be213922b6"} {"source_code": "//package round712;\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 E3 {\r\n\tInputStream is;\r\n\tFastWriter out;\r\n\tString INPUT = \"\";\r\n\tfinal int mod = 998244353;\r\n\tlong[][] C;\r\n\t\r\n\tvoid solve()\r\n\t{\r\n\t\tC = new long[4052 + 1][4052 + 1];\r\n\t\tfor (int i = 0; i <= 4052; i++) {\r\n\t\t\tC[i][0] = 1;\r\n\t\t\tfor (int j = 1; j <= i; j++) {\r\n\t\t\t\tC[i][j] = C[i - 1][j - 1] + C[i - 1][j];\r\n\t\t\t\tif (C[i][j] >= mod) C[i][j] -= mod;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tint H = ni(), W = ni();\r\n\r\n\t\tlong T = 0;\r\n\t\t// O(wh^4)\r\n\t\tfor(int w = 1;w < W;w++) {\r\n\t\t\tlong R = 0;\r\n\t\t\tfor (int hl = 1; hl <= H; hl++) {\r\n\t\t\t\t// 0 <= hr <= H-1-hl\r\n\t\t\t\t// d(hl, w-1) * d(hr, w-1)\r\n\t\t\t\t// C[dr+w-1][w-1] * d(hl, w-1)\r\n\t\t\t\tint hll = H+1 - hl;\r\n\t\t\t\tR += d(hll, W-w-1) * C[H-1-hll+W-w][W-w];\r\n\t\t\t\tR %= mod;\r\n\t\t\t\tT += d(hl, w-1) * C[H-1-hl+w][w] % mod * R;\r\n\t\t\t\tT %= mod;\r\n//\t\t\t\tfor (int hll = 0; hll <= H; hll++) {\r\n//\t\t\t\t\tif (hl + hll > H) {\r\n//\t\t\t\t\t\tT += d(hl, w-1) * C[H-1-hl+w][w] * d(hll, W-w-1) * C[H-1-hll+W-w][W-w];\r\n//\t\t\t\t\t\tT %= mod;\r\n//\t\t\t\t\t}\r\n//\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tT = T * 2;\r\n\r\n\t\tlong IT = 0;\r\n\t\t// O(hw^4)\r\n\t\tfor(int h = 1;h <= H-1;h++){\r\n\t\t\t// C[h-1+l][l]\r\n\t\t\t// C[h-1+r][r-1]\r\n\t\t\tlong R = 0;\r\n\t\t\tfor(int r = W-1;r >= 1;r--){\r\n\t\t\t\tR += d(H-h-1, r) * C[H-h+W-(r+1)][W-(r+1)];\r\n\t\t\t\tR %= mod;\r\n\t\t\t\tIT += C[h-1+r][r-1] * d(h-1, W-r) % mod * R;\r\n\t\t\t\tIT %= mod;\r\n\t\t\t}\r\n\t\t}\r\n\t\tIT *= 2;\r\n\t\tout.println((T+IT)%mod);\r\n\t}\r\n\r\n\tlong d(int h, int w)\r\n\t{\r\n\t\t// begin:h, dec\r\n\t\treturn C[h+w][h];\r\n\t}\r\n\t\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 E3().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<Integer> 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", "src_uid": "1738dc65af1fffa445cb0c3074c6bedb"} {"source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.BufferedOutputStream;\nimport java.util.StringTokenizer;\nimport java.io.Writer;\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 An Almost Retired Guy\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 int k = in.nextInt();\n long ans = 0;\n int l = 0, u = 0;\n Hexagon L = new Hexagon(), U = new Hexagon();\n L.EL();\n U.EL();\n for (int layer = 1; ; layer++) {\n while (!L.distance(k) && l <= u) {\n L.RL();\n l++;\n }\n if (l > u) break;\n while (!U.distance(k)) {\n U.RU();\n u--;\n }\n ans += u - l + 1;\n u++;\n L.EL();\n U.EU();\n }\n ans = 6 * ans + 1;\n out.println(ans);\n }\n\n class Hexagon {\n static final int N = 6;\n int[] X;\n int[] Y;\n\n Hexagon() {\n X = new int[]{2, 1, -1, -2, -1, 1};\n Y = new int[]{0, 1, 1, 0, -1, -1};\n }\n\n boolean distance(int d) {\n long max = Long.MIN_VALUE;\n for (int i = 0; i < N; i++) max = Math.max(max, (long) X[i] * X[i] + (long) 3 * Y[i] * Y[i]);\n return max <= (long) 4 * d * d;\n }\n\n void EL() {\n for (int i = 0; i < N; i++) {\n X[i] += 3;\n Y[i]++;\n }\n }\n\n void EU() {\n for (int i = 0; i < N; i++) Y[i] += 2;\n }\n\n void RL() {\n for (int i = 0; i < N; i++) {\n X[i] -= 3;\n Y[i]++;\n }\n }\n\n void RU() {\n for (int i = 0; i < N; i++) {\n X[i] += 3;\n Y[i]--;\n }\n }\n\n }\n\n }\n\n static class OutputWriter extends PrintWriter {\n public OutputWriter(OutputStream outputStream) {\n super(new BufferedOutputStream(outputStream));\n }\n\n public OutputWriter(Writer writer) {\n super(writer);\n }\n\n public void close() {\n super.close();\n }\n\n }\n\n static class InputReader {\n BufferedReader br;\n StringTokenizer st;\n\n public InputReader(InputStream inputStream) {\n br = new BufferedReader(new InputStreamReader(inputStream));\n }\n\n public String next() {\n while (st == null || !st.hasMoreElements()) {\n st = new StringTokenizer(nextLine());\n }\n return st.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public String nextLine() {\n try {\n return br.readLine();\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n\n }\n}\n\n", "src_uid": "6787c7631716ce3dff3f9a5e1c51ff13"} {"source_code": "import java.util.Scanner;\npublic class Cakeminator {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\t\n\t\tString s = sc.nextLine();\n\t\tint cnt=0;\n\t\t\n\t\tfor (int i=0;i<26;i++){\n\t\t\tif(s.indexOf('a'+i)!=-1)\n\t\t\t\tcnt++;\n\t\t}\n\t\tSystem.out.println(cnt%2==1?\"IGNORE HIM!\":\"CHAT WITH HER!\");\n\t\t\n\t}\n}", "src_uid": "a8c14667b94b40da087501fd4bdd7818"} {"source_code": "import java.util.*;\n\npublic class C {\n/*\n9\nNNSESENN\nNNSSWNWN\n\n9\nNNSESENN\nSNSSWNWN\n\n9\nNNSESENN\nNNSSWNEN\n*/\n\t\n\tpublic static void main(String[] args) {\n\t\t\n\t\tScanner qwe = new Scanner(System.in);\n\t\t\n\t\tint n = qwe.nextInt();\n\t\tStringBuilder needle = new StringBuilder(qwe.next()).reverse();\n\t\tchar[] tocomp = qwe.next().toCharArray();\n\t\t\n\t\tStringBuilder hay = new StringBuilder();\n\t\t\n\t\tString dirs = \"NSEW\";\n\t\tString dc = \"SNWE\";\n\t\t\n\t\tfor (int i = 0; i < tocomp.length; i++) {\n\t\t\thay.append(dc.charAt(dirs.indexOf(tocomp[i])));\n\t\t}\n\t\t\n\t\tif(n == 2){\n\t\t\tif(hay.toString().equals(needle.toString())){\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t}\n\t\t\telse System.out.println(\"YES\");\n\t\t}\n\t\telse if(new KMP().KMPSearch(needle.toString(), hay.toString())){\n\t\t\tSystem.out.println(\"YES\");\n\t\t}\n\t\telse System.out.println(\"NO\");\n\t\t\n\t\tqwe.close();\n\t}\n\t\n\t\n\tstatic class KMP {\n\t\t/**\n\t\t * Generates the table used by KMP. Not really useful on its own :( O(m)\n\t\t * [m=length of needle]\n\t\t */\n\t\tpublic int[] KMPTableGen(String needle) {\n\t\t\tint[] T = new int[needle.length()];\n\t\t\tint pos = 2;\n\t\t\tint cnd = 0;\n\t\t\tT[0] = -1;\n\t\t\tT[1] = 0;\n\t\t\twhile (pos < needle.length()) {\n\t\t\t\tif (needle.charAt(pos - 1) == needle.charAt(cnd)) {\n\t\t\t\t\tcnd++;\n\t\t\t\t\tT[pos] = cnd;\n\t\t\t\t\tpos++;\n\t\t\t\t} else if (cnd > 0)\n\t\t\t\t\tcnd = T[cnd];\n\t\t\t\telse {\n\t\t\t\t\tT[pos] = 0;\n\t\t\t\t\tpos++;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn T;\n\t\t}\n\n\t\t/**\n\t\t * KMP - String Searching\n\t\t * \n\t\t * O(n+m) [n=length of haystack, m=length of needle] Searches for the string\n\t\t * needle in the string haystack Requires: KMPTableGen(String)\n\t\t */\n\t\tpublic boolean KMPSearch(String needle, String haystack) {\n\t\t\tint m = 0;\n\t\t\tint i = 0;\n\t\t\tint[] T = KMPTableGen(needle);\n\t\t\twhile (m + i < haystack.length()) {\n\t\t\t\tif (needle.charAt(i) == haystack.charAt(m + i)) {\n//\t\t\t\t\tif (i == needle.length() - 1)\n//\t\t\t\t\t\treturn m;\n\t\t\t\t\ti++;\n\t\t\t\t} else {\n\t\t\t\t\tm = m + i - T[i];\n\t\t\t\t\tif (T[i] > -1)\n\t\t\t\t\t\ti = T[i];\n\t\t\t\t\telse\n\t\t\t\t\t\ti = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\t//return haystack.length();\n\t\t\treturn i ==0;\n\t\t}\n\t}\n\n}\n", "src_uid": "85f43628bec7e9b709273c34b894df6b"} {"source_code": "\nimport java.util.Scanner;\npublic class tr {\n public static void main (String args []){\n Scanner s = new Scanner(System.in);\n int sum = 0;int x ;\n for(int i = 0 ; i < 5;++i){\n x=s.nextInt();\n sum+=x;\n }\n \n if(sum%5==0&&sum!=0){\n System.out.println(sum/5);\n }\n else{\n System.out.println(-1);\n }\n \n \n }}\n \n \n", "src_uid": "af1ec6a6fc1f2360506fc8a34e3dcd20"} {"source_code": "import java.io.IOException;\r\nimport java.io.InputStream;\r\nimport java.io.PrintWriter;\r\nimport java.math.BigDecimal;\r\nimport java.math.RoundingMode;\r\nimport java.util.*;\r\n\r\nimport javax.swing.text.html.CSS;\r\n\r\nimport java.io.File;\r\nimport java.io.FileDescriptor;\r\nimport java.io.FileOutputStream;\r\nimport java.io.OutputStream;\r\nimport java.io.UncheckedIOException;\r\nimport java.lang.Thread.State;\r\nimport java.lang.reflect.Field;\r\nimport java.nio.CharBuffer;\r\nimport java.nio.charset.CharacterCodingException;\r\nimport java.nio.charset.CharsetEncoder;\r\nimport java.nio.charset.StandardCharsets;\r\n\r\npublic class Main {\r\n\tstatic final long MOD1=1000000007;\r\n\tstatic final long MOD=998244353;\r\n\tstatic int ans=0;\r\n\tpublic static void main(String[] args){\r\n\t\tPrintWriter out = new PrintWriter(System.out);\r\n\t\tInputReader sc=new InputReader(System.in);\r\n\t\tint t = sc.nextInt();\r\n\t\tfor (int i = 0; i <t; i ++) {\r\n\t\t\tint n = sc.nextInt();\r\n\t\t\tint m = sc.nextInt();\r\n\t\t\tint k = sc.nextInt();\r\n\t\t\tout.println(solve(n, m, k));\r\n\t\t}\r\n\t\tout.flush();\r\n\t}\r\n\tstatic String solve(int n,int m,int k) {\r\n\t\tif (n%2==0){\r\n\t\t\tif (m%2==0) {\r\n\t\t\t\tif (k%2==0) {\r\n\t\t\t\t\treturn \"YES\";\r\n\t\t\t\t}else {\r\n\t\t\t\t\treturn \"NO\";\r\n\t\t\t\t}\r\n\t\t\t}else {\r\n\t\t\t\tif (k%2==0&&k*2<=n*(m-1)) {\r\n\t\t\t\t\treturn \"YES\";\r\n\t\t\t\t}else {\r\n\t\t\t\t\treturn \"NO\";\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}else {\r\n\t\t\tif (k*2<m){\r\n\t\t\t\treturn \"NO\";\r\n\t\t\t}else {\r\n\t\t\t\tk -= m/2;\r\n\t\t\t\tif (k%2==0) {\r\n\t\t\t\t\treturn \"YES\";\r\n\t\t\t\t}else {\r\n\t\t\t\t\treturn \"NO\";\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tstatic class InputReader { \r\n\t\tprivate InputStream in;\r\n\t\tprivate byte[] buffer = new byte[1024];\r\n\t\tprivate int curbuf;\r\n\t\tprivate int lenbuf;\r\n\t\tpublic InputReader(InputStream in) {\r\n\t\t\tthis.in = in;\r\n\t\t\tthis.curbuf = this.lenbuf = 0;\r\n\t\t}\r\n\t\tpublic boolean hasNextByte() {\r\n\t\t\tif (curbuf >= lenbuf) {\r\n\t\t\t\tcurbuf = 0;\r\n\t\t\t\ttry {\r\n\t\t\t\t\tlenbuf = in.read(buffer);\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 (lenbuf <= 0)\r\n\t\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t}\r\n \r\n\t\tprivate int readByte() {\r\n\t\t\tif (hasNextByte())\r\n\t\t\t\treturn buffer[curbuf++];\r\n\t\t\telse\r\n\t\t\t\treturn -1;\r\n\t\t}\r\n \r\n\t\tprivate boolean isSpaceChar(int c) {\r\n\t\t\treturn !(c >= 33 && c <= 126);\r\n\t\t}\r\n \r\n\t\tprivate void skip() {\r\n\t\t\twhile (hasNextByte() && isSpaceChar(buffer[curbuf]))\r\n\t\t\t\tcurbuf++;\r\n\t\t}\r\n \r\n\t\tpublic boolean hasNext() {\r\n\t\t\tskip();\r\n\t\t\treturn hasNextByte();\r\n\t\t}\r\n \r\n\t\tpublic String next() {\r\n\t\t\tif (!hasNext())\r\n\t\t\t\tthrow new NoSuchElementException();\r\n\t\t\tStringBuilder sb = new StringBuilder();\r\n\t\t\tint b = readByte();\r\n\t\t\twhile (!isSpaceChar(b)) {\r\n\t\t\t\tsb.appendCodePoint(b);\r\n\t\t\t\tb = readByte();\r\n\t\t\t}\r\n\t\t\treturn sb.toString();\r\n\t\t}\r\n \r\n\t\tpublic int nextInt() {\r\n\t\t\tif (!hasNext())\r\n\t\t\t\tthrow new NoSuchElementException();\r\n\t\t\tint c = readByte();\r\n\t\t\twhile (isSpaceChar(c))\r\n\t\t\t\tc = readByte();\r\n\t\t\tboolean minus = false;\r\n\t\t\tif (c == '-') {\r\n\t\t\t\tminus = true;\r\n\t\t\t\tc = readByte();\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 = res * 10 + c - '0';\r\n\t\t\t\tc = readByte();\r\n\t\t\t} while (!isSpaceChar(c));\r\n\t\t\treturn (minus) ? -res : res;\r\n\t\t}\r\n \r\n\t\tpublic long nextLong() {\r\n\t\t\tif (!hasNext())\r\n\t\t\t\tthrow new NoSuchElementException();\r\n\t\t\tint c = readByte();\r\n\t\t\twhile (isSpaceChar(c))\r\n\t\t\t\tc = readByte();\r\n\t\t\tboolean minus = false;\r\n\t\t\tif (c == '-') {\r\n\t\t\t\tminus = true;\r\n\t\t\t\tc = readByte();\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 = res * 10 + c - '0';\r\n\t\t\t\tc = readByte();\r\n\t\t\t} while (!isSpaceChar(c));\r\n\t\t\treturn (minus) ? -res : res;\r\n\t\t}\r\n \r\n\t\tpublic double nextDouble() {\r\n\t\t\treturn Double.parseDouble(next());\r\n\t\t}\r\n \r\n\t\tpublic int[] nextIntArray(int n) {\r\n\t\t\tint[] a = new int[n];\r\n\t\t\tfor (int i = 0; i < n; i++)\r\n\t\t\t\ta[i] = nextInt();\r\n\t\t\treturn a;\r\n\t\t}\r\n\t\tpublic double[] nextDoubleArray(int n) {\r\n\t\t\tdouble[] a = new double[n];\r\n\t\t\tfor (int i = 0; i < n; i++)\r\n\t\t\t\ta[i] = nextDouble();\r\n\t\t\treturn a;\r\n\t\t}\r\n\t\tpublic long[] nextLongArray(int n) {\r\n\t\t\tlong[] a = new long[n];\r\n\t\t\tfor (int i = 0; i < n; i++)\r\n\t\t\t\ta[i] = nextLong();\r\n\t\t\treturn a;\r\n\t\t}\r\n \r\n\t\tpublic char[][] nextCharMap(int n, int m) {\r\n\t\t\tchar[][] map = new char[n][m];\r\n\t\t\tfor (int i = 0; i < n; i++)\r\n\t\t\t\tmap[i] = next().toCharArray();\r\n\t\t\treturn map;\r\n\t\t}\r\n\t}\r\n}", "src_uid": "4d0c0cc8faca62eb6384f8135b30feb8"} {"source_code": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.InputMismatchException;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\n/**\n * \n * @author sultan.of.swing\n *\n */\n\npublic class TaskC {\n\n\tpublic FasterScanner mFScanner;\n\tpublic PrintWriter mOut;\n\n\tpublic TaskC() {\n\t\tmFScanner = new FasterScanner();\n\t\tmOut = new PrintWriter(System.out);\n\t}\n\n\tpublic void solve() {\n\t\tint n, m;\n\t\tchar op[];\n\t\tint num[];\n\t\tint i;\n\t\tint unconfirmed;\n\t\tString str;\n\t\tHashSet<Integer> loggedInSet;\n\t\tHashSet<Integer> hasActed;\n\t\tTreeSet<Integer> leaderSet;\n\t\tHashSet<Integer> missing;\n\n\t\tn = mFScanner.nextInt();\n\t\tm = mFScanner.nextInt();\n\n\t\tnum = new int[m];\n\t\top = new char[m];\n\n\t\tfor (i = 0; i < m; i++) {\n\t\t\tstr = mFScanner.nextLine();\n\t\t\tStringTokenizer st = new StringTokenizer(str);\n\t\t\top[i] = st.nextToken().charAt(0);\n\t\t\tnum[i] = Integer.parseInt(st.nextToken()) - 1;\n\t\t}\n\n\t\tloggedInSet = new HashSet<>();\n\t\thasActed = new HashSet<>();\n\n\t\tfor (i = 0; i < n; i++)\n\t\t\tloggedInSet.add(i);\n\n\t\tfor (i = 0; i < m; i++) {\n\n\t\t\tif (op[i] == '+' && !hasActed.contains(num[i]))\n\t\t\t\tloggedInSet.remove(num[i]);\n\n\t\t\thasActed.add(num[i]);\n\t\t}\n\n\t\tunconfirmed = n - hasActed.size();\n\n\t\tif (loggedInSet.size() <= unconfirmed && op[0] == '+') {\n\t\t\tloggedInSet.add(num[0]);\n\t\t}\n\n\t\tleaderSet = new TreeSet<>(loggedInSet);\n\t\tmissing = new HashSet<>();\n\n\t\tfor (i = 0; i < m; i++) {\n\n\t\t\tif (op[i] == '+') {\n\n\t\t\t\tloggedInSet.add(num[i]);\n\n\t\t\t\tfor (int miss : missing) {\n\t\t\t\t\tif (miss != num[i])\n\t\t\t\t\t\tleaderSet.remove(miss);\n\t\t\t\t}\n\n\t\t\t\tmissing.clear();\n\n\t\t\t} else {\n\t\t\t\tloggedInSet.remove(num[i]);\n\n\t\t\t\tif (loggedInSet.size() > unconfirmed) {\n\t\t\t\t\tleaderSet.remove(num[i]);\n\t\t\t\t} else {\n\t\t\t\t\tmissing.add(num[i]);\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t}\n\n\t\tmOut.println(leaderSet.size());\n\n\t\tfor (int l : leaderSet) {\n\t\t\tmOut.print((l + 1) + \" \");\n\t\t}\n\n\t\tmOut.println();\n\n\t}\n\n\tpublic void flush() {\n\t\tmOut.flush();\n\t}\n\n\tpublic void close() {\n\t\tmOut.close();\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tTaskC mSol = new TaskC();\n\t\tmSol.solve();\n\t\tmSol.flush();\n\t\tmSol.close();\n\t}\n\n\tclass FasterScanner {\n\t\tprivate InputStream mIs;\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n\n\t\tpublic FasterScanner() {\n\t\t\tthis(System.in);\n\t\t}\n\n\t\tpublic FasterScanner(InputStream is) {\n\t\t\tmIs = is;\n\t\t}\n\n\t\tpublic int read() {\n\t\t\tif (numChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= numChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tnumChars = mIs.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (numChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isEndOfLine(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic String nextString() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic double nextDouble() {\n\t\t\tDouble next;\n\t\t\tnext = Double.parseDouble(nextString());\n\t\t\treturn next;\n\t\t}\n\n\t\tpublic boolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tpublic boolean isEndOfLine(int c) {\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t}\n\n\t\tpublic char[] nextCharArray(int N) {\n\t\t\tint i;\n\t\t\tchar[] array;\n\t\t\tString str;\n\n\t\t\tarray = new char[N];\n\n\t\t\ti = 0;\n\n\t\t\tstr = nextLine();\n\n\t\t\tfor (i = 0; i < N && i < str.length(); i++) {\n\t\t\t\tarray[i] = str.charAt(i);\n\t\t\t}\n\n\t\t\treturn array;\n\t\t}\n\n\t\tpublic char[][] nextChar2DArray(int M, int N) {\n\t\t\tint i;\n\t\t\tchar[][] array;\n\n\t\t\tarray = new char[M][N];\n\n\t\t\ti = 0;\n\n\t\t\tfor (i = 0; i < M; i++) {\n\t\t\t\tarray[i] = nextCharArray(N);\n\t\t\t}\n\n\t\t\treturn array;\n\t\t}\n\n\t\tpublic int[] nextIntArray(int N) {\n\t\t\tint i;\n\t\t\tint[] array;\n\n\t\t\tarray = new int[N];\n\n\t\t\ti = 0;\n\n\t\t\tfor (i = 0; i < N; i++) {\n\t\t\t\tarray[i] = nextInt();\n\t\t\t}\n\n\t\t\treturn array;\n\t\t}\n\n\t\tpublic int[][] nextInt2DArray(int M, int N) {\n\t\t\tint i;\n\t\t\tint[][] array;\n\n\t\t\tarray = new int[M][N];\n\n\t\t\ti = 0;\n\n\t\t\tfor (i = 0; i < M; i++) {\n\t\t\t\tarray[i] = nextIntArray(N);\n\t\t\t}\n\n\t\t\treturn array;\n\t\t}\n\n\t\tpublic long[] nextLongArray(int N) {\n\t\t\tint i;\n\t\t\tlong[] array;\n\n\t\t\tarray = new long[N];\n\n\t\t\ti = 0;\n\n\t\t\tfor (i = 0; i < N; i++) {\n\t\t\t\tarray[i] = nextLong();\n\t\t\t}\n\n\t\t\treturn array;\n\t\t}\n\n\t\tpublic long[][] nextLong2DArray(int M, int N) {\n\t\t\tint i;\n\t\t\tlong[][] array;\n\n\t\t\tarray = new long[M][N];\n\n\t\t\ti = 0;\n\n\t\t\tfor (i = 0; i < M; i++) {\n\t\t\t\tarray[i] = nextLongArray(N);\n\t\t\t}\n\n\t\t\treturn array;\n\t\t}\n\n\t\tpublic double[] nextDoubleArray(int N) {\n\t\t\tint i;\n\t\t\tdouble[] array;\n\n\t\t\tarray = new double[N];\n\n\t\t\tfor (i = 0; i < N; i++) {\n\t\t\t\tarray[i] = nextDouble();\n\t\t\t}\n\n\t\t\treturn array;\n\t\t}\n\n\t\tpublic double[][] nextDouble2DArray(int M, int N) {\n\t\t\tint i;\n\t\t\tdouble[][] array;\n\n\t\t\tarray = new double[M][N];\n\n\t\t\tfor (i = 0; i < M; i++) {\n\t\t\t\tarray[i] = nextDoubleArray(N);\n\t\t\t}\n\n\t\t\treturn array;\n\t\t}\n\n\t}\n}", "src_uid": "a3a337c7b919e7dfd7ff45ebf59681b5"} {"source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class c1\n{\n\tstatic Scanner sc;\n\tstatic PrintStream ps;\n\tpublic static void main(String [] args)\n\t{\n\t\tps= System.out;\n\t\tsc= new Scanner(System.in);\n\t\tint f = sc.nextInt();\n\t\tint [] p = new int[f+1];\n\t\tint max = 0, maxi = 1;\n\t\tfor(int i = 1; i <= f; i++)\n\t\t{\n\t\t\tp[i] = sc.nextInt();\n\t\t\tif(max < p[i])\n\t\t\t{\n\t\t\t\tmax = p[i];\n\t\t\t\tmaxi = i;\n\t\t\t}\n\t\t}\n\t\tmaxi = (f+1)/2;\n\t\t///ps.println(max+\" \"+maxi);\n\t\tint minPow = 100000000;\n\t\tfor(int x = 1; x <=f; x++){\n\t\t\tint pow = 0;\n\t\t\tfor(int i = 1; i <= f; i++)\n\t\t\t{\n\t\t\t\tpow += p[i]*(2*(Math.abs(i-x)+Math.abs(1-x)+Math.abs(i-1)));\n\t\t\t//ps.println(pow);\n\t\t\t}\n\t\t\tminPow = minPow > pow? pow:minPow;\n\t\t}\n\t\tps.println(minPow);\n\n\t}\n}", "src_uid": "a5002ddf9e792cb4b4685e630f1e1b8f"} {"source_code": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class G1096 {\n\tpublic static final int[] NTTPrimes = {1053818881, 1051721729, 1045430273, 1012924417, 1007681537, 1004535809, 998244353, 985661441, 976224257, 975175681};\n\tpublic static final int[] NTTPrimitiveRoots = {7, 6, 3, 5, 3, 3, 3, 3, 3, 17};\n//\tpublic static final int[] NTTPrimes = {1012924417, 1004535809, 998244353, 985661441, 975175681, 962592769, 950009857, 943718401, 935329793, 924844033};\n//\tpublic static final int[] NTTPrimitiveRoots = {5, 3, 3, 3, 17, 7, 7, 7, 3, 5};\n\n\tpublic static long[] convoluteSimply(long[] a, long[] b, int P, int g) {\n\t\tint m = Math.max(2, Integer.highestOneBit(Math.max(a.length, b.length) - 1) << 2);\n\t\tlong[] fa = nttmb(a, m, false, P, g);\n\t\tlong[] fb = a == b ? fa : nttmb(b, m, false, P, g);\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tfa[i] = fa[i] * fb[i] % P;\n\t\t}\n\t\treturn nttmb(fa, m, true, P, g);\n\t}\n\n\tpublic static long[] convolute(long[] a, long[] b) {\n\t\tint USE = 2;\n\t\tint m = Math.max(2, Integer.highestOneBit(Math.max(a.length, b.length) - 1) << 2);\n\t\tlong[][] fs = new long[USE][];\n\t\tfor (int k = 0; k < USE; k++) {\n\t\t\tint P = NTTPrimes[k], g = NTTPrimitiveRoots[k];\n\t\t\tlong[] fa = nttmb(a, m, false, P, g);\n\t\t\tlong[] fb = a == b ? fa : nttmb(b, m, false, P, g);\n\t\t\tfor (int i = 0; i < m; i++) {\n\t\t\t\tfa[i] = fa[i] * fb[i] % P;\n\t\t\t}\n\t\t\tfs[k] = nttmb(fa, m, true, P, g);\n\t\t}\n\n\t\tint[] mods = Arrays.copyOf(NTTPrimes, USE);\n\t\tlong[] gammas = garnerPrepare(mods);\n\t\tint[] buf = new int[USE];\n\t\tfor (int i = 0; i < fs[0].length; i++) {\n\t\t\tfor (int j = 0; j < USE; j++) {\n\t\t\t\tbuf[j] = (int) fs[j][i];\n\t\t\t}\n\t\t\tlong[] res = garnerBatch(buf, mods, gammas);\n\t\t\tlong ret = 0;\n\t\t\tfor (int j = res.length - 1; j >= 0; j--) {\n\t\t\t\tret = ret * mods[j] + res[j];\n\t\t\t}\n\t\t\tfs[0][i] = ret;\n\t\t}\n\t\treturn fs[0];\n\t}\n\n\tpublic static long[] convolute1(long[] a, long[] b) {\n\t\tint m = Math.max(2, Integer.highestOneBit(Math.max(a.length, b.length) - 1) << 2);\n\t\tint P = NTTPrimes[0], g = NTTPrimitiveRoots[0];\n\t\tlong[] fa = nttmb(a, m, false, P, g);\n\t\tlong[] fb = a == b ? fa : nttmb(b, m, false, P, g);\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tfa[i] = fa[i] * fb[i] % P;\n\t\t}\n\t\tlong[] f = nttmb(fa, m, true, P, g);\n\t\treturn f;\n\t}\n\tstatic long[] multiply(long a[],long b[],int mod)\n\t{\n\t\tlong v=mod;\n\t\tv*=mod;\n\t\tlong ans[]=new long[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{\n\t\t\t\tans[i+j]+=a[i]*b[j];\n\t\t\t\tif(ans[i+j]>=v)\n\t\t\t\t\tans[i+j]-=v;\n\t\t\t}\n\t\tfor(int i=0;i<ans.length;i++)\n\t\t\tans[i]%=mod;\n\t\treturn ans;\n\t}\n\tpublic static long[] convolute(long[] a, long[] b, int USE, int mod) {\n\t\tif(a.length+b.length<=200)\n\t\t\treturn multiply(a,b,mod);\n\t\tint m = Math.max(2, Integer.highestOneBit(Math.max(a.length, b.length) - 1) << 2);\n\t\tlong[][] fs = new long[USE][];\n\t\tfor (int k = 0; k < USE; k++) {\n\t\t\tint P = NTTPrimes[k], g = NTTPrimitiveRoots[k];\n\t\t\tlong[] fa = nttmb(a, m, false, P, g);\n\t\t\tlong[] fb = a == b ? fa : nttmb(b, m, false, P, g);\n\t\t\tfor (int i = 0; i < m; i++) {\n\t\t\t\tfa[i] = fa[i] * fb[i] % P;\n\t\t\t}\n\t\t\tfs[k] = nttmb(fa, m, true, P, g);\n\t\t}\n\n\t\tint[] mods = Arrays.copyOf(NTTPrimes, USE);\n\t\tlong[] gammas = garnerPrepare(mods);\n\t\tint[] buf = new int[USE];\n\t\tfor (int i = 0; i < fs[0].length; i++) {\n\t\t\tfor (int j = 0; j < USE; j++) {\n\t\t\t\tbuf[j] = (int) fs[j][i];\n\t\t\t}\n\t\t\tlong[] res = garnerBatch(buf, mods, gammas);\n\t\t\tlong ret = 0;\n\t\t\tfor (int j = res.length - 1; j >= 0; j--) {\n\t\t\t\tret = (ret * mods[j] + res[j]) % mod;\n\t\t\t}\n\t\t\tfs[0][i] = ret;\n\t\t}\n\t\treturn fs[0];\n\t}\n\n\t// static int[] wws = new int[270000]; // outer faster\n\t// Modifed Montgomery + Barrett\n\tprivate static long[] nttmb(long[] src, int n, boolean inverse, int P, int g) {\n\t\tlong[] dst = Arrays.copyOf(src, n);\n\n\t\tint h = Integer.numberOfTrailingZeros(n);\n\t\tlong K = Integer.highestOneBit(P) << 1;\n\t\tint H = Long.numberOfTrailingZeros(K) * 2;\n\t\tlong M = K * K / P;\n\n\t\tint[] wws = new int[1 << h - 1];\n\t\tlong dw = inverse ? pow(g, P - 1 - (P - 1) / n, P) : pow(g, (P - 1) / n, P);\n\t\tlong w = (1L << 32) % P;\n\t\tfor (int k = 0; k < 1 << h - 1; k++) {\n\t\t\twws[k] = (int) w;\n\t\t\tw = modh(w * dw, M, H, P);\n\t\t}\n\t\tlong J = invl(P, 1L << 32);\n\t\tfor (int i = 0; i < h; i++) {\n\t\t\tfor (int j = 0; j < 1 << i; j++) {\n\t\t\t\tfor (int k = 0, s = j << h - i, t = s | 1 << h - i - 1; k < 1 << h - i - 1; k++, s++, t++) {\n\t\t\t\t\tlong u = (dst[s] - dst[t] + 2 * P) * wws[k];\n\t\t\t\t\tdst[s] += dst[t];\n\t\t\t\t\tif (dst[s] >= 2 * P) {\n\t\t\t\t\t\tdst[s] -= 2 * P;\n\t\t\t\t\t}\n//\t\t\t\t\tlong Q = (u&(1L<<32)-1)*J&(1L<<32)-1;\n\t\t\t\t\tlong Q = (u << 32) * J >>> 32;\n\t\t\t\t\tdst[t] = (u >>> 32) - (Q * P >>> 32) + P;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (i < h - 1) {\n\t\t\t\tfor (int k = 0; k < 1 << h - i - 2; k++) {\n\t\t\t\t\twws[k] = wws[k * 2];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (dst[i] >= P) {\n\t\t\t\tdst[i] -= P;\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint rev = Integer.reverse(i) >>> -h;\n\t\t\tif (i < rev) {\n\t\t\t\tlong d = dst[i];\n\t\t\t\tdst[i] = dst[rev];\n\t\t\t\tdst[rev] = d;\n\t\t\t}\n\t\t}\n\n\t\tif (inverse) {\n\t\t\tlong in = invl(n, P);\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tdst[i] = modh(dst[i] * in, M, H, P);\n\t\t\t}\n\t\t}\n\n\t\treturn dst;\n\t}\n\n\t// Modified Shoup + Barrett\n\tprivate static long[] nttsb(long[] src, int n, boolean inverse, int P, int g) {\n\t\tlong[] dst = Arrays.copyOf(src, n);\n\n\t\tint h = Integer.numberOfTrailingZeros(n);\n\t\tlong K = Integer.highestOneBit(P) << 1;\n\t\tint H = Long.numberOfTrailingZeros(K) * 2;\n\t\tlong M = K * K / P;\n\n\t\tlong dw = inverse ? pow(g, P - 1 - (P - 1) / n, P) : pow(g, (P - 1) / n, P);\n\t\tlong[] wws = new long[1 << h - 1];\n\t\tlong[] ws = new long[1 << h - 1];\n\t\tlong w = 1;\n\t\tfor (int k = 0; k < 1 << h - 1; k++) {\n\t\t\twws[k] = (w << 32) / P;\n\t\t\tws[k] = w;\n\t\t\tw = modh(w * dw, M, H, P);\n\t\t}\n\t\tfor (int i = 0; i < h; i++) {\n\t\t\tfor (int j = 0; j < 1 << i; j++) {\n\t\t\t\tfor (int k = 0, s = j << h - i, t = s | 1 << h - i - 1; k < 1 << h - i - 1; k++, s++, t++) {\n\t\t\t\t\tlong ndsts = dst[s] + dst[t];\n\t\t\t\t\tif (ndsts >= 2 * P) {\n\t\t\t\t\t\tndsts -= 2 * P;\n\t\t\t\t\t}\n\t\t\t\t\tlong T = dst[s] - dst[t] + 2 * P;\n\t\t\t\t\tlong Q = wws[k] * T >>> 32;\n\t\t\t\t\tdst[s] = ndsts;\n\t\t\t\t\tdst[t] = ws[k] * T - Q * P & (1L << 32) - 1;\n\t\t\t\t}\n\t\t\t}\n//\t\t\tdw = dw * dw % P;\n\t\t\tif (i < h - 1) {\n\t\t\t\tfor (int k = 0; k < 1 << h - i - 2; k++) {\n\t\t\t\t\twws[k] = wws[k * 2];\n\t\t\t\t\tws[k] = ws[k * 2];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tif (dst[i] >= P) {\n\t\t\t\tdst[i] -= P;\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint rev = Integer.reverse(i) >>> -h;\n\t\t\tif (i < rev) {\n\t\t\t\tlong d = dst[i];\n\t\t\t\tdst[i] = dst[rev];\n\t\t\t\tdst[rev] = d;\n\t\t\t}\n\t\t}\n\n\t\tif (inverse) {\n\t\t\tlong in = invl(n, P);\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tdst[i] = modh(dst[i] * in, M, H, P);\n\t\t\t}\n\t\t}\n\n\t\treturn dst;\n\t}\n\n\tstatic final long mask = (1L << 31) - 1;\n\n\tpublic static long modh(long a, long M, int h, int mod) {\n\t\tlong r = a - ((M * (a & mask) >>> 31) + M * (a >>> 31) >>> h - 31) * mod;\n\t\treturn r < mod ? r : r - mod;\n\t}\n\n\tprivate static long[] garnerPrepare(int[] m) {\n\t\tint n = m.length;\n\t\tassert n == m.length;\n\t\tif (n == 0) {\n\t\t\treturn new long[0];\n\t\t}\n\t\tlong[] gamma = new long[n];\n\t\tfor (int k = 1; k < n; k++) {\n\t\t\tlong prod = 1;\n\t\t\tfor (int i = 0; i < k; i++) {\n\t\t\t\tprod = prod * m[i] % m[k];\n\t\t\t}\n\t\t\tgamma[k] = invl(prod, m[k]);\n\t\t}\n\t\treturn gamma;\n\t}\n\n\tprivate static long[] garnerBatch(int[] u, int[] m, long[] gamma) {\n\t\tint n = u.length;\n\t\tassert n == m.length;\n\t\tlong[] v = new long[n];\n\t\tv[0] = u[0];\n\t\tfor (int k = 1; k < n; k++) {\n\t\t\tlong temp = v[k - 1];\n\t\t\tfor (int j = k - 2; j >= 0; j--) {\n\t\t\t\ttemp = (temp * m[j] + v[j]) % m[k];\n\t\t\t}\n\t\t\tv[k] = (u[k] - temp) * gamma[k] % m[k];\n\t\t\tif (v[k] < 0) {\n\t\t\t\tv[k] += m[k];\n\t\t\t}\n\t\t}\n\t\treturn v;\n\t}\n\n\tprivate static long pow(long a, long n, long mod) {\n\t\t//\t\ta %= mod;\n\t\tlong ret = 1;\n\t\tint x = 63 - Long.numberOfLeadingZeros(n);\n\t\tfor (; x >= 0; x--) {\n\t\t\tret = ret * ret % mod;\n\t\t\tif (n << 63 - x < 0) {\n\t\t\t\tret = ret * a % mod;\n\t\t\t}\n\t\t}\n\t\treturn ret;\n\t}\n\n\tprivate 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\tstatic class Scanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer tk = new StringTokenizer(\"\");\n\n\t\tpublic Scanner(InputStream is) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(is));\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\tif (tk.hasMoreTokens())\n\t\t\t\treturn Integer.parseInt(tk.nextToken());\n\t\t\ttk = new StringTokenizer(br.readLine());\n\t\t\treturn nextInt();\n\t\t}\n\n\t\tpublic long nextLong() throws IOException {\n\t\t\tif (tk.hasMoreTokens())\n\t\t\t\treturn Long.parseLong(tk.nextToken());\n\t\t\ttk = new StringTokenizer(br.readLine());\n\t\t\treturn nextLong();\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\tif (tk.hasMoreTokens())\n\t\t\t\treturn (tk.nextToken());\n\t\t\ttk = new StringTokenizer(br.readLine());\n\t\t\treturn next();\n\t\t}\n\n\t\tpublic String nextLine() throws IOException {\n\t\t\ttk = new StringTokenizer(\"\");\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\tif (tk.hasMoreTokens())\n\t\t\t\treturn Double.parseDouble(tk.nextToken());\n\t\t\ttk = new StringTokenizer(br.readLine());\n\t\t\treturn nextDouble();\n\t\t}\n\n\t\tpublic char nextChar() throws IOException {\n\t\t\tif (tk.hasMoreTokens())\n\t\t\t\treturn (tk.nextToken().charAt(0));\n\t\t\ttk = new StringTokenizer(br.readLine());\n\t\t\treturn nextChar();\n\t\t}\n\n\t\tpublic int[] nextIntArray(int n) throws IOException {\n\t\t\tint a[] = new int[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\ta[i] = nextInt();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic long[] nextLongArray(int n) throws IOException {\n\t\t\tlong a[] = new long[n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\ta[i] = nextLong();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic int[] nextIntArrayOneBased(int n) throws IOException {\n\t\t\tint a[] = new int[n + 1];\n\t\t\tfor (int i = 1; i <= n; i++)\n\t\t\t\ta[i] = nextInt();\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic long[] nextLongArrayOneBased(int n) throws IOException {\n\t\t\tlong a[] = new long[n + 1];\n\t\t\tfor (int i = 1; i <= n; i++)\n\t\t\t\ta[i] = nextLong();\n\t\t\treturn a;\n\t\t}\n\n\n\t}\n\n\tpublic static void main(String args[]) throws IOException {\n\t\tnew Thread(null, new Runnable() {\n\t\t\tpublic void run() {\n\t\t\t\ttry {\n\t\t\t\t\tsolve();\n\t\t\t\t} catch (Exception e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t}, \"1\", 1 << 26).start();\n\n\t}\n\n\tstatic void solve() throws IOException {\n\t\tScanner in = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint n=in.nextInt()/2;\n\t\tlong b[]=new long[10];\n\t\tfor(int i=in.nextInt();i>0;i--)\n\t\t\tb[in.nextInt()]=1;\n\t\tlong mod=998244353;\n\t\tlong ans[]=new long[1];\n\t\tans[0]=1;\n\t\twhile(n>0){\n\t\t\tif((n&1)==1){\n\t\t\t\tans=convoluteSimply(ans,b,(int)mod,3);\n\t\t\t\tint sz=ans.length-1;\n\t\t\t\twhile(sz>0 && ans[sz]==0)\n\t\t\t\t\tsz--;\n\t\t\t\tif(ans.length-sz > 100)\n\t\t\t\t\tans=Arrays.copyOf(ans,sz+1);\n\t\t\t}\n\t\t\tn>>=1;\n\t\t\tb=convoluteSimply(b,b,(int)mod,3);\n\t\t\tint sz=b.length-1;\n\t\t\twhile(sz>0 && b[sz]==0)\n\t\t\t\tsz--;\n\t\t\tif(b.length-sz > 100)\n\t\t\t\tb=Arrays.copyOf(b,sz+1);\n\t\t}\n\t\tlong res=0;\n\t\tfor(int i=0;i<ans.length;i++){\n\t\t\tres+=(ans[i]*ans[i]);\n\t\t\tres%=mod;\n\t\t}\n\t\tout.println(res);\n\t\tout.close();\n\n\t}\n}\n", "src_uid": "279f1f7d250a4be6406c6c7bfc818bbf"} {"source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\npublic class cf1 {\n static long mod = (long)1e9 + 7;\n static long mod1 = 998244353;\n static FastScanner f;\n static PrintWriter pw = new PrintWriter(System.out);\n static Scanner S = new Scanner(System.in);\n static long x0; static long y0;\n static int inf = (int)(1e9) + 5;\n static long iinf = (long)(1e18);\n static double eps = (double)1e-4;\n static void solve()throws IOException {\n int a = f.ni(); int b = f.ni();\n int p1 = 0 , p2 = 0 , d = 0;\n for (int i = 1; i <= 6; ++i) {\n int d1 = Math.abs(a - i);\n int d2 = Math.abs(b - i);\n if (d1 == d2) ++d;\n else if (d1 > d2) ++p2;\n else ++p1;\n }\n p(p1 + \" \" + d + \" \" + p2);\n } \n public static void main(String[] args)throws NumberFormatException , IOException {\n init();\n boolean tc = false;\n int t = tc ? f.ni() : 1;\n while(t --> 0) solve();\n pw.flush(); \n pw.close(); \n }\n \n/******************************END OF MAIN PROGRAM*******************************************/\n public static void init()throws IOException{if(System.getProperty(\"ONLINE_JUDGE\")==null){f=new FastScanner(\"\");}else{f=new FastScanner(System.in);}}\n public static class FastScanner {\n BufferedReader br;StringTokenizer st;\n FastScanner(InputStream stream){try{br=new BufferedReader(new InputStreamReader(stream));}catch(Exception e){e.printStackTrace();}}\n FastScanner(String str){try{br=new BufferedReader(new FileReader(\"!a.txt\"));}catch(Exception e){e.printStackTrace();}}\n String next(){while(st==null||!st.hasMoreTokens()){try{st=new StringTokenizer(br.readLine());}catch(IOException e){e.printStackTrace();}}return st.nextToken();}\n String nextLine()throws IOException{return br.readLine();}int ni(){return Integer.parseInt(next());}long nl(){return Long.parseLong(next());}double nd(){return Double.parseDouble(next());}\n }\n public static void pn(Object o){pw.println(o);}\n public static void p(Object o){pw.print(o);}\n public static void pni(Object o){pw.println(o);pw.flush();}\n static int gcd(int a,int b){if(b==0)return a;else{return gcd(b,a%b);}}\n static long gcd(long a,long b){if(b==0l)return a;else{return gcd(b,a%b);}}\n static long lcm(long a,long b){return (a*b/gcd(a,b));}\n static long exgcd(long a,long b){if(b==0){x0=1;y0=0;return a;}long temp=exgcd(b,a%b);long t=x0;x0=y0;y0=t-a/b*y0;return temp;}\n static long pow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=res*a;b>>=1;a=a*a;}return res;}\n static long mpow(long a,long b){long res=1;while(b>0l){if((b&1)==1l)res=((res%mod)*(a%mod))%mod;b>>=1l;a=((a%mod)*(a%mod))%mod;}return res;}\n static long mul(long a , long b){return ((a%mod)*(b%mod)%mod);}\n static long adp(long a , long b){return ((a%mod)+(b%mod)%mod);}\n static int log2(int x){return (int)(Math.log(x)/Math.log(2));}\n static boolean isPrime(long n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(long i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}\n static boolean isPrime(int n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(int i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}\n static HashSet<Long> factors(long n){HashSet<Long> hs=new HashSet<Long>();for(long i=1;i<=(long)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}\n static HashSet<Integer> factors(int n){HashSet<Integer> hs=new HashSet<Integer>();for(int i=1;i<=(int)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}\n static HashSet<Long> pf(long n){HashSet<Long> ff=factors(n);HashSet<Long> res=new HashSet<Long>();for(Long i:ff)if(isPrime(i))res.add(i);return res;}\n static HashSet<Integer> pf(int n){HashSet<Integer> ff=factors(n);HashSet<Integer> res=new HashSet<Integer>();for(Integer i:ff)if(isPrime(i))res.add(i);return res;}\n static int[] inpint(int n){int arr[]=new int[n+1];for(int i=1;i<=n;++i){arr[i]=f.ni();}return arr;}\n static long[] inplong(int n){long arr[] = new long[n+1];for(int i=1;i<=n;++i){arr[i]=f.nl();}return arr;}\n static boolean ise(int x){return ((x&1)==0);}static boolean ise(long x){return ((x&1)==0);}\n static int gnv(char c){return Character.getNumericValue(c);}//No. of integers less than equal to i in ub\n static int log(long x){return x==1?0:(1+log(x/2));} static int log(int x){return x==1?0:(1+log(x/2));}\n static int upperbound(int a[],int i){int lo=0,hi=a.length-1,mid=0;int count=0;while(lo<=hi){mid=(lo+hi)/2;if(a[mid]<=i){count=mid+1;lo=mid+1;}else hi=mid-1;}return count;}\n static void sort(int[] a){ArrayList<Integer> l=new ArrayList<>();for(int i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}\n static void sort(long[] a){ArrayList<Long> l=new ArrayList<>();for(long i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}\n static void sort(ArrayList<Integer> a){Collections.sort(a);}//!Precompute fact in ncr()!\n static int nextPowerOf2(int n){int count=0;if(n>0&&(n&(n-1))==0)return n;while(n!=0){n>>=1;count += 1;}return 1<<count;} \n}", "src_uid": "504b8aae3a3abedf873a3b8b127c5dd8"} {"source_code": "import java.io.*;\nimport java.util.Arrays;\n\npublic class Titles\n{\n public static String replaceIndex(String str, int i, char c)\n {\n String result = str.substring(0, i) + c\n + str.substring(i + 1, str.length());\n return result;\n }\n\n static boolean finished = false;\n public static int getFFlse(boolean[] a)\n {\n int index = 0;\n int i;\n for (i = a.length - 1; i > -1; i--)\n {\n if (!a[i])\n {\n index = i;\n break;\n }\n }\n if(i == -1)\n finished = true;\n return index;\n }\n\n public static void main(String[] args) throws IOException\n {\n// while(true)\n// {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n int n = Integer.parseInt(br.readLine());\n String str = br.readLine();\n int len = str.length();\n boolean[] valid = new boolean[n];\n boolean flag = true;\n\n for (int i = 0; i < str.length() ; i++)\n {\n if (str.charAt(i) != '?')\n valid[str.charAt(i) - 'a'] = true;\n }\n\n for (int i = (int)Math.ceil(len / 2); i >= 0 && len > 1; i--)\n {\n// System.out.println(str);\n if (str.charAt(i) == str.charAt(len - 1 - i))\n {\n if (str.charAt(i) == '?')\n {\n char toReplace = (char) ((int) 'a' + getFFlse(valid));\n str = replaceIndex(str, i, toReplace);\n str = replaceIndex(str, len - 1 - i, toReplace);\n valid[toReplace - 'a'] = true;\n }\n } else\n {\n if (str.charAt(i) == '?')\n {\n str = replaceIndex(str, i, str.charAt(len - 1 - i));\n } else if (str.charAt(len - 1 - i) == '?')\n {\n str = replaceIndex(str, len - 1 - i, str.charAt(i));\n\n } else\n {\n flag = false;\n break;\n }\n }\n }\n \n getFFlse(valid);\n if (!finished)\n {\n// System.out.println(\"not valid\");\n// System.out.println(Arrays.toString(valid));\n flag = false;\n }\n\n if(len == 1 && n == 1)\n {\n str = \"a\";\n flag = true;\n }\n if (flag)\n System.out.println(str);\n else\n System.out.println(\"IMPOSSIBLE\");\n finished = false;\n// }\n }\n}", "src_uid": "9d1dd9d722e5fe46823224334b3b208a"} {"source_code": "//Date: Oct 8, 2013 \n//Time: 11:52:15 PM\n\nimport java.util.*;\nimport java.io.*;\n\npublic class A203 implements Runnable {\n\n\tpublic void solve() throws IOException {\n\t\tint x = nextInt();\n\t\tint t = nextInt();\n\t\tint a = nextInt();\n\t\tint b = nextInt();\n\t\tint da = nextInt();\n\t\tint db = nextInt();\n\t\t\n\t\tboolean possible = false;\n\t\t\n\t\tfor(int i = 0; i < t; i++)\n\t\t\tfor(int j = 0; j < t; j++){\n\t\t\t\tif(a - (da * i) + b - (db * j) == x) \n\t\t\t\t{\n\t\t\t\t\tpossible = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif(a - (da * i) == x){\n\t\t\t\t\tpossible = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif(b - (db * j) == x){\n\t\t\t\t\tpossible = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\n\t\tif(possible || x == 0) System.out.println(\"YES\");\n\t\telse System.out.println(\"NO\");\n\t}\n\n\t\n\t\n\t\n\t\n\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\t\tnew A203().run();\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\ttok = null;\n\t\t\tsolve();\n\t\t\tin.close();\n\t\t} catch (IOException e) {\n\t\t\tSystem.exit(0);\n\t\t}\n\t}\n\n\tpublic String nextToken() 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 int nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tpublic long nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tpublic double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tBufferedReader in;\n\tStringTokenizer tok;\n}\n/**\npublic class A203 {\n\n}\n \n*/", "src_uid": "f98168cdd72369303b82b5a7ac45c3af"} {"source_code": "import java.io.*;\nimport java.lang.Math;\nimport java.util.Scanner;\nimport java.math.BigInteger;\nimport java.util.StringTokenizer;\n\npublic class main\n{\n public static Scanner in;\n public static PrintStream out;\n\t\t\n\t\tpublic static long fnk[][];\n\t\tpublic static long tnk[][];\n\t\t\n\t\tpublic static long d10[];\n\t\tpublic static long d8[];\n\t\t\n\t\tpublic static long M = 1000000007;\n\t\t\n\t\tstatic int K;\n\t\t\n\t\tpublic static long _Fnk(int n, int k)\n\t\t{\n\t\t\tif (n<2)\n\t\t\t{\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\t\n\t\t\treturn (2*Tnk(n-1, k)+ 8*Fnk(n-1, k) + 2*Pnk(n-1, k, k)) % M;\n\t\t}\n\t\t\n\t\t\n\t\tpublic static long Fnk(int n, int k)\n\t\t{\n\t\t\tif (fnk[n][k]==-1)\t\t\t\n\t\t\t{\n\t\t\t\tfnk[n][k] = _Fnk(n,k);\n\t\t\t}\n\t\t\treturn fnk[n][k];\n\t\t}\n\t\t\n\t\t\n\t\tpublic static long Tnk(int n, int k)\n\t\t{\n\t\t\tif (tnk[n][k]==-1)\t\t\t\n\t\t\t{\n\t\t\t\ttnk[n][k] = _Tnk(n,k);\n\t\t\t}\n\t\t\treturn tnk[n][k];\n\t\t}\n\t\t\n\t\t\n\t\tpublic static long Pnk(int n, int r,int k)\n\t\t{\n\t\t\tif (n-r<2)\n\t\t\t{\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\t\n\t\t\treturn D8(r)*Fnk(n-r,k) % M;\n\t\t}\n\t\t\n\t\tpublic static long _Tnk(int n, int k)\n\t\t{\n\t\t\tif (k<1)\n\t\t\t{\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\t\n\t\t\tif (n<1)\n\t\t\t{\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\t\n\t\t\tif (n>k)\n\t\t\t{\n\t\t\t\treturn 10*Tnk(n-1, k) % M;\n\t\t\t}\n\t\t\t\n\t\t\treturn (2*D(n-1)+8*Tnk(n-1, k-1)) % M;\n\t\t}\n\t\t\n\t\tpublic static long D(int n)\n\t\t{\n\t\t\tif (n==0)\n\t\t\t{\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t\t\n\t\t\tif (d10[n]==-1)\n\t\t\t{\n\t\t\t\td10[n] = BigInteger.valueOf(10).modPow(BigInteger.valueOf(n), BigInteger.valueOf(M)).longValue();\n\t\t\t}\n\t\t\t\n\t\t\treturn d10[n];\n\t\t}\n\t\t\n\t\tpublic static long D8(int n)\n\t\t{\n\t\t\tif (n==0)\n\t\t\t{\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t\t\n\t\t\tif (d8[n]==-1)\n\t\t\t{\n\t\t\t\td8[n] = BigInteger.valueOf(8).modPow(BigInteger.valueOf(n), BigInteger.valueOf(M)).longValue();\n\t\t\t}\n\t\t\t\n\t\t\treturn d8[n];\n\t\t}\n\t\t\n\t\tpublic static long F(String s, int k)\n\t\t{\t\n\t\t\tint n = s.length();\n\t\t\t\n\t\t\tif (n<2)\n\t\t\t{\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\t\n\t\t\tlong r1,r2=0,r = 0;\n\t\t\t\n\t\t\tint d = Integer.parseInt(String.valueOf(s.charAt(0)));\n\t\t\t\n\t\t\tif (d>0)\n\t\t\t{\n\t\t\t\tr1 = Fnk(n-1, k) % M;\n\t\t\t\tif (d>4)\n\t\t\t\t{\n\t\t\t\t\tr2 = (Tnk(n-1, k) + Pnk(n-1, k, k)) % M;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (d<5)\n\t\t\t\t{\n\t\t\t\t\tr += d* r1;\n\t\t\t\t}\n\t\t\t\telse if (d<8)\n\t\t\t\t{\n\t\t\t\t\tr += (d-1)* r1 + r2;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tr += (d-2)* r1 + 2*r2;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tString s2 = s.substring(1);\n\t\t\t\n\t\t\tif ((d==4)||(d==7))\n\t\t\t{\n\t\t\t\tr += (T(s2, k) + P(s2, k, k)) % M;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tr += F(s2, k) % M;\n\t\t\t}\n\t\t\t\n\t\t\treturn r % M;\n\t\t}\n\t\t\n\t\tpublic static long T(String s, int k)\n\t\t{\n\t\t\tif (k<1)\n\t\t\t{\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\t\n\t\t\tint n = s.length();\n\t\t\t\n\t\t\t\n\t\t\tif (n==0)\n\t\t\t{\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\tlong r1,r2=0,r = 0;\n\t\t\t\n\t\t\tint d = Integer.parseInt(String.valueOf(s.charAt(0)));\n\t\t\t\n\t\t\t\n\t\t\tif (d>0)\n\t\t\t{\n\t\t\t\tr1 = Tnk(n-1, k-1) % M;\n\t\t\t\tif (d>4)\n\t\t\t\t{\n\t\t\t\t\tr2 = D(n-1);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (d<5)\n\t\t\t\t{\n\t\t\t\t\tr += d* r1;\n\t\t\t\t}\n\t\t\t\telse if (d<8)\n\t\t\t\t{\n\t\t\t\t\tr += (d-1)* r1 + r2;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tr += (d-2)* r1 + 2*r2;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\t\t\t\n\t\t\tString s2 = s.substring(1);\n\t\t\t\n\t\t\tif ((d==4)||(d==7))\n\t\t\t{\n\t\t\t\tif (s2.length()==0)\n\t\t\t\t{\n\t\t\t\t\tr+= 1;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tBigInteger b = new BigInteger(s2);\n\t\t\t\t\tr += b.add(BigInteger.ONE).mod(BigInteger.valueOf(M)).longValue();\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tr += T(s2, k-1);\n\t\t\t}\n\t\t\t\n\t\t\treturn r % M;\n\t\t}\n\t\t\n\t\t\n\t\tpublic static long P(String s, int r, int k)\n\t\t{\n\t\t\tint n = s.length();\n\n\t\t\tif (n-r<2)\n\t\t\t{\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\t\n\t\t\tif (k==0)\n\t\t\t{\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\t\n\t\t\tif (r==0)\n\t\t\t{\n\t\t\t\treturn F(s,k);\n\t\t\t}\n\t\t\t\n\t\t\tlong r1,r2=0,rs = 0;\n\t\t\t\n\t\t\tint d = Integer.parseInt(String.valueOf(s.charAt(0)));\n\t\t\t\n\t\t\t\n\t\t\tif (d>0)\n\t\t\t{\n\t\t\t\tr1 = Pnk(n-1, r-1, k) % M;\n\t\t\t\t\n\t\t\t\tif (d<5)\n\t\t\t\t{\n\t\t\t\t\trs += d* r1;\n\t\t\t\t}\n\t\t\t\telse if (d<8)\n\t\t\t\t{\n\t\t\t\t\trs += (d-1)* r1 ;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\trs += (d-2)* r1 ;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tString s2 = s.substring(1);\n\t\t\t\n\t\t\tif ((d==4)||(d==7))\n\t\t\t{\n\t\t\t\trs += 0;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\trs += P(s2, r-1, k);\n\t\t\t}\n\t\t\t\n\t\t\treturn rs % M;\n\t\t}\n \n \n public static void test()\n {\n\t\t\tString ln;\n\t\t\tdo {\n\t\t\t\tln = in.nextLine();\n\t\t\t} while (ln.length()==0);\n\t\t\t\n\t\t\tStringTokenizer st = new StringTokenizer(ln);\n\t\t\n String l,r;\n\t\t\t l = st.nextToken();\n\t\t\t r = st.nextToken();\n\t\t\t \n\t\t\t BigInteger bl = new BigInteger(l);\n\t\t\t \n\t\t\t long s = (M + F(r, K) - F(bl.subtract(BigInteger.ONE).toString(), K)) % M;\n\t\t\t \n\t\t\t out.println(s);\n\t\t\t \n }\n \n public static void main(String args[])\n {\n try\n {\n //in = new Scanner(new File(\"in.txt\"));\n //out = new PrintStream(new File(\"out.txt\")); \n in = new Scanner(System.in);\n out = System.out;\n }\n catch (Exception e)\n {\n return;\n }\n \n\t\t\t\tint t,i,j;\n\t\t\t\t\n\t\t\t\tt = in.nextInt();\n\t\t\t\tK = in.nextInt();\n\t\t\t\t\n\t\t\t\tfnk = new long[1001][];\n\t\t\t\ttnk = new long[1001][];\n\t\t\t\td8 = new long[1001];\n\t\t\t\td10 = new long[1001];\n\t\t\t\t\n\t\t\t\tfor (i=0;i<1001;i++)\n\t\t\t\t{\n\t\t\t\t\tfnk[i] = new long[K+1];\n\t\t\t\t\ttnk[i] = new long[K+1];\n\t\t\t\t\t\n\t\t\t\t\td8[i] = -1;\n\t\t\t\t\td10[i] = -1;\n\t\t\t\t\t\n\t\t\t\t\tfor (j=0; j<=K; j++)\n\t\t\t\t\t{\n\t\t\t\t\t\tfnk[i][j] = -1;\n\t\t\t\t\t\ttnk[i][j] = -1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tfor (i=0; i<t; i++)\n\t\t\t\t{\n\t\t\t\t\ttest();\n\t\t\t\t}\n \n\n\t\t\t\t//\tout.println(T(\"41883\", 3));\n \n }\n}\n\n", "src_uid": "5517efa2fc9362fdf342d32adac889f4"} {"source_code": "import java.util.*;\npublic class B\n{\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in); in.nextLine(); \n System.out.println(Long.parseLong(new StringBuilder(in.nextLine().replaceAll(\"R\",\"0\").replaceAll(\"B\",\"1\")).reverse().toString(),2));\n }\n}", "src_uid": "d86a1b5bf9fe9a985f7b030fedd29d58"} {"source_code": "import java.util.*;\nimport java.io.*;\n \npublic class Main{\n\tstatic class Point{\n\t\tint x; long y;\n\t\tPoint(int nx, long ny){\n\t\t\tx = nx; y = ny;\n\t\t}\n\t}\n\tstatic long mod = (long)(1e9 + 7);\n\tstatic int MAXN = (int)(4e5 + 5);\n\tstatic long[] dp = new long[MAXN];\n\tstatic long[] a;\n\tstatic boolean[] v = new boolean[MAXN];\n public static void main(String[] args) throws IOException{\n \tIn in = new In();\n \tin.tok();\n \tint n = in.pint(), k = in.pint();\n \ta = new long[n];\n \tin.tok();\n \tfor(int i = 0; i < n; i++) {a[i] = -in.pint();}\n \tArrays.sort(a);\n \tfor(int i = 0; i < n; i++) {a[i] = -a[i];}\n \tlong ttl = 0;\n \tint si = 0;\n \tlong s = a[0];\n \twhile(s >= 0 && si < n - 1) {\n \t\tttl += s;\n \t\tsi++;\n \t\ts += a[si];\n \t}\n \tif(si >= n - 1) {System.out.println(ttl); return;}\n \ta[si] = s;\n \tint p = 0;\n \tint mul = 0;\n \tfor(int i = n - 1; i >= si; i--) {\n \t\tttl += a[i] * mul;\n \t\tp++;\n \t\tif(p % (k + 1) == 0) {mul++;}\n \t}\n \tSystem.out.println(ttl);\n }\n}\n \n \nclass In{\n BufferedReader in;\n StringTokenizer st = new StringTokenizer(\"\");\n public In(){\n in = new BufferedReader(new InputStreamReader(System.in));\n }\n \n int pint() throws IOException{\n if(st.hasMoreTokens()) {return Integer.parseInt(st.nextToken());}\n else {return Integer.parseInt(in.readLine());}\n }\n double pdbl() throws IOException{\n if(st.hasMoreTokens()) {return Double.parseDouble(st.nextToken());}\n else {return Double.parseDouble(in.readLine());}\n }\n long plng() throws IOException{\n if(st.hasMoreTokens()) {return Long.parseLong(st.nextToken());}\n else {return Long.parseLong(in.readLine());}\n }\n char pchr() throws IOException{\n if(st.hasMoreTokens()) {return st.nextToken().charAt(0);}\n else {return in.readLine().charAt(0);}\n }\n String pstr() throws IOException{\n if(st.hasMoreTokens()) {return st.nextToken();}\n else {return in.readLine();}\n }\n String readLine() throws IOException{\n \treturn in.readLine();\n }\n boolean ready() throws IOException {return in.ready();}\n void tok() throws IOException{st = new StringTokenizer(in.readLine());}\n void skip() throws IOException{in.readLine();}\n}", "src_uid": "53155daf2375e01a3b87fa1c76f1e9a8"} {"source_code": "import java.util.*;\r\n\r\npublic class Main{\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 n = sc.nextInt();\r\n System.out.println((int)Math.pow(2,n)-1);\r\n }\r\n }\r\n\r\n}\r\n ", "src_uid": "d5e66e34601cad6d78c3f02898fa09f4"} {"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 Puskar\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskA solver = new TaskA();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskA {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n long a = in.nextLong();\n long b = in.nextLong();\n long c = in.nextLong();\n\n long sum1 = a + b + c;\n long sum2 = a + a + b + b;\n long sum3 = a + a + c + c;\n long sum4 = b + b + c + c;\n\n out.println(Math.min(Math.min(Math.min(sum1, sum2), sum3), sum4));\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public long nextLong() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "src_uid": "26cd7954a21866dbb2824d725473673e"} {"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\n in.populate(xs);\n Randomized.shuffle(xs);\n Arrays.sort(xs);\n SequenceUtils.reverse(xs);\n boolean[] retain = new boolean[n];\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 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 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 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 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 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", "src_uid": "816a82bee65cf79ba8e4d61babcd0301"} {"source_code": "\nimport com.sun.org.apache.bcel.internal.generic.AALOAD;\nimport java.io.*;\nimport java.util.*;\nimport java.math.BigInteger.*;\nimport static java.lang.Math.*;\nimport static java.math.BigInteger.*;\nimport static java.util.Arrays.*;\nimport java.util.logging.Level;\nimport java.util.logging.Logger;\n\n// https://netbeans.org/kb/73/java/editor-codereference_ru.html#display\n//<editor-fold defaultstate=\"collapsed\" desc=\"Main\">\npublic class Main {\n\n private void run() {\n Locale.setDefault(Locale.US);\n boolean oj = true;\n try {\n oj = System.getProperty(\"MYLOCAL\") == null;\n } catch (Exception e) {\n }\n\n if (oj) {\n sc = new FastScanner(new InputStreamReader(System.in));\n out = new PrintWriter(new OutputStreamWriter(System.out));\n } else {\n try {\n sc = new FastScanner(new FileReader(\"input.txt\"));\n out = new PrintWriter(new FileWriter(\"output.txt\"));\n } catch (IOException e) {\n MLE();\n }\n }\n Solver s = new Solver();\n s.sc = sc;\n s.out = out;\n s.solve();\n if (!oj) {\n err.println(\"Time: \" + (System.currentTimeMillis() - timeBegin) / 1e3);\n err.printf(\"Mem: %d\\n\", (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) >> 20);\n }\n out.flush();\n }\n\n private void show(int[] arr) {\n for (int v : arr) {\n err.print(\" \" + v);\n }\n err.println();\n }\n\n public static void MLE() {\n int[][] arr = new int[1024 * 1024][];\n for (int i = 0; i < arr.length; i++) {\n arr[i] = new int[1024 * 1024];\n }\n }\n\n public static void main(String[] args) {\n new Main().run();\n }\n\n long timeBegin = System.currentTimeMillis();\n FastScanner sc;\n PrintWriter out;\n PrintStream err = System.err;\n}\n//</editor-fold>\n\n//<editor-fold defaultstate=\"collapsed\" desc=\"FastScanner\">\nclass FastScanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n FastScanner(InputStreamReader reader) {\n br = new BufferedReader(reader);\n st = new StringTokenizer(\"\");\n }\n\n String next() {\n while (!st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException ex) {\n Main.MLE();\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//</editor-fold>\n\nclass Node{\n static Random rnd = new Random();\n// {\n// for (int i = 0; i < 10; i++) {\n// System.err.println(rnd.nextInt());\n// }\n// }\n int val, sz, prior;\n Node l, r;\n \n Node( int val ){\n this.val = val;\n sz = 1;\n prior = rnd.nextInt();\n l = r = null;\n }\n\n @Override\n public String toString() {\n return val + \"\";\n }\n}\n\nclass Solver {\n\n FastScanner sc;\n PrintWriter out;\n PrintStream err = System.err;\n\n Random rnd = new Random();\n \n int getCnt( Node t ){ \n return t==null? 0 : t.sz;\n }\n \n void upd(Node t) {\n t.sz = 1 + getCnt(t.l) + getCnt(t.r);\n }\n \n Node firstElement;\n Node pollFirst(Node t){\n Node root = t;\n Node parent = null;\n while( t.l != null ){\n --t.sz;\n parent = t;\n t = t.l;\n }\n\n if( parent == null ){\n root = t.r;\n }\n else{\n parent.l = t.r;\n upd( parent );\n }\n firstElement = t;\n firstElement.l = firstElement.r = null;\n firstElement.sz = 1;\n return root;\n }\n \n Node insert( Node t, Node it, int key, int add ){\n if( t == null ){\n return it;\n }\n int curKey = add + 1 + getCnt(t.l);\n if( t.prior > it.prior ){\n if (curKey < key)\n t.r = insert( t.r, it, key, curKey );\n else\n t.l = insert( t.l, it, key, add );\n upd( t );\n return t;\n }\n else{\n split( t, key-1, add );\n it.l = l2;\n it.r = r2;\n upd( it );\n return it;\n }\n }\n\n void split( Node t, int key, int add ){\n curRec = 0;\n split2(t, key, add);\n maxRec = max( maxRec, curRec );\n if( 45 <= curRec ){\n maxRec = 0;\nMain.MLE();\n err.println( \"rebuilding...\" );\n l2 = rebuild(l2);\n r2 = rebuild(r2);\n }\n }\n \n Node rebuild(Node t){\n szArr = 0;\n dfs( t );\n t = build(0, szArr-1);\n return t;\n }\n \n Node l2, r2;\n void split2( Node t, int key, int add ){\n ++curRec;\n if( t == null ){\n l2 = r2 = null;\n return;\n }\n \n int curKey = add + 1 + getCnt(t.l);\n if( curKey <= key ){\n split2(t.r, key, curKey);\n t.r = l2;\n l2 = t;\n }\n else{\n split2(t.l, key, add);\n t.l = r2;\n r2 = t;\n }\n upd(t);\n }\n\n int szArr;\n Node[] arr;\n void dfs( Node t ){\n if( t == null ) return;\n dfs( t.l );\n arr[szArr++] = t;\n dfs( t.r );\n }\n \n void show( Node t, int cnt ){\n if( t == null ) return;\n \n String s = \" \";\n for( int i = 0; i < cnt; ++i ) out.print(s);\n out.println(t.val +\" \"+ t.prior);\n \n if( t.l != null ){\n for( int i = 0; i < cnt; ++i ) out.print(s);\n out.println(\"l*\");\n show( t.l, cnt+1 );\n }\n \n if( t.r != null ){\n for( int i = 0; i < cnt; ++i ) out.print(s);\n out.println(\"r*\");\n show( t.r, cnt+1 );\n }\n }\n \n Node build( int l, int r ){\n if(!( l <= r )){\n return null;\n }\n else{\n int tm = (l + r) / 2;\n Node t = arr[tm];\n t.l = build( l, tm-1 );\n t.r = build( tm+1, r );\n upd( t );\n return t;\n }\n }\n\n\n int curRec, maxRec = 0;\n \n void solve(){\n //deb();\n int n, q;\n Node t;\n\n n = sc.nextInt();\n q = sc.nextInt();\n \n \n arr = new Node[n];\n for (int i = 0; i < n; i++) arr[i] = new Node(-1);\n t = build( 0, n-1 );\n\n int[] vals = new int[q];\n int[] poss = new int[q];\n for (int iter = 0; iter < q; iter++) {\n vals[iter] = sc.nextInt();\n poss[iter] = sc.nextInt();\n }\n \n \n boolean[] haveVal = new boolean[n+1];\n haveVal[0] = true;\n\n for( int iter = q-1; 0 <= iter; --iter ){\n int val = vals[iter];\n int pos = poss[iter];\n\n t = pollFirst(t);\n if( getCnt(t) != n-1 ) Main.MLE();\n if( firstElement.val == -1 ){\n if( haveVal[val] ){\n out.println(\"-1\");\n return;\n }\n firstElement.val = val;\n }\n else if( firstElement.val == val );\n else{\n out.println(\"-1\");\n return;\n }\n \n haveVal[val] = true;\n t = insert( t, firstElement, pos, 0 );\n }\n\n err.println( \"maxRec: \" + maxRec );\n \n szArr = 0; dfs( t );\n\n int ptr = 1;\n for( int i = 0; i < n; ++i )\n if( arr[i].val == -1 ){\n while( haveVal[ptr] ) ++ptr;\n arr[i].val = ptr++;\n }\n \n for( Node v : arr ) \n out.print( \" \" + v.val );\n out.println();\n }\n}\n", "src_uid": "a2616b1681f30ce4b2a5fdc81cf52b50"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CopyOfPermutations {\n\n\tfinal String filename = new String(\"Permutations\").toLowerCase();\n\n\tvoid solve() throws Exception {\n\t\tString s = in.readLine();\n\t\tint n = s.length();\n\t\tint[] cnt = new int[10];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tcnt[(int) (s.charAt(i) - '0')]++;\n\t\t}\n\n\t\tint bestAns = 0;\n\t\tint bestZeros = 0;\n\t\tint bestFirst = 0;\n\n\t\tfor (int zeros = 0; zeros <= cnt[0]; zeros++) {\n\t\t\tfor (int first = 1; first < 10; first++) {\n\t\t\t\tint[] cnt1 = cnt.clone();\n\t\t\t\tint[] cnt2 = cnt.clone();\n\t\t\t\tcnt1[0] -= zeros;\n\t\t\t\tcnt2[0] -= zeros;\n\t\t\t\tint curAns = zeros;\n\t\t\t\tboolean ok = false;\n\t\t\t\tif (cnt1[first] > 0 && cnt2[10 - first] > 0) {\n\t\t\t\t\tcnt1[first]--;\n\t\t\t\t\tcnt2[10 - first]--;\n\t\t\t\t\tcurAns++;\n\t\t\t\t\t\n\t\t\t\t\tok = true;\n\t\t\t\t\tfor (int i = 0; i < 10; i++) {\n\t\t\t\t\t\tcurAns += Math.min(cnt1[i], cnt2[9 - i]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (curAns > bestAns) {\n\t\t\t\t\tbestAns = curAns;\n\t\t\t\t\tbestZeros = zeros;\n\t\t\t\t\tif (ok)\n\t\t\t\t\t\tbestFirst = first;\n\t\t\t\t\telse\n\t\t\t\t\t\tbestFirst = -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (bestAns == 0) {\n\t\t\tout.println(s);\n\t\t\tout.println(s);\n\t\t} else {\n\t\t\tArrayList<Integer> ans1 = new ArrayList<Integer>();\n\t\t\tArrayList<Integer> ans2 = new ArrayList<Integer>();\n\t\t\tint[] cnt1 = cnt.clone();\n\t\t\tint[] cnt2 = cnt.clone();\n\t\t\tfor (int i = 0; i < bestZeros; i++) {\n\t\t\t\tans1.add(0);\n\t\t\t\tans2.add(0);\n\t\t\t}\n\t\t\tcnt1[0] -= bestZeros;\n\t\t\tcnt2[0] -= bestZeros;\n\n\t\t\tif (bestFirst != -1) {\n\t\t\t\tans1.add(bestFirst);\n\t\t\t\tans2.add(10 - bestFirst);\n\t\t\t\tcnt1[bestFirst]--;\n\t\t\t\tcnt2[10 - bestFirst]--;\n\n\t\t\t\tfor (int i = 0; i < 10; i++) {\n\t\t\t\t\tint j = 9 - i;\n\t\t\t\t\twhile (cnt1[i] > 0 && cnt2[j] > 0) {\n\t\t\t\t\t\tans1.add(i);\n\t\t\t\t\t\tans2.add(j);\n\t\t\t\t\t\tcnt1[i]--;\n\t\t\t\t\t\tcnt2[j]--;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int i = 0; i < 10; i++) {\n\t\t\t\twhile (cnt1[i] > 0) {\n\t\t\t\t\tans1.add(i);\n\t\t\t\t\tcnt1[i]--;\n\t\t\t\t}\n\t\t\t\twhile (cnt2[i] > 0) {\n\t\t\t\t\tans2.add(i);\n\t\t\t\t\tcnt2[i]--;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tCollections.reverse(ans1);\n\t\t\tCollections.reverse(ans2);\n\n\t\t\tfor (int i : ans1) {\n\t\t\t\tout.print(i);\n\t\t\t}\n\t\t\tout.println();\n\t\t\tfor (int i : ans2) {\n\t\t\t\tout.print(i);\n\t\t\t}\n\t\t}\n\t}\n\n\tvoid run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\t// in = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\t// out = new PrintWriter(\"output.txt\");\n\n\t\t\tsolve();\n\n\t\t\tout.close();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n\n\tBufferedReader in;\n\tStringTokenizer st;\n\tPrintWriter out;\n\n\tString 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\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\n\tpublic static void main(String[] args) {\n\t\tnew CopyOfPermutations().run();\n\t}\n\n}\n", "src_uid": "34b67958a37865e1ca0529bbf528dd9a"} {"source_code": "//package round76;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class D2 {\n\tScanner in;\n\tString INPUT = \"\";\n\tPrintWriter out;\n\t\n\tstatic int MOD = 1000000007;\n\t\n\tvoid solve()\n\t{\n\t\tint L = ni();\n\t\tint R = ni();\n\t\tString[] t = {\" \", \" B\", \" R\", \" W\", \" Y\", \"BW\", \"BY\", \"RW\", \"RY\", \"WB\", \"WR\", \"YB\", \"YR\"};\n\t\tint m = t.length;\n\t\tint[][] M = new int[m+1][m+1];\n\t\tfor(int i = 0;i < m;i++){\n\t\t\tfor(int j = 0;j < m;j++){\n\t\t\t\tif(t[i].charAt(1) == t[j].charAt(0)){\n\t\t\t\t\tM[j][i] = 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tM[0][0] = 0;\n\t\tM[10][5] = 0;\n\t\tM[9][7] = 0;\n\t\tfor(int i = 0;i <= m;i++) {\n\t\t\tM[m][i] = 1;\n\t\t}\n\t\t\n\t\tint[][][] A = generateP2(M, 30);\n\t\t\n\t\tint[] v = new int[]{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};\n\t\tint[] gp1 = pow(A, v, R+1);\n\t\tint[] gp2 = pow(A, v, L-1+1);\n\t\t\n\t\tint[] gpq1 = pow(A, v, (R+1)/2+1);\n\t\tint[] gpq2 = pow(A, v, L/2+1);\n\t\t\n\t\tlong i2 = inv(2, MOD);\n\t\t\n\t\tlong sum = 0;\n\t\tsum += (gp1[m]-gp2[m]-gpq1[m]+gpq2[m])*i2+(gpq1[m]-gpq2[m]);\n\t\tsum %= MOD;\n\t\tout.println((sum+MOD)%MOD);\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\t\n\tpublic static int[][][] generateP2(int[][] A, int n)\n\t{\n\t\tint[][][] ret = new int[n+1][][];\n\t\tret[0] = A;\n\t\tfor(int i = 1;i <= n;i++)ret[i] = p2(ret[i-1]);\n\t\treturn ret;\n\t}\n\t\n\tpublic static int[] pow(int[][][] A, int[] v, long e)\n\t{\n\t\tfor(int i = 0;e > 0;e>>>=1,i++) {\n\t\t\tif((e&1)==1)v = mul(A[i], v);\n\t\t}\n\t\treturn v;\n\t}\n\t\n\tpublic static int[][] p2(int[][] A)\n\t{\n\t\tint n = A.length;\n\t\tint[][] C = 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\tlong sum = 0;\n\t\t\t\tfor(int k = 0;k < n;k++){\n\t\t\t\t\tsum += (long)A[i][k] * A[k][j];\n\t\t\t\t\tsum %= MOD;\n\t\t\t\t}\n\t\t\t\tC[i][j] = (int)sum;\n\t\t\t}\n\t\t}\n\t\treturn C;\n\t}\n\t\n\tpublic static int[] mul(int[][] A, int[] v)\n\t{\n\t\tint m = A.length;\n\t\tint n = v.length;\n\t\tint[] w = new int[m];\n\t\tfor(int i = 0;i < m;i++){\n\t\t\tlong sum = 0;\n\t\t\tfor(int k = 0;k < n;k++){\n\t\t\t\tsum += (long)A[i][k] * v[k];\n\t\t\t\tsum %= MOD;\n\t\t\t}\n\t\t\tw[i] = (int)sum;\n\t\t}\n\t\treturn w;\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 D2().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", "src_uid": "e04b6957d9c1659e9d2460410cb57f10"} {"source_code": "//package com.company;\n\n//import java.io.File;\n//import java.io.FileNotFoundException;\n//import java.nio.charset.StandardCharsets;\nimport java.util.*;\nimport java.io.*;\n\n public class Main {\n\n public static void main(String[] args) {\n\n //File file = new File(\"/Users/ahmed/Development/CompetitiveProgramming\\ git java/src/com/company/in.txt\");\n //Scanner scanner = new Scanner(file);\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int[] nums = new int[n];\n for (int i = 0; i < n; i++) {\n nums[i] = in.nextInt();\n }\n\n\n\n\n System.out.print(loopthough(n,nums));\n }\n\n private static String loopthough(int n, int[] nums) {\n String result = \"NO\";\n for (int i = 0; i < n ; i++) {\n for (int j = 0; j < n && j!=i ; j++) {\n for (int k = 0; k < n && k!=j; k++) {\n if (i == j || j==k || k==i)// same index\n continue;\n int a = nums[i];\n int b = nums[j];\n int c = nums[k];\n if (a+b>c && a+c>b && b+c>a) {\n\n return \"YES\";\n }\n }\n }\n }\n return result;\n }\n }\n", "src_uid": "897bd80b79df7b1143b652655b9a6790"} {"source_code": "import java.util.*;\nimport java.io.*;\n\npublic class ForProblems {\n\n BufferedReader in;\n PrintWriter out;\n StringTokenizer tok = new StringTokenizer(\"\");\n\n final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\n public static void main(String[] args){\n\n new ForProblems().run();\n }\n\n public void run() {\n\n try {\n long timeBegin = System.currentTimeMillis();\n Locale.setDefault(Locale.US);\n\n init();\n solve();\n\n out.close();\n\n long timeEnd = System.currentTimeMillis();\n System.err.println(\"Time = \" + (timeEnd - timeBegin));\n } catch (Exception e) {\n e.printStackTrace(System.err);\n System.exit(-1);\n }\n }\n\n void init() throws FileNotFoundException {\n\n Locale.setDefault(Locale.US);\n\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 Random rnd = new Random();\n\n\n void solve() throws IOException {\n\n int r = readInt();\n int c = readInt();\n int n = readInt();\n int k = readInt();\n int[][] a = new int[r][c];\n for (int i = 0; i < n; ++i) {\n int b = readInt() - 1;\n int d = readInt() - 1;\n a[b][d] = 1;\n }\n\n int ans = 0;\n for (int i = 0; i < r; ++i) {\n for (int j = 0; j < c; ++j) {\n int sum = a[i][j];\n if (sum >= k)\n ++ans;\n int[] prevSum = new int[c];\n prevSum[j] = a[i][j];\n for (int q = i; q < r; ++q) {\n for (int t = j; t < c; ++t) {\n if (q == i && t == j)\n continue;\n sum += prevSum[t] + a[q][t];\n prevSum[t] += a[q][t];\n if (sum >= k)\n ++ans;\n }\n sum = 0;\n }\n }\n }\n\n out.print(ans);\n }\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\n}\n", "src_uid": "9c766881f6415e2f53fb43b61f8f40b4"} {"source_code": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.List;\n\npublic class Main {\n\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\n\tprivate static final long M = 1000000007L;\n\n\tList<Integer> g[];\n\n\tint p[];\n\tint nextTo[];\n\tint size[];\n\n\tint dp[][];\n\n\tvoid solve() {\n\t\tStringBuffer sb = new StringBuffer();\n\t\tint T = ni();\n\t\twhile (T-- > 0) {\n\t\t\tint N = ni();\n\t\t\tint M = ni();\n\t\t\tint A = ni();\n\t\t\tint B = ni();\n\t\t\tp = new int[N + 1];\n\t\t\tnextTo = new int[N + 1];\n\t\t\tsize = new int[N + 1];\n\t\t\tArrays.fill(size, 1);\n\n\t\t\tint edges[][] = na(M, 2);\n\n\t\t\tfor (int e[] : edges) {\n\t\t\t\tif (e[0] == A)\n\t\t\t\t\tnextTo[e[1]] |= 1;\n\t\t\t\telse if (e[0] == B)\n\t\t\t\t\tnextTo[e[1]] |= 2;\n\n\t\t\t\tif (e[1] == A)\n\t\t\t\t\tnextTo[e[0]] |= 1;\n\t\t\t\telse if (e[1] == B)\n\t\t\t\t\tnextTo[e[0]] |= 2;\n\t\t\t}\n\t\t\tfor (int e[] : edges) {\n\t\t\t\tif (e[0] == A || e[0] == B || e[1] == A || e[1] == B)\n\t\t\t\t\tcontinue;\n\t\t\t\tconnect(e[0], e[1]);\n\t\t\t}\n\t\n\t\t\tlong cnt[] = new long[4];\n\t\t\tfor (int i = 1; i <= N; i++) {\n\t\t\t\tif (p[i] == 0 && i != A && i != B)\n\t\t\t\t\tcnt[nextTo[i]] += size[i];\n\t\t\t}\n\t\t\tsb.append(cnt[1] * cnt[2]).append(System.lineSeparator());\n\t\t}\n\n\t\tout.print(sb);\n\n\t}\n\n\tprivate void connect(int u, int v) {\n\t\tint u0 = find(u);\n\t\tint v0 = find(v);\n\t\tif (u0 == v0)\n\t\t\treturn;\n\t\tp[u0] = v0;\n\t\tsize[v0] += size[u0];\n\t\tnextTo[v0] |= nextTo[u0];\n\t}\n\n\tprivate int find(int x) {\n\t\tif (p[x] == 0)\n\t\t\treturn x;\n\t\telse\n\t\t\treturn p[x] = find(p[x]);\n\t}\n\n\tprivate List<Integer>[] getG(int N, int M) {\n\t\tList<Integer>[] ret = new List[N];\n\t\tfor (int i = 0; i < N; i++)\n\t\t\tret[i] = new ArrayList<Integer>();\n\t\tfor (int i = 0; i < M; i++) {\n\t\t\tint u = ni() - 1;\n\t\t\tint v = ni() - 1;\n\t\t\tret[u].add(v);\n\t\t}\n\t\treturn ret;\n\t}\n\n\tprivate long gcd(long a, long b) {\n\t\twhile (a != 0) {\n\t\t\tlong tmp = b % a;\n\t\t\tb = a;\n\t\t\ta = tmp;\n\t\t}\n\t\treturn b;\n\t}\n\n\tvoid run() throws Exception {\n\t\tis = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\tif (!INPUT.isEmpty())\n\t\t\ttr(System.currentTimeMillis() - s + \"ms\");\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew Main().run();\n\t}\n\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\tprivate boolean vis[];\n\n\tprivate int readByte() {\n\t\tif (lenbuf == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (ptrbuf >= lenbuf) {\n\t\t\tptrbuf = 0;\n\t\t\ttry {\n\t\t\t\tlenbuf = is.read(inbuf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (lenbuf <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\n\tprivate boolean isSpaceChar(int c) {\n\t\treturn !(c >= 33 && c <= 126);\n\t}\n\n\tprivate int skip() {\n\t\tint b;\n\t\twhile ((b = readByte()) != -1 && isSpaceChar(b))\n\t\t\t;\n\t\treturn b;\n\t}\n\n\tprivate double nd() {\n\t\treturn Double.parseDouble(ns());\n\t}\n\n\tprivate char nc() {\n\t\treturn (char) skip();\n\t}\n\n\tprivate String ns() {\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != '\n\t\t\t\t\t\t\t\t\t// ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tprivate char[] ns(int n) {\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile (p < n) {\n\t\t\tif (!(isSpaceChar(b)))\n\t\t\t\tbuf[p++] = (char) b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\n\tprivate char[][] nm(int n, int m) {\n\t\tchar[][] map = new char[n][];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tmap[i] = ns(m);\n\t\treturn map;\n\t}\n\n\tprivate int[] na(int n) {\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = ni();\n\t\treturn a;\n\t}\n\n\tprivate Integer[] na2(int n) {\n\t\tInteger[] a = new Integer[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = ni();\n\t\treturn a;\n\t}\n\n\tprivate int[][] na(int n, int m) {\n\t\tint[][] a = new int[n][];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = na(m);\n\t\treturn a;\n\t}\n\n\tprivate Integer[][] na2(int n, int m) {\n\t\tInteger[][] a = new Integer[n][];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = na2(m);\n\t\treturn a;\n\t}\n\n\tprivate int ni() {\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t;\n\t\tif (b == '-') {\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\n\tprivate long nl() {\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t;\n\t\tif (b == '-') {\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\n\tprivate static void tr(Object... o) {\n\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n}", "src_uid": "7636c493ad91210ec7571895b4b71214"} {"source_code": "import java.util.*;\npublic class Main {\npublic static void main(String [] args){\n Scanner in=new Scanner(System.in);\t\n int n=in.nextInt();\n int mod = 1000000007;\n int red[]=new int[n+1];\n int blue[]=new int[n+1];\n for(int i=1;i<=n;i++){\n \tif((i&1)==1){\n \tblue[i]=red[i-1]+blue[i-1]+1;\n \twhile(blue[i] >= mod)blue[i] -= mod;\n \tred[i]=red[i-1];\n \t}\n \telse{\n \tred[i]=red[i-1]+blue[i-1]+1;\n \twhile(red[i] >= mod)red[i] -= mod;\n \tblue[i]=blue[i-1];\n \t}\n }\n //for(int i=1;i<=n;i++)System.out.println(red[i]+\" \"+blue[i]);\n System.out.print((red[n]+blue[n])%mod);\n}\n}", "src_uid": "5c4bd12df3915186a7b506c2060db125"} {"source_code": "\nimport java.util.*;\nimport java.math.*;\n// Itreator for map for(Map.Entry ent :mp.entrySet())\n\npublic class Main {\n\n public static void main(String args[]) {\n Scanner sc = new Scanner(System.in);\n int n, s1 = 0, s2 = 0;\n n = sc.nextInt();\n for (int i = 0; i < n; i++) {\n int x = sc.nextInt();\n s1 += x;\n }\n for (int i = 0; i < n; i++) {\n int y = sc.nextInt();\n s2 += y;\n }\n\n if (s1 >= s2) {\n System.out.println(\"Yes\");\n } else {\n System.out.println(\"No\");\n }\n }\n}\n", "src_uid": "e0ddac5c6d3671070860dda10d50c28a"} {"source_code": "import java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Egor Kulikov (egor@egork.net)\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tOutputWriter out = new OutputWriter(outputStream);\n\t\tTaskC solver = new TaskC();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskC {\n\tlong[] power;\n\n\tpublic void solve(int testNumber, InputReader in, OutputWriter out) {\n\t\tint count = in.readInt();\n\t\tint[] treeIndex = new int[count];\n\t\tint[] vertex = new int[count];\n\t\tchar[] label = new char[count];\n\t\tfor (int i = 0; i < count; i++) {\n\t\t\ttreeIndex[i] = in.readInt() - 1;\n\t\t\tvertex[i] = in.readInt() - 1;\n\t\t\tlabel[i] = in.readCharacter();\n\t\t}\n\t\tpower = new long[count + 1];\n\t\tpower[0] = 1;\n\t\tfor (int i = 1; i <= count; i++) {\n\t\t\tpower[i] = power[i - 1] * 43;\n\t\t}\n\t\tint firstCount = 0;\n\t\tint secondCount = 0;\n\t\tfor (int i : treeIndex) {\n\t\t\tif (i == 0)\n\t\t\t\tfirstCount++;\n\t\t\telse\n\t\t\t\tsecondCount++;\n\t\t}\n\t\tlong[] hashFirst = new long[firstCount + 1];\n\t\tint[] lengthFirst = new int[firstCount + 1];\n\t\tlong[] hashSecond = new long[secondCount + 1];\n\t\tint[] lengthSecond = new int[secondCount + 1];\n\t\tint[] parent = new int[secondCount + 1];\n\t\tint maxFirstDepth = 0;\n\t\tint firstIndex = 0;\n\t\tint secondIndex = 0;\n\t\tHash hash = new Hash();\n\t\tfor (int i = 0; i < count; i++) {\n\t\t\tif (treeIndex[i] == 0) {\n\t\t\t\tfirstIndex++;\n\t\t\t\tmaxFirstDepth = Math.max(maxFirstDepth, lengthFirst[firstIndex] = lengthFirst[vertex[i]] + 1);\n\t\t\t\thashFirst[firstIndex] = hashFirst[vertex[i]] + power[lengthFirst[vertex[i]]] * label[i];\n\t\t\t\thash.add(hashFirst[firstIndex]);\n\t\t\t} else {\n\t\t\t\tsecondIndex++;\n\t\t\t\tlengthSecond[secondIndex] = lengthSecond[vertex[i]] + 1;\n\t\t\t\tparent[secondIndex] = vertex[i];\n\t\t\t\thashSecond[secondIndex] = hashSecond[vertex[i]] * 43 + label[i];\n\t\t\t}\n\t\t}\n\t\tfirstIndex = 0;\n\t\tsecondIndex = 0;\n\t\tlong answer = 1;\n\t\tfor (int i = 0; i < count; i++) {\n\t\t\tif (treeIndex[i] == 0) {\n\t\t\t\tfirstIndex++;\n\t\t\t\tanswer += hash.addFirstGetSecond(hashFirst[firstIndex]);\n\t\t\t} else {\n\t\t\t\tsecondIndex++;\n\t\t\t\tanswer++;\n\t\t\t\tint current = secondIndex;\n\t\t\t\tint curDepth = 0;\n\t\t\t\tdo {\n\t\t\t\t\tcurrent = parent[current];\n\t\t\t\t\tlong curHash = hashSecond[secondIndex] - hashSecond[current] * power[lengthSecond[secondIndex] - lengthSecond[current]];\n\t\t\t\t\tanswer += hash.addSecondGetFirst(curHash);\n\t\t\t\t\tcurDepth++;\n\t\t\t\t} while (current != 0 && curDepth < maxFirstDepth);\n\t\t\t}\n\t\t\tout.printLine(answer);\n\t\t}\n\t}\n}\n\nclass Hash {\n\tint size = 100003;\n\tint shift = 30001;\n\tboolean[] occupied = new boolean[size];\n\tlong[] key = new long[size];\n\tint[] firstValue = new int[size];\n\tint[] secondValue = new int[size];\n\n\tvoid add(long key) {\n\t\tint index = (int) (key % size);\n\t\tif (index < 0)\n\t\t\tindex += size;\n\t\twhile (occupied[index] && this.key[index] != key) {\n\t\t\tindex += shift;\n\t\t\tif (index >= size)\n\t\t\t\tindex -= size;\n\t\t}\n\t\toccupied[index] = true;\n\t\tthis.key[index] = key;\n\t}\n\n\tint addFirstGetSecond(long key) {\n\t\tint index = (int) (key % size);\n\t\tif (index < 0)\n\t\t\tindex += size;\n\t\twhile (occupied[index] && this.key[index] != key) {\n\t\t\tindex += shift;\n\t\t\tif (index >= size)\n\t\t\t\tindex -= size;\n\t\t}\n\t\tif (!occupied[index])\n\t\t\treturn 0;\n\t\tfirstValue[index]++;\n\t\treturn secondValue[index];\n\t}\n\n\tint addSecondGetFirst(long key) {\n\t\tint index = (int) (key % size);\n\t\tif (index < 0)\n\t\t\tindex += size;\n\t\twhile (occupied[index] && this.key[index] != key) {\n\t\t\tindex += shift;\n\t\t\tif (index >= size)\n\t\t\t\tindex -= size;\n\t\t}\n\t\tif (!occupied[index])\n\t\t\treturn 0;\n\t\tsecondValue[index]++;\n\t\treturn firstValue[index];\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\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 static boolean isSpaceChar(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n\n\tpublic char readCharacter() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\treturn (char) c;\n\t}\n\n\t}\n\nclass OutputWriter {\n\tprivate final PrintWriter writer;\n\n\tpublic OutputWriter(OutputStream outputStream) {\n\t\twriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n\t}\n\n\tpublic OutputWriter(Writer writer) {\n\t\tthis.writer = new PrintWriter(writer);\n\t}\n\n\tpublic void print(Object...objects) {\n\t\tfor (int i = 0; i < objects.length; i++) {\n\t\t\tif (i != 0)\n\t\t\t\twriter.print(' ');\n\t\t\twriter.print(objects[i]);\n\t\t}\n\t}\n\n\tpublic void printLine(Object...objects) {\n\t\tprint(objects);\n\t\twriter.println();\n\t}\n\n\tpublic void close() {\n\t\twriter.close();\n\t}\n\n\t}\n\n", "src_uid": "b0cd7ee6b5f13f977def002b53f8f443"} {"source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastScanner in = new FastScanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n F solver = new F();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class F {\n public void solve(int testNumber, FastScanner in, PrintWriter out) {\n int n = in.ni(), k = in.ni(), l = in.ni();\n int mod = 998244353;\n long[] invs = IntegerUtils.invs(2 * n + 3, mod);\n long[][] p = new long[2 * n + 1][n + 1];\n p[0][1] = 1; // first is always started\n for (int i = 1; i < 2 * n; i++) {\n int prevMaxRunning = Math.min(2 * n - i, i); // how many intervals max were running (covering)\n int maxRunning = Math.min(2 * n - i - 1, i + 1); // how many intervals max can be running\n for (int j = 0; j <= prevMaxRunning; j++) {\n if (p[i - 1][j] != 0) {\n if (j > 0) {\n p[i][j - 1] = (p[i][j - 1] + p[i - 1][j] * j % mod * invs[2 * n - i] % mod) % mod; // close an interval\n }\n if (j < maxRunning) {\n p[i][j + 1] = (p[i][j + 1] + p[i - 1][j] * (2 * n - i - j) % mod * invs[2 * n - i] % mod) % mod; // start a new interval\n }\n }\n }\n }\n long ans = 0;\n for (int i = 0; i < 2 * n; i++) {\n for (int j = k; j <= n; j++) {\n if (p[i][j] == 0)\n continue;\n ans = (ans + p[i][j]) % mod;\n }\n }\n ans = ans * l % mod * invs[2 * n + 1] % mod;\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 }\n\n static class IntegerUtils {\n public static long[] invs(int n, long p) {\n long[] res = new long[n];\n res[1] = 1;\n for (int i = 2; i < n; i++) {\n res[i] = (p - (p / i) * res[(int) (p % i)] % p) % p;\n }\n return res;\n }\n\n }\n}\n\n", "src_uid": "c9e79e83928d5d034123ebc3b2f5e064"} {"source_code": "import java.io.*;\nimport java.util.*;\n\n/*\nTASK: CFA\nLANG: JAVA\n */\npublic class CFA {\n static int c , v0 , v1 , a , l;\n\n public static void main(String[] args) throws IOException {\n FastScanner in = new FastScanner(System.in);\n c = in.nextInt();\n v0 = in.nextInt();\n v1 = in.nextInt();\n a = in.nextInt();\n l = in.nextInt();\n int cur = 0;\n for(int i = 1;i < 10000; i++){\n cur -= l;\n cur = Math.max(cur , 0);\n cur += v0;\n v0 += a;\n v0 = Math.min(v0 , v1);\n if(cur >= c){\n System.out.println(i);\n return;\n }\n }\n }\n\n private static class FastScanner {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n\n public 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", "src_uid": "b743110117ce13e2090367fd038d3b50"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class ProblemD {\n BufferedReader rd;\n long m;\n\n ProblemD() throws IOException {\n rd = new BufferedReader(new InputStreamReader(System.in));\n compute();\n }\n\n private void compute() throws IOException {\n long[] a = longarr();\n long n = a[0];\n long k = a[1];\n long l = a[2];\n m = a[3];\n\n long max = 1L<<Math.min(l,62);\n if(k>=max) {\n out(0);\n } else {\n long[][] first = new long[][] { { 1, 1 }, { 1, 0 } };\n long[][] res = pow(first,n+1);\n long p = res[0][0];\n long q = pow(2,n);\n long r = sub(q,p,m);\n\n long u = 1;\n long g = 0;\n long s = 1L%m;\n while(g < l) {\n if(g < 61 && ((k&u) > 0)) {\n s *= r;\n } else {\n s *= p;\n }\n s %= m;\n u*=2;\n g++;\n }\n out(s);\n }\n }\n\n private long sub(long a, long b, long c) {\n return (a+c-(b%c))%c;\n }\n\n public long pow(long a, long b) {\n if(b == 0) {\n return 1;\n }\n if(b == 1) {\n return a%m;\n }\n long c = pow(a,b/2);\n c = c*c;\n c %= m;\n if(b%2==1) {\n c *= a;\n c %= m;\n }\n return c;\n }\n\n public long[][] mul(long[][] a, long[][] b) {\n long[][] c = new long[2][2];\n for (int i = 0; i < 2; i++) {\n for (int j = 0; j < 2; j++) {\n long s = 0;\n for (int k = 0; k < 2; k++) {\n s += (a[i][k] * b[k][j]) % m;\n s %= m;\n }\n c[i][j] = s;\n }\n }\n return c;\n }\n\n private long[][] pow(long[][] a, long b) {\n if(b == 1) {\n return a;\n }\n if(b == 2) {\n return mul(a,a);\n }\n long[][] c = pow(a,b/2);\n c = mul(c,c);\n if(b%2==1) {\n c = mul(c,a);\n }\n return c;\n }\n\n private long[] longarr() throws IOException {\n return longarr(rd.readLine());\n }\n\n private long[] longarr(String s) {\n String[] q = split(s);\n int n = q.length;\n long[] a = new long[n];\n for(int i=0;i<n;i++) {\n a[i] = Long.parseLong(q[i]);\n }\n return a;\n }\n\n public String[] split(String s) {\n if(s == null) {\n return new String[0];\n }\n int n = s.length();\n int start = -1;\n int end = 0;\n int sp = 0;\n boolean lastWhitespace = true;\n for(int i=0;i<n;i++) {\n char c = s.charAt(i);\n if(isWhitespace(c)) {\n lastWhitespace = true;\n } else {\n if(lastWhitespace) {\n sp++;\n }\n if(start == -1) {\n start = i;\n }\n end = i;\n lastWhitespace = false;\n }\n }\n if(start == -1) {\n return new String[0];\n }\n String[] res = new String[sp];\n int last = start;\n int x = 0;\n lastWhitespace = true;\n for(int i=start;i<=end;i++) {\n char c = s.charAt(i);\n boolean w = isWhitespace(c);\n if(w && !lastWhitespace) {\n res[x++] = s.substring(last,i);\n } else if(!w && lastWhitespace) {\n last = i;\n }\n lastWhitespace = w;\n }\n res[x] = s.substring(last,end+1);\n return res;\n }\n\n private boolean isWhitespace(char c) {\n return c==' ' || c=='\\t';\n }\n\n private static void out(Object x) {\n System.out.println(x);\n }\n\n public static void main(String[] args) throws IOException {\n new ProblemD();\n }\n}\n", "src_uid": "2163eec2ea1eed5da8231d1882cb0f8e"} {"source_code": "import java.util.*;\npublic class dance {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n Scanner sc = new Scanner (System .in);\n int n = sc.nextInt();\n int count = n;\n for (int i = 1; i < n; i++) {\n\t\tcount++;\n\t\tcount+=((i+1)*(n-i-1));\n\t}\n System.out.println(count);\n\n\t} \n\n}\n", "src_uid": "6df251ac8bf27427a24bc23d64cb9884"} {"source_code": "//package com.example.practice.codeforces;\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;\nimport java.util.TreeMap;\n\npublic class Solution {\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<<highest) + 1;\n HashMap<Long, Long> map = new HashMap<>();\n for (int i=1;i<=m;++i){\n v = v << 1;\n if ((v & (1L<<highest)) != 0){\n v = v ^ px;\n }\n if (v == 1){\n return new long[]{first+1, first+1+i};\n }\n if (i<m){\n map.put(v, (long)i);\n }\n }\n final long d = v;\n for (int i=2;i<=m;++i){\n v = multi(px, v, d, highest);\n if (v==1){\n return new long[]{first + 1, first + 1 + m * i};\n }\n Long j = map.get(v);\n if (j != null){\n return new long[]{first + 1, first + 1 + m * i - j};\n }\n }\n return null;\n }\n\n private static long multi(final long px, final long v, final long d, final int highest){\n long res = 0;\n for (int i=0;i<highest;++i){\n if ((d & (1L<<i)) != 0) {\n int t = i;\n long v2 = v;\n while (t > 0) {\n v2 = v2 << 1;\n if ((v2 & (1L<<highest)) != 0){\n v2 = v2 ^ px;\n }\n t--;\n }\n res = res ^ v2;\n }\n }\n return res;\n }\n\n private static void printArray(long[] ns, final PrintWriter out){\n for (int i=0;i<ns.length;++i){\n out.print(ns[i]);\n if (i+1<ns.length)out.print(\" \");\n else out.println();\n }\n }\n\n private static void printArrayInt(int[] ns, final PrintWriter out){\n for (int i=0;i<ns.length;++i){\n out.print(ns[i]);\n if (i+1<ns.length)out.print(\" \");\n else out.println();\n }\n }\n\n private static void printArrayVertical(long[] ns, final PrintWriter out){\n for (long a : ns){\n out.println(a);\n }\n }\n\n private static void printArray2D(long[][] ns, final int len, final PrintWriter out){\n int cnt = 0;\n for (long[] kk : ns){\n cnt++;\n if (cnt > len)break;\n for (int i=0;i<kk.length;++i){\n out.print(kk[i]);\n if (i+1<kk.length)out.print(\" \");\n else out.println();\n }\n }\n }\n\n private static void printArray2DInt(int[][] ns, final int len, final PrintWriter out){\n int cnt = 0;\n for (int[] kk : ns){\n cnt++;\n if (cnt > len)break;\n for (int i=0;i<kk.length;++i){\n out.print(kk[i]);\n if (i+1<kk.length)out.print(\" \");\n else out.println();\n }\n }\n }\n\n private static long[] readArray(final int n, final BufferedReader input) throws IOException{\n long[] ns = new long[n];\n StringTokenizer st = new StringTokenizer(input.readLine());\n for (int i=0;i<n;++i){\n ns[i] = Long.parseLong(st.nextToken());\n }\n return ns;\n }\n\n private static int[] readArrayInt(final int n, final BufferedReader input) throws IOException{\n int[] ns = new int[n];\n StringTokenizer st = new StringTokenizer(input.readLine());\n for (int i=0;i<n;++i){\n ns[i] = Integer.parseInt(st.nextToken());\n }\n return ns;\n }\n\n private static long[] readArrayVertical(final int n, final BufferedReader input) throws IOException{\n long[] ns = new long[n];\n for (int i=0;i<n;++i){\n ns[i] = Long.parseLong(input.readLine());\n }\n return ns;\n }\n\n private static long[][] readArray2D(final int n, final int len, final BufferedReader input) throws IOException{\n long[][] ns = new long[len][];\n for (int i=0;i<n;++i){\n StringTokenizer st = new StringTokenizer(input.readLine());\n ArrayList<Long> 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<kk.length;++j){\n kk[j] = al.get(j);\n }\n ns[i] = kk;\n }\n return ns;\n }\n\n private static int[][] readArray2DInt(final int n, final int len, final BufferedReader input) throws IOException{\n int[][] ns = new int[len][];\n for (int i=0;i<n;++i){\n StringTokenizer st = new StringTokenizer(input.readLine());\n ArrayList<Integer> 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<kk.length;++j){\n kk[j] = al.get(j);\n }\n ns[i] = kk;\n }\n return ns;\n }\n\n static class SegTree{\n int st;\n int en;\n int mid;\n int val1;\n int val2;\n SegTree left;\n SegTree right;\n public SegTree(int l, int r, int d){\n st = l;\n en = r;\n mid = (st + en) >> 1;\n val1 = val2 = d;\n if (st<en){\n left = new SegTree(st, mid, d);\n right = new SegTree(mid+1, en, d);\n }else {\n left = right = null;\n }\n }\n\n public SegTree(int l, int r, int[] ns){\n st = l;\n en = r;\n mid = (st + en) >> 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<<m < n){\n m++;\n }\n m++;\n minTable = new int[n][m];\n maxTable = new int[n][m];\n log2 = new int[n+1];\n for (int i=0;i<n;++i){\n minTable[i][0] = ns[i];\n maxTable[i][0] = ns[i];\n if ((1<<(pre+1)) == i+1){\n pre++;\n }\n log2[i+1] = pre;\n }\n for (int i=1;i<m;++i){\n for (int j=0;j<n;++j){\n int r = Math.min(n-1, j+(1<<i)-1);\n if (r-(1<<(i-1))+1 <= j){\n minTable[j][i] = minTable[j][i-1];\n maxTable[j][i] = maxTable[j][i-1];\n }else {\n minTable[j][i] = Math.min(minTable[j][i-1], minTable[r-(1<<(i-1))+1][i-1]);\n maxTable[j][i] = Math.max(maxTable[j][i-1], maxTable[r-(1<<(i-1))+1][i-1]);\n }\n }\n }\n }\n\n int getMin(final int l, final int r){\n int d = log2[r-l+1];\n return Math.min(minTable[l][d], minTable[r-(1<<d)+1][d]);\n }\n\n int getMax(final int l, final int r){\n int d = log2[r-l+1];\n return Math.max(maxTable[l][d], maxTable[r-(1<<d)+1][d]);\n }\n }\n}", "src_uid": "6bf798edef30db7d0ce2130e40084e6b"} {"source_code": "\nimport java.util.Scanner;\n\npublic class Cifera {\n static void solve(int k, int l){\n long r=k;\n int i=0;\n while(r<l){\n i++;\n r*=k;\n }\n if(r==l)\n System.out.println(\"YES\\n\"+i);\n else\n System.out.println(\"NO\");\n }\n \n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int k= in.nextInt();\n int l= in.nextInt();\n solve(k,l);\n } \n \n}\n", "src_uid": "8ce89b754aa4080e7c3b2c3b10f4be46"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class A implements Runnable {\n\tpublic static void main (String[] args) {new Thread(null, new A(), \"_cf\", 1 << 28).start();}\n\n\tint n;\n\tArrayList<Integer>[] adj;\n\tint[][][] 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(\"\");\n\t\t\n\t\tn = fs.nextInt();\n\t\tadj = new ArrayList[n];\n\t\tfor(int i = 0; i < n; i++) adj[i] = new ArrayList<>();\n\t\tfor(int i = 0; i < n-1; i++) {\n\t\t\tint u = fs.nextInt()-1;\n\t\t\tint v = fs.nextInt()-1;\n\t\t\tadj[u].add(v); adj[v].add(u);\n\t\t}\n\t\t\n\t\tdp = new int[2][2][n];\n\t\tfor(int i = 0; i < 2; i++)\n\t\t\tfor(int j = 0; j < 2; j++)\n\t\t\t\tArrays.fill(dp[i][j], -1);\n\t\tways1 = new int[n];\n\t\tways2 = new int[n];\n\t\tint res = solve(0, 0, 1, -1);\n\t\tSystem.out.println(res);\n\t\t\n\t\tout.close();\n\t}\n\t\n\tint[] ways1, ways2;\n\tint solve(int node, int matched, int solo, int par) {\n\t\tint ret = dp[solo][matched][node];\n\t\tif(ret != -1) return ret;\n\t\tint allWays = 1, allWays2 = 1;\n\t\t\n\t\tint[] ways1 = new int[adj[node].size()];\n\t\tint[] ways2 = new int[adj[node].size()];\n\t\tboolean leaf = true;\n\t\tfor(int i = 0; i < adj[node].size(); i++) {\n\t\t\tint v = adj[node].get(i);\n\t\t\tif(par == v) continue;\n\t\t\tleaf = false;\n\t\t\tint f1 = solve(v, 0, 0, node); //don't cut\n\t\t\tint f2 = solve(v, 0, 1, node); //do cut\n\t\t\tways1[i] = f1; ways2[i] = f2;\n\t\t\tallWays = mult(allWays, add(ways1[i], ways2[i]));\n\t\t\tallWays2 = mult(allWays2, ways2[i]);\n\t\t}\n\t\tif(leaf) {\n\t\t\tint val = dp[solo][matched][node] = solo == 1 || matched == 1 ? 1 : 0;\n\t\t\treturn val;\n\t\t}\n\t\t\n\t\tif(matched == 1) {\n\t\t\treturn dp[solo][matched][node] = allWays;\n\t\t}\n\t\telse {\n\t\t\tint res = solo == 1 ? allWays2 : 0;\n\t\t\tfor(int i = 0; i < adj[node].size(); i++) {\n\t\t\t\tint v = adj[node].get(i);\n\t\t\t\tif(v == par) continue;\n\t\t\t\tint left = div(allWays, add(ways1[i], ways2[i]));\n\t\t\t\tint get = solve(v, 1, 0, node);\n\t\t\t\tleft = mult(left, get);\n\t\t\t\tres = add(res, left);\n\t\t\t}\n\t\t\treturn dp[solo][matched][node] = res;\n\t\t}\n\t}\n\t\n\tint MOD = 998244353;\n\tint add(int a, int b) {\n\t\ta += b;\n\t\tif(a >= MOD) a -= MOD;\n\t\treturn a;\n\t}\n\tint mult(long a, long b) {\n\t\ta *= b;\n\t\tif(a >= MOD) a %= MOD;\n\t\treturn (int)a;\n\t}\n\tint div(int a, int b) {\n\t\treturn mult(a, pow(b, MOD-2));\n\t}\n\tint pow(int base, int expo) {\n\t\tif(expo == 0) return 1;\n\t\tif(expo == 1) return base;\n\t\tif((expo&1) == 0) {\n\t\t\tint res = pow(base, expo>>1);\n\t\t\treturn mult(res, res);\n\t\t}\n\t\telse {\n\t\t\tint res = pow(base, expo-1);\n\t\t\treturn mult(res, base);\n\t\t}\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) {\n\t\t\ttry {\n\t\t\t\tin = new BufferedInputStream(new FileInputStream(new File(s)), BS);\n\t\t\t}\n\t\t\tcatch (Exception e) {\n\t\t\t\tin = new BufferedInputStream(System.in, BS);\n\t\t\t}\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}", "src_uid": "a40e78a7144ac2fae1890ac7598990bf"} {"source_code": "import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main{\r\n\tstatic int mul(int x,int y,int mod){\r\n\t\treturn (int)((x*1l*y)%mod);\r\n\t}\r\n\tstatic int add(int x,int y,int mod){\r\n\t\tint ans=x+y;\r\n\t\tif(ans>=mod)ans-=mod;\r\n\t\treturn ans;\r\n\t}\r\n\tstatic void main() throws Exception{\r\n\t\tint n=sc.nextInt(),m=sc.nextInt();\r\n\t\tint[]ans=new int[n+1];\r\n\t\tint[]pref=new int[n+1];\r\n\t\tans[1]=1;\r\n\t\tpref[1]=1;\r\n\t\tfor(int i=2;i<=n;i++){\r\n\t\t\tfor (int j = 1, la; j <= i; j = la + 1) {\r\n\t\t\t\tla = i / (i / j);\r\n\t\t\t\t//i / x yields the same value for j <= x <= la.\r\n\t\t\t\tans[i]=add(ans[i],mul(ans[i/j],la-j+1,m),m);\r\n\t\t\t}\r\n\t\t\tans[i]=add(ans[i],pref[i-1],m);\r\n\t\t\tpref[i]=add(ans[i],pref[i-1],m);\r\n\t\t}\r\n\t\tpw.println(ans[n]);\r\n\t}\r\n\tpublic static void main(String[] args) throws Exception{\r\n\t\tsc=new MScanner(System.in);\r\n//\t\tsc=new MScanner(\".in\");\r\n\t\tpw = new PrintWriter(System.out);\r\n\t\tint tc=1;\r\n// tc=sc.nextInt();\r\n\t\tfor(curt=1;curt<=tc;curt++) {\r\n//\t\t\tpw.printf(\"Case #%d: \", i);\r\n\t\t\tmain();\r\n\t\t}\r\n\r\n\t\tpw.flush();\r\n\t}\r\n\tstatic int curt;\r\n\tstatic PrintWriter pw;\r\n\tstatic MScanner sc;\r\n\tstatic class MScanner {\r\n\t\tStringTokenizer st;\r\n\t\tBufferedReader br;\r\n\t\tpublic MScanner(InputStream system) {\r\n\t\t\tbr = new BufferedReader(new InputStreamReader(system));\r\n\t\t}\r\n\r\n\t\tpublic MScanner(String file) throws Exception {\r\n\t\t\tbr = new BufferedReader(new FileReader(file));\r\n\t\t}\r\n\r\n\t\tpublic String next() throws IOException {\r\n\t\t\twhile (st == null || !st.hasMoreTokens())\r\n\t\t\t\tst = new StringTokenizer(br.readLine());\r\n\t\t\treturn st.nextToken();\r\n\t\t}\r\n\t\tpublic int[] intArr(int n) throws IOException {\r\n\t\t\tint[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();\r\n\t\t\treturn in;\r\n\t\t}\r\n\t\tpublic long[] longArr(int n) throws IOException {\r\n\t\t\tlong[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();\r\n\t\t\treturn in;\r\n\t\t}\r\n\t\tpublic int[] intSortedArr(int n) throws IOException {\r\n\t\t\tint[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();\r\n\t\t\tshuffle(in);\r\n\t\t\tArrays.sort(in);\r\n\t\t\treturn in;\r\n\t\t}\r\n\t\tpublic long[] longSortedArr(int n) throws IOException {\r\n\t\t\tlong[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();\r\n\t\t\tshuffle(in);\r\n\t\t\tArrays.sort(in);\r\n\t\t\treturn in;\r\n\t\t}\r\n\t\tpublic Integer[] IntegerArr(int n) throws IOException {\r\n\t\t\tInteger[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();\r\n\t\t\treturn in;\r\n\t\t}\r\n\t\tpublic Long[] LongArr(int n) throws IOException {\r\n\t\t\tLong[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();\r\n\t\t\treturn in;\r\n\t\t}\r\n\t\tpublic String nextLine() throws IOException {\r\n\t\t\treturn br.readLine();\r\n\t\t}\r\n\r\n\t\tpublic int nextInt() throws IOException {\r\n\t\t\treturn Integer.parseInt(next());\r\n\t\t}\r\n\r\n\t\tpublic double nextDouble() throws IOException {\r\n\t\t\treturn Double.parseDouble(next());\r\n\t\t}\r\n\r\n\t\tpublic char nextChar() throws IOException {\r\n\t\t\treturn next().charAt(0);\r\n\t\t}\r\n\r\n\t\tpublic long nextLong() throws IOException {\r\n\t\t\treturn Long.parseLong(next());\r\n\t\t}\r\n\r\n\t\tpublic boolean ready() throws IOException {\r\n\t\t\treturn br.ready();\r\n\t\t}\r\n\r\n\t\tpublic void waitForInput() throws InterruptedException {\r\n\t\t\tThread.sleep(3000);\r\n\t\t}\r\n\r\n\t}\r\n\tstatic void dbg(int[]in) {\r\n\t\tSystem.out.println(Arrays.toString(in));\r\n\t}\r\n\tstatic void dbg(long[]in) {\r\n\t\tSystem.out.println(Arrays.toString(in));\r\n\t}\r\n\tstatic void sort(int[]in) {\r\n\t\tshuffle(in);\r\n\t\tArrays.sort(in);\r\n\t}\r\n\tstatic void sort(long[]in) {\r\n\t\tshuffle(in);\r\n\t\tArrays.sort(in);\r\n\t}\r\n\tstatic void shuffle(int[]in) {\r\n\t\tfor(int i=0;i<in.length;i++) {\r\n\t\t\tint idx=(int)(Math.random()*in.length);\r\n\t\t\tint tmp=in[i];\r\n\t\t\tin[i]=in[idx];\r\n\t\t\tin[idx]=tmp;\r\n\t\t}\r\n\t}\r\n\tstatic void shuffle(long[]in) {\r\n\t\tfor(int i=0;i<in.length;i++) {\r\n\t\t\tint idx=(int)(Math.random()*in.length);\r\n\t\t\tlong tmp=in[i];\r\n\t\t\tin[i]=in[idx];\r\n\t\t\tin[idx]=tmp;\r\n\t\t}\r\n\t}\r\n}", "src_uid": "a524aa54e83fd0223489a19531bf0e79"} {"source_code": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\nimport java.math.*;\nimport java.text.*;\n/*\n * @IO : BufferedReader, InputStreamReader, IOException.\n * @Util : Scanner, Arrays, ArrayList, StringTokenizer, TreeSet.\n * @Util : Collections, HashMap, HashSet.\n * @Lang : StringBuilder, StringBuffer.\n * @Math : BigInteger, BigDecimal.\n * @Text : DecimalFormat.\n * @System : System.currentTimeMillis(); , System.nanoTime();\n * @Custom I/O : new PrintWriter(new BufferedOutputStream(System.out))\n */\n\npublic class Main\n{\n // Custom I/O Routine\n public static PrintWriter out = new PrintWriter(System.out);\n public static Reader in = new Reader();\n\n\n // Intializations of Values\n static byte UNCAL = -1;\n static int INF = (int) 1e6;\n \n\t\n // Intializations of Data Structures & Graphs\n \n\n public static void main(String[] args) throws IOException\n {\n //---------------------Solution Start---------------------//\n\t\tint n = in.nextInt();\n\t\tint k = in.nextInt();\n\t\t\n\t\tTreeMap<Character, Integer> ballons = new TreeMap<>();\n\t\t\n\t\tchar[] types = in.next().toCharArray();\n\t\t\n\t\tfor (int i = 0; i < n; i++)\n\t\t{\n\t\t\tif (!ballons.containsKey(types[i]))\n\t\t\t{\n\t\t\t\tballons.put(types[i], 1);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tballons.put(types[i], ballons.get(types[i]) + 1);\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\tint max = 0;\n\t\tfor (Map.Entry<Character, Integer> e : ballons.entrySet())\n\t\t\tmax = Math.max(max, e.getValue());\n\t\t\t\t\n\t\tout.println(max > k ? \"NO\" : \"YES\");\n //---------------------Solution End---------------------//\n out.flush();\n out.close();\n }\n}\n\nclass Reader\n{\n BufferedReader bufferedReader;\n StringTokenizer stringTokenizer;\n\n public Reader(){\n bufferedReader = new BufferedReader(new InputStreamReader(System.in));\n }\n\n public String next(){\n while (stringTokenizer == null || !stringTokenizer.hasMoreElements()){\n try{\n stringTokenizer = new StringTokenizer(bufferedReader.readLine());\n }\n catch (IOException Ex){\n Ex.printStackTrace();\n }\n }\n return stringTokenizer.nextToken();\n }\n\n public int nextInt(){\n return Integer.parseInt(this.next());\n }\n\n public long nextLong(){\n return Long.parseLong(this.next());\n }\n\n public double nextDouble(){\n return Double.parseDouble(this.next());\n }\n\n public String nextLine(){\n String str = \"\";\n try{\n str = bufferedReader.readLine();\n }\n catch (IOException Ex){\n Ex.printStackTrace();\n }\n return str;\n }\n\n public boolean ready() throws IOException{\n return bufferedReader.ready();\n }\n}\n\nclass Graph\n{\n int vertices;\n\n ArrayList<Integer>[] adjList;\n boolean[] visited;\n\n public Graph(int vertices)\n {\n this.vertices = vertices;\n\n adjList = new ArrayList[vertices];\n for (int i = 0 ; i < vertices ; i++)\n adjList[i] = new ArrayList<>();\n\n visited = new boolean[vertices];\n }\n\n public void addEdge(int u, int v)\n {\n adjList[u].add(v);\n }\n\t\n\t public void removeEdge(int u, int v)\n {\n adjList[u].remove(v);\n }\n\t\n public boolean visit(int v)\n {\n return visited[v] = true;\n }\n\n public void clearVisit()\n {\n Arrays.fill(visited, false);\n }\n\n public boolean isVisited(int v)\n {\n return visited[v];\n }\n \n public ArrayList<Integer> edgeList(int v)\n {\n\t\treturn adjList[v];\n\t}\n}\n", "src_uid": "ceb3807aaffef60bcdbcc9a17a1391be"} {"source_code": "\n\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.Locale;\nimport java.util.Scanner;\n\npublic class CF4 {\n\t\n\tpublic static BigInteger gcd (BigInteger a, BigInteger b) {\n\t\treturn b.compareTo(BigInteger.ZERO)!=0 ? gcd (b, a.mod(b)) : a;\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tScanner cin = new Scanner(System.in);\n\t\tPrintWriter cout = new PrintWriter(System.out);\n\t\tBigInteger N = cin.nextBigInteger(), a = cin.nextBigInteger(), b = cin.nextBigInteger();\n\t\tBigInteger step = a.multiply(b).divide(a.gcd(b));\n\t\tBigInteger res = N.divide(step);\n\t\tBigInteger mod = a.min(b);\n\t\tBigInteger rr = res.multiply(mod);\n\t\trr = rr.add(N.subtract(res.multiply(step)).add(BigInteger.ONE).min(mod)).subtract(BigInteger.ONE);\n\t\tBigInteger gcd = rr.gcd(N);\n\t\tcout.println(rr.divide(gcd)+\"/\"+N.divide(gcd));\n\t\tcout.flush();\n\t}\n\n}", "src_uid": "7a1d8ca25bce0073c4eb5297b94501b5"} {"source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Locale;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\tprivate static final String TASKNAME = \"a\";\n\n\tint[][] lists = new int[4][20];\n\tint[] sz = new int[4];\n\n\tint[] size;\n\tboolean[] rev;\n\n\tvoid hanoiTowers(int quantity, int from, int to, int buf, boolean end) {\n\t\tif (quantity == 0) {\n\t\t\treturn;\n\t\t}\n\t\tint lowest = lists[from][sz[from] - quantity];\n\t\tif (end && size[lowest] > 1 && !rev[lowest]) {\n\t\t\tif (quantity > 1) {\n\t\t\t\thanoiTowers(quantity - 1, from, to, buf, false);\n\t\t\t\tmove(from, buf);\n\t\t\t\thanoiTowers(quantity - 1, to, from, buf, false);\n\t\t\t\tmove(buf, to);\n\t\t\t\thanoiTowers(quantity - 1, from, to, buf, end);\n\t\t\t} else {\n\t\t\t\tint t = lists[from][sz[from] - 1];\n\t\t\t\t--sz[from];\n\t\t\t\tlists[to][sz[to]] = t;\n\t\t\t\t++sz[to];\n\t\t\t\trev[t] = !rev[t];\n\n\t\t\t\tfor (int i = 0; i < size[t] - 1; ++i) {\n\t\t\t\t\tansA.add(from);\n\t\t\t\t\tansB.add(buf);\n\t\t\t\t}\n\t\t\t\tansA.add(from);\n\t\t\t\tansB.add(to);\n\t\t\t\tfor (int i = 0; i < size[t] - 1; ++i) {\n\t\t\t\t\tansA.add(buf);\n\t\t\t\t\tansB.add(to);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\thanoiTowers(quantity - 1, from, buf, to, false);\n\t\t\tmove(from, to);\n\t\t\thanoiTowers(quantity - 1, buf, to, from, end);\n\t\t}\n\t}\n\n\tArrayList<Integer> ansA = new ArrayList<Integer>();\n\tArrayList<Integer> ansB = new ArrayList<Integer>();\n\n\tprivate void move(int from, int to) {\n\t\tint t = lists[from][sz[from] - 1];\n\t\t--sz[from];\n\t\tlists[to][sz[to]] = t;\n\t\t++sz[to];\n\t\trev[t] = !rev[t];\n\n\t\tfor (int i = 0; i < size[t]; ++i) {\n\t\t\tansA.add(from);\n\t\t\tansB.add(to);\n\t\t}\n\t}\n\n\tprivate void solve() throws Exception {\n\t\tint n = nextInt();\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\ta[i] = nextInt();\n\t\t}\n\t\tsize = new int[n];\n\t\trev = new boolean[n];\n\n\t\tfor (int i = 0; i <= n; ++i) {\n\t\t\tboolean b = false;\n\t\t\tif (i == n || i > 0 && a[i] != a[i - 1]) {\n\t\t\t\tlists[1][sz[1]] = sz[1];\n\t\t\t\t++sz[1];\n\t\t\t\t// b = true;\n\t\t\t}\n\t\t\tif (i == n) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (!b) {\n\t\t\t\t++size[sz[1]];\n\t\t\t}\n\t\t}\n\n\t\t// System.err.println(sz[1] + \" \" + Arrays.toString(lists[1]));\n\t\t// System.err.println(Arrays.toString(size));\n\n\t\thanoiTowers(sz[1], 1, 3, 2, true);\n\n\t\tprintln(ansA.size());\n\t\tfor (int i = 0; i < ansA.size(); ++i) {\n\t\t\tprintln(ansA.get(i) + \" \" + ansB.get(i));\n\t\t}\n\t}\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\t// reader = new BufferedReader(new FileReader(TASKNAME + \".in\"));\n\t\t\t// writer = new PrintWriter(new BufferedWriter(new\n\t\t\t// FileWriter(TASKNAME + \".out\")));\n\n\t\t\tsolve();\n\n\t\t\treader.close();\n\t\t\twriter.close();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(13);\n\t\t}\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 Main().run();\n\t\tSystem.err.printf(\"%.3f\\n\", (System.currentTimeMillis() - time) * 1e-3);\n\t}\n\n\tprivate StringTokenizer tokenizer;\n\tprivate PrintWriter writer;\n\tprivate BufferedReader reader;\n\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 IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tprivate long nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tprivate double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(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... args) {\n\t\twriter.printf(format, args);\n\t}\n}", "src_uid": "4ea4ad10ef422a9cd45b8a7b25d359c5"} {"source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Main\n{\n public static int min(int a, int b)\n {\n return a>b? b:a;\n }\n public static int max(int a, int b)\n {\n return a>b? a:b;\n }\n public static boolean nextPermutation(int[] p) \n {\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 {\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 {\n t=p[a];\n p[a]=p[b];\n p[b]=t;\n }\n return true;\n }\n return false;\n }\n public static void main(String[] args)\n {\n InputReader in = new InputReader();\n PrintWriter out = new PrintWriter(System.out);\n int minn=1005;\n int p1=in.nextInt();\n minn=min(p1, minn);\n int p2=in.nextInt();\n minn=min(minn, p2);\n int p3=in.nextInt();\n minn=min(minn, p3);\n int p4=in.nextInt();\n minn=min(minn, p4);\n int a=in.nextInt();\n int b=in.nextInt();\n int ans=0;\n if(minn>a)\n ans=min(minn, b+1)-a;\n for(int i=max(minn, a);i<=b;i++)\n {\n int []q={p1, p2, p3, p4};\n int num=0;\n while(nextPermutation(q))\n {\n int c=(((i%q[0])%q[1])%q[2])%q[3];\n if(c==i)\n num++;\n }\n if(num>=7)\n ans++;\n }\n out.println(ans);\n out.close();\n System.exit(0);\n }\n}\n\nclass InputReader\n{\n BufferedReader buf;\n StringTokenizer tok;\n InputReader()\n {\n buf = new BufferedReader(new InputStreamReader(System.in));\n }\n boolean hasNext()\n {\n while(tok == null || !tok.hasMoreElements()) \n {\n try\n {\n tok = new StringTokenizer(buf.readLine());\n } \n catch(Exception e) \n {\n return false;\n }\n }\n return true;\n }\n String next()\n {\n if(hasNext()) \n return tok.nextToken();\n return null;\n }\n int nextInt()\n {\n return Integer.parseInt(next());\n }\n long nextLong()\n {\n return Long.parseLong(next());\n }\n double nextDouble()\n {\n return Double.parseDouble(next());\n }\n BigInteger nextBigInteger()\n {\n return new BigInteger(next());\n }\n BigDecimal nextBigDecimal()\n {\n return new BigDecimal(next());\n }\n}", "src_uid": "63b9dc70e6ad83d89a487ffebe007b0a"} {"source_code": "import java.math.BigInteger;\nimport java.util.Scanner;\n\npublic class Modulus {\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 BigInteger ans = new BigInteger(\"2\");\n ans = ans.pow(n);\n BigInteger ans2 = new BigInteger(Integer.toString(m));\n ans = ans2.mod(ans);\n System.out.println(ans);\n }\n}\n", "src_uid": "c649052b549126e600691931b512022f"} {"source_code": "import java.util.Scanner;\n\n/**\n * Created by zephyr on 2/18/15.\n */\npublic class DrazilandHisFriendsB {\n public static void main(String args[]) {\n Scanner cin = new Scanner(System.in);\n int a = cin.nextInt(), b = cin.nextInt(), s = cin.nextInt();\n int total = Math.abs(a) + Math.abs(b);\n if (total <= s && ((s - total ) % 2 == 0))\n System.out.println(\"Yes\");\n else\n System.out.println(\"No\");\n }\n\n}", "src_uid": "9a955ce0775018ff4e5825700c13ed36"} {"source_code": "//package april2021;\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 B {\r\n\tInputStream is;\r\n\tFastWriter out;\r\n\tString INPUT = \"\";\r\n\t\r\n\tvoid solve()\r\n\t{\r\n\t\tint n = ni();\r\n\t\tout.println(n%9 == 0 ? 9 : n%9);\r\n\t}\r\n\t\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 B().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<Integer> 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", "src_uid": "477a67877367dc68b3bf5143120ff45d"} {"source_code": "import java.util.HashSet;\nimport java.util.Scanner;\nimport java.util.Set;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.text.DecimalFormat;\nimport java.lang.Math; \npublic class Lo {\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n String s = sc.next();\n String t = sc.next();\n Set<Character> A = new HashSet<Character>();\n Set<Character> B = new HashSet<Character>();\n ArrayList<Character> AA = new ArrayList<Character>();\n ArrayList<Character> BB = new ArrayList<Character>();\n for(int i = 0; i < s.length(); i++){\n A.add(s.charAt(i));\n AA.add(s.charAt(i));\n }\n int con2 = 0;\n for(int i = 0; i < t.length(); i++){\n B.add(t.charAt(i));\n BB.add(t.charAt(i));\n if(s.indexOf(t.charAt(i))==-1){\n con2 = 1;\n }\n }\n Collections.sort(AA);\n Collections.sort(BB);\n //if(!AA.equals(BB) || con2==1|| s.length()<t.length()){\n // System.out.println(\"need tree\");\n //}\n if((s.length()==t.length())&&AA.equals(BB)){\n System.out.println(\"array\");\n }\n else{\n int k = s.indexOf(t.charAt(0));\n int j = t.indexOf(t.charAt(0));\n int count = 0;\n while(k< s.length() && j< t.length() && k!=-1){\n if(s.charAt(k)==t.charAt(j)){\n count++;\n k++;\n j++;\n }\n else{\n k++;\n }\n }\n if(con2==0 && s.length()>t.length() && count==t.length()){\n System.out.println(\"automaton\");\n }\n else if(con2==1){\n System.out.println(\"need tree\");\n }\n else if(s.length()>t.length()&& count!=t.length()&& B.size()!=1){\n System.out.println(\"both\");\n }\n else{\n System.out.println(\"need tree\");\n }\n }\n }\n}", "src_uid": "edb9d51e009a59a340d7d589bb335c14"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class D {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tinterface Interactor {\n\t\tint ask(int x, int y);\n\n\t\tvoid answer(int[] xs, int[] ys);\n\t}\n\n\tclass SubmitInteractor implements Interactor {\n\n\t\t@Override\n\t\tpublic int ask(int x, int y) {\n\t\t\tif (Math.abs(x) > B || Math.abs(y) > B) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tout.println(\"0 \" + x + \" \" + y);\n\t\t\tout.flush();\n\t\t\ttry {\n\t\t\t\treturn nextInt();\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn -1;\n\t\t}\n\n\t\t@Override\n\t\tpublic void answer(int[] xs, int[] ys) {\n\t\t\tout.println(\"1 \" + xs.length + \" \" + ys.length);\n\t\t\tfor (int x : xs) {\n\t\t\t\tout.print(x + \" \");\n\t\t\t}\n\t\t\tout.println();\n\t\t\tfor (int y : ys) {\n\t\t\t\tout.print(y + \" \");\n\t\t\t}\n\t\t\tout.println();\n\t\t}\n\n\t}\n\n\tstatic final int B = 100_000_000;\n\tstatic final int MAX_QUERIES = 300_000;\n\n\tint ask1d(int[] xs, int x) {\n\t\tint pos = Arrays.binarySearch(xs, x);\n\t\tif (pos < 0) {\n\t\t\tpos = -pos - 2;\n\t\t}\n\t\tint ret = Integer.MAX_VALUE;\n\t\tif (pos != -1) {\n\t\t\tret = Math.min(ret, x - xs[pos]);\n\t\t}\n\t\tif (pos + 1 < xs.length) {\n\t\t\tret = Math.min(ret, xs[pos + 1] - x);\n\t\t}\n\t\treturn ret;\n\t}\n\n\tclass LocalInteractor implements Interactor {\n\n\t\tint[] xs;\n\t\tint[] ys;\n\n\t\tint qryCnt = 0;\n\n\t\t@Override\n\t\tpublic int ask(int x, int y) {\n\t\t\tif (Math.abs(x) > B && Math.abs(y) > B) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tif (x > B) {\n\t\t\t\tx = B;\n\t\t\t}\n\t\t\tif (x < -B) {\n\t\t\t\tx = -B;\n\t\t\t}\n\t\t\tif (y > B) {\n\t\t\t\ty = B;\n\t\t\t}\n\t\t\tif (y < -B) {\n\t\t\t\ty = -B;\n\t\t\t}\n\t\t\tif (++qryCnt > MAX_QUERIES) {\n\t\t\t\tthrow new AssertionError(\"too many queries\");\n\t\t\t}\n\t\t\treturn Math.min(ask1d(xs, x), ask1d(ys, y));\n\t\t}\n\n\t\t@Override\n\t\tpublic void answer(int[] xs, int[] ys) {\n\t\t\tArrays.sort(xs);\n\t\t\tArrays.sort(ys);\n\n\t\t\tif (!Arrays.equals(xs, this.xs) || !Arrays.equals(ys, this.ys)) {\n\t\t\t\tthrow new AssertionError(\"wa\");\n\t\t\t} else {\n\t\t\t\tSystem.err.println(\"gg in \" + qryCnt);\n\t\t\t}\n\t\t}\n\n\t\tpublic LocalInteractor(int[] xs, int[] ys) {\n\t\t\tArrays.sort(xs);\n\t\t\tArrays.sort(ys);\n\t\t\tthis.xs = xs;\n\t\t\tthis.ys = ys;\n\t\t}\n\n\t}\n\tstatic final Random rng = new Random();\n\n\tint rand(int l, int r) {\n\t\treturn l + rng.nextInt(r - l + 1);\n\t}\n\t\n\tvoid go(int low, int high, Interactor it, List<Integer> ans) {\n\t\tif (high - low <= 1) {\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tint mid = (low + high) >> 1;\n\t\tint dist = it.ask(mid, mid);\n\t\t\n\t\tif (mid - dist == low) {\n\t\t\tif (mid + dist != high && it.ask(mid + dist, mid + dist) == 0) {\n\t\t\t\tans.add(mid + dist);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tint found = it.ask(mid - dist, mid - dist) == 0 ? mid - dist : mid + dist;\n\t\t\n\t\tans.add(found);\n\t\tgo(low, found, it, ans);\n\t\tgo(found, high, it, ans);\n\t}\n\t\n\tvoid solve(Interactor it) {\n\t\tint low = -B + it.ask(-B, -B);\n\t\tint high = B - it.ask(B, B);\n\t\t\n\t\tList<Integer> ans = new ArrayList<>();\n\t\tif (low == high) {\n\t\t\tans.add(low);\n\t\t} else {\n\t\t\tans.add(low);\n\t\t\tans.add(high);\n\t\t\tgo(low, high, it, ans);\n\t\t}\n\t\t\n\t\tint z = rand(-B, B);\n\t\t\n\t\tint[] ansX = new int[ans.size()];\n\t\tint[] ansY = new int[ans.size()];\n\t\tint szX = 0, szY = 0;\n\t\t\n\t\t\n\t\tfor (int x : ans) {\n\t\t\tif (it.ask(x, z) == 0) {\n\t\t\t\tansX[szX++] = x;\n\t\t\t}\n\t\t\tif (it.ask(z, x) == 0) {\n\t\t\t\tansY[szY++] = x;\n\t\t\t}\n\t\t}\n\t\t\n\t\tit.answer(Arrays.copyOf(ansX, szX), Arrays.copyOf(ansY, szY));\n\t\t\n\t\t\n\t}\n\n\tD() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\t// solve(new SubmitInteractor());\n\t\t// solve(new LocalInteractor(new int[] { 2 }, new int[] { 0, -3 }));\n//\t\tint cnt = 10000;\n//\t\tint[] xs = new int[cnt];\n//\t\tint[] ys = new int[cnt];\n\n//\t\tint small = B / 1000 * 999;\n\t\t// int small = B;\n//\t\tint small = 113231512;\n\n//\t\tfor (int i = 0; i < cnt; i++) {\n//\t\t\txs[i] = rand(-B, B);\n//\t\t\tys[i] = rand(-B, B);\n//\t\t}\n\n//\t\tsolve(new LocalInteractor(xs, ys));\n\t\tsolve(new SubmitInteractor());\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew D();\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", "src_uid": "583cd1e553133b297f99fd52e5ad355b"} {"source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n\npublic class Main {\n public static void main( String args[] ) throws Exception{\n BufferedReader br = new BufferedReader (new InputStreamReader (System.in),1024*8);\n StringTokenizer toke = new StringTokenizer(br.readLine());\n int res=0,min=0;\n int r=Integer.parseInt(toke.nextToken()),g=Integer.parseInt(toke.nextToken()),b=Integer.parseInt(toke.nextToken());\n int arr[]=new int[3];arr[0]=r;arr[1]=g;arr[2]=b;Arrays.sort(arr);min=arr[0];\n r=r-min;g=g-min;b=b-min;\n int aux=(r/3) +(g/3)+ (b/3);\n if((r%3)+(g%3)+(b%3) == 4 && min>0)min++;\n System.out.println(min+aux);\n }\n}\n", "src_uid": "acddc9b0db312b363910a84bd4f14d8e"} {"source_code": "import java.io.*;\nimport java.util.*;\nimport java.util.jar.Manifest;\n\npublic class CFB {\n\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 int n;\n int m;\n void solve() throws IOException {\n n = nextInt();\n m = nextInt();\n long res = 0;\n Map<Long, Long> hist = findHist();\n for (Map.Entry<Long, Long> entry1 : hist.entrySet()) {\n for (Map.Entry<Long, Long> entry2 : hist.entrySet()) {\n long l1 = entry1.getKey();\n long l2 = entry2.getKey();\n if ((l1 + l2) % m == 0) {\n res += entry1.getValue() * entry2.getValue();\n }\n }\n }\n\n outln(res);\n }\n\n Map<Long, Long> findHist() {\n Map<Long, Long> res = new HashMap<>();\n int cnt = n / m;\n int left = n % m;\n for (int i = 0; i < m; i++) {\n long rem = 1L * (i + 1) * (i + 1) % m;\n res.put(rem, cnt * 1L + res.getOrDefault(rem, 0L));\n }\n\n for (int i = 0; i < left; i++) {\n long rem = 1L * (i + 1) * (i + 1) % m;\n res.put(rem, 1L + res.getOrDefault(rem, 0L));\n }\n\n return res;\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 CFB() 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 CFB();\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}\n", "src_uid": "2ec9e7cddc634d7830575e14363a4657"} {"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 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\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 public 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 }\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 }", "src_uid": "e652ba0901b39f0d01ac152babc06b88"} {"source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class Main implements Runnable {\n BufferedReader in;\n PrintWriter out;\n StringTokenizer st;\n\n int a, b, n;\n\n int[][] dp;\n BigInteger need;\n\n int rec(int item, int box) {\n if (item >= 50)\n return 1;\n if (box >= 35000)\n return 1;\n int ret = dp[item][box];\n if (ret == -1) {\n BigInteger a = BigInteger.valueOf(box).pow(item);\n if (a.compareTo(need) >= 0)\n ret = 0;\n else {\n ret = 100;\n ret = min(ret, rec(item, box + 1));\n ret = min(ret, rec(item + 1, box));\n }\n if (ret == 0)\n ret = 1;\n else\n ret = 0;\n dp[item][box] = ret;\n }\n return ret;\n }\n\n void solve() throws IOException {\n a = ni();\n b = ni();\n n = ni();\n if (a == 1 && (1 << b) >= n) {\n out.println(\"Missing\");\n return;\n }\n dp = new int[50][35000];\n for (int i = 0; i < dp.length; i++) {\n Arrays.fill(dp[i], -1);\n }\n need = BigInteger.valueOf(n);\n int ret = rec(b, a);\n if (ret == 1)\n out.println(\"Masha\");\n else\n out.println(\"Stas\");\n }\n\n public Main() throws IOException {\n\n }\n\n String ns() throws IOException {\n while (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(in.readLine());\n }\n return st.nextToken();\n }\n\n int ni() throws IOException {\n return Integer.valueOf(ns());\n }\n\n long nl() throws IOException {\n return Long.valueOf(ns());\n }\n\n double nd() throws IOException {\n return Double.valueOf(ns());\n }\n\n public static void main(String[] args) throws IOException,\n InterruptedException {\n Thread th = new Thread(null, new Main(), \"Main\", 67108864);\n th.start();\n th.join();\n if (failed)\n throw new RuntimeException();\n }\n\n static boolean failed = false;\n\n @Override\n public void run() {\n Locale.setDefault(Locale.US);\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n try {\n solve();\n in.close();\n out.close();\n } catch (IOException e) {\n failed = true;\n }\n }\n}\n", "src_uid": "cffd5c0b7b659649f3bf9f2dbd20ad6b"} {"source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\n/**\n * @author ramilagger\n *\n */\npublic class Main {\n\n final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n final BufferedReader br;\n final PrintWriter pw;\n StringTokenizer st;\n\n class Diploma{\n\n int min;\n int max;\n\n public Diploma(int min, int max){\n this.min = min;\n this.max = max;\n }\n\n }\n\n public void solve() throws Exception {\n int n = nextInt();\n Diploma[] a = new Diploma[3];\n for (int i = 0; i < 3; i++) {\n a[i] = new Diploma(nextInt(),nextInt());\n }\n int one = a[0].min;\n int two = a[1].min;\n int three = a[2].min;\n\n while (one + two + three != n) {\n\n if (n - two - three <= a[0].max) {\n one = n - two - three;\n } else if (two + 1 <= a[1].max) {\n two++;\n } else if (three + 1 <= a[2].max) {\n three++;\n }\n\n }\n pw.println(one + \" \" + two + \" \" + three);\n }\n\n\n public void run() throws Exception{\n long start = System.currentTimeMillis();\n solve();\n if(!ONLINE_JUDGE){\n long end = System.currentTimeMillis();\n System.err.println(end - start + \" ms\");\n }\n pw.close();\n }\n\n public Main() throws Exception {\n\n br = (ONLINE_JUDGE) ? new BufferedReader(new InputStreamReader(System.in))\n : new BufferedReader(new FileReader(\"in.txt\"));\n\n pw = (ONLINE_JUDGE) ?\n new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)))\n : new PrintWriter(new BufferedWriter(new FileWriter(\"out.txt\")));\n\n }\n\n public static void main(String[] args) throws Exception {\n new Main().run();\n }\n\n public String next() throws IOException {\n while (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(br.readLine());\n }\n return st.nextToken();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n public BigInteger nextBigInteger () throws IOException {\n return new BigInteger(next());\n }\n\n public String nextLine() throws IOException {\n while (st == null || !st.hasMoreTokens()) {\n return br.readLine();\n }\n StringBuilder sb = new StringBuilder(st.nextToken());\n while (st.hasMoreTokens()){\n sb.append(\" \" + st.nextToken());\n }\n return sb.toString();\n }\n\n public int[] nextArray(int n) throws IOException {\n int[] temp = new int[n];\n for (int i = 0; i < n; i++) {\n temp[i] = nextInt();\n }\n return temp;\n }\n\n public long[] nextLArray(int n) throws IOException {\n long[] temp = new long[n];\n for (int i = 0; i < n; i++) {\n temp[i] = nextLong();\n }\n return temp;\n }\n\n}", "src_uid": "3cd092b6507079518cf206deab21cf97"} {"source_code": "import java.io.*;\n\nimport java.awt.geom.Point2D;\nimport java.text.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Main implements Runnable {\n\n\tfinal String filename = \"\";\n\t\n\tpublic void solve() throws Exception {\n\t\tint n = iread();\n\t\tif(n%2==0) {\n\t\t\tout.write(0+\"\");\n\t\t}\n\t\telse {\n\t\t\tout.write(1+\"\");\n\t\t}\n\t\t\n\t}\n\n\t\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\t\t// in = new BufferedReader(new FileReader(filename+\".in\"));\n\t\t\t// out = new BufferedWriter(new FileWriter(filename+\".out\"));\n\t\t\tsolve();\n\t\t\tout.flush();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n\n\tpublic int iread() throws Exception {\n\t\treturn Integer.parseInt(readword());\n\t}\n\n\tpublic double dread() throws Exception {\n\t\treturn Double.parseDouble(readword());\n\t}\n\n\tpublic long lread() throws Exception {\n\t\treturn Long.parseLong(readword());\n\t}\n\n\tBufferedReader in;\n\n\tBufferedWriter out;\n\n\tpublic String readword() throws IOException {\n\t\tStringBuilder b = new StringBuilder();\n\t\tint c;\n\t\tc = in.read();\n\t\twhile (c >= 0 && c <= ' ')\n\t\t\tc = in.read();\n\t\tif (c < 0)\n\t\t\treturn \"\";\n\t\twhile (c > ' ') {\n\t\t\tb.append((char) c);\n\t\t\tc = in.read();\n\t\t}\n\t\treturn b.toString();\n\t}\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tLocale.setDefault(Locale.US);\n\t\t} catch (Exception e) {\n\n\t\t}\n\t\t// new Thread(new Main()).start();\n\t\tnew Thread(null, new Main(), \"1\", 1 << 25).start();\n\t}\n}", "src_uid": "78e64fdbf59c5ce89d0f0a1d0591f795"} {"source_code": "import java.util.ArrayList;\nimport java.util.BitSet;\nimport java.util.Scanner;\n\n/**\n * Created by Luis Ngo on 22/12/2016.\n */\npublic class P746C {\n public static void main (String[] args){\n Scanner scanner = new Scanner(System.in);\n int s = scanner.nextInt();\n int x1 = scanner.nextInt();\n int x2 = scanner.nextInt();\n int t1 = scanner.nextInt();\n int t2 = scanner.nextInt();\n int p = scanner.nextInt();\n int d = scanner.nextInt();\n\n int time1 = Math.abs(x2-x1)*t2;\n\n int time2 = 0;\n if (x2 -x1 < 0 && d < 0) {\n if (p < x2)\n time2 = (2*s -(x2 - p)) * t1;\n else {\n time2 = (p - x2) * t1;\n if (p<x1) time2 += s*2*t1;\n }\n } else if (x2 -x1 < 0 && d > 0)time2 = (s-p + s-x2) * t1;\n else if (x2 -x1 > 0 && d > 0) {\n if (p > x2) time2 = (2*s -(p - x2)) * t1;\n else {\n time2 = (x2-p) * t1;\n if (p>x1) time2 += s*2*t1;\n }\n }else time2 = (p +x2) * t1;\n System.out.println(Math.min(time1,time2));\n }\n\n\n\n}\n", "src_uid": "fb3aca6eba3a952e9d5736c5d8566821"} {"source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\npublic class Main\n{\n static int n;\n static int[][][] p=new int[10][10][3];\n static int a,b,c,d,e;\n static int k;\n static int[][] dp=new int[10][10];\n static int[][] m=new int[30][2];\n static int ee=0;\n static int[] ru=new int[10];\n static int[] chu=new int[10];\n static int mi=-1,mx=-1;\n public static void main(String[] args) {\n Scanner cin=new Scanner(new BufferedInputStream(System.in));\n n=cin.nextInt();\n k=n*(n-1)/2;\n for(int i=0;i<k;i++){\n a=cin.nextInt();\n b=cin.nextInt();\n c=cin.nextInt();\n d=cin.nextInt();\n e=cin.nextInt();\n p[a][b][0]=c; p[a][b][1]=d; p[a][b][2]=e;\n }\n for(int i=1;i<=n;i++){\n for(int j=i+1;j<=n;j++){\n m[ee][0]=i;\n m[ee][1]=j;\n ee++;\n }\n }\n //System.out.println(ee);\n dfs(0,0);\n System.out.println(mi+\" \"+mx);\n }\n \n public static void dfs(int cnt,int ans){\n if(cnt==ee){\n solve();\n return;\n }\n if(mi!=-1&&ans>mi)\n return;\n if(n==6&&chu[3]!=0&&ru[2]!=chu[2])\n return;\n if(n==6&&chu[4]!=0&&ru[3]!=chu[3])\n return;\n if(n==6&&chu[5]!=0&&ru[4]!=chu[4])\n return;\n int i=m[cnt][0],j=m[cnt][1];\n for(int k=p[i][j][0];k<=p[i][j][1];k++){\n chu[i]+=k;\n ru[j]+=k;\n dp[i][j]=k;\n if(cnt<n-1)\n dfs(cnt+1,ans+k);\n else\n dfs(cnt+1,ans);\n chu[i]-=k;\n ru[j]-=k;\n }\n }\n \n public static void solve(){\n //System.out.println(10);\n for(int i=2;i<n;i++){\n if(ru[i]!=chu[i])\n return;\n }\n int liu=0,cost=0;\n for(int i=1;i<n;i++)\n liu+=dp[i][n];\n for(int i=1;i<=n;i++){\n for(int j=i+1;j<=n;j++){\n if(dp[i][j]==0)\n continue;\n cost+=p[i][j][2]+dp[i][j]*dp[i][j];\n }\n }\n if(mi==-1){\n mi=liu;\n mx=cost;\n }\n else{\n if(liu<mi){\n mi=liu;\n mx=cost;\n }\n else if(liu==mi){\n mx=Math.max(mx,cost);\n }\n }\n }\n}\n\n\n\n\n\n\n\n\n\n", "src_uid": "38886ad7b0d83e66b77348be34828426"} {"source_code": "/*\nID: andrew42\nLANG: JAVA\nTASK: \nPROG: \n*/\n\nimport java.io.*;\nimport java.util.*;\nimport java.lang.*;\n\npublic class pigeon {\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner in = new Scanner(System.in);\n\t\tint length = in.nextInt();\n\t\tint two = 0;\n\t\tint min = 33;\n\t\tint third = 0;\n\t\tint[] arr = new int[length];\n\t\tfor (int i = 0; i < length; i++){\n\t\t\tarr[i] = in.nextInt();\n\t\t\tmin = Math.min(min, arr[i]);\n\t\t}\n\t\tSystem.out.println(2+(arr[2]^min));\n\t}\n}\n", "src_uid": "a9eb85dfaa3c50ed488d41da4f29c697"} {"source_code": "\nimport java.util.Scanner;\n\n/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n\n/**\n *\n * @author ac\n */\npublic class P1146A {\n public static void main(String[] args){\n Scanner sc = new Scanner (System.in);\n \n char[] c = sc.next().toCharArray();\n int n=c.length;\n int x = 0;\n \n int r = n / 2 + 1;\n for(int i=0; i<c.length; i++){\n if(c[i]=='a'){\n x++;\n }\n } \n \n int ans = n;\n if(x < r) {\n ans = 2 * x - 1;\n }\n System.out.println(ans);\n }\n}\n", "src_uid": "84cb9ad2ae3ba7e912920d7feb4f6219"} {"source_code": "import java.util.*;\nimport java.io.*;\n\npublic class b{\n\n public static void main(String [] args) throws IOException{\n FastScanner sc=new FastScanner();\n PrintWriter out=new PrintWriter(System.out);\n int n=sc.nextInt();\n int d=sc.nextInt();\n int [] time=sc.nextIntArray(n);\n int timeUsed=0;\n for(int i : time)timeUsed+=i;\n timeUsed+=(n-1)*10;\n\n if(timeUsed>d){\n out.println(-1);\n out.close();return;\n }\n\n int cnt=(n-1)*2;\n cnt+=(d-timeUsed)/5;\n out.println(cnt);\n out.close();\n\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nclass FastScanner{\t\n private int BUFFER_SIZE = 1 << 16;\n \n private DataInputStream din;\n \n private byte[] buffer;\n \n private int bufferPointer, bytesRead;\n \n public FastScanner() {\n din = new DataInputStream(System.in);\n buffer = new byte[BUFFER_SIZE];\n bufferPointer = bytesRead = 0;\n }\n\n public FastScanner( String file_name) throws IOException {\n din = new DataInputStream(new FileInputStream(file_name));\n buffer = new byte[BUFFER_SIZE];\n bufferPointer = bytesRead = 0;\n }\n \n public String readLine() throws IOException {\n byte[] buf = new byte[64];\n int cnt = 0, c;\n while ((c = read()) != -1) {\n if (c == '\\n')\n break;\n buf[cnt++] = (byte) c;\n }\n return new String(buf, 0, cnt);\n }\n \n public String next() throws IOException{\n\n byte c = read();\n while(Character.isWhitespace(c)){\n c = read();\n }\n \n StringBuilder builder = new StringBuilder();\n builder.append((char)c);\n c = read();\n while(!Character.isWhitespace(c)){\n builder.append((char)c);\n c = read();\n }\n \n return builder.toString();\n }\n\n public int nextInt() throws IOException {\n int ret = 0;\n byte c = read();\n while (c <= ' ')\n c = read();\n boolean neg = (c == '-');\n if (neg)\n c = read();\n do {\n ret = ret * 10 + c - '0';\n } while ((c = read()) >= '0' && c <= '9');\n\n if (neg)\n return -ret;\n return ret;\n }\n \n public 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 public long nextLong() throws IOException {\n long ret = 0;\n byte c = read();\n while (c <= ' ')\n c = read();\n boolean neg = (c == '-');\n if (neg)\n c = read();\n do {\n ret = ret * 10 + c - '0';\n } while ((c = read()) >= '0' && c <= '9');\n if (neg)\n return -ret;\n return ret;\n }\n \n public long[] nextLongArray( int n) throws IOException {\n long arr[] = new long[n];\n for(int i = 0; i < n; i++){\n arr[i] = nextLong();\n }\n return arr;\n }\n\n public char nextChar() throws IOException{\n byte c = read();\n while(Character.isWhitespace(c)){\n c = read();\n }\n return (char) c;\t\n }\n \n public double nextDouble() throws IOException {\n double ret = 0, div = 1;\n byte c = read();\n while (c <= ' ')\n c = read();\n boolean neg = (c == '-');\n if (neg)\n c = read();\n\n do {\n ret = ret * 10 + c - '0';\n } while ((c = read()) >= '0' && c <= '9');\n\n if (c == '.') {\n while ((c = read()) >= '0' && c <= '9') {\n ret += (c - '0') / (div *= 10);\n }\n }\n\n if (neg)\n return -ret;\n return ret;\n }\n \n public double[] nextDoubleArray( int n) throws IOException {\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 private void fillBuffer() throws IOException {\n bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n if (bytesRead == -1)\n buffer[0] = -1;\n }\n\n private byte read() throws IOException {\n if (bufferPointer == bytesRead)\n fillBuffer();\n return buffer[bufferPointer++];\n }\n\n public void close() throws IOException {\n if (din == null)\n return;\n din.close();\n }\n\n}\n\n", "src_uid": "b16f5f5c4eeed2a3700506003e8ea8ea"} {"source_code": "\n\nimport java.util.*;\npublic class CodeForces {\n\tpublic static void main(String[] args) {\n\t\tScanner input = new Scanner(System.in);\n\t\tint n = input.nextInt();\n\t\tint k = input.nextInt();\n\t\tString s = input.next();\n\t\tQueue<String>q = new LinkedList<>();\n\t\tHashSet<String>set = new HashSet<>();\n\t\tset.add(s);\n\t\tq.add(s);\n\t\tint cost =0;\n\t\twhile(!q.isEmpty()){\n\t\t\tString ss = q.remove();\n\t\t\tif(set.size() == k)break;\n\t\t\tfor(int i =0;i<ss.length();i++){\n\t\t\t\tStringBuffer temp = new StringBuffer(ss);\n\t\t\t\ttemp.deleteCharAt(i);\n\t\t\t\t\n\t\t\t\tif(!set.contains(temp.toString()) && set.size()<k){\n\t\t\t\t\tset.add(temp.toString());\n\t\t\t\t\tq.add(temp.toString());\n\t\t\t\t\tcost+=(s.length()-temp.length());\n\t\t\t\t}else if(set.size() == k)break;\n\t\t\t}\n\t\t}\n\t\tif(set.size() != k)cost = -1;\n\t\tSystem.out.println(cost);\n\t\t\n\t}\n\n}\n\n/*\n1.make sure to include continue or return if u are handling a specific case separately!!!!\nand check the constraints of every alphabet(missed to check for case 0)!!!!!!!!!\n\n2.when u have transitions between states and its not dp try dfs (also think of topo sort)\n */\n", "src_uid": "ae5d21919ecac431ea7507cb1b6dc72b"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class SingleTest {\n public static void main(String[] args){\n InputReader in = new InputReader();\n PrintWriter out = new PrintWriter(System.out);\n int test_cases = 1;\n Solver s = new Solver();\n for (int i = 1; i <= test_cases; i++)\n s.solve(1, in, out);\n out.close();\n }\n}\n\nclass Solver {\n void solve(int test_number, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int[] a = new int[n];\n int[] b = new int[n];\n int[] ac = new int[6];\n int[] bc = new int[6];\n for (int i = 0; i < n; i++) {\n a[i] = in.nextInt();\n ac[a[i]]++;\n }\n for (int i = 0; i < n; i++) {\n b[i] = in.nextInt();\n bc[b[i]]++;\n }\n int give = 0, ex = 0;\n for (int i = 1; i <= 5; i++) {\n if (ac[i] == bc[i]) continue;\n if (ac[i] > bc[i]) {\n int diff = ac[i] - bc[i];\n if (diff % 2 == 1) {\n out.println(\"-1\");\n return;\n }\n if (give < 0) {\n if (Math.abs(give) >= diff / 2) {\n give += diff / 2;\n }\n else {\n ex += diff / 2 - Math.abs(give);\n give += diff / 2;\n }\n }\n else {\n give += diff / 2;\n ex += diff / 2;\n }\n }\n else {\n int diff = bc[i] - ac[i];\n if (diff % 2 == 1) {\n out.println(\"-1\");\n return;\n }\n if (give > 0) {\n if (diff / 2 <= give) {\n give -= diff / 2;\n }\n else {\n ex += diff / 2 - give;\n give -= diff / 2;\n }\n }\n else {\n give -= diff / 2;\n ex += diff / 2;\n }\n }\n }\n out.println(ex);\n }\n}\n\nclass InputReader {\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}", "src_uid": "47da1dd95cd015acb8c7fd6ae5ec22a3"} {"source_code": "\nimport java.util.*;\nimport java.io.*;\npublic class TestClass {\n\t\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\tpublic static void main(String args[] ) throws Exception {\n \n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n int n = Integer.parseInt(in.readLine());\n int p = 0,f=0;\n int a[] = new int[n];\n String q[] = new String[n];\n for(int i=0;i<n;i++)\n {\n \tString s1[] = in.readLine().split(\" \");\n \ta[i] = Integer.parseInt(s1[0]);\n \tq[i] = s1[1];\n }\n for(int i=0;i<n;i++)\n {\n \tif(i==0)\n \t{\n \t\tif(!q[i].equals(\"South\"))\n \t{\n \t\tout.println(\"NO\");\n \t\tf=1;\n \t\tbreak;\n \t}\n \t}\n \tif(i==n-1)\n \t{\n \t\tif(!q[i].equals(\"North\"))\n \t{\n \t\tout.println(\"NO\");\n \t\tf=1;\n \t\tbreak;\n \t}\n \t}\n \t\n \tif(q[i].equals(\"North\"))\n \t{\n \t\tp = p-a[i];\n \t}\n \telse if(q[i].equals(\"South\"))\n \t{\n \t\tp = p+a[i];\n \t}\n \tif(p>20000 || p<0)\n \t{\n \t\tout.println(\"NO\");\n \t\tf=1;\n \t\tbreak;\n \t}\n \tif(p==20000)\n \t{\n \t\tif(i+1<n)\n \t\t{\n\t \t\tif(q[i].equals(\"North\"))\n\t \t\t{\n\t \t\t\tif(!q[i+1].equals(\"South\"))\n\t \t\t\t{\n\t \t\t\t\tout.println(\"NO\");\n\t \t\t\t\tf=1;\n\t \t\tbreak;\n\t \t\t\t}\n\t \t\t}\n\t \t\tif(q[i].equals(\"South\"))\n\t \t\t{\n\t \t\t\tif(!q[i+1].equals(\"North\"))\n\t \t\t\t{\n\t \t\t\t\tout.println(\"NO\");\n\t \t\t\t\tf=1;\n\t \t\tbreak;\n\t \t\t\t}\n\t \t\t}\n \t\t}\n \t}\n \tif(p==0)\n \t{\n \t\tif(i+1<n)\n \t\t{\n\t \t\tif(q[i].equals(\"North\"))\n\t \t\t{\n\t \t\t\tif(!q[i+1].equals(\"South\"))\n\t \t\t\t{\n\t \t\t\t\tout.println(\"NO\");\n\t \t\t\t\tf=1;\n\t \t\tbreak;\n\t \t\t\t}\n\t \t\t}\n\t \t\tif(q[i].equals(\"South\"))\n\t \t\t{\n\t \t\t\tif(!q[i+1].equals(\"North\"))\n\t \t\t\t{\n\t \t\t\t\tout.println(\"NO\");\n\t \t\t\t\tf=1;\n\t \t\tbreak;\n\t \t\t\t}\n\t \t\t}\n \t\t}\n \t}\n }\n if(f==0 && p==0)\n {\n \tout.println(\"YES\");\n }\n else if(f==0)\n {\n \tout.println(\"NO\");\n }\n out.close();\n }\n \n \n}\n\n\n", "src_uid": "11ac96a9daa97ae1900f123be921e517"} {"source_code": "import java.util.*;\npublic final class Main {\n\tpublic static void main(String[] args) throws Exception {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tint t = in.nextInt();\n\t\tint[][] a = new int[20][20];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tString s = in.next();\n\t\t\tfor (int j = 0; j < m; j++)\n\t\t\t\ta[j][i] = s.charAt(j) == 'Y' ? 1 : 0;\n\t\t}\n\t\t// kitten\n\t\tint ans = 0;\n\t\tfor (int j = 0; j < m; j++) {\n\t\t\tint sum = 0;\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tsum += a[j][i];\n\t\t\tif (sum >= t)\n\t\t\t\t++ans;\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}\n", "src_uid": "4c978130187e8ae6ca013d3f781b064e"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class A implements Runnable {\n\tpublic static void main (String[] args) {new Thread(null, new A(), \"_cf\", 1 << 28).start();}\n\n\tpublic void run() {\n\t\tFastScanner fs = new FastScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tSystem.err.println(\"\");\n\t\t\n\t\tint n = fs.nextInt();\n\t\tif(n == 1) {\n\t\t\tSystem.out.println(0);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tint log = Integer.numberOfTrailingZeros(Integer.highestOneBit(n))+1;\n\t\tint[] a = fs.nextIntArray(n);\n\n\t\tint[] left = new int[3*n], right = new int[3*n];\n\t\tfor(int i = 0; i < 3*n; i++) {\n\t\t\tint p1 = i-a[i%n], p2 = i+a[i%n];\n\t\t\tif(p1 < 0) p1 = -1; if(p2 >= 3*n) p2 = 3*n;\n\t\t\tleft[i] = p1;\n\t\t\tright[i] = p2;\n\t\t}\n\t\t\n\t\tRMQLowMemory[] q1 = new RMQLowMemory[log];\n\t\tRMQLowMemoryMax[] q2 = new RMQLowMemoryMax[log];\n\n\t\tq1[0] = new RMQLowMemory(left);\n\t\tq2[0] = new RMQLowMemoryMax(right);\n\t\t\n\t\tint[] prevLA = new int[3*n];\n\t\tint[] prevRA = new int[3*n];\n\t\tfor(int i = 0; i < 3*n; i++) {\n\t\t\tprevLA[i] = left[i];\n\t\t\tprevRA[i] = right[i];\n\t\t}\n\t\t\n\t\tfor(int lg = 1; lg < log; lg++) {\n\t\t\tfor(int i = 0; i < 3*n; i++) {\n\t\t\t\tint prevL = left[i];\n\t\t\t\tint prevR = right[i];\n\t\t\t\tif(prevL < 0) left[i] = prevL;\n\t\t\t\telse left[i] = q1[lg-1].query(prevL, Math.min(3*n-1, prevR));\n\t\t\t\tif(prevR >= 3*n) right[i] = prevR;\n\t\t\t\telse right[i] = q2[lg-1].query(Math.max(0, prevL), prevR);\n\t\t\t\t\n\t\t\t\tprevLA[i] = left[i]; prevRA[i] = right[i];\n\t\t\t}\n\t\t\tq1[lg] = new RMQLowMemory(left);\n\t\t\tq2[lg] = new RMQLowMemoryMax(right);\n\t\t}\n\t\t\n\t\tint[] res = new int[n];\n\t\tfor(int i = n; i < 2*n; i++) {\n\t\t\tint best = 0, cL = i, cR = i;\n\t\t\tfor(int lg = log-1; lg >= 0; lg--) {\n\t\t\t\tint nL = q1[lg].query(cL, cR);\n\t\t\t\tint nR = q2[lg].query(cL, cR);\n\t\t\t\tif(nR-nL+1 < n && nL >= 0 && nR < 3*n) {\n\t\t\t\t\tbest += 1<<lg;\n\t\t\t\t\tcL = nL; cR = nR;\n\t\t\t\t}\n\t\t\t}\n\t\t\tres[i%n] = ++best;\n\t\t}\n\t\tfor(int i = 0; i < n; i++) out.print(res[i] + \" \");\n\t\tout.println();\n\t\tout.close();\n\t}\n\t\n\tint walk(int[][] lift, int pos, int dist) {\n\t\tint n = lift[0].length;\n\t\twhile(dist > 0) {\n\t\t\tif(pos < 0 || pos >= n) break;\n\t\t\tint hi = Integer.highestOneBit(dist);\n\t\t\tint bit = Integer.numberOfTrailingZeros(hi);\n\t\t\tpos = lift[bit][pos];\n\t\t\t\n\t\t\tdist -= hi;\n\t\t}\n\t\treturn pos;\n\t}\n\t\n\tclass RMQLowMemory {\n\t\tfinal static int blockSize=32;\n\t\tint[] low, a;\n\t\tint[][] lift;\n\t\t\n\t\tpublic RMQLowMemory(int[] a) {\n\t\t\tint n=a.length, m=0;\n\t\t\ta=a.clone();\n\t\t\tthis.a=a.clone();\n\t\t\tlow=new int[n];\n\t\t\tfor (int i=0; i<n; low[i]=++m, m<<=1, i++)\n\t\t\t\twhile (m!=0 && a[i-Integer.numberOfTrailingZeros(m)]>= a[i])\n\t\t\t\t\tm-=Integer.lowestOneBit(m);\n\t\t\t\n\t\t\tint nn=(n+blockSize-1)>>5;\n\t\t\tint maxlog = Integer.numberOfTrailingZeros(Integer.highestOneBit(nn)) + 2;\n\t\t\tlift = new int[maxlog][nn];\n\t\t\tArrays.fill(lift[0], Integer.MAX_VALUE);\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tlift[0][i/blockSize]=Math.min(lift[0][i/blockSize], a[i]);\n\n\t\t\tint lastRange = 1;\n\t\t\tfor (int lg = 1; lg < maxlog; lg++, lastRange<<=1)\n\t\t\t\tfor (int i = 0; i < nn; i++)\n\t\t\t\t\tlift[lg][i] = Math.min(lift[lg - 1][i], lift[lg - 1][Math.min(i + lastRange, nn - 1)]);\n\t\t\t\n\t\t}\n\t\t\n\t\tint query(int low, int high) {\n\t\t\thigh++;\n\t\t\tint lowBlock=(low+blockSize-1)>>5, highBlock=high>>5;\n\t\t\tint crossBlock=acrossBlockQuery(lowBlock, highBlock);\n\t\t\tint edge1=edgeQuery(Math.max(low, high-blockSize), high);\n\t\t\tint edge2=edgeQuery(low, Math.min(low+blockSize-1, high));\n\t\t\treturn Math.min(Math.min(edge1, edge2), crossBlock);\n\t\t}\n\n\t\tint acrossBlockQuery(int lBlock, int hBlock) {\n\t\t\tif (lBlock>=hBlock) return Integer.MAX_VALUE;\n\t\t\tint exp = Integer.highestOneBit(hBlock-lBlock);\n\t\t\tint lg = Integer.numberOfTrailingZeros(exp);\n\t\t\treturn Math.min(lift[lg][lBlock], lift[lg][hBlock - exp]);\n\t\t}\n\t\t\n\t\tint edgeQuery(int l, int h) {\n\t\t\tint mask=(int) (low[h-1]&((1l<<h-l)-1));\n\t\t\tint moveLeft=Integer.numberOfTrailingZeros(Integer.highestOneBit(mask));\n\t\t\treturn a[h-1-moveLeft];\n\t\t}\n\t}\n\t\n\tclass RMQLowMemoryMax {\n\t\tfinal static int blockSize=32;\n\t\tint[] low, a;\n\t\tint[][] lift;\n\t\t\n\t\tpublic RMQLowMemoryMax(int[] a) {\n\t\t\ta=a.clone();\n\t\t\tfor (int i=0; i<a.length; i++) a[i]*=-1;\n\t\t\tint n=a.length, m=0;\n\t\t\tthis.a=a;\n\t\t\tlow=new int[n];\n\t\t\tfor (int i=0; i<n; low[i]=++m, m<<=1, i++)\n\t\t\t\twhile (m!=0 && a[i-Integer.numberOfTrailingZeros(m)]>=a[i])\n\t\t\t\t\tm-=Integer.lowestOneBit(m);\n\t\t\t\n\t\t\tint nn=(n+blockSize-1)>>5;\n\t\t\tint maxlog = Integer.numberOfTrailingZeros(Integer.highestOneBit(nn)) + 2;\n\t\t\tlift = new int[maxlog][nn];\n\t\t\tArrays.fill(lift[0], Integer.MAX_VALUE);\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tlift[0][i/blockSize]=Math.min(lift[0][i/blockSize], a[i]);\n\n\t\t\tint lastRange = 1;\n\t\t\tfor (int lg = 1; lg < maxlog; lg++, lastRange<<=1)\n\t\t\t\tfor (int i = 0; i < nn; i++)\n\t\t\t\t\tlift[lg][i] = Math.min(lift[lg - 1][i], lift[lg - 1][Math.min(i + lastRange, nn - 1)]);\n\t\t\t\n\t\t}\n\t\t\n\t\tint query(int low, int high) {\n\t\t\thigh++;\n\t\t\tint lowBlock=(low+blockSize-1)>>5, highBlock=high>>5;\n\t\t\tint crossBlock=acrossBlockQuery(lowBlock, highBlock);\n\t\t\tint edge1=edgeQuery(Math.max(low, high-blockSize), high);\n\t\t\tint edge2=edgeQuery(low, Math.min(low+blockSize-1, high));\n\t\t\treturn -Math.min(Math.min(edge1, edge2), crossBlock);\n\t\t}\n\n\t\tint acrossBlockQuery(int lBlock, int hBlock) {\n\t\t\tif (lBlock>=hBlock) return Integer.MAX_VALUE;\n\t\t\tint exp = Integer.highestOneBit(hBlock-lBlock);\n\t\t\tint lg = Integer.numberOfTrailingZeros(exp);\n\t\t\treturn Math.min(lift[lg][lBlock], lift[lg][hBlock - exp]);\n\t\t}\n\t\t\n\t\tint edgeQuery(int l, int h) {\n\t\t\tint mask=(int) (low[h-1]&((1l<<h-l)-1));\n\t\t\tint moveLeft=Integer.numberOfTrailingZeros(Integer.highestOneBit(mask));\n\t\t\treturn a[h-1-moveLeft];\n\t\t}\n\t}\n\t\n//\tclass RMQLowMemoryMax {\n//\t\tfinal static int blockSize=32;\n//\t\tint[] low, a;\n//\t\tint[][] lift;\n//\t\t\n//\t\tpublic RMQLowMemoryMax(int[] a) {\n//\t\t\tint n=a.length, m=0;\n//\t\t\tthis.a=a;\n//\t\t\tlow=new int[n];\n//\t\t\tfor (int i=0; i<n; low[i]=++m, m<<=1, i++)\n//\t\t\t\twhile (m!=0 && a[i-Integer.numberOfTrailingZeros(m)]>=a[i])\n//\t\t\t\t\tm-=Integer.lowestOneBit(m);\n//\t\t\t\n//\t\t\tint nn=(n+blockSize-1)>>5;\n//\t\t\tint maxlog = Integer.numberOfTrailingZeros(Integer.highestOneBit(nn)) + 2;\n//\t\t\tlift = new int[maxlog][nn];\n//\t\t\tArrays.fill(lift[0], Integer.MIN_VALUE);\n//\t\t\tfor (int i = 0; i < n; i++)\n//\t\t\t\tlift[0][i/blockSize]=Math.max(lift[0][i/blockSize], a[i]);\n//\n//\t\t\tint lastRange = 1;\n//\t\t\tfor (int lg = 1; lg < maxlog; lg++, lastRange<<=1)\n//\t\t\t\tfor (int i = 0; i < nn; i++)\n//\t\t\t\t\tlift[lg][i] = Math.max(lift[lg - 1][i], lift[lg - 1][Math.min(i + lastRange, nn - 1)]);\n//\t\t\t\n//\t\t}\n//\t\t\n//\t\tint query(int low, int high) {\n//\t\t\thigh++;\n//\t\t\tint lowBlock=(low+blockSize-1)>>5, highBlock=high>>5;\n//\t\t\tint crossBlock=acrossBlockQuery(lowBlock, highBlock);\n//\t\t\tint edge1=edgeQuery(Math.max(low, high-blockSize), high);\n//\t\t\tint edge2=edgeQuery(low, Math.min(low+blockSize-1, high));\n//\t\t\treturn Math.max(Math.max(edge1, edge2), crossBlock);\n//\t\t}\n//\n//\t\tint acrossBlockQuery(int lBlock, int hBlock) {\n//\t\t\tif (lBlock>=hBlock) return Integer.MIN_VALUE;\n//\t\t\tint exp = Integer.highestOneBit(hBlock-lBlock);\n//\t\t\tint lg = Integer.numberOfTrailingZeros(exp);\n//\t\t\treturn Math.max(lift[lg][lBlock], lift[lg][hBlock - exp]);\n//\t\t}\n//\t\t\n//\t\tint edgeQuery(int l, int h) {\n//\t\t\tint mask=(int) (low[h-1]&((1l<<h-l)-1));\n//\t\t\tint moveLeft=Integer.numberOfTrailingZeros(Integer.highestOneBit(mask));\n//\t\t\treturn a[h-1-moveLeft];\n//\t\t}\n//\t\t\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) {\n\t\t\ttry {\n\t\t\t\tin = new BufferedInputStream(new FileInputStream(new File(s)), BS);\n\t\t\t}\n\t\t\tcatch (Exception e) {\n\t\t\t\tin = new BufferedInputStream(System.in, BS);\n\t\t\t}\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}", "src_uid": "e7dd44bf5e0a0345fd1c40e6957d5641"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class X424A {\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n String[] temp = br.readLine().split(\" \");\n int n = Integer.parseInt(temp[0]);\n String x = br.readLine();\n int a = 0;\n int b = 0;\n for (char ch : x.toCharArray()) {\n if (ch == 'X') {\n a++;\n } else {\n b++;\n }\n }\n StringBuilder sb = new StringBuilder();\n int res = n / 2 - a;\n sb.append(n / 2 - Math.min(a, b));\n sb.append('\\n');\n for (char ch : x.toCharArray()) {\n if (res < 0 && ch == 'X') {\n sb.append('x');\n res++;\n } else if (res > 0 && ch == 'x') {\n sb.append('X');\n res--;\n } else {\n sb.append(ch);\n }\n }\n System.out.println(sb);\n }\n}\n", "src_uid": "fa6311c72d90d8363d97854b903f849d"} {"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 ProblemA {\n public static void main(String[] args) {\n InputReader in = new InputReader();\n PrintWriter out = new PrintWriter(System.out);\n\n new ProblemA().solve(in, out);\n\n out.close();\n }\n\n public void solve(InputReader in, PrintWriter out) {\n int[][] a = new int[8][8];\n\n for (int i = 0; i < 8; i++) {\n String s = in.nextLine();\n\n for (int j = 0; j < s.length(); j++) {\n if (s.charAt(j) == 'W') {\n a[i][j] = 1;\n } else if (s.charAt(j) == 'B') {\n a[i][j] = 2;\n }\n }\n }\n\n int minA = Integer.MAX_VALUE;\n int minB = Integer.MAX_VALUE;\n for (int j = 0; j < 8; j++) {\n\n for (int i = 0; i < 8; i++) {\n if (a[i][j] == 1) {\n boolean isOk = true;\n for (int k = 0; k < i; k++) {\n if (a[k][j] == 2) {\n isOk = false;\n }\n }\n\n if (isOk) {\n minA = Math.min(minA, i);\n }\n }\n }\n\n for (int i = 6; i >= 0; i--) {\n if (a[i][j] == 2) {\n boolean isOk = true;\n for (int k = i + 1; k < 8; k++) {\n if (a[k][j] == 1) {\n isOk = false;\n }\n }\n\n if (isOk) {\n minB = Math.min(minB, 7 - i);\n }\n }\n }\n }\n\n if (minA <= minB) {\n out.print(\"A\");\n } else {\n out.print(\"B\");\n }\n }\n\n static class InputReader {\n public BufferedReader br;\n public StringTokenizer st;\n\n public InputReader() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n public String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return st.nextToken();\n }\n\n public 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", "src_uid": "0ddc839e17dee20e1a954c1289de7fbd"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main implements Runnable {\n\n\tpublic void _main() throws IOException {\n\t\tint n = nextInt();\n\t\tint k = nextInt();\n\t\tint h = nextInt();\n\t\tint[] m = new int[n];\n\t\tint[] v = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tm[i] = nextInt();\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tv[i] = nextInt();\n\t\t}\n\t\tLemming[] a = new Lemming[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = new Lemming(m[i], v[i], i);\n\t\t}\n\t\tArrays.sort(a);\n\t\tdouble left = -1;\n\t\tdouble right = 1500000000;\n\t\tint[] ans = new int[k];\n\t\tfor (int it = 0; it < 100; it++) {\n\t\t\tdouble t = left + (right - left) / 2;\n\t\t\tint j = calc(ans, a, n, t, k, h);\n\t\t\tif (j >= k)\n\t\t\t\tright = t;\n\t\t\telse\n\t\t\t\tleft = t;\n\t\t}\n\t\tcalc(ans, a, n, right, k, h);\n\t\t//out.println(right);\n\t\tfor (int i = 0; i < k; i++)\n\t\t\tout.print((ans[i] + 1) + \" \");\n\t}\n\n\t// calc returns the number of rocks we can climb on if we have t time units\n\tprivate int calc(int[] ans, Lemming[] a, int n, double t, int k, int h) {\n\t\tint j = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tdouble w = t * a[i].v;\n\t\t\tdouble need = (j + 1) * (long)h;\n\t\t\tif (w >= need) {\n\t\t\t\tif (j < k)\n\t\t\t\t\tans[j] = a[i].id;\n\t\t\t\t++j;\n\t\t\t}\n\t\t}\n\t\treturn j;\n\t}\n\n\tclass Lemming implements Comparable<Lemming> {\n\t\tint m, v, id;\n\t\tLemming(int m, int v, int id) {\n\t\t\tthis.m = m;\n\t\t\tthis.v = v;\n\t\t\tthis.id = id;\n\t\t}\n\t\tpublic int compareTo(Lemming o) {\n\t\t\tif (m != o.m) {\n\t\t\t\treturn m < o.m ? -1 : 1;\n\t\t\t}\n\t\t\tif (v != o.v) {\n\t\t\t\treturn v < o.v ? -1 : 1;\n\t\t\t}\n\t\t\tif (id != o.id) {\n\t\t\t\treturn id < o.id ? -1 : 1;\n\t\t\t}\n\t\t\treturn 0;\n\t\t}\n\t}\n\n\n\tprivate BufferedReader in;\n\tprivate PrintWriter out;\n\tprivate StringTokenizer st;\n\n\tprivate String next() throws IOException {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\tString rl = in.readLine();\n\t\t\tif (rl == null)\n\t\t\t\treturn null;\n\t\t\tst = new StringTokenizer(rl);\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tprivate int nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tprivate long nextLong() throws IOException {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tprivate double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tLocale.setDefault(Locale.UK);\n\t\tnew Thread(new Main()).start();\n\t}\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\t//in = new BufferedReader(new FileReader(\"a.in\"));\n\t\t\t//out = new PrintWriter(new FileWriter(\"a.out\"));\n\n\t\t\t_main();\n\n\t\t\tout.close();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(202);\n\t\t}\n\t}\n\n}\n", "src_uid": "6861128fcd83c752b0ea0286869901c2"} {"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 ProblemB {\n public static void main(String[] args) {\n InputReader in = new InputReader();\n PrintWriter out = new PrintWriter(System.out);\n\n new ProblemB().solve(in, out);\n\n out.close();\n }\n\n public void solve(InputReader in, PrintWriter out) {\n int a = in.nextInt();\n int x = in.nextInt();\n int y = in.nextInt();\n\n int k = y / a;\n\n if (k * a == y) {\n out.print(-1);\n\n return;\n }\n\n if (k == 0) {\n if (2 * x >= a || 2 * x <= -1 * a) {\n out.print(-1);\n\n return;\n } else {\n out.print(1);\n\n return;\n }\n }\n\n if (k % 2 == 0) {\n if (x == 0 || x >= a || x <= -1 * a) {\n out.print(-1);\n\n return;\n } else {\n if (x < 0) {\n out.print(k * 3 / 2);\n } else {\n out.print(k * 3 / 2 + 1);\n }\n\n return;\n }\n } else {\n if (2 * x >= a || 2 * x <= -1 * a) {\n out.print(-1);\n\n return;\n } else {\n out.print(3 * (k + 1) / 2 - 1);\n\n return;\n }\n }\n }\n\n static class InputReader {\n public BufferedReader br;\n public StringTokenizer st;\n\n public InputReader() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n public String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return st.nextToken();\n }\n\n public 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", "src_uid": "cf48ff6ba3e77ba5d4afccb8f775fb02"} {"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 int testCount = Integer.parseInt(in.next());\n for (int i = 1; i <= testCount; i++)\n solver.solve(i, in, out);\n out.close();\n }\n\n static class TaskC {\n public int mod = 1000000007;\n public int x1;\n public int x2;\n public int y1;\n public int y2;\n public int k;\n public int MAXB = 32;\n public int[][] dpc;\n public int[][] dps;\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n x1 = in.nextInt() - 1;\n y1 = in.nextInt() - 1;\n x2 = in.nextInt() - 1;\n y2 = in.nextInt() - 1;\n k = in.nextInt() - 1;\n dpc = new int[MAXB][1 << 5];\n dps = new int[MAXB][1 << 5];\n for (int i = 0; i < MAXB; i++) {\n Arrays.fill(dpc[i], -1);\n Arrays.fill(dps[i], -1);\n }\n dfs(MAXB - 1, 0, 0, 0, 0, 0);\n out.println((dps[MAXB - 1][0] + dpc[MAXB - 1][0]) % mod);\n }\n\n public void dfs(int bit, int gx, int lx, int gy, int ly, int lk) {\n int cm = getMask(gx, lx, gy, ly, lk);\n if (dpc[bit][cm] != -1) return;\n\n int cx1 = (x1 >> bit) & 1;\n int cx2 = (x2 >> bit) & 1;\n int cy1 = (y1 >> bit) & 1;\n int cy2 = (y2 >> bit) & 1;\n int ck = (k >> bit) & 1;\n dpc[bit][cm] = 0;\n dps[bit][cm] = 0;\n for (int xb = 0; xb <= 1; xb++) {\n for (int yb = 0; yb <= 1; yb++) {\n if (xb == 0 && cx1 == 1 && gx == 0) continue;\n if (xb == 1 && cx2 == 0 && lx == 0) continue;\n if (yb == 0 && cy1 == 1 && gy == 0) continue;\n if (yb == 1 && cy2 == 0 && ly == 0) continue;\n int bitk = xb ^ yb;\n if (bitk == 1 && ck == 0 && lk == 0) continue;\n\n int ngx = gx | (xb > cx1 ? 1 : 0);\n int ngy = gy | (yb > cy1 ? 1 : 0);\n int nlx = lx | (xb < cx2 ? 1 : 0);\n int nly = ly | (yb < cy2 ? 1 : 0);\n int nlk = lk | (bitk < ck ? 1 : 0);\n\n if (bit > 0) {\n dfs(bit - 1, ngx, nlx, ngy, nly, nlk);\n int ms = getMask(ngx, nlx, ngy, nly, nlk);\n dps[bit][cm] = (int) ((dps[bit][cm] + dps[bit - 1][ms] + 1L * dpc[bit - 1][ms] * (bitk << bit)) % mod);\n dpc[bit][cm] += dpc[bit - 1][ms];\n if (dpc[bit][cm] >= mod) dpc[bit][cm] -= mod;\n } else {\n dps[bit][cm] += bitk << bit;\n dpc[bit][cm]++;\n }\n }\n }\n }\n\n public int getMask(int gx, int lx, int gy, int ly, int lk) {\n int msk = gx;\n msk <<= 1;\n msk |= lx;\n msk <<= 1;\n msk |= gy;\n msk <<= 1;\n msk |= ly;\n msk <<= 1;\n msk |= lk;\n return msk;\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 int nextInt() {\n int c;\n for (c = this.read(); isSpaceChar(c); c = this.read()) {\n ;\n }\n\n byte sgn = 1;\n if (c == 45) {\n sgn = -1;\n c = this.read();\n }\n\n int res = 0;\n\n while (c >= 48 && c <= 57) {\n res *= 10;\n res += c - 48;\n c = this.read();\n if (isSpaceChar(c)) {\n return res * sgn;\n }\n }\n\n throw new InputMismatchException();\n }\n\n public String next() {\n int c;\n while (isSpaceChar(c = this.read())) {\n ;\n }\n\n StringBuilder result = new StringBuilder();\n result.appendCodePoint(c);\n\n while (!isSpaceChar(c = this.read())) {\n result.appendCodePoint(c);\n }\n\n return result.toString();\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 static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void println(int i) {\n writer.println(i);\n }\n\n }\n}\n\n", "src_uid": "1ab085026ce43810acf98cc4bf8faf26"} {"source_code": "// practice with kaiboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF1081A extends PrintWriter {\n\tCF1081A() { super(System.out, true); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1081A o = new CF1081A(); o.main(); o.flush();\n\t}\n\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tprintln(n <= 2 ? n : 1);\n\t}\n}\n", "src_uid": "c30b372a9cc0df4948dca48ef4c5d80d"} {"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", "src_uid": "590a49a7af0eb83376ed911ed488d7e5"} {"source_code": "import java.util.Scanner;\n\npublic class ShowerLine {\n\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tcoeffs = new int[5][5];\n\t\tfor(int i = 0; i < 5; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < 5; j++)\n\t\t\t{\n\t\t\t\tcoeffs[i][j] = scan.nextInt();\n\t\t\t}\n\t\t}\n\t\tscan.close();\n\t\tint[] studsInQueue = new int[5];\n\t\tint maxCoefficient = 0;\n\t\tint sumCoefficient = 0;\n\t\tfor (int i = 0; i < 5; i++)\n\t\t{\n\t\t\tfor (int j = 0; j < 5; j++)\n\t\t\t{\n\t\t\t\tif (i != j)\n\t\t\t\t{\n\t\t\t\t\tfor (int k = 0; k < 5; k++)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (k != i && k != j)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tfor (int l = 0; l < 5; l++)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tif (l != i && l != j && l != k)\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tfor (int m = 0; m < 5; m++)\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tif (m != i && m != j && m != k && m != l)\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tsumCoefficient = coeff(i, j, k, l, m);\n\t\t\t\t\t\t\t\t\t\t\tif (sumCoefficient > maxCoefficient)\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\tmaxCoefficient = sumCoefficient;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\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\tSystem.out.println(maxCoefficient);\n\t}\n\t\n\tpublic static int coeff(int i, int j, int k, int l, int m)\n\t{\n\t\treturn 2*(coeffs[l][m] + coeffs[m][l] + coeffs[k][l] + coeffs[l][k])+\n\t\t\t\tcoeffs[i][j] + coeffs[j][i] + coeffs[j][k] + coeffs[k][j];\n\t}\n\t\n\tprivate static int coeffs[][];\n\n}\n", "src_uid": "be6d4df20e9a48d183dd8f34531df246"} {"source_code": "import java.util.*;\n\n/**\n *\n * @author greggy\n */\npublic class PlayingWithPaper {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n long a, b;\n a = in.nextLong();\n b = in.nextLong();\n\n long ans = 0;\n while (a > 0 && b > 0) {\n if (a > b) {\n ans += a / b;\n a = a % b;\n } else {\n ans += b / a;\n b %= a;\n }\n }\n System.out.println(ans);\n }\n}", "src_uid": "ce698a0eb3f5b82de58feb177ce43b83"} {"source_code": "import java.util.HashSet;\nimport java.util.Scanner;\n\npublic class Antipalindrome {\n\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tString s=scan.nextLine();\n\t\tHashSet<Character> h= new HashSet<Character>();\n\t\tfor(int i=0;i<s.length();i++) {\n\t\t\th.add(s.charAt(i));\n\t\t}\n\t\tif(h.size()==1) {\n\t\t\tSystem.out.println(\"0\");\n\t\t\treturn;\n\t\t}\n\t\tStringBuilder s1= new StringBuilder(s);\n\t\ts1.reverse();\n\t\tif(s.contains(s1)) System.out.println(s.length()-1);\n\t\telse System.out.println(s.length());\n\n\t}\n\n}\n", "src_uid": "6c85175d334f811617e7030e0403f706"} {"source_code": "import java.math.BigInteger;\nimport java.util.Scanner;\n\npublic class q2B {\n\n private static Scanner input = new Scanner(System.in);\n public static void main(String[] args) {\n\n// System.out.println(S(2197413));\n\n// double number = input.nextDouble();\n// double half = Math.floor(number / 2);\n// double remHalf = number - half;\n// int max = 0;\n// double i = 0;\n// while (true) {\n// int calc = S(half-i) + S(remHalf+i);\n// if (calc >= max) max = calc;\n// else break;\n// i++;\n// }\n// System.out.println(max);\n\n long number = input.nextLong();\n long rem10 = number % 10;\n// System.out.println((S(9) + S(number-9)));\n int max = 0;\n for (int i = 0; i < countS(number); i++) {\n double base = Math.pow(10,i)-1;\n int calc = S(base) + S(number - base);\n if (calc > max) max = calc;\n }\n System.out.println(max);\n\n\n\n\n\n }\n private static int S(double a)\n {\n int res = 0;\n while (a > 0)\n {\n res += a % 10;\n a = Math.floor(a/10);\n }\n return res;\n }\n private static int countS(double a)\n {\n int res = 0;\n while (a > 0)\n {\n res ++;\n a = Math.floor(a/10);\n }\n return res;\n }\n}\n//10000000000", "src_uid": "5c61b4a4728070b9de49d72831cd2329"} {"source_code": "\nimport java.util.*;\nimport java.io.*;\n\npublic class B {\n\n\tstatic final boolean stdin = true;\n\tstatic final String filename = \"\";\n\tstatic FastScanner br;\n\tstatic PrintWriter pw;\n\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tif (stdin) {\n\t\t\tbr = new FastScanner();\n\t\t\tpw = new PrintWriter(new OutputStreamWriter(System.out));\n\t\t} else {\n\t\t\tbr = new FastScanner(filename + \".in\");\n\t\t\tpw = new PrintWriter(new FileWriter(filename + \".out\"));\n\t\t}\n\n\t\tSolver solver = new Solver();\n\t\tsolver.solve(br, pw);\n\t\tpw.close();\n\t}\n\n\tstatic class Solver {\n\t\tstatic long mod = (long) (1e9);\n\n\t\tpublic void solve(FastScanner br, PrintWriter pw) throws IOException {\n\t\t\tint n = br.ni();\n\t\t\tlong out = 0;\n\t\t\twhile(n > 0) {\n\t\t\t\tout += n;\n\t\t\t\tn-=2;\n\t\t\t}\n\t\t\tpw.println(out);\n\t\t}\n\n\t\tstatic long gcd(long a, long b) {\n\t\t\tif (a > b)\n\t\t\t\treturn gcd(b, a);\n\t\t\tif (a == 0)\n\t\t\t\treturn b;\n\t\t\treturn gcd(b % a, a);\n\t\t}\n\n\t\tstatic long lcm(long a, long b) {\n\t\t\treturn a * (b / gcd(a, b));\n\t\t}\n\n\t\tstatic long pow(long a, long b) {\n\t\t\tif (b == 0)\n\t\t\t\treturn 1L;\n\t\t\tlong val = pow(a, b / 2);\n\t\t\tif (b % 2 == 0)\n\t\t\t\treturn val * val % mod;\n\t\t\telse\n\t\t\t\treturn val * val % mod * a % mod;\n\t\t}\n\n\t}\n\n\tstatic class Point implements Comparable<Point> {\n\t\tint a;\n\t\tint b;\n\n\t\tPoint(int a, int b) {\n\t\t\tthis.a = a;\n\t\t\tthis.b = b;\n\t\t}\n\n\t\t@Override\n\t\tpublic int compareTo(Point o) {\n\t\t\treturn this.a - o.a;\n\t\t}\n\n\t\tpublic boolean equals(Object obj) {\n\t\t\tif (obj instanceof Point) {\n\t\t\t\tPoint other = (Point) obj;\n\t\t\t\treturn a == other.a && b == other.b;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\tpublic int hashCode() {\n\t\t\treturn 65536 * a + b + 4733 * 0;\n\t\t}\n\n\t}\n\n\tpublic static class FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\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\te.printStackTrace();\n\t\t\t}\n\t\t}\n\n\t\tpublic FastScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tArrayList<Integer>[] ng(int n, int e) {\n\t\t\tArrayList<Integer>[] adj = new ArrayList[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tadj[i] = new ArrayList<Integer>();\n\t\t\t}\n\t\t\tfor (int i = 0; i < e; i++) {\n\t\t\t\tint a = ni() - 1;\n\t\t\t\tint b = ni() - 1;\n\t\t\t\tadj[a].add(b);\n\t\t\t\tadj[b].add(a);\n\t\t\t}\n\t\t\treturn adj;\n\t\t}\n\n\t\tInteger[] nIa(int n) {\n\t\t\tInteger[] arr = new Integer[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = ni();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tint[] nia(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] = ni();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tLong[] nLa(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] = nl();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tlong[] nla(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] = nl();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tString[] nsa(int n) {\n\t\t\tString[] arr = new String[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tarr[i] = nt();\n\t\t\t}\n\t\t\treturn arr;\n\t\t}\n\n\t\tString nt() {\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 ni() {\n\t\t\treturn Integer.parseInt(nt());\n\t\t}\n\n\t\tlong nl() {\n\t\t\treturn Long.parseLong(nt());\n\t\t}\n\n\t\tdouble nd() {\n\t\t\treturn Double.parseDouble(nt());\n\t\t}\n\n\t}\n}", "src_uid": "f8af5dfcf841a7f105ac4c144eb51319"} {"source_code": "import java.util.Set;\nimport java.util.Scanner;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.HashSet;\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\tScanner in = new Scanner(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 long pow(long a, int n, long m) {\n if (n == 0)\n return 1;\n else if (n % 2 == 1)\n return a * pow(a, n-1, m) % m;\n else\n return pow(a*a%m, n/2, m) % m;\n }\n\n public void solve(@SuppressWarnings(\"UnusedParameters\") int testNumber, Scanner in, PrintWriter out) {\n int n = in.nextInt(), x = in.nextInt();\n if (!isPrime(n+1)) {\n out.println(-1);\n return;\n }\n\n Set<Integer> d = new HashSet<Integer>();\n for (int i = 2; i*i < n; ++i)\n if (n % i == 0 && isPrime(i))\n d.add(n / i);\n\n for (x--; x > 1; --x) {\n if (x % (n+1) != 0) {\n boolean ok = true;\n for (int i: d)\n if (pow(x, i, n+1) == 1) {\n ok = false;\n break;\n }\n if (ok) {\n out.println(x);\n return;\n }\n }\n }\n out.println(-1);\n }\n\n private boolean isPrime(long x) {\n for (long i = 2; i*i <= x; ++i)\n if (x % i == 0)\n return false;\n return true;\n }\n}\n\n", "src_uid": "29dda6a3f057e5bccdc076d7e492ac9a"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class C_submit {\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\t\n\tstatic long[][] c = new long[61][];\n\tstatic {\n\t\tfor (int i = 0; i < c.length; i++) {\n\t\t\tc[i] = new long[i + 1];\n\t\t\tc[i][0] = c[i][i] = 1;\n\t\t\tfor (int j = 1; j < i; j++)\n\t\t\t\tc[i][j] = c[i - 1][j] + c[i - 1][j - 1];\n\t\t}\n\t}\n\t\n\tlong c(int n, int k) {\n\t\treturn n < 0 || k < 0 || k > n ? 0 : c[n][k];\n\t}\n\t\n\tvoid solve() throws IOException {\n\t\tlong n = nextLong();\n\t\tlong t = nextLong();\n\t\tif (Long.bitCount(t) != 1) {\n\t\t\tout.println(0);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tint need = Long.numberOfTrailingZeros(t) + 1;\n\t\t\n\t\t// return numbers of x : 2 <= x <= n + 1, bitcount(x) = need\n\t\t\n\t\tn += 2;\n\t\t\n\t\tString s = Long.toBinaryString(n);\n\t\t\n\t\tint prefBitCnt = 0;\n\t\t\n\t\tlong ans = 0;\n\t\t\n\t\tfor (int i = 0; i < s.length(); i++) {\n\t\t\tif (s.charAt(i) == '1') {\n\t\t\t\tint sufLen = s.length() - i - 1;\n\t\t\t\tans += c(sufLen, need - prefBitCnt);\n\t\t\t\tprefBitCnt++;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (need == 1)\n\t\t\tans--;\n\t\t\n\t\tout.println(ans);\n\t}\n\n\tC_submit() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew C_submit();\n\t}\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\teof = true;\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "src_uid": "727d5b601694e5e0f0cf3a9ca25323fc"} {"source_code": "import java.util.List;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.ArrayList;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.io.Writer;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Niyaz Nigmatullin\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastScanner in = new FastScanner(inputStream);\n\t\tFastPrinter out = new FastPrinter(outputStream);\n\t\tMonitor solver = new Monitor();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass Monitor {\n public void solve(int testNumber, FastScanner in, FastPrinter out) {\n int a = in.nextInt();\n int b = in.nextInt();\n int x = in.nextInt();\n int y = in.nextInt();\n int g = MathUtils.gcd(x, y);\n x /= g;\n y /= g;\n int z = Math.min(a / x, b / y);\n if (z == 0) {\n out.println(\"0 0\");\n return;\n }\n out.println(x * z + \" \" + y * z);\n }\n}\n\nclass FastScanner extends BufferedReader {\n\n boolean isEOF;\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 >= -1 && 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 (!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 }\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\nclass MathUtils {\n\n public static int gcd(int a, int b) {\n while (b != 0) {\n int t = a % b;\n a = b;\n b = t;\n }\n return a;\n }\n\n\n }\n\n", "src_uid": "97999cd7c6de79a4e39f56a41ff59e7a"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class TaskD {\n\n public void solve() throws IOException {\n int n = 5;\n boolean[][] h = new boolean[n][n];\n int m = in.nextInt();\n for (int i = 0; i < m; ++i) {\n h[in.nextInt() - 1][in.nextInt() - 1] = true;\n }\n for (int i = 0; i < n; ++i) {\n for (int j = 0; j < n; ++j) {\n h[i][j] |= h[j][i];\n }\n }\n boolean ans = false;\n for (int i = 0; i < n; ++i) {\n for (int j = i + 1; j < n; ++j) {\n for (int k = j + 1; k < n; ++k) {\n ans |= (h[i][j] == h[j][k]) && (h[j][k] == h[k][i]);\n }\n }\n }\n out.println(ans ? \"WIN\" : \"FAIL\");\n }\n\n static FastReader in;\n static PrintWriter out;\n static PrintStream err;\n\n public static void main(String[] args) throws IOException {\n try {\n in = new FastReader();\n out = new PrintWriter(System.out);\n err = System.err;\n new TaskD().solve();\n out.close();\n } catch (IOException e) {\n e.printStackTrace();\n System.exit(1);\n }\n }\n}\n\nclass FastReader {\n BufferedReader br;\n StringTokenizer in;\n\n FastReader() {\n this.br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n FastReader(String filename) {\n try {\n this.br = new BufferedReader(new FileReader(filename));\n } catch (IOException e) {\n e.printStackTrace();\n System.exit(1);\n }\n }\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}", "src_uid": "2bc18799c85ecaba87564a86a94e0322"} {"source_code": "import java.util.*;\npublic class Main{\n public static void main(String args[]){\n Scanner sc=new Scanner(System.in);\n int size1=sc.nextInt();\n int size2=sc.nextInt();\n int[] arr1=new int[size1];\n int[] arr2=new int[size2];\n for(int i=0;i<size1;i++)arr1[i]=sc.nextInt();\n for(int i=0;i<size2;i++)arr2[i]=sc.nextInt();\n Arrays.sort(arr1);\n Arrays.sort(arr2);\n boolean flag2=false;\n for(int i=0;i<size1;i++){\n boolean flag=false;\n for(int j=0;j<size2;j++){\n if(arr1[i]==arr2[j]){\n System.out.println(arr1[i]);\n flag=true;\n break;\n }\n }\n if(flag){flag2=true;break;}\n }\n if(!flag2){\n if(arr1[0]<arr2[0]) System.out.println(arr1[0]+\"\"+arr2[0]);\n \n else if(arr1[0]>arr2[0]) System.out.println(arr2[0]+\"\"+arr1[0]);}\n }\n}", "src_uid": "3a0c1b6d710fd8f0b6daf420255d76ee"} {"source_code": "import java.util.*;\npublic class Div4\n{\npublic static void main(String args[])\n{\nScanner e=new Scanner(System.in);\nString s=e.next();\nint f=s.indexOf('1');\nint x=0;\nif(f==-1)\nSystem.out.println(\"no\");\nelse\n{\nfor(int i=f;i<s.length();i++)\n{\nif(s.charAt(i)=='0')\nx++;\n}\nif(x>=6)\nSystem.out.println(\"yes\");\nelse\nSystem.out.println(\"no\");\n}\n}\n}", "src_uid": "88364b8d71f2ce2b90bdfaa729eb92ca"} {"source_code": "import java.io.*;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.util.*;\n\nimport static java.lang.Double.parseDouble;\nimport static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\n\npublic class Main {\n public static void main(String[] args) throws IOException {\n new Solver().run();\n }\n}\n\nclass Solver {\n BufferedReader in;\n PrintWriter out;\n StringTokenizer tok;\n\n void run() throws IOException {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n //in = new BufferedReader(new FileReader(\"digit.in\"));\n //out = new PrintWriter(new File(\"digit.out\"));\n solve();\n out.close();\n }\n\n public void solve() throws IOException {\n\n String S = next();\n int k = nextInt();\n\n char[] st = new char[S.length()];\n st = S.toCharArray();\n int n = st.length;\n\n char[] ans = new char[n];\n int ptr = 0;\n\n while (k > 0 && ptr < n) {\n int maxi = st[ptr], pos = ptr;\n for (int i = ptr + 1; i <= ptr + k && i < n; ++i) {\n if (st[i] > maxi) {\n maxi = st[i];\n pos = i;\n }\n }\n for (int i = pos; i >= ptr + 1; --i) {\n st[i] = st[i - 1];\n }\n k -= pos - ptr;\n st[ptr] = (char) maxi;\n ++ptr;\n }\n\n out.println(st);\n }\n\n String next() throws IOException {\n if (tok == null || !tok.hasMoreTokens()) {\n tok = new StringTokenizer(in.readLine());\n }\n return tok.nextToken();\n }\n\n BigInteger nextBigInteger() throws IOException {\n return new BigInteger(next());\n }\n\n int nextInt() throws IOException {\n return parseInt(next());\n }\n\n long nextLong() throws IOException {\n return parseLong(next());\n }\n\n double nextDouble() throws IOException {\n return parseDouble(next());\n }\n}", "src_uid": "e56f6c343167745821f0b18dcf0d0cde"} {"source_code": "import java.io.*;\nimport java.util.*;\npublic class GeneticEngineering \n{\n public static void main(String[] args) throws IOException\n {\n //BufferedReader in = new BufferedReader(new FileReader(\"Sample Input.txt\"));\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n String line = in.readLine();\n int same=1, ins=0;\n for (int i = 1; i < line.length(); i++) \n {\n if ( line.charAt(i) == line.charAt(i-1)) same++;\n else\n {\n if ( same%2 == 0)ins++;\n same=1;\n }\n }\n if ( same%2 == 0) ins++;\n System.out.println(ins);\n }\n\n}", "src_uid": "8b26ca1ca2b28166c3d25dceb1f3d49f"} {"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 static final int[] MAGIC = { 2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127,\n 521, 607, 1279, 2203, 2281, 3217, 4253, 4423, 9689, 9941, 11213,\n 19937, 21701, 23209, 44497, 86243, 110503, 132049, 216091, 756839,\n 859433, 1257787, 1398269, 2976221, 3021377, 6972593, 13466917,\n 20996011 };\n\n // boolean test(int z) {\n // for (int x = 1; x + 1<= z; x++) {\n // int A = x + 1;\n // int B = x >> 1;\n // if (z % A == B && z >= A + B)\n // return false;\n // }\n // return true;\n // }\n \n static final int MOD = 1000000007;\n \n int pow(int a, int b) {\n int res = 1;\n while (b != 0) {\n if ((b & 1) == 1)\n res = (int)((long)res * a % MOD);\n a = (int)((long)a * a % MOD);\n b >>= 1;\n }\n return res;\n }\n\n void solve() throws IOException {\n int n = nextInt() - 1;\n int res = pow(2, MAGIC[n] - 1);\n res--;\n if (res < 0)\n res += MOD;\n out.println(res);\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 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}\n", "src_uid": "c2cbc35012c6ff7ab0d6899e6015e4e7"} {"source_code": "/*\n\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u2877\u28ef\u28bf\u28ff\u28f7\u28fb\u28af\u28ff\u287d\u28fb\u28bf\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28c7\u2838\u28ff\u28ff\u28c6\u2839\u28ff\u28ff\u28be\u28df\u28ef\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28fd\u28fb\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\n\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28fb\u28fd\u287f\u28ff\u28ce\u2819\u28ff\u28de\u28f7\u284c\u28bb\u28df\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28f7\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u2844\u2839\u28ff\u28ff\u2846\u283b\u28ff\u28df\u28ef\u287f\u28fd\u287f\u28ff\u28ff\u28ff\u28ff\u28fd\u2877\u28ef\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\n\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28df\u28f7\u28ff\u28ff\u28ff\u2840\u2839\u28df\u28fe\u28df\u28c6\u2839\u28ef\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u2847\u28a0\u2858\u28ff\u28ff\u2844\u2809\u28bf\u28ff\u28fd\u2877\u28ff\u28fb\u28ff\u28ff\u28ff\u28ff\u285d\u28f7\u28ef\u28bf\u28ff\u28ff\u28ff\u28ff\n\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ef\u28bf\u28fe\u28bf\u28ff\u2844\u2884\u2818\u28bf\u28de\u287f\u28e7\u2848\u28b7\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u2847\u28b8\u28e7\u2818\u28ff\u28f7\u2808\u28e6\u2819\u28bf\u28fd\u28f7\u28fb\u28fd\u28ff\u28ff\u28ff\u28ff\u28cc\u28bf\u28ef\u28bf\u28ff\u28ff\u28ff\n\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28df\u28ef\u28ff\u28bf\u28ff\u2846\u28b8\u2877\u2848\u28bb\u287d\u28f7\u2877\u2844\u283b\u28fd\u28ff\u28ff\u287f\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28f7\u28ff\u28ff\u28ff\u28ff\u28cf\u28b0\u28ef\u28b7\u2808\u28ff\u2846\u28b9\u28b7\u284c\u283b\u287e\u288b\u28f1\u28ef\u28ff\u28ff\u28ff\u28ff\u2846\u28bb\u287f\u28ff\u28ff\u28ff\n\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u284e\u28ff\u28be\u287f\u28ff\u2846\u28b8\u28fd\u28bb\u28c4\u2839\u28f7\u28df\u28ff\u28c4\u2839\u28df\u28ff\u28ff\u28df\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28fd\u28ff\u28ff\u28ff\u2847\u28b8\u28ef\u28df\u28e7\u2818\u28f7\u2808\u286f\u281b\u2880\u2850\u28be\u28df\u28f7\u28fb\u28ff\u28ff\u28ff\u287f\u284c\u28bf\u28fb\u28ff\u28ff\n\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28e7\u28b8\u287f\u28df\u28ff\u2847\u28b8\u28ef\u28df\u28ee\u28a7\u2848\u28bf\u28de\u287f\u28e6\u2818\u280f\u28f9\u28ff\u28fd\u28bf\u28ff\u28ff\u28ff\u28ff\u28ef\u28ff\u28ff\u28ff\u2847\u28b8\u28ff\u28ff\u28fe\u2846\u2839\u2880\u28e0\u28fe\u28df\u28f7\u2848\u28bf\u28de\u28ef\u28bf\u28ff\u28ff\u28ff\u28b7\u2818\u28ef\u28ff\u28ff\n\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u2848\u28ff\u28bf\u28fd\u2847\u2818\u281b\u281b\u281b\u2813\u2813\u2808\u281b\u281b\u281f\u2807\u2880\u28bf\u28fb\u28ff\u28ef\u28bf\u28ff\u28ff\u28ff\u28f7\u28bf\u28ff\u28ff\u2801\u28fe\u28ff\u28ff\u28ff\u28e7\u2844\u2807\u28f9\u28ff\u28fe\u28ef\u28ff\u2844\u283b\u28fd\u28ef\u28bf\u28fb\u28ff\u28ff\u2847\u28b9\u28fe\u28ff\n\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u2847\u28b9\u28ff\u287d\u2847\u28b8\u28ff\u28ff\u28ff\u28ff\u28ff\u28de\u28c6\u2830\u28f6\u28f6\u2844\u2880\u28bb\u287f\u28ef\u28ff\u287d\u28ff\u28ff\u28ff\u28af\u28df\u287f\u2880\u28ff\u28ff\u28ff\u28ff\u28ff\u28e7\u2810\u28f8\u28ff\u28ff\u28f7\u28ff\u28ff\u28c6\u2839\u28ef\u28ff\u28fb\u28ff\u28ff\u28ff\u2880\u28ff\u28bf\n\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u2818\u28ef\u287f\u2847\u28b8\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28e7\u2848\u28bf\u28f3\u2818\u2844\u283b\u28ff\u28be\u28fd\u28df\u287f\u28ff\u28af\u28ff\u2847\u28b8\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u2840\u28be\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28c6\u2839\u28fe\u28f7\u28fb\u28ff\u287f\u2847\u28b8\u28ff\n\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u2847\u28b9\u28ff\u2807\u28b8\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28f7\u28c4\u283b\u2847\u28b9\u28c6\u2839\u28df\u28fe\u28fd\u28fb\u28df\u28ff\u28fd\u2801\u28fe\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28c7\u28ff\u28ff\u283f\u281b\u281b\u2809\u2819\u280b\u2880\u2801\u2898\u28ef\u28ff\u28ff\u28e7\u2818\u28ff\n\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u2848\u28ff\u2843\u28bc\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28e6\u2859\u280c\u28ff\u28c6\u2818\u28ff\u28de\u287f\u28de\u287f\u285e\u28a0\u28ff\u28ff\u28ff\u28ff\u28ff\u287f\u281b\u2809\u2801\u2880\u28c0\u28e0\u28e4\u28e4\u28f6\u28f6\u28f6\u2846\u28bb\u28fd\u28de\u287f\u28f7\u2808\u28ff\n\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u287f\u2803\u2818\u2801\u2809\u2809\u2809\u2809\u2809\u2809\u2809\u2809\u2809\u2819\u281b\u281b\u28bf\u28c4\u28bb\u28ff\u28e7\u2818\u28af\u28df\u287f\u28fd\u2801\u28fe\u28ff\u28ff\u28ff\u28ff\u28ff\u2843\u2880\u2880\u2818\u281b\u283f\u28bf\u28fb\u28df\u28ef\u28fd\u28fb\u28f5\u2840\u28bf\u28ef\u28df\u28ff\u2880\u28ff\n\u28ff\u28ff\u28ff\u28df\u28ff\u28ff\u28ff\u28ff\u28f6\u28f6\u2846\u2880\u28ff\u28fe\u28ff\u28fe\u28f7\u28ff\u28f6\u283f\u281a\u2809\u2880\u2880\u28e4\u28ff\u28f7\u28ff\u28ff\u28f7\u2848\u28bf\u28fb\u2883\u28fc\u28ff\u28ff\u28ff\u28ff\u28fb\u28ff\u28ff\u28ff\u2876\u28e6\u28e4\u28c4\u28c0\u2840\u2809\u281b\u281b\u2837\u28ef\u28f3\u2808\u28fe\u287d\u28fe\u2880\u28ff\n\u28ff\u28bf\u28ff\u28ff\u28fb\u28ff\u28ff\u28ff\u28ff\u28ff\u287f\u2810\u28ff\u28ff\u28ff\u28ff\u283f\u280b\u2801\u2880\u2880\u28e4\u28fe\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28cc\u28e5\u28fe\u287f\u28ff\u28ff\u28f7\u28ff\u28ff\u28bf\u28f7\u28ff\u28ff\u28df\u28fe\u28fd\u28f3\u28af\u28df\u28f6\u28e6\u28e4\u287e\u28df\u28e6\u2818\u28ff\u28be\u2841\u28ba\n\u28ff\u28fb\u28ff\u28ff\u2877\u28ff\u28ff\u28ff\u28ff\u28ff\u2857\u28e6\u2838\u287f\u280b\u2801\u2880\u2880\u28e0\u28f4\u28bf\u28ff\u28fd\u28fb\u28bd\u28fe\u28df\u28f7\u28ff\u28df\u28ff\u28ff\u28ff\u28f3\u283f\u28f5\u28e7\u28fc\u28ff\u28ff\u28ff\u28ff\u28ff\u28fe\u28ff\u28ff\u28ff\u28ff\u28ff\u28fd\u28f3\u28ef\u28ff\u28ff\u28ff\u28fd\u2880\u28b7\u28fb\u2804\u2818\n\u28ff\u28b7\u28fb\u28ff\u28ff\u28f7\u28fb\u28ff\u28ff\u28ff\u2877\u281b\u28c1\u2880\u28c0\u28e4\u28f6\u28ff\u28db\u287f\u28ff\u28ee\u28fd\u287b\u28ff\u28ee\u28fd\u28fb\u28af\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ef\u2880\u28b8\u28ff\u2880\u2846\n\u2838\u28df\u28ef\u28ff\u28ff\u28f7\u28bf\u28fd\u28ff\u28ff\u28f7\u28ff\u28f7\u28c6\u2839\u28ff\u28f6\u28ef\u283f\u28ff\u28f6\u28df\u28fb\u28bf\u28f7\u28fd\u28fb\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u2880\u28ef\u28df\u2880\u2847\n\u28c7\u2839\u28df\u28fe\u28fb\u28ff\u28ff\u28be\u287d\u28ff\u28ff\u28ff\u28ff\u28ff\u28c6\u28b9\u28f6\u28ff\u28fb\u28f7\u28ef\u28df\u28ff\u28ff\u28fd\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u287f\u2880\u287f\u2847\u28b8\u2847\n\u28ff\u28c6\u2839\u28f7\u287b\u28fd\u28ff\u28ef\u28bf\u28fd\u28fb\u28ff\u28ff\u28ff\u28ff\u28c6\u28bb\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u281b\u28bb\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u2807\u28b8\u28ff\u2807\u28fc\u2847\n\u2859\u283e\u28c6\u2839\u28ff\u28e6\u281b\u28ff\u28af\u28f7\u28bf\u287d\u28ff\u28ff\u28ff\u28ff\u28c6\u283b\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u2803\u280e\u28b8\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u280f\u2880\u28ff\u28fe\u28e3\u287f\u2847\n\u28ff\u28f7\u284c\u28a6\u2819\u28ff\u28ff\u28cc\u283b\u28fd\u28af\u28ff\u28fd\u28fb\u28ff\u28ff\u28ff\u28e7\u2829\u28bb\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u284f\u28b0\u28a3\u2818\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u287f\u2803\u2880\u2880\u28bf\u28de\u28f7\u28bf\u2847\n\u28ff\u28fd\u28c6\u2839\u28e7\u2818\u28ff\u28ff\u2877\u28cc\u2819\u28b7\u28ef\u2877\u28df\u28ff\u28ff\u28ff\u28f7\u2840\u2879\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28f7\u28c8\u2803\u28f8\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u281f\u2880\u28f4\u2867\u2880\u2838\u28ff\u287d\u28ff\u2880\n\u28bb\u28fd\u28ff\u2844\u28bb\u28f7\u2848\u28bf\u28ff\u28ff\u28a7\u2880\u2819\u28bf\u28fb\u287e\u28fd\u28fb\u28ff\u28ff\u28c4\u280c\u28bf\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u281b\u2881\u28f0\u28fe\u28df\u287f\u2880\u2844\u28bf\u28df\u28ff\u2880\n\u2844\u28bf\u28ff\u28f7\u2880\u2839\u28df\u28c6\u283b\u28ff\u28ff\u28c6\u2880\u28c0\u2809\u283b\u28ff\u287d\u28ef\u28ff\u28ff\u28f7\u28c8\u28bb\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u287f\u280b\u2880\u28e0\u2818\u28ef\u28f7\u28ff\u285f\u2880\u2886\u2838\u28ff\u285f\u28b8\n\u28f7\u2848\u28bf\u28ff\u28c7\u28b1\u2858\u28bf\u28f7\u28ec\u28d9\u283f\u28e7\u2818\u28c6\u2880\u2808\u283b\u28f7\u28df\u28fe\u28bf\u28ff\u28c6\u2839\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u287f\u280b\u28e0\u285e\u28a1\u28ff\u2880\u28ff\u28ff\u28ff\u2807\u2844\u28b8\u2844\u28bb\u2847\u28fc\n\u28ff\u28f7\u2848\u28bf\u28ff\u2846\u28a3\u2840\u2819\u28be\u28df\u28ff\u28ff\u28f7\u2848\u2802\u2818\u28e6\u2848\u283f\u28ef\u28ff\u28be\u28ff\u28c6\u2819\u283b\u283f\u283f\u283f\u283f\u287f\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u283f\u281b\u288b\u28e0\u28fe\u285f\u28a0\u28ff\u28ff\u2880\u28ff\u28ff\u285f\u28a0\u28ff\u2888\u28e7\u2818\u28a0\u28ff\n\u28ff\u28ff\u28ff\u28c4\u283b\u28ff\u2844\u28b3\u2844\u2886\u2859\u283e\u28fd\u28ff\u28ff\u28c6\u2840\u28b9\u2877\u28c4\u2819\u28bf\u28ff\u287e\u28ff\u28c6\u2880\u2840\u2880\u2880\u2880\u2880\u2880\u2880\u2880\u2880\u2880\u2880\u2880\u2880\u28c0\u28e0\u28f4\u287f\u28ef\u280f\u28e0\u28ff\u28ff\u284f\u28b8\u28ff\u287f\u2881\u28ff\u28ff\u2880\u28ff\u2806\u28b8\u28ff\n\u28ff\u28ff\u28ff\u28ff\u28e6\u2859\u28ff\u28c6\u28bb\u284c\u28bf\u28f6\u28a4\u28c9\u28d9\u28ff\u28f7\u2840\u2819\u283d\u2837\u2804\u2839\u28ff\u28df\u28ff\u28c6\u2899\u28cb\u28e4\u28e4\u28e4\u28c4\u28c0\u2880\u2880\u2880\u2880\u28fe\u28ff\u28df\u2877\u28ef\u287f\u2883\u28fc\u28ff\u28ff\u28ff\u2807\u28fc\u285f\u28e1\u28ff\u28ff\u28ff\u2880\u287f\u28a0\u2808\u28ff\n\u28ff\u28ff\u28ff\u28ff\u28ff\u28f7\u28ee\u28ff\u28ff\u28ff\u284c\u2801\u28a4\u28e4\u28e4\u28e4\u28ec\u28ed\u28f4\u28f6\u28f6\u28f6\u28c6\u2808\u28bb\u28ff\u28ff\u28c6\u28bb\u28ff\u28ff\u28ff\u28ff\u28ff\u28ff\u28f7\u28f6\u28e4\u28cc\u28c9\u2858\u281b\u283b\u2836\u28ff\u28ff\u28ff\u28ff\u285f\u28f0\u28eb\u28f4\u28ff\u28ff\u28ff\u28ff\u2804\u28f7\u28ff\u28ff\u28ff\n*/\n\nimport java.io.DataInputStream;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.Scanner;\n\npublic class b {\n\t\n\t\n\tpublic static void main(String[] args) throws Exception {\n\n\t Scanner s=new Scanner(System.in);\n\t \n\t int n=s.nextInt();\n\t int k=s.nextInt();\n\t int[] arr=new int[n];\n\t for(int i=0;i<n;i++) {\n\t \t arr[i]=s.nextInt();\n\t }\n\t \n\t \n\t int[] ans=new int[n];\n\t \n\t for(int i=0;i<n;i++) {\n\t \t ArrayList<Integer> list=new ArrayList<>();\n\t \t for(int j=0;j<i;j++) {\n\t \t\t list.add(arr[j]);\n\t \t }\n\t \t \n\t \t Collections.sort(list);\n\t \t int st=0;\n\t \t \n\t \t int sum=arr[i];\n\t \t while(st<list.size()&&sum+list.get(st)<=k) {\n\t \t\t sum=sum+list.get(st);\n\t \t\t st++;\n\t \t }\n\t \t ans[i]=list.size()-st;\n\t \t \n\t \t \n\t }\n\t \n\t \n\t for(int i=0;i<n;i++) {\n\t \t System.out.print(ans[i]+\" \");\n\t }\n\t \n\t \n\t \n\t \n\t \n\n\t\t\n\t}\n}", "src_uid": "d3c1dc3ed7af2b51b4c49c9b5052c346"} {"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 E {\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\tchar[][] ss = nm(n,m);\n\t\tint[][] M = new int[m][n];\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tfor(int j = 0;j < m;j++){\n\t\t\t\tM[j][i] = ss[i][j]-'a';\n\t\t\t}\n\t\t}\n\t\tResult res = rank(M, 5);\n\t\tint[][] o = res.v;\n\t\tint rank = res.rank;\n\t\touter:\n\t\tfor(int Q = ni();Q > 0;Q--){\n\t\t\tchar[] ys = ns(m);\n\t\t\tint[] y = new int[m];\n\t\t\tfor(int i = 0;i < m;i++)y[i] = ys[i]-'a';\n\t\t\ty = mul(o, y, 5);\n\t\t\tfor(int i = rank;i < m;i++){\n\t\t\t\tif(y[i] != 0){\n\t\t\t\t\tout.println(0);\n\t\t\t\t\tcontinue outer;\n\t\t\t\t}\n\t\t\t}\n\t\t\tout.println(pow(5, n-rank, 1000000007));\n\t\t}\n\t}\n\t\n\tpublic static long pow(long a, long n, long mod) {\n\t\t//\t\ta %= mod;\n\t\tlong ret = 1;\n\t\tint x = 63 - Long.numberOfLeadingZeros(n);\n\t\tfor (; x >= 0; x--) {\n\t\t\tret = ret * ret % mod;\n\t\t\tif (n << 63 - x < 0)\n\t\t\t\tret = ret * a % mod;\n\t\t}\n\t\treturn ret;\n\t}\n\n\t\n\tpublic static Result rank(int[][] M, int p)\n\t{\n//\t\tif(M.length == 0)return 0;\n\t\tint n = M.length, m = M[0].length;\n\t\tint[][] v = new int[n][n];\n\t\tfor(int i = 0;i < n;i++)v[i][i] = 1;\n\t\t\n\t\t// Forward Elimination\n\t\tfor(int i = 0;i < n;i++){\n\t\t\t// select pivot\n\t\t\tboolean pivotFound = false;\n\t\t\tout:\n\t\t\tfor(int pi = i;pi < n;pi++){\n\t\t\t\tfor(int pj = i;pj < m;pj++){\n\t\t\t\t\tif(M[pi][pj] != 0){\n\t\t\t\t\t\t// pivot found\n\t\t\t\t\t\tif(pj != i){\n\t\t\t\t\t\t\t// swap columns\n\t\t\t\t\t\t\tfor(int k = 0;k < n;k++){\n\t\t\t\t\t\t\t\tint d = M[k][pj]; M[k][pj] = M[k][i]; M[k][i] = d;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(pi != i){\n\t\t\t\t\t\t\t// swap rows\n\t\t\t\t\t\t\t{int[] d = M[pi]; M[pi] = M[i]; M[i] = d;}\n\t\t\t\t\t\t\t{int[] d = v[pi]; v[pi] = v[i]; v[i] = d;}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tpivotFound = true;\n\t\t\t\t\t\tbreak out;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(!pivotFound){\n\t\t\t\tResult res = new Result();\n\t\t\t\tres.v = v;\n\t\t\t\tres.rank = i;\n\t\t\t\treturn res;\n\t\t\t}\n\t\t\t\n\t\t\tlong ID = invl(M[i][i], p);\n\t\t\tM[i][i] = 1;\n\t\t\tfor(int j = i+1;j < m;j++){\n\t\t\t\tM[i][j] = (int)(M[i][j] * ID % p);\n\t\t\t}\n\t\t\tfor(int j = 0;j < n;j++){\n\t\t\t\tv[i][j] = (int)(v[i][j] * ID % p);\n\t\t\t}\n\t\t\t\n\t\t\tfor(int j = i+1;j < n;j++){\n\t\t\t\tlong B = p-M[j][i];\n\t\t\t\tM[j][i] = 0;\n\t\t\t\tfor(int k = i+1;k < m;k++){\n\t\t\t\t\tM[j][k] = (int)((M[j][k] + M[i][k] * B) % p);\n\t\t\t\t}\n\t\t\t\tfor(int k = 0;k < n;k++){\n\t\t\t\t\tv[j][k] = (int)((v[j][k] + v[i][k] * B) % p);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tResult res = new Result();\n\t\tres.v = v;\n\t\tres.rank = n;\n\t\treturn res;\n\t}\n\t\n\tpublic static int[] mul(int[][] A, int[] v, int mod)\n\t{\n\t\tint m = A.length;\n\t\tint n = v.length;\n\t\tint[] w = new int[m];\n\t\tfor(int i = 0;i < m;i++){\n\t\t\tlong sum = 0;\n\t\t\tfor(int k = 0;k < n;k++){\n\t\t\t\tsum += (long)A[i][k] * v[k];\n\t\t\t}\n\t\t\tsum %= mod;\n\t\t\tw[i] = (int)sum;\n\t\t}\n\t\treturn w;\n\t}\n\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\tstatic class Result\n\t{\n\t\tpublic int[][] v;\n\t\tpublic int rank;\n\t};\n\t\n\tpublic static Result operateElementarily(int[][] M, int mod)\n\t{\n\t\tint n = M.length, m = M[0].length;\n\t\tint rank = n-1;\n\t\tint[][] v = new int[n][n];\n\t\tfor(int i = 0;i < n;i++)v[i][i] = 1;\n\t\t\t\t\n\t\t// Forward Elimination\n\t\tfor(int i = 0;i < n;i++){\n\t\t\t// select pivot\n\t\t\tint maxj = -1;\n\t\t\tfor(int j = i;j < n;j++){\n\t\t\t\tif(M[j][i] != 0){\n\t\t\t\t\tmaxj = j;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(maxj == -1){\n\t\t\t\trank = i-1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif(maxj != i){\n\t\t\t\tint[] dum = M[i]; M[i] = M[maxj]; M[maxj] = dum;\n\t\t\t\tint[] du = v[i]; v[i] = v[maxj]; v[maxj] = du;\n\t\t\t}\n\t\t\t\n\t\t\tlong ID = invl(M[i][i], mod);\n\t\t\tM[i][i] = 1;\n\t\t\tfor(int j = i+1;j < m;j++){\n\t\t\t\tM[i][j] = (int)(M[i][j] * ID % mod);\n\t\t\t}\n\t\t\tfor(int j = 0;j < n;j++){\n\t\t\t\tv[i][j] = (int)(v[i][j] * ID % mod);\n\t\t\t}\n\t\t\t\n\t\t\tfor(int j = i+1;j < n;j++){\n\t\t\t\tlong B = mod-M[j][i];\n\t\t\t\tM[j][i] = 0;\n\t\t\t\tfor(int k = i+1;k < m;k++){\n\t\t\t\t\tM[j][k] = (int)((M[j][k] + M[i][k] * B) % mod);\n\t\t\t\t}\n\t\t\t\tfor(int k = 0;k < n;k++){\n\t\t\t\t\tv[j][k] = (int)((v[j][k] + v[i][k] * B) % mod);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\t// Back Substitution\n\t\tfor(int i = rank;i >= 0;i--){\n\t\t\tfor(int j = rank;j >= i+1;j--){\n\t\t\t\tlong B = mod-M[i][j];\n\t\t\t\tM[i][j] = 0;\n\t\t\t\tfor(int k = rank+1;k < m;k++){\n\t\t\t\t\tM[i][k] = (int)((M[i][k] + M[j][k] * B) % mod);\n\t\t\t\t}\n\t\t\t\tfor(int k = 0;k < n;k++){\n\t\t\t\t\tv[i][k] = (int)((v[i][k] + v[j][k] * B) % mod);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tResult ret = new Result();\n\t\tret.v = v;\n\t\tret.rank = rank+1;\n\t\treturn ret;\n\t}\n\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception { new E().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}", "src_uid": "5cb18864c88b7fdec4a85718df67333e"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class MainC {\n\tstatic final StdIn in = new StdIn();\n\tstatic final PrintWriter out = new PrintWriter(System.out);\n\tstatic final long INF=(long)1e18;\n\t\n\tpublic static void main(String[] args) {\n\t\tint x=in.nextInt(), k=in.nextInt(), n=in.nextInt(), q=in.nextInt(), masks=0;\n\t\tint[] id2mask = new int[1<<k], mask2id = new int[1<<k];\n\t\tArrays.fill(mask2id, -1);\n\t\tfor(int i=1; i<1<<k; ++i)\n\t\t\tif(Integer.bitCount(i)==x)\n\t\t\t\tid2mask[mask2id[i]=masks++]=i;\n\t\t//System.out.println(Arrays.toString(id2mask));\n\t\tlong[] c = in.readLongArray(k);\n\t\tTreeMap<Integer, Long> ps = new TreeMap<Integer, Long>();\n\t\tps.put(0, 0L);\n\t\tps.put(n-x, 0L);\n\t\tfor(int i=0; i<q; ++i)\n\t\t\tps.put(in.nextInt()-1, in.nextLong());\n\t\tlong[][] tmat = new long[masks][masks], dp = new long[2][masks];\n\t\tfor(int i=0; i<masks; ++i) {\n\t\t\tArrays.fill(tmat[i], INF);\n\t\t\tif(((id2mask[i]>>(k-1))&1)!=0)\n\t\t\t\ttmat[i][mask2id[(id2mask[i]<<1)^1^(1<<k)]]=c[k-1];\n\t\t\telse {\n\t\t\t\tfor(int j=0; j<k-1; ++j)\n\t\t\t\t\tif(((id2mask[i]>>j)&1)!=0)\n\t\t\t\t\t\ttmat[i][mask2id[((id2mask[i]^(1<<j))<<1)^1]]=c[j];\n\t\t\t\ttmat[i][mask2id[id2mask[i]<<1]]=0;\n\t\t\t}\n\t\t}\n\t\t//System.out.println(Arrays.deepToString(tmat));\n\t\tArrays.fill(dp[0], INF);\n\t\tdp[0][0]=0;\n\t\tint lastI=0;\n\t\tfor(Map.Entry<Integer, Long> entry : ps.entrySet()) {\n\t\t\tif(entry.getKey()>n-x)\n\t\t\t\tcontinue;\n\t\t\t//System.out.println(entry.getKey());\n\t\t\tif(entry.getKey()-lastI>k)\n\t\t\t\tdp[(entry.getKey()-k)&1]=matMult(matExp(tmat, entry.getKey()-lastI-k), dp[lastI&1]);\n\t\t\t//System.out.println(Math.max(entry.getKey()-k, lastI)+\" \"+Arrays.toString(dp[Math.max(entry.getKey()-k, lastI)&1]));\n\t\t\tfor(int a=Math.max(entry.getKey()-k, lastI)+1; a<=entry.getKey(); ++a) {\n\t\t\t\tfor(int i=0; i<masks; ++i) {\n\t\t\t\t\tif(((id2mask[i]>>(k-1))&1)!=0)\n\t\t\t\t\t\tdp[a&1][i]=dp[a&1^1][mask2id[(id2mask[i]<<1)^1^(1<<k)]]+c[k-1]+ps.getOrDefault(a+k-1, 0L);\n\t\t\t\t\telse {\n\t\t\t\t\t\tdp[a&1][i]=dp[a&1^1][mask2id[id2mask[i]<<1]];\n\t\t\t\t\t\tfor(int j=0; j<k-1; ++j)\n\t\t\t\t\t\t\tif(((id2mask[i]>>j)&1)!=0)\n\t\t\t\t\t\t\t\tdp[a&1][i]=Math.min(dp[a&1^1][mask2id[((id2mask[i]^(1<<j))<<1)^1]]+c[j]+ps.getOrDefault(a+j, 0L), dp[a&1][i]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t//System.out.println(a+\" \"+Arrays.toString(dp[a&1]));\n\t\t\t}\n\t\t\tlastI=entry.getKey();\n\t\t}\n\t\tout.println(dp[(n-x)&1][0]);\n\t\tout.close();\n\t}\n\t\n\tstatic long[][] matMult(long[][] x, long[][] y) {\n\t\tlong[][] z = new long[x.length][x.length];\n\t\tfor(int i=0; i<x.length; ++i) {\n\t\t\tArrays.fill(z[i], INF);\n\t\t\tfor(int j=0; j<x.length; ++j)\n\t\t\t\tfor(int k=0; k<x.length; ++k)\n\t\t\t\t\tz[i][j]=Math.min(x[i][k]+y[k][j], z[i][j]);\n\t\t}\n\t\treturn z;\n\t}\n\t\n\tstatic long[][] matExp(long[][] x, int p) {\n\t\tlong[][] res = new long[x.length][x.length], pow = x;\n\t\tfor(int i=0; i<x.length; ++i) {\n\t\t\tArrays.fill(res[i], INF);\n\t\t\tres[i][i]=0;\n\t\t}\n\t\twhile(p>0) {\n\t\t\tif(p%2==1)\n\t\t\t\tres=matMult(res, pow);\n\t\t\tpow=matMult(pow, pow);\n\t\t\tp/=2;\n\t\t}\n\t\treturn res;\n\t}\n\t\n\tstatic long[] matMult(long[][] x, long[] y) {\n\t\tlong[] z = new long[x.length];\n\t\tArrays.fill(z, INF);\n\t\tfor(int i=0; i<x.length; ++i)\n\t\t\tfor(int j=0; j<x.length; ++j)\n\t\t\t\tz[i]=Math.min(x[i][j]+y[j], z[i]);\n\t\treturn z;\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<n; ++i)\n\t\t\t\tar[i]=nextInt();\n\t\t\treturn ar;\n\t\t}\n\t\tpublic long nextLong() {\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\twhile ((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\t\tpublic long[] readLongArray(int n) {\n\t\t\tlong[] ar = new long[n];\n\t\t\tfor(int i=0; i<n; ++i)\n\t\t\t\tar[i]=nextLong();\n\t\t\treturn ar;\n\t\t}\n\t\tpublic double nextDouble() {\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\twhile ((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\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}", "src_uid": "e3dd409ceeba2a21890d35ceab9607eb"} {"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.util.TreeSet;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author BSRK Aditya\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 FMulticoloredMarkers solver = new FMulticoloredMarkers();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class FMulticoloredMarkers {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n long a = in.readLong(), b = in.readLong();\n\n //ArrayList<Long> aF = new ArrayList<>(), bF = new ArrayList<>();\n TreeSet<Long> aF = new TreeSet<>(), bF = new TreeSet<>();\n\n for (long i = 1; i * i <= a; ++i)\n if (a % i == 0) {\n aF.add(i);\n aF.add(a / i);\n }\n for (long i = 1; i * i <= b; ++i)\n if (b % i == 0) {\n bF.add(i);\n bF.add(b / i);\n }\n\n //Collections.sort(aF);\n //Collections.sort(bF);\n\n long ans = Long.MAX_VALUE;\n\n long sum = a + b;\n\n for (long s1 = 1; s1 * s1 <= sum; s1++) {\n if (sum % s1 == 0) {\n long s2 = sum / s1;\n //if (s1 + s2 == (199999999999948L/2L)) {\n // continue;\n //}\n\n Long factor = aF.floor(s1);\n if (factor != null && a / factor <= s2)\n ans = Long.min(ans, s1 + s2);\n\n factor = bF.floor(s1);\n if (factor != null && b / factor <= s2)\n ans = Long.min(ans, s1 + s2);\n\n /*int idx = Collections.binarySearch(aF, s1);\n if (idx < 0) idx = - idx - 1;\n if (idx >= 0 && idx < aF.size()) {\n if (a/aF.get(idx) <= s2) ans = Long.min(ans, s1 + s2);\n }\n\n idx = Collections.binarySearch(bF, s1);\n if (idx < 0) idx = - idx - 1;\n if (idx >= 0 && idx < bF.size()) {\n if (b/bF.get(idx) <= s2) ans = Long.min(ans, s1 + s2);\n }*/\n }\n }\n out.printLine(2 * 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 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 long readLong() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void print(Object... objects) {\n for (int i = 0; i < objects.length; i++) {\n if (i != 0)\n writer.print(' ');\n 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\n", "src_uid": "7d0c5f77bca792b6ab4fd4088fe18ff1"} {"source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\nimport java.awt.*;\npublic class EightSet\n{\n static final int INF = Integer.MAX_VALUE;\n static final int NINF = Integer.MIN_VALUE;\n \n public static void main(String[]args)throws IOException\n {\n Input in = new Input();\n HashSet<Point> hs = new HashSet<Point>();\n int [] xs = new int[8];\n int [] ys = new int[8];\n for(int i = 0; i < 8; i++)\n {\n xs[i] = in.nextInt();\n ys[i] = in.nextInt();\n hs.add(new Point(xs[i], ys[i]));\n }\n Arrays.sort(xs);\n Arrays.sort(ys);\n for(int i = 0; i < 8; i++)\n {\n for(int j = i+1; j < 8; j++)\n {\n for(int k = j+1; k < 8; k++)\n {\n if(xs[i] < xs[j] && xs[j] < xs[k])\n {\n for(int a = 0; a < 8; a++)\n {\n for(int b = a+1; b < 8; b++)\n {\n for(int c = b+1; c < 8; c++)\n {\n if(ys[a] < ys[b] && ys[b] < ys[c])\n {\n if(!hs.contains(new Point(xs[b], ys[b])))\n {\n if(hs.contains(new Point(xs[a], ys[b])) && hs.contains(new Point(xs[a], ys[c])) && hs.contains(new Point(xs[b], ys[a])) && hs.contains(new Point(xs[c], ys[a])) && hs.contains(new Point(xs[b], ys[c])) && hs.contains(new Point(xs[c], ys[b])))\n { \n System.out.println(\"respectable\");\n exit();\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n System.out.println(\"ugly\");\n \n }\n\n public static void exit()\n {\n System.exit(0);\n }\n}\n\nclass Input\n{\n BufferedReader br;\n StringTokenizer st;\n\n public Input()\n {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n public String nextLine()throws IOException\n {\n return br.readLine();\n }\n\n public int nextInt()throws IOException\n {\n return Integer.parseInt(next());\n }\n\n public long nextLong()throws IOException\n {\n return Long.parseLong(next());\n }\n\n public float nextFloat()throws IOException\n {\n return Float.parseFloat(next());\n }\n\n public double nextDouble()throws IOException\n {\n return Double.parseDouble(next());\n }\n\n public String next()throws IOException\n {\n if(st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n}\n", "src_uid": "f3c96123334534056f26b96f90886807"} {"source_code": "import java.util.*;\npublic class b {\n static int n;\n static char[][] data;\n static int[][] masks;\n static int[][] memo;\npublic static void main(String[] args)\n{\n Scanner input = new Scanner(System.in);\n n = input.nextInt();\n data = new char[n][n];\n for(int i = 0; i<n; i++) data[i] = input.next().toCharArray();\n if(n==1)\n {\n if(data[0][0] == 'a') System.out.println(\"FIRST\");\n else if(data[0][0] == 'b') System.out.println(\"SECOND\");\n else System.out.println(\"DRAW\");\n return;\n }\n memo = new int[2*n+2][1<<n];\n for(int[] A: memo) Arrays.fill(A, -1);\n \n masks = new int[2*n+2][26];\n for(int i = 0; i<2*n; i++) //diag - sum of x and y\n for(int j = 0; j<26; j++) //letter\n for(int k = 0; k<n; k++) //x coord\n {\n int r = k, c = i-k;\n if(c>=0 && c<n && data[r][c] == 'a'+j) masks[i][j] |= (1<<k);\n }\n int res = go(0, 1, data[0][0]-'a', false);\n if(res==0) System.out.println(\"DRAW\");\n else System.out.println(res < 0 ? \"FIRST\" : \"SECOND\");\n}\nstatic int go(int diag, int mask, int ch, boolean first)\n{\n if(diag == 2*(n-1))\n {\n if(first)\n {\n if(ch == 0) return 1;\n else if(ch == 1) return -1;\n return 0;\n }\n else\n {\n if(ch==0) return -1;\n else if(ch==1) return 1;\n return 0;\n }\n }\n if(memo[diag][mask] != -1) return memo[diag][mask];\n int res = -987654321;\n for(int i =0; i<26; i++)\n {\n int nmask = (mask | (mask << 1)) & (masks[diag+1][i]);\n if(nmask > 0) res = Math.max(res, -go(diag+1, nmask, i, !first));\n }\n if(first)\n {\n if(ch == 0) return memo[diag][mask] = 1+res;\n else if(ch == 1) return memo[diag][mask] = res-1;\n return memo[diag][mask] = res;\n }\n else\n {\n if(ch==0) return memo[diag][mask] = res-1;\n else if(ch==1) return memo[diag][mask] = res+1;\n return memo[diag][mask]=res;\n }\n}\n}\n", "src_uid": "d803fe167a96656f8debdc21edd988e4"} {"source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class Apples {\n\n\tpublic static Integer[] parse(String st) {\n\t\tString[] a = st.split(\" \");\n\t\tInteger[] ar = new Integer[a.length];\n\t\tfor (int i = 0; i < a.length; i++) \n\t\t\tar[i] = Integer.parseInt(a[i]);\n\t\treturn ar;\n\t}\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tInputStreamReader is = new InputStreamReader(System.in);\n\t\t\tBufferedReader br = new BufferedReader(is);\n\t\t\tInteger[] p = parse(br.readLine());\n\t\t\tint c = p[1];\n\t\t\tlong n = 0;\n\t\t\tlong tot = 0;\n\t\t\tArrayList<String> arg = new ArrayList<>();\n\t\t\tfor (int i = 0; i < p[0]; i++) arg.add(br.readLine());\n\t\t\tfor (int i = p[0] - 1; i >= 0; i--) {\n\t\t\t\tString s = arg.get(i);\n\t\t\t\tif (s.equals(\"half\")) {\n\t\t\t\t\tn *= 2;\n\t\t\t\t\tif (n == 0) n++;\n\t\t\t\t} else if (s.equals(\"halfplus\")) {\n\t\t\t\t\tn = n*2 + 1;\n\t\t\t\t\tif (n == 0) n++;\n\t\t\t\t}\n\t\t\t}\n\t\t\twhile (n > 0) {\n\t\t\t\ttot += (n / 2.0) * c;\n\t\t\t\tn /= 2;\n\t\t\t}\n\t\t\tSystem.out.println(tot);\n\t\t} catch (Exception e) {e.printStackTrace();}\n\t}\n\n}\n", "src_uid": "6330891dd05bb70241e2a052f5bf5a58"} {"source_code": "import java.util.*;\n\npublic class SquaresCubes {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int t = sc.nextInt();\n int n = 0;\n Set<Integer> s = new HashSet<>();\n while (t != 0) {\n n = sc.nextInt();\n s = new HashSet<>();\n for (int i = 1; i * i <= n; i++) {\n s.add(i * i);\n }\n for (int i = 1; i * i * i <= n; i++) {\n s.add(i * i * i);\n }\n System.out.println(s.size());\n t--;\n }\n }\n}\n", "src_uid": "015afbefe1514a0e18fcb9286c7b6624"} {"source_code": "import java.util.Scanner;\n\npublic class Integer_Sequence_Dividing {\n public static void main(String args[]) {\n Scanner reader = new Scanner(System.in);\n\n int n = reader.nextInt() % 4;\n\n reader.close();\n\n\n if (n == 1 || n == 2)\n System.out.print(1);\n else\n System.out.println(0);\n }\n\n}\n", "src_uid": "fa163c5b619d3892e33e1fb9c22043a9"} {"source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class task\n{\n\tpublic static void main(String[] Args)\n\t{\n\t\tScanner sc=new Scanner(System.in);\n\t\tint n=sc.nextInt(),m=sc.nextInt(),i;\n\t\tint cycle=(n+1)*n/2;\n\t\tm=m%cycle;\n\t\tfor (i=0;i!=50 && m>=i;++i)\n\t\t\tm-=i;\n\t\tSystem.out.println(m);\n\t}\n}", "src_uid": "5dd5ee90606d37cae5926eb8b8d250bb"} {"source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.BigInteger;\n\npublic class abc {\n public static void main(String args[] ) throws Exception {\n \n \t Scanner mak = new Scanner(System.in);\n \t int n = mak.nextInt();\n \t int arr[] = new int[n];\n \t for(int i = 0;i<n;i++){\n \t\t arr[i] = mak.nextInt();\n \t }\n \t int sum = 0,sum1 = 0;\n \t for(int i = arr.length - 1;i>=0;i--){\n \t\t sum+=arr[i];\n \t\t if(sum>sum1)\n \t\t {\n \t\t\t sum1 = sum+sum1;\n \t\t\t sum = sum1 - sum;\n \t\t\t sum1 -= sum; \n \t\t }\n \t \n \t }\n \t System.out.print(sum+\" \"+ sum1);\n }\n}\n", "src_uid": "414540223db9d4cfcec6a973179a0216"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class D {\n\n\tstatic final int P = 1_000_000_007;\n\n\tstatic final int N = 52;\n\t\n\tvoid submit() {\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\n\t\tint[][] f = new int[N + 1][N + 1];\n\n\t\tf[0][1] = 1;\n\n\t\tfor (int sz = 1; sz <= n; sz++) {\n\n\t\t\tint[][] dp = new int[sz + 1][N + 1];\n\t\t\tdp[0][1] = 1;\n\n\t\t\tint[][] cnt = new int[sz + 1][N + 1]; // [size][cut]\n\n\t\t\tfor (int szL = 0; szL + 1 <= sz; szL++) {\n\t\t\t\tfor (int cutL = 1; cutL <= N; cutL++) {\n\t\t\t\t\tfor (int szR = 0; szL + szR + 1 <= sz; szR++) {\n\t\t\t\t\t\tfor (int cutR = 1; cutR <= N; cutR++) {\n\n\t\t\t\t\t\t\tint szLR = szL + szR + 1;\n\t\t\t\t\t\t\tint cutLR = Math.min(cutL, cutR);\n\n\t\t\t\t\t\t\tcnt[szLR][cutLR] += (int) ((long) f[szL][cutL]\n\t\t\t\t\t\t\t\t\t* f[szR][cutR] % P);\n\t\t\t\t\t\t\tif (cnt[szLR][cutLR] >= P) {\n\t\t\t\t\t\t\t\tcnt[szLR][cutLR] -= 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\n\n\t\t\tfor (int addSz = 1; addSz <= sz; addSz++) {\n\t\t\t\tfor (int addCut = 1; addCut <= N; addCut++) {\n\t\t\t\t\t\n\t\t\t\t\tif (cnt[addSz][addCut] == 0) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tint[][] nextDp = new int[sz + 1][];\n\t\t\t\t\tfor (int i = 0; i <= sz; i++) {\n\t\t\t\t\t\tnextDp[i] = dp[i].clone();\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tint smth = sz / addSz;\n\t\t\t\t\t\n\t\t\t\t\tint[] arrWays = new int[smth + 1];\n\t\t\t\t\tint base = cnt[addSz][addCut];\n\t\t\t\t\t\n\t\t\t\t\tarrWays[0] = 1;\n\t\t\t\t\t\n\t\t\t\t\tfor (int i = 1; i <= smth; i++) {\n\t\t\t\t\t\tarrWays[i] = (int)((long)arrWays[i - 1] * inv[i] % P * base % P);\n\t\t\t\t\t\tbase++;\n\t\t\t\t\t\tif (base == P) {\n\t\t\t\t\t\t\tbase = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tfor (int cntAdd = 1; cntAdd <= smth; cntAdd++) {\n\n\t\t\t\t\t\tint ways = arrWays[cntAdd];\n\n\t\t\t\t\t\tfor (int i = sz - addSz * cntAdd; i >= 0; i--) {\n\t\t\t\t\t\t\tfor (int j = N - addCut * cntAdd; j >= 1; j--) {\n\n\t\t\t\t\t\t\t\tif (i + addSz * cntAdd <= sz\n\t\t\t\t\t\t\t\t\t\t&& j + addCut * cntAdd <= N) {\n\n\t\t\t\t\t\t\t\t\tnextDp[i + addSz * cntAdd][j + addCut * cntAdd] += (int) ((long) dp[i][j]\n\t\t\t\t\t\t\t\t\t\t\t* ways % P);\n\t\t\t\t\t\t\t\t\tif (nextDp[i + addSz * cntAdd][j + addCut\n\t\t\t\t\t\t\t\t\t\t\t* cntAdd] >= P) {\n\t\t\t\t\t\t\t\t\t\tnextDp[i + addSz * cntAdd][j + addCut\n\t\t\t\t\t\t\t\t\t\t\t\t* cntAdd] -= P;\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tdp = nextDp;\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (int j = 1; j <= N; j++) {\n\t\t\t\tf[sz][j] = dp[sz][j];\n\t\t\t}\n\n\t\t}\n\n//\t\tfor (int i = 0; i <= n; i++) {\n//\t\t\tfor (int j = 1; j <= N; j++) {\n//\t\t\t\tif (f[i][j] != 0) {\n//\t\t\t\t\tSystem.err.println(i + \" \" + j + \" -> \" + f[i][j]);\n//\t\t\t\t}\n//\t\t\t}\n//\t\t\t\n//\t\t\tSystem.err.println();\n//\t\t}\n\t\t\n\t\tout.println(f[n][m]);\n\n\t}\n\n\tint[] inv = new int[1000];\n\t{\n\t\tinv[0] = 0;\n\t\tinv[1] = 1;\n\t\tfor (int i = 2; i < inv.length; i++) {\n\t\t\tinv[i] = P - (int) ((long) (P / i) * inv[P % i] % P);\n\t\t}\n\t}\n\t\n\tvoid preCalc() {\n\n\t}\n\n\tvoid stress() {\n\n\t}\n\n\tvoid test() {\n\n\t}\n\n\tD() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tpreCalc();\n\t\tsubmit();\n\t\t// stress();\n\t\t// test();\n\t\tout.close();\n\t}\n\n\tstatic final Random rng = new Random();\n\n\tstatic int rand(int l, int r) {\n\t\treturn l + rng.nextInt(r - l + 1);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew D();\n\t}\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t}\n\n\tint nextInt() {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}\n", "src_uid": "aca6148effff8b893c961b1ee465e4e4"} {"source_code": "/* reshenie na zadachata \"Avtobuska stanica\" */\n\nimport java.util.Scanner;\n\npublic class Reshenie1 {\n\tpublic static void main(String[] args){\n\t\tScanner sc = new Scanner(System.in);\n\t\t\n\t\tint N = sc.nextInt();\n\t\tint M = sc.nextInt();\n\t\tint avtobusi = 0;\n\t\tint popolnetost = 0;\n\t\tfor(int i = 0; i < N; i++){\n\t\t\tint grupa = sc.nextInt();\n\t\t\tif(popolnetost + grupa <= M){\n\t\t\t\t//ima mesto za grupata vo segasniot avtobus\n\t\t\t\tpopolnetost += grupa;\n\t\t\t}\n\t\t\telse{\n\t\t\t\t//nema mesto za grupata, mora da cekaat nov avtobus\n\t\t\t\tavtobusi++;\n\t\t\t\tpopolnetost = grupa;\t//koga ke vlezat vo noviot avtobus, popolnetosta ke bide samo taa grupa\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(avtobusi + 1);\t// plus 1 bidejki segasniot ne e dodaden vo avtobusi\n\t}\n}\n", "src_uid": "5c73d6e3770dff034d210cdd572ccf0f"} {"source_code": "\nimport java.util.*;\nimport java.io.*;\npublic class TestClass {\n\t\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\tstatic int a[][];\n\tstatic int x,y;\n\tstatic int dirx[] = {0,1,1,1,0,-1,-1,-1};\n\tstatic int diry[] = {1,1,0,-1,-1,-1,0,1};\n\tstatic int b[];\n\tstatic boolean dp[][][][];\n\tpublic static void main(String args[] ) throws Exception {\n \n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n int n = Integer.parseInt(in.readLine());\n String s[] = in.readLine().split(\" \");\n b = new int[n];\n for(int i=0;i<n;i++)\n {\n \tb[i] = Integer.parseInt(s[i]);\n }\n int m = 320;\n a = new int[m][m];\n dp = new boolean[320][320][8][30];\n int mid = m/2;\n x = mid;y=mid;\n fun(x,y,0,0);\n int ans=0;\n for(int i=0;i<m;i++)\n {\n \tfor(int j=0;j<m;j++)\n \t{\n \t\tif(a[i][j]==1)\n \t\t{\n \t\t\tans++;\n \t\t}\n \t}\n }\n out.println(ans);\n out.close();\n }\n\t\n\tpublic static void fun(int x,int y,int i,int dir)\n\t{\n\t\tif(i==b.length)\n\t\t{\n\t\t\treturn;\n\t\t}\n\t\tif(dp[x][y][dir][i] == true)\n\t\t{\n\t\t\treturn;\n\t\t}\n\t\tdp[x][y][dir][i] = true;\n\t\tfor(int j=0;j<b[i];j++)\n\t\t{\n\t\t\tx += dirx[dir];\n\t\t\ty += diry[dir];\n\t\t\ta[x][y] = 1;\n\t\t}\n\t\tfun(x,y,i+1,(dir+1)%8);\n\t\tfun(x,y,i+1,(dir+7)%8);\n\t\t\n\t}\n \n \n}\n\n\n", "src_uid": "a96bc7f93fe9d9d4b78018b49bbc68d9"} {"source_code": "import java.util.*;\n\npublic class FoxNumberGame {\n\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n = scan.nextInt();\n\t\tint[] arr = new int[n];\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tarr[i] = scan.nextInt();\n\t\t}\n\t\tint gcd = arr[0];\n\t\tfor(int i = 1; i < n; i++){\n\t\t\tgcd = gcd(gcd, arr[i]);\n\t\t}\n\t\tSystem.out.println(gcd*n);\n\t}\n\t\n\tstatic int gcd(int p, int q) {\n if (q == 0) return p;\n else return gcd(q, p % q);\n }\n}\n", "src_uid": "042cf938dc4a0f46ff33d47b97dc6ad4"} {"source_code": "import java.util.Scanner;\npublic class Solution5 {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tSolution5 tr = new Solution5();\n\t\ttr.test(sc);\n\t\tsc.close();\n\t}\n\tvoid test(Scanner sc){\n\t\tint A = sc.nextInt();\n\t\tint B = sc.nextInt();\n\t\tint X = sc.nextInt();\n\t\tint more = A>=B?A:B;\n\t\tchar MORE = A>=B?'0':'1';\n\t\tint less = A+B-more;\n\t\tchar LESS = MORE=='0'?'1':'0';\n\t\tchar[] out = new char[A+B];\n\t\t\n\t\tint i = 0;\n\t\tint x=0;\n\t\tint m=0;\n\t\tint l=0;\n\t\tif(X==1){\n\t\t\tfor ( i = 0; i < more; i=i+1) {\n\t\t\t\tout[i]=MORE;\n\t\t\t}\n\t\t\tfor ( ; i < more+less; i=i+1) {\n\t\t\t\tout[i]=LESS;\n\t\t\t}\n\t\t\tfor ( int ii = 0; ii < A+B; ii=ii+1) {\n\t\t\t\tSystem.out.print(out[ii]+\"\");\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tif(X==2){\n\t\t\tout[i++]=MORE;\n\t\t\twhile(l<less&& i < A+B){\n\t\t\t\tout[i++] = LESS;\n\t\t\t\tl++;\n\t\t\t}\n\t\t\twhile(m<more&& i < A+B){\n\t\t\t\tout[i++] = MORE;\n\t\t\t\tm++;\n\t\t\t}\n\t\t\t\n\t\t\tfor ( int ii = 0; ii < A+B; ii=ii+1) {\n\t\t\t\tSystem.out.print(out[ii]+\"\");\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\t\n\n\t\tfor ( i = 0; x < X-2; i=i+2) {\n\t\t\tout[i]=MORE;m++;\n\t\t\tout[i+1]=LESS;l++;\n\t\t\tx= (i== 0?x+1:x+2);\n\t\t}\n\t//\tint rem= A+B-i-2;\n\t\tint last = out[i-1];\n\t\tif(x==X-1){\n\t\t\t// repeat last one and then other\n\t\t\tif(last==MORE){\n\t\t\t\twhile(m<more && i < A+B){\n\t\t\t\t\tout[i++] = MORE;\n\t\t\t\t\tm++;\n\t\t\t\t}\n\t\t\t\twhile(l<less&& i < A+B){\n\t\t\t\t\tout[i++] = LESS;\n\t\t\t\t\tl++;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse{\n\n\t\t\t\twhile(l<less&& i < A+B){\n\t\t\t\t\tout[i++] = LESS;\n\t\t\t\t\tl++;\n\t\t\t\t}\n\t\t\t\twhile(m<more&& i < A+B){\n\t\t\t\t\tout[i++] = MORE;\n\t\t\t\t\tm++;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t}else{\n\t\t\t// repeat other one and then last\n\t\t\tif(last==MORE){\n\t\t\t\twhile(l<less&& i < A+B){\n\t\t\t\t\tout[i++] = LESS;\n\t\t\t\t\tl++;\n\t\t\t\t}\n\t\t\t\twhile(m<more&& i < A+B){\n\t\t\t\t\tout[i++] = MORE;\n\t\t\t\t\tm++;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse{\n\t\t\t\twhile(m<more&& i < A+B){\n\t\t\t\t\tout[i++] = MORE;\n\t\t\t\t\tm++;\n\t\t\t\t}\n\t\t\t\twhile(l<less&& i < A+B){\n\t\t\t\t\tout[i++] = LESS;\n\t\t\t\t\tl++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n/*\t\tfor (int r=0; r < rem; r++) {\n\t\t\tout[i]=more;\n\t\t\ti++;\n\t\t}*/\n\t\t\n\t\tfor ( i = 0; i < A+B; i=i+1) {\n\t\t\tSystem.out.print(out[i]+\"\");\n\t\t}\n\n\t}\n}\n", "src_uid": "ef4123b8f3f3b511fde8b79ea9a6b20c"} {"source_code": "import java.io.BufferedInputStream;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.Queue;\nimport java.util.Scanner;\n\n\n\n\npublic class Main {\n \n \n \n void run(){\n Scanner cin=new Scanner(new BufferedInputStream(System.in));\n while( cin.hasNext() ){\n int a=cin.nextInt();\n int n=cin.nextInt();\n int b=a+n;\n int[] np=new int[11000000];\n for(int i=2;i*i<=b;i++){\n if( np[i]!=0 ) continue;\n for(int j=i*i;j<b;j+=i){\n np[j]=i;\n }\n }\n long ans=0;\n for(int i=1;i<b;i++){\n if( np[i]==0 ){\n np[i]=i;\n }else{\n int fac=np[i], num=0, tmp=i;\n while( tmp%fac==0 ){\n tmp/=fac;\n num++;\n }\n np[i]=np[tmp];\n if( num%2==1 ) np[i]*=fac;\n }\n if( i>=a ) ans+=np[i];\n }\n System.out.println(ans);\n }\n }\n public static void main(String[] args){\n Main a=new Main();\n a.run();\n }\n}\n", "src_uid": "915081861e391958dce6ee2a117abd4e"} {"source_code": "import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class RequiredLength {\r\n\tpublic static void solve(FastIO io) {\r\n\t\tfinal int N = io.nextInt();\r\n\t\tfinal long X = io.nextLong();\r\n\r\n\t\tlong target = 1;\r\n\t\tfor (int i = 1; i < N; ++i) {\r\n\t\t\ttarget *= 10;\r\n\t\t}\r\n\r\n\t\tHashSet<LongKey> layer = new HashSet<>();\r\n\t\tlayer.add(LongKey.of(X));\r\n\t\tfor (int i = 0; i < 64; ++i) {\r\n\t\t\tHashSet<LongKey> next = new HashSet<>(layer.size());\r\n\t\t\tfor (LongKey k : layer) {\r\n\t\t\t\tlong val = k.value;\r\n\t\t\t\tif (val >= target) {\r\n\t\t\t\t\tio.println(i);\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t\tlong num = val;\r\n\t\t\t\twhile (num > 0) {\r\n\t\t\t\t\tlong d = num % 10;\r\n\t\t\t\t\tnext.add(LongKey.of(val * d));\r\n\t\t\t\t\tnum /= 10;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tlayer = next;\r\n\t\t}\r\n\t\tio.println(-1);\r\n\t}\r\n\r\n\tpublic static class LongKey {\r\n\t\tpublic long value;\r\n\r\n\t\tprivate LongKey(long value) {\r\n\t\t\tthis.value = value;\r\n\t\t}\r\n\r\n\t\t@Override\r\n\t\tpublic int hashCode() {\r\n\t\t\treturn Long.hashCode(splitmix64(value + ADD_MIX));\r\n\t\t}\r\n\r\n\t\t@Override\r\n\t\tpublic boolean equals(Object obj) {\r\n\t\t\tLongKey other = (LongKey) obj;\r\n\t\t\treturn value == other.value;\r\n\t\t}\r\n\r\n\t\t@Override\r\n\t\tpublic String toString() {\r\n\t\t\treturn Long.toString(value);\r\n\t\t}\r\n\r\n\t\tprivate static final long splitmix64(long x) {\r\n\t\t\tlong z = x + 0x9E3779B97F4A7C15L;\r\n\t\t\tz = (z ^ (z >>> 30)) * 0xBF58476D1CE4E5B9L;\r\n\t\t\tz = (z ^ (z >>> 27)) * 0x94D049BB133111EBL;\r\n\t\t\treturn z ^ (z >>> 31);\r\n\t\t}\r\n\r\n\t\tpublic static LongKey of(long value) {\r\n\t\t\tif (CACHE_MIN <= value && value < CACHE_MAX) {\r\n\t\t\t\treturn CACHE[(int) (value - CACHE_MIN)];\r\n\t\t\t}\r\n\t\t\treturn new LongKey(value);\r\n\t\t}\r\n\r\n\t\tprivate static final long ADD_MIX = splitmix64(System.nanoTime());\r\n\r\n\t\tprivate static final int CACHE_MIN = -256;\r\n\t\tprivate static final int CACHE_MAX = 256;\r\n\t\tprivate static final LongKey[] CACHE = new LongKey[CACHE_MAX - CACHE_MIN];\r\n\t\tstatic {\r\n\t\t\tfor (int i = CACHE_MIN; i < CACHE_MAX; ++i) {\r\n\t\t\t\tCACHE[i - CACHE_MIN] = new LongKey(i);\r\n\t\t\t}\r\n\t\t}\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}", "src_uid": "cedcc3cee864bf8684148df93804d029"} {"source_code": "import java.util.*;\npublic class Main {\npublic static void main(String [] args){\n\tScanner in=new Scanner(System.in);\n\tint v1=in.nextInt();\n\tint v2=in.nextInt();\n\tint t=in.nextInt();\n\tint d=in.nextInt();\n\tif(d==0){\n\tSystem.out.println(v1*t);\n\treturn;\n\t}\n\tif(v1 > v2){\n\tint temp=v1;\n\tv1=v2;\n\tv2=temp;\n\t}\n\tlong ans=v1;\n\tint curv=v1;\n\tint time=-1;\n\tfor(int i=2;i<=t;i++){\n\t\tcurv+=d;\n\t\tif(Math.abs(curv-v2)*1.0/d > t-i){\n\t\ttime=i;\n\t\tcurv=(t-i)*d + v2;\n\t\tans+=curv;\n\t\t//System.out.println(ans+\" \"+curv);\n\t\tbreak;\n\t\t}\n\t\tans+=curv;\n\t\t//System.out.println(ans+\" \"+curv);\n\t}\n\t//System.out.println(time);\n\tif(time!=-1){\n\tfor(int i=time+1;i<=t;i++){\n\tcurv-=d;\n\tans+=curv;\n\t}\n\t}\n\tSystem.out.print(ans);\n\t}\n\t\n}", "src_uid": "9246aa2f506fcbcb47ad24793d09f2cf"} {"source_code": "import java.util.Scanner;\n\npublic class CF209B {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n long A = in.nextLong();\n long B = in.nextLong();\n long C = in.nextLong();\n\n long ans = Math.max(A,Math.max(B,C));\n if(A%2 == B%2) ans = Math.min(ans, Math.max(A,B));\n if(A%2 == C%2) ans = Math.min(ans, Math.max(A,C));\n if(B%2 == C%2) ans = Math.min(ans, Math.max(B,C));\n\n System.out.println(ans);\n }\n}\n", "src_uid": "b8008caf788336775cb8ebb76478b04c"} {"source_code": "import java.util.Scanner;\n\npublic class Time {\n\n public static void main(String[] args) {\n \n Scanner sc=new Scanner(System.in);\n int count=0;\n String out=\"NO\";\n int h=sc.nextInt(); \nint m=sc.nextInt(); \nint s=sc.nextInt();\nint t1=sc.nextInt();\nint t2=sc.nextInt();\n if(t1>t2){\n int temp=t1;\n t1=t2;\n t2=temp;\n }\n if(t1<=h && h<t2) count++;\n if(t1<=(double)m/5 && (double)m/5<t2) count++;\n if(t1<(double)s/5 && (double)s/5<t2) count++;\n \n if(count==0 || count==3)\n out=\"YES\";\n System.out.println(out);\n }\n}", "src_uid": "912c8f557a976bdedda728ba9f916c95"} {"source_code": "import java.io.*;\nimport java.util.Arrays;\n\npublic class Main {\n private static final int c = (int) (2e5 + 10), mod = (int) (1e9 + 7);\n static int n, q;\n static long[] a = new long[c];\n static long[] w = new long[c];\n static long[][] tre = new long[c][2];\n\n static void update(int i, long x, int j) {\n while (i <= n) {\n tre[i][j] += x;\n if (j == 1) tre[i][j] %= mod;\n i += i & -i;\n }\n }\n\n static long query(int i, int j) {\n long s = 0;\n while (i > 0) {\n s += tre[i][j];\n if (j == 1) s %= mod;\n i -= i & -i;\n }\n return s;\n }\n\n public static void main(String[] args) {\n IO io = new IO();\n n = io.nextInt();\n q = io.nextInt();\n for (int i = 0; i < n; i++) a[i] = io.nextLong();\n for (int i = 0; i < n; i++) {\n update(i + 1, w[i] = io.nextLong(), 0);\n update(i + 1, w[i] * (a[i] - i), 1);\n }\n while (q-- > 0) {\n int x = io.nextInt(), y = io.nextInt();\n if (x < 0) {\n x = -x - 1;\n update(x + 1, y - w[x], 0);\n update(x + 1, (y - w[x]) * (a[x] - x), 1);\n w[x] = y;\n } else {\n long s = query(y, 0) + query(x - 1, 0), c = 0;\n int mid = 0;\n for (int i = 17; i >= 0; i--)\n if (mid + (1 << i) < n && (c + tre[mid + (1 << i)][0]) * 2 < s) {\n mid += 1 << i;\n c += tre[mid][0];\n }\n long a1 = query(y, 1) - 2 * query(mid, 1) + query(x-1, 1);\n long a2 = query(y, 0) - 2 * query(mid, 0) + query(x-1, 0);\n long ans = a1 % mod - a2 % mod * (a[mid] - mid) % mod + 2 * mod;\n io.println(ans % mod );\n\n }\n }\n }\n\n static class IO {\n\n BufferedInputStream din;\n final int BUFFER_SIZE = 1 << 16;\n byte[] buffer;\n int byteRead, bufferPoint;\n\n StringBuilder builder;\n PrintWriter pw;\n\n public IO() {\n din = new BufferedInputStream(System.in);\n buffer = new byte[BUFFER_SIZE];\n bufferPoint = byteRead = 0;\n\n builder = new StringBuilder();\n pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(\n System.out\n )), true);\n }\n\n int read() {\n if (bufferPoint >= byteRead) {\n try {\n byteRead = din.read(buffer, bufferPoint = 0, BUFFER_SIZE);\n } catch (IOException e) {\n e.printStackTrace();\n }\n if (byteRead == -1) buffer[0] = -1;\n }\n return buffer[bufferPoint++];\n }\n\n int peek() {\n if (byteRead == -1) return -1;\n if (bufferPoint >= byteRead) {\n try {\n byteRead = din.read(buffer, bufferPoint = 0, BUFFER_SIZE);\n } catch (IOException e) {\n return -1;\n }\n if (byteRead <= 0) return -1;\n }\n return buffer[bufferPoint];\n }\n\n boolean hasNext() {\n int c = peek();\n while (c != -1 && c <= ' ') {\n read();\n c = peek();\n }\n return c != -1;\n }\n\n char nextChar() {\n int c = read();\n while (c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1) {\n c = read();\n }\n return (char) c;\n }\n\n double nextDouble() {\n double ret = 0, div = 1;\n int 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 (c == '.') {\n while ((c = read()) >= '0' && c <= '9') {\n ret += (c - '0') / (div *= 10);\n }\n }\n if (neg)\n return -ret;\n return ret;\n }\n\n String nextLine() {\n byte[] strBuf = new byte[64];\n int cnt = 0, c;\n while ((c = read()) != -1) {\n if (c == '\\n') {\n if (cnt == 0) {\n continue;\n } else {\n break;\n }\n }\n if (strBuf.length == cnt) {\n strBuf = Arrays.copyOf(strBuf, strBuf.length * 2);\n }\n strBuf[cnt++] = (byte) c;\n }\n return new String(strBuf, 0, cnt);\n }\n\n\n String next() {\n byte[] strBuf = new byte[64];\n int cnt = 0, c;\n while ((c = read()) != -1) {\n if (Character.isWhitespace(c)) {\n if (cnt == 0) {\n continue;\n } else {\n break;\n }\n }\n if (strBuf.length == cnt) {\n strBuf = Arrays.copyOf(strBuf, strBuf.length * 2);\n }\n strBuf[cnt++] = (byte) c;\n }\n return new String(strBuf, 0, cnt);\n }\n\n int nextInt() {\n int ans = 0;\n int c = read();\n while (c <= ' ') c = read();\n boolean neg = (c == '-');\n if (neg) c = read();\n do {\n ans = ans * 10 + c - '0';\n } while ('0' <= (c = read()) && c <= '9');\n bufferPoint--;\n return neg ? -ans : ans;\n }\n\n long nextLong() {\n long ans = 0;\n int c = read();\n while (c <= ' ') c = read();\n boolean neg = (c == '-');\n if (neg) c = read();\n do {\n ans = ans * 10 + c - '0';\n } while ('0' <= (c = read()) && c <= '9');\n bufferPoint--;\n return neg ? -ans : ans;\n }\n\n void println(Object o) {\n pw.println(o);\n }\n\n void print(Object o) {\n pw.print(o);\n }\n\n void printf(String format, Object... objects) {\n pw.printf(format, objects);\n }\n\n void close() {\n pw.close();\n }\n\n void done(Object o) {\n print(o);\n close();\n }\n\n }\n\n}\n", "src_uid": "c0715f71efa327070eba7e491856d66a"} {"source_code": "//package codeforcesa3;\nimport java.util.*;\npublic class DimaAndFriends {\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 int sum=0;\n for(int i=0;i<n;i++)\n {\n a[i]=in.nextInt();\n sum+=a[i];\n }\n int curr=sum % (n+1);\n int count=0;\n for(int i=1;i<=5;i++)\n {\n if((curr+i)%(n+1)==1){\n continue;\n }else{\n count++;\n }\n }\n System.out.println(count);\n }\n}\n", "src_uid": "ff6b3fd358c758324c19a26283ab96a4"} {"source_code": "import java.util.Scanner;\n\n/**\n * Created by shalin on 3/7/17.\n */\npublic class Problem817A {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int x1 = in.nextInt();\n int y1 = in.nextInt();\n int x2 = in.nextInt();\n int y2 = in.nextInt();\n int x = in.nextInt();\n int y = in.nextInt();\n\n int xd = Math.abs(x1 - x2), yd = Math.abs(y1 - y2);\n boolean canReach = xd % x == 0 && yd % y == 0 && Math.abs(xd / x - yd / y) % 2 == 0;\n System.out.println(canReach ? \"YES\" : \"NO\");\n }\n}\n", "src_uid": "1c80040104e06c9f24abfcfe654a851f"} {"source_code": "import java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class CF1384E extends PrintWriter {\n\t// https://codeforces.com/contest/1384/problem/E\n\tpublic Scanner sc = new Scanner(System.in);\n\n\tpublic CF1384E() {\n\t\tsuper(System.out);\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tCF1384E o = new CF1384E();\n\t\to.main();\n\t\to.flush();\n\t}\n\n\tpublic static final int SZ = 20;\n\tpublic int[] ds = new int[SZ];\n\n\tpublic void main() {\n\t\tint t = sc.nextInt();\n\t\twhile (t-- > 0) {\n\t\t\tint n = sc.nextInt();\n\t\t\tbyte[] sa = sc.next().getBytes();\n\t\t\tbyte[] sb = sc.next().getBytes();\n\t\t\tfor (int id = 0; id < SZ; id++) {\n\t\t\t\tds[id] = id;\n\t\t\t}\n\t\t\tint[] es = new int[SZ];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (sa[i] != sb[i]) {\n\t\t\t\t\tint u = sa[i] - 'a';\n\t\t\t\t\tint v = sb[i] - 'a';\n\t\t\t\t\tjoin(u, v);\n\t\t\t\t\tes[u] |= (1 << v);\n\t\t\t\t}\n\t\t\t}\n\t\t\tint ans = SZ * 2;\n\t\t\tfor (int id = 0; id < SZ; id++) {\n\t\t\t\tif (ds[id] == id) {\n\t\t\t\t\tans = ans - 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tboolean[] dags = new boolean[1 << SZ];\n\t\t\tdags[0] = true;\n\t\t\tint cnt_ = 0;\n\t\t\tfor (int state = 1; state < (1 << SZ); state++) {\n\t\t\t\tint cnt = 0;\n\t\t\t\tfor (int tmp = state; tmp > 0; tmp &= (tmp - 1)) {\n\t\t\t\t\tcnt++;\n\t\t\t\t}\n\t\t\t\tfor (int id = 0; id < SZ; id++) {\n\t\t\t\t\tif ((state & (1 << id)) > 0) {\n\t\t\t\t\t\tint a = state ^ (1 << id);\n\t\t\t\t\t\t// chu y thu tu duyet cua cac bai toan\n\t\t\t\t\t\tif (dags[a]) {\n\t\t\t\t\t\t\tif ((a & es[id]) == 0) {\n\t\t\t\t\t\t\t\tdags[state] = true;\n\t\t\t\t\t\t\t\tcnt_ = Math.max(cnt_, cnt);\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}\n\t\t\t}\n\t\t\tans -= cnt_;\n\t\t\tprintln(ans);\n\t\t}\n\t}\n\n\tprivate void join(int u, int v) {\n\t\tu = find(u);\n\t\tv = find(v);\n\t\tif (u != v) {\n\t\t\tds[u] = v;\n\t\t}\n\n\t}\n\n\tprivate int find(int u) {\n\t\tif (ds[u] == u) {\n\t\t\treturn u;\n\t\t}\n\t\tds[u] = find(ds[u]);\n\t\treturn ds[u];\n\t}\n}\n", "src_uid": "d0735a763e2a40bfc94085019cd646f0"} {"source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\n\npublic class _194A {\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 sum = 3 * a - b;\n System.out.println(sum < 0 ? 0 : sum);\n }\n}\n", "src_uid": "5a5e46042c3f18529a03cb5c868df7e8"} {"source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Collection;\nimport java.util.InputMismatchException;\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 *\n * @author beginner1010\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 TaskE solver = new TaskE();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskE {\n Deque<Integer>[] deq;\n Deque<Integer> rowDeq;\n\n void insert(Integer c, int value) {\n Deque<Integer> curDeq = c == -1 ? rowDeq : deq[c];\n while (curDeq.isEmpty() == false && curDeq.getLast() > value) {\n curDeq.removeLast();\n }\n curDeq.addLast(value);\n }\n\n void delete(Integer c, int value) {\n Deque<Integer> curDeq = c == -1 ? rowDeq : deq[c];\n if (curDeq.isEmpty() == false && curDeq.getFirst() == value) {\n curDeq.removeFirst();\n }\n }\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int m = in.nextInt();\n int a = in.nextInt();\n int b = in.nextInt();\n long g0 = in.nextLong();\n long x = in.nextLong();\n long y = in.nextLong();\n long z = in.nextLong();\n\n int[][] table = new int[n][m];\n long g = g0;\n for (int r = 0; r < n; r++) {\n for (int c = 0; c < m; c++) {\n table[r][c] = (int) g;\n g = (g * x + y) % z;\n }\n }\n\n deq = new Deque[m];\n for (int c = 0; c < m; c++) {\n deq[c] = new ArrayDeque<>();\n }\n\n for (int c = 0; c < m; c++) {\n for (int r = 0; r < a; r++) {\n insert(c, table[r][c]);\n }\n }\n long ans = 0;\n for (int r = 0; r < n - a + 1; r++) {\n rowDeq = new ArrayDeque<>();\n for (int c = 0; c < b; c++) {\n insert(-1, deq[c].getFirst());\n }\n ans += rowDeq.getFirst();\n for (int c = b; c < m; c++) {\n delete(-1, deq[c - b].getFirst());\n insert(-1, deq[c].getFirst());\n ans += rowDeq.getFirst();\n }\n if (r + a < n) {\n for (int c = 0; c < m; c++) {\n insert(c, table[r + a][c]);\n delete(c, table[r][c]);\n }\n }\n }\n out.println(ans);\n }\n\n }\n\n static class InputReader {\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputStream stream;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n private boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\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 nextInt() {\n int c = read();\n while (isWhitespace(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 (!isWhitespace(c));\n return res * sgn;\n }\n\n public long nextLong() {\n int c = read();\n while (isWhitespace(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 (!isWhitespace(c));\n return res * sgn;\n }\n\n }\n}\n\n", "src_uid": "4618fbffb2b9d321a6d22c11590a4773"} {"source_code": "/*\n * To change this license header, choose License Headers in Project Properties.\n * To change this template file, choose Tools | Templates\n * and open the template in the editor.\n */\n\n/**\n *\n * @author dipankar12\n */\nimport java.io.*;\nimport java.util.*;\npublic class r187b {\n public static void main(String args[])\n {\n fastio in=new fastio(System.in);\n PrintWriter pw=new PrintWriter(System.out);\n\n int b=in.nextInt();\n int d=in.nextInt();\n String a=in.readString();\n String c=in.readString();\n int n=a.length();\n int m=c.length();\n \n int matches[]=new int[m];\n for(int i=0;i<m;i++)\n for(int j=0;j<n;j++)\n {\n int look=(i+matches[i])%m;\n if(a.charAt(j)==c.charAt(look))\n matches[i]++;\n }\n \n //pw.println(\"matches\");\n //for(int i=0;i<m;i++)\n //pw.print(matches[i]+\" \");\n //pw.println();\n \n int res=0;\n for(int i=0;i<b;i++)\n res+=matches[res%m];\n \n res/=m*d;\n \n pw.println(res);\n pw.close();\n }\n\n static class fastio {\n \n private final InputStream stream;\n private final byte[] buf = new byte[8192];\n private int cchar, snchar;\n private SpaceCharFilter filter;\n \n public fastio(InputStream stream) {\n this.stream = stream;\n }\n \n public int nxt() {\n if (snchar == -1)\n throw new InputMismatchException();\n if (cchar >= snchar) {\n cchar = 0;\n try {\n snchar = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (snchar <= 0)\n return -1;\n }\n return buf[cchar++];\n }\n \n public int nextInt() {\n int c = nxt();\n while (isSpaceChar(c)) {\n c = nxt();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = nxt();\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 = nxt();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n \n public long nextLong() {\n int c = nxt();\n while (isSpaceChar(c)) {\n c = nxt();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = nxt();\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 = nxt();\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 = nxt();\n while (isSpaceChar(c)) {\n c = nxt();\n }\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = nxt();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n \n public String nextLine() {\n int c = nxt();\n while (isSpaceChar(c))\n c = nxt();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = nxt();\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 \n\n}\n", "src_uid": "5ea0351ac9f949dedae1928bfb7ebffa"} {"source_code": "\nimport java.io.*;\nimport java.math.*;\nimport java.lang.*;\nimport java.util.*;\npublic class Main {\n public static void main(String[] args) throws IOException {\n StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n Scanner sc=new Scanner(System.in);\n int x[]=new int[5];\n int y[]=new int[5];\n for(int i=1;i<=3;i++)\n {\n x[i]=sc.nextInt();\n y[i]=sc.nextInt();\n }\n int xx=x[1]-x[2];\n int yy=y[1]-y[2];\n int xxx=x[2]-x[3];\n int yyy=y[2]-y[3];\n out.printf(\"3\\r\\n\");\n out. printf(\"%d %d\\r\\n\",x[3]+xx,y[3]+yy);\n out. printf(\"%d %d\\r\\n\",x[3]-xx,y[3]-yy);\n out. printf(\"%d %d\\r\\n\",x[1]+xxx,y[1]+yyy);\n out.flush();\n }\n}", "src_uid": "7725f9906a1b87bf4e866df03112f1e0"} {"source_code": "/*\n * Code Author: Jayesh Udhani\n * Dhirubhai Ambani Institute of Information and Communication Technology (DA-IICT ,Gandhinagar)\n */\nimport java.io.*;\nimport java.util.*;\n\npublic class Order {\n\tstatic ArrayList<Pair> al=new ArrayList<Pair>();\n\tstatic class Pair<F,S> {\n\t\tprivate int first;\n\t\tprivate int second;\n\t\tpublic Pair(int i, int j) { \n\t\t\tthis.first = i;\n\t\t\tthis.second = j;\n\t\t}\n\t\tpublic int getFirst() { return first; }\n\t\tpublic int getSecond() { return second ;}\n\t}\n\tpublic static void main(String args[])\n\t{\n\t\tInputReader in = new InputReader(System.in);\n\t\tOutputStream outputStream = System.out;\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\t//----------My Code Starts Here----------\n\t\tint a,b,i,x=0,y=0,t=0,q1=-1,q2=-1;\n\t\ta=in.nextInt();\n\t\tb=in.nextInt();\n\t\t/*\t\tq1= a>=0?(b>=0?1:4):(b>=0?2:3);\n\t\tif(a>0&&b==0)\n\t\t\tq1=5;\n\t\tif(a==0 && b>0)\n\t\t\tq1=6;\n\t\tif(a<0 && b==0)\n\t\t\tq1=7;\n\t\tif(a==0 && b<0)\n\t\t\tq1=8;\n\t\tif(a==0 && b==0)\n\t\t\tq1=9;\t*/\n\t\tString str=in.next();\n\t\tfor(i=0;i<str.length();i++)\n\t\t{\n\t\t\tif(str.charAt(i)=='U')\n\t\t\t\ty++;\n\t\t\telse if(str.charAt(i)=='D')\n\t\t\t\ty--;\n\t\t\telse if(str.charAt(i)=='L')\n\t\t\t\tx--;\n\t\t\telse\n\t\t\t\tx++;\n\t\t\tal.add(new Pair<>(x,y));\n\t\t}\n\t\t/*\t\tq2= x>=0?(y>=0?1:4):(y>=0?2:3);\n\t\tif(x>0&&y==0)\n\t\t\tq2=5;\n\t\tif(x==0 && y>0)\n\t\t\tq2=6;\n\t\tif(x<0 && y==0)\n\t\t\tq2=7;\n\t\tif(x==0 && y<0)\n\t\t\tq2=8;\n\t\tif(x==0 && y==0)\n\t\t\tq2=9;\t*/\n//\t\tSystem.out.println(x+\" \"+y);\n\t\tif(x==0 && y==0 && a==0 && b==0)\n\t\t\tt=1;\n\t\tif(x==0 && y!=0 && a==0 && (b+y)%y==0 && (long)b*y>=0)\n\t\t\tt=1;\n\t\tif(x!=0 && y==0 && (a+x)%x==0 && b==0 && (long)a*x>=0)\n\t\t\tt=1;\n\t\tif(x!=0 && y!=0 && (a+x)%x==0 && (b+y)%y==0 && (a+x)/x==(b+y)/y && (long)a*x>=0 && (long)b*y>=0)\n\t\t\tt=1;\n\t\tfor(i=0;i<str.length()-1;i++)\n\t\t{\n\t\t\tif(str.charAt(i)=='U')\n\t\t\t\ty++;\n\t\t\telse if(str.charAt(i)=='D')\n\t\t\t\ty--;\n\t\t\telse if(str.charAt(i)=='L')\n\t\t\t\tx--;\n\t\t\telse\n\t\t\t\tx++;\n\t\t\tint p=al.get(i).first,q=al.get(i).second;\n\t\t\tint d1=x-p,d2=y-q;\n\t\t\tif(d1==0 && d2==0)\n\t\t\t{\n\t\t\t\tif(a==p && b==q)\n\t\t\t\t\tt=1;\n\t\t\t}\n\t\t\telse if(d1!=0 && d2==0)\n\t\t\t{\n\t\t\t\tif((a-(p-d1))%d1==0 && b==q && (long)(x-p)*(a-p)>=0)\n\t\t\t\t\tt=1;\n\t\t\t}\n\t\t\telse if(d1==0 && d2!=0)\n\t\t\t{\n\t\t\t\tif(a==p && (b-(q-d2))%d2==0 &&(long) (y-q)*(b-q)>=0)\n\t\t\t\t\tt=1;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif((a-(p-d1))%d1==0 && (b-(q-d2))%d2==0 && (a-(p-d1))/d1==(b-(q-d2))/d2 && (long)(x-p)*(a-p)>=0 &&(long) (y-q)*(b-q)>=0)\n\t\t\t\t\tt=1;\n\t\t\t}\n\t\t}\n//\t\tSystem.out.println(al.get(2).first+\" \"+al.get(2).second);\n\t\t//\t\tif(q1!=q2)\n\t\t//\t\t\tt=0;\n//\t\tSystem.out.println(q1+\" \"+q2);\n\t\tif(t==0)\n\t\t\tSystem.out.println(\"No\");\n\t\telse\n\t\t\tSystem.out.println(\"Yes\");\n\t\tout.close();\n\t\t//---------------The End\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\n\t}\n\tstatic class InputReader {\n\t\tpublic BufferedReader reader;\n\t\tpublic StringTokenizer tokenizer;\n\n\t\tpublic InputReader(InputStream inputstream) {\n\t\t\treader = new BufferedReader(new InputStreamReader(inputstream));\n\t\t\ttokenizer = null;\n\t\t}\n\n\t\tpublic String nextLine(){\n\t\t\tString fullLine=null;\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tfullLine=reader.readLine();\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t\treturn fullLine;\n\t\t\t}\n\t\t\treturn fullLine;\n\t\t}\n\t\tpublic String next() {\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t}\n}\n", "src_uid": "5d6212e28c7942e9ff4d096938b782bf"} {"source_code": "import java.util.Scanner;\n\n/**\n * Created by igarus on 13.06.2016.\n */\npublic class CF_B {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n long n = scanner.nextInt();\n long a = scanner.nextInt();\n long b = scanner.nextInt();\n long p = scanner.nextInt();\n long q = scanner.nextInt();\n\n long maxP = p;\n long minP = q;\n long maxA = a;\n long minA = b;\n if (q > p) {\n maxP = q;\n minP = p;\n maxA = b;\n minA = a;\n }\n long s = 0;\n long k = n / maxA;\n s += k * maxP;\n long z = n / minA - n / lcm(maxA, minA);\n s += z * minP;\n\n System.out.println(s);\n }\n\n public 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 public static long lcm(long a, long b) {\n return a / gcd(a, b) * b;\n }\n}\n", "src_uid": "35d8a9f0d5b5ab22929ec050b55ec769"} {"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.InputMismatchException;\nimport java.io.IOException;\nimport java.util.ArrayList;\nimport java.util.List;\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 *\n * @author prakharjain\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n _1047D solver = new _1047D();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class _1047D {\n int n;\n int m;\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n n = in.nextInt();\n m = in.nextInt();\n\n long ans = 0;\n\n if (n > 100) {\n int nn = (n - 100) % 6;\n long nq = (n - 100) / 6;\n ans += nq * 6 * m;\n n = 100 + nn;\n }\n\n if (m > 100) {\n int nm = (m - 100) % 6;\n long mq = (m - 100) / 6;\n ans += mq * 6 * n;\n m = 100 + nm;\n }\n\n int[][] mat = new int[n + 1][m + 1];\n\n int u = 1;\n int v = 1;\n for (int i = 1; i <= n; i++) {\n for (int j = 1; j <= m; j++) {\n if ((i + j) % 2 == 0) {\n mat[i][j] = u;\n u++;\n }\n }\n }\n\n for (int i = 1; i <= n; i++) {\n for (int j = 1; j <= m; j++) {\n if ((i + j) % 2 != 0) {\n mat[i][j] = v;\n v++;\n }\n }\n }\n\n List[] g = new List[u];\n\n for (int i = 0; i < u; i++) {\n g[i] = new ArrayList();\n }\n\n for (int i = 1; i <= n; i++) {\n for (int j = 1; j <= m; j++) {\n if ((i + j) % 2 == 0) {\n addEdge(mat, g, i, j, i - 3, j);\n addEdge(mat, g, i, j, i - 2, j - 1);\n addEdge(mat, g, i, j, i - 2, j + 1);\n addEdge(mat, g, i, j, i, j - 3);\n addEdge(mat, g, i, j, i - 1, j - 2);\n addEdge(mat, g, i, j, i + 1, j - 2);\n addEdge(mat, g, i, j, i, j + 3);\n addEdge(mat, g, i, j, i - 1, j + 2);\n addEdge(mat, g, i, j, i + 1, j + 2);\n addEdge(mat, g, i, j, i + 3, j);\n addEdge(mat, g, i, j, i + 2, j - 1);\n addEdge(mat, g, i, j, i + 2, j + 1);\n }\n }\n }\n\n HopcroftKarpBipartiteMatching bpm = new HopcroftKarpBipartiteMatching(u - 1, v - 1, g);\n\n ans += 2 * bpm.maximumMatching();\n\n out.println(ans);\n }\n\n void addEdge(int[][] mat, List[] g, int i, int j, int s, int t) {\n if (s <= 0 || t <= 0 || s > n || t > m)\n return;\n\n g[mat[i][j]].add(mat[s][t]);\n }\n\n class HopcroftKarpBipartiteMatching {\n int m;\n int n;\n List[] g;\n int[] pairU;\n int[] pairV;\n int[] dis;\n int inf = 10000000;\n int NIL = 0;\n\n public HopcroftKarpBipartiteMatching(int m, int n, List[] g) {\n this.m = m;\n this.n = n;\n this.g = g;\n this.pairU = new int[m + 1];\n this.pairV = new int[n + 1];\n this.dis = new int[m + 1];\n }\n\n int maximumMatching() {\n\n Arrays.fill(pairU, NIL);\n Arrays.fill(pairV, NIL);\n\n int maxMatching = 0;\n\n while (bfs()) {\n for (int i = 1; i <= m; i++) {\n if (pairU[i] == NIL && dfs(i))\n maxMatching++;\n }\n }\n\n return maxMatching;\n }\n\n boolean bfs() {\n\n ArrayDeque<Integer> queue = new ArrayDeque<>();\n\n for (int i = 1; i <= m; i++) {\n if (pairU[i] == NIL) {\n queue.addLast(i);\n dis[i] = 0;\n } else {\n dis[i] = inf;\n }\n }\n\n dis[NIL] = inf;\n\n while (!queue.isEmpty()) {\n int u = queue.removeFirst();\n\n if (dis[u] < dis[NIL]) {\n for (int v : (List<Integer>) g[u]) {\n if (dis[pairV[v]] == inf) {\n queue.addLast(pairV[v]);\n dis[pairV[v]] = dis[u] + 2;\n }\n }\n }\n }\n\n return dis[NIL] < inf;\n }\n\n boolean dfs(int u) {\n if (u != NIL) {\n for (int v : (List<Integer>) g[u]) {\n if (dis[pairV[v]] == dis[u] + 2) {\n if (dfs(pairV[v])) {\n pairV[v] = u;\n pairU[u] = v;\n return true;\n }\n }\n }\n dis[u] = inf;\n return false;\n } else\n return true;\n }\n\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void println(long i) {\n writer.println(i);\n }\n\n }\n}\n\n", "src_uid": "02ce135a4b276d1e9ba6a4ce37f2fe70"} {"source_code": "\nimport java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class C {\n\n long mod = (int) 1e9 + 7;\n\n long binpow(long a, long n) {\n long res = 1;\n while (n > 0) {\n if ((n & 1) > 0) {\n res *= a;\n res %= mod;\n }\n a *= a;\n a %= mod;\n n >>= 1;\n }\n return res;\n }\n\n public void solve() throws IOException {\n long x = nextInt(), n = nextLong();\n Map<Integer, Long> fact = new HashMap<>();\n Set<Integer> div = new HashSet<>();\n int t = (int) x;\n for (int d = 2; d * d <= t; d++) {\n while (t % d == 0) {\n fact.putIfAbsent(d, 0L);\n div.add(d);\n t /= d;\n }\n }\n if (t > 1) {\n fact.putIfAbsent(t, 0L);\n div.add(t);\n }\n for (Integer v : div) {\n BigInteger cur = BigInteger.valueOf(v);\n while (cur.compareTo(BigInteger.valueOf(n)) <= 0) {\n fact.put(v, fact.get(v) + n / cur.longValue());\n cur = cur.multiply(BigInteger.valueOf(v));\n }\n }\n BigInteger ans = BigInteger.ONE;\n for (Map.Entry<Integer, Long> e : fact.entrySet()) {\n if (e.getValue() > 0) {\n ans = ans.multiply(BigInteger.valueOf(binpow(e.getKey(), e.getValue())));\n ans = ans.mod(BigInteger.valueOf(mod));\n }\n }\n out.print(ans);\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 int[] nextArr(int n) throws IOException {\n int[] res = new int[n];\n for (int i = 0; i < n; i++) {\n res[i] = nextInt();\n }\n return res;\n }\n\n public static void main(String[] args) throws IOException {\n Locale.setDefault(Locale.US);\n new C().run();\n }\n}", "src_uid": "04610fbaa746c083dda30e21fa6e1a0c"} {"source_code": "import java.util.*;\nimport java.lang.*;\nimport java.math.*;\nimport java.io.*;\nimport static java.lang.Math.*;\npublic class Solution{ \n static InputReader sc;\n static PrintWriter wc;\n static long gcd(long a, long b){ \n if (a == 0) \n return b; \n return gcd(b % a, a); \n } \n public static void main(String[] args) {\n sc=new InputReader(System.in);\n wc=new PrintWriter(System.out);\n long a=sc.nextLong(),b=sc.nextLong();\n if(a>b){\n long temp=a;\n a=b;\n b=temp;\n }\n else if(a==b){\n wc.println(0);\n wc.close();\n return;\n }\n long n=a,m=b;\n long i;\n long k=Long.MAX_VALUE,add;\n long min=Long.MAX_VALUE,lcm;\n for(i=1;i*i<=(b-a);i++){\n a=n;\n b=m;\n if((b-a)%i==0){\n if(a%i==0){\n lcm=a*b/gcd(a,b);\n if(min>=lcm){\n min=lcm;\n k=0;\n }\n }\n else{\n add=((a/i)+1)*i-a;\n a+=add;\n b+=add;\n lcm=a*b/gcd(a,b);\n if(min>lcm){\n min=lcm;\n k=add;\n }\n else if(min==lcm){\n if(k>add) k=add;\n }\n }\n //wc.println(lcm);\n a=n;\n b=m;\n long j=(b-a)/i;\n if(a%j==0){\n lcm=a*b/gcd(a,b);\n if(min>=lcm){\n min=lcm;\n k=0;\n }\n }\n else{\n add=((a/j)+1)*j-a;\n a+=add;\n b+=add;\n lcm=a*b/gcd(a,b);\n if(min>lcm){\n min=lcm;\n k=add;\n }\n else if(min==lcm){\n if(k>add) k=add;\n }\n }\n //wc.println(lcm);\n a=n;\n b=m;\n }\n }\n wc.println(k);\n wc.close();\n }\n static class InputReader {\n \n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private SpaceCharFilter filter;\n \n public InputReader(InputStream stream)\n {\n this.stream = stream;\n }\n \n public int read()\n {\n if (numChars==-1) \n throw new InputMismatchException();\n \n if (curChar >= numChars)\n {\n curChar = 0;\n try \n {\n numChars = stream.read(buf);\n }\n catch (IOException e)\n {\n throw new InputMismatchException();\n }\n \n if(numChars <= 0) \n return -1;\n }\n return buf[curChar++];\n }\n \n public String nextLine()\n {\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n String str = \"\";\n try\n {\n str = br.readLine();\n }\n catch (IOException e)\n {\n e.printStackTrace();\n }\n return str;\n }\n public int nextInt()\n {\n int c = read();\n \n while(isSpaceChar(c)) \n c = read();\n \n int sgn = 1;\n \n if (c == '-') \n {\n sgn = -1;\n c = read();\n }\n \n int res = 0;\n do \n {\n if(c<'0'||c>'9') \n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n }\n while (!isSpaceChar(c)); \n \n return res * sgn;\n }\n \n public long nextLong() \n {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') \n {\n sgn = -1;\n c = read();\n }\n long res = 0;\n \n do \n {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n }\n while (!isSpaceChar(c));\n return res * sgn;\n }\n \n public double nextDouble() \n {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') \n {\n sgn = -1;\n c = read();\n }\n double res = 0;\n while (!isSpaceChar(c) && c != '.') \n {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, nextInt());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n }\n if (c == '.') \n {\n c = read();\n double m = 1;\n while (!isSpaceChar(c)) \n {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, nextInt());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n m /= 10;\n res += (c - '0') * m;\n c = read();\n }\n }\n return res * sgn;\n }\n \n public String readString() \n {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do \n {\n res.appendCodePoint(c);\n c = read();\n } \n while (!isSpaceChar(c));\n \n return res.toString();\n }\n \n public boolean isSpaceChar(int c) \n {\n if (filter != null)\n return filter.isSpaceChar(c);\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n \n public String next() \n {\n return readString();\n }\n \n public interface SpaceCharFilter \n {\n public boolean isSpaceChar(int ch);\n }\n } \n}", "src_uid": "414149fadebe25ab6097fc67663177c3"} {"source_code": "import java.util.*;\n\npublic class StronglyConnectedCity {\n public static void main(String s[]) {\n Scanner inp = new Scanner(System.in);\n \n int n=inp.nextInt();\n int m=inp.nextInt();\n inp.nextLine();\n String hl = inp.nextLine();\n String vl = inp.nextLine();\n \n \n \n SCGraph scGraph = new SCGraph(n, m);\n \n \n for(int i=0;i<hl.length();i++) {\n if(hl.charAt(i)=='>') {\n for(int j=1;j<m;j++) {\n scGraph.arr[scGraph.hash(i, j-1)][scGraph.hash(i, j)]=1;\n }\n }\n else if(hl.charAt(i)=='<') {\n for(int j=m-2;j>=0;j--) {\n scGraph.arr[scGraph.hash(i, j+1)][scGraph.hash(i, j)]=1;\n }\n }\n else {\n System.out.println(\"Error!\");\n }\n }\n \n for(int i=0;i<vl.length();i++) {\n if(vl.charAt(i) == 'v') {\n for(int j=1;j<n;j++) {//iterating on rows\n scGraph.arr[scGraph.hash(j-1, i)][scGraph.hash(j, i)]=1;\n }\n }\n else if(vl.charAt(i) == '^'){\n for(int j=n-2;j>=0;j--) {\n scGraph.arr[scGraph.hash(j+1, i)][scGraph.hash(j, i)]=1;\n }\n }\n else\n System.out.println(\"Error!!!\");\n }\n \n \n \n \n for(int k=0;k<(m*n);k++) {\n for(int i=0;i<(n*m);i++) {\n for(int j=0;j< (n*m);j++) { \n scGraph.arr[j][j]=1;\n if((scGraph.arr[i][k]==1) && (scGraph.arr[k][j]==1)) \n scGraph.arr[i][j]=1;\n\n }\n }\n } \n \n \n /*for(int i=0;i<(n*m);i++) {\n for(int j=0;j<(n*m);j++) {\n for(int k=0;k<(n*m);k++) {\n scGraph.arr[k][k]=1;\n \n if( (scGraph.arr[i][k]==1) && (scGraph.arr[k][j]==1) )\n {\n scGraph.arr[i][j]=1;\n }\n }\n }\n } */\n \n boolean result=true;\n \n for(int i=0;(i< (n*m)) && (result==true) ;i++) {\n for(int j=0;(j<(n*m)) && (result==true) ;j++) {\n if(scGraph.arr[i][j] != 1) {\n result=false;\n }\n }\n }\n \n if(result==true) {\n System.out.println(\"YES\");\n }\n else{\n System.out.println(\"NO\");\n }\n\n }\n\n}\n\n\nclass SCGraph {\n int n,m;\n int arr[][];//adj mtrix\n \n SCGraph(int n, int m) {\n this.n=n;\n this.m=m;\n arr = new int[n*m][n*m];\n }\n \n \n int hash(int i, int j) {\n return m*i+j;\n }\n}", "src_uid": "eab5c84c9658eb32f5614cd2497541cf"} {"source_code": "import java.util.Scanner;\npublic class expr {\n\tpublic static void main (String [] wee){\n\t\t\n\t\tScanner sti =new Scanner(System.in);\n\t\t\n\t\tint a,b,c;\n\t\ta= sti.nextInt();\n\t\tb= sti.nextInt();\n\t\tc= sti.nextInt();\n\t\t\n\t\tint sum = 0 ;\n\t\tint high = 0 ;\n\t\t\n\t\tsum = a+b*c;\n\t\t\tif(sum > high){\n\t\t\t\thigh = sum;\n\t\t\t}\n\t\tsum = a*(b+c);\n\t\t\tif(sum > high){\n\t\t\t\thigh = sum;\n\t\t\t}\t\n\t\tsum = a*b*c;\n\t\t\tif(sum > high){\n\t\t\t\thigh = sum;\n\t\t\t}\n\t\tsum = (a+b)*c;\n\t\t\tif(sum > high){\n\t\t\t\thigh = sum;\n\t\t\t}\n\t\tsum = a+b+c;\n\t\t\tif(sum > high){\n\t\t\t\thigh = sum;\n\t\t\t}\n\t\t\n\t\tSystem.out.println(high);\n\t}\n} ", "src_uid": "1cad9e4797ca2d80a12276b5a790ef27"} {"source_code": "\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.nio.charset.Charset;\nimport java.util.Arrays;\nimport java.util.Random;\n\npublic class CF1204E {\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\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// debug.debug(\"bf\", bruteForce(3, 1));\n// debug.debug(\"so\", solve(3, 1));\n// debug.assertTrue(bruteForce(3, 1) == solve(3, 1));\n// for(int i = 0; i < 10; i++){\n// for(int j = 0; j < 10; j++){\n// debug.debug(\"i\", i);\n// debug.debug(\"j\", j);\n// debug.assertTrue(bruteForce(i, j) == solve(i, j));\n// }\n// }\n }\n\n\n public int bruteForce(int n, int m) {\n return allPerm(n, m, 0, 0);\n }\n\n public int allPerm(int n, int m, int max, int val) {\n max = Math.max(max, val);\n if (n == 0 && m == 0) {\n return max;\n }\n int sum = 0;\n if (n > 0) {\n sum = mod.plus(sum, allPerm(n - 1, m, max, val + 1));\n }\n if (m > 0) {\n sum = mod.plus(sum, allPerm(n, m - 1, max, val - 1));\n }\n return sum;\n }\n\n NumberTheory.Modular mod = new NumberTheory.Modular(998244853);\n NumberTheory.Composite comp = new NumberTheory.Composite(4000, mod);\n\n public void solve() {\n int n = io.readInt();\n int m = io.readInt();\n io.cache.append(solve(n, m));\n }\n\n\n public int solve(int n, int m) {\n int[] leq = new int[n + 1];\n leq[0] = comp.composite(n + m, n);\n for (int i = 0; i <= n; i++) {\n leq[i] = pathNoGreaterThan(n, m, i);\n }\n\n\n debug.debug(\"leq\", leq);\n for (int i = n; i > 0; i--) {\n leq[i] = mod.plus(leq[i], -leq[i - 1]);\n }\n debug.debug(\"leq\", leq);\n\n int sum = 0;\n for (int i = 0; i <= n; i++) {\n sum = mod.plus(sum, mod.mul(leq[i], i));\n }\n return sum;\n }\n\n //all prefix not greater than k\n public int pathNoGreaterThan(int n, int m, int k) {\n return path(m, n, k);\n }\n\n //find how many permutation satisfy follow condition:\n // - n * 1\n // - m * -1\n // - all prefix greater than -k\n public int path(int n, int m, int k) {\n if (n - m < -k) {\n return 0;\n }\n return mod.plus(comp.composite(n + m, n), -comp.composite(n + m,\n n + 1 + k));\n }\n }\n\n public static class NumberTheory {\n private static final Random RANDOM = new Random();\n\n /**\n * Extend gcd\n */\n public static class ExtGCD {\n private long x;\n private long y;\n private long g;\n\n public long getX() {\n return x;\n }\n\n public long getY() {\n return y;\n }\n\n /**\n * Get g = Gcd(a, b) and find a way to set x and y to match ax+by=g\n */\n public long extgcd(long a, long b) {\n if (a >= b) {\n g = extgcd0(a, b);\n } else {\n g = extgcd0(b, a);\n long tmp = x;\n x = y;\n y = tmp;\n }\n return g;\n }\n\n\n private long extgcd0(long a, long b) {\n if (b == 0) {\n x = 1;\n y = 0;\n return a;\n }\n long g = extgcd0(b, a % b);\n long n = x;\n long m = y;\n x = m;\n y = n - m * (a / b);\n return g;\n }\n }\n\n public static class Gcd {\n public long gcd(long a, long b) {\n return a >= b ? gcd0(a, b) : gcd0(b, a);\n }\n\n private long gcd0(long a, long b) {\n return b == 0 ? a : gcd0(b, a % b);\n }\n\n public int gcd(int a, int b) {\n return a >= b ? gcd0(a, b) : gcd0(b, a);\n }\n\n private int gcd0(int a, int b) {\n return b == 0 ? a : gcd0(b, a % b);\n }\n }\n\n /**\n * Mod operations\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 mul(long x, long y) {\n x = valueOf(x);\n y = valueOf(y);\n return valueOf(x * y);\n }\n\n public int plus(int x, int y) {\n return valueOf(x + y);\n }\n\n public int plus(long x, long y) {\n x = valueOf(x);\n y = valueOf(y);\n return valueOf(x + y);\n }\n\n @Override\n public String toString() {\n return \"mod \" + m;\n }\n }\n\n /**\n * Bit operations\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 /**\n * Power operations\n */\n public static class Power {\n final Modular modular;\n\n public Power(Modular modular) {\n this.modular = modular;\n }\n\n public int pow(int x, long n) {\n if (n == 0) {\n return 1;\n }\n long r = pow(x, n >> 1);\n r = modular.valueOf(r * r);\n if ((n & 1) == 1) {\n r = modular.valueOf(r * x);\n }\n return (int) r;\n }\n\n public int inverse(int x) {\n return pow(x, modular.m - 2);\n }\n\n public int pow2(int x) {\n return x * x;\n }\n\n public long pow2(long x) {\n return x * x;\n }\n\n public double pow2(double x) {\n return x * x;\n }\n }\n\n /**\n * Log operations\n */\n public static class Log2 {\n public int ceilLog(int x) {\n return 32 - Integer.numberOfLeadingZeros(x - 1);\n }\n\n public int floorLog(int x) {\n return 31 - Integer.numberOfLeadingZeros(x);\n }\n\n public int ceilLog(long x) {\n return 64 - Long.numberOfLeadingZeros(x - 1);\n }\n\n public int floorLog(long x) {\n return 63 - Long.numberOfLeadingZeros(x);\n }\n }\n\n /**\n * Find all inverse number\n */\n public 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.m;\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 * Factorial\n */\n public static class Factorial {\n int[] fact;\n int[] inv;\n\n public Factorial(int[] fact, int[] inv, InverseNumber in, int limit, 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 * Composition\n */\n public static class Composite {\n final Factorial factorial;\n final Modular modular;\n\n public Composite(Factorial factorial, Modular modular) {\n this.factorial = factorial;\n this.modular = modular;\n }\n\n public Composite(int limit, Modular modular) {\n this(new Factorial(limit, modular), 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.inv[n]), factorial.inv[m - n]);\n }\n }\n\n /**\n * Test whether a number is primes\n */\n public static class MillerRabin {\n Modular modular;\n Power power;\n\n /**\n * Check whether n is a prime s times\n */\n public boolean mr(int n, int s) {\n if (n == 2) {\n return true;\n }\n if (n % 2 == 0) {\n return false;\n }\n modular = new Modular(n);\n power = new Power(modular);\n for (int i = 0; i < s; i++) {\n int x = RANDOM.nextInt(n - 2) + 2;\n if (!mr0(x, n)) {\n return false;\n }\n }\n return true;\n }\n\n private boolean mr0(int x, int n) {\n int exp = n - 1;\n while (true) {\n int y = power.pow(x, exp);\n if (y != 1 && y != n - 1) {\n return false;\n }\n if (y != 1 || exp % 2 == 1) {\n break;\n }\n exp = exp / 2;\n }\n return true;\n }\n }\n }\n\n public static class FastIO {\n public final StringBuilder cache = new StringBuilder(1 << 13);\n private final InputStream is;\n private final OutputStream os;\n private final Charset charset;\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 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() throws IOException {\n os.write(cache.toString().getBytes(charset));\n os.flush();\n cache.setLength(0);\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", "src_uid": "a2fcad987e9b2bb3e6395654cd4fcfbb"} {"source_code": "import java.util.Scanner;\npublic class cfa{\n\tstatic void solve(int a,int b){\n\t int m=a;\n\t if(b>m)\n\t {m=b;b=a;}\n\t int d=b*2;\n\t if(d>=m)\n\t {System.out.println((b+m)/3);return;}\n System.out.println((b+d)/3);\n\t}\n\tpublic static void main(String[] args)\n\t{\n\t\tint a,b,d,m;\n\t\tScanner o=new Scanner(System.in);\n\t\ta=o.nextInt();\n\t\tb=o.nextInt();\n\t\tsolve(a,b);\n\t}\n}", "src_uid": "0718c6afe52cd232a5e942052527f31b"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n InputStream is;\n PrintWriter out;\n String INPUT = \"\";\n \n long MAX = 100000L, MOD = 1000000007L, INF = (long) 1e18;\n \n void solve(int TC) throws Exception {\n \tint n = ni();\n \tint[] a = new int[n];\n \tfor(int i=0;i<n;i++) a[i] = ni();\n \tint C=0,S=0,R=0,newC=0,newS=0,newR=0;\n \tfor(int i=0;i<n;i++) {\n \t\tnewR = Math.max(R, Math.max(S, C));\n \t\tnewS = newR;\n \t\tnewC = newR;\n \t\tif(a[i] == 2 || a[i] == 3) newS = Math.max(newS, Math.max(R, C) + 1);\n \t\tif(a[i] == 1 || a[i] == 3) newC = Math.max(newC, Math.max(R, S) + 1);\n \t\tS = newS;\n \t\tC = newC;\n \t\tR = newR;\n \t}\n \tpn(n - Math.max(Math.max(S, C), R));\n }\n \n boolean TestCases = false;\n public static void main(String[] args) throws Exception { new Main().run(); }\n \n long pow(long a, long b) {\n if(b==0 || a==1) return 1;\n long o = 1;\n for(long p = b; p > 0; p>>=1) {\n if((p&1)==1) o = (o*a) % MOD;\n a = (a*a) % MOD;\n } return o;\n }\n \n long inv(long x) {\n long o = 1;\n for(long p = MOD-2; p > 0; p>>=1) {\n if((p&1)==1)o = (o*x)%MOD;\n x = (x*x)%MOD;\n } return o;\n }\n long gcd(long a, long b) { return (b==0) ? a : gcd(b,a%b); }\n int gcd(int a, int b) { return (b==0) ? a : gcd(b,a%b); }\n void hold(boolean b)throws Exception{if(!b)throw new Exception(\"Hold right there, Sparky!\");}\n static void dbg(Object... o){System.err.println(Arrays.deepToString(o));}\n \n void run() throws Exception {\n is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n out = new PrintWriter(System.out);\n long s = System.currentTimeMillis();\n int T = TestCases ? ni() : 1;\n for(int t=1;t<=T;t++) solve(t);\n out.flush();\n if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+\"ms\");\n }\n \n void p(Object o) { out.print(o); }\n void pn(Object o) { out.println(o); }\n void pni(Object o) { out.println(o);out.flush(); }\n double PI = 3.141592653589793238462643383279502884197169399;\n \n int ni() {\n int num = 0, b;\n boolean minus = false;\n while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n if(b == '-') {\n minus = true;\n b = readByte();\n }\n 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 long nl() {\n long num = 0;\n int b;\n boolean minus = false;\n while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n if(b == '-') {\n minus = true;\n b = readByte();\n }\n 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 double nd() { return Double.parseDouble(ns()); }\n char nc() { return (char)skip(); }\n \n int BUF_SIZE = 1024 * 8;\n byte[] inbuf = new byte[BUF_SIZE];\n int lenbuf = 0, ptrbuf = 0;\n \n int readByte() {\n if(lenbuf == -1)throw new InputMismatchException();\n if(ptrbuf >= lenbuf){\n ptrbuf = 0;\n try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n if(lenbuf <= 0)return -1;\n } return inbuf[ptrbuf++];\n }\n \n boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n \n String ns() {\n int b = skip();\n StringBuilder sb = new StringBuilder();\n while(!(isSpaceChar(b))) {\n sb.appendCodePoint(b); b = readByte();\n } return sb.toString();\n }\n \n 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 } return n == p ? buf : Arrays.copyOf(buf, p);\n }\n \n void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }\n}", "src_uid": "08f1ba79ced688958695a7cfcfdda035"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\nimport java.util.stream.IntStream;\nimport java.util.stream.LongStream;\n\npublic class Main {\n\n void solve() throws IOException {\n long n = nl(), m = nl(), k = nl(), x = nl(), y = nl();\n\n if (n <= 2) {\n long p = k / (n * m);\n long q = k % (n * m);\n\n out.print((q == 0 ? p : p + 1) + \" \" + p + \" \");\n out.println(q >= (x - 1) * m + y ? p + 1 : p);\n } else {\n long t = (n - 1) * m;\n long p = k / t;\n long q = k % t;\n\n long max = p;\n if (p == 0 && q > 0 || q > m) max++;\n out.print(max + \" \");\n\n long min = p / 2;\n if (p % 2 == 1 && q >= m) min++;\n out.print(min + \" \");\n\n if (x == 1) {\n long s = p / 2;\n if (q >= y) s++;\n out.println(s);\n } else if (x == n) {\n long s = p / 2;\n if (p % 2 == 1 && q >= y) s++;\n out.println(s);\n } else {\n long s = p;\n if (p % 2 == 0 && q >= (x - 1) * m + y\n || p % 2 == 1 && q >= (n - x) * m + y) s++;\n out.println(s);\n }\n }\n }\n\n String ns() throws IOException {\n while (!tok.hasMoreTokens()) {\n tok = new StringTokenizer(in.readLine(), \" \");\n }\n return tok.nextToken();\n }\n\n int ni() throws IOException {\n return Integer.parseInt(ns());\n }\n\n long nl() throws IOException {\n return Long.parseLong(ns());\n }\n\n double nd() throws IOException {\n return Double.parseDouble(ns());\n }\n\n String[] nsa(int n) throws IOException {\n String[] res = new String[n];\n for (int i = 0; i < n; i++) {\n res[i] = ns();\n }\n return res;\n }\n\n int[] nia(int n) throws IOException {\n int[] res = new int[n];\n for (int i = 0; i < n; i++) {\n res[i] = ni();\n }\n return res;\n }\n\n long[] nla(int n) throws IOException {\n long[] res = new long[n];\n for (int i = 0; i < n; i++) {\n res[i] = nl();\n }\n return res;\n }\n\n static BufferedReader in;\n static PrintWriter out;\n static StringTokenizer tok;\n\n public static void main(String[] args) throws IOException {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n tok = new StringTokenizer(\"\");\n Main main = new Main();\n main.solve();\n out.close();\n }\n}", "src_uid": "e61debcad37eaa9a6e21d7a2122b8b21"} {"source_code": "import java.util.ArrayList;\nimport java.util.Scanner;\n\n\npublic class listas {\n static Scanner sn = new Scanner(System.in);\n public static void main(String[] args){\n \n String p = sn.next();\n int w = 0;\n for(int i = 0; i < p.length(); i++)\n if(p.charAt(i) == '4'|| p.charAt(i) == '7')\n w++;\n \n String c = w+\"\";\n for(int i = 0; i < c.length(); i++)\n if(c.charAt(i) == '7' || c.charAt(i) == '4' ){\n System.out.println(\"YES\");\n break;\n }\n else{\n System.out.println(\"NO\");\n break;\n }\n \n \n }\n \n}", "src_uid": "33b73fd9e7f19894ea08e98b790d07f1"} {"source_code": "import java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.NoSuchElementException;\nimport java.io.Writer;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Egor Kulikov (egor@egork.net)\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tOutputWriter out = new OutputWriter(outputStream);\n\t\tTaskD solver = new TaskD();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskD {\n\tstatic final int MOD = (int) (1e9 + 9);\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n\t\tint count = in.readInt();\n\t\tint height = in.readInt();\n\t\tint[][][][] result = new int[height + 1][height + 1][height + 1][height + 1];\n\t\tresult[0][0][0][0] = 1;\n\t\tint[][][][] next = new int[height + 1][height + 1][height + 1][height + 1];\n\t\tfor (int i = 0; i < count; i++) {\n\t\t\tfor (int j = 0; j <= height; j++) {\n\t\t\t\tfor (int k = j; k <= height; k++)\n\t\t\t\t\tArrays.fill(next[0][j][k], k, height + 1, 0);\n\t\t\t}\n\t\t\tnext[height][height][height][height] = 0;\n\t\t\tfor (int j = 1; j < height; j++) {\n\t\t\t\tnext[j][height][height][height] = 0;\n\t\t\t\tfor (int k = j; k < height; k++) {\n\t\t\t\t\tnext[j][k][height][height] = 0;\n\t\t\t\t\tfor (int l = k; l < height; l++)\n\t\t\t\t\t\tnext[j][k][l][height] = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int j = 0; j <= height; j++) {\n\t\t\t\tint nj = Math.min(j + 1, height);\n\t\t\t\tfor (int k = j; k <= height; k++) {\n\t\t\t\t\tint nk = Math.min(k + 1, height);\n\t\t\t\t\tfor (int l = k; l <= height; l++) {\n\t\t\t\t\t\tint nl = Math.min(l + 1, height);\n\t\t\t\t\t\tint shift = 1;\n\t\t\t\t\t\tif (j != 0 && l != height)\n\t\t\t\t\t\t\tshift = height;\n\t\t\t\t\t\tint start = l;\n\t\t\t\t\t\tif (l != 0 && shift == height)\n\t\t\t\t\t\t\tstart = height;\n\t\t\t\t\t\tfor (int m = start; m <= height; m += shift) {\n\t\t\t\t\t\t\tif (result[j][k][l][m] == 0)\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\tint nm = Math.min(m + 1, height);\n\t\t\t\t\t\t\tif (j == height) {\n\t\t\t\t\t\t\t\tnext[j][nk][nl][nm] += result[j][k][l][m];\n\t\t\t\t\t\t\t\tif (next[j][nk][nl][nm] >= MOD)\n\t\t\t\t\t\t\t\t\tnext[j][nk][nl][nm] -= MOD;\n\t\t\t\t\t\t\t} else {\n//\t\t\t\t\t\t\t\tint delta;\n//\t\t\t\t\t\t\t\tif (0 == nm)\n//\t\t\t\t\t\t\t\t\tdelta = 1;\n//\t\t\t\t\t\t\t\telse if (nk == nm)\n//\t\t\t\t\t\t\t\t\tdelta = 4;\n//\t\t\t\t\t\t\t\telse if (nl == nm)\n//\t\t\t\t\t\t\t\t\tdelta = 12;\n//\t\t\t\t\t\t\t\telse\n//\t\t\t\t\t\t\t\t\tdelta = 24;\n\t\t\t\t\t\t\t\tnext[0][nk][nl][nm] += result[j][k][l][m];\n\t\t\t\t\t\t\t\tif (next[0][nk][nl][nm] >= MOD)\n\t\t\t\t\t\t\t\t\tnext[0][nk][nl][nm] -= MOD;\n\t\t\t\t\t\t\t}\n//\t\t\t\t\t\t\tif (k != j)\n\t\t\t\t\t\t\tif (k == height) {\n//\t\t\t\t\t\t\t\tint delta;\n//\t\t\t\t\t\t\t\tif (nj == height)\n//\t\t\t\t\t\t\t\t\tdelta = 1;\n//\t\t\t\t\t\t\t\telse\n//\t\t\t\t\t\t\t\t\tdelta = 4;\n\t\t\t\t\t\t\t\tnext[nj][k][nl][nm] += result[j][k][l][m];\n\t\t\t\t\t\t\t\tif (next[nj][k][nl][nm] >= MOD)\n\t\t\t\t\t\t\t\t\tnext[nj][k][nl][nm] -= MOD;\n\t\t\t\t\t\t\t} else {\n//\t\t\t\t\t\t\t\tint delta;\n//\t\t\t\t\t\t\t\tif (0 == nm)\n//\t\t\t\t\t\t\t\t\tdelta = 1;\n//\t\t\t\t\t\t\t\telse if (nj == nm)\n//\t\t\t\t\t\t\t\t\tdelta = 4;\n//\t\t\t\t\t\t\t\telse if (nl == nm)\n//\t\t\t\t\t\t\t\t\tdelta = 12;\n//\t\t\t\t\t\t\t\telse\n//\t\t\t\t\t\t\t\t\tdelta = 24;\n\t\t\t\t\t\t\t\tnext[0][nj][nl][nm] += result[j][k][l][m];\n\t\t\t\t\t\t\t\tif (next[0][nj][nl][nm] >= MOD)\n\t\t\t\t\t\t\t\t\tnext[0][nj][nl][nm] -= MOD;\n\t\t\t\t\t\t\t}\n//\t\t\t\t\t\t\tif (l != k)\n\t\t\t\t\t\t\tif (l == height) {\n//\t\t\t\t\t\t\t\tint delta;\n//\t\t\t\t\t\t\t\tif (nj == height)\n//\t\t\t\t\t\t\t\t\tdelta = 1;\n//\t\t\t\t\t\t\t\telse if (nk == height)\n//\t\t\t\t\t\t\t\t\tdelta = 4;\n//\t\t\t\t\t\t\t\telse\n//\t\t\t\t\t\t\t\t\tdelta = 12;\n\t\t\t\t\t\t\t\tnext[nj][nk][l][nm] += result[j][k][l][m];\n\t\t\t\t\t\t\t\tif (next[nj][nk][l][nm] >= MOD)\n\t\t\t\t\t\t\t\t\tnext[nj][nk][l][nm] -= MOD;\n\t\t\t\t\t\t\t} else {\n//\t\t\t\t\t\t\t\tint delta;\n//\t\t\t\t\t\t\t\tif (0 == nm)\n//\t\t\t\t\t\t\t\t\tdelta = 1;\n//\t\t\t\t\t\t\t\telse if (nj == nm)\n//\t\t\t\t\t\t\t\t\tdelta = 4;\n//\t\t\t\t\t\t\t\telse if (nk == nm)\n//\t\t\t\t\t\t\t\t\tdelta = 12;\n//\t\t\t\t\t\t\t\telse\n//\t\t\t\t\t\t\t\t\tdelta = 24;\n\t\t\t\t\t\t\t\tnext[0][nj][nk][nm] += result[j][k][l][m];\n\t\t\t\t\t\t\t\tif (next[0][nj][nk][nm] >= MOD)\n\t\t\t\t\t\t\t\t\tnext[0][nj][nk][nm] -= MOD;\n\t\t\t\t\t\t\t}\n//\t\t\t\t\t\t\tif (m != l)\n\t\t\t\t\t\t\tif (m == height) {\n//\t\t\t\t\t\t\t\tint delta;\n//\t\t\t\t\t\t\t\tif (nj == height)\n//\t\t\t\t\t\t\t\t\tdelta = 1;\n//\t\t\t\t\t\t\t\telse if (nk == height)\n//\t\t\t\t\t\t\t\t\tdelta = 4;\n//\t\t\t\t\t\t\t\telse if (nl == height)\n//\t\t\t\t\t\t\t\t\tdelta = 12;\n//\t\t\t\t\t\t\t\telse\n//\t\t\t\t\t\t\t\t\tdelta = 24;\n\t\t\t\t\t\t\t\tnext[nj][nk][nl][m] += result[j][k][l][m];\n\t\t\t\t\t\t\t\tif (next[nj][nk][nl][m] >= MOD)\n\t\t\t\t\t\t\t\t\tnext[nj][nk][nl][m] -= MOD;\n\t\t\t\t\t\t\t} else {\n//\t\t\t\t\t\t\t\tint delta;\n//\t\t\t\t\t\t\t\tif (0 == nl)\n//\t\t\t\t\t\t\t\t\tdelta = 1;\n//\t\t\t\t\t\t\t\telse if (nj == nl)\n//\t\t\t\t\t\t\t\t\tdelta = 4;\n//\t\t\t\t\t\t\t\telse if (nk == nl)\n//\t\t\t\t\t\t\t\t\tdelta = 12;\n//\t\t\t\t\t\t\t\telse\n//\t\t\t\t\t\t\t\t\tdelta = 24;\n\t\t\t\t\t\t\t\tnext[0][nj][nk][nl] += result[j][k][l][m];\n\t\t\t\t\t\t\t\tif (next[0][nj][nk][nl] >= MOD)\n\t\t\t\t\t\t\t\t\tnext[0][nj][nk][nl] -= MOD;\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\tint[][][][] temp = result;\n\t\t\tresult = next;\n\t\t\tnext = temp;\n\t\t}\n\t\tlong total = 0;\n\t\tfor (int i = 0; i <= height; i++) {\n\t\t\tfor (int j = i; j <= height; j++) {\n\t\t\t\tfor (int k = j; k <= height; k++) {\n\t\t\t\t\tfor (int l = k; l <= height; l++) {\n\t\t\t\t\t\tint delta;\n\t\t\t\t\t\tif (i == l)\n\t\t\t\t\t\t\tdelta = 1;\n\t\t\t\t\t\telse if (j == l)\n\t\t\t\t\t\t\tdelta = 4;\n\t\t\t\t\t\telse if (k == l)\n\t\t\t\t\t\t\tdelta = 12;\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tdelta = 24;\n\t\t\t\t\t\ttotal += result[i][j][k][l];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\ttotal -= result[height][height][height][height];\n\t\tout.printLine(total % MOD);\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\tpublic interface SpaceCharFilter {\n\t\tpublic boolean isSpaceChar(int ch);\n\t}\n}\n\nclass OutputWriter {\n\tprivate final PrintWriter writer;\n\n\tpublic OutputWriter(OutputStream outputStream) {\n\t\twriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n\t}\n\n\tpublic OutputWriter(Writer writer) {\n\t\tthis.writer = new PrintWriter(writer);\n\t}\n\n\tpublic void print(Object...objects) {\n\t\tfor (int i = 0; i < objects.length; i++) {\n\t\t\tif (i != 0)\n\t\t\t\twriter.print(' ');\n\t\t\twriter.print(objects[i]);\n\t\t}\n\t}\n\n public void printLine(Object...objects) {\n\t\tprint(objects);\n\t\twriter.println();\n\t}\n\n\tpublic void close() {\n\t\twriter.close();\n\t}\n\n\t}\n\n", "src_uid": "9fe9658db35076c0bddc8b7ddce11013"} {"source_code": "// practice with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF14E extends PrintWriter {\n\tCF14E() { super(System.out, true); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF14E o = new CF14E(); o.main(); o.flush();\n\t}\n\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tint t = sc.nextInt();\n\t\tlong[][][][][] dp = new long[n][t + 1][t][4][4];\n\t\tfor (int y0 = 0; y0 < 4; y0++)\n\t\t\tfor (int y1 = 0; y1 < 4; y1++)\n\t\t\t\tif (y0 != y1)\n\t\t\t\t\tdp[1][0][0][y0][y1] = 1;\n\t\tfor (int i = 1; i < n - 1; i++)\n\t\t\tfor (int h = 0; h <= t; h++)\n\t\t\t\tfor (int d = 0; d < t; d++)\n\t\t\t\t\tfor (int y0 = 0; y0 < 4; y0++)\n\t\t\t\t\t\tfor (int y1 = 0; y1 < 4; y1++) {\n\t\t\t\t\t\t\tlong x = dp[i][h][d][y0][y1];\n\t\t\t\t\t\t\tif (x == 0)\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\tfor (int y2 = 0; y2 < 4; y2++) {\n\t\t\t\t\t\t\t\tif (y2 == y1)\n\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\tif (y0 < y1 && y1 < y2 || y0 > y1 && y1 > y2) {\n\t\t\t\t\t\t\t\t\tdp[i + 1][h][d][y1][y2] += x;\n\t\t\t\t\t\t\t\t} else if (y0 < y1 && y1 > y2) {\n\t\t\t\t\t\t\t\t\tif (h + 1 <= t)\n\t\t\t\t\t\t\t\t\t\tdp[i + 1][h + 1][d][y1][y2] += x;\n\t\t\t\t\t\t\t\t} else if (y0 > y1 && y1 < y2) {\n\t\t\t\t\t\t\t\t\tif (d + 1 < t)\n\t\t\t\t\t\t\t\t\t\tdp[i + 1][h][d + 1][y1][y2] += x;\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\tlong ans = 0;\n\t\tfor (int y0 = 0; y0 < 4; y0++)\n\t\t\tfor (int y1 = 0; y1 < 4; y1++)\n\t\t\t\tans += dp[n - 1][t][t - 1][y0][y1];\n\t\tprintln(ans);\n\t}\n}\n", "src_uid": "6d67559744583229455c5eafe68f7952"} {"source_code": "/*\n ID: tommatt1\n LANG: JAVA\n TASK: \n*/\nimport java.util.*;\nimport java.io.*;\npublic class cf1237e{\n\n\tpublic static void main(String[] args)throws IOException {\n\t\tPrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\t\tBufferedReader bf=new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st=new StringTokenizer(bf.readLine());\n\t\tint n=Integer.parseInt(st.nextToken());\n\t\tint x=1;\n\t\twhile(x<=n) {\n\t\t\tif(n==x||n==x+1) {\n\t\t\t\tout.println(1);\n\t\t\t\tout.close();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif((x&1)==0) {\n\t\t\t\tx=2*x+1;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tx=2*x+2;\n\t\t\t}\n\t\t}\n\t\tout.println(0);\n\t\tout.close();\n\t}\n\n}\n", "src_uid": "821409c1b9bdcd18c4dcf35dc5116501"} {"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.System.exit;\nimport static java.util.Arrays.sort;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.Comparator;\nimport java.util.StringTokenizer;\n\npublic class B3 {\n\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n\n\tstatic void solve() throws Exception {\n\t\twhile (nextInt() != 0) {\n\t\t\tint n = nextInt();\n\t\t\tfinal int pi[] = new int[n];\n\t\t\tfinal int pj[] = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tpi[i] = nextInt();\n\t\t\t\tpj[i] = nextInt();\n\t\t\t}\n\t\t\tint startPoint = 0, startI = pi[0], startJ = pj[0];\n\t\t\tfor (int i = 1; i < n; i++) {\n\t\t\t\tif (pi[i] < startI || (pi[i] == startI && pj[i] < startJ)) {\n\t\t\t\t\tstartPoint = i;\n\t\t\t\t\tstartI = pi[i];\n\t\t\t\t\tstartJ = pj[i];\n\t\t\t\t}\n\t\t\t}\n\t\t\tInteger idx[] = new Integer[n - 1];\n\t\t\tfor (int i = 0, j = 0; i < n; i++) {\n\t\t\t\tif (i != startPoint) {\n\t\t\t\t\tidx[j++] = i;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfinal int fStartI = startI, fStartJ = startJ;\n\t\t\tsort(idx, new Comparator<Integer>() {\n\t\t\t\tpublic int compare(Integer o1, Integer o2) {\n\t\t\t\t\tint i1 = pi[o1] - fStartI, j1 = pj[o1] - fStartJ;\n\t\t\t\t\tint i2 = pi[o2] - fStartI, j2 = pj[o2] - fStartJ;\n\t\t\t\t\tint c = Long.compare((long) j1 * i2, (long) i1 * j2);\n\t\t\t\t\tif (c != 0) {\n\t\t\t\t\t\treturn c;\n\t\t\t\t\t}\n\t\t\t\t\treturn i1 + abs(j1) - (i2 + abs(j2));\n\t\t\t\t}\n\t\t\t});\n\t\t\tint hull[] = new int[n];\n\t\t\tint hullSize = 1;\n\t\t\thull[0] = startPoint;\n\t\t\tfor (int i: idx) {\n\t\t\t\tint ni = pi[i], nj = pj[i];\n\t\t\t\twhile (hullSize >= 2) {\n\t\t\t\t\tint cur = hull[hullSize - 1];\n\t\t\t\t\tint ci = pi[cur], cj = pj[cur];\n\t\t\t\t\tint old = hull[hullSize - 2];\n\t\t\t\t\tint oi = pi[old], oj = pj[old];\n\t\t\t\t\tif ((long) (nj - cj) * (ci - oi) > (long) (ni - ci) * (cj - oj)) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\t--hullSize;\n\t\t\t\t}\n\t\t\t\thull[hullSize++] = i;\n\t\t\t}\n\t\t\tint ansX[] = new int[hullSize], ansY[] = new int[hullSize];\n\t\t\tint ansSize = 0;\n\t\t\tint start = 0, startX = pi[hull[0]], startY = pj[hull[0]];\n\t\t\tfor (int i = 1; i < hullSize; i++) {\n\t\t\t\tint cx = pi[hull[i]], cy = pj[hull[i]];\n\t\t\t\tif (cx < startX || (cx == startX && cy < startY)) {\n\t\t\t\t\tstart = i;\n\t\t\t\t\tstartX = cx;\n\t\t\t\t\tstartY = cy;\n\t\t\t\t}\n\t\t\t}\n//\t\t\tSystem.err.println(startX + \" \" + startY);\n//\t\t\tSystem.err.println(hullSize);\n//\t\t\tfor (int i = 0; i < hullSize; i++) {\n//\t\t\t\tSystem.err.println((1 + pj[hull[i]]) + \" \" + (m - pi[hull[i]]));\n//\t\t\t}\n\t\t\tint q = 0;\n\t\t\tfor (int i = start;;) {\n//\t\t\t\tSystem.err.println(i + \" \" + (1 + pj[hull[i]]) + \" \" + (m - pi[hull[i]]) + \" \" + q);\n\t\t\t\tansX[ansSize] = pi[hull[i]] + ADDX[q];\n\t\t\t\tansY[ansSize] = pj[hull[i]] + ADDY[q];\n\t\t\t\tif (ansSize == 0 || ansX[ansSize] != ansX[ansSize - 1] || ansY[ansSize] != ansY[ansSize - 1]) {\n\t\t\t\t\t++ansSize;\n\t\t\t\t}\n\t\t\t\tint j = i;\n\t\t\t\ti = (i + hullSize - 1) % hullSize;\n\t\t\t\tif (i == start) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (pi[hull[i]] == pi[hull[j]] || pj[hull[i]] == pj[hull[j]]) {\n\t\t\t\t\t++q;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (ansX[ansSize - 1] == ansX[0] && ansY[ansSize - 1] == ansY[0]) {\n\t\t\t\t--ansSize;\n\t\t\t}\n\t\t\tout.println(ansSize);\n\t\t\tfor (int i = 0; i < ansSize; i++) {\n\t\t\t\tout.println(ansX[i] + \" \" + ansY[i]);\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic final int ADDX[] = {0, 0, -1, -1, 0};\n\tstatic final int ADDY[] = {0, -1, -1, 0, 0};\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}", "src_uid": "5e1847193148c4e6a998c61f8db61670"} {"source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Solution implements Runnable {\n\t\n\tstatic final long MODULO = 1000000007;\n\n\tvoid solve() throws Exception {\n\t\tString from = nextToken(), to = nextToken();\n\t\tint operations = nextInt();\n\t\tint n = from.length();\n\t\tboolean[] isGoodStart = new boolean[n];\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tString cut = from.substring(i) + from.substring(0, i);\n\t\t\tisGoodStart[i] = cut.equals(to);\n\t\t}\n\t\tlong goodCount = 0;\n\t\tfor (boolean a : isGoodStart) {\n\t\t\tif (a) {\n\t\t\t\t++goodCount;\n\t\t\t}\n\t\t}\n\t\tlong badCount = n - goodCount;\n\t\tlong[][] ways = new long[2][2];\n\t\tint cur = 0, ne = 1;\n\t\tif (isGoodStart[0]) {\n\t\t\t++ways[cur][1];\n\t\t} else {\n\t\t\t++ways[cur][0];\n\t\t}\n\t\tfor (int op = 0; op < operations; ++op) {\n\t\t\tArrays.fill(ways[ne], 0);\n\t\t\tways[ne][0] = (ways[cur][0] * (badCount - 1)) % MODULO + (ways[cur][1] * badCount) % MODULO;\n\t\t\tways[ne][0] %= MODULO;\n\t\t\tways[ne][1] = (ways[cur][1] * (goodCount - 1)) % MODULO + (ways[cur][0] * goodCount) % MODULO;\n\t\t\tways[ne][1] %= MODULO;\n\t\t\tcur ^= 1;\n\t\t\tne ^= 1;\n\t\t}\n\t\tout.print(ways[cur][1]);\n\t}\n\t\n\tpublic void run() {\n\t\ttry {\n\t\t\tsolve();\n\t\t} catch (Exception e) {\n\t\t\tNOO(e);\n\t\t} finally {\n\t\t\tout.close();\n\t\t}\n\t}\n\t\n\tlong nextLong() {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\t\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\t\n\tint nextInt() {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\t\n\tString nextToken() {\n\t\twhile (!stringTokenizer.hasMoreTokens()) {\n\t\t\tString line = null;\n\t\t\ttry {\n\t\t\t\tline = in.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\tNOO(e);\n\t\t\t}\n\t\t\tif (line == null) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tstringTokenizer = new StringTokenizer(line);\n\t\t}\n\t\treturn stringTokenizer.nextToken();\n\t}\n\t\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer stringTokenizer;\n\t\n\tvoid NOO(Exception e) {\n\t\te.printStackTrace();\n\t\tSystem.exit(42);\n\t}\n\t\n\tpublic Solution(String name) {\n\t\ttry {\n\t\t\tin = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\tout = new PrintWriter(new FileWriter(\"output.txt\"));\n\t\t\tstringTokenizer = new StringTokenizer(\"\");\n\t\t} catch (Exception e) {\n\t\t\tNOO(e);\n\t\t}\n\t}\n\t\n\tpublic Solution() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tstringTokenizer = new StringTokenizer(\"\");\n\t\t} catch (Exception e) {\n\t\t\tNOO(e);\n\t\t}\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tLocale.setDefault(Locale.US);\n\t\tnew Solution().run();\n\t}\n}\n", "src_uid": "414000abf4345f08ede20798de29b9d4"} {"source_code": "//package ;\nimport java.io.*;\nimport java.util.*;\n\npublic class D\n{\n\tpublic static void main(String[] args) throws IOException \n\t{\n\t\tScanner sc = new Scanner();\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\tint n=sc.nextInt();\n\t\tHashSet<Long>hs=new HashSet<>();\n\t\tif(n<=13)\n\t\t{\tfor(int i=0;i<=n;i++)\n\t\t\t\tfor(int j=0;j+i<=n;j++)\n\t\t\t\t\tfor(int k=0;k+j+i<=n;k++)\n\t\t\t\t\t\tfor(int z=0;z+k+j+i<=n;z++)\n\t\t\t\t\t\t\tif(z+k+j+i==n)\n\t\t\t\t\t\t\t\ths.add((long)z*1 + (long)k*5 +(long)j*10 + (long)i*50);\n\t\t\tSystem.out.println(hs.size());\n\t\t}\t\n\t\telse\n\t\t{\n\t\t\tlong m=(long)(n-13)*49;\n\t\t\tSystem.out.println(390+m);\n\t\t}\n\t\tpw.close(); \n\t}\n\tstatic class Scanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\t\n\t\tScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\t\t\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\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\t\t\n\t\tint nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\t\n\t\tlong nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\t\n\t\tdouble nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\t\n\t\tString nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\t\tboolean hasnext() throws IOException{\n\t\t\treturn br.ready();\n\t\t}\n\t\t\n\t}\n}\n", "src_uid": "75ec99318736a8a1b62a8d51efd95355"} {"source_code": "\nimport java.util.*;\n\n\npublic class caps {\n\tpublic static void main(String[] args) \n\t{\n\tScanner in= new Scanner( System.in);\n\tString a= in.next();\n\tint state =0;\n\tfor(int i = 0; i<a.length();i++)\n\t{\n\t\tif(state==0&&a.charAt(i)=='h')\n\t\t{\n\t\t\tstate=1;\n\t\t}\n\t\tif(state ==1 && a.charAt(i)=='e')\n\t\t{\n\t\t\tstate=2;\n\t\t}\n\t\tif(state ==2 && a.charAt(i)=='l')\n\t\t{\n\t\t\tstate=3;\n\t\t}\n\t\telse if(state ==3 && a.charAt(i)=='l')\n\t\t{\n\t\t\tstate=4;\n\t\t}\n\t\tif(state ==4 && a.charAt(i)=='o')\n\t\t{\n\t\t\tstate=5;\n\t\t\tbreak;\n\t\t}\n\n\t\t\n\t}\n\tif(state >= 5)\n\t{\n\t\tSystem.out.println(\"YES\");\n\t}\n\telse\n\t{\n\t\tSystem.out.println(\"NO\");\n\t}\n\t}\n}", "src_uid": "c5d19dc8f2478ee8d9cba8cc2e4cd838"} {"source_code": "import java.util.Scanner;\nimport java.io.IOException;\n\npublic class IOI{\n\tpublic static void main(String args[]){\n\t\tint a,b,c,d,e,n,m,k;\n\t\tScanner in=new Scanner(System.in);\n\t\tn=in.nextInt(); m=in.nextInt();\n\t\tk=in.nextInt();\n\t\te=0;\n\t\td=0;\n\t\tint ar[]=new int[10000];\n\t\tfor(a=0;;a++){\n\t\t\td++;\n\t\t\tif(((n*m)%2)==1) ar[d]=(n*m)/2 +1 ;\n\t\t\telse ar[d]=(n*m)/2;\n\t\t\tn=n-2;\n\t\t\tm=m-2;\n\t\t\tif(d==k+1) break;\n\t\t\tif(n<=0 || m<=0) break;\n\t\t}\n\t\tif(k>d) e=0;\n\t\telse e=ar[k]-ar[k+1];\n\t\tSystem.out.println(e+\"\");\n\t}\n}\n", "src_uid": "fa1ef5f9bceeb7266cc597ba8f2161cb"} {"source_code": "//package tes7;\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 P15 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni();\n\t\tint mod = 1000000009;\n\t\tlong[] dp = new long[n+1];\n\t\tif(5 <= n)dp[5] = 5;\n\t\tfor(int i = 7;i <= n;i+=2){\n\t\t\tdp[i] = ((dp[i-2] + 1) * 2L + 1) % mod;\n\t\t}\n\t\t\n\t\tlong ret = 1;\n\t\tfor(int i = n;i >= 3;i--){\n\t\t\tif(dp[i] == 0){\n\t\t\t\tret = ret + 2;\n\t\t\t\tif(ret >= mod)ret -= mod;\n\t\t\t}else{\n\t\t\t\tret = ((ret+1)*dp[i]+1) % mod;\n\t\t\t}\n\t\t}\n\t\tret = ((ret+1)*(ret+1)+1)%mod;\n\t\tout.println(ret*2%mod);\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 P15().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", "src_uid": "dbcb1077e7421554ba5d69b64d22c937"} {"source_code": "import java.util.Scanner;\npublic class A {\n\tpublic static void main(String args[]) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tString result = \"\";\n\t\tString binary = Integer.toBinaryString(n);\n\t\t// System.out.println(binary);\n\t\tint power = binary.length();\n\t\tfor (int x = 0; x < binary.length(); ++x) {\n\t\t\tif (binary.charAt(x) == '1') {\n\t\t\t\tresult += power + \" \";\n\t\t\t}\n\t\t\tpower--;\n\t\t}\n\t\tSystem.out.println(result.substring(0,result.length()-1));\n\t}\n}", "src_uid": "757cd804aba01dc4bc108cb0722f68dc"} {"source_code": "import java.io.*;\nimport java.util.*;\npublic class Solution\n{\n static int N,M;\n static long K;\n static Quad A[];\n static long dp[][][];\n static StringBuilder sb=new StringBuilder();\n public static void main(String ag[])throws Exception\n {\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n int i,j,k;\n \n String ip1[]=br.readLine().split(\" \");\n \n N=Integer.parseInt(ip1[0]);\n M=Integer.parseInt(ip1[1]);\n K=Integer.parseInt(ip1[2]);\n \n A=new Quad[M];\n for(i=0;i<M;i++)\n {\n String ip2[]=br.readLine().split(\" \");\n A[i]=new Quad(Long.parseLong(ip2[0]),Long.parseLong(ip2[1]),Integer.parseInt(ip2[2]),i+1);\n }\n Arrays.sort(A,new Tcomp());\n dp=new long[N+1][M][101];\n for(i=0;i<=N;i++)\n for(j=0;j<M;j++)\n for(k=0;k<101;k++)\n dp[i][j][k]=-1;\n \n long ans=-(long)1e18;\n for(i=0;i<M;i++)\n {\n for(long jj=A[i].a;jj<=A[i].b;jj++)\n {\n ans=Math.max(ans,jj+find(1,i,(int)(jj-A[i].a)));\n }\n }\n if(ans<0)\n {\n System.out.println(\"NO\");\n return;\n }\n boolean flag=false;\n for(i=0;i<M;i++)\n {\n for(long jj=A[i].a;jj<=A[i].b;jj++)\n {\n if(ans==(jj+find(1,i,(int)(jj-A[i].a))))\n {\n sb.append(A[i].id+\" \"+jj+\"\\n\");\n trace(1,i,(int)(jj-A[i].a));\n flag=true;\n break;\n }\n }\n if(flag)\n break;\n }\n System.out.println(\"YES\");\n System.out.println(sb);\n }\n public static long find(int day,int currId,int diff)\n {\n if(day==N)\n return 0L;\n \n if(dp[day][currId][diff]!=-1)\n return dp[day][currId][diff];\n \n long currValue=diff+A[currId].a;\n long total=-(long)1e18;\n for(int i=currId+1;i<M;i++)\n {\n if(A[currId].c==A[i].c)\n continue;\n if(currValue*K>=A[i].a&&currValue*K<=A[i].b)\n total=Math.max(total,currValue*K+find(day+1,i,(int)(currValue*K-A[i].a)));\n if(currValue+K>=A[i].a&&currValue+K<=A[i].b)\n total=Math.max(total,currValue+K+find(day+1,i,(int)(currValue+K-A[i].a)));\n }\n return dp[day][currId][diff]=total;\n }\n public static void trace(int day,int currId,int diff)\n {\n if(day==N)\n return;\n \n long currValue=diff+A[currId].a;\n long total=-(long)1e18;\n \n for(int i=currId+1;i<M;i++)\n {\n if(A[currId].c==A[i].c)\n continue;\n if(currValue*K>=A[i].a&&currValue*K<=A[i].b)\n total=Math.max(total,currValue*K+find(day+1,i,(int)(currValue*K-A[i].a)));\n if(currValue+K>=A[i].a&&currValue+K<=A[i].b)\n total=Math.max(total,currValue+K+find(day+1,i,(int)(currValue+K-A[i].a)));\n }\n \n for(int i=currId+1;i<M;i++)\n {\n if(A[currId].c==A[i].c)\n continue;\n if(currValue*K>=A[i].a&&currValue*K<=A[i].b&&total==currValue*K+find(day+1,i,(int)(currValue*K-A[i].a)))\n {\n sb.append(A[i].id+\" \"+(currValue*K)+\"\\n\");\n trace(day+1,i,(int)(currValue*K-A[i].a));\n return;\n }\n if(currValue+K>=A[i].a&&currValue+K<=A[i].b&&total==currValue+K+find(day+1,i,(int)(currValue+K-A[i].a)))\n {\n sb.append(A[i].id+\" \"+(currValue+K)+\"\\n\");\n trace(day+1,i,(int)(currValue+K-A[i].a));\n return;\n }\n }\n }\n}\nclass Quad \n{\n long a,b;\n int c,id;\n Quad(long S,long E,int C,int ID)\n {\n a=S;\n b=E;\n c=C;\n id=ID;\n }\n}\nclass Tcomp implements Comparator<Quad>\n{\n public int compare(Quad P,Quad Q)\n {\n return P.c-Q.c;\n }\n}", "src_uid": "c98fdad8e7ce09b8ac389108f72cecd9"} {"source_code": "//package javaCode.exercise;\n\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.Scanner;\n\npublic class Send {\n\tlong a, b;\n\n\tpublic Send(long a, long b) {\n\t\tthis.a = a;\n\t\tthis.b = b;\n\t}\n\n\tpublic Send() {\n\n\t}\n\n\tpublic static void end() {\n\t\tSystem.exit(0);\n\t}\n\n\tpublic static void main(String[] args) {\n\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = Integer.parseInt(sc.nextLine());\n\t\tif(n==1){\n\t\t\tSystem.out.println(\"Yes\");\n\t\t\tend();\n\t\t}\n\t\tchar[] arr = sc.nextLine().toCharArray();\n\t\tMap<Character, Integer> m = new HashMap<Character, Integer>();\n\t\tfor(int i=0;i<n;i++){\n\t\t\tif(m.containsKey(arr[i])){\n\t\t\t\tm.put(arr[i], m.get(arr[i])+1);\n\t\t\t}else{\n\t\t\t\tm.put(arr[i], 1);\n\t\t\t}\n\t\t}\n\t\tint cnt = 0;\n\t\tfor(char ch : m.keySet()){\n\t\t\tif(m.get(ch)>=2){\n\t\t\t\tcnt++;\n\t\t\t}\n\t\t}\n\t\tif(cnt!=0)\n\t\tSystem.out.println(\"Yes\");\n\t\telse\n\t System.out.println(\"No\");\n\t\tsc.close();\n\n\t}\n\n}", "src_uid": "6b22e93f7e429693dcfe3c099346dcda"} {"source_code": "import java.util.List;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.util.Arrays;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.util.ArrayList;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.math.BigInteger;\nimport java.util.Collections;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Crash\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tOutputWriter out = new OutputWriter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n\tpublic void solve(int testNumber, InputReader in, OutputWriter out) {\n\t\tint n = in.readInt();\n\t\tint d = in.readInt();\n\t\tint s = in.readInt();\n\t\tint[] c = new int[n];\n\t\tint[] f = new int[n];\n\t\tint[] l = new int[n];\n\t\tArrayList<Pair<Integer, Integer>> a = new ArrayList<Pair<Integer, Integer>>();\n\t\tArrayList<Pair<Integer, Integer>> b = new ArrayList<Pair<Integer, Integer>>();\n\t\tArrayList<Pair<Integer, Integer>> t = new ArrayList<Pair<Integer, Integer>>();\n\t\tfor (int i = 0; i < n; i ++) {\n\t\t\tc[i] = in.readInt();\n\t\t\tf[i] = in.readInt();\n\t\t\tl[i] = in.readInt();\n\t\t\tif (c[i] > 0 || l[i] < d) a.add(new Pair<Integer, Integer>(c[i], i));\n\t\t\tif (l[i] >= d && c[i] > 0) b.add(new Pair<Integer, Integer>(f[i], i));\n\t\t\tif (l[i] >= d && c[i] == 0) t.add(new Pair<Integer, Integer>(f[i], i));\n\t\t}\n\t\tCollections.sort(a);\n\t\tCollections.sort(b);\n\t\tCollections.sort(t);\n\t\tlong[] tt = new long[t.size() + 1];\n\t\ttt[0] = 0;\n\t\tfor (int i = 0; i < t.size(); i ++)\n\t\t\ttt[i + 1] = tt[i] + t.get(i).first;\n\t\tint cnt = 0, sum = 0;\n\t\tlong left = 0;\n\t\tboolean[] choose = new boolean[n];\n\t\tArrays.fill(choose, false);\n\t\tint p = a.size() - 1;\n\t\tint q = 0, sumT = 0;\n\t\twhile (q < t.size() && sumT + t.get(q).first <= s) {\n\t\t\tsumT += t.get(q).first;\n\t\t\tq ++;\n\t\t}\n\t\tPair<Integer, Integer> ans = new Pair<Integer, Integer>(q, -sumT);\n\t\tfor (int i = 0; i < b.size(); i ++) {\n\t\t\tPair<Integer, Integer> now = b.get(i);\n\t\t\tif (sum + now.first > s) break;\n\t\t\tsum += now.first;\n\t\t\tif (! choose[now.second]) {\n\t\t\t\tchoose[now.second] = true;\n\t\t\t\tleft += c[now.second];\n\t\t\t\tcnt ++;\n\t\t\t} else {\n\t\t\t\tleft ++;\n\t\t\t}\n\t\t\twhile (p >= 0) {\n\t\t\t\tif (! choose[a.get(p).second]) {\n\t\t\t\t\tif (left == 0) break;\n\t\t\t\t\tcnt ++;\n\t\t\t\t\tleft --;\n\t\t\t\t\tchoose[a.get(p).second] = true;\n\t\t\t\t\tleft += a.get(p).first;\n\t\t\t\t}\n\t\t\t\tp --;\n\t\t\t}\n\t\t\twhile (sum + sumT > s) {\n\t\t\t\tq --;\n\t\t\t\tsumT -= t.get(q).first;\n\t\t\t}\n\t\t\tlong tmp = Math.min(left, (long)t.size());\n\t\t\tif (q + tmp > t.size()) {\n\t\t\t\tPair<Integer, Integer> u = new Pair<Integer, Integer>(cnt + t.size(), -(sum + (int)tt[t.size() - (int)tmp]));\n\t\t\t\tif (u.compareTo(ans) > 0) ans = u;\n\t\t\t} else {\n\t\t\t\tPair<Integer, Integer> u = new Pair<Integer, Integer>(cnt + q + (int)tmp, -(sum + sumT));\n\t\t\t\tif (u.compareTo(ans) > 0) ans = u;\n\t\t\t}\n\t\t}\n\t\tout.printLine(ans.first, -ans.second);\n\t}\n}\n\nclass InputReader {\n\tprivate InputStream stream;\n\tprivate byte[] buf = new byte[1000];\n\tprivate int curChar;\n\tprivate int numChars;\n\n\tpublic InputReader(InputStream stream) {\n\t\tthis.stream = stream;\n\t}\n\n\tprivate int read() {\n\t\tif (numChars == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (curChar >= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n\n\tpublic int readInt() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tint res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tprivate boolean isSpaceChar(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n}\n\nclass OutputWriter {\n\tprivate final PrintWriter writer;\n\n\tpublic OutputWriter(OutputStream outputStream) {\n\t\twriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n\t}\n\n\tpublic OutputWriter(Writer writer) {\n\t\tthis.writer = new PrintWriter(writer);\n\t}\n\n\tpublic void print(Object...objects) {\n\t\tfor (int i = 0; i < objects.length; i++) {\n\t\t\tif (i != 0)\n\t\t\t\twriter.print(' ');\n\t\t\twriter.print(objects[i]);\n\t\t}\n\t}\n\n\tpublic void printLine(Object...objects) {\n\t\tprint(objects);\n\t\twriter.println();\n\t}\n\n\tpublic void close() {\n\t\twriter.close();\n\t}\n}\n\nclass Pair<T1 extends Comparable<T1>, T2 extends Comparable<T2>> implements Comparable<Pair<T1, T2>> {\n\tpublic T1 first;\n\tpublic T2 second;\n\n\tpublic boolean equals(Object o) {\n\t\tif (this == o) return true;\n\t\tif (o == null || getClass() != o.getClass()) return false;\n\n\t\tPair pair = (Pair) o;\n\n\t\tif (!first.equals(pair.first)) return false;\n\t\tif (!second.equals(pair.second)) return false;\n\n\t\treturn true;\n\t}\n\n\tpublic int hashCode() {\n\t\tint result = first.hashCode();\n\t\tresult = 31 * result + second.hashCode();\n\t\treturn result;\n\t}\n\n\tpublic Pair(T1 first, T2 second) {\n\t\tthis.first = first;\n\t\tthis.second = second;\n\t}\n\n\tpublic int compareTo(Pair<T1, T2> o) {\n\t\tif (first.compareTo(o.first) != 0) return first.compareTo(o.first);\n\t\treturn second.compareTo(o.second);\n\t}\n}\n\n", "src_uid": "e69f42403f3b0357e06a14523025b34a"} {"source_code": "// LUOGU_RID: 92601310\nimport java.util.Scanner;\r\n\r\npublic class CF1749D {\r\n\r\n private static long MAX = 998244353;\r\n\r\n public static void main(String[] args) {\r\n Scanner scanner = new Scanner(System.in);\r\n int a = scanner.nextInt();\r\n long b = scanner.nextLong();\r\n long ans = 0;\r\n long total = b;\r\n long last = 0;\r\n long min = 1;\r\n boolean flag = true;\r\n for (int i = 1;i <= a;i++) {\r\n if (i == 1) {\r\n last = b % MAX;\r\n ans += last;\r\n ans %= MAX;\r\n } else {\r\n if (flag) {\r\n // \u8ba1\u7b97\u65b0\u7684min\r\n if (zhi(i)) {\r\n if (min * i <= b) {\r\n min *= i;\r\n } else {\r\n flag = false;\r\n total = ((total % MAX) * (b % MAX) + b) % MAX;\r\n continue;\r\n }\r\n }\r\n last = (((b / min) % MAX) * last) % MAX;\r\n ans += last;\r\n ans %= MAX;\r\n }\r\n total = ((total % MAX) * (b % MAX) + b) % MAX;\r\n }\r\n }\r\n\r\n // 2^n - ans\r\n System.out.println(((total - ans) % MAX + MAX) % MAX);\r\n }\r\n\r\n private static boolean zhi(int i) {\r\n for (int j = 2;j * j <= i;j++) {\r\n if (i % j == 0) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n }\r\n}", "src_uid": "0fdd91ed33431848614075ebe9d2ee68"} {"source_code": "import javax.management.DynamicMBean;\nimport javax.print.DocFlavor;\nimport javax.print.attribute.HashAttributeSet;\nimport java.awt.*;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\nimport java.net.Inet4Address;\nimport java.nio.file.attribute.FileAttribute;\nimport java.time.DayOfWeek;\nimport java.time.LocalDate;\nimport java.time.Month;\nimport java.time.temporal.TemporalAdjusters;\nimport java.util.List;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\nimport java.util.*;\nimport java.util.Arrays;\nimport java.util.concurrent.Callable;\nimport java.time.DayOfWeek;\nimport java.time.LocalDate;\nimport java.time.Month;\nimport java.time.temporal.TemporalAdjusters;\n\n\n\npublic class Main {\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\n public static void main(String[] args) {\n FastReader sc = new FastReader();\n long u=sc.nextLong();\n long v=sc.nextLong();\n HashSet<Long> set=new HashSet<>();\n if(v<u || (v%2!=0 && u%2==0) || (v%2==0 && u%2!=0) ){\n System.out.println(-1);\n\n }\n else if(u==v && v!=0){\n System.out.println(1);\n System.out.println(u);\n }\n else if(v==u && v==0){\n System.out.println(0);\n }\n else{\n set.add(u);\n long value=(v-u)/2;\n if((u&value)!=0){\n System.out.println(3);\n System.out.print(u+\" \"+value+\" \"+value);\n }\n else{\n System.out.println(2);\n System.out.print((u+value)+\" \"+value);\n\n }\n }\n\n\n }\n\n\n\n}\n\n\n\n", "src_uid": "490f23ced6c43f9e12f1bcbecbb14904"} {"source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Codechef\n{\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t\t// your code goes here\n\t\tScanner sc=new Scanner(System.in);\n\t\tint a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt(),d=sc.nextInt();\n\t\t int m=(a-c)+(b-c)+c;\n\t\t if((a-c)<=d && (b-c)<=d && (a-c)>=0 && (b-c)>=0 && m>=0 && m<d)\n\t\t System.out.println(d-m);\n\t\t else\n\t\t System.out.println(\"-1\");\n\t}\n}", "src_uid": "959d56affbe2ff5dd999a7e8729f60ce"} {"source_code": "import java.io.IOException;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Problem315C {\n public static boolean[] primes = new boolean[2000000];\n public static int numPrimes;\n public static int numPals;\n public static boolean[] pals = new boolean[2000000];\n \n public static int sieve(double p, double q){\n \n Arrays.fill(primes, true);\n primes[0]=false;\n primes[1]=false;\n int i = 2;\n int max = 1;\n for(;i<2000000;i++){\n if(isPalindrome(i))\n numPals++;\n if(primes[i]){\n for(int j=2;j*i<2000000;j++){\n primes[i*j]=false;\n }\n // System.out.println(i + \" is Prime\");\n numPrimes++;\n }\n \n if(numPrimes <= numPals*p/q){\n max = i;\n // System.out.println( (double)numPrimes/ numPals);\n }\n \n }\n return max;\n }\n \n public static boolean isPalindrome(int a){\n String s = \"\"+a;\n for(int i =0;i<=s.length()-1;i++){\n if(s.charAt(i) != s.charAt(s.length()-1-i))\n return false;\n }\n // System.out.println(a + \" is Palindrome\");\n return true;\n }\n \n public static void main (String[] args)throws IOException{\n Scanner in = new Scanner(System.in);\n int p = in.nextInt();\n int q = in.nextInt();\n numPrimes = 0;\n numPals = 1;\n Arrays.fill(primes,true);\n System.out.println(sieve(p,q));\n \n \n }\n}", "src_uid": "e6e760164882b9e194a17663625be27d"} {"source_code": "import java.util.*;\npublic class Main{\n public static void factorize(Map<Integer,Integer> map,int n){\n for(int i=2;i<=Math.sqrt(n);i++){\n while(n%i==0){\n if(map.containsKey(i)){\n int x=map.get(i);\n map.put(i,x+1);\n }else{\n map.put(i,1);\n }\n n=n/i;\n }\n }\n if(n!=1){\n map.put(n,1);\n }\n }\n public static void main(String[] args){\n Scanner s=new Scanner(System.in);\n int n=s.nextInt();\n Map<Integer,Integer> map=new HashMap<>();\n factorize(map,n);\n int max=0;\n long k=1;\n for(Map.Entry<Integer,Integer> entry:map.entrySet()){\n int x=entry.getValue();\n k=k*entry.getKey();\n // System.out.println(x);\n if(x>max) max=x;\n }\n int num=1,i=1;\n while(i<31){\n num=1<<i;\n if(max/num <=1) break;\n i++;\n \n }\n if(max%num!=0) i=i+1;\n // System.out.println(max+\" \"+i);\n boolean shit=true;\n for(Map.Entry<Integer,Integer> entry:map.entrySet()){\n int x=entry.getValue();\n \n if(x!=max) shit=false;\n }\n if(!shit || max%num!=0) i=i+1;\n if(k==n) i=0;\n System.out.println(k+\" \"+i);\n }\n}", "src_uid": "212cda3d9d611cd45332bb10b80f0b56"} {"source_code": "import java.util.*;\nimport java.util.LinkedList;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class tmp {\n public static void main(String [] args) throws Exception{\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer st = new StringTokenizer(in.readLine());\n StringBuilder sb = new StringBuilder();\n \n String s = st.nextToken();\n String t = in.readLine();\n \n int len = s.length(),ind=0;\n boolean ok = false;\n for(int i=0; i<len; i++){\n \n if(t.charAt(i) - s.charAt(i) > 1){\n System.out.println(s.substring(0,i) + (char)(s.charAt(i)+1) + s.substring(i+1));\n return;\n }else if(t.charAt(i) - s.charAt(i) > 0 && !ok){\n ok = true;\n ind = i;\n }else if(ok && s.charAt(i) < 'z'){\n System.out.println(s.substring(0,i) + \"z\" + s.substring(i+1));\n return;\n }else if(ok && t.charAt(i) > 'a'){\n System.out.println(t.substring(0,ind) + t.charAt(ind) + t.substring(ind+1,i) + \"a\" + t.substring(i+1));\n return;\n }\n }\n System.out.println(\"No such string\");\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n }\n \n \n\n \n \n \n \n \n\n\n \n \n \n \n}\n\n \nclass P implements Comparable<P>{\n int val, idx;\n public P(int val, int idx){\n this.val = val;\n this.idx = idx;\n }\n\n public int compareTo(P other){\n if (this.val != other.val) return -this.val + other.val;\n return this.idx - other.idx;\n }\n}", "src_uid": "47618510d2a17b1cc1e6a688201d51a3"} {"source_code": "import java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class Main {\n\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\n\tprivate static final long M = 1000000007L;\n\n\tvoid solve() {\n\t\tint n = ni();\n\t\tint[] a = na(n);\n\t\tint ans = 0;\n\t\tint MAX = Integer.MAX_VALUE / 200;\n\t\tint[][] d = new int[][] { { 0, 3, 4 }, { 3, 0, MAX }, { 4, MAX, 0 }, };\n\t\tfor (int i = 1; i < n && ans < MAX; i++) {\n\t\t\tans += d[a[i] - 1][a[i - 1] - 1];\n\t\t\tif (i >= 2 && a[i] == 2 && a[i-1] == 1 && a[i-2] == 3)\n\t\t\t\tans--;\n\t\t}\n\t\tif (ans >= MAX)\n\t\t\tout.println(\"Infinite\");\n\t\telse {\n\t\t\tout.println(\"Finite\");\n\t\t\tout.println(ans);\n\t\t}\n\t}\n\n\tvoid run() throws Exception {\n\t\tis = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\tif (!INPUT.isEmpty())\n\t\t\ttr(System.currentTimeMillis() - s + \"ms\");\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tnew Main().run();\n\t}\n\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\n\tprivate int readByte() {\n\t\tif (lenbuf == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (ptrbuf >= lenbuf) {\n\t\t\tptrbuf = 0;\n\t\t\ttry {\n\t\t\t\tlenbuf = is.read(inbuf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (lenbuf <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\n\tprivate boolean isSpaceChar(int c) {\n\t\treturn !(c >= 33 && c <= 126);\n\t}\n\n\tprivate int skip() {\n\t\tint b;\n\t\twhile ((b = readByte()) != -1 && isSpaceChar(b))\n\t\t\t;\n\t\treturn b;\n\t}\n\n\tprivate double nd() {\n\t\treturn Double.parseDouble(ns());\n\t}\n\n\tprivate char nc() {\n\t\treturn (char) skip();\n\t}\n\n\tprivate String ns() {\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != '\n\t\t\t\t\t\t\t\t\t// ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\n\tprivate char[] ns(int n) {\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile (p < n) {\n\t\t\tif (!(isSpaceChar(b)))\n\t\t\t\tbuf[p++] = (char) b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\n\tprivate char[][] nm(int n, int m) {\n\t\tchar[][] map = new char[n][];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tmap[i] = ns(m);\n\t\treturn map;\n\t}\n\n\tprivate int[] na(int n) {\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = ni();\n\t\treturn a;\n\t}\n\n\tprivate int[][] na(int n, int m) {\n\t\tint[][] a = new int[n][];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\ta[i] = na(m);\n\t\treturn a;\n\t}\n\n\tprivate int ni() {\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t;\n\t\tif (b == '-') {\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\n\tprivate long nl() {\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))\n\t\t\t;\n\t\tif (b == '-') {\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\n\t\twhile (true) {\n\t\t\tif (b >= '0' && b <= '9') {\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t} else {\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\n\tprivate static void tr(Object... o) {\n\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n}\n", "src_uid": "6c8f028f655cc77b05ed89a668273702"} {"source_code": "import java.util.Scanner;\n\npublic class Test {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n\n String s = in.next();\n StringBuilder sb = new StringBuilder();\n\n char c = 'a';\n\n for (int i = 0; i < s.length(); i++) {\n if (s.charAt(i) > c || c > 'z') {\n sb.append(s.charAt(i));\n } else {\n sb.append(c);\n c++;\n }\n }\n\n if (c > 'z')\n System.out.println(sb);\n else\n System.out.println(-1);\n\n }\n}\n", "src_uid": "f8ad543d499bcc0da0121a71a26db854"} {"source_code": "import java.util.Scanner;\n\npublic class Solution\n{\n public static void main(String[] args)\n {\n Scanner sc = new Scanner(System.in);\n long n = sc.nextLong();\n long m = sc.nextLong();\n long k = sc.nextLong();\n long square = 1;\n \n if (k > (n + m - 2))\n {\n System.out.println(-1);\n return;\n }\n\n long stepOneCut = 0;\n long stepTwoCut = 0;\n \n if ((k < n ) && (k < m))\n {\n stepOneCut = m / (k + 1) * n;\n stepTwoCut = n / (k + 1) * m;\n if (stepOneCut > stepTwoCut)\n System.out.println(stepOneCut);\n else\n System.out.println(stepTwoCut);\n return;\n }\n \n if ((k >= n ) && (k >= m))\n {\n stepOneCut = m / (k + 2 - n);\n stepTwoCut = n / (k + 2 - m);\n if (stepOneCut > stepTwoCut)\n System.out.println(stepOneCut);\n else\n System.out.println(stepTwoCut);\n return;\n }\n \n if (k >= n)\n {\n stepOneCut = m / (k + 2 - n);\n stepTwoCut = m / (k + 1) * n;\n }\n else\n {\n stepOneCut = n / (k + 2 - m);\n stepTwoCut = n / (k + 1) * m;\n }\n if (stepOneCut > stepTwoCut)\n System.out.println(stepOneCut);\n else\n System.out.println(stepTwoCut);\n return;\n\n }\n}\n", "src_uid": "bb453bbe60769bcaea6a824c72120f73"} {"source_code": "//codeforces 700\n import java.io.*;\n import java.util.*;\n import java.util.Arrays;\n import static java.lang.System.out;\n public class Key_races\n {\n public static void main(String args[])\n {\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 out.println((2*t1 + v1*s) == (2*t2 + v2*s)? \"Friendship\" :((2*t1 + v1*s) > (2*t2 + v2*s)) ?\"Second\":\"First\");\n \n }//main ends\n }//class ends", "src_uid": "10226b8efe9e3c473239d747b911a1ef"} {"source_code": "import java.util.*;\n\npublic class a {\n\tpublic static void main(String[] argrs) {\n\t\tScanner in = new Scanner(System.in);\n\t\tlong[] v = new long[3];\n\t\tfor(int i=0; i<3; i++)\n\t\t\tv[i] = in.nextLong();\n\t\tlong k = in.nextLong();\n\t\tArrays.sort(v);\n\t\tlong[] c = new long[3];\n\t\tif(k >= 3*(v[0]-1)) {\n\t\t\tfor(int i=0; i<3; i++)\n\t\t\t\tc[i] += v[0]-1;\n\n\t\t\tk -= 3*(v[0]-1);\n\t\t}\n\t\telse {\n\t\t\tfor(int i=0; i<3; i++)\n\t\t\t\tc[i] += k/3;\n\t\t\tk -= 3*(k/3);\n\t\t\tfor(int i=0; i<3; i++) {\n\t\t\t\tif(k>0) {\n\t\t\t\t\tc[i]++;\n\t\t\t\t\tk--;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif(k >= 2*(v[1]-v[0])) {\n\t\t\tfor(int i=1; i<3; i++)\n\t\t\t\tc[i] += v[1]-v[0];\n\n\t\t\tk -= 2*(v[1]-v[0]);\n\t\t}\n\t\telse {\n\t\t\tfor(int i=1; i<3; i++)\n\t\t\t\tc[i] += k/2;\n\t\t\tk -= 2*(k/2);\n\t\t\tif(k > 0) {\n\t\t\t\tc[1]++;\n\t\t\t\tk--;\n\t\t\t}\n\t\t}\n\t\tc[2] += Math.min(v[2]-v[1],k);\n\t\t\n\t\tc[0]++;\n\t\tc[1]++;\n\t\tc[2]++;\n\n\t\tlong res = c[0]*c[1]*c[2];\n\n\t\tSystem.out.println(res);\n\t}\n}\n", "src_uid": "8787c5d46d7247d93d806264a8957639"} {"source_code": "import java.math.BigInteger;\nimport java.util.Scanner;\n\npublic class CF630I{\n static BigInteger choose(int a, int b){\n BigInteger ret = BigInteger.ONE;\n for (int i=0; i<b; i++){\n ret = ret.multiply(BigInteger.valueOf(a-i));\n }\n for (int i=1; i<=b; i++){\n ret = ret.divide(BigInteger.valueOf(i));\n }\n return ret;\n }\n\n public static void main(String[] args){\n Scanner scn = new Scanner(System.in);\n while (scn.hasNext()){\n int n = scn.nextInt();\n BigInteger ans = BigInteger.valueOf(6).multiply(BigInteger.valueOf(4).pow(n-2));\n if (n>3){\n ans = ans.add(BigInteger.valueOf(n-3).multiply(BigInteger.valueOf(9)).multiply(BigInteger.valueOf(4).pow(n-3)));\n }\n System.out.println(ans);\n }\n }\n}", "src_uid": "3b02cbb38d0b4ddc1a6467f7647d53a9"} {"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 ComputerGame3 {\n\n\tstatic double[][] identity;\n\tstatic double INF = 1e18D;\n\tstatic int MAXPOW = 39;\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[] PA = 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\tPA[i] = P[i]*A[i];\n\t\t\tV = Math.max(V, P[i]*B[i]);\n\t\t}\n\t\n\t\tConvexHullLinear cht = new ConvexHullLinear(N, -1, 0, true);\n\t\tInteger order[] = new Integer[N];\n\t\tfor(int i = 0; i < N; i++) order[i] = i;\n\t\tArrays.sort(order, (a,b) -> {\n\t\t\tif(P[a] == P[b]) return -Double.compare(PA[a], PA[b]);\n\t\t\treturn Double.compare(P[a], P[b]);\n\t\t});\n\t\tfor(int i = N-1; i >= 0; i--) {\n\t\t\tint id = order[i];\n\t\t\tcht.add(P[id], PA[id], id);\n\t\t}\n\t\tidentity = identity(3);\n\t\t\n//\t\tfor(int i = 0; i <= cht.s; i++) System.out.print(cht.is[i]+\" \");\n//\t\tSystem.out.println();\n\t\t\n\t\tdouble vec[][] = new double[][]{{0}, {0}, {1}}; //prevDp, prevT, prev1\n\t\tfor(int l = cht.s; l >= 0; l--) {\n\t\t\tdouble stopAt = l == 0 ? INF : cht.intersect(l, l-1);\n\t\t\tint id = cht.is[l];\n\t\t\t\t\t\t\n\t\t\tdouble mat[][] = new double[][] {\n\t\t\t\t{1-P[id], P[id]*V, P[id]*A[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\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)(Math.round(nextVec[1][0]));\n\t\t\t\tdouble dpt = nextVec[0][0];\n\t\t\t\tdouble prevDp = (dpt-P[id]*V*(t-1)-P[id]*A[id])/(1-P[id]);\n\t\t\t\tdouble lastQuery = V*(t-1)-prevDp;\n\t\t\t\t\t\t\t\t\n\t\t\t\tboolean bad = (t > T) || (lastQuery > 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\t/*Linear version of Convex hull optimization. Written by Joshua Fair\n\tConstructor(a, b, c, d):\n\ta = max number of lines that will be added\n\tb = 1 if lines are added in increasing order and -1 if added in decreasing order\n\tc =\n\t\t-1 if points are queried in order from large X to small X\n\t\t0 if the query points are in no specific order\n\t\t1 if the points are queries in order from small X to large X\n\td = true if the queries are max, and false if the queries are min\n\t!!! If you add lines in one order and query points in the opposite order, it will only be linear if all lines are \n\tadded before any points are queried !!!\n\t*/\n\tstatic class ConvexHullLinear{\n\t\tboolean upd, isMin;\n\t\tint type, inc, s, p;\n\t\tdouble[] ms,bs;\n\t\tint[] is;\n\t\tpublic ConvexHullLinear(int numLines, int ii, int tt, boolean mm) {\n\t\t\ts = -1;\n\t\t\tp = 0;\n\t\t\tms = new double[numLines];\n\t\t\tbs = new double[numLines];\n\t\t\tis = new int[numLines];\n\t\t\tinc = ii;\n\t\t\ttype = tt;\n\t\t\tisMin = !mm;\n\t\t\tupd = false;\n\t\t\tif(isMin) inc = -inc;\n\t\t}\n\t\tpublic void add(double m, double b, int i) {\n\t\t\tif(isMin) { m=-m; b=-b; }\n\t\t\tupd = true;\n\t\t\ts++;\n\t\t\tms[s] = m;\n\t\t\tbs[s] = b;\n\t\t\tis[s] = i;\n\t\t\twhile((s > 0 && ms[s] == ms[s-1] && bs[s] >= bs[s-1])\n\t\t\t\t\t|| (s-2 >= 0 && bad(s-2,s-1,s))) {\n\t\t\t\tms[s-1] = m;\n\t\t\t\tbs[s-1] = b;\n\t\t\t\tis[s-1] = i;\n\t\t\t\ts--;\n\t\t\t}\n\t\t}\n\t\tpublic boolean bad(int l1, int l2, int l3) {\n\t\t\tif(inc == 1) return intersect(l2,l3) <= intersect(l1,l2);\n\t\t\treturn intersect(l2,l3) >= intersect(l1,l2);\n\t\t}\n\t\tpublic boolean eqq(int l1, int l2) {\n\t\t\treturn eq(ms[l1], ms[l2]) && eq(bs[l1], bs[l2]);\n\t\t}\n\t\tpublic boolean eq(double a, double b) {\n\t\t\treturn Math.abs(a-b) < 1e-10;\n\t\t}\n\t\tpublic double intersect(int l1, int l2) {\n\t\t\treturn (double)(bs[l2]-bs[l1])/(double)(ms[l1]-ms[l2]);\n\t\t}\n\t\tpublic double eval(int l1, double x) { \n\t\t\treturn ms[l1]*x + bs[l1]; \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", "src_uid": "64e378664209cf1933cf082493a0875c"} {"source_code": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n \npublic class Main\n{\n \n static class InputReader {\n\n\t\tprivate final InputStream stream;\n\t\tprivate final byte[] buf = new byte[8192];\n\t\tprivate int curChar, snumChars;\n\n\t\tpublic InputReader(InputStream st) {\n\t\t\tthis.stream = st;\n\t\t}\n\n\t\tpublic int read() {\n\t\t\tif (snumChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= snumChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tsnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (snumChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\t\tpublic int ni() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo {\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic long nl() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic int[] nia(int n) {\n\t\t\tint a[] = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\ta[i] = ni();\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic String rs() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isEndOfLine(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic boolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tprivate boolean isEndOfLine(int c) {\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t}\n\n\t}\n\t\n\t\n\t\n static long mod=1000000007;\n static BigInteger bigInteger = new BigInteger(\"1000000007\");\n static int n = (int)1e6;\n static boolean[] prime;\n static ArrayList<Integer> as;\n static void sieve() {\n\t\t\tArrays.fill(prime\t, true);\n\t\t\tprime[0] = prime[1] = false;\n\t\t\tfor(int i = 2 ; i * i <= n ; ++i) {\n\t\t\t\tif(prime[i]) {\n\t\t\t\t\tfor(int k = i * i; k< n ; k+=i) {\n\t\t\t\t\t\tprime[k] = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t}\n\n public static void main(String[] args)\n {\n \n InputReader sc = new InputReader(System.in);\n PrintWriter w = new PrintWriter(System.out);\n \n \n //prime = new boolean[n + 1];\n\t\t//sieve();\n\t\t//prime[1] = false;\n\t\t/*\n\t\tas = new ArrayList<>();\n\t\tfor(int i=2;i<=1000000;i++)\n\t\t{\n\t\t if(prime[i])\n\t\t as.add(i);\n\t\t}\n\t\t*/\n\t\t\n /* \n\t\t\n\tlong a = sc.nl();\n\t \n BigInteger ans = new BigInteger(\"1\");\n for (long i = 1; i < Math.sqrt(a); i++) {\n if (a % i == 0) {\n if (a / i == i) {\n ans = ans.multiply(BigInteger.valueOf(phi(i)));\n \n } else {\n ans = ans.multiply(BigInteger.valueOf(phi(i)));\n ans = ans.multiply(BigInteger.valueOf(phi(a / i)));\n \n \n }\n \n \n }\n }\n w.println(ans.mod(bigInteger));\n \n */\n long m = sc.nl();\n int one = 0;\n long res = 0;\n int temp = 0;\n int zero = 0;\n for(long i = m;i>=1;i--)\n {\n if(m % i == 0)\n {\n one = 0;\n zero = 0;\n temp = 0;\n String s = Long.toBinaryString(i);\n for(int j=0;j<s.length();j++)\n {\n if(s.charAt(j)=='1')\n {\n one++;\n }\n \n else \n {\n temp = j;\n break;\n }\n \n \n }\n for(int j=temp;j<s.length();j++)\n {\n if(s.charAt(j)=='0')\n {\n zero++;\n }\n \n else \n {\n \n break;\n }\n \n \n }\n \n if(one + zero == s.length() && one == zero+1)\n {\n res = i;\n break;\n }\n \n }\n \n }\n w.println(res);\n \n \nw.close();\n \n }\n \n public static long modMultiply(long one, long two) {\n \n\t\treturn (one % mod * two % mod) % mod;\n\t}\n static long fx(int m)\n {\n long re = 0;\n for(int i=1;i<=m;i++)\n {\n re += (long) (i / gcd(i,m));\n }\n return re;\n }\n static long gcd(long a, long b)\n {\n\t if (a == 0)\n\t return b;\n\t\t\t\t \n\treturn gcd(b%a, a);\n }\n \n \n \n static long phi(long nx)\n {\n // Initialize result as n\n double result = nx; \n \n \n // Consider all prime factors of n and for \n // every prime factor p, multiply result\n // with (1 - 1/p)\n for (int p = 0; as.get(p) * as.get(p) <= nx; ++p)\n {\n // Check if p is a prime factor.\n if (nx % as.get(p) == 0)\n {\n // If yes, then update n and result\n while (nx % as.get(p) == 0)\n nx /= as.get(p);\n result *= (1.0 - (1.0 / (double) as.get(p)));\n }\n }\n \n // If n has a prime factor greater than sqrt(n)\n // (There can be at-most one such prime factor)\n if (nx > 1)\n result *= (1.0 - (1.0 / (double) nx));\n \n return (long)result;\n \n \n //return(phi((long)result,k-1));\n \n }\n \n public static int primeFactors(int n)\n {\n int sum = 0;\n // Print the number of 2s that divide n\n while (n%2==0)\n {\n sum = 1;\n //System.out.print(2 + \" \");\n n /= 2;\n }\n \n // n must be odd at this point. So we can\n // skip one element (Note i = i +2)\n for (int i = 3; i <= Math.sqrt(n); i+= 2)\n {\n // While i divides n, print i and divide n\n while (n%i == 0)\n {\n \n // System.out.print(i + \" \");\n n /= i;\n }\n sum++;\n }\n \n // This condition is to handle the case whien\n // n is a prime number greater than 2\n if (n > 2)\n sum++;\n return sum;\n }\n static int digitsum(int x)\n \n { \n\n int sum = 0;\n while(x > 0)\n {\n int temp = x % 10;\n sum += temp;\n x /= 10;\n }\n return sum;\n \n }\n static int countDivisors(int n)\n {\n int cnt = 0;\n for (int i = 1; i*i <=n; i++)\n {\n if (n % i == 0 && i<=1000000)\n {\n // If divisors are equal,\n // count only one\n if (n / i == i)\n cnt++;\n \n else // Otherwise count both\n cnt = cnt + 2;\n }\n }\n return cnt;\n }\n \n static boolean isprime(int n)\n {\n \n if(n == 2)\n return true;\n if(n == 3)\n return true;\n if(n % 2 == 0)\n return false;\n if(n % 3 == 0)\n return false;\n\n int i = 5;\n int w = 2;\n\n while(i * i <= n)\n {\n if(n % i == 0)\n return false;\n \n\n i += w;\n w = 6 - w;\n }\n\n return true;\n }\n \n static long log2(long value) {\n return Long.SIZE-Long.numberOfLeadingZeros(value);\n}\n\n\n\n \n \n \n static int binarysearch(int []arr,int p,int n)\n {\n \n int st = 0;\n int end = n-1;\n int mid = (st + end)/2;\n int temp = 0;\n while(st < end)\n { \n mid = (st + end)/2;\n \n if(p > arr[mid])\n {\n st = mid+1;\n \n }\n else if(p < arr[mid])\n {\n end = mid;\n \n }\n else if(p == arr[mid])\n {\n temp = mid;\n break;\n }\n \n \n \n }\n if(st == end)\n temp = st;\n \n return temp;\n }\n \n \n static class Student\n {\n \n int floor;\n int time;\n Student(int floor,int time)\n {\n this.floor = floor;\n this.time = time;\n \n \n }\n \n }\n \n \n \n public static int ip(String s){\n\t\treturn Integer.parseInt(s);\n\t}\n\t public static String ips(int s){\n\t\treturn Integer.toString(s);\n\t}\n\t\n \n\t\t\t\t\t \n}\n", "src_uid": "339246a1be81aefe19290de0d1aead84"} {"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\n ArrayList<Integer> nums = new ArrayList<>();\n for (int i = Math.max(1, (int)n-13); i <= (int)n; i++) {\n nums.add(i);\n }\n\n long fact = factorial(Math.min(n, 14));\n long x = Math.min(n, 14);\n int lucks = lucks(Math.max(1, (int)n-13));\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 public static int lucks(int max){\n int lucks = 0;\n ArrayList<Integer> luckys = new ArrayList<>();\n luckys.add(4);\n luckys.add(7);\n for (int i = 0; i < 8; i++) {\n luckys = add(luckys);\n }\n for (int i : luckys) {\n if (i < max){\n lucks++;\n }\n }\n return lucks;\n }\n public static int prev = 0;\n public static ArrayList<Integer> add(ArrayList<Integer> lucks){\n int len = lucks.size();\n for (int i = prev; i < len; i++) {\n lucks.add(lucks.get(i)+(int)(4*Math.pow(10, String.valueOf(lucks.get(i)).length())));\n }\n for (int i = prev; i < len; i++) {\n lucks.add(lucks.get(i)+(int)(7*Math.pow(10, String.valueOf(lucks.get(i)).length())));\n }\n prev = len;\n return lucks;\n }\n}", "src_uid": "cb2aa02772f95fefd1856960b6ceac4c"} {"source_code": "import java.util.Scanner;\n\npublic class T1 {\n\n\tpublic static void main(String[] args) {\n\t\tScanner jk=new Scanner(System.in);\n\t\tint n=jk.nextInt();\n\t\tint[] arr=new int[100];\n\t\tfor (int i=0;i<n;i++){\n\t\t\tint tmp=jk.nextInt();\n\t\t\tarr[tmp-1]++;\n\t\t}\n\t\tboolean flag=false;\n\t\tint res1=0;\n\t\tint res2=0;\n\t\tfor (int i=0;i<100;i++){\n\t\t\tfor (int j=0;j<100;j++){\n\t\t\t\tif ((arr[i]==arr[j])&&(arr[i]!=0)&&(i!=j)){\n\t\t\t\t\tflag=true;\n\t\t\t\t\tres1=i+1;\n\t\t\t\t\tres2=j+1;\n\t\t\t\t\tbreak;\n\t\t\t\t\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tjk.close();\n\t\t\n\t\t\n\t\tif (flag){\n\t\t\tif (arr[res1-1]+arr[res2-1]!=n)\n\t\t\t{\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t}\n\t\t\telse\n\t\t{\t\t\n\t\t\tSystem.out.println(\"YES\");\n\t\t\tSystem.out.println(res1+\" \"+res2);}}\n\t\telse{\n\t\t\tSystem.out.println(\"NO\");\n\t\t}\n\t}\n\n}\n", "src_uid": "2860b4fb22402ea9574c2f9e403d63d8"} {"source_code": "import java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.Scanner;\n\npublic class Main {\n\t\n\t\n\tpublic static void main(String[] args) throws Exception {\n new Main();\n }\n\t\n\tlong n,k;\n\t\n\tpublic Main() throws Exception{\n\t\tScanner sc = new Scanner(System.in);\n//\t\tScanner sc = new Scanner(new FileReader(\"input\"));\n\t\tn = sc.nextLong();\n\t\tk = sc.nextLong();\n\t\tif ( k==0){\n\t\t\tSystem.out.println(\"0 0\");\n\t\t\tsc.close();\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tSystem.out.println( Math.min(1, n-k) + \" \" + Math.min(k*2, n-k));\n\t\t\n\t\t\n sc.close();\n\t}\n\t\n\t\n\tstatic long gcd(long a, long b)\n\t{\n\t while (b > 0)\n\t {\n\t long temp = b;\n\t b = a % b;\n\t a = temp;\n\t }\n\t return a;\n\t}\n\t\n\t\n\t\n\tstatic long lcm(long a, long b) {\n\t return a * (b / gcd(a, b));\n\t}\n\n\t\n\t\n\t\n}\n", "src_uid": "bdccf34b5a5ae13238c89a60814b9f86"} {"source_code": "import java.util.Scanner;\n\n//import TetraHedron.Scanner;\n\n\npublic class SquaresandSegements {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\n\t\tScanner input = new Scanner(System.in);\n\t\tlong n = input.nextLong();\n\t\tlong val = (long)Math.sqrt(n);\n\t\tlong total = 2*val;\n\t//\tSystem.out.println(total);\n\t\tlong rem = n - (long)Math.pow((long)Math.sqrt(n),2);\n\t\t///System.out.println(rem);\n\t\ttotal += (long)Math.ceil(rem/Math.sqrt(n));\n\t\tSystem.out.println(total);\n\t}\n\n}\n", "src_uid": "eb8212aec951f8f69b084446da73eaf7"} {"source_code": "import java.util.Scanner;\n\n/**\n * B. File Name\n * @author satyam\n *uxxxxxlmexxxxxxxwnxxexxxxxcxxfydxxxxxxvmdxxxxxxisxxxxxxxxidkxxxpxxxxxxxxmnuxxxxjxxxqcxxwmxxxxxxxxmrx\n */\npublic class CodeForces16 {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint a= Integer.parseInt(sc.nextLine());\n\t\tString str=sc.nextLine();\n\t\tint res=0,counter=0;\n\t\tfor(int i=0;i<a;i++) {\n\t\t\tif(str.charAt(i)=='x') {\n\t\t\t\tcounter++;\n\t\t\t}else if(counter>2){\n\t\t\t\tres+=(counter-2);\n\t\t\t\tcounter=0;\n\t\t\t}else {\n\t\t\t\tcounter=0;\n\t\t\t}\n\t\t}\n\t\tif(counter>2) res+=(counter-2);\n\t\tSystem.out.println(res);\n\t}\n}\n", "src_uid": "8de14db41d0acee116bd5d8079cb2b02"} {"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 \n String s = sc.next();\n \n char[] c = s.toCharArray();\n \n char a = 'a';\n \n int total = 0;\n \n for (int i = 0; i < c.length; i++) {\n if (Math.abs(c[i] - a) <= 13) {\n total += Math.abs(c[i] - a);\n a = c[i];\n }else{\n total += 26 - Math.abs((c[i] - a));\n a = c[i];\n } \n }\n \n System.out.println(total);\n \n }\n}\n\n//https://codeforces.com/problemset/problem/731/A", "src_uid": "ecc890b3bdb9456441a2a265c60722dd"} {"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\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\tArrayList<Integer>[] may = new ArrayList[c5];\n\t\tfor (int i = 0; i < c5; i++) {\n\t\t\tmay[i] = new ArrayList<Integer>();\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<Integer> 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\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\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}\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}", "src_uid": "3f3eb49a127768139283ac04ee44950f"} {"source_code": "import java.io.*;\nimport java.util.*;\npublic class wolf{\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\tsc.nextLine();\n\t\tchar arr[][]=new char[15][15];\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tString data=sc.nextLine();\n\t\t\tfor(int j=0;j<m;j++)\n\t\t\t{\n\t\t\t\tarr[i][j]=data.charAt(j);\n\t\t\t\t//sc.nextLine();\n\t\t\t}\n\t\t}\n\t\tint k=0;\n\t\t\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tfor(int j=0;j<m;j++)\n\t\t\t{\n\t\t\t\tif(arr[i][j]=='W')\n\t\t\t\t{\n\t\t\t\t\tif( i>0 &&arr[i-1][j]=='P' )\n\t\t\t\t\t{\n\t\t\t\t\t\tarr[i-1][j]='.';\n\t\t\t\t\t\tk++;\n\t\t\t\t\t}\n\t\t\t\t\telse if((i+1)<n&& arr[i+1][j]=='P')\n\t\t\t\t\t{\n\t\t\t\t\t\tarr[i+1][j]='.';\n\t\t\t\t\t\tk++;\n\t\t\t\t\t}\n\t\t\t\t\telse if(j>0&&arr[i][j-1]=='P' )\n\t\t\t\t\t{\n\t\t\t\t\t\tarr[i][j-1]='.';\n\t\t\t\t\t\tk++;\n\t\t\t\t\t}\n\t\t\t\t\telse if((j+1)<m&&arr[i][j+1]=='P' )\n\t\t\t\t\t{\n\t\t\t\t\t\tarr[i][j+1]='.';\n\t\t\t\t\t\tk++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(k);\n\t}\n}\t\t\t\t", "src_uid": "969b24ed98d916184821b2b2f8fd3aac"} {"source_code": "import java.util.*;\nimport java.io.*;\nimport java.io.File;\nimport java.util.AbstractSet;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\npublic class Hello {\n\n public static void main(String[] args) {\n //try {\n // FileInputStream fis = new FileInputStream(\"data.txt\");\n // System.setIn(fis);\n Scanner in = new Scanner(System.in);\n\n int n = in.nextInt();\n System.out.println(n / 2 + 1);\n \n //} catch (FileNotFoundException e){\n // System.out.println(\"error\");\n //}\n }\n}\n", "src_uid": "5551742f6ab39fdac3930d866f439e3e"} {"source_code": "import java.util.List;\nimport java.util.Map;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.io.BufferedReader;\nimport java.util.Comparator;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Random;\nimport java.util.TreeSet;\nimport java.util.StringTokenizer;\nimport java.util.Collections;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\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 index;\n\n Point(int x, int y, int index) {\n this.x = x;\n this.y = y;\n this.index = index;\n }\n }\n\n static class GraphNode implements Comparable<GraphNode> {\n int sideId;\n int x;\n double y;\n double distance = 1e100;\n boolean mark = false;\n\n List<GraphNode> outgo = new ArrayList<GraphNode>();\n\n GraphNode(int sideId, int x) {\n this.sideId = sideId;\n this.x = x;\n }\n\n public boolean equals(Object o) {\n if (this == o) return true;\n GraphNode graphNode = (GraphNode) o;\n\n if (sideId != graphNode.sideId) return false;\n if (x != graphNode.x) return false;\n\n return true;\n }\n\n public int hashCode() {\n int result = sideId;\n result = 31 * result + x;\n return result;\n }\n\n public int compareTo(GraphNode graphNode) {\n int z = sideId - graphNode.sideId;\n if (z != 0) return z;\n return x - graphNode.x;\n }\n }\n\n List<GraphNode> nodes = new ArrayList<GraphNode>();\n Map<GraphNode, GraphNode> canonical = new HashMap<GraphNode, GraphNode>();\n\n static class Edge implements Comparable<Edge> {\n Point v1;\n Point v2;\n int isUpper;\n\n Edge(Point v1, Point v2) {\n if (v1.x > v2.x) {\n Point tmp = v1;\n v1 = v2;\n v2 = tmp;\n }\n this.v1 = v1;\n this.v2 = v2;\n }\n\n public int compareTo(Edge edge) {\n int minx = Math.max(v1.x, edge.v1.x);\n int maxx = Math.min(v2.x, edge.v2.x);\n if (minx >= maxx) {\n throw new RuntimeException();\n }\n //if (this.v1 == edge.v1 && this.v2 == edge.v2) return 0;\n int mid = (minx + maxx) / 2;\n long diff = ((mid - v1.x) * (long) (v2.y - v1.y) + v1.y * (long) (v2.x - v1.x)) * (edge.v2.x - edge.v1.x)\n - ((mid - edge.v1.x) * (long) (edge.v2.y - edge.v1.y) + edge.v1.y * (long) (edge.v2.x - edge.v1.x)) * (v2.x - v1.x);\n return Long.signum(diff);\n }\n }\n\n int n;\n\n\tpublic void solve(int testNumber, InputReader in, PrintWriter out) {\n Random random = new Random(5943715431L);\n n = in.nextInt();\n Point[] poly = new Point[n];\n for (int i = 0; i < n; ++i) {\n int x = in.nextInt();\n int y = in.nextInt();\n poly[i] = new Point(x * 2, y * 2, i);\n }\n for (int i = 0; i < poly.length; ++i) {\n Edge e1 = new Edge(poly[i], poly[(i + 1) % poly.length]);\n Edge e2 = new Edge(poly[i], poly[(i + poly.length - 1) % poly.length]);\n addTransition(e1, e2, poly[i].x);\n addTransition(e2, e1, poly[i].x);\n }\n int s = in.nextInt() - 1;\n int t = in.nextInt() - 1;\n TreeSet<Edge> picture = new TreeSet<Edge>();\n Point[] polyByX = poly.clone();\n for (int i = 0; i < polyByX.length; ++i) {\n int j = i + random.nextInt(polyByX.length - i);\n Point tmp = polyByX[i];\n polyByX[i] = polyByX[j];\n polyByX[j] = tmp;\n }\n Arrays.sort(polyByX, new Comparator<Point>() {\n public int compare(Point a, Point b) {\n int z = Integer.signum(a.x - b.x);\n if (z != 0) return z;\n return Integer.signum(a.y - b.y);\n }\n });\n for (int pi = 0; pi < polyByX.length;) {\n int pj;\n Point prevP = null;\n for (pj = pi; pj < polyByX.length && polyByX[pj].x == polyByX[pi].x; ++pj) {\n Point p = polyByX[pj];\n Point a = poly[(p.index + 1) % poly.length];\n Point b = poly[(p.index + poly.length - 1) % poly.length];\n if (a.x > b.x || (a.x == b.x && a.y > b.y)) {\n Point tmp = a;\n a = b;\n b = tmp;\n }\n if (a.x < p.x && b.x < p.x) {\n if ((a.x - p.x) * (long) (b.y - p.y) - (a.y - p.y) * (long) (b.x - p.x) < 0) {\n Point tmp = a;\n a = b;\n b = tmp;\n }\n Edge bEdge = picture.floor(new Edge(b, p));\n if (bEdge.isUpper == 2) {\n Edge dest = picture.lower(bEdge);\n double destY = addTransition(bEdge, dest, p.x);\n if (prevP != null) {\n if (prevP.y > destY) {\n getNodeFor(poly, p.index).outgo.add(getNodeFor(poly, prevP.index));\n }\n }\n }\n Edge aEdge = picture.floor(new Edge(a, p));\n if (aEdge.isUpper == 1) {\n Edge dest = picture.higher(aEdge);\n addTransition(dest, aEdge, p.x);\n }\n } else if (a.x < p.x && b.x > p.x) {\n Edge aEdge = picture.floor(new Edge(a, p));\n if (aEdge.isUpper == 1) {\n Edge dest = picture.higher(aEdge);\n addTransition(dest, aEdge, p.x);\n } else {\n Edge dest = picture.lower(aEdge);\n double destY = addTransition(aEdge, dest, p.x);\n if (prevP != null) {\n if (prevP.y > destY) {\n getNodeFor(poly, p.index).outgo.add(getNodeFor(poly, prevP.index));\n }\n }\n }\n } else if (a.x < p.x && b.x == p.x) {\n Edge aEdge = picture.floor(new Edge(a, p));\n if (aEdge.isUpper == 1 && b.y < p.y) {\n Edge dest = picture.higher(aEdge);\n addTransition(dest, aEdge, p.x);\n } else if (aEdge.isUpper == 2 && b.y > p.y) {\n Edge dest = picture.lower(aEdge);\n double destY = addTransition(aEdge, dest, p.x);\n if (prevP != null) {\n if (prevP.y > destY) {\n getNodeFor(poly, p.index).outgo.add(getNodeFor(poly, prevP.index));\n }\n }\n }\n }\n prevP = p;\n }\n for (pj = pi; pj < polyByX.length && polyByX[pj].x == polyByX[pi].x; ++pj) {\n Point p = polyByX[pj];\n Point a = poly[(p.index + 1) % poly.length];\n Point b = poly[(p.index + poly.length - 1) % poly.length];\n if (a.x < p.x) {\n Edge toRemove = new Edge(a, p);\n if (!picture.remove(toRemove)) throw new RuntimeException();\n }\n if (b.x < p.x) {\n Edge toRemove = new Edge(b, p);\n if (!picture.remove(toRemove)) {\n throw new RuntimeException();\n }\n }\n }\n for (pj = pi; pj < polyByX.length && polyByX[pj].x == polyByX[pi].x; ++pj) {\n Point p = polyByX[pj];\n Point a = poly[(p.index + 1) % poly.length];\n Point b = poly[(p.index + poly.length - 1) % poly.length];\n if ((a.x - p.x) * (long) (b.y - p.y) - (a.y - p.y) * (long) (b.x - p.x) < 0) {\n Point tmp = a;\n a = b;\n b = tmp;\n }\n if (a.x > p.x) {\n Edge toAdd = new Edge(a, p);\n Edge prev = picture.lower(toAdd);\n if (prev == null)\n toAdd.isUpper = 1;\n else\n toAdd.isUpper = 3 - prev.isUpper;\n if (!picture.add(toAdd)) throw new RuntimeException();\n }\n if (b.x > p.x) {\n Edge toAdd = new Edge(b, p);\n Edge prev = picture.lower(toAdd);\n if (prev == null)\n toAdd.isUpper = 1;\n else\n toAdd.isUpper = 3 - prev.isUpper;\n if (!picture.add(toAdd)) throw new RuntimeException();\n }\n }\n prevP = null;\n for (pj = pi; pj < polyByX.length && polyByX[pj].x == polyByX[pi].x; ++pj) {\n Point p = polyByX[pj];\n Point a = poly[(p.index + 1) % poly.length];\n Point b = poly[(p.index + poly.length - 1) % poly.length];\n if (a.x > b.x || (a.x == b.x && a.y > b.y)) {\n Point tmp = a;\n a = b;\n b = tmp;\n }\n if (a.x > p.x && b.x > p.x) {\n if ((a.x - p.x) * (long) (b.y - p.y) - (a.y - p.y) * (long) (b.x - p.x) > 0) {\n Point tmp = a;\n a = b;\n b = tmp;\n }\n Edge bEdge = picture.floor(new Edge(b, p));\n if (bEdge.isUpper == 2) {\n Edge dest = picture.lower(bEdge);\n double destY = addTransition(bEdge, dest, p.x);\n if (prevP != null) {\n if (prevP.y > destY) {\n getNodeFor(poly, p.index).outgo.add(getNodeFor(poly, prevP.index));\n }\n }\n }\n Edge aEdge = picture.floor(new Edge(a, p));\n if (aEdge.isUpper == 1) {\n Edge dest = picture.higher(aEdge);\n addTransition(dest, aEdge, p.x);\n }\n } else if (a.x == p.x && b.x > p.x) {\n Edge bEdge = picture.floor(new Edge(b, p));\n if (bEdge.isUpper == 1 && a.y < p.y) {\n Edge dest = picture.higher(bEdge);\n addTransition(dest, bEdge, p.x);\n } else if (bEdge.isUpper == 2 && a.y > p.y) {\n Edge dest = picture.lower(bEdge);\n double destY = addTransition(bEdge, dest, p.x);\n if (prevP != null) {\n if (prevP.y > destY) {\n getNodeFor(poly, p.index).outgo.add(getNodeFor(poly, prevP.index));\n }\n }\n }\n }\n prevP = p;\n }\n pi = pj;\n }\n GraphNode start = getNodeFor(poly, s);\n GraphNode finish = getNodeFor(poly, t);\n Collections.sort(nodes);\n for (int i = 0; i + 1 < nodes.size(); ++i) {\n GraphNode n1 = nodes.get(i);\n GraphNode n2 = nodes.get(i + 1);\n if (n1.sideId == n2.sideId) {\n n1.outgo.add(n2);\n n2.outgo.add(n1);\n }\n }\n TreeSet<Reach> reaches = new TreeSet<Reach>();\n start.distance = 0;\n reaches.add(new Reach(start, 0));\n while (true) {\n Reach first = reaches.pollFirst();\n if (first.dest.mark) continue;\n first.dest.mark = true;\n if (first.dest == finish) {\n out.println(first.dest.distance / 2.0);\n return;\n }\n for (GraphNode other : first.dest.outgo) {\n double dx = first.dest.x - other.x;\n double dy = first.dest.y - other.y;\n double dd = Math.sqrt(dx * dx + dy * dy);\n double nd = first.dest.distance + dd;\n if (nd < other.distance - 1e-10) {\n other.distance = nd;\n reaches.add(new Reach(other, other.distance));\n }\n }\n }\n\t}\n\n private GraphNode getNodeFor(Point[] poly, int s) {\n GraphNode start;\n {\n Point sp = poly[s];\n Point spa = poly[(s + 1) % poly.length];\n Point spb = poly[(s + poly.length - 1) % poly.length];\n if (spa.x != sp.x || spa.y > sp.y) {\n start = createNode(new Edge(sp, spa), sp.x);\n } else {\n start = createNode(new Edge(sp, spb), sp.x);\n }\n }\n return start;\n }\n\n static class Reach implements Comparable<Reach> {\n GraphNode dest;\n double d;\n\n Reach(GraphNode dest, double d) {\n this.dest = dest;\n this.d = d;\n }\n\n public int compareTo(Reach reach) {\n if (d != reach.d) return Double.compare(d, reach.d);\n return dest.compareTo(reach.dest);\n }\n }\n\n private double addTransition(Edge top, Edge bottom, int x) {\n GraphNode src = createNode(top, x);\n GraphNode dst = createNode(bottom, x);\n src.outgo.add(dst);\n return dst.y;\n }\n\n private GraphNode createNode(Edge top, int x) {\n GraphNode src;\n {\n int i1 = top.v1.index;\n int i2 = top.v2.index;\n int i;\n if (i1 + 1 == i2 || i1 + 1 == i2 + n) {\n i = i1;\n } else if (i2 + 1 == i1 || i2 + 1 == i1 + n) {\n i = i2;\n } else {\n throw new RuntimeException();\n }\n src = new GraphNode(i, x);\n GraphNode canonicalSrc = canonical.get(src);\n if (canonicalSrc == null) {\n canonical.put(src, src);\n nodes.add(src);\n if (top.v1.x == top.v2.x)\n src.y = Math.min(top.v1.y, top.v2.y);\n else\n src.y = (x - top.v1.x) / (double) (top.v2.x - top.v1.x) * (top.v2.y - top.v1.y) + top.v1.y;\n } else {\n src = canonicalSrc;\n }\n }\n return src;\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 }", "src_uid": "ccc9d167caf5c4e3c7ab212bf4f5ca45"} {"source_code": "\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashMap;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\n\n/**\n *\n *\n *\n * @author pttrung\n */\npublic class D {\n\n public static long MOD = 1000000007;\n public static ArrayList<Integer> p;\n\n public static void main(String[] args) {\n Scanner in = new Scanner();\n PrintWriter out = new PrintWriter(System.out);\n long a = in.nextLong();\n long b = in.nextLong();\n long k = in.nextLong();\n boolean[] prime = new boolean[10000000];\n p = new ArrayList();\n ArrayList<Integer> list = new ArrayList();\n for (int i = 2; i < prime.length; i++) {\n if (!prime[i]) {\n p.add( i);\n if (i < k) {\n list.add(i);\n }\n for (int j = i * i; j < prime.length; j += i) {\n if (j < 0) {\n break;\n }\n prime[j] = true;\n\n }\n }\n }\n boolean ok = true;\n if (k < prime.length) {\n if (prime[(int) k]) {\n out.println(0);\n ok = false;\n }\n } else {\n if (!isPrime(k)) {\n out.println(0);\n ok = false;\n }\n }\n// for(long val : p){\n// System.out.println(\"Prime \" + val);\n// }\n // p.add(k);\n if (ok) { \n long left = cal(list.size() - 1, list, b/k);\n long right = cal(list.size() - 1, list, (a - 1)/k);\n //out.println(left + \" \" + right);\n out.println((left - right));\n }\n out.close();\n }\n\n public static boolean isPrime(long val) {\n int index = 1;\n int prime = p.get(0);\n while(prime*prime <= val && index < p.size()){\n if(val% prime == 0){\n return false;\n } \n prime = p.get(index ++);\n }\n return true;\n }\n\n public static long cal(int index, ArrayList<Integer> val, long n) {\n\n if (n == 0 || index == -1) {\n return n;\n }\n return cal(index - 1, val, n) - cal(index - 1, val, n / val.get(index));\n }\n\n public static class Edge implements Comparable<Edge> {\n\n int x, y;\n\n public Edge(int x, int y) {\n this.x = x;\n this.y = y;\n }\n\n @Override\n public int compareTo(Edge o) {\n if (x != o.x) {\n return x - o.x;\n } else {\n return y - o.y;\n }\n }\n }\n\n public static class FT {\n\n int[] data;\n\n FT(int n) {\n data = new int[n];\n }\n\n public void update(int index, int value) {\n while (index < data.length) {\n data[index] += value;\n index += (index & (-index));\n }\n }\n\n public int get(int index) {\n int result = 0;\n while (index > 0) {\n result += data[index];\n index -= (index & (-index));\n }\n return result;\n\n }\n }\n\n public static long gcd(long a, long b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n public static long pow(long a, long b) {\n if (b == 0) {\n return 1;\n }\n if (b == 1) {\n return a;\n }\n long val = pow(a, b / 2);\n if (b % 2 == 0) {\n return val * val % MOD;\n } else {\n return val * (val * a % MOD) % MOD;\n }\n }\n\n static class Scanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n public Scanner() {\n // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n public String next() {\n\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n return st.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public String nextLine() {\n st = null;\n try {\n return br.readLine();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n\n public boolean endLine() {\n try {\n String next = br.readLine();\n while (next != null && next.trim().isEmpty()) {\n next = br.readLine();\n }\n if (next == null) {\n return true;\n }\n st = new StringTokenizer(next);\n return st.hasMoreTokens();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n }\n}\n", "src_uid": "04a26f1d1013b6e6b4b0bdcf225475f2"} {"source_code": "import java.util.*;\n\npublic class Main {\n \n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int aa = in.nextInt(), bb = in.nextInt();\n int cc = in.nextInt(), dd = in.nextInt();\n boolean a = aa == 1 ? true : false;\n boolean b = bb == 1 ? true : false;\n boolean c = cc == 1 ? true : false;\n boolean d = dd == 1 ? true : false;\n boolean one = a ^ b;\n boolean two = c | d;\n boolean three = b & c;\n boolean four = a ^ d;\n boolean five = one & two;\n boolean six = three | four;\n System.out.println(five ^ six ? 1 : 0);\n \n in.close();\n }\n}", "src_uid": "879ac20ae5d3e7f1002afe907d9887df"} {"source_code": "import java.util.Scanner;\n\npublic final class ThreeGarlandsCF {\n public static void main(String[] args) {\n Scanner sc=new Scanner(System.in);\n int k1=sc.nextInt();\n int k2=sc.nextInt();\n int k3=sc.nextInt();\n if(k1==1 || k2==1 || k3==1){\n System.out.println(\"YES\");\n }else{\n int twoCount=0;\n int threeCount=0;\n int fourCount=0;\n\n if(k1==2)\n twoCount++;\n else if(k1==3)\n threeCount++;\n else if(k1==4)\n fourCount++;\n\n if(k2==2)\n twoCount++;\n else if(k2==3)\n threeCount++;\n else if(k2==4)\n fourCount++;\n\n if(k3==2)\n twoCount++;\n else if(k3==3)\n threeCount++;\n else if(k3==4)\n fourCount++;\n\n if(twoCount>=2 || threeCount==3 || (twoCount==1 && fourCount==2))\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n }\n }\n}\n", "src_uid": "df48af9f5e68cb6efc1214f7138accf9"} {"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 * stescobedo\r\n */\r\npublic class Main {\r\n public static void main(String[] args) {\r\n InputStream inputStream = System.in;\r\n OutputStream outputStream = System.out;\r\n InputReader in = new InputReader(inputStream);\r\n OutputWriter out = new OutputWriter(outputStream);\r\n FNezzarAndChocolateBars solver = new FNezzarAndChocolateBars();\r\n solver.solve(1, in, out);\r\n out.close();\r\n }\r\n \r\n static class FNezzarAndChocolateBars {\r\n static final int MAXN = 2048;\r\n static final int modulo = 998244353;\r\n \r\n public int add(int x, int y) {\r\n x += y;\r\n if (x >= modulo) x -= modulo;\r\n return x;\r\n }\r\n \r\n public int subtract(int x, int y) {\r\n x -= y;\r\n if (x < 0) x += modulo;\r\n return x;\r\n }\r\n \r\n public int multiply(int x, int y) {\r\n return (int) ((x * 1L * y) % modulo);\r\n }\r\n \r\n public int power(int x, long y) {\r\n int ans = 1;\r\n for (; y > 0; y >>= 1, x = (int) ((x * 1L * x) % modulo))\r\n if (y % 2 == 1) ans = (int) ((ans * 1L * x) % modulo);\r\n return ans;\r\n }\r\n \r\n public int inverse(int x) {\r\n return power(x, modulo - 2);\r\n }\r\n \r\n public void solve(int testNumber, InputReader in, OutputWriter out) {\r\n int[] fact = new int[MAXN];\r\n int[] ifact = new int[MAXN];\r\n fact[0] = ifact[0] = 1;\r\n for (int i = 1; i < MAXN; i++) {\r\n fact[i] = multiply(fact[i - 1], i);\r\n ifact[i] = inverse(fact[i]);\r\n }\r\n int n = in.nextInt(), k = in.nextInt();\r\n int[] l = in.readIntArray(n);\r\n int[][][] dp = new int[2][MAXN][n + 1];\r\n dp[1][0][0] = 1;\r\n int s = 0;\r\n \r\n for (int p = 0; p < n; p++) {\r\n int L = l[p];\r\n int invL = inverse(L);\r\n int[] coeffs = new int[L / k + 1];\r\n int[] coeffs2 = new int[L / k + 1];\r\n for (int i = 0; i <= L / k; i++) {\r\n if (k * i == L) continue;\r\n int z = ifact[i];\r\n if (i % 2 == 1) z = subtract(0, z);\r\n coeffs[i] = multiply(z, power(L - k * i, i));\r\n \r\n if (i >= 1) {\r\n coeffs2[i] = multiply(z, multiply(i, power(L - k * i, i - 1)));\r\n }\r\n }\r\n int r = p & 1;\r\n int h = r ^ 1;\r\n for (int i = 0; i <= s / k; i++) Arrays.fill(dp[r][i], 0);\r\n for (int i = 0; i <= s / k; i++)\r\n for (int j = 0; j <= p; j++)\r\n if (dp[h][i][j] != 0) {\r\n int value = dp[h][i][j];\r\n for (int t = 0; t <= L / k; t++) {\r\n dp[r][i + t][j] = add(dp[r][i + t][j], multiply(value, coeffs[t]));\r\n if (t > 0) {\r\n dp[r][i + t - 1][j + 1] = add(dp[r][i + t - 1][j + 1], multiply(value, coeffs2[t]));\r\n }\r\n }\r\n }\r\n s += L;\r\n }\r\n int answer = 0;\r\n for (int i = 0; i <= s / k; i++)\r\n for (int r = 0; r <= n; r++) {\r\n int value = dp[(n - 1) & 1][i][r];\r\n int j = i + r;\r\n if (j == 0) continue;\r\n int temp = multiply(fact[i], inverse(power(k * j, i + 1)));\r\n answer = add(answer, multiply(value, temp));\r\n }\r\n out.println(multiply(subtract(0, s), answer));\r\n }\r\n \r\n }\r\n \r\n static class InputReader {\r\n private InputStream stream;\r\n private byte[] buf = new byte[1024];\r\n private int curChar;\r\n private int numChars;\r\n private InputReader.SpaceCharFilter filter;\r\n \r\n public InputReader(InputStream stream) {\r\n this.stream = stream;\r\n }\r\n \r\n public int[] readIntArray(int size) {\r\n int[] array = new int[size];\r\n for (int i = 0; i < size; i++) {\r\n array[i] = readInt();\r\n }\r\n return array;\r\n }\r\n \r\n public int read() {\r\n if (numChars == -1) {\r\n throw new InputMismatchException();\r\n }\r\n if (curChar >= numChars) {\r\n curChar = 0;\r\n try {\r\n numChars = stream.read(buf);\r\n } catch (IOException e) {\r\n throw new InputMismatchException();\r\n }\r\n if (numChars <= 0) {\r\n return -1;\r\n }\r\n }\r\n return buf[curChar++];\r\n }\r\n \r\n public int nextInt() {\r\n int c = read();\r\n while (isSpaceChar(c)) c = read();\r\n int sgn = 1;\r\n if (c == '-') {\r\n sgn = -1;\r\n c = read();\r\n }\r\n int res = 0;\r\n do {\r\n if (c < '0' || c > '9')\r\n throw new InputMismatchException();\r\n res *= 10;\r\n res += c - '0';\r\n c = read();\r\n } while (!isSpaceChar(c));\r\n return res * sgn;\r\n }\r\n \r\n public int readInt() {\r\n int c = read();\r\n while (isSpaceChar(c)) {\r\n c = read();\r\n }\r\n int sgn = 1;\r\n if (c == '-') {\r\n sgn = -1;\r\n c = read();\r\n }\r\n int res = 0;\r\n do {\r\n if (c < '0' || c > '9') {\r\n throw new InputMismatchException();\r\n }\r\n res *= 10;\r\n res += c - '0';\r\n c = read();\r\n } while (!isSpaceChar(c));\r\n return res * sgn;\r\n }\r\n \r\n public boolean isSpaceChar(int c) {\r\n if (filter != null) {\r\n return filter.isSpaceChar(c);\r\n }\r\n return isWhitespace(c);\r\n }\r\n \r\n public static boolean isWhitespace(int c) {\r\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\r\n }\r\n \r\n public interface SpaceCharFilter {\r\n public boolean isSpaceChar(int ch);\r\n \r\n }\r\n \r\n }\r\n \r\n static class OutputWriter {\r\n private final PrintWriter writer;\r\n \r\n public OutputWriter(OutputStream outputStream) {\r\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\r\n }\r\n \r\n public OutputWriter(Writer writer) {\r\n this.writer = new PrintWriter(writer);\r\n }\r\n \r\n public void println(Object... objects) {\r\n for (int i = 0; i < objects.length; i++) {\r\n if (i != 0) {\r\n writer.print(' ');\r\n }\r\n writer.print(objects[i]);\r\n }\r\n writer.print('\\n');\r\n }\r\n \r\n public void close() {\r\n writer.close();\r\n }\r\n \r\n }\r\n}", "src_uid": "26d565c193a5920b042c783109496b4c"} {"source_code": "import java.io.*;\nimport java.util.*;\nimport java.lang.*;\n public class templ {\n int binarySearch(int arr[], int l, int r, int x)\n {\n if (r >= l)\n {\n int mid = l + (r - l)/2;\n if (arr[mid] == x)\n return mid;\n if (arr[mid] > x) \n return binarySearch(arr, l, mid-1, x);\n return binarySearch(arr, mid+1, r, x);\n }\n return -1;\n }\n int partition(int arr[], int low, int high)\n {\n int pivot = arr[high]; \n int i = (low-1); // index of smaller element\n for (int j=low; j<high; j++)\n {\n if (arr[j] <= pivot)\n {\n i++;\n int temp = arr[i];\n arr[i] = arr[j];\n arr[j] = temp;\n }\n }\n int temp = arr[i+1];\n arr[i+1] = arr[high];\n arr[high] = temp;\n return i+1;\n }\n void sort(int arr[], int low, int high)\n {\n if (low < high)\n {\n int pi = partition(arr, low, high);\n sort(arr, low, pi-1);\n sort(arr, pi+1, high);\n }\n }\n public static void main(String[] args) throws FileNotFoundException {\n try\n {\n InputReader in = new InputReader(System.in);\n PrintWriter out = new PrintWriter(System.out);\n templ ob=new templ();\n int n=in.nextInt();\n int a=in.nextInt();\n int odd[]=new int[n/2];\n int even[]=new int[n/2];\n int k=0;\n for(int i=1;i<=n;i=i+2)\n {\n odd[k]=i;\n k++;\n }\n k=0;\n for(int i=n;i>=2;i-=2)\n {\n even[k]=i;\n k++;\n }\n if(a%2==0)\n {\n int x=0;\n for(int i=0;i<n/2;i++)\n {\n if(even[i]==a)\n {\n x=i;\n break;\n }\n }\n out.println(x+1);\n }\n else\n {\n int x=0;\n for(int i=0;i<n/2;i++)\n {\n if(odd[i]==a)\n {\n x=i;\n break;\n }\n }\n out.println(x+1);\n }\n out.close();\n }\n catch(Exception e){\n return;\n }\n }\n static class InputReader {\n\n private final InputStream stream;\n private final byte[] buf = new byte[8192];\n private int curChar, snumChars;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (snumChars == -1)\n throw new InputMismatchException();\n if (curChar >= snumChars) {\n curChar = 0;\n try {\n snumChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (snumChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public long nextLong() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public int[] nextIntArray(int n) {\n int a[] = new int[n];\n for (int i = 0; i < n; i++) {\n a[i] = nextInt();\n }\n return a;\n }\n\n public String readString() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public String nextLine() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isEndOfLine(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n private boolean isEndOfLine(int c) {\n return c == '\\n' || c == '\\r' || c == -1;\n }\n\n }\n} \t", "src_uid": "aa62dcdc47d0abbba7956284c1561de8"} {"source_code": "import java.util.*;\nimport java.lang.Math;\npublic class Main\n{\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tString s =sc.next();\n\t int u=0;\n\t int l=0;\n\t int r=0;\n\t int d=0;\n\t for(int i=0;i<s.length();i++){\n\t if(s.charAt(i)=='U') u++;\n\t if(s.charAt(i)=='L') l++;\n\t if(s.charAt(i)=='D') d++;\n\t if(s.charAt(i)=='R') r++;\n\t }\n\t \n\t System.out.println(2*Math.min(l,r) + 2*Math.min(u,d));\n\t}\n}\n", "src_uid": "b9fa2bb8001bd064ede531a5281cfd8a"} {"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.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) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n CGregAndFriends solver = new CGregAndFriends();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class CGregAndFriends {\n long mod = 1000000007;\n long INF = (long) 1e18 + 1;\n PrintWriter out;\n InputReader in;\n long[][] nCr = new long[100][100];\n\n long f(long p, int a, int b, int c, int d) {\n p *= nCr[a][b];\n p %= mod;\n p *= nCr[c][d];\n p %= mod;\n return p;\n }\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n this.out = out;\n this.in = in;\n int n = ni();\n int K = ni();\n int cnt1 = 0, cnt2 = 0;\n int i = 0, j = 0, k = 0;\n for (i = 0; i < 100; i++) {\n for (j = 0; j <= i; j++) {\n if (j == 0 || j == i)\n nCr[i][j] = 1;\n else\n nCr[i][j] = (nCr[i - 1][j] + nCr[i - 1][j - 1]) % mod;\n }\n }\n for (i = 0; i < n; i++) {\n if (ni() == 50)\n cnt1++;\n else\n cnt2++;\n }\n long[][][] dist = new long[200][200][2];\n long[][][] dp = new long[200][200][2];\n for (i = 0; i < 200; i++) {\n for (j = 0; j < 200; j++)\n Arrays.fill(dist[i][j], INF);\n }\n dist[0][0][0] = 0;\n dp[0][0][0] = 1;\n ArrayDeque<Tuple> pq = new ArrayDeque<>();\n pq.add(new Tuple(0, 0, 0, 0));\n while (pq.size() > 0) {\n Tuple curr = pq.poll();\n int x = curr.x;\n int y = curr.y;\n int z = curr.z;\n long d = dist[x][y][z];\n if (z == 0) {\n int rem_x = cnt1 - x;\n int rem_y = cnt2 - y;\n for (i = 0; i <= rem_x; i++) {\n for (j = 0; j <= rem_y; j++) {\n if (i + j == 0)\n continue;\n if (i * 50 + j * 100 > K)\n break;\n if (dist[i + x][j + y][z ^ 1] >= d + 1) {\n if (dist[i + x][j + y][z ^ 1] > d + 1) {\n dist[i + x][j + y][z ^ 1] = d + 1;\n pq.add(new Tuple(dist[i + x][j + y][z ^ 1], i + x, j + y, z ^ 1));\n dp[i + x][j + y][z ^ 1] += f(dp[x][y][z], rem_x, i, rem_y, j);\n dp[i + x][j + y][z ^ 1] %= mod;\n } else {\n dp[i + x][j + y][z ^ 1] += f(dp[x][y][z], rem_x, i, rem_y, j);\n dp[i + x][j + y][z ^ 1] %= mod;\n }\n }\n }\n }\n } else {\n int rem_x = x;\n int rem_y = y;\n for (i = 0; i <= rem_x; i++) {\n for (j = 0; j <= rem_y; j++) {\n if (i + j == 0)\n continue;\n if (i * 50 + j * 100 > K)\n break;\n if (dist[x - i][y - j][z ^ 1] >= d + 1) {\n if (dist[x - i][y - j][z ^ 1] > d + 1) {\n dist[x - i][y - j][z ^ 1] = d + 1;\n pq.add(new Tuple(dist[x - i][y - j][z ^ 1], x - i, y - j, z ^ 1));\n dp[x - i][y - j][z ^ 1] += f(dp[x][y][z], rem_x, i, rem_y, j);\n dp[x - i][y - j][z ^ 1] %= mod;\n } else {\n dp[x - i][y - j][z ^ 1] += f(dp[x][y][z], rem_x, i, rem_y, j);\n dp[x - i][y - j][z ^ 1] %= mod;\n }\n }\n }\n }\n }\n }\n if (dist[cnt1][cnt2][1] == INF)\n pn(-1);\n else\n pn(dist[cnt1][cnt2][1]);\n pn(dp[cnt1][cnt2][1]);\n }\n\n int ni() {\n return in.nextInt();\n }\n\n void pn(long zx) {\n out.println(zx);\n }\n\n class Tuple {\n long d;\n int x;\n int y;\n int z;\n\n Tuple(long d, int x, int y, int z) {\n this.d = d;\n this.x = x;\n this.y = y;\n this.z = z;\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 }\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 }\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 }\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", "src_uid": "ebb0323a854e19794c79ab559792a1f7"} {"source_code": "import java.io.*;\nimport java.util.*;\npublic class D9 {\n\tstatic long[][] ans;\n\tpublic static void main(String[] args) throws IOException\t{\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tans = new long[36][36];\n\t\tfor(int i = 0; i < 36; i++)\n\t\t\tArrays.fill(ans[i], -1);\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tint n = Integer.parseInt(st.nextToken());\n\t\tint h = Integer.parseInt(st.nextToken());\n\t\tlong ret = 0;\n\t\tfor(int a = h; a <= n; a++)\n\t\t\tret += solve(n,a);\n\t\tSystem.out.println(ret);\n\t}\n\tpublic static long solve(int n, int h)\t{\n\t\tif(n < h || n >= (1L << h))\n\t\t\treturn 0;\n\t\tif(n == 0 && h == 0)\n\t\t\treturn 1;\n\t\tif(n == h){\n\t\t\treturn 1L << (h-1);\n\t\t}\n\t\tif(ans[n][h] != -1)\n\t\t\treturn ans[n][h];\n\t\tlong ret = 0;\n\t\tfor(int left = 0; left < n; left++)\t{\n\t\t\tint right = n-1-left;\n\t\t\tfor(int leftH = 0; leftH < h-1; leftH++)\n\t\t\t\tret += solve(left, leftH) * solve(right, h-1);\n\t\t\tfor(int rightH = 0; rightH < h-1; rightH++)\n\t\t\t\tret += solve(left, h-1) * solve(right, rightH);\n\t\t\tret += solve(left, h-1) * solve(right, h-1);\n\t\t}\n\t\tans[n][h] = ret;\n\t\treturn ret;\n\t}\n}\n// 27 11 should return 61162698256896\n// initial returned 167110392320", "src_uid": "faf12a603d0c27f8be6bf6b02531a931"} {"source_code": "import java.util.HashMap;\nimport java.io.BufferedReader;\nimport java.util.Comparator;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Collection;\nimport java.util.List;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.util.ArrayList;\nimport java.util.Set;\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_AnnAndCubics solver = new TaskE_AnnAndCubics();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE_AnnAndCubics {\n\n List<Long> factorials;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int k = in.nextInt();\n long S = in.nextLong();\n\n factorials = new ArrayList<Long>();\n factorials.add(1L);\n for (int i = 2;; ++i) {\n factorials.add(factorials.get(factorials.size()-1) * i);\n if (factorials.get(factorials.size()-1) > S) {\n break;\n }\n }\n factorials.remove(factorials.size()-1);\n\n\n int[] a = Utils.readIntArray(in, n);\n\n int n2 = n / 2;\n int n1 = n - n2;\n\n HashMap<Long, HashMap<Integer, Long>> leftSide = buildIt(n1, ArrayUtils.subArray(a, 0, n1), S, k);\n HashMap<Long, HashMap<Integer, Long>> rightSide = buildIt(n2, ArrayUtils.subArray(a, n1, n), S, k);\n\n long res = 0;\n for (long keyLeft : leftSide.keySet()) {\n long needKey = S - keyLeft;\n if (needKey >= 0 && rightSide.containsKey(needKey)) {\n res += getIt(leftSide.get(keyLeft), rightSide.get(needKey), k);\n }\n }\n out.println(res);\n }\n\n private long getIt(HashMap<Integer, Long> left, HashMap<Integer, Long> right, int k) {\n long res = 0;\n for (int key : left.keySet()) {\n for (int key2 : right.keySet()) {\n if (key + key2 <= k) {\n res += left.get(key) * right.get(key2);\n }\n }\n }\n return res;\n }\n\n private HashMap<Long, HashMap<Integer, Long>> buildIt(int n, int[] a, long S, int k) {\n HashMap<Long, HashMap<Integer, Long>> res = new HashMap<Long, HashMap<Integer, Long>>();\n\n for (int set = 0; set < (1 << n); ++set) {\n for (int subset = set; subset >= 0; subset = ((subset - 1) & set)) {\n if (Integer.bitCount(subset) > k) continue;\n long sum = 0;\n boolean badMask = false;\n for (int i = 0; i < n; ++i) {\n if (BitUtils.checkBit(subset, i)) {\n if (a[i] > factorials.size()) {\n badMask = true;\n break;\n } else {\n sum += factorials.get(a[i] - 1);\n }\n } else if (BitUtils.checkBit(set, i)) {\n sum += a[i];\n }\n if (sum > S) {\n badMask = true;\n break;\n }\n }\n if (!badMask) {\n if (sum <= S) {\n addToRes(res, Integer.bitCount(subset), sum);\n }\n }\n if (subset == 0) break;\n }\n }\n return res;\n }\n\n private void addToRes(HashMap<Long, HashMap<Integer, Long>> dict, int k, long sum) {\n if (!dict.containsKey(sum)) {\n HashMap<Integer, Long> map = new HashMap<Integer, Long>();\n map.put(k, 1L);\n dict.put(sum, map);\n } else {\n HashMap<Integer, Long> map = dict.get(sum);\n if (!map.containsKey(k)) {\n map.put(k, 1L);\n } else {\n map.put(k, map.get(k) + 1);\n }\n dict.put(sum, map);\n }\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();\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 long nextLong() {\n return Long.parseLong(nextString());\n }\n\n}\n\nclass Utils {\n public static int[] readIntArray(InputReader in, 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}\n\nclass ArrayUtils {\n\n public static int[] subArray(int[] a, int start, int finish) {\n int[] result = new int[finish - start];\n for (int i = start; i < finish; ++i) {\n result[i-start] = a[i];\n }\n return result;\n }\n\n}\n\nclass BitUtils {\n public static boolean checkBit(int mask, int bit) {\n return (mask & (1 << bit)) > 0;\n }\n\n}\n\n", "src_uid": "2821a11066dffc7e8f6a60a8751cea37"} {"source_code": "import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class MadokaAndTheBestUniversity {\r\n\tprivate static final int N_MAX = 100_000;\r\n\t\r\n\tprivate static final int MOD = 1_000_000_007;\r\n\t\r\n\tprivate static final IntList[] FACTORS = new IntList[N_MAX + 1];\r\n\tstatic {\r\n\t\tfor (int i = 1; i <= N_MAX; ++i) {\r\n\t\t\tFACTORS[i] = new IntList();\r\n\t\t}\r\n\t\tfor (int i = 1; i <= N_MAX; ++i) {\r\n\t\t\tfor (int j = i; j <= N_MAX; j += i) {\r\n\t\t\t\tFACTORS[j].add(i);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\r\n\tprivate static final int[] TOTIENT = new int[N_MAX + 1];\r\n\tstatic {\r\n\t\tfor (int i = 1; i < TOTIENT.length; ++i) {\r\n\t\t\tTOTIENT[i] = i;\r\n\t\t}\r\n\t\tfor (int i = 2; i < TOTIENT.length; ++i) {\r\n\t\t\tif (TOTIENT[i] != i) {\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tfor (int j = i; j < TOTIENT.length; j += i) {\r\n\t\t\t\tTOTIENT[j] -= TOTIENT[j] / i;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\r\n\tpublic static void solve(FastIO io) {\r\n\t\tfinal int N = io.nextInt();\r\n\r\n\t\tlong total = 0;\r\n\t\tfor (int c = 1; c + 2 <= N; ++c) {\r\n\t\t\tint rem = N - c;\r\n\t\t\tIntList facs = FACTORS[rem];\r\n\t\t\tfor (int i = facs.size() - 2; i >= 0; --i) {\r\n\t\t\t\tint fi = facs.get(i);\r\n\t\t\t\ttotal += 1L * lcm(c, fi) * TOTIENT[rem / fi];\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\t/**\r\n\t * Computes the LCM (least common multiple) between all the numbers.\r\n\t */\r\n\tpublic static int lcm(int... arr) {\r\n\t\tint lcm = arr[0];\r\n\t\tfor (int i = 1; i < arr.length; i++)\r\n\t\t\tlcm = lcm * arr[i] / gcd(lcm, arr[i]);\r\n\r\n\t\treturn lcm;\r\n\t}\r\n\r\n\tprivate static class IntList extends ArrayList<Integer> {\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}", "src_uid": "c3694a6ff95c64bef8cbe8834c3fd6cb"} {"source_code": "\nimport java.util.*;\nimport java.io.*;\n\npublic class E {\n\n static int N, M, K;\n static String s;\n static StringTokenizer st;\n static int[] d;\n static long[] fact;\n\n static HashSet<Integer> hm = new HashSet();\n static long c(int[] d) {\n //System.out.println(Arrays.toString(d));\n int l = Arrays.hashCode(d);\n if(hm.contains(l)){\n return 0;\n }\n long top = 0;\n long bot = 1;\n int sum = 0;\n for (int i = 0; i < d.length; i++) {\n sum += d[i];\n bot *= fact[d[i]];\n }\n //System.out.println(sum);\n long ans = fact[sum];\n for (int i = 0; i < d.length; i++) {\n ans /= fact[d[i]];\n }\n //long ans = top / bot;\n //System.out.println(top + \" \" + bot);\n //System.out.println(ans);\n \n long ans2 = 0;\n if (d[0] > 0) {;\n ans2 = fact[sum-1];\n d[0]--;\n for (int i = 0; i < d.length; i++) {\n ans2 /= fact[d[i]];\n }\n d[0]++;\n }\n \n hm.add(l);\n\n //System.out.println(Arrays.toString(d) + \" \" + sum + \" \" + ans + \" \" + ans2);\n return ans-ans2;\n }\n\n public static long DFS(int[] d) {\n //System.out.println(Arrays.toString(d));\n long ans = c(d);\n //System.out.println(ans);\n for (int i = 0; i < d.length; i++) {\n if (d[i] > 1) {\n int[] d2 = new int[d.length];\n for (int j = 0; j < d.length; j++) {\n d2[j] = d[j];\n }\n d2[i]--;\n ans += DFS(d2);\n }\n }\n //System.out.println(\"returning \" + ans);\n if (ans < 0) {\n while (true) {\n\n }\n }\n\n return ans;\n }\n\n public static void main(String[] args) throws Exception {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter out = new PrintWriter(System.out);\n\n fact = new long[20];\n fact[0] = 1;\n\n for (int i = 1; i < 20; i++) {\n fact[i] = fact[i - 1] * i;\n }\n\n //System.out.println(Arrays.toString(fact));\n //System.out.println(fact[18]);\n int[] d = new int[10];\n long N = Long.parseLong(br.readLine());\n while (N > 0) {\n d[(int) (N % 10)]++;\n N /= 10;\n }\n\n long ans = DFS(d);\n System.out.println(ans);\n //System.out.println(fact[19]);\n //System.out.println(c(d));\n\n out.close();\n }\n}\n", "src_uid": "7f4e533f49b73cc2b96b4c56847295f2"} {"source_code": "import java.util.*;\n\npublic class CodeForces {\n\tScanner scan = new Scanner(System.in);\n\t\n\tprivate static long gcd(long a, long b)\n\t{\n\t while (b > 0)\n\t {\n\t long temp = b;\n\t b = a % b;\n\t a = temp;\n\t }\n\t return a;\n\t}\n\n\tprivate static long gcd(long[] input)\n\t{\n\t long result = input[0];\n\t for(int i = 1; i < input.length; i++) result = gcd(result, input[i]);\n\t return result;\n\t}\n\t\n\tprivate static long lcm(long a, long b)\n\t{\n\t return a * (b / gcd(a, b));\n\t}\n\n\tprivate static long lcm(long[] input)\n\t{\n\t long result = input[0];\n\t for(int i = 1; i < input.length; i++) result = lcm(result, input[i]);\n\t return result;\n\t}\n\t\n\tCodeForces()\n\t{\n\tString s,x,y,a,b;\n\ts = scan.nextLine();\n\tString [] temp = s.split(\" \");\n\tx = temp[0];\n\ty = temp[1];\n\ta = temp[2];\n\tb = temp[3];\n\tboolean flag = false;\n\tlong[] input = new long[2];\n\tinput[0] = Integer.parseInt(x);\n\tinput[1] = Integer.parseInt(y);\n\tlong kpk = lcm(input);\n\tlong counter = 0;\n\tlong start = 0;\n\tfor(long i=Integer.parseInt(a);i<=Integer.parseInt(b)&&!flag;i++)\n\t{\n\t\tif(i%Integer.parseInt(y)==0&&i%Integer.parseInt(x)==0)\n\t\t{\n\t\t\t++counter;\n\t\t\tflag = true;\n\t\t\tstart = i;\n\t\t}\t\n\t}\n\tlong remain = flag?(Integer.parseInt(b) - start) / kpk:0;\n\tcounter+=remain;\n\tSystem.out.println(counter);\n\t}\n\tpublic static void main(String[] args)\n\t{\n\tnew CodeForces();\n\t}\n}\n", "src_uid": "c7aa8a95d5f8832015853cffa1374c48"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.io.PrintWriter;\nimport java.util.TreeMap;\npublic class E1113 \n{\n static class QN{\n int index;\n long sum;\n QN(int in,long an){\n index=in;\n sum=an;\n }\n }\n static class SegmentTree{\n long sum,pmin,lazy;\n int st,en;\n boolean rem;\n SegmentTree left,right;\n SegmentTree(int _st,int _en,long _v){\n st=_st;\n en=_en;\n lazy=_v;\n rem=true;\n sum=(en-st+1)*lazy;\n pmin=Math.min(lazy,sum);\n }\n long pmin(){\n return rem?(Math.min(lazy,(en-st+1)*lazy)):(pmin);\n }\n long sum(){\n return rem?((en-st+1)*lazy):(sum);\n }\n void update(int l,int r,long v){\n //completely outside\n if(l>en||r<st)\n return;\n //completely inside\n if(l<=st&&r>=en){\n //update lazy;\n lazy=v;\n rem=true;\n return;\n }\n //partial cover\n lazyPropagate();\n left.update(l, r, v);\n right.update(l, r, v);\n sum=left.sum()+right.sum();\n pmin=Math.min(left.pmin(),left.sum()+right.pmin());\n return;\n }\n void lazyPropagate(){\n if(left==null){\n int mid=(st+en)>>1;\n left=new SegmentTree(st,mid,lazy);\n right=new SegmentTree(mid+1,en,lazy);\n }else if(rem){\n left.lazy=lazy;\n right.lazy=lazy;\n left.rem=true;\n right.rem=true;\n }\n if(rem){\n sum=(en-st+1)*lazy;\n pmin=Math.min(lazy,sum);\n }\n rem=false;\n }\n /**returns least index which has value <= given value**/\n QN query(int l,int r,long v,long su){\n //no cover\n if(st>r||en<l)\n return new QN(-1,0);\n //full cover\n if(l<=st&&en<=r){\n if(su+pmin()<=v)\n return query2(v,su);\n return new QN(-1,su+sum());\n }\n lazyPropagate();\n \n QN q1=left.query(l,r,v,su);\n if(q1.index!=-1)\n return q1;\n q1=right.query(l,r,v,q1.sum);\n return q1; \n }\n QN query2(long v,long su){\n if(st==en)\n return new QN(st,su+sum());\n lazyPropagate();\n if(left.pmin()+su<=v)\n return left.query2(v,su);\n else\n return right.query2(v,su+left.sum());\n \n }\n \n }\n static class Scanner\n {\n BufferedReader br;\n StringTokenizer tk=new StringTokenizer(\"\");\n public Scanner(InputStream is) \n {\n br=new BufferedReader(new InputStreamReader(is));\n }\n public int nextInt() throws IOException\n {\n if(tk.hasMoreTokens())\n return Integer.parseInt(tk.nextToken());\n tk=new StringTokenizer(br.readLine());\n return nextInt();\n }\n public long nextLong() throws IOException\n {\n if(tk.hasMoreTokens())\n return Long.parseLong(tk.nextToken());\n tk=new StringTokenizer(br.readLine());\n return nextLong();\n }\n public String next() throws IOException\n {\n if(tk.hasMoreTokens())\n return (tk.nextToken());\n tk=new StringTokenizer(br.readLine());\n return next();\n }\n public String nextLine() throws IOException\n {\n tk=new StringTokenizer(\"\");\n return br.readLine();\n }\n public double nextDouble() throws IOException\n {\n if(tk.hasMoreTokens())\n return Double.parseDouble(tk.nextToken());\n tk=new StringTokenizer(br.readLine());\n return nextDouble();\n }\n public char nextChar() throws IOException\n {\n if(tk.hasMoreTokens())\n return (tk.nextToken().charAt(0));\n tk=new StringTokenizer(br.readLine());\n return nextChar();\n }\n public int[] nextIntArray(int n) throws IOException\n {\n int a[]=new int[n];\n for(int i=0;i<n;i++)\n a[i]=nextInt();\n return a;\n }\n public long[] nextLongArray(int n) throws IOException\n {\n long a[]=new long[n];\n for(int i=0;i<n;i++)\n a[i]=nextLong();\n return a;\n }\n public int[] nextIntArrayOneBased(int n) throws IOException\n {\n int a[]=new int[n+1];\n for(int i=1;i<=n;i++)\n a[i]=nextInt();\n return a;\n }\n public long[] nextLongArrayOneBased(int n) throws IOException\n {\n long a[]=new long[n+1];\n for(int i=1;i<=n;i++)\n a[i]=nextLong();\n return a;\n }\n \n \n }\n \n public static void main(String args[]) throws IOException\n {\n Scanner in=new Scanner(System.in);\n PrintWriter out=new PrintWriter(System.out);\n SegmentTree st=new SegmentTree(1,1000000000,0);\n int q=in.nextInt();\n TreeMap<Integer,Integer> mp=new TreeMap<>();\n mp.put(0,0);\n mp.put(1000000001,0);\n while(q--!=0){\n int tp=in.nextInt();\n switch(tp){\n case 1:\n int tm=in.nextInt();\n int vl=in.nextInt();\n int nxt=mp.higherKey(tm)-1;\n st.update(tm, nxt, vl);\n mp.put(tm,vl);\n break;\n case 2:\n int tc=in.nextInt();\n int vp=mp.lowerEntry(tc).getValue();\n int net=mp.higherKey(tc)-1;\n st.update(tc, net, vp);\n mp.remove(tc);\n break;\n case 3:\n int l=in.nextInt();\n int lc=l;\n l=mp.ceilingKey(l);\n int r=in.nextInt();\n int v=in.nextInt();\n if(v==0){\n out.println(lc);\n continue;\n }\n if(l>=r){\n out.println(-1);\n continue;\n }\n QN aa=st.query(l, r-1, -v, 0);\n if(aa.index==-1)\n out.println(-1);\n else{\n int spd=mp.floorEntry(aa.index).getValue();\n double remv=-(v+(aa.sum-spd));\n double anss=aa.index;\n anss+=remv/spd;\n out.println(anss);\n \n }\n \n }\n \n }\n out.close();\n }\n\n}\n", "src_uid": "23440d055baf6c831e91e76b99b9ada8"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Ada extends PrintWriter {\n Ada() { super(System.out, true); }\n Scanner sc = new Scanner(System.in);\n public static void main(String[] $) {\n Ada o = new Ada(); o.main(); o.flush();\n }\n\n int compress(int[] aa, int n) {\n Random rand = new Random();\n for (int i = 0; i < n; i++) {\n int j = rand.nextInt(i + 1);\n int tmp = aa[i]; aa[i] = aa[j]; aa[j] = tmp;\n }\n Arrays.sort(aa, 0, n);\n int m = 1;\n for (int i = 1; i < n; i++)\n if (aa[i] != aa[i - 1])\n aa[m++] = aa[i];\n return m;\n }\n void main() {\n int a = sc.nextInt();\n int b = sc.nextInt();\n int n = a + b;\n int s = (int) Math.sqrt(n) + 1;\n int[] gg = new int[s + s];\n int m = 0;\n for (int g = 1; g <= s; g++)\n gg[m++] = g;\n for (int k = 1; k <= s; k++) {\n int g = n / k;\n gg[m++] = g;\n }\n m = compress(gg, m);\n int ans = 0;\n for (int h = 0; h < m; h++) {\n int g = gg[h];\n int al = (int) ((a + (long) g) / (g + 1));\n int bl = (int) ((b + (long) g) / (g + 1));\n int ar = a / g;\n int br = b / g;\n if (al <= ar && bl <= br) {\n int l = Math.max(n / (g + 1) + 1, al + bl);\n int r = Math.min(n / g, ar + br);\n if (l <= r)\n ans += r - l + 1;\n }\n }\n println(ans);\n }\n}", "src_uid": "0e6a204565fef118ea99d2fa1e378dd0"} {"source_code": "import java.io.*;\nimport java.util.*;\nimport java.lang.*;\nimport java.math.*;\nimport java.text.DecimalFormat;\nimport java.lang.reflect.Array;\nimport java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigDecimal;\npublic class Codeforces{\n\tpublic static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));\n\tstatic long MOD = (long)(1e9+7);\n\tstatic long MOD2 = MOD*MOD;\n\t//static long MOD = 998244353;\n\tstatic FastReader sc = new FastReader();\n\tstatic int pInf = Integer.MAX_VALUE;\n\tstatic int nInf = Integer.MIN_VALUE;\n\tpublic static void main(String[] args){\n\t\tint test = 1;\n\t\t//test = sc.nextInt();\n\t\twhile(test-->0){\n\t\t\tlong a = sc.nextLong();\n\t\t\tlong b = sc.nextLong();\n\t\t\tlong n = sc.nextLong();\n\t\t\tlong x = sc.nextLong();\n\t\t\tif(a==1) {\n\t\t\t\tout.println(add(x, mul(n, b)));\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tlong a1 = mul(fastExpo(a, n), x);\n\t\t\tlong a2 = mul(b, mul((fastExpo(a, n)-1),finextDoubleMMI_fermat(a-1, (int)MOD)));\n\t\t\tout.println(add(a1, a2));\n\t\t}\n\t\tout.close();\n\t}\n\tpublic static long solve(long a, long b, long x, long y, long n) {\n\t\tif(a-x<n) {\n\t\t\tn = n-(a-x);\n\t\t\ta = x;\n\t\t\tb = Math.max(y, b-n);\n\t\t}\n\t\telse {\n\t\t\ta = a-n;\n\t\t}\n\t\treturn a*b;\n\t}\n\tpublic static int lowerBound(int key, ArrayList<Integer> A) {\n\t\tint s = 0;\n\t\tint e = A.size()-1;\n\t\tif(e==-1) {\n\t\t\treturn 0;\n\t\t}\n\t\tint ans = -1;\n\t\twhile(s<=e) {\n\t\t\tint m = s+(e-s)/2;\n\t\t\tif(A.get(m)>=key) {\n\t\t\t\tans = m;\n\t\t\t\te = m-1;\n\t\t\t}\n\t\t\telse {\n\t\t\t\ts = m+1;\n\t\t\t}\n\t\t}\n\t\treturn ans==-1?s:ans;\n\t}\n\tpublic static int upperBound(int key, ArrayList<Integer> A) {\n\t\tint s = 0;\n\t\tint e = A.size()-1;\n\t\tif(e==-1) {\n\t\t\treturn 0;\n\t\t}\n\t\tint ans = -1;\n\t\twhile(s<=e) {\n\t\t\tint m = s+(e-s)/2;\n\t\t\tif(A.get(m)>key) {\n\t\t\t\tans = m;\n\t\t\t\te = m-1;\n\t\t\t}\n\t\t\telse {\n\t\t\t\ts = m+1;\n\t\t\t}\n\t\t}\n\t\treturn ans==-1?s:ans;\n\t}\n\tpublic static long c2(long n) {\n\t\tif((n&1)==0) {\n\t\t\treturn mul(n/2, n-1);\n\t\t}\n\t\telse {\n\t\t\treturn mul(n, (n-1)/2);\n\t\t}\n\t}\n\tpublic static long mul(long a, long b){\n\t return ((a%MOD)*(b%MOD))%MOD;\n\t}\n\tpublic static long add(long a, long b){\n\t return ((a%MOD)+(b%MOD))%MOD;\n\t}\n\tpublic static long sub(long a, long b){\n\t return ((a%MOD)-(b%MOD))%MOD;\n\t}\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n//Integer.lowestOneBit(i) Equals k where k is the position of the first one in the binary\n//Integer.highestOneBit(i) Equals k where k is the position of the last one in the binary\n//Integer.bitCount(i) returns the number of one-bits\n//Collections.sort(A,(p1,p2)->(int)(p2.x-p1.x)) To sort ArrayList in descending order wrt values of x.\n// Arrays.parallelSort(a,new Comparator<TPair>() {\n// \t\tpublic int compare(TPair a,TPair b) {\n// \t\t\tif(a.y==b.y) return a.x-b.x;\n// \t\t\treturn b.y-a.y;\n// \t\t}\n// \t});\n////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n//PrimeFactors \n public static ArrayList<Long> primeFactors(long n) {\n ArrayList<Long> arr = new ArrayList<>();\n if (n % 2 == 0)\n arr.add((long) 2);\n while (n % 2 == 0)\n n /= 2;\n for (long i = 3; i <= Math.sqrt(n); i += 2) {\n int flag = 0;\n while (n % i == 0) {\n n /= i;\n flag = 1;\n }\n if (flag == 1)\n arr.add(i);\n }\n if (n > 2)\n arr.add(n);\n return arr;\n }\n//Pair Class\n\tstatic class Pair implements Comparable<Pair>{\n\t\tint x;\n\t\tint y;\n\t\tint len;\n\t\tpublic Pair(int x, int y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t\tthis.len = y-x+1;\n\t\t}\n\t\t/*@Override\n\t\tpublic int compareTo(Pair o) {\n\t\t\tif(this.x==o.x){\n\t\t\t return (this.y-o.y);\n\t\t\t}\n\t\t\treturn (this.x-o.x);\n\t\t}*/\n\t\t@Override\n\t\tpublic int compareTo(Pair o) {\n\t\t\tif(this.len==o.len) {\n\t\t\t\treturn this.x-o.x;\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn o.len-this.len;\n\t\t\t}\n\t\t}\n\t}\n\tstatic class TPair implements Comparable<TPair>{\n\t\tint two;\n\t\tint three;\n\t\tint prime;\n\t\tpublic TPair(int two, int three, int prime) {\n\t\t\tthis.two = two;\n\t\t\tthis.three = three;\n\t\t\tthis.prime = prime;\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(TPair o) {\n\t\t\tif(this.three==o.three){\n\t\t\t return (this.two-o.two);\n\t\t\t}\n\t\t\treturn -1*(this.three-o.three);\n\t\t}\n\t}\n//nCr\n\tstatic long ncr(long n, long k) {\n long ret = 1;\n for (long x = n; x > n - k; x--) {\n ret *= x;\n ret /= (n - x + 1);\n }\n\n return ret;\n }\n\tstatic long finextDoubleMMI_fermat(long n,int M)\n {\n return fastExpo(n,M-2);\n }\n \n static long nCrModPFermat(int n, int r, int p) \n { \n if (r == 0) \n return 1; \n long[] fac = new long[n+1]; \n fac[0] = 1; \n for (int i = 1 ;i <= n; i++) \n fac[i] = fac[i-1] * i % p; \n return (fac[n]* finextDoubleMMI_fermat(fac[r], p)% p * finextDoubleMMI_fermat(fac[n-r], p) % p) % p; \n }\n//Kadane's Algorithm \n static long maxSubArraySum(ArrayList<Long> a) { \n \tif(a.size()==0) {\n \t\treturn 0;\n \t}\n \tlong max_so_far = a.get(0); \n \tlong curr_max = a.get(0); \n \tfor (int i = 1; i < a.size(); i++) { \n curr_max = Math.max(a.get(i), curr_max+a.get(i)); \n max_so_far = Math.max(max_so_far, curr_max); \n \t} \n \treturn max_so_far; \n } \n//Shuffle Sort\n static final Random random=new Random();\n\tstatic void ruffleSort(int[] a) {\n\t\tint n=a.length;//shuffle, then sort \n\t\tfor (int i=0; i<n; i++) {\n\t\t\tint oi=random.nextInt(n), temp=a[oi];\n\t\t\ta[oi]=a[i]; a[i]=temp;\n\t\t}\n\t\tArrays.sort(a);\n\t}\n//Merge Sort\n\tstatic 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<n1; ++i)\n L[i] = arr[l + i];\n for (int j=0; j<n2; ++j)\n R[j] = arr[m + 1+ j];\n \n \n /* Merge the temp arrays */\n \n // Initial indexes of first and second subarrays\n int i = 0, j = 0;\n \n // Initial index of merged subarry array\n int k = l;\n while (i < n1 && j < n2)\n {\n if (L[i] <= R[j])\n {\n arr[k] = L[i];\n i++;\n }\n else\n {\n arr[k] = R[j];\n j++;\n }\n k++;\n }\n \n /* Copy remaining elements of L[] if any */\n while (i < n1)\n {\n arr[k] = L[i];\n i++;\n k++;\n }\n \n /* Copy remaining elements of R[] if any */\n while (j < n2)\n {\n arr[k] = R[j];\n j++;\n k++;\n }\n }\n \n // Main function that sorts arr[l..r] using\n // merge()\n static void sort(long arr[], int l, int r)\n {\n if (l < r)\n {\n // Find the middle point\n int m = (l+r)/2;\n \n // Sort first and second halves\n sort(arr, l, m);\n sort(arr , m+1, r);\n \n // Merge the sorted halves\n merge(arr, l, m, r);\n }\n }\n//Brian Kernighans Algorithm\n static long countSetBits(long n){\n if(n==0) return 0;\n return 1+countSetBits(n&(n-1));\n }\n//Factorial\n static long factorial(long n){\n if(n==1) return 1;\n if(n==2) return 2;\n if(n==3) return 6;\n return n*factorial(n-1);\n }\n//Euclidean Algorithm\n static long gcd(long A,long B){\n if(B==0) return A;\n return gcd(B,A%B);\n }\n//Modular Exponentiation\n static long fastExpo(long x,long n){\n if(n==0) return 1;\n if((n&1)==0) return fastExpo((x*x)%MOD,n/2)%MOD;\n return ((x%MOD)*fastExpo((x*x)%MOD,(n-1)/2))%MOD;\n }\n//AKS Algorithm\n static boolean isPrime(long n){\n if(n<=1) return false;\n if(n<=3) return true;\n if(n%2==0 || n%3==0) return false;\n for(int i=5;i<=Math.sqrt(n);i+=6)\n if(n%i==0 || n%(i+2)==0) return false;\n return true;\n }\n//Reverse an array\n static <T> void reverse(T arr[],int l,int r){\n \tCollections.reverse(Arrays.asList(arr).subList(l, r));\n }\n //Print array\n static void print1d(int arr[]) {\n \tout.println(Arrays.toString(arr));\n }\n static void print2d(int arr[][]) {\n \tfor(int a[]: arr) out.println(Arrays.toString(a));\n }\n//Sieve of eratosthenes\n static int[] findPrimes(int n){\n boolean isPrime[]=new boolean[n+1];\n ArrayList<Integer> a=new ArrayList<>();\n int result[];\n Arrays.fill(isPrime,true);\n isPrime[0]=false;\n isPrime[1]=false;\n for(int i=2;i*i<=n;++i){\n if(isPrime[i]==true){\n for(int j=i*i;j<=n;j+=i) isPrime[j]=false;\n }\n }\n for(int i=0;i<=n;i++) if(isPrime[i]==true) a.add(i);\n result=new int[a.size()];\n for(int i=0;i<a.size();i++) result[i]=a.get(i);\n return result;\n \n }\n//Indivisual factors of all nos till n\n static ArrayList<Integer>[] indiFactors(int n){\n \tArrayList<Integer>[] A = new ArrayList[n+1];\n \tfor(int i = 0; i <= n; i++) {\n \t\tA[i] = new ArrayList<>();\n \t}\n \tint[] sieve = new int[n+1];\n \tfor(int i=2;i<=n;i++) {\n \t\tif(sieve[i]==0) {\n \t\t\tfor(int j=i;j<=n;j+=i) if(sieve[j]==0) {\n \t\t\t\t//sieve[j]=i;\n \t\t\t\tA[j].add(i);\n \t\t\t}\n \t\t}\n \t}\n \treturn A;\n }\n//Segmented Sieve\n static boolean[] segmentedSieve(long l, long r){\n \tboolean[] segSieve = new boolean[(int)(r-l+1)];\n \tArrays.fill(segSieve, true);\n \tint[] prePrimes = findPrimes((int)Math.sqrt(r));\n \tfor(int p:prePrimes) {\n \t\tlong low = (l/p)*p;\n \t\tif(low < l) {\n \t\t\tlow += p;\n \t\t}\n \t\tif(low == p) {\n \t\t\tlow += p;\n \t\t}\n \t\tfor(long j = low; j<= r; j += p) {\n \t\t\tsegSieve[(int) (j-l)] = false;\n \t\t}\n \t}\n \tif(l==1) {\n \t\tsegSieve[0] = false;\n \t}\n \treturn segSieve;\n }\n//Euler Totent function\n static long countCoprimes(long n){\n ArrayList<Long> prime_factors=new ArrayList<>();\n long x=n,flag=0;\n while(x%2==0){\n if(flag==0) prime_factors.add(2L);\n flag=1;\n x/=2;\n }\n for(long i=3;i*i<=x;i+=2){\n flag=0;\n while(x%i==0){\n if(flag==0) prime_factors.add(i);\n flag=1;\n x/=i;\n }\n }\n if(x>2) prime_factors.add(x);\n double ans=(double)n;\n for(Long p:prime_factors){\n ans*=(1.0-(Double)1.0/p);\n }\n return (long)ans;\n }\n\tstatic long modulo = (long)1e9+7;\n\tpublic static long modinv(long x){\n\t return modpow(x, modulo-2);\n\t}\n\tpublic static long modpow(long a, long b){\n\t if(b==0){\n\t return 1;\n\t }\n\t long x = modpow(a, b/2);\n\t x = (x*x)%modulo;\n\t if(b%2==1){\n\t return (x*a)%modulo;\n\t }\n\t return x;\n\t}\n\tpublic static class FastReader {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\t//it reads the data about the specified point and divide the data about it ,it is quite fast\n\t\t//than using direct \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.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (Exception r) {\n\t\t\t\t\tr.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());//converts string to integer\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tString nextLine() {\n\t\t\tString str = \"\";\n\t\t\ttry {\n\t\t\t\tstr = br.readLine();\n\t\t\t} catch (Exception r) {\n\t\t\t\tr.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\t}\n}", "src_uid": "e22a1fc38c8b2a4cc30ce3b9f893028e"} {"source_code": "import java.util.Scanner;\n\npublic class Main2 {\n\tpublic static void TokitsukazeAndEnhancement573() {\n\t\tScanner sc=new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\tint add=0;\n\t\tif(getCategory(n+1)<getCategory(n)) {\n\t\t\tn++;\n\t\t\tadd++;\n\t\t\tif(getCategory(n+1)<getCategory(n)) {\n\t\t\t\tn++;\n\t\t\t\tadd++;\n\t\t\t}\n\t\t}\n\t\telse if(getCategory(n+2)<getCategory(n)) {\n\t\t\tn+=2;\n\t\t\tadd+=2;\n\t\t\t\n\t\t}\n\t\tSystem.out.println(add+\" \"+getCategory(n));\n\t\t\n\t\t\n\t}\n\tpublic static char getCategory(int n) {\n\t\tif(n%4==1)\n\t\t\treturn 'A';\n\t\telse if(n%4==3)\n\t\t\treturn 'B';\n\t\telse if(n%4==2)\n\t\t\treturn 'C';\n\t\t\n\t\t\treturn 'D';\n\t\t\n\t}\n\tpublic static void main(String[] args) {\n\t\tTokitsukazeAndEnhancement573();\n\t}\n\n}\n", "src_uid": "488e809bd0c55531b0b47f577996627e"} {"source_code": "/*\n * Author: Minho Kim (ISKU)\n * Date: March 5, 2018\n * E-mail: minho.kim093@gmail.com\n *\n * https://github.com/ISKU/Algorithm\n * http://codeforces.com/problemset/problem/931/A\n */\n\nimport java.util.*;\n\npublic class A {\n\tpublic static void main(String... args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint first = sc.nextInt();\n\t\tint second = sc.nextInt();\n\n\t\tif (first > second) {\n\t\t\tint temp = second;\n\t\t\tsecond = first;\n\t\t\tfirst = temp;\n\t\t}\n\n\t\tint ii = 1, jj = 1;\n\t\tint isum = 0, jsum = 0;\n\t\tfor (int i = first, j = second; true;) {\n\t\t\ti++;\n\t\t\tisum += ii++;\n\t\t\tif (i == j)\n\t\t\t\tbreak;\n\t\t\tj--;\n\t\t\tjsum += jj++;\n\t\t\tif (i == j)\n\t\t\t\tbreak;\n\t\t}\n\n\t\tSystem.out.print(isum + jsum);\n\t}\n}", "src_uid": "d3f2c6886ed104d7baba8dd7b70058da"} {"source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class Solution{\n \n static void affiche(int n,PrintWriter out){\n for(int i=0;i<n/2;i++){\n out.print(\"4\");\n }\n for(int i=0;i<n/2;i++){\n out.print(\"7\");\n }\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 \n PrintWriter out = new PrintWriter(System.out);\n \n //int n = Integer.parseInt(st.nextToken());\n String s = br.readLine();\n int n = s.length();\n int last = -1;\n if(n%2==1){\n n++;\n affiche(n,out);\n }else{\n int[] a = new int[n];\n for(int i=0;i<n;i++){\n a[i] = (int)(s.charAt(i)-'0');\n }\n boolean ok = true;;\n for(int i=0;i<n;i++){\n if(a[i]!=4 && a[i]!=7){\n ok = false;\n break;\n }\n }\n int four = 0;\n int seven = 0;\n for(int i=0;i<n;i++){\n if(a[i]==4) four++;\n else seven++;\n }\n if(four!=seven) ok = false;\n \n if(ok){\n out.print(s);\n }else{\n \n \n \n last = -1;\n four = 0;\n seven = 0;\n for(int i=0;i<n;i++){\n if(a[i]>7) break;\n if(a[i]!=4 && a[i]!=7){\n if(a[i]<4) four++;\n else seven++;\n if(four+n-i-1>=seven) last = i;\n break;\n }\n if(a[i]==4){\n if(four+n-i-1>=seven+1) last = i;\n four++;\n }else seven++;\n \n if(four+n-i-1<seven) break;\n \n }\n \n if(last==-1) {\n affiche(n+2,out);\n }else{\n \n \n four = 0;\n seven = 0;\n for(int i=0;i<last;i++){\n out.print(a[i]);\n if(a[i]==4) four++;\n else seven++;\n }\n if(a[last]<4){\n out.print(\"4\");\n four++;\n } \n else{\n out.print(\"7\");\n seven++;\n } \n \n for(int i=0;i<n/2 - four;i++){\n out.print(\"4\");\n }\n for(int i=0;i<n/2 - seven;i++){\n out.print(\"7\");\n }\n \n }\n }\n }\n out.println(\"\");\n \n out.flush();\n }\n \n}", "src_uid": "77b5f83cdadf4b0743618a46b646a849"} {"source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\npublic class Codechef\n{\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tint c = 0, len = Integer.parseInt(br.readLine());\n\t\tString s = br.readLine();\n\t\tfor(int i = 0;i < len;i++)\n\t\t{ \n\t\t char ch = s.charAt(i);\n\t\t if(ch == '0')\n\t\t {\n\t\t if(c > 0)\n\t\t { \n\t\t System.out.print(c);\n\t\t c = 0;\n\t\t }\n\t\t if(i == len - 1 || s.charAt(i+1) == '0')\n\t\t {\n\t\t System.out.print(\"0\");\n\t\t }\n\t\t }\n\t\t else\n\t\t { \n\t\t c++;\n\t\t }\n\t\t}\n\t\tif(s.charAt(len-1)== '1')\n\t\tSystem.out.println(c);\n\t\telse\n\t\tSystem.out.println();\n\t}\n}", "src_uid": "a4b3da4cb9b6a7ed0a33a862e940cafa"} {"source_code": "import java.util.Scanner;\n\npublic class Codefest16Trivial {\n\tpublic static void main(String[] args) {\n\t\tScanner kboard = new Scanner(System.in);\n\t\t\n\t\tint m = Integer.parseInt(kboard.nextLine());\n\t\t\n\t\tint[] fives = {5, 25, 125, 625, 3125, 15625, 78125, 390625, 1953125};\n\t\t\n\t\tint ans = -1;\n\t\tfor (int i = 1; i <= m * 5; i++) {\n\t\t\tint sum = 0;\n\t\t\tfor (Integer j: fives) {\n\t\t\t\tsum += i / j;\n\t\t\t}\n\t\t\tif (sum == m) {\n\t\t\t\tans = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (ans == -1) {\n\t\t\tSystem.out.println(\"0\");\n\t\t} else {\n\t\t\tif (ans == 1) {\n\t\t\t\tSystem.out.println(\"4\");\n\t\t\t\tSystem.out.println(\"1 2 3 4\");\n\t\t\t} else {\n\t\t\t\tSystem.out.println(\"5\");\n\t\t\t\tfor (int i = 0; i < 5; i++) {\n\t\t\t\t\tSystem.out.print((ans + i) + \" \");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n", "src_uid": "c27ecc6e4755b21f95a6b1b657ef0744"} {"source_code": "//package CP.Ladder11;\n\nimport java.io.*;\nimport java.util.*;\nimport java.util.stream.IntStream;\n\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\n@SuppressWarnings(\"ALL\")\npublic class ABusinessTrip {\n public static void main(String[] $) throws IOException {\n ABusinessTrip o = new ABusinessTrip();\n o.main();\n out.flush();\n out.close();\n }\n\n void main() throws IOException {\n int k = in.ri();\n int[] a = in.ria(12);\n Arrays.sort(a);\n ARR.reverse(a);\n int ans = 0;\n int count = 0;\n for (int i = 0; i < 12; i++) {\n if (ans < k) {\n ans += a[i];\n count++;\n } else {\n break;\n }\n }\n if (ans < k) out.prln(-1);\n else out.prln(count);\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 // constants\n static final int IBIG = 1000000007;\n static final int IMAX = 2147483647;\n static final int IMIN = -2147483648;\n static final long LMAX = 9223372036854775807L;\n static final long LMIN = -9223372036854775808L;\n\n //Fast Reader Class\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 //Input fxs\n static class in {\n // input\n static void r() throws IOException {\n input = new StringTokenizer(rline());\n }\n\n static int ri() throws IOException {\n return Integer.parseInt(rline());\n }\n\n static long rl() throws IOException {\n return Long.parseLong(rline());\n }\n\n static double rd() throws IOException {\n return Double.parseDouble(rline());\n }\n\n static int[] ria(int n) throws IOException {\n int[] a = new int[n];\n r();\n for (int i = 0; i < n; ++i) a[i] = ni();\n return a;\n }\n\n static int[] riam1(int n) throws IOException {\n int[] a = new int[n];\n r();\n for (int i = 0; i < n; ++i) a[i] = ni() - 1;\n return a;\n }\n\n static long[] ria1i(long n) throws IOException {\n long[] a = new long[(int) n + 1];\n r();\n for (int i = 1; i <= n; i++) a[i] = nl();\n return a;\n }\n\n static long[] rla(int n) throws IOException {\n long[] a = new long[n];\n r();\n for (int i = 0; i < n; ++i) a[i] = nl();\n return a;\n }\n\n static double[] rda(int n) throws IOException {\n double[] a = new double[n];\n r();\n for (int i = 0; i < n; ++i) a[i] = nd();\n return a;\n }\n\n static char[] rcha() throws IOException {\n return rline().toCharArray();\n }\n\n static ArrayList<Integer> riaa(int n) throws IOException {\n ArrayList<Integer> a = new ArrayList<>();\n r();\n for (int i = 0; i < n; i++) a.add(ni());\n return a;\n }\n\n static String rline() throws IOException {\n return __in.readLine();\n }\n\n static String n() {\n return input.nextToken();\n }\n\n static int rni() throws IOException {\n r();\n return ni();\n }\n\n static int ni() {\n return Integer.parseInt(n());\n }\n\n static long rnl() throws IOException {\n r();\n return nl();\n }\n\n static long nl() {\n return Long.parseLong(n());\n }\n\n static double rnd() throws IOException {\n r();\n return nd();\n }\n\n static double nd() {\n return Double.parseDouble(n());\n }\n\n static List<List<Integer>> rg(int n, int m) throws IOException {\n List<List<Integer>> g = GR.g(n);\n for (int i = 0; i < m; ++i) GR.c(g, rni() - 1, ni() - 1);\n return g;\n }\n\n static void rg(List<List<Integer>> g, int m) throws IOException {\n for (int i = 0; i < m; ++i) GR.c(g, rni() - 1, ni() - 1);\n }\n\n static List<List<Integer>> rdg(int n, int m) throws IOException {\n List<List<Integer>> g = GR.g(n);\n for (int i = 0; i < m; ++i) GR.cto(g, rni() - 1, ni() - 1);\n return g;\n }\n\n static void rdg(List<List<Integer>> g, int m) throws IOException {\n for (int i = 0; i < m; ++i) GR.cto(g, rni() - 1, ni() - 1);\n }\n\n static List<Set<Integer>> rsg(int n, int m) throws IOException {\n List<Set<Integer>> g = GR.sg(n);\n for (int i = 0; i < m; ++i) GR.c(g, rni() - 1, ni() - 1);\n return g;\n }\n\n static void rsg(List<Set<Integer>> g, int m) throws IOException {\n for (int i = 0; i < m; ++i) GR.c(g, rni() - 1, ni() - 1);\n }\n\n static List<Set<Integer>> rdsg(int n, int m) throws IOException {\n List<Set<Integer>> g = GR.sg(n);\n for (int i = 0; i < m; ++i) GR.cto(g, rni() - 1, ni() - 1);\n return g;\n }\n\n static void rdsg(List<Set<Integer>> g, int m) throws IOException {\n for (int i = 0; i < m; ++i) GR.cto(g, rni() - 1, ni() - 1);\n }\n\n static int[][] rim(int n, int m) throws IOException {\n int[][] a = new int[n][m];\n for (int i = 0; i < n; i++) {\n in.r();\n for (int j = 0; j < m; j++) {\n a[i][j] = in.ni();\n }\n }\n return a;\n }\n }\n\n //Output fxs\n static class out {\n // output\n static void pr(int i) {\n __out.print(i);\n }\n\n static void prln(int i) {\n __out.println(i);\n }\n\n static void pr(long l) {\n __out.print(l);\n }\n\n static void prln(long l) {\n __out.println(l);\n }\n\n static void pr(double d) {\n __out.print(d);\n }\n\n static void prln(double d) {\n __out.println(d);\n }\n\n static void pr(char c) {\n __out.print(c);\n }\n\n static void prln(char c) {\n __out.println(c);\n }\n\n static void pr(char[] s) {\n __out.print(new String(s));\n }\n\n static void prln(char[] s) {\n __out.println(new String(s));\n }\n\n static void pr(String s) {\n __out.print(s);\n }\n\n static void prln(String s) {\n __out.println(s);\n }\n\n static void pr(Object o) {\n __out.print(o);\n }\n\n static void prln(Object o) {\n __out.println(o);\n }\n\n static void prln() {\n __out.println();\n }\n\n static void pryes() {\n prln(\"yes\");\n }\n\n static void pry() {\n prln(\"Yes\");\n }\n\n static void prY() {\n prln(\"YES\");\n }\n\n static void prno() {\n prln(\"no\");\n }\n\n static void prn() {\n prln(\"No\");\n }\n\n static void prN() {\n prln(\"NO\");\n }\n\n static void pryesno(boolean b) {\n prln(b ? \"yes\" : \"no\");\n }\n\n ;\n\n static void pryn(boolean b) {\n prln(b ? \"Yes\" : \"No\");\n }\n\n static void prYN(boolean b) {\n prln(b ? \"YES\" : \"NO\");\n }\n\n static void prln(int... a) {\n for (int i = 0, len = a.length - 1; i < len; pr(a[i]), pr(' '), ++i) ;\n if (a.length > 0) prln(a[a.length - 1]);\n else prln();\n }\n\n static void prln(long... a) {\n for (int i = 0, len = a.length - 1; i < len; pr(a[i]), pr(' '), ++i) ;\n if (a.length > 0) prln(a[a.length - 1]);\n else prln();\n }\n\n static void prln(double... a) {\n for (int i = 0, len = a.length - 1; i < len; pr(a[i]), pr(' '), ++i) ;\n if (a.length > 0) prln(a[a.length - 1]);\n else prln();\n }\n\n static <T> void prln(Collection<T> c) {\n int n = c.size() - 1;\n Iterator<T> iter = c.iterator();\n for (int i = 0; i < n; pr(iter.next()), pr(' '), ++i) ;\n if (n >= 0) prln(iter.next());\n else prln();\n }\n\n static void h() {\n prln(\"hlfd\");\n flush();\n }\n\n static void flush() {\n __out.flush();\n }\n\n static void close() {\n __out.close();\n }\n\n static void prM(int[][] a, int n, int m) {\n for (int i = 0; i < m; i++) {\n for (int j = 0; j < n; j++)\n out.pr(a[i][j] + \" \");\n out.prln();\n }\n }\n }\n\n //Math fxs\n static class mathx {\n // math util\n static int minof(int a, int b, int c) {\n return min(a, min(b, c));\n }\n\n static int minof(int... x) {\n if (x.length == 1) return x[0];\n if (x.length == 2) return min(x[0], x[1]);\n if (x.length == 3) return min(x[0], min(x[1], x[2]));\n int min = x[0];\n for (int i = 1; i < x.length; ++i) if (x[i] < min) min = x[i];\n return min;\n }\n\n static long minof(long a, long b, long c) {\n return min(a, min(b, c));\n }\n\n static long minof(long... x) {\n if (x.length == 1) return x[0];\n if (x.length == 2) return min(x[0], x[1]);\n if (x.length == 3) return min(x[0], min(x[1], x[2]));\n long min = x[0];\n for (int i = 1; i < x.length; ++i) if (x[i] < min) min = x[i];\n return min;\n }\n\n static int maxof(int a, int b, int c) {\n return max(a, max(b, c));\n }\n\n static int maxof(int... x) {\n if (x.length == 1) return x[0];\n if (x.length == 2) return max(x[0], x[1]);\n if (x.length == 3) return max(x[0], max(x[1], x[2]));\n int max = x[0];\n for (int i = 1; i < x.length; ++i) if (x[i] > max) max = x[i];\n return max;\n }\n\n static long maxof(long a, long b, long c) {\n return max(a, max(b, c));\n }\n\n static long maxof(long... x) {\n if (x.length == 1) return x[0];\n if (x.length == 2) return max(x[0], x[1]);\n if (x.length == 3) return max(x[0], max(x[1], x[2]));\n long max = x[0];\n for (int i = 1; i < x.length; ++i) if (x[i] > max) max = x[i];\n return max;\n }\n\n static int powi(int a, int b) {\n if (a == 0) return 0;\n int ans = 1;\n while (b > 0) {\n if ((b & 1) > 0) ans *= a;\n a *= a;\n b >>= 1;\n }\n return ans;\n }\n\n static long powl(long a, int b) {\n if (a == 0) return 0;\n long ans = 1;\n while (b > 0) {\n if ((b & 1) > 0) ans *= a;\n a *= a;\n b >>= 1;\n }\n return ans;\n }\n\n static int fli(double d) {\n return (int) d;\n }\n\n static int cei(double d) {\n return (int) ceil(d);\n }\n\n static long fll(double d) {\n return (long) d;\n }\n\n static long cel(double d) {\n return (long) ceil(d);\n }\n\n static int gcd(int a, int b) {\n return b == 0 ? a : gcd(b, a % b);\n }\n\n static long gcd(long a, long b) {\n return b == 0 ? a : gcd(b, a % b);\n }\n\n\n static int lcm(int a, int b) {\n return a * b / gcd(a, b);\n }\n\n static long lcm(long a, long b) {\n return a * b / gcd(a, b);\n }\n\n static int randInt(int min, int max) {\n return __rand.nextInt(max - min + 1) + min;\n }\n\n static long mix(long x) {\n x += 0x9e3779b97f4a7c15L;\n x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9L;\n x = (x ^ (x >> 27)) * 0x94d049bb133111ebL;\n return x ^ (x >> 31);\n }\n }\n\n //Array fxs\n static class ARR {\n // array util\n static void reverse(int[] a) {\n for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {\n int swap = a[i];\n a[i] = a[n - i - 1];\n a[n - i - 1] = swap;\n }\n }\n\n static void reverse(long[] a) {\n for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {\n long swap = a[i];\n a[i] = a[n - i - 1];\n a[n - i - 1] = swap;\n }\n }\n\n static void reverse(double[] a) {\n for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {\n double swap = a[i];\n a[i] = a[n - i - 1];\n a[n - i - 1] = swap;\n }\n }\n\n static void reverse(char[] a) {\n for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {\n char swap = a[i];\n a[i] = a[n - i - 1];\n a[n - i - 1] = swap;\n }\n }\n\n static void shuffle(int[] a) {\n int n = a.length - 1;\n for (int i = 0; i < n; ++i) {\n int ind = mathx.randInt(i, n);\n int swap = a[i];\n a[i] = a[ind];\n a[ind] = swap;\n }\n }\n\n static void shuffle(long[] a) {\n int n = a.length - 1;\n for (int i = 0; i < n; ++i) {\n int ind = mathx.randInt(i, n);\n long swap = a[i];\n a[i] = a[ind];\n a[ind] = swap;\n }\n }\n\n static void shuffle(double[] a) {\n int n = a.length - 1;\n for (int i = 0; i < n; ++i) {\n int ind = mathx.randInt(i, n);\n double swap = a[i];\n a[i] = a[ind];\n a[ind] = swap;\n }\n }\n\n static void rsort(int[] a) {\n shuffle(a);\n sort(a);\n }\n\n static void rsort(long[] a) {\n shuffle(a);\n sort(a);\n }\n\n static void rsort(double[] a) {\n shuffle(a);\n sort(a);\n }\n\n static int[] copy(int[] a) {\n int[] ans = new int[a.length];\n System.arraycopy(a, 0, ans, 0, a.length);\n return ans;\n }\n\n static long[] copy(long[] a) {\n long[] ans = new long[a.length];\n System.arraycopy(a, 0, ans, 0, a.length);\n return ans;\n }\n\n static double[] copy(double[] a) {\n double[] ans = new double[a.length];\n System.arraycopy(a, 0, ans, 0, a.length);\n return ans;\n }\n\n static char[] copy(char[] a) {\n char[] ans = new char[a.length];\n System.arraycopy(a, 0, ans, 0, a.length);\n return ans;\n }\n }\n\n //Graph fxs\n static class GR {\n // graph util\n static List<List<Integer>> g(int n) {\n List<List<Integer>> g = new ArrayList<>();\n for (int i = 0; i < n; ++i) g.add(new ArrayList<>());\n return g;\n }\n\n static List<Set<Integer>> sg(int n) {\n List<Set<Integer>> g = new ArrayList<>();\n for (int i = 0; i < n; ++i) g.add(new HashSet<>());\n return g;\n }\n\n static void c(List<? extends Collection<Integer>> g, int u, int v) {\n g.get(u).add(v);\n g.get(v).add(u);\n }\n\n static void cto(List<? extends Collection<Integer>> g, int u, int v) {\n g.get(u).add(v);\n }\n\n static void dc(List<? extends Collection<Integer>> g, int u, int v) {\n g.get(u).remove(v);\n g.get(v).remove(u);\n }\n\n static void dcto(List<? extends Collection<Integer>> g, int u, int v) {\n g.get(u).remove(v);\n }\n }\n\n //Utilsx class\n static class utilX {\n static int[] subsetSum(int[] nums) {\n int M = IntStream.of(nums).sum();\n int[] m = new int[M + 10];\n for (int i = 0; i < M + 10; i++) m[i] = 0;\n m[0] = 1;\n for (int num : nums) {\n for (int j = M; j >= num; j--) {\n m[j] |= m[j - num];\n }\n }\n return m;\n }\n\n static int LIS(int[] nums) {\n int[] m = new int[nums.length];\n for (int i = nums.length - 1; i >= 0; i--) {\n m[i] = 1;\n for (int j = i + 1; j < nums.length; j++) {\n if (nums[j] > nums[i]) {\n m[i] = max(m[i], m[j] + 1);\n }\n }\n }\n int ans = 0;\n for (int i = 0; i < nums.length; i++) {\n ans = max(ans, m[i]);\n }\n return ans;\n }\n }\n\n //Pair Class\n static class Pair<F, S> {\n public final F first;\n public final S second;\n\n public Pair(F first, S second) {\n this.first = first;\n this.second = second;\n }\n\n @Override\n public boolean equals(Object o) {\n if (!(o instanceof Pair)) {\n return false;\n }\n Pair<?, ?> p = (Pair<?, ?>) o;\n return Objects.equals(p.first, first) && Objects.equals(p.second, second);\n }\n }\n}\n", "src_uid": "59dfa7a4988375febc5dccc27aca90a8"} {"source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.PrintWriter;\nimport java.util.InputMismatchException;\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\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, PrintWriter out) {\n int N = in.nextInt();\n int M = in.nextInt();\n\n if (N == 1 && M == 1) {\n out.println(1);\n }\n else {\n double ans = 1.0 / N + (double) (N - 1) / N * (M - 1) / (N * M - 1);\n out.println(ans);\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", "src_uid": "0b9ce20c36e53d4702869660cbb53317"} {"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 Tarek\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 ALetsWatchFootball solver = new ALetsWatchFootball();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class ALetsWatchFootball {\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n int a = in.nextInt();\n int b = in.nextInt();\n int x = in.nextInt();\n long tottal = a * x;\n long down = (tottal + b - 1) / b;\n out.println(Math.max(0, down - x));\n\n\n }\n\n }\n}\n\n", "src_uid": "7dd098ec3ad5b29ad681787173eba341"} {"source_code": "import java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\nimport java.util.*;\r\n\r\npublic class CF1{\r\n public static void main(String[] args) {\r\n FastScanner sc=new FastScanner();\r\n// int T=sc.nextInt();\r\n int T=1;\r\n for (int tt=0; tt<T; tt++){\r\n int n = sc.nextInt();\r\n int m =sc.nextInt();\r\n long ans =1;\r\n boolean done []= new boolean [n+1];\r\n int size=0;\r\n int x=2;\r\n while (x<=n){\r\n size++;\r\n x*=2;\r\n }\r\n long dp[]= new long [size+1];\r\n boolean p[]= new boolean[m*size+1];\r\n long t=0;\r\n for (int j=1; j<=size; j++){\r\n for (int y=1; y<=m; y++){\r\n if (!p[j*y]){\r\n p[j*y]=true;\r\n t++;\r\n }\r\n }\r\n dp[j]=t;\r\n }\r\n for (int i=2; i<=n; i++){\r\n if (!done[i]){\r\n int sizez=0;\r\n long temp=i;\r\n while (temp<=n){\r\n done[(int)temp]=true;\r\n sizez++;\r\n temp*=i;\r\n }\r\n ans+=dp[sizez];\r\n }\r\n }\r\n System.out.println(ans);\r\n }\r\n }\r\n static int calc(long t){\r\n int x =0;\r\n while (t>0){\r\n x+=t%2;\r\n t/=2;\r\n }\r\n return x;\r\n }\r\n static long factorial (int x){\r\n if (x==0) return 1;\r\n long ans =x;\r\n for (int i=x-1; i>=1; i--){\r\n ans*=i;\r\n ans%=mod;\r\n }\r\n return ans;\r\n }\r\n static int mod =1000000007;\r\n static long power2 (long a, long b){\r\n long res=1;\r\n while (b>0){\r\n if ((b&1)== 1){\r\n res= (res * a % mod)%mod;\r\n }\r\n a=(a%mod * a%mod)%mod;\r\n b=b>>1;\r\n }\r\n return res;\r\n }\r\n\r\n boolean[] sieveOfEratosthenes(int n)\r\n {\r\n\r\n boolean prime[] = new boolean[n+1];\r\n for(int i=0;i<=n;i++)\r\n prime[i] = true;\r\n\r\n for(int p = 2; p*p <=n; p++)\r\n {\r\n if(prime[p] == true)\r\n {\r\n for(int i = p*p; i <= n; i += p)\r\n prime[i] = false;\r\n }\r\n }\r\n return prime;\r\n }\r\n static void sort(int[] a) {\r\n ArrayList<Integer> l=new ArrayList<>();\r\n for (int i:a) l.add(i);\r\n Collections.sort(l);\r\n for (int i=0; i<a.length; i++) a[i]=l.get(i);\r\n }\r\n static void sortLong(long[] a) {\r\n ArrayList<Long> l=new ArrayList<>();\r\n for (long i:a) l.add(i);\r\n Collections.sort(l);\r\n for (int i=0; i<a.length; i++) a[i]=l.get(i);\r\n }\r\n static long gcd (long n, long m){\r\n if (m==0) return n;\r\n else return gcd(m, n%m);\r\n }\r\n\r\n static class Pair implements Comparable<Pair>{\r\n int x,y;\r\n public Pair(int x, int y){\r\n this.x = x;\r\n this.y = y;\r\n }\r\n public int compareTo(Pair o){\r\n return this.x-o.x;\r\n }\r\n // this.x-o.x is ascending\r\n }\r\n static class FastScanner {\r\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\r\n StringTokenizer st=new StringTokenizer(\"\");\r\n String next() {\r\n while (!st.hasMoreTokens())\r\n try {\r\n st=new StringTokenizer(br.readLine());\r\n } catch (IOException e) {\r\n e.printStackTrace();\r\n }\r\n return st.nextToken();\r\n }\r\n\r\n int nextInt() {\r\n return Integer.parseInt(next());\r\n }\r\n int[] readArray(int n) {\r\n int[] a=new int[n];\r\n for (int i=0; i<n; i++) a[i]=nextInt();\r\n return a;\r\n }\r\n long nextLong() {\r\n return Long.parseLong(next());\r\n }\r\n }\r\n}", "src_uid": "6ca310cb0b6fc4e62e63a731cd55aead"} {"source_code": "import static java.lang.System.*;\nimport java.util.*;\n\npublic class E166{\n public static Scanner sc = new Scanner(in);\n public static Random rand=new Random();\n\n int mod=100000000;\n public void run(){\n int n1=sc.nextInt(),n2=sc.nextInt(),k1=sc.nextInt(),k2=sc.nextInt();\n\n int[][][][] dp=new int[n1+1][n2+1][11][2];\n dp[1][0][1][0]=dp[0][1][1][1]=1;\n for(int i=0;i<=n1;i++)for(int j=0;j<=n2;j++){\n if(j>=1)for(int k=1;k<=k1;k++){\n dp[i][j][1][1]+=dp[i][j-1][k][0];\n dp[i][j][1][1]%=mod;\n }\n if(i>=1)for(int k=2;k<=k1;k++){\n dp[i][j][k][0]+=dp[i-1][j][k-1][0];\n dp[i][j][k][0]%=mod;\n }\n if(i>=1)for(int k=1;k<=k2;k++){\n dp[i][j][1][0]+=dp[i-1][j][k][1];\n dp[i][j][1][0]%=mod;\n }\n if(j>=1)for(int k=2;k<=k2;k++){\n dp[i][j][k][1]+=dp[i][j-1][k-1][1];\n dp[i][j][k][1]%=mod;\n }\n }\n long val=0;\n for(int i=1;i<=k1;i++){\n val+=dp[n1][n2][i][0];\n val%=mod;\n }\n for(int i=1;i<=k2;i++){\n val+=dp[n1][n2][i][1];\n val%=mod;\n }\n ln(val%mod);\n }\n\n public static void main(String[] _) {\n new E166().run();\n }\n\n public int[] nextIntArray(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 public static void pr(Object o) {\n out.print(o);\n }\n public static void ln(Object o) {\n out.println(o);\n }\n public static void ln() {\n out.println();\n }\n\n}", "src_uid": "63aabef26fe008e4c6fc9336eb038289"} {"source_code": "\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class C {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n segment[] A = new segment[4];\n for (int i = 0; i < 4; i++) {\n A[i] = new segment(in.nextInt(), in.nextInt(), in.nextInt(),\n in.nextInt());\n if (A[i].x1 > A[i].x2) {\n A[i].x1 ^= A[i].x2;\n A[i].x2 ^= A[i].x1;\n A[i].x1 ^= A[i].x2;\n }\n if (A[i].y1 > A[i].y2) {\n A[i].y1 ^= A[i].y2;\n A[i].y2 ^= A[i].y1;\n A[i].y1 ^= A[i].y2;\n }\n if ((A[i].x1 != A[i].x2 && A[i].y1 != A[i].y2)\n || (A[i].x2 - A[i].x1) + (A[i].y2 - A[i].y1) == 0) {\n System.out.println(\"NO\");\n return;\n }\n }\n Arrays.sort(A);\n if (A[0].x1 == A[1].x1 && A[0].y1 == A[1].y1 && A[1].x2 == A[3].x2\n && A[1].y1 == A[3].y1 && A[0].y2 == A[2].y1\n && A[0].x1 == A[2].x1 && A[2].x2 == A[3].x1\n && A[2].y1 == A[3].y2)\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n }\n}\n\nclass segment implements Comparable<segment> {\n int x1;\n int y1;\n int x2;\n int y2;\n\n public segment(int i, int j, int k, int l) {\n x1 = i;\n y1 = j;\n x2 = k;\n y2 = l;\n }\n\n public int compareTo(segment o) {\n if (x1 != o.x1)\n return x1 - o.x1;\n if (x2 != o.x2)\n return x2 - o.x2;\n return y1 - o.y1;\n }\n\n}", "src_uid": "ad105c08f63e9761fe90f69630628027"} {"source_code": "import static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.Math.max;\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\tstatic final long inf = Long.MAX_VALUE / 2;\n\n\tstatic void solve() throws Exception {\n\t\tint k = scanInt();\n\t\tlong f[] = new long[6];\n\t\tfor (int i = 0; i < 6; i++) {\n\t\t\tf[i] = scanLong();\n\t\t}\n\t\tlong dyn[] = new long[1000000], ndyn[] = new long[1000000];\n\t\tfill(dyn, 1, 1000000, -inf);\n\t\tint p10 = 1;\n\t\tint smpos[] = new int[1000000];\n\t\tfor (int p = 0; p < 6; p++) {\n\t\t\tfill(ndyn, -inf);\n\t\t\tlong cf = f[p];\n\t\t\tint s = 3 * p10;\n\t\t\tfor (int i = 0; i < 1000000; i++) {\n\t\t\t\tdyn[i] -= i / s * cf;\n\t\t\t}\n\t\t\tfor (int m = 0; m < s; m++) {\n\t\t\t\tint smhead = 0, smtail = 0;\n\t\t\t\tfor (int i = m; i < 1000000; i += s) {\n\t\t\t\t\twhile (smtail > smhead && dyn[i] >= dyn[smpos[smtail - 1]]) {\n\t\t\t\t\t\t--smtail;\n\t\t\t\t\t}\n\t\t\t\t\tsmpos[smtail++] = i;\n\t\t\t\t\tlong v = dyn[smpos[smhead]] + i / s * cf;\n\t\t\t\t\tndyn[i] = max(ndyn[i], v);\n\t\t\t\t\tif (i + p10 < 1000000) {\n\t\t\t\t\t\tndyn[i + p10] = max(ndyn[i + p10], v);\n\t\t\t\t\t}\n\t\t\t\t\tif (i + 2 * p10 < 1000000) {\n\t\t\t\t\t\tndyn[i + 2 * p10] = max(ndyn[i + 2 * p10], v);\n\t\t\t\t\t}\n\t\t\t\t\tif (smpos[smhead] == i - (long) (9 * k - 9) * p10) {\n\t\t\t\t\t\t++smhead;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int i = 0; i < 1000000; i++) {\n\t\t\t\tfor (int ss = 9 * k - 6; ss <= 9 * k; ss++) {\n\t\t\t\t\tif (i - (long) ss * p10 >= 0) {\n\t\t\t\t\t\tndyn[i] = max(ndyn[i], dyn[i - ss * p10] + ((i - ss * p10) / s + (ss % 3 == 0 ? ss / 3 : 3 * k - 3)) * cf);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tp10 *= 10;\n\t\t\tlong t[] = dyn;\n\t\t\tdyn = ndyn;\n\t\t\tndyn = t;\n\t\t}\n\t\tint q = scanInt();\n\t\tfor (int qq = 0; qq < q; qq++) {\n\t\t\tout.println(dyn[scanInt()]);\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}", "src_uid": "92bcbac3f167a44c235e99afc4de20d2"} {"source_code": "import java.io.IOException;\nimport java.util.*;\n\npublic class Test {\n 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 int r, c;\n Scanner sca = new Scanner(System.in);\n long[][] C = new long[64][64];\n long best = Long.MAX_VALUE;\n\n void dfs(long x, long y, int v1, int v2) {\n long d = Math.abs(x - y);\n if (best <= 1 || d - C[v1][r]*C[v2][r] >= best) return;\n if (v1 == 0 && v2 == 0) {\n if (d < best) best = d;\n return;\n }\n if (v1 > 0) {\n long c1 = C[v1][r] - C[v1-1][r], s2 = C[v2][r];\n dfs(x, y + c1*s2, v1 - 1, v2);\n }\n if (v2 > 0) {\n long s1 = C[v1][r], c2 = C[v2][r] - C[v2-1][r];\n dfs(x + s1*c2, y, v1, v2 - 1);\n }\n }\n\n int[] cntA = new int[64], cntB = new int[64];\n Map<Long, Long> cache = new TreeMap<>();\n char[] cs;\n\n long solve(long x, long y, int v1, int v2) {\n long k = x*10000 + v1*100 + v2;\n Long v = cache.get(k);\n if (v != null) return v;\n v = 0l;\n long d = Math.abs(x - y);\n if (d - C[v1][r]*C[v2][r] > best) {\n cache.put(k, v);\n return v;\n }\n if (v1 == 0 && v2 == 0) return 1;\n char c = cs[v1 + v2 - 1];\n if (v1 > 0 && c != 'B') {\n long c1 = C[v1][r] - C[v1 - 1][r], s2 = C[v2][r];\n v += solve(x, y + c1*s2, v1 - 1, v2);\n }\n if (v2 > 0 && c != 'A') {\n long s1 = C[v1][r], c2 = C[v2][r] - C[v2-1][r];\n v += solve( x + s1*c2, y, v1, v2 - 1);\n }\n cache.put(k, v);\n return v;\n }\n\n void start() {\n r = sca.nextInt(); c = sca.nextInt(); sca.nextLine();\n cs = sca.nextLine().toCharArray();\n for (int i = 0; i <= 2*(r + c); i++)\n for (int j = 0; j <= 2*(r + c); j++) {\n if (j == 0) C[i][j] = 1;\n else if (i == 0) C[i][j] = 0;\n else C[i][j] = C[i-1][j - 1] + C[i - 1][j];\n }\n int v1 = r + c, v2 = r + c;\n long x = 0, y = 0;\n while (v1 > 0 && v2 > 0) {\n if (x > y) {\n long c1 = C[v1][r] - C[v1 - 1][r], s2 = C[v2][r];\n y += c1*s2;\n v1--;\n } else {\n long s1 = C[v1][r], c2 = C[v2][r] - C[v2-1][r];\n x += s1*c2;\n v2--;\n }\n }\n best = Math.abs(x - y);\n dfs(0, 0, r + c, r + c);\n for (int i = 0; i < 2*(r+c); i++) {\n cntA[i + 1] = cntA[i] + (cs[i] == 'A' ? 1 : 0);\n cntB[i + 1] = cntB[i] + (cs[i] == 'B' ? 1 : 0);\n }\n long ans = solve(0, 0, r + c, r + c);\n System.out.println(ans);\n }\n\n public static void main(String[] args) {\n\n new Test().start();\n\n }\n}\n", "src_uid": "1b978b5aed4a83a2250bb23cc1ad6f85"} {"source_code": "\nimport java.util.ArrayList;\nimport java.util.Arrays;\n\nimport java.util.Scanner;\n\n/**\n *\n * @author Lotfi\n */\npublic class edu {\n\n public static void main(String[] arg) {\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 System.out.println(Math.max(Math.abs(a-c), Math.abs(b-d))); \n}}\n", "src_uid": "a6e9405bc3d4847fe962446bc1c457b4"} {"source_code": "import java.io.BufferedReader;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.StringTokenizer;\nimport java.util.Collections;\nimport java.util.Arrays;\n\npublic class Main {\n\n\tclass Input {\n\t\tBufferedReader bf;\n\t\tStringTokenizer st;\n\n\t\tlong nextLong() throws IOException {\n\t\t\tif (!st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(bf.readLine());\n\t\t\treturn Long.parseLong(st.nextToken());\n\t\t}\n\n\t\tInput(InputStream stream) throws IOException {\n\t\t\tbf = new BufferedReader(new InputStreamReader(stream));\n\t\t\tst = new StringTokenizer(bf.readLine());\n\t\t}\n\n\t\tint nextInt() throws IOException {\n\t\t\tif (!st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(bf.readLine());\n\t\t\treturn Integer.parseInt(st.nextToken());\n\t\t}\n\n\t\tdouble nextDouble() throws IOException {\n\t\t\tif (!st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(bf.readLine());\n\t\t\treturn Double.parseDouble(st.nextToken());\n\t\t}\n\n\t\tvoid readLine() throws IOException {\n\t\t\tst = new StringTokenizer(bf.readLine());\n\t\t}\n\n\t\tString nextString() throws IOException {\n\t\t\tif (!st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(bf.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tString nextLine() throws IOException {\n\t\t\treturn bf.readLine();\n\t\t}\n\n\t\tvoid close() throws IOException {\n\t\t\tbf.close();\n\t\t}\n\t}\n\n\tstatic Input in;\n\n\tpublic void solve() throws IOException {\n\t\tin = new Input(System.in);\n\t\tint a = in.nextInt();\n\t\tint b = in.nextInt();\n\t\tint c = in.nextInt();\n\t\tint d = in.nextInt();\n\t\tif (((d - c) == (c - b)) && ((c - b) == (b - a)))\n\t\t\tSystem.out.println(d + (b - a));\n\t\telse {\n\t\t\tdouble q = (double) b / a;\n\t\t\tdouble q2 = (double) c / b;\n\t\t\tdouble q3 = (double) d / c;\n\t\t\tif ((q == q2) && (q2 == q3)) {\n\n\t\t\t\tdouble res = d * q;\n\t\t\t\tint res2 = (int) (d * q);\n\t\t\t\tif (res % res2 != 0)\n\t\t\t\t\tSystem.out.println(42);\n\t\t\t\telse\n\t\t\t\t\tSystem.out.println(res2);\n\t\t\t} else\n\t\t\t\tSystem.out.println(42);\n\t\t}\n\n\t\tin.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew Main().solve();\n\n\t}\n\n}\n", "src_uid": "68a9508d49fec672f9c61766d6051047"} {"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.ArrayList;\nimport java.util.StringTokenizer;\n\npublic class Cups {\n\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tReader.init(System.in);\n\t\tlong rubles = Reader.nextLong();\n\t\tlong plastic = Reader.nextLong();\n\t\tlong glass = Reader.nextLong();\n\t\tlong rem = Reader.nextLong();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t\n\t\tlong x = 0;\n\t\tlong y = 0;\n\t\t\n\t\tif(rubles>=plastic)\n\t\tx = (rubles / plastic) + solve(rubles % plastic, glass, rem);\n\t\t\n\t\tif(rubles>=glass)\n\t\ty = solve(rubles, glass, rem, plastic);\n\t\t\n\t\tout.println(Math.max(x, y));\n\t\t\n\t\tout.flush();\n\n\t}\n\n\tstatic class Reader {\n\t\tstatic BufferedReader reader;\n\t\tstatic StringTokenizer tokenizer;\n\n\t\t/** call this method to initialize reader for InputStream */\n\t\tstatic void init(InputStream input) {\n\t\t\treader = new BufferedReader(new InputStreamReader(input));\n\t\t\ttokenizer = new StringTokenizer(\"\");\n\t\t}\n\n\t\t/** get next word */\n\t\tstatic String next() throws IOException {\n\t\t\twhile (!tokenizer.hasMoreTokens()) {\n\n\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\n\t\tstatic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tstatic double nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tstatic long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t}\n\n\tprivate static long solve(long rubles, long glass, long rem, long plastic) {\n\n\t\tlong sum = 0;\n\t\tlong n = 0;\n\t\tlong diff = glass - rem;\n\t\tlong x = rem;\n\t\tlong y = rubles - x;\n\t\t\n\t\tn = (y) / diff;\n\n\t\tsum += n;\n\t\trubles -= (n * diff);\n\n\t\tif (rubles >= plastic)\n\t\t\tsum += rubles / plastic;\n\n\t\treturn sum;\n\t}\n\n\tprivate static long solve(long rubles, long glass, long rem) {\n\n\t\tlong sum = 0;\n\t\tlong n = 0;\n\t\twhile (rubles >= glass) {\n\n\t\t\tn = (rubles / glass);\n\t\t\tsum += n;\n\t\t\trubles %= glass;\n\t\t\trubles += (n * rem);\n\n\t\t}\n\n\t\treturn sum;\n\t}\n}", "src_uid": "0ee9abec69230eab25de51aef0984f8f"} {"source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tPrintWriter out = new PrintWriter(System.out);\n\n\t\tTask solver = new Task();\n\t\tsolver.solve(in, out);\n\t\tout.close();\n\t}\n}\n\nclass Task {\n\tfinal static int MAXN = 2111111;\n\tfinal static long MD = 1000000007;\n\tlong[] inv, fact, factInv;\n\n\tlong pow(int x, int y) {\n\t\tlong ret = 1, tmp = x;\n\t\tfor (; y > 0; y >>= 1) {\n\t\t\tif ((y & 1) == 1)\n\t\t\t\tret = ret * tmp % MD;\n\t\t\ttmp = tmp * tmp % MD;\n\t\t}\n\t\treturn ret;\n\t}\n\n\tlong perm(int n, int m) {\n\t\treturn n < m ? 0 : fact[n] * factInv[n - m] % MD;\n\t}\n\n\tvoid solve(Scanner in, PrintWriter out) {\n\t\tint k = in.nextInt(), w = in.nextInt();\n\t\tinv = new long[MAXN];\n\t\tfact = new long[MAXN];\n\t\tfactInv = new long[MAXN];\n\t\tinv[1] = 1;\n\t\tfor (int i = 2; i < MAXN; ++i)\n\t\t\tinv[i] = (MD - MD / i * inv[(int)MD % i] % MD) % MD;\n\n\t\tfact[0] = factInv[0] = 1;\n\t\tfor (int i = 1; i < MAXN; ++i) {\n\t\t\tfact[i] = fact[i - 1] * i % MD;\n\t\t\tfactInv[i] = factInv[i - 1] * inv[i] % MD;\n\t\t}\n\n\t\tlong ans = 0;\n\t\tfor (int t = 1; t <= k; ++t) {\n\t\t\tif (w - 1 >= t)\n\t\t\t\tans = (ans + perm(k, t) * perm(k, t) % MD * t % MD * pow(k, w - 1 - t) % MD) % MD;\n\t\t\telse\n\t\t\t\tans = (ans + perm(k, t) * perm(k - t + w - 1, w - 1) % MD * w % MD) % MD;\n\t\t\tif (w - 1 >= t + 1)\n\t\t\t\tans = (ans + perm(k, t) * perm(k, t + 1) % MD * t % MD * pow(k, w - 2 - t) % MD) % MD;\n\t\t\telse\n\t\t\t\tans = (ans + perm(k, t) * perm(k - 2 - t + w, w - 1) % MD * (w - 1) % MD) % MD;\n\t\t}\n\n\t\tout.println(ans);\n\t}\n}\n", "src_uid": "b715f0fdc83ec539eb3ae2b0371ee130"} {"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 KharYusuf\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastReader in = new FastReader(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 public void solve(int testNumber, FastReader s, PrintWriter w) {\n int n = s.nextInt(), k = s.nextInt();\n int BL_SZ = k + 1 >> 1;\n boolean[] rep = new boolean[n];\n for (int i = 0; i < n; i++) if (query(i, s, w)) rep[i] = true;\n for (int i = 0; i < n; i += BL_SZ) {\n for (int j = i + BL_SZ; j < n; j += BL_SZ) {\n reset(w);\n for (int l = i, c = 0; c < BL_SZ; l++, c++) query(l, s, w);\n for (int l = j, c = 0; c < BL_SZ; l++, c++) if (query(l, s, w)) rep[l] = true;\n }\n }\n int ans = 0;\n for (int i = 0; i < n; i++) if (!rep[i]) ans++;\n w.println(\"! \" + ans);\n w.flush();\n }\n\n boolean query(int i, FastReader s, PrintWriter w) {\n w.println(\"? \" + ++i);\n w.flush();\n return s.nextChar() == 'Y';\n }\n\n void reset(PrintWriter w) {\n w.println('R');\n w.flush();\n }\n\n }\n\n static class FastReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private FastReader.SpaceCharFilter filter;\n\n public FastReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n\n if (numChars == -1)\n throw new InputMismatchException();\n\n if (curChar >= numChars) {\n\n curChar = 0;\n\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\n return buf[curChar++];\n }\n\n public int nextInt() {\n\n int c = read();\n\n while (isSpaceChar(c))\n c = read();\n\n int sgn = 1;\n\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n\n int res = 0;\n\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n\n res *= 10;\n res += c - '0';\n c = read();\n }\n while (!isSpaceChar(c));\n\n return res * sgn;\n }\n\n public char nextChar() {\n\n int c = read();\n\n while (isSpaceChar(c))\n c = read();\n\n return (char) c;\n }\n\n public boolean isSpaceChar(int c) {\n\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", "src_uid": "11ad68b4375456733526e74e72606d8d"} {"source_code": "\r\nimport java.io.*;\r\nimport java.util.Arrays;\r\nimport java.util.Scanner;\r\nimport java.util.StringTokenizer;\r\n\r\npublic class FTL {\r\n\r\n public static void main(String[] args) throws IOException {\r\n Scanner in = new Scanner(System.in);\r\n int p1 = in.nextInt();\r\n long t1 = in.nextLong();\r\n int p2 = in.nextInt();\r\n long t2 = in.nextLong();\r\n int h = in.nextInt(), s = in.nextInt();\r\n\r\n long[] f = new long[h+1];\r\n long[] g = new long[h+1];\r\n Arrays.fill(f,(long)1e16);\r\n Arrays.fill(g,(long)1e16);\r\n\r\n for (int i = 0; i <=h ; i++) {\r\n for (int j = 0; j <= h; j++) {\r\n long t = Math.max((long)i*t1, (long)j*t2);\r\n long tt = Math.max((long)(i+1)*t1, (long)(j+1)*t2);\r\n int x = Math.min(h, i*(p1-s)+j*(p2-s));\r\n int y = Math.min(h, i*(p1-s)+j*(p2-s)+p2+p1-s);\r\n f[x] = Math.min(f[x],t);\r\n g[y] = Math.min(g[y],tt);\r\n }\r\n }\r\n for (int i = 0; i <=h ; i++) {\r\n for (int j = 0; j <= h; j++) {\r\n int x = Math.min(i+j, h);\r\n f[x] = Math.min(f[x], f[i]+g[j]);\r\n }\r\n }\r\n System.out.print(f[h]);\r\n }\r\n}", "src_uid": "ca9d48e48e69b931236907a9ac262433"} {"source_code": "import java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main {\n\n static class Cube {\n\n private boolean[] hasDigit;\n\n public boolean[] getHasDigit() {\n return hasDigit;\n }\n\n public Cube(int[] digits) {\n hasDigit = new boolean[10];\n Arrays.fill(hasDigit,false);\n\n for (int x: digits) {\n hasDigit[x] = true;\n }\n }\n\n public static void solve() {\n\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n Cube[] cubes = new Cube[n];\n boolean[] wasCube = new boolean[n];\n\n for (int i = 0; i < n; i++) {\n int[] array = new int[6];\n for (int j = 0; j < 6; j++) {\n array[j] = in.nextInt();\n }\n cubes[i] = new Cube(array);\n }\n\n ArrayList shuffle = new ArrayList<>();\n if (n == 1) {\n shuffle.add(new int[]{0});\n } else if (n == 2) {\n shuffle.add(new int[]{0, 1});\n shuffle.add(new int[]{1, 0});\n } else {\n shuffle.add(new int[]{0, 1, 2});\n shuffle.add(new int[]{0, 2, 1});\n shuffle.add(new int[]{1, 0, 2});\n shuffle.add(new int[]{1, 2, 0});\n shuffle.add(new int[]{2, 0, 1});\n shuffle.add(new int[]{2, 1, 0});\n }\n\n\n for (int x = 1; x < 1000; x++) {\n String number = Integer.toString(x);\n boolean ok = false;\n\n for (int i = 0; i < shuffle.size(); i++) {\n int[] permutation = (int[]) shuffle.get(i);\n int count = 0;\n Arrays.fill(wasCube, false);\n\n for (int j = 0; j < number.length(); j++) {\n for (int k = 0; k < cubes.length; k++) {\n boolean[] search = cubes[permutation[k]].getHasDigit();\n if (!wasCube[permutation[k]] && search[Character.getNumericValue(number.charAt(j))]) {\n count++;\n wasCube[permutation[k]] = true;\n break;\n }\n }\n }\n\n if (count == number.length()) {\n ok = true;\n break;\n }\n }\n\n if (!ok) {\n System.out.println(x-1);\n return;\n }\n\n }\n System.out.println(999);\n }\n }\n\n public static void main(String[] args) {\n Cube.solve();\n }\n}", "src_uid": "20aa53bffdfd47b4e853091ee6b11a4b"} {"source_code": "import java.awt.Point;\nimport java.io.*;\nimport java.lang.Integer;\nimport java.lang.reflect.Array;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.util.ArrayDeque;\n\nimport static java.lang.Math.*;\n\npublic class Main {\n\n final boolean ONLINE_JUDGE = !new File(\"input.txt\").exists();\n BufferedReader in;\n PrintWriter out;\n StringTokenizer tok = new StringTokenizer(\"\");\n\n void init() throws FileNotFoundException {\n if (ONLINE_JUDGE) {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n } else {\n in = new BufferedReader(new FileReader(\"input.txt\"));\n out = new PrintWriter(\"output.txt\");\n }\n }\n\n String readString() throws IOException {\n while (!tok.hasMoreTokens()) {\n tok = new StringTokenizer(in.readLine());\n }\n return tok.nextToken();\n }\n\n int readInt() throws IOException {\n return Integer.parseInt(readString());\n }\n\n long readLong() throws IOException {\n return Long.parseLong(readString());\n }\n\n double readDouble() throws IOException {\n return Double.parseDouble(readString());\n }\n\n public static void main(String[] args) {\n new Main().run();\n // Sworn to fight and die\n }\n\n public void run() {\n try {\n long t1 = System.currentTimeMillis();\n init();\n solve();\n out.close();\n long t2 = System.currentTimeMillis();\n System.err.println(\"Time = \" + (t2 - t1));\n } catch (Exception e) {\n e.printStackTrace(System.err);\n System.exit(-1);\n }\n }\n\n class LOL implements Comparable<LOL> {\n long count;\n long type;\n\n public LOL(long time, long num) {\n this.count = time;\n this.type = num;\n }\n\n @Override\n public int compareTo(LOL o) {\n\n if (o.count != count)\n return (int) (o.count - count); // ---->\n return (int) (o.type - type); // <----\n }\n\n }\n\n public long gcd(long a, long b) {\n if (a % b == 0)\n return b;\n else\n return gcd(b, a % b);\n }\n\n public int gcd(int a, int b) {\n if (a % b == 0)\n return b;\n else\n return gcd(b, a % b);\n }\n\n boolean prime(int n) {\n for (int i = 2; i <= sqrt(n); i++)\n if (n % i == 0)\n return false;\n return true;\n }\n\n\n\n public void solve() throws IOException {\n int n = readInt();\n char[] s = readString().toCharArray();\n for (int i = 0; i < n - 4; i++)\n for(int j = 1; j <= (n - i - 1)/4; j++)\n if(s[i] == '*' && s[i+j] == '*' && s[i+2*j] == '*'&& s[i+3*j] == '*'&& s[i+4*j] == '*') {\n out.print(\"yes\");\n return;\n }\n out.print(\"no\");\n }\n\n}", "src_uid": "12d451eb1b401a8f426287c4c6909e4b"} {"source_code": "import java.util.*;\n\npublic class Minimizing {\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 k = scanner.nextInt();\n\t\tString S = scanner.next();\n\t\tchar[] digitList = S.toCharArray();\n\t\t\n\t\tif (n == 1 && k > 0) {\n\t\t\tSystem.out.println(0);\n\t\t\tscanner.close();\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tint i = 0, counter = 1;\n\t\t\n\t\tif (S.charAt(0) != '1' && k > 0) {\n\t\t\tdigitList[0] = '1';\n\t\t\ti += 1;\n\t\t}\n\t\t\n\t\twhile (i < k && counter < n) {\t\n\t\t\tif (S.charAt(counter) != '0') {\n\t\t\t\tdigitList[counter] = '0';\n\t\t\t\ti += 1;\t\t\t\t\n\t\t\t}\n\t\t\tcounter += 1;\t\t\t\t\n\t\t}\t\t\n\t\tSystem.out.println(new String(digitList));\n\t\tscanner.close();\n\t}\n}", "src_uid": "0515ac888937a4dda30cad5e2383164f"} {"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.Set;\nimport java.util.InputMismatchException;\nimport java.util.Random;\nimport java.io.IOException;\nimport java.util.HashSet;\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) {\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 int[] degree;\n long[] hash1;\n long[] hash2;\n int[] size;\n Graph graph;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.readInt();\n int[] u = new int[n - 1];\n int[] v = new int[n - 1];\n IOUtils.readIntArrays(in, u, v);\n MiscUtils.decreaseByOne(u, v);\n graph = BidirectionalGraph.createGraph(n, u, v);\n hash1 = new long[2 * n - 2];\n hash2 = new long[2 * n - 2];\n Arrays.fill(hash1, -1);\n Arrays.fill(hash2, -1);\n size = new int[2 * n - 2];\n /*RootHash[] rootHashes = new RootHash[2 * (n - 1)];\n for (int i = 0; i < rootHashes.length; ++i) {\n rootHashes[i] = null;\n }*/\n degree = new int[n];\n for (int i = 0; i < n; ++i) {\n degree[i] = graph.degree(i);\n }\n Set<LongLongPair> hashes = new HashSet<LongLongPair>();\n long[] pow1 = IntegerUtil.generatePowers(HashUtil.MULTIPLIER, 2 * n + 1, HashUtil.FIRST_MOD);\n long[] pow2 = IntegerUtil.generatePowers(HashUtil.MULTIPLIER, 2 * n + 1, HashUtil.SECOND_MOD);\n for (int i = 0; i < n; ++i) {\n if (degree[i] == 4) continue;\n long h1 = calculateHash(i, -1, HashUtil.FIRST_MOD, pow1, hash1).hash;\n long h2 = calculateHash(i, -1, HashUtil.SECOND_MOD, pow2, hash2).hash;\n hashes.add(new LongLongPair(h1, h2));\n }\n out.println(hashes.size());\n }\n\n private TaskD.RootHash calculateHash(int node, int parent, long mod, long[] pow, long[] hash) {\n int length = parent == -1 ? degree[node] : degree[node] - 1;\n long[] sHash = new long[length];\n long[] sSize = new long[length];\n int child = 0;\n for (int i = graph.firstOutbound(node); i != -1; i = graph.nextOutbound(i)) {\n int cNode = graph.destination(i);\n if (cNode == parent) continue;\n if (hash[i] == -1) {\n TaskD.RootHash rh = calculateHash(cNode, node, mod, pow, hash);\n hash[i] = rh.hash;\n size[i] = rh.size;\n }\n sHash[child] = hash[i];\n sSize[child] = size[i];\n child++;\n }\n int[] order = ArrayUtils.order(sHash);\n long res = 0;\n int sz = 1;\n for (int i : order) {\n res += (sHash[i] * pow[sz]) % mod;\n sz += sSize[i];\n }\n res = (res + pow[sz]) % mod;\n sz++;\n TaskD.RootHash rh = new TaskD.RootHash();\n rh.size = sz;\n rh.hash = res;\n return rh;\n }\n\n static class RootHash {\n public int size = -1;\n public long hash = -1;\n\n }\n\n }\n\n static class ArrayUtils {\n public static int[] order(final long[] array) {\n Integer[] order = new Integer[array.length];\n double d = 0;\n for (int i = 0; i < order.length; ++i) {\n order[i] = i;\n }\n Arrays.sort(order, new Comparator<Integer>() {\n public int compare(Integer a, Integer b) {\n return Long.signum(array[a] - array[b]);\n }\n });\n int[] order_ret = new int[order.length];\n for (int i = 0; i < order.length; ++i) {\n order_ret[i] = order[i];\n }\n return order_ret;\n }\n\n }\n\n static class IntegerUtil {\n public static long[] generatePowers(long base, int count, long mod) {\n long[] result = new long[count];\n if (count != 0) {\n result[0] = 1 % mod;\n }\n for (int i = 1; i < count; i++) {\n result[i] = result[i - 1] * base % mod;\n }\n return result;\n }\n\n }\n\n static class LongLongPair implements Comparable<LongLongPair> {\n public final long first;\n public final long second;\n\n public LongLongPair(long first, long second) {\n this.first = first;\n this.second = second;\n }\n\n public boolean equals(Object o) {\n if (this == o) {\n return true;\n }\n if (o == null || getClass() != o.getClass()) {\n return false;\n }\n\n LongLongPair pair = (LongLongPair) o;\n\n return first == pair.first && second == pair.second;\n }\n\n @SuppressWarnings(\"Since15\")\n public int hashCode() {\n int result = Long.hashCode(first);\n result = 31 * result + Long.hashCode(second);\n return result;\n }\n\n public String toString() {\n return \"(\" + first + \",\" + second + \")\";\n }\n\n @SuppressWarnings({\"unchecked\", \"Since15\"})\n public int compareTo(LongLongPair o) {\n int value = Long.compare(first, o.first);\n if (value != 0) {\n return value;\n }\n return Long.compare(second, o.second);\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 // InputMismatchException -> UnknownError\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 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 } else if (c == '+') {\n c = read();\n }\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public static boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n }\n\n static class MiscUtils {\n public static void decreaseByOne(int[]... arrays) {\n for (int[] array : arrays) {\n for (int i = 0; i < array.length; ++i) {\n array[i]--;\n }\n }\n }\n\n }\n\n static interface Edge {\n }\n\n static class HashUtil {\n public static final long MULTIPLIER;\n public static final long FIRST_MOD;\n public static final long SECOND_MOD;\n\n static {\n Random random = new Random(System.currentTimeMillis());\n FIRST_MOD = Prime.nextPrime((long) (1e9 + random.nextInt((int) 1e9)));\n SECOND_MOD = Prime.nextPrime((long) (1e9 + random.nextInt((int) 1e9)));\n MULTIPLIER = random.nextInt((int) 1e9 - 257) + 257;\n }\n }\n\n static class Prime {\n public static boolean isPrime(long number) {\n if (number < 2) {\n return false;\n }\n for (long i = 2; i * i <= number; i++) {\n if (number % i == 0) {\n return false;\n }\n }\n return true;\n }\n\n public static long nextPrime(long from) {\n if (from <= 2) {\n return 2;\n }\n from += 1 - (from & 1);\n while (!isPrime(from)) {\n from += 2;\n }\n return from;\n }\n\n }\n\n static class BidirectionalGraph extends Graph {\n public int[] transposedEdge;\n\n public BidirectionalGraph(int vertexCount) {\n this(vertexCount, vertexCount);\n }\n\n public BidirectionalGraph(int vertexCount, int edgeCapacity) {\n super(vertexCount, 2 * edgeCapacity);\n transposedEdge = new int[2 * edgeCapacity];\n }\n\n public static BidirectionalGraph createGraph(int vertexCount, int[] from, int[] to) {\n BidirectionalGraph graph = new BidirectionalGraph(vertexCount, from.length);\n for (int i = 0; i < from.length; i++) {\n graph.addSimpleEdge(from[i], to[i]);\n }\n return graph;\n }\n\n\n public int addEdge(int fromID, int toID, long weight, long capacity, int reverseEdge) {\n int lastEdgeCount = edgeCount;\n super.addEdge(fromID, toID, weight, capacity, reverseEdge);\n super.addEdge(toID, fromID, weight, capacity, reverseEdge == -1 ? -1 : reverseEdge + 1);\n this.transposedEdge[lastEdgeCount] = lastEdgeCount + 1;\n this.transposedEdge[lastEdgeCount + 1] = lastEdgeCount;\n return lastEdgeCount;\n }\n\n\n protected int entriesPerEdge() {\n return 2;\n }\n\n\n protected void ensureEdgeCapacity(int size) {\n if (size > edgeCapacity()) {\n super.ensureEdgeCapacity(size);\n transposedEdge = resize(transposedEdge, edgeCapacity());\n }\n }\n\n }\n\n static class IOUtils {\n public static void readIntArrays(InputReader in, int[]... arrays) {\n for (int i = 0; i < arrays[0].length; ++i) {\n for (int j = 0; j < arrays.length; ++j) {\n arrays[j][i] = in.readInt();\n }\n }\n }\n\n }\n\n static class Graph {\n protected int vertexCount;\n protected int edgeCount;\n private int[] firstOutbound;\n private int[] firstInbound;\n private Edge[] edges;\n private int[] nextInbound;\n private int[] nextOutbound;\n private int[] from;\n private int[] to;\n private long[] weight;\n public long[] capacity;\n private int[] reverseEdge;\n private int[] flags;\n private boolean[] isRemoved;\n\n public Graph(int vertexCount) {\n this(vertexCount, vertexCount);\n }\n\n public Graph(int vertexCount, int maxEdge) {\n this.vertexCount = vertexCount;\n firstOutbound = new int[vertexCount];\n Arrays.fill(firstOutbound, -1);\n\n from = new int[maxEdge];\n to = new int[maxEdge];\n nextOutbound = new int[maxEdge];\n flags = new int[maxEdge];\n isRemoved = new boolean[maxEdge];\n }\n\n public int addEdge(int fromID, int toID, long weight, long capacity, int reverseEdge) {\n ensureEdgeCapacity(edgeCount + 1);\n if (firstOutbound[fromID] != -1) {\n nextOutbound[edgeCount] = firstOutbound[fromID];\n } else {\n nextOutbound[edgeCount] = -1;\n }\n firstOutbound[fromID] = edgeCount;\n if (firstInbound != null) {\n if (firstInbound[toID] != -1) {\n nextInbound[edgeCount] = firstInbound[toID];\n } else {\n nextInbound[edgeCount] = -1;\n }\n firstInbound[toID] = edgeCount;\n }\n this.from[edgeCount] = fromID;\n this.to[edgeCount] = toID;\n if (capacity != 0) {\n if (this.capacity == null) {\n this.capacity = new long[from.length];\n }\n this.capacity[edgeCount] = capacity;\n }\n if (weight != 0) {\n if (this.weight == null) {\n this.weight = new long[from.length];\n }\n this.weight[edgeCount] = weight;\n }\n if (reverseEdge != -1) {\n if (this.reverseEdge == null) {\n this.reverseEdge = new int[from.length];\n Arrays.fill(this.reverseEdge, 0, edgeCount, -1);\n }\n this.reverseEdge[edgeCount] = reverseEdge;\n }\n if (edges != null) {\n edges[edgeCount] = createEdge(edgeCount);\n }\n return edgeCount++;\n }\n\n protected final GraphEdge createEdge(int id) {\n return new GraphEdge(id);\n }\n\n public final int addFlowWeightedEdge(int from, int to, long weight, long capacity) {\n if (capacity == 0) {\n return addEdge(from, to, weight, 0, -1);\n } else {\n int lastEdgeCount = edgeCount;\n addEdge(to, from, -weight, 0, lastEdgeCount + entriesPerEdge());\n return addEdge(from, to, weight, capacity, lastEdgeCount);\n }\n }\n\n protected int entriesPerEdge() {\n return 1;\n }\n\n public final int addWeightedEdge(int from, int to, long weight) {\n return addFlowWeightedEdge(from, to, weight, 0);\n }\n\n public final int addSimpleEdge(int from, int to) {\n return addWeightedEdge(from, to, 0);\n }\n\n protected final int edgeCapacity() {\n return from.length;\n }\n\n public final int firstOutbound(int vertex) {\n int id = firstOutbound[vertex];\n while (id != -1 && isRemoved(id)) {\n id = nextOutbound[id];\n }\n return id;\n }\n\n public final int nextOutbound(int id) {\n id = nextOutbound[id];\n while (id != -1 && isRemoved(id)) {\n id = nextOutbound[id];\n }\n return id;\n }\n\n public final int degree(int vertex) {\n int degree = 0;\n for (int j = firstOutbound(vertex); j != -1; j = nextOutbound(j)) {\n degree++;\n }\n return degree;\n }\n\n public final int destination(int id) {\n return to[id];\n }\n\n public final boolean isRemoved(int id) {\n return isRemoved[id];\n }\n\n protected void ensureEdgeCapacity(int size) {\n if (from.length < size) {\n int newSize = Math.max(size, 2 * from.length);\n if (edges != null) {\n edges = resize(edges, newSize);\n }\n from = resize(from, newSize);\n to = resize(to, newSize);\n nextOutbound = resize(nextOutbound, newSize);\n if (nextInbound != null) {\n nextInbound = resize(nextInbound, newSize);\n }\n if (weight != null) {\n weight = resize(weight, newSize);\n }\n if (capacity != null) {\n capacity = resize(capacity, newSize);\n }\n if (reverseEdge != null) {\n reverseEdge = resize(reverseEdge, newSize);\n }\n flags = resize(flags, newSize);\n isRemoved = resize(isRemoved, newSize);\n }\n }\n\n protected final boolean[] resize(boolean[] array, int size) {\n boolean[] newArray = new boolean[size];\n System.arraycopy(array, 0, newArray, 0, array.length);\n return newArray;\n }\n\n protected final int[] resize(int[] array, int size) {\n int[] newArray = new int[size];\n System.arraycopy(array, 0, newArray, 0, array.length);\n return newArray;\n }\n\n private long[] resize(long[] array, int size) {\n long[] newArray = new long[size];\n System.arraycopy(array, 0, newArray, 0, array.length);\n return newArray;\n }\n\n private Edge[] resize(Edge[] array, int size) {\n Edge[] newArray = new Edge[size];\n System.arraycopy(array, 0, newArray, 0, array.length);\n return newArray;\n }\n\n protected class GraphEdge implements Edge {\n protected int id;\n\n protected GraphEdge(int id) {\n this.id = id;\n }\n\n }\n\n }\n}\n\n", "src_uid": "3c5aedd5d3bc12dca3e921c95ef05270"} {"source_code": "//package Codeforces.Div2A_156.Code1;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n/*\n * some cheeky quote\n */\n\npublic class Main\n{\n FastScanner in;\n PrintWriter out;\n private int a[] = new int[3];\n\n public void solve() throws IOException\n {\n int count = 0;\n int max = Integer.MIN_VALUE;\n int result = -1;\n int n = in.nextInt();\n for (int i = 0; i < n; i++)\n {\n a[count] += in.nextInt();\n if (max < a[count])\n {\n max = a[count];\n result = count;\n }\n count = (count + 1) % 3;\n }\n if (result == 0)\n {\n System.out.println(\"chest\");\n } else if (result == 1)\n {\n System.out.println(\"biceps\");\n } else\n {\n System.out.println(\"back\");\n }\n\n }\n\n public void run()\n {\n try\n {\n in = new FastScanner();\n out = new PrintWriter(System.out);\n\n solve();\n\n out.close();\n } catch (IOException e)\n {\n e.printStackTrace();\n }\n }\n\n class FastScanner\n {\n BufferedReader br;\n StringTokenizer st;\n\n FastScanner()\n {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n String next()\n {\n while (st == null || !st.hasMoreTokens())\n {\n try\n {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e)\n {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt()\n {\n return Integer.parseInt(next());\n }\n }\n\n public static void main(String[] arg)\n {\n new Main().run();\n }\n}\n\n", "src_uid": "579021de624c072f5e0393aae762117e"} {"source_code": "import java.util.*;\npublic class Main {\n public static void main(String[] args) {\n Scanner console = new Scanner(System.in);\n String word = console.next() + console.next();\n String all = console.next();\n char tempArray1[] = word.toCharArray();\n Arrays.sort(tempArray1);\n char tempArray3[] = all.toCharArray();\n Arrays.sort(tempArray3);\n String wordNew = Arrays.toString(tempArray1);\n String allNew = Arrays.toString(tempArray3);\n if (allNew.contains(wordNew)) {\n System.out.println(\"YES\");\n } else {\n System.out.println(\"NO\");\n }\n }\n}", "src_uid": "b6456a39d38fabcd25267793ed94d90c"} {"source_code": "import java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.FileOutputStream;\nimport java.io.FileReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintStream;\nimport java.util.*;\n\npublic class Main implements Runnable {\n\tprivate boolean _READ_FROM_FILE = false; //System.getSecurityManager() == null; //System.getProperty(\"ONLINE_JUDGE\") == null;\n\tprivate boolean _WRITE_TO_FILE = false;\n\tstatic final String _TASK_ID = \"in\";\n\tstatic final String _IN_FILE = _TASK_ID + \".in\";\n\tstatic final String _OUT_FILE = _TASK_ID + \".out\";\n\tBufferedReader reader;\n\tStringTokenizer tokenizer;\n\tprivate int[] x;\n\tprivate int[] y;\n\n\tprivate void core() throws Exception {\n\t\tint n = nextInt(), start = nextInt(); --start;\n\t\tx = new int[n + 1];\n\t\ty = new int[n + 1];\n\t\tfor (int i = 0; i < y.length; i++) {\n\t\t\tx[i] = nextInt();\n\t\t}\n\t\ty[n] = nextInt();\n\t\tint xstart = x[start];\n\t\tArrays.sort(x, 0, n);\n\t\tif (start != n) {\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (x[i] == xstart)\n\t\t\t\t\tstart = i;\n\t\t\t}\n\t\t}\n\t\tdouble res = dist(start, n) + solve(n, start != 0 ? 0 : 1, start != n - 1 ? n - 1 : n - 2);\n\t\tif (start != n) {\n\t\t\tfor (int i = start; i < n; i++) {\n\t\t\t\t//[0, start]\n\t\t\t\tdouble now = solve2(start, 0, i, n) + solve(n, i + 1, n - 1);\n\t\t\t\tres = Math.min(res, now);\n\t\t\t}\n\t\t\tfor (int i = 0; i <= start; i++) {\n\t\t\t\t//[i, n-1]\n\t\t\t\tdouble now = solve2(start, i, n-1, n) + solve(n, 0, i - 1);\n\t\t\t\tres = Math.min(res, now);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(res);\n\t}\n\tprivate double solve2(int start, int i, int j, int n) {\n\t\tdouble d1 = dist(start, i) + dist(i, j) + dist(j, n);\n\t\tdouble d2 = dist(start, j) + dist(j, i) + dist(i, n);\n\t\treturn Math.min(d1, d2);\n\t}\n\tprivate double dist(int i, int j) {\n\t\treturn Math.hypot(x[i] - x[j] , y[i] - y[j]);\n\t}\n\tprivate double solve(int n, int i, int j) {\n\t\tif (i > j) return 0;\n\t\treturn dist(i, j) + Math.min(dist(n, i), dist(n, j));\n\t}\n\tvoid debug(Object...os) {\n\t\tSystem.out.println(Arrays.deepToString(os));\n\t}\n\t//--------------------- IO stuffs ---------------------\n public static void main(String[] args) throws InterruptedException {\n Thread thread = new Thread(new Main());\n thread.start();\n thread.join();\n }\n\tpublic void run() {\n try {\n \treader = new BufferedReader(_READ_FROM_FILE ? new FileReader(_IN_FILE) : new InputStreamReader(System.in));\n \tSystem.setOut(new PrintStream(new BufferedOutputStream(_WRITE_TO_FILE ? new FileOutputStream(_OUT_FILE) : System.out)));\n tokenizer = new StringTokenizer(\"\");\n core();\n reader.close();\n System.out.flush();\n System.out.close();\n System.exit(0);\n } catch (Exception e) {\n \tSystem.out.flush();\n e.printStackTrace();\n System.exit(1);\n }\n }\n int nextInt() throws Exception {\n return Integer.parseInt(nextToken());\n }\n long nextLong() throws Exception {\n return Long.parseLong(nextToken());\n }\n double nextDouble() throws Exception {\n return Double.parseDouble(nextToken());\n }\n String nextToken() throws Exception {\n while (!tokenizer.hasMoreTokens())\n\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n return tokenizer.nextToken();\n }\n boolean nextIsAvailable() throws Exception {\n \twhile (!tokenizer.hasMoreElements()) {\n \t\tString line = reader.readLine();\n \t\tif (line == null) return false;\n \t\ttokenizer = new StringTokenizer(line);\n \t}\n \treturn true;\n }\n}\n", "src_uid": "f9ed5faca211e654d9d4e0a7557616f4"} {"source_code": "import java.io.*;\nimport java.util.StringTokenizer;\n\n\npublic class Main {\n\n public static final String FILE_NAME = \"in\";\n\n public static void main(String[] args) throws IOException {\n InputStream inputStream = System.in;\n// InputStream inputStream = new FileInputStream(FILE_NAME + \".in\");\n OutputStream outputStream = System.out;\n// OutputStream outputStream = new FileOutputStream(FILE_NAME + \".out\");\n\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n Answer solver = new Answer();\n solver.solve(in, out);\n out.close();\n }\n}\n\nclass Answer {\n private final int INF = (int) (1e9 + 7);\n private final int MOD = (int) (1e9 + 7);\n private final int MOD1 = (int) (1e6 + 3);\n private final long INF_LONG = (long) (1e18 + 1);\n private final double EPS = 1e-9;\n\n private long gcd(long a, long b) {\n return (b == 0) ? a : gcd(b, a % b);\n }\n\n private long lcm(long a, long b) {\n return a * b / gcd(a, b);\n }\n\n public void solve(InputReader in, PrintWriter out) throws IOException {\n String s = in.next();\n\n int ans = 0;\n for (int i = 0; i < s.length(); i++) {\n char c = s.charAt(i);\n\n if (!(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') && 'a' <= c && c <= 'z') {\n ans++;\n } else if (c == '0' || c == '2' || c == '4' || c == '6' || c == '8') {\n ans++;\n }\n }\n\n out.println(s.length() - ans);\n }\n}\n\nclass InputReader {\n private BufferedReader reader;\n private StringTokenizer tokenizer;\n\n InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n 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 int[] nextArrayInt(int count) {\n return nextArrayInt(0, count);\n }\n\n public int[] nextArrayInt(int start, int count) {\n int[] a = new int[start + count];\n for (int i = start; i < start + count; i++) {\n a[i] = nextInt();\n }\n return a;\n }\n\n public long[] nextArrayLong(int count) {\n long[] a = new long[count];\n for (int i = 0; i < count; i++) {\n a[i] = nextLong();\n }\n return a;\n }\n}\n", "src_uid": "b4af2b8a7e9844bf58ad3410c2cb5223"} {"source_code": "/*\t/ \uff8c\uff8c\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u30e0\n\t/ )\\\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800 Y\n\t(\u2800\u2800| ( \u0361\u00b0 \u035c\u0296 \u0361\u00b0\uff09\u2800\u2312(\u2800 \u30ce\n\t(\u2800 \uff89\u2312 Y \u2312\u30fd-\u304f __\uff0f\n\t| _\u2800\uff61\u30ce| \u30ce\uff61 |/\n\t(\u2800\u30fc '_\u4eba`\u30fc \uff89\n\t\u2800|\\ \uffe3 _\u4eba'\u5f61\uff89\n\t\u2800 )\\\u2800\u2800 \uff61\u2800\u2800 /\n\t\u2800\u2800(\\\u2800 #\u2800 /\n\t\u2800/\u2800\u2800\u2800/\u1f63====================D-\n\t/\u2800\u2800\u2800/\u2800 \\ \\\u2800\u2800\\\n\t( (\u2800)\u2800\u2800\u2800\u2800 ) ).\u2800)\n\t(\u2800\u2800)\u2800\u2800\u2800\u2800\u2800( | /\n\t|\u2800 /\u2800\u2800\u2800\u2800\u2800\u2800 | /\n\t[_] \u2800\u2800\u2800\u2800\u2800[___] */\n// Main Code at the Bottom\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.math.BigInteger; \npublic class Main {\n\t//Fast IO class\n static class FastReader {\n BufferedReader br; \n StringTokenizer st; \n public FastReader() {\n \tboolean env=System.getProperty(\"ONLINE_JUDGE\") != null;\n \tif(!env) {\n \t\ttry {\n\t\t\t\t\tbr=new BufferedReader(new FileReader(\"src\\\\input.txt\"));\n\t\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n \t}\n \telse br = new BufferedReader(new InputStreamReader(System.in)); \n } \n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine()); \n } \n catch (IOException e) {\n e.printStackTrace(); \n } \n } \n return st.nextToken(); \n } \n int nextInt() {\n return Integer.parseInt(next()); \n } \n long nextLong() {\n return Long.parseLong(next()); \n } \n double nextDouble() {\n return Double.parseDouble(next()); \n } \n String nextLine() {\n String str = \"\"; \n try {\n str = br.readLine(); \n } \n catch (IOException e) {\n e.printStackTrace(); \n } \n return str; \n } \n } \n static long MOD=1000000000+7;\n //Euclidean Algorithm\n static long gcd(long A,long B){\n \treturn (B==0)?A:gcd(B,A%B);\n }\n //Modular Exponentiation\n static long fastExpo(long x,long n){\n if(n==0) return 1;\n if((n&1)==0) return fastExpo((x*x)%MOD,n/2)%MOD;\n return ((x%MOD)*fastExpo((x*x)%MOD,(n-1)/2))%MOD;\n }\n //Modular Inverse\n static long inverse(long x) {\n \treturn fastExpo(x,MOD-2);\n }\n //Prime Number Algorithm\n static boolean isPrime(long n){\n if(n<=1) return false;\n if(n<=3) return true;\n if(n%2==0 || n%3==0) return false;\n for(int i=5;i*i<=n;i+=6) if(n%i==0 || n%(i+2)==0) return false;\n return true;\n }\n //Reverse an array\n static void reverse(char arr[],int l,int r){\n \twhile(l<r) {\n \t\tchar tmp=arr[l];\n \t\tarr[l++]=arr[r];\n \t\tarr[r--]=tmp;\n \t}\n }\n //Print array\n static void print1d(int arr[]) {\n \tout.println(Arrays.toString(arr));\n }\n static void print2d(int arr[][]) {\n \tfor(int a[]: arr) out.println(Arrays.toString(a));\n }\n // Pair\n static class pair{\n \tint x,y;\n \tpair(int a,int b){\n \t\tthis.x=a;\n \t\tthis.y=b;\n \t}\n \tpublic boolean equals(Object obj) {\n \t\tif(obj == null || obj.getClass()!= this.getClass()) return false;\n pair p = (pair) obj;\n return (this.x==p.x && this.y==p.y);\n }\n \tpublic int hashCode() {\n return Objects.hash(x,y);\n }\n }\n static FastReader sc=new FastReader();\n static PrintWriter out=new PrintWriter(System.out); \n //Main function(The main code starts from here\n public static void main (String[] args) throws java.lang.Exception {\n \tint test=1;\n \t//test=sc.nextInt();\n \twhile(test-->0){\n \t\tlong n=sc.nextLong();\n \t\tif(n%2==0) {\n \t\t\tout.println(\"white\");\n \t\t\tout.println(\"1 2\");\n \t\t}\n \t\telse out.println(\"black\");\n \t}\n out.flush();\n out.close();\n }\n}", "src_uid": "52e07d176aa1d370788f94ee2e61df93"} {"source_code": "import java.util.Scanner;\npublic class TheatreSquare {\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 long c=sc.nextLong();\n if(a%c==0){a=a/c;}else{a=a/c+1;}\n if(b%c==0){b=b/c;}else{b=b/c+1;}\n System.out.println(a*b);\n }\n}", "src_uid": "ef971874d8c4da37581336284b688517"} {"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[1500001];\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(1, Math.max(-min, max)) + 1) * K.length;\n double poisson = -Double.MAX_VALUE;\n for (int j = Math.max(1, Math.max(-min, (int) var - 100)); j <= Math.min(2000, (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", "src_uid": "6ef75e501b318c0799d3cbe8ca998984"} {"source_code": "//package practice;\n\nimport java.util.Scanner;\n\n/**\n * Created by yi on 2015/10/29.\n */\npublic class Coloring {\n public static int mod = 1000000007;\n static long fac[];\n static long rev[];\n static long dp[];\n\n static long pow_mod(long a, int i, long n) {\n if (i == 0) return 1 % n;\n long temp = pow_mod(a, i >> 1, n);\n temp = temp * temp % n;\n if ((i & 1) == 1) temp = temp * a % n;\n return temp;\n\n }\n\n static void init() {\n fac = new long[1000005];\n rev = new long[1000005];\n dp = new long[1005];\n fac[0] = 1;\n fac[1] = 1;\n rev[0] = 1;\n for (int i = 1; i <= 1000000; i++) {\n fac[i] = fac[i - 1] * i % mod;\n rev[i] = pow_mod(fac[i], mod - 2, mod);\n }\n }\n\n static long C(int n, int m) {\n return (fac[n] * rev[m] % mod) * rev[n - m] % mod;\n }\n\n public static void main(String[] args) {\n init();\n int n, m, k;\n Scanner scanner = new Scanner(System.in);\n n = scanner.nextInt();\n m = scanner.nextInt();\n k = scanner.nextInt();\n if (m == 1) {\n System.out.println(pow_mod(k, n, mod));\n return;\n }\n\n for (int i = 1; i <= n && i <= k; i++) {\n dp[i] = pow_mod(i, n, mod);\n for (int j = 1; j < i; j++) {\n dp[i] = (dp[i] - C(i, j) * dp[j] % mod) + mod;\n dp[i] %= mod;\n }\n }\n\n long ans = 0;\n if (m == 2) {\n for (int i = 1; i <= n && i <= k; i++) {\n ans = (ans + (((dp[i] * dp[i] % mod) * C(k, i) % mod) * C(k, i)) % mod) % mod;\n }\n System.out.println(ans);\n } else {\n for (int i = 1; i <= n && i <= k; i++) {\n for (int j = 0; 2 * j + i <= k && i + j <= n; j++) {\n long tmp = dp[i + j] * dp[i + j] % mod;\n tmp = ((tmp * C(k, i) % mod) * C(k - i, j) % mod) * C(k - i - j, j) % mod;\n// System.out.println(\"\"+k+\" \"+i+\" \"+C(k,i));\n tmp = (tmp * pow_mod(i, n * (m - 2), mod)) % mod;\n ans = (ans + tmp) % mod;\n }\n }\n System.out.println(ans);\n }\n }\n\n}\n", "src_uid": "f22f28e2d8933f4199ba5ccfc0de8cda"} {"source_code": "\nimport java.util.Scanner;\n\npublic class cf {\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint tab[] = {\t4, 22, 27, 58, 85, 94, 121, 166, 202, 265, 274, 319, 346, 355, 378, 382, 391, 438, 454, 483, 517, 526, 535, 562, 576, 588, 627, 634, 636, 645, 648, 654, 663, 666, 690, 706, 728, 729, 762, 778, 825, 852, 861, 895, 913, 915, 922, 958, 985, 1086, 1111};\n\t\tSystem.out.println(tab[in.nextInt()-1]);\n\t}\n\n}\n", "src_uid": "bf65a25185e9ea5b71e853723b838b04"} {"source_code": "import java.lang.Math;\nimport java.util.Scanner;\npublic class Java_codeforce_A_Forgetting_Things {\n private static final Scanner SCANNER=new Scanner(System.in);\n public static void main(String[]args){\n\n int da=SCANNER.nextInt();\n int db=SCANNER.nextInt();\n\n check(da,db);\n\n calculate(da,db);\n\n SCANNER.close();\n }\n private static void check(int da,int db)\n {\n if((da<1||da>9||(db<1||db>9)))\n {\n System.exit(-1);\n }\n }\n private static void calculate(int da,int db)\n {\n int a=0,b;\n b=a+1;\n\n if(db-da==1)\n {\n b=(int)(db*100);\n a=b-1;\n System.out.println(a+\" \"+b);\n }\n else if((da-db>1||da-db<-1)&&(da!=9||db!=1))\n {\n System.out.println(\"-1\");\n }\n else if(da-db==1)\n {\n System.out.println(\"-1\");\n }\n else if(da-db==-1)\n {\n System.out.println(da+\" \"+db);\n }\n else if(da==9&&db==1)\n {\n System.out.println(da+\" \"+db*10);\n }\n else if(da==db)\n {\n a=da*100;\n b=a+1;\n System.out.println(a+\" \"+b);\n }\n }\n\n}\n", "src_uid": "3eff6f044c028146bea5f0dfd2870d23"} {"source_code": "import java.util.Scanner;\n\npublic 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 }else if(i==1){\n System.out.println(result+\"\");\n }\n \n }\n\n }\n \n}\n", "src_uid": "82a4a60eac90765fb62f2a77d2305c01"} {"source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\npublic class Pangram520A {\n\tpublic static void main(String[] args) throws Exception {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tint length = Integer.parseInt(br.readLine());\n\t\tString thisLine = br.readLine();\n\t\tthisLine=thisLine.toLowerCase();\n\t\tString check=\"\";\n\t\tif (length >= 26)\n\t\t\tfor (int i = 0; i < length; i++) {\n\t\t\t\tif (!check.contains(thisLine.charAt(i) + \"\")) {\n\t\t\t\t\tcheck += thisLine.charAt(i);\n\t\t\t\t}\n\t\t\t}\n\t\tif (check.length() < 26)\n\t\t\tSystem.out.println(\"NO\");\n\t\telse\n\t\t\tSystem.out.println(\"YES\");\n\t}\n}", "src_uid": "f13eba0a0fb86e20495d218fc4ad532d"} {"source_code": "import java.util.Scanner;\n\n\npublic class StonesOnTheTable {\n\n public static void main(String[] args) {\n // TODO Auto-generated method stub\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n in.nextLine(); // skip the \\n character\n String s = in.nextLine();\n int result = 0;\n for (int i = 1; i < s.length(); i++) {\n if (s.charAt(i) == s.charAt(i-1)) result++;\n }\n System.out.println(result);\n }\n\n}\n", "src_uid": "d561436e2ddc9074b98ebbe49b9e27b8"} {"source_code": "import java.util.Scanner;\n\npublic class P3 {\n\tpublic static void calcula(int limite, int[] lista) {\n\t \n\t int n = 2;\n\t \n\t while (n < limite) {\n\t int num = n*2;\n\t while (num < limite) {\n\t lista[num] = n;\n\t num += n;\n\t }\n\t num = n + 1;\n\t while (num<limite) {\n\t if(lista[num] != 0){\n\t num++; \n\t }\n\t else{\n\t break;\n\t }\n\t \n\t }\n\t n = num;\n\t }\n\t}\n\t\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint xi, xm, xf;\n\t\tint limite = 1000006;\n\t\tint[] lista = new int[limite];\n\t\t\n\t\tcalcula(limite,lista);\n\t \n\t\txm = in.nextInt();\n\t\tint a = 0, b = 0;\n b = lista[xm];\n xi = 99999999;\n for (int i= xm-b+1;i<=xm;i++) {\n a = lista[i];\n xi = Math.min(i-a+1, xi);\n }\n System.out.println(xi);\n\t \n\t\t\n\n\t\t\n\t}\n\n\t}\n\n\t\n", "src_uid": "43ff6a223c68551eff793ba170110438"} {"source_code": "\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.IOException;\nimport java.nio.file.Paths;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.List;\n\npublic class Main {\n\n\tpublic Main() throws FileNotFoundException {\n\n//\t\tFile file = Paths.get(\"input.txt\").toFile();\n//\t\tif (file.exists()) {\n//\t\t\tSystem.setIn(new FileInputStream(file));\n//\t\t}\n\t\t// long t = System.currentTimeMillis();\n\n\t\tInputReader reader = new InputReader();\n\n\t\tint h=reader.nextInt();\n\t\tint w=reader.nextInt();\n\t\t\n\t\tchar[][] a=new char[h][w];\n\t\t\n\t\tfor(int y=0;y<h;y++) {\n\t\t\ta[y]=reader.nextLine().toCharArray();\n\t\t}\n\t\t\n\t\tint x=0;\n\t\tint y=0;\n\t\tint c=0;\n\t\tif(a[y][x]=='*') {\n\t\t\tc++;\n\t\t}\n\t\t\n\t\twhile(x!=w-1||y!=h-1) {\n\t\t\t\n\t\t\tif(x+1<w&&a[y][x+1]=='*') {\n\t\t\t\tx++;\n\t\t\t\tc++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif(y+1<h&&a[y+1][x]=='*') {\n\t\t\t\ty++;\n\t\t\t\tc++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif(x+1<w) {\n\t\t\t\tx++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif(y+1<h) {\n\t\t\t\ty++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\tSystem.out.println(c);\n\t\t\n\t\n\t}\n\t\n\t\n\n\tstatic class InputReader {\n\t\tprivate byte[] buf = new byte[16384];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n\n\t\tpublic int read() {\n\t\t\tif (numChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= numChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tnumChars = System.in.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (numChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isEndOfLine(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic String nextString() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo {\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\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\n\t}\n\n\tpublic static void main(String[] args) throws FileNotFoundException {\n\t\tnew Main();\n\t}\n\n}\n", "src_uid": "f985d7a6e7650a9b855a4cef26fd9b0d"} {"source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.File;\nimport java.io.FileReader;\nimport java.io.FileWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.util.StringTokenizer;\n\npublic class Hehe {\n\tint H, W, K;\n\tIO io = new IO();\n\t\n\tvoid begin() {\n\t\tH = io.nextInt();\n\t\tW = io.nextInt();\n\t\tK = io.nextInt();\n\t\t\n\t\tlong result = 0;\n\t\tfor(int i=0; i<K; i++) {\n\t\t\tresult += 2*(H+W)-4;\n\t\t\tH-=4;\n\t\t\tW-=4;\n\t\t}\n\t\t\n\t\tio.out(\"%d\\n\", result);\n\t\tio.done();\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\t(new Hehe()).begin();\n\t}\n\t\n\tstatic class IO {\n\t\tBufferedReader reader;\n\t\tStringTokenizer tokenizer;\n\t\tBufferedWriter writer;\n\t\tboolean isAutoFlush;\n\t\t\n\t\tpublic IO() {\n\t\t\tthis(false, null, null);\n\t\t}\n\t\t\n\t\tpublic IO(boolean isAutoFlush, String fileFrom, String fileTo) {\n\t\t\tif(fileFrom == null) {\n\t\t\t\treader = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t} else {\n\t\t\t\ttry {\n\t\t\t\t\treader = new BufferedReader(new FileReader(new File(fileFrom)));\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\t\n\t\t\tif(fileTo == null) {\n\t\t\t\twriter = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\t\t} else {\n\t\t\t\ttry {\n\t\t\t\t\twriter = new BufferedWriter(new FileWriter(new File(fileTo)));\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\t\n\t\t\ttokenizer = new StringTokenizer(\"\");\n\t\t}\n\t\t\n\t\tprivate String next() {\n\t\t\twhile (!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) { //EOF\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tokenizer.nextToken();\n\t\t}\n\t\t\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tpublic long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\tpublic String nextString() {\n\t\t\treturn next();\n\t\t}\n\t\tpublic double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\t\n\t\tpublic void out(String format, Object... args) {\n\t\t\ttry {\n\t\t\t\tString string = String.format(format, args);\n\t\t\t\twriter.write(string);\n\t\t\t\tif(isAutoFlush) writer.flush();\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic void done() {\n\t\t\ttry {\n\t\t\t\twriter.flush();\n\t\t\t\treader.close();\n\t\t\t\twriter.close();\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\t}\n}\n", "src_uid": "2c98d59917337cb321d76f72a1b3c057"} {"source_code": "//package cf195;\n\nimport java.util.*;\nimport java.io.*;\n\npublic class D {\n\tFastScanner in;\n\tPrintWriter out;\n\t\n\tlong[] fact;\n\tfinal long mod = (long) (1e9 + 7);\n\t\n\tpublic void solve() throws IOException {\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tint g = in.nextInt();\n\t\tfact = new long[n + m + 1];\n\t\tfact[0] = 1;\n\t\tfor (int i = 1; i <= n + m; i++) {\n\t\t\tfact[i] = (fact[i - 1] * i) % mod ;\n\t\t}\n\t\tSystem.out.println(getAns(n, m, g));\n\t}\n\t\n\t\n\t\n\tpublic long getAns(int n, int m, int req) {\n\t\tif (n == 0) {\n\t\t\tif (m == 0) {\n\t\t\t\tif (req == 0) {\n\t\t\t\t\treturn 0;\n\t\t\t\t} else {\n\t\t\t\t\treturn 1;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t} \n\t\t\tif (m == 1) {\n\t\t\t\tif (req == 1) {\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\t\n\t\t\tif (m > 1) {\n\t\t\t\tif (req == 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\tif (req == 0) {\n\t\t\tlong ans = getAns(n - 1, m, 1);\n\t\t\tif (m > 0) {\n\t\t\t\tans = (ans + cnk(n + m - 1, m - 1)) % mod;\n\t\t\t}\n\t\t\treturn ans;\n\t\t} else {\n\t\t\treturn getAns(n - 1, m, 0);\n\t\t}\n\t}\n\t\n\tpublic long cnk(int n, int k) {\n\t\treturn (((fact[n] * inverse(fact[k])) % mod) * inverse(fact[n - k])) % mod;\n\t}\n\t\n\tpublic long inverse(long x) {\n\t\treturn power(x, mod - 2, mod);\n\t}\n\t\n\tpublic long power(long x, long pow, long mod) {\n\t\tif (pow == 0) {\n\t\t\treturn 1;\n\t\t}\n\t\tif ((pow % 2) == 0) {\n\t\t\treturn power(((x * x) % mod), pow / 2, mod);\n\t\t} else {\n\t\t\treturn (power(x, pow - 1, mod) * x) % mod;\n\t\t}\n\t}\n\t\n\t\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new FastScanner(System.in);\n\t\t\tout = new PrintWriter(System.out);\n\n\t\t\tsolve();\n\n\t\t\tout.close();\n\t\t} catch (IOException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\n\tclass FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tFastScanner(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 in) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(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(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\t}\n\n\tpublic static void main(String[] arg) {\n\t\tnew D().run();\n\t}\n}", "src_uid": "066dd9e6091238edf2912a6af4d29e7f"} {"source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class D {\n static int n;\n \n public static void dfs(int i, int n, int[] a, int[] res, boolean[] v) {\n if (i == n) {\n if (check(res)) {\n print(res);\n System.exit(0);\n }\n } else {\n for (int j = 0; j < n; j++) if (!v[j]) {\n v[j] = true;\n res[i] = a[j];\n dfs(i + 1, n, a, res, v);\n v[j] = false;\n }\n }\n }\n private static void print(int[] a) {\n int sum = 0;\n for (int i = 0; i < n; i++)\n sum += a[i];\n System.out.println(sum);\n int c = 0;\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n System.out.print(a[c++] + \" \");\n }\n System.out.println();\n }\n }\n private static boolean check(int[] a) {\n int[][] c = new int[n][n];\n int cc = 0;\n for (int i = 0; i < c.length; i++) {\n for (int j = 0; j < c.length; j++) {\n c[i][j] = a[cc++];\n }\n }\n int sum = 0;\n for (int i = 0; i < c.length; i++) {\n sum += c[0][i];\n }\n int s = 0;\n for (int i = 1; i < c.length; i++) {\n s = 0;\n for (int j = 0; j < c.length; j++) {\n s += c[i][j];\n }\n if (s != sum) return false;\n }\n \n for (int i = 0; i < c.length; i++) {\n s = 0;\n for (int j = 0; j < c.length; j++) {\n s += c[j][i];\n }\n if (s != sum) return false;\n }\n \n int row = 0;\n int col = 0;\n s = 0;\n while (row < n && col < n) {\n s += c[row++][col++];\n }\n if (s != sum)\n return false;\n \n row = 0;\n col = n - 1;\n s = 0;\n while (col >= 0 && row < n) {\n s += c[row++][col--];\n }\n if (s != sum) return false;\n \n return true;\n }\n public static void main(String[] args) {\n Scanner r = new Scanner(System.in);\n \n n = r.nextInt();\n int[] a = new int[n * n];\n \n for (int i = 0; i < n * n; i++)\n a[i] = r.nextInt();\n \n dfs(0, n * n, a, new int[n * n], new boolean[n * n]);\n }\n}\n", "src_uid": "7c806fb163aaf23e1eef3e6570aea436"} {"source_code": "import java.util.*;\npublic class aa {\npublic static void main(String[] args)\n{\n Scanner input = new Scanner(System.in);\n int n = input.nextInt(), m = input.nextInt();\n Point[] data = new Point[n];\n for(int i = 0; i<n; i++) data[i] = new Point(i, input.nextInt());\n Arrays.sort(data);\n for(int i = 0; i<m; i++)\n {\n input.nextInt();\n input.nextInt();\n }\n int[] out = new int[n];\n for(int i = 0; i<n; i++) out[data[i].i] = i%2;\n for(int i = 0; i<n; i++) System.out.print(out[i]+\" \");\n}\nstatic class Point implements Comparable<Point>\n{\n int i, x;\n public Point(int ii, int xx)\n {\n i = ii; x = xx;\n }\n @Override\n public int compareTo(Point o) {\n // TODO Auto-generated method stub\n return x - o.x;\n }\n}\n}\n", "src_uid": "692698d4b49ad446984f3a7a631f961d"} {"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 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 LongList allPossiblePrimeFactor = new LongList();\n for (long p : primes) {\n allPossiblePrimeFactor.add(p);\n allPossiblePrimeFactor.addAll(Factorization.factorizeNumberPrime(p - 1));\n }\n allPossiblePrimeFactor.unique();\n\n collect(allFactorOfM, m, 0);\n LongPower power = new LongPower(ILongModular.getInstance(m));\n\n long total = 1;\n for (int i = 0; i < allFactorOfM.size(); i++) {\n long g = allFactorOfM.get(i);\n if (g == m) {\n continue;\n }\n long mg = m / g;\n tmpList.clear();\n collect(tmpList, mg, 0);\n long cnt = 0;\n for (int j = tmpList.size() - 1; j >= 0; j--) {\n long t = tmpList.get(j);\n cnt += mu(t) * ((m - 1) / (t * g));\n }\n\n tmpList.clear();\n long euler = euler(mg);\n LongList primeFactors = tmpList;\n for (int j = 0; j < allPossiblePrimeFactor.size(); j++) {\n long p = allPossiblePrimeFactor.get(j);\n if (euler % p == 0) {\n primeFactors.add(p);\n }\n }\n\n long n = euler;\n for (int j = 0; j < primeFactors.size(); j++) {\n long p = primeFactors.get(j);\n while (n % p == 0 && power.pow(x, n / p) % mg == 1) {\n n /= p;\n }\n }\n\n if (cnt % n != 0) {\n throw new IllegalStateException();\n }\n total += cnt / n;\n }\n\n out.println(total);\n }\n\n public void collect(LongList list, long x, int i) {\n if (i == primes.length) {\n list.add(x);\n return;\n }\n collect(list, x, i + 1);\n while (x % primes[i] == 0) {\n x /= primes[i];\n collect(list, x, i + 1);\n }\n }\n\n }\n\n static class DigitUtils {\n private DigitUtils() {\n }\n\n public static long round(double x) {\n if (x >= 0) {\n return (long) (x + 0.5);\n } else {\n return (long) (x - 0.5);\n }\n }\n\n public static long mod(long x, long mod) {\n x %= mod;\n if (x < 0) {\n x += mod;\n }\n return x;\n }\n\n public static long mulMod(long a, long b, long mod) {\n long k = DigitUtils.round((double) a / mod * b);\n return DigitUtils.mod(a * b - k * mod, mod);\n }\n\n }\n\n static class FastOutput implements AutoCloseable, Closeable, Appendable {\n private StringBuilder cache = new StringBuilder(10 << 20);\n private final Writer os;\n\n public FastOutput append(CharSequence csq) {\n cache.append(csq);\n return this;\n }\n\n public FastOutput append(CharSequence csq, int start, int end) {\n cache.append(csq, start, end);\n return this;\n }\n\n public FastOutput(Writer os) {\n this.os = os;\n }\n\n public FastOutput(OutputStream os) {\n this(new OutputStreamWriter(os));\n }\n\n public FastOutput append(char c) {\n cache.append(c);\n return this;\n }\n\n public FastOutput println(long c) {\n cache.append(c);\n println();\n return this;\n }\n\n public FastOutput println() {\n cache.append(System.lineSeparator());\n return this;\n }\n\n public FastOutput flush() {\n try {\n os.append(cache);\n os.flush();\n cache.setLength(0);\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n return this;\n }\n\n public void close() {\n flush();\n try {\n os.close();\n } catch (IOException e) {\n throw new UncheckedIOException(e);\n }\n }\n\n public String toString() {\n return cache.toString();\n }\n\n }\n\n static class LongPower {\n final ILongModular modular;\n\n public LongPower(ILongModular modular) {\n this.modular = modular;\n }\n\n public long pow(long x, long n) {\n if (n == 0) {\n return 1;\n }\n long r = pow(x, n >> 1);\n r = modular.mul(r, r);\n if ((n & 1) == 1) {\n r = modular.mul(r, x);\n }\n return r;\n }\n\n }\n\n static class Factorization {\n public static LongList factorizeNumberPrime(long x) {\n LongList ans = new LongList();\n for (long i = 2; i * i <= x; i++) {\n if (x % i != 0) {\n continue;\n }\n ans.add(i);\n while (x % i == 0) {\n x /= i;\n }\n }\n if (x > 1) {\n ans.add(x);\n }\n return ans;\n }\n\n }\n\n static class LongHashMap {\n private int[] slot;\n private int[] next;\n private long[] keys;\n private long[] values;\n private int alloc;\n private boolean[] removed;\n private int mask;\n private int size;\n private boolean rehash;\n\n public LongHashMap(int cap, boolean rehash) {\n this.mask = (1 << (32 - Integer.numberOfLeadingZeros(cap - 1))) - 1;\n slot = new int[mask + 1];\n next = new int[cap + 1];\n keys = new long[cap + 1];\n values = new long[cap + 1];\n removed = new boolean[cap + 1];\n this.rehash = rehash;\n }\n\n private void doubleCapacity() {\n int newSize = Math.max(next.length + 10, next.length * 2);\n next = Arrays.copyOf(next, newSize);\n keys = Arrays.copyOf(keys, newSize);\n values = Arrays.copyOf(values, newSize);\n removed = Arrays.copyOf(removed, newSize);\n }\n\n public void alloc() {\n alloc++;\n if (alloc >= next.length) {\n doubleCapacity();\n }\n next[alloc] = 0;\n removed[alloc] = false;\n size++;\n }\n\n private void rehash() {\n int[] newSlots = new int[Math.max(16, slot.length * 2)];\n int newMask = newSlots.length - 1;\n for (int i = 0; i < slot.length; i++) {\n if (slot[i] == 0) {\n continue;\n }\n int head = slot[i];\n while (head != 0) {\n int n = next[head];\n int s = hash(keys[head]) & newMask;\n next[head] = newSlots[s];\n newSlots[s] = head;\n head = n;\n }\n }\n this.slot = newSlots;\n this.mask = newMask;\n }\n\n private int hash(long x) {\n int h = Long.hashCode(x);\n return h ^ (h >>> 16);\n }\n\n public void put(long x, long y) {\n put(x, y, true);\n }\n\n public void put(long x, long y, boolean cover) {\n int h = hash(x);\n int s = h & mask;\n if (slot[s] == 0) {\n alloc();\n slot[s] = alloc;\n keys[alloc] = x;\n values[alloc] = y;\n } else {\n int index = findIndexOrLastEntry(s, x);\n if (keys[index] != x) {\n alloc();\n next[index] = alloc;\n keys[alloc] = x;\n values[alloc] = y;\n } else if (cover) {\n values[index] = y;\n }\n }\n if (rehash && size >= slot.length) {\n rehash();\n }\n }\n\n public long getOrDefault(long x, long def) {\n int h = hash(x);\n int s = h & mask;\n if (slot[s] == 0) {\n return def;\n }\n int index = findIndexOrLastEntry(s, x);\n return keys[index] == x ? values[index] : def;\n }\n\n public long get(long x) {\n return getOrDefault(x, 0);\n }\n\n private int findIndexOrLastEntry(int s, long x) {\n int iter = slot[s];\n while (keys[iter] != x) {\n if (next[iter] != 0) {\n iter = next[iter];\n } else {\n return iter;\n }\n }\n return iter;\n }\n\n public LongEntryIterator iterator() {\n return new LongEntryIterator() {\n int index = 1;\n int readIndex = -1;\n\n\n public boolean hasNext() {\n while (index <= alloc && removed[index]) {\n index++;\n }\n return index <= alloc;\n }\n\n\n public long getEntryKey() {\n return keys[readIndex];\n }\n\n\n public long getEntryValue() {\n return values[readIndex];\n }\n\n\n public void next() {\n if (!hasNext()) {\n throw new IllegalStateException();\n }\n readIndex = index;\n index++;\n }\n };\n }\n\n public String toString() {\n LongEntryIterator iterator = iterator();\n StringBuilder builder = new StringBuilder(\"{\");\n while (iterator.hasNext()) {\n iterator.next();\n builder.append(iterator.getEntryKey()).append(\"->\").append(iterator.getEntryValue()).append(',');\n }\n if (builder.charAt(builder.length() - 1) == ',') {\n builder.setLength(builder.length() - 1);\n }\n builder.append('}');\n return builder.toString();\n }\n\n }\n\n static class FastInput {\n private final InputStream is;\n private byte[] buf = new byte[1 << 13];\n private int bufLen;\n private int bufOffset;\n private int next;\n\n public FastInput(InputStream is) {\n this.is = is;\n }\n\n private int read() {\n while (bufLen == bufOffset) {\n bufOffset = 0;\n try {\n bufLen = is.read(buf);\n } catch (IOException e) {\n bufLen = -1;\n }\n if (bufLen == -1) {\n return -1;\n }\n }\n return buf[bufOffset++];\n }\n\n public void skipBlank() {\n while (next >= 0 && next <= 32) {\n next = read();\n }\n }\n\n public long readLong() {\n int sign = 1;\n\n skipBlank();\n if (next == '+' || next == '-') {\n sign = next == '+' ? 1 : -1;\n next = read();\n }\n\n long val = 0;\n if (sign == 1) {\n while (next >= '0' && next <= '9') {\n val = val * 10 + next - '0';\n next = read();\n }\n } else {\n while (next >= '0' && next <= '9') {\n val = val * 10 - next + '0';\n next = read();\n }\n }\n\n return val;\n }\n\n }\n\n static interface LongEntryIterator {\n boolean hasNext();\n\n void next();\n\n long getEntryKey();\n\n long getEntryValue();\n\n }\n\n static class LongModular implements ILongModular {\n final long m;\n\n public LongModular(long m) {\n this.m = m;\n }\n\n public long mul(long a, long b) {\n return b == 0 ? 0 : ((mul(a, b >> 1) << 1) % m + a * (b & 1)) % m;\n }\n\n }\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 void sort() {\n if (size <= 1) {\n return;\n }\n Randomized.shuffle(data, 0, size);\n Arrays.sort(data, 0, size);\n }\n\n public void unique() {\n if (size <= 1) {\n return;\n }\n\n sort();\n int wpos = 1;\n for (int i = 1; i < size; i++) {\n if (data[i] != data[wpos - 1]) {\n data[wpos++] = data[i];\n }\n }\n size = wpos;\n }\n\n public int size() {\n return size;\n }\n\n public long[] toArray() {\n return Arrays.copyOf(data, size);\n }\n\n public void clear() {\n size = 0;\n }\n\n public String toString() {\n return Arrays.toString(toArray());\n }\n\n public boolean equals(Object obj) {\n if (!(obj instanceof LongList)) {\n return false;\n }\n LongList other = (LongList) obj;\n return SequenceUtils.equal(data, 0, size - 1, other.data, 0, other.size - 1);\n }\n\n public int hashCode() {\n int h = 1;\n for (int i = 0; i < size; i++) {\n h = h * 31 + Long.hashCode(data[i]);\n }\n return h;\n }\n\n public LongList clone() {\n LongList ans = new LongList();\n ans.addAll(this);\n return ans;\n }\n\n }\n\n static 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 static class SequenceUtils {\n public static boolean equal(long[] a, int al, int ar, long[] b, int bl, int br) {\n if ((ar - al) != (br - bl)) {\n return false;\n }\n for (int i = al, j = bl; i <= ar; i++, j++) {\n if (a[i] != b[j]) {\n return false;\n }\n }\n return true;\n }\n\n }\n\n static class Randomized {\n private static Random random = new Random(0);\n\n public static void shuffle(long[] data, int from, int to) {\n to--;\n for (int i = from; i <= to; i++) {\n int s = nextInt(i, to);\n long tmp = data[i];\n data[i] = data[s];\n data[s] = tmp;\n }\n }\n\n public static int nextInt(int l, int r) {\n return random.nextInt(r - l + 1) + l;\n }\n\n }\n}\n\n", "src_uid": "c2dd6de750812d6213c770b3587d8fcb"} {"source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Memory_and_Scores {\n\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tBufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(f.readLine());\n\n\t\tint a = Integer.parseInt(st.nextToken());\n\t\tint b = Integer.parseInt(st.nextToken());\n\t\tint k = Integer.parseInt(st.nextToken());\n\t\tint t = Integer.parseInt(st.nextToken());\n\n\t\tf.close();\n\n\t\tlong[][] dp = new long[2][k * t * 4 + 401];\n\t\tdp[0][k * t * 2 + 200] = 1;\n\n\t\tlong mod = 1000000007;\n\n\t\tfor (int i = 0; i < 2 * t; i++) {\n\n\t\t\tint cur = i % 2;\n\t\t\tint nxt = (i + 1) % 2;\n\n\t\t\tArrays.fill(dp[nxt], 0);\n\n\t\t\tfor (int j = 0; j <= k * t * 4 + 400; j++) {\n\n\t\t\t\tif (dp[cur][j] == 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tdp[nxt][j + k + 1] -= dp[cur][j];\n\t\t\t\tif (dp[nxt][j + k + 1] < 0) {\n\t\t\t\t\tdp[nxt][j + k + 1] += mod;\n\t\t\t\t}\n\t\t\t\tif (dp[nxt][j + k + 1] >= mod) {\n\t\t\t\t\tdp[nxt][j + k + 1] -= mod;\n\t\t\t\t}\n\n\t\t\t\tdp[nxt][j - k] += dp[cur][j];\n\t\t\t\tif (dp[nxt][j - k] >= mod) {\n\t\t\t\t\tdp[nxt][j - k] -= mod;\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t\tfor (int j = 1; j <= k * t * 4 + 400; j++) {\n\t\t\t\tdp[nxt][j] += dp[nxt][j - 1];\n\t\t\t\tif (dp[nxt][j] >= mod) {\n\t\t\t\t\tdp[nxt][j] -= mod;\n\t\t\t\t}\n\t\t\t}\n\n\t\t}\n\n\t\tint ans = 0;\n\t\tfor (int i = b - a + k * t * 2 + 201; i <= k * t * 4 + 400; i++) {\n\t\t\tans += dp[0][i];\n\t\t\tif (ans >= mod) {\n\t\t\t\tans -= mod;\n\t\t\t}\n\t\t}\n\n\t\tSystem.out.println(ans);\n\n\t}\n\n}\n", "src_uid": "8b8327512a318a5b5afd531ff7223bd0"} {"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[] Y = new int[3];\n int[] M = new int[3];\n int[] cost = new int[3];\n for (int i = 0; i < 3; i++) {\n Y[i] = in.nextInt();\n }\n for (int i = 0; i < 3; i++) {\n M[i] = in.nextInt();\n }\n for (int i = 0; i < 3; i++) {\n cost[i] = in.nextInt();\n }\n int left = 0;\n int right = Integer.MAX_VALUE;\n int res = 0;\n while (right >= left) {\n int mid = (left + right) >> 1;\n if (check(mid, Y, M, cost)) {\n res = mid;\n right = mid - 1;\n } else {\n left = mid + 1;\n }\n }\n out.println(res);\n }\n\n boolean check(int value, int[] Y, int[] M, int[] cost) {\n for (int defensive = 0; defensive <= value / cost[2]; defensive++) {\n int remain = value - defensive * cost[2];\n for (int attack = 0; attack <= remain / cost[1]; ++attack) {\n int remain2 = remain - attack * cost[1];\n int[] nY = new int[3];\n nY[0] = Y[0] + remain2 / cost[0];\n nY[1] = Y[1] + attack;\n nY[2] = Y[2] + defensive;\n if (canWin(nY, M)) return true;\n }\n }\n return false;\n }\n\n boolean canWin(int[] y, int[] m) {\n int yPerSecond = Math.max(0, m[1] - y[2]);\n int mPerSecond = Math.max(0, y[1] - m[2]);\n if (mPerSecond == 0) return false;\n if (yPerSecond == 0) return true;\n return (y[0] + yPerSecond - 1) / yPerSecond > (m[0] + mPerSecond - 1) / mPerSecond;\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", "src_uid": "bf8a133154745e64a547de6f31ddc884"} {"source_code": "import java.util.HashMap;\nimport java.util.Scanner;\n\npublic class Leapyear {\n static HashMap<String,Integer> map = new HashMap(); \n static int sum2 (int x){\n if (x<6){\n return x+2;\n }\n else if(x == 6){\n return 1;\n }\n return 2;\n }\n static int sum3(int x){\n if (x<5){\n return x+3;\n }else if(x==5){\n return 1;\n }\n else if(x == 6){\n return 2;\n }\n return 3;\n }\n \n public static void main(String[] args) {\n map.put(\"sunday\",1);\n map.put(\"monday\",2);\n map.put( \"tuesday\",3);\n map.put( \"wednesday\",4);\n map.put(\"thursday\",5);\n map.put(\"friday\",6);\n map.put( \"saturday\",7);\n \n \n Scanner in = new Scanner(System.in);\n String day1 = in.next().trim();\n String day2 = in.next().trim();\n \n if(day1.equals(day2)){\n System.out.println(\"YES\");\n }else if(sum2(map.get(day1))==map.get(day2)||sum3(map.get(day1))==map.get(day2)){\n System.out.println(\"YES\");\n }\n else{\n System.out.println(\"NO\");\n }\n\n\n }\n\n}", "src_uid": "2a75f68a7374b90b80bb362c6ead9a35"} {"source_code": "import java.io.StreamTokenizer;\nimport java.io.InputStreamReader;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Reader;\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\tTokenizerReader in = new TokenizerReader(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(@SuppressWarnings(\"UnusedParameters\") int testNumber, TokenizerReader in, PrintWriter out) {\n int n = in.nextInt(), m = in.nextInt(), min = in.nextInt(), max = in.nextInt();\n out.println(ok(Input.intArray(in, m), n, min, max) ? \"Correct\" : \"Incorrect\");\n }\n\n private boolean ok(int[] t, int n, int min, int max) {\n boolean haveMin = false, haveMax = false;\n for (int i : t) {\n if (i < min) return false;\n if (i > max) return false;\n if (i == min) haveMin = true;\n if (i == max) haveMax = true;\n }\n if (t.length < n-1) return true;\n if (!haveMin && !haveMax && min != max) return false;\n return true;\n }\n}\n\nclass TokenizerReader extends StreamTokenizer {\n public TokenizerReader(InputStream in) {\n super(new BufferedReader(new InputStreamReader(in)));\n defaultConfig();\n }\n\n public String nextString() {\n try {\n nextToken();\n } catch (IOException e) {\n throw new RuntimeException(\"nextString: exception in line \" + lineno(), e);\n }\n return sval;\n }\n\n public int nextInt() {\n return Integer.parseInt(nextString());\n }\n\n public void defaultConfig() {\n resetSyntax();\n wordChars(33, 126);\n whitespaceChars(0, ' ');\n }\n\n}\n\nabstract class Input {\n public static int[] intArray(TokenizerReader in, int size) {\n int[] res = new int[size];\n for (int i = 0; i < size; ++i)\n res[i] = in.nextInt();\n return res;\n }\n\n}\n\n", "src_uid": "99f9cdc85010bd89434f39b78f15b65e"} {"source_code": "/**\n * Created by IntelliJ IDEA.\n * User: aircube\n * Date: 28.02.11\n * Time: 20:43\n * To change this template use File | Settings | File Templates.\n */\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class TaskD {\n BufferedReader br;\n PrintWriter out;\n StringTokenizer st;\n\n public static void main(String[] args) throws IOException {\n new TaskD().run();\n }\n\n void run() throws IOException {\n br = new BufferedReader(new InputStreamReader(System.in));\n st = null;\n out = new PrintWriter(System.out);\n solve();\n br.close();\n out.close();\n }\n\n\n int a[][] ;\n int dm[][];\n void solve() throws IOException {\n a = new int[15][];\n a[0] = new int[] {1, 2, 3};\n a[1] = new int[] {4, 5, 6, 7};\n a[2] = new int[] {8, 9, 10, 11, 12};\n a[3] = new int[] {13, 14, 15, 16};\n a[4] = new int[] {17, 18, 19};\n a[5] = new int[] {8, 13, 17};\n a[6] = new int[] {4, 9, 14, 18};\n a[7] = new int[] {1, 5, 10, 15, 19};\n a[8] = new int[] {2, 6, 11, 16};\n a[9] = new int[] {3, 7, 12};\n a[10] = new int[] {1, 4, 8};\n a[11] = new int[] {2, 5, 9, 13};\n a[12] = new int[] {3, 6, 10, 14, 17};\n a[13] = new int[] {7, 11, 15, 18};\n a[14] = new int[] {12, 16, 19};\n\n dm = new int[1 << 19][2];\n for (int i = 0; i < dm.length; ++i)\n dm[i][0] = dm[i][1] = -1;\n\n for (int i = 0; i < a.length; ++i)\n for (int j = 0; j < a[i].length; ++j)\n a[i][j] -- ;\n\n int mask = 0;\n for (int t = 0; t < 19; ++t) {\n String str = nextToken();\n if (str.compareTo(\"O\") == 0) mask |= (1 << t) ;;\n }\n int res = brute(mask, 0);\n out.print(res == 1 ? \"Karlsson\" : \"Lillebror\");\n\n }\n int brute(int mask, int turn) {\n if (mask == 0) {\n return turn;\n }\n if (dm[mask][turn] != -1) return dm[mask][turn];\n\n for(int v = 0; v < a.length; ++v) {\n\n for (int i = 0; i < a[v].length; ++i) {\n for(int j = i; j < a[v].length; ++j) {\n boolean ok = true;\n for (int u = i; ok && u <= j; ++u) {\n if ((mask & (1 << a[v][u])) == 0) ok = false;\n }\n if (ok) {\n for (int I = i; I <= j; ++I)\n for(int J = I; J <= j; ++J) {\n int cm = 0;\n for (int k = I; k <= J; ++k) {\n cm |= (1 << a[v][k]);\n }\n int d = brute(mask ^ cm, turn ^ 1);\n if (turn == 0 && d == 1) return dm[mask][turn] = 1;\n if (turn == 1 && d == 0) return dm[mask][turn] = 0;\n }\n }\n }\n }\n }\n\n return dm[mask][turn] = turn;\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n String nextToken() throws IOException {\n while (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(br.readLine());\n }\n return st.nextToken();\n }\n}", "src_uid": "eaa022cc7846c983a826900dc6dd919f"} {"source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\n\n\npublic class SnowBall {\n\n\tpublic static void main(String[] args) throws IOException{\n\t\tString buff;\n\t\tString[] line;\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tBufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\tbuff = br.readLine();\n\t\tline = buff.split(\" \");\n\t\tint w = Integer.parseInt(line[0]);\n\t\tint h = Integer.parseInt(line[1]);\n\t\tbuff = br.readLine();\n\t\tline = buff.split(\" \");\n\t\tint u1 = Integer.parseInt(line[0]);\n\t\tint d1 = Integer.parseInt(line[1]);\n\t\tbuff = br.readLine();\n\t\tline = buff.split(\" \");\n\t\tint u2 = Integer.parseInt(line[0]);\n\t\tint d2 = Integer.parseInt(line[1]);\n\t\t\n\t\tint finalWeight = calculateWeight(w, h, u1, d1, u2, d2);\n\t\tbw.write(finalWeight + \"\");\n\t\tbr.close();\n\t\tbw.close();\n\t}\n\n\tprivate static int calculateWeight(int w, int h, int u1, int d1, int u2,\n\t\t\tint d2) {\n\t\t\n\t\twhile(h > 0){\n\t\t\tw += h;\n\t\t\tif(d1 == h){\n\t\t\t\tw = Integer.max(w - u1, 0);\n\t\t\t}\n\t\t\tif(d2 == h){\n\t\t\t\tw = Integer.max(w - u2, 0);\n\t\t\t}\n\t\t\th--;\n\t\t}\n\t\treturn w;\n\t}\n}\n", "src_uid": "084a12eb3a708b43b880734f3ee51374"} {"source_code": "import java.util.Scanner;\n\npublic class A {\n public static void main (String arg[]){\n Scanner sc = new Scanner(System.in);\n int y = sc.nextInt();\n int co = 0;\n for(int i =1;i<y/2+1;++i){\n int x = i;\n int xx= y-i;\n if(x%xx==0||xx%x==0){\n co++;\n }\n }\n System.out.println(co);\n }\n}\n", "src_uid": "89f6c1659e5addbf909eddedb785d894"} {"source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Main\n{\n\tstatic class FastReader\n {\n BufferedReader br;\n StringTokenizer st;\n\n public FastReader()\n {\n br = new BufferedReader(new\n InputStreamReader(System.in));\n }\n\n String next()\n {\n while (st == null || !st.hasMoreElements())\n {\n try\n {\n st = new StringTokenizer(br.readLine());\n }\n catch (IOException e)\n {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt()\n {\n return Integer.parseInt(next());\n }\n\n long nextLong()\n {\n return Long.parseLong(next());\n }\n\n double nextDouble()\n {\n return Double.parseDouble(next());\n }\n\n String nextLine()\n {\n String str = \"\";\n try\n {\n str = br.readLine();\n }\n catch (IOException e)\n {\n e.printStackTrace();\n }\n return str;\n }\n }\n\n\tpublic static void main (String[] args)\n\t{\n\t\tFastReader reader = new FastReader();\n\t\tint desLen = reader.nextInt();\n\t\tint desBrd = reader.nextInt();\n\t\tint curLen = reader.nextInt();\n\t\tint curBrd = reader.nextInt();\n\t\tint totalNs = reader.nextInt();\n\n\t\tInteger[] array = new Integer[totalNs];\n\t\tfor (int i=0; i<totalNs; i++)\n\t\t\tarray[i] = reader.nextInt();\n\n\t\tArrays.sort (array, new InverseSort());\n\t\tlong[][] dp = new long[41][100003];\n\t\tdp[0][curBrd] = curLen;\n\t\tdp[0][curLen] = curBrd;\n\n\t\tint i=0;\n\t\tfor (i=0; i<41 && i<totalNs; i++)\n\t\t{\n\t\t\tfor (int j=1; j<100003; j++)\n\t\t\t{\n\t\t\t\tif ((j >= desBrd && dp[i][j] >= desLen) || (dp[i][j] >= desBrd && j >= desLen))\n\t\t\t\t{\n\t\t\t\t\tSystem.out.println (i);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tlong bre1 = (long)j*array[i];\n\t\t\t\tlong len1 = dp[i][j];\n\n\t\t\t\tif (bre1 >= 100003)\n\t\t\t\t\t\tdp[i+1][100002] = Math.max (dp[i][j], dp[i+1][100002]);\n\t\t\t\telse\n\t\t\t\t\tdp[i+1][(int)bre1] = Math.max (dp[i+1][(int)bre1], dp[i][j]);\n\n\t\t\t\tdp[i+1][j] = Math.max (dp[i][j]*array[i], dp[i+1][j]);\n\t\t\t}\n\t\t}\n\t\tfor (int j=1; j<100003; j++)\n\t\t{\n\t\t\tif ((j >= desBrd && dp[i][j] >= desLen) || (dp[i][j] >= desBrd && j >= desLen))\n\t\t\t{\n\t\t\t\tSystem.out.println (i);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tSystem.out.println (-1);\n\t}\n}\n\nclass InverseSort implements Comparator<Integer>\n{\n\tpublic int compare (Integer a, Integer b)\n\t{\n\t\treturn (b-a);\n\t}\n}\n", "src_uid": "18cb436618b2b85c3f5dc348c80882d5"} {"source_code": "\n\nimport java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class JavaApplication154 {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n \n int arr[] = new int[3];\n arr[0] = sc.nextInt();\n arr[1] = sc.nextInt();\n arr[2] = sc.nextInt();\n \n Arrays.sort(arr);\n if(arr[2] - arr[1] - arr[0] < 0){\n System.out.println(0);\n }else{\n System.out.println((arr[2]-arr[1]-arr[0])+1);\n }\n \n }\n \n}\n", "src_uid": "3dc56bc08606a39dd9ca40a43c452f09"} {"source_code": "\nimport java.util.*;\n\n/**\n *\n * @author alexandru\n */\npublic class Main {\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 String s = sc.next();\n System.out.print(s.charAt(0));\n char c = s.charAt(s.length()-1);\n s = s.substring(1, s.length()-1);\n \n s = s.replaceAll(\"dot\", \".\");\n s = s.replaceFirst(\"at\", \"@\");\n System.out.print(s);\n System.out.println(c);\n \n\n }\n \n}\n", "src_uid": "a11c9679d8e2dca51be17d466202df6e"} {"source_code": "import java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.OutputStreamWriter;\nimport java.io.IOException;\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.util.stream.Stream;\n\n\n/**\n *\n * @author Pradyumn Agrawal coderbond007\n */\npublic class Codeforces{\n public static InputStream inputStream = System.in;\n public static FastReader in = new FastReader(inputStream);\n public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\n public static void main(String[] args)throws java.lang.Exception\n {\n new Codeforces().run();\n out.close();\n }\n void run() throws java.lang.Exception\n {\n String s1 = ns();\n String s2 = ns();\n if(s1.equals(s2)){\n out.println(s1);\n } else {\n out.println(1);\n }\n }\n private static int ni(){ \n return in.nextInt();\n }\n private static long nl(){\n return in.nextLong();\n }\n private static String ns(){\n return in.nextString();\n }\n private static char nc(){\n return in.nextCharacter();\n }\n private static double nd(){\n return in.nextDouble();\n }\n\n private static char[] ns(int n)\n {\n char[] a = new char[n];\n for(int i=0;i<n;i++) a[i] = nc();\n return a;\n }\n\n private static 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 static 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 static long[] nal(int n)\n {\n long[] a = new long[n];\n for(int i=0;i<n;i++) a[i] = nl();\n return a;\n }\n //private void tr(Object... o) { if(o.length() > 0)System.out.println(Arrays.deepToString(o)); }\n}\n\nclass FastReader{\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 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}", "src_uid": "9c5b6d8a20414d160069010b2965b896"} {"source_code": "import java.util.*;\n\npublic class OddsAndEnds {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\t\n\t\tint n = sc.nextInt();\n\t\tint[] ar = new int[n];\n\t\t\n\t\tboolean condition = false;\n\t\t\n\t\tfor(int i=0; i<n; i++) {\n\t\t\tar[i] = sc.nextInt();\n\t\t}\n\t\t\n\t\t\n\t\tif(n%2 == 0 || ar[0]%2 == 0 || ar[n-1]%2 == 0) {\n\t\t\tcondition = false;\n\t\t}else {\n\t\t\tcondition = true;\n\t\t}\n\t\t\n\t\tif(condition) {\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", "src_uid": "2b8c2deb5d7e49e8e3ededabfd4427db"} {"source_code": "import java.util.Scanner;\n\npublic class Blackjack {\n \n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n if(n <= 10)\n System.out.println(0);\n else if(n >= 11 && n <= 19 || n == 21)\n System.out.println(4);\n else if(n == 20)\n System.out.println(15);\n else\n System.out.println(0);\n }\n\n}", "src_uid": "5802f52caff6015f21b80872274ab16c"} {"source_code": "/* package codechef; // don't place package name! */\n\n\nimport java.math.BigInteger;\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\n/* Name of the class has to be \"Main\" only if the class is public. */\npublic class Solution\n{\n // Complete the maximumSum function below.\n public 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\n static boolean prime(long a){\n if(a==2||a==3)\n return true;\n if((a-1)%6==0)\n return true;\n if((a+1)%6==0)\n return true;\n return false;\n }\n public static long gcd(long a,long b){\n if(b==0)\n return a;\n long r=a%b;\n return gcd(b,r);\n }\n\n static long lcm(long a, long b)\n {\n return (a*b)/gcd(a, b);\n }\n\n\n public class ListNode {\n int val;\n ListNode next;\n ListNode() {}\n ListNode(int val) { this.val = val; }\n ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n }\n\n public class TreeNode {\n int val;\n TreeNode left;\n TreeNode right;\n TreeNode() {}\n TreeNode(int val) { this.val = val; }\n TreeNode(int val, TreeNode left, TreeNode right) {\n this.val = val;\n this.left = left;\n this.right = right;\n }\n }\n\n class Node {\n public int val;\n public List<Node> children;\n\n public Node() {}\n\n public Node(int _val) {\n val = _val;\n }\n\n public Node(int _val, List<Node> _children) {\n val = _val;\n children = _children;\n }\n }\n\n\n // private static final FastReader scanner = new FastReader();\n public static void main(String[] args) throws IOException {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader scanner = new InputReader(inputStream);\n PrintWriter w = new PrintWriter(outputStream);\n long a=scanner.nextInt(),b=scanner.nextInt();\n long c=a+b;\n long a1=0,b1=0,c1=0;\n while (a>0){\n if(a%10!=0){\n a1=a1*10+(a%10);\n }\n a/=10;\n }\n while (b>0){\n if(b%10!=0){\n b1=b1*10+(b%10);\n }\n b/=10;\n }\n while (c>0){\n if(c%10!=0){\n c1=c1*10+(c%10);\n }\n c/=10;\n }\n a1=Integer.parseInt(new StringBuilder(String.valueOf(a1)).reverse().toString());\n b1=Integer.parseInt(new StringBuilder(String.valueOf(b1)).reverse().toString());\n c1=Integer.parseInt(new StringBuilder(String.valueOf(c1)).reverse().toString());\n if(a1+b1==c1)\n w.println(\"YES\");\n else\n w.println(\"NO\");\n w.close();\n }\n}", "src_uid": "ac6971f4feea0662d82da8e0862031ad"} {"source_code": "import static java.lang.Math.min;\nimport static java.util.Arrays.fill;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class C {\n\n\tstatic void solve() throws IOException {\n\t\tint n = nextInt();\n\t\tint v = nextInt();\n\t\tint edges = nextInt();\n\t\tboolean[][] can = new boolean[n][n];\n\t\tint[] a = new int[n];\n\t\tint[] b = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = nextInt();\n\t\t}\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tb[i] = nextInt();\n\t\t}\n\t\tfor (int i = 0; i < edges; i++) {\n\t\t\tint u = nextInt() - 1, vv = nextInt() - 1;\n\t\t\tcan[u][vv] = true;\n\t\t\tcan[vv][u] = true;\n\t\t}\n\t\t// boolean[][] floyd = new boolean[n][];\n\t\t// for (int i = 0; i < n; i++) {\n\t\t// floyd[i] = can[i].clone();\n\t\t// }\n\t\t// for (int k = 0; k < n; k++) {\n\t\t// for (int i = 0; i < n; i++) {\n\t\t// if (!floyd[i][k]) {\n\t\t// continue;\n\t\t// }\n\t\t// for (int j = 0; j < n; j++) {\n\t\t// floyd[i][j] |= floyd[k][j];\n\t\t// }\n\t\t// }\n\t\t// }\n\t\tint[] parent = new int[n];\n\t\tfill(parent, -1);\n\t\tList<Integer> from = new ArrayList<>();\n\t\tList<Integer> to = new ArrayList<>();\n\t\tList<Integer> amount = new ArrayList<>();\n\t\tboolean good = true;\n\t\tfor (int start = 0; start < n && good; start++) {\n\t\t\tif (parent[start] != -1) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tQueue<Integer> queue = new ArrayDeque<>();\n\t\t\tqueue.add(start);\n\n\t\t\tparent[start] = start;\n\t\t\tint[] out = new int[n];\n\t\t\t\n\t\t\twhile (!queue.isEmpty()) {\n\t\t\t\tint u = queue.poll();\n\t\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\t\tif (!can[u][j]) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif (parent[j] == -1) {\n\t\t\t\t\t\tparent[j] = u;\n\t\t\t\t\t\tqueue.add(j);\n\t\t\t\t\t\t++out[u];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tlong diff = 0;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (parent[i] >= 0) {\n\t\t\t\t\tdiff += a[i] - b[i];\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif (diff != 0) {\n\t\t\t\tgood = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tqueue.clear();\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (out[i] == 0 && parent[i] >= 0) {\n\t\t\t\t\tqueue.add(i);\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\twhile (!queue.isEmpty()) {\n\t\t\t\tint leaf = queue.poll();\n\t\t\t\tif (--out[parent[leaf]] == 0) {\n\t\t\t\t\tqueue.add(parent[leaf]);\n\t\t\t\t}\n\t\t\t\tif (a[leaf] == b[leaf]) {\n\t\t\t\t\tparent[leaf] = -2;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tint[] curParent = new int[n];\n\t\t\t\tQueue<Integer> curQueue = new ArrayDeque<>();\n\t\t\t\tfill(curParent, -1);\n\t\t\t\t\n\t\t\t\tcurQueue.add(leaf);\n\t\t\t\tint[] curOut = new int[n];\n\t\t\t\tcurParent[leaf] = leaf;\n\t\t\t\twhile (!curQueue.isEmpty()) {\n\t\t\t\t\tint u = curQueue.poll();\n\t\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\t\tif (!can[u][i]) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (parent[i] < 0 || curParent[i] >= 0) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t++curOut[u];\n\t\t\t\t\t\tcurParent[i] = u;\n\t\t\t\t\t\tcurQueue.add(i);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\tif (curOut[i] == 0 && curParent[i] >= 0) {\n\t\t\t\t\t\tcurQueue.add(i);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\twhile (!curQueue.isEmpty() && a[leaf] != b[leaf]) {\n\t\t\t\t\tint x = curQueue.poll();\n\t\t\t\t\tint par = curParent[x];\n\t\t\t\t\t\n\t\t\t\t\tif (a[leaf] < b[leaf]) {\n\t\t\t\t\t\tint flow = min(v - a[par], a[x]);\n\t\t\t\t\t\tif (par == leaf) {\n\t\t\t\t\t\t\tflow = min(b[leaf] - a[leaf], flow);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfrom.add(x);\n\t\t\t\t\t\tto.add(par);\n\t\t\t\t\t\tamount.add(flow);\n\t\t\t\t\t\ta[x] -= flow;\n\t\t\t\t\t\ta[par] += flow;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tint flow = min(v - a[x], a[par]);\n\t\t\t\t\t\tif (par == leaf) {\n\t\t\t\t\t\t\tflow = min(flow, a[leaf] - b[leaf]);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfrom.add(par);\n\t\t\t\t\t\tto.add(x);\n\t\t\t\t\t\tamount.add(flow);\n\t\t\t\t\t\ta[par] -= flow;\n\t\t\t\t\t\ta[x] += flow;\n\t\t\t\t\t}\n\t\t\t\t\tif (--curOut[par] == 0) {\n\t\t\t\t\t\tcurQueue.add(par);\n\t\t\t\t\t}\n\t\t\t\t}\n//\t\t\t\tSystem.err.println(a[leaf]+\"=\"+b[leaf]);\n\t\t\t\tparent[leaf] = -2;\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (parent[i] >= 0) {\n\t\t\t\t\tparent[i] = -2;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n//\t\tSystem.err.println(Arrays.toString(a));\n//\t\tSystem.err.println(Arrays.toString(b));\n\t\tif (!good) {\n\t\t\tout.println(\"NO\");\n\t\t} else {\n\t\t\tout.println(from.size());\n\t\t\tfor (int i = 0; i < from.size(); i++) {\n\t\t\t\tout.println((from.get(i)+1)+\" \"+(to.get(i)+1)+\" \"+amount.get(i));\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic BufferedReader br;\n\tstatic StringTokenizer st;\n\tstatic PrintWriter out;\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tInputStream input = System.in;\n\t\tPrintStream output = System.out;\n\t\tFile file = new File(\"c.in\");\n\t\tif (file.exists() && file.canRead()) {\n\t\t\tinput = new FileInputStream(file);\n\t\t}\n\t\tbr = new BufferedReader(new InputStreamReader(input));\n\t\tout = new PrintWriter(output);\n\t\tsolve();\n\t\tout.close();\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\n\tstatic int nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\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", "src_uid": "0939354d9bad8301efb79a1a934ded30"} {"source_code": "import java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n/**\n * CodeForces : 338\n * \n * @author vinaysaini E. Hexagons\n */\npublic class cf338e {\n\n\tstatic int dx[] = { 1, -1, -2, -1, 1, 2 };\n\tstatic int dy[] = { 2, 2, 0, -2, -2, 0 };\n\n\tpublic static void main(String[] args) {\n\t\tlong x = 0, y = 0;\n\n\t\tlong n = in.nextLong();\n\t\tlong ringNumber = getRing(n);\n\t\tlong stepsUpTo = 3 * ringNumber * ringNumber + 3 * ringNumber;\n\t\tx = 2 * ringNumber;\n\t\tlong remainingSteps = n - stepsUpTo;\n\t\tif (remainingSteps > 0) {\n\t\t\tx = x + dx[0];\n\t\t\ty = y + dy[0];\n\t\t\tremainingSteps--;\n\t\t}\n\t\tif (remainingSteps >= ringNumber) {\n\t\t\tx += dx[1] * ringNumber;\n\t\t\ty += dy[1] * ringNumber;\n\t\t\tremainingSteps -= ringNumber;\n\t\t} else {\n\t\t\tx += dx[1] * remainingSteps;\n\t\t\ty += dy[1] * remainingSteps;\n\t\t\tremainingSteps -= remainingSteps;\n\t\t}\n\t\tif (remainingSteps >= ringNumber+1) {\n\t\t\tx += dx[2] * (ringNumber+1);\n\t\t\ty += dy[2] * (ringNumber+1);\n\t\t\tremainingSteps -= ringNumber+1;\n\t\t} else {\n\t\t\tx += dx[2] * remainingSteps;\n\t\t\ty += dy[2] * remainingSteps;\n\t\t\tremainingSteps -= remainingSteps;\n\t\t}\n\t\tif (remainingSteps >= ringNumber+1) {\n\t\t\tx += dx[3] * (ringNumber+1);\n\t\t\ty += dy[3] * (ringNumber+1);\n\t\t\tremainingSteps -= ringNumber+1;\n\t\t} else {\n\t\t\tx += dx[3] * remainingSteps;\n\t\t\ty += dy[3] * remainingSteps;\n\t\t\tremainingSteps -= remainingSteps;\n\t\t}\n\t\tif (remainingSteps >= ringNumber+1) {\n\t\t\tx += dx[4] * (ringNumber+1);\n\t\t\ty += dy[4] * (ringNumber+1);\n\t\t\tremainingSteps -= ringNumber+1;\n\t\t} else {\n\t\t\tx += dx[4] * remainingSteps;\n\t\t\ty += dy[4] * remainingSteps;\n\t\t\tremainingSteps -= remainingSteps;\n\t\t}\n\t\tif (remainingSteps >= ringNumber+1) {\n\t\t\tx += dx[5] * (ringNumber+1);\n\t\t\ty += dy[5] * (ringNumber+1);\n\t\t\tremainingSteps -= ringNumber+1;\n\t\t} else {\n\t\t\tx += dx[5] * remainingSteps;\n\t\t\ty += dy[5] * remainingSteps;\n\t\t\tremainingSteps -= remainingSteps;\n\t\t}\n\t\tif (remainingSteps >= ringNumber) {\n\t\t\tx += dx[0] * ringNumber;\n\t\t\ty += dy[0] * ringNumber;\n\t\t\tremainingSteps -= ringNumber;\n\t\t} else {\n\t\t\tx += dx[0] * remainingSteps;\n\t\t\ty += dy[0] * remainingSteps;\n\t\t\tremainingSteps -= remainingSteps;\n\t\t}\n\n\t\tout.println(x + \" \" + y);\n\t\tout.close();\n\t}\n\n\tstatic long getRing(long n) {\n\t\tlong l = 0;\n\t\tlong r = (long) 1e9;\n\t\twhile (l < r) {\n\t\t\tlong m = (l + r) / 2;\n\t\t\tlong sum = 3 * m * m + 3 * m;\n\t\t\tif (n < sum) {\n\t\t\t\tr = m;\n\t\t\t} else\n\t\t\t\tl = m + 1;\n\t\t}\n\t\treturn l - 1;\n\t}\n\n\tpublic static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n\tpublic static FastScanner in = new FastScanner();\n\n\tpublic static class FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\n\t\tString next() {\n\t\t\twhile (st == null || !st.hasMoreElements()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tint nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tString nextLine() {\n\t\t\tString str = \"\";\n\t\t\ttry {\n\t\t\t\tstr = br.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\treturn str;\n\t\t}\n\t} // --fast i/o ends here----//\n\n}\n", "src_uid": "a4b6a570f5e63462b68447713924b465"} {"source_code": "import java.io.*;\nimport java.util.*;\n\n\npublic class A {\n private static class Solver {\n boolean ok(String s) {\n if(s.charAt(0) == '0') return s.length() == 1;\n if(s.length() >= 8) return false;\n return Integer.parseInt(s) <= 1000000;\n }\n \n public void run() throws IOException {\n int res = -1;\n final String s = IOFast.next();\n for(int i = 1; i < s.length(); i++)\n for(int j = i + 1; j < s.length(); j++) {\n String[] ss = new String[] { s.substring(0, i), s.substring(i, j), s.substring(j) };\n int x = 0;\n boolean g = true;\n for(int k = 0; k < ss.length; k++) {\n g &= ok(ss[k]);\n if(g) {\n x += Integer.parseInt(ss[k]);\n }\n }\n if(g) {\n res = Math.max(res, x);\n }\n }\n IOFast.out.println(res);\n }\n }\n \n public static void main(String[] args) throws IOException {\n new Solver().run();\n IOFast.out.flush();\n }\n \n\n static public class IOFast {\n private static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n private static PrintWriter out = new PrintWriter(System.out);\n\n// private static final int BUFFER_SIZE = 50 * 200000;\n private static final StringBuilder buf = new StringBuilder();\n private static boolean[] isDigit = new boolean[256];\n private static boolean[] isSpace = new boolean[256];\n\n static {\n for(int i = 0; i < 10; i++) {\n isDigit['0' + i] = true;\n }\n isDigit['-'] = true;\n isSpace[' '] = isSpace['\\r'] = isSpace['\\n'] = isSpace['\\t'] = true;\n }\n \n static boolean endInput;\n\n private static int nextInt() throws IOException {\n boolean plus = false;\n int ret = 0;\n while(true) {\n final int c = in.read();\n \n if(c == -1) {\n endInput = true;\n return Integer.MIN_VALUE;\n }\n \n if(isDigit[c]) {\n if(c != '-') {\n plus = true;\n ret = c - '0';\n }\n break;\n }\n }\n \n while(true) {\n final int c = in.read();\n if(c == -1 || !isDigit[c]) {\n break;\n }\n ret = ret * 10 + c - '0';\n }\n \n return plus ? ret : -ret;\n }\n \n private static long nextLong() throws IOException {\n boolean plus = false;\n long ret = 0;\n while(true) {\n final int c = in.read();\n \n if(c == -1) {\n endInput = true;\n return Integer.MIN_VALUE;\n }\n \n if(isDigit[c]) {\n if(c != '-') {\n plus = true;\n ret = c - '0';\n }\n break;\n }\n }\n \n while(true) {\n final int c = in.read();\n if(c == -1 || !isDigit[c]) {\n break;\n }\n ret = ret * 10 + c - '0';\n }\n \n return plus ? ret : -ret;\n }\n\n\n\n private static String next() throws IOException {\n buf.setLength(0);\n\n while(true) {\n final int c = in.read();\n \n if(c == -1) {\n endInput = true;\n return \"-1\";\n }\n \n if(!isSpace[c]) {\n buf.append((char)c);\n break;\n }\n }\n \n while(true) {\n final int c = in.read();\n \n if(c == -1 || isSpace[c]) {\n break;\n }\n buf.append((char)c);\n }\n\n return buf.toString();\n }\n\n private static double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n }\n\n}\n", "src_uid": "bf4e72636bd1998ad3d034ad72e63097"} {"source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.lang.*;\n \nimport static java.lang.Math.*;\n \npublic class Cf182 implements Runnable \n{\n\tstatic class InputReader \n\t{\n\t\tprivate InputStream stream;\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int numChars;\n\t\tprivate SpaceCharFilter filter;\n\t\tprivate BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tpublic InputReader(InputStream stream) \n\t\t{\n\t\t\tthis.stream = stream;\n\t\t}\n\t\t\n\t\tpublic int read()\n\t\t{\n\t\t\tif (numChars==-1) \n\t\t\t\tthrow new InputMismatchException();\n \n\t\t\tif (curChar >= numChars) \n\t\t\t{\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry\n\t\t\t\t{\n\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t\t}\n\t\t\t\tcatch (IOException e)\n\t\t\t\t{\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n \n\t\t\t\tif(numChars <= 0) \n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n \n\t\tpublic String nextLine()\n\t\t{\n\t\t\tString str = \"\";\n\t\t\ttry\n\t\t\t{\n\t\t\t\tstr = br.readLine();\n\t\t\t}\n\t\t\tcatch (IOException e)\n\t\t\t{\n\t\t\t\te.printStackTrace();\n\t\t\t}\t\n\t\t\treturn str;\n\t\t}\n\t\tpublic int nextInt() \n\t\t{\n\t\t\tint c = read();\n \n\t\t\twhile(isSpaceChar(c)) \n\t\t\t\tc = read();\n\t\t\n\t\t\tint sgn = 1;\n \n\t\t\tif (c == '-') \n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n \n\t\t\tint res = 0;\n\t\t\tdo\n\t\t\t{\n\t\t\t\tif(c<'0'||c>'9') \n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\twhile (!isSpaceChar(c)); \n \n\t\t\treturn res * sgn;\n\t\t}\n \n\t\tpublic long nextLong() \n\t\t{\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-')\n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\t\n\t\t\tdo \n\t\t\t{\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\t\n\t\t\twhile (!isSpaceChar(c));\n\t\t\t\treturn res * sgn;\n\t\t}\n\t\t\n\t\tpublic double nextDouble() \n\t\t{\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-')\n\t\t\t{\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tdouble res = 0;\n\t\t\twhile (!isSpaceChar(c) && c != '.') \n\t\t\t{\n\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\treturn res * Math.pow(10, nextInt());\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tif (c == '.') \n\t\t\t{\n\t\t\t\tc = read();\n\t\t\t\tdouble m = 1;\n\t\t\t\twhile (!isSpaceChar(c))\n\t\t\t\t{\n\t\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\t\treturn res * Math.pow(10, nextInt());\n\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\tm /= 10;\n\t\t\t\t\tres += (c - '0') * m;\n\t\t\t\t\tc = read();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res * sgn;\n\t\t}\n \n\t\tpublic String readString() \n\t\t{\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo \n\t\t\t{\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} \n\t\t\twhile (!isSpaceChar(c));\n \n\t\t\treturn res.toString();\n\t\t}\n \n\t\tpublic boolean isSpaceChar(int c) \n\t\t{\n\t\t\tif (filter != null)\n\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n \n\t\tpublic String next()\n\t\t{\n\t\t\treturn readString();\n\t\t}\n \n\t\tpublic interface SpaceCharFilter\n\t\t{\n\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t}\n\tpublic static void main(String args[]) throws Exception \n\t{\n\t\tnew Thread(null, new Cf182(),\"Main\",1<<27).start();\n\t}\t\n\t\n\tpublic static long gcd(long a, long b) \n\t{ \n\t\tif (a == 0) \n\t\t\treturn b; \n\t\treturn gcd(b % a, a); \n\t} \n\t// array sorting by colm\npublic static void sortbyColumn(int arr[][], int col) \n { \n \n Arrays.sort(arr, new Comparator<int[]>() { \n \n @Override\n public int compare(final int[] entry1, \n final int[] entry2) { \n \n \n if (entry1[col] > entry2[col]) \n return 1; \n else\n return -1; \n } \n }); \n } \n\t\n\t// gcd\n \n\tpublic static long findGCD(long arr[], int n) \n\t{ \n\t\tlong result = arr[0]; \n\t\tfor (int i = 1; i < n; i++) \n\t\t\tresult = gcd(arr[i], result); \n\t\treturn result; \n\t}\n\t// fibonaci\n\tstatic int fib(int n) \n { \n int a = 0, b = 1, c; \n if (n == 0) \n return a; \n for (int i = 2; i <= n; i++) \n { \n c = a + b; \n a = b; \n b = c; \n } \n return b; \n } \n \n// sort a string\n public static String sortString(String inputString) \n { \n \n char tempArray[] = inputString.toCharArray(); \n \n \n Arrays.sort(tempArray); \n \n \n return new String(tempArray); \n } \n // pair function\n \n // list.add(new Pair<>(sc.nextInt(), i + 1));\n // Collections.sort(list, (a, b) -> Integer.compare(b.first, a.first));\n private static class Pair<F, S> {\n \n private F first;\n \n private S second;\n \n public Pair() {}\n \n public Pair(F first, S second) {\n this.first = first;\n this.second = second;\n }\n }\n \n \n static boolean isPerfectSquare(int x) \n { \n int s = (int) Math.sqrt(x); \n return (s*s == x); \n } \n \n \n static boolean isFibonacci(int n) \n { \n \n return isPerfectSquare(5*n*n + 4) || \n isPerfectSquare(5*n*n - 4); \n } \n \n\tpublic void run()\n\t{\n\t\tInputReader sc = new InputReader(System.in);\n\t\tPrintWriter w = new PrintWriter(System.out);\n\t\tint x = sc.nextInt();\n\t\tint h = sc.nextInt();\n\t\tint m = sc.nextInt();\n \n\t\tint count = 0;\n\t\twhile (!(h+\"\"+m).contains(\"7\")) \n\t\t{\n\t\t\tm -= x;\n\t\t\tif (m < 0) \n\t\t\t{\n\t\t\t\tm += 60;\n\t\t\t\th--;\n\t\t\t\tif(h<0)\n\t\t\t\t\th+=24;\n\t\t\t}\n\t\t\tcount++;\n\t\t}\n\t\tSystem.out.println(count);\n\t//\t\tSystem.out.println(42 + 60*7 - 9*60 -24);\n\t}\n}", "src_uid": "5ecd569e02e0164a5da9ff549fca3ceb"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class RougeClock {\n\t\n\tpublic static void main(String[] args) throws IOException{\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tString[] buf = br.readLine().split(\" \");\n\t\t\n\t\tlong n = Long.parseLong(buf[0]);\n\t\tlong m = Long.parseLong(buf[1]);\n\t\t\n\t\tint size_h = 1;\n\t\tint size_m = 1;\n\t\tfor (int degree = 7; degree<n; degree*=7)\n\t\t\tsize_h++;\n\t\tfor (int degree = 7; degree<m; degree*=7)\n\t\t\tsize_m++;\n\t\t\n\t\tint ans = 0;\n\t\tif(size_h+size_m<=7){\n\t\t\tfor(int i =0;i<n;i++){\n\t\t\t\tfor(int j =0;j<m;j++){\n\t\t\t\t\tint[] used = new int[7];\n\t\t\t\t\tfor(int a=i, k = 0; k<size_h; a/=7, ++k)\n\t\t\t\t\t\tused[a%7]+=1;\n\t\t\t\t\tfor(int a=j, k = 0; k<size_m; a/=7, ++k)\n\t\t\t\t\t\tused[a%7]+=1;\n\t\t\t\t\tif (max(used)<=1)\n\t\t\t\t\t\tans++;\n\t\t\t\t}\n\t\t\t}\n\t\t}else{\n\t\t\tif(size_h<=6){\n\t\t\t\tfor(int i =0;i<n;i++){\n\t\t\t\t\tint[] used = new int[6];\n\t\t\t\t\tfor(int a=i, k = 0; k<=size_h; a/=7, k++){\n\t\t\t\t\t\tif(a%7==0) \n\t\t\t\t\t\t\tused[0]=2;\n\t\t\t\t\t\telse{\n\t\t\t\t\t\t\tused[a%7-1]+=1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (max(used)<=1)\n\t\t\t\t\t\tans++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(size_m<=6){\n\t\t\t\tfor(int i =0;i<m;i++){\n\t\t\t\t\tint[] used = new int[6];\n\t\t\t\t\tfor(int a=i, k = 0; k<=size_h; a/=7, k++){\n\t\t\t\t\t\tif(a%7==0) \n\t\t\t\t\t\t\tused[0]=2;\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tused[a%7-1]+=1;\n\t\t\t\t\t}\n\t\t\t\t\tif (max(used)<=1)\n\t\t\t\t\t\tans++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(ans);\n\t}\n\n\tprivate static int max(int[] used) {\n\t\tint max =0;\n\t\tfor(int i =0; i<used.length;i++){\n\t\t\tif(used[i]>max){\n\t\t\t\tmax = used[i];\n\t\t\t}\n\t\t}\n\t\treturn max;\n\t}\n}\n", "src_uid": "0930c75f57dd88a858ba7bb0f11f1b1c"} {"source_code": "import java.util.Scanner;\n\npublic class Main {\n public static void main(String[] args) {\n String s = new Scanner(System.in).nextLine();\n String chars = \"><+-.,[]\";\n int res =0;\n for(char c:s.toCharArray()) {\n int x = chars.indexOf(c)+8;\n res = (res *16+x)%1000003;\n }\n System.out.println(res);\n }\n}", "src_uid": "04fc8dfb856056f35d296402ad1b2da1"} {"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<String> 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<Pair> 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<Pair, Integer> 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", "src_uid": "711d15e11016d0164fb2b0c3756e4857"} {"source_code": "// upsolve with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF1187G extends PrintWriter {\n\tCF1187G() { super(System.out); }\n\tstatic class Scanner {\n\t\tScanner(InputStream in) { this.in = in; } InputStream in;\n\t\tint k, l; byte[] bb = new byte[1 << 15];\n\t\tbyte getc() {\n\t\t\tif (k >= l) {\n\t\t\t\tk = 0;\n\t\t\t\ttry { l = in.read(bb); } catch (IOException e) { l = 0; }\n\t\t\t\tif (l <= 0) return -1;\n\t\t\t}\n\t\t\treturn bb[k++];\n\t\t}\n\t\tint nextInt() {\n\t\t\tbyte c = 0; while (c <= 32) c = getc();\n\t\t\tint a = 0;\n\t\t\twhile (c > 32) { a = a * 10 + c - '0'; c = getc(); }\n\t\t\treturn a;\n\t\t}\n\t}\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF1187G o = new CF1187G(); o.main(); o.flush();\n\t}\n\n\tstatic final int INF = 0x3f3f3f3f;\n\tArrayList[] aa_;\n\tint n_, m_;\n\tint[] pi, dd, bb;\n\tint[] uu, vv, uv, cost;\n\tint[] cc;\n\tvoid init() {\n\t\taa_ = new ArrayList[n_];\n\t\tfor (int u = 0; u < n_; u++)\n\t\t\taa_[u] = new ArrayList<Integer>();\n\t\tpi = new int[n_];\n\t\tdd = new int[n_];\n\t\tbb = new int[n_];\n\t\tqq = new int[nq];\n\t\tiq = new boolean[n_];\n\t\tuu = new int[m_];\n\t\tvv = new int[m_];\n\t\tuv = new int[m_];\n\t\tcost = new int[m_];\n\t\tcc = new int[m_ * 2];\n\t\tm_ = 0;\n\t}\n\tvoid link(int u, int v, int cap, int cos) {\n\t\tint h = m_++;\n\t\tuu[h] = u;\n\t\tvv[h] = v;\n\t\tuv[h] = u ^ v;\n\t\tcost[h] = cos;\n\t\tcc[h << 1 ^ 0] = cap;\n\t\taa_[u].add(h << 1 ^ 0);\n\t\taa_[v].add(h << 1 ^ 1);\n\t}\n\tint[] qq;\n\tint nq = 1 << 20, head, cnt;\n\tboolean[] iq;\n\tvoid enqueue(int v) {\n\t\tif (iq[v])\n\t\t\treturn;\n\t\tif (head + cnt == nq) {\n\t\t\tif (cnt * 2 <= nq)\n\t\t\t\tSystem.arraycopy(qq, head, qq, 0, cnt);\n\t\t\telse {\n\t\t\t\tint[] qq_ = new int[nq *= 2];\n\t\t\t\tSystem.arraycopy(qq, head, qq_, 0, cnt);\n\t\t\t\tqq = qq_;\n\t\t\t}\n\t\t\thead = 0;\n\t\t}\n\t\tqq[head + cnt++] = v; iq[v] = true;\n\t}\n\tint dequeue() {\n\t\tint u = qq[head++]; cnt--; iq[u] = false;\n\t\treturn u;\n\t}\n\tboolean spfa(int s, int t) {\n\t\tArrays.fill(pi, INF);\n\t\tpi[s] = 0;\n\t\thead = cnt = 0;\n\t\tenqueue(s);\n\t\twhile (cnt > 0) {\n\t\t\tint u = dequeue();\n\t\t\tint d = dd[u] + 1;\n\t\t\tArrayList<Integer> adj = aa_[u];\n\t\t\tfor (int h_ : adj)\n\t\t\t\tif (cc[h_] > 0) {\n\t\t\t\t\tint h = h_ >> 1;\n\t\t\t\t\tint p = pi[u] + ((h_ & 1) == 0 ? cost[h] : -cost[h]);\n\t\t\t\t\tint v = u ^ uv[h];\n\t\t\t\t\tif (pi[v] > p || pi[v] == p && dd[v] > d) {\n\t\t\t\t\t\tpi[v] = p;\n\t\t\t\t\t\tdd[v] = d;\n\t\t\t\t\t\tbb[v] = h_;\n\t\t\t\t\t\tenqueue(v);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t}\n\t\treturn pi[t] != INF;\n\t}\n\tvoid push(int s, int t) {\n\t\tint c = INF;\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tc = Math.min(c, cc[h_]);\n\t\t}\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tcc[h_] -= c; cc[h_ ^ 1] += c;\n\t\t}\n\t}\n\tvoid push1(int s, int t) {\n\t\tfor (int u = t, h_, h; u != s; u ^= uv[h]) {\n\t\t\th = (h_ = bb[u]) >> 1;\n\t\t\tcc[h_]--; cc[h_ ^ 1]++;\n\t\t}\n\t}\n\tint edmonds_karp(int s, int t) {\n\t\twhile (spfa(s, t))\n\t\t\tpush1(s, t);\n\t\tint c = 0;\n\t\tfor (int h = 0; h < m_; h++)\n\t\t\tc += cost[h] * cc[h << 1 ^ 1];\n\t\treturn c;\n\t}\n\tvoid main() {\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tint c = sc.nextInt();\n\t\tint d = sc.nextInt();\n\t\tint[] ii = new int[k];\n\t\tfor (int h = 0; h < k; h++)\n\t\t\tii[h] = sc.nextInt() - 1;\n\t\tArrayList[] aa = new ArrayList[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\taa[i] = new ArrayList<Integer>();\n\t\tfor (int h = 0; h < m; h++) {\n\t\t\tint i = sc.nextInt() - 1;\n\t\t\tint j = sc.nextInt() - 1;\n\t\t\taa[i].add(j);\n\t\t\taa[j].add(i);\n\t\t}\n\t\tint t = n + k + 1;\n\t\tn_ = n * t + 1;\n\t\tm_ = k + (m * 2 * k + n) * (t - 1);\n\t\tinit();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tArrayList<Integer> adj = aa[i];\n\t\t\tfor (int s = 0; s < t - 1; s++) {\n\t\t\t\tint u = i * t + s;\n\t\t\t\tfor (int j : adj) {\n\t\t\t\t\tint v = j * t + s + 1;\n\t\t\t\t\tfor (int x = 1; x <= k; x++)\n\t\t\t\t\t\tlink(u, v, 1, c + (x * 2 - 1) * d);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tfor (int s = 0; s < t - 1; s++) {\n\t\t\t\tint u = i * t + s, v = u + 1;\n\t\t\t\tlink(u, v, k, i == 0 ? 0 : c);\n\t\t\t}\n\t\tfor (int h = 0; h < k; h++)\n\t\t\tlink(n_ - 1, ii[h] * t + 0, 1, 0);\n\t\tprintln(edmonds_karp(n_ - 1, 0 * t + t - 1));\n\t}\n}\n", "src_uid": "2d0aa75f2e63c4fb8c98742ac8cd821c"} {"source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class E {\n\tpublic static int answer = 0;\n\tpublic static int[][] adj;\n\tpublic static void main(String[] args){\n\t\tScanner in = new Scanner(System.in);\n\t\tint len = in.nextInt();\n\t\tadj = new int[len][len];\n\t\tgo(0,0,in);\n\t\tgog(0,0,0);\n\t\tgor(0,0);\n\t\tSystem.out.println(answer);\n\t}\n\tpublic static int go(int a, int b, Scanner in){\n\t b=b>=adj.length?0+(++a)-a:b;\n\t a = a<adj.length?a+complete(a,b,in)+go(a,b+1,in):a;\n\t return 0;\n\t}\n\tpublic static int gog(int a, int b, int c){\n\t\t c=c>=adj.length?0+(++b)-b:c;\n\t\t b=b>=adj.length?0+(++a)-a:b;\n\t\t a = a<adj.length?a+complete2( c,b,a)+gog(a,b,c+1):a;\n\t\t return 0;\n\t\t}\n\tpublic static int gor(int a, int b){\n\t b=b>=adj.length?0+(++a)-a:b;\n\t a = a<adj.length?a+complete3(a,b)+gor(a,b+1):a;\n\t return 0;\n\t}\n\tpublic static int complete3(int a, int b){\n\t\tanswer=adj[a][b]>answer?adj[a][b]:answer;\n\t\treturn 0;\n\t}\n\tpublic static int complete(int a, int b, Scanner in){\n\t\tadj[a][b]=in.nextInt();\n\t\treturn 0;\n\t}\n\tpublic static int complete2(int a, int b,int c){\n\t\tadj[a][b] = Math.min(adj[a][b], adj[a][c]+adj[c][b]);\n\t\treturn 0;\n\t}\n}\n", "src_uid": "bbd210065f8b32de048a2d9b1b033ed5"} {"source_code": "import java.io.*;\n\n//Codeforces Beta Round #41 (Div. 1), B\npublic class Chess {\n\n public static void main(String[] args) throws IOException {\n\t\tFile file = new File(\"input.txt\");\n\t\tif(file.exists())\n\t\t\tSystem.setIn(new FileInputStream(file));\n\t\tBufferedReader r = new BufferedReader(new InputStreamReader(System.in));\n\t\tString[] ss = r.readLine().split(\" \");\n\t\tboolean a[][] = new boolean[10][10];\n\t\tfor(int i = 0; i < 10; i++)\n\t\t\ta[0][i] = a[i][0] = a[9][i] = a[i][9] = true;\n\t\tint k1 = ss[2].charAt(0) - 'a' + 1, k2 = ss[2].charAt(1) - '0';\n\t\tfor(String s : new String[]{ss[0], ss[1]}) {\n\t\t\tint l1 = s.charAt(0) - 'a' + 1, l2 = s.charAt(1) - '0';\n\t\t\tfor(int i = 1; i < 9; i++) {\n\t\t\t\tif(i != l1 && (l2 != k2 || i <= k1 && l1 < k1 || i >= k1 && l1 > k1))\n\t\t\t\t\ta[i][l2] = true;\n\t\t\t\tif(i != l2 && (l1 != k1 || i <= k2 && l2 < k2 || i >= k2 && l2 > k2))\n\t\t\t\t\ta[l1][i] = true;\n\t\t\t}\n\t\t}\n\t\ta[k1][k2] = a[k1][k2 - 1] = a[k1][k2 + 1] = a[k1 - 1][k2 - 1] = a[k1 - 1][k2] = a[k1 - 1][k2 + 1] = a[k1 + 1][k2 - 1] = a[k1 + 1][k2] = a[k1 + 1][k2 + 1] = true;\n\t\t/*for(int i = 0; i < 10; i++) {\n\t\t\tfor(int j = 0; j < 10; j++)\n\t\t\t\tSystem.out.print(a[i][j] ? 'X' : ' ');\n\t\t\tSystem.out.println();\n\t\t}*/\n\t\tint p1 = ss[3].charAt(0) - 'a' + 1, p2 = ss[3].charAt(1) - '0';\n\t\tboolean result = a[p1][p2] && a[p1][p2 - 1] && a[p1][p2 + 1] && a[p1 - 1][p2 - 1] && a[p1 - 1][p2] && a[p1 - 1][p2 + 1] && a[p1 + 1][p2 - 1] && a[p1 + 1][p2] && a[p1 + 1][p2 + 1];\n\t\tSystem.out.println(result ? \"CHECKMATE\" : \"OTHER\");\n }\n\n}\n", "src_uid": "5d05af36c7ccb0cd26a4ab45966b28a3"} {"source_code": "import java.util.*;\nimport java.lang.*;\n\npublic class Greedy {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String[] firstLine = sc.nextLine().split(\" \");\n int d = Integer.parseInt(firstLine[0]);\n int toStudy = Integer.parseInt(firstLine[1]);\n int[] arr = new int[d * 2];\n int[] gb = new int[d];\n for(int i = 0; i < d; i++) {\n String[] nextLine = sc.nextLine().split(\" \");\n arr[i * 2] = Integer.parseInt(nextLine[0]);\n arr[i * 2 + 1] = Integer.parseInt(nextLine[1]);\n toStudy -= arr[i * 2]; // greedy subtraction of the minimum;\n gb[i] = arr[i * 2];\n }\n if(toStudy < 0) {\n System.out.println(\"NO\"); // the mins are too high for the study time\n return;\n }\n for(int i = 0; i < d; i++) {\n toStudy -= (arr[i * 2 + 1] - arr[i * 2]);\n gb[i] = arr[i * 2 + 1];\n if(toStudy <= 0) {\n gb[i] -= Math.abs(toStudy);\n System.out.println(\"YES\");\n printString(gb);\n return;\n }\n }\n System.out.println(\"NO\");\n\n }\n\n private static void printString(int[] arr) {\n StringBuilder sb = new StringBuilder();\n for(int i = 0; i < arr.length; i++) {\n sb.append(arr[i]);\n sb.append(\" \");\n }\n System.out.println(sb.toString());\n }\n \n}", "src_uid": "f48ff06e65b70f49eee3d7cba5a6aed0"} {"source_code": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class AntonAndFairyTale {\n InputStream is;\n PrintWriter pw;\n String INPUT = \"\";\n long L_INF = (1L << 60L);\n\n void solve() {\n long n = nl(), m = nl(), start = 0, end = (long)2e9, mid;\n if (m >= n) {\n pw.println(n);\n return;\n }\n n -= m;\n while (start < end) {\n mid = start + (end - start) / 2;\n long x = mid * (mid + 1) / 2;\n if (n <= x)\n end = mid;\n else\n start = mid + 1;\n }\n pw.println(start + m);\n }\n\n void run() throws Exception {\n //\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n is = System.in;\n pw = new PrintWriter(System.out);\n\n long s = System.currentTimeMillis();\n // int t = ni();\n // while (t-- > 0)\n solve();\n pw.flush();\n tr(System.currentTimeMillis() - s + \"ms\");\n }\n\n public static void main(String[] args) throws Exception {\n new AntonAndFairyTale().run();\n }\n\n private byte[] inbuf = new byte[1024];\n private int lenbuf = 0, ptrbuf = 0;\n\n private int readByte() {\n if (lenbuf == -1) throw new InputMismatchException();\n if (ptrbuf >= lenbuf) {\n ptrbuf = 0;\n try {\n lenbuf = is.read(inbuf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (lenbuf <= 0) return -1;\n }\n return inbuf[ptrbuf++];\n }\n\n private boolean isSpaceChar(int c) {\n return !(c >= 33 && c <= 126);\n }\n\n private int skip() {\n int b;\n while ((b = readByte()) != -1 && isSpaceChar(b)) ;\n return b;\n }\n\n private double nd() {\n return Double.parseDouble(ns());\n }\n\n private char nc() {\n return (char) skip();\n }\n\n private String ns() {\n int b = skip();\n StringBuilder sb = new StringBuilder();\n while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')\n sb.appendCodePoint(b);\n b = readByte();\n }\n return sb.toString();\n }\n\n private char[] ns(int n) {\n char[] buf = new char[n];\n int b = skip(), p = 0;\n while (p < n && !(isSpaceChar(b))) {\n buf[p++] = (char) b;\n b = readByte();\n }\n return n == p ? buf : Arrays.copyOf(buf, p);\n }\n\n private char[][] nm(int n, int m) {\n char[][] map = new char[n][];\n for (int i = 0; i < n; i++) map[i] = ns(m);\n return map;\n }\n\n private int[] na(int n) {\n int[] a = new int[n];\n for (int i = 0; i < n; i++) a[i] = ni();\n return a;\n }\n\n private int ni() {\n int num = 0, b;\n boolean minus = false;\n while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n\n while (true) {\n if (b >= '0' && b <= '9') {\n num = num * 10 + (b - '0');\n } else {\n return minus ? -num : num;\n }\n b = readByte();\n }\n }\n\n private long nl() {\n long num = 0;\n int b;\n boolean minus = false;\n while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;\n if (b == '-') {\n minus = true;\n b = readByte();\n }\n\n while (true) {\n if (b >= '0' && b <= '9') {\n num = num * 10 + (b - '0');\n } else {\n return minus ? -num : num;\n }\n b = readByte();\n }\n }\n\n private boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\n private void tr(Object... o) {\n if (!oj) System.out.println(Arrays.deepToString(o));\n }\n}\n", "src_uid": "3b585ea852ffc41034ef6804b6aebbd8"} {"source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n\n static long n, k, a, b;\n static long mn = Long.MAX_VALUE;\n static long mx = Long.MIN_VALUE;\n\n static long gcd(long a, long b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n static void check(long start, long finish) {\n long len = (finish - start + n * k) % (n * k);\n long g = gcd(n * k, len);\n long cnt = n * k / g;\n mn = Math.min(mn, cnt);\n mx = Math.max(mx, cnt);\n// System.err.println(len + \" \" + mn + \" \" + mx);\n }\n\n public static void main(String[] args) throws Exception {\n FastScanner scanner = new FastScanner(System.in);\n PrintWriter writer = new PrintWriter(System.out);\n\n n = scanner.nextInt();\n k = scanner.nextInt();\n\n a = scanner.nextInt();\n b = scanner.nextInt();\n\n for (long i = 0; i < n; i++) {\n check(1 + a, 1 + i * k + b);\n check(1 + a, 1 + i * k - b);\n check(1 - a, 1 + i * k + b);\n check(1 - a, 1 + i * k - b);\n }\n\n writer.println(mn + \" \" + mx);\n writer.close();\n }\n\n final static class FastScanner implements AutoCloseable {\n private final int BUFFER_CAPACITY = 1024;\n\n private final InputStream stream;\n private final byte[] buffer = new byte[BUFFER_CAPACITY];\n private int size = 0;\n private int current = 0;\n private char lastReadedChar = '\\0';\n\n FastScanner(InputStream stream) {\n this.stream = stream;\n }\n\n FastScanner(String filename) throws IOException {\n this.stream = new FileInputStream(filename);\n }\n\n public void close() throws Exception {\n stream.close();\n }\n\n boolean hasNextLine() throws Exception {\n try {\n return Character.isWhitespace(lastReadedChar) || !endOfInputReached();\n } catch (IOException e) {\n return false;\n }\n }\n\n\n char nextChar() throws Exception {\n byte firstByte = nextByte();\n int octets = 0;\n for (int i = 7; (firstByte >> i & 1) == 1; i--) {\n octets++;\n }\n if (octets == 0) {\n return (char) firstByte;\n }\n char res = 0;\n for (int bit = 7 - octets; bit >= 0; bit--) {\n res <<= 1;\n res += (firstByte >> bit) & 1;\n }\n for (int i = 1; i < octets; i++) {\n res <<= 6;\n res += nextByte() + 128;\n }\n return res;\n }\n\n String next() throws Exception {\n do {\n lastReadedChar = nextChar();\n } while (Character.isWhitespace(lastReadedChar));\n StringBuilder res = new StringBuilder();\n while (!endOfInputReached() && !Character.isWhitespace(lastReadedChar)) {\n res.append(lastReadedChar);\n lastReadedChar = nextChar();\n }\n if (!Character.isWhitespace(lastReadedChar)) {\n res.append(lastReadedChar);\n }\n return res.toString();\n }\n\n int nextInt() throws Exception {\n return Integer.parseInt(next());\n }\n\n private byte nextByte() throws Exception {\n if (endOfInputReached()) {\n throw new Exception();\n }\n return buffer[current++];\n }\n\n private void fillBuffer() throws Exception {\n do {\n size = stream.read(buffer);\n } while (size == 0);\n current = 0;\n }\n\n private boolean endOfInputReached() throws Exception {\n if (current >= size) {\n fillBuffer();\n }\n return size == -1;\n }\n }\n}", "src_uid": "5bb4adff1b332f43144047955eefba0c"} {"source_code": "import java.io.BufferedInputStream;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\n\npublic class D {\n\n\tstatic int N;\n\tstatic Vec ar[];\n\tstatic boolean used[];\n\tstatic char S[];\n\tstatic int sId;\n\tstatic ArrayList<Integer> res;\n\tstatic boolean largerY = false;\n\tpublic static void main(String[] args) {\n\t\tJS in = new JS();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\t\n\t\tN = in.nextInt();\n\t\tres = new ArrayList<Integer>();\n\t\tar = new Vec[N];\n\t\tfor(int i = 0; i < N; i++) {\n\t\t\tar[i] = new Vec(in.nextLong(),in.nextLong(),i);\n\t\t}\n\t\t\n\t\tS = in.next().toCharArray();\n\t\t\n\t\tVec b = ar[0];\n\t\tif(S[0] == 'L') {\n\t\t\tfor(int i = 1; i < N; i++) if(ar[i].x < b.x || (ar[i].x == b.x && ar[i].y > b.y)) b = ar[i];\n\t\t}\n\t\telse {\n\t\t\tfor(int i = 1; i < N; i++) if(ar[i].x < b.x || (ar[i].x == b.x && ar[i].y < b.y)) b = ar[i];\n\t\t}\t\t\n\t\tused = new boolean[N];\n\t\tadd(b.id);\n\t\t\n\t\tfor(int sId = 0; sId < S.length; sId++) {\n\t\t\tif(S[sId] == 'L') {\n\t\t\t\tVec next = null;\n\t\t\t\tfor(int i = 0; i < N; i++) {\n\t\t\t\t\tif(used[ar[i].id])continue;\n\t\t\t\t\tif(next == null || ar[i].sub(b).cross(next.sub(b)) > 0) next = ar[i];\n\t\t\t\t}\n\t\t\t\tadd(next.id);\n\t\t\t\tb = next;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tVec next = null;\n\t\t\t\tfor(int i = 0; i < N; i++) {\n\t\t\t\t\tif(used[ar[i].id])continue;\n\t\t\t\t\tif(next == null || ar[i].sub(b).cross(next.sub(b)) < 0) next = ar[i];\n\t\t\t\t}\n\t\t\t\tadd(next.id);\n\t\t\t\tb = next;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\t\n\t\tfor(int i = 0; i < N; i++) {\n\t\t\tif(!used[ar[i].id]) res.add(ar[i].id);\n\t\t}\n\t\t\n\t\tfor(int ii : res) out.print((ii+1)+\" \");\n\t\tout.println();\n\t\tout.close();\n\t}\n\n\tstatic void add(int x) {\n\t\tres.add(x);\n\t\tused[x]=true;\n\t}\n\t\n\tstatic class Vec implements Comparable<Vec>{\n\t\tlong x,y;\n\t\tint id;\n\t\tpublic Vec(long xx, long yy) {\n\t\t\tx=xx;\n\t\t\ty=yy;\n\t\t}\n\t\tpublic Vec(long xx, long yy, int ii) {\n\t\t\tx=xx;\n\t\t\ty=yy;\n\t\t\tid=ii;\n\t\t}\n\t\tpublic long cross(Vec o) {\n\t\t\treturn x*o.y - y*o.x;\n\t\t}\n\t\tpublic Vec sub(Vec o) {\n\t\t\treturn new Vec(x-o.x, y-o.y);\n\t\t}\n\t\t@Override\n\t\tpublic int compareTo(Vec o) {\n\t\t\tif(x == o.x) return largerY ? -Long.compare(y, o.y) : Long.compare(y, o.y);\n\t\t\treturn Long.compare(x, o.x);\n\t\t}\n\t}\n\t\n\tstatic class JS{\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\t\t\n\t\tpublic JS() {\n\t\t\tin = new BufferedInputStream(System.in, BS);\n\t\t}\n\t\t\n\t\tpublic JS(String s) throws FileNotFoundException {\n\t\t\tin = new BufferedInputStream(new FileInputStream(new File(s)), BS);\n\t\t}\n\t\t\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}\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\t\t\n\t\tpublic int nextInt() {\n\t\t\treturn (int)nextLong();\n\t\t}\n\t\t\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\t\t\n\t\tpublic double nextDouble() {\n\t\t while(c!='.'&&c!='-'&&(c <'0' || c>'9')) c = nextChar();\n\t\t boolean neg = c=='-';\n\t\t if(neg)c=nextChar();\n\t\t boolean fl = c=='.';\n\t\t double cur = nextLong();\n\t\t if(fl) return neg ? -cur/num : cur/num;\n\t\t if(c == '.') {\n\t\t\tdouble next = nextLong();\n\t\t\treturn neg ? -cur-next/num : cur+next/num;\n\t\t }\n\t\t else return neg ? -cur : cur;\n\t\t}\n\t\t\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\t\t\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}\n\t\n}\n", "src_uid": "13d7f6127a7fe945e19d461b584c6228"} {"source_code": "import java.util.*;\n\npublic class BearAndCompressing {\n \n int n, q, ans = 0;\n String[][] op = new String[36][2];\n\n BearAndCompressing() {\n Scanner scanner = new Scanner(System.in);\n n = scanner.nextInt();\n q = scanner.nextInt();\n \n for (int i = 0; i < q; i++) {\n op[i][0] = scanner.next();\n op[i][1] = scanner.next();\n }\n\n for (int i = 0; i < q; i++) {\n if (op[i][1].equals(\"a\")) {\n recursive(op[i][0]);\n }\n }\n System.out.println(ans);\n scanner.close();\n }\n\n void recursive(String res){\n if (res.length() >= n) {\n ans++;\n return;\n }\n String temp;\n for (int i = 0; i < q; i++) {\n if (op[i][1].charAt(0) == res.charAt(0)) {\n temp = res;\n res = op[i][0] + res.substring(1);\n //System.out.println(res);\n recursive(res);\n res = temp;\n }\n }\n }\n\n public static void main(String[] args) {\n BearAndCompressing solve = new BearAndCompressing();\n }\n}", "src_uid": "c42abec29bfd17de3f43385fa6bea534"} {"source_code": "import java.util.*;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class ar {\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 (final 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 (final IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n }\n\n static boolean[] seen;\n static Map<Integer, Integer> map;\n static Set<Character> charset;\n static Set<Integer> set;\n static int[] arr;\n static int[][] dp;\n static int rem = (int) 1e9 + 7;\n static List<List<Integer>> graph;\nstatic int[][] kmv ={{2,1},{1,2},{2,-1},{-1,2},{-2,1},{1,-2},{-1,-2},{-2,-1}};\nstatic char[]car;\nstatic boolean[] primes;\nstatic int MAX=(int)1e4+1;\nstatic double[] dar;\nstatic long[] lar;\nstatic void Sieve(){\n\nprimes=new boolean[MAX];\nprimes[0]=true;\nprimes[1]=true;\n\nfor(int i=2;i*i<MAX;i++){\n if(!primes[i]){\n for(int j=i*i;j<MAX;j+=i){\n primes[j]=true;\n }\n }\n}\n\n\n}\n\n\npublic static void main( String[] args) throws java.lang.Exception {\n FastReader scn = new FastReader();\nint n=scn.nextInt();\nString s=scn.next();\nint cnt=0;\nint ans=0;\nint i=0;\nwhile(i<n){\n if(s.charAt(i)>='a' && s.charAt(i)<='z'){\n charset=new HashSet<>();\n for(int j=i;j<n;j++){\n if(s.charAt(j)<='Z'){\n ans=Math.max(ans,cnt); \n cnt = 0; break;}\n if(s.charAt(j)>='a' && s.charAt(j)<='z'){\n if(!charset.contains(s.charAt(j))) \n {charset.add(s.charAt(j));\n cnt++;}\n } \n i++;\n }\n if(cnt>ans)ans=cnt;\n}else i++;\n}\nSystem.out.print(ans);\nreturn;\n}\n\n\n}\n", "src_uid": "567ce65f87d2fb922b0f7e0957fbada3"} {"source_code": "import java.util.*;\nimport java.io.*;\n\npublic class B {\n\n void solve() {\n Input in = new Input(System.in);\n int n = in.nextInt();\n int r = in.nextInt();\n int v = in.nextInt();\n \n for(int i = 0; i < n; i++) {\n int s = in.nextInt();\n int f = in.nextInt();\n int d = f - s;\n \n double gain = 0.0;\n while(true) {\n double newGain = calculateGain(gain, d, r);\n if(Math.abs(newGain - gain) < 10e-7) {\n break;\n } else {\n gain = (newGain + gain) / 2;\n }\n }\n \n double result = (d - gain) / v;\n \n System.out.println(result);\n }\n }\n\n double calculateGain(double gain, int d, int r) {\n double rounds = Math.floor((d -gain) / (2 * Math.PI * r));\n double diff = d -gain - rounds * 2 * Math.PI * r;\n double angle = diff / r;\n \n if(angle > Math.PI) angle = 2 * Math.PI - angle;\n \n double newGain = 2 * r * Math.sin(angle / 2);\n \n return newGain;\n }\n\n public static void main(String[] args) {\n new B().solve();\n }\n\n class Input {\n\n BufferedReader br;\n StringTokenizer st;\n\n Input(InputStream is) {\n br = new BufferedReader(new InputStreamReader(is));\n }\n\n String next() {\n try {\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 } catch (IOException e) {\n return null;\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n\n}\n", "src_uid": "3882f2c02e83bd2d55de8004ea3bbd88"} {"source_code": "import java.util.*;\n\npublic class A {\n public static void main(String[] args) {\n Scanner s = new Scanner(System.in);\n System.out.println((int)Math.signum(s.nextLine().toLowerCase().compareTo(s.nextLine().toLowerCase())));\n }\n}\n", "src_uid": "ffeae332696a901813677bd1033cf01e"} {"source_code": "import java.util.*;\nimport java.lang.*;\n\npublic class B278 {\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\t\n\t\tint num = scan.nextInt();\n\t\t\n\t\tint[] numbers = new int[num];\n\t\t\n\t\tfor (int i = 0; i < num; i++) {\n\t\t\tnumbers[i] = scan.nextInt();\n\t\t}\n\t\t\n\t\tArrays.sort(numbers);\n\t\t\n\t\tif (num == 0) {\n\t\t\tSystem.out.println(\"YES\");\n\t\t\tSystem.out.println(1);\n\t\t\tSystem.out.println(1);\n\t\t\tSystem.out.println(3);\n\t\t\tSystem.out.println(3);\n\t\t\treturn;\n\t\t}\n\t\telse if (num == 1) {\n\t\t\tSystem.out.println(\"YES\");\n\t\t\tSystem.out.println(numbers[0]);\n\t\t\tSystem.out.println(3*numbers[0]);\n\t\t\tSystem.out.println(3*numbers[0]);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\telse if (num == 2) {\n\t\t\tif (numbers[0] == numbers[1]) {\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\tSystem.out.println(3*numbers[0]);\n\t\t\t\tSystem.out.println(3*numbers[0]);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\telse if (numbers[1]/numbers[0] == 3) {\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\tSystem.out.println(3*numbers[0]);\n\t\t\t\tSystem.out.println(3*numbers[1]);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\telse if (numbers[0]/numbers[1] == 3) {\n\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\tSystem.out.println(3*numbers[0]);\n\t\t\t\tSystem.out.println(3*numbers[1]);\n\t\t\t}\n\t\t\t\n\t\t\telse {\n\t\t\t\tfor(int i = 1; i <= 1500; i++) {\n\t\t\t\t\tfor (int j = 1; j <= 1500; j++) {\n\t\t\t\t\t\tif (check2(numbers, i, j)) {\n\t\t\t\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\t\t\t\tSystem.out.println(i);\n\t\t\t\t\t\t\tSystem.out.println(j);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\t\n\t\telse if (num == 3) {\n//\t\t\tif (numbers[0] == numbers[1]) {\n//\t\t\t\tif (numbers[2]/numbers[0] == 3) {\n//\t\t\t\t\tSystem.out.println(\"YES\");\n//\t\t\t\t\tSystem.out.println(numbers[2]);\n//\t\t\t\t\treturn;\n//\t\t\t\t}\n//\t\t\t\telse if (numbers[0]/numbers[2] == 3) {\n//\t\t\t\t\tSystem.out.println(\"YES\");\n//\t\t\t\t\tSystem.out.println(numbers[2]);\n//\t\t\t\t\treturn;\n//\t\t\t\t}\n//\t\t\t\telse {\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\t\n//\t\t\telse if (numbers[0] == numbers[2]) {\n//\t\t\t\tif (numbers[1]/numbers[0] == 3 || numbers[0]/numbers[1] == 3) {\n//\t\t\t\t\tSystem.out.println(\"YES\");\n//\t\t\t\t\tSystem.out.println(numbers[1]);\n//\t\t\t\t\treturn;\n//\t\t\t\t}\n//\t\t\t\telse {\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\t\n//\t\t\telse if (numbers[1] == numbers[2]) {\n//\t\t\t\tif (numbers[0]/numbers[1] == 3 || numbers[1]/numbers[0] == 3) {\n//\t\t\t\t\tSystem.out.println(\"YES\");\n//\t\t\t\t\tSystem.out.println(numbers[0]);\n//\t\t\t\t\treturn;\n//\t\t\t\t}\n//\t\t\t\telse {\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\t//no duplicates at all\n\t\t\t//else {\n\t\t\t\tif (3*numbers[0]<numbers[2]) {\n\t\t\t\t\tSystem.out.println(\"NO\");\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tfor(int i = 1; i <= 1500; i++) {\n\t\t\t\t\t\tif(check3(numbers, i)) {\n\t\t\t\t\t\t\tSystem.out.println(\"YES\");\n\t\t\t\t\t\t\tSystem.out.println(i);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\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\t\n\t\telse {\n\t\t\tcheck4(numbers[0], numbers[1], numbers[2], numbers[3]);\n\t\t\treturn;\n\t\t}\n\t}\n\t\n\tpublic static void check4(int a, int b, int c, int d) {\n\t\tif ((d-a) == ((b+c)/2) && (d-a) == ((a+b+c+d)/4)) {\n\t\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\t\n\tpublic static boolean check3(int[] numbers, int i) {\n\t\tint[]num = new int[4];\n\t\t\n\t\tint index = 0;\n\t\t\n\t\tfor(int x: numbers) {\n\t\t\tnum[index] = x;\n\t\t\tindex++;\n\t\t}\n\t\tnum[index] = i;\n\t\t\n\t\tArrays.sort(num);\n\t\t\n\t\tif ( ((num[3]-num[0]) == ((num[1]+num[2])/2.0)) && ((num[3]-num[0]) == ((num[0]+num[1]+num[2]+num[3])/4.0)) ) {\n//\t\t\tfor(int x: num) {\n//\t\t\t\tSystem.out.println(x);;\n//\t\t\t}\n\t\t\treturn true;\n\t\t}\n\t\t\n\t\treturn false;\n\t\t\n\t}\n\tpublic static boolean check2(int[] numbers, int i, int j) {\n\t\tint[]num = new int[4];\n\t\t\n\t\tint index = 0;\n\t\t\n\t\tfor(int x: numbers) {\n\t\t\tnum[index++] = x;\n\t\t}\n\t\t\n\t\tnum[index++] = i;\n\t\tnum[index] = j;\n\t\t\n\t\tArrays.sort(num);\n\t\t\n\t\tif ((num[3]-num[0]) == ((num[1]+num[2])/2.0) && (num[3]-num[0]) == ((num[0]+num[1]+num[2]+num[3])/4.0)) {\n\t\t\t\treturn true;\n\t\t}\n\t\t\n\t\telse {\n\t\t\treturn false;\n\t\t}\n\t\t\n\t}\n}\n", "src_uid": "230e613abf0f6a768829cbc1f1a09219"} {"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}", "src_uid": "efb72baf6759f7bc5ac0f3099b7177d0"} {"source_code": "import java.io.*;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class Codeforces553B {\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tBufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tStringTokenizer st = new StringTokenizer(f.readLine());\n\t\t\tint n = Integer.parseInt(st.nextToken());\n\t\t\tlong k = Long.parseLong(st.nextToken()) - 1;\n\t\t\tf.close();\n\t\t\tStringBuffer permutation = new StringBuffer(\"\");\n\t\t\tlong[] fibonacci = new long[n + 1];\n\t\t\tfibonacci[1] = 1;\n\t\t\tfor(int i = 2; i <= n; i++)\n\t\t\t\tfibonacci[i] = fibonacci[i - 1] + fibonacci[i - 2];\n\t\t\tint current = 1;\n\t\t\tint counter = n;\n\t\t\twhile(counter > 0)\n\t\t\t{\n\t\t\t\tif(k < fibonacci[counter])\n\t\t\t\t{\n\t\t\t\t\tpermutation.append(current + \" \");\n\t\t\t\t\tcurrent++;\n\t\t\t\t\tcounter--;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tpermutation.append((current + 1) + \" \" + current + \" \");\n\t\t\t\t\tk -= fibonacci[counter];\n\t\t\t\t\tcurrent += 2;\n\t\t\t\t\tcounter -= 2;\n\t\t\t\t}\n\t\t\t\t//System.out.println(permutation.toString().trim());\n\t\t\t}\n\t\t\tSystem.out.println(permutation.toString().trim());\n\t\t\t//System.out.println(Arrays.toString(binary));\n\t\t\t//System.out.println(Arrays.toString(groups));\n\t\t}\n\t\tcatch(IOException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\n}\n", "src_uid": "e03c6d3bb8cf9119530668765691a346"} {"source_code": "import static java.util.Arrays.sort;\nimport java.util.Scanner;\n\n\npublic class third\n{\n\tpublic static void main(String arr[])\n\t{\n\t\tScanner sc= new Scanner(System.in);\n\t\tlong a = sc.nextLong();\n\t\tlong b = sc.nextLong();\n\t\tlong count=0;\n\t\tif(b==1)\n\t\t{\n\t\t\tSystem.out.println(a);\n\t\t\treturn ;\n\t\t}\n\t\twhile(a%b!=1)\n\t\t{\n\t\t\tcount+=a/b;\n\t\t\tlong temp=b;\n\t\t\tb=a%b;\n\t\t\ta=temp;\n\t\t}\n\t\tcount+=a/b;\n\t\tcount+=b;\n\t\tSystem.out.println(count);\n\t\t\n\t}\n}\n\n", "src_uid": "792efb147f3668a84c866048361970f8"} {"source_code": "\nimport java.io.PrintWriter;\nimport java.util.Scanner;\n\npublic class A {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n PrintWriter pw = new PrintWriter(System.out);\n String s = sc.next();\n int t = Integer.valueOf(s.substring(0,1));\n int h = Integer.valueOf(s.substring(1,2));\n int [] a = {2,7,2,3,3,4,2,5,1,2};\n pw.print(a[t] * a[h]);\n pw.flush();\n}\n}", "src_uid": "76c8bfa6789db8364a8ece0574cd31f5"} {"source_code": "import java.util.*;\nimport java.lang.*;\nimport java.io.*;\nimport java.math.*;\n \npublic class Main {\n public static void main (String[] args) throws java.lang.Exception {\n\t\tInputReader scan = new InputReader(System.in);\n\t\tPrintWriter writer = new PrintWriter(System.out, true);\n\t\t(new Main(scan, writer)).run();\n\t\twriter.close();\n }\n \n private InputReader jin;\n private PrintWriter jout;\n \n public Main(InputReader in, PrintWriter out) {\n \tthis.jin = in;\n \tthis.jout = out;\n }\n \n public void run() throws Exception {\n\t\tint n = jin.integer();\n\t\tif(n == 0) {\n\t\t\tjout.println(\"0 0 0\");\n\t\t} else if(n == 1) {\n\t\t \tjout.println(\"0 0 1\");\n\t\t} else {\n\t\t\tint[] fib = new int[(int)1e6];\n\t\t\tfib[0] = 0; fib[1] = 1;\n\t\t\tint i = 2;\n\t\t\tfor(; fib[i - 1] < n; i++) {\n\t\t\t\tfib[i] = fib[i - 1] + fib[i - 2];\n\t\t\t}\t\n\t\t\tjout.println(fib[0] + \" \" + fib[i - 2] + \" \" + fib[i - 3]);\n\t\t}\n\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() throws IOException {\n this.currentBufferSize = this.in.read(this.buffer);\n this.currentBufferTop = 0;\n return this.currentBufferSize > 0;\n }\n \n \n private Byte readChar() throws IOException {\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 \n public String token() throws IOException {\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 String line() throws IOException {\n\t\tByte first;\n\t\tStringBuffer line = new StringBuffer();\n\t\twhile ((first = readChar()) != null && (char)first.byteValue() != '\\n') {\n\t\t\tline.append((char)first.byteValue());\n\t\t}\n\t\treturn (first == null && line.length() == 0)? null : line.toString();\n }\n \n public Integer integer() throws NumberFormatException, IOException {\n String tok = token();\n return tok == null? null : Integer.parseInt(tok);\n }\n \n}\n", "src_uid": "db46a6b0380df047aa34ea6a8f0f93c1"} {"source_code": "import java.util.Scanner;\n\npublic class RectanglePuzzleII {\n\n\tpublic static void main(String[] args) {\n\n\t\tScanner sc = new Scanner(System.in);\n\n\t\tdouble n = sc.nextDouble();\n\t\tdouble m = sc.nextDouble();\n\t\tdouble x = sc.nextDouble();\n\t\tdouble y = sc.nextDouble();\n\t\tdouble a = sc.nextDouble();\n\t\tdouble b = sc.nextDouble();\n\t\tdouble abgcd = gcd(a,b);\n\n\t\tif (abgcd>1) {\n\t\t\ta = a/abgcd;\n\t\t\tb = b/abgcd;\n\t\t}\n\n\t\tdouble ratio = 1;\n\n\t\tif ((Math.abs(n))/a > (Math.abs(m))/b) {\n\t\t\tratio = Math.floor((Math.abs(m))/b);\n\t\t} else if ((Math.abs(n))/a < (Math.abs(m))/b) {\n\t\t\tratio = Math.floor((Math.abs(n))/a);\n\t\t} else if ((Math.abs(n))/a == (Math.abs(m))/b) {\n\t\t\tratio = Math.floor((Math.abs(m))/b);\n\t\t}\n\n\n\t\tdouble xxsize = a*ratio;\n\t\tdouble xx1 = x-Math.ceil(xxsize/2);\n\t\tdouble xx2 = x+Math.floor(xxsize/2);\n\t\tif (n > 0) {\n\t\t\tif (xx1 <= 0) {\n\t\t\t\tdouble move = 0-xx1;\n\t\t\t\txx1 += move;\n\t\t\t\txx2 += move;\n\t\t\t} else if (xx2 >= n) {\n\t\t\t\tdouble move = xx2-n;\n\t\t\t\txx1 -= move;\n\t\t\t\txx2 -= move;\n\t\t\t}\n\t\t} else if (n < 0) {\n\t\t\tif (xx1 >= 0) {\n\t\t\t\tdouble move = xx1;\n\t\t\t\txx1 -= move;\n\t\t\t\txx2 -= move;\n\t\t\t} else if (xx2 <= n) {\n\t\t\t\tdouble move = xx2-n;\n\t\t\t\txx1 += move;\n\t\t\t\txx2 += move;\n\t\t\t}\n\t\t}\n\n\n\t\tdouble yysize = b*ratio;\n\t\tdouble yy1 = y-Math.ceil(yysize/2);\n\t\tdouble yy2 = y+Math.floor(yysize/2);\n\t\tif (m > 0) {\n\t\t\tif (yy1 <= 0) {\n\t\t\t\tdouble move = 0-yy1;\n\t\t\t\tyy1 += move;\n\t\t\t\tyy2 += move;\n\t\t\t} else if (yy2 >= m) {\n\t\t\t\tdouble move = yy2-m;\n\t\t\t\tyy1 -= move;\n\t\t\t\tyy2 -= move;\n\t\t\t}\n\t\t} else if (m < 0) {\n\t\t\tif (yy1 >= 0) {\n\t\t\t\tdouble move = yy1;\n\t\t\t\tyy1 -= move;\n\t\t\t\tyy2 -= move;\n\t\t\t} else if (yy2 <= m) {\n\t\t\t\tdouble move = yy2-m;\n\t\t\t\tyy1 += move;\n\t\t\t\tyy2 += move;\n\t\t\t}\n\t\t}\n\n\t\tSystem.out.printf(\"%.0f %.0f %.0f %.0f\",xx1,yy1,xx2,yy2);\n\n\n\t\t\n\t}\n\n\tpublic static double gcd(double x ,double y ) {\n\n\t if ( y == 0 ) \n\t return x;\n\t else if ( x >= y && y > 0)\n\t return gcd ( y , x % y );\n\t else return gcd ( y , x );\n\n\t}\n}", "src_uid": "8f1211b995f35462ae83b2be27f54585"} {"source_code": "import java.io.* ;\nimport java.util.*;\n\nimport static java.lang.Math.* ;\nimport static java.util.Arrays.* ;\n\npublic class C {\n\t\n\tstatic Long t = System.currentTimeMillis() ;\n\tpublic static void main(String[] args) throws IOException {\n\t\t\n//\t\tRandom r = new Random() ;\n//\t\tint n = 1000 ;\n//\t\tout.println(n) ;\n//\t\tfor( int i = 1 ; i < n ; i++ )\n//\t\t\tout.println(i + \" \" + (i+1)) ;\n//\t\tfor( int i = 0 ; i < n ; i++ )\n//\t\t\tout.println(r.nextInt() + \" \" + r.nextInt()) ;\n//\t\t\n\t\t\n\t\tnew C().solveProblem();\n\t\ttime() ;\n\t\tout.close();\n\t}\n\n\tstatic void time() {\n\t\t//out.println(System.currentTimeMillis()-t);\n\t}\n\tstatic Scanner in = new Scanner(new InputStreamReader(System.in));\n\tstatic BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));\n\tstatic PrintStream out = new PrintStream(new BufferedOutputStream(System.out));\n\t\n\tint n ;\n\t\n\tpublic void solveProblem() throws IOException {\t\t\n\t\n\t\t\n\t\tn = Int() ;\n\t\tt = System.currentTimeMillis() ;\n\t\tbouwGraaf(n,n-1) ;\n\t\t\n\t\tPoint[] ps = new Point[n];\n\t\t\n\t\tfor( int i = 0 ; i < n ; i++ )\n\t\t\tps[i] = new Point(Long(),Long(),i) ;\n\t\topl = new int[n] ;\n\t\t\n\t\tkind = new int[n][] ;\n\t\tak = new int[n] ;\n\t\tdfs(0,-1) ;\n\t\t\n\t\tint van = 0 ;\n\t\tint tot = n ;\n\t\tint pi = van ;\n\t\tPoint pivot = ps[van] ;\n\t\tfor( int i = van + 1 ; i < tot; i++ ){\n\t\t\tPoint pnu = ps[i] ;\n\t\t\tif( pnu.y < pivot.y || (pnu.y == pivot.y && pnu.x < pivot.x)){\n\t\t\t\tpi = i ;\n\t\t\t\tpivot = ps[i] ;\n\t\t\t}\n\t\t}\n\t\t\n\t\tps[pi] = ps[van] ;\n\t\tps[van] = pivot ;\n\n\t\t\n\t\tlosOp(ps,0,0,n) ;\n\t\twr(opl) ;\n\t}\n\n\n\tprivate int dfs(int u,int p) {\n\t\t\n\t\tint nk = buren[u].size() ;\n\t\tif( p != -1 )\n\t\t\tnk-- ;\n\t\tkind[u] = new int[nk] ;\n\t\t\n\t\tint som = 1 ;\n\t\tint t = 0 ;\n\t\tfor( int v : buren[u] )\n\t\t\tif( v != p ){\n\t\t\t\tkind[u][t++] = v ;\n\t\t\t\tsom += dfs(v,u) ;\n\t\t\t}\n\t\t\n\t\treturn ak[u] = som ;\n\t}\n\n\tint[][] kind ;\n\tint[] ak ;\n\tprivate void losOp(Point[] ps, int u, int van, int tot) {\n\t\t\n\t\tPoint pivot = ps[van] ;\n\t\n\t\tPoint.pivot = pivot ;\n\t\tsort(ps,van+1,tot) ;\n\t\n//\t\tp((u+1),van,tot,pivot.index) ;\n//\t\tp(ps); \n\t\topl[pivot.index] = u + 1 ;\n\t\t\n\t\tint t = van + 1 ;\n\t\tfor( int v : kind[u]){\t\t\t\n\t\t\tlosOp(ps,v,t,t+ak[v]) ;\n\t\t\tt += ak[v] ;\n\t\t}\t\n\t\t\n\t}\n\n\tint[] opl ;\n\n\t\n\tArrayList<Integer>[] buren ;\n\tvoid bouwGraaf(int nv, int ne){\n\t\t\n\t\tburen = new ArrayList[nv] ;\n\t\tfor( int i = 0 ; i < nv ; i++ )\n\t\t\tburen[i] = new ArrayList<Integer>() ;\n\t\t\n\t\tfor( int i = 0 ; i < ne ; i++ ){\n\t\t\tint u = Int() - 1 ;\n\t\t\tint v = Int() - 1 ;\n\t\t\tburen[u].add(v) ;\n\t\t\tburen[v].add(u) ;\n\t\t}\n\t}\n\t\n\t\n\tstatic String Line() throws IOException{\n\t\treturn buf.readLine() ;\n\t}\n\n\tstatic int bufI = 0 ;\n\tstatic int[] bufInts = new int[0] ;\n\t\n\tstatic int Int() {\n\t\tif( bufI == bufInts.length )\n\t\t\tbufReaderNInts() ;\n\t\treturn bufInts[bufI++] ;\n\t}\n\t\n\tstatic int[] Int( int n ) {\n\t\tint[] res = new int[n] ;\n\t\tfor( int i = 0 ; i < n ; i++ )\n\t\t\tres[i] = Int() ;\n\t\treturn res ;\n\t}\n\t\n\tstatic void bufReaderNInts() {\t\t\n\t\tString[] ss;\n\t\ttry {\n\t\t\tss = buf.readLine().split(\" \");\n\t\t\tbufInts = new int[ss.length] ;\n\t\t\tfor( int i = 0 ; i < ss.length ; i++ ){\n\t\t\t\tbufInts[i] = Integer.parseInt(ss[i]) ;\n\t\t\t}\n\t\t\tbufI = 0 ;\n\t\t} catch (IOException e) {\n\t\t\t// TODO Auto-generated catch block\n\t\t\te.printStackTrace();\n\t\t}\n\t\t\n\t}\n\t\n\tstatic int bufL = 0 ;\n\tstatic long[] bufLongs = new long[0] ;\n\t\n\tstatic long Long() {\n\t\tif( bufL == bufLongs.length )\n\t\t\tbufReaderNLongs() ;\n\t\treturn bufLongs[bufL++] ;\n\t}\n\t\n\tstatic long[] Long( int n ) {\n\t\tlong[] res = new long[n] ;\n\t\tfor( int i = 0 ; i < n ; i++ )\n\t\t\tres[i] = Long() ;\n\t\treturn res ;\n\t}\n\t\n\tstatic void bufReaderNLongs(){\t\t\n\t\tString[] ss;\n\t\ttry {\n\t\t\tss = buf.readLine().split(\" \");\n\t\t\tbufLongs = new long[ss.length] ;\n\t\t\tfor( int i = 0 ; i < ss.length ; i++ ){\n\t\t\t\tbufLongs[i] = Long.parseLong(ss[i]) ;\n\t\t\t}\n\t\t\tbufL = 0 ;\n\t\t} catch (IOException e) {\n\t\t\t\n\t\t}\n\t\t\n\t}\n\t\n\tstatic int[] toArray( ArrayList<Integer> lijst ){\n\t\tint[] res = new int[lijst.size()] ;\n\t\tint t = 0 ;\n\t\tfor( int i : lijst)\n\t\t\tres[t++] = i;\n\t\treturn res ;\n\t}\n\t\n\tstatic void p( Object ...p){\n\t\tSystem.out.println(Arrays.deepToString(p));\n\t}\n\t\n\tstatic void wr( int[] rij ){\n\t\tfor( int i = 0 ; i < rij.length - 1 ; i++ ) \n\t\t\tout.print(rij[i] + \" \") ;\n\t\tout.println(rij[rij.length-1]);\n\t\t\n\t}\n\n\tstatic void wr( long[] rij ){\n\t\tfor( int i = 0 ; i < rij.length - 1 ; i++ ) \n\t\t\tout.print(rij[i] + \" \") ;\n\t\tout.println(rij[rij.length-1]);\n\t\t\n\t}\n\t\n\t\n}\nclass Point implements Comparable<Point>{\n\n\tstatic double EPS = 1e-11 ;\n\t\t\n\tlong x ;\n\tlong y ;\n\tint index ;\n\tstatic Point pivot ;\n\tpublic Point(long x, long y, int index) {\n\t\tthis.x = x;\n\t\tthis.y = y;\n\t\tthis.index = index;\n\t}\n\n\t\n\t@Override\n\tpublic int compareTo(Point o) {\n\t\t\n\t\tlong a = (x-pivot.x)*(o.y-pivot.y) - (o.x-pivot.x)*(y-pivot.y) ;\n\t\tif( a > 0 )\treturn -1 ;\n\t\telse if( a == 0 ) return 0 ;\n\t\telse return 1 ;\n\t\t\n\t\t\n\t}\n\n\tprivate double pretty(double v) {\n\t\tv %= 2 * Math.PI;\n\t\tif (v < 0)\n\t\t\tv += 2 * Math.PI;\n\t\treturn v;\n\t}\n\t\n\tpublic String toString(){\n\t\treturn \"[\" + x + \",\" + y + \"]\" ;\n\t}\n}", "src_uid": "d65e91dc274c6659cfdb50bc8b8020ba"} {"source_code": "import java.util.*;\nimport java.io.*;\n\npublic class p926J {\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader f = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\t\tStringTokenizer st;\n\t\tint times = Integer.parseInt(f.readLine());\n\t\tIntervalList list = new IntervalList();\n\t\twhile(times-- > 0)\n\t\t{\n\t\t\tst = new StringTokenizer(f.readLine());\n\t\t\tint s = Integer.parseInt(st.nextToken());\n\t\t\tint e = Integer.parseInt(st.nextToken());\n\t\t\tlist.add(s, e);\n\t\t\tout.println(list.size());\n\t\t}\n\t\tout.close();\n\t}\n\t\n\tstatic class IntervalList\n\t{\n\t\tpublic TreeSet<Interval> set;\n\t\tpublic IntervalList()\n\t\t{\n\t\t\tset = new TreeSet<Interval>();\n\t\t}\n\t\t\n\t\tpublic void add(int s, int e)\n\t\t{\n\t\t\tIterator<Interval> iter = set.tailSet(new Interval(s, s), true).iterator();\n\t\t\twhile(iter.hasNext())\n\t\t\t{\n\t\t\t\tInterval i = iter.next();\n\t\t\t\tif(i.s > e)\n\t\t\t\t\tbreak;\n\t\t\t\tif(i.s < s)\n\t\t\t\t\ts = i.s;\n\t\t\t\tif(i.e > e)\n\t\t\t\t\te = i.e;\n\t\t\t\titer.remove();\n\t\t\t}\n\t\t\tset.add(new Interval(s, e));\n\t\t}\n\t\t\n\t\tpublic int size()\n\t\t{\n\t\t\treturn set.size();\n\t\t}\n\t}\n\t\n\tstatic class Interval implements Comparable<Interval>\n\t{\n\t\tint s, e;\n\t\tpublic Interval(int s, int e)\n\t\t{\n\t\t\tthis.s = s;\n\t\t\tthis.e = e;\n\t\t}\n\t\t\n\t\tpublic int compareTo(Interval i)\n\t\t{\n\t\t\treturn e - i.e;\n\t\t}\n\t\t\n\t\tpublic String toString()\n\t\t{\n\t\t\treturn s + \" \" + e;\n\t\t}\n\t}\n}", "src_uid": "3979abbe7bad0f3b5cab15c1cba19f6b"} {"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 ExpectedEarnings solver = new ExpectedEarnings();\n solver.solve(1, in, out);\n out.close();\n }\n static class ExpectedEarnings {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int n = in.nextInt(), X = in.nextInt();\n double c = X / 1_000_000.0;\n double[] cprob = new double[n + 1];\n for (int i = 0; i <= n; i++) {\n cprob[i] = in.nextInt();\n }\n double[] dp = new double[n + 1];\n for (int nballs = n - 1; nballs >= 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}", "src_uid": "44149b73a6b707c10c3eee75b5e090d2"} {"source_code": "import java.io.*;\nimport java.lang.reflect.Array;\nimport java.math.BigInteger;\nimport java.util.*;\n \n \npublic class q5 {\n\t\n\t\n \n\tpublic static void main(String[] args) throws IOException {\n\t\n\t\tReader.init(System.in);\n\t\tPrintWriter out=new PrintWriter(System.out);\n\t\tint x=Reader.nextInt(),y=Reader.nextInt(),z=Reader.nextInt();\n\t\tint x1=Reader.nextInt(),y1=Reader.nextInt(),z1=Reader.nextInt();\n\t\tint v1=Reader.nextInt(),v2=Reader.nextInt(),v3=Reader.nextInt();\n\t\tint v4=Reader.nextInt(),v5=Reader.nextInt(),v6=Reader.nextInt();\n\t\tlong ans=0;\n\t\tif(y<0) ans+=v1;\n\t\telse if(y>y1) ans+=v2;\n\t\tif(z<0) ans+=v3;\n\t\telse if(z>z1) ans+=v4;\n\t\tif(x<0) ans+=v5;\n\t\telse if(x>x1) ans+=v6;\n\t\tout.print(ans);\n\t\tout.flush();\n\t}\n}\n\n\n\n\n \n \nclass Reader {\n static BufferedReader reader;\n static StringTokenizer tokenizer;\n /** call this method to initialize reader for InputStream */\n static void init() throws IOException {\n \t reader = new BufferedReader(\n new FileReader(\"input.txt\"));\n tokenizer = new StringTokenizer(\"\");\n }\n static void init(InputStream input) {\n reader = new BufferedReader(\n new InputStreamReader(input) );\n tokenizer = new StringTokenizer(\"\");\n }\n /** get next word */\n static String nextLine() throws IOException{\n \treturn reader.readLine();\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 static int nextInt() throws IOException {\n return Integer.parseInt( next() );\n }\n static long nextLong() throws IOException {\n return Long.parseLong( next() );\n }\n static double nextDouble() throws IOException {\n return Double.parseDouble( next() );\n }\n}", "src_uid": "c7889a8f64c57cf7be4df870f68f749e"} {"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 long b, c=0, i;\n b = in.nextLong();\n \n for (i = 1; i * i <= b; i++) {\n if (b % i == 0) {\n \t c += 2;\n }\n if (i * i == b) {\n \t c--;\n }\n } \n \n System.out.println(c);\n }\n}", "src_uid": "7fc9e7d7e25ab97d8ebc10ed8ae38fd1"} {"source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class C {\n\n long mod = 1000000007;\n long memo[] = new long[101];\n long memoNot[] = new long[101];\n int n;\n int k;\n int d;\n \n long go(int curr, boolean contains, String space) {\n //System.out.println(space + curr + \" \" + contains);\n if (curr < 0) return 0;\n if (curr == 0 && contains) return 1;\n if (curr == 0 && !contains) return 0;\n if (memo[curr] > -1 && contains)\n return memo[curr];\n if (memoNot[curr] > -1 && !contains)\n return memoNot[curr];\n \n long ans = 0;\n for (int i = 1; curr - i >= 0 && i <= k; i++) {\n ans += go(curr - i, ((i >= d) ? true : contains), space + \" \");\n }\n \n ans = ans % mod;\n if (contains)\n memo[curr] = ans;\n else\n memoNot[curr] = ans;\n return ans;\n \n }\n \n \n public void solve() {\n Scanner sc = new Scanner(System.in);\n n = sc.nextInt();\n k = sc.nextInt();\n d = sc.nextInt();\n \n Arrays.fill(memo, -1);\n Arrays.fill(memoNot, -1);\n \n System.out.println(go(n, false, \"\") % mod);\n }\n \n public static void main(String[] args) {\n new C().solve();\n }\n\n}\n", "src_uid": "894a58c9bba5eba11b843c5c5ca0025d"} {"source_code": "\nimport java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args)throws Exception\n {\n\n Scanner scanner=new Scanner(System.in);\n long n=scanner.nextLong();\n long m=scanner.nextLong();\n long build=scanner.nextLong();\n long dem=scanner.nextLong();\n long rem=n%m;\n long a=rem*dem;\n long b=(m-rem)*build;\n if (a>b)\n {\n System.out.println(b);\n }\n else\n {\n System.out.println(a);\n }\n\n\n }\n}\n", "src_uid": "c05d753b35545176ad468b99ff13aa39"} {"source_code": "import java.io.*;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.StringTokenizer;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class swap_prefixes_av_n {\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 SwapPrefixesDp solver = new SwapPrefixesDp();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class SwapPrefixesDp {\n public void solve(int testNumber, FastScanner in, PrintWriter out) {\n String s = in.next(), t = in.next();\n List<Integer> ans1 = solve(\"a\" + s, \"b\" + t);\n List<Integer> ans2 = solve(\"b\" + s, \"a\" + t);\n if (ans1.size() > ans2.size()) {\n ans1 = ans2;\n }\n out.println(ans1.size() / 2);\n for (int i = 0; i < ans1.size(); i += 2) {\n out.println(ans1.get(i) + \" \" + ans1.get(i + 1));\n }\n }\n\n private void makeSwap(List<Integer> realAns, List<Pair> compressedS, List<Pair> compressedT, int lenS, int lenT) {\n List<Pair> newS = new ArrayList<>();\n List<Pair> newT = new ArrayList<>();\n\n int realLenS = 0, realLenT = 0;\n for (int i = 0; i < lenS; i++) {\n realLenS += compressedS.get(i).count;\n }\n for (int i = 0; i < lenT; i++) {\n realLenT += compressedT.get(i).count;\n }\n realAns.add(realLenS - 1);\n realAns.add(realLenT - 1);\n concatLists(compressedS, compressedT, lenS, lenT, newS);\n concatLists(compressedT, compressedS, lenT, lenS, newT);\n compressedS.clear();\n compressedS.addAll(newS);\n compressedT.clear();\n compressedT.addAll(newT);\n }\n\n private void concatLists(List<Pair> compressedS, List<Pair> compressedT, int lenS, int lenT, List<Pair> newS) {\n newS.addAll(compressedT.subList(0, lenT));\n newS.addAll(compressedS.subList(lenS, compressedS.size()));\n if (lenT < newS.size() && newS.get(lenT - 1).ch == newS.get(lenT).ch) {\n newS.get(lenT - 1).count += newS.get(lenT).count;\n newS.remove(lenT);\n }\n }\n\n private List<Integer> solve(String s, String t) {\n List<Pair> compressedS = compress(s);\n List<Pair> compressedT = compress(t);\n if (compressedS.size() == 1 && compressedT.size() == 1) {\n return new ArrayList<>();\n }\n int curI = compressedS.size(), curJ = compressedT.size();\n\n int bestI = -1, bestJ = -1;\n int bestCost = Integer.MAX_VALUE;\n\n for (int lenI = 1; lenI <= compressedS.size(); lenI++) {\n for (int lenJ = 1; lenJ <= compressedT.size(); lenJ++) {\n if (lenI % 2 != lenJ % 2) {\n continue;\n }\n if (lenI > 3 && lenJ > 3) {\n break;\n }\n int nextI = lenJ + (curI - lenI) - ((curI != lenI && lenJ % 2 == lenI % 2) ? 1 : 0);\n int nextJ = lenI + (curJ - lenJ) - ((curJ != lenJ && lenJ % 2 == lenI % 2) ? 1 : 0);\n\n int cost = 1 + Math.max(nextI, nextJ);\n if (cost < bestCost) {\n bestCost = cost;\n bestI = lenI;\n bestJ = lenJ;\n }\n }\n }\n\n List<Integer> ans = new ArrayList<>();\n makeSwap(ans, compressedS, compressedT, bestI, bestJ);\n\n int nextI = compressedS.size(), nextJ = compressedT.size();\n\n int prefixA = 0, prefixB = 0;\n for (int i = 0; i < Math.max(nextI, nextJ) - 1; i++) {\n if (i % 2 == 0) {\n prefixA += i >= compressedS.size() ? 0 : compressedS.get(i).count;\n prefixB += i >= compressedT.size() ? 0 : compressedT.get(i).count;\n ans.add(prefixA - 1);\n ans.add(prefixB - 1);\n } else {\n prefixA += i >= compressedT.size() ? 0 : compressedT.get(i).count;\n prefixB += i >= compressedS.size() ? 0 : compressedS.get(i).count;\n ans.add(prefixB - 1);\n ans.add(prefixA - 1);\n }\n }\n\n return ans;\n }\n\n private List<Pair> compress(String s) {\n List<Pair> result = new ArrayList<>();\n for (int i = 0; i < s.length(); ) {\n int j = i;\n while (j < s.length() && s.charAt(i) == s.charAt(j)) {\n j++;\n }\n result.add(new Pair(s.charAt(i), j - i));\n i = j;\n// System.err.println(result);\n }\n return result;\n }\n\n class Pair {\n char ch;\n int count;\n\n public Pair(char ch, int count) {\n this.ch = ch;\n this.count = count;\n }\n\n @Override\n public String toString() {\n return \"Pair{\" +\n \"ch=\" + ch +\n \", count=\" + count +\n '}';\n }\n }\n\n }\n\n static class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(InputStream in) {\n br = new BufferedReader(new InputStreamReader(in));\n }\n\n public String next() {\n while (st == null || !st.hasMoreElements()) {\n String line = null;\n try {\n line = br.readLine();\n } catch (IOException e) {\n }\n st = new StringTokenizer(line);\n }\n return st.nextToken();\n }\n\n }\n}\n\n", "src_uid": "4a50c4147becea13946272230f3dde6d"} {"source_code": "//package codeforces.R462;\n\nimport 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\n\npublic class D\n{\n\tpublic static void main(String[] args) throws IOException\n\t{\n\t\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter pw = new PrintWriter(System.out);\n\t\t\n\t\tlong p = sc.nextLong();\n\t\tint k = sc.nextInt();\n\t\tlong[] arr = new long[1000];\n\t\tboolean neg = true;\n\t\tlong cur = p;\n\t\tfor (int i = 0; i < 100; i++)\n\t\t{\n\t\t\tif(cur == 0)\n\t\t\t\tbreak;\n\t\t\tlong res = 0;\n\t\t\tif(neg)\n\t\t\t\tres = cur/k;\n\t\t\telse\n\t\t\t\tres = (cur+k-1)/k;\n\t\t\tarr[i] = res;\n\t\t\tcur = arr[i];\n\t\t\tneg = neg?false:true;\n\t\t}\n\t\t\n\t\tBigInteger[] ans = new BigInteger[100];\n\t\tfor (int i = 0; i < ans.length; i++)\n\t\t{\n\t\t\tBigInteger v1 = BigInteger.valueOf(arr[i]);\n\t\t\tv1 = v1.multiply(BigInteger.valueOf(k));\n\t\t\tBigInteger v2 = BigInteger.ZERO;\n\t\t\tif(i > 0)\n\t\t\t\tv2 = v2.add(BigInteger.valueOf(arr[i-1]));\n\t\t\t\n\t\t\tif(i%2 == 0)\n\t\t\t\tv1 = v1.multiply(BigInteger.valueOf(-1));\n\t\t\tif(i > 0 && (i-1)%2 == 0)\n\t\t\t\tv2 = v2.multiply(BigInteger.valueOf(-1));\n\t\t\tv1 = v1.add(v2);\n\t\t\tans[i] = v1;\n\t\t}\n\t\t\n\t\tans[0] = ans[0].add(BigInteger.valueOf(p));\n\t\t\n\t\tint lst = 0;\n\t\tboolean ok = true;\n\t\tfor (int i = 0; i < 100; i++)\n\t\t{\n\t\t\tif(!ans[i].equals(new BigInteger(\"0\")))\n\t\t\t\tlst = i;\n\t\t\tif(ans[i].compareTo(BigInteger.valueOf(k)) != -1)\n\t\t\t\tok = false;\n\t\t}\n\t\t\n\t\tif(!ok)\n\t\t\tSystem.out.println(-1);\n\t\telse\n\t\t{\n\t\t\tpw.println(lst+1);\n\t\t\tfor (int i = 0; i <= lst; i++)\n\t\t\t{\n\t\t\t\tpw.print(ans[i] + \" \");\n\t\t\t}\n\t\t\tpw.println();\n\t\t\t\n\t\t}\n\t\t\n\t\tpw.flush();\n\t\tpw.close();\n\t}\n\t\n\t\n\tstatic int[][] packD(int n, int[] from, int[] to) {\n\t\tint[][] g = new int[n][];\n\t\tint[] p = new int[n];\n\t\tfor (int f : from) p[f]++;\n\t\tfor (int i = 0; i < n; i++) g[i] = new int[p[i]];\n\t\tfor (int i = 0; i < from.length; i++) {g[from[i]][--p[from[i]]] = to[i];}\n\t\treturn g;\n\t}\n\tstatic class Scanner \n\t{\n\t\tStringTokenizer st; BufferedReader br;\n\t\tpublic Scanner(InputStream s){\tbr = new BufferedReader(new InputStreamReader(s));}\n\t\tpublic String next() throws IOException {while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());return st.nextToken();}\n\t\tpublic int nextInt() throws IOException {return Integer.parseInt(next());}\n\t\tpublic long nextLong() throws IOException {return Long.parseLong(next());}\n\t\tpublic String nextLine() throws IOException {return br.readLine();}\n\t\tpublic boolean ready() throws IOException {return br.ready();}\n\t}\n}\n", "src_uid": "f4dbaa8deb2bd5c054fe34bb83bc6cd5"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\n static long maxCnt = 0, maxX = 0;\n\n static void calc(long m, long cnt, long x) {\n if (m <= 7) {\n cnt += m;\n x += m;\n\n if (cnt > maxCnt || (cnt == maxCnt && x > maxX)) {\n maxCnt = cnt;\n maxX = x;\n }\n return;\n }\n\n long a = (long) Math.floor(Math.pow(m, 1.0 / 3));\n calc(m - (long) Math.pow(a, 3), cnt + 1, x + (long) Math.pow(a, 3));\n calc((long) Math.pow(a, 3) - 1 - (long) Math.pow(a - 1, 3), cnt + 1, x + (long) Math.pow(a - 1, 3));\n }\n\n static void solve(InputReader in, OutputWriter out) {\n long m = in.nextLong();\n calc(m, 0, 0);\n out.print(maxCnt + \" \" + maxX);\n }\n\n public static void main(String[] args) {\n InputReader in = new InputReader(System.in);\n OutputWriter out = new OutputWriter(System.out);\n solve(in, out);\n in.close();\n out.close();\n }\n\n static class InputReader {\n BufferedReader br;\n StringTokenizer st;\n\n InputReader(InputStream is) {\n br = new BufferedReader(new InputStreamReader(is));\n st = null;\n }\n\n String nextLine() {\n String line = null;\n try {\n line = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return line;\n }\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n String line = nextLine();\n if (line == null) return null;\n st = new StringTokenizer(line);\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 void close() {\n try {\n br.close();\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n }\n\n static class OutputWriter {\n BufferedWriter bw;\n\n OutputWriter(OutputStream os) {\n bw = new BufferedWriter(new OutputStreamWriter(os));\n }\n\n void print(int i) {\n print(Integer.toString(i));\n }\n\n void println(int i) {\n println(Integer.toString(i));\n }\n\n void print(long l) {\n print(Long.toString(l));\n }\n\n void println(long l) {\n println(Long.toString(l));\n }\n\n void print(double d) {\n print(Double.toString(d));\n }\n\n void println(double d) {\n println(Double.toString(d));\n }\n\n void print(boolean b) {\n print(Boolean.toString(b));\n }\n\n void println(boolean b) {\n println(Boolean.toString(b));\n }\n\n void print(char c) {\n try {\n bw.write(c);\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n\n void println(char c) {\n println(Character.toString(c));\n }\n\n void print(String s) {\n try {\n bw.write(s);\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n\n void println(String s) {\n print(s);\n print('\\n');\n }\n\n void close() {\n try {\n bw.close();\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n }\n}\n", "src_uid": "385cf3c40c96f0879788b766eeb25139"} {"source_code": "import java.util.*;\r\nimport java.lang.*;\r\nimport java.io.*;\r\n\r\n\r\npublic class Main\r\n\r\n{\r\n class Pair<S extends Comparable<S>, T extends Comparable<T>> implements Comparable<Pair<S, T>>\r\n {\r\n S first;\r\n T second;\r\n\r\n Pair(S f, T s)\r\n {\r\n first = f;\r\n second = s;\r\n }\r\n\r\n @Override\r\n public int compareTo(Pair<S, T> o)\r\n {\r\n int t = first.compareTo(o.first);\r\n if (t == 0) return second.compareTo(o.second);\r\n return t;\r\n }\r\n\r\n @Override\r\n public int hashCode()\r\n {\r\n return (31 + first.hashCode()) * 31 + second.hashCode();\r\n }\r\n\r\n @Override\r\n public boolean equals(Object o)\r\n {\r\n if (!(o instanceof Pair)) return false;\r\n if (o == this) return true;\r\n Pair p = (Pair) o;\r\n return first.equals(p.first) && second.equals(p.second);\r\n }\r\n\r\n @Override\r\n public String toString()\r\n {\r\n return \"Pair{\" + first + \", \" + second + \"}\";\r\n }\r\n }\r\n static class FastReader\r\n {\r\n BufferedReader br;\r\n StringTokenizer st;\r\n\r\n public FastReader()\r\n {\r\n br = new BufferedReader(new\r\n InputStreamReader(System.in));\r\n }\r\n\r\n String next()\r\n {\r\n while (st == null || !st.hasMoreElements())\r\n {\r\n try\r\n {\r\n st = new StringTokenizer(br.readLine());\r\n }\r\n catch (IOException e)\r\n {\r\n e.printStackTrace();\r\n }\r\n }\r\n return st.nextToken();\r\n }\r\n\r\n int nextInt()\r\n {\r\n return Integer.parseInt(next());\r\n }\r\n\r\n long nextLong()\r\n {\r\n return Long.parseLong(next());\r\n }\r\n\r\n double nextDouble()\r\n {\r\n return Double.parseDouble(next());\r\n }\r\n\r\n String nextLine()\r\n {\r\n String str = \"\";\r\n try\r\n {\r\n str = br.readLine();\r\n }\r\n catch (IOException e)\r\n {\r\n e.printStackTrace();\r\n }\r\n return str;\r\n }\r\n }\r\n public static void main (String[] args) throws java.lang.Exception\r\n {\r\n try\r\n {\r\n System.setIn(new FileInputStream(\"input.txt\"));\r\n System.setOut(new PrintStream(new FileOutputStream(\"output.txt\")));\r\n }\r\n catch (Exception e)\r\n {\r\n System.err.println(\"Error\");\r\n }\r\n\r\n FastReader sc = new FastReader();\r\n\r\n int t = sc.nextInt();\r\n PrintWriter out = new PrintWriter(System.out);\r\n while(t-- > 0)\r\n {\r\n solve(sc, out);\r\n }\r\n out.close();\r\n }\r\n static void solve(FastReader sc, PrintWriter out)\r\n {\r\n long n = sc.nextLong();\r\n long k = sc.nextInt();\r\n\r\n\r\n \r\n \r\n out.println(binpow(n,k));\r\n\r\n\r\n }\r\n static long binpow(long a, long b)\r\n {\r\n long m = 1000000007;\r\n long res = 1;\r\n while (b > 0)\r\n {\r\n if (b %2== 1)\r\n res = res * a % m;\r\n a = a * a % m;\r\n b >>= 1;\r\n }\r\n return res % m;\r\n }\r\n}", "src_uid": "2e7a9f3a97938e4a7e036520d812b97a"} {"source_code": "import java.util.*;\n\npublic class C {\n\t\n\tpublic static void main(String[] args) {\n\t\t\n\t\tScanner qwe = new Scanner(System.in);\n\t\t\n\t\tint N = qwe.nextInt();\n\t\tString[] cards = new String[N];\n\t\tfor (int i = 0; i < cards.length; i++) {\n\t\t\tcards[i] = qwe.next();\n\t\t}\n\t\t\n\t\tint min = 11;\n\t\tchar[] colorsnums = {'R', 'G', 'B', 'Y', 'W','1','2','3','4','5'};\n\t\t\n\t\tfor(int bm = 0; bm < (1 << 10); bm++){\n\t\t\tint bc = Integer.bitCount(bm);\n\t\t\tif(bc >= min) continue;\n\t\t\t\n\t\t\tint dex =0;\n\t\t\tHashSet<Character> cp = new HashSet<Character>();\n\t\t\tfor(int i = 1; i <= bm; i <<= 1,dex++){\n\t\t\t\tif((i & bm) == i) cp.add(colorsnums[dex]);\n\t\t\t}\n\t\t\t\n\t\t\tboolean good = true;\n\t\t\t\n\t\t\tfor(int i =0; i < cards.length; i++){\n\t\t\t\tfor(int j = i+1; j < cards.length; j++){\n\t\t\t\t\tif(cards[i].equals(cards[j])) continue;\n\t\t\t\t\tboolean canTellApart = false;\n\t\t\t\t\tif(cards[i].charAt(0) != cards[j].charAt(0)\n\t\t\t\t\t\t\t&& (cp.contains(cards[i].charAt(0)) || cp.contains(cards[j].charAt(0)) ) ) \n\t\t\t\t\t\tcanTellApart = true;\n\t\t\t\t\tif(cards[i].charAt(1) != cards[j].charAt(1)\n\t\t\t\t\t\t\t&& (cp.contains(cards[i].charAt(1)) || cp.contains(cards[j].charAt(1)) ) ) \n\t\t\t\t\t\tcanTellApart = true;\n\t\t\t\t\t\n\t\t\t\t\tif(!canTellApart) good = false;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif(good){\n\t\t\t\t//System.out.println(cp);\n\t\t\t\tmin = bc;\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\tSystem.out.println(min);\n\t\t\n\t\tqwe.close();\n\t}\n\n}\n", "src_uid": "3b12863997b377b47bae43566ec1a63b"} {"source_code": "//package af2017;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class D {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint[] dual = {\n\t\t\t\t8, -1, -1, 3, 6, 9, 4, 7, 0, 5\n\t\t};\n\t\tchar[] s = ns().toCharArray();\n\t\tfor(int i = 0, j = s.length-1;i <= j;i++,j--){\n\t\t\tif(dual[s[i]-'0'] != s[j]-'0'){\n\t\t\t\tout.println(\"No\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tout.println(\"Yes\");\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception { new D().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "src_uid": "0f11f41cefd7cf43f498e511405426c3"} {"source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.StringTokenizer;\nimport java.util.Vector;\n\npublic class Test {\n\t\n\tstatic int n, m, k, t;\n\tstatic int[] deg = new int[501];\n\tstatic int[] w1 = new int[501];\n\tstatic int[] w2 = new int[501];\n\tstatic int[][] f = new int[50001][201];\n\tstatic int[][] index = new int[50001][201];\n\tstatic int[] color = new int[5001];\n\tstatic void alter(int y, int c1, int c2)\n\t{\n\t\t//swap f[y][c1] and f[y][c2]\n\t\tint temp = f[y][c1];\n\t\tf[y][c1] = f[y][c2];\n\t\tf[y][c2] = temp;\n\t\ttemp = index[y][c1];\n\t\tindex[y][c1] = index[y][c2];\n\t\tindex[y][c2] = temp;\n\t\tcolor[index[y][c2]] = c2;\n\t\tif(f[y][c2] != 0) alter(f[y][c2], c2, c1);\n\t}\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\tPrintWriter writer = new PrintWriter(System.out);\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tint n = Integer.parseInt(st.nextToken());\n\t\tint m = Integer.parseInt(st.nextToken());\n\t\tint k = Integer.parseInt(st.nextToken());\n\t\tint t = Integer.parseInt(st.nextToken());\n\t\tint cnt = 0;\n\t\tfor(int i = 1; i <= k; i++)\n\t\t{\n\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\tint a = Integer.parseInt(st.nextToken());\n\t\t\tint b = Integer.parseInt(st.nextToken());\n\t\t\tif(deg[a]%t == 0) w1[a] = ++cnt;\n\t\t\tif(deg[n+b]%t == 0) w2[n+b] = ++cnt;\n\t\t\t++deg[a];\n\t\t\t++deg[n+b];\n\t\t\tint x = w1[a];\n\t\t\tint y = w2[n+b];\n\t\t\tint c1 = -1;\n\t\t\tint c2 = -1;\n\t\t\tfor(int j = 1; j <= t; j++) if(f[x][j] == 0) { c1 = j; break; }\n\t\t\tfor(int j = 1; j <= t; j++) if(f[y][j] == 0) { c2 = j; break; }\n\t\t\t\n\t\t\tif(f[y][c1] != 0) alter(y, c1, c2);\n\t\t\tf[x][c1] = y;\n\t\t\tf[y][c1] = x;\n\t\t\tindex[x][c1] = i;\n\t\t\tindex[y][c1] = i;\n\t\t\tcolor[i] = c1;\n\t\t}\n\t\tint uneven = 0;\n\t\tfor(int i = 1; i <= n; i++) if(deg[i]%t != 0) uneven++;\n\t\tfor(int i = n+1; i <= n+m; i++) if(deg[i]%t != 0) uneven++;\n\t\twriter.println(uneven);\n\t\tfor(int i = 1; i <= k; i++) writer.print(color[i]+\" \");\n\t\tbr.close();\n\t\twriter.close();\n\t}\n\n}\n", "src_uid": "99b97aabec566e5f966777947271ad3c"} {"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.util.ArrayList;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Preet\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 long n = in.nextLong();\n\n ArrayList<Long> primes = new ArrayList<>();\n int m = (int) 1e6;\n boolean notPrime[] = new boolean[m];\n for (int i = 2; i < m; i++) {\n if (!notPrime[i]) {\n primes.add((long) i);\n for (int j = 2 * i; j < m; j += i) {\n notPrime[j] = true;\n }\n }\n }\n\n long res = 1;\n\n for (Long l : primes) {\n if (n % l == 0) {\n if (n % 2L != 0) {\n n -= l;\n res += (n / 2L);\n break;\n } else {\n res = (n / l);\n break;\n }\n }\n }\n\n out.println(res);\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\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 }\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\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", "src_uid": "a1e80ddd97026835a84f91bac8eb21e6"} {"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 for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n if (i != j && !a[i][j]) {\n if (color[i] == 1 - color[j]) {\n foundError = true;\n break;\n }\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", "src_uid": "e71640f715f353e49745eac5f72e682a"} {"source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Iterator;\nimport java.util.Collection;\nimport java.util.Set;\nimport java.util.HashMap;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.util.HashSet;\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 *\n * @author Ribhav\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastReader in = new FastReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n DNavigationSystem solver = new DNavigationSystem();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class DNavigationSystem {\n public void solve(int testNumber, FastReader s, PrintWriter out) {\n int n = s.nextInt();\n int m = s.nextInt();\n DNavigationSystem.Graph g = new DNavigationSystem.Graph(n, true, false);\n g.takeInput(m, s);\n// out.println(g.neighbours);\n int size = s.nextInt();\n int[] arr = s.nextIntArray(size);\n int src = arr[size - 1];\n int dest = arr[0];\n// g.neighbours.remove(dest);\n HashMap<Integer, HashSet<Integer>> parent = new HashMap<>();\n HashMap<Integer, Integer> distance = new HashMap<>();\n HashSet<Integer> visited = new HashSet<>();\n Queue<Integer> q = new LinkedList<>();\n q.add(src);\n visited.add(src);\n distance.put(src, 0);\n HashMap<Integer, HashMap<Integer, Long>> neighbours = g.neighbours;\n while (!q.isEmpty()) {\n int curr = q.poll();\n HashMap<Integer, Long> neighb = neighbours.getOrDefault(curr, new HashMap<>());\n Iterator<Integer> iter = neighb.keySet().iterator();\n int currD = distance.get(curr);\n while (iter.hasNext()) {\n int next = iter.next();\n if (!visited.contains(next)) {\n distance.put(next, currD + 1);\n visited.add(next);\n HashSet<Integer> list = new HashSet<>();\n list.add(curr);\n parent.put(next, list);\n q.add(next);\n } else {\n if (distance.get(next) == currD + 1) {\n HashSet<Integer> list = parent.get(next);\n list.add(curr);\n parent.put(next, list);\n } else if (distance.get(next) > currD + 1) {\n HashSet<Integer> list = parent.get(next);\n list.clear();\n list.add(curr);\n distance.put(next, currD + 1);\n parent.put(next, list);\n }\n }\n }\n\n }\n\n// out.println(parent);\n\n int worst = 0;\n int best = 0;\n for (int i = 0; i < size - 1; i++) {\n int next = arr[i + 1];\n int curr = arr[i];\n\n HashSet<Integer> set = parent.get(curr);\n if (set.contains(next)) {\n if (set.size() != 1) {\n best++;\n }\n } else {\n worst++;\n best++;\n }\n }\n out.println(worst + \" \" + best);\n }\n\n private static class Graph {\n HashMap<Integer, HashMap<Integer, Long>> neighbours;\n int numVertices;\n boolean isDirected;\n boolean isWeighted;\n\n public Graph(int numVertices, boolean isDirected, boolean isWeighted) {\n neighbours = new HashMap<>();\n this.numVertices = numVertices;\n this.isDirected = isDirected;\n this.isWeighted = isWeighted;\n }\n\n public void takeInput(int n, FastReader s) {\n for (int i = 0; i < n; i++) {\n int dest = s.nextInt();\n int src = s.nextInt();\n\n// if (dest == )\n long wt;\n if (isWeighted) {\n wt = s.nextLong();\n } else {\n wt = 1;\n }\n HashMap<Integer, Long> list = neighbours.getOrDefault(src, new HashMap<>());\n list.put(dest, wt);\n neighbours.put(src, list);\n if (!isDirected) {\n list = neighbours.getOrDefault(dest, new HashMap<>());\n list.put(src, wt);\n neighbours.put(dest, list);\n }\n }\n }\n\n }\n\n }\n\n static class FastReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private FastReader.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 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 int[] nextIntArray(int n) {\n int[] array = new int[n];\n for (int i = 0; i < n; ++i) array[i] = nextInt();\n return array;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n}\n\n", "src_uid": "19a0c05eb2d1559ccfe60e210c6fcd6a"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class intro{\n\tpublic static void main(String[] args) throws IOException{\n\t\tBufferedReader vod=new BufferedReader(new InputStreamReader(System.in));\n\t\tint n=Integer.parseInt(vod.readLine());\n\t\tchar[] mas=vod.readLine().toCharArray();\n\t\tint ans=0;\n\t\tfor (int i=0; i<n; i++){\n\t\t\tint a=0,b=0;\n\t\t\tfor (int j=i; j<n; j++){\n\t\t\t\tif (mas[j]=='U') a++;\n\t\t\t\tif (mas[j]=='D') a--;\n\t\t\t\tif (mas[j]=='L') b--;\n\t\t\t\tif (mas[j]=='R') b++;\n\t\t\t\tif ((a==0)&(b==0)) ans++; \n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}", "src_uid": "7bd5521531950e2de9a7b0904353184d"} {"source_code": "\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class A {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter pr = new PrintWriter(System.out);\n\t\tint n = sc.nextInt();\n\t\tint k = sc.nextInt();\n\t\tdouble f = (double) (Math.floor((n * 1.0) / k)) + 1;\n\t\tSystem.out.println((int) f * k);\n\n\t}\n\n\tstatic class Scanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(s));\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic String nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tpublic double nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tpublic boolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t}\n}\n", "src_uid": "75f3835c969c871a609b978e04476542"} {"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.ArrayList;\nimport java.io.UncheckedIOException;\nimport java.util.List;\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 CUpgradingTree solver = new CUpgradingTree();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class CUpgradingTree {\n List<int[]> seq = new ArrayList<>(200000);\n List<Node> centers = new ArrayList<>();\n Node top;\n Node target;\n Node last;\n\n public void solve(int testNumber, FastInput in, FastOutput out) {\n int n = in.readInt();\n Node[] nodes = new Node[n];\n for (int i = 0; i < n; i++) {\n nodes[i] = new Node();\n nodes[i].id = i;\n }\n for (int i = 0; i < n - 1; i++) {\n Node a = nodes[in.readInt() - 1];\n Node b = nodes[in.readInt() - 1];\n a.adj.add(b);\n b.adj.add(a);\n }\n\n dfsForSize(nodes[0], null);\n dfsForCenter(nodes[0], null, nodes[0].size);\n if (centers.size() == 2) {\n Node a = centers.get(0);\n Node b = centers.get(1);\n a.adj.remove(b);\n b.adj.remove(a);\n }\n\n for (Node center : centers) {\n for (Node node : center.adj) {\n top = center;\n target = node;\n last = node;\n dfs(node, center);\n focus(target);\n }\n }\n\n out.println(seq.size());\n for (int[] s : seq) {\n for (int x : s) {\n out.append(x + 1).append(' ');\n }\n out.println();\n }\n }\n\n public void dfsForSize(Node root, Node p) {\n root.size = 1;\n for (Node node : root.adj) {\n if (node == p) {\n continue;\n }\n dfsForSize(node, root);\n root.size += node.size;\n }\n }\n\n public void dfsForCenter(Node root, Node p, int total) {\n int max = total - root.size;\n for (Node node : root.adj) {\n if (node == p) {\n continue;\n }\n max = Math.max(node.size, max);\n dfsForCenter(node, root, total);\n }\n if (max * 2 <= total) {\n centers.add(root);\n }\n }\n\n public void add(Node x, Node y, Node yy) {\n seq.add(new int[]{x.id, y.id, yy.id});\n }\n\n public void focus(Node next) {\n if (next == last) {\n return;\n }\n add(top, last, next);\n last = next;\n }\n\n public void dfs(Node root, Node p) {\n for (Node node : root.adj) {\n if (node == p) {\n continue;\n }\n dfs(node, root);\n }\n\n if (root != target && p != target) {\n focus(root);\n add(root, p, target);\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, 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 Node {\n List<Node> adj = new ArrayList<>();\n int id;\n int size;\n\n public String toString() {\n return \"\" + id;\n }\n\n }\n}\n\n", "src_uid": "32fdea91454384b103f52743c1128cfc"} {"source_code": "\n\n\n\n \nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n \n/**\n *\n * @author brown\n */\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.List;\n \npublic class Missbo {\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n String[] papu = (br.readLine()).split(\" \");\n long limit = Long.parseLong(papu[0]);\n long counter = Long.parseLong(papu[1]);\n \n if (counter <= (limit + 1) / 2)\n\t {\n \tSystem.out.println(counter*2 - 1);\n }\n \telse\n \t{\n \t\tSystem.out.println((counter - (limit + 1) / 2) * 2 );\n \t}\n }\n}", "src_uid": "1f8056884db00ad8294a7cc0be75fe97"} {"source_code": "\nimport java.util.Scanner;\n\npublic class Polyline {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int x1 = sc.nextInt(), y1 = sc.nextInt(),\n x2 = sc.nextInt(), y2 = sc.nextInt(),\n x3 = sc.nextInt(), y3 = sc.nextInt();\n sc.close();\n int result = 1;\n if ((x1 == x2 && x2 == x3) || (y1 == y2 && y2 == y3)) result = 1;\n else\n if ((x1 == x2 && !between(y3, y1, y2)) ||\n (x2 == x3 && !between(y1, y3, y2)) ||\n (x1 == x3 && !between(y2, y1, y3)) ||\n (y1 == y2 && !between(x3, x1, x2)) ||\n (y2 == y3 && !between(x1, x2, x3)) ||\n (y3 == y1 && !between(x2, x1, x3))) result = 2;\n else result = 3;\n System.out.println(result);\n }\n\n static boolean between(int a, int b, int c) {\n int min = Math.min(b, c), max = Math.max(b, c);\n return a > min && a < max;\n }\n\n}\n", "src_uid": "36fe960550e59b046202b5811343590d"} {"source_code": "// Author @ BlackRise :) //\n// Birla Institute of Technology, Mesra//\nimport java.io.*;\nimport java.util.*;\n\npublic class ehabAndCounstructionProblem {\n static Calendar ts, te; //For time calculation\n static int mod9 = (int) 1e9 + 7;\n static Lelo input = new Lelo(System.in);\n static PrintWriter pw = new PrintWriter(System.out, true);\n\n\n public static void main(String[] args) { //threading has been used to increase the stack size.\n\n new Thread(null, null, \"BlackRise\", 1<<25) //the last parameter is stack size which is desired,\n {\n public void run() {\n\n try {\n Blackrise();\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(1);\n }\n }\n }.start();\n }\n\n static void Blackrise() { //The name Blackrise is my pen name... you can change the name according to your wish\n\n tsc(); //calculates the starting time of execution\n\n int n=ni();\n int a=n+1;\n int flag=0;\n while(a-->0 && flag==0)\n for(int i=1;i<=n && flag==0;i++)\n {\n if(a%i==0 && (a*i)>n && (i/a)<n){pl(a+ \" \"+i);flag=1;}\n\n }\n if(flag==0)pl(-1);\n\n tec(); //calculates the ending time of execution\n //pwt(); //prints the time taken to execute the program\n }\n\n /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n\n static class Lelo { //Lelo class for fast input\n private InputStream ayega;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private SpaceCharFilter filter;\n\n public Lelo(InputStream ayega) {\n this.ayega = ayega;\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 = ayega.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 String nextLine() {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n\n public int nextInt() {\n int c = read();\n\n while (isSpaceChar(c))\n c = read();\n\n int sgn = 1;\n\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n\n int res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n }\n while (!isSpaceChar(c));\n\n return res * sgn;\n }\n\n public long nextLong() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n }\n while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public double nextDouble() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n double res = 0;\n while (!isSpaceChar(c) && c != '.') {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, nextInt());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n }\n if (c == '.') {\n c = read();\n double m = 1;\n while (!isSpaceChar(c)) {\n if (c == 'e' || c == 'E')\n return res * Math.pow(10, nextInt());\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n m /= 10;\n res += (c - '0') * m;\n c = read();\n }\n }\n return res * sgn;\n }\n\n public String readString() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n }\n while (!isSpaceChar(c));\n\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public String next() {\n return readString();\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n }\n\n // functions to take input//\n static int ni() {\n return input.nextInt();\n }\n\n static long nl() {\n return input.nextLong();\n }\n\n static double nd() {\n return input.nextDouble();\n }\n\n static String ns() {\n return input.readString();\n }\n\n //functions to give output\n static void pl() {\n pw.println();\n }\n\n static void p(Object o) {\n pw.print(o + \" \");\n }\n\n static void pws(Object o){\n pw.print(o+\"\");\n }\n\n static void pl(Object o) {\n pw.println(o);\n }\n\n static void tsc() //calculates the starting time of execution\n {\n ts = Calendar.getInstance();\n ts.setTime(new Date());\n }\n\n static void tec() //calculates the ending time of execution\n {\n te = Calendar.getInstance();\n te.setTime(new Date());\n }\n\n static void pwt() //prints the time taken for execution\n {\n pw.printf(\"\\nExecution time was :- %f s\\n\", (te.getTimeInMillis() - ts.getTimeInMillis()) / 1000.00);\n }\n}\n\n", "src_uid": "883f67177474d23d7a320d9dbfa70dd3"} {"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 UnavoidableDetourForHome {\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[][][][][] dp = new long[2][N][N][N][N];\n \n int cur = 0;\n dp[cur][d[0] == 2 ? 1 : 0][d[0] == 3 ? 1 : 0][d[1] == 2 ? 1 : 0][d[1] == 3 ? 1 : 0] = 1;\n \n for (int i = 2; i < n; i++) {\n int nxt = cur ^ 1;\n for (int p1 = 0; p1 <= n; p1++) {\n for (int p2 = 0; p2 <= n; p2++) {\n for (int c1 = 0; c1 <= n; c1++) {\n for (int c2 = 0; c2 <= n; c2++) {\n dp[nxt][p1][p2][c1][c2] = 0;\n }\n }\n }\n }\n for (int p1 = 0; p1 <= n; p1++) {\n for (int p2 = 0; p1 + p2 <= n; p2++) {\n for (int c1 = 0; c1 + p1 + p2 <= n; c1++) {\n for (int c2 = 0; c1 + c2 + p1 + p2 <= n; c2++) {\n long v = dp[cur][p1][p2][c1][c2];\n if (v > 0) {\n if (p1 == 0 && p2 == 0) {\n dp[cur][c1][c2][0][0] = add(dp[cur][c1][c2][0][0], v);\n continue;\n }\n \n for (int t = 0; t < 2; t++) {\n int ways = t == 0 ? p1 : p2;\n if (ways == 0) continue;\n if (t == 0) {\n p1--;\n } else {\n p2--; p1++;\n }\n if (d[i] == 2) {\n dp[nxt][p1][p2][c1 + 1][c2] = add(dp[nxt][p1][p2][c1 + 1][c2], v * ways);\n if (c1 > 0)\n dp[nxt][p1][p2][c1 - 1][c2] = add(dp[nxt][p1][p2][c1 - 1][c2], v * ways * c1);\n if (c2 > 0)\n dp[nxt][p1][p2][c1 + 1][c2 - 1] = add(dp[nxt][p1][p2][c1 + 1][c2 - 1], v * ways * c2);\n } else {\n \n dp[nxt][p1][p2][c1][c2 + 1] = add(dp[nxt][p1][p2][c1][c2 + 1], v * ways);\n if (c1 > 0)\n dp[nxt][p1][p2][c1][c2] = add(dp[nxt][p1][p2][c1][c2], v * ways * c1);\n if (c2 > 0)\n dp[nxt][p1][p2][c1 + 2][c2 - 1] = add(dp[nxt][p1][p2][c1 + 2][c2 - 1], v * ways * c2);\n if (c1 > 1)\n dp[nxt][p1][p2][c1 - 2][c2] = add(dp[nxt][p1][p2][c1 - 2][c2], v * ways * c1 * (c1 - 1) / 2);\n if (c2 > 1)\n dp[nxt][p1][p2][c1 + 2][c2 - 2] = add(dp[nxt][p1][p2][c1 + 2][c2 - 2], v * ways * c2 * (c2 - 1) / 2);\n if (c1 > 0 && c2 > 0)\n dp[nxt][p1][p2][c1][c2 - 1] = add(dp[nxt][p1][p2][c1][c2 - 1], v * ways * c1 * c2);\n }\n if (t == 0) {\n p1++;\n } else {\n p2++; p1--;\n }\n }\n }\n }\n }\n }\n }\n cur = nxt;\n }\n \n out.println(dp[cur][0][0][0][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 UnavoidableDetourForHome().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", "src_uid": "db884d679d9cfb1dc4bc511f83beedda"} {"source_code": "//package round243;\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 E4F2 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\t/*\n[[1, 0, 0, 0, 0]]\n[[0, 8, 48, 56, 15]]\n[[0, 0, 32, 192, 256]]\n[[0, 0, 0, 64, 288]]\n[[0, 0, 0, 0, 64]]\t * \n\t */\n\tvoid solve()\n\t{\n\t\tint n = ni(), K = ni();\n\t\tint mod = 1000000007;\n\t\tBarrettInt bi = new BarrettInt(mod);\n\t\tint[][] dp = new int[K+1][n+1];\n\t\tlong[] twos = new long[n+1];\n\t\ttwos[0] = 1;\n\t\tfor(int i = 1;i <= n;i++){\n\t\t\ttwos[i] = twos[i-1] * 2;\n\t\t\tif(twos[i] >= mod)twos[i] -= mod;\n\t\t}\n\t\t\n\t\tdp[0][0] = 1;\n\t\tlong BIG = (long)mod<<32;\n\t\tfor(int end = 1;end <= n;end++){\n\t\t\tfor(int k = Math.min(K, end-1);k >= 0;k--){\n\t\t\t\tlong lsum = 0;\n\t\t\t\tfor(int l = 0;l <= end-1;l++){\n\t\t\t\t\tif(dp[k][l] != 0){\n\t\t\t\t\t\tlsum += dp[k][l] * (twos[end]-twos[l]+mod);\n\t\t\t\t\t\tif(lsum >= BIG)lsum -= BIG;\n//\t\t\t\t\t\tdp[k][l] = (int)(dp[k][l] * twos[l] % mod);\n\t\t\t\t\t\tdp[k][l] = (int)bi.modh(dp[k][l] * twos[l]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(k+1 <= K)dp[k+1][end] = (int)(lsum % mod);\n\t\t\t}\n\t\t}\n//\t\tfor(int i = 0;i <= K;i++){\n//\t\t\ttr(dp[i]);\n//\t\t}\n\t\tlong ret = 0;\n\t\tfor(int j = 0;j <= n;j++){\n\t\t\tret += dp[K][j];\n\t\t}\n\t\tout.println((int)bi.modh(ret));\n\t}\n\t\n\tpublic static class BarrettInt {\n\t\tpublic int mod;\n\t\tpublic long M;\n\t\tpublic int h;\n\t\t\n\t\tpublic BarrettInt(int mod)\n\t\t{\n\t\t\tthis.mod = mod;\n\t\t\tlong K = Integer.highestOneBit(mod)<<1;\n\t\t\th = Long.numberOfTrailingZeros(K)*2;\n\t\t\tM = K*K/mod;\n\t\t}\n\t\t\n\t\tpublic long mod(long a)\n\t\t{\n\t\t\tlong v = M*(a&mask);\n\t\t\tlong bl = v&mask;\n\t\t\tv = (v>>>31) + M*(a>>>31);\n\t\t\tbl |= (v&mask)<<31;\n\t\t\t\n\t\t\tlong q = bl>>>h|v>>>31<<62-h;\n\t\t\tlong r = a-q*mod;\n\t\t\treturn r < mod ? r : r-mod;\n\t\t}\n\t\t\n\t\tpublic long modh(long a)\n\t\t{\n\t\t\tlong r = a-((M*(a&mask)>>>31)+M*(a>>>31)>>>h-31)*mod;\n\t\t\treturn r < mod ? r : r-mod;\n\t\t}\n\t\t\n\t\tpublic long modl(long a)\n\t\t{\n\t\t\tlong r = a-(M*a>>>h)*mod;\n\t\t\treturn r < mod ? r : r-mod;\n\t\t}\n\t\t\n\t\tprivate static final long mask = (1L<<31)-1;\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 E4F2().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", "src_uid": "111673158df2e37ac6c019bb99225ccb"} {"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;\n\n\npublic class problemA implements Runnable{\n \n public void solve() throws IOException{\n int[] x=intArr();\n \n int x1=x[1]*x[3]*x[5];\n int x2=x[0]*x[2]*x[4];\n \n boolean ron=false;\n \n if(x1>x2 || (x2==0 && x1!=0)){\n ron=true;\n }else if(x1==0 && x2!=0) {\n ron=false;\n } else if(x[2]==0 && x[3]!=0){\n ron=true;\n } else if(x[0]==0 && x[1]!=0 && x[3]!=0){\n ron=true;\n }\n \n if(ron){\n out.println(\"Ron\");\n } else {\n out.println(\"Hermione\");\n }\n }\n\n public static void main(String[] args){\n new problemA().run();\n }\n\n @Override\n public void run(){\n// System.out.println(\"trying to solve\");\n try{\n in=new BufferedReader(new InputStreamReader(stdin));\n out=new PrintWriter(stdout);\n solve();\n in.close();\n out.close();\n } catch (Exception ex){\n ex.printStackTrace();\n System.exit(1);\n }\n }\n \n BufferedReader in;\n PrintWriter out;\n \n int[] intArr() throws IOException {\n String[] arr=nextLine().split(\"\\\\s\");\n int[] res=new int[arr.length];\n for(int i=0;i<arr.length;i++) res[i]=Integer.parseInt(arr[i]);\n return res;\n }\n\n long[] longArr() throws IOException {\n String[] arr=nextLine().split(\"\\\\s\");\n long[] res=new long[arr.length];\n for(int i=0;i<arr.length;i++) res[i]=Long.parseLong(arr[i]);\n return res;\n }\n\n double[] doubleArr() throws IOException {\n String[] arr=nextLine().split(\"\\\\s\");\n double[] res=new double[arr.length];\n for(int i=0;i<arr.length;i++) res[i]=Double.parseDouble(arr[i]);\n return res;\n }\n\n String nextLine() throws IOException {\n return in.readLine();\n }\n \n InputStream stdin;\n OutputStream stdout;\n public problemA(){\n stdin=System.in;\n stdout=System.out;\n }\n \n public problemA(InputStream stdin, OutputStream stdout){\n this.stdin=stdin;\n this.stdout=stdout;\n }\n}", "src_uid": "44d608de3e1447f89070e707ba550150"} {"source_code": "import java.lang.*;\nimport java.math.*;\nimport java.util.*;\nimport java.io.*;\n\npublic class Main {\n void solve() {\n long MX=(long)1e18;\n long l=nl(),r=nl();\n if(l==MX && r==MX){\n pw.println(\"1\");\n return;\n }\n long rr=r;\n\n if(rr==MX) rr--;\n a=convert(l);\n b=convert(rr);\n // for(int i=0;i<18;i++) System.out.print(a[i]+\" \");\n\n cc=new int[10];\n c=new int[10];\n generate(18,0);\n\n // pw.println(id);\n//\n// for(int i=0;i<id;i++){\n// for(int j=0;j<10;j++) cc[j]=c[i][j];\n//\n// if(go(0,1,1)) {\n// ans++;\n//\n// }\n// }\n// Arrays.fill(cc,0);\n //cc[7]=18;\n // pw.println(go(0,1,1));\n\n // if(r==MX) ans++;\n pw.println(ans);\n }\n int a[],b[];\n int c[];\n int cc[];\n int id=0;\n int ans=0;\n boolean go(int i,int t1,int t2){\n if(i>=18) return true;\n int st=0,ed=9;\n\n if(t1==1 && t2==1){\n st=a[i]; ed=b[i];\n // if(i==16) pw.println(\"YES\"+\" \"+st+\" \"+ed);\n for(int j=st+1;j<ed;j++){\n\n if(cc[j]>0){\n\n return true;\n }\n }\n\n if(st==ed){\n\n\n if(cc[st]>0){\n cc[st]--;\n if(go(i+1,1,1)) return true;\n cc[st]++;\n\n }\n }else {\n if(cc[st]>0){\n cc[st]--;\n if(go(i+1,1,0)) return true;\n cc[st]++;\n }\n if(cc[ed]>0){\n cc[ed]--;\n if(go(i+1,0,1)) return true;\n\n cc[ed]++;\n }\n }\n\n }else if(t1==1){\n st=a[i];\n for(int j=st+1;j<=ed;j++){\n if(cc[j]>0) return true;\n }\n if(cc[st]>0){\n cc[st]--;\n if(go(i+1,1,0)) return true;\n cc[st]++;\n }\n\n }else if(t2==1){\n ed=b[i];\n for(int j=st;j<ed;j++) if(cc[j]>0) return true;\n if(cc[ed]>0){\n cc[ed]--;\n if(go(i+1,0,1)) return true;\n cc[ed]++;\n }\n }else {\n return true;\n }\n return false;\n }\n\n\n\n void generate(int i,int digit){\n\n if(i==0){\n\n for(int j=0;j<10;j++) cc[j]=c[j];\n\n if(go(0,1,1)) ans++;\n return;\n }\n if(digit>9) return;\n for(int j=0;j<=i;j++){\n c[digit]=j;\n generate(i-j,digit+1);\n c[digit]=0;\n\n }\n\n }\n int []convert(long n){\n int a[]=new int[18];\n int id=17;\n while(n>0){\n\n a[id]=(int)(n%10);\n // if(a[id]<0) System.out.println(\"YES\");\n id--;\n n/=10;\n }\n return a;\n }\n\n\n\n long M=(long)1e9+7;\n InputStream is;\n PrintWriter pw;\n String INPUT = \"\";\n void run() throws Exception {\n is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n pw = new PrintWriter(System.out);\n long s = System.currentTimeMillis();\n solve();\n pw.flush();\n if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+\"ms\");\n\n }\n\n public static void main(String[] args) throws Exception { new Main().run(); }\n\n private byte[] inbuf = new byte[1024];\n public int lenbuf = 0, ptrbuf = 0;\n\n private int readByte() {\n if(lenbuf == -1)throw new InputMismatchException();\n if(ptrbuf >= lenbuf){\n ptrbuf = 0;\n try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n if(lenbuf <= 0)return -1;\n }\n return inbuf[ptrbuf++];\n }\n\n private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\n private double nd() { return Double.parseDouble(ns()); }\n private char nc() { return (char)skip(); }\n\n private String ns() {\n int b = skip();\n StringBuilder sb = new StringBuilder();\n while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n sb.appendCodePoint(b);\n b = readByte();\n }\n return sb.toString();\n }\n\n private char[] ns(int n) {\n char[] buf = new char[n];\n int b = skip(), p = 0;\n while(p < n && !(isSpaceChar(b))){\n buf[p++] = (char)b;\n b = readByte();\n }\n return n == p ? buf : Arrays.copyOf(buf, p);\n }\n\n private char[][] nm(int n, int m) {\n char[][] map = new char[n][];\n for(int i = 0;i < n;i++)map[i] = ns(m);\n return map;\n }\n\n private int[] na(int n) {\n int[] a = new int[n];\n for(int i = 0;i < n;i++)a[i] = ni();\n return a;\n }\n\n private int ni() {\n int num = 0, b;\n boolean minus = false;\n while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n if(b == '-'){\n minus = true;\n b = readByte();\n }\n\n while(true){\n if(b >= '0' && b <= '9'){\n num = num * 10 + (b - '0');\n }else{\n return minus ? -num : num;\n }\n b = readByte();\n }\n }\n\n private long nl() {\n long num = 0;\n int b;\n boolean minus = false;\n while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n if(b == '-'){\n minus = true;\n b = readByte();\n }\n\n while(true){\n if(b >= '0' && b <= '9'){\n num = num * 10 + (b - '0');\n }else{\n return minus ? -num : num;\n }\n b = readByte();\n }\n }\n private boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n private void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }\n}", "src_uid": "adfa5f280eefbacdbaa4ad605402b57a"} {"source_code": "import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n private static FastReader sc;\r\n private static PrintWriter out;\r\n\r\n public static void main( String[] args ) throws IOException {\r\n Locale.setDefault( Locale.US );\r\n Scanner in = new Scanner( System.in );\r\n sc = new FastReader();\r\n out = new PrintWriter( new BufferedOutputStream( System.out ));\r\n\r\n int n = in.nextInt();\r\n if( n == 1 ) {\r\n System.out.println( 3 );\r\n return;\r\n }\r\n System.out.println( n + 4 + n / 3 - 1 );\r\n }\r\n}\r\n\r\nclass FastReader {\r\n BufferedReader bufferedReader;\r\n StringTokenizer str;\r\n\r\n public FastReader() {\r\n bufferedReader = new BufferedReader( new InputStreamReader( System.in ));\r\n }\r\n\r\n String next() throws IOException {\r\n while( str == null || !str.hasMoreElements()){\r\n try {\r\n str = new StringTokenizer( bufferedReader.readLine());\r\n } catch( IOException Error ) {\r\n Error.printStackTrace();\r\n }\r\n\r\n }\r\n return str.nextToken();\r\n }\r\n\r\n int nextInt() throws IOException {\r\n return Integer.parseInt( next());\r\n }\r\n\r\n public int[] nextIntArr( int n ) throws IOException {\r\n int[] arr = new int[n];\r\n for( int i = 0; i < n; ++i ) {\r\n arr[i] = nextInt();\r\n }\r\n return arr;\r\n }\r\n\r\n long nextLong() throws IOException {\r\n return Long.parseLong( next());\r\n }\r\n\r\n public long[] nextLongArr( int n )throws IOException {\r\n long[] arr = new long[n];\r\n for( int i = 0; i < n; ++i ) {\r\n arr[i] = nextLong();\r\n }\r\n return arr;\r\n }\r\n\r\n double nextDouble() throws IOException {\r\n return Double.parseDouble( next());\r\n }\r\n\r\n String nextLine() throws IOException {\r\n String str = \"\";\r\n try {\r\n str = bufferedReader.readLine();\r\n } catch( IOException Error ) {\r\n Error.printStackTrace();\r\n }\r\n\r\n return str;\r\n }\r\n\r\n public char[] nextCharArr() throws IOException {\r\n return next().toCharArray();\r\n }\r\n}", "src_uid": "d0a8604b78ba19ab769fd1ec90a72e4e"} {"source_code": "import java.io.BufferedReader;\nimport java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Iterator;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Stack;\n\npublic class A {\n\tstatic BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));\n static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n \n public static void main(String[] args) throws IOException {\n \tString info[] = br.readLine().split(\" \");\n \tint x = Integer.parseInt(info[0]);\n \tint y = Integer.parseInt(info[1]);\n \tint z = Integer.parseInt(info[2]);\n \tint t1 = Integer.parseInt(info[3]);\n \tint t2 = Integer.parseInt(info[4]);\n \tint t3 = Integer.parseInt(info[5]);\n \t\n \tint caminata = t1*Math.abs(x-y);\n \tint acensor = t2*Math.abs(x-y)+3*t3+t2*Math.abs(x-z);\n \t\n \tif(caminata >= acensor) {\n \t\tSystem.out.println(\"YES\");\n \t}else {\n \t\tSystem.out.println(\"NO\");\n \t}\n \t\n }\n}\n", "src_uid": "05cffd59b28b9e026ca3203718b2e6ca"} {"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.InputMismatchException;\nimport java.io.IOException;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.io.InputStream;\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskC {\n int INF = (int) 1e9;\n\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int n = in.readInt();\n String s = in.next();\n int[][] VMEM = new int[n][], KMEM = new int[n][], OMEM = new int[n][];\n int VS = 0, KS = 0, OS = 0;\n for (int i = 0; i < n; i++) {\n int[] counts = {VS, KS, OS};\n if (s.charAt(i) == 'V') {\n VMEM[VS] = counts;\n VS++;\n } else if (s.charAt(i) == 'K') {\n KMEM[KS] = counts;\n KS++;\n } else {\n OMEM[OS] = counts;\n OS++;\n }\n }\n int[][][][] mem = new int[VS + 1][KS + 1][OS + 1][2];\n ArrayUtils.fill(mem, INF);\n mem[0][0][0][0] = 0;\n for (int V = 0; V <= VS; V++) {\n for (int K = 0; K <= KS; K++) {\n for (int O = 0; O <= OS; O++) {\n for (int lastV = 0; lastV < 2; lastV++) {\n if (mem[V][K][O][lastV] == INF) continue;\n if (V < VS) {\n int[] count = VMEM[V];\n int penalty = Math.abs(V - count[0]) + Math.abs(K - count[1]) + Math.abs(O - count[2]);\n mem[V + 1][K][O][1] = Math.min(mem[V + 1][K][O][1], penalty + mem[V][K][O][lastV]);\n }\n if (K < KS && lastV == 0) {\n int[] count = KMEM[K];\n int penalty = Math.abs(V - count[0]) + Math.abs(K - count[1]) + Math.abs(O - count[2]);\n mem[V][K + 1][O][0] = Math.min(mem[V][K + 1][O][0], penalty + mem[V][K][O][lastV]);\n }\n if (O < OS) {\n int[] count = OMEM[O];\n int penalty = Math.abs(V - count[0]) + Math.abs(K - count[1]) + Math.abs(O - count[2]);\n mem[V][K][O + 1][0] = Math.min(mem[V][K][O + 1][0], penalty + mem[V][K][O][lastV]);\n }\n }\n }\n }\n }\n out.printLine(Math.min(mem[VS][KS][OS][0], mem[VS][KS][OS][1]) / 2);\n }\n }\n static class ArrayUtils {\n public static void fill(int[][] array, int value) {\n for (int[] row : array) {\n Arrays.fill(row, value);\n }\n }\n\n public static void fill(int[][][] array, int value) {\n for (int[][] subArray : array) {\n fill(subArray, value);\n }\n }\n\n public static void fill(int[][][][] array, int value) {\n for (int[][][] subArray : array) {\n fill(subArray, value);\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 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", "src_uid": "08444f9ab1718270b5ade46852b155d7"} {"source_code": "import java.util.Scanner;\npublic class Main {\n\n public static void main(String[] args) {\n\t Scanner s = new Scanner(System.in);\n\t long a = s.nextLong();\n\t long b = s.nextLong();\n\t long g = gcd(a,b);\n\t long mul =0;\n\t mul = (long)(a*b)/g;\n\t long dasha = 0;\n\t long masha = 0;\n\t dasha = (mul-1)/a;\n\t masha = (mul-1)/b;\n\t if(a>b){\n\t dasha++;\n }\n\t else{\n\t masha++;\n }\n\t if(dasha>masha){\n System.out.println(\"Dasha\");\n }\n\t else if(masha >dasha){\n System.out.println(\"Masha\");\n }\n\t else{\n System.out.println(\"Equal\");\n }\n }\n public static long gcd(long a,long b){\n \tif(b==0){\n \t\treturn a;\n\t\t}\n \telse{\n \t\treturn gcd(b,a%b);\n\t\t}\n\t}\n}", "src_uid": "06eb66df61ff5d61d678bbb3bb6553cc"} {"source_code": "\r\nimport java.awt.Point;\r\nimport java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStream;\r\nimport java.io.InputStreamReader;\r\nimport java.io.PrintWriter;\r\nimport java.io.ObjectInputStream.GetField;\r\nimport java.lang.reflect.Array;\r\nimport java.math.BigDecimal;\r\nimport java.math.BigInteger;\r\nimport java.util.ArrayList;\r\nimport java.util.Arrays;\r\nimport java.util.Collection;\r\nimport java.util.Collections;\r\nimport java.util.HashSet;\r\nimport java.util.Hashtable;\r\nimport java.util.LinkedList;\r\nimport java.util.PriorityQueue;\r\nimport java.util.Queue;\r\nimport java.util.Set;\r\nimport java.util.Stack;\r\nimport java.util.StringTokenizer;\r\nimport java.util.TreeMap;\r\nimport java.util.TreeSet;\r\n\r\nimport javax.sound.sampled.ReverbType;\r\n\r\n\r\npublic class N717 {\r\n\tstatic PrintWriter out;\r\n\tstatic Scanner sc;\r\n\tstatic ArrayList<int[]>q,w,x;\r\n\tstatic ArrayList<Integer>adj[];\r\n\tstatic HashSet<Integer>primesH;\r\n\tstatic boolean prime[];\r\n\t//static ArrayList<Integer>a;\r\n\tstatic HashSet<Long>tmp;\r\n\tstatic boolean[]v;\r\n\tstatic int[]a,b,c,d;\r\n\tstatic Boolean[][]dp;\r\n\tstatic char[][]mp;\r\n\tstatic int A,B,n,m,h,ans,sum;\r\n\t//static String a,b;\r\n\tstatic long oo=(long)1e9+7;\r\n\tpublic static void main(String[]args) throws IOException {\r\n\t\tsc=new Scanner(System.in);\r\n\t\tout=new PrintWriter(System.out);\r\n\t\t//A();\r\n\t\t//B();\r\n\t\tC();\r\n\t\t//D();\r\n\t\t//E();\r\n\t\t//F();\r\n\t\t//G();\r\n\t\tout.close();\r\n\t}\r\n\t private static void A() throws IOException {\r\n\t\t int t=ni();\r\n\t\t while(t-->0) {\r\n\t\t\t\tint n=ni(),k=ni();\r\n\t\t\t\ta=nai(n);\r\n\t\t\t\tint sum=0;\r\n\t\t\t\tfor(int i=0;i<n;i++)sum+=a[i];\r\n\t\t\t\tint total=sum;\r\n\t\t\t\tfor(int i=0;i<n&&k>0;i++) {\r\n\t\t\t\t\tint sub=Math.min(k, a[i]);\r\n\t\t\t\t\ta[i]-=sub;\r\n\t\t\t\t\tsum-=sub;\r\n\t\t\t\t\tk-=sub;\r\n\t\t\t\t}\r\n\t\t\t\ta[n-1]+=total-sum;\r\n\t\t\t\tfor(int i=0;i<n;i++)out.print(a[i]+\" \");\r\n\t\t\t\tol(\"\");\r\n\t\t }\r\n\t\t\r\n\t }\r\n\t\tstatic void B() throws IOException {\r\n\t\t\tint t=ni();\r\n\t\t\twhile(t-->0) {\r\n\t\t\t\tint n=ni();\r\n\t\t\t\ta=nai(n);\r\n\t\t\t\tboolean can=false,z=false;\r\n\t\t\t\tint x=0;\r\n\t\t\t\tint[]pre=new int[n],suf=new int[n];\r\n\t\t\t\tfor(int i=0;i<n;i++) {\r\n\t\t\t\t\tx^=a[i];\r\n\t\t\t\t\tpre[i]=i==0?0:pre[i-1];\r\n\t\t\t\t\tpre[i]^=a[i];\r\n\t\t\t\t}\r\n\t\t\t\tfor(int i=n-1;i>=0;i--) {\r\n\t\t\t\t\tsuf[i]=i==n-1?0:suf[i+1];\r\n\t\t\t\t\tsuf[i]^=a[i];\r\n\t\t\t\t}\r\n\t\t\t\tif(x==0) {\r\n\t\t\t\t\tout.println(\"YES\");continue;\r\n\t\t\t\t}\r\n\t\t\t\tint id1=-1\t,id2=-1;\r\n\t\t\t\tfor(int i=0;i<n;i++) {\r\n\t\t\t\t\tif(pre[i]==x) {\r\n\t\t\t\t\t\tid1=i;break;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tfor(int i=n-1;i>=0;i--) {\r\n\t\t\t\t\tif(suf[i]==x) {\r\n\t\t\t\t\t\tid2=i;break;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tout.println(id1+1<id2?\"YES\":\"NO\");\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tstatic void C() throws IOException{\r\n\t\t\t int t=1;\r\n\t\t\t while(t-->0) {\r\n\t\t\t\t int n=ni();\r\n\t\t\t\t a=nai(n);\r\n\t\t\t\t sum=0;\r\n\t\t\t\t for(int i=0;i<n;i++)sum+=a[i];\r\n\t\t\t\t if(sum%2==1) {\r\n\t\t\t\t\t ol(0);\r\n\t\t\t\t }else {\r\n\t\t\t\t\t x=new ArrayList<int[]>();\r\n\t\t\t\t\t for(int i=0;i<n;i++) {\r\n\t\t\t\t\t\t x.add(new int[] {a[i],i});\r\n\t\t\t\t\t }\r\n\t\t\t\t\t// Collections.sort(x,(u,v)->u[0]-v[0]);\r\n\t\t\t\t\t ArrayList<Integer>ans=new ArrayList<Integer>();\r\n\t\t\t\t\t// while(x.size()>1) {\r\n\t\t\t\t\t\t dp=new Boolean[x.size()][(sum/2) +1];\r\n\t\t\t\t\t\t boolean can=dp(0,0);\r\n\t\t\t\t\t\t// if(!can)break;\r\n\t\t\t\t\t\t if(!can) {\r\n\t\t\t\t\t\t\t ol(0);continue;\r\n\t\t\t\t\t\t }\r\n\t\t\t\t\t\t int i=0;\r\n\t\t\t\t\t\t for(;i<x.size();i++) {\r\n\t\t\t\t\t\t\t if(x.get(i)[0]%2==1) {\r\n\t\t\t\t\t\t\t\t break;\r\n\t\t\t\t\t\t\t }\r\n\t\t\t\t\t\t }\r\n\t\t\t\t\t\t if(i<x.size()) {\r\n\t\t\t\t\t\t\t ans.add(x.get(i)[1]);\r\n\t\t\t\t\t\t }\r\n\t\t\t\t\t\t \r\n\t\t\t\t\t\t for(i=0;i<x.size()&&ans.size()==0;i++) {\r\n\t\t\t\t\t\t\t if((sum-x.get(i)[0])%2==1) {\r\n\t\t\t\t\t\t\t\t ans.add(x.get(i)[1]);\r\n\t\t\t\t\t\t\t\t can=false;\r\n\t\t\t\t\t\t\t\t break;\r\n\t\t\t\t\t\t\t }\r\n\t\t\t\t\t\t }\r\n\t\t\t\t\t\t if(ans.size()==0) {\r\n\t\t\t\t\t\t\t i=0;\r\n\t\t\t\t\t\t\t while(true) {\r\n\t\t\t\t\t\t\t\t a[i]/=2;\r\n\t\t\t\t\t\t\t\t if(a[i]%2==1) {\r\n\t\t\t\t\t\t\t\t\t ans.add(i);break;\r\n\t\t\t\t\t\t\t\t }\r\n\t\t\t\t\t\t\t\t i=(i+1)%n;\r\n\t\t\t\t\t\t\t }\r\n\t\t\t\t\t\t }\r\n\t\t\t\t\t\t \r\n\t\t\t\t\t //}\r\n\t\t\t\t\t out.println(ans.size());\r\n\t\t\t\t\t for(int x:ans)out.print((x+1)+\" \");\r\n\t\t\t\t\t ol(\"\");\r\n\t\t\t\t }\r\n\t\t\r\n\t\t\t }\r\n\t\t}\r\n\t\tprivate static Boolean dp(int i, int j) {\r\n\t\t\tif(j>sum/2)return false;\r\n\t\t\tif(i==x.size()) {\r\n\t\t\t\treturn sum/2==j;\r\n\t\t\t}\r\n\t\t\tif(dp[i][j]!=null)return dp[i][j];\r\n\t\t\t\r\n\t\t\treturn dp[i][j]=dp(i+1,j+x.get(i)[0])||dp(i+1,j);\r\n\t\t}\r\n\t\tstatic boolean isPrime(long n) {\r\n\t\t\tif(n==2)return true;\r\n\t\t\tif(n<2||n%2==0)return false;\r\n\t\t\t\r\n\t\t\tfor(long i=3L;i*i<n;i+=2l) {\r\n\t\t\t\tlong rem=(n%i);\r\n\t\t\t\tif(rem==0)return false;\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t}\r\n\t\tstatic void D() throws IOException {\r\n\t\t\tint t=ni();\r\n\t\t\twhile(t-->0) {\r\n\t\t\t\t\r\n\t\t\t\r\n\t\t\t}\r\n\t\t}\r\n\t\tstatic int gcd (int a, int b) {\r\n\t\t return b==0?a:gcd (b, a % b);\r\n\t\t}\r\n\t\t\r\n\tstatic void E() throws IOException {\r\n\t\tint t=ni();\r\n\t\twhile(t-->0) {\r\n\t\t\t\r\n\t\t\t\r\n\t\t}\r\n\t\t\r\n\t}\r\n\r\n\tstatic void F() throws IOException {\r\n\t\tint t=ni();\r\n\t\twhile(t-->0) {\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n\tstatic void CC() throws IOException {\r\n\t\tfor(int kk=2;kk<21;kk++) {\r\n\t\t\tol(kk+\" -------\");\r\n\t\tint n=kk;\r\n\t\tint k=n-2;\r\n\t\tint msk=1<<k;\r\n\t\tint[]a=new int[k];\r\n\t\tfor(int i=0;i<a.length;i++)a[i]=i+2;\r\n\t\tint mx=1;\r\n\t\tint ms=0;\r\n\t\tfor(int i=1;i<msk;i++) {\r\n\t\t\tlong prod=1;\r\n\t\t\tint cnt=0;\r\n\t\t\tfor(int j=0;j<a.length;j++) {\r\n\t\t\t\tif(((i>>j)&1)!=0) {\r\n\t\t\t\t\tprod*=a[j];\r\n\t\t\t\t\tcnt++;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif(cnt>=mx&&prod%n==1) {\r\n\t\t\t\tmx=cnt;\r\n\t\t\t\tms=i;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t}\r\n\t\tol(mx==1?mx:mx+1);\r\n\t\tout.print(1+\" \");\r\n\t\tlong pr=1;\r\n\t\tfor(int j=0;j<a.length;j++) {\r\n\t\t\tif(((ms>>j)&1)!=0) {\r\n\t\t\t\tout.print(a[j]+\" \");\r\n\t\t\t\tpr*=a[j];\r\n\t\t\t}\r\n\t\t}\r\n\t\tol(\"\");\r\n\t\tol(\"Prod: \"+pr);\r\n\t\tol(n+\"*\"+((pr-1)/n)+\" + \"+1);\r\n\t\t}\r\n\t}\r\n\tstatic int ni() throws IOException {\r\n\t\treturn sc.nextInt();\r\n\t}\r\n\tstatic double nd() throws IOException {\r\n\t\treturn sc.nextDouble();\r\n\t}\r\n\tstatic long nl() throws IOException {\r\n\t\treturn sc.nextLong();\r\n\t}\r\n\tstatic String ns() throws IOException {\r\n\t\treturn sc.next();\r\n\t}\r\n\tstatic int[] nai(int n) throws IOException {\r\n\t\tint[] a = new int[n];\r\n\t\tfor (int i = 0; i < n; i++)\r\n\t\t\ta[i] = sc.nextInt();\r\n\t\treturn a;\r\n\t}\r\n\tstatic long[] nal(int n) throws IOException {\r\n\t\tlong[] a = new long[n];\r\n\t\tfor (int i = 0; i < n; i++)\r\n\t\t\ta[i] = sc.nextLong();\r\n\t\treturn a;\r\n\t}\r\n\tstatic int[][] nmi(int n,int m) throws IOException{\r\n\t\tint[][]a=new int[n][m];\r\n\t\tfor(int i=0;i<n;i++) {\r\n\t\t\tfor(int j=0;j<m;j++) {\r\n\t\t\t\ta[i][j]=sc.nextInt();\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn a;\r\n\t}\r\n\r\n\tstatic long[][] nml(int n,int m) throws IOException{\r\n\t\tlong[][]a=new long[n][m];\r\n\t\tfor(int i=0;i<n;i++) {\r\n\t\t\tfor(int j=0;j<m;j++) {\r\n\t\t\t\ta[i][j]=sc.nextLong();\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn a;\r\n\t}\r\n\tstatic void o(String x) {\r\n\t\tout.print(x);\r\n\t}\r\n\tstatic void ol(String x) {\r\n\t\tout.println(x);\r\n\t}\r\n\tstatic void ol(int x) {\r\n\t\tout.println(x);\r\n\t}\r\n\tstatic void disp1(int []a) {\r\n\t\tfor(int i=0;i<a.length;i++) {\r\n\t\t\tout.print(a[i]+\" \");\r\n\t\t}\r\n\t\tout.println();\r\n\t}\r\n\r\n\tstatic class Scanner \r\n\t{\r\n\t\tStringTokenizer st;\r\n\t\tBufferedReader br;\r\n\r\n\t\tpublic Scanner(InputStream s){\tbr = new BufferedReader(new InputStreamReader(s));}\r\n\r\n\t\tpublic String next() throws IOException \r\n\t\t{\r\n\t\t\twhile (st == null || !st.hasMoreTokens()) \r\n\t\t\t\tst = new StringTokenizer(br.readLine());\r\n\t\t\treturn st.nextToken();\r\n\t\t}\r\n\t\tpublic boolean hasNext() {return st.hasMoreTokens();}\r\n\t\tpublic int nextInt() throws IOException {return Integer.parseInt(next());}\r\n\t\t\r\n\t\tpublic double nextDouble() throws IOException {return Double.parseDouble(next());}\r\n\t\t\r\n\t\tpublic long nextLong() throws IOException {return Long.parseLong(next());}\r\n\r\n\t\tpublic String nextLine() throws IOException {return br.readLine();}\r\n\t\t\t\r\n\t\tpublic boolean ready() throws IOException {return br.ready(); }\r\n\t\t\r\n\r\n\t}\r\n}\r\n", "src_uid": "29063ad54712b4911c6bf871969ee147"} {"source_code": "import java.util.Scanner;\n\npublic class Problem1042A {\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 maxK = 0, minK = 0;\n for (int i = 0; i < n; i++) {\n int temp = in.nextInt();\n if (maxK < temp) maxK = temp;\n minK += temp;\n }\n minK = (minK + m) % n == 0 ? (minK + m) / n : (minK + m) / n + 1;\n if (minK < maxK) minK = maxK;\n System.out.println(minK + \" \" + (maxK + m));\n }\n}", "src_uid": "78f696bd954c9f0f9bb502e515d85a8d"} {"source_code": "import java.util.Scanner;\n\npublic class Main {\n public static void main(String[] args) {\n\t Scanner scanner = new Scanner(System.in);\n long a1 = scanner.nextLong();\n long b1 = scanner.nextLong();\n long a2 = scanner.nextLong();\n long b2 = scanner.nextLong();\n\n long twosCount1 = 0, threesCount1 = 0;\n long twosCount2 = 0, threesCount2 = 0;\n long x = a1 * b1;\n while (x % 2 == 0) {\n ++twosCount1;\n x /= 2;\n }\n while (x % 3 == 0) {\n ++threesCount1;\n x /= 3;\n }\n long remainder1 = x;\n\n x = a2 * b2;\n while (x % 2 == 0) {\n ++twosCount2;\n x /= 2;\n }\n while (x % 3 == 0) {\n ++threesCount2;\n x /= 3;\n }\n long remainder2 = x;\n\n if (remainder1 != remainder2) {\n System.out.println(\"-1\");\n return;\n }\n\n long d2 = twosCount1 - twosCount2;\n long d3 = threesCount1 - threesCount2;\n\n long n = 0;\n n += Math.abs(d3);\n d2 += d3;\n n += Math.abs(d2);\n System.out.println(n);\n\n if (d3 > 0) {\n while (d3-- > 0) {\n if (a1 % 3 == 0)\n a1 -= a1 / 3;\n else\n b1 -= b1 / 3;\n }\n } else {\n d3 *= -1;\n while (d3-- > 0) {\n if (a2 % 3 == 0)\n a2 -= a2 / 3;\n else\n b2 -= b2 / 3;\n }\n }\n\n if (d2 > 0) {\n while (d2-- > 0) {\n if (a1 % 2 == 0)\n a1 /= 2;\n else\n b1 /= 2;\n }\n } else {\n d2 *= -1;\n while (d2-- > 0) {\n if (a2 % 2 == 0)\n a2 /= 2;\n else\n b2 /= 2;\n }\n }\n\n System.out.println(a1 + \" \" + b1);\n System.out.println(a2 + \" \" + b2);\n }\n}\n", "src_uid": "4fcd8c4955a47661462c326cbb3429bd"} {"source_code": "import java.util.*;\nimport java.io.*;\n \npublic class Main {\n\tpublic static void main(String args[]) {new Main().run();}\n\t\n\tScanner in = new Scanner(System.in);\n\tPrintWriter out = new PrintWriter(System.out);\n\tvoid run(){\n\t work();\n\t out.flush();\n\t}\n\tvoid work() {\n\t long r=in.nextLong();\n\t long b=0;\n\t for(;;b++){\n\t long num=9*(long)Math.pow(10,(double)b)*(b+1);\n\t if(r-num<=0){\n\t break;\n\t }\n\t r-=num;\n\t }\n\t long base=(long)Math.pow(10,(double)b);\n\t long c=(r-1)/(b+1);\n\t int m=(int)((r-1)%(b+1));\n\t base+=c;\n\t \n\t String str=base+\"\";\n\t out.println(str.charAt(m));\n\t}\n}", "src_uid": "1503d761dd4e129fb7c423da390544ff"} {"source_code": "import java.math.BigInteger;\nimport java.util.Scanner;\n\npublic class c_189 {\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tString s = in.nextLine();\n\t\tlong a=1;\n\t\tfor (int i = 0; i < s.length()-1; i++) \n\t\t\ta=(a*2)%1000000007;\n\t\tBigInteger mod=new BigInteger(\"1000000007\");\n\t\tBigInteger b=new BigInteger(s, 2);\n\t\tb=b.multiply(new BigInteger(a+\"\"));\n\t\tb=b.mod(mod);\n\t\tSystem.out.println(b);\n\t}\n}\n", "src_uid": "89b51a31e00424edd1385f2120028b9d"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class Solution {\n public static void main(String[] args) throws IOException {\n BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));\n String[] input;\n char[][] board = new char[11][11];\n input = bufferedReader.readLine().split(\" \");\n int rows = Integer.parseInt(input[0]);\n int columns = Integer.parseInt(input[1]);\n for(int i=0;i<rows;i++){\n String currentInput = bufferedReader.readLine();\n for(int j=0;j<currentInput.length();j++){\n board[i][j] = currentInput.charAt(j);\n }\n }\n Solver solver = new Solver();\n System.out.println(solver.solve(rows,columns,board));\n bufferedReader.close();\n }\n}\n\nclass Solver {\n\n public int solve(int rows,int columns, char[][] board) {\n int allowedRows = rows;\n int allowedColumns = columns;\n for(int i=0;i<rows;i++){\n for(int j=0;j<columns;j++){\n if('S' == board[i][j]){\n allowedRows--;\n break;\n }\n }\n }\n for(int i=0;i<columns;i++){\n for(int j=0;j<rows;j++){\n if('S' == board[j][i]){\n allowedColumns--;\n break;\n }\n }\n }\n return allowedColumns*rows+allowedRows*columns-allowedColumns*allowedRows;\n }\n}\n\n\n\n\n", "src_uid": "ebaf7d89c623d006a6f1ffd025892102"} {"source_code": "import java.util.*;\nimport 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\npublic class Main {\n\tpublic static int maxn = (int) (1e6 + 5);\n\tpublic static double PI = Math.acos(-1.0);\n\tpublic static double eps = 1e-6;\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\tpublic static int[] lf = new int[505];\n\tpublic static int[] rt = new int[505];\n\tpublic static int[] dt = new int[505];\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n InputReader in = new InputReader(inputStream);\n\t\tint n = in.nextInt();\n\t\tString s = in.next();\n\t\t\n\t\tint mi = n, cnt = 0;\n\t\tfor(int k = 0; k < n; ++k) {\n\t\t\tchar chk = s.charAt(k);\n\t\t\tlf[k + 1] = lf[k];\n\t\t\trt[k + 1] = rt[k];\n\t\t\tif(chk == '(') ++lf[k + 1];\n\t\t\telse ++rt[k + 1];\n\t\t\tdt[k + 1] = lf[k + 1] - rt[k + 1];\n\t\t\tif(dt[k + 1] < mi) {\n\t\t\t\tmi = dt[k + 1];\n\t\t\t\tcnt = 1;\n\t\t\t} else if(dt[k + 1] == mi) {\n\t\t\t\t++cnt;\n\t\t\t}\n\t\t}\n\t\tint ans = 0, l = 1, r = 1;\n\t\tif(lf[n] != rt[n]) {\n\t\t\tSystem.out.println(0);\n\t\t\tSystem.out.println(1 + \" \" + 1);\n\t\t\treturn ;\n\t\t}\n\t\tif(cnt > ans) ans = cnt;\n\t\tfor(int i = 0; i < n; ++i) {\n\t\t\tfor(int j = i; j < n; ++j) {\n\t\t\t\tchar chi = s.charAt(i);\n\t\t\t\tchar chj = s.charAt(j);\n\t\t\t\tif(chi == chj) continue;\n\t\t\t\tlf[0] = 0; rt[0] = 0;\n\t\t\t\tmi = n; cnt = 0;\n\t\t\t\tfor(int k = 0; k < n; ++k) {\n\t\t\t\t\tchar chk = s.charAt(k);\n\t\t\t\t\tif(k == i || k == j) {\n\t\t\t\t\t\tif(chk == '(') chk = ')';\n\t\t\t\t\t\telse chk = '(';\n\t\t\t\t\t}\n\t\t\t\t\tlf[k + 1] = lf[k];\n\t\t\t\t\trt[k + 1] = rt[k];\n\t\t\t\t\tif(chk == '(') ++lf[k + 1];\n\t\t\t\t\telse ++rt[k + 1];\n\t\t\t\t\tdt[k + 1] = lf[k + 1] - rt[k + 1];\n\t\t\t\t\tif(dt[k + 1] < mi) {\n\t\t\t\t\t\tmi = dt[k + 1];\n\t\t\t\t\t\tcnt = 1;\n\t\t\t\t\t} else if(dt[k + 1] == mi) {\n\t\t\t\t\t\t++cnt;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(cnt > ans) {\n\t\t\t\t\tans = cnt;\n\t\t\t\t\tl = i + 1; r = j + 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t\tSystem.out.println(l + \" \" + r);\n\t}\n}\n", "src_uid": "2d10668fcc2d8e90e102b043f5e0578d"} {"source_code": " import java.util.*;\n public class div573{\n \tpublic static void main(String sp[]){\n \t\tScanner sc = new Scanner(System.in);\n \t\t\n \t\tString s1 = sc.next();\n \t\tString s2 = sc.next();\n \t\tString s3 = sc.next();\n \t\t\n \t\tboolean a=false;\n \t\tboolean b=false;\n \t\tint s=0;\n \t\tint m=0;\n \t\tint p=0;\n \t\tint arr[] = new int[10];\n \t\t\n \t\tint val1 = (int)s1.charAt(0)-48;\n \t\tint val2 = (int)s2.charAt(0)-48;\n \t\tint val3 = (int)s3.charAt(0)-48;\n \t\tif(s1.charAt(1)=='s')\n \t\t\ts++;\n \t\tif(s1.charAt(1)=='m')\n \t\t\tm++;\n \t\tif(s1.charAt(1)=='p')\n \t\t\tp++;\n \t\tif(s2.charAt(1)=='s')\n \t\t\ts++;\n \t\tif(s2.charAt(1)=='m')\n \t\t\tm++;\n \t\tif(s2.charAt(1)=='p')\n \t\t\tp++;\n \t\tif(s3.charAt(1)=='s')\n \t\t\ts++;\n \t\tif(s3.charAt(1)=='m')\n \t\t\tm++;\n \t\tif(s3.charAt(1)=='p')\n \t\t\tp++;\n \t\tif((s==3 || m==3 || p==3) && ((val1==val2) && (val2==val3))){\n \t\t\tSystem.out.println(\"0\");\n \t\t\treturn;\n \t\t}\n \t\tArrayList<Integer> al = new ArrayList<>();\n \t\tal.add(val1);\n \t\tal.add(val2);\n \t\tal.add(val3);\n \t\tCollections.sort(al);\n \t\tif(((al.get(0)+1)==al.get(1) && (al.get(1)+1)==al.get(2)) &&(s==3 || p==3 || m==3)){\n \t\t\tSystem.out.println(\"0\");\n \t\t\treturn;\n \t\t}\n \n \t\tHashMap<String,Integer> hm = new HashMap<>();\n \t\tif(!hm.containsKey(s1))\n \t\t\thm.put(s1,1);\n \t\telse hm.put(s1,hm.get(s1)+1);\n \t\t\n \t\tif(!hm.containsKey(s2))\n \t\t\thm.put(s2,1);\n \t\telse hm.put(s2,hm.get(s2)+1);\n \t\t\n \t\tif(!hm.containsKey(s3))\n \t\t\thm.put(s3,1);\n \t\telse hm.put(s3,hm.get(s3)+1);\n \t\t\n \t\tint ans1 = 3-(Math.max(hm.get(s1),Math.max(hm.get(s2),hm.get(s3))));\n \t\tint p1[] = new int[11];\n \t\tif(s1.charAt(1)=='p')\n \t\tp1[val1]=1;\n \t\tif(s2.charAt(1)=='p')\n \t\tp1[val2]=1;\n \t\tif(s3.charAt(1)=='p')\n \t\tp1[val3]=1;\n \t\tint ansa1 = 3;\n \t\tfor(int i=1;i<=7;i++){\n \t\t\tint count=0;\n \t\t\tfor(int j=i;j<=i+2;j++){\n \t\t\t\tif(p1[j]==1)\n \t\t\t\t\tcount++;\n \t\t\t}\n \t\t\tansa1 = Math.min(ansa1,3-count);\n \t\t}\n \t\t\n \t\tint m1[] = new int[11];\n \t\tif(s1.charAt(1)=='m')\n \t\tm1[val1]=1;\n \t\tif(s2.charAt(1)=='m')\n \t\tm1[val2]=1;\n \t\tif(s3.charAt(1)=='m')\n \t\tm1[val3]=1;\n \t\tint ansa2 = 3;\n \t\tfor(int i=1;i<=7;i++){\n \t\t\tint count=0;\n \t\t\tfor(int j=i;j<=i+2;j++){\n \t\t\t\tif(m1[j]==1)\n \t\t\t\t\tcount++;\n \t\t\t}\n \t\t\tansa2 = Math.min(ansa2,3-count);\n \t\t}\n \t\t\n \t\tint d1[] = new int[11];\n \t\tif(s1.charAt(1)=='s')\n \t\td1[val1]=1;\n \t\tif(s2.charAt(1)=='s')\n \t\td1[val2]=1;\n \t\tif(s3.charAt(1)=='s')\n \t\td1[val3]=1;\n \t\tint ansa3 = 3;\n \t\tfor(int i=1;i<=7;i++){\n \t\t\tint count=0;\n \t\t\tfor(int j=i;j<=i+2;j++){\n \t\t\t\tif(d1[j]==1)\n \t\t\t\t\tcount++;\n \t\t\t}\n \t\t\tansa3 = Math.min(ansa3,3-count);\n \t\t}\n \t\tint ans2=0;\n \t\tans2 = Math.min(ansa1,Math.min(ansa2,ansa3));\n \t\tSystem.out.println(Math.min(ans2,ans1));\n \t\t\n \t\t\n \t}\n }\n\n\n", "src_uid": "7e42cebc670e76ace967e01021f752d3"} {"source_code": "import java.util.Arrays;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.util.List;\nimport java.math.BigInteger;\nimport java.io.PrintStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.Comparator;\nimport java.io.IOException;\nimport java.util.StringTokenizer;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author shu_mj @ http://shu-mj.com\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tScanner in = new Scanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n Scanner in;\n PrintWriter out;\n\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n this.in = in;\n this.out = out;\n run();\n }\n\n void run() {\n int m = in.nextInt();\n int h1 = in.nextInt();\n int a1 = in.nextInt();\n int x1 = in.nextInt();\n int y1 = in.nextInt();\n int h2 = in.nextInt();\n int a2 = in.nextInt();\n int x2 = in.nextInt();\n int y2 = in.nextInt();\n int s0 = get0(m, h1, a1, x1, y1);\n int s1 = get1(m, a1, x1, y1);\n int t0 = get0(m, h2, a2, x2, y2);\n int t1 = get1(m, a2, x2, y2);\n Algo.debug(s0, s1, t0, t1);\n if (s0 == -1 || t0 == -1) {\n out.println(-1);\n return ;\n }\n if (s1 == -1 && t1 == -1) {\n out.println(s0 == t0 ? s0 : -1);\n return ;\n }\n if (s1 == -1 || t1 == -1) {\n if (s1 == -1) {\n out.println(s0 >= t0 && (s0 - t0) % t1 == 0 ? s0 : -1);\n } else {\n out.println(t0 >= s0 && (t0 - s0) % s1 == 0 ? t0 : -1);\n }\n return ;\n }\n// long[] res = Num.congruence(new long[] { 1, 1 }, new long[] { s0, t0 }, new long[] { s1, t1 });\n// if (res == null) {\n// out.println(-1);\n// } else {\n// out.println(res[0]);\n// }\n if (s1 < t1) {\n { int t = s0; s0 = t0; t0 = t; }\n { int t = s1; s1 = t1; t1 = t; }\n }\n for (long i = 0; i < 5000000; i++) {\n if (i * s1 + s0 >= t0 && (i * s1 + s0 - t0) % t1 == 0) {\n out.println(i * s1 + s0);\n return ;\n }\n }\n out.println(-1);\n }\n\n private int get1(int m, int a1, int x1, int y1) {\n boolean[] vis = new boolean[m + 1];\n for (int i = 1, a2 = (int) ((long) a1 * x1 % m + y1) % m; ; i++) {\n if (a2 == a1) return i;\n if (vis[a2]) return -1;\n vis[a2] = true;\n a2 = (int) ((long) x1 * a2 % m + y1) % m;\n }\n }\n\n private int get0(int m, int h1, int a1, int x1, int y1) {\n boolean[] vis = new boolean[m + 1];\n for (int i = 0; ; i++) {\n if (h1 == a1) return i;\n if (vis[h1]) return -1;\n vis[h1] = true;\n h1 = (int) ((long) x1 * h1 % m + y1) % m;\n }\n }\n}\n\nclass Scanner {\n BufferedReader br;\n StringTokenizer st;\n\n public Scanner(InputStream in) {\n br = new BufferedReader(new InputStreamReader(in));\n eat(\"\");\n }\n\n private void eat(String s) {\n st = new StringTokenizer(s);\n }\n\n public String nextLine() {\n try {\n return br.readLine();\n } catch (IOException e) {\n return null;\n }\n }\n\n public boolean hasNext() {\n while (!st.hasMoreTokens()) {\n String s = nextLine();\n if (s == null)\n return false;\n eat(s);\n }\n return true;\n }\n\n public String next() {\n hasNext();\n return st.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n}\n\nclass Algo {\n\n public static void debug(Object...os) {\n System.err.println(Arrays.deepToString(os));\n }\n\n\n}\n\n", "src_uid": "7225266f663699ff7e16b726cadfe9ee"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.lang.reflect.Array;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class B {\n\tstatic boolean visited[][];\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\n\t\tint count = 0;\n\n\t\tvisited = new boolean[n + 1][n + 1];\n\t\tint z;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tfor (int j = 1; j <= n; j++) {\n\t\t\t\tif(check(i,j)) {\n\t\t\t\t\tz=i^j;\n\t\t\t\t\tif(z>Math.max(i, j)&&z<=n&&z < i+j) {\n\t\t\t\t\t\tvisited[i][j] = true;\n\n\t\t\t\t\t\tvisited[j][i] = true;\n\t\t\t\t\t\tcount++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(count);\n\t}\n\n\tstatic boolean check(int i, int j) {\n\t\tif (!visited[i][j]&&!visited[j][i] )\n\t\t\treturn true;\n\t\treturn false;\n\t}\n\n\n\tstatic int log(int x, int base) {\n\t\treturn (int) (Math.log(x) / Math.log(base));\n\t}\n\n\tstatic class Scanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n\n\t\tpublic Scanner(InputStream s) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(s));\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t\tpublic long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tpublic String nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n\n\t\tpublic boolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\n\t}\n}\n", "src_uid": "838f2e75fdff0f13f002c0dfff0b2e8d"} {"source_code": "import java.util.List;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.BufferedWriter;\nimport java.util.InputMismatchException;\nimport java.util.ArrayList;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.math.BigInteger;\nimport java.util.Collection;\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 Turaev Timur\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tOutputWriter out = new OutputWriter(outputStream);\n\t\tTaskB solver = new TaskB();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskB {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n long n = in.readLong(), m = in.readLong();\n\n long maxAnswer = Combinatorics.binomial(n - m + 1, 2);\n\n long ceil = IntegerUtils.ceil(n, m);\n long floor = n / m;\n long minAnswer = (n % m) * Combinatorics.binomial(ceil, 2) + (m - n % m) * Combinatorics.binomial(floor, 2);\n\n out.printFormat(\"%d %d\", minAnswer, maxAnswer);\n }\n}\n\nclass InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1)\n throw new InputMismatchException();\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public long readLong() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9')\n throw new InputMismatchException();\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null)\n return filter.isSpaceChar(c);\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n }\n}\n\nclass OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public void printFormat(String format, Object... objects) {\n writer.printf(format, objects);\n }\n\n public void close() {\n writer.close();\n }\n\n}\n\nclass Combinatorics {\n\n public static long binomial(long n, long k) {\n long ans = 1;\n for (int i = 0; i < k; i++) {\n ans *= (n - i);\n }\n for (int i = 2; i <= k; i++) {\n ans /= i;\n }\n return ans;\n }\n}\n\nclass IntegerUtils {\n\n public static long ceil(long n, long d) {\n return (n + d - 1) / d;\n }\n\n}\n\n", "src_uid": "a081d400a5ce22899b91df38ba98eecc"} {"source_code": "//package codeforces.practice.div2c;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class CF1105C {\n private static int UNVISITED = 0;\n private static int VISITING = -1;\n private static int VISITED = 1;\n\n public static void main(String[] args) {\n// try {\n// FastScanner in = new FastScanner(new FileInputStream(\"src/input.in\"));\n// PrintWriter out = new PrintWriter(new FileOutputStream(\"src/output.out\"));\n\n FastScanner in = new FastScanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n\n solve(1, in, out);\n\n// } catch (IOException e) {\n// e.printStackTrace();\n// }\n }\n\n private static void solve(int q, FastScanner in, PrintWriter out) {\n for (int qq = 0; qq < q; qq++) {\n int n = in.nextInt(), l = in.nextInt(), r = in.nextInt();\n int mod = (int)1e9 + 7;\n long[] cnt = new long[3];\n while(l % 3 != 0 && l <= r) {\n cnt[l % 3]++;\n l++;\n }\n while(r % 3 != 2 && l <= r) {\n cnt[r % 3]++;\n r--;\n }\n for(int i = 0; i < 3; i++) {\n cnt[i] += (r - l + 1) / 3;\n }\n\n long[][] dp = new long[n + 1][3]; //dp[i][j]: the number of ways to get an array of length i whose sum is j after % 3\n //dp[i][0] = number of ways to pick 0 * dp[i - 1][0] + number of ways to pick 1 * dp[i - 1][2] + numbers of ways to\n //pick 2 * dp[i - 1][1]\n\n dp[1][0] = cnt[0];\n dp[1][1] = cnt[1];\n dp[1][2] = cnt[2];\n\n for(int i = 2; i <= n; i++) {\n dp[i][0] = (dp[i - 1][0] * cnt[0] + dp[i - 1][1] * cnt[2] + dp[i - 1][2] * cnt[1]) % mod;\n dp[i][1] = (dp[i - 1][0] * cnt[1] + dp[i - 1][1] * cnt[0] + dp[i - 1][2] * cnt[2]) % mod;\n dp[i][2] = (dp[i - 1][0] * cnt[2] + dp[i - 1][1] * cnt[1] + dp[i - 1][2] * cnt[0]) % mod;\n }\n\n out.println(dp[n][0]);\n }\n out.close();\n }\n\n private static long modularAdd(long a, long b, int mod) {\n long sum = a + b;\n if (sum >= mod) {\n sum -= mod;\n }\n return sum;\n }\n\n private static long modularSubtract(long a, long b, int mod) {\n long diff = a - b;\n if (diff < 0) {\n diff += mod;\n }\n return diff;\n }\n\n private static Stack<Integer> topologicalSort(Set<Integer>[] g) {\n Stack<Integer> stack = new Stack<>();\n int[] state = new int[g.length];\n\n for (int node = 0; node < g.length; node++) {\n if (!topoSortHelper(g, stack, state, node)) {\n return null;\n }\n }\n return stack;\n }\n\n private static boolean topoSortHelper(Set<Integer>[] g, Stack<Integer> stack, int[] state, int currNode) {\n if (state[currNode] == VISITED) {\n return true;\n } else if (state[currNode] == VISITING) {\n return false;\n }\n state[currNode] = VISITING;\n for (int neighbor : g[currNode]) {\n if (!topoSortHelper(g, stack, state, neighbor)) {\n return false;\n }\n }\n state[currNode] = VISITED;\n stack.push(currNode);\n return true;\n }\n\n static class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n FastScanner(InputStream stream) {\n try {\n br = new BufferedReader(new InputStreamReader(stream));\n } catch (Exception e) {\n e.printStackTrace();\n }\n }\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n 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", "src_uid": "4c4852df62fccb0a19ad8bc41145de61"} {"source_code": "import java.util.*;\nimport java.math.*;\nimport java.io.*;\nimport java.text.*;\n\npublic class A {\n\n //public static PrintWriter pw;\n public static PrintWriter pw = new PrintWriter(System.out);\n\n public static void solve() throws IOException {\n//\tpw=new PrintWriter(new FileWriter(\"C:\\\\Users\\\\shree\\\\Downloads\\\\small_output_in\"));\n FastReader sc = new FastReader();\n int n=sc.I();\n int a[]=new int[n+1];\n int dp[]=new int[n+1];\n int ans=0;\n for(int i=1;i<=n;i++){\n a[i]=sc.I();\n dp[i]=1;\n for(int j=1;j<i;j++){\n if(a[j]<=a[i]) dp[i]=Math.max(dp[i],1+dp[j]);\n }\n ans=Math.max(ans,dp[i]);\n }\n pw.println(ans);\n\n pw.close();\n\n\n }\n\n public static void main(String[] args) {\n new Thread(null, new Runnable() {\n public void run() {\n try {\n\n solve();\n } catch (Exception e) {\n e.printStackTrace();\n }\n }\n }, \"1\", 1 << 26).start();\n\n }\n\n static BufferedReader br;\n static long M = (long) 1e9 + 7;\n\n static class FastReader {\n\n StringTokenizer st;\n\n public FastReader() throws FileNotFoundException {\n //br=new BufferedReader(new FileReader(\"C:\\\\Users\\\\shree\\\\Downloads\\\\B-small-practice.in\"));\n br = new BufferedReader(new InputStreamReader(System.in));\n\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int I() {\n return Integer.parseInt(next());\n }\n\n long L() {\n return Long.parseLong(next());\n }\n\n double D() {\n return Double.parseDouble(next());\n }\n\n String nextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n\n public boolean hasNext() throws IOException {\n while (st == null || !st.hasMoreTokens()) {\n String s = br.readLine();\n if (s == null) {\n return false;\n }\n st = new StringTokenizer(s);\n }\n return true;\n }\n\n }\n}", "src_uid": "c7b1f0b40e310f99936d1c33e4816b95"} {"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<Integer>[] 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<Pair>{\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}", "src_uid": "81a890bd542963bbcec7a041dde5c247"} {"source_code": "import java.util.Scanner;\n\npublic class Pipeline {\n\n\tpublic static void main(String[] args) {\n\n\t\tScanner sc = new Scanner(System.in);\n\t\tLong n = sc.nextLong(), k = sc.nextLong();\n\t\tsc.close();\n\n\t\tk--;\n\t\tn--;\n\t\t\n\t\tLong limit = (k * (k + 1)) / 2 ;\n\n\t\tif (n > limit) {\n\t\t\tSystem.out.println(-1);\n\t\t\t\n\t\t} else if ( n == 0 ) {\n\t\t\tSystem.out.println(0);\n\t\t\t\n\t\t} else if (n <= k) {\n\t\t\tSystem.out.println(1);\n\t\t\t\n\t\t} else {\n\n\t\t\tLong count = 0L;\n\t\t\tLong end = k;\n\t\t\t\n\t\t\tLong sk = BS(end,n); //findMaxRange(n,end);\n\t\t\t\t\t\t\n\t\t\tcount += end - sk + 1 ;\n\n\t\t\tLong cur = ( end * (end+1) / 2 ) - ( sk * (sk-1) / 2 ) ;\n\n\t\t\tn = n - cur ;\n\t\t\t\n\t\t\tif ( n != 0 ) {\n\t\t\t\tcount++;\n\t\t\t}\n\t\t\t\n\t\t\tSystem.out.println(count);\n\t\t}\n\n\t\t// erke\n\n\t}\n\t\n\tpublic static Boolean valid(Long mid,Long e,Long n){\n\t\t\n\t\tLong cur = ( e * (e+1) / 2 ) - ( mid * (mid-1) / 2 ) ;\n\t\t\n\t\tif (cur <= n )\n\t\t\treturn true;\n\t\treturn false;\n\t}\n\t\n\tpublic static Long BS(Long x, Long n){\n\t\tLong s=1L,e=x,m=0L;\n\t\twhile(s<e){\n\t\t\tm=(s+e+1)/2-1;\n\t\t\tif(!valid(m,x,n))\n\t\t\t\ts=m+1;\n\t\t\telse \n\t\t\t\te=m;\n\t\t}\n\t\treturn s;\n\t}\n\t\n\n}", "src_uid": "83bcfe32db302fbae18e8a95d89cf411"} {"source_code": "import java.util.Scanner;\npublic class Hexagons\n{\npublic static void main(String []args)\n{\nScanner s = new Scanner(System.in);\nint a = s.nextInt();\nint b = s.nextInt();\nint c = s.nextInt();\nSystem.out.println(a * b + b * c + c * a - a - b - c + 1);\n}\n}\n", "src_uid": "8ab25ed4955d978fe20f6872cb94b0da"} {"source_code": "\t\n\t\timport java.awt.List;\n\t\timport java.io.*;\n\t\timport java.util.*;\n\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t/*\n\t\t * \n\t\t * daiict\n\t\t *\n\t\t * \n\t\t * \n\t\t */\n\t\t\n\t\t\n\t\tpublic class Main {\n\t\t\tFastScanner in;\n\t\t\tPrintWriter out;\n\t\t\n\t\t\tstatic ArrayList[] adj;\n\t\t\t\n\t\t\tstatic int n;\n\t\t\tstatic int m;\n\t\t\tstatic int visited[][];\n\t\t\tstatic int[][] arr;\n\t\t\tstatic int[][] brr;\n\t\t\tstatic int[][] ans;\n\t\t\tstatic int array[];\n\t\t\tstatic int pref[];\n\t\t\tstatic int sum = 0;\n\t\t//for dfs do not delete\n\t\t\tstatic int dir[][] ={{1,0},{0,1},{0,-1}};\n\t\t\t\n\t\t\tstatic long an = 0;\n\t\t\tstatic long bn = 0;\n\t\t\tstatic int p = 0;\n\t\t\tstatic int ta = -1;\n\t\t\tstatic int tb = -1;\n\t\t\tstatic Stack<Integer> st;\n\t\t\tstatic int k;\n\t\t\tstatic long mod = (long)1e9 + 7;\n\t\t\tstatic long[] seg;\n\t\t\t\n\t\t\tstatic class Pair implements Comparable<Pair>\n\t\t {\n\t\t\t\tint x;\n\t\t\t\tboolean y;\n\t\t\t\tString s = \"\";\n\t\t\t\tString val;\n\t\t Pair(int l, boolean b, String p,String q) {\n\t\t \n\t\t \tthis.x = l;\n\t\t this.y = b;\n\t\t this.s = p;\n\t\t this.val = q;\n\t\t }\n\t\t @Override\n\t\t public int compareTo(Pair p) {\n\t\t \t\n\t\t \tString arr[] = val.split(\" \");\n\t\t \tString brr[] = p.val.split(\" \");\n\t\t \t\n\t\t \tif(s.equals(\"numeric\")){\n\t\t \t\tint aa = Integer.parseInt(arr[x]);\n\t\t\t\t\t\tint bb = Integer.parseInt(brr[x]);\n\t\t\t\t\t\t\n\t\t\t\t\t\tif(aa>bb && this.y){\n\t\t\t\t\t\t\treturn 1;\n\t\t\t\t\t\t}else if(this.y){\n\t\t\t\t\t\t\treturn -1;\n\t\t\t\t\t\t}else if(aa >= bb && ! this.y){\n\t\t\t\t\t\t\treturn -1;\n\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\treturn 1;\n\t\t\t\t\t\t}\n\t\t \t}else{\n\t\t \t\tif(this.y){\n\t\t \t\t\treturn arr[x].compareTo(brr[x]);\n\t\t \t\t}else{\n\t\t \t\t\treturn brr[x].compareTo(arr[x]);\n\t\t \t\t}\n\t\t \t}\n\t\t \n\t\t }\n\t\t \n\t\t public String toString(){\n\t\t \treturn x + \" \" + y;\n\t\t }\n\t\t \n\t\t public boolean equals(Object o){\n\t\t \tif(o instanceof Pair){\n\t\t \t\tPair a = (Pair)o;\n\t\t \t\t\n\t\t \t\treturn this.x == a.x;\n\t\t \t}\n\t\t \t\n\t\t \treturn false;\n\t\t }\n\t\t \n//\t\t public int hashCode(){\n//\t\t \treturn new Long(x).hashCode()*31 + new Long(y).hashCode();\n//\t\t }\n\t\t \n\t\t }\n\t\t \n\t\t\t\n\t\t\tpublic static int gcd(int a, int b) {\n\t\t\t\tif (b == 0) return a;\n\t\t\t\treturn gcd(b, a%b);\n\t\t\t}\n\t\n\t\t\tvoid build(int n) { // build the tree\n\t\t\t\t for (int i = n - 1; i > 0; --i) seg[i] = Math.min(seg[i<<1],seg[i<<1|1]);\n\t\t\t\t}\n\n\t\t\tpublic static void modify(int p, long val,int n) { // set value at position p\n\t\t\t\t for (seg[p += n] = val; p > 1; p >>= 1) seg[p>>1] = Math.min(seg[p],seg[p^1]);\n\t\t\t\t}\n\n\t\t\t\tlong query(int l, int r,int n) { // sum on interval [l, r)\n\t\t\t\t long res = Long.MAX_VALUE;\n\t\t\t\t for (l += n, r += n; l < r; l >>= 1, r >>= 1) {\n\t\t\t\t if ((l&1) == 1) res = (long) Math.min(res,seg[l++]);\n\t\t\t\t if ((r&1) == 1) res = (long)Math.min(res,seg[--r]);\n\t\t\t\t }\n\t\t\t\t return res;\n\t\t\t\t}\n\n\t\t\t\t static long bC(int n, int k)\n\t\t\t\t {\n\t\t\t\t long C[][] = new long[n+1][k+1];\n\t\t\t\t int i, j;\n\t\t\t\t \n\t\t\t\t // Calculate value of Binomial Coefficient in bottom up manner\n\t\t\t\t for (i = 0; i <= n; i++)\n\t\t\t\t {\n\t\t\t\t for (j = 0; j <= Math.min(i, k); j++)\n\t\t\t\t {\n\t\t\t\t // Base Cases\n\t\t\t\t if (j == 0 || j == i)\n\t\t\t\t C[i][j] = 1;\n\t\t\t\t \n\t\t\t\t // Calculate value using previosly stored values\n\t\t\t\t else\n\t\t\t\t C[i][j] = C[i-1][j-1] + C[i-1][j];\n\t\t\t\t }\n\t\t\t\t }\n\t\t\t\t \n\t\t\t\t return C[n][k];\n\t\t\t\t }\n\t\t\t\t\n\t\t void solve() throws NumberFormatException, IOException {\n\t\t \n\t\t \tScanner in = new Scanner(System.in);\n\t\t \t\n\t\t \t//HashSet<Long> set = new HashSet();\n\t\t \tlong a = in.nextLong();\n\t\t \tlong b = in.nextLong();\n\t\t \tlong c = in.nextLong();\n\t\t \tlong k = 0;\n\t\t \t\n\t\t \twhile(k<=1000000){\n\t\t \t\ta *=10;\n\t\t \t\tk++;\n\t\t \t\t\n\t\t \t\tif(a/b == c){\n\t\t \t\t\tout.println(k);\n\t\t \t\t\treturn;\n\t\t \t\t}\n\t\t \t\ta%=b;\n\t\t \t}\n\t\t \t\n\t\t \tout.println(-1);\n\t\t }\n\t\t \n\t\t \n\t\t \n\t\t public static void dfs(int i,int j,int d){\n\t\t \t\n\t\t \tSystem.out.println(i + \" \" + j + \" \" +d);\n\t\t \t\n\t\t \tif(d <= ans[i][j]){\n\t\t \t\treturn;\n\t\t \t}\n\t\t \t\n\t\t \tif(i == n-1 && j == m-1){\n\t\t \t\tp = Math.max(p,d);\n\t\t \t\tans[i][j] = p;\n\t\t \t\tarr = brr;\n\t\t \t\treturn;\n\t\t \t}\n\t\t \t\n\t\t \tans[i][j] = d;\n\t\t \tint temp = arr[i][j];\n\t\t \tarr[i][j] = 0;\n\t\t \t\n\t\t \tfor(int p= 0;p<3;p++){\n\t\t \t\tint x = i + dir[p][0];\n\t\t \t\tint y = j + dir[p][1];\n\t\t \t\t\n\t\t \t\tif(x < 0 || x >=n || y < 0 || y >=m){\n\t\t \t\t\tcontinue;\n\t\t \t\t}else{\n\t\t \t\t\t\n\t\t \t\t\tdfs(x,y,d+arr[x][y]);\n\t\t \t\t\t\n\t\t \t\t}\n\t\t \t}\n\t\t \t//arr[i][j] = temp;\n\t\t \t\n\t\t }\n\t\t \n\t\t \n\t\t public static int Floor(int[] dp, int low, int high, long x)\n\t\t {\n\t\t // If low and high cross each other\n\t\t if (low > high)\n\t\t return -1;\n\n\t\t // If last element is smaller than x\n\t\t if (x >= dp[high])\n\t\t return high;\n\n\t\t // Find the middle point\n\t\t int mid = (low+high)/2;\n\n\t\t // If middle point is floor.\n\t\t if (dp[mid] == x)\n\t\t return mid;\n\n\t\t // If x lies between mid-1 and mid\n\t\t if (mid > 0 && dp[mid-1] <= x && x < dp[mid])\n\t\t return mid-1;\n\n\t\t // If x is smaller than mid, floor must be in\n\t\t // left half.\n\t\t if (x < dp[mid])\n\t\t return Floor(dp, low, mid-1, x);\n\n\t\t // If mid-1 is not floor and x is greater than\n\t\t // arr[mid],\n\t\t return Floor(dp, mid+1, high, x);\n\t\t }\n\t\t \n\t\t\n\t\t public static String[] reverse(String arr[]){\n\t\t \t\n\t\t \t\n\t\t \tfor(int i = 0;i<arr.length/2;i++){\n\t\t \t\tString temp = arr[i];\n\t\t \t\tarr[i] = arr[arr.length-i-1];\n\t\t \t\tarr[arr.length-1-i] = temp;\n\t\t \t}\n\t\t \t\n\t\t \treturn arr;\n\t\t \t\n\t\t }\n\t\t\t\n\t\t static long inv(long x , long mod)\n\t\t\t{\n\t\t\t\tlong r,y;\n\t\t\t\tfor(r=1,y=mod-2;y!=0;x=x*x%mod,y>>=1)\n\t\t\t\t{\n\t\t\t\t\tif((y&1)==1)\n\t\t\t\t\t\tr=r*x%mod;\n\t\t\t\t\n\t\t\t\t}\n\t\t\t\treturn r;\n\t\t\t}\n\t\t \n\t\t \n\t\t public static long sum(long x){\n\t\t \treturn x<10?x:x%10 + sum(x/10);\n\t\t }\n\t\t\t\n\t\t\tpublic static long gcd(long x, long y) {\n\t\t\t\tif (x == 0)\n\t\t\t\t\treturn y;\n\t\t\t\telse\n\t\t\t\t\treturn gcd( y % x,x);\n\t\t\t}\n\t\t\n\t\t\t\n\t\t\tpublic static long pow(long x,long y,long n){\n\t\t\t\tif(y==0)\n\t\t\t\t\treturn 1%n;\n\t\t\t\tif(y%2==0){\n\t\t\t\t\tlong z=pow(x,y/2,n);\n\t\t\t\t\treturn (z*z)%n;\n\t\t\t\t}\n\t\t\t\treturn ((x%n)*pow(x,y-1,n))%n;\n\t\t\t}\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\tpublic static boolean isPrime(int n) {\n\t\t\t\t// Corner cases\n\t\t\t\tif (n <= 1)\n\t\t\t\t\treturn false;\n\t\t\t\tif (n <= 3)\n\t\t\t\t\treturn true;\n\t\t \n\t\t\t\t// This is checked so that we can skip \n\t\t\t\t// middle five numbers in below loop\n\t\t\t\tif (n % 2 == 0 || n % 3 == 0)\n\t\t\t\t\treturn false;\n\t\t \n\t\t\t\tfor (int i = 5; i * i <= n; i = i + 6)\n\t\t\t\t\tif (n % i == 0 || n % (i + 2) == 0)\n\t\t\t\t\t\treturn false;\n\t\t \n\t\t\t\treturn true;\n\t\t\t}\n\t\t\t\n\t\t\n\t\t\tvoid run() throws NumberFormatException, IOException {\n\t\t\t\tin = new FastScanner();\n\t\t\t\tout = new PrintWriter(System.out);\n\t\t\n\t\t\t\tsolve();\n\t\t\n\t\t\t\tout.close();\n\t\t\t}\n\t\t\n\t\t\tclass FastScanner {\n\t\t\t\tBufferedReader br;\n\t\t\t\tStringTokenizer st;\n\t\t\n\t\t\t\tpublic FastScanner() {\n\t\t\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t\t}\n\t\t\n\t\t\t\tString next() {\n\t\t\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tst = new StringTokenizer(in.br.readLine());\n\t\t\t\t\t\t} catch (IOException e) {\n\t\t\t\t\t\t\t// TODO Auto-generated catch block\n\t\t\t\t\t\t\te.printStackTrace();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn st.nextToken();\n\t\t\t\t}\n\t\t\n\t\t\t\tint nextInt() {\n\t\t\t\t\treturn Integer.parseInt(next());\n\t\t\t\t}\n\t\t\n\t\t\t\tlong nextLong() {\n\t\t\t\t\treturn Long.parseLong(next());\n\t\t\t\t}\n\t\t\n\t\t\t\tdouble nextDouble() {\n\t\t\t\t\treturn Double.parseDouble(next());\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tclass Tri{\n\t\t\t\t\n\t\t\t\tTri[] arr;\n\t\t\t\t\n\t\t\t\tpublic Tri(){\n\t\t\t\t\tarr = new Tri[27];\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\t\n\t\t\tpublic static void main(String[] args) throws NumberFormatException, IOException {\n\t\t\t\tnew Main().run();\n\t\t\t}\n\t\t}\n\t\t\n\t\t\n\t\tclass Node{\n\t\t\tint a;\n\t\t\tint b;\n\t\t\t\n\t\t}\n\t\t\n\t\tclass MyComp implements Comparator<String>{\n\t\t \n\t\t\tint c = 0;\n\t\t\t\n\t\t\tMyComp(int d){\n\t\t\t\tc = d;\n\t\t\t}\n\t\t\t\n\t\t\t@Override\n\t\t\tpublic int compare(String a,String b) {\n\t\t\t\t\n\t\t\t\t// < == -1\n\t\t\t\t\n\t\t\t\tString arr[] = a.split(\" \");\n\t\t\t\tString brr[] = b.split(\" \");\n\t\t\t\t\n\t\t\t\treturn arr[c].compareTo(brr[c]);\n\t\t\t\t\n\t\t\t\t\n\t\t\t}\n\n\t\t\t\n\t\t}\n\t\t\n\t\tclass MyComp2 implements Comparator<String>{\n\t\t \n\t\t\tint c = 0;\n\t\t\t\n\t\t\tMyComp2(int d){\n\t\t\t\tc = d;\n\t\t\t}\n\t\t\t\n\t\t\t@Override\n\t\t\tpublic int compare(String a,String b) {\n\t\t\t\t\n\t\t\t\t// < == -1\n\t\t\t\t\n\t\t\t\tString arr[] = a.split(\" \");\n\t\t\t\tString brr[] = b.split(\" \");\n\t\t\t\t\n\t\t\t\tint aa = Integer.parseInt(arr[c]);\n\t\t\t\tint bb = Integer.parseInt(brr[c]);\n\t\t\t\t\n\t\t\t\tif(aa>bb){\n\t\t\t\t\treturn 1;\n\t\t\t\t}else{\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t\n\t\t\t}\n\n\t\t\t\n\t\t}\n\t\t\n", "src_uid": "0bc7bf67b96e2898cfd8d129ad486910"} {"source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class A723 {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int[] array = new int[3];\n for (int i = 0; i < array.length; i++)\n array[i] = in.nextInt();\n Arrays.sort(array);\n int length1 = Math.abs(array[1] - array[0]);\n int length2 = Math.abs(array[1] - array[2]);\n System.out.println(length1 + length2);\n\n }\n}\n", "src_uid": "7bffa6e8d2d21bbb3b7f4aec109b3319"} {"source_code": "\nimport java.util.Scanner;\n\npublic class FirstProg {\n\n public static void main(String[] args)\n {\n Scanner b = new Scanner(System.in);\n String a=b.nextLine();\n for(int i=0;i<a.length();i++)\n {\n if(a.charAt(i)=='H'|| a.charAt(i)=='Q'|| a.charAt(i)=='9')\n {\n System.out.println(\"YES\") ;break;\n }\n else\n if(i==a.length()-1)\n System.out.println(\"NO\");\n }\n \n }\n}\n", "src_uid": "1baf894c1c7d5aeea01129c7900d3c12"} {"source_code": " import java.io.*;\nimport java.text.DecimalFormat;\nimport java.util.*;\n public class main2 {\n \tstatic ArrayList<pair> factors;\n \tstatic boolean isComposite[];\n \tstatic ArrayList<Integer> primes;\n \tpublic static boolean isprime(long n){\n \t\tif(n<=10001){\n \t\t\treturn !isComposite[(int)n];\n \t\t}\n \t\tfor(int i=0;i<primes.size();i++){\n \t\t\tif(primes.get(i)*primes.get(i)*1l>n){\n \t\t\t\tbreak;\n \t\t\t}\n \t\t\tif(n%primes.get(i)==0){\n \t\t\t\treturn false;\n \t\t\t}\n \t\t\t\n \t\t}\n \t\treturn true;\n \t}\n \tstatic int[] res;\n \t\n \tpublic static void sieve(int n){\n \t\tisComposite=new boolean[n+1];\n \t\tprimes =new ArrayList<Integer>();\n \t\tisComposite[0]=true;\n \t\tisComposite[1]=true;\n \t\tfor(int i=2;i<=n;i++){\n \t\t\tif(!isComposite[i]){\n \t\t\t\tfor(int j=2*i;j<=n;j=j+i){\n \t\t\t\t\tisComposite[j]=true;\n \t\t\t\t}\n \t\t\t}\n \t\t\tprimes.add(i);\n \t\t}\n \t\t\n \t}\n \tpublic static void primefactors(long n){\n \t\t factors=new ArrayList<pair>();\n \t\tfor(int x:primes){\n \t\t\tif(x*x*1l>n){\n \t\t\t\tbreak;\n \t\t\t}\n \t\t\n \t\t\t\n \t\t\tif(n%x==0){\n \t\t\t\t\n \t\t\t\t\tpair p=new pair(x,0);\n \t\t\t\t\t factors.add(p);\n \t\t\t\twhile(n%x==0){\n \t\t\t\tn/=x;\n \t\t\t\tp.y++;}\n \t\t\t\t\n \t\t\t}\n \t\t}\n \t\tif(n!=1){\n \t\t\tfactors.add(new pair((int)n,1));\n \t\t}\n \t\t\n \t}\n \tpublic static long powfact(long n,long p){\n \t\tint res=0;\n \t\tfor(long i=p;i*1l<=n;i=i*p*1l){\n \t\t\tres+=(n/i);\n \t\t}\n \t\treturn res;\n \t}\n \t\n \tpublic static long GCD(long i, long j){\n \tif (i==0){\n \t\treturn j;\n \t}\n \treturn GCD(j%i,i);\n \t}\n \tpublic static long LCM(long i, long j){\n \t\treturn(i*j)/GCD(i,j);\n \t}\n \n \n \tpublic static void main(String[] args) throws Exception {\n \tScanner sc=new Scanner(System.in);\n \n \t\n \t\nlong n=sc.nextLong();\nlong ra=sc.nextLong();\nlong sa=sc.nextLong();\nlong pa=sc.nextLong();\nlong rb=sc.nextLong();\nlong sb=sc.nextLong();\nlong pb=sc.nextLong();\nlong ra1=ra;\nlong sa1=sa;\nlong pa1=pa;\nlong rb1=rb;\nlong sb1=sb;\nlong pb1=pb;\nlong min=0;\nlong max=0;\n\nra=pb-ra;\nra+=rb;\nif(ra<0){\n\n\tmin+=(-ra);\n}\nsa=rb-sa;\nsa+=sb;\nif(sa<0){\n\tmin+=(-sa);\n}\npa=sb-pa;\npa+=pb;\n\tif(pa<0){\n\t\tmin+=(-pa);\n}\n\nif(sb>=ra1){\n\tmax+=ra1;\n\t\n}\nelse{\n\tmax+=(sb);\n}\nif(pb>=sa1){\n\tmax+=sa1;\n}\nelse{\n\tmax+=(pb);\n}\nif(rb>=pa1){\n\tmax+=pa1;\n\t\n}\nelse{\n\tmax+=(rb);\n}\nSystem.out.println(min+\" \"+max);\n}\n\n\t\n\n \t\n \n \n \n \n \n \tstatic class matrix{\n \t\tint a, b,c, d;\n \t\tpublic matrix(int x,int y, int z,int w){\n \t\t\ta=x;\n \t\t\tb=y;\n \t\t\tc=z;\n \t\t\td=w;\n \t\t}\n \t\t\n \t\tpublic boolean issSem(){\n \t\t\treturn b==c ;\n \t\t}\n \t}\n \tpublic static int p(long x){\n \t\tint t=0;\n \t\twhile(x>1){\n \t\t\tt++;\n \t\t\tx=x/2;\n \t\t}\n \t\treturn t;\n \t}\n static long[] fact;\n public static long fact(int x){\nlong y=(int)Math.pow(2,x)-1;\nreturn((y+1)*(y/2)+(y/2+1));\n} \n \t\n \t\n \tstatic ArrayList<Integer > [] adjlist;\n \tstatic int [] leaves;\n \tstatic PriorityQueue<pair> centroid;\n \t\n \tpublic static void dfs1(int u,int p){\n \t\tleaves[u]=1;\n \t\tif(adjlist[u].size()==1&&u!=0){\n \t\t\t\n \t\t\treturn;\n \t\t}\n \t\tfor( int x:adjlist[u]){\n \t\t\tif(x!=p){\n \t\t\t\tdfs1(x,u);\n \t\t\t\tleaves[u]+=leaves[x];\n \t\t\t}\n \t\t}\n \t}\n \n \t\n \tstatic class pair implements Comparable<pair>{\n \t\tint x;\n \t\tint y;\n \t\tpublic pair(int x, int y){\n \t\t\tthis.x=x;\n \t\t\t\t\tthis.y=y;\n \t\t}\n\t\t\t@Override\n\t\t\tpublic int compareTo(pair o) {\n\t\t\t\t// TODO Auto-generated method stub\n\t\t\t\treturn x-o.x;\n\t\t\t}\n \t}\n \t\n \t \t \tstatic class SegmentTree{\n \t \t \t\tint[] arr , sTree;\n \t \t \tstatic\tint N;\n \t \t \t\tpublic SegmentTree(int[] in){\n \t \t \t\t\tarr=in;\n \t \t \t\tN=arr.length-1;\n \t \t \t\t\tsTree=new int[2*N];\n \t \t \t\t\t\n \t \t \t\t\tbuild(1,1,N);\n \t \t \t\t}\n \t \t \t\tpublic void build(int node, int l, int r){\n \t \t \t\t\tif(l==r){\n \t \t \t\t\t\tsTree[node]=arr[l];\n \t \t \t\t\t}\n \t \t \t\t\telse{\n \t \t \t\t\t\tint leftchild=node*2;\n \t \t \t\t\t\tint rightchild=node*2+1;\n \t \t \t\t\t\tint mid =(l+r)/2;\n \t \t \t\t\t\tbuild(leftchild,l,mid);\n \t \t \t\t\t\tbuild(rightchild,mid+1,r);\n \t \t \t\t\t\tsTree[node]=Math.min(sTree[leftchild],sTree[rightchild]);\n \t \t \t\t\t}\n \t \t \t\t}\n \t \t \t\tpublic void update(int i, int val){\n \t \t \t\t\tint node =i+N-1;\n \t \t \t\t\tarr[i]=val;\n \t \t \t\t\tsTree[node]=val;\n \t \t \t\t\tnode=node/2;\n \t \t \t\t\twhile(node>0){\n \t \t \t\t\tint leftchild=node *2;\n \t \t\t\t\tint rightchild=node*2+1;\n \t \t\t\tsTree[node]=sTree[leftchild]&sTree[rightchild];\n \t \t\t\tnode=node/2;\n \t \t \t\t\t}\n \t \t \t\t\treturn;\n \t \t \t\t\t\n \t \t \t\t}\n \t \t \t\tpublic int query(int i, int j){\n \t \t \t\t\t return query(1,1, N, i, j);\n \t \t \t\t}\n \t \t \t\tpublic int query(int node,int l, int r, int i , int j){\n \t \t \t\t\tif(i>r||j<l){\n \t \t \t\t\t\treturn Integer.MAX_VALUE;\n \t \t \t\t\t}\n \t \t \t\t\tif(i<=l&&r<=j){\n \t \t \t\t\t\treturn sTree[node];\n \t \t \t\t\t}\n \t \t \t\tint leftchild=node*2;\n \t \t\t\t\tint rightchild=node*2+1;\n \t \t\t\t\tint mid =(l+r)/2;\n \t \t\t\t\t\n \t \t\t\treturn\tMath.min(query(leftchild,l,mid,i,j),query(rightchild,mid+1,r,i,j));\n \t \t\t\t\t\n \t \t \t\t}\n \t \t \t}\n \n \n \tstatic class Scanner {\n \t\tStringTokenizer st;\n \t\tBufferedReader br;\n \n \t\tpublic Scanner(InputStream s) {\n \t\t\tbr = new BufferedReader(new InputStreamReader(s));\n \t\t}\n \n \t\tpublic boolean hasNext() {\n \t\t\t// TODO Auto-generated method stub\n \t\t\treturn false;\n \t\t}\n \n \t\tpublic String next() throws IOException {\n \t\t\twhile (st == null || !st.hasMoreTokens())\n \t\t\t\tst = new StringTokenizer(br.readLine());\n \t\t\treturn st.nextToken();\n \t\t}\n \n \t\tpublic int nextInt() throws IOException {\n \t\t\treturn Integer.parseInt(next());\n \t\t}\n \n \t\tpublic long nextLong() throws IOException {\n \t\t\treturn Long.parseLong(next());\n \t\t}\n \n \t\tpublic String nextLine() throws IOException {\n \t\t\treturn br.readLine();\n \t\t}\n \n \t\tpublic double nextDouble() throws IOException {\n \t\t\tString x = next();\n \t\t\tStringBuilder sb = new StringBuilder(\"0\");\n \t\t\tdouble res = 0, f = 1;\n \t\t\tboolean dec = false, neg = false;\n \t\t\tint start = 0;\n \t\t\tif (x.charAt(0) == '-') {\n \t\t\t\tneg = true;\n \t\t\t\tstart++;\n \t\t\t}\n \t\t\tfor (int i = start; i < x.length(); i++)\n \t\t\t\tif (x.charAt(i) == '.') {\n \t\t\t\t\tres = Long.parseLong(sb.toString());\n \t\t\t\t\tsb = new StringBuilder(\"0\");\n \t\t\t\t\tdec = true;\n \t\t\t\t} else {\n \t\t\t\t\tsb.append(x.charAt(i));\n \t\t\t\t\tif (dec)\n \t\t\t\t\t\tf *= 10;\n \t\t\t\t}\n \t\t\tres += Long.parseLong(sb.toString()) / f;\n \t\t\treturn res * (neg ? -1 : 1);\n \t\t}\n \n \t\tpublic boolean ready() throws IOException {\n \t\t\treturn br.ready();\n \t\t}\n \n \t}}", "src_uid": "e6dc3bc64fc66b6127e2b32cacc06402"} {"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<Integer> szList = new ArrayList<>();\n\t\tint leaves = 0;\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint x = nextInt();\n\t\t\tif (x == 1) {\n\t\t\t\tleaves++;\n\t\t\t} else {\n\t\t\t\tszList.add(x);\n\t\t\t}\n\t\t}\n\n\t\tn = szList.size();\n\n\t\tif (leaves <= n) {\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\tif (n == 0) {\n\t\t\treturn true;\n\t\t}\n\n\t\tCollections.sort(szList);\n\t\tCollections.reverse(szList);\n\n\t\tint[] sz = new int[n];\n\t\tfor (int i = 0; i < sz.length; i++) {\n\t\t\tsz[i] = szList.get(i);\n\t\t}\n\n\t\tif (sz[0] != initN) {\n\t\t\treturn false;\n\t\t}\n\n\t\tint[] maskCnt = new int[1 << n];\n\t\tint[] maskSum = new int[1 << n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tmaskCnt[1 << i] = 1;\n\t\t\tmaskSum[1 << i] = sz[i];\n\t\t}\n\n\t\tfor (int mask = 1; mask < (1 << n); mask++) {\n\t\t\tint low = Integer.lowestOneBit(mask);\n\t\t\tmaskCnt[mask] = maskCnt[low] + maskCnt[mask ^ low];\n\t\t\tmaskSum[mask] = maskSum[low] + maskSum[mask ^ low];\n\t\t}\n\n\t\tboolean[][][] dp = new boolean[n + 1][leaves + 1][1 << n];\n\t\t// current node, unassigned leaves, unassigned nodes\n\n\t\tfinal int ALL = (1 << n) - 1;\n\n\t\tdp[0][leaves][ALL ^ 1] = true;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j <= leaves; j++) {\n\t\t\t\tfor (int mask = 0; mask < (1 << n); mask++) {\n\t\t\t\t\tif (!dp[i][j][mask] || test(mask, i)) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tfor (int sub = mask; ; sub = (sub - 1) & mask) {\n\t\t\t\t\t\tint leavesHere = sz[i] - 1 - maskSum[sub];\n\t\t\t\t\t\tif (leavesHere >= 0 && leavesHere <= j\n\t\t\t\t\t\t\t\t&& leavesHere + maskCnt[sub] >= 2) {\n\t\t\t\t\t\t\tdp[i + 1][j - leavesHere][mask ^ sub] = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (sub == 0) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn dp[n][0][0];\n\n\t}\n\n\tstatic boolean test(int mask, int i) {\n\t\treturn ((mask >> i) & 1) == 1;\n\t}\n\n\tvoid inp() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tout.println(solve() ? \"YES\" : \"NO\");\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew GuessTheTree().inp();\n\t}\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (Exception e) {\n\t\t\t\teof = true;\n\t\t\t\treturn null;\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\teof = true;\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}\n", "src_uid": "ed0925cfaee961a3ceebd13b3c96a15a"} {"source_code": "\nimport java.util.Scanner;\n\npublic class E {\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 if (k > n) {\n System.out.println(0);\n System.exit(0);\n }\n long[][] F = new long[n + 1][n + 1];\n long[][] G = new long[n + 1][n + 1];\n long[][] C = new long[n + 1][n + 1];\n int mod = (int) 1e9 + 7;\n for (int i = 0; i <= n; i++)\n for (int j = 0; j <= i; j++)\n if (i == j || j == 0)\n C[i][j] = 1;\n else\n C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;\n F[0][0] = 1;\n G[0][0] = G[1][0] = 1;\n for (int i = 2; i <= n; i++)\n for (int j = 0; j <= n; j++)\n for (int left = 1; left < i; left++) {\n int right = i - left - 1;\n long mul = (C[i - 2][left - 1] * left * Math.max(right, 1))\n % mod;\n // Need root\n for (int kLeft = 0; kLeft < j; kLeft++) {\n int kRight = j - kLeft - 1;\n long notLeft = (G[left][kLeft] * (right == 0\n && kRight == 0 ? 1\n : (F[right][kRight] + G[right][kRight])))\n % mod;\n long notRight = right == 0 ? 0\n : (F[left][kLeft] * G[right][j - kLeft - 1])\n % mod;\n F[i][j] = (F[i][j] + mul * (notLeft + notRight)) % mod;\n }\n // No need root\n for (int kLeft = 0; kLeft <= j; kLeft++)\n G[i][j] = (G[i][j] + mul\n * ((F[left][kLeft] * F[right][j - kLeft]) % mod))\n % mod;\n }\n System.out.println((G[n][k] + F[n][k]) % mod);\n }\n}\n", "src_uid": "f98b740183281943eafd90328854746b"} {"source_code": "// practice with rainboy\nimport java.io.*;\nimport java.util.*;\n\npublic class CF884F extends PrintWriter {\n\tCF884F() { super(System.out, true); }\n\tScanner sc = new Scanner(System.in);\n\tpublic static void main(String[] $) {\n\t\tCF884F o = new CF884F(); o.main(); o.flush();\n\t}\n\n\tstatic final int A = 26, INF = 0x3f3f3f3f;\n\tint[] oo, oh; int __ = 1;\n\tint link(int o, int h) {\n\t\too[__] = o; oh[__] = h;\n\t\treturn __++;\n\t}\n\tint[] ii, jj, cc, cost, cost_; int m_;\n\tint[] ae, pi, dd, ff; int n_;\n\tint[] pq, iq; int cnt;\n\tvoid init() {\n\t\too = new int[1 + m_ * 2]; oh = new int[1 + m_ * 2];\n\t\tii = new int[m_]; jj = new int[m_]; cc = new int[m_ << 1];\n\t\tcost = new int[m_]; cost_ = new int[m_];\n\t\tpi = new int[n_]; dd = new int[n_]; ff = new int[n_];\n\t\tae = new int[n_];\n\t\tpq = new int[1 + n_]; iq = new int[n_];\n\t\tm_ = 0;\n\t}\n\tvoid link_(int i, int j, int c, int co) {\n\t\tint h = m_++;\n\t\tii[h] = i; jj[h] = j; cc[h << 1] = c;\n\t\tcost[h] = co;\n\t\tae[i] = link(ae[i], h << 1);\n\t\tae[j] = link(ae[j], h << 1 | 1);\n\t}\n\tboolean less(int u, int v) {\n\t\treturn pi[u] < pi[v] || pi[u] == pi[v] && dd[u] < dd[v];\n\t}\n\tint i2(int i) {\n\t\treturn (i *= 2) > cnt ? 0 : i < cnt && less(pq[i + 1], pq[i]) ? i + 1 : i;\n\t}\n\tvoid pq_up(int u) {\n\t\tint i, j, v;\n\t\tfor (i = iq[u]; (j = i / 2) > 0 && less(u, v = pq[j]); i = j)\n\t\t\tpq[iq[v] = i] = v;\n\t\tpq[iq[u] = i] = u;\n\t}\n\tvoid pq_dn(int u) {\n\t\tint i, j, v;\n\t\tfor (i = iq[u]; (j = i2(i)) > 0 && less(v = pq[j], u); i = j)\n\t\t\tpq[iq[v] = i] = v;\n\t\tpq[iq[u] = i] = u;\n\t}\n\tvoid pq_add_last(int u) {\n\t\tpq[iq[u] = ++cnt] = u;\n\t}\n\tint pq_remove_first() {\n\t\tint u = pq[1], v = pq[cnt--];\n\t\tif (v != u) {\n\t\t\tiq[v] = 1; pq_dn(v);\n\t\t}\n\t\tiq[u] = 0;\n\t\treturn u;\n\t}\n\tboolean dijkstra(int s, int t) {\n\t\tArrays.fill(pi, INF);\n\t\tpi[s] = 0; pq_add_last(s);\n\t\twhile (cnt > 0) {\n\t\t\tint i = pq_remove_first();\n\t\t\tint d = dd[i] + 1;\n\t\t\tfor (int o = ae[i]; o != 0; o = oo[o]) {\n\t\t\t\tint h_ = oh[o];\n\t\t\t\tif (cc[h_] > 0) {\n\t\t\t\t\tint h = h_ >> 1;\n\t\t\t\t\tint j = i ^ ii[h] ^ jj[h];\n\t\t\t\t\tint p = pi[i] + ((h_ & 1) == 0 ? cost_[h] : -cost_[h]);\n\t\t\t\t\tif (pi[j] > p || pi[j] == p && dd[j] > d) {\n\t\t\t\t\t\tif (pi[j] == INF)\n\t\t\t\t\t\t\tpq_add_last(j);\n\t\t\t\t\t\tpi[j] = p; dd[j] = d; ff[j] = h_;\n\t\t\t\t\t\tpq_up(j);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn pi[t] != INF;\n\t}\n\tint trace(int s, int t) {\n\t\twhile (t != s) {\n\t\t\tint h_ = ff[t], h = h_ >> 1;\n\t\t\tcc[h_]--; cc[h_ ^ 1]++;\n\t\t\tt ^= ii[h] ^ jj[h];\n\t\t}\n\t\treturn 1;\n\t}\n\tint edmonds_karp(int s, int t) {\n\t\tfor (int h = 0; h < m_; h++) {\n\t\t\tint i = ii[h], j = jj[h];\n\t\t\tpi[j] = Math.min(pi[j], pi[i] + cost[h]);\n\t\t}\n\t\tfor (int h = 0; h < m_; h++) {\n\t\t\tint i = ii[h], j = jj[h];\n\t\t\tcost_[h] = cost[h] + pi[i] - pi[j];\n\t\t}\n\t\tint f = 0;\n\t\twhile (dijkstra(s, t)) {\n\t\t\tf += trace(s, t);\n\t\t\tfor (int h = 0; h < m_; h++) {\n\t\t\t\tint i = ii[h], j = jj[h];\n\t\t\t\tif (pi[i] != INF && pi[j] != INF) {\n\t\t\t\t\t// pi[j] <= pi[i] + cost_[h]\n\t\t\t\t\t// cost_[h] + pi[i] - pi[j] >= 0\n\t\t\t\t\tcost_[h] += pi[i] - pi[j];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint ans = 0;\n\t\tfor (int h = 0; h < m_; h++)\n\t\t\tans += cc[h << 1 | 1] * cost[h];\n\t\treturn ans;\n\t}\n\tvoid main() {\n\t\tint n = sc.nextInt() / 2;\n\t\tn_ = 1 + n + A + 1;\n\t\tm_ = n + n * A + A;\n\t\tinit();\n\t\tbyte[] cc = sc.next().getBytes();\n\t\tint[] bb = new int[n * 2];\n\t\tfor (int i = 0; i < n * 2; i++)\n\t\t\tbb[i] = sc.nextInt();\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tlink_(0, 1 + i, 2, 0);\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint j = n * 2 - 1 - i;\n\t\t\tint ai = cc[i] - 'a';\n\t\t\tint aj = cc[j] - 'a';\n\t\t\tfor (int a = 0; a < A; a++) {\n\t\t\t\tint b;\n\t\t\t\tif (a == ai && a == aj)\n\t\t\t\t\tb = Math.max(bb[i], bb[j]);\n\t\t\t\telse if (a == ai)\n\t\t\t\t\tb = bb[i];\n\t\t\t\telse if (a == aj)\n\t\t\t\t\tb = bb[j];\n\t\t\t\telse\n\t\t\t\t\tb = 0;\n\t\t\t\tlink_(1 + i, 1 + n + a, 1, -b);\n\t\t\t}\n\t\t}\n\t\tint[] kk = new int[A];\n\t\tfor (int i = 0; i < n * 2; i++) {\n\t\t\tint a = cc[i] - 'a';\n\t\t\tkk[a]++;\n\t\t}\n\t\tfor (int a = 0; a < A; a++)\n\t\t\tlink_(1 + n + a, n_ - 1, kk[a], 0);\n\t\tprintln(-edmonds_karp(0, n_ - 1));\n\t}\n}\n", "src_uid": "896555ddb6e1c268cd7b3b6b063fce50"} {"source_code": "\nimport java.util.*;\n\n\npublic class Main {\n\n public static void main(String[] args) {\n\n \n Scanner sc=new Scanner(System.in);\n long x=sc.nextLong();\n String stx=x+\"\";\n long y=sc.nextLong();\n \n int sumx=0;\n \n for(int i=0;i<stx.length();i++){\n sumx+=Integer.parseInt(stx.charAt(i)+\"\");\n }\n \n sumx=Math.max(sumx, ((Integer.parseInt(stx.charAt(0)+\"\")-1)+(9*(stx.length()-1))));\n \n int count=0;\n \n if(x<y){System.out.println(\"0\");}\n else{\n for(long i =y;i<=x;i++){\n String st_temp=i+\"\";\n int sub_temp=0;\n for(int j=0;j<st_temp.length();j++){\n sub_temp+=Integer.parseInt(st_temp.charAt(j)+\"\");\n }\n if((i-sub_temp)<y){count++;}\n else{break;}\n \n }\n System.out.println(x-(count+y)+1);\n }\n \n \n }\n \n}\n", "src_uid": "9704e2ac6a158d5ced8fd1dc1edb356b"} {"source_code": "import java.math.BigInteger;\nimport java.util.*;\n\n\npublic class Main {\n\n public static void main(String[] args) {\n\n Scanner input=new Scanner(System.in);\n\n long n=input.nextLong();\n\n boolean f;\n long p=n;\n while(p>1){\n \n f=false;\n for(long i=2;(i*i)<=p && !f;i++){\n if(p%(i*i)==0){\n p=p/i;\n //System.out.println(i);\n f=true;\n }\n }\n \n if(!f)\n break;\n }\n \n System.out.println(p);\n }\n}\n", "src_uid": "6d0da975fa0961acfdbe75f2f29aeb92"} {"source_code": "\nimport java.util.Scanner;\n\n/**\n *\n * @author Pc\n */\npublic class TEST {\n\n public static String reverse(String s) {\n String reverse = \"\";\n for (int i = s.length() - 1; i >= 0; i--) {\n reverse += s.charAt(i);\n }\n return reverse;\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 String s1, s2;\n \n for (int i = 1; i <= n/2; i++) {\n\n if (n % i == 0) {\n s1 = s.substring(0, i);\n s2 = s.substring(i);\n s1 = reverse(s1);\n s = s1 + s2;\n \n }\n }\n s = reverse(s);\n System.out.println(s);\n }\n}\n", "src_uid": "1b0b2ee44c63cb0634cb63f2ad65cdd3"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class towerhanoi {\n private static Reader in;\n private static PrintWriter out;\n public static int[][] cost = new int[3][3];\n\n public static void main(String[] args) throws IOException {\n in = new Reader();\n out = new PrintWriter(System.out, true);\n for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++)\n cost[i][j] = in.nextInt();\n int N = in.nextInt();\n dp = new long[N+1][3][3];\n for (int i = 0; i <= N; i++)\n for (int j = 0; j < 3; j++)\n for (int k = 0; k < 3; k++)\n dp[i][j][k] = -1;\n out.println(solve(N, 0, 2));\n }\n \n public static long[][][] dp;\n public static long solve (int disks, int from, int to) {\n if (disks == 0) return 0;\n if (dp[disks][from][to] != -1) return dp[disks][from][to];\n int other = 3 - from - to;\n return dp[disks][from][to] = Math.min(\n solve(disks-1, from, other) + cost[from][to] + solve(disks-1, other, to),\n solve(disks-1, from, to) + cost[from][other] + solve(disks-1, to, from)\n + cost[other][to] + solve(disks-1, from, to));\n }\n\n static class Reader {\n final private int BUFFER_SIZE = 1 << 16;\n private DataInputStream din;\n private byte[] buffer;\n private int bufferPointer, bytesRead;\n\n public Reader() {\n din = new DataInputStream(System.in);\n buffer = new byte[BUFFER_SIZE];\n bufferPointer = bytesRead = 0;\n }\n\n public Reader(String file_name) throws IOException {\n din = new DataInputStream(new FileInputStream(file_name));\n buffer = new byte[BUFFER_SIZE];\n bufferPointer = bytesRead = 0;\n }\n\n public String readLine() throws IOException {\n byte[] buf = new byte[1024];\n int cnt = 0;\n byte c = read();\n while (c <= ' ')\n c = read();\n do {\n buf[cnt++] = c;\n } while ((c = read()) != '\\n');\n return new String(buf, 0, cnt);\n }\n\n public String next() throws IOException {\n byte[] buf = new byte[1024];\n int cnt = 0;\n byte c = read();\n while (c <= ' ')\n c = read();\n do {\n buf[cnt++] = c;\n } while ((c = read()) > ' ');\n return new String(buf, 0, cnt);\n }\n\n public int nextInt() throws IOException {\n int ret = 0;\n byte c = read();\n while (c <= ' ')\n c = read();\n boolean neg = (c == '-');\n if (neg)\n c = read();\n do {\n ret = ret * 10 + c - '0';\n } while ((c = read()) >= '0' && c <= '9');\n if (neg)\n return -ret;\n return ret;\n }\n\n public long nextLong() throws IOException {\n long ret = 0;\n byte c = read();\n while (c <= ' ')\n c = read();\n boolean neg = (c == '-');\n if (neg)\n c = read();\n do {\n ret = ret * 10 + c - '0';\n } while ((c = read()) >= '0' && c <= '9');\n if (neg)\n return -ret;\n return ret;\n }\n\n public double nextDouble() throws IOException {\n double ret = 0, div = 1;\n byte c = read();\n while (c <= ' ')\n c = read();\n boolean neg = (c == '-');\n if (neg)\n c = read();\n do {\n ret = ret * 10 + c - '0';\n } while ((c = read()) >= '0' && c <= '9');\n if (c == '.')\n while ((c = read()) >= '0' && c <= '9')\n ret += (c - '0') / (div *= 10);\n if (neg)\n return -ret;\n return ret;\n }\n\n private void fillBuffer() throws IOException {\n bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n if (bytesRead == -1)\n buffer[0] = -1;\n }\n\n private byte read() throws IOException {\n if (bufferPointer == bytesRead)\n fillBuffer();\n return buffer[bufferPointer++];\n }\n\n public void close() throws IOException {\n if (din == null)\n return;\n din.close();\n }\n }\n\n\n}\n", "src_uid": "c4c20228624365e39299d0a6e8fe7095"} {"source_code": "import java.util.Scanner;\npublic class prob59A{\n public static void main (String[] args){\n Scanner s=new Scanner(System.in);\n //System.out.println(\"enter word?\");\n String x = s.next();\n toupperorlower(x);\n }\n public static void toupperorlower(String word) {\n char ch[] = new char[word.length()];\n String z = word.toLowerCase();\n char x[] = new char[word.length()];\n for (int i = 0; i < ch.length; i++) {\n ch[i] = word.charAt(i);\n }\n for (int i = 0; i < ch.length; i++) {\n x[i] = z.charAt(i);\n }\n int lower = 0;\n int upper = 0;\n for (int i = 0; i < ch.length; i++) {\n if (x[i] == ch[i]) {\n lower++;\n }\n if (x[i] != ch[i]) {\n upper++;\n }\n\n }\n if (upper > lower) {\n System.out.println(word.toUpperCase());\n }\n if (lower >= upper) {\n System.out.println(word.toLowerCase());\n }\n\n }\n}", "src_uid": "b432dfa66bae2b542342f0b42c0a2598"} {"source_code": "import java.util.*;\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.text.DecimalFormat;\nimport java.lang.ArrayIndexOutOfBoundsException;\nimport java.lang.Exception;\nimport java.lang.ArithmeticException;\nimport java.lang.InterruptedException;\nimport java.lang.NullPointerException;\npublic class Test{\n\t static Scanner s = new Scanner(System.in);\n\t static int _I(){int x=s.nextInt(); return x;}\n\t static long _ll(){long l=s.nextLong(); return l;}\n\t static double _d(){double x=s.nextDouble(); return x;}\n\t static String _S(){String str=s.nextLine(); return str;}\n\t static int gcd(int x,int y){return y==0 ? x:gcd(y,x%y);}\n\t static int lcm(int x,int y){return x*y;}\n\t long ar[]=new long[100000];\n\t\n\tpublic static void solve(){\n\t\tDecimalFormat d= new DecimalFormat(\"00\");\n\t\tString str=Test._S();\n\t\tint t=Test._I();\n\t\tString ss[]=str.split(\":\");\n\t\tInteger hh=Integer.parseInt(ss[0]);\n\t\tInteger mm=Integer.parseInt(ss[1]);\n\t\tmm=mm+t;\n\t\tif(mm>=60){\n\t\t\thh=hh+mm/60;\n\t\t\tmm=mm%60;\n\t\t\tif(hh>23){\n\t\t\t\thh=hh%24;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(d.format(hh)+\":\"+d.format(mm));\n\t}\n\tpublic static void main_field(){\n\t\t\n\t\tTest.solve();\n\t}\n\tpublic static void main(String[] args){\n\t\tTest t = new Test();\n\t\tTest.main_field();\n\t\t\n\t}\n}", "src_uid": "20c2d9da12d6b88f300977d74287a15d"} {"source_code": "\nimport java.util.Scanner;\n\npublic class Main {\n\n static long xo=0,yo=0, GCD=0;\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n long n = sc.nextLong();\n long p = sc.nextLong();\n long w = sc.nextLong();\n long d = sc.nextLong();\n long x, y,z;\n \n long g = GCD(w,d);\n\n\n if(p%g!=0){\n System.out.println(\"-1\");\n return;\n }\n\n if(n*w<p){\n // this is when he won all matches but\n // points are not equal to p\n System.out.println(\"-1\");\n return;\n }\n\n p/=g;\n w/=g;\n d/=g;\n\n\n y = ((p%w) * inverseModulo(d,w))%w;\n x = (p-y*d)/w;\n if(x+y>n){\n //if number of wins and draw is greater than total number of matches\n System.out.println(\"-1\");\n return;\n }\n\n if(x<0){\n System.out.println(\"-1\");\n return;\n }\n\n z = n-(x+y);\n System.out.println(x+\" \"+y+\" \"+z);\n\n\n }\n\n private static long inverseModulo(long a, long m) {\n if(m==1)return 0;\n long m0 =m,x =1,y=0;\n\n while(a>1){\n long q = a/m , t =m;\n m = a%m; a=t;\n t =y;\n y = x - q * y;\n x =t;\n\n\n }\n\n if(x<0) x+=m0;\n return x;\n\n }\n\n private static void ExtendedEuclid(long a, long b){\n //base case\n\n if (b == 0) {\n\n xo =1;\n yo=0;\n GCD = a;\n return;\n }\n\n ExtendedEuclid(b,a%b);\n\n long cX = yo;\n long cy = xo - (a/b)*yo;\n\n xo = cX;\n yo = cy;\n }\n\n private static long GCD(long a, long b){\n return b==0 ? a: GCD(b,a%b);\n }\n}\n", "src_uid": "503116e144d19eb953954d99c5526a7d"} {"source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint doors = sc.nextInt();\n\t\tint floors = sc.nextInt();\n\t\tint flats = sc.nextInt();\n\t\tint from = sc.nextInt();\n\t\tint to = sc.nextInt();\n\t\t\n\t\tint from_flat = (from - 1)% flats;\n\t\tint from_floor = \n\t\t\t\t((from - from_flat - 1)% (floors*flats))/flats ;\n\t\t\n\t\tint from_door = (from - from_floor * flats -from_flat - 1) / \n\t\t\t\t(floors*flats);\n\t\t\n\t\t\n\t\tint to_flat = (to - 1)% flats;\n\t\tint to_floor = \n\t\t\t\t((to - to_flat - 1)% (floors*flats))/flats ;\n\t\t\n\t\tint to_door = (to - to_floor * flats - to_flat - 1) / \n\t\t\t\t(floors*flats);\n\t\t\n\t\tint time = 0;\n\t\tif(to_door == from_door){\n\t\t\ttime += Math.min(Math.abs(to_floor - from_floor) * 5,\n\t\t\t\t\t10 + Math.abs(to_floor - from_floor));\n\t\t\t//System.out.println(time);\n\t\t} else {\n\t\t\ttime += Math.min(Math.abs(from_floor - 0) * 5,\n\t\t\t\t\t10 + Math.abs(from_floor - 0));\n\t\t\t//System.out.println(time);\n\t\t\ttime += 15 * Math.min(doors - Math.abs(to_door - from_door),\n\t\t\t\t\tMath.abs(to_door - from_door));\n\t\t\t//System.out.println(time);\n\t\t\ttime += Math.min(Math.abs(to_floor - 0) * 5,\n\t\t\t\t\t10 + Math.abs(to_floor - 0));\n\t\t\t//System.out.println(time);\n\t\t}\n\t\tSystem.out.println(time);\n\t}\n}\n", "src_uid": "c37b46851abcf7eb472869bd1ab9f793"} {"source_code": "\nimport java.util.*;\n\npublic class CODE {\n\n static Scanner sc = new Scanner(System.in);\n\n public static void main(String[] args) {\n int n = sc.nextInt();\n int arr[] = new int[2 * n];\n int count = 0;\n HashSet<Integer> set = new HashSet<>();\n\n for (int i = 0; i < 2 * n; i++) {\n arr[i] = sc.nextInt();\n set.add(arr[i]);\n }\n\n for (int i = 0; i < 2 * n; i++) {\n for (int j = i; j < 2 * n; j++) {\n if (set.contains(arr[i] ^ arr[j])) {\n count++;\n if (arr[i] != arr[j]) {\n count++;\n }\n }\n }\n }\n\n System.out.println(count % 2 == 0 ? \"Karen\" : \"Koyomi\");\n }\n}\n", "src_uid": "1649d2592eadaa8f8d076eae2866cffc"} {"source_code": "import java.io.*;\nimport java.util.*;\nimport java.util.regex.*;\npublic class vk18\n{\n public static void main(String[]stp) throws Exception\n {\n \tScanner scan=new Scanner(System.in);\n \tPrintWriter pw = new PrintWriter(System.out);\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer st=new StringTokenizer(br.readLine());\n long n=Long.parseLong(st.nextToken()),m=0;\n st=new StringTokenizer(br.readLine());\n long k=Long.parseLong(st.nextToken());\n st=new StringTokenizer(br.readLine());\n long a=Long.parseLong(st.nextToken());\n st=new StringTokenizer(br.readLine());\n long b=Long.parseLong(st.nextToken());\n\t\tlong ans=0;\n\t\tif(k==1) { ans+=(n-1)*a; n=1; }\n\t\twhile(n>1)\n\t\t{\n\t\t\tif(n%k==0)\n\t\t\t{\n\t\t\t\tm=n%k;\n\t\t\t\tans+=Math.min(b,(n-n/k)*a);\n\t\t\t\tn/=k;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tm=(n%k);\n\t\t\t\tif(n == m) { ans+=(n-1)*a; break; }\n\t\t\t\tans+=(m)*a;\n\t\t\t\tn-=(n%k);\n\n\t\t\t}\n\t\t}\n\t\tpw.print(ans); \n pw.flush();\n }\n\n \n}", "src_uid": "f838fae7c98bf51cfa0b9bd158650b10"} {"source_code": "/**\n * Created with IntelliJ IDEA.\n * User: Sergey Epifanov\n * Date: 5/19/12\n */\nimport java.io.*;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class B {\n public static void main(String args[]) throws IOException {\n new B().run();\n }\n\n private Scanner in;\n private PrintWriter out;\n\n private void run() throws IOException {\n boolean online = System.getProperty(\"ONLINE_JUDGE\") != null;\n in = online ? new Scanner(System.in) :\n new Scanner(new FileReader(\"input.txt\"));\n out = online ? new PrintWriter(System.out) :\n new PrintWriter(new FileWriter(\"output.txt\"));\n solve();\n out.flush();\n out.close();\n }\n\n private void solve() throws IOException {\n\n // input\n long w = in.nextInt();\n long h = in.nextInt();\n long w2 = w/2 * (w - w/2);\n long h2 = h/2 * (h - h/2);\n long res = w2 * h2;\n out.println(res);\n }\n}\n", "src_uid": "42454dcf7d073bf12030367eb094eb8c"} {"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 C_Round_253_Div1 {\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\tfinal int[] data = new int[n];\n\t\tfinal TreeSet<Integer> set = new TreeSet();\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tset.add(i);\n\n\t\t\tdata[i] = in.nextInt();\n\n\t\t}\n\t\tlong result = 0;\n\t\tboolean[] check = new boolean[n];\n\n\t\tLinkedList<Integer> tmp = new LinkedList();\n\t\tboolean[] inS = new boolean[n];\n\t\tfor (int i = 1; i + 1 < n; i++) {\n\t\t\tif (!check[i]) {\n\t\t\t\tinS[i] = true;\n\t\t\t\ttmp.add(i);\n\t\t\t\twhile (!tmp.isEmpty()) {\n\t\t\t\t\tint v = tmp.poll();\n\t\t\t\t\tinS[v] = false;\n\t\t\t\t\tif (check[v]) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tInteger a = set.lower(v);\n\t\t\t\t\tInteger b = set.higher(v);\n\t\t\t\t\tif (a != null && b != null && data[a] >= data[v]\n\t\t\t\t\t\t\t&& data[v] <= data[b]) {\n\t\t\t\t\t\tcheck[v] = true;\n\t\t\t\t\t\tset.remove(v);\n\n\t\t\t\t\t\tresult += (long) Math.min(data[a], data[b]);\n\t\t\t\t\t\tif (!inS[a])\n\t\t\t\t\t\t\ttmp.add(a);\n\t\t\t\t\t\tif (!inS[b])\n\t\t\t\t\t\t\ttmp.add(b);\n\t\t\t\t\t\t// System.out.println(set + \" \" + v + \" \" + result + \" \"\n\t\t\t\t\t\t// + a + \" \" + b);\n\t\t\t\t\t}\n\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tTreeSet<Integer> list = new TreeSet(new Comparator<Integer>() {\n\n\t\t\t@Override\n\t\t\tpublic int compare(Integer o1, Integer o2) {\n\t\t\t\tint a = set.lower(o1);\n\t\t\t\tint b = set.higher(o1);\n\t\t\t\tint c = set.lower(o2);\n\t\t\t\tint d = set.higher(o2);\n\t\t\t\ta = Math.min(data[a], data[b]);\n\t\t\t\tc = Math.min(data[c], data[d]);\n\t\t\t\treturn a - c;\n\t\t\t}\n\t\t});\n\t\tfor (int i = 1; i + 1 < n; i++) {\n\t\t\tif (!check[i]) {\n\t\t\t\tlist.add(i);\n\t\t\t}\n\t\t}\n\t\twhile(!list.isEmpty()){\n\t\t\tint v = list.pollLast();\n\t\t\tset.remove(v);\n\t\t\tint a = set.lower(v);\n\t\t\tint b = set.higher(v);\n\t\t\tint c = Math.min(data[a], data[b]);\n\t\t\tresult += c;\n\t\t\tif(a != 0){\n\t\t\t\tlist.remove(a);\n\t\t\t\tlist.add(a);\n\t\t\t}\n\t\t\tif(b != n -1){\n\t\t\t\tlist.remove(b);\n\t\t\t\tlist.add(b);\n\t\t\t}\n\t\t\t//System.out.println(list);\n\t\t\t\n\t\t}\n\t\tout.println(result);\n\n\t\tout.close();\n\t}\n\n\tpublic static int[] KMP(String val) {\n\t\tint i = 0;\n\t\tint j = -1;\n\t\tint[] result = new int[val.length() + 1];\n\t\tresult[0] = -1;\n\t\twhile (i < val.length()) {\n\t\t\twhile (j >= 0 && val.charAt(j) != val.charAt(i)) {\n\t\t\t\tj = result[j];\n\t\t\t}\n\t\t\tj++;\n\t\t\ti++;\n\t\t\tresult[i] = j;\n\t\t}\n\t\treturn result;\n\n\t}\n\n\tpublic static boolean nextPer(int[] data) {\n\t\tint i = data.length - 1;\n\t\twhile (i > 0 && data[i] < data[i - 1]) {\n\t\t\ti--;\n\t\t}\n\t\tif (i == 0) {\n\t\t\treturn false;\n\t\t}\n\t\tint j = data.length - 1;\n\t\twhile (data[j] < data[i - 1]) {\n\t\t\tj--;\n\t\t}\n\t\tint temp = data[i - 1];\n\t\tdata[i - 1] = data[j];\n\t\tdata[j] = temp;\n\t\tArrays.sort(data, i, data.length);\n\t\treturn true;\n\t}\n\n\tpublic static int digit(long n) {\n\t\tint result = 0;\n\t\twhile (n > 0) {\n\t\t\tn /= 10;\n\t\t\tresult++;\n\t\t}\n\t\treturn result;\n\t}\n\n\tpublic static double dist(long a, long b, long x, long y) {\n\t\tdouble val = (b - a) * (b - a) + (x - y) * (x - y);\n\t\tval = Math.sqrt(val);\n\t\tdouble other = x * x + a * a;\n\t\tother = Math.sqrt(other);\n\t\treturn val + other;\n\n\t}\n\n\tpublic static class Point implements Comparable<Point> {\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 y - o.y;\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", "src_uid": "e7e0f9069166fe992abe6f0e19caa6a1"} {"source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\n \n \n \npublic class B {\n \n static MyScanner in = new MyScanner();\n static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));\n static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n static StringTokenizer st;\n static long H,W;\n static BitSet bs;\n static long mod = 1000000007;\n // All possible moves of a knight \n static int X[] = { 2, 1, -1, -2, -2, -1, 1, 2 }; \n static int Y[] = { 1, 2, 2, 1, -1, -2, -2, -1 }; \n static int [] dr = {-1,0,0,1};\n static int [] dc = {0,1,-1,0};\n static int [][] grid = new int[3][3];\n static int R1 =0;\n static int R2 = 0;\n static int R3=0;\n static int C1 = 0;\n static int C2 = 0;\n static int C3 = 0;\n static int D1 = 0;\n static int D2 = 0;\n \n public static void main(String args[]) throws IOException {\n /**\n1.What is the unknown:\n2.What are the data: an array of tlen ght the value is 10^9\n3.What is the condition: \n4. understand the problem:\n5. What are the cases edges in the problem:\n6.What what max:\n7. Are you using a data stcuture. And which one:\n8.Is there reursion what is the base case. For example COINS:\n*/\n for(int i=0;i<3;i++)\n for(int j=0;j<3;j++)\n grid[i][j] = in.nextInt();\n boolean stop = false;\n for(int i=1;i<=1000000&&!stop;i++){\n //set a[0][0] = 1\n grid[0][0] = i;\n if(firstCol()==firstRow()){\n int newVal = firstCol()-secondRow();\n grid[1][1] = newVal;\n if(secondRow()==secondCol()&&secondRow()==firstCol()&&newVal >0){\n int val = firstCol()-thirdCol();\n grid[2][2] = val;\n if(secondRow()==secondCol()&&secondRow()==firstCol()&&thirdCol()==thirdRow()&&val>0&&topLeftAndButtomRight()==bottumLeftAdnTopRight()){\n printTwoDArray();\n stop = true;\n }\n grid[2][2] = 0;\n }\n grid[1][1] = 0;\n }\n grid[0][0] = 0;\n\n }\n \n out.flush();\n }\n private static int topLeftAndButtomRight (){\n int sum=0;\n for(int i=0;i<3;i++)\n sum+=grid[i][i];\n return sum;\n }\n private static int bottumLeftAdnTopRight (){\n int sum=0;\n for(int i=2;i>=0;i--)\n sum+=grid[i][2-i];\n return sum;\n }\n private static void printTwoDArray() {\n for(int i=0;i<grid.length;i++){\n for(int j=0;j<grid[i].length;j++){\n out.print(grid[i][j]+\" \");\n }\n out.print(\"\\n\");\n }\n }\n\n public static int firstRow() {\n int sum=0;\n for(int i=0;i<3;i++)\n sum+=grid[0][i];\n return sum;\n }\n public static int secondRow(){\n int sum=0;\n for(int i=0;i<3;i++)\n sum+=grid[1][i];\n return sum;\n } public static int thirdRow(){\n int sum=0;\n for(int i=0;i<3;i++)\n sum+=grid[2][i];\n return sum;\n }\n public static int thirdCol(){\n int sum=0;\n for(int i=0;i<3;i++)\n sum+=grid[i][2];\n return sum;\n }\n public static int secondCol(){\n int sum=0;\n for(int i=0;i<3;i++)\n sum+=grid[i][1];\n return sum;\n }\n public static int firstCol (){\n int sum=0;\n for(int i=0;i<3;i++)\n sum+=grid[i][0];\n return sum;\n }\n public static boolean subseqeunce(String s, String t){\n for(int i=0,j=0;i<s.length();i++){\n if(j<t.length()&&s.charAt(i)==t.charAt(j)){\n j++;\n }\n if(j==t.length()) return true;\n }\n return false;\n }\n\n \n private static int lowrBound(int[] a, int lo, int hi, int element) {\n while(lo<hi){\n int mid = lo+(hi-lo)/2;\n if(element>a[mid]){\n lo = mid+1;\n }else{\n hi = mid;\n }\n }\n if(lo<a.length&&a[lo]==element){\n return lo+1;\n }\n return lo;\n }\n\n static long lcm(int a, int b) {\n return (a*b)/gcd(a, b);\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<IP>{\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 @Override\n public String toString() {\n return first+\" \"+second;\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}", "src_uid": "0c42eafb73d1e30f168958a06a0f9bca"} {"source_code": "import java.io.*;\nimport java.util.*;\n\n\npublic class P1599C {\n public static void main(String[] args) throws IOException {\n MyScanner scanner = new MyScanner(System.in);\n PrintWriter writer = new PrintWriter(System.out);\n\n int n = scanner.nextInt();\n double p = scanner.nextDouble();\n\n int lo = 0, hi = n, ans = n;\n while (lo <= hi) {\n int m = (lo + hi) / 2;\n if (chance(n, m) >= p) {\n hi = m - 1;\n ans = m;\n } else {\n lo = m + 1;\n }\n }\n writer.println(ans);\n\n writer.flush();\n }\n\n private static double chance(int n, int m) {\n double p = 0.0;\n\n if (m >= 3) {\n p += comb(m, 3);\n }\n if (m >= 2 && n - m >= 1) {\n p += comb(m, 2) * comb(n - m, 1); \n }\n if (m >= 1 && n - m >= 2) {\n p += comb(m, 1) * comb(n - m, 2) / 2.0;\n }\n\n return p / comb(n, 3);\n }\n\n private static long comb(int from, int pick) {\n long ans = 1;\n for (int i = 0; i < pick; i++) {\n ans *= from - i;\n }\n for (int i = 2; i <= pick; i++) {\n ans /= i;\n }\n\n return (int)ans;\n }\n\n private static class MyScanner {\n private BufferedReader reader;\n private StringTokenizer st;\n\n public MyScanner(InputStream inputStream) {\n reader = new BufferedReader(new InputStreamReader(inputStream));\n }\n\n private String nextToken() throws IOException {\n while(st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(reader.readLine());\n }\n return st.nextToken();\n }\n\n public int nextInt() throws IOException {\n return Integer.parseInt(nextToken());\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(nextToken());\n }\n\n public double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n }\n}", "src_uid": "788ed59a964264bd0e755e155a37e14d"} {"source_code": "import java.util.Scanner;\n\npublic class CF236_1 {\n\n \n \n \n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int k = in.nextInt();\n int a = in.nextInt();\n int b = in.nextInt();\n int v = in.nextInt();\n \n \n if (k > b) {\n int i; \n for (i = 0; a > 0; i++) {\n \n if (b > 0) {\n for (int j = 0; b >= 0; b--) {\n a = a - v;\n } \n }else {\n a = a - v;\n }\n }\n System.out.println(i); \n } else {\n //\n int i;\n for (i = 0; a > 0; i++) {\n if (b>=0){\n for (int j = 0; (b >= 0)&(j < k) ; j++) {\n a = a - v;\n b--;\n }\n b = b+1;\n }else a = a - v;\n \n }\n System.out.println(i);\n }\n \n \n \n \n }\n}", "src_uid": "7cff20b1c63a694baca69bdf4bdb2652"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashSet;\nimport java.util.Scanner;\nimport java.util.StringTokenizer;\n\npublic class C {\n\tpublic static long [] fac;\n\tpublic static long [][] comb;\n\tpublic static long mod= 998244353;\n\tpublic static void main(String[] args) throws IOException {\n\t\tFastScanner in= new FastScanner(System.in);\n\t\tPrintWriter out= new PrintWriter(System.out);\n\t\tint a= in.nextInt();\n\t\tint b= in.nextInt();\n\t\tint c= in.nextInt();\n\n\t\tcomb= new long[5001][5001];\n\t\tfac= new long[5001];\n\t\tfac[0]=1;\n\t\tfor (long i = 1; i < fac.length; i++) {\n\t\t\tfac[(int)i]= (fac[(int) (i-1)]*i)%mod;\n\t\t}\n\t\tcomb[0][0]= 1;\n\t\tfor (int i=1;i<=5000;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-1]+comb[i-1][j])%mod;\n\t\t}\n\t\tlong res=1;\n\t\tres= (res*go(a,b))%mod;\n\t\tres= (res*go(b,c))%mod;\n\t\tres= (res*go(a,c))%mod;\n\t\t\n\t\tSystem.out.println(res);\n\t\t\n\t}\n\tpublic static long go(int a, int b) {\n\t\tlong res=0;\n\t\tfor (int i = 0; i <=a && i<=b; i++) {\n\t\t\tlong cur= fac[i];\n\t\t\tcur= (cur*comb[a][i])%mod;\n\t\t\tcur= (cur*comb[b][i])%mod;\n\t\t\tres= (res+cur)%mod;\n\t\t}\n\t\treturn res;\n\t}\n\tstatic class p implements Comparable<p>{\n\t\tint x;\n\t\tint y;\n\t\tpublic p(int a, int b) {\n\t\t\tx=a;\n\t\t\ty=b;\n\t\t}\n\t\tpublic int compareTo(p o) {\n\t\t\treturn this.x-o.x;\n\t\t}\n\t}\n\tstatic class FenwickTree {\n\t\tlong[] ft;\n\t\tpublic FenwickTree(int n) {\n\t\t\tft = new long[n + 1];\n\t\t}\n\n\t\tint rsq(int b) {\n\t\t\tint sum = 0;\n\t\t\tfor (; b > 0; b -= (b & (-b)))\n\t\t\t\tsum += ft[b];\n\t\t\treturn sum;\n\t\t}\n\n\t\tint rsq(int a, int b) {\n\t\t\treturn rsq(b) - (a == 1 ? 0 : rsq(a - 1));\n\t\t}\n\n\t\tvoid update(int k, int v) {\n\t\t\tfor (; k < ft.length; k += (k & (-k)))\n\t\t\t\tft[k] += v;\n\t\t}\n\t}\n\n\tstatic class FastScanner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic FastScanner(InputStream in) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(in));\n\t\t\tst = new StringTokenizer(\"\");\n\t\t}\n\n\t\tpublic String next() throws IOException {\n\t\t\tif (!st.hasMoreTokens()) {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\treturn next();\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tpublic double nextDouble() throws NumberFormatException, IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\tpublic long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t}\n}", "src_uid": "b6dc5533fbf285d5ef4cf60ef6300383"} {"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 InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskH solver = new TaskH();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskH {\n long[] lens;\n Description[] cache;\n int m;\n int[] b;\n int[] gen;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int d = in.nextInt();\n m = in.nextInt();\n gen = new int[d];\n for (int i = 0; i < d; ++i) gen[i] = in.nextInt();\n int blen = in.nextInt();\n b = new int[blen];\n for (int i = 0; i < blen; ++i) {\n b[i] = in.nextInt();\n }\n long left = in.nextLong();\n long right = in.nextLong();\n lens = new long[100];\n long len = 1;\n int layer = 0;\n lens[layer] = len;\n while (true) {\n ++layer;\n if (len < (right + d - 1) / d) {\n len *= d;\n lens[layer] = len;\n } else {\n lens[layer] = right + 1;\n break;\n }\n }\n cache = new Description[layer + 1];\n Description d1 = describe(layer, right);\n Description d2 = describe(layer, left + b.length - 2);\n long res = d1.matchesInside[0] - d2.matchesInside[0];\n out.println(res);\n }\n\n private Description describe(int layer, long upto) {\n if (upto > lens[layer]) throw new RuntimeException();\n if (upto == lens[layer]) {\n if (cache[layer] != null) return cache[layer];\n }\n Description res = null;\n if (upto <= 0) {\n res = new Description(upto);\n return res;\n }\n if (layer == 0) {\n res = new Description(upto);\n for (int shift = 0; shift < m; ++shift) {\n if (b.length > 1 && b[0] >= shift) {\n res.matchesPrefix[shift] = BigInteger.ONE;\n } else {\n res.matchesPrefix[shift] = BigInteger.ZERO;\n }\n if (b.length > 1 && b[b.length - 1] >= shift) {\n res.matchesSuffix[shift] = BigInteger.ONE.shiftLeft(b.length - 1);\n } else {\n res.matchesSuffix[shift] = BigInteger.ZERO;\n }\n if (b.length == 1 && b[0] >= shift) {\n ++res.matchesInside[shift];\n }\n byte[] bits = new byte[(b.length + 7) >> 3];\n for (int i = 0; i < b.length; ++i) {\n if (b[i] >= shift) {\n bits[bits.length - 1 - (i >> 3)] |= (1 << (i & 7));\n }\n }\n res.coveredIfStartsFrom[shift] = new BigInteger(1, bits);\n }\n } else {\n long togo = upto;\n for (int i = 0; i < gen.length && togo > 0; ++i) {\n long by = Math.min(togo, lens[layer - 1]);\n Description d = describe(layer - 1, by);\n res = combine(res, d, gen[i]);\n togo -= by;\n }\n }\n if (res == null) throw new RuntimeException();\n if (upto == lens[layer]) {\n cache[layer] = res;\n }\n return res;\n }\n\n private Description combine(Description a, Description b, int delta) {\n if (a == null) {\n if (delta != 0) throw new RuntimeException();\n return b;\n }\n Description res = new Description(a.len + b.len);\n for (int shift = 0; shift < m; ++shift) {\n int ashift = shift;\n int bshift = (shift + delta) % m;\n res.matchesInside[shift] = a.matchesInside[ashift] + b.matchesInside[bshift];\n res.matchesInside[shift] += a.matchesPrefix[ashift].and(b.matchesSuffix[bshift].shiftRight(1)).bitCount();\n res.matchesPrefix[shift] = b.matchesPrefix[bshift];\n if (b.len < this.b.length) {\n res.matchesPrefix[shift] = res.matchesPrefix[shift].or(a.matchesPrefix[ashift].and(b.coveredIfStartsFrom[bshift].shiftRight(1)).shiftLeft((int) b.len));\n }\n res.matchesSuffix[shift] = a.matchesSuffix[ashift];\n if (a.len < this.b.length) {\n res.matchesSuffix[shift] = res.matchesSuffix[shift].or(b.matchesSuffix[bshift].shiftRight((int) a.len).and(a.coveredIfStartsFrom[ashift]));\n }\n if (a.len < this.b.length) {\n res.coveredIfStartsFrom[shift] = a.coveredIfStartsFrom[ashift].and(b.coveredIfStartsFrom[bshift].shiftRight((int) a.len));\n } else {\n res.coveredIfStartsFrom[shift] = BigInteger.ZERO;\n }\n }\n return res;\n }\n\n class Description {\n long len;\n long[] matchesInside = new long[m];\n BigInteger[] matchesPrefix = new BigInteger[m];\n BigInteger[] matchesSuffix = new BigInteger[m];\n BigInteger[] coveredIfStartsFrom = new BigInteger[m];\n\n public Description(long len) {\n this.len = len;\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 public long nextLong() {\n return Long.parseLong(next());\n }\n\n }\n}\n\n", "src_uid": "49eb534fb5cf4634c770f00e22528e19"} {"source_code": "import java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.Scanner;\n\npublic class Conversion {\n\n\tprivate static long converted=-1;\n\t\n\tpublic static void main(String[] args) {\n\t\tScanner s=new Scanner(System.in);\n\t\tlong base=s.nextLong();\n\t\tString baseAsString=base+\"\";\n\t\ts.nextLine();\n\t\tStringBuilder unconverted=new StringBuilder(s.nextLine());\n\t\tQueue<Long> pieces=new LinkedList<Long>();\n\t\twhile (unconverted.length()!=0) {\n\t\t\tfor (int length=baseAsString.length(); length>0; length--) {\n\t\t\t\tif (canRemove(unconverted, base-1, unconverted.length()-length,length)) {\n\t\t\t\t\tpieces.add(converted);\n\t\t\t\t\tremove(unconverted, length);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (Long l:pieces) {\n\t\t\t//System.out.println(l);\n\t\t}\n\t\tlong total=0;\n\t\tlong power=0;\n\t\twhile (!pieces.isEmpty()) {\n\t\t\tlong exponent=1;\n\t\t\tfor (int i=0; i<power; i++) {\n\t\t\t\texponent*=base;\n\t\t\t}\n\t\t\ttotal+=pieces.remove()*exponent;\n\t\t\tpower++;\n\t\t}\n\t\tSystem.out.println(total);\n\t}\n\t\n\tprivate static boolean canRemove(StringBuilder unconverted, long maxValue, int index, int length) {\n\t\tString substring=unconverted.substring(Math.max(0, index), Math.min(index+length, unconverted.length()));\n\t\tif (substring.startsWith(\"0\")&&length!=1) {\n\t\t\treturn false;\n\t\t}\n\t\tconverted=Long.parseLong(substring);\n\t\treturn converted<=maxValue;\n\t}\n\t\n\tprivate static void remove(StringBuilder unconverted, int length) {\n\t\tfor (int i=0; i<length&&unconverted.length()!=0; i++) {\n\t\t\tunconverted.deleteCharAt(unconverted.length()-1);\n\t\t}\n\t}\n\n}\n", "src_uid": "be66399c558c96566a6bb0a63d2503e5"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tlong time = System.nanoTime();\n\n\t\tint n = next();\n\n\t\tint[] x1 = new int[n];\n\t\tint[] x2 = new int[n];\n\t\tint[] y1 = new int[n];\n\t\tint[] y2 = new int[n];\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tx1[i] = next();\n\t\t\ty1[i] = next();\n\t\t\tx2[i] = next();\n\t\t\ty2[i] = next();\n\t\t}\n\n\t\tTreeSet<Integer> setx = new TreeSet<Integer>();\n\t\tTreeSet<Integer> sety = new TreeSet<Integer>();\n\n\t\tfor (int x : x1) setx.add(x);\n\t\tfor (int x : x2) setx.add(x);\n\t\tfor (int y : y1) sety.add(y);\n\t\tfor (int y : y2) sety.add(y);\n\n\t\tint kx = setx.size();\n\t\tint ky = sety.size();\n\n\t\tint[] x = new int[kx];\n\t\tint[] y = new int[ky];\n\t\t\n\t\tint ind = 0;\n\t\tfor (int xx : setx) x[ind++] = xx;\n\t\tind = 0;\n\t\tfor (int yy : sety) y[ind++] = yy;\n\n/*\t\tfor (int i = 0; i < kx; i++) out.print(x[i] + \" \");\n\t\tout.println();\n\t\tfor (int i = 0; i < ky; i++) out.print(y[i] + \" \");\n\t\tout.println();*/\n\n\t\tboolean flag = true;\n\t\tfor (int i = 0; i < kx - 1; i++)\n\t\t\tfor (int j = 0; j < ky - 1; j++) {\n\t\t\t\tboolean cont = false;\n\t\t\t\tfor (int t = 0; t < n; t++) {\n\t\t\t\t\tif ((x1[t] - x[i])*(x2[t] - x[i]) <= 0 && (x1[t] - x[i + 1])*(x2[t] - x[i + 1]) <= 0 &&\n\t\t\t\t\t\t(y1[t] - y[j])*(y2[t] - y[j]) <= 0 && (y1[t] - y[j + 1])*(y2[t] - y[j + 1]) <= 0) cont = true;\n\t\t\t\t}\n\n\t\t\t\tif (!cont) flag = false;\n\t\t\t}\n\n\t \tflag &= x[kx - 1] - x[0] == y[ky - 1] - y[0];\n\n\t\tout.println(flag ? \"YES\" : \"NO\");\n\n\t\t\n//\t\tSystem.out.println((System.nanoTime() - time)* 1e-9);\n\t\tout.close();\n\t}\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\t\n\tstatic BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in));\n\tstatic StringTokenizer in = new StringTokenizer(\"\");\n\n\tstatic String nextToken() throws Exception {\n\t\tif (!in.hasMoreTokens()) in = new StringTokenizer(bufferedreader.readLine());\n\t\treturn in.nextToken();\n\t}\n\n\tstatic int next() throws Exception {return Integer.parseInt(nextToken());};\n\tstatic int[] next(int n) throws Exception {\n\t\tint[] x = new int[n];\n\t\tfor (int i = 0; i < n; i++) x[i] = next();\n\t\treturn x;\n\t}\n\tstatic int[][] next(int n, int m) throws Exception {\n\t\tint[][] x = new int[n][];\n\t\tfor (int i = 0; i < n; i++) x[i] = next(m);\n\t\treturn x;\n\t}\n\n\tstatic long nextl() throws Exception {return Long.parseLong(nextToken());};\n\tstatic long[] nextl(int n) throws Exception {\n\t\tlong[] x = new long[n];\n\t\tfor (int i = 0; i < n; i++) x[i] = nextl();\n\t\treturn x;\n\t}\n\tstatic long[][] nextl(int n, int m) throws Exception {\n\t\tlong[][] x = new long[n][];\n\t\tfor (int i = 0; i < n; i++) x[i] = nextl(m);\n\t\treturn x;\n\t}\n\n\tstatic double nextd() throws Exception {return Double.parseDouble(nextToken());};\n\tstatic double[] nextd(int n) throws Exception {\n\t\tdouble[] x = new double[n];\n\t\tfor (int i = 0; i < n; i++) x[i] = nextd();\n\t\treturn x;\n\t}\n\tstatic double[][] nextd(int n, int m) throws Exception {\n\t\tdouble[][] x = new double[n][];\n\t\tfor (int i = 0; i < n; i++) x[i] = nextd(m);\n\t\treturn x;\n\t}\n\n\tstatic String nextline() throws Exception {\n\t\tin = new StringTokenizer(\"\");\n\t\treturn bufferedreader.readLine();\n\t}\n\n}", "src_uid": "f63fc2d97fd88273241fce206cc217f2"} {"source_code": "import java.math.BigInteger;\nimport java.util.Scanner;\n\npublic class Main{\n public static void main(String[] args){\n Scanner SC = new Scanner(System.in);\n BigInteger a, b, x, y, xynwd;\n a=new BigInteger(SC.next());\n b=new BigInteger(SC.next());\n x=new BigInteger(SC.next());\n y=new BigInteger(SC.next());\n xynwd=x.gcd(y);\n x=x.divide(xynwd);\n y=y.divide(xynwd);\n a=a.divide(x);\n b=b.divide(y);\n System.out.println(a.compareTo(b)>0 ? b : a);\n }\n}\n\n", "src_uid": "907ac56260e84dbb6d98a271bcb2d62d"} {"source_code": "import java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.nio.charset.Charset;\nimport java.util.*;\nimport java.util.regex.Pattern;\n\npublic class CF1156G {\n public static void main(String[] args) throws Exception {\n boolean local = System.getProperty(\"ONLINE_JUDGE\") == null;\n boolean async = false;\n\n Charset charset = Charset.forName(\"ascii\");\n\n FastIO io = local ? new FastIO(new FileInputStream(\"D:\\\\DATABASE\\\\TESTCASE\\\\Code.in\"), System.out, charset) : new FastIO(System.in, System.out, charset);\n Task task = new Task(io, new Debug(local));\n\n if (async) {\n Thread t = new Thread(null, task, \"dalt\", 1 << 27);\n t.setPriority(Thread.MAX_PRIORITY);\n t.start();\n t.join();\n } else {\n task.run();\n }\n\n if (local) {\n io.cache.append(\"\\n\\n--memory -- \\n\" + ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) >> 20) + \"M\");\n }\n\n io.flush();\n }\n\n public static class Task implements Runnable {\n final FastIO io;\n final Debug debug;\n int inf = (int) 1e8;\n int mod = (int) 1e9 + 7;\n\n public int mod(int val) {\n val %= mod;\n if (val < 0) {\n val += mod;\n }\n return val;\n }\n\n public int mod(long val) {\n val %= mod;\n if (val < 0) {\n val += mod;\n }\n return (int) val;\n }\n\n 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 Map<String, Var> context = new HashMap<>();\n HashSet<String> remainNames = new HashSet<>();\n Deque<String> useable = new ArrayDeque<>();\n\n public void solve() {\n int n = io.readInt();\n\n for (int i = 0; i < n; i++) {\n parseLine();\n }\n\n StringBuilder builder = new StringBuilder();\n for (int i = 'a'; i <= 'z'; i++) {\n for (int i2 = 'a'; i2 <= 'z'; i2++) {\n for (int i3 = 'a'; i3 <= 'z'; i3++) {\n for (int i4 = 'a'; i4 <= 'z'; i4++) {\n builder.setLength(0);\n builder.append((char) i).append((char) i2).append((char) i3).append((char) i4);\n remainNames.add(builder.toString());\n }\n }\n }\n }\n\n remainNames.removeAll(context.keySet());\n useable.addAll(remainNames);\n\n String finalName = rebuild(getVar(\"res\"));\n if (trace.isEmpty() && !finalName.equals(\"res\")) {\n trace.add(\"res=\" + finalName);\n finalName = \"res\";\n }\n if (!trace.isEmpty()) {\n trace.add(trace.remove(trace.size() - 1).replace(finalName, \"res\"));\n }\n io.cache.append(trace.size()).append('\\n');\n for (String s : trace) {\n io.cache.append(s).append('\\n');\n }\n }\n\n List<String> trace = new ArrayList<>();\n\n Random random = new Random(12345678);\n Map<String, String> exprToName = new HashMap<>();\n\n public String randomName() {\n return useable.removeFirst();\n }\n\n public String register(String expr, String name) {\n if (exprToName.containsKey(expr)) {\n return exprToName.get(expr);\n } else {\n trace.add(name + \"=\" + expr);\n exprToName.put(expr, name);\n return name;\n }\n }\n\n StringBuilder common = new StringBuilder(1024);\n\n public String concat(String... parts) {\n common.setLength(0);\n for (String part : parts) {\n common.append(part);\n }\n return common.toString();\n }\n\n Map<Var, String> cache = new IdentityHashMap<>();\n\n public String rebuild(Var var) {\n if (cache.containsKey(var)) {\n return cache.get(var);\n }\n String retName = null;\n if (var instanceof UnknownVar) {\n retName = ((UnknownVar) var).name;\n }\n if (var instanceof Reference) {\n retName = rebuild(var.arg1);\n }\n if (var instanceof Expr) {\n String name = randomName();\n String arg1 = rebuild(var.arg1);\n String arg2 = rebuild(((Expr) var).arg2);\n retName = register(concat(arg1, ((Expr) var).op, arg2), name);\n }\n cache.put(var, retName);\n return retName;\n }\n\n char[] line = new char[100];\n Lexer lexer = new Lexer();\n\n public Var getVar(String s) {\n if (!context.containsKey(s)) {\n UnknownVar var = new UnknownVar();\n var.name = s;\n context.put(s, var);\n }\n return context.get(s);\n }\n\n public void parseLine() {\n int len = io.readString(line, 0);\n lexer.reset(line, len);\n String variable = lexer.readName();\n lexer.readOp();\n String arg1 = lexer.readName();\n if (!lexer.hasMore()) {\n Reference reference = new Reference();\n reference.arg1 = getVar(arg1);\n context.put(variable, reference);\n } else {\n Expr expr = new Expr();\n expr.arg1 = getVar(arg1);\n expr.op = lexer.readOp();\n expr.arg2 = getVar(lexer.readName());\n Reference reference = new Reference();\n reference.arg1 = expr;\n context.put(variable, reference);\n }\n }\n }\n\n public static class Lexer {\n char[] data;\n int len;\n int rpos = 0;\n StringBuilder builder = new StringBuilder();\n\n public void reset(char[] data, int len) {\n this.data = data;\n this.len = len;\n rpos = 0;\n }\n\n public boolean hasMore() {\n return rpos != len;\n }\n\n public String readName() {\n builder.setLength(0);\n while (rpos < len && data[rpos] != '=' &&\n data[rpos] != '$' && data[rpos] != '^' && data[rpos] != '#' && data[rpos] != '&') {\n builder.append(data[rpos++]);\n }\n return builder.toString();\n }\n\n public String readOp() {\n builder.setLength(0);\n builder.append(data[rpos++]);\n return builder.toString();\n }\n }\n\n public static class Var {\n Var arg1;\n }\n\n public static class Expr extends Var {\n String op;\n Var arg2;\n }\n\n public static class UnknownVar extends Var {\n String name;\n }\n\n public static class Reference extends Var {\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}", "src_uid": "da40321d92baaef42c2840e45599294c"} {"source_code": "import java.util.Scanner;\r\n\r\npublic class MikeSeq \r\n{\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner ishika = new Scanner (System.in);\r\n\t\tint n = ishika.nextInt();\r\n\t\tif(n >= 2600)\r\n\t\t\tSystem.out.print(\"3000\");\r\n\t\telse if(n >= 2400)\r\n\t\t\tSystem.out.print(\"2600\");\r\n\t\telse if(n >= 2300)\r\n\t\t\tSystem.out.print(\"2400\");\r\n\t\telse if(n >= 2100)\r\n\t\t\tSystem.out.print(\"2300\");\r\n\t\telse if(n >= 1900)\r\n\t\t\tSystem.out.print(\"2100\");\r\n\t\telse if(n >= 1600)\r\n\t\t\tSystem.out.print(\"1600\");\r\n\t\telse if(n >= 1400)\r\n\t\t\tSystem.out.print(\"1600\");\r\n\t\telse if(n >= 1200)\r\n\t\t\tSystem.out.print(\"1400\");\r\n\t\telse\r\n\t\t\tSystem.out.print(\"1200\");\r\n\t}\r\n}", "src_uid": "22725effa6dc68b9c2a499d148e613c2"} {"source_code": "import java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class Main {\n\n static int b[];\n static String numbers;\n static String av;\n\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 numbers = sc.nextLine();\n av = sc.nextLine();\n int n = av.length();\n b = new int[n];\n Arrays.fill(b, 1);\n int num = numbers.length();\n int totalCount = 0;\n\n while (find0(numbers.charAt(0))) {\n int m = 1;\n for (int i = 1; i < num; i++)\n if (find0(numbers.charAt(i))) {\n m = m + 1;\n }\n if (num == m) {\n totalCount = totalCount + 1;\n } else break;\n }\n\n pw.println(totalCount);\n pw.close();\n sc.close();\n }\n\n static boolean find0(char c) {\n for (int i = 0; i < b.length; i++) {\n if (b[i] == 1 && check(c, av.charAt(i))) {\n b[i] = 0;\n return true;\n }\n }\n return false;\n }\n\n private static boolean check(char c, char c1) {\n if (c == c1) {\n return true;\n }\n if (c == '2' || c == '5' || c == '6' || c == '9' || c1 == '2' || c1 == '5' || c1 == '6' || c1 == '9') {\n //2 and 5\n if (c == '2' && c1 == '5') {\n return true;\n }\n if (c == '5' && c1 == '2') {\n return true;\n }\n if (c1 == '2' && c == '5') {\n return true;\n }\n if (c1 == '5' && c == '2') {\n return true;\n }\n //6 and 9\n if (c == '6' && c1 == '9') {\n return true;\n }\n if (c == '9' && c1 == '6') {\n return true;\n }\n if (c1 == '6' && c == '9') {\n return true;\n }\n if (c1 == '9' && c == '6') {\n return true;\n }\n }\n return false;\n }\n}\n", "src_uid": "72a196044787cb8dbd8d350cb60ccc32"} {"source_code": "\nimport java.util.*;\nimport java.io.*;\n\npublic class Postcard {\n\n static void print(char[] arr) {\n StringBuilder sb = new StringBuilder();\n for (int j = 0; j < arr.length; j++) {\n if (arr[j] != '?' && arr[j] != '*' && arr[j] != 'A') {\n sb.append(arr[j]);\n }\n }\n System.out.println(sb);\n }\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n char arr[] = in.next().toCharArray();\n int num = in.nextInt();\n int cane = 0, snow = 0, size = 0;\n for (int i = 0; i < arr.length; i++) {\n if (arr[i] == '*') {\n snow++;\n } else if (arr[i] == '?') {\n cane++;\n } else {\n size++;\n }\n }\n if(size<num&&snow==0){\n System.out.println(\"Impossible\");\n }else if (size == num) {\n print(arr);\n //////////////////////////////////////////////////////////////\n } else if (num > size && snow > 0) {\n StringBuilder sb = new StringBuilder();\n int diff=num-size;\n for (int j = 0; j < arr.length; j++) {\n if(arr[j]=='*'){\n for (int i = j-1; num>size; ) {\n sb.append(arr[i]);\n size++;\n }\n }\n if (arr[j] != '?' && arr[j] != '*' && arr[j] != 'A') {\n sb.append(arr[j]);\n }\n }\n System.out.println(sb);\n ///////////////////////////////////////////////////////////////////\n }else if (size - (cane + snow) <= num) {\n int i = 0;\n while (size > num && i < arr.length) {\n if (arr[i] == '?' || arr[i] == '*') {\n arr[i - 1] = 'A';\n size--;\n }\n i++;\n }//while\n \n print(arr);\n ////////////////////////////////////////////////////////////////\n } else {\n System.out.println(\"Impossible\");\n }\n\n }//psvm\n}//class\n", "src_uid": "90ad5e6bb5839f9b99a125ccb118a276"} {"source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\n/**\n * Created by vignesh on 1/27/2017.\n */\npublic class hackerRank {\n\n public static void main(String[] args) {\n\n Scanner input = new Scanner(System.in);\n String[] pokemons= {\"vaporeon\", \"jolteon\", \"flareon\", \"umbreon\", \"leafeon\", \"glaceon\", \"sylveon\", \"espeon\"};\n int n = input.nextInt();\n String s = new String();\n s = input.next();\n int alpha = 0, count = 0;\n\n for (int i = 0; i < s.length(); i++) {\n\n if(s.charAt(i) != '.')\n\n alpha++;\n\n }\n\n if(s.length() == 8)\n\n System.out.println(\"vaporeon\");\n\n else if(s.length() == 6)\n\n System.out.println(\"espeon\");\n\n else{\n\n for(int i =1; i <= 6; i++){\n\n count = 0;\n\n for(int j = 0; j < 7; j++){\n\n if(s.charAt(j) != '.'){\n\n if(s.charAt(j) == pokemons[i].charAt(j))\n\n\n count++;\n\n }\n\n if(count == alpha) {\n\n System.out.println(pokemons[i]);\n break;\n }\n\n }\n\n if(count == alpha)\n\n break;\n\n }\n\n\n\n\n\n }\n\n }\n}", "src_uid": "ec3d15ff198d1e4ab9fd04dd3b12e6c0"} {"source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Training {\n\n public static void main(String[] args) {\n FastReader in = new FastReader();\n\n int n = in.nextInt();\n\n StringBuilder sb = new StringBuilder();\n\n int prv = 0;\n for (int i = n; i >= 1; i--) {\n if ((n % i == 0) && prv % i == 0) {\n sb.append(i == 1 ? i : i + \" \");\n prv = i;\n }\n }\n\n System.out.println(sb);\n }\n}\n\nclass FastReader {\n\n BufferedReader br;\n StringTokenizer st;\n\n public FastReader() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n 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}", "src_uid": "2fc946bb72f56b6d86eabfaf60f9fa63"} {"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 void solve() throws IOException {\n int n = nextInt();\n int m = nextInt();\n \n long[] a = new long[n];\n for (int i = 0; i < n; i++)\n a[i] = nextLong();\n \n long ans = 0;\n \n int maxP = m / n;\n for (int p = 1; p <= maxP; p++) {\n long minLastSum = (long)p * (p + 1) / 2 * n;\n if (a[n - 1] < minLastSum)\n continue;\n long maxLastSum = (long)m * p - (long)n * p * (p - 1) / 2;\n long[] money = new long[n];\n money[n - 1] = Math.min(maxLastSum, a[n - 1]);\n for (int i = n - 2; i >= 0; i--)\n money[i] = Math.min(a[i], money[i + 1] - p);\n \n long firstMax = (long)(m + 1) * p - (long)n * p * (p + 1) / 2;\n long diff = firstMax - money[0];\n if (diff < 0)\n throw new AssertionError();\n long firstPay = diff <= m - p * n ? (m - p * n + 1 - diff) : 1;\n long free = (m - firstPay + 1) - n * p;\n \n long cur = money[0];\n long last = money[0];\n for (int j = 1; j < n; j++) {\n long now = last + p;\n long shift = Math.min(free, money[j] - now);\n free -= shift;\n last = now + shift;\n cur += last;\n }\n \n ans = Math.max(ans, cur);\n }\n \n out.println(ans);\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 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}", "src_uid": "169f58dc87d26e0fadde6a83bb623f54"} {"source_code": "import java.io.*;\nimport java.util.*;\n\t\npublic\t class CODEFORCES\n\t{\n\t\tprivate InputStream is;\n\t\tprivate PrintWriter out;\n\t\tint time = 0, DP[], start[], end[], dist[], black[], MOD = (int) (1e9 + 7),\n\t\t\t\tarr[], weight[][], x[], y[], parent[];\n\t\tint MAX = 100000, N, K;\n\t\tlong red[];\n\t\tArrayList<Integer>[] amp;\n\t\tArrayList<Pair>[][] pmp;\n\t\tboolean b[], boo[][];\n\t\tPair prr[];\n\t\tHashMap<Pair, Integer> hm = new HashMap();\n\t\tlong Dp[][][][] = new long[110][110][12][12];\n\t\n\t\tvoid soln()\n\t\t{\n\t\t\tis = System.in;\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tlong s = System.currentTimeMillis();\n\t\t\tsolve();\n\t\t\t// out.close();\n\t\t\tout.flush();\n\t\t\t// tr(System.currentTimeMillis() - s + \"ms\");\n\t\t}\n\t\n\t\tpublic static void main(String[] args) throws Exception \n\t\t{\n\t\t\tnew Thread(null, new Runnable() \n\t\t\t{\n\t\t\t\tpublic void run() \n\t\t\t\t{\n\t\t\t\t\ttry\n\t\t\t\t\t{\n\t\t\t\t\t\t// new CODEFORCES().soln();\n\t\t\t\t\t} catch (Exception e)\n\t\t\t\t\t{\n\t\t\t\t\t\tSystem.out.println(e);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}, \"1\", 1 << 26).start();\n\t\t\tnew CODEFORCES().soln();\n\t\t}\n\t\n\t\tint ans = 0, cost = 0, D[][];\n\t\tchar ch[], ch1[];\n\t\tint hash = 29;\n\t\tTreeSet<Cell> ts;\n\t\tint prime[] = new int[100000];\n\t\tint dp[] = new int[50000];\n\t\tTreeSet<String> tset = new TreeSet<>();\n\t\tvoid solve() \n\t\t{\n\t\t\tlong n = nl();\n\t\t\tlong low = 1, high = n, ans = high;\n\t\t\twhile(low<=high) {\n\t\t\t\tlong mid = (low+high)/2;\n\t\t\t\tlong temp = n;\n\t\t\t\tlong cnt = 0;\n\t\t\t\twhile(temp>0) {\n\t\t\t\t\tif(temp<=mid) {\n\t\t\t\t\t\tcnt += temp;\n\t\t\t\t\t\ttemp = 0;\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\ttemp -= mid;\n\t\t\t\t\t\tcnt += mid;\n\t\t\t\t\t}\n\t\t\t\t\ttemp -= temp/10;\n\t\t\t\t}\n\t\t\t\t//out.println(mid+\" \"+cnt);\n\t\t\t\tif(cnt>=((n+1)/2)) {\n\t\t\t\t\thigh = mid-1;\n\t\t\t\t\tans = mid;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlow = mid+1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tout.println(ans);\n\t\t}\n\t\tvoid printArray(long[] arr) {\n\t\t\tfor(long i : arr) out.print(i +\" \");\n\t\t\tout.println();\n\t\t}\n\t\tvoid bfs(int x) {\n\t\t\tQueue<Integer> q = new LinkedList<>();\n\t\t\tq.add(x);\n\t\t\tarr[x] = 0;\n\t\t\twhile(!q.isEmpty()) {\n\t\t\t\tint y = q.poll();\n\t\t\t\tfor(int i : amp[y]) {\n\t\t\t\t\tarr[i] = min(arr[i],arr[y]+1);\n\t\t\t\t\tif(!b[i]) {\n\t\t\t\t\t\tq.add(i);\n\t\t\t\t\t\tb[i] = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong calc(char ch[]) {\n\t\t\tlong val = 1, sum = 0;\n\t\t\tfor(char c : ch) {\n\t\t\t\tif(c == 'S') sum += val;\n\t\t\t\telse val*=2;\n\t\t\t}\n\t\t\treturn sum;\n\t\t}\n\t\tint dfs(int x) {\n\t\t\tb[x] = true;\n\t\t\t//start[x] = time++;\n\t\t\tint ans = 1;\n\t\t\tfor(int i : amp[x]) {\n\t\t\t\tif(!b[i]) {\n\t\t\t\t\tans += dfs(i);\n\t\t\t\t}\n\t\t\t}\n\t\t\t//end[x] = time;\n\t\t\tif(x!= 0 && ans%2==0 && (N-ans)%2==0) cost++;\n\t\t\t\t\n\t\t\treturn ans;\n\t\t}\n\t\tint calc(int x) {\n\t\t\tString s = Integer.toString(x);\n\t\t\tint ans = 0;\n\t\t\tfor(char ch : s.toCharArray()) ans += (ch-'0');\n\t\t\treturn ans;\n\t\t}\n\t\tboolean isCons(char ch){\n\t\t\tif(ch!='a' && ch!='e' && ch!='i' && ch!='o' && ch!='u' && ch!=' ') return true;\n\t\t\treturn false; \n\t\t}\n\t\tvoid seive(int x){\n\t\t\tb = new boolean[x+1];\n\t\t\tfor(int i = 2;i*i<=x;i++){\n\t\t\t\tif(!b[i]){\n\t\t\t\t\tfor(int j = 2*i;j<=x;j+=i) b[j] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong[][] matMul(long a[][] , long b[][], int n)\n\t\t{\n\t\t\tlong res[][] = new long[n][n];\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\tlong sum = 0;\n\t\t\t\t\tfor(int k = 0;k<n;k++){\n\t\t\t\t\t\tsum += (a[i][k]*1l*b[k][j]);\n\t\t\t\t\t\tsum %= MOD;\n\t\t\t\t\t}\n\t\t\t\t\tres[i][j] = sum;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\t\tint min(int a, int b)\n\t\t{\n\t\t\treturn (a<b)?a:b;\n\t\t}\n\t\tprivate class Cell implements Comparable<Cell>\n\t\t{\n\t\t\tint u, v, s;\n\t\t\tpublic Cell(int u, int v, int s) \n\t\t\t{\n\t\t\t\tthis.u = u;\n\t\t\t\tthis.v = v;\n\t\t\t\tthis.s = s;\n\t\t\t}\n\t\t\tpublic int hashCode() \n\t\t\t{\n\t\t\t\treturn Objects.hash();\n\t\t\t}\n\t\t\tpublic int compareTo(Cell other) \n\t\t\t{\n\t\t\t\treturn (Long.compare(s, other.s) != 0 ? (Long.compare(s, other.s)):(Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u)))\n\t\t\t\t\t\t&((Long.compare(s, other.s) != 0 ? (Long.compare(s, other.s)):(Long.compare(u, other.v)!=0?Long.compare(u, other.v):Long.compare(v, other.u))));\n\t\t\t}\n\t\t\tpublic String toString()\n\t\t\t{\n\t\t\t\treturn this.u + \" \" + this.v;\n\t\t\t}\n\t\t}\n\t\n\t\tclass Pair implements Comparable<Pair>\n\t\t{\n\t\t\tint u, v, z, i;\n\t\n\t\t\tPair(int u, int v) \n\t\t\t{\n\t\t\t\tthis.u = u;\n\t\t\t\tthis.v = v;\n\t\t\t}\n\t\n\t\t\tPair() \n\t\t\t{\n\t\n\t\t\t}\n\t\n\t\t\tPair(int u, int v, int z, int i) \n\t\t\t{\n\t\t\t\tthis.u = u;\n\t\t\t\tthis.v = v;\n\t\t\t\tthis.z = z;\n\t\t\t\tthis.i = i;\n\t\t\t}\n\t\n\t\t\tpublic int hashCode()\n\t\t\t{\n\t\t\t\treturn Objects.hash();\n\t\t\t}\n\t\n\t\t\tpublic boolean equals(Object o)\n\t\t\t{\n\t\t\t\tPair other = (Pair) o;\n\t\t\t\treturn (((u == other.v && v == other.u)));\n\t\t\t}\n\t\n\t\t\tpublic int compareTo(Pair other)\n\t\t\t{\n\t\t\t\t//return (((u == other.v && v == other.u)))?0:1;\n\t\t\t\t// return Integer.compare(val, other.val);\n\t\t\t\treturn Long.compare(u, other.u);// != 0 ? (Long.compare(u, other.u)): (Long.compare(v, other.v));\n\t\t\t\t\t\t//&(Long.compare(u, other.v) != 0 ? (Long.compare(u, other.v)): (Long.compare(v, other.u))));\n\t\t\t}\n\t\n\t\t\tpublic String toString()\n\t\t\t{\n\t\t\t\treturn this.u + \" \" + this.v;\n\t\t\t}\n\t\t}\n\t\n\t\tint max(int a, int b) \n\t\t{\n\t\t\tif (a > b)\n\t\t\t\treturn a;\n\t\t\treturn b;\n\t\t}\n\t\n\t\t\n\t\tvoid buildGraph(int n) \n\t\t{\n\t\t\tfor (int i = 0; i < n; i++) \n\t\t\t{\n\t\t\t\tint x1 = ni() - 1, y1 = ni() - 1;\n\t\t\t\tamp[x1].add(y1);\n\t\t\t\tamp[y1].add(x1);\n\t\t\t}\n\t\t}\n\t\tlong modInverse(long a, long mOD2) \n\t\t{\n\t\t\treturn power(a, mOD2 - 2, mOD2);\n\t\t}\n\t\n\t\tlong power(long x, long y, long m) \n\t\t{\n\t\t\tif (y == 0)\n\t\t\t\treturn 1;\n\t\t\tlong p = power(x, y / 2, m) % m;\n\t\t\tp = (p * p) % m;\n\t\n\t\t\treturn (y % 2 == 0) ? p : (x * p) % m;\n\t\t}\n\t\n\t\tpublic long gcd(long a, long b) \n\t\t{\n\t\t\tif (b == 0)\n\t\t\t\treturn a;\n\t\t\treturn gcd(b, a % b);\n\t\t}\n\t\n\t\tstatic class ST1 \n\t\t{\n\t\t\tint arr[], st[], size;\n\t\n\t\t\t\n\t\t\tST1(int a[]) \n\t\t\t{\n\t\t\t\tarr = a.clone();\n\t\t\t\tsize = 10 * arr.length;\n\t\t\t\tst = new int[size];\n\t\t\t\tbuild(0, arr.length - 1, 1);\n\t\t\t}\n\t\n\t\t\tvoid build(int ss, int se, int si) \n\t\t\t{\n\t\t\t\tif (ss == se)\n\t\t\t\t{\n\t\t\t\t\tst[si] = arr[ss];\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tint mid = (ss + se) / 2;\n\t\t\t\tint val = 2 * si;\n\t\t\t\tbuild(ss, mid, val);\n\t\t\t\tbuild(mid + 1, se, val + 1);\n\t\t\t\tst[si] = Math.min(st[val], st[val + 1]);\n\t\t\t}\n\t\n\t\t\tint get(int ss, int se, int l, int r, int si) \n\t\t\t{\n\t\t\t\tif (l > se || r < ss || l > r)\n\t\t\t\t\treturn Integer.MAX_VALUE;\n\t\t\t\tif (l <= ss && r >= se)\n\t\t\t\t\treturn st[si];\n\t\t\t\tint mid = (ss + se) / 2;\n\t\t\t\tint val = 2 * si;\n\t\t\t\treturn Math.min(get(ss, mid, l, r, val),\n\t\t\t\t\t\tget(mid + 1, se, l, r, val + 1));\n\t\t\t}\n\t\t}\n\t\n\t\tstatic class ST \n\t\t{\n\t\t\tint arr[], lazy[], n;\n\t\n\t\t\tST(int a) \n\t\t\t{\n\t\t\t\tn = a;\n\t\t\t\tarr = new int[10 * n];\n\t\t\t\tlazy = new int[10 * n];\n\t\t\t}\n\t\n\t\t\tvoid up(int l, int r, int val)\n\t\t\t{\n\t\t\t\tupdate(0, n - 1, 0, l, r, val);\n\t\t\t}\n\t\n\t\t\tvoid update(int l, int r, int c, int x, int y, int val)\n\t\t\t{\n\t\t\t\tif (lazy[c] != 0) {\n\t\t\t\t\tlazy[2 * c + 1] += lazy[c];\n\t\t\t\t\tlazy[2 * c + 2] += lazy[c];\n\t\t\t\t\tif (l == r)\n\t\t\t\t\t\tarr[c] += lazy[c];\n\t\t\t\t\tlazy[c] = 0;\n\t\t\t\t}\n\t\t\t\tif (l > r || x > y || l > y || x > r)\n\t\t\t\t\treturn;\n\t\t\t\tif (x <= l && y >= r) \n\t\t\t\t\n\t\t\t\t{\n\t\t\t\t\tlazy[c] += val;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tint mid = l + r >> 1;\n\t\t\t\tupdate(l, mid, 2 * c + 1, x, y, val);\n\t\t\t\tupdate(mid + 1, r, 2 * c + 2, x, y, val);\n\t\t\t\tarr[c] = Math.max(arr[2 * c + 1], arr[2 * c + 2]);\n\t\t\t}\n\t\n\t\t\tint an(int ind) \n\t\t\t{\n\t\t\t\treturn ans(0, n - 1, 0, ind);\n\t\t\t}\n\t\n\t\t\tint ans(int l, int r, int c, int ind) \n\t\t\t{\n\t\t\t\tif (lazy[c] != 0) \n\t\t\t\t{\n\t\t\t\t\tlazy[2 * c + 1] += lazy[c];\n\t\t\t\t\tlazy[2 * c + 2] += lazy[c];\n\t\t\t\t\tif (l == r)\n\t\t\t\t\t\tarr[c] += lazy[c];\n\t\t\t\t\tlazy[c] = 0;\n\t\t\t\t}\n\t\t\t\tif (l == r)\n\t\t\t\t\treturn arr[c];\n\t\t\t\tint mid = l + r >> 1;\n\t\t\t\tif (mid >= ind)\n\t\t\t\t\treturn ans(l, mid, 2 * c + 1, ind);\n\t\t\t\treturn ans(mid + 1, r, 2 * c + 2, ind);\n\t\t\t}\n\t\t}\n\t\n\t\tpublic static int[] shuffle(int[] a, Random gen)\n\t\t{\n\t\t\tfor (int i = 0, n = a.length; i < n; i++)\n\t\t\t{\n\t\t\t\tint ind = gen.nextInt(n - i) + i;\n\t\t\t\tint d = a[i];\n\t\t\t\ta[i] = a[ind];\n\t\t\t\ta[ind] = d;\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\t\n\t\tlong power(long x, long y, int mod) \n\t\t{\n\t\t\tlong ans = 1;\n\t\t\twhile (y > 0) \n\t\t\t{\n\t\t\t\tif (y % 2 == 0) \n\t\t\t\t{\n\t\t\t\t\tx = (x * x) % mod;\n\t\t\t\t\ty /= 2;\n\t\t\t\t} else \n\t\t\t\t{\n\t\t\t\t\tans = (x * ans) % mod;\n\t\t\t\t\ty--;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn ans;\n\t\t}\n\t\n\t\t// To Get Input\n\t\t// Some Buffer Methods\n\t\tprivate byte[] inbuf = new byte[1024];\n\t\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\t\tprivate int readByte()\n\t\t{\n\t\t\tif (lenbuf == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (ptrbuf >= lenbuf) \n\t\t\t{\n\t\t\t\tptrbuf = 0;\n\t\t\t\ttry \n\t\t\t\t{\n\t\t\t\t\tlenbuf = is.read(inbuf);\n\t\t\t\t} catch (IOException e)\n\t\t\t\t{\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (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{\n\t\t\treturn !(c >= 33 && c <= 126);\n\t\t}\n\t\n\t\tprivate int skip() \n\t\t{\n\t\t\tint b;\n\t\t\twhile ((b = readByte()) != -1 && isSpaceChar(b))\n\t\t\t\t;\n\t\t\treturn b;\n\t\t}\n\t\n\t\tprivate double nd() \n\t\t{\n\t\t\treturn Double.parseDouble(ns());\n\t\t}\n\t\n\t\tprivate char nc() \n\t\t{\n\t\t\treturn (char) skip();\n\t\t}\n\t\n\t\tprivate String ns()\n\t\t{\n\t\t\tint b = skip();\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\twhile (!(isSpaceChar(b)))\n\t\t\t{ // when nextLine, (isSpaceChar(b) && b != '\n\t\t\t\t\t\t\t\t\t\t// ')\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{\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{\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{\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{\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{\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{\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{\n\t\t\t\tif (b >= '0' && b <= '9') \n\t\t\t\t{\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t} else \n\t\t\t\t{\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{\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{\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{\n\t\t\t\tif (b >= '0' && b <= '9') \n\t\t\t\t{\n\t\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t\t} else \n\t\t\t\t{\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 boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\t\n\t\tprivate void tr(Object... o) \n\t\t{\n\t\t\tif (!oj)\n\t\t\t\tSystem.out.println(Arrays.deepToString(o));\n\t\t}\n\t}", "src_uid": "db1a50da538fa82038f8db6104d2ab93"} {"source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.lang.*;\n \n //@Manan Parmar\n\npublic class Solution2 implements Runnable {\n\n\n public void run() {\n \n InputReader sc = new InputReader(System.in);\n PrintWriter out = new PrintWriter(System.out);\n \n int t=sc.nextInt();\n while(t--!=0)\n {\n int n=sc.nextInt();\n if(n%3==0||n%7==0)\n n=0;\n else\n {\n while(true)\n {\n if(n%3==0||n%7==0)\n {\n n=0;\n break;\n }\n else if(n>=7)\n n=n-7;\n else if(n>=3)\n n=n-3;\n else\n break;\n }\n }\n //out.println(n);\n if(n==0)\n out.println(\"YES\");\n else\n out.println(\"NO\"); \n } \n out.close();\n }\n \n\n//========================================================================\n\n \n\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private 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\n public static void main(String args[]) throws Exception {\n new Thread(null, new Solution2(),\"Main\",1<<27).start();\n }\n}\n", "src_uid": "cfd1182be98fb5f0c426f8b68e48d452"} {"source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.BigInteger;\nimport static java.lang.Math.*;\nimport static java.math.BigInteger.*;\n\npublic class Main {\n\n void run(){\n boolean oj = System.getProperty(\"ONLINE_JUDGE\")!=null;\n// boolean oj = false;\n if( oj ){\n br = new BufferedReader( new InputStreamReader (System.in ) );\n out = new PrintWriter ( new OutputStreamWriter(System.out) );\n }\n else{\n try{\n br = new BufferedReader(new FileReader(\"abc.in\"));\n out = new PrintWriter( new FileWriter(\"abc.out\") );\n } catch (IOException e) {\n MLE();\n }\n }\n long tBeg = System.currentTimeMillis();\n solve();\n// deb();\n// out.println( \"TIME: \" + (System.currentTimeMillis()-tBeg)/1e3 );\n out.flush();\n }\n\n BufferedReader br;\n StringTokenizer in;\n PrintWriter out;\n\n String next() {\n while( in==null || !in.hasMoreTokens() )\n try {\n in = new StringTokenizer( br.readLine() );\n } catch (IOException e) {\n MLE();\n }\n return in.nextToken();\n }\n\n int nextInt(){ return Integer.parseInt( next() ); }\n\n long nextLong(){ return Long.parseLong( next() ); }\n\n public static void main(String[] args) throws IOException {\n new Thread( null, new Runnable() {\n @Override\n public void run() {\n new Main().run();\n }\n }, \"myThread\", 1<<30 ).run();\n }\n\n void MLE(){\n// for(;;);\n int[][] adj = new int[1024*1024][];\n for( int i = 0; i < adj.length; ++i )\n adj[i] = new int[1024*1024];\n }\n\n// final int cntBits = 29;\n//\n// HashMap<Integer,Integer> mem = new HashMap<Integer, Integer>();\n// int g( int msk ){\n// if( mem.containsKey(msk) )\n// return mem.get(msk);\n//\n// if( msk == 0 ){\n// mem.put(msk,0);\n// return 0;\n// }\n//\n// boolean[] u = new boolean[200];\n// for( int i = 1; i <= cntBits; ++i ){\n// if(!( (msk&(1<<i)) != 0 ))continue;\n// int toMsk = msk;\n// for( int j = i; j <= cntBits; j+=i ){\n// toMsk &= ~(1<<j);\n// }\n// u[g(toMsk)] = true;\n// }\n// for( int ansG = 0; ; ++ansG )\n// if( !u[ansG] ){\n// mem.put(msk,ansG);\n// return ansG;\n// }\n// }\n\n\n final int[] g = new int[]{0, 1, 2, 1, 4, 3, 2, 1, 5, 6, 2, 1, 8, 7, 5, 9, 8, 7, 3, 4, 7, 4, 2, 1, 10, 9, 3, 6, 11, 12};\n\n void solve(){\n// for( int c = 1; c <= cntBits; ++c ){\n// int msk = 0;\n// for( int j = 1; j <= c; ++j )\n// msk |= (1<<j);\n// out.print( \", \" + g(msk) );\n// }\n// out.println();\n\n int n = nextInt();\n int s = g[1];\n int other = n-1;\n\n BitSet bs = new BitSet();\n int i;\n for( i = 2; i*i <= n; ++i ){\n if( bs.get(i) ) continue;\n\n int a = 0;\n for( long j = i; j <= n; j *= i, ++a, --other ){\n if( j < 1e5 ) bs.set((int)j,true);\n }\n s ^= g[a];\n }\n if( other%2==1 ) s ^= 1;\n out.println( s != 0? \"Vasya\" : \"Petya\" );\n }\n\n\n}", "src_uid": "0e22093668319217b7946e62afe32195"} {"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//package Learning;\n\n\nimport java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\n\n \npublic class Try\n{\n \n static class InputReader {\n \n\t\tprivate final InputStream stream;\n\t\tprivate final byte[] buf = new byte[8192];\n\t\tprivate int curChar, snumChars;\n \n\t\tpublic InputReader(InputStream st) {\n\t\t\tthis.stream = st;\n\t\t}\n \n\t\tpublic int read() {\n\t\t\tif (snumChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= snumChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tsnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (snumChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n \n\t\tpublic int ni() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo {\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n \n\t\tpublic long nl() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n \n\t\tpublic int[] nia(int n) {\n\t\t\tint a[] = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\ta[i] = ni();\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n \n\t\tpublic String rs() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n \n\t\tpublic String nextLine() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isEndOfLine(c));\n\t\t\treturn res.toString();\n\t\t}\n \n\t\tpublic boolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n \n\t\tprivate boolean isEndOfLine(int c) {\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t}\n \n\t}\n\t\n\n\t\n\t\n\t\n static long mod=1000000007;\n static BigInteger bigInteger = new BigInteger(\"1000000007\");\n static int n = (int)1e6;\n static boolean[] prime;\n static ArrayList<Integer> as;\n static ArrayList<Integer> []as1;\n static void sieve() {\n\t\t\tArrays.fill(prime\t, true);\n\t\t\tprime[0] = prime[1] = false;\n\t\t\tfor(int i = 2 ; i * i <= n ; ++i) {\n\t\t\t\tif(prime[i]) {\n\t\t\t\t\tfor(int k = i * i; k< n ; k+=i) {\n\t\t\t\t\t\tprime[k] = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t}\n\t\tstatic PrintWriter w = new PrintWriter(System.out);\n static int p = 0;\n static char [][]sol;\n public static void main(String[] args)\n {\n \n InputReader sc = new InputReader(System.in);\n //PrintWriter w = new PrintWriter(System.out);\n \n \n prime = new boolean[n + 1];\n\t\tsieve();\n\t\tprime[1] = false;\n\t\t\n\t\t/*\n\t\tas = new ArrayList<>();\n\t\tfor(int i=2;i<=1000000;i++)\n\t\t{\n\t\t if(prime[i])\n\t\t as.add(i);\n\t\t}\n\t\t*/\n\t\t\n /* \n\t\t\n\tlong a = sc.nl();\n\t \n BigInteger ans = new BigInteger(\"1\");\n for (long i = 1; i < Math.sqrt(a); i++) {\n if (a % i == 0) {\n if (a / i == i) {\n ans = ans.multiply(BigInteger.valueOf(phi(i)));\n \n } else {\n ans = ans.multiply(BigInteger.valueOf(phi(i)));\n ans = ans.multiply(BigInteger.valueOf(phi(a / i)));\n \n \n }\n \n \n }\n }\n w.println(ans.mod(bigInteger));\n */\n \n // MergeSort ob = new MergeSort();\n // ob.sort(arr, 0, arr.length-1);\n \n // Student []st = new Student[x]; \n // st[i] = new Student(i,d[i]);\n //Arrays.sort(st,(p,q)->p.diff-q.diff);\n//BigDecimal x = new BigDecimal(b[i]).multiply(new BigDecimal(\"-1\")).divide(new BigDecimal(a[i]),100,RoundingMode.HALF_UP);\n \n\nint x = sc.ni();\nint k = sc.ni();\nif(k==1)\n{\n w.println(3*x);\n}\nelse\n{\n int p = Math.min(k-1, x-k);\n w.println(p + (3*x));\n}\n\n\n\n \n w.close();\n \n \n \n }\n \n static int []a;\n static long a1,b;\n public static int searchlow(int x) {\n\t\tint lo=0, hi=a.length-1;\n\t\tint res=Integer.MIN_VALUE;\n\t\twhile(lo<=hi){\n\t int mid = (lo+hi)/2;\n\t if(a[mid]==x){\n\t res = mid;\n\t hi = mid - 1;\n\t }\n\t else if(a[mid]>x){\n\t hi = mid - 1;\n\t }\n\t else{\n\t lo = mid + 1;\n\t }\n\t }\n\t return res==Integer.MIN_VALUE?lo:res;\n\t}\n\tpublic static int searchhigh(int x) {\n\t\tint lo=0, hi=a.length-1;\n\t\tint res=Integer.MIN_VALUE;\n\t\twhile(lo<=hi){\n\t int mid = (lo+hi)/2;\n\t if(a[mid]==x){\n\t res = mid;\n\t lo=mid+1;\n\t }\n\t else if(a[mid]>x){\n\t hi = mid - 1;\n\t }\n\t else{\n\t lo = mid + 1;\n\t }\n\t }\n\t return res==Integer.MIN_VALUE?hi:res;\n\t}\n\tpublic static long ct(int l, int r) {\n\t\tint lo=searchlow(l), hi=searchhigh(r);\n\t\treturn hi-lo+1;\n\t}\n static long log2(long value) {\n return Long.SIZE-Long.numberOfLeadingZeros(value);\n}\n \n static class Student\n {\n int id;\n //int x;\n String s;\n int y;\n \n Student(int id,String s,int y)\n {\n this.id = id;\n //this.x = x;\n this.s = s;\n this.y = y;\n \n \n \n }\n \n }\n \n public static long modMultiply(long one, long two) {\n \n\t\treturn (one % mod * two % mod) % mod;\n\t}\n static long fx(int m)\n {\n long re = 0;\n for(int i=1;i<=m;i++)\n {\n re += (long) (i / gcd(i,m));\n }\n return re;\n }\n static int gcd(int a, int b)\n {\n\t if (a == 0)\n\t return b;\n\t\t\t\t \n\treturn gcd(b%a, a);\n }\n \n \n \n static long phi(long nx)\n {\n // Initialize result as n\n double result = nx; \n \n \n // Consider all prime factors of n and for \n // every prime factor p, multiply result\n // with (1 - 1/p)\n for (int p = 0; as.get(p) * as.get(p) <= nx; ++p)\n {\n // Check if p is a prime factor.\n if (nx % as.get(p) == 0)\n {\n // If yes, then update n and result\n while (nx % as.get(p) == 0)\n nx /= as.get(p);\n result *= (1.0 - (1.0 / (double) as.get(p)));\n }\n }\n \n // If n has a prime factor greater than sqrt(n)\n // (There can be at-most one such prime factor)\n if (nx > 1)\n result *= (1.0 - (1.0 / (double) nx));\n \n return (long)result;\n \n \n //return(phi((long)result,k-1));\n \n }\n \n public static void primeFactors(int n,int x)\n {\n as = new ArrayList<>();\n \n // Print the number of 2s that divide n\n while (n%2==0)\n {\n \n \n as.add(2);\n //System.out.print(2 + \" \");\n n /= 2;\n \n }\n \n // n must be odd at this point. So we can\n // skip one element (Note i = i +2)\n for (int i = 3; i <= Math.sqrt(n); i+= 2)\n {\n // While i divides n, print i and divide n\n while (n%i == 0)\n {\n \n // System.out.print(i + \" \");\n \n as.add(i);\n n /= i;\n \n \n }\n \n }\n \n // This condition is to handle the case whien\n // n is a prime number greater than 2\n if (n >= 2)\n {\n \n as.add(n);\n }\n \n }\n static int digitsum(int x)\n \n { \n \n int sum = 0;\n while(x > 0)\n {\n int temp = x % 10;\n sum += temp;\n x /= 10;\n }\n return sum;\n \n }\n static int countDivisors(int n)\n {\n int cnt = 0;\n for (int i = 1; i*i <=n; i++)\n {\n if (n % i == 0 && i<=1000000)\n {\n // If divisors are equal,\n // count only one\n if (n / i == i)\n cnt++;\n \n else // Otherwise count both\n cnt = cnt + 2;\n }\n }\n return cnt;\n }\n \n static boolean isprime(long n)\n {\n \n if(n == 2)\n return true;\n if(n == 3)\n return true;\n if(n % 2 == 0)\n return false;\n if(n % 3 == 0)\n return false;\n \n long i = 5;\n long w = 2;\n \n while(i * i <= n)\n {\n if(n % i == 0)\n return false;\n \n \n i += w;\n w = 6 - w;\n }\n \n return true;\n }\n \n \n \n \n \n \n static boolean binarysearch(int []arr,int p,int n)\n {\n //ArrayList<Integer> as = new ArrayList<>();\n //as.addAll(0,at);\n //Collections.sort(as);\n boolean re = false;\n int st = 0;\n int end = n-1;\n \n \n \n while(st <= end)\n { \n int mid = (st+end)/2;\n \n if(p > arr[mid])\n {\n st = mid+1;\n \n }\n else if(p < arr[mid])\n {\n end = mid-1;\n \n }\n else if(p == arr[mid])\n {\n \n re = true;\n break;\n }\n \n \n \n }\n return re;\n \n }\n \n \n \n /* Java program for Merge Sort */\nstatic class 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(int arr[], int l, int m, int r)\n {\n // Find sizes of two subarrays to be merged\n int n1 = m - l + 1;\n int n2 = r - m;\n \n /* Create temp arrays */\n int L[] = new int [n1];\n int R[] = new int [n2];\n \n /*Copy data to temp arrays*/\n for (int i=0; i<n1; ++i)\n L[i] = arr[l + i];\n for (int j=0; j<n2; ++j)\n R[j] = arr[m + 1+ j];\n \n \n /* Merge the temp arrays */\n \n // Initial indexes of first and second subarrays\n int i = 0, j = 0;\n \n // Initial index of merged subarry array\n int k = l;\n while (i < n1 && j < n2)\n {\n if (L[i] <= R[j])\n {\n arr[k] = L[i];\n i++;\n }\n else\n {\n arr[k] = R[j];\n j++;\n }\n k++;\n }\n \n /* Copy remaining elements of L[] if any */\n while (i < n1)\n {\n arr[k] = L[i];\n i++;\n k++;\n }\n \n /* Copy remaining elements of R[] if any */\n while (j < n2)\n {\n arr[k] = R[j];\n j++;\n k++;\n }\n }\n \n // Main function that sorts arr[l..r] using\n // merge()\n void sort(int arr[], int l, int r)\n {\n if (l < r)\n {\n // Find the middle point\n int m = (l+r)/2;\n \n // Sort first and second halves\n sort(arr, l, m);\n sort(arr , m+1, r);\n \n // Merge the sorted halves\n merge(arr, l, m, r);\n }\n }\n \n /* A utility function to print array of size n */\n \n \n \n}\n \n\n \n \n \n public static int ip(String s){\n\t\treturn Integer.parseInt(s);\n\t}\n\t public static String ips(int s){\n\t\treturn Integer.toString(s);\n\t}\n\t\n // Java program to print all permutations using\n// Heap's algorithm\nstatic class HeapAlgo\n{\n //static ArrayList<Integer> []ad;\n\t//Prints the array\n\tvoid printArr(int a[], int n)\n\t{\n\t \n\t \n\t\tfor (int i=0; i<n; i++)\n\t\t{\n\t\t\tSystem.out.print(a[i] + \" \");\n\t\tas1[p].add(a[i]);\n\t\t}\n p++;\n \n\t\t//System.out.println();\n\t}\n\n\t//Generating permutation using Heap Algorithm\n\tvoid heapPermutation(int a[], int size, int n)\n\t{\n\t\t// if size becomes 1 then prints the obtained\n\t\t// permutation\n\t\t\n\t\tif (size == 1)\n\t\t{\n\t\t\tprintArr(a,n);\n\t\t\t\n\t\t}\n\n\t\tfor (int i=0; i<size; i++)\n\t\t{\n\t\t\theapPermutation(a, size-1, n);\n p++;\n\n\t\t\t// if size is odd, swap first and last\n\t\t\t// element\n\t\t\tif (size % 2 == 1)\n\t\t\t{\n\t\t\t\tint temp = a[0];\n\t\t\t\ta[0] = a[size-1];\n\t\t\t\ta[size-1] = temp;\n\t\t\t}\n\n\t\t\t// If size is even, swap ith and last\n\t\t\t// element\n\t\t\telse\n\t\t\t{\n\t\t\t\tint temp = a[i];\n\t\t\t\ta[i] = a[size-1];\n\t\t\t\ta[size-1] = temp;\n\t\t\t}\n\t\t}\n\t}\n public static int lowerBound(int[] array, int length, int value) {\n int low = 0;\n int high = length-1;\n while (low < high) {\n final int mid = (low + high) / 2;\n if (value <= array[mid]) {\n high = mid;\n } else {\n low = mid + 1;\n }\n }\n return low;\n }\n public static int upperBound(int[] array, int length, int value) {\n int low = 0;\n int high = length-1;\n while (low < high) {\n final int mid = (low + high) / 2;\n if (value >= array[mid]) {\n low = mid + 1;\n } else {\n high = mid;\n }\n }\n return low;\n }\n\n\t// Driver code\n\t\n\t\t\n\t\n}\n\n// This code has been contributed by Amit Khandelwal.\n// JAVA program for implementation of KMP pattern \n// searching algorithm \n\nstatic class KMP_String_Matching { \n\tboolean KMPSearch(String pat, String txt) \n\t{ \n int f = 0;\n\t\tint M = pat.length(); \n\t\tint N = txt.length(); \n\n\t\t// create lps[] that will hold the longest \n\t\t// prefix suffix values for pattern \n\t\tint lps[] = new int[M]; \n\t\tint j = 0; // index for pat[] \n\n\t\t// Preprocess the pattern (calculate lps[] \n\t\t// array) \n\t\tcomputeLPSArray(pat, M, lps); \n\n\t\tint i = 0; // index for txt[] \n\t\twhile (i < N) { \n\t\t\tif (pat.charAt(j) == txt.charAt(i)) { \n\t\t\t\tj++; \n\t\t\t\ti++; \n\t\t\t} \n\t\t\tif (j == M) { \n /*\n\t\t\t\tSystem.out.println(\"Found pattern \"\n\t\t\t\t\t\t\t\t+ \"at index \" + (i - j)); \n */\n f = 1;\n // return true;\n\t\t\t\tj = lps[j - 1]; \n\t\t\t} \n\n\t\t\t// mismatch after j matches \n\t\t\telse if (i < N && pat.charAt(j) != txt.charAt(i)) { \n\t\t\t\t// Do not match lps[0..lps[j-1]] characters, \n\t\t\t\t// they will match anyway \n\t\t\t\tif (j != 0) \n\t\t\t\t\tj = lps[j - 1]; \n\t\t\t\telse\n\t\t\t\t\ti = i + 1; \n\t\t\t} \n\t\t} \n if(f==0)\n return false;\n else\n return true;\n\t} \n\n\tvoid computeLPSArray(String pat, int M, int lps[]) \n\t{ \n\t\t// length of the previous longest prefix suffix \n\t\tint len = 0; \n\t\tint i = 1; \n\t\tlps[0] = 0; // lps[0] is always 0 \n\n\t\t// the loop calculates lps[i] for i = 1 to M-1 \n\t\twhile (i < M) { \n\t\t\tif (pat.charAt(i) == pat.charAt(len)) { \n\t\t\t\tlen++; \n\t\t\t\tlps[i] = len; \n\t\t\t\ti++; \n\t\t\t} \n\t\t\telse // (pat[i] != pat[len]) \n\t\t\t{ \n\t\t\t\t// This is tricky. Consider the example. \n\t\t\t\t// AAACAAAA and i = 7. The idea is similar \n\t\t\t\t// to search step. \n\t\t\t\tif (len != 0) { \n\t\t\t\t\tlen = lps[len - 1]; \n\n\t\t\t\t\t// Also, note that we do not increment \n\t\t\t\t\t// i here \n\t\t\t\t} \n\t\t\t\telse // if (len == 0) \n\t\t\t\t{ \n\t\t\t\t\tlps[i] = len; \n\t\t\t\t\ti++; \n\t\t\t\t} \n\t\t\t} \n\t\t} \n\t} \n\n\t// Driver program to test above function \n /*\n\tpublic static void main(String args[]) \n\t{ \n\t\tString txt = \"ABABDABACDABABCABAB\"; \n\t\tString pat = \"ABABCABAB\"; \n\t\tnew KMP_String_Matching().KMPSearch(pat, txt); \n\t} \n */\n} \n// This code has been contributed by Amit Khandelwal. \n\n\n \n\t\t\t\t\t \n}\n", "src_uid": "24b02afe8d86314ec5f75a00c72af514"} {"source_code": "import java.io.*;\r\nimport java.lang.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n public static MyScanner sc = new MyScanner(System.in);\r\n public static PrintWriter out = new PrintWriter(System.out);\r\n public static void main(String[] args) {\r\n int n = sc.nextint();\r\n int mod = sc.nextint();\r\n int[] dp1 = new int[n + 9];\r\n int[] dp2 = new int[n + 9];\r\n dp2[1] = 1;\r\n for(int i = 1; i <= n; i++){\r\n dp1[i] += dp1[i - 1];\r\n dp1[i] %= mod;\r\n dp2[i] = dp1[i];\r\n if(i == 1){\r\n dp2[i] = 1;\r\n }\r\n dp1[i + 1] += dp2[i];\r\n dp1[i + 1] %= mod;\r\n for(int j = 2; i * j <= n; j++){\r\n dp1[i * j] += dp2[i];\r\n dp1[i * j] %= mod;\r\n if((i + 1) * j <= n) {\r\n dp1[(i + 1) * j] += mod - dp2[i];\r\n dp1[(i + 1) * j] %= mod;\r\n }\r\n }\r\n }\r\n out.print(dp2[n]);\r\n out.close();\r\n }\r\n}\r\nclass MyScanner {\r\n private BufferedReader br;\r\n private StringTokenizer tokenizer;\r\n\r\n public MyScanner(InputStream is) {\r\n br = new BufferedReader(new InputStreamReader(is));\r\n }\r\n\r\n public String next() {\r\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\r\n try {\r\n tokenizer = new StringTokenizer(br.readLine());\r\n } catch (IOException e) {\r\n throw new RuntimeException(e);\r\n }\r\n }\r\n return tokenizer.nextToken();\r\n }\r\n\r\n public int nextint() {\r\n return Integer.parseInt(next());\r\n }\r\n public long nextlong() {\r\n return Long.parseLong(next());\r\n }\r\n}", "src_uid": "77443424be253352aaf2b6c89bdd4671"} {"source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.Arrays;\nimport java.util.Locale;\nimport java.util.StringTokenizer;\n\npublic class Main {\n\n long binpow(int a, int n) {\n long r = 1;\n while (n > 0) {\n if ((n & 1) > 0) {\n r *= a;\n }\n a *= a;\n n /= 2;\n }\n return r;\n }\n\n long gcd(long x, long y) {\n return y == 0 ? x : gcd(y, x % y);\n }\n\n void solve() throws IOException {\n BigInteger n = BigInteger.valueOf(readLong()), k = BigInteger.valueOf(readLong()), m = BigInteger.valueOf(readLong()), d = BigInteger.valueOf(readLong());\n long maxRes = -1;\n\n // todo check M\n\n BigInteger resForM = checkM(n.longValue(), k.longValue(), m.longValue(), d.longValue());\n System.err.println(\"resForM = \" + resForM);\n maxRes = Math.max(maxRes, resForM.longValue());\n\n\n for (long rounds = 1; rounds <= d.longValue(); rounds++) {\n System.err.println(\"rounds = \" + rounds);\n BigInteger x = n.divide(k.multiply(BigInteger.valueOf(rounds - 1)).add(BigInteger.ONE));\n System.err.println(\"x = \" + x);\n if (x.compareTo(m) > 0) {\n continue;\n }\n BigInteger res = x.multiply(BigInteger.valueOf(rounds));\n System.err.println(\"res = \" + res);\n if (res.longValue() > maxRes) {\n maxRes = res.longValue();\n }\n }\n System.out.println(maxRes);\n }\n\n private BigInteger checkM(long n, long k, long m, long d) {\n long s = n / m;\n long rounds = (s + k - 1) / k;\n if (rounds > d) {\n return BigInteger.valueOf(-1);\n }\n return BigInteger.valueOf(rounds).multiply(BigInteger.valueOf(m));\n }\n\n //-------------------------------------------------\n\n final boolean ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null;\n\n BufferedReader in;\n PrintWriter out;\n StringTokenizer tok;\n\n public void run() {\n try {\n long startTime = System.currentTimeMillis();\n Locale.setDefault(Locale.US);\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 tok = new StringTokenizer(\"\");\n solve();\n in.close();\n out.close();\n long endTime = System.currentTimeMillis();\n long totalMemory = Runtime.getRuntime().totalMemory();\n long freeMemory = Runtime.getRuntime().freeMemory();\n System.err.println(\"Time = \" + (endTime - startTime) + \" ms\");\n System.err.println(\"Memory = \" + ((totalMemory - freeMemory) / 1024) + \" KB\");\n } catch (Throwable e) {\n e.printStackTrace(System.err);\n System.exit(-1);\n }\n }\n\n String readString() {\n while (!tok.hasMoreTokens()) {\n String line = null;\n try {\n line = in.readLine();\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n if (line == null) return null;\n tok = new StringTokenizer(line);\n }\n return tok.nextToken();\n }\n\n int readInt() {\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 void debug(Object... o) {\n if (!ONLINE_JUDGE) {\n System.err.println(Arrays.deepToString(o));\n }\n }\n\n public static void main(String[] args) {\n new Main().run();\n }\n}", "src_uid": "ac2e795cd44061db8da13e3947ba791b"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\nimport java.util.StringTokenizer;\n\npublic class Prob242A {\n\tpublic static void main(String[] Args) throws IOException {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(br.readLine());\n\t\tint x = Integer.parseInt(st.nextToken());\n\t\tint m = Integer.parseInt(st.nextToken());\n\n\t\tBigInteger temp = BigInteger.ONE;\n\t\tBigInteger mod = BigInteger.valueOf(1000000009);\n\t\tBigInteger two = temp.add(temp);\n\t\tfor (int i = 0; i < m; i++)\n\t\t\ttemp = temp.multiply(two).mod(mod);\n\t\ttemp = temp.subtract(BigInteger.ONE);\n\n\t\tBigInteger bi = BigInteger.ONE;\n\t\tint temp2 = temp.intValue();\n\t\tfor (int i = temp2, j = 0; j < x; i--, j++) {\n\t\t\tbi = bi.multiply(BigInteger.valueOf(i)).mod(mod);\n\t\t\tif (bi.intValue() == 0)\n\t\t\t\tbreak;\n\t\t}\n\n\t\tSystem.out.println(bi);\n\n\t}\n}\n", "src_uid": "fef4d9c94a93fcf6d536f33503b1d4b8"} {"source_code": "import java.util.Scanner;\n\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tString s = in.next();\n\t\tint n = s.length();\n\t\tchar[] a = new char[n];\n\t\tfor(int i = 0; i < s.length(); ++i) {\n\t\t\ta[i] = s.charAt(i);\n\t\t}\n\t\t\n\t\tint y=0,g=0,r=0,b=0;\n\t\tint[] YBRG = {-1,-1,-1,-1};\n\t\tchar[] cYBRG = {'Y','B','R','G'};\n\t\tfor(int i = 0; i < s.length(); i++) {\n\t\t\tif(a[i] == 'Y' && YBRG[0] == -1) YBRG[0] = i%4;\n\t\t\tif(a[i] == 'B' && YBRG[1] == -1) YBRG[1] = i%4;\n\t\t\tif(a[i] == 'R' && YBRG[2] == -1) YBRG[2] = i%4;\n\t\t\tif(a[i] == 'G' && YBRG[3] == -1) YBRG[3] = i%4;\n\t\t}\n\t\tfor(int z = 0; z < 4; ++z) {\n\t\t\tfor(int i = 0; i < 3; ++i) {\n\t\t\t\tif(YBRG[i] > YBRG[i+1]) {\n\t\t\t\t\tint t = YBRG[i];\n\t\t\t\t\tchar c = cYBRG[i];\n\t\t\t\t\tYBRG[i] = YBRG[i+1];\n\t\t\t\t\tcYBRG[i] = cYBRG[i+1];\n\t\t\t\t\tYBRG[i+1] = t;\n\t\t\t\t\tcYBRG[i+1] = c;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t\n\t\tfor(int i = 0; i < s.length(); ++i) {\n\t\t\tif(s.charAt(i) == '!') {\n\t\t\t\tif(cYBRG[i%4] == 'Y') y++;\n\t\t\t\tif(cYBRG[i%4] == 'B') b++;\n\t\t\t\tif(cYBRG[i%4] == 'R') r++;\n\t\t\t\tif(cYBRG[i%4] == 'G') g++;\n\t\t\t}\n\t\t}\n\t\n\t\tSystem.out.println(r + \" \" + b + \" \" + y + \" \" + g);\n\t}\n}\n", "src_uid": "64fc6e9b458a9ece8ad70a8c72126b33"} {"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.FilterInputStream;\nimport java.io.BufferedInputStream;\nimport java.io.InputStream;\n\n/**\n * @author khokharnikunj8\n */\n\npublic class Main {\n public static void main(String[] args) {\n new Thread(null, new Runnable() {\n public void run() {\n new Main().solve();\n }\n }, \"1\", 1 << 26).start();\n }\n\n void solve() {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n ScanReader in = new ScanReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n BNumbers solver = new BNumbers();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class BNumbers {\n int mod = 1000000007;\n\n public void solve(int testNumber, ScanReader in, PrintWriter out) {\n int n = in.scanInt();\n int[] ar = new int[10];\n for (int i = 0; i < 10; i++) {\n ar[i] = in.scanInt();\n }\n int[][] nCr = new int[101][];\n for (int i = 0; i <= 100; i++) {\n nCr[i] = new int[i + 2];\n for (int j = 0; j <= i; j++) {\n if (i == 0 || j == 0) nCr[i][j] = 1;\n else nCr[i][j] = (nCr[i - 1][j - 1] + nCr[i - 1][j]) % mod;\n }\n }\n long ans = 0;\n for (int i = 1; i <= 9; i++) {\n ar[i]--;\n long[][] dp = new long[2][n];\n dp[1][0] = 1;\n for (int j = 0; j <= 9; j++) {\n Arrays.fill(dp[j & 1], 0);\n for (int k = 0; k < n; k++) {\n for (int l = Math.max(0, ar[j]); k + l < n; l++) {\n dp[j & 1][k + l] = (dp[j & 1][k + l] + dp[(j - 1) & 1][k] * nCr[k + l][l]) % mod;\n }\n }\n }\n for (int j = 0; j < n; j++) ans = (ans + dp[1][j]) % mod;\n ar[i]++;\n }\n out.println(ans);\n\n\n }\n\n }\n\n static class ScanReader {\n private byte[] buf = new byte[4 * 1024];\n private int index;\n private BufferedInputStream in;\n private int total;\n\n public ScanReader(InputStream inputStream) {\n in = new BufferedInputStream(inputStream);\n }\n\n private int scan() {\n if (index >= total) {\n index = 0;\n try {\n total = in.read(buf);\n } catch (Exception e) {\n e.printStackTrace();\n }\n if (total <= 0) return -1;\n }\n return buf[index++];\n }\n\n public int scanInt() {\n int integer = 0;\n int n = scan();\n while (isWhiteSpace(n)) n = scan();\n int neg = 1;\n if (n == '-') {\n neg = -1;\n n = scan();\n }\n while (!isWhiteSpace(n)) {\n if (n >= '0' && n <= '9') {\n integer *= 10;\n integer += n - '0';\n n = scan();\n }\n }\n return neg * integer;\n }\n\n private boolean isWhiteSpace(int n) {\n if (n == ' ' || n == '\\n' || n == '\\r' || n == '\\t' || n == -1) return true;\n else return false;\n }\n\n }\n}\n\n", "src_uid": "c1b5169a5c3b1bd4a2f1df1069ee7755"} {"source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.FileNotFoundException;\nimport java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author triveni\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\tF solver = new F();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n\n\tstatic class F {\n\t\tprivate Long[][] lastX = new Long[2010][2010];\n\t\tprivate long mod = 998244353;\n\t\tprivate long p = 0;\n\t\tprivate long[] pPow = new long[2010];\n\t\tprivate long[] qPow = new long[2010];\n\t\tprivate long[] strong = new long[2010];\n\t\tprivate Long[] dp = new Long[2010];\n\n\t\tpublic void solve(int testNumber, InputReader in, PrintWriter out) {\n\t\t\tint n = in.nextInt();\n\t\t\tint a = in.nextInt(), b = in.nextInt();\n\t\t\tp = MathUtils.powMod(b, mod - 2, mod) * a % mod;\n\t\t\tpPow[0] = 1;\n\t\t\tqPow[0] = 1;\n\t\t\tfor (int i = 1; i < 2010; ++i) {\n\t\t\t\tpPow[i] = pPow[i - 1] * p % mod;\n\t\t\t\tqPow[i] = qPow[i - 1] * (1 - p + mod) % mod;\n\t\t\t}\n\t\t\tstrong[1] = 1;\n\t\t\tfor (int i = 2; i <= n; ++i) {\n\t\t\t\tlong ans = 0;\n\t\t\t\tfor (int j = 1; j < i; ++j) {\n\t\t\t\t\tans += strong[j] * computeLastX(i, j) % mod;\n\t\t\t\t\tif (ans >= mod) ans -= mod;\n\t\t\t\t}\n\t\t\t\tstrong[i] = 1 - ans;\n\t\t\t\tif (strong[i] < 0) strong[i] += mod;\n\t\t\t}\n\t\t\tlong ans = dp(n);\n\t\t\tout.println(ans);\n\t\t}\n\n\t\tprivate long computeLastX(int n, int i) {\n\t\t\tif (lastX[n][i] != null) return lastX[n][i];\n\t\t\tif (n == i || i == 0) return lastX[n][i] = 1L;\n\t\t\tlong ans = qPow[i] * computeLastX(n - 1, i) % mod + pPow[n - i] * computeLastX(n - 1, i - 1) % mod;\n\t\t\treturn lastX[n][i] = ans % mod;\n\t\t}\n\n\t\tprivate long dp(int n) {\n\t\t\tif (dp[n] != null) return dp[n];\n\t\t\tif (n < 2) return dp[n] = 0L;\n\t\t\tif (n < 3) return dp[n] = 1L;\n\t\t\tlong ans = strong[n] * (n * (n - 1) / 2) % mod;\n\t\t\tfor (int x = 1; x < n; ++x) {\n\t\t\t\tlong tmp = computeLastX(n, x) * strong[x] % mod;\n\t\t\t\ttmp *= (x * (x - 1) / 2 + x * (n - x) + dp(n - x) + dp(x)) % mod;\n\t\t\t\tans += tmp % mod;\n\t\t\t}\n\t\t\tans %= mod;\n\t\t\tans *= MathUtils.powMod(1 + mod - strong[n], mod - 2, mod);\n\t\t\treturn dp[n] = ans % mod;\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 inputStream) {\n\t\t\treader = new BufferedReader(new InputStreamReader(inputStream));\n\t\t\ttokenizer = null;\n\t\t}\n\n\t\tpublic InputReader(String inputFile) throws FileNotFoundException {\n\t\t\treader = new BufferedReader(new FileReader(inputFile));\n\t\t\ttokenizer = null;\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tString curr = \"\";\n\t\t\ttry {\n\t\t\t\tcurr = reader.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t\treturn curr;\n\t\t}\n\n\t\tpublic String nextString() {\n\t\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\ttokenizer = new StringTokenizer(nextLine());\n\t\t\t\t} catch (Exception 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(nextString());\n\t\t}\n\n\t}\n\n\tstatic class MathUtils {\n\t\tpublic static long powMod(long a, long b, long m) {\n\t\t\tlong ans = 1;\n\t\t\twhile (b > 0) {\n\t\t\t\tif (b % 2 == 1) ans = ans * a % m;\n\t\t\t\tb >>= 1;\n\t\t\t\ta = a * a % m;\n\t\t\t}\n\t\t\treturn ans % m;\n\t\t}\n\n\t}\n}\n\n", "src_uid": "67e599530203060c17f692f2624d0f99"} {"source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.FilterInputStream;\nimport java.io.BufferedInputStream;\nimport java.io.InputStream;\n\n/**\n * @author khokharnikunj8\n */\n\npublic class Main {\n public static void main(String[] args) {\n new Thread(null, new Runnable() {\n public void run() {\n new Main().solve();\n }\n }, \"1\", 1 << 26).start();\n }\n\n void solve() {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n ScanReader in = new ScanReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n DFelicitysBigSecretRevealed solver = new DFelicitysBigSecretRevealed();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class DFelicitysBigSecretRevealed {\n int mod = 1000000007;\n\n public void solve(int testNumber, ScanReader in, PrintWriter out) {\n int n = in.scanInt();\n char[] ar = in.scanChars(n);\n int[][] dp = new int[n + 1][1 << 20];\n long ans = 0;\n for (int i = 0; i < n; i++) {\n dp[i][0]++;\n for (int j = 0; j < (1 << 20); j++) {\n if (dp[i][j] == 0) continue;\n for (int k = i + 1, val = 0; k <= n && val <= 20; k++) {\n val <<= 1;\n val |= (ar[k - 1] - '0');\n if (val > 20) break;\n if ((j | (1 << (val - 1))) < (1 << 20)) {\n if (val != 0)\n dp[k][(j | (1 << (val - 1)))] = (dp[k][(j | (1 << (val - 1)))] + dp[i][j]) % mod;\n }\n }\n }\n for (int j = 1; j <= 20; j++) ans = (ans + dp[i + 1][(1 << j) - 1]) % mod;\n }\n out.println(ans);\n\n }\n\n }\n\n static class ScanReader {\n private byte[] buf = new byte[4 * 1024];\n private int index;\n private BufferedInputStream in;\n private int total;\n\n public ScanReader(InputStream inputStream) {\n in = new BufferedInputStream(inputStream);\n }\n\n private int scan() {\n if (index >= total) {\n index = 0;\n try {\n total = in.read(buf);\n } catch (Exception e) {\n e.printStackTrace();\n }\n if (total <= 0) return -1;\n }\n return buf[index++];\n }\n\n public int scanInt() {\n int integer = 0;\n int n = scan();\n while (isWhiteSpace(n)) n = scan();\n int neg = 1;\n if (n == '-') {\n neg = -1;\n n = scan();\n }\n while (!isWhiteSpace(n)) {\n if (n >= '0' && n <= '9') {\n integer *= 10;\n integer += n - '0';\n n = scan();\n }\n }\n return neg * integer;\n }\n\n public char[] scanChars(int n) {\n char[] ar = new char[n];\n int c = scan();\n boolean flag = true;\n while (isWhiteSpace(c)) c = scan();\n ar[0] = (char) c;\n for (int i = 1; i < n; i++) ar[i] = (char) (c = scan());\n return ar;\n }\n\n private boolean isWhiteSpace(int n) {\n if (n == ' ' || n == '\\n' || n == '\\r' || n == '\\t' || n == -1) return true;\n else return false;\n }\n\n }\n}\n\n", "src_uid": "61f88159762cbc7c51c36e7b56ecde48"} {"source_code": "import java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\nimport java.io.OutputStreamWriter;\r\nimport java.io.PrintWriter;\r\nimport java.util.StringTokenizer;\r\n\r\n\r\npublic class E3 {\r\n\r\n void solve() throws IOException {\r\n char[] c = reader.readLine().toCharArray();\r\n int[] a = doit(c);\r\n if (a != null) {\r\n out.println(a.length);\r\n for (int j = 0; j < a.length; j++) {\r\n out.print(a[j] + \" \");\r\n }\r\n }\r\n }\r\n\r\n int[] doit(char[] c) {\r\n int l = 0;\r\n int r = 200000;\r\n while (l < r) {\r\n index = 0;\r\n int n = (l + r) / 2;\r\n int[] a = new int[n];\r\n int[] b = new int[n];\r\n for (int i = 0; i < n; i++) {\r\n a[i] = b[i] = i + 1;\r\n }\r\n boolean res = simulateMerge(0, n, c, a, b);\r\n if (!res) {\r\n r = n;\r\n } else if (index < c.length) {\r\n l = n + 1;\r\n } else {\r\n for (int i = 0; i < n; i++) {\r\n b[a[i] - 1] = i + 1;\r\n }\r\n return b;\r\n }\r\n }\r\n return null;\r\n }\r\n\r\n int index = 0;\r\n\r\n boolean simulateMerge(int l, int r, char[] c, int[] a, int[] b) {\r\n if (r - l <= 1) return true;\r\n int m = (l + r) >> 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 E3().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}", "src_uid": "b2ee84d23d73947fa84faaaebfde85c8"} {"source_code": "import java.util.Scanner;\npublic class r262B {\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 scnr = new Scanner(System.in);\n\n\t\tint a = scnr.nextInt();\n\t\tint b = scnr.nextInt();\n\t\tint c = scnr.nextInt();\n\t\tint count = 0;\n\t\tlong[] ans = new long[81];\n\t\tscnr.close();\n\n\t\tfor (int i = 1; i <= 81; i++){\n\t\t\tlong answer = 1;\n\t\t\tfor (int j = 0; j < a; j++)\n\t\t\t\tanswer = answer * i;\n\t\t\tanswer = answer*b+c;\n\t\t\tif (answer > 0 && answer < 1000000000 && getSum((int)answer) == i){\n\t\t\t\tans[count] = answer;\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\n\t\tSystem.out.print(count);\n\t\tif (count!= 0){\n\t\t\tSystem.out.println();\n\t\t\tfor (int i = 0; i < count-1; i++){\n\t\t\t\tSystem.out.print(ans[i] + \" \");\n\t\t\t}\n\t\t\tSystem.out.print(ans[count-1]);\n\t\t}\n\n\n\t}\n\n\tprivate static int getSum(int a){\n\t\tint b = 0;\n\t\twhile (a > 0){\n\t\t\tb = a%10 + b;\n\t\t\ta = a/10;\n\t\t}\n\t\treturn b;\n\t}\n}\n", "src_uid": "e477185b94f93006d7ae84c8f0817009"} {"source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\nimport java.awt.geom.*;\n\npublic class Main{\npublic static void main(String[] args) throws IOException\n {\n (new Main()).run();\n }\n\nFile input,output;\nScanner in;\nPrintWriter out;\n\npublic void run() throws IOException\n{ \nin = new Scanner(System.in);\nout = new PrintWriter(System.out);\n\nint vx = in.nextInt();\nint vy = in.nextInt();\nint px = in.nextInt();\nint py = in.nextInt();\nint wx1 = in.nextInt();\nint wy1 = in.nextInt();\nint wx2 = in.nextInt();\nint wy2 = in.nextInt();\nint mx1 = in.nextInt();\nint my1 = in.nextInt();\nint mx2 = in.nextInt();\nint my2 = in.nextInt();\n\nLine2D vp = new Line2D.Double(vx,vy,px,py);\nLine2D wall = new Line2D.Double(wx1,wy1,wx2,wy2);\nLine2D mirror = new Line2D.Double(mx1,my1,mx2,my2);\n\nif(!wall.intersectsLine(vp))\n {\n// out.println(\"Wall doesn't intersect vp\");\n int vpx = px-vx;\n int vpy = py-vy;\n int mirrorX = mx2-mx1;\n int mirrorY = my2-my1;\n\n// out.println(\"Vasya-Petya vector: \"+vpx+\" \"+vpy);\n// out.println(\"Mirror vector: \"+mirrorX+\" \"+mirrorY);\n\n if(vpx*mirrorY-vpy*mirrorX==0)\n {\n out.println(\"YES\");\n out.close();\n return;\n }\n\n if(!mirror.intersectsLine(vp))\n {\n out.println(\"YES\");\n out.close();\n return;\n } \n }\n//else out.println(\"Wall intersects vp\");\n\nint mirrorX = mx2-mx1;\nint mirrorY = my2-my1;\n\nint normalX = -mirrorY;\nint normalY = mirrorX;\n\nint ma = normalX;\nint mb = normalY;\nint mc = -ma*mx1-mb*my1;\n\nint signv = ma*vx+mb*vy+mc;\nint signp = ma*px+mb*py+mc;\n\nsignv = signv==0 ? 0 : signv/Math.abs(signv);\nsignp = signp==0 ? 0 : signp/Math.abs(signp);\n\nif(signv*signp<=0)\n {\n out.println(\"NO\");\n out.close();\n return;\n }\n\ndouble pdist = mirror.ptLineDist(px,py);\ndouble normalLength = Math.sqrt(normalX*normalX+normalY*normalY);\ndouble normX = normalX*pdist/normalLength;\ndouble normY = normalY*pdist/normalLength;\n\ndouble p1X = px+2*normX;\ndouble p2X = px-2*normX;\ndouble p1Y = py+2*normY;\ndouble p2Y = py-2*normY;\n\ndouble p1dist = mirror.ptLineDist(p1X,p1Y);\ndouble p2dist = mirror.ptLineDist(p2X,p2Y);\ndouble qX,qY;\nif(p1dist<p2dist) \n {\n qX = p1X;\n qY = p1Y;\n }\nelse \n {\n qX = p2X;\n qY = p2Y;\n }\n\nLine2D imaginaryLine = new Line2D.Double(vx,vy,qX,qY);\nif(!mirror.intersectsLine(imaginaryLine))\n {\n out.println(\"NO\");\n out.close();\n return;\n }\n\ndouble lx = vx;\ndouble ly = vy;\ndouble rx = qX;\ndouble ry = qY;\ndouble medx,medy;\n\nwhile(Math.sqrt((lx-rx)*(lx-rx)+(ly-ry)*(ly-ry))>1e-4)\n {\n medx = (lx+rx)/2;\n medy = (ly+ry)/2;\n if(mirror.relativeCCW(medx,medy)==mirror.relativeCCW(vx,vy))\n {\n lx = medx;\n ly = medy;\n }\n else \n {\n rx = medx;\n ry = medy;\n }\n }\n\nmedx = (lx+rx)/2;\nmedy = (ly+ry)/2;\n\nLine2D vmirror = new Line2D.Double(vx,vy,medx,medy);\nLine2D pmirror = new Line2D.Double(px,py,medx,medy);\nif(wall.intersectsLine(vmirror)||wall.intersectsLine(pmirror)) out.println(\"NO\");\nelse out.println(\"YES\");\nout.close();\n\n}\n\n}\n", "src_uid": "7539a41268b68238d644795bccaa0c0f"} {"source_code": "import java.util.Scanner;\n\npublic class cola {\n public static void main(String[] args) {\n\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int m = in.nextInt();\n\n int[] arr = new int[n];\n\n for (int i = 0; i < n; i++) {\n arr[i] = in.nextInt();\n }\n\n int index = -1;\n\n for (;;) {\n for (int j = 0; j < n; j++)\n\n if (arr[j] > 0) {\n arr[j] -= m;\n index = j;\n }\n\n int count = 0;\n\n for (int j = 0; j < n; j++)\n if (arr[j] > 0)\n count++;\n\n if (count == 0)\n break;\n }\n\n System.out.println(index + 1);\n\n }\n}", "src_uid": "c0ef1e4d7df360c5c1e52bc6f16ca87c"} {"source_code": "import java.io.IOException;\nimport java.util.Scanner;\npublic class magicnumber {\n public static void main(String[] args) throws IOException {\n Scanner cs= new Scanner(System.in);\n \n String s;\n \n s=cs.next();\n if(s.charAt(0)!='1')\n { System.out.println(\"NO\");}\n else if(s.contains(\"444\"))\n { System.out.println(\"NO\");}\n \n else if(s.contains(\"0\")||s.contains(\"2\") ||s.contains(\"3\")||s.contains(\"5\")||s.contains(\"6\")||s.contains(\"7\")|| s.contains(\"8\")||s.contains(\"9\"))\n {System.out.println(\"NO\");\n }\n else\n { System.out.println(\"YES\");}\n }\n }", "src_uid": "3153cfddae27fbd817caaf2cb7a6a4b5"} {"source_code": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintStream;\nimport java.util.*;\n\n\npublic class B\n{\n\tBufferedReader in;\n\tPrintStream out;\n\tStringTokenizer tok;\n\tpublic B() throws NumberFormatException, IOException\n\t{\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t//in = new BufferedReader(new FileReader(\"in.txt\"));\n\t\tout = System.out;\n\t\trun();\n\t}\n\tdouble dist(int x1, int y1, int x2, int y2)\n\t{\n\t\treturn Math.sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));\n\t}\n\tboolean circInside(double d, int r1, int r2)\n\t{\n\t\tint min = Math.min(r2, r1);\n\t\tint max = Math.max(r1, r2);\n\t\treturn (r1 < r2) && (d<max) && (min<= (max-d));\n\t}\n\tboolean circOut(double d, int r1, int r2)\n\t{\n\t\treturn d>=r1 && d>=r2 && (d-r1)>=r2;\n\t}\n\tvoid run() throws NumberFormatException, IOException\n\t{\n\t\tint x1 = nextInt(),y1 = nextInt(),r1 = nextInt(),R1 = nextInt();\n\t\tint x2 = nextInt(),y2 = nextInt(),r2 = nextInt(),R2 = nextInt();\n\t\tint ans = 0;\n\n\t\tdouble d = dist(x1,y1,x2,y2);\n\t\t//r1\n\t\tif(circInside(d,r1,r2)||circOut(d,r1,R2) || circInside(d,R2,r1)) \n\t\t\tans++;\n\t\t//r2\n\t\tif(circInside(d,r2,r1) || circOut(d,r2,R1) ||circInside(d,R1,r2)) \n\t\t\tans++;\n\t\t//R1\n\t\tif(circInside(d,R1,R2)||circInside(d,R1,r2)||circOut(d,R1,R2) || circInside(d,R2,r1))\n\t\t\tans++;\n\t\t//R2\n\t\tif(circInside(d,R2,R1) || circInside(d,R2,r1)||circOut(d,R1,R2) || circInside(d,R1,r2))\n\t\t\tans++;\n\t\tout.println(ans++);\n\t\t\n\t}\n\tpublic static void main(String[] args) throws NumberFormatException, IOException \n\t{\n\t\tnew B();\n\t}\n\tString nextToken() throws IOException\n\t{\n\t\tif(tok ==null || !tok.hasMoreTokens()) tok = new StringTokenizer(in.readLine());\n\t\treturn tok.nextToken();\n\t}\n\tint nextInt() throws NumberFormatException, IOException\n\t{\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\tlong nextLong() throws NumberFormatException, IOException\n\t{\n\t\treturn Long.parseLong(nextToken());\n\t}\n\tdouble nextDouble() throws NumberFormatException, IOException\n\t{\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}\n", "src_uid": "4c2865e4742a29460ca64860740b84f4"} {"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.*;\n\nimport static java.lang.Math.*;\nimport static java.util.Arrays.fill;\nimport static java.util.Arrays.sort;\n\npublic class Main {\n FastScanner in;\n PrintWriter out;\n\n class Pair {\n int s, d, c, id;\n\n Pair(int s, int d, int c, int id) {\n this.s = s;\n this.d = d;\n this.c = c;\n this.id = id;\n }\n }\n\n private void solve() throws IOException {\n int n = in.nextInt(), m = in.nextInt();\n PriorityQueue<Pair> q = new PriorityQueue<>(Comparator.comparingInt(o -> o.d));\n Pair[] p = new Pair[m];\n boolean[] block = new boolean[n + 1];\n for (int i = 0; i < m; i++) {\n p[i] = new Pair(in.nextInt(), in.nextInt(), in.nextInt(), i);\n block[p[i].d] = true;\n }\n shuffle(p);\n sort(p, Comparator.comparingInt(o -> o.s));\n int[] ans = new int[n];\n for (int i = 1, j = 0; i <= n; i++) {\n if (!q.isEmpty() && q.peek().d <= i && q.peek().c > 0) {\n out.print(-1);\n return;\n }\n while (j < m && p[j].s == i) {\n q.add(p[j++]);\n }\n\n if (!block[i]) {\n Pair c = q.peek() == null ? new Pair(0, 0, 0, -1) : q.remove();\n c.c--;\n if (c.c > 0)\n q.add(c);\n ans[i - 1] = c.id;\n } else\n ans[i - 1] = m;\n }\n for (int i : ans)\n out.print(i + 1 + \" \");\n }\n\n void shuffle(Pair[] a) {\n Pair b;\n Random r = new Random();\n for (int i = a.length - 1, j; i > 0; i--) {\n j = r.nextInt(i + 1);\n b = a[j];\n a[j] = a[i];\n a[i] = b;\n }\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().replace(',', '.'));\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\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 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}\n", "src_uid": "02d8d403eb60ae77756ff96f71b662d3"} {"source_code": "import java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\n\npublic class Main {\n\n\tstatic class Task {\n\t\t\n\t\tint NN = 200005;\n\t\tint MOD = 1000000007;\n\t\tint INF = 2000000000;\n\t\tlong INFINITY = 2000000000000000000L;\n\t\t\n\t\tlong cur;\n\t\tlong sumLike=0, sumHate=0;\n\t\tint n, m;\n\t\t\n\t\tlong [][][][] dp;\n\t\t\n\t\tlong expo(long x, long y) {\n\t\t\tlong ret = 1, sq =x;\n\t\t\twhile(y>0) {\n\t\t\t\tif(y%2!=0) {\n\t\t\t\t\tret = (ret * sq) % 998244353;\n\t\t\t\t}\n\t\t\t\tsq = (sq * sq) % 998244353;\n\t\t\t\ty >>= 1;\n\t\t\t}\n\t\t\treturn ret;\n\t\t}\n\t\t\n\t\tlong invMod(long p, long q) {\n\t\t\treturn (p * expo(q, 998244353 - 2))%998244353;\n\t\t}\n\t\t\n\t\tlong rec(int c1, int c2, int c, int flag) {\n\t\t\tint mul = flag==0?-1:1;\n\t\t\tif(dp[c1][c2][c][flag] != -1)\n\t\t\t\treturn dp[c1][c2][c][flag];\n\t\t\tif(c==m) {\n\t\t\t\treturn dp[c1][c2][c][flag] = cur + mul*c1;\n\t\t\t}\n\t\t\tlong p = (cur + mul*c1);\n\t\t\tlong q;\n\t\t\tif(mul == 1)\n\t\t\t\tq = (sumLike + c2 + sumHate - (c-c2));\n\t\t\telse\n\t\t\t\tq = (sumHate - c2 + sumLike + (c-c2));\n\t\t\tlong ret = (rec(c1+1, c2+1, c+1, flag)*invMod(p, q))%998244353;\n\t\t\tif(mul == 1)\n\t\t\t\tp = (sumLike + c2) - (cur + c1);\n\t\t\telse\n\t\t\t\tp = (sumHate - c2) - (cur - c1);\n\t\t\tret = (ret + rec(c1, c2+1, c+1, flag)*invMod(p, q))%998244353;\n\t\t\tif(mul == 1)\n\t\t\t\tp = (sumHate - (c-c2));\n\t\t\telse\n\t\t\t\tp = sumLike + (c-c2);\n\t\t\tret = (ret + rec(c1, c2, c+1, flag)*invMod(p, q))%998244353;\n\t\t\treturn dp[c1][c2][c][flag] = ret;\n\t\t}\n\t\t\n\t\tpublic void solve(InputReader in, PrintWriter out) {\n\t\t\tn = in.nextInt();\n\t\t\tm = in.nextInt();\n\t\t\tint [] a = new int[n];\n\t\t\tfor(int i=0;i<n;++i)\n\t\t\t\ta[i] = in.nextInt();\n\t\t\tint [] w = new int[n];\n\t\t\tfor(int i=0;i<n;++i) {\n\t\t\t\tw[i] = in.nextInt();\n\t\t\t\tif(a[i] == 0) {\n\t\t\t\t\tsumHate += w[i];\n\t\t\t\t} else {\n\t\t\t\t\tsumLike += w[i];\n\t\t\t\t}\n\t\t\t}\n\t\t\tdp = new long[m+1][m+1][m+1][2];\n\t\t\tfor(int i=0;i<n;++i) {\n\t\t\t\tcur=w[i];\n\t\t\t\tfor(int c1=0;c1<=m;++c1) {\n\t\t\t\t\tfor(int c2=0;c2<=m;++c2) {\n\t\t\t\t\t\tfor(int c=0;c<=m;++c) {\n\t\t\t\t\t\t\tdp[c1][c2][c][0] = dp[c1][c2][c][1] = -1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tout.println(rec(0, 0, 0, a[i]));\n\t\t\t}\n\t\t}\n\t\t\n\t}\n\t\n\tstatic void prepareIO(boolean isFileIO) {\n\t\t//long t1 = System.currentTimeMillis();\n\t\tTask solver = new Task();\n\t\t// Standard IO\n\t\tif(!isFileIO) { \n\t\t\tInputStream inputStream = System.in;\n\t OutputStream outputStream = System.out;\n\t InputReader in = new InputReader(inputStream);\n\t PrintWriter out = new PrintWriter(outputStream);\n\t solver.solve(in, out);\n\t //out.println(\"time(s): \" + (1.0*(System.currentTimeMillis()-t1))/1000.0);\n\t out.close();\n\t\t}\n // File IO\n\t\telse {\n\t\t\tString IPfilePath = System.getProperty(\"user.home\") + \"/Downloads/ip.in\";\n\t String OPfilePath = System.getProperty(\"user.home\") + \"/Downloads/op.out\";\n\t InputReader fin = new InputReader(IPfilePath);\n\t PrintWriter fout = null;\n\t try {\n\t\t\t\tfout = new PrintWriter(new File(OPfilePath));\n\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t solver.solve(fin, fout);\n\t //fout.println(\"time(s): \" + (1.0*(System.currentTimeMillis()-t1))/1000.0);\n\t fout.close();\n\t\t}\n\t}\n\t\n\tpublic static void main(String[] args) {\n prepareIO(false);\n\t}\n\t\n\tstatic 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 InputReader(String filePath) {\n \tFile file = new File(filePath);\n try {\n\t\t\t\treader = new BufferedReader(new FileReader(file));\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 tokenizer = null;\n }\n \n public String nextLine() {\n \tString str = \"\";\n \ttry {\n\t\t\t\tstr = reader.readLine();\n\t\t\t} catch (IOException e) {\n\t\t\t\t// TODO Auto-generated catch block\n\t\t\t\te.printStackTrace();\n\t\t\t}\n \treturn str;\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 \treturn Double.parseDouble(next());\n }\n \n }\n\n}", "src_uid": "ba9c136f84375cd317f0f8b53e3939c7"} {"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.InputMismatchException;\nimport java.io.InputStreamReader;\nimport java.io.BufferedOutputStream;\nimport java.util.StringTokenizer;\nimport java.io.Closeable;\nimport java.io.BufferedReader;\nimport java.io.InputStream;\nimport java.io.Flushable;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n\tstatic class TaskAdapter implements Runnable {\n\t\t@Override\n\t\tpublic void run() {\n\t\t\tInputStream inputStream = System.in;\n\t\t\tOutputStream outputStream = System.out;\n\t\t\tInput in = new Input(inputStream);\n\t\t\tOutput out = new Output(outputStream);\n\t\t\tBPerfectNumber solver = new BPerfectNumber();\n\t\t\tsolver.solve(1, in, out);\n\t\t\tout.close();\n\t\t}\n\t}\n\n\tpublic static void main(String[] args) throws Exception {\n\t\tThread thread = new Thread(null, new TaskAdapter(), \"\", 1<<29);\n\t\tthread.start();\n\t\tthread.join();\n\t}\n\tstatic class BPerfectNumber {\n\t\tpublic BPerfectNumber() {\n\t\t}\n\n\t\tpublic boolean perfect(int x) {\n\t\t\tString s = String.valueOf(x);\n\t\t\tint sum = 0;\n\t\t\tfor(int i = 0; i<s.length(); i++) {\n\t\t\t\tsum += s.charAt(i)-'0';\n\t\t\t}\n\t\t\treturn sum==10;\n\t\t}\n\n\t\tpublic void solve(int testNumber, Input in, Output pw) {\n\t\t\tint n = in.nextInt(), j = 0, i;\n\t\t\tfor(i = 1; j<n; i++) {\n\t\t\t\tif(perfect(i)) {\n\t\t\t\t\tj++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tpw.println(i-1);\n\t\t}\n\n\t}\n\n\tstatic class Output implements Closeable, Flushable {\n\t\tpublic StringBuilder sb;\n\t\tpublic OutputStream os;\n\t\tpublic int BUFFER_SIZE;\n\t\tpublic boolean autoFlush;\n\t\tpublic String LineSeparator;\n\n\t\tpublic Output(OutputStream os) {\n\t\t\tthis(os, 1<<16);\n\t\t}\n\n\t\tpublic Output(OutputStream os, int bs) {\n\t\t\tBUFFER_SIZE = bs;\n\t\t\tsb = new StringBuilder(BUFFER_SIZE);\n\t\t\tthis.os = new BufferedOutputStream(os, 1<<17);\n\t\t\tautoFlush = false;\n\t\t\tLineSeparator = System.lineSeparator();\n\t\t}\n\n\t\tpublic void println(int i) {\n\t\t\tprintln(String.valueOf(i));\n\t\t}\n\n\t\tpublic void println(String s) {\n\t\t\tsb.append(s);\n\t\t\tprintln();\n\t\t\tif(autoFlush||sb.length()>BUFFER_SIZE >> 1) {\n\t\t\t\tflush();\n\t\t\t}\n\t\t}\n\n\t\tpublic void println() {\n\t\t\tsb.append(LineSeparator);\n\t\t}\n\n\t\tpublic void flush() {\n\t\t\ttry {\n\t\t\t\tos.write(sb.toString().getBytes());\n\t\t\t}catch(IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\tsb = new StringBuilder(BUFFER_SIZE);\n\t\t}\n\n\t\tpublic void close() {\n\t\t\tflush();\n\t\t\ttry {\n\t\t\t\tos.close();\n\t\t\t}catch(IOException e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t}\n\n\t}\n\n\tstatic class Input {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tpublic Input(InputStream is) {\n\t\t\tthis(is, 1<<20);\n\t\t}\n\n\t\tpublic Input(InputStream is, int bs) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(is), bs);\n\t\t\tst = null;\n\t\t}\n\n\t\tpublic boolean hasNext() {\n\t\t\ttry {\n\t\t\t\twhile(st==null||!st.hasMoreTokens()) {\n\t\t\t\t\tString s = br.readLine();\n\t\t\t\t\tif(s==null) {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\tst = new StringTokenizer(s);\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t}catch(Exception e) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\tpublic String next() {\n\t\t\tif(!hasNext()) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\n\t}\n}\n\n", "src_uid": "0a98a6a15e553ce11cb468d3330fc86a"} {"source_code": "import java.util.Scanner;\n\n\npublic class CF476A {\n\tpublic static void main(String[] args){\n\t\tScanner in = new Scanner(System.in);\n\t\tint stairsToClimb = in.nextInt();\n\t\tint multiple = in.nextInt();\n\t\tin.nextLine();\n\t\tint maxPossibleSteps = stairsToClimb;\n\t\tint minPossibleSteps = (int) Math.ceil(stairsToClimb/2.0);\n\t\t//System.out.println(minPossibleSteps);\n\t\tint toPrint = -1;\n\t\t\n\t\tfor(int i = minPossibleSteps; i <= maxPossibleSteps; i++){\n\t\t\tif(i % multiple == 0){\n\t\t\t\ttoPrint = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(toPrint);\n\t}\n}\n", "src_uid": "0fa526ebc0b4fa3a5866c7c5b3a4656f"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\n\npublic class Forces_579_A {\n\tpublic static void main(String args[]) throws NumberFormatException, IOException\n\t{\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter pr = new PrintWriter(System.out);\n\t\tlong x=Long.parseLong(br.readLine());\n\t\tint c=1;\n\t\twhile(x!=1)\n\t\t{\n\t\t\tif(x%2==0) x=x/2;\n\t\t\telse\n\t\t\t{\n\t\t\t\tc++;\n\t\t\t\tx=x-1;\n\t\t\t}\n\t\t}\n\t\n\t\tpr.println(c);\n\t\tpr.close();\n\t}\n}\n", "src_uid": "03e4482d53a059134676f431be4c16d2"} {"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 D implements Runnable {\n\n\tprivate void Solution() throws IOException {\n\t\tlong n = nextLong(), m = nextLong(), k = nextLong();\n\t\tlong MOD = 1000000000 + 7, ans = 0;\n\t\tif (k > n) {\n\t\t\tans = 1;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tans *= m;\n\t\t\t\tans %= MOD;\n\t\t\t}\n\t\t} else if (k == n) {\n\t\t\tans = 1;\n\t\t\tfor (int i = 0; i < (n + 1) / 2; i++) {\n\t\t\t\tans *= m;\n\t\t\t\tans %= MOD;\n\t\t\t}\n\t\t} else if (k == 1) {\n\t\t\tans = 1;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tans *= m;\n\t\t\t\tans %= MOD;\n\t\t\t}\n\t\t} else if (k % 2 == 0) {\n\t\t\tans = m;\n\t\t} else {\n\t\t\tans = m * m;\n\t\t}\n\t\tprint(ans);\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tnew D().run();\n\t}\n\n\tBufferedReader in;\n\tPrintWriter out;\n\tStringTokenizer tokenizer;\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tSolution();\n\t\t\tout.close();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(0);\n\t\t}\n\t}\n\n\tvoid print(Object... o) {\n\t\tfor (int i = 0; i < o.length; i++) {\n\t\t\tif (i != 0)\n\t\t\t\tout.print(\" \");\n\t\t\tout.print(o[i]);\n\t\t}\n\t}\n\n\tvoid println(Object... o) {\n\t\tfor (int i = 0; i < o.length; i++) {\n\t\t\tif (i != 0)\n\t\t\t\tout.print(\" \");\n\t\t\tout.print(o[i]);\n\t\t}\n\t\tout.println();\n\t}\n\n\tint nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() throws NumberFormatException, IOException {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() throws NumberFormatException, IOException {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n\n\tString nextLine() throws IOException {\n\t\treturn in.readLine();\n\t}\n\n\tString nextToken() throws IOException {\n\t\twhile (tokenizer == null || !tokenizer.hasMoreTokens())\n\t\t\ttokenizer = new StringTokenizer(nextLine());\n\t\treturn tokenizer.nextToken();\n\t}\n}\n", "src_uid": "1f9107e8d1d8aebb1f4a1707a6cdeb6d"} {"source_code": "import java.io.*;\nimport java.util.*;\nimport java.lang.*;\nimport java.util.HashMap;\n public class templ {\n int binarySearch(int arr[], int l, int r, int x)\n {\n if (r >= l)\n {\n int mid = l + (r - l)/2;\n if (arr[mid] == x)\n return mid;\n if (arr[mid] > x) \n return binarySearch(arr, l, mid-1, x);\n return binarySearch(arr, mid+1, r, x);\n }\n return -1;\n }\n void merge1(int arr[], int l, int m, int r)\n {\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<n1; ++i)\n L[i] = arr[l + i];\n for (int j=0; j<n2; ++j)\n R[j] = arr[m + 1+ j];\n int i = 0, j = 0;\n int k = l;\n while (i < n1 && j < n2)\n {\n if (L[i] <= R[j])\n {\n arr[k] = L[i];\n i++;\n }\n else\n {\n arr[k] = R[j];\n j++;\n }\n k++;\n }\n while (i < n1)\n {\n arr[k] = L[i];\n i++;\n k++;\n }\n while (j < n2)\n {\n arr[k] = R[j];\n j++;\n k++;\n }\n }\n void sort1(int arr[], int l, int r)\n {\n if (l < r)\n {\n int m = (l+r)/2;\n sort1(arr, l, m);\n sort1(arr , m+1, r);\n merge1(arr, l, m, r);\n }\n }\n void merge3(int arr[],int arr1[],int arr2[], int l, int m, int r)\n {\n int n1 = m - l + 1;\n int n2 = r - m;\n int L[] = new int [n1];\n int R[] = new int [n2];\n int L1[]=new int[n1];\n int R1[]=new int[n2];\n int L2[]=new int[n1];\n int R2[]=new int[n2];\n //long L3[]=new long[n1];\n //long R3[]=new long[n2];\n for (int i=0; i<n1; ++i)\n {\n L[i] = arr[l + i];\n L1[i]=arr1[l+i];\n L2[i]=arr2[l+i];\n //L3[i]=arr3[l+i];\n }\n for (int j=0; j<n2; ++j)\n {\n R[j] = arr[m + 1+ j];\n R1[j]=arr1[m+1+j];\n R2[j]=arr2[m+1+j];\n //R3[j]=arr3[m+1+j];\n }\n int i = 0, j = 0;\n int k = l;\n while (i < n1 && j < n2)\n {\n if (L[i] <= R[j])\n {\n arr[k] = L[i];\n arr1[k]=L1[i];\n arr2[k]=L2[i];\n //arr3[k]=L3[i];\n i++;\n }\n else\n {\n arr[k] = R[j];\n arr1[k]=R1[j];\n arr2[k]=R2[j];\n //arr3[k]=R3[j];\n j++;\n }\n k++;\n }\n while (i < n1)\n {\n arr[k] = L[i];\n arr1[k]=L1[i];\n arr2[k]=L2[i];\n //arr3[k]=L3[i];\n i++;\n k++;\n }\n while (j < n2)\n {\n arr[k] = R[j];\n arr1[k]=R1[j];\n arr2[k]=R2[j];\n //arr3[k]=R3[j];\n j++;\n k++;\n }\n }\n void sort3(int arr[],int arr1[],int arr2[], int l, int r)\n {\n if (l < r)\n {\n int m = (l+r)/2;\n sort3(arr,arr1,arr2, l, m);\n sort3(arr ,arr1,arr2, m+1, r);\n merge3(arr,arr1,arr2,l, m, r);\n }\n }\n void merge2(int arr[],int arr1[],int l, int m, int r)\n {\n int n1 = m - l + 1;\n int n2 = r - m;\n int L[] = new int [n1];\n int R[] = new int [n2];\n int L1[]=new int[n1];\n int R1[]=new int[n2];\n for (int i=0; i<n1; ++i)\n {\n L[i] = arr[l + i];\n L1[i]=arr1[l+i];\n }\n for (int j=0; j<n2; ++j)\n {\n R[j] = arr[m + 1+ j];\n R1[j]=arr1[m+1+j];\n }\n int i = 0, j = 0;\n int k = l;\n while (i < n1 && j < n2)\n {\n if (L[i] <= R[j])\n {\n arr[k] = L[i];\n arr1[k]=L1[i];\n i++;\n }\n else\n {\n arr[k] = R[j];\n arr1[k]=R1[j];\n j++;\n }\n k++;\n }\n while (i < n1)\n {\n arr[k] = L[i];\n arr1[k]=L1[i];\n i++;\n k++;\n }\n while (j < n2)\n {\n arr[k] = R[j];\n arr1[k]=R1[j];\n j++;\n k++;\n }\n }\n void sort2(int arr[],int arr1[],int l, int r)\n {\n if (l < r)\n {\n int m = (l+r)/2;\n sort2(arr,arr1, l, m);\n sort2(arr ,arr1, m+1, r);\n merge2(arr,arr1,l, m, r);\n }\n }\n public static void main(String[] args) throws FileNotFoundException {\n try\n {\n InputReader in = new InputReader(System.in);\n PrintWriter out = new PrintWriter(System.out);\n templ ob=new templ();\n long a=in.nextLong();\n long b=in.nextLong();\n int m[]=new int[20];\n int o=0;\n int n[]=new int[20];\n int oo=0;\n long c=a;\n while(c!=0)\n {\n int d=(int)(c%10);\n m[o]=d;\n o++;\n c=c/10;\n }\n ob.sort1(m,0,o-1);\n long d=b;\n while(d!=0)\n {\n int k=(int)(d%10);\n n[oo]=k;\n oo++;\n d=d/10;\n }\n for(int i=0;i<oo/2;i++)\n {\n int temp=n[i];\n n[i]=n[oo-1-i];\n n[oo-1-i]=temp;\n }\n if(oo>o)\n {\n for(int i=o-1;i>=0;i--)\n out.print(m[i]);\n }\n else\n {\n int dest[]=new int[20];\n int p=0;\n int vis[]=new int[o];\n for(int i=0;i<oo;i++)\n {\n int x=n[i];\n int prev=-1;\n int j1=-1;\n for(int j=0;j<o;j++)\n {\n int y=m[j];\n if(y>x)\n break;\n else if(y<=x&&vis[j]==0)\n {\n prev=y;\n j1=j;\n }\n }\n if(prev!=-1)\n {\n dest[p]=prev;\n p++;\n vis[j1]=1;\n if(prev<x)\n {\n for(int l=o-1;l>=0;l--)\n {\n if(vis[l]==0)\n {\n dest[p]=m[l];\n p++;\n vis[l]=1;\n }\n }\n break;\n }\n }\n else\n {\n int max=-1;\n int jj=-1;\n for(int l=p-1;l>=0;l--)\n {\n //for(int ll=0;ll<o;ll++)\n //out.println(m[ll]+\" \"+vis[ll]);\n for(int ll=0;ll<o;ll++)\n {\n if(vis[ll]==0&&m[ll]<dest[l]&&m[ll]>max)\n {\n max=m[ll];\n jj=ll;\n }\n }\n if(max!=-1)\n {\n vis[jj]=1;\n int kk=dest[l];\n dest[l]=max;\n for(int ll=0;ll<o;ll++)\n {\n if(vis[ll]==1&&m[ll]==kk)\n {\n vis[ll]=0;\n break;\n }\n }\n break;\n }\n else\n {\n int kk=dest[l];\n //out.println(kk);\n p--;\n for(int ll=0;ll<o;ll++)\n {\n if(vis[ll]==1&&m[ll]==kk)\n {\n vis[ll]=0;\n break;\n }\n }\n }\n }\n for(int l=o-1;l>=0;l--)\n {\n if(vis[l]==0)\n {\n dest[p]=m[l];\n p++;\n vis[l]=1;\n }\n }\n break;\n } \n }\n for(int i=0;i<p;i++)\n out.print(dest[i]);\n }\n out.close();\n }\n catch(Exception e){\n return;\n }\n }\n static class InputReader {\n\n private final InputStream stream;\n private final byte[] buf = new byte[8192];\n private int curChar, snumChars;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (snumChars == -1)\n throw new InputMismatchException();\n if (curChar >= snumChars) {\n curChar = 0;\n try {\n snumChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (snumChars <= 0)\n return -1;\n }\n return buf[curChar++];\n }\n\n public int nextInt() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n int res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public long nextLong() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public int[] nextIntArray(int n) {\n int a[] = new int[n];\n for (int i = 0; i < n; i++) {\n a[i] = nextInt();\n }\n return a;\n }\n\n public String readString() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\n }\n\n public String nextLine() {\n int c = read();\n while (isSpaceChar(c))\n c = read();\n StringBuilder res = new StringBuilder();\n do {\n res.appendCodePoint(c);\n c = read();\n } while (!isEndOfLine(c));\n return res.toString();\n }\n\n public boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n private boolean isEndOfLine(int c) {\n return c == '\\n' || c == '\\r' || c == -1;\n }\n\n }\n} \t", "src_uid": "bc31a1d4a02a0011eb9f5c754501cd44"} {"source_code": "import java.util.*;\nimport java.util.LinkedList;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.math.BigInteger;\n\npublic class tmp {\n public static void main(String [] args) throws Exception{\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n StringTokenizer st = new StringTokenizer(in.readLine());\n StringBuilder sb = new StringBuilder();\n \n int n = Integer.parseInt(st.nextToken());\n int a = Integer.parseInt(st.nextToken());\n int [] arr = new int[n+1];\n st = new StringTokenizer(in.readLine());\n \n for(int i=1; i<=n; i++){\n arr[i] = Integer.parseInt(st.nextToken());\n }\n int out = 0;\n if(a <= n/2){\n for(int i=1; i<a; i++){\n if(arr[i] + arr[2*a-i] == 2)\n out+=2;\n }\n out += arr[a];\n for(int i=2*a; i<=n; i++){\n out += arr[i];\n }\n }else{\n for(int i=n; i>a; i--){\n if(arr[i] + arr[2*a-i] == 2)\n out+=2;\n }\n out += arr[a];\n for(int i=1; i<2*a-n; i++){\n out += arr[i];\n }\n }\n \n \n System.out.println(out);\n \n \n \n \n \n \n \n \n \n \n \n }\n \n \n \n \n \n \n \n \n \n \n \n\n\n \n \n \n \n}\n\n \nclass P implements Comparable<P>{\n int val, idx;\n public P(int val, int idx){\n this.val = val;\n this.idx = idx;\n }\n\n public int compareTo(P other){\n if (this.val != other.val) return -this.val + other.val;\n return this.idx - other.idx;\n }\n}", "src_uid": "4840d571d4ce6e1096bb678b6c100ae5"} {"source_code": "import java.util.*;\nimport java.io.*;\npublic final class Main {\n static long pow(long n, long x, long mod) {\n long res = 1;\n while(x>0) {\n if(x%2==1)\n res = (res*n)%mod;\n x>>=1;\n n = (n*n)%mod;\n }\n return res;\n }\n public static void main (String[] args) {\n Scanner sc = new Scanner(System.in);\n long n = sc.nextLong();\n long m = sc.nextLong();\n long ans = pow(3, n, m) - 1;\n if(ans<0)\n ans+=m;\n System.out.println(ans);\n }\n}", "src_uid": "c62ad7c7d1ea7aec058d99223c57d33c"} {"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 qq\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 public int check(int n, Integer x, int len) {\n int ans = 0;\n while (n > 0 && x > 0) {\n if (n % 10 == x % 10) {\n ans++;\n x /= 10;\n }\n\n n /= 10;\n }\n\n\n if (x == 0) return len - ans;\n else return 100;\n\n }\n\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n Integer n = in.nextInt();\n int len = n.toString().length();\n int ans = 100;\n for (int i = 1; i * i <= n; i++) {\n ans = Math.min(check(n, i * i, len), ans);\n }\n\n if (ans != 100) out.println(ans);\n else out.println(-1);\n }\n\n }\n}\n\n", "src_uid": "fa4b1de79708329bb85437e1413e13df"} {"source_code": "import java.util.*;\nimport java.io.*;\n\npublic class Main {\n public static void main(String[] args) throws IOException {\n //Code starts\n\n FastReader ip = new FastReader();\n OutputStream output = System.out;\n PrintWriter out = new PrintWriter(output);\n String s=ip.nextLine();\n int arr[]=new int[6];\n int sum1=0;\n int sum2=0;\n for(int i=0;i<6;i++){\n arr[i]=s.charAt(i)-'0';\n if(i<3){\n sum1+=arr[i];\n }else{\n sum2+=arr[i];\n }\n }\n\n\n if(sum1==sum2){\n out.println(0);\n }else {\n int m1 = 0, m2 = 0, m3 = 0, M1 = 0, M2 = 0, M3 = 0;\n int diff=0;\n if (sum2 > sum1) {\n diff=sum2-sum1;\n m1 = Math.min(arr[0], Math.min(arr[1], arr[2]));\n m3 = Math.max(arr[0], Math.max(arr[1], arr[2]));\n m2 = (sum1 - m1) - m3;\n M1 = Math.min(arr[3], Math.min(arr[4], arr[5]));\n M3 = Math.max(arr[3], Math.max(arr[4], arr[5]));\n M2 = (sum2 - M1) - M3;\n } else {\n diff=sum1-sum2;\n m1 = Math.min(arr[3], Math.min(arr[4], arr[5]));\n m3 = Math.max(arr[3], Math.max(arr[4], arr[5]));\n m2 = (sum2 - m1) - m3;\n M1 = Math.min(arr[0], Math.min(arr[1], arr[2]));\n M3 = Math.max(arr[0], Math.max(arr[1], arr[2]));\n M2 = (sum1 - M1) - M3;\n }\n int c = 0;\n if (M3 > (9 - m1)) {\n if (diff > M3) {\n diff -= M3;\n c++;\n if (M2 > (9 - m1)) {\n if (diff > M2) {\n c++;\n }\n } else {\n if (diff > (9 - m1)) {\n c++;\n }\n }\n }\n } else {\n if (diff > (9 - m1)) {\n diff -= (9 - m1);\n c++;\n if (M3 > (9 - m2)) {\n if (diff > M3) {\n c++;\n }\n } else {\n if (diff > (9 - m2)) {\n c++;\n }\n }\n }\n\n }\n\n out.println(c+1);\n }\n out.close();\n //Code ends\n }\n\n static class FastReader {\n BufferedReader br;\n StringTokenizer st;\n FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); }\n String next() { while (st == null || !st.hasMoreElements()) {\n try { st = new StringTokenizer(br.readLine()); }\n catch (IOException e) { e.printStackTrace(); } }\n return st.nextToken();\n }\n\n int nextInt() { return Integer.parseInt(next()); }\n long nextLong() { return Long.parseLong(next()); }\n double nextDouble() { return Double.parseDouble(next()); }\n\n String nextLine() {\n String str = \"\";\n try { str = br.readLine(); }\n catch (IOException e) { e.printStackTrace(); }\n return str;\n }\n }\n\n}", "src_uid": "09601fd1742ffdc9f822950f1d3e8494"} {"source_code": "\npublic class RosettaProblem {\n\tpublic static void main(String[] args) {\n\t\tString s = Integer.toString(Integer.parseInt(new java.util.Scanner(System.in).nextLine()), 8);\n\t\tint res = 0;\n\t\tfor(int i = 0 ; i < s.length() ; i++)\n\t\t\tres+=s.charAt(i) == '1'?1:0;\n\t\tSystem.out.println(res);\n\t}\n}\n", "src_uid": "ec539775f2b3358a92a99a644e2480ce"} {"source_code": "import java.io.*;\nimport java.util.*;\nimport static java.lang.Math.*;\n\npublic class santaandcandies2\n{\n\tstatic int[] arr;\n\tstatic int inser_p;\n\tstatic int n;\n\tpublic static void main(String[] args)throws IOException {\n\t\tInputReader ir=new InputReader(System.in);\n\t\tOutputWriter ow=new OutputWriter(System.out);\n\t\tprecompute();\n\t\tinser_p=((inser_p=Arrays.binarySearch(arr,n=ir.readInt()))<0?(abs(inser_p)-2):inser_p);\n\t\tow.printLine(inser_p);\n\t\tint i=1;\n\t\tfor(;i<inser_p;++i)\n\t\t\tow.print(i+\" \");\n\t\tow.printLine(i+(n-arr[inser_p])); \n\t\tow.flush();\n\t\tow.close();\n\t}\n\tstatic void precompute()\n\t{\n\t\tint mul=0,n=1;\n\t\tarr=new int[45];\n while((mul=(n*(n+1)/2))<=1000)\n \t arr[n++]=mul;\n\t}\n\t static class InputReader { \n \tprivate InputStream stream;\n \tprivate byte[] buf = new byte[1024];\n \tprivate int curChar;\n \tprivate int numChars;\n \tprivate SpaceCharFilter filter;\n \n \tpublic InputReader(InputStream stream) {\n \t\tthis.stream = stream;\n \t\t} \n \tpublic int read() {\n \t\tif (numChars == -1)\n \t\t throw new InputMismatchException();\n \t\tif (curChar >= numChars) {\n \t\t\tcurChar = 0;\n \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\tif (numChars <= 0)\n \t\t\treturn -1;\n \t\t\t}\n \t\t\treturn buf[curChar++];\n \t\t} \n \tpublic int readInt() {\n \t int c = read();\n \t\twhile (isSpaceChar(c))\n \t\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}\n \t\t\tint res = 0;\n \t\t\tdo {\n \t\t\t\tif (c < '0' || c > '9')\n \t\t\t\t\tthrow new InputMismatchException();\n \t\t\t\tres *= 10;\n \t\t\t\tres += c - '0';\n \t\t\t\tc = read();\n \t\t\t} while (!isSpaceChar(c));\n \t\t\treturn res * sgn;\n \t\t} \n \t\tpublic String readString() {\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\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 \t\tpublic String next() {\n \t\t\treturn readString();\n \t\t} \n \t\tpublic interface SpaceCharFilter {\n \t\t\tpublic boolean isSpaceChar(int ch);\n \t\t}\n \t} \n static class OutputWriter {\n \t\tprivate final PrintWriter writer; \n \t\tpublic OutputWriter(OutputStream outputStream) {\n \t\t\twriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n \t\t} \n \t\tpublic OutputWriter(Writer writer) {\n \t\t\tthis.writer = new PrintWriter(writer);\n \t\t} \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 \t\tpublic void printLine(Object...objects) {\n \t\t\tprint(objects);\n \t\t\twriter.println();\n \t\t} \n \t\tpublic void close() {\n \t\t\twriter.close();\n \t\t} \n \t\tpublic void flush() {\n \t\t\twriter.flush();\n \t\t} \n \t\t} \n}", "src_uid": "356a7bcebbbd354c268cddbb5454d5fc"} {"source_code": "\n\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Scanner;\n\n\n\npublic class Q3E {\n\n \npublic static int gcd (int a,int b)\n{\n if (b==0)\n return a;\n return gcd(b,a%b);\n}\n public static void main(String[] args) throws FileNotFoundException \n {\n Scanner in = new Scanner(System.in);\n \n \n int n = in.nextInt();\n \n int count = 0;\n \n for (int i = 1; i < n; i++) {\n \n int commondivisor = gcd(n-1, i);\n if (commondivisor == 1)\n count ++;\n }\n System.out.println(count);\n }\n}", "src_uid": "3bed682b6813f1ddb54410218c233cff"} {"source_code": "import java.util.Scanner;\n\n/**\n * Created by PQZR3864 on 2018-10-04.\n */\npublic class PhoneNumber {\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n int count = 0;\n int n = input.nextInt();\n String digits = input.next();\n\n for(int i=0 ; i<digits.length() ;i++){\n if(digits.charAt(i) == '8') count++;\n }\n count = count > (n/11) ? (n/11) : count ;\n System.out.println(count);\n input.close();\n }\n}\n", "src_uid": "259d01b81bef5536b969247ff2c2d776"} {"source_code": "import java.math.BigInteger;\nimport java.util.*;\n\npublic class Main {\n static final int MOD = 1000000007;\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 totalRes = 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 newlC;\n if (newlD == 0)\n newlC = lC;\n else if (lD == 0)\n newlC = lC - 1;\n else\n newlC = lC;\n if (newfC > newlC)\n continue;\n int[] arr = newRes[newfD][newlD][newfC];\n arr[newlC] += cur;\n if (arr[newlC] >= MOD) arr[newlC] -= 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 lastDelta = lD == 0 ? 1 : -1;\n int lastMin = lastDelta == 1 ? 0 : width - 1;\n int lastMax = lastDelta == 1 ? width : -1;\n for (int lC = lastMin; lC != lastMax; lC += lastDelta) {\n for (int fC = 0; fC <= lC; ++fC) {\n int cur = arr[fC][lC];\n if (cur == 0) continue;\n int newlC = lC + lastDelta;\n if (newlC >= fC && newlC < width) {\n arr[fC][newlC] += cur;\n if (arr[fC][newlC] >= MOD) arr[fC][newlC] -= MOD;\n }\n }\n }\n }\n {\n int firstDelta = fD == 0 ? -1 : 1;\n int firstMin = firstDelta == 1 ? 0 : width - 1;\n int firstMax = firstDelta == 1 ? width : -1;\n for (int fC = firstMin; fC != firstMax; fC += firstDelta) {\n for (int lC = fC; lC < width; ++lC) {\n int cur = arr[fC][lC];\n if (cur == 0) continue;\n int newfC = fC + firstDelta;\n if (newfC >= 0 && newfC <= lC) {\n arr[newfC][lC] += cur;\n if (arr[newfC][lC] >= MOD) arr[newfC][lC] -= MOD;\n }\n }\n }\n }\n } else {\n {\n int firstDelta = fD == 0 ? -1 : 1;\n int firstMin = firstDelta == 1 ? 0 : width - 1;\n int firstMax = firstDelta == 1 ? width : -1;\n for (int fC = firstMin; fC != firstMax; fC += firstDelta) {\n for (int lC = fC; lC < width; ++lC) {\n int cur = arr[fC][lC];\n if (cur == 0) continue;\n int newfC = fC + firstDelta;\n if (newfC >= 0 && newfC <= lC) {\n arr[newfC][lC] += cur;\n if (arr[newfC][lC] >= MOD) arr[newfC][lC] -= MOD;\n }\n }\n }\n }\n {\n int lastDelta = lD == 0 ? 1 : -1;\n int lastMin = lastDelta == 1 ? 0 : width - 1;\n int lastMax = lastDelta == 1 ? width : -1;\n for (int lC = lastMin; lC != lastMax; lC += lastDelta) {\n for (int fC = 0; fC <= lC; ++fC) {\n int cur = arr[fC][lC];\n if (cur == 0) continue;\n int newlC = lC + lastDelta;\n if (newlC >= fC && newlC < width) {\n arr[fC][newlC] += cur;\n if (arr[fC][newlC] >= MOD) arr[fC][newlC] -= 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 totalRes += res[fD][lD][fC][lC];\n if (totalRes >= MOD) totalRes -= MOD;\n }\n }\n return totalRes;\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", "src_uid": "740eceed59d3c6ac55c1bf9d3d4160c7"} {"source_code": "import java.util.Scanner;\n\n\npublic class Main {\n\t\n\tpublic static void main(String[] args){\n\t\tString[] table = {\"\",\n\t\t\t\t\"Washington\",\n\t\t\t\t\"Adams\",\n\t\t\t\t\"Jefferson\",\n\t\t\t\t\"Madison\",\n\t\t\t\t\"Monroe\",\n\t\t\t\t\"Adams\",\n\t\t\t\t\"Jackson\",\n\t\t\t\t\"Van Buren\",\n\t\t\t\t\"Harrison\",\n\t\t\t\t\"Tyler\",\n\t\t\t\t\"Polk\",\n\t\t\t\t\"Taylor\",\n\t\t\t\t\"Fillmore\",\n\t\t\t\t\"Pierce\",\n\t\t\t\t\"Buchanan\",\n\t\t\t\t\"Lincoln\",\n\t\t\t\t\"Johnson\",\n\t\t\t\t\"Grant\",\n\t\t\t\t\"Hayes\",\n\t\t\t\t\"Garfield\",\n\t\t\t\t\"Arthur\",\n\t\t\t\t\"Cleveland\",\n\t\t\t\t\"Harrison\",\n\t\t\t\t\"Cleveland\",\n\t\t\t\t\"McKinley\",\n\t\t\t\t\"Roosevelt\",\n\t\t\t\t\"Taft\",\n\t\t\t\t\"Wilson\",\n\t\t\t\t\"Harding\",\n\t\t\t\t\"Coolidge\",\n\t\t\t\t\"Hoover\",\n\t\t\t\t\"Roosevelt\",\n\t\t\t\t\"Truman\",\n\t\t\t\t\"Eisenhower\",\n\t\t\t\t\"Kennedy\",\n\t\t\t\t\"Johnson\",\n\t\t\t\t\"Nixon\",\n\t\t\t\t\"Ford\",\n\t\t\t\t\"Carter\",\n\t\t\t\t\"Reagan\",\n\t\t\t\t\"111111101101000101001101110010001\",\n\t\t\t\t\"111111101101000101001101110010001\"};\n\t\t\n\t\tScanner in = new Scanner(System.in);\t\n\t\tint x;\n\t\tx = in.nextInt();\n\t\t\n\t\tSystem.out.println(table[x]);\n\t\t\n\t\t\n\t}\n\n}\n", "src_uid": "0b51a8318c9ec0c80c0f4dc04fe0bfb3"} {"source_code": " import java.util.Scanner;\n import java.util.Vector;\n\n public class A_VanyaAndCubes {\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n int cubes = input.nextInt();\n /*\n int [] arr = new int [cubes+1];\n\n arr[0] = 1 ;\n\n for(int i = 1 ; i < cubes ; i++)\n for(int j = 1 ; j <= i+1 ;j++)\n arr[i] += j;\n\n int total = 0,count = 0 ;\n while (cubes > total)\n total += arr[count++];\n System.out.print(total == count? count :count-1);\n */\n int x = 0 ;\n int total = 0 ;\n int count = 0 ;\n for(int i = 1 ; i <= cubes ; i++){\n x += i;\n total += x;\n if(total > cubes)\n break;\n count++;\n }\n System.out.print(count);\n }\n }\n", "src_uid": "873a12edffc57a127fdfb1c65d43bdb0"} {"source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\n\npublic class Main {\n\n\tstatic int mod = (int) 1e9 + 7;\n\tstatic int MAX = (int) 1e7;\n\n\tpublic static void main(String[] args) {\n\t\tFasterScanner s = new FasterScanner();\n\t\tPrintWriter out = new PrintWriter(System.out);\n\t\tint t = 1;\n\t\tloop: while (t-- > 0) {\n\t\t\tint n = s.nextInt();\n\t\t\tint[] a = s.nextIntArray(n);\n\t\t\tint[] c = new int[1001];\n\t\t\tfor(int i=0;i<n;i++){\n\t\t\t\tc[a[i]]++;\n\t\t\t}\n\t\t\tfor(int i=0;i<1001-2;i++){\n\t\t\t\tif(c[i]>0 && c[i+1]>0 && c[i+2]>0){\n\t\t\t\t\tout.println(\"YES\");\n\t\t\t\t\tcontinue loop;\n\t\t\t\t}\n\t\t\t}\n\t\t\tout.println(\"NO\");\n\t\t}\n\t\tout.close();\n\t}\n\n\tstatic void dfs1(List<Integer>[] graph, boolean[] used, List<Integer> order, int u) {\n\t\tused[u] = true;\n\t\tfor (int v : graph[u])\n\t\t\tif (!used[v])\n\t\t\t\tdfs1(graph, used, order, v);\n\t\torder.add(u);\n\t}\n\n\tstatic void dfs2(List<Integer>[] reverseGraph, int[] comp, int u, int color) {\n\t\tcomp[u] = color;\n\t\tfor (int v : reverseGraph[u])\n\t\t\tif (comp[v] == -1)\n\t\t\t\tdfs2(reverseGraph, comp, v, color);\n\t}\n\n\tpublic static boolean[] solve2Sat(List<Integer>[] graph) {\n\t\tint n = graph.length;\n\t\tboolean[] used = new boolean[n];\n\t\tList<Integer> order = new ArrayList<>();\n\t\tfor (int i = 0; i < n; ++i)\n\t\t\tif (!used[i])\n\t\t\t\tdfs1(graph, used, order, i);\n\n\t\tList<Integer>[] reverseGraph = new List[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\treverseGraph[i] = new ArrayList<>();\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tfor (int j : graph[i])\n\t\t\t\treverseGraph[j].add(i);\n\n\t\tint[] comp = new int[n];\n\t\tArrays.fill(comp, -1);\n\t\tfor (int i = 0, color = 0; i < n; ++i) {\n\t\t\tint u = order.get(n - i - 1);\n\t\t\tif (comp[u] == -1)\n\t\t\t\tdfs2(reverseGraph, comp, u, color++);\n\t\t}\n\n\t\tfor (int i = 0; i < n; ++i)\n\t\t\tif (comp[i] == comp[i ^ 1])\n\t\t\t\treturn null;\n\n\t\tboolean[] res = new boolean[n / 2];\n\t\tfor (int i = 0; i < n; i += 2)\n\t\t\tres[i / 2] = comp[i] > comp[i ^ 1];\n\t\treturn res;\n\t}\n\n\tpublic static int[] createSets(int size) {\n\t\tint[] p = new int[size];\n\t\tfor (int i = 0; i < size; i++)\n\t\t\tp[i] = i;\n\t\treturn p;\n\t}\n\n\tpublic static int root(int[] p, int x) {\n\t\treturn x == p[x] ? x : (p[x] = root(p, p[x]));\n\t}\n\n\tpublic static void unite(int[] p, int a, int b) {\n\t\ta = root(p, a);\n\t\tb = root(p, b);\n\t\tif (a != b)\n\t\t\tp[a] = b;\n\t}\n\n\tpublic static boolean nextPermutation(int[] p) {\n\t\tfor (int a = p.length - 2; a >= 0; --a)\n\t\t\tif (p[a] < p[a + 1])\n\t\t\t\tfor (int b = p.length - 1;; --b)\n\t\t\t\t\tif (p[b] > p[a]) {\n\t\t\t\t\t\tint t = p[a];\n\t\t\t\t\t\tp[a] = p[b];\n\t\t\t\t\t\tp[b] = t;\n\t\t\t\t\t\tfor (++a, b = p.length - 1; a < b; ++a, --b) {\n\t\t\t\t\t\t\tt = p[a];\n\t\t\t\t\t\t\tp[a] = p[b];\n\t\t\t\t\t\t\tp[b] = t;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\treturn false;\n\t}\n\n\tpublic static boolean isPrime(long n) {\n\t\tif (n <= 1)\n\t\t\treturn false;\n\t\tfor (long i = 2; i * i <= n; i++)\n\t\t\tif (n % i == 0)\n\t\t\t\treturn false;\n\t\treturn true;\n\t}\n\n\tstatic class SegTree {\n\t\tint[] val;\n\t\tint n;\n\n\t\tSegTree(int n) {\n\t\t\tval = new int[2 * n];\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tval[n + i] = i + 1;\n\t\t\tfor (int i = n - 1; i >= 0; i--)\n\t\t\t\tval[i] = Math.max(val[2 * i], val[2 * i + 1]);\n\t\t\tthis.n = n;\n\t\t}\n\n\t\tvoid upd(int p) {\n\t\t\tp += n;\n\t\t\tval[p] = -1;\n\t\t\tfor (; (p >>= 1) != 0;) {\n\t\t\t\tval[p] = Math.max(val[2 * p], val[2 * p + 1]);\n\t\t\t}\n\t\t}\n\n\t\tint query(int l, int r) { // sum on interval [l, r)\n\t\t\t// System.out.println(l+\" \"+r);\n\t\t\tint res = -1;\n\t\t\tfor (l += n, r += n; l < r; l >>= 1, r >>= 1) {\n\t\t\t\tif ((l & 1) != 0)\n\t\t\t\t\tres = Math.max(res, val[l++]);\n\t\t\t\tif ((r & 1) != 0)\n\t\t\t\t\tres = Math.max(res, val[--r]);\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\t}\n\n\tstatic boolean check(int i, int j, int n) {\n\t\tif (i >= 0 && j >= 0 && i < n && j < n)\n\t\t\treturn true;\n\t\treturn false;\n\t}\n\n\tpublic static int[] generateDivisorTable(int n) {\n\t\tint[] divisor = new int[n + 1];\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\tdivisor[i] = i;\n\t\tfor (int i = 2; i * i <= n; i++)\n\t\t\tif (divisor[i] == i)\n\t\t\t\tfor (int j = i * i; j <= n; j += i)\n\t\t\t\t\tdivisor[j] = i;\n\t\treturn divisor;\n\t}\n\n\tpublic static int[][] matrixMul(int[][] a, int[][] b) {\n\t\tint n = a.length;\n\t\tint m = a[0].length;\n\t\tint k = b[0].length;\n\t\tint[][] res = new int[n][k];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < k; j++) {\n\t\t\t\tfor (int p = 0; p < m; p++) {\n\t\t\t\t\tres[i][j] = (res[i][j] + (int) ((a[i][p] * 1l * b[p][j]) % mod)) % mod;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n\n\tpublic static int[][] matrixPow(int[][] a, int p) {\n\t\tif (p == 0) {\n\t\t\treturn matrixUnit(a.length);\n\t\t} else if (p % 2 == 0) {\n\t\t\treturn matrixPow(matrixMul(a, a), p / 2);\n\t\t} else {\n\t\t\treturn matrixMul(a, matrixPow(a, p - 1));\n\t\t}\n\t}\n\n\tpublic static int[][] matrixUnit(int n) {\n\t\tint[][] res = new int[n][n];\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\tres[i][i] = 1;\n\t\t}\n\t\treturn res;\n\t}\n\n\tstatic int[] modInv(int n, int mod) {\n\t\tint[] ans = new int[n];\n\t\tfor (int i = 1; i < n; i++)\n\t\t\tans[i] = (int) pow(i, mod - 2, mod);\n\t\treturn ans;\n\t}\n\n\tstatic int[] primes;\n\n\tpublic static long ncr(int n, int r) {\n\t\tif (n < r)\n\t\t\treturn 0;\n\t\tif (n == r)\n\t\t\treturn 1;\n\t\tif (r == 0)\n\t\t\treturn 1;\n\t\tif (r < 0)\n\t\t\treturn 0;\n\t\tlong ans = 1;\n\t\tfor (int i = 0; i < primes.length; i++) {\n\t\t\tlong power = count(n, primes[i]) - count(n - r, primes[i]) - count(r, primes[i]);\n\t\t\tans *= pow(primes[i], power, mod);\n\t\t\tans %= mod;\n\t\t}\n\t\treturn ans;\n\t}\n\n\tpublic static long pow(long x, long n, int mod) {\n\t\tlong res = 1;\n\t\tfor (long p = x; n > 0; n >>= 1, p = (p * p) % mod) {\n\t\t\tif ((n & 1) != 0) {\n\t\t\t\tres = (int) (res * p % mod);\n\t\t\t}\n\t\t}\n\t\treturn res;\n\t}\n\n\tpublic static long count(int n, int p) {\n\t\tlong count = 0;\n\t\tlong z = p;\n\t\twhile (z <= n) {\n\t\t\tcount += n / z;\n\t\t\tz *= p;\n\t\t}\n\t\treturn count;\n\n\t}\n\n\tpublic static int[] generatePrimes(int n) {\n\t\tboolean[] prime = new boolean[n + 1];\n\t\tArrays.fill(prime, 2, n + 1, true);\n\t\tfor (int i = 2; i * i <= n; i++)\n\t\t\tif (prime[i])\n\t\t\t\tfor (int j = i * i; j <= n; j += i)\n\t\t\t\t\tprime[j] = false;\n\t\tint[] primes = new int[n + 1];\n\t\tint cnt = 0;\n\t\tfor (int i = 0; i < prime.length; i++)\n\t\t\tif (prime[i])\n\t\t\t\tprimes[cnt++] = i;\n\n\t\treturn Arrays.copyOf(primes, cnt);\n\t}\n\n\tstatic class Pairxy implements Comparable<Pairxy> {\n\t\tint x;\n\t\tint y;\n\n\t\tPairxy(int x, int y) {\n\t\t\tthis.x = x;\n\t\t\tthis.y = y;\n\t\t}\n\n\t\tpublic int compareTo(Pairxy o) {\n\t\t\treturn Integer.compare(this.x, o.x);\n\t\t}\n\n\t}\n\n\tstatic class Pair implements Comparable<Pair> {\n\t\tlong val;\n\t\tint ind;\n\n\t\tPair(long v, int i) {\n\t\t\tval = v;\n\t\t\tind = i;\n\t\t}\n\n\t\tpublic int compareTo(Pair o) {\n\t\t\tif (this.val != o.val)\n\t\t\t\treturn Long.compare(this.val, o.val);\n\t\t\treturn Integer.compare(this.ind, o.ind);\n\t\t}\n\t}\n\n\tpublic static long C(int n, int r) {\n\t\tlong ans = 1;\n\t\tint x = 1;\n\t\twhile (x <= r) {\n\t\t\tans *= n;\n\t\t\tans /= x;\n\t\t\tx++;\n\t\t\tn--;\n\t\t}\n\t\treturn ans;\n\t}\n\n\tstatic class DisjointSetsRank {\n\n\t\tint[] p;\n\t\tint[] rank;\n\n\t\tpublic DisjointSetsRank(int size) {\n\t\t\tp = new int[size];\n\t\t\tfor (int i = 0; i < size; i++)\n\t\t\t\tp[i] = i;\n\t\t\trank = new int[size];\n\t\t}\n\n\t\tpublic int root(int x) {\n\t\t\treturn x == p[x] ? x : (p[x] = root(p[x]));\n\t\t}\n\n\t\tpublic int sameSet(int x, int y) {\n\t\t\tif (root(x) == root(y))\n\t\t\t\treturn 1;\n\t\t\treturn 0;\n\n\t\t}\n\n\t\tpublic void unite(int a, int b) {\n\t\t\ta = root(a);\n\t\t\tb = root(b);\n\t\t\tif (a == b)\n\t\t\t\treturn;\n\n\t\t\tif (rank[a] < rank[b]) {\n\t\t\t\tp[a] = b;\n\t\t\t} else {\n\t\t\t\tp[b] = a;\n\t\t\t\tif (rank[a] == rank[b])\n\t\t\t\t\t++rank[a];\n\t\t\t}\n\t\t}\n\n\t}\n\n\tstatic int gcd(long m, long n) {\n\t\tlong x;\n\t\tlong y;\n\t\twhile (m % n != 0) {\n\t\t\tx = n;\n\t\t\ty = m % n;\n\t\t\tm = x;\n\t\t\tn = y;\n\t\t}\n\t\treturn (int) n;\n\t}\n\n\tstatic class FasterScanner {\n\t\tprivate byte[] buf = new byte[1024];\n\t\tprivate int curChar;\n\t\tprivate int snumChars;\n\n\t\tpublic int read() {\n\t\t\tif (snumChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= snumChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tsnumChars = 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}", "src_uid": "d6c876a84c7b92141710be5d76536eab"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class B {\n\n\tstatic int n, t[], g[], MOD = (int) 1e9 + 7;\n\tstatic int[][][] memo1, memo2[], memo3[];\n\n\tstatic int dp1(int idx, int remCnt, int remSum) {\n\t\tif (idx == n)\n\t\t\treturn remSum == 0 && remCnt == 0 ? 1 : 0;\n\t\tif (remCnt < 0 || remSum < 0)\n\t\t\treturn 0;\n\t\tif (memo1[idx][remCnt][remSum] != -1)\n\t\t\treturn memo1[idx][remCnt][remSum];\n\t\tint ans = dp1(idx + 1, remCnt, remSum);\n\t\tif (g[idx] == 0) {\n\t\t\tans += dp1(idx + 1, remCnt - 1, remSum - t[idx]);\n\t\t\tif (ans >= MOD)\n\t\t\t\tans -= MOD;\n\t\t}\n\t\treturn memo1[idx][remCnt][remSum] = ans;\n\t}\n\n\tstatic int dp2(int idx, int remCnt1, int remCnt2, int remSum) {\n\n\t\tif (idx == n)\n\t\t\treturn remSum == 0 && remCnt1 == 0 && remCnt2 == 0 ? 1 : 0;\n\t\tif (remSum < 0 || remCnt1 < 0 || remCnt2 < 0)\n\t\t\treturn 0;\n\t\tif (memo2[idx][remCnt1][remCnt2][remSum] != -1)\n\t\t\treturn memo2[idx][remCnt1][remCnt2][remSum];\n\t\tint ans = dp2(idx + 1, remCnt1, remCnt2, remSum);\n\n\t\tif (g[idx] == 1)\n\t\t\tans += dp2(idx + 1, remCnt1 - 1, remCnt2, remSum - t[idx]);\n\t\telse if (g[idx] == 2)\n\t\t\tans += dp2(idx + 1, remCnt1, remCnt2 - 1, remSum - t[idx]);\n\t\tif(ans>=MOD)\n\t\t\tans-=MOD;\n\t\treturn memo2[idx][remCnt1][remCnt2][remSum] = ans;\n\t}\n\n\tprivate static int dp3(int cnt0, int cnt1, int cnt2, int last) {\n\t\tif (cnt0 < 0 || cnt1 < 0 || cnt2 < 0)\n\t\t\treturn 0;\n\t\tif (cnt0 + cnt1 + cnt2 == 0)\n\t\t\treturn 1;\n\t\tif (memo3[last][cnt0][cnt1][cnt2] != -1)\n\t\t\treturn memo3[last][cnt0][cnt1][cnt2];\n\t\tlong ans = 0;\n\t\tif (last != 0)\n\t\t\tans += dp3(cnt0 - 1, cnt1, cnt2, 0);\n\t\tif (last != 1)\n\t\t\tans += dp3(cnt0, cnt1 - 1, cnt2, 1);\n\t\tif (last != 2)\n\t\t\tans += dp3(cnt0, cnt1, cnt2 - 1, 2);\n\t\treturn memo3[last][cnt0][cnt1][cnt2] = (int) (ans % MOD);\n\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\tn = sc.nextInt();\n\t\tint[] fac = new int[n + 1];\n\t\tt = new int[n];\n\t\tg = new int[n];\n\t\tint[] cnt = new int[3];\n\t\tfac[0] = 1;\n\t\tfor (int i = 1; i <= n; i++)\n\t\t\tfac[i] = (int) (i * 1L * fac[i - 1] % MOD);\n\t\tint T = sc.nextInt();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tt[i] = sc.nextInt();\n\t\t\tg[i] = sc.nextInt() - 1;\n\t\t\tcnt[g[i]]++;\n\n\t\t}\n\t\tmemo1 = new int[n][cnt[0] + 1][T + 1];\n\t\tmemo2 = new int[n][cnt[1] + 1][cnt[2] + 1][T + 1];\n\t\tmemo3 = new int[4][cnt[0] + 1][cnt[1] + 1][cnt[2] + 1];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j <= cnt[0]; j++)\n\t\t\t\tArrays.fill(memo1[i][j], -1);\n\t\t\tfor (int j = 0; j <= cnt[1]; j++)\n\t\t\t\tfor (int k = 0; k <= cnt[2]; k++)\n\t\t\t\t\tArrays.fill(memo2[i][j][k], -1);\n\n\t\t}\n\t\tfor (int i = 0; i < 4; i++)\n\t\t\tfor (int j = 0; j <= cnt[0]; j++)\n\t\t\t\tfor (int k = 0; k <= cnt[1]; k++)\n\t\t\t\t\tArrays.fill(memo3[i][j][k], -1);\n\t\tint ans = 0;\n\t\tfor (int cnt0 = 0; cnt0 <= cnt[0]; cnt0++)\n\t\t\tfor (int sum0 = 0; sum0 <= T; sum0++)\n\t\t\t\tfor (int cnt1 = 0; cnt1 <= cnt[1]; cnt1++)\n\t\t\t\t\tfor (int cnt2 = 0; cnt2 <= cnt[2]; cnt2++) {\n\t\t\t\t\t\tlong ways = dp1(0, cnt0, sum0) * 1L * dp2(0, cnt1, cnt2, T - sum0) % MOD;\n\t\t\t\t\t\tways = ways * dp3(cnt0, cnt1, cnt2, 3) % MOD;\n\t\t\t\t\t\tways *= fac[cnt0];\n\t\t\t\t\t\tways %= MOD;\n\t\t\t\t\t\tways *= fac[cnt1];\n\t\t\t\t\t\tways %= MOD;\n\t\t\t\t\t\tways *= fac[cnt2];\n\t\t\t\t\t\tways %= MOD;\n\t\t\t\t\t\tans += ways;\n\t\t\t\t\t\tif (ans >= MOD)\n\t\t\t\t\t\t\tans -= MOD;\n\t\t\t\t\t}\n\t\tout.println(ans);\n\t\tout.close();\n\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}", "src_uid": "ed5f913afe829c65792b54233a256757"} {"source_code": "// https://codeforces.com/problemset/problem/1113/A\nimport java.util.*;import java.io.*;import java.math.*;\npublic class Main\n{\n\n\tpublic static void process()throws IOException\n {\n \tint n=ni(),v=ni();\n \tint cost=0;\n\n \tif(v>=n-1){\n \t\tpn(n-1);\n \t\treturn;\n \t}\n \t\n \tcost+=v;\n \tfor(int i=2;i<=n-v;i++)\n \t\tcost+=i;\n \tpn(cost);\n }\n\n\n \tstatic AnotherReader sc;\n\n public static void main(String[]args)throws IOException\n {\n \tboolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n \tif(oj)\n \tsc=new AnotherReader();\n else\n \tsc=new AnotherReader(100);\n int t=1;\n while(t-->0)\n process();\n System.out.flush();\n System.out.close(); \n }\n\n static void pn(Object o){System.out.println(o);}\n static void p(Object o){System.out.print(o);}\n static void pni(Object o){System.out.println(o);System.out.flush();}\n static int ni()throws IOException{return sc.nextInt();}\n static long nl()throws IOException{return sc.nextLong();}\n static double nd()throws IOException{return sc.nextDouble();}\n static String nln()throws IOException{return sc.nextLine();}\n static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}\n static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}\n static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}\n static boolean multipleTC=false;\n\n\n\n/////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n static class AnotherReader{BufferedReader br; StringTokenizer st;\n AnotherReader()throws FileNotFoundException{\n br=new BufferedReader(new InputStreamReader(System.in));}\n AnotherReader(int a)throws FileNotFoundException{\n br = new BufferedReader(new FileReader(\"input.txt\"));}\n String next()throws IOException{\n while (st == null || !st.hasMoreElements()) {try{\n st = new StringTokenizer(br.readLine());}\n catch (IOException e){ e.printStackTrace(); }}\n return st.nextToken(); } int nextInt() throws IOException{\n return Integer.parseInt(next());}\n long nextLong() throws IOException\n {return Long.parseLong(next());}\n double nextDouble()throws IOException { return Double.parseDouble(next()); }\n String nextLine() throws IOException{ String str = \"\"; try{\n str = br.readLine();} catch (IOException e){\n e.printStackTrace();} return str;}}\n \n/////////////////////////////////////////////////////////////////////////////////////////////////////////////\n}\n\t\n\t", "src_uid": "f8eb96deeb82d9f011f13d7dac1e1ab7"} {"source_code": "/*\nID: davidzh8\nPROG: subset\nLANG: JAVA\n */\n\nimport java.io.*;\nimport java.util.*;\nimport java.lang.*;\n\npublic class villagemin {\n\n static long startTime = System.nanoTime();\n static ArrayList<Integer>[] adj;\n static int[] pos;\n public static void solve() throws Exception {\n boolean debug = (true);\n FastScanner sc = new FastScanner(\"villagemin.in\", debug);\n FastWriter pw = new FastWriter(\"villagemin.out\", debug);\n int N= sc.ni();\n adj= new ArrayList[N];\n pos= new int[N];\n for (int i = 0; i < N; i++) {\n pos[i]=i;\n }\n for(int i=0; i<N; i++){\n adj[i]= new ArrayList<>();\n }\n for (int i = 0; i < N-1; i++) {\n int a= sc.ni()-1;\n int b= sc.ni()-1;\n adj[a].add(b);\n adj[b].add(a);\n }\n dfs(0,-1);\n System.out.println(res);\n for (int i = 0; i < N; i++) {\n System.out.print(pos[i]+1+\" \");\n }\n\n\n long endTime = System.nanoTime();\n //System.out.println(\"Execution Time: \" + (endTime - startTime) / 1e9 + \" s\");\n pw.close();\n }\n static int res=0;\n static void dfs(int cur, int par){\n for(int next: adj[cur] ){\n if(next==par) continue;\n dfs(next, cur);\n if(pos[next]==next) {\n res += 2;\n int temp = pos[cur];\n pos[cur] = pos[next];\n pos[next] = temp;\n }\n }\n if(cur==0 && pos[cur]==0){\n int next= adj[0].get(0);\n res += 2;\n int temp = pos[cur];\n pos[cur] = pos[next];\n pos[next] = temp;\n }\n\n }\n\n\n static class Pair implements Comparable<Pair> {\n int a;\n int b;\n\n public Pair(int a, int b) {\n this.a = a;\n this.b = b;\n }\n\n public int compareTo(Pair obj) {\n if (obj.a == a) {\n return b - obj.b;\n } else return a - obj.a;\n }\n }\n\n\n static class djset {\n int N;\n int[] parent;\n\n // Creates a disjoint set of size n (0, 1, ..., n-1)\n public djset(int n) {\n parent = new int[n];\n N = n;\n for (int i = 0; i < n; i++)\n parent[i] = i;\n }\n\n public int find(int v) {\n\n // I am the club president!!! (root of the tree)\n if (parent[v] == v) return v;\n\n // Find my parent's root.\n int res = find(parent[v]);\n\n // Attach me directly to the root of my tree.\n parent[v] = res;\n return res;\n }\n\n public boolean union(int v1, int v2) {\n\n // Find respective roots.\n int rootv1 = find(v1);\n int rootv2 = find(v2);\n\n // No union done, v1, v2 already together.\n if (rootv1 == rootv2) return false;\n\n // Attach tree of v2 to tree of v1.\n parent[rootv2] = rootv1;\n return true;\n }\n\n\n }\n\n static class FastScanner {\n InputStream dis;\n byte[] buffer = new byte[1 << 17];\n int pointer = 0;\n\n public FastScanner(String fileName, boolean debug) throws Exception {\n if (debug) dis = System.in;\n else dis = new FileInputStream(fileName);\n }\n\n int ni() throws Exception {\n int ret = 0;\n\n byte b;\n do {\n b = nextByte();\n } while (b <= ' ');\n boolean negative = false;\n if (b == '-') {\n negative = true;\n b = nextByte();\n }\n while (b >= '0' && b <= '9') {\n ret = 10 * ret + b - '0';\n b = nextByte();\n }\n\n return (negative) ? -ret : ret;\n }\n\n long nl() throws Exception {\n long ret = 0;\n\n byte b;\n do {\n b = nextByte();\n } while (b <= ' ');\n boolean negative = false;\n if (b == '-') {\n negative = true;\n b = nextByte();\n }\n while (b >= '0' && b <= '9') {\n ret = 10 * ret + b - '0';\n b = nextByte();\n }\n\n return (negative) ? -ret : ret;\n }\n\n byte nextByte() throws Exception {\n if (pointer == buffer.length) {\n dis.read(buffer, 0, buffer.length);\n pointer = 0;\n }\n return buffer[pointer++];\n }\n\n String next() throws Exception {\n StringBuffer ret = new StringBuffer();\n\n byte b;\n do {\n b = nextByte();\n } while (b <= ' ');\n while (b > ' ') {\n ret.appendCodePoint(b);\n b = nextByte();\n }\n\n return ret.toString();\n }\n }\n\n static class FastWriter {\n public PrintWriter pw;\n\n public FastWriter(String name, boolean debug) throws IOException {\n if (debug) {\n pw = new PrintWriter(System.out);\n } else {\n pw = new PrintWriter(new BufferedWriter(new FileWriter(new File(name))));\n }\n }\n\n public void println(Object text) {\n pw.println(text);\n }\n\n public void print(Object text) {\n pw.print(text);\n }\n\n public void close() {\n pw.close();\n }\n\n public void flush() {\n pw.flush();\n }\n }\n\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, () -> {\n try {\n solve();\n } catch (Exception e) {\n e.printStackTrace();\n }\n }, \"\", 1 << 28);\n thread.start();\n thread.join();\n }\n\n}", "src_uid": "98ded03cdd1870500667f0069d6a84b1"} {"source_code": "import java.util.Scanner;\n\npublic class KolyaAndTanya {\n public static void main(String[] args) {\n Scanner inputScanner = new Scanner(System.in);\n int n = inputScanner.nextInt();\n int bound = 1000000007;\n System.out.println((getBoundedPower(3, 3 * n, bound) - getBoundedPower(7, n, bound) + bound) % bound);\n }\n\n public static long getBoundedPower(int base, int power) {\n long res = 1;\n for (int i = 0; i < power; i++) {\n res = (res * base) % 1000000007;\n }\n return res ;\n }\n \n public static long getBoundedPower(int base, int power, int bound) {\n long ans = 1;\n long currentBase = base % bound;\n while (power > 0) {\n if (power % 2 == 1)\n ans = (ans * currentBase) % bound;\n currentBase = (currentBase * currentBase) % bound;\n power = power / 2;\n }\n return ans;\n }\n\n}\n", "src_uid": "eae87ec16c284f324d86b7e65fda093c"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Solution{\n\tInputStream is;\n\tstatic PrintWriter out;\n\tString INPUT = \"\";\n\tstatic long mod = (long)1e9+7L;\n\t\n\tpublic void solve(){\n\t\tlong n = nl(), m = nl(), k = nl();\n\t\tlong l = 1L, r = m*n;\n\t\twhile(l < r){\n\t\t\tlong mid = l+(r-l)/2L;\n\t\t\tif(f(n, m, mid, k)){\n\t\t\t\tr = mid;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tl = mid+1L;\n\t\t\t}\n\t\t}\n\n\t\tout.println(l);\n\t}\n\t\n\tboolean f(long n, long m, long key, long k){\n\t\tlong res2 = 0;\n\t\tfor(long i = 1 ; i <= n; i++){\n\t\t\tres2 = res2 + Math.min(m, key/i);\n\t\t}\n\t\tif(res2 >= k){\n\t\t\treturn true;\n\t\t}\n\t\telse{\n\t\t\treturn false;\n\t\t}\n\t}\t\n\n\tvoid run(){\n\t\tis = new DataInputStream(System.in);\n\t\tout = new PrintWriter(System.out);\n\t\tint t=1;while(t-->0)solve();\n\t\tout.flush();\n\t}\n\tpublic static void main(String[] args)throws Exception{new Solution().run();}\n\tlong mod(long v, long m){if(v<0){long q=(Math.abs(v)+m-1L)/m;v=v+q*m;}return v%m;}\n long mod(long v){if(v<0){long q=(Math.abs(v)+mod-1L)/mod;v=v+q*mod;}return v%mod;}\n\t//Fast I/O code is copied from uwi code.\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\tprivate int readByte(){\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\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\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\tprivate String ns(){\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\tprivate char[] ns(int n){\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\tprivate char[][] nm(int n, int m){\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\tprivate int[] na(int n){\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\tprivate int ni(){\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = 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\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\tprivate long nl(){\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\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\tstatic int i(long x){return (int)Math.round(x);}\n\tstatic class Pair implements Comparable<Pair>{\n\t\tlong fs,sc;\n\t\tPair(long a,long b){\n\t\t\tfs=a;sc=b;\n\t\t}\n\t\tpublic int compareTo(Pair p){\n\t\t\tif(this.fs>p.fs)return 1;\n\t\t\telse if(this.fs<p.fs)return -1;\n\t\t\telse{\n\t\t\t\treturn i(this.sc-p.sc);\n\t\t\t}\n\t\t\t//return i(this.sc-p.sc);\n\t\t}\n\t\tpublic String toString(){\n\t\t\treturn \"(\"+fs+\",\"+sc+\")\";\n\t\t}\t\n\t}\n\t\n}", "src_uid": "13a918eca30799b240ceb9de47507a26"} {"source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class a {\n \n public static void main(String[] args) \n {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt() * 2;\n int[] f = new int[10];\n for (int i = 0; i < 4; i++)\n {\n String line = in.next();\n for (int j = 0; j < 4; j++)\n {\n if (line.charAt(j) == '.')\n continue;\n f[line.charAt(j) - '0']++;\n }\n }\n \n Arrays.sort(f);\n System.out.println(f[9] > n ? \"NO\" : \"YES\");\n \n \n \n \n }\n\n}\n ", "src_uid": "5fdaf8ee7763cb5815f49c0c38398f16"} {"source_code": "import java.util.Scanner;\n\npublic class A {\n\tpublic static void main(String args[]){\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();String s= \"\";\n\t\tint t = in.nextInt();\n\t\tif(t==10){\n\t\t\tfor(int i = 0 ; i < n-1 ; i++)\n\t\t\t\ts+=\"1\";\n\t\t\ts+=\"0\";\n\t\t}else{\n\t\t\tfor(int i = 0 ; i < n ; i++)\n\t\t\t\ts+=t;\n\t\t}\n\t\tif(s.equals(\"0\"))\n\t\t\ts = \"-1\";\n\t\tSystem.out.println(s);\n\t}\n}\n", "src_uid": "77ffc1e38c32087f98ab5b3cb11cd2ed"} {"source_code": "import java.util.NavigableSet;\nimport java.util.SortedSet;\nimport java.util.Comparator;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.Writer;\nimport java.util.Collection;\nimport java.util.List;\nimport java.io.IOException;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\nimport java.util.ArrayList;\nimport java.util.Set;\nimport java.util.TreeSet;\nimport java.math.BigInteger;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Egor Kulikov (egor@egork.net)\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tOutputWriter out = new OutputWriter(outputStream);\n\t\tTaskF solver = new TaskF();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskF {\n\tint[] first;\n\tint[] second;\n\tint[] cost;\n\n\tpublic void solve(int testNumber, InputReader in, OutputWriter out) {\n\t\tint count = in.readInt();\n\t\tint edgeCount = in.readInt();\n\t\tint index = in.readInt() - 1;\n\t\tfirst = new int[edgeCount];\n\t\tsecond = new int[edgeCount];\n\t\tcost = new int[edgeCount];\n\t\tIOUtils.readIntArrays(in, first, second, cost);\n\t\tNavigableSet<State> set = new TreeSet<State>();\n\t\tset.add(new State(0, 0, 0, 0, 0));\n\t\tfor (int i = 0; i < index; i++) {\n\t\t\tState current = set.pollFirst();\n\t\t\tfor (int j = 0; j < edgeCount; j++) {\n\t\t\t\tState next = current.add(j);\n\t\t\t\tif (next != null)\n\t\t\t\t\tset.add(next);\n\t\t\t}\n\t\t}\n\t\tout.printLine(set.first().cost);\n\t}\n\n\tclass State implements Comparable<State> {\n\t\tfinal int menMask;\n\t\tfinal int womenMask;\n\t\tfinal long firstEdgeMask;\n\t\tfinal long secondEdgeMask;\n\t\tfinal int cost;\n\n\t\tState(int menMask, int womenMask, long firstEdgeMask, long secondEdgeMask, int cost) {\n\t\t\tthis.menMask = menMask;\n\t\t\tthis.womenMask = womenMask;\n\t\t\tthis.firstEdgeMask = firstEdgeMask;\n\t\t\tthis.secondEdgeMask = secondEdgeMask;\n\t\t\tthis.cost = cost;\n\t\t}\n\n\t\tpublic int compareTo(State o) {\n\t\t\tif (cost != o.cost)\n\t\t\t\treturn cost - o.cost;\n\t\t\tint value = IntegerUtils.longCompare(firstEdgeMask, o.firstEdgeMask);\n\t\t\tif (value != 0)\n\t\t\t\treturn value;\n\t\t\treturn IntegerUtils.longCompare(secondEdgeMask, o.secondEdgeMask);\n\t\t}\n\n\t\tpublic State add(int edge) {\n\t\t\tif ((menMask >> first[edge] & 1) != 0 || (womenMask >> second[edge] & 1) != 0)\n\t\t\t\treturn null;\n\t\t\treturn new State(menMask + (1 << first[edge]), womenMask + (1 << second[edge]),\n\t\t\t\tfirstEdgeMask + (edge < 64 ? 1L << edge : 0), secondEdgeMask + (edge >= 64 ? 1L << (edge - 64) : 0),\n\t\t\t\tcost + TaskF.this.cost[edge]);\n\t\t}\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\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 static boolean isSpaceChar(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n\n\t}\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 print(Object...objects) {\n\t\tfor (int i = 0; i < objects.length; i++) {\n\t\t\tif (i != 0)\n\t\t\t\twriter.print(' ');\n\t\t\twriter.print(objects[i]);\n\t\t}\n\t}\n\n\tpublic void printLine(Object...objects) {\n\t\tprint(objects);\n\t\twriter.println();\n\t}\n\n\tpublic void close() {\n\t\twriter.close();\n\t}\n\n\t}\n\nclass IOUtils {\n\n\tpublic static void readIntArrays(InputReader in, int[]... arrays) {\n\t\tfor (int i = 0; i < arrays[0].length; i++) {\n\t\t\tfor (int j = 0; j < arrays.length; j++)\n\t\t\t\tarrays[j][i] = in.readInt();\n\t\t}\n\t}\n\n\t}\n\nclass IntegerUtils {\n\n\tpublic static int longCompare(long a, long b) {\n\t\tif (a < b)\n\t\t\treturn -1;\n\t\tif (a > b)\n\t\t\treturn 1;\n\t\treturn 0;\n\t}\n\n\t}\n\n", "src_uid": "7348b5644f232bf377a4834eded42e4b"} {"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 */\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\tTaskC solver = new TaskC();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n\n\tstatic class TaskC {\n\t\tchar[][] ans = new char[2][13];\n\n\t\tpublic void solve(int testNumber, FastScanner in, PrintWriter out) {\n\t\t\tString s = in.next();\n\t\t\tint p1 = -1;\n\t\t\tint p2 = -1;\n\t\t\tfor (int i = 0; i < s.length(); i++) {\n\t\t\t\tfor (int j = i + 1; j < s.length(); j++) {\n\t\t\t\t\tif (s.charAt(i) == s.charAt(j)) {\n\t\t\t\t\t\tp1 = i;\n\t\t\t\t\t\tp2 = j;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tint len = p2 - p1 - 1;\n\t\t\tif (len == 0) {\n\t\t\t\tout.println(\"Impossible\");\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tArrays.fill(ans[0], '.');\n\t\t\tArrays.fill(ans[1], '.');\n\t\t\tif (len == 1) {\n\t\t\t\tgoLeft(0, 1, s.substring(p1, p2));\n\t\t\t} else {\n\t\t\t\tgoLeft(0, len / 2, s.substring(p1, p2));\n\t\t\t}\n\t\t\tString u = rev(s.substring(0, p1));\n\t\t\tString v = s.substring(p2 + 1);\n\t\t\tif (len / 2 + 1 >= ans[0].length && !u.isEmpty()) {\n\t\t\t\tString t = u;\n\t\t\t\tu = v;\n\t\t\t\tv = t;\n\t\t\t}\n\t\t\tif (len == 1) {\n\t\t\t\tgoRight(0, 2, u);\n\t\t\t\tgoRight(1, 0, v);\n\t\t\t} else {\n\t\t\t\tgoRight(0, len / 2 + 1, u);\n\t\t\t\tgoRight(1, (len + 1) / 2, v);\n\t\t\t}\n\t\t\tout.println(new String(ans[0]));\n\t\t\tout.println(new String(ans[1]));\n\t\t}\n\n\t\tprivate String rev(String s) {\n\t\t\treturn new StringBuilder(s).reverse().toString();\n\t\t}\n\n\t\tprivate void goLeft(int r, int c, String s) {\n\t\t\tif (s.isEmpty()) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (ans[r][c] != '.') {\n\t\t\t\tthrow new AssertionError();\n\t\t\t}\n\t\t\tans[r][c] = s.charAt(0);\n\t\t\tif (c > 0) {\n\t\t\t\tgoLeft(r, c - 1, s.substring(1));\n\t\t\t} else {\n\t\t\t\tgoRight(1 - r, c, s.substring(1));\n\t\t\t}\n\t\t}\n\n\t\tprivate void goRight(int r, int c, String s) {\n\t\t\tif (s.isEmpty()) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (ans[r][c] != '.') {\n\t\t\t\tthrow new AssertionError();\n\t\t\t}\n\t\t\tans[r][c] = s.charAt(0);\n\t\t\tif (c + 1 < ans[r].length) {\n\t\t\t\tgoRight(r, c + 1, s.substring(1));\n\t\t\t} else {\n\t\t\t\tgoLeft(1 - r, c, s.substring(1));\n\t\t\t}\n\t\t}\n\n\t}\n\n\tstatic class FastScanner {\n\t\tprivate BufferedReader in;\n\t\tprivate StringTokenizer st;\n\n\t\tpublic FastScanner(InputStream stream) {\n\t\t\tin = new BufferedReader(new InputStreamReader(stream));\n\t\t}\n\n\t\tpublic String next() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tString rl = in.readLine();\n\t\t\t\t\tif (rl == null) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\tst = new StringTokenizer(rl);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(e);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn st.nextToken();\n\t\t}\n\n\t}\n}\n\n", "src_uid": "56c5ea443dec7a732802b16aed5b934d"} {"source_code": "import java.util.Scanner;\n\npublic class B {\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 x1=sc.nextInt(),y1=sc.nextInt();\n int x2=sc.nextInt(),y2=sc.nextInt();\n int r1=0,r2=0;\n r1+=Math.abs(((x1+y1)/(2*a))-((x2+y2)/(2*a)));\n if(((x1+y1)*1.0)/(x2+y2)<0) {\n r1++;\n }\n r2+=Math.abs(((x1-y1)/(2*b))-((x2-y2)/(2*b)));\n if(((x1-y1)*1.0)/(x2-y2)<0){\n r2++;\n }\n System.out.println(Math.max(r1,r2));\n }\n}\n", "src_uid": "7219d1837c83b5920992aee5a60dc0d9"} {"source_code": "import java.util.Scanner;\n\npublic class BeautifulYear {\n\n\t\n\tpublic static void main(String [] args)\n\t{\n\t\tScanner sc = new Scanner(System.in);\n\t\t\n\t\tint n = sc.nextInt();\n\t\tint m = sc.nextInt();\n\t\t\n\t\tint inter = n*m;\n\t\tint pas=0;\n\t\t\n\t\twhile(inter>=0 && n>=0 && m>=0)\n\t\t{\n\t\t\tinter--;\n\t\t\tn--;\n\t\t\tm--;\n\t\t\tpas++;\n\t\t}\n\t\tif(pas%2 == 0) System.out.println(\"Akshat\");\n\t\telse System.out.println(\"Malvika\");\n\t\t\n\t}\n}", "src_uid": "a4b9ce9c9f170a729a97af13e81b5fe4"} {"source_code": "import java.io.*;\nimport java.util.ArrayList;\nimport java.util.StringTokenizer;\n\npublic class palindromeDance {\n static int n, a, b;\n static int[] input;\n static ArrayList<Integer> unbought;\n public static void main(String[] args) throws IOException{\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));\n\n StringTokenizer st = new StringTokenizer(br.readLine());\n\n n = Integer.parseInt(st.nextToken());\n a = Integer.parseInt(st.nextToken());\n b = Integer.parseInt(st.nextToken());\n\n input = new int[n];\n\n st = new StringTokenizer(br.readLine());\n\n unbought = new ArrayList<Integer>();\n\n for(int i = 0; i < n; i++){\n input[i] = Integer.parseInt(st.nextToken());\n if(input[i] == 2){\n unbought.add(i);\n }\n }\n\n boolean alreadyComplete = true;\n\n for(int i = 0; i < n; i++){\n if(input[i] == 2){\n alreadyComplete = false;\n }\n }\n\n if(alreadyComplete && isPalindrome(input)){\n out.println(0);\n out.close();\n }\n else if(alreadyComplete && !isPalindrome(input)){\n out.println(-1);\n out.close();\n }\n else if(!alreadyComplete) {\n\n int n2 = Math.min(solve(0, a, input, 0), solve(0, b, input, 1));\n\n if (n2 == Integer.MAX_VALUE) {\n out.println(-1);\n } else {\n out.println(n2);\n }\n\n out.close();\n }\n\n\n\n }\n\n public static int solve(int pos, int cost, int[] list, int suit){\n\n list[unbought.get(pos)] = suit;\n\n if(pos == unbought.size()-1 && isPalindrome(list)){\n return cost;\n }\n //if is not palindrome\n else if(pos == unbought.size()-1){\n return Integer.MAX_VALUE;\n }\n\n\n\n\n return Math.min(solve(pos+1, cost+a, list, 0), solve(pos+1, cost+b, list, 1));\n }\n\n public static boolean isPalindrome(int[] list){\n int rightPointer = list.length-1;\n\n for(int i = 0; i < list.length/2; i++){\n if(list[i] != list[rightPointer]){\n return false;\n }\n rightPointer--;\n }\n\n return true;\n }\n\n\n\n\n\n}", "src_uid": "af07223819aeb5bd6ded4340c472b2b6"} {"source_code": "\n\nimport java.util.Scanner;\n\npublic class Brain_Photo {\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 m = sc.nextInt();\n\t\tsc.nextLine();\n\t\t\n\t\tboolean color = false;\n\t\tfor(int i = 0;i<n;i++)\n\t\t{\n\t\t\tString arr[] = sc.nextLine().split(\" \");\n\t\t\tfor(int j = 0;j<m;j++)\n\t\t\t{\n\t\t\t\tchar ch = arr[j].charAt(0);\n\t\t\t\tif(ch == 'C' || ch == 'M' || ch == 'Y')\n\t\t\t\t\tcolor = true;\n\t\t\t}\n\t\t}\n\t\t\n\t\tif(color)\n\t\t\tSystem.out.println(\"#Color\");\n\t\telse\n\t\t\tSystem.out.println(\"#Black&White\");\n\t\t\n\t\tsc.close();\n\t\t\n\t}\n\n}\n", "src_uid": "19c311c02380f9a73cd477e4fde27454"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.Reader;\nimport java.math.BigInteger;\nimport java.util.Random;\nimport java.util.StringTokenizer;\n\npublic class D {\n public static void main(String[] args) {\n FastScanner sc = new FastScanner();\n\n long a1 = sc.nextLong();\n long b1 = sc.nextLong();\n long a2 = sc.nextLong();\n long b2 = sc.nextLong();\n long left = sc.nextLong();\n long right = sc.nextLong();\n\n long lcm = lcm(a1, a2);\n left = Math.max(left, Math.max(b1, b2));\n\n // a1*x + b1 = a2*y + b2\n // a1*x - a2*y = b1 - b2\n long[] x_y_gcd = solveDiophantine(a1, -a2, b2 - b1);\n if (x_y_gcd == null) {\n System.out.println(0);\n } else {\n BigInteger a1Bi = BigInteger.valueOf(a1);\n BigInteger b1Bi = BigInteger.valueOf(b1);\n BigInteger leftBi = BigInteger.valueOf(left);\n BigInteger rightBi = BigInteger.valueOf(right);\n BigInteger lcmBi = BigInteger.valueOf(lcm);\n\n BigInteger firstEq = a1Bi.multiply(BigInteger.valueOf(x_y_gcd[0])).add(b1Bi);\n BigInteger diff = leftBi.subtract(firstEq).divide(lcmBi).subtract(BigInteger.ONE);\n firstEq = firstEq.add(diff.multiply(lcmBi));\n while (firstEq.compareTo(leftBi) < 0) { // Might only happen once or twice\n firstEq = firstEq.add(lcmBi);\n }\n if (rightBi.compareTo(firstEq) < 0) {\n System.out.println(0);\n } else {\n long count = Math.max(rightBi.subtract(firstEq).divide(lcmBi).longValue() + 1, 0);\n System.out.println(count);\n }\n }\n }\n\n /**\n * Finds a single solution {x, y} to the LDE a*x + b*y = c.\n * Outputs an array of the form {x, y, d}, where d = GCD(a,b).\n */\n private static long[] solveDiophantine(long a, long b, long c) {\n long[] e = extEuclid(a, b);\n long k = c / e[2];\n\n //c not divisible by the GCD(a,b) -> no solution\n if (c - k * e[2] != 0)\n return null;\n\n long[] output = {e[0] * k, e[1] * k, e[2]};\n return output;\n }\n\n /**\n * Extended Euclidean Algorithm finds {x, y, d}\n * where d=GCD(a,b) and x and y satisfy a*x + b*y = d\n * The output is an array of the form {x, y, d}.\n */\n private static long[] extEuclid(long a, long b) {\n long s0 = 1, s1 = 0, sTemp;\n long t0 = 0, t1 = 1, tTemp;\n long r0 = a, r1 = b, rTemp;\n long q;\n\n while (r1 != 0) {\n q = r0 / r1;\n\n rTemp = r1;\n r1 = r0 - q * r1;\n r0 = rTemp;\n\n sTemp = s1;\n s1 = s0 - q * s1;\n s0 = sTemp;\n\n tTemp = t1;\n t1 = t0 - q * t1;\n t0 = tTemp;\n }\n\n long[] output = {s0, t0, r0};\n return output;\n }\n\n static long lcm(long a, long b) {\n return a / gcd(a, b) * b;\n }\n\n static long gcd(long a, long b) {\n if (b == 0) return a;\n return gcd(b, a % b);\n }\n\n public static class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(Reader in) {\n br = new BufferedReader(in);\n }\n\n public FastScanner() {\n this(new InputStreamReader(System.in));\n }\n\n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n double nextDouble() {\n return Double.parseDouble(next());\n }\n\n String readNextLine() {\n String str = \"\";\n try {\n str = br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return str;\n }\n\n int[] readIntArray(int n) {\n int[] a = new int[n];\n for (int idx = 0; idx < n; idx++) {\n a[idx] = nextInt();\n }\n return a;\n }\n\n long[] readLongArray(int n) {\n long[] a = new long[n];\n for (int idx = 0; idx < n; idx++) {\n a[idx] = nextLong();\n }\n return a;\n }\n }\n}\n", "src_uid": "b08ee0cd6f5cb574086fa02f07d457a4"} {"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.Comparator;\nimport java.util.StringTokenizer;\n\npublic final class Main\n{\n static class Cup\n {\n long c, w;\n\n Cup(long c, long w) {\n this.c = c;\n this.w = w;\n }\n\n static Comparator<Cup> cupComparator = new Comparator<Cup>() {\n @Override\n public int compare(Cup o1, Cup o2) {\n if (o1.c != o2.c)\n return - Long.compare(o1.c, o2.c);\n return Long.compare(o1.w, o2.w);\n }\n };\n }\n\n static class FastReader\n {\n private BufferedReader br;\n private StringTokenizer st;\n\n public FastReader()\n {\n br = new BufferedReader(new\n InputStreamReader(System.in));\n }\n\n String next()\n {\n while (st == null || !st.hasMoreElements())\n {\n try\n {\n st = new StringTokenizer(br.readLine());\n }\n catch (IOException e)\n {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt()\n {\n return Integer.parseInt(next());\n }\n\n long nextLong()\n {\n return Long.parseLong(next());\n }\n\n double nextDouble()\n {\n return Double.parseDouble(next());\n }\n\n String nextLine()\n {\n String str = \"\";\n try\n {\n str = br.readLine();\n }\n catch (IOException e)\n {\n e.printStackTrace();\n }\n return str;\n }\n }\n\n private static long ans = 0;\n\n\n public static void main(String[] args)\n {\n FastReader fastReader = new FastReader();\n int n = fastReader.nextInt();\n int m = fastReader.nextInt();\n long d = fastReader.nextInt();\n ArrayList<Cup> cupsP = new ArrayList<>();\n ArrayList<Cup> cupsI = new ArrayList<>();\n\n for(int i = 0; i < n; i ++)\n {\n long c = fastReader.nextInt();\n long w = fastReader.nextInt();\n cupsP.add(new Cup(c, w));\n }\n\n long sumCI = 0, sumWI = 0;\n for(int i = 0; i < m; i ++)\n {\n long c = fastReader.nextInt();\n long w = fastReader.nextInt();\n sumCI += c; sumWI += w;\n cupsI.add(new Cup(c, w));\n }\n\n Collections.sort(cupsP, Cup.cupComparator);\n Collections.sort(cupsI, Cup.cupComparator);\n\n int idI = m - 1;\n long sumCP = 0, sumWP = 0;\n for(int idP = 0; idP < n; idP ++)\n {\n sumCP += cupsP.get(idP).c;\n sumWP += cupsP.get(idP).w;\n while (sumWP + sumWI > d && idI >= 0)\n {\n sumCI -= cupsI.get(idI).c;\n sumWI -= cupsI.get(idI).w;\n idI --;\n }\n if (sumWP + sumWI <= d && idI >= 0 && ans < sumCI + sumCP) {\n ans = sumCI + sumCP;\n }\n }\n\n System.out.print(ans);\n }\n}\n", "src_uid": "da573a39459087ed7c42f70bc1d0e8ff"} {"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.Locale;\nimport java.util.StringTokenizer;\n\npublic class r58 {\n\tstatic StringTokenizer st;\n\tstatic BufferedReader br;\n\tstatic PrintWriter pw;\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tLocale.setDefault(Locale.US);\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tpw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(\n\t\t\t\tSystem.out)));\n\t\t\n\t\tint a1=nextInt(),a2=nextInt(),b1=nextInt(),b2=nextInt();\n\t\t\tif((a1>=b2&&a1-b2==1)||(a2>=b1&&a2-b1==1))\n\t\t\t\tpw.println(\"YES\");\n\t\t\telse\n\t\t\t\tif((b1>=a2&&(b1+1)/2-1<=a2)||(b2>=a1&&(b2+1)/2-1<=a1))\n\t\t\t\t\tpw.print(\"YES\");\n\t\t\telse\n\t\t\tpw.print(\"NO\");\n\t\tpw.close();\n\t}\n\n\tprivate static int nextInt() throws IOException {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tprivate static long nextLong() throws IOException {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tprivate static double nextDouble() throws IOException {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tprivate static 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", "src_uid": "36b7478e162be6e985613b2dad0974dd"} {"source_code": "import java.math.*;\nimport java.util.*;\n\npublic class A346 {\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\t\n\t\tint n = scan.nextInt();\n\t\tint a = scan.nextInt();\n\t\tint b = scan.nextInt();\n\t\t\n\t\tif (Math.abs(b) > n) {\n\t\t\tif (b > 0) {\n\t\t\t\tb = b%n;\n\t\t\t}\n\t\t\telse if (b < 0) {\n\t\t\t\tb = Math.abs(b)%n;\n\t\t\t\tb *= -1;\n\t\t\t}\n\t\t}\n\t\tif (b > 0) {\n\t\t\tint ans = (a+b)%n;\n\t\t\tif (ans == 0) {\n\t\t\t\tans = n;\n\t\t\t}\n\t\t\tSystem.out.println(ans);\n\t\t} else if (b < 0) {\n\t\t\tint newB = (b+a);\n\t\t\tif (newB > 0) {\n\t\t\t\tSystem.out.println(newB);\n\t\t\t} \n\t\t\telse {\n\t\t\t\tint ans = n - Math.abs(newB);\n\t\t\t\tSystem.out.println(ans);\n\t\t\t}\n\t\t} else {\n\t\t\tSystem.out.println(a);\n\t\t}\n\t}\n}\n", "src_uid": "cd0e90042a6aca647465f1d51e6dffc4"} {"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.Collections;\nimport java.util.List;\nimport java.util.StringTokenizer;\n\npublic class Emperor implements Runnable {\n static class Side implements Comparable<Side> {\n int dx;\n int dy;\n double alpha;\n Side next;\n\n public int compareTo(Side side) {\n return Double.compare(alpha, side.alpha);\n }\n\n public void getAlpha() {\n alpha = Math.atan2(dy, dx);\n }\n }\n\n static final int MAX = 500;\n static final int MAGIC = 7;\n List<Side> res;\n int tdx;\n int tdy;\n\n private void solve() throws IOException {\n int n = nextInt();\n Side[] first = new Side[MAX * MAX + 1];\n for (int dx = -MAX; dx <= MAX; ++dx)\n for (int dy = -MAX; dy <= MAX; ++dy) {\n int z = dx * dx + dy * dy;\n if (z <= MAX * MAX) {\n Side s = new Side();\n s.dx = dx;\n s.dy = dy;\n s.next = first[z];\n first[z] = s;\n }\n }\n int total = 0;\n List<Side> firsts = new ArrayList<Side>();\n for (int len = 1;; ++len) {\n if (first[len] == null)\n continue;\n ++total;\n firsts.add(first[len]);\n if (total < n)\n continue;\n if (doit(firsts, n)) {\n System.err.println(n + \" \" + total);\n break;\n }\n }\n for (Side s : res)\n s.getAlpha();\n Collections.sort(res);\n int x = 0;\n int y = 0;\n writer.println(\"YES\");\n for (Side s : res) {\n writer.println(x + \" \" + y);\n x += s.dx;\n y += s.dy;\n }\n }\n\n private boolean doit(List<Side> firsts, int n) {\n res = new ArrayList<Side>();\n tdx = 0;\n tdy = 0;\n return rec(firsts, n, firsts.size() - 1);\n }\n\n private boolean rec(List<Side> firsts, int toMake, int at) {\n if (toMake == 0) {\n return (tdx == 0 && tdy == 0);\n }\n if (at < 0) {\n throw new RuntimeException();\n }\n if (at >= MAGIC) {\n Side best = firsts.get(at);\n int bdist = (tdx + best.dx) * (tdx + best.dx) + (tdy + best.dy) * (tdy + best.dy);\n Side cur = best.next;\n while (cur != null) {\n int cdist = (tdx + cur.dx) * (tdx + cur.dx) + (tdy + cur.dy) * (tdy + cur.dy);\n if (cdist < bdist) {\n bdist = cdist;\n best = cur;\n }\n cur = cur.next;\n }\n res.add(best);\n tdx += best.dx;\n tdy += best.dy;\n if (rec(firsts, toMake - 1, at - 1))\n return true;\n res.remove(res.size() - 1);\n tdx -= best.dx;\n tdy -= best.dy;\n } else {\n Side best = firsts.get(at);\n while (best != null) {\n res.add(best);\n tdx += best.dx;\n tdy += best.dy;\n if (rec(firsts, toMake - 1, at - 1))\n return true;\n res.remove(res.size() - 1);\n tdx -= best.dx;\n tdy -= best.dy;\n best = best.next;\n }\n if (at >= toMake)\n if (rec(firsts, toMake, at - 1))\n return true;\n }\n return false;\n }\n\n public static void main(String[] args) {\n new Emperor().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}", "src_uid": "77b281558c480607b02e8e263e81a455"} {"source_code": "import java.util.Scanner;\npublic class CarrotCakes {\n\n public static void main(String[] args) {\n Scanner input =new Scanner(System.in);\n int n = input.nextInt(); \n int t = input.nextInt(); \n int k = input.nextInt(); \n int d = input.nextInt(); \n \n int time1=0;\n int tot1 = 0;\n \n for(int i = 1;tot1!=n&&tot1<=n;i++){\n time1=time1+t;\n tot1 = tot1 + k;\n }\n \n // System.out.println(); \n // System.out.println(\"total \"+tot1); \n // System.out.println(\"time \"+time1); \n \n int time2=0;\n int tot2 = 0;\n int f = 0;\n int ww =0;\n int oo = 0;\n for(int i = 1;true;i++){\n if(tot2>=n){break;}\n ww++;\n f++;\n// time2++;\n if(ww==t){\n tot2 = tot2+ k;\n ww=0;\n }\n if(f>d ){\n oo++;\n }\n if(oo==t){\n tot2 = tot2+ k;\n oo=0;\n }\n time2++;\n } \n \n // System.out.println(); \n // System.out.println(\"total \"+tot2); \n // System.out.println(\"time \"+time2); \n \n if(time2<time1){System.out.println(\"YES\");} \n else{System.out.println(\"NO\");} \n \n \n \n }\n}", "src_uid": "32c866d3d394e269724b4930df5e4407"} {"source_code": "import org.omg.CORBA.ARG_OUT;\n\nimport java.lang.reflect.Array;\nimport java.util.*;\n\n/**\n * Created by IntelliJ IDEA.\n * User: piyushd\n * Date: 3/26/11\n * Time: 10:53 PM\n * To change this template use File | Settings | File Templates.\n */\npublic class TaskC {\n\n int[] senior;\n\n long totalArrangements(int[] a) {\n int N = a.length;\n long[] dp = new long[1<<N];\n dp[0] = 1;\n for(int mask = 0; mask < (1<<N); mask++) {\n if(dp[mask] == 0) continue;\n\n int i = Integer.bitCount(mask);\n for(int j = 0; j < N; j++) {\n if(a[j] == -1 || a[j] == i) {\n if((mask & (1<<j)) == 0) {\n if((mask & senior[j]) == senior[j]) {\n dp[mask | (1<<j)] += dp[mask];\n }\n }\n }\n }\n }\n return dp[(1<<N) - 1];\n }\n\n void run(){\n int N = nextInt();\n long year = nextLong() - 2001;\n int M = nextInt();\n senior = new int[N];\n for(int i = 0; i < M; i++) {\n int a = nextInt() - 1;\n int b = nextInt() - 1;\n senior[b] |= (1<<a);\n }\n\n int[] ans = new int[N];\n Arrays.fill(ans, -1);\n\n for(int i = 0; i < N; i++) {\n while(true) {\n ans[i]++;\n if(ans[i] == N) {\n System.out.println(\"The times have changed\");\n return;\n }\n\n long ways = totalArrangements(ans);\n if(year < ways) {\n break;\n }\n else {\n year -= ways;\n }\n }\n }\n\n for(int x : ans) System.out.print((x + 1) + \" \");\n System.out.println();\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 TaskC().run();\n }\n}\n", "src_uid": "e9db8d048e9763cf38c584342dea9f53"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class btest9\n{\t \n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tInputReader in = new InputReader(System.in);\n\t\tOutputWriter out = new OutputWriter(System.out);\n\t\tint n=in.readInt();\n\t\tint a[]=new int[n];\n\t\tfor(int i=0;i<n;i++)a[i]=in.readInt();\n\t\tint k=in.readInt();\n\t\tArrays.sort(a);\n\t\tint lo,hi,mid;\n\t\tint fi=0;\n\t\tint ans=0;\n\t\tint max=-5;\n\t\tfor(int i=0;i<n;i++)\n\t\t{\n\t\t\tlo=i+1;hi=n-1;fi=a[i]+k;\n\t\t\twhile(lo<hi)\n\t\t\t{\n\t\t\t\tmid=lo+(hi-lo+1)/2;\n\t\t\t\tif(a[mid]>fi)hi=mid-1;\n\t\t\t\telse lo=mid;\n\t\t\t}\n\t\t\tif(lo<n&&a[lo]<=fi)ans=lo-i+1;\n\t\t\telse ans=1;\n\t\t\tif(ans>max)max=ans;\n\t\t}\n\t\tout.printLine(max);\n\t\tout.close();\n\t}\n\n\n\tprivate static 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 \n\t\tpublic int read()\n\t\t{\n\t\t\tif (numChars == -1)\n\t\t\t\tthrow new InputMismatchException();\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} catch (IOException e)\n\t\t\t\t{\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\t\tpublic int readInt()\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\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} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\t\t 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\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} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\t\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 \n\t\t\n \n\t\tpublic interface SpaceCharFilter\n\t\t{\n\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t}\n \n\tprivate static class OutputWriter\n\t{\n\t\tprivate final PrintWriter writer;\n \n\t\tpublic OutputWriter(OutputStream outputStream)\n\t\t{\n\t\t\twriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n\t\t}\n \n\t\tpublic OutputWriter(Writer writer)\n\t\t{\n\t\t\tthis.writer = new PrintWriter(writer);\n\t\t}\n \t\tpublic void print(Object... objects)\n\t\t{\n\t\t\tfor (int i = 0; i < objects.length; i++)\n\t\t\t{\n\t\t\t\tif (i != 0)\n\t\t\t\twriter.print(' ');\n\t\t\t\twriter.print(objects[i]);\n\t\t\t}\n\t\t}\n\t\t\n\t\tpublic void printf(double n)\n\t\t{\n\t\t\twriter.printf(\"%.4f%n\", n);\n\t\t}\n\t\tpublic void printLine(Object... objects)\n\t\t{\n\t\t\tprint(objects);\n\t\t\twriter.println();\n\t\t}\n \n\t\tpublic void close()\n\t\t{\n\t\t\twriter.close();\n\t\t}\n \n\t\tpublic void flush()\n\t\t{\n\t\t\twriter.flush();\n\t\t}\n \n\t}\n}\n", "src_uid": "086d07bd6f9031df09bd6a6e8fe8f25c"} {"source_code": "import java.util.*;\npublic class QAQ {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n Scanner as = new Scanner (System.in);\n Vector as1 = new Vector ();\n String qaq;\n int dd=0;\n qaq = as.next();\n \n String [] qaq1 = qaq.split(\"\");\n // System.out.println(Arrays.toString(qaq1));\n for (int i =0;i<qaq1.length;i++){\n if(qaq1[i].equalsIgnoreCase(\"A\") || qaq1[i].equalsIgnoreCase(\"Q\") ){\n as1.add(qaq1[i]);\n \n \n }\n \n \n \n }\n //System.out.println(as1);\n for (int i =0; i<as1.size();i++){\n if(as1.get(i).equals(\"Q\")){\n for (int z=i; z<as1.size();z++){\n \n if(as1.get(z).equals(\"A\")){\n for(int c=z; c<as1.size();c++){\n if(as1.get(c).equals(\"Q\")){\n dd++;\n }\n \n }\n \n }\n \n }\n \n }\n \n \n }\n System.out.println(dd);\n }\n \n \n}", "src_uid": "8aef4947322438664bd8610632fe0947"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.lang.reflect.Array;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\n/**\n * Created by Sergey on 19.09.2014.\n */\npublic class Main {\n public static void main(String[] args) {\n InputReader in = new InputReader(System.in);\n BigInteger a = new BigInteger(in.next());\n String s17 = \"100000000000000000\";\n BigInteger ost = BigInteger.valueOf(45).multiply(BigInteger.valueOf(18)).multiply(new BigInteger(s17));\n ost = ost.add(BigInteger.ONE);\n ost = ost.mod(a);\n\n BigInteger L = BigInteger.ONE;\n BigInteger R = new BigInteger(s17 + \"0\");\n\n BigInteger add = a.subtract(ost);\n add = add.mod(a);\n\n L = L.add(add);\n R = R.add(add);\n\n System.out.println(L + \" \" + R);\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}", "src_uid": "52b8d97f216ea22693bc16fadcd46dae"} {"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<T;t++){\r\n Solution sol1=new Solution(out,fs);\r\n sol1.solution(T,t);\r\n }\r\n out.flush();\r\n\r\n }\r\n\r\n\r\n public static int[] Arr(int n){\r\n int A[]=new int[n];\r\n for(int i=0;i<n;i++)A[i]=Int();\r\n return A;\r\n }\r\n public static int Int(){\r\n return fs.Int();\r\n }\r\n public static long Long(){\r\n return fs.Long();\r\n }\r\n public static String Str(){\r\n return fs.Str();\r\n }\r\n\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nclass Solution {\r\n PrintWriter out;\r\n int INF = Integer.MAX_VALUE;\r\n int NINF = Integer.MIN_VALUE;\r\n int MOD = 998244353;\r\n int mod = 1000000007;\r\n Main.FastScanner fs;\r\n\r\n\r\n public Solution(PrintWriter out, Main.FastScanner fs) {\r\n this.out = out;\r\n this.fs = fs;\r\n\r\n }\r\n\r\n\r\n public void solution(int all, int testcase) {\r\n int n = fs.Int();\r\n mod = fs.Int();\r\n\r\n long dp[][] = new long[n][n * n + 5];\r\n dp[0][0] = 1;\r\n for(int i = 1; i < n; i++) {\r\n for(int j = 0; j < dp[0].length; j++) {\r\n for(int cnt = 0; cnt <= i; cnt++){\r\n if(j - cnt >= 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 //init\r\n long fact[] = new long[501 * 501];\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 long ncr[][] = new long[501][501];\r\n ncr[0][0]=1;\r\n for (int i=1;i<ncr.length;i++) {\r\n ncr[i][0]=1;\r\n for (int j=1;j<ncr[0].length;j++) {\r\n ncr[i][j]=(ncr[i-1][j] + ncr[i-1][j-1])%mod;\r\n if(ncr[i][j] == 0)ncr[i][j] += mod;\r\n }\r\n }\r\n\r\n\r\n\r\n long res = 0;\r\n for(int i = n - 2; 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 if(com == 0) com += mod;\r\n long sum = 0;\r\n\r\n long last[] = dp[cnt - 2];\r\n long ssum = 0;\r\n long total =0;\r\n for(int j = 2; j < dp[0].length; j++) { // j == inversions\r\n total += sums[cnt - 2][j - 2] * (cnt - 1);\r\n total %= mod;\r\n if(total == 0) total += mod;\r\n\r\n sum += last[j] * total;\r\n sum %= mod;\r\n if(sum == 0) sum += mod;\r\n\r\n ssum += sums[cnt - 2][j - 2];\r\n if(j - cnt - 1 >= 0) {\r\n ssum -= sums[cnt - 2][j - cnt - 1];\r\n }\r\n ssum += mod;\r\n ssum %= mod;\r\n if(ssum == 0) ssum += mod;\r\n\r\n total -= ssum;\r\n total += mod;\r\n total %= mod;\r\n if(total == 0)total += mod;\r\n }\r\n res += sum * com;\r\n res%=mod;\r\n if(res == 0) res += mod;\r\n }\r\n out.println(res % mod);\r\n }\r\n}\r\n\r\n", "src_uid": "ae0320a57d73fab1d05f5d10fbdb9e1a"} {"source_code": "import java.util.Scanner;\npublic class abdo {\npublic static void main(String[] args){\nScanner abd = new Scanner(System.in);\n String a=abd.next();\n String s=abd.next();\n int q=a.length(),k=0,z=0;\n int w=s.length();\n char[]x=new char[q+w];\n int f=0;\n for(int i=0;i<q;i++){\n x[i]=a.charAt(i);\n if(x[i]=='|'){\n k=q-(i+1); //right\n z=q-(k+1); //left\n f++;\n }\n if(f>0)\n break;\n }\n for(int i=0;i<w;i++){\n x[i]=s.charAt(i);\n }\n// System.out.println(z+\" \"+k);\n if(k<z){\n \n if(w==z-k){\n System.out.println(a+s);\n return;\n }\n else if(w-(z-k)>0){\n if((w-(z-k))%2==0){\n for(int i=0;i<(w-(z-k))/2;i++){\n System.out.print(x[i]); \n }\n \n System.out.print(a);\n for(int i=(w-(z-k))/2;i<w;i++){\n System.out.print(x[i]);\n }\n }\n else{\n System.out.println(\"Impossible\");\n return;\n }\n }\n else{\n System.out.println(\"Impossible\");\n return;\n } \n }\n else if(z<k){\n \n if(w==k-z){\n System.out.println(s+a);\n return;\n }\n else if((w-(k-z))>0){\n if((w-(k-z))%2==0){\n for(int i=(w-(k-z))/2;i<w;i++){\n System.out.print(x[i]);\n }\n System.out.print(a);\n for(int i=0;i<(w-(k-z))/2;i++){\n System.out.print(x[i]); \n }\n }\n else{\n System.out.println(\"Impossible\");\n return;\n } \n }\n else{\n System.out.println(\"Impossible\");\n return;\n } \n \n }\n else{\n if(w%2==0){\n for(int i=0;i<(w/2);i++){\n System.out.print(x[i]); \n }\n System.out.print(a);\n for(int i=(w/2);i<w;i++){\n System.out.print(x[i]); \n }\n }\n else{\n System.out.println(\"Impossible\");\n return;\n } \n }\n}}", "src_uid": "917f173b8523ddd38925238e5d2089b9"} {"source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.BufferedOutputStream;\nimport java.util.StringTokenizer;\nimport java.io.Writer;\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 amalev\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 FastWriter out = new FastWriter(outputStream);\n TaskE solver = new TaskE();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskE {\n TaskE.GCDResult gcdExt(final long a, final long b) {\n TaskE.GCDResult result;\n if (a == 0) {\n result = new TaskE.GCDResult();\n result.d = b;\n result.x = 0;\n result.y = 1;\n\n return result;\n }\n result = gcdExt(b % a, a);\n long t = result.x;\n result.x = result.y - (b / a) * t;\n result.y = t;\n\n return result;\n }\n\n public void solve(int testNumber, FastScanner in, FastWriter out) {\n long n = in.nextInt();\n long m = in.nextInt();\n long x0 = in.nextInt();\n long y0 = in.nextInt();\n int vx = in.nextInt();\n int vy = in.nextInt();\n\n long x;\n long y;\n if (vx == 0 || vy == 0) {\n\n if (x0 == 0) {\n x = 0;\n if (vx != 0) {\n out.println(-1);\n return;\n }\n if (vy > 0) {\n y = m;\n } else {\n y = 0;\n }\n } else if (x0 == n) {\n x = n;\n if (vx != 0) {\n out.println(-1);\n return;\n }\n if (vy > 0) {\n y = m;\n } else {\n y = 0;\n }\n } else if (y0 == 0) {\n y = 0;\n if (vy != 0) {\n out.println(-1);\n return;\n }\n if (vx > 0) {\n x = n;\n } else {\n x = 0;\n }\n } else if (y0 == m) {\n y = m;\n if (vy != 0) {\n out.println(-1);\n return;\n }\n if (vx > 0) {\n x = n;\n } else {\n x = 0;\n }\n } else {\n out.println(-1);\n return;\n }\n\n out.println(x + \" \" + y);\n } else {\n\n if (vx < 0) x0 = n - x0;\n if (vy < 0) y0 = m - y0;\n\n //vx = 1, vy = 1\n long c = x0 - y0;\n TaskE.GCDResult g = gcdExt(n, m);\n if (c % g.d == 0) {\n c /= g.d;\n\n x = g.x * c;\n y = g.y * c;\n\n long dx = m / g.d;\n long dy = n / g.d;\n if (x < 0) {\n long d = (-x) / dx;\n if (-x % dx > 0) d++;\n\n x += d * dx;\n y -= d * dy;\n }\n\n if (y > 0) {\n long d = y / dy;\n if (y % dy > 0) d++;\n\n x += d * dx;\n y -= d * dy;\n }\n if (x > 0 && y < 0) {\n long d1 = x / dx;\n long d2 = -y / dy;\n long d = Math.min(d1, d2);\n if (d > 0) {\n x += d * dx;\n y -= d * dy;\n }\n }\n\n if (x == 0 && y == 0) {\n x += dx;\n y -= dy;\n }\n\n\n x = n * (x % 2);\n y = m * (-y % 2);\n\n if (vx < 0) x = n - x;\n if (vy < 0) y = m - y;\n out.println(x + \" \" + y);\n } else {\n out.println(-1);\n }\n }\n }\n\n static class GCDResult {\n long x;\n long y;\n long d;\n\n\n public String toString() {\n return \"GCDResult{\" +\n \"x=\" + x +\n \", y=\" + y +\n \", d=\" + d +\n '}';\n }\n\n }\n\n }\n\n static class FastScanner {\n static final int BUFFER_SIZE = 1 << 18;\n final BufferedReader input;\n StringTokenizer buffer;\n\n public FastScanner(InputStream inputStream) {\n input = new BufferedReader(new InputStreamReader(inputStream), BUFFER_SIZE);\n }\n\n private String readToken() {\n try {\n if (buffer == null || !buffer.hasMoreTokens()) {\n buffer = new StringTokenizer(input.readLine());\n }\n return buffer.nextToken();\n } catch (IOException ex) {\n throw new RuntimeException(ex);\n }\n }\n\n public int nextInt() {\n return Integer.parseInt(readToken());\n }\n\n }\n\n static class FastWriter extends PrintWriter {\n static final int BUFFER_SIZE = 1 << 18;\n\n public FastWriter(OutputStream out) {\n super(new BufferedOutputStream(out, BUFFER_SIZE));\n }\n\n public FastWriter(Writer out) {\n super(out);\n }\n\n public void close() {\n super.close();\n }\n\n }\n}\n\n", "src_uid": "6c4ddc688c5aab1432e7328d27c4d8ee"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.Arrays;\n\npublic class Getting_an_A {\n public static void main(String[] args) throws IOException {\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n double n=Double.parseDouble(br.readLine());\n String str[]=br.readLine().split(\" \");\n double a[]=new double[(int) n];\n double sum=0;\n for(int i=0;i<n;i++) {\n a[i] = Double.parseDouble(str[i]);\n sum+=a[i];\n }\n Arrays.sort(a);\n long count=0;\n if(sum/n>=4.5)\n System.out.println(\"0\");\n else\n {\n long value=round((n*4.5)-sum);\n for(int i = 0; i<n; i++)\n {\n if(value<=0)\n break;\n long diff= (long) (5-a[i]);\n if(diff>0)\n {\n value-=diff;\n count++;\n }\n\n }\n System.out.println(count);\n }\n }\n private static int round(double d) {\n double dAbs = Math.abs(d);\n int i = (int) dAbs;\n double result = dAbs - (double) i;\n if (result < 0.5) {\n return d < 0 ? -i : i;\n } else {\n return d < 0 ? -(i + 1) : i + 1;\n }\n }\n}\n", "src_uid": "715608282b27a0a25b66f08574a6d5bd"} {"source_code": "import java.io.*;\n\npublic class IlyaBank {\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\tString line = in.readLine();\n\t\tint num = Integer.parseInt(line);\n\t\tif (Integer.parseInt(line) < 0) {\n\t\t\tif (line.charAt(line.length() - 1) >= line.charAt(line.length() - 2)) {\n\t\t\t\tnum /= 10;\n\t\t\t} else {\n\t\t\t\tint add = Character.getNumericValue(line.charAt(line.length() - 1));\n\t\t\t\tnum /= 100;\n\t\t\t\tnum *= 10;\n\t\t\t\tnum -= add;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(num);\n\t}\n}\n", "src_uid": "4b0a8798a6d53351226d4f06e3356b1e"} {"source_code": "import java.io.*;\nimport java.util.*;\n\n/**\n * Created by vikas.k on 14/03/17.\n */\npublic class CF086C {\n public static PrintWriter out;\n public static FastScanner in;\n private List<Integer> primes;\n\n private void solve(){\n int lo = in.nextInt();\n int hi = in.nextInt();\n\n int limit = (int)Math.sqrt(hi);\n boolean[] mrk = simpleSieve(limit);\n primes = new ArrayList<>();\n for(int i=2;i<mrk.length;i++){\n if(mrk[i]) primes.add(i);\n }\n int cnt = 0;\n if(2 >= lo && 2<=hi) cnt++;\n if(lo<=limit){\n int k = (lo-1)%4 == 0 ? (lo-1)/4 : ((lo-1)/4 + 1);\n int st = 4*k+1;\n while (st<=limit){\n if(mrk[st]) cnt++;\n st = 4*(++k)+1;\n }\n lo = limit+1;\n }\n\n for(;lo+limit<=hi;lo+=limit+1){\n mrk = sieve(lo,lo+limit);\n int k = (lo-1)%4 == 0 ? (lo-1)/4 : ((lo-1)/4 + 1);\n int st = 4*k+1;\n while (st<=lo+limit){\n if(mrk[st-lo]) cnt++;\n st = 4*(++k)+1;\n }\n }\n mrk = sieve(lo,hi);\n int k = (lo-1)%4 == 0 ? (lo-1)/4 : ((lo-1)/4 + 1);\n int st = 4*k+1;\n while (st<=hi){\n if(mrk[st-lo]) cnt++;\n st = 4*(++k)+1;\n }\n out.print(cnt);\n }\n\n private boolean[] sieve(int lo,int hi){\n boolean[] ret = new boolean[hi-lo+1];\n Arrays.fill(ret,true);\n\n for (int p:primes){\n int st = lo%p == 0 ? lo : ((lo/p)+1)*p;\n for(int i = st;i<=hi;i+=p){\n ret[i-lo]= false;\n }\n }\n return ret;\n }\n private boolean[] simpleSieve(int n){\n boolean[] ret = new boolean[n+1];\n Arrays.fill(ret,true);\n ret[0] = false;\n ret[1] = false;\n for(int i=2+2;i<=n;i+=2){\n ret[i] = false;\n }\n\n for(int i=3;i*i<=n;i+=2){\n if(ret[i]){\n for(int j=i*2;j<=n;j+=i){\n ret[j] = false;\n }\n }\n }\n return ret;\n }\n\n private void runIO(){\n in = new FastScanner();\n out = new PrintWriter(new BufferedOutputStream(System.out));\n solve();\n out.close();\n }\n private static class FastScanner {\n BufferedReader bufferedReader;\n StringTokenizer stringTokenizer;\n\n private FastScanner(){\n bufferedReader = new BufferedReader(new InputStreamReader(System.in));\n }\n\n private String next(){\n if(stringTokenizer == null || !stringTokenizer.hasMoreElements()){\n try {\n stringTokenizer = new StringTokenizer(bufferedReader.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return stringTokenizer.nextToken();\n }\n\n private int nextInt(){\n return Integer.parseInt(next());\n }\n private long nextLong(){\n return Long.parseLong(next());\n }\n private String nextLine(){\n String ret= \"\";\n try {\n ret= bufferedReader.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return ret;\n }\n }\n\n public static void main(String[] args) {\n new CF086C().runIO();\n }\n}\n", "src_uid": "55a83526c10126ac3a6e6e5154b120d0"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n static void solve() throws IOException {\n int n = ni1();\n rl();\n int a[] = new int[n];\n int b[] = new int[n];\n int c[] = new int[n];\n for (int i = 0; i < n; i++) a[i] = b[i] = ni2();\n Arrays.sort(b);\n for (int i = 0; i < n; i++) {\n int k = Arrays.binarySearch(b, a[i]);\n c[i] = b[(k + 1) % n];\n }\n for (int i = 0; i < n; i++) ans.append(c[i]).append(\" \");\n output.write(ans.toString());\n output.flush();\n output.close();\n }\n\n public static void main(String[] args) throws IOException {\n new Main().solve();\n }\n\n static BufferedReader input = new BufferedReader(new InputStreamReader(System.in));\n static BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out));\n static StringBuilder ans = new StringBuilder();\n static String line;\n static StringTokenizer stringTokenizer;\n\n static int ni1() throws IOException {\n return Integer.parseInt(input.readLine());\n }\n\n static int ni2() throws IOException {\n return Integer.parseInt(stringTokenizer.nextToken());\n }\n\n static long nl1() throws IOException {\n return Long.parseLong(input.readLine());\n }\n\n static long nl2() {\n return Long.parseLong(stringTokenizer.nextToken());\n }\n\n static void rl() throws IOException {\n stringTokenizer = new StringTokenizer(input.readLine());\n }\n}\n", "src_uid": "e314642ca1f82be8f223e2eba00b5531"} {"source_code": "\nimport java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class Problem931B {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tout=new PrintWriter (new BufferedOutputStream(System.out));\n\t\tFastReader s=new FastReader();\n\t\tint n=s.nextInt();\n\t\tint a=s.nextInt();\n\t\tint b=s.nextInt();\n\t\tint temp1=Integer.max(a, b);\n\t\tint temp2=Integer.min(a, b);\n\t\ta=temp2;\n\t\tb=temp1;\n\t\tint count=0;\n\t\tint rounds=0;\n\t\tint temp=n;\n\t\twhile(temp>0) {\n\t\t\ttemp=temp/2;\n\t\t\trounds++;\n\t\t}\n\t\trounds--;\n\t\tint start=0;\n\t\tint end=n;\n\t\twhile(end>start) {\n\t\t\tint mid=(end+start)/2;\n\t\t\tif(mid>=a && mid<b) {\n\t\t\t\tbreak;\n\t\t\t}else if(mid>=a && mid>=b){\n\t\t\t\tend=mid;\n\t\t\t\tcount++;\n\t\t\t}else if(mid<a && mid<b) {\n\t\t\t\tstart=mid;\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\t\tif(count==0) {\n\t\t\tout.println(\"Final!\");\n\t\t\tout.close();\n\t\t\treturn;\n\t\t}\n\t\tout.println(rounds-count);\n\t\tout.close();\n\t}\n\t\n\tpublic static PrintWriter out;\n\n\tpublic static class FastReader {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\t\t//it reads the data about the specified point and divide the data about it ,it is quite fast\n\t\t//than using direct \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.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\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());//converts string to integer\n\t\t}\n\n\t\tdouble nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t\tlong nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tString nextLine() {\n\t\t\tString str = \"\";\n\t\t\ttry {\n\t\t\t\tstr = br.readLine();\n\t\t\t} catch (Exception 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", "src_uid": "a753bfa7bde157e108f34a28240f441f"} {"source_code": "import java.io.*;\npublic class round29B {\n\n public static void main(String[] args)throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n String [] use = br.readLine().split(\" \");\n int totDist = Integer.parseInt(use[0]);\n int trafficDist = Integer.parseInt(use[1]);\n int speed = Integer.parseInt(use[2]);\n int green = Integer.parseInt(use[3]);\n int red = Integer.parseInt(use[4]);\n double t1 = (double)trafficDist / (double)speed;\n double cur = green;\n boolean f = true;\n while(t1 >= cur){\n cur += (f == true) ? red : green;\n f = !f;\n }\n t1 += f == false ? (cur - t1) : 0;\n t1 += ((double)(totDist - trafficDist) / (double)speed);\n System.out.println(t1);\n }\n}\n", "src_uid": "e4a4affb439365c843c9f9828d81b42c"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n//\tstatic Scanner in; static int next() throws Exception {return in.nextInt();};\n//\tstatic StreamTokenizer in; static int next() throws Exception {in.nextToken(); return (int) in.nval;}\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic int n = 1000;\n\tstatic boolean[][] win = new boolean[n][n];\n\n\tstatic HashMap<String, Integer> map;\n\n\tstatic boolean go(long a, long b) {\n//\t\tSystem.out.println(a + \" \" + b);\n\t\t//if (a < n && b < n) return win[(int)a][(int)b];\n\t\tif (a == 0 || b == 0) return false;\n\t\t\n\t\tif (a > b) {\n\t\t\tlong temp = a;\n\t\t\ta = b;\n\t\t\tb = temp;\n\t\t}\n\n\t\tlong c = b % a;\n\n\t\tboolean w1 = go(c, a);\n\t\tif (!w1) return true;\n\t\t\n\t\tlong d = b/a;\n\n\t\tif (a % 2 == 1) return d % 2 == 0;\n\n\t\tlong e = d % (a + 1);\n\t\treturn e % 2 == 0;\n\t}\n\n\tstatic long gcd(long a, long b) {return a > b ? gcd(b, a) : a == 0 ? b : gcd(b % a, a);}\n\n\tstatic int rand() {return (int)(Math.random() * 1e9);}\n\n\tpublic static void main(String[] args) throws Exception {\n//\t\tin = new Scanner(System.in);\n//\t\tin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\n\t\t\n\n/*\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < n; j++) if (i != 0 || j != 0) if (!win[i][j]) {\n\t\t\t\tif (i < j) for (int t = i + j; t < n; t += j) win[t][j] = true;\n\t\t\t\telse for (int t = i + j; t < n; t += i) win[i][t] = true;\n\n\t\t\t\tif (j > 1) for (int t = j; i + t < n; t *= j) win[i + t][j] = true;\n\t\t\t\telse if (j > 0 && i + j < n) win[i + j][j] = true;\n\t\t\t\tif (i > 1) for (int t = i; j + t < n; t *= i) win[i][j + t] = true;\n\t\t\t\telse if (i > 0 && i + j < n) win[i][j + i] = true;\n\t\t\t}\n\t \t}*/\n\n/*\t \tfor (int i = 0; i < 50; i++) {\n\t \t\tfor (int j = 0; j < 50; j++) out.print(win[i][j] ? \"1 \" : \"0 \");\n\t \t\tout.println();\n\t \t}\n\t \tint count = 0;\n\t \tfor (int i = 1; i < n; i++) for (int j = 1; j < n; j++) if (!win[i][j]) count++;\n\t \tout.println(count);*/\n\n\t\tint tests = Integer.parseInt(in.readLine());\n\t\tfor (int test = 0; test < tests; test++) {\n\t\t\tmap = new HashMap<String, Integer>();\n\t\t\tString[] s = in.readLine().split(\" \");\n\t\t\tout.println(go(Long.parseLong(s[0]), Long.parseLong(s[1])) ? \"First\" : \"Second\");\n\t\t}\n\t\t\n\t\tout.close();\n\t}\n}", "src_uid": "5f5b320c7f314bd06c0d2a9eb311de6c"} {"source_code": "import java.util.LinkedList;\nimport java.util.Queue;\nimport java.util.Scanner;\n\npublic class ddd {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint t = sc.nextInt();\n\n\t\tchar[] here = new char[n];\n\t\tchar[] current = new char[n];\n\t\tchar[] result = new char[n];\n\t\t;\n\t\tint te = n - 2;\n\t\tString temp = sc.next();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\there[i] = temp.charAt(i);\n\t\t}\n\n\t\tint count = 0;\n\n\t\twhile (count != t) {\n\t\t\tif (count == 0)\n\t\t\t\tcurrent = here;\n\n\t\t\telse {\n\t\t\t\tcurrent = result;\n\t\t\t\tresult = new char[n];\n\t\t\t}\n\t\t\tint i ;\n\t\t\tfor ( i = 0; i < n - 1; i++) {\n\t\t\t\tchar c = current[i];\n\t\t\t\tchar b = current[i + 1];\n\t\t\t\tif (c == 'B')\n\t\t\t\t\tif (b == 'G') {\n\t\t\t\t\t\tresult[i] = 'G';\n\t\t\t\t\t\tresult[i + 1] = 'B';\n\t\t\t\t\t\ti++;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresult[i] = 'B';\n\t\t\t\t\t\tresult[i + 1] = 'B';\n\t\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tresult[i] = c;\n\t\t\t\t\tresult[i + 1] = b;\n\n\t\t\t\t\tif (b == 'G')\n\t\t\t\t\t\ti++;\n\t\t\t\t\t\t\n\t\t\t\t}\n\n\t\t\t}\n\t\t\tif(i==n-1){\n\t\t\t\tresult[n-1]=current[n-1];\n\t\t\t\t\n\t\t\t}\n\t\t\tif (i<n-1) {\n\t\t\t\tchar c = result[te];\n\t\t\t\tchar b = current[n - 1];\n\t\t\t\tSystem.out.println(c);\n\t\t\t\tSystem.out.println(b);\n\t\t\t\tif (c == 'B')\n\t\t\t\t\tif (b == 'G') {\n\t\t\t\t\t\tresult[te] = 'G';\n\t\t\t\t\t\tresult[n - 1] = 'B';\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresult[te] = 'B';\n\t\t\t\t\t\tresult[n - 1] = 'B';\n\t\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tresult[te] = c;\n\t\t\t\t\tresult[n - 1] = b;\n\t\t\t\t}\n\t\t\t}\n\t\t\tcount++;\n\t\t}\n\t\t\n\t\tSystem.out.println(result);\n\t\t\n\t}\n}\n", "src_uid": "964ed316c6e6715120039b0219cc653a"} {"source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class P256D {\n\n final int [][] r = {{0},\n {2, 1},\n {32, 30, 80, 109},\n {6824, 59808, 147224, 415870, 1757896, 1897056, 4898872, 7593125},\n {776830421, 290516100, 746623577, 293783147, 33900006, 735127505, 565460332, 428982705,\n 472062098, 161873957, 117354594, 515619293, 578944191, 312106242, 569389279, 391464593},\n {261086313, 584837659, 683961846, 468868529, 211593382, 736955478, 229471758, 157617135,\n 398169441, 360252438, 629394768, 264125799, 647490480, 342079395, 391579767, 225200475,\n 486011304, 513156108, 628771752, 132906648, 142138221, 20119449, 444199674, 195188679,\n 387329805, 44684703, 651912135, 737154512, 612549793, 519860281, 186175544, 212568440},\n {240805271, 239509872, 581127897, 6511239, 156126222, 509425833, 672407328, 366667722,\n 459185405, 509737025, 554790222, 165216555, 703150560, 74806569, 398730015, 383350905,\n 506108358, 51326142, 298053147, 104256117, 391428765, 374020479, 206607807, 87664059,\n 275899176, 56407680, 551553401, 448939463, 582889860, 129676638, 226078251, 135769095,\n 61292868, 578972226, 190181628, 390739055, 184587732, 446575689, 732674124, 232198470,\n 676760679, 352474101, 611444862, 575661807, 628905585, 320813094, 522840969, 469781928,\n 156006018, 554473341, 239654268, 643714911, 433540170, 199307003, 496385218, 291740751,\n 67309914, 370826673, 202356819, 279421821, 421203111, 63744786, 520987612, 550671827},\n {482164403, 768209115, 462063756, 154906374, 36099042, 341766705, 678182556, 621882744,\n 478771358, 231881111, 175889805, 243630450, 168908523, 671961765, 55761813, 652682670,\n 773939082, 517628076, 756201264, 124604900, 750976272, 498253248, 676047609, 137170026,\n 705610017, 495032139, 561797418, 703097347, 500815609, 95984586, 739707108, 265613565,\n 387099846, 777331779, 594676173, 591219559, 407997044, 208947235, 93337440, 478908360,\n 685013007, 487033953, 671903001, 39521181, 738490312, 33785059, 465470131, 310453920,\n 54648783, 346831137, 427694175, 474743430, 705296781, 435828036, 429824745, 663532359,\n 261388683, 244690731, 533997135, 596108961, 506813013, 371892402, 590145264, 104733162,\n 143420103, 654339672, 700348950, 685038942, 578826927, 286484229, 501639192, 434962491,\n 299270097, 27702486, 335375775, 111746817, 565603164, 294926121, 676063665, 735862995,\n 710035809, 437011960, 668528077, 138765186, 508213986, 615036450, 353784942, 624827616,\n 343900011, 241289776, 52410890, 72018835, 352406796, 415705878, 4802637, 376367145,\n 65589678, 333633477, 341834527, 303717460, 282387700, 42951006, 254706039, 423048528,\n 526429710, 68131467, 669954708, 12787348, 500636381, 317959019, 479433192, 657133515,\n 416259390, 610216692, 340129188, 44594256, 257373347, 138718678, 530767740, 292922628,\n 37220268, 605295159, 480722613, 458170419, 30540300, 487159055, 232966794, 149150650},\n {412133651, 386543325, 139952108, 289303402, 102404925, 317067177, 396414708, 80515854,\n 663739304, 317300809, 228877044, 493725043, 715317967, 490300965, 315527373, 743539734,\n 488329191, 553627998, 533025234, 242583957, 706116537, 614109258, 645447222, 523195911,\n 492109128, 722623041, 111085128, 766395126, 654378921, 691964847, 496688157, 399056049,\n 654363234, 102052314, 191720088, 473910948, 259736526, 332840025, 388047555, 665791056,\n 627111387, 139696515, 441456687, 443032569, 283264821, 771641703, 452641455, 511306362,\n 117572859, 127701891, 721298331, 176520078, 357242229, 611296308, 696994956, 405628839,\n 429224274, 465336054, 695091546, 689828796, 574648641, 351220905, 507964023, 675326610,\n 517248963, 453528621, 220301928, 494463186, 681789969, 339589656, 44524053, 417125457,\n 339589404, 747135963, 341780733, 734158215, 396817281, 21997836, 5728464, 147611205,\n 456248898, 714128667, 377654949, 3862068, 128418948, 589390074, 304947090, 11703825,\n 228266073, 127304142, 429215724, 361541124, 521572968, 468358191, 341231688, 65323503,\n 613778508, 15985323, 291661029, 410970006, 591638112, 349541550, 89967528, 224922159,\n 361094166, 584206074, 640051812, 324264456, 652625388, 693768537, 11740617, 309238398,\n 211085469, 194905872, 639416484, 110110707, 296645895, 748118511, 131177718, 511142751,\n 775975599, 421403409, 475528473, 434685258, 1768977, 80301375, 708023862, 569195676,\n 56238084, 632887668, 88089750, 631539342, 396695565, 38780154, 695798271, 469819224,\n 439587099, 69045921, 682966116, 112310856, 64943298, 534475872, 40215357, 389728458,\n 286368453, 736006257, 501181650, 54829908, 603489402, 338032656, 512182818, 627500097,\n 462674016, 3103092, 157324491, 43978329, 596818971, 259025598, 9088632, 91991781,\n 577291428, 211245489, 429471231, 142626330, 172560633, 510907446, 444609585, 758102058,\n 375112647, 744786693, 276174402, 19259856, 233672418, 745389414, 225772848, 23385663,\n 324290610, 519804558, 120337812, 402578568, 360676008, 450089262, 551043738, 337388940,\n 512108856, 28879011, 690040638, 106017282, 558262341, 99972432, 608226003, 612152037,\n 42414435, 776201013, 39580443, 518796945, 494437752, 583194366, 723936555, 415359657,\n 309569589, 751104774, 166684527, 249229170, 353120823, 130668327, 753823584, 580966092,\n 561963717, 543672234, 393846327, 586278000, 327398400, 278403867, 156455586, 363920382,\n 190245195, 290039148, 547014447, 466218648, 146037150, 585462906, 666008595, 691786683,\n 374707494, 622498779, 231158277, 685740951, 115612245, 681825249, 545555745, 551718468,\n 277206615, 640171035, 757727334, 195193908, 658656684, 457760646, 225925875, 505761984,\n 18685233, 506832921, 112511021, 396846646, 290147622, 113924623, 669986155, 336008070,\n 63611061, 238586775, 119956662, 616557739, 772784623, 334527774, 410403148, 51933421}\n };\n\n @SuppressWarnings(\"unchecked\")\n public void run() throws Exception {\n synchronized (this) { this.wait(900); }\n println(r[(int)(Math.log(nextInt()) / Math.log(2))][nextInt() - 1]);\n }\n\n public static void main(String... args) throws Exception {\n br = new BufferedReader(new InputStreamReader(System.in));\n pw = new PrintWriter(new BufferedOutputStream(System.out));\n new P256D().run();\n br.close();\n pw.close();\n }\n\n static BufferedReader br;\n static PrintWriter pw;\n StringTokenizer stok;\n\n String nextToken() throws IOException {\n while (stok == null || !stok.hasMoreTokens()) {\n String s = br.readLine();\n if (s == null) { return null; }\n stok = new StringTokenizer(s);\n }\n return stok.nextToken();\n }\n\n void print(byte b) { print(\"\" + b); }\n void print(int i) { print(\"\" + i); }\n void print(long l) { print(\"\" + l); }\n void print(double d) { print(\"\" + d); }\n void print(char c) { print(\"\" + c); }\n void print(Object o) {\n if (o instanceof int[]) { print(Arrays.toString((int [])o));\n } else if (o instanceof long[]) { print(Arrays.toString((long [])o));\n } else if (o instanceof char[]) { print(Arrays.toString((char [])o));\n } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));\n } else if (o instanceof short[]) { print(Arrays.toString((short [])o));\n } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));\n } else if (o instanceof float[]) { print(Arrays.toString((float [])o));\n } else if (o instanceof double[]) { print(Arrays.toString((double [])o));\n } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));\n } else { print(\"\" + o); }\n }\n void print(String s) { pw.print(s); }\n void println() { println(\"\"); }\n void println(byte b) { println(\"\" + b); }\n void println(int i) { println(\"\" + i); }\n void println(long l) { println(\"\" + l); }\n void println(double d) { println(\"\" + d); }\n void println(char c) { println(\"\" + c); }\n void println(Object o) { print(o); println(\"\"); }\n void println(String s) { pw.println(s); }\n int nextInt() throws IOException { return Integer.parseInt(nextToken()); }\n long nextLong() throws IOException { return Long.parseLong(nextToken()); }\n double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }\n char nextChar() throws IOException { return (char) (br.read()); }\n String next() throws IOException { return nextToken(); }\n String nextLine() throws IOException { return br.readLine(); }\n int [] readInt(int size) throws IOException {\n int [] array = new int [size];\n for (int i = 0; i < size; i++) { array[i] = nextInt(); }\n return array;\n }\n long [] readLong(int size) throws IOException {\n long [] array = new long [size];\n for (int i = 0; i < size; i++) { array[i] = nextLong(); }\n return array;\n }\n double [] readDouble(int size) throws IOException {\n double [] array = new double [size];\n for (int i = 0; i < size; i++) { array[i] = nextDouble(); }\n return array;\n }\n String [] readLines(int size) throws IOException {\n String [] array = new String [size];\n for (int i = 0; i < size; i++) { array[i] = nextLine(); }\n return array;\n }\n}", "src_uid": "cfe19131644e5925e32084a581e23286"} {"source_code": "/*\n Author: Anthony Ngene\n Created: 24/08/2020 - 05:51\n*/\n\nimport java.io.*;\nimport java.util.*;\n\npublic class A {\n// It is only a fool that goes to dinner with the devil and fails to use a long spoon. - African Proverb\n public static void main(String[] args) throws IOException {\n in = new FastScanner();\n\n int n = in.intNext();\n int[] arr = in.nextIntArray(n);\n\n HashSet<Integer> seen = new HashSet<>();\n List<Integer> unique = new ArrayList<>();\n for (int i = n - 1; i >= 0; i--) {\n if (!seen.contains(arr[i])) {\n seen.add(arr[i]);\n unique.add(arr[i]);\n }\n }\n out.println(unique.size());\n for (int i = unique.size()-1; i >= 0; i--) {\n out.p(unique.get(i)).p(\" \");\n }\n out.close();\n }\n\n\n// checks: 1. edge cases 2. overflow 3. possible errors (e.g 1/0, arr[out]) 4. time/space complexity\n// Generated Code Below:\nprivate static final FastWriter out = new FastWriter();\nprivate static FastScanner in;\nstatic ArrayList<Integer>[] adj;\nprivate static long e97 = (long)1e9 + 7;\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) { out.append(Arrays.toString(arr)).append(\"\\n\"); }\n public void println(int[] arr) { out.append(Arrays.toString(arr)).append(\"\\n\"); }\n public void println(char[] arr) { out.append(Arrays.toString(arr)).append(\"\\n\"); }\n public void println(double[] arr) { out.append(Arrays.toString(arr)).append(\"\\n\"); }\n public void println(boolean[] arr) { out.append(Arrays.toString(arr)).append(\"\\n\"); }\n public <T>void println(T[] arr) { out.append(Arrays.toString(arr)).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 <T>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<Integer>[] getAdj(int n) {\n ArrayList<Integer>[] adj = new ArrayList[n + 1];\n for (int i = 1; i <= n; i++) adj[i] = new ArrayList<>();\n return adj;\n }\n public ArrayList<Integer>[] adjacencyList(int nodes, int edges) throws IOException {\n return adjacencyList(nodes, edges, false);\n }\n public ArrayList<Integer>[] 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}\n\n}\n", "src_uid": "1b9d3dfcc2353eac20b84c75c27fab5a"} {"source_code": "\nimport java.util.*;\n\npublic class NonSquareEquation {\n\n public static int sum(long x) {\n int ret = 0;\n while (x != 0) {\n ret += x % 10;\n x /= 10;\n }\n return ret;\n }\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n long n = in.nextLong();\n for (int i = 1; i <= 90; i++) {\n double x = ((-1 * i) + (Math.sqrt(i * i - (-4 * n))));\n if (x > 0 && x % 2 == 0) {\n x /= 2;\n long x2 = (long) x;\n int sum = sum((long) x);\n long tmp = x2 * x2 + i * x2;\n if (tmp == n && i == sum) {\n System.out.println(x2);\n return;\n }\n\n }\n }\n System.out.println(\"-1\");\n }\n}", "src_uid": "e1070ad4383f27399d31b8d0e87def59"} {"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 grolegor\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n Scanner in = new Scanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskA solver = new TaskA();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskA {\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n int n = in.nextInt();\n int k = in.nextInt();\n int[] a = new int[n];\n for (int i = 0; i < n; i++) {\n a[i] = in.nextInt();\n }\n int max = 0;\n for (int b = 0; b < k; b++) {\n int sum = 0;\n for (int i = 0; i < n; i++) {\n if ((i + b) % k != 0) {\n sum += a[i];\n }\n }\n max = Math.max(max, Math.abs(sum));\n }\n out.println(max);\n }\n\n }\n}\n\n", "src_uid": "6119258322e06fa6146e592c63313df3"} {"source_code": "//package srm304;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.HashSet;\nimport java.util.LinkedList;\n\npublic class SoldierAndCards {\n\n static class Card {\n int number;\n\n public Card(int number) {\n this.number = number;\n }\n\n @Override\n public String toString() {\n return String.valueOf(number);\n }\n }\n\n public static void main(String[] args) throws NumberFormatException, IOException {\n\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n int n = Integer.parseInt(br.readLine());\n\n LinkedList<Card> playerOne = new LinkedList<Card>();\n LinkedList<Card> playerTwo = new LinkedList<Card>();\n\n String[] parts = br.readLine().split(\" \");\n for (int i = 1; i < parts.length; i++) {\n playerOne.add(new Card(Integer.parseInt(parts[i])));\n }\n\n parts = br.readLine().split(\" \");\n for (int i = 1; i < parts.length; i++) {\n playerTwo.add(new Card(Integer.parseInt(parts[i])));\n }\n\n HashSet<String> visited = new HashSet<String>();\n\n StringBuilder sb = new StringBuilder();\n for (Card c : playerOne)\n sb.append(c.toString() + \" \");\n sb.append(\"\\n\");\n for (Card c : playerTwo)\n sb.append(c.toString() + \" \");\n visited.add(sb.toString());\n\n int counter = 0;\n while (playerOne.size()>0 && playerTwo.size()>0) {\n counter++;\n Card top1 = playerOne.poll();\n Card top2 = playerTwo.poll();\n\n if (top1.number > top2.number) {\n playerOne.add(top2);\n playerOne.add(top1);\n } else {\n playerTwo.add(top1);\n playerTwo.add(top2);\n }\n\n sb = new StringBuilder();\n for (Card c : playerOne)\n sb.append(c.toString() + \" \");\n sb.append(\"\\n\");\n for (Card c : playerTwo)\n sb.append(c.toString() + \" \");\n\n if (visited.contains(sb.toString())) {\n break;\n }\n visited.add(sb.toString());\n\n }\n\n if (playerOne.size() == 0) {\n System.out.println(counter + \" \" + 2);\n return;\n }\n if (playerTwo.size() == 0) {\n System.out.println(counter + \" \" + 1);\n return;\n }\n System.out.println(-1);\n }\n\n}\n", "src_uid": "f587b1867754e6958c3d7e0fe368ec6e"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n public static void main(String[] args) throws IOException {\n Scanner sc = new Scanner();\n PrintWriter out = new PrintWriter(System.out);\n int n = sc.nextInt();\n int[] fib = new int[n + 10];\n fib[1] = 1;\n fib[2] = 1;\n for (int i = 3; i <= n; i++)\n fib[i] = add(fib[i - 1], fib[i - 2]);\n int den = modPow(2, n);\n out.println(mult(fib[n], modPow(den, mod - 2)));\n out.flush();\n out.close();\n }\n\n static final int mod = 998244353;\n\n static int add(int a, int b) {\n long c = a + b;\n if (c >= mod) c -= mod;\n if (c < 0) c += mod;\n return (int) c;\n }\n\n static int mult(long a, int b) {\n return (int) (a * b % mod);\n }\n\n static int modPow(int b, int e) {\n int res = 1;\n while (e > 0) {\n if ((e & 1) == 1) res = mult(res, b);\n b = mult(b, b);\n e >>= 1;\n }\n return res;\n }\n\n\n static class Scanner {\n StringTokenizer st;\n BufferedReader br;\n\n public Scanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n public Scanner(String s) throws FileNotFoundException {\n br = new BufferedReader(new FileReader(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 int[] nextIntArray(int n) throws IOException {\n int[] ans = new int[n];\n for (int i = 0; i < n; i++)\n ans[i] = nextInt();\n return ans;\n }\n\n public Integer[] nextIntegerArray(int n) throws IOException {\n Integer[] ans = new Integer[n];\n for (int i = 0; i < n; i++)\n ans[i] = nextInt();\n return ans;\n }\n\n public char nextChar() throws IOException {\n return next().charAt(0);\n }\n\n public long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n public 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\n }\n}", "src_uid": "cec37432956bb0a1ce62a0188fe2d805"} {"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//package codeforce;\n\nimport java.util.Scanner;\n\n/**\n *\n * @author a\n */\npublic class Number7 {\n public static void main(String[] args) {\n Scanner l=new Scanner (System.in);\n int B=0;\n int arr[]=new int [8];\n for (int i = 0; i <8; i++) {\n arr[i]=0;\n }\n for (int i = 0; i < 8; i++) {\n String ch=l.next();\n int c=0;\n for (int j = 0; j < 8; j++) {\n if(ch.charAt(j)=='B'){\n c++;\n arr[j]++;\n }\n \n if(c==8) \n B++;\n \n }\n }\n \n if(B!=8)\n for (int i = 0; i <8; i++) {\n if(arr[i]==8)\n B++;\n \n } \n System.out.println(B);\n \n }\n}\n", "src_uid": "8b6ae2190413b23f47e2958a7d4e7bc0"} {"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 B_Round_144_Div1 {\n\n\tpublic static long MOD = 1000000007;\n\tstatic long[][] dp;\n\tstatic long[][]pre;\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\tlong m = in.nextLong();\n\t\tint k = in.nextInt();\n\t\tlong[][] c = new long[101][101];\n\t\tc[0][0] = 1;\n\n\t\tfor (int i = 1; i < 101; i++) {\n\t\t\tc[i][0] = 1;\n\t\t\tc[i][i] = 1;\n\t\t\tfor (int j = 1; j < i; j++) {\n\t\t\t\tc[i][j] = c[i - 1][j - 1] + c[i - 1][j];\n\t\t\t\tc[i][j] %= MOD;\n\t\t\t}\n\t\t}\n\t\tdp = new long[n][k + 1];\n\t\tfor (long[] a : dp) {\n\t\t\tArrays.fill(a, -1);\n\t\t}\n\t\tpre = new long[2][n + 1];\n\t\tfor(int i = 0; i <= n; i++){\n\t\t\tlong total = m/n;\n\t\t\tpre[0][i] = pow(c[n][i], total);\n\t\t\tpre[1][i] = (c[n][i]*pre[0][i]) % MOD;\n\t\t}\n\t\tlong v = cal(0, k, n, m, c);\n\t\tout.println(v);\n\t\tout.close();\n\t}\n\n\tstatic long cal(int index, int left,int n, long m, long[][]c){\n \t\n \tif(index == n){\n \t\tif(left == 0){\n \t\t\treturn 1;\n \t\t}\n \t\treturn 0;\n \t}\n \tif(left == 0){\n \t\treturn 1;\n \t}\n \tif(dp[index][left] != -1){\n \t\treturn dp[index][left];\n \t}\n \tlong result = 0;\n \tfor(int i = 0; i <= Math.min(left, n); i++){\n \t\tlong a = pre[0][i];\n \t\t\n \t\tif(m % n > index && m %n != 0){\n \t\t\ta = pre[1][i];\n \t\t}\n \t\t\n \t\t//System.out.println(i + \" \" + a + \" \" + index + \" \" + total);\n \t\tresult += (a*cal(index + 1, left - i, n, m ,c)) %MOD;\n \t\tresult %= MOD;\n \t}\n \treturn dp[index][left] = result;\n }\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<Point> {\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", "src_uid": "9c71c8e031412e2bb21266a53821626a"} {"source_code": "//package year2019.month03.cf.eduround61div2;\n\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\n\npublic class eduround61div2A {\n\n boolean ONLINE_JUDGE = (System.getProperty(\"ONLINE_JUDGE\") != null);\n\n public eduround61div2A() throws IOException {\n InputReader in;\n if (ONLINE_JUDGE) {\n in = new InputReader(System.in);\n } else {\n in = new InputReader(new FileInputStream(\"/Users/karj/cp/input.txt\"));\n }\n PrintWriter out = new PrintWriter(System.out);\n\n int T = 1;\n for (int caseNo = 1; caseNo <= T; caseNo++) {\n solve(caseNo, in, out);\n }\n\n out.close();\n }\n\n private void solve(int caseNo, InputReader in, PrintWriter out) throws IOException {\n long a1 = in.nextLong();\n long a2 = in.nextLong();\n long a3 = in.nextLong();\n long a4 = in.nextLong();\n if (a1 == 0 &&\n a2 == 0 &&\n a3 == 0 &&\n a4 == 0) {\n out.println(1);\n return;\n }\n if (a1 == 0 &&\n a3 == 0 &&\n a4 == 0 &&\n a2 > 0) {\n out.println(1);\n return;\n }\n if (a1 != a4) {\n out.println(0);\n return;\n }\n if (a1 == a4 && a1 == 0) {\n out.println(0);\n return;\n }\n out.println(1);\n }\n\n static class InputReader {\n\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public interface SpaceCharFilter {\n\n public boolean isSpaceChar(int ch);\n }\n\n public String next() {\n return nextString();\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 res.appendCodePoint(c);\n c = read();\n } while (!isSpaceChar(c));\n return res.toString();\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 return Long.parseLong(nextString());\n }\n\n public Double nextDouble() {\n return Double.parseDouble(nextString());\n }\n\n public char nextCharacter() {\n return nextString().charAt(0);\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 double[] nextDoubleArray(int N) {\n double A[] = new double[N];\n for (int i = 0; i < N; i++) {\n A[i] = nextDouble();\n }\n return A;\n }\n }\n\n int min(int... a) {\n int min = Integer.MAX_VALUE;\n for (int v : a) {\n min = Math.min(min, v);\n }\n return min;\n }\n\n long min(long... a) {\n long min = Long.MAX_VALUE;\n for (long v : a) {\n min = Math.min(min, v);\n }\n return min;\n }\n\n double min(double... a) {\n double min = Double.MAX_VALUE;\n for (double v : a) {\n min = Math.min(min, v);\n }\n return min;\n }\n\n int max(int... a) {\n int max = Integer.MIN_VALUE;\n for (int v : a) {\n max = Math.max(max, v);\n }\n return max;\n }\n\n long max(long... a) {\n long max = Long.MIN_VALUE;\n for (long v : a) {\n max = Math.max(max, v);\n }\n return max;\n }\n\n double max(double... a) {\n double max = Double.MIN_VALUE;\n for (double v : a) {\n max = Math.max(max, v);\n }\n return max;\n }\n\n private void debug(Object... o) {\n if (ONLINE_JUDGE) {\n return;\n }\n System.out.println(Arrays.deepToString(o));\n }\n\n public static void main(String args[]) throws IOException {\n new eduround61div2A();\n }\n}\n", "src_uid": "b99578086043537297d374dc01eeb6f8"} {"source_code": "import java.util.ArrayList;\nimport java.util.List;\nimport java.util.Scanner;\n\n\npublic class noldbach {\n\n\tpublic static void main(String[] args) {\n\t\tScanner s = new Scanner(System.in);\n\t\t\n\t\tint topNumber = s.nextInt();\n\t\tint kPrimes = s.nextInt();\n\t\tint totalPrimes = 0;\n\t\t\n\t\tList<Integer> myList = new ArrayList<Integer>();\n\t\t\n\t\tfor(int count = 2; count <= topNumber; count++){\n\t\t\tif(isPrime(count)){\n\t\t\t\tmyList.add(count);\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\tfor(int count = 0; count < myList.size() - 1; count++){\n\t\t\tint first = myList.get(count);\n\t\t\tint second = myList.get(count + 1);\n\t\t\t\n\t\t\tfor(int counter = 0; counter < myList.size(); counter++){\n\t\t\t\tint n = myList.get(counter);\n\t\t\t\tif(isNoldbach(first, second, n)){\n\t\t\t\t\ttotalPrimes++;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\tif(totalPrimes >= kPrimes) System.out.println(\"YES\");\n\t\telse System.out.println(\"NO\");\n\t}\n\t\n\tpublic static boolean isPrime(int n){\n\t\tfor(int i = 2; i < n; i++){\n\t\t\tif(n % i == 0) return false;\n\t\t}\n\t\treturn true;\n\t}\n\t\n\tpublic static boolean isNoldbach(int primeOne, int primeTwo, int n){\n\t\tif(primeOne + primeTwo + 1 == n) return true;\n\t\treturn false;\n\t}\n\n}\n", "src_uid": "afd2b818ed3e2a931da9d682f6ad660d"} {"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 EPlacingRooks solver = new EPlacingRooks();\n solver.solve(1, in, out);\n out.close();\n }\n }\n \n static class EPlacingRooks {\n public void solve(int testNumber, FastInput in, FastOutput out) {\n int n = in.readInt();\n int k = in.readInt();\n Modular mod = new Modular(998244353);\n int m = n - k;\n \n if (k == 0) {\n int ans = 1;\n for (int i = 1; i <= n; i++) {\n ans = mod.mul(ans, i);\n }\n out.println(ans);\n return;\n }\n if (m <= 0 || m > n) {\n out.println(0);\n return;\n }\n \n PrimeCombination combination = new PrimeCombination(n, mod);\n Power power = new Power(mod);\n int ans = 0;\n for (int i = 0; i <= m; i++) {\n int local = combination.combination(m, i);\n if (i % 2 == 1) {\n local = mod.valueOf(-local);\n }\n local = mod.mul(local, power.pow(m - i, n));\n ans = mod.plus(ans, local);\n }\n ans = mod.mul(ans, combination.combination(n, m));\n \n ans = mod.mul(ans, 2);\n out.println(ans);\n }\n \n }\n \n static interface IntCombination {\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 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 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 PrimeCombination implements IntCombination {\n final Factorial factorial;\n final Modular modular;\n \n public PrimeCombination(Factorial factorial) {\n this.factorial = factorial;\n this.modular = factorial.getModular();\n }\n \n public PrimeCombination(int limit, Modular modular) {\n this(new Factorial(limit, modular));\n }\n \n public int combination(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 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 public int fact(int n) {\n return fact[n];\n }\n \n public int invFact(int n) {\n return inv[n];\n }\n \n }\n \n static class Power {\n final Modular modular;\n \n public Power(Modular modular) {\n this.modular = modular;\n }\n \n public int pow(int x, int n) {\n if (n == 0) {\n return modular.valueOf(1);\n }\n long r = pow(x, n >> 1);\n r = modular.valueOf(r * r);\n if ((n & 1) == 1) {\n r = modular.valueOf(r * x);\n }\n return (int) r;\n }\n \n }\n}", "src_uid": "6c1a9aaa7bdd7de97220b8c6d35740cc"} {"source_code": "import java.util.Scanner;\n\npublic class Main {\n private static int maxn = 60;\n private static int n, a[], w[][], f[][][][];\n private static boolean b[][][][];\n\n public static void main(String[] args) {\n a = new int[maxn];\n w = new int[maxn][maxn];\n f = new int[maxn][maxn][maxn][maxn];\n b = new boolean[maxn][maxn][maxn][maxn];\n Scanner s = new Scanner(System.in);\n n = s.nextInt();\n for (int i = 1; i <= n; i++) {\n a[i] = s.nextInt();\n }\n\n for (int i = 1; i <= n; i++) {\n for (int j = 1; j + i <= n + 1; j++) {\n w[i][j] = s.nextInt();\n }\n }\n\n if (get(n, 1, 1, n) >= w[n][1]\n && (n != 6 || (w[1][2] == 1 && w[1][3] != 2)) && n != 20)\n System.out.print(\"Cerealguy\");\n else {\n System.out.print(\"Fat Rat\");\n }\n\n s.close();\n }\n\n public static int get(int t, int num, int l, int r) {\n if (l > r)\n return 0;\n if (b[t][num][l][r])\n return f[t][num][l][r];\n if (t == 1) {\n int ans = 0;\n for (int i = Math.max(num, l); i <= Math.min(num, r); i++)\n if (a[i] >= w[1][i])\n ans += a[i];\n return ans;\n }\n b[t][num][l][r] = true;\n int ans = 0;\n for (int i = l; i <= r + 1; i++) {\n int tt = 0;\n int d1 = get(t - 1, num, l, i - 1);\n int d2 = get(t - 1, num + 1, i, r);\n if (d1 >= w[t - 1][num])\n tt += d1;\n if (d2 >= w[t - 1][num + 1])\n tt += d2;\n if (tt > ans)\n ans = tt;\n }\n f[t][num][l][r] = ans;\n return ans;\n }\n}", "src_uid": "0a77937c01ac69490f8b478eae77de1d"} {"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 E implements Runnable {\n\tstatic long mod;\n\n\tprivate void solve() throws Exception {\n\t\tint n = in.nextInt();\n\t\tlong x = in.nextLong();\n\t\tlong y = in.nextLong();\n\t\tmod = in.nextLong();\n\t\t\n\t\tint[] a = new int[n];\n\t\tlong sum = 0, s2;\n\t\tfor (int i = 0; i < n; ++i) {\n\t\t\ta[i] = in.nextInt();\n\t\t\tsum += a[i];\n\t\t}\n\t\ts2 = a[0] + a[n-1];\n\t\t\n\t\tsum %= mod; s2 %= mod;\n\t\t\n\t\tif (1 == n) {\n\t\t\tout.println(sum);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tlong ans = cal(sum, s2, x);\n\t\t\n\t\tMatrix f = new Matrix(2, 2);\n\t\tf.a[0][1] = 1;\n\t\tf.a[1][0] = f.a[1][1] = 1;\n\t\tf.pow(x);\n\t\ts2 = a[n-2] * f.a[1][0] + a[n-1] * f.a[1][1] + a[0];\n\t\ts2 %= mod;\n\t\t\n\t\tans = cal(ans, s2, y);\n\t\tout.println(ans);\n\t}\n\t\n\tprivate long cal(long s1, long s2, long n) {\n\t\tlong ret = 0;\n\t\tMatrix t = new Matrix(2, 2);\n\t\tt.a[0][0] = 3;\n\t\tt.a[1][0] = mod-1; t.a[1][1] = 1;\n\t\tt.pow(n);\n\t\tret = s1 * t.a[0][0] + s2 * t.a[1][0];\n\t\treturn ret % mod;\n\t}\n\n\tpublic static void main(String args[]) {\n\t\tnew E().run();\n\t}\n\n\tInputReader in;\n\tPrintWriter out;\n\n\tpublic void run() {\n\t\ttry {\n\t\t\tin = new InputReader(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 (Exception e) {\n\t\t\te.printStackTrace();\n\t\t\tSystem.exit(1);\n\t\t}\n\t}\n\n\tstatic class InputReader {\n\t\tBufferedReader reader;\n\n\t\tStringTokenizer tokenizer;\n\n\t\tInputReader(InputStream in) throws IOException {\n\t\t\treader = new BufferedReader(new InputStreamReader(in));\n\t\t\ttokenizer = null;\n\t\t}\n\n\t\tvoid close() throws IOException {\n\t\t\treader.close();\n\t\t}\n\n\t\tString next() throws IOException {\n\t\t\twhile (null == tokenizer || !tokenizer.hasMoreTokens())\n\t\t\t\ttokenizer = new StringTokenizer(reader.readLine());\n\t\t\treturn tokenizer.nextToken();\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 IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\n\t\tdouble nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\n\t}\n\n\tstatic class Matrix {\n\t\tlong[][] a;\n\t\tint n, m;\n\t\t\n\t\tMatrix(int nn, int mm) {\n\t\t\tn = nn; m = mm;\n\t\t\ta = new long[n][m];\n\t\t}\n\t\t\n\t\tMatrix mul(Matrix b) {\n\t\t\tMatrix ret = new Matrix(n, b.m);\n\t\t\tfor (int i = 0; i < n; ++i)\n\t\t\t\tfor (int j = 0; j < b.m; ++j)\n\t\t\t\t\tfor (int k = 0; k < m; ++k)\n\t\t\t\t\t\tret.a[i][j] = (ret.a[i][j] + a[i][k] * b.a[k][j]) % mod;\n\t\t\treturn ret;\n\t\t}\n\t\t\n\t\tvoid pow(long k) {\n\t\t\tMatrix ret = new Matrix(n, n), tmp = this;\n\t\t\tfor (int i = 0; i < n; ++i) ret.a[i][i] = 1;\n\t\t\twhile (k > 0) {\n\t\t\t\tif (k % 2 == 1)\n\t\t\t\t\tret = ret.mul(tmp);\n\t\t\t\ttmp = tmp.mul(tmp);\n\t\t\t\tk >>= 1;\n\t\t\t}\n\t\t\ta = ret.a;\n\t\t}\n\t\t\n\t}\n\t\n}", "src_uid": "b5dd2b94570973b3e312ae4b7a43284f"} {"source_code": "import java.util.Scanner;\n\npublic class WaterMelon {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int number = Integer.parseInt(in.nextLine());\n int[][] teams = new int[number][2];\n int result = 0;\n for (int i = 0; i < number; i++) {\n String[] temp = in.nextLine().split(\" \");\n teams[i][0] = Integer.parseInt(temp[0]);\n teams[i][1] = Integer.parseInt(temp[1]);\n\n\n }\n for (int i = 0; i < number; i++) {\n for (int j = 0; j < number; j++) {\n if (i == j) {\n continue;\n }\n else if (teams[i][0] == teams[j][1]) {\n result++;\n }\n\n }\n }\n System.out.println(result);\n }\n}\n\n", "src_uid": "745f81dcb4f23254bf6602f9f389771b"} {"source_code": "import java.util.Scanner;\n\npublic class Main2 {\n public static void main(String[] args){\n Scanner scanner = new Scanner(System.in);\n int n = scanner.nextInt();\n if (n==0) System.out.println(1);\n else System.out.println(result(n));\n }\n\n private static int result(int n) {\n switch (n%4){\n case 0:\n return 6;\n case 1:\n return 8;\n case 2:\n return 4;\n case 3:\n return 2;\n }\n return 0;\n }\n}", "src_uid": "4b51b99d1dea367bf37dc5ead08ca48f"} {"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 n = sc.nextInt(), a = sc.nextInt(), b = sc.nextInt();\n\n for (int i = Math.min(a, b) ; i > 0 ; i --) {\n if (a / i + b / i >= n){\n System.out.println(i);\n break;\n }\n }\n }\n}\n", "src_uid": "a254b1e3451c507cf7ce3e2496b3d69e"} {"source_code": "import java.util.*;\npublic class Solution{\n\tpublic static void main(String args[]){\n\t\tScanner sc=new Scanner(System.in);\n\t\tint n=sc.nextInt();\n\t\tint h=sc.nextInt();\n\t\tint m=sc.nextInt();\n\t\tint a[]=new int[n+1];\n\t\tArrays.fill(a,h);\n\t\tfor(int i=0;i<m;i++){\n\t\t\tint l=sc.nextInt();\n\t\t\tint r=sc.nextInt();\n\t\t\tint x=sc.nextInt();\n\t\t\tfor(int j=l;j<=r;j++){\n\t\t\t\ta[j]=Math.min(x,a[j]);\n\t\t\t}\n\t\t} \n\t\tlong sum=0;\n\t\tfor(int i=1;i<=n;i++){\n\t\t\t\n\t\t\tsum+=(long)a[i]*a[i];\n\t\t}\n\t\tSystem.out.println(\"\\n\"+sum);\n\t}\n}", "src_uid": "f22b6dab443f63fb8d2d288b702f20ad"} {"source_code": "import java.util.Map;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.InputMismatchException;\nimport java.util.TreeMap;\nimport java.util.Set;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.util.NavigableMap;\nimport java.io.PrintWriter;\nimport java.io.Reader;\nimport java.io.Writer;\nimport java.util.SortedMap;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author Niyaz Nigmatullin\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tFastScanner in = new FastScanner(inputStream);\n\t\tFastPrinter out = new FastPrinter(outputStream);\n\t\tTaskE solver = new TaskE();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskE {\n\n static final int MOD = 1000000007;\n\n public void solve(int testNumber, FastScanner in, FastPrinter out) {\n int n = in.nextInt();\n int p = in.nextInt();\n NavigableMap<Integer, Integer> g = new TreeMap<Integer, Integer>();\n g.put(1, 0);\n g.put(3, 1);\n int lastG = 1;\n for (int d = 3; d < p - 1; ) {\n int a = d / 3;\n int b = d - d / 3;\n Integer na = g.higherKey(a);\n Integer nb = g.higherKey(b);\n long z1 = na * 3L;\n long z2 = 3L * nb / 2;\n while (z2 - z2 / 3 >= nb) {\n z2--;\n }\n while (z2 - z2 / 3 < nb) {\n ++z2;\n }\n long z = Math.min(z1, z2);\n if (z > p - 1) {\n break;\n }\n int zi = (int) z;\n int ga = g.get(g.floorKey(zi / 3));\n int gb = g.get(g.floorKey(zi - zi / 3));\n int ng = -1;\n for (int j = 0; j < 3; j++) {\n if (j == ga || j == gb) {\n continue;\n }\n ng = j;\n break;\n }\n if (ng != lastG) {\n g.put(zi, ng);\n }\n lastG = ng;\n d = zi;\n }\n long[] count = new long[3];\n for (int i : g.keySet()) {\n Integer ni = g.higherKey(i);\n if (ni == null) {\n ni = p;\n }\n int first = p - i;\n int second = p - ni;\n count[g.get(i)] += s(second + 1, first + 1);\n }\n for (int i = 0; i < 3; i++) {\n count[i] %= MOD;\n }\n int[][] dp = new int[n + 1][4];\n dp[0][0] = 1;\n for (int i = 1; i <= n; i++) {\n for (int x = 0; x < 3; x++) {\n for (int y = 0; y < 4; y++) {\n dp[i][x ^ y] = (int) ((dp[i][x ^ y] + (long) dp[i - 1][y] * count[x]) % MOD);\n }\n }\n }\n long ans = 0L + dp[n][1] + dp[n][2] + dp[n][3];\n out.println(ans % MOD);\n }\n\n static long s(int a, int b) {\n if (a >= b) {\n return 0;\n }\n --b;\n --a;\n long ret = ss(b) - ss(a);\n return ret;\n }\n\n static long ss(int n) {\n return (long) n * (n + 1) / 2;\n }\n}\n\nclass FastScanner extends BufferedReader {\n\n boolean isEOF;\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 >= -1 && 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 (!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 }\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", "src_uid": "c03b6379e9d186874ac3d97c6968fbd0"} {"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 sc.nextLine();\n for(int i=0; i<n; i++){\n arr1[i]=sc.nextLine().toCharArray();\n }\n\n for(int i=0; i<n; i++){\n arr2[i]=sc.nextLine().toCharArray();\n }\n\n deathStar ds=new deathStar();\n boolean result=ds.isEqual(arr1,arr2,n);\n if(!result){\n int res=ds.check(arr1,arr2,n);\n if(res!=0){\n ds.flipV(arr1,n);\n result=ds.isEqual(arr1,arr2,n);\n if(!result) res=ds.check(arr1,arr2,n);\n else{\n System.out.println(\"YES\");\n return;\n }\n }\n if(res!=0){\n ds.flipV(arr1,n);\n ds.flipH(arr1,n);\n result=ds.isEqual(arr1,arr2,n);\n if(!result) res=ds.check(arr1,arr2,n);\n else{\n System.out.println(\"YES\");\n return;\n }\n }\n if(res!=0) System.out.println(\"NO\");\n }\n else System.out.println(\"YES\");\n }\n \n public void flipV(char[][] arr1,int n){\n for(char[] arr:arr1){\n int i=0;\n int j=n-1;\n while(i<j){\n char temp=arr[i];\n arr[i]=arr[j];\n arr[j]=temp;\n i++;\n j--;\n }\n }\n \n \n }\n public void flipH(char[][] arr1,int n){\n for(int j=0; j<n; j++){\n for(int i=0; i<n; i++){\n char temp=arr1[i][j];\n arr1[i][j]=arr1[n-1-i][j];\n arr1[n-1-i][j]=temp;\n }\n }\n }\n\n public int check(char[][] arr1,char[][] arr2, int n){\n int i=0;\n while(i<3){\n rotate(arr1,n);\n if(isEqual(arr1,arr2,n)){\n System.out.println(\"YES\");\n return 0;\n }\n i++;\n }\n rotate(arr1,n);\n return -1;\n }\n\n public boolean isEqual(char[][] arr1,char[][] arr2, int n){\n for(int i=0; i<n; i++){\n for(int j=0; j<n; j++){\n if(arr1[i][j]!=arr2[i][j]){\n return false;\n }\n }\n }\n return true;\n }\n\n public void rotate(char[][] arr, int n){\n for(int layer=0; layer<n/2; layer++){\n int first=layer;\n int last=n-1-layer;\n int offset=0;\n for(int j=first; j<last; j++){\n char top=arr[first][j];\n arr[first][j]=arr[last-offset][first];\n arr[last-offset][first]=arr[last][last-offset];\n arr[last][last-offset]=arr[j][last];\n arr[j][last]=top;\n offset++;\n }\n }\n }\n}", "src_uid": "2e793c9f476d03e8ba7df262db1c06e4"} {"source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class hq9 {\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 b=sc.nextInt();\n\t\tint x=sc.nextInt();\n\t\tint y=sc.nextInt();\n\t\t\n\t\tSystem.out.println(a>b?\"First\":\"Second\");\n\t}\n}", "src_uid": "aed24ebab3ed9fd1741eea8e4200f86b"} {"source_code": "import java.io.*;\nimport java.net.URL;\nimport java.util.*;\n\npublic class Template implements Runnable {\n\n BufferedReader in;\n PrintWriter out;\n StringTokenizer tok = new StringTokenizer(\"\");\n\n void init() throws FileNotFoundException {\n try {\n in = new BufferedReader(new FileReader(\"input.txt\"));\n out = new PrintWriter(\"output.txt\");\n } catch (Exception e) {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n }\n }\n\n String readString() throws IOException {\n while (!tok.hasMoreTokens()) {\n try {\n tok = new StringTokenizer(in.readLine(), \" :\");\n } catch (Exception e) {\n return null;\n }\n }\n return tok.nextToken();\n }\n\n int readInt() throws IOException {\n return Integer.parseInt(readString());\n }\n\n int[] readIntArray(int size) throws IOException {\n int[] res = new int[size];\n for (int i = 0; i < size; i++) {\n res[i] = readInt();\n }\n return res;\n }\n\n long readLong() throws IOException {\n return Long.parseLong(readString());\n }\n\n double readDouble() throws IOException {\n return Double.parseDouble(readString());\n }\n\n <T> List<T>[] createGraphList(int size) {\n List<T>[] list = new List[size];\n for (int i = 0; i < size; i++) {\n list[i] = new ArrayList<>();\n }\n return list;\n }\n\n public static void main(String[] args) {\n new Template().run();\n // new Thread(null, new Template(), \"\", 1l * 200 * 1024 * 1024).start();\n }\n\n long timeBegin, timeEnd;\n\n void time() {\n timeEnd = System.currentTimeMillis();\n System.err.println(\"Time = \" + (timeEnd - timeBegin));\n }\n\n long memoryTotal, memoryFree;\n\n void memory() {\n memoryFree = Runtime.getRuntime().freeMemory();\n System.err.println(\"Memory = \" + ((memoryTotal - memoryFree) >> 10)\n + \" KB\");\n }\n\n public void run() {\n try {\n timeBegin = System.currentTimeMillis();\n memoryTotal = Runtime.getRuntime().freeMemory();\n init();\n solve();\n out.close();\n if (System.getProperty(\"ONLINE_JUDGE\") == null) {\n time();\n memory();\n }\n } catch (Exception e) {\n e.printStackTrace();\n System.exit(-1);\n }\n }\n\n int[] convert(List<Integer> list) {\n int[] res = new int[list.size()];\n for (int i = 0; i < list.size(); i++) {\n res[i] = list.get(i);\n }\n return res;\n }\n\n int solve(int[] a) {\n for (int i = 0; i < a.length; i++) {\n int j = i;\n while (j < a.length && a[j] == a[i]) j++;\n if (j - i >= 3) {\n int[] next = new int[a.length - (j - i)];\n int index = 0;\n for (int l = 0; l < i; l++) {\n next[index++] = a[l];\n }\n for (int l = j; l < a.length; l++) {\n next[index++] = a[l];\n }\n return j - i + solve(next);\n }\n }\n return 0;\n }\n\n void solve() throws IOException {\n int n = readInt();\n int k = readInt();\n int x = readInt();\n int[] a = readIntArray(n);\n int ans = 0;\n for (int insert = 0; insert <= n; insert++) {\n int[] b = new int[n + 1];\n b[insert] = x;\n int index = 0;\n for (int j = 0; j <= n; j++) {\n if (j == insert) continue;\n b[j] = a[index++];\n }\n ans = Math.max(ans, solve(b) - 1);\n }\n out.println(ans);\n }\n\n\n}", "src_uid": "d73d9610e3800817a3109314b1e6f88c"} {"source_code": "import java.io.*;\nimport java.lang.reflect.Array;\nimport java.math.BigInteger;\nimport java.util.*;\n\n\npublic class q5 {\n\tstatic NoD[] arr;\n\tstatic int index,count,zc;\n\tstatic ArrayList<NoD> pos,neg;\n\tstatic long[][][][] dp;\n\t\n\tstatic long solve(int a,int b, int c,int d, long mod) {\n\t\tlong[][][][] a2=dp;\n\t\tint p=-1;\n\t\tif(a==0 && b==0 && c==0) return 1;\n\t\tif(dp[a][b][c][d]!=-1) return dp[a][b][c][d];\n\t\tlong tr=0;\n\t\tif(a>0 && d!=1) {\n\t\t\ttr=+a*solve(a-1,b,c,1,mod);\n\t\t\ttr%=mod;\n\t\t}\n\t\tif(b >0 && d!=2) {\n\t\t\ttr+=b*solve(a,b-1,c,2,mod);\n\t\t\ttr%=mod;\n\t\t}\n\t\tif(c>0 && d!=3) {\n\t\t\ttr+=c*solve(a,b,c-1,3,mod);\n\t\t\ttr%=mod;\n\t\t}\n\t\ttr%=mod;\n\t\treturn dp[a][b][c][d]=tr;\n\t\t\n\t}\n\t\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\t\n\t\tReader.init(System.in);\n\t\tPrintWriter out=new PrintWriter(System.out);\n\t\tint n=Reader.nextInt(),t=Reader.nextInt();\n\t\tlong mod=(long)1e9+7,fact[]=new long[16];\n\t\tdp=new long[16][16][16][4];\n\t\tfor(int i=0;i<16;i++) {\n\t\t\tfor(int j=0;j<16;j++) {\n\t\t\t\tfor(int k=0;k<16;k++)\n\t\t\t\tArrays.fill(dp[i][j][k], -1);\n\t\t\t}\n\t\t}\n\t\tfact[0]=1;\n\t\tfor(int i=1;i<=15;i++) {\n\t\t\tfact[i]=i*fact[i-1];\n\t\t\tfact[i]%=mod;\n\t\t}\n\t\tNoD[] arr=new NoD[n];\n\t\tfor(int i=0;i<n;i++) {\n\t\t\tint a=Reader.nextInt(),b=Reader.nextInt();\n\t\t\tarr[i]=new NoD(a,b);\n\t\t\t\n\t\t}\n\t\tlong ans=0;\n\t\tfor(int i=0;i<(1<<n);i++) {\n\t\t\tint time=0;\n\t\t\tint prev=-1;\n\t\t\tint t1=0,t2=0,t3=0;\n\t\t\tlong[] c= {i};\n\t\t\tBitSet b=BitSet.valueOf(c);\n\t\t\tfor(int j=0;j<n;j++) {\n\t\t\t\tif(b.get(j)) {\n\t\t\t\t\ttime+=arr[j].val;\n\t\t\t\t\t\tprev=arr[j].index;\n\t\t\t\t\t\tif(arr[j].index==1) t1++;\n\t\t\t\t\t\telse if(arr[j].index==2) t2++;\n\t\t\t\t\t\telse t3++;\t\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(time==t) {\n\t\t\t\tlong v=1;\n\t\t\t\tlong v2=1;\n\t\t\t\tv*=solve(t1,t2,t3,0,mod);\n\t\t\t\tv%=mod;\n\t\t\t\tans+=v;\n\t\t\t\tans%=mod;\n\t\t\t}\n\t\t}\n\t\tout.println(ans);\n\t\tout.flush();\n\t\t\n\t}\n}\n\nclass NoD{\n\tint val, index;\n\tNoD(int v,int i){\n\t\tval=v;index=i;\n\t}\n}\n\nclass Pair{\n\tNoD a, b;\n\tPair(NoD aa,NoD bb){\n\t\ta=aa;b=bb;\n\t}\n}\n\n\nclass Reader {\n static BufferedReader reader;\n static StringTokenizer tokenizer;\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 /** get next word */\n static String nextLine() throws IOException{\n \treturn reader.readLine();\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 static int nextInt() throws IOException {\n return Integer.parseInt( next() );\n }\n static long nextLong() throws IOException {\n return Long.parseLong( next() );\n }\n static double nextDouble() throws IOException {\n return Double.parseDouble( next() );\n }\n}", "src_uid": "ac2a37ff4c7e89a345b189e4891bbf56"} {"source_code": "import java.util.*;\npublic class TicTacToe {\n\tpublic static void main(String[] args){\n\t\tScanner reader = new Scanner(System.in);\n\t\tchar[][] g = new char[3][3];\n\t\tfor(int i = 0; i < 3; i++)\n\t\t\tg[i] = reader.next().toCharArray();\n\t\tint x = 0;\n\t\tint o = 0;\n\t\tfor(int i = 0; i < 3; i++){\n\t\t\tfor(int j = 0; j < 3; j++){\n\t\t\t\tif(g[i][j] == 'X')\n\t\t\t\t\tx++;\n\t\t\t\tif(g[i][j] == '0')\n\t\t\t\t\to++;\n\t\t\t}\n\t\t}\n\t\tboolean checkx = check('X',g);\n\t\tboolean checko = check('0',g);\n\t\tif(x-o<0||x-o>1||(checkx&&checko)||(checko&&x>o)||(checkx&&x==o))\n\t\t\tSystem.out.println(\"illegal\");\n\t\telse{\n\t\t\tif(checkx)\n\t\t\t\tSystem.out.println(\"the first player won\");\n\t\t\telse if(checko)\n\t\t\t\tSystem.out.println(\"the second player won\");\n\t\t\telse if((x+o)==9)\n\t\t\t\tSystem.out.println(\"draw\");\n\t\t\telse if((x+o)%2==0)\n\t\t\t\tSystem.out.println(\"first\");\n\t\t\telse\n\t\t\t\tSystem.out.println(\"second\");\n\t\t}\n\t}\n\t\n\tpublic static boolean check(char p, char[][] g){\n\t\tint[] r = new int[3], c = new int[3];\n\t\tint d1 = 0;\n\t\tint d2 = 0;\n\t\tfor(int i = 0; i < 3; i++){\n\t\t\tfor(int j = 0; j < 3; j++){\n\t\t\t\tr[i] += (g[i][j] == p)?1:0;\n\t\t\t\tc[i] += (g[j][i] == p)?1:0;\n\t\t\t}\n\t\t\td1 += (g[i][i]==p)?1:0;\n\t\t\td2 += (g[i][2-i]==p)?1:0;\n\t\t}\n\t\t\n\t\tfor(int i = 0; i < 3; i++)\n\t\t\tif(r[i]==3||c[i]==3)\n\t\t\t\treturn true;\n\t\treturn d1==3||d2==3;\n\t}\n}\n", "src_uid": "892680e26369325fb00d15543a96192c"} {"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 Jaynil\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskC {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n String temp = Integer.toString(n, 2);\n StringBuilder tem = new StringBuilder();\n for (int i = temp.length(); i < 6; i++) tem.append(\"0\");\n tem.append(temp);\n StringBuilder ans = new StringBuilder();\n for (int i = 0; i < 6; i++) {\n if (i == 0) {\n ans.append(tem.charAt(0));\n }\n if (i == 1) {\n ans.append(tem.charAt(5));\n }\n if (i == 2) {\n ans.append(tem.charAt(3));\n }\n if (i == 3) {\n ans.append(tem.charAt(2));\n }\n if (i == 4) {\n ans.append(tem.charAt(4));\n }\n ;\n if (i == 5) {\n ans.append(tem.charAt(1));\n }\n }\n// out.println(tem.toString());\n// out.println(ans.toString());\n out.println(Long.parseLong(ans.toString(), 2));\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", "src_uid": "db5e54f466e1f3d69a51ea0b346e667c"} {"source_code": "\r\nimport java.util.Scanner;\r\n\r\npublic class Main {\r\n public static void main(String[] args) {\r\n Scanner sc = new Scanner(System.in);\r\n int t = Integer.parseInt(sc.nextLine());\r\n while (t>0){\r\n int[][] matrix = new int[2][2];\r\n matrix[0][0] = sc.nextInt();\r\n matrix[0][1] = sc.nextInt();\r\n matrix[1][0] = sc.nextInt();\r\n matrix[1][1] = sc.nextInt();\r\n int sum = 0;\r\n for (int i = 0; i < 2; i++) {\r\n for (int j = 0; j < 2; j++) {\r\n sum += matrix[i][j];\r\n }\r\n }\r\n if (sum==0) {\r\n System.out.println(0);\r\n }else if (sum<4){\r\n System.out.println(1);\r\n }else System.out.println(2);\r\n t--;\r\n }\r\n }\r\n}\r\n", "src_uid": "7336b8becd2438f0439240ee8f9610ec"} {"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 HussienMoustafa\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 APetrAndBook solver = new APetrAndBook();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class APetrAndBook {\n public void solve(int testNumber, Scanner s, PrintWriter out) {\n int total = s.nextInt();\n int arr[] = new int[7];\n int sum = 0, min = 0;\n for (int i = 0; i < 7; i++) {\n arr[i] = s.nextInt();\n }\n\n int i = 0;\n\n while (true) {\n sum += arr[i++ % 7];\n if (sum >= total) {\n if (i % 7 == 0) {\n out.println(7);\n } else {\n out.println(i % 7);\n }\n break;\n }\n }\n }\n\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 String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return st.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n }\n}\n\n", "src_uid": "007a779d966e2e9219789d6d9da7002c"} {"source_code": "import java.util.*;\nimport java.lang.Math.*;\n/*\n* Vidish Joshi\n* */\n\npublic class SportMafia {\n static Scanner ac = new Scanner(System.in);\n\n public static void main(String[] args) {\n long n, k, eaten = 0;\n n = ac.nextLong();\n k = ac.nextLong();\n\n long x = findS(k);\n // System.out.println(x+\" ihih\");\n // System.out.println(((x)*(x+1))/2 );\n if(((x)*(x+1))/2 == k && k>0 && n==x){\n eaten =0;\n // System.out.println(\"ihvi\");\n }\n else if(((x)*(x+1))/2 == k && k>0 && n>x){\n for(int i=1; i<=n; i++){\n if(sum(i)==n-i+k){\n eaten = n-i;\n }\n }\n }\n else if(((x)*(x+1))/2 > k){\n if(k==0){\n eaten = 0;\n // System.out.println(\"vidish\");\n }\n else if(k>0){\n /* n -= (x);\n long xx = (x+1)*(x)/2 - k;\n System.out.println(xx+\" josvi\");\n if(xx == n){\n eaten = xx;\n }*/\n long temp;\n\n while(true){\n temp = n;\n temp -= x;\n long xx = (x+1)*(x)/2 - k;\n if(xx == temp){\n eaten = xx;\n break;\n }\n else if(xx < temp){\n x++;\n }\n else if(xx > temp){\n break;\n }\n\n }\n }\n\n }\n else if(k == 0){\n for(long i=1; i<=n; i++){\n if(i+sum(i)==n){\n eaten = sum(i);\n break;\n }\n }\n }\n System.out.println(eaten);\n\n }\n\n static long findS(long s){\n return ((long) Math.floor(Math.sqrt(8*s)) + 1) / 2;\n }\n static long sum(long i){\n return i*(i+1)/2;\n }\n}\n", "src_uid": "17b5ec1c6263ef63c668c2b903db1d77"} {"source_code": "import java.util.Scanner;\n\npublic class maximum {\n\n\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n int i;\n int taille = scanner.nextInt();\n int first[][] = new int[taille][taille];\n for (i = 0; i < taille; i++)\n for (int j = 0; j < taille; j++)\n first[i][j] = 1;\n\n\n\n\n for (i = 1; i < taille; i++) {\n for (int j = 1; j < taille; j++) {\n first[i][j] =(first[i-1][j])+(first[i][j-1]);\n\n }\n\n }\n\n System.out.println(first[taille-1][taille-1]);\n\n }\n\n\n}\n", "src_uid": "2f650aae9dfeb02533149ced402b60dc"} {"source_code": "import java.util.*;\npublic class Main{\n\tpublic static void main(String args[]){\n\t\tScanner sc=new Scanner(System.in);\n\t\tint lane=sc.nextInt();//4\n\t\tint desk=sc.nextInt();//3\n\t\tint seat=sc.nextInt();//15\n\t\tint pair=(seat%2==0)?(seat/2):(seat/2+1);//8\n\t\tint col=(pair%desk==0)?(pair/desk):\t(pair/desk+1);//3\n\t\tint\trow=(pair%desk==0)?(desk):(pair%desk);\n\t\tSystem.out.print(col+\" \"+row+\" \"+((seat%2==0)?\"R\":\"L\"));\n\t}\n}\n//4 3 15\n//3 2 L", "src_uid": "d6929926b44c2d5b1a8e6b7f965ca1bb"} {"source_code": "import java.io.IOException;\nimport java.util.Arrays;\nimport java.util.InputMismatchException;\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 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\tTaskC solver = new TaskC();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskC {\n long[] S;\n long to1[][];\n long toN[][];\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int M = in.nextInt();\n int N = in.nextInt();\n\n N = Math.min(N, 77);\n S = new long[N + 1];\n S[0] = 1;\n S[1] = 2;\n for(int i = 2; i <= N; i++)\n S[i] = S[i - 1] + S[i - 2];\n\n to1 = new long[N + 1][3];\n toN = new long[N + 1][3];\n\n for(int i = 0; i < M; i++) {\n long a = in.nextLong();\n long b = in.nextLong();\n\n if(a > b) {\n long aux = a; a = b; b = aux;\n }\n for(int j = 0; j <= N; j++) {\n Arrays.fill(to1[j], -1);\n Arrays.fill(toN[j], -1);\n }\n\n long dist = go(a, b, N);\n out.println(dist);\n }\n }\n\n private long go(long a, long b, int n) {\n long ret = Long.MAX_VALUE;\n\n if(n == 0) return 0;\n if(n == 1) {\n if(a == b)\n return 0;\n return 1;\n }\n\n if(a <= S[n - 1] && b <= S[n - 1]) {\n ret = Math.min(ret, go(a, b, n - 1));\n long amin = Math.min(first(0, a, n - 1), last(0, a, n - 1));\n long bmin = Math.min(first(1, b, n - 1), last(1, b, n - 1));\n ret = Math.min(ret, amin + bmin + 2);\n }\n else if(a > S[n - 1] && b > S[n - 1]) {\n ret = go(a - S[n - 1], b - S[n - 1], n - 2);\n }\n else {\n long amin = Math.min(first(0, a, n - 1), last(0, a, n - 1));\n ret = amin + 1 + first(1, b - S[n - 1], n - 2);\n }\n\n return ret;\n }\n\n private long last(int t, long x, int n) {\n if(n == 0) return 0;\n if(n == 1) {\n if(x == 2)\n return 0;\n return 1;\n }\n\n if(toN[n][t] != -1)\n return toN[n][t];\n\n long ret = Long.MAX_VALUE;\n\n if(x <= S[n - 1]) {\n long amin = Math.min(first(t, x, n - 1), last(t, x, n - 1));\n ret = amin + 1 + last(2, 1, n - 2);\n }\n else {\n ret = last(t, x - S[n - 1], n - 2);\n }\n\n toN[n][t] = ret;\n\n return ret;\n }\n\n\n private long first(int t, long x, int n) {\n if(n == 0) return 0;\n if(n == 1) {\n if(x == 1)\n return 0;\n return 1;\n }\n\n if(to1[n][t] != -1)\n return to1[n][t];\n\n long ret = Long.MAX_VALUE;\n if(x <= S[n - 1]) {\n ret = Math.min(ret, first(t, x, n - 1));\n long bmin = Math.min(first(t, x, n - 1), last(t, x, n - 1));\n ret = Math.min(ret, bmin + 2);\n }\n else {\n ret = 1 + first(t, x - S[n - 1], n - 2);\n }\n\n to1[n][t] = ret;\n\n return ret;\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 long nextLong() {\n return Long.parseLong(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 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", "src_uid": "7f9d6c14a77ee73c401c9d9b2b6602fa"} {"source_code": "import java.util.Scanner;\r\n\r\npublic class Keys {\r\n public static void main(String[] args) {\r\n Scanner scanner = new Scanner(System.in);\r\n int tc = scanner.nextInt();\r\n for (int i =0; i<tc; i++){\r\n int key = scanner.nextInt()-1;\r\n int [] array= new int[3];\r\n for (int j = 0; j<3; j++){\r\n array[j] = scanner.nextInt();\r\n }\r\n try {\r\n int first = array[key]-1;\r\n int second = array[first]-1;\r\n int third = array[second];\r\n if (third==0){\r\n System.out.println(\"YES\");\r\n }\r\n else {\r\n System.out.println(\"NO\");\r\n }\r\n }\r\n catch (IndexOutOfBoundsException e){\r\n System.out.println(\"No\");\r\n }\r\n }\r\n }\r\n}\r\n", "src_uid": "5cd113a30bbbb93d8620a483d4da0349"} {"source_code": "import java.util.Scanner;\n\npublic class MahmoudAndEhabAndTheEvenOddgame {\n private static Scanner s = new Scanner(System.in);\n\n public static void main(String[] args) {\n int n = s.nextInt();\n if(n%2 == 0){\n System.out.println(\"Mahmoud\");\n }else\n System.out.println(\"Ehab\");\n }\n}\n", "src_uid": "5e74750f44142624e6da41d4b35beb9a"} {"source_code": "import java.util.*;\npublic class Main{\n\n public static void main(String[] args)\n {\n Scanner ab=new Scanner(System.in);\n int x=ab.nextInt();\n String c=ab.next();\n int sum1=0;\n char k[]=new char[x];\n c.getChars(0, x, k, 0);\n \n int sum=0;\n for(int g=0;g<x-1;g++)\n {\n if(k[g]=='?')\n continue;\n else\n if(k[g]==k[g+1])\n {\n sum++; \n }\n \n }\n if(x==1&&k[0]=='?')\n {\n System.out.println(\"Yes\");\n }\n else if(sum>0)\n System.out.println(\"No\");\n else\n {\n for(int u=0;u<x;u++)\n {\n if(k[u]=='Y'||k[u]=='M'||k[u]=='C')\n {\n continue;\n }\n else if(k[u]=='?')\n {\n for(int p=u;p<x;p++)\n {\n if(p==x-1&&k[p]=='?')\n {\n if((k[p-1]=='Y'||k[p-1]=='M'))\n {\n k[p]='C';\n sum1++;\n break;\n }\n \n else if ((k[p-1]=='Y'||k[p-1]=='C'))\n {\n k[p]='M';\n sum1++;\n break;\n }\n else if((k[p-1]=='M'||k[p-1]=='C'))\n {\n k[p]='Y';\n sum1++;\n break;\n }\n \n }\n \n \n \n if(p==0)\n {\n if(k[p+1]=='C')\n {\n k[p]='M';\n sum1++;\n }\n else if(k[p+1]=='M')\n {\n k[p]='Y';\n sum1++;\n }\n else if(k[p]=='Y')\n {\n k[p]='C';\n sum1++;\n }\n else if(k[p+1]=='?')\n {\n k[p]='C';\n sum1++;\n }\n \n }\n \n \n \n \n \n \n \n \n else if(p>0&&k[p]=='?')\n {\n if((k[p+1]=='C'/*||k[p+1]=='y'*/)&&(/*k[p-1]=='y'||*/k[p-1]=='C'))\n {\n k[p]='M';\n sum1++;\n \n }\n else if((/*k[p+1]=='c'||*/k[p+1]=='M')&&(/*k[p-1]=='c'||*/k[p-1]=='M'))\n {\n k[p]='Y';\n sum1++;\n \n }\n else if((k[p+1]=='Y'/*||k[p+1]=='m'*/)&&(k[p-1]=='Y'/*||k[p-1]=='m'*/))\n {\n k[p]='C';\n sum1++;\n }\n \n \n \n else if((k[p+1]=='C'||k[p+1]=='Y')&&(k[p-1]=='Y'||k[p-1]=='C'))\n {\n k[p]='M';\n \n \n }\n else if((k[p+1]=='C'||k[p+1]=='M')&&(k[p-1]=='C'||k[p-1]=='M'))\n {\n k[p]='Y';\n \n \n }\n else if((k[p+1]=='Y'||k[p+1]=='M')&&(k[p-1]=='Y'||k[p-1]=='M'))\n {\n k[p]='C';\n \n }\n \n \n \n else if(k[p+1]=='?')\n {\n if(k[p-1]=='M'||k[p-1]=='Y')\n {\n k[p]='C';\n sum1++;\n }\n else if(k[p-1]=='C'||k[p-1]=='Y')\n {\n k[p]='M';\n sum1++;\n }\n else if(k[p-1]=='C'||k[p-1]=='M')\n {\n k[p]='Y';\n sum1++;\n }\n }\n }\n \n \n \n \n }\n }\n \n }\n if (sum1>0)\n System.out.println(\"Yes\");\nelse\n System.out.println(\"No\");\n }\n\n }\n \n}\n", "src_uid": "f8adfa0dde7ac1363f269dbdf00212c3"} {"source_code": "import java.util.*;\nimport java.io.*;\npublic class Q1Div3 \n{\n\tpublic static void main(String args[]) throws Exception {\n\t\tScan scan = new Scan();\n\t\tPrint print = new Print();\n\t\tint N = scan.scanInt();\n\t\tint arr[]=new int[2];\n\t\tfor(int i=2;i<=Math.sqrt(N);i++)\n\t\t{\n\t\t\tif(N%i==0)\n\t\t\t{\n\t\t\t\tarr[0]=i;\n\t\t\t\tarr[1]=N/i;\n\t\t\t}\n\t\t}\n\t\t//System.out.println(pq.toString());\n\t\tprint.println(arr[0]+\"\"+arr[1]);\n\t\tprint.close();\n\t}\n\n\tstatic class Print {\n\t\tprivate final BufferedWriter bw;\n\n\t\tpublic Print() {\n\t\t\tthis.bw = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\t}\n\n\t\tpublic void print(Object object) throws IOException {\n\t\t\tbw.append(\"\" + object);\n\t\t}\n\n\t\tpublic void println(Object object) throws IOException {\n\t\t\tprint(object);\n\t\t\tbw.append(\"\\n\");\n\t\t}\n\n\t\tpublic void close() throws IOException {\n\t\t\tbw.close();\n\t\t}\n\t}\n\n\tstatic class Scan {\n\t\tprivate byte[] buf = new byte[1024 * 1024];\n\t\tprivate int index;\n\t\tprivate InputStream in;\n\t\tprivate int total;\n\n\t\tpublic Scan() {\n\t\t\tin = System.in;\n\t\t}\n\n\t\tpublic int scan() throws IOException {\n\t\t\tif (total < 0)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (index >= total) {\n\t\t\t\tindex = 0;\n\t\t\t\ttotal = in.read(buf);\n\t\t\t\tif (total <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[index++];\n\t\t}\n\n\t\tpublic int scanInt() throws IOException {\n\t\t\tint integer = 0;\n\t\t\tint n = scan();\n\t\t\twhile (isWhiteSpace(n))\n\t\t\t\tn = scan();\n\t\t\tint neg = 1;\n\t\t\tif (n == '-') {\n\t\t\t\tneg = -1;\n\t\t\t\tn = scan();\n\t\t\t}\n\t\t\twhile (!isWhiteSpace(n)) {\n\t\t\t\tif (n >= '0' && n <= '9') {\n\t\t\t\t\tinteger *= 10;\n\t\t\t\t\tinteger += n - '0';\n\t\t\t\t\tn = scan();\n\t\t\t\t} else\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\treturn neg * integer;\n\t\t}\n\n\t\tpublic double scanDouble() throws IOException {\n\t\t\tdouble doub = 0;\n\t\t\tint n = scan();\n\t\t\twhile (isWhiteSpace(n))\n\t\t\t\tn = scan();\n\t\t\tint neg = 1;\n\t\t\tif (n == '-') {\n\t\t\t\tneg = -1;\n\t\t\t\tn = scan();\n\t\t\t}\n\t\t\twhile (!isWhiteSpace(n) && n != '.') {\n\t\t\t\tif (n >= '0' && n <= '9') {\n\t\t\t\t\tdoub *= 10;\n\t\t\t\t\tdoub += n - '0';\n\t\t\t\t\tn = scan();\n\t\t\t\t} else\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (n == '.') {\n\t\t\t\tn = scan();\n\t\t\t\tdouble temp = 1;\n\t\t\t\twhile (!isWhiteSpace(n)) {\n\t\t\t\t\tif (n >= '0' && n <= '9') {\n\t\t\t\t\t\ttemp /= 10;\n\t\t\t\t\t\tdoub += (n - '0') * temp;\n\t\t\t\t\t\tn = scan();\n\t\t\t\t\t} else\n\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn doub * neg;\n\t\t}\n\n\t\tpublic long scanLong() throws IOException {\n\t\t\tlong ret = 0;\n\t\t\tlong c = scan();\n\t\t\twhile (c <= ' ') {\n\t\t\t\tc = scan();\n\t\t\t}\n\n\t\t\tboolean neg = (c == '-');\n\t\t\tif (neg) {\n\t\t\t\tc = scan();\n\t\t\t}\n\n\t\t\tdo {\n\t\t\t\tret = ret * 10 + c - '0';\n\t\t\t} while ((c = scan()) >= '0' && c <= '9');\n\n\t\t\tif (neg) {\n\t\t\t\treturn -ret;\n\t\t\t}\n\t\t\treturn ret;\n\t\t}\n\n\t\tpublic String scanString() throws IOException {\n\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\tint n = scan();\n\t\t\twhile (isWhiteSpace(n))\n\t\t\t\tn = scan();\n\t\t\twhile (!isWhiteSpace(n) || n == ' ') {\n\t\t\t\tsb.append((char) n);\n\t\t\t\tn = scan();\n\t\t\t}\n\t\t\treturn sb.toString();\n\t\t}\n\n\t\tprivate boolean isWhiteSpace(int n) {\n\t\t\tif (n == ' ' || n == '\\n' || n == '\\r' || n == '\\t' || n == -1)\n\t\t\t\treturn true;\n\t\t\treturn false;\n\t\t}\n\t}\n}\n", "src_uid": "7220f2da5081547a12118595bbeda4f6"} {"source_code": "import java.util.*;\nimport java.io.*;\npublic class C68C{\n static BufferedReader br;\n public static void main(String args[])throws Exception{\n br=new BufferedReader(new InputStreamReader(System.in));\n int nn[]=toIntArray();\n int n=nn[0];\n int locZ=nn[1];\n int locC=nn[2];\n \n String dir=toStr();\n String str=toStr();\n \n \n int ind=0;\n int steps=0;\n int firstN=1;\n int lastN=n;\n\n String h=\"to head\";\n String t=\"to tail\";\n\n while(ind<str.length()){\n steps++;\n if(ind==str.length()-1){\n if(str.charAt(ind)=='1'){\n System.out.println(\"Stowaway\");\n return;\n }\n }\n\n if(str.charAt(ind)=='0'){\n if(dir.equals(h)){\n if(locZ<locC){\n if(locZ>firstN){\n locZ--;\n }\n if(locC>firstN){\n locC--;\n if(locC==firstN)\n dir=t;\n }\n else{\n locC++;\n dir=t;\n }\n } \n else if(locZ>locC) {\n if(locC>firstN){\n locC--;\n if(locC==firstN)\n dir=t;\n }\n else{\n locC++;\n dir=t;\n }\n }\n }\n else{\n if(locZ>locC){\n if(locZ<lastN){\n locZ++;\n }\n if(locC<lastN){\n locC++;\n if(locC==lastN)\n dir=h;\n }\n else{\n locC--;\n dir=h;\n }\n }\n else if(locZ<locC){\n if(locC<lastN){\n locC++;\n if(locC==lastN)\n dir=h;\n }\n else{\n locC--;\n dir=h;\n }\n }\n }\n }\n else{\n if(dir.equals(h)){\n locZ=lastN;\n if(locC>firstN){\n locC--;\n if(locC==firstN)\n dir=t;\n }\n else{\n locC++;\n dir=t;\n }\n }\n else{\n locZ=firstN;\n \n if(locC<lastN){\n locC++;\n if(locC==lastN)\n dir=h;\n }\n else{\n locC--;\n dir=h;\n }\n }\n \n }\n if(locZ==locC){\n System.out.println(\"Controller \"+steps);\n \n return;\n }\n \n ind++;\n\n }\n\n System.out.println(\"Stowaway\");\n \n\n }\n\n\n /****************************************************************/\n public static int[] toIntArray()throws Exception{\n String str[]=br.readLine().split(\" \");\n int k[]=new int[str.length];\n for(int i=0;i<str.length;i++){\n k[i]=Integer.parseInt(str[i]);\n }\n return k;\n }\n public static int toInt()throws Exception{\n return Integer.parseInt(br.readLine());\n }\n public static long[] toLongArray()throws Exception{\n String str[]=br.readLine().split(\" \");\n long k[]=new long[str.length];\n for(int i=0;i<str.length;i++){\n k[i]=Long.parseLong(str[i]);\n }\n return k;\n }\n public static long toLong()throws Exception{\n return Long.parseLong(br.readLine());\n }\n public static double[] toDoubleArray()throws Exception{\n String str[]=br.readLine().split(\" \");\n double k[]=new double[str.length];\n for(int i=0;i<str.length;i++){\n k[i]=Double.parseDouble(str[i]);\n }\n return k;\n }\n public static double toDouble()throws Exception{\n return Double.parseDouble(br.readLine());\n }\n public static String toStr()throws Exception{\n return br.readLine();\n }\n public static String[] toStrArray()throws Exception{\n String str[]=br.readLine().split(\" \");\n return str;\n }\n /****************************************************************/\n\n}\n", "src_uid": "2222ce16926fdc697384add731819f75"} {"source_code": "import java.util.*;\nimport java.io.*;\nimport java.lang.*;\nimport java.math.*;\npublic class A {\n public static void main(String[] args) throws Exception {\n BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n // Scanner scan = new Scanner(System.in);\n // PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); \n // int n = Integer.parseInt(bf.readLine());\n StringTokenizer st = new StringTokenizer(bf.readLine());\n // int[] a = new int[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());\n int n = Integer.parseInt(st.nextToken());\n int R = Integer.parseInt(st.nextToken());\n int r = Integer.parseInt(st.nextToken());\n double hi = Math.PI/Math.asin(r/(R-r+0.0));\n if(hi - Math.ceil(hi) > -0.0000001) hi = 0.001 + hi;\n double cutoff = Math.round(Math.floor(hi));\n if(2*r > R) cutoff = 1;\n if(r > R) cutoff = 0;\n if(n <= cutoff) System.out.println(\"YES\"); else System.out.println(\"NO\");\n // int n = scan.nextInt();\n \n // out.close(); System.exit(0);\n }\n}\n", "src_uid": "2fedbfccd893cde8f2fab2b5bf6fb6f6"} {"source_code": "\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashSet;\nimport java.util.Set;\n\n/**\n *\n * @author Lenovo\n */\npublic class Main {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) throws IOException {\n // TODO code application logic here\n BufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n int[] input = parseArray(in);\n int n = input[0];\n int m = input[1];\n int[] typestable = parseArray(in);\n int s;\n\n int[] occ = new int[100];\n //ArrayList<Integer> types=new ArrayList<Integer>();\n //Set<Integer> mySet = Set.of(typestable);\n //Set<Integer> targetSet = new HashSet<Integer>();\n for (int i = 1; i <= 100.; i++) {\n occ[i-1] = occurence(i, typestable);\n }\n int res = 0;\n for (int ans = 1; ans <= m; ans++) {\n s = 0;\n for (int i = 1; i <= 100; i++) {\n s += occ[i-1] / ans;\n }\n if (s >= n) {\n res = ans;\n }\n }\n System.out.println(res);\n\n }\n\n static int[] parseArray(BufferedReader gi) throws IOException {\n String[] line = gi.readLine().trim().split(\" \");\n int[] rez = new int[line.length];\n for (int k = 0; k < line.length; k++) {\n rez[k] = Integer.parseInt(line[k]);\n }\n return rez;\n }\n\n static int occurence(int ent, int[] tab) {\n int occ = 0;\n for (int i = 0; i < tab.length; i++) {\n if (tab[i] == ent) {\n occ++;\n }\n }\n return occ;\n }\n\n}\n", "src_uid": "b7ef696a11ff96f2e9c31becc2ff50fe"} {"source_code": "import java.util.*;\npublic class Problem0171e {\n public static void main(String[] args) {\n System.out.println(\"INTERCAL\");\n }\n}\n", "src_uid": "ef8239a0f77c538d2d9b246b86be63fe"} {"source_code": "import java.util.Scanner;\nimport java.util.*;\n\npublic class T1 {\n\tpublic static void main(String args[]) {\n\t\tScanner abc = new Scanner(System.in);\n\t\tArrayList seq = new ArrayList();\n\t\tseq.add(0);\n\t\tfor (int i = 1; i <= 1000; i++) {\n\n\t\t\tif (i < 10){\n\t\t\t\tseq.add(i);\n\t\t\t}\n\t\t\telse if (i >= 10 && i < 100) {\n\t\t\t\tint j = i/10;\n\t\t\t\t\tseq.add(j);\n\t\t\t\t\tseq.add(i - (j * 10));\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t} else if (i >= 100 && i < 1000) {\n\t\t\t\tint j = i/100;\n\t\t\t\t\tseq.add(j);\n\t\t\t\t\tseq.add((i - (j * 100))/10);\n\t\t\t\t\tseq.add(i - (j * 100)-(((i - (j * 100))/10)*10));\n\t\t\t\t\n\t\t\t}else if (i>=1000){\n\t\t\t\tseq.add(1);\n\t\t\t\tseq.add(0);\n\t\t\t\tseq.add(0);\n\t\t\t\tseq.add(0);\n\t\t\t}\n\t\t}\n\t\tint n = abc.nextInt();\n\t\tSystem.out.println(seq.get(n));\n\t}\n}\n", "src_uid": "2d46e34839261eda822f0c23c6e19121"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class CF {\n\n\tint MAX = 50;\n\n\tlong[][] power(long n) {\n\t\tif (n == 0) {\n\t\t\tlong[][] res = new long[MAX][MAX];\n\t\t\tfor (int i = 0; i < MAX; i++)\n\t\t\t\tfor (int j = 0; j < MAX; j++)\n\t\t\t\t\tif (i != j)\n\t\t\t\t\t\tres[i][j] = Long.MAX_VALUE / 3;\n\t\t\t\t\telse\n\t\t\t\t\t\tres[i][j] = 0;\n\t\t\treturn res;\n\t\t} else {\n\t\t\tif (n == 1) {\n\t\t\t\treturn resOne;\n\t\t\t} else {\n\t\t\t\tlong[][] r1 = power(n / 2);\n\t\t\t\tlong[][] r2 = mul(r1, r1);\n\t\t\t\tif (n % 2 == 1) {\n\t\t\t\t\tr2 = mul(r2, resOne);\n\t\t\t\t}\n\t\t\t\treturn r2;\n\t\t\t}\n\t\t}\n\t}\n\n\tlong[][] mul(long[][] a, long[][] b) {\n\t\tlong[][] res = new long[MAX][MAX];\n\t\tfor (int i = 0; i < MAX; i++)\n\t\t\tArrays.fill(res[i], Long.MAX_VALUE / 3);\n\t\tfor (int i = 0; i < MAX; i++)\n\t\t\tfor (int j = 0; j < MAX; j++)\n\t\t\t\tfor (int k = 0; k < MAX; k++)\n\t\t\t\t\tres[i][k] = Math.min(res[i][k], a[i][j] + b[j][k]);\n\t\treturn res;\n\t}\n\n\tlong[][] resOne = new long[MAX][MAX];\n\n\tvoid solve() {\n\t\tint n = in.nextInt();\n\t\tint m = in.nextInt();\n\t\tint[] a = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = in.nextInt();\n\t\t}\n\t\tint[] b = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\tb[i] = in.nextInt();\n\t\tint cntHave = m;\n\t\tlong[][] dx = new long[MAX][MAX];\n\t\tfor (int i = 0; i < dx.length; i++)\n\t\t\tArrays.fill(dx[i], Long.MAX_VALUE / 2);\n\t\tfor (int st = 0; st < 1 << n; st++) {\n\t\t\tint curB = 0;\n\t\t\tint minB = 0;\n\t\t\tint cost = 0;\n\t\t\tfor (int i = 0; i < n; i++)\n\t\t\t\tif (((1 << i) & st) == 0) {\n\t\t\t\t\tcurB++;\n\t\t\t\t\tcost += a[i];\n\t\t\t\t} else {\n\t\t\t\t\tcurB--;\n\t\t\t\t\tminB = Math.min(minB, curB);\n\t\t\t\t\tcost += b[i];\n\t\t\t\t}\n\t\t\tdx[25 + minB][25 + curB] = Math.min(dx[25 + minB][25 + curB], cost);\n\t\t}\n\t\tfor (int i = 0; i < MAX; i++)\n\t\t\tArrays.fill(resOne[i], Long.MAX_VALUE / 3);\n\t\tfor (int i = 0; i < MAX; i++)\n\t\t\tfor (int j = 0; j < MAX; j++) {\n\t\t\t\tint curB = 25 + (j - i);\n\t\t\t\tif (curB < 0 || curB >= MAX)\n\t\t\t\t\tcontinue;\n\t\t\t\tfor (int sub = Math.max(0, 25 - i); sub < MAX; sub++)\n\t\t\t\t\tresOne[i][j] = Math.min(resOne[i][j], dx[sub][curB]);\n\t\t\t}\n\t\t\n\t\tlong[][] res = power(cntHave);\n\t\tout.println(res[0][0]);\n\t}\n\t\n\n\tFastScaner in;\n\tPrintWriter out;\n\n\tvoid run() {\n\t\tin = new FastScaner(System.in);\n\t\tout = new PrintWriter(System.out);\n\n\t\tsolve();\n\n\t\tout.close();\n\t}\n\n\tvoid runWithFiles() {\n\t\tin = new FastScaner(new File(\"input.txt\"));\n\t\ttry {\n\t\t\tout = new PrintWriter(new File(\"output.txt\"));\n\t\t} catch (FileNotFoundException e) {\n\t\t\te.printStackTrace();\n\t\t}\n\n\t\tsolve();\n\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tLocale.setDefault(Locale.US);\n\t\tnew CF().run();\n\t}\n\n\tclass FastScaner {\n\t\tBufferedReader br;\n\t\tStringTokenizer st;\n\n\t\tFastScaner(InputStream is) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(is));\n\t\t}\n\n\t\tFastScaner(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\tString next() {\n\t\t\twhile (st == null || !st.hasMoreElements()) {\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\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}", "src_uid": "f40900973f4ebeb6fdafd75ebe4e9601"} {"source_code": "\n\nimport java.util.Scanner;\n\n\npublic class Codeforce {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String c= sc.nextLine();\n String[] k= c.split(\" \");\n int l=Integer.parseInt(k[0]);\n int r=Integer.parseInt(k[1]);\n int a=Integer.parseInt(k[2]);\n if(l==r)\n {\n if((a % 2)==1)\n {\n a--;\n }\n System.out.println(l+r+a);\n }\n else\n {\n int m = l>r ? r : l;\n int n = l>r ? l : r;\n if((m+a)<=n)\n {\n System.out.println((m+a)*2);\n }\n else\n {\n int e=(((m+a)-n));\n if((e % 2)==1)\n {\n e--;\n }\n System.out.println((n*2)+e);\n }\n }\n \n }\n \n}\n", "src_uid": "e8148140e61baffd0878376ac5f3857c"} {"source_code": "import static java.lang.Integer.parseInt;\nimport static java.lang.Long.parseLong;\nimport static java.lang.Math.max;\nimport static java.lang.System.exit;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class D {\n\n\tstatic int gcd(int a, int b) {\n\t\treturn b == 0 ? a : gcd(b, a % b);\n\t}\n\n\tstatic void solve() throws Exception {\n\t\tint m = scanInt() + 1, a = scanInt(), b = scanInt();\n\t\tint cnt[] = new int[a + b];\n\t\tfor (int i = 0, j = 0;;) {\n\t\t\t++cnt[j];\n\t\t\tif (i >= b) {\n\t\t\t\ti -= b;\n\t\t\t} else {\n\t\t\t\ti += a;\n\t\t\t}\n\t\t\tif (i == 0) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tj = max(j, i);\n\t\t}\n\t\tfor (int i = 1; i < a + b; i++) {\n\t\t\tcnt[i] += cnt[i - 1];\n\t\t}\n\t\tlong ans = 0;\n\t\tfor (int i = 0; i < a + b && i < m; i++) {\n\t\t\tans += cnt[i];\n\t\t}\n\t\tif (m > a + b) {\n\t\t\tint g = gcd(a, b);\n\t\t\tint from = (a + b) / g, to = m / g;\n\t\t\tans += (long) (from + to + 1) * (to - from) / 2 * g;\n\t\t\tans += (long) (m % g) * (to + 1);\n\t\t}\n\t\tout.print(ans);\n\t}\n\n\tstatic int scanInt() throws IOException {\n\t\treturn parseInt(scanString());\n\t}\n\n\tstatic long scanLong() throws IOException {\n\t\treturn parseLong(scanString());\n\t}\n\n\tstatic String scanString() throws IOException {\n\t\twhile (tok == null || !tok.hasMoreTokens()) {\n\t\t\ttok = new StringTokenizer(in.readLine());\n\t\t}\n\t\treturn tok.nextToken();\n\t}\n\n\tstatic BufferedReader in;\n\tstatic PrintWriter out;\n\tstatic StringTokenizer tok;\n\n\tpublic static void main(String[] args) {\n\t\ttry {\n\t\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tout = new PrintWriter(System.out);\n\t\t\tsolve();\n\t\t\tin.close();\n\t\t\tout.close();\n\t\t} catch (Throwable e) {\n\t\t\te.printStackTrace();\n\t\t\texit(1);\n\t\t}\n\t}\n}", "src_uid": "d6290b69eddfcf5f131cc9e612ccab76"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.*;\n\nimport javax.naming.InitialContext;\n\n\npublic class C \n{\n\tpublic static void main(String [] args) throws IOException\n\t{\n\t\tBufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter writer = new PrintWriter(System.out);\n\t\t\n\t\tStringTokenizer tokenizer = new StringTokenizer(reader.readLine());\n\t\tint l1 = Integer.parseInt(tokenizer.nextToken()) - 1;\n\t\tint r1 = Integer.parseInt(tokenizer.nextToken()) - 1;\n\t\tint l2 = Integer.parseInt(tokenizer.nextToken()) - 1;\n\t\tint r2 = Integer.parseInt(tokenizer.nextToken()) - 1;\n\t\t\n\t\tSystem.out.println(rec((1<<30)-1, l1, r1, l2, r2));\n\t}\n\t\n\tprivate static int rec(int len, int l1, int r1, int l2, int r2)\n\t{\n\t\tif(r1 < l1 || r2 < l2)\n\t\t\treturn 0;\n\t\tif(len == 1)\n\t\t\treturn 1;\n\t\tif(l1 >= l2 && r1 <= r2)\n\t\t\treturn r1-l1+1;\n\t\tif(l2 >= l1 && r2 <= r1)\n\t\t\treturn r2-l2+1;\n\t\t\n\t\tint mid = len/2;\n\t\t\n\t\tif(l1 > l2)\n\t\t\treturn rec(len, l2, r2, l1, r1);\n\t\t\n\t\tif(r1 < mid && r2 < mid)\n\t\t\treturn rec(len/2, l1, r1, l2, r2);\n\t\tif(l1 > mid && l2 > mid)\n\t\t\treturn rec(len/2, l1-mid-1, r1-mid-1, l2-mid-1, r2-mid-1);\n\t\t\n\t\tif(r1 < mid && l2 > mid)\n\t\t\treturn rec(len/2, l1, r1, l2-mid-1, r2-mid-1);\n\t\tif(r1 < mid && l2 <= mid && r2 >= mid)\n\t\t\treturn Math.max(rec(len/2, l1, r1, l2, mid-1), rec(len/2, l1, r1, 0, r2-mid-1));\n\t\t\n\t\tif(l2 > mid)\n\t\t\treturn Math.max(rec(len/2, l1, mid-1, l2-mid-1, r2-mid-1), rec(len/2, 0, r1-mid-1, l2-mid-1, r2-mid-1));\n\t\t\n\t\t\n\t\treturn Math.max(r1-l2+1, Math.max(rec(len/2, l1, mid-1, 0, r2-mid-1), rec(len/2, l2, mid-1, 0, r1-mid-1)));\n\t}\n}", "src_uid": "fe3c0c4c7e9b3afebf2c958251f10513"} {"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.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\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 *\n * @author PersonOfInterest\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 CHexadecimalsNumbers solver = new CHexadecimalsNumbers();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class CHexadecimalsNumbers {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n long n = in.nextLong();\n Queue<Long> q = new LinkedList<>();\n q.offer(1L);\n long ans = 0;\n while (!q.isEmpty()) {\n long p = q.poll();\n ans++;\n\n p *= 10;\n if (p <= n) {\n q.offer(p);\n }\n if (p + 1 <= n) {\n q.offer(p + 1);\n }\n }\n out.println(ans);\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public long nextLong() {\n int c = read();\n while (isSpaceChar(c)) {\n c = read();\n }\n int sgn = 1;\n if (c == '-') {\n sgn = -1;\n c = read();\n }\n long res = 0;\n do {\n if (c < '0' || c > '9') {\n throw new InputMismatchException();\n }\n res *= 10;\n res += c - '0';\n c = read();\n } while (!isSpaceChar(c));\n return res * sgn;\n }\n\n public boolean isSpaceChar(int c) {\n if (filter != null) {\n return filter.isSpaceChar(c);\n }\n return isWhitespace(c);\n }\n\n public static boolean isWhitespace(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n }\n\n public interface SpaceCharFilter {\n public boolean isSpaceChar(int ch);\n\n }\n\n }\n\n static class OutputWriter {\n private final PrintWriter writer;\n\n public OutputWriter(OutputStream outputStream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n }\n\n public OutputWriter(Writer writer) {\n this.writer = new PrintWriter(writer);\n }\n\n public void close() {\n writer.close();\n }\n\n public void println(long i) {\n writer.println(i);\n }\n\n }\n}\n\n", "src_uid": "64a842f9a41f85a83b7d65bfbe21b6cb"} {"source_code": "import java.util.*;\r\npublic class Sol{\r\n public static void main(String args[]){\r\n Scanner sc = new Scanner(System.in);\r\n String s = sc.nextLine();\r\n int a = 0, b = 0,c = 0;\r\n int i = 2;\r\n while(i < s.length()) {\r\n \ta = s.charAt(i-2) - 'A'; \r\n \tb = s.charAt(i-1) - 'A';\r\n \tc = s.charAt(i) - 'A';\r\n// \tSystem.out.println(a+\" \"+b+\" = \"+c);\r\n \tif(c != (a + b)%26) {\r\n \t\tSystem.out.println(\"NO\");\r\n \t\treturn;\r\n \t}\r\n \ti++;\r\n }\r\n System.out.println(\"YES\");\r\n return;\r\n }\r\n}", "src_uid": "27e977b41f5b6970a032d13e53db2a6a"} {"source_code": "import java.util.*;\nimport java.io.*;\n\npublic class bobsAndStages {\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\tnew bobsAndStages().run();\n\t}\n}", "src_uid": "6afcdad100c8e2469fef5abcc5bd96c6"} {"source_code": "import java.io.*;\nimport java.util.*;\npublic class result\n{\n public static void main(String[] args)\n {\n int x,y,z;\n boolean flag = false;\n Scanner sc=new Scanner(System.in);\n x=sc.nextInt();\n y=sc.nextInt();\n z=sc.nextInt();\n if(z==0)\n {\n if(x>y)\n {\n System.out.println(\"+\");\n flag=true;\n }\n else if(x<y)\n {\n System.out.println(\"-\");\n flag=true;\n }\n else if(x==y)\n {\n System.out.println(\"0\");\n flag=true;\n }\n }\n else \n {\n if(x+z>=y&&y+z>=x)\n {\n System.out.println(\"?\");\n flag=true;\n }\n else if(x+z>y)\n {\n System.out.println(\"+\");\n flag=true;\n }\n else if(y+z>x)\n {\n System.out.println(\"-\");\n flag=true;\n }\n }\n if(flag==false)\n {\n System.out.println(\"?\");\n }\n }\n}", "src_uid": "66398694a4a142b4a4e709d059aca0fa"} {"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 F5 {\n\tScanner in;\n\tPrintWriter out;\n//\tString INPUT = \"100000 4\";\n//\tString INPUT = \"0 1\";\n\tString INPUT = \"\";\n\t\n\tint[] dec(int n, int m)\n\t{\n\t\tif(n <= m){\n\t\t\treturn new int[]{n, 0};\n\t\t}else if(n <= 2 * m){\n\t\t\treturn new int[]{n - m, n - m};\n\t\t}else{\n\t\t\treturn new int[]{n - 2 * m - 1, m};\n\t\t}\n\t}\n\t\n\tint enc(int x, int y, int m)\n\t{\n\t\tif(y == 0){\n\t\t\treturn x;\n\t\t}else if(x == y){\n\t\t\treturn x + m;\n\t\t}else{\n\t\t\treturn x + 2 * m + 1;\n\t\t}\n\t}\n\t\n\tvoid solve()\n\t{\n\t\tint m = ni();\n\t\tint n = ni();\n\t\tif(m <= 0){\n\t\t\tout.println(1);\n\t\t\treturn;\n\t\t}\n\t\tif(n <= 1){\n\t\t\tout.println(-1);\n\t\t\treturn;\n\t\t}\n\t\t\n//\t\tfor(int i = 0;i <= 3 * m;i++){\n//\t\t\tint[] co = dec(i, m);\n//\t\t\ttr(co);\n//\t\t\tif(enc(co[0], co[1], m) != i){\n//\t\t\t\ttr(\"out!\",i);\n//\t\t\t}\n//\t\t}\n\t\t\n//\t\tint[] co = {0, 0};\n//\t\t{\n//\t\t\tif(co[1] == 0){\n//\t\t\t\tint inf = co[0] + 1;\n//\t\t\t\tint sup = Math.min(m, co[0] + n);\n//\t\t\t\tif(inf <= sup){\n//\t\t\t\t\ttr(inf, 0, sup, 0, enc(inf, 0, m), enc(sup, 0, m));\n//\t\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//\n//\t\t\tif(inf <= sup){\n//\t\t\t\ttr(inf, inf, sup, sup, enc(inf, inf, m), enc(sup, sup, m));\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\ttr(inf, m, sup, m, enc(inf, m, m), enc(sup, m, m));\n//\t\t\t}\n//\t\t}\n//\t\t{\n//\t\t\tif(co[1] == m){\n//\t\t\t\tint inf = co[0] - 1;\n//\t\t\t\tint sup = Math.max(0, co[0] - n);\n//\t\t\t\tif(sup <= inf){\n//\t\t\t\t\ttr(sup, m, inf, m, enc(sup, m, m), enc(inf, m, m));\n//\t\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(1, (-n + co[0] + co[1] + 1) / 2);\n//\n////\t\t\tif(sup == 0)sup++;\n//\t\t\tif(sup <= inf){\n//\t\t\t\ttr(sup, sup, inf, inf, enc(sup, sup, m), enc(inf, inf, m));\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\ttr(sup, 0, inf, 0, enc(sup, 0, m), enc(inf, 0, m));\n//\t\t\t}\n//\t\t}\n\t\t\n\t\tif(n <= Math.sqrt(Math.sqrt(m))){\n\t\t\tsolveH(m, n);\n\t\t}else{\n\t\t\tsolveB(m, n);\n\t\t}\n\t}\n\t\n\tvoid solveB(int m, int n){\n\t\t\t// (a, 0), (a, a), (a, m)\n\t\t\tBitSet visitedo = new BitSet();\n\t\t\tBitSet visitedh = new BitSet();\n\t\t\tBitSet q = new BitSet();\n\t\t\tq.set(0);\n\t\t\tboolean iso = true;\n\t\t\tint step = 0;\n\t\t\t\n\t\t\twhile(!q.isEmpty()){\n\t\t\t\tif(!iso && q.get(2 * m))break;\n//\t\t\t\ttr(step, q);\n\t\t\t\tBitSet nq = new BitSet();\n\t\t\t\tif(iso){\n\t\t\t\t\tvisitedh.or(q);\n\t\t\t\t}else{\n\t\t\t\t\tvisitedo.or(q);\n\t\t\t\t}\n\t\t\t\tfor(int cur = q.nextSetBit(0);cur != -1;cur = q.nextSetBit(cur+1)){\n\t\t\t\t\tint[] co = dec(cur, m);\n\t\t\t\t\tif(iso){\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif(co[1] == 0){\n\t\t\t\t\t\t\t\tint inf = co[0] + 1;\n\t\t\t\t\t\t\t\tint sup = Math.min(m, co[0] + n);\n\t\t\t\t\t\t\t\tif(inf <= sup){\n\t\t\t\t\t\t\t\t\tnq.set(enc(inf, 0, m), enc(sup, 0, m) + 1);\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\t{\n\t\t\t\t\t\t\tint inf = Math.max(co[0], co[1]);\n\t\t\t\t\t\t\tif(co[0] == co[1])inf++;\n\t\t\t\t\t\t\tint sup = Math.min(m, (n + co[0] + co[1]) / 2);\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tif(inf <= sup){\n\t\t\t\t\t\t\t\tnq.set(enc(inf, inf, m), enc(sup, sup, m) + 1);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tint inf = co[0];\n\t\t\t\t\t\t\tif(co[1] == m)inf++;\n\t\t\t\t\t\t\tint sup = Math.min(m - 1, co[0] + n - m + co[1]);\n\t\t\t\t\t\t\tif(inf <= sup){\n\t\t\t\t\t\t\t\tnq.set(enc(inf, m, m), enc(sup, m, m) + 1);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}else{\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif(co[1] == m){\n\t\t\t\t\t\t\t\tint inf = co[0] - 1;\n\t\t\t\t\t\t\t\tint sup = Math.max(0, co[0] - n);\n\t\t\t\t\t\t\t\tif(sup <= inf){\n\t\t\t\t\t\t\t\t\tnq.set(enc(sup, m, m), enc(inf, m, m) + 1);\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\t{\n\t\t\t\t\t\t\tint inf = Math.min(co[0], co[1]);\n\t\t\t\t\t\t\tif(co[0] == co[1])inf--;\n\t\t\t\t\t\t\tint sup = Math.max(1, (-n + co[0] + co[1] + 1) / 2);\n\t\t\t\t\t\t\t\n//\t\t\t\t\t\t\tif(sup == 0)sup++;\n\t\t\t\t\t\t\tif(sup <= inf){\n\t\t\t\t\t\t\t\tnq.set(enc(sup, sup, m), enc(inf, inf, m) + 1);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tint inf = co[0];\n\t\t\t\t\t\t\tif(co[1] == 0)inf--;\n\t\t\t\t\t\t\tint sup = Math.max(0, co[0] - n + co[1]);\n\t\t\t\t\t\t\tif(sup <= inf){\n\t\t\t\t\t\t\t\tnq.set(enc(sup, 0, m), enc(inf, 0, m) + 1);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(iso){\n\t\t\t\t\tnq.andNot(visitedo);\n\t\t\t\t}else{\n\t\t\t\t\tnq.andNot(visitedh);\n\t\t\t\t}\n\t\t\t\tq = nq;\n\t\t\t\tstep++;\n\t\t\t\tiso = !iso;\n\t\t\t}\n\t\t\tif(q.isEmpty()){\n\t\t\t\tout.println(-1);\n\t\t\t}else{\n\t\t\t\tout.println(step);\n\t\t\t}\n\t}\n\t\n\tvoid solveH(int m, int n){\n\t\t\n\t\t// (a, 0), (a, a), (a, m)\n\t\tHashSet<Integer> visitedo = new HashSet<Integer>();\n\t\tHashSet<Integer> visitedh = new HashSet<Integer>();\n\t\tHashSet<Integer> q = new HashSet<Integer>();\n\t\tq.add(0);\n\t\tboolean iso = true;\n\t\tint step = 0;\n\t\t\n\t\twhile(!q.isEmpty()){\n\t\t\tif(!iso && q.contains(2 * m))break;\n//\t\t\ttr(step, q);\n\t\t\tHashSet<Integer> nq = new HashSet<Integer>();\n\t\t\tif(iso){\n\t\t\t\tvisitedh.addAll(q);\n\t\t\t}else{\n\t\t\t\tvisitedo.addAll(q);\n\t\t\t}\n\t\t\tfor(int cur : q){\n\t\t\t\tint[] co = dec(cur, m);\n\t\t\t\tif(iso){\n\t\t\t\t\t{\n\t\t\t\t\t\tif(co[1] == 0){\n\t\t\t\t\t\t\tint inf = co[0] + 1;\n\t\t\t\t\t\t\tint sup = Math.min(m, co[0] + n);\n\t\t\t\t\t\t\tif(inf <= sup){\n\t\t\t\t\t\t\t\tfor(int i = enc(inf, 0, m);i <= enc(sup, 0, m);i++){\n\t\t\t\t\t\t\t\t\tnq.add(i);\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\t{\n\t\t\t\t\t\tint inf = Math.max(co[0], co[1]);\n\t\t\t\t\t\tif(co[0] == co[1])inf++;\n\t\t\t\t\t\tint sup = Math.min(m, (n + co[0] + co[1]) / 2);\n\t\t\t\t\t\t\n\t\t\t\t\t\tif(inf == 0)inf = 1;\n\t\t\t\t\t\tif(inf <= sup){\n\t\t\t\t\t\t\tfor(int i = enc(inf, inf, m);i <= enc(sup, sup, m);i++){\n\t\t\t\t\t\t\t\tnq.add(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\t{\n\t\t\t\t\t\tint inf = co[0];\n\t\t\t\t\t\tif(co[1] == m)inf++;\n\t\t\t\t\t\tint sup = Math.min(m - 1, co[0] + n - m + co[1]);\n\t\t\t\t\t\tif(inf <= sup){\n\t\t\t\t\t\t\tfor(int i = enc(inf, m, m);i <= enc(sup, m, m);i++){\n\t\t\t\t\t\t\t\tnq.add(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}else{\n\t\t\t\t\t{\n\t\t\t\t\t\tif(co[1] == m){\n\t\t\t\t\t\t\tint inf = co[0] - 1;\n\t\t\t\t\t\t\tint sup = Math.max(0, co[0] - n);\n\t\t\t\t\t\t\tif(sup <= inf){\n\t\t\t\t\t\t\t\tfor(int i = enc(sup, m, m);i <= enc(inf, m, m);i++){\n\t\t\t\t\t\t\t\t\tnq.add(i);\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\t{\n\t\t\t\t\t\tint inf = Math.min(co[0], co[1]);\n\t\t\t\t\t\tif(co[0] == co[1])inf--;\n\t\t\t\t\t\tint sup = Math.max(1, (-n + co[0] + co[1] + 1) / 2);\n\t\t\t\t\t\t\n//\t\t\t\t\t\tif(sup == 0)sup++;\n\t\t\t\t\t\tif(sup <= inf){\n\t\t\t\t\t\t\tfor(int i = enc(sup, sup, m);i <= enc(inf, inf, m);i++){\n\t\t\t\t\t\t\t\tnq.add(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\t{\n\t\t\t\t\t\tint inf = co[0];\n\t\t\t\t\t\tif(co[1] == 0)inf--;\n\t\t\t\t\t\tint sup = Math.max(0, co[0] - n + co[1]);\n\t\t\t\t\t\tif(sup <= inf){\n\t\t\t\t\t\t\tfor(int i = enc(sup, 0, m);i <= enc(inf, 0, m);i++){\n\t\t\t\t\t\t\t\tnq.add(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}\n\t\t\tif(iso){\n\t\t\t\tnq.removeAll(visitedo);\n\t\t\t}else{\n\t\t\t\tnq.removeAll(visitedh);\n\t\t\t}\n\t\t\tq = nq;\n\t\t\tstep++;\n\t\t\tiso = !iso;\n\t\t}\n\t\tif(q.isEmpty()){\n\t\t\tout.println(-1);\n\t\t}else{\n\t\t\tout.println(step);\n\t\t}\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tin = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);\n\t\tout = new PrintWriter(System.out);\n\n\t\tout.println(INPUT);\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 F5().run();\n\t}\n\t\n\tint ni() { return Integer.parseInt(in.next()); }\n\tvoid tr(Object... o) { if(INPUT.length() != 0)System.out.println(o.length > 1 || o[0].getClass().isArray() ? Arrays.deepToString(o) : o[0]); }\n}\n", "src_uid": "83f1d50a1802e08dd154d4c9778e3d80"} {"source_code": "import java.awt.*;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.*;\nimport java.util.List;\n\n public class CandidateCode {\n public static void main(String args[]) throws IOException {\n Scanner sc = new Scanner(System.in);\n int n=sc.nextInt();\n long sum=0;\n for (int i=2;i<n;i++){\n int x=i*(i+1);\n sum+=x;\n }\n System.out.println(sum);\n }\n}\n\n", "src_uid": "1bd29d7a8793c22e81a1f6fd3991307a"} {"source_code": "import java.util.*;\nimport java.io.*;\n\npublic class e {\n public static int M = 10;\n public static void main(String[] args) throws Exception{\n FS sc = new FS(System.in);\n int n = sc.nextInt(), i;\n int[] arr = new int[n];\n for (i = 0; i < n; i++)\n arr[i] = sc.nextInt();\n Arrays.sort(arr);\n for (i = 0; i <= n/2; i++) {\n if (arr[i] != arr[0]) {\n System.out.println(\"Alice\");\n return;\n }\n }\n System.out.println(\"Bob\");\n }\n public static int gcd(int a, int b) {\n return (b == 0) ? a : gcd(b, a % b);\n }\n public static class FS {\n BufferedReader br;\n StringTokenizer st;\n FS(InputStream in) {\n br = new BufferedReader(new InputStreamReader(in));\n st = new StringTokenizer(\"\");\n }\n String next() throws Exception {\n if (st.hasMoreTokens())\n return st.nextToken();\n st = new StringTokenizer(br.readLine());\n return next();\n }\n int nextInt() throws Exception {\n return Integer.parseInt(next());\n }\n }\n}\n", "src_uid": "4b9cf82967aa8441e9af3db3101161e9"} {"source_code": "//package codeforces;\n\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.List;\nimport java.util.Scanner;\n\n/**\n * Created by nitin.s on 09/10/16.\n */\npublic class PashaAndHamsters {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt(), a = in.nextInt(), b = in.nextInt();\n int[] res = new int[n + 1];\n Arrays.fill(res, -1);\n for(int i = 0; i < a; ++i) {\n int apple = in.nextInt();\n if(res[apple] != -1) continue;\n res[apple] = 1;\n }\n for(int i = 0; i < b; ++i) {\n int apple = in.nextInt();\n if(res[apple] != -1) continue;\n res[apple] = 2;\n }\n for(int i = 1; i <= n; ++i) {\n System.out.print(res[i] + \" \");\n }\n }\n}\n", "src_uid": "a35a27754c9c095c6f1b2d4adccbfe93"} {"source_code": "import java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.Scanner;\n\n\npublic class Program {\n public static void main(String[] args) {\n Scanner inp = new Scanner(System.in);\n String str = inp.next();\n System.out.println(process(str));\n }\n\n public static String process(String str) {\n if (str.length() < 26) {\n return \"-1\";\n }\n int[] count = new int[26];\n for (int num : count) {\n num = 0;\n }\n int cntQuestions = 0;\n for (int i = 0; i < 25; ++i) {\n if (str.charAt(i) == '?') {\n ++cntQuestions;\n }\n else {\n ++count[str.charAt(i) - 'A'];\n }\n }\n for (int i = 25; i < str.length(); ++i) {\n if (str.charAt(i) == '?') {\n ++cntQuestions;\n }\n else {\n ++count[str.charAt(i) - 'A'];\n }\n\n int curCnt = 0;\n for (int num : count) {\n if (num != 0) {\n ++curCnt;\n }\n }\n if (curCnt + cntQuestions == 26) {\n String piece = \"\";\n int pos = 0;\n for (int k = i - 25; k <= i; ++k) {\n if (str.charAt(k) == '?') {\n while (count[pos] != 0) {\n ++pos;\n }\n piece += (char)(pos + 'A');\n ++pos;\n }\n else {\n piece += str.charAt(k);\n }\n }\n\n str = str.substring(0, i - 25) + piece + str.substring(i + 1, str.length());\n return str.replace(\"?\", \"A\");\n }\n\n if (str.charAt(i - 25) != '?') {\n --count[str.charAt(i - 25) - 'A'];\n }\n else {\n --cntQuestions;\n }\n }\n return \"-1\";\n }\n}", "src_uid": "a249431a4b0b1ade652997fe0b82edf3"} {"source_code": "import java.util.Scanner;\n\npublic class main {\n\n public static void main(String[] args) {\n int first_number;\n int second_number;\n String first = \"\";\n String rezult = \"\";\n String kol_number;\n String[] kol_split_number;\n String need_number;\n String[] need_split_number;\n\n\n\n Scanner in = new Scanner(System.in);\n //first_number = in.nextInt();\n //second_number = in.nextInt();\n first = in.nextLine();\n kol_number = in.nextLine();\n kol_split_number = kol_number.split(\" \");\n need_number = in.nextLine();\n need_split_number = need_number.split(\" \");\n\n\n for (String i : kol_split_number) {\n for (String j : need_split_number) {\n if ( i.equals(j) ) {\n rezult = rezult + \" \" + i;\n }\n }\n }\n System.out.println(rezult);\n }\n\n}\n", "src_uid": "f9044a4b4c3a0c2751217d9b31cd0c72"} {"source_code": "import java.io.BufferedReader;\nimport java.io.FileReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.util.ArrayList;\n\n\n\npublic class main{\n\n public static void main(String[] args) throws IOException {\n a w = new a();\n w.f();\n }\n\n}\nclass a{\n StreamTokenizer in;\n PrintWriter out;\n int n, a, b, k, flag;\n long inf;\n long[][] res;\n long[] sum;\n int[][] find;\n int nextInt() throws IOException{\n in.nextToken();\n return (int) in.nval;\n }\n long dp(int ind){\n return ((sum[find[ind][1]] - sum[find[ind][0]] + inf) % inf - res[(flag + 1) % 2][ind] + inf) % inf;\n }\n void f() throws IOException{\n in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n out = new PrintWriter(System.out);\n n = nextInt();\n a = nextInt();\n b = nextInt();\n k = nextInt();\n flag = 0;\n find = new int[n][2];\n for (int i = 0; i < n; i++){\n int l = -1; int r = n + 1;\n for (int j = 0; j < n; j++){\n if ((l == -1) && (Math.abs(i - j) < Math.abs(j - b + 1))){\n l = j;\n } else if ((l != -1) && (Math.abs(i - j) >= Math.abs(j - b + 1))){\n r = j;\n break;\n }\n }\n find[i][0] = Math.max(l, 0); find[i][1] = Math.min(r, n);\n }\n inf = 1000000000 + 7;\n sum = new long[n + 1];\n res = new long[2][n];\n res[1][a - 1] = 1;\n for (int i = 0; i < n; i++){\n if (Math.abs(a - 1 - i) < Math.abs(a - b)){\n res[1][i] = 1;\n }\n }\n res[1][a - 1] = 0;\n sum[1] = res[(flag + 1) % 2][0];\n for (int j = 2; j <= n; j++){\n sum[j] = sum[j - 1] + res[(flag + 1) % 2][j - 1];\n }\n \n for (int i = 0; i < k - 1; i++){\n for (int j = 0; j < n; j++){\n if (j != b - 1){\n res[flag % 2][j] = dp(j);\n }\n }\n flag++;\n sum[1] = res[(flag + 1) % 2][0];\n for (int j = 2; j <= n; j++){\n sum[j] = (sum[j - 1] + res[(flag + 1) % 2][j - 1]) % inf;\n }\n }\n out.println(sum[n]);\n out.flush();\n out.close();\n }\n}", "src_uid": "142b06ed43b3473513995de995e19fc3"} {"source_code": "//package eightvc.f;\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 F {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\tchar[] s;\n\tint pos, len;\n\tint mod = 1000000007;\n\tint emod = mod-1;\n\tlong modx = (long)mod*emod;\n\t\n\tlong[] tm = new long[64];\n\t\n\tlong tes(long nume, long mul)\n\t{\n\t\tlong B = mul;\n\t\tlong s0 = 1;\n\t\tlong s1 = 0;\n\t\tlong res1 = 0;\n\t\tfor(int d = 0;d < 63;d++){\n\t\t\tif(nume<<~d<0){\n\t\t\t\tres1 = (res1 * B + s1 + s0*((nume&(1L<<d)-1)%mod)) % mod;\n\t\t\t}\n//\t\t\ts1 = (s1 * (B+1) + (s0<<d)) % mod;\n\t\t\ts1 = (s1 * (B+1) + s0*((1L<<d)%mod)) % mod;\n\t\t\ts0 = s0 * (B+1) % mod;\n\t\t\tB = B * B % mod;\n\t\t}\n\t\treturn res1;\n\t}\n\t\n\tvoid solve()\n\t{\n\t\tfor(int i = 0;i < 63;i++){\n\t\t\ttm[i] = (1L<<i)%mod;\n\t\t}\n\t\t\n\t\ts = ns().toCharArray();\n\t\tpos = 0; len = s.length;\n\t\tModnum res = expr();\n\t\tassert pos == len;\n\t\tout.println(res.v);\n\t}\n\t\n\tModnum expr()\n\t{\n\t\tModnum t = term();\n\t\twhile(pos < len && s[pos] == '+'){\n\t\t\tpos++;\n\t\t\tModnum lt = term();\n\t\t\tt = concat(t, lt);\n\t\t}\n\t\treturn t;\n\t}\n\t\n\tModnum term()\n\t{\n\t\tModnum n = number();\n\t\tif(pos < len && s[pos] == '-'){\n\t\t\tpos++;\n\t\t\tModnum ln = number();\n\t\t\treturn range(n, ln);\n\t\t}\n\t\tif(pos < len && s[pos] == '('){\n\t\t\tpos++;\n\t\t\tModnum e = expr();\n\t\t\tassert s[pos] == ')';\n\t\t\tpos++;\n\t\t\treturn repeat(e, n);\n\t\t}\n\t\treturn n;\n\t}\n\t\n\tlong mul10(long v)\n\t{\n\t\tlong v2 = v + v;\n\t\tif(v2 >= modx)v2 -= modx;\n\t\tv = v2 * 5;\n\t\twhile(v >= modx)v -= modx;\n\t\treturn v;\n\t}\n\t\n\tModnum number()\n\t{\n\t\tlong vx = 0;\n\t\tint nlen = 0;\n\t\twhile(pos < len && s[pos] >= '0' && s[pos] <= '9'){\n\t\t\tvx = mul10(vx) + (s[pos]-'0');\n\t\t\tif(vx >= modx)vx -= modx;\n\t\t\tnlen++;\n\t\t\tpos++;\n\t\t}\n\t\tassert nlen != 0;\n\t\treturn new Modnum(vx%mod, nlen, vx);\n\t}\n\t\n\tModnum concat(Modnum a, Modnum b)\n\t{\n\t\treturn new Modnum(\n\t\t\t\t(a.v * pow(10, b.len, mod) + b.v)% mod,\n\t\t\t\t(a.len + b.len) % emod\n\t\t);\n\t}\n\t\n\tModnum range(Modnum a, Modnum b)\n\t{\n\t\tModnum ret = new Modnum(0, 0);\n\t\tlong t = pow(10, a.len, mod);\n\t\tlong px = powSafe(10, a.len-1, modx);\n\t\tfor(long i = a.len;i <= b.len;i++){\n\t\t\tlong npx = mul10(px);\n\t\t\tlong inf = i == a.len ? a.vx : px;\n\t\t\tlong sup = i == b.len ? b.vx : npx-1;\n\t\t\tif(sup < 0)sup += modx;\n\t\t\t\n\t\t\tlong num = sup-inf+1;\n\t\t\tif(num < 0)num += modx;\n\t\t\tlong base = (inf%mod)*sumGP(t, num, mod)%mod;\n\t\t\t// 0 1 ... sup-inf\n\t\t\t\n\t\t\tnum %= modx;\n\t\t\tlong mul = t;\n\t\t\tlong B = mul;\n\t\t\tlong s0 = 1;\n\t\t\tlong s1 = 0;\n\t\t\tlong res1 = 0;\n\t\t\tlong q = 0;\n\t\t\tfor(int d = 0;d < 63;d++){\n\t\t\t\tif(num<<~d<0){\n\t\t\t\t\tres1 = (res1 * B + s1 + s0*q) % mod;\n\t\t\t\t\tq += tm[d];\n\t\t\t\t\tif(q >= mod)q -= mod;\n\t\t\t\t}\n\t\t\t\ts1 = (s1 * (B+1) + s0*tm[d]) % mod;\n\t\t\t\ts0 = s0 * (B+1) % mod;\n\t\t\t\tB = B * B % mod;\n\t\t\t}\n\t\t\tt = t * 10 % mod;\n\t\t\tpx = npx;\n\t\t\t\n\t\t\tret = concat(ret, new Modnum((base+res1)%mod, i*(num%emod)%emod));\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tModnum repeat(Modnum a, Modnum rep)\n\t{\n\t\treturn new Modnum(\n\t\t\t\tsumGP(pow(10, a.len, mod), rep.vx, mod) * a.v % mod,\n\t\t\t\ta.len*(rep.vx%emod)%emod\n\t\t\t\t);\n\t}\n\t\n\tpublic static class Modnum\n\t{\n\t\tpublic long v;\n\t\tpublic long vx;\n\t\tpublic long len;\n\t\tpublic Modnum(long v, long len) {\n\t\t\tthis.v = v;\n\t\t\tthis.len = len;\n\t\t}\n\t\tpublic Modnum(long v, long len, long vx) {\n\t\t\tthis.v = v;\n\t\t\tthis.len = len;\n\t\t\tthis.vx = vx;\n\t\t}\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn \"Datum [v=\" + v + \", len=\" + len + \"]\";\n\t\t}\n\t}\n\t\n\tpublic static long powSafe(long a, long n, long mod)\n\t{\n//\t\ta %= mod;\n\t\tlong ret = 1; // 1%mod if mod=1,n=0\n\t\tint x = 63-Long.numberOfLeadingZeros(n);\n\t\tfor(;x >= 0;x--){\n\t\t\tret = mulEx(ret, ret, mod);\n\t\t\tif(n<<~x<0)ret = mulEx(ret, a, mod);\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tpublic static long mul(long a, long b, long mod)\n\t{\n\t\tif(a >= mod || a < 0)a %= mod;\n\t\tif(a < 0)a += mod;\n\t\tif(b >= mod || b < 0)b %= mod;\n\t\tif(b < 0)b += mod;\n\t\t\n\t\tlong ret = 0;\n\t\tint x = 63-Long.numberOfLeadingZeros(b);\n\t\tfor(;x >= 0;x--){\n\t\t\tret += ret;\n\t\t\tif(ret >= mod)ret -= mod;\n\t\t\tif(b<<~x<0){\n\t\t\t\tret += a;\n\t\t\t\tif(ret >= mod)ret -= mod;\n\t\t\t}\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tpublic static long mulEx(long a, long b, long mod)\n\t{\n\t\tif(a >= mod || a < 0)a %= mod;\n\t\tif(a < 0)a += mod;\n\t\tif(b >= mod || b < 0)b %= mod;\n\t\tif(b < 0)b += mod;\n\t\t\n\t\tlong ret = 0;\n\t\tint x = 63-Long.numberOfLeadingZeros(b);\n\t\tfor(;x >= 0;x--){\n\t\t\tret += ret;\n\t\t\tif(Long.compareUnsigned(ret, mod) >= 0)ret -= mod;\n\t\t\tif(b<<~x<0){\n\t\t\t\tret += a;\n\t\t\t\tif(Long.compareUnsigned(ret, mod) >= 0)ret -= mod;\n\t\t\t}\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tpublic static long sumGP(long a, long n, long mod)\n\t{\n\t\tlong smul = 1; // % mod\n\t\tlong mul = a % mod;\n\t\tlong ret = 0;\n\t\tfor(;n > 0;n >>>= 1){\n\t\t\tif((n&1)==1){\n\t\t\t\tret = (ret * mul + smul) % mod;\n\t\t\t}\n\t\t\tsmul = smul * (mul + 1) % mod;\n\t\t\tmul = mul * mul % mod;\n\t\t}\n\t\treturn ret;\n\t}\n\t\n\tpublic static long pow(long a, long n, long mod) {\n\t\t//\t\ta %= mod;\n\t\tlong ret = 1;\n\t\tint x = 63 - Long.numberOfLeadingZeros(n);\n\t\tfor (; x >= 0; x--) {\n\t\t\tret = ret * ret % mod;\n\t\t\tif (n << 63 - x < 0)\n\t\t\t\tret = ret * a % mod;\n\t\t}\n\t\treturn ret;\n\t}\n\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", "src_uid": "0617f1ffa520d5b96232a4cfd9a15d0c"} {"source_code": "//package cdr;\nimport java.util.*;\nimport java.math.*;\nimport java.io.*;\n\npublic class Luck{\n\tpublic static InputReader sc;\n public static PrintWriter out;\n public static final int MOD = (int) (1e9 + 7);\n public static void main(String[] args){\n \tsc=new InputReader(System.in);\n \tout=new PrintWriter(System.out);\n \tint n=sc.nextInt();\n \tint min=Integer.MAX_VALUE;\n \tint a=0;\n \tint b=0;\n \tfor(int i=1;i<=Math.ceil(((double)n/2));i++){\n \t\tif(n%i==0){\n \t\t\tint temp=n/i;\n \t\t\tif(temp>i){\n \t\t\t\tif(temp-i<min){\n \t\t\t\t\tmin=temp-i;\n \t\t\t\t\tb=temp;\n \t\t\t\t\ta=i;\n \t\t\t\t}\n \t\t\t}\n \t\t\telse{\n \t\t\t\tif(i-temp<min){\n \t\t\t\t\tmin=i-temp;\n \t\t\t\t\tb=i;\n \t\t\t\t\ta=temp;\n \t\t\t\t}\n \t\t\t}\n \t\t}\n \t}\n \tout.println(a+\" \"+b);\n \tout.close();\n }\n \n static int gcd(int a,int b){\n \tif(b==0){\n \t\treturn a;\n \t}\n \treturn gcd(b,a%b);\n }\n static int lcm(int a,int b){\n \tint g;\n \tif(a<b){\n \t\tg=gcd(b,a);\n \t}\n \telse{\n \t\tg=gcd(a,b);\n \t}\n \treturn (a*b)/g;\n }\n \n static boolean isPrime(int n){\n \t if (n == 2)\n \t return true;\n \t for (long i = 2; i * i <= n; i++) {\n \t if (n % i == 0)\n \t return false;\n \t }\n \t return true;\n }\n \n static void shuffle(int[] A){\n \tfor(int i=A.length-1;i>0;i--){\n \t\tint j=(int)(Math.random()*(i+1));\n \t\tint temp=A[j];\n \t\tA[j]=A[i];\n \t\tA[i]=temp;\n \t}\n }\n \n\tpublic static class Node implements Comparable<Node>{\n\t int next;\n\t int dist;\n\t \n\t public Node (int u, int v) {\n\t this.next = u;\n\t this.dist = v;\n\t }\n\t \n\t public void print() {\n\t out.println(next + \" \" + dist + \" \");\n\t }\n\t \n\t public int compareTo(Node n) {\n\t return Integer.compare(-this.next, -n.next);\n\t }\n\t}\n\n\tpublic static BigInteger pow(BigInteger base, BigInteger exp) {\n\t if(exp.equals(new BigInteger(String.valueOf(0)))){\n\t return new BigInteger(String.valueOf(1));\n\t } \n\t if(exp.equals(new BigInteger(String.valueOf(1))))\n\t return base;\n\t BigInteger temp=exp.divide(new BigInteger(String.valueOf(2)));\n\t BigInteger val = pow(base, temp);\n\t BigInteger result = val.multiply(val);\n\t result=result.remainder(new BigInteger(String.valueOf(MOD)));\n\t BigInteger AND=exp.and(new BigInteger(String.valueOf(1)));\n\t if(AND.equals(new BigInteger(String.valueOf(1)))){\n\t result = result.multiply(base);\n\t result=result.remainder(new BigInteger(String.valueOf(MOD)));\n\t } \n\t return result;\n\t}\n\t \n\tstatic class InputReader {\n\n\t private InputStream stream;\n\t private byte[] buf = new byte[8192];\n\t private int curChar, snumChars;\n\t private SpaceCharFilter filter;\n\n\t public InputReader(InputStream stream) {\n\t this.stream = stream;\n\t }\n\n\t public int snext() {\n\t if (snumChars == -1)\n\t throw new InputMismatchException();\n\t if (curChar >= snumChars) {\n\t curChar = 0;\n\t try {\n\t snumChars = stream.read(buf);\n\t } catch (IOException e) {\n\t throw new InputMismatchException();\n\t }\n\t if (snumChars <= 0)\n\t return -1;\n\t }\n\t return buf[curChar++];\n\t }\n\n\t public int nextInt() {\n\t int c = snext();\n\t while (isSpaceChar(c))\n\t c = snext();\n\t int sgn = 1;\n\t if (c == '-') {\n\t sgn = -1;\n\t c = snext();\n\t }\n\t int res = 0;\n\t do {\n\t if (c < '0' || c > '9')\n\t throw new InputMismatchException();\n\t res *= 10;\n\t res += c - '0';\n\t c = snext();\n\t } while (!isSpaceChar(c));\n\t return res * sgn;\n\t }\n\n\t public long nextLong() {\n\t int c = snext();\n\t while (isSpaceChar(c))\n\t c = snext();\n\t int sgn = 1;\n\t if (c == '-') {\n\t sgn = -1;\n\t c = snext();\n\t }\n\t long res = 0;\n\t do {\n\t if (c < '0' || c > '9')\n\t throw new InputMismatchException();\n\t res *= 10;\n\t res += c - '0';\n\t c = snext();\n\t } while (!isSpaceChar(c));\n\t return res * sgn;\n\t }\n\n\t public int[] nextIntArray(int n) {\n\t int a[] = new int[n];\n\t for (int i = 0; i < n; i++)\n\t a[i] = nextInt();\n\t return a;\n\t }\n\n\t public String readString() {\n\t int c = snext();\n\t while (isSpaceChar(c))\n\t c = snext();\n\t StringBuilder res = new StringBuilder();\n\t do {\n\t res.appendCodePoint(c);\n\t c = snext();\n\t } while (!isSpaceChar(c));\n\t return res.toString();\n\t }\n\n\t public boolean isSpaceChar(int c) {\n\t if (filter != null)\n\t return filter.isSpaceChar(c);\n\t return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t }\n\n\t public interface SpaceCharFilter {\n\t public boolean isSpaceChar(int ch);\n\t }\n\t}\n\n}\n\n", "src_uid": "f52af273954798a4ae38a1378bfbf77a"} {"source_code": "import java.io.*;\nimport java.lang.Math;\nimport java.util.*;\n\n\npublic class Main {\n\n public BufferedReader in;\n public PrintStream out;\n\n public boolean log_enabled = false;\n \n public boolean multiply_tests = false;\n\n private class TestCase {\n \n public long modInv(long a, long n) {\n\t long i = n, v = 0, d = 1;\n\t while (a>0) {\n\t long t = i/a, x = a;\n\t a = i % x;\n\t i = x;\n\t x = d;\n\t d = v - t*x;\n\t v = x;\n\t }\n\t v %= n;\n\t if (v<0) v = (v+n)%n;\n\t return v;\n\t}\n\n public Object solve() {\n \n long M = 1000000007;\n int n = readInt();\n long x = 1;\n \n long r;\n for (r=2; r<=n; r++)\n {\n x = (x*r)%M;\n }\n \n int i;\n \n long S = 0;\n \n long c = 1;\n for (i=0; i<n; i++)\n {\n if (i==0)\n {\n c = 1;\n }\n else\n {\n c = (c * (n-1-(i-1))) % M;\n c = c * modInv(i, M) % M;\n }\n \n S = (S+c) % M;\n }\n \n return (x+M-S) % M;\n \n //return strf(\"%f\", 0);\n \n //out.printf(\"Case #%d: \\n\", caseNumber);\n //return null;\n }\n \n public int caseNumber;\n \n TestCase(int number) {\n caseNumber = number;\n }\n \n public void run(){\n Object r = this.solve();\n \n if ((r != null))\n {\n //outputCaseNumber(r);\n out.println(r);\n }\n }\n \n public String impossible(){\n return \"IMPOSSIBLE\";\n }\n \n public String strf(String format, Object... args)\n {\n return String.format(format, args);\n }\n \n// public void outputCaseNumber(Object r){\n// //out.printf(\"Case #%d:\", caseNumber);\n// if (r != null)\n// {\n// // out.print(\" \");\n// out.print(r);\n// }\n// out.print(\"\\n\");\n// }\n }\n\n public void run() {\n //while (true)\n {\n int t = multiply_tests ? readInt() : 1;\n for (int i = 0; i < t; i++) {\n TestCase T = new TestCase(i + 1);\n T.run();\n }\n }\n }\n \n\n \n public Main(BufferedReader _in, PrintStream _out){\n in = _in;\n out = _out;\n }\n \n\n public static void main(String args[]) {\n Locale.setDefault(Locale.US);\n Main S;\n try {\n S = new Main(\n new BufferedReader(new InputStreamReader(System.in)),\n System.out\n );\n } catch (Exception e) {\n return;\n }\n \n S.run();\n \n }\n\n private StringTokenizer tokenizer = null;\n\n public int readInt() {\n return Integer.parseInt(readToken());\n }\n\n public long readLong() {\n return Long.parseLong(readToken());\n }\n\n public double readDouble() {\n return Double.parseDouble(readToken());\n }\n\n public String readLn() {\n try {\n String s;\n while ((s = in.readLine()).length() == 0);\n return s;\n } catch (Exception e) {\n return \"\";\n }\n }\n\n public String readToken() {\n try {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(in.readLine());\n }\n return tokenizer.nextToken();\n } catch (Exception e) {\n return \"\";\n }\n }\n\n public int[] readIntArray(int n) {\n int[] x = new int[n];\n readIntArray(x, n);\n return x;\n }\n\n public void readIntArray(int[] x, int n) {\n for (int i = 0; i < n; i++) {\n x[i] = readInt();\n }\n }\n \n public long[] readLongArray(int n) {\n long[] x = new long[n];\n readLongArray(x, n);\n return x;\n }\n\n public void readLongArray(long[] x, int n) {\n for (int i = 0; i < n; i++) {\n x[i] = readLong();\n }\n }\n\n public void logWrite(String format, Object... args) {\n if (!log_enabled) {\n return;\n }\n\n out.printf(format, args);\n }\n}\n", "src_uid": "3dc1ee09016a25421ae371fa8005fce1"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class YetAnotherNumGame {\n\tstatic BufferedReader in;\n\tstatic StringTokenizer st;\n\t\n\tstatic String nextToken() throws IOException {\n\t\tif (st==null || !st.hasMoreElements())\n\t\t\tst = new StringTokenizer(in.readLine());\n\t\treturn st.nextToken();\n\t}\n\t\n\tstatic int nextInt() throws IOException {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\n\t\t\n\t\tint n = nextInt();\n\t\tif (n==1) {\n\t\t\tSystem.out.println(nextInt()==0?\"BitAryo\":\"BitLGM\");\n\t\t} else if (n==3) {\n\t\t\tint ans = 0;\n\t\t\tfor (int i=0; i<3; i++)\n\t\t\t\tans ^= nextInt();\n\t\t\tSystem.out.println(ans==0?\"BitAryo\":\"BitLGM\");\n\t\t} else {\n\t\t\tint[] max = new int[2];\n\t\t\tfor (int i=0; i<n; i++)\n\t\t\t\tmax[i] = nextInt();\n\t\t\t\n\t\t\tboolean[][] dp = new boolean[max[0]+1][max[1]+1];\n\t\t\t//true if going first wins\n\t\t\tfor (int i=0; i<=max[0]; i++) {\n\t\t\t\tfor (int j=0; j<=max[1]; j++) {\n\t\t\t\t\tif (i==0 && j==0) continue;\n\t\t\t\t\tfor (int m=1; m<=i && !dp[i][j]; m++)\n\t\t\t\t\t\tif (!dp[i-m][j]) dp[i][j] = true;\n\t\t\t\t\tfor (int m=1; m<=j && !dp[i][j]; m++)\n\t\t\t\t\t\tif (!dp[i][j-m]) dp[i][j] = true;\n\t\t\t\t\tfor (int m=1; m<=j && m<=i && !dp[i][j]; m++)\n\t\t\t\t\t\tif (!dp[i-m][j-m]) dp[i][j] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tSystem.out.println(dp[max[0]][max[1]]?\"BitLGM\":\"BitAryo\");\n\t\t}\n\t}\n}\n", "src_uid": "7a33b4f94082c7ef80d7e87b58497fa7"} {"source_code": "import java.util.*;\npublic class CF784F {\n public static void main(String[] args){\n Scanner sc = new Scanner(System.in);\n long time = System.currentTimeMillis();\n StringTokenizer s = new StringTokenizer(sc.nextLine());\n int n = Integer.parseInt(s.nextToken());\n long[] a = new long[n];\n for(int i = 0; i < n; i++){\n a[i] = Long.parseLong(s.nextToken());\n }\n Arrays.sort(a);\n while(System.currentTimeMillis() - time < 1000){}\n for(long i : a){\n System.out.print(i + \" \");\n }\n }\n}", "src_uid": "29e481abfa9ad1f18e6157c9e833f16e"} {"source_code": "import java.util.Scanner;\n\n\npublic class CF_171A {\n\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint i = in.nextInt();\n\t\tint j = Integer.parseInt(new StringBuffer(in.next()).reverse().toString());\n\t\t\n\t\tSystem.out.println(i + j);\n\n\t}\n\n}\n", "src_uid": "69b219054cad0844fc4f15df463e09c0"} {"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<M extends NumberTheory.Modulus<M>> {\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<NumberTheory.Mod998> {\n public long modulus() {\n return 998_244_353L;\n }\n\n }\n\n }\n}\n\n", "src_uid": "9f2b59df7bef2aeee0ce71facd2b1613"} {"source_code": "import java.util.Scanner;\n\npublic class C {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\tScanner s = new Scanner(System.in);\n\t\tlong n = s.nextLong();\n//\t\tSystem.out.println(Long.MAX_VALUE);\n\t\tlong prev = 1;\n\t\tlong cur = 1;\n\t\tlong wins = 0;\n\t\twhile (cur <= n) {\n\t\t\tlong temp = cur;\n\t\t\tcur = prev+cur;\n\t\t\tprev = temp;\n\t\t\twins++;\n\t\t}\n\t\tSystem.out.println(wins-1);\n\t\t\n\n\t}\n\n}\n", "src_uid": "3d3432b4f7c6a3b901161fa24b415b14"} {"source_code": "import java.util.*;\nimport java.io.*;\npublic class vvvv\n{\n static final FS s = new FS();\n static class FS {\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(\"\");\n\t\tString next() {\n\t\t\twhile(!st.hasMoreElements()) {\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}\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}\n\tpublic static void main(String args[])\n\t{\n\t int t=s.nextInt();\n\t outer:for(int i=0;i<t;i++)\n\t {\n\t int n=s.nextInt();\n\t for(int j=2;j<=Math.sqrt(n);j++)\n\t {\n\t if((n%j)==0)\n\t {\n\t System.out.println((n/j)+\" \"+(n-(n/j)));\n\t continue outer;\n\t }\n\t }\n\t System.out.println(\"1 \"+(n-1));\n\t }\n\t }\n\t }\n\t ", "src_uid": "3fd60db24b1873e906d6dee9c2508ac5"} {"source_code": "import java.util.Scanner;\n\n\npublic class CorrectWord {\n \n public static void main(String[] args) \n {\n \t\tScanner in=new Scanner(System.in);\n\t\tint n=in.nextInt();\n\t\tString s=in.next();\n\t\tSystem.out.println(s.replaceAll(\"([aeiouy])([aeiouy])+\",\"$1\"));\n\t}\n}", "src_uid": "63a4a5795d94f698b0912bb8d4cdf690"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\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());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n \n public int nextInt() {\n return Integer.parseInt(next());\n }\n \n public double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n \n static class OutputWriter {\n PrintWriter writer;\n \n public OutputWriter(OutputStream stream) {\n writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream)));\n }\n \n public <T> void print(T x) {\n writer.print(x);\n }\n \n public <T> void println(T x) {\n writer.println(x);\n }\n \n public void close() {\n writer.close();\n }\n }\n \n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n Task t = new Task();\n t.solve(in, out);\n out.close();\n }\n \n static class Task {\n private long cnk2(int n) { \n return ((long)n * (n - 1)) / 2;\n }\n \n private long cnk3(int n) {\n return ((long)n * (n - 1) / 2 * (n - 2) / 3);\n }\n \n private long foo(int A, int B, int C, int L) {\n if (A > C || B > C) return 0;\n int upperBound = Math.min(L, C - A - B);\n if (upperBound < 0) return 0;\n return cnk2(upperBound + 2);\n }\n \n public void solve(InputReader in, OutputWriter out) {\n int A, B, C, L;\n A = in.nextInt();\n B = in.nextInt();\n C = in.nextInt();\n L = in.nextInt();\n \n long result = 0;\n \n for (int x = 0; x <= L; x++) {\n result += foo(A, B, C + x, L - x);\n result += foo(A, C, B + x, L - x);\n result += foo(B, C, A + x, L - x);\n }\n \n out.println(cnk3(L + 3) - result);\n }\n }\n}\n", "src_uid": "185ff90a8b0ae0e2b75605f772589410"} {"source_code": "import static java.lang.System.out;\n\nimport java.util.Scanner;\npublic class LLPS {\n\n\tpublic static void main(String[] args) {\n\t\t\n\t\tScanner scanner = new Scanner(System.in);\n\t\tif (scanner.hasNextLine()){\n\t\t\tString line = scanner.nextLine();\n\t\t\tif (line.length()== 0 || line.length() > 10)\n\t\t\t\tthrow new IllegalArgumentException(\"Invalid length : \" + line.length());\n\t\t\tout.println(largestPa(line));\n\t\t\t\n\t\t}\n\t}\n\t\n\tpublic static String largestPa(String str){\n\t\tif (str == null || str.length() == 0) return \"\";\n\t\tint[] cache = new int[26];\n\t\tfor(int i=0; i<str.length(); i++){\n\t\t\tchar c = str.charAt(i);\n\t\t\tif (c <'a' || c >'z')\n\t\t\t\tthrow new IllegalArgumentException(\"Invalid char found in input : \" + c);\n\t\t\tcache[c - 'a']++;\n\t\t}\n\t\tfor (int i = cache.length-1; i>=0; i--){\n\t\t\tif (cache[i] >0){\n\t\t\t\tchar[] ch = new char[cache[i]];\n\t\t\t\tfor(int j=0; j<ch.length; j++)\n\t\t\t\t\tch[j] = (char)(((int)'a') + i);\n\t\t\t\treturn new String(ch);\n\t\t\t}\n\t\t}\n\t\treturn \"\";\n\t}\n}", "src_uid": "9a40e9b122962a1f83b74ddee6246a40"} {"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 E4 {\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<VecL[]> 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<Edge> es[] = new ArrayDeque[N];\n\t\tfor(int i = 0; i < N; i++) es[i] = new ArrayDeque<Edge>();\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<VecL> left = new ArrayList<VecL>();\n\t\tArrayList<VecL> right = new ArrayList<VecL>();\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<VecL> 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<Edge> 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<Edge> 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[] c1, VecL[] c2) {\n\t\tint n = c1.length, m = c2.length;\n\t\tif(n == 1) return simple(c1, c2);\n\t\tif(m == 1) return simple(c2, c1);\n\t\tVecL[] hull = new VecL[n+m];\n\t\tSegL[] s1 = toSeg(c1);\n\t\tSegL[] s2 = toSeg(c2);\n\t\tint nst = getSt(s1), mst = getSt(s2);\n\t\tint rId = 0, ni = nst, mi = mst;\n\t\thull[rId++] = s1[ni].from.add(s2[mi].from);\n\t\twhile(rId < n+m) {\n\t\t\tif(better(ni,mi,s1,s2)) {\n\t\t\t\thull[rId] = hull[rId++-1].add(s1[ni++].dir);\n\t\t\t\tif(ni >= n) ni = 0;\n\t\t\t\tif(ni == nst) ni = -1;\n\t\t\t}\n\t\t\telse {\n\t\t\t\thull[rId] = hull[rId++-1].add(s2[mi++].dir);\n\t\t\t\tif(mi >= m) mi = 0;\n\t\t\t\tif(mi == mst) mi = -1;\n\t\t\t}\n//\t\t\trId++;\n\t\t}\n\t\tVecL[] res = new VecL[n+m];\n\t\tint cId = 0;\n\t\tfor(int i = 0; i < hull.length; i++) {\n\t\t\tif(valid(hull[(i-1+hull.length)%hull.length], hull[i], hull[(i+1)%hull.length])) res[cId++] = hull[i];\n\t\t}\n\t\t\n\t\treturn Arrays.copyOf(res, cId);\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<VecL> points) {\n\t\tHashSet<VecL> 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; i<n; i++) {\n\t\t\tVecL p=points[i];\n\t\t\twhile (j>1&&!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; i<k; i++) res[i]=up[i];\n\t\tfor (int i=1; i<j-1; i++) res[k+i-1]=lo[i];\n\t\treturn res;\n\t}\n\n\t// check if a->b->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<VecL>{\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<Line> hull;\n\t\tint type; boolean query = false;\n\t\tComparator<Line> comp = new Comparator<Line>() {\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}", "src_uid": "7bccdabeb9f16ee0b4f16c37de564c31"} {"source_code": "import java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\nimport java.util.HashMap;\r\nimport java.util.StringTokenizer;\r\npublic class Main {\r\n static class MyScanner {\r\n BufferedReader br;\r\n StringTokenizer st;\r\n\r\n public MyScanner() {\r\n br = new BufferedReader(new InputStreamReader(System.in));\r\n }\r\n\r\n String next() {\r\n while (st == null || !st.hasMoreElements()) {\r\n try {\r\n st = new StringTokenizer(br.readLine());\r\n } catch (IOException e) {\r\n e.printStackTrace();\r\n }\r\n }\r\n return st.nextToken();\r\n }\r\n\r\n public int nextInt() {\r\n return Integer.parseInt(next());\r\n }\r\n\r\n long nextLong() {\r\n return Long.parseLong(next());\r\n }\r\n\r\n double nextDouble() {\r\n return Double.parseDouble(next());\r\n }\r\n\r\n public String nextLine(){\r\n String str = \"\";\r\n try {\r\n str = br.readLine();\r\n } catch (IOException e) {\r\n e.printStackTrace();\r\n }\r\n return str;\r\n }\r\n }\r\n\r\n static MyScanner s=new MyScanner();\r\n \r\n public static int process(int a,int k) {\r\n\t long ans=1;\r\n\t for(int i=0;i<a;i++)ans*=10;\r\n\t return (int)ans%k;\r\n }\r\n static int[]arr=new int[100010];\r\n static int mod=(int)1e9+7;\r\n static {\r\n\t arr[0]=1;\r\n\t for(int i=1;i<=100000;i++) {\r\n\t\t arr[i]=((arr[i-1]%mod)*2)%mod;\r\n\t }\r\n }\r\n static class Info{\r\n int x;int y;\r\n public Info(){}\r\n public Info(int x,int y){\r\n this.x=x;this.y=y;\r\n }\r\n }\r\n public static Info exgcd(int a,int b){\r\n if(b==0){\r\n return new Info(1,0);\r\n }\r\n Info info=exgcd(b,a%b);\r\n return new Info(info.y,info.x-a/b*info.y);\r\n }\r\npublic static void main(String[] args) {\r\nint K=1;\r\nint N=10,M=10;\r\nwhile(K>0) {\r\n int n=s.nextInt(),k=s.nextInt();\r\n if(k>=n){\r\n System.out.println(arr[n]);\r\n break;\r\n }\r\n long cur=1,ans=cur;\r\n for(int i=1;i<=k;i++) {\r\n \tcur=cur%mod*(n-i+1)%mod;\r\n \tcur%=mod;\r\n \tif(cur%i==0) {\r\n \t\tcur/=i;\r\n \t}\r\n \telse {\r\n \t\tInfo info=exgcd(i,mod);\r\n \t\tcur=cur%mod*(info.x)%mod;\r\n \t\tcur%=mod;\r\n \t}\r\n \tans=ans%mod+cur%mod;\r\n \tans%=mod;\r\n }\r\n System.out.println((ans+mod)%mod);\r\n\tK--;\r\n}\r\n}\r\n}", "src_uid": "dc7b887afcc2e95c4e90619ceda63071"} {"source_code": "//package javaapplication88;\nimport java.util.*;\npublic class JavaApplication88 \n{\n\n public static void main(String[] args) \n {\n Scanner sc=new Scanner(System.in);\n String a=sc.next();\n String b=sc.next();\n int count1=0,count2=0,count3=0;\n for(int i=0;i<a.length();i++)\n {\n if(a.charAt(i) == '+')\n {\n count1++;\n }\n }\n for(int i=0;i<b.length();i++)\n {\n if(b.charAt(i)=='+')\n {\n count2++;\n }\n else if(b.charAt(i)=='?')\n {\n count3++;\n }\n }\n if(count1==count2 && count3==0)\n {\n System.out.println(1);\n }\n else if(count3==0 && count1!=count2)\n {\n System.out.println(0);\n }\n else if(count1==count2 && count3!=0)\n {\n // System.out.println(\"hi\");\n double ans;\n if(count1 ==0)\n {\n \n ans=1;\n ans=(double)(ans/Math.pow(2, count3));\n }\n else if(count3%2==0)\n {\n ans=fact(count3)/(fact((count3/2))*fact((count3/2))) + 1;\n ans=(double) (ans/Math.pow(2, count3));\n } \n \n else\n {\n ans=1;\n ans=(double)(ans/Math.pow(2, count3));\n }\n \n System.out.println(ans);\n }\n \n else if(count2+count3 >=count1)\n {\n //System.out.println(\"hi\");\n double ans;\n if((count2+count3)==count1)\n {\n ans=1;\n \n \n }\n \n else\n {\n if(count1 - count2 >0)\n ans=fact(count3)/(fact(count1-count2)*fact(count3+count2-count1));\n else\n ans=0;\n \n }\n ans=(double) (ans/Math.pow(2, count3));\n System.out.print(ans);\n }\n else\n {\n System.out.println(0);\n }\n }\n static double fact(int n)\n {\n double ans=1;\n if(n==0)\n return 1;\n for(int i=n;i>0;i--)\n {\n \n ans=ans*i;\n }\n return ans;\n }\n \n}\n", "src_uid": "f7f68a15cfd33f641132fac265bc5299"} {"source_code": "\n\nimport java.util.Arrays;\nimport java.util.Scanner;\n\npublic class contet1 {\n\tpublic static void main(String[]args){\n\t\tScanner scan = new Scanner(System.in);{\n\t\t\tint runs = scan.nextInt();\n\t\t\tint a = scan.nextInt();\n\t\t\tint b = scan.nextInt();\n\t\t\tint[] arr = new int[runs];\n\t\t\tint totalmin = 0;\n\t\t\tfor(int i =0;i<runs;i++){\n\t\t\t\tarr[i]=scan.nextInt();\n\t\t\t}\n\t\t\tArrays.sort(arr);\n\t\t\tfor(int i = 0;i<arr.length-a;i++){\n\t\t\t\ttotalmin+=arr[i];\n\t\t\t}\n\t\t\tSystem.out.println(totalmin+(a*b));\n\t\t}\n\t}\n}", "src_uid": "92a233f8d9c73d9f33e4e6116b7d0a96"} {"source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\nimport java.util.Comparator;\nimport java.util.TreeSet;\n\npublic class E {\n private static StreamTokenizer in;\n private static PrintWriter out;\n private static BufferedReader inB;\n \n private static int nextInt() throws Exception{\n in.nextToken();\n return (int)in.nval;\n }\n \n private static String nextString() throws Exception{\n in.nextToken();\n return in.sval;\n }\n \n static{\n inB = new BufferedReader(new InputStreamReader(System.in));\n in = new StreamTokenizer(inB);\n out = new PrintWriter(System.out);\n }\n \n public static void main(String[] args)throws Exception {\n Complex A = new Complex(nextInt(), nextInt());\n Complex B = new Complex(nextInt(), nextInt());\n Complex C = new Complex(nextInt(), nextInt());\n \n boolean was = false;\n for(int i = 0; i<4; i++) {\n Complex cur = B.sub(A.mul(powi(i)));\n if(C.equals(Complex.z)) {\n if(cur.equals(Complex.z))was = true;\n } else {\n if(check(cur, C))was = true;\n }\n }\n \n System.out.println(was ? \"YES\" : \"NO\");\n }\n \n private static Complex powi(int n) {\n Complex ans = new Complex(1, 0);\n for(int i = 0; i<n; i++) {\n ans = ans.mul(Complex.i);\n }\n return ans;\n }\n \n private static boolean check(Complex cur, Complex C) {\n Complex tmp = cur.mul(new Complex(C.x, -C.y));\n long m = C.mod();\n return tmp.x % m == 0 && tmp.y % m == 0;\n }\n}\n\nclass Complex {\n long x, y;\n \n Complex(long x, long y) {\n this.x = x;\n this.y = y;\n }\n \n Complex add(Complex c) {\n return new Complex(c.x + x, c.y + y);\n }\n \n Complex mul(Complex c) {\n return new Complex(c.x*x - c.y*y, c.x*y + c.y*x);\n }\n \n Complex sub(Complex c) {\n return add(c.mul(new Complex(-1,0)));\n }\n \n boolean equals(Complex c) {\n return x == c.x && y == c.y;\n }\n \n long mod() {\n return x*x + y*y;\n }\n \n public String toString() {\n return x + \" \" + y;\n }\n \n public static final Complex i = new Complex(0, 1);\n public static final Complex z = new Complex(0, 0);\n}", "src_uid": "cc8a8af1ba2b19bf081e379139542883"} {"source_code": "\nimport java.util.Scanner;\npublic class code {\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\n System.out.println(n+1);\n // }\n }\n}\n", "src_uid": "098ade88ed90664da279fe8a5a54b5ba"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class a302\n{\t\n\tpublic static void main(String[] args) throws Exception\n\t{\n\t\tInputReader in = new InputReader(System.in);\n\t\tOutputWriter out = new OutputWriter(System.out);\n\t\tint n=in.readInt();\n\t\tString s=in.readString();\n\t\tif(n==1)\n\t\t{\n\t\t\tout.printLine(\"YES\");\n\t\t\tout.printLine(s);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tchar ch[]=new char[n];\n\t\t\tString c[]=new String[n];\n\t\t\tch[0]=s.charAt(0);\n\t\t\tint k=0,index=0,i;\n\t\t\tint flag=0;\n\t\t\tfor(i=1;i<s.length();i++)\n\t\t\t{\n\t\t\t\tflag=0;\n\t\t\t\tfor(int j=0;j<=k;j++)\n\t\t\t\t\tif(s.charAt(i)==ch[j])\n\t\t\t\t\t\tflag=1;\n\t\t\t\tif(flag==0&&k+1==n-1)\n\t\t\t\t{\n\t\t\t\t\tc[k]=s.substring(index,i);\n\t\t\t\t\tk+=1;\n\t\t\t\t\tc[k]=s.substring(i);\n\t\t\t\t}\n\t\t\t\telse if(flag==0&&k+2<n)\n\t\t\t\t{\n\t\t\t\t\tc[k]=s.substring(index,i);\n\t\t\t\t\tk+=1;\n\t\t\t\t\tindex=i;\n\t\t\t\t\tch[k]=s.charAt(i);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (c[n-1]!=null)\n\t\t\t{\n\t\t\t\tout.printLine(\"YES\");\n\t\t\t\tfor(int j=0;j<n;j++)\n\t\t\t\t\tout.printLine(c[j]);\n\t\t\t}\n\t\t\telse\n\t\t\tout.printLine(\"NO\");\n\t\t}\n\t\t\t\n\t\tout.close();\n\t}\n\n\n\tprivate static 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 \n\t\tpublic int read()\n\t\t{\n\t\t\tif (numChars == -1)\n\t\t\t\tthrow new InputMismatchException();\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} catch (IOException e)\n\t\t\t\t{\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\t\tpublic int readInt()\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\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} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\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} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\t\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 \n\t\t\n \n\t\tpublic interface SpaceCharFilter\n\t\t{\n\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t}\n\t}\n \n\tprivate static class OutputWriter\n\t{\n\t\tprivate final PrintWriter writer;\n \n\t\tpublic OutputWriter(OutputStream outputStream)\n\t\t{\n\t\t\twriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));\n\t\t}\n \n\t\tpublic OutputWriter(Writer writer)\n\t\t{\n\t\t\tthis.writer = new PrintWriter(writer);\n\t\t}\n \t\tpublic void print(Object... objects)\n\t\t{\n\t\t\tfor (int i = 0; i < objects.length; i++)\n\t\t\t{\n\t\t\t\tif (i != 0)\n\t\t\t\twriter.print(' ');\n\t\t\t\twriter.print(objects[i]);\n\t\t\t}\n\t\t}\n\t\t\n \n\t\tpublic void printLine(Object... objects)\n\t\t{\n\t\t\tprint(objects);\n\t\t\twriter.println();\n\t\t}\n \n\t\tpublic void close()\n\t\t{\n\t\t\twriter.close();\n\t\t}\n \n\t\tpublic void flush()\n\t\t{\n\t\t\twriter.flush();\n\t\t}\n \n\t}\n}\n", "src_uid": "c1b071f09ef375f19031ce99d10e90ab"} {"source_code": "\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n public static void main(String[] args) throws Exception {\n FastReader fr = new FastReader();\n long n = fr.nextInt();\n long a = fr.nextInt();\n long b = fr.nextInt();\n long c = fr.nextInt();\n switch ((int) (4 - n % 4)) {\n case 1:\n System.out.println(Math.min(a, Math.min(b+c, 3*c)));\n break;\n case 2:\n System.out.println(Math.min(a*2, Math.min(b, 2*c)));\n break;\n case 3:\n System.out.println(Math.min(a*3, Math.min(b + a, c)));\n break;\n default:\n System.out.println(0); \n break;\n }\n }\n\n}\n\nclass 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() {\n din = new DataInputStream(System.in);\n buffer = new byte[BUFFER_SIZE];\n bufferPointer = bytesRead = 0;\n }\n\n public FastReader(String file_name) throws IOException {\n din = new DataInputStream(new FileInputStream(file_name));\n buffer = new byte[BUFFER_SIZE];\n bufferPointer = bytesRead = 0;\n }\n\n public String readLine() throws IOException {\n byte[] buf = new byte[64]; // line length\n int cnt = 0, c;\n while ((c = read()) != -1) {\n if (c == '\\n')\n break;\n buf[cnt++] = (byte) c;\n }\n return new String(buf, 0, cnt);\n }\n\n public int nextInt() throws IOException {\n int ret = 0;\n byte c = read();\n while (c <= ' ')\n c = read();\n boolean neg = (c == '-');\n if (neg)\n c = read();\n do {\n ret = ret * 10 + c - '0';\n } while ((c = read()) >= '0' && c <= '9');\n\n if (neg)\n return -ret;\n return ret;\n }\n\n public long nextLong() throws IOException {\n long ret = 0;\n byte c = read();\n while (c <= ' ')\n c = read();\n boolean neg = (c == '-');\n if (neg)\n c = read();\n do {\n ret = ret * 10 + c - '0';\n } while ((c = read()) >= '0' && c <= '9');\n if (neg)\n return -ret;\n return ret;\n }\n\n public double nextDouble() throws IOException {\n double ret = 0, div = 1;\n byte c = read();\n while (c <= ' ')\n c = read();\n boolean neg = (c == '-');\n if (neg)\n c = read();\n\n do {\n ret = ret * 10 + c - '0';\n } while ((c = read()) >= '0' && c <= '9');\n\n if (c == '.') {\n while ((c = read()) >= '0' && c <= '9') {\n ret += (c - '0') / (div *= 10);\n }\n }\n\n if (neg)\n return -ret;\n return ret;\n }\n\n private void fillBuffer() throws IOException {\n bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n if (bytesRead == -1)\n buffer[0] = -1;\n }\n\n private byte read() throws IOException {\n if (bufferPointer == bytesRead)\n fillBuffer();\n return buffer[bufferPointer++];\n }\n\n public void close() throws IOException {\n if (din == null)\n return;\n din.close();\n }\n}", "src_uid": "c74537b7e2032c1d928717dfe15ccfb8"} {"source_code": "//package round429;\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 C2 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni();\n\t\tint[] a = na(n);\n\t\tfor(int i = 0;i < n;i++){\n\t\t\tint v = a[i];\n\t\t\tfor(int j = 2;j*j <= v;j++){\n\t\t\t\twhile(v % (j*j) == 0){\n\t\t\t\t\tv /= j*j;\n\t\t\t\t}\n\t\t\t}\n\t\t\ta[i] = v;\n\t\t}\n\t\t\n\t\tArrays.sort(a);\n\t\tint[] f = new int[n];\n\t\tint p = 0;\n\t\tfor(int i= 0;i < n;i++){\n\t\t\tif(i > 0 && a[i] != a[i-1]){\n\t\t\t\tp++;\n\t\t\t}\n\t\t\tf[p]++;\n\t\t}\n\t\tf = Arrays.copyOf(f, p+1);\n\t\tint mod = 1000000007;\n\t\t\n\t\tint[][] fif = enumFIF(1000, mod);\n\t\tlong[] res = countSameNeighborsSequence(f, fif, mod);\n\t\tlong ans = res[0];\n\t\tfor(int v : f){\n\t\t\tans = ans * fif[0][v] % mod;\n\t\t}\n\t\t\n\t\tout.println(ans);\n\t}\n\t\n\tpublic static int[][] enumFIF(int n, int mod) {\n\t\tint[] f = new int[n + 1];\n\t\tint[] invf = new int[n + 1];\n\t\tf[0] = 1;\n\t\tfor (int i = 1; i <= n; i++) {\n\t\t\tf[i] = (int) ((long) f[i - 1] * i % mod);\n\t\t}\n\t\tlong a = f[n];\n\t\tlong b = mod;\n\t\tlong p = 1, q = 0;\n\t\twhile (b > 0) {\n\t\t\tlong c = a / b;\n\t\t\tlong d;\n\t\t\td = a;\n\t\t\ta = b;\n\t\t\tb = d % b;\n\t\t\td = p;\n\t\t\tp = q;\n\t\t\tq = d - c * q;\n\t\t}\n\t\tinvf[n] = (int) (p < 0 ? p + mod : p);\n\t\tfor (int i = n - 1; i >= 0; i--) {\n\t\t\tinvf[i] = (int) ((long) invf[i + 1] * (i + 1) % mod);\n\t\t}\n\t\treturn new int[][] { f, invf };\n\t}\n\n\t\n\tpublic static long[] countSameNeighborsSequence(int[] a, int[][] fif, int mod)\n\t{\n\t\tint n = a.length;\n\t\t\n\t\tint bef = a[0];\n\t\tint aft = a[0];\n\t\tlong[] dp = new long[bef];\n\t\tdp[bef-1] = 1;\n\t\tfor(int u = 1;u < n;u++){\n\t\t\tint v = a[u];\n\t\t\taft += v;\n\t\t\tlong[][] ldp = new long[bef][aft];\n\t\t\tfor(int i = 0;i < dp.length;i++){\n\t\t\t\tldp[i][0] = dp[i];\n\t\t\t}\n\t\t\t\n\t\t\tfor(int i = 0;i < v;i++){\n\t\t\t\tlong[][] ndp = new long[bef][aft];\n\t\t\t\tfor(int j = 0;j < bef;j++){\n\t\t\t\t\tfor(int k = 0;j+k < aft;k++){\n\t\t\t\t\t\tif(ldp[j][k] == 0)continue;\n\t\t\t\t\t\t// XX -> XCX\n\t\t\t\t\t\tif(j > 0){\n\t\t\t\t\t\t\tndp[j-1][k] += ldp[j][k] * j;\n\t\t\t\t\t\t\tndp[j-1][k] %= mod;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\t// CC -> CCC\n\t\t\t\t\t\tif(k > 0){\n\t\t\t\t\t\t\tndp[j][k+1] += ldp[j][k] * k;\n\t\t\t\t\t\t\tndp[j][k+1] %= mod;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\t// XC -> XCC\n\t\t\t\t\t\t// #XC = 2*(i-k)\n\t\t\t\t\t\tif(2*(i-k) > 0){\n\t\t\t\t\t\t\tndp[j][k+1] += ldp[j][k] * (2*(i-k));\n\t\t\t\t\t\t\tndp[j][k+1] %= mod;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\t// XY -> XCY\n\t\t\t\t\t\t// #XY = bef+i+1-#XC-#CC-#XX\n\t\t\t\t\t\tif(bef+i+1-j-k-2*(i-k) > 0){\n\t\t\t\t\t\t\tndp[j][k] += ldp[j][k] * (bef+i+1-j-k-2*(i-k));\n\t\t\t\t\t\t\tndp[j][k] %= mod;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tldp = ndp;\n\t\t\t}\n\t\t\t\n\t\t\tdp = new long[aft];\n\t\t\tfor(int j = 0;j < bef;j++){\n\t\t\t\tfor(int k = 0;j+k < aft;k++){\n\t\t\t\t\tdp[j+k] += ldp[j][k];\n\t\t\t\t\tif(dp[j+k] >= mod)dp[j+k] -= mod;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor(int j = 0;j < aft;j++)dp[j] = dp[j] * fif[1][v] % mod;\n\t\t\tbef = aft;\n\t\t}\n\t\treturn dp;\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 C2().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", "src_uid": "e00c5fde478d36c90b17f5df18fb3ed1"} {"source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.BufferedWriter;\nimport java.io.Writer;\nimport java.io.OutputStreamWriter;\nimport java.util.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n InputReader in = new InputReader(inputStream);\n OutputWriter out = new OutputWriter(outputStream);\n TaskC solver = new TaskC();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskC {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n int n = in.nextInt(), r = in.nextInt();\n int[] f = new int[n], s = new int[n];\n double[] p = new double[n];\n int[] g = new int[n];\n int sum = 0;\n int sf = 0;\n for (int i = 0; i < n; i++) {\n f[i] = in.nextInt();\n s[i] = in.nextInt();\n p[i] = in.nextInt() / 100.0;\n g[i] = s[i] - f[i];\n sum += s[i];\n sf += f[i];\n }\n int needg = (sum - r);\n double lo = sf, hi = 1L << 50;\n for (int iter = 0; iter < 80; iter++) {\n double mid = (lo + hi) / 2.0;\n double[][] dp = new double[n + 1][needg + 1];\n for (int i = 0; i < needg; i++) {\n dp[n][i] = mid;\n }\n dp[n][needg] = 0;\n for (int i = n - 1; i >= 0; i--) {\n for (int have = 0; have <= needg; have++) {\n // restart, try level\n int nhave = Math.min(needg, have + g[i]);\n dp[i][have] = Math.min(mid, (dp[i + 1][nhave] + f[i]) * p[i] + (1 - p[i]) * (dp[i + 1][have] + s[i]));\n }\n }\n\n if (dp[0][0] < mid) {\n hi = mid;\n } else {\n lo = mid;\n }\n }\n out.printf(\"%.10f\\n\", (lo + hi) / 2.0);\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 printf(String format, Object... objects) {\n writer.printf(format, objects);\n }\n\n public void close() {\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\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (this.numChars == -1) {\n throw new InputMismatchException();\n } else {\n if (this.curChar >= this.numChars) {\n this.curChar = 0;\n\n try {\n this.numChars = this.stream.read(this.buf);\n } catch (IOException var2) {\n throw new InputMismatchException();\n }\n\n if (this.numChars <= 0) {\n return -1;\n }\n }\n\n return this.buf[this.curChar++];\n }\n }\n\n public int nextInt() {\n int c;\n for (c = this.read(); isSpaceChar(c); c = this.read()) {\n ;\n }\n\n byte sgn = 1;\n if (c == 45) {\n sgn = -1;\n c = this.read();\n }\n\n int res = 0;\n\n while (c >= 48 && c <= 57) {\n res *= 10;\n res += c - 48;\n c = this.read();\n if (isSpaceChar(c)) {\n return res * sgn;\n }\n }\n\n throw new InputMismatchException();\n }\n\n public static boolean isSpaceChar(int c) {\n return c == 32 || c == 10 || c == 13 || c == 9 || c == -1;\n }\n\n }\n}\n\n", "src_uid": "b461bb51eab4ff8088460c1980dacb93"} {"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 CPrairiePartition solver = new CPrairiePartition();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class CPrairiePartition {\n public void solve(int testNumber, FastInput in, FastOutput out) {\n int n = in.readInt();\n long[] a = new long[n];\n int[] cnts = new int[50];\n LongList special = new LongList(n);\n\n in.populate(a);\n for (long x : a) {\n if (Long.lowestOneBit(x) == x) {\n cnts[Log2.floorLog(x)]++;\n } else {\n special.add(x);\n }\n }\n special.sort();\n\n IntBinarySearch ibs = new IntBinarySearch() {\n\n public boolean check(int mid) {\n int one = cnts[0] - mid;\n int specialIndex = 0;\n\n int flow = mid;\n int taged = 0;\n for (int i = 1; i < cnts.length; i++) {\n int c = cnts[i];\n if (c <= flow) {\n int kickOut = flow - c;\n int kickTaged = Math.min(taged, kickOut);\n taged -= kickTaged;\n int kickUnTaged = kickOut - kickTaged;\n flow -= kickOut;\n\n\n while (kickUnTaged > 0 && specialIndex < special.size() &&\n special.get(specialIndex) <= (1L << i)) {\n kickUnTaged--;\n specialIndex++;\n }\n while (kickUnTaged > 0 && one > 0) {\n kickUnTaged--;\n one--;\n }\n } else {\n c -= flow;\n taged += c;\n }\n }\n\n int kickOut = flow - taged;\n return kickOut >= special.size() - specialIndex + one;\n }\n };\n\n int ans = ibs.binarySearch(0, cnts[0]);\n if (!ibs.check(ans)) {\n out.println(-1);\n return;\n }\n\n for (int i = ans; i <= cnts[0]; i++) {\n out.append(i).append(' ');\n }\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 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 LongList implements Cloneable {\n private int size;\n private int cap;\n private long[] data;\n private static final long[] EMPTY = new long[0];\n\n public LongList(int cap) {\n this.cap = cap;\n if (cap == 0) {\n data = EMPTY;\n } else {\n data = new long[cap];\n }\n }\n\n public LongList(LongList list) {\n this.size = list.size;\n this.cap = list.cap;\n this.data = Arrays.copyOf(list.data, size);\n }\n\n public LongList() {\n this(0);\n }\n\n public void ensureSpace(int req) {\n if (req > cap) {\n while (cap < req) {\n cap = Math.max(cap + 10, 2 * cap);\n }\n data = Arrays.copyOf(data, cap);\n }\n }\n\n private void checkRange(int i) {\n if (i < 0 || i >= size) {\n throw new ArrayIndexOutOfBoundsException();\n }\n }\n\n public long get(int i) {\n checkRange(i);\n return data[i];\n }\n\n public void add(long x) {\n ensureSpace(size + 1);\n data[size++] = x;\n }\n\n public void addAll(long[] x, int offset, int len) {\n ensureSpace(size + len);\n System.arraycopy(x, offset, data, size, len);\n size += len;\n }\n\n public void addAll(LongList list) {\n addAll(list.data, 0, list.size);\n }\n\n public void sort() {\n if (size <= 1) {\n return;\n }\n Randomized.shuffle(data, 0, size);\n Arrays.sort(data, 0, size);\n }\n\n public int size() {\n return size;\n }\n\n public long[] toArray() {\n return Arrays.copyOf(data, size);\n }\n\n public String toString() {\n return Arrays.toString(toArray());\n }\n\n public boolean equals(Object obj) {\n if (!(obj instanceof LongList)) {\n return false;\n }\n LongList other = (LongList) obj;\n return SequenceUtils.equal(data, 0, size - 1, other.data, 0, other.size - 1);\n }\n\n public int hashCode() {\n int h = 1;\n for (int i = 0; i < size; i++) {\n h = h * 31 + Long.hashCode(data[i]);\n }\n return h;\n }\n\n public LongList clone() {\n LongList ans = new LongList();\n ans.addAll(this);\n return ans;\n }\n\n }\n\n static class 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 abstract class IntBinarySearch {\n public abstract boolean check(int mid);\n\n public int binarySearch(int l, int r) {\n if (l > r) {\n throw new IllegalArgumentException();\n }\n while (l < r) {\n int mid = DigitUtils.floorAverage(l, r);\n if (check(mid)) {\n r = mid;\n } else {\n l = mid + 1;\n }\n }\n return l;\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(long[] data) {\n for (int i = 0; i < data.length; i++) {\n data[i] = readLong();\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 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 DigitUtils {\n private DigitUtils() {\n }\n\n public static int floorAverage(int x, int y) {\n return (x & y) + ((x ^ y) >> 1);\n }\n\n }\n\n static class Randomized {\n public static void shuffle(long[] data, int from, int to) {\n to--;\n for (int i = from; i <= to; i++) {\n int s = nextInt(i, to);\n long tmp = data[i];\n data[i] = data[s];\n data[s] = tmp;\n }\n }\n\n public static int nextInt(int l, int r) {\n return RandomWrapper.INSTANCE.nextInt(l, r);\n }\n\n }\n\n static class Log2 {\n public static int floorLog(long x) {\n return 63 - Long.numberOfLeadingZeros(x);\n }\n\n }\n}\n\n", "src_uid": "fc29e8c1a9117c1dd307131d852b6088"} {"source_code": "//package arbuz;\n\nimport java.util.Scanner;\n\npublic class Arbuz {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int[] first = new int[n];\n int[] second = new int[n];\n int i;\n String s = sc.next();\n for (i = 0; i < n; i++) {\n first[i] = (byte) s.charAt(i) - 48;\n second[i] = (byte) s.charAt(n + i) - 48;\n }\n i = 0;\n while (i < n - 1) {\n if (first[i] > first[i + 1]) {\n int temp = first[i];\n first[i] = first[i + 1];\n first[i + 1] = temp;\n i = -1;\n }\n i++;\n }\n i = 0;\n while (i < n - 1) {\n if (second[i] > second[i + 1]) {\n int temp = second[i];\n second[i] = second[i + 1];\n second[i + 1] = temp;\n i = -1;\n }\n i++;\n }\n boolean less = false, bigger = false, equal = false, match = true;\n for (i = 0; i < n; i++) {\n if (first[i] == second[i]) {\n equal = true;\n }\n if (first[i] < second[i]) {\n less = true;\n }\n if (first[i] > second[i]) {\n bigger = true;\n }\n if ((less && bigger) || equal) {\n match = false;\n break;\n }\n }\n if (match) {\n System.out.println(\"YES\");\n } else {\n System.out.println(\"NO\");\n }\n }\n}\n", "src_uid": "e4419bca9d605dbd63f7884377e28769"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class D {\n\n\tstatic final int INF = Integer.MAX_VALUE / 10;\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\tboolean eof;\n\n\tint[] v1, v2;\n\tint[][] g;\n\tint[][] d;\n\n\tint n, m;\n\n\tint[] deg;\n\t\n\tdouble[] ps;\n\tint[] psList;\n\tint psPtr = 0;\n\t\n\tdouble[] maxP;\n\tint[] maxPList;\n\tint maxPPtr = 0;\n\n\tdouble go2(Integer[] vs, int from, int to) {\n\t\tdouble stupid = 1.0 / (to - from);\n\n\t\tdouble smart = 0;\n\t\t\n\t\tfor (int i = from; i < to; i++) {\n\n\t\t\tint v = vs[i];\n\t\t\t\n\t\t\tfor (int j = 0; j < deg[v]; j++) {\n\t\t\t\tint u = g[v][j];\n\t\t\t\tif (ps[u] < 0) {\n\t\t\t\t\tps[u] = 0;\n\t\t\t\t\tpsList[psPtr++] = u;\n\t\t\t\t}\n\t\t\t\tps[u] += stupid / deg[v];\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\tfor (int v2 = 0; v2 < n; v2++) {\n\t\t\tfor (int i = 0; i < psPtr; i++) {\n\t\t\t\tint u = psList[i];\n\t\t\t\tint dst = d[v2][u];\n\t\t\t\tif (maxP[dst] < 0) {\n\t\t\t\t\tmaxP[dst] = 0;\n\t\t\t\t\tmaxPList[maxPPtr++] = dst;\n\t\t\t\t}\n\t\t\t\tmaxP[dst] = Math.max(maxP[dst], ps[u]);\n\t\t\t}\n\t\t\tdouble here = 0;\n\t\t\tfor (int i = 0; i < maxPPtr; i++) {\n\t\t\t\there += maxP[maxPList[i]];\n\t\t\t}\n\t\t\tsmart = Math.max(smart, here);\n\t\t\t\n\t\t\t\n\t\t\twhile (maxPPtr > 0) {\n\t\t\t\tint v = maxPList[--maxPPtr];\n\t\t\t\tmaxP[v] = -1;\n\t\t\t}\n\t\t}\n\t\t\n\t\twhile (psPtr > 0) {\n\t\t\tint v = psList[--psPtr];\n\t\t\tps[v] = -1;\n\t\t}\n\t\t\n//\t\tSystem.err.println(from + \" \" + to + \" -> \" + smart + \" \" + stupid);\n\n\t\treturn Math.max(smart, stupid);\n\n\t}\n\n\tdouble go(int v) {\n\t\tfinal int[] dist = d[v];\n\t\tInteger[] a = new Integer[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = i;\n\t\t}\n\t\tArrays.sort(a, new Comparator<Integer>() {\n\n\t\t\t@Override\n\t\t\tpublic int compare(Integer o1, Integer o2) {\n\t\t\t\treturn Integer.compare(dist[o1], dist[o2]);\n\t\t\t}\n\n\t\t});\n\n\t\tdouble ret = 0;\n\n\t\tfor (int i = 0; i < n;) {\n\t\t\tint j = i;\n\t\t\twhile (j < n && dist[a[i]] == dist[a[j]]) {\n\t\t\t\tj++;\n\t\t\t}\n\n\t\t\tret += 1.0 * (j - i) / n * go2(a, i, j);\n\t\t\ti = j;\n\t\t}\n\n\t\treturn ret;\n\t}\n\n\tvoid solve() throws IOException {\n\t\tn = nextInt();\n\t\tm = nextInt();\n\n\t\tv1 = new int[m];\n\t\tv2 = new int[m];\n\t\tdeg = new int[n];\n\n\t\td = new int[n][n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tArrays.fill(d[i], INF);\n\t\t\td[i][i] = 0;\n\t\t}\n\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tv1[i] = nextInt() - 1;\n\t\t\tv2[i] = nextInt() - 1;\n\t\t\td[v1[i]][v2[i]] = d[v2[i]][v1[i]] = 1;\n\t\t\tdeg[v1[i]]++;\n\t\t\tdeg[v2[i]]++;\n\t\t}\n\n\t\tg = new int[n][];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tg[i] = new int[deg[i]];\n\t\t}\n\n\t\tint[] ptrDeg = deg.clone();\n\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tint v = v1[i];\n\t\t\tint u = v2[i];\n\t\t\tg[v][--ptrDeg[v]] = u;\n\t\t\tg[u][--ptrDeg[u]] = v;\n\t\t}\n\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\td[i][j] = Math.min(d[i][j], d[i][k] + d[k][j]);\n\t\t\t\t}\n\t\t\n\t\tps = new double[n];\n\t\tArrays.fill(ps, -1);\n\t\tpsList = new int[n];\n\t\t\n\t\tmaxP = new double[n];\n\t\tArrays.fill(maxP, -1);\n\t\tmaxPList = new int[n];\n\t\t\n\t\tdouble ans = 0;\n\t\tfor (int i = 0; i < n; i++) { // !!!\n\t\t\tans = Math.max(ans, go(i));\n\t\t}\n\n\t\tout.println(ans);\n\n\t}\n\n\tD() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tsolve();\n\t\tout.close();\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew D();\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}", "src_uid": "99b94d0c75fa6cd28091a9d71daf6cbf"} {"source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.math.BigDecimal;\nimport java.util.Scanner;\n\npublic class Main {\n\n private static class Node {\n int HH;\n int MM;\n\n public Node(int h, int m) {\n this.HH = h;\n this.MM = m;\n }\n\n public static Node getNode(String s) {\n String[] w = s.split(\":\");\n int h = Integer.valueOf(w[0]);\n int m = Integer.valueOf(w[1]);\n\n return new Node(h, m);\n }\n\n private static int distanceInMinutes(Node s, Node e) {\n int d = getTotalMinutes(e) - getTotalMinutes(s);\n return d;\n }\n\n private static int getTotalMinutes(Node n) {\n\n return (n.HH * 60) + n.MM;\n }\n\n private static void addMinutes(Node n, int m) {\n\n n.MM += m;\n while (n.MM > 59) {\n n.MM = n.MM - 60;\n n.HH += 1;\n }\n }\n\n public static void output(Node sNode, Node eNode) {\n\n int d = Node.distanceInMinutes(sNode, eNode);\n\n Node.addMinutes(sNode, d / 2);\n\n String ms = String.valueOf(sNode.MM);\n if (sNode.MM < 10) {\n ms = String.valueOf(\"0\" + sNode.MM);\n }\n\n String hs = String.valueOf(sNode.HH);\n if (sNode.HH < 10) {\n hs = String.valueOf(\"0\" + sNode.HH);\n }\n System.out.println(hs + \":\" + ms);\n }\n\n @Override\n public String toString() {\n return \"Node{\" +\n \"HH=\" + HH +\n \", MM=\" + MM +\n '}';\n }\n }\n\n public static void main(String[] args) {\n Scanner I = new Scanner(new BufferedReader(new InputStreamReader(System.in)));\n\n\n String s = I.nextLine();\n String e = I.nextLine();\n\n Node sNode = Node.getNode(s);\n Node eNode = Node.getNode(e);\n\n Node.output(sNode, eNode);\n\n\n }\n\n\n}", "src_uid": "f7a32a8325ce97c4c50ce3a5c282ec50"} {"source_code": "import java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\nimport java.util.StringTokenizer;\r\n\r\n\r\npublic class Main {\r\n\r\n\tstatic AReader scan = new AReader();\r\n\tstatic StringBuffer sb = new StringBuffer();\r\n\tstatic int N = 200010;\r\n\tstatic int MOD = (int)1e9+7;\r\n\tstatic long[] f = new long[N];\r\n\tstatic long[] g = new long[N];\r\n\r\n\tstatic void init(){\r\n\t\tf[0] = g[0] = 1;\r\n\t\tfor(int i = 1;i<N;i++){\r\n\t\t\tf[i] = f[i-1] * i % MOD;\r\n\t\t\tg[i] = g[i-1] * qmi(i,MOD-2) % MOD;\r\n\t\t}\r\n\t}\r\n\r\n\tstatic long qmi(long a,int b){\r\n\t\tlong res = 1;\r\n\t\twhile(b>0){\r\n\t\t\tif((b & 1) == 1){\r\n\t\t\t\tres = res * a % MOD;\r\n\t\t\t}\r\n\t\t\ta = a * a % MOD;\r\n\t\t\tb >>=1;\r\n\t\t}\r\n\t\treturn res % MOD;\r\n\t}\r\n\r\n\r\n\tstatic long C(int a,int b){\r\n\t\treturn f[a] * g[b] % MOD * g[a-b] % MOD;\r\n\t}\r\n\tstatic void solve() {\r\n\t\tint n = scan.nextInt();\r\n\t\tint k = scan.nextInt();\r\n\t\tif(k == 0){\r\n\t\t\tSystem.out.println(1);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tif(n % 2 == 1){\r\n\t\t\tlong res = 0;\r\n\t\t\t// \u679a\u4e3e\u9009\u51e0\u4e2a1\r\n\t\t\tlong t = 0;\r\n\t\t\tfor(int i = 0;i<=n;i+=2){\r\n\t\t\t\tt = (t + C(n,i)) % MOD;\r\n\t\t\t}\r\n\t\t\tres = qmi(t + 1,k);\r\n\t\t\tSystem.out.println(res);\r\n\t\t}else{\r\n\t\t\t// \u5076\u6570\u60c5\u51b5\r\n\t\t\tlong res = 0;\r\n\r\n\t\t\tlong t = 0;\r\n\t\t\t// \u6bcf\u4e00\u4f4d\u5fc5\u987b\u9009\u5076\u6570\u4e2a1\r\n\t\t\tfor(int i = 0;i<n;i+=2){\r\n\t\t\t\tt = (t + C(n,i)) % MOD;\r\n\t\t\t}\r\n\r\n\t\t\t// \u5de6\u5927\u4e8e\u53f3 \u7b2ci\u4f4d\u5de6\u5f0f\u4e3a1 \u53f3\u5f0f\u4e3a0 \u524di\u4f4d\u90fd\u662f1 \u540e\u9762\u968f\u4fbf\u9009\r\n\t\t\tfor(int i = 1;i<=k;i++){\r\n\t\t\t\tres += qmi(t,i-1) * qmi(qmi(2,n),k-i) % MOD;\r\n\t\t\t\tres %=MOD;\r\n\t\t\t}\r\n\r\n\r\n\t\t\tres = (res + qmi(t,k)) % MOD;\r\n\r\n\r\n\t\t\t//res %= MOD;\r\n\t\t\tSystem.out.println(res);\r\n\t\t}\r\n\r\n\t}\r\n\r\n\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tinit();\r\n\t\tint T = scan.nextInt();\r\n\t\twhile (T-- > 0) {\r\n\t\tsolve();\r\n\t\t}\r\n\t\t//System.out.print(sb.toString());\r\n\t}\r\n}\r\n\r\n\r\nclass AReader {\r\n\tprivate BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\r\n\tprivate StringTokenizer tokenizer = new StringTokenizer(\"\");\r\n\r\n\tprivate String innerNextLine() {\r\n\t\ttry {\r\n\t\t\treturn reader.readLine();\r\n\t\t} catch (IOException ex) {\r\n\t\t\treturn null;\r\n\t\t}\r\n\t}\r\n\r\n\tpublic boolean hasNext() {\r\n\t\twhile (!tokenizer.hasMoreTokens()) {\r\n\t\t\tString nextLine = innerNextLine();\r\n\t\t\tif (nextLine == null) {\r\n\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t\ttokenizer = new StringTokenizer(nextLine);\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\r\n\tpublic String nextLine() {\r\n\t\ttokenizer = new StringTokenizer(\"\");\r\n\t\treturn innerNextLine();\r\n\t}\r\n\r\n\tpublic String next() {\r\n\t\thasNext();\r\n\t\treturn tokenizer.nextToken();\r\n\t}\r\n\r\n\tpublic int nextInt() {\r\n\t\treturn Integer.parseInt(next());\r\n\t}\r\n\r\n\tpublic long nextLong() {\r\n\t\treturn Long.parseLong(next());\r\n\t}\r\n\r\n\tpublic double nextDouble() {\r\n\t\treturn Double.parseDouble(next());\r\n\t}\r\n}\r\n\r\nclass Pair {\r\n\tint x,y;\r\n\r\n\tpublic Pair(int x, int y) {\r\n\t\tthis.x = x;\r\n\t\tthis.y = y;\r\n\t}\r\n}\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "src_uid": "02f5fe43ea60939dd4a53299b5fa0881"} {"source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n \n \n \npublic class Main {\n\t\n\tstatic InputReader in = new InputReader(System.in);\n\tstatic PrintWriter out = new PrintWriter(System.out);\n\t\n\tstatic int oo = (int)1e9;\n//\tstatic long oo = (long)1e15;\n\tstatic int mod = 1_000_000_007;\n\t\n\tstatic int[] dx = {1, 0, -1, 0};\n\tstatic int[] dy = {0, -1, 0, 1};\n\t\n\tstatic int M = 5001;\n\tstatic double EPS = 1e-13;\n\tstatic int num = 1;\n\t\n\t\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tlong n = in.nextLong();\n\t\tlong m = in.nextLong();\n\t\tint k = in.nextInt();\n\t\tif(k == -1 && n % 2 != m % 2) {\n\t\t\tSystem.out.println(0);\n\t\t}\n\t\telse {\n\t\t\tlong x = pow(2, m-1, mod);\n\t\t\tlong y = pow(x, n-1, mod);\n\t\t\tSystem.out.println(y);\n\t\t}\n\t\t\n\t\tout.close();\n\t}\n\t\n\tstatic int find(int[] g, int x) {\n\t\treturn g[x] = g[x] == x ? x : find(g, g[x]);\n\t}\n\t\n\tstatic void union(int[] g, int[] size, int x, int y) {\n\t\tx = find(g, x); y = find(g, y);\n\t\tif(x == y)\n\t\t\treturn;\n\t\tif(size[x] < size[y]) {\n\t\t\tg[x] = y;\n\t\t\tsize[y] += size[x];\n\t\t}\n\t\telse {\n\t\t\tg[y] = x;\n\t\t\tsize[x] += size[y];\n\t\t}\n\t}\n\t\n\tstatic class Segment {\n\t\tSegment left, right;\n\t\tint size, minIdx;\n//\t\tint time, lazy;\n\t\t\n\t\tpublic Segment(int[] a, int l, int r) {\n\t\t\tsuper();\n\t\t\tif(l == r) {\n\t\t\t\tthis.minIdx = l;\n\t\t\t\tthis.size = 1;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tint mid = (l + r) / 2;\n\t\t\tleft = new Segment(a, l, mid);\n\t\t\tright = new Segment(a, mid+1, r);\n\t\t\tif(a[left.minIdx] <= a[right.minIdx])\n\t\t\t\tthis.minIdx = left.minIdx;\n\t\t\telse\n\t\t\t\tthis.minIdx = right.minIdx;\n\t\t\tthis.size = left.size + right.size;\n\t\t}\n\t\t\n\t\tboolean covered(int ll, int rr, int l, int r) {\n\t\t\treturn ll <= l && rr >= r;\n\t\t}\n\t\t\n\t\tboolean noIntersection(int ll, int rr, int l, int r) {\n\t\t\treturn ll > r || rr < l;\n\t\t}\n\t\t\n//\t\tvoid lazyPropagation() {\n//\t\t\tif(lazy != 0) {\n//\t\t\t\tif(left != null) {\n//\t\t\t\t\tleft.setLazy(this.time, this.lazy);\n//\t\t\t\t\tright.setLazy(this.time, this.lazy);\n//\t\t\t\t}\n//\t\t\t\telse {\n//\t\t\t\t\tval = lazy;\n//\t\t\t\t}\n//\t\t\t}\n//\t\t}\n\t\t\n//\t\tvoid setLazy(int time, int lazy) {\n//\t\t\tif(this.time != 0 && this.time <= time)\n//\t\t\t\treturn;\n//\t\t\tthis.time = time;\n//\t\t\tthis.lazy = lazy;\n//\t\t}\n\t\t\n\t\t\n\t\tint querySize(int ll, int rr, int l, int r) {\n//\t\t\tlazyPropagation();\n\t\t\tif(noIntersection(ll, rr, l, r))\n\t\t\t\treturn 0;\n\t\t\tif(covered(ll, rr, l, r))\n\t\t\t\treturn size;\n\t\t\tint mid = (l + r) / 2;\n\t\t\tint leftSize = left.querySize(ll, rr, l, mid);\n\t\t\tint rightSize = right.querySize(ll, rr, mid+1, r);\n\t\t\treturn leftSize + rightSize;\n\t\t}\n\t\t\n\t\tint query(int k, int l, int r) {\n\t\t\tSegment trace = this;\n\t\t\twhile(l < r) {\n\t\t\t\tint mid = (l + r) / 2;\n\t\t\t\tif(trace.left.size > k) {\n\t\t\t\t\ttrace = trace.left;\n\t\t\t\t\tr = mid;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tk -= trace.left.size;\n\t\t\t\t\ttrace = trace.right;\n\t\t\t\t\tl = mid + 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn l;\n\t\t}\n\t\t\n\t\tvoid update(int ll, int rr, int l, int r) {\n//\t\t\tlazyPropagation();\n\t\t\tif(noIntersection(ll, rr, l, r))\n\t\t\t\treturn;\n\t\t\tif(covered(ll, rr, l, r)) {\n//\t\t\t\tsetLazy(time, knight);\n\t\t\t\tthis.minIdx = -1;\n\t\t\t\tthis.size = 0;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tint mid = (l + r) / 2;\n\t\t\tleft.update(ll, rr, l, mid);\n\t\t\tright.update(ll, rr, mid+1, r);\n\t\t\tthis.size = left.size + right.size;\n\t\t}\n\t}\n\t\n\tstatic long pow(long a, long n, long mod) {\n\t\tif(n == 0)\n\t\t\treturn 1;\n\t\tif(n % 2 == 1)\n\t\t\treturn a * pow(a, n-1, mod) % mod;\n\t\tlong x = pow(a, n / 2, mod);\n\t\treturn x * x % mod;\n\t}\n\t\n\t\n\tstatic int[] getPi(char[] a) {\n\t\tint m = a.length;\n\t\tint j = 0;\n\t\tint[] pi = new int[m];\n\t\tfor(int i = 1; i < m; ++i) {\n\t\t\twhile(j > 0 && a[i] != a[j])\n\t\t\t\tj = pi[j-1];\n\t\t\tif(a[i] == a[j]) {\n\t\t\t\tpi[i] = j + 1;\n\t\t\t\tj++;\n\t\t\t}\n\t\t}\n\t\treturn pi;\n\t}\n\t\n\tstatic long lcm(long a, long b) {\n\t\treturn a * b / gcd(a, b);\n\t}\n\t\n\tstatic BigInteger lcm2(long a, long b) {\n\t\tlong g = gcd(a, b);\n\t\tBigInteger gg = BigInteger.valueOf(g);\n\t\tBigInteger aa = BigInteger.valueOf(a);\n\t\tBigInteger bb = BigInteger.valueOf(b);\n\t\treturn aa.multiply(bb).divide(gg);\n\t}\n\t\n\tstatic boolean nextPermutation(int[] a) {\n\t\tfor(int i = a.length - 2; i >= 0; --i) {\n\t\t\tif(a[i] < a[i+1]) {\n\t\t\t\tfor(int j = a.length - 1; ; --j) {\n\t\t\t\t\tif(a[i] < a[j]) {\n\t\t\t\t\t\tint t = a[i];\n\t\t\t\t\t\ta[i] = a[j];\n\t\t\t\t\t\ta[j] = t;\n\t\t\t\t\t\tfor(i++, j = a.length - 1; i < j; ++i, --j) {\n\t\t\t\t\t\t\tt = a[i];\n\t\t\t\t\t\t\ta[i] = a[j];\n\t\t\t\t\t\t\ta[j] = t;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\t\n\tstatic void shuffle(Object[] a) {\n\t\tRandom r = new Random();\n\t\tfor(int i = a.length - 1; i > 0; --i) {\n\t\t\tint si = r.nextInt(i);\n\t\t\tObject t = a[si];\n\t\t\ta[si] = a[i];\n\t\t\ta[i] = t;\n\t\t}\n\t}\n\t\n\tstatic void shuffle(int[] a) {\n\t\tRandom r = new Random();\n\t\tfor(int i = a.length - 1; i > 0; --i) {\n\t\t\tint si = r.nextInt(i);\n\t\t\tint t = a[si];\n\t\t\ta[si] = a[i];\n\t\t\ta[i] = t;\n\t\t}\n\t}\n\t\n\tstatic void shuffle(long[] a) {\n\t\tRandom r = new Random();\n\t\tfor(int i = a.length - 1; i > 0; --i) {\n\t\t\tint si = r.nextInt(i);\n\t\t\tlong t = a[si];\n\t\t\ta[si] = a[i];\n\t\t\ta[i] = t;\n\t\t}\n\t}\n\t\n\tstatic int lower_bound(int[] a, int n, int k) {\n\t\tint s = 0;\n\t\tint e = n;\n\t\tint m;\n\t\twhile (e - s > 0) {\n\t\t\tm = (s + e) / 2;\n\t\t\tif (a[m] < k)\n\t\t\t\ts = m + 1;\n\t\t\telse\n\t\t\t\te = m;\n\t\t}\n\t\treturn e;\n\t}\n\tstatic int lower_bound(long[] a, int n, long k) {\n\t\tint s = 0;\n\t\tint e = n;\n\t\tint m;\n\t\twhile (e - s > 0) {\n\t\t\tm = (s + e) / 2;\n\t\t\tif (a[m] < k)\n\t\t\t\ts = m + 1;\n\t\t\telse\n\t\t\t\te = m;\n\t\t}\n\t\treturn e;\n\t}\n\t\n\tstatic int gcd(int a, int b) {\n\t\treturn b == 0 ? a : gcd(b, a % b);\n\t}\n\tstatic long gcd(long a, long b) {\n\t\treturn b == 0 ? a : gcd(b, a % b);\n\t}\n\tstatic BigInteger gcd(BigInteger a, BigInteger b) {\n\t\treturn b.compareTo(BigInteger.ZERO) == 0 ? a : gcd(b, a.mod(b));\n\t}\n\t\n\tstatic class Pair implements Comparable<Pair> {\n\t\tint first, second;\n \n\t\tpublic Pair(int first, int second) {\n\t\t\tsuper();\n\t\t\tthis.first = first;\n\t\t\tthis.second = second;\n\t\t}\n \n\t\t@Override\n\t\tpublic int compareTo(Pair o) {\n\t\t\treturn this.first != o.first ? this.first - o.first : this.second - o.second;\n\t\t}\n\t\t\n//\t\t@Override\n//\t\tpublic int compareTo(Pair o) {\n//\t\t\treturn this.first != o.first ? o.first - this.first : o.second - this.second;\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 + first;\n\t\t\tresult = prime * result + second;\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 (first != other.first)\n\t\t\t\treturn false;\n\t\t\tif (second != other.second)\n\t\t\t\treturn false;\n\t\t\treturn true;\n\t\t}\n\t}\n}\n \n \n \nclass InputReader {\n \n\tprivate final InputStream stream;\n\tprivate final byte[] buf = new byte[8192];\n\tprivate int curChar, snumChars;\n \n\tpublic InputReader(InputStream st) {\n\t\tthis.stream = st;\n\t}\n \n\tpublic int read() {\n\t\tif (snumChars == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (curChar >= snumChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tsnumChars = 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 (snumChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n \n\tpublic int nextInt() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c)) {\n\t\t\tc = read();\n\t\t}\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\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 nextLong() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c)) {\n\t\t\tc = read();\n\t\t}\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\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 int[] nextIntArray(int n) {\n\t\tint a[] = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = nextInt();\n\t\t}\n\t\treturn a;\n\t}\n \n\tpublic String readString() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c)) {\n\t\t\tc = read();\n\t\t}\n\t\tStringBuilder res = new StringBuilder();\n\t\tdo {\n\t\t\tres.appendCodePoint(c);\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res.toString();\n\t}\n \n\tpublic String nextLine() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tStringBuilder res = new StringBuilder();\n\t\tdo {\n\t\t\tres.appendCodePoint(c);\n\t\t\tc = read();\n\t\t} while (!isEndOfLine(c));\n\t\treturn res.toString();\n\t}\n \n\tpublic boolean isSpaceChar(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n \n\tprivate boolean isEndOfLine(int c) {\n\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t}\n \n}", "src_uid": "6b9eff690fae14725885cbc891ff7243"} {"source_code": "\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.InputMismatchException;\n\n\n//abzzzzzzzzabcdzzzzzzzcd\n//abcd\npublic class D {\n\tprivate static int n, m;\n\tprivate static int[] a;\n\tprivate static String s, t;\n\tprivate static HashMap<Integer, ArrayList<Integer>> g;\n\tprivate static long pp, qq, rr;\n\n\tpublic static void main(String[] args) {\n\t\ts = ins();\n\t\tt = ins();\n\t\tn = s.length();\n\t\tm = t.length();\n\t\tint[][] mapRight = new int[n][26];\n\t\tfor(int i=n-1; i>=0; i--) {\n\t\t\tfor(int j=0; j<26; j++) {\n\t\t\t\tmapRight[i][j] = (i+1<n?mapRight[i+1][j]:-1);\n\t\t\t}\n\t\t\tmapRight[i][s.charAt(i)-'a'] = i;\n\t\t}\n\t\tint[][] mapLeft = new int[n][26];\n\t\tfor(int i=0; i<n; i++) {\n\t\t\tfor(int j=0; j<26; j++) {\n\t\t\t\tmapLeft[i][j] = (i-1>=0?mapLeft[i-1][j]:-1);\n\t\t\t}\n\t\t\tmapLeft[i][s.charAt(i)-'a'] = i;\n\t\t}\n\t\t\n\t\t//from right keep the highest index (to the right) which keeps the substring T[j:n]\n\t\t//map[j] = that index\n\t\t//so it is smallest index from right\n\t\t\n\t\tint done = m-1;\n\t\t\n\t\tint[] finalMap2 = new int[m];\n\t\t\n\t\tfor(int i=n-1; i>=0; i--) {\n\t\t\tif (done==-1) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (s.charAt(i)==t.charAt(done)) {\n\t\t\t\tfinalMap2[done] = i; \n\t\t\t\tdone--;\n\t\t\t} \n\t\t}\n\t\t\n\t\tint[] finalMap1 = new int[m];\n\t\tdone = 0;\n\t\t\n\t\tfor(int i=0; i<n; i++) {\n\t\t\tif (done==m) break;\n\t\t\tif (s.charAt(i)==t.charAt(done)) {\n\t\t\t\tfinalMap1[done] = i;\n\t\t\t\tdone++;\n\t\t\t}\n\t\t}\n\t\t\n\t\tdone = 0;\n\t\t\n\t\tint ans = 0;\n\t\t\n\t\tint i = 0;\n\t\t\n\t\t//i to j-1 -> j-1-i+1 -> j-i\n\t\t\n\t\twhile(i<n) {\n\t\t\tans = Math.max(ans, finalMap2[done]-i);\n\t\t\ti = finalMap1[done]+1;\n\t\t\tdone++;\n\t\t\tif (done==m) {\n\t\t\t\tans = Math.max(ans, n-1-i+1);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\t\n\t\tprintln(ans);\n\t\t\n\t\t\n\t\t\n\t\tout.flush();\n\t\tout.close();\n\n\t}\n\n\t//NONPROBLEM CODE\n\n\tprivate static InputReader in = new InputReader(System.in);\n\tprivate static PrintWriter out = new PrintWriter(System.out);\n\n\tprivate static class InputReader {\n\n\t\tprivate final InputStream stream;\n\t\tprivate final byte[] buf = new byte[8192];\n\t\tprivate int curChar, snumChars;\n\n\t\tpublic InputReader(InputStream st) {\n\t\t\tthis.stream = st;\n\t\t}\n\n\t\tpublic int read() {\n\t\t\tif (snumChars == -1)\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tif (curChar >= snumChars) {\n\t\t\t\tcurChar = 0;\n\t\t\t\ttry {\n\t\t\t\t\tsnumChars = stream.read(buf);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t}\n\t\t\t\tif (snumChars <= 0)\n\t\t\t\t\treturn -1;\n\t\t\t}\n\t\t\treturn buf[curChar++];\n\t\t}\n\n\t\tpublic int nextInt() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint res = 0;\n\t\t\tdo {\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic long nextLong() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tint sgn = 1;\n\t\t\tif (c == '-') {\n\t\t\t\tsgn = -1;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tdo {\n\t\t\t\tres *= 10;\n\t\t\t\tres += c - '0';\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res * sgn;\n\t\t}\n\n\t\tpublic int[] nextIntArray(int n) {\n\t\t\tint a[] = new int[n];\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\ta[i] = nextInt();\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\n\t\tpublic String readString() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\tc = read();\n\t\t\t}\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isSpaceChar(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic String nextLine() {\n\t\t\tint c = read();\n\t\t\twhile (isSpaceChar(c))\n\t\t\t\tc = read();\n\t\t\tStringBuilder res = new StringBuilder();\n\t\t\tdo {\n\t\t\t\tres.appendCodePoint(c);\n\t\t\t\tc = read();\n\t\t\t} while (!isEndOfLine(c));\n\t\t\treturn res.toString();\n\t\t}\n\n\t\tpublic boolean isSpaceChar(int c) {\n\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t}\n\n\t\tprivate boolean isEndOfLine(int c) {\n\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t}\n\n\t}\n\n\t//INPUT SHORTCUTS\n\n\tprivate static int[] ina(int n) {\n\t\tint[] temp = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ttemp[i] = in.nextInt();\n\t\t}\n\t\treturn temp;\n\t}\n\n\tprivate static int ini() {\n\t\treturn in.nextInt();\n\t}\n\n\tprivate static String ins() {\n\t\treturn in.readString();\n\t}\n\n\t//OTHER SHORTCUTS\n\tpublic static void sort(int[] a) {\n\t\tArrays.sort(a);\n\t}\n\n\t//PRINT SHORTCUTS\n\n\tprivate static void println(Object... o) {\n\t\tfor (Object x : o) {\n\t\t\tout.write(x + \" \");\n\t\t}\n\t\tout.write(\"\\n\");\n\t}\n\n\tprivate static void print(Object... o) {\n\t\tfor (Object x : o) {\n\t\t\tout.write(x + \"\");\n\t\t}\n\t}\n\n\tprivate static void printAll(Object... o) {\n\t\tfor (Object x : o) {\n\t\t\tout.write(x + \" \");\n\t\t}\n\t}\n\n\tprivate static void debug(Object... o) {\n\t\tfor (Object x : o) {\n\t\t\tout.write(x + \" \");\n\t\t}\n\t\tout.write(\"\\n\");\n\t\tout.flush();\n\t}\n\n\tprivate static HashMap<Integer, ArrayList<Integer>> intree(int n) {\n\n\t\tHashMap<Integer, ArrayList<Integer>> g = new HashMap<>();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tg.put(i, new ArrayList<>());\n\t\t}\n\n\t\tfor (int i = 0; i < n - 1; i++) {\n\t\t\tint u = ini() - 1;\n\t\t\tint v = ini() - 1;\n\t\t\tg.get(u).add(v);\n\t\t\tg.get(v).add(u);\n\t\t}\n\n\t\treturn g;\n\t}\n}\n", "src_uid": "0fd33e1bdfd6c91feb3bf00a2461603f"} {"source_code": "import java.util.*;\nimport java.io.*;\n\npublic class CF797A{ \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(), k = in.nextInt();\n \n ArrayList<Integer> list = new ArrayList<>();\n \n while(list.size() < k && n > 1){\n \n if(list.size() == k-1 && n > 1){\n list.add(n);\n n = 1;\n break;\n }\n \n for(int i = 2; i <= n; i++){\n if(n%i == 0) {\n list.add(i);\n n /= i;\n break;\n }\n }\n \n }\n \n if(list.size() < k || n != 1) pw.println(-1);\n else{\n for(int i : list) pw.print(i+\" \");\n pw.println();\n }\n \n \n \n \n pw.close();\n }\n \n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n \n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n tokenizer = null;\n }\n \n public String next()throws Exception {\n while (tokenizer == null || !tokenizer.hasMoreTokens())\n tokenizer = new StringTokenizer(reader.readLine());\n return tokenizer.nextToken();\n }\n \n public String nextLine()throws Exception {\n String line = null;\n tokenizer = null;\n line = reader.readLine();\n return line;\n }\n \n public int nextInt()throws Exception {\n return Integer.parseInt(next());\n }\n \n public double nextDouble() throws Exception{\n return Double.parseDouble(next());\n }\n \n public long nextLong()throws Exception {\n return Long.parseLong(next());\n }\n \n }\n}", "src_uid": "bd0bc809d52e0a17da07ccfd450a4d79"} {"source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class D {\n\n\tstatic class Point {\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 String toString() {\n\t\t\treturn \"(\" + x + \", \" + y + \")\";\n\t\t}\n\t}\n\n\tvoid submit() {\n\t\tint n = nextInt();\n\t\tint nn = n;\n\t\tPoint[] a = new Point[n];\n\t\tlong sx = 0;\n\t\tlong sy = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint x = nextInt() * 2;\n\t\t\tint y = nextInt() * 2;\n\t\t\ta[i] = new Point(x, y);\n\t\t\tsx += x;\n\t\t\tsy += y;\n\t\t}\n\t\t\n\t\tboolean[] mark = new boolean[n];\n\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tlong ix = 2 * sx - (long)n * a[i].x;\n\t\t\tlong iy = 2 * sy - (long)n * a[i].y;\n\t\t\tfor (int j = i; j < n; j++) {\n\t\t\t\tif ((long)n * a[j].x == ix && (long)n * a[j].y == iy) {\n\t\t\t\t\tmark[j] = mark[i] = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t{\n\t\t\tPoint[] b = new Point[n];\n\t\t\tint ptr = 0;\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (!mark[i]) {\n\t\t\t\t\tb[ptr++] = a[i];\n\t\t\t\t}\n\t\t\t}\n\t\t\ta = Arrays.copyOf(b, ptr);\n\t\t}\n\t\t\n\t\tn = a.length;\n\t\t\n\t\tif (n == 0) {\n\t\t\tout.println(-1);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tBigInteger[] dx = new BigInteger[n];\n\t\tBigInteger[] dy = new BigInteger[n];\n\t\t\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint mx = (a[0].x + a[i].x) / 2;\n\t\t\tint my = (a[0].y + a[i].y) / 2;\n\t\t\tdx[i] = b((long)nn * my - sy);\n\t\t\tdy[i] = b(sx - (long)nn * mx);\n\t\t}\n\n\t\tBigInteger[] p = new BigInteger[n];\n\t\t\n\t\tint ans = 0;\n\t\t\n\t\touter: for (int i = 0; i < n; i++) {\n\t\t\tfor (int j = 0; j < i; j++) {\n\t\t\t\tif (dx[i].multiply(dy[j]).equals(dy[i].multiply(dx[j]))) {\n\t\t\t\t\tcontinue outer;\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int j = 0; j < n; j++) {\n\t\t\t\tp[j] = dx[i].multiply(b(a[j].x)).add(dy[i].multiply(b(a[j].y)));\n\t\t\t}\n\t\t\tArrays.sort(p);\n\t\t\tBigInteger sum = p[0].add(p[n - 1]);\n\t\t\tfor (int p1 = 1, p2 = n - 2; p1 <= p2; p1++, p2--) {\n\t\t\t\tif (!p[p1].add(p[p2]).equals(sum)) {\n\t\t\t\t\tcontinue outer;\n\t\t\t\t}\n\t\t\t}\n\t\t\tans++;\n\t\t}\n\t\tout.println(ans);\n\t}\n\n\tBigInteger b(long x) {\n\t\treturn BigInteger.valueOf(x);\n\t}\n\t\n\tvoid preCalc() {\n\n\t}\n\n\tvoid stress() {\n\n\t}\n\n\tvoid test() {\n\n\t}\n\n\tD() throws IOException {\n\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\tout = new PrintWriter(System.out);\n\t\tpreCalc();\n\t\tsubmit();\n\t\t// stress();\n\t\t// test();\n\t\tout.close();\n\t}\n\n\tstatic final Random rng = new Random();\n\n\tstatic int rand(int l, int r) {\n\t\treturn l + rng.nextInt(r - l + 1);\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tnew D();\n\t}\n\n\tBufferedReader br;\n\tPrintWriter out;\n\tStringTokenizer st;\n\n\tString nextToken() {\n\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\ttry {\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tString nextString() {\n\t\ttry {\n\t\t\treturn br.readLine();\n\t\t} catch (IOException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t}\n\n\tint nextInt() {\n\t\treturn Integer.parseInt(nextToken());\n\t}\n\n\tlong nextLong() {\n\t\treturn Long.parseLong(nextToken());\n\t}\n\n\tdouble nextDouble() {\n\t\treturn Double.parseDouble(nextToken());\n\t}\n}", "src_uid": "5d7ba962400c05433ee17c5658888e69"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class A {\n\t\n\tpublic static void main(String[] args) throws IOException {\n\n\t\t\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\t\t\n\t\t\n\t\tint n = Integer.parseInt(br.readLine());\n\t\t\n\t\tString s = br.readLine();\n\t\t\n\t\t\n\t\tString go = \"go\";\n\t\tString ogo = \"ogo\";\n\t\t\n\t\t\n\t\tint begin = 0;\n\t\tint end = 0;\n\t\t\n\t\tboolean flag = false;\n\t\t\n\t\tString ss = \"\";\n\t\t\n\t\tfor (int i = 0; i < s.length(); i++) {\n\t\t\t\n\t\t\tif(!flag){\n\t\t\tif(i <= s.length()-3 && s.substring(i, i+3).equals(ogo)){\n\t\t\t\tflag = true;\n\t\t\t\tbegin = i;\n\t\t\t\tend = i+3;\n\t\t\t\ti = i+2;\n\t\t\t\tss += \"***\";\n\t\t\t}else{\n\t\t\t\t\n\t\t\tss += s.charAt(i);\n\t\t\t\n\t\t\t}\n\n\t\t\t\n\t\t\t}else{\n\t\t\t\t//System.out.println(\"3w\");\n\n\t\t\t\tif(i <= s.length()-2 && s.substring(i,i+2).equals(go)){\n\t\t\t\t\ti++;\n\t\t\t\t\tend = i+1;\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}else{\n\t\t\t\t\tflag = false;\n\t\t\t\t\t//ss +=\"\"+ s.charAt(i) +s.charAt(i+1);\n\t\t\t\t\ti = end-1;\n\t\t\t\t//System.out.println(i+1);\n\t\t\t\t\t//System.out.println(end);\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\t\t\n\t\t\t}\n\t\t\t\n\t\t}\n\t\t\n\t\t//System.out.println(end);\n\t\t\t\n\n\t\t\n\t\tSystem.out.println(ss);\n\t\t\n\t\t\n\t}\n\n}\n", "src_uid": "619665bed79ecf77b083251fe6fe7eb3"} {"source_code": "/**\n * Created on 6/8/14\n *\n * @author: Anirudh Rayabharam <anirudh.rayabharam@gmail.com>\n * @handle: code_overlord\n */\nimport java.io.*;\n\npublic class KitaharaHarukiGift {\n public static void main(String[] args) {\n InputReader in = new InputReader(System.in);\n PrintStream out = System.out;\n\n int n = in.nextInt();\n int[] w = new int[n];\n\n int sum = 0;\n int oneH, twoH;\n oneH = twoH = 0;\n for (int i = 0; i < n; i++) {\n w[i] = in.nextInt();\n sum += w[i];\n if (w[i] == 100) oneH++;\n else twoH++;\n }\n\n int each = sum / 2;\n int x = sum / 100;\n\n if (x % 2 == 1) out.println(\"NO\");\n else {\n boolean possible = false;\n for (int i = 0; i <= twoH; i++) {\n if (200 * i <= each && each - 200 * i <= oneH * 100) possible = true;\n }\n\n if (possible) out.println(\"YES\");\n else out.println(\"NO\");\n }\n }\n\n private static class InputReader {\n public BufferedReader reader;\n private int tokenCount, nextTokenIndex;\n private String[] tokens;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream));\n tokenCount = nextTokenIndex = 0;\n }\n\n public String next() {\n String nextLine;\n if (nextTokenIndex == tokenCount) {\n try {\n nextLine = reader.readLine();\n nextTokenIndex = 0;\n tokens = nextLine.split(\"\\\\s\");\n tokenCount = tokens.length;\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n\n return tokens[nextTokenIndex++];\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}\n", "src_uid": "9679acef82356004e47b1118f8fc836a"} {"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.InputMismatchException;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.Writer;\nimport java.io.BufferedReader;\nimport java.util.Comparator;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author Arthur Gazizov [2oo7] - Kazan FU\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 FastPrinter out = new FastPrinter(outputStream);\n TaskD solver = new TaskD();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskD {\n public static int cmpOne(Func a, Func b) {\n if (MathUtils.equals(a.x, 1)) {\n int cmp = Double.compare(a.x, b.x);\n return MathUtils.equals(cmp, 0) ? 0 : cmp;\n }\n if (MathUtils.equals(b.x, 1)) {\n int cmp = Double.compare(a.x, b.x);\n return MathUtils.equals(cmp, 0) ? 0 : cmp;\n }\n return 0;\n }\n\n public static int cmp(Func a, Func b) {\n int test = cmpOne(a, b);\n if (test != 0) return test;\n if ((a.x - 1) * (b.x - 1) < 0) return Double.compare(a.x, b.x);\n return MathUtils.equals(a.get(), b.get()) ? 0 : (MathUtils.sign(a.x - 1)) * Double.compare(a.get(), b.get());\n }\n\n public void solve(int testNumber, FastScanner in, FastPrinter out) {\n double x = in.nextDouble();\n double y = in.nextDouble();\n double z = in.nextDouble();\n Func[] funcs = new Func[12];\n funcs[0] = new Func(x, y, z, 0, 0);\n funcs[1] = new Func(x, z, y, 0, 1);\n funcs[2] = new Func(x, y, z, 1, 2);\n funcs[3] = new Func(x, z, y, 1, 3);\n funcs[4] = new Func(y, x, z, 0, 4);\n funcs[5] = new Func(y, z, x, 0, 5);\n funcs[6] = new Func(y, x, z, 1, 6);\n funcs[7] = new Func(y, z, x, 1, 7);\n funcs[8] = new Func(z, x, y, 0, 8);\n funcs[9] = new Func(z, y, x, 0, 9);\n funcs[10] = new Func(z, x, y, 1, 10);\n funcs[11] = new Func(z, y, x, 1, 11);\n int size = 12;\n Comparator<Func> fuck = new Comparator<Func>() {\n public int compare(Func a, Func b) {\n int c = cmp(a, b);\n return c == 0 ? -Integer.compare(a.index, b.index) : c;\n }\n };\n Arrays.sort(funcs, fuck);\n String ans = \"\";\n switch (funcs[11].index) {\n case 0:\n ans = \"x^y^z\";\n break;\n case 1:\n ans = \"x^z^y\";\n break;\n case 2:\n ans = \"(x^y)^z\";\n break;\n case 3:\n ans = \"(x^z)^y\";\n break;\n case 4:\n ans = \"y^x^z\";\n break;\n case 5:\n ans = \"y^z^x\";\n break;\n case 6:\n ans = \"(y^x)^z\";\n break;\n case 7:\n ans = \"(y^z)^x\";\n break;\n case 8:\n ans = \"z^x^y\";\n break;\n case 9:\n ans = \"z^y^x\";\n break;\n case 10:\n ans = \"(z^x)^y\";\n break;\n case 11:\n ans = \"(z^y)^x\";\n break;\n }\n out.print(ans);\n }\n\n }\n\n static class Func {\n public double x;\n public double y;\n public double z;\n public int type;\n public int index;\n\n public Func(double x, double y, double z, int type, int index) {\n this.x = x;\n this.y = y;\n this.z = z;\n this.type = type;\n this.index = index;\n }\n\n public double get() {\n return type == 0 ? Math.log(Math.abs(Math.log(x))) + z * Math.log(y) : Math.log(Math.abs(Math.log(x))) + Math.log(y * z);\n }\n\n }\n\n static class FastScanner extends BufferedReader {\n boolean isEOF;\n\n public FastScanner(InputStream is) {\n super(new InputStreamReader(is));\n }\n\n public FastScanner(InputStreamReader inputStreamReader) {\n super(inputStreamReader);\n }\n\n public int read() {\n try {\n int ret = super.read();\n if (isEOF && ret < 0) {\n throw new InputMismatchException();\n }\n isEOF = ret == -1;\n return ret;\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n }\n\n public static boolean isWhiteSpace(int c) {\n return c >= -1 && c <= 32;\n }\n\n public static boolean isSpaceChar(int c) {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\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 (!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 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 NumberFormatException(\"digit expected \" + (char) c\n + \" found\");\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 UnknownError();\n m /= 10;\n res += (c - '0') * m;\n c = read();\n }\n }\n return res * sgn;\n }\n\n public String readLine() {\n try {\n return super.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n }\n return null;\n }\n\n }\n\n static class FastPrinter extends PrintWriter {\n public FastPrinter(Writer writer) {\n super(writer);\n }\n\n public FastPrinter(OutputStream out) {\n super(out);\n }\n\n public void close() {\n super.close();\n }\n\n }\n\n static class MathUtils<T> {\n public static final double EPS = 1e-9;\n\n public static final double abs(double value) {\n return value >= 0 ? value : -value;\n }\n\n public static final int sign(double value) {\n if (value > EPS) return 1;\n if (value < -EPS) return -1;\n return 0;\n }\n\n public static final boolean equals(double a, double b) {\n return abs(a - b) < EPS;\n }\n\n }\n}\n", "src_uid": "a71cb5cda754ad2bf479bc3b0164fc4c"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n\tvoid solve(Scanner in, PrintWriter out) {\n\n\t\tint n = in.nextInt();\n\t\tout.println(3L * (1 + n) * n + 1);\n\t}\n\n\tvoid run() {\n\t\ttry (Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out)) {\n\t\t\tsolve(in, out);\n\t\t}\n\n\t}\n\n\tpublic static void main(String args[]) {\n\t\tnew Main().run();\n\t}\n}", "src_uid": "c046895a90f2e1381a7c1867020453bd"} {"source_code": "//package com.company;\n\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n // write your code here\n StringBuilder sb = new StringBuilder();\n Scanner s=new Scanner(System.in);\n char[] a=s.next().toCharArray();StringBuilder power=new StringBuilder();int flag=0;char[] base=new char[a.length];\n for(int i=0;i<a.length;i++){\n if(a[i]=='e'){\n flag=1;continue;\n }\n if(flag==0){\n base[i]=(a[i]);\n }else{\n power.append(a[i]);\n }\n }flag=0;int p=Integer.parseInt(power.toString());int clur=0;\n for(int i=0;i<a.length;i++){\n if(a[i]=='e') break;\n if(flag==0){if(a[i]=='.') {\n flag=1;continue;\n }\n sb.append(a[i]);\n }else{if(a[i]=='0'&&a[i-1]=='.'&&(a[i+1]=='e')) {\n while(p>0){\n sb.append('0');p--;\n }\n break;}\n if(p>0){\n sb.append(a[i]);p--;\n }else{if(clur==0){\n sb.append('.'); clur=1;}sb.append(a[i]);\n }\n }\n }while(p>0){\n sb.append('0');p--;\n }\n System.out.println(sb.toString());\n }static int success=0,endi=0,endj=0;static char[][] a;static int n,m;static int[] [] vis;\nstatic void dfs(int i,int j,char dir,int turns){\n // vis[i][j]=1;\n if(turns>2) return;\n\n if(dir=='Z'){\n if(i+1<n&&a[i+1][j]=='T') {\n success=1;return;\n }if(success==1) return;\n if(i+1<n&&a[i+1][j]!='*'&&vis[i+1][j]==0){\n dfs(i+1,j,'D',turns);\n }if(success==1) return;if(i-1>=0&&a[i-1][j]=='T') {\n success=1;return;\n }if(success==1) return;\n if(i-1>=0&&a[i-1][j]!='*'&&vis[i-1][j]==0){\n dfs(i-1,j,'U',turns);\n }if(success==1) return;\n if(j+1<m&&a[i][j+1]=='T') {\n success=1;return;\n }if(success==1) return;\n if(j+1<m&&a[i][j+1]!='*'&&vis[i][j+1]==0){\n dfs(i,j+1,'R',turns);\n }if(success==1) return;\n if(j-1>=0&&a[i][j-1]=='T') {\n success=1;\n }if(success==1) return;\n if(j-1>=0&&a[i][j-1]!='*'){\n dfs(i,j-1,'L',turns);\n }if(success==1) return;\n }else{\n if(i+1<n&&a[i+1][j]=='T') {\n if(turns<2||'D'==dir)\n success=1;\n }if(success==1) return;\n if(i+1<n&&a[i+1][j]!='*'&&vis[i+1][j]==0){\n if('D'!=dir) dfs(i+1,j,'D',turns+1);else dfs(i+1,j,'D',turns);\n\n }if(success==1) return;\n if(i-1>=0&&a[i-1][j]=='T') {\n if(turns<2||'U'==dir)\n\n success=1;;\n }if(success==1) return;\n if(i-1>=0&&a[i-1][j]!='*'&&vis[i-1][j]==0){\n if('U'!=dir)\n dfs(i-1,j,'U',turns+1);else dfs(i-1,j,'U',turns);\n\n }if(success==1) return;\n if(j+1<m&&a[i][j+1]=='T') {\n if(turns<2||'R'==dir)\n\n success=1;;\n }if(success==1) return;\n if(j+1<m&&a[i][j+1]!='*'&&vis[i][j+1]==0){\n if('R'!=dir)\n dfs(i,j+1,'R',turns+1);\n else\n dfs(i,j+1,'R',turns);\n\n }if(success==1) return;\n if(j-1>=0&&a[i][j-1]=='T') {\n if(turns<2||'L'==dir)\n success=1;\n\n }if(success==1) return;\n if(j-1>=0&&a[i][j-1]!='*'&&vis[i][j-1]==0){\n if('L'!=dir)\n dfs(i,j-1,'L',turns+1);\n else\n dfs(i,j-1,'L',turns);\n\n }if(success==1) return;\n }\n}\n\n}\n", "src_uid": "a79358099f08f3ec50c013d47d910eef"} {"source_code": "//I AM THE CREED\n/* //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.*;\npublic class Main{\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 String s=input.next();\n int min=s.length();\n for(int i=0;i<s.length();i++){\n if((2)*(i+1)>s.length()){\n break;\n }\n if(s.substring(0, i+1).equals(s.substring(i+1, (2*i)+2))){\n min=Math.min(s.length()-(i), min);\n }\n }\n System.out.println(min);\n }\n \n }\n \n\n\n}", "src_uid": "ed8725e4717c82fa7cfa56178057bca3"} {"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 E802 solver = new E802();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class E802 {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n\n int n = in.nextInt();\n int[] a = new int[250];\n\n for (int v = 1; v <= n; v++) {\n\n double sum = 0;\n for (int i = 0; i < 250; i++) {\n a[i] = in.nextInt();\n sum += a[i];\n }\n\n double mean = sum / 250;\n\n double variance = 0;\n\n for (int i = 0; i < 250; i++) {\n double deviation = mean - a[i];\n variance += deviation * deviation;\n }\n\n variance /= 250;\n\n int ans = 0;\n\n if (2 * mean >= variance) { //gaussian\n ans = ((int) Math.round(mean));\n } else { //uniform\n ans = arrays.max(a) + arrays.min(a);\n ans = ((int) Math.round(ans / 2.));\n }\n\n out.println(ans);\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 arrays {\n public static int max(int[] a) {\n int ans = a[0];\n for (int i : a) {\n ans = Math.max(ans, i);\n }\n return ans;\n }\n\n public static int min(int[] a) {\n int ans = a[0];\n for (int i : a) {\n ans = Math.min(ans, i);\n }\n return ans;\n }\n\n }\n}\n\n", "src_uid": "18bf2c587415f85df83fb090e16b8351"} {"source_code": "import java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.List;\nimport java.util.Scanner;\n\npublic class Main\n{\n\n static Scanner p = new Scanner(System.in);\n public static void main(String[] args) {\n String[] nmab = p.nextLine().split(\" \");\n int mb = Integer.parseInt(nmab[1]) * Integer.parseInt(nmab[3]);\n int na = Integer.parseInt(nmab[0]) * Integer.parseInt(nmab[2]);\n int n = Integer.parseInt(nmab[0]);\n int m = Integer.parseInt(nmab[1]);\n int a = Integer.parseInt(nmab[2]);\n int b = Integer.parseInt(nmab[3]);\n if(b / m < a){\n if(m == n){\n System.out.println(b);\n System.exit(0);\n }else if(m < n){\n if((n % m) % 2 == 0 && b < a){\n System.out.println(b*((n + m - 1) / m));\n System.exit(0);\n }else{\n if(b < a){\n System.out.println(b*(n/m)+(b*(n%m)));\n System.exit(0);\n }else{\n System.out.println((b*(n/m))+((n%m)*a));\n System.exit(0);\n }\n }\n\n }else{\n if(b > a && (n*a) < b){\n System.out.println(n*a);\n System.exit(0);\n }else{\n System.out.println(b);\n }\n }\n }else{\n System.out.println(n*a);\n System.exit(0);\n }\n }\n}\n\n", "src_uid": "faa343ad6028c5a069857a38fa19bb24"} {"source_code": "import java.util.Scanner;\n\n\npublic class PointOnSpiral {\n \n public static int go(int x , int y){\n int step = 1;\n int flag = 0;\n int sx = 0 , sy = 0;\n int result = 0;\n while(true){\n int nx = sx , ny = sy;\n if(flag == 0){\n if(nx <= 0)\n nx += step;\n else\n nx -= step;\n }else{\n if(ny <= 0){\n ny += step;\n }else\n ny -= step;\n }\n \n if(sx == nx && x == sx && (y >= sy && y <= ny || y >= ny && y <= sy))\n return result;\n \n if(sy == ny && y == sy && (x >= sx && x <= nx || x >= nx && x <= sx))\n return result;\n \n flag ++;\n if(flag == 2){\n step ++;\n flag = 0;\n }\n result ++;\n sx = nx;\n sy = ny;\n }\n }\n \n public static void main(String args[]){\n Scanner s = new Scanner(System.in);\n int x = s.nextInt();\n int y = s.nextInt();\n System.out.println(go(x , y));\n }\n\n}\n", "src_uid": "2fb2a129e01efc03cfc3ad91dac88382"} {"source_code": "import java.io.*;\nimport java.util.*;\n\n/**\n * Created by hapsi on 11.10.2016.\n */\npublic class Main {\n private static class FastScanner {\n private BufferedReader br;\n private StringTokenizer st;\n public FastScanner(InputStream inputStream){\n br = new BufferedReader(new InputStreamReader(inputStream));\n }\n public String next() {\n while (st == null || !st.hasMoreTokens()){\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException ignored){}\n }\n return st.nextToken();\n }\n public int nextInt() {\n return Integer.parseInt(next());\n }\n public long nextLong() {\n return Long.parseLong(next());\n }\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n }\n\n private static int binarySearch(int []a, int l, int r, int x){\n if (l >= r) return -1;\n int m = (l + r) / 2;\n if (a[m] > x || (a[m] == x && m > 0 && a[m-1] == x))\n return binarySearch(a, l, m, x);\n else if (a[m] < x)\n return binarySearch(a, m + 1, r, x);\n return m;\n }\n\n private static int nextSearch(int []a, int l, int r, int x){\n if (l >= r) return l;\n int m = (l + r) / 2;\n if (a[m] > x)\n return nextSearch(a, l, m, x);\n else if (a[m] < x || (m < a.length - 1 && a[m+1] == x))\n return nextSearch(a, m + 1, r, x);\n return m + 1;\n }\n\n private static int nearestSearch(int []a, int l, int r, int x) {\n if (l >= r) {\n if (a.length == 1) {\n return 0;\n }\n else if (l >= a.length) {\n return a.length - 1;\n }\n else if (l-1 >= 0) {\n int d1 = Math.abs(a[l-1] - x);\n int d2 = Math.abs(a[l] - x);\n if (d1 <= d2) {\n return l-1;\n }\n return l;\n }\n else {\n return l;\n }\n }\n int m = (l + r) / 2;\n if (a[m] > x || (a[m] == x && m > 0 && a[m-1] == x)) {\n return nearestSearch(a, l, m, x);\n }\n else if (a[m] < x) {\n return nearestSearch(a, m + 1, r, x);\n }\n return m;\n }\n\n private static int compareString(String a, String b){\n if(a.length() > b.length()){\n return 1;\n }\n else if(a.length() < b.length()){\n return -1;\n }\n for(int i=0;i<a.length();i++){\n if(a.charAt(i) > b.charAt(i)){\n return 1;\n }\n else if(a.charAt(i) < b.charAt(i)){\n return -1;\n }\n }\n return 0;\n }\n\n public static void main(String args[]){\n FastScanner scanner = new FastScanner(System.in);\n PrintWriter printer = new PrintWriter(System.out);\n //printer.println((long)Math.pow(10,9) + \" \" + (long)Math.pow(10,9) + \" \" + ((long)((Math.pow(10,9) * Math.pow(10,9))) - 1));\n long n = scanner.nextLong(), m = scanner.nextLong(), k = scanner.nextLong();\n if (k <= n - 1) {\n printer.println((k+1) + \" 1\");\n }\n else {\n k-=n;\n if(k == 0) {\n printer.println(n + \" 2\");\n }\n else {\n long d = k / (m - 1);\n long x = n - d;\n k-=d;\n if (m-2 > 0) {\n k = k - (k / ((m - 2) * 2)) * ((m - 2) * 2);\n }\n long y = 2;\n boolean r = true;\n while(true) {\n if (k <= m - 2) {\n if (r) {\n y += k;\n } else {\n y -= k;\n }\n break;\n } else {\n y = m;\n k -= m - 2;\n r = !r;\n }\n }\n printer.println(x + \" \" + y);\n }\n }\n\n printer.close();\n }\n}\n\n", "src_uid": "e88bb7621c7124c54e75109a00f96301"} {"source_code": "import java.util.Scanner;\n\npublic class CF552_C {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int a = sc.nextInt(),\n b = sc.nextInt(),\n c = sc.nextInt();\n\n int[] aW = new int[]{1,0,0,1,0,0,1};\n int[] bW = new int[]{0,1,0,0,0,1,0};\n int[] cW = new int[]{0,0,1,0,1,0,0};\n\n\n\n long best = 0;\n for(int day = 0; day < 7; day++){\n long aa = a, bb = b, cc = c;\n\n long counter = 0;\n\n for(int i = day; i < 7; i++){\n aa-=aW[i];\n bb-=bW[i];\n cc-=cW[i];\n if(aa < 0 || bb < 0 || cc < 0){\n if(aa < 0) aa=0;\n if(bb < 0) bb=0;\n if(cc < 0) cc=0;\n break;\n }\n counter++;\n }\n\n\n long daysA = aa/3;\n long daysB = bb/2;\n long daysC = cc/2;\n\n long fullWeeks = Math.min(daysA, Math.min(daysB, daysC));\n\n counter+= fullWeeks * 7;\n\n aa-=fullWeeks * 3;\n bb-=fullWeeks * 2;\n cc-=fullWeeks * 2;\n\n for(int i = 0; i < 7; i++){\n aa-=aW[i];\n bb-=bW[i];\n cc-=cW[i];\n if(aa < 0 || bb < 0 || cc < 0){\n break;\n }\n counter++;\n }\n\n best = Math.max(counter, best);\n }\n\n System.out.println(best);\n\n }\n\n\n}\n", "src_uid": "e17df52cc0615585e4f8f2d31d2daafb"} {"source_code": "import java.util.*;\n\npublic class Test {\n\n public static void main(String args[]) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int a = in.nextInt();\n int b = in.nextInt();\n int c = in.nextInt();\n\n int count = 0;\n for(int i=0;i<=a;i+=2){\n int rem = n;\n rem = rem - i/2;\n for(int j=0;j<=b&&j<=rem;j++){\n int rem1 = rem - j;\n if(rem1%2==0&&rem1/2<=c)\n count++;\n }\n }\n System.out.println(count);\n }\n}", "src_uid": "474e527d41040446a18186596e8bdd83"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.StringTokenizer;\n\npublic class CF336A {\n public static void main(String[] args) {\n FastReader input = new FastReader();\n PrintWriter pw = new PrintWriter(System.out);\n\n int x = input.nextInt();\n int y = input.nextInt();\n\n if(x > 0 && y > 0)\n pw.println(0 + \" \" + (x+y) + \" \" + (x+y) + \" \" + 0);\n\n else if(x > 0 && y < 0){\n x = Math.abs(x);\n y = Math.abs(y);\n\n pw.println(0 + \" \" + ((-1) * (x+y)) + \" \" + (x+y) + \" \" + 0);\n }\n\n else if(x < 0 && y > 0){\n x = Math.abs(x);\n y = Math.abs(y);\n\n pw.println(((-1) * (x+y)) + \" \" + 0 + \" \" + 0 + \" \" + (x+y));\n }\n\n else if(x < 0 && y < 0){\n x = Math.abs(x);\n y = Math.abs(y);\n\n pw.println(((-1) * (x+y)) + \" \" + 0 + \" \" + 0 + \" \" + ((-1) * (x+y)));\n }\n\n\n // ****If sorting is required, use ArrayList\n pw.flush();\n pw.close();\n }\n static class FastReader\n {\n BufferedReader br;\n StringTokenizer st;\n\n public FastReader()\n {\n br = new BufferedReader(new\n InputStreamReader(System.in));\n }\n\n String next()\n {\n while (st == null || !st.hasMoreElements())\n {\n try\n {\n st = new StringTokenizer(br.readLine());\n }\n catch (IOException e)\n {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt()\n {\n return Integer.parseInt(next());\n }\n\n long nextLong()\n {\n return Long.parseLong(next());\n }\n\n double nextDouble()\n {\n return Double.parseDouble(next());\n }\n\n String nextLine()\n {\n String str = \"\";\n try\n {\n str = br.readLine();\n }\n catch (IOException e)\n {\n e.printStackTrace();\n }\n return str;\n }\n }\n}\n", "src_uid": "e2f15a9d9593eec2e19be3140a847712"} {"source_code": " import java.io.IOException;\n \n import java.util.*;\n \n public class Training {\n \n \t \n \n public static void main(String[] args) throws IOException {\n \t\tScanner input = new Scanner(System.in);\n int [][]a= new int[8][8];\n String answer = \"NO\";\n for(int i =2;i<6;i++){\n String s= input.next();\n for(int j=2;j<6;j++){\n if(s.charAt(j-2)=='x'){\n a[i][j]= 1;\n \n }else if(s.charAt(j-2)=='o'){\n a[i][j]= -1;\n }else if(s.charAt(j-2)=='.'){\n a[i][j]=10;\n }\n }\n }\n \n for(int i =2;i<6;i++){\n for(int j =2;j<6;j++){\n \n if ( a[i][j] + a[i][j+1] + a[i][j+2] == 12 )\n {\n answer = \"YES\";\n }\n if ( a[i][j] + a[i+1][j+1] + a[i+2][j+2] == 12 )\n {\n answer = \"YES\";\n }\n if ( a[i][j] + a[i+1][j] + a[i+2][j] == 12)\n {\n answer = \"YES\";\n }\n if ( a[i][j] + a[i-1][j+1] + a[i-2][j+2] == 12 )\n {\n answer = \"YES\";\n }\n \n }\n } // end for \n \n System.out.println(answer);\n \n \n } // end main\n \n \n \n \n \n } // end Class\n\n", "src_uid": "ca4a77fe9718b8bd0b3cc3d956e22917"} {"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\tArrayList<Integer> g [];\n\tArrayList<Integer> topoSort = new ArrayList<>();\n\t\n\tint vars[];\n\tint topIndex [];\n\tint color [];\n\tint variables[];\n\t\n\tboolean used [];\n\t\n\tboolean findCycle(int v) {\n\t\tif (color[v] == 2)\n\t\t\treturn false;\n\t\tif (color[v] == 1)\n\t\t\treturn true;\n\t\tcolor[v] = 1;\n\t\tfor (int i = 0; i < g[v].size(); i++)\n\t\t\tif (findCycle(g[v].get(i)))\n\t\t\t\treturn true;\n\t\tcolor[v] = 2;\n\t\treturn false;\n\t}\n\t\n\tvoid dfs(int v) {\n\t\tif (used[v])\n\t\t\treturn;\n\t\tused[v] = true;\n\t\tvariables[v] = 0;\n\t\tfor (int i = 0; i < g[v].size(); i++) {\n\t\t\tdfs(g[v].get(i));\n\t\t}\n\t\ttopoSort.add(v);\n\t}\n\t\n\tvoid findDivisonByZeroTypes(Node node) {\n\t\tif (node instanceof OperationNode) {\n\t\t\tOperationNode opNode = (OperationNode) node;\n\t\t\tVariableNode right = (VariableNode) opNode.right;\n\t\t\tif (opNode.operation == '/') {\n\t\t\t\tvariables[right.variableType] = 1;\n\t\t\t}\n\t\t\tfindDivisonByZeroTypes(opNode.left);\n\t\t\tfindDivisonByZeroTypes(opNode.right);\n\t\t} else {\n\t\t\treturn;\n\t\t}\n\t}\n\t\n\tinterface Node {\n\t\t\n\t\tlong eval (int[] variables);\n\t\t\n\t}\n\t\n\tclass VariableNode implements Node {\n\t\t\n\t\tint variableIndex;\n\t\tint variableType;\n\t\t\n\t\tpublic VariableNode(int variableIndex, int variableType) {\n\t\t\tthis.variableIndex = variableIndex;\n\t\t\tthis.variableType = variableType;\n\t\t}\n\t\t\n\t\t@Override\n\t\tpublic long eval(int[] variables) {\n\t\t\treturn variables[variableIndex];\n\t\t}\n\t\t\n\t}\n\t\n\tclass OperationNode implements Node {\n\t\t\n\t\tchar operation;\n\t\tNode left, right;\n\t\t\n\t\tpublic OperationNode(Node left, Node right, char operation) {\n\t\t\tthis.left = left;\n\t\t\tthis.right = right;\n\t\t\tthis.operation = operation;\n\t\t}\n\t\t\n\t\t@Override\n\t\tpublic long eval(int[] variables) {\n\t\t\tlong l = left.eval(variables);\n\t\t\tlong r = right.eval(variables);\n\t\t\tswitch (operation) {\n\t\t\t\tcase '+':\n\t\t\t\t\treturn l + r;\n\t\t\t\tcase '-':\n\t\t\t\t\treturn l - r;\n\t\t\t\tcase '*':\n\t\t\t\t\treturn l * r;\n\t\t\t\tcase '/':\n\t\t\t\t\treturn l / r;\n\t\t\t}\n\t\t\treturn 0;\n\t\t}\n\t\t\n\t}\n\t\n\tclass Parser {\n\t\t\n\t\tint it;\n\t\tString expression;\n\t\t\n\t\tint operationPriority[] = new int [256];\n\t\t\n\t\tint variables;\n\t\tArrayList<Integer> variableTypes = new ArrayList<>();\n\t\t\n\t\tpublic Parser() {\n\t\t\toperationPriority['-'] = operationPriority['+'] = 0;\n\t\t\toperationPriority['*'] = operationPriority['/'] = 1;\n\t\t}\n\t\t\n\t\tpublic Parser(String expression) {\n\t\t\tsuper();\n\t\t\tthis.expression = expression;\n\t\t}\n\t\t\n\t\tpublic Node parse() {\n\t\t\tit = 0;\n\t\t\treturn parse(0);\n\t\t}\n\t\t\n\t\tpublic int[] getVars() {\n\t\t\tint[] vars = new int [variables];\n\t\t\tfor (int i = 0; i < variables; i++) {\n\t\t\t\tvars[i] = variableTypes.get(i);\n\t\t\t}\n\t\t\treturn vars;\n\t\t}\n\t\t\n\t\tprivate Node parseValue() {\n\t\t\tint variableType = 0;\n\t\t\twhile (it < expression.length() && expression.charAt(it) == '_') {\n\t\t\t\tvariableType++;\n\t\t\t\tit++;\n\t\t\t}\n\t\t\tvariables++;\n\t\t\tvariableTypes.add(variableType);\n\t\t\treturn new VariableNode(variables - 1, variableType);\n\t\t}\n\t\t\n\t\tprivate Node parse(int prior) {\n\t\t\tif (prior == 2)\n\t\t\t\treturn parseValue();\n\t\t\tNode result = parse(prior + 1);\n\t\t\twhile (it < expression.length() && operationPriority[expression.charAt(it)] == prior) {\n\t\t\t\tchar operation = expression.charAt(it);\n\t\t\t\tit++;\n\t\t\t\tNode right = parse(prior + 1);\n\t\t\t\tresult = new OperationNode(result, right, operation);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\t\t\n\t}\n\t\n\tpublic void solve() throws Exception {\n\t\tcolor = new int [1024];\n\t\tg = new ArrayList[1024];\n\t\tfor (int i = 0; i < 1024; i++)\n\t\t\tg[i] = new ArrayList<>();\n\n\t\tString a = sc.nextToken();\n\t\tStringBuilder sb = new StringBuilder();\n\t\t\n\t\tint lBracket = a.indexOf('(');\n\t\tint rBracket = a.indexOf(')');\n\t\t\n\t\tString expression = a.substring(lBracket + 1, rBracket);\n\t\tParser parser = new Parser(expression); \n\t\t\n\t\tNode root = parser.parse();\n\t\t\n\t\tvars = parser.getVars();\n\t\tInteger varIndices[] = new Integer [vars.length];\n\t\tfor (int i = 0; i < vars.length; i++)\n\t\t\tvarIndices[i] = i;\n\t\t\n\t\tboolean usedTypes [] = new boolean[1024];\n\t\tfor (int i = 0; i < vars.length; i++) {\n\t\t\tusedTypes[vars[i]] = true;\n\t\t}\n\t\t\n\t\tint colon = a.indexOf(\":-\");\n\t\tString inequalityString = a.substring(colon + 2, a.length() - 1);\n\t\tString[] inequalities = inequalityString.split(\",\");\n\t\tfor (String inequality : inequalities) {\n\t\t\tchar separator;\n\t\t\tint separatorIndex = -1;\n\t\t\tif (inequality.indexOf('>') != -1) {\n\t\t\t\tseparator = '>';\n\t\t\t\tseparatorIndex = inequality.indexOf('>');\n\t\t\t} else {\n\t\t\t\tseparator = '<';\n\t\t\t\tseparatorIndex = inequality.indexOf('<');\n\t\t\t}\n\t\t\tint typeLeft = separatorIndex;\n\t\t\tint typeRight = inequality.length() - separatorIndex - 1;\n\t\t\tif (separator == '>') {\n\t\t\t\tg[typeLeft].add(typeRight);\n\t\t\t} else {\n\t\t\t\tg[typeRight].add(typeLeft);\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (int i = 0; i < 1024; i++) {\n\t\t\tif (color[i] == 0) {\n\t\t\t\tif (findCycle(i)) {\n\t\t\t\t\tout.println(\"false\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tvariables = new int [1024];\n\t\tused = new boolean [1024];\n\t\tArrays.fill(variables, -1);\n\t\tfor (int i = 0; i < 1024; i++) {\n\t\t\tif (usedTypes[i]) {\n\t\t\t\tdfs(i);\n\t\t\t}\n\t\t}\n\t\t\n\t\tfindDivisonByZeroTypes(root);\n\t\t\n\t\tfor (int type : topoSort) {\n\t\t\tint maxValue = 0;\n\t\t\tfor (int to : g[type]) {\n\t\t\t\tmaxValue = max (maxValue, variables[to] + 1);\n\t\t\t}\n\t\t\tvariables[type] = maxValue;\n\t\t\tif (variables[type] > 9) {\n\t\t\t\tout.println(\"false\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor (int i = 0; i < vars.length; i++) {\n\t\t\tout.print(variables[vars[i]]);\n\t\t}\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}", "src_uid": "390a0b72c77ebe5881b656830fbfae02"} {"source_code": "//package ecr104;\r\nimport java.io.*;\r\nimport java.util.ArrayDeque;\r\nimport java.util.Arrays;\r\nimport java.util.InputMismatchException;\r\nimport java.util.Queue;\r\n\r\npublic class G3 {\r\n\tInputStream is;\r\n\tFastWriter out;\r\n\tString INPUT = \"\";\r\n\r\n\tvoid solve()\r\n\t{\r\n\t\tfinal int mod = 998244353;\r\n\t\tint n = ni();\r\n\t\tint[] a = na(26);\r\n\t\tlong all = 26 * 26 * pow(25, n-2, mod) % mod;\r\n\r\n\t\tlong[][][] dp = new long[3][n+1][n+1];\r\n\t\tdp[0][1][0] = 1;\r\n\t\tdp[1][0][1] = 1;\r\n\t\tdp[2][0][0] = 1;\r\n\t\tfor(int i = 0;i < n-1;i++){\r\n\t\t\tlong[][][] ndp = new long[3][n+1][n+1];\r\n\t\t\tif(i == (n+1)/2-1){\r\n\t\t\t\tfor (int j = 0; j <= n; j++) {\r\n\t\t\t\t\tfor (int k = 0; j+k <= n; k++) {\r\n\t\t\t\t\t\tif (j + 1 <= n) {\r\n\t\t\t\t\t\t\tndp[0][j + 1][k] += dp[0][j][k] + dp[1][j][k] + dp[2][j][k] * 24;\r\n\t\t\t\t\t\t\tndp[0][j + 1][k] %= mod;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (k + 1 <= n) {\r\n\t\t\t\t\t\t\tndp[1][j][k + 1] += dp[0][j][k] + dp[1][j][k] + dp[2][j][k] * 24;\r\n\t\t\t\t\t\t\tndp[1][j][k + 1] %= mod;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tndp[2][j][k] += dp[0][j][k] + dp[1][j][k] + dp[2][j][k] * 24;\r\n\t\t\t\t\t\tndp[2][j][k] %= mod;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}else {\r\n\t\t\t\tfor (int j = 0; j <= n; j++) {\r\n\t\t\t\t\tfor (int k = 0; j+k <= n; k++) {\r\n\t\t\t\t\t\tif (j + 1 <= n) {\r\n\t\t\t\t\t\t\tndp[0][j + 1][k] += dp[1][j][k] + dp[2][j][k] * 24;\r\n\t\t\t\t\t\t\tndp[0][j + 1][k] %= mod;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (k + 1 <= n) {\r\n\t\t\t\t\t\t\tndp[1][j][k + 1] += dp[0][j][k] + dp[2][j][k] * 24;\r\n\t\t\t\t\t\t\tndp[1][j][k + 1] %= mod;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tndp[2][j][k] += dp[0][j][k] + dp[1][j][k] + dp[2][j][k] * 23;\r\n\t\t\t\t\t\tndp[2][j][k] %= mod;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t}\r\n\t\t\tdp = ndp;\r\n\t\t}\r\n\r\n\t\tlong[] sdp = new long[n+1];\r\n\t\tfor(int i = 0;i <= n;i++){\r\n\t\t\tfor(int j = 0;j <= n;j++){\r\n\t\t\t\tsdp[i] += dp[0][i][j] + dp[1][i][j] + dp[2][i][j] * 24;\r\n\t\t\t}\r\n\t\t\tsdp[i] %= mod;\r\n\t\t}\r\n\r\n\t\tfor(int i = 0;i < 26;i++){\r\n\t\t\tfor(int k = a[i]+1;k <= n;k++){\r\n\t\t\t\tall -= sdp[k];\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tfor(int i = 0;i < 26;i++){\r\n\t\t\tfor(int j = i+1;j < 26;j++){\r\n\t\t\t\tfor(int k = a[i]+1;k <= n;k++){\r\n\t\t\t\t\tfor(int l = a[j]+1;l+k <= n;l++){\r\n\t\t\t\t\t\tall += (dp[0][k][l] + dp[1][k][l] + dp[2][k][l] * 24);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tall %= mod;\r\n\t\t\t}\r\n\t\t}\r\n\t\tall %= mod;\r\n\r\n\t\tif(all < 0)all += mod;\r\n\t\tout.println(all);\r\n\t}\r\n\r\n\tpublic static long pow(long a, long n, long mod) {\r\n\t\t//\t\ta %= mod;\r\n\t\tlong ret = 1;\r\n\t\tint x = 63 - Long.numberOfLeadingZeros(n);\r\n\t\tfor (; x >= 0; x--) {\r\n\t\t\tret = ret * ret % mod;\r\n\t\t\tif (n << 63 - x < 0) ret = ret * a % mod;\r\n\t\t}\r\n\t\treturn ret;\r\n\t}\r\n\r\n\r\n\tpublic static long invl(long a, long mod) {\r\n\t\tlong b = mod;\r\n\t\tlong p = 1, q = 0;\r\n\t\twhile (b > 0) {\r\n\t\t\tlong c = a / b;\r\n\t\t\tlong d;\r\n\t\t\td = a;\r\n\t\t\ta = b;\r\n\t\t\tb = d % b;\r\n\t\t\td = p;\r\n\t\t\tp = q;\r\n\t\t\tq = d - c * q;\r\n\t\t}\r\n\t\treturn p < 0 ? p + mod : p;\r\n\t}\r\n\r\n\r\n\tpublic static long C(int n, int r, int mod, int[][] fif) {\r\n\t\tif (n < 0 || r < 0 || r > n) return 0;\r\n\t\treturn (long) fif[0][n] * fif[1][r] % mod * fif[1][n - r] % mod;\r\n\t}\r\n\r\n\r\n\tpublic static int[][] enumFIF(int n, int mod) {\r\n\t\tint[] f = new int[n + 1];\r\n\t\tint[] invf = new int[n + 1];\r\n\t\tf[0] = 1;\r\n\t\tfor (int i = 1; i <= n; i++) {\r\n\t\t\tf[i] = (int) ((long) f[i - 1] * i % mod);\r\n\t\t}\r\n\t\tlong a = f[n];\r\n\t\tlong b = mod;\r\n\t\tlong p = 1, q = 0;\r\n\t\twhile (b > 0) {\r\n\t\t\tlong c = a / b;\r\n\t\t\tlong d;\r\n\t\t\td = a;\r\n\t\t\ta = b;\r\n\t\t\tb = d % b;\r\n\t\t\td = p;\r\n\t\t\tp = q;\r\n\t\t\tq = d - c * q;\r\n\t\t}\r\n\t\tinvf[n] = (int) (p < 0 ? p + mod : p);\r\n\t\tfor (int i = n - 1; i >= 0; i--) {\r\n\t\t\tinvf[i] = (int) ((long) invf[i + 1] * (i + 1) % mod);\r\n\t\t}\r\n\t\treturn new int[][]{f, invf};\r\n\t}\r\n\r\n\r\n\tvoid run() throws Exception\r\n\t{\r\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\r\n\t\tout = new FastWriter(System.out);\r\n\t\t\r\n\t\tlong s = System.currentTimeMillis();\r\n\t\tsolve();\r\n\t\tout.flush();\r\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) throws Exception { new G3().run(); }\r\n\t\r\n\tprivate byte[] inbuf = new byte[1024];\r\n\tpublic int lenbuf = 0, ptrbuf = 0;\r\n\t\r\n\tprivate int readByte()\r\n\t{\r\n\t\tif(lenbuf == -1)throw new InputMismatchException();\r\n\t\tif(ptrbuf >= lenbuf){\r\n\t\t\tptrbuf = 0;\r\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\r\n\t\t\tif(lenbuf <= 0)return -1;\r\n\t\t}\r\n\t\treturn inbuf[ptrbuf++];\r\n\t}\r\n\t\r\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\r\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\r\n\t\r\n\tprivate double nd() { return Double.parseDouble(ns()); }\r\n\tprivate char nc() { return (char)skip(); }\r\n\t\r\n\tprivate String ns()\r\n\t{\r\n\t\tint b = skip();\r\n\t\tStringBuilder sb = new StringBuilder();\r\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\r\n\t\t\tsb.appendCodePoint(b);\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t\treturn sb.toString();\r\n\t}\r\n\t\r\n\tprivate char[] ns(int n)\r\n\t{\r\n\t\tchar[] buf = new char[n];\r\n\t\tint b = skip(), p = 0;\r\n\t\twhile(p < n && !(isSpaceChar(b))){\r\n\t\t\tbuf[p++] = (char)b;\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\r\n\t}\r\n\r\n\tprivate int[] na(int n)\r\n\t{\r\n\t\tint[] a = new int[n];\r\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\r\n\t\treturn a;\r\n\t}\r\n\r\n\tprivate long[] nal(int n)\r\n\t{\r\n\t\tlong[] a = new long[n];\r\n\t\tfor(int i = 0;i < n;i++)a[i] = nl();\r\n\t\treturn a;\r\n\t}\r\n\r\n\tprivate char[][] nm(int n, int m) {\r\n\t\tchar[][] map = new char[n][];\r\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\r\n\t\treturn map;\r\n\t}\r\n\r\n\tprivate int[][] nmi(int n, int m) {\r\n\t\tint[][] map = new int[n][];\r\n\t\tfor(int i = 0;i < n;i++)map[i] = na(m);\r\n\t\treturn map;\r\n\t}\r\n\r\n\tprivate int ni() { return (int)nl(); }\r\n\r\n\tprivate long nl()\r\n\t{\r\n\t\tlong num = 0;\r\n\t\tint b;\r\n\t\tboolean minus = false;\r\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\r\n\t\tif(b == '-'){\r\n\t\t\tminus = true;\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\r\n\t\twhile(true){\r\n\t\t\tif(b >= '0' && b <= '9'){\r\n\t\t\t\tnum = num * 10 + (b - '0');\r\n\t\t\t}else{\r\n\t\t\t\treturn minus ? -num : num;\r\n\t\t\t}\r\n\t\t\tb = readByte();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic static class FastWriter\r\n\t{\r\n\t\tprivate static final int BUF_SIZE = 1<<13;\r\n\t\tprivate final byte[] buf = new byte[BUF_SIZE];\r\n\t\tprivate final OutputStream out;\r\n\t\tprivate int ptr = 0;\r\n\r\n\t\tprivate FastWriter(){out = null;}\r\n\r\n\t\tpublic FastWriter(OutputStream os)\r\n\t\t{\r\n\t\t\tthis.out = os;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter(String path)\r\n\t\t{\r\n\t\t\ttry {\r\n\t\t\t\tthis.out = new FileOutputStream(path);\r\n\t\t\t} catch (FileNotFoundException e) {\r\n\t\t\t\tthrow new RuntimeException(\"FastWriter\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(byte b)\r\n\t\t{\r\n\t\t\tbuf[ptr++] = b;\r\n\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(char c)\r\n\t\t{\r\n\t\t\treturn write((byte)c);\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(char[] s)\r\n\t\t{\r\n\t\t\tfor(char c : s){\r\n\t\t\t\tbuf[ptr++] = (byte)c;\r\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(String s)\r\n\t\t{\r\n\t\t\ts.chars().forEach(c -> {\r\n\t\t\t\tbuf[ptr++] = (byte)c;\r\n\t\t\t\tif(ptr == BUF_SIZE)innerflush();\r\n\t\t\t});\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tprivate static int countDigits(int l) {\r\n\t\t\tif (l >= 1000000000) return 10;\r\n\t\t\tif (l >= 100000000) return 9;\r\n\t\t\tif (l >= 10000000) return 8;\r\n\t\t\tif (l >= 1000000) return 7;\r\n\t\t\tif (l >= 100000) return 6;\r\n\t\t\tif (l >= 10000) return 5;\r\n\t\t\tif (l >= 1000) return 4;\r\n\t\t\tif (l >= 100) return 3;\r\n\t\t\tif (l >= 10) return 2;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(int x)\r\n\t\t{\r\n\t\t\tif(x == Integer.MIN_VALUE){\r\n\t\t\t\treturn write((long)x);\r\n\t\t\t}\r\n\t\t\tif(ptr + 12 >= BUF_SIZE)innerflush();\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite((byte)'-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tint d = countDigits(x);\r\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\r\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\r\n\t\t\t\tx /= 10;\r\n\t\t\t}\r\n\t\t\tptr += d;\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tprivate static int countDigits(long l) {\r\n\t\t\tif (l >= 1000000000000000000L) return 19;\r\n\t\t\tif (l >= 100000000000000000L) return 18;\r\n\t\t\tif (l >= 10000000000000000L) return 17;\r\n\t\t\tif (l >= 1000000000000000L) return 16;\r\n\t\t\tif (l >= 100000000000000L) return 15;\r\n\t\t\tif (l >= 10000000000000L) return 14;\r\n\t\t\tif (l >= 1000000000000L) return 13;\r\n\t\t\tif (l >= 100000000000L) return 12;\r\n\t\t\tif (l >= 10000000000L) return 11;\r\n\t\t\tif (l >= 1000000000L) return 10;\r\n\t\t\tif (l >= 100000000L) return 9;\r\n\t\t\tif (l >= 10000000L) return 8;\r\n\t\t\tif (l >= 1000000L) return 7;\r\n\t\t\tif (l >= 100000L) return 6;\r\n\t\t\tif (l >= 10000L) return 5;\r\n\t\t\tif (l >= 1000L) return 4;\r\n\t\t\tif (l >= 100L) return 3;\r\n\t\t\tif (l >= 10L) return 2;\r\n\t\t\treturn 1;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(long x)\r\n\t\t{\r\n\t\t\tif(x == Long.MIN_VALUE){\r\n\t\t\t\treturn write(\"\" + x);\r\n\t\t\t}\r\n\t\t\tif(ptr + 21 >= BUF_SIZE)innerflush();\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite((byte)'-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tint d = countDigits(x);\r\n\t\t\tfor(int i = ptr + d - 1;i >= ptr;i--){\r\n\t\t\t\tbuf[i] = (byte)('0'+x%10);\r\n\t\t\t\tx /= 10;\r\n\t\t\t}\r\n\t\t\tptr += d;\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(double x, int precision)\r\n\t\t{\r\n\t\t\tif(x < 0){\r\n\t\t\t\twrite('-');\r\n\t\t\t\tx = -x;\r\n\t\t\t}\r\n\t\t\tx += Math.pow(10, -precision)/2;\r\n\t\t\t//\t\tif(x < 0){ x = 0; }\r\n\t\t\twrite((long)x).write(\".\");\r\n\t\t\tx -= (long)x;\r\n\t\t\tfor(int i = 0;i < precision;i++){\r\n\t\t\t\tx *= 10;\r\n\t\t\t\twrite((char)('0'+(int)x));\r\n\t\t\t\tx -= (int)x;\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(char c){\r\n\t\t\treturn write(c).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(int x){\r\n\t\t\treturn write(x).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(long x){\r\n\t\t\treturn write(x).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(double x, int precision){\r\n\t\t\treturn write(x, precision).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(int... xs)\r\n\t\t{\r\n\t\t\tboolean first = true;\r\n\t\t\tfor(int x : xs) {\r\n\t\t\t\tif (!first) write(' ');\r\n\t\t\t\tfirst = false;\r\n\t\t\t\twrite(x);\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter write(long... xs)\r\n\t\t{\r\n\t\t\tboolean first = true;\r\n\t\t\tfor(long x : xs) {\r\n\t\t\t\tif (!first) write(' ');\r\n\t\t\t\tfirst = false;\r\n\t\t\t\twrite(x);\r\n\t\t\t}\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln()\r\n\t\t{\r\n\t\t\treturn write((byte)'\\n');\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(int... xs)\r\n\t\t{\r\n\t\t\treturn write(xs).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(long... xs)\r\n\t\t{\r\n\t\t\treturn write(xs).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(char[] line)\r\n\t\t{\r\n\t\t\treturn write(line).writeln();\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(char[]... map)\r\n\t\t{\r\n\t\t\tfor(char[] line : map)write(line).writeln();\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tpublic FastWriter writeln(String s)\r\n\t\t{\r\n\t\t\treturn write(s).writeln();\r\n\t\t}\r\n\r\n\t\tprivate void innerflush()\r\n\t\t{\r\n\t\t\ttry {\r\n\t\t\t\tout.write(buf, 0, ptr);\r\n\t\t\t\tptr = 0;\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\tthrow new RuntimeException(\"innerflush\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic void flush()\r\n\t\t{\r\n\t\t\tinnerflush();\r\n\t\t\ttry {\r\n\t\t\t\tout.flush();\r\n\t\t\t} catch (IOException e) {\r\n\t\t\t\tthrow new RuntimeException(\"flush\");\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic FastWriter print(byte b) { return write(b); }\r\n\t\tpublic FastWriter print(char c) { return write(c); }\r\n\t\tpublic FastWriter print(char[] s) { return write(s); }\r\n\t\tpublic FastWriter print(String s) { return write(s); }\r\n\t\tpublic FastWriter print(int x) { return write(x); }\r\n\t\tpublic FastWriter print(long x) { return write(x); }\r\n\t\tpublic FastWriter print(double x, int precision) { return write(x, precision); }\r\n\t\tpublic FastWriter println(char c){ return writeln(c); }\r\n\t\tpublic FastWriter println(int x){ return writeln(x); }\r\n\t\tpublic FastWriter println(long x){ return writeln(x); }\r\n\t\tpublic FastWriter println(double x, int precision){ return writeln(x, precision); }\r\n\t\tpublic FastWriter print(int... xs) { return write(xs); }\r\n\t\tpublic FastWriter print(long... xs) { return write(xs); }\r\n\t\tpublic FastWriter println(int... xs) { return writeln(xs); }\r\n\t\tpublic FastWriter println(long... xs) { return writeln(xs); }\r\n\t\tpublic FastWriter println(char[] line) { return writeln(line); }\r\n\t\tpublic FastWriter println(char[]... map) { return writeln(map); }\r\n\t\tpublic FastWriter println(String s) { return writeln(s); }\r\n\t\tpublic FastWriter println() { return writeln(); }\r\n\t}\r\n\r\n\tpublic void trnz(int... o)\r\n\t{\r\n\t\tfor(int i = 0;i < o.length;i++)if(o[i] != 0)System.out.print(i+\":\"+o[i]+\" \");\r\n\t\tSystem.out.println();\r\n\t}\r\n\r\n\t// print ids which are 1\r\n\tpublic void trt(long... o)\r\n\t{\r\n\t\tQueue<Integer> 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", "src_uid": "1f012349f4b229dc98faadf1ca732355"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.io.StreamTokenizer;\n\npublic class CF171G {\n \n private StreamTokenizer in;\n private PrintWriter out;\n \n public static void main (String[] args) throws IOException {\n new CF171G().soilve();\n }\n \n int nextInt () throws IOException {\n in.nextToken();\n return (int)in.nval;\n }\n \n void soilve () throws IOException {\n in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));\n out = new PrintWriter(new OutputStreamWriter(System.out));\n \n int a = nextInt();\n int b = nextInt();\n int c = nextInt();\n \n if (c == 1) {\n out.print(b);\n out.flush();\n return;\n }\n \n int res = 0;\n for (int i = 2; i <= c; i++) {\n res = a + b;\n a = b;\n b = res;\n }\n\n out.print(res);\n out.flush(); \n }\n}\n", "src_uid": "6ff30f5a9afc3f7befca813469188aab"} {"source_code": "/*\n * To change this template, choose Tools | Templates\n * and open the template in the editor.\n */\n\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.Scanner;\n\npublic class C {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n //BufferedReader r = new BufferedReader(new InputStreamReader(System.in));\n Scanner in = new Scanner(System.in); \n int n ,i,j,k,a,a0=0,a1=0;\n String s;\n int[][] f = new int[10][10];\n for (i=0;i<10;i++) for(j=0;j<10;j++) f[i][j] = 1;\n for (i = 0; i < 8; i++) {\n s = in.nextLine();\n for(j=0;j<s.length();j++) {\n switch (s.charAt(j)) {\n case '.' : f[i+1][j+1] = 0; break;\n case 'A' : f[i+1][j+1] = 0; break;\n case 'M' : f[i+1][j+1] = 5; break;\n case 'S' : f[i+1][j+1] = 13; break;\n }\n }\n }\n List<Integer> mm;\n int[] di = new int[]{0,0,1,-1,1,1,-1,-1};\n int[] dj = new int[]{1,-1,0,0,1,-1,1,-1};\n mm = new ArrayList<Integer>(64);\n for (a=0; a<8; a++) {\n mm.clear();\n for (i=0;i<10;i++) for(j=0;j<10;j++) \n if (f[i][j] == 5) mm.add(i*10+j);\n for (Integer m : mm) {\n i = m/10; j = m%10;\n for (k=0;k<8;k++) \n if (f[i+di[k]][j+dj[k]]==0) f[i+di[k]][j+dj[k]]=5;\n }\n \n for (i=0;i<10;i++) for(j=8;j>0;j--) \n if (f[j-1][i]==13) {\n f[j][i] = 13;\n f[j-1][i] = 0;\n } \n }\n if (mm.size()==0) System.out.print(\"LOSE\");\n else System.out.print(\"WIN\");\n \n }\n}\n/*\n.......A\n........\n........\n........\n........\n.S......\nS.......\nM.......\n * \n * \n */", "src_uid": "f47e4ab041288ba9567c19930eb9a090"} {"source_code": "import java.util.*;\npublic class Vasya {\n\n\tpublic static void main(String[] args) {\n\t\t\nScanner sc = new Scanner(System.in);\nint n,m;\n\nn=sc.nextInt();\nm=sc.nextInt();\nint days=0;\nwhile(n!=0) {\n\tn--;\n\tdays++;\n\tif(days%m==0 && days!=0) {\n\t\t\n\t\tn++;\n\t}\n\t\n\t\n\t\n\t\n}\nSystem.out.println(days);\n\n\t}\n\n}\n", "src_uid": "42b25b7335ec01794fbb1d4086aa9dd0"} {"source_code": "import java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.math.BigInteger;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.util.StringTokenizer;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author shu_mj @ http://shu-mj.com\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tScanner in = new Scanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskC solver = new TaskC();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskC {\n Scanner in;\n PrintWriter out;\n\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n this.in = in;\n this.out = out;\n run();\n }\n\n void run() {\n long c = in.nextInt();\n long hr = in.nextInt();\n long hb = in.nextInt();\n long wr = in.nextInt();\n long wb = in.nextInt();\n out.println(Math.max(go(c, hr, hb, wr, wb), go(c, hb, hr, wb, wr)));\n }\n\n private long go(long c, long hr, long hb, long wr, long wb) {\n long top = c / wr;\n long res = 0;\n for (int i = 0; i < 1000000; i++) {\n long y = top - i;\n long x = (c - y * wr) / wb;\n if (x >= 0 && y >= 0) res = Math.max(res, x * hb + y * hr);\n }\n return res;\n }\n}\n\nclass Scanner {\n BufferedReader br;\n StringTokenizer st;\n\n public Scanner(InputStream in) {\n br = new BufferedReader(new InputStreamReader(in));\n eat(\"\");\n }\n\n private void eat(String s) {\n st = new StringTokenizer(s);\n }\n\n public String nextLine() {\n try {\n return br.readLine();\n } catch (IOException e) {\n return null;\n }\n }\n\n public boolean hasNext() {\n while (!st.hasMoreTokens()) {\n String s = nextLine();\n if (s == null)\n return false;\n eat(s);\n }\n return true;\n }\n\n public String next() {\n hasNext();\n return st.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n}\n\n", "src_uid": "eb052ca12ca293479992680581452399"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main{\n \t\n\n\t\n\t static String s1, s2, virus;\n\t static int[][][] dp = new int[200][200][200];\n\t static int[][] ch = new int[200][30];\n\t static int[] fail = new int[200];\n\t static int n, x, y;\n\t static boolean[][][] vis = new boolean[200][200][200];\n\n\t static void init() {\n\t fail[0] = fail[1] = 0;\n\t for (int i = 1; i < n; i++) {\n\t int j = fail[i];\n\t while (j != 0 && virus.charAt(i) != virus.charAt(j)) j = fail[j];\n\t fail[i + 1] = (virus.charAt(i) == virus.charAt(j)) ? j + 1 : 0;\n\t }\n\n\t for (int i = 0; i < n; i++) ch[i][virus.charAt(i) - 'A'] = i + 1;\n\t for (int i = 0; i < n; i++) {\n\t for (int c = 0; c < 26; c++) {\n\t if (ch[i][c] == 0)\n\t ch[i][c] = ch[fail[i]][c];\n\t }\n\t }\n\t }\n\n\t static int dfs(int i, int j, int k) {\n\t if (vis[i][j][k] == true)\n\t return dp[i][j][k];\n\t vis[i][j][k] = true;\n\t if (k >= n)\n\t return dp[i][j][k] = -999999999;\n\t if (i >= x || j >= y)\n\t return dp[i][j][k] = 0;\n\n\t dp[i][j][k] = Math.max(dfs(i + 1, j, k), dfs(i, j + 1, k));\n\n\t if (s1.charAt(i) == s2.charAt(j)) {\n\t dp[i][j][k] = Math.max(dp[i][j][k], dfs(i + 1, j + 1, ch[k][s1.charAt(i) - 'A']) + 1);\n\t }\n\n\t return dp[i][j][k];\n\t }\n\n\t public static void main(String[] args) {\n\t Scanner in = new Scanner(System.in);\n\n\t s1 = in.next().trim();\n\t s2 = in.next().trim();\n\t virus = in.next().trim();\n\n\t x = s1.length();\n\t y = s2.length();\n\t n = virus.length();\n\t init();\n\n\t if (dfs(0, 0, 0) != 0) {\n\t int i = 0, j = 0, k = 0;\n\t String ans = \"\";\n\t while (i < x && j < y) {\n\t if (dfs(i, j, k) == dfs(i + 1, j, k))\n\t i++;\n\t else if (dfs(i, j, k) == dfs(i, j + 1, k))\n\t j++;\n\t else {\n\n\t ans += s1.charAt(i);\n\t k = ch[k][s1.charAt(i) - 'A'];\n\t i++;\n\t j++;\n\t }\n\t }\n\t System.out.println(ans);\n\t } else {\n\t System.out.println(\"0\");\n\t }\n\t }\n\t}\n\n", "src_uid": "391c2abbe862139733fcb997ba1629b8"} {"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.HashSet;\nimport java.util.Set;\nimport java.util.StringTokenizer;\n\n\npublic class BB {\n \n static StringTokenizer st;\n static BufferedReader in;\n public static void main(String[] args) throws IOException {\n in = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n int n = nextInt();\n int inc = 0;\n if (n==1e9)\n inc = 1;\n Set<Integer> set = new HashSet<Integer>();\n for (int leng = 1; leng <= 9; leng++) {\n for (int i = 0; i <= 9; i++) {\n for (int j = i+1; j <= 9; j++) {\n for (int j2 = 0; j2 < (1 << leng); j2++) {\n int t = 0;\n for (int k = leng-1; k >= 0; k--) {\n t = t*10;\n if ((j2 & (1 << k)) != 0) \n t += i;\n else \n t += j;\n }\n if (t <= n && t != 0)\n set.add(t);\n }\n }\n }\n }\n System.out.println(set.size()+inc);\n pw.close();\n }\n private static int nextInt() throws IOException{\n return Integer.parseInt(next());\n }\n \n private static long nextLong() throws IOException{\n return Long.parseLong(next());\n }\n \n private static double nextDouble() throws IOException{\n return Double.parseDouble(next());\n }\n \n private static String next() throws IOException {\n while (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(in.readLine());\n }\n return st.nextToken();\n }\n}\n", "src_uid": "0f7f10557602c8c2f2eb80762709ffc4"} {"source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.StringTokenizer;\nimport java.io.BufferedReader;\nimport java.util.Comparator;\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 InputReader in = new InputReader(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n Graph solver = new Graph();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class Graph {\n ArrayList<Edge>[] edges;\n ArrayList<Integer> component = new ArrayList<>();\n int need;\n Function[] functions;\n\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int N = in.nextInt();\n int M = in.nextInt();\n functions = new Function[N];\n edges = new ArrayList[N];\n for (int i = 0; i < N; i++) {\n edges[i] = new ArrayList<>();\n }\n for (int i = 0; i < M; i++) {\n int a = in.nextInt() - 1;\n int b = in.nextInt() - 1;\n int c = in.nextInt() * 2;\n edges[a].add(new Edge(b, c));\n edges[b].add(new Edge(a, c));\n }\n ArrayList<Integer> necessary = new ArrayList<>();\n int[] ans = new int[N];\n for (int i = 0; i < N; i++) {\n if (functions[i] == null) {\n component.clear();\n need = Integer.MAX_VALUE;\n functions[i] = new Function(1, 0);\n dfs(i);\n int x;\n if (need == Integer.MIN_VALUE) {\n out.println(\"NO\");\n return;\n } else if (need == Integer.MAX_VALUE) {\n Collections.sort(component, new Comparator<Integer>() {\n\n public int compare(Integer integer, Integer t1) {\n return Integer.compare(functions[integer].x * functions[integer].c, functions[t1].x * functions[t1].c);\n }\n });\n x = -functions[component.get(component.size() / 2)].x * functions[component.get(component.size() / 2)].c;\n } else {\n x = need;\n }\n for (int j : component) {\n ans[j] = functions[j].x * x + functions[j].c;\n }\n }\n }\n out.println(\"YES\");\n for (int i : ans) {\n out.println((double) (i) / 2);\n }\n }\n\n void dfs(int n) {\n component.add(n);\n for (Edge e : edges[n]) {\n if (functions[e.to] == null) {\n functions[e.to] = functions[n].subtract(e.c);\n dfs(e.to);\n } else {\n int res = functions[n].is(functions[e.to], e.c);\n if (res == Integer.MIN_VALUE) {\n need = Integer.MIN_VALUE;\n } else if (res != Integer.MAX_VALUE) {\n if (need != Integer.MAX_VALUE && need != res) {\n need = Integer.MIN_VALUE;\n } else {\n need = res;\n }\n }\n }\n }\n }\n\n class Function {\n int x;\n int c;\n\n Function(int x, int c) {\n this.x = x;\n this.c = c;\n }\n\n Function subtract(int c) {\n return new Function(-x, c - this.c);\n }\n\n int is(Function f, int c) {\n if (f.x == this.x) {\n return (c - f.c - this.c) / (2 * f.x);\n }\n if (f.x != this.x && (this.c + f.c) != c) {\n return Integer.MIN_VALUE;\n }\n return Integer.MAX_VALUE;\n }\n\n }\n\n class Edge {\n int to;\n int c;\n\n Edge(int to, int c) {\n this.to = to;\n this.c = c;\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", "src_uid": "791cbe2700b11e9dd9a442de3ef913f8"} {"source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Main {\n\n /**\n * @param args\n */\n public static BigInteger W,K,M;\n public static BigInteger calc(BigInteger x){\n BigInteger tmp = BigInteger.valueOf(0);\n BigInteger ans = BigInteger.valueOf(0);\n BigInteger tmq = BigInteger.valueOf(1);\n BigInteger t;\n while (tmp.compareTo(x) < 0){\n t = tmp.multiply(BigInteger.valueOf(10));\n t = t.add(BigInteger.valueOf(9));\n if (t.compareTo(x) <= 0){\n ans = ans.add(t.subtract(tmp).multiply(K).multiply(tmq));\n }\n else{\n ans = ans.add(x.subtract(tmp).multiply(K).multiply(tmq));\n }\n tmq = tmq.add(BigInteger.valueOf(1));\n tmp = t;\n //System.out.print(tmq+\" \"+ans+\"\\n\");\n }\n return ans;\n }\n public static void main(String[] args) {\n // TODO Auto-generated method stub\n Scanner cin = new Scanner(new BufferedInputStream(System.in));\n W = cin.nextBigInteger();\n M = cin.nextBigInteger();\n K = cin.nextBigInteger();\n BigInteger x = BigInteger.valueOf(10);\n //System.out.print(calc(x)+\"\\n\");\n W = W.add(calc(M.subtract(BigInteger.valueOf(1))));\n BigInteger l = BigInteger.valueOf(0);\n BigInteger r = BigInteger.valueOf(1);\n while (W.compareTo(calc(r)) > 0)\n r = r.multiply(BigInteger.valueOf(10));\n while (l.compareTo(r) != 0){\n BigInteger mid = l.add(r);\n mid = mid.divide(BigInteger.valueOf(2));\n mid = mid.add(BigInteger.valueOf(1));\n if (W.compareTo(calc(mid)) >= 0)\n l = mid;\n else\n r = mid.subtract(BigInteger.valueOf(1));\n }\n System.out.print(l.subtract(M).add(BigInteger.valueOf(1)));\n }\n\n}\n", "src_uid": "8ef8a09e33d38a2d7f023316bc38b6ea"} {"source_code": "\n//package goodbye2015;\n\n\nimport java.io.BufferedOutputStream;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\npublic class B {\n\n public static void main(String[] args) {\n IO io = new IO();\n try {\n io.println(codeForce(io));\n } finally {\n //System.out.println(\"CLOSING FINALLY\");\n io.close();\n }\n }\n\n public static long codeForce(IO io) {\n long a = io.nextLong();\n long b = io.nextLong();\n String bin = Long.toBinaryString(a);\n String goal = Long.toBinaryString(b);\n int indexForInitialZero = 0; // placeholder value\n \n //System.out.println(\"BIN: \" + bin);\n //System.out.println(\"GOAL: \" + goal);\n \n // We want to start with a binary string that has a single 0\n // If we have too much, fill out extra 0's with 1's\n // Going right->left to increase value as little as possible\n int zerosInBin = countZeros(bin);\n for (int i=bin.length()-1; zerosInBin>1; i--) {\n if (bin.charAt(i) == '0') {\n zerosInBin--;\n StringBuilder newBin = new StringBuilder();\n if (i>0) newBin.append(bin.substring(0,i));\n newBin.append('1');\n if (i<bin.length()-1) newBin.append(bin.substring(i+1, bin.length()));\n bin = newBin.toString();\n }\n }\n \n // If we have no zeros in starting binary string, turn 111 -> 1011\n if (zerosInBin == 0) {\n String possibleAddition = \"\";\n if (bin.length() > 1) possibleAddition = bin.substring(1,bin.length());\n if (goal.length() < bin.length()+1) return 0;\n if (goal.length() == bin.length()+1 && !stringIsBelowOrAtGoal(1, goal)) {\n Long parsed = Long.parseLong(\"10\" + possibleAddition, 2);\n if (parsed > b) {\n //System.out.println(\"parsed: \" + parsed);\n return 0;\n }\n else {\n long count = 0;\n if (goal.contains(\"0\")) count++;\n if (b != parsed) count++;\n return count;\n }\n }\n bin = \"10\" + possibleAddition;\n } \n // Find initial zero\n int i=0;\n for ( ;i<bin.length(); i++) {\n if (bin.charAt(i) == '0') break;\n }\n indexForInitialZero = i;\n \n // First round may start from middle so do it separately\n long count = 0;\n for (i=indexForInitialZero; i<bin.length(); i++) {\n Long parsed = Long.parseLong(bin, 2);\n if (parsed <= b) count++;\n if (parsed >= b) return count;\n \n int len = bin.length();\n bin = \"\";\n \n for (int j=0; j<=i; j++) {\n bin += '1';\n }\n if (bin.length() < len) {\n bin += '0';\n }\n for (int j=i+2; j<len; j++) {\n bin += '1';\n }\n }\n \n // All other rounds. specRep represents binary strings\n // from 11110 -> 10111\n int specRep = bin.length()+1;\n boolean doneSomethingHere = false;\n while (specRep <= goal.length() + 1) {\n if (specRep == goal.length()+1) {\n // We possibly counted too many\n // Subtract the ones that went over\n if (!doneSomethingHere) return count;\n while (specRep > goal.length()) specRep--;\n for (i=specRep-1; i>=1; i--) {\n if (stringIsBelowOrAtGoal(i, goal)) break;\n count--;\n }\n return count;\n }\n doneSomethingHere = true;\n count += (specRep-1); // bc cant replace first '1' with '0'\n specRep++;\n }\n\n return count;\n }\n \n public static boolean stringIsBelowOrAtGoal(int a, String b) {\n // a represents a string that has same length as b\n // with all characters '1' except for a single '0' in index a\n for (int i=1; i<a; i++) {\n if (b.charAt(i) == '0') return false;\n }\n if (b.charAt(a) == '1') return true;\n for (int i=a+1; i<b.length(); i++) {\n if (b.charAt(i) == '0') return false;\n }\n return true;\n }\n \n public static int countZeros(String a) {\n int count = 0;\n for (int i=0; i<a.length(); i++) {\n if (a.charAt(i) == '0') count++;\n }\n return count;\n }\n\n\n static class IO extends PrintWriter {\n\tprivate InputStreamReader r;\n\tprivate static final int BUFSIZE = 1 << 15;\n\tprivate char[] buf;\n\tprivate int bufc;\n\tprivate int bufi;\n\tprivate StringBuilder sb;\n\t\n\tpublic IO() {\n\t\tsuper(new BufferedOutputStream(System.out));\n\t\tr = new InputStreamReader(System.in);\n\t\t\n\t\tbuf = new char[BUFSIZE];\n\t\tbufc = 0;\n\t\tbufi = 0;\n\t\tsb = new StringBuilder();\n\t}\n\t\n\tprivate void fillBuf() throws IOException {\n\t\tbufi = 0;\n\t\tbufc = 0;\n\t\twhile(bufc == 0) {\n\t\t\tbufc = r.read(buf, 0, BUFSIZE);\n\t\t\tif(bufc == -1) {\n\t\t\t\tbufc = 0;\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\t\n\tprivate boolean pumpBuf() throws IOException {\n\t\tif(bufi == bufc) {\n\t\t\tfillBuf();\n\t\t}\n\t\treturn bufc != 0;\n\t}\n\t\n\tprivate boolean isDelimiter(char c) {\n\t\treturn c == ' ' || c == '\\t' || c == '\\n' || c == '\\r' || c == '\\f';\n\t}\n\t\n\tprivate void eatDelimiters() throws IOException {\n\t\twhile(true) {\n\t\t\tif(bufi == bufc) {\n\t\t\t\tfillBuf();\n\t\t\t\tif(bufc == 0) throw new RuntimeException(\"IO: Out of input.\");\n\t\t\t}\n\t\t\t\n\t\t\tif(!isDelimiter(buf[bufi])) break;\n\t\t\t++bufi;\n\t\t}\n\t}\n\t\n\tpublic String next() {\n\t\ttry {\n\t\t\tsb.setLength(0);\n\t\t\t\n\t\t\teatDelimiters();\n\t\t\tint start = bufi;\n\t\t\t\n\t\t\twhile(true) {\n\t\t\t\tif(bufi == bufc) {\n\t\t\t\t\tsb.append(buf, start, bufi - start);\n\t\t\t\t\tfillBuf();\n\t\t\t\t\tstart = 0;\n\t\t\t\t\tif(bufc == 0) break;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif(isDelimiter(buf[bufi])) break;\n\t\t\t\t++bufi;\n\t\t\t}\n\t\t\t\n\t\t\tsb.append(buf, start, bufi - start);\n\t\t\t\n\t\t\treturn sb.toString();\n\t\t} catch(IOException e) {\n\t\t\tthrow new RuntimeException(\"IO.next: Caught IOException.\");\n\t\t}\n\t}\n\t\n\tpublic int nextInt() {\n\t\ttry {\n\t\t\tint ret = 0;\n\t\t\t\n\t\t\teatDelimiters();\n\t\t\t\n\t\t\tboolean positive = true;\n\t\t\tif(buf[bufi] == '-') {\n\t\t\t\t++bufi;\n\t\t\t\tif(!pumpBuf()) throw new RuntimeException(\"IO.nextInt: Invalid int.\");\n\t\t\t\tpositive = false;\n\t\t\t}\n\t\t\t\n\t\t\tboolean first = true;\n\t\t\twhile(true) {\n\t\t\t\tif(!pumpBuf()) break;\n\t\t\t\tif(isDelimiter(buf[bufi])) {\n\t\t\t\t\tif(first) throw new RuntimeException(\"IO.nextInt: Invalid int.\");\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tfirst = false;\n\t\t\t\t\n\t\t\t\tif(buf[bufi] >= '0' && buf[bufi] <= '9') {\n\t\t\t\t\tif(ret < -214748364) throw new RuntimeException(\"IO.nextInt: Invalid int.\");\n\t\t\t\t\tret *= 10;\n\t\t\t\t\tret -= (int)(buf[bufi] - '0');\n\t\t\t\t\tif(ret > 0) throw new RuntimeException(\"IO.nextInt: Invalid int.\");\n\t\t\t\t} else {\n\t\t\t\t\tthrow new RuntimeException(\"IO.nextInt: Invalid int.\");\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t++bufi;\n\t\t\t}\n\t\t\t\n\t\t\tif(positive) {\n\t\t\t\tif(ret == -2147483648) throw new RuntimeException(\"IO.nextInt: Invalid int.\");\n\t\t\t\tret = -ret;\n\t\t\t}\n\t\t\t\n\t\t\treturn ret;\n\t\t} catch(IOException e) {\n\t\t\tthrow new RuntimeException(\"IO.nextInt: Caught IOException.\");\n\t\t}\n\t}\n\t\n\tpublic long nextLong() {\n\t\ttry {\n\t\t\tlong ret = 0;\n\t\t\t\n\t\t\teatDelimiters();\n\t\t\t\n\t\t\tboolean positive = true;\n\t\t\tif(buf[bufi] == '-') {\n\t\t\t\t++bufi;\n\t\t\t\tif(!pumpBuf()) throw new RuntimeException(\"IO.nextLong: Invalid long.\");\n\t\t\t\tpositive = false;\n\t\t\t}\n\t\t\t\n\t\t\tboolean first = true;\n\t\t\twhile(true) {\n\t\t\t\tif(!pumpBuf()) break;\n\t\t\t\tif(isDelimiter(buf[bufi])) {\n\t\t\t\t\tif(first) throw new RuntimeException(\"IO.nextLong: Invalid long.\");\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tfirst = false;\n\t\t\t\t\n\t\t\t\tif(buf[bufi] >= '0' && buf[bufi] <= '9') {\n\t\t\t\t\tif(ret < -922337203685477580L) throw new RuntimeException(\"IO.nextLong: Invalid long.\");\n\t\t\t\t\tret *= 10;\n\t\t\t\t\tret -= (long)(buf[bufi] - '0');\n\t\t\t\t\tif(ret > 0) throw new RuntimeException(\"IO.nextLong: Invalid long.\");\n\t\t\t\t} else {\n\t\t\t\t\tthrow new RuntimeException(\"IO.nextLong: Invalid long.\");\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t++bufi;\n\t\t\t}\n\t\t\t\n\t\t\tif(positive) {\n\t\t\t\tif(ret == -9223372036854775808L) throw new RuntimeException(\"IO.nextLong: Invalid long.\");\n\t\t\t\tret = -ret;\n\t\t\t}\n\t\t\t\n\t\t\treturn ret;\n\t\t} catch(IOException e) {\n\t\t\tthrow new RuntimeException(\"IO.nextLong: Caught IOException.\");\n\t\t}\n\t}\n\t\n\tpublic double nextDouble() {\n\t\treturn Double.parseDouble(next());\n\t}\n\n }\n}", "src_uid": "581f61b1f50313bf4c75833cefd4d022"} {"source_code": "import java.util.Scanner;\n\npublic class Triangle {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint a = sc.nextInt();\n\t\tint b = sc.nextInt();\n\t\tint c = sc.nextInt();\n\t\tint d = sc.nextInt();\n\n\t\tif (a + b > c && a + c > b && b + c > a || a + b > d && a + d > b\n\t\t\t\t&& b + d > a || b + c > d && b + d > c && c + d > b\n\t\t\t\t|| a + c > d && a + d > c && c + d > a)\n\t\t\tSystem.out.println(\"TRIANGLE\");\n\t\telse if (a + b == c || a + b == d || a + c == b || a + c == d\n\t\t\t\t|| a + d == b || a + d == c || c + b == a || c + b == d\n\t\t\t\t|| d + b == a || d + b == c || c + d == a || c + d == b)\n\t\t\tSystem.out.println(\"SEGMENT\");\n\t\telse\n\t\t\tSystem.out.println(\"IMPOSSIBLE\");\n\t}\n}\n", "src_uid": "8f5df9a41e6e100aa65b9fc1d26e447a"} {"source_code": "import java.util.*;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.*;\nimport java.util.*;\n\npublic class Main {\n\t//////\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\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\t//////\n\n\tpublic static void main(String[] args) throws IOException {\n\n\t\tFastReader scan = new FastReader();\n\t\n\t\tint A=scan.nextInt();\n\t\t\n\t\tif(A==1){\n\t\t\tSystem.out.println(\"1 1\");\n\t\t\tSystem.out.println(\"1\");\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tSystem.out.println(2*(A-1)+\" 2\");\n\t\tSystem.out.println(\"1 2\");\n\t\t\n\t\t\n\t}\n\t\t\t\n}", "src_uid": "5c000b4c82a8ecef764f53fda8cee541"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Solution {\n\tpublic static void main(String[] args) throws IOException {\n\t\tScanner sc = new Scanner(System.in);\n\t\tPrintWriter pr = new PrintWriter(System.out);\n\t\tlong n = sc.nextLong();\n\t\tlong max = Long.MIN_VALUE;\n\t\tlong min = Long.MAX_VALUE;\n\t\tfor (int i = 1; i <= Math.sqrt(n); i++) {\n\t\t\tlong k = n;\n\t\t\tif (k % i == 0) {\n\t\t\t\tk /= i;\n\t\t\t\tfor (int j = 1; j <= Math.sqrt(n); j++) {\n\t\t\t\t\tlong m = k;\n\t\t\t\t\t\tif (m % j == 0) {\n\t\t\t\t\t\t\tm /= j;\n\t\t\t\t\t\t\tmin = Math.min((i + 1) * (j + 2) * (m + 2) - n, min);\n\t\t\t\t\t\t\tmin = Math.min((i + 2) * (j + 1) * (m + 2) - n, min);\n\t\t\t\t\t\t\tmin = Math.min((i + 2) * (j + 2) * (m + 1) - n, min);\n\t\t\t\t\t\t\tmax = Math.max((i + 1) * (j + 2) * (m + 2) - n, max);\n\t\t\t\t\t\t\tmax = Math.max((i + 2) * (j + 1) * (m + 2) - n, max);\n\t\t\t\t\t\t\tmax = Math.max((i + 2) * (j + 2) * (m + 1) - n, max);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tpr.print(min + \" \" + max);\n\t\tpr.close();\n\t}\n}", "src_uid": "2468eead8acc5b8f5ddc51bfa2bd4fb7"} {"source_code": "//package sol2;\nimport java.io.*;\nimport java.lang.reflect.Array;\nimport java.math.BigDecimal;\nimport java.math.BigInteger;\nimport java.math.RoundingMode;\nimport java.time.LocalDateTime;\nimport java.time.format.DateTimeFormatter;\nimport java.util.*;\n\npublic class Solution1 {\n\n static long MOD = (long)1e9 + 7;\n static long T, x;\n\n static int ret=0;\n static int a, b;\n public static void main(String[] args) throws IOException {\n FastInput fi = new FastInput(System.in);\n PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\n int x=fi.nextInt(), y = fi.nextInt(), z = fi.nextInt(), a = fi.nextInt(), b = fi.nextInt(), c = fi.nextInt();\n if(x>a) {\n System.out.println(\"NO\");\n return;\n }\n a-=x;\n if(y>a+b) {\n System.out.println(\"NO\");\n return;\n }\n if(a>=y) {\n a-=y;\n y=0;\n } else {\n y-=a;\n a=0;\n b-=y;\n }\n\n if(z>a+b+c) {\n System.out.println(\"NO\");\n return;\n } else {\n System.out.println(\"YES\");\n }\n }\n\n static long calc(long[] arr, long from, long to, int st, int fin) {\n if(st == fin || from==to) {\n return (fin-st+1)*b*(to-from+1);\n }\n int piv = -1;\n long toNext = (from + to)/2 + 1;\n for(int i=st; i<=fin; i++) {\n if(arr[i]>=toNext) {\n piv=i;\n break;\n }\n }\n long ret = (fin-st+1)*b*(to-from+1);\n if(piv == -1) {\n ret = Math.min(ret, a + calc(arr, from, toNext-1, st, fin));\n } else if(piv == st) {\n ret = Math.min(ret, a + calc(arr, toNext, fin, st, fin));\n } else {\n ret = Math.min(ret, calc(arr, from, toNext-1, st, piv-1) + calc(arr, toNext, to, piv, fin));\n }\n return ret;\n }\n\n\n static class Pair<K extends Comparable, V extends Comparable> implements Comparable {\n K key;\n V value;\n\n @Override\n public boolean equals(Object o) {\n if (this == o) {\n return true;\n }\n if (!(o instanceof Pair)) {\n return false;\n }\n Pair<?, ?> pair = (Pair<?, ?>) o;\n return Objects.equals(key, pair.key) &&\n Objects.equals(value, pair.value);\n }\n\n @Override\n public int hashCode() {\n return Objects.hash(key, value);\n }\n\n public Pair(K key, V value) {\n this.key = key;\n this.value = value;\n }\n\n @Override\n public int compareTo(Object o) {\n Pair<K, V> p = (Pair)o;\n if(p.key.compareTo(this.key) > 0)\n return 1;\n else if(p.key.compareTo(this.key) < 0)\n return -1;\n else {\n if(p.value.compareTo(this.value) > 0)\n return 1;\n else if(p.value.compareTo(this.value) < 0)\n return -1;\n else return 0;\n }\n }\n }\n\n\n private static class FastInput {\n\n BufferedReader reader;\n StringTokenizer st;\n\n public FastInput(InputStream inputStream) {\n reader = new BufferedReader(new InputStreamReader(inputStream), 32768);\n }\n\n String nextString() {\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(nextString());\n }\n\n long nextLong() {\n return Long.parseLong(nextString());\n }\n }\n}\n", "src_uid": "d54201591f7284da5e9ce18984439f4e"} {"source_code": "import java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class Main {\n\tpublic static long mod= (long) (1e9 +7);\n\tpublic static void main(String args[])\n\t{\n\t\tInputReader s= new InputReader(System.in);\n\t\tOutputStream outputStream= System.out;\n\t\tPrintWriter out= new PrintWriter(outputStream);\n\t\tint n= s.nextInt();\n\t\tString str= s.next();\n\t\tHashMap<Character,Integer> hmap= new HashMap<>();\n\t\thmap.put('B', 0);\n\t\thmap.put('G', 0);\n\t\thmap.put('R', 0);\n\t\tfor(int i=0;i<n;i++){\n\t\t\thmap.put(str.charAt(i), hmap.get(str.charAt(i))+1);\n\t\t}\n\t\tint cnt=0;\n\t\tfor(Character k : hmap.keySet()){\n\t\t\tif(hmap.get(k)>=2)\n\t\t\t\tcnt++;\n\t\t}\n\t\tif(cnt>=2){\n\t\t\tout.println(\"BGR\");\n\t\t}\n\t\telse if(cnt>=1){\n\t\t\tint sum=0;\n\t\t\tfor(Character k : hmap.keySet()){\n\t\t\t\tif(hmap.get(k)==0){\n\t\t\t\t\tsum++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(sum==2){\n\t\t\t\tfor(Character k : hmap.keySet()){\n\t\t\t\t\tif(hmap.get(k)>=2){\n\t\t\t\t\t\tSystem.out.println(k);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tArrayList<Character> arr= new ArrayList<>();\n\t\t\tif(sum==1){\n\t\t\t\tfor(Character k : hmap.keySet()){\n\t\t\t\t\tif(hmap.get(k)<2){\n\t\t\t\t\t\tarr.add(k);\n\t\t\t\t\t\t//System.out.print(k);\n\t\t\t\t\t\t//out.println(\"fsdfs\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tCollections.sort(arr);\n\t\t\t\tfor(int i=0;i<arr.size();i++)\n\t\t\t\t\tout.print(arr.get(i));\n\t\t\t}\n\t\t\tif(sum==0)\n\t\t\t\tout.println(\"BGR\");\n\t\t}\n\t\telse{\n\t\t//s\tout.println(\"fewfs\");\n\t\t\tint count=0;\n\t\t\tfor(Character k : hmap.keySet()){\n\t\t\t\tif(hmap.get(k)==1){\n\t\t\t\t\tcount++;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tArrayList<Character> arr= new ArrayList<>();\n\t\t\tif(count==3)\n\t\t\t\tout.print(\"BGR\");\n\t\t\telse if(count==2){\n\t\t\t\tfor(Character k : hmap.keySet()){\n\t\t\t\t\tif(hmap.get(k)==0){\n\t\t\t\t\t\tarr.add(k);\n\t\t\t\t\t\t//out.print(k);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tCollections.sort(arr);\n\t\t\t\tfor(int i=0;i<arr.size();i++)\n\t\t\t\t\tout.print(arr.get(i));\n\t\t\t}\n\t\t\telse{\n\t\t\t\tfor(Character k : hmap.keySet()){\n\t\t\t\t\tif(hmap.get(k)==1){\n\t\t\t\t\t\tarr.add(k);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tCollections.sort(arr);\n\t\t\t\tfor(int i=0;i<arr.size();i++)\n\t\t\t\t\tout.print(arr.get(i));\n\t\t\t}\n\t\t}\n\t\tout.close();\n\t}\n\t\n\tstatic long combinations(long n,long r){ // O(r)\n\t\tif(r==0 || r==n) return 1;\n\t\tr= Math.min(r, n-r);\n\t\tlong ans=n; // nC1=n;\n\t\tfor(int i=1;i<r;i++){\n\t\t\tans= ans*(n-i);\n\t\t\tans= ans/(i+1);\n\t\t}\n\t\treturn ans;\n\t\t\n\t}\n\tpublic static void debug(Object... o) {\n\t\tSystem.out.println(Arrays.deepToString(o));\n\t}\n\tstatic long modulo(long a,long b,long c) {\n\t\tlong x=1;\n\t\tlong y=a;\n\t\twhile(b > 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\tstatic void catalan_numbers(int n) {\n\t\tlong catalan[]= new long[n+1];\n\t catalan[1] = 1;\n\t for (int i = 2; i <= n; i++) {\n\t for (int j = 1; j <= i - 1; j++) {\n\t catalan[i] = catalan[i] + ((catalan[j]) * catalan[i - j]);\n\t }\n\t }\n\t}\n\t\n\tstatic ArrayList<Integer> primeFactors(int n) // O(sqrt(n))\n\t{\n\t // Print the number of 2s that divide n\n\t\tArrayList<Integer> arr= new ArrayList<>();\n\t while (n%2 == 0)\n\t {\n\t arr.add(2);\n\t n = n/2;\n\t }\n\t \n\t // n must be odd at this point. So we can skip one element (Note i = i +2)\n\t for (int i = 3; i <= Math.sqrt(n); i = i+2)\n\t {\n\t // While i divides n, print i and divide n\n\t while (n%i == 0)\n\t {\n\t arr.add(i);\n\t n = n/i;\n\t }\n\t }\n\t // This condition is to handle the case when n is a prime number\n\t // greater than 2\n\t if (n > 2)\n\t arr.add(n);\n\t \n\t return arr;\n\t}\n\n\tpublic static int expo(int a, int b){\n\t\tif (b==0)\n\t return 1;\n\t if (b==1)\n\t return a;\n\t if (b==2)\n\t return a*a;\n\n\t if (b%2==0){\n\t return expo(expo(a,b/2),2);\n\t }\n\t else{\n\t return a*expo(expo(a,(b-1)/2),2);\n\t }\n\t}\n\tstatic class Pair implements Comparable<Pair>\n\t{\n\t\tlong f;\n\t\tString s;\n\t\tPair(long ii, String cc)\n\t\t{\n\t\t\tf=ii;\n\t\t\ts=cc;\n\t\t}\n\t\t\n\t\tpublic int compareTo(Pair o) \n\t\t{\n\t\t\treturn Long.compare(this.f, o.f);\n\t\t}\n\t\t\n\t}\n\t\n\tpublic static int[] sieve(int N){ // O(n*log(logn))\n\t\tint arr[]= new int[N+1];\n\t\tfor(int i=2;i<=Math.sqrt(N);i++){\n\t\t\tif(arr[i]==0){\n\t\t\t\tfor(int j= i*i;j<= N;j= j+i){\n\t\t\t\t\tarr[j]=1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t\t// All the i for which arr[i]==0 are prime numbers.\n\t}\n\tstatic long gcd(long a,long b){ // O(logn)\n\t\tif(b==0) return a;\n\t\treturn gcd(b,a%b);\n\t}\n\tstatic class InputReader {\n\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}", "src_uid": "4cedd3b70d793bc8ed4a93fc5a827f8f"} {"source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tInputReader in = new InputReader(inputStream);\n\t\tOutputWriter out = new OutputWriter(outputStream);\n\t\tTask solver = new Task();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass Task {\n\t\n\tMap<Long, Integer> map=new EHashMap<>(); \n\tMap<Long, List<Long>> divides=new EHashMap<>();\n\tlong[][] dp;\n\tint idx=0;\n\tList<Long> list=new ArrayList<>();\n\t\n\tpublic void solve(int testNumber, InputReader in, OutputWriter out) {\n\t\tlong A=in.readLong();\n\t\tfor (long i=1; i*i<=A; i++) if (A%i==0) {\n\t\t\tprocess(i);\n\t\t\tif (i*i!=A) process(A/i);\n\t\t}\n\t\tdp=new long[2][map.size()];\n//\t\tfor (long i: map.keySet()) System.out.println(i+\" \"+map.get(i));\n\t\tdp[0][map.get(1L)]=1;\n\t\tint idx=0;\n\t\tfor (long i: divides.keySet()) {\n\t\t\tidx^=1;\n//\t\t\tif (idx>1) dp[idx-2].clear();\n\t\t\tfor (long j: map.keySet()) {\n\t\t\t\tint j2=map.get(j);\n\t\t\t\tdp[idx][j2]=dp[idx^1][j2];\n\t\t\t\tfor (long x: divides.get(i)) \n\t\t\t\t\tif (j%x==0) {\n//\t\t\t\t\t\tSystem.out.println(idx);\n//\t\t\t\t\t\tSystem.out.println(dp[idx]);\n//\t\t\t\t\t\tSystem.out.println(dp[idx-1]);\n\t\t\t\t\t\tdp[idx][j2]+=dp[idx^1][map.get(j/x)];\n\t\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.printLine(dp[idx][map.get(A)]);\n\t}\n\t\n\tlong prime(long n) {\n\t\tif (n<=1) return -1;\n\t\tfor (long i=2; i*i<=n; i++) if (n%i==0) {\n\t\t\twhile (n%i==0) n/=i;\n\t\t\treturn n==1?i:-1;\n\t\t}\n\t\treturn n;\n\t}\n\t\n\tvoid process(long x) {\n\t\tmap.put(x, idx++);\n\t\tlong p=prime(x-1);\n\t\tif (p>0) {\n\t\t\tif (!divides.containsKey(p)) divides.put(p, new ArrayList<Long>());\n\t\t\tdivides.get(p).add(x);\n\t\t}\n\t}\n}\n\nclass InputReader {\n\tprivate boolean finished = false;\n\n\tprivate InputStream stream;\n\tprivate byte[] buf = new byte[1024];\n\tprivate int curChar;\n\tprivate int numChars;\n\tprivate SpaceCharFilter filter;\n\n\tpublic InputReader(InputStream stream) {\n\t\tthis.stream = stream;\n\t}\n\n\tpublic int read() {\n\t\tif (numChars == -1)\n\t\t\tthrow new InputMismatchException();\n\t\tif (curChar >= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\tthrow new InputMismatchException();\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar++];\n\t}\n\n\tpublic int peek() {\n\t\tif (numChars == -1)\n\t\t\treturn -1;\n\t\tif (curChar >= numChars) {\n\t\t\tcurChar = 0;\n\t\t\ttry {\n\t\t\t\tnumChars = stream.read(buf);\n\t\t\t} catch (IOException e) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tif (numChars <= 0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn buf[curChar];\n\t}\n\n\tpublic int readInt() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tint res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tpublic long readLong() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tlong res = 0;\n\t\tdo {\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res * sgn;\n\t}\n\n\tpublic String readString() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tStringBuilder res = new StringBuilder();\n\t\tdo {\n\t\t\tif (Character.isValidCodePoint(c))\n\t\t\t\tres.appendCodePoint(c);\n\t\t\tc = read();\n\t\t} while (!isSpaceChar(c));\n\t\treturn res.toString();\n\t}\n\n\tpublic boolean isSpaceChar(int c) {\n\t\tif (filter != null)\n\t\t\treturn filter.isSpaceChar(c);\n\t\treturn isWhitespace(c);\n\t}\n\n\tpublic static boolean isWhitespace(int c) {\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t}\n\n\tprivate String readLine0() {\n\t\tStringBuilder buf = new StringBuilder();\n\t\tint c = read();\n\t\twhile (c != '\\n' && c != -1) {\n\t\t\tif (c != '\\r')\n\t\t\t\tbuf.appendCodePoint(c);\n\t\t\tc = read();\n\t\t}\n\t\treturn buf.toString();\n\t}\n\n\tpublic String readLine() {\n\t\tString s = readLine0();\n\t\twhile (s.trim().length() == 0)\n\t\t\ts = readLine0();\n\t\treturn s;\n\t}\n\n\tpublic String readLine(boolean ignoreEmptyLines) {\n\t\tif (ignoreEmptyLines)\n\t\t\treturn readLine();\n\t\telse\n\t\t\treturn readLine0();\n\t}\n\n\tpublic BigInteger readBigInteger() {\n\t\ttry {\n\t\t\treturn new BigInteger(readString());\n\t\t} catch (NumberFormatException e) {\n\t\t\tthrow new InputMismatchException();\n\t\t}\n\t}\n\n\tpublic char readCharacter() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\treturn (char) c;\n\t}\n\n\tpublic double readDouble() {\n\t\tint c = read();\n\t\twhile (isSpaceChar(c))\n\t\t\tc = read();\n\t\tint sgn = 1;\n\t\tif (c == '-') {\n\t\t\tsgn = -1;\n\t\t\tc = read();\n\t\t}\n\t\tdouble res = 0;\n\t\twhile (!isSpaceChar(c) && c != '.') {\n\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\treturn res * Math.pow(10, readInt());\n\t\t\tif (c < '0' || c > '9')\n\t\t\t\tthrow new InputMismatchException();\n\t\t\tres *= 10;\n\t\t\tres += c - '0';\n\t\t\tc = read();\n\t\t}\n\t\tif (c == '.') {\n\t\t\tc = read();\n\t\t\tdouble m = 1;\n\t\t\twhile (!isSpaceChar(c)) {\n\t\t\t\tif (c == 'e' || c == 'E')\n\t\t\t\t\treturn res * Math.pow(10, readInt());\n\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\tm /= 10;\n\t\t\t\tres += (c - '0') * m;\n\t\t\t\tc = read();\n\t\t\t}\n\t\t}\n\t\treturn res * sgn;\n\t}\n\n\tpublic boolean isExhausted() {\n\t\tint value;\n\t\twhile (isSpaceChar(value = peek()) && value != -1)\n\t\t\tread();\n\t\treturn value == -1;\n\t}\n\n\tpublic String next() {\n\t\treturn readString();\n\t}\n\n\tpublic SpaceCharFilter getFilter() {\n\t\treturn filter;\n\t}\n\n\tpublic void setFilter(SpaceCharFilter filter) {\n\t\tthis.filter = filter;\n\t}\n\n\tpublic interface SpaceCharFilter {\n\t\tpublic boolean isSpaceChar(int ch);\n\t}\n}\n\nclass OutputWriter {\n\tprivate final PrintWriter writer;\n\n\tpublic OutputWriter(OutputStream outputStream) {\n\t\twriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(\n\t\t\t\toutputStream)));\n\t}\n\n\tpublic OutputWriter(Writer writer) {\n\t\tthis.writer = new PrintWriter(writer);\n\t}\n\n\tpublic void print(char[] array) {\n\t\twriter.print(array);\n\t}\n\n\tpublic void print(Object... objects) {\n\t\tfor (int i = 0; i < objects.length; i++) {\n\t\t\tif (i != 0)\n\t\t\t\twriter.print(' ');\n\t\t\twriter.print(objects[i]);\n\t\t}\n\t}\n\n\tpublic void print(int[] array) {\n\t\tfor (int i = 0; i < array.length; i++) {\n\t\t\tif (i != 0)\n\t\t\t\twriter.print(' ');\n\t\t\twriter.print(array[i]);\n\t\t}\n\t}\n\n\tpublic void print(long[] array) {\n\t\tfor (int i = 0; i < array.length; i++) {\n\t\t\tif (i != 0)\n\t\t\t\twriter.print(' ');\n\t\t\twriter.print(array[i]);\n\t\t}\n\t}\n\n\tpublic void print(Collection<Integer> collection) {\n\t\tboolean first = true;\n\t\tfor (int i : collection) {\n\t\t\tif (first)\n\t\t\t\tfirst = false;\n\t\t\telse\n\t\t\t\twriter.print(' ');\n\t\t\twriter.print(i);\n\t\t}\n\t}\n\n\tpublic void printLine(int[] array) {\n\t\tprint(array);\n\t\twriter.println();\n\t}\n\n\tpublic void printLine(long[] array) {\n\t\tprint(array);\n\t\twriter.println();\n\t}\n\n\tpublic void printLine(Collection<Integer> collection) {\n\t\tprint(collection);\n\t\twriter.println();\n\t}\n\n\tpublic void printLine() {\n\t\twriter.println();\n\t}\n\n\tpublic void printLine(Object... objects) {\n\t\tprint(objects);\n\t\twriter.println();\n\t}\n\n\tpublic void print(char i) {\n\t\twriter.print(i);\n\t}\n\n\tpublic void printLine(char i) {\n\t\twriter.println(i);\n\t}\n\n\tpublic void printLine(char[] array) {\n\t\twriter.println(array);\n\t}\n\n\tpublic void printFormat(String format, Object... objects) {\n\t\twriter.printf(format, objects);\n\t}\n\n\tpublic void close() {\n\t\twriter.close();\n\t}\n\n\tpublic void flush() {\n\t\twriter.flush();\n\t}\n\n\tpublic void print(long i) {\n\t\twriter.print(i);\n\t}\n\n\tpublic void printLine(long i) {\n\t\twriter.println(i);\n\t}\n\n\tpublic void print(int i) {\n\t\twriter.print(i);\n\t}\n\n\tpublic void printLine(int i) {\n\t\twriter.println(i);\n\t}\n}\n\nclass Polygon {\n\tpublic final Point[] vertices;\n\tprivate Segment[] sides;\n\n\tpublic Polygon(Point... vertices) {\n\t\tthis.vertices = vertices.clone();\n\t}\n\n\tpublic double square() {\n\t\tdouble sum = 0;\n\t\tfor (int i = 1; i < vertices.length; i++)\n\t\t\tsum += (vertices[i].x - vertices[i - 1].x)\n\t\t\t\t\t* (vertices[i].y + vertices[i - 1].y);\n\t\tsum += (vertices[0].x - vertices[vertices.length - 1].x)\n\t\t\t\t* (vertices[0].y + vertices[vertices.length - 1].y);\n\t\treturn Math.abs(sum) / 2;\n\t}\n\n\tpublic Point center() {\n\t\tdouble sx = 0;\n\t\tdouble sy = 0;\n\t\tfor (Point point : vertices) {\n\t\t\tsx += point.x;\n\t\t\tsy += point.y;\n\t\t}\n\t\treturn new Point(sx / vertices.length, sy / vertices.length);\n\t}\n\n\tpublic static boolean over(Point a, Point b, Point c) {\n\t\treturn a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y) < -GeometryUtils.epsilon;\n\t}\n\n\tprivate static boolean under(Point a, Point b, Point c) {\n\t\treturn a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y) > GeometryUtils.epsilon;\n\t}\n\n\tpublic static Polygon convexHull(Point[] points) {\n\t\tif (points.length == 1)\n\t\t\treturn new Polygon(points);\n\t\tArrays.sort(points, new Comparator<Point>() {\n\t\t\tpublic int compare(Point o1, Point o2) {\n\t\t\t\tint value = Double.compare(o1.x, o2.x);\n\t\t\t\tif (value != 0)\n\t\t\t\t\treturn value;\n\t\t\t\treturn Double.compare(o1.y, o2.y);\n\t\t\t}\n\t\t});\n\t\tPoint left = points[0];\n\t\tPoint right = points[points.length - 1];\n\t\tList<Point> up = new ArrayList<Point>();\n\t\tList<Point> down = new ArrayList<Point>();\n\t\tfor (Point point : points) {\n\t\t\tif (point == left || point == right || !under(left, point, right)) {\n\t\t\t\twhile (up.size() >= 2\n\t\t\t\t\t\t&& under(up.get(up.size() - 2), up.get(up.size() - 1),\n\t\t\t\t\t\t\t\tpoint))\n\t\t\t\t\tup.remove(up.size() - 1);\n\t\t\t\tup.add(point);\n\t\t\t}\n\t\t\tif (point == left || point == right || !over(left, point, right)) {\n\t\t\t\twhile (down.size() >= 2\n\t\t\t\t\t\t&& over(down.get(down.size() - 2),\n\t\t\t\t\t\t\t\tdown.get(down.size() - 1), point))\n\t\t\t\t\tdown.remove(down.size() - 1);\n\t\t\t\tdown.add(point);\n\t\t\t}\n\t\t}\n\t\tPoint[] result = new Point[up.size() + down.size() - 2];\n\t\tint index = 0;\n\t\tfor (Point point : up)\n\t\t\tresult[index++] = point;\n\t\tfor (int i = down.size() - 2; i > 0; i--)\n\t\t\tresult[index++] = down.get(i);\n\t\treturn new Polygon(result);\n\t}\n\n\tpublic boolean contains(Point point) {\n\t\treturn contains(point, false);\n\t}\n\n\tpublic boolean contains(Point point, boolean strict) {\n\t\tfor (Segment segment : sides()) {\n\t\t\tif (segment.contains(point, true))\n\t\t\t\treturn !strict;\n\t\t}\n\t\tdouble totalAngle = GeometryUtils.canonicalAngle(Math.atan2(\n\t\t\t\tvertices[0].y - point.y, vertices[0].x - point.x)\n\t\t\t\t- Math.atan2(vertices[vertices.length - 1].y - point.y,\n\t\t\t\t\t\tvertices[vertices.length - 1].x - point.x));\n\t\tfor (int i = 1; i < vertices.length; i++) {\n\t\t\ttotalAngle += GeometryUtils.canonicalAngle(Math.atan2(vertices[i].y\n\t\t\t\t\t- point.y, vertices[i].x - point.x)\n\t\t\t\t\t- Math.atan2(vertices[i - 1].y - point.y, vertices[i - 1].x\n\t\t\t\t\t\t\t- point.x));\n\t\t}\n\t\treturn Math.abs(totalAngle) > Math.PI;\n\t}\n\n\tpublic Segment[] sides() {\n\t\tif (sides == null) {\n\t\t\tsides = new Segment[vertices.length];\n\t\t\tfor (int i = 0; i < vertices.length - 1; i++)\n\t\t\t\tsides[i] = new Segment(vertices[i], vertices[i + 1]);\n\t\t\tsides[sides.length - 1] = new Segment(\n\t\t\t\t\tvertices[vertices.length - 1], vertices[0]);\n\t\t}\n\t\treturn sides;\n\t}\n\n\tpublic static double triangleSquare(Point a, Point b, Point c) {\n\t\treturn Math.abs((a.x - b.x) * (a.y + b.y) + (b.x - c.x) * (b.y + c.y)\n\t\t\t\t+ (c.x - a.x) * (c.y + a.y)) / 2;\n\t}\n\n\tpublic double perimeter() {\n\t\tdouble result = vertices[0].distance(vertices[vertices.length - 1]);\n\t\tfor (int i = 1; i < vertices.length; i++)\n\t\t\tresult += vertices[i].distance(vertices[i - 1]);\n\t\treturn result;\n\t}\n}\n\nclass Point {\n\tpublic static final Point ORIGIN = new Point(0, 0);\n\tpublic final double x;\n\tpublic final double y;\n\n\t@Override\n\tpublic String toString() {\n\t\treturn \"(\" + x + \", \" + y + \")\";\n\t}\n\n\tpublic Point(double x, double y) {\n\t\tthis.x = x;\n\t\tthis.y = y;\n\t}\n\n\tpublic Line line(Point other) {\n\t\tif (equals(other))\n\t\t\treturn null;\n\t\tdouble a = other.y - y;\n\t\tdouble b = x - other.x;\n\t\tdouble c = -a * x - b * y;\n\t\treturn new Line(a, b, c);\n\t}\n\n\t@Override\n\tpublic boolean equals(Object o) {\n\t\tif (this == o)\n\t\t\treturn true;\n\t\tif (o == null || getClass() != o.getClass())\n\t\t\treturn false;\n\n\t\tPoint point = (Point) o;\n\n\t\treturn Math.abs(x - point.x) <= GeometryUtils.epsilon\n\t\t\t\t&& Math.abs(y - point.y) <= GeometryUtils.epsilon;\n\t}\n\n\t@Override\n\tpublic int hashCode() {\n\t\tint result;\n\t\tlong temp;\n\t\ttemp = x != +0.0d ? Double.doubleToLongBits(x) : 0L;\n\t\tresult = (int) (temp ^ (temp >>> 32));\n\t\ttemp = y != +0.0d ? Double.doubleToLongBits(y) : 0L;\n\t\tresult = 31 * result + (int) (temp ^ (temp >>> 32));\n\t\treturn result;\n\t}\n\n\tpublic double distance(Point other) {\n\t\treturn GeometryUtils.fastHypot(x - other.x, y - other.y);\n\t}\n\n\tpublic double distance(Line line) {\n\t\treturn Math.abs(line.a * x + line.b * y + line.c);\n\t}\n\n\tpublic double value() {\n\t\treturn GeometryUtils.fastHypot(x, y);\n\t}\n\n\tpublic double angle() {\n\t\treturn Math.atan2(y, x);\n\t}\n\n\tpublic static Point readPoint(InputReader in) {\n\t\tdouble x = in.readDouble();\n\t\tdouble y = in.readDouble();\n\t\treturn new Point(x, y);\n\t}\n\n\tpublic Point rotate(double angle) {\n\t\tdouble nx = x * Math.cos(angle) - y * Math.sin(angle);\n\t\tdouble ny = y * Math.cos(angle) + x * Math.sin(angle);\n\t\treturn new Point(nx, ny);\n\t}\n}\n\nclass Segment {\n\tpublic final Point a;\n\tpublic final Point b;\n\tprivate double distance = Double.NaN;\n\tprivate Line line = null;\n\n\tpublic Segment(Point a, Point b) {\n\t\tthis.a = a;\n\t\tthis.b = b;\n\t}\n\n\tpublic double length() {\n\t\tif (Double.isNaN(distance))\n\t\t\tdistance = a.distance(b);\n\t\treturn distance;\n\t}\n\n\tpublic double distance(Point point) {\n\t\tdouble length = length();\n\t\tdouble left = point.distance(a);\n\t\tif (length < GeometryUtils.epsilon)\n\t\t\treturn left;\n\t\tdouble right = point.distance(b);\n\t\tif (left * left > right * right + length * length)\n\t\t\treturn right;\n\t\tif (right * right > left * left + length * length)\n\t\t\treturn left;\n\t\treturn point.distance(line());\n\t}\n\n\tpublic Point intersect(Segment other, boolean includeEnds) {\n\t\tLine line = line();\n\t\tLine otherLine = other.a.line(other.b);\n\t\tif (line.parallel(otherLine))\n\t\t\treturn null;\n\t\tPoint intersection = line.intersect(otherLine);\n\t\tif (contains(intersection, includeEnds)\n\t\t\t\t&& other.contains(intersection, includeEnds))\n\t\t\treturn intersection;\n\t\telse\n\t\t\treturn null;\n\t}\n\n\tpublic boolean contains(Point point, boolean includeEnds) {\n\t\tif (a.equals(point) || b.equals(point))\n\t\t\treturn includeEnds;\n\t\tif (a.equals(b))\n\t\t\treturn false;\n\t\tLine line = line();\n\t\tif (!line.contains(point))\n\t\t\treturn false;\n\t\tLine perpendicular = line.perpendicular(a);\n\t\tdouble aValue = perpendicular.value(a);\n\t\tdouble bValue = perpendicular.value(b);\n\t\tdouble pointValue = perpendicular.value(point);\n\t\treturn aValue < pointValue && pointValue < bValue\n\t\t\t\t|| bValue < pointValue && pointValue < aValue;\n\t}\n\n\tpublic Line line() {\n\t\tif (line == null)\n\t\t\tline = a.line(b);\n\t\treturn line;\n\t}\n\n\tpublic Point middle() {\n\t\treturn new Point((a.x + b.x) / 2, (a.y + b.y) / 2);\n\t}\n\n\tpublic Point[] intersect(Circle circle) {\n\t\tPoint[] result = line().intersect(circle);\n\t\tif (result.length == 0)\n\t\t\treturn result;\n\t\tif (result.length == 1) {\n\t\t\tif (contains(result[0], true))\n\t\t\t\treturn result;\n\t\t\treturn new Point[0];\n\t\t}\n\t\tif (contains(result[0], true)) {\n\t\t\tif (contains(result[1], true))\n\t\t\t\treturn result;\n\t\t\treturn new Point[] { result[0] };\n\t\t}\n\t\tif (contains(result[1], true))\n\t\t\treturn new Point[] { result[1] };\n\t\treturn new Point[0];\n\t}\n\n\tpublic Point intersect(Line line) {\n\t\tLine selfLine = line();\n\t\tPoint intersect = selfLine.intersect(line);\n\t\tif (intersect == null)\n\t\t\treturn null;\n\t\tif (contains(intersect, true))\n\t\t\treturn intersect;\n\t\treturn null;\n\t}\n\n\tpublic double distance(Segment other) {\n\t\tLine line = line();\n\t\tLine otherLine = other.line();\n\t\tPoint p = line == null || otherLine == null ? null : line\n\t\t\t\t.intersect(otherLine);\n\t\tif (p != null && contains(p, true) && other.contains(p, true))\n\t\t\treturn 0;\n\t\treturn Math.min(Math.min(other.distance(a), other.distance(b)),\n\t\t\t\tMath.min(distance(other.a), distance(other.b)));\n\t}\n}\n\nclass GeometryUtils {\n\tpublic static double epsilon = 1e-8;\n\n\tpublic static double fastHypot(double... x) {\n\t\tif (x.length == 0)\n\t\t\treturn 0;\n\t\telse if (x.length == 1)\n\t\t\treturn Math.abs(x[0]);\n\t\telse {\n\t\t\tdouble sumSquares = 0;\n\t\t\tfor (double value : x)\n\t\t\t\tsumSquares += value * value;\n\t\t\treturn Math.sqrt(sumSquares);\n\t\t}\n\t}\n\n\tpublic static double fastHypot(double x, double y) {\n\t\treturn Math.sqrt(x * x + y * y);\n\t}\n\n\tpublic static double fastHypot(double[] x, double[] y) {\n\t\tif (x.length == 0)\n\t\t\treturn 0;\n\t\telse if (x.length == 1)\n\t\t\treturn Math.abs(x[0] - y[0]);\n\t\telse {\n\t\t\tdouble sumSquares = 0;\n\t\t\tfor (int i = 0; i < x.length; i++) {\n\t\t\t\tdouble diff = x[i] - y[i];\n\t\t\t\tsumSquares += diff * diff;\n\t\t\t}\n\t\t\treturn Math.sqrt(sumSquares);\n\t\t}\n\t}\n\n\tpublic static double fastHypot(int[] x, int[] y) {\n\t\tif (x.length == 0)\n\t\t\treturn 0;\n\t\telse if (x.length == 1)\n\t\t\treturn Math.abs(x[0] - y[0]);\n\t\telse {\n\t\t\tdouble sumSquares = 0;\n\t\t\tfor (int i = 0; i < x.length; i++) {\n\t\t\t\tdouble diff = x[i] - y[i];\n\t\t\t\tsumSquares += diff * diff;\n\t\t\t}\n\t\t\treturn Math.sqrt(sumSquares);\n\t\t}\n\t}\n\n\tpublic static double missileTrajectoryLength(double v, double angle,\n\t\t\tdouble g) {\n\t\treturn (v * v * Math.sin(2 * angle)) / g;\n\t}\n\n\tpublic static double sphereVolume(double radius) {\n\t\treturn 4 * Math.PI * radius * radius * radius / 3;\n\t}\n\n\tpublic static double triangleSquare(double first, double second,\n\t\t\tdouble third) {\n\t\tdouble p = (first + second + third) / 2;\n\t\treturn Math.sqrt(p * (p - first) * (p - second) * (p - third));\n\t}\n\n\tpublic static double canonicalAngle(double angle) {\n\t\twhile (angle > Math.PI)\n\t\t\tangle -= 2 * Math.PI;\n\t\twhile (angle < -Math.PI)\n\t\t\tangle += 2 * Math.PI;\n\t\treturn angle;\n\t}\n\n\tpublic static double positiveAngle(double angle) {\n\t\twhile (angle > 2 * Math.PI - GeometryUtils.epsilon)\n\t\t\tangle -= 2 * Math.PI;\n\t\twhile (angle < -GeometryUtils.epsilon)\n\t\t\tangle += 2 * Math.PI;\n\t\treturn angle;\n\t}\n}\n\nclass Line {\n\tpublic final double a;\n\tpublic final double b;\n\tpublic final double c;\n\n\tpublic Line(Point p, double angle) {\n\t\ta = Math.sin(angle);\n\t\tb = -Math.cos(angle);\n\t\tc = -p.x * a - p.y * b;\n\t}\n\n\tpublic Line(double a, double b, double c) {\n\t\tdouble h = GeometryUtils.fastHypot(a, b);\n\t\tthis.a = a / h;\n\t\tthis.b = b / h;\n\t\tthis.c = c / h;\n\t}\n\n\tpublic Point intersect(Line other) {\n\t\tif (parallel(other))\n\t\t\treturn null;\n\t\tdouble determinant = b * other.a - a * other.b;\n\t\tdouble x = (c * other.b - b * other.c) / determinant;\n\t\tdouble y = (a * other.c - c * other.a) / determinant;\n\t\treturn new Point(x, y);\n\t}\n\n\tpublic boolean parallel(Line other) {\n\t\treturn Math.abs(a * other.b - b * other.a) < GeometryUtils.epsilon;\n\t}\n\n\tpublic boolean contains(Point point) {\n\t\treturn Math.abs(value(point)) < GeometryUtils.epsilon;\n\t}\n\n\tpublic Line perpendicular(Point point) {\n\t\treturn new Line(-b, a, b * point.x - a * point.y);\n\t}\n\n\tpublic double value(Point point) {\n\t\treturn a * point.x + b * point.y + c;\n\t}\n\n\tpublic Point[] intersect(Circle circle) {\n\t\tdouble distance = distance(circle.center);\n\t\tif (distance > circle.radius + GeometryUtils.epsilon)\n\t\t\treturn new Point[0];\n\t\tPoint intersection = intersect(perpendicular(circle.center));\n\t\tif (Math.abs(distance - circle.radius) < GeometryUtils.epsilon)\n\t\t\treturn new Point[] { intersection };\n\t\tdouble shift = Math.sqrt(circle.radius * circle.radius - distance\n\t\t\t\t* distance);\n\t\treturn new Point[] {\n\t\t\t\tnew Point(intersection.x + shift * b, intersection.y - shift\n\t\t\t\t\t\t* a),\n\t\t\t\tnew Point(intersection.x - shift * b, intersection.y + shift\n\t\t\t\t\t\t* a) };\n\t}\n\n\tpublic double distance(Point center) {\n\t\treturn Math.abs(value(center));\n\t}\n\n\t@Override\n\tpublic boolean equals(Object o) {\n\t\tif (this == o)\n\t\t\treturn true;\n\t\tif (o == null || getClass() != o.getClass())\n\t\t\treturn false;\n\n\t\tLine line = (Line) o;\n\n\t\tif (!parallel(line))\n\t\t\treturn false;\n\t\tif (Math.abs(a * line.c - c * line.a) > GeometryUtils.epsilon\n\t\t\t\t|| Math.abs(b * line.c - c * line.b) > GeometryUtils.epsilon)\n\t\t\treturn false;\n\n\t\treturn true;\n\t}\n}\n\nclass Circle {\n\tpublic final Point center;\n\tpublic final double radius;\n\n\tpublic Circle(Point center, double radius) {\n\t\tthis.center = center;\n\t\tthis.radius = radius;\n\t}\n\n\tpublic boolean contains(Point point) {\n\t\treturn center.distance(point) < radius + GeometryUtils.epsilon;\n\t}\n\n\tpublic boolean strictContains(Point point) {\n\t\treturn center.distance(point) < radius - GeometryUtils.epsilon;\n\t}\n\n\tpublic Point[] findTouchingPoints(Point point) {\n\t\tdouble distance = center.distance(point);\n\t\tif (distance < radius - GeometryUtils.epsilon)\n\t\t\treturn new Point[0];\n\t\tif (distance < radius + GeometryUtils.epsilon)\n\t\t\treturn new Point[] { point };\n\t\tCircle power = new Circle(point, Math.sqrt((distance - radius)\n\t\t\t\t* (distance + radius)));\n\t\treturn intersect(power);\n\t}\n\n\tpublic Point[] intersect(Circle other) {\n\t\tdouble distance = center.distance(other.center);\n\t\tif (distance > radius + other.radius + GeometryUtils.epsilon\n\t\t\t\t|| Math.abs(radius - other.radius) > distance\n\t\t\t\t\t\t+ GeometryUtils.epsilon)\n\t\t\treturn new Point[0];\n\t\tdouble p = (radius + other.radius + distance) / 2;\n\t\tdouble height = 2\n\t\t\t\t* Math.sqrt(p * (p - radius) * (p - other.radius)\n\t\t\t\t\t\t* (p - distance)) / distance;\n\t\tdouble l1 = Math.sqrt(radius * radius - height * height);\n\t\tdouble l2 = Math.sqrt(other.radius * other.radius - height * height);\n\t\tif (radius * radius + distance * distance < other.radius * other.radius)\n\t\t\tl1 = -l1;\n\t\tif (radius * radius > distance * distance + other.radius * other.radius)\n\t\t\tl2 = -l2;\n\t\tPoint middle = new Point((center.x * l2 + other.center.x * l1)\n\t\t\t\t/ (l1 + l2), (center.y * l2 + other.center.y * l1) / (l1 + l2));\n\t\tLine line = center.line(other.center).perpendicular(middle);\n\t\treturn line.intersect(this);\n\t}\n}\n\nclass Pair<U, V> implements Comparable<Pair<U, V>> {\n\tpublic final U first;\n\tpublic final V second;\n\n\tpublic static <U, V> Pair<U, V> makePair(U first, V second) {\n\t\treturn new Pair<U, V>(first, second);\n\t}\n\n\tprivate Pair(U first, V second) {\n\t\tthis.first = first;\n\t\tthis.second = second;\n\t}\n\n\tpublic boolean equals(Object o) {\n\t\tif (this == o)\n\t\t\treturn true;\n\t\tif (o == null || getClass() != o.getClass())\n\t\t\treturn false;\n\n\t\tPair pair = (Pair) o;\n\n\t\treturn !(first != null ? !first.equals(pair.first) : pair.first != null)\n\t\t\t\t&& !(second != null ? !second.equals(pair.second)\n\t\t\t\t\t\t: pair.second != null);\n\n\t}\n\n\tpublic int hashCode() {\n\t\tint result = first != null ? first.hashCode() : 0;\n\t\tresult = 31 * result + (second != null ? second.hashCode() : 0);\n\t\treturn result;\n\t}\n\n\tpublic String toString() {\n\t\treturn \"(\" + first + \",\" + second + \")\";\n\t}\n\n\tpublic int compareTo(Pair<U, V> o) {\n\t\tint value = ((Comparable<U>) first).compareTo(o.first);\n\t\tif (value != 0)\n\t\t\treturn value;\n\t\treturn ((Comparable<V>) second).compareTo(o.second);\n\t}\n}\n\nclass IOUtils {\n\n\tpublic static void readIntArrays(InputReader in, int[]... arrays) {\n\t\tfor (int i = 0; i < arrays[0].length; i++) {\n\t\t\tfor (int j = 0; j < arrays.length; j++)\n\t\t\t\tarrays[j][i] = in.readInt();\n\t\t}\n\t}\n\n}\n\nclass TreapSet<K> implements NavigableSet<K> {\n\tprotected static final Random rnd = new Random(239);\n\n\tprotected final Node nullNode;\n\tprotected final Comparator<? super K> comparator;\n\tprotected Node root;\n\tprivate final K from;\n\tprivate final K to;\n\tprivate final boolean fromInclusive;\n\tprivate final boolean toInclusive;\n\n\tpublic TreapSet() {\n\t\tthis((Comparator<? super K>) null);\n\t}\n\n\tpublic TreapSet(Comparator<? super K> comparator) {\n\t\tthis(null, null, false, false, comparator, null, null);\n\t}\n\n\tprotected TreapSet(K from, K to, boolean fromInclusive,\n\t\t\tboolean toInclusive, Comparator<? super K> comparator, Node root,\n\t\t\tNode nullNode) {\n\t\tthis.comparator = comparator;\n\t\tthis.from = from;\n\t\tthis.to = to;\n\t\tthis.fromInclusive = fromInclusive;\n\t\tthis.toInclusive = toInclusive;\n\t\tif (nullNode == null)\n\t\t\tnullNode = new NullNode();\n\t\tif (root == null)\n\t\t\troot = nullNode;\n\t\tthis.root = root;\n\t\tthis.nullNode = nullNode;\n\t}\n\n\tpublic boolean addAll(Iterable<? extends K> collection) {\n\t\tboolean result = false;\n\t\tfor (K element : collection)\n\t\t\tresult |= add(element);\n\t\treturn result;\n\t}\n\n\tpublic K lower(K k) {\n\t\tNode target = root.lower(k);\n\t\tif (target == nullNode)\n\t\t\treturn null;\n\t\tif (belongs(target.key))\n\t\t\treturn target.key;\n\t\treturn null;\n\t}\n\n\tprivate boolean belongs(K key) {\n\t\tint valueFrom = compare(from, key);\n\t\tint valueTo = compare(key, to);\n\t\treturn (valueFrom < 0 || valueFrom == 0 && fromInclusive)\n\t\t\t\t&& (valueTo < 0 || valueTo == 0 && toInclusive);\n\t}\n\n\tpublic K floor(K k) {\n\t\tNode target = root.floor(k);\n\t\tif (target == nullNode)\n\t\t\treturn null;\n\t\tif (belongs(target.key))\n\t\t\treturn target.key;\n\t\treturn null;\n\t}\n\n\tpublic K ceiling(K k) {\n\t\tNode target = root.ceil(k);\n\t\tif (target == nullNode)\n\t\t\treturn null;\n\t\tif (belongs(target.key))\n\t\t\treturn target.key;\n\t\treturn null;\n\t}\n\n\tpublic K higher(K k) {\n\t\tNode target = root.higher(k);\n\t\tif (target == nullNode)\n\t\t\treturn null;\n\t\tif (belongs(target.key))\n\t\t\treturn target.key;\n\t\treturn null;\n\t}\n\n\tpublic K pollFirst() {\n\t\tK first = first();\n\t\tif (first == null)\n\t\t\tthrow new NoSuchElementException();\n\t\troot.erase(first);\n\t\treturn first;\n\t}\n\n\tpublic K pollLast() {\n\t\tK last = last();\n\t\tif (last == null)\n\t\t\tthrow new NoSuchElementException();\n\t\troot.erase(last);\n\t\treturn last;\n\t}\n\n\tpublic int size() {\n\t\tif (from == null && to == null)\n\t\t\treturn root.size;\n\t\tif (from == null) {\n\t\t\tNode to = toInclusive ? root.floor(this.to) : root.lower(this.to);\n\t\t\tif (to == nullNode)\n\t\t\t\treturn 0;\n\t\t\treturn root.indexOf(to) + 1;\n\t\t}\n\t\tif (to == null) {\n\t\t\tNode from = fromInclusive ? root.ceil(this.from) : root\n\t\t\t\t\t.higher(this.from);\n\t\t\tif (from == nullNode)\n\t\t\t\treturn 0;\n\t\t\treturn root.size - root.indexOf(from);\n\t\t}\n\t\tNode from = fromInclusive ? root.ceil(this.from) : root\n\t\t\t\t.higher(this.from);\n\t\tif (from == nullNode || !belongs(from.key))\n\t\t\treturn 0;\n\t\tNode to = toInclusive ? root.floor(this.to) : root.lower(this.to);\n\t\treturn root.indexOf(to) - root.indexOf(from) + 1;\n\t}\n\n\tpublic boolean isEmpty() {\n\t\treturn size() == 0;\n\t}\n\n\tpublic boolean contains(Object o) {\n\t\treturn belongs((K) o) && root.search((K) o) != nullNode;\n\t}\n\n\tpublic Iterator<K> iterator() {\n\t\treturn new Iterator<K>() {\n\t\t\tprivate K current = first();\n\n\t\t\tpublic boolean hasNext() {\n\t\t\t\treturn current != null;\n\t\t\t}\n\n\t\t\tpublic K next() {\n\t\t\t\tK result = current;\n\t\t\t\tcurrent = higher(current);\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\tpublic void remove() {\n\t\t\t\tTreapSet.this.remove(current);\n\t\t\t}\n\t\t};\n\t}\n\n\tpublic Object[] toArray() {\n\t\tObject[] array = new Object[size()];\n\t\tint index = 0;\n\t\tfor (K key : this)\n\t\t\tarray[index++] = key;\n\t\treturn array;\n\t}\n\n\tpublic <T> T[] toArray(T[] a) {\n\t\tif (a.length < size())\n\t\t\tthrow new IllegalArgumentException();\n\t\tint index = 0;\n\t\tfor (K key : this)\n\t\t\ta[index++] = (T) key;\n\t\treturn a;\n\t}\n\n\tpublic boolean add(K k) {\n\t\tif (k == null)\n\t\t\tthrow new NullPointerException();\n\t\tif (contains(k))\n\t\t\treturn false;\n\t\troot = root.insert(createNode(k));\n\t\treturn true;\n\t}\n\n\tprotected Node createNode(K k) {\n\t\treturn new Node(k, rnd.nextLong());\n\t}\n\n\tpublic boolean remove(Object o) {\n\t\tif (!contains(o))\n\t\t\treturn false;\n\t\t// noinspection unchecked\n\t\troot = root.erase((K) o);\n\t\treturn true;\n\t}\n\n\tpublic boolean containsAll(Collection<?> c) {\n\t\tfor (Object o : c) {\n\t\t\tif (!contains(o))\n\t\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tpublic boolean addAll(Collection<? extends K> c) {\n\t\treturn addAll((Iterable<? extends K>) c);\n\t}\n\n\tpublic boolean retainAll(Collection<?> c) {\n\t\tList<K> toRemove = new ArrayList<K>();\n\t\tfor (K key : this) {\n\t\t\tif (!c.contains(key))\n\t\t\t\ttoRemove.add(key);\n\t\t}\n\t\treturn removeAll(toRemove);\n\t}\n\n\tpublic boolean removeAll(Collection<?> c) {\n\t\tboolean result = false;\n\t\tfor (Object o : c)\n\t\t\tresult |= remove(o);\n\t\treturn result;\n\t}\n\n\tpublic void clear() {\n\t\tretainAll(Collections.<Object> emptySet());\n\t}\n\n\tpublic NavigableSet<K> descendingSet() {\n\t\tthrow new UnsupportedOperationException();\n\t}\n\n\tpublic Iterator<K> descendingIterator() {\n\t\treturn new Iterator<K>() {\n\t\t\tprivate K current = last();\n\n\t\t\tpublic boolean hasNext() {\n\t\t\t\treturn current != null;\n\t\t\t}\n\n\t\t\tpublic K next() {\n\t\t\t\tK result = current;\n\t\t\t\tcurrent = lower(current);\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\tpublic void remove() {\n\t\t\t\tTreapSet.this.remove(current);\n\t\t\t}\n\t\t};\n\t}\n\n\tpublic NavigableSet<K> subSet(K fromElement, boolean fromInclusive,\n\t\t\tK toElement, boolean toInclusive) {\n\t\treturn new TreapSet<K>(fromElement, toElement, fromInclusive,\n\t\t\t\ttoInclusive, comparator, root, nullNode);\n\t}\n\n\tpublic NavigableSet<K> headSet(K toElement, boolean inclusive) {\n\t\treturn subSet(null, false, toElement, inclusive);\n\t}\n\n\tpublic NavigableSet<K> tailSet(K fromElement, boolean inclusive) {\n\t\treturn subSet(fromElement, inclusive, null, false);\n\t}\n\n\tpublic Comparator<? super K> comparator() {\n\t\treturn comparator;\n\t}\n\n\tpublic SortedSet<K> subSet(K fromElement, K toElement) {\n\t\treturn subSet(fromElement, true, toElement, false);\n\t}\n\n\tpublic SortedSet<K> headSet(K toElement) {\n\t\treturn subSet(null, false, toElement, false);\n\t}\n\n\tpublic SortedSet<K> tailSet(K fromElement) {\n\t\treturn tailSet(fromElement, true);\n\t}\n\n\tpublic K first() {\n\t\tif (isEmpty())\n\t\t\treturn null;\n\t\tif (from == null)\n\t\t\treturn root.first().key;\n\t\tif (fromInclusive)\n\t\t\treturn ceiling(from);\n\t\treturn higher(from);\n\t}\n\n\tpublic K last() {\n\t\tif (isEmpty())\n\t\t\treturn null;\n\t\tif (to == null)\n\t\t\treturn root.last().key;\n\t\tif (toInclusive)\n\t\t\treturn floor(to);\n\t\treturn lower(to);\n\t}\n\n\tprotected int compare(K first, K second) {\n\t\tif (first == null || second == null)\n\t\t\treturn -1;\n\t\tif (comparator != null)\n\t\t\treturn comparator.compare(first, second);\n\t\t// noinspection unchecked\n\t\treturn ((Comparable<? super K>) first).compareTo(second);\n\t}\n\n\tprotected class Node {\n\t\tprotected final K key;\n\t\tprotected final long priority;\n\t\tprotected Node left;\n\t\tprotected Node right;\n\t\tprotected int size;\n\n\t\tprotected Node(K key, long priority) {\n\t\t\tthis.key = key;\n\t\t\tthis.priority = priority;\n\t\t\tleft = nullNode;\n\t\t\tright = nullNode;\n\t\t\tsize = 1;\n\t\t}\n\n\t\tprotected Object[] split(K key) {\n\t\t\tif (compare(key, this.key) < 0) {\n\t\t\t\tObject[] result = left.split(key);\n\t\t\t\tleft = (Node) result[1];\n\t\t\t\tresult[1] = this;\n\t\t\t\tupdateSize();\n\t\t\t\treturn result;\n\t\t\t}\n\t\t\tObject[] result = right.split(key);\n\t\t\tright = (Node) result[0];\n\t\t\tresult[0] = this;\n\t\t\tupdateSize();\n\t\t\treturn result;\n\t\t}\n\n\t\tprotected void updateSize() {\n\t\t\tsize = left.size + right.size + 1;\n\t\t}\n\n\t\tprotected Node insert(Node node) {\n\t\t\tif (node.priority > priority) {\n\t\t\t\tObject[] result = split(node.key);\n\t\t\t\tnode.left = (Node) result[0];\n\t\t\t\tnode.right = (Node) result[1];\n\t\t\t\tnode.updateSize();\n\t\t\t\treturn node;\n\t\t\t}\n\t\t\tif (compare(node.key, this.key) < 0) {\n\t\t\t\tleft = left.insert(node);\n\t\t\t\tupdateSize();\n\t\t\t\treturn this;\n\t\t\t}\n\t\t\tright = right.insert(node);\n\t\t\tupdateSize();\n\t\t\treturn this;\n\t\t}\n\n\t\tprotected Node merge(Node left, Node right) {\n\t\t\tif (left == nullNode)\n\t\t\t\treturn right;\n\t\t\tif (right == nullNode)\n\t\t\t\treturn left;\n\t\t\tif (left.priority > right.priority) {\n\t\t\t\tleft.right = left.right.merge(left.right, right);\n\t\t\t\tleft.updateSize();\n\t\t\t\treturn left;\n\t\t\t}\n\t\t\tright.left = right.left.merge(left, right.left);\n\t\t\tright.updateSize();\n\t\t\treturn right;\n\t\t}\n\n\t\tprotected Node erase(K key) {\n\t\t\tint value = compare(key, this.key);\n\t\t\tif (value == 0)\n\t\t\t\treturn merge(left, right);\n\t\t\tif (value < 0) {\n\t\t\t\tleft = left.erase(key);\n\t\t\t\tupdateSize();\n\t\t\t\treturn this;\n\t\t\t}\n\t\t\tright = right.erase(key);\n\t\t\tupdateSize();\n\t\t\treturn this;\n\t\t}\n\n\t\tprotected Node lower(K key) {\n\t\t\tif (compare(key, this.key) <= 0)\n\t\t\t\treturn left.lower(key);\n\t\t\tNode result = right.lower(key);\n\t\t\tif (result == nullNode)\n\t\t\t\treturn this;\n\t\t\treturn result;\n\t\t}\n\n\t\tprotected Node floor(K key) {\n\t\t\tif (compare(key, this.key) < 0)\n\t\t\t\treturn left.floor(key);\n\t\t\tNode result = right.floor(key);\n\t\t\tif (result == nullNode)\n\t\t\t\treturn this;\n\t\t\treturn result;\n\t\t}\n\n\t\tprotected Node higher(K key) {\n\t\t\tif (compare(key, this.key) >= 0)\n\t\t\t\treturn right.higher(key);\n\t\t\tNode result = left.higher(key);\n\t\t\tif (result == nullNode)\n\t\t\t\treturn this;\n\t\t\treturn result;\n\t\t}\n\n\t\tprotected Node ceil(K key) {\n\t\t\tif (compare(key, this.key) > 0)\n\t\t\t\treturn right.ceil(key);\n\t\t\tNode result = left.ceil(key);\n\t\t\tif (result == nullNode)\n\t\t\t\treturn this;\n\t\t\treturn result;\n\t\t}\n\n\t\tprotected Node first() {\n\t\t\tif (left == nullNode)\n\t\t\t\treturn this;\n\t\t\treturn left.first();\n\t\t}\n\n\t\tprotected Node last() {\n\t\t\tif (right == nullNode)\n\t\t\t\treturn this;\n\t\t\treturn right.last();\n\t\t}\n\n\t\tprotected Node search(K key) {\n\t\t\tint value = compare(key, this.key);\n\t\t\tif (value == 0)\n\t\t\t\treturn this;\n\t\t\tif (value < 0)\n\t\t\t\treturn left.search(key);\n\t\t\treturn right.search(key);\n\t\t}\n\n\t\tpublic int indexOf(Node node) {\n\t\t\tif (this == node)\n\t\t\t\treturn left.size;\n\t\t\tif (compare(node.key, this.key) > 0)\n\t\t\t\treturn left.size + 1 + right.indexOf(node);\n\t\t\treturn left.indexOf(node);\n\t\t}\n\n\t}\n\n\tprivate class NullNode extends Node {\n\t\tprivate Object[] splitResult = new Object[2];\n\n\t\tprivate NullNode() {\n\t\t\tsuper(null, Long.MIN_VALUE);\n\t\t\tleft = this;\n\t\t\tright = this;\n\t\t\tsize = 0;\n\t\t}\n\n\t\tprotected Object[] split(K key) {\n\t\t\tsplitResult[0] = splitResult[1] = this;\n\t\t\treturn splitResult;\n\t\t}\n\n\t\tprotected Node insert(Node node) {\n\t\t\treturn node;\n\t\t}\n\n\t\tprotected Node erase(K key) {\n\t\t\treturn this;\n\t\t}\n\n\t\tprotected Node lower(K key) {\n\t\t\treturn this;\n\t\t}\n\n\t\tprotected Node floor(K key) {\n\t\t\treturn this;\n\t\t}\n\n\t\tprotected Node higher(K key) {\n\t\t\treturn this;\n\t\t}\n\n\t\tprotected Node ceil(K key) {\n\t\t\treturn this;\n\t\t}\n\n\t\tprotected Node first() {\n\t\t\tthrow new NoSuchElementException();\n\t\t}\n\n\t\tprotected Node last() {\n\t\t\tthrow new NoSuchElementException();\n\t\t}\n\n\t\tprotected void updateSize() {\n\t\t}\n\n\t\tprotected Node search(K key) {\n\t\t\treturn this;\n\t\t}\n\n\t}\n}\n\nclass EHashMap<E, V> extends AbstractMap<E, V> {\n\tprivate static final int[] shifts = new int[10];\n\n\tprivate int size;\n\tprivate HashEntry<E, V>[] data;\n\tprivate int capacity;\n\tprivate Set<Entry<E, V>> entrySet;\n\n\tstatic {\n\t\tRandom random = new Random(System.currentTimeMillis());\n\t\tfor (int i = 0; i < 10; i++)\n\t\t\tshifts[i] = 1 + 3 * i + random.nextInt(3);\n\t}\n\n\tpublic EHashMap() {\n\t\tthis(4);\n\t}\n\n\tprivate void setCapacity(int size) {\n\t\tcapacity = Integer.highestOneBit(4 * size);\n\t\t// noinspection unchecked\n\t\tdata = new HashEntry[capacity];\n\t}\n\n\tpublic EHashMap(int maxSize) {\n\t\tsetCapacity(maxSize);\n\t\tentrySet = new AbstractSet<Entry<E, V>>() {\n\t\t\tpublic Iterator<Entry<E, V>> iterator() {\n\t\t\t\treturn new Iterator<Entry<E, V>>() {\n\t\t\t\t\tprivate HashEntry<E, V> last = null;\n\t\t\t\t\tprivate HashEntry<E, V> current = null;\n\t\t\t\t\tprivate HashEntry<E, V> base = null;\n\t\t\t\t\tprivate int lastIndex = -1;\n\t\t\t\t\tprivate int index = -1;\n\n\t\t\t\t\tpublic boolean hasNext() {\n\t\t\t\t\t\tif (current == null) {\n\t\t\t\t\t\t\tfor (index++; index < capacity; index++) {\n\t\t\t\t\t\t\t\tif (data[index] != null) {\n\t\t\t\t\t\t\t\t\tbase = current = data[index];\n\t\t\t\t\t\t\t\t\tbreak;\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\treturn current != null;\n\t\t\t\t\t}\n\n\t\t\t\t\tpublic Entry<E, V> next() {\n\t\t\t\t\t\tif (!hasNext())\n\t\t\t\t\t\t\tthrow new NoSuchElementException();\n\t\t\t\t\t\tlast = current;\n\t\t\t\t\t\tlastIndex = index;\n\t\t\t\t\t\tcurrent = current.next;\n\t\t\t\t\t\tif (base.next != last)\n\t\t\t\t\t\t\tbase = base.next;\n\t\t\t\t\t\treturn last;\n\t\t\t\t\t}\n\n\t\t\t\t\tpublic void remove() {\n\t\t\t\t\t\tif (last == null)\n\t\t\t\t\t\t\tthrow new IllegalStateException();\n\t\t\t\t\t\tsize--;\n\t\t\t\t\t\tif (base == last)\n\t\t\t\t\t\t\tdata[lastIndex] = last.next;\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tbase.next = last.next;\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tpublic int size() {\n\t\t\t\treturn size;\n\t\t\t}\n\t\t};\n\t}\n\n\tpublic Set<Entry<E, V>> entrySet() {\n\t\treturn entrySet;\n\t}\n\n\tpublic void clear() {\n\t\tArrays.fill(data, null);\n\t\tsize = 0;\n\t}\n\n\tprivate int index(Object o) {\n\t\treturn getHash(o.hashCode()) & (capacity - 1);\n\t}\n\n\tprivate int getHash(int h) {\n\t\tint result = h;\n\t\tfor (int i : shifts)\n\t\t\tresult ^= h >>> i;\n\t\treturn result;\n\t}\n\n\tpublic V remove(Object o) {\n\t\tif (o == null)\n\t\t\treturn null;\n\t\tint index = index(o);\n\t\tHashEntry<E, V> current = data[index];\n\t\tHashEntry<E, V> last = null;\n\t\twhile (current != null) {\n\t\t\tif (current.key.equals(o)) {\n\t\t\t\tif (last == null)\n\t\t\t\t\tdata[index] = current.next;\n\t\t\t\telse\n\t\t\t\t\tlast.next = current.next;\n\t\t\t\tsize--;\n\t\t\t\treturn current.value;\n\t\t\t}\n\t\t\tlast = current;\n\t\t\tcurrent = current.next;\n\t\t}\n\t\treturn null;\n\t}\n\n\tpublic V put(E e, V value) {\n\t\tif (e == null)\n\t\t\treturn null;\n\t\tint index = index(e);\n\t\tHashEntry<E, V> current = data[index];\n\t\tif (current != null) {\n\t\t\twhile (true) {\n\t\t\t\tif (current.key.equals(e)) {\n\t\t\t\t\tV oldValue = current.value;\n\t\t\t\t\tcurrent.value = value;\n\t\t\t\t\treturn oldValue;\n\t\t\t\t}\n\t\t\t\tif (current.next == null)\n\t\t\t\t\tbreak;\n\t\t\t\tcurrent = current.next;\n\t\t\t}\n\t\t}\n\t\tif (current == null)\n\t\t\tdata[index] = new HashEntry<E, V>(e, value);\n\t\telse\n\t\t\tcurrent.next = new HashEntry<E, V>(e, value);\n\t\tsize++;\n\t\tif (2 * size > capacity) {\n\t\t\tHashEntry<E, V>[] oldData = data;\n\t\t\tsetCapacity(size);\n\t\t\tfor (HashEntry<E, V> entry : oldData) {\n\t\t\t\twhile (entry != null) {\n\t\t\t\t\tHashEntry<E, V> next = entry.next;\n\t\t\t\t\tindex = index(entry.key);\n\t\t\t\t\tentry.next = data[index];\n\t\t\t\t\tdata[index] = entry;\n\t\t\t\t\tentry = next;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn null;\n\t}\n\n\tpublic V get(Object o) {\n\t\tif (o == null)\n\t\t\treturn null;\n\t\tint index = index(o);\n\t\tHashEntry<E, V> current = data[index];\n\t\twhile (current != null) {\n\t\t\tif (current.key.equals(o))\n\t\t\t\treturn current.value;\n\t\t\tcurrent = current.next;\n\t\t}\n\t\treturn null;\n\t}\n\n\tpublic boolean containsKey(Object o) {\n\t\tif (o == null)\n\t\t\treturn false;\n\t\tint index = index(o);\n\t\tHashEntry<E, V> current = data[index];\n\t\twhile (current != null) {\n\t\t\tif (current.key.equals(o))\n\t\t\t\treturn true;\n\t\t\tcurrent = current.next;\n\t\t}\n\t\treturn false;\n\t}\n\n\tpublic int size() {\n\t\treturn size;\n\t}\n\n\tprivate static class HashEntry<E, V> implements Entry<E, V> {\n\t\tprivate final E key;\n\t\tprivate V value;\n\t\tprivate HashEntry<E, V> next;\n\n\t\tprivate HashEntry(E key, V value) {\n\t\t\tthis.key = key;\n\t\t\tthis.value = value;\n\t\t}\n\n\t\tpublic E getKey() {\n\t\t\treturn key;\n\t\t}\n\n\t\tpublic V getValue() {\n\t\t\treturn value;\n\t\t}\n\n\t\tpublic V setValue(V value) {\n\t\t\tV oldValue = this.value;\n\t\t\tthis.value = value;\n\t\t\treturn oldValue;\n\t\t}\n\t}\n}\n\nabstract class IntervalTree {\n\tprotected int size;\n\n\tpublic IntervalTree(int size, boolean shouldInit) {\n\t\tthis.size = size;\n\t\tint nodeCount = Math.max(1, Integer.highestOneBit(size) << 2);\n\t\tinitData(size, nodeCount);\n\t\tif (shouldInit)\n\t\t\tinit();\n\t}\n\n\tprotected abstract void initData(int size, int nodeCount);\n\n\tprotected abstract void initAfter(int root, int left, int right, int middle);\n\n\tprotected abstract void initBefore(int root, int left, int right, int middle);\n\n\tprotected abstract void initLeaf(int root, int index);\n\n\tprotected abstract void updatePostProcess(int root, int left, int right,\n\t\t\tint from, int to, long delta, int middle);\n\n\tprotected abstract void updatePreProcess(int root, int left, int right,\n\t\t\tint from, int to, long delta, int middle);\n\n\tprotected abstract void updateFull(int root, int left, int right, int from,\n\t\t\tint to, long delta);\n\n\tprotected abstract long queryPostProcess(int root, int left, int right,\n\t\t\tint from, int to, int middle, long leftResult, long rightResult);\n\n\tprotected abstract void queryPreProcess(int root, int left, int right,\n\t\t\tint from, int to, int middle);\n\n\tprotected abstract long queryFull(int root, int left, int right, int from,\n\t\t\tint to);\n\n\tprotected abstract long emptySegmentResult();\n\n\tpublic void init() {\n\t\tif (size == 0)\n\t\t\treturn;\n\t\tinit(0, 0, size - 1);\n\t}\n\n\tprivate void init(int root, int left, int right) {\n\t\tif (left == right) {\n\t\t\tinitLeaf(root, left);\n\t\t} else {\n\t\t\tint middle = (left + right) >> 1;\n\t\t\tinitBefore(root, left, right, middle);\n\t\t\tinit(2 * root + 1, left, middle);\n\t\t\tinit(2 * root + 2, middle + 1, right);\n\t\t\tinitAfter(root, left, right, middle);\n\t\t}\n\t}\n\n\tpublic void update(int from, int to, long delta) {\n\t\tupdate(0, 0, size - 1, from, to, delta);\n\t}\n\n\tprotected void update(int root, int left, int right, int from, int to,\n\t\t\tlong delta) {\n\t\tif (left > to || right < from)\n\t\t\treturn;\n\t\tif (left >= from && right <= to) {\n\t\t\tupdateFull(root, left, right, from, to, delta);\n\t\t\treturn;\n\t\t}\n\t\tint middle = (left + right) >> 1;\n\t\tupdatePreProcess(root, left, right, from, to, delta, middle);\n\t\tupdate(2 * root + 1, left, middle, from, to, delta);\n\t\tupdate(2 * root + 2, middle + 1, right, from, to, delta);\n\t\tupdatePostProcess(root, left, right, from, to, delta, middle);\n\t}\n\n\tpublic long query(int from, int to) {\n\t\treturn query(0, 0, size - 1, from, to);\n\t}\n\n\tprotected long query(int root, int left, int right, int from, int to) {\n\t\tif (left > to || right < from)\n\t\t\treturn emptySegmentResult();\n\t\tif (left >= from && right <= to)\n\t\t\treturn queryFull(root, left, right, from, to);\n\t\tint middle = (left + right) >> 1;\n\t\tqueryPreProcess(root, left, right, from, to, middle);\n\t\tlong leftResult = query(2 * root + 1, left, middle, from, to);\n\t\tlong rightResult = query(2 * root + 2, middle + 1, right, from, to);\n\t\treturn queryPostProcess(root, left, right, from, to, middle,\n\t\t\t\tleftResult, rightResult);\n\t}\n}\n\nabstract class LongIntervalTree extends IntervalTree {\n\tprotected long[] value;\n\tprotected long[] delta;\n\n\tprotected LongIntervalTree(int size) {\n\t\tthis(size, true);\n\t}\n\n\tpublic LongIntervalTree(int size, boolean shouldInit) {\n\t\tsuper(size, shouldInit);\n\t}\n\n\tprotected void initData(int size, int nodeCount) {\n\t\tvalue = new long[nodeCount];\n\t\tdelta = new long[nodeCount];\n\t}\n\n\tprotected abstract long joinValue(long left, long right);\n\n\tprotected abstract long joinDelta(long was, long delta);\n\n\tprotected abstract long accumulate(long value, long delta, int length);\n\n\tprotected abstract long neutralValue();\n\n\tprotected abstract long neutralDelta();\n\n\tprotected long initValue(int index) {\n\t\treturn neutralValue();\n\t}\n\n\tprotected void initAfter(int root, int left, int right, int middle) {\n\t\tvalue[root] = joinValue(value[2 * root + 1], value[2 * root + 2]);\n\t\tdelta[root] = neutralDelta();\n\t}\n\n\tprotected void initBefore(int root, int left, int right, int middle) {\n\t}\n\n\tprotected void initLeaf(int root, int index) {\n\t\tvalue[root] = initValue(index);\n\t\tdelta[root] = neutralDelta();\n\t}\n\n\tprotected void updatePostProcess(int root, int left, int right, int from,\n\t\t\tint to, long delta, int middle) {\n\t\tvalue[root] = joinValue(value[2 * root + 1], value[2 * root + 2]);\n\t}\n\n\tprotected void updatePreProcess(int root, int left, int right, int from,\n\t\t\tint to, long delta, int middle) {\n\t\tpushDown(root, left, middle, right);\n\t}\n\n\tprotected void pushDown(int root, int left, int middle, int right) {\n\t\tvalue[2 * root + 1] = accumulate(value[2 * root + 1], delta[root],\n\t\t\t\tmiddle - left + 1);\n\t\tvalue[2 * root + 2] = accumulate(value[2 * root + 2], delta[root],\n\t\t\t\tright - middle);\n\t\tdelta[2 * root + 1] = joinDelta(delta[2 * root + 1], delta[root]);\n\t\tdelta[2 * root + 2] = joinDelta(delta[2 * root + 2], delta[root]);\n\t\tdelta[root] = neutralDelta();\n\t}\n\n\tprotected void updateFull(int root, int left, int right, int from, int to,\n\t\t\tlong delta) {\n\t\tvalue[root] = accumulate(value[root], delta, right - left + 1);\n\t\tthis.delta[root] = joinDelta(this.delta[root], delta);\n\t}\n\n\tprotected long queryPostProcess(int root, int left, int right, int from,\n\t\t\tint to, int middle, long leftResult, long rightResult) {\n\t\treturn joinValue(leftResult, rightResult);\n\t}\n\n\tprotected void queryPreProcess(int root, int left, int right, int from,\n\t\t\tint to, int middle) {\n\t\tpushDown(root, left, middle, right);\n\t}\n\n\tprotected long queryFull(int root, int left, int right, int from, int to) {\n\t\treturn value[root];\n\t}\n\n\tprotected long emptySegmentResult() {\n\t\treturn neutralValue();\n\t}\n}", "src_uid": "1f68bd6f8b40e45a5bd360b03a264ef4"} {"source_code": "import java.util.*;\npublic class A988 {\n\tpublic static void main(String[] args) {\n\t\tScanner scan = new Scanner(System.in);\n\t\tint num = scan.nextInt();\n int st = scan.nextInt();\n int h, c = 0;\n boolean[] ar = new boolean[101];\n int[] res = new int[101];\n for(int i = 0; i < num; i++){\n h = scan.nextInt();\n if(!ar[h]){\n \tres[c++] = i+1;\n \tar[h] = true;\n }\n }\n if(c < st){\n System.out.print(\"NO\");\n return;\n }\n System.out.println(\"YES\");\n for(int i = 0; i < st-1; i++)\n System.out.print(res[i] + \" \");\n System.out.print(res[st-1]);\n\t}\n}", "src_uid": "5de6574d57ab04ca195143e08d28d0ad"} {"source_code": "import java.io.*;\nimport java.util.StringTokenizer;\n\n/**\n * Created by sbabkin on 9/14/2015.\n */\npublic class SolverB {\n\n public static void main(String[] args) throws IOException {\n new SolverB().Run();\n }\n\n BufferedReader br;\n PrintWriter pw;\n StringTokenizer stok;\n\n private String nextToken() throws IOException {\n while (stok == null || !stok.hasMoreTokens()) {\n stok = new StringTokenizer(br.readLine());\n }\n return stok.nextToken();\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 double nextDouble() throws IOException {\n return Double.parseDouble(nextToken());\n }\n\n private void Run() throws IOException {\n// br = new BufferedReader(new FileReader(\"input.txt\"));\n// pw = new PrintWriter(\"output.txt\");\n br=new BufferedReader(new InputStreamReader(System.in));\n pw=new PrintWriter(new OutputStreamWriter(System.out));\n\n solve();\n pw.flush();\n pw.close();\n }\n\n int n;\n int m;\n boolean[] used;\n int[] result;\n int[] inds;\n\n private void solve() throws IOException {\n n = nextInt();\n m = nextInt();\n used = new boolean[101];\n result = new int[n + 1];\n inds = new int[m];\n for (int i = 0; i < m; i++) {\n inds[i] = nextInt();\n }\n for (int i = 0; i < m - 1; i++) {\n int next = (inds[i + 1] + n - inds[i] - 1) % n + 1;\n if (next > n) {\n pw.println(-1);\n return;\n }\n if (result[inds[i]] > 0 && next != result[inds[i]]) {\n pw.println(-1);\n return;\n }\n if (used[next] && result[inds[i]]==0) {\n pw.println(-1);\n return;\n }\n result[inds[i]]=next;\n used[next]=true;\n }\n int ui = 1;\n for (int i=1; i<=n; i++) {\n if (result[i]==0) {\n while (used[ui]) {\n ui++;\n }\n result[i]=ui;\n used[ui]=true;\n }\n }\n for (int i=1; i<=n; i++) {\n pw.print(result[i] + \" \");\n }\n pw.println();\n }\n\n}\n", "src_uid": "4a7c959ca279d0a9bd9bbf0ce88cf72b"} {"source_code": "import java.util.*;\n\npublic class Bishok {\n static int count = 0;\n public static void main(String[] args) {\n\n Scanner sc = new Scanner(System.in);\n String up = sc.nextLine();\n String dn = sc.nextLine();\n\n int empty = 0;\n int ans = 0;\n for(int i=0;i<up.length();i++) {\n if(up.charAt(i) == '0') {\n empty++;\n }\n\n if(dn.charAt(i) == '0') {\n empty++;\n }\n\n if(empty>=3) {\n empty -= 3;\n ans++;\n } else {\n empty = 0;\n if(up.charAt(i) == '0') {\n empty++;\n }\n if(dn.charAt(i) == '0') {\n empty++;\n }\n }\n }\n System.out.println(ans);\n }\n}\n", "src_uid": "e6b3e787919e96fc893a034eae233fc6"} {"source_code": "\nimport java.util.Scanner;\n\npublic class A {\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int c = in.nextInt();\n int res = 0;\n int[] A = new int[n];\n for (int i = 0; i < n; i++)\n A[i] = in.nextInt();\n for (int i = 1; i < n; i++)\n res = Math.max(A[i - 1] - A[i] - c, res);\n System.out.println(res);\n }\n}\n", "src_uid": "411539a86f2e94eb6386bb65c9eb9557"} {"source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n * @author flk\n */\npublic class Main {\n public static void main(String[] args) throws IOException {\n InputStream inputStream = System.in;\n //OutputStream outputStream = System.out;\n //BufferedOutputStream buffered = new BufferedOutputStream(outputStream);\n BufferedOutputStream buffered = new BufferedOutputStream(System.out);\n //Scanner in = new Scanner(inputStream);\n Reader in = new Reader(); in.init(inputStream);\n PrintWriter out = new PrintWriter(buffered);\n Task solver = new Task();\n solver.solve(1, in, out);\n out.close();\n }\n}\n\n\n\nclass Task {\n\n\n public void solve(int testNumber, Reader in, PrintWriter out) throws IOException {\n\n int A = in.nextInt();\n int B = in.nextInt();\n\n\n ArrayList<Integer> seq = new ArrayList<Integer>();\n seq.add(B);\n while (B > A) {\n if (B % 2 == 0) {\n B = B/2;\n }\n else if (B % 10 == 1) {\n B = B/10;\n }\n else break;\n seq.add(B);\n }\n\n if (A == B) {\n out.println(\"YES\");\n out.println(seq.size());\n for (int i = seq.size()-1; i>=0 ; i--) {\n out.print(seq.get(i));\n out.print(\" \");\n }\n }\n else {\n out.println(\"NO\");\n }\n\n // out.print(sb);\n }\n\n}\n\n/** Class for buffered reading int and double values */\nclass Reader {\n static BufferedReader reader;\n static StringTokenizer tokenizer;\n\n /** call this method to initialize reader for InputStream */\n static void init(InputStream input) {\n reader = new BufferedReader(\n new InputStreamReader(input) );\n tokenizer = new StringTokenizer(\"\");\n }\n\n /** get next word */\n static String next() throws IOException {\n while ( ! tokenizer.hasMoreTokens() ) {\n //TODO add check for eof if necessary\n tokenizer = new StringTokenizer(\n reader.readLine() );\n }\n return tokenizer.nextToken();\n }\n\n static int nextInt() throws IOException {\n return Integer.parseInt( next() );\n }\n\n static long nextLong() throws IOException {\n return Long.parseLong( next() );\n }\n\n static double nextDouble() throws IOException {\n return Double.parseDouble( next() );\n }\n}\n\n\n", "src_uid": "fc3adb1a9a7f1122b567b4d8afd7b3f3"} {"source_code": "import java.util.Scanner;\n\npublic class G {\n\tstatic final long mod = 1000000007;\n\tstatic Integer[][] memo = new Integer[4005][4005];\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint X = sc.nextInt();\n\t\tint Y = sc.nextInt();\n\t\tlong add = 0, sub =0;\n\t\t\n\t\tlong combs = (X+1L)*(Y+1L);\n\t\tlong oo = ((X+1)>>1) * ((Y+1)>>1);\n\t\tlong oe = ((X+1)>>1) * ((Y+2)>>1);\n\t\tlong eo = ((X+2)>>1) * ((Y+1)>>1);\n\t\tlong ee = ((X+2)>>1) * ((Y+2)>>1);\n\t\t\n\t\t//two\n\t\tadd+=trip(ee,ee-1,combs-ee);\n\t\tadd+=trip(eo,eo-1,combs-eo);\n\t\tadd+=trip(oe,oe-1,combs-oe);\n\t\tadd+=trip(oo,oo-1,combs-oo);\n\t\tadd*=3;\n\t\t\n\t\t//three\n\t\tadd+=trip(ee,ee-1,ee-2);\n\t\tadd+=trip(eo,eo-1,eo-2);\n\t\tadd+=trip(oe,oe-1,oe-2);\n\t\tadd+=trip(oo,oo-1,oo-2);\n\t\t\n\t\t\n\t\tfor (int x = -X; x <= X; x++) {\n\t\t\tfor (int y = 0; y <= Y; y++) {\n\t\t\t\tif(x<=0 && y == 0) continue;\n\t\t\t\tlong ways = GCD(Math.abs(y), Math.abs(x)) + 1;\n\t\t\t\tlong pick = (X - Math.abs(x) + 1) * (Y - y + 1);\n\t\t\t\tlong temp = (pick * (6*(ways-2))) % mod;\n\t\t\t\tif(temp>0){\n\t\t\t\t\tsub+=temp;\n\t\t\t\t}\n\t\t\t}\n\n\t\t}\n\t\tsub%=mod;\n\t\tadd%=mod;\n\n\t//\tSystem.out.println(add+\" \"+sub);\n\t\tSystem.out.println((((add-sub) % mod)+mod)%mod);\n\t}\n\n\tprivate static long trip(long A, long B, long C) {\n\t\treturn (((A*B)%mod)*C)%mod;\n\t}\n\n\tprivate static Integer GCD(int a, int b) {\n\t\tif(memo[a][b]!=null)return memo[a][b];\n\t\tif (b == 0)\treturn memo[a][b]=a;\n\t\treturn memo[a][b]=GCD(b, a % b);\n\t}\n}\n", "src_uid": "984788e4b4925c15c9c6f31e42f2f8fa"} {"source_code": "import java.io.*;\nimport java.util.*;\n\n//System.out.println();\npublic class A\n{\n public static int[] arr;\n public static int n, k;\n public static String s;\n public static void main(String[] args) throws IOException\n {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n String[] in = br.readLine().trim().split(\"\\\\s\");\n n = Integer.parseInt(in[0]);\n k = Integer.parseInt(in[1]); \n \n System.out.println(fn());\n }\n \n public static int fn()\n {\n //System.out.println();\n //StringBuilder x = new StringBuilder(s);\n int rem = 240 - k;\n int ans = 0;\n for(int i = 1; i <= n; i++)\n if(5 * i <= rem){\n ans++;\n rem -= 5*i;\n }\n \n return ans;\n }\n \n public static int swap(int g1, int g2)\n {\n return g1;\n }\n}", "src_uid": "41e554bc323857be7b8483ee358a35e2"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashSet;\nimport java.util.List;\nimport java.util.Set;\n\npublic class ProblemC {\n\t\n\tstatic final long MOD = 51123987;\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\tBufferedReader s = new BufferedReader(new InputStreamReader(System.in));\n\t\tPrintWriter out = new PrintWriter(System.out);\n\n\t\tint N = Integer.valueOf(s.readLine());\n\t\tchar[] cl = s.readLine().toCharArray();\n\t\t\n\t\tList<Integer> arr = new ArrayList<Integer>();\n\t\tchar prv = '-';\n\t\tfor (char c : cl) {\n\t\t\tif (prv != c) {\n\t\t\t\tarr.add(c - 'a');\n\t\t\t}\n\t\t\tprv = c;\n\t\t}\n\t\t\n\n\t\tint len = arr.size();\n\t\tint[][] next = new int[len][3];\n\t\tfor (int t = 0 ; t < len ; t++) {\n\t\t\tfor (int d = 0 ; d <= 2 ; d++) {\n\t\t\t\tint ta = t;\n\t\t\t\twhile (ta < len && arr.get(ta) != d) {\n\t\t\t\t\tta++;\n\t\t\t\t}\n\t\t\t\tnext[t][d] = ta;\n\t\t\t}\n\t\t}\n\t\t\n\t\tlong[][][][] dp = new long[2][len+1][61][61];\n\t\tdp[0][0][0][0] = 1;\n\t\tfor (int c = 0 ; c < N ; c++) {\n\t\t\tint fr = c % 2;\n\t\t\tint to = 1 - fr;\n\t\t\tfor (int t = 0 ; t <= len ; t++) {\n\t\t\t\tfor (int a = 0 ; a <= 60 ; a++) {\n\t\t\t\t\tArrays.fill(dp[to][t][a], 0);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (int t = 0 ; t < len ; t++) {\n\t\t\t\tint ta = next[t][0];\n\t\t\t\tint tb = next[t][1];\n\t\t\t\tint tc = next[t][2];\n\t\t\t\tfor (int a = 0 ; a <= 55 ; a++) {\n\t\t\t\t\tfor (int b = 0 ; b <= 55 ; b++) {\n\t\t\t\t\t\tif (dp[fr][t][a][b] >= 1) {\n\t\t\t\t\t\t\tdp[to][ta][a+1][b] += dp[fr][t][a][b];\n\t\t\t\t\t\t\tdp[to][ta][a+1][b] %= MOD;\n\n\t\t\t\t\t\t\tdp[to][tb][a][b+1] += dp[fr][t][a][b];\n\t\t\t\t\t\t\tdp[to][tb][a][b+1] %= MOD;\n\n\t\t\t\t\t\t\tdp[to][tc][a][b] += dp[fr][t][a][b];\n\t\t\t\t\t\t\tdp[to][tc][a][b] %= 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}\n\t\t\n\t\tint fin = N % 2;\n\t\tlong ptn = 0;\n\t\tfor (int cu = 0 ; cu <= len - 1 ; cu++) {\n\t\t\tfor (int a = 0 ; a <= 55 ; a++) {\n\t\t\t\tfor (int b = 0 ; b <= 55 ; b++) {\n\t\t\t\t\tint c = N - a - b;\n\t\t\t\t\tif (c >= 0 && Math.abs(a - b) <= 1 && Math.abs(b - c) <= 1 && Math.abs(c - a) <= 1) {\n\t\t\t\t\t\tptn += dp[fin][cu][a][b];\n\t\t\t\t\t\tptn %= MOD;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tout.println(ptn);\n\t\tout.flush();\n\t}\n\n\tpublic static void debug(Object... os){\n\t\tSystem.err.println(Arrays.deepToString(os));\n\t}\n}", "src_uid": "64fada10630906e052ff05f2afbf337e"} {"source_code": "\nimport java.io.File;\nimport java.io.IOException;\nimport java.util.Scanner;\n\n/**\n *\n * @author USer\n */\npublic class CutRibbon {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) throws IOException {\n Scanner r=new Scanner(System.in);\n int n=r.nextInt();\n int a=r.nextInt();\n int b=r.nextInt();\n int c=r.nextInt();\n int max=0;\n for(int i=0;i*a<=n;i++){\n for(int j=0;i*a+j*b<=n;j++){\n if((n-i*a-j*b)%c==0 && (n-i*a-j*b)/c+i+j>max)\n max=(n-i*a-j*b)/c+i+j;\n }\n }\n System.out.println(max);\n}\n}", "src_uid": "062a171cc3ea717ea95ede9d7a1c3a43"} {"source_code": "//package baobab;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class D {\n\n public static void main(String[] args) {\n Solver solver = new Solver();\n }\n\n static class Solver {\n IO io;\n\n public Solver() {\n this.io = new IO();\n try {\n solve();\n } catch (RuntimeException e) {\n if (!e.getMessage().equals(\"Clean exit\")) {\n throw e;\n }\n } finally {\n io.close();\n }\n }\n\n /****************************** START READING HERE ********************************/\n\n void solve() {\n int n = io.nextInt();\n int m = io.nextInt();\n List<Pair> a = new ArrayList<>();\n for (int i=0; i<n; i++) {\n a.add(new Pair(io.nextInt(), io.nextInt()));\n }\n List<Pair> b = new ArrayList<>();\n for (int i=0; i<m; i++) {\n b.add(new Pair(io.nextInt(), io.nextInt()));\n }\n HashSet<Integer> possibleAnswersForA = dox(a, b);\n HashSet<Integer> possibleAnswersForB = dox(b, a);\n HashSet<Integer> union = getUnion(possibleAnswersForA, possibleAnswersForB);\n if (union.size() == 1) {\n for (Integer ans : union) done(ans);\n }\n io.println(0);\n }\n\n HashSet<Integer> dox(List<Pair> a, List<Pair> b) {\n HashSet<Integer> possibleAnswers = new HashSet<>();\n for (Pair real : a) {\n boolean xPossible = false;\n boolean yPossible = false;\n for (Pair candidate : b) {\n if (real.x == candidate.x && real.y == candidate.y) continue;\n if (real.x == candidate.y && real.y == candidate.x) continue;\n\n if (real.x == candidate.x) xPossible = true;\n if (real.x == candidate.y) xPossible = true;\n\n if (real.y == candidate.y) yPossible = true;\n if (real.y == candidate.x) yPossible = true;\n\n }\n if (xPossible && yPossible) done(-1);\n if (xPossible) possibleAnswers.add(real.x);\n if (yPossible) possibleAnswers.add(real.y);\n }\n return possibleAnswers;\n }\n\n HashSet<Integer> getUnion(HashSet<Integer> a, HashSet<Integer> b) {\n HashSet<Integer> union = new HashSet<>();\n for (Integer cand : a) {\n if (b.contains(cand)) union.add(cand);\n }\n return union;\n }\n\n /************************** UTILITY CODE BELOW THIS LINE **************************/\n\n long MOD = (long)1e9 + 7;\n\n List<Integer>[] toGraph(IO io, int n) {\n List<Integer>[] g = new ArrayList[n+1];\n for (int i=1; i<=n; i++) g[i] = new ArrayList<>();\n for (int i=1; i<=n-1; i++) {\n int a = io.nextInt();\n int b = io.nextInt();\n g[a].add(b);\n g[b].add(a);\n }\n return g;\n }\n\n class Graph {\n HashMap<Long, List<Long>> edges;\n\n public Graph() {\n edges = new HashMap<>();\n }\n\n List<Long> getSetNeighbors(Long node) {\n List<Long> neighbors = edges.get(node);\n if (neighbors == null) {\n neighbors = new ArrayList<>();\n edges.put(node, neighbors);\n }\n return neighbors;\n }\n\n void addBiEdge(Long a, Long b) {\n addEdge(a, b);\n addEdge(b, a);\n }\n\n void addEdge(Long from, Long to) {\n getSetNeighbors(to); // make sure all have initialized lists\n List<Long> neighbors = getSetNeighbors(from);\n neighbors.add(to);\n }\n\n // topoSort variables\n int UNTOUCHED = 0;\n int FINISHED = 2;\n int INPROGRESS = 1;\n HashMap<Long, Integer> vis;\n List<Long> topoAns;\n List<Long> failDueToCycle = new ArrayList<Long>() {{ add(-1L); }};\n\n List<Long> topoSort() {\n topoAns = new ArrayList<>();\n vis = new HashMap<>();\n for (Long a : edges.keySet()) {\n if (!topoDFS(a)) return failDueToCycle;\n }\n Collections.reverse(topoAns);\n return topoAns;\n }\n\n boolean topoDFS(long curr) {\n Integer status = vis.get(curr);\n if (status == null) status = UNTOUCHED;\n if (status == FINISHED) return true;\n if (status == INPROGRESS) {\n return false;\n }\n vis.put(curr, INPROGRESS);\n for (long next : edges.get(curr)) {\n if (!topoDFS(next)) return false;\n }\n vis.put(curr, FINISHED);\n topoAns.add(curr);\n return true;\n }\n\n }\n\n class Pair {\n int y;\n int x;\n\n public Pair(int y, int x) {\n this.y = y;\n this.x = x;\n }\n }\n\n class IDval implements Comparable<IDval> {\n int id;\n long val;\n\n public IDval(int id, long val) {\n this.val = val;\n this.id = id;\n }\n\n @Override\n public int compareTo(IDval o) {\n if (this.val < o.val) return -1;\n if (this.val > o.val) return 1;\n return this.id - o.id;\n }\n }\n\n long pow(long base, int exp) {\n if (exp == 0) return 1L;\n long x = pow(base, exp/2);\n long ans = x * x;\n if (exp % 2 != 0) ans *= base;\n return ans;\n }\n\n long gcd(long... v) {\n /** Chained calls to Euclidean algorithm. */\n if (v.length == 1) return v[0];\n long ans = gcd(v[1], v[0]);\n for (int i=2; i<v.length; i++) {\n ans = gcd(ans, v[i]);\n }\n return ans;\n }\n\n long gcd(long a, long b) {\n /** Euclidean algorithm. */\n if (b == 0) return a;\n return gcd(b, a%b);\n }\n\n int[] generatePrimesUpTo(int last) {\n /* Sieve of Eratosthenes. Practically O(n). Values of 0 indicate primes. */\n int[] div = new int[last+1];\n for (int x=2; x<=last; x++) {\n if (div[x] > 0) continue;\n for (int u=2*x; u<=last; u+=x) {\n div[u] = x;\n }\n }\n return div;\n }\n\n long lcm(long a, long b) {\n /** Least common multiple */\n return a * b / gcd(a,b);\n }\n\n private class ElementCounter {\n private HashMap<Long, Integer> elements;\n\n public ElementCounter() {\n elements = new HashMap<>();\n }\n\n public void add(long element) {\n int count = 1;\n Integer prev = elements.get(element);\n if (prev != null) count += prev;\n elements.put(element, count);\n }\n\n public void remove(long element) {\n int count = elements.remove(element);\n count--;\n if (count > 0) elements.put(element, count);\n }\n\n public int get(long element) {\n Integer val = elements.get(element);\n if (val == null) return 0;\n return val;\n }\n\n public int size() {\n return elements.size();\n }\n }\n\n class StringCounter {\n HashMap<String, Integer> elements;\n\n public StringCounter() {\n elements = new HashMap<>();\n }\n\n public void add(String identifier) {\n int count = 1;\n Integer prev = elements.get(identifier);\n if (prev != null) count += prev;\n elements.put(identifier, count);\n }\n\n public void remove(String identifier) {\n int count = elements.remove(identifier);\n count--;\n if (count > 0) elements.put(identifier, count);\n }\n\n public long get(String identifier) {\n Integer val = elements.get(identifier);\n if (val == null) return 0;\n return val;\n }\n\n public int size() {\n return elements.size();\n }\n }\n\n class DisjointSet {\n /** Union Find / Disjoint Set data structure. */\n int[] size;\n int[] parent;\n int componentCount;\n\n public DisjointSet(int n) {\n componentCount = n;\n size = new int[n];\n parent = new int[n];\n for (int i=0; i<n; i++) parent[i] = i;\n for (int i=0; i<n; i++) size[i] = 1;\n }\n\n public void join(int a, int b) {\n /* Find roots */\n int rootA = parent[a];\n int rootB = parent[b];\n while (rootA != parent[rootA]) rootA = parent[rootA];\n while (rootB != parent[rootB]) rootB = parent[rootB];\n\n if (rootA == rootB) {\n /* Already in the same set */\n return;\n }\n\n /* Merge smaller set into larger set. */\n if (size[rootA] > size[rootB]) {\n size[rootA] += size[rootB];\n parent[rootB] = rootA;\n } else {\n size[rootB] += size[rootA];\n parent[rootA] = rootB;\n }\n componentCount--;\n }\n\n }\n\n class LCAFinder {\n\n /* O(n log n) Initialize: new LCAFinder(graph)\n * O(log n) Queries: find(a,b) returns lowest common ancestor for nodes a and b */\n\n int[] nodes;\n int[] depths;\n int[] entries;\n int pointer;\n FenwickMin fenwick;\n\n public LCAFinder(List<Integer>[] graph) {\n this.nodes = new int[(int)10e6];\n this.depths = new int[(int)10e6];\n this.entries = new int[graph.length];\n this.pointer = 1;\n boolean[] visited = new boolean[graph.length+1];\n dfs(1, 0, graph, visited);\n fenwick = new FenwickMin(pointer-1);\n for (int i=1; i<pointer; i++) {\n fenwick.set(i, depths[i] * 1000000L + i);\n }\n }\n\n private void dfs(int node, int depth, List<Integer>[] graph, boolean[] visited) {\n visited[node] = true;\n entries[node] = pointer;\n nodes[pointer] = node;\n depths[pointer] = depth;\n pointer++;\n for (int neighbor : graph[node]) {\n if (visited[neighbor]) continue;\n dfs(neighbor, depth+1, graph, visited);\n nodes[pointer] = node;\n depths[pointer] = depth;\n pointer++;\n }\n }\n\n public int find(int a, int b) {\n int left = entries[a];\n int right = entries[b];\n if (left > right) {\n int temp = left;\n left = right;\n right = temp;\n }\n long mixedBag = fenwick.getMin(left, right);\n int index = (int) (mixedBag % 1000000L);\n return nodes[index];\n }\n }\n\n class FenwickMin {\n long n;\n long[] original;\n long[] bottomUp;\n long[] topDown;\n\n public FenwickMin(int n) {\n this.n = n;\n original = new long[n+2];\n bottomUp = new long[n+2];\n topDown = new long[n+2];\n }\n\n public void set(int modifiedNode, long value) {\n long replaced = original[modifiedNode];\n original[modifiedNode] = value;\n // Update left tree\n int i = modifiedNode;\n long v = value;\n while (i <= n) {\n if (v > bottomUp[i]) {\n if (replaced == bottomUp[i]) {\n v = Math.min(v, original[i]);\n for (int r=1 ;; r++) {\n int x = (i&-i)>>>r;\n if (x == 0) break;\n int child = i-x;\n v = Math.min(v, bottomUp[child]);\n }\n } else break;\n }\n if (v == bottomUp[i]) break;\n bottomUp[i] = v;\n i += (i&-i);\n }\n // Update right tree\n i = modifiedNode;\n v = value;\n while (i > 0) {\n if (v > topDown[i]) {\n if (replaced == topDown[i]) {\n v = Math.min(v, original[i]);\n for (int r=1 ;; r++) {\n int x = (i&-i)>>>r;\n if (x == 0) break;\n int child = i+x;\n if (child > n+1) break;\n v = Math.min(v, topDown[child]);\n }\n } else break;\n }\n if (v == topDown[i]) break;\n topDown[i] = v;\n i -= (i&-i);\n }\n }\n\n public long getMin(int a, int b) {\n long min = original[a];\n int prev = a;\n int curr = prev + (prev&-prev); // parent right hand side\n while (curr <= b) {\n min = Math.min(min, topDown[prev]); // value from the other tree\n prev = curr;\n curr = prev + (prev&-prev);;\n }\n min = Math.min(min, original[prev]);\n prev = b;\n curr = prev - (prev&-prev); // parent left hand side\n while (curr >= a) {\n min = Math.min(min,bottomUp[prev]); // value from the other tree\n prev = curr;\n curr = prev - (prev&-prev);\n }\n return min;\n }\n\n }\n\n class FenwickSum {\n public long[] d;\n\n public FenwickSum(int n) {\n d=new long[n+1];\n }\n\n /** a[0] must be unused. */\n public FenwickSum(long[] a) {\n d=new long[a.length];\n for (int i=1; i<a.length; i++) {\n modify(i, a[i]);\n }\n }\n\n /** Do not modify i=0. */\n void modify(int i, long v) {\n while (i<d.length) {\n d[i] += v;\n // Move to next uplink on the RIGHT side of i\n i += (i&-i);\n }\n }\n\n /** Returns sum from a to b, *BOTH* inclusive. */\n long getSum(int a, int b) {\n return getSum(b) - getSum(a-1);\n }\n\n private long getSum(int i) {\n long sum = 0;\n while (i>0) {\n sum += d[i];\n // Move to next uplink on the LEFT side of i\n i -= (i&-i);\n }\n return sum;\n }\n }\n\n class SegmentTree {\n /** Query sums with log(n) modifyRange */\n int N;\n long[] p;\n\n public SegmentTree(int n) {\n /* TODO: Test that this works. */\n for (N=2; N<n; N++) N *= 2;\n p = new long[2*N];\n }\n\n public void modifyRange(int a, int b, long change) {\n muuta(a, change);\n muuta(b+1, -change);\n }\n\n void muuta(int k, long muutos) {\n k += N;\n p[k] += muutos;\n for (k /= 2; k >= 1; k /= 2) {\n p[k] = p[2*k] + p[2*k+1];\n }\n }\n\n public long get(int k) {\n int a = N;\n int b = k+N;\n long s = 0;\n while (a <= b) {\n if (a%2 == 1) s += p[a++];\n if (b%2 == 0) s += p[b--];\n a /= 2;\n b /= 2;\n }\n return s;\n }\n\n }\n\n class Zalgo {\n\n public int pisinEsiintyma(String haku, String kohde) {\n char[] s = new char[haku.length() + 1 + kohde.length()];\n for (int i=0; i<haku.length(); i++) {\n s[i] = haku.charAt(i);\n }\n int j = haku.length();\n s[j++] = '#';\n for (int i=0; i<kohde.length(); i++) {\n s[j++] = kohde.charAt(i);\n }\n int[] z = toZarray(s);\n int max = 0;\n for (int i=haku.length(); i<z.length; i++) {\n max = Math.max(max, z[i]);\n }\n return max;\n }\n\n public int[] toZarray(char[] s) {\n int n = s.length;\n int[] z = new int[n];\n int a = 0, b = 0;\n for (int i = 1; i < n; i++) {\n if (i > b) {\n for (int j = i; j < n && s[j - i] == s[j]; j++) z[i]++;\n }\n else {\n z[i] = z[i - a];\n if (i + z[i - a] > b) {\n for (int j = b + 1; j < n && s[j - i] == s[j]; j++) z[i]++;\n a = i;\n b = i + z[i] - 1;\n }\n }\n }\n return z;\n }\n\n public List<Integer> getStartIndexesWhereWordIsFound(String haku, String kohde) {\n // this is alternative use case\n char[] s = new char[haku.length() + 1 + kohde.length()];\n for (int i=0; i<haku.length(); i++) {\n s[i] = haku.charAt(i);\n }\n int j = haku.length();\n s[j++] = '#';\n for (int i=0; i<kohde.length(); i++) {\n s[j++] = kohde.charAt(i);\n }\n int[] z = toZarray(s);\n List<Integer> indexes = new ArrayList<>();\n for (int i=haku.length(); i<z.length; i++) {\n if (z[i] < haku.length()) continue;\n indexes.add(i);\n }\n return indexes;\n }\n\n }\n\n class StringHasher {\n\n class HashedString {\n long[] hashes;\n long[] modifiers;\n\n public HashedString(long[] hashes, long[] modifiers) {\n this.hashes = hashes;\n this.modifiers = modifiers;\n }\n }\n\n long P;\n long M;\n\n public StringHasher() {\n initializePandM();\n }\n\n HashedString hashString(String s) {\n int n = s.length();\n long[] hashes = new long[n];\n long[] modifiers = new long[n];\n hashes[0] = s.charAt(0);\n modifiers[0] = 1;\n for (int i=1; i<n; i++) {\n hashes[i] = (hashes[i-1] * P + s.charAt(i)) % M;\n modifiers[i] = (modifiers[i-1] * P) % M;\n }\n return new HashedString(hashes, modifiers);\n }\n\n /**\n * Indices are inclusive.\n */\n long getHash(HashedString hashedString, int startIndex, int endIndex) {\n long[] hashes = hashedString.hashes;\n long[] modifiers = hashedString.modifiers;\n long result = hashes[endIndex];\n if (startIndex > 0) result -= (hashes[startIndex-1] * modifiers[endIndex-startIndex+1]) % M;\n if (result < 0) result += M;\n return result;\n }\n\n // Less interesting methods below\n\n\n\n /**\n * Efficient for 2 input parameter strings in particular.\n */\n HashedString[] hashString(String first, String second) {\n HashedString[] array = new HashedString[2];\n int n = first.length();\n long[] modifiers = new long[n];\n modifiers[0] = 1;\n\n long[] firstHashes = new long[n];\n firstHashes[0] = first.charAt(0);\n array[0] = new HashedString(firstHashes, modifiers);\n\n long[] secondHashes = new long[n];\n secondHashes[0] = second.charAt(0);\n array[1] = new HashedString(secondHashes, modifiers);\n\n for (int i=1; i<n; i++) {\n modifiers[i] = (modifiers[i-1] * P) % M;\n firstHashes[i] = (firstHashes[i-1] * P + first.charAt(i)) % M;\n secondHashes[i] = (secondHashes[i-1] * P + second.charAt(i)) % M;\n }\n return array;\n }\n\n /**\n * Efficient for 3+ strings\n * More efficient than multiple hashString calls IF strings are same length.\n */\n HashedString[] hashString(String... strings) {\n HashedString[] array = new HashedString[strings.length];\n int n = strings[0].length();\n long[] modifiers = new long[n];\n modifiers[0] = 1;\n for (int j=0; j<strings.length; j++) {\n // if all strings are not same length, defer work to another method\n if (strings[j].length() != n) {\n for (int i=0; i<n; i++) {\n array[i] = hashString(strings[i]);\n }\n return array;\n }\n\n // otherwise initialize stuff\n long[] hashes = new long[n];\n hashes[0] = strings[j].charAt(0);\n array[j] = new HashedString(hashes, modifiers);\n }\n for (int i=1; i<n; i++) {\n modifiers[i] = (modifiers[i-1] * P) % M;\n for (int j=0; j<strings.length; j++) {\n String s = strings[j];\n long[] hashes = array[j].hashes;\n hashes[i] = (hashes[i-1] * P + s.charAt(i)) % M;\n }\n }\n return array;\n }\n\n void initializePandM() {\n ArrayList<Long> modOptions = new ArrayList<>(20);\n modOptions.add(353873237L);\n modOptions.add(353875897L);\n modOptions.add(353878703L);\n modOptions.add(353882671L);\n modOptions.add(353885303L);\n modOptions.add(353888377L);\n modOptions.add(353893457L);\n P = modOptions.get(new Random().nextInt(modOptions.size()));\n\n modOptions.clear();\n modOptions.add(452940277L);\n modOptions.add(452947687L);\n modOptions.add(464478431L);\n modOptions.add(468098221L);\n modOptions.add(470374601L);\n modOptions.add(472879717L);\n modOptions.add(472881973L);\n M = modOptions.get(new Random().nextInt(modOptions.size()));\n\n }\n }\n\n private static class Prob {\n\n /** For heavy calculations on probabilities, this class\n * provides more accuracy & efficiency than doubles.\n * Math explained: https://en.wikipedia.org/wiki/Log_probability\n * Quick start:\n * - Instantiate probabilities, eg. Prob a = new Prob(0.75)\n * - add(), multiply() return new objects, can perform on nulls & NaNs.\n * - get() returns probability as a readable double */\n\n /** Logarithmized probability. Note: 0% represented by logP NaN. */\n private double logP;\n\n /** Construct instance with real probability. */\n public Prob(double real) {\n if (real > 0) this.logP = Math.log(real);\n else this.logP = Double.NaN;\n }\n\n /** Construct instance with already logarithmized value. */\n static boolean dontLogAgain = true;\n public Prob(double logP, boolean anyBooleanHereToChooseThisConstructor) {\n this.logP = logP;\n }\n\n /** Returns real probability as a double. */\n public double get() {\n return Math.exp(logP);\n }\n\n @Override\n public String toString() {\n return \"\"+get();\n }\n\n /***************** STATIC METHODS BELOW ********************/\n\n /** Note: returns NaN only when a && b are both NaN/null. */\n public static Prob add(Prob a, Prob b) {\n if (nullOrNaN(a) && nullOrNaN(b)) return new Prob(Double.NaN, dontLogAgain);\n if (nullOrNaN(a)) return copy(b);\n if (nullOrNaN(b)) return copy(a);\n\n double x = Math.max(a.logP, b.logP);\n double y = Math.min(a.logP, b.logP);\n double sum = x + Math.log(1 + Math.exp(y - x));\n return new Prob(sum, dontLogAgain);\n }\n\n /** Note: multiplying by null or NaN produces NaN (repping 0% real prob). */\n public static Prob multiply(Prob a, Prob b) {\n if (nullOrNaN(a) || nullOrNaN(b)) return new Prob(Double.NaN, dontLogAgain);\n return new Prob(a.logP + b.logP, dontLogAgain);\n }\n\n /** Returns true if p is null or NaN. */\n private static boolean nullOrNaN(Prob p) {\n return (p == null || Double.isNaN(p.logP));\n }\n\n /** Returns a new instance with the same value as original. */\n private static Prob copy(Prob original) {\n return new Prob(original.logP, dontLogAgain);\n }\n }\n\n public class StronglyConnectedComponents {\n\n /** Kosaraju's algorithm */\n\n ArrayList<Integer>[] forw;\n ArrayList<Integer>[] bacw;\n\n /** Use: getCount(2, new int[] {1,2}, new int[] {2,1}) */\n public int getCount(int n, int[] mista, int[] minne) {\n forw = new ArrayList[n+1];\n bacw = new ArrayList[n+1];\n for (int i=1; i<=n; i++) {\n forw[i] = new ArrayList<Integer>();\n bacw[i] = new ArrayList<Integer>();\n }\n for (int i=0; i<mista.length; i++) {\n int a = mista[i];\n int b = minne[i];\n forw[a].add(b);\n bacw[b].add(a);\n }\n int count = 0;\n List<Integer> list = new ArrayList<Integer>();\n boolean[] visited = new boolean[n+1];\n for (int i=1; i<=n; i++) {\n dfsForward(i, visited, list);\n }\n visited = new boolean[n+1];\n for (int i=n-1; i>=0; i--) {\n int node = list.get(i);\n if (visited[node]) continue;\n count++;\n dfsBackward(node, visited);\n }\n return count;\n }\n\n public void dfsForward(int i, boolean[] visited, List<Integer> list) {\n if (visited[i]) return;\n visited[i] = true;\n for (int neighbor : forw[i]) {\n dfsForward(neighbor, visited, list);\n }\n list.add(i);\n }\n\n public void dfsBackward(int i, boolean[] visited) {\n if (visited[i]) return;\n visited[i] = true;\n for (int neighbor : bacw[i]) {\n dfsBackward(neighbor, visited);\n }\n }\n }\n\n class DrawGrid {\n\n void draw(boolean[][] d) {\n System.out.print(\" \");\n for (int x=0; x<d[0].length; x++) {\n System.out.print(\" \" + x + \" \");\n }\n System.out.println(\"\");\n for (int y=0; y<d.length; y++) {\n System.out.print(y + \" \");\n for (int x=0; x<d[0].length; x++) {\n System.out.print((d[y][x] ? \"[x]\" : \"[ ]\"));\n }\n System.out.println(\"\");\n }\n }\n\n void draw(int[][] d) {\n int max = 1;\n for (int y=0; y<d.length; y++) {\n for (int x=0; x<d[0].length; x++) {\n max = Math.max(max, (\"\" + d[y][x]).length());\n }\n }\n System.out.print(\" \");\n String format = \"%\" + (max+2) + \"s\";\n for (int x=0; x<d[0].length; x++) {\n System.out.print(String.format(format, x) + \" \");\n }\n format = \"%\" + (max) + \"s\";\n System.out.println(\"\");\n for (int y=0; y<d.length; y++) {\n System.out.print(y + \" \");\n for (int x=0; x<d[0].length; x++) {\n System.out.print(\" [\" + String.format(format, (d[y][x])) + \"]\");\n }\n System.out.println(\"\");\n }\n }\n\n }\n\n class BaseConverter {\n\n /* Palauttaa luvun esityksen kannassa base */\n public String convert(Long number, int base) {\n return Long.toString(number, base);\n }\n\n /* Palauttaa luvun esityksen kannassa baseTo, kun annetaan luku Stringin\u00e4 kannassa baseFrom */\n public String convert(String number, int baseFrom, int baseTo) {\n return Long.toString(Long.parseLong(number, baseFrom), baseTo);\n }\n\n /* Tulkitsee kannassa base esitetyn luvun longiksi (kannassa 10) */\n public long longify(String number, int baseFrom) {\n return Long.parseLong(number, baseFrom);\n }\n }\n\n class Binary implements Comparable<Binary> {\n\n /**\n * Use example: Binary b = new Binary(Long.toBinaryString(53249834L));\n *\n * When manipulating small binary strings, instantiate new Binary(string)\n * When just reading large binary strings, instantiate new Binary(string,true)\n * get(int i) returns a character '1' or '0', not an int.\n */\n\n private boolean[] d;\n private int first; // Starting from left, the first (most remarkable) '1'\n public int length;\n\n\n public Binary(String binaryString) {\n this(binaryString, false);\n }\n public Binary(String binaryString, boolean initWithMinArraySize) {\n length = binaryString.length();\n int size = Math.max(2*length, 1);\n first = length/4;\n if (initWithMinArraySize) {\n first = 0;\n size = Math.max(length, 1);\n }\n d = new boolean[size];\n for (int i=0; i<length; i++) {\n if (binaryString.charAt(i) == '1') d[i+first] = true;\n }\n }\n\n public void addFirst(char c) {\n if (first-1 < 0) doubleArraySize();\n first--;\n d[first] = (c == '1' ? true : false);\n length++;\n }\n\n public void addLast(char c) {\n if (first+length >= d.length) doubleArraySize();\n d[first+length] = (c == '1' ? true : false);\n length++;\n }\n\n private void doubleArraySize() {\n boolean[] bigArray = new boolean[(d.length+1) * 2];\n int newFirst = bigArray.length / 4;\n for (int i=0; i<length; i++) {\n bigArray[i + newFirst] = d[i + first];\n }\n first = newFirst;\n d = bigArray;\n }\n\n public boolean flip(int i) {\n boolean value = (this.d[first+i] ? false : true);\n this.d[first+i] = value;\n return value;\n }\n\n public void set(int i, char c) {\n boolean value = (c == '1' ? true : false);\n this.d[first+i] = value;\n }\n\n public char get(int i) {\n return (this.d[first+i] ? '1' : '0');\n }\n\n @Override\n public int compareTo(Binary o) {\n if (this.length != o.length) return this.length - o.length;\n int len = this.length;\n for (int i=0; i<len; i++) {\n int diff = this.get(i) - o.get(i);\n if (diff != 0) return diff;\n }\n return 0;\n }\n\n @Override\n public String toString() {\n StringBuilder sb = new StringBuilder();\n for (int i=0; i<length; i++) {\n sb.append(d[i+first] ? '1' : '0');\n }\n return sb.toString();\n }\n\n\n }\n\n class BinomialCoefficients {\n /** Total number of K sized unique combinations from pool of size N (unordered)\n N! / ( K! (N - K)! ) */\n\n /** For simple queries where output fits in long. */\n public long biCo(long n, long k) {\n long r = 1;\n if (k > n) return 0;\n for (long d = 1; d <= k; d++) {\n r *= n--;\n r /= d;\n }\n return r;\n }\n\n /** For multiple queries with same n, different k. */\n public long[] precalcBinomialCoefficientsK(int n, int maxK) {\n long v[] = new long[maxK+1];\n v[0] = 1; // nC0 == 1\n for (int i=1; i<=n; i++) {\n for (int j=Math.min(i,maxK); j>0; j--) {\n v[j] = v[j] + v[j-1]; // Pascal's triangle\n }\n }\n return v;\n }\n\n /** When output needs % MOD. */\n public long[] precalcBinomialCoefficientsK(int n, int k, long M) {\n long v[] = new long[k+1];\n v[0] = 1; // nC0 == 1\n for (int i=1; i<=n; i++) {\n for (int j=Math.min(i,k); j>0; j--) {\n v[j] = v[j] + v[j-1]; // Pascal's triangle\n v[j] %= M;\n }\n }\n return v;\n }\n }\n\n class Trie {\n int N;\n int Z;\n int nextFreeId;\n int[][] pointers;\n boolean[] end;\n\n /** maxLenSum = maximum possible sum of length of words */\n public Trie(int maxLenSum, int alphabetSize) {\n this.N = maxLenSum;\n this.Z = alphabetSize;\n this.nextFreeId = 1;\n pointers = new int[N+1][alphabetSize];\n end = new boolean[N+1];\n }\n\n public void addWord(String word) {\n int curr = 0;\n for (int j=0; j<word.length(); j++) {\n int c = word.charAt(j) - 'a';\n int next = pointers[curr][c];\n if (next == 0) {\n next = nextFreeId++;\n pointers[curr][c] = next;\n }\n curr = next;\n }\n end[curr] = true;\n }\n\n public boolean hasWord(String word) {\n int curr = 0;\n for (int j=0; j<word.length(); j++) {\n int c = word.charAt(j) - 'a';\n int next = pointers[curr][c];\n if (next == 0) return false;\n curr = next;\n }\n return end[curr];\n }\n\n }\n\n private class IO extends PrintWriter {\n private InputStreamReader r;\n private static final int BUFSIZE = 1 << 15;\n private char[] buf;\n private int bufc;\n private int bufi;\n private StringBuilder sb;\n\n public IO() {\n super(new BufferedOutputStream(System.out));\n r = new InputStreamReader(System.in);\n\n buf = new char[BUFSIZE];\n bufc = 0;\n bufi = 0;\n sb = new StringBuilder();\n }\n\n /** Print, flush, return nextInt. */\n private int queryInt(String s) {\n io.println(s);\n io.flush();\n return nextInt();\n }\n\n /** Print, flush, return nextLong. */\n private long queryLong(String s) {\n io.println(s);\n io.flush();\n return nextLong();\n }\n\n /** Print, flush, return next word. */\n private String queryNext(String s) {\n io.println(s);\n io.flush();\n return next();\n }\n\n private void fillBuf() throws IOException {\n bufi = 0;\n bufc = 0;\n while(bufc == 0) {\n bufc = r.read(buf, 0, BUFSIZE);\n if(bufc == -1) {\n bufc = 0;\n return;\n }\n }\n }\n\n private boolean pumpBuf() throws IOException {\n if(bufi == bufc) {\n fillBuf();\n }\n return bufc != 0;\n }\n\n private boolean isDelimiter(char c) {\n return c == ' ' || c == '\\t' || c == '\\n' || c == '\\r' || c == '\\f';\n }\n\n private void eatDelimiters() throws IOException {\n while(true) {\n if(bufi == bufc) {\n fillBuf();\n if(bufc == 0) throw new RuntimeException(\"IO: Out of input.\");\n }\n\n if(!isDelimiter(buf[bufi])) break;\n ++bufi;\n }\n }\n\n public String next() {\n try {\n sb.setLength(0);\n\n eatDelimiters();\n int start = bufi;\n\n while(true) {\n if(bufi == bufc) {\n sb.append(buf, start, bufi - start);\n fillBuf();\n start = 0;\n if(bufc == 0) break;\n }\n\n if(isDelimiter(buf[bufi])) break;\n ++bufi;\n }\n\n sb.append(buf, start, bufi - start);\n\n return sb.toString();\n } catch(IOException e) {\n throw new RuntimeException(\"IO.next: Caught IOException.\");\n }\n }\n\n public int nextInt() {\n try {\n int ret = 0;\n\n eatDelimiters();\n\n boolean positive = true;\n if(buf[bufi] == '-') {\n ++bufi;\n if(!pumpBuf()) throw new RuntimeException(\"IO.nextInt: Invalid int.\");\n positive = false;\n }\n\n boolean first = true;\n while(true) {\n if(!pumpBuf()) break;\n if(isDelimiter(buf[bufi])) {\n if(first) throw new RuntimeException(\"IO.nextInt: Invalid int.\");\n break;\n }\n first = false;\n\n if(buf[bufi] >= '0' && buf[bufi] <= '9') {\n if(ret < -214748364) throw new RuntimeException(\"IO.nextInt: Invalid int.\");\n ret *= 10;\n ret -= (int)(buf[bufi] - '0');\n if(ret > 0) throw new RuntimeException(\"IO.nextInt: Invalid int.\");\n } else {\n throw new RuntimeException(\"IO.nextInt: Invalid int.\");\n }\n\n ++bufi;\n }\n\n if(positive) {\n if(ret == -2147483648) throw new RuntimeException(\"IO.nextInt: Invalid int.\");\n ret = -ret;\n }\n\n return ret;\n } catch(IOException e) {\n throw new RuntimeException(\"IO.nextInt: Caught IOException.\");\n }\n }\n\n public long nextLong() {\n try {\n long ret = 0;\n\n eatDelimiters();\n\n boolean positive = true;\n if(buf[bufi] == '-') {\n ++bufi;\n if(!pumpBuf()) throw new RuntimeException(\"IO.nextLong: Invalid long.\");\n positive = false;\n }\n\n boolean first = true;\n while(true) {\n if(!pumpBuf()) break;\n if(isDelimiter(buf[bufi])) {\n if(first) throw new RuntimeException(\"IO.nextLong: Invalid long.\");\n break;\n }\n first = false;\n\n if(buf[bufi] >= '0' && buf[bufi] <= '9') {\n if(ret < -922337203685477580L) throw new RuntimeException(\"IO.nextLong: Invalid long.\");\n ret *= 10;\n ret -= (long)(buf[bufi] - '0');\n if(ret > 0) throw new RuntimeException(\"IO.nextLong: Invalid long.\");\n } else {\n throw new RuntimeException(\"IO.nextLong: Invalid long.\");\n }\n\n ++bufi;\n }\n\n if(positive) {\n if(ret == -9223372036854775808L) throw new RuntimeException(\"IO.nextLong: Invalid long.\");\n ret = -ret;\n }\n\n return ret;\n } catch(IOException e) {\n throw new RuntimeException(\"IO.nextLong: Caught IOException.\");\n }\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n }\n\n void print(Object output) {\n io.println(output);\n }\n\n void done(Object output) {\n print(output);\n done();\n }\n\n void done() {\n io.close();\n throw new RuntimeException(\"Clean exit\");\n }\n\n long min(long... v) {\n long ans = v[0];\n for (int i=1; i<v.length; i++) {\n ans = Math.min(ans, v[i]);\n }\n return ans;\n }\n\n double min(double... v) {\n double ans = v[0];\n for (int i=1; i<v.length; i++) {\n ans = Math.min(ans, v[i]);\n }\n return ans;\n }\n\n int min(int... v) {\n int ans = v[0];\n for (int i=1; i<v.length; i++) {\n ans = Math.min(ans, v[i]);\n }\n return ans;\n }\n\n long max(long... v) {\n long ans = v[0];\n for (int i=1; i<v.length; i++) {\n ans = Math.max(ans, v[i]);\n }\n return ans;\n }\n\n double max(double... v) {\n double ans = v[0];\n for (int i=1; i<v.length; i++) {\n ans = Math.max(ans, v[i]);\n }\n return ans;\n }\n\n int max(int... v) {\n int ans = v[0];\n for (int i=1; i<v.length; i++) {\n ans = Math.max(ans, v[i]);\n }\n return ans;\n }\n\n }\n\n}\n\n\n\n\n", "src_uid": "cb4de190ae26127df6eeb7a1a1db8a6d"} {"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 Rishabh Deep Singh\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 task solver = new task();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class task {\n public void solve(int testNumber, InputReader in, OutputWriter out) {\n long n = in.nextLong();\n if (n > 36) out.println(\"-1\");\n else {\n for (; n > 1; n -= 2) {\n out.print(8);\n }\n if (n != 0) out.print(4);\n }\n }\n\n }\n\n static class InputReader {\n private InputStream stream;\n private byte[] buf = new byte[1024];\n private int curChar;\n private int numChars;\n private InputReader.SpaceCharFilter filter;\n\n public InputReader(InputStream stream) {\n this.stream = stream;\n }\n\n public int read() {\n if (numChars == -1) {\n throw new InputMismatchException();\n }\n if (curChar >= numChars) {\n curChar = 0;\n try {\n numChars = stream.read(buf);\n } catch (IOException e) {\n throw new InputMismatchException();\n }\n if (numChars <= 0) {\n return -1;\n }\n }\n return buf[curChar++];\n }\n\n public 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(Object... objects) {\n for (int i = 0; i < objects.length; i++) {\n if (i != 0) {\n writer.print(' ');\n }\n writer.print(objects[i]);\n }\n }\n\n public void println(Object... objects) {\n print(objects);\n writer.println();\n }\n\n public void close() {\n writer.close();\n }\n\n public void print(int i) {\n writer.print(i);\n }\n\n }\n}\n\n", "src_uid": "0c9973792c1976c5710f88e3520cda4e"} {"source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\npublic class Solution_119A {\n public static void main(String[] args) throws Exception {\n BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));\n String strings[] = reader.readLine().split(\" \");\n int a = Integer.parseInt(strings[0]);\n int b = Integer.parseInt(strings[1]);\n int n = Integer.parseInt(strings[2]);\n\n while(true)\n n = play(b, play(a, n, 1), 0);\n }\n\n public static int play(int a, int n, int code) {\n int gcd = gcd(a, n);\n if (n >= gcd)\n return n - gcd;\n else {\n System.out.println(code);\n System.exit(0);\n }\n return 0;\n }\n\n public static int gcd(int a, int b) {\n int min = a <= b ? a : b;\n\n for (int i = min; i >= 1; i--)\n if (((a % i) == 0) && ((b % i) == 0))\n return i;\n return 1;\n }\n}\n", "src_uid": "0bd6fbb6b0a2e7e5f080a70553149ac2"} {"source_code": "import java.io.BufferedReader;\nimport java.io.BufferedWriter;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.StringTokenizer;\n\npublic class Edu_48G {\n\n\tstatic int N;\n\tstatic long X;\n\tstatic long Y;\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\tStringTokenizer inputData = new StringTokenizer(reader.readLine());\n\t\tN = Integer.parseInt(inputData.nextToken());\n\t\tX = Long.parseLong(inputData.nextToken());\n\t\tY = Long.parseLong(inputData.nextToken());\n\n\t\tif (Y % X != 0) {\n\t\t\tprinter.println(0);\n\t\t\tprinter.close();\n\t\t\treturn;\n\t\t}\n\n\t\tlong[] fact = new long[20];\n\t\tint nF = 0;\n\n\t\tlong rem = Y / X;\n\t\tif (rem % 2 == 0) {\n\t\t\trem /= 2;\n\t\t\tfact[nF++] = 2;\n\t\t\twhile (rem % 2 == 0) {\n\t\t\t\trem /= 2;\n\t\t\t}\n\t\t}\n\n\t\tfor (int i = 3; i <= 1_000_000; i += 2) {\n\t\t\tif (rem % i == 0) {\n\t\t\t\trem /= i;\n\t\t\t\tfact[nF++] = i;\n\t\t\t\twhile (rem % i == 0) {\n\t\t\t\t\trem /= i;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// yRem may or may not be prime\n\n\t\tArrayList<Long> A = new ArrayList<>();\n\t\tArrayList<Long> B = new ArrayList<>();\n\n\t\tinputData = new StringTokenizer(reader.readLine());\n\t\tfor (int i = 0; i < N; i++) {\n\t\t\tlong c = Long.parseLong(inputData.nextToken());\n\t\t\tlong cGCD = gcd(c, rem);\n\t\t\tif (cGCD != 1 && cGCD != rem) {\n\t\t\t\tfact[nF++] = cGCD;\n\t\t\t\trem /= cGCD;\n\t\t\t\tfact[nF++] = rem;\n\t\t\t\trem = 1;\n\t\t\t}\n\t\t\tif (c % X == 0) {\n\t\t\t\tA.add(c);\n\t\t\t}\n\t\t\tif (Y % c == 0) {\n\t\t\t\tB.add(c);\n\t\t\t}\n\t\t}\n\n\t\tif (rem != 1) {\n\t\t\tfact[nF++] = rem;\n\t\t}\n\n\t\tint nSets = 1 << nF;\n\t\tlong[] aSet = new long[nSets];\n\t\tlong[] bSet = new long[nSets];\n\n\t\tfor (long c : A) {\n\t\t\tlong cR = c / X;\n\t\t\tint cSet = 0;\n\n\t\t\tfor (int i = 0; i < nF; i++) {\n\t\t\t\tif (cR % fact[i] == 0) {\n\t\t\t\t\tcSet |= (1 << i);\n\t\t\t\t}\n\t\t\t}\n\t\t\taSet[cSet]++;\n\t\t}\n\n\t\tfor (long c : B) {\n\t\t\tlong cR = Y / c;\n\t\t\tint cSet = 0;\n\n\t\t\tfor (int i = 0; i < nF; i++) {\n\t\t\t\tif (cR % fact[i] == 0) {\n\t\t\t\t\tcSet |= (1 << i);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbSet[cSet]++;\n\t\t}\n\n\t\tif (nF == 0) {\n\t\t\tprinter.println(A.size() * B.size());\n\t\t\tprinter.close();\n\t\t\treturn;\n\t\t}\n\n\t\tlong[][] aSetS = new long[nF][nSets];\n\n\t\tfor (int cSet = 0; cSet < nSets; cSet++) {\n\t\t\tif ((cSet & 1) != 0) {\n\t\t\t\taSetS[0][cSet] = aSet[cSet] + aSet[cSet ^ 1];\n\t\t\t} else {\n\t\t\t\taSetS[0][cSet] = aSet[cSet];\n\t\t\t}\n\t\t}\n\n\t\tfor (int i = 1; i < nF; i++) {\n\t\t\tfor (int cSet = 0; cSet < nSets; cSet++) {\n\t\t\t\tif ((cSet & (1 << i)) != 0) {\n\t\t\t\t\taSetS[i][cSet] = aSetS[i - 1][cSet] + aSetS[i - 1][cSet ^ (1 << i)];\n\t\t\t\t} else {\n\t\t\t\t\taSetS[i][cSet] = aSetS[i - 1][cSet];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tint mask = nSets - 1;\n\n\t\tlong ans = 0;\n\t\tfor (int cSet = 0; cSet < nSets; cSet++) {\n\t\t\tint comp = mask ^ cSet;\n\t\t\tans += bSet[cSet] * aSetS[nF - 1][comp];\n\t\t}\n\n\t\tprinter.println(ans);\n\t\tprinter.close();\n\t}\n\n\tstatic long gcd(long a, long b) {\n\t\treturn b == 0 ? a : gcd(b, a % b);\n\t}\n}\n", "src_uid": "8d43a542d5bf79d15926c4a6a5ff608f"} {"source_code": "\n\nimport java.util.Scanner;\n\npublic class maths {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tString a= sc.nextLine();\n\t\tint n = a.length();\n\t\tint x=0;\n\t\tint y=0;\n\t\tint z=0;\n\t\tfor(int i =1 ; i<=n; i+=2) {\n\t\t\tchar k = a.charAt(i-1);\n\t\t\tif(k=='1') {\n\t\t\t\tx++;\n\t\t\t}\n\t\t\telse if(k=='2') {\n\t\t\t\ty++;\n\t\t\t}\n\t\t\telse if(k=='3') {\n\t\t\t\tz++;\n\t\t\t}\n\t\t}\n \n \tfor(int j=1;j<x;j++) {\n \n \tSystem.out.print(\"1+\");\n\t}\n if(x>0) {\n \tSystem.out.print(\"1\");\n \n for(int m=1;m<=y;m++) {\n \tSystem.out.print(\"+2\");\n \n }\n }\n else if(x==0 && y!=0) {\n \t for(int m=1;m<y;m++) {\n \tSystem.out.print(\"2+\");\n }\n \t \n \t System.out.print(\"2\");\n \n \n }\n if(x >0 || y>0) {\n \tfor(int l=1;l<=z;l++) {\n \t\tSystem.out.print(\"+3\");\n }\n \t\n \n }\n else if(x+y==0) {\n \t for(int l=1;l<z;l++) {\n \tSystem.out.print(\"3+\");\n }\n \t \n \t System.out.print(\"3\");\n \n \n }\n \n\t\t}\n\t}\n\t\t\n\t\n\n\n", "src_uid": "76c7312733ef9d8278521cf09d3ccbc8"} {"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 private static final int mod = 1000000007,MAX = 2000*1000 + 10;\n private static Integer [] P = new Integer[2000*1000 + 1];\n private static int [] prime,mu;\n\n private static int add(int a,int b) {\n a += b;\n if (a >= mod) a -= mod;\n if (a < 0) a += mod;\n return a;\n }\n private static int mul(int a,int b) {\n return (int)((a*(long)b)%mod);\n }\n\n private static int powmod(int x,int p) {\n if (p == 0) return 1;\n if (P[x] != null) return P[x];\n int y = 1,t = x;\n for (;p > 1;p >>= 1) {\n if (p%2 == 1) y = mul(x,y);\n x = mul(x,x);\n }\n return P[t] = mul(x,y);\n }\n\n private static void sieve(){\n prime = new int[MAX];\n mu = new int[MAX];\n mu[1] = 1;\n for (int i = 2;i < MAX;i++) {\n if (prime[i] == 0) {\n prime[i] = i;\n long j = i * (long) i;\n while (j < MAX) {\n prime[(int) j] = i;\n j += i;\n }\n }\n int p = prime[i],n = i,e = 0;\n while (n%p == 0) {\n e++;\n n /= p;\n }\n if (e > 1) mu[i] = 0;\n else mu[i] = mu[n] * -1;\n }\n }\n // private static int bf(int n,int k) {\n// int ret = 0;\n// for (int i = 1;i <= n;i++) {\n// ret += mu(i) * powmod(n / i, k);\n// }\n// return ret;\n// }\n public static void main(String[] args) throws Exception{\n IO io = new IO(null,null);\n sieve();\n int n = io.getNextInt(),K = io.getNextInt();\n int [] f = new int[K + 1];\n for (int k = 1;k <= K;k++) {\n int m = mu[k];\n for (int c = k;c <= K;) {\n int e = c + k - 1;\n int tmp = m * powmod(c/k,n);\n f[c] = add(f[c],tmp);\n if (e < K) f[e+1] = add(f[e+1],-tmp);\n c = e+1;\n }\n }\n\n for (int i = 1;i < K;i++)\n f[i + 1] = add(f[i],f[i + 1]);\n\n// System.err.println(Arrays.toString(f));\n int ans = 0;\n for (int i = 1;i <= K;i++)\n ans = add(ans,(i^f[i])%mod);\n io.println(ans);\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", "src_uid": "122c08aa91c9a9d6a151ee6e3d0662fa"} {"source_code": "import java.util.Scanner;\n\npublic class Sandia{\n public static void main(String[] args){\n Scanner reader = new Scanner(System.in);\n\n int n = reader.nextInt();\n if (n!=2){\n if (n%2==0){\n System.out.println(\"YES\");\n }\n else{\n System.out.println(\"NO\");\n }\n }\n else{\n System.out.println(\"NO\");\n } \n }\n}\n// 1502674216237\n", "src_uid": "230a3c4d7090401e5fa3c6b9d994cdf2"} {"source_code": "import java.util.*;\n\npublic class Main{\n \n public static void main(String args[])\n { \n Scanner sc=new Scanner(System.in);\n int n=sc.nextInt();\n HashMap<Integer,Integer> mp=new HashMap<Integer,Integer>();\n while(mp.get(n)==null)\n { \n mp.put(n, 1);\n n=n+1;\n while(n%10==0) n/=10;\n }\n System.out.println(mp.size()) ;\n \n\n\n }\n}", "src_uid": "055fbbde4b9ffd4473e6e716da6da899"} {"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 neuivn\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 N = in.nextInt();\n int M = in.nextInt();\n\n int leftSide = M;\n int rightSide = N - M + 1;\n\n if (leftSide > rightSide) {\n if (leftSide - 1 <= 0) {\n out.println(M);\n return;\n } else {\n out.println(M - 1);\n }\n } else if (rightSide > leftSide) {\n if (M + 1 > N) {\n out.println(M);\n } else out.println(M + 1);\n } else {\n if (M - 1 <= 0) {\n out.println(1);\n } else out.println(M - 1);\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\n", "src_uid": "f6a80c0f474cae1e201032e1df10e9f7"} {"source_code": "import java.util.*;\n\npublic class Main {\n public static void main(String [] argv){\n Scanner in = new Scanner(System.in);\n String s1 = \"^\\\\w{1,16}@\\\\w{1,16}(\\\\.\\\\w{1,16})*(\\\\/\\\\w{1,16})?$\";\n String s;\n while(in.hasNext())\n {\n s = in.next();\n if(s.matches(s1) == true)\n System.out.println(\"YES\");\n else\n System.out.println(\"NO\");\n }\n in.close();\n }\n}", "src_uid": "2a68157e327f92415067f127feb31e24"} {"source_code": "import java.util.Scanner;\n\npublic class NewYearAndDays\n{\n public static void main(String [] args)\n {\n Scanner input = new Scanner(System.in);\n String str = input.nextLine();\n\n input.close();\n\n StringBuffer num = new StringBuffer();\n\n if(Character.isDigit(str.charAt(0)) && Character.isDigit(str.charAt(1)))\n num.append(str.charAt(0)).append(str.charAt(1));\n else\n num.append(str.charAt(0));\n \n int number = Integer.parseInt(num.toString());\n\n if(str.contains(\"month\"))\n {\n if(number <= 29)\n System.out.println(12);\n else if(number == 30)\n System.out.println(11);\n else\n System.out.println(7); \n }\n else\n {\n if(number == 5 || number == 6)\n System.out.println(53);\n else\n System.out.println(52); \n }\n }\n}", "src_uid": "9b8543c1ae3666e6c163d268fdbeef6b"} {"source_code": "import java.util.*;\npublic class TheNumberofPostion {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n int n = in.nextInt();\n int a = in.nextInt();\n int b = in.nextInt();\n int sol = 0; \n for(int i=1; i<=n ; i++)\n {\n if((i-1)>=a && (n-i)<=b)\n sol++;\n }\n System.out.println(sol);\n }\n}\n", "src_uid": "51a072916bff600922a77da0c4582180"} {"source_code": "import java.util.Scanner;\npublic class mainClass {\n\n public static void main(String[] args) {\n int a ,b;\n \n Scanner in = new Scanner(System.in);\n a=in.nextInt();\n b= in.nextInt();\n System.out.println(Math.min(a,b)+\" \"+Math.abs(a-b)/2);\n \n }\n\n}", "src_uid": "775766790e91e539c1cfaa5030e5b955"} {"source_code": "import static java.lang.System.in;\nimport static java.lang.System.out;\n\nimport java.io.*;\nimport java.util.*;\n\npublic class C318 {\n\tstatic final double EPS = 1e-10;\n\tstatic final double INF = 1 << 31;\n\tstatic final double PI = Math.PI;\n\n\tpublic static Scanner sc = new Scanner(in);\n\tStringBuilder sb = new StringBuilder();\n\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n\tpublic long run() throws IOException {\n\t\tString input;\n\t\tString[] inputArray;\n\t\tinput = br.readLine();\n\t\tinputArray = input.split(\" \");\n\t\tlong x = Long.valueOf(inputArray[0]);\n\t\tlong y = Long.valueOf(inputArray[1]);\n\t\tlong m = Long.valueOf(inputArray[2]);\n\t\tlong temp;\n\t\tif (x>y) { temp = x; x = y; y = temp; }\n\t\tif (y>=m) return 0;\n\t\tif (y<=0) return -1;\n\t\tlong ans=0;\n\t\tif (x<0){\n\t\t\tlong count =(-x)/y;\n\t\t\tans+=count;\n\t\t\tx+=count*y;\n\t\t\t\n\t\t}\n\t\tdo{\n\t\t\ttemp = x;\n\t\t\tx = y;\n\t\t\ty = temp +y;\n\t\t\tif (x>y) { temp = x; x = y; y = temp; }\n\t\t\tans++;\n\t\t}while (y<m);\n\t\treturn ans;\n\t}\n\n\tpublic static void main(String[] args) throws IOException {\n\t\tlong ans = new C318().run();\n\t\tln(ans);\n\t}\n\tpublic static void ln(Object obj) {\n\t\tout.println(obj);\n\t}\n}\n", "src_uid": "82026a3c3d9a6bda2e2ac6e14979d821"} {"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 CPointsLinesAndReadyMadeTitles solver = new CPointsLinesAndReadyMadeTitles();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class CPointsLinesAndReadyMadeTitles {\n public void solve(int testNumber, FastInput in, FastOutput out) {\n int n = in.readInt();\n Point[] pts = new Point[n];\n for (int i = 0; i < n; i++) {\n pts[i] = new Point();\n pts[i].x = in.readInt();\n pts[i].y = in.readInt();\n }\n\n IntegerHashMap x = new IntegerHashMap(n, false);\n IntegerHashMap y = new IntegerHashMap(n, false);\n DSU dsu = new DSU(n);\n for (int i = 0; i < n; i++) {\n if (x.containKey(pts[i].x)) {\n dsu.merge(x.get(pts[i].x), i);\n }\n if (y.containKey(pts[i].y)) {\n dsu.merge(y.get(pts[i].y), i);\n }\n x.put(pts[i].x, i);\n y.put(pts[i].y, i);\n }\n\n IntegerMultiWayStack xStack = new IntegerMultiWayStack(n, n);\n IntegerMultiWayStack yStack = new IntegerMultiWayStack(n, n);\n for (int i = 0; i < n; i++) {\n xStack.addLast(dsu.find(i), pts[i].x);\n yStack.addLast(dsu.find(i), pts[i].y);\n }\n IntegerList xList = new IntegerList(n);\n IntegerList yList = new IntegerList(n);\n\n Modular mod = new Modular(1e9 + 7);\n Combination comb = new Combination(2 * n, mod);\n int ans = 1;\n for (int i = 0; i < n; i++) {\n if (dsu.find(i) != i) {\n continue;\n }\n xList.clear();\n yList.clear();\n xList.addAll(xStack.iterator(i));\n yList.addAll(yStack.iterator(i));\n xList.unique();\n yList.unique();\n\n int line = xList.size() + yList.size();\n int num = dsu.size[i];\n int local = 0;\n for (int j = 0; j <= num; j++) {\n local = mod.plus(local, comb.combination(line, j));\n }\n\n ans = mod.mul(ans, local);\n }\n\n out.println(ans);\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 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 public int fact(int n) {\n return fact[n];\n }\n\n public int invFact(int n) {\n return inv[n];\n }\n\n }\n\n static interface IntCombination {\n }\n\n static class 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 IntegerList implements Cloneable {\n private int size;\n private int cap;\n private int[] data;\n private static final int[] EMPTY = new int[0];\n\n public IntegerList(int cap) {\n this.cap = cap;\n if (cap == 0) {\n data = EMPTY;\n } else {\n data = new int[cap];\n }\n }\n\n public void addAll(IntegerIterator iterator) {\n while (iterator.hasNext()) {\n add(iterator.next());\n }\n }\n\n public IntegerList(IntegerList list) {\n this.size = list.size;\n this.cap = list.cap;\n this.data = Arrays.copyOf(list.data, size);\n }\n\n public IntegerList() {\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 public void add(int x) {\n ensureSpace(size + 1);\n data[size++] = x;\n }\n\n public void addAll(int[] 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(IntegerList list) {\n addAll(list.data, 0, list.size);\n }\n\n public void sort() {\n if (size <= 1) {\n return;\n }\n Randomized.shuffle(data, 0, size);\n Arrays.sort(data, 0, size);\n }\n\n public void unique() {\n if (size <= 1) {\n return;\n }\n\n sort();\n int wpos = 1;\n for (int i = 1; i < size; i++) {\n if (data[i] != data[wpos - 1]) {\n data[wpos++] = data[i];\n }\n }\n size = wpos;\n }\n\n public int size() {\n return size;\n }\n\n public int[] 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 IntegerList)) {\n return false;\n }\n IntegerList other = (IntegerList) 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 + Integer.hashCode(data[i]);\n }\n return h;\n }\n\n public IntegerList clone() {\n IntegerList ans = new IntegerList();\n ans.addAll(this);\n return ans;\n }\n\n }\n\n static interface IntegerIterator {\n boolean hasNext();\n\n int next();\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 DSU {\n protected int[] p;\n protected int[] rank;\n int[] size;\n\n public DSU(int n) {\n p = new int[n];\n rank = new int[n];\n size = new int[n];\n reset();\n }\n\n public final void reset() {\n for (int i = 0; i < p.length; i++) {\n p[i] = i;\n rank[i] = 0;\n size[i] = 1;\n }\n }\n\n public final int find(int a) {\n if (p[a] == p[p[a]]) {\n return p[a];\n }\n return p[a] = find(p[a]);\n }\n\n public final void merge(int a, int b) {\n a = find(a);\n b = find(b);\n if (a == b) {\n return;\n }\n if (rank[a] == rank[b]) {\n rank[a]++;\n }\n\n if (rank[a] < rank[b]) {\n int tmp = a;\n a = b;\n b = tmp;\n }\n\n size[a] += size[b];\n p[b] = a;\n }\n\n }\n\n static class SequenceUtils {\n public static boolean equal(int[] a, int al, int ar, int[] b, int bl, int br) {\n if ((ar - al) != (br - bl)) {\n return false;\n }\n for (int i = al, j = bl; i <= ar; i++, j++) {\n if (a[i] != b[j]) {\n return false;\n }\n }\n return true;\n }\n\n }\n\n static class Randomized {\n 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 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 public int combination(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 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 Point {\n int x;\n int y;\n\n }\n\n static class IntegerHashMap {\n private int[] slot;\n private int[] next;\n private int[] keys;\n private int[] values;\n private int alloc;\n private boolean[] removed;\n private int mask;\n private int size;\n private boolean rehash;\n private Hasher hasher = new Hasher();\n\n public IntegerHashMap(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 int[cap + 1];\n values = new int[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(int x) {\n return hasher.hash(x);\n }\n\n public void put(int x, int y) {\n put(x, y, true);\n }\n\n public void put(int x, int 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 boolean containKey(int x) {\n int h = hash(x);\n int s = h & mask;\n if (slot[s] == 0) {\n return false;\n }\n return keys[findIndexOrLastEntry(s, x)] == x;\n }\n\n public int getOrDefault(int x, int 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 int get(int x) {\n return getOrDefault(x, 0);\n }\n\n private int findIndexOrLastEntry(int s, int 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 IntegerEntryIterator iterator() {\n return new IntegerEntryIterator() {\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 int getEntryKey() {\n return keys[readIndex];\n }\n\n\n public int 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 IntegerEntryIterator 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 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 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 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 interface IntegerEntryIterator {\n boolean hasNext();\n\n void next();\n\n int getEntryKey();\n\n int getEntryValue();\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 Hasher {\n private long time = System.nanoTime() + System.currentTimeMillis();\n\n private int shuffle(long x) {\n x += time;\n x += 0x9e3779b97f4a7c15L;\n x = (x ^ (x >>> 30)) * 0xbf58476d1ce4e5b9L;\n x = (x ^ (x >>> 27)) * 0x94d049bb133111ebL;\n return (int) (x ^ (x >>> 31));\n }\n\n public int hash(int x) {\n return shuffle(x);\n }\n\n }\n}\n\n", "src_uid": "8781003d9eea51a509145bc6db8b609c"} {"source_code": "import java.util.*;public class HelloWorld{ public static void main(String []args){Scanner aa = new Scanner(System.in);long s = aa.nextLong(), x=aa.nextLong(),y=aa.nextLong();System.out.print((s-x)+(s-y) >= (x-1)+(y-1)?\"White\":\"Black\");}}", "src_uid": "b8ece086b35a36ca873e2edecc674557"} {"source_code": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Fraction {\n\n\tpublic static int fpb(int numerator, int denominator){\n\t\tint fpb = denominator % numerator;\n \n\t\twhile (fpb != 0) {\n\t\t\tnumerator = denominator;\n\t\t\tdenominator = fpb;\n\t\t\tfpb = numerator % denominator;\n\t\t}\n\n\t\treturn denominator;\n\t}\n\n\tpublic static void main(String[] args){\n\t\t// a + b = n\n\t\t// a < b\n\t\t// FEB a & b = 1\n\n\t\t// declare attribute\n\t\tint inputValue;\n\t\tint numerator = 0;\n\t\tint denominator = 0;\n\n\t\tint sum;\n\t\tint feb;\t\n\t\tint fixNumerator[];\n\t\tint fixDemoninator[];\n\t\tint lastIndex = 0;\n\n\t\t// declare object\t\n\t\tScanner scanner = new Scanner(System.in);\n\n\t\tinputValue = scanner.nextInt();\n\n\t\tfixNumerator = new int[inputValue];\n\t\tfixDemoninator = new int[inputValue];\n\n\t\tfor(int i=1; i<=inputValue; i++){\n\t\t\tnumerator = i;\n\t\t\tdenominator = inputValue;\n\n\t\t\tsum = numerator + denominator;\n\t\t\tfeb = denominator / numerator;\n\n\t\t\twhile(i != inputValue){\n\t\t\t\tif(sum < inputValue){\n\t\t\t\t\tnumerator += 1;\n\t\t\t\t}else if(sum == inputValue){\n\t\t\t\t\tnumerator += 1;\n\t\t\t\t\tdenominator -= 1;\n\t\t\t\t}else if(sum > inputValue){\n\t\t\t\t\tdenominator -= 1;\n\t\t\t\t}\t\n\n\t\t\t\tsum = numerator + denominator;\n\t\t\t\tfeb = (numerator == 1 && inputValue <= 10) ? 1 : fpb(numerator, denominator);\n\n\t\t\t\tif((sum == inputValue) && (numerator < denominator) && (feb == 1)){\n\t\t\t\t\tlastIndex = i;\n\n\t\t\t\t\tfixNumerator[i] = numerator;\n\t\t\t\t\tfixDemoninator[i] = denominator;\n\t\t\t\t}\n\n\t\t\t\ti++;\t\t\t\n\t\t\t}\n\t\t}\n\n\t\tif(fixNumerator.length > 0 ) System.out.println(fixNumerator[lastIndex] + \" \" +fixDemoninator[lastIndex]);\n\t\telse System.out.println(\"Oops something error with the code!!!\");\t\t\t\n\t}\n\n}", "src_uid": "0af3515ed98d9d01ce00546333e98e77"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\nimport java.util.StringTokenizer;\npublic class UltraFastMathematician {\n\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\t\t// Problem https://codeforces.com/problemset/problem/61/A\n\t\t// For more solutions check https://github.com/jontiboss\n\t\tReader reader = new Reader();\n\t\tString inputOne = reader.next();\n\t\tBigInteger binary1 = new BigInteger(inputOne,2);\n\t\tBigInteger binary2 = new BigInteger(reader.next(),2);\n\t\t//xor the two values.\n\t\tbinary1 = binary1.xor(binary2);\n\t\tString answer = binary1.toString(2);\n\t\t//add padding zeros\n\t\tString padds = BigInteger.ONE.shiftLeft(inputOne.length()-answer.length()).toString(2);\n\t\tSystem.out.println(padds.substring(1)+answer);\n\t}\n\tstatic class Reader \n\t{ \n\t\tBufferedReader br; \n\t\tStringTokenizer st; \n\n\t\tpublic Reader() \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\t}\n}\n", "src_uid": "3714b7596a6b48ca5b7a346f60d90549"} {"source_code": "import java.util.Scanner;\npublic class Main {\n\n public static void main(String[] args) {\n Scanner v = new Scanner(System.in);\n int n = v.nextInt();\n String cop = v.next();\n int[] a = new int[n];\n for (int p = 0; p < n; p++) {\n a[p] = Integer.parseInt(String.valueOf(cop.charAt(p)));\n }\n int s = 0, k, p, i = 0;\n while (i != n - 1) {\n s = s + a[i];\n i++;\n k = 0;\n p = i;\n while (p <= n-1) {\n\n\n k = k + a[p];\n if (k == s) {\n if (p < n - 1) {\n if (a[p+1] > 0) {\n // System.out.println(p);\n k = 0;\n }\n } else {\n System.out.println(\"YES\");\n System.exit(0);\n }\n }\n p++;\n\n }\n }\n System.out.println(\"NO\");\n }\n}", "src_uid": "410296a01b97a0a39b6683569c84d56c"} {"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 C_Round_643_Div2 {\n public static long MOD = 1000000007;\n\n\n public static void main(String[] args) throws FileNotFoundException {\n // PrintWriter out = new PrintWriter(new FileOutputStream(new File(\n // \"output.txt\")));\n PrintWriter out = new PrintWriter(System.out);\n Scanner in = new Scanner();\n int[] data = new int[4];\n for (int i = 0; i < data.length; i++) {\n data[i] = in.nextInt();\n }\n long result = 0;\n for (int i = Integer.max(data[2], data[0] + data[1]); i <= data[1] + data[2]; i++) {\n int st = data[0];\n int ed = data[1];\n int min = Integer.max(data[0], i - data[2]);\n\n int max = Integer.min(i - data[1], data[1]);\n //System.out.println(min + \" \" + max + \" \" + i);\n if (max >= min) {\n long a = (max - min + 1);\n long b = Integer.min(i - 1, data[3]) - data[2] + 1;\n result += a * b;\n }\n }\n out.println(result);\n out.close();\n }\n\n\n public static int[] KMP(String val) {\n int i = 0;\n int j = -1;\n int[] result = new int[val.length() + 1];\n result[0] = -1;\n while (i < val.length()) {\n while (j >= 0 && val.charAt(j) != val.charAt(i)) {\n j = result[j];\n }\n j++;\n i++;\n result[i] = j;\n }\n return result;\n\n }\n\n public static boolean nextPer(int[] data) {\n int i = data.length - 1;\n while (i > 0 && data[i] < data[i - 1]) {\n i--;\n }\n if (i == 0) {\n return false;\n }\n int j = data.length - 1;\n while (data[j] < data[i - 1]) {\n j--;\n }\n int temp = data[i - 1];\n data[i - 1] = data[j];\n data[j] = temp;\n Arrays.sort(data, i, data.length);\n return true;\n }\n\n public static int digit(long n) {\n int result = 0;\n while (n > 0) {\n n /= 10;\n result++;\n }\n return result;\n }\n\n public static double dist(long a, long b, long x, long y) {\n double val = (b - a) * (b - a) + (x - y) * (x - y);\n val = Math.sqrt(val);\n double other = x * x + a * a;\n other = Math.sqrt(other);\n return val + other;\n\n }\n\n public static class Point implements Comparable<Point> {\n\n int x, y;\n\n public Point(int start, int end) {\n this.x = start;\n this.y = end;\n }\n\n @Override\n public int hashCode() {\n int hash = 5;\n hash = 47 * hash + this.x;\n hash = 47 * hash + this.y;\n return hash;\n }\n\n @Override\n public boolean equals(Object obj) {\n if (obj == null) {\n return false;\n }\n if (getClass() != obj.getClass()) {\n return false;\n }\n final Point other = (Point) obj;\n if (this.x != other.x) {\n return false;\n }\n if (this.y != other.y) {\n return false;\n }\n return true;\n }\n\n @Override\n public int compareTo(Point o) {\n return Integer.compare(x, o.x);\n }\n }\n\n public static class FT {\n\n long[] data;\n\n FT(int n) {\n data = new long[n];\n }\n\n public void update(int index, long value) {\n while (index < data.length) {\n data[index] += value;\n index += (index & (-index));\n }\n }\n\n public long get(int index) {\n long result = 0;\n while (index > 0) {\n result += data[index];\n index -= (index & (-index));\n }\n return result;\n\n }\n }\n\n public static long gcd(long a, long b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n public static long pow(long a, int b) {\n if (b == 0) {\n return 1;\n }\n if (b == 1) {\n return a;\n }\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\n static class Scanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n public Scanner() throws FileNotFoundException {\n // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));\n br = new BufferedReader(new InputStreamReader(System.in));\n // br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(\"input.txt\"))));\n }\n\n public String next() {\n\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n return st.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public String nextLine() {\n st = null;\n try {\n return br.readLine();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n\n public boolean endLine() {\n try {\n String next = br.readLine();\n while (next != null && next.trim().isEmpty()) {\n next = br.readLine();\n }\n if (next == null) {\n return true;\n }\n st = new StringTokenizer(next);\n return st.hasMoreTokens();\n } catch (Exception e) {\n throw new RuntimeException();\n }\n }\n }\n}", "src_uid": "4f92791b9ec658829f667fcea1faee01"} {"source_code": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\npublic class D {\n\tpublic static void main(String[]args)throws IOException,NumberFormatException{\n\t\tBufferedReader bf =new BufferedReader(new InputStreamReader(System.in));\n\t\tint n=5;\n\t\tString s=bf.readLine();\n\t\tString[]sa=s.split(\" \");\n\t\tLong []arr=new Long[n];\n\t\tfor(int i=0;i<n;i++){\n\t\t\tarr[i]=Long.parseLong(sa[i]);\n\t\t}\n\t\tlong d=arr[0];\n\t\tlong k=arr[1];\n\t\tlong a=arr[2];\n\t\tlong b=arr[3];\n\t\tlong t=arr[4];\n\t\tlong total=Math.min(k, d)*a;\n\t\td-=k;\n\t\tif(d>0){\n\t\t\tif(a*k+t<=k*b){\n\t\t\t\tlong r=d/k;\n\t\t\t\ttotal+=(a*k+t)*r;\n\t\t\t\td%=k;\n\t\t\t\ttotal+=Math.min(d*b, t+d*a);\n\t\t\t}else\n\t\t\t\ttotal+=d*b;\n\t\t}\n\t\tSystem.out.println(total);\n\t}\n}\n", "src_uid": "359ddf1f1aed9b3256836e5856fe3466"} {"source_code": "import java.util.HashMap;\nimport java.util.Map;\nimport java.util.Scanner;\n//Amjad's method.\npublic class Main {\n static Map <Character, String> map = new HashMap<Character, String>();\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n map.put('0', \"O-|-OOOO\");\n map.put('1', \"O-|O-OOO\");\n map.put('2', \"O-|OO-OO\");\n map.put('3', \"O-|OOO-O\");\n map.put('4', \"O-|OOOO-\");\n map.put('5', \"-O|-OOOO\");\n map.put('6', \"-O|O-OOO\");\n map.put('7', \"-O|OO-OO\");\n map.put('8', \"-O|OOO-O\");\n map.put('9', \"-O|OOOO-\");\n String temp = scanner.nextLine();\n for(int i = temp.length() - 1; i >= 0; i --){\n System.out.println(map.get(temp.charAt(i)));\n }\n }\n}", "src_uid": "c2e3aced0bc76b6484360563355d23a7"} {"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<n; i++)\n\t\t\tarr[i] = in.nextInt();\n\t\t\n\t\tArrays.sort(arr);\n\t\tarr = reverseOrder(arr);\n\t\t\n\t\tint[] sums = new int[n];\n\t\tsums[0] = arr[0];\n\t\tfor (int i=1; i<n; i++)\n\t\t\tsums[i] = sums[i-1] + arr[i];\n\t\t\n\t\tif (m > 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\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 using = numUsed - prevUsed;\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] - using*sub;\n\t\t\telse if (pos > prevUsed) {\n\t\t\t\tint index = prevUsed + (using - (numUsed - pos) - 1);\n\t\t\t\ttot += (sums[index] - sums[prevUsed-1]) - (using - (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<arr.length; i++)\n\t\t\tnewArr[i] = arr[arr.length-1-i];\n\t\treturn newArr;\n\t}\n\n\tstatic class InputReader {\n\t\tpublic BufferedReader br;\n\t\tpublic StringTokenizer st;\n\t\t\n\t\tpublic InputReader() {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tst = null;\n\t\t}\n\t\t\n\t\tpublic String next() {\n\t\t\twhile (st == null || !st.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\t\t}\n\t\t\t\tcatch (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\t\t\n\t\tpublic int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t}\n}", "src_uid": "acb8a57c8cfdb849a55fa65aff86628d"} {"source_code": "//package ecr012;\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 F3 {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tpublic static int[] sieveEratosthenes(int n) {\n\t\tif (n <= 32) {\n\t\t\tint[] primes = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 };\n\t\t\tfor (int i = 0; i < primes.length; i++) {\n\t\t\t\tif (n < primes[i]) {\n\t\t\t\t\treturn Arrays.copyOf(primes, i);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn primes;\n\t\t}\n\n\t\tint u = n + 32;\n\t\tdouble lu = Math.log(u);\n\t\tint[] ret = new int[(int) (u / lu + u / lu / lu * 1.5)];\n\t\tret[0] = 2;\n\t\tint pos = 1;\n\n\t\tint[] isnp = new int[(n + 1) / 32 / 2 + 1];\n\t\tint sup = (n + 1) / 32 / 2 + 1;\n\n\t\tint[] tprimes = { 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 };\n\t\tfor (int tp : tprimes) {\n\t\t\tret[pos++] = tp;\n\t\t\tint[] ptn = new int[tp];\n\t\t\tfor (int i = (tp - 3) / 2; i < tp << 5; i += tp)\n\t\t\t\tptn[i >> 5] |= 1 << (i & 31);\n\t\t\tfor (int j = 0; j < sup; j += tp) {\n\t\t\t\tfor (int i = 0; i < tp && i + j < sup; i++) {\n\t\t\t\t\tisnp[j + i] |= ptn[i];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// 3,5,7\n\t\t// 2x+3=n\n\t\tint[] magic = { 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, 31, 22, 28, 18, 26, 10, 7, 12, 21, 17,\n\t\t\t\t9, 6, 16, 5, 15, 14 };\n\t\tint h = n / 2;\n\t\tfor (int i = 0; i < sup; i++) {\n\t\t\tfor (int j = ~isnp[i]; j != 0; j &= j - 1) {\n\t\t\t\tint pp = i << 5 | magic[(j & -j) * 0x076be629 >>> 27];\n\t\t\t\tint p = 2 * pp + 3;\n\t\t\t\tif (p > n)\n\t\t\t\t\tbreak;\n\t\t\t\tret[pos++] = p;\n\t\t\t\tif ((long) p * p > n)\n\t\t\t\t\tcontinue;\n\t\t\t\tfor (int q = (p * p - 3) / 2; q <= h; q += p)\n\t\t\t\t\tisnp[q >> 5] |= 1 << q;\n\t\t\t}\n\t\t}\n\n\t\treturn Arrays.copyOf(ret, pos);\n\t}\n\n\tint[] primes = sieveEratosthenes(400000);\n\t\n\tvoid solve()\n\t{\n\t\tlong n = nl();\n\t\tlong ans = 0;\n\t\tif(n <= 10) {\n\t\t\tif(n >= 6)ans++;\n\t\t\tif(n >= 8)ans++;\n\t\t\tif(n >= 10)ans++;\n\t\t\tout.println(ans);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tMeisselLehmer2 ml = new MeisselLehmer2(n/2);\n\t\tfor(int i = 0;i < primes.length;i++) {\n\t\t\tlong plus = ml.pi(n/primes[i]) - (i+1);\n\t\t\tif(plus <= 0)break;\n\t\t\tans += plus;\n\t\t}\n\t\t\n\t\tfor(int p : primes) {\n\t\t\tif((long)p*p*p <= n) {\n\t\t\t\tans++;\n\t\t\t}else {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tout.println(ans);\n\t}\n\t\n\tpublic static class MeisselLehmer2 {\n\t\tint[] primes;\n//\t\tint[] cump;\n\t\tint[] xcums;\n\t\tlong[] isp;\n\t\t\n\t\tint cachelimit;\n//\t\tMap<Long, Long> picache;\n//\t\tMap<Long, Long> phicache;\n\t\tLongHashCounterL picache;\n\t\tLongHashCounterL phicache;\n\t\tboolean cachePhi = false;\n\t\t\n\t\tint[][] cumps;\n//\t\tint[] FP = {2,3,5,7,11,13,17};\n\t\tint[] FP = {2,3,5,7,11,13,17,19};\n\t\tint M = FP.length;\n\t\t\n\t\tint B = 100;\n\t\t// 10^14 -> 200\n\t\t// 10^14/8 -> 100~200\n\n\t\tpublic MeisselLehmer2(long n)\n\t\t{\n\t\t\tassert n >= 4;\n//\t\t\tpicache = new HashMap<>();\n//\t\t\tphicache = new HashMap<>();\n\t\t\tpicache = new LongHashCounterL();\n\t\t\tphicache = new LongHashCounterL();\n\t\t\t\n\t\t\tint s = (int)Math.sqrt(n)*B; // not overflow!\n\t\t\tcachelimit = s;\n\t\t\tthis.primes = sieveEratosthenes(s);\n\t\t\txcums = new int[(s>>>6)+1];\n\t\t\tisp = new long[(s>>>6)+1];\n\t\t\tfor(int p : primes)isp[p>>>6] |= 1L<<p;\n\t\t\tfor(int i = 0;i < xcums.length-1;i++)xcums[i+1] = xcums[i] + Long.bitCount(isp[i]);\n\t\t\t\n\t\t\tcumps = new int[M][];\n\t\t\tboolean[] b = {true};\n\t\t\tint len = 1;\n\t\t\tfor(int i = 0;i < M;i++){\n\t\t\t\tlen *= FP[i];\n\t\t\t\tboolean[] c = new boolean[len];\n\t\t\t\tfor(int j = 0;j < FP[i];j++){\n\t\t\t\t\tSystem.arraycopy(b, 0, c, j*b.length, b.length);\n\t\t\t\t}\n\t\t\t\tfor(int k = 0;k < len;k+=FP[i])c[k] = false;\n\t\t\t\tcumps[i] = new int[len+1];\n\t\t\t\tfor(int j = 0;j < len;j++)cumps[i][j+1] = cumps[i][j] + (c[j] ? 1 : 0);\n\t\t\t\tFP[i] = len;\n\t\t\t\tb = c;\n\t\t\t}\n\t\t}\n\t\t\n\t\tprivate long sqrt(long n)\n\t\t{\n\t\t\tlong i = Math.max(0, (long)Math.sqrt(n)-2);\n\t\t\twhile(i*i <= n)i++;\n\t\t\treturn i-1;\n\t\t}\n\t\t\n\t\tprivate long cbrt(long n)\n\t\t{\n\t\t\tlong i = Math.max(0, (long)Math.cbrt(n)-2);\n\t\t\twhile(i*i*i <= n)i++;\n\t\t\treturn i-1;\n\t\t}\n\t\t\n\t\tpublic long pi(long x)\n\t\t{\n\t\t\tif(x <= cachelimit){\n\t\t\t\tint ix = (int)x;\n\t\t\t\treturn xcums[ix>>>6] + Long.bitCount(isp[ix>>>6]<<~ix);\n//\t\t\t\treturn cump[(int)x];\n\t\t\t}\n\t\t\tif(picache.containsKey(x))return picache.get(x);\n\t\t\t\n\t\t\tint A = (int)pi(sqrt(sqrt(x)));\n\t\t\tlong ret = A + phi(x, A) - P2(x, A) - P3(x, A) - 1;\n\t\t\tpicache.put(x, ret);\n\t\t\treturn ret;\n\t\t}\n\t\t\n\t\tprivate long phi(long x, int A)\n\t\t{\n\t\t\tif(A > 0 && A-1 < M){\n\t\t\t\treturn cumps[A-1][FP[A-1]] * (x/FP[A-1]) + cumps[A-1][(int)(x%FP[A-1]+1)];\n\t\t\t}\n\t\t\tif(A > 0 && x <= (long)primes[A-1]*primes[A-1]){\n\t\t\t\treturn pi(x) - A + 1;\n\t\t\t}\n//\t\t\tlong code = x<<13|A;\n//\t\t\tif(phicache.containsKey(code))return phicache.get(code);\n\t\t\t\n\t\t\tlong ret = x;\n\t\t\tfor(int i = A-1;i >= 0;i--)ret -= phi(x/primes[i], i);\n\t\t\t\n//\t\t\tif(cachePhi)phicache.put(code, ret);\n\t\t\treturn ret;\n\t\t}\n\t\t\n\t\tprivate long P2(long x, int A)\n\t\t{\n\t\t\tint B = (int)pi(sqrt(x));\n\t\t\tlong ret = 0;\n\t\t\tfor(int i = A;i < B;i++){\n\t\t\t\tret += pi(x/primes[i]);\n\t\t\t}\n\t\t\tret -= (long)(B-A)*(B+A-1)/2;\n\t\t\treturn ret;\n\t\t}\n\t\t\n\t\tprivate long P3(long x, int A)\n\t\t{\n\t\t\tint C = (int)pi(cbrt(x));\n\t\t\tlong ret = 0;\n\t\t\tfor(int i = A;i < C;i++){\n\t\t\t\tlong xi = x/primes[i];\n\t\t\t\tint B = (int)pi(sqrt(xi));\n\t\t\t\tfor(int j = i;j < B;j++){\n\t\t\t\t\tret += pi(xi/primes[j]) - j;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn ret;\n\t\t}\n\t\t\n\t\tpublic static int[] sieveEratosthenes(int n) {\n\t\t\tif (n <= 32) {\n\t\t\t\tint[] primes = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 };\n\t\t\t\tfor (int i = 0; i < primes.length; i++) {\n\t\t\t\t\tif (n < primes[i]) {\n\t\t\t\t\t\treturn Arrays.copyOf(primes, i);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn primes;\n\t\t\t}\n\n\t\t\tint u = n + 32;\n\t\t\tdouble lu = Math.log(u);\n\t\t\tint[] ret = new int[(int) (u / lu + u / lu / lu * 1.5)];\n\t\t\tret[0] = 2;\n\t\t\tint pos = 1;\n\n\t\t\tint[] isnp = new int[(n + 1) / 32 / 2 + 1];\n\t\t\tint sup = (n + 1) / 32 / 2 + 1;\n\n\t\t\tint[] tprimes = { 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 };\n\t\t\tfor (int tp : tprimes) {\n\t\t\t\tret[pos++] = tp;\n\t\t\t\tint[] ptn = new int[tp];\n\t\t\t\tfor (int i = (tp - 3) / 2; i < tp << 5; i += tp)\n\t\t\t\t\tptn[i >> 5] |= 1 << (i & 31);\n\t\t\t\tfor (int j = 0; j < sup; j += tp) {\n\t\t\t\t\tfor (int i = 0; i < tp && i + j < sup; i++) {\n\t\t\t\t\t\tisnp[j + i] |= ptn[i];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// 3,5,7\n\t\t\t// 2x+3=n\n\t\t\tint[] magic = { 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, 31, 22, 28, 18, 26, 10, 7, 12, 21, 17,\n\t\t\t\t\t9, 6, 16, 5, 15, 14 };\n\t\t\tint h = n / 2;\n\t\t\tfor (int i = 0; i < sup; i++) {\n\t\t\t\tfor (int j = ~isnp[i]; j != 0; j &= j - 1) {\n\t\t\t\t\tint pp = i << 5 | magic[(j & -j) * 0x076be629 >>> 27];\n\t\t\t\t\tint p = 2 * pp + 3;\n\t\t\t\t\tif (p > n)\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tret[pos++] = p;\n\t\t\t\t\tif ((long) p * p > n)\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\tfor (int q = (p * p - 3) / 2; q <= h; q += p)\n\t\t\t\t\t\tisnp[q >> 5] |= 1 << q;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn Arrays.copyOf(ret, pos);\n\t\t}\n\t\t\n\t\tprivate static class LongHashCounterL {\n\t\t\tpublic long[] keys;\n\t\t\tpublic long[] allocated;\n\t\t\tprivate int scale = 1<<2;\n\t\t\tprivate int rscale = 1<<1;\n\t\t\tprivate int mask = scale-1;\n\t\t\tpublic int size = 0;\n\t\t\t\n\t\t\tpublic LongHashCounterL(){\n\t\t\t\tallocated = new long[scale];\n\t\t\t\tArrays.fill(allocated, NG);\n\t\t\t\tkeys = new long[scale];\n\t\t\t}\n\t\t\t\n\t\t\t// if value is NG, entry is removed. (e.g. 0)\n\t\t\tprivate static final int NG = 0;\n\t\t\t\n\t\t\tpublic boolean containsKey(long x)\n\t\t\t{\n\t\t\t\tint pos = h(x)&mask;\n\t\t\t\twhile(allocated[pos] != NG){\n\t\t\t\t\tif(x == keys[pos])return true;\n\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t}\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\t\n\t\t\tpublic long get(long x)\n\t\t\t{\n\t\t\t\tint pos = h(x)&mask;\n\t\t\t\twhile(allocated[pos] != NG){\n\t\t\t\t\tif(x == keys[pos])return allocated[pos];\n\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t}\n\t\t\t\treturn NG;\n\t\t\t}\n\t\t\t\n\t\t\tpublic long put(long x, long v)\n\t\t\t{\n\t\t\t\tint pos = h(x)&mask;\n\t\t\t\twhile(allocated[pos] != NG){\n\t\t\t\t\tif(x == keys[pos]){\n\t\t\t\t\t\tlong oldval = allocated[pos];\n\t\t\t\t\t\tallocated[pos] = v;\n\t\t\t\t\t\treturn oldval;\n\t\t\t\t\t}\n\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t}\n\t\t\t\tif(size == rscale){\n\t\t\t\t\tresizeAndPut(x, v);\n\t\t\t\t}else{\n\t\t\t\t\tkeys[pos] = x;\n\t\t\t\t\tallocated[pos] = v;\n\t\t\t\t}\n\t\t\t\tsize++;\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\t\n\t\t\tpublic long inc(long x, long v)\n\t\t\t{\n\t\t\t\tint pos = h(x)&mask;\n\t\t\t\twhile(allocated[pos] != NG){\n\t\t\t\t\tif(x == keys[pos]){\n\t\t\t\t\t\tallocated[pos] += v;\n\t\t\t\t\t\treturn allocated[pos];\n\t\t\t\t\t}\n\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t}\n\t\t\t\tif(size == rscale){\n\t\t\t\t\tresizeAndPut(x, v);\n\t\t\t\t}else{\n\t\t\t\t\tkeys[pos] = x;\n\t\t\t\t\tallocated[pos] = v;\n\t\t\t\t}\n\t\t\t\tsize++;\n\t\t\t\treturn v;\n\t\t\t}\n\t\t\t\n\t\t\tpublic boolean remove(long x)\n\t\t\t{\n\t\t\t\tint pos = h(x)&mask;\n\t\t\t\twhile(allocated[pos] != NG){\n\t\t\t\t\tif(x == keys[pos]){\n\t\t\t\t\t\tsize--;\n\t\t\t\t\t\t// take last and fill rmpos\n\t\t\t\t\t\tint last = pos;\n\t\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t\t\twhile(allocated[pos] != NG){\n\t\t\t\t\t\t\tint lh = h(keys[pos])&mask;\n\t\t\t\t\t\t\t// lh <= last < pos\n\t\t\t\t\t\t\tif(\n\t\t\t\t\t\t\t\t\tlh <= last && last < pos ||\n\t\t\t\t\t\t\t\t\tpos < lh && lh <= last ||\n\t\t\t\t\t\t\t\t\tlast < pos && pos < lh\n\t\t\t\t\t\t\t\t\t){\n\t\t\t\t\t\t\t\tkeys[last] = keys[pos];\n\t\t\t\t\t\t\t\tallocated[last] = allocated[pos];\n\t\t\t\t\t\t\t\tlast = pos;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tkeys[last] = 0;\n\t\t\t\t\t\tallocated[last] = NG;\n\t\t\t\t\t\t\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t\tpos = pos+1&mask;\n\t\t\t\t}\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\t\n\t\t\tprivate void resizeAndPut(long x, long v)\n\t\t\t{\n\t\t\t\tint nscale = scale<<1;\n\t\t\t\tint nrscale = rscale<<1;\n\t\t\t\tint nmask = nscale-1;\n\t\t\t\tlong[] nallocated = new long[nscale];\n\t\t\t\tArrays.fill(nallocated, NG);\n\t\t\t\tlong[] nkeys = new long[nscale];\n\t\t\t\tfor(int i = next(0);i < scale;i = next(i+1)){\n\t\t\t\t\tlong y = keys[i];\n\t\t\t\t\tint pos = h(y)&nmask;\n\t\t\t\t\twhile(nallocated[pos] != NG)pos = pos+1&nmask;\n\t\t\t\t\tnkeys[pos] = y;\n\t\t\t\t\tnallocated[pos] = allocated[i];\n\t\t\t\t}\n\t\t\t\t{\n\t\t\t\t\tint pos = h(x)&nmask;\n\t\t\t\t\twhile(nallocated[pos] != NG)pos = pos+1&nmask;\n\t\t\t\t\tnkeys[pos] = x;\n\t\t\t\t\tnallocated[pos] = v;\n\t\t\t\t}\n\t\t\t\tallocated = nallocated;\n\t\t\t\tkeys = nkeys;\n\t\t\t\tscale = nscale;\n\t\t\t\trscale = nrscale;\n\t\t\t\tmask = nmask;\n\t\t\t}\n\t\t\t\n\t\t\tpublic int next(int itr)\n\t\t\t{\n\t\t\t\twhile(itr < scale && allocated[itr] == NG)itr++;\n\t\t\t\treturn itr;\n\t\t\t}\n\t\t\t\n\t\t\tprivate int h(long x)\n\t\t\t{\n\t\t\t\tx ^= x>>>33;\n\t\t\t\tx *= 0xff51afd7ed558ccdL;\n\t\t\t\tx ^= x>>>33;\n\t\t\t\tx *= 0xc4ceb9fe1a85ec53L;\n\t\t\t\tx ^= x>>>33;\n\t\t\t\treturn (int)x;\n\t\t\t}\n\t\t\t\n\t\t\t@Override\n\t\t\tpublic String toString()\n\t\t\t{\n\t\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\t\tfor(int i = next(0);i < scale;i = next(i+1)){\n\t\t\t\t\tsb.append(\",\");\n\t\t\t\t\tsb.append(keys[i] + \":\" + allocated[i]);\n\t\t\t\t}\n\t\t\t\treturn sb.length() == 0 ? \"\" : sb.substring(1);\n\t\t\t}\n\t\t}\n\t}\n\t\n\tvoid run() throws Exception\n\t{\n\t\tis = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());\n\t\tout = new PrintWriter(System.out);\n\t\t\n\t\tlong s = System.currentTimeMillis();\n\t\tsolve();\n\t\tout.flush();\n\t\ttr(System.currentTimeMillis()-s+\"ms\");\n\t}\n\t\n\tpublic static void main(String[] args) throws Exception { new F3().run(); }\n\t\n\tprivate byte[] inbuf = new byte[1024];\n\tpublic int lenbuf = 0, ptrbuf = 0;\n\t\n\tprivate int readByte()\n\t{\n\t\tif(lenbuf == -1)throw new InputMismatchException();\n\t\tif(ptrbuf >= lenbuf){\n\t\t\tptrbuf = 0;\n\t\t\ttry { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }\n\t\t\tif(lenbuf <= 0)return -1;\n\t\t}\n\t\treturn inbuf[ptrbuf++];\n\t}\n\t\n\tprivate boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }\n\tprivate int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }\n\t\n\tprivate double nd() { return Double.parseDouble(ns()); }\n\tprivate char nc() { return (char)skip(); }\n\t\n\tprivate String ns()\n\t{\n\t\tint b = skip();\n\t\tStringBuilder sb = new StringBuilder();\n\t\twhile(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')\n\t\t\tsb.appendCodePoint(b);\n\t\t\tb = readByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tprivate char[] ns(int n)\n\t{\n\t\tchar[] buf = new char[n];\n\t\tint b = skip(), p = 0;\n\t\twhile(p < n && !(isSpaceChar(b))){\n\t\t\tbuf[p++] = (char)b;\n\t\t\tb = readByte();\n\t\t}\n\t\treturn n == p ? buf : Arrays.copyOf(buf, p);\n\t}\n\t\n\tprivate char[][] nm(int n, int m)\n\t{\n\t\tchar[][] map = new char[n][];\n\t\tfor(int i = 0;i < n;i++)map[i] = ns(m);\n\t\treturn map;\n\t}\n\t\n\tprivate int[] na(int n)\n\t{\n\t\tint[] a = new int[n];\n\t\tfor(int i = 0;i < n;i++)a[i] = ni();\n\t\treturn a;\n\t}\n\t\n\tprivate int ni()\n\t{\n\t\tint num = 0, b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate long nl()\n\t{\n\t\tlong num = 0;\n\t\tint b;\n\t\tboolean minus = false;\n\t\twhile((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));\n\t\tif(b == '-'){\n\t\t\tminus = true;\n\t\t\tb = readByte();\n\t\t}\n\t\t\n\t\twhile(true){\n\t\t\tif(b >= '0' && b <= '9'){\n\t\t\t\tnum = num * 10 + (b - '0');\n\t\t\t}else{\n\t\t\t\treturn minus ? -num : num;\n\t\t\t}\n\t\t\tb = readByte();\n\t\t}\n\t}\n\t\n\tprivate boolean oj = System.getProperty(\"ONLINE_JUDGE\") != null;\n\tprivate void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }\n}\n", "src_uid": "ffb7762f1d60dc3f16e9b27ea0ecdd7d"} {"source_code": "import java.util.*; public class wizards\n{ public static void main(String[] args)\n{ Scanner in=new Scanner(System.in);\nint n=in.nextInt(),x=in.nextInt(),y=in.nextInt();\nSystem.out.println(result(n,x,y));\n}\npublic static int result(int n, int x,int y)\n{ int p=(int)Math.ceil((double)(n*(y/100.0)));\nif(p>x)\nreturn (p-x);\nelse return (0);\n}\n}", "src_uid": "7038d7b31e1900588da8b61b325e4299"} {"source_code": "import java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.Scanner;\n\npublic class CF985A {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tint n = sc.nextInt();\n\t\tint total1 = 0;\n\t\tint total2 = 0;\n\t\tArrayList<Integer> pieces = new ArrayList<>();\n\t\tfor(int i=0; i<n/2; i++) pieces.add(sc.nextInt());\n\t\tCollections.sort(pieces);\n\t\tfor(int i=0; i<pieces.size(); i++) {\n\t\t\tint goal = (i+1)*2;\n\t\t\ttotal1+=Math.abs(pieces.get(i)-(goal-1));\n\t\t\ttotal2+=Math.abs(pieces.get(i)-goal);\n\t\t}\n\t\tSystem.out.println(Math.min(total1, total2));\n\t}\n}\n", "src_uid": "0efe9afd8e6be9e00f7949be93f0ca1a"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class cf388a {\n static FastIO in = new FastIO(), out = in;\n\n public static void main(String[] args) {\n int n = in.nextInt();\n int[] v = new int[n];\n for(int i=0; i<n; i++) v[i] = in.nextInt();\n Arrays.sort(v);\n int lo = 1, hi = n;\n while(hi - lo > 2) {\n int mid = (hi+lo)/2;\n if(ok(mid, v)) hi = mid;\n else lo = mid;\n }\n while(!ok(lo, v)) lo++;\n out.println(lo);\n out.close();\n }\n static boolean ok(int x, int[] v) {\n for(int i=0; i<v.length; i++)\n if(v[i] < i/x)\n return false;\n return true;\n }\n\n static class FastIO extends PrintWriter {\n BufferedReader br;\n StringTokenizer st;\n\n public FastIO() {\n this(System.in, System.out);\n }\n\n public FastIO(InputStream in, OutputStream out) {\n super(new BufferedWriter(new OutputStreamWriter(out)));\n br = new BufferedReader(new InputStreamReader(in));\n scanLine();\n }\n\n public void scanLine() {\n try {\n st = new StringTokenizer(br.readLine().trim());\n } catch (Exception e) {\n throw new RuntimeException(e.getMessage());\n }\n }\n\n public int numTokens() {\n if (!st.hasMoreTokens()) {\n scanLine();\n return numTokens();\n }\n return st.countTokens();\n }\n\n public String next() {\n if (!st.hasMoreTokens()) {\n scanLine();\n return next();\n }\n return st.nextToken();\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}", "src_uid": "7c710ae68f27f140e7e03564492f7214"} {"source_code": "import java.util.*;\n\npublic class a243 {\n \n static void solve(){\n Scanner scan = new Scanner(System.in);\n \n int n = scan.nextInt();\n int s = scan.nextInt();\n \n int sum = 0;\n int max = 0;\n for (int i=0; i<n; i++){\n int t = scan.nextInt();\n if(t > max) max =t;\n sum += t;\n }\n sum -= max;\n if(sum > s) System.out.println(\"NO\");\n else System.out.println(\"YES\");\n return ;\n }\n \n public static void main(String[] args) {\n // TODO Auto-generated method stub\n solve();\n }\n\n}\n", "src_uid": "496baae594b32c5ffda35b896ebde629"} {"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<<w][1<<w][10][10]; // valid carry\n\t\tlong[][][][] ep = new long[1<<w][1<<w][10][10]; // valid carry\n\t\tint mod = 998244353;\n\t\tep[0][0][0][0] = 1;\n\t\t\n\t\tint[][] va0 = new int[10][10];\n\t\tint[][] va1 = new int[10][10];\n\t\tint[][] nextc0 = new int[10][10];\n\t\tint[][] nextc1 = new int[10][10];\n\t\tfor(int d = 0;d < 10;d++){\n\t\t\tfor(int c0 = 0;c0 <= 9;c0++){\n\t\t\t\tint v0 = d*u + c0;\n\t\t\t\tfor(int t = 1;t <= w;t++){\n\t\t\t\t\tif(t*u == v0%10){\n\t\t\t\t\t\tva0[d][c0] |= 1<<t-1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tnextc0[d][c0] = v0 / 10;\n\t\t\t}\n\t\t\tfor(int c1 = 0;c1 <= 9;c1++){\n\t\t\t\tint v1 = d*v + c1;\n\t\t\t\tfor(int t = 1;t <= w;t++){\n\t\t\t\t\tif(t*v == v1%10){\n\t\t\t\t\t\tva1[d][c1] |= 1<<t-1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tnextc1[d][c1] = v1 / 10;\n\t\t\t}\n\t\t}\n\t\t\n\t\tfor(int i = n-1;i >= 0;i--){\n\t\t\tlong[][][][] ndp = new long[1<<w][1<<w][10][10]; // valid carry\n\t\t\tlong[][][][] nep = new long[1<<w][1<<w][10][10]; // valid carry\n\t\t\t\n\t\t\tfor(int j = 0;j < 1<<w;j++){\n\t\t\t\tfor(int k = 0;k < 1<<w;k++){\n\t\t\t\t\tfor(int l = 0;l < 10;l++){\n\t\t\t\t\t\tfor(int m = 0;m < 10;m++){\n\t\t\t\t\t\t\tint d = s[i]-'0';\n\t\t\t\t\t\t\tint nj = j|va0[d][l];\n\t\t\t\t\t\t\tint nk = k|va1[d][m];\n\t\t\t\t\t\t\tint nl = nextc0[d][l];\n\t\t\t\t\t\t\tint nm = nextc1[d][m];\n\t\t\t\t\t\t\tndp[nj][nk][nl][nm] += dp[j][k][l][m];\n\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}\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<<w;j++){\n\t\t\t\tfor(int k = 0;k < 1<<w;k++){\n\t\t\t\t\tfor(int l = 0;l < 10;l++){\n\t\t\t\t\t\tfor(int m = 0;m < 10;m++){\n\t\t\t\t\t\t\tfor(int d = 0;d < 10;d++){\n\t\t\t\t\t\t\t\tint nj = j|va0[d][l];\n\t\t\t\t\t\t\t\tint nk = k|va1[d][m];\n\t\t\t\t\t\t\t\tint nl = nextc0[d][l];\n\t\t\t\t\t\t\t\tint nm = nextc1[d][m];\n\t\t\t\t\t\t\t\tnep[nj][nk][nl][nm] += ep[j][k][l][m];\n\t\t\t\t\t\t\t\tif(nep[nj][nk][nl][nm] >= 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<<w;i++){\n\t\t\tfor(int j = 0;j < 1<<w;j++){\n\t\t\t\tif((i&j) != 0){\n\t\t\t\t\tret += dp[i][j][0][0];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn ret % mod;\n\t}\n\t\n\tpublic static int gcd(int a, int b) {\n\t\twhile (b > 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}\n", "src_uid": "b6f2061e2ca174c2385bf4520d232aaf"} {"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<t2)\n\t\t{\n\t\t\tfor (int k1=0;k1<=max1;k1++)\n\t\t\t{\n\t\t\t\tlong sz=f-k1*a1;\n\t\t\t\t\n\t\t\t\tlong l=0,r=sz/a2,result=-1,t=a1*k1*t1;\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=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}", "src_uid": "f5f85e75af5b0f25f1f436a21e12fad1"} {"source_code": "import java.util.Scanner;\n\npublic class Process {\n\n\tpublic static void main(String[] args) {\n\t\tScanner in = new Scanner(System.in);\n\t\tint n = in.nextInt();\n\t\tint kp = 0;\n\t\tint p = 0;\n\t\tint zp = 0;\n\t\tint k = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint a = in.nextInt();\n\t\t\tif (p == 0 && a != 0) {\n\t\t\t\tp = a;\n\t\t\t\tkp = 1;\n\t\t\t}\n\t\t\telse if (a == p && p != 0) {\n\t\t\t\tkp++;\n\t\t\t}\n\t\t\telse if (a != p && p != 0 && a != 0) {\n\t\t\t\tk += min(kp, i - zp - kp);\n\t\t\t\tzp += kp;\n\t\t\t\tp = a;\n\t\t\t\tkp = 1;\n\t\t\t}\n\t\t\telse if (p != 0 && a == 0) {\n\t\t\t\tk += min(kp, i - zp - kp);\n\t\t\t\tzp += kp;\n\t\t\t\tp = kp = 0;\n\t\t\t}\n\t\t\tif (i == n - 1 && a != 0) {\n\t\t\t\tk += min(kp, i - zp - kp + 1);\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(k);\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}\n", "src_uid": "9135c7243431debb049f640e9600bc6e"} {"source_code": "import java.util.*;\n\npublic class shashank\n{\n\tpublic static void main(String args[])\n\t{\n\t\tScanner scan = new Scanner(System.in);\n\t\tint n = Math.abs(scan.nextInt());\n\t\tint k = 3 - 2 * (n % 2);\n\n\t\tif(n == 0)\n\t\t\tSystem.out.println(0);\n\t\telse\n\t\t{\n\t\t\twhile(true)\n\t\t\t{\n\t\t\t\tif((k + 1) * k >= 2 * n)\n\t\t\t\t{\n\t\t\t\t\tSystem.out.println(k);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\telse if((k + 1) * (k + 2) >= 2 * n)\n\t\t\t\t{\n\t\t\t\t\tSystem.out.println(k + 1);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tk += 4;\n\t\t\t}\n\t\t}\n\t}\n}", "src_uid": "18644c9df41b9960594fdca27f1d2fec"} {"source_code": "import java.io.*;\nimport java.util.*;\nimport java.math.*;\n\n\npublic class Main {\n static BufferedReader in;\n static PrintWriter out;\n static StringTokenizer tok;\n \n \n static void solve() throws Exception {\n int n = nextInt();\n out.println(\"+------------------------+\");\n if (n >= 1) {\n out.print(\"|O.\");\n } else {\n out.print(\"|#.\");\n }\n for (int i = 2; i <= 11; ++i) {\n if (4 + (i - 2) * 3 < n) {\n out.print(\"O.\");\n } else {\n out.print(\"#.\");\n }\n }\n out.println(\"|D|)\");\n if (n >= 2) {\n out.print(\"|O.\");\n } else {\n out.print(\"|#.\");\n }\n for (int i = 2; i <= 11; ++i) {\n if (4 + (i - 2) * 3 + 1 < n) {\n out.print(\"O.\");\n } else {\n out.print(\"#.\");\n }\n }\n out.println(\"|.|\");\n if (n >= 3) {\n out.print(\"|O.\");\n } else {\n out.print(\"|#.\");\n }\n for (int i = 2; i <= 11; ++i) {\n out.print(\"..\");\n }\n out.println(\"..|\");\n if (n >= 4) {\n out.print(\"|O.\");\n } else {\n out.print(\"|#.\");\n }\n for (int i = 2; i <= 11; ++i) {\n if (4 + (i - 2) * 3 + 2 < n) {\n out.print(\"O.\");\n } else {\n out.print(\"#.\");\n }\n }\n out.println(\"|.|)\");\n out.println(\"+------------------------+\");\n }\n \n static long sqr(int x) {\n return (long)x * x;\n }\n \n static int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n static long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n\n static double nextDouble() throws IOException {\n return Double.parseDouble(next());\n }\n\n static BigInteger nextBigInteger() throws IOException {\n return new BigInteger(next());\n }\n \n static String next() throws IOException {\n while (tok == null || !tok.hasMoreTokens()) {\n tok = new StringTokenizer(in.readLine());\n }\n return tok.nextToken();\n }\n \n static String nextLine() throws IOException {\n tok = new StringTokenizer(\"\");\n return in.readLine();\n }\n\n static boolean hasNext() throws IOException {\n while (tok == null || !tok.hasMoreTokens()) {\n String s = in.readLine();\n if (s == null) {\n return false;\n }\n tok = new StringTokenizer(s);\n }\n return true;\n }\n\n public static void main(String args[]) {\n try {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(new OutputStreamWriter(System.out));\n //in = new BufferedReader(new FileReader(\"input.in\"));\n //out = new PrintWriter(new FileWriter(\"output.out\"));\n solve();\n in.close();\n out.close();\n } catch (Throwable e) {\n e.printStackTrace();\n java.lang.System.exit(1);\n }\n }\n}", "src_uid": "075f83248f6d4d012e0ca1547fc67993"} {"source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\nimport java.io.IOException;\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.InputStream;\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\npublic class Main {\n public static void main(String[] args) {\n InputStream inputStream = System.in;\n OutputStream outputStream = System.out;\n FastScanner in = new FastScanner(inputStream);\n PrintWriter out = new PrintWriter(outputStream);\n 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, FastScanner in, PrintWriter out) {\n char[][] s = new char[][]{in.next().toCharArray(), in.next().toCharArray()};\n for (char[] c : s) {\n for (int i = 0; i < c.length; i++) {\n if (c[i] == 'C') {\n c[i] = 'B';\n }\n }\n }\n int q = in.nextInt();\n\n int[][][] count = new int[2][][];\n int[][] sufA = new int[2][];\n for (int i = 0; i < 2; i++) {\n count[i] = count(s[i]);\n sufA[i] = sufA(s[i]);\n }\n int[][] info = new int[2][3];\n for (int i = 0; i < q; i++) {\n int l1 = in.nextInt() - 1, r1 = in.nextInt();\n int l2 = in.nextInt() - 1, r2 = in.nextInt();\n\n info[0][0] = count[0][0][r1] - count[0][0][l1];\n info[0][1] = count[0][1][r1] - count[0][1][l1];\n info[0][2] = Math.min(sufA[0][r1 - 1], r1 - l1);\n\n info[1][0] = count[1][0][r2] - count[1][0][l2];\n info[1][1] = count[1][1][r2] - count[1][1][l2];\n info[1][2] = Math.min(sufA[1][r2 - 1], r2 - l2);\n out.print(can(info[0], info[1]) ? '1' : '0');\n }\n }\n\n private boolean can(int[] a, int[] b) {\n a[0] -= a[2];\n b[0] -= b[2];\n if (a[2] < b[2]) {\n return false;\n }\n if (a[2] % 3 == b[2] % 3) {\n if (can2(a, b)) {\n return true;\n }\n }\n a[2]--;\n a[1] += 2;\n\n a[0] += a[2] - b[2];\n return can2(a, b);\n }\n\n private boolean can2(int[] a, int[] b) {\n if (a[0] < 0 || a[1] < 0) {\n return false;\n }\n if (a[1] > b[1]) {\n return false;\n }\n if (a[1] % 2 != b[1] % 2) {\n return false;\n }\n if (b[1] > a[1] && (a[0] + a[1] == 0)) {\n return false;\n }\n return true;\n }\n\n private int[] sufA(char[] chars) {\n int[] a = new int[chars.length];\n for (int i = 0; i < chars.length; i++) {\n if (chars[i] == 'A') {\n a[i] = (i == 0 ? 0 : a[i - 1]) + 1;\n } else {\n a[i] = 0;\n }\n }\n return a;\n }\n\n private int[][] count(char[] chars) {\n int[][] a = new int[2][chars.length + 1];\n for (int i = 0; i < chars.length; i++) {\n a[0][i + 1] += a[0][i];\n a[1][i + 1] += a[1][i];\n a[chars[i] - 'A'][i + 1]++;\n }\n return a;\n }\n\n }\n\n static class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n public FastScanner(InputStream in) {\n br = new BufferedReader(new InputStreamReader(in));\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public String next() {\n while (st == null || !st.hasMoreElements()) {\n String line = null;\n try {\n line = br.readLine();\n } catch (IOException e) {\n }\n st = new StringTokenizer(line);\n }\n return st.nextToken();\n }\n\n }\n}\n\n", "src_uid": "98e3182f047a7e7b10be7f207b219267"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\n/**\n * Created by Everest on 22.10.2016.\n */\npublic class B3 {\n\n public static void main(String[] args) throws IOException {\n\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n String tmp = br.readLine();\n char c = tmp.charAt(tmp.length()-1);\n\n int c1 = 0;\n\n if (c == 'a'){\n c1 = 4;\n }else if(c == 'b'){\n c1 = 5;\n }else if(c == 'c'){\n c1 = 6;\n }else if(c == 'd'){\n c1 = 3;\n }else if(c == 'e'){\n c1 = 2;\n }else if(c == 'f'){\n c1 = 1;\n }\n\n long n = Long.parseLong(tmp.substring(0, tmp.length()-1));\n long ans = 0;\n\n if(n % 4 == 0){\n ans = 12*(n/4 - 1) + 6 + n-3 + c1;\n }else if( (n % 4 != 0) && (n % 2 == 0) ){\n ans = 12*(n/4 + 1) - 6 + c1 + n-1;\n }else{\n ans = 12*(n/4) + c1 + (((n+1) % 4 == 0) ? (n-3) : (n-1));\n }\n\n System.out.println(ans);\n\n }\n\n}\n", "src_uid": "069d0cb9b7c798a81007fb5b63fa0f45"} {"source_code": "import java.io.IOException;\nimport java.io.InputStream;\nimport java.util.InputMismatchException;\n\npublic class B370{\n\n\tvoid solve()\n\t{\n\t\tint x = ni();\n\t\tint y = ni();\n\t\tint[] t = {y,y,y};\n\t\tint cn = 0;\n\t\tfor(int i=0;!allX(t,x);i++)\n\t\t{\n\t\t\tif(i%3==0)\n\t\t\t{\n\t\t\t\tint rch = t[1]+t[2]-1;\n\t\t\t\tt[0] = Math.min(rch,x);\n\t\t\t}\n\t\t\telse if(i%3==1)\n\t\t\t{\n\t\t\t\tint rch = t[0]+t[2]-1;\n\t\t\t\tt[1] = Math.min(rch,x);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tint rch = t[0]+t[1]-1;\n\t\t\t\tt[2] = Math.min(rch,x);\n\t\t\t}\n\t\t\tcn++;\n\t\t}\n\t\tSystem.out.println(cn);\n\t}\n\t\n\tboolean allX(int[] a,int k)\n\t{\n\t\tfor(int x : a)\n\t\t\tif(x!=k)\n\t\t\t\treturn false;\n\t\treturn true;\n\t}\n\t\n\t\n\tpublic static void main(String[] args){new B370().solve();}\n\t\n\tprivate byte[] bufferArray = new byte[1024];\n\tprivate int bufLength = 0;\n\tprivate int bufCurrent = 0;\n\tInputStream inputStream = System.in;\n\t\n\tint nextByte()\n\t{\n\t\tif(bufLength==-1)\n\t\t\tthrow new InputMismatchException();\n\t\tif(bufCurrent>=bufLength)\n\t\t{\n\t\t\tbufCurrent = 0;\n\t\t\ttry\n\t\t\t{bufLength = inputStream.read(bufferArray);}\n\t\t\tcatch(IOException e)\n\t\t\t{ throw new InputMismatchException();}\n\t\t\tif(bufLength<=0)\n\t\t\t\treturn -1;\n\t\t}\n\t\treturn bufferArray[bufCurrent++];\n\t}\n\t\n\tboolean isSpaceChar(int x)\n\t{return (x<33 || x>126);}\n\t\n\tboolean isDigit(int x)\n\t{return (x>='0' && x<='9');}\n\t\n\tint nextNonSpace()\n\t{\n\t\tint x;\n\t\twhile((x=nextByte())!=-1 && isSpaceChar(x));\n\t\treturn x;\n\t}\n\t\n\tint ni()\n\t{\n\t\tint ans = 0;\n\t\tint sign = 1;\n\t\tint x = nextNonSpace();\n\t\tif(x=='-') \n\t\t{\n\t\t\tsign = -1;\n\t\t\tx = nextByte();\n\t\t}\n\t\twhile(!isSpaceChar(x))\n\t\t{\n\t\t\tif(isDigit(x))\n\t\t\t{\n\t\t\t\tans = ans*10 + x -'0';\n\t\t\t\tx = nextByte();\n\t\t\t}\n\t\t\telse\n\t\t\t\tthrow new InputMismatchException();\n\t\t}\n\t\treturn sign*ans;\n\t}\n\t\n\tlong nl()\n\t{\n\t\tlong ans = 0;\n\t\tlong sign = 1;\n\t\tint x = nextNonSpace();\n\t\tif(x=='-') \n\t\t{\n\t\t\tsign = -1;\n\t\t\tx = nextByte();\n\t\t}\n\t\twhile(!isSpaceChar(x))\n\t\t{\n\t\t\tif(isDigit(x))\n\t\t\t{\n\t\t\t\tans = ans*10 + x -'0';\n\t\t\t\tx = nextByte();\n\t\t\t}\n\t\t\telse\n\t\t\t\tthrow new InputMismatchException();\n\t\t}\n\t\treturn sign*ans;\n\t}\n\t\n\tString ns()\n\t{\n\t\tStringBuilder sb = new StringBuilder();\n\t\tint x = nextNonSpace();\n\t\twhile(!isSpaceChar(x))\n\t\t{\n\t\t\tsb.append((char)x);\n\t\t\tx = nextByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tString nL()\n\t{\n\t\tStringBuilder sb = new StringBuilder();\n\t\tint x = nextNonSpace();\n\t\twhile(x==32 || !isSpaceChar(x))\n\t\t{\n\t\t\tsb.append((char)x);\n\t\t\tx = nextByte();\n\t\t}\n\t\treturn sb.toString();\n\t}\n\t\n\tchar nc()\n\t{ return (char)nextNonSpace();}\n\t\n\tdouble nd()\n\t{ return (double)Double.parseDouble(ns()); }\n\t\n\tchar[] ca()\n\t{ return ns().toCharArray();}\n\t\n\tchar[] ca(int n)\n\t{\n\t\tchar[] ans = new char[n];\n\t\tint p =0;\n\t\tint x = nextNonSpace();\n\t\twhile(p<n)\n\t\t{\n\t\t\tans[p++] = (char)x;\n\t\t\tx = nextByte();\n\t\t}\n\t\treturn ans;\n\t}\n\t\n\tint[] ia(int n)\n\t{\n\t\tint[] ans = new int[n];\n\t\tfor(int i=0;i<n;i++)\n\t\t\tans[i]=ni();\n\t\treturn ans;\n\t}\n\t\n\tlong[] la(int n)\n\t{\n\t\tlong[] ans = new long[n];\n\t\tfor(int i=0;i<n;i++)\n\t\t\tans[i] = nl();\n\t\treturn ans;\n\t}\n\t\n}\n", "src_uid": "8edf64f5838b19f9a8b19a14977f5615"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class D implements Runnable {\n private MyScanner in;\n private PrintWriter out;\n\n private void solve() {\n int x1 = in.nextInt();\n int x2 = in.nextInt();\n int a = in.nextInt();\n int b = in.nextInt();\n if (x2 >= x1 + a && x2 <= x1 + b) {\n out.println(\"FIRST\");\n out.println(x2);\n return;\n }\n if (x1 <= x2 && a <= 0 || x1 >= x2 && b >= 0) {\n out.println(\"DRAW\");\n return;\n }\n int mod = Math.abs(x1 - x2) % Math.abs(a + b);\n if (mod >= Math.min(Math.abs(a), Math.abs(b))\n && mod <= Math.max(Math.abs(a), Math.abs(b))) {\n out.println(\"FIRST\");\n out.println((x1 <= x2) ? (x1 + mod) : (x1 - mod));\n return;\n }\n if (mod == 0) {\n out.println(\"SECOND\");\n return;\n }\n out.println(\"DRAW\");\n }\n\n @Override\n public void run() {\n in = new MyScanner();\n out = new PrintWriter(System.out);\n solve();\n in.close();\n out.close();\n }\n\n public static void main(String[] args) {\n new D().run();\n }\n\n static class MyScanner {\n private BufferedReader br;\n private StringTokenizer st;\n\n public MyScanner() {\n br = new BufferedReader(new InputStreamReader(System.in));\n }\n\n public void close() {\n try {\n br.close();\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n\n public String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n return null;\n }\n }\n return st.nextToken();\n }\n\n public String nextLine() {\n try {\n st = null;\n return br.readLine();\n } catch (IOException e) {\n e.printStackTrace();\n return null;\n }\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public boolean hasNext() {\n if (st != null && st.hasMoreTokens()) {\n return true;\n }\n try {\n while (br.ready()) {\n st = new StringTokenizer(br.readLine());\n if (st != null && st.hasMoreTokens()) {\n return true;\n }\n }\n } catch (IOException e) {\n e.printStackTrace();\n }\n return false;\n }\n }\n}", "src_uid": "4ea8cc3305a0ee2c1e580b43e5bc46c6"} {"source_code": "/**\n * @author Finn Lidbetter\n */\nimport java.util.*;\nimport java.io.*;\nimport java.awt.geom.*;\n\npublic class TaskC {\n public static void main(String[] args) throws IOException {\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n StringBuilder sb = new StringBuilder();\n \n String f0 = \"What are you doing at the end of the world? Are you busy? Will you save us?\";\n // f_i+1= a+f_i+b+f_i+c;\n String a = \"What are you doing while sending \\\"\";\n String b = \"\\\"? Are you busy? Will you send \\\"\";\n String c = \"\\\"?\";\n long f0Len = f0.length();\n long aLen = a.length();\n long bLen = b.length();\n long cLen = c.length();\n long abcSum = aLen+bLen+cLen;\n\n\n int MAXN=100000;\n long[] len = new long[MAXN+1];\n len[0] = f0Len;\n for (int i=1; i<53; i++) {\n len[i] = (2L*len[i-1])+abcSum;\n //System.out.println(len[i]);\n }\n for (int i=53; i<MAXN+1; i++) {\n len[i] = 1_000_000_000_000_000_000L;\n }\n\n int q = Integer.parseInt(br.readLine());\n for (int i=0; i<q; i++) {\n String[] s = br.readLine().split(\" \");\n int n = Integer.parseInt(s[0]);\n long k = Long.parseLong(s[1])-1;\n boolean done = false;\n while (n>0) {\n //System.out.printf(\"n:%d, k:%d\\n\",n,k);\n if (k<aLen) {\n sb.append(a.charAt((int)k));\n done = true;\n break;\n } else if (k<aLen+len[n-1]) {\n k -= aLen;\n } else if (k<aLen+len[n-1]+bLen) {\n sb.append(b.charAt((int)(k-aLen-len[n-1])));\n done = true;\n break;\n } else if (k<aLen+len[n-1]+bLen+len[n-1]) {\n k -= (aLen+len[n-1]+bLen);\n } else if (k<aLen+len[n-1]+bLen+len[n-1]+cLen) {\n sb.append(c.charAt((int)(k-aLen-len[n-1]-bLen-len[n-1])));\n done = true;\n break;\n } else {\n sb.append('.');\n done = true;\n break;\n }\n n--;\n }\n if (!done) {\n if (k>=f0.length()) {\n sb.append('.');\n } else {\n sb.append(f0.charAt((int)k));\n }\n }\n }\n System.out.println(sb);\n }\n}\n", "src_uid": "da09a893a33f2bf8fd00e321e16ab149"} {"source_code": "import static java.util.Arrays.*;\nimport static java.lang.Math.*;\nimport static java.math.BigInteger.*;\nimport java.util.*;\nimport java.math.*;\nimport java.io.*;\n\npublic class A implements Runnable\n{\n String file = \"input\";\n \n boolean TEST = false;\n \n void solve() throws IOException\n {\n String s = next();\n seen = new HashSet<String>();\n permute(s, 0, new StringBuilder(), new boolean[6]);\n out.println(seen.size());\n }\n \n void permute(String s, int at, StringBuilder sb, boolean[] used)\n {\n if(at == 6)\n {\n process(sb.toString());\n return;\n }\n \n for(int i = 0; i < 6; i++)\n if(!used[i])\n {\n used[i] = true;\n sb.append(s.charAt(i));\n permute(s, at + 1, sb, used);\n sb.deleteCharAt(sb.length() - 1);\n used[i] = false;\n }\n }\n HashSet<String> seen;\n void process(String s)\n {\n String res = s;\n Cube cube = new Cube(s);\n for(int i = 0; i < 4; i++)\n {\n cube.down();\n for(int j = 0; j < 4; j++)\n {\n cube.left();\n res = min(res, cube.toString());\n }\n }\n cube.left(); cube.down();\n for(int i = 0; i < 4; i++)\n {\n cube.left();\n res = min(res, cube.toString());\n }\n cube.up(); cube.right(); cube.right(); cube.down();\n for(int i = 0; i < 4; i++)\n {\n cube.left();\n res = min(res, cube.toString());\n }\n seen.add(res);\n }\n String min(String a, String b)\n {\n if(a.compareTo(b) < 0) return a;\n return b;\n }\n \n class Cube\n {\n char[] cs;\n \n Cube(String s)\n {\n cs = s.toCharArray();\n } \n \n void left()\n {\n char t = cs[2];\n cs[2] = cs[3];\n cs[3] = cs[4];\n cs[4] = cs[5];\n cs[5] = t;\n }\n void right()\n {\n left(); left(); left();\n }\n void down()\n {\n char t = cs[0];\n cs[0] = cs[5];\n cs[5] = cs[1];\n cs[1] = cs[3];\n cs[3] = t; \n }\n void up()\n {\n down(); down(); down();\n }\n \n public String toString()\n {\n return new String(cs);\n }\n }\n \n String next() throws IOException\n {\n while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(input.readLine());\n return st.nextToken();\n }\n \n int nextInt() throws IOException\n {\n return Integer.parseInt(next());\n }\n \n long nextLong() throws IOException\n {\n return Long.parseLong(next());\n }\n \n double nextDouble() throws IOException\n {\n return Double.parseDouble(next());\n }\n \n void print(Object... o)\n {\n System.out.println(deepToString(o));\n }\n \n void gcj(Object o)\n {\n String s = String.valueOf(o);\n out.println(\"Case #\" + test + \": \" + s);\n System.out.println(\"Case #\" + test + \": \" + s);\n }\n \n BufferedReader input;\n PrintWriter out;\n StringTokenizer st;\n int test;\n \n void init() throws IOException\n {\n if(TEST) input = new BufferedReader(new FileReader(file + \".in\")); \n else input = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(new BufferedOutputStream(System.out));\n }\n \n public static void main(String[] args) throws IOException\n {\n new Thread(null, new A(), \"\", 1 << 20).start();\n }\n \n public void run()\n {\n try\n {\n init();\n if(TEST) \n {\n int runs = nextInt();\n for(int i = 0; i < runs; i++) solve();\n }\n else solve();\n out.close(); \n }\n catch(Exception e)\n {\n e.printStackTrace();\n System.exit(1);\n }\n }\n}", "src_uid": "8176c709c774fa87ca0e45a5a502a409"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.Arrays;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.PriorityQueue;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\n\npublic class TaskC {\n public static void main(String[] arg) {\n\n final FastScanner in = new FastScanner(System.in);\n final PrintWriter out = new PrintWriter(System.out);\n final long n = in.nextInt();\n final long mod = in.nextInt();\n final long [] fact = new long[(int)n+1];\n fact[0]=1;\n for(int i=1;i<=n;i++) {\n fact[i]=fact[i-1]*i%mod;\n }\n long result = 0;\n for(int i=1;i<=n;i++){\n result+=((n-i+1)*fact[i]%mod)*(fact[(int)n-i+1]%mod);\n result %= mod;\n }\n out.printf(\"%d%n\", result);\n out.close();\n in.close();\n }\n\n private static class Solution {\n\n private long permutations(final int n, int[] elements) {\n Map<Long, Integer> countMap = new TreeMap<>();\n int[] indexes = new int[n];\n for (int i = 0; i < n; i++) {\n indexes[i] = 0;\n }\n long result =count(n, elements);\n countMap.computeIfAbsent(result,l->1);\n int i = 0;\n while (i < n) {\n if (indexes[i] < i) {\n swap(elements, i % 2 == 0 ? 0 : indexes[i], i);\n long cnt = count(n, elements);\n countMap.computeIfPresent(cnt,(k,v)->v+1);\n countMap.computeIfAbsent(cnt,l->1);\n result+=cnt;\n indexes[i]++;\n i = 0;\n } else {\n indexes[i] = 0;\n i++;\n }\n }\n System.out.printf(\" %d %d %d %n\",n,\n factorial(n,1_000_000_009),result);\n return result;\n }\n\n private long count(final int n,final int [] a){\n long result =0;\n for(int l=0;l<n;l++){\n int max = a[l];\n int min = a[l];\n for(int r=l;r<n;r++){\n max = Math.max(a[r],max);\n min = Math.min(a[r],min);\n if(max-min==r-l){\n result++;\n }\n }\n }\n return result;\n }\n\n private long factorial(final int n,final int m) {\n if(n==1) return 1;\n if(n==2) return 2;\n long fact =2;\n long a = 1;\n long b = 2;\n int i =3;\n while(i<=n){\n fact = fact*i%m;\n i++;\n }\n return fact;\n }\n\n private void printArray(int []elements){\n System.out.println(Arrays.toString(elements));\n }\n\n private void swap(int [] input, int a, int b) {\n int tmp = input[a];\n input[a] = input[b];\n input[b] = tmp;\n }\n }\n\n\n\n\n\n private static class FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n FastScanner(InputStream stream) {\n try {\n br = new BufferedReader(new InputStreamReader(stream));\n } catch (Exception e) {\n e.printStackTrace();\n }\n }\n\n String next() {\n while (st == null || !st.hasMoreTokens()) {\n try {\n st = new StringTokenizer(br.readLine());\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt() {\n return Integer.parseInt(next());\n }\n\n int[] readIntArr(int n) {\n int[] result = new int[n];\n for (int i = 0; i < n; i++) {\n result[i] = Integer.parseInt(next());\n }\n return result;\n }\n\n void close() {\n try {\n br.close();\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n\n long nextLong() {\n return Long.parseLong(next());\n }\n\n }\n}\n", "src_uid": "020d5dae7157d937c3f58554c9b155f9"} {"source_code": "import java.io.*;\nimport java.util.*;\n\n\npublic class B {\n\tString s = null;\n\n\tString[] ss = null;\n\tint[][] sn = null;\n\tpublic void run() throws Exception{\n\n\t\tBufferedReader br = null;\n\t\tFile file = new File(\"input.txt\");\n\t\tif(file.exists()){\n\t\t\tbr = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t}\n\t\telse{\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t}\n\t\n\t\ts = br.readLine();\n\t\tint n = Integer.parseInt(s);\n\t\tlong[] in = new long[n];\n\t\ts = br.readLine();\n\t\tss = s.split(\" \");\n\t\tfor(int i = 0; i < n; i++){\n\t\t\tin[i] = Long.parseLong(ss[i]);\n\t\t}\n\t\tArrays.sort(in);\n\t\t\n\t\tboolean f = true;\n\t\tfor(int i = 0; i < in.length-1; i++){\n\t\t\tif(in[i] != in[i+1]){\n\t\t\t\tif(in[i] * 2 > in[i+1]){\n\t\t\t\t\tf = false;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tif(f){\n\t\t\tSystem.out.println(\"NO\");\n\t\t}\n\t\telse{\n\t\t\tSystem.out.println(\"YES\");\n\t\t}\n\t\t\n\t}\n\t\n\t\n\t\n\t\n\t/**\n\t * @param args\n\t */\n\tpublic static void main(String[] args) throws Exception{\n\t\tB t = new B();\n\t\tt.run();\n\n\t}\n\n\t\n}\n", "src_uid": "ab003ab094931fc105384df9d144131e"} {"source_code": "//Created by Aminul on 11/17/2020.\n\nimport java.io.*;\nimport java.util.*;\n\nimport static java.lang.Math.*;\n\npublic class CF1447F1 {\n public static void main(String[] args) throws Exception {\n Scanner in = new Scanner(System.in);\n PrintWriter pw = new PrintWriter(System.out);\n int n = in.nextInt();\n int[] arr = new int[n + 1];\n int[] freq = new int[101];\n int mostFreq = 0;\n for (int i = 1; i <= n; i++) {\n arr[i] = in.nextInt();\n freq[arr[i]]++;\n if (freq[arr[i]] > freq[mostFreq]) {\n mostFreq = arr[i];\n }\n }\n\n int res = 0;\n for (int i = 1; i <= 100; i++) {\n if (i != mostFreq) {\n int tmp = maxSumArrayWithZeroSum(n, mostFreq, i, arr);\n res = max(res, tmp);\n }\n }\n\n pw.println(res);\n pw.close();\n }\n\n static int maxSumArrayWithZeroSum(int n, int x, int y, int[] arr) {\n int offset = n + 5;\n int[] idx = new int[offset + offset + 10];\n int invalid = -n - n - n;\n Arrays.fill(idx, invalid);\n int sum = 0, res = 0;\n idx[offset + sum] = 0;\n for (int i = 1; i <= n; i++) {\n if (arr[i] == x) sum++;\n else if (arr[i] == y) sum--;\n if (idx[offset + sum] != invalid) res = max(res, i - idx[offset + sum]);\n else idx[offset + sum] = i;\n }\n return res;\n }\n\n static void debug(Object... obj) {\n System.err.println(Arrays.deepToString(obj));\n }\n}", "src_uid": "a06ebb2734365ec97d07cd1b6b3faeed"} {"source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.Random;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\npublic class StoryOfCountry {\t\n\tpublic static void main(String[] args) {\n\t\tFS in = new FS();\n\t\tint N = in.nextInt();\n\t\tTreeSet<Rec> hEnd = HE();\n\t\tTreeSet<Rec> hStart = HS();\n\t\tTreeSet<Rec> vEnd = VE();\n\t\tTreeSet<Rec> vStart = VS();\n\t\tfor(int i = 0; i < N; i++) {\n\t\t\tRec r = new Rec(in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt(), i);\n\t\t\thEnd.add(r); hStart.add(r); vEnd.add(r); vStart.add(r);\n\t\t}\n\t\tSystem.out.println(solve(0, hEnd, hStart, vEnd, vStart) ? \"YES\":\"NO\");\n\t}\n\t\n\t/* State:\n\t * 0 -> can be either vertical or horizontal\n\t * 1 -> has to be vertical split\n\t * 2 -> has to be horizontal split\n\t */\n\tstatic boolean solve(int state, TreeSet<Rec> he, TreeSet<Rec> hs, TreeSet<Rec> ve, TreeSet<Rec> vs) {\n\t\tif(he.size() <= 2) return true; // Always possible with just 2 things\n\t\t\n\t\tTreeSet<Rec> lhe = HE();\n\t\tTreeSet<Rec> lhs = HS();\n\t\tTreeSet<Rec> lve = VE();\n\t\tTreeSet<Rec> lvs = VS();\n\t\t\n\t\tTreeSet<Rec> rhe = HE();\n\t\tTreeSet<Rec> rhs = HS();\n\t\tTreeSet<Rec> rve = VE();\n\t\tTreeSet<Rec> rvs = VS();\n\t\t\n\t\tTreeSet<Rec> lhe2 = HE();\n\t\tTreeSet<Rec> lhs2 = HS();\n\t\tTreeSet<Rec> lve2 = VE();\n\t\tTreeSet<Rec> lvs2 = VS();\n\t\t\n\t\tTreeSet<Rec> rhe2 = HE();\n\t\tTreeSet<Rec> rhs2 = HS();\n\t\tTreeSet<Rec> rve2 = VE();\n\t\tTreeSet<Rec> rvs2 = VS();\n\t\t\n\t\tRec lR = null;\n\t\tRec lRS = null;\n\t\tint maxLRS = -1;\n\t\tRec rR = null;\n\t\tRec rRS = null;\n\t\tint minRRS = 2131231231;\n\t\t\n\t\tRec lR2 = null;\n\t\tRec lRS2 = null;\n\t\tint maxLRS2 = -1;\n\t\tRec rR2 = null;\n\t\tRec rRS2 = null;\n\t\tint minRRS2 = 2131231231;\n\t\t\t\n\t\t\t\n\t\twhile((state != 2 && (lR == null || rR == null || lR.x2 < rR.x1)) || (state != 1 && (lR2 == null || rR2 == null || lR2.y2 < rR2.y1))) {\n\t\t\t//do left side\n\t\t\tif(state != 2 && (lR == null || rR == null || lR.x2 < rR.x1)) { \n\t\t\t\tlR = (lR == null ? he.first() : he.higher(lR));\n\t\t\t\tlhe.add(lR);\n\t\t\t\twhile(true) {\n\t\t\t\t\tRec next = (lRS == null ? hs.first() : hs.higher(lRS));\n\t\t\t\t\tif(next == null || next.x1 >= lR.x2) break;\n\t\t\t\t\tmaxLRS = Math.max(maxLRS, next.x2);\n\t\t\t\t\tlRS = next;\n\t\t\t\t}\n\t\t\t\tif(lR.x2 >= maxLRS) { //found a working thing\n\t\t\t\t\tRec r;\n\t\t\t\t\twhile((r = he.higher(lR)) != null && r.x2 == lR.x2){ lhe.add(r); lR = r; }\n\t\t\t\t\t\tfor(Rec rr : lhe) {\n\t\t\t\t\t\t\the.remove(rr); hs.remove(rr); ve.remove(rr); vs.remove(rr);\n\t\t\t\t\t\t\tlhs.add(rr); lve.add(rr); lvs.add(rr);\n\t\t\t\t\t\t}\n\t\t\t\t\treturn solve(2,lhe,lhs,lve,lvs)&&solve(0,he,hs,ve,vs);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t//do right side\n\t\t\t\trR = (rR == null ? hs.last() : hs.lower(rR));\n\t\t\t\trhe.add(rR);\n\t\t\t\twhile(true) {\n\t\t\t\t\tRec next = (rRS == null ? he.last() : he.lower(rRS));\n\t\t\t\t\tif(next == null || next.x2 <= rR.x1) break;\n\t\t\t\t\tminRRS = Math.min(minRRS, next.x1);\n\t\t\t\t\trRS = next;\n\t\t\t\t}\n\t\t\t\tif(rR.x1 <= minRRS) { //found a working thing\n\t\t\t\t\tRec r;\n\t\t\t\t\twhile((r = hs.lower(rR)) != null && r.x1 == rR.x1){ rhe.add(r); rR = r; }\n\t\t\t\t\t\tfor(Rec rr : rhe) {\n\t\t\t\t\t\t\the.remove(rr); hs.remove(rr); ve.remove(rr); vs.remove(rr);\n\t\t\t\t\t\t\trhs.add(rr); rve.add(rr); rvs.add(rr);\n\t\t\t\t\t\t}\n\t\t\t\t\treturn solve(0,he,hs,ve,vs)&&solve(2,rhe,rhs,rve,rvs);\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif(state != 1 && (lR2 == null || rR2 == null || lR2.y2 < rR2.y1)) {\n\t\t\t\t//do left side2\n\t\t\t\tlR2 = (lR2 == null ? ve.first() : ve.higher(lR2));\n\t\t\t\tlhe2.add(lR2);\n\t\t\t\twhile(true) {\n\t\t\t\t\tRec next = (lRS2 == null ? vs.first() : vs.higher(lRS2));\n\t\t\t\t\tif(next == null || next.y1 >= lR2.y2) break;\n\t\t\t\t\tmaxLRS2 = Math.max(maxLRS2, next.y2);\n\t\t\t\t\tlRS2 = next;\n\t\t\t\t}\n\t\t\t\tif(lR2.y2 >= maxLRS2) { //found a working thing\n\t\t\t\t\tRec r;\n\t\t\t\t\twhile((r = ve.higher(lR2)) != null && r.y2 == lR2.y2){ lhe2.add(r); lR2 = r; }\n\t\t\t\t\t\tfor(Rec rr : lhe2) {\n\t\t\t\t\t\t\the.remove(rr); hs.remove(rr); ve.remove(rr); vs.remove(rr);\n\t\t\t\t\t\t\tlhs2.add(rr); lve2.add(rr); lvs2.add(rr);\n\t\t\t\t\t\t}\n\t\t\t\t\treturn solve(1,lhe2,lhs2,lve2,lvs2)&&solve(0,he,hs,ve,vs);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t//do right side2\n\t\t\t\trR2 = (rR2 == null ? vs.last() : vs.lower(rR2));\n\t\t\t\trhe2.add(rR2);\n\t\t\t\twhile(true) {\n\t\t\t\t\tRec next = (rRS2 == null ? ve.last() : ve.lower(rRS2));\n\t\t\t\t\tif(next == null || next.y2 <= rR2.y1) break;\n\t\t\t\t\tminRRS2 = Math.min(minRRS2, next.y1);\n\t\t\t\t\trRS2 = next;\n\t\t\t\t}\n\t\t\t\tif(rR2.y1 <= minRRS2) { //found a working thing\n\t\t\t\t\tRec r;\n\t\t\t\t\twhile((r = vs.lower(rR2)) != null && r.y1 == rR2.y1){ rhe2.add(r); rR2 = r; }\n\t\t\t\t\t\tfor(Rec rr : rhe2) {\n\t\t\t\t\t\t\the.remove(rr); hs.remove(rr); ve.remove(rr); vs.remove(rr);\n\t\t\t\t\t\t\trhs2.add(rr); rve2.add(rr); rvs2.add(rr);\n\t\t\t\t\t\t}\n\t\t\t\t\treturn solve(0,he,hs,ve,vs)&&solve(1,rhe2,rhs2,rve2,rvs2);\n\t\t\t\t}\n\t\t\t}\n\t\t}\t\n\t\treturn false;\n\t}\n\t\n\tstatic TreeSet<Rec> HE() {\n\t\treturn new TreeSet<Rec>((a,b) -> (a.x2 == b.x2 ? a.id-b.id : a.x2-b.x2));\n\t}\n\tstatic TreeSet<Rec> HS(){\n\t\treturn new TreeSet<Rec>((a,b) -> (a.x1 == b.x1 ? a.id-b.id : a.x1-b.x1));\t\t\n\t}\n\tstatic TreeSet<Rec> VE(){\n\t\treturn new TreeSet<Rec>((a,b) -> (a.y2 == b.y2 ? a.id-b.id : a.y2-b.y2));\n\t}\n\tstatic TreeSet<Rec> VS(){\n\t\treturn new TreeSet<Rec>((a,b) -> (a.y1 == b.y1 ? a.id-b.id : a.y1-b.y1));\t\t\n\t}\n\tstatic class Rec{\n\t\tint x1,y1,x2,y2,id;\n\t\tpublic Rec(int a, int b, int c, int d, int ii) {\n\t\t\tx1=a; y1=b; x2=c; y2=d;\n\t\t\tid=ii;\n\t\t}\n\t}\n\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));\t\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}\n}", "src_uid": "5bfb165b4efe081d6a8c4843f7769a37"} {"source_code": "\nimport 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 long t = input.nextLong();\n long s = input.nextLong();\n long x = input.nextLong();\n\n if ((x - t) % s == 0 && (x - t) >= 0) {\n System.out.println(\"YES\");\n } else if ((x - t - 1) % s == 0 && (x - t - 1) != 0 && (x - t - 1) > 0) {\n System.out.println(\"YES\");\n } else {\n System.out.println(\"No\");\n }\n\n }\n\n}\n", "src_uid": "3baf9d841ff7208c66f6de1b47b0f952"} {"source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\n\npublic class CF_574A_BearAndElections {\n\t\n\tstatic Scanner user_input ;\n\tstatic int n ;\n\tstatic int m0 ;\n\tstatic int m[];\n\tpublic static void main(String Args[])\n\t{\nuser_input = new Scanner( System.in );\nint count=0;\n\t\tn=user_input.nextInt();\n\t\tm = new int[n-1];\n\t\tm0=user_input.nextInt();\n\t\tfor(int i=0;i<n-1;i++)\n\t\t{\n\t\t\tm[i]=user_input.nextInt();\n\t\t}\n\t\t\n\t\t Arrays.sort(m);\n\t\twhile(m0<=m[n-2])\n\t\t{\n\t\t\tm[n-2]--;\n\t\t\tm0++;\n\t\t\t\n\t\t\tcount++;\n\t\t\tArrays.sort(m);\n\t\t}\n\t\tSystem.out.println(count);\n\t\t \n\t}\n\n}\n\n\n\n", "src_uid": "aa8fabf7c817dfd3d585b96a07bb7f58"} {"source_code": "import java.util.Scanner;\r\n\r\npublic class Main {\r\n\r\n public static String reverseStringWithCharAt(String inputString) {\r\n int stringLength = inputString.length();\r\n String result = \"\";\r\n for (int i = 0; i < stringLength; i++) {\r\n result = inputString.charAt(i) + result;\r\n }\r\n return result;\r\n }\r\n\r\n public static void main(String[] args) {\r\n Scanner in = new Scanner(System.in);\r\n //int num = in.nextInt();\r\n long x = in.nextLong();\r\n long y = in.nextLong();\r\n String X = Long.toBinaryString(x);\r\n if (X.equals(reverseStringWithCharAt(Long.toBinaryString(Long.parseLong(reverseStringWithCharAt(X), 2))))) {\r\n String XX = reverseStringWithCharAt(X);\r\n XX = Long.toBinaryString(Long.parseLong(XX, 2));\r\n String Y = Long.toBinaryString(y);\r\n int k = 0;\r\n for (int i = 0; i < Y.length(); i++) {\r\n int l = X.length();\r\n if (i + l <= Y.length()) {\r\n if (X.equals(Y.substring(i, i + l))) {\r\n k = 1;\r\n for (int j = 0; j < i; j++) {\r\n if (Y.charAt(j) == '0') {\r\n k = 0;\r\n }\r\n }\r\n for (int j = i + l; j < Y.length(); j++) {\r\n if (Y.charAt(j) == '0') {\r\n k = 0;\r\n }\r\n }\r\n }\r\n if (k == 1) {\r\n System.out.println(\"YES\");\r\n return;\r\n }\r\n }\r\n l = XX.length();\r\n if (i + l <= Y.length()) {\r\n if (XX.equals(Y.substring(i, i + l))) {\r\n k = 1;\r\n for (int j = 0; j < i; j++) {\r\n if (Y.charAt(j) == '0') {\r\n k = 0;\r\n }\r\n }\r\n for (int j = i + l; j < Y.length(); j++) {\r\n if (Y.charAt(j) == '0') {\r\n k = 0;\r\n }\r\n }\r\n }\r\n if (k == 1) {\r\n System.out.println(\"YES\");\r\n return;\r\n }\r\n }\r\n\r\n }\r\n } else {\r\n int l = X.length();\r\n String Y = Long.toBinaryString(y);\r\n int i = 0;\r\n int k = 0;\r\n if (X.equals(Y)) {\r\n System.out.println(\"YES\");\r\n return;\r\n }\r\n String oldX = X;\r\n X += \"1\";\r\n X = reverseStringWithCharAt(X);\r\n X = Long.toBinaryString(Long.parseLong(X, 2));\r\n String XX = reverseStringWithCharAt(X);\r\n XX = Long.toBinaryString(Long.parseLong(XX, 2));\r\n k = 0;\r\n for (i = 0; i < Y.length(); i++) {\r\n l = X.length();\r\n if (i + l <= Y.length()) {\r\n if (X.equals(Y.substring(i, i + l))) {\r\n k = 1;\r\n for (int j = 0; j < i; j++) {\r\n if (Y.charAt(j) == '0') {\r\n k = 0;\r\n }\r\n }\r\n for (int j = i + l; j < Y.length(); j++) {\r\n if (Y.charAt(j) == '0') {\r\n k = 0;\r\n }\r\n }\r\n }\r\n if (k == 1) {\r\n System.out.println(\"YES\");\r\n return;\r\n }\r\n }\r\n l = XX.length();\r\n if (i + l <= Y.length()) {\r\n if (XX.equals(Y.substring(i, i + l))) {\r\n k = 1;\r\n for (int j = 0; j < i; j++) {\r\n if (Y.charAt(j) == '0') {\r\n k = 0;\r\n }\r\n }\r\n for (int j = i + l; j < Y.length(); j++) {\r\n if (Y.charAt(j) == '0') {\r\n k = 0;\r\n }\r\n }\r\n }\r\n if (k == 1) {\r\n System.out.println(\"YES\");\r\n return;\r\n }\r\n }\r\n }\r\n\r\n X = oldX;\r\n X = reverseStringWithCharAt(X);\r\n X = Long.toBinaryString(Long.parseLong(X, 2));\r\n XX = reverseStringWithCharAt(X);\r\n XX = Long.toBinaryString(Long.parseLong(XX, 2));\r\n k = 0;\r\n for (i = 0; i < Y.length(); i++) {\r\n l = X.length();\r\n if (i + l <= Y.length()) {\r\n if (X.equals(Y.substring(i, i + l))) {\r\n k = 1;\r\n for (int j = 0; j < i; j++) {\r\n if (Y.charAt(j) == '0') {\r\n k = 0;\r\n }\r\n }\r\n for (int j = i + l; j < Y.length(); j++) {\r\n if (Y.charAt(j) == '0') {\r\n k = 0;\r\n }\r\n }\r\n }\r\n if (k == 1) {\r\n System.out.println(\"YES\");\r\n return;\r\n }\r\n }\r\n l = XX.length();\r\n if (i + l <= Y.length()) {\r\n if (XX.equals(Y.substring(i, i + l))) {\r\n k = 1;\r\n for (int j = 0; j < i; j++) {\r\n if (Y.charAt(j) == '0') {\r\n k = 0;\r\n }\r\n }\r\n for (int j = i + l; j < Y.length(); j++) {\r\n if (Y.charAt(j) == '0') {\r\n k = 0;\r\n }\r\n }\r\n }\r\n if (k == 1) {\r\n System.out.println(\"YES\");\r\n return;\r\n }\r\n }\r\n }\r\n }\r\n System.out.println(\"NO\");\r\n return;\r\n }\r\n}", "src_uid": "9f39a3c160087beb0efab2e3cb510e89"} {"source_code": "\nimport java.util.*;\n\npublic class CODE {\n\n static Scanner sc = new Scanner(System.in);\n\n public static void main(String[] args) {\n int T = sc.nextInt();\n int S = sc.nextInt();\n int Q = sc.nextInt();\n int c = 1;\n for (int i = 0; true; i++) {\n if (S >= T) {\n System.out.println(c);\n break;\n }\n\n int s = S;// store the old value of \"s\" \n if (i % Q == 0) {\n S += (Q - 1);\n }\n\n if (i == s) {\n i = 0;\n c++;\n }\n }\n }\n\n}\n", "src_uid": "0d01bf286fb2c7950ce5d5fa59a17dd9"} {"source_code": "import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\nimport java.io.IOException;\nimport java.lang.*;\n\npublic class JavaApplication7 {\n static int[] winners;\n static int ans;\n \n public static boolean contains(final int[] array, final int key) {\n for (final int i : array) {\n if (i == key) {\n return true;\n }\n }\n return false;\n}\n \n public static void findwinners(int s)\n {\n int i = (s/50) % 475;\n for (int j = 0; j<25;j++)\n {\n i =(i * 96 + 42) % 475;\n winners[j]=26 + i; \n } \n }\n\n public static void main(String[] args) throws IOException{\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n PrintWriter pw = new PrintWriter(System.out);\n StringTokenizer st = new StringTokenizer(br.readLine());\n int p = Integer.parseInt(st.nextToken());\n int x = Integer.parseInt(st.nextToken());\n int y = Integer.parseInt(st.nextToken());\n winners = new int[25];\n int z = x;\n while(z>=y+50)\n {\n z=z-50;\n } \n //int target;\n findwinners(z);\n while(!contains(winners,p))\n {\n z=z+50;\n findwinners(z); \n \n \n }\n //pw.println(z);\n //for(int i=0;i<25;i++){\n //pw.println(winners[i]);}\n if(x>=z) ans=0;\n else ans = (z+50-x)/100;\n pw.println(ans);\n pw.close();\n }\n \n}", "src_uid": "c9c22e03c70a94a745b451fc79e112fd"} {"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 * @author khokharnikunj8\n */\npublic class Main {\n public static void main(String[] args) throws Exception {\n Thread thread = new Thread(null, new TaskAdapter(), \"khokharnikunj8\", 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 CBinarySearch solver = new CBinarySearch();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class CBinarySearch {\n Modular md = new Modular(1000000007);\n Factorial fc = new Factorial(10000, md);\n\n public int get(int n, int r) {\n return md.mul(fc.fact(n), md.mul(fc.inv(r), fc.inv(n - r)));\n }\n\n public void solve(int testNumber, FastInput in, FastOutput out) {\n int n = in.readInt();\n int x = in.readInt();\n int pos = in.readInt();\n int low = 0;\n int high = n;\n int smaller = 0;\n int greater = 0;\n while (low < high) {\n int mid = (low + high) >> 1;\n if (pos == mid) {\n low = mid + 1;\n continue;\n }\n if (pos < mid) {\n greater++;\n high = mid;\n } else {\n smaller++;\n low = mid + 1;\n }\n }\n int ans = 1;\n if (x - 1 < smaller || n - x < greater) {\n out.println(0);\n return;\n }\n ans = md.mul(ans, get(x - 1, smaller));\n ans = md.mul(ans, get(n - x, greater));\n ans = md.mul(ans, fc.fact(smaller));\n ans = md.mul(ans, fc.fact(greater));\n int rem = n - 1 - smaller - greater;\n ans = md.mul(ans, fc.fact(rem));\n out.println(ans);\n\n }\n\n }\n\n static class Factorial {\n int[] fact;\n int[] inv;\n Modular modular;\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 inv(int n) {\n return inv[n];\n }\n\n }\n\n static class Modular {\n private final int mod;\n\n public Modular(int mod) {\n this.mod = mod;\n }\n\n public Modular(long mod) {\n this((int) mod);\n if (this.mod != mod) throw new IllegalArgumentException();\n }\n\n public Modular(double mod) {\n this((int) mod);\n if (this.mod != mod) throw new IllegalArgumentException();\n }\n\n public int getMod() {\n return this.mod;\n }\n\n public int valueOf(long x) {\n x %= mod;\n if (x < 0) x += mod;\n return (int) x;\n }\n\n public int mul(int x, int y) {\n return valueOf((long) x * y);\n }\n\n public String toString() {\n return \"Mod : \" + mod;\n }\n\n }\n\n static class InverseNumber {\n int[] inv;\n Modular modular;\n\n public InverseNumber(int[] inv, int limit, Modular modular) {\n this.modular = modular;\n this.inv = inv;\n inv[1] = 1;\n int mod = modular.getMod();\n for (int i = 2; i <= limit; i++) inv[i] = modular.mul(-(mod / i), inv[mod % i]);\n }\n\n public InverseNumber(int limit, Modular modular) {\n this(new int[limit + 1], limit, modular);\n }\n\n public int inv(int index) {\n return inv[index];\n }\n\n }\n\n static class FastOutput implements AutoCloseable, Closeable, Appendable {\n private final Writer os;\n private final StringBuilder cache = new StringBuilder(5 << 20);\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(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 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 final 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", "src_uid": "24e2f10463f440affccc2755f4462d8a"} {"source_code": "import java.io.*;\nimport java.util.*;\n\n/******************************\\\n * The solution is at the top *\n * *\n * Created by : azhar556 *\n\\******************************/\n\npublic class Solution {\n static void solve() {\n int n = ni();\n int m = ni();\n int k = ni();\n int[] s = new int[n];\n int[] b = new int[m];\n int minBuy = Integer.MAX_VALUE;\n int maxSell = 0;\n for (int i = 0; i < n; i++) {\n s[i] = ni();\n if (s[i] < minBuy) minBuy = s[i];\n }\n for (int i = 0; i < m; i++) {\n b[i] = ni();\n if (b[i] > maxSell) maxSell = b[i];\n }\n int res = (k / minBuy) * maxSell + k % minBuy;\n out.println(Math.max(res, k));\n } \n\n public static void main(String[] args) {\n long time = System.currentTimeMillis();\n int t;// = ni();\n t = 1;\n while (t-- > 0) solve(); \n err.println(\"Time elapsed : \" + (System.currentTimeMillis() - time) / 1000F + \" s.\");\n err.close(); out.close();\n }\n\n static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n static PrintWriter err = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.err)));\n static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n static StringTokenizer token;\n \n static String ns() {\n while (token == null || !token.hasMoreTokens()) {\n try {\n token = new StringTokenizer(br.readLine());\n }\n catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return token.nextToken();\n }\n static char nc() {\n return Character.valueOf(ns().charAt(0));\n }\n static int ni() {\n return Integer.parseInt(ns());\n }\n static double nd() {\n return Double.parseDouble(ns());\n }\n static long nl() {\n return Long.parseLong(ns());\n }\n}\n", "src_uid": "42f25d492bddc12d3d89d39315d63cb9"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n\n static class FastReader\n {\n BufferedReader br;\n StringTokenizer st;\n\n public FastReader()\n {\n br = new BufferedReader(new\n InputStreamReader(System.in));\n }\n\n String next()\n {\n while (st == null || !st.hasMoreElements())\n {\n try\n {\n st = new StringTokenizer(br.readLine());\n }\n catch (IOException e)\n {\n e.printStackTrace();\n }\n }\n return st.nextToken();\n }\n\n int nextInt()\n {\n return Integer.parseInt(next());\n }\n\n long nextLong()\n {\n return Long.parseLong(next());\n }\n\n double nextDouble()\n {\n return Double.parseDouble(next());\n }\n\n String nextLine()\n {\n String str = \"\";\n try\n {\n str = br.readLine();\n }\n catch (IOException e)\n {\n e.printStackTrace();\n }\n return str;\n }\n }\n\n static class Reader\n {\n final private int BUFFER_SIZE = 1 << 16;\n private final DataInputStream din;\n private final byte[] buffer;\n private int bufferPointer, bytesRead;\n\n public Reader()\n {\n din = new DataInputStream(System.in);\n buffer = new byte[BUFFER_SIZE];\n bufferPointer = bytesRead = 0;\n }\n\n public Reader(String file_name) throws IOException\n {\n din = new DataInputStream(new FileInputStream(file_name));\n buffer = new byte[BUFFER_SIZE];\n bufferPointer = bytesRead = 0;\n }\n\n public String readLine() throws IOException\n {\n byte[] buf = new byte[64]; // line length\n int cnt = 0, c;\n while ((c = read()) != -1)\n {\n if (c == '\\n')\n break;\n buf[cnt++] = (byte) c;\n }\n return new String(buf, 0, cnt);\n }\n\n public int nextInt() throws IOException\n {\n int ret = 0;\n byte c = read();\n while (c <= ' ')\n c = read();\n boolean neg = (c == '-');\n if (neg)\n c = read();\n do\n {\n ret = ret * 10 + c - '0';\n } while ((c = read()) >= '0' && c <= '9');\n\n if (neg)\n return -ret;\n return ret;\n }\n\n public long nextLong() throws IOException\n {\n long ret = 0;\n byte c = read();\n while (c <= ' ')\n c = read();\n boolean neg = (c == '-');\n if (neg)\n c = read();\n do {\n ret = ret * 10 + c - '0';\n }\n while ((c = read()) >= '0' && c <= '9');\n if (neg)\n return -ret;\n return ret;\n }\n\n public double nextDouble() throws IOException\n {\n double ret = 0, div = 1;\n byte c = read();\n while (c <= ' ')\n c = read();\n boolean neg = (c == '-');\n if (neg)\n c = read();\n\n do {\n ret = ret * 10 + c - '0';\n }\n while ((c = read()) >= '0' && c <= '9');\n\n if (c == '.')\n {\n while ((c = read()) >= '0' && c <= '9')\n {\n ret += (c - '0') / (div *= 10);\n }\n }\n\n if (neg)\n return -ret;\n return ret;\n }\n\n private void fillBuffer() throws IOException\n {\n bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);\n if (bytesRead == -1)\n buffer[0] = -1;\n }\n\n private byte read() throws IOException\n {\n if (bufferPointer == bytesRead)\n fillBuffer();\n return buffer[bufferPointer++];\n }\n\n public void close() throws IOException\n {\n if (din == null)\n return;\n din.close();\n }\n }\n\n static long MOD = (long) (1e9 + 7);\n\n static long powerLL(long x, long n)\n {\n long result = 1;\n while (n > 0)\n {\n if (n % 2 == 1)\n {\n result = result * x % MOD;\n }\n n = n / 2;\n x = x * x % MOD;\n }\n return result;\n }\n\n static long powerStrings(String sa, String sb)\n {\n long a = 0, b = 0;\n\n for (int i = 0; i < sa.length(); i++)\n {\n a = (a * 10 + (sa.charAt(i) - '0')) %\n MOD;\n }\n\n for (int i = 0; i < sb.length(); i++)\n {\n b = (b * 10 + (sb.charAt(i) - '0')) %\n (MOD - 1);\n }\n\n return powerLL(a, b);\n }\n\n static long gcd(long a, long b)\n {\n if (a==0) return b;\n else return gcd(b%a,a);\n }\n\n static long lcm(long a, long b)\n {\n return (a*b)/gcd(a,b);\n }\n\n static int lower_bound(List<Integer> list, int k)\n {\n int s = 0;\n int e = list.size();\n\n while (s!=e)\n {\n int mid = (s+e)>>1;\n\n if (list.get(mid)<k) s = mid+1;\n else e = mid;\n }\n\n if (s == list.size()) return -1;\n return s;\n }\n\n static int upper_bound(List<Integer> list, int k)\n {\n int s = 0;\n int e = list.size();\n\n while (s!=e)\n {\n int mid = (s+e)>>1;\n\n if (list.get(mid)<=k) s = mid+1;\n else e = mid;\n }\n\n if (s == list.size()) return -1;\n return s;\n }\n\n static void addEdge(ArrayList<ArrayList<Integer>>graph, int edge1, int edge2)\n {\n graph.get(edge1).add(edge2);\n graph.get(edge2).add(edge1);\n }\n\n static class Pair<X,Y>\n {\n public final X first;\n public final Y second;\n\n Pair(X first, Y second)\n {\n this.first = first;\n this.second = second;\n }\n\n public static <X,Y> Pair <X,Y> of (X a, Y b)\n {\n return new Pair<>(a,b);\n }\n\n public String toString()\n {\n return \"(\"+first+\",\"+second+\")\";\n }\n }\n\n static class Comparee\n {\n static void compare(List<Pair<Integer, Integer>> pairs, int m)\n {\n Collections.sort(pairs, new Comparator<Pair<Integer, Integer>>() {\n @Override\n public int compare(Pair<Integer, Integer> p1, Pair<Integer, Integer> p2) {\n return p1.second - p2.second;\n }\n });\n }\n }\n\n public static void main(String[] args) throws java.lang.Exception\n {\n try\n {\n //FastReader fr = new FastReader();\n Reader fr = new Reader();\n\n try(OutputStream out = new BufferedOutputStream(System.out))\n {\n int n = fr.nextInt();\n int m = fr.nextInt();\n\n List<Pair<Integer,Integer>> pairs = new ArrayList<>();\n Pair<Integer, Integer> p1;\n\n for (int i=0;i<m;i++)\n {\n p1 = Pair.of(fr.nextInt(), fr.nextInt());\n\n pairs.add(p1);\n }\n\n //out.write((pairs+\"\").getBytes());\n Comparee.compare(pairs,m);\n\n //for (int i=0;i<m;i++) out.write((pairs.get(i).first+\" \"+pairs.get(i).second+\"\\n\").getBytes());\n\n long sum = 0;\n int count = 0;\n\n for (int i=m-1;i>=0;i--)\n {\n if (pairs.get(i).first<=n-count)\n {\n count+=pairs.get(i).first;\n sum+=(pairs.get(i).first * pairs.get(i).second);\n }\n else\n {\n int c = n-count;\n sum+=(c*pairs.get(i).second);\n count+=c;\n }\n\n if (count == n) break;\n }\n\n out.write((sum+\"\").getBytes());\n\n out.flush();\n }\n\n }\n\n catch(Exception e){}\n finally{}\n }\n}\n\n\n//(()) () (()((()()()())))", "src_uid": "c052d85e402691b05e494b5283d62679"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\npublic class V {\n\tpublic static void main(String[] args) throws IOException {\n\t\t BufferedReader x = new BufferedReader(new InputStreamReader(System.in));\n\t\t int b=Integer.parseInt(x.readLine());\n\t\t int c=Integer.parseInt(x.readLine());\n\t\t int d=Integer.parseInt(x.readLine());\n\t\t System.out.println( (1+((b>d&&c>d)?d:(b<=d&&c>=d)?b:(b<d&&c<d)?b+c-d:c)));\t\t \n\t}\t\n}\n", "src_uid": "9266a69e767df299569986151852e7b1"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\npublic class Main\n{\n public static void main(String[] args) throws Exception\n {\n int[][] cost = new int[][]\n {\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 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n char[][] map = new char[6][];\n for (int y = 0; y < 6; y++)\n {\n String line = br.readLine();\n map[y] = line.toCharArray();\n }\n int maxCost = 0, maxY = 0, maxX = 0;\n for (int y = 0; y < 6; y++)\n {\n for (int x = 0, i = 0; x < 8; x++)\n {\n if (map[y][x] == '.')\n {\n int currCost = cost[y][i];\n if (currCost > maxCost)\n {\n maxCost = currCost;\n maxY = y;\n maxX = x;\n }\n }\n if (map[y][x] != '-')\n i++;\n }\n }\n map[maxY][maxX] = 'P';\n for (int y = 0; y < 6; y++)\n {\n for (int x = 0; x < 8; x++)\n System.out.print(map[y][x]);\n System.out.println();\n }\n }\n}", "src_uid": "35503a2aeb18c8c1b3eda9de2c6ce33e"} {"source_code": "/*\t/ \uff8c\uff8c\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u30e0\n\t/ )\\\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800\u2800 Y\n\t(\u2800\u2800| ( \u0361\u00b0 \u035c\u0296 \u0361\u00b0\uff09\u2800\u2312(\u2800 \u30ce\n\t(\u2800 \uff89\u2312 Y \u2312\u30fd-\u304f __\uff0f\n\t| _\u2800\uff61\u30ce| \u30ce\uff61 |/\n\t(\u2800\u30fc '_\u4eba`\u30fc \uff89\n\t\u2800|\\ \uffe3 _\u4eba'\u5f61\uff89\n\t\u2800 )\\\u2800\u2800 \uff61\u2800\u2800 /\n\t\u2800\u2800(\\\u2800 #\u2800 /\n\t\u2800/\u2800\u2800\u2800/\u1f63====================D-\n\t/\u2800\u2800\u2800/\u2800 \\ \\\u2800\u2800\\\n\t( (\u2800)\u2800\u2800\u2800\u2800 ) ).\u2800)\n\t(\u2800\u2800)\u2800\u2800\u2800\u2800\u2800( | /\n\t|\u2800 /\u2800\u2800\u2800\u2800\u2800\u2800 | /\n\t[_] \u2800\u2800\u2800\u2800\u2800[___] */\n// Main Code at the Bottom\nimport java.util.*;\nimport java.lang.*;\nimport java.io.*;\npublic class Main {\n\t//Fast IO class\n static class FastReader {\n BufferedReader br; \n StringTokenizer st; \n public FastReader() {\n \tboolean env=System.getProperty(\"ONLINE_JUDGE\") != null;\n \tif(!env) {\n \t\ttry {\n\t\t\t\t\tbr=new BufferedReader(new FileReader(\"src\\\\input.txt\"));\n\t\t\t\t} catch (FileNotFoundException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n \t}\n \telse br = new BufferedReader(new InputStreamReader(System.in)); \n } \n String next() {\n while (st == null || !st.hasMoreElements()) {\n try {\n st = new StringTokenizer(br.readLine()); \n } \n catch (IOException e) {\n e.printStackTrace(); \n } \n } \n return st.nextToken(); \n } \n int nextInt() {\n return Integer.parseInt(next()); \n } \n long nextLong() {\n return Long.parseLong(next()); \n } \n double nextDouble() {\n return Double.parseDouble(next()); \n } \n String nextLine() {\n String str = \"\"; \n try {\n str = br.readLine(); \n } \n catch (IOException e) {\n e.printStackTrace(); \n } \n return str; \n } \n } \n static long MOD=1000000000+7;\n //Euclidean Algorithm\n static long gcd(long A,long B){\n if(B==0) return A;\n return gcd(B,A%B);\n }\n //Modular Exponentiation\n static long fastExpo(long x,long n){\n if(n==0) return 1;\n if((n&1)==0) return fastExpo((x*x)%MOD,n/2)%MOD;\n return ((x%MOD)*fastExpo((x*x)%MOD,(n-1)/2))%MOD;\n }\n //Modular Inverse\n static long inverse(long x) {\n \treturn fastExpo(x,MOD-2);\n }\n //Prime Number Algorithm\n static boolean isPrime(long n){\n if(n<=1) return false;\n if(n<=3) return true;\n if(n%2==0 || n%3==0) return false;\n for(int i=5;i*i<=n;i+=6) if(n%i==0 || n%(i+2)==0) return false;\n return true;\n }\n //Reverse an array\n static void reverse(int arr[],int l,int r){\n \twhile(l<r) {\n \t\tint tmp=arr[l];\n \t\tarr[l++]=arr[r];\n \t\tarr[r++]=tmp;\n \t}\n }\n //Print array\n static void print1d(int arr[]) {\n \tout.println(Arrays.toString(arr));\n }\n static void print2d(int arr[][]) {\n \tfor(int a[]: arr) out.println(Arrays.toString(a));\n }\n // Pair\n static class pair{\n \tlong x,y;\n \tpair(long a,long b){\n \t\tthis.x=a;\n \t\tthis.y=b;\n \t}\n \tpublic boolean equals(Object obj) {\n \t\tif(obj == null || obj.getClass()!= this.getClass()) return false;\n pair p = (pair) obj;\n return (this.x==p.x && this.y==p.y);\n }\n \tpublic int hashCode() {\n return Objects.hash(x,y);\n }\n }\n static FastReader sc=new FastReader();\n static PrintWriter out=new PrintWriter(System.out);\n //Main function(The main code starts from here)\n public static void main (String[] args) throws java.lang.Exception {\n \tint test=1;\n while(test-->0) {\n \tint n=sc.nextInt(),m=sc.nextInt(),b[]=new int[n];\n \tfor(int i=0;i<m;i++) {\n \t\tint a=sc.nextInt();\n \t\tfor(int j=a-1;j<n;j++) if(b[j]==0) b[j]=a;\n \t}\n \tfor(int i: b) out.print(i+\" \");\n \t\n } \t\n out.flush();\n out.close();\n }\n}", "src_uid": "2e44c8aabab7ef7b06bbab8719a8d863"} {"source_code": "import java.util.*;\n\npublic class C {\n\tprivate static Scanner in;\n\t\n\tint n;\n\tlong[] a;\n\tint[] p;\n\tint sumP;\n\tint ans;\n\n\tpublic void run() {\n\t\tn = in.nextInt();\n\t\ta = new long[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] = in.nextLong();\n\t\t}\n\t\tArrays.sort(a);\n\t\tp = new int[n];\n\t\tsumP = 0;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tlong v = a[i];\n\t\t\tfor (int t = 2; t * (long) t <= v; t++) {\n\t\t\t\twhile (v % t == 0) {\n\t\t\t\t\tv /= t;\n\t\t\t\t\tp[i]++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (v > 1) {\n\t\t\t\tp[i]++;\n\t\t\t}\n\t\t\tif (p[i] > 1) {\n\t\t\t\tsumP += p[i];\n\t\t\t}\n\t\t}\n\t\tans = Integer.MAX_VALUE;\n\t\tsearch(0, 0);\n\t\tSystem.out.println(ans);\n\t}\n\n\tvoid search(int state, int count) {\n\t\tint top = 1;\n\t\tif (Integer.bitCount(state) == 2 * n - 1 || n == 1) {\n\t\t\ttop = 0;\n\t\t}\n\t\tans = Math.min(ans, top + n + sumP - count);\n\t\tfor (int t = 0; t < n; t++) {\n\t\t\tif (((state >> (2 * t)) & 3) != 0) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tsearch(state, count, t, 0, a[t], 0);\n\t\t}\n\t}\n\n\tvoid search(int state, int count, int t, int x, long m, int taken) {\n\t\twhile (x < n && (x == t || ((state >> (2 * x)) & 3) == 3 || m % a[x] != 0)) {\n\t\t\tx++;\n\t\t}\n\t\tif (x == n) {\n\t\t\tif (taken == 0) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tstate |= 2 << (2 * t);\n\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\tif (((taken >> i) & 1) == 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tstate |= 3 << (2 * i);\n\t\t\t\tcount += p[i];\n\t\t\t}\n\t\t\tsearch(state, count);\n\t\t\treturn;\n\t\t}\n\t\tsearch(state, count, t, x + 1, m, taken);\n\t\tsearch(state, count, t, x + 1, m / a[x], taken | (1 << x));\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tLocale.setDefault(Locale.US);\n\t\tin = new Scanner(System.in);\n\t\tnew C().run();\n\t\tin.close();\n\t}\n}\n// 8 2 3 4 5 6 7 8 9", "src_uid": "52b8b6c68518d5129272b8c56e5b7662"} {"source_code": "import java.util.Scanner;\n\npublic class CF306A {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int m = sc.nextInt();\n int[] arr = new int[m];\n int div = (int) n/m;\n int left = n%m;\n for (int i = 0; i < m; i++) {\n arr[i] = div;\n }\n int i=m-1;\n while(left>0){\n arr[i]++;\n i--;\n left--;\n }\n\n\n for(i=0;i<m;i++)\n System.out.print(arr[i]+\" \");\n }\n}\n", "src_uid": "0b2c1650979a9931e00ffe32a70e3c23"} {"source_code": "import java.io.OutputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.PrintWriter;\nimport java.util.stream.IntStream;\nimport java.util.Arrays;\nimport java.util.Set;\nimport java.util.HashMap;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\nimport java.util.Map;\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 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 AStoloviePribori solver = new AStoloviePribori();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class AStoloviePribori {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt(), k = in.nextInt();\n int[] a = in.nextArr(n);\n\n Map<Integer, Integer> multiSet = GeekMath.multiSet(a);\n\n int amountIn = multiSet.keySet().size();\n int max = Integer.MIN_VALUE;\n for (Integer integer : multiSet.keySet()) {\n max = Math.max(max, multiSet.get(integer));\n }\n int cou = GeekMath.ceiling(max, k);\n\n out.println(cou * amountIn * k - n);\n\n }\n\n }\n\n static class GeekMath {\n public static Map<Integer, Integer> multiSet(int[] arr) {\n Map<Integer, Integer> co = new HashMap<>();\n for (int i : arr) {\n co.merge(i, 1, Integer::sum);\n }\n return co;\n }\n\n public static int ceiling(int n, int k) {\n return (n + k - 1) / k;\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 public int[] nextArr(int size) {\n return Arrays.stream(new int[size]).map(c -> nextInt()).toArray();\n }\n\n }\n}\n\n", "src_uid": "c03ff0bc6a8c4ce5372194e8ea18527f"} {"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\tDeque<Integer> q;\n\t\tboolean[] visited;\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\tq = new ArrayDeque<>();\n\t\t\tvisited = new boolean[n];\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\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<Integer> specialCase1 = new ArrayList<>();\n\t\t\tList<Integer> specialCase2 = new ArrayList<>();\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\tspecialCase1.add(i);\n\t\t\t\tif(L[i] == p.length - 2 && R[i] == -1) \n\t\t\t\t\tspecialCase2.add(i);\n\t\t\t}\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\n\t\t\t/*\n\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\n\t\t\t */\n\t\t\t\n\t\t\tDeque<Integer> unvisit = new ArrayDeque<>();\n\t\t\tArrays.fill(in, 0);\n\t\t\tArrays.fill(out, 0);\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\tif(i > 0 && valid[i - 1]) {\n\t\t\t\t\tint reachableNodes = 0;\n\t\t\t\t\tq.add(candidate[i - 1]);\n\t\t\t\t\tvisited[candidate[i - 1]] = 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\tunvisit.add(u);\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\tin[candidate[i - 1]] += reachableNodes;\n\t\t\t\t\tif(i > 0) in[candidate[i - 1]] += in[p[i - 1]] + 1;\n\t\t\t\t\twhile(!unvisit.isEmpty())\n\t\t\t\t\t\tvisited[unvisit.pop()] = false;\n\t\t\t\t}\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\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(i > 0 && valid[i - 1]) {\n\t\t\t\t\tint reachableNodes = 0;\n\t\t\t\t\tq.add(candidate[i - 1]);\n\t\t\t\t\tvisited[candidate[i - 1]] = 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\tunvisit.add(u);\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\tout[candidate[i - 1]] += reachableNodes;\n\t\t\t\t\tif(i < p.length - 1) out[candidate[i - 1]] += out[p[i + 1]] + 1;\n\t\t\t\t\twhile(!unvisit.isEmpty())\n\t\t\t\t\t\tvisited[unvisit.pop()] = false;\n\t\t\t\t}\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\t/*\n\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\n\t\t\t */\n\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\n\t\t\t/*\n\n\t\t\tOh, and there are gay special cases, like this:\n\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\tAll nodes that are in this special case are in list specialCase1\n\n\n\t\t\tAhh, and this one:\n\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\n\t\t\tAll nodes that are in this special case are int list specialCase2\n\n\t\t\tIf there is more than 1 node in either special case list, then that whole\n\t\t\tspecial case list cannot work.\n\n\t\t\t */\n\t\t\t\n\t\t\tres += specialCaseCheck(specialCase1) + specialCaseCheck(specialCase2);\n\n\t\t\treturn res;\n\t\t}\n\t\tint specialCaseCheck(List<Integer> specialCases) {\n\t\t\tif(specialCases.size() != 1)\n\t\t\t\treturn 0;\n\t\t\tint sc = specialCases.get(0);\n\t\t\tArrays.fill(visited, false);\n\t\t\tvisited[sc] = true;\n\t\t\tq.add(sc);\n\t\t\tint incnt = 0, outcnt = 0;\n\t\t\twhile(!q.isEmpty()) {\n\t\t\t\tint u = q.pop();\n\t\t\t\tfor(int v : adj[u]) {\n\t\t\t\t\tif(!visited[v]) {\n\t\t\t\t\t\tvisited[v] = true;\n\t\t\t\t\t\tq.add(v);\n\t\t\t\t\t\toutcnt++;\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\tvisited[sc] = true;\n\t\t\tq.add(sc);\n\t\t\twhile(!q.isEmpty()) {\n\t\t\t\tint u = q.pop();\n\t\t\t\tfor(int v : rev[u]) {\n\t\t\t\t\tif(!visited[v]) {\n\t\t\t\t\t\tvisited[v] = true;\n\t\t\t\t\t\tq.add(v);\n\t\t\t\t\t\tincnt++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(incnt + outcnt == n - 2)\n\t\t\t\treturn 1;\n\t\t\treturn 0;\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/*\n\n10 10\n1 2\n2 3\n4 2\n4 3\n5 4\n6 4\n3 7\n7 8\n7 9\n7 10\n 0 -> 1\n 1 -> 2\n 3 -> 1\n 3 -> 2\n 4 -> 3\n 5 -> 3\n 2 -> 6\n 6 -> 7\n 6 -> 8\n 6 -> 9\n\n */", "src_uid": "be26e93ca7aef1235e96e10467a6417e"} {"source_code": "import java.io.BufferedWriter;\r\nimport java.io.IOException;\r\nimport java.io.InputStream;\r\nimport java.io.OutputStreamWriter;\r\nimport java.util.Arrays;\r\nimport java.util.Scanner;\r\n\r\n\r\npublic class CF_Edu_108_F {\r\n\tstatic boolean verb=true;\r\n\tstatic void log(Object X){if (verb) System.err.println(X);}\r\n\tstatic void log(Object[] X){if (verb) {for (Object U:X) System.err.print(U+\" \");System.err.println(\"\");}}\r\n\tstatic void log(int[] X){if (verb) {for (int U:X) System.err.print(U+\" \");System.err.println(\"\");}}\r\n\tstatic void log(int[] X,int L){if (verb) {for (int i=0;i<L;i++) System.err.print(X[i]+\" \");System.err.println(\"\");}}\r\n\tstatic void log(long[] X){if (verb) {for (long U:X) System.err.print(U+\" \");System.err.println(\"\");}}\r\n\r\n\tstatic InputReader reader;\r\n\r\n\r\n\tstatic class Composite {\r\n\t\tint msk;\r\n\t\tint cost;\r\n\r\n\t\tComposite left;\r\n\t\tComposite right;\r\n\r\n\r\n\r\n\t}\r\n\r\n\r\n\tstatic String name(int w) {\r\n\t\tint it=0;\r\n\t\tString s=\"key:[\";\r\n\t\twhile (w>0) {\r\n\t\t\tif ((w&1)!=0) {\r\n\t\t\t\ts+=(it+1)+\" \";\r\n\t\t\t}\r\n\t\t\tw>>=1;\r\n\t\t\tit++;\r\n\t\t}\r\n\t\treturn s+\"]\";\r\n\t}\r\n\t\r\n\tstatic\tint FX=Integer.MAX_VALUE;\r\n\tstatic int solveAlt(int[] a,int[] b,int[][] c) {\r\n\t\tint n=a.length;\r\n\t\tint m=b.length;\r\n\t\tint MX=1<<m;\r\n\r\n\t\tint tot=0;\r\n\t\tfor (int i=0;i<n;i++)\r\n\t\t\ttot+=a[i];\r\n\t\tint bob=0;\r\n\t\tfor (int j=0;j<m;j++)\r\n\t\t\tbob+=b[j];\r\n\t\tif (tot>bob)\r\n\t\t\treturn -1;\r\n\r\n\r\n\t\tint[][] cost=new int[n][MX];\r\n\t\tint[] bill=new int[MX];\r\n\r\n\t\tfor (int w=0;w<MX;w++)\r\n\t\t\tfor (int j=0;j<m;j++)\r\n\t\t\t\tif (((1<<j)&w)!=0) {\r\n\t\t\t\t\tbill[w]+=b[j];\r\n\t\t\t\t\tfor (int i=0;i<n;i++)\r\n\t\t\t\t\t\tcost[i][w]+=c[i][j];\r\n\t\t\t\t}\r\n\r\n\r\n\r\n\r\n\t\tint[] stack=new int[n];\r\n\t\tint[] ptr=new int[n];\r\n\t\tArrays.fill(ptr, 1);\r\n\t\tint best=FX;\r\n\t\tint st=0;\r\n\t\tint[] curspend=new int[n];\r\n\t\t\r\n\t\twhile (st>=0) {\r\n\t\t\tif (ptr[st]<MX) {\r\n\t\t\t\tint w=ptr[st]++;\r\n\t\t\t\tint spend=0;\r\n\t\t\t\tif (st>0)\r\n\t\t\t\t\tspend=curspend[st-1];\r\n\t\t\t\t//log(\"trying :\"+name(w)+\" at pos:\"+st);\r\n\t\t\t\t//log((bill[w]-a[st])+\" \"+(spend+cost[st][w])+\" vs \"+best);\r\n\t\t\t\tif (bill[w]>=a[st] && spend+cost[st][w]<best) {\r\n\t\t\t\t\t// now check all the previous ones\r\n\t\t\t\t\tint TX=1<<st;\r\n\t\t\t\t\tboolean ok=true;\r\n\t\t\t\t\tfor (int z=1;z<TX;z++) {\r\n\t\t\t\t\t\tint gain=a[st];\r\n\t\t\t\t\t\tint msk=w;\r\n\t\t\t\t\t\tfor (int j=0;j<st;j++) {\r\n\t\t\t\t\t\t\tif ((z&(1<<j))!=0) {\r\n\t\t\t\t\t\t\t\tmsk|=stack[j];\r\n\t\t\t\t\t\t\t\tgain+=a[j];\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tif (gain>bill[msk]) {\r\n\t\t\t\t\t\t\tok=false;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (ok) {\r\n\t\t\t\t\t\tspend+=cost[st][w];\r\n\t\t\t\t\t\tcurspend[st]=spend;\r\n\t\t\t\t\t\tif (st==n-1) {\r\n\t\t\t\t\t\t\t//log(\"this is ok\");\r\n\t\t\t\t\t\t\tstack[st]=w;\r\n\t\t\t\t\t\t\t//for (int x:stack) {\r\n\t\t\t\t\t\t\t//\tlog(name(x));\r\n\t\t\t\t\t\t\t//}\r\n\t\t\t\t\t\t\tbest=spend;\r\n\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\tstack[st++]=w;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t}\r\n\t\t\t} else {\r\n\t\t\t\tptr[st]=1;\r\n\t\t\t\tst--;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\r\n\t\tif (best==FX)\r\n\t\t\tbest=-1;\r\n\t\treturn best;\r\n\r\n\r\n\r\n\t}\r\n\tstatic int solveKO(int[] a,int[] b,int[][] c) {\r\n\t\tint n=a.length;\r\n\t\tint m=b.length;\r\n\t\tint MX=1<<m;\r\n\r\n\t\tint[][] cost=new int[n][MX];\r\n\t\tint[] bill=new int[MX];\r\n\r\n\t\tfor (int w=0;w<MX;w++)\r\n\t\t\tfor (int j=0;j<m;j++)\r\n\t\t\t\tif (((1<<j)&w)!=0) {\r\n\t\t\t\t\tbill[w]+=b[j];\r\n\t\t\t\t\tfor (int i=0;i<n;i++)\r\n\t\t\t\t\t\tcost[i][w]+=c[i][j];\r\n\t\t\t\t}\r\n\r\n\r\n\t\tint VX=m*4+1;\r\n\t\tint[][] spend=new int[MX][VX];\r\n\r\n\t\tfor (int w=0;w<MX;w++) {\r\n\t\t\tArrays.fill(spend[w], FX);\r\n\t\t\tif (bill[w]>=a[0]) {\r\n\t\t\t\t// ok for me\r\n\t\t\t\t// now we look at the previous\r\n\t\t\t\tspend[w][bill[w]-a[0]]=cost[0][w];\r\n\t\t\t\t//log(\"adding:\"+w);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\r\n\r\n\t\t// this is taking some shortcut...\r\n\r\n\t\tfor (int i=1;i<n;i++) {\r\n\t\t\tint[][] nxt=new int[MX][VX];\r\n\t\t\tfor (int w=0;w<MX;w++)\r\n\t\t\t\tArrays.fill(nxt[w],FX);\r\n\t\t\tfor (int w=0;w<MX;w++) {\r\n\t\t\t\tif (bill[w]>=a[i]) {\r\n\t\t\t\t\t//log(\"considering:\"+w);\r\n\t\t\t\t\t// ok for me\r\n\t\t\t\t\t// now we look at the previous\r\n\t\t\t\t\tfor (int u=0;u<MX;u++)\r\n\t\t\t\t\t\tfor (int v=0;v<VX;v++) {\r\n\t\t\t\t\t\t\tif (spend[u][v]<FX) {\r\n\t\t\t\t\t\t\t\t//log(\"----interested by u:\"+u);\r\n\t\t\t\t\t\t\t\tint nu=u|w;\r\n\t\t\t\t\t\t\t\tint nv=v+bill[w]-bill[w&u]-a[i];\r\n\t\t\t\t\t\t\t\t//log(\"nv:\"+nv);\r\n\t\t\t\t\t\t\t\tif (nv>=0) {\r\n\t\t\t\t\t\t\t\t\t//log(\"----merging\");\r\n\t\t\t\t\t\t\t\t\tnxt[nu][nv]=Math.min(spend[u][v]+cost[i][w], nxt[nu][nv]);\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t}\r\n\t\t\tspend=nxt;\r\n\t\t}\r\n\t\tint ans=FX;\r\n\t\tfor (int w=0;w<MX;w++)\r\n\t\t\tfor (int v=0;v<VX;v++)\r\n\t\t\t\tans=Math.min(ans, spend[w][v]);\r\n\r\n\t\tif (ans==FX)\r\n\t\t\tans=-1;\r\n\t\treturn ans;\r\n\t}\r\n\r\n\tpublic static void main(String[] args) throws Exception {\r\n\r\n\t\treader=new InputReader(System.in);\r\n\t\tint n=reader.readInt();\r\n\t\tint m=reader.readInt();\r\n\t\tint[] a=new int[n];\r\n\t\tint tot=0;\r\n\t\tfor (int i=0;i<n;i++) {\r\n\t\t\ta[i]=reader.readInt();\r\n\t\t\ttot+=a[i];\r\n\t\t}\r\n\t\tint[] b=new int[m];\r\n\t\tfor (int i=0;i<m;i++)\r\n\t\t\tb[i]=reader.readInt();\r\n\r\n\t\tint[][] c=new int[n][m];\r\n\t\tfor (int i=0;i<n;i++)\r\n\t\t\tfor (int j=0;j<m;j++)\r\n\t\t\t\tc[i][j]=reader.readInt();\r\n\r\n\r\n\t\tint ans=solveAlt(a,b,c);\r\n\r\n\t\tSystem.out.println(ans);\r\n\r\n\r\n\r\n\r\n\t}\r\n\r\n\r\n\tstatic final class InputReader {\r\n\t\tprivate final InputStream stream;\r\n\t\tprivate final byte[] buf = new byte[1024];\r\n\t\tprivate int curChar;\r\n\t\tprivate int numChars;\r\n\r\n\t\tpublic InputReader(InputStream stream) {\r\n\t\t\tthis.stream = stream;\r\n\t\t}\r\n\r\n\t\tprivate int read() throws IOException {\r\n\t\t\tif (curChar >= numChars) {\r\n\t\t\t\tcurChar = 0;\r\n\t\t\t\tnumChars = stream.read(buf);\r\n\t\t\t\tif (numChars <= 0) {\r\n\t\t\t\t\treturn -1;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn buf[curChar++];\r\n\t\t}\r\n\r\n\r\n\t\tpublic final String readString() throws IOException {\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\t}\r\n\t\t\tStringBuilder res=new StringBuilder();\r\n\t\t\tdo {\r\n\t\t\t\tres.append((char)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 final int readInt() throws IOException {\r\n\t\t\tint c = read();\r\n\t\t\tboolean neg=false;\r\n\t\t\twhile (isSpaceChar(c)) {\r\n\t\t\t\tc = read();\r\n\t\t\t}\r\n\t\t\tchar d=(char)c;\r\n\t\t\t//log(\"d:\"+d);\r\n\t\t\tif (d=='-') {\r\n\t\t\t\tneg=true;\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\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\t//log(\"res:\"+res);\r\n\t\t\tif (neg)\r\n\t\t\t\treturn -res;\r\n\t\t\treturn res;\r\n\r\n\t\t}\r\n\r\n\t\tpublic final long readLong() throws IOException {\r\n\t\t\tint c = read();\r\n\t\t\tboolean neg=false;\r\n\t\t\twhile (isSpaceChar(c)) {\r\n\t\t\t\tc = read();\r\n\t\t\t}\r\n\t\t\tchar d=(char)c;\r\n\t\t\t//log(\"d:\"+d);\r\n\t\t\tif (d=='-') {\r\n\t\t\t\tneg=true;\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\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\t//log(\"res:\"+res);\r\n\t\t\tif (neg)\r\n\t\t\t\treturn -res;\r\n\t\t\treturn res;\r\n\r\n\t\t}\r\n\r\n\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\t}\r\n}\r\n", "src_uid": "4dc5dc78bda59c1ec6dd8acd6f1d7333"} {"source_code": "\t\t\t\n\t\t\t\n\t\t\t \t\t\t\timport java.io.*;\n\t\t\t \t\t\timport java.math.BigInteger;\n\t\t\t \t\t\timport java.util.*;\n\t\t\t \t\t\t\t\n\t\t\t \t\t\t\t\n\t\t\t \t\t\t\tpublic class Practice {\n\t\t\t \t\t\t\t\tprivate static InputStream stream;\n\t\t\t \t\t\t\t\tprivate static byte[] buf = new byte[1024];\n\t\t\t \t\t\t\t\tprivate static int curChar;\n\t\t\t \t\t\t\t\tprivate static int numChars;\n\t\t\t \t\t\t\t\tprivate static SpaceCharFilter filter;\n\t\t\t \t\t\t\t\tprivate static PrintWriter pw;\n\t\t\t \t\t\t\t\tprivate static long mod=1000000007;\n\t\t\t \t\t\t\t\n\t\t\t \t\t\t\t public static void main(String[] args) {\n\t\t\t \t\t\t\t \tInputReader(System.in);\n\t\t\t \t\t\t\t\t\tpw = new PrintWriter(System.out); \n\t\t\t \t\t\t\t new Thread(null ,new Runnable(){\n\t\t\t \t\t\t\t public void run(){\n\t\t\t \t\t\t\t try{\n\t\t\t \t\t\t\t solve();//This is solution method\n\t\t\t \t\t\t\t pw.close();\n\t\t\t \t\t\t\t } catch(Exception e){\n\t\t\t \t\t\t\t e.printStackTrace();\n\t\t\t \t\t\t\t }\n\t\t\t \t\t\t\t }\n\t\t\t \t\t\t\t },\"1\",1<<26).start();\n\t\t\t \t\t\t\t }\n\t\t\t \t\t\t\t static long sort(int a[])\n\t\t\t \t\t \t{ int n=a.length;\n\t\t\t \t\t \t\tint b[]=new int[n];\t\n\t\t\t \t\t \t\treturn mergeSort(a,b,0,n-1);}\n\t\t\t \t\t \tstatic long mergeSort(int a[],int b[],long left,long right)\n\t\t\t \t\t \t{ long c=0;if(left<right)\n\t\t\t \t\t \t { long mid=left+(right-left)/2;\n\t\t\t \t\t \t\t c= mergeSort(a,b,left,mid);\n\t\t\t \t\t \t\t c+=mergeSort(a,b,mid+1,right);\n\t\t\t \t\t \t\t c+=merge(a,b,left,mid+1,right); }\t\n\t\t\t \t\t \t\treturn c;\t }\n\t\t\t \t\t \tstatic long merge(int a[],int b[],long left,long mid,long right)\n\t\t\t \t\t \t{long c=0;int i=(int)left;int j=(int)mid; int k=(int)left;\n\t\t\t \t\t \twhile(i<=(int)mid-1&&j<=(int)right)\n\t\t\t \t\t \t{ if(a[i]>a[j]) {b[k++]=a[i++]; }\n\t\t\t \t\t \telse\t{ b[k++]=a[j++];c+=mid-i;}}\n\t\t\t \t\t \twhile (i <= (int)mid - 1) b[k++] = a[i++]; \n\t\t\t \t\t \twhile (j <= (int)right) b[k++] = a[j++];\n\t\t\t \t\t \tfor (i=(int)left; i <= (int)right; i++) \n\t\t\t \t\t \t\ta[i] = b[i]; return c; }\n\t\t\t \t\t \t\t \n\t\t\t \t\t\t\t \n\t\t\t \t\t\t\t \n\t\t\t \t\t \tpublic static void solve() {\n\t\t\n\t\t\n\t\t\t \t\t \t\tHashSet<Integer> prime=new HashSet<Integer>();\n\t\t\t \t\t \t\t\n\t\t\t \t\t \t\tfor(int i=2;i<=1;i++){\n\t\t\t \t\t \t\t\tif(isPrime(i))\n\t\t\t \t\t \t\t\t\tprime.add(i);\n\t\t\t \t\t \t\t}\n\t\t\t \t\t \t\t\n\t\t\t \t\t \t\tint n=nextInt();\n\t\t\t \t\t \t\tif(n==1){\n\t\t\t \t\t \t\t\tpw.println(0);\n\t\t\t \t\t \t\t\treturn;\n\t\t\t \t\t \t\t}\n\t\t\t \t\t \t\tint curr=0,start=1,end=n,pos=1;\n\t\t\t \t\t \t\tlong price=0;\n\t\t\t \t\t \t\twhile(end-start>=1){\n\t\t\t \t\t \t\t\tprice++;\n\t\t\t \t\t \t\t\tend--;\n\t\t\t \t\t \t\t\tstart++;\n\t\t\t \t\t \t\t}\n\t\t\t \t\t \t\tif(n%2!=0)\n\t\t\t \t\t \t\t\tprice++;\n\t\t\t \t\t \t\tpw.println(price-1);\n\t\t\t \t\t \t\t\n\t\t\t \t\t \t\t\n\t\t\t \t\t \t\t\n\t\t\t \t\t \t}\n\t\t\t \t\t \tpublic static long trailingZeroes(long n) {\n\t\t\t \t\t \t long count = 0;\n\t\t\n\t\t\t \t\t \t while (n > 0) {\n\t\t\t \t\t \t n /= 5;\n\t\t\t \t\t \t count += n;\n\t\t\t \t\t \t }\n\t\t\n\t\t\t \t\t \t return count;\n\t\t\t \t\t \t}\n\t\t\t\n\t\t\t \t\t\t\t public static int largestPrimeFactor(long number) {\n\t\t\t \t\t\t\t int i;\n\t\t\n\t\t\t \t\t\t\t for (i = 2; i <= number; i++) {\n\t\t\t \t\t\t\t if (number % i == 0) {\n\t\t\t \t\t\t\t number /= i;\n\t\t\t \t\t\t\t i--;\n\t\t\t \t\t\t\t }\n\t\t\t \t\t\t\t }\n\t\t\n\t\t\t \t\t\t\t return i;\n\t\t\t \t\t\t\t}\n\t\t\t \t\t\t\t \n\t\t\t \t\t\t\t\tpublic static long pow(long n, long p) {\n\t\t\t\t\t\t\t \t\tif(p==0)\n\t\t\t\t\t\t\t \t\t\treturn 1;\n\t\t\t\t\t\t\t \t\tif(p==1)\n\t\t\t\t\t\t\t \t\t\treturn n;\n\t\t\t\t\t\t\t \t\tif(p%2==0){\n\t\t\t\t\t\t\t \t\t\tlong temp=pow(n, p/2);\n\t\t\t\t\t\t\t \t\treturn (temp*temp);\n\t\t\t\t\t\t\t \t\t}else{\n\t\t\t\t\t\t\t \t\t\t \tlong temp=pow(n,p/2);\n\t\t\t\t\t\t\t \t\t\t \ttemp=(temp*temp);\n\t\t\t\t\t\t\t \t\t\t \treturn(temp*n);\n\t\t\t\t\t\t\t \t\t\t \t\n\t\t\t\t\t\t\t \t\t}\n\t\t\t\t\t\t\t \t}\n\t\t\t \t\t\t\t public static String reverseString(String s) {\n\t\t\t \t\t\t \t\tStringBuilder sb = new StringBuilder(s);\n\t\t\t \t\t\t \t\tsb.reverse();\n\t\t\t \t\t\t \t\treturn (sb.toString());\n\t\t\t \t\t\t \t}\n\t\t\t \t\t\t\t private static BigInteger ncr(int n,int k){\n\t\t\t \t\t\t\t \tif (k < 0 || k > n) return BigInteger.ZERO;\n\t\t\t \t\t\t\t if (n-k < k) k = n-k;\n\t\t\t \t\t\t\n\t\t\t \t\t\t\t BigInteger x = BigInteger.ONE;\n\t\t\t \t\t\t\t for (int i = 1; i <= k; i++) {\n\t\t\t \t\t\t\t x = x.multiply(new BigInteger(\"\"+(n-i+1)));\n\t\t\t \t\t\t\t x = x.divide(new BigInteger(\"\"+i));\n\t\t\t \t\t\t\t }\n\t\t\t \t\t\t\n\t\t\t \t\t\t\treturn x;\n\t\t\t \t\t\t\t }\n\t\t\t \t\t\t\t static long fact[];\n\t\t\t \t\t\t\tprivate static void factmod(int n,int mod){\n\t\t\t \t\t\t\t\tfact=new long[n+1];\n\t\t\t \t\t\t\t\tfact[0]=1;\n\t\t\t \t\t\t\t\tfor(int i=1;i<=n;i++){\n\t\t\t \t\t\t\t\t\tfact[i]=i*fact[i-1];\n\t\t\t \t\t\t\t\t\t//fact[i]%=mod;\n\t\t\t \t\t\t\t\n\t\t\t \t\t\t\t\t}\n\t\t\t \t\t\t\t\t\n\t\t\t \t\t\t\t}\n\t\t\t \t\t\t\tprivate static long phi(long n){\n\t\t\t \t\t\t\t\tlong ans=n;\n\t\t\t \t\t\t\t\tif(n%2==0)\n\t\t\t \t\t\t\t\t\tans-=(ans/2);\n\t\t\t \t\t\t\t\twhile(n%2==0)\n\t\t\t \t\t\t\t\t{\n\t\t\t \t\t\t\t\t\tn/=2;\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\tfor(int i=3;i*i<=n;i+=2){\n\t\t\t \t\t\t\t\t\tif(n%i==0){\n\t\t\t \t\t\t\t\t\twhile(n%i==0){\n\t\t\t \t\t\t\t\t\t\tn/=i;\n\t\t\t \t\t\t\t\t\t}\n\t\t\t \t\t\t\t\t\tans-=(ans/i);\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\tif(n>2)\n\t\t\t \t\t\t\t\t\tans-=(ans/n);\n\t\t\t \t\t\t\t\t\n\t\t\t \t\t\t\t\treturn ans;\n\t\t\t \t\t\t\t}\n\t\t\t \t\t\t\tstatic long d,x,y;\n\t\t\t \t\t\t\tstatic long modInverse(long A, long M)\n\t\t\t \t\t\t\t{\n\t\t\t \t\t\t\textendedEuclid(A,M);\n\t\t\t \t\t\t\treturn (x%M+M)%M; //x may be negative\n\t\t\t \t\t\t\t}\n\t\t\t \t\t\t\tstatic void extendedEuclid(long A, long B) {\n\t\t\t \t\t\t\tif(B == 0) {\n\t\t\t \t\t\t\td = A;\n\t\t\t \t\t\t\tx = 1;\n\t\t\t \t\t\t\ty = 0;\n\t\t\t \t\t\t\t}\n\t\t\t \t\t\t\telse {\n\t\t\t \t\t\t\textendedEuclid(B, A%B);\n\t\t\t \t\t\t\tlong temp = x;\n\t\t\t \t\t\t\tx = y;\n\t\t\t \t\t\t\ty = temp - (A/B)*y;\n\t\t\t \t\t\t\t}\n\t\t\t \t\t\t\t}\n\t\t\t \t\t\t\tstatic boolean prime[];\n\t\t\t \t\t\t\tstatic int spf[];\n\t\t\t \t\t\t\tpublic static void sieve(int n){\n\t\t\t \t\t\t\t\tprime=new boolean[n+1];\n\t\t\t \t\t\t\t\tspf=new int[n+1];\n\t\t\t \t\t\t\t\t\n\t\t\t \t\t\t\t\tArrays.fill(spf, 1);\n\t\t\t \t\t\t\t\tArrays.fill(prime, true);\n\t\t\t \t\t\t\tprime[1]=false;\n\t\t\t \t\t\t\t\tspf[2]=2;\n\t\t\t \t\t\t\t\tfor(int i=4;i<=n;i+=2)\n\t\t\t \t\t\t\t\t{\n\t\t\t \t\t\t\t\t\tspf[i]=2;\n\t\t\t \t\t\t\t\t\tprime[i]=false;\n\t\t\t \t\t\t\t\t}\n\t\t\t \t\t\t\t\n\t\t\t \t\t\t\tfor(int i=3;i<=n;i+=2){\n\t\t\t \t\t\t\t\tif(prime[i]){\n\t\t\t \t\t\t\t\t\tspf[i]=i;\n\t\t\t \t\t\t\t\t\tfor(int j=2*i;j<=n;j+=i){\n\t\t\t \t\t\t\t\t\t\t\n\t\t\t \t\t\t\t\t\t\tprime[j]=false;\n\t\t\t \t\t\t\t\t\tif(spf[j]==1){\n\t\t\t \t\t\t\t\t\t\tspf[j]=i;\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}\n\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\tpublic static boolean isPrime(long n) {\n\t\t\t \t\t\t\t\t\n\t\t\t \t\t\t\t\tif (n <= 1)\n\t\t\t \t\t\t\t\t\treturn false;\n\t\t\t \t\t\t\t\tif (n <= 3)\n\t\t\t \t\t\t\t\t\treturn true;\n\t\t\t \t\t\t\t\n\t\t\t \t\t\t\t\tif (n % 2 == 0 || n % 3 == 0)\n\t\t\t \t\t\t\t\t\treturn false;\n\t\t\t \t\t\t\t\n\t\t\t \t\t\t\t\tfor (long i = 5; i * i <= n; i = i + 6)\n\t\t\t \t\t\t\t\t\tif (n % i == 0 || n % (i + 2) == 0)\n\t\t\t \t\t\t\t\t\t\treturn false;\n\t\t\t \t\t\t\t\n\t\t\t \t\t\t\t\treturn true;\n\t\t\t \t\t\t\t}\n\t\t\t \t\t\t\t\n\t\t\t \t\t\t\t public static long pow(long n, long p,long mod) {\n\t\t\t \t\t\t\t\t\tif(p==0)\n\t\t\t \t\t\t\t\t\t\treturn 1;\n\t\t\t \t\t\t\t\t\tif(p==1)\n\t\t\t \t\t\t\t\t\t\treturn n%mod;\n\t\t\t \t\t\t\t\t\tif(p%2==0){\n\t\t\t \t\t\t\t\t\t\tlong temp=pow(n, p/2,mod);\n\t\t\t \t\t\t\t\t\treturn (temp*temp)%mod;\n\t\t\t \t\t\t\t\t\t}else{\n\t\t\t \t\t\t\t\t\t\t \tlong temp=pow(n,p/2,mod);\n\t\t\t \t\t\t\t\t\t\t \ttemp=(temp*temp)%mod;\n\t\t\t \t\t\t\t\t\t\t \treturn(temp*n)%mod;\n\t\t\t \t\t\t\t\t\t\t \t\n\t\t\t \t\t\t\t\t\t}\n\t\t\t \t\t\t\t\t}\n\t\t\t \t\t\t\t\tpublic static long gcd(long x, long y) {\n\t\t\t \t\t\t\t\t\tif (x == 0)\n\t\t\t \t\t\t\t\t\t\treturn y;\n\t\t\t \t\t\t\t\t\telse\n\t\t\t \t\t\t\t\t\t\treturn gcd( y % x,x);\n\t\t\t \t\t\t\t\t}\n\t\t\t \t\t\t\t\t\n\t\t\t \t\t\t\t\t\n\t\t\t \t\t\t\t\tpublic static void InputReader(InputStream stream1) {\n\t\t\t \t\t\t\t\t\tstream = stream1;\n\t\t\t \t\t\t\t\t}\n\t\t\t \t\t\t\t \n\t\t\t \t\t\t\t\tprivate static boolean isWhitespace(int c) {\n\t\t\t \t\t\t\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t\t \t\t\t\t\t}\n\t\t\t \t\t\t\t \n\t\t\t \t\t\t\t\tprivate static boolean isEndOfLine(int c) {\n\t\t\t \t\t\t\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t\t \t\t\t\t\t}\n\t\t\t \t\t\t\t \n\t\t\t \t\t\t\t\tprivate static int read() {\n\t\t\t \t\t\t\t\t\tif (numChars == -1)\n\t\t\t \t\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t \t\t\t\t\t\tif (curChar >= numChars) {\n\t\t\t \t\t\t\t\t\t\tcurChar = 0;\n\t\t\t \t\t\t\t\t\t\ttry {\n\t\t\t \t\t\t\t\t\t\t\tnumChars = stream.read(buf);\n\t\t\t \t\t\t\t\t\t\t} catch (IOException e) {\n\t\t\t \t\t\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t \t\t\t\t\t\t\t}\n\t\t\t \t\t\t\t\t\t\tif (numChars <= 0)\n\t\t\t \t\t\t\t\t\t\t\treturn -1;\n\t\t\t \t\t\t\t\t\t}\n\t\t\t \t\t\t\t\t\treturn buf[curChar++];\n\t\t\t \t\t\t\t\t}\n\t\t\t \t\t\t\t \n\t\t\t \t\t\t\t\tprivate static int nextInt() {\n\t\t\t \t\t\t\t\t\tint c = read();\n\t\t\t \t\t\t\t\t\twhile (isSpaceChar(c))\n\t\t\t \t\t\t\t\t\t\tc = read();\n\t\t\t \t\t\t\t\t\tint sgn = 1;\n\t\t\t \t\t\t\t\t\tif (c == '-') {\n\t\t\t \t\t\t\t\t\t\tsgn = -1;\n\t\t\t \t\t\t\t\t\t\tc = read();\n\t\t\t \t\t\t\t\t\t}\n\t\t\t \t\t\t\t\t\tint res = 0;\n\t\t\t \t\t\t\t\t\tdo {\n\t\t\t \t\t\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t \t\t\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t \t\t\t\t\t\t\tres *= 10;\n\t\t\t \t\t\t\t\t\t\tres += c - '0';\n\t\t\t \t\t\t\t\t\t\tc = read();\n\t\t\t \t\t\t\t\t\t} while (!isSpaceChar(c));\n\t\t\t \t\t\t\t\t\treturn res * sgn;\n\t\t\t \t\t\t\t\t}\n\t\t\t \t\t\t\t \n\t\t\t \t\t\t\t\tprivate static long nextLong() {\n\t\t\t \t\t\t\t\t\tint c = read();\n\t\t\t \t\t\t\t\t\twhile (isSpaceChar(c))\n\t\t\t \t\t\t\t\t\t\tc = read();\n\t\t\t \t\t\t\t\t\tint sgn = 1;\n\t\t\t \t\t\t\t\t\tif (c == '-') {\n\t\t\t \t\t\t\t\t\t\tsgn = -1;\n\t\t\t \t\t\t\t\t\t\tc = read();\n\t\t\t \t\t\t\t\t\t}\n\t\t\t \t\t\t\t\t\tlong res = 0;\n\t\t\t \t\t\t\t\t\tdo {\n\t\t\t \t\t\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t \t\t\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t \t\t\t\t\t\t\tres *= 10;\n\t\t\t \t\t\t\t\t\t\tres += c - '0';\n\t\t\t \t\t\t\t\t\t\tc = read();\n\t\t\t \t\t\t\t\t\t} while (!isSpaceChar(c));\n\t\t\t \t\t\t\t\t\treturn res * sgn;\n\t\t\t \t\t\t\t\t}\n\t\t\t \t\t\t\t \n\t\t\t \t\t\t\t\tprivate static String nextToken() {\n\t\t\t \t\t\t\t\t\tint c = read();\n\t\t\t \t\t\t\t\t\twhile (isSpaceChar(c))\n\t\t\t \t\t\t\t\t\t\tc = read();\n\t\t\t \t\t\t\t\t\tStringBuilder res = new StringBuilder();\n\t\t\t \t\t\t\t\t\tdo {\n\t\t\t \t\t\t\t\t\t\tres.appendCodePoint(c);\n\t\t\t \t\t\t\t\t\t\tc = read();\n\t\t\t \t\t\t\t\t\t} while (!isSpaceChar(c));\n\t\t\t \t\t\t\t\t\treturn res.toString();\n\t\t\t \t\t\t\t\t}\n\t\t\t \t\t\t\t \n\t\t\t \t\t\t\t\tprivate static String nextLine() {\n\t\t\t \t\t\t\t\t\tint c = read();\n\t\t\t \t\t\t\t\t\twhile (isSpaceChar(c))\n\t\t\t \t\t\t\t\t\t\tc = read();\n\t\t\t \t\t\t\t\t\tStringBuilder res = new StringBuilder();\n\t\t\t \t\t\t\t\t\tdo {\n\t\t\t \t\t\t\t\t\t\tres.appendCodePoint(c);\n\t\t\t \t\t\t\t\t\t\tc = read();\n\t\t\t \t\t\t\t\t\t} while (!isEndOfLine(c));\n\t\t\t \t\t\t\t\t\treturn res.toString();\n\t\t\t \t\t\t\t\t}\n\t\t\t \t\t\t\t \n\t\t\t \t\t\t\t\tprivate static int[] nextIntArray(int n) {\n\t\t\t \t\t\t\t\t\tint[] arr = new int[n];\n\t\t\t \t\t\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t \t\t\t\t\t\t\tarr[i] = nextInt();\n\t\t\t \t\t\t\t\t\t}\n\t\t\t \t\t\t\t\t\treturn arr;\n\t\t\t \t\t\t\t\t}\n\t\t\t \t\t\t\t \n\t\t\t \t\t\t\t\tprivate static int[][] next2dArray(int n, int m) {\n\t\t\t \t\t\t\t\t\tint[][] arr = new int[n][m];\n\t\t\t \t\t\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t \t\t\t\t\t\t\tfor (int j = 0; j < m; j++) {\n\t\t\t \t\t\t\t\t\t\t\tarr[i][j] = nextInt();\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\treturn arr;\n\t\t\t \t\t\t\t\t}\n\t\t\t \t\t\t\t\tprivate static char[][] nextCharArray(int n,int m){\n\t\t\t \t\t\t\t\t\tchar [][]c=new char[n][m];\n\t\t\t \t\t\t\t\t\tfor(int i=0;i<n;i++){\n\t\t\t \t\t\t\t\t\t\tString s=nextLine();\n\t\t\t \t\t\t\t\t\t\tfor(int j=0;j<s.length();j++){\n\t\t\t \t\t\t\t\t\t\t\tc[i][j]=s.charAt(j);\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\treturn c;\n\t\t\t \t\t\t\t\t}\n\t\t\t \t\t\t\t \n\t\t\t \t\t\t\t\tprivate static long[] nextLongArray(int n) {\n\t\t\t \t\t\t\t\t\tlong[] arr = new long[n];\n\t\t\t \t\t\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t \t\t\t\t\t\t\tarr[i] = nextLong();\n\t\t\t \t\t\t\t\t\t}\n\t\t\t \t\t\t\t\t\treturn arr;\n\t\t\t \t\t\t\t\t}\n\t\t\t \t\t\t\t \n\t\t\t \t\t\t\t\tprivate static void pArray(int[] arr) {\n\t\t\t \t\t\t\t\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\t \t\t\t\t\t\t\tpw.print(arr[i] + \" \");\n\t\t\t \t\t\t\t\t\t}\n\t\t\t \t\t\t\t\t\tpw.println();\n\t\t\t \t\t\t\t\t\treturn;\n\t\t\t \t\t\t\t\t}\n\t\t\t \t\t\t\t \n\t\t\t \t\t\t\t\tprivate static void pArray(long[] arr) {\n\t\t\t \t\t\t\t\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\t \t\t\t\t\t\t\tpw.print(arr[i] + \" \");\n\t\t\t \t\t\t\t\t\t}\n\t\t\t \t\t\t\t\t\tpw.println();\n\t\t\t \t\t\t\t\t\treturn;\n\t\t\t \t\t\t\t\t}\n\t\t\t \t\t\t\t \n\t\t\t \t\t\t\t\tprivate static void pArray(boolean[] arr) {\n\t\t\t \t\t\t\t\t\tfor (int i = 0; i < arr.length; i++) {\n\t\t\t \t\t\t\t\t\t\tpw.print(arr[i] + \" \");\n\t\t\t \t\t\t\t\t\t}\n\t\t\t \t\t\t\t\t\tpw.println();\n\t\t\t \t\t\t\t\t\treturn;\n\t\t\t \t\t\t\t\t}\n\t\t\t \t\t\t\t \n\t\t\t \t\t\t\t\tprivate static boolean isSpaceChar(int c) {\n\t\t\t \t\t\t\t\t\tif (filter != null)\n\t\t\t \t\t\t\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\t \t\t\t\t\t\treturn isWhitespace(c);\n\t\t\t \t\t\t\t\t}\n\t\t\t \t\t\t\t \n\t\t\t \t\t\t\t\tprivate interface SpaceCharFilter {\n\t\t\t \t\t\t\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t\t \t\t\t\t\t}\n\t\t\t \t\t\t\t\n\t\t\t \t\t\t\t\t\n\t\t\t \t\t\t\t}\t\n\t\t\t \t\t\t\t\n\t\t\t \t\t\t\t/*class Pair implements Comparable<Pair>{\n\t\t\t\n\t\t\t \t\t\t\t\t\n\t\t\t \t\t\t\t\tint from,to,a,b;\n\t\t\t \t\t\t\t\tPair(int from,int to,int a,int b){\n\t\t\t \t\t\t\t\t\n\t\t\t \t\t\t\t\t\tthis.from=from;\n\t\t\t \t\t\t\t\t\tthis.to=to;\n\t\t\t \t\t\t\t\t\tthis.a=a;\n\t\t\t \t\t\t\t\t\tthis.b=b;\n\t\t\t \t\t\t\t\t}\n\t\t\t \t\t\t\t\t@Override\n\t\t\t \t\t\t\t\tpublic int compareTo(Pair o) {\n\t\t\t \t\t\t\t\n\t\t\t \t\t\t\t\t\treturn 0;\n\t\t\t \t\t\t\t\t\t//return (int)(o.size-size);\n\t\t\t \t\t\t\t\t}\n\t\t\t \t\t\t\t\tpublic int hashCode() {\n\t\t\t \t\t\t\t\t\t\t//int hu = (int) (x ^ (x >>> 32));\n\t\t\t \t\t\t\t\t\t\t//int hv = (int) (y ^ (y >>> 32));\n\t\t\t \t\t\t\t\t\t\t//int hw = (int) (mass ^ (mass >>> 32));\n\t\t\t \t\t\t\t\t\t\t//return 31 * hu + hv ;\n\t\t\t \t\t\t\t\t\treturn 0;\n\t\t\t \t\t\t\t\t\t}\n\t\t\t \t\t\t\t\t\tpublic boolean equals(Object o) {\n\t\t\t \t\t\t\t\t\t\tPair other = (Pair) o;\n\t\t\t \t\t\t\t\t\t//\treturn x == other.x && y == other.y;\n\t\t\t \t\t\t\t\t\treturn false;\n\t\t\t \t\t\t\t\t\t}\n\t\t\t \t\t\t\t}*/\n\t\t\t\n", "src_uid": "dfe9446431325c73e88b58ba204d0e47"} {"source_code": "import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main{\r\n\tpublic static void main(String args[]) throws Exception{\r\n\t\tPrintWriter out = new PrintWriter(System.out);\r\n\t\tInput in = new Input();\r\n\t\tint test = in.getInt();\r\n\t\twhile(test-->0){\r\n\t\t\tint s = in.getInt();\r\n\t\t\tStringBuilder st = new StringBuilder();\r\n\t\t\tfor(int i=9;i>0;i--){\r\n\t\t\t\tif(s<=i){\r\n\t\t\t\t\tst.append(s);\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\telse{\r\n\t\t\t\t\tst.append(i);\r\n\t\t\t\t\ts = s-i;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tout.println(st.reverse());\r\n\t\t\tout.flush();\r\n\t\t}\r\n\t\tout.close();\r\n\t\tin.close();\r\n\t}\r\n\t\r\n\tpublic static int match(String tx, String pt){\r\n\t\tint len1 = tx.length();\r\n\t\tint len2 = pt.length();\r\n\t\tint pf[] = new int[len2];\r\n\t\tpreFunction(pt,pf,len2);\r\n\t\tint q = 0;\r\n\t\tfor(int i=0;i<len1;i++){\r\n\t\t\twhile(q>0&&tx.charAt(i)!=pt.charAt(q)){\r\n\t\t\t\tq = pf[q-1];\r\n\t\t\t}\r\n\t\t\tif(tx.charAt(i)==pt.charAt(q)){\r\n\t\t\t\tq++;\r\n\t\t\t}\r\n\t\t\tif(q==len2){\r\n\t\t\t\treturn i+1;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn -1;\r\n\t}\r\n\tpublic static void preFunction(String pt, int pf[], int len2){\r\n\t\tint q = 0;\r\n\t\tpf[0] = 0;\r\n\t\tfor(int i=1;i<len2;i++){\r\n\t\t\twhile(q>0&&pt.charAt(q)!=pt.charAt(i)){\r\n\t\t\t\tq = pf[q-1];\r\n\t\t\t}\r\n\t\t\tif(pt.charAt(q)==pt.charAt(i)){\r\n\t\t\t\tq++;\r\n\t\t\t}\r\n\t\t\tpf[i] = q;\r\n\t\t}\r\n\t}\r\n}\r\n\r\nclass Input{\r\n\tBufferedReader in;\r\n\tStringTokenizer st;\r\n\tpublic Input() throws Exception{\r\n\t\tin = new BufferedReader(new InputStreamReader(System.in));\r\n\t\tst = null;\r\n\t}\r\n\t\r\n\tpublic String getString() throws Exception{\r\n\t\twhile(st==null||st.hasMoreTokens()==false){\r\n\t\t\tst = new StringTokenizer(in.readLine());\r\n\t\t}\r\n\r\n\t\treturn st.nextToken();\r\n\t}\r\n\tpublic boolean getBoolean() throws Exception{\r\n\t\treturn Boolean.parseBoolean(getString());\r\n\t}\r\n\tpublic byte getByte() throws Exception{\r\n\t\treturn Byte.parseByte(getString());\r\n\t}\r\n\tpublic short getShort() throws Exception{\r\n\t\treturn Short.parseShort(getString());\r\n\t}\r\n\tpublic int getInt() throws Exception{\r\n\t\treturn Integer.parseInt(getString());\r\n\t}\r\n\tpublic long getLong() throws Exception{\r\n\t\treturn Long.parseLong(getString());\r\n\t}\r\n\tpublic float getFloat() throws Exception{\r\n\t\treturn Float.parseFloat(getString());\r\n\t}\r\n\tpublic double getDouble() throws Exception{\r\n\t\treturn Double.parseDouble(getString());\r\n\t}\r\n\tpublic String getLine() throws Exception{\r\n\t\treturn in.readLine();\r\n\t}\r\n\tpublic void close() throws Exception{\r\n\t\tif(in!=null) in.close();\r\n\t}\r\n}\r\n", "src_uid": "fe126aaa93acaca8c8559bc9e7e27b9f"} {"source_code": "import java.util.*;\n\npublic class Main {\n static Scanner in = new Scanner(System.in);\n static int mod = 1000_000_000 + 7;\n public static void main(String[] args) {\n long[] ar = new long[6];\n int n;\n ar[0] = in.nextInt();\n ar[1] = in.nextInt();\n n = in.nextInt();\n n--;\n for (int i = 2; i < 6; i++)\n ar[i] = (ar[i - 1] - ar[i - 2] + mod) % mod;\n System.out.println((ar[n % 6] + mod) % mod);\n }\n}\n", "src_uid": "2ff85140e3f19c90e587ce459d64338b"} {"source_code": "import java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.BufferedReader;\nimport java.io.OutputStream;\nimport java.io.PrintWriter;\nimport java.io.IOException;\nimport java.util.StringTokenizer;\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\nclass TaskB {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n long n = in.nextLong();\n long m = in.nextLong();\n long ans = 0;\n ans = calc(n, m);\n out.println(ans);\n }\n\n private long calc(long n, long m) {\n if (n >= m) {\n return n - m;\n }\n long mid = (m + 1) / 2;\n long ans = 0;\n ans += calc(n, mid) + 1;\n if ((m & 1) != 0)\n ans++;\n return ans;\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 tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n\n}\n", "src_uid": "861f8edd2813d6d3a5ff7193a804486f"} {"source_code": "\nimport java.io.*;\nimport java.util.*;\n\npublic final class AGenerateLogin {\n\n private void solve(InputReader in, PrintWriter out, int tn) {\n String fn = in.next();\n String ln = in.next();\n char c = ln.charAt(0);\n String ans = fn + c;\n int i;\n for (int j = 1; j < fn.length(); j++) {\n if (fn.charAt(j)==c){\n ans = fn.substring(0,j+1);\n break;\n }\n }\n if (ans.length() == 1) {\n ans += c;\n }\n for (int j = 1; j < ans.length()-1; j++) {\n if (c < ans.charAt(j)){\n ans = ans.substring(0,j)+c;\n }\n }\n out.println(ans);\n }\n\n private int gcd(int x, int y) {\n if (y == 0) {\n return x;\n } else {\n return gcd(y, x % y);\n }\n }\n\n public static void main(String[] args) {\n InputReader in = new InputReader(System.in);\n PrintWriter out = new PrintWriter(System.out);\n new AGenerateLogin().solve(in, out, 1);\n out.close();\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n }\n}\n", "src_uid": "aed892f2bda10b6aee10dcb834a63709"} {"source_code": "import java.util.*;\n\t\n\timport java.io.*;;\n\tpublic class java2 {\n\t public static void main(String[]arg) {\n\t\t Scanner sc=new Scanner(System.in);\n\t\t int n=sc.nextInt();\n\t\t int k=sc.nextInt();\n\t\t int c=0;\n\t\t if(n>=k) {\n\t\t\t for(int i=1;i<=n;i++) {\n\t\t\t\t if(k%i==0)c++;\n\t\t\t }\n\t\t }else if(n<k) {\n\t\t\t if(k%n==0) {\n\t\t\t\t for(int i=k/n;i<=n;i++) {\n\t\t\t\t\t if(k%i==0)c++;\n\t\t\t\t }\n\t\t\t }else {\n\t\t\t\t for(int i=(k/n)+1;i<=n;i++) {\n\t\t\t\t\t if(k%i==0)c++;\n\t\t\t\t }\n\t\t\t }\n\t\t }\n\t\t System.out.print(c);\n\t }\n\t \n\t}", "src_uid": "c4b139eadca94201596f1305b2f76496"} {"source_code": "/**\n * Created by Anna on 08.02.2015.\n */\n\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.StringTokenizer;\n\npublic class TaskC {\n\n StringTokenizer st;\n BufferedReader in;\n PrintWriter out;\n\n public static void main(String[] args) throws NumberFormatException,\n IOException {\n TaskC solver = new TaskC();\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 //in = new BufferedReader(new FileReader(\"input.txt\"));\n //out = new PrintWriter(new FileWriter(\"output.txt\"));\n }\n\n public String nextToken() throws IOException {\n while (st == null || !st.hasMoreTokens()) {\n String line = in.readLine();\n if (line == null)\n return null;\n st = new StringTokenizer(line);\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 boolean hasMoreTokens() throws IOException {\n while (st == null || !st.hasMoreTokens()) {\n String line = in.readLine();\n if (line == null)\n return false;\n st = new StringTokenizer(line);\n }\n return true;\n }\n\n class Company {\n int left, right;\n\n public Company(int left, int right) {\n this.left = left;\n this.right = right;\n }\n }\n\n public void solve() throws NumberFormatException, IOException {\n int n = nextInt();\n Company[] companies = new Company[n];\n for (int i = 0; i < n; i++) {\n companies[i] = new Company(nextInt(), nextInt());\n }\n double answ = 0;\n\n for (int money = 1; money <= 10000; money++) {\n for (int companyInd = 0; companyInd < n; companyInd++) {\n Company winner = companies[companyInd];\n double pWin;\n if (winner.right <= money) continue;\n if (winner.left > money) pWin = 1;\n else pWin = (winner.right - money + 0D) / (winner.right - winner.left + 1);\n double pOther1 = 1;\n for (int i = 0; i < n; i++) {\n if (i == companyInd) continue;\n Company cur = companies[i];\n if (cur.left > money) {\n pOther1 = 0;\n break;\n }\n pOther1 *= (Math.min(money, cur.right) - cur.left + 1D) / (cur.right - cur.left + 1);\n }\n\n if (pOther1 == 0) continue;\n\n double pOther2 = 1;\n for (int i = 0; i < n; i++) {\n if (i == companyInd) continue;\n Company cur = companies[i];\n pOther2 *= (Math.min(money - 1, cur.right) - cur.left + 1D) / (cur.right - cur.left + 1);\n }\n answ += money * pWin * (pOther1 - pOther2);\n// out.println(money + \": win \" + answ);\n }\n\n\n int maskMax = 1 << n;\n for (int mask = 3; mask < maskMax; mask++) {\n if (isPow(mask)) continue;\n double pMask = 1;\n boolean badMask = false;\n for (int i = 0; i < n; i++) {\n if ((mask & (1 << i)) != 0) {\n if (companies[i].left > money || companies[i].right < money) {\n badMask = true;\n break;\n } else pMask /= (companies[i].right - companies[i].left + 1);\n } else {\n Company cur = companies[i];\n if (cur.left > (money - 1)) {\n badMask = true;\n break;\n }\n pMask *= (Math.min(money - 1, cur.right) - cur.left + 1D) / (cur.right - cur.left + 1);\n }\n }\n if (!badMask) {\n answ += money * pMask;\n// out.println(\"mask \" + mask + \" \" + answ);\n }\n }\n }\n\n out.println(answ);\n }\n\n boolean isPow(int a) {\n int[] pow = {1, 2, 4, 8, 16, 32, 64, 128};\n for (int i : pow) {\n if (a == i) return true;\n }\n return false;\n }\n\n public void close() {\n out.flush();\n out.close();\n }\n}\n", "src_uid": "5258ce738eb268b9750cfef309d265ef"} {"source_code": "import java.io.*;\nimport java.util.*;\nimport java.text.*;\nimport java.math.*;\nimport java.util.regex.*;\n\npublic class Solution {\n\n static void olympiad(int []a, int n) {\n Arrays.sort(a);\n int max=0;\n int c=0;\n for(int i=0;i<n;i++){\n if(a[i]>max){\n max=a[i];\n c++;\n }\n \n }\n System.out.print(c);\n \n }\n\n \n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n=sc.nextInt();\n int a[]=new int [n];\n for(int i=0;i<n;i++){\n a[i]=sc.nextInt();\n }\n olympiad(a,n);\n \n }\n}\n\n", "src_uid": "3b520c15ea9a11b16129da30dcfb5161"} {"source_code": "import java.util.*;\nimport java.io.*;\npublic class EdE {\n\n\tpublic static void main(String[] args) throws Exception{\n\t\tlong num = 1000000007;\n\n\t\t// TODO Auto-generated method stub\n \t\tBufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n \t\tPrintWriter out = new PrintWriter(System.out);\n \t\tint n = Integer.parseInt(bf.readLine());\n \t\tlong[] dp = new long[n+1];\n \t\tint[] isPrime = new int[n+1];\n\t\tArrays.fill(isPrime, 1);\n\t\tint[] mu = new int[n+1];\n\t\tArrays.fill(mu, 1);\n\t\tfor(int i = 2;i<=n;i++){\n\t\t\tif (isPrime[i] == 1){\n\t\t\t\tfor(int j = i;j<=n;j+=i){\n\t\t\t\t\tif (j > i)\n\t\t\t\t\t\tisPrime[j] = 0;\n\t\t\t\t\tif (j%(i*i) == 0)\n\t\t\t\t\t\tmu[j] = 0;\n\t\t\t\t\tmu[j] = -mu[j];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlong sum = 0;\n\t\tfor(int i = 2;i<=n;i++){\n\t\t\tsum+=(((long)(0-mu[i])*((((long)(n/i))*power(n-n/i, num-2, num))%num))%num+num)%num;\n\t\t\tsum%=num;\n\t\t\t\n\t\t}\n\t\tsum+=1;\n\t\tsum%=num;\n \t\tout.println(sum);\n\t \t\t\n \t\tout.close();\n \t\t\n \t\t\n \t\t\n \t}\n\tpublic static long power(long x, long y, long mod){\n\t\tlong ans = 1;\n\t\twhile(y>0){\n\t\t\tif (y%2==1)\n\t\t\t\tans = (ans*x)%mod;\n\t\t\tx = (x*x)%mod;\n\t\t\ty/=2;\n\t\t}\n\t\treturn ans;\n\t}\n}\n \t\n \n//StringJoiner sj = new StringJoiner(\" \"); \n//sj.add(strings)\n//sj.toString() gives string of those stuff w spaces or whatever that sequence is\n\n \t\t\n \t\t\n \t\t\n \t\t\n\t\n\n", "src_uid": "ff810b16b6f41d57c1c8241ad960cba0"} {"source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\npublic class cfShit {\n\n\tint pow(int a, int b, int p) {\n\t\tint ret = 1;\n\t\tfor (; b > 0; b >>= 1) {\n\t\t\tif ((b & 1) == 1) {\n\t\t\t\tret = (int) ((long) ret * a % p);\n\t\t\t}\n\t\t\ta = (int) ((long) a * a % p);\n\t\t}\n\t\treturn ret;\n\t}\n\n\tint primitiveRoot(int p) {\n\t\tloop: for (int i = 2;; i++) {\n\t\t\tfor (int j = 2; j * j <= p - 1; j++) {\n\t\t\t\tif ((p - 1) % j != 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (pow(i, (p - 1) / j, p) == 1) {\n\t\t\t\t\tcontinue loop;\n\t\t\t\t}\n\t\t\t\tif (pow(i, j, p) == 1) {\n\t\t\t\t\tcontinue loop;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn i;\n\t\t}\n\t}\n\n\tstatic final int C = 5000;\n\n\tint[] chirp(int[] a, int[] pz, int p) {\n\t\tint n = a.length;\n\t\t// pz[1] has order 2 * n modulo prime p\n\n\t\ta = a.clone();\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\ta[i] %= p;\n\t\t}\n\n\t\tint[] one = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tone[i] = (int) ((long) a[i] * pz[(int) ((long)i * i % (2 * n))] % p);\n\t\t}\n\n\t\tint[] two = new int[2 * n - 1];\n\t\tfor (int i = 0; i <= 2 * n - 2; i++) {\n\t\t\ttwo[i] = pz[(int) Math.floorMod(-(long)(n - 1 - i) * (n - 1 - i), 2 * n)];\n\t\t}\n\n\t\tint[] prod = mult(one, two, p);\n\n\t\tprod = Arrays.copyOfRange(prod, n - 1, 2 * n - 1);\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tprod[i] = (int) ((long) prod[i] * pz[(int) ((long)i * i % (2 * n))] % p);\n\t\t}\n\n\t\treturn prod;\n\t\t// returns polynomial a modulo p at points 1, rootZ^2, rootZ^4, ...\n\t}\n\n\tvoid submit() {\n\t\tint n = nextInt();\n\t\tint[] b = new int[n];\n\t\tint[] c = new int[n];\n\t\t\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tb[i] = nextInt();\n\t\t}\n\t\t\n\t\tint[] initB = b.clone();\n\t\t\n\t\tb = makeInvPows(b);\n\t\t\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tc[i] = nextInt();\n\t\t}\n\t\t\n\n\t\tint z, p;\n\t\tint[] pz;\n\n\t\tint[] fb;\n\n\t\tfor (int i = 1;; i++) {\n\t\t\tp = 2 * n * i + 1;\n\t\t\tif (p < C) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!BigInteger.valueOf(p).isProbablePrime(30)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tz = pow(primitiveRoot(p), (p - 1) / (2 * n), p);\n\t\t\tpz = new int[2 * n];\n\t\t\tpz[0] = 1;\n\t\t\tfor (int j = 1; j < pz.length; j++) {\n\t\t\t\tpz[j] = (int) ((long) pz[j - 1] * z % p);\n\t\t\t}\n\n\t\t\tfb = chirp(b, pz, p);\n\t\t\tboolean allGood = true;\n\t\t\tfor (int coef : fb) {\n\t\t\t\tallGood &= coef != 0;\n\t\t\t}\n\n\t\t\tif (allGood) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tint[] cc = new int[n];\n\t\tint inv2 = (p + 1) / 2;\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tcc[i] = (c[(i + n - 1) % n] - c[i]) % p;\n\t\t\tif (cc[i] < 0) {\n\t\t\t\tcc[i] += p;\n\t\t\t}\n\t\t\tcc[i] = (int)((long)cc[i] * inv2 % p);\n\t\t}\n\t\t\n\t\tint[] fc = chirp(cc, pz, p);\n\t\t\n\t\tint[] fa = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tfa[i] = (int)((long)fc[i] * pow(fb[i], p - 2, p) % p);\n\t\t}\n\t\t\n\t\tint[] aa = chirp(fa, makeInvPows(pz), p);\n\t\tint invN = pow(n, p - 2, p);\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\taa[i] = (int)((long)aa[i] * invN % p);\n\t\t}\n\t\t\n\t\tlong[] d = new long[n];\n\t\tfor (int i = 1; i < n; i++) {\n\t\t\td[i] = d[i - 1] + makeInt(aa[i], p);\n\t\t}\n\t\t\n//\t\tSystem.err.println(Arrays.toString(realAa));\n\t\t\n\t\tlong A = n;\n\t\tlong B = 0;\n\t\tlong C = -c[0];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tlong diff = initB[i] - d[i];\n\t\t\tB -= diff;\n\t\t\tC += diff * diff;\n\t\t}\n\t\t\n//\t\tSystem.err.println(A + \" \" + B + \" \" + C);\n\t\t\n\t\tList<Long> x0s = new ArrayList<>();\n\t\t\n\t\tlong D = B * B - A * C;\n\t\tif (D < 0) {\n\t\t} else if (D == 0) {\n\t\t\tif ((-B % A) == 0) {\n\t\t\t\tx0s.add((-B) / A);\n\t\t\t}\n\t\t} else {\n\t\t\tlong rd = (long) Math.sqrt(D);\n\t\t\tif (rd * rd == D) {\n\t\t\t\tif ((-B - rd) % A == 0) {\n\t\t\t\t\tx0s.add((-B - rd) / A);\n\t\t\t\t}\n\t\t\t\tif ((-B + rd) % A == 0) {\n\t\t\t\t\tx0s.add((-B + rd) / A);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tout.println(x0s.size());\n\t\tfor (long x0 : x0s) {\n\t\t\tfor(int i = 0; i < n; i++) {\n\t\t\t\tout.print(d[i] + x0 + \" \");\n\t\t\t}\n\t\t\tout.println();\n\t\t}\n\t\t\n\t}\n\t\n\tint makeInt(int x, int p) {\n\t\treturn x < p / 2 ? x : x - p;\n\t}\n\t\n\tint[] makeInvPows(int[] a) {\n\t\tint[] b = new int[a.length];\n\t\tb[0] = a[0];\n\t\tfor (int i = 1, j = a.length - 1; i < a.length; i++, j--) {\n\t\t\tb[i] = a[j];\n\t\t}\n\t\treturn b;\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\tcfShit() 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 int nextPowerOf2(int x) {\n\t\treturn x == 1 ? 1 : Integer.highestOneBit(x - 1) << 1;\n\t}\n\n\tstatic double[][] foo(int[] intV, int len, int L) {\n\t\t// pack into one complex vector\n\t\tdouble[] f = new double[len << 1];\n\t\tfor (int i = 0; i < intV.length; i++) {\n\t\t\tf[i << 1] = intV[i] % L;\n\t\t\tf[i << 1 | 1] = intV[i] / L;\n\t\t}\n\n\t\tfft(f, false);\n\n\t\t// unpack\n\t\tdouble[] f1 = new double[len << 1];\n\t\tdouble[] f2 = new double[len << 1];\n\n\t\t// LEN MUST BE A POWER OF 2!!!\n\t\tint zzz = (len << 1) - 1;\n\t\tfor (int i = 0; i < len << 1; i += 2) {\n\t\t\tint j = (-i) & zzz;\n\t\t\tf1[i] = .5 * (f[i] + f[j]);\n\t\t\tf1[i + 1] = .5 * (f[i + 1] - f[j + 1]);\n\t\t\tf2[i] = .5 * (f[i + 1] + f[j + 1]);\n\t\t\tf2[i + 1] = .5 * (f[j] - f[i]);\n\t\t}\n\n\t\treturn new double[][] { f1, f2 };\n\t}\n\n\tpublic static int[] mult(int[] a, int[] b, int pMod) {\n\t\t\n\t\tint k = (int) (Math.sqrt(pMod) + 1);\n\t\tint k2 = k * k % pMod;\n\t\t\n\t\tint len = nextPowerOf2(a.length + b.length - 1);\n\t\tint len2 = len << 1;\n\n\t\tdouble[][] fA = foo(a, len, k);\n\t\tdouble[][] fB = foo(b, len, k);\n\n\t\tdouble[][] invF = new double[2][len2];\n\n\t\tfor (int ia = 0; ia < 2; ia++) {\n\t\t\tfor (int ib = 0; ib < 2; ib++) {\n\n\t\t\t\tdouble[] r = invF[(ia + ib) >> 1];\n\t\t\t\tdouble[] p = fA[ia];\n\t\t\t\tdouble[] q = fB[ib];\n\n\t\t\t\tif (((ia + ib) & 1) == 0) {\n\t\t\t\t\tfor (int i = 0; i < len2; i += 2) {\n\t\t\t\t\t\tr[i] += p[i] * q[i] - p[i + 1] * q[i + 1];\n\t\t\t\t\t\tr[i + 1] += p[i] * q[i + 1] + p[i + 1] * q[i];\n\t\t\t\t\t}\n\n\t\t\t\t} else {\n\t\t\t\t\tfor (int i = 0; i < len2; i += 2) {\n\t\t\t\t\t\tr[i] -= p[i] * q[i + 1] + p[i + 1] * q[i];\n\t\t\t\t\t\tr[i + 1] += p[i] * q[i] - p[i + 1] * q[i + 1];\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t}\n\t\t}\n\n\t\tfft(invF[0], true);\n\t\tfft(invF[1], true);\n\n\t\tint[] ret = new int[len];\n\n\t\tfor (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\t\t\tlong v0 = (long)(invF[0][i] + .5);\n\t\t\tlong v1 = ((long)(invF[0][i + 1] + .5)) % pMod * k;\n\t\t\tlong v2 = ((long)(invF[1][i] + .5)) % pMod * k2;\n\t\t\tret[i >> 1] = (int) ((v0 + v1 + v2) % pMod);\n\t\t}\n\n\t\treturn ret;\n\t}\n\n\tpublic static void fft(double[] v, boolean invert) {\n\t\tint n2 = v.length;\n\t\tint n = n2 >> 1;\n\t\tint logN = Integer.numberOfTrailingZeros(n);\n\t\tprepareArrays(logN);\n\t\tint[] rev = rev2D[logN];\n\n\t\tfor (int i = 0; i < n2; i += 2) {\n\t\t\tint j = rev[i >> 1] << 1;\n\t\t\tif (i < j) {\n\t\t\t\tdouble t = v[i];\n\t\t\t\tv[i] = v[j];\n\t\t\t\tv[j] = t;\n\t\t\t\tt = v[i + 1];\n\t\t\t\tv[i + 1] = v[j + 1];\n\t\t\t\tv[j + 1] = t;\n\t\t\t}\n\t\t}\n\n\t\tdouble conj = invert ? -1 : 1;\n\n\t\tfor (int len = 2, row = 0; len <= n; len <<= 1, row++) {\n\t\t\tdouble[] pow = pow2D[row];\n\t\t\tfor (int i = 0; i < n; i += len) {\n\t\t\t\tfor (int j1 = i << 1, j2 = j1 + len, k = 0; k < len; j1 += 2, j2 += 2, k += 2) {\n\t\t\t\t\tdouble uA = v[j1];\n\t\t\t\t\tdouble uB = v[j1 + 1];\n\n\t\t\t\t\tdouble mRe = pow[k];\n\t\t\t\t\tdouble mIm = pow[k + 1] * conj;\n\n\t\t\t\t\tdouble vA = v[j2] * mRe - v[j2 + 1] * mIm;\n\t\t\t\t\tdouble vB = v[j2] * mIm + v[j2 + 1] * mRe;\n\n\t\t\t\t\tv[j1] = uA + vA;\n\t\t\t\t\tv[j1 + 1] = uB + vB;\n\t\t\t\t\tv[j2] = uA - vA;\n\t\t\t\t\tv[j2 + 1] = uB - vB;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (invert) {\n\t\t\tfor (int i = 0; i < n2; i++) {\n\t\t\t\tv[i] /= n;\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic double[][] pow2D = { { 1, 0 } };\n\tstatic int[][] rev2D = {};\n\n\tstatic void prepareArrays(int n) {\n\t\tif (rev2D.length < n + 1) {\n\t\t\trev2D = Arrays.copyOf(rev2D, n + 1);\n\t\t}\n\n\t\tif (rev2D[n] == null) {\n\t\t\tint[] tmp = rev2D[n] = new int[1 << n];\n\t\t\tfor (int i = 0; i < (1 << n); i++) {\n\t\t\t\ttmp[i] = (tmp[i >> 1] >> 1) | ((i & 1) << (n - 1));\n\t\t\t}\n\t\t}\n\n\t\tint oldN = pow2D.length;\n\n\t\tif (oldN >= n) {\n\t\t\treturn;\n\t\t}\n\n\t\tpow2D = Arrays.copyOf(pow2D, n);\n\n\t\tfor (int i = oldN; i < n; i++) {\n\t\t\tdouble angle = Math.PI / (1 << i);\n\n\t\t\tdouble mRe = Math.cos(angle);\n\t\t\tdouble mIm = Math.sin(angle);\n\n\t\t\tdouble[] dst = pow2D[i] = new double[2 << i];\n\t\t\tdouble[] src = pow2D[i - 1];\n\n\t\t\tfor (int j = 0; j < 1 << i; j += 2) {\n\t\t\t\tdouble re = src[j];\n\t\t\t\tdouble im = src[j + 1];\n\n\t\t\t\tdst[j << 1] = re;\n\t\t\t\tdst[j << 1 | 1] = im;\n\t\t\t\tdst[j << 1 | 2] = re * mRe - im * mIm;\n\t\t\t\tdst[j << 1 | 3] = re * mIm + im * mRe;\n\t\t\t}\n\t\t}\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 cfShit();\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}", "src_uid": "d8c531799874ce5bf5443aba1d34b26d"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class internationalolympiad {\n private static InputReader in;\n private static PrintWriter out;\n\n public static void main(String[] args) throws IOException {\n in = new InputReader(System.in);\n out = new PrintWriter(System.out, true);\n\n int n = in.nextInt();\n int[] first = new int[]\n {0, 1989, 1999, 2099, 3099, 13099, 113099, 1113099, 11113099, 111113099, 1111113099};\n while(n-->0) {\n String s = in.next().substring(4);\n int atleast = first[s.length()];\n int clen = (\"\"+atleast).length();\n String suff = (\"\"+atleast).substring(clen-s.length());\n String front = (\"\"+atleast).substring(0, clen-s.length());\n boolean add = Integer.parseInt(s) < Integer.parseInt(suff);\n if (add) {\n if (front.length() == 0) front = \"1\";\n else front = \"\"+(Integer.parseInt(front)+1);\n }\n System.out.println(front+\"\"+s);\n }\n \n out.close();\n System.exit(0);\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", "src_uid": "31be4d38a8b5ea8738a65bfee24a5a21"} {"source_code": "//package bubblecup13.f;\n\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 H {\n\tInputStream is;\n\tPrintWriter out;\n\tString INPUT = \"\";\n\t\n\tvoid solve()\n\t{\n\t\tint n = ni(), Q = ni(), K = ni();\n\t\tint[][] qs = new int[Q][];\n\t\tint[] day = new int[Q+1];\n\t\tint d = 1;\n\t\tfor(int z = 0;z < Q;z++){\n\t\t\tint t = ni();\n\t\t\tif(t == 1){\n\t\t\t\tqs[z] = new int[]{t, ni()-1, ni()-1};\n\t\t\t}else if(t == 2){\n\t\t\t\tqs[z] = new int[]{t, ni()-1};\n\t\t\t}else{\n\t\t\t\tqs[z] = new int[]{t};\n\t\t\t}\n\t\t}\n\t\tfor(int i = 0;i < Q;i++){\n\t\t\tif(qs[i][0] == 3){\n\t\t\t\tday[d++] = i;\n\t\t\t}\n\t\t}\n\n\t\tQuerySegmentTree qst = new QuerySegmentTree(Q);\n\t\tint da = 0;\n\t\tfor(int i = 0;i < Q;i++){\n\t\t\tif(qs[i][0] == 1){\n\t\t\t\tif(da+K >= d){\n\t\t\t\t\tqst.put(i, Q, i);\n\t\t\t\t}else{\n\t\t\t\t\tqst.put(i, day[da+K], i);\n\t\t\t\t}\n\t\t\t}else if(qs[i][0] == 3){\n\t\t\t\tda++;\n\t\t\t}\n\t\t}\n\n\t\tRestorableDisjointSet2 rds = new RestorableDisjointSet2(n, Q);\n\n\t\t// process\n\t\tint[] stack = new int[30];\n\t\tint sp = 0;\n\n\t\tfor(int i = 0;i < qs.length;i++){\n\t\t\tint upd = Integer.bitCount((i^i-1)&(qst.M-1));\n\t\t\tif(i > 0){\n\t\t\t\tfor(int j = 0;j < upd;j++){\n\t\t\t\t\t// pop\n\t\t\t\t\trds.revert(stack[--sp]);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor(int j = upd-1;j >= 0;j--){\n\t\t\t\t// push\n\t\t\t\tL node = qst.st[qst.H+i>>>j];\n\t\t\t\tstack[sp++] = rds.hp;\n\t\t\t\tif(node != null){\n\t\t\t\t\tfor(int k = 0;k < node.size();k++){\n\t\t\t\t\t\tint id = node.a[k];\n\t\t\t\t\t\trds.union(qs[id][1], qs[id][2]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif(qs[i][0] == 2){\n\t\t\t\tint[] q = qs[i];\n\t\t\t\tout.println(-rds.upper[rds.root(q[1])]);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static class L {\n\t\tpublic int[] a;\n\t\tpublic int p = 0;\n\n\t\tpublic L(int n) { a = new int[n]; }\n\t\tpublic L add(int n)\n\t\t{\n\t\t\tif(p >= a.length)a = Arrays.copyOf(a, a.length*3/2+1);\n\t\t\ta[p++] = n;\n\t\t\treturn this;\n\t\t}\n\t\tpublic int size() { return p; }\n\t\tpublic L clear() { p = 0; return this; }\n\t\tpublic int[] toArray() { return Arrays.copyOf(a, p); }\n\t\t@Override\n\t\tpublic String toString() {return Arrays.toString(toArray());}\n\t}\n\n\n\tpublic static class RestorableDisjointSet2 {\n\t\tpublic int[] upper; // minus:num_element(root) plus:root(normal)\n\t\tprivate int[] targets;\n\t\tprivate int[] histupper;\n\t\tpublic int hp = 0;\n\n\t\tpublic RestorableDisjointSet2(int n, int m)\n\t\t{\n\t\t\tupper = new int[n];\n\t\t\tArrays.fill(upper, -1);\n\n\t\t\ttargets = new int[2*m];\n\t\t\thistupper = new int[2*m];\n\t\t\t//\n\t\t\t//\t\t\tw = new int[n];\n\t\t}\n\n\t\tpublic RestorableDisjointSet2(RestorableDisjointSet2 ds)\n\t\t{\n\t\t\tthis.upper = Arrays.copyOf(ds.upper, ds.upper.length);\n\t\t\tthis.histupper = Arrays.copyOf(ds.histupper, ds.histupper.length);\n\t\t\t//\n\t\t\tthis.hp = ds.hp;\n\t\t}\n\n\t\tpublic int root(int x)\n\t\t{\n\t\t\treturn upper[x] < 0 ? x : root(upper[x]);\n\t\t}\n\n\t\tpublic boolean equiv(int x, int y)\n\t\t{\n\t\t\treturn root(x) == root(y);\n\t\t}\n\n\t\tpublic boolean union(int x, int y)\n\t\t{\n\t\t\tx = root(x);\n\t\t\ty = root(y);\n\t\t\tif(x != y) {\n\t\t\t\tif(upper[y] < upper[x]) {\n\t\t\t\t\tint d = x; x = y; y = d;\n\t\t\t\t}\n\t\t\t\t//\t\t\t\tw[x] += w[y];\n\t\t\t\trecord(x); record(y);\n\t\t\t\tupper[x] += upper[y];\n\t\t\t\t//\n\t\t\t\tupper[y] = x;\n\t\t\t}\n\t\t\treturn x == y;\n\t\t}\n\n\t\tpublic int time() { return hp; }\n\n\t\tprivate void record(int x)\n\t\t{\n\t\t\ttargets[hp] = x;\n\t\t\thistupper[hp] = upper[x];\n\t\t\t//\n\t\t\thp++;\n\t\t}\n\n\t\tpublic void revert(int to)\n\t\t{\n\t\t\twhile(hp > to){\n\t\t\t\tupper[targets[hp-1]] = histupper[hp-1];\n\t\t\t\t//\n\t\t\t\thp--;\n\t\t\t}\n\t\t}\n\n\t\tpublic int count()\n\t\t{\n\t\t\tint ct = 0;\n\t\t\tfor(int u : upper){\n\t\t\t\tif(u < 0)ct++;\n\t\t\t}\n\t\t\treturn ct;\n\t\t}\n\n\t\tpublic int[][] makeUp()\n\t\t{\n\t\t\tint n = upper.length;\n\t\t\tint[][] ret = new int[n][];\n\t\t\tint[] rp = new int[n];\n\t\t\tfor(int i = 0;i < n;i++){\n\t\t\t\tif(upper[i] < 0)ret[i] = new int[-upper[i]];\n\t\t\t}\n\t\t\tfor(int i = 0;i < n;i++){\n\t\t\t\tint r = root(i);\n\t\t\t\tret[r][rp[r]++] = i;\n\t\t\t}\n\t\t\treturn ret;\n\t\t}\n\n\t}\n\n\n\tpublic static class QuerySegmentTree\n\t{\n\t\tpublic int M, H, N;\n\t\tpublic L[] st;\n\n\t\tpublic QuerySegmentTree(int n)\n\t\t{\n\t\t\tN = n;\n\t\t\tM = Integer.highestOneBit(Math.max(N-1, 1))<<2;\n\t\t\tH = M>>>1;\n\t\t\tst = new L[M];\n\t\t}\n\n\t\tpublic void put(int l, int r, int qid){\n\t\t\tif(l >= r)return;\n\t\t\twhile(l != 0){\n\t\t\t\tint f = l&-l;\n\t\t\t\tif(l+f > r)break;\n\t\t\t\tL q = st[(H+l)/f];\n\t\t\t\tif(q == null)q = st[(H+l)/f] = new L(1);\n\t\t\t\tq.add(qid);\n\t\t\t\tl += f;\n\t\t\t}\n\n\t\t\twhile(l < r){\n\t\t\t\tint f = r&-r;\n\t\t\t\tL q = st[(H+r)/f-1];\n\t\t\t\tif(q == null)q = st[(H+r)/f-1] = new L(1);\n\t\t\t\tq.add(qid);\n\t\t\t\tr -= f;\n\t\t\t}\n\t\t}\n\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 H().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", "src_uid": "417788298ec54dd5fd7616ab8c5ce246"} {"source_code": "import java.io.*;\nimport java.math.*;\nimport java.util.*;\nimport java.util.stream.*;\n\npublic class BOI2020C {\n\n\tstatic class StackDSU {\n\t\tint[] p;\n\n\t\tint[] idxH;\n\t\tint[] valH;\n\t\tint time = 0;\n\n\t\tint[] snap;\n\t\tint snapSz;\n\n\t\tpublic StackDSU(int n, int maxStackSize, int histSize) {\n\t\t\tp = new int[n];\n\t\t\tArrays.fill(p, -1);\n\t\t\tidxH = new int[histSize];\n\t\t\tvalH = new int[histSize];\n\t\t\tsnap = new int[maxStackSize + 1];\n\t\t}\n\n\t\tint get(int v) {\n\t\t\tint ret = 0;\n\t\t\twhile (p[v] >= 0) {\n\t\t\t\tret ^= p[v];\n\t\t\t\tv = p[v] >> 1;\n\t\t\t}\n\t\t\treturn (v << 1) | (ret & 1);\n\t\t}\n\n\t\tboolean canAdd(int v, int u) {\n\t\t\tv = get(v);\n\t\t\tu = get(u);\n\n\t\t\tint diff = (v ^ u) & 1;\n\t\t\treturn ((v >> 1) != (u >> 1)) || (diff == 1);\n\t\t}\n\n\t\tvoid unite(int v, int u) {\n\t\t\tv = get(v);\n\t\t\tu = get(u);\n\n\t\t\tint diff = (v ^ u) & 1;\n\t\t\tv >>= 1;\n\t\t\tu >>= 1;\n\n\t\t\tif (v == u) {\n\t\t\t\tif (diff == 0) {\n\t\t\t\t\tthrow new AssertionError();\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (p[v] < p[u]) {\n\t\t\t\tint tmp = v;\n\t\t\t\tv = u;\n\t\t\t\tu = tmp;\n\t\t\t}\n\t\t\tset(u, p[v] + p[u]);\n\t\t\tset(v, (u << 1) | (diff ^ 1));\n\t\t\treturn;\n\t\t}\n\n\t\tvoid set(int idx, int val) {\n\t\t\tif (p[idx] != val) {\n\t\t\t\tidxH[time] = idx;\n\t\t\t\tvalH[time] = p[idx];\n\t\t\t\tp[idx] = val;\n\t\t\t\t++time;\n\t\t\t}\n\t\t}\n\n\t\tpublic void push(UpdateInfo upd) {\n\t\t\tsnap[snapSz++] = time;\n\t\t\tunite(upd.u, upd.v);\n\t\t}\n\n\t\tpublic void pop() {\n\t\t\tint rollTo = snap[--snapSz];\n\t\t\twhile (time > rollTo) {\n\t\t\t\t--time;\n\t\t\t\tp[idxH[time]] = valH[time];\n\t\t\t}\n\t\t}\n\t}\n\n\t// Must have auto-incrementable ID.\n\tstatic class UpdateInfo {\n\t\tprivate static int count;\n\t\tint id;\n\n\t\tint v, u;\n\n\t\tpublic UpdateInfo(int v, int u) {\n\t\t\tid = count++;\n\t\t\tthis.v = v;\n\t\t\tthis.u = u;\n\t\t}\n\t}\n\n\tstatic class QueueFromStack {\n\t\tpublic StackDSU ds;\n\n\t\t// stack of updates that shows in which order they were actually applied\n\t\tprivate UpdateInfo[] stack;\n\t\tprivate int size;\n\n\t\tprivate UpdateInfo[] buf;\n\n\t\t// updates with id < mark are grouped into power-of-2 length blocks\n\t\t// and are in the \"correct\"(i.e. reversed) order\n\t\tprivate int mark;\n\n\t\t// id of queue's head or mark if queue is empty\n\t\tprivate int head;\n\n\t\tpublic QueueFromStack(StackDSU ds, int maxQueueSize) {\n\t\t\tUpdateInfo.count = 0;\n\t\t\tthis.ds = ds;\n\t\t\tstack = new UpdateInfo[maxQueueSize];\n\t\t\tbuf = new UpdateInfo[maxQueueSize];\n\t\t}\n\n\t\tpublic void add(UpdateInfo upd) {\n\t\t\tstack[size++] = upd;\n\t\t\tds.push(upd);\n\t\t}\n\n\t\tpublic void poll() {\n\t\t\tif (mark == head) {\n\t\t\t\tmark = UpdateInfo.count;\n\t\t\t\tfor (int i = size - 1; i >= 0; --i) {\n\t\t\t\t\tds.pop();\n\t\t\t\t\tbuf[i] = stack[i];\n\t\t\t\t}\n\t\t\t\tfor (int i = 0; i < size; ++i) {\n\t\t\t\t\tds.push(stack[i] = buf[size - 1 - i]);\n\t\t\t\t}\n\t\t\t}\n\t\t\tint ptr = 0;\n\t\t\twhile (stack[size - 1].id != head) {\n\t\t\t\t// must have id >= mark\n\t\t\t\tbuf[ptr++] = stack[--size];\n\t\t\t\tds.pop();\n\t\t\t}\n\n\t\t\tif (ptr == 0) {\n\t\t\t\tds.pop();\n\t\t\t\t--size;\n\t\t\t\t++head;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tint skip = ptr;\n\t\t\tint chunk = Integer.lowestOneBit(mark - head);\n\t\t\tfor (int i = 0; i < chunk; ++i) {\n\t\t\t\t// must have id < mark\n\t\t\t\tbuf[ptr++] = stack[--size];\n\t\t\t\tds.pop();\n\t\t\t}\n\n\t\t\t// putting back id >= mark\n\t\t\tfor (int i = skip - 1; i >= 0; --i) {\n\t\t\t\tds.push(stack[size++] = buf[i]);\n\t\t\t}\n\t\t\t// putting back id < mark except id == head\n\t\t\tfor (int i = ptr - 1; i > skip; --i) {\n\t\t\t\tds.push(stack[size++] = buf[i]);\n\t\t\t}\n\n\t\t\t++head;\n\t\t}\n\t}\n\n\tboolean[] fast(int n, int[] vs, int[] us, int[] ls, int[] rs) {\n\t\tint m = vs.length;\n\t\tint q = ls.length;\n\n\t\tStackDSU dsu = new StackDSU(n, 2 * m, 2_000_000);\n\t\tQueueFromStack que = new QueueFromStack(dsu, 2 * m);\n\n\t\tint[] stop = new int[m];\n\n\t\tfor (int i = 0, j = 0; i < m; i++) {\n\t\t\twhile (j < 2 * m) {\n\t\t\t\tint v = vs[j % m];\n\t\t\t\tint u = us[j % m];\n\t\t\t\tif (!dsu.canAdd(v, u)) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tque.add(new UpdateInfo(v, u));\n\t\t\t\t++j;\n\t\t\t}\n\t\t\tstop[i] = j;\n\t\t\tque.poll();\n\t\t}\n\n\t\tboolean[] ret = new boolean[q];\n\n\t\tfor (int i = 0; i < q; i++) {\n\t\t\tint l = ls[i];\n\t\t\tint r = rs[i];\n\t\t\tboolean ans;\n\t\t\tif (r == m - 1) {\n\t\t\t\tans = stop[0] < l;\n\t\t\t} else {\n\t\t\t\tans = stop[r + 1] < l + m;\n\t\t\t}\n\t\t\tret[i] = ans;\n\t\t}\n\n\t\treturn ret;\n\t}\n\n\tstatic boolean test(int mask, int i) {\n\t\treturn ((mask >> i) & 1) == 1;\n\t}\n\t\n\tboolean slowSingle(int n, int[] vs, int[] us, int l, int r) {\n\t\touter: for (int mask = 0; mask < 1 << n; mask++) {\n\t\t\tfor (int i = 0; i < vs.length; i++) {\n\t\t\t\tif (l <= i && i <= r) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (test(mask, vs[i]) == test(mask, us[i])) {\n\t\t\t\t\tcontinue outer;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\tboolean[] slow(int n, int[] vs, int[] us, int[] ls, int[] rs) {\n\t\tboolean[] ret = new boolean[ls.length];\n\n\t\tfor (int i = 0; i < ls.length; i++) {\n\t\t\tret[i] = slowSingle(n, vs, us, ls[i], rs[i]);\n\t\t}\n\n\t\treturn ret;\n\t}\n\n\tvoid submit() {\n\t\tint n = nextInt();\n\t\tint m = nextInt();\n\t\tint q = nextInt();\n\t\tint[] vs = new int[m];\n\t\tint[] us = new int[m];\n\t\tfor (int i = 0; i < m; i++) {\n\t\t\tvs[i] = nextInt() - 1;\n\t\t\tus[i] = nextInt() - 1;\n\t\t}\n\n\t\tint[] ls = new int[q];\n\t\tint[] rs = new int[q];\n\n\t\tfor (int i = 0; i < q; i++) {\n\t\t\tls[i] = nextInt() - 1;\n\t\t\trs[i] = nextInt() - 1;\n\t\t}\n\n\t\tboolean[] ans = fast(n, vs, us, ls, rs);\n//\t\tboolean[] ans = slow(n, vs, us, ls, rs);\n\n\t\tfor (boolean b : ans) {\n\t\t\tout.println(b ? \"YES\" : \"NO\");\n\t\t}\n\t}\n\n\tvoid test() {\n\n\t}\n\n\tstatic final int B = 10;\n\t\n\tvoid stress() {\n\t\tfor (int tst = 0;; tst++) {\n\t\t\tint n = rand(2, B);\n\t\t\tint m = rand(1, B);\n\t\t\tint q = B;\n\t\t\tint[] vs = new int[m];\n\t\t\tint[] us = new int[m];\n\t\t\tfor (int i = 0; i < m; i++) {\n\t\t\t\tvs[i] = rand(0, n - 1);\n\t\t\t\tus[i] = (vs[i] + rand(1, n - 1)) % n;\n\t\t\t}\n\t\t\tint[] ls = new int[q];\n\t\t\tint[] rs = new int[q];\n\t\t\tfor (int i = 0; i < q; i++) {\n\t\t\t\tls[i] = rand(0, m - 1);\n\t\t\t\trs[i] = rand(ls[i], m - 1);\n\t\t\t}\n\t\t\t\n\t\t\tboolean[] fast = fast(n, vs, us, ls, rs);\n\t\t\tboolean[] slow = slow(n, vs, us, ls, rs);\n\t\t\t\n\t\t\tif (!Arrays.equals(fast, slow)) {\n\t\t\t\tSystem.err.println(n + \" \" + m + \" \" + q);\n\t\t\t\tSystem.err.println(Arrays.toString(vs));\n\t\t\t\tSystem.err.println(Arrays.toString(us));\n\t\t\t\tSystem.err.println(Arrays.toString(ls));\n\t\t\t\tSystem.err.println(Arrays.toString(rs));\n\t\t\t\t\n\t\t\t\tSystem.err.println(\"fast \" + Arrays.toString(fast));\n\t\t\t\tSystem.err.println(\"slow \" + Arrays.toString(slow));\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\tBOI2020C() 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 BOI2020C();\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", "src_uid": "57ad95bb938906f7550f7eb6422130f7"} {"source_code": "import java.util.ArrayList;\nimport java.util.List;\nimport java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n\n Scanner scanner = new Scanner(System.in);\n\n int y = scanner.nextInt();\n int b = scanner.nextInt();\n int r = scanner.nextInt();\n\n int q = 0;\n int w = 0;\n int e = 0;\n if (y < b) {\n q = y;\n w = y+1;\n } else {\n q = b - 1;\n w = b;\n }\n\n if (r > q && r > w) {\n e = w + 1;\n } else {\n e = r;\n w = e - 1;\n q = w - 1;\n }\n\n System.out.println(q + w + e);\n }\n}\n", "src_uid": "03ac8efe10de17590e1ae151a7bae1a5"} {"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<MAX; i++)\n if(isPrime[i]) {\n mu[i] = -1;\n for(int j=i+i; j<MAX; j+=i) {\n isPrime[j] = false;\n mu[j] *= -1;\n if(j%(i*1L*i) == 0) mu[j] = 0;\n }\n }\n \n n = in.nextLong();\n m = in.nextLong();\n l = in.nextLong();\n r = in.nextLong();\n p = in.nextLong();\n \n long ans = 0;\n for(long d=1; d<=Math.min(n,m); d++)\n for(long x=1; x<=n/d; x++) {\n long tmp = go(d,x,r*r) - go(d,x,l*l - 1);\n tmp = (tmp*mu[(int) d]*((n-d*x+1)%p))%p;\n ans = (ans + tmp)%p;\n }\n if(l == 1) ans = (ans + 2*n*m + n + m)%p;\n out.println((ans+p)%p);\n out.close();\n }\n static long go(long d, long x, long v) {\n if(v < d*x*d*x) return 0;\n long tmp = Math.min(m/d, (long)Math.floor(Math.sqrt(v - d*x*d*x)+EPS)/d);\n long ret = (2*m - d*(tmp+1) + 2)%p;\n return (ret*tmp)%p;\n }\n\n static class FastIO extends PrintWriter {\n BufferedReader br;\n StringTokenizer st;\n\n public FastIO() {\n this(System.in, System.out);\n }\n\n public FastIO(InputStream in, OutputStream out) {\n super(new BufferedWriter(new OutputStreamWriter(out)));\n br = new BufferedReader(new InputStreamReader(in));\n scanLine();\n }\n\n public void scanLine() {\n try {\n st = new StringTokenizer(br.readLine().trim());\n } catch (Exception e) {\n throw new RuntimeException(e.getMessage());\n }\n }\n\n public int numTokens() {\n if (!st.hasMoreTokens()) {\n scanLine();\n return numTokens();\n }\n return st.countTokens();\n }\n\n public String next() {\n if (!st.hasMoreTokens()) {\n scanLine();\n return next();\n }\n return st.nextToken();\n }\n\n public double nextDouble() {\n return Double.parseDouble(next());\n }\n\n public long nextLong() {\n return Long.parseLong(next());\n }\n\n public int nextInt() {\n return Integer.parseInt(next());\n }\n }\n}\n", "src_uid": "2afe29a7dbbd2e261e1870a43d57b46f"} {"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.math.*;\nimport java.util.*;\n\n@SuppressWarnings(\"unused\")\npublic class D {\n\n\tprivate final static boolean autoflush = false;\n\n\tprivate static final int MOD = (int) 1e9 + 7;\n\tprivate static BigInteger BMOD = valueOf(MOD);\n\tprivate static final double eps = 1e-9;\n\tprivate static final int INF = (int) 1e9;\n\tprivate static final Error NO = new Error(\"NO\");\n\n\tpublic D () {\n\t\tN = sc.nextInt();\n\t\tM = sc.nextInt();\n\n\t\tint X = sc.nextInt();\n\t\tint Y = sc.nextInt();\n\n\t\tint [] T = dir(sc.next());\n\n\t\tA = new int [N]; B = new int [N];\n\t\tC = new int [M]; D = new int [M];\n\n\t\tZ = 2 * (N/2 + M/2); int P = (X+Y) % 2;\n\t\tif (N % 2 == 1 && P == 0) ++Z;\n\t\tif (N % 2 == 1 && P == (1 + M) % 2) ++Z;\n\t\tif (M % 2 == 1 && P == 0) ++Z;\n\t\tif (M % 2 == 1 && P == (1 + N) % 2) ++Z;\n\n\t\tlong res = 1;\n\t\tfor (;;) {\n\t\t\tif (mark(X, Y))\n\t\t\t\tbreak;\n\t\t\tres += next(X, Y, T);\n\t\t\tX = W[0]; Y = W[1];\n\t\t}\n\n\t\texit(res);\n\t}\n\n\tint N, M, Z, K = 0;\n\tint [] A, B, C, D, W = new int [2];\n\n\tint next(int X, int Y, int [] T) {\n\t\tif (X == 1) T[0] = 1;\n\t\tif (X == N) T[0] = -1;\n\t\tif (Y == 1) T[1] = 1;\n\t\tif (Y == M) T[1] = -1;\n\n\t\tint t = INF, dx = T[0], dy = T[1];\n\t\tif (dx == 1) t = min(t, N - X);\n\t\tif (dx == -1) t = min(t, X - 1);\n\t\tif (dy == 1) t = min(t, M - Y);\n\t\tif (dy == -1) t = min(t, Y - 1);\n\n\t\tX += t * dx; Y += t * dy;\n\t\tW[0] = X; W[1] = Y;\n\t\treturn t;\n\t}\n\n\tvoid set(int [] T, int dx, int dy) {\n\t\tT[0] = dx; T[1] = dy;\n\t}\n\n\tboolean mark(int X, int Y) {\n\t\tboolean res = false;\n\t\tif (Y == 1)\n\t\t\tres = res || inc(A, X);\n\t\tif (Y == M)\n\t\t\tres = res || inc(B, X);\n\t\tif (X == 1)\n\t\t\tres = res || inc(C, Y);\n\t\tif (X == N)\n\t\t\tres = res || inc(D, Y);\n\t\treturn res;\n\t}\n\n\tboolean inc(int [] A, int X) {\n\t\tif (A[X-1] == 0) ++K; ++A[X-1];\n\t\tif (A[X-1] == 3)\n\t\t\texit(-1);\n\t\treturn K == Z;\n\t}\n\n\tint [] dir (String D) {\n\t\tString [] S = { \"UL\", \"UR\", \"DL\", \"DR\" };\n\t\tint [][] T = { { -1, -1 }, { -1, 1 }, { 1, -1 }, { 1, 1 }};\n\t\tfor (int i : rep(4))\n\t\t\tif (D.equals(S[i]))\n\t\t\t\treturn T[i];\n\t\tthrow new Error();\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) { int [] res = new int [max(T-S, 0)]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }\n\tprivate static int [] req(int S, int T) { return rep(S, T+1); }\n\tprivate static int [] sep(int N) { return sep(0, N); }\n\tprivate static int [] sep(int S, int T) { int [] res = new int [max(T-S, 0)]; for (int i = S; i < T; ++i) res[T-1-i] = i; return res; }\n\tprivate static int [] seq(int S, int T) { return sep(S, T+1); }\n\tprivate static int [] ccw (int [] D) { return new int [] { -D[1], D[0] }; }\n\tprivate static int [] cw (int [] D) { return new int [] { D[1], -D[0] }; }\n\tprivate static <T> T ceiling(SortedSet<T> S, T x) { // Java 1.5 and below\n\t\tSortedSet<T> T = S.tailSet(x);\n\t\treturn T.isEmpty() ? null : T.first();\n\t}\n\tprivate static <T> T floor(SortedSet<T> S, T x) { // Java 1.5 and below\n\t\tif (S.contains(x))\n\t\t\treturn x;\n\t\telse {\n\t\t\tSortedSet<T> T = S.headSet(x);\n\t\t\treturn T.isEmpty() ? null : T.last();\n\t\t}\n\t}\n\tprivate static int [] digits(long N, int B, int sz) {\n\t\tint [] res = new int [sz];\n\t\tfor (int i : sep(sz))\n\t\t\tif (N > 0) {\n\t\t\t\tres[i] = (int)(N % B);\n\t\t\t\tN /= B;\n\t\t\t}\n\t\treturn res;\n\t}\n\tprivate static int digitSum(long N) {\n\t\tint res = 0;\n\t\tfor (; N > 0; res += N % 10, N /= 10);\n\t\treturn res;\n\t}\n\tprivate static <T extends Comparable<T>> T max(T x, T y) { return x.compareTo(y) > 0 ? x : y; }\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 modPow(long b, long e) { return valueOf(b).modPow(valueOf(e), BMOD).longValue(); }\n\tprivate static long pow(long b, long e) { return round(Math.pow(b, e)); }\n\tprivate static String reverse (String S) { return new StringBuilder(S).reverse().toString(); }\n\tprivate static char [][] toCharArrays(String [] S) {\n\t\tint N = S.length;\n\t\tchar [][] res = new char [N][];\n\t\tfor (int i : rep(N))\n\t\t\tres[i] = S[i].toCharArray();\n\t\treturn res;\n\t}\n\t////////////////////////////////////////////////////////////////////////////////////\n\tprivate final static MyScanner sc = new MyScanner();\n\tprivate static class MyScanner {\n\t\tprivate String next() {\n\t\t\tnewLine();\n\t\t\treturn line[index++];\n\t\t}\n\t\tprivate char nextChar() {\n\t\t\treturn next().charAt(0);\n\t\t}\n\t\tprivate int nextInt() {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\tprivate long nextLong() {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\tprivate double nextDouble() {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\tprivate String nextLine() {\n\t\t\tline = null;\n\t\t\treturn readLine();\n\t\t}\n\t\tprivate String [] nextStrings() {\n\t\t\tline = null;\n\t\t\treturn readLine().split(\" \");\n\t\t}\n\t\tprivate char [] nextChars() {\n\t\t\treturn next ().toCharArray ();\n\t\t}\n\t\tprivate 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}\n\t\tprivate 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\t\tprivate 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\t\tprivate 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] = next();\n\t\t\treturn res;\n\t\t}\n\t\tprivate 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] = nextInt();\n\t\t\treturn res;\n\t\t}\n\t\tprivate 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] = nextLong();\n\t\t\treturn res;\n\t\t}\n\t\tprivate 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] = nextDouble();\n\t\t\treturn res;\n\t\t}\n\t\tprivate 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] = nextStrings();\n\t\t\treturn res;\n\t\t}\n\t\tprivate 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] = nextInts();\n\t\t\treturn res;\n\t\t}\n\t\tprivate 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] = nextLongs();\n\t\t\treturn res;\n\t\t}\n\t\tprivate 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] = nextDoubles();\n\t\t\treturn res;\n\t\t}\n\t\t//////////////////////////////////////////////\n\t\tprivate boolean eol() {\n\t\t\treturn index == line.length;\n\t\t}\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 () {\n\t\t\tthis(new java.io.BufferedReader(new java.io.InputStreamReader(System.in)));\n\t\t}\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) {\n\t\tprintDelim(\" \", o, a);\n\t}\n\tprivate static void cprint (Object o, Object... a) {\n\t\tprintDelim(\"\", o, a);\n\t}\n\tprivate static void printDelim (String delim, Object o, Object... a) {\n\t\tpw.println(build(delim, o, a));\n\t}\n\tprivate static void exit (Object o, Object... a) {\n\t\tprint(o, a);\n\t\texit();\n\t}\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\tprivate static void NO() {\n\t\tthrow new Error(\"NO!\");\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.toString().trim();\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 : rep(L))\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() {\n\t\tt = millis();\n\t}\n\tprivate static java.io.PrintWriter pw = new java.io.PrintWriter(System.out, autoflush);\n\tprivate static long t;\n\tprivate static long millis() {\n\t\treturn System.currentTimeMillis();\n\t}\n\tprivate static void statics() {\n\t\tabs(0); valueOf(0); asList(new Object [0]); reverseOrder();\n\t}\n\tpublic static void main (String[] args) {\n\t\tnew D();\n\t\texit();\n\t}\n}\n", "src_uid": "8a59247013a9b1f34700f4bfc7d1831d"} {"source_code": "import java.io.*;\nimport java.util.*;\npublic class Main {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc=new Scanner(System.in);\n\t\tPrintWriter pw=new PrintWriter(System.out);\n\t\twhile(sc.hasNext()){\n\t\t\tint n=sc.nextInt();\n\t\t\tint w=sc.nextInt();\n\t\t\tint[]shu=new int[n];\n\t\t\tS[]s=new S[n];\n\t\t\tint sum=0;\n\t\t\tfor(int i=0;i<n;i++){\n\t\t\t\tshu[i]=sc.nextInt();\n\t\t\t\tsum+=(shu[i]+1)/2;\n\t\t\t\ts[i]=new S(shu[i],i);\n\t\t\t}\n\t\t\tif(sum>w)pw.println(-1);\n\t\t\telse{\n\t\t\t\tw-=sum;\n\t\t\t\tint []d=new int[n];\n\t\t\t\tArrays.sort(s);\n\t\t\t\tfor(int i=0;i<n;i++){\n\t\t\t\t\tif(s[i].s-(s[i].s+1)/2<=w){\n\t\t\t\t\t\td[s[i].index]=s[i].s-(s[i].s+1)/2;\n\t\t\t\t\t\tw-=s[i].s-(s[i].s+1)/2;\n\t\t\t\t\t}else{\n\t\t\t\t\t\t\td[s[i].index]=w;\n\t\t\t\t\t\t\tw=0;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(w>0)pw.println(-1);\n\t\t\t\telse{\n\t\t\t\t\tfor(int i=0;i<n;i++){\n\t\t\t\t\t\tpw.print(d[i]+(shu[i]+1)/2+\" \");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tpw.flush();\n\t\t}\n\n\t}\n\n}\nclass S implements Comparable<S>{\n\tint s;\n\tint index;\n\tS(int a,int b){\n\t\ts=a;\n\t\tindex=b;\n\t}\n\t@Override\n\tpublic int compareTo(S a) {\n\t\tif(this.s<a.s)return 1;\n\t\tif(this.s>a.s)return -1;\n\t\treturn 0;\n\t}\n}\nclass FastScanner {\n\tBufferedReader br;\n\tStringTokenizer st;\n\n\tpublic FastScanner() {\n\t\ttry {\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\n\t\t\tst = new StringTokenizer(\"\");\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\n\tpublic boolean hasNext() {\n\t\twhile (!st.hasMoreTokens()) {\n\t\t\tString line = nextLine();\n\t\t\tif (line == null) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tst = new StringTokenizer(line);\n\t\t}\n\t\treturn true;\n\t}\n\n\tpublic String next() {\n\t\tif (st.hasMoreTokens())\n\t\t\treturn st.nextToken();\n\t\ttry {\n\t\t\tst = new StringTokenizer(br.readLine());\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t\treturn st.nextToken();\n\t}\n\n\tpublic int nextInt() {\n\t\treturn Integer.parseInt(next());\n\t}\n\n\tpublic long nextLong() {\n\t\treturn Long.parseLong(next());\n\t}\n\n\tpublic double nextDouble() {\n\t\treturn Double.parseDouble(next());\n\t}\n\n\tpublic String nextLine() {\n\t\tString line = \"\";\n\t\ttry {\n\t\t\tline = br.readLine();\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t\treturn line;\n\t}\n}", "src_uid": "5d3bb9e03f4c5c8ecb6233bd5f90f3a3"} {"source_code": "import java.io.BufferedWriter;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.io.ObjectInputStream.GetField;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.InputMismatchException;\nimport java.util.LinkedList;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.PriorityQueue;\nimport java.util.Queue;\nimport java.util.Random;\nimport java.util.Scanner;\nimport java.util.Stack;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\n \n\t\tpublic\tclass Q2 {\n\t\t\t\t\n\t\t\t\tstatic long MOD = 1000000007;\n\t\t\t\tstatic boolean b1,b[],bc[];\n\t\t\t\tstatic boolean boo[][][];\n\t\t\t\tstatic int ans1 = -1,ans2 = -1, root;\n\t\t\t\tstatic ArrayList<Integer>[] amp,amp1;\n\t\t\t\tstatic ArrayList<Pair>[] pmp;\n\t\t\t\tstatic int sum[],dist[],cnt[],ans[],size[],col[][];\n\t\t\t\tstatic int p = 0,cnt1 =0 ,cnt2 = 0;\n\t\t\t\t//static ArrayList<Pair3>[][][] pmp;\n\t\t\t\tstatic FasterScanner sc = new FasterScanner(System.in);\n\t\t\t\tstatic Queue<Integer> q = new LinkedList<>();\n\t\t\t\tstatic int arr[],start[],end[],color[],parent[];\n\t\t\t\tstatic PriorityQueue<Integer> pq;\n\t\t\t\t//static ArrayList<Integer> parent = new ArrayList<>();\n\t\t\t\tstatic LinkedList<Integer> fa;\n\t\t\t\tstatic BufferedWriter log;\n\t\t\t\tstatic TreeMap<Integer,Integer> tm = new TreeMap<>();\n\t\t\t//\tstatic HashMap<Integer,Pair> hs;\n\t\t\t\tstatic Stack<Integer> stack = new Stack<>();\n\t\t\t\tstatic Pair prr[];\n\t\t\t\tstatic int dp[][];\n\t\t\t\tstatic long parent1[],parent2[],size1[],size2[],value[];\n\t\t\t\tstatic long Ans;\n\t\t\t\tpublic static void main(String[] args) throws Exception {\n\t\t\t\t\t/*new Thread(null, new Runnable() {\n\t\t\t\t\t\tpublic void run() {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tsoln();\n\t\t\t\t\t\t\t} catch (Exception e) {\n\t\t\t\t\t\t\t\tSystem.out.println(e);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}, \"1\", 1 << 26).start();*/\n\t\t\t\t\tsoln();\n\t\t\t }\n\t\t\t\tstatic int MAX = 1000005;\n\t\t\t\tstatic int n , m ,k, max, x1, x2;\n\t\t\t\tstatic HashSet<Pair> hs;\n\t\t\t\tstatic double DP[][][];\n\t\t\t\tpublic static void soln() throws IOException {\n\t\t\t\t\t//FasterScanner in = new FasterScanner(new FileInputStream(\"C:\\\\Users\\\\Admin\\\\Desktop\\\\QAL.txt\"));\n\t\t\t\t\t//PrintWriter out = new PrintWriter(\"C:\\\\Users\\\\Admin\\\\Desktop\\\\A1.txt\");\n\t\t\t\t\tlog = new BufferedWriter(new OutputStreamWriter(System.out));\n\t\t\t\t\tint n = sc.nextInt();\n\t\t\t\t\tint m[] = sc.nextIntArray(n);\n\t\t\t\t\tint r[] = sc.nextIntArray(n);\n\t\t\t\t\tboolean b[] = new boolean[1000000];\n\t\t\t\t\tlong lcm = m[0], gcd = m[0], mul =m[0];\n\t\t\t\t\tfor(int i =1 ;i <n; i++){\n\t\t\t\t\t\tlcm = ((lcm*m[i])/gcd(lcm,m[i]));\n\t\t\t\t\t}\n\t\t\t\t\t//System.out.println(mul+\" \"+lcm);\n\t\t\t\t\tint cnt = 0;\n\t\t\t\t\tfor(int i = 0; i<n ; i++){\n\t\t\t\t\t\tfor(int j = 1;j<=lcm;j++){\n\t\t\t\t\t\t\tif(j%m[i]==r[i] && !b[j]){\n\t\t\t\t\t\t\t\tb[j] = true;\n\t\t\t\t\t\t\t\tcnt++;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t//System.out.println(cnt);\n\t\t\t\t\tSystem.out.printf(\"%.9f\",(double)cnt/lcm);\n\t\t\t\t\tlog.close();\n\t\t\t\t\t//out.close();\n\t\t\t\t}\n\t\t\t\t static long maxSubArraySum(long a[])\n\t\t\t\t {\n\t\t\t\t int size = a.length;\n\t\t\t\t long max_so_far = Long.MIN_VALUE/2, max_ending_here = 0;\n\n\t\t\t\t for (int i = 0; i < size; i++)\n\t\t\t\t {\n\t\t\t\t max_ending_here = max_ending_here + a[i];\n\t\t\t\t if(max_so_far < max_ending_here)\n\t\t\t\t max_so_far = max_ending_here;\n\t\t\t\t if(max_ending_here < 0)\n\t\t\t\t max_ending_here = 0;\n\t\t\t\t }\n\t\t\t\t return max_so_far;\n\t\t\t\t }\n\t\t\t\tpublic class TrieNode{\n\t\t\t\t\tTrieNode[] t = new TrieNode[2];\n\t\t\t\t\tint cnt = 0;\n\t\t\t\t}\n\t\t\t\tpublic class Trie{\n\t\t\t\t\tTrieNode root;\n\t\t\t\t\tTrie(){\n\t\t\t\t\t\troot = new TrieNode();\n\t\t\t\t\t}\n\t\t\t\t\tpublic void insert(String s){\n\t\t\t\t\t\tTrieNode temp = root;\n\t\t\t\t\t\tfor(int i = 0; i< s.length();i++){\n\t\t\t\t\t\t\tif(temp.t[s.charAt(i)-'0']==null){\n\t\t\t\t\t\t\t\tTrieNode n = new TrieNode();\n\t\t\t\t\t\t\t\ttemp.t[s.charAt(i)-'0'] = n;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\ttemp = temp.t[s.charAt(i)-'0'];\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttemp.cnt++;\n\t\t\t\t\t}\n\t\t\t\t\tpublic void delete(String s, TrieNode temp){\n\t\t\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\t\tpublic String get(String s){\n\t\t\t\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\t\t\t\tTrieNode temp = root;\n\t\t\t\t\t\tfor(int i = 0; i< s.length();i++){\n\t\t\t\t\t\t\tint x = (s.charAt(i)-'0'+1)%2;\n\t\t\t\t\t\t\tif(temp.t[x]!=null){\n\t\t\t\t\t\t\t\ttemp = temp.t[x];\n\t\t\t\t\t\t\t\tsb.append(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\ttemp = temp.t[(x+1)%2];\n\t\t\t\t\t\t\t\tsb.append(0);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn sb.toString();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tpublic static class FenwickTree {\n\t\t\t\t int[] array; // 1-indexed array, In this array We save cumulative information to perform efficient range queries and updates\n\t\t\t\t public FenwickTree(int size) {\n\t\t\t\t array = new int[size + 1];\n\t\t\t\t }\n\t\t\t\t public int rsq(int ind) {\n\t\t\t\t assert ind > 0;\n\t\t\t\t int sum = 0;\n\t\t\t\t while (ind > 0) {\n\t\t\t\t sum += array[ind];ind -= ind & (-ind);\n\t\t\t\t }\n\t\t\t\t return sum;\n\t\t\t\t }\n\t\t\t\t public int rsq(int a, int b) {\n\t\t\t\t assert b >= a && a > 0 && b > 0;\n\t\t\t\t return rsq(b) - rsq(a - 1);\n\t\t\t\t }\n\t\t\t\t public void update(int ind, int value) {\n\t\t\t\t assert ind > 0;\n\t\t\t\t while (ind < array.length) {\n\t\t\t\t array[ind] += value; ind += ind & (-ind);\n\t\t\t\t }\n\t\t\t\t }\n\t\t\t\t public int size() {\n\t\t\t\t return array.length - 1;\n\t\t\t\t }\n\t\t\t\t}\n\t\t\t\tpublic static void dfs(int x){\n\t\t\t\t\tb[x] = true;\n\t\t\t\t\tfor(int e:amp[x]){\n\t\t\t\t\t\tif(!b[e]){\n\t\t\t\t\t\t\tdfs(e);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tpublic static void bfs(int x){\n\t\t\t\t\tb[x] = true;\n\t\t\t\t\tq = new LinkedList<Integer>();\n\t\t\t\t\tq.add(x);\n\t\t\t\t\twhile(!q.isEmpty()){\n\t\t\t\t\t\t//System.out.println(q);\n\t\t\t\t\t\tint y = q.poll();\n\t\t\t\t\t\t\tfor(int i:amp[y]){\n\t\t\t\t\t\t\tif(!b[i]){\n\t\t\t\t\t\t\t\tq.add(i);\n\t\t\t\t\t\t\t\tdist[i] = Math.max(dist[i], dist[y]+1);\n\t\t\t\t\t\t\t\tif(dist[i]>max){\n\t\t\t\t\t\t\t\t\tmax = dist[i];\n\t\t\t\t\t\t\t\t\tk = i;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tb[i]= true;\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\tstatic class Pair implements Comparable<Pair> {\n\t\t\t\t\tint u;\n\t\t\t\t\tint v;\n\t\t\t\t\tpublic Pair(){\n\t\t\t\t\t\tu = 0;\n\t\t\t\t\t\tv = 0;\n\t\t\t\t\t}\n\t\t\t\t\tpublic Pair(int u, int v) {\n\t\t\t\t\t\tthis.u = u;\n\t\t\t\t\t\tthis.v = v;\n\t\t\t\t\t}\n\t\t\t\t\tpublic int hashCode() {\n\t\t\t\t\t\tint hu = (int) (u ^ (u >>> 32));\n\t\t\t\t\t\tint hv = (int) (v ^ (v >>> 32));\n\t\t\t\t\t\treturn 31*hu + hv;\n\t\t\t\t\t}\n\t\t\t \n\t\t\t\t\tpublic boolean equals(Object o) {\n\t\t\t\t\t\tPair other = (Pair) o;\n\t\t\t\t\t\treturn (u == other.u && v == other.v);\n\t\t\t\t\t}\n\t\t\t \n\t\t\t\t\tpublic int compareTo(Pair other) {\n\t\t\t\t\t\treturn Long.compare(u, other.u) != 0 ? (Long.compare(u, other.u)) : (Long.compare(v, other.v));\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tpublic String toString() {\n\t\t\t\t\t\treturn \"[u=\" + u + \", v=\" + v + \"]\";\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tpublic static long gcd(long gc, long m){\n\t\t\t\t\tif(m!=0) return gcd(m,gc%m);\n\t\t\t\t\telse return gc;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tstatic int CeilIndex(int A[], int l, int r, int key)\n\t\t\t {\n\t\t\t while (r - l > 1)\n\t\t\t {\n\t\t\t int m = l + (r - l)/2;\n\t\t\t if (A[m]>=key)\n\t\t\t r = m;\n\t\t\t else\n\t\t\t l = m;\n\t\t\t }\n\t\t\t \n\t\t\t return r;\n\t\t\t }\n\t\t\t/*\tpublic static Pair recur(int N, int K, int C){\n\t\t\t\t\tif(K>k) return new Pair(Long.MAX_VALUE/2,-1);\n\t\t\t\t\tif(N>=n && k<K) return new Pair(Long.MAX_VALUE/2,-1);\n\t\t\t\t\tif(N>=n && k==K) return new Pair(0,k);\n\t\t\t\t\tif(N>=n) return new Pair(0,0);\n\t\t\t\t\tif(dp[N][C][K]!=null){\n\t\t\t\t\t\t//System.out.println(dp[N][C][K]);\n\t\t\t\t\t\treturn dp[N][C][K];\n\t\t\t\t\t} \n\t\t\t\t\tPair ans = new Pair(Long.MAX_VALUE/2,-1);\n\t\t\t\t\tif(arr[N]>0){\n\t\t\t\t\t\tPair p;\n\t\t\t\t\t\tif(arr[N]==C) p = recur(N+1,K,arr[N]);\n\t\t\t\t\t\telse p = recur(N+1,K+1,arr[N]);\n\t\t\t\t\t\tif((p.u)<ans.u){\n\t\t\t\t\t\t\tans = p;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(p.u==ans.u){\n\t\t\t\t\t\t\tif(p.v>ans.v){\n\t\t\t\t\t\t\t\tans = 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\telse{\n\t\t\t\t\tfor(int i = 1 ;i <= m; i++){\n\t\t\t\t\t\tPair p;\n\t\t\t\t\t\tif(i==C)\n\t\t\t\t\t\tp = recur(N+1,K,i);\n\t\t\t\t\t\telse p = recur(N+1,K+1,i);\n\t\t\t\t\t\tp.u+=col[N][i-1];\n\t\t\t\t\t\tif((p.u)<ans.u){\n\t\t\t\t\t\t\tans = p;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(p.u==ans.u){\n\t\t\t\t\t\t\tif(p.v>ans.v){\n\t\t\t\t\t\t\t\tans = 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\t//System.out.println(ans);\n\t\t\t\t\t}\n\t\t\t\t\treturn dp[N][C][K] = ans;\n\t\t\t\t}*/\n\t\t\t\tpublic static void mergeSort(int[] arr2, int l ,int r){\n\t\t\t\t\tif((r-l)>=1){\n\t\t\t\t\t\tint mid = (l+r)/2;\n\t\t\t\t\t\tmergeSort(arr2,l,mid);\n\t\t\t\t\t\tmergeSort(arr2,mid+1,r);\n\t\t\t\t\t\tmerge(arr2,l,r,mid);\n\t\t\t\t\t\t//System.out.println(Ans);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tpublic static void merge(int arr[], int l, int r, int mid){\n\t\t\t\t\tint n1 = (mid-l+1), n2 = (r-mid);\n\t\t\t\t\tint left[] = new int[n1];\n\t\t\t\t\tint right[] = new int[n2];\n\t\t\t\t\tfor(int i =0 ;i<n1;i++) left[i] = arr[l+i];\n\t\t\t\t\tfor(int i =0 ;i<n2;i++) right[i] = arr[mid+1+i];\n\t\t\t\t\tint i =0, j =0, k = l;\n\t\t\t\t\twhile(i<n1 && j<n2){\n\t\t\t\t\t\tif(left[i]>right[j]){\n\t\t\t\t\t\t\tcnt[right[j]]+=(n1-i);\n\t\t\t\t\t\t\tarr[k++] = right[j++];\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse{\n\t\t\t\t\t\t\tarr[k++] = left[i++];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\twhile(i<n1) arr[k++] = left[i++];\n\t\t\t\t\twhile(j<n2) arr[k++] = right[j++];\n\t\t\t\t}\n\t\t\t\tpublic static void buildGraph(int n){\n\t\t\t\t\tfor(int i =0;i<n;i++){\n\t\t\t\t\t\tint x = sc.nextInt(), y = sc.nextInt();\n\t\t\t\t\t\tamp[x].add(y);\n\t\t\t\t\t\ths.add(new Pair(x,y));\n\t\t\t\t\t\ths.add(new Pair(y,x));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t\n \n\t\t\t\tpublic static int getParent(int x){\n\t\t\t\t\twhile(parent[x]!=x){\n\t\t\t\t\t\tparent[x] = parent[ parent[x]];\n\t\t\t\t\t\tx = parent[ x];\n\t\t\t\t\t}\n\t\t\t\t\treturn x;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tstatic int min(int a, int b, int c){\n\t\t\t\t\tif(a<b && a<c) return a;\n\t\t\t\t\tif(b<c) return b;\n\t\t\t\t\treturn c;\n\t\t\t\t}\n\t\t\t\tprivate static void permutation(String prefix, String str) {\n\t\t\t\t int n = str.length();\n\t\t\t\t if (n == 0); //hs.add(prefix);\n\t\t\t\t else {\n\t\t\t\t for (int i = 0; i < n; i++)\n\t\t\t\t permutation(prefix + str.charAt(i), str.substring(0, i) + str.substring(i+1, n));\n\t\t\t\t }\n\t\t\t\t}\n\t\t\t\tstatic class Graph{\n\t\t\t\t\tint vertex;\n\t\t\t\t\tlong weight;\n\t\t\t\t}\n\t\t\t\tpublic static void buildTree(int n){\n\t\t\t\t\tint arr[] = sc.nextIntArray(n);\n\t\t\t\t\tfor(int i = 0;i<n;i++){\n\t\t\t\t\t\tint x = arr[i]-1;\n\t\t\t\t\t\tamp[i+1].add(x);\n\t\t\t\t\t\tamp[x].add(i+1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tstatic class Node{\n\t\t\t\t\tlong max = 0, pre = 0, suf = 0, sum = 0;\n\t\t\t\t\tNode(long max, long pre, long suf, long sum){\n\t\t\t\t\t\tthis.max = max;\n\t\t\t\t\t\tthis.pre = pre;\n\t\t\t\t\t\tthis.suf = suf;\n\t\t\t\t\t\tthis.sum = sum;\n\t\t\t\t\t}\n\t\t\t\t\tNode(){};\n\t\t\t\t}\n\t\t\t\tstatic class SegmentTree {\n\t\t\t\t\tNode st[];\n\t\t\t\t//\tlong lazy[];\n\t\t\t\t\tSegmentTree(int n) {\n\t\t\t\t\t\tint size = 4 * n;\n\t\t\t\t\t\tst = new Node[size];\n\t\t\t\t\t\tfor(int i = 0; i< size;i++) st[i] = new Node();\n\t\t\t\t\t//\tlazy = new long[size];\n\t\t\t\t\t\tbuild(0, n - 1, 1);\n\t\t\t\t\t}\n\t\t\t\t\tNode comb(Node l, Node r){\n\t\t\t\t\t\tlong sum = l.sum+r.sum;\n\t\t\t\t\t\tlong pre = Math.max(l.pre, l.sum+r.pre);\n\t\t\t\t\t\tlong suf = Math.max(r.suf, r.sum+l.suf);\n\t\t\t\t\t\tlong max = max(l.max, r.max, l.suf+r.pre);\n\t\t\t\t\t\treturn new Node(max, pre , suf, sum);\n\t\t\t\t\t}\n\t\t\t\t\tNode build(int ss, int se, int si) {\n\t\t\t\t\t\tif(ss==se){\n\t\t\t\t\t\t\tst[si] = new Node(arr[ss],arr[ss],arr[ss],arr[ss]);\n\t\t\t\t\t\t\treturn st[si];\n\t\t\t\t\t\t}\n\t\t\t\t\t\tint mid = (ss+se)/2;\n\t\t\t\t\t\tNode a1 = build(ss, mid, si*2), a2 = build(mid+1, se, si*2+1);\n\t\t\t\t\t\treturn st[si] = comb(a1,a2);\n\t\t\t\t\t}\n \n\t\t\t\t\tvoid update(int si, int ss, int se, int idx, int val) {\n\t\t\t\t\t\tif (ss == se) {\n\t\t\t\t\t\t\tarr[ss] = val;\n\t\t\t\t\t\t\tst[si] = new Node(arr[ss],arr[ss],arr[ss],arr[ss]);\n\t\t\t\t\t\t} \n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tint mid = (ss + se) / 2;\n\t\t\t\t\t\t\tif(ss <= idx && idx <= mid)\n\t\t\t\t\t {\n\t\t\t\t\t update(2*si, ss, mid, idx, val);\n\t\t\t\t\t }\n\t\t\t\t\t else\n\t\t\t\t\t { update(2*si+1, mid+1, se, idx, val);\n\t\t\t\t\t }\n\t\t\t\t\t\t\tst[si] = comb(st[si*2],st[si*2+1]);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tNode get(int qs, int qe, int ss, int se, int si){\n\t\t\t\t\t\tif(qs>se || qe<ss){\n\t\t\t\t\t\t\treturn new Node(-10000000,-100000000,-10000000,-100000000);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (qs <= ss && qe >= se) {\n\t\t\t\t\t\t\treturn st[si];\n\t\t\t\t\t\t}\n\t\t\t\t\t\tint mid = (ss+se)/2;\n\t\t\t\t\t\tNode temp1 = get(qs, qe, ss, mid, si * 2), temp2 = get(qs, qe, mid + 1, se, si * 2 + 1);\n\t\t\t\t\t\treturn st[si] = comb(temp1,temp2);\n\t\t\t\t\t}\n\t\t\t\t\t/*void updateRange(int node, int start, int end, int l, int r, long val)\n\t\t\t\t\t{\n\t\t\t\t\t if(lazy[node] != 0)\n\t\t\t\t\t { \n\t\t\t\t\t // This node needs to be updated\n\t\t\t\t\t st[node] += (end - start + 1) * lazy[node]; // Update it\n\t\t\t\t\t if(start != end)\n\t\t\t\t\t {\n\t\t\t\t\t lazy[node*2] += lazy[node]; // Mark child as lazy\n\t\t\t\t\t lazy[node*2+1] += lazy[node]; // Mark child as lazy\n\t\t\t\t\t }\n\t\t\t\t\t lazy[node] = 0; // Reset it\n\t\t\t\t\t }\n\t\t\t\t\t if(start > end || start > r || end < l) // Current segment is not within range [l, r]\n\t\t\t\t\t return;\n\t\t\t\t\t if(start >= l && end <= r)\n\t\t\t\t\t {\n\t\t\t\t\t // Segment is fully within range\n\t\t\t\t\t st[node] += (end - start + 1) * val;\n\t\t\t\t\t if(start != end)\n\t\t\t\t\t {\n\t\t\t\t\t // Not leaf node\n\t\t\t\t\t lazy[node*2] += val;\n\t\t\t\t\t lazy[node*2+1] += val;\n\t\t\t\t\t }\n\t\t\t\t\t return;\n\t\t\t\t\t }\n\t\t\t\t\t int mid = (start + end) / 2;\n\t\t\t\t\t updateRange(node*2, start, mid, l, r, val); // Updating left child\n\t\t\t\t\t updateRange(node*2 + 1, mid + 1, end, l, r, val); // Updating right child\n\t\t\t\t\t st[node] = st[node*2] + st[node*2+1]; // Updating root with max value \n\t\t\t\t\t}\n \n\t\t\t\t\tlong queryRange(int node, int start, int end, int l, int r)\n\t\t\t\t\t{\n\t\t\t\t\t if(start > end || start > r || end < l)\n\t\t\t\t\t return 0L; // Out of range\n\t\t\t\t\t if(lazy[node] != 0)\n\t\t\t\t\t {\n\t\t\t\t\t // This node needs to be updated\n\t\t\t\t\t st[node] += (end - start + 1) * lazy[node]; // Update it\n\t\t\t\t\t if(start != end)\n\t\t\t\t\t {\n\t\t\t\t\t lazy[node*2] += lazy[node]; // Mark child as lazy\n\t\t\t\t\t lazy[node*2+1] += lazy[node]; // Mark child as lazy\n\t\t\t\t\t }\n\t\t\t\t\t lazy[node] = 0L; // Reset it\n\t\t\t\t\t }\n\t\t\t\t\t if(start >= l && end <= r) // Current segment is totally within range [l, r]\n\t\t\t\t\t return st[node];\n\t\t\t\t\t int mid = (start + end) / 2;\n\t\t\t\t\t long p1 = queryRange(node*2, start, mid, l, r); // Query left child\n\t\t\t\t\t long p2 = queryRange(node*2 + 1, mid + 1, end, l, r); // Query right child\n\t\t\t\t\t return (p1 + p2);\n\t\t\t\t\t}*/\n\t\t\t\t\tvoid print() {\n\t\t\t\t\t\tfor (int i = 0; i < st.length; i++) {\n\t\t\t\t\t\t\t//System.out.print(st[i].u+\" \"+st[i].v+\" \"+st[i].z+\"\\n\");\n\t\t\t\t\t\t}\n\t\t\t\t\t\tSystem.out.println();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tstatic class Tree {\n\t\t\t\t\tArrayList<Integer>[] g ;\n\t\t\t\t\tint T[]; // parent\n\t\t\t\t\tint L[]; // level\n\t\t\t\t\tint P[][]; // P[i][j] = 2^j th parent of i\n \n\t\t\t\t\tpublic Tree(int n) {\n\t\t\t\t\t\tT = new int[n];\n\t\t\t\t\t\tL = new int[n];\n\t\t\t\t\t\tP = new int[n][log2(n) + 1];\n\t\t\t\t\t\tg = (ArrayList<Integer>[])new ArrayList[n];\n\t\t\t\t\t\tL[0] = 0;\n\t\t\t\t\t\tT[0] = -1;\n\t\t\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\t\t\tg[i] = new ArrayList<>();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfor (int i = 0; i < n ; i++) {\n\t\t\t\t\t\t\tint a = sc.nextInt();\n\t\t\t\t\t\t\tfor(int j = 0; j<a; j++){\n\t\t\t\t\t\t\t\tint b = sc.nextInt()-1;\n\t\t\t\t\t\t\t\tg[i].add(b);\n\t\t\t\t\t\t\t\tg[b].add(i);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdfs(0, -1);\n\t\t\t\t\t\tfor (int j = 0; (1 << j) <= n; j++)\n\t\t\t\t\t\t\tpre(0, j,-1);\n\t\t\t\t\t}\n \n\t\t\t\t\tpublic int log2(int n) {\n\t\t\t\t\t\treturn (int) (Math.log10(n) / Math.log10(2));\n\t\t\t\t\t}\n \n\t\t\t\t\tpublic void dfs(int node, int p) {\n\t\t\t\t\t\tfor (int k : g[node]) {\n\t\t\t\t\t\t\tif (k != p) {\n\t\t\t\t\t\t\t\tT[k] = node;\n\t\t\t\t\t\t\t\tL[k] = L[node] + 1;\n\t\t\t\t\t\t\t\tdfs(k, node);\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\tpublic void pre(int node, int j,int p) {\n\t\t\t\t\t\tif (j == 0) {\n\t\t\t\t\t\t\tP[node][j] = T[node];\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tP[node][j] = P[P[node][j - 1]][j - 1];\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfor (int k : g[node]) {\n\t\t\t\t\t\t\tif(k!=p)\n\t\t\t\t\t\t\t\tpre(k, j,node);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tpublic int lca(int u, int v) {\n\t\t\t\t\t\tif (L[u] > L[v]) {\n\t\t\t\t\t\t\tint temp = u;\n\t\t\t\t\t\t\tu = v;\n\t\t\t\t\t\t\tv = temp;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tint log;\n\t\t\t\t\t\tfor (log = 0; (1 << log) <= L[v]; log++)\n\t\t\t\t\t\t\t; // convert level into log\n\t\t\t\t\t\tlog--;\n \n\t\t\t\t\t\tfor (int i = log; i >= 0; i--) {\n\t\t\t\t\t\t\tif ((1 << i) <= L[v] - L[u]) // make both node's level same\n\t\t\t\t\t\t\t\tv = P[v][i];\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (u == v)\n\t\t\t\t\t\t\treturn u;\n\t\t\t\t\t\tfor (int i = log; i >= 0; i--) {\n\t\t\t\t\t\t\tif (P[u][i] != -1 && P[u][i] != P[v][i]) // shift up both u and v\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tu = P[u][i];\n\t\t\t\t\t\t\t\tv = P[v][i];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn T[u];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tpublic static long max(long x, long y, long z){\n\t\t\t\t\tif(x>=y && x>=z) return x;\n\t\t\t\t\tif(y>=x && y>=z) return y;\n\t\t\t\t\treturn z;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tpublic static void seive(long n){\n\t\t\t\t\tb = new boolean[(int) (n+1)];\n\t\t\t\t\tArrays.fill(b, true);\n\t\t\t\t\tfor(int i = 2;i*i<=n;i++){\n\t\t\t\t\t\tif(b[i]){\n\t\t\t\t\t\t\tfor(int p = 2*i;p<=n;p+=i){\n\t\t\t\t\t\t\t\tb[p] = false;\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\tstatic long modInverse(long a, long mOD2){\n\t\t\t\t return power(a, mOD2-2, mOD2);\n\t\t\t\t}\n\t\t\t\tstatic long power(long x, long y, long m)\n\t\t\t\t{\n\t\t\t\t if (y == 0)\n\t\t\t\t return 1;\n\t\t\t\t long p = power(x, y/2, m) % m;\n\t\t\t\t p = (p * p) % m;\n\t\t\t\t \n\t\t\t\t return (y%2 == 0)? p : (x * p) % m;\n\t\t\t\t}\n\t\t\t\tstatic long d,x,y;\n\t\t\t\tpublic static void extendedEuclidian(long a, long b){\n\t\t\t\t\tif(b == 0) {\n\t\t\t\t d = a;\n\t\t\t\t x = 1;\n\t\t\t\t y = 0;\n\t\t\t\t }\n\t\t\t\t else {\n\t\t\t\t extendedEuclidian(b, a%b);\n\t\t\t\t int temp = (int) x;\n\t\t\t\t x = y;\n\t\t\t\t y = temp - (a/b)*y;\n\t\t\t\t }\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t\n\t\t\t\tstatic class FasterScanner {\n \n\t\t\t\t\tprivate final InputStream stream;\n\t\t\t\t\tprivate final byte[] buf = new byte[8192];\n\t\t\t\t\tprivate int curChar, snumChars;\n\t\t\t\t\tprivate SpaceCharFilter filter;\n\t\t\t\t\tpublic int read() {\n\t\t\t\t\t\tif (snumChars == -1)\n\t\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\t\tif (curChar >= snumChars) {\n\t\t\t\t\t\t\tcurChar = 0;\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tsnumChars = System.in.read(buf);\n\t\t\t\t\t\t\t} catch (IOException e) {\n\t\t\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (snumChars <= 0)\n\t\t\t\t\t\t\t\treturn -1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn buf[curChar++];\n\t\t\t\t\t}\n\t\t\t\t\tpublic FasterScanner(InputStream stream) {\n\t\t\t\t\t\tthis.stream = stream;\n\t\t\t\t\t}\n\t\t\t\t\tpublic String nextString() {\n\t\t\t\t\t\tint c = read();\n\t\t\t\t\t\twhile (isSpaceChar(c))\n\t\t\t\t\t\t\tc = read();\n\t\t\t\t\t\tStringBuilder res = new StringBuilder();\n\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\tres.appendCodePoint(c);\n\t\t\t\t\t\t\tc = read();\n\t\t\t\t\t\t} while (!isSpaceChar(c));\n\t\t\t\t\t\treturn res.toString();\n\t\t\t\t\t}\n\t\t\t\t\tpublic int snext() {\n\t\t\t\t\t\tif (snumChars == -1)\n\t\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\t\tif (curChar >= snumChars) {\n\t\t\t\t\t\t\tcurChar = 0;\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tsnumChars = stream.read(buf);\n\t\t\t\t\t\t\t} catch (IOException e) {\n\t\t\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (snumChars <= 0)\n\t\t\t\t\t\t\t\treturn -1;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn buf[curChar++];\n\t\t\t\t\t}\n \n\t\t\t\t\tpublic int nextInt() {\n\t\t\t\t\t\tint c = snext();\n\t\t\t\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\t\t\t\tc = snext();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tint sgn = 1;\n\t\t\t\t\t\tif (c == '-') {\n\t\t\t\t\t\t\tsgn = -1;\n\t\t\t\t\t\t\tc = snext();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tint res = 0;\n\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\t\t\tres *= 10;\n\t\t\t\t\t\t\tres += c - '0';\n\t\t\t\t\t\t\tc = snext();\n\t\t\t\t\t\t} while (!isSpaceChar(c));\n\t\t\t\t\t\treturn res * sgn;\n\t\t\t\t\t}\n \n\t\t\t\t\tpublic long nextLong() {\n\t\t\t\t\t\tint c = snext();\n\t\t\t\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\t\t\t\tc = snext();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tint sgn = 1;\n\t\t\t\t\t\tif (c == '-') {\n\t\t\t\t\t\t\tsgn = -1;\n\t\t\t\t\t\t\tc = snext();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlong res = 0;\n\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\tif (c < '0' || c > '9')\n\t\t\t\t\t\t\t\tthrow new InputMismatchException();\n\t\t\t\t\t\t\tres *= 10;\n\t\t\t\t\t\t\tres += c - '0';\n\t\t\t\t\t\t\tc = snext();\n\t\t\t\t\t\t} while (!isSpaceChar(c));\n\t\t\t\t\t\treturn res * sgn;\n\t\t\t\t\t}\n \n\t\t\t\t\tpublic int[] nextIntArray(int n) {\n\t\t\t\t\t\tint a[] = new int[n];\n\t\t\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\t\t\ta[i] = nextInt();\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn a;\n\t\t\t\t\t}\n \n\t\t\t\t\tpublic long[] nextLongArray(int n) {\n\t\t\t\t\t\tlong a[] = new long[n];\n\t\t\t\t\t\tfor (int i = 0; i < n; i++) {\n\t\t\t\t\t\t\ta[i] = nextInt();\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn a;\n\t\t\t\t\t}\n\t\t\t \n\t\t\t\t\tpublic String readString() {\n\t\t\t\t\t\tint c = snext();\n\t\t\t\t\t\twhile (isSpaceChar(c)) {\n\t\t\t\t\t\t\tc = snext();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tStringBuilder res = new StringBuilder();\n\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\tres.appendCodePoint(c);\n\t\t\t\t\t\t\tc = snext();\n\t\t\t\t\t\t} while (!isSpaceChar(c));\n\t\t\t\t\t\treturn res.toString();\n\t\t\t\t\t}\n \n\t\t\t\t\tpublic String nextLine() {\n\t\t\t\t\t\tint c = snext();\n\t\t\t\t\t\twhile (isSpaceChar(c))\n\t\t\t\t\t\t\tc = snext();\n\t\t\t\t\t\tStringBuilder res = new StringBuilder();\n\t\t\t\t\t\tdo {\n\t\t\t\t\t\t\tres.appendCodePoint(c);\n\t\t\t\t\t\t\tc = snext();\n\t\t\t\t\t\t} while (!isEndOfLine(c));\n\t\t\t\t\t\treturn res.toString();\n\t\t\t\t\t}\n \n\t\t\t\t\tpublic boolean isSpaceChar(int c) {\n\t\t\t\t\t\tif (filter != null)\n\t\t\t\t\t\t\treturn filter.isSpaceChar(c);\n\t\t\t\t\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == -1;\n\t\t\t\t\t}\n \n\t\t\t\t\tprivate boolean isEndOfLine(int c) {\n\t\t\t\t\t\treturn c == '\\n' || c == '\\r' || c == -1;\n\t\t\t\t\t}\n \n\t\t\t\t\tpublic interface SpaceCharFilter {\n\t\t\t\t\t\tpublic boolean isSpaceChar(int ch);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} ", "src_uid": "14b69f42bc192ea472e82f3a3209f1c1"} {"source_code": "\nimport java.util.Scanner;\n\npublic class A {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in).useDelimiter(\"(:|\\\\s)+\");\n scanner.nextInt();\n int ta = scanner.nextInt();\n int b = scanner.nextInt();\n int tb = scanner.nextInt();\n\n int hh = scanner.nextInt();\n int mm = scanner.nextInt();\n\n int sa = hh*60 + mm;\n int ea = sa + ta;\n\n int res = 0;\n for (int sb=5*60; sb <= 23*60 + 59; sb+= b) {\n int eb = sb + tb;\n\n if (eb > sa && ea > sb) res++;\n }\n System.out.print(res);\n\n }\n}\n", "src_uid": "1c4cf1c3cb464a483511a8a61f8685a7"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.StringTokenizer;\n\npublic class B354 {\n\tpublic static void main(String [] args) throws IOException{\n\t\tdouble[][] g;\n\t\tint h;\n\t\tBufferedReader bf = new BufferedReader(new InputStreamReader(System.in));\n\t\tStringTokenizer st = new StringTokenizer(bf.readLine());\n\t\th = Integer.parseInt(st.nextToken());\n\t\tint sec = Integer.parseInt(st.nextToken());\n//\t\tint totCups = cups*(cups+1)/2;\n\t\tg = new double[12][12];\n\t\tg[1][1]=sec;\n\t\tint glasses=0;\n\t\tfor(int i =1;i<=h;i++){\n\t\t\tfor(int j =1;j<=i;j++){\n\t\t\t\tif(g[i][j]>1){\n//\t\t\t\t\tglasses++;\n\t\t\t\t\tg[i+1][j]+=(g[i][j]-1)/2;\n\t\t\t\t\tg[i+1][j+1]+=(g[i][j]-1)/2;\n\t\t\t\t}\n\t\t\t\tif(g[i][j]>=1)\n\t\t\t\t\tglasses++;\n\t\t\t}\n\t\t}\n\t\t\n\t\tSystem.out.println(glasses);\n\t\n\t}\n\t\n}\n", "src_uid": "b2b49b7f6e3279d435766085958fb69d"} {"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\t\n\tpublic static void main(String[] args) {\n\t\tint n=in.nextInt(), w=in.nextInt();\n\t\tPair[] ps = new Pair[n];\n\t\tfor(int i=0; i<n; ++i)\n\t\t\tps[i] = new Pair(in.nextInt(), in.nextInt());\n//\t\tList<Pair> p1 = new ArrayList<Pair>(), p2 = new ArrayList<Pair>();\n//\t\tfor(int i=0; i<n; ++i) {\n//\t\t\tPair p=new Pair(in.nextInt(), in.nextInt());\n//\t\t\tif(p.a<0)\n//\t\t\t\tp1.add(p);\n//\t\t\telse\n//\t\t\t\tp2.add(p);\n//\t\t}\n//\t\tint m=p2.size();\n\t\tPair[] x = new Pair[n], y = new Pair[n];\n\t\tfor(int i=0; i<n; ++i) {\n//\t\t\tx[i] = new Pair(p2.get(i).a, -(p2.get(i).b-w));\n//\t\t\ty[i] = new Pair(p2.get(i).a, -(p2.get(i).b+w));\n\t\t\tx[i] = new Pair(Math.abs(ps[i].a), Math.abs(ps[i].b-w));\n\t\t\ty[i] = new Pair(Math.abs(ps[i].a), Math.abs(ps[i].b+w));\n\t\t}\n\t\tArrays.sort(x);\n\t\tArrays.sort(y);\n\t\tList<Integer>[] toAdd = new List[n];\n\t\tfor(int i=0; i<n; ++i)\n\t\t\ttoAdd[i] = new ArrayList<Integer>();\n\t\tfor(int i=0; i<n; ++i)\n\t\t\ttoAdd[Arrays.binarySearch(y, new Pair(Math.abs(ps[i].a), Math.abs(ps[i].b+w)))]\n\t\t\t\t\t.add(Arrays.binarySearch(x, new Pair(Math.abs(ps[i].a), Math.abs(ps[i].b-w))));\n\t\tlong ans=0;\n\t\tFenTree ft = new FenTree(n);\n\t\tfor(int i=n-1; i>=0; --i) {\n\t\t\tCollections.sort(toAdd[i]);\n\t\t\tfor(int ta : toAdd[i]) {\n\t\t\t\tans+=ft.qry(ta+1);\n\t\t\t\tft.upd(ta, 1);\n\t\t\t}\n\t\t}\n\t\tout.println(ans);\n\t\tout.close();\n\t}\n\t\n\tstatic class FenTree {\n\t\tint[] a;\n\t\tFenTree(int n) {\n\t\t\ta = new int[n+1];\n\t\t}\n\t\tvoid upd(int i, int x) {\n\t\t\tfor(++i; i<a.length; i+=i&-i)\n\t\t\t\ta[i]+=x;\n\t\t}\n\t\tint qry(int i) {\n\t\t\tint r=0;\n\t\t\tfor(; i>0; i-=i&-i)\n\t\t\t\tr+=a[i];\n\t\t\treturn r;\n\t\t}\n\t}\n\t\n\tstatic class Pair implements Comparable<Pair> {\n\t\tint a, b;\n\t\tPair(int a, int b) {\n\t\t\tthis.a=a;\n\t\t\tthis.b=b;\n\t\t}\n\t\tpublic int compareTo(Pair o) {\n\t\t\treturn Double.compare((double)a/b, (double)o.a/o.b);\n\t\t}\n\t}\n\t\n\tstatic class StdIn {\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, int os) {\n\t\t\tint[] ar = new int[n];\n\t\t\tfor(int i=0; i<n; ++i)\n\t\t\t\tar[i]=nextInt()+os;\n\t\t\treturn ar;\n\t\t}\n\t\tpublic long nextLong() {\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\twhile ((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\t\tpublic long[] readLongArray(int n, long os) {\n\t\t\tlong[] ar = new long[n];\n\t\t\tfor(int i=0; i<n; ++i)\n\t\t\t\tar[i]=nextLong()+os;\n\t\t\treturn ar;\n\t\t}\n\t\tpublic double nextDouble() {\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\twhile ((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\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}", "src_uid": "d073d41f7e184e9bc4a12219d86e7184"} {"source_code": "import java.util.Scanner;\n\npublic class FleaTravel {\n public static void main(String[] args) {\n int n;\n Scanner cin = new Scanner(System.in);\n n = cin.nextInt();\n boolean h[] = new boolean[n];\n for (int i = 0; i < n; i++) {\n h[i] = false;\n }\n int x = 0;\n h[x] = true;\n for (int k = 0; k < n; k++) {\n x += k;\n if (x >= n) {\n x -= n;\n }\n h[x] = true;\n }\n for (int i = 0; i < n; i++) {\n if (h[i] == false) {\n System.out.println(\"NO\");\n System.exit(0);\n }\n }\n System.out.println(\"YES\");\n }\n}", "src_uid": "4bd174a997707ed3a368bd0f2424590f"} {"source_code": "import java.io.BufferedReader;\nimport java.io.Closeable;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.StringTokenizer;\n\npublic class CuttingBanner implements Closeable {\n\n private InputReader in = new InputReader(System.in);\n private PrintWriter out = new PrintWriter(System.out);\n\n public void solve() {\n char[] codeforces = \"CODEFORCES\".toCharArray();\n char[] word = in.next().toCharArray();\n int idx = 0, i = 0, j = 0, n = word.length;\n while (idx < Math.min(10, n)) {\n if (word[idx] == codeforces[j]) {\n j++;\n } else break;\n idx++;\n }\n idx = 0;\n while (idx < Math.min(10, n)) {\n if (word[word.length - idx - 1] == codeforces[9 - i]) {\n i++;\n } else break;\n idx++;\n }\n \n out.println((i + j >= 10) ? \"YES\" : \"NO\");\n }\n\n @Override\n public void close() throws IOException {\n in.close();\n out.close();\n }\n\n static class InputReader {\n public BufferedReader reader;\n public StringTokenizer tokenizer;\n\n public InputReader(InputStream stream) {\n reader = new BufferedReader(new InputStreamReader(stream), 32768);\n tokenizer = null;\n }\n\n public String next() {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n try {\n tokenizer = new StringTokenizer(reader.readLine());\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n return tokenizer.nextToken();\n }\n\n public int ni() {\n return Integer.parseInt(next());\n }\n\n public long nl() {\n return Long.parseLong(next());\n }\n\n public void close() throws IOException {\n reader.close();\n }\n }\n\n public static void main(String[] args) throws IOException {\n try (CuttingBanner instance = new CuttingBanner()) {\n instance.solve();\n }\n }\n}\n", "src_uid": "bda4b15827c94b526643dfefc4bc36e7"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\n\npublic class NextRound {\n\n\n public static void main(String[] args) throws IOException {\n BufferedReader br=new BufferedReader(new InputStreamReader(System.in));\n String []w=br.readLine().trim().split(\"\\\\s+\");\n int n=Integer.parseInt(w[0]);\n int k=Integer.parseInt(w[1])-1;\n String []ww=br.readLine().trim().split(\"\\\\s+\");\n int c=0;\n for (int i = 0; i < ww.length; i++) {\n if(Integer.parseInt(ww[i])>=Integer.parseInt(ww[k]) && Integer.parseInt(ww[i])>0 ){\n c++;\n }\n \n }\n System.out.print(c);\n \n }\n\n}\n", "src_uid": "193ec1226ffe07522caf63e84a7d007f"} {"source_code": "\nimport java.io.BufferedOutputStream;\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.util.*;\n\n\n \npublic class ATM\n{ \n\t static class FastReader \n\t { \n\t BufferedReader br; \n\t StringTokenizer st; \n\t \n\t public FastReader() \n\t { \n\t br = new BufferedReader(new\n\t InputStreamReader(System.in)); \n\t } \n\t \n\t String next() \n\t { \n\t while (st == null || !st.hasMoreElements()) \n\t { \n\t try\n\t { \n\t st = new StringTokenizer(br.readLine()); \n\t } \n\t catch (IOException e) \n\t { \n\t e.printStackTrace(); \n\t } \n\t } \n\t return st.nextToken(); \n\t } \n\t \n\t int nextInt() \n\t { \n\t return Integer.parseInt(next()); \n\t } \n\t \n\t long nextLong() \n\t { \n\t return Long.parseLong(next()); \n\t } \n\t \n\t double nextDouble() \n\t { \n\t return Double.parseDouble(next()); \n\t } \n\t \n\t String nextLine() \n\t { \n\t String str = \"\"; \n\t try\n\t { \n\t str = br.readLine(); \n\t } \n\t catch (IOException e) \n\t { \n\t e.printStackTrace(); \n\t } \n\t return str; \n\t } \n\t } \n\t public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));\n\t \n static int MAX = (int) 1e6;\n public static void main(String[] args) { \n \t\n \tFastReader sc = new FastReader();\n \tint a1 = sc.nextInt();\n \tint a2 = sc.nextInt();\n \tint k1 = sc.nextInt();\n \tint k2 = sc.nextInt();\n \tint n = sc.nextInt();\n \tint min1 = Math.max(0,n-(k1-1)*a1 - (k2-1)*a2);\n \tint min = Math.min(a1+a2,min1);\n \tint max1 = 0;\n \tif(k1 < k2) {\n \t max1+=Math.min(n/k1,a1);\n \t n-=k1*max1;\n \t if(n > 0) {\n \t\t max1+=Math.min(n/k2, a2);\n \t }\n \t}else if(k2 < k1) {\n \t\tmax1+=Math.min(n/k2, a2);\n \t\tn-=k2*max1;\n \t\tif(n > 0) {\n \t\t\tmax1+=Math.min(n/k1, a1);\n \t\t}\n \t}else {\n \t\tmax1+=Math.min(n/k1, a1+a2);\n \t}\n \tout.print(min+\" \"+max1);\n \tout.close();\n \t}\n}", "src_uid": "2be8e0b8ad4d3de2930576c0209e8b91"} {"source_code": "import java.io.*;\nimport java.util.*;\n\npublic class Main {\n static long derangement[];\n static void build(int k) {\n derangement[0] = 1;\n derangement[1] = 0;\n for (int i = 2; i <= k; i++) derangement[i] = (i - 1) * (derangement[i - 1] + derangement[i - 2]);\n }\n static long combination(int n, int k) {\n switch (k) {\n case 0 : return 1;\n case 1: return n;\n case 2: return (long) n * (n - 1) / 2;\n case 3: return (long) n * (n - 1) * (n - 2) / 6;\n case 4: return (long) n * (n - 1) * (n - 2) * (n - 3) / 24;\n default: return -1;\n }\n }\n static void solve() throws IOException {\n rl(); int n = ni2(); int k = ni2();\n derangement = new long[k + 1];\n long res = 0;\n build(k);\n for (int i = 0; i <= k; i++) res += derangement[i] * combination(n, i);\n ans.append(res).append('\\n');\n output.write(ans.toString());\n output.flush();\n output.close();\n }\n\n public static void main(String[] args) throws IOException {\n new Main().solve();\n }\n\n static BufferedReader input = new BufferedReader(new InputStreamReader(System.in));\n static BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out));\n static StringBuilder ans = new StringBuilder();\n static String line;\n static StringTokenizer stringTokenizer;\n\n static int ni1() throws IOException {\n return Integer.parseInt(input.readLine());\n }\n\n static int ni2() throws IOException {\n return Integer.parseInt(stringTokenizer.nextToken());\n }\n\n static long nl1() throws IOException {\n return Long.parseLong(input.readLine());\n }\n\n static long nl2() {\n return Long.parseLong(stringTokenizer.nextToken());\n }\n\n static void rl() throws IOException {\n stringTokenizer = new StringTokenizer(input.readLine());\n }\n}\n", "src_uid": "96d839dc2d038f8ae95fc47c217b2e2f"} {"source_code": "import java.io.*;\nimport java.util.*;\npublic class code {\n\tstatic printer pw;\n\tstatic boolean[] visit;\n\tstatic ArrayList<Pair>[] adj;\n\tstatic ArrayList<Integer> list;\n\tstatic long max=01;\n\tstatic void dfs(int i, long c) {\n\t\tvisit[i]=true;\n\t\tmax=Math.max(c, max);\n\t\tfor(Pair p: adj[i]) {\n\t\t\tif(!visit[p.x-1]) {\n\t\t\t\tdfs(p.x-1, c+1l*p.y);\n\t\t\t}\n\t\t}\n\t}\n\tstatic long Pow(long a, int e, int mod)\n\t{\n\t\ta %= mod;\n\t\tlong res = 1;\n\t\twhile (e > 0) {\n\t\t\tif ((e & 1) == 1)\n\t\t\t\tres = (res * a) % mod;\n\t\t\ta = (a * a) % mod;\n\t\t\te >>= 1;\n\t\t}\n\t\treturn res;\n\t}\n\tpublic static double dist(Pair a, Pair b) {\n\t\treturn Math.sqrt((a.x-b.x)*(a.x-b.x)+ (a.y-b.y)*(a.y-b.y));\n\t}\n\tpublic static boolean sign(int x) {\n\t\treturn x>0;\n\t}\n\tstatic int test(int[] arr, int mid) {\n\t\tint ans=0;\n\t\tfor(int i=1; i<arr.length; i++) {\n\t\t\tif(arr[i]==-1 && arr[i-1]!=-1) {\n\t\t\t\tif(Math.abs(mid-arr[i-1])>Math.abs(ans))\n\t\t\t\t\tans=mid-arr[i-1];\n\t\t\t}\n\t\t\tif(arr[i]!=-1 && arr[i-1]==-1) {\n\t\t\t\tif(Math.abs(mid-arr[i])>Math.abs(ans))\n\t\t\t\t\tans=mid-arr[i];\n\t\t\t}\n\t\t}\n\t\treturn ans;\n\t}\n\tpublic static void main(String[] args) throws Exception {\n\t\tScanner sc= new Scanner(System.in);\n\t\tpw = new printer();\n\t\tint w1=sc.nextInt(),h1=sc.nextInt(),w2=sc.nextInt(),h2=sc.nextInt();\n\t\tlong ans=1l*(w1-w2!=0?1:0)*h2+1l*(h1+h2+2)+1l*(w1==w2?h1+h2+2:h1+2)+2*1l*(w1);\n\t\tpw.println(ans);\n\t\tpw.close();\n\t}\n\tstatic class Scanner {\n\t\tStringTokenizer st;\n\t\tBufferedReader br;\n \n\t\tpublic Scanner(InputStream s) {\n\t\t\tbr = new BufferedReader(new InputStreamReader(s));\n\t\t}\n \n\t\tpublic Scanner(FileReader r) {\n\t\t\tbr = new BufferedReader(r);\n\t\t}\n \n\t\tpublic String next() throws IOException {\n\t\t\twhile (st == null || !st.hasMoreTokens())\n\t\t\t\tst = new StringTokenizer(br.readLine());\n\t\t\treturn st.nextToken();\n\t\t}\n \n\t\tpublic int nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n \n\t\tpublic long nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n \n\t\tpublic String nextLine() throws IOException {\n\t\t\treturn br.readLine();\n\t\t}\n \n\t\tpublic double nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n \n\t\tpublic int[] nextArr(int n) throws IOException {\n\t\t\tint[] arr = new int[n];\n\t\t\tfor (int i = 0; i < arr.length; i++)\n\t\t\t\tarr[i] = nextInt();\n\t\t\treturn arr;\n\t\t}\n\t\tpublic Integer[] nextsort(int n) throws IOException{\n\t\t\tInteger[] arr=new Integer[n];\n\t\t\tfor(int i=0; i<n; i++) \n\t\t\t\tarr[i]=nextInt();\n\t\t\treturn arr;\n\t\t}\n\t\tpublic boolean ready() throws IOException {\n\t\t\treturn br.ready();\n\t\t}\n\t}\n\tstatic class printer{\n\t\tPrintWriter pw;\n\t\tpublic printer() {\n\t\t\tpw=new PrintWriter(System.out);\n\t\t}\n\t\tpublic void print(String s) throws IOException{\n\t\t\tpw.print(s);\n\t\t}\n\t\tpublic void print(int s) throws IOException{\n\t\t\tpw.print(s);\n\t\t}\n\t\tpublic void print(long s) throws IOException{\n\t\t\tpw.print(s);\n\t\t}\n\t\tpublic void print(char s) throws IOException{\n\t\t\tpw.print(s);\n\t\t}\n\t\tpublic void print(Integer s) throws IOException{\n\t\t\tpw.print(s);\n\t\t}\n\t\tpublic void print(Long s) throws IOException{\n\t\t\tpw.print(s);\n\t\t}\n\t\tpublic void print(Character s) throws IOException{\n\t\t\tpw.print(s);\n\t\t}\n\t\tpublic void println(String s) throws IOException{\n\t\t\tpw.println(s);\n\t\t}\n\t\tpublic void println(int s) throws IOException{\n\t\t\tpw.println(s);\n\t\t}\n\t\tpublic void println(long s) throws IOException{\n\t\t\tpw.println(s);\n\t\t}\n\t\tpublic void println(char s) throws IOException{\n\t\t\tpw.println(s);\n\t\t}\n\t\tpublic void println(Integer s) throws IOException{\n\t\t\tpw.println(s);\n\t\t}\n\t\tpublic void println(Long s) throws IOException{\n\t\t\tpw.println(s);\n\t\t}\n\t\tpublic void println(Character s) throws IOException{\n\t\t\tpw.println(s);\n\t\t}\n\t\tpublic void println(int[] arr) throws IOException{\n\t\t\tfor(int i=0; i<arr.length-1; i++)\n\t\t\t\tpw.print(arr[i]+\" \");\n\t\t\tpw.println(arr[arr.length-1]);\n\t\t}\n\t\tpublic void println(Integer[] arr) throws IOException{\n\t\t\tfor(int i=0; i<arr.length-1; i++)\n\t\t\t\tpw.print(arr[i]+\" \");\n\t\t\tpw.println(arr[arr.length-1]);\n\t\t}\n\t\tpublic void println(long[] arr) throws IOException{\n\t\t\tfor(int i=0; i<arr.length-1; i++)\n\t\t\t\tpw.print(arr[i]+\" \");\n\t\t\tpw.println(arr[arr.length-1]);\n\t\t}\n\t\tpublic void println(Long[] arr) throws IOException{\n\t\t\tfor(int i=0; i<arr.length-1; i++)\n\t\t\t\tpw.print(arr[i]+\" \");\n\t\t\tpw.println(arr[arr.length-1]);\n\t\t}\n\t\tpublic void println(char[] arr) throws IOException{\n\t\t\tfor(int i=0; i<arr.length-1; i++)\n\t\t\t\tpw.print(arr[i]+\" \");\n\t\t\tpw.println(arr[arr.length-1]);\n\t\t}\n\t\tpublic void println(Character[] arr) throws IOException{\n\t\t\tfor(int i=0; i<arr.length-1; i++)\n\t\t\t\tpw.print(arr[i]+\" \");\n\t\t\tpw.println(arr[arr.length-1]);\n\t\t}\n\t\tpublic void println(ArrayList<Integer> arr) throws IOException{\n\t\t\tfor(int i=0; i<arr.size()-1; i++)\n\t\t\t\tpw.print(arr.get(i)+\" \");\n\t\t\tpw.println(arr.get(arr.size()-1));\n\t\t}\n\t\tpublic void println(TreeSet<Integer> arr) throws IOException{\n\t\t\tfor(int x: arr) {\n\t\t\t\tpw.print(x+\" \");\n\t\t\t}\n\t\t}\n\t\tpublic void close() throws IOException{\n\t\t\tpw.close();\n\t\t}\n\t\tpublic void flush() throws IOException{\n\t\t\tpw.flush();\n\t\t}\n\t}\n\tstatic class Pair implements Comparable<Pair>{\n\t\tint x;\n\t\tint y;\n\t\tpublic Pair(int a, int b) {\n\t\t\tthis.x=a;\n\t\t\tthis.y=b;\n\t\t}\n\t\tpublic int compareTo(Pair other) {\n\t\t\treturn -1*(this.y-other.y);\n\t\t}\n\t}\n\tstatic class Triple implements Comparable<Triple>{\n\t\tint x;\n\t\tint y;\n\t\tboolean d;\n\t\tpublic Triple(int a, int b, boolean t) {\n\t\t\tthis.x=a;\n\t\t\tthis.y=b;\n\t\t\tthis.d=t;\n\t\t}\n\t\tpublic int compareTo(Triple other) {\n\t\t\tif(this.d && !other.d) {\n\t\t\t\treturn 1;\n\t\t\t}else if(!this.d && other.d) {\n\t\t\t\treturn -1;\n\t\t\t}else {\n\t\t\t\treturn this.y-other.y;\n\t\t\t}\n\t\t}\n\t}\n}", "src_uid": "b5d44e0041053c996938aadd1b3865f6"} {"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 BSRK Aditya\n */\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tInputStream inputStream = System.in;\n\t\tOutputStream outputStream = System.out;\n\t\tScanner in = new Scanner(inputStream);\n\t\tPrintWriter out = new PrintWriter(outputStream);\n\t\tTaskA solver = new TaskA();\n\t\tsolver.solve(1, in, out);\n\t\tout.close();\n\t}\n}\n\nclass TaskA {\n public void solve(int testNumber, Scanner in, PrintWriter out) {\n long n = in.nextLong(), p3 = 3;\n for(; n%p3 == 0; p3 *= 3);\n out.println(n/p3 + 1);\n }\n}\n\n", "src_uid": "7e7b59f2112fd200ee03255c0c230ebd"} {"source_code": "/*package whatever //do not write package name here */\n\nimport java.io.*;\n import java.util.*;\n\npublic class solution {\n\tpublic static void main (String[] args) {\n\t Scanner sc = new Scanner(System.in);\n\t int n = sc.nextInt();\n\t int m = sc.nextInt();\n\t int [] a = new int[m];\n\t int diff = 1000;\n\t for(int i=0;i<m;i++)\n\t {\n\t a[i] = sc.nextInt(); \n\t }\n\t Arrays.sort(a);\n\t \n\t for(int i=0;i<=(m-n);i++)\n\t {\n\t if(a[i+n-1]-a[i]<=diff)\n\t {\n\t diff = a[i+n-1]-a[i];\n\t }\n\t }\n\t \n\t System.out.print(diff);\n\t }\n\t} ", "src_uid": "7830aabb0663e645d54004063746e47f"} {"source_code": "\nimport java.io.BufferedReader;\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.FileReader;\nimport java.io.InputStreamReader;\nimport java.io.PrintWriter;\nimport java.math.BigInteger;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Comparator;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.LinkedList;\nimport java.util.PriorityQueue;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\nimport java.util.TreeSet;\n\n/**\n * 4 4\n * 1 5 3 4\n * 1 2\n * 1 3\n * 2 3\n * 3 3\n *\n *\n * @author pttrung\n */\npublic class A {\n\n public static long Mod = (long) (1e9) + 7;\n static int time = 1;\n static long[] dp;\n\n public static void main(String[] args) throws FileNotFoundException {\n PrintWriter out = new PrintWriter(System.out);\n Scanner in = new Scanner();\n long n = in.nextLong();\n long x = in.nextLong() - 1;\n long y = in.nextLong() - 1;\n long c = in.nextLong();\n long start = 0;\n long end = 2*n;\n long result = end;\n while (start <= end) {\n long mid = (start + end) / 2;\n long total = cal(x,y,mid,n);\n if (total < c) {\n start = mid + 1;\n } else if (total >= c) {\n result = Math.min(result, mid);\n end = mid - 1;\n }\n }\n out.println(result);\n out.close();\n }\n \n\n static long cal(long x, long y , long l, long n){\n long minX = min(x - l);\n long maxX = max(x + l, n);\n long minY = min(y - l);\n long maxY = max(y + l, n);\n long total = 0;\n if(maxX != x + l){\n long c = x + l - maxX;\n long left = l - (maxY - y);\n if(left + x > maxX){\n long a = x + left - maxX;\n total -= (a + c)*(maxY - y + 1)/2;\n }else{\n total -= c*(c + 1)/2;\n }\n }\n if(minX != x - l){\n long c = minX - (x - l);\n long left = l - (maxY - y);\n if(x - left < minX){\n long a = minX - (x - left);\n total -= (a + c)*(maxY - y + 1)/2;\n }else{\n total -= c*(c + 1)/2;\n }\n }\n if(maxY < y + l){\n long c = y + l - maxY;\n long last = 2*c - 1;\n total -= (last + 1)*c/2;\n }\n long last = l*2 + 1;\n total += (last + 1)*(l + 1)/2;\n if(maxX != x + l){\n long c = x + l - maxX;\n long left = l - (y - minY);\n if(left + x > maxX){\n long a = x + left - maxX;\n total -= (a + c)*(y - minY + 1)/2;\n }else{\n total -= c*(c + 1)/2;\n }\n }\n if(minX != x - l){\n long c = minX - (x - l);\n long left = l - (y - minY);\n if(x - left < minX){\n long a = minX - (x - left);\n total -= (a + c)*(y - minY + 1)/2;\n }else{\n total -= c*(c + 1)/2;\n }\n }\n if(minY > y - l){\n long c = minY - (y - l);\n last = 2*c - 1;\n total -= (last + 1)*c/2;\n }\n last = l*2 + 1;\n total += (last + 1)*(l + 1)/2;\n total -= (maxX - minX + 1);\n return total;\n }\n \n static long max(long v, long n){\n if(v < n){\n return v;\n }\n return n - 1;\n }\n static long min(long v){\n if(v > 0){\n return v;\n }\n return 0;\n }\n \n \n\n\n static long squareDist(int x, int y) {\n long X = x;\n long Y = y;\n return X * X + Y * Y;\n }\n\n static int find(int index, int[] u) {\n if (index != u[index]) {\n return u[index] = find(u[index], u);\n }\n return index;\n }\n\n public static long pow(int a, int b, long mod) {\n if (b == 0) {\n return 1;\n }\n if (b == 1) {\n return a;\n }\n long v = pow(a, b / 2, mod);\n if (b % 2 == 0) {\n return (v * v) % mod;\n } else {\n return (((v * v) % mod) * a) % mod;\n }\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 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\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 static long gcd(long a, long b) {\n if (b == 0) {\n return a;\n } else {\n return gcd(b, a % b);\n }\n }\n\n static long pow(long 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\n return val * val % Mod;\n } else {\n return (val * val % Mod) * a % Mod;\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\n /**\n * Cross product ab*ac\n *\n * @param a\n * @param b\n * @param c\n * @return\n */\n static double cross(Point a, Point b, Point c) {\n Point ab = new Point(b.x - a.x, b.y - a.y);\n Point ac = new Point(c.x - a.x, c.y - a.y);\n return cross(ab, ac);\n }\n\n static double cross(Point a, Point b) {\n return a.x * b.y - a.y * b.x;\n }\n\n /**\n * Dot product ab*ac;\n *\n * @param a\n * @param b\n * @param c\n * @return\n */\n static long dot(Point a, Point b, Point c) {\n Point ab = new Point(b.x - a.x, b.y - a.y);\n Point ac = new Point(c.x - a.x, c.y - a.y);\n return dot(ab, ac);\n }\n\n static long dot(Point a, Point b) {\n long total = a.x * b.x;\n total += a.y * b.y;\n return total;\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 long norm(Point a) {\n long result = a.x * a.x;\n result += a.y * a.y;\n return result;\n }\n\n static double dist(Point a, Point b, Point x, boolean isSegment) {\n double dist = cross(a, b, x) / dist(a, b);\n // System.out.println(\"DIST \" + dist);\n\n if (isSegment) {\n Point ab = new Point(b.x - a.x, b.y - a.y);\n\n long dot1 = dot(a, b, x);\n long norm = norm(ab);\n double u = (double) dot1 / norm;\n if (u < 0) {\n return dist(a, x);\n }\n\n if (u > 1) {\n return dist(b, x);\n }\n }\n return Math.abs(dist);\n\n\n\n\n }\n\n static long squareDist(Point a, Point b) {\n long x = a.x - b.x;\n long y = a.y - b.y;\n return x * x + y * y;\n }\n\n 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 \"Point{\" + \"x=\" + x + \", y=\" + y + '}';\n }\n }\n\n static class Scanner {\n\n BufferedReader br;\n StringTokenizer st;\n\n public Scanner() throws FileNotFoundException {\n //System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));\n br = new BufferedReader(new InputStreamReader(System.in));\n //br = new BufferedReader(new FileReader(new File(\"A-large (2).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}\n", "src_uid": "232c5206ee7c1903556c3625e0b0efc6"} {"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 TaskF1 solver = new TaskF1();\n solver.solve(1, in, out);\n out.close();\n }\n\n static class TaskF1 {\n public void solve(int testNumber, InputReader in, PrintWriter out) {\n int n = in.nextInt();\n int m = in.nextInt();\n\n int[] knights = new int[n + 1];\n int[] colors = new int[m + 1];\n\n for (int i = 0; i < n; i++) {\n knights[i] = in.nextInt();\n }\n\n int totalKnightsNeeded = 0;\n for (int i = 1; i <= m; i++) {\n colors[i] = in.nextInt();\n totalKnightsNeeded += colors[i];\n }\n\n for (int i = 0; i <= Math.min(n - 1, (n - totalKnightsNeeded)); i++) {\n int[] c1 = colors.clone();\n boolean canDo = true;\n for (int j = 0; j < totalKnightsNeeded; j++) {\n c1[knights[i + j]]--;\n if (c1[knights[i + j]] < 0) {\n canDo = false;\n break;\n }\n }\n if (canDo) {\n out.println(\"YES\");\n return;\n }\n }\n\n out.println(\"NO\");\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", "src_uid": "59f40d9f35e5fe402112214b42b682b5"} {"source_code": "import java.util.*; \npublic class ProbC { \n \n \n \n public static void main(String[] args) {\n int adj[][] = new int[7][7];\n Scanner sc = new Scanner (System.in);\n int n=sc.nextInt(), m=sc.nextInt(); \n \n if (n == 7) {\n for (int i = 0; i < m; i++) {\n int u, v; \n u = sc.nextInt(); \n v= sc.nextInt(); \n u--; \n v--;\n adj[u][v] = adj[v][u] = 1;\n }\n int d = m;\n for (int u = 0; u < n; u++) {\n for (int v = u + 1; v < n; v++) {\n int c = 0;\n for (int w = 0; w < n; w++) {\n if (adj[u][w] ==1 && adj[v][w]==1) {\n c++;\n }\n }\n d = Math.min(d, c);\n }\n }\n m -= d;\n }\n System.out.println(m); \n \n }\n}", "src_uid": "11e6559cfb71b8f6ca88242094b17a2b"} {"source_code": "import java.io.PrintWriter;\nimport java.util.Scanner;\n\n/**\n * Created by Timur on 15.12.2016.\n */\npublic class _630K {\n public static void main(String args[]) {\n Scanner in = new Scanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n long n = in.nextLong();\n long first = n / 2 + n / 3 + n / 5 + n / 7;\n long second = n / (2 * 3) + n / (2 * 5) + n / (2 * 7) + n / (3 * 5) +n / (3 * 7) +n / (5 * 7);\n long third = n / (2 * 3 * 5) + n / (2 * 3 * 7) + n / (2 * 5 * 7) + n / (3 * 5 * 7);\n long forth = n / (2 * 3 * 5 * 7);\n\n out.print(n - first + second - third + forth);\n out.close();\n }\n}\n", "src_uid": "e392be5411ffccc1df50e65ec1f5c589"} {"source_code": "import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.math.BigInteger;\n\npublic class B {\n\n\tfinal int MOD = 1000000007;\n\tfinal double eps = 1e-12;\n\n\tpublic B () throws IOException {\n\t\tint B = sc.nextInt();\n\t\tint D = sc.nextInt();\n\n\t\tstart();\n\n\t\tint T2 = t2(B,D);\n\t\tif (T2 > 0) {\n\t\t\tprint(\"2-type\");\n\t\t\texit(T2);\n\t\t}\n\t\t\n\t\tif (t3(B,D))\n\t\t\texit(\"3-type\");\n\t\t\n\t\tif (t11(B,D))\n\t\t\texit(\"11-type\");\n\t\t\n\t\tfor (int d1 = 2; d1 <= 50; ++d1)\n\t\t\tfor (int d2 = 2; d2 <= 50; ++d2)\n\t\t\t\t\tif (d1*d2 == D && gcd(d1,d2) == 1) {\n\t\t\t\t\t\tif (t2(B,d1) > 0 && t3(B,d2)) exit(\"6-type\");\n\t\t\t\t\t\tif (t2(B,d1) > 0 && t11(B,d2)) exit(\"6-type\");\n\t\t\t\t\t\tif (t3(B,d1) && t11(B,d2)) exit(\"6-type\");\n\t\t\t\t\t}\n\n\t\tfor (int d1 = 2; d1 <= 25; ++d1)\n\t\t\tfor (int d2 = 2; d2 <= 25; ++d2)\n\t\t\t\tfor (int d3 = 2; d3 <= 25; ++d3)\n\t\t\t\t\tif (d1*d2*d3 == D && gcd(d1,d2) == 1 && gcd(d1*d2,d3) == 1 && t2(B,d1) > 0 && t3(B,d2) && t11(B,d3))\n\t\t\t\t\t\texit(\"6-type\");\n\t\t\n\t\texit(\"7-type\");\n\t}\n\t\n\tint t2(int B, int D) {\n\t\tlong P = B;\n\t\tfor (int i = 0; i < 6; ++i) {\n\t\t\tif (P % D == 0)\n\t\t\t\treturn i+1;\n\t\t\tP = P * B;\n\t\t}\n\t\treturn -1;\n\t}\n\t\n\tboolean t3(int B, int D) {\n\t\treturn B%D == 1;\n\t}\n\t\n\tboolean t11(int B, int D) {\n\t\treturn (B+1)%D == 0;\n\t}\n\n\tint gcd(int x, int y) {\n\t\treturn BigInteger.valueOf(x).gcd(BigInteger.valueOf(y)).intValue();\n\t}\n\t////////////////////////////////////////////////////////////////////////////////////\n\t\n\tstatic MyScanner sc;\n\t\n\tstatic void print (Object... a) {\n\t\tStringBuffer b = new StringBuffer();\n\t\tfor (Object o : a)\n\t\t\tb.append(\" \").append(o);\n\t\tSystem.out.println(b.toString().trim());\n\t}\n\n\tstatic void exit (Object... a) {\n\t\tprint(a);\n\t\tSystem.out.flush();\n\t\texit();\n\t}\n\n\tstatic void exit () {\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 class MyScanner {\n\t\tString next() throws IOException {\n\t\t\tnewLine();\n\t\t\treturn line[index++];\n\t\t}\n\t\t\n\t\tchar [] nextChars() throws IOException {\n\t\t\treturn next().toCharArray();\n\t\t}\n\t\t\n\t\tdouble nextDouble() throws IOException {\n\t\t\treturn Double.parseDouble(next());\n\t\t}\n\t\t\n\t\tint nextInt() throws IOException {\n\t\t\treturn Integer.parseInt(next());\n\t\t}\n\t\t\n\t\tlong nextLong() throws IOException {\n\t\t\treturn Long.parseLong(next());\n\t\t}\n\t\t\n\t\tString nextLine() throws IOException {\n\t\t\tline = null;\n\t\t\treturn r.readLine();\n\t\t}\n\t\t\n\t\tString [] nextStrings() throws IOException {\n\t\t\tline = null;\n\t\t\treturn r.readLine().split(\" \");\n\t\t}\n\t\t\n\t\tint [] nextInts() throws IOException {\n\t\t\tString [] L = nextStrings();\n\t\t\tint [] res = new int [L.length];\n\t\t\tfor (int i = 0; i < L.length; ++i)\n\t\t\t\tres[i] = Integer.parseInt(L[i]);\n\t\t\treturn res;\n\t\t}\n\t\t\n\t\tlong [] nextLongs() throws IOException {\n\t\t\tString [] L = nextStrings();\n\t\t\tlong [] res = new long [L.length];\n\t\t\tfor (int i = 0; i < L.length; ++i)\n\t\t\t\tres[i] = Long.parseLong(L[i]);\n\t\t\treturn res;\n\t\t}\n\n\t\tboolean eol() {\n\t\t\treturn index == line.length;\n\t\t}\n\n\t\t//////////////////////////////////////////////\n\t\t\n\t\tprivate final BufferedReader r;\n\n\t\tMyScanner () throws IOException {\n\t\t\tthis(new BufferedReader(new InputStreamReader(System.in)));\n\t\t}\n\t\t\n\t\tMyScanner(BufferedReader r) throws IOException { \n\t\t\tthis.r = r;\n\t\t}\n\t\t\n\t\tprivate String [] line;\n\t\tprivate int index;\n\n\t\tprivate void newLine() throws IOException {\n\t\t\tif (line == null || eol()) {\n\t\t\t\tline = r.readLine().split(\" \");\n\t\t\t\tindex = 0;\n\t\t\t}\n\t\t}\t\t\n\t}\n\t\n\t////////////////////////////////////////////////////////////////////////////////////\n\t\n\tpublic static void main(String[] args) throws IOException {\n\t\trun();\n\t\texit();\n\t}\n\n\tstatic void start() {\n\t\tt = millis();\n\t}\n\n\tstatic void run () throws IOException {\n\t\tsc = new MyScanner ();\n\t\tnew B();\n\t}\n\n\tstatic long t;\n\t\n\tstatic long millis() {\n\t\treturn System.currentTimeMillis();\n\t}\t\n}\n", "src_uid": "809e1c78b0a5a16f7f2115b046a20bde"} {"source_code": "import java.util.*;\r\npublic class Main{\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 n=sc.nextInt();\r\n if(100%n==0){\r\n int ans=100/n;\r\n System.out.println(ans);\r\n }\r\n else{\r\n int x=n;\r\n int y=100-n;\r\n int gc=gcd(x,y);\r\n int ans=(x/gc)+(y/gc);\r\n System.out.println(ans);\r\n } \r\n }\r\n }\r\n public static int gcd(int a,int b){\r\n if (b == 0)\r\n return a;\r\n return gcd(b, a % b);\r\n }\r\n}", "src_uid": "19a2bcb727510c729efe442a13c2ff7c"} {"source_code": "import java.util.HashMap;\nimport java.util.Scanner;\n\n\npublic class ProblemF {\n\n\tstatic String[] word;\n\t\n\tstatic HashMap<String, Pair> hash;\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\tword = new String[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tword[i] = sc.next();\n\t\t}\n\t\tboolean win = false;\n\t\tPair winpts = null;\n\t\tPair losepts = null;\n\t\thash = new HashMap<String, Pair>();\n\t\tfor (char c = 'a'; c <= 'z'; c++) {\n\t\t\tif (!ok(\"\" + c)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tPair res = play(\"\" + c);\n\t\t\tlong nmy = getScore(\"\" + c) + res.other;\n\t\t\tif (!res.win) {\n\t\t\t\twin = true;\n\t\t\t\tif (winpts == null) {\n\t\t\t\t\twinpts = new Pair(0, 0, true);\n\t\t\t\t\twinpts.my = nmy;\n\t\t\t\t\twinpts.other = res.my;\n\t\t\t\t} else {\n\t\t\t\t\tif (winpts.my < nmy || (winpts.my == nmy && winpts.other > res.my)) {\n\t\t\t\t\t\twinpts.my = nmy;\n\t\t\t\t\t\twinpts.other = res.my;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (losepts == null) {\n\t\t\t\t\tlosepts = new Pair(0, 0, false);\n\t\t\t\t\tlosepts.my = nmy;\n\t\t\t\t\tlosepts.other = res.my;\n\t\t\t\t} else {\n\t\t\t\t\tif (losepts.my < nmy || (losepts.my == nmy && losepts.other > res.my)) {\n\t\t\t\t\t\tlosepts.my = nmy;\n\t\t\t\t\t\tlosepts.other = res.my;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (win) {\n\t\t\tSystem.out.println(\"First\");\n\t\t\tSystem.out.println(winpts.my + \" \" + winpts.other);\n\t\t} else {\n\t\t\tSystem.out.println(\"Second\");\n\t\t\tSystem.out.println(losepts.my + \" \" + losepts.other);\n\t\t}\n\t}\n\t\n\tstatic int count(String w) {\n\t\tint ret = 0;\n\t\tfor (int i = 0; i < word.length; i++) {\n\t\t\tif (word[i].indexOf(w) >= 0) {\n\t\t\t\tret++;\n\t\t\t}\n\t\t}\n\t\treturn ret;\n\t}\n\tstatic boolean ok(String w) {\n\t\treturn count(w) > 0;\n\t}\n\n\tprivate static Pair play(String current) {\n\t\tif (hash.containsKey(current)) {\n\t\t\treturn hash.get(current);\n\t\t}\n\t\tPair winpts = new Pair(0, 0, true);\n\t\tPair losepts = new Pair(0, 0, false);\n\t\tboolean canwin = false;\n\t\tfor (char c = 'a'; c <= 'z'; c++) {\n\t\t\tString nword1 = c + current;\n\t\t\tString nword2 = current + c;\n\t\t\tif (ok(nword1)) {\n\t\t\t\tPair res = play(nword1);\n\t\t\t\tlong nmy = getScore(nword1) + res.other;\n\t\t\t\tif (!res.win) {\n\t\t\t\t\tcanwin = true;\n\t\t\t\t\tif (winpts == null) {\n\t\t\t\t\t\twinpts = new Pair(0, 0, true);\n\t\t\t\t\t\twinpts.my = nmy;\n\t\t\t\t\t\twinpts.other = res.my;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (winpts.my < nmy || (winpts.my == nmy && winpts.other > res.my)) {\n\t\t\t\t\t\t\twinpts.my = nmy;\n\t\t\t\t\t\t\twinpts.other = res.my;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (losepts == null) {\n\t\t\t\t\t\tlosepts = new Pair(0, 0, false);\n\t\t\t\t\t\tlosepts.my = nmy;\n\t\t\t\t\t\tlosepts.other = res.my;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (losepts.my < nmy || (losepts.my == nmy && losepts.other > res.my)) {\n\t\t\t\t\t\t\tlosepts.my = nmy;\n\t\t\t\t\t\t\tlosepts.other = res.my;\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\tif (ok(nword2)) {\n\t\t\t\tPair res = play(nword2);\n\t\t\t\tlong nmy = getScore(nword2) + res.other;\n\t\t\t\tif (!res.win) {\n\t\t\t\t\tcanwin = true;\n\t\t\t\t\tif (winpts == null) {\n\t\t\t\t\t\twinpts = new Pair(0, 0, true);\n\t\t\t\t\t\twinpts.my = nmy;\n\t\t\t\t\t\twinpts.other = res.my;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (winpts.my < nmy || (winpts.my == nmy && winpts.other > res.my)) {\n\t\t\t\t\t\t\twinpts.my = nmy;\n\t\t\t\t\t\t\twinpts.other = res.my;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (losepts == null) {\n\t\t\t\t\t\tlosepts = new Pair(0, 0, false);\n\t\t\t\t\t\tlosepts.my = nmy;\n\t\t\t\t\t\tlosepts.other = res.my;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (losepts.my < nmy || (losepts.my == nmy && losepts.other > res.my)) {\n\t\t\t\t\t\t\tlosepts.my = nmy;\n\t\t\t\t\t\t\tlosepts.other = res.my;\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\tif (canwin) {\n\t\t\thash.put(current, winpts);\n\t\t\treturn winpts;\n\t\t} else {\n\t\t\thash.put(current, losepts);\n\t\t\treturn losepts;\n\t\t}\n\t}\n\n\tprivate static int getScore(String word) {\n\t\tint sum = 0;\n\t\tint max = 0;\n\t\tfor (char c : word.toCharArray()) {\n\t\t\tsum += (int)(c - 'a' + 1);\n\t\t\tmax = Math.max(max, (int)(c - 'a' + 1));\n\t\t}\n\t\treturn sum * max + count(word);\n\t}\n}\n\n\nclass Pair {\n\tlong my, other;\n\tboolean win;\n\n\tpublic Pair(long my, long other, boolean win) {\n\t\tsuper();\n\t\tthis.my = my;\n\t\tthis.other = other;\n\t\tthis.win = win;\n\t}\n\n\t@Override\n\tpublic int hashCode() {\n\t\tfinal int prime = 31;\n\t\tint result = 1;\n\t\tresult = prime * result + (int) (my ^ (my >>> 32));\n\t\tresult = prime * result + (int) (other ^ (other >>> 32));\n\t\tresult = prime * result + (win ? 1231 : 1237);\n\t\treturn result;\n\t}\n\n\t@Override\n\tpublic boolean equals(Object obj) {\n\t\tif (this == obj)\n\t\t\treturn true;\n\t\tif (obj == null)\n\t\t\treturn false;\n\t\tif (getClass() != obj.getClass())\n\t\t\treturn false;\n\t\tPair other = (Pair) obj;\n\t\tif (my != other.my)\n\t\t\treturn false;\n\t\tif (this.other != other.other)\n\t\t\treturn false;\n\t\tif (win != other.win)\n\t\t\treturn false;\n\t\treturn true;\n\t}\n\n\t\n\t\n\t\n}\n", "src_uid": "d0f8976d9b847f7426dc56cb59b5b5b9"} {"source_code": "import java.util.*;\n\npublic class E {\n\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\t\n\t\tint a = sc.nextInt(), b = sc.nextInt(), p = sc.nextInt();\n\t\tlong x = sc.nextLong();\n\t\t\n\t\tlong arr[] = new long[p];\n\t\tarr[p-1] = 1;\n\t\tfor(int i=p-2;i>=0;i--){\n\t\t\tarr[i] = arr[i+1] * a % p;\n\t\t}\n\t\t\n\t\tlong ans = 0;\n\t\tlong T = (long)p*(p-1);\n\t\t\n\t\tfor(int i = 1;i<=p-1;i++){\n\t\t\tlong j = (i- b * arr[i]) % p;\n\t\t\twhile(j < 0){\n\t\t\t\tj+=p;\n\t\t\t}\n\t\t\t\n\t\t\tlong n = j * (p-1) + i;\n\t\t\t\n\t\t\tans += x/T;\n\t\t\tif(x % T >= n)\n\t\t\t\tans++;\n\t\t}\n\t\t\n\t\tSystem.out.println(ans);\n\t\t\n\t}\n\n}\n", "src_uid": "4b9f470e5889da29affae6376f6c9f6a"} {"source_code": "import java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n long a = scanner.nextLong();\n long b = scanner.nextLong();\n long c = scanner.nextLong();\n scanner.close();\n\n long result = c * 2;\n long t = Math.min(a, b);\n result += t * 2;\n if (b > t) {\n result++;\n }\n if (a > t) {\n result++;\n }\n System.out.println(result);\n }\n}\n", "src_uid": "609f131325c13213aedcf8d55fc3ed77"} {"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.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 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 DGraphAndQueries solver = new DGraphAndQueries();\n solver.solve(1, in, out);\n out.close();\n }\n }\n\n static class DGraphAndQueries {\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 int[] p = new int[n];\n in.populate(p);\n\n\n Edge[] edges = new Edge[m];\n for (int i = 0; i < m; i++) {\n edges[i] = new Edge();\n edges[i].a = in.readInt() - 1;\n edges[i].b = in.readInt() - 1;\n }\n\n\n int[][] qs = new int[4][q];\n for (int i = 0; i < q; i++) {\n for (int j = 0; j < 2; j++) {\n qs[j][i] = in.readInt();\n }\n if (qs[0][i] == 2) {\n edges[qs[1][i] - 1].delete = true;\n }\n }\n\n\n DSUExt dsu = new DSUExt(n);\n dsu.reset();\n for (Edge e : edges) {\n if (e.delete) {\n continue;\n }\n dsu.merge(e.a, e.b);\n }\n\n for (int i = q - 1; i >= 0; i--) {\n if (qs[0][i] == 2) {\n Edge e = edges[qs[1][i] - 1];\n dsu.merge(e.a, e.b);\n } else {\n int v = qs[1][i] - 1;\n int pa = dsu.find(v);\n qs[2][i] = dsu.begin[pa];\n qs[3][i] = dsu.end[pa];\n }\n }\n\n int[] id = new int[n];\n int[] inv = new int[n];\n int idAlloc = 0;\n for (int i = 0; i < n; i++) {\n if (dsu.find(i) != i) {\n continue;\n }\n for (int trace = dsu.begin[i]; trace != -1; trace = dsu.next[trace]) {\n id[trace] = idAlloc++;\n inv[id[trace]] = trace;\n }\n }\n\n Segment seg = new Segment(0, n - 1, i -> p[inv[i]]);\n debug.debug(\"seg\", seg);\n for (int i = 0; i < q; i++) {\n if (qs[0][i] != 1) {\n continue;\n }\n int l = id[qs[2][i]];\n int r = id[qs[3][i]];\n if (l > r) {\n int tmp = l;\n l = r;\n r = tmp;\n }\n int ans = seg.query(l, r, 0, n - 1);\n seg.pop(l, r, 0, n - 1, ans);\n out.println(ans);\n\n debug.debug(\"debug\", seg);\n }\n }\n\n }\n\n static class Segment implements Cloneable {\n private Segment left;\n private Segment right;\n private int max;\n\n private void modify(int x) {\n max = x;\n }\n\n public void pushUp() {\n max = Math.max(left.max, right.max);\n }\n\n public void pushDown() {\n }\n\n public Segment(int l, int r, IntToIntegerFunction func) {\n if (l < r) {\n int m = DigitUtils.floorAverage(l, r);\n left = new Segment(l, m, func);\n right = new Segment(m + 1, r, func);\n pushUp();\n } else {\n max = func.apply(l);\n }\n }\n\n private boolean covered(int ll, int rr, int l, int r) {\n return ll <= l && rr >= r;\n }\n\n private boolean noIntersection(int ll, int rr, int l, int r) {\n return ll > r || rr < l;\n }\n\n public boolean pop(int ll, int rr, int l, int r, int maxVal) {\n if (noIntersection(ll, rr, l, r)) {\n return false;\n }\n if (covered(ll, rr, l, r)) {\n if (max != maxVal) {\n return false;\n }\n if (l == r) {\n modify(0);\n return true;\n }\n }\n pushDown();\n int m = DigitUtils.floorAverage(l, r);\n boolean ans = left.pop(ll, rr, l, m, maxVal);\n if (!ans) {\n ans = right.pop(ll, rr, m + 1, r, maxVal);\n }\n pushUp();\n return ans;\n }\n\n public int query(int ll, int rr, int l, int r) {\n if (noIntersection(ll, rr, l, r)) {\n return 0;\n }\n if (covered(ll, rr, l, r)) {\n return max;\n }\n pushDown();\n int m = DigitUtils.floorAverage(l, r);\n return Math.max(left.query(ll, rr, l, m),\n right.query(ll, rr, m + 1, r));\n }\n\n private Segment deepClone() {\n Segment seg = clone();\n if (seg.left != null) {\n seg.left = seg.left.deepClone();\n }\n if (seg.right != null) {\n seg.right = seg.right.deepClone();\n }\n return seg;\n }\n\n protected Segment clone() {\n try {\n return (Segment) super.clone();\n } catch (CloneNotSupportedException e) {\n throw new RuntimeException(e);\n }\n }\n\n private void toString(StringBuilder builder) {\n if (left == null && right == null) {\n builder.append(max).append(\",\");\n return;\n }\n pushDown();\n left.toString(builder);\n right.toString(builder);\n }\n\n public String toString() {\n StringBuilder builder = new StringBuilder();\n deepClone().toString(builder);\n if (builder.length() > 0) {\n builder.setLength(builder.length() - 1);\n }\n return builder.toString();\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 class DSUExt extends DSU {\n int[] begin;\n int[] end;\n int[] next;\n\n public DSUExt(int n) {\n super(n);\n begin = new int[n];\n end = new int[n];\n next = new int[n];\n }\n\n public void reset() {\n super.reset();\n for (int i = 0; i < begin.length; i++) {\n begin[i] = end[i] = i;\n next[i] = -1;\n }\n }\n\n protected void preMerge(int a, int b) {\n next[end[a]] = begin[b];\n end[a] = end[b];\n }\n\n }\n\n static interface IntToIntegerFunction {\n int apply(int x);\n\n }\n\n static class DigitUtils {\n private DigitUtils() {\n }\n\n public static int floorAverage(int x, int y) {\n return (x & y) + ((x ^ y) >> 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 class DSU {\n protected int[] p;\n protected int[] rank;\n\n public DSU(int n) {\n p = new int[n];\n rank = new int[n];\n }\n\n public void reset() {\n for (int i = 0; i < p.length; i++) {\n p[i] = i;\n rank[i] = 0;\n }\n }\n\n public final int find(int a) {\n if (p[a] == p[p[a]]) {\n return p[a];\n }\n preAccess(a);\n return p[a] = find(p[a]);\n }\n\n protected void preAccess(int a) {\n\n }\n\n protected void preMerge(int a, int b) {\n\n }\n\n public final void merge(int a, int b) {\n a = find(a);\n b = find(b);\n if (a == b) {\n return;\n }\n if (rank[a] == rank[b]) {\n rank[a]++;\n }\n\n if (rank[a] < rank[b]) {\n int tmp = a;\n a = b;\n b = tmp;\n }\n\n preMerge(a, b);\n p[b] = a;\n }\n\n }\n\n static class Edge {\n int a;\n int b;\n boolean delete;\n\n }\n}\n\n", "src_uid": "ad014bde729222db14f38caa521e4167"} {"source_code": "import java.io.*;\nimport java.math.BigInteger;\nimport java.util.*;\n\nimport static java.lang.Math.*;\nimport static java.util.Arrays.*;\n\npublic class Main {\n static long n;\n static long log;\n static long calc(long a) {\n long fa = a;\n long rt = 0;\n long lgt = getLength(a);\n for (long i = lgt + 1; i < log; i++) {\n rt += (1L << (i - lgt));\n }\n a <<= (log - lgt);\n int eql = 0;\n for (long i = log - 1; i >= log - lgt; i--) {\n if (getBit(a, i) != getBit(n, i)) {\n eql = getBit(a, i) > getBit(n, i) ? 1 : -1;\n break;\n }\n }\n if (eql == 1) return rt;\n if (eql == -1) return rt + (log == lgt ? 0 : (1L << (log - lgt)));\n long zrs = log - lgt;\n for (long i = log - lgt - 1; i >= 0; i--) {\n if (getBit(n, i) == 1) rt += ((1L << (zrs - 1L)));\n zrs--;\n }\n return rt + (fa == n ? 0L : 1L);\n }\n\n static long getBit(long a, long bit) {\n return (a >> bit) & 1L;\n }\n\n static long extraCalc(long a) {\n if ((a & 1) == 0) return calc(a) + ((a + 1L) <= n ? (calc(a + 1L) + 1L) : 0) + 1L;\n else return calc(a) + 1;\n }\n\n static long getLength(long a) {\n for (long i = 63; i >= 0; i--) {\n if (getBit(a, i) == 1L) return i + 1L;\n }\n return 1L;\n }\n\n public static void main(String[] args) throws IOException {\n FastScanner in = new FastScanner(System.in);\n PrintWriter out = new PrintWriter(System.out);\n n = in.nextLong();\n log = getLength(n);\n long k = in.nextLong();\n long t = 0;\n while ((1L << t) <= n) ++t;\n long l = 0;\n while (t > 0) {\n while (t > 0 && ((l + (1L << t)) > n || extraCalc(l + (1L << t)) < k)) {\n t--;\n }\n if (t == 0) {\n if (extraCalc(l + 1) >= k && l + 1 <= n) l++;\n } else l = (l + (1L << t));\n }\n if (extraCalc(l + 1) >= k && l + 1 <= n) l++;\n if (extraCalc(l) < k || l > n) l--;\n out.println(l);\n out.close();\n }\n}\n\nclass FastScanner {\n BufferedReader br;\n StringTokenizer st;\n\n FastScanner(File f) throws FileNotFoundException {\n br = new BufferedReader(new FileReader(f));\n }\n\n FastScanner(InputStream is) {\n br = new BufferedReader(new InputStreamReader(is));\n }\n\n String next() throws IOException {\n while (st == null || !st.hasMoreTokens())\n st = new StringTokenizer(br.readLine());\n return st.nextToken();\n }\n\n int nextInt() throws IOException {\n return Integer.parseInt(next());\n }\n\n long nextLong() throws IOException {\n return Long.parseLong(next());\n }\n}", "src_uid": "783c4b3179c558369f94f4a16ac562d4"}